react-store-input 0.2.3 → 0.2.5
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/dist/create_render.d.mts +1 -1
- package/dist/create_render.d.ts +1 -1
- package/dist/create_render.js +3 -31
- package/dist/create_render.mjs +1 -27
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +118 -104
- package/dist/index.mjs +110 -92
- package/dist/text_editor.d.mts +13 -0
- package/dist/text_editor.d.ts +13 -0
- package/dist/text_editor.js +135 -0
- package/dist/text_editor.mjs +112 -0
- package/dist/use_form_store.d.mts +3 -1
- package/dist/use_form_store.d.ts +3 -1
- package/dist/use_form_store.js +113 -95
- package/dist/use_form_store.mjs +105 -85
- package/dist/use_store_component.d.mts +4 -1
- package/dist/use_store_component.d.ts +4 -1
- package/dist/use_store_component.js +98 -26
- package/dist/use_store_component.mjs +105 -31
- package/dist/use_store_controller.d.mts +1 -1
- package/dist/use_store_controller.d.ts +1 -1
- package/dist/use_store_controller.js +10 -18
- package/dist/use_store_controller.mjs +11 -19
- package/dist/use_store_input.d.mts +1 -1
- package/dist/use_store_input.d.ts +1 -1
- package/dist/use_store_input.js +10 -18
- package/dist/use_store_input.mjs +11 -19
- package/dist/use_store_input_with_name.d.mts +1 -1
- package/dist/use_store_input_with_name.d.ts +1 -1
- package/dist/use_store_input_with_name.js +10 -18
- package/dist/use_store_input_with_name.mjs +11 -19
- package/package.json +6 -4
- package/dist/use_selector.d.mts +0 -5
- package/dist/use_selector.d.ts +0 -5
- package/dist/use_selector.js +0 -54
- package/dist/use_selector.mjs +0 -29
- package/dist/use_store.d.mts +0 -12
- package/dist/use_store.d.ts +0 -12
- package/dist/use_store.js +0 -71
- package/dist/use_store.mjs +0 -46
- package/dist/use_subscribe.d.mts +0 -5
- package/dist/use_subscribe.d.ts +0 -5
- package/dist/use_subscribe.js +0 -38
- package/dist/use_subscribe.mjs +0 -13
package/dist/use_form_store.js
CHANGED
|
@@ -24,39 +24,13 @@ __export(use_form_store_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(use_form_store_exports);
|
|
26
26
|
|
|
27
|
-
// src/use_selector.tsx
|
|
28
|
-
var import_react2 = require("react");
|
|
29
|
-
|
|
30
|
-
// src/use_subscribe.tsx
|
|
31
|
-
var import_react = require("react");
|
|
32
|
-
function useSubscribe(store, subscriber) {
|
|
33
|
-
(0, import_react.useEffect)(() => {
|
|
34
|
-
const unsubscribe = store.subscribe(subscriber);
|
|
35
|
-
return () => {
|
|
36
|
-
unsubscribe();
|
|
37
|
-
};
|
|
38
|
-
}, [store]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/use_selector.tsx
|
|
42
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
43
|
-
const [state, setState] = (0, import_react2.useState)(selector(store.state));
|
|
44
|
-
useSubscribe(store, (newState) => {
|
|
45
|
-
const result = selector(newState);
|
|
46
|
-
if (compare(state, result)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
setState(result);
|
|
50
|
-
});
|
|
51
|
-
return state;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
27
|
// src/create_render.tsx
|
|
28
|
+
var import_gw_store = require("gw-store");
|
|
55
29
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
56
30
|
function createRenderWithStore(store) {
|
|
57
31
|
return function createRender(selector, compare) {
|
|
58
32
|
function Component() {
|
|
59
|
-
const result = useSelector(store, (state) => state, compare);
|
|
33
|
+
const result = (0, import_gw_store.useSelector)(store, (state) => state, compare);
|
|
60
34
|
const content = selector(result);
|
|
61
35
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: content });
|
|
62
36
|
}
|
|
@@ -64,66 +38,30 @@ function createRenderWithStore(store) {
|
|
|
64
38
|
};
|
|
65
39
|
}
|
|
66
40
|
|
|
67
|
-
// src/
|
|
68
|
-
var
|
|
69
|
-
var import_immer = require("immer");
|
|
70
|
-
function useStore(initialState) {
|
|
71
|
-
const stateRef = (0, import_react3.useRef)(initialState);
|
|
72
|
-
const subscribers = (0, import_react3.useRef)([]);
|
|
73
|
-
const dispatch = (recipe, options = {}) => {
|
|
74
|
-
if (typeof recipe === "function") {
|
|
75
|
-
stateRef.current = (0, import_immer.produce)(stateRef.current, recipe);
|
|
76
|
-
} else {
|
|
77
|
-
stateRef.current = (0, import_immer.produce)(
|
|
78
|
-
stateRef.current,
|
|
79
|
-
(draft) => {
|
|
80
|
-
for (const key in recipe) {
|
|
81
|
-
draft[key] = recipe[key];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
notify(options.key);
|
|
87
|
-
};
|
|
88
|
-
const subscribe = (subscriber) => {
|
|
89
|
-
subscribers.current.push(subscriber);
|
|
90
|
-
return () => {
|
|
91
|
-
const index = subscribers.current.indexOf(subscriber);
|
|
92
|
-
if (index !== -1) {
|
|
93
|
-
subscribers.current.splice(index, 1);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
const notify = (key) => {
|
|
98
|
-
for (const listener of subscribers.current) {
|
|
99
|
-
listener(stateRef.current, key);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
return {
|
|
103
|
-
get state() {
|
|
104
|
-
return stateRef.current;
|
|
105
|
-
},
|
|
106
|
-
dispatch,
|
|
107
|
-
subscribe
|
|
108
|
-
};
|
|
109
|
-
}
|
|
41
|
+
// src/use_form_store.tsx
|
|
42
|
+
var import_gw_store2 = require("gw-store");
|
|
110
43
|
|
|
111
44
|
// src/use_store_component.tsx
|
|
112
|
-
var
|
|
45
|
+
var import_react3 = require("react");
|
|
113
46
|
|
|
114
47
|
// src/use_store_input.tsx
|
|
115
48
|
var import_date_fns = require("date-fns");
|
|
116
49
|
|
|
117
50
|
// src/use_store_controller.tsx
|
|
118
|
-
var
|
|
51
|
+
var import_react = require("react");
|
|
119
52
|
function useStoreController(store, props) {
|
|
120
|
-
const dispatchKey = (0,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
53
|
+
const dispatchKey = (0, import_react.useId)();
|
|
54
|
+
(0, import_react.useEffect)(() => {
|
|
55
|
+
const unsub = store.subscribe((state, key) => {
|
|
56
|
+
if (key === dispatchKey) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
props.onSubscribe(state);
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
unsub();
|
|
63
|
+
};
|
|
64
|
+
}, []);
|
|
127
65
|
const dispatch = () => {
|
|
128
66
|
store.dispatch(
|
|
129
67
|
(state) => {
|
|
@@ -254,22 +192,102 @@ function useStoreInputWithName(ref, store, props) {
|
|
|
254
192
|
};
|
|
255
193
|
}
|
|
256
194
|
|
|
257
|
-
// src/
|
|
195
|
+
// src/text_editor.tsx
|
|
196
|
+
var import_gw_react_text_editor = require("gw-react-text-editor");
|
|
197
|
+
var import_react2 = require("react");
|
|
258
198
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
199
|
+
function TextEditor({
|
|
200
|
+
store,
|
|
201
|
+
name,
|
|
202
|
+
getter,
|
|
203
|
+
setter,
|
|
204
|
+
defaultValue,
|
|
205
|
+
ref,
|
|
206
|
+
...props
|
|
207
|
+
}) {
|
|
208
|
+
const controllerRef = (0, import_react2.useRef)(null);
|
|
209
|
+
(0, import_react2.useImperativeHandle)(
|
|
210
|
+
ref,
|
|
211
|
+
() => controllerRef.current,
|
|
212
|
+
[]
|
|
213
|
+
);
|
|
214
|
+
const { dispatch } = useStoreController(store, {
|
|
215
|
+
onSubscribe: (state) => {
|
|
216
|
+
const controller = controllerRef.current;
|
|
217
|
+
if (!controller) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const getResult = () => {
|
|
221
|
+
if (getter) {
|
|
222
|
+
return getter(state) || "";
|
|
223
|
+
}
|
|
224
|
+
if (name) {
|
|
225
|
+
return state[name] || "";
|
|
226
|
+
}
|
|
227
|
+
return "";
|
|
228
|
+
};
|
|
229
|
+
const result = getResult();
|
|
230
|
+
if (controller.value !== result) {
|
|
231
|
+
controller.value = result;
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
onDispatch: (state) => {
|
|
235
|
+
const controller = controllerRef.current;
|
|
236
|
+
if (!controller) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (setter) {
|
|
240
|
+
setter(state, controller.value);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (name) {
|
|
244
|
+
state[name] = controller.value;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
const getDefaultValue = () => {
|
|
249
|
+
if (getter) {
|
|
250
|
+
return getter(store.state);
|
|
251
|
+
}
|
|
252
|
+
if (name) {
|
|
253
|
+
return store.state[name];
|
|
254
|
+
}
|
|
255
|
+
return void 0;
|
|
256
|
+
};
|
|
257
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
258
|
+
import_gw_react_text_editor.TextEditor,
|
|
259
|
+
{
|
|
260
|
+
...props,
|
|
261
|
+
ref: controllerRef,
|
|
262
|
+
defaultValue: defaultValue ?? getDefaultValue(),
|
|
263
|
+
onChange: (e) => {
|
|
264
|
+
dispatch();
|
|
265
|
+
props.onChange?.(e);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/use_store_component.tsx
|
|
272
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
259
273
|
function useStoreComponent(store) {
|
|
260
|
-
const input = (0,
|
|
261
|
-
return /* @__PURE__ */ (0,
|
|
274
|
+
const input = (0, import_react3.useCallback)(function Component(props) {
|
|
275
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Input, { store, ...props });
|
|
276
|
+
}, []);
|
|
277
|
+
const select = (0, import_react3.useCallback)(function Component(props) {
|
|
278
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Select, { store, ...props });
|
|
262
279
|
}, []);
|
|
263
|
-
const
|
|
264
|
-
return /* @__PURE__ */ (0,
|
|
280
|
+
const textarea = (0, import_react3.useCallback)(function Component(props) {
|
|
281
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Textarea, { store, ...props });
|
|
265
282
|
}, []);
|
|
266
|
-
const
|
|
267
|
-
return /* @__PURE__ */ (0,
|
|
283
|
+
const textEditor = (0, import_react3.useCallback)(function Component(props) {
|
|
284
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TextEditor, { store, ...props });
|
|
268
285
|
}, []);
|
|
269
286
|
return {
|
|
270
287
|
input,
|
|
271
288
|
select,
|
|
272
|
-
textarea
|
|
289
|
+
textarea,
|
|
290
|
+
textEditor
|
|
273
291
|
};
|
|
274
292
|
}
|
|
275
293
|
function Input({
|
|
@@ -280,7 +298,7 @@ function Input({
|
|
|
280
298
|
toStateValue,
|
|
281
299
|
...props
|
|
282
300
|
}) {
|
|
283
|
-
const ref = (0,
|
|
301
|
+
const ref = (0, import_react3.useRef)(null);
|
|
284
302
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
285
303
|
...props,
|
|
286
304
|
getter,
|
|
@@ -288,7 +306,7 @@ function Input({
|
|
|
288
306
|
toInputValue,
|
|
289
307
|
toStateValue
|
|
290
308
|
});
|
|
291
|
-
return /* @__PURE__ */ (0,
|
|
309
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { ref, ...props, ...storeProps });
|
|
292
310
|
}
|
|
293
311
|
function Select({
|
|
294
312
|
store,
|
|
@@ -298,7 +316,7 @@ function Select({
|
|
|
298
316
|
toStateValue,
|
|
299
317
|
...props
|
|
300
318
|
}) {
|
|
301
|
-
const ref = (0,
|
|
319
|
+
const ref = (0, import_react3.useRef)(null);
|
|
302
320
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
303
321
|
...props,
|
|
304
322
|
getter,
|
|
@@ -306,7 +324,7 @@ function Select({
|
|
|
306
324
|
toInputValue,
|
|
307
325
|
toStateValue
|
|
308
326
|
});
|
|
309
|
-
return /* @__PURE__ */ (0,
|
|
327
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("select", { ref, ...props, ...storeProps });
|
|
310
328
|
}
|
|
311
329
|
function Textarea({
|
|
312
330
|
store,
|
|
@@ -316,7 +334,7 @@ function Textarea({
|
|
|
316
334
|
toStateValue,
|
|
317
335
|
...props
|
|
318
336
|
}) {
|
|
319
|
-
const ref = (0,
|
|
337
|
+
const ref = (0, import_react3.useRef)(null);
|
|
320
338
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
321
339
|
...props,
|
|
322
340
|
getter,
|
|
@@ -324,12 +342,12 @@ function Textarea({
|
|
|
324
342
|
toInputValue,
|
|
325
343
|
toStateValue
|
|
326
344
|
});
|
|
327
|
-
return /* @__PURE__ */ (0,
|
|
345
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("textarea", { ref, ...props, ...storeProps });
|
|
328
346
|
}
|
|
329
347
|
|
|
330
348
|
// src/use_form_store.tsx
|
|
331
349
|
function useFormStore(initialState) {
|
|
332
|
-
const store = useStore(initialState);
|
|
350
|
+
const store = (0, import_gw_store2.useStore)(initialState);
|
|
333
351
|
const storeComponent = useStoreComponent(store);
|
|
334
352
|
return {
|
|
335
353
|
get state() {
|
package/dist/use_form_store.mjs
CHANGED
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
// src/use_selector.tsx
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
|
|
4
|
-
// src/use_subscribe.tsx
|
|
5
|
-
import { useEffect } from "react";
|
|
6
|
-
function useSubscribe(store, subscriber) {
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const unsubscribe = store.subscribe(subscriber);
|
|
9
|
-
return () => {
|
|
10
|
-
unsubscribe();
|
|
11
|
-
};
|
|
12
|
-
}, [store]);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/use_selector.tsx
|
|
16
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
17
|
-
const [state, setState] = useState(selector(store.state));
|
|
18
|
-
useSubscribe(store, (newState) => {
|
|
19
|
-
const result = selector(newState);
|
|
20
|
-
if (compare(state, result)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
setState(result);
|
|
24
|
-
});
|
|
25
|
-
return state;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
1
|
// src/create_render.tsx
|
|
2
|
+
import { useSelector } from "gw-store";
|
|
29
3
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
30
4
|
function createRenderWithStore(store) {
|
|
31
5
|
return function createRender(selector, compare) {
|
|
@@ -38,49 +12,8 @@ function createRenderWithStore(store) {
|
|
|
38
12
|
};
|
|
39
13
|
}
|
|
40
14
|
|
|
41
|
-
// src/
|
|
42
|
-
import {
|
|
43
|
-
import { produce } from "immer";
|
|
44
|
-
function useStore(initialState) {
|
|
45
|
-
const stateRef = useRef(initialState);
|
|
46
|
-
const subscribers = useRef([]);
|
|
47
|
-
const dispatch = (recipe, options = {}) => {
|
|
48
|
-
if (typeof recipe === "function") {
|
|
49
|
-
stateRef.current = produce(stateRef.current, recipe);
|
|
50
|
-
} else {
|
|
51
|
-
stateRef.current = produce(
|
|
52
|
-
stateRef.current,
|
|
53
|
-
(draft) => {
|
|
54
|
-
for (const key in recipe) {
|
|
55
|
-
draft[key] = recipe[key];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
notify(options.key);
|
|
61
|
-
};
|
|
62
|
-
const subscribe = (subscriber) => {
|
|
63
|
-
subscribers.current.push(subscriber);
|
|
64
|
-
return () => {
|
|
65
|
-
const index = subscribers.current.indexOf(subscriber);
|
|
66
|
-
if (index !== -1) {
|
|
67
|
-
subscribers.current.splice(index, 1);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
const notify = (key) => {
|
|
72
|
-
for (const listener of subscribers.current) {
|
|
73
|
-
listener(stateRef.current, key);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
return {
|
|
77
|
-
get state() {
|
|
78
|
-
return stateRef.current;
|
|
79
|
-
},
|
|
80
|
-
dispatch,
|
|
81
|
-
subscribe
|
|
82
|
-
};
|
|
83
|
-
}
|
|
15
|
+
// src/use_form_store.tsx
|
|
16
|
+
import { useStore } from "gw-store";
|
|
84
17
|
|
|
85
18
|
// src/use_store_component.tsx
|
|
86
19
|
import { useCallback, useRef as useRef2 } from "react";
|
|
@@ -89,15 +22,20 @@ import { useCallback, useRef as useRef2 } from "react";
|
|
|
89
22
|
import { format } from "date-fns";
|
|
90
23
|
|
|
91
24
|
// src/use_store_controller.tsx
|
|
92
|
-
import { useId } from "react";
|
|
25
|
+
import { useEffect, useId } from "react";
|
|
93
26
|
function useStoreController(store, props) {
|
|
94
27
|
const dispatchKey = useId();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const unsub = store.subscribe((state, key) => {
|
|
30
|
+
if (key === dispatchKey) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
props.onSubscribe(state);
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
unsub();
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
101
39
|
const dispatch = () => {
|
|
102
40
|
store.dispatch(
|
|
103
41
|
(state) => {
|
|
@@ -228,22 +166,104 @@ function useStoreInputWithName(ref, store, props) {
|
|
|
228
166
|
};
|
|
229
167
|
}
|
|
230
168
|
|
|
231
|
-
// src/
|
|
169
|
+
// src/text_editor.tsx
|
|
170
|
+
import {
|
|
171
|
+
TextEditor as GwTextEditor
|
|
172
|
+
} from "gw-react-text-editor";
|
|
173
|
+
import { useImperativeHandle, useRef } from "react";
|
|
232
174
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
175
|
+
function TextEditor({
|
|
176
|
+
store,
|
|
177
|
+
name,
|
|
178
|
+
getter,
|
|
179
|
+
setter,
|
|
180
|
+
defaultValue,
|
|
181
|
+
ref,
|
|
182
|
+
...props
|
|
183
|
+
}) {
|
|
184
|
+
const controllerRef = useRef(null);
|
|
185
|
+
useImperativeHandle(
|
|
186
|
+
ref,
|
|
187
|
+
() => controllerRef.current,
|
|
188
|
+
[]
|
|
189
|
+
);
|
|
190
|
+
const { dispatch } = useStoreController(store, {
|
|
191
|
+
onSubscribe: (state) => {
|
|
192
|
+
const controller = controllerRef.current;
|
|
193
|
+
if (!controller) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const getResult = () => {
|
|
197
|
+
if (getter) {
|
|
198
|
+
return getter(state) || "";
|
|
199
|
+
}
|
|
200
|
+
if (name) {
|
|
201
|
+
return state[name] || "";
|
|
202
|
+
}
|
|
203
|
+
return "";
|
|
204
|
+
};
|
|
205
|
+
const result = getResult();
|
|
206
|
+
if (controller.value !== result) {
|
|
207
|
+
controller.value = result;
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
onDispatch: (state) => {
|
|
211
|
+
const controller = controllerRef.current;
|
|
212
|
+
if (!controller) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (setter) {
|
|
216
|
+
setter(state, controller.value);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (name) {
|
|
220
|
+
state[name] = controller.value;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
const getDefaultValue = () => {
|
|
225
|
+
if (getter) {
|
|
226
|
+
return getter(store.state);
|
|
227
|
+
}
|
|
228
|
+
if (name) {
|
|
229
|
+
return store.state[name];
|
|
230
|
+
}
|
|
231
|
+
return void 0;
|
|
232
|
+
};
|
|
233
|
+
return /* @__PURE__ */ jsx2(
|
|
234
|
+
GwTextEditor,
|
|
235
|
+
{
|
|
236
|
+
...props,
|
|
237
|
+
ref: controllerRef,
|
|
238
|
+
defaultValue: defaultValue ?? getDefaultValue(),
|
|
239
|
+
onChange: (e) => {
|
|
240
|
+
dispatch();
|
|
241
|
+
props.onChange?.(e);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/use_store_component.tsx
|
|
248
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
233
249
|
function useStoreComponent(store) {
|
|
234
250
|
const input = useCallback(function Component(props) {
|
|
235
|
-
return /* @__PURE__ */
|
|
251
|
+
return /* @__PURE__ */ jsx3(Input, { store, ...props });
|
|
236
252
|
}, []);
|
|
237
253
|
const select = useCallback(function Component(props) {
|
|
238
|
-
return /* @__PURE__ */
|
|
254
|
+
return /* @__PURE__ */ jsx3(Select, { store, ...props });
|
|
239
255
|
}, []);
|
|
240
256
|
const textarea = useCallback(function Component(props) {
|
|
241
|
-
return /* @__PURE__ */
|
|
257
|
+
return /* @__PURE__ */ jsx3(Textarea, { store, ...props });
|
|
258
|
+
}, []);
|
|
259
|
+
const textEditor = useCallback(function Component(props) {
|
|
260
|
+
return /* @__PURE__ */ jsx3(TextEditor, { store, ...props });
|
|
242
261
|
}, []);
|
|
243
262
|
return {
|
|
244
263
|
input,
|
|
245
264
|
select,
|
|
246
|
-
textarea
|
|
265
|
+
textarea,
|
|
266
|
+
textEditor
|
|
247
267
|
};
|
|
248
268
|
}
|
|
249
269
|
function Input({
|
|
@@ -262,7 +282,7 @@ function Input({
|
|
|
262
282
|
toInputValue,
|
|
263
283
|
toStateValue
|
|
264
284
|
});
|
|
265
|
-
return /* @__PURE__ */
|
|
285
|
+
return /* @__PURE__ */ jsx3("input", { ref, ...props, ...storeProps });
|
|
266
286
|
}
|
|
267
287
|
function Select({
|
|
268
288
|
store,
|
|
@@ -280,7 +300,7 @@ function Select({
|
|
|
280
300
|
toInputValue,
|
|
281
301
|
toStateValue
|
|
282
302
|
});
|
|
283
|
-
return /* @__PURE__ */
|
|
303
|
+
return /* @__PURE__ */ jsx3("select", { ref, ...props, ...storeProps });
|
|
284
304
|
}
|
|
285
305
|
function Textarea({
|
|
286
306
|
store,
|
|
@@ -298,7 +318,7 @@ function Textarea({
|
|
|
298
318
|
toInputValue,
|
|
299
319
|
toStateValue
|
|
300
320
|
});
|
|
301
|
-
return /* @__PURE__ */
|
|
321
|
+
return /* @__PURE__ */ jsx3("textarea", { ref, ...props, ...storeProps });
|
|
302
322
|
}
|
|
303
323
|
|
|
304
324
|
// src/use_form_store.tsx
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { DetailedHTMLProps } from 'react';
|
|
3
|
-
import { Store } from '
|
|
3
|
+
import { Store } from 'gw-store';
|
|
4
4
|
import { StoreInputWithNameProps } from './use_store_input_with_name.mjs';
|
|
5
|
+
import { TextEditorProps } from './text_editor.mjs';
|
|
5
6
|
import './use_store_input.mjs';
|
|
7
|
+
import 'gw-react-text-editor';
|
|
6
8
|
|
|
7
9
|
type StoreInputWithNameComponentProps<TElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameProps<TElement, TState, TName, TValue> & Omit<DetailedHTMLProps<React.InputHTMLAttributes<TElement>, TElement>, keyof StoreInputWithNameProps<TElement, TState, TName, TValue>>;
|
|
8
10
|
declare function useStoreComponent<TState>(store: Store<TState>): {
|
|
9
11
|
input: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLInputElement, TState, TName, TValue>) => react_jsx_runtime.JSX.Element;
|
|
10
12
|
select: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLSelectElement, TState, TName, TValue>) => react_jsx_runtime.JSX.Element;
|
|
11
13
|
textarea: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLTextAreaElement, TState, TName, TValue>) => react_jsx_runtime.JSX.Element;
|
|
14
|
+
textEditor: (props: Omit<TextEditorProps<TState>, "store">) => react_jsx_runtime.JSX.Element;
|
|
12
15
|
};
|
|
13
16
|
type StoreComponentPropsWithStore<TElement extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameComponentProps<TElement, TState, TName, TValue> & {
|
|
14
17
|
store: Store<TState>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { DetailedHTMLProps } from 'react';
|
|
3
|
-
import { Store } from '
|
|
3
|
+
import { Store } from 'gw-store';
|
|
4
4
|
import { StoreInputWithNameProps } from './use_store_input_with_name.js';
|
|
5
|
+
import { TextEditorProps } from './text_editor.js';
|
|
5
6
|
import './use_store_input.js';
|
|
7
|
+
import 'gw-react-text-editor';
|
|
6
8
|
|
|
7
9
|
type StoreInputWithNameComponentProps<TElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameProps<TElement, TState, TName, TValue> & Omit<DetailedHTMLProps<React.InputHTMLAttributes<TElement>, TElement>, keyof StoreInputWithNameProps<TElement, TState, TName, TValue>>;
|
|
8
10
|
declare function useStoreComponent<TState>(store: Store<TState>): {
|
|
9
11
|
input: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLInputElement, TState, TName, TValue>) => react_jsx_runtime.JSX.Element;
|
|
10
12
|
select: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLSelectElement, TState, TName, TValue>) => react_jsx_runtime.JSX.Element;
|
|
11
13
|
textarea: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLTextAreaElement, TState, TName, TValue>) => react_jsx_runtime.JSX.Element;
|
|
14
|
+
textEditor: (props: Omit<TextEditorProps<TState>, "store">) => react_jsx_runtime.JSX.Element;
|
|
12
15
|
};
|
|
13
16
|
type StoreComponentPropsWithStore<TElement extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameComponentProps<TElement, TState, TName, TValue> & {
|
|
14
17
|
store: Store<TState>;
|