{"version":3,"names":["dynamic","createEffect","createMemo","omit","onCleanup","Show","untrack","useBaseUiId","useFieldRootContext","fieldStateAttrs","useFormContext","mergeRootProps","resolveClassStyle","useFieldMessagesContext","FieldError","props","field","form","messages","id","undefined","match","name","formError","n","errs","errors","e","rendered","m","v","validityData","state","Boolean","valid","source","Symbol","shown","registerMessageId","errorMessage","formErr","validity","hasSpecificMatch","clientMessage","length","map","message","error","Array","isArray","join","userStyling","userHtmlProps","internalProps","role","data-disabled","disabled","styledUserProps","merged","Tag","as","element","children","_item"],"sources":["field-error.tsx"],"sourcesContent":["import type { JSX, ValidComponent } from \"@solidjs/web\";\nimport { dynamic } from \"@solidjs/web\";\nimport {\n\tcreateEffect,\n\tcreateMemo,\n\tomit,\n\tonCleanup,\n\tShow,\n\tuntrack,\n} from \"solid-js\";\nimport { useBaseUiId } from \"../../internals/base-ui-id\";\nimport {\n\ttype FieldRootState,\n\ttype FieldValidityState,\n\tuseFieldRootContext,\n} from \"../../internals/field-context.ts\";\nimport { fieldStateAttrs } from \"../../internals/field-state-attrs.ts\";\nimport { useFormContext } from \"../../internals/form-context.ts\";\nimport { mergeRootProps } from \"../../internals/merge-root-props\";\nimport { resolveClassStyle } from \"../../internals/resolve-class-style\";\nimport type { BaseUIComponentProps } from \"../../internals/types\";\nimport { useFieldMessagesContext } from \"../field-messages-context.ts\";\n\nexport interface FieldErrorState extends FieldRootState {}\n\nexport interface FieldErrorProps\n\textends BaseUIComponentProps<\"div\", FieldErrorState> {\n\t/** Tag/component to render. Defaults to `\"div\"`. */\n\tas?: ValidComponent;\n\t/**\n\t * Determines whether to show the error message according to the field's\n\t * [ValidityState](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState).\n\t *\n\t * - `true` forces the error to render regardless of validity (lets external\n\t *   libraries drive visibility).\n\t * - A string picks a specific `ValidityState` key — the error renders only\n\t *   when that key is `true` in the field's validity snapshot.\n\t * - Omitted: render when the field has a `<Form>`-level error for its\n\t *   `name`, OR when the field's own validity has collapsed to `false`.\n\t */\n\tmatch?: boolean | keyof ValidityState | undefined;\n}\n\n/**\n * An error message displayed when the field control fails validation.\n * Renders a `<div role=\"alert\">` element (inline — the caller can override\n * via `render`).\n *\n * Conditionally rendered via `<Show>`: no DOM node is produced when the\n * field is valid (and no override match hits). The error id is registered\n * with the surrounding `<Field.Root>`'s message registry ONLY while the\n * element is actually rendered — unmounting cleans up `onCleanup` + the\n * `<Show>` block's tear-down.\n */\nexport function FieldError(props: FieldErrorProps): JSX.Element {\n\tconst field = useFieldRootContext();\n\tconst form = useFormContext();\n\tconst messages = useFieldMessagesContext();\n\n\t// Stable id for the error element. Shared across the mount/unmount cycles\n\t// triggered by `<Show>` — the registry is what tracks presence, the id\n\t// itself is fixed for the component's lifetime.\n\tconst id = useBaseUiId(\n\t\tuntrack(() => (typeof props.id === \"string\" ? props.id : undefined)),\n\t);\n\n\t// Accessor-friendly reads for `match` and `name` — any of these can drive\n\t// the `rendered` memo; reading them via accessors instead of at the top of\n\t// the component keeps Solid 2's STRICT_READ_UNTRACKED rule happy.\n\tconst match = (): FieldErrorProps[\"match\"] => props.match;\n\tconst name = (): string | undefined => field.name();\n\n\tconst formError = createMemo((): string | string[] | null => {\n\t\tconst n = name();\n\t\tif (!n) return null;\n\t\tconst errs = form.errors();\n\t\tconst e = errs[n];\n\t\treturn e === undefined ? null : e;\n\t});\n\n\tconst rendered = createMemo((): boolean => {\n\t\tconst m = match();\n\t\tif (m === true) return true;\n\t\tif (typeof m === \"string\") {\n\t\t\tconst v = field.validityData().state as FieldValidityState;\n\t\t\treturn Boolean(v[m as keyof FieldValidityState]);\n\t\t}\n\t\tif (formError() !== null) return true;\n\t\treturn field.validityData().state.valid === false;\n\t});\n\n\t// Track the rendered-state transition and register/unregister the id with\n\t// the message registry accordingly. The registration is what makes the\n\t// control's `aria-describedby` pick us up.\n\t//\n\t// A split `createEffect(compute, apply)` is the right Solid 2 primitive:\n\t// the compute phase observes `rendered()` (tracked); the apply phase\n\t// writes into the registry (side effect, unowned scope, safe). Using\n\t// `onCleanup` in the apply is legal — it's unowned and the cleanup fires\n\t// on the NEXT apply OR on owner disposal.\n\tconst source = Symbol(\"field-error\");\n\tcreateEffect(\n\t\t() => rendered(),\n\t\t(shown) => {\n\t\t\tif (shown) {\n\t\t\t\tmessages.registerMessageId(source, id);\n\t\t\t\treturn () => {\n\t\t\t\t\tmessages.registerMessageId(source, undefined);\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t);\n\t// Extra safety: also unregister on root disposal. (The split-effect\n\t// cleanup already handles the \"rendered → not rendered\" transition; this\n\t// catches the \"still rendered on disposal\" case.)\n\tonCleanup(() => {\n\t\tmessages.registerMessageId(source, undefined);\n\t});\n\n\tconst errorMessage = createMemo((): JSX.Element => {\n\t\tconst m = match();\n\t\tconst formErr = formError();\n\t\tconst validity = field.validityData();\n\n\t\tconst hasSpecificMatch = typeof m === \"string\";\n\t\tconst clientMessage: JSX.Element =\n\t\t\tvalidity.errors.length > 1 ? (\n\t\t\t\t<ul>\n\t\t\t\t\t{validity.errors.map((message) => (\n\t\t\t\t\t\t<li>{message}</li>\n\t\t\t\t\t))}\n\t\t\t\t</ul>\n\t\t\t) : (\n\t\t\t\tvalidity.error\n\t\t\t);\n\n\t\tif (hasSpecificMatch) return clientMessage;\n\t\tif (formErr != null) {\n\t\t\t// `formErr` may be string or string[]; match React: join arrays\n\t\t\t// with a newline (the consumer typically only renders the first,\n\t\t\t// but we surface the whole thing).\n\t\t\treturn Array.isArray(formErr) ? formErr.join(\"\\n\") : formErr;\n\t\t}\n\t\treturn clientMessage;\n\t});\n\n\tconst userStyling = resolveClassStyle(props, () => field.state());\n\n\tconst userHtmlProps = omit(\n\t\tprops,\n\t\t\"class\",\n\t\t\"style\",\n\t\t\"attrs\",\n\t\t\"as\",\n\t\t\"id\",\n\t\t\"match\",\n\t\t\"children\",\n\t) as Record<string, unknown>;\n\n\tconst internalProps = mergeRootProps(fieldStateAttrs(field.state), {\n\t\tid,\n\t\trole: \"alert\" as const,\n\t\tget \"data-disabled\"(): \"\" | undefined {\n\t\t\treturn field.state().disabled ? \"\" : undefined;\n\t\t},\n\t});\n\n\tconst styledUserProps = mergeRootProps(userStyling, userHtmlProps);\n\n\tconst merged = mergeRootProps(internalProps, styledUserProps);\n\n\tconst Tag = dynamic(() => props.as ?? \"div\");\n\tconst element = (): JSX.Element => (\n\t\t<Tag {...merged}>{props.children ?? errorMessage()}</Tag>\n\t);\n\n\treturn <Show when={rendered()}>{(_item) => element()}</Show>;\n}\n"],"mappings":"AACA,SAASA,OAAO,QAAQ,cAAc;AACtC,SACCC,YAAY,EACZC,UAAU,EACVC,IAAI,EACJC,SAAS,EACTC,IAAI,EACJC,OAAO,QACD,UAAU;AACjB,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAGCC,mBAAmB,QACb,kCAAkC;AACzC,SAASC,eAAe,QAAQ,sCAAsC;AACtE,SAASC,cAAc,QAAQ,iCAAiC;AAChE,SAASC,cAAc,QAAQ,kCAAkC;AACjE,SAASC,iBAAiB,QAAQ,qCAAqC;AAEvE,SAASC,uBAAuB,QAAQ,8BAA8B;AAsBtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,KAAsB,EAAe;EAC/D,MAAMC,KAAK,GAAGR,mBAAmB,CAAC,CAAC;EACnC,MAAMS,IAAI,GAAGP,cAAc,CAAC,CAAC;EAC7B,MAAMQ,QAAQ,GAAGL,uBAAuB,CAAC,CAAC;;EAE1C;EACA;EACA;EACA,MAAMM,EAAE,GAAGZ,WAAW,CACrBD,OAAO,CAAC,MAAO,OAAOS,KAAK,CAACI,EAAE,KAAK,QAAQ,GAAGJ,KAAK,CAACI,EAAE,GAAGC,SAAU,CACpE,CAAC;;EAED;EACA;EACA;EACA,MAAMC,KAAK,GAAGA,CAAA,KAAgCN,KAAK,CAACM,KAAK;EACzD,MAAMC,IAAI,GAAGA,CAAA,KAA0BN,KAAK,CAACM,IAA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