@modern-js/plugin-state 1.2.10 → 2.65.5-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +14 -18
- package/dist/cjs/cli/index.js +70 -0
- package/dist/cjs/cli/types.js +16 -0
- package/dist/cjs/index.js +43 -0
- package/dist/cjs/plugins.js +50 -0
- package/dist/cjs/runtime/index.js +42 -0
- package/dist/cjs/runtime/plugin.js +95 -0
- package/dist/esm/cli/index.js +48 -0
- package/dist/esm/cli/types.js +0 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/plugins.js +19 -0
- package/dist/esm/runtime/index.js +6 -0
- package/dist/esm/runtime/plugin.js +92 -0
- package/dist/esm-node/cli/index.js +46 -0
- package/dist/esm-node/cli/types.js +0 -0
- package/dist/esm-node/index.js +7 -0
- package/dist/esm-node/plugins.js +13 -0
- package/dist/esm-node/runtime/index.js +6 -0
- package/dist/esm-node/runtime/plugin.js +68 -0
- package/dist/types/cli/index.d.ts +3 -5
- package/dist/types/cli/types.d.ts +6 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/runtime/index.d.ts +1 -2
- package/dist/types/runtime/plugin.d.ts +13 -17
- package/package.json +56 -83
- package/types/index.d.ts +27 -0
- package/CHANGELOG.md +0 -419
- package/dist/js/modern/cli/index.js +0 -110
- package/dist/js/modern/plugins.js +0 -7
- package/dist/js/modern/runtime/index.js +0 -4
- package/dist/js/modern/runtime/plugin.js +0 -70
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/cli/index.js +0 -127
- package/dist/js/node/plugins.js +0 -35
- package/dist/js/node/runtime/index.js +0 -61
- package/dist/js/node/runtime/plugin.js +0 -99
- package/dist/js/node/types.js +0 -5
- package/dist/js/treeshaking/cli/index.js +0 -100
- package/dist/js/treeshaking/plugins.js +0 -13
- package/dist/js/treeshaking/runtime/index.js +0 -4
- package/dist/js/treeshaking/runtime/plugin.js +0 -62
- package/dist/js/treeshaking/types.js +0 -1
- package/dist/types/types.d.ts +0 -17
- package/type.d.ts +0 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
|
|
2
1
|
<p align="center">
|
|
3
2
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
4
3
|
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
5
7
|
<p align="center">
|
|
6
|
-
|
|
7
|
-
<br/>
|
|
8
|
-
<a href="https://modernjs.dev" target="blank">
|
|
9
|
-
modernjs.dev
|
|
10
|
-
</a>
|
|
11
|
-
</p>
|
|
12
|
-
<p align="center">
|
|
13
|
-
The meta-framework suite designed from scratch for frontend-focused modern web development
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
14
9
|
</p>
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
|
|
11
|
+
## Getting Started
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
21
14
|
|
|
22
|
-
##
|
|
15
|
+
## Documentation
|
|
23
16
|
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [API References](https://modernjs.dev/docs/apis)
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
27
19
|
|
|
28
20
|
## Contributing
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cli_exports = {};
|
|
20
|
+
__export(cli_exports, {
|
|
21
|
+
default: () => cli_default,
|
|
22
|
+
statePlugin: () => statePlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cli_exports);
|
|
25
|
+
var import_utils = require("@modern-js/utils");
|
|
26
|
+
const PLUGIN_IDENTIFIER = "state";
|
|
27
|
+
const statePlugin = () => ({
|
|
28
|
+
name: "@modern-js/plugin-state",
|
|
29
|
+
required: [
|
|
30
|
+
"@modern-js/runtime"
|
|
31
|
+
],
|
|
32
|
+
setup: (api) => {
|
|
33
|
+
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
|
34
|
+
var _getEntryOptions;
|
|
35
|
+
const { entryName, isMainEntry } = entrypoint;
|
|
36
|
+
const userConfig = api.getNormalizedConfig();
|
|
37
|
+
const { packageName, metaName } = api.getAppContext();
|
|
38
|
+
const stateConfig = (_getEntryOptions = (0, import_utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
39
|
+
plugins.push({
|
|
40
|
+
name: PLUGIN_IDENTIFIER,
|
|
41
|
+
path: `@${metaName}/plugin-state/runtime`,
|
|
42
|
+
config: typeof stateConfig === "boolean" ? {} : stateConfig || {}
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
entrypoint,
|
|
46
|
+
plugins
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
api.config(() => {
|
|
50
|
+
const { metaName } = api.getAppContext();
|
|
51
|
+
return {
|
|
52
|
+
source: {
|
|
53
|
+
alias: {
|
|
54
|
+
[`@${metaName}/runtime/model`]: `@${metaName}/plugin-state/runtime`
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
api.addRuntimeExports(() => {
|
|
60
|
+
const { internalDirectory, metaName } = api.useAppContext();
|
|
61
|
+
const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
|
|
62
|
+
pluginsExportsUtils.addExport(`export { default as state } from '@${metaName}/plugin-state/runtime'`);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
var cli_default = statePlugin;
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
statePlugin
|
|
70
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => import_runtime2.default,
|
|
33
|
+
state: () => import_runtime.default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_runtime = __toESM(require("./runtime"));
|
|
37
|
+
var import_runtime2 = __toESM(require("./runtime"));
|
|
38
|
+
__reExport(src_exports, require("./runtime"), module.exports);
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
state,
|
|
42
|
+
...require("./runtime")
|
|
43
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var plugins_exports = {};
|
|
30
|
+
__export(plugins_exports, {
|
|
31
|
+
autoActions: () => autoActions,
|
|
32
|
+
devtools: () => import_plugin_devtools.default,
|
|
33
|
+
effects: () => effects,
|
|
34
|
+
immer: () => immer
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(plugins_exports);
|
|
37
|
+
var import_plugin_auto_actions = __toESM(require("@modern-js-reduck/plugin-auto-actions"));
|
|
38
|
+
var import_plugin_effects = require("@modern-js-reduck/plugin-effects");
|
|
39
|
+
var import_plugin_immutable = __toESM(require("@modern-js-reduck/plugin-immutable"));
|
|
40
|
+
var import_plugin_devtools = __toESM(require("@modern-js-reduck/plugin-devtools"));
|
|
41
|
+
const effects = () => import_plugin_effects.plugin;
|
|
42
|
+
const immer = () => import_plugin_immutable.default;
|
|
43
|
+
const autoActions = () => import_plugin_auto_actions.default;
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
autoActions,
|
|
47
|
+
devtools,
|
|
48
|
+
effects,
|
|
49
|
+
immer
|
|
50
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var runtime_exports = {};
|
|
31
|
+
__export(runtime_exports, {
|
|
32
|
+
default: () => import_plugin.default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
35
|
+
__reExport(runtime_exports, require("@modern-js-reduck/react"), module.exports);
|
|
36
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
37
|
+
__reExport(runtime_exports, require("./plugin"), module.exports);
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
...require("@modern-js-reduck/react"),
|
|
41
|
+
...require("./plugin")
|
|
42
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var plugin_exports = {};
|
|
21
|
+
__export(plugin_exports, {
|
|
22
|
+
Provider: () => import_react.Provider,
|
|
23
|
+
default: () => plugin_default,
|
|
24
|
+
statePlugin: () => statePlugin
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
27
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
+
var import_react = require("@modern-js-reduck/react");
|
|
29
|
+
var import_store = require("@modern-js-reduck/store");
|
|
30
|
+
var import_runtime = require("@modern-js/runtime");
|
|
31
|
+
var import_merge = require("@modern-js/runtime-utils/merge");
|
|
32
|
+
var import_plugins = require("../plugins");
|
|
33
|
+
__reExport(plugin_exports, require("../plugins"), module.exports);
|
|
34
|
+
const StatePluginHandleMap = {
|
|
35
|
+
immer: import_plugins.immer,
|
|
36
|
+
effects: import_plugins.effects,
|
|
37
|
+
autoActions: import_plugins.autoActions,
|
|
38
|
+
devtools: import_plugins.devtools
|
|
39
|
+
};
|
|
40
|
+
const getStoreConfig = (config) => {
|
|
41
|
+
const internalPlugins = [
|
|
42
|
+
"immer",
|
|
43
|
+
"effects",
|
|
44
|
+
"autoActions",
|
|
45
|
+
"devtools"
|
|
46
|
+
];
|
|
47
|
+
const plugins = [];
|
|
48
|
+
internalPlugins.filter((plugin) => config[plugin] !== false).forEach((plugin) => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
|
|
49
|
+
const storeConfig = {};
|
|
50
|
+
for (const [key, value] of Object.entries(config)) {
|
|
51
|
+
if (!internalPlugins.includes(key)) {
|
|
52
|
+
storeConfig[key] = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
storeConfig.plugins = plugins;
|
|
56
|
+
return storeConfig;
|
|
57
|
+
};
|
|
58
|
+
const statePlugin = (userConfig = {}) => ({
|
|
59
|
+
name: "@modern-js/plugin-state",
|
|
60
|
+
setup: (api) => {
|
|
61
|
+
let storeConfig;
|
|
62
|
+
return {
|
|
63
|
+
wrapRoot(App) {
|
|
64
|
+
const getStateApp = (props) => {
|
|
65
|
+
const context = (0, import_runtime.useRuntimeContext)();
|
|
66
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Provider, {
|
|
67
|
+
store: context.store,
|
|
68
|
+
config: storeConfig,
|
|
69
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
70
|
+
...props
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
return getStateApp;
|
|
75
|
+
},
|
|
76
|
+
beforeRender(context) {
|
|
77
|
+
const pluginConfig = api.useRuntimeConfigContext();
|
|
78
|
+
const config = (0, import_merge.merge)(pluginConfig.state || {}, userConfig);
|
|
79
|
+
storeConfig = getStoreConfig(config);
|
|
80
|
+
if ((0, import_runtime.isBrowser)()) {
|
|
81
|
+
var _window__SSR_DATA_data, _window__SSR_DATA, _window;
|
|
82
|
+
storeConfig.initialState = storeConfig.initialState || ((_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_data = _window__SSR_DATA.data) === null || _window__SSR_DATA_data === void 0 ? void 0 : _window__SSR_DATA_data.storeState) || {};
|
|
83
|
+
}
|
|
84
|
+
context.store = (0, import_store.createStore)(storeConfig);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
var plugin_default = statePlugin;
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
Provider,
|
|
93
|
+
statePlugin,
|
|
94
|
+
...require("../plugins")
|
|
95
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
+
import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
|
|
3
|
+
var PLUGIN_IDENTIFIER = "state";
|
|
4
|
+
var statePlugin = function() {
|
|
5
|
+
return {
|
|
6
|
+
name: "@modern-js/plugin-state",
|
|
7
|
+
required: [
|
|
8
|
+
"@modern-js/runtime"
|
|
9
|
+
],
|
|
10
|
+
setup: function(api) {
|
|
11
|
+
api._internalRuntimePlugins(function(param) {
|
|
12
|
+
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
13
|
+
var _getEntryOptions;
|
|
14
|
+
var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
|
|
15
|
+
var userConfig = api.getNormalizedConfig();
|
|
16
|
+
var _api_getAppContext = api.getAppContext(), packageName = _api_getAppContext.packageName, metaName = _api_getAppContext.metaName;
|
|
17
|
+
var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
18
|
+
plugins.push({
|
|
19
|
+
name: PLUGIN_IDENTIFIER,
|
|
20
|
+
path: "@".concat(metaName, "/plugin-state/runtime"),
|
|
21
|
+
config: typeof stateConfig === "boolean" ? {} : stateConfig || {}
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
entrypoint,
|
|
25
|
+
plugins
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
api.config(function() {
|
|
29
|
+
var metaName = api.getAppContext().metaName;
|
|
30
|
+
return {
|
|
31
|
+
source: {
|
|
32
|
+
alias: _define_property({}, "@".concat(metaName, "/runtime/model"), "@".concat(metaName, "/plugin-state/runtime"))
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
api.addRuntimeExports(function() {
|
|
37
|
+
var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
|
|
38
|
+
var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
39
|
+
pluginsExportsUtils.addExport("export { default as state } from '@".concat(metaName, "/plugin-state/runtime'"));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var cli_default = statePlugin;
|
|
45
|
+
export {
|
|
46
|
+
cli_default as default,
|
|
47
|
+
statePlugin
|
|
48
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import autoActionsPlugin from "@modern-js-reduck/plugin-auto-actions";
|
|
2
|
+
import { plugin as effectsPlugin } from "@modern-js-reduck/plugin-effects";
|
|
3
|
+
import immerPlugin from "@modern-js-reduck/plugin-immutable";
|
|
4
|
+
import { default as default2 } from "@modern-js-reduck/plugin-devtools";
|
|
5
|
+
var effects = function() {
|
|
6
|
+
return effectsPlugin;
|
|
7
|
+
};
|
|
8
|
+
var immer = function() {
|
|
9
|
+
return immerPlugin;
|
|
10
|
+
};
|
|
11
|
+
var autoActions = function() {
|
|
12
|
+
return autoActionsPlugin;
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
autoActions,
|
|
16
|
+
default2 as devtools,
|
|
17
|
+
effects,
|
|
18
|
+
immer
|
|
19
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Provider } from "@modern-js-reduck/react";
|
|
5
|
+
import { createStore } from "@modern-js-reduck/store";
|
|
6
|
+
import { isBrowser, useRuntimeContext } from "@modern-js/runtime";
|
|
7
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
8
|
+
import { autoActions, devtools, effects, immer } from "../plugins";
|
|
9
|
+
var StatePluginHandleMap = {
|
|
10
|
+
immer,
|
|
11
|
+
effects,
|
|
12
|
+
autoActions,
|
|
13
|
+
devtools
|
|
14
|
+
};
|
|
15
|
+
var getStoreConfig = function(config) {
|
|
16
|
+
var internalPlugins = [
|
|
17
|
+
"immer",
|
|
18
|
+
"effects",
|
|
19
|
+
"autoActions",
|
|
20
|
+
"devtools"
|
|
21
|
+
];
|
|
22
|
+
var plugins = [];
|
|
23
|
+
internalPlugins.filter(function(plugin) {
|
|
24
|
+
return config[plugin] !== false;
|
|
25
|
+
}).forEach(function(plugin) {
|
|
26
|
+
return plugins.push(StatePluginHandleMap[plugin](config[plugin]));
|
|
27
|
+
});
|
|
28
|
+
var storeConfig = {};
|
|
29
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
30
|
+
try {
|
|
31
|
+
for (var _iterator = Object.entries(config)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
32
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
33
|
+
if (!internalPlugins.includes(key)) {
|
|
34
|
+
storeConfig[key] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch (err) {
|
|
38
|
+
_didIteratorError = true;
|
|
39
|
+
_iteratorError = err;
|
|
40
|
+
} finally {
|
|
41
|
+
try {
|
|
42
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
43
|
+
_iterator.return();
|
|
44
|
+
}
|
|
45
|
+
} finally {
|
|
46
|
+
if (_didIteratorError) {
|
|
47
|
+
throw _iteratorError;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
storeConfig.plugins = plugins;
|
|
52
|
+
return storeConfig;
|
|
53
|
+
};
|
|
54
|
+
var statePlugin = function() {
|
|
55
|
+
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
56
|
+
return {
|
|
57
|
+
name: "@modern-js/plugin-state",
|
|
58
|
+
setup: function(api) {
|
|
59
|
+
var storeConfig;
|
|
60
|
+
return {
|
|
61
|
+
wrapRoot: function wrapRoot(App) {
|
|
62
|
+
var getStateApp = function(props) {
|
|
63
|
+
var context = useRuntimeContext();
|
|
64
|
+
return /* @__PURE__ */ _jsx(Provider, {
|
|
65
|
+
store: context.store,
|
|
66
|
+
config: storeConfig,
|
|
67
|
+
children: /* @__PURE__ */ _jsx(App, _object_spread({}, props))
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return getStateApp;
|
|
71
|
+
},
|
|
72
|
+
beforeRender: function beforeRender(context) {
|
|
73
|
+
var pluginConfig = api.useRuntimeConfigContext();
|
|
74
|
+
var config = merge(pluginConfig.state || {}, userConfig);
|
|
75
|
+
storeConfig = getStoreConfig(config);
|
|
76
|
+
if (isBrowser()) {
|
|
77
|
+
var _window__SSR_DATA_data, _window__SSR_DATA, _window;
|
|
78
|
+
storeConfig.initialState = storeConfig.initialState || ((_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_data = _window__SSR_DATA.data) === null || _window__SSR_DATA_data === void 0 ? void 0 : _window__SSR_DATA_data.storeState) || {};
|
|
79
|
+
}
|
|
80
|
+
context.store = createStore(storeConfig);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
var plugin_default = statePlugin;
|
|
87
|
+
export * from "../plugins";
|
|
88
|
+
export {
|
|
89
|
+
Provider,
|
|
90
|
+
plugin_default as default,
|
|
91
|
+
statePlugin
|
|
92
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
|
|
2
|
+
const PLUGIN_IDENTIFIER = "state";
|
|
3
|
+
const statePlugin = () => ({
|
|
4
|
+
name: "@modern-js/plugin-state",
|
|
5
|
+
required: [
|
|
6
|
+
"@modern-js/runtime"
|
|
7
|
+
],
|
|
8
|
+
setup: (api) => {
|
|
9
|
+
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
|
10
|
+
var _getEntryOptions;
|
|
11
|
+
const { entryName, isMainEntry } = entrypoint;
|
|
12
|
+
const userConfig = api.getNormalizedConfig();
|
|
13
|
+
const { packageName, metaName } = api.getAppContext();
|
|
14
|
+
const stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
15
|
+
plugins.push({
|
|
16
|
+
name: PLUGIN_IDENTIFIER,
|
|
17
|
+
path: `@${metaName}/plugin-state/runtime`,
|
|
18
|
+
config: typeof stateConfig === "boolean" ? {} : stateConfig || {}
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
entrypoint,
|
|
22
|
+
plugins
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
api.config(() => {
|
|
26
|
+
const { metaName } = api.getAppContext();
|
|
27
|
+
return {
|
|
28
|
+
source: {
|
|
29
|
+
alias: {
|
|
30
|
+
[`@${metaName}/runtime/model`]: `@${metaName}/plugin-state/runtime`
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
api.addRuntimeExports(() => {
|
|
36
|
+
const { internalDirectory, metaName } = api.useAppContext();
|
|
37
|
+
const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
38
|
+
pluginsExportsUtils.addExport(`export { default as state } from '@${metaName}/plugin-state/runtime'`);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var cli_default = statePlugin;
|
|
43
|
+
export {
|
|
44
|
+
cli_default as default,
|
|
45
|
+
statePlugin
|
|
46
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import autoActionsPlugin from "@modern-js-reduck/plugin-auto-actions";
|
|
2
|
+
import { plugin as effectsPlugin } from "@modern-js-reduck/plugin-effects";
|
|
3
|
+
import immerPlugin from "@modern-js-reduck/plugin-immutable";
|
|
4
|
+
import { default as default2 } from "@modern-js-reduck/plugin-devtools";
|
|
5
|
+
const effects = () => effectsPlugin;
|
|
6
|
+
const immer = () => immerPlugin;
|
|
7
|
+
const autoActions = () => autoActionsPlugin;
|
|
8
|
+
export {
|
|
9
|
+
autoActions,
|
|
10
|
+
default2 as devtools,
|
|
11
|
+
effects,
|
|
12
|
+
immer
|
|
13
|
+
};
|