react-store-input 0.2.4 → 0.2.6
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 -27
- package/dist/create_render.mjs +1 -23
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +119 -107
- package/dist/index.mjs +113 -99
- 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 +111 -102
- package/dist/use_form_store.mjs +108 -97
- package/dist/use_store_component.d.mts +4 -1
- package/dist/use_store_component.d.ts +4 -1
- package/dist/use_store_component.js +97 -25
- package/dist/use_store_component.mjs +104 -30
- package/dist/use_store_controller.d.mts +1 -1
- package/dist/use_store_controller.d.ts +1 -1
- package/dist/use_store_controller.js +9 -17
- package/dist/use_store_controller.mjs +10 -18
- package/dist/use_store_input.d.mts +1 -1
- package/dist/use_store_input.d.ts +1 -1
- package/dist/use_store_input.js +9 -17
- package/dist/use_store_input.mjs +10 -18
- 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 +9 -17
- package/dist/use_store_input_with_name.mjs +10 -18
- 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 -50
- package/dist/use_selector.mjs +0 -25
- 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
|
@@ -32,28 +32,20 @@ var import_react3 = require("react");
|
|
|
32
32
|
var import_date_fns = require("date-fns");
|
|
33
33
|
|
|
34
34
|
// src/use_store_controller.tsx
|
|
35
|
-
var import_react2 = require("react");
|
|
36
|
-
|
|
37
|
-
// src/use_subscribe.tsx
|
|
38
35
|
var import_react = require("react");
|
|
39
|
-
function
|
|
36
|
+
function useStoreController(store, props) {
|
|
37
|
+
const dispatchKey = (0, import_react.useId)();
|
|
40
38
|
(0, import_react.useEffect)(() => {
|
|
41
|
-
const
|
|
39
|
+
const unsub = store.subscribe((state, key) => {
|
|
40
|
+
if (key === dispatchKey) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
props.onSubscribe(state);
|
|
44
|
+
});
|
|
42
45
|
return () => {
|
|
43
|
-
|
|
46
|
+
unsub();
|
|
44
47
|
};
|
|
45
48
|
}, []);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/use_store_controller.tsx
|
|
49
|
-
function useStoreController(store, props) {
|
|
50
|
-
const dispatchKey = (0, import_react2.useId)();
|
|
51
|
-
useSubscribe(store, (state, key) => {
|
|
52
|
-
if (key === dispatchKey) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
props.onSubscribe(state);
|
|
56
|
-
});
|
|
57
49
|
const dispatch = () => {
|
|
58
50
|
store.dispatch(
|
|
59
51
|
(state) => {
|
|
@@ -184,22 +176,102 @@ function useStoreInputWithName(ref, store, props) {
|
|
|
184
176
|
};
|
|
185
177
|
}
|
|
186
178
|
|
|
187
|
-
// src/
|
|
179
|
+
// src/text_editor.tsx
|
|
180
|
+
var import_gw_react_text_editor = require("gw-react-text-editor");
|
|
181
|
+
var import_react2 = require("react");
|
|
188
182
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
183
|
+
function TextEditor({
|
|
184
|
+
store,
|
|
185
|
+
name,
|
|
186
|
+
getter,
|
|
187
|
+
setter,
|
|
188
|
+
defaultValue,
|
|
189
|
+
ref,
|
|
190
|
+
...props
|
|
191
|
+
}) {
|
|
192
|
+
const controllerRef = (0, import_react2.useRef)(null);
|
|
193
|
+
(0, import_react2.useImperativeHandle)(
|
|
194
|
+
ref,
|
|
195
|
+
() => controllerRef.current,
|
|
196
|
+
[]
|
|
197
|
+
);
|
|
198
|
+
const { dispatch } = useStoreController(store, {
|
|
199
|
+
onSubscribe: (state) => {
|
|
200
|
+
const controller = controllerRef.current;
|
|
201
|
+
if (!controller) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const getResult = () => {
|
|
205
|
+
if (getter) {
|
|
206
|
+
return getter(state) || "";
|
|
207
|
+
}
|
|
208
|
+
if (name) {
|
|
209
|
+
return state[name] || "";
|
|
210
|
+
}
|
|
211
|
+
return "";
|
|
212
|
+
};
|
|
213
|
+
const result = getResult();
|
|
214
|
+
if (controller.value !== result) {
|
|
215
|
+
controller.value = result;
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
onDispatch: (state) => {
|
|
219
|
+
const controller = controllerRef.current;
|
|
220
|
+
if (!controller) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (setter) {
|
|
224
|
+
setter(state, controller.value);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (name) {
|
|
228
|
+
state[name] = controller.value;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
const getDefaultValue = () => {
|
|
233
|
+
if (getter) {
|
|
234
|
+
return getter(store.state);
|
|
235
|
+
}
|
|
236
|
+
if (name) {
|
|
237
|
+
return store.state[name];
|
|
238
|
+
}
|
|
239
|
+
return void 0;
|
|
240
|
+
};
|
|
241
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
242
|
+
import_gw_react_text_editor.TextEditor,
|
|
243
|
+
{
|
|
244
|
+
...props,
|
|
245
|
+
ref: controllerRef,
|
|
246
|
+
defaultValue: defaultValue ?? getDefaultValue(),
|
|
247
|
+
onChange: (e) => {
|
|
248
|
+
dispatch();
|
|
249
|
+
props.onChange?.(e);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/use_store_component.tsx
|
|
256
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
189
257
|
function useStoreComponent(store) {
|
|
190
258
|
const input = (0, import_react3.useCallback)(function Component(props) {
|
|
191
|
-
return /* @__PURE__ */ (0,
|
|
259
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Input, { store, ...props });
|
|
192
260
|
}, []);
|
|
193
261
|
const select = (0, import_react3.useCallback)(function Component(props) {
|
|
194
|
-
return /* @__PURE__ */ (0,
|
|
262
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Select, { store, ...props });
|
|
195
263
|
}, []);
|
|
196
264
|
const textarea = (0, import_react3.useCallback)(function Component(props) {
|
|
197
|
-
return /* @__PURE__ */ (0,
|
|
265
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Textarea, { store, ...props });
|
|
266
|
+
}, []);
|
|
267
|
+
const textEditor = (0, import_react3.useCallback)(function Component(props) {
|
|
268
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TextEditor, { store, ...props });
|
|
198
269
|
}, []);
|
|
199
270
|
return {
|
|
200
271
|
input,
|
|
201
272
|
select,
|
|
202
|
-
textarea
|
|
273
|
+
textarea,
|
|
274
|
+
textEditor
|
|
203
275
|
};
|
|
204
276
|
}
|
|
205
277
|
function Input({
|
|
@@ -218,7 +290,7 @@ function Input({
|
|
|
218
290
|
toInputValue,
|
|
219
291
|
toStateValue
|
|
220
292
|
});
|
|
221
|
-
return /* @__PURE__ */ (0,
|
|
293
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { ref, ...props, ...storeProps });
|
|
222
294
|
}
|
|
223
295
|
function Select({
|
|
224
296
|
store,
|
|
@@ -236,7 +308,7 @@ function Select({
|
|
|
236
308
|
toInputValue,
|
|
237
309
|
toStateValue
|
|
238
310
|
});
|
|
239
|
-
return /* @__PURE__ */ (0,
|
|
311
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("select", { ref, ...props, ...storeProps });
|
|
240
312
|
}
|
|
241
313
|
function Textarea({
|
|
242
314
|
store,
|
|
@@ -254,7 +326,7 @@ function Textarea({
|
|
|
254
326
|
toInputValue,
|
|
255
327
|
toStateValue
|
|
256
328
|
});
|
|
257
|
-
return /* @__PURE__ */ (0,
|
|
329
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("textarea", { ref, ...props, ...storeProps });
|
|
258
330
|
}
|
|
259
331
|
// Annotate the CommonJS export names for ESM import in node:
|
|
260
332
|
0 && (module.exports = {
|
|
@@ -1,32 +1,24 @@
|
|
|
1
1
|
// src/use_store_component.tsx
|
|
2
|
-
import { useCallback, useRef } from "react";
|
|
2
|
+
import { useCallback, useRef as useRef2 } from "react";
|
|
3
3
|
|
|
4
4
|
// src/use_store_input.tsx
|
|
5
5
|
import { format } from "date-fns";
|
|
6
6
|
|
|
7
7
|
// src/use_store_controller.tsx
|
|
8
|
-
import { useId } from "react";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { useEffect } from "react";
|
|
12
|
-
function useSubscribe(store, subscriber) {
|
|
8
|
+
import { useEffect, useId } from "react";
|
|
9
|
+
function useStoreController(store, props) {
|
|
10
|
+
const dispatchKey = useId();
|
|
13
11
|
useEffect(() => {
|
|
14
|
-
const
|
|
12
|
+
const unsub = store.subscribe((state, key) => {
|
|
13
|
+
if (key === dispatchKey) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
props.onSubscribe(state);
|
|
17
|
+
});
|
|
15
18
|
return () => {
|
|
16
|
-
|
|
19
|
+
unsub();
|
|
17
20
|
};
|
|
18
21
|
}, []);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/use_store_controller.tsx
|
|
22
|
-
function useStoreController(store, props) {
|
|
23
|
-
const dispatchKey = useId();
|
|
24
|
-
useSubscribe(store, (state, key) => {
|
|
25
|
-
if (key === dispatchKey) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
props.onSubscribe(state);
|
|
29
|
-
});
|
|
30
22
|
const dispatch = () => {
|
|
31
23
|
store.dispatch(
|
|
32
24
|
(state) => {
|
|
@@ -157,22 +149,104 @@ function useStoreInputWithName(ref, store, props) {
|
|
|
157
149
|
};
|
|
158
150
|
}
|
|
159
151
|
|
|
160
|
-
// src/
|
|
152
|
+
// src/text_editor.tsx
|
|
153
|
+
import {
|
|
154
|
+
TextEditor as GwTextEditor
|
|
155
|
+
} from "gw-react-text-editor";
|
|
156
|
+
import { useImperativeHandle, useRef } from "react";
|
|
161
157
|
import { jsx } from "react/jsx-runtime";
|
|
158
|
+
function TextEditor({
|
|
159
|
+
store,
|
|
160
|
+
name,
|
|
161
|
+
getter,
|
|
162
|
+
setter,
|
|
163
|
+
defaultValue,
|
|
164
|
+
ref,
|
|
165
|
+
...props
|
|
166
|
+
}) {
|
|
167
|
+
const controllerRef = useRef(null);
|
|
168
|
+
useImperativeHandle(
|
|
169
|
+
ref,
|
|
170
|
+
() => controllerRef.current,
|
|
171
|
+
[]
|
|
172
|
+
);
|
|
173
|
+
const { dispatch } = useStoreController(store, {
|
|
174
|
+
onSubscribe: (state) => {
|
|
175
|
+
const controller = controllerRef.current;
|
|
176
|
+
if (!controller) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const getResult = () => {
|
|
180
|
+
if (getter) {
|
|
181
|
+
return getter(state) || "";
|
|
182
|
+
}
|
|
183
|
+
if (name) {
|
|
184
|
+
return state[name] || "";
|
|
185
|
+
}
|
|
186
|
+
return "";
|
|
187
|
+
};
|
|
188
|
+
const result = getResult();
|
|
189
|
+
if (controller.value !== result) {
|
|
190
|
+
controller.value = result;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
onDispatch: (state) => {
|
|
194
|
+
const controller = controllerRef.current;
|
|
195
|
+
if (!controller) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (setter) {
|
|
199
|
+
setter(state, controller.value);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (name) {
|
|
203
|
+
state[name] = controller.value;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
const getDefaultValue = () => {
|
|
208
|
+
if (getter) {
|
|
209
|
+
return getter(store.state);
|
|
210
|
+
}
|
|
211
|
+
if (name) {
|
|
212
|
+
return store.state[name];
|
|
213
|
+
}
|
|
214
|
+
return void 0;
|
|
215
|
+
};
|
|
216
|
+
return /* @__PURE__ */ jsx(
|
|
217
|
+
GwTextEditor,
|
|
218
|
+
{
|
|
219
|
+
...props,
|
|
220
|
+
ref: controllerRef,
|
|
221
|
+
defaultValue: defaultValue ?? getDefaultValue(),
|
|
222
|
+
onChange: (e) => {
|
|
223
|
+
dispatch();
|
|
224
|
+
props.onChange?.(e);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/use_store_component.tsx
|
|
231
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
162
232
|
function useStoreComponent(store) {
|
|
163
233
|
const input = useCallback(function Component(props) {
|
|
164
|
-
return /* @__PURE__ */
|
|
234
|
+
return /* @__PURE__ */ jsx2(Input, { store, ...props });
|
|
165
235
|
}, []);
|
|
166
236
|
const select = useCallback(function Component(props) {
|
|
167
|
-
return /* @__PURE__ */
|
|
237
|
+
return /* @__PURE__ */ jsx2(Select, { store, ...props });
|
|
168
238
|
}, []);
|
|
169
239
|
const textarea = useCallback(function Component(props) {
|
|
170
|
-
return /* @__PURE__ */
|
|
240
|
+
return /* @__PURE__ */ jsx2(Textarea, { store, ...props });
|
|
241
|
+
}, []);
|
|
242
|
+
const textEditor = useCallback(function Component(props) {
|
|
243
|
+
return /* @__PURE__ */ jsx2(TextEditor, { store, ...props });
|
|
171
244
|
}, []);
|
|
172
245
|
return {
|
|
173
246
|
input,
|
|
174
247
|
select,
|
|
175
|
-
textarea
|
|
248
|
+
textarea,
|
|
249
|
+
textEditor
|
|
176
250
|
};
|
|
177
251
|
}
|
|
178
252
|
function Input({
|
|
@@ -183,7 +257,7 @@ function Input({
|
|
|
183
257
|
toStateValue,
|
|
184
258
|
...props
|
|
185
259
|
}) {
|
|
186
|
-
const ref =
|
|
260
|
+
const ref = useRef2(null);
|
|
187
261
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
188
262
|
...props,
|
|
189
263
|
getter,
|
|
@@ -191,7 +265,7 @@ function Input({
|
|
|
191
265
|
toInputValue,
|
|
192
266
|
toStateValue
|
|
193
267
|
});
|
|
194
|
-
return /* @__PURE__ */
|
|
268
|
+
return /* @__PURE__ */ jsx2("input", { ref, ...props, ...storeProps });
|
|
195
269
|
}
|
|
196
270
|
function Select({
|
|
197
271
|
store,
|
|
@@ -201,7 +275,7 @@ function Select({
|
|
|
201
275
|
toStateValue,
|
|
202
276
|
...props
|
|
203
277
|
}) {
|
|
204
|
-
const ref =
|
|
278
|
+
const ref = useRef2(null);
|
|
205
279
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
206
280
|
...props,
|
|
207
281
|
getter,
|
|
@@ -209,7 +283,7 @@ function Select({
|
|
|
209
283
|
toInputValue,
|
|
210
284
|
toStateValue
|
|
211
285
|
});
|
|
212
|
-
return /* @__PURE__ */
|
|
286
|
+
return /* @__PURE__ */ jsx2("select", { ref, ...props, ...storeProps });
|
|
213
287
|
}
|
|
214
288
|
function Textarea({
|
|
215
289
|
store,
|
|
@@ -219,7 +293,7 @@ function Textarea({
|
|
|
219
293
|
toStateValue,
|
|
220
294
|
...props
|
|
221
295
|
}) {
|
|
222
|
-
const ref =
|
|
296
|
+
const ref = useRef2(null);
|
|
223
297
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
224
298
|
...props,
|
|
225
299
|
getter,
|
|
@@ -227,7 +301,7 @@ function Textarea({
|
|
|
227
301
|
toInputValue,
|
|
228
302
|
toStateValue
|
|
229
303
|
});
|
|
230
|
-
return /* @__PURE__ */
|
|
304
|
+
return /* @__PURE__ */ jsx2("textarea", { ref, ...props, ...storeProps });
|
|
231
305
|
}
|
|
232
306
|
export {
|
|
233
307
|
Input,
|
|
@@ -23,28 +23,20 @@ __export(use_store_controller_exports, {
|
|
|
23
23
|
useStoreController: () => useStoreController
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(use_store_controller_exports);
|
|
26
|
-
var import_react2 = require("react");
|
|
27
|
-
|
|
28
|
-
// src/use_subscribe.tsx
|
|
29
26
|
var import_react = require("react");
|
|
30
|
-
function
|
|
27
|
+
function useStoreController(store, props) {
|
|
28
|
+
const dispatchKey = (0, import_react.useId)();
|
|
31
29
|
(0, import_react.useEffect)(() => {
|
|
32
|
-
const
|
|
30
|
+
const unsub = store.subscribe((state, key) => {
|
|
31
|
+
if (key === dispatchKey) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
props.onSubscribe(state);
|
|
35
|
+
});
|
|
33
36
|
return () => {
|
|
34
|
-
|
|
37
|
+
unsub();
|
|
35
38
|
};
|
|
36
39
|
}, []);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// src/use_store_controller.tsx
|
|
40
|
-
function useStoreController(store, props) {
|
|
41
|
-
const dispatchKey = (0, import_react2.useId)();
|
|
42
|
-
useSubscribe(store, (state, key) => {
|
|
43
|
-
if (key === dispatchKey) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
props.onSubscribe(state);
|
|
47
|
-
});
|
|
48
40
|
const dispatch = () => {
|
|
49
41
|
store.dispatch(
|
|
50
42
|
(state) => {
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
// src/use_store_controller.tsx
|
|
2
|
-
import { useId } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { useEffect } from "react";
|
|
6
|
-
function useSubscribe(store, subscriber) {
|
|
2
|
+
import { useEffect, useId } from "react";
|
|
3
|
+
function useStoreController(store, props) {
|
|
4
|
+
const dispatchKey = useId();
|
|
7
5
|
useEffect(() => {
|
|
8
|
-
const
|
|
6
|
+
const unsub = store.subscribe((state, key) => {
|
|
7
|
+
if (key === dispatchKey) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
props.onSubscribe(state);
|
|
11
|
+
});
|
|
9
12
|
return () => {
|
|
10
|
-
|
|
13
|
+
unsub();
|
|
11
14
|
};
|
|
12
15
|
}, []);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/use_store_controller.tsx
|
|
16
|
-
function useStoreController(store, props) {
|
|
17
|
-
const dispatchKey = useId();
|
|
18
|
-
useSubscribe(store, (state, key) => {
|
|
19
|
-
if (key === dispatchKey) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
props.onSubscribe(state);
|
|
23
|
-
});
|
|
24
16
|
const dispatch = () => {
|
|
25
17
|
store.dispatch(
|
|
26
18
|
(state) => {
|
package/dist/use_store_input.js
CHANGED
|
@@ -26,28 +26,20 @@ module.exports = __toCommonJS(use_store_input_exports);
|
|
|
26
26
|
var import_date_fns = require("date-fns");
|
|
27
27
|
|
|
28
28
|
// src/use_store_controller.tsx
|
|
29
|
-
var import_react2 = require("react");
|
|
30
|
-
|
|
31
|
-
// src/use_subscribe.tsx
|
|
32
29
|
var import_react = require("react");
|
|
33
|
-
function
|
|
30
|
+
function useStoreController(store, props) {
|
|
31
|
+
const dispatchKey = (0, import_react.useId)();
|
|
34
32
|
(0, import_react.useEffect)(() => {
|
|
35
|
-
const
|
|
33
|
+
const unsub = store.subscribe((state, key) => {
|
|
34
|
+
if (key === dispatchKey) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
props.onSubscribe(state);
|
|
38
|
+
});
|
|
36
39
|
return () => {
|
|
37
|
-
|
|
40
|
+
unsub();
|
|
38
41
|
};
|
|
39
42
|
}, []);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// src/use_store_controller.tsx
|
|
43
|
-
function useStoreController(store, props) {
|
|
44
|
-
const dispatchKey = (0, import_react2.useId)();
|
|
45
|
-
useSubscribe(store, (state, key) => {
|
|
46
|
-
if (key === dispatchKey) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
props.onSubscribe(state);
|
|
50
|
-
});
|
|
51
43
|
const dispatch = () => {
|
|
52
44
|
store.dispatch(
|
|
53
45
|
(state) => {
|
package/dist/use_store_input.mjs
CHANGED
|
@@ -2,28 +2,20 @@
|
|
|
2
2
|
import { format } from "date-fns";
|
|
3
3
|
|
|
4
4
|
// src/use_store_controller.tsx
|
|
5
|
-
import { useId } from "react";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { useEffect } from "react";
|
|
9
|
-
function useSubscribe(store, subscriber) {
|
|
5
|
+
import { useEffect, useId } from "react";
|
|
6
|
+
function useStoreController(store, props) {
|
|
7
|
+
const dispatchKey = useId();
|
|
10
8
|
useEffect(() => {
|
|
11
|
-
const
|
|
9
|
+
const unsub = store.subscribe((state, key) => {
|
|
10
|
+
if (key === dispatchKey) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
props.onSubscribe(state);
|
|
14
|
+
});
|
|
12
15
|
return () => {
|
|
13
|
-
|
|
16
|
+
unsub();
|
|
14
17
|
};
|
|
15
18
|
}, []);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/use_store_controller.tsx
|
|
19
|
-
function useStoreController(store, props) {
|
|
20
|
-
const dispatchKey = useId();
|
|
21
|
-
useSubscribe(store, (state, key) => {
|
|
22
|
-
if (key === dispatchKey) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
props.onSubscribe(state);
|
|
26
|
-
});
|
|
27
19
|
const dispatch = () => {
|
|
28
20
|
store.dispatch(
|
|
29
21
|
(state) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { RefObject } from 'react';
|
|
3
|
-
import { Store } from '
|
|
3
|
+
import { Store } from 'gw-store';
|
|
4
4
|
import { StoreInputProps } from './use_store_input.mjs';
|
|
5
5
|
|
|
6
6
|
type InferNameFromProps<TState, TName extends keyof TState | undefined, TValue> = undefined extends TName ? TValue : TName extends keyof TState ? TState[TName] : TValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { RefObject } from 'react';
|
|
3
|
-
import { Store } from '
|
|
3
|
+
import { Store } from 'gw-store';
|
|
4
4
|
import { StoreInputProps } from './use_store_input.js';
|
|
5
5
|
|
|
6
6
|
type InferNameFromProps<TState, TName extends keyof TState | undefined, TValue> = undefined extends TName ? TValue : TName extends keyof TState ? TState[TName] : TValue;
|
|
@@ -28,28 +28,20 @@ module.exports = __toCommonJS(use_store_input_with_name_exports);
|
|
|
28
28
|
var import_date_fns = require("date-fns");
|
|
29
29
|
|
|
30
30
|
// src/use_store_controller.tsx
|
|
31
|
-
var import_react2 = require("react");
|
|
32
|
-
|
|
33
|
-
// src/use_subscribe.tsx
|
|
34
31
|
var import_react = require("react");
|
|
35
|
-
function
|
|
32
|
+
function useStoreController(store, props) {
|
|
33
|
+
const dispatchKey = (0, import_react.useId)();
|
|
36
34
|
(0, import_react.useEffect)(() => {
|
|
37
|
-
const
|
|
35
|
+
const unsub = store.subscribe((state, key) => {
|
|
36
|
+
if (key === dispatchKey) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
props.onSubscribe(state);
|
|
40
|
+
});
|
|
38
41
|
return () => {
|
|
39
|
-
|
|
42
|
+
unsub();
|
|
40
43
|
};
|
|
41
44
|
}, []);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// src/use_store_controller.tsx
|
|
45
|
-
function useStoreController(store, props) {
|
|
46
|
-
const dispatchKey = (0, import_react2.useId)();
|
|
47
|
-
useSubscribe(store, (state, key) => {
|
|
48
|
-
if (key === dispatchKey) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
props.onSubscribe(state);
|
|
52
|
-
});
|
|
53
45
|
const dispatch = () => {
|
|
54
46
|
store.dispatch(
|
|
55
47
|
(state) => {
|
|
@@ -2,28 +2,20 @@
|
|
|
2
2
|
import { format } from "date-fns";
|
|
3
3
|
|
|
4
4
|
// src/use_store_controller.tsx
|
|
5
|
-
import { useId } from "react";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { useEffect } from "react";
|
|
9
|
-
function useSubscribe(store, subscriber) {
|
|
5
|
+
import { useEffect, useId } from "react";
|
|
6
|
+
function useStoreController(store, props) {
|
|
7
|
+
const dispatchKey = useId();
|
|
10
8
|
useEffect(() => {
|
|
11
|
-
const
|
|
9
|
+
const unsub = store.subscribe((state, key) => {
|
|
10
|
+
if (key === dispatchKey) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
props.onSubscribe(state);
|
|
14
|
+
});
|
|
12
15
|
return () => {
|
|
13
|
-
|
|
16
|
+
unsub();
|
|
14
17
|
};
|
|
15
18
|
}, []);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/use_store_controller.tsx
|
|
19
|
-
function useStoreController(store, props) {
|
|
20
|
-
const dispatchKey = useId();
|
|
21
|
-
useSubscribe(store, (state, key) => {
|
|
22
|
-
if (key === dispatchKey) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
props.onSubscribe(state);
|
|
26
|
-
});
|
|
27
19
|
const dispatch = () => {
|
|
28
20
|
store.dispatch(
|
|
29
21
|
(state) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-store-input",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/
|
|
21
|
+
"url": "git+https://github.com/gawonsoft/react-store-input.git"
|
|
22
22
|
},
|
|
23
23
|
"author": "",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"bugs": {
|
|
26
|
-
"url": "https://github.com/
|
|
26
|
+
"url": "https://github.com/gawonsoft/react-store-input/issues"
|
|
27
27
|
},
|
|
28
|
-
"homepage": "https://github.com/
|
|
28
|
+
"homepage": "https://github.com/gawonsoft/react-store-input#readme",
|
|
29
29
|
"description": "",
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^24.10.1",
|
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"date-fns": "^4.1.0",
|
|
43
|
+
"gw-react-text-editor": "^0.1.4",
|
|
44
|
+
"gw-store": "^0.1.1",
|
|
43
45
|
"immer": "^11.1.3"
|
|
44
46
|
}
|
|
45
47
|
}
|