react-store-input 0.2.6 → 0.5.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 (44) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/README.md +211 -199
  3. package/dist/index.d.mts +127 -11
  4. package/dist/index.d.ts +127 -11
  5. package/dist/index.js +542 -280
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +529 -272
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/text-editor.d.mts +11 -0
  10. package/dist/text-editor.d.ts +11 -0
  11. package/dist/text-editor.js +203 -0
  12. package/dist/text-editor.js.map +1 -0
  13. package/dist/text-editor.mjs +178 -0
  14. package/dist/text-editor.mjs.map +1 -0
  15. package/package.json +78 -18
  16. package/dist/create_render.d.mts +0 -9
  17. package/dist/create_render.d.ts +0 -9
  18. package/dist/create_render.js +0 -51
  19. package/dist/create_render.mjs +0 -25
  20. package/dist/text_editor.d.mts +0 -13
  21. package/dist/text_editor.d.ts +0 -13
  22. package/dist/text_editor.js +0 -135
  23. package/dist/text_editor.mjs +0 -112
  24. package/dist/use_form_store.d.mts +0 -16
  25. package/dist/use_form_store.d.ts +0 -16
  26. package/dist/use_form_store.js +0 -365
  27. package/dist/use_form_store.mjs +0 -340
  28. package/dist/use_store_component.d.mts +0 -23
  29. package/dist/use_store_component.d.ts +0 -23
  30. package/dist/use_store_component.js +0 -337
  31. package/dist/use_store_component.mjs +0 -311
  32. package/dist/use_store_controller.d.mts +0 -11
  33. package/dist/use_store_controller.d.ts +0 -11
  34. package/dist/use_store_controller.js +0 -57
  35. package/dist/use_store_controller.mjs +0 -32
  36. package/dist/use_store_input.d.mts +0 -22
  37. package/dist/use_store_input.d.ts +0 -22
  38. package/dist/use_store_input.js +0 -151
  39. package/dist/use_store_input.mjs +0 -126
  40. package/dist/use_store_input_with_name.d.mts +0 -17
  41. package/dist/use_store_input_with_name.d.ts +0 -17
  42. package/dist/use_store_input_with_name.js +0 -177
  43. package/dist/use_store_input_with_name.mjs +0 -150
  44. package/tsup.config.ts +0 -9
package/package.json CHANGED
@@ -1,47 +1,107 @@
1
1
  {
2
2
  "name": "react-store-input",
3
- "version": "0.2.6",
3
+ "version": "0.5.0",
4
+ "description": "Typed React form inputs backed by a small immutable store",
5
+ "keywords": [
6
+ "react",
7
+ "form",
8
+ "input",
9
+ "state-management",
10
+ "typescript"
11
+ ],
12
+ "author": "gawonsoft",
13
+ "license": "MIT",
14
+ "type": "commonjs",
15
+ "files": [
16
+ "dist",
17
+ "CHANGELOG.md",
18
+ "LICENSE",
19
+ "README.md"
20
+ ],
4
21
  "types": "./dist/index.d.ts",
5
- "main": "./dist/index.mjs",
6
- "module": "./dist/index.js",
22
+ "main": "./dist/index.js",
23
+ "module": "./dist/index.mjs",
7
24
  "sideEffects": false,
8
25
  "exports": {
9
26
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
27
+ "import": {
28
+ "types": "./dist/index.d.mts",
29
+ "default": "./dist/index.mjs"
30
+ },
31
+ "require": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ }
35
+ },
36
+ "./text-editor": {
37
+ "import": {
38
+ "types": "./dist/text-editor.d.mts",
39
+ "default": "./dist/text-editor.mjs"
40
+ },
41
+ "require": {
42
+ "types": "./dist/text-editor.d.ts",
43
+ "default": "./dist/text-editor.js"
44
+ }
13
45
  }
14
46
  },
15
47
  "scripts": {
16
- "build": "NODE_OPTIONS='--max-old-space-size=16384' tsup",
17
- "dev": "tsup --watch"
48
+ "build": "tsup",
49
+ "dev": "tsup --watch",
50
+ "lint": "eslint src",
51
+ "typecheck": "tsc --noEmit",
52
+ "test:types": "tsc -p tests/tsconfig.json",
53
+ "test:runtime": "node --test tests/runtime/binding.test.cjs tests/runtime/input.test.cjs tests/runtime/reset.test.cjs",
54
+ "test:package": "node scripts/package-smoke.cjs",
55
+ "test:example": "npm --prefix example run lint && npm --prefix example run build",
56
+ "check": "npm run lint && npm run typecheck && npm run build && npm run test:types && npm run test:runtime && npm run test:package && npm run test:example",
57
+ "test": "npm run check",
58
+ "prepack": "npm run build",
59
+ "prepublishOnly": "npm run check"
18
60
  },
19
61
  "repository": {
20
62
  "type": "git",
21
63
  "url": "git+https://github.com/gawonsoft/react-store-input.git"
22
64
  },
23
- "author": "",
24
- "license": "MIT",
25
65
  "bugs": {
26
66
  "url": "https://github.com/gawonsoft/react-store-input/issues"
27
67
  },
28
68
  "homepage": "https://github.com/gawonsoft/react-store-input#readme",
29
- "description": "",
30
69
  "devDependencies": {
70
+ "@eslint/js": "^9.39.5",
31
71
  "@types/node": "^24.10.1",
32
72
  "@types/react": "^18.3.1 || ^19.2.1",
33
73
  "@types/react-dom": "^18.3.1 || ^19.2.1",
74
+ "eslint": "^9.39.5",
75
+ "eslint-plugin-react-hooks": "^7.1.1",
76
+ "gw-react-text-editor": "^0.1.6",
77
+ "jsdom": "^24.1.3",
78
+ "react": "^19.2.8",
79
+ "react-dom": "^19.2.8",
34
80
  "tsup": "^8.5.1",
35
- "typescript": "^5.7.3"
81
+ "typescript": "^5.7.3",
82
+ "typescript-eslint": "^8.65.0"
36
83
  },
37
84
  "peerDependencies": {
38
- "react": "^18.3.1 || ^19.2.1",
39
- "react-dom": "^18.3.1 || ^19.2.1"
85
+ "gw-react-text-editor": "^0.1.6",
86
+ "react": ">=18.0.0 <20.0.0",
87
+ "react-dom": ">=18.0.0 <20.0.0"
88
+ },
89
+ "peerDependenciesMeta": {
90
+ "gw-react-text-editor": {
91
+ "optional": true
92
+ }
40
93
  },
41
94
  "dependencies": {
42
- "date-fns": "^4.1.0",
43
- "gw-react-text-editor": "^0.1.4",
44
- "gw-store": "^0.1.1",
45
- "immer": "^11.1.3"
95
+ "gw-result": "0.3.0",
96
+ "gw-store": "0.2.0",
97
+ "immer": "^11.1.4"
98
+ },
99
+ "engines": {
100
+ "node": ">=18.0.0"
101
+ },
102
+ "publishConfig": {
103
+ "access": "public",
104
+ "provenance": true,
105
+ "registry": "https://registry.npmjs.org/"
46
106
  }
47
107
  }
@@ -1,9 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { Store } from 'gw-store';
3
- import { ReactNode } from 'react';
4
-
5
- type CreateRender<TState> = (selector: (state: TState) => ReactNode, compare?: (a: TState, b: TState) => boolean) => ReactNode;
6
- declare function createRender<TState>(store: Store<TState>, selector: (state: TState) => ReactNode, compare?: (a: TState, b: TState) => boolean): react_jsx_runtime.JSX.Element;
7
- declare function createRenderWithStore<TState>(store: Store<TState>): CreateRender<TState>;
8
-
9
- export { type CreateRender, createRender, createRenderWithStore };
@@ -1,9 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { Store } from 'gw-store';
3
- import { ReactNode } from 'react';
4
-
5
- type CreateRender<TState> = (selector: (state: TState) => ReactNode, compare?: (a: TState, b: TState) => boolean) => ReactNode;
6
- declare function createRender<TState>(store: Store<TState>, selector: (state: TState) => ReactNode, compare?: (a: TState, b: TState) => boolean): react_jsx_runtime.JSX.Element;
7
- declare function createRenderWithStore<TState>(store: Store<TState>): CreateRender<TState>;
8
-
9
- export { type CreateRender, createRender, createRenderWithStore };
@@ -1,51 +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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/create_render.tsx
21
- var create_render_exports = {};
22
- __export(create_render_exports, {
23
- createRender: () => createRender,
24
- createRenderWithStore: () => createRenderWithStore
25
- });
26
- module.exports = __toCommonJS(create_render_exports);
27
- var import_gw_store = require("gw-store");
28
- var import_jsx_runtime = require("react/jsx-runtime");
29
- function createRender(store, selector, compare) {
30
- function Component() {
31
- const result = (0, import_gw_store.useSelector)(store, (state) => state, compare);
32
- const content = selector(result);
33
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: content });
34
- }
35
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
36
- }
37
- function createRenderWithStore(store) {
38
- return function createRender2(selector, compare) {
39
- function Component() {
40
- const result = (0, import_gw_store.useSelector)(store, (state) => state, compare);
41
- const content = selector(result);
42
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: content });
43
- }
44
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
45
- };
46
- }
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- createRender,
50
- createRenderWithStore
51
- });
@@ -1,25 +0,0 @@
1
- // src/create_render.tsx
2
- import { useSelector } from "gw-store";
3
- import { Fragment, jsx } from "react/jsx-runtime";
4
- function createRender(store, selector, compare) {
5
- function Component() {
6
- const result = useSelector(store, (state) => state, compare);
7
- const content = selector(result);
8
- return /* @__PURE__ */ jsx(Fragment, { children: content });
9
- }
10
- return /* @__PURE__ */ jsx(Component, {});
11
- }
12
- function createRenderWithStore(store) {
13
- return function createRender2(selector, compare) {
14
- function Component() {
15
- const result = useSelector(store, (state) => state, compare);
16
- const content = selector(result);
17
- return /* @__PURE__ */ jsx(Fragment, { children: content });
18
- }
19
- return /* @__PURE__ */ jsx(Component, {});
20
- };
21
- }
22
- export {
23
- createRender,
24
- createRenderWithStore
25
- };
@@ -1,13 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { TextEditorProps as TextEditorProps$1 } from 'gw-react-text-editor';
3
- import { Store } from 'gw-store';
4
-
5
- type TextEditorProps<TState> = {
6
- store: Store<TState>;
7
- name?: keyof TState;
8
- getter?: (state: TState) => string;
9
- setter?: (state: TState, value: string) => void;
10
- } & TextEditorProps$1;
11
- declare function TextEditor<TState>({ store, name, getter, setter, defaultValue, ref, ...props }: TextEditorProps<TState>): react_jsx_runtime.JSX.Element;
12
-
13
- export { TextEditor, type TextEditorProps };
@@ -1,13 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { TextEditorProps as TextEditorProps$1 } from 'gw-react-text-editor';
3
- import { Store } from 'gw-store';
4
-
5
- type TextEditorProps<TState> = {
6
- store: Store<TState>;
7
- name?: keyof TState;
8
- getter?: (state: TState) => string;
9
- setter?: (state: TState, value: string) => void;
10
- } & TextEditorProps$1;
11
- declare function TextEditor<TState>({ store, name, getter, setter, defaultValue, ref, ...props }: TextEditorProps<TState>): react_jsx_runtime.JSX.Element;
12
-
13
- export { TextEditor, type TextEditorProps };
@@ -1,135 +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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/text_editor.tsx
21
- var text_editor_exports = {};
22
- __export(text_editor_exports, {
23
- TextEditor: () => TextEditor
24
- });
25
- module.exports = __toCommonJS(text_editor_exports);
26
- var import_gw_react_text_editor = require("gw-react-text-editor");
27
- var import_react2 = require("react");
28
-
29
- // src/use_store_controller.tsx
30
- var import_react = require("react");
31
- function useStoreController(store, props) {
32
- const dispatchKey = (0, import_react.useId)();
33
- (0, import_react.useEffect)(() => {
34
- const unsub = store.subscribe((state, key) => {
35
- if (key === dispatchKey) {
36
- return;
37
- }
38
- props.onSubscribe(state);
39
- });
40
- return () => {
41
- unsub();
42
- };
43
- }, []);
44
- const dispatch = () => {
45
- store.dispatch(
46
- (state) => {
47
- props.onDispatch(state);
48
- },
49
- {
50
- key: dispatchKey
51
- }
52
- );
53
- };
54
- return {
55
- dispatch
56
- };
57
- }
58
-
59
- // src/text_editor.tsx
60
- var import_jsx_runtime = require("react/jsx-runtime");
61
- function TextEditor({
62
- store,
63
- name,
64
- getter,
65
- setter,
66
- defaultValue,
67
- ref,
68
- ...props
69
- }) {
70
- const controllerRef = (0, import_react2.useRef)(null);
71
- (0, import_react2.useImperativeHandle)(
72
- ref,
73
- () => controllerRef.current,
74
- []
75
- );
76
- const { dispatch } = useStoreController(store, {
77
- onSubscribe: (state) => {
78
- const controller = controllerRef.current;
79
- if (!controller) {
80
- return;
81
- }
82
- const getResult = () => {
83
- if (getter) {
84
- return getter(state) || "";
85
- }
86
- if (name) {
87
- return state[name] || "";
88
- }
89
- return "";
90
- };
91
- const result = getResult();
92
- if (controller.value !== result) {
93
- controller.value = result;
94
- }
95
- },
96
- onDispatch: (state) => {
97
- const controller = controllerRef.current;
98
- if (!controller) {
99
- return;
100
- }
101
- if (setter) {
102
- setter(state, controller.value);
103
- return;
104
- }
105
- if (name) {
106
- state[name] = controller.value;
107
- }
108
- }
109
- });
110
- const getDefaultValue = () => {
111
- if (getter) {
112
- return getter(store.state);
113
- }
114
- if (name) {
115
- return store.state[name];
116
- }
117
- return void 0;
118
- };
119
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
120
- import_gw_react_text_editor.TextEditor,
121
- {
122
- ...props,
123
- ref: controllerRef,
124
- defaultValue: defaultValue ?? getDefaultValue(),
125
- onChange: (e) => {
126
- dispatch();
127
- props.onChange?.(e);
128
- }
129
- }
130
- );
131
- }
132
- // Annotate the CommonJS export names for ESM import in node:
133
- 0 && (module.exports = {
134
- TextEditor
135
- });
@@ -1,112 +0,0 @@
1
- // src/text_editor.tsx
2
- import {
3
- TextEditor as GwTextEditor
4
- } from "gw-react-text-editor";
5
- import { useImperativeHandle, useRef } from "react";
6
-
7
- // src/use_store_controller.tsx
8
- import { useEffect, useId } from "react";
9
- function useStoreController(store, props) {
10
- const dispatchKey = useId();
11
- useEffect(() => {
12
- const unsub = store.subscribe((state, key) => {
13
- if (key === dispatchKey) {
14
- return;
15
- }
16
- props.onSubscribe(state);
17
- });
18
- return () => {
19
- unsub();
20
- };
21
- }, []);
22
- const dispatch = () => {
23
- store.dispatch(
24
- (state) => {
25
- props.onDispatch(state);
26
- },
27
- {
28
- key: dispatchKey
29
- }
30
- );
31
- };
32
- return {
33
- dispatch
34
- };
35
- }
36
-
37
- // src/text_editor.tsx
38
- import { jsx } from "react/jsx-runtime";
39
- function TextEditor({
40
- store,
41
- name,
42
- getter,
43
- setter,
44
- defaultValue,
45
- ref,
46
- ...props
47
- }) {
48
- const controllerRef = useRef(null);
49
- useImperativeHandle(
50
- ref,
51
- () => controllerRef.current,
52
- []
53
- );
54
- const { dispatch } = useStoreController(store, {
55
- onSubscribe: (state) => {
56
- const controller = controllerRef.current;
57
- if (!controller) {
58
- return;
59
- }
60
- const getResult = () => {
61
- if (getter) {
62
- return getter(state) || "";
63
- }
64
- if (name) {
65
- return state[name] || "";
66
- }
67
- return "";
68
- };
69
- const result = getResult();
70
- if (controller.value !== result) {
71
- controller.value = result;
72
- }
73
- },
74
- onDispatch: (state) => {
75
- const controller = controllerRef.current;
76
- if (!controller) {
77
- return;
78
- }
79
- if (setter) {
80
- setter(state, controller.value);
81
- return;
82
- }
83
- if (name) {
84
- state[name] = controller.value;
85
- }
86
- }
87
- });
88
- const getDefaultValue = () => {
89
- if (getter) {
90
- return getter(store.state);
91
- }
92
- if (name) {
93
- return store.state[name];
94
- }
95
- return void 0;
96
- };
97
- return /* @__PURE__ */ jsx(
98
- GwTextEditor,
99
- {
100
- ...props,
101
- ref: controllerRef,
102
- defaultValue: defaultValue ?? getDefaultValue(),
103
- onChange: (e) => {
104
- dispatch();
105
- props.onChange?.(e);
106
- }
107
- }
108
- );
109
- }
110
- export {
111
- TextEditor
112
- };
@@ -1,16 +0,0 @@
1
- import { CreateRender } from './create_render.mjs';
2
- import { Store } from 'gw-store';
3
- import { useStoreComponent } from './use_store_component.mjs';
4
- import 'react/jsx-runtime';
5
- import 'react';
6
- import './use_store_input_with_name.mjs';
7
- import './use_store_input.mjs';
8
- import './text_editor.mjs';
9
- import 'gw-react-text-editor';
10
-
11
- type FormStore<TState> = Store<TState> & ReturnType<typeof useStoreComponent<TState>> & {
12
- render: CreateRender<TState>;
13
- };
14
- declare function useFormStore<TState>(initialState: TState): FormStore<TState>;
15
-
16
- export { type FormStore, useFormStore };
@@ -1,16 +0,0 @@
1
- import { CreateRender } from './create_render.js';
2
- import { Store } from 'gw-store';
3
- import { useStoreComponent } from './use_store_component.js';
4
- import 'react/jsx-runtime';
5
- import 'react';
6
- import './use_store_input_with_name.js';
7
- import './use_store_input.js';
8
- import './text_editor.js';
9
- import 'gw-react-text-editor';
10
-
11
- type FormStore<TState> = Store<TState> & ReturnType<typeof useStoreComponent<TState>> & {
12
- render: CreateRender<TState>;
13
- };
14
- declare function useFormStore<TState>(initialState: TState): FormStore<TState>;
15
-
16
- export { type FormStore, useFormStore };