@modern-js/plugin-state 2.65.5-alpha.2 → 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.
@@ -23,6 +23,7 @@ __export(cli_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(cli_exports);
25
25
  var import_utils = require("@modern-js/utils");
26
+ var import_types = require("./types");
26
27
  const PLUGIN_IDENTIFIER = "state";
27
28
  const statePlugin = () => ({
28
29
  name: "@modern-js/plugin-state",
@@ -19,9 +19,7 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var plugin_exports = {};
21
21
  __export(plugin_exports, {
22
- Provider: () => import_react.Provider,
23
22
  default: () => plugin_default,
24
- getStoreConfig: () => getStoreConfig,
25
23
  statePlugin: () => statePlugin
26
24
  });
27
25
  module.exports = __toCommonJS(plugin_exports);
@@ -30,6 +28,7 @@ var import_react = require("@modern-js-reduck/react");
30
28
  var import_store = require("@modern-js-reduck/store");
31
29
  var import_runtime = require("@modern-js/runtime");
32
30
  var import_merge = require("@modern-js/runtime-utils/merge");
31
+ var import_react2 = require("react");
33
32
  var import_plugins = require("../plugins");
34
33
  __reExport(plugin_exports, require("../plugins"), module.exports);
35
34
  const StatePluginHandleMap = {
@@ -63,7 +62,7 @@ const statePlugin = (userConfig = {}) => ({
63
62
  return {
64
63
  wrapRoot(App) {
65
64
  const getStateApp = (props) => {
66
- const context = (0, import_runtime.useRuntimeContext)();
65
+ const context = (0, import_react2.useContext)(import_runtime.RuntimeReactContext);
67
66
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Provider, {
68
67
  store: context.store,
69
68
  config: storeConfig,
@@ -90,8 +89,6 @@ const statePlugin = (userConfig = {}) => ({
90
89
  var plugin_default = statePlugin;
91
90
  // Annotate the CommonJS export names for ESM import in node:
92
91
  0 && (module.exports = {
93
- Provider,
94
- getStoreConfig,
95
92
  statePlugin,
96
93
  ...require("../plugins")
97
94
  });
@@ -1,5 +1,6 @@
1
1
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
2
  import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
3
+ import "./types";
3
4
  var PLUGIN_IDENTIFIER = "state";
4
5
  var statePlugin = function() {
5
6
  return {
@@ -3,8 +3,9 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  import { Provider } from "@modern-js-reduck/react";
5
5
  import { createStore } from "@modern-js-reduck/store";
6
- import { isBrowser, useRuntimeContext } from "@modern-js/runtime";
6
+ import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
7
7
  import { merge } from "@modern-js/runtime-utils/merge";
8
+ import { useContext } from "react";
8
9
  import { autoActions, devtools, effects, immer } from "../plugins";
9
10
  var StatePluginHandleMap = {
10
11
  immer,
@@ -60,7 +61,7 @@ var statePlugin = function() {
60
61
  return {
61
62
  wrapRoot: function wrapRoot(App) {
62
63
  var getStateApp = function(props) {
63
- var context = useRuntimeContext();
64
+ var context = useContext(RuntimeReactContext);
64
65
  return /* @__PURE__ */ _jsx(Provider, {
65
66
  store: context.store,
66
67
  config: storeConfig,
@@ -86,8 +87,6 @@ var statePlugin = function() {
86
87
  var plugin_default = statePlugin;
87
88
  export * from "../plugins";
88
89
  export {
89
- Provider,
90
90
  plugin_default as default,
91
- getStoreConfig,
92
91
  statePlugin
93
92
  };
@@ -1,4 +1,5 @@
1
1
  import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
2
+ import "./types";
2
3
  const PLUGIN_IDENTIFIER = "state";
3
4
  const statePlugin = () => ({
4
5
  name: "@modern-js/plugin-state",
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Provider } from "@modern-js-reduck/react";
3
3
  import { createStore } from "@modern-js-reduck/store";
4
- import { isBrowser, useRuntimeContext } from "@modern-js/runtime";
4
+ import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
5
5
  import { merge } from "@modern-js/runtime-utils/merge";
6
+ import { useContext } from "react";
6
7
  import { autoActions, devtools, effects, immer } from "../plugins";
7
8
  const StatePluginHandleMap = {
8
9
  immer,
@@ -35,7 +36,7 @@ const statePlugin = (userConfig = {}) => ({
35
36
  return {
36
37
  wrapRoot(App) {
37
38
  const getStateApp = (props) => {
38
- const context = useRuntimeContext();
39
+ const context = useContext(RuntimeReactContext);
39
40
  return /* @__PURE__ */ _jsx(Provider, {
40
41
  store: context.store,
41
42
  config: storeConfig,
@@ -62,8 +63,6 @@ const statePlugin = (userConfig = {}) => ({
62
63
  var plugin_default = statePlugin;
63
64
  export * from "../plugins";
64
65
  export {
65
- Provider,
66
66
  plugin_default as default,
67
- getStoreConfig,
68
67
  statePlugin
69
68
  };
@@ -1,3 +1,4 @@
1
1
  import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
+ import './types';
2
3
  export declare const statePlugin: () => CliPluginFuture<AppTools<"shared">>;
3
4
  export default statePlugin;
@@ -1,14 +1,11 @@
1
- import { Provider } from '@modern-js-reduck/react';
2
- import { type Model, type StoreConfig } from '@modern-js-reduck/store';
1
+ import { type Model } from '@modern-js-reduck/store';
3
2
  import type { Plugin } from '@modern-js/runtime';
4
- export { Provider };
5
3
  type StatePluginType = 'immer' | 'effects' | 'autoActions' | 'devtools';
6
4
  type StateExtraType = {
7
5
  initialState: any;
8
6
  models: Array<Model>;
9
7
  };
10
8
  export type StateConfig = Partial<Record<StatePluginType, boolean> & StateExtraType>;
11
- export declare const getStoreConfig: (config: StateConfig) => StoreConfig;
12
9
  export declare const statePlugin: (userConfig?: StateConfig) => Plugin;
13
10
  export default statePlugin;
14
11
  export * from '../plugins';
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.65.5-alpha.2",
18
+ "version": "2.67.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "main": "./dist/cjs/cli/index.js",
@@ -58,14 +58,14 @@
58
58
  "@modern-js-reduck/react": "^1.1.10",
59
59
  "@modern-js-reduck/store": "^1.1.10",
60
60
  "@swc/helpers": "0.5.13",
61
- "@modern-js/types": "2.65.4",
62
- "@modern-js/utils": "2.65.4",
63
- "@modern-js/runtime-utils": "2.65.4"
61
+ "@modern-js/types": "2.67.0",
62
+ "@modern-js/runtime-utils": "2.67.0",
63
+ "@modern-js/utils": "2.67.0"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "react": ">=17",
67
67
  "react-dom": ">=17",
68
- "@modern-js/runtime": "^2.65.4"
68
+ "@modern-js/runtime": "^2.67.0"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@testing-library/react": "^13.4.0",
@@ -78,10 +78,10 @@
78
78
  "react-dom": "^18.3.1",
79
79
  "ts-jest": "^29.1.0",
80
80
  "typescript": "^5",
81
- "@modern-js/app-tools": "2.65.4",
82
- "@scripts/build": "2.65.4",
83
- "@modern-js/runtime": "2.65.4",
84
- "@scripts/jest-config": "2.65.4"
81
+ "@modern-js/app-tools": "2.67.0",
82
+ "@modern-js/runtime": "2.67.0",
83
+ "@scripts/build": "2.66.0",
84
+ "@scripts/jest-config": "2.66.0"
85
85
  },
86
86
  "sideEffects": false,
87
87
  "publishConfig": {
package/types/index.d.ts CHANGED
@@ -1,9 +1,15 @@
1
+ import type { Store } from '@modern-js-reduck/store';
1
2
  import type { StateConfig } from '../dist/types';
2
3
  import '@modern-js-reduck/plugin-auto-actions';
3
4
  import '@modern-js-reduck/plugin-devtools';
4
5
  import '@modern-js-reduck/plugin-effects';
5
6
  import '@modern-js-reduck/plugin-immutable';
6
7
 
8
+ /**
9
+ * This type file defines the runtime types for the runtime plugin, which will be referenced in the user's project at `src/modern-app-env.d.ts`.
10
+ * The CLI type definitions for the runtime plugin are located in cli/types, which are used for type hints in modern.config.ts.
11
+ * cli/types cannot be defined in this types file because the types from `src/modern-app-env.d.ts` cannot be used in `modern.config.ts`.
12
+ */
7
13
  export { default } from '../dist/types/runtime';
8
14
  export * from '../dist/types/runtime';
9
15
 
@@ -19,9 +25,8 @@ declare module '@modern-js/runtime' {
19
25
  interface RuntimeConfig {
20
26
  state?: StateConfig;
21
27
  }
22
- }
23
- declare module '@modern-js/app-tools' {
24
- interface RuntimeUserConfig {
25
- state?: StateConfig | boolean;
28
+
29
+ interface TRuntimeContext {
30
+ store?: Store;
26
31
  }
27
32
  }