@modern-js/plugin-state 1.2.10 → 2.65.5-alpha.0

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.
Files changed (46) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +14 -18
  3. package/dist/cjs/cli/index.js +70 -0
  4. package/dist/cjs/cli/types.js +16 -0
  5. package/dist/cjs/index.js +43 -0
  6. package/dist/cjs/plugins.js +50 -0
  7. package/dist/cjs/runtime/index.js +42 -0
  8. package/dist/cjs/runtime/plugin.js +93 -0
  9. package/dist/esm/cli/index.js +48 -0
  10. package/dist/esm/cli/types.js +0 -0
  11. package/dist/esm/index.js +7 -0
  12. package/dist/esm/plugins.js +19 -0
  13. package/dist/esm/runtime/index.js +6 -0
  14. package/dist/esm/runtime/plugin.js +91 -0
  15. package/dist/esm-node/cli/index.js +46 -0
  16. package/dist/esm-node/cli/types.js +0 -0
  17. package/dist/esm-node/index.js +7 -0
  18. package/dist/esm-node/plugins.js +13 -0
  19. package/dist/esm-node/runtime/index.js +6 -0
  20. package/dist/esm-node/runtime/plugin.js +67 -0
  21. package/dist/types/cli/index.d.ts +3 -5
  22. package/dist/types/cli/types.d.ts +6 -0
  23. package/dist/types/index.d.ts +3 -0
  24. package/dist/types/plugins.d.ts +1 -1
  25. package/dist/types/runtime/index.d.ts +1 -2
  26. package/dist/types/runtime/plugin.d.ts +11 -17
  27. package/package.json +56 -83
  28. package/types/index.d.ts +27 -0
  29. package/CHANGELOG.md +0 -419
  30. package/dist/js/modern/cli/index.js +0 -110
  31. package/dist/js/modern/plugins.js +0 -7
  32. package/dist/js/modern/runtime/index.js +0 -4
  33. package/dist/js/modern/runtime/plugin.js +0 -70
  34. package/dist/js/modern/types.js +0 -1
  35. package/dist/js/node/cli/index.js +0 -127
  36. package/dist/js/node/plugins.js +0 -35
  37. package/dist/js/node/runtime/index.js +0 -61
  38. package/dist/js/node/runtime/plugin.js +0 -99
  39. package/dist/js/node/types.js +0 -5
  40. package/dist/js/treeshaking/cli/index.js +0 -100
  41. package/dist/js/treeshaking/plugins.js +0 -13
  42. package/dist/js/treeshaking/runtime/index.js +0 -4
  43. package/dist/js/treeshaking/runtime/plugin.js +0 -62
  44. package/dist/js/treeshaking/types.js +0 -1
  45. package/dist/types/types.d.ts +0 -17
  46. package/type.d.ts +0 -4
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Modern.js
3
+ Copyright (c) 2021-present Modern.js
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- 现代 Web 工程体系
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
- # Introduction
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
- - [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
13
+ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
21
14
 
22
- ## Getting Started
15
+ ## Documentation
23
16
 
24
- - [Quick Start](https://modernjs.dev/docs/start)
25
- - [Guides](https://modernjs.dev/docs/guides)
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
- - [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)
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,93 @@
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
+ default: () => plugin_default,
23
+ statePlugin: () => statePlugin
24
+ });
25
+ module.exports = __toCommonJS(plugin_exports);
26
+ var import_jsx_runtime = require("react/jsx-runtime");
27
+ var import_react = require("@modern-js-reduck/react");
28
+ var import_store = require("@modern-js-reduck/store");
29
+ var import_runtime = require("@modern-js/runtime");
30
+ var import_merge = require("@modern-js/runtime-utils/merge");
31
+ var import_plugins = require("../plugins");
32
+ __reExport(plugin_exports, require("../plugins"), module.exports);
33
+ const StatePluginHandleMap = {
34
+ immer: import_plugins.immer,
35
+ effects: import_plugins.effects,
36
+ autoActions: import_plugins.autoActions,
37
+ devtools: import_plugins.devtools
38
+ };
39
+ const getStoreConfig = (config) => {
40
+ const internalPlugins = [
41
+ "immer",
42
+ "effects",
43
+ "autoActions",
44
+ "devtools"
45
+ ];
46
+ const plugins = [];
47
+ internalPlugins.filter((plugin) => config[plugin] !== false).forEach((plugin) => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
48
+ const storeConfig = {};
49
+ for (const [key, value] of Object.entries(config)) {
50
+ if (!internalPlugins.includes(key)) {
51
+ storeConfig[key] = value;
52
+ }
53
+ }
54
+ storeConfig.plugins = plugins;
55
+ return storeConfig;
56
+ };
57
+ const statePlugin = (userConfig = {}) => ({
58
+ name: "@modern-js/plugin-state",
59
+ setup: (api) => {
60
+ let storeConfig;
61
+ return {
62
+ wrapRoot(App) {
63
+ const getStateApp = (props) => {
64
+ const context = (0, import_runtime.useRuntimeContext)();
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Provider, {
66
+ store: context.store,
67
+ config: storeConfig,
68
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
69
+ ...props
70
+ })
71
+ });
72
+ };
73
+ return getStateApp;
74
+ },
75
+ beforeRender(context) {
76
+ const pluginConfig = api.useRuntimeConfigContext();
77
+ const config = (0, import_merge.merge)(pluginConfig.state || {}, userConfig);
78
+ storeConfig = getStoreConfig(config);
79
+ if ((0, import_runtime.isBrowser)()) {
80
+ var _window__SSR_DATA_data, _window__SSR_DATA, _window;
81
+ 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) || {};
82
+ }
83
+ context.store = (0, import_store.createStore)(storeConfig);
84
+ }
85
+ };
86
+ }
87
+ });
88
+ var plugin_default = statePlugin;
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ statePlugin,
92
+ ...require("../plugins")
93
+ });
@@ -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,7 @@
1
+ import { default as default2 } from "./runtime";
2
+ import { default as default3 } from "./runtime";
3
+ export * from "./runtime";
4
+ export {
5
+ default3 as default,
6
+ default2 as state
7
+ };
@@ -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,6 @@
1
+ export * from "@modern-js-reduck/react";
2
+ import { default as default2 } from "./plugin";
3
+ export * from "./plugin";
4
+ export {
5
+ default2 as default
6
+ };
@@ -0,0 +1,91 @@
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
+ plugin_default as default,
90
+ statePlugin
91
+ };
@@ -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,7 @@
1
+ import { default as default2 } from "./runtime";
2
+ import { default as default3 } from "./runtime";
3
+ export * from "./runtime";
4
+ export {
5
+ default3 as default,
6
+ default2 as state
7
+ };
@@ -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
+ };
@@ -0,0 +1,6 @@
1
+ export * from "@modern-js-reduck/react";
2
+ import { default as default2 } from "./plugin";
3
+ export * from "./plugin";
4
+ export {
5
+ default2 as default
6
+ };