@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.
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 -413
  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
@@ -1,127 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
- var _utils = require("@modern-js/utils");
11
-
12
- require("../types");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const PLUGIN_IDENTIFIER = 'state';
17
-
18
- var _default = () => ({
19
- name: '@modern-js/plugin-state',
20
- required: ['@modern-js/runtime'],
21
- setup: api => {
22
- const stateConfigMap = new Map();
23
- let pluginsExportsUtils;
24
-
25
- const stateModulePath = _path.default.resolve(__dirname, '../../../../');
26
-
27
- return {
28
- config() {
29
- const appContext = api.useAppContext();
30
- pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'plugins');
31
- return {
32
- source: {
33
- alias: {
34
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
35
- }
36
- }
37
- };
38
- },
39
-
40
- modifyEntryImports({
41
- entrypoint,
42
- imports
43
- }) {
44
- var _getEntryOptions;
45
-
46
- const {
47
- entryName
48
- } = entrypoint;
49
- const userConfig = api.useResolvedConfigContext();
50
- const {
51
- packageName
52
- } = api.useAppContext();
53
- const stateConfig = (_getEntryOptions = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
54
- stateConfigMap.set(entryName, stateConfig);
55
-
56
- const getEnabledPlugins = () => {
57
- const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
58
- return internalPlugins.filter(name => stateConfig[name] !== false);
59
- };
60
-
61
- if (stateConfig) {
62
- imports.push({
63
- value: '@modern-js/runtime/plugins',
64
- specifiers: [{
65
- imported: PLUGIN_IDENTIFIER
66
- }]
67
- });
68
- imports.push({
69
- value: '@modern-js/runtime/model',
70
- specifiers: getEnabledPlugins().map(imported => ({
71
- imported
72
- })),
73
- initialize: `
74
- const createStatePlugins = (config) => {
75
- const plugins = [];
76
-
77
- ${getEnabledPlugins().map(name => `
78
- plugins.push(${name}(config['${name}']));
79
- `).join('\n')}
80
-
81
- return plugins;
82
- }
83
- `
84
- });
85
- }
86
-
87
- return {
88
- entrypoint,
89
- imports
90
- };
91
- },
92
-
93
- modifyEntryRuntimePlugins({
94
- entrypoint,
95
- plugins
96
- }) {
97
- const stateOptions = stateConfigMap.get(entrypoint.entryName);
98
-
99
- if (stateOptions) {
100
- const isBoolean = typeof stateOptions === 'boolean';
101
- let options = isBoolean ? '{}' : JSON.stringify(stateOptions);
102
- options = `${options.substr(0, options.length - 1)}${isBoolean ? '' : ','}plugins: createStatePlugins(${JSON.stringify(stateConfigMap.get(entrypoint.entryName))})}`;
103
- plugins.push({
104
- name: PLUGIN_IDENTIFIER,
105
- options
106
- });
107
- }
108
-
109
- return {
110
- entrypoint,
111
- plugins
112
- };
113
- },
114
-
115
- validateSchema() {
116
- return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-state'];
117
- },
118
-
119
- addRuntimeExports() {
120
- pluginsExportsUtils.addExport(`export { default as state } from '${stateModulePath}'`);
121
- }
122
-
123
- };
124
- }
125
- });
126
-
127
- exports.default = _default;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.autoActions = void 0;
7
- Object.defineProperty(exports, "devtools", {
8
- enumerable: true,
9
- get: function () {
10
- return _pluginDevtools.default;
11
- }
12
- });
13
- exports.immer = exports.effects = void 0;
14
-
15
- var _pluginEffects = require("@modern-js-reduck/plugin-effects");
16
-
17
- var _pluginAutoActions = _interopRequireDefault(require("@modern-js-reduck/plugin-auto-actions"));
18
-
19
- var _pluginImmutable = _interopRequireDefault(require("@modern-js-reduck/plugin-immutable"));
20
-
21
- var _pluginDevtools = _interopRequireDefault(require("@modern-js-reduck/plugin-devtools"));
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
25
- const effects = () => _pluginEffects.plugin;
26
-
27
- exports.effects = effects;
28
-
29
- const immer = () => _pluginImmutable.default;
30
-
31
- exports.immer = immer;
32
-
33
- const autoActions = () => _pluginAutoActions.default;
34
-
35
- exports.autoActions = autoActions;
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- model: true,
8
- createStore: true
9
- };
10
- Object.defineProperty(exports, "createStore", {
11
- enumerable: true,
12
- get: function () {
13
- return _store.createStore;
14
- }
15
- });
16
- Object.defineProperty(exports, "default", {
17
- enumerable: true,
18
- get: function () {
19
- return _plugin.default;
20
- }
21
- });
22
- Object.defineProperty(exports, "model", {
23
- enumerable: true,
24
- get: function () {
25
- return _store.model;
26
- }
27
- });
28
-
29
- var _react = require("@modern-js-reduck/react");
30
-
31
- Object.keys(_react).forEach(function (key) {
32
- if (key === "default" || key === "__esModule") return;
33
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
34
- if (key in exports && exports[key] === _react[key]) return;
35
- Object.defineProperty(exports, key, {
36
- enumerable: true,
37
- get: function () {
38
- return _react[key];
39
- }
40
- });
41
- });
42
-
43
- var _store = require("@modern-js-reduck/store");
44
-
45
- var _plugin = _interopRequireWildcard(require("./plugin"));
46
-
47
- Object.keys(_plugin).forEach(function (key) {
48
- if (key === "default" || key === "__esModule") return;
49
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
50
- if (key in exports && exports[key] === _plugin[key]) return;
51
- Object.defineProperty(exports, key, {
52
- enumerable: true,
53
- get: function () {
54
- return _plugin[key];
55
- }
56
- });
57
- });
58
-
59
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
60
-
61
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -1,99 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {};
7
- exports.default = void 0;
8
-
9
- var _react = require("react");
10
-
11
- var _runtimeCore = require("@modern-js/runtime-core");
12
-
13
- var _store = require("@modern-js-reduck/store");
14
-
15
- var _react2 = require("@modern-js-reduck/react");
16
-
17
- var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
18
-
19
- var _jsxRuntime = require("react/jsx-runtime");
20
-
21
- var _plugins = require("../plugins");
22
-
23
- Object.keys(_plugins).forEach(function (key) {
24
- if (key === "default" || key === "__esModule") return;
25
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
- if (key in exports && exports[key] === _plugins[key]) return;
27
- Object.defineProperty(exports, key, {
28
- enumerable: true,
29
- get: function () {
30
- return _plugins[key];
31
- }
32
- });
33
- });
34
-
35
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
-
37
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
38
-
39
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
40
-
41
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
42
-
43
- const state = config => ({
44
- name: '@modern-js/plugin-state',
45
- setup: () => {
46
- return {
47
- hoc({
48
- App
49
- }, next) {
50
- const getStateApp = props => {
51
- // eslint-disable-next-line react-hooks/rules-of-hooks
52
- const context = (0, _react.useContext)(_runtimeCore.RuntimeReactContext);
53
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Provider, {
54
- store: context.store,
55
- config: config,
56
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
57
- });
58
- };
59
-
60
- return next({
61
- App: (0, _hoistNonReactStatics.default)(getStateApp, App)
62
- });
63
- },
64
-
65
- init({
66
- context
67
- }, next) {
68
- const storeConfig = config || {};
69
-
70
- if (typeof window !== 'undefined') {
71
- var _window, _window$_SSR_DATA, _window$_SSR_DATA$dat;
72
-
73
- 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$dat = _window$_SSR_DATA.data) === null || _window$_SSR_DATA$dat === void 0 ? void 0 : _window$_SSR_DATA$dat.storeState) || {};
74
- }
75
-
76
- context.store = (0, _store.createStore)(storeConfig);
77
- next({
78
- context
79
- });
80
- },
81
-
82
- pickContext({
83
- context,
84
- pickedContext
85
- }, next) {
86
- return next({
87
- context,
88
- pickedContext: _objectSpread(_objectSpread({}, pickedContext), {}, {
89
- store: context.store
90
- })
91
- });
92
- }
93
-
94
- };
95
- }
96
- });
97
-
98
- var _default = state;
99
- exports.default = _default;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,100 +0,0 @@
1
- import path from 'path';
2
- import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
3
- import "../types";
4
- var PLUGIN_IDENTIFIER = 'state';
5
- export default (function () {
6
- return {
7
- name: '@modern-js/plugin-state',
8
- required: ['@modern-js/runtime'],
9
- setup: function setup(api) {
10
- var stateConfigMap = new Map();
11
- var pluginsExportsUtils;
12
- var stateModulePath = path.resolve(__dirname, '../../../../');
13
- return {
14
- config: function config() {
15
- var appContext = api.useAppContext();
16
- pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'plugins');
17
- return {
18
- source: {
19
- alias: {
20
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
21
- }
22
- }
23
- };
24
- },
25
- modifyEntryImports: function modifyEntryImports(_ref) {
26
- var _getEntryOptions;
27
-
28
- var entrypoint = _ref.entrypoint,
29
- imports = _ref.imports;
30
- var entryName = entrypoint.entryName;
31
- var userConfig = api.useResolvedConfigContext();
32
-
33
- var _api$useAppContext = api.useAppContext(),
34
- packageName = _api$useAppContext.packageName;
35
-
36
- var stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
37
- stateConfigMap.set(entryName, stateConfig);
38
-
39
- var getEnabledPlugins = function getEnabledPlugins() {
40
- var internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
41
- return internalPlugins.filter(function (name) {
42
- return stateConfig[name] !== false;
43
- });
44
- };
45
-
46
- if (stateConfig) {
47
- imports.push({
48
- value: '@modern-js/runtime/plugins',
49
- specifiers: [{
50
- imported: PLUGIN_IDENTIFIER
51
- }]
52
- });
53
- imports.push({
54
- value: '@modern-js/runtime/model',
55
- specifiers: getEnabledPlugins().map(function (imported) {
56
- return {
57
- imported: imported
58
- };
59
- }),
60
- initialize: "\n const createStatePlugins = (config) => {\n const plugins = [];\n\n ".concat(getEnabledPlugins().map(function (name) {
61
- return "\n plugins.push(".concat(name, "(config['").concat(name, "']));\n ");
62
- }).join('\n'), "\n\n return plugins;\n }\n ")
63
- });
64
- }
65
-
66
- return {
67
- entrypoint: entrypoint,
68
- imports: imports
69
- };
70
- },
71
- modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref2) {
72
- var entrypoint = _ref2.entrypoint,
73
- plugins = _ref2.plugins;
74
- var stateOptions = stateConfigMap.get(entrypoint.entryName);
75
-
76
- if (stateOptions) {
77
- var isBoolean = typeof stateOptions === 'boolean';
78
- var options = isBoolean ? '{}' : JSON.stringify(stateOptions);
79
- options = "".concat(options.substr(0, options.length - 1)).concat(isBoolean ? '' : ',', "plugins: createStatePlugins(").concat(JSON.stringify(stateConfigMap.get(entrypoint.entryName)), ")}");
80
- plugins.push({
81
- name: PLUGIN_IDENTIFIER,
82
- options: options
83
- });
84
- }
85
-
86
- return {
87
- entrypoint: entrypoint,
88
- plugins: plugins
89
- };
90
- },
91
- validateSchema: function validateSchema() {
92
- return PLUGIN_SCHEMAS['@modern-js/plugin-state'];
93
- },
94
- addRuntimeExports: function addRuntimeExports() {
95
- pluginsExportsUtils.addExport("export { default as state } from '".concat(stateModulePath, "'"));
96
- }
97
- };
98
- }
99
- };
100
- });
@@ -1,13 +0,0 @@
1
- import { plugin as effectsPlugin } from '@modern-js-reduck/plugin-effects';
2
- import autoActionsPlugin from '@modern-js-reduck/plugin-auto-actions';
3
- import immerPlugin from '@modern-js-reduck/plugin-immutable';
4
- export { default as devtools } from '@modern-js-reduck/plugin-devtools';
5
- export var effects = function effects() {
6
- return effectsPlugin;
7
- };
8
- export var immer = function immer() {
9
- return immerPlugin;
10
- };
11
- export var autoActions = function autoActions() {
12
- return autoActionsPlugin;
13
- };
@@ -1,4 +0,0 @@
1
- export * from '@modern-js-reduck/react';
2
- export { model, createStore } from '@modern-js-reduck/store';
3
- export { default } from "./plugin";
4
- export * from "./plugin";
@@ -1,62 +0,0 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import { useContext } from 'react';
3
- import { RuntimeReactContext } from '@modern-js/runtime-core';
4
- import { createStore } from '@modern-js-reduck/store';
5
- import { Provider } from '@modern-js-reduck/react';
6
- import hoistNonReactStatics from 'hoist-non-react-statics';
7
- import { jsx as _jsx } from "react/jsx-runtime";
8
-
9
- var state = function state(config) {
10
- return {
11
- name: '@modern-js/plugin-state',
12
- setup: function setup() {
13
- return {
14
- hoc: function hoc(_ref, next) {
15
- var App = _ref.App;
16
-
17
- var getStateApp = function getStateApp(props) {
18
- // eslint-disable-next-line react-hooks/rules-of-hooks
19
- var context = useContext(RuntimeReactContext);
20
- return /*#__PURE__*/_jsx(Provider, {
21
- store: context.store,
22
- config: config,
23
- children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
24
- });
25
- };
26
-
27
- return next({
28
- App: hoistNonReactStatics(getStateApp, App)
29
- });
30
- },
31
- init: function init(_ref2, next) {
32
- var context = _ref2.context;
33
- var storeConfig = config || {};
34
-
35
- if (typeof window !== 'undefined') {
36
- var _window, _window$_SSR_DATA, _window$_SSR_DATA$dat;
37
-
38
- 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$dat = _window$_SSR_DATA.data) === null || _window$_SSR_DATA$dat === void 0 ? void 0 : _window$_SSR_DATA$dat.storeState) || {};
39
- }
40
-
41
- context.store = createStore(storeConfig);
42
- next({
43
- context: context
44
- });
45
- },
46
- pickContext: function pickContext(_ref3, next) {
47
- var context = _ref3.context,
48
- pickedContext = _ref3.pickedContext;
49
- return next({
50
- context: context,
51
- pickedContext: _objectSpread(_objectSpread({}, pickedContext), {}, {
52
- store: context.store
53
- })
54
- });
55
- }
56
- };
57
- }
58
- };
59
- };
60
-
61
- export default state;
62
- export * from "../plugins";
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import { createStore } from '@modern-js-reduck/store';
2
- import { ReduxLoggerOptions } from 'redux-logger';
3
- export declare type PluginOptions = Parameters<typeof createStore>[0] & {
4
- /**
5
- * If it's false, the logger will be disabled.
6
- * If it's a object, it means options will pass to createLogger function
7
- */
8
- logger?: false | ReduxLoggerOptions;
9
- effects?: any;
10
- /**
11
- * Default: false
12
- * When it's true, will remove immer plugin
13
- */
14
-
15
- disableImmer?: boolean;
16
- devtools?: any;
17
- };
package/type.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /// <reference types="@modern-js-reduck/plugin-auto-actions" />
2
- /// <reference types="@modern-js-reduck/plugin-devtools" />
3
- /// <reference types="@modern-js-reduck/plugin-effects" />
4
- /// <reference types="@modern-js-reduck/plugin-immutable" />