@modern-js/runtime 2.65.5 → 2.67.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 (71) hide show
  1. package/dist/cjs/cli/index.js +2 -7
  2. package/dist/cjs/router/cli/code/index.js +3 -4
  3. package/dist/cjs/router/cli/code/templates.js +3 -0
  4. package/dist/cjs/router/cli/entry.js +2 -2
  5. package/dist/cjs/router/cli/handler.js +6 -7
  6. package/dist/cjs/router/cli/index.js +12 -10
  7. package/dist/esm/cli/index.js +1 -5
  8. package/dist/esm/router/cli/code/index.js +6 -7
  9. package/dist/esm/router/cli/code/templates.js +13 -6
  10. package/dist/esm/router/cli/entry.js +3 -4
  11. package/dist/esm/router/cli/handler.js +9 -11
  12. package/dist/esm/router/cli/index.js +13 -11
  13. package/dist/esm-node/cli/index.js +1 -5
  14. package/dist/esm-node/router/cli/code/index.js +4 -5
  15. package/dist/esm-node/router/cli/code/templates.js +3 -0
  16. package/dist/esm-node/router/cli/entry.js +3 -3
  17. package/dist/esm-node/router/cli/handler.js +6 -7
  18. package/dist/esm-node/router/cli/index.js +13 -11
  19. package/dist/types/cli/code.d.ts +1 -1
  20. package/dist/types/cli/index.d.ts +3 -4
  21. package/dist/types/cli/ssr/index.d.ts +1 -1
  22. package/dist/types/cli/template.d.ts +8 -8
  23. package/dist/types/common.d.ts +2 -8
  24. package/dist/types/config.d.ts +0 -2
  25. package/dist/types/core/compat/requestContext.d.ts +4 -7
  26. package/dist/types/core/context/index.d.ts +0 -1
  27. package/dist/types/core/context/monitors/index.server.d.ts +1 -1
  28. package/dist/types/core/context/runtime.d.ts +0 -4
  29. package/dist/types/core/loader/useLoader.d.ts +2 -2
  30. package/dist/types/core/plugin/base.d.ts +0 -1
  31. package/dist/types/core/server/shared.d.ts +0 -1
  32. package/dist/types/core/server/utils.d.ts +9 -1
  33. package/dist/types/document/Script.d.ts +0 -1
  34. package/dist/types/document/Title.d.ts +0 -1
  35. package/dist/types/document/cli/index.d.ts +1 -1
  36. package/dist/types/index.d.ts +1 -2
  37. package/dist/types/router/cli/code/index.d.ts +1 -1
  38. package/dist/types/router/cli/code/templates.d.ts +5 -5
  39. package/dist/types/router/cli/code/utils.d.ts +1 -1
  40. package/dist/types/router/cli/entry.d.ts +1 -1
  41. package/dist/types/router/cli/handler.d.ts +3 -3
  42. package/dist/types/router/cli/index.d.ts +1 -1
  43. package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +0 -1
  44. package/dist/types/router/runtime/hooks.d.ts +2 -2
  45. package/dist/types/router/runtime/routeModule.d.ts +0 -1
  46. package/dist/types/router/runtime/types.d.ts +0 -1
  47. package/dist/types/router/runtime/withRouter.d.ts +1 -1
  48. package/package.json +12 -27
  49. package/types/index.d.ts +1 -13
  50. package/types/router.d.ts +0 -1
  51. package/dist/cjs/state/cli/index.js +0 -62
  52. package/dist/cjs/state/index.js +0 -43
  53. package/dist/cjs/state/plugins.js +0 -50
  54. package/dist/cjs/state/runtime/index.js +0 -42
  55. package/dist/cjs/state/runtime/plugin.js +0 -95
  56. package/dist/esm/state/cli/index.js +0 -41
  57. package/dist/esm/state/index.js +0 -7
  58. package/dist/esm/state/plugins.js +0 -19
  59. package/dist/esm/state/runtime/index.js +0 -6
  60. package/dist/esm/state/runtime/plugin.js +0 -93
  61. package/dist/esm-node/state/cli/index.js +0 -38
  62. package/dist/esm-node/state/index.js +0 -7
  63. package/dist/esm-node/state/plugins.js +0 -13
  64. package/dist/esm-node/state/runtime/index.js +0 -6
  65. package/dist/esm-node/state/runtime/plugin.js +0 -69
  66. package/dist/types/state/cli/index.d.ts +0 -3
  67. package/dist/types/state/index.d.ts +0 -3
  68. package/dist/types/state/plugins.d.ts +0 -4
  69. package/dist/types/state/runtime/index.d.ts +0 -3
  70. package/dist/types/state/runtime/plugin.d.ts +0 -11
  71. package/types/model.d.ts +0 -7
@@ -1,50 +0,0 @@
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
- });
@@ -1,42 +0,0 @@
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
- });
@@ -1,95 +0,0 @@
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_merge = require("@modern-js/runtime-utils/merge");
30
- var import_react2 = require("react");
31
- var import_common = require("../../common");
32
- var import_core = require("../../core");
33
- var import_plugins = require("../plugins");
34
- __reExport(plugin_exports, require("../plugins"), module.exports);
35
- const StatePluginHandleMap = {
36
- immer: import_plugins.immer,
37
- effects: import_plugins.effects,
38
- autoActions: import_plugins.autoActions,
39
- devtools: import_plugins.devtools
40
- };
41
- const getStoreConfig = (config) => {
42
- const internalPlugins = [
43
- "immer",
44
- "effects",
45
- "autoActions",
46
- "devtools"
47
- ];
48
- const plugins = [];
49
- internalPlugins.filter((plugin) => config[plugin] !== false).forEach((plugin) => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
50
- const storeConfig = {};
51
- for (const [key, value] of Object.entries(config)) {
52
- if (!internalPlugins.includes(key)) {
53
- storeConfig[key] = value;
54
- }
55
- }
56
- storeConfig.plugins = plugins;
57
- return storeConfig;
58
- };
59
- const statePlugin = (userConfig = {}) => ({
60
- name: "@modern-js/plugin-state",
61
- setup: (api) => {
62
- let storeConfig;
63
- return {
64
- wrapRoot(App) {
65
- const getStateApp = (props) => {
66
- const context = (0, import_react2.useContext)(import_core.RuntimeReactContext);
67
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Provider, {
68
- store: context.store,
69
- config: storeConfig,
70
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
71
- ...props
72
- })
73
- });
74
- };
75
- return getStateApp;
76
- },
77
- beforeRender(context) {
78
- const pluginConfig = api.useRuntimeConfigContext();
79
- const config = (0, import_merge.merge)(pluginConfig.state || {}, userConfig);
80
- storeConfig = getStoreConfig(config);
81
- if ((0, import_common.isBrowser)()) {
82
- var _window__SSR_DATA_data, _window__SSR_DATA, _window;
83
- 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) || {};
84
- }
85
- context.store = (0, import_store.createStore)(storeConfig);
86
- }
87
- };
88
- }
89
- });
90
- var plugin_default = statePlugin;
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- statePlugin,
94
- ...require("../plugins")
95
- });
@@ -1,41 +0,0 @@
1
- import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
2
- var PLUGIN_IDENTIFIER = "state";
3
- var statePlugin = function() {
4
- return {
5
- name: "@modern-js/plugin-state",
6
- required: [
7
- "@modern-js/runtime"
8
- ],
9
- setup: function(api) {
10
- api._internalRuntimePlugins(function(param) {
11
- var entrypoint = param.entrypoint, plugins = param.plugins;
12
- var _getEntryOptions;
13
- var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
14
- var userConfig = api.getNormalizedConfig();
15
- var _api_getAppContext = api.getAppContext(), packageName = _api_getAppContext.packageName, metaName = _api_getAppContext.metaName;
16
- var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
17
- if (stateConfig) {
18
- plugins.push({
19
- name: PLUGIN_IDENTIFIER,
20
- path: "@".concat(metaName, "/runtime/model"),
21
- config: typeof stateConfig === "boolean" ? {} : stateConfig
22
- });
23
- }
24
- return {
25
- entrypoint,
26
- plugins
27
- };
28
- });
29
- api.addRuntimeExports(function() {
30
- var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
31
- var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
32
- pluginsExportsUtils.addExport("export { default as state } from '@".concat(metaName, "/runtime/model'"));
33
- });
34
- }
35
- };
36
- };
37
- var cli_default = statePlugin;
38
- export {
39
- cli_default as default,
40
- statePlugin
41
- };
@@ -1,7 +0,0 @@
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
- };
@@ -1,19 +0,0 @@
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
- };
@@ -1,6 +0,0 @@
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
- };
@@ -1,93 +0,0 @@
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 { merge } from "@modern-js/runtime-utils/merge";
7
- import { useContext } from "react";
8
- import { isBrowser } from "../../common";
9
- import { RuntimeReactContext } from "../../core";
10
- import { autoActions, devtools, effects, immer } from "../plugins";
11
- var StatePluginHandleMap = {
12
- immer,
13
- effects,
14
- autoActions,
15
- devtools
16
- };
17
- var getStoreConfig = function(config) {
18
- var internalPlugins = [
19
- "immer",
20
- "effects",
21
- "autoActions",
22
- "devtools"
23
- ];
24
- var plugins = [];
25
- internalPlugins.filter(function(plugin) {
26
- return config[plugin] !== false;
27
- }).forEach(function(plugin) {
28
- return plugins.push(StatePluginHandleMap[plugin](config[plugin]));
29
- });
30
- var storeConfig = {};
31
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
32
- try {
33
- for (var _iterator = Object.entries(config)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
34
- var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
35
- if (!internalPlugins.includes(key)) {
36
- storeConfig[key] = value;
37
- }
38
- }
39
- } catch (err) {
40
- _didIteratorError = true;
41
- _iteratorError = err;
42
- } finally {
43
- try {
44
- if (!_iteratorNormalCompletion && _iterator.return != null) {
45
- _iterator.return();
46
- }
47
- } finally {
48
- if (_didIteratorError) {
49
- throw _iteratorError;
50
- }
51
- }
52
- }
53
- storeConfig.plugins = plugins;
54
- return storeConfig;
55
- };
56
- var statePlugin = function() {
57
- var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
58
- return {
59
- name: "@modern-js/plugin-state",
60
- setup: function(api) {
61
- var storeConfig;
62
- return {
63
- wrapRoot: function wrapRoot(App) {
64
- var getStateApp = function(props) {
65
- var context = useContext(RuntimeReactContext);
66
- return /* @__PURE__ */ _jsx(Provider, {
67
- store: context.store,
68
- config: storeConfig,
69
- children: /* @__PURE__ */ _jsx(App, _object_spread({}, props))
70
- });
71
- };
72
- return getStateApp;
73
- },
74
- beforeRender: function beforeRender(context) {
75
- var pluginConfig = api.useRuntimeConfigContext();
76
- var config = merge(pluginConfig.state || {}, userConfig);
77
- storeConfig = getStoreConfig(config);
78
- if (isBrowser()) {
79
- var _window__SSR_DATA_data, _window__SSR_DATA, _window;
80
- 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) || {};
81
- }
82
- context.store = createStore(storeConfig);
83
- }
84
- };
85
- }
86
- };
87
- };
88
- var plugin_default = statePlugin;
89
- export * from "../plugins";
90
- export {
91
- plugin_default as default,
92
- statePlugin
93
- };
@@ -1,38 +0,0 @@
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
- if (stateConfig) {
16
- plugins.push({
17
- name: PLUGIN_IDENTIFIER,
18
- path: `@${metaName}/runtime/model`,
19
- config: typeof stateConfig === "boolean" ? {} : stateConfig
20
- });
21
- }
22
- return {
23
- entrypoint,
24
- plugins
25
- };
26
- });
27
- api.addRuntimeExports(() => {
28
- const { internalDirectory, metaName } = api.useAppContext();
29
- const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
30
- pluginsExportsUtils.addExport(`export { default as state } from '@${metaName}/runtime/model'`);
31
- });
32
- }
33
- });
34
- var cli_default = statePlugin;
35
- export {
36
- cli_default as default,
37
- statePlugin
38
- };
@@ -1,7 +0,0 @@
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
- };
@@ -1,13 +0,0 @@
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
- };
@@ -1,6 +0,0 @@
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
- };
@@ -1,69 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Provider } from "@modern-js-reduck/react";
3
- import { createStore } from "@modern-js-reduck/store";
4
- import { merge } from "@modern-js/runtime-utils/merge";
5
- import { useContext } from "react";
6
- import { isBrowser } from "../../common";
7
- import { RuntimeReactContext } from "../../core";
8
- import { autoActions, devtools, effects, immer } from "../plugins";
9
- const StatePluginHandleMap = {
10
- immer,
11
- effects,
12
- autoActions,
13
- devtools
14
- };
15
- const getStoreConfig = (config) => {
16
- const internalPlugins = [
17
- "immer",
18
- "effects",
19
- "autoActions",
20
- "devtools"
21
- ];
22
- const plugins = [];
23
- internalPlugins.filter((plugin) => config[plugin] !== false).forEach((plugin) => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
24
- const storeConfig = {};
25
- for (const [key, value] of Object.entries(config)) {
26
- if (!internalPlugins.includes(key)) {
27
- storeConfig[key] = value;
28
- }
29
- }
30
- storeConfig.plugins = plugins;
31
- return storeConfig;
32
- };
33
- const statePlugin = (userConfig = {}) => ({
34
- name: "@modern-js/plugin-state",
35
- setup: (api) => {
36
- let storeConfig;
37
- return {
38
- wrapRoot(App) {
39
- const getStateApp = (props) => {
40
- const context = useContext(RuntimeReactContext);
41
- return /* @__PURE__ */ _jsx(Provider, {
42
- store: context.store,
43
- config: storeConfig,
44
- children: /* @__PURE__ */ _jsx(App, {
45
- ...props
46
- })
47
- });
48
- };
49
- return getStateApp;
50
- },
51
- beforeRender(context) {
52
- const pluginConfig = api.useRuntimeConfigContext();
53
- const config = merge(pluginConfig.state || {}, userConfig);
54
- storeConfig = getStoreConfig(config);
55
- if (isBrowser()) {
56
- var _window__SSR_DATA_data, _window__SSR_DATA, _window;
57
- 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) || {};
58
- }
59
- context.store = createStore(storeConfig);
60
- }
61
- };
62
- }
63
- });
64
- var plugin_default = statePlugin;
65
- export * from "../plugins";
66
- export {
67
- plugin_default as default,
68
- statePlugin
69
- };
@@ -1,3 +0,0 @@
1
- import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
- export declare const statePlugin: () => CliPluginFuture<AppTools<'shared'>>;
3
- export default statePlugin;
@@ -1,3 +0,0 @@
1
- export { default as state } from './runtime';
2
- export { default } from './runtime';
3
- export * from './runtime';
@@ -1,4 +0,0 @@
1
- export { default as devtools } from '@modern-js-reduck/plugin-devtools';
2
- export declare const effects: () => (context: import("@modern-js-reduck/store/dist/types/types/plugin").PluginContext) => import("@modern-js-reduck/store/dist/types/types/plugin").PluginLifeCycle;
3
- export declare const immer: () => (context: import("@modern-js-reduck/store/dist/types/types/plugin").PluginContext) => import("@modern-js-reduck/store/dist/types/types/plugin").PluginLifeCycle;
4
- export declare const autoActions: () => (context: import("@modern-js-reduck/store/dist/types/types/plugin").PluginContext) => import("@modern-js-reduck/store/dist/types/types/plugin").PluginLifeCycle;
@@ -1,3 +0,0 @@
1
- export * from '@modern-js-reduck/react';
2
- export { default } from './plugin';
3
- export * from './plugin';
@@ -1,11 +0,0 @@
1
- import { type Model } from '@modern-js-reduck/store';
2
- import type { Plugin } from '../../core';
3
- type StatePluginType = 'immer' | 'effects' | 'autoActions' | 'devtools';
4
- type StateExtraType = {
5
- initialState: any;
6
- models: Array<Model>;
7
- };
8
- export type StateConfig = Partial<Record<StatePluginType, boolean> & StateExtraType>;
9
- export declare const statePlugin: (userConfig?: StateConfig) => Plugin;
10
- export default statePlugin;
11
- export * from '../plugins';
package/types/model.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import '@modern-js-reduck/plugin-auto-actions';
2
- import '@modern-js-reduck/plugin-devtools';
3
- import '@modern-js-reduck/plugin-effects';
4
- import '@modern-js-reduck/plugin-immutable';
5
-
6
- export { default } from '../dist/types/state';
7
- export * from '../dist/types/state';