@gridui/form 0.0.0 → 2.0.1
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/README.md +33 -4
- package/dist/field/field.d.ts +1 -0
- package/dist/field-grid/field-grid.d.ts +3 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +141 -64
- package/dist/index.js.map +4 -4
- package/dist/list-field-control/list-field-control.d.ts +13 -0
- package/dist/shared/field-sizing.d.ts +9 -0
- package/dist/shared/focus-invalid-control.d.ts +8 -0
- package/dist/shared/use-form-reset.d.ts +12 -0
- package/dist/styles.css +22 -29
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @gridui/form
|
|
2
2
|
|
|
3
|
-
Core family. Public API: `ActionForm`, `ActionFormProps`, `Field`, `FieldGrid`, `FieldGridProps`, `FieldNote`, `FieldNoteProps`, `FieldProps`, `Fieldset`, `FieldsetProps`, `ListFieldProps`, `SearchForm`, `SearchFormProps`, `fieldClass`, `runFormAction`, `useListField`, `useUnsavedNavigation`.
|
|
3
|
+
Core family. Public API: `ActionForm`, `ActionFormProps`, `Field`, `FieldGrid`, `FieldGridProps`, `FieldNote`, `FieldNoteProps`, `FieldProps`, `Fieldset`, `FieldsetProps`, `ListFieldControl`, `ListFieldControlProps`, `ListFieldProps`, `SearchForm`, `SearchFormProps`, `fieldClass`, `focusInvalidControl`, `runFormAction`, `useFormReset`, `useListField`, `useUnsavedNavigation`.
|
|
4
4
|
|
|
5
5
|
Import components from `@gridui/form` and load `@gridui/form/styles.css` after Theme.
|
|
6
6
|
Load styles for any composed dependency used by this family. Applications own routes, labels, state persistence, and branding.
|
|
@@ -13,7 +13,7 @@ See [component ownership](../../docs/component-ownership.md) and [release histor
|
|
|
13
13
|
Inputs preserve native form constraints, refs, labels, descriptions and invalid
|
|
14
14
|
state; controls use 2.75rem standard or 2.25rem small sizing. Select accepts explicit
|
|
15
15
|
options with managed keyboard navigation, focus, and native form integration. `Field`, `Fieldset`, and
|
|
16
|
-
`FieldNote` own field grouping
|
|
16
|
+
`FieldNote` own field grouping and error presentation. Input Label owns label/icon alignment.
|
|
17
17
|
Fieldset keeps native disabled propagation and legend semantics.
|
|
18
18
|
|
|
19
19
|
`FilePicker` owns the bordered surface, drag state, native input, and optional
|
|
@@ -36,8 +36,13 @@ color token; keyboard focus remains owned by the theme.
|
|
|
36
36
|
|
|
37
37
|
Import `FieldGrid` and `SearchForm` from `@gridui/form`.
|
|
38
38
|
FieldGrid supplies full-width field spans, two columns above 24rem, and one
|
|
39
|
-
column at or below 24rem. SearchForm aligns
|
|
40
|
-
|
|
39
|
+
column at or below 24rem. SearchForm aligns fields and submit actions.
|
|
40
|
+
Use `<Field grow>` or `<FieldGrid grow>` for a flexible search region; other
|
|
41
|
+
children retain their own sizing. Layout containers do not style arbitrary divs,
|
|
42
|
+
labels, or icons. Use Input's `<Label icon={...}>` for label/icon alignment.
|
|
43
|
+
Migration: add `grow` to former implicitly stretched SearchForm children and
|
|
44
|
+
use Label instead of relying on FieldGrid to restyle native labels.
|
|
45
|
+
Both forward native props and refs. The corresponding Core families own labels, constraints, invalid
|
|
41
46
|
state, field notes, and native fieldset semantics; applications own values,
|
|
42
47
|
validation, and submission actions. These local form arrangements do not own
|
|
43
48
|
page frames or shared region seams.
|
|
@@ -55,3 +60,27 @@ console. Applications own visible feedback. `Input.onValueChange` exposes text
|
|
|
55
60
|
values directly; native onChange props remain available for browser-level
|
|
56
61
|
consumers.
|
|
57
62
|
|
|
63
|
+
|
|
64
|
+
## Native form collaborators
|
|
65
|
+
|
|
66
|
+
`useFormReset(elementRef, onReset, form?)` observes cancellable native resets using
|
|
67
|
+
the element's current form owner, including forms mounted later, replacement
|
|
68
|
+
forms, and controls moved between forms. Native controls supply their own form
|
|
69
|
+
association; composite roots use the optional form ID or their closest form.
|
|
70
|
+
The callback runs after native reset and cancellation handlers. Pending callbacks
|
|
71
|
+
are discarded on unmount or reassociation. Value ownership remains with each
|
|
72
|
+
control: selection families can request controlled resets, while ordinary
|
|
73
|
+
controlled inputs leave reset policy to their caller.
|
|
74
|
+
|
|
75
|
+
`focusInvalidControl(event, focus)` cancels the native invalid action for a hidden
|
|
76
|
+
input/select mirror and invokes the visible-control focus callback only when that
|
|
77
|
+
mirror is the form's first participating invalid control. Applications still own
|
|
78
|
+
validation messages and invalid appearance.
|
|
79
|
+
|
|
80
|
+
`ListFieldControl` renders the hidden multiple select shared by MultiSelect and
|
|
81
|
+
TagInput. It forwards `ref`, `name`, `form`, `required`, and `disabled`, accepts
|
|
82
|
+
`value` and caller-owned option children, and routes native changes through
|
|
83
|
+
`onValueChange` and invalid focus through `onInvalidFocus`. Pair it with
|
|
84
|
+
`useListField` for controlled/local values and cancellable reset synchronization.
|
|
85
|
+
Option membership, unavailable values, tag parsing, and visible focus targets
|
|
86
|
+
remain caller-owned. Single-value SelectionForm remains Select-owned.
|
package/dist/field/field.d.ts
CHANGED
|
@@ -5,5 +5,7 @@
|
|
|
5
5
|
* @description Field Grid
|
|
6
6
|
*/
|
|
7
7
|
import type { ComponentPropsWithRef, FC } from "react";
|
|
8
|
-
export type FieldGridProps = ComponentPropsWithRef<"div"
|
|
8
|
+
export type FieldGridProps = ComponentPropsWithRef<"div"> & {
|
|
9
|
+
readonly grow?: boolean;
|
|
10
|
+
};
|
|
9
11
|
export declare const FieldGrid: FC<FieldGridProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -16,8 +16,12 @@ export type { FieldNoteProps } from "./field-note/field-note";
|
|
|
16
16
|
export { FieldNote } from "./field-note/field-note";
|
|
17
17
|
export type { FieldsetProps } from "./fieldset/fieldset";
|
|
18
18
|
export { Fieldset } from "./fieldset/fieldset";
|
|
19
|
+
export type { ListFieldControlProps } from "./list-field-control/list-field-control";
|
|
20
|
+
export { ListFieldControl } from "./list-field-control/list-field-control";
|
|
19
21
|
export type { SearchFormProps } from "./search-form/search-form";
|
|
20
22
|
export { SearchForm } from "./search-form/search-form";
|
|
23
|
+
export { focusInvalidControl } from "./shared/focus-invalid-control";
|
|
21
24
|
export { useUnsavedNavigation } from "./shared/navigation";
|
|
25
|
+
export { useFormReset } from "./shared/use-form-reset";
|
|
22
26
|
export type { ListFieldProps } from "./shared/use-list-field";
|
|
23
27
|
export { useListField } from "./shared/use-list-field";
|
package/dist/index.js
CHANGED
|
@@ -34,10 +34,18 @@ var ActionForm = (props) => {
|
|
|
34
34
|
);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
// src/shared/field-sizing.ts
|
|
38
|
+
import { cva } from "class-variance-authority";
|
|
39
|
+
var fieldSizingStyles = cva("", {
|
|
40
|
+
variants: {
|
|
41
|
+
grow: { true: "flex-1 basis-48" }
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
37
45
|
// src/field/style.ts
|
|
38
46
|
import { cn } from "@gridui/style-utils";
|
|
39
|
-
import { cva } from "class-variance-authority";
|
|
40
|
-
var fieldStyles =
|
|
47
|
+
import { cva as cva2 } from "class-variance-authority";
|
|
48
|
+
var fieldStyles = cva2(cn(
|
|
41
49
|
"gridui-field",
|
|
42
50
|
"grid min-w-0 gap-gridui-8"
|
|
43
51
|
));
|
|
@@ -46,56 +54,55 @@ var fieldClass = (className) => {
|
|
|
46
54
|
};
|
|
47
55
|
|
|
48
56
|
// src/field/field.tsx
|
|
57
|
+
import { cn as cn2 } from "@gridui/style-utils";
|
|
49
58
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
50
59
|
var Field = (props) => {
|
|
51
|
-
const { span = "auto", className, ...restProps } = props;
|
|
60
|
+
const { span = "auto", grow = false, className, ...restProps } = props;
|
|
52
61
|
return /* @__PURE__ */ jsx2(
|
|
53
62
|
"div",
|
|
54
63
|
{
|
|
55
64
|
...restProps,
|
|
56
|
-
className: fieldClass(className),
|
|
65
|
+
className: cn2(fieldClass(), fieldSizingStyles({ grow }), className),
|
|
57
66
|
"data-span": span
|
|
58
67
|
}
|
|
59
68
|
);
|
|
60
69
|
};
|
|
61
70
|
|
|
62
71
|
// src/field-grid/style.ts
|
|
63
|
-
import { cn as
|
|
64
|
-
import { cva as
|
|
65
|
-
var fieldGridStyles =
|
|
72
|
+
import { cn as cn3 } from "@gridui/style-utils";
|
|
73
|
+
import { cva as cva3 } from "class-variance-authority";
|
|
74
|
+
var fieldGridStyles = cva3(cn3(
|
|
66
75
|
"gridui-field-grid",
|
|
67
76
|
"grid grid-cols-2 gap-gridui-16",
|
|
68
77
|
"*:data-[span='full']:col-span-full",
|
|
69
|
-
"[&_label]:inline-flex [&_label]:items-center [&_label]:gap-gridui-4",
|
|
70
|
-
"[&_label_svg]:w-gridui-16 [&_label_svg]:h-gridui-16 [&_label_svg]:text-foreground",
|
|
71
78
|
"[@media(max-width:24rem)]:grid-cols-[1fr]"
|
|
72
79
|
));
|
|
73
80
|
|
|
74
81
|
// src/field-grid/field-grid.tsx
|
|
75
|
-
import { cn as
|
|
82
|
+
import { cn as cn4 } from "@gridui/style-utils";
|
|
76
83
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
77
84
|
var FieldGrid = (props) => {
|
|
78
|
-
const { className, ...restProps } = props;
|
|
85
|
+
const { grow = false, className, ...restProps } = props;
|
|
79
86
|
return /* @__PURE__ */ jsx3(
|
|
80
87
|
"div",
|
|
81
88
|
{
|
|
82
89
|
...restProps,
|
|
83
|
-
className:
|
|
90
|
+
className: cn4(fieldGridStyles(), fieldSizingStyles({ grow }), className)
|
|
84
91
|
}
|
|
85
92
|
);
|
|
86
93
|
};
|
|
87
94
|
|
|
88
95
|
// src/field-note/style.ts
|
|
89
|
-
import { cn as
|
|
90
|
-
import { cva as
|
|
91
|
-
var fieldNoteStyles =
|
|
96
|
+
import { cn as cn5 } from "@gridui/style-utils";
|
|
97
|
+
import { cva as cva4 } from "class-variance-authority";
|
|
98
|
+
var fieldNoteStyles = cva4(cn5(
|
|
92
99
|
"gridui-field-note",
|
|
93
100
|
"text-muted type-supporting wrap-anywhere",
|
|
94
101
|
"data-[invalid='true']:text-danger-foreground"
|
|
95
102
|
));
|
|
96
103
|
|
|
97
104
|
// src/field-note/field-note.tsx
|
|
98
|
-
import { cn as
|
|
105
|
+
import { cn as cn6 } from "@gridui/style-utils";
|
|
99
106
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
100
107
|
var FieldNote = (props) => {
|
|
101
108
|
const {
|
|
@@ -107,24 +114,23 @@ var FieldNote = (props) => {
|
|
|
107
114
|
"span",
|
|
108
115
|
{
|
|
109
116
|
...restProps,
|
|
110
|
-
className:
|
|
117
|
+
className: cn6(fieldNoteStyles(), className),
|
|
111
118
|
"data-invalid": invalid
|
|
112
119
|
}
|
|
113
120
|
);
|
|
114
121
|
};
|
|
115
122
|
|
|
116
123
|
// src/fieldset/style.ts
|
|
117
|
-
import { cn as
|
|
118
|
-
import { cva as
|
|
119
|
-
var fieldsetStyles =
|
|
124
|
+
import { cn as cn7 } from "@gridui/style-utils";
|
|
125
|
+
import { cva as cva5 } from "class-variance-authority";
|
|
126
|
+
var fieldsetStyles = cva5(cn7(
|
|
120
127
|
"gridui-fieldset",
|
|
121
128
|
"min-w-0 m-0 p-0 border-0",
|
|
122
|
-
"[
|
|
123
|
-
"[&_legend_span]:ml-gridui-8"
|
|
129
|
+
"[&>legend]:mb-gridui-24 [&>legend]:p-0"
|
|
124
130
|
));
|
|
125
131
|
|
|
126
132
|
// src/fieldset/fieldset.tsx
|
|
127
|
-
import { cn as
|
|
133
|
+
import { cn as cn8 } from "@gridui/style-utils";
|
|
128
134
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
129
135
|
var Fieldset = (props) => {
|
|
130
136
|
const { className, ...restProps } = props;
|
|
@@ -132,30 +138,66 @@ var Fieldset = (props) => {
|
|
|
132
138
|
"fieldset",
|
|
133
139
|
{
|
|
134
140
|
...restProps,
|
|
135
|
-
className:
|
|
141
|
+
className: cn8(fieldsetStyles(), className)
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/shared/focus-invalid-control.ts
|
|
147
|
+
var focusInvalidControl = (event, focus) => {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
const control = event.currentTarget;
|
|
150
|
+
const owner = control.form;
|
|
151
|
+
const firstInvalid = owner && Array.from(owner.elements).find((element) => {
|
|
152
|
+
return "willValidate" in element && element.willValidate && element.matches(":invalid");
|
|
153
|
+
});
|
|
154
|
+
if (!owner || firstInvalid === control) {
|
|
155
|
+
focus();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/list-field-control/list-field-control.tsx
|
|
160
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
161
|
+
var ListFieldControl = (props) => {
|
|
162
|
+
const { onValueChange, onInvalidFocus, ...restProps } = props;
|
|
163
|
+
return /* @__PURE__ */ jsx6(
|
|
164
|
+
"select",
|
|
165
|
+
{
|
|
166
|
+
...restProps,
|
|
167
|
+
multiple: true,
|
|
168
|
+
className: "sr-only",
|
|
169
|
+
"aria-hidden": "true",
|
|
170
|
+
tabIndex: -1,
|
|
171
|
+
onChange: (event) => {
|
|
172
|
+
onValueChange?.(Array.from(event.currentTarget.selectedOptions, (option) => {
|
|
173
|
+
return option.value;
|
|
174
|
+
}));
|
|
175
|
+
},
|
|
176
|
+
onInvalid: (event) => {
|
|
177
|
+
focusInvalidControl(event, onInvalidFocus);
|
|
178
|
+
}
|
|
136
179
|
}
|
|
137
180
|
);
|
|
138
181
|
};
|
|
139
182
|
|
|
140
183
|
// src/search-form/style.ts
|
|
141
|
-
import { cn as
|
|
142
|
-
import { cva as
|
|
143
|
-
var searchFormStyles =
|
|
184
|
+
import { cn as cn9 } from "@gridui/style-utils";
|
|
185
|
+
import { cva as cva6 } from "class-variance-authority";
|
|
186
|
+
var searchFormStyles = cva6(cn9(
|
|
144
187
|
"gridui-search-form",
|
|
145
|
-
"flex flex-wrap items-end gap-gridui-16"
|
|
146
|
-
"[&_>_div]:flex-1 [&_>_div]:min-w-48"
|
|
188
|
+
"flex flex-wrap items-end gap-gridui-16"
|
|
147
189
|
));
|
|
148
190
|
|
|
149
191
|
// src/search-form/search-form.tsx
|
|
150
|
-
import { cn as
|
|
151
|
-
import { jsx as
|
|
192
|
+
import { cn as cn10 } from "@gridui/style-utils";
|
|
193
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
152
194
|
var SearchForm = (props) => {
|
|
153
195
|
const { className, ...restProps } = props;
|
|
154
|
-
return /* @__PURE__ */
|
|
196
|
+
return /* @__PURE__ */ jsx7(
|
|
155
197
|
"form",
|
|
156
198
|
{
|
|
157
199
|
...restProps,
|
|
158
|
-
className:
|
|
200
|
+
className: cn10(searchFormStyles(), className)
|
|
159
201
|
}
|
|
160
202
|
);
|
|
161
203
|
};
|
|
@@ -177,8 +219,54 @@ var useUnsavedNavigation = (pending) => {
|
|
|
177
219
|
}, [pending]);
|
|
178
220
|
};
|
|
179
221
|
|
|
222
|
+
// src/shared/use-form-reset.ts
|
|
223
|
+
import { useEffect as useEffect2, useLayoutEffect, useRef } from "react";
|
|
224
|
+
var formOwner = (element, form) => {
|
|
225
|
+
if (element.form !== void 0) {
|
|
226
|
+
return element.form;
|
|
227
|
+
}
|
|
228
|
+
return form === void 0 ? element.closest("form") : element.ownerDocument.getElementById(form);
|
|
229
|
+
};
|
|
230
|
+
var useFormReset = (element, onReset, form) => {
|
|
231
|
+
const latest = useRef(onReset);
|
|
232
|
+
useLayoutEffect(() => {
|
|
233
|
+
latest.current = onReset;
|
|
234
|
+
});
|
|
235
|
+
useEffect2(() => {
|
|
236
|
+
const document = element.current?.ownerDocument;
|
|
237
|
+
if (!document) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const pending = /* @__PURE__ */ new Set();
|
|
241
|
+
const reset = (event) => {
|
|
242
|
+
const control = element.current;
|
|
243
|
+
if (!control || event.target !== formOwner(control, form)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const timer = setTimeout(() => {
|
|
247
|
+
pending.delete(timer);
|
|
248
|
+
const current = element.current;
|
|
249
|
+
if (!event.defaultPrevented && current && event.target === formOwner(current, form)) {
|
|
250
|
+
latest.current();
|
|
251
|
+
}
|
|
252
|
+
}, 0);
|
|
253
|
+
pending.add(timer);
|
|
254
|
+
};
|
|
255
|
+
document.addEventListener("reset", reset, true);
|
|
256
|
+
return () => {
|
|
257
|
+
document.removeEventListener("reset", reset, true);
|
|
258
|
+
pending.forEach((timer) => {
|
|
259
|
+
clearTimeout(timer);
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
}, [
|
|
263
|
+
element,
|
|
264
|
+
form
|
|
265
|
+
]);
|
|
266
|
+
};
|
|
267
|
+
|
|
180
268
|
// src/shared/use-list-field.ts
|
|
181
|
-
import {
|
|
269
|
+
import { useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState } from "react";
|
|
182
270
|
import { flushSync } from "react-dom";
|
|
183
271
|
var useListField = (props, onReset) => {
|
|
184
272
|
const { value, defaultValue = [], onValueChange, disabled, readOnly, form } = props;
|
|
@@ -189,9 +277,9 @@ var useListField = (props, onReset) => {
|
|
|
189
277
|
return [...new Set(defaultValue)];
|
|
190
278
|
});
|
|
191
279
|
const selected = [...new Set(value ?? local)];
|
|
192
|
-
const initial =
|
|
193
|
-
const native =
|
|
194
|
-
const control =
|
|
280
|
+
const initial = useRef2(selected);
|
|
281
|
+
const native = useRef2(null);
|
|
282
|
+
const control = useRef2(null);
|
|
195
283
|
const available = () => {
|
|
196
284
|
return !disabled && !readOnly && !control.current?.matches(":disabled");
|
|
197
285
|
};
|
|
@@ -207,43 +295,29 @@ var useListField = (props, onReset) => {
|
|
|
207
295
|
}
|
|
208
296
|
onValueChange?.(unique);
|
|
209
297
|
};
|
|
210
|
-
const latest =
|
|
298
|
+
const latest = useRef2({
|
|
211
299
|
update,
|
|
212
300
|
onReset,
|
|
213
301
|
selected
|
|
214
302
|
});
|
|
215
|
-
|
|
303
|
+
useLayoutEffect2(() => {
|
|
216
304
|
latest.current = {
|
|
217
305
|
update,
|
|
218
306
|
onReset,
|
|
219
307
|
selected
|
|
220
308
|
};
|
|
221
309
|
});
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
});
|
|
234
|
-
if (native.current) {
|
|
235
|
-
for (const option of native.current.options) {
|
|
236
|
-
option.selected = latest.current.selected.includes(option.value);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}, 0);
|
|
240
|
-
};
|
|
241
|
-
owner?.addEventListener("reset", reset);
|
|
242
|
-
return () => {
|
|
243
|
-
mounted = false;
|
|
244
|
-
owner?.removeEventListener("reset", reset);
|
|
245
|
-
};
|
|
246
|
-
}, [form]);
|
|
310
|
+
useFormReset(native, () => {
|
|
311
|
+
flushSync(() => {
|
|
312
|
+
latest.current.update(initial.current);
|
|
313
|
+
latest.current.onReset();
|
|
314
|
+
});
|
|
315
|
+
if (native.current) {
|
|
316
|
+
for (const option of native.current.options) {
|
|
317
|
+
option.selected = latest.current.selected.includes(option.value);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}, form);
|
|
247
321
|
const change = (next) => {
|
|
248
322
|
if (available()) {
|
|
249
323
|
update(next);
|
|
@@ -263,9 +337,12 @@ export {
|
|
|
263
337
|
FieldGrid,
|
|
264
338
|
FieldNote,
|
|
265
339
|
Fieldset,
|
|
340
|
+
ListFieldControl,
|
|
266
341
|
SearchForm,
|
|
267
342
|
fieldClass,
|
|
343
|
+
focusInvalidControl,
|
|
268
344
|
runFormAction,
|
|
345
|
+
useFormReset,
|
|
269
346
|
useListField,
|
|
270
347
|
useUnsavedNavigation
|
|
271
348
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/action-form/run-action.ts", "../src/action-form/action-form.tsx", "../src/field/style.ts", "../src/field/field.tsx", "../src/field-grid/style.ts", "../src/field-grid/field-grid.tsx", "../src/field-note/style.ts", "../src/field-note/field-note.tsx", "../src/fieldset/style.ts", "../src/fieldset/fieldset.tsx", "../src/search-form/style.ts", "../src/search-form/search-form.tsx", "../src/shared/navigation.ts", "../src/shared/use-list-field.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @author WMXPY\n * @package Form\n * @namespace ActionForm\n * @description Run Action\n */\n\nexport const runFormAction = async (\n action: () => void | Promise<void>,\n onError?: (error: unknown) => void,\n): Promise<void> => {\n try {\n await action();\n } catch (error) {\n if (onError) {\n onError(error);\n } else {\n console.error(error);\n }\n }\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace ActionForm\n * @description Action Form\n */\n\nimport { runFormAction } from \"./run-action\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type ActionFormProps = Omit<ComponentPropsWithRef<\"form\">, \"onSubmit\"> & {\n readonly onAction: () => void | Promise<void>;\n readonly onActionError?: (error: unknown) => void;\n readonly disabled?: boolean;\n};\n\nexport const ActionForm: FC<ActionFormProps> = (props: ActionFormProps) => {\n const {\n onAction,\n onActionError,\n disabled = false,\n ...restProps\n } = props;\n return (<form\n {...restProps}\n onSubmit={(event) => {\n event.preventDefault();\n if (!disabled) {\n void runFormAction(onAction, onActionError);\n }\n }}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Field\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldStyles = cva(cn(\n \"gridui-field\",\n \"grid min-w-0 gap-gridui-8\",\n));\n\nexport const fieldClass = (className?: string): string => {\n return cn(fieldStyles(), className);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Field\n * @description Field\n */\n\nimport { fieldClass } from \"./style\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FieldProps = ComponentPropsWithRef<\"div\"> & {\n readonly span?: \"auto\" | \"full\";\n};\n\nexport const Field: FC<FieldProps> = (props: FieldProps) => {\n const { span = \"auto\", className, ...restProps } = props;\n return (<div\n {...restProps}\n className={fieldClass(className)}\n data-span={span}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace FieldGrid\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldGridStyles = cva(cn(\n \"gridui-field-grid\",\n \"grid grid-cols-2 gap-gridui-16\",\n \"*:data-[span='full']:col-span-full\",\n \"[&_label]:inline-flex [&_label]:items-center [&_label]:gap-gridui-4\",\n \"[&_label_svg]:w-gridui-16 [&_label_svg]:h-gridui-16 [&_label_svg]:text-foreground\",\n \"[@media(max-width:24rem)]:grid-cols-[1fr]\",\n));\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace FieldGrid\n * @description Field Grid\n */\n\nimport { fieldGridStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FieldGridProps = ComponentPropsWithRef<\"div\">;\n\nexport const FieldGrid: FC<FieldGridProps> = (props: FieldGridProps) => {\n const { className, ...restProps } = props;\n return (<div\n {...restProps}\n className={cn(fieldGridStyles(), className)}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace FieldNote\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldNoteStyles = cva(cn(\n \"gridui-field-note\",\n \"text-muted type-supporting wrap-anywhere\",\n \"data-[invalid='true']:text-danger-foreground\",\n));\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace FieldNote\n * @description Field Note\n */\n\nimport { fieldNoteStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FieldNoteProps = ComponentPropsWithRef<\"span\"> & {\n readonly invalid?: boolean;\n};\n\nexport const FieldNote: FC<FieldNoteProps> = (props: FieldNoteProps) => {\n const {\n invalid = false,\n className,\n ...restProps\n } = props;\n return (<span\n {...restProps}\n className={cn(fieldNoteStyles(), className)}\n data-invalid={invalid}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Fieldset\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldsetStyles = cva(cn(\n \"gridui-fieldset\",\n \"min-w-0 m-0 p-0 border-0\",\n \"[&_legend]:mb-gridui-24 [&_legend]:p-0\",\n \"[&_legend_span]:ml-gridui-8\",\n));\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Fieldset\n * @description Fieldset\n */\n\nimport { fieldsetStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FieldsetProps = ComponentPropsWithRef<\"fieldset\">;\n\nexport const Fieldset: FC<FieldsetProps> = (props: FieldsetProps) => {\n const { className, ...restProps } = props;\n return (<fieldset\n {...restProps}\n className={cn(fieldsetStyles(), className)}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace SearchForm\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const searchFormStyles = cva(cn(\n \"gridui-search-form\",\n \"flex flex-wrap items-end gap-gridui-16\",\n \"[&_>_div]:flex-1 [&_>_div]:min-w-48\",\n));\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace SearchForm\n * @description Search Form\n */\n\nimport { searchFormStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type SearchFormProps = ComponentPropsWithRef<\"form\">;\n\nexport const SearchForm: FC<SearchFormProps> = (props: SearchFormProps) => {\n const { className, ...restProps } = props;\n return (<form\n {...restProps}\n className={cn(searchFormStyles(), className)}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Shared\n * @description Navigation\n */\n\nimport { useEffect } from \"react\";\n\nexport const protectUnsavedNavigation = (target: EventTarget): () => void => {\n const warn = (event: Event): void => {\n event.preventDefault();\n };\n target.addEventListener(\"beforeunload\", warn);\n return () => {\n target.removeEventListener(\"beforeunload\", warn);\n };\n};\n\nexport const useUnsavedNavigation = (pending: boolean): void => {\n useEffect(() => {\n return pending ? protectUnsavedNavigation(window) : undefined;\n }, [pending]);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Shared\n * @description Use List Field\n */\n\nimport { useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport { flushSync } from \"react-dom\";\n\nexport type ListFieldProps = {\n readonly value?: readonly string[] | undefined;\n readonly defaultValue?: readonly string[] | undefined;\n readonly onValueChange?: ((value: string[]) => void) | undefined;\n readonly disabled?: boolean | undefined;\n readonly readOnly?: boolean | undefined;\n readonly form?: string | undefined;\n};\n\nexport const useListField = (props: ListFieldProps, onReset: () => void) => {\n const { value, defaultValue = [], onValueChange, disabled, readOnly, form } = props;\n const [\n local,\n setLocal,\n ] = useState(() => {\n return [...new Set(defaultValue)];\n });\n const selected = [...new Set(value ?? local)];\n const initial = useRef(selected);\n const native = useRef<HTMLSelectElement>(null);\n const control = useRef<HTMLElement>(null);\n const available = () => {\n return !disabled && !readOnly && !control.current?.matches(\":disabled\");\n };\n const update = (next: readonly string[]) => {\n const unique = [...new Set(next)];\n if (selected.length === unique.length && selected.every((entry, index) => {\n return entry === unique[index];\n })) {\n return;\n }\n if (value === undefined) {\n setLocal(unique);\n }\n onValueChange?.(unique);\n };\n const latest = useRef({\n update,\n onReset,\n selected,\n });\n useLayoutEffect(() => {\n latest.current = {\n update,\n onReset,\n selected,\n };\n });\n useEffect(() => {\n const owner = native.current?.form;\n let mounted = true;\n const reset = (event: Event) => {\n setTimeout(() => {\n if (!mounted || event.defaultPrevented) {\n return;\n }\n flushSync(() => {\n latest.current.update(initial.current); latest.current.onReset();\n });\n if (native.current) {\n for (const option of native.current.options) { option.selected = latest.current.selected.includes(option.value); }\n }\n }, 0);\n };\n owner?.addEventListener(\"reset\", reset);\n return () => {\n mounted = false; owner?.removeEventListener(\"reset\", reset);\n };\n }, [form]);\n const change = (next: readonly string[]) => {\n if (available()) {\n update(next);\n }\n };\n return {\n selected,\n native,\n control,\n change,\n available,\n };\n};\n"],
|
|
5
|
-
"mappings": ";AAOO,IAAM,gBAAgB,OACzB,QACA,YACgB;AAChB,MAAI;AACA,UAAM,OAAO;AAAA,EACjB,SAAS,OAAO;AACZ,QAAI,SAAS;AACT,cAAQ,KAAK;AAAA,IACjB,OAAO;AACH,cAAQ,MAAM,KAAK;AAAA,IACvB;AAAA,EACJ;AACJ;;;ACGY;AAPL,IAAM,aAAkC,CAAC,UAA2B;AACvE,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,GAAG;AAAA,EACP,IAAI;AACJ,SAAQ;AAAA,IAAC;AAAA;AAAA,MACJ,GAAG;AAAA,MACJ,UAAU,CAAC,UAAU;AACjB,cAAM,eAAe;AACrB,YAAI,CAAC,UAAU;AACX,eAAK,cAAc,UAAU,aAAa;AAAA,QAC9C;AAAA,MACJ;AAAA;AAAA,EACJ;AACJ;;;ACzBA,SAAS,UAAU;AACnB,SAAS,
|
|
6
|
-
"names": ["jsx", "cn", "cva", "cn", "jsx", "cn", "cva", "cn", "jsx", "cn", "cva", "cn", "jsx", "cn", "cva", "cn", "jsx", "useEffect"]
|
|
3
|
+
"sources": ["../src/action-form/run-action.ts", "../src/action-form/action-form.tsx", "../src/shared/field-sizing.ts", "../src/field/style.ts", "../src/field/field.tsx", "../src/field-grid/style.ts", "../src/field-grid/field-grid.tsx", "../src/field-note/style.ts", "../src/field-note/field-note.tsx", "../src/fieldset/style.ts", "../src/fieldset/fieldset.tsx", "../src/shared/focus-invalid-control.ts", "../src/list-field-control/list-field-control.tsx", "../src/search-form/style.ts", "../src/search-form/search-form.tsx", "../src/shared/navigation.ts", "../src/shared/use-form-reset.ts", "../src/shared/use-list-field.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * @author WMXPY\n * @package Form\n * @namespace ActionForm\n * @description Run Action\n */\n\nexport const runFormAction = async (\n action: () => void | Promise<void>,\n onError?: (error: unknown) => void,\n): Promise<void> => {\n try {\n await action();\n } catch (error) {\n if (onError) {\n onError(error);\n } else {\n console.error(error);\n }\n }\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace ActionForm\n * @description Action Form\n */\n\nimport { runFormAction } from \"./run-action\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type ActionFormProps = Omit<ComponentPropsWithRef<\"form\">, \"onSubmit\"> & {\n readonly onAction: () => void | Promise<void>;\n readonly onActionError?: (error: unknown) => void;\n readonly disabled?: boolean;\n};\n\nexport const ActionForm: FC<ActionFormProps> = (props: ActionFormProps) => {\n const {\n onAction,\n onActionError,\n disabled = false,\n ...restProps\n } = props;\n return (<form\n {...restProps}\n onSubmit={(event) => {\n event.preventDefault();\n if (!disabled) {\n void runFormAction(onAction, onActionError);\n }\n }}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Shared\n * @description Field Sizing\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldSizingStyles = cva(\"\", {\n variants: {\n grow: { true: \"flex-1 basis-48\" },\n },\n});\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Field\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldStyles = cva(cn(\n \"gridui-field\",\n \"grid min-w-0 gap-gridui-8\",\n));\n\nexport const fieldClass = (className?: string): string => {\n return cn(fieldStyles(), className);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Field\n * @description Field\n */\n\nimport { fieldSizingStyles } from \"../shared/field-sizing\";\nimport { fieldClass } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FieldProps = ComponentPropsWithRef<\"div\"> & {\n readonly grow?: boolean;\n readonly span?: \"auto\" | \"full\";\n};\n\nexport const Field: FC<FieldProps> = (props: FieldProps) => {\n const { span = \"auto\", grow = false, className, ...restProps } = props;\n return (<div\n {...restProps}\n className={cn(fieldClass(), fieldSizingStyles({ grow }), className)}\n data-span={span}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace FieldGrid\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldGridStyles = cva(cn(\n \"gridui-field-grid\",\n \"grid grid-cols-2 gap-gridui-16\",\n \"*:data-[span='full']:col-span-full\",\n \"[@media(max-width:24rem)]:grid-cols-[1fr]\",\n));\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace FieldGrid\n * @description Field Grid\n */\n\nimport { fieldSizingStyles } from \"../shared/field-sizing\";\nimport { fieldGridStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FieldGridProps = ComponentPropsWithRef<\"div\"> & {\n readonly grow?: boolean;\n};\n\nexport const FieldGrid: FC<FieldGridProps> = (props: FieldGridProps) => {\n const { grow = false, className, ...restProps } = props;\n return (<div\n {...restProps}\n className={cn(fieldGridStyles(), fieldSizingStyles({ grow }), className)}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace FieldNote\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldNoteStyles = cva(cn(\n \"gridui-field-note\",\n \"text-muted type-supporting wrap-anywhere\",\n \"data-[invalid='true']:text-danger-foreground\",\n));\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace FieldNote\n * @description Field Note\n */\n\nimport { fieldNoteStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FieldNoteProps = ComponentPropsWithRef<\"span\"> & {\n readonly invalid?: boolean;\n};\n\nexport const FieldNote: FC<FieldNoteProps> = (props: FieldNoteProps) => {\n const {\n invalid = false,\n className,\n ...restProps\n } = props;\n return (<span\n {...restProps}\n className={cn(fieldNoteStyles(), className)}\n data-invalid={invalid}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Fieldset\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const fieldsetStyles = cva(cn(\n \"gridui-fieldset\",\n \"min-w-0 m-0 p-0 border-0\",\n \"[&>legend]:mb-gridui-24 [&>legend]:p-0\",\n));\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Fieldset\n * @description Fieldset\n */\n\nimport { fieldsetStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type FieldsetProps = ComponentPropsWithRef<\"fieldset\">;\n\nexport const Fieldset: FC<FieldsetProps> = (props: FieldsetProps) => {\n const { className, ...restProps } = props;\n return (<fieldset\n {...restProps}\n className={cn(fieldsetStyles(), className)}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Shared\n * @description Focus Invalid Control\n */\n\nimport type { SyntheticEvent } from \"react\";\n\nexport const focusInvalidControl = (\n event: SyntheticEvent<HTMLInputElement | HTMLSelectElement>,\n focus: () => void,\n): void => {\n event.preventDefault();\n const control = event.currentTarget;\n const owner = control.form;\n const firstInvalid = owner && Array.from(owner.elements).find(element => {\n return \"willValidate\" in element && element.willValidate && element.matches(\":invalid\");\n });\n if (!owner || firstInvalid === control) {\n focus();\n }\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace ListFieldControl\n * @description List Field Control\n */\n\nimport { focusInvalidControl } from \"../shared/focus-invalid-control\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type ListFieldControlProps = Pick<ComponentPropsWithRef<\"select\">, \"name\" | \"form\" | \"disabled\" | \"required\" | \"ref\" | \"children\"> & {\n readonly value: readonly string[];\n readonly onValueChange?: (value: string[]) => void;\n readonly onInvalidFocus: () => void;\n};\n\nexport const ListFieldControl: FC<ListFieldControlProps> = (props: ListFieldControlProps) => {\n const { onValueChange, onInvalidFocus, ...restProps } = props;\n return (<select\n {...restProps}\n multiple\n className=\"sr-only\"\n aria-hidden=\"true\"\n tabIndex={-1}\n onChange={event => {\n onValueChange?.(Array.from(event.currentTarget.selectedOptions, option => {\n return option.value;\n }));\n }}\n onInvalid={event => {\n focusInvalidControl(event, onInvalidFocus);\n }}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace SearchForm\n * @description Style\n */\n\nimport { cn } from \"@gridui/style-utils\";\nimport { cva } from \"class-variance-authority\";\n\nexport const searchFormStyles = cva(cn(\n \"gridui-search-form\",\n \"flex flex-wrap items-end gap-gridui-16\",\n));\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace SearchForm\n * @description Search Form\n */\n\nimport { searchFormStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type SearchFormProps = ComponentPropsWithRef<\"form\">;\n\nexport const SearchForm: FC<SearchFormProps> = (props: SearchFormProps) => {\n const { className, ...restProps } = props;\n return (<form\n {...restProps}\n className={cn(searchFormStyles(), className)}\n />);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Shared\n * @description Navigation\n */\n\nimport { useEffect } from \"react\";\n\nexport const protectUnsavedNavigation = (target: EventTarget): () => void => {\n const warn = (event: Event): void => {\n event.preventDefault();\n };\n target.addEventListener(\"beforeunload\", warn);\n return () => {\n target.removeEventListener(\"beforeunload\", warn);\n };\n};\n\nexport const useUnsavedNavigation = (pending: boolean): void => {\n useEffect(() => {\n return pending ? protectUnsavedNavigation(window) : undefined;\n }, [pending]);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Shared\n * @description Use Form Reset\n */\n\nimport { type RefObject, useEffect, useLayoutEffect, useRef } from \"react\";\n\ntype ResetElement = HTMLElement & {\n readonly form?: HTMLFormElement | null;\n};\n\nconst formOwner = (element: ResetElement, form?: string): Element | null => {\n if (element.form !== undefined) {\n return element.form;\n }\n return form === undefined ? element.closest(\"form\") : element.ownerDocument.getElementById(form);\n};\n\nexport const useFormReset = (element: RefObject<ResetElement | null>, onReset: () => void, form?: string): void => {\n const latest = useRef(onReset);\n useLayoutEffect(() => {\n latest.current = onReset;\n });\n useEffect(() => {\n const document = element.current?.ownerDocument;\n if (!document) {\n return;\n }\n const pending = new Set<ReturnType<typeof setTimeout>>();\n const reset = (event: Event): void => {\n const control = element.current;\n if (!control || event.target !== formOwner(control, form)) {\n return;\n }\n // Native reset runs after dispatch; React bubbling handlers can cancel it.\n const timer = setTimeout(() => {\n pending.delete(timer);\n const current = element.current;\n if (!event.defaultPrevented && current && event.target === formOwner(current, form)) {\n latest.current();\n }\n }, 0);\n pending.add(timer);\n };\n document.addEventListener(\"reset\", reset, true);\n return () => {\n document.removeEventListener(\"reset\", reset, true);\n pending.forEach(timer => {\n clearTimeout(timer);\n });\n };\n }, [\n element,\n form,\n ]);\n};\n", "/**\n * @author WMXPY\n * @package Form\n * @namespace Shared\n * @description Use List Field\n */\n\nimport { useFormReset } from \"./use-form-reset\";\nimport { useLayoutEffect, useRef, useState } from \"react\";\nimport { flushSync } from \"react-dom\";\n\nexport type ListFieldProps = {\n readonly value?: readonly string[] | undefined;\n readonly defaultValue?: readonly string[] | undefined;\n readonly onValueChange?: ((value: string[]) => void) | undefined;\n readonly disabled?: boolean | undefined;\n readonly readOnly?: boolean | undefined;\n readonly form?: string | undefined;\n};\n\nexport const useListField = (props: ListFieldProps, onReset: () => void) => {\n const { value, defaultValue = [], onValueChange, disabled, readOnly, form } = props;\n const [\n local,\n setLocal,\n ] = useState(() => {\n return [...new Set(defaultValue)];\n });\n const selected = [...new Set(value ?? local)];\n const initial = useRef(selected);\n const native = useRef<HTMLSelectElement>(null);\n const control = useRef<HTMLElement>(null);\n const available = () => {\n return !disabled && !readOnly && !control.current?.matches(\":disabled\");\n };\n const update = (next: readonly string[]) => {\n const unique = [...new Set(next)];\n if (selected.length === unique.length && selected.every((entry, index) => {\n return entry === unique[index];\n })) {\n return;\n }\n if (value === undefined) {\n setLocal(unique);\n }\n onValueChange?.(unique);\n };\n const latest = useRef({\n update,\n onReset,\n selected,\n });\n useLayoutEffect(() => {\n latest.current = {\n update,\n onReset,\n selected,\n };\n });\n useFormReset(native, () => {\n flushSync(() => {\n latest.current.update(initial.current);\n latest.current.onReset();\n });\n if (native.current) {\n for (const option of native.current.options) {\n option.selected = latest.current.selected.includes(option.value);\n }\n }\n }, form);\n const change = (next: readonly string[]) => {\n if (available()) {\n update(next);\n }\n };\n return {\n selected,\n native,\n control,\n change,\n available,\n };\n};\n"],
|
|
5
|
+
"mappings": ";AAOO,IAAM,gBAAgB,OACzB,QACA,YACgB;AAChB,MAAI;AACA,UAAM,OAAO;AAAA,EACjB,SAAS,OAAO;AACZ,QAAI,SAAS;AACT,cAAQ,KAAK;AAAA,IACjB,OAAO;AACH,cAAQ,MAAM,KAAK;AAAA,IACvB;AAAA,EACJ;AACJ;;;ACGY;AAPL,IAAM,aAAkC,CAAC,UAA2B;AACvE,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,GAAG;AAAA,EACP,IAAI;AACJ,SAAQ;AAAA,IAAC;AAAA;AAAA,MACJ,GAAG;AAAA,MACJ,UAAU,CAAC,UAAU;AACjB,cAAM,eAAe;AACrB,YAAI,CAAC,UAAU;AACX,eAAK,cAAc,UAAU,aAAa;AAAA,QAC9C;AAAA,MACJ;AAAA;AAAA,EACJ;AACJ;;;ACzBA,SAAS,WAAW;AAEb,IAAM,oBAAoB,IAAI,IAAI;AAAA,EACrC,UAAU;AAAA,IACN,MAAM,EAAE,MAAM,kBAAkB;AAAA,EACpC;AACJ,CAAC;;;ACND,SAAS,UAAU;AACnB,SAA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B;AACxC,UAAM,SAAS,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC;AAChC,QAAI,SAAS,WAAW,OAAO,UAAU,SAAS,MAAM,CAAC,OAAO,UAAU;AACtE,aAAO,UAAU,OAAO,KAAK;AAAA,IACjC,CAAC,GAAG;AACA;AAAA,IACJ;AACA,QAAI,UAAU,QAAW;AACrB,eAAS,MAAM;AAAA,IACnB;AACA,oBAAgB,MAAM;AAAA,EAC1B;AACA,QAAM,SAASA,QAAO;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACJ,CAAC;AACD,EAAAD,iBAAgB,MAAM;AAClB,WAAO,UAAU;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAAA,EACJ,CAAC;AACD,eAAa,QAAQ,MAAM;AACvB,cAAU,MAAM;AACZ,aAAO,QAAQ,OAAO,QAAQ,OAAO;AACrC,aAAO,QAAQ,QAAQ;AAAA,IAC3B,CAAC;AACD,QAAI,OAAO,SAAS;AAChB,iBAAW,UAAU,OAAO,QAAQ,SAAS;AACzC,eAAO,WAAW,OAAO,QAAQ,SAAS,SAAS,OAAO,KAAK;AAAA,MACnE;AAAA,IACJ;AAAA,EACJ,GAAG,IAAI;AACP,QAAM,SAAS,CAAC,SAA4B;AACxC,QAAI,UAAU,GAAG;AACb,aAAO,IAAI;AAAA,IACf;AAAA,EACJ;AACA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;",
|
|
6
|
+
"names": ["cva", "cn", "jsx", "cn", "cva", "cn", "jsx", "cn", "cva", "cn", "jsx", "cn", "cva", "cn", "jsx", "jsx", "cn", "cva", "cn", "jsx", "useEffect", "useLayoutEffect", "useRef"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package Form
|
|
4
|
+
* @namespace ListFieldControl
|
|
5
|
+
* @description List Field Control
|
|
6
|
+
*/
|
|
7
|
+
import type { ComponentPropsWithRef, FC } from "react";
|
|
8
|
+
export type ListFieldControlProps = Pick<ComponentPropsWithRef<"select">, "name" | "form" | "disabled" | "required" | "ref" | "children"> & {
|
|
9
|
+
readonly value: readonly string[];
|
|
10
|
+
readonly onValueChange?: (value: string[]) => void;
|
|
11
|
+
readonly onInvalidFocus: () => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const ListFieldControl: FC<ListFieldControlProps>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package Form
|
|
4
|
+
* @namespace Shared
|
|
5
|
+
* @description Field Sizing
|
|
6
|
+
*/
|
|
7
|
+
export declare const fieldSizingStyles: (props?: ({
|
|
8
|
+
grow?: boolean | null | undefined;
|
|
9
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package Form
|
|
4
|
+
* @namespace Shared
|
|
5
|
+
* @description Focus Invalid Control
|
|
6
|
+
*/
|
|
7
|
+
import type { SyntheticEvent } from "react";
|
|
8
|
+
export declare const focusInvalidControl: (event: SyntheticEvent<HTMLInputElement | HTMLSelectElement>, focus: () => void) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @package Form
|
|
4
|
+
* @namespace Shared
|
|
5
|
+
* @description Use Form Reset
|
|
6
|
+
*/
|
|
7
|
+
import { type RefObject } from "react";
|
|
8
|
+
type ResetElement = HTMLElement & {
|
|
9
|
+
readonly form?: HTMLFormElement | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const useFormReset: (element: RefObject<ResetElement | null>, onReset: () => void, form?: string) => void;
|
|
12
|
+
export {};
|
package/dist/styles.css
CHANGED
|
@@ -7,6 +7,17 @@
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
@layer utilities {
|
|
10
|
+
.sr-only {
|
|
11
|
+
position: absolute;
|
|
12
|
+
width: 1px;
|
|
13
|
+
height: 1px;
|
|
14
|
+
padding: 0;
|
|
15
|
+
margin: -1px;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
clip-path: inset(50%);
|
|
18
|
+
white-space: nowrap;
|
|
19
|
+
border-width: 0;
|
|
20
|
+
}
|
|
10
21
|
.m-0 {
|
|
11
22
|
margin: 0px;
|
|
12
23
|
}
|
|
@@ -19,6 +30,15 @@
|
|
|
19
30
|
.min-w-0 {
|
|
20
31
|
min-width: 0px;
|
|
21
32
|
}
|
|
33
|
+
.flex-1 {
|
|
34
|
+
flex: 1;
|
|
35
|
+
}
|
|
36
|
+
.grow {
|
|
37
|
+
flex-grow: 1;
|
|
38
|
+
}
|
|
39
|
+
.basis-48 {
|
|
40
|
+
flex-basis: calc(var(--spacing) * 48);
|
|
41
|
+
}
|
|
22
42
|
.grid-cols-2 {
|
|
23
43
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
24
44
|
}
|
|
@@ -57,39 +77,12 @@
|
|
|
57
77
|
:is(.\*\:data-\[span\=\'full\'\]\:col-span-full > *)[data-span='full'] {
|
|
58
78
|
grid-column: 1 / -1;
|
|
59
79
|
}
|
|
60
|
-
.\[
|
|
61
|
-
min-width: calc(var(--spacing) * 48);
|
|
62
|
-
}
|
|
63
|
-
.\[\&_\>_div\]\:flex-1 > div {
|
|
64
|
-
flex: 1;
|
|
65
|
-
}
|
|
66
|
-
.\[\&_label\]\:inline-flex label {
|
|
67
|
-
display: inline-flex;
|
|
68
|
-
}
|
|
69
|
-
.\[\&_label\]\:items-center label {
|
|
70
|
-
align-items: center;
|
|
71
|
-
}
|
|
72
|
-
.\[\&_label\]\:gap-gridui-4 label {
|
|
73
|
-
gap: var(--gridui-space-4);
|
|
74
|
-
}
|
|
75
|
-
.\[\&_label_svg\]\:h-gridui-16 label svg {
|
|
76
|
-
height: var(--gridui-space-16);
|
|
77
|
-
}
|
|
78
|
-
.\[\&_label_svg\]\:w-gridui-16 label svg {
|
|
79
|
-
width: var(--gridui-space-16);
|
|
80
|
-
}
|
|
81
|
-
.\[\&_label_svg\]\:text-foreground label svg {
|
|
82
|
-
color: var(--gridui-foreground);
|
|
83
|
-
}
|
|
84
|
-
.\[\&_legend\]\:mb-gridui-24 legend {
|
|
80
|
+
.\[\&\>legend\]\:mb-gridui-24 > legend {
|
|
85
81
|
margin-bottom: var(--gridui-space-24);
|
|
86
82
|
}
|
|
87
|
-
.\[
|
|
83
|
+
.\[\&\>legend\]\:p-0 > legend {
|
|
88
84
|
padding: 0px;
|
|
89
85
|
}
|
|
90
|
-
.\[\&_legend_span\]\:ml-gridui-8 legend span {
|
|
91
|
-
margin-left: var(--gridui-space-8);
|
|
92
|
-
}
|
|
93
86
|
@media (max-width:24rem) {
|
|
94
87
|
.\[\@media\(max-width\:24rem\)\]\:grid-cols-\[1fr\] {
|
|
95
88
|
grid-template-columns: 1fr;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gridui/form",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "GridUI React form",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"react-dom": "^19.2.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@gridui/style-utils": "^2.1.
|
|
30
|
-
"@gridui/theme": "^2.1
|
|
29
|
+
"@gridui/style-utils": "^2.1.3",
|
|
30
|
+
"@gridui/theme": "^2.2.1",
|
|
31
31
|
"class-variance-authority": "0.7.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@gridui-internal/configuration": "0.0.0",
|
|
34
|
+
"@gridui-internal/configuration": "0.0.0-internal",
|
|
35
35
|
"@jest/globals": "30.5.2",
|
|
36
36
|
"@types/jest": "30.0.0",
|
|
37
|
-
"@types/node": "26.6.
|
|
37
|
+
"@types/node": "26.6.6",
|
|
38
38
|
"@types/react": "19.3.0",
|
|
39
39
|
"@types/react-dom": "19.3.0",
|
|
40
40
|
"jest": "30.5.2",
|