@10x-media/fields 0.1.0-beta.7 → 0.1.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -21
- package/dist/exports/client.d.ts +7 -1
- package/dist/exports/client.js +6 -1
- package/dist/exports/phone-utils.d.ts +4 -0
- package/dist/exports/phone-utils.js +4 -0
- package/dist/exports/phone.d.ts +6 -0
- package/dist/exports/phone.js +3 -0
- package/dist/exports/rsc.d.ts +3 -1
- package/dist/exports/rsc.js +3 -1
- package/dist/exports/types.d.ts +3 -2
- package/dist/fields/color/client/ColorField.d.ts +2 -0
- package/dist/fields/color/client/ColorField.js +34 -337
- package/dist/fields/color/client/ColorField.js.map +1 -1
- package/dist/fields/color/client/ColorInput.d.ts +44 -0
- package/dist/fields/color/client/ColorInput.js +374 -0
- package/dist/fields/color/client/ColorInput.js.map +1 -0
- package/dist/fields/color/valueIssue.js +23 -0
- package/dist/fields/color/valueIssue.js.map +1 -0
- package/dist/fields/icon/rsc/IconFieldServer.js +1 -1
- package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
- package/dist/fields/icon/shared/iconLabel.js +1 -1
- package/dist/fields/icon/shared/iconLabel.js.map +1 -1
- package/dist/fields/measurement/client/MeasurementField.d.ts +2 -0
- package/dist/fields/measurement/client/MeasurementField.js +29 -345
- package/dist/fields/measurement/client/MeasurementField.js.map +1 -1
- package/dist/fields/measurement/client/MeasurementInput.d.ts +42 -0
- package/dist/fields/measurement/client/MeasurementInput.js +327 -0
- package/dist/fields/measurement/client/MeasurementInput.js.map +1 -0
- package/dist/fields/measurement/client/useMeasurementModel.d.ts +19 -0
- package/dist/fields/measurement/client/useMeasurementModel.js +85 -0
- package/dist/fields/measurement/client/useMeasurementModel.js.map +1 -0
- package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
- package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
- package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
- package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
- package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
- package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
- package/dist/fields/phoneNumber/client/editModel.js +86 -0
- package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
- package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
- package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
- package/dist/fields/phoneNumber/engine/countries.js +68 -0
- package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
- package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
- package/dist/fields/phoneNumber/engine/draft.js +72 -0
- package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
- package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
- package/dist/fields/phoneNumber/engine/metadata.js +32 -0
- package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
- package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
- package/dist/fields/phoneNumber/engine/phone.js +59 -0
- package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
- package/dist/fields/phoneNumber/options.d.ts +72 -0
- package/dist/fields/phoneNumber/options.js +37 -0
- package/dist/fields/phoneNumber/options.js.map +1 -0
- package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
- package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
- package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
- package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
- package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
- package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
- package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
- package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
- package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -1
- package/dist/translations/ar.js +9 -1
- package/dist/translations/ar.js.map +1 -1
- package/dist/translations/de.js +9 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +9 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +9 -1
- package/dist/translations/es.js.map +1 -1
- package/dist/translations/fr.js +9 -1
- package/dist/translations/fr.js.map +1 -1
- package/dist/translations/id.js +9 -1
- package/dist/translations/id.js.map +1 -1
- package/dist/translations/keys.d.ts +8 -0
- package/dist/translations/keys.js +9 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +9 -1
- package/dist/translations/ko.js.map +1 -1
- package/dist/translations/pt.js +9 -1
- package/dist/translations/pt.js.map +1 -1
- package/dist/translations/ru.js +9 -1
- package/dist/translations/ru.js.map +1 -1
- package/dist/translations/uk.js +9 -1
- package/dist/translations/uk.js.map +1 -1
- package/dist/translations/zh.js +9 -1
- package/dist/translations/zh.js.map +1 -1
- package/dist/types.d.ts +22 -1
- package/dist/utils/resolveStaticLabel.js +13 -0
- package/dist/utils/resolveStaticLabel.js.map +1 -0
- package/package.json +16 -4
- package/dist/fields/icon/shared/resolveStaticLabel.js +0 -16
- package/dist/fields/icon/shared/resolveStaticLabel.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorField.js","names":["useTranslation"],"sources":["../../../../src/fields/color/client/ColorField.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n\tuseField,\n\tXIcon,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps, Validate } from 'payload'\nimport { text } from 'payload/shared'\nimport type React from 'react'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { resolveCommitValue } from '../commitValue'\nimport {\n\tformatColor,\n\tisColorSchemeValue,\n\tparseColor,\n\trgbToHsv,\n\tsalvageColor,\n\ttoRgb,\n} from '../engine'\nimport { type ColorFieldClientOptions, PRESET_PREFIX, type ResolvedColorPreset } from '../options'\nimport { derivePresetChip } from '../presetChip'\nimport {\n\tapplyReferenceAlpha,\n\tformatPresetReference,\n\tparsePresetReference,\n\tpresetReferenceIssue,\n\tpresetReferenceParts,\n} from '../presetReference'\nimport { flatValue, swatchBackground } from '../schemeValue'\nimport { ColorPickerPanel, type Hsva } from './ColorPickerPanel'\nimport './colorField.css'\n\nconst baseClass = 'fields-color'\n\nexport type ColorFieldProps = {\n\tcolorOptions: ColorFieldClientOptions\n\tpresetsLabel?: string\n\tresolvedPresets?: ResolvedColorPreset[]\n} & TextFieldClientProps\n\nexport const ColorField: React.FC<ColorFieldProps> = (props) => {\n\tconst {\n\t\tcolorOptions,\n\t\tfield,\n\t\tfield: {\n\t\t\tadmin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},\n\t\t\tlabel,\n\t\t\tlocalized,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tpath: pathFromProps,\n\t\tpresetsLabel,\n\t\treadOnly: readOnlyFromProps,\n\t\tresolvedPresets = [],\n\t} = props\n\tconst { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = colorOptions\n\tconst { t } = useTranslation()\n\n\tconst memoizedValidate = useCallback<Validate<string>>(\n\t\t(value, options) => {\n\t\t\tif (typeof value === 'string' && value !== '') {\n\t\t\t\tif (linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\t\tconst hasKey =\n\t\t\t\t\t\tresolvedPresets.length > 0\n\t\t\t\t\t\t\t? (key: string) => resolvedPresets.some((preset) => preset.key === key)\n\t\t\t\t\t\t\t: null\n\t\t\t\t\tconst issue = presetReferenceIssue(value, hasKey)\n\t\t\t\t\tif (issue === 'invalidAlpha') return t(keys.invalidColor)\n\t\t\t\t\tif (issue !== null) return t(keys.missingPreset)\n\t\t\t\t} else if (!parseColor(value)) {\n\t\t\t\t\treturn t(keys.invalidColor)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn text(value, { ...options, name, required, type: 'text' })\n\t\t},\n\t\t[linked, name, required, resolvedPresets, t]\n\t)\n\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps, validate: memoizedValidate })\n\n\t// renderField only maps permissions into the readOnly clientProp; admin.readOnly\n\t// reaches custom Field components solely via clientField.admin (native fields get\n\t// it merged client-side in RenderFields, a path custom components bypass)\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\n\tconst stringValue = typeof value === 'string' ? value : ''\n\tconst reference = linked ? parsePresetReference(stringValue) : null\n\tconst presetKey = reference?.key ?? null\n\t// With alpha disabled a stored suffix still parses, but renders at full\n\t// opacity so the field matches server resolution until commit strips it\n\tconst referenceAlpha = alpha ? (reference?.alpha ?? 100) : 100\n\tconst activePreset =\n\t\tpresetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : undefined\n\tconst presetMissing = presetKey !== null && !activePreset\n\tconst rawValue: unknown =\n\t\tpresetKey !== null ? (activePreset?.value ?? linkedFallback) : stringValue || null\n\tconst cssValue = flatValue(rawValue)\n\tconst parsed = useMemo(() => (cssValue ? parseColor(cssValue) : null), [cssValue])\n\n\tconst [displayFormat, setDisplayFormat] = useState<ColorFormat>(format)\n\tconst displayValue = useMemo(() => {\n\t\tif (presetKey !== null || !parsed || displayFormat === format) return stringValue\n\t\treturn formatColor(parsed, displayFormat, { alpha })\n\t}, [alpha, displayFormat, format, parsed, presetKey, stringValue])\n\n\tconst [draft, setDraft] = useState(displayValue)\n\tconst editingRef = useRef(false)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) setDraft(displayValue)\n\t}, [displayValue])\n\n\t// Typing dismisses the chip into plain text entry; blur re-derives it from the committed value\n\tconst [chipDismissed, setChipDismissed] = useState(false)\n\tconst chip = useMemo(\n\t\t() =>\n\t\t\tderivePresetChip({\n\t\t\t\tediting: chipDismissed,\n\t\t\t\tlinked,\n\t\t\t\tpresets: resolvedPresets,\n\t\t\t\tvalue: stringValue,\n\t\t\t}),\n\t\t[chipDismissed, linked, resolvedPresets, stringValue]\n\t)\n\n\tconst debounceRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// Revert target for non-clearable commits; tracked from committed values so\n\t// picker commits, preset picks, and the initially loaded value all count\n\tconst lastValidRef = useRef<null | string>(null)\n\tuseEffect(() => {\n\t\tif (stringValue === '') return\n\t\tif (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue\n\t}, [presetKey, stringValue])\n\n\t// Commits to the form without touching editingRef: the debounced path must not let the draft resync mid-typing.\n\t// Returns true when a non-clearable empty or unparseable draft was reverted to the last valid value.\n\tconst commitText = useCallback(\n\t\t(raw: string): boolean => {\n\t\t\tlet normalized: null | string = null\n\t\t\tif (linked && raw.startsWith(PRESET_PREFIX)) {\n\t\t\t\tconst parts = presetReferenceParts(raw)\n\t\t\t\t// Canonical form: /100 collapses to the bare reference, and a disabled\n\t\t\t\t// alpha channel strips any hand-typed suffix. Empty keys commit raw so\n\t\t\t\t// validation surfaces the missing-preset error.\n\t\t\t\tif (parts) normalized = formatPresetReference(parts.key, alpha ? parts.alpha : 100)\n\t\t\t\telse if (raw.length > PRESET_PREFIX.length) normalized = raw\n\t\t\t} else {\n\t\t\t\tconst parsedRaw = parseColor(raw)\n\t\t\t\t// Unparseable input commits raw so validation surfaces the error\n\t\t\t\tif (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha })\n\t\t\t}\n\t\t\tconst resolution = resolveCommitValue({\n\t\t\t\tdraft: raw,\n\t\t\t\tisClearable,\n\t\t\t\tlastValid: lastValidRef.current,\n\t\t\t\tparsed: normalized,\n\t\t\t})\n\t\t\tlastValidRef.current = resolution.lastValid\n\t\t\tsetValue(resolution.value)\n\t\t\treturn resolution.reverted\n\t\t},\n\t\t[alpha, format, isClearable, linked, setValue]\n\t)\n\n\tconst onTextChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst raw = event.target.value\n\t\t\teditingRef.current = true\n\t\t\tsetChipDismissed(true)\n\t\t\tsetDraft(raw)\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = setTimeout(() => commitText(raw), 250)\n\t\t},\n\t\t[commitText]\n\t)\n\n\tconst onTextBlur = useCallback(() => {\n\t\tif (debounceRef.current) {\n\t\t\tclearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = null\n\t\t}\n\t\tif (editingRef.current) {\n\t\t\teditingRef.current = false\n\t\t\t// Blur-only salvage: recover the first valid color from dirty input\n\t\t\t// (double pastes, stray junk) before the normal commit pipeline\n\t\t\tconst isPresetDraft = linked && draft.startsWith(PRESET_PREFIX)\n\t\t\tconst salvaged =\n\t\t\t\t!isPresetDraft && draft.trim() !== '' && !parseColor(draft) ? salvageColor(draft) : null\n\t\t\tif (commitText(salvaged ?? draft)) {\n\t\t\t\t// A reverted commit usually leaves the form value unchanged, so the\n\t\t\t\t// displayValue resync effect never fires; restore the draft here\n\t\t\t\tsetDraft(displayValue)\n\t\t\t} else if (salvaged !== null) {\n\t\t\t\t// A salvaged commit can store the same value as before (double paste of\n\t\t\t\t// the current color), which also skips the resync; clean the draft here\n\t\t\t\tconst parsedSalvaged = parseColor(salvaged)\n\t\t\t\tsetDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged)\n\t\t\t}\n\t\t}\n\t\tsetChipDismissed(false)\n\t}, [alpha, commitText, displayFormat, displayValue, draft, linked])\n\n\t// Backspace/Delete on the empty chip input never fires a change event, so clear here\n\tconst onTextKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\tif (!chip || isReadOnly) return\n\t\t\tif (event.key === 'Backspace' || event.key === 'Delete') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tsetDraft('')\n\t\t\t\tif (isClearable) {\n\t\t\t\t\tsetValue(null)\n\t\t\t\t} else {\n\t\t\t\t\t// Keep the stored ref; the emptied draft reverts or gets replaced at commit\n\t\t\t\t\teditingRef.current = true\n\t\t\t\t\tsetChipDismissed(true)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[chip, isClearable, isReadOnly, setValue]\n\t)\n\n\tconst commitCss = useCallback(\n\t\t(css: string) => {\n\t\t\tconst parsedCss = parseColor(css)\n\t\t\tif (parsedCss) setValue(formatColor(parsedCss, format, { alpha }))\n\t\t},\n\t\t[alpha, format, setValue]\n\t)\n\n\t// With a reference active the slider represents the reference alpha, not the\n\t// resolved color's own channel, so returning it to 100 restores the bare ref\n\tconst initialHsva = useMemo<Hsva | null>(() => {\n\t\tif (!parsed) return null\n\t\tconst rgb = toRgb(parsed)\n\t\tconst hsv = rgbToHsv(rgb)\n\t\treturn {\n\t\t\ta: presetKey !== null ? referenceAlpha / 100 : rgb.alpha,\n\t\t\th: hsv.h,\n\t\t\ts: hsv.s,\n\t\t\tv: hsv.v,\n\t\t}\n\t}, [parsed, presetKey, referenceAlpha])\n\n\tconst commitReferenceAlpha = useCallback(\n\t\t(alpha100: number) => {\n\t\t\tif (presetKey === null) return\n\t\t\tsetValue(formatPresetReference(presetKey, alpha100))\n\t\t},\n\t\t[presetKey, setValue]\n\t)\n\n\t// The fade must track real overflow, not chip presence: the badge always hugs\n\t// the content run's right edge (the input's flex-grow pushes it there), so an\n\t// unconditional mask would fade it even in a full-width field with room to spare\n\tconst contentRef = useRef<HTMLDivElement>(null)\n\tconst [contentClipped, setContentClipped] = useState(false)\n\tconst measureClip = useCallback(() => {\n\t\tconst el = contentRef.current\n\t\t// +1 absorbs subpixel rounding between scrollWidth (int) and clientWidth\n\t\tif (el) setContentClipped(el.scrollWidth > el.clientWidth + 1)\n\t}, [])\n\t// No dependency array on purpose: chip mount and label changes alter\n\t// scrollWidth without resizing the observed box, so re-measure every render\n\tuseEffect(measureClip)\n\tuseEffect(() => {\n\t\tconst el = contentRef.current\n\t\tif (!el) return\n\t\tconst observer = new ResizeObserver(measureClip)\n\t\tobserver.observe(el)\n\t\treturn () => observer.disconnect()\n\t}, [measureClip])\n\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\tconst swatchValue =\n\t\treferenceAlpha !== 100 && (typeof rawValue === 'string' || isColorSchemeValue(rawValue))\n\t\t\t? applyReferenceAlpha(rawValue, referenceAlpha, 'rgb')\n\t\t\t: rawValue\n\tconst swatchCss = swatchBackground(swatchValue)\n\n\tconst swatch = (\n\t\t<span className={`${baseClass}__swatch ${baseClass}__checker`}>\n\t\t\t{swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} style={{ background: swatchCss }} />\n\t\t\t) : null}\n\t\t\t{presetMissing && !swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} data-missing=\"true\" />\n\t\t\t) : null}\n\t\t\t{isReadOnly ? null : <span className={`${baseClass}__sr-only`}>{t(keys.pickColor)}</span>}\n\t\t</span>\n\t)\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\tshowError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={styles}\n\t\t>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel label={label} localized={localized} path={path} required={required} />\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div className={`${baseClass}__container`}>\n\t\t\t\t\t{isReadOnly ? (\n\t\t\t\t\t\t<span className={`${baseClass}__swatch-button ${baseClass}__swatch-button--static`}>\n\t\t\t\t\t\t\t{swatch}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Popup\n\t\t\t\t\t\t\tbutton={swatch}\n\t\t\t\t\t\t\tbuttonClassName={`${baseClass}__swatch-button`}\n\t\t\t\t\t\t\tbuttonType=\"custom\"\n\t\t\t\t\t\t\tcaret={false}\n\t\t\t\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\t\t\t\thorizontalAlign=\"left\"\n\t\t\t\t\t\t\trender={({ close }) => (\n\t\t\t\t\t\t\t\t<ColorPickerPanel\n\t\t\t\t\t\t\t\t\tactiveReference={reference}\n\t\t\t\t\t\t\t\t\talphaEnabled={alpha}\n\t\t\t\t\t\t\t\t\tclose={close}\n\t\t\t\t\t\t\t\t\tdisplayFormat={displayFormat}\n\t\t\t\t\t\t\t\t\tenableEyedropper={enableEyedropper}\n\t\t\t\t\t\t\t\t\tinitial={initialHsva}\n\t\t\t\t\t\t\t\t\tonPickAlpha={commitReferenceAlpha}\n\t\t\t\t\t\t\t\t\tonPickCss={commitCss}\n\t\t\t\t\t\t\t\t\tonPickPreset={(preset) => {\n\t\t\t\t\t\t\t\t\t\tif (linked) setValue(`${PRESET_PREFIX}${preset.key}`)\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t// A text column holds one color, so a scheme preset stores its light member\n\t\t\t\t\t\t\t\t\t\t\tconst flat = flatValue(preset.value)\n\t\t\t\t\t\t\t\t\t\t\tif (flat) commitCss(flat)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\tpresetMissing={presetMissing}\n\t\t\t\t\t\t\t\t\tpresets={resolvedPresets}\n\t\t\t\t\t\t\t\t\tpresetsLabel={presetsLabel ?? t(keys.presets)}\n\t\t\t\t\t\t\t\t\tsetDisplayFormat={setDisplayFormat}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tsize=\"fit-content\"\n\t\t\t\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={[`${baseClass}__content`, contentClipped && `${baseClass}__content--fade`]\n\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t.join(' ')}\n\t\t\t\t\t\tref={contentRef}\n\t\t\t\t\t>\n\t\t\t\t\t\t{chip ? (\n\t\t\t\t\t\t\t<span className={`${baseClass}__chip`}>\n\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-swatch ${baseClass}__checker`}>\n\t\t\t\t\t\t\t\t\t{swatchCss ? (\n\t\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__chip-color`}\n\t\t\t\t\t\t\t\t\t\t\tstyle={{ background: swatchCss }}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t{chip.missing && !swatchCss ? (\n\t\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-color`} data-missing=\"true\" />\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-label`}>{chip.label}</span>\n\t\t\t\t\t\t\t\t{alpha && chip.alpha !== 100 ? (\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-alpha`}>{chip.alpha}%</span>\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\tid={`field-${path?.replace(/\\./g, '__')}`}\n\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\tonBlur={onTextBlur}\n\t\t\t\t\t\t\tonChange={onTextChange}\n\t\t\t\t\t\t\tonKeyDown={onTextKeyDown}\n\t\t\t\t\t\t\tplaceholder={chip || typeof placeholder !== 'string' ? undefined : placeholder}\n\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\tvalue={chip ? '' : draft}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__badge`}>\n\t\t\t\t\t\t\t{chip ? t(keys.preset) : displayFormat}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t{isClearable && !required && !isReadOnly && stringValue !== '' ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearColor)}\n\t\t\t\t\t\t\tclassName={`${baseClass}__clear`}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetDraft('')\n\t\t\t\t\t\t\t\tsetValue(null)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<XIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,YAAY;AAQlB,MAAa,cAAyC,UAAU;CAC/D,MAAM,EACL,cACA,OACA,OAAO,EACN,OAAO,EAAE,WAAW,aAAa,aAAa,UAAU,sBAAsB,CAAC,GAC/E,OACA,WACA,MACA,YAED,MAAM,eACN,cACA,UAAU,mBACV,kBAAkB,CAAC,MAChB;CACJ,MAAM,EAAE,OAAO,kBAAkB,QAAQ,aAAa,QAAQ,mBAAmB;CACjF,MAAM,EAAE,MAAMA,iBAAe;CAsB7B,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB;EAAE,sBAAsB;EAAe,UA3BnC,aACvB,OAAO,YAAY;GACnB,IAAI,OAAO,UAAU,YAAY,UAAU;QACtC,UAAU,MAAM,WAAA,SAAwB,GAAG;KAK9C,MAAM,QAAQ,qBAAqB,OAHlC,gBAAgB,SAAS,KACrB,QAAgB,gBAAgB,MAAM,WAAW,OAAO,QAAQ,GAAG,IACpE,IAC4C;KAChD,IAAI,UAAU,gBAAgB,OAAO,EAAE,KAAK,YAAY;KACxD,IAAI,UAAU,MAAM,OAAO,EAAE,KAAK,aAAa;IAChD,OAAO,IAAI,CAAC,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ACC;;UACN,oBAAC,QAAD;WAAM,WAAW,GAAG,UAAU;qBAAgB,KAAK;UAAY,CAAA;UAC9D,SAAS,KAAK,UAAU,MACxB,qBAAC,QAAD;WAAM,WAAW,GAAG,UAAU;qBAA9B,CAA8C,KAAK,OAAM,GAAO;eAC7D;SACC;aACH;QACJ,oBAAC,SAAD;SACC,WAAW,GAAG,UAAU;SACxB,IAAI,SAAS,MAAM,QAAQ,OAAO,IAAI;SACtC,MAAM;SACN,QAAQ;SACR,UAAU;SACV,WAAW;SACX,aAAa,QAAQ,OAAO,gBAAgB,WAAW,KAAA,IAAY;SACnE,UAAU;SACV,MAAK;SACL,OAAO,OAAO,KAAK;QACnB,CAAA;QACD,oBAAC,QAAD;SAAM,eAAY;SAAO,WAAW,GAAG,UAAU;mBAC/C,OAAO,EAAE,KAAK,MAAM,IAAI;QACpB,CAAA;OACF;;MACJ,eAAe,CAAC,YAAY,CAAC,cAAc,gBAAgB,KAC3D,oBAAC,UAAD;OACC,cAAY,EAAE,KAAK,UAAU;OAC7B,WAAW,GAAG,UAAU;OACxB,eAAe;QACd,SAAS,EAAE;QACX,SAAS,IAAI;OACd;OACA,MAAK;iBAEL,oBAAC,OAAD,CAAQ,CAAA;MACD,CAAA,IACL;KACA;;IACJ;IACD,oBAAC,uBAAD;KACC,iBAAiB;KACjB,UAAU,oBAAC,kBAAD;MAA+B;MAAmB;KAAO,CAAA;IACnE,CAAA;GACG;IACD;;AAEP"}
|
|
1
|
+
{"version":3,"file":"ColorField.js","names":["useTranslation"],"sources":["../../../../src/fields/color/client/ColorField.tsx"],"sourcesContent":["'use client'\nimport { useField } from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps, Validate } from 'payload'\nimport { text } from 'payload/shared'\nimport type React from 'react'\nimport { useCallback, useMemo } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFieldClientOptions, ResolvedColorPreset } from '../options'\nimport { colorValueIssue } from '../valueIssue'\nimport { ColorInput } from './ColorInput'\n\nconst NO_PRESETS: ResolvedColorPreset[] = []\n\nexport type ColorFieldProps = {\n\tcolorOptions: ColorFieldClientOptions\n\tpresetsLabel?: string\n\tresolvedPresets?: ResolvedColorPreset[]\n} & TextFieldClientProps\n\n/** `ColorInput` bound to the document form through `useField`, with the field's validation. */\nexport const ColorField: React.FC<ColorFieldProps> = (props) => {\n\tconst {\n\t\tcolorOptions,\n\t\tfield,\n\t\tfield: {\n\t\t\tadmin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},\n\t\t\tlabel,\n\t\t\tlocalized,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tpath: pathFromProps,\n\t\tpresetsLabel,\n\t\treadOnly: readOnlyFromProps,\n\t\tresolvedPresets = NO_PRESETS,\n\t} = props\n\tconst { linked } = colorOptions\n\tconst { t } = useTranslation()\n\n\tconst memoizedValidate = useCallback<Validate<string>>(\n\t\t(value, options) => {\n\t\t\tconst issue = colorValueIssue(value, { linked, presets: resolvedPresets })\n\t\t\tif (issue) return t(keys[issue])\n\t\t\treturn text(value, { ...options, name, required, type: 'text' })\n\t\t},\n\t\t[linked, name, required, resolvedPresets, t]\n\t)\n\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps, validate: memoizedValidate })\n\n\t// renderField only maps permissions into the readOnly clientProp; admin.readOnly\n\t// reaches custom Field components solely via clientField.admin (native fields get\n\t// it merged client-side in RenderFields, a path custom components bypass)\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\treturn (\n\t\t<ColorInput\n\t\t\tAfterInput={AfterInput}\n\t\t\tBeforeInput={BeforeInput}\n\t\t\tclassName={className}\n\t\t\tDescription={Description}\n\t\t\tdescription={description}\n\t\t\tError={ErrorComponent}\n\t\t\tLabel={Label}\n\t\t\tlabel={label}\n\t\t\tlocalized={localized}\n\t\t\tonChange={setValue}\n\t\t\toptions={colorOptions}\n\t\t\tpath={path}\n\t\t\tplaceholder={typeof placeholder === 'string' ? placeholder : undefined}\n\t\t\tpresets={resolvedPresets}\n\t\t\tpresetsLabel={presetsLabel}\n\t\t\treadOnly={isReadOnly}\n\t\t\trequired={required}\n\t\t\tshowError={showError}\n\t\t\tstyle={styles}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,aAAoC,CAAC;;AAS3C,MAAa,cAAyC,UAAU;CAC/D,MAAM,EACL,cACA,OACA,OAAO,EACN,OAAO,EAAE,WAAW,aAAa,aAAa,UAAU,sBAAsB,CAAC,GAC/E,OACA,WACA,MACA,YAED,MAAM,eACN,cACA,UAAU,mBACV,kBAAkB,eACf;CACJ,MAAM,EAAE,WAAW;CACnB,MAAM,EAAE,MAAMA,iBAAe;CAW7B,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB;EAAE,sBAAsB;EAAe,UAhBnC,aACvB,OAAO,YAAY;GACnB,MAAM,QAAQ,gBAAgB,OAAO;IAAE;IAAQ,SAAS;GAAgB,CAAC;GACzE,IAAI,OAAO,OAAO,EAAE,KAAK,MAAM;GAC/B,OAAO,KAAK,OAAO;IAAE,GAAG;IAAS;IAAM;IAAU,MAAM;GAAO,CAAC;EAChE,GACA;GAAC;GAAQ;GAAM;GAAU;GAAiB;EAAC,CAUyC;CAAE,CAAC;CAKxF,MAAM,aAAa,QAAQ,qBAAqB,YAAY,iBAAiB;CAC7E,MAAM,SAAS,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE7D,OACC,oBAAC,YAAD;EACa;EACC;EACF;EACE;EACA;EACb,OAAO;EACA;EACA;EACI;EACX,UAAU;EACV,SAAS;EACH;EACN,aAAa,OAAO,gBAAgB,WAAW,cAAc,KAAA;EAC7D,SAAS;EACK;EACd,UAAU;EACA;EACC;EACX,OAAO;EACA;CACP,CAAA;AAEH"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ColorFieldClientOptions, ResolvedColorPreset } from "../options.js";
|
|
2
|
+
import { StaticDescription, StaticLabel } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
//#region src/fields/color/client/ColorInput.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Props for the form-free color input. `value` and `onChange` carry the stored string
|
|
7
|
+
* exactly as `colorField` would persist it: normalized to `options.format` on commit,
|
|
8
|
+
* or a `preset:<key>` reference when `options.linked` is on.
|
|
9
|
+
*/
|
|
10
|
+
type ColorInputProps = {
|
|
11
|
+
value: null | string | undefined; /** Fires at commit boundaries (debounced typing, blur, picker, preset, clear), never per keystroke. */
|
|
12
|
+
onChange: (value: null | string) => void; /** Any option left out takes `colorField`'s default (hex, alpha on, clearable, eyedropper, unlinked). */
|
|
13
|
+
options?: Partial<ColorFieldClientOptions>; /** Already resolved presets; labels are plain strings in the viewer's language. */
|
|
14
|
+
presets?: ResolvedColorPreset[];
|
|
15
|
+
presetsLabel?: string; /** Names the input (`id`, `name`, label `htmlFor`), as on a native field. */
|
|
16
|
+
path?: string;
|
|
17
|
+
label?: StaticLabel;
|
|
18
|
+
description?: StaticDescription;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
localized?: boolean;
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Message shown in the error tooltip. Left unset, the input reports its own
|
|
25
|
+
* malformed-color and missing-preset errors.
|
|
26
|
+
*/
|
|
27
|
+
error?: string; /** Forces the error state on or off. Left unset, it follows `error` and the input's own check. */
|
|
28
|
+
showError?: boolean;
|
|
29
|
+
className?: string;
|
|
30
|
+
style?: React.CSSProperties;
|
|
31
|
+
Label?: React.ReactNode;
|
|
32
|
+
Error?: React.ReactNode;
|
|
33
|
+
Description?: React.ReactNode;
|
|
34
|
+
BeforeInput?: React.ReactNode;
|
|
35
|
+
AfterInput?: React.ReactNode;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The color field's row, picker, preset chip and commit pipeline with no form behind
|
|
39
|
+
* it, for custom admin views and components. `ColorField` is this plus `useField`.
|
|
40
|
+
*/
|
|
41
|
+
declare const ColorInput: React.FC<ColorInputProps>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { ColorInput, ColorInputProps };
|
|
44
|
+
//# sourceMappingURL=ColorInput.d.ts.map
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../../../translations/keys.js";
|
|
3
|
+
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
+
import { rgbToHsv, toRgb } from "../engine/convert.js";
|
|
5
|
+
import { parseColor } from "../engine/parse.js";
|
|
6
|
+
import { formatColor } from "../engine/format.js";
|
|
7
|
+
import { salvageColor } from "../engine/salvage.js";
|
|
8
|
+
import { isColorSchemeValue } from "../engine/scheme.js";
|
|
9
|
+
import { PRESET_PREFIX } from "../options.js";
|
|
10
|
+
import { applyReferenceAlpha, formatPresetReference, parsePresetReference, presetReferenceParts } from "../presetReference.js";
|
|
11
|
+
import { colorValueIssue } from "../valueIssue.js";
|
|
12
|
+
import { resolveCommitValue } from "../commitValue.js";
|
|
13
|
+
import { derivePresetChip } from "../presetChip.js";
|
|
14
|
+
import { flatValue, swatchBackground } from "../schemeValue.js";
|
|
15
|
+
import { ColorPickerPanel } from "./ColorPickerPanel.js";
|
|
16
|
+
import { FieldDescription, FieldError, FieldLabel, Popup, RenderCustomComponent, XIcon, fieldBaseClass } from "@payloadcms/ui";
|
|
17
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
18
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
import "./colorField.css";
|
|
20
|
+
//#region src/fields/color/client/ColorInput.tsx
|
|
21
|
+
const baseClass = "fields-color";
|
|
22
|
+
const DEFAULT_OPTIONS = {
|
|
23
|
+
alpha: true,
|
|
24
|
+
enableEyedropper: true,
|
|
25
|
+
format: "hex",
|
|
26
|
+
isClearable: true,
|
|
27
|
+
linked: false,
|
|
28
|
+
linkedFallback: null
|
|
29
|
+
};
|
|
30
|
+
const NO_PRESETS = [];
|
|
31
|
+
/**
|
|
32
|
+
* The color field's row, picker, preset chip and commit pipeline with no form behind
|
|
33
|
+
* it, for custom admin views and components. `ColorField` is this plus `useField`.
|
|
34
|
+
*/
|
|
35
|
+
const ColorInput = (props) => {
|
|
36
|
+
const { AfterInput, BeforeInput, className, Description, description, Error: ErrorComponent, error, Label, label, localized, onChange, options, path, placeholder, presets: resolvedPresets = NO_PRESETS, presetsLabel, readOnly, required, showError: showErrorFromProps, style, value } = props;
|
|
37
|
+
const { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = {
|
|
38
|
+
...DEFAULT_OPTIONS,
|
|
39
|
+
...options
|
|
40
|
+
};
|
|
41
|
+
const { t } = useTranslation$1();
|
|
42
|
+
const isReadOnly = Boolean(readOnly);
|
|
43
|
+
const stringValue = typeof value === "string" ? value : "";
|
|
44
|
+
const ownIssue = showErrorFromProps === void 0 && error === void 0 ? colorValueIssue(stringValue, {
|
|
45
|
+
linked,
|
|
46
|
+
presets: resolvedPresets
|
|
47
|
+
}) : null;
|
|
48
|
+
const errorMessage = error ?? (ownIssue ? t(keys[ownIssue]) : void 0);
|
|
49
|
+
const showError = showErrorFromProps ?? errorMessage !== void 0;
|
|
50
|
+
const reference = linked ? parsePresetReference(stringValue) : null;
|
|
51
|
+
const presetKey = reference?.key ?? null;
|
|
52
|
+
const referenceAlpha = alpha ? reference?.alpha ?? 100 : 100;
|
|
53
|
+
const activePreset = presetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : void 0;
|
|
54
|
+
const presetMissing = presetKey !== null && !activePreset;
|
|
55
|
+
const rawValue = presetKey !== null ? activePreset?.value ?? linkedFallback : stringValue || null;
|
|
56
|
+
const cssValue = flatValue(rawValue);
|
|
57
|
+
const parsed = useMemo(() => cssValue ? parseColor(cssValue) : null, [cssValue]);
|
|
58
|
+
const [displayFormat, setDisplayFormat] = useState(format);
|
|
59
|
+
const displayValue = useMemo(() => {
|
|
60
|
+
if (presetKey !== null || !parsed || displayFormat === format) return stringValue;
|
|
61
|
+
return formatColor(parsed, displayFormat, { alpha });
|
|
62
|
+
}, [
|
|
63
|
+
alpha,
|
|
64
|
+
displayFormat,
|
|
65
|
+
format,
|
|
66
|
+
parsed,
|
|
67
|
+
presetKey,
|
|
68
|
+
stringValue
|
|
69
|
+
]);
|
|
70
|
+
const [draft, setDraft] = useState(displayValue);
|
|
71
|
+
const editingRef = useRef(false);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!editingRef.current) setDraft(displayValue);
|
|
74
|
+
}, [displayValue]);
|
|
75
|
+
const [chipDismissed, setChipDismissed] = useState(false);
|
|
76
|
+
const chip = useMemo(() => derivePresetChip({
|
|
77
|
+
editing: chipDismissed,
|
|
78
|
+
linked,
|
|
79
|
+
presets: resolvedPresets,
|
|
80
|
+
value: stringValue
|
|
81
|
+
}), [
|
|
82
|
+
chipDismissed,
|
|
83
|
+
linked,
|
|
84
|
+
resolvedPresets,
|
|
85
|
+
stringValue
|
|
86
|
+
]);
|
|
87
|
+
const debounceRef = useRef(null);
|
|
88
|
+
useEffect(() => () => {
|
|
89
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
90
|
+
}, []);
|
|
91
|
+
const onChangeRef = useRef(onChange);
|
|
92
|
+
onChangeRef.current = onChange;
|
|
93
|
+
const setValue = useCallback((next) => onChangeRef.current(next), []);
|
|
94
|
+
const lastValidRef = useRef(null);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (stringValue === "") return;
|
|
97
|
+
if (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue;
|
|
98
|
+
}, [presetKey, stringValue]);
|
|
99
|
+
const commitText = useCallback((raw) => {
|
|
100
|
+
let normalized = null;
|
|
101
|
+
if (linked && raw.startsWith("preset:")) {
|
|
102
|
+
const parts = presetReferenceParts(raw);
|
|
103
|
+
if (parts) normalized = formatPresetReference(parts.key, alpha ? parts.alpha : 100);
|
|
104
|
+
else if (raw.length > 7) normalized = raw;
|
|
105
|
+
} else {
|
|
106
|
+
const parsedRaw = parseColor(raw);
|
|
107
|
+
if (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha });
|
|
108
|
+
}
|
|
109
|
+
const resolution = resolveCommitValue({
|
|
110
|
+
draft: raw,
|
|
111
|
+
isClearable,
|
|
112
|
+
lastValid: lastValidRef.current,
|
|
113
|
+
parsed: normalized
|
|
114
|
+
});
|
|
115
|
+
lastValidRef.current = resolution.lastValid;
|
|
116
|
+
setValue(resolution.value);
|
|
117
|
+
return resolution.reverted;
|
|
118
|
+
}, [
|
|
119
|
+
alpha,
|
|
120
|
+
format,
|
|
121
|
+
isClearable,
|
|
122
|
+
linked,
|
|
123
|
+
setValue
|
|
124
|
+
]);
|
|
125
|
+
const onTextChange = useCallback((event) => {
|
|
126
|
+
const raw = event.target.value;
|
|
127
|
+
editingRef.current = true;
|
|
128
|
+
setChipDismissed(true);
|
|
129
|
+
setDraft(raw);
|
|
130
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
131
|
+
debounceRef.current = setTimeout(() => commitText(raw), 250);
|
|
132
|
+
}, [commitText]);
|
|
133
|
+
const onTextBlur = useCallback(() => {
|
|
134
|
+
if (debounceRef.current) {
|
|
135
|
+
clearTimeout(debounceRef.current);
|
|
136
|
+
debounceRef.current = null;
|
|
137
|
+
}
|
|
138
|
+
if (editingRef.current) {
|
|
139
|
+
editingRef.current = false;
|
|
140
|
+
const salvaged = !(linked && draft.startsWith("preset:")) && draft.trim() !== "" && !parseColor(draft) ? salvageColor(draft) : null;
|
|
141
|
+
if (commitText(salvaged ?? draft)) setDraft(displayValue);
|
|
142
|
+
else if (salvaged !== null) {
|
|
143
|
+
const parsedSalvaged = parseColor(salvaged);
|
|
144
|
+
setDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
setChipDismissed(false);
|
|
148
|
+
}, [
|
|
149
|
+
alpha,
|
|
150
|
+
commitText,
|
|
151
|
+
displayFormat,
|
|
152
|
+
displayValue,
|
|
153
|
+
draft,
|
|
154
|
+
linked
|
|
155
|
+
]);
|
|
156
|
+
const onTextKeyDown = useCallback((event) => {
|
|
157
|
+
if (!chip || isReadOnly) return;
|
|
158
|
+
if (event.key === "Backspace" || event.key === "Delete") {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
setDraft("");
|
|
161
|
+
if (isClearable) setValue(null);
|
|
162
|
+
else {
|
|
163
|
+
editingRef.current = true;
|
|
164
|
+
setChipDismissed(true);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, [
|
|
168
|
+
chip,
|
|
169
|
+
isClearable,
|
|
170
|
+
isReadOnly,
|
|
171
|
+
setValue
|
|
172
|
+
]);
|
|
173
|
+
const commitCss = useCallback((css) => {
|
|
174
|
+
const parsedCss = parseColor(css);
|
|
175
|
+
if (parsedCss) setValue(formatColor(parsedCss, format, { alpha }));
|
|
176
|
+
}, [
|
|
177
|
+
alpha,
|
|
178
|
+
format,
|
|
179
|
+
setValue
|
|
180
|
+
]);
|
|
181
|
+
const initialHsva = useMemo(() => {
|
|
182
|
+
if (!parsed) return null;
|
|
183
|
+
const rgb = toRgb(parsed);
|
|
184
|
+
const hsv = rgbToHsv(rgb);
|
|
185
|
+
return {
|
|
186
|
+
a: presetKey !== null ? referenceAlpha / 100 : rgb.alpha,
|
|
187
|
+
h: hsv.h,
|
|
188
|
+
s: hsv.s,
|
|
189
|
+
v: hsv.v
|
|
190
|
+
};
|
|
191
|
+
}, [
|
|
192
|
+
parsed,
|
|
193
|
+
presetKey,
|
|
194
|
+
referenceAlpha
|
|
195
|
+
]);
|
|
196
|
+
const commitReferenceAlpha = useCallback((alpha100) => {
|
|
197
|
+
if (presetKey === null) return;
|
|
198
|
+
setValue(formatPresetReference(presetKey, alpha100));
|
|
199
|
+
}, [presetKey, setValue]);
|
|
200
|
+
const contentRef = useRef(null);
|
|
201
|
+
const [contentClipped, setContentClipped] = useState(false);
|
|
202
|
+
const measureClip = useCallback(() => {
|
|
203
|
+
const el = contentRef.current;
|
|
204
|
+
if (el) setContentClipped(el.scrollWidth > el.clientWidth + 1);
|
|
205
|
+
}, []);
|
|
206
|
+
useEffect(measureClip);
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
const el = contentRef.current;
|
|
209
|
+
if (!el) return;
|
|
210
|
+
const observer = new ResizeObserver(measureClip);
|
|
211
|
+
observer.observe(el);
|
|
212
|
+
return () => observer.disconnect();
|
|
213
|
+
}, [measureClip]);
|
|
214
|
+
const generatedId = useId();
|
|
215
|
+
const inputId = path ? `field-${path.replace(/\./g, "__")}` : generatedId;
|
|
216
|
+
const swatchCss = swatchBackground(referenceAlpha !== 100 && (typeof rawValue === "string" || isColorSchemeValue(rawValue)) ? applyReferenceAlpha(rawValue, referenceAlpha, "rgb") : rawValue);
|
|
217
|
+
const swatch = /* @__PURE__ */ jsxs("span", {
|
|
218
|
+
className: `${baseClass}__swatch ${baseClass}__checker`,
|
|
219
|
+
children: [
|
|
220
|
+
swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
221
|
+
className: `${baseClass}__swatch-color`,
|
|
222
|
+
style: { background: swatchCss }
|
|
223
|
+
}) : null,
|
|
224
|
+
presetMissing && !swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
225
|
+
className: `${baseClass}__swatch-color`,
|
|
226
|
+
"data-missing": "true"
|
|
227
|
+
}) : null,
|
|
228
|
+
isReadOnly ? null : /* @__PURE__ */ jsx("span", {
|
|
229
|
+
className: `${baseClass}__sr-only`,
|
|
230
|
+
children: t(keys.pickColor)
|
|
231
|
+
})
|
|
232
|
+
]
|
|
233
|
+
});
|
|
234
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
235
|
+
className: [
|
|
236
|
+
fieldBaseClass,
|
|
237
|
+
baseClass,
|
|
238
|
+
className,
|
|
239
|
+
showError && "error",
|
|
240
|
+
isReadOnly && "read-only"
|
|
241
|
+
].filter(Boolean).join(" "),
|
|
242
|
+
style,
|
|
243
|
+
children: [/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
244
|
+
CustomComponent: Label,
|
|
245
|
+
Fallback: /* @__PURE__ */ jsx(FieldLabel, {
|
|
246
|
+
htmlFor: path ? void 0 : inputId,
|
|
247
|
+
label,
|
|
248
|
+
localized,
|
|
249
|
+
path,
|
|
250
|
+
required
|
|
251
|
+
})
|
|
252
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
253
|
+
className: `${fieldBaseClass}__wrap`,
|
|
254
|
+
children: [
|
|
255
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
256
|
+
CustomComponent: ErrorComponent,
|
|
257
|
+
Fallback: /* @__PURE__ */ jsx(FieldError, {
|
|
258
|
+
message: errorMessage,
|
|
259
|
+
path,
|
|
260
|
+
showError
|
|
261
|
+
})
|
|
262
|
+
}),
|
|
263
|
+
BeforeInput,
|
|
264
|
+
/* @__PURE__ */ jsxs("div", {
|
|
265
|
+
className: `${baseClass}__container`,
|
|
266
|
+
children: [
|
|
267
|
+
isReadOnly ? /* @__PURE__ */ jsx("span", {
|
|
268
|
+
className: `${baseClass}__swatch-button ${baseClass}__swatch-button--static`,
|
|
269
|
+
children: swatch
|
|
270
|
+
}) : /* @__PURE__ */ jsx(Popup, {
|
|
271
|
+
button: swatch,
|
|
272
|
+
buttonClassName: `${baseClass}__swatch-button`,
|
|
273
|
+
buttonType: "custom",
|
|
274
|
+
caret: false,
|
|
275
|
+
className: `${baseClass}__popup`,
|
|
276
|
+
horizontalAlign: "left",
|
|
277
|
+
render: ({ close }) => /* @__PURE__ */ jsx(ColorPickerPanel, {
|
|
278
|
+
activeReference: reference,
|
|
279
|
+
alphaEnabled: alpha,
|
|
280
|
+
close,
|
|
281
|
+
displayFormat,
|
|
282
|
+
enableEyedropper,
|
|
283
|
+
initial: initialHsva,
|
|
284
|
+
onPickAlpha: commitReferenceAlpha,
|
|
285
|
+
onPickCss: commitCss,
|
|
286
|
+
onPickPreset: (preset) => {
|
|
287
|
+
if (linked) setValue(`${PRESET_PREFIX}${preset.key}`);
|
|
288
|
+
else {
|
|
289
|
+
const flat = flatValue(preset.value);
|
|
290
|
+
if (flat) commitCss(flat);
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
presetMissing,
|
|
294
|
+
presets: resolvedPresets,
|
|
295
|
+
presetsLabel: presetsLabel ?? t(keys.presets),
|
|
296
|
+
setDisplayFormat
|
|
297
|
+
}),
|
|
298
|
+
size: "fit-content",
|
|
299
|
+
verticalAlign: "bottom"
|
|
300
|
+
}),
|
|
301
|
+
/* @__PURE__ */ jsxs("div", {
|
|
302
|
+
className: [`${baseClass}__content`, contentClipped && `${baseClass}__content--fade`].filter(Boolean).join(" "),
|
|
303
|
+
ref: contentRef,
|
|
304
|
+
children: [
|
|
305
|
+
chip ? /* @__PURE__ */ jsxs("span", {
|
|
306
|
+
className: `${baseClass}__chip`,
|
|
307
|
+
children: [
|
|
308
|
+
/* @__PURE__ */ jsxs("span", {
|
|
309
|
+
className: `${baseClass}__chip-swatch ${baseClass}__checker`,
|
|
310
|
+
children: [swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
311
|
+
className: `${baseClass}__chip-color`,
|
|
312
|
+
style: { background: swatchCss }
|
|
313
|
+
}) : null, chip.missing && !swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
314
|
+
className: `${baseClass}__chip-color`,
|
|
315
|
+
"data-missing": "true"
|
|
316
|
+
}) : null]
|
|
317
|
+
}),
|
|
318
|
+
/* @__PURE__ */ jsx("span", {
|
|
319
|
+
className: `${baseClass}__chip-label`,
|
|
320
|
+
children: chip.label
|
|
321
|
+
}),
|
|
322
|
+
alpha && chip.alpha !== 100 ? /* @__PURE__ */ jsxs("span", {
|
|
323
|
+
className: `${baseClass}__chip-alpha`,
|
|
324
|
+
children: [chip.alpha, "%"]
|
|
325
|
+
}) : null
|
|
326
|
+
]
|
|
327
|
+
}) : null,
|
|
328
|
+
/* @__PURE__ */ jsx("input", {
|
|
329
|
+
className: `${baseClass}__input`,
|
|
330
|
+
id: inputId,
|
|
331
|
+
name: path,
|
|
332
|
+
onBlur: onTextBlur,
|
|
333
|
+
onChange: onTextChange,
|
|
334
|
+
onKeyDown: onTextKeyDown,
|
|
335
|
+
placeholder: chip ? void 0 : placeholder,
|
|
336
|
+
readOnly: isReadOnly,
|
|
337
|
+
type: "text",
|
|
338
|
+
value: chip ? "" : draft
|
|
339
|
+
}),
|
|
340
|
+
/* @__PURE__ */ jsx("span", {
|
|
341
|
+
"aria-hidden": "true",
|
|
342
|
+
className: `${baseClass}__badge`,
|
|
343
|
+
children: chip ? t(keys.preset) : displayFormat
|
|
344
|
+
})
|
|
345
|
+
]
|
|
346
|
+
}),
|
|
347
|
+
isClearable && !required && !isReadOnly && stringValue !== "" ? /* @__PURE__ */ jsx("button", {
|
|
348
|
+
"aria-label": t(keys.clearColor),
|
|
349
|
+
className: `${baseClass}__clear`,
|
|
350
|
+
onClick: () => {
|
|
351
|
+
setDraft("");
|
|
352
|
+
setValue(null);
|
|
353
|
+
},
|
|
354
|
+
type: "button",
|
|
355
|
+
children: /* @__PURE__ */ jsx(XIcon, {})
|
|
356
|
+
}) : null
|
|
357
|
+
]
|
|
358
|
+
}),
|
|
359
|
+
AfterInput,
|
|
360
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
361
|
+
CustomComponent: Description,
|
|
362
|
+
Fallback: /* @__PURE__ */ jsx(FieldDescription, {
|
|
363
|
+
description,
|
|
364
|
+
path: path ?? ""
|
|
365
|
+
})
|
|
366
|
+
})
|
|
367
|
+
]
|
|
368
|
+
})]
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
//#endregion
|
|
372
|
+
export { ColorInput };
|
|
373
|
+
|
|
374
|
+
//# sourceMappingURL=ColorInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorInput.js","names":["useTranslation"],"sources":["../../../../src/fields/color/client/ColorInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n\tXIcon,\n} from '@payloadcms/ui'\nimport type { StaticDescription, StaticLabel } from 'payload'\nimport type React from 'react'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { resolveCommitValue } from '../commitValue'\nimport {\n\tformatColor,\n\tisColorSchemeValue,\n\tparseColor,\n\trgbToHsv,\n\tsalvageColor,\n\ttoRgb,\n} from '../engine'\nimport { type ColorFieldClientOptions, PRESET_PREFIX, type ResolvedColorPreset } from '../options'\nimport { derivePresetChip } from '../presetChip'\nimport {\n\tapplyReferenceAlpha,\n\tformatPresetReference,\n\tparsePresetReference,\n\tpresetReferenceParts,\n} from '../presetReference'\nimport { flatValue, swatchBackground } from '../schemeValue'\nimport { colorValueIssue } from '../valueIssue'\nimport { ColorPickerPanel, type Hsva } from './ColorPickerPanel'\nimport './colorField.css'\n\nconst baseClass = 'fields-color'\n\nconst DEFAULT_OPTIONS: ColorFieldClientOptions = {\n\talpha: true,\n\tenableEyedropper: true,\n\tformat: 'hex',\n\tisClearable: true,\n\tlinked: false,\n\tlinkedFallback: null,\n}\n\nconst NO_PRESETS: ResolvedColorPreset[] = []\n\n/**\n * Props for the form-free color input. `value` and `onChange` carry the stored string\n * exactly as `colorField` would persist it: normalized to `options.format` on commit,\n * or a `preset:<key>` reference when `options.linked` is on.\n */\nexport type ColorInputProps = {\n\tvalue: null | string | undefined\n\t/** Fires at commit boundaries (debounced typing, blur, picker, preset, clear), never per keystroke. */\n\tonChange: (value: null | string) => void\n\t/** Any option left out takes `colorField`'s default (hex, alpha on, clearable, eyedropper, unlinked). */\n\toptions?: Partial<ColorFieldClientOptions>\n\t/** Already resolved presets; labels are plain strings in the viewer's language. */\n\tpresets?: ResolvedColorPreset[]\n\tpresetsLabel?: string\n\t/** Names the input (`id`, `name`, label `htmlFor`), as on a native field. */\n\tpath?: string\n\tlabel?: StaticLabel\n\tdescription?: StaticDescription\n\tplaceholder?: string\n\trequired?: boolean\n\tlocalized?: boolean\n\treadOnly?: boolean\n\t/**\n\t * Message shown in the error tooltip. Left unset, the input reports its own\n\t * malformed-color and missing-preset errors.\n\t */\n\terror?: string\n\t/** Forces the error state on or off. Left unset, it follows `error` and the input's own check. */\n\tshowError?: boolean\n\tclassName?: string\n\tstyle?: React.CSSProperties\n\tLabel?: React.ReactNode\n\tError?: React.ReactNode\n\tDescription?: React.ReactNode\n\tBeforeInput?: React.ReactNode\n\tAfterInput?: React.ReactNode\n}\n\n/**\n * The color field's row, picker, preset chip and commit pipeline with no form behind\n * it, for custom admin views and components. `ColorField` is this plus `useField`.\n */\nexport const ColorInput: React.FC<ColorInputProps> = (props) => {\n\tconst {\n\t\tAfterInput,\n\t\tBeforeInput,\n\t\tclassName,\n\t\tDescription,\n\t\tdescription,\n\t\tError: ErrorComponent,\n\t\terror,\n\t\tLabel,\n\t\tlabel,\n\t\tlocalized,\n\t\tonChange,\n\t\toptions,\n\t\tpath,\n\t\tplaceholder,\n\t\tpresets: resolvedPresets = NO_PRESETS,\n\t\tpresetsLabel,\n\t\treadOnly,\n\t\trequired,\n\t\tshowError: showErrorFromProps,\n\t\tstyle,\n\t\tvalue,\n\t} = props\n\tconst { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = {\n\t\t...DEFAULT_OPTIONS,\n\t\t...options,\n\t}\n\tconst { t } = useTranslation()\n\tconst isReadOnly = Boolean(readOnly)\n\n\tconst stringValue = typeof value === 'string' ? value : ''\n\tconst ownIssue =\n\t\tshowErrorFromProps === undefined && error === undefined\n\t\t\t? colorValueIssue(stringValue, { linked, presets: resolvedPresets })\n\t\t\t: null\n\tconst errorMessage = error ?? (ownIssue ? t(keys[ownIssue]) : undefined)\n\tconst showError = showErrorFromProps ?? errorMessage !== undefined\n\n\tconst reference = linked ? parsePresetReference(stringValue) : null\n\tconst presetKey = reference?.key ?? null\n\t// With alpha disabled a stored suffix still parses, but renders at full\n\t// opacity so the field matches server resolution until commit strips it\n\tconst referenceAlpha = alpha ? (reference?.alpha ?? 100) : 100\n\tconst activePreset =\n\t\tpresetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : undefined\n\tconst presetMissing = presetKey !== null && !activePreset\n\tconst rawValue: unknown =\n\t\tpresetKey !== null ? (activePreset?.value ?? linkedFallback) : stringValue || null\n\tconst cssValue = flatValue(rawValue)\n\tconst parsed = useMemo(() => (cssValue ? parseColor(cssValue) : null), [cssValue])\n\n\tconst [displayFormat, setDisplayFormat] = useState<ColorFormat>(format)\n\tconst displayValue = useMemo(() => {\n\t\tif (presetKey !== null || !parsed || displayFormat === format) return stringValue\n\t\treturn formatColor(parsed, displayFormat, { alpha })\n\t}, [alpha, displayFormat, format, parsed, presetKey, stringValue])\n\n\tconst [draft, setDraft] = useState(displayValue)\n\tconst editingRef = useRef(false)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) setDraft(displayValue)\n\t}, [displayValue])\n\n\t// Typing dismisses the chip into plain text entry; blur re-derives it from the committed value\n\tconst [chipDismissed, setChipDismissed] = useState(false)\n\tconst chip = useMemo(\n\t\t() =>\n\t\t\tderivePresetChip({\n\t\t\t\tediting: chipDismissed,\n\t\t\t\tlinked,\n\t\t\t\tpresets: resolvedPresets,\n\t\t\t\tvalue: stringValue,\n\t\t\t}),\n\t\t[chipDismissed, linked, resolvedPresets, stringValue]\n\t)\n\n\tconst debounceRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// The commit callbacks below read onChange through a ref, so a caller passing an\n\t// inline arrow does not re-create them (and with them the debounce) every render\n\tconst onChangeRef = useRef(onChange)\n\tonChangeRef.current = onChange\n\tconst setValue = useCallback((next: null | string) => onChangeRef.current(next), [])\n\n\t// Revert target for non-clearable commits; tracked from committed values so\n\t// picker commits, preset picks, and the initially loaded value all count\n\tconst lastValidRef = useRef<null | string>(null)\n\tuseEffect(() => {\n\t\tif (stringValue === '') return\n\t\tif (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue\n\t}, [presetKey, stringValue])\n\n\t// Commits without touching editingRef: the debounced path must not let the draft resync mid-typing.\n\t// Returns true when a non-clearable empty or unparseable draft was reverted to the last valid value.\n\tconst commitText = useCallback(\n\t\t(raw: string): boolean => {\n\t\t\tlet normalized: null | string = null\n\t\t\tif (linked && raw.startsWith(PRESET_PREFIX)) {\n\t\t\t\tconst parts = presetReferenceParts(raw)\n\t\t\t\t// Canonical form: /100 collapses to the bare reference, and a disabled\n\t\t\t\t// alpha channel strips any hand-typed suffix. Empty keys commit raw so\n\t\t\t\t// validation surfaces the missing-preset error.\n\t\t\t\tif (parts) normalized = formatPresetReference(parts.key, alpha ? parts.alpha : 100)\n\t\t\t\telse if (raw.length > PRESET_PREFIX.length) normalized = raw\n\t\t\t} else {\n\t\t\t\tconst parsedRaw = parseColor(raw)\n\t\t\t\t// Unparseable input commits raw so validation surfaces the error\n\t\t\t\tif (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha })\n\t\t\t}\n\t\t\tconst resolution = resolveCommitValue({\n\t\t\t\tdraft: raw,\n\t\t\t\tisClearable,\n\t\t\t\tlastValid: lastValidRef.current,\n\t\t\t\tparsed: normalized,\n\t\t\t})\n\t\t\tlastValidRef.current = resolution.lastValid\n\t\t\tsetValue(resolution.value)\n\t\t\treturn resolution.reverted\n\t\t},\n\t\t[alpha, format, isClearable, linked, setValue]\n\t)\n\n\tconst onTextChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst raw = event.target.value\n\t\t\teditingRef.current = true\n\t\t\tsetChipDismissed(true)\n\t\t\tsetDraft(raw)\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = setTimeout(() => commitText(raw), 250)\n\t\t},\n\t\t[commitText]\n\t)\n\n\tconst onTextBlur = useCallback(() => {\n\t\tif (debounceRef.current) {\n\t\t\tclearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = null\n\t\t}\n\t\tif (editingRef.current) {\n\t\t\teditingRef.current = false\n\t\t\t// Blur-only salvage: recover the first valid color from dirty input\n\t\t\t// (double pastes, stray junk) before the normal commit pipeline\n\t\t\tconst isPresetDraft = linked && draft.startsWith(PRESET_PREFIX)\n\t\t\tconst salvaged =\n\t\t\t\t!isPresetDraft && draft.trim() !== '' && !parseColor(draft) ? salvageColor(draft) : null\n\t\t\tif (commitText(salvaged ?? draft)) {\n\t\t\t\t// A reverted commit usually leaves the value unchanged, so the\n\t\t\t\t// displayValue resync effect never fires; restore the draft here\n\t\t\t\tsetDraft(displayValue)\n\t\t\t} else if (salvaged !== null) {\n\t\t\t\t// A salvaged commit can store the same value as before (double paste of\n\t\t\t\t// the current color), which also skips the resync; clean the draft here\n\t\t\t\tconst parsedSalvaged = parseColor(salvaged)\n\t\t\t\tsetDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged)\n\t\t\t}\n\t\t}\n\t\tsetChipDismissed(false)\n\t}, [alpha, commitText, displayFormat, displayValue, draft, linked])\n\n\t// Backspace/Delete on the empty chip input never fires a change event, so clear here\n\tconst onTextKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\tif (!chip || isReadOnly) return\n\t\t\tif (event.key === 'Backspace' || event.key === 'Delete') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tsetDraft('')\n\t\t\t\tif (isClearable) {\n\t\t\t\t\tsetValue(null)\n\t\t\t\t} else {\n\t\t\t\t\t// Keep the stored ref; the emptied draft reverts or gets replaced at commit\n\t\t\t\t\teditingRef.current = true\n\t\t\t\t\tsetChipDismissed(true)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[chip, isClearable, isReadOnly, setValue]\n\t)\n\n\tconst commitCss = useCallback(\n\t\t(css: string) => {\n\t\t\tconst parsedCss = parseColor(css)\n\t\t\tif (parsedCss) setValue(formatColor(parsedCss, format, { alpha }))\n\t\t},\n\t\t[alpha, format, setValue]\n\t)\n\n\t// With a reference active the slider represents the reference alpha, not the\n\t// resolved color's own channel, so returning it to 100 restores the bare ref\n\tconst initialHsva = useMemo<Hsva | null>(() => {\n\t\tif (!parsed) return null\n\t\tconst rgb = toRgb(parsed)\n\t\tconst hsv = rgbToHsv(rgb)\n\t\treturn {\n\t\t\ta: presetKey !== null ? referenceAlpha / 100 : rgb.alpha,\n\t\t\th: hsv.h,\n\t\t\ts: hsv.s,\n\t\t\tv: hsv.v,\n\t\t}\n\t}, [parsed, presetKey, referenceAlpha])\n\n\tconst commitReferenceAlpha = useCallback(\n\t\t(alpha100: number) => {\n\t\t\tif (presetKey === null) return\n\t\t\tsetValue(formatPresetReference(presetKey, alpha100))\n\t\t},\n\t\t[presetKey, setValue]\n\t)\n\n\t// The fade must track real overflow, not chip presence: the badge always hugs\n\t// the content run's right edge (the input's flex-grow pushes it there), so an\n\t// unconditional mask would fade it even in a full-width field with room to spare\n\tconst contentRef = useRef<HTMLDivElement>(null)\n\tconst [contentClipped, setContentClipped] = useState(false)\n\tconst measureClip = useCallback(() => {\n\t\tconst el = contentRef.current\n\t\t// +1 absorbs subpixel rounding between scrollWidth (int) and clientWidth\n\t\tif (el) setContentClipped(el.scrollWidth > el.clientWidth + 1)\n\t}, [])\n\t// No dependency array on purpose: chip mount and label changes alter\n\t// scrollWidth without resizing the observed box, so re-measure every render\n\tuseEffect(measureClip)\n\tuseEffect(() => {\n\t\tconst el = contentRef.current\n\t\tif (!el) return\n\t\tconst observer = new ResizeObserver(measureClip)\n\t\tobserver.observe(el)\n\t\treturn () => observer.disconnect()\n\t}, [measureClip])\n\n\t// Without a path there is no field id to derive, so the label pairs with a generated one\n\tconst generatedId = useId()\n\tconst inputId = path ? `field-${path.replace(/\\./g, '__')}` : generatedId\n\n\tconst swatchValue =\n\t\treferenceAlpha !== 100 && (typeof rawValue === 'string' || isColorSchemeValue(rawValue))\n\t\t\t? applyReferenceAlpha(rawValue, referenceAlpha, 'rgb')\n\t\t\t: rawValue\n\tconst swatchCss = swatchBackground(swatchValue)\n\n\tconst swatch = (\n\t\t<span className={`${baseClass}__swatch ${baseClass}__checker`}>\n\t\t\t{swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} style={{ background: swatchCss }} />\n\t\t\t) : null}\n\t\t\t{presetMissing && !swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} data-missing=\"true\" />\n\t\t\t) : null}\n\t\t\t{isReadOnly ? null : <span className={`${baseClass}__sr-only`}>{t(keys.pickColor)}</span>}\n\t\t</span>\n\t)\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\tshowError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={style}\n\t\t>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel\n\t\t\t\t\t\thtmlFor={path ? undefined : inputId}\n\t\t\t\t\t\tlabel={label}\n\t\t\t\t\t\tlocalized={localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError message={errorMessage} path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div className={`${baseClass}__container`}>\n\t\t\t\t\t{isReadOnly ? (\n\t\t\t\t\t\t<span className={`${baseClass}__swatch-button ${baseClass}__swatch-button--static`}>\n\t\t\t\t\t\t\t{swatch}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Popup\n\t\t\t\t\t\t\tbutton={swatch}\n\t\t\t\t\t\t\tbuttonClassName={`${baseClass}__swatch-button`}\n\t\t\t\t\t\t\tbuttonType=\"custom\"\n\t\t\t\t\t\t\tcaret={false}\n\t\t\t\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\t\t\t\thorizontalAlign=\"left\"\n\t\t\t\t\t\t\trender={({ close }) => (\n\t\t\t\t\t\t\t\t<ColorPickerPanel\n\t\t\t\t\t\t\t\t\tactiveReference={reference}\n\t\t\t\t\t\t\t\t\talphaEnabled={alpha}\n\t\t\t\t\t\t\t\t\tclose={close}\n\t\t\t\t\t\t\t\t\tdisplayFormat={displayFormat}\n\t\t\t\t\t\t\t\t\tenableEyedropper={enableEyedropper}\n\t\t\t\t\t\t\t\t\tinitial={initialHsva}\n\t\t\t\t\t\t\t\t\tonPickAlpha={commitReferenceAlpha}\n\t\t\t\t\t\t\t\t\tonPickCss={commitCss}\n\t\t\t\t\t\t\t\t\tonPickPreset={(preset) => {\n\t\t\t\t\t\t\t\t\t\tif (linked) setValue(`${PRESET_PREFIX}${preset.key}`)\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t// A text column holds one color, so a scheme preset stores its light member\n\t\t\t\t\t\t\t\t\t\t\tconst flat = flatValue(preset.value)\n\t\t\t\t\t\t\t\t\t\t\tif (flat) commitCss(flat)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\tpresetMissing={presetMissing}\n\t\t\t\t\t\t\t\t\tpresets={resolvedPresets}\n\t\t\t\t\t\t\t\t\tpresetsLabel={presetsLabel ?? t(keys.presets)}\n\t\t\t\t\t\t\t\t\tsetDisplayFormat={setDisplayFormat}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tsize=\"fit-content\"\n\t\t\t\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={[`${baseClass}__content`, contentClipped && `${baseClass}__content--fade`]\n\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t.join(' ')}\n\t\t\t\t\t\tref={contentRef}\n\t\t\t\t\t>\n\t\t\t\t\t\t{chip ? (\n\t\t\t\t\t\t\t<span className={`${baseClass}__chip`}>\n\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-swatch ${baseClass}__checker`}>\n\t\t\t\t\t\t\t\t\t{swatchCss ? (\n\t\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__chip-color`}\n\t\t\t\t\t\t\t\t\t\t\tstyle={{ background: swatchCss }}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t{chip.missing && !swatchCss ? (\n\t\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-color`} data-missing=\"true\" />\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-label`}>{chip.label}</span>\n\t\t\t\t\t\t\t\t{alpha && chip.alpha !== 100 ? (\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-alpha`}>{chip.alpha}%</span>\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\tonBlur={onTextBlur}\n\t\t\t\t\t\t\tonChange={onTextChange}\n\t\t\t\t\t\t\tonKeyDown={onTextKeyDown}\n\t\t\t\t\t\t\tplaceholder={chip ? undefined : placeholder}\n\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\tvalue={chip ? '' : draft}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__badge`}>\n\t\t\t\t\t\t\t{chip ? t(keys.preset) : displayFormat}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t{isClearable && !required && !isReadOnly && stringValue !== '' ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearColor)}\n\t\t\t\t\t\t\tclassName={`${baseClass}__clear`}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetDraft('')\n\t\t\t\t\t\t\t\tsetValue(null)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<XIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path ?? ''} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;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,GAAG,UAAU;OACxB,eAAe;QACd,SAAS,EAAE;QACX,SAAS,IAAI;OACd;OACA,MAAK;iBAEL,oBAAC,OAAD,CAAQ,CAAA;MACD,CAAA,IACL;KACA;;IACJ;IACD,oBAAC,uBAAD;KACC,iBAAiB;KACjB,UAAU,oBAAC,kBAAD;MAA+B;MAAa,MAAM,QAAQ;KAAK,CAAA;IACzE,CAAA;GACG;IACD;;AAEP"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { parseColor } from "./engine/parse.js";
|
|
2
|
+
import "./options.js";
|
|
3
|
+
import { presetReferenceIssue } from "./presetReference.js";
|
|
4
|
+
//#region src/fields/color/valueIssue.ts
|
|
5
|
+
/**
|
|
6
|
+
* Format-level problem with a stored or typed color value, shared by the form-bound
|
|
7
|
+
* field's validate and the standalone input's own error display. Empty values have
|
|
8
|
+
* no issue here; `required` is the caller's concern.
|
|
9
|
+
*/
|
|
10
|
+
const colorValueIssue = (value, args) => {
|
|
11
|
+
if (typeof value !== "string" || value === "") return null;
|
|
12
|
+
const { linked, presets } = args;
|
|
13
|
+
if (linked && value.startsWith("preset:")) {
|
|
14
|
+
const issue = presetReferenceIssue(value, presets.length > 0 ? (key) => presets.some((preset) => preset.key === key) : null);
|
|
15
|
+
if (issue === "invalidAlpha") return "invalidColor";
|
|
16
|
+
return issue === null ? null : "missingPreset";
|
|
17
|
+
}
|
|
18
|
+
return parseColor(value) ? null : "invalidColor";
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { colorValueIssue };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=valueIssue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valueIssue.js","names":[],"sources":["../../../src/fields/color/valueIssue.ts"],"sourcesContent":["import { parseColor } from './engine'\nimport { PRESET_PREFIX, type ResolvedColorPreset } from './options'\nimport { presetReferenceIssue } from './presetReference'\n\nexport type ColorValueIssue = 'invalidColor' | 'missingPreset'\n\n/**\n * Format-level problem with a stored or typed color value, shared by the form-bound\n * field's validate and the standalone input's own error display. Empty values have\n * no issue here; `required` is the caller's concern.\n */\nexport const colorValueIssue = (\n\tvalue: unknown,\n\targs: { linked: boolean; presets: readonly ResolvedColorPreset[] }\n): ColorValueIssue | null => {\n\tif (typeof value !== 'string' || value === '') return null\n\tconst { linked, presets } = args\n\tif (linked && value.startsWith(PRESET_PREFIX)) {\n\t\tconst hasKey =\n\t\t\tpresets.length > 0 ? (key: string) => presets.some((preset) => preset.key === key) : null\n\t\tconst issue = presetReferenceIssue(value, hasKey)\n\t\tif (issue === 'invalidAlpha') return 'invalidColor'\n\t\treturn issue === null ? null : 'missingPreset'\n\t}\n\treturn parseColor(value) ? null : 'invalidColor'\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,mBACZ,OACA,SAC4B;CAC5B,IAAI,OAAO,UAAU,YAAY,UAAU,IAAI,OAAO;CACtD,MAAM,EAAE,QAAQ,YAAY;CAC5B,IAAI,UAAU,MAAM,WAAA,SAAwB,GAAG;EAG9C,MAAM,QAAQ,qBAAqB,OADlC,QAAQ,SAAS,KAAK,QAAgB,QAAQ,MAAM,WAAW,OAAO,QAAQ,GAAG,IAAI,IACtC;EAChD,IAAI,UAAU,gBAAgB,OAAO;EACrC,OAAO,UAAU,OAAO,OAAO;CAChC;CACA,OAAO,WAAW,KAAK,IAAI,OAAO;AACnC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getFieldsRegistry } from "../../../plugin/registry.js";
|
|
2
2
|
import { resolveAvailableLibraries, unionAlwaysAvailable } from "../server/availability.js";
|
|
3
|
-
import { resolveStaticLabel } from "
|
|
3
|
+
import { resolveStaticLabel } from "../../../utils/resolveStaticLabel.js";
|
|
4
4
|
import { resolveIconValue } from "../shared/value.js";
|
|
5
5
|
import { IconField } from "../client/IconFieldClient.js";
|
|
6
6
|
import { resolveIconMeta } from "../server/resolveIconMeta.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconFieldServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconFieldServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\nimport type { ReactNode } from 'react'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { IconField } from '../client/IconFieldClient'\nimport { resolveAvailableLibraries, unionAlwaysAvailable } from '../server/availability'\nimport { resolveIconMeta } from '../server/resolveIconMeta'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport {
|
|
1
|
+
{"version":3,"file":"IconFieldServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconFieldServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\nimport type { ReactNode } from 'react'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { IconField } from '../client/IconFieldClient'\nimport { resolveAvailableLibraries, unionAlwaysAvailable } from '../server/availability'\nimport { resolveIconMeta } from '../server/resolveIconMeta'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { resolveIconValue } from '../shared/value'\n\ntype IconFieldServerExtraProps = {\n\tadapters?: IconAdapter[]\n\talwaysAvailable?: string[]\n\tdefaultLibrary?: string\n\tresolveAvailable?: IconAvailabilityResolver\n\tshowTextInput?: boolean\n}\n\ntype ServerProps = IconFieldServerExtraProps & TextFieldServerProps\n\n/**\n * Resolves adapters (inline beats registry), availability (memoized per request,\n * fails open), and adapter client components from the importMap, then renders the\n * client field with those component references as props. A missing importMap entry\n * degrades to no glyph for that library rather than throwing, so the edit view\n * never 500s over a mis-registered adapter.\n */\nexport const IconFieldServer = async (props: ServerProps): Promise<ReactNode> => {\n\tconst {\n\t\tclientField,\n\t\tdata,\n\t\ti18n,\n\t\tpath,\n\t\tpayload,\n\t\tpermissions,\n\t\treadOnly,\n\t\treq,\n\t\tschemaPath,\n\t\tsiblingData,\n\t} = props\n\tconst registryIcon = getFieldsRegistry(payload.config)?.icon\n\tconst adapters = props.adapters ?? registryIcon?.adapters ?? []\n\tconst defaultLibrary =\n\t\tprops.defaultLibrary ?? registryIcon?.defaultLibrary ?? adapters[0]?.slug ?? ''\n\tconst resolver = props.resolveAvailable ?? registryIcon?.resolveAvailable\n\tconst alwaysAvailable = unionAlwaysAvailable(props.alwaysAvailable, registryIcon?.alwaysAvailable)\n\n\tconst available = await resolveAvailableLibraries({\n\t\tadapters,\n\t\talwaysAvailable,\n\t\tdata: data as Record<string, unknown> | undefined,\n\t\treq,\n\t\tresolver,\n\t\tsiblingData: siblingData as Record<string, unknown> | undefined,\n\t})\n\n\tconst adapterComponents: Record<string, AdapterComponentsEntry> = {}\n\tfor (const adapter of adapters) {\n\t\tconst Icon = getFromImportMap<AdapterComponentsEntry['Icon']>({\n\t\t\timportMap: payload.importMap,\n\t\t\tPayloadComponent: adapter.Icon,\n\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\tsilent: true,\n\t\t})\n\t\tconst Assets = getFromImportMap<AdapterComponentsEntry['Assets']>({\n\t\t\timportMap: payload.importMap,\n\t\t\tPayloadComponent: adapter.Assets,\n\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\tsilent: true,\n\t\t})\n\t\t// Optional: libraries with bulk node-data (lucide, tabler) resolve a Nodes\n\t\t// loader so the drawer renders glyphs inline; radix omits it and falls back\n\t\t// to the per-icon Icon component.\n\t\tconst Nodes = adapter.Nodes\n\t\t\t? getFromImportMap<NonNullable<AdapterComponentsEntry['Nodes']>>({\n\t\t\t\t\timportMap: payload.importMap,\n\t\t\t\t\tPayloadComponent: adapter.Nodes,\n\t\t\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\t\t\tsilent: true,\n\t\t\t\t})\n\t\t\t: undefined\n\t\tif (Icon && Assets)\n\t\t\tadapterComponents[adapter.slug] = { Assets, canvas: adapter.canvas, Icon, Nodes }\n\t}\n\n\t// The trigger renders from a stored value alone, so a library-supplied label has to\n\t// arrive with it. A miss is not an error here: an unknown or removed icon still\n\t// renders, falling back to the name-derived label exactly as before.\n\tconst storedValue =\n\t\ttypeof siblingData?.[String(clientField.name)] === 'string'\n\t\t\t? (siblingData[String(clientField.name)] as string)\n\t\t\t: null\n\tlet selectedMeta = null\n\tif (storedValue !== null && storedValue !== '') {\n\t\tconst { library, name } = resolveIconValue(storedValue, defaultLibrary)\n\t\tconst adapter = adapters.find((candidate) => candidate.slug === library)\n\t\tif (adapter) selectedMeta = await resolveIconMeta(adapter, name, { payload, req })\n\t}\n\n\treturn (\n\t\t<IconField\n\t\t\tadapterComponents={adapterComponents}\n\t\t\tadapters={adapters.map((adapter) => ({\n\t\t\t\tlabel: resolveStaticLabel(adapter.label, i18n.language) ?? adapter.slug,\n\t\t\t\tslug: adapter.slug,\n\t\t\t}))}\n\t\t\tavailable={available}\n\t\t\tdefaultLibrary={defaultLibrary}\n\t\t\tfield={clientField}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\treadOnly={readOnly}\n\t\t\tschemaPath={schemaPath}\n\t\t\tselectedMeta={selectedMeta}\n\t\t\tshowTextInput={props.showTextInput === true}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6BA,MAAa,kBAAkB,OAAO,UAA2C;CAChF,MAAM,EACL,aACA,MACA,MACA,MACA,SACA,aACA,UACA,KACA,YACA,gBACG;CACJ,MAAM,eAAe,kBAAkB,QAAQ,MAAM,GAAG;CACxD,MAAM,WAAW,MAAM,YAAY,cAAc,YAAY,CAAC;CAC9D,MAAM,iBACL,MAAM,kBAAkB,cAAc,kBAAkB,SAAS,IAAI,QAAQ;CAC9E,MAAM,WAAW,MAAM,oBAAoB,cAAc;CAGzD,MAAM,YAAY,MAAM,0BAA0B;EACjD;EACA,iBAJ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-
import { resolveStaticLabel } from "
|
|
1
|
+
import { resolveStaticLabel } from "../../../utils/resolveStaticLabel.js";
|
|
2
2
|
import { IconLibrarySelect } from "../client/IconLibrarySelect.js";
|
|
3
3
|
import { getIconLibraryOptions } from "../server/libraryOptions.js";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconLibrarySelectServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconLibrarySelectServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport type { ReactNode } from 'react'\nimport type { IconAdapter } from '../../../types'\nimport {
|
|
1
|
+
{"version":3,"file":"IconLibrarySelectServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconLibrarySelectServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport type { ReactNode } from 'react'\nimport type { IconAdapter } from '../../../types'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { IconLibrarySelect } from '../client/IconLibrarySelect'\nimport { getIconLibraryOptions } from '../server/libraryOptions'\n\ntype ServerProps = { adapters?: IconAdapter[] } & TextFieldServerProps\n\n/** Resolves selectable library options (inline beats registry) and renders the client select. */\nexport const IconLibrarySelectServer = (props: ServerProps): ReactNode => {\n\tconst { clientField, i18n, path, payload, permissions, readOnly, schemaPath } = props\n\tconst options = getIconLibraryOptions(payload.config, props.adapters).map((option) => ({\n\t\tlabel: resolveStaticLabel(option.label, i18n.language) ?? option.value,\n\t\tvalue: option.value,\n\t}))\n\treturn (\n\t\t<IconLibrarySelect\n\t\t\tfield={clientField}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\treadOnly={readOnly}\n\t\t\tschemaPath={schemaPath}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;AAUA,MAAa,2BAA2B,UAAkC;CACzE,MAAM,EAAE,aAAa,MAAM,MAAM,SAAS,aAAa,UAAU,eAAe;CAKhF,OACC,oBAAC,mBAAD;EACC,OAAO;EACP,SAPc,sBAAsB,QAAQ,QAAQ,MAAM,QAAQ,EAAE,KAAK,YAAY;GACtF,OAAO,mBAAmB,OAAO,OAAO,KAAK,QAAQ,KAAK,OAAO;GACjE,OAAO,OAAO;EACf,EAIiB;EACT;EACO;EACH;EACE;CACZ,CAAA;AAEH"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { resolveStaticLabel } from "../../../utils/resolveStaticLabel.js";
|
|
1
2
|
import { formatIconLabel } from "./formatIconLabel.js";
|
|
2
|
-
import { resolveStaticLabel } from "./resolveStaticLabel.js";
|
|
3
3
|
//#region src/fields/icon/shared/iconLabel.ts
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the display text for one icon. A library-supplied `label` wins; otherwise
|