react-store-input 0.1.6 → 0.1.8

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/index.d.mts CHANGED
@@ -4,7 +4,7 @@ export { useSubscribe } from './use_subscribe.mjs';
4
4
  export { StoreControllerProps, useStoreController } from './use_store_controller.mjs';
5
5
  export { InferNameFromProps, StoreInputWithNameProps, useStoreInputWithName } from './use_store_input_with_name.mjs';
6
6
  export { StoreInputProps, useStoreInput } from './use_store_input.mjs';
7
- export { Input, Select, StoreComponentPropsWithStore, Textarea, useStoreComponent } from './use_store_component.mjs';
7
+ export { Input, Select, StoreComponentPropsWithStore, StoreInputWithNameComponentProps, Textarea, useStoreComponent } from './use_store_component.mjs';
8
8
  export { FormStore, useFormStore } from './use_form_store.mjs';
9
9
  import 'react';
10
10
  import './create_render.mjs';
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { useSubscribe } from './use_subscribe.js';
4
4
  export { StoreControllerProps, useStoreController } from './use_store_controller.js';
5
5
  export { InferNameFromProps, StoreInputWithNameProps, useStoreInputWithName } from './use_store_input_with_name.js';
6
6
  export { StoreInputProps, useStoreInput } from './use_store_input.js';
7
- export { Input, Select, StoreComponentPropsWithStore, Textarea, useStoreComponent } from './use_store_component.js';
7
+ export { Input, Select, StoreComponentPropsWithStore, StoreInputWithNameComponentProps, Textarea, useStoreComponent } from './use_store_component.js';
8
8
  export { FormStore, useFormStore } from './use_form_store.js';
9
9
  import 'react';
10
10
  import './create_render.js';
package/dist/index.js CHANGED
@@ -118,22 +118,17 @@ function useSelector(store, selector, compare = (a, b) => a === b) {
118
118
  // src/use_store_controller.tsx
119
119
  var import_react4 = require("react");
120
120
  function useStoreController(store, props) {
121
- const ref = (0, import_react4.useRef)(null);
122
- (0, import_react4.useImperativeHandle)(props.ref, () => ref.current, []);
123
121
  const dispatchKey = (0, import_react4.useId)();
124
122
  useSubscribe(store, (state, key) => {
125
123
  if (key === dispatchKey) {
126
124
  return;
127
125
  }
128
- if (!ref.current) return;
129
- props.onSubscribe(state, ref.current);
126
+ props.onSubscribe(state);
130
127
  });
131
128
  const dispatch = () => {
132
129
  store.dispatch(
133
130
  (state) => {
134
- const element = ref.current;
135
- if (!element) return;
136
- props.onDispatch(state, element);
131
+ props.onDispatch(state);
137
132
  },
138
133
  {
139
134
  key: dispatchKey
@@ -141,7 +136,6 @@ function useStoreController(store, props) {
141
136
  );
142
137
  };
143
138
  return {
144
- ref,
145
139
  dispatch
146
140
  };
147
141
  }
@@ -149,7 +143,7 @@ function useStoreController(store, props) {
149
143
  // src/use_store_input.tsx
150
144
  var import_react5 = require("react");
151
145
  var import_date_fns = require("date-fns");
152
- function useStoreInput(store, props) {
146
+ function useStoreInput(ref, store, props) {
153
147
  const toInputValue = props.toInputValue || ((value) => {
154
148
  if (value === void 0 || value === null) {
155
149
  return "";
@@ -196,8 +190,11 @@ function useStoreInput(store, props) {
196
190
  return value;
197
191
  });
198
192
  const inputProps = useStoreController(store, {
199
- ref: props.ref,
200
- onSubscribe: (state, element) => {
193
+ onSubscribe: (state) => {
194
+ const element = ref.current;
195
+ if (!element) {
196
+ return;
197
+ }
201
198
  if ("checked" in element && (props.type === "checkbox" || props.type === "radio")) {
202
199
  const checked = toInputChecked(props.getter(state));
203
200
  if (element.checked === checked) {
@@ -214,7 +211,11 @@ function useStoreInput(store, props) {
214
211
  const event = new Event("input", { bubbles: true });
215
212
  element.dispatchEvent(event);
216
213
  },
217
- onDispatch: (state, element) => {
214
+ onDispatch: (state) => {
215
+ const element = ref.current;
216
+ if (!element) {
217
+ return;
218
+ }
218
219
  if ("checked" in element && props.type === "checkbox") {
219
220
  props.setter(state, element.checked);
220
221
  } else {
@@ -223,7 +224,6 @@ function useStoreInput(store, props) {
223
224
  }
224
225
  });
225
226
  return {
226
- ref: inputProps.ref,
227
227
  defaultValue: getDefaultValue(),
228
228
  defaultChecked: getDefaultChecked(),
229
229
  onChange: (event) => {
@@ -234,8 +234,8 @@ function useStoreInput(store, props) {
234
234
  }
235
235
 
236
236
  // src/use_store_input_with_name.tsx
237
- function useStoreInputWithName(store, props) {
238
- const inputProps = useStoreInput(store, {
237
+ function useStoreInputWithName(ref, store, props) {
238
+ const inputProps = useStoreInput(ref, store, {
239
239
  ...props,
240
240
  getter: (state) => {
241
241
  if (props.getter) {
@@ -293,7 +293,8 @@ function Input({
293
293
  toStateValue,
294
294
  ...props
295
295
  }) {
296
- const storeProps = useStoreInputWithName(store, {
296
+ const ref = (0, import_react6.useRef)(null);
297
+ const storeProps = useStoreInputWithName(ref, store, {
297
298
  ...props,
298
299
  getter,
299
300
  setter,
@@ -310,7 +311,8 @@ function Select({
310
311
  toStateValue,
311
312
  ...props
312
313
  }) {
313
- const storeProps = useStoreInputWithName(store, {
314
+ const ref = (0, import_react6.useRef)(null);
315
+ const storeProps = useStoreInputWithName(ref, store, {
314
316
  ...props,
315
317
  getter,
316
318
  setter,
@@ -327,7 +329,8 @@ function Textarea({
327
329
  toStateValue,
328
330
  ...props
329
331
  }) {
330
- const storeProps = useStoreInputWithName(store, {
332
+ const ref = (0, import_react6.useRef)(null);
333
+ const storeProps = useStoreInputWithName(ref, store, {
331
334
  ...props,
332
335
  getter,
333
336
  setter,
package/dist/index.mjs CHANGED
@@ -70,24 +70,19 @@ function useSelector(store, selector, compare = (a, b) => a === b) {
70
70
  }
71
71
 
72
72
  // src/use_store_controller.tsx
73
- import { useId, useImperativeHandle, useRef as useRef2 } from "react";
73
+ import { useId } from "react";
74
74
  function useStoreController(store, props) {
75
- const ref = useRef2(null);
76
- useImperativeHandle(props.ref, () => ref.current, []);
77
75
  const dispatchKey = useId();
78
76
  useSubscribe(store, (state, key) => {
79
77
  if (key === dispatchKey) {
80
78
  return;
81
79
  }
82
- if (!ref.current) return;
83
- props.onSubscribe(state, ref.current);
80
+ props.onSubscribe(state);
84
81
  });
85
82
  const dispatch = () => {
86
83
  store.dispatch(
87
84
  (state) => {
88
- const element = ref.current;
89
- if (!element) return;
90
- props.onDispatch(state, element);
85
+ props.onDispatch(state);
91
86
  },
92
87
  {
93
88
  key: dispatchKey
@@ -95,7 +90,6 @@ function useStoreController(store, props) {
95
90
  );
96
91
  };
97
92
  return {
98
- ref,
99
93
  dispatch
100
94
  };
101
95
  }
@@ -103,7 +97,7 @@ function useStoreController(store, props) {
103
97
  // src/use_store_input.tsx
104
98
  import "react";
105
99
  import { format } from "date-fns";
106
- function useStoreInput(store, props) {
100
+ function useStoreInput(ref, store, props) {
107
101
  const toInputValue = props.toInputValue || ((value) => {
108
102
  if (value === void 0 || value === null) {
109
103
  return "";
@@ -150,8 +144,11 @@ function useStoreInput(store, props) {
150
144
  return value;
151
145
  });
152
146
  const inputProps = useStoreController(store, {
153
- ref: props.ref,
154
- onSubscribe: (state, element) => {
147
+ onSubscribe: (state) => {
148
+ const element = ref.current;
149
+ if (!element) {
150
+ return;
151
+ }
155
152
  if ("checked" in element && (props.type === "checkbox" || props.type === "radio")) {
156
153
  const checked = toInputChecked(props.getter(state));
157
154
  if (element.checked === checked) {
@@ -168,7 +165,11 @@ function useStoreInput(store, props) {
168
165
  const event = new Event("input", { bubbles: true });
169
166
  element.dispatchEvent(event);
170
167
  },
171
- onDispatch: (state, element) => {
168
+ onDispatch: (state) => {
169
+ const element = ref.current;
170
+ if (!element) {
171
+ return;
172
+ }
172
173
  if ("checked" in element && props.type === "checkbox") {
173
174
  props.setter(state, element.checked);
174
175
  } else {
@@ -177,7 +178,6 @@ function useStoreInput(store, props) {
177
178
  }
178
179
  });
179
180
  return {
180
- ref: inputProps.ref,
181
181
  defaultValue: getDefaultValue(),
182
182
  defaultChecked: getDefaultChecked(),
183
183
  onChange: (event) => {
@@ -188,8 +188,8 @@ function useStoreInput(store, props) {
188
188
  }
189
189
 
190
190
  // src/use_store_input_with_name.tsx
191
- function useStoreInputWithName(store, props) {
192
- const inputProps = useStoreInput(store, {
191
+ function useStoreInputWithName(ref, store, props) {
192
+ const inputProps = useStoreInput(ref, store, {
193
193
  ...props,
194
194
  getter: (state) => {
195
195
  if (props.getter) {
@@ -212,7 +212,7 @@ function useStoreInputWithName(store, props) {
212
212
  }
213
213
 
214
214
  // src/use_store_component.tsx
215
- import { useCallback } from "react";
215
+ import { useCallback, useRef as useRef2 } from "react";
216
216
  import React from "react";
217
217
  function useStoreComponent(store) {
218
218
  const input = useCallback(
@@ -247,7 +247,8 @@ function Input({
247
247
  toStateValue,
248
248
  ...props
249
249
  }) {
250
- const storeProps = useStoreInputWithName(store, {
250
+ const ref = useRef2(null);
251
+ const storeProps = useStoreInputWithName(ref, store, {
251
252
  ...props,
252
253
  getter,
253
254
  setter,
@@ -264,7 +265,8 @@ function Select({
264
265
  toStateValue,
265
266
  ...props
266
267
  }) {
267
- const storeProps = useStoreInputWithName(store, {
268
+ const ref = useRef2(null);
269
+ const storeProps = useStoreInputWithName(ref, store, {
268
270
  ...props,
269
271
  getter,
270
272
  setter,
@@ -281,7 +283,8 @@ function Textarea({
281
283
  toStateValue,
282
284
  ...props
283
285
  }) {
284
- const storeProps = useStoreInputWithName(store, {
286
+ const ref = useRef2(null);
287
+ const storeProps = useStoreInputWithName(ref, store, {
285
288
  ...props,
286
289
  getter,
287
290
  setter,
@@ -129,22 +129,17 @@ var import_date_fns = require("date-fns");
129
129
  // src/use_store_controller.tsx
130
130
  var import_react5 = require("react");
131
131
  function useStoreController(store, props) {
132
- const ref = (0, import_react5.useRef)(null);
133
- (0, import_react5.useImperativeHandle)(props.ref, () => ref.current, []);
134
132
  const dispatchKey = (0, import_react5.useId)();
135
133
  useSubscribe(store, (state, key) => {
136
134
  if (key === dispatchKey) {
137
135
  return;
138
136
  }
139
- if (!ref.current) return;
140
- props.onSubscribe(state, ref.current);
137
+ props.onSubscribe(state);
141
138
  });
142
139
  const dispatch = () => {
143
140
  store.dispatch(
144
141
  (state) => {
145
- const element = ref.current;
146
- if (!element) return;
147
- props.onDispatch(state, element);
142
+ props.onDispatch(state);
148
143
  },
149
144
  {
150
145
  key: dispatchKey
@@ -152,13 +147,12 @@ function useStoreController(store, props) {
152
147
  );
153
148
  };
154
149
  return {
155
- ref,
156
150
  dispatch
157
151
  };
158
152
  }
159
153
 
160
154
  // src/use_store_input.tsx
161
- function useStoreInput(store, props) {
155
+ function useStoreInput(ref, store, props) {
162
156
  const toInputValue = props.toInputValue || ((value) => {
163
157
  if (value === void 0 || value === null) {
164
158
  return "";
@@ -205,8 +199,11 @@ function useStoreInput(store, props) {
205
199
  return value;
206
200
  });
207
201
  const inputProps = useStoreController(store, {
208
- ref: props.ref,
209
- onSubscribe: (state, element) => {
202
+ onSubscribe: (state) => {
203
+ const element = ref.current;
204
+ if (!element) {
205
+ return;
206
+ }
210
207
  if ("checked" in element && (props.type === "checkbox" || props.type === "radio")) {
211
208
  const checked = toInputChecked(props.getter(state));
212
209
  if (element.checked === checked) {
@@ -223,7 +220,11 @@ function useStoreInput(store, props) {
223
220
  const event = new Event("input", { bubbles: true });
224
221
  element.dispatchEvent(event);
225
222
  },
226
- onDispatch: (state, element) => {
223
+ onDispatch: (state) => {
224
+ const element = ref.current;
225
+ if (!element) {
226
+ return;
227
+ }
227
228
  if ("checked" in element && props.type === "checkbox") {
228
229
  props.setter(state, element.checked);
229
230
  } else {
@@ -232,7 +233,6 @@ function useStoreInput(store, props) {
232
233
  }
233
234
  });
234
235
  return {
235
- ref: inputProps.ref,
236
236
  defaultValue: getDefaultValue(),
237
237
  defaultChecked: getDefaultChecked(),
238
238
  onChange: (event) => {
@@ -243,8 +243,8 @@ function useStoreInput(store, props) {
243
243
  }
244
244
 
245
245
  // src/use_store_input_with_name.tsx
246
- function useStoreInputWithName(store, props) {
247
- const inputProps = useStoreInput(store, {
246
+ function useStoreInputWithName(ref, store, props) {
247
+ const inputProps = useStoreInput(ref, store, {
248
248
  ...props,
249
249
  getter: (state) => {
250
250
  if (props.getter) {
@@ -300,7 +300,8 @@ function Input({
300
300
  toStateValue,
301
301
  ...props
302
302
  }) {
303
- const storeProps = useStoreInputWithName(store, {
303
+ const ref = (0, import_react7.useRef)(null);
304
+ const storeProps = useStoreInputWithName(ref, store, {
304
305
  ...props,
305
306
  getter,
306
307
  setter,
@@ -317,7 +318,8 @@ function Select({
317
318
  toStateValue,
318
319
  ...props
319
320
  }) {
320
- const storeProps = useStoreInputWithName(store, {
321
+ const ref = (0, import_react7.useRef)(null);
322
+ const storeProps = useStoreInputWithName(ref, store, {
321
323
  ...props,
322
324
  getter,
323
325
  setter,
@@ -334,7 +336,8 @@ function Textarea({
334
336
  toStateValue,
335
337
  ...props
336
338
  }) {
337
- const storeProps = useStoreInputWithName(store, {
339
+ const ref = (0, import_react7.useRef)(null);
340
+ const storeProps = useStoreInputWithName(ref, store, {
338
341
  ...props,
339
342
  getter,
340
343
  setter,
@@ -83,7 +83,7 @@ function useStore(initialState) {
83
83
  }
84
84
 
85
85
  // src/use_store_component.tsx
86
- import { useCallback } from "react";
86
+ import { useCallback, useRef as useRef2 } from "react";
87
87
  import React2 from "react";
88
88
 
89
89
  // src/use_store_input.tsx
@@ -91,24 +91,19 @@ import "react";
91
91
  import { format } from "date-fns";
92
92
 
93
93
  // src/use_store_controller.tsx
94
- import { useId, useImperativeHandle, useRef as useRef2 } from "react";
94
+ import { useId } from "react";
95
95
  function useStoreController(store, props) {
96
- const ref = useRef2(null);
97
- useImperativeHandle(props.ref, () => ref.current, []);
98
96
  const dispatchKey = useId();
99
97
  useSubscribe(store, (state, key) => {
100
98
  if (key === dispatchKey) {
101
99
  return;
102
100
  }
103
- if (!ref.current) return;
104
- props.onSubscribe(state, ref.current);
101
+ props.onSubscribe(state);
105
102
  });
106
103
  const dispatch = () => {
107
104
  store.dispatch(
108
105
  (state) => {
109
- const element = ref.current;
110
- if (!element) return;
111
- props.onDispatch(state, element);
106
+ props.onDispatch(state);
112
107
  },
113
108
  {
114
109
  key: dispatchKey
@@ -116,13 +111,12 @@ function useStoreController(store, props) {
116
111
  );
117
112
  };
118
113
  return {
119
- ref,
120
114
  dispatch
121
115
  };
122
116
  }
123
117
 
124
118
  // src/use_store_input.tsx
125
- function useStoreInput(store, props) {
119
+ function useStoreInput(ref, store, props) {
126
120
  const toInputValue = props.toInputValue || ((value) => {
127
121
  if (value === void 0 || value === null) {
128
122
  return "";
@@ -169,8 +163,11 @@ function useStoreInput(store, props) {
169
163
  return value;
170
164
  });
171
165
  const inputProps = useStoreController(store, {
172
- ref: props.ref,
173
- onSubscribe: (state, element) => {
166
+ onSubscribe: (state) => {
167
+ const element = ref.current;
168
+ if (!element) {
169
+ return;
170
+ }
174
171
  if ("checked" in element && (props.type === "checkbox" || props.type === "radio")) {
175
172
  const checked = toInputChecked(props.getter(state));
176
173
  if (element.checked === checked) {
@@ -187,7 +184,11 @@ function useStoreInput(store, props) {
187
184
  const event = new Event("input", { bubbles: true });
188
185
  element.dispatchEvent(event);
189
186
  },
190
- onDispatch: (state, element) => {
187
+ onDispatch: (state) => {
188
+ const element = ref.current;
189
+ if (!element) {
190
+ return;
191
+ }
191
192
  if ("checked" in element && props.type === "checkbox") {
192
193
  props.setter(state, element.checked);
193
194
  } else {
@@ -196,7 +197,6 @@ function useStoreInput(store, props) {
196
197
  }
197
198
  });
198
199
  return {
199
- ref: inputProps.ref,
200
200
  defaultValue: getDefaultValue(),
201
201
  defaultChecked: getDefaultChecked(),
202
202
  onChange: (event) => {
@@ -207,8 +207,8 @@ function useStoreInput(store, props) {
207
207
  }
208
208
 
209
209
  // src/use_store_input_with_name.tsx
210
- function useStoreInputWithName(store, props) {
211
- const inputProps = useStoreInput(store, {
210
+ function useStoreInputWithName(ref, store, props) {
211
+ const inputProps = useStoreInput(ref, store, {
212
212
  ...props,
213
213
  getter: (state) => {
214
214
  if (props.getter) {
@@ -264,7 +264,8 @@ function Input({
264
264
  toStateValue,
265
265
  ...props
266
266
  }) {
267
- const storeProps = useStoreInputWithName(store, {
267
+ const ref = useRef2(null);
268
+ const storeProps = useStoreInputWithName(ref, store, {
268
269
  ...props,
269
270
  getter,
270
271
  setter,
@@ -281,7 +282,8 @@ function Select({
281
282
  toStateValue,
282
283
  ...props
283
284
  }) {
284
- const storeProps = useStoreInputWithName(store, {
285
+ const ref = useRef2(null);
286
+ const storeProps = useStoreInputWithName(ref, store, {
285
287
  ...props,
286
288
  getter,
287
289
  setter,
@@ -298,7 +300,8 @@ function Textarea({
298
300
  toStateValue,
299
301
  ...props
300
302
  }) {
301
- const storeProps = useStoreInputWithName(store, {
303
+ const ref = useRef2(null);
304
+ const storeProps = useStoreInputWithName(ref, store, {
302
305
  ...props,
303
306
  getter,
304
307
  setter,
@@ -1,18 +1,19 @@
1
+ import React__default, { DetailedHTMLProps } from 'react';
1
2
  import { Store } from './use_store.mjs';
2
- import React__default from 'react';
3
3
  import { StoreInputWithNameProps } from './use_store_input_with_name.mjs';
4
4
  import './use_store_input.mjs';
5
5
 
6
+ type StoreInputWithNameComponentProps<TElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameProps<TElement, TState, TName, TValue> & Omit<DetailedHTMLProps<React__default.InputHTMLAttributes<TElement>, TElement>, keyof StoreInputWithNameProps<TElement, TState, TName, TValue>>;
6
7
  declare function useStoreComponent<TState>(store: Store<TState>): {
7
- input: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameProps<HTMLInputElement, TState, TName, TValue>) => React__default.JSX.Element;
8
- select: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameProps<HTMLSelectElement, TState, TName, TValue>) => React__default.JSX.Element;
9
- textarea: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameProps<HTMLTextAreaElement, TState, TName, TValue>) => React__default.JSX.Element;
8
+ input: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLInputElement, TState, TName, TValue>) => React__default.JSX.Element;
9
+ select: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLSelectElement, TState, TName, TValue>) => React__default.JSX.Element;
10
+ textarea: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLTextAreaElement, TState, TName, TValue>) => React__default.JSX.Element;
10
11
  };
11
- type StoreComponentPropsWithStore<TElement extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameProps<TElement, TState, TName, TValue> & {
12
+ type StoreComponentPropsWithStore<TElement extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameComponentProps<TElement, TState, TName, TValue> & {
12
13
  store: Store<TState>;
13
14
  };
14
15
  declare function Input<TState, TName extends keyof TState | undefined, TValue>({ store, getter, setter, toInputValue, toStateValue, ...props }: StoreComponentPropsWithStore<HTMLInputElement, TState, TName, TValue>): React__default.JSX.Element;
15
16
  declare function Select<TState, TName extends keyof TState | undefined, TValue>({ store, getter, setter, toInputValue, toStateValue, ...props }: StoreComponentPropsWithStore<HTMLSelectElement, TState, TName, TValue>): React__default.JSX.Element;
16
17
  declare function Textarea<TState, TName extends keyof TState | undefined, TValue>({ store, getter, setter, toInputValue, toStateValue, ...props }: StoreComponentPropsWithStore<HTMLTextAreaElement, TState, TName, TValue>): React__default.JSX.Element;
17
18
 
18
- export { Input, Select, type StoreComponentPropsWithStore, Textarea, useStoreComponent };
19
+ export { Input, Select, type StoreComponentPropsWithStore, type StoreInputWithNameComponentProps, Textarea, useStoreComponent };
@@ -1,18 +1,19 @@
1
+ import React__default, { DetailedHTMLProps } from 'react';
1
2
  import { Store } from './use_store.js';
2
- import React__default from 'react';
3
3
  import { StoreInputWithNameProps } from './use_store_input_with_name.js';
4
4
  import './use_store_input.js';
5
5
 
6
+ type StoreInputWithNameComponentProps<TElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameProps<TElement, TState, TName, TValue> & Omit<DetailedHTMLProps<React__default.InputHTMLAttributes<TElement>, TElement>, keyof StoreInputWithNameProps<TElement, TState, TName, TValue>>;
6
7
  declare function useStoreComponent<TState>(store: Store<TState>): {
7
- input: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameProps<HTMLInputElement, TState, TName, TValue>) => React__default.JSX.Element;
8
- select: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameProps<HTMLSelectElement, TState, TName, TValue>) => React__default.JSX.Element;
9
- textarea: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameProps<HTMLTextAreaElement, TState, TName, TValue>) => React__default.JSX.Element;
8
+ input: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLInputElement, TState, TName, TValue>) => React__default.JSX.Element;
9
+ select: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLSelectElement, TState, TName, TValue>) => React__default.JSX.Element;
10
+ textarea: <TName extends keyof TState | undefined, TValue>(props: StoreInputWithNameComponentProps<HTMLTextAreaElement, TState, TName, TValue>) => React__default.JSX.Element;
10
11
  };
11
- type StoreComponentPropsWithStore<TElement extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameProps<TElement, TState, TName, TValue> & {
12
+ type StoreComponentPropsWithStore<TElement extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, TState, TName extends keyof TState | undefined, TValue> = StoreInputWithNameComponentProps<TElement, TState, TName, TValue> & {
12
13
  store: Store<TState>;
13
14
  };
14
15
  declare function Input<TState, TName extends keyof TState | undefined, TValue>({ store, getter, setter, toInputValue, toStateValue, ...props }: StoreComponentPropsWithStore<HTMLInputElement, TState, TName, TValue>): React__default.JSX.Element;
15
16
  declare function Select<TState, TName extends keyof TState | undefined, TValue>({ store, getter, setter, toInputValue, toStateValue, ...props }: StoreComponentPropsWithStore<HTMLSelectElement, TState, TName, TValue>): React__default.JSX.Element;
16
17
  declare function Textarea<TState, TName extends keyof TState | undefined, TValue>({ store, getter, setter, toInputValue, toStateValue, ...props }: StoreComponentPropsWithStore<HTMLTextAreaElement, TState, TName, TValue>): React__default.JSX.Element;
17
18
 
18
- export { Input, Select, type StoreComponentPropsWithStore, Textarea, useStoreComponent };
19
+ export { Input, Select, type StoreComponentPropsWithStore, type StoreInputWithNameComponentProps, Textarea, useStoreComponent };
@@ -59,22 +59,17 @@ function useSubscribe(store, subscriber) {
59
59
 
60
60
  // src/use_store_controller.tsx
61
61
  function useStoreController(store, props) {
62
- const ref = (0, import_react2.useRef)(null);
63
- (0, import_react2.useImperativeHandle)(props.ref, () => ref.current, []);
64
62
  const dispatchKey = (0, import_react2.useId)();
65
63
  useSubscribe(store, (state, key) => {
66
64
  if (key === dispatchKey) {
67
65
  return;
68
66
  }
69
- if (!ref.current) return;
70
- props.onSubscribe(state, ref.current);
67
+ props.onSubscribe(state);
71
68
  });
72
69
  const dispatch = () => {
73
70
  store.dispatch(
74
71
  (state) => {
75
- const element = ref.current;
76
- if (!element) return;
77
- props.onDispatch(state, element);
72
+ props.onDispatch(state);
78
73
  },
79
74
  {
80
75
  key: dispatchKey
@@ -82,13 +77,12 @@ function useStoreController(store, props) {
82
77
  );
83
78
  };
84
79
  return {
85
- ref,
86
80
  dispatch
87
81
  };
88
82
  }
89
83
 
90
84
  // src/use_store_input.tsx
91
- function useStoreInput(store, props) {
85
+ function useStoreInput(ref, store, props) {
92
86
  const toInputValue = props.toInputValue || ((value) => {
93
87
  if (value === void 0 || value === null) {
94
88
  return "";
@@ -135,8 +129,11 @@ function useStoreInput(store, props) {
135
129
  return value;
136
130
  });
137
131
  const inputProps = useStoreController(store, {
138
- ref: props.ref,
139
- onSubscribe: (state, element) => {
132
+ onSubscribe: (state) => {
133
+ const element = ref.current;
134
+ if (!element) {
135
+ return;
136
+ }
140
137
  if ("checked" in element && (props.type === "checkbox" || props.type === "radio")) {
141
138
  const checked = toInputChecked(props.getter(state));
142
139
  if (element.checked === checked) {
@@ -153,7 +150,11 @@ function useStoreInput(store, props) {
153
150
  const event = new Event("input", { bubbles: true });
154
151
  element.dispatchEvent(event);
155
152
  },
156
- onDispatch: (state, element) => {
153
+ onDispatch: (state) => {
154
+ const element = ref.current;
155
+ if (!element) {
156
+ return;
157
+ }
157
158
  if ("checked" in element && props.type === "checkbox") {
158
159
  props.setter(state, element.checked);
159
160
  } else {
@@ -162,7 +163,6 @@ function useStoreInput(store, props) {
162
163
  }
163
164
  });
164
165
  return {
165
- ref: inputProps.ref,
166
166
  defaultValue: getDefaultValue(),
167
167
  defaultChecked: getDefaultChecked(),
168
168
  onChange: (event) => {
@@ -173,8 +173,8 @@ function useStoreInput(store, props) {
173
173
  }
174
174
 
175
175
  // src/use_store_input_with_name.tsx
176
- function useStoreInputWithName(store, props) {
177
- const inputProps = useStoreInput(store, {
176
+ function useStoreInputWithName(ref, store, props) {
177
+ const inputProps = useStoreInput(ref, store, {
178
178
  ...props,
179
179
  getter: (state) => {
180
180
  if (props.getter) {
@@ -230,7 +230,8 @@ function Input({
230
230
  toStateValue,
231
231
  ...props
232
232
  }) {
233
- const storeProps = useStoreInputWithName(store, {
233
+ const ref = (0, import_react4.useRef)(null);
234
+ const storeProps = useStoreInputWithName(ref, store, {
234
235
  ...props,
235
236
  getter,
236
237
  setter,
@@ -247,7 +248,8 @@ function Select({
247
248
  toStateValue,
248
249
  ...props
249
250
  }) {
250
- const storeProps = useStoreInputWithName(store, {
251
+ const ref = (0, import_react4.useRef)(null);
252
+ const storeProps = useStoreInputWithName(ref, store, {
251
253
  ...props,
252
254
  getter,
253
255
  setter,
@@ -264,7 +266,8 @@ function Textarea({
264
266
  toStateValue,
265
267
  ...props
266
268
  }) {
267
- const storeProps = useStoreInputWithName(store, {
269
+ const ref = (0, import_react4.useRef)(null);
270
+ const storeProps = useStoreInputWithName(ref, store, {
268
271
  ...props,
269
272
  getter,
270
273
  setter,