@10x-media/fields 0.1.0-beta.9 → 4.0.0-alpha.1
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 +6 -0
- package/README.md +8 -3
- package/dist/fields/color/client/ColorInput.js +17 -6
- package/dist/fields/color/client/ColorInput.js.map +1 -1
- package/dist/fields/color/client/ColorPickerPanel.js +18 -12
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
- package/dist/fields/color/client/colorField.css +131 -178
- package/dist/fields/color/client/icons.js +17 -24
- package/dist/fields/color/client/icons.js.map +1 -1
- package/dist/fields/color/colorField.js +5 -3
- package/dist/fields/color/colorField.js.map +1 -1
- package/dist/fields/color/server/colorCell.css +8 -9
- package/dist/fields/encrypted/components/EncryptedInput.js +44 -26
- package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedTextarea.js +29 -29
- package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
- package/dist/fields/encrypted/components/EyeToggle.js +14 -35
- package/dist/fields/encrypted/components/EyeToggle.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedField.css +107 -159
- package/dist/fields/encrypted/components/ProtectedField.js +6 -2
- package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
- package/dist/fields/encrypted/components/RichTextRevealGate.js +3 -3
- package/dist/fields/encrypted/components/RichTextRevealGate.js.map +1 -1
- package/dist/fields/encrypted/components/WriteOnlyActions.js +58 -53
- package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -1
- package/dist/fields/encrypted/components/WriteOnlyField.js +39 -21
- package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -1
- package/dist/fields/encrypted/components/facsimiles.js +70 -79
- package/dist/fields/encrypted/components/facsimiles.js.map +1 -1
- package/dist/fields/encrypted/components/placement.js.map +1 -1
- package/dist/fields/encrypted/encryptedField.js +25 -12
- package/dist/fields/encrypted/encryptedField.js.map +1 -1
- package/dist/fields/encrypted/{typescriptSchema.js → jsonSchema.js} +4 -4
- package/dist/fields/encrypted/jsonSchema.js.map +1 -0
- package/dist/fields/encrypted/queryRewrite.js +20 -0
- package/dist/fields/encrypted/queryRewrite.js.map +1 -1
- package/dist/fields/encrypted/validators.js +1 -1
- package/dist/fields/encrypted/validators.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/nodes.js +1 -1
- package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
- package/dist/fields/icon/client/IconDrawerContent.js +8 -6
- package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
- package/dist/fields/icon/client/IconFieldClient.js +15 -37
- package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
- package/dist/fields/icon/client/icon-field.css +137 -233
- package/dist/fields/icon/codegen/sources/tabler.js +25 -6
- package/dist/fields/icon/codegen/sources/tabler.js.map +1 -1
- package/dist/fields/icon/layers/upload.js +3 -0
- package/dist/fields/icon/layers/upload.js.map +1 -1
- package/dist/fields/icon/react/createIcon.js +4 -4
- package/dist/fields/icon/react/createIcon.js.map +1 -1
- package/dist/fields/measurement/client/MeasurementInput.js +18 -32
- package/dist/fields/measurement/client/MeasurementInput.js.map +1 -1
- package/dist/fields/measurement/client/measurementField.css +58 -105
- package/dist/fields/measurement/server/getUserUnits.js +2 -1
- package/dist/fields/measurement/server/getUserUnits.js.map +1 -1
- package/dist/fields/phoneNumber/client/CountryPicker.js +14 -9
- package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -1
- package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +1 -1
- package/dist/fields/phoneNumber/client/PhoneNumberField.js +22 -4
- package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -1
- package/dist/fields/phoneNumber/client/phoneNumberField.css +109 -142
- package/dist/fields/phoneNumber/phoneNumberField.js +1 -1
- package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -1
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +2 -1
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/plugin/companionSelect.d.ts +12 -0
- package/dist/plugin/companionSelect.js +107 -0
- package/dist/plugin/companionSelect.js.map +1 -0
- package/package.json +15 -15
- package/dist/fields/encrypted/typescriptSchema.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colorField.js","names":[],"sources":["../../../src/fields/color/colorField.ts"],"sourcesContent":["import type { FieldHook, JSONField, PayloadRequest, TextField, TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\nimport type { ColorFormat, ColorSchemeValue } from '../../types'\nimport { formatColor, isColorSchemeValue, parseColor } from './engine'\nimport {\n\tCOLOR_CUSTOM_KEY,\n\ttype ColorFieldCustom,\n\ttype ColorFieldOptions,\n\ttype ColorFieldServerOptions,\n\ttype ColorLinkedOptions,\n\ttype ColorPresetsSource,\n\tPRESET_PREFIX,\n} from './options'\nimport {\n\tapplyReferenceAlpha,\n\tformatPresetReference,\n\tparsePresetReference,\n\tpresetReferenceIssue,\n\tpresetReferenceParts,\n} from './presetReference'\nimport { resolveColorFormat } from './resolveFormat'\nimport { resolvePresets } from './resolvePresets'\nimport { flatValue } from './schemeValue'\n\nconst buildValidate =\n\t(opts: {\n\t\tlinked: boolean\n\t\tmemoKey: symbol\n\t\tpresets: ColorPresetsSource | undefined\n\t}): TextFieldValidation =>\n\tasync (value, args) => {\n\t\tif (typeof value === 'string' && value !== '') {\n\t\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\tlet hasKey: ((key: string) => boolean) | null = null\n\t\t\t\tif (presetReferenceParts(value)?.explicit) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst all = await resolvePresets({\n\t\t\t\t\t\t\tmemoKey: opts.memoKey,\n\t\t\t\t\t\t\treq: args.req,\n\t\t\t\t\t\t\tsource: opts.presets,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// An empty list means no presets are configured (or none resolved);\n\t\t\t\t\t\t// skip the existence check rather than rejecting every reference\n\t\t\t\t\t\tif (all.length > 0) hasKey = (key) => all.some((preset) => preset.key === key)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// A broken resolver must not block writes; reads degrade and log separately\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst issue = presetReferenceIssue(value, hasKey)\n\t\t\t\tif (issue === 'invalidAlpha') return asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t\tif (issue !== null) return asTranslate(args.req.t)(keys.missingPreset)\n\t\t\t} else if (!parseColor(value)) {\n\t\t\t\treturn asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t}\n\t\t}\n\t\treturn text(value, args)\n\t}\n\nconst buildNormalizeHook =\n\t(opts: { alpha: boolean; format: ColorFormat | undefined; linked: boolean }): FieldHook =>\n\t({ req, value }) => {\n\t\tif (typeof value !== 'string' || value === '') return value\n\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\tconst parts = presetReferenceParts(value)\n\t\t\t// Empty keys pass through so validate rejects them with a proper message\n\t\t\tif (!parts) return value\n\t\t\treturn formatPresetReference(parts.key, opts.alpha ? parts.alpha : 100)\n\t\t}\n\t\tconst parsed = parseColor(value)\n\t\t// Unparseable input passes through so validate rejects it with a proper message\n\t\tif (!parsed) return value\n\t\treturn formatColor(parsed, resolveColorFormat(opts.format, req), { alpha: opts.alpha })\n\t}\n\n/**\n * Text-backed color field storing a CSS string in the configured format.\n * Linked mode returns a tuple: the field plus a hidden virtual sibling\n * `${name}Resolved` populated on read (spread it into `fields`). The sibling\n * keeps the stored `preset:<key>` reference round-trip safe in the admin form\n * while consumers read the resolved CSS value.\n */\nexport function colorField(options?: ColorFieldOptions & { linked?: false }): TextField\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: (ColorLinkedOptions & { resolve?: 'value' }) | true }\n): [TextField, TextField]\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: ColorLinkedOptions & { resolve: 'schemes' } }\n): [TextField, JSONField]\nexport function colorField(\n\toptions: ColorFieldOptions = {}\n): TextField | [TextField, JSONField | TextField] {\n\tconst {\n\t\tname = 'color',\n\t\talpha = true,\n\t\tenableEyedropper = true,\n\t\tformat,\n\t\tisClearable = true,\n\t\tlabel,\n\t\tlinked: linkedOption = false,\n\t\tlocalized,\n\t\toverrides,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\trequired,\n\t} = options\n\n\tconst linked = linkedOption !== false\n\tconst linkedOptions: ColorLinkedOptions = typeof linkedOption === 'object' ? linkedOption : {}\n\tconst linkedFallback = linkedOptions.fallback ?? null\n\tconst resolveMode = linkedOptions.resolve ?? 'value'\n\tconst memoKey = Symbol(`colorField:${name}`)\n\n\t// format stays possibly-undefined here; ColorFieldServer resolves the effective\n\t// format (field-level, else plugin registry, else hex) per request for the client.\n\tconst clientOptions: ColorFieldServerOptions = {\n\t\talpha,\n\t\tenableEyedropper,\n\t\tformat,\n\t\tisClearable,\n\t\tlinked,\n\t\tlinkedFallback,\n\t}\n\n\tconst custom: ColorFieldCustom = { memoKey, presets, presetsLabel }\n\n\tconst base: TextField = {\n\t\tname,\n\t\ttype: 'text',\n\t\t...(label !== undefined ? { label } : {}),\n\t\t...(required !== undefined ? { required } : {}),\n\t\t...(localized !== undefined ? { localized } : {}),\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tCell: { path: '@10x-media/fields/rsc#ColorCell' },\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: { colorOptions: clientOptions },\n\t\t\t\t\tpath: '@10x-media/fields/rsc#ColorFieldServer',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tcustom: { [COLOR_CUSTOM_KEY]: custom },\n\t\thooks: { beforeValidate: [buildNormalizeHook({ alpha, format, linked })] },\n\t\tvalidate: buildValidate({ linked, memoKey, presets }),\n\t}\n\n\tconst field = typeof overrides === 'function' ? overrides({ field: base }) : base\n\n\tif (!linked) return field\n\n\tconst loggedRequests = new WeakSet<PayloadRequest>()\n\n\t/**\n\t * Shapes a resolved value for the configured sibling. 'value' flattens a\n\t * scheme to its light member so a field configured before schemes existed\n\t * keeps working when its resolver starts returning them; 'schemes' inflates\n\t * a flat color so consumers never branch on the shape.\n\t */\n\tconst shape = (value: null | string | ColorSchemeValue): null | string | ColorSchemeValue => {\n\t\tif (value === null) return null\n\t\tif (resolveMode === 'value') return flatValue(value)\n\t\treturn isColorSchemeValue(value) ? value : { dark: value, light: value }\n\t}\n\n\t/** The stored reference alpha, applied to whatever the reference resolved to. */\n\tconst withAlpha = (\n\t\tresolved: null | string | ColorSchemeValue,\n\t\trefAlpha: number,\n\t\treq: PayloadRequest\n\t): null | string | ColorSchemeValue => {\n\t\tconst effective = alpha ? refAlpha : 100\n\t\tif (resolved === null || effective === 100) return resolved\n\t\treturn applyReferenceAlpha(resolved, effective, resolveColorFormat(format, req))\n\t}\n\n\tconst resolveHook: FieldHook = async ({ collection, global, req, siblingData }) => {\n\t\tconst raw = siblingData?.[field.name]\n\t\tif (typeof raw !== 'string' || raw === '') return null\n\t\tif (!raw.startsWith(PRESET_PREFIX)) return shape(raw)\n\t\tconst ref = parsePresetReference(raw)\n\t\tconst key = ref?.key ?? raw.slice(PRESET_PREFIX.length)\n\t\tconst refAlpha = ref?.alpha ?? 100\n\t\ttry {\n\t\t\tconst all = await resolvePresets({ memoKey, req, source: presets })\n\t\t\tconst match = all.find((preset) => preset.key === key)\n\t\t\treturn withAlpha(shape(match ? match.value : linkedFallback), refAlpha, req)\n\t\t} catch (error) {\n\t\t\t// A broken resolver must not take down reads; degrade like a missing preset\n\t\t\tif (!loggedRequests.has(req)) {\n\t\t\t\tloggedRequests.add(req)\n\t\t\t\tconst slug = collection?.slug ?? global?.slug ?? 'unknown'\n\t\t\t\treq.payload.logger.error(\n\t\t\t\t\t{ err: error },\n\t\t\t\t\t`colorField preset resolver failed for ${slug}.${field.name}`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn withAlpha(shape(linkedFallback), refAlpha, req)\n\t\t}\n\t}\n\n\tconst resolvedAdmin = { disableListColumn: true, hidden: true } as const\n\n\tconst resolvedField: JSONField | TextField =\n\t\tresolveMode === 'schemes'\n\t\t\t? {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'json',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'text',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\n\treturn [field, resolvedField]\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,MAAM,iBACJ,SAKD,OAAO,OAAO,SAAS;CACtB,IAAI,OAAO,UAAU,YAAY,UAAU;MACtC,KAAK,UAAU,MAAM,WAAA,SAAwB,GAAG;GACnD,IAAI,SAA4C;GAChD,IAAI,qBAAqB,KAAK,GAAG,UAChC,IAAI;IACH,MAAM,MAAM,MAAM,eAAe;KAChC,SAAS,KAAK;KACd,KAAK,KAAK;KACV,QAAQ,KAAK;IACd,CAAC;IAGD,IAAI,IAAI,SAAS,GAAG,UAAU,QAAQ,IAAI,MAAM,WAAW,OAAO,QAAQ,GAAG;GAC9E,QAAQ,CAER;GAED,MAAM,QAAQ,qBAAqB,OAAO,MAAM;GAChD,IAAI,UAAU,gBAAgB,OAAO,YAAY,KAAK,IAAI,CAAC,EAAE,KAAK,YAAY;GAC9E,IAAI,UAAU,MAAM,OAAO,YAAY,KAAK,IAAI,CAAC,EAAE,KAAK,aAAa;EACtE,OAAO,IAAI,CAAC,WAAW,KAAK,GAC3B,OAAO,YAAY,KAAK,IAAI,CAAC,EAAE,KAAK,YA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AAG,GAAG;IAC7B,eAAe,IAAI,GAAG;IACtB,MAAM,OAAO,YAAY,QAAQ,QAAQ,QAAQ;IACjD,IAAI,QAAQ,OAAO,MAClB,EAAE,KAAK,MAAM,GACb,yCAAyC,KAAK,GAAG,MAAM,MACxD;GACD;GACA,OAAO,UAAU,MAAM,cAAc,GAAG,UAAU,GAAG;EACtD;CACD;CAEA,MAAM,gBAAgB;EAAE,mBAAmB;EAAM,QAAQ;CAAK;CAmB9D,OAAO,CAAC,OAhBP,gBAAgB,YACb;EACA,MAAM,GAAG,MAAM,KAAK;EACpB,MAAM;EACN,OAAO;EACP,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CACV,IACC;EACA,MAAM,GAAG,MAAM,KAAK;EACpB,MAAM;EACN,OAAO;EACP,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CACV,CAEyB;AAC7B"}
|
|
1
|
+
{"version":3,"file":"colorField.js","names":[],"sources":["../../../src/fields/color/colorField.ts"],"sourcesContent":["import type { FieldHook, JSONField, PayloadRequest, TextField, TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { withCompanions } from '../../plugin/companionSelect'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\nimport type { ColorFormat, ColorSchemeValue } from '../../types'\nimport { formatColor, isColorSchemeValue, parseColor } from './engine'\nimport {\n\tCOLOR_CUSTOM_KEY,\n\ttype ColorFieldCustom,\n\ttype ColorFieldOptions,\n\ttype ColorFieldServerOptions,\n\ttype ColorLinkedOptions,\n\ttype ColorPresetsSource,\n\tPRESET_PREFIX,\n} from './options'\nimport {\n\tapplyReferenceAlpha,\n\tformatPresetReference,\n\tparsePresetReference,\n\tpresetReferenceIssue,\n\tpresetReferenceParts,\n} from './presetReference'\nimport { resolveColorFormat } from './resolveFormat'\nimport { resolvePresets } from './resolvePresets'\nimport { flatValue } from './schemeValue'\n\nconst buildValidate =\n\t(opts: {\n\t\tlinked: boolean\n\t\tmemoKey: symbol\n\t\tpresets: ColorPresetsSource | undefined\n\t}): TextFieldValidation =>\n\tasync (value, args) => {\n\t\tif (typeof value === 'string' && value !== '') {\n\t\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\tlet hasKey: ((key: string) => boolean) | null = null\n\t\t\t\tif (presetReferenceParts(value)?.explicit) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst all = await resolvePresets({\n\t\t\t\t\t\t\tmemoKey: opts.memoKey,\n\t\t\t\t\t\t\treq: args.req,\n\t\t\t\t\t\t\tsource: opts.presets,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// An empty list means no presets are configured (or none resolved);\n\t\t\t\t\t\t// skip the existence check rather than rejecting every reference\n\t\t\t\t\t\tif (all.length > 0) hasKey = (key) => all.some((preset) => preset.key === key)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// A broken resolver must not block writes; reads degrade and log separately\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst issue = presetReferenceIssue(value, hasKey)\n\t\t\t\tif (issue === 'invalidAlpha') return asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t\tif (issue !== null) return asTranslate(args.req.t)(keys.missingPreset)\n\t\t\t} else if (!parseColor(value)) {\n\t\t\t\treturn asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t}\n\t\t}\n\t\treturn text(value, args)\n\t}\n\nconst buildNormalizeHook =\n\t(opts: { alpha: boolean; format: ColorFormat | undefined; linked: boolean }): FieldHook =>\n\t({ req, value }) => {\n\t\tif (typeof value !== 'string' || value === '') return value\n\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\tconst parts = presetReferenceParts(value)\n\t\t\t// Empty keys pass through so validate rejects them with a proper message\n\t\t\tif (!parts) return value\n\t\t\treturn formatPresetReference(parts.key, opts.alpha ? parts.alpha : 100)\n\t\t}\n\t\tconst parsed = parseColor(value)\n\t\t// Unparseable input passes through so validate rejects it with a proper message\n\t\tif (!parsed) return value\n\t\treturn formatColor(parsed, resolveColorFormat(opts.format, req), { alpha: opts.alpha })\n\t}\n\n/**\n * Text-backed color field storing a CSS string in the configured format.\n * Linked mode returns a tuple: the field plus a hidden virtual sibling\n * `${name}Resolved` populated on read (spread it into `fields`). The sibling\n * keeps the stored `preset:<key>` reference round-trip safe in the admin form\n * while consumers read the resolved CSS value.\n */\nexport function colorField(options?: ColorFieldOptions & { linked?: false }): TextField\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: (ColorLinkedOptions & { resolve?: 'value' }) | true }\n): [TextField, TextField]\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: ColorLinkedOptions & { resolve: 'schemes' } }\n): [TextField, JSONField]\nexport function colorField(\n\toptions: ColorFieldOptions = {}\n): TextField | [TextField, JSONField | TextField] {\n\tconst {\n\t\tname = 'color',\n\t\talpha = true,\n\t\tenableEyedropper = true,\n\t\tformat,\n\t\tisClearable = true,\n\t\tlabel,\n\t\tlinked: linkedOption = false,\n\t\tlocalized,\n\t\toverrides,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\trequired,\n\t} = options\n\n\tconst linked = linkedOption !== false\n\tconst linkedOptions: ColorLinkedOptions = typeof linkedOption === 'object' ? linkedOption : {}\n\tconst linkedFallback = linkedOptions.fallback ?? null\n\tconst resolveMode = linkedOptions.resolve ?? 'value'\n\tconst memoKey = Symbol(`colorField:${name}`)\n\n\t// format stays possibly-undefined here; ColorFieldServer resolves the effective\n\t// format (field-level, else plugin registry, else hex) per request for the client.\n\tconst clientOptions: ColorFieldServerOptions = {\n\t\talpha,\n\t\tenableEyedropper,\n\t\tformat,\n\t\tisClearable,\n\t\tlinked,\n\t\tlinkedFallback,\n\t}\n\n\tconst custom: ColorFieldCustom = { memoKey, presets, presetsLabel }\n\n\tconst base: TextField = {\n\t\tname,\n\t\ttype: 'text',\n\t\t...(label !== undefined ? { label } : {}),\n\t\t...(required !== undefined ? { required } : {}),\n\t\t...(localized !== undefined ? { localized } : {}),\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tCell: { path: '@10x-media/fields/rsc#ColorCell' },\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: { colorOptions: clientOptions },\n\t\t\t\t\tpath: '@10x-media/fields/rsc#ColorFieldServer',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tcustom: { [COLOR_CUSTOM_KEY]: custom },\n\t\thooks: { beforeValidate: [buildNormalizeHook({ alpha, format, linked })] },\n\t\tvalidate: buildValidate({ linked, memoKey, presets }),\n\t}\n\n\tconst field = typeof overrides === 'function' ? overrides({ field: base }) : base\n\n\tif (!linked) return field\n\n\tconst loggedRequests = new WeakSet<PayloadRequest>()\n\n\t/**\n\t * Shapes a resolved value for the configured sibling. 'value' flattens a\n\t * scheme to its light member so a field configured before schemes existed\n\t * keeps working when its resolver starts returning them; 'schemes' inflates\n\t * a flat color so consumers never branch on the shape.\n\t */\n\tconst shape = (value: null | string | ColorSchemeValue): null | string | ColorSchemeValue => {\n\t\tif (value === null) return null\n\t\tif (resolveMode === 'value') return flatValue(value)\n\t\treturn isColorSchemeValue(value) ? value : { dark: value, light: value }\n\t}\n\n\t/** The stored reference alpha, applied to whatever the reference resolved to. */\n\tconst withAlpha = (\n\t\tresolved: null | string | ColorSchemeValue,\n\t\trefAlpha: number,\n\t\treq: PayloadRequest\n\t): null | string | ColorSchemeValue => {\n\t\tconst effective = alpha ? refAlpha : 100\n\t\tif (resolved === null || effective === 100) return resolved\n\t\treturn applyReferenceAlpha(resolved, effective, resolveColorFormat(format, req))\n\t}\n\n\tconst resolveHook: FieldHook = async ({ collection, global, req, siblingData }) => {\n\t\tconst raw = siblingData?.[field.name]\n\t\tif (typeof raw !== 'string' || raw === '') return null\n\t\tif (!raw.startsWith(PRESET_PREFIX)) return shape(raw)\n\t\tconst ref = parsePresetReference(raw)\n\t\tconst key = ref?.key ?? raw.slice(PRESET_PREFIX.length)\n\t\tconst refAlpha = ref?.alpha ?? 100\n\t\ttry {\n\t\t\tconst all = await resolvePresets({ memoKey, req, source: presets })\n\t\t\tconst match = all.find((preset) => preset.key === key)\n\t\t\treturn withAlpha(shape(match ? match.value : linkedFallback), refAlpha, req)\n\t\t} catch (error) {\n\t\t\t// A broken resolver must not take down reads; degrade like a missing preset\n\t\t\tif (!loggedRequests.has(req)) {\n\t\t\t\tloggedRequests.add(req)\n\t\t\t\tconst slug = collection?.slug ?? global?.slug ?? 'unknown'\n\t\t\t\treq.payload.logger.error(\n\t\t\t\t\t{ err: error },\n\t\t\t\t\t`colorField preset resolver failed for ${slug}.${field.name}`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn withAlpha(shape(linkedFallback), refAlpha, req)\n\t\t}\n\t}\n\n\tconst resolvedAdmin = { disabled: { column: true }, hidden: true } as const\n\n\tconst resolvedField: JSONField | TextField =\n\t\tresolveMode === 'schemes'\n\t\t\t? {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'json',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'text',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\n\t// The list Cell renders a linked value from its resolved sibling.\n\treturn [withCompanions(field, [resolvedField.name]), resolvedField]\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAM,iBACJ,SAKD,OAAO,OAAO,SAAS;CACtB,IAAI,OAAO,UAAU,YAAY,UAAU;MACtC,KAAK,UAAU,MAAM,WAAA,SAAwB,GAAG;GACnD,IAAI,SAA4C;GAChD,IAAI,qBAAqB,KAAK,GAAG,UAChC,IAAI;IACH,MAAM,MAAM,MAAM,eAAe;KAChC,SAAS,KAAK;KACd,KAAK,KAAK;KACV,QAAQ,KAAK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 @@
|
|
|
9
9
|
width: 16px;
|
|
10
10
|
height: 16px;
|
|
11
11
|
overflow: hidden;
|
|
12
|
-
border:
|
|
13
|
-
border-radius: var(--
|
|
12
|
+
border: var(--stroke-width-small) solid var(--field-color-border);
|
|
13
|
+
border-radius: var(--radius-chip);
|
|
14
14
|
background-image: conic-gradient(
|
|
15
|
-
var(--
|
|
15
|
+
var(--color-bg-tertiary) 0 25%,
|
|
16
16
|
transparent 0 50%,
|
|
17
|
-
var(--
|
|
17
|
+
var(--color-bg-tertiary) 0 75%,
|
|
18
18
|
transparent 0
|
|
19
19
|
);
|
|
20
20
|
background-size: 8px 8px;
|
|
21
|
+
background-clip: padding-box;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
.fields-color-cell__swatch > span {
|
|
@@ -27,11 +28,9 @@
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
.fields-color-cell__alpha {
|
|
30
|
-
color: var(--
|
|
31
|
-
font-size: 0.75rem;
|
|
31
|
+
color: var(--color-text-secondary);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
.fields-color-cell__missing {
|
|
35
|
-
color: var(--
|
|
36
|
-
font-size: 0.75rem;
|
|
35
|
+
color: var(--color-text-danger);
|
|
37
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { EyeToggle } from "./EyeToggle.js";
|
|
3
3
|
import { dotString } from "./MaskDots.js";
|
|
4
|
-
import { FieldDescription, FieldError, FieldLabel, useField, useFormFields, useFormSubmitted } from "@payloadcms/ui";
|
|
4
|
+
import { FieldDescription, FieldError, FieldLabel, InputStepper, useField, useFormFields, useFormSubmitted } from "@payloadcms/ui";
|
|
5
5
|
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
6
6
|
import { useCallback, useMemo, useState } from "react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -14,9 +14,10 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
* Concealed, the input is readOnly and its value is the dot run, so the decrypted
|
|
15
15
|
* plaintext (already in form state from afterRead) never reaches the DOM and
|
|
16
16
|
* masking cannot mutate form state; setValue only runs while revealed. The eye is
|
|
17
|
-
* a sibling flex segment that stays put across toggles.
|
|
17
|
+
* a sibling flex segment that stays put across toggles. Read-only still reveals
|
|
18
|
+
* (that is reading), but the input is disabled, as on a native field.
|
|
18
19
|
*/
|
|
19
|
-
const EncryptedInput = ({ field, kind, maskDots, path }) => {
|
|
20
|
+
const EncryptedInput = ({ field, kind, maskDots, path, readOnly }) => {
|
|
20
21
|
const [revealed, setRevealed] = useState(false);
|
|
21
22
|
const { setValue, showError, value } = useField({ path });
|
|
22
23
|
const submitted = useFormSubmitted();
|
|
@@ -33,6 +34,9 @@ const EncryptedInput = ({ field, kind, maskDots, path }) => {
|
|
|
33
34
|
}
|
|
34
35
|
setValue(event.target.value);
|
|
35
36
|
};
|
|
37
|
+
const handleStep = (direction) => {
|
|
38
|
+
setValue((typeof value === "number" ? value : 0) + direction * (field.admin?.step ?? 1));
|
|
39
|
+
};
|
|
36
40
|
const revealedValue = isNumber ? typeof value === "number" ? value : "" : typeof value === "string" ? value : "";
|
|
37
41
|
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
38
42
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -41,7 +45,8 @@ const EncryptedInput = ({ field, kind, maskDots, path }) => {
|
|
|
41
45
|
kind,
|
|
42
46
|
showFieldError && "error",
|
|
43
47
|
"tenx-protected-field",
|
|
44
|
-
"tenx-protected-field--attached"
|
|
48
|
+
"tenx-protected-field--attached",
|
|
49
|
+
readOnly && "read-only"
|
|
45
50
|
].filter(Boolean).join(" "),
|
|
46
51
|
style: styles,
|
|
47
52
|
children: [/* @__PURE__ */ jsx(FieldLabel, {
|
|
@@ -54,29 +59,42 @@ const EncryptedInput = ({ field, kind, maskDots, path }) => {
|
|
|
54
59
|
children: [
|
|
55
60
|
/* @__PURE__ */ jsx(FieldError, { path }),
|
|
56
61
|
/* @__PURE__ */ jsxs("div", {
|
|
57
|
-
className:
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
revealed
|
|
62
|
+
className: [
|
|
63
|
+
"form-input-group",
|
|
64
|
+
showFieldError && "form-input-group-error",
|
|
65
|
+
"tenx-protected-field__attached-row"
|
|
66
|
+
].filter(Boolean).join(" "),
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ jsx("input", {
|
|
69
|
+
"aria-invalid": revealed ? showError : void 0,
|
|
70
|
+
autoComplete: revealed && !isNumber ? field.admin?.autoComplete : void 0,
|
|
71
|
+
className: ["form-input", revealed ? "tenx-protected-field__revealed-input" : "tenx-protected-field__masked-input"].join(" "),
|
|
72
|
+
disabled: readOnly,
|
|
73
|
+
id: inputId,
|
|
74
|
+
inputMode: revealed && isNumber ? "decimal" : void 0,
|
|
75
|
+
name: path,
|
|
76
|
+
onChange: revealed ? handleChange : void 0,
|
|
77
|
+
placeholder: revealed && !isNumber && typeof field.admin?.placeholder === "string" ? field.admin.placeholder : void 0,
|
|
78
|
+
readOnly: !revealed,
|
|
79
|
+
step: revealed && isNumber ? field.admin?.step : void 0,
|
|
80
|
+
tabIndex: revealed ? void 0 : -1,
|
|
81
|
+
type: revealed ? isNumber ? "number" : kind === "email" ? "email" : "text" : "text",
|
|
82
|
+
value: revealed ? revealedValue : dotString(maskDots)
|
|
83
|
+
}),
|
|
84
|
+
isNumber ? /* @__PURE__ */ jsx(InputStepper, {
|
|
85
|
+
disabled: !revealed || readOnly,
|
|
86
|
+
onDecrement: () => handleStep(-1),
|
|
87
|
+
onIncrement: () => handleStep(1)
|
|
88
|
+
}) : null,
|
|
89
|
+
/* @__PURE__ */ jsx("div", {
|
|
90
|
+
className: "tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--attached",
|
|
91
|
+
children: /* @__PURE__ */ jsx(EyeToggle, {
|
|
92
|
+
className: "tenx-protected-field__eye--attached",
|
|
93
|
+
onToggle: toggle,
|
|
94
|
+
revealed
|
|
95
|
+
})
|
|
78
96
|
})
|
|
79
|
-
|
|
97
|
+
]
|
|
80
98
|
}),
|
|
81
99
|
/* @__PURE__ */ jsx(FieldDescription, {
|
|
82
100
|
description: field.admin?.description,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptedInput.js","names":[],"sources":["../../../../src/fields/encrypted/components/EncryptedInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type React from 'react'\nimport { useCallback, useMemo, useState } from 'react'\nimport { EyeToggle } from './EyeToggle'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig } from './placement'\n\ntype InputKind = 'email' | 'number' | 'text'\n\ninterface EncryptedInputProps {\n\tfield: EncryptedFieldConfig\n\tkind: InputKind\n\tmaskDots: number\n\tpath: string\n}\n\n/**\n * Attached-placement field for single text, email, and number. One input is\n * mounted in both states and only morphs on toggle: a readOnly dots facsimile\n * while concealed, the bound editable input while revealed. Reusing the same\n * element means revealing never remounts the control and never shifts layout.\n * Concealed, the input is readOnly and its value is the dot run, so the decrypted\n * plaintext (already in form state from afterRead) never reaches the DOM and\n * masking cannot mutate form state; setValue only runs while revealed. The eye is\n * a sibling flex segment that stays put across toggles.\n */\nexport const EncryptedInput: React.FC<EncryptedInputProps> = ({
|
|
1
|
+
{"version":3,"file":"EncryptedInput.js","names":[],"sources":["../../../../src/fields/encrypted/components/EncryptedInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tInputStepper,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type React from 'react'\nimport { useCallback, useMemo, useState } from 'react'\nimport { EyeToggle } from './EyeToggle'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig } from './placement'\n\ntype InputKind = 'email' | 'number' | 'text'\n\ninterface EncryptedInputProps {\n\tfield: EncryptedFieldConfig\n\tkind: InputKind\n\tmaskDots: number\n\tpath: string\n\treadOnly?: boolean\n}\n\n/**\n * Attached-placement field for single text, email, and number. One input is\n * mounted in both states and only morphs on toggle: a readOnly dots facsimile\n * while concealed, the bound editable input while revealed. Reusing the same\n * element means revealing never remounts the control and never shifts layout.\n * Concealed, the input is readOnly and its value is the dot run, so the decrypted\n * plaintext (already in form state from afterRead) never reaches the DOM and\n * masking cannot mutate form state; setValue only runs while revealed. The eye is\n * a sibling flex segment that stays put across toggles. Read-only still reveals\n * (that is reading), but the input is disabled, as on a native field.\n */\nexport const EncryptedInput: React.FC<EncryptedInputProps> = ({\n\tfield,\n\tkind,\n\tmaskDots,\n\tpath,\n\treadOnly,\n}) => {\n\tconst [revealed, setRevealed] = useState(false)\n\tconst { setValue, showError, value } = useField<number | string>({ path })\n\tconst submitted = useFormSubmitted()\n\tconst invalid = useFormFields(([fields]) => fields?.[path]?.valid === false)\n\tconst showFieldError = submitted && invalid\n\tconst toggle = useCallback(() => setRevealed((prev) => !prev), [])\n\tconst inputId = `field-${path.replace(/\\./g, '__')}`\n\tconst isNumber = kind === 'number'\n\n\tconst handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\tif (isNumber) {\n\t\t\tconst parsed = Number.parseFloat(event.target.value)\n\t\t\tsetValue(Number.isNaN(parsed) ? null : parsed)\n\t\t\treturn\n\t\t}\n\t\tsetValue(event.target.value)\n\t}\n\n\t// Native number fields carry Payload's stepper inside the input group; it\n\t// stays mounted while concealed (disabled) so revealing never shifts layout.\n\tconst handleStep = (direction: 1 | -1) => {\n\t\tconst current = typeof value === 'number' ? value : 0\n\t\tsetValue(current + direction * (field.admin?.step ?? 1))\n\t}\n\n\tconst revealedValue = isNumber\n\t\t? typeof value === 'number'\n\t\t\t? value\n\t\t\t: ''\n\t\t: typeof value === 'string'\n\t\t\t? value\n\t\t\t: ''\n\n\t// A custom Field component short-circuits the path where Payload applies\n\t// admin.width and admin.style, so the field has to carry them itself.\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\t'field-type',\n\t\t\t\tkind,\n\t\t\t\tshowFieldError && 'error',\n\t\t\t\t'tenx-protected-field',\n\t\t\t\t'tenx-protected-field--attached',\n\t\t\t\treadOnly && '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<FieldLabel\n\t\t\t\tlabel={field.label}\n\t\t\t\tlocalized={field.localized}\n\t\t\t\tpath={path}\n\t\t\t\trequired={field.required}\n\t\t\t/>\n\t\t\t<div className=\"field-type__wrap\">\n\t\t\t\t<FieldError path={path} />\n\t\t\t\t<div\n\t\t\t\t\tclassName={[\n\t\t\t\t\t\t'form-input-group',\n\t\t\t\t\t\tshowFieldError && 'form-input-group-error',\n\t\t\t\t\t\t'tenx-protected-field__attached-row',\n\t\t\t\t\t]\n\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t.join(' ')}\n\t\t\t\t>\n\t\t\t\t\t<input\n\t\t\t\t\t\taria-invalid={revealed ? showError : undefined}\n\t\t\t\t\t\tautoComplete={revealed && !isNumber ? field.admin?.autoComplete : undefined}\n\t\t\t\t\t\tclassName={[\n\t\t\t\t\t\t\t'form-input',\n\t\t\t\t\t\t\trevealed\n\t\t\t\t\t\t\t\t? 'tenx-protected-field__revealed-input'\n\t\t\t\t\t\t\t\t: 'tenx-protected-field__masked-input',\n\t\t\t\t\t\t].join(' ')}\n\t\t\t\t\t\tdisabled={readOnly}\n\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\tinputMode={revealed && isNumber ? 'decimal' : undefined}\n\t\t\t\t\t\tname={path}\n\t\t\t\t\t\tonChange={revealed ? handleChange : undefined}\n\t\t\t\t\t\tplaceholder={\n\t\t\t\t\t\t\trevealed && !isNumber && typeof field.admin?.placeholder === 'string'\n\t\t\t\t\t\t\t\t? field.admin.placeholder\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\treadOnly={!revealed}\n\t\t\t\t\t\tstep={revealed && isNumber ? field.admin?.step : undefined}\n\t\t\t\t\t\ttabIndex={revealed ? undefined : -1}\n\t\t\t\t\t\ttype={revealed ? (isNumber ? 'number' : kind === 'email' ? 'email' : 'text') : 'text'}\n\t\t\t\t\t\tvalue={revealed ? revealedValue : dotString(maskDots)}\n\t\t\t\t\t/>\n\t\t\t\t\t{isNumber ? (\n\t\t\t\t\t\t<InputStepper\n\t\t\t\t\t\t\tdisabled={!revealed || readOnly}\n\t\t\t\t\t\t\tonDecrement={() => handleStep(-1)}\n\t\t\t\t\t\t\tonIncrement={() => handleStep(1)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--attached\">\n\t\t\t\t\t\t<EyeToggle\n\t\t\t\t\t\t\tclassName=\"tenx-protected-field__eye--attached\"\n\t\t\t\t\t\t\tonToggle={toggle}\n\t\t\t\t\t\t\trevealed={revealed}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<FieldDescription description={field.admin?.description} path={path} />\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,MAAa,kBAAiD,EAC7D,OACA,MACA,UACA,MACA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W,YAAY,KAAA;OACrC,cAAc,YAAY,CAAC,WAAW,MAAM,OAAO,eAAe,KAAA;OAClE,WAAW,CACV,cACA,WACG,yCACA,oCACJ,EAAE,KAAK,GAAG;OACV,UAAU;OACV,IAAI;OACJ,WAAW,YAAY,WAAW,YAAY,KAAA;OAC9C,MAAM;OACN,UAAU,WAAW,eAAe,KAAA;OACpC,aACC,YAAY,CAAC,YAAY,OAAO,MAAM,OAAO,gBAAgB,WAC1D,MAAM,MAAM,cACZ,KAAA;OAEJ,UAAU,CAAC;OACX,MAAM,YAAY,WAAW,MAAM,OAAO,OAAO,KAAA;OACjD,UAAU,WAAW,KAAA,IAAY;OACjC,MAAM,WAAY,WAAW,WAAW,SAAS,UAAU,UAAU,SAAU;OAC/E,OAAO,WAAW,gBAAgB,UAAU,QAAQ;MACpD,CAAA;MACA,WACA,oBAAC,cAAD;OACC,UAAU,CAAC,YAAY;OACvB,mBAAmB,WAAW,EAAE;OAChC,mBAAmB,WAAW,CAAC;MAC/B,CAAA,IACE;MACJ,oBAAC,OAAD;OAAK,WAAU;iBACd,oBAAC,WAAD;QACC,WAAU;QACV,UAAU;QACA;OACV,CAAA;MACG,CAAA;KACD;;IACL,oBAAC,kBAAD;KAAkB,aAAa,MAAM,OAAO;KAAmB;IAAO,CAAA;GAClE;IACD;;AAEP"}
|
|
@@ -11,27 +11,25 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
* concealed state renders a readOnly dots textarea instead, so masking cannot
|
|
12
12
|
* write form state. Validation stays server-side.
|
|
13
13
|
*/
|
|
14
|
-
const BoundTextarea = ({ field, path }) => {
|
|
14
|
+
const BoundTextarea = ({ field, path, readOnly }) => {
|
|
15
15
|
const { setValue, value } = useField({ path });
|
|
16
|
-
return /* @__PURE__ */ jsx("
|
|
17
|
-
className: "textarea
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
value: typeof value === "string" ? value : ""
|
|
25
|
-
})
|
|
16
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
17
|
+
className: "form-input tenx-protected-field__revealed-textarea",
|
|
18
|
+
disabled: readOnly,
|
|
19
|
+
id: `field-${path.replace(/\./g, "__")}`,
|
|
20
|
+
name: path,
|
|
21
|
+
onChange: (event) => setValue(event.target.value),
|
|
22
|
+
rows: field.admin?.rows,
|
|
23
|
+
value: typeof value === "string" ? value : ""
|
|
26
24
|
});
|
|
27
25
|
};
|
|
28
26
|
/**
|
|
29
27
|
* Corner-placement wrapper for textarea. Renders the stable native chrome with
|
|
30
|
-
* the eye pinned to the top-right corner of the
|
|
28
|
+
* the eye pinned to the top-right corner of the textarea; only the textarea
|
|
31
29
|
* swaps between the concealed dots facsimile and the bound textarea. The wrapper
|
|
32
30
|
* only reads form state (no `useField`, no `setValue`).
|
|
33
31
|
*/
|
|
34
|
-
const EncryptedTextarea = ({ field, maskDots, path }) => {
|
|
32
|
+
const EncryptedTextarea = ({ field, maskDots, path, readOnly }) => {
|
|
35
33
|
const [revealed, setRevealed] = useState(false);
|
|
36
34
|
const submitted = useFormSubmitted();
|
|
37
35
|
const invalid = useFormFields(([fields]) => fields?.[path]?.valid === false);
|
|
@@ -43,7 +41,8 @@ const EncryptedTextarea = ({ field, maskDots, path }) => {
|
|
|
43
41
|
"textarea",
|
|
44
42
|
showError && "error",
|
|
45
43
|
"tenx-protected-field",
|
|
46
|
-
"tenx-protected-field--corner"
|
|
44
|
+
"tenx-protected-field--corner",
|
|
45
|
+
readOnly && "read-only"
|
|
47
46
|
].filter(Boolean).join(" "),
|
|
48
47
|
style: styles,
|
|
49
48
|
children: [/* @__PURE__ */ jsx(FieldLabel, {
|
|
@@ -55,26 +54,27 @@ const EncryptedTextarea = ({ field, maskDots, path }) => {
|
|
|
55
54
|
className: "field-type__wrap",
|
|
56
55
|
children: [
|
|
57
56
|
/* @__PURE__ */ jsx(FieldError, { path }),
|
|
58
|
-
|
|
59
|
-
field,
|
|
60
|
-
path
|
|
61
|
-
}) : /* @__PURE__ */ jsx("div", {
|
|
57
|
+
/* @__PURE__ */ jsxs("div", {
|
|
62
58
|
className: "textarea-outer",
|
|
63
|
-
children: /* @__PURE__ */ jsx(
|
|
64
|
-
|
|
59
|
+
children: [revealed ? /* @__PURE__ */ jsx(BoundTextarea, {
|
|
60
|
+
field,
|
|
61
|
+
path,
|
|
62
|
+
readOnly
|
|
63
|
+
}) : /* @__PURE__ */ jsx("textarea", {
|
|
64
|
+
className: "form-input tenx-protected-field__masked-textarea",
|
|
65
|
+
disabled: readOnly,
|
|
65
66
|
readOnly: true,
|
|
66
67
|
rows: field.admin?.rows,
|
|
67
68
|
tabIndex: -1,
|
|
68
69
|
value: dotString(maskDots)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})
|
|
70
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
71
|
+
className: "tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--corner",
|
|
72
|
+
children: /* @__PURE__ */ jsx(EyeToggle, {
|
|
73
|
+
className: "tenx-protected-field__eye--floating",
|
|
74
|
+
onToggle: () => setRevealed((prev) => !prev),
|
|
75
|
+
revealed
|
|
76
|
+
})
|
|
77
|
+
})]
|
|
78
78
|
}),
|
|
79
79
|
/* @__PURE__ */ jsx(FieldDescription, {
|
|
80
80
|
description: field.admin?.description,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptedTextarea.js","names":[],"sources":["../../../../src/fields/encrypted/components/EncryptedTextarea.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport { EyeToggle } from './EyeToggle'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig } from './placement'\n\ninterface EncryptedTextareaProps {\n\tfield: EncryptedFieldConfig\n\tmaskDots: number\n\tpath: string\n}\n\n/**\n * The revealed, bound textarea. The only part that calls `useField`; the\n * concealed state renders a readOnly dots textarea instead, so masking cannot\n * write form state. Validation stays server-side.\n */\nconst BoundTextarea: React.FC<{
|
|
1
|
+
{"version":3,"file":"EncryptedTextarea.js","names":[],"sources":["../../../../src/fields/encrypted/components/EncryptedTextarea.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport { EyeToggle } from './EyeToggle'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig } from './placement'\n\ninterface EncryptedTextareaProps {\n\tfield: EncryptedFieldConfig\n\tmaskDots: number\n\tpath: string\n\treadOnly?: boolean\n}\n\n/**\n * The revealed, bound textarea. The only part that calls `useField`; the\n * concealed state renders a readOnly dots textarea instead, so masking cannot\n * write form state. Validation stays server-side.\n */\nconst BoundTextarea: React.FC<{\n\tfield: EncryptedFieldConfig\n\tpath: string\n\treadOnly?: boolean\n}> = ({ field, path, readOnly }) => {\n\tconst { setValue, value } = useField<string>({ path })\n\treturn (\n\t\t<textarea\n\t\t\tclassName=\"form-input tenx-protected-field__revealed-textarea\"\n\t\t\tdisabled={readOnly}\n\t\t\tid={`field-${path.replace(/\\./g, '__')}`}\n\t\t\tname={path}\n\t\t\tonChange={(event) => setValue(event.target.value)}\n\t\t\trows={field.admin?.rows}\n\t\t\tvalue={typeof value === 'string' ? value : ''}\n\t\t/>\n\t)\n}\n\n/**\n * Corner-placement wrapper for textarea. Renders the stable native chrome with\n * the eye pinned to the top-right corner of the textarea; only the textarea\n * swaps between the concealed dots facsimile and the bound textarea. The wrapper\n * only reads form state (no `useField`, no `setValue`).\n */\nexport const EncryptedTextarea: React.FC<EncryptedTextareaProps> = ({\n\tfield,\n\tmaskDots,\n\tpath,\n\treadOnly,\n}) => {\n\tconst [revealed, setRevealed] = useState(false)\n\tconst submitted = useFormSubmitted()\n\tconst invalid = useFormFields(([fields]) => fields?.[path]?.valid === false)\n\tconst showError = submitted && invalid\n\t// A custom Field component short-circuits the path where Payload applies\n\t// admin.width and admin.style, so the field has to carry them itself.\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\t'field-type',\n\t\t\t\t'textarea',\n\t\t\t\tshowError && 'error',\n\t\t\t\t'tenx-protected-field',\n\t\t\t\t'tenx-protected-field--corner',\n\t\t\t\treadOnly && '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<FieldLabel\n\t\t\t\tlabel={field.label}\n\t\t\t\tlocalized={field.localized}\n\t\t\t\tpath={path}\n\t\t\t\trequired={field.required}\n\t\t\t/>\n\t\t\t<div className=\"field-type__wrap\">\n\t\t\t\t<FieldError path={path} />\n\t\t\t\t<div className=\"textarea-outer\">\n\t\t\t\t\t{revealed ? (\n\t\t\t\t\t\t<BoundTextarea field={field} path={path} readOnly={readOnly} />\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<textarea\n\t\t\t\t\t\t\tclassName=\"form-input tenx-protected-field__masked-textarea\"\n\t\t\t\t\t\t\tdisabled={readOnly}\n\t\t\t\t\t\t\treadOnly\n\t\t\t\t\t\t\trows={field.admin?.rows}\n\t\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\t\tvalue={dotString(maskDots)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--corner\">\n\t\t\t\t\t\t<EyeToggle\n\t\t\t\t\t\t\tclassName=\"tenx-protected-field__eye--floating\"\n\t\t\t\t\t\t\tonToggle={() => setRevealed((prev) => !prev)}\n\t\t\t\t\t\t\trevealed={revealed}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<FieldDescription description={field.admin?.description} path={path} />\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,MAAM,iBAIA,EAAE,OAAO,MAAM,eAAe;CACnC,MAAM,EAAE,UAAU,UAAU,SAAiB,EAAE,KAAK,CAAC;CACrD,OACC,oBAAC,YAAD;EACC,WAAU;EACV,UAAU;EACV,IAAI,SAAS,KAAK,QAAQ,OAAO,IAAI;EACrC,MAAM;EACN,WAAW,UAAU,SAAS,MAAM,OAAO,KAAK;EAChD,MAAM,MAAM,OAAO;EACnB,OAAO,OAAO,UAAU,WAAW,QAAQ;CAC3C,CAAA;AAEH;;;;;;;AAQA,MAAa,qBAAuD,EACnE,OACA,UACA,MACA,eACK;CACL,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,YAAY,iBAAiB;CACnC,MAAM,UAAU,eAAe,CAAC,YAAY,SAAS,OAAO,UAAU,KAAK;CAC3E,MAAM,YAAY,aAAa;CAG/B,MAAM,SAAS,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE7D,OACC,qBAAC,OAAD;EACC,WAAW;GACV;GACA;GACA,aAAa;GACb;GACA;GACA,YAAY;EACb,EACE,OAAO,OAAO,EACd,KAAK,GAAG;EACV,OAAO;YAXR,CAaC,oBAAC,YAAD;GACC,OAAO,MAAM;GACb,WAAW,MAAM;GACX;GACN,UAAU,MAAM;EAChB,CAAA,GACD,qBAAC,OAAD;GAAK,WAAU;aAAf;IACC,oBAAC,YAAD,EAAkB,KAAO,CAAA;IACzB,qBAAC,OAAD;KAAK,WAAU;eAAf,CACE,WACA,oBAAC,eAAD;MAAsB;MAAa;MAAgB;KAAW,CAAA,IAE9D,oBAAC,YAAD;MACC,WAAU;MACV,UAAU;MACV,UAAA;MACA,MAAM,MAAM,OAAO;MACnB,UAAU;MACV,OAAO,UAAU,QAAQ;KACzB,CAAA,GAEF,oBAAC,OAAD;MAAK,WAAU;gBACd,oBAAC,WAAD;OACC,WAAU;OACV,gBAAgB,aAAa,SAAS,CAAC,IAAI;OACjC;MACV,CAAA;KACG,CAAA,CACD;;IACL,oBAAC,kBAAD;KAAkB,aAAa,MAAM,OAAO;KAAmB;IAAO,CAAA;GAClE;IACD;;AAEP"}
|
|
@@ -1,48 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { keys } from "../../../translations/keys.js";
|
|
3
3
|
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { EyeIcon } from "@payloadcms/ui";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
6
|
//#region src/fields/encrypted/components/EyeToggle.tsx
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
const EyeGlyph = ({ active }) => /* @__PURE__ */ jsx("svg", {
|
|
15
|
-
"aria-hidden": "true",
|
|
16
|
-
className: "tenx-protected-field__eye-icon",
|
|
17
|
-
viewBox: "0 0 16 12",
|
|
18
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
19
|
-
children: active ? /* @__PURE__ */ jsx("path", {
|
|
20
|
-
className: "stroke",
|
|
21
|
-
d: "M2 11.5L4.35141 9.51035M15 0.5L12.6486 2.48965M10.915 6.64887C10.6493 7.64011 9.78959 8.38832 8.7408 8.48855M10.4085 4.38511C9.94992 3.84369 9.2651 3.5 8.5 3.5C7.11929 3.5 6 4.61929 6 6C6 6.61561 6.22251 7.17926 6.59149 7.61489M10.4085 4.38511L6.59149 7.61489M10.4085 4.38511L12.6486 2.48965M6.59149 7.61489L4.35141 9.51035M14.1292 3.92915C15.0431 5.02085 15.5 6 15.5 6C15.5 6 13.1667 11 8.5 11C7.67995 11 6.93195 10.8456 6.256 10.5911M4.35141 9.51035C2.45047 8.03672 1.5 6 1.5 6C1.5 6 3.83333 1 8.5 1C10.1882 1 11.5711 1.65437 12.6486 2.48965"
|
|
22
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("circle", {
|
|
23
|
-
className: "stroke",
|
|
24
|
-
cx: "8.5",
|
|
25
|
-
cy: "6",
|
|
26
|
-
r: "2.5"
|
|
27
|
-
}), /* @__PURE__ */ jsx("path", {
|
|
28
|
-
className: "stroke",
|
|
29
|
-
d: "M8.5 1C3.83333 1 1.5 6 1.5 6C1.5 6 3.83333 11 8.5 11C13.1667 11 15.5 6 15.5 6C15.5 6 13.1667 1 8.5 1Z"
|
|
30
|
-
})] })
|
|
31
|
-
});
|
|
32
|
-
/**
|
|
33
|
-
* The reveal toggle shared by every concealed field. Present in both masked and
|
|
34
|
-
* revealed states so toggling never removes the focused control from the tree.
|
|
8
|
+
* The reveal toggle shared by every concealed field, drawn like the native
|
|
9
|
+
* password toggle: a plain button around Payload's own `EyeIcon` (struck-through
|
|
10
|
+
* while the value is shown, open while it is concealed). Present in both masked
|
|
11
|
+
* and revealed states so toggling never removes the focused control from the tree.
|
|
35
12
|
*/
|
|
36
13
|
const EyeToggle = ({ className, onToggle, revealed }) => {
|
|
37
14
|
const { t } = useTranslation$1();
|
|
38
|
-
return /* @__PURE__ */ jsx(
|
|
15
|
+
return /* @__PURE__ */ jsx("button", {
|
|
39
16
|
"aria-label": revealed ? t(keys.hideValue) : t(keys.showValue),
|
|
40
|
-
|
|
17
|
+
"aria-pressed": revealed,
|
|
41
18
|
className: ["tenx-protected-field__eye", className].filter(Boolean).join(" "),
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
onClick: onToggle,
|
|
20
|
+
type: "button",
|
|
21
|
+
children: /* @__PURE__ */ jsx(EyeIcon, {
|
|
22
|
+
active: revealed,
|
|
23
|
+
size: 24
|
|
24
|
+
})
|
|
46
25
|
});
|
|
47
26
|
};
|
|
48
27
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EyeToggle.js","names":["useTranslation"],"sources":["../../../../src/fields/encrypted/components/EyeToggle.tsx"],"sourcesContent":["'use client'\nimport {
|
|
1
|
+
{"version":3,"file":"EyeToggle.js","names":["useTranslation"],"sources":["../../../../src/fields/encrypted/components/EyeToggle.tsx"],"sourcesContent":["'use client'\nimport { EyeIcon } from '@payloadcms/ui'\nimport type React from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\n\n/**\n * The reveal toggle shared by every concealed field, drawn like the native\n * password toggle: a plain button around Payload's own `EyeIcon` (struck-through\n * while the value is shown, open while it is concealed). Present in both masked\n * and revealed states so toggling never removes the focused control from the tree.\n */\nexport const EyeToggle: React.FC<{\n\tclassName?: string\n\tonToggle: () => void\n\trevealed: boolean\n}> = ({ className, onToggle, revealed }) => {\n\tconst { t } = useTranslation()\n\treturn (\n\t\t<button\n\t\t\taria-label={revealed ? t(keys.hideValue) : t(keys.showValue)}\n\t\t\taria-pressed={revealed}\n\t\t\tclassName={['tenx-protected-field__eye', className].filter(Boolean).join(' ')}\n\t\t\tonClick={onToggle}\n\t\t\ttype=\"button\"\n\t\t>\n\t\t\t<EyeIcon active={revealed} size={24} />\n\t\t</button>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,aAIP,EAAE,WAAW,UAAU,eAAe;CAC3C,MAAM,EAAE,MAAMA,iBAAe;CAC7B,OACC,oBAAC,UAAD;EACC,cAAY,WAAW,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,SAAS;EAC3D,gBAAc;EACd,WAAW,CAAC,6BAA6B,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;EAC5E,SAAS;EACT,MAAK;YAEL,oBAAC,SAAD;GAAS,QAAQ;GAAU,MAAM;EAAK,CAAA;CAC/B,CAAA;AAEV"}
|