@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordion/accordion-item.mjs +2 -2
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +3 -20
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
- package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
- package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
- package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
- package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
- package/dist/alert-dialog/index.d.mts +33 -0
- package/dist/alert-dialog/index.d.mts.map +1 -0
- package/dist/alert-dialog/index.mjs +33 -0
- package/dist/alert-dialog/index.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
- package/dist/collapsible/collapsible-context.mjs +8 -0
- package/dist/collapsible/collapsible-context.mjs.map +1 -0
- package/dist/collapsible/collapsible-panel.d.mts +53 -0
- package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
- package/dist/collapsible/collapsible-panel.mjs +41 -0
- package/dist/collapsible/collapsible-panel.mjs.map +1 -0
- package/dist/collapsible/collapsible-root.d.mts +108 -0
- package/dist/collapsible/collapsible-root.d.mts.map +1 -0
- package/dist/collapsible/collapsible-root.mjs +147 -0
- package/dist/collapsible/collapsible-root.mjs.map +1 -0
- package/dist/collapsible/collapsible-trigger.d.mts +45 -0
- package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
- package/dist/collapsible/collapsible-trigger.mjs +62 -0
- package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
- package/dist/collapsible/index.d.mts +21 -0
- package/dist/collapsible/index.d.mts.map +1 -0
- package/dist/collapsible/index.mjs +21 -0
- package/dist/collapsible/index.mjs.map +1 -0
- package/dist/combobox/chip-text.mjs +24 -0
- package/dist/combobox/chip-text.mjs.map +1 -0
- package/dist/combobox/combobox-chips.d.mts +159 -0
- package/dist/combobox/combobox-chips.d.mts.map +1 -0
- package/dist/combobox/combobox-chips.mjs +198 -0
- package/dist/combobox/combobox-chips.mjs.map +1 -0
- package/dist/combobox/combobox-clear.d.mts +5 -2
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +3 -1
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs +4 -5
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts +10 -3
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +13 -5
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +50 -4
- package/dist/combobox/combobox-keyboard.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts +1 -1
- package/dist/combobox/combobox-list.mjs +2 -1
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts +5 -2
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +4 -3
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +127 -35
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +396 -44
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/index.d.mts +8 -2
- package/dist/combobox/index.d.mts.map +1 -1
- package/dist/combobox/index.mjs +7 -1
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/combobox/use-combobox-form.mjs +2 -3
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/dialog/dialog-close.d.mts +9 -5
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +19 -8
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.d.mts +2 -0
- package/dist/dialog/dialog-context.mjs +14 -2
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-description.d.mts +2 -1
- package/dist/dialog/dialog-description.d.mts.map +1 -1
- package/dist/dialog/dialog-description.mjs +8 -4
- package/dist/dialog/dialog-description.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts +2 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +11 -6
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +2 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +23 -14
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts +2 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +15 -5
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-title.d.mts +2 -1
- package/dist/dialog/dialog-title.d.mts.map +1 -1
- package/dist/dialog/dialog-title.mjs +8 -4
- package/dist/dialog/dialog-title.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts +2 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +14 -9
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/accordion.md +2 -0
- package/dist/docs/components/alert-dialog.md +546 -0
- package/dist/docs/components/collapsible.md +408 -0
- package/dist/docs/components/combobox.md +288 -26
- package/dist/docs/components/dialog.md +7 -5
- package/dist/docs/components/field.md +180 -3
- package/dist/docs/components/hover-card.md +494 -0
- package/dist/docs/components/multi-select.md +622 -0
- package/dist/docs/components/number-field.md +1 -1
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/select.md +9 -1
- package/dist/docs/components/separator.md +182 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/components/tooltip.md +1 -1
- package/dist/docs/concepts/experimental.md +3 -3
- package/dist/docs/concepts/server-components.md +1 -1
- package/dist/docs/index.md +7 -2
- package/dist/docs/roadmap.md +8 -0
- package/dist/field/field-control.d.mts +13 -4
- package/dist/field/field-control.d.mts.map +1 -1
- package/dist/field/field-control.mjs +39 -10
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-label.d.mts +6 -2
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +12 -2
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +9 -1
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/hover-card/hover-card-context.mjs +13 -0
- package/dist/hover-card/hover-card-context.mjs.map +1 -0
- package/dist/hover-card/hover-card-popup.d.mts +102 -0
- package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
- package/dist/hover-card/hover-card-popup.mjs +80 -0
- package/dist/hover-card/hover-card-popup.mjs.map +1 -0
- package/dist/hover-card/hover-card-root.d.mts +94 -0
- package/dist/hover-card/hover-card-root.d.mts.map +1 -0
- package/dist/hover-card/hover-card-root.mjs +74 -0
- package/dist/hover-card/hover-card-root.mjs.map +1 -0
- package/dist/hover-card/hover-card-trigger.d.mts +65 -0
- package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
- package/dist/hover-card/hover-card-trigger.mjs +109 -0
- package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
- package/dist/hover-card/index.d.mts +24 -0
- package/dist/hover-card/index.d.mts.map +1 -0
- package/dist/hover-card/index.mjs +24 -0
- package/dist/hover-card/index.mjs.map +1 -0
- package/dist/hover-card/use-hover-card-interest.mjs +242 -0
- package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
- package/dist/index.d.mts +38 -9
- package/dist/index.mjs +6 -1
- package/dist/internal/action/use-multiple-selection.mjs +83 -0
- package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
- package/dist/internal/details-summary.mjs +56 -0
- package/dist/internal/details-summary.mjs.map +1 -0
- package/dist/internal/form/field-context.mjs.map +1 -1
- package/dist/internal/form/hidden-values.mjs +29 -0
- package/dist/internal/form/hidden-values.mjs.map +1 -0
- package/dist/internal/form/validity.mjs +3 -1
- package/dist/internal/form/validity.mjs.map +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-close.mjs +5 -3
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +4 -1
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-popup.mjs +20 -7
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
- package/dist/internal/typeahead.mjs +52 -0
- package/dist/internal/typeahead.mjs.map +1 -0
- package/dist/{combobox → internal}/use-active-option.mjs +8 -6
- package/dist/internal/use-active-option.mjs.map +1 -0
- package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
- package/dist/internal/use-deferred-leave.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +57 -1
- package/dist/internal/use-name-warning.mjs.map +1 -1
- package/dist/internal/use-option-registry.mjs +70 -0
- package/dist/internal/use-option-registry.mjs.map +1 -0
- package/dist/menu/use-menu-keyboard.mjs +7 -27
- package/dist/menu/use-menu-keyboard.mjs.map +1 -1
- package/dist/multi-select/index.d.mts +37 -0
- package/dist/multi-select/index.d.mts.map +1 -0
- package/dist/multi-select/index.mjs +37 -0
- package/dist/multi-select/index.mjs.map +1 -0
- package/dist/multi-select/multi-select-context.mjs +19 -0
- package/dist/multi-select/multi-select-context.mjs.map +1 -0
- package/dist/multi-select/multi-select-group.d.mts +120 -0
- package/dist/multi-select/multi-select-group.d.mts.map +1 -0
- package/dist/multi-select/multi-select-group.mjs +111 -0
- package/dist/multi-select/multi-select-group.mjs.map +1 -0
- package/dist/multi-select/multi-select-keyboard.mjs +145 -0
- package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
- package/dist/multi-select/multi-select-label.d.mts +42 -0
- package/dist/multi-select/multi-select-label.d.mts.map +1 -0
- package/dist/multi-select/multi-select-label.mjs +41 -0
- package/dist/multi-select/multi-select-label.mjs.map +1 -0
- package/dist/multi-select/multi-select-list.d.mts +47 -0
- package/dist/multi-select/multi-select-list.d.mts.map +1 -0
- package/dist/multi-select/multi-select-list.mjs +65 -0
- package/dist/multi-select/multi-select-list.mjs.map +1 -0
- package/dist/multi-select/multi-select-option.d.mts +68 -0
- package/dist/multi-select/multi-select-option.d.mts.map +1 -0
- package/dist/multi-select/multi-select-option.mjs +93 -0
- package/dist/multi-select/multi-select-option.mjs.map +1 -0
- package/dist/multi-select/multi-select-popup.d.mts +58 -0
- package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
- package/dist/multi-select/multi-select-popup.mjs +71 -0
- package/dist/multi-select/multi-select-popup.mjs.map +1 -0
- package/dist/multi-select/multi-select-root.d.mts +125 -0
- package/dist/multi-select/multi-select-root.d.mts.map +1 -0
- package/dist/multi-select/multi-select-root.mjs +257 -0
- package/dist/multi-select/multi-select-root.mjs.map +1 -0
- package/dist/multi-select/multi-select-trigger.d.mts +66 -0
- package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
- package/dist/multi-select/multi-select-trigger.mjs +169 -0
- package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
- package/dist/multi-select/multi-select-value.d.mts +57 -0
- package/dist/multi-select/multi-select-value.d.mts.map +1 -0
- package/dist/multi-select/multi-select-value.mjs +41 -0
- package/dist/multi-select/multi-select-value.mjs.map +1 -0
- package/dist/number-field/number-field-root.mjs +1 -1
- package/dist/number-field/use-step-button.d.mts.map +1 -1
- package/dist/number-field/use-step-button.mjs +11 -2
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +6 -3
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +3 -2
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.mjs +1 -1
- package/dist/select/select-root.d.mts +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +5 -1
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/separator/index.d.mts +3 -0
- package/dist/separator/index.mjs +1 -0
- package/dist/separator/separator.d.mts +58 -0
- package/dist/separator/separator.d.mts.map +1 -0
- package/dist/separator/separator.mjs +41 -0
- package/dist/separator/separator.mjs.map +1 -0
- package/dist/slider/slider-root.mjs +1 -0
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.mjs +1 -1
- package/package.json +6 -1
- package/skills/funstack-ui-knowledge/SKILL.md +14 -9
- package/dist/combobox/use-active-option.mjs.map +0 -1
- package/dist/combobox/use-deferred-leave.mjs.map +0 -1
- package/dist/combobox/use-option-registry.mjs +0 -52
- package/dist/combobox/use-option-registry.mjs.map +0 -1
|
@@ -168,14 +168,19 @@ function FieldRoot({ name, disabled = false, required = false, validate, classNa
|
|
|
168
168
|
element.addEventListener("change", onEdit, true);
|
|
169
169
|
element.addEventListener("focusout", onBlur, true);
|
|
170
170
|
element.addEventListener("invalid", onInvalid, true);
|
|
171
|
+
const outside = validityElementOf(element) === null ? control?.validityElement?.() ?? null : null;
|
|
172
|
+
const listenOutside = outside !== null && !element.contains(outside);
|
|
173
|
+
if (listenOutside) outside.addEventListener("invalid", onInvalid, true);
|
|
171
174
|
return () => {
|
|
172
175
|
element.removeEventListener("input", onEdit, true);
|
|
173
176
|
element.removeEventListener("change", onEdit, true);
|
|
174
177
|
element.removeEventListener("focusout", onBlur, true);
|
|
175
178
|
element.removeEventListener("invalid", onInvalid, true);
|
|
179
|
+
if (listenOutside) outside.removeEventListener("invalid", onInvalid, true);
|
|
176
180
|
};
|
|
177
181
|
}, [
|
|
178
182
|
element,
|
|
183
|
+
control,
|
|
179
184
|
refresh,
|
|
180
185
|
dismiss
|
|
181
186
|
]);
|
|
@@ -235,7 +240,7 @@ function FieldRoot({ name, disabled = false, required = false, validate, classNa
|
|
|
235
240
|
]);
|
|
236
241
|
useEffect(() => {
|
|
237
242
|
if (!isDev || controlRef.current !== null) return;
|
|
238
|
-
console.error("Field.Root: no form control registered. Render a Field.Control or a FUNSTACK form control (Checkbox, Switch, RadioGroup, CheckboxGroup, Select, Combobox, Slider, NumberField) inside it.");
|
|
243
|
+
console.error("Field.Root: no form control registered. Render a Field.Control or a FUNSTACK form control (Checkbox, Switch, RadioGroup, CheckboxGroup, Select, Combobox, MultiSelect, Slider, NumberField) inside it.");
|
|
239
244
|
}, []);
|
|
240
245
|
const invalid = mirror.userInvalid || serverShown;
|
|
241
246
|
const messages = serverShown ? serverMessages : mirror.userInvalid ? mirror.messages : NONE;
|
|
@@ -258,6 +263,7 @@ function FieldRoot({ name, disabled = false, required = false, validate, classNa
|
|
|
258
263
|
formPending
|
|
259
264
|
]);
|
|
260
265
|
const labelable = control?.labelable ?? true;
|
|
266
|
+
const controlElement = useCallback(() => controlRef.current?.element ?? null, []);
|
|
261
267
|
const context = useMemo(() => ({
|
|
262
268
|
ids,
|
|
263
269
|
name,
|
|
@@ -265,6 +271,7 @@ function FieldRoot({ name, disabled = false, required = false, validate, classNa
|
|
|
265
271
|
required,
|
|
266
272
|
state: memoState,
|
|
267
273
|
labelable,
|
|
274
|
+
controlElement,
|
|
268
275
|
registerControl,
|
|
269
276
|
registerError,
|
|
270
277
|
notifyChange
|
|
@@ -275,6 +282,7 @@ function FieldRoot({ name, disabled = false, required = false, validate, classNa
|
|
|
275
282
|
required,
|
|
276
283
|
memoState,
|
|
277
284
|
labelable,
|
|
285
|
+
controlElement,
|
|
278
286
|
registerControl,
|
|
279
287
|
registerError,
|
|
280
288
|
notifyChange
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-root.mjs","names":[],"sources":["../../src/field/field-root.tsx"],"sourcesContent":["\"use client\";\nimport {\n use,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode, RefObject } from \"react\";\nimport { useFormStatus } from \"react-dom\";\nimport { FieldContext, fieldDataAttributes, FormContext } from \"../internal/form/field-context.js\";\nimport type {\n FieldContextValue,\n FieldControlRegistration,\n FieldState,\n FormFieldRegistration,\n} from \"../internal/form/field-context.js\";\nimport { collectInvalid } from \"../internal/form/focus-first-invalid.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useFormOwnerEvent } from \"../internal/form/use-form-owner-event.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useServerErrorVisibility } from \"./use-server-error-visibility.js\";\nimport {\n focusTargetOf,\n normaliseErrorValue,\n snapshotValidity,\n supportsUserInvalid,\n VALID,\n validityElementOf,\n validityEquals,\n} from \"../internal/form/validity.js\";\nimport type {\n FieldErrorValue,\n FieldValidity,\n ValidatableElement,\n} from \"../internal/form/validity.js\";\nimport { arraysEqual } from \"../internal/value-set.js\";\n\nexport type { FieldState } from \"../internal/form/field-context.js\";\nexport type { FieldValidity } from \"../internal/form/validity.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * A custom constraint: receives the field's submitted value (`formData.get(name)` as a string,\n * `\"\"` when absent) and the whole form's `FormData`. Return a message (or several) for an error,\n * `null` / `undefined` / `\"\"` for none.\n */\nexport type FieldValidate = (value: string, formData: FormData) => FieldErrorValue;\n\n/**\n * Props of `Field.Root`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"className\" | \"style\" | \"children\"\n> {\n /** Form field name: the control's default `name`, the key in `Form.Root errors`, and the entry `validate` reads. */\n name?: string;\n /**\n * Disables the control (native `disabled`) and marks every part `data-disabled`.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Makes the control `required` (native) and marks every part `data-required`.\n *\n * @defaultValue `false`\n */\n required?: boolean;\n /**\n * A custom constraint, written into the control with `setCustomValidity`. Sync. Receives the\n * field's submitted value (`formData.get(name)` as a string, `\"\"` when absent) and the whole\n * form's `FormData`, so a cross-field rule can read the other field. Runs at mount, on every\n * `input` / `change` in the form (and a FUNSTACK control's value change), on blur, after a\n * reset, on a submission attempt, and in every commit in which this prop changed identity, so\n * a rule that reads outside state (a list that loads, a sibling value in React state) updates\n * on render. An inline function therefore re-runs on every render of the Field; wrap it in\n * `useCallback` to re-run only when its inputs change. Return a string\n * or strings for an error, `null` / `undefined` / `\"\"` for none. Shown when the platform's\n * `:user-invalid` heuristic says so, like a native constraint. Not serialisable: a Field with\n * `validate` is rendered from a client component.\n */\n validate?: FieldValidate;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, FieldState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, FieldState>;\n}\n\n/** The urgent mirror of browser-owned validity (design 2.4). */\ninterface Mirror {\n readonly userInvalid: boolean;\n readonly validity: FieldValidity;\n readonly messages: readonly string[];\n}\n\nconst NONE: readonly string[] = Object.freeze([]);\nconst INITIAL_MIRROR: Mirror = { userInvalid: false, validity: VALID, messages: NONE };\n\ninterface RefreshOptions {\n /** The user edited the control: the server message is dropped from the slot at once. */\n readonly dismiss?: boolean;\n /** After a form reset: the user-validity flag is clear again. */\n readonly reset?: boolean;\n}\n\nfunction mirrorEquals(a: Mirror, b: Mirror): boolean {\n return (\n a.userInvalid === b.userInvalid &&\n validityEquals(a.validity, b.validity) &&\n arraysEqual(a.messages, b.messages)\n );\n}\n\n/** `FormData` entries as comparable strings; a `File` counts as unchanged (design 3.2 item 2). */\nfunction entryStrings(entries: readonly FormDataEntryValue[]): string[] {\n return entries.map((entry) => (typeof entry === \"string\" ? entry : \"\\u0000file\"));\n}\n\n/**\n * The field: a `div` that owns the ids, the urgent validity mirror, the custom-validity slot\n * (`validate` and the server error), the control registration and the native listeners\n * (design/components/field-form.md 2, 14). `data-pending` is the enclosing form's submission\n * (`useFormStatus`), the one part that folds the form channel into its own state, because a\n * Field has no action of its own.\n *\n * Owned keys (conventions 1.2): `data-invalid`, `data-disabled`, `data-required`, `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldRoot({\n name,\n disabled = false,\n required = false,\n validate,\n className,\n style,\n children,\n render,\n ...rest\n}: FieldRootProps) {\n const parent = use(FieldContext);\n const form = use(FormContext);\n useDevWarning(\n parent !== null,\n isDev &&\n \"Field.Root: nested inside another Field.Root. A control registers with the nearest Field \" +\n \"only; give each control its own, sibling Field.\",\n );\n useDevWarning(\n validate !== undefined && name === undefined,\n isDev &&\n \"Field.Root: `validate` without `name`. `validate` receives `formData.get(name)`, which is \" +\n 'always \"\" without a name.',\n );\n\n const id = useId();\n const ids = useMemo(\n () => ({\n control: `${id}-control`,\n label: `${id}-label`,\n description: `${id}-description`,\n error: `${id}-error`,\n }),\n [id],\n );\n\n const { pending: formPending } = useFormStatus();\n\n // --- Registration -------------------------------------------------------------------------\n\n const controlRef = useRef<FieldControlRegistration | null>(null);\n const [control, setControl] = useState<FieldControlRegistration | null>(null);\n const warnedTwoControls = useRef(false);\n const registerControl = useCallback((registration: FieldControlRegistration) => {\n const current = controlRef.current;\n if (current !== null && current.element !== registration.element) {\n if (isDev && !warnedTwoControls.current) {\n warnedTwoControls.current = true;\n console.error(\n \"Field.Root: two form controls registered in one Field. The first one is the \" +\n \"Field's control; give each control its own Field.Root.\",\n );\n }\n return () => {};\n }\n controlRef.current = registration;\n setControl(registration);\n return () => {\n if (controlRef.current !== registration) return;\n controlRef.current = null;\n setControl(null);\n };\n }, []);\n\n const errorCount = useRef(0);\n const registerError = useCallback(() => {\n errorCount.current += 1;\n if (isDev && errorCount.current === 2) {\n console.error(\n \"Field.Error: two Field.Error parts in one Field.Root. Render one; its function \" +\n \"`children` receives `validity` for per-constraint wording.\",\n );\n }\n return () => {\n errorCount.current -= 1;\n };\n }, []);\n\n // --- Server errors: shown, dismissed, re-armed, suppressed (design 3.4) -------------------\n\n const errors = form?.errors;\n const serverMessages = useMemo(\n () => normaliseErrorValue(name === undefined ? undefined : errors?.[name]),\n [errors, name],\n );\n const serverKey = serverMessages.join(\"\\n\");\n const { serverShown, dismiss, setSuppressNext } = useServerErrorVisibility(\n formPending,\n serverMessages,\n );\n\n // --- The mirror -----------------------------------------------------------------------------\n\n const [mirror, setMirror] = useState<Mirror>(INITIAL_MIRROR);\n /** The last mirror written: `refresh` compares against it, so an unchanged read renders nothing. */\n const mirrorRef = useRef<Mirror>(INITIAL_MIRROR);\n /** jsdom fallback for `:user-invalid` (design 2.2): `invalid` fired, cleared by a reset. */\n const attempted = useRef(false);\n /** The element the slot was last written on (a group's first member can change). */\n const slotElement = useRef<ValidatableElement | null>(null);\n\n const latest = useLatest({ name, validate, serverMessages, serverShown, formPending, form });\n\n /** Re-reads the slot and the mirror; returns the messages the Field shows for the control. */\n const refresh = useCallback(\n (options: RefreshOptions = {}): readonly string[] => {\n const registration = controlRef.current;\n if (registration === null) return NONE;\n // The element whose validity is real (field-form.md, `validityElement`) and the\n // element whose `:user-invalid` the user's interaction sets; the same for every control but\n // NumberField.\n const surface = validityElementOf(registration.element);\n const el = registration.validityElement?.() ?? surface;\n if (el === null) return NONE;\n const { name, validate, serverMessages, serverShown, formPending, form } = latest.current;\n\n const owner = el.form;\n const formData = owner === null ? new FormData() : new FormData(owner);\n const entry = name === undefined ? null : formData.get(name);\n const value = typeof entry === \"string\" ? entry : \"\";\n const custom = validate === undefined ? NONE : normaliseErrorValue(validate(value, formData));\n\n // The slot (design 2.1): the server message while shown, else `validate`'s.\n const showServer = serverShown && options.dismiss !== true;\n if (slotElement.current !== null && slotElement.current !== el) {\n slotElement.current.setCustomValidity(\"\");\n }\n slotElement.current = el;\n el.setCustomValidity(showServer ? serverMessages.join(\"\\n\") : custom.join(\"\\n\"));\n // Mirror onto the surface so its `:user-invalid` read below sees the new state (the control\n // writes the same derived value after each of its own writes).\n if (\n surface !== null &&\n surface !== el &&\n surface.validationMessage !== el.validationMessage\n ) {\n surface.setCustomValidity(el.validationMessage);\n }\n\n if (options.reset === true) attempted.current = false;\n const userInvalid = supportsUserInvalid()\n ? (surface ?? el).matches(\":user-invalid\")\n : attempted.current && !el.validity.valid;\n const validity = snapshotValidity(el.validity);\n const messages = validity.valid\n ? NONE\n : validity.customError && !showServer && custom.length > 0\n ? custom\n : el.validationMessage === \"\"\n ? NONE\n : [el.validationMessage];\n const next: Mirror = { userInvalid, validity, messages };\n // Only a change schedules a render (a `focusout` with nothing new causes none).\n if (!mirrorEquals(mirrorRef.current, next)) {\n mirrorRef.current = next;\n setMirror(next);\n }\n\n // Stale-value suppression (design 3.2 item 2): while the Form's own submission is in\n // flight, an error is about the value it sent; compare with what the field holds now.\n const submitted = formPending && name !== undefined ? (form?.submittedData() ?? null) : null;\n if (submitted !== null && name !== undefined) {\n setSuppressNext(\n !arraysEqual(entryStrings(formData.getAll(name)), entryStrings(submitted.getAll(name))),\n );\n }\n return showServer ? serverMessages : messages;\n },\n [latest, setSuppressNext],\n );\n\n // The slot follows the server error and `validate` (and is written once the control is known).\n // Keyed on `validate`'s identity (design 2.1): a rule reading outside state updates in the\n // commit that changed it. An inline function re-runs on every render (documented: `useCallback`\n // avoids it); the form's own values are covered by the listeners below.\n useLayoutEffect(() => {\n refresh();\n }, [refresh, control, serverShown, serverKey, validate]);\n\n // Clear the slot when the control goes away (it may be reused outside the Field).\n useLayoutEffect(\n () => () => {\n slotElement.current?.setCustomValidity(\"\");\n slotElement.current = null;\n },\n [],\n );\n\n // The control's own events (capture, so a group's members are seen on its fieldset).\n const element = control?.element ?? null;\n useLayoutEffect(() => {\n if (element === null) return;\n const onEdit = () => {\n dismiss();\n refresh({ dismiss: true });\n };\n const onBlur = () => refresh();\n const onInvalid = (event: Event) => {\n const target = event.target as ValidatableElement;\n // A submission attempt sets user validity before validating; `checkValidity()` and\n // `reportValidity()` do not (design 2.5). The fallback cannot tell them apart.\n const attempt = supportsUserInvalid() ? target.matches(\":user-invalid\") : true;\n if (!supportsUserInvalid()) attempted.current = true;\n if (attempt && errorCount.current > 0) {\n event.preventDefault();\n const messages = refresh();\n collectInvalid(focusTargetOf(element), messages.join(\" \"), target);\n return;\n }\n refresh();\n };\n element.addEventListener(\"input\", onEdit, true);\n element.addEventListener(\"change\", onEdit, true);\n element.addEventListener(\"focusout\", onBlur, true);\n element.addEventListener(\"invalid\", onInvalid, true);\n return () => {\n element.removeEventListener(\"input\", onEdit, true);\n element.removeEventListener(\"change\", onEdit, true);\n element.removeEventListener(\"focusout\", onBlur, true);\n element.removeEventListener(\"invalid\", onInvalid, true);\n };\n }, [element, refresh, dismiss]);\n\n // The form owner's events: another field's edit re-runs `validate` (cross-field rules); a reset\n // clears the user-validity flag, re-read when the controls hold their reset values.\n const ownerRef = useMemo<RefObject<Element | null>>(\n () => ({\n get current() {\n return controlRef.current?.element ?? null;\n },\n set current(_ignored) {},\n }),\n [],\n );\n const onOwnerEdit = (event: Event) => {\n const target = event.target;\n if (target instanceof Node && controlRef.current?.element.contains(target) === true) return;\n refresh();\n };\n useFormOwnerEvent(ownerRef, \"input\", onOwnerEdit);\n useFormOwnerEvent(ownerRef, \"change\", onOwnerEdit);\n // A new submission sends the current values: nothing differs from it yet (a queued second\n // submit arrives while the status stays pending, so the pending edge alone would miss it).\n useFormOwnerEvent(ownerRef, \"submit\", () => {\n setSuppressNext(false);\n });\n useFormOwnerEvent(ownerRef, \"reset\", (event) => {\n queueMicrotask(() => {\n if (event.defaultPrevented) return;\n refresh({ reset: true });\n });\n });\n\n // Registration with the Form, for the first-error focus after a settle (design 3.5) and the\n // refresh of the other Fields on a change no DOM event carried.\n const registerField = form?.registerField;\n const formRegistration = useRef<FormFieldRegistration | null>(null);\n useLayoutEffect(() => {\n if (registerField === undefined) return;\n const registration: FormFieldRegistration = {\n getFocusTarget: () => focusTargetOf(controlRef.current?.element ?? null),\n showsServerError: () => latest.current.serverShown,\n serverMessages: () => latest.current.serverMessages,\n refresh: () => {\n refresh();\n },\n };\n formRegistration.current = registration;\n const unregister = registerField(registration);\n return () => {\n unregister();\n if (formRegistration.current === registration) formRegistration.current = null;\n };\n }, [registerField, latest, refresh]);\n\n const notifyChange = useCallback(\n (edit: boolean) => {\n if (edit) dismiss();\n refresh(edit ? { dismiss: true } : {});\n latest.current.form?.refreshFields(formRegistration.current);\n },\n [refresh, latest, dismiss],\n );\n\n // Development: a Field around something that is not a form control (Toggle, Menu, ...).\n useEffect(() => {\n if (!isDev || controlRef.current !== null) return;\n console.error(\n \"Field.Root: no form control registered. Render a Field.Control or a FUNSTACK form \" +\n \"control (Checkbox, Switch, RadioGroup, CheckboxGroup, Select, Combobox, Slider, \" +\n \"NumberField) inside it.\",\n );\n }, []);\n\n const invalid = mirror.userInvalid || serverShown;\n const messages = serverShown ? serverMessages : mirror.userInvalid ? mirror.messages : NONE;\n const validity = mirror.validity;\n const stateDisabled = disabled || (control?.disabled ?? false);\n const stateRequired = required || (control?.required ?? false);\n // Memoised: the context value (and so every part) changes only with the state.\n const memoState = useMemo<FieldState>(\n () => ({\n invalid,\n messages,\n validity,\n disabled: stateDisabled,\n required: stateRequired,\n pending: formPending,\n }),\n [invalid, messages, validity, stateDisabled, stateRequired, formPending],\n );\n\n const labelable = control?.labelable ?? true;\n const context = useMemo<FieldContextValue>(\n () => ({\n ids,\n name,\n disabled,\n required,\n state: memoState,\n labelable,\n registerControl,\n registerError,\n notifyChange,\n }),\n [\n ids,\n name,\n disabled,\n required,\n memoState,\n labelable,\n registerControl,\n registerError,\n notifyChange,\n ],\n );\n\n const element$ = useRender<ComponentPropsWithRef<\"div\">, FieldState>({\n defaultElement: \"div\",\n render,\n state: memoState,\n className,\n style,\n children,\n props: rest,\n libraryProps: fieldDataAttributes(memoState),\n });\n\n return <FieldContext value={context}>{element$}</FieldContext>;\n}\n\nFieldRoot.displayName = \"FieldRoot\";\n"],"mappings":";;;;;;;;;;;;;;AA8CA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AA+DvC,MAAM,OAA0B,OAAO,OAAO,CAAC,CAAC;AAChD,MAAM,iBAAyB;CAAE,aAAa;CAAO,UAAU;CAAO,UAAU;AAAK;AASrF,SAAS,aAAa,GAAW,GAAoB;CACnD,OACE,EAAE,gBAAgB,EAAE,eACpB,eAAe,EAAE,UAAU,EAAE,QAAQ,KACrC,YAAY,EAAE,UAAU,EAAE,QAAQ;AAEtC;;AAGA,SAAS,aAAa,SAAkD;CACtE,OAAO,QAAQ,KAAK,UAAW,OAAO,UAAU,WAAW,QAAQ,QAAa;AAClF;;;;;;;;;;;;AAaA,SAAgB,UAAU,EACxB,MACA,WAAW,OACX,WAAW,OACX,UACA,WACA,OACA,UACA,QACA,GAAG,QACc;CACjB,MAAM,SAAS,IAAI,YAAY;CAC/B,MAAM,OAAO,IAAI,WAAW;CAC5B,cACE,WAAW,MACX,SACE,0IAEJ;CACA,cACE,aAAa,KAAA,KAAa,SAAS,KAAA,GACnC,SACE,uHAEJ;CAEA,MAAM,KAAK,MAAM;CACjB,MAAM,MAAM,eACH;EACL,SAAS,GAAG,GAAG;EACf,OAAO,GAAG,GAAG;EACb,aAAa,GAAG,GAAG;EACnB,OAAO,GAAG,GAAG;CACf,IACA,CAAC,EAAE,CACL;CAEA,MAAM,EAAE,SAAS,gBAAgB,cAAc;CAI/C,MAAM,aAAa,OAAwC,IAAI;CAC/D,MAAM,CAAC,SAAS,cAAc,SAA0C,IAAI;CAC5E,MAAM,oBAAoB,OAAO,KAAK;CACtC,MAAM,kBAAkB,aAAa,iBAA2C;EAC9E,MAAM,UAAU,WAAW;EAC3B,IAAI,YAAY,QAAQ,QAAQ,YAAY,aAAa,SAAS;GAChE,IAAI,SAAS,CAAC,kBAAkB,SAAS;IACvC,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ACA,UAAU;EACV,UAAU;EACV,SAAS;CACX,IACA;EAAC;EAAS;EAAU;EAAU;EAAe;EAAe;CAAW,CACzE;CAEA,MAAM,YAAY,SAAS,aAAa;CACxC,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,WAAW,UAAoD;EACnE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP,cAAc,oBAAoB,SAAS;CAC7C,CAAC;CAED,OAAO,oBAAC,cAAD;EAAc,OAAO;EAAU,UAAA;CAAuB,CAAA;AAC/D;AAEA,UAAU,cAAc"}
|
|
1
|
+
{"version":3,"file":"field-root.mjs","names":[],"sources":["../../src/field/field-root.tsx"],"sourcesContent":["\"use client\";\nimport {\n use,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode, RefObject } from \"react\";\nimport { useFormStatus } from \"react-dom\";\nimport { FieldContext, fieldDataAttributes, FormContext } from \"../internal/form/field-context.js\";\nimport type {\n FieldContextValue,\n FieldControlRegistration,\n FieldState,\n FormFieldRegistration,\n} from \"../internal/form/field-context.js\";\nimport { collectInvalid } from \"../internal/form/focus-first-invalid.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useFormOwnerEvent } from \"../internal/form/use-form-owner-event.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useServerErrorVisibility } from \"./use-server-error-visibility.js\";\nimport {\n focusTargetOf,\n normaliseErrorValue,\n snapshotValidity,\n supportsUserInvalid,\n VALID,\n validityElementOf,\n validityEquals,\n} from \"../internal/form/validity.js\";\nimport type {\n FieldErrorValue,\n FieldValidity,\n ValidatableElement,\n} from \"../internal/form/validity.js\";\nimport { arraysEqual } from \"../internal/value-set.js\";\n\nexport type { FieldState } from \"../internal/form/field-context.js\";\nexport type { FieldValidity } from \"../internal/form/validity.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * A custom constraint: receives the field's submitted value (`formData.get(name)` as a string,\n * `\"\"` when absent) and the whole form's `FormData`. Return a message (or several) for an error,\n * `null` / `undefined` / `\"\"` for none.\n */\nexport type FieldValidate = (value: string, formData: FormData) => FieldErrorValue;\n\n/**\n * Props of `Field.Root`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"className\" | \"style\" | \"children\"\n> {\n /** Form field name: the control's default `name`, the key in `Form.Root errors`, and the entry `validate` reads. */\n name?: string;\n /**\n * Disables the control (native `disabled`) and marks every part `data-disabled`.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Makes the control `required` (native) and marks every part `data-required`.\n *\n * @defaultValue `false`\n */\n required?: boolean;\n /**\n * A custom constraint, written into the control with `setCustomValidity`. Sync. Receives the\n * field's submitted value (`formData.get(name)` as a string, `\"\"` when absent) and the whole\n * form's `FormData`, so a cross-field rule can read the other field. Runs at mount, on every\n * `input` / `change` in the form (and a FUNSTACK control's value change), on blur, after a\n * reset, on a submission attempt, and in every commit in which this prop changed identity, so\n * a rule that reads outside state (a list that loads, a sibling value in React state) updates\n * on render. An inline function therefore re-runs on every render of the Field; wrap it in\n * `useCallback` to re-run only when its inputs change. Return a string\n * or strings for an error, `null` / `undefined` / `\"\"` for none. Shown when the platform's\n * `:user-invalid` heuristic says so, like a native constraint. Not serialisable: a Field with\n * `validate` is rendered from a client component.\n */\n validate?: FieldValidate;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, FieldState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, FieldState>;\n}\n\n/** The urgent mirror of browser-owned validity (design 2.4). */\ninterface Mirror {\n readonly userInvalid: boolean;\n readonly validity: FieldValidity;\n readonly messages: readonly string[];\n}\n\nconst NONE: readonly string[] = Object.freeze([]);\nconst INITIAL_MIRROR: Mirror = { userInvalid: false, validity: VALID, messages: NONE };\n\ninterface RefreshOptions {\n /** The user edited the control: the server message is dropped from the slot at once. */\n readonly dismiss?: boolean;\n /** After a form reset: the user-validity flag is clear again. */\n readonly reset?: boolean;\n}\n\nfunction mirrorEquals(a: Mirror, b: Mirror): boolean {\n return (\n a.userInvalid === b.userInvalid &&\n validityEquals(a.validity, b.validity) &&\n arraysEqual(a.messages, b.messages)\n );\n}\n\n/** `FormData` entries as comparable strings; a `File` counts as unchanged (design 3.2 item 2). */\nfunction entryStrings(entries: readonly FormDataEntryValue[]): string[] {\n return entries.map((entry) => (typeof entry === \"string\" ? entry : \"\\u0000file\"));\n}\n\n/**\n * The field: a `div` that owns the ids, the urgent validity mirror, the custom-validity slot\n * (`validate` and the server error), the control registration and the native listeners\n * (design/components/field-form.md 2, 14). `data-pending` is the enclosing form's submission\n * (`useFormStatus`), the one part that folds the form channel into its own state, because a\n * Field has no action of its own.\n *\n * Owned keys (conventions 1.2): `data-invalid`, `data-disabled`, `data-required`, `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldRoot({\n name,\n disabled = false,\n required = false,\n validate,\n className,\n style,\n children,\n render,\n ...rest\n}: FieldRootProps) {\n const parent = use(FieldContext);\n const form = use(FormContext);\n useDevWarning(\n parent !== null,\n isDev &&\n \"Field.Root: nested inside another Field.Root. A control registers with the nearest Field \" +\n \"only; give each control its own, sibling Field.\",\n );\n useDevWarning(\n validate !== undefined && name === undefined,\n isDev &&\n \"Field.Root: `validate` without `name`. `validate` receives `formData.get(name)`, which is \" +\n 'always \"\" without a name.',\n );\n\n const id = useId();\n const ids = useMemo(\n () => ({\n control: `${id}-control`,\n label: `${id}-label`,\n description: `${id}-description`,\n error: `${id}-error`,\n }),\n [id],\n );\n\n const { pending: formPending } = useFormStatus();\n\n // --- Registration -------------------------------------------------------------------------\n\n const controlRef = useRef<FieldControlRegistration | null>(null);\n const [control, setControl] = useState<FieldControlRegistration | null>(null);\n const warnedTwoControls = useRef(false);\n const registerControl = useCallback((registration: FieldControlRegistration) => {\n const current = controlRef.current;\n if (current !== null && current.element !== registration.element) {\n if (isDev && !warnedTwoControls.current) {\n warnedTwoControls.current = true;\n console.error(\n \"Field.Root: two form controls registered in one Field. The first one is the \" +\n \"Field's control; give each control its own Field.Root.\",\n );\n }\n return () => {};\n }\n controlRef.current = registration;\n setControl(registration);\n return () => {\n if (controlRef.current !== registration) return;\n controlRef.current = null;\n setControl(null);\n };\n }, []);\n\n const errorCount = useRef(0);\n const registerError = useCallback(() => {\n errorCount.current += 1;\n if (isDev && errorCount.current === 2) {\n console.error(\n \"Field.Error: two Field.Error parts in one Field.Root. Render one; its function \" +\n \"`children` receives `validity` for per-constraint wording.\",\n );\n }\n return () => {\n errorCount.current -= 1;\n };\n }, []);\n\n // --- Server errors: shown, dismissed, re-armed, suppressed (design 3.4) -------------------\n\n const errors = form?.errors;\n const serverMessages = useMemo(\n () => normaliseErrorValue(name === undefined ? undefined : errors?.[name]),\n [errors, name],\n );\n const serverKey = serverMessages.join(\"\\n\");\n const { serverShown, dismiss, setSuppressNext } = useServerErrorVisibility(\n formPending,\n serverMessages,\n );\n\n // --- The mirror -----------------------------------------------------------------------------\n\n const [mirror, setMirror] = useState<Mirror>(INITIAL_MIRROR);\n /** The last mirror written: `refresh` compares against it, so an unchanged read renders nothing. */\n const mirrorRef = useRef<Mirror>(INITIAL_MIRROR);\n /** jsdom fallback for `:user-invalid` (design 2.2): `invalid` fired, cleared by a reset. */\n const attempted = useRef(false);\n /** The element the slot was last written on (a group's first member can change). */\n const slotElement = useRef<ValidatableElement | null>(null);\n\n const latest = useLatest({ name, validate, serverMessages, serverShown, formPending, form });\n\n /** Re-reads the slot and the mirror; returns the messages the Field shows for the control. */\n const refresh = useCallback(\n (options: RefreshOptions = {}): readonly string[] => {\n const registration = controlRef.current;\n if (registration === null) return NONE;\n // The element whose validity is real (field-form.md, `validityElement`) and the\n // element whose `:user-invalid` the user's interaction sets; the same for every control but\n // NumberField.\n const surface = validityElementOf(registration.element);\n const el = registration.validityElement?.() ?? surface;\n if (el === null) return NONE;\n const { name, validate, serverMessages, serverShown, formPending, form } = latest.current;\n\n const owner = el.form;\n const formData = owner === null ? new FormData() : new FormData(owner);\n const entry = name === undefined ? null : formData.get(name);\n const value = typeof entry === \"string\" ? entry : \"\";\n const custom = validate === undefined ? NONE : normaliseErrorValue(validate(value, formData));\n\n // The slot (design 2.1): the server message while shown, else `validate`'s.\n const showServer = serverShown && options.dismiss !== true;\n if (slotElement.current !== null && slotElement.current !== el) {\n slotElement.current.setCustomValidity(\"\");\n }\n slotElement.current = el;\n el.setCustomValidity(showServer ? serverMessages.join(\"\\n\") : custom.join(\"\\n\"));\n // Mirror onto the surface so its `:user-invalid` read below sees the new state (the control\n // writes the same derived value after each of its own writes).\n if (\n surface !== null &&\n surface !== el &&\n surface.validationMessage !== el.validationMessage\n ) {\n surface.setCustomValidity(el.validationMessage);\n }\n\n if (options.reset === true) attempted.current = false;\n const userInvalid = supportsUserInvalid()\n ? (surface ?? el).matches(\":user-invalid\")\n : attempted.current && !el.validity.valid;\n const validity = snapshotValidity(el.validity);\n const messages = validity.valid\n ? NONE\n : validity.customError && !showServer && custom.length > 0\n ? custom\n : el.validationMessage === \"\"\n ? NONE\n : [el.validationMessage];\n const next: Mirror = { userInvalid, validity, messages };\n // Only a change schedules a render (a `focusout` with nothing new causes none).\n if (!mirrorEquals(mirrorRef.current, next)) {\n mirrorRef.current = next;\n setMirror(next);\n }\n\n // Stale-value suppression (design 3.2 item 2): while the Form's own submission is in\n // flight, an error is about the value it sent; compare with what the field holds now.\n const submitted = formPending && name !== undefined ? (form?.submittedData() ?? null) : null;\n if (submitted !== null && name !== undefined) {\n setSuppressNext(\n !arraysEqual(entryStrings(formData.getAll(name)), entryStrings(submitted.getAll(name))),\n );\n }\n return showServer ? serverMessages : messages;\n },\n [latest, setSuppressNext],\n );\n\n // The slot follows the server error and `validate` (and is written once the control is known).\n // Keyed on `validate`'s identity (design 2.1): a rule reading outside state updates in the\n // commit that changed it. An inline function re-runs on every render (documented: `useCallback`\n // avoids it); the form's own values are covered by the listeners below.\n useLayoutEffect(() => {\n refresh();\n }, [refresh, control, serverShown, serverKey, validate]);\n\n // Clear the slot when the control goes away (it may be reused outside the Field).\n useLayoutEffect(\n () => () => {\n slotElement.current?.setCustomValidity(\"\");\n slotElement.current = null;\n },\n [],\n );\n\n // The control's own events (capture, so a group's members are seen on its fieldset).\n const element = control?.element ?? null;\n useLayoutEffect(() => {\n if (element === null) return;\n const onEdit = () => {\n dismiss();\n refresh({ dismiss: true });\n };\n const onBlur = () => refresh();\n const onInvalid = (event: Event) => {\n const target = event.target as ValidatableElement;\n // A submission attempt sets user validity before validating; `checkValidity()` and\n // `reportValidity()` do not (design 2.5). The fallback cannot tell them apart.\n const attempt = supportsUserInvalid() ? target.matches(\":user-invalid\") : true;\n if (!supportsUserInvalid()) attempted.current = true;\n if (attempt && errorCount.current > 0) {\n event.preventDefault();\n const messages = refresh();\n collectInvalid(focusTargetOf(element), messages.join(\" \"), target);\n return;\n }\n refresh();\n };\n element.addEventListener(\"input\", onEdit, true);\n element.addEventListener(\"change\", onEdit, true);\n element.addEventListener(\"focusout\", onBlur, true);\n element.addEventListener(\"invalid\", onInvalid, true);\n // A control that cannot validate itself and keeps its validity on an element outside it\n // (MultiSelect's Trigger and its hidden validity `<select>`, multi-select.md B.10): the\n // `invalid` fires there. NumberField's surface validates itself (its hidden input's `invalid`\n // is cancelled and the visible input reports), so it is not listened to twice.\n const outside =\n validityElementOf(element) === null ? (control?.validityElement?.() ?? null) : null;\n const listenOutside = outside !== null && !element.contains(outside);\n if (listenOutside) outside.addEventListener(\"invalid\", onInvalid, true);\n return () => {\n element.removeEventListener(\"input\", onEdit, true);\n element.removeEventListener(\"change\", onEdit, true);\n element.removeEventListener(\"focusout\", onBlur, true);\n element.removeEventListener(\"invalid\", onInvalid, true);\n if (listenOutside) outside.removeEventListener(\"invalid\", onInvalid, true);\n };\n }, [element, control, refresh, dismiss]);\n\n // The form owner's events: another field's edit re-runs `validate` (cross-field rules); a reset\n // clears the user-validity flag, re-read when the controls hold their reset values.\n const ownerRef = useMemo<RefObject<Element | null>>(\n () => ({\n get current() {\n return controlRef.current?.element ?? null;\n },\n set current(_ignored) {},\n }),\n [],\n );\n const onOwnerEdit = (event: Event) => {\n const target = event.target;\n if (target instanceof Node && controlRef.current?.element.contains(target) === true) return;\n refresh();\n };\n useFormOwnerEvent(ownerRef, \"input\", onOwnerEdit);\n useFormOwnerEvent(ownerRef, \"change\", onOwnerEdit);\n // A new submission sends the current values: nothing differs from it yet (a queued second\n // submit arrives while the status stays pending, so the pending edge alone would miss it).\n useFormOwnerEvent(ownerRef, \"submit\", () => {\n setSuppressNext(false);\n });\n useFormOwnerEvent(ownerRef, \"reset\", (event) => {\n queueMicrotask(() => {\n if (event.defaultPrevented) return;\n refresh({ reset: true });\n });\n });\n\n // Registration with the Form, for the first-error focus after a settle (design 3.5) and the\n // refresh of the other Fields on a change no DOM event carried.\n const registerField = form?.registerField;\n const formRegistration = useRef<FormFieldRegistration | null>(null);\n useLayoutEffect(() => {\n if (registerField === undefined) return;\n const registration: FormFieldRegistration = {\n getFocusTarget: () => focusTargetOf(controlRef.current?.element ?? null),\n showsServerError: () => latest.current.serverShown,\n serverMessages: () => latest.current.serverMessages,\n refresh: () => {\n refresh();\n },\n };\n formRegistration.current = registration;\n const unregister = registerField(registration);\n return () => {\n unregister();\n if (formRegistration.current === registration) formRegistration.current = null;\n };\n }, [registerField, latest, refresh]);\n\n const notifyChange = useCallback(\n (edit: boolean) => {\n if (edit) dismiss();\n refresh(edit ? { dismiss: true } : {});\n latest.current.form?.refreshFields(formRegistration.current);\n },\n [refresh, latest, dismiss],\n );\n\n // Development: a Field around something that is not a form control (Toggle, Menu, ...).\n useEffect(() => {\n if (!isDev || controlRef.current !== null) return;\n console.error(\n \"Field.Root: no form control registered. Render a Field.Control or a FUNSTACK form \" +\n \"control (Checkbox, Switch, RadioGroup, CheckboxGroup, Select, Combobox, MultiSelect, \" +\n \"Slider, NumberField) inside it.\",\n );\n }, []);\n\n const invalid = mirror.userInvalid || serverShown;\n const messages = serverShown ? serverMessages : mirror.userInvalid ? mirror.messages : NONE;\n const validity = mirror.validity;\n const stateDisabled = disabled || (control?.disabled ?? false);\n const stateRequired = required || (control?.required ?? false);\n // Memoised: the context value (and so every part) changes only with the state.\n const memoState = useMemo<FieldState>(\n () => ({\n invalid,\n messages,\n validity,\n disabled: stateDisabled,\n required: stateRequired,\n pending: formPending,\n }),\n [invalid, messages, validity, stateDisabled, stateRequired, formPending],\n );\n\n const labelable = control?.labelable ?? true;\n const controlElement = useCallback(() => controlRef.current?.element ?? null, []);\n const context = useMemo<FieldContextValue>(\n () => ({\n ids,\n name,\n disabled,\n required,\n state: memoState,\n labelable,\n controlElement,\n registerControl,\n registerError,\n notifyChange,\n }),\n [\n ids,\n name,\n disabled,\n required,\n memoState,\n labelable,\n controlElement,\n registerControl,\n registerError,\n notifyChange,\n ],\n );\n\n const element$ = useRender<ComponentPropsWithRef<\"div\">, FieldState>({\n defaultElement: \"div\",\n render,\n state: memoState,\n className,\n style,\n children,\n props: rest,\n libraryProps: fieldDataAttributes(memoState),\n });\n\n return <FieldContext value={context}>{element$}</FieldContext>;\n}\n\nFieldRoot.displayName = \"FieldRoot\";\n"],"mappings":";;;;;;;;;;;;;;AA8CA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AA+DvC,MAAM,OAA0B,OAAO,OAAO,CAAC,CAAC;AAChD,MAAM,iBAAyB;CAAE,aAAa;CAAO,UA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EACA,UAAU;EACV,UAAU;EACV,SAAS;CACX,IACA;EAAC;EAAS;EAAU;EAAU;EAAe;EAAe;CAAW,CACzE;CAEA,MAAM,YAAY,SAAS,aAAa;CACxC,MAAM,iBAAiB,kBAAkB,WAAW,SAAS,WAAW,MAAM,CAAC,CAAC;CAChF,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,WAAW,UAAoD;EACnE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP,cAAc,oBAAoB,SAAS;CAC7C,CAAC;CAED,OAAO,oBAAC,cAAD;EAAc,OAAO;EAAU,UAAA;CAAuB,CAAA;AAC/D;AAEA,UAAU,cAAc"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, use } from "react";
|
|
3
|
+
//#region src/hover-card/hover-card-context.ts
|
|
4
|
+
const HoverCardContext = createContext(null);
|
|
5
|
+
function useHoverCardContext(part) {
|
|
6
|
+
const context = use(HoverCardContext);
|
|
7
|
+
if (context === null) throw new Error(`${part} must be rendered inside a HoverCard.Root.`);
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { HoverCardContext, useHoverCardContext };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=hover-card-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-card-context.mjs","names":[],"sources":["../../src/hover-card/hover-card-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\n\n/** What `HoverCard.Root` gives its Trigger and Popup (design/components/hover-card.md 12). */\nexport interface HoverCardContextValue extends PopoverRootValue {\n readonly disabled: boolean;\n /** Written onto the Trigger as `interest-delay-start` / `-end` with `experimental_interestFor`. */\n readonly delay: number;\n readonly closeDelay: number;\n /**\n * \"No open until fresh interest\" (design 2.4): set by Escape, a press on the Trigger and the\n * library's focus return; cleared when the pointer enters or leaves the Trigger and when it\n * loses focus. Read by the JS path's `focus` listener and by the Popup's `beforetoggle`\n * interception of an interest open (the flagged path). A ref, never React state.\n */\n readonly suppressed: RefObject<boolean>;\n /**\n * Trigger and Popup register their elements here too (besides `triggerRef` / `popupRef`), so\n * the Root's interest effect re-runs when either changes.\n */\n readonly setTriggerElement: (element: HTMLElement | null) => void;\n readonly setPopupElement: (element: HTMLElement | null) => void;\n /**\n * The Trigger reports whether it writes `interestfor` (the flag is on and the Root is not\n * disabled), so the Root's effect re-detects the flagged path.\n */\n readonly setInterestForRequested: (requested: boolean) => void;\n /** The Root's document listeners attach now (an open routed at the Popup's `beforetoggle`). */\n readonly listenDocumentNow: () => void;\n}\n\nexport const HoverCardContext = createContext<HoverCardContextValue | null>(null);\n\nexport function useHoverCardContext(part: string): HoverCardContextValue {\n const context = use(HoverCardContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a HoverCard.Root.`);\n }\n return context;\n}\n"],"mappings":";;;AAiCA,MAAa,mBAAmB,cAA4C,IAAI;AAEhF,SAAgB,oBAAoB,MAAqC;CACvE,MAAM,UAAU,IAAI,gBAAgB;CACpC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,2CAA2C;CAErE,OAAO;AACT"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { AnchorAlign, AnchorSide } from "../internal/overlay/anchor-position.mjs";
|
|
3
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode, ViewTransitionClass } from "react";
|
|
4
|
+
//#region src/hover-card/hover-card-popup.d.ts
|
|
5
|
+
/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */
|
|
6
|
+
export type HoverCardSide = AnchorSide;
|
|
7
|
+
/**
|
|
8
|
+
* Alignment of the Popup along its side: inline-relative on a top / bottom side, the top / bottom
|
|
9
|
+
* edges on the others.
|
|
10
|
+
*/
|
|
11
|
+
export type HoverCardAlign = AnchorAlign;
|
|
12
|
+
/**
|
|
13
|
+
* State of `HoverCard.Popup`, passed to the function forms of `className`, `style`, `children`
|
|
14
|
+
* and `render`.
|
|
15
|
+
*/
|
|
16
|
+
export interface HoverCardPopupState {
|
|
17
|
+
/** Committed open state. Read `:popover-open` for the DOM truth. */
|
|
18
|
+
readonly open: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* While shown: the physical side the browser placed the card on (after any fallback flip;
|
|
21
|
+
* conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`.
|
|
22
|
+
*/
|
|
23
|
+
readonly side: HoverCardSide | null;
|
|
24
|
+
/** While shown: the resolved alignment; otherwise the `align` prop. */
|
|
25
|
+
readonly align: HoverCardAlign;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Props of `HoverCard.Popup`.
|
|
29
|
+
*
|
|
30
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
31
|
+
*/
|
|
32
|
+
export interface HoverCardPopupProps extends Omit<ComponentPropsWithRef<"div">, "id" | "popover" | "onToggle" | "onBeforeToggle" | "className" | "style" | "children"> {
|
|
33
|
+
/**
|
|
34
|
+
* Placement relative to the Trigger through inline `position-area`, with
|
|
35
|
+
* `position-try-fallbacks` flipping it when it does not fit. `null` emits no inline positioning
|
|
36
|
+
* (and no `data-side` / `data-align`), so a stylesheet owns placement.
|
|
37
|
+
*
|
|
38
|
+
* @defaultValue `"bottom"`
|
|
39
|
+
*/
|
|
40
|
+
side?: HoverCardSide | null;
|
|
41
|
+
/**
|
|
42
|
+
* Alignment along the side. Ignored when `side` is `null`.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue `"center"`
|
|
45
|
+
*/
|
|
46
|
+
align?: HoverCardAlign;
|
|
47
|
+
/**
|
|
48
|
+
* What happens to the children while the card is closed.
|
|
49
|
+
* - `false` (default): not rendered. Mounting them is part of the opening transition, so
|
|
50
|
+
* content that suspends holds the open (the Trigger is `data-pending`) until it is ready.
|
|
51
|
+
* - `true`: rendered inside `<Activity mode="hidden">`: pre-rendered at low priority, state
|
|
52
|
+
* kept. Suits a single prominent card, not a list of them.
|
|
53
|
+
*
|
|
54
|
+
* @defaultValue `false`
|
|
55
|
+
*/
|
|
56
|
+
keepMounted?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Experimental (Chrome 151+, Firefox 153+; Safari 27.2 treats it as `"manual"`). Renders
|
|
59
|
+
* `popover="hint"` instead of `"manual"`: opening the card closes an open Tooltip or other
|
|
60
|
+
* hint, and the browser's light dismiss applies next to the library's.
|
|
61
|
+
*
|
|
62
|
+
* @defaultValue `false`
|
|
63
|
+
*/
|
|
64
|
+
experimental_hint?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Forwarded to the `<ViewTransition default>` around the popover element. Animates the opening
|
|
67
|
+
* commit, content changes while open (a skeleton swapped for the content) and a controlled
|
|
68
|
+
* close. Every close the user causes is a fact and animates with CSS only.
|
|
69
|
+
*/
|
|
70
|
+
transition?: ViewTransitionClass;
|
|
71
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
72
|
+
className?: StateValue<string | undefined, HoverCardPopupState>;
|
|
73
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
74
|
+
style?: StateValue<CSSProperties | undefined, HoverCardPopupState>;
|
|
75
|
+
/** Content, or a function of the part's state. Rendered from committed state; may suspend. */
|
|
76
|
+
children?: StateValue<ReactNode, HoverCardPopupState>;
|
|
77
|
+
/** A `<div>` (default) or a `<span>` for a card inside running text (phrasing content only). */
|
|
78
|
+
render?: RenderProp<ComponentPropsWithRef<"div">, HoverCardPopupState>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The card: a `<div popover="manual" role="group">` placed against the Trigger with CSS Anchor
|
|
82
|
+
* Positioning. Its children render from committed state, so they mount in the opening transition
|
|
83
|
+
* and content that suspends holds the open; `showPopover({ source: trigger })` runs in the layout
|
|
84
|
+
* effect of the commit that mounted them, always as a no-focus show (the card is `inert` for the
|
|
85
|
+
* call). Every close the user causes (lost interest, Escape, a press outside) is a fact: the
|
|
86
|
+
* native `toggle` makes committed state `false` urgently and calls `onOpenChange(false, { reason:
|
|
87
|
+
* "dismiss" })`.
|
|
88
|
+
*
|
|
89
|
+
* Style it with `:popover-open`; it emits `data-side` / `data-align` (the resolved placement
|
|
90
|
+
* while shown) but no `data-open`.
|
|
91
|
+
*
|
|
92
|
+
* Owned keys (conventions 1.2): `id`, `popover`, and `data-side` / `data-align` unless `side` is
|
|
93
|
+
* `null`. `role` is a default (`"group"`) the consumer may override.
|
|
94
|
+
*
|
|
95
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
96
|
+
*/
|
|
97
|
+
export declare function HoverCardPopup({ side: sideProp, align: alignProp, keepMounted, experimental_hint, transition, className, style, children, render, ...rest }: HoverCardPopupProps): ReactNode;
|
|
98
|
+
export declare namespace HoverCardPopup {
|
|
99
|
+
var displayName: string;
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//# sourceMappingURL=hover-card-popup.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-card-popup.d.mts","names":[],"sources":["../../src/hover-card/hover-card-popup.tsx"],"mappings":";;;;;YAgBY,gBAAgB;;;;;YAKhB,iBAAiB;;;;;iBAMZ;;WAEN;;;;;WAKA,MAAM;;WAEN,OAAO;;;;;;;iBAQD,4BAA4B,KAC3C;;;;;;;;EAUA,OAAO;;;;;;EAMP,QAAQ;;;;;;;;;;EAUR;;;;;;;;EAQA;;;;;;EAMA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;wBAuBpC,iBACd,MAAM,UACN,OAAO,WACP,aACA,mBACA,YACA,WACA,OACA,UACA,WACG,QACF,sBAAmB;yBAXN"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
3
|
+
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
4
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
5
|
+
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
6
|
+
import { useAnchoredPlacement } from "../internal/overlay/use-resolved-placement.mjs";
|
|
7
|
+
import { eventSource } from "../internal/overlay/invokers.mjs";
|
|
8
|
+
import { usePopoverPopup } from "../internal/overlay/use-popover-popup.mjs";
|
|
9
|
+
import { useHoverCardContext } from "./hover-card-context.mjs";
|
|
10
|
+
import { blurFocusInside } from "./use-hover-card-interest.mjs";
|
|
11
|
+
//#region src/hover-card/hover-card-popup.tsx
|
|
12
|
+
/** The card may be a `<span>` inside running text (design 1.1). */
|
|
13
|
+
const POPUP_ELEMENTS = ["DIV", "SPAN"];
|
|
14
|
+
/**
|
|
15
|
+
* The card: a `<div popover="manual" role="group">` placed against the Trigger with CSS Anchor
|
|
16
|
+
* Positioning. Its children render from committed state, so they mount in the opening transition
|
|
17
|
+
* and content that suspends holds the open; `showPopover({ source: trigger })` runs in the layout
|
|
18
|
+
* effect of the commit that mounted them, always as a no-focus show (the card is `inert` for the
|
|
19
|
+
* call). Every close the user causes (lost interest, Escape, a press outside) is a fact: the
|
|
20
|
+
* native `toggle` makes committed state `false` urgently and calls `onOpenChange(false, { reason:
|
|
21
|
+
* "dismiss" })`.
|
|
22
|
+
*
|
|
23
|
+
* Style it with `:popover-open`; it emits `data-side` / `data-align` (the resolved placement
|
|
24
|
+
* while shown) but no `data-open`.
|
|
25
|
+
*
|
|
26
|
+
* Owned keys (conventions 1.2): `id`, `popover`, and `data-side` / `data-align` unless `side` is
|
|
27
|
+
* `null`. `role` is a default (`"group"`) the consumer may override.
|
|
28
|
+
*
|
|
29
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
30
|
+
*/
|
|
31
|
+
function HoverCardPopup({ side: sideProp = "bottom", align: alignProp = "center", keepMounted, experimental_hint = false, transition, className, style, children, render, ...rest }) {
|
|
32
|
+
const ctx = useHoverCardContext("HoverCard.Popup");
|
|
33
|
+
const { ids, suppressed, triggerRef } = ctx;
|
|
34
|
+
const { setElement, renderContent } = usePopoverPopup(ctx, {
|
|
35
|
+
part: "HoverCard.Popup",
|
|
36
|
+
keepMounted,
|
|
37
|
+
transition,
|
|
38
|
+
quietShow: true,
|
|
39
|
+
allowOpen: (event) => !(suppressed.current && eventSource(event) === triggerRef.current),
|
|
40
|
+
elements: POPUP_ELEMENTS,
|
|
41
|
+
beforeInterestHide: blurFocusInside,
|
|
42
|
+
onRoutedOpen: () => ctx.listenDocumentNow()
|
|
43
|
+
});
|
|
44
|
+
const placement = useAnchoredPlacement({
|
|
45
|
+
side: sideProp,
|
|
46
|
+
align: alignProp
|
|
47
|
+
});
|
|
48
|
+
const { side, align } = placement;
|
|
49
|
+
const ref = useMergedRefs(setElement, placement.ref, ctx.setPopupElement);
|
|
50
|
+
const state = {
|
|
51
|
+
open: ctx.committed,
|
|
52
|
+
side,
|
|
53
|
+
align
|
|
54
|
+
};
|
|
55
|
+
const libraryProps = {
|
|
56
|
+
id: ids.popup,
|
|
57
|
+
popover: experimental_hint ? "hint" : "manual",
|
|
58
|
+
...placement.dataAttributes
|
|
59
|
+
};
|
|
60
|
+
const element = useRender({
|
|
61
|
+
defaultElement: "div",
|
|
62
|
+
render,
|
|
63
|
+
state,
|
|
64
|
+
className,
|
|
65
|
+
style: placement.style(style),
|
|
66
|
+
children: (s) => renderContent(() => resolveStateValue(children, s)),
|
|
67
|
+
props: {
|
|
68
|
+
role: "group",
|
|
69
|
+
...rest
|
|
70
|
+
},
|
|
71
|
+
libraryProps,
|
|
72
|
+
ref
|
|
73
|
+
});
|
|
74
|
+
return useTransitionBoundary("HoverCard.Popup", transition, element);
|
|
75
|
+
}
|
|
76
|
+
HoverCardPopup.displayName = "HoverCardPopup";
|
|
77
|
+
//#endregion
|
|
78
|
+
export { HoverCardPopup };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=hover-card-popup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-card-popup.mjs","names":[],"sources":["../../src/hover-card/hover-card-popup.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode, ViewTransitionClass } from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/overlay/anchor-position.js\";\nimport { eventSource } from \"../internal/overlay/invokers.js\";\nimport { usePopoverPopup } from \"../internal/overlay/use-popover-popup.js\";\nimport { useAnchoredPlacement } from \"../internal/overlay/use-resolved-placement.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { useHoverCardContext } from \"./hover-card-context.js\";\nimport { blurFocusInside } from \"./use-hover-card-interest.js\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */\nexport type HoverCardSide = AnchorSide;\n/**\n * Alignment of the Popup along its side: inline-relative on a top / bottom side, the top / bottom\n * edges on the others.\n */\nexport type HoverCardAlign = AnchorAlign;\n\n/**\n * State of `HoverCard.Popup`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface HoverCardPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the card on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`.\n */\n readonly side: HoverCardSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: HoverCardAlign;\n}\n\n/**\n * Props of `HoverCard.Popup`.\n *\n * @see https://ui.funstack.work/components/hover-card\n */\nexport interface HoverCardPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"popover\" | \"onToggle\" | \"onBeforeToggle\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Placement relative to the Trigger through inline `position-area`, with\n * `position-try-fallbacks` flipping it when it does not fit. `null` emits no inline positioning\n * (and no `data-side` / `data-align`), so a stylesheet owns placement.\n *\n * @defaultValue `\"bottom\"`\n */\n side?: HoverCardSide | null;\n /**\n * Alignment along the side. Ignored when `side` is `null`.\n *\n * @defaultValue `\"center\"`\n */\n align?: HoverCardAlign;\n /**\n * What happens to the children while the card is closed.\n * - `false` (default): not rendered. Mounting them is part of the opening transition, so\n * content that suspends holds the open (the Trigger is `data-pending`) until it is ready.\n * - `true`: rendered inside `<Activity mode=\"hidden\">`: pre-rendered at low priority, state\n * kept. Suits a single prominent card, not a list of them.\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chrome 151+, Firefox 153+; Safari 27.2 treats it as `\"manual\"`). Renders\n * `popover=\"hint\"` instead of `\"manual\"`: opening the card closes an open Tooltip or other\n * hint, and the browser's light dismiss applies next to the library's.\n *\n * @defaultValue `false`\n */\n experimental_hint?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popover element. Animates the opening\n * commit, content changes while open (a skeleton swapped for the content) and a controlled\n * close. Every close the user causes is a fact and animates with CSS only.\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, HoverCardPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, HoverCardPopupState>;\n /** Content, or a function of the part's state. Rendered from committed state; may suspend. */\n children?: StateValue<ReactNode, HoverCardPopupState>;\n /** A `<div>` (default) or a `<span>` for a card inside running text (phrasing content only). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, HoverCardPopupState>;\n}\n\n/** The card may be a `<span>` inside running text (design 1.1). */\nconst POPUP_ELEMENTS: readonly string[] = [\"DIV\", \"SPAN\"];\n\n/**\n * The card: a `<div popover=\"manual\" role=\"group\">` placed against the Trigger with CSS Anchor\n * Positioning. Its children render from committed state, so they mount in the opening transition\n * and content that suspends holds the open; `showPopover({ source: trigger })` runs in the layout\n * effect of the commit that mounted them, always as a no-focus show (the card is `inert` for the\n * call). Every close the user causes (lost interest, Escape, a press outside) is a fact: the\n * native `toggle` makes committed state `false` urgently and calls `onOpenChange(false, { reason:\n * \"dismiss\" })`.\n *\n * Style it with `:popover-open`; it emits `data-side` / `data-align` (the resolved placement\n * while shown) but no `data-open`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, and `data-side` / `data-align` unless `side` is\n * `null`. `role` is a default (`\"group\"`) the consumer may override.\n *\n * @see https://ui.funstack.work/components/hover-card\n */\nexport function HoverCardPopup({\n side: sideProp = \"bottom\",\n align: alignProp = \"center\",\n keepMounted,\n experimental_hint = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: HoverCardPopupProps) {\n const ctx = useHoverCardContext(\"HoverCard.Popup\");\n const { ids, suppressed, triggerRef } = ctx;\n\n const { setElement, renderContent } = usePopoverPopup(ctx, {\n part: \"HoverCard.Popup\",\n keepMounted,\n transition,\n // Opening never moves focus (design 6.2).\n quietShow: true,\n // No open until fresh interest (design 2.4): the flagged path's interest show after Escape,\n // a press on the Trigger or the library's focus return is cancelled and dispatches nothing.\n allowOpen: (event) => !(suppressed.current && eventSource(event) === triggerRef.current),\n elements: POPUP_ELEMENTS,\n // The flagged path's lost-interest hide returns no focus to the Trigger (design 6.2): with\n // `hint` the platform would restore it there, and that focus is interest again.\n beforeInterestHide: blurFocusInside,\n // Escape and a press outside work from the dispatch of a routed open (design 2.2).\n onRoutedOpen: () => ctx.listenDocumentNow(),\n });\n\n const placement = useAnchoredPlacement({ side: sideProp, align: alignProp });\n const { side, align } = placement;\n const ref = useMergedRefs(setElement, placement.ref, ctx.setPopupElement);\n\n const state: HoverCardPopupState = { open: ctx.committed, side, align };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: ids.popup,\n popover: experimental_hint ? \"hint\" : \"manual\",\n ...placement.dataAttributes,\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, HoverCardPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The consumer's style wins over the inline placement.\n style: placement.style(style),\n children: (s: HoverCardPopupState) => renderContent(() => resolveStateValue(children, s)),\n // `role` is a default the consumer's `rest` overrides (design 7): HTML-AAM's minimum role for\n // a popover, which WebKit does not apply by itself.\n props: { role: \"group\", ...rest },\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"HoverCard.Popup\", transition, element);\n}\n\nHoverCardPopup.displayName = \"HoverCardPopup\";\n"],"mappings":";;;;;;;;;;;;AAiGA,MAAM,iBAAoC,CAAC,OAAO,MAAM;;;;;;;;;;;;;;;;;;AAmBxD,SAAgB,eAAe,EAC7B,MAAM,WAAW,UACjB,OAAO,YAAY,UACnB,aACA,oBAAoB,OACpB,YACA,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,MAAM,oBAAoB,iBAAiB;CACjD,MAAM,EAAE,KAAK,YAAY,eAAe;CAExC,MAAM,EAAE,YAAY,kBAAkB,gBAAgB,KAAK;EACzD,MAAM;EACN;EACA;EAEA,WAAW;EAGX,YAAY,UAAU,EAAE,WAAW,WAAW,YAAY,KAAK,MAAM,WAAW;EAChF,UAAU;EAGV,oBAAoB;EAEpB,oBAAoB,IAAI,kBAAkB;CAC5C,CAAC;CAED,MAAM,YAAY,qBAAqB;EAAE,MAAM;EAAU,OAAO;CAAU,CAAC;CAC3E,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,MAAM,cAAc,YAAY,UAAU,KAAK,IAAI,eAAe;CAExE,MAAM,QAA6B;EAAE,MAAM,IAAI;EAAW;EAAM;CAAM;CAEtE,MAAM,eAA8D;EAClE,IAAI,IAAI;EACR,SAAS,oBAAoB,SAAS;EACtC,GAAG,UAAU;CACf;CAEA,MAAM,UAAU,UAA6D;EAC3E,gBAAgB;EAChB;EACA;EACA;EAEA,OAAO,UAAU,MAAM,KAAK;EAC5B,WAAW,MAA2B,oBAAoB,kBAAkB,UAAU,CAAC,CAAC;EAGxF,OAAO;GAAE,MAAM;GAAS,GAAG;EAAK;EAChC;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,mBAAmB,YAAY,OAAO;AACrE;AAEA,eAAe,cAAc"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ActionDetails, ChangeAction, ChangeReason, StateValue, UrgentChangeHandler } from "../internal/types.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/hover-card/hover-card-root.d.ts
|
|
4
|
+
/** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */
|
|
5
|
+
export interface HoverCardOpenChangeDetails extends ActionDetails {
|
|
6
|
+
/**
|
|
7
|
+
* `"activate"`: the user showed interest in the Trigger (hover or keyboard focus held for
|
|
8
|
+
* `delay`), or something else opened the card (`details.event` is a `ToggleEvent` then).
|
|
9
|
+
* `"dismiss"`: every close: lost interest, Escape, a press outside the card (the Trigger
|
|
10
|
+
* included).
|
|
11
|
+
* `"platform"`: the card was found open on mount; `event` is `undefined`.
|
|
12
|
+
*/
|
|
13
|
+
readonly reason: ChangeReason;
|
|
14
|
+
}
|
|
15
|
+
/** State of `HoverCard.Root`, passed to the function forms of `children`. */
|
|
16
|
+
export interface HoverCardRootState {
|
|
17
|
+
/** Optimistic open state. Content rendered from it must not suspend. */
|
|
18
|
+
readonly open: boolean;
|
|
19
|
+
/** A request (`openChangeAction`) dispatched through this HoverCard is in flight. */
|
|
20
|
+
readonly pending: boolean;
|
|
21
|
+
/** The `disabled` prop. */
|
|
22
|
+
readonly disabled: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Props of `HoverCard.Root`.
|
|
26
|
+
*
|
|
27
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
28
|
+
*/
|
|
29
|
+
export interface HoverCardRootProps {
|
|
30
|
+
/**
|
|
31
|
+
* Controlled open state. A controlled Root needs `onOpenChange` too: every close the user
|
|
32
|
+
* causes is a fact (development warns without it).
|
|
33
|
+
*/
|
|
34
|
+
open?: boolean;
|
|
35
|
+
/** Initial open state when uncontrolled. Shown after hydration, never in the server HTML. */
|
|
36
|
+
defaultOpen?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Requests only. Awaited for `true` when the user shows interest: the card appears when it
|
|
39
|
+
* resolves and the content has rendered. Called with `false` only to cancel an open that has
|
|
40
|
+
* not appeared yet (the user moved on). Never called for the close of a shown card: that goes
|
|
41
|
+
* to `onOpenChange`. May be a Server Function. Rejections reach the nearest Error Boundary
|
|
42
|
+
* above Root, which takes the Trigger with it: catch inside the action, or load in the content
|
|
43
|
+
* with an Error Boundary inside the Popup.
|
|
44
|
+
*
|
|
45
|
+
* A `setState` placed after your own `await` is not a Transition update; wrap it in
|
|
46
|
+
* `startTransition` (React limitation).
|
|
47
|
+
*/
|
|
48
|
+
openChangeAction?: ChangeAction<boolean, HoverCardOpenChangeDetails>;
|
|
49
|
+
/**
|
|
50
|
+
* Facts only: the card was closed (lost interest, Escape, a press outside). Always `false`.
|
|
51
|
+
* Called synchronously, outside any Transition, not awaited. A controlled Root adopts it
|
|
52
|
+
* directly (`onOpenChange={setOpen}`); a parent that keeps `open={true}` gets the card
|
|
53
|
+
* re-shown. May return a promise; a rejection or a throw goes to `reportError`.
|
|
54
|
+
*/
|
|
55
|
+
onOpenChange?: UrgentChangeHandler<boolean, HoverCardOpenChangeDetails>;
|
|
56
|
+
/**
|
|
57
|
+
* Milliseconds of interest (hover or keyboard focus) before the open is requested.
|
|
58
|
+
*
|
|
59
|
+
* @defaultValue `600`
|
|
60
|
+
*/
|
|
61
|
+
delay?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Milliseconds from losing interest to the close.
|
|
64
|
+
*
|
|
65
|
+
* @defaultValue `300`
|
|
66
|
+
*/
|
|
67
|
+
closeDelay?: number;
|
|
68
|
+
/**
|
|
69
|
+
* When true, interest never opens the card, and a shown card is closed (a dismissal). Does not
|
|
70
|
+
* disable the Trigger: a link still navigates. A controlled `open={true}` still shows the card.
|
|
71
|
+
*
|
|
72
|
+
* @defaultValue `false`
|
|
73
|
+
*/
|
|
74
|
+
disabled?: boolean;
|
|
75
|
+
/** The parts. The function form receives the optimistic state and must not suspend. */
|
|
76
|
+
children?: StateValue<ReactNode, HoverCardRootState>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Owns the ids, the open state (Popover's library mode: opening is a request, every close the
|
|
80
|
+
* user causes is a fact), `delay` / `closeDelay` / `disabled`, and the interest effect. Renders
|
|
81
|
+
* no DOM, so it has no `ref`, `className` or `style`; `pending` is exposed through
|
|
82
|
+
* `children(state)` and the Trigger.
|
|
83
|
+
*
|
|
84
|
+
* Render `HoverCard.Popup` immediately after `HoverCard.Trigger` in DOM order: Tab from the
|
|
85
|
+
* Trigger then enters the open card in every engine.
|
|
86
|
+
*
|
|
87
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
88
|
+
*/
|
|
89
|
+
export declare function HoverCardRoot({ open, defaultOpen, openChangeAction, onOpenChange, delay, closeDelay, disabled, children }: HoverCardRootProps): import("react").JSX.Element;
|
|
90
|
+
export declare namespace HoverCardRoot {
|
|
91
|
+
var displayName: string;
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//# sourceMappingURL=hover-card-root.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-card-root.d.mts","names":[],"sources":["../../src/hover-card/hover-card-root.tsx"],"mappings":";;;;iBAiBiB,mCAAmC;;;;;;;;WAQzC,QAAQ;;;iBAIF;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM;;;;;EAKf;;EAEA;;;;;;;;;;;;EAYA,mBAAmB,sBAAsB;;;;;;;EAOzC,eAAe,6BAA6B;;;;;;EAM5C;;;;;;EAMA;;;;;;;EAOA;;EAEA,WAAW,WAAW,WAAW;;;;;;;;;;;;;wBAcnB,gBACd,MACA,aACA,kBACA,cACA,OACA,YACA,UACA,YACC,qCAAkB,IAAA;yBATL"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
3
|
+
import { HoverCardContext } from "./hover-card-context.mjs";
|
|
4
|
+
import { useHoverCardInterest } from "./use-hover-card-interest.mjs";
|
|
5
|
+
import { popoverDetails, usePopoverRoot } from "../internal/overlay/use-overlay-root.mjs";
|
|
6
|
+
import { useMemo, useRef, useState } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
//#region src/hover-card/hover-card-root.tsx
|
|
9
|
+
/**
|
|
10
|
+
* Owns the ids, the open state (Popover's library mode: opening is a request, every close the
|
|
11
|
+
* user causes is a fact), `delay` / `closeDelay` / `disabled`, and the interest effect. Renders
|
|
12
|
+
* no DOM, so it has no `ref`, `className` or `style`; `pending` is exposed through
|
|
13
|
+
* `children(state)` and the Trigger.
|
|
14
|
+
*
|
|
15
|
+
* Render `HoverCard.Popup` immediately after `HoverCard.Trigger` in DOM order: Tab from the
|
|
16
|
+
* Trigger then enters the open card in every engine.
|
|
17
|
+
*
|
|
18
|
+
* @see https://ui.funstack.work/components/hover-card
|
|
19
|
+
*/
|
|
20
|
+
function HoverCardRoot({ open, defaultOpen, openChangeAction, onOpenChange, delay = 600, closeDelay = 300, disabled = false, children }) {
|
|
21
|
+
const popover = usePopoverRoot({
|
|
22
|
+
component: "hover-card",
|
|
23
|
+
part: "HoverCard.Root",
|
|
24
|
+
mode: "library",
|
|
25
|
+
open,
|
|
26
|
+
defaultOpen,
|
|
27
|
+
openChangeAction,
|
|
28
|
+
onOpenChange,
|
|
29
|
+
details: popoverDetails
|
|
30
|
+
});
|
|
31
|
+
const [trigger, setTriggerElement] = useState(null);
|
|
32
|
+
const [popup, setPopupElement] = useState(null);
|
|
33
|
+
const [interestForRequested, setInterestForRequested] = useState(false);
|
|
34
|
+
const suppressed = useRef(false);
|
|
35
|
+
const { listenDocumentNow } = useHoverCardInterest(popover, trigger, popup, {
|
|
36
|
+
delay,
|
|
37
|
+
closeDelay,
|
|
38
|
+
disabled,
|
|
39
|
+
interestForRequested,
|
|
40
|
+
suppressed,
|
|
41
|
+
active: popover.optimistic || popover.committed
|
|
42
|
+
});
|
|
43
|
+
const context = useMemo(() => ({
|
|
44
|
+
...popover,
|
|
45
|
+
disabled,
|
|
46
|
+
delay,
|
|
47
|
+
closeDelay,
|
|
48
|
+
suppressed,
|
|
49
|
+
setTriggerElement,
|
|
50
|
+
setPopupElement,
|
|
51
|
+
setInterestForRequested,
|
|
52
|
+
listenDocumentNow
|
|
53
|
+
}), [
|
|
54
|
+
popover,
|
|
55
|
+
disabled,
|
|
56
|
+
delay,
|
|
57
|
+
closeDelay,
|
|
58
|
+
listenDocumentNow
|
|
59
|
+
]);
|
|
60
|
+
const state = {
|
|
61
|
+
open: popover.optimistic,
|
|
62
|
+
pending: popover.pending,
|
|
63
|
+
disabled
|
|
64
|
+
};
|
|
65
|
+
return /* @__PURE__ */ jsx(HoverCardContext, {
|
|
66
|
+
value: context,
|
|
67
|
+
children: resolveStateValue(children, state)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
HoverCardRoot.displayName = "HoverCardRoot";
|
|
71
|
+
//#endregion
|
|
72
|
+
export { HoverCardRoot };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=hover-card-root.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-card-root.mjs","names":[],"sources":["../../src/hover-card/hover-card-root.tsx"],"sourcesContent":["\"use client\";\nimport { useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { popoverDetails, usePopoverRoot } from \"../internal/overlay/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { HoverCardContext } from \"./hover-card-context.js\";\nimport type { HoverCardContextValue } from \"./hover-card-context.js\";\nimport { useHoverCardInterest } from \"./use-hover-card-interest.js\";\n\n/** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */\nexport interface HoverCardOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user showed interest in the Trigger (hover or keyboard focus held for\n * `delay`), or something else opened the card (`details.event` is a `ToggleEvent` then).\n * `\"dismiss\"`: every close: lost interest, Escape, a press outside the card (the Trigger\n * included).\n * `\"platform\"`: the card was found open on mount; `event` is `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\n/** State of `HoverCard.Root`, passed to the function forms of `children`. */\nexport interface HoverCardRootState {\n /** Optimistic open state. Content rendered from it must not suspend. */\n readonly open: boolean;\n /** A request (`openChangeAction`) dispatched through this HoverCard is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `HoverCard.Root`.\n *\n * @see https://ui.funstack.work/components/hover-card\n */\nexport interface HoverCardRootProps {\n /**\n * Controlled open state. A controlled Root needs `onOpenChange` too: every close the user\n * causes is a fact (development warns without it).\n */\n open?: boolean;\n /** Initial open state when uncontrolled. Shown after hydration, never in the server HTML. */\n defaultOpen?: boolean;\n /**\n * Requests only. Awaited for `true` when the user shows interest: the card appears when it\n * resolves and the content has rendered. Called with `false` only to cancel an open that has\n * not appeared yet (the user moved on). Never called for the close of a shown card: that goes\n * to `onOpenChange`. May be a Server Function. Rejections reach the nearest Error Boundary\n * above Root, which takes the Trigger with it: catch inside the action, or load in the content\n * with an Error Boundary inside the Popup.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, HoverCardOpenChangeDetails>;\n /**\n * Facts only: the card was closed (lost interest, Escape, a press outside). Always `false`.\n * Called synchronously, outside any Transition, not awaited. A controlled Root adopts it\n * directly (`onOpenChange={setOpen}`); a parent that keeps `open={true}` gets the card\n * re-shown. May return a promise; a rejection or a throw goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, HoverCardOpenChangeDetails>;\n /**\n * Milliseconds of interest (hover or keyboard focus) before the open is requested.\n *\n * @defaultValue `600`\n */\n delay?: number;\n /**\n * Milliseconds from losing interest to the close.\n *\n * @defaultValue `300`\n */\n closeDelay?: number;\n /**\n * When true, interest never opens the card, and a shown card is closed (a dismissal). Does not\n * disable the Trigger: a link still navigates. A controlled `open={true}` still shows the card.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, HoverCardRootState>;\n}\n\n/**\n * Owns the ids, the open state (Popover's library mode: opening is a request, every close the\n * user causes is a fact), `delay` / `closeDelay` / `disabled`, and the interest effect. Renders\n * no DOM, so it has no `ref`, `className` or `style`; `pending` is exposed through\n * `children(state)` and the Trigger.\n *\n * Render `HoverCard.Popup` immediately after `HoverCard.Trigger` in DOM order: Tab from the\n * Trigger then enters the open card in every engine.\n *\n * @see https://ui.funstack.work/components/hover-card\n */\nexport function HoverCardRoot({\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n delay = 600,\n closeDelay = 300,\n disabled = false,\n children,\n}: HoverCardRootProps) {\n const popover = usePopoverRoot<HoverCardOpenChangeDetails>({\n component: \"hover-card\",\n part: \"HoverCard.Root\",\n // One mode: no JS-free mode (design 2.5, conventions 3.9.11).\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: popoverDetails,\n });\n\n const [trigger, setTriggerElement] = useState<HTMLElement | null>(null);\n const [popup, setPopupElement] = useState<HTMLElement | null>(null);\n const [interestForRequested, setInterestForRequested] = useState(false);\n const suppressed = useRef(false);\n\n const { listenDocumentNow } = useHoverCardInterest(popover, trigger, popup, {\n delay,\n closeDelay,\n disabled,\n interestForRequested,\n suppressed,\n active: popover.optimistic || popover.committed,\n });\n\n const context = useMemo<HoverCardContextValue>(\n () => ({\n ...popover,\n disabled,\n delay,\n closeDelay,\n suppressed,\n setTriggerElement,\n setPopupElement,\n setInterestForRequested,\n listenDocumentNow,\n }),\n [popover, disabled, delay, closeDelay, listenDocumentNow],\n );\n\n const state: HoverCardRootState = {\n open: popover.optimistic,\n pending: popover.pending,\n disabled,\n };\n\n return <HoverCardContext value={context}>{resolveStateValue(children, state)}</HoverCardContext>;\n}\n\nHoverCardRoot.displayName = \"HoverCardRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwGA,SAAgB,cAAc,EAC5B,MACA,aACA,kBACA,cACA,QAAQ,KACR,aAAa,KACb,WAAW,OACX,YACqB;CACrB,MAAM,UAAU,eAA2C;EACzD,WAAW;EACX,MAAM;EAEN,MAAM;EACN;EACA;EACA;EACA;EACA,SAAS;CACX,CAAC;CAED,MAAM,CAAC,SAAS,qBAAqB,SAA6B,IAAI;CACtE,MAAM,CAAC,OAAO,mBAAmB,SAA6B,IAAI;CAClE,MAAM,CAAC,sBAAsB,2BAA2B,SAAS,KAAK;CACtE,MAAM,aAAa,OAAO,KAAK;CAE/B,MAAM,EAAE,sBAAsB,qBAAqB,SAAS,SAAS,OAAO;EAC1E;EACA;EACA;EACA;EACA;EACA,QAAQ,QAAQ,cAAc,QAAQ;CACxC,CAAC;CAED,MAAM,UAAU,eACP;EACL,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EAAC;EAAS;EAAU;EAAO;EAAY;CAAiB,CAC1D;CAEA,MAAM,QAA4B;EAChC,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;CACF;CAEA,OAAO,oBAAC,kBAAD;EAAkB,OAAO;EAAU,UAAA,kBAAkB,UAAU,KAAK;CAAoB,CAAA;AACjG;AAEA,cAAc,cAAc"}
|