fluid-primitives 0.19.1 → 1.0.0-beta.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 +9 -0
- package/dist/Client-HrMIqv7d.js +1934 -0
- package/dist/accordion.d.ts +2 -2
- package/dist/accordion.js +25 -29
- package/dist/button.d.ts +52 -0
- package/dist/button.js +135 -0
- package/dist/checkbox-group.d.ts +6 -5
- package/dist/checkbox-group.js +36 -20
- package/dist/{checkbox-group.registry-CGwuF7SF.js → checkbox-group.registry-D8P8A4LY.js} +13 -8
- package/dist/checkbox.d.ts +18 -4
- package/dist/checkbox.js +30 -27
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -2
- package/dist/clipboard.d.ts +12 -5
- package/dist/clipboard.js +14 -16
- package/dist/collapsible.d.ts +3 -3
- package/dist/collapsible.js +13 -17
- package/dist/combobox.d.ts +37 -0
- package/dist/combobox.js +151 -0
- package/dist/date-picker.d.ts +67 -0
- package/dist/date-picker.js +289 -0
- package/dist/dialog.d.ts +3 -3
- package/dist/dialog.js +11 -12
- package/dist/field-array.d.ts +97 -0
- package/dist/field-array.js +223 -0
- package/dist/field.d.ts +30 -54
- package/dist/field.js +589 -175
- package/dist/fieldset.d.ts +15 -0
- package/dist/fieldset.js +27 -0
- package/dist/file-upload.d.ts +85 -0
- package/dist/file-upload.js +255 -0
- package/dist/form.d.ts +2 -83
- package/dist/form.fields-B58TZukv.js +329 -0
- package/dist/form.js +263 -276
- package/dist/index-B06gIN_k.d.ts +1358 -0
- package/dist/input.d.ts +96 -0
- package/dist/input.js +233 -0
- package/dist/menu.d.ts +55 -0
- package/dist/menu.js +144 -0
- package/dist/navigation-menu.d.ts +3 -3
- package/dist/navigation-menu.js +29 -43
- package/dist/number-input.d.ts +13 -4
- package/dist/number-input.js +30 -31
- package/dist/popover.d.ts +11 -3
- package/dist/popover.js +17 -18
- package/dist/radio-group.d.ts +4 -4
- package/dist/radio-group.js +35 -42
- package/dist/scroll-area.d.ts +3 -3
- package/dist/scroll-area.js +10 -9
- package/dist/select.d.ts +13 -51
- package/dist/select.js +62 -55
- package/dist/slider.d.ts +27 -0
- package/dist/slider.js +71 -0
- package/dist/switch.d.ts +4 -4
- package/dist/switch.js +24 -33
- package/dist/tabs.d.ts +3 -3
- package/dist/tabs.js +12 -15
- package/dist/textarea.d.ts +101 -0
- package/dist/textarea.js +231 -0
- package/dist/tooltip.d.ts +11 -3
- package/dist/tooltip.js +11 -10
- package/package.json +79 -24
- package/dist/Client-C51NSHxg.js +0 -248
- package/dist/field.dom-CJQXpQbZ.js +0 -11
- package/dist/form.registry-Cb8Pvoe8.d.ts +0 -7
- package/dist/form.registry-CmpTny_s.js +0 -51
- package/dist/index-B8JCdyld.d.ts +0 -118
package/dist/dialog.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as normalizeProps, at as Machine, rt as Component } from "./Client-HrMIqv7d.js";
|
|
2
2
|
import * as dialog from "@zag-js/dialog";
|
|
3
3
|
|
|
4
4
|
//#region Resources/Private/Primitives/Dialog/Dialog.ts
|
|
5
5
|
var Dialog = class extends Component {
|
|
6
|
-
static
|
|
6
|
+
static componentName = "dialog";
|
|
7
7
|
initMachine(props) {
|
|
8
|
-
|
|
8
|
+
const [machineProps] = dialog.splitProps(props);
|
|
9
|
+
return new Machine(dialog.machine, machineProps);
|
|
9
10
|
}
|
|
10
11
|
initApi() {
|
|
11
12
|
return dialog.connect(this.machine.service, normalizeProps);
|
|
12
13
|
}
|
|
13
14
|
render() {
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
const backdropEl = this.getElement("backdrop");
|
|
15
|
+
this.spreadPropsByOptionalValue("trigger", ({ value }) => this.api.getTriggerProps({ value }));
|
|
16
|
+
const backdropEl = this.hydrator.query("backdrop");
|
|
18
17
|
if (backdropEl) this.spreadProps(backdropEl, this.api.getBackdropProps());
|
|
19
|
-
const positionerEl = this.
|
|
18
|
+
const positionerEl = this.hydrator.query("positioner");
|
|
20
19
|
if (positionerEl) this.spreadProps(positionerEl, this.api.getPositionerProps());
|
|
21
|
-
const contentEl = this.
|
|
20
|
+
const contentEl = this.hydrator.query("content");
|
|
22
21
|
if (contentEl) this.spreadProps(contentEl, this.api.getContentProps());
|
|
23
|
-
const titleEl = this.
|
|
22
|
+
const titleEl = this.hydrator.query("title");
|
|
24
23
|
if (titleEl) this.spreadProps(titleEl, this.api.getTitleProps());
|
|
25
|
-
const descriptionEl = this.
|
|
24
|
+
const descriptionEl = this.hydrator.query("description");
|
|
26
25
|
if (descriptionEl) this.spreadProps(descriptionEl, this.api.getDescriptionProps());
|
|
27
|
-
this.
|
|
26
|
+
this.hydrator.queryAll("closeTrigger").forEach((trigger) => {
|
|
28
27
|
this.spreadProps(trigger, this.api.getCloseTriggerProps());
|
|
29
28
|
});
|
|
30
29
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { C as FieldValue, c as Machine$1, z as Component } from "./index-B06gIN_k.js";
|
|
2
|
+
import { EventObject } from "@zag-js/core";
|
|
3
|
+
import { PropTypes } from "@zag-js/types";
|
|
4
|
+
//#region Resources/Private/Primitives/FieldArray/src/field-array.types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* What a `translations.rowAdded` or `rowRemoved` callback receives, to build an announcement from the
|
|
7
|
+
* data of the row, e.g. "Person Ada Lovelace was removed" instead of the generic default.
|
|
8
|
+
*/
|
|
9
|
+
interface FieldArrayAnnounceInfo {
|
|
10
|
+
/** The index of the row. */
|
|
11
|
+
index: number;
|
|
12
|
+
/**
|
|
13
|
+
* The element of the row, for anything `getFieldValue` doesn't cover. For `rowRemoved` it is
|
|
14
|
+
* already detached from the document, but still readable.
|
|
15
|
+
*/
|
|
16
|
+
rowEl: HTMLElement;
|
|
17
|
+
/** Reads the value of a field in this row by its bare name, `'firstName'` and not `people[2][firstName]`. */
|
|
18
|
+
getFieldValue: (name: string) => FieldValue;
|
|
19
|
+
}
|
|
20
|
+
/** A screen reader announcement: a string, `false` to stay silent, or a callback that builds one from the row. */
|
|
21
|
+
type FieldArrayAnnounceTranslation = string | false | ((info: FieldArrayAnnounceInfo) => string | false);
|
|
22
|
+
interface FieldArrayProps {
|
|
23
|
+
/** The unique identifier of the field array. */
|
|
24
|
+
id: string;
|
|
25
|
+
/** The name the rows are nested under, e.g. `people` for `people[0][firstName]`. */
|
|
26
|
+
name: string;
|
|
27
|
+
/**
|
|
28
|
+
* The number of rows the server rendered. It sets the state of the triggers before hydration,
|
|
29
|
+
* once the client runs it counts the rows in the DOM instead.
|
|
30
|
+
*/
|
|
31
|
+
itemCount?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The fewest rows allowed. At this many, `remove()` and the remove triggers do nothing and the
|
|
34
|
+
* remove triggers are disabled.
|
|
35
|
+
* @default 0
|
|
36
|
+
*/
|
|
37
|
+
minItems?: number;
|
|
38
|
+
/**
|
|
39
|
+
* The most rows allowed. At this many, `append()` and the add trigger do nothing and the add
|
|
40
|
+
* trigger is disabled.
|
|
41
|
+
*/
|
|
42
|
+
maxItems?: number;
|
|
43
|
+
/**
|
|
44
|
+
* The screen reader announcements of an added and a removed row. In a string, `%number%` is
|
|
45
|
+
* replaced with the 1-based position of the row, e.g. `Row %number% removed.`. A callback builds
|
|
46
|
+
* the message from the data of the row, and may use `%number%` in what it returns.
|
|
47
|
+
*/
|
|
48
|
+
translations?: {
|
|
49
|
+
rowAdded?: FieldArrayAnnounceTranslation;
|
|
50
|
+
rowRemoved?: FieldArrayAnnounceTranslation;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Called after a row was added by the add trigger, with its index and the client names of the
|
|
54
|
+
* components inside it, e.g. `['field', 'input']`. Call their `mountAll()` here: the field
|
|
55
|
+
* array doesn't know what the template of a row contains.
|
|
56
|
+
*/
|
|
57
|
+
onItemAdded?: (detail: {
|
|
58
|
+
index: number;
|
|
59
|
+
componentNames: string[];
|
|
60
|
+
}) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Called after a row was removed by its remove trigger, with the index it had. The later rows
|
|
63
|
+
* have already moved up by then.
|
|
64
|
+
*/
|
|
65
|
+
onItemRemoved?: (detail: {
|
|
66
|
+
index: number;
|
|
67
|
+
}) => void;
|
|
68
|
+
}
|
|
69
|
+
interface FieldArrayApiActions {
|
|
70
|
+
/** The rows that currently exist, by index. */
|
|
71
|
+
getRows(): {
|
|
72
|
+
index: number;
|
|
73
|
+
}[];
|
|
74
|
+
/** Whether `append()` would currently add a row, i.e. `maxItems` hasn't been reached. */
|
|
75
|
+
canAppend(): boolean;
|
|
76
|
+
/** Whether `remove()` would currently remove a row, i.e. more than `minItems` remain. */
|
|
77
|
+
canRemove(): boolean;
|
|
78
|
+
/** Adds a row, if `maxItems` allows it. */
|
|
79
|
+
append(): void;
|
|
80
|
+
/** Removes the row at `index`, if `minItems` allows it. */
|
|
81
|
+
remove(index: number): void;
|
|
82
|
+
}
|
|
83
|
+
interface FieldArrayApiProps {
|
|
84
|
+
getAddTriggerProps(): PropTypes['button'];
|
|
85
|
+
getRemoveTriggerProps(index: number): PropTypes['button'];
|
|
86
|
+
}
|
|
87
|
+
interface FieldArrayApi extends FieldArrayApiActions, FieldArrayApiProps {}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region Resources/Private/Primitives/FieldArray/FieldArray.d.ts
|
|
90
|
+
declare class FieldArray extends Component<FieldArrayProps, FieldArrayApi> {
|
|
91
|
+
static componentName: string;
|
|
92
|
+
initMachine(props: FieldArrayProps): Machine$1<any>;
|
|
93
|
+
initApi(): FieldArrayApi;
|
|
94
|
+
render(): void;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { FieldArray, type FieldArrayAnnounceInfo, type FieldArrayAnnounceTranslation, type FieldArrayApi, type FieldArrayProps };
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { B as stringifyFieldPathAsBrackets, F as renameFieldMachineForForm, J as destroyComponentsWithin, R as parseFieldPath, a as normalizeProps, at as Machine$1, g as getFieldValueFromContainer, n as Template, rt as Component } from "./Client-HrMIqv7d.js";
|
|
2
|
+
import { nextTick } from "@zag-js/dom-query";
|
|
3
|
+
import { createSplitProps } from "@zag-js/utils";
|
|
4
|
+
import { createAnatomy } from "@zag-js/anatomy";
|
|
5
|
+
import { createMachine } from "@zag-js/core";
|
|
6
|
+
import { createProps } from "@zag-js/types";
|
|
7
|
+
import { createLiveRegion } from "@zag-js/live-region";
|
|
8
|
+
|
|
9
|
+
//#region Resources/Private/Primitives/FieldArray/src/field-array.anatomy.ts
|
|
10
|
+
const anatomy = createAnatomy("field-array").parts("addTrigger", "removeTrigger");
|
|
11
|
+
const parts = anatomy.build();
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region Resources/Private/Primitives/FieldArray/src/field-array.connect.ts
|
|
15
|
+
/**
|
|
16
|
+
* Builds `FieldArray`'s API. Deliberately takes the `Component` instance itself, not a Zag
|
|
17
|
+
* `service` the way `Field`/`Form`'s own `connect()` do - their API is "read context, return a
|
|
18
|
+
* plain object", but `append`/`remove` here are DOM mutations over an open-ended row collection,
|
|
19
|
+
* which needs `Component`-level helpers (`hydrator`/`refresh`) that a
|
|
20
|
+
* Zag service's `context`/`scope` alone don't provide. Still takes `normalize` like every other
|
|
21
|
+
* `connect()` though, so `getAddTriggerProps`/`getRemoveTriggerProps` stay framework-portable and
|
|
22
|
+
* carry the same anatomy attrs every other primitive's parts do.
|
|
23
|
+
*/
|
|
24
|
+
function connect(component, normalize) {
|
|
25
|
+
const actions = {
|
|
26
|
+
getRows: () => getRows(component),
|
|
27
|
+
canAppend: () => canAppend(component),
|
|
28
|
+
canRemove: () => canRemove(component),
|
|
29
|
+
append: () => append(component),
|
|
30
|
+
remove: (index) => remove(component, index)
|
|
31
|
+
};
|
|
32
|
+
const props = {
|
|
33
|
+
getAddTriggerProps: () => {
|
|
34
|
+
const disabled = !actions.canAppend();
|
|
35
|
+
return normalize.button({
|
|
36
|
+
...parts.addTrigger.attrs(component.machine.scope.id),
|
|
37
|
+
onClick: () => actions.append(),
|
|
38
|
+
"aria-disabled": disabled ? true : void 0,
|
|
39
|
+
"data-disabled": disabled ? true : void 0
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
getRemoveTriggerProps: (index) => {
|
|
43
|
+
const disabled = !actions.canRemove();
|
|
44
|
+
return normalize.button({
|
|
45
|
+
...parts.removeTrigger.attrs(component.machine.scope.id),
|
|
46
|
+
onClick: () => actions.remove(index),
|
|
47
|
+
"aria-disabled": disabled ? true : void 0,
|
|
48
|
+
"data-disabled": disabled ? true : void 0,
|
|
49
|
+
/** The index of the row the trigger removes. */
|
|
50
|
+
"data-value": index
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
...actions,
|
|
56
|
+
...props
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getRows(component) {
|
|
60
|
+
return component.hydrator.queryAll("item").map((el) => ({ index: Number(el.dataset.value) })).filter(({ index }) => !Number.isNaN(index)).sort((a, b) => a.index - b.index);
|
|
61
|
+
}
|
|
62
|
+
function canAppend(component) {
|
|
63
|
+
const maxItems = component.machine.prop("maxItems");
|
|
64
|
+
return maxItems == null || getRows(component).length < maxItems;
|
|
65
|
+
}
|
|
66
|
+
function canRemove(component) {
|
|
67
|
+
const minItems = component.machine.prop("minItems") ?? 0;
|
|
68
|
+
return getRows(component).length > minItems;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clones the `itemTemplate` stencil for a new row and appends it to `itemGroup` - `Template`'s own
|
|
72
|
+
* `{value}` option (via `ComponentHydrator.restampValue`) prepares any nested root components the
|
|
73
|
+
* row happens to compose (Field/Input/...) too, but doesn't construct them (see `restampValue`'s
|
|
74
|
+
* own docblock for why that step can't happen here) - `onItemAdded` carries `clone.componentNames`,
|
|
75
|
+
* so consumer code can call `mountAll()` again for each of them.
|
|
76
|
+
*/
|
|
77
|
+
function append(component) {
|
|
78
|
+
if (!canAppend(component)) return;
|
|
79
|
+
const itemGroupEl = component.hydrator.query("itemGroup");
|
|
80
|
+
if (!itemGroupEl) return;
|
|
81
|
+
const index = nextIndex(component);
|
|
82
|
+
const clone = new Template(component.hydrator, "itemTemplate", { value: String(index) });
|
|
83
|
+
itemGroupEl.appendChild(clone);
|
|
84
|
+
component.machine.prop("onItemAdded")?.({
|
|
85
|
+
index,
|
|
86
|
+
componentNames: clone.componentNames
|
|
87
|
+
});
|
|
88
|
+
announce(component, "rowAdded", index, clone.root);
|
|
89
|
+
component.refresh();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Removes a row and shifts every later row's index (and its nested fields' `name`s) down by
|
|
93
|
+
* one, via `renameFieldMachineForForm` - the same mechanism `Form.api.renameField` itself uses,
|
|
94
|
+
* which keeps recurring-field rows contiguously indexed without touching any field's value/
|
|
95
|
+
* touched/dirty/error state.
|
|
96
|
+
*/
|
|
97
|
+
function remove(component, index) {
|
|
98
|
+
if (!canRemove(component)) return;
|
|
99
|
+
const rowEl = component.hydrator.queryAll("item").find((el) => el.dataset.value === String(index));
|
|
100
|
+
if (!rowEl) return;
|
|
101
|
+
const focusTargetEl = findFocusTargetAfterRemoval(component, rowEl);
|
|
102
|
+
announce(component, "rowRemoved", index, rowEl);
|
|
103
|
+
destroyComponentsWithin(rowEl);
|
|
104
|
+
rowEl.remove();
|
|
105
|
+
reindexRowsAfter(component, index);
|
|
106
|
+
component.machine.prop("onItemRemoved")?.({ index });
|
|
107
|
+
component.refresh();
|
|
108
|
+
nextTick(() => focusTargetEl?.focus());
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Resolves what should receive focus once `rowEl` is gone, so keyboard/screen-reader users
|
|
112
|
+
* don't lose focus to `<body>` when the element they were just interacting with (its own
|
|
113
|
+
* `removeTrigger`) disappears: the next row's `removeTrigger`, or the previous row's if the
|
|
114
|
+
* removed row was last, or `addTrigger` if no rows remain. Resolved to a real element
|
|
115
|
+
* *before* removal, so the reference stays valid through the DOM mutation and reindexing that
|
|
116
|
+
* follow - `queryAll('item')` already reflects visual/DOM order, so this doesn't need to
|
|
117
|
+
* reason about numeric row indices at all.
|
|
118
|
+
*/
|
|
119
|
+
function findFocusTargetAfterRemoval(component, rowEl) {
|
|
120
|
+
const rows = component.hydrator.queryAll("item");
|
|
121
|
+
const removedPosition = rows.indexOf(rowEl);
|
|
122
|
+
const siblingRowEl = rows[removedPosition + 1] ?? rows[removedPosition - 1];
|
|
123
|
+
return siblingRowEl && component.hydrator.query("removeTrigger", siblingRowEl) || component.hydrator.query("addTrigger");
|
|
124
|
+
}
|
|
125
|
+
function nextIndex(component) {
|
|
126
|
+
const rows = getRows(component);
|
|
127
|
+
return rows.length > 0 ? Math.max(...rows.map((row) => row.index)) + 1 : 0;
|
|
128
|
+
}
|
|
129
|
+
function reindexRowsAfter(component, removedIndex) {
|
|
130
|
+
const rowsToShift = getRows(component).filter(({ index }) => index > removedIndex);
|
|
131
|
+
for (const { index } of rowsToShift) {
|
|
132
|
+
const rowEl = component.hydrator.queryAll("item").find((el) => el.dataset.value === String(index));
|
|
133
|
+
if (!rowEl) continue;
|
|
134
|
+
const newIndex = index - 1;
|
|
135
|
+
rowEl.querySelectorAll("[data-field-root]").forEach((fieldRootEl) => {
|
|
136
|
+
const oldName = fieldRootEl.dataset.name;
|
|
137
|
+
if (!oldName) return;
|
|
138
|
+
renameFieldMachineForForm(fieldRootEl, oldName, oldName.replace(`[${index}]`, `[${newIndex}]`));
|
|
139
|
+
});
|
|
140
|
+
component.hydrator.renameValue(rowEl, String(newIndex));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function announce(component, translationKey, index, rowEl) {
|
|
144
|
+
const entry = component.machine.prop("translations")?.[translationKey];
|
|
145
|
+
const text = typeof entry === "function" ? entry({
|
|
146
|
+
index,
|
|
147
|
+
rowEl,
|
|
148
|
+
getFieldValue: (name) => getRowFieldValue(component, rowEl, index, name)
|
|
149
|
+
}) : entry;
|
|
150
|
+
if (typeof text !== "string" || text === "") return;
|
|
151
|
+
component.machine.refs.get("liveRegion")?.announce(text.replaceAll("%number%", String(index + 1)));
|
|
152
|
+
}
|
|
153
|
+
function getRowFieldValue(component, rowEl, index, name) {
|
|
154
|
+
return getFieldValueFromContainer(rowEl, stringifyFieldPathAsBrackets([
|
|
155
|
+
component.machine.prop("name"),
|
|
156
|
+
index,
|
|
157
|
+
...parseFieldPath(name)
|
|
158
|
+
]));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region Resources/Private/Primitives/FieldArray/src/field-array.machine.ts
|
|
163
|
+
const machine = createMachine({
|
|
164
|
+
initialState() {
|
|
165
|
+
return "idle";
|
|
166
|
+
},
|
|
167
|
+
context() {
|
|
168
|
+
return {};
|
|
169
|
+
},
|
|
170
|
+
refs() {
|
|
171
|
+
return { liveRegion: null };
|
|
172
|
+
},
|
|
173
|
+
effects: ["manageLiveRegion"],
|
|
174
|
+
states: { idle: {} },
|
|
175
|
+
implementations: { effects: { manageLiveRegion({ refs }) {
|
|
176
|
+
const liveRegion = createLiveRegion({ level: "polite" });
|
|
177
|
+
refs.set("liveRegion", liveRegion);
|
|
178
|
+
return () => {
|
|
179
|
+
liveRegion.destroy();
|
|
180
|
+
};
|
|
181
|
+
} } }
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region Resources/Private/Primitives/FieldArray/src/field-array.props.ts
|
|
186
|
+
const props = createProps()([
|
|
187
|
+
"id",
|
|
188
|
+
"name",
|
|
189
|
+
"itemCount",
|
|
190
|
+
"minItems",
|
|
191
|
+
"maxItems",
|
|
192
|
+
"translations",
|
|
193
|
+
"onItemAdded",
|
|
194
|
+
"onItemRemoved"
|
|
195
|
+
]);
|
|
196
|
+
const splitProps = createSplitProps(props);
|
|
197
|
+
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region Resources/Private/Primitives/FieldArray/FieldArray.ts
|
|
200
|
+
var FieldArray = class extends Component {
|
|
201
|
+
static componentName = "fieldArray";
|
|
202
|
+
initMachine(props) {
|
|
203
|
+
const [machineProps] = splitProps(props);
|
|
204
|
+
return new Machine$1(machine, machineProps);
|
|
205
|
+
}
|
|
206
|
+
initApi() {
|
|
207
|
+
return connect(this, normalizeProps);
|
|
208
|
+
}
|
|
209
|
+
render() {
|
|
210
|
+
const addTriggerEl = this.hydrator.query("addTrigger");
|
|
211
|
+
if (addTriggerEl) this.spreadProps(addTriggerEl, this.api.getAddTriggerProps());
|
|
212
|
+
for (const removeTriggerEl of this.hydrator.queryAll("removeTrigger")) {
|
|
213
|
+
const index = Number(removeTriggerEl.dataset.value);
|
|
214
|
+
if (Number.isNaN(index)) continue;
|
|
215
|
+
this.spreadProps(removeTriggerEl, this.api.getRemoveTriggerProps(index));
|
|
216
|
+
}
|
|
217
|
+
const emptyStateEl = this.hydrator.query("emptyState");
|
|
218
|
+
if (emptyStateEl) emptyStateEl.hidden = this.hydrator.queryAll("item").length > 0;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
export { FieldArray };
|
package/dist/field.d.ts
CHANGED
|
@@ -1,60 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as FormMachine } from "./form.registry-Cb8Pvoe8.js";
|
|
3
|
-
import { EventObject } from "@zag-js/core";
|
|
4
|
-
import { PropTypes } from "@zag-js/types";
|
|
1
|
+
import { C as FieldValue, F as FieldSchema, P as FieldProps, S as FieldHandle, b as FieldClientApi, c as Machine, x as FieldDependencyChangeDetail, z as Component } from "./index-B06gIN_k.js";
|
|
5
2
|
|
|
6
|
-
//#region Resources/Private/Primitives/Field/src/field.types.d.ts
|
|
7
|
-
interface FieldProps {
|
|
8
|
-
id: string;
|
|
9
|
-
name: string;
|
|
10
|
-
invalid?: boolean;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
readOnly?: boolean;
|
|
14
|
-
}
|
|
15
|
-
interface FieldSchema {
|
|
16
|
-
props: FieldProps;
|
|
17
|
-
context: {
|
|
18
|
-
invalid: boolean;
|
|
19
|
-
required: boolean;
|
|
20
|
-
disabled: boolean;
|
|
21
|
-
readOnly: boolean;
|
|
22
|
-
formMachine: FormMachine | null;
|
|
23
|
-
describeIds: string | undefined;
|
|
24
|
-
hasDescription: boolean;
|
|
25
|
-
};
|
|
26
|
-
computed: {
|
|
27
|
-
errors: string[];
|
|
28
|
-
};
|
|
29
|
-
state: 'ready';
|
|
30
|
-
event: EventObject;
|
|
31
|
-
action: string;
|
|
32
|
-
effect: string;
|
|
33
|
-
}
|
|
34
|
-
interface FieldApi {
|
|
35
|
-
getFormMachine(): FieldSchema['context']['formMachine'];
|
|
36
|
-
invalid: boolean;
|
|
37
|
-
errors: string[];
|
|
38
|
-
name: string;
|
|
39
|
-
disabled: boolean;
|
|
40
|
-
required: boolean;
|
|
41
|
-
readOnly: boolean;
|
|
42
|
-
getRootProps(): PropTypes['element'];
|
|
43
|
-
getLabelProps(): PropTypes['label'];
|
|
44
|
-
getControlProps(): PropTypes['element'];
|
|
45
|
-
getErrorProps(): PropTypes['element'];
|
|
46
|
-
getDescriptionProps(): PropTypes['element'];
|
|
47
|
-
getErrorText(): string | null;
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
3
|
//#region Resources/Private/Primitives/Field/Field.d.ts
|
|
51
|
-
declare class Field extends Component<FieldProps,
|
|
52
|
-
static
|
|
53
|
-
|
|
4
|
+
declare class Field extends Component<FieldProps, FieldClientApi> {
|
|
5
|
+
static componentName: string;
|
|
6
|
+
/** The `validate` a consumer set; the machine itself runs {@link validate}, which adds the form's. */
|
|
7
|
+
private ownValidate;
|
|
8
|
+
private cleanups;
|
|
9
|
+
private cancelDeferredRender;
|
|
10
|
+
/** The base class types its machine as `Machine<any>`. */
|
|
11
|
+
private get fieldMachine();
|
|
54
12
|
initMachine(props: FieldProps): Machine<FieldSchema>;
|
|
55
|
-
initApi():
|
|
56
|
-
|
|
13
|
+
initApi(): FieldClientApi;
|
|
14
|
+
init(): void;
|
|
15
|
+
updateProps(newProps: Partial<FieldProps>): void;
|
|
57
16
|
render(): void;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Zag's props differ per element only in `readOnly`, and the control part is the one place a
|
|
20
|
+
* bare native element is wired up by the field itself (primitives bring their own control).
|
|
21
|
+
*/
|
|
22
|
+
private getControlProps;
|
|
23
|
+
/** What the machine validates with: the form's messages for this field, then the consumer's own. */
|
|
24
|
+
private validate;
|
|
25
|
+
/**
|
|
26
|
+
* `listenTo`: when a named sibling field in the same form changes value, this field announces
|
|
27
|
+
* `fluid-primitives:field:dependencychange` for consumer DOM reactions and treats it like a
|
|
28
|
+
* change of its own, so it revalidates under the same rules as when its user types.
|
|
29
|
+
*
|
|
30
|
+
* A sibling's registration may come later than this field's (the form can hydrate after its
|
|
31
|
+
* fields), so subscribing is retried whenever a form registers, until every name resolved.
|
|
32
|
+
*/
|
|
33
|
+
private listenToDependencies;
|
|
58
34
|
}
|
|
59
35
|
//#endregion
|
|
60
|
-
export { Field };
|
|
36
|
+
export { Field, type FieldClientApi, type FieldDependencyChangeDetail, type FieldHandle, type FieldProps, type FieldValue };
|