{"version":3,"file":"chunk-Field.mjs","names":["FieldPrimitive"],"sources":["../../src/components/Field/Field.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { Field as FieldPrimitive, useFieldContext } from '@ark-ui/react/field';\nimport { useFieldsetContext } from '@ark-ui/react/fieldset';\nimport React, { Children, type ComponentPropsWithoutRef, forwardRef, isValidElement } from 'react';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type MessageValence, type ThemedClassName } from '@dxos/ui-types';\n\nimport { recipes } from '../../recipes.ts';\nimport { type Size } from '../../sizes.ts';\nimport { type Level, type Span, spanAttributes } from '../Container/Container.tsx';\n\n//\n// Root\n//\n\n/** The current Field's validation tones; `error` is the one that makes the field invalid. */\ntype FieldValence = MessageValence;\n\ntype FieldRootProps = ThemedClassName<FieldPrimitive.RootProps> & {\n  /**\n   * Tones the control's border and focus ring and the HelperText; `error` also sets `invalid` (unless given), so\n   * ErrorText shows and the control reports `aria-invalid`.\n   */\n  validationValence?: FieldValence;\n  /**\n   * `stack` (default) puts the label above the control (decision 13). `row` joins the parent's `columns` as a subgrid\n   * row (Phase 4 decision 3): the Header and HelperText take the tracks before the parent's interior `control` line,\n   * every other child the tracks after it; below the pane's collapse width the row stacks.\n   */\n  layout?: 'stack' | 'row';\n  /** A surface rung for a `row` field, which then draws a separator border around itself (a settings card row). */\n  level?: Level;\n  /** Tracks the field spans in its parent Container (e.g. two columns of a multi-column form). */\n  span?: Span;\n};\n\n/** A part, not a container (decision 13): a flex stack in the content track with the label above its control. */\nconst FieldRoot = forwardRef<HTMLDivElement, FieldRootProps>(\n  ({ classNames, invalid, validationValence, layout, level, span, style, ...props }, forwardedRef) => {\n    // Ark inherits only `disabled` from an enclosing Fieldset; an invalid set marks its fields invalid too.\n    const fieldset = useFieldsetContext();\n    const { style: spanStyle, ...spanAttrs } = spanAttributes(span);\n    return (\n      <FieldPrimitive.Root\n        {...props}\n        {...spanAttrs}\n        style={{ ...spanStyle, ...style }}\n        invalid={invalid ?? (validationValence === 'error' || fieldset?.invalid)}\n        data-valence={validationValence === 'neutral' ? undefined : validationValence}\n        data-layout={layout === 'row' ? layout : undefined}\n        data-surface={layout === 'row' ? level : undefined}\n        className={mx(recipes.field(), classNames)}\n        ref={forwardedRef}\n      />\n    );\n  },\n);\n\nFieldRoot.displayName = 'Field.Root';\n\n//\n// Header\n//\n\ntype FieldHeaderProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & {\n  /** Overrides the field's size; by default the row shares it, so its actions share the control's end column. */\n  size?: Size;\n};\n\n/** The label row: a Label followed by optional trailing Icons or icon-only Buttons, aligned to the control's edges. */\nconst FieldHeader = forwardRef<HTMLDivElement, FieldHeaderProps>(({ classNames, size, ...props }, forwardedRef) => (\n  <div\n    {...props}\n    data-scope='field'\n    data-part='header'\n    data-size={size}\n    className={mx(recipes.fieldHeader(), classNames)}\n    ref={forwardedRef}\n  />\n));\n\nFieldHeader.displayName = 'Field.Header';\n\n//\n// Label\n//\n\ntype FieldLabelProps = ThemedClassName<FieldPrimitive.LabelProps> & {\n  /** Visually hidden but still names the control, like `srOnly` on a standalone label. */\n  srOnly?: boolean;\n};\n\n/**\n * Marks the part a label click focuses in a control whose labelled element is a hidden input (DateInput's first\n * segment, PinInput's first cell), since the browser cannot focus the hidden input the label points at.\n */\nconst LABEL_TARGET_ATTRIBUTE = 'data-label-target';\n\n/**\n * Names the control; while the root is `required` it ends with the required indicator, unless a\n * `RequiredIndicator` among its children places the mark itself.\n */\nconst FieldLabel = forwardRef<HTMLLabelElement, FieldLabelProps>(\n  ({ classNames, srOnly, onClick, children, ...props }, forwardedRef) => {\n    const field = useFieldContext();\n    const placed = Children.toArray(children).some(\n      (child) => isValidElement(child) && child.type === FieldRequiredIndicator,\n    );\n    return (\n      <FieldPrimitive.Label\n        {...props}\n        onClick={(event) => {\n          onClick?.(event);\n          const control = field && event.currentTarget.ownerDocument.getElementById(field.ids.control);\n          const target = control?.parentElement?.querySelector<HTMLElement>(`[${LABEL_TARGET_ATTRIBUTE}]`);\n          if (!event.defaultPrevented && target) {\n            event.preventDefault();\n            target.focus();\n          }\n        }}\n        data-sr-only={srOnly ? '' : undefined}\n        className={mx(recipes.label(), classNames)}\n        ref={forwardedRef}\n      >\n        {children}\n        {field?.required && !placed && <FieldRequiredIndicator />}\n      </FieldPrimitive.Label>\n    );\n  },\n);\n\nFieldLabel.displayName = 'Field.Label';\n\n//\n// RequiredIndicator\n//\n\ntype FieldRequiredIndicatorProps = ThemedClassName<FieldPrimitive.RequiredIndicatorProps>;\n\n/** Ark's mark for a `required` root (`*` by default); `Field.Label` renders one, so use this only to place it yourself. */\nconst FieldRequiredIndicator = forwardRef<HTMLSpanElement, FieldRequiredIndicatorProps>(\n  ({ classNames, ...props }, forwardedRef) => (\n    <FieldPrimitive.RequiredIndicator\n      aria-hidden\n      {...props}\n      className={mx(recipes.fieldRequired(), classNames)}\n      ref={forwardedRef}\n    />\n  ),\n);\n\nFieldRequiredIndicator.displayName = 'Field.RequiredIndicator';\n\n//\n// HelperText\n//\n\ntype FieldHelperTextProps = ThemedClassName<FieldPrimitive.HelperTextProps>;\n\nconst FieldHelperText = forwardRef<HTMLSpanElement, FieldHelperTextProps>(({ classNames, ...props }, forwardedRef) => (\n  <FieldPrimitive.HelperText {...props} className={mx(recipes.fieldHelper(), classNames)} ref={forwardedRef} />\n));\n\nFieldHelperText.displayName = 'Field.HelperText';\n\n//\n// ErrorText\n//\n\ntype FieldErrorTextProps = ThemedClassName<FieldPrimitive.ErrorTextProps>;\n\n/** Rendered only while the root is `invalid`. */\nconst FieldErrorText = forwardRef<HTMLSpanElement, FieldErrorTextProps>(({ classNames, ...props }, forwardedRef) => (\n  <FieldPrimitive.ErrorText {...props} className={mx(recipes.fieldError(), classNames)} ref={forwardedRef} />\n));\n\nFieldErrorText.displayName = 'Field.ErrorText';\nexport { LABEL_TARGET_ATTRIBUTE };\n\nexport type {\n  FieldErrorTextProps as ErrorTextProps,\n  FieldHeaderProps as HeaderProps,\n  FieldHelperTextProps as HelperTextProps,\n  FieldLabelProps as LabelProps,\n  FieldRequiredIndicatorProps as RequiredIndicatorProps,\n  FieldRootProps as RootProps,\n  FieldValence as Valence,\n};\n\nexport {\n  FieldErrorText as ErrorText,\n  FieldHeader as Header,\n  FieldHelperText as HelperText,\n  FieldLabel as Label,\n  FieldRequiredIndicator as RequiredIndicator,\n  FieldRoot as Root,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2CA,IAAM,YAAY,YACf,EAAE,YAAY,SAAS,mBAAmB,QAAQ,OAAO,MAAM,OAAO,GAAG,SAAS,iBAAiB;CAElG,MAAM,WAAW,mBAAmB;CACpC,MAAM,EAAE,OAAO,WAAW,GAAG,cAAc,eAAe,IAAI;CAC9D,OACE,oBAACA,MAAe,MAAhB;EACE,GAAI;EACJ,GAAI;EACJ,OAAO;GAAE,GAAG;GAAW,GAAG;EAAM;EAChC,SAAS,YAAY,sBAAsB,WAAW,UAAU;EAChE,gBAAc,sBAAsB,YAAY,KAAA,IAAY;EAC5D,eAAa,WAAW,QAAQ,SAAS,KAAA;EACzC,gBAAc,WAAW,QAAQ,QAAQ,KAAA;EACzC,WAAW,GAAG,QAAQ,MAAM,GAAG,UAAU;EACzC,KAAK;CACN,CAAA;AAEL,CACF;AAEA,UAAU,cAAc;;AAYxB,IAAM,cAAc,YAA8C,EAAE,YAAY,MAAM,GAAG,SAAS,iBAChG,oBAAC,OAAD;CACE,GAAI;CACJ,cAAW;CACX,aAAU;CACV,aAAW;CACX,WAAW,GAAG,QAAQ,YAAY,GAAG,UAAU;CAC/C,KAAK;AACN,CAAA,CACF;AAED,YAAY,cAAc;;;;;AAe1B,IAAM,yBAAyB;;;;;AAM/B,IAAM,aAAa,YAChB,EAAE,YAAY,QAAQ,SAAS,UAAU,GAAG,SAAS,iBAAiB;CACrE,MAAM,QAAQ,gBAAgB;CAC9B,MAAM,SAAS,SAAS,QAAQ,QAAQ,CAAC,CAAC,MACvC,UAAU,eA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