@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
@@ -0,0 +1,67 @@
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 { isBrowser, useRuntimeContext } from "@modern-js/runtime";
5
+ import { merge } from "@modern-js/runtime-utils/merge";
6
+ import { autoActions, devtools, effects, immer } from "../plugins";
7
+ const StatePluginHandleMap = {
8
+ immer,
9
+ effects,
10
+ autoActions,
11
+ devtools
12
+ };
13
+ const getStoreConfig = (config) => {
14
+ const internalPlugins = [
15
+ "immer",
16
+ "effects",
17
+ "autoActions",
18
+ "devtools"
19
+ ];
20
+ const plugins = [];
21
+ internalPlugins.filter((plugin) => config[plugin] !== false).forEach((plugin) => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
22
+ const storeConfig = {};
23
+ for (const [key, value] of Object.entries(config)) {
24
+ if (!internalPlugins.includes(key)) {
25
+ storeConfig[key] = value;
26
+ }
27
+ }
28
+ storeConfig.plugins = plugins;
29
+ return storeConfig;
30
+ };
31
+ const statePlugin = (userConfig = {}) => ({
32
+ name: "@modern-js/plugin-state",
33
+ setup: (api) => {
34
+ let storeConfig;
35
+ return {
36
+ wrapRoot(App) {
37
+ const getStateApp = (props) => {
38
+ const context = useRuntimeContext();
39
+ return /* @__PURE__ */ _jsx(Provider, {
40
+ store: context.store,
41
+ config: storeConfig,
42
+ children: /* @__PURE__ */ _jsx(App, {
43
+ ...props
44
+ })
45
+ });
46
+ };
47
+ return getStateApp;
48
+ },
49
+ beforeRender(context) {
50
+ const pluginConfig = api.useRuntimeConfigContext();
51
+ const config = merge(pluginConfig.state || {}, userConfig);
52
+ storeConfig = getStoreConfig(config);
53
+ if (isBrowser()) {
54
+ var _window__SSR_DATA_data, _window__SSR_DATA, _window;
55
+ 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) || {};
56
+ }
57
+ context.store = createStore(storeConfig);
58
+ }
59
+ };
60
+ }
61
+ });
62
+ var plugin_default = statePlugin;
63
+ export * from "../plugins";
64
+ export {
65
+ plugin_default as default,
66
+ statePlugin
67
+ };
@@ -1,5 +1,3 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
-
3
- declare const _default: () => CliPlugin;
4
-
5
- export default _default;
1
+ import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
+ export declare const statePlugin: () => CliPluginFuture<AppTools<"shared">>;
3
+ export default statePlugin;
@@ -0,0 +1,6 @@
1
+ import type { StateConfig } from '../runtime/plugin';
2
+ declare module '@modern-js/app-tools' {
3
+ interface RuntimeUserConfig {
4
+ state?: StateConfig | boolean;
5
+ }
6
+ }
@@ -0,0 +1,3 @@
1
+ export { default as state } from './runtime';
2
+ export { default } from './runtime';
3
+ export * from './runtime';
@@ -1,4 +1,4 @@
1
1
  export { default as devtools } from '@modern-js-reduck/plugin-devtools';
2
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
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;
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,4 +1,3 @@
1
1
  export * from '@modern-js-reduck/react';
2
- export { model, createStore } from '@modern-js-reduck/store';
3
2
  export { default } from './plugin';
4
- export * from './plugin';
3
+ export * from './plugin';
@@ -1,17 +1,11 @@
1
- import { createStore, Store } from '@modern-js-reduck/store';
2
- import type { Plugin } from '@modern-js/runtime-core';
3
- declare module '@modern-js/runtime-core' {
4
- interface RuntimeContext {
5
- store: Store;
6
- }
7
- interface TRuntimeContext {
8
- store: Store;
9
- }
10
- interface SSRData {
11
- storeState: any;
12
- }
13
- }
14
- export declare type StateConfig = Parameters<typeof createStore>[0];
15
- declare const state: (config: StateConfig) => Plugin;
16
- export default state;
17
- export * from '../plugins';
1
+ import { type Model } from '@modern-js-reduck/store';
2
+ import type { Plugin } from '@modern-js/runtime';
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/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@modern-js/plugin-state",
3
- "description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
3
+ "description": "A Progressive React Framework for modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
- "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
- "repository": "modern-js-dev/modern.js",
5
+ "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/web-infra-dev/modern.js",
9
+ "directory": "packages/runtime/plugin-router-v5"
10
+ },
7
11
  "license": "MIT",
8
12
  "keywords": [
9
13
  "react",
@@ -11,41 +15,32 @@
11
15
  "modern",
12
16
  "modern.js"
13
17
  ],
14
- "version": "1.2.10",
15
- "jsnext:source": "./src/runtime/index.tsx",
16
- "types": "./dist/types/runtime/index.d.ts",
17
- "main": "./dist/js/node/runtime/index.js",
18
- "module": "./dist/js/treeshaking/runtime/index.js",
19
- "jsnext:modern": "./dist/js/modern/runtime/index.js",
18
+ "version": "2.65.5-alpha.0",
19
+ "jsnext:source": "./src/index.ts",
20
+ "types": "./dist/types/cli/index.d.ts",
21
+ "main": "./dist/cjs/cli/index.js",
22
+ "module": "./dist/esm/index.js",
20
23
  "exports": {
21
24
  ".": {
22
- "node": {
23
- "jsnext:source": "./src/runtime/index.tsx",
24
- "import": "./dist/js/modern/runtime/index.js",
25
- "require": "./dist/js/node/runtime/index.js"
26
- },
27
- "default": "./dist/js/treeshaking/runtime/index.js"
25
+ "types": "./dist/types/cli/index.d.ts",
26
+ "jsnext:source": "./src/cli/index.ts",
27
+ "default": "./dist/cjs/cli/index.js"
28
+ },
29
+ "./runtime": {
30
+ "types": "./dist/types/runtime/index.d.ts",
31
+ "jsnext:source": "./src/runtime/index.ts",
32
+ "default": "./dist/esm/runtime/index.js"
28
33
  },
29
34
  "./cli": {
35
+ "types": "./dist/types/cli/index.d.ts",
30
36
  "jsnext:source": "./src/cli/index.ts",
31
- "default": "./dist/js/node/cli/index.js"
32
- },
33
- "./plugins": {
34
- "jsnext:source": "./src/plugins.ts",
35
- "node": {
36
- "import": "./dist/js/modern/plugins.js",
37
- "require": "./dist/js/node/plugins.js"
38
- },
39
- "default": "./dist/js/treeshaking/plugins.js"
37
+ "default": "./dist/cjs/cli/index.js"
40
38
  }
41
39
  },
42
40
  "typesVersions": {
43
41
  "*": {
44
42
  ".": [
45
- "./dist/types/runtime/index.d.ts"
46
- ],
47
- "plugins": [
48
- "./dist/types/plugins.d.ts"
43
+ "./dist/types/cli/index.d.ts"
49
44
  ],
50
45
  "cli": [
51
46
  "./dist/types/cli/index.d.ts"
@@ -56,69 +51,47 @@
56
51
  }
57
52
  },
58
53
  "dependencies": {
59
- "@babel/runtime": "^7.18.0",
60
- "@modern-js-reduck/plugin-auto-actions": "^1.0.2",
61
- "@modern-js-reduck/plugin-devtools": "^1.0.3",
62
- "@modern-js-reduck/plugin-effects": "^1.0.2",
63
- "@modern-js-reduck/plugin-immutable": "^1.0.1",
64
- "@modern-js-reduck/react": "^1.0.1",
65
- "@modern-js-reduck/store": "^1.0.3",
66
- "@types/redux-logger": "^3.0.9",
67
- "hoist-non-react-statics": "^3.3.2",
68
- "redux-logger": "^3.0.6"
54
+ "@modern-js-reduck/plugin-auto-actions": "^1.1.10",
55
+ "@modern-js-reduck/plugin-devtools": "^1.1.10",
56
+ "@modern-js-reduck/plugin-effects": "^1.1.10",
57
+ "@modern-js-reduck/plugin-immutable": "^1.1.10",
58
+ "@modern-js-reduck/react": "^1.1.10",
59
+ "@modern-js-reduck/store": "^1.1.10",
60
+ "@swc/helpers": "0.5.13",
61
+ "@modern-js/types": "2.65.4",
62
+ "@modern-js/runtime-utils": "2.65.4",
63
+ "@modern-js/utils": "2.65.4"
64
+ },
65
+ "peerDependencies": {
66
+ "react": ">=17",
67
+ "react-dom": ">=17",
68
+ "@modern-js/runtime": "^2.65.4"
69
69
  },
70
70
  "devDependencies": {
71
- "@modern-js/core": "1.11.2",
72
- "@modern-js/plugin": "1.3.6",
73
- "@modern-js/runtime-core": "1.4.9",
74
- "@modern-js/utils": "1.7.6",
75
- "@scripts/build": "0.0.0",
76
- "@scripts/jest-config": "0.0.0",
77
- "@types/hoist-non-react-statics": "^3.3.1",
78
- "@types/jest": "^27",
71
+ "@testing-library/react": "^13.4.0",
72
+ "@types/react": "^18.3.11",
73
+ "@types/invariant": "^2.2.30",
74
+ "@types/jest": "^29",
79
75
  "@types/node": "^14",
80
- "@types/react": "^17",
81
- "@types/react-dom": "^17",
82
- "jest": "^27",
83
- "react": "^17.0.2",
84
- "typescript": "^4"
76
+ "jest": "^29",
77
+ "react": "^18.3.1",
78
+ "react-dom": "^18.3.1",
79
+ "ts-jest": "^29.1.0",
80
+ "typescript": "^5",
81
+ "@modern-js/runtime": "2.65.4",
82
+ "@modern-js/app-tools": "2.65.4",
83
+ "@scripts/build": "2.65.4",
84
+ "@scripts/jest-config": "2.65.4"
85
85
  },
86
86
  "sideEffects": false,
87
- "peerDependencies": {
88
- "react": "^17.0.2"
89
- },
90
- "modernConfig": {},
91
87
  "publishConfig": {
92
88
  "registry": "https://registry.npmjs.org/",
93
89
  "access": "public"
94
90
  },
95
- "wireit": {
96
- "build": {
97
- "command": "modern build",
98
- "files": [
99
- "src/**/*",
100
- "tsconfig.json",
101
- "package.json"
102
- ],
103
- "output": [
104
- "dist/**/*"
105
- ]
106
- },
107
- "test": {
108
- "command": "jest --passWithNoTests",
109
- "files": [
110
- "src/**/*",
111
- "tsconfig.json",
112
- "package.json",
113
- "tests/**/*"
114
- ],
115
- "output": []
116
- }
117
- },
118
91
  "scripts": {
119
- "new": "modern new",
120
- "build": "wireit",
121
- "test": "wireit"
122
- },
123
- "readme": "\n<p align=\"center\">\n <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>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> 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.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
92
+ "dev": "modern-lib build --watch",
93
+ "new": "modern-lib new",
94
+ "build": "modern-lib build",
95
+ "test": "jest --passWithNoTests"
96
+ }
124
97
  }
@@ -0,0 +1,27 @@
1
+ import type { StateConfig } from '../dist/types';
2
+ import '@modern-js-reduck/plugin-auto-actions';
3
+ import '@modern-js-reduck/plugin-devtools';
4
+ import '@modern-js-reduck/plugin-effects';
5
+ import '@modern-js-reduck/plugin-immutable';
6
+
7
+ export { default } from '../dist/types/runtime';
8
+ export * from '../dist/types/runtime';
9
+
10
+ declare module '@modern-js/runtime/model' {
11
+ export * from '../dist/types/runtime';
12
+ }
13
+
14
+ declare module '@modern-js/runtime' {
15
+ interface AppConfig {
16
+ state?: StateConfig;
17
+ }
18
+
19
+ interface RuntimeConfig {
20
+ state?: StateConfig;
21
+ }
22
+ }
23
+ declare module '@modern-js/app-tools' {
24
+ interface RuntimeUserConfig {
25
+ state?: StateConfig | boolean;
26
+ }
27
+ }