react-store-input 0.2.5 → 0.4.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 (43) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +179 -201
  3. package/dist/index.d.mts +128 -11
  4. package/dist/index.d.ts +128 -11
  5. package/dist/index.js +559 -249
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +552 -247
  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 → text-editor.js} +31 -51
  12. package/dist/text-editor.js.map +1 -0
  13. package/dist/text-editor.mjs +90 -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.mjs +0 -112
  23. package/dist/use_form_store.d.mts +0 -16
  24. package/dist/use_form_store.d.ts +0 -16
  25. package/dist/use_form_store.js +0 -365
  26. package/dist/use_form_store.mjs +0 -340
  27. package/dist/use_store_component.d.mts +0 -23
  28. package/dist/use_store_component.d.ts +0 -23
  29. package/dist/use_store_component.js +0 -337
  30. package/dist/use_store_component.mjs +0 -311
  31. package/dist/use_store_controller.d.mts +0 -11
  32. package/dist/use_store_controller.d.ts +0 -11
  33. package/dist/use_store_controller.js +0 -57
  34. package/dist/use_store_controller.mjs +0 -32
  35. package/dist/use_store_input.d.mts +0 -22
  36. package/dist/use_store_input.d.ts +0 -22
  37. package/dist/use_store_input.js +0 -151
  38. package/dist/use_store_input.mjs +0 -126
  39. package/dist/use_store_input_with_name.d.mts +0 -17
  40. package/dist/use_store_input_with_name.d.ts +0 -17
  41. package/dist/use_store_input_with_name.js +0 -177
  42. package/dist/use_store_input_with_name.mjs +0 -150
  43. package/tsup.config.ts +0 -9
package/dist/index.d.mts CHANGED
@@ -1,11 +1,128 @@
1
- export { StoreControllerProps, useStoreController } from './use_store_controller.mjs';
2
- export { InferNameFromProps, StoreInputWithNameProps, useStoreInputWithName } from './use_store_input_with_name.mjs';
3
- export { StoreInputProps, useStoreInput } from './use_store_input.mjs';
4
- export { Input, Select, StoreComponentPropsWithStore, StoreInputWithNameComponentProps, Textarea, useStoreComponent } from './use_store_component.mjs';
5
- export { FormStore, useFormStore } from './use_form_store.mjs';
6
- export { TextEditor, TextEditorProps } from './text_editor.mjs';
7
- import 'gw-store';
8
- import 'react';
9
- import 'react/jsx-runtime';
10
- import './create_render.mjs';
11
- import 'gw-react-text-editor';
1
+ import { Immutable, Draft } from 'immer';
2
+ import { Store, EqualityFn } from 'gw-store';
3
+ export * from 'gw-store';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import * as react from 'react';
6
+ import { ReactNode, ChangeEvent, HTMLInputTypeAttribute, RefObject, InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react';
7
+ import { Result } from 'gw-result';
8
+ export { Result, err, ok } from 'gw-result';
9
+
10
+ type StoreControllerProps<TState extends object> = {
11
+ onSubscribe: (state: Immutable<TState>) => void;
12
+ onDispatch: (state: Draft<TState>) => void;
13
+ };
14
+ declare function useStoreController<TState extends object>(store: Store<TState>, props: StoreControllerProps<TState>): {
15
+ dispatch: () => void;
16
+ };
17
+
18
+ type CreateRender<TState extends object> = (selector: (state: Immutable<TState>) => ReactNode, compare?: EqualityFn<Immutable<TState>>) => ReactNode;
19
+ declare function createRender<TState extends object>(store: Store<TState>, selector: (state: Immutable<TState>) => ReactNode, compare?: EqualityFn<Immutable<TState>>): react_jsx_runtime.JSX.Element;
20
+ declare function createRenderWithStore<TState extends object>(store: Store<TState>): CreateRender<TState>;
21
+
22
+ type Lens<TState extends object, TValue> = {
23
+ get: (state: Immutable<TState>) => TValue;
24
+ set: (state: Draft<TState>, value: TValue) => void;
25
+ };
26
+ type LensBuilder<TState extends object, TValue> = Lens<TState, TValue> & (TValue extends object ? {
27
+ prop<TKey extends keyof TValue>(key: TKey): LensBuilder<TState, TValue[TKey]>;
28
+ } : object);
29
+ type StateLens<TState extends object> = {
30
+ prop<TKey extends keyof TState>(key: TKey): LensBuilder<TState, TState[TKey]>;
31
+ };
32
+ declare function defineLens<TState extends object, TValue>(lens: Lens<TState, TValue>): Lens<TState, TValue>;
33
+ declare function stateLens<TState extends object>(): StateLens<TState>;
34
+
35
+ type Codec<TValue, TInput, TError = never> = {
36
+ format: (value: TValue) => TInput;
37
+ parse: (input: TInput) => Result<TValue, TError>;
38
+ equals?: (previous: TValue, next: TValue) => boolean;
39
+ };
40
+ declare function defineCodec<TValue, TInput, TError = never>(codec: Codec<TValue, TInput, TError>): Codec<TValue, TInput, TError>;
41
+
42
+ type InputBinding<TState extends object, TValue, TInput, TError = never> = {
43
+ lens: Lens<TState, TValue>;
44
+ codec: Codec<TValue, TInput, TError>;
45
+ };
46
+ declare function defineBinding<TState extends object, TValue, TInput, TError = never>(binding: InputBinding<TState, TValue, TInput, TError>): InputBinding<TState, TValue, TInput, TError>;
47
+
48
+ type Equality<TValue> = (previous: TValue, next: TValue) => boolean;
49
+ declare function assertLensLaws<TState extends object, TValue>(lens: Lens<TState, TValue>, options: {
50
+ state: TState;
51
+ values: readonly TValue[];
52
+ equalsState?: Equality<TState>;
53
+ equalsValue?: Equality<TValue>;
54
+ }): void;
55
+ declare function assertCodecLaws<TValue, TInput, TError>(codec: Codec<TValue, TInput, TError>, options: {
56
+ values: readonly TValue[];
57
+ inputs?: readonly TInput[];
58
+ equals?: Equality<TValue>;
59
+ equalsInput?: Equality<TInput>;
60
+ }): void;
61
+
62
+ type InputDisplayValue = string | number | readonly string[];
63
+ type InputStateValue = string | string[];
64
+ type InputControlValue = string | readonly string[] | number | boolean | FileList | null;
65
+ type StoreInputOptions<TInputElement> = {
66
+ type?: HTMLInputTypeAttribute;
67
+ defaultValue?: InputDisplayValue;
68
+ value?: InputDisplayValue;
69
+ checked?: boolean;
70
+ defaultChecked?: boolean;
71
+ multiple?: boolean;
72
+ onChange?: (event: ChangeEvent<TInputElement>) => void;
73
+ };
74
+ type StoreInputBindingOptions<TInputElement, TValue> = StoreInputOptions<TInputElement> & {
75
+ resetValue?: TValue;
76
+ };
77
+ type StoreInputDomProps<TInputElement> = {
78
+ defaultValue?: InputDisplayValue;
79
+ defaultChecked?: boolean;
80
+ onChange: (event: ChangeEvent<TInputElement>) => void;
81
+ };
82
+ type StoreInputMeta<TError> = {
83
+ valid: true;
84
+ error?: never;
85
+ } | {
86
+ valid: false;
87
+ error: TError;
88
+ };
89
+ type BindingInputResult<TInputElement, TError> = {
90
+ inputProps: StoreInputDomProps<TInputElement>;
91
+ meta: StoreInputMeta<TError>;
92
+ };
93
+
94
+ type StoreElement$2 = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
95
+ declare function useStoreInput<TInputElement extends StoreElement$2, TState extends object, TValue, TInput extends InputControlValue, TError>(ref: RefObject<TInputElement | null>, store: Store<TState>, binding: InputBinding<TState, TValue, TInput, TError>, options?: StoreInputBindingOptions<TInputElement, TValue>): BindingInputResult<TInputElement, TError>;
96
+
97
+ type StoreElement$1 = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
98
+ type StoreInputWithNameProps<TInputElement, TState extends object, TName extends keyof TState> = StoreInputOptions<TInputElement> & {
99
+ name: TName;
100
+ };
101
+ declare function useStoreInputWithName<TInputElement extends StoreElement$1, TState extends object, TName extends keyof TState>(ref: RefObject<TInputElement | null>, store: Store<TState>, props: StoreInputWithNameProps<TInputElement, TState, TName>): {
102
+ name: string;
103
+ defaultValue?: InputDisplayValue;
104
+ defaultChecked?: boolean;
105
+ onChange: (event: react.ChangeEvent<TInputElement>) => void;
106
+ };
107
+
108
+ type StoreElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
109
+ type ElementAttributes<TElement extends StoreElement> = TElement extends HTMLInputElement ? InputHTMLAttributes<HTMLInputElement> : TElement extends HTMLSelectElement ? SelectHTMLAttributes<HTMLSelectElement> : TextareaHTMLAttributes<HTMLTextAreaElement>;
110
+ type StoreInputWithNameComponentProps<TElement extends StoreElement, TState extends object, TName extends keyof TState> = StoreInputWithNameProps<TElement, TState, TName> & Omit<ElementAttributes<TElement>, keyof StoreInputWithNameProps<TElement, TState, TName>>;
111
+ type StoreComponentPropsWithStore<TElement extends StoreElement, TState extends object, TName extends keyof TState> = StoreInputWithNameComponentProps<TElement, TState, TName> & {
112
+ store: Store<TState>;
113
+ };
114
+ declare function Input<TState extends object, TName extends keyof TState>({ store, ...props }: StoreComponentPropsWithStore<HTMLInputElement, TState, TName>): react_jsx_runtime.JSX.Element;
115
+ declare function Select<TState extends object, TName extends keyof TState>({ store, ...props }: StoreComponentPropsWithStore<HTMLSelectElement, TState, TName>): react_jsx_runtime.JSX.Element;
116
+ declare function Textarea<TState extends object, TName extends keyof TState>({ store, ...props }: StoreComponentPropsWithStore<HTMLTextAreaElement, TState, TName>): react_jsx_runtime.JSX.Element;
117
+ declare function useStoreComponent<TState extends object>(store: Store<TState>): {
118
+ input: <TName extends keyof TState>(props: StoreInputWithNameComponentProps<HTMLInputElement, TState, TName>) => react_jsx_runtime.JSX.Element;
119
+ select: <TName extends keyof TState>(props: StoreInputWithNameComponentProps<HTMLSelectElement, TState, TName>) => react_jsx_runtime.JSX.Element;
120
+ textarea: <TName extends keyof TState>(props: StoreInputWithNameComponentProps<HTMLTextAreaElement, TState, TName>) => react_jsx_runtime.JSX.Element;
121
+ };
122
+
123
+ type FormStore<TState extends object> = Store<TState> & ReturnType<typeof useStoreComponent<TState>> & {
124
+ render: CreateRender<TState>;
125
+ };
126
+ declare function useFormStore<TState extends object>(initialState: TState): FormStore<TState>;
127
+
128
+ export { type BindingInputResult, type Codec, type CreateRender, type FormStore, Input, type InputBinding, type InputControlValue, type InputDisplayValue, type InputStateValue, type Lens, type LensBuilder, Select, type StateLens, type StoreComponentPropsWithStore, type StoreControllerProps, type StoreInputBindingOptions, type StoreInputDomProps, type StoreInputMeta, type StoreInputOptions, type StoreInputWithNameComponentProps, type StoreInputWithNameProps, Textarea, assertCodecLaws, assertLensLaws, createRender, createRenderWithStore, defineBinding, defineCodec, defineLens, stateLens, useFormStore, useStoreComponent, useStoreController, useStoreInput, useStoreInputWithName };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,128 @@
1
- export { StoreControllerProps, useStoreController } from './use_store_controller.js';
2
- export { InferNameFromProps, StoreInputWithNameProps, useStoreInputWithName } from './use_store_input_with_name.js';
3
- export { StoreInputProps, useStoreInput } from './use_store_input.js';
4
- export { Input, Select, StoreComponentPropsWithStore, StoreInputWithNameComponentProps, Textarea, useStoreComponent } from './use_store_component.js';
5
- export { FormStore, useFormStore } from './use_form_store.js';
6
- export { TextEditor, TextEditorProps } from './text_editor.js';
7
- import 'gw-store';
8
- import 'react';
9
- import 'react/jsx-runtime';
10
- import './create_render.js';
11
- import 'gw-react-text-editor';
1
+ import { Immutable, Draft } from 'immer';
2
+ import { Store, EqualityFn } from 'gw-store';
3
+ export * from 'gw-store';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import * as react from 'react';
6
+ import { ReactNode, ChangeEvent, HTMLInputTypeAttribute, RefObject, InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react';
7
+ import { Result } from 'gw-result';
8
+ export { Result, err, ok } from 'gw-result';
9
+
10
+ type StoreControllerProps<TState extends object> = {
11
+ onSubscribe: (state: Immutable<TState>) => void;
12
+ onDispatch: (state: Draft<TState>) => void;
13
+ };
14
+ declare function useStoreController<TState extends object>(store: Store<TState>, props: StoreControllerProps<TState>): {
15
+ dispatch: () => void;
16
+ };
17
+
18
+ type CreateRender<TState extends object> = (selector: (state: Immutable<TState>) => ReactNode, compare?: EqualityFn<Immutable<TState>>) => ReactNode;
19
+ declare function createRender<TState extends object>(store: Store<TState>, selector: (state: Immutable<TState>) => ReactNode, compare?: EqualityFn<Immutable<TState>>): react_jsx_runtime.JSX.Element;
20
+ declare function createRenderWithStore<TState extends object>(store: Store<TState>): CreateRender<TState>;
21
+
22
+ type Lens<TState extends object, TValue> = {
23
+ get: (state: Immutable<TState>) => TValue;
24
+ set: (state: Draft<TState>, value: TValue) => void;
25
+ };
26
+ type LensBuilder<TState extends object, TValue> = Lens<TState, TValue> & (TValue extends object ? {
27
+ prop<TKey extends keyof TValue>(key: TKey): LensBuilder<TState, TValue[TKey]>;
28
+ } : object);
29
+ type StateLens<TState extends object> = {
30
+ prop<TKey extends keyof TState>(key: TKey): LensBuilder<TState, TState[TKey]>;
31
+ };
32
+ declare function defineLens<TState extends object, TValue>(lens: Lens<TState, TValue>): Lens<TState, TValue>;
33
+ declare function stateLens<TState extends object>(): StateLens<TState>;
34
+
35
+ type Codec<TValue, TInput, TError = never> = {
36
+ format: (value: TValue) => TInput;
37
+ parse: (input: TInput) => Result<TValue, TError>;
38
+ equals?: (previous: TValue, next: TValue) => boolean;
39
+ };
40
+ declare function defineCodec<TValue, TInput, TError = never>(codec: Codec<TValue, TInput, TError>): Codec<TValue, TInput, TError>;
41
+
42
+ type InputBinding<TState extends object, TValue, TInput, TError = never> = {
43
+ lens: Lens<TState, TValue>;
44
+ codec: Codec<TValue, TInput, TError>;
45
+ };
46
+ declare function defineBinding<TState extends object, TValue, TInput, TError = never>(binding: InputBinding<TState, TValue, TInput, TError>): InputBinding<TState, TValue, TInput, TError>;
47
+
48
+ type Equality<TValue> = (previous: TValue, next: TValue) => boolean;
49
+ declare function assertLensLaws<TState extends object, TValue>(lens: Lens<TState, TValue>, options: {
50
+ state: TState;
51
+ values: readonly TValue[];
52
+ equalsState?: Equality<TState>;
53
+ equalsValue?: Equality<TValue>;
54
+ }): void;
55
+ declare function assertCodecLaws<TValue, TInput, TError>(codec: Codec<TValue, TInput, TError>, options: {
56
+ values: readonly TValue[];
57
+ inputs?: readonly TInput[];
58
+ equals?: Equality<TValue>;
59
+ equalsInput?: Equality<TInput>;
60
+ }): void;
61
+
62
+ type InputDisplayValue = string | number | readonly string[];
63
+ type InputStateValue = string | string[];
64
+ type InputControlValue = string | readonly string[] | number | boolean | FileList | null;
65
+ type StoreInputOptions<TInputElement> = {
66
+ type?: HTMLInputTypeAttribute;
67
+ defaultValue?: InputDisplayValue;
68
+ value?: InputDisplayValue;
69
+ checked?: boolean;
70
+ defaultChecked?: boolean;
71
+ multiple?: boolean;
72
+ onChange?: (event: ChangeEvent<TInputElement>) => void;
73
+ };
74
+ type StoreInputBindingOptions<TInputElement, TValue> = StoreInputOptions<TInputElement> & {
75
+ resetValue?: TValue;
76
+ };
77
+ type StoreInputDomProps<TInputElement> = {
78
+ defaultValue?: InputDisplayValue;
79
+ defaultChecked?: boolean;
80
+ onChange: (event: ChangeEvent<TInputElement>) => void;
81
+ };
82
+ type StoreInputMeta<TError> = {
83
+ valid: true;
84
+ error?: never;
85
+ } | {
86
+ valid: false;
87
+ error: TError;
88
+ };
89
+ type BindingInputResult<TInputElement, TError> = {
90
+ inputProps: StoreInputDomProps<TInputElement>;
91
+ meta: StoreInputMeta<TError>;
92
+ };
93
+
94
+ type StoreElement$2 = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
95
+ declare function useStoreInput<TInputElement extends StoreElement$2, TState extends object, TValue, TInput extends InputControlValue, TError>(ref: RefObject<TInputElement | null>, store: Store<TState>, binding: InputBinding<TState, TValue, TInput, TError>, options?: StoreInputBindingOptions<TInputElement, TValue>): BindingInputResult<TInputElement, TError>;
96
+
97
+ type StoreElement$1 = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
98
+ type StoreInputWithNameProps<TInputElement, TState extends object, TName extends keyof TState> = StoreInputOptions<TInputElement> & {
99
+ name: TName;
100
+ };
101
+ declare function useStoreInputWithName<TInputElement extends StoreElement$1, TState extends object, TName extends keyof TState>(ref: RefObject<TInputElement | null>, store: Store<TState>, props: StoreInputWithNameProps<TInputElement, TState, TName>): {
102
+ name: string;
103
+ defaultValue?: InputDisplayValue;
104
+ defaultChecked?: boolean;
105
+ onChange: (event: react.ChangeEvent<TInputElement>) => void;
106
+ };
107
+
108
+ type StoreElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
109
+ type ElementAttributes<TElement extends StoreElement> = TElement extends HTMLInputElement ? InputHTMLAttributes<HTMLInputElement> : TElement extends HTMLSelectElement ? SelectHTMLAttributes<HTMLSelectElement> : TextareaHTMLAttributes<HTMLTextAreaElement>;
110
+ type StoreInputWithNameComponentProps<TElement extends StoreElement, TState extends object, TName extends keyof TState> = StoreInputWithNameProps<TElement, TState, TName> & Omit<ElementAttributes<TElement>, keyof StoreInputWithNameProps<TElement, TState, TName>>;
111
+ type StoreComponentPropsWithStore<TElement extends StoreElement, TState extends object, TName extends keyof TState> = StoreInputWithNameComponentProps<TElement, TState, TName> & {
112
+ store: Store<TState>;
113
+ };
114
+ declare function Input<TState extends object, TName extends keyof TState>({ store, ...props }: StoreComponentPropsWithStore<HTMLInputElement, TState, TName>): react_jsx_runtime.JSX.Element;
115
+ declare function Select<TState extends object, TName extends keyof TState>({ store, ...props }: StoreComponentPropsWithStore<HTMLSelectElement, TState, TName>): react_jsx_runtime.JSX.Element;
116
+ declare function Textarea<TState extends object, TName extends keyof TState>({ store, ...props }: StoreComponentPropsWithStore<HTMLTextAreaElement, TState, TName>): react_jsx_runtime.JSX.Element;
117
+ declare function useStoreComponent<TState extends object>(store: Store<TState>): {
118
+ input: <TName extends keyof TState>(props: StoreInputWithNameComponentProps<HTMLInputElement, TState, TName>) => react_jsx_runtime.JSX.Element;
119
+ select: <TName extends keyof TState>(props: StoreInputWithNameComponentProps<HTMLSelectElement, TState, TName>) => react_jsx_runtime.JSX.Element;
120
+ textarea: <TName extends keyof TState>(props: StoreInputWithNameComponentProps<HTMLTextAreaElement, TState, TName>) => react_jsx_runtime.JSX.Element;
121
+ };
122
+
123
+ type FormStore<TState extends object> = Store<TState> & ReturnType<typeof useStoreComponent<TState>> & {
124
+ render: CreateRender<TState>;
125
+ };
126
+ declare function useFormStore<TState extends object>(initialState: TState): FormStore<TState>;
127
+
128
+ export { type BindingInputResult, type Codec, type CreateRender, type FormStore, Input, type InputBinding, type InputControlValue, type InputDisplayValue, type InputStateValue, type Lens, type LensBuilder, Select, type StateLens, type StoreComponentPropsWithStore, type StoreControllerProps, type StoreInputBindingOptions, type StoreInputDomProps, type StoreInputMeta, type StoreInputOptions, type StoreInputWithNameComponentProps, type StoreInputWithNameProps, Textarea, assertCodecLaws, assertLensLaws, createRender, createRenderWithStore, defineBinding, defineCodec, defineLens, stateLens, useFormStore, useStoreComponent, useStoreController, useStoreInput, useStoreInputWithName };