@10x-media/fields 0.1.0-beta.1 → 0.1.0-beta.10
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 +120 -0
- package/README.md +7 -3
- package/dist/exports/client.d.ts +10 -1
- package/dist/exports/client.js +9 -1
- package/dist/exports/color-utils.d.ts +2 -1
- package/dist/exports/color-utils.js +2 -1
- package/dist/exports/color.d.ts +2 -1
- package/dist/exports/color.js +2 -1
- package/dist/exports/encrypted.d.ts +7 -4
- package/dist/exports/encrypted.js +6 -3
- package/dist/exports/measurement-utils.d.ts +9 -0
- package/dist/exports/measurement-utils.js +8 -0
- package/dist/exports/measurement.d.ts +11 -0
- package/dist/exports/measurement.js +10 -0
- 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 +5 -1
- package/dist/exports/rsc.js +5 -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 +35 -293
- 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/client/ColorPickerPanel.d.ts +3 -1
- package/dist/fields/color/client/ColorPickerPanel.js +29 -4
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
- package/dist/fields/color/client/colorField.css +30 -0
- package/dist/fields/color/colorField.js +36 -8
- package/dist/fields/color/colorField.js.map +1 -1
- package/dist/fields/color/presetChip.js +10 -9
- package/dist/fields/color/presetChip.js.map +1 -1
- package/dist/fields/color/presetReference.d.ts +13 -0
- package/dist/fields/color/presetReference.js +94 -0
- package/dist/fields/color/presetReference.js.map +1 -0
- package/dist/fields/color/server/ColorCell.js +7 -1
- package/dist/fields/color/server/ColorCell.js.map +1 -1
- package/dist/fields/color/server/colorCell.css +5 -0
- package/dist/fields/color/valueIssue.js +23 -0
- package/dist/fields/color/valueIssue.js.map +1 -0
- package/dist/fields/encrypted/boot.js +2 -1
- package/dist/fields/encrypted/boot.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
- package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
- package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
- package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
- package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedField.css +134 -39
- package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
- package/dist/fields/encrypted/components/ProtectedField.js +14 -0
- package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
- package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
- package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
- package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
- package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
- package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
- package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
- package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
- package/dist/fields/encrypted/crypto/wire.js +1 -1
- package/dist/fields/encrypted/encryptedField.js +63 -6
- package/dist/fields/encrypted/encryptedField.js.map +1 -1
- package/dist/fields/encrypted/generateSecret.d.ts +10 -0
- package/dist/fields/encrypted/generateSecret.js +41 -0
- package/dist/fields/encrypted/generateSecret.js.map +1 -0
- package/dist/fields/encrypted/hint.js +67 -0
- package/dist/fields/encrypted/hint.js.map +1 -0
- package/dist/fields/encrypted/hooks.js +59 -31
- package/dist/fields/encrypted/hooks.js.map +1 -1
- package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
- package/dist/fields/encrypted/queryRewrite.js +34 -8
- package/dist/fields/encrypted/queryRewrite.js.map +1 -1
- package/dist/fields/encrypted/rawRead.d.ts +24 -0
- package/dist/fields/encrypted/rawRead.js +40 -0
- package/dist/fields/encrypted/rawRead.js.map +1 -0
- package/dist/fields/encrypted/scan.js +21 -4
- package/dist/fields/encrypted/scan.js.map +1 -1
- package/dist/fields/encrypted/types.d.ts +67 -2
- package/dist/fields/encrypted/types.js +8 -1
- package/dist/fields/encrypted/types.js.map +1 -1
- package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
- package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
- package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
- package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
- package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
- package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
- package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
- package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
- package/dist/fields/icon/client/icon-field.css +4 -2
- package/dist/fields/icon/codegen/emit.js +2 -2
- package/dist/fields/icon/codegen/emit.js.map +1 -1
- 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/MeasurementCell.d.ts +18 -0
- package/dist/fields/measurement/client/MeasurementCell.js +47 -0
- package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementField.d.ts +13 -0
- package/dist/fields/measurement/client/MeasurementField.js +70 -0
- package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
- 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/MeasurementUnitsProvider.d.ts +24 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
- package/dist/fields/measurement/client/editModel.js +124 -0
- package/dist/fields/measurement/client/editModel.js.map +1 -0
- package/dist/fields/measurement/client/measurementCell.css +4 -0
- package/dist/fields/measurement/client/measurementField.css +215 -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/measurement/engine/convert.d.ts +8 -0
- package/dist/fields/measurement/engine/convert.js +21 -0
- package/dist/fields/measurement/engine/convert.js.map +1 -0
- package/dist/fields/measurement/engine/format.d.ts +37 -0
- package/dist/fields/measurement/engine/format.js +156 -0
- package/dist/fields/measurement/engine/format.js.map +1 -0
- package/dist/fields/measurement/engine/locale.d.ts +25 -0
- package/dist/fields/measurement/engine/locale.js +79 -0
- package/dist/fields/measurement/engine/locale.js.map +1 -0
- package/dist/fields/measurement/engine/precision.d.ts +34 -0
- package/dist/fields/measurement/engine/precision.js +63 -0
- package/dist/fields/measurement/engine/precision.js.map +1 -0
- package/dist/fields/measurement/engine/registry.d.ts +55 -0
- package/dist/fields/measurement/engine/registry.js +117 -0
- package/dist/fields/measurement/engine/registry.js.map +1 -0
- package/dist/fields/measurement/engine/units.d.ts +178 -0
- package/dist/fields/measurement/engine/units.js +198 -0
- package/dist/fields/measurement/engine/units.js.map +1 -0
- package/dist/fields/measurement/measurementField.d.ts +17 -0
- package/dist/fields/measurement/measurementField.js +139 -0
- package/dist/fields/measurement/measurementField.js.map +1 -0
- package/dist/fields/measurement/options.d.ts +76 -0
- package/dist/fields/measurement/options.js +9 -0
- package/dist/fields/measurement/options.js.map +1 -0
- package/dist/fields/measurement/presets.d.ts +117 -0
- package/dist/fields/measurement/presets.js +136 -0
- package/dist/fields/measurement/presets.js.map +1 -0
- package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
- package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
- package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
- package/dist/fields/measurement/server/getUserUnits.js +39 -0
- package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
- package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
- package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
- package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
- package/dist/fields/measurement/server/resolveRegistryDefault.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 +5 -3
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/dist/translations/ar.js +62 -0
- package/dist/translations/ar.js.map +1 -0
- package/dist/translations/de.js +19 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +19 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +62 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.js +62 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.js +62 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.js +19 -1
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +19 -1
- package/dist/translations/keys.js +20 -2
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +62 -0
- package/dist/translations/ko.js.map +1 -0
- package/dist/translations/pt.js +62 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.js +62 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/uk.js +62 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.js +62 -0
- package/dist/translations/zh.js.map +1 -0
- package/dist/types.d.ts +41 -1
- package/dist/utils/resolveStaticLabel.js +13 -0
- package/dist/utils/resolveStaticLabel.js.map +1 -0
- package/package.json +28 -6
- package/dist/fields/icon/shared/resolveStaticLabel.js +0 -16
- package/dist/fields/icon/shared/resolveStaticLabel.js.map +0 -1
|
@@ -408,7 +408,8 @@ html[data-theme="dark"] .tenx-icon-drawer__banner {
|
|
|
408
408
|
background: transparent;
|
|
409
409
|
border: none;
|
|
410
410
|
border-radius: var(--style-radius-s);
|
|
411
|
-
|
|
411
|
+
/* 700, not 600: the small rail label needs 4.5:1 on the drawer background */
|
|
412
|
+
color: var(--theme-elevation-700);
|
|
412
413
|
font-family: inherit;
|
|
413
414
|
font-size: 0.875rem;
|
|
414
415
|
text-align: left;
|
|
@@ -527,6 +528,7 @@ html[data-theme="dark"] .tenx-icon-drawer__banner {
|
|
|
527
528
|
padding-top: calc(var(--base) * 0.5);
|
|
528
529
|
background: var(--theme-bg);
|
|
529
530
|
border-top: 1px solid var(--theme-elevation-100);
|
|
530
|
-
|
|
531
|
+
/* 700, not 600: the small counter needs 4.5:1 on the drawer background */
|
|
532
|
+
color: var(--theme-elevation-700);
|
|
531
533
|
font-size: 0.75rem;
|
|
532
534
|
}
|
|
@@ -30,7 +30,7 @@ const EXPORT_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
|
30
30
|
*/
|
|
31
31
|
const UNSAFE_IN_SPECIFIER = /['\\\n\r\u2028\u2029]/;
|
|
32
32
|
const emitManifestModule = (icons, categories, header = GENERATED_HEADER) => {
|
|
33
|
-
return `${header}export const manifest: {\n\ticons: {
|
|
33
|
+
return `${header}export const manifest: {\n\ticons: {\n\t\tname: string\n\t\ttags: string[]\n\t\tcategories: string[]\n\t\tlabel?: string | Record<string, string>\n\t}[]\n\tcategories: string[]\n} = ${JSON.stringify({
|
|
34
34
|
icons,
|
|
35
35
|
categories
|
|
36
36
|
}, null, " ")}\n`;
|
|
@@ -74,7 +74,7 @@ const emitNodesModule = (icons, nodes, header = GENERATED_HEADER) => {
|
|
|
74
74
|
for (const [tag] of glyph) if (!SVG_NODE_TAGS.has(tag)) throw new Error(`icon "${icon.name}": unexpected SVG node tag "${tag}"`);
|
|
75
75
|
ordered[icon.name] = glyph;
|
|
76
76
|
}
|
|
77
|
-
return `${header}
|
|
77
|
+
return `${header}type GeneratedIconNode =\n\t| [string, Record<string, string>]\n\t| [string, Record<string, string>, GeneratedIconNode[]]\n\nexport const nodes: Record<string, GeneratedIconNode[]> = ${JSON.stringify(ordered)}\n`;
|
|
78
78
|
};
|
|
79
79
|
//#endregion
|
|
80
80
|
export { emitImportsModule, emitManifestModule, emitNodesModule, generatedHeader };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.js","names":[],"sources":["../../../../src/fields/icon/codegen/emit.ts"],"sourcesContent":["import type { IconMeta, IconNodeMap } from '../../../types'\nimport type { IconImportSpec } from './types'\n\n/** Regen command named in the generated-file header when a source does not override it. */\nconst DEFAULT_REGEN_COMMAND = 'pnpm generate:manifests'\n\n/** Header line telling a reader the file is generated and which command re-emits it. */\nexport const generatedHeader = (regenCommand: string = DEFAULT_REGEN_COMMAND): string =>\n\t`/* GENERATED by @10x-media/fields icon codegen. Do not edit; run \\`${regenCommand}\\`. */\\n`\n\nexport const GENERATED_HEADER = generatedHeader()\n\n/**\n * Node-data renders straight into the DOM via createElement(tag, attrs), so the\n * tag is restricted to the SVG shape elements lucide and tabler actually emit. An\n * unexpected tag means the upstream node shape changed; fail generation loudly\n * rather than commit data the drawer would render as an unknown element.\n */\nconst SVG_NODE_TAGS = new Set([\n\t'circle',\n\t'ellipse',\n\t'g',\n\t'line',\n\t'path',\n\t'polygon',\n\t'polyline',\n\t'rect',\n])\n\n/** Interpolated bare into `m.<exportName>`, so nothing but an identifier is safe. */\nconst EXPORT_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n/**\n * The complete set of characters that can escape a single-quoted JS string:\n * the quote, the escape character, and the four line terminators. Specifiers\n * and icon names are validated rather than escaped so a bad one fails generation\n * loudly instead of emitting a module that only breaks at import time.\n */\nconst UNSAFE_IN_SPECIFIER = /['\\\\\\n\\r\\u2028\\u2029]/\n\nexport const emitManifestModule = (\n\ticons: IconMeta[],\n\tcategories: string[],\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst data = JSON.stringify({ icons, categories }, null, '\\t')\n\treturn `${header}export const manifest: {\\n\\ticons: {
|
|
1
|
+
{"version":3,"file":"emit.js","names":[],"sources":["../../../../src/fields/icon/codegen/emit.ts"],"sourcesContent":["import type { IconMeta, IconNodeMap } from '../../../types'\nimport type { IconImportSpec } from './types'\n\n/** Regen command named in the generated-file header when a source does not override it. */\nconst DEFAULT_REGEN_COMMAND = 'pnpm generate:manifests'\n\n/** Header line telling a reader the file is generated and which command re-emits it. */\nexport const generatedHeader = (regenCommand: string = DEFAULT_REGEN_COMMAND): string =>\n\t`/* GENERATED by @10x-media/fields icon codegen. Do not edit; run \\`${regenCommand}\\`. */\\n`\n\nexport const GENERATED_HEADER = generatedHeader()\n\n/**\n * Node-data renders straight into the DOM via createElement(tag, attrs), so the\n * tag is restricted to the SVG shape elements lucide and tabler actually emit. An\n * unexpected tag means the upstream node shape changed; fail generation loudly\n * rather than commit data the drawer would render as an unknown element.\n */\nconst SVG_NODE_TAGS = new Set([\n\t'circle',\n\t'ellipse',\n\t'g',\n\t'line',\n\t'path',\n\t'polygon',\n\t'polyline',\n\t'rect',\n])\n\n/** Interpolated bare into `m.<exportName>`, so nothing but an identifier is safe. */\nconst EXPORT_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n/**\n * The complete set of characters that can escape a single-quoted JS string:\n * the quote, the escape character, and the four line terminators. Specifiers\n * and icon names are validated rather than escaped so a bad one fails generation\n * loudly instead of emitting a module that only breaks at import time.\n */\nconst UNSAFE_IN_SPECIFIER = /['\\\\\\n\\r\\u2028\\u2029]/\n\nexport const emitManifestModule = (\n\ticons: IconMeta[],\n\tcategories: string[],\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst data = JSON.stringify({ icons, categories }, null, '\\t')\n\t// The annotation mirrors IconMeta by hand because the generated file must stand alone\n\t// with no import. Anything the data can carry must be annotated, or a consumer whose\n\t// manifest uses an optional field fails strict typecheck against our own output.\n\treturn `${header}export const manifest: {\\n\\ticons: {\\n\\t\\tname: string\\n\\t\\ttags: string[]\\n\\t\\tcategories: string[]\\n\\t\\tlabel?: string | Record<string, string>\\n\\t}[]\\n\\tcategories: string[]\\n} = ${data}\\n`\n}\n\nexport const emitImportsModule = (\n\ticons: IconMeta[],\n\timportFor: (icon: IconMeta) => IconImportSpec,\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst lines: string[] = [\n\t\theader,\n\t\t`import type { ComponentType } from 'react'`,\n\t\t'',\n\t\t`export type GeneratedIconModule = { default: ComponentType<{ className?: string; size?: number | string }> }`,\n\t\t'',\n\t\t'const map = {',\n\t]\n\tfor (const icon of icons) {\n\t\t// The name is interpolated bare as the map key, so it needs the same guard the\n\t\t// specifier gets. `generate` rejects these too; this is the emitter standing on\n\t\t// its own, since it is exported and callable directly.\n\t\tif (UNSAFE_IN_SPECIFIER.test(icon.name)) {\n\t\t\tthrow new Error(`unsafe icon name for an emitted key: ${icon.name}`)\n\t\t}\n\t\tconst spec = importFor(icon)\n\t\tif (UNSAFE_IN_SPECIFIER.test(spec.module)) {\n\t\t\tthrow new Error(`icon \"${icon.name}\": unsafe module specifier: ${spec.module}`)\n\t\t}\n\t\tif (spec.exportName !== undefined && !EXPORT_NAME.test(spec.exportName)) {\n\t\t\tthrow new Error(`icon \"${icon.name}\": export name is not an identifier: ${spec.exportName}`)\n\t\t}\n\t\tif (spec.exportName) {\n\t\t\tlines.push(\n\t\t\t\t`\\t'${icon.name}': () => import('${spec.module}').then((m) => ({ default: m.${spec.exportName} })),`\n\t\t\t)\n\t\t} else {\n\t\t\tlines.push(`\\t'${icon.name}': () => import('${spec.module}'),`)\n\t\t}\n\t}\n\tlines.push('}')\n\tlines.push('')\n\tlines.push(\n\t\t'export const iconImports = map as unknown as Record<string, () => Promise<GeneratedIconModule>>'\n\t)\n\tlines.push('')\n\treturn lines.join('\\n')\n}\n\n/**\n * Emits a library's bulk glyph node-data, keyed by icon name in the same sorted\n * order as the manifest so a regeneration is byte-stable. The drawer lazily\n * imports this once per library and renders each glyph as inline SVG, which\n * replaces the per-icon dynamic imports that made large libraries scroll poorly.\n * Compact JSON keeps the committed file (thousands of glyphs) as small as the\n * source; the module is admin-only and never enters a frontend bundle.\n */\nexport const emitNodesModule = (\n\ticons: IconMeta[],\n\tnodes: IconNodeMap,\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst ordered: IconNodeMap = {}\n\tfor (const icon of icons) {\n\t\tconst glyph = nodes[icon.name]\n\t\tif (!glyph) throw new Error(`icon \"${icon.name}\": no node-data for this manifest entry`)\n\t\tfor (const [tag] of glyph) {\n\t\t\tif (!SVG_NODE_TAGS.has(tag)) {\n\t\t\t\tthrow new Error(`icon \"${icon.name}\": unexpected SVG node tag \"${tag}\"`)\n\t\t\t}\n\t\t}\n\t\tordered[icon.name] = glyph\n\t}\n\tconst data = JSON.stringify(ordered)\n\t// Recursive alias mirroring IconNode, since a glyph may nest children under <g> or\n\t// <defs> and a flat tuple annotation would reject the module's own data.\n\treturn `${header}type GeneratedIconNode =\\n\\t| [string, Record<string, string>]\\n\\t| [string, Record<string, string>, GeneratedIconNode[]]\\n\\nexport const nodes: Record<string, GeneratedIconNode[]> = ${data}\\n`\n}\n"],"mappings":";;AAIA,MAAM,wBAAwB;;AAG9B,MAAa,mBAAmB,eAAuB,0BACtD,sEAAsE,aAAa;AAEpF,MAAa,mBAAmB,gBAAgB;;;;;;;AAQhD,MAAM,gBAAgB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;AAGD,MAAM,cAAc;;;;;;;AAQpB,MAAM,sBAAsB;AAE5B,MAAa,sBACZ,OACA,YACA,SAAiB,qBACL;CAKZ,OAAO,GAAG,OAAO,wLAJJ,KAAK,UAAU;EAAE;EAAO;CAAW,GAAG,MAAM,GAImJ,EAAE;AAC/M;AAEA,MAAa,qBACZ,OACA,WACA,SAAiB,qBACL;CACZ,MAAM,QAAkB;EACvB;EACA;EACA;EACA;EACA;EACA;CACD;CACA,KAAK,MAAM,QAAQ,OAAO;EAIzB,IAAI,oBAAoB,KAAK,KAAK,IAAI,GACrC,MAAM,IAAI,MAAM,wCAAwC,KAAK,MAAM;EAEpE,MAAM,OAAO,UAAU,IAAI;EAC3B,IAAI,oBAAoB,KAAK,KAAK,MAAM,GACvC,MAAM,IAAI,MAAM,SAAS,KAAK,KAAK,8BAA8B,KAAK,QAAQ;EAE/E,IAAI,KAAK,eAAe,KAAA,KAAa,CAAC,YAAY,KAAK,KAAK,UAAU,GACrE,MAAM,IAAI,MAAM,SAAS,KAAK,KAAK,uCAAuC,KAAK,YAAY;EAE5F,IAAI,KAAK,YACR,MAAM,KACL,MAAM,KAAK,KAAK,mBAAmB,KAAK,OAAO,+BAA+B,KAAK,WAAW,MAC/F;OAEA,MAAM,KAAK,MAAM,KAAK,KAAK,mBAAmB,KAAK,OAAO,IAAI;CAEhE;CACA,MAAM,KAAK,GAAG;CACd,MAAM,KAAK,EAAE;CACb,MAAM,KACL,iGACD;CACA,MAAM,KAAK,EAAE;CACb,OAAO,MAAM,KAAK,IAAI;AACvB;;;;;;;;;AAUA,MAAa,mBACZ,OACA,OACA,SAAiB,qBACL;CACZ,MAAM,UAAuB,CAAC;CAC9B,KAAK,MAAM,QAAQ,OAAO;EACzB,MAAM,QAAQ,MAAM,KAAK;EACzB,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,SAAS,KAAK,KAAK,wCAAwC;EACvF,KAAK,MAAM,CAAC,QAAQ,OACnB,IAAI,CAAC,cAAc,IAAI,GAAG,GACzB,MAAM,IAAI,MAAM,SAAS,KAAK,KAAK,8BAA8B,IAAI,EAAE;EAGzE,QAAQ,KAAK,QAAQ;CACtB;CAIA,OAAO,GAAG,OAAO,yLAHJ,KAAK,UAAU,OAGiL,EAAE;AAChN"}
|
|
@@ -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,iBAJuB,qBAAqB,MAAM,iBAAiB,cAAc,eAInE;EACR;EACN;EACA;EACa;CACd,CAAC;CAED,MAAM,oBAA4D,CAAC;CACnE,KAAK,MAAM,WAAW,UAAU;EAC/B,MAAM,OAAO,iBAAiD;GAC7D,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC;EACD,MAAM,SAAS,iBAAmD;GACjE,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC;EAID,MAAM,QAAQ,QAAQ,QACnB,iBAA+D;GAC/D,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC,IACA,KAAA;EACH,IAAI,QAAQ,QACX,kBAAkB,QAAQ,QAAQ;GAAE;GAAQ,QAAQ,QAAQ;GAAQ;GAAM;EAAM;CAClF;CAKA,MAAM,cACL,OAAO,cAAc,OAAO,YAAY,IAAI,OAAO,WAC/C,YAAY,OAAO,YAAY,IAAI,KACpC;CACJ,IAAI,eAAe;CACnB,IAAI,gBAAgB,QAAQ,gBAAgB,IAAI;EAC/C,MAAM,EAAE,SAAS,SAAS,iBAAiB,aAAa,cAAc;EACtE,MAAM,UAAU,SAAS,MAAM,cAAc,UAAU,SAAS,OAAO;EACvE,IAAI,SAAS,eAAe,MAAM,gBAAgB,SAAS,MAAM;GAAE;GAAS;EAAI,CAAC;CAClF;CAEA,OACC,oBAAC,WAAD;EACoB;EACnB,UAAU,SAAS,KAAK,aAAa;GACpC,OAAO,mBAAmB,QAAQ,OAAO,KAAK,QAAQ,KAAK,QAAQ;GACnE,MAAM,QAAQ;EACf,EAAE;EACS;EACK;EAChB,OAAO;EACD;EACO;EACH;EACE;EACE;EACd,eAAe,MAAM,kBAAkB;CACvC,CAAA;AAEH"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iconLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/iconLabel.ts"],"sourcesContent":["import type { IconMeta } from '../../../types'\nimport {
|
|
1
|
+
{"version":3,"file":"iconLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/iconLabel.ts"],"sourcesContent":["import type { IconMeta } from '../../../types'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { formatIconLabel } from './formatIconLabel'\n\n/** What an editor sees for one icon: its accessible name, plus the raw name where that adds information. */\nexport type IconDisplayLabel = { code?: string; label: string }\n\n/**\n * Resolves the display text for one icon. A library-supplied `label` wins; otherwise\n * the name is sentence-cased as before, so every existing manifest is unaffected.\n *\n * `code` carries the raw name for surfaces that can show it alongside the label. It is\n * the only place an editor can learn that \"Hungary\" stores as `HUN`, which they need to\n * write frontend code, and it is deliberately kept out of the accessible name: a screen\n * reader announcing \"Hungary HUN\" across 215 cells is the defect this fixes.\n */\nexport const resolveIconDisplay = (args: {\n\tlanguage: string\n\tmeta?: IconMeta | null\n\tname: string\n}): IconDisplayLabel => {\n\tconst derived = formatIconLabel(args.name)\n\tconst supplied = resolveStaticLabel(args.meta?.label, args.language)\n\tif (!supplied) return { label: derived }\n\t// A code only earns its place when the label hides it. A label matching the name, or\n\t// matching what the name would have derived anyway, tells the editor nothing new.\n\tif (supplied === args.name || supplied === derived) return { label: supplied }\n\treturn { code: args.name, label: supplied }\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,sBAAsB,SAIX;CACvB,MAAM,UAAU,gBAAgB,KAAK,IAAI;CACzC,MAAM,WAAW,mBAAmB,KAAK,MAAM,OAAO,KAAK,QAAQ;CACnE,IAAI,CAAC,UAAU,OAAO,EAAE,OAAO,QAAQ;CAGvC,IAAI,aAAa,KAAK,QAAQ,aAAa,SAAS,OAAO,EAAE,OAAO,SAAS;CAC7E,OAAO;EAAE,MAAM,KAAK;EAAM,OAAO;CAAS;AAC3C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MeasurementResolvedClientOptions } from "../options.js";
|
|
2
|
+
import { ClientField, DefaultCellComponentProps } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
//#region src/fields/measurement/client/MeasurementCell.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* `field` and `onClick` are excluded and re-added as optional: the RSC cell only
|
|
7
|
+
* carries the server-sanitized Field (which serializes functions Payload attaches,
|
|
8
|
+
* e.g. hooks/validate), never a ClientField, and no onClick handler crosses the
|
|
9
|
+
* flight boundary. This cell reads neither, so both stay optional rather than forced.
|
|
10
|
+
*/
|
|
11
|
+
type MeasurementCellProps = {
|
|
12
|
+
measurementOptions: MeasurementResolvedClientOptions;
|
|
13
|
+
field?: ClientField;
|
|
14
|
+
} & Omit<DefaultCellComponentProps, 'field' | 'onClick'>;
|
|
15
|
+
declare const MeasurementCell: React.FC<MeasurementCellProps>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { MeasurementCell, MeasurementCellProps };
|
|
18
|
+
//# sourceMappingURL=MeasurementCell.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { exactModePrecisionOverride, resolvePrecision } from "../engine/precision.js";
|
|
3
|
+
import { useTranslation } from "../../../translations/useTranslation.js";
|
|
4
|
+
import { resolveDisplayUnit, systemForLocale } from "../engine/locale.js";
|
|
5
|
+
import { createEngine, defaultEngine } from "../engine/registry.js";
|
|
6
|
+
import { useMeasurementUnits } from "./MeasurementUnitsProvider.js";
|
|
7
|
+
import { useEffect, useMemo, useState } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
import "./measurementCell.css";
|
|
10
|
+
//#region src/fields/measurement/client/MeasurementCell.tsx
|
|
11
|
+
/** MeasurementCellServer always resolves and threads precision; this only covers a hand-authored Cell with no server wrapper. */
|
|
12
|
+
const DEFAULT_PRECISION = resolvePrecision([]);
|
|
13
|
+
const MeasurementCell = (props) => {
|
|
14
|
+
const { cellData, measurementOptions } = props;
|
|
15
|
+
const { custom, dimension, fallbackUnit, localeDefaults, precision, preferenceKey, registryDefault, storageUnit, units } = measurementOptions;
|
|
16
|
+
const { i18n } = useTranslation();
|
|
17
|
+
const context = useMeasurementUnits();
|
|
18
|
+
const engine = useMemo(() => custom ? createEngine(custom) : defaultEngine, [custom]);
|
|
19
|
+
const [system, setSystem] = useState(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (context) setSystem(systemForLocale(navigator.language));
|
|
22
|
+
}, [context]);
|
|
23
|
+
if (typeof cellData !== "number" || Number.isNaN(cellData)) return null;
|
|
24
|
+
const displayUnit = resolveDisplayUnit({
|
|
25
|
+
dimension,
|
|
26
|
+
fallbackUnit,
|
|
27
|
+
localeDefaults,
|
|
28
|
+
preferenceUnit: context?.units[preferenceKey] ?? null,
|
|
29
|
+
registryDefault,
|
|
30
|
+
system,
|
|
31
|
+
units
|
|
32
|
+
});
|
|
33
|
+
const precisionOverride = exactModePrecisionOverride(precision ?? DEFAULT_PRECISION, displayUnit);
|
|
34
|
+
return /* @__PURE__ */ jsx("span", {
|
|
35
|
+
className: "fields-measurement-cell",
|
|
36
|
+
children: engine.formatMeasurement(cellData, {
|
|
37
|
+
displayUnit,
|
|
38
|
+
locale: i18n.language,
|
|
39
|
+
precision: precisionOverride,
|
|
40
|
+
storageUnit
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { MeasurementCell };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=MeasurementCell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeasurementCell.js","names":[],"sources":["../../../../src/fields/measurement/client/MeasurementCell.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, DefaultCellComponentProps } from 'payload'\nimport type React from 'react'\nimport { useEffect, useMemo, useState } from 'react'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { type MeasurementSystem, systemForLocale } from '../engine/locale'\nimport { exactModePrecisionOverride, resolvePrecision } from '../engine/precision'\nimport { createEngine, defaultEngine } from '../engine/registry'\nimport type { MeasurementResolvedClientOptions } from '../options'\nimport { resolveDisplayUnit } from './editModel'\nimport { useMeasurementUnits } from './MeasurementUnitsProvider'\nimport './measurementCell.css'\n\n/** MeasurementCellServer always resolves and threads precision; this only covers a hand-authored Cell with no server wrapper. */\nconst DEFAULT_PRECISION = resolvePrecision([])\n\n/**\n * `field` and `onClick` are excluded and re-added as optional: the RSC cell only\n * carries the server-sanitized Field (which serializes functions Payload attaches,\n * e.g. hooks/validate), never a ClientField, and no onClick handler crosses the\n * flight boundary. This cell reads neither, so both stay optional rather than forced.\n */\nexport type MeasurementCellProps = {\n\tmeasurementOptions: MeasurementResolvedClientOptions\n\tfield?: ClientField\n} & Omit<DefaultCellComponentProps, 'field' | 'onClick'>\n\nexport const MeasurementCell: React.FC<MeasurementCellProps> = (props) => {\n\tconst { cellData, measurementOptions } = props\n\tconst {\n\t\tcustom,\n\t\tdimension,\n\t\tfallbackUnit,\n\t\tlocaleDefaults,\n\t\tprecision,\n\t\tpreferenceKey,\n\t\tregistryDefault,\n\t\tstorageUnit,\n\t\tunits,\n\t} = measurementOptions\n\tconst { i18n } = useTranslation()\n\tconst context = useMeasurementUnits()\n\tconst engine = useMemo(() => (custom ? createEngine(custom) : defaultEngine), [custom])\n\tconst [system, setSystem] = useState<MeasurementSystem | null>(null)\n\t// Gated on the provider: plugin-less cells stay on the field default, not the browser locale.\n\tuseEffect(() => {\n\t\tif (context) setSystem(systemForLocale(navigator.language))\n\t}, [context])\n\n\tif (typeof cellData !== 'number' || Number.isNaN(cellData)) return null\n\n\tconst displayUnit = resolveDisplayUnit({\n\t\tdimension,\n\t\tfallbackUnit,\n\t\tlocaleDefaults,\n\t\tpreferenceUnit: context?.units[preferenceKey] ?? null,\n\t\tregistryDefault,\n\t\tsystem,\n\t\tunits,\n\t})\n\tconst resolvedPrecision = precision ?? DEFAULT_PRECISION\n\t// The override key is the unit id itself, so it works for a compound displayUnit\n\t// too: precisionFor/formatMeasurement treat that key as the compound's minor digits.\n\tconst precisionOverride = exactModePrecisionOverride(resolvedPrecision, displayUnit)\n\treturn (\n\t\t<span className=\"fields-measurement-cell\">\n\t\t\t{engine.formatMeasurement(cellData, {\n\t\t\t\tdisplayUnit,\n\t\t\t\tlocale: i18n.language,\n\t\t\t\tprecision: precisionOverride,\n\t\t\t\tstorageUnit,\n\t\t\t})}\n\t\t</span>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,oBAAoB,iBAAiB,CAAC,CAAC;AAa7C,MAAa,mBAAmD,UAAU;CACzE,MAAM,EAAE,UAAU,uBAAuB;CACzC,MAAM,EACL,QACA,WACA,cACA,gBACA,WACA,eACA,iBACA,aACA,UACG;CACJ,MAAM,EAAE,SAAS,eAAe;CAChC,MAAM,UAAU,oBAAoB;CACpC,MAAM,SAAS,cAAe,SAAS,aAAa,MAAM,IAAI,eAAgB,CAAC,MAAM,CAAC;CACtF,MAAM,CAAC,QAAQ,aAAa,SAAmC,IAAI;CAEnE,gBAAgB;EACf,IAAI,SAAS,UAAU,gBAAgB,UAAU,QAAQ,CAAC;CAC3D,GAAG,CAAC,OAAO,CAAC;CAEZ,IAAI,OAAO,aAAa,YAAY,OAAO,MAAM,QAAQ,GAAG,OAAO;CAEnE,MAAM,cAAc,mBAAmB;EACtC;EACA;EACA;EACA,gBAAgB,SAAS,MAAM,kBAAkB;EACjD;EACA;EACA;CACD,CAAC;CAID,MAAM,oBAAoB,2BAHA,aAAa,mBAGiC,WAAW;CACnF,OACC,oBAAC,QAAD;EAAM,WAAU;YACd,OAAO,kBAAkB,UAAU;GACnC;GACA,QAAQ,KAAK;GACb,WAAW;GACX;EACD,CAAC;CACI,CAAA;AAER"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MeasurementResolvedClientOptions } from "../options.js";
|
|
2
|
+
import { NumberFieldClientProps } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/fields/measurement/client/MeasurementField.d.ts
|
|
6
|
+
type MeasurementFieldProps = {
|
|
7
|
+
measurementOptions: MeasurementResolvedClientOptions;
|
|
8
|
+
} & NumberFieldClientProps;
|
|
9
|
+
/** The measurement row bound to the document form through `useField`, with unit-aware bound messages. */
|
|
10
|
+
declare const MeasurementField: React.FC<MeasurementFieldProps>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { MeasurementField, MeasurementFieldProps };
|
|
13
|
+
//# sourceMappingURL=MeasurementField.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../../../translations/keys.js";
|
|
3
|
+
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
+
import { useMeasurementModel } from "./useMeasurementModel.js";
|
|
5
|
+
import { MeasurementInputView } from "./MeasurementInput.js";
|
|
6
|
+
import { number } from "payload/shared";
|
|
7
|
+
import { useField } from "@payloadcms/ui";
|
|
8
|
+
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
9
|
+
import { useCallback, useMemo } from "react";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
//#region src/fields/measurement/client/MeasurementField.tsx
|
|
12
|
+
/** The measurement row bound to the document form through `useField`, with unit-aware bound messages. */
|
|
13
|
+
const MeasurementField = (props) => {
|
|
14
|
+
const { field, field: { admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {}, label, localized, max, min, name, required }, measurementOptions, path: pathFromProps, readOnly: readOnlyFromProps } = props;
|
|
15
|
+
const { t } = useTranslation$1();
|
|
16
|
+
const model = useMeasurementModel(measurementOptions);
|
|
17
|
+
const { fmtBound } = model;
|
|
18
|
+
const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({
|
|
19
|
+
potentiallyStalePath: pathFromProps,
|
|
20
|
+
validate: useCallback((value, options) => {
|
|
21
|
+
if (typeof value === "number" && !Number.isNaN(value)) {
|
|
22
|
+
if (typeof min === "number" && value < min) return t(keys.measurementBelowMin, { min: fmtBound(min) });
|
|
23
|
+
if (typeof max === "number" && value > max) return t(keys.measurementAboveMax, { max: fmtBound(max) });
|
|
24
|
+
}
|
|
25
|
+
return number(value, {
|
|
26
|
+
...options,
|
|
27
|
+
max: void 0,
|
|
28
|
+
min: void 0,
|
|
29
|
+
name,
|
|
30
|
+
required,
|
|
31
|
+
type: "number"
|
|
32
|
+
});
|
|
33
|
+
}, [
|
|
34
|
+
fmtBound,
|
|
35
|
+
max,
|
|
36
|
+
min,
|
|
37
|
+
name,
|
|
38
|
+
required,
|
|
39
|
+
t
|
|
40
|
+
])
|
|
41
|
+
});
|
|
42
|
+
const isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin);
|
|
43
|
+
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
44
|
+
return /* @__PURE__ */ jsx(MeasurementInputView, {
|
|
45
|
+
AfterInput,
|
|
46
|
+
BeforeInput,
|
|
47
|
+
className,
|
|
48
|
+
Description,
|
|
49
|
+
description,
|
|
50
|
+
Error: ErrorComponent,
|
|
51
|
+
Label,
|
|
52
|
+
label,
|
|
53
|
+
localized,
|
|
54
|
+
max,
|
|
55
|
+
min,
|
|
56
|
+
model,
|
|
57
|
+
onChange: setValue,
|
|
58
|
+
path,
|
|
59
|
+
placeholder: typeof placeholder === "string" ? placeholder : void 0,
|
|
60
|
+
readOnly: isReadOnly,
|
|
61
|
+
required,
|
|
62
|
+
showError,
|
|
63
|
+
style: styles,
|
|
64
|
+
value
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { MeasurementField };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=MeasurementField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeasurementField.js","names":["useTranslation"],"sources":["../../../../src/fields/measurement/client/MeasurementField.tsx"],"sourcesContent":["'use client'\nimport { useField } from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { NumberFieldClientProps, Validate } from 'payload'\nimport { number } 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 { MeasurementResolvedClientOptions } from '../options'\nimport { MeasurementInputView } from './MeasurementInput'\nimport { useMeasurementModel } from './useMeasurementModel'\n\nexport type MeasurementFieldProps = {\n\tmeasurementOptions: MeasurementResolvedClientOptions\n} & NumberFieldClientProps\n\n/** The measurement row bound to the document form through `useField`, with unit-aware bound messages. */\nexport const MeasurementField: React.FC<MeasurementFieldProps> = (props) => {\n\tconst {\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\tmax,\n\t\t\tmin,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tmeasurementOptions,\n\t\tpath: pathFromProps,\n\t\treadOnly: readOnlyFromProps,\n\t} = props\n\tconst { t } = useTranslation()\n\tconst model = useMeasurementModel(measurementOptions)\n\tconst { fmtBound } = model\n\n\tconst memoizedValidate = useCallback<Validate<number | null | undefined>>(\n\t\t(value, options) => {\n\t\t\tif (typeof value === 'number' && !Number.isNaN(value)) {\n\t\t\t\tif (typeof min === 'number' && value < min) {\n\t\t\t\t\treturn t(keys.measurementBelowMin, { min: fmtBound(min) })\n\t\t\t\t}\n\t\t\t\tif (typeof max === 'number' && value > max) {\n\t\t\t\t\treturn t(keys.measurementAboveMax, { max: fmtBound(max) })\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn number(value, {\n\t\t\t\t...options,\n\t\t\t\tmax: undefined,\n\t\t\t\tmin: undefined,\n\t\t\t\tname,\n\t\t\t\trequired,\n\t\t\t\ttype: 'number',\n\t\t\t} as Parameters<typeof number>[1])\n\t\t},\n\t\t[fmtBound, max, min, name, required, 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<number | null>({ 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\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\treturn (\n\t\t<MeasurementInputView\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\tmax={max}\n\t\t\tmin={min}\n\t\t\tmodel={model}\n\t\t\tonChange={setValue}\n\t\t\tpath={path}\n\t\t\tplaceholder={typeof placeholder === 'string' ? placeholder : undefined}\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":";;;;;;;;;;;;AAkBA,MAAa,oBAAqD,UAAU;CAC3E,MAAM,EACL,OACA,OAAO,EACN,OAAO,EAAE,WAAW,aAAa,aAAa,UAAU,sBAAsB,CAAC,GAC/E,OACA,WACA,KACA,KACA,MACA,YAED,oBACA,MAAM,eACN,UAAU,sBACP;CACJ,MAAM,EAAE,MAAMA,iBAAe;CAC7B,MAAM,QAAQ,oBAAoB,kBAAkB;CACpD,MAAM,EAAE,aAAa;CAwBrB,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAwB;EAAE,sBAAsB;EAAe,UA7B1C,aACvB,OAAO,YAAY;GACnB,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,MAAM,KAAK,GAAG;IACtD,IAAI,OAAO,QAAQ,YAAY,QAAQ,KACtC,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,SAAS,GAAG,EAAE,CAAC;IAE1D,IAAI,OAAO,QAAQ,YAAY,QAAQ,KACtC,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,SAAS,GAAG,EAAE,CAAC;GAE3D;GACA,OAAO,OAAO,OAAO;IACpB,GAAG;IACH,KAAK,KAAA;IACL,KAAK,KAAA;IACL;IACA;IACA,MAAM;GACP,CAAiC;EAClC,GACA;GAAC;GAAU;GAAK;GAAK;GAAM;GAAU;EAAC,CAUqD;CAAE,CAAC;CAI/F,MAAM,aAAa,QAAQ,qBAAqB,YAAY,iBAAiB;CAC7E,MAAM,SAAS,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE7D,OACC,oBAAC,sBAAD;EACa;EACC;EACF;EACE;EACA;EACb,OAAO;EACA;EACA;EACI;EACN;EACA;EACE;EACP,UAAU;EACJ;EACN,aAAa,OAAO,gBAAgB,WAAW,cAAc,KAAA;EAC7D,UAAU;EACA;EACC;EACX,OAAO;EACA;CACP,CAAA;AAEH"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MeasurementInputOptions } from "./useMeasurementModel.js";
|
|
2
|
+
import { StaticDescription, StaticLabel } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
//#region src/fields/measurement/client/MeasurementInput.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Props for the form-free measurement input. `value` is the number in
|
|
7
|
+
* `options.storageUnit`, exactly as `measurementField` stores it; the viewer reads and
|
|
8
|
+
* types in their display unit.
|
|
9
|
+
*/
|
|
10
|
+
type MeasurementInputProps = {
|
|
11
|
+
value: null | number | undefined; /** Fires on every edit with the value converted back to the storage unit. */
|
|
12
|
+
onChange: (value: null | number) => void;
|
|
13
|
+
options: MeasurementInputOptions; /** Bounds in the storage unit; a value outside them shows a message in the display unit. */
|
|
14
|
+
min?: number;
|
|
15
|
+
max?: number; /** 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; /** Message shown in the error tooltip. Left unset, the input reports its own bound errors. */
|
|
23
|
+
error?: string; /** Forces the error state on or off. Left unset, it follows `error` and the bound check. */
|
|
24
|
+
showError?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
style?: React.CSSProperties;
|
|
27
|
+
Label?: React.ReactNode;
|
|
28
|
+
Error?: React.ReactNode;
|
|
29
|
+
Description?: React.ReactNode;
|
|
30
|
+
BeforeInput?: React.ReactNode;
|
|
31
|
+
AfterInput?: React.ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The measurement field's row, unit menu and conversion pipeline with no form behind
|
|
35
|
+
* it, for custom admin views and components. Inside the admin the display unit is the
|
|
36
|
+
* viewer's saved preference for `preferenceKey`, shared with every measurement field
|
|
37
|
+
* on that key; `MeasurementField` is this plus `useField`.
|
|
38
|
+
*/
|
|
39
|
+
declare const MeasurementInput: React.FC<MeasurementInputProps>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { MeasurementInput, MeasurementInputProps };
|
|
42
|
+
//# sourceMappingURL=MeasurementInput.d.ts.map
|