@namroodinc/liquid-editorial 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/UPGRADING.md +23 -0
  2. package/dist/chunks/{EntryPicker-CR8Phuzl.js → EntryPicker-B88N69zH.js} +2 -2
  3. package/dist/chunks/{EntryPicker-CR8Phuzl.js.map → EntryPicker-B88N69zH.js.map} +1 -1
  4. package/dist/chunks/{EntryPicker-D7JIgx23.cjs → EntryPicker-daSkD4aR.cjs} +2 -2
  5. package/dist/chunks/{EntryPicker-D7JIgx23.cjs.map → EntryPicker-daSkD4aR.cjs.map} +1 -1
  6. package/dist/chunks/{FormEditor-DNcSAnRF.cjs → FormEditor-B4mtAxaU.cjs} +2 -2
  7. package/dist/chunks/FormEditor-B4mtAxaU.cjs.map +1 -0
  8. package/dist/chunks/{FormEditor-BSfxVqLn.js → FormEditor-BkBhcYI5.js} +3 -2
  9. package/dist/chunks/FormEditor-BkBhcYI5.js.map +1 -0
  10. package/dist/chunks/frame-C8TwdWBC.cjs +2 -0
  11. package/dist/chunks/frame-C8TwdWBC.cjs.map +1 -0
  12. package/dist/chunks/frame-DaC03_n-.js +203 -0
  13. package/dist/chunks/frame-DaC03_n-.js.map +1 -0
  14. package/dist/chunks/{group-Ckz4Xya-.js → group-C6EOgTgM.js} +2 -2
  15. package/dist/chunks/{group-Ckz4Xya-.js.map → group-C6EOgTgM.js.map} +1 -1
  16. package/dist/chunks/{group-Bj9ZKc0R.cjs → group-QSnlx4jX.cjs} +2 -2
  17. package/dist/chunks/{group-Bj9ZKc0R.cjs.map → group-QSnlx4jX.cjs.map} +1 -1
  18. package/dist/components/Choice/index.cjs +1 -1
  19. package/dist/components/Choice/index.js +1 -1
  20. package/dist/components/EntryPicker/index.cjs +1 -1
  21. package/dist/components/EntryPicker/index.js +1 -1
  22. package/dist/components/Field/frame.d.cts +1 -1
  23. package/dist/components/Field/frame.d.cts.map +1 -1
  24. package/dist/components/Field/frame.d.ts +1 -1
  25. package/dist/components/Field/frame.d.ts.map +1 -1
  26. package/dist/components/Field/header.d.cts +5 -3
  27. package/dist/components/Field/header.d.cts.map +1 -1
  28. package/dist/components/Field/header.d.ts +5 -3
  29. package/dist/components/Field/header.d.ts.map +1 -1
  30. package/dist/components/Field/index.cjs +1 -1
  31. package/dist/components/Field/index.js +1 -1
  32. package/dist/components/Field/style.css +18 -0
  33. package/dist/components/Field/types.d.cts +2 -0
  34. package/dist/components/Field/types.d.cts.map +1 -1
  35. package/dist/components/Field/types.d.ts +2 -0
  36. package/dist/components/Field/types.d.ts.map +1 -1
  37. package/dist/components/FormEditor/README.md +9 -0
  38. package/dist/components/FormEditor/index.cjs +1 -1
  39. package/dist/components/FormEditor/index.d.cts.map +1 -1
  40. package/dist/components/FormEditor/index.d.ts.map +1 -1
  41. package/dist/components/FormEditor/index.js +1 -1
  42. package/dist/components/FormEditor/model.d.cts +1 -0
  43. package/dist/components/FormEditor/model.d.cts.map +1 -1
  44. package/dist/components/FormEditor/model.d.ts +1 -0
  45. package/dist/components/FormEditor/model.d.ts.map +1 -1
  46. package/dist/components/SelectionCard/index.cjs +1 -1
  47. package/dist/components/SelectionCard/index.js +1 -1
  48. package/dist/index.cjs +1 -1
  49. package/dist/index.js +2 -2
  50. package/package.json +1 -1
  51. package/dist/chunks/FormEditor-BSfxVqLn.js.map +0 -1
  52. package/dist/chunks/FormEditor-DNcSAnRF.cjs.map +0 -1
  53. package/dist/chunks/frame-BBVQTBcX.cjs +0 -2
  54. package/dist/chunks/frame-BBVQTBcX.cjs.map +0 -1
  55. package/dist/chunks/frame-De6IuTQz.js +0 -189
  56. package/dist/chunks/frame-De6IuTQz.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormEditor-DNcSAnRF.cjs","names":["selectionLimit","sliderScale","preciseSum","documentError","isIsoDate","clampToScale","parseColour","RadioCard","CheckboxCard","Radio","Checkbox","SelectionCardGroup","ChoiceGroup","_Fragment","Button","sliderScale","Slider","RangeSlider","ColourField","parseColour","TagsInput","DateField","NumberField","Select","EntryPicker","TextField","TextArea","Switch","RichTextEditor","emptyDocument","useMemo","Container","Field","useState","require_colour","require_components_Button_index","require_components_Field_index","require_components_TextField_index","require_RichTextEditor","require_components_Container_index","require_EntryPicker","require_components_NumberField_index","require_components_Select_index","require_components_Switch_index","require_ColourField","require_Slider","require_DatePicker","require_components_TagsInput_index","require_components_Choice_index","require_components_SelectionCard_index","react","react_jsx_runtime","expandedWidths","fieldWidths","fieldTypes","assertModel","ids","field","model","assertChoices","assertSlider","assertMeasures","assertLimitOptions","limitedTypes","supportsLimit","fieldLimitProps","schemaLimit","stored","selected","textValue","stringList","pickerMode","pickerCopy","min","max","step","kind","values","option","value","linkCopy","fieldLabel","defaults","selectedIds","isLink","link","key","parseUtcDateTime","match","canonical","date","hasRichText","node","requiredError","textError","richTextError","error","choiceError","item","listError","numberError","dateError","sliderValue","scale","rangeSliderValue","range","start","end","low","high","a","b","rangeError","colourError","linkError","itemLabel","itemsLabel","validators","fieldError","validateFormValues","Option","props","isDisabled","invalid","onChange","Card","Choice","ChoiceControl","multiple","Group","accessibility","required","SliderControl","shown","next","RangeSliderControl","AdditionalControl","raw","event","pickerValue","links","NumberControl","SelectControl","isClearable","PickerControl","FormControl","shared","FormEditorField","validation","isErrorVisible","groupTypes","loadedValidationTypes","FormEditor","rest","internal","setInternal","defaultValue","changed","setChanged","current","schema","commit","fieldId","previous","onValueChange","layout","columns","minColumnWidth","className","style","fieldDisabled","isLocked","isLoaded","showAllErrors","pickerItems","errors"],"sources":["../../src/components/RichTextEditor/expanded-width.ts","../../src/components/FormEditor/model.ts","../../src/components/FormEditor/choice-control.tsx","../../src/components/FormEditor/additional-control.tsx","../../src/components/FormEditor/control.tsx","../../src/components/FormEditor/index.tsx"],"sourcesContent":["/** Expanded writing measures: `wide` caps at the shared wide Modal width; `full` fills the viewport inside the scrim's gutters. */\nexport const expandedWidths = [\"wide\", \"full\"] as const;\n\nexport type RichTextEditorExpandedWidth = (typeof expandedWidths)[number];\n","import type { ReactNode } from \"react\";\nimport type { SelectOption } from \"../Select\";\nimport type { EntryPickerMode, EntryPickerProps } from \"../EntryPicker\";\nimport { selectionLimit } from \"../EntryPicker/limit\";\nimport type { JSONContent } from \"@tiptap/react\";\nimport { documentError } from \"../RichTextEditor/document\";\nimport type { RichTextDocument } from \"../RichTextEditor\";\nimport { expandedWidths, type RichTextEditorExpandedWidth } from \"../RichTextEditor/expanded-width\";\nimport { isIsoDate } from \"../DatePicker/date\";\nimport type { RangeSliderValue } from \"../Slider\";\nimport { clampToScale, preciseSum, sliderScale, type SliderScale } from \"../Slider/scale\";\nimport { parseColour } from \"../ColourField/colour\";\nimport type { PopoverPlacement } from \"../Popover\";\nimport type { ContainerWidth } from \"../Container\";\nimport type { FieldLimit, FieldLimitOptions } from \"../Field/types\";\n\n/** The shared measures a field may cap at; checked against Container's scale. */\nconst fieldWidths = [\"sm\", \"md\", \"lg\"] as const satisfies readonly ContainerWidth[];\n\ninterface FormFieldBase {\n id: string;\n label: string;\n hint?: ReactNode;\n /** Maximum width of the whole field, using Container's measures and its `lg` default. */\n width?: (typeof fieldWidths)[number];\n placeholder?: string;\n required?: boolean;\n isDisabled?: boolean;\n}\n\ninterface SliderOptions {\n multiple?: never;\n min?: number;\n max?: number;\n step?: number;\n prefix?: string;\n suffix?: string;\n hasValueLabel?: boolean;\n}\n\ninterface ChoiceOptions {\n multiple?: never;\n autoFocus?: never;\n options: SelectOption[];\n appearance?: \"default\" | \"card\";\n /** Maximum options per row inside this group; independent of FormEditor columns. */\n columns?: 1 | 2 | 3;\n}\n\nexport type FormField = FormFieldBase &\n (\n | ({\n type: \"shortText\";\n inputType?: \"text\" | \"email\";\n maxLength?: number;\n readOnly?: boolean;\n autoFocus?: boolean;\n multiple?: never;\n } & FieldLimitOptions)\n | ({\n type: \"longText\";\n rows?: number;\n maxLength?: number;\n readOnly?: boolean;\n autoFocus?: boolean;\n multiple?: never;\n } & FieldLimitOptions)\n | { type: \"boolean\" | \"dateTime\"; autoFocus?: boolean; multiple?: never }\n | {\n type: \"richText\";\n expandedWidth?: RichTextEditorExpandedWidth;\n autoFocus?: never;\n multiple?: never;\n }\n | {\n type: \"number\";\n min?: number;\n max?: number;\n step?: number | \"any\";\n hasSteppers?: boolean;\n prefix?: string;\n suffix?: string;\n autoFocus?: boolean;\n multiple?: never;\n }\n | { type: \"select\"; options: SelectOption[]; autoFocus?: boolean; multiple?: never }\n | ({ type: \"slider\"; autoFocus?: boolean } & SliderOptions)\n | ({ type: \"rangeSlider\"; autoFocus?: never } & SliderOptions)\n | ({ type: \"radioGroup\" } & ChoiceOptions)\n | ({ type: \"checkboxGroup\" } & ChoiceOptions)\n | {\n type: \"colour\";\n multiple?: never;\n presets?: string[];\n showPresets?: boolean;\n picker?: \"custom\" | \"native\";\n placement?: PopoverPlacement;\n readOnly?: boolean;\n autoFocus?: boolean;\n }\n | ({ type: \"tags\"; max?: number; multiple?: never; autoFocus?: never } & FieldLimitOptions)\n | {\n type: \"date\";\n min?: string;\n max?: string;\n placement?: PopoverPlacement;\n multiple?: never;\n autoFocus?: never;\n }\n | ({\n type: \"asset\" | \"reference\";\n multiple?: boolean;\n autoFocus?: never;\n picker?: Pick<\n EntryPickerProps,\n \"label\" | \"addLabel\" | \"emptyLabel\" | \"itemLabel\" | \"itemsLabel\" | \"max\" | \"isReorderable\"\n >;\n } & FieldLimitOptions)\n );\n\nexport type FieldOf<T extends FormField[\"type\"]> = Extract<FormField, { type: T }>;\n\n/** Layout only: no label, value, disabled state, or validation. */\nexport interface FormDivider {\n id: string;\n type: \"divider\";\n}\n\nexport type FormItem = FormField | FormDivider;\n\nexport interface FormSchema {\n fields: readonly FormItem[];\n}\n\nexport interface AssetValue {\n assetId: string;\n}\nexport interface ReferenceValue {\n entryId: string;\n}\nexport type FormFieldValue =\n | string\n | number\n | boolean\n | RichTextDocument\n | AssetValue\n | ReferenceValue\n | string[]\n | RangeSliderValue\n | AssetValue[]\n | ReferenceValue[];\nexport type FormValues = Record<string, FormFieldValue | undefined>;\nexport type FormErrors = Partial<Record<string, string>>;\n\nconst fieldTypes = new Set([\n \"shortText\",\n \"longText\",\n \"richText\",\n \"number\",\n \"boolean\",\n \"dateTime\",\n \"asset\",\n \"reference\",\n \"select\",\n \"slider\",\n \"rangeSlider\",\n \"colour\",\n \"radioGroup\",\n \"checkboxGroup\",\n \"tags\",\n \"date\",\n \"divider\",\n]);\n\nexport function assertModel(model: FormSchema) {\n const ids = new Set<string>();\n for (const field of model.fields) {\n if (!field.id?.trim() || ids.has(field.id)) {\n throw new Error(\"Form field IDs must be nonempty and unique.\");\n }\n if (!fieldTypes.has(field.type)) {\n throw new Error(`Unsupported form field type: ${field.type}`);\n }\n if (field.type === \"select\" || field.type === \"radioGroup\" || field.type === \"checkboxGroup\") {\n assertChoices(field);\n }\n if (field.type === \"slider\" || field.type === \"rangeSlider\") {\n assertSlider(field);\n }\n if (field.type !== \"divider\") {\n assertMeasures(field);\n assertLimitOptions(field);\n }\n ids.add(field.id);\n }\n}\n\nconst limitedTypes = new Set([\"shortText\", \"longText\", \"tags\", \"asset\", \"reference\"]);\n\nfunction supportsLimit(\n field: FormField,\n): field is FieldOf<\"shortText\" | \"longText\" | \"tags\" | \"asset\" | \"reference\"> {\n return limitedTypes.has(field.type);\n}\n\nfunction assertLimitOptions(field: FormField) {\n if (!supportsLimit(field)) {\n return;\n }\n if (field.limitDisplay !== undefined && ![\"used\", \"remaining\"].includes(field.limitDisplay)) {\n throw new Error(`Field ${field.id} needs a limitDisplay of used or remaining.`);\n }\n if (\n field.limitVisibility !== undefined &&\n ![\"always\", \"nearLimit\"].includes(field.limitVisibility)\n ) {\n throw new Error(`Field ${field.id} needs a limitVisibility of always or nearLimit.`);\n }\n if (field.showLimitRing !== undefined && typeof field.showLimitRing !== \"boolean\") {\n throw new Error(`Field ${field.id} needs a boolean showLimitRing.`);\n }\n}\n\n/**\n * Explicit limits for complete server markup. Counts come from the helpers the\n * adapters display with (`textValue`, `stringList`, the owning field's selected\n * IDs and EntryPicker's `selectionLimit`), so the counter cannot drift from them.\n */\nexport function fieldLimitProps(\n field: FormField,\n stored: FormFieldValue | undefined,\n selected: string[] | undefined,\n): FieldLimitOptions & { limit?: FieldLimit } {\n if (!supportsLimit(field)) {\n return {};\n }\n return {\n limitDisplay: field.limitDisplay,\n limitVisibility: field.limitVisibility,\n showLimitRing: field.showLimitRing,\n limit: schemaLimit(field, stored, selected ?? []),\n };\n}\n\nfunction schemaLimit(\n field: FieldOf<\"shortText\" | \"longText\" | \"tags\" | \"asset\" | \"reference\">,\n stored: FormFieldValue | undefined,\n selected: string[],\n): FieldLimit | undefined {\n switch (field.type) {\n case \"shortText\":\n case \"longText\":\n return field.maxLength === undefined\n ? undefined\n : { count: textValue(stored).length, max: field.maxLength };\n case \"tags\":\n return field.max === undefined\n ? undefined\n : { count: stringList(stored).length, max: field.max };\n default:\n return selectionLimit(pickerMode(field), selected.length, pickerCopy(field).max);\n }\n}\n\n/** The text a shortText or longText adapter displays. */\nexport function textValue(stored: unknown): string {\n return typeof stored === \"string\" ? stored : \"\";\n}\n\n/** The EntryPicker mode a picker field renders with. */\nexport function pickerMode(field: FieldOf<\"asset\" | \"reference\">): EntryPickerMode {\n return field.multiple ? \"multiple\" : \"single\";\n}\n\n/** Runtime schemas can carry any string; the types only cover typed schemas. */\nfunction assertMeasures(field: FormField) {\n if (field.width !== undefined && !fieldWidths.includes(field.width)) {\n throw new Error(`Field ${field.id} needs a width of sm, md or lg.`);\n }\n if (\n field.type === \"richText\" &&\n field.expandedWidth !== undefined &&\n !expandedWidths.includes(field.expandedWidth)\n ) {\n throw new Error(`Rich text field ${field.id} needs an expandedWidth of wide or full.`);\n }\n}\n\nfunction assertSlider(field: FieldOf<\"slider\" | \"rangeSlider\">) {\n const { min, max, step } = sliderScale(field);\n if (![min, max, step].every(Number.isFinite) || min >= max || step <= 0) {\n throw new Error(`Slider field ${field.id} needs finite min < max and a positive step.`);\n }\n if (field.type === \"rangeSlider\" && step > preciseSum(max, -min)) {\n throw new Error(`Range slider ${field.id} needs room for at least one step.`);\n }\n}\n\nfunction assertChoices(field: FieldOf<\"select\" | \"radioGroup\" | \"checkboxGroup\">) {\n if (!Array.isArray(field.options)) {\n const kind = field.type === \"select\" ? \"Select\" : \"Choice\";\n throw new Error(`${kind} field ${field.id} needs an options array.`);\n }\n if (field.type === \"select\") {\n return;\n }\n const values = field.options.map((option) => option.value);\n if (\n values.some((value) => typeof value !== \"string\" || !value.trim()) ||\n new Set(values).size !== values.length\n ) {\n throw new Error(`Choice field ${field.id} needs nonempty, unique option values.`);\n }\n}\n\nconst linkCopy = {\n asset: { key: \"assetId\", itemLabel: \"asset\", itemsLabel: \"assets\" },\n reference: { key: \"entryId\", itemLabel: \"entry\", itemsLabel: \"entries\" },\n} as const;\n\n/** The field's visible and accessible name. A picker's `label` overrides it. */\nexport function fieldLabel(field: FormField): string {\n return field.type === \"asset\" || field.type === \"reference\"\n ? (field.picker?.label ?? field.label)\n : field.label;\n}\n\n/** Picker action and item copy, with asset or entry wording for any option left out or undefined. */\nexport function pickerCopy(field: FieldOf<\"asset\" | \"reference\">) {\n const defaults = linkCopy[field.type];\n const {\n addLabel = `Choose ${fieldLabel(field)}`,\n emptyLabel,\n itemLabel = defaults.itemLabel,\n itemsLabel = defaults.itemsLabel,\n max,\n isReorderable,\n } = field.picker ?? {};\n return { addLabel, emptyLabel, itemLabel, itemsLabel, max, isReorderable };\n}\n\n/** The picked IDs, in stored order, skipping anything that isn't a link. */\nexport function selectedIds(field: FieldOf<\"asset\" | \"reference\">, value: unknown): string[] {\n const { key } = linkCopy[field.type];\n const links = Array.isArray(value) ? value : value === undefined ? [] : [value];\n return links.flatMap((link) =>\n isLink(link, key) ? [(link as Record<string, string>)[key]] : [],\n );\n}\n\n/** Accept UTC ISO strings without rolling invalid dates into the next month. */\nexport function parseUtcDateTime(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return;\n }\n const match = /^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2})(?::(\\d{2})(?:\\.(\\d{1,3}))?)?(?:Z|\\+00:00)$/.exec(\n value,\n );\n if (!match) {\n return;\n }\n const canonical = `${match[1]}:${match[2] ?? \"00\"}.${(match[3] ?? \"\").padEnd(3, \"0\")}Z`;\n const date = new Date(canonical);\n if (Number.isFinite(date.getTime()) && date.toISOString() === canonical) {\n return canonical;\n }\n}\n\nfunction isLink(value: unknown, key: \"assetId\" | \"entryId\"): boolean {\n return (\n !!value &&\n typeof value === \"object\" &&\n key in value &&\n typeof (value as Record<string, unknown>)[key] === \"string\" &&\n (value as Record<string, string>)[key].trim().length > 0\n );\n}\n\nfunction hasRichText(node: JSONContent): boolean {\n return !!node.text?.trim() || node.type === \"horizontalRule\" || !!node.content?.some(hasRichText);\n}\n\nfunction requiredError(field: FormField): string {\n return `${fieldLabel(field)} is required.`;\n}\n\nfunction textError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return \"Enter text.\";\n }\n if (field.required && !value.trim()) {\n return requiredError(field);\n }\n if (\n (field.type === \"shortText\" || field.type === \"longText\") &&\n field.maxLength !== undefined &&\n value.length > field.maxLength\n ) {\n return `Enter no more than ${field.maxLength} characters.`;\n }\n}\n\nfunction richTextError(field: FormField, value: unknown): string | undefined {\n const error = documentError(value);\n if (error) {\n return error;\n }\n if (field.required && !hasRichText(value as RichTextDocument)) {\n return requiredError(field);\n }\n}\n\nfunction choiceError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return \"Choose an available option.\";\n }\n if (value === \"\") {\n return field.required ? requiredError(field) : undefined;\n }\n // An empty list means the choices are still loading, so a stored value stays valid until they arrive.\n if (\n (field.type === \"select\" || field.type === \"radioGroup\") &&\n field.options.length > 0 &&\n !field.options.some((option) => option.value === value)\n ) {\n return \"Choose an available option.\";\n }\n}\n\nexport function stringList(value: unknown): string[] {\n return Array.isArray(value)\n ? value.filter((item): item is string => typeof item === \"string\")\n : [];\n}\n\nfunction listError(field: FormField, value: unknown): string | undefined {\n if (\n !Array.isArray(value) ||\n !value.every((item) => typeof item === \"string\" && item.trim()) ||\n new Set(value).size !== value.length\n ) {\n return \"Enter a list of unique, nonempty text values.\";\n }\n if (field.required && !value.length) {\n return requiredError(field);\n }\n if (field.type === \"tags\" && field.max !== undefined && value.length > field.max) {\n return `Enter no more than ${field.max} tags.`;\n }\n if (\n field.type === \"checkboxGroup\" &&\n field.options.length &&\n value.some((item) => !field.options.some((option) => option.value === item))\n ) {\n return \"Choose available options.\";\n }\n}\n\nfunction numberError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n return \"Enter a finite number.\";\n }\n const { min, max }: { min?: number; max?: number } =\n field.type === \"slider\" || field.type === \"rangeSlider\"\n ? sliderScale(field)\n : field.type === \"number\"\n ? field\n : {};\n if (min !== undefined && value < min) {\n return `Enter a number of at least ${min}.`;\n }\n if (max !== undefined && value > max) {\n return `Enter a number no greater than ${max}.`;\n }\n}\n\nfunction dateError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return \"Enter a valid calendar date (YYYY-MM-DD).\";\n }\n if (!value) {\n return field.required ? requiredError(field) : undefined;\n }\n if (!isIsoDate(value)) {\n return \"Enter a valid calendar date (YYYY-MM-DD).\";\n }\n if (field.type !== \"date\") {\n return;\n }\n if (field.min && value < field.min) {\n return `Choose a date on or after ${field.min}.`;\n }\n if (field.max && value > field.max) {\n return `Choose a date on or before ${field.max}.`;\n }\n}\n\n/**\n * Display positions for loaded values: out-of-scale numbers clamp and reversed\n * endpoints swap, without overwriting the stored data that validation reports.\n * A value that is not a finite number has no position, so the control is unset.\n */\nexport function sliderValue(value: unknown, scale: SliderScale): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value)\n ? clampToScale(value, scale)\n : undefined;\n}\n\n/** A range with neither endpoint usable is unset; one usable endpoint pairs with the scale's end. */\nexport function rangeSliderValue(value: unknown, scale: SliderScale): RangeSliderValue | undefined {\n const range = value as Partial<Record<\"min\" | \"max\", unknown>> | null;\n const start = sliderValue(range?.min, scale);\n const end = sliderValue(range?.max, scale);\n if (start === undefined && end === undefined) {\n return undefined;\n }\n const [low, high] = [start ?? scale.min, end ?? scale.max].sort((a, b) => a - b);\n return { min: low, max: high };\n}\n\nfunction rangeError(field: FormField, value: unknown): string | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return \"Enter a range.\";\n }\n const range = value as Record<string, unknown>;\n const start = range.min;\n const end = range.max;\n const error = numberError(field, start) ?? numberError(field, end);\n if (error) {\n return error;\n }\n if ((start as number) > (end as number)) {\n return \"The start must not be greater than the end.\";\n }\n if (\n field.type === \"rangeSlider\" &&\n preciseSum(end as number, -(start as number)) < sliderScale(field).step\n ) {\n return \"Keep the range endpoints at least one step apart.\";\n }\n}\n\nfunction colourError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return \"Enter a valid colour.\";\n }\n if (!value.trim()) {\n return field.required ? requiredError(field) : undefined;\n }\n return parseColour(value) ? undefined : \"Enter a valid colour.\";\n}\n\nfunction linkError(field: FormField, value: unknown): string | undefined {\n if (field.type !== \"asset\" && field.type !== \"reference\") {\n return;\n }\n const { key, itemLabel, itemsLabel } = linkCopy[field.type];\n if (!field.multiple) {\n return isLink(value, key) ? undefined : `Choose an ${itemLabel}.`;\n }\n if (!Array.isArray(value) || !value.every((item) => isLink(item, key))) {\n return `Choose a list of ${itemsLabel}.`;\n }\n if (field.required && value.length === 0) {\n return requiredError(field);\n }\n const max = field.picker?.max;\n if (max !== undefined && value.length > max) {\n return `Choose no more than ${max} ${pickerCopy(field).itemsLabel}.`;\n }\n}\n\nconst validators: Record<\n FormField[\"type\"],\n (field: FormField, value: unknown) => string | undefined\n> = {\n shortText: textError,\n longText: textError,\n richText: richTextError,\n number: numberError,\n slider: numberError,\n rangeSlider: rangeError,\n date: dateError,\n colour: colourError,\n radioGroup: choiceError,\n checkboxGroup: listError,\n tags: listError,\n boolean: (_field, value) => (typeof value === \"boolean\" ? undefined : \"Choose a boolean value.\"),\n dateTime: (_field, value) =>\n parseUtcDateTime(value) ? undefined : \"Enter a valid UTC date and time.\",\n select: choiceError,\n asset: linkError,\n reference: linkError,\n};\n\nexport function fieldError(field: FormField, value: unknown): string | undefined {\n if (value === undefined) {\n return field.required ? requiredError(field) : undefined;\n }\n return validators[field.type](field, value);\n}\n\n/** Validate data loaded from JSON as well as values emitted by FormEditor. */\nexport function validateFormValues(model: FormSchema, values: Record<string, unknown>): FormErrors {\n assertModel(model);\n return Object.fromEntries(\n model.fields.flatMap((field): [string, string][] => {\n if (field.type === \"divider\") {\n return [];\n }\n const error = fieldError(\n field,\n Object.hasOwn(values, field.id) ? values[field.id] : undefined,\n );\n return error ? [[field.id, error]] : [];\n }),\n );\n}\n","import { Button } from \"../Button\";\nimport { Checkbox, ChoiceGroup, Radio } from \"../Choice\";\nimport { CheckboxCard, RadioCard, SelectionCardGroup } from \"../SelectionCard\";\nimport type { SelectOption } from \"../Select\";\nimport type { ControlProps } from \"./control\";\nimport { stringList, type FieldOf } from \"./model\";\n\ntype ChoiceField = FieldOf<\"radioGroup\" | \"checkboxGroup\">;\n\nfunction Option({\n field,\n option,\n name,\n checked,\n isDisabled,\n invalid,\n onChange,\n}: {\n field: ChoiceField;\n option: SelectOption;\n name: string;\n checked: boolean;\n isDisabled: boolean;\n invalid: true | undefined;\n onChange: () => void;\n}) {\n const props = {\n name,\n value: option.value,\n checked,\n disabled: isDisabled || option.isDisabled,\n \"aria-invalid\": invalid,\n onChange: () => {\n if (!isDisabled && !option.isDisabled) {\n onChange();\n }\n },\n };\n if (field.appearance === \"card\") {\n const Card = field.type === \"radioGroup\" ? RadioCard : CheckboxCard;\n return (\n <Card\n {...props}\n title={option.label}\n description={option.description}\n />\n );\n }\n const Choice = field.type === \"radioGroup\" ? Radio : Checkbox;\n return (\n <Choice {...props}>\n <span>\n {option.label}\n {option.description && (\n <span className=\"ds-form-editor__option-description\">{option.description}</span>\n )}\n </span>\n </Choice>\n );\n}\n\nexport function ChoiceControl({\n field,\n stored,\n isDisabled,\n required,\n accessibility,\n onChange,\n}: ControlProps<ChoiceField>) {\n const multiple = field.type === \"checkboxGroup\";\n // Option values are nonempty, so a stored \"\" selects nothing.\n const selected = multiple\n ? stringList(stored)\n : typeof stored === \"string\" && stored\n ? [stored]\n : [];\n const Group = field.appearance === \"card\" ? SelectionCardGroup : ChoiceGroup;\n return (\n <>\n <Group\n {...accessibility}\n label={field.label}\n columns={field.columns ?? (field.appearance === \"card\" ? 2 : 1)}\n >\n {field.options.map((option) => (\n <Option\n key={option.value}\n field={field}\n option={option}\n name={accessibility.id}\n checked={selected.includes(option.value)}\n isDisabled={isDisabled}\n invalid={accessibility[\"aria-invalid\"]}\n onChange={() => {\n if (multiple) {\n onChange(\n selected.includes(option.value)\n ? selected.filter((value) => value !== option.value)\n : [...selected, option.value],\n );\n } else {\n onChange(option.value);\n }\n }}\n />\n ))}\n </Group>\n {!multiple && !required && selected.length > 0 && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isDisabled={isDisabled}\n onClick={() => onChange(undefined)}\n >\n Clear {field.label}\n </Button>\n )}\n </>\n );\n}\n","import { ColourField } from \"../ColourField\";\nimport { parseColour } from \"../ColourField/colour\";\nimport { DateField } from \"../DatePicker\";\nimport { RangeSlider, Slider } from \"../Slider\";\nimport { sliderScale } from \"../Slider/scale\";\nimport { TagsInput } from \"../TagsInput\";\nimport { ChoiceControl } from \"./choice-control\";\nimport type { ControlProps } from \"./control\";\nimport { rangeSliderValue, sliderValue, stringList, type FieldOf } from \"./model\";\n\ntype AdditionalField = FieldOf<\n \"slider\" | \"rangeSlider\" | \"date\" | \"colour\" | \"tags\" | \"radioGroup\" | \"checkboxGroup\"\n>;\n\nfunction SliderControl({\n field,\n stored,\n isDisabled,\n accessibility,\n onChange,\n}: ControlProps<FieldOf<\"slider\">>) {\n const scale = sliderScale(field);\n const shown = sliderValue(stored, scale);\n return (\n <Slider\n {...accessibility}\n {...scale}\n prefix={field.prefix}\n suffix={field.suffix}\n hasValueLabel={field.hasValueLabel}\n valueText={shown === undefined ? (field.placeholder ?? \"Not set\") : undefined}\n autoFocus={field.autoFocus}\n isDisabled={isDisabled}\n value={shown ?? scale.min}\n onValueChange={onChange}\n // An unset thumb rests at the minimum, where a click or a key toward it fires\n // no change event. Committing stores the position the slider shows.\n onValueCommit={(next) => {\n if (shown === undefined) {\n onChange(next);\n }\n }}\n />\n );\n}\n\nfunction RangeSliderControl({\n field,\n stored,\n isDisabled,\n accessibility,\n onChange,\n}: ControlProps<FieldOf<\"rangeSlider\">>) {\n const scale = sliderScale(field);\n const shown = rangeSliderValue(stored, scale);\n return (\n <RangeSlider\n {...accessibility}\n {...scale}\n prefix={field.prefix}\n suffix={field.suffix}\n hasValueLabel={field.hasValueLabel}\n minLabel={`${field.label} minimum`}\n maxLabel={`${field.label} maximum`}\n isDisabled={isDisabled}\n // Unset thumbs rest at both ends without a fill, so nothing looks chosen; a click\n // or key that leaves them there stores the full range they show.\n valueText={shown === undefined ? (field.placeholder ?? \"Not set\") : undefined}\n hasFill={shown !== undefined}\n value={shown ?? { min: scale.min, max: scale.max }}\n onValueChange={onChange}\n onValueCommit={(next) => {\n if (shown === undefined) {\n onChange(next);\n }\n }}\n />\n );\n}\n\nexport function AdditionalControl({\n field,\n stored,\n isDisabled,\n required,\n accessibility,\n onChange,\n}: ControlProps<AdditionalField>) {\n const props = { stored, isDisabled, required, accessibility, onChange };\n switch (field.type) {\n case \"radioGroup\":\n case \"checkboxGroup\":\n return (\n <ChoiceControl\n field={field}\n {...props}\n />\n );\n case \"rangeSlider\":\n return (\n <RangeSliderControl\n field={field}\n {...props}\n />\n );\n case \"slider\":\n return (\n <SliderControl\n field={field}\n {...props}\n />\n );\n case \"colour\":\n return (\n <ColourField\n {...accessibility}\n required={required}\n placeholder={field.placeholder}\n presets={field.presets}\n showPresets={field.showPresets}\n picker={field.picker}\n placement={field.placement}\n readOnly={field.readOnly}\n autoFocus={field.autoFocus}\n isDisabled={isDisabled}\n value={typeof stored === \"string\" ? stored : \"\"}\n onInput={(event) => {\n const raw = event.currentTarget.value;\n if (raw.trim() && !parseColour(raw)) {\n onChange(raw);\n }\n }}\n onValueChange={(next) => onChange(next === \"\" ? undefined : next)}\n />\n );\n case \"tags\":\n return (\n <TagsInput\n {...accessibility}\n required={required}\n placeholder={field.placeholder}\n max={field.max}\n isDisabled={isDisabled}\n value={stringList(stored)}\n onValueChange={onChange}\n />\n );\n case \"date\":\n return (\n <DateField\n {...accessibility}\n placeholder={field.placeholder}\n min={field.min}\n max={field.max}\n placement={field.placement}\n isDisabled={isDisabled}\n isClearable\n clearLabel={`Clear ${field.label}`}\n value={typeof stored === \"string\" ? stored : \"\"}\n onValueChange={(next) => onChange(next === \"\" ? undefined : next)}\n />\n );\n }\n}\n","import { EntryPicker, type EntryItem } from \"../EntryPicker\";\nimport type { FieldRenderProps } from \"../Field\";\nimport { NumberField } from \"../NumberField\";\nimport { RichTextEditor, type RichTextDocument } from \"../RichTextEditor\";\nimport { emptyDocument } from \"../RichTextEditor/document\";\nimport { Select } from \"../Select\";\nimport { Switch } from \"../Switch\";\nimport { TextArea, TextField } from \"../TextField\";\nimport { AdditionalControl } from \"./additional-control\";\nimport {\n parseUtcDateTime,\n pickerCopy,\n pickerMode,\n textValue,\n type FieldOf,\n type FormField,\n type FormFieldValue,\n} from \"./model\";\n\nfunction pickerValue(\n field: FieldOf<\"asset\" | \"reference\">,\n ids: string[],\n): FormFieldValue | undefined {\n if (field.type === \"asset\") {\n const links = ids.map((assetId) => ({ assetId }));\n return field.multiple ? links : links[0];\n }\n const links = ids.map((entryId) => ({ entryId }));\n return field.multiple ? links : links[0];\n}\n\ntype Accessibility = FieldRenderProps;\n\nexport interface ControlProps<F extends FormField> {\n field: F;\n stored: FormFieldValue | undefined;\n isDisabled: boolean;\n required: boolean | undefined;\n accessibility: Omit<Accessibility, \"required\">;\n onChange: (value: FormFieldValue | undefined) => void;\n}\n\nfunction NumberControl({\n field,\n stored,\n isDisabled,\n required,\n accessibility,\n onChange,\n}: ControlProps<FieldOf<\"number\">>) {\n return (\n <NumberField\n {...accessibility}\n required={required}\n isDisabled={isDisabled}\n placeholder={field.placeholder}\n min={field.min}\n max={field.max}\n step={field.step ?? \"any\"}\n hasSteppers={field.hasSteppers ?? false}\n prefix={field.prefix}\n suffix={field.suffix}\n autoFocus={field.autoFocus}\n decreaseLabel={`Decrease ${field.label}`}\n increaseLabel={`Increase ${field.label}`}\n value={typeof stored === \"number\" && Number.isFinite(stored) ? stored : \"\"}\n onValueChange={(next) => {\n if (next === \"\" || Number.isFinite(next)) {\n onChange(next === \"\" ? undefined : next);\n }\n }}\n />\n );\n}\n\nfunction SelectControl({\n field,\n stored,\n isDisabled,\n required,\n accessibility,\n onChange,\n}: ControlProps<FieldOf<\"select\">>) {\n // Optional selects lead with an empty choice; picking it removes the key.\n const isClearable = !required && !field.options.some((option) => option.value === \"\");\n return (\n <Select\n {...accessibility}\n aria-required={required || undefined}\n isDisabled={isDisabled}\n isInvalid={accessibility[\"aria-invalid\"]}\n options={\n isClearable\n ? [{ value: \"\", label: field.placeholder ?? \"None\" }, ...field.options]\n : field.options\n }\n placeholder={field.placeholder}\n autoFocus={field.autoFocus}\n value={typeof stored === \"string\" ? stored : \"\"}\n onValueChange={(next) => onChange(next === \"\" ? undefined : next)}\n />\n );\n}\n\nfunction PickerControl({\n field,\n selected,\n items,\n isDisabled,\n accessibility,\n onChange,\n}: ControlProps<FieldOf<\"asset\" | \"reference\">> & { items: EntryItem[]; selected: string[] }) {\n return (\n <EntryPicker\n {...accessibility}\n items={items}\n value={selected}\n {...pickerCopy(field)}\n mode={pickerMode(field)}\n isDisabled={isDisabled}\n onValueChange={(ids) => onChange(pickerValue(field, ids))}\n />\n );\n}\n\ninterface FormControlProps {\n field: FormField;\n stored: FormFieldValue | undefined;\n /** Picker fields' stored IDs, derived once by the owning field. */\n selected: string[] | undefined;\n items: EntryItem[];\n isDisabled: boolean;\n accessibility: Accessibility;\n onChange: (value: FormFieldValue | undefined) => void;\n}\n\nexport function FormControl({\n field,\n stored,\n selected,\n items,\n isDisabled,\n accessibility: { required, ...accessibility },\n onChange,\n}: FormControlProps) {\n const shared = { stored, isDisabled, required, accessibility, onChange };\n switch (field.type) {\n case \"shortText\":\n return (\n <TextField\n {...accessibility}\n required={required}\n disabled={isDisabled}\n placeholder={field.placeholder}\n type={field.inputType}\n maxLength={field.maxLength}\n readOnly={field.readOnly}\n autoFocus={field.autoFocus}\n value={textValue(stored)}\n onChange={(event) => onChange(event.target.value)}\n />\n );\n case \"longText\":\n return (\n <TextArea\n {...accessibility}\n required={required}\n disabled={isDisabled}\n placeholder={field.placeholder}\n rows={field.rows}\n maxLength={field.maxLength}\n readOnly={field.readOnly}\n autoFocus={field.autoFocus}\n value={textValue(stored)}\n onChange={(event) => onChange(event.target.value)}\n />\n );\n case \"number\":\n return (\n <NumberControl\n field={field}\n {...shared}\n />\n );\n case \"boolean\":\n return (\n <Switch\n {...accessibility}\n isDisabled={isDisabled}\n autoFocus={field.autoFocus}\n isSelected={stored === true}\n onSelectedChange={onChange}\n />\n );\n case \"dateTime\":\n return (\n <TextField\n {...accessibility}\n required={required}\n disabled={isDisabled}\n type=\"datetime-local\"\n step=\"0.001\"\n autoFocus={field.autoFocus}\n value={parseUtcDateTime(stored)?.slice(0, -1) ?? \"\"}\n onChange={(event) => onChange(parseUtcDateTime(`${event.target.value}Z`))}\n />\n );\n case \"richText\":\n return (\n <RichTextEditor\n {...accessibility}\n expandedWidth={field.expandedWidth}\n label={field.label}\n isRequired={required}\n isDisabled={isDisabled}\n placeholder={field.placeholder}\n format=\"json\"\n value={stored === undefined ? emptyDocument : (stored as RichTextDocument)}\n onChange={onChange}\n />\n );\n case \"select\":\n return (\n <SelectControl\n field={field}\n {...shared}\n />\n );\n case \"asset\":\n case \"reference\":\n return (\n <PickerControl\n field={field}\n items={items}\n selected={selected ?? []}\n {...shared}\n />\n );\n default:\n return (\n <AdditionalControl\n field={field}\n {...shared}\n />\n );\n }\n}\n","import { useMemo, useState, type CSSProperties, type HTMLAttributes } from \"react\";\nimport { Container } from \"../Container\";\nimport type { EntryItem } from \"../EntryPicker\";\nimport { Field } from \"../Field\";\nimport type { GridColumns } from \"../Grid\";\nimport { FormControl } from \"./control\";\nimport {\n assertModel,\n fieldError,\n fieldLabel,\n fieldLimitProps,\n selectedIds,\n stringList,\n type FormField,\n type FormSchema,\n type FormErrors,\n type FormFieldValue,\n type FormValues,\n} from \"./model\";\nimport \"./style.css\";\n\nexport { validateFormValues } from \"./model\";\nexport type {\n AssetValue,\n FormField,\n FormDivider,\n FormItem,\n FormSchema,\n FormErrors,\n FormFieldValue,\n FormValues,\n ReferenceValue,\n} from \"./model\";\n\nexport interface FormChange {\n fieldId: string;\n}\n\nexport interface FormEditorProps extends Omit<\n HTMLAttributes<HTMLDivElement>,\n \"defaultValue\" | \"onChange\"\n> {\n schema: FormSchema;\n value?: FormValues;\n defaultValue?: FormValues;\n onValueChange?: (values: FormValues, change: FormChange) => void;\n /** Available assets or entries, keyed by field ID. Loading belongs to the app. */\n pickerItems?: Record<string, EntryItem[]>;\n /** App-provided messages take precedence over built-in validation. */\n errors?: FormErrors;\n isDisabled?: boolean;\n showAllErrors?: boolean;\n /** Columns at the widest. The form drops one whenever a field would be narrower than `minColumnWidth`. */\n columns?: GridColumns;\n /** Narrowest a field may get before the form drops a column. */\n minColumnWidth?: string;\n}\n\ninterface FormEditorFieldProps {\n field: FormField;\n stored: FormFieldValue | undefined;\n items: EntryItem[];\n isDisabled: boolean;\n error: string | undefined;\n isErrorVisible: boolean;\n onChange: (value: FormFieldValue | undefined) => void;\n}\n\n/** Validates only when its message can show, and only when its own field or value changes. */\nfunction FormEditorField({\n field,\n stored,\n items,\n isDisabled,\n error,\n isErrorVisible,\n onChange,\n}: FormEditorFieldProps) {\n const validation = useMemo(\n () => (error === undefined && isErrorVisible ? fieldError(field, stored) : undefined),\n [error, isErrorVisible, field, stored],\n );\n const selected = useMemo(\n () =>\n field.type === \"asset\" || field.type === \"reference\" ? selectedIds(field, stored) : undefined,\n [field, stored],\n );\n return (\n <Container\n width={field.width}\n padded={false}\n center={false}\n className=\"ds-form-editor__field\"\n >\n <Field\n {...fieldLimitProps(field, stored, selected)}\n label={field.type === \"dateTime\" ? `${field.label} (UTC)` : fieldLabel(field)}\n hint={field.hint}\n error={error ?? validation}\n isRequired={field.required}\n count={\n selected?.length ??\n (field.type === \"checkboxGroup\" ? stringList(stored).length : undefined)\n }\n isGroup={selected !== undefined || groupTypes.has(field.type)}\n >\n {(accessibility) => (\n <FormControl\n field={field}\n stored={stored}\n selected={selected}\n items={items}\n isDisabled={isDisabled}\n accessibility={accessibility}\n onChange={onChange}\n />\n )}\n </Field>\n </Container>\n );\n}\n\nconst groupTypes = new Set([\"radioGroup\", \"checkboxGroup\", \"rangeSlider\"]);\nconst loadedValidationTypes = new Set([\"slider\", \"rangeSlider\", \"date\", \"colour\"]);\n\n/** Ordered form controls. Loading, submission, and persistence belong to the app. */\nexport function FormEditor({\n schema,\n value,\n defaultValue = {},\n onValueChange,\n pickerItems = {},\n errors = {},\n isDisabled = false,\n showAllErrors = false,\n columns = 1,\n minColumnWidth = \"16rem\",\n className,\n style,\n ...rest\n}: FormEditorProps) {\n const [internal, setInternal] = useState<FormValues>(defaultValue);\n const [changed, setChanged] = useState<Set<string>>(() => new Set());\n const current = value ?? internal;\n useMemo(() => assertModel(schema), [schema]);\n\n const commit = (fieldId: string, next: FormFieldValue | undefined) => {\n const values = { ...current };\n if (next === undefined) {\n delete values[fieldId];\n } else {\n values[fieldId] = next;\n }\n if (value === undefined) {\n setInternal(values);\n }\n setChanged((previous) => new Set(previous).add(fieldId));\n onValueChange?.(values, { fieldId });\n };\n\n const layout =\n columns === \"auto\"\n ? { \"--form-editor-min-column\": minColumnWidth }\n : { \"--form-editor-columns\": columns, \"--form-editor-min-column\": minColumnWidth };\n\n return (\n <div\n className={[\"ds-form-editor\", columns === \"auto\" && \"ds-form-editor--auto\", className]\n .filter(Boolean)\n .join(\" \")}\n style={{ ...layout, ...style } as CSSProperties}\n {...rest}\n >\n {schema.fields.map((field) => {\n if (field.type === \"divider\") {\n return (\n <hr\n key={field.id}\n className=\"ds-form-editor__divider\"\n />\n );\n }\n const stored = Object.hasOwn(current, field.id) ? current[field.id] : undefined;\n const fieldDisabled = isDisabled || Boolean(field.isDisabled);\n const isLocked = fieldDisabled || (\"readOnly\" in field && Boolean(field.readOnly));\n // Explain loaded invalid values alongside the controls' invalid styling. Blank\n // strings are empty, so their required message waits like any other field's.\n const isLoaded = typeof stored === \"string\" ? stored.trim() !== \"\" : stored !== undefined;\n const isErrorVisible =\n showAllErrors ||\n changed.has(field.id) ||\n (isLoaded && loadedValidationTypes.has(field.type)) ||\n (field.type === \"number\" && typeof stored === \"number\");\n return (\n <FormEditorField\n key={field.id}\n field={field}\n stored={stored}\n items={pickerItems[field.id] ?? []}\n isDisabled={fieldDisabled}\n error={errors[field.id]}\n isErrorVisible={isErrorVisible}\n onChange={(next) => {\n if (!isLocked) {\n commit(field.id, next);\n }\n }}\n />\n );\n })}\n </div>\n );\n}\n"],"mappings":"A,gvBACA,IAAaoD,EAAiB,CAAC,OAAQ,MAAM,ECgBvCC,EAAc,CAAC,KAAM,KAAM,IAAI,EAyI/BC,EAAa,IAAI,IAAI,CACzB,YACA,WACA,WACA,SACA,UACA,WACA,QACA,YACA,SACA,SACA,cACA,SACA,aACA,gBACA,OACA,OACA,SACF,CAAC,EAED,SAAgBC,EAAY,EAAmB,CAC7C,IAAMC,EAAM,IAAI,IAChB,IAAK,IAAMC,KAASC,EAAM,OAAQ,CAChC,GAAI,CAACD,EAAM,IAAI,KAAK,GAAKD,EAAI,IAAIC,EAAM,EAAE,EACvC,MAAU,MAAM,6CAA6C,EAE/D,GAAI,CAACH,EAAW,IAAIG,EAAM,IAAI,EAC5B,MAAU,MAAM,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C,IAAY,OACR,CAAE,2BAA4BC,CAAe,EAC7C,CAAE,wBAAyBD,EAAS,2BAA4BC,CAAe,EAErF,OACE,EAAApH,EAAA,IAAA,CAAC,MAAD,CACE,UAAW,CAAC,iBAAkBmH,IAAY,QAAU,uBAAwBE,CAAS,CAAC,CACnF,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,EACX,MAAO,CAAE,GAAGH,EAAQ,GAAGI,CAAM,EAC7B,GAAIhB,EAEH,SAAAO,EAAO,OAAO,IAAK,GAAU,CAC5B,GAAIvG,EAAM,OAAS,UACjB,OACE,EAAAN,EAAA,IAAA,CAAC,KAAD,CAEE,UAAU,yBACX,EAFMM,EAAM,EAEZ,EAGL,IAAMU,EAAS,OAAO,OAAO4F,EAAStG,EAAM,EAAE,EAAIsG,EAAQtG,EAAM,IAAM,IAAA,GAChEiH,EAAgBhD,GAAc,EAAQjE,EAAM,WAC5CkH,EAAWD,GAAkB,aAAcjH,GAAS,EAAQA,EAAM,SAGlEmH,EAAW,OAAOzG,GAAW,SAAWA,EAAO,KAAK,IAAM,GAAKA,IAAW,IAAA,GAC1EkF,EACJwB,GACAhB,EAAQ,IAAIpG,EAAM,EAAE,GACnBmH,GAAYrB,GAAsB,IAAI9F,EAAM,IAAI,GAChDA,EAAM,OAAS,UAAY,OAAOU,GAAW,SAChD,OACE,EAAAhB,EAAA,IAAA,CAACgG,GAAD,CAES,QACC,SACR,MAAO2B,EAAYrH,EAAM,KAAO,CAAC,EACjC,WAAYiH,EACZ,MAAOK,EAAOtH,EAAM,IACJ,iBAChB,SAAW,GAAS,CACbkH,GACHV,EAAOxG,EAAM,GAAI6E,CAAI,CAEzB,CACD,EAZM7E,EAAM,EAYZ,CAEL,CAAC,CACE,CAAA,CAET,C"}
@@ -1,2 +0,0 @@
1
- const e=require("./context-BONPXF-V.cjs"),t=require("../components/Badge/index.cjs"),n=require("./limit-BX6-o1a2.cjs");;/* empty css */let r=require("react"),i=require("react/jsx-runtime");function a({label:e,count:n,isRequired:r,isGroup:a,id:o,labelId:s,hasLimit:c,children:l}){let u=a?`legend`:`label`,d=(0,i.jsxs)(i.Fragment,{children:[e,n!==void 0&&(0,i.jsx)(t.Badge,{className:`ds-field__count`,shape:`count`,isCountExact:!0,"aria-hidden":`true`,children:n}),r&&(0,i.jsx)(`span`,{className:`ds-field__required`,"aria-hidden":`true`,children:`*`})]}),f=(0,i.jsx)(u,{id:s,className:`ds-field__label`,htmlFor:a?void 0:o,children:d});return c?a?(0,i.jsxs)(`legend`,{className:`ds-field__header`,children:[(0,i.jsx)(`span`,{id:s,className:`ds-field__label`,children:d}),l]}):(0,i.jsxs)(`div`,{className:`ds-field__header`,children:[f,l]}):f}function o({count:e,max:t,id:r,limitDisplay:a=`used`,showLimitRing:o=!0}){let s=Math.min(1,e/t),c={"--limit-mix":`${(s<=.6?s/.6:(s-.6)/.4)*100}%`,"--limit-from":s<=.6?`var(--color-success)`:`var(--color-warning)`,"--limit-to":s<=.6?`var(--color-warning)`:`var(--color-danger)`};return(0,i.jsxs)(`span`,{className:`ds-field__limit`,"data-tone":n.n({count:e,max:t}),style:c,children:[(0,i.jsx)(`span`,{"aria-hidden":`true`,children:a===`remaining`?`${t-e} left`:`${e}/${t}`}),(0,i.jsx)(`span`,{id:r,className:`ds-field__limit-description`,children:n.t({count:e,max:t},a)}),o&&(0,i.jsxs)(`svg`,{className:`ds-field__limit-ring`,width:`16`,height:`16`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[(0,i.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,i.jsx)(`circle`,{className:`ds-field__limit-progress`,cx:`8`,cy:`8`,r:`6`,pathLength:`1`,strokeDasharray:s>=1?`none`:`${s} 1`})]})]})}var s={warning:1,danger:2};function c({limitDisplay:e,...t}){let a=n.n(t),o=a?s[a]:0,[c,l]=(0,r.useState)({level:o,text:``});return c.level!==o&&l({level:o,text:o>c.level?n.t(t,e):``}),(0,i.jsx)(`span`,{className:`ds-field__limit-announcement`,"aria-live":`polite`,"aria-atomic":`true`,children:c.text})}function l({label:t,hint:s,error:l,isRequired:p,count:m,limit:h,limitDisplay:g,limitVisibility:_,showLimitRing:v,isGroup:y=!1,children:b,className:x,groupBinding:S}){let C=(0,r.useId)(),w=d(s,l,C),T=`${C}-label`,E=`${C}-limit`,D=y?`fieldset`:`div`,[O,k]=(0,r.useState)(),[A,j]=(0,r.useState)(()=>new Map),M=h!==void 0,N=(0,r.useMemo)(()=>({labelId:T,isGroup:y,reportCount:k,reportLimit:M?void 0:(e,t)=>j(n=>u(n,e,t))}),[T,y,M]),P=m??O,[F]=A.values(),I=h??F,L=n.i(I,_),R=[w?.id,L?E:void 0].filter(Boolean).join(` `)||void 0,z=L&&(0,i.jsx)(o,{...L,id:E,limitDisplay:g,showLimitRing:v}),B=n.r(I)?I:void 0,V=B!==void 0;return(0,i.jsxs)(D,{...y?f(S,R,!!l,V?T:void 0):void 0,className:[`ds-field`,x].filter(Boolean).join(` `),children:[(0,i.jsx)(a,{label:t,count:P,isRequired:p,isGroup:y,id:C,labelId:T,hasLimit:V,children:z}),B&&(0,i.jsx)(c,{...B,limitDisplay:g}),(0,i.jsx)(e.t.Provider,{value:N,children:b({id:C,"aria-describedby":R,"aria-labelledby":T,"aria-invalid":l?!0:void 0,required:p})}),w&&(0,i.jsx)(`span`,{...w})]})}function u(e,t,n){let r=e.get(t);if(n?r?.count===n.count&&r.max===n.max:!r)return e;let i=new Map(e);return n?i.set(t,n):i.delete(t),i}function d(e,t,n){if(t)return{id:`${n}-error`,className:`ds-field__error`,children:t};if(e)return{id:`${n}-hint`,className:`ds-field__hint`,children:e}}function f(e,t,n,r){return{...e,"aria-labelledby":e?.[`aria-labelledby`]||(e?.[`aria-label`]?void 0:r),"aria-describedby":[e?.[`aria-describedby`],t].filter(Boolean).join(` `)||void 0,"aria-invalid":n||e?.[`aria-invalid`]}}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return l}});
2
- //# sourceMappingURL=frame-BBVQTBcX.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"frame-BBVQTBcX.cjs","names":["_Fragment","Badge","limitTone","limitDescription","useState","useId","useState","useMemo","visibleLimit","usableLimit","FieldFrameContext","require_context","require_components_Badge_index","require_limit","react","react_jsx_runtime","FieldHeader","Label","isGroup","contents","label","count","isRequired","labelElement","labelId","id","hasLimit","children","LimitReading","ratio","max","style","limitDisplay","showLimitRing","levels","LimitAnnouncer","limit","tone","level","announcement","setAnnouncement","FieldFrame","message","fieldMessage","hint","error","limitId","Wrapper","reportedCount","reportCount","reports","setReports","hasExplicitLimit","frame","withReport","current","key","next","shownCount","reportedLimit","currentLimit","shownLimit","limitVisibility","describedBy","reading","activeLimit","groupAttributes","groupBinding","className","binding","limitLabelId","description","invalid"],"sources":["../../src/components/Field/header.tsx","../../src/components/Field/limit-reading.tsx","../../src/components/Field/frame.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { Badge } from \"../Badge\";\nimport type { FieldProps } from \"./types\";\n\ninterface FieldHeaderProps extends Pick<FieldProps, \"label\" | \"count\" | \"isRequired\" | \"isGroup\"> {\n id: string;\n labelId: string;\n hasLimit: boolean;\n children: ReactNode;\n}\n\n/** Keep the usage reading outside the label's name and the legend directly in its fieldset. */\nexport function FieldHeader({\n label,\n count,\n isRequired,\n isGroup,\n id,\n labelId,\n hasLimit,\n children,\n}: FieldHeaderProps) {\n const Label = isGroup ? \"legend\" : \"label\";\n const contents = (\n <>\n {label}\n {count !== undefined && (\n <Badge\n className=\"ds-field__count\"\n shape=\"count\"\n isCountExact\n aria-hidden=\"true\"\n >\n {count}\n </Badge>\n )}\n {isRequired && (\n <span\n className=\"ds-field__required\"\n aria-hidden=\"true\"\n >\n *\n </span>\n )}\n </>\n );\n const labelElement = (\n <Label\n id={labelId}\n className=\"ds-field__label\"\n htmlFor={isGroup ? undefined : id}\n >\n {contents}\n </Label>\n );\n if (!hasLimit) {\n return labelElement;\n }\n if (isGroup) {\n return (\n <legend className=\"ds-field__header\">\n <span\n id={labelId}\n className=\"ds-field__label\"\n >\n {contents}\n </span>\n {children}\n </legend>\n );\n }\n return (\n <div className=\"ds-field__header\">\n {labelElement}\n {children}\n </div>\n );\n}\n","import { useState, type CSSProperties } from \"react\";\nimport { limitDescription, limitTone } from \"./limit\";\nimport type { FieldLimit, FieldLimitOptions } from \"./types\";\n\nexport function LimitReading({\n count,\n max,\n id,\n limitDisplay = \"used\",\n showLimitRing = true,\n}: FieldLimit & FieldLimitOptions & { id: string }) {\n const ratio = Math.min(1, count / max);\n const progress = ratio <= 0.6 ? ratio / 0.6 : (ratio - 0.6) / 0.4;\n const style = {\n \"--limit-mix\": `${progress * 100}%`,\n \"--limit-from\": ratio <= 0.6 ? \"var(--color-success)\" : \"var(--color-warning)\",\n \"--limit-to\": ratio <= 0.6 ? \"var(--color-warning)\" : \"var(--color-danger)\",\n } as CSSProperties;\n return (\n <span\n className=\"ds-field__limit\"\n data-tone={limitTone({ count, max })}\n style={style}\n >\n <span aria-hidden=\"true\">\n {limitDisplay === \"remaining\" ? `${max - count} left` : `${count}/${max}`}\n </span>\n <span\n id={id}\n className=\"ds-field__limit-description\"\n >\n {limitDescription({ count, max }, limitDisplay)}\n </span>\n {showLimitRing && (\n <svg\n className=\"ds-field__limit-ring\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n aria-hidden=\"true\"\n >\n <circle\n cx=\"8\"\n cy=\"8\"\n r=\"6\"\n />\n <circle\n className=\"ds-field__limit-progress\"\n cx=\"8\"\n cy=\"8\"\n r=\"6\"\n pathLength=\"1\"\n // A continuous stroke avoids a dash seam at the circle's closing point.\n strokeDasharray={ratio >= 1 ? \"none\" : `${ratio} 1`}\n />\n </svg>\n )}\n </span>\n );\n}\n\nconst levels = { warning: 1, danger: 2 } as const;\n\n/**\n * A polite region that exists for as long as the limit does, so it is already\n * registered when usage first crosses into warning or danger. It speaks only on\n * those crossings, not on every keystroke, and falls silent below them so a\n * later crossing is announced again. Loaded values are described, not announced.\n */\nexport function LimitAnnouncer({\n limitDisplay,\n ...limit\n}: FieldLimit & Pick<FieldLimitOptions, \"limitDisplay\">) {\n const tone = limitTone(limit);\n const level = tone ? levels[tone] : 0;\n const [announcement, setAnnouncement] = useState({ level, text: \"\" });\n if (announcement.level !== level) {\n setAnnouncement({\n level,\n text: level > announcement.level ? limitDescription(limit, limitDisplay) : \"\",\n });\n }\n return (\n <span\n className=\"ds-field__limit-announcement\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {announcement.text}\n </span>\n );\n}\n","import { useId, useMemo, useState } from \"react\";\nimport { FieldFrameContext, type FieldFrameContextValue } from \"./context\";\nimport { FieldHeader } from \"./header\";\nimport { LimitAnnouncer, LimitReading } from \"./limit-reading\";\nimport { usableLimit, visibleLimit } from \"./limit\";\nimport type { FieldBinding, FieldLimit, FieldProps } from \"./types\";\nimport \"./style.css\";\n\ninterface FieldFrameProps extends FieldProps {\n className?: string;\n groupBinding?: FieldBinding;\n}\n\ntype LimitReports = ReadonlyMap<string, FieldLimit>;\n\n/**\n * Shared label/legend, count, required marker and messages, including standalone\n * groups. A group's fieldset carries the description; bound controls don't repeat it.\n */\nexport function FieldFrame({\n label,\n hint,\n error,\n isRequired,\n count,\n limit,\n limitDisplay,\n limitVisibility,\n showLimitRing,\n isGroup = false,\n children,\n className,\n groupBinding,\n}: FieldFrameProps) {\n const id = useId();\n const message = fieldMessage(hint, error, id);\n const labelId = `${id}-label`;\n const limitId = `${id}-limit`;\n const Wrapper = isGroup ? \"fieldset\" : \"div\";\n const [reportedCount, reportCount] = useState<number>();\n const [reports, setReports] = useState<LimitReports>(() => new Map());\n const hasExplicitLimit = limit !== undefined;\n const frame = useMemo<FieldFrameContextValue>(\n () => ({\n labelId,\n isGroup,\n reportCount,\n reportLimit: hasExplicitLimit\n ? undefined\n : (key, next) => setReports((current) => withReport(current, key, next)),\n }),\n [labelId, isGroup, hasExplicitLimit],\n );\n const shownCount = count ?? reportedCount;\n // The first bound control to report keeps the reading while others come and go.\n const [reportedLimit] = reports.values();\n const currentLimit = limit ?? reportedLimit;\n const shownLimit = visibleLimit(currentLimit, limitVisibility);\n const describedBy =\n [message?.id, shownLimit ? limitId : undefined].filter(Boolean).join(\" \") || undefined;\n const reading = shownLimit && (\n <LimitReading\n {...shownLimit}\n id={limitId}\n limitDisplay={limitDisplay}\n showLimitRing={showLimitRing}\n />\n );\n const activeLimit = usableLimit(currentLimit) ? currentLimit : undefined;\n const hasLimit = activeLimit !== undefined;\n return (\n <Wrapper\n {...(isGroup\n ? groupAttributes(groupBinding, describedBy, Boolean(error), hasLimit ? labelId : undefined)\n : undefined)}\n className={[\"ds-field\", className].filter(Boolean).join(\" \")}\n >\n <FieldHeader\n label={label}\n count={shownCount}\n isRequired={isRequired}\n isGroup={isGroup}\n id={id}\n labelId={labelId}\n hasLimit={hasLimit}\n >\n {reading}\n </FieldHeader>\n {activeLimit && (\n <LimitAnnouncer\n {...activeLimit}\n limitDisplay={limitDisplay}\n />\n )}\n <FieldFrameContext.Provider value={frame}>\n {children({\n id,\n \"aria-describedby\": describedBy,\n \"aria-labelledby\": labelId,\n \"aria-invalid\": error ? true : undefined,\n required: isRequired,\n })}\n </FieldFrameContext.Provider>\n {message && <span {...message} />}\n </Wrapper>\n );\n}\n\n/** Updates keep a report's position, so one control never displaces another. */\nfunction withReport(reports: LimitReports, key: string, limit: FieldLimit | undefined) {\n const current = reports.get(key);\n if (limit ? current?.count === limit.count && current.max === limit.max : !current) {\n return reports;\n }\n const next = new Map(reports);\n if (limit) {\n next.set(key, limit);\n } else {\n next.delete(key);\n }\n return next;\n}\n\nfunction fieldMessage(hint: FieldProps[\"hint\"], error: FieldProps[\"error\"], id: string) {\n if (error) {\n return { id: `${id}-error`, className: \"ds-field__error\", children: error };\n }\n if (hint) {\n return { id: `${id}-hint`, className: \"ds-field__hint\", children: hint };\n }\n}\n\n/**\n * A limited legend also holds the counter, so `limitLabelId` names the group by\n * its label text alone. A consumer's own name for the group always wins.\n */\nfunction groupAttributes(\n binding: FieldBinding | undefined,\n description: string | undefined,\n invalid: boolean,\n limitLabelId: string | undefined,\n) {\n return {\n ...binding,\n \"aria-labelledby\":\n binding?.[\"aria-labelledby\"] || (binding?.[\"aria-label\"] ? undefined : limitLabelId),\n \"aria-describedby\":\n [binding?.[\"aria-describedby\"], description].filter(Boolean).join(\" \") || undefined,\n \"aria-invalid\": invalid || binding?.[\"aria-invalid\"],\n };\n}\n"],"mappings":"A,6MAYA,SAAgBgB,EAAY,CAC1B,QACA,QACA,aACA,UACA,KACA,UACA,WACA,YACmB,CACnB,IAAMC,EAAQC,EAAU,SAAW,QAC7BC,GACJ,EAAAJ,EAAA,KAAA,CAAAf,EAAAA,SAAA,CAAA,SAAA,CACGoB,EACAC,IAAU,IAAA,KACT,EAAAN,EAAA,IAAA,CAACd,EAAAA,MAAD,CACE,UAAU,kBACV,MAAM,QACN,aAAA,GACA,cAAY,OAEX,SAAAoB,CACI,CAAA,EAERC,IACC,EAAAP,EAAA,IAAA,CAAC,OAAD,CACE,UAAU,qBACV,cAAY,OACb,SAAA,GAEK,CAAA,CAER,CAAA,CAAA,EAEEQ,GACJ,EAAAR,EAAA,IAAA,CAACE,EAAD,CACE,GAAIO,EACJ,UAAU,kBACV,QAASN,EAAU,IAAA,GAAYO,EAE9B,SAAAN,CACI,CAAA,EAkBT,OAhBKO,EAGDR,GAEA,EAAAH,EAAA,KAAA,CAAC,SAAD,CAAQ,UAAU,mBAAlB,SAAA,EACE,EAAAA,EAAA,IAAA,CAAC,OAAD,CACE,GAAIS,EACJ,UAAU,kBAET,SAAAL,CACG,CAAA,EACLQ,CACK,C,IAIV,EAAAZ,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,mBAAf,SAAA,CACGQ,EACAI,CACE,C,GAnBEJ,CAqBX,CCzEA,SAAgBK,EAAa,CAC3B,QACA,MACA,KACA,eAAe,OACf,gBAAgB,IACkC,CAClD,IAAMC,EAAQ,KAAK,IAAI,EAAGR,EAAQS,CA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3E,CAMA,SAASsB,EACP,EACA,EACA,EACA,EACA,CACA,MAAO,CACL,GAAGG,EACH,kBACEA,IAAU,qBAAuBA,IAAU,cAAgB,IAAA,GAAYC,GACzE,mBACE,CAACD,IAAU,oBAAqBE,CAAW,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,GAAK,IAAA,GAC5E,eAAgBC,GAAWH,IAAU,eACvC,CACF,C"}
@@ -1,189 +0,0 @@
1
- import { t as e } from "./context-CXvOl4Kt.js";
2
- import { Badge as t } from "../components/Badge/index.js";
3
- import { i as n, n as r, r as i, t as a } from "./limit-ChteDN4T.js";
4
- /* empty css */
5
- import { useId as o, useMemo as s, useState as c } from "react";
6
- import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
7
- //#region src/components/Field/header.tsx
8
- function f({ label: e, count: n, isRequired: r, isGroup: i, id: a, labelId: o, hasLimit: s, children: c }) {
9
- let f = i ? "legend" : "label", p = /* @__PURE__ */ d(l, { children: [
10
- e,
11
- n !== void 0 && /* @__PURE__ */ u(t, {
12
- className: "ds-field__count",
13
- shape: "count",
14
- isCountExact: !0,
15
- "aria-hidden": "true",
16
- children: n
17
- }),
18
- r && /* @__PURE__ */ u("span", {
19
- className: "ds-field__required",
20
- "aria-hidden": "true",
21
- children: "*"
22
- })
23
- ] }), m = /* @__PURE__ */ u(f, {
24
- id: o,
25
- className: "ds-field__label",
26
- htmlFor: i ? void 0 : a,
27
- children: p
28
- });
29
- return s ? i ? /* @__PURE__ */ d("legend", {
30
- className: "ds-field__header",
31
- children: [/* @__PURE__ */ u("span", {
32
- id: o,
33
- className: "ds-field__label",
34
- children: p
35
- }), c]
36
- }) : /* @__PURE__ */ d("div", {
37
- className: "ds-field__header",
38
- children: [m, c]
39
- }) : m;
40
- }
41
- //#endregion
42
- //#region src/components/Field/limit-reading.tsx
43
- function p({ count: e, max: t, id: n, limitDisplay: i = "used", showLimitRing: o = !0 }) {
44
- let s = Math.min(1, e / t), c = {
45
- "--limit-mix": `${(s <= .6 ? s / .6 : (s - .6) / .4) * 100}%`,
46
- "--limit-from": s <= .6 ? "var(--color-success)" : "var(--color-warning)",
47
- "--limit-to": s <= .6 ? "var(--color-warning)" : "var(--color-danger)"
48
- };
49
- return /* @__PURE__ */ d("span", {
50
- className: "ds-field__limit",
51
- "data-tone": r({
52
- count: e,
53
- max: t
54
- }),
55
- style: c,
56
- children: [
57
- /* @__PURE__ */ u("span", {
58
- "aria-hidden": "true",
59
- children: i === "remaining" ? `${t - e} left` : `${e}/${t}`
60
- }),
61
- /* @__PURE__ */ u("span", {
62
- id: n,
63
- className: "ds-field__limit-description",
64
- children: a({
65
- count: e,
66
- max: t
67
- }, i)
68
- }),
69
- o && /* @__PURE__ */ d("svg", {
70
- className: "ds-field__limit-ring",
71
- width: "16",
72
- height: "16",
73
- viewBox: "0 0 16 16",
74
- "aria-hidden": "true",
75
- children: [/* @__PURE__ */ u("circle", {
76
- cx: "8",
77
- cy: "8",
78
- r: "6"
79
- }), /* @__PURE__ */ u("circle", {
80
- className: "ds-field__limit-progress",
81
- cx: "8",
82
- cy: "8",
83
- r: "6",
84
- pathLength: "1",
85
- strokeDasharray: s >= 1 ? "none" : `${s} 1`
86
- })]
87
- })
88
- ]
89
- });
90
- }
91
- var m = {
92
- warning: 1,
93
- danger: 2
94
- };
95
- function h({ limitDisplay: e, ...t }) {
96
- let n = r(t), i = n ? m[n] : 0, [o, s] = c({
97
- level: i,
98
- text: ""
99
- });
100
- return o.level !== i && s({
101
- level: i,
102
- text: i > o.level ? a(t, e) : ""
103
- }), /* @__PURE__ */ u("span", {
104
- className: "ds-field__limit-announcement",
105
- "aria-live": "polite",
106
- "aria-atomic": "true",
107
- children: o.text
108
- });
109
- }
110
- //#endregion
111
- //#region src/components/Field/frame.tsx
112
- function g({ label: t, hint: r, error: a, isRequired: l, count: m, limit: g, limitDisplay: b, limitVisibility: x, showLimitRing: S, isGroup: C = !1, children: w, className: T, groupBinding: E }) {
113
- let D = o(), O = v(r, a, D), k = `${D}-label`, A = `${D}-limit`, j = C ? "fieldset" : "div", [M, N] = c(), [P, F] = c(() => /* @__PURE__ */ new Map()), I = g !== void 0, L = s(() => ({
114
- labelId: k,
115
- isGroup: C,
116
- reportCount: N,
117
- reportLimit: I ? void 0 : (e, t) => F((n) => _(n, e, t))
118
- }), [
119
- k,
120
- C,
121
- I
122
- ]), R = m ?? M, [z] = P.values(), B = g ?? z, V = n(B, x), H = [O?.id, V ? A : void 0].filter(Boolean).join(" ") || void 0, U = V && /* @__PURE__ */ u(p, {
123
- ...V,
124
- id: A,
125
- limitDisplay: b,
126
- showLimitRing: S
127
- }), W = i(B) ? B : void 0, G = W !== void 0;
128
- return /* @__PURE__ */ d(j, {
129
- ...C ? y(E, H, !!a, G ? k : void 0) : void 0,
130
- className: ["ds-field", T].filter(Boolean).join(" "),
131
- children: [
132
- /* @__PURE__ */ u(f, {
133
- label: t,
134
- count: R,
135
- isRequired: l,
136
- isGroup: C,
137
- id: D,
138
- labelId: k,
139
- hasLimit: G,
140
- children: U
141
- }),
142
- W && /* @__PURE__ */ u(h, {
143
- ...W,
144
- limitDisplay: b
145
- }),
146
- /* @__PURE__ */ u(e.Provider, {
147
- value: L,
148
- children: w({
149
- id: D,
150
- "aria-describedby": H,
151
- "aria-labelledby": k,
152
- "aria-invalid": a ? !0 : void 0,
153
- required: l
154
- })
155
- }),
156
- O && /* @__PURE__ */ u("span", { ...O })
157
- ]
158
- });
159
- }
160
- function _(e, t, n) {
161
- let r = e.get(t);
162
- if (n ? r?.count === n.count && r.max === n.max : !r) return e;
163
- let i = new Map(e);
164
- return n ? i.set(t, n) : i.delete(t), i;
165
- }
166
- function v(e, t, n) {
167
- if (t) return {
168
- id: `${n}-error`,
169
- className: "ds-field__error",
170
- children: t
171
- };
172
- if (e) return {
173
- id: `${n}-hint`,
174
- className: "ds-field__hint",
175
- children: e
176
- };
177
- }
178
- function y(e, t, n, r) {
179
- return {
180
- ...e,
181
- "aria-labelledby": e?.["aria-labelledby"] || (e?.["aria-label"] ? void 0 : r),
182
- "aria-describedby": [e?.["aria-describedby"], t].filter(Boolean).join(" ") || void 0,
183
- "aria-invalid": n || e?.["aria-invalid"]
184
- };
185
- }
186
- //#endregion
187
- export { g as t };
188
-
189
- //# sourceMappingURL=frame-De6IuTQz.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"frame-De6IuTQz.js","names":["_Fragment","FieldFrameContext","visibleLimit","limitTone","usableLimit","limitDescription","Fragment$1","FieldHeader","Label","isGroup","contents","label","count","Badge","isRequired","labelElement","labelId","id","hasLimit","children","LimitReading","ratio","max","style","limitDisplay","showLimitRing","levels","LimitAnnouncer","limit","tone","level","announcement","setAnnouncement","useState","FieldFrame","useId","message","fieldMessage","hint","error","limitId","Wrapper","reportedCount","reportCount","reports","setReports","hasExplicitLimit","frame","useMemo","withReport","current","key","next","shownCount","reportedLimit","currentLimit","shownLimit","limitVisibility","describedBy","reading","activeLimit","groupAttributes","groupBinding","className","binding","limitLabelId","description","invalid"],"sources":["../../src/components/Field/header.tsx","../../src/components/Field/limit-reading.tsx","../../src/components/Field/frame.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { Badge } from \"../Badge\";\nimport type { FieldProps } from \"./types\";\n\ninterface FieldHeaderProps extends Pick<FieldProps, \"label\" | \"count\" | \"isRequired\" | \"isGroup\"> {\n id: string;\n labelId: string;\n hasLimit: boolean;\n children: ReactNode;\n}\n\n/** Keep the usage reading outside the label's name and the legend directly in its fieldset. */\nexport function FieldHeader({\n label,\n count,\n isRequired,\n isGroup,\n id,\n labelId,\n hasLimit,\n children,\n}: FieldHeaderProps) {\n const Label = isGroup ? \"legend\" : \"label\";\n const contents = (\n <>\n {label}\n {count !== undefined && (\n <Badge\n className=\"ds-field__count\"\n shape=\"count\"\n isCountExact\n aria-hidden=\"true\"\n >\n {count}\n </Badge>\n )}\n {isRequired && (\n <span\n className=\"ds-field__required\"\n aria-hidden=\"true\"\n >\n *\n </span>\n )}\n </>\n );\n const labelElement = (\n <Label\n id={labelId}\n className=\"ds-field__label\"\n htmlFor={isGroup ? undefined : id}\n >\n {contents}\n </Label>\n );\n if (!hasLimit) {\n return labelElement;\n }\n if (isGroup) {\n return (\n <legend className=\"ds-field__header\">\n <span\n id={labelId}\n className=\"ds-field__label\"\n >\n {contents}\n </span>\n {children}\n </legend>\n );\n }\n return (\n <div className=\"ds-field__header\">\n {labelElement}\n {children}\n </div>\n );\n}\n","import { useState, type CSSProperties } from \"react\";\nimport { limitDescription, limitTone } from \"./limit\";\nimport type { FieldLimit, FieldLimitOptions } from \"./types\";\n\nexport function LimitReading({\n count,\n max,\n id,\n limitDisplay = \"used\",\n showLimitRing = true,\n}: FieldLimit & FieldLimitOptions & { id: string }) {\n const ratio = Math.min(1, count / max);\n const progress = ratio <= 0.6 ? ratio / 0.6 : (ratio - 0.6) / 0.4;\n const style = {\n \"--limit-mix\": `${progress * 100}%`,\n \"--limit-from\": ratio <= 0.6 ? \"var(--color-success)\" : \"var(--color-warning)\",\n \"--limit-to\": ratio <= 0.6 ? \"var(--color-warning)\" : \"var(--color-danger)\",\n } as CSSProperties;\n return (\n <span\n className=\"ds-field__limit\"\n data-tone={limitTone({ count, max })}\n style={style}\n >\n <span aria-hidden=\"true\">\n {limitDisplay === \"remaining\" ? `${max - count} left` : `${count}/${max}`}\n </span>\n <span\n id={id}\n className=\"ds-field__limit-description\"\n >\n {limitDescription({ count, max }, limitDisplay)}\n </span>\n {showLimitRing && (\n <svg\n className=\"ds-field__limit-ring\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n aria-hidden=\"true\"\n >\n <circle\n cx=\"8\"\n cy=\"8\"\n r=\"6\"\n />\n <circle\n className=\"ds-field__limit-progress\"\n cx=\"8\"\n cy=\"8\"\n r=\"6\"\n pathLength=\"1\"\n // A continuous stroke avoids a dash seam at the circle's closing point.\n strokeDasharray={ratio >= 1 ? \"none\" : `${ratio} 1`}\n />\n </svg>\n )}\n </span>\n );\n}\n\nconst levels = { warning: 1, danger: 2 } as const;\n\n/**\n * A polite region that exists for as long as the limit does, so it is already\n * registered when usage first crosses into warning or danger. It speaks only on\n * those crossings, not on every keystroke, and falls silent below them so a\n * later crossing is announced again. Loaded values are described, not announced.\n */\nexport function LimitAnnouncer({\n limitDisplay,\n ...limit\n}: FieldLimit & Pick<FieldLimitOptions, \"limitDisplay\">) {\n const tone = limitTone(limit);\n const level = tone ? levels[tone] : 0;\n const [announcement, setAnnouncement] = useState({ level, text: \"\" });\n if (announcement.level !== level) {\n setAnnouncement({\n level,\n text: level > announcement.level ? limitDescription(limit, limitDisplay) : \"\",\n });\n }\n return (\n <span\n className=\"ds-field__limit-announcement\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {announcement.text}\n </span>\n );\n}\n","import { useId, useMemo, useState } from \"react\";\nimport { FieldFrameContext, type FieldFrameContextValue } from \"./context\";\nimport { FieldHeader } from \"./header\";\nimport { LimitAnnouncer, LimitReading } from \"./limit-reading\";\nimport { usableLimit, visibleLimit } from \"./limit\";\nimport type { FieldBinding, FieldLimit, FieldProps } from \"./types\";\nimport \"./style.css\";\n\ninterface FieldFrameProps extends FieldProps {\n className?: string;\n groupBinding?: FieldBinding;\n}\n\ntype LimitReports = ReadonlyMap<string, FieldLimit>;\n\n/**\n * Shared label/legend, count, required marker and messages, including standalone\n * groups. A group's fieldset carries the description; bound controls don't repeat it.\n */\nexport function FieldFrame({\n label,\n hint,\n error,\n isRequired,\n count,\n limit,\n limitDisplay,\n limitVisibility,\n showLimitRing,\n isGroup = false,\n children,\n className,\n groupBinding,\n}: FieldFrameProps) {\n const id = useId();\n const message = fieldMessage(hint, error, id);\n const labelId = `${id}-label`;\n const limitId = `${id}-limit`;\n const Wrapper = isGroup ? \"fieldset\" : \"div\";\n const [reportedCount, reportCount] = useState<number>();\n const [reports, setReports] = useState<LimitReports>(() => new Map());\n const hasExplicitLimit = limit !== undefined;\n const frame = useMemo<FieldFrameContextValue>(\n () => ({\n labelId,\n isGroup,\n reportCount,\n reportLimit: hasExplicitLimit\n ? undefined\n : (key, next) => setReports((current) => withReport(current, key, next)),\n }),\n [labelId, isGroup, hasExplicitLimit],\n );\n const shownCount = count ?? reportedCount;\n // The first bound control to report keeps the reading while others come and go.\n const [reportedLimit] = reports.values();\n const currentLimit = limit ?? reportedLimit;\n const shownLimit = visibleLimit(currentLimit, limitVisibility);\n const describedBy =\n [message?.id, shownLimit ? limitId : undefined].filter(Boolean).join(\" \") || undefined;\n const reading = shownLimit && (\n <LimitReading\n {...shownLimit}\n id={limitId}\n limitDisplay={limitDisplay}\n showLimitRing={showLimitRing}\n />\n );\n const activeLimit = usableLimit(currentLimit) ? currentLimit : undefined;\n const hasLimit = activeLimit !== undefined;\n return (\n <Wrapper\n {...(isGroup\n ? groupAttributes(groupBinding, describedBy, Boolean(error), hasLimit ? labelId : undefined)\n : undefined)}\n className={[\"ds-field\", className].filter(Boolean).join(\" \")}\n >\n <FieldHeader\n label={label}\n count={shownCount}\n isRequired={isRequired}\n isGroup={isGroup}\n id={id}\n labelId={labelId}\n hasLimit={hasLimit}\n >\n {reading}\n </FieldHeader>\n {activeLimit && (\n <LimitAnnouncer\n {...activeLimit}\n limitDisplay={limitDisplay}\n />\n )}\n <FieldFrameContext.Provider value={frame}>\n {children({\n id,\n \"aria-describedby\": describedBy,\n \"aria-labelledby\": labelId,\n \"aria-invalid\": error ? true : undefined,\n required: isRequired,\n })}\n </FieldFrameContext.Provider>\n {message && <span {...message} />}\n </Wrapper>\n );\n}\n\n/** Updates keep a report's position, so one control never displaces another. */\nfunction withReport(reports: LimitReports, key: string, limit: FieldLimit | undefined) {\n const current = reports.get(key);\n if (limit ? current?.count === limit.count && current.max === limit.max : !current) {\n return reports;\n }\n const next = new Map(reports);\n if (limit) {\n next.set(key, limit);\n } else {\n next.delete(key);\n }\n return next;\n}\n\nfunction fieldMessage(hint: FieldProps[\"hint\"], error: FieldProps[\"error\"], id: string) {\n if (error) {\n return { id: `${id}-error`, className: \"ds-field__error\", children: error };\n }\n if (hint) {\n return { id: `${id}-hint`, className: \"ds-field__hint\", children: hint };\n }\n}\n\n/**\n * A limited legend also holds the counter, so `limitLabelId` names the group by\n * its label text alone. A consumer's own name for the group always wins.\n */\nfunction groupAttributes(\n binding: FieldBinding | undefined,\n description: string | undefined,\n invalid: boolean,\n limitLabelId: string | undefined,\n) {\n return {\n ...binding,\n \"aria-labelledby\":\n binding?.[\"aria-labelledby\"] || (binding?.[\"aria-label\"] ? undefined : limitLabelId),\n \"aria-describedby\":\n [binding?.[\"aria-describedby\"], description].filter(Boolean).join(\" \") || undefined,\n \"aria-invalid\": invalid || binding?.[\"aria-invalid\"],\n };\n}\n"],"mappings":";;;;;;;AAYA,SAAgBO,EAAY,EAC1B,UACA,UACA,eACA,YACA,OACA,YACA,aACA,eACmB;CACnB,IAAMC,IAAQC,IAAU,WAAW,SAC7BC,IACJ,kBAAAV,GAAA,EAAA,UAAA;EACGW;EACAC,MAAU,KAAA,KACT,kBAACC,GAAD;GACE,WAAU;GACV,OAAM;GACN,cAAA;GACA,eAAY;GAEX,UAAAD;EACI,CAAA;EAERE,KACC,kBAAC,QAAD;GACE,WAAU;GACV,eAAY;GACb,UAAA;EAEK,CAAA;CAER,EAAA,CAAA,GAEEC,IACJ,kBAACP,GAAD;EACE,IAAIQ;EACJ,WAAU;EACV,SAASP,IAAU,KAAA,IAAYQ;EAE9B,UAAAP;CACI,CAAA;CAkBT,OAhBKQ,IAGDT,IAEA,kBAAC,UAAD;EAAQ,WAAU;EAAlB,UAAA,CACE,kBAAC,QAAD;GACE,IAAIO;GACJ,WAAU;GAET,UAAAN;EACG,CAAA,GACLS,CACK;C,KAIV,kBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACGJ,GACAI,CACE;C,KAnBEJ;AAqBX;;;ACzEA,SAAgBK,EAAa,EAC3B,UACA,QACA,OACA,kBAAe,QACf,mBAAgB,MACkC;CAClD,IAAMC,IAAQ,KAAK,IAAI,GAAGT,I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