@modern-js/plugin-state 1.2.9 → 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.
- 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 +93 -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 +91 -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 +67 -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 +11 -17
- package/package.json +56 -83
- package/types/index.d.ts +27 -0
- package/CHANGELOG.md +0 -413
- 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
|
@@ -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 {
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
package/dist/types/plugins.d.ts
CHANGED
|
@@ -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,17 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Plugin } from '@modern-js/runtime
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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": "
|
|
3
|
+
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
|
-
"bugs": "https://github.com/
|
|
6
|
-
"repository":
|
|
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": "
|
|
15
|
-
"jsnext:source": "./src/
|
|
16
|
-
"types": "./dist/types/
|
|
17
|
-
"main": "./dist/
|
|
18
|
-
"module": "./dist/
|
|
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
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
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/
|
|
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/
|
|
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
|
-
"@
|
|
60
|
-
"@modern-js-reduck/plugin-
|
|
61
|
-
"@modern-js-reduck/plugin-
|
|
62
|
-
"@modern-js-reduck/plugin-
|
|
63
|
-
"@modern-js-reduck/
|
|
64
|
-
"@modern-js-reduck/
|
|
65
|
-
"@
|
|
66
|
-
"@types
|
|
67
|
-
"
|
|
68
|
-
"
|
|
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
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"@
|
|
74
|
-
"@
|
|
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
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"typescript": "^
|
|
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
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
|
|
123
|
-
|
|
92
|
+
"dev": "modern-lib build --watch",
|
|
93
|
+
"new": "modern-lib new",
|
|
94
|
+
"build": "modern-lib build",
|
|
95
|
+
"test": "jest --passWithNoTests"
|
|
96
|
+
}
|
|
124
97
|
}
|
package/types/index.d.ts
ADDED
|
@@ -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
|
+
}
|