mirror of
https://github.com/flarum/core.git
synced 2025-08-16 05:14:20 +02:00
Compare commits
4 Commits
v1.1.1
...
as/export-
Author | SHA1 | Date | |
---|---|---|---|
|
3ef541a152 | ||
|
81894d7cc2 | ||
|
97aa569bfa | ||
|
7d80b88d5c |
@@ -8,7 +8,7 @@
|
|||||||
"clsx": "^1.1.1",
|
"clsx": "^1.1.1",
|
||||||
"color-thief-browser": "^2.0.2",
|
"color-thief-browser": "^2.0.2",
|
||||||
"dayjs": "^1.10.4",
|
"dayjs": "^1.10.4",
|
||||||
"expose-loader": "^1.0.3",
|
"expose-loader": "^2.0.0",
|
||||||
"jquery": "^3.6.0",
|
"jquery": "^3.6.0",
|
||||||
"jquery.hotkeys": "^0.1.0",
|
"jquery.hotkeys": "^0.1.0",
|
||||||
"mithril": "^2.0.4",
|
"mithril": "^2.0.4",
|
||||||
@@ -25,13 +25,13 @@
|
|||||||
"@types/textarea-caret": "^3.0.0",
|
"@types/textarea-caret": "^3.0.0",
|
||||||
"bundlewatch": "^0.3.2",
|
"bundlewatch": "^0.3.2",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"flarum-webpack-config": "0.1.0-beta.10",
|
"flarum-webpack-config": "^1.0.0",
|
||||||
"husky": "^4.3.8",
|
"husky": "^4.3.8",
|
||||||
"prettier": "^2.2.1",
|
"prettier": "^2.2.1",
|
||||||
"webpack": "^4.46.0",
|
"webpack": "^5.0.0",
|
||||||
"webpack-bundle-analyzer": "^4.4.0",
|
"webpack-bundle-analyzer": "^4.4.1",
|
||||||
"webpack-cli": "^3.3.12",
|
"webpack-cli": "^4.0.0",
|
||||||
"webpack-merge": "^4.2.2"
|
"webpack-merge": "^4.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "webpack --mode development --watch",
|
"dev": "webpack --mode development --watch",
|
||||||
|
@@ -12,6 +12,7 @@ import mapRoutes from './utils/mapRoutes';
|
|||||||
import RequestError from './utils/RequestError';
|
import RequestError from './utils/RequestError';
|
||||||
import ScrollListener from './utils/ScrollListener';
|
import ScrollListener from './utils/ScrollListener';
|
||||||
import liveHumanTimes from './utils/liveHumanTimes';
|
import liveHumanTimes from './utils/liveHumanTimes';
|
||||||
|
import patchMithril from './utils/patchMithril';
|
||||||
import { extend } from './extend';
|
import { extend } from './extend';
|
||||||
|
|
||||||
import Forum from './models/Forum';
|
import Forum from './models/Forum';
|
||||||
@@ -166,6 +167,8 @@ export default class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boot() {
|
boot() {
|
||||||
|
patchMithril(window);
|
||||||
|
|
||||||
this.initializers.toArray().forEach((initializer) => initializer(this));
|
this.initializers.toArray().forEach((initializer) => initializer(this));
|
||||||
|
|
||||||
this.store.pushPayload({ data: this.data.resources });
|
this.store.pushPayload({ data: this.data.resources });
|
||||||
|
60
js/src/common/FlarumRegistry.ts
Normal file
60
js/src/common/FlarumRegistry.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
interface ExportRegistry {
|
||||||
|
moduleExports: object;
|
||||||
|
|
||||||
|
onLoads: object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an instance to the registry.
|
||||||
|
* This serves as the equivalent of `flarum.core.compat[id] = object`
|
||||||
|
*/
|
||||||
|
add(namespace: string, id: string, object: any): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a function to run when object of id "id" is added (or overriden).
|
||||||
|
* If such an object is already registered, the handler will be applied immediately.
|
||||||
|
*/
|
||||||
|
onLoad(namespace: string, id: string, handler: Function): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve an object of type `id` from the registry.
|
||||||
|
*/
|
||||||
|
get(namespace: string, id: string): any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class FlarumRegistry implements ExportRegistry {
|
||||||
|
moduleExports = new Map<string, any>();
|
||||||
|
onLoads = new Map<string, Function[]>();
|
||||||
|
|
||||||
|
protected genKey(namespace: string, id: string): string {
|
||||||
|
return `${namespace};${id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
add(namespace: string, id: string, object: any) {
|
||||||
|
const key = this.genKey(namespace, id);
|
||||||
|
|
||||||
|
const onLoads = this.onLoads.get(key);
|
||||||
|
if (onLoads) {
|
||||||
|
onLoads.reduce((acc, handler) => handler(acc), object);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.moduleExports.set(key, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
onLoad(namespace: string, id: string, handler: Function) {
|
||||||
|
const key = this.genKey(namespace, id);
|
||||||
|
|
||||||
|
const loadedObject = this.moduleExports.get(key);
|
||||||
|
if (loadedObject) {
|
||||||
|
this.moduleExports[id] = handler(loadedObject);
|
||||||
|
} else {
|
||||||
|
const currOnLoads = this.onLoads.get(key);
|
||||||
|
this.onLoads.set(key, [...(currOnLoads || []), handler]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get(namespace: string, id: string): any {
|
||||||
|
const key = this.genKey(namespace, id);
|
||||||
|
|
||||||
|
return this.moduleExports.get(key);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
// Expose jQuery, mithril and dayjs to the window browser object
|
// Expose jQuery, mithril and dayjs to the window browser object
|
||||||
import 'expose-loader?exposes[]=$&exposes[]=jQuery!jquery';
|
import 'expose-loader?exposes=$,jQuery!jquery';
|
||||||
import 'expose-loader?exposes=m!mithril';
|
import 'expose-loader?exposes=m!mithril';
|
||||||
import 'expose-loader?exposes=dayjs!dayjs';
|
import 'expose-loader?exposes=dayjs!dayjs';
|
||||||
|
|
||||||
@@ -16,9 +16,9 @@ import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
dayjs.extend(localizedFormat);
|
dayjs.extend(localizedFormat);
|
||||||
|
|
||||||
import patchMithril from './utils/patchMithril';
|
import FlarumRegistry from './FlarumRegistry';
|
||||||
|
|
||||||
patchMithril(window);
|
window.flreg = new FlarumRegistry();
|
||||||
|
|
||||||
import * as Extend from './extend/index';
|
import * as Extend from './extend/index';
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* The `evented` mixin provides methods allowing an object to trigger events,
|
* The `evented` mixin provides methods allowing an object to trigger events,
|
||||||
* running externally registered event handlers.
|
* running externally registered event handlers.
|
||||||
*/
|
*/
|
||||||
export default {
|
const evented = {
|
||||||
/**
|
/**
|
||||||
* Arrays of registered event handlers, grouped by the event name.
|
* Arrays of registered event handlers, grouped by the event name.
|
||||||
*
|
*
|
||||||
@@ -79,3 +79,5 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default evented;
|
||||||
|
@@ -11,7 +11,7 @@ import extractText from '../../common/utils/extractText';
|
|||||||
* The `DiscussionControls` utility constructs a list of buttons for a
|
* The `DiscussionControls` utility constructs a list of buttons for a
|
||||||
* discussion which perform actions on it.
|
* discussion which perform actions on it.
|
||||||
*/
|
*/
|
||||||
export default {
|
const DiscussionControls = {
|
||||||
/**
|
/**
|
||||||
* Get a list of controls for a discussion.
|
* Get a list of controls for a discussion.
|
||||||
*
|
*
|
||||||
@@ -259,3 +259,5 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default DiscussionControls;
|
||||||
|
@@ -8,7 +8,7 @@ import extractText from '../../common/utils/extractText';
|
|||||||
* The `PostControls` utility constructs a list of buttons for a post which
|
* The `PostControls` utility constructs a list of buttons for a post which
|
||||||
* perform actions on it.
|
* perform actions on it.
|
||||||
*/
|
*/
|
||||||
export default {
|
const PostControls = {
|
||||||
/**
|
/**
|
||||||
* Get a list of controls for a post.
|
* Get a list of controls for a post.
|
||||||
*
|
*
|
||||||
@@ -199,3 +199,5 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default PostControls;
|
||||||
|
@@ -8,7 +8,7 @@ import ItemList from '../../common/utils/ItemList';
|
|||||||
* The `UserControls` utility constructs a list of buttons for a user which
|
* The `UserControls` utility constructs a list of buttons for a user which
|
||||||
* perform actions on it.
|
* perform actions on it.
|
||||||
*/
|
*/
|
||||||
export default {
|
const UserControls = {
|
||||||
/**
|
/**
|
||||||
* Get a list of controls for a user.
|
* Get a list of controls for a user.
|
||||||
*
|
*
|
||||||
@@ -141,3 +141,5 @@ export default {
|
|||||||
app.modal.show(EditUserModal, { user });
|
app.modal.show(EditUserModal, { user });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default UserControls;
|
||||||
|
@@ -24,4 +24,4 @@ module.exports = merge(config(), {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.exports['module'].rules[0].test = /\.(tsx?|js)$/;
|
module.exports['module'].rules[0].test = /\.(tsx?|js)$/;
|
||||||
module.exports['module'].rules[0].use.options.presets.push('@babel/preset-typescript');
|
module.exports['module'].rules[0].use[1].options.presets.push('@babel/preset-typescript');
|
||||||
|
@@ -97,11 +97,11 @@ class Frontend implements ExtenderInterface
|
|||||||
if ($this->js) {
|
if ($this->js) {
|
||||||
$assets->js(function (SourceCollector $sources) use ($moduleName) {
|
$assets->js(function (SourceCollector $sources) use ($moduleName) {
|
||||||
$sources->addString(function () {
|
$sources->addString(function () {
|
||||||
return 'var module={}';
|
return 'var module={};';
|
||||||
});
|
});
|
||||||
$sources->addFile($this->js);
|
$sources->addFile($this->js);
|
||||||
$sources->addString(function () use ($moduleName) {
|
$sources->addString(function () use ($moduleName) {
|
||||||
return "flarum.extensions['$moduleName']=module.exports";
|
return "flarum.extensions['$moduleName']=module.exports;";
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user