@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
|
@@ -27,6 +27,7 @@ const findDocs = async (args) => {
|
|
|
27
27
|
collection: args.collection,
|
|
28
28
|
depth: 0,
|
|
29
29
|
limit: 0,
|
|
30
|
+
overrideAccess: true,
|
|
30
31
|
pagination: false,
|
|
31
32
|
...args.ctx.req ? { req: args.ctx.req } : {},
|
|
32
33
|
...args.where ? { where: args.where } : {}
|
|
@@ -85,6 +86,7 @@ const uploadIconLayer = (options) => {
|
|
|
85
86
|
collection: options.collection,
|
|
86
87
|
depth: 0,
|
|
87
88
|
limit: 1,
|
|
89
|
+
overrideAccess: true,
|
|
88
90
|
...ctx.req ? { req: ctx.req } : {},
|
|
89
91
|
where
|
|
90
92
|
})).docs.map(asUploadDoc)[0];
|
|
@@ -97,6 +99,7 @@ const uploadIconLayer = (options) => {
|
|
|
97
99
|
collection: options.collection,
|
|
98
100
|
depth: 0,
|
|
99
101
|
limit: 0,
|
|
102
|
+
overrideAccess: true,
|
|
100
103
|
pagination: false,
|
|
101
104
|
...ctx.req ? { req: ctx.req } : {},
|
|
102
105
|
where
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","names":[],"sources":["../../../../src/fields/icon/layers/upload.ts"],"sourcesContent":["import type { CollectionSlug, Payload, Where } from 'payload'\nimport type { IconLayer, IconLayerCache, IconLayerContext, IconMeta } from '../../../types'\n\n/** Document shape the layer reads, after the configurable field names are applied. */\ntype UploadDoc = Record<string, unknown>\n\n/**\n * Widens one document to a bag of fields.\n *\n * Payload types `find` as the document union of the host app's collections, and a generated\n * document type has no index signature, so asserting the array directly is rejected wherever\n * types have been generated. That is the dev app and every real consumer, and it is why this\n * only shows up outside the package's own typecheck. Taking `unknown` keeps it one legal\n * assertion rather than a double cast.\n */\nconst asUploadDoc = (doc: unknown): UploadDoc => doc as UploadDoc\n\nexport type UploadIconLayerOptions = {\n\t/** Upload collection holding the icons. */\n\tcollection: CollectionSlug\n\t/** Layer id, unique within the adapter. Defaults to the collection slug. */\n\tid?: string\n\t/** Field holding the icon name that becomes part of the stored value. Defaults to `name`. */\n\tnameField?: string\n\t/** Field holding the human-readable label. Defaults to `label`. */\n\tlabelField?: string\n\t/** Field holding search tags, a string array. Defaults to `tags`. */\n\ttagsField?: string\n\t/** Field holding categories, a string array. Defaults to `categories`. */\n\tcategoriesField?: string\n\t/**\n\t * Extra constraint, typically tenant scoping. Receives the request so it can read the\n\t * caller. Supply `cacheKey` alongside it, or one caller's listing is served to another.\n\t */\n\twhere?: (ctx: IconLayerContext) => Where | undefined\n\t/**\n\t * Cache-key segment for a scoped layer. Required whenever `where` varies by request:\n\t * the listing cache is otherwise keyed by adapter slug and layer id alone.\n\t */\n\tcacheKey?: (ctx: IconLayerContext) => string\n\t/** Listing cache policy. Defaults to a 30 second TTL, since uploads change at runtime. */\n\tcache?: IconLayerCache\n\t/**\n\t * How glyphs paint. `'url'` is the default and renders each icon through an `<img>`,\n\t * which is inert by construction: an SVG loaded that way cannot execute script.\n\t *\n\t * `'svg'` inlines the markup instead, which allows `currentColor` recolouring but means\n\t * rendering editor-uploaded markup inside the admin. On a multi-tenant install the\n\t * uploader may be a customer rather than an operator, so that is a deliberate choice\n\t * with a real blast radius. The markup is sanitised either way; `'url'` simply removes\n\t * the question.\n\t */\n\trender?: 'url' | 'svg'\n\t/** importMap path resolving `(name: string) => null | string` for the `url` strategy. */\n\tresolveUrl?: string\n\t/** importMap path resolving `() => Promise<Record<string, string>>` for the `svg` strategy. */\n\tloadSvgs?: string\n}\n\nconst DEFAULT_TTL = 30_000\n\nconst asStrings = (value: unknown): string[] =>\n\tArray.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : []\n\nconst toMeta = (doc: UploadDoc, options: Required<FieldNames>): IconMeta | null => {\n\tconst name = doc[options.nameField]\n\tif (typeof name !== 'string' || name === '') return null\n\tconst label = doc[options.labelField]\n\treturn {\n\t\tcategories: asStrings(doc[options.categoriesField]),\n\t\tname,\n\t\ttags: asStrings(doc[options.tagsField]),\n\t\t...(typeof label === 'string' && label !== '' ? { label } : {}),\n\t}\n}\n\ntype FieldNames = {\n\tcategoriesField: string\n\tlabelField: string\n\tnameField: string\n\ttagsField: string\n}\n\nconst findDocs = async (args: {\n\tctx: IconLayerContext\n\tcollection: CollectionSlug\n\tpayload: Payload\n\twhere: Where | undefined\n}): Promise<UploadDoc[]> => {\n\tconst result = await args.payload.find({\n\t\tcollection: args.collection,\n\t\tdepth: 0,\n\t\tlimit: 0,\n\t\tpagination: false,\n\t\t...(args.ctx.req ? { req: args.ctx.req } : {}),\n\t\t...(args.where ? { where: args.where } : {}),\n\t})\n\treturn result.docs.map(asUploadDoc)\n}\n\n/**\n * An icon layer backed by a Payload upload collection, so editors can add icons without a\n * deploy.\n *\n * This is the preset that proves the layer contract holds: if a real upload-backed library\n * needs anything expressible only here and not through `IconLayer`, that is a gap in the\n * contract rather than in this file.\n *\n * Validation never reads the listing cache. `resolveMetaMany` answers from one indexed\n * query, so an icon uploaded a moment ago is valid immediately, on every instance, rather\n * than after a cache expiry or a restart.\n */\nexport const uploadIconLayer = (options: UploadIconLayerOptions): IconLayer => {\n\tconst fields: Required<FieldNames> = {\n\t\tcategoriesField: options.categoriesField ?? 'categories',\n\t\tlabelField: options.labelField ?? 'label',\n\t\tnameField: options.nameField ?? 'name',\n\t\ttagsField: options.tagsField ?? 'tags',\n\t}\n\tconst strategy = options.render ?? 'url'\n\tif (strategy === 'url' && !options.resolveUrl) {\n\t\tthrow new Error('[fields] uploadIconLayer: the url strategy needs a resolveUrl import path')\n\t}\n\tif (strategy === 'svg' && !options.loadSvgs) {\n\t\tthrow new Error('[fields] uploadIconLayer: the svg strategy needs a loadSvgs import path')\n\t}\n\n\tconst scopedWhere = (ctx: IconLayerContext): Where | undefined => options.where?.(ctx)\n\n\treturn {\n\t\tcache: options.cache ?? { ttl: DEFAULT_TTL },\n\t\t...(options.cacheKey ? { cacheKey: options.cacheKey } : {}),\n\t\tid: options.id ?? String(options.collection),\n\t\tloadManifest: async (ctx) => {\n\t\t\tconst docs = await findDocs({\n\t\t\t\tcollection: options.collection,\n\t\t\t\tctx,\n\t\t\t\tpayload: ctx.payload,\n\t\t\t\twhere: scopedWhere(ctx),\n\t\t\t})\n\t\t\tconst icons = docs\n\t\t\t\t.map((doc) => toMeta(doc, fields))\n\t\t\t\t.filter((icon): icon is IconMeta => icon !== null)\n\t\t\tconst categories = [...new Set(icons.flatMap((icon) => icon.categories))].sort()\n\t\t\treturn { categories, icons }\n\t\t},\n\t\trender:\n\t\t\tstrategy === 'url'\n\t\t\t\t? { resolve: options.resolveUrl ?? '', type: 'url' }\n\t\t\t\t: { load: options.loadSvgs ?? '', type: 'svg' },\n\t\tresolveMeta: async (name, ctx) => {\n\t\t\tconst scoped = scopedWhere(ctx)\n\t\t\tconst where: Where = scoped\n\t\t\t\t? { and: [scoped, { [fields.nameField]: { equals: name } }] }\n\t\t\t\t: { [fields.nameField]: { equals: name } }\n\t\t\tconst result = await ctx.payload.find({\n\t\t\t\tcollection: options.collection,\n\t\t\t\tdepth: 0,\n\t\t\t\tlimit: 1,\n\t\t\t\t...(ctx.req ? { req: ctx.req } : {}),\n\t\t\t\twhere,\n\t\t\t})\n\t\t\tconst doc = result.docs.map(asUploadDoc)[0]\n\t\t\treturn doc ? toMeta(doc, fields) : null\n\t\t},\n\t\t// One `in` query for every name looked up in the tick. A document holding eight icon\n\t\t// fields, or a fifty-row list, costs one query rather than eight or fifty.\n\t\tresolveMetaMany: async (names, ctx) => {\n\t\t\tconst scoped = scopedWhere(ctx)\n\t\t\tconst where: Where = scoped\n\t\t\t\t? { and: [scoped, { [fields.nameField]: { in: names } }] }\n\t\t\t\t: { [fields.nameField]: { in: names } }\n\t\t\tconst result = await ctx.payload.find({\n\t\t\t\tcollection: options.collection,\n\t\t\t\tdepth: 0,\n\t\t\t\tlimit: 0,\n\t\t\t\tpagination: false,\n\t\t\t\t...(ctx.req ? { req: ctx.req } : {}),\n\t\t\t\twhere,\n\t\t\t})\n\t\t\tconst found = new Map<string, IconMeta>()\n\t\t\tfor (const doc of result.docs.map(asUploadDoc)) {\n\t\t\t\tconst meta = toMeta(doc, fields)\n\t\t\t\tif (meta) found.set(meta.name, meta)\n\t\t\t}\n\t\t\treturn found\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;AAeA,MAAM,eAAe,QAA4B;AA4CjD,MAAM,cAAc;AAEpB,MAAM,aAAa,UAClB,MAAM,QAAQ,KAAK,IAAI,MAAM,QAAQ,UAA2B,OAAO,UAAU,QAAQ,IAAI,CAAC;AAE/F,MAAM,UAAU,KAAgB,YAAmD;CAClF,MAAM,OAAO,IAAI,QAAQ;CACzB,IAAI,OAAO,SAAS,YAAY,SAAS,IAAI,OAAO;CACpD,MAAM,QAAQ,IAAI,QAAQ;CAC1B,OAAO;EACN,YAAY,UAAU,IAAI,QAAQ,gBAAgB;EAClD;EACA,MAAM,UAAU,IAAI,QAAQ,UAAU;EACtC,GAAI,OAAO,UAAU,YAAY,UAAU,KAAK,EAAE,MAAM,IAAI,CAAC;CAC9D;AACD;AASA,MAAM,WAAW,OAAO,SAKI;CAS3B,QAAO,MARc,KAAK,QAAQ,KAAK;EACtC,YAAY,KAAK;EACjB,OAAO;EACP,OAAO;EACP,YAAY;EACZ,GAAI,KAAK,IAAI,MAAM,EAAE,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC;EAC5C,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;CAC3C,CAAC,GACa,KAAK,IAAI,WAAW;AACnC;;;;;;;;;;;;;AAcA,MAAa,mBAAmB,YAA+C;CAC9E,MAAM,SAA+B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O;IACP,OAAO;IACP,GAAI,IAAI,MAAM,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC;IAClC;GACD,CAAC,GACkB,KAAK,IAAI,WAAW,EAAE;GACzC,OAAO,MAAM,OAAO,KAAK,MAAM,IAAI;EACpC;EAGA,iBAAiB,OAAO,OAAO,QAAQ;GACtC,MAAM,SAAS,YAAY,GAAG;GAC9B,MAAM,QAAe,SAClB,EAAE,KAAK,CAAC,QAAQ,GAAG,OAAO,YAAY,EAAE,IAAI,MAAM,EAAE,CAAC,EAAE,IACvD,GAAG,OAAO,YAAY,EAAE,IAAI,MAAM,EAAE;GACvC,MAAM,SAAS,MAAM,IAAI,QAAQ,KAAK;IACrC,YAAY,QAAQ;IACpB,OAAO;IACP,OAAO;IACP,YAAY;IACZ,GAAI,IAAI,MAAM,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC;IAClC;GACD,CAAC;GACD,MAAM,wBAAQ,IAAI,IAAsB;GACxC,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,WAAW,GAAG;IAC/C,MAAM,OAAO,OAAO,KAAK,MAAM;IAC/B,IAAI,MAAM,MAAM,IAAI,KAAK,MAAM,IAAI;GACpC;GACA,OAAO;EACR;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"upload.js","names":[],"sources":["../../../../src/fields/icon/layers/upload.ts"],"sourcesContent":["import type { CollectionSlug, Payload, Where } from 'payload'\nimport type { IconLayer, IconLayerCache, IconLayerContext, IconMeta } from '../../../types'\n\n/** Document shape the layer reads, after the configurable field names are applied. */\ntype UploadDoc = Record<string, unknown>\n\n/**\n * Widens one document to a bag of fields.\n *\n * Payload types `find` as the document union of the host app's collections, and a generated\n * document type has no index signature, so asserting the array directly is rejected wherever\n * types have been generated. That is the dev app and every real consumer, and it is why this\n * only shows up outside the package's own typecheck. Taking `unknown` keeps it one legal\n * assertion rather than a double cast.\n */\nconst asUploadDoc = (doc: unknown): UploadDoc => doc as UploadDoc\n\nexport type UploadIconLayerOptions = {\n\t/** Upload collection holding the icons. */\n\tcollection: CollectionSlug\n\t/** Layer id, unique within the adapter. Defaults to the collection slug. */\n\tid?: string\n\t/** Field holding the icon name that becomes part of the stored value. Defaults to `name`. */\n\tnameField?: string\n\t/** Field holding the human-readable label. Defaults to `label`. */\n\tlabelField?: string\n\t/** Field holding search tags, a string array. Defaults to `tags`. */\n\ttagsField?: string\n\t/** Field holding categories, a string array. Defaults to `categories`. */\n\tcategoriesField?: string\n\t/**\n\t * Extra constraint, typically tenant scoping. Receives the request so it can read the\n\t * caller. Supply `cacheKey` alongside it, or one caller's listing is served to another.\n\t */\n\twhere?: (ctx: IconLayerContext) => Where | undefined\n\t/**\n\t * Cache-key segment for a scoped layer. Required whenever `where` varies by request:\n\t * the listing cache is otherwise keyed by adapter slug and layer id alone.\n\t */\n\tcacheKey?: (ctx: IconLayerContext) => string\n\t/** Listing cache policy. Defaults to a 30 second TTL, since uploads change at runtime. */\n\tcache?: IconLayerCache\n\t/**\n\t * How glyphs paint. `'url'` is the default and renders each icon through an `<img>`,\n\t * which is inert by construction: an SVG loaded that way cannot execute script.\n\t *\n\t * `'svg'` inlines the markup instead, which allows `currentColor` recolouring but means\n\t * rendering editor-uploaded markup inside the admin. On a multi-tenant install the\n\t * uploader may be a customer rather than an operator, so that is a deliberate choice\n\t * with a real blast radius. The markup is sanitised either way; `'url'` simply removes\n\t * the question.\n\t */\n\trender?: 'url' | 'svg'\n\t/** importMap path resolving `(name: string) => null | string` for the `url` strategy. */\n\tresolveUrl?: string\n\t/** importMap path resolving `() => Promise<Record<string, string>>` for the `svg` strategy. */\n\tloadSvgs?: string\n}\n\nconst DEFAULT_TTL = 30_000\n\nconst asStrings = (value: unknown): string[] =>\n\tArray.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : []\n\nconst toMeta = (doc: UploadDoc, options: Required<FieldNames>): IconMeta | null => {\n\tconst name = doc[options.nameField]\n\tif (typeof name !== 'string' || name === '') return null\n\tconst label = doc[options.labelField]\n\treturn {\n\t\tcategories: asStrings(doc[options.categoriesField]),\n\t\tname,\n\t\ttags: asStrings(doc[options.tagsField]),\n\t\t...(typeof label === 'string' && label !== '' ? { label } : {}),\n\t}\n}\n\ntype FieldNames = {\n\tcategoriesField: string\n\tlabelField: string\n\tnameField: string\n\ttagsField: string\n}\n\nconst findDocs = async (args: {\n\tctx: IconLayerContext\n\tcollection: CollectionSlug\n\tpayload: Payload\n\twhere: Where | undefined\n}): Promise<UploadDoc[]> => {\n\tconst result = await args.payload.find({\n\t\tcollection: args.collection,\n\t\tdepth: 0,\n\t\tlimit: 0,\n\t\t// Icon metadata is library data, not the viewer's: lookups ran unrestricted on\n\t\t// Payload 3, and validation depends on them for any editor.\n\t\toverrideAccess: true,\n\t\tpagination: false,\n\t\t...(args.ctx.req ? { req: args.ctx.req } : {}),\n\t\t...(args.where ? { where: args.where } : {}),\n\t})\n\treturn result.docs.map(asUploadDoc)\n}\n\n/**\n * An icon layer backed by a Payload upload collection, so editors can add icons without a\n * deploy.\n *\n * This is the preset that proves the layer contract holds: if a real upload-backed library\n * needs anything expressible only here and not through `IconLayer`, that is a gap in the\n * contract rather than in this file.\n *\n * Validation never reads the listing cache. `resolveMetaMany` answers from one indexed\n * query, so an icon uploaded a moment ago is valid immediately, on every instance, rather\n * than after a cache expiry or a restart.\n */\nexport const uploadIconLayer = (options: UploadIconLayerOptions): IconLayer => {\n\tconst fields: Required<FieldNames> = {\n\t\tcategoriesField: options.categoriesField ?? 'categories',\n\t\tlabelField: options.labelField ?? 'label',\n\t\tnameField: options.nameField ?? 'name',\n\t\ttagsField: options.tagsField ?? 'tags',\n\t}\n\tconst strategy = options.render ?? 'url'\n\tif (strategy === 'url' && !options.resolveUrl) {\n\t\tthrow new Error('[fields] uploadIconLayer: the url strategy needs a resolveUrl import path')\n\t}\n\tif (strategy === 'svg' && !options.loadSvgs) {\n\t\tthrow new Error('[fields] uploadIconLayer: the svg strategy needs a loadSvgs import path')\n\t}\n\n\tconst scopedWhere = (ctx: IconLayerContext): Where | undefined => options.where?.(ctx)\n\n\treturn {\n\t\tcache: options.cache ?? { ttl: DEFAULT_TTL },\n\t\t...(options.cacheKey ? { cacheKey: options.cacheKey } : {}),\n\t\tid: options.id ?? String(options.collection),\n\t\tloadManifest: async (ctx) => {\n\t\t\tconst docs = await findDocs({\n\t\t\t\tcollection: options.collection,\n\t\t\t\tctx,\n\t\t\t\tpayload: ctx.payload,\n\t\t\t\twhere: scopedWhere(ctx),\n\t\t\t})\n\t\t\tconst icons = docs\n\t\t\t\t.map((doc) => toMeta(doc, fields))\n\t\t\t\t.filter((icon): icon is IconMeta => icon !== null)\n\t\t\tconst categories = [...new Set(icons.flatMap((icon) => icon.categories))].sort()\n\t\t\treturn { categories, icons }\n\t\t},\n\t\trender:\n\t\t\tstrategy === 'url'\n\t\t\t\t? { resolve: options.resolveUrl ?? '', type: 'url' }\n\t\t\t\t: { load: options.loadSvgs ?? '', type: 'svg' },\n\t\tresolveMeta: async (name, ctx) => {\n\t\t\tconst scoped = scopedWhere(ctx)\n\t\t\tconst where: Where = scoped\n\t\t\t\t? { and: [scoped, { [fields.nameField]: { equals: name } }] }\n\t\t\t\t: { [fields.nameField]: { equals: name } }\n\t\t\tconst result = await ctx.payload.find({\n\t\t\t\tcollection: options.collection,\n\t\t\t\tdepth: 0,\n\t\t\t\tlimit: 1,\n\t\t\t\toverrideAccess: true,\n\t\t\t\t...(ctx.req ? { req: ctx.req } : {}),\n\t\t\t\twhere,\n\t\t\t})\n\t\t\tconst doc = result.docs.map(asUploadDoc)[0]\n\t\t\treturn doc ? toMeta(doc, fields) : null\n\t\t},\n\t\t// One `in` query for every name looked up in the tick. A document holding eight icon\n\t\t// fields, or a fifty-row list, costs one query rather than eight or fifty.\n\t\tresolveMetaMany: async (names, ctx) => {\n\t\t\tconst scoped = scopedWhere(ctx)\n\t\t\tconst where: Where = scoped\n\t\t\t\t? { and: [scoped, { [fields.nameField]: { in: names } }] }\n\t\t\t\t: { [fields.nameField]: { in: names } }\n\t\t\tconst result = await ctx.payload.find({\n\t\t\t\tcollection: options.collection,\n\t\t\t\tdepth: 0,\n\t\t\t\tlimit: 0,\n\t\t\t\toverrideAccess: true,\n\t\t\t\tpagination: false,\n\t\t\t\t...(ctx.req ? { req: ctx.req } : {}),\n\t\t\t\twhere,\n\t\t\t})\n\t\t\tconst found = new Map<string, IconMeta>()\n\t\t\tfor (const doc of result.docs.map(asUploadDoc)) {\n\t\t\t\tconst meta = toMeta(doc, fields)\n\t\t\t\tif (meta) found.set(meta.name, meta)\n\t\t\t}\n\t\t\treturn found\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;AAeA,MAAM,eAAe,QAA4B;AA4CjD,MAAM,cAAc;AAEpB,MAAM,aAAa,UAClB,MAAM,QAAQ,KAAK,IAAI,MAAM,QAAQ,UAA2B,OAAO,UAAU,QAAQ,IAAI,CAAC;AAE/F,MAAM,UAAU,KAAgB,YAAmD;CAClF,MAAM,OAAO,IAAI,QAAQ;CACzB,IAAI,OAAO,SAAS,YAAY,SAAS,IAAI,OAAO;CACpD,MAAM,QAAQ,IAAI,QAAQ;CAC1B,OAAO;EACN,YAAY,UAAU,IAAI,QAAQ,gBAAgB;EAClD;EACA,MAAM,UAAU,IAAI,QAAQ,UAAU;EACtC,GAAI,OAAO,UAAU,YAAY,UAAU,KAAK,EAAE,MAAM,IAAI,CAAC;CAC9D;AACD;AASA,MAAM,WAAW,OAAO,SAKI;CAY3B,QAAO,MAXc,KAAK,QAAQ,KAAK;EACtC,YAAY,KAAK;EACjB,OAAO;EACP,OAAO;EAGP,gBAAgB;EAChB,YAAY;EACZ,GAAI,KAAK,IAAI,MAAM,EAAE,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC;EAC5C,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;CAC3C,CAAC,GACa,KAAK,IAAI,WAAW;AACnC;;;;;;;;;;;;;AAcA,MAAa,mBAAmB,YAA+C;CAC9E,MAAM,SA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AO;IACP,OAAO;IACP,gBAAgB;IAChB,GAAI,IAAI,MAAM,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC;IAClC;GACD,CAAC,GACkB,KAAK,IAAI,WAAW,EAAE;GACzC,OAAO,MAAM,OAAO,KAAK,MAAM,IAAI;EACpC;EAGA,iBAAiB,OAAO,OAAO,QAAQ;GACtC,MAAM,SAAS,YAAY,GAAG;GAC9B,MAAM,QAAe,SAClB,EAAE,KAAK,CAAC,QAAQ,GAAG,OAAO,YAAY,EAAE,IAAI,MAAM,EAAE,CAAC,EAAE,IACvD,GAAG,OAAO,YAAY,EAAE,IAAI,MAAM,EAAE;GACvC,MAAM,SAAS,MAAM,IAAI,QAAQ,KAAK;IACrC,YAAY,QAAQ;IACpB,OAAO;IACP,OAAO;IACP,gBAAgB;IAChB,YAAY;IACZ,GAAI,IAAI,MAAM,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC;IAClC;GACD,CAAC;GACD,MAAM,wBAAQ,IAAI,IAAsB;GACxC,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,WAAW,GAAG;IAC/C,MAAM,OAAO,OAAO,KAAK,MAAM;IAC/B,IAAI,MAAM,MAAM,IAAI,KAAK,MAAM,IAAI;GACpC;GACA,OAAO;EACR;CACD;AACD"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { resolveIconValue } from "../shared/value.js";
|
|
3
3
|
import { resolveRenderedIcon } from "./resolveRendered.js";
|
|
4
4
|
import React, { Suspense, createContext, useContext } from "react";
|
|
5
|
-
import { Fragment
|
|
5
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/fields/icon/react/createIcon.tsx
|
|
7
7
|
/**
|
|
8
8
|
* Carries the caller's `fallback` down to the cached lazy component. The lazy is
|
|
@@ -12,7 +12,7 @@ import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
|
12
12
|
*/
|
|
13
13
|
const FallbackContext = createContext(null);
|
|
14
14
|
/** Stands in for an icon the adapter resolved to null, so a miss renders the caller's fallback. */
|
|
15
|
-
const MissingIcon = () => /* @__PURE__ */ jsx(Fragment
|
|
15
|
+
const MissingIcon = () => /* @__PURE__ */ jsx(Fragment, { children: useContext(FallbackContext) });
|
|
16
16
|
/**
|
|
17
17
|
* Client dispatcher: per-value React.lazy components cached module-wide so a
|
|
18
18
|
* value renders one stable lazy component (per-icon chunks, loaded once).
|
|
@@ -38,10 +38,10 @@ const createIcon = (args) => {
|
|
|
38
38
|
return component;
|
|
39
39
|
};
|
|
40
40
|
const Icon = ({ className, fallback = null, icon, label, size = 20 }) => {
|
|
41
|
-
if (!icon) return /* @__PURE__ */ jsx(Fragment
|
|
41
|
+
if (!icon) return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
42
42
|
const { library, name } = resolveIconValue(icon, defaultLibrary);
|
|
43
43
|
const Component = lazyFor(library, name);
|
|
44
|
-
if (!Component) return /* @__PURE__ */ jsx(Fragment
|
|
44
|
+
if (!Component) return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
45
45
|
const tree = /* @__PURE__ */ jsx(Suspense, {
|
|
46
46
|
fallback,
|
|
47
47
|
children: /* @__PURE__ */ jsx(Component, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createIcon.js","names":[],"sources":["../../../../src/fields/icon/react/createIcon.tsx"],"sourcesContent":["'use client'\n\nimport type { ComponentType, ReactNode } from 'react'\nimport React, { createContext, Suspense, useContext } from 'react'\nimport { resolveIconValue } from '../shared/value'\nimport { resolveRenderedIcon } from './resolveRendered'\nimport type { IconProps, IconRendererAdapter, IconRenderProps } from './types'\n\n/**\n * Carries the caller's `fallback` down to the cached lazy component. The lazy is\n * cached module-wide on `library:name` so a repeated value loads its chunk once,\n * which means it cannot close over any one caller's prop. Context is how a shared\n * component reads a per-subtree value without giving up that cache.\n */\nconst FallbackContext = createContext<ReactNode>(null)\n\n/** Stands in for an icon the adapter resolved to null, so a miss renders the caller's fallback. */\nconst MissingIcon: ComponentType<IconRenderProps> = () => <>{useContext(FallbackContext)}</>\n\n/**\n * Client dispatcher: per-value React.lazy components cached module-wide so a\n * value renders one stable lazy component (per-icon chunks, loaded once).\n *\n * A rejected load stays cached, because React.lazy caches its own rejection.\n * That is deliberate: retrying would re-request a failing icon on every render\n * against an endpoint already struggling. `createRscIcon` evicts instead, because\n * a server render has no equivalent re-render pressure.\n */\nexport const createIcon = (args: {\n\tadapters: IconRendererAdapter[]\n\tdefaultLibrary?: string\n}): React.FC<IconProps> => {\n\tconst bySlug = new Map(args.adapters.map((adapter) => [adapter.slug, adapter]))\n\tconst defaultLibrary = args.defaultLibrary ?? args.adapters[0]?.slug ?? ''\n\tconst cache = new Map<string, ComponentType<IconRenderProps>>()\n\n\tconst lazyFor = (library: string, name: string): ComponentType<IconRenderProps> | null => {\n\t\tconst adapter = bySlug.get(library)\n\t\tif (!adapter) return null\n\t\tconst key = `${library}:${name}`\n\t\tlet component = cache.get(key)\n\t\tif (!component) {\n\t\t\tcomponent = React.lazy(async () => ({\n\t\t\t\tdefault: (await resolveRenderedIcon(adapter, name)) ?? MissingIcon,\n\t\t\t})) as unknown as ComponentType<IconRenderProps>\n\t\t\tcache.set(key, component)\n\t\t}\n\t\treturn component\n\t}\n\n\tconst Icon: React.FC<IconProps> = ({ className, fallback = null, icon, label, size = 20 }) => {\n\t\tif (!icon) return <>{fallback}</>\n\t\tconst { library, name } = resolveIconValue(icon, defaultLibrary)\n\t\tconst Component = lazyFor(library, name)\n\t\tif (!Component) return <>{fallback}</>\n\t\tconst tree = (\n\t\t\t<Suspense fallback={fallback}>\n\t\t\t\t<Component\n\t\t\t\t\taria-hidden={label ? undefined : true}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tclassName={className}\n\t\t\t\t\trole={label ? 'img' : undefined}\n\t\t\t\t\tsize={size}\n\t\t\t\t/>\n\t\t\t</Suspense>\n\t\t)\n\t\t// Provider only where there is something to carry, so the common decorative\n\t\t// call renders exactly the tree it always did.\n\t\treturn fallback == null ? (\n\t\t\ttree\n\t\t) : (\n\t\t\t<FallbackContext.Provider value={fallback}>{tree}</FallbackContext.Provider>\n\t\t)\n\t}\n\treturn Icon\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,kBAAkB,cAAyB,IAAI;;AAGrD,MAAM,oBAAoD,oBAAA,
|
|
1
|
+
{"version":3,"file":"createIcon.js","names":[],"sources":["../../../../src/fields/icon/react/createIcon.tsx"],"sourcesContent":["'use client'\n\nimport type { ComponentType, ReactNode } from 'react'\nimport React, { createContext, Suspense, useContext } from 'react'\nimport { resolveIconValue } from '../shared/value'\nimport { resolveRenderedIcon } from './resolveRendered'\nimport type { IconProps, IconRendererAdapter, IconRenderProps } from './types'\n\n/**\n * Carries the caller's `fallback` down to the cached lazy component. The lazy is\n * cached module-wide on `library:name` so a repeated value loads its chunk once,\n * which means it cannot close over any one caller's prop. Context is how a shared\n * component reads a per-subtree value without giving up that cache.\n */\nconst FallbackContext = createContext<ReactNode>(null)\n\n/** Stands in for an icon the adapter resolved to null, so a miss renders the caller's fallback. */\nconst MissingIcon: ComponentType<IconRenderProps> = () => <>{useContext(FallbackContext)}</>\n\n/**\n * Client dispatcher: per-value React.lazy components cached module-wide so a\n * value renders one stable lazy component (per-icon chunks, loaded once).\n *\n * A rejected load stays cached, because React.lazy caches its own rejection.\n * That is deliberate: retrying would re-request a failing icon on every render\n * against an endpoint already struggling. `createRscIcon` evicts instead, because\n * a server render has no equivalent re-render pressure.\n */\nexport const createIcon = (args: {\n\tadapters: IconRendererAdapter[]\n\tdefaultLibrary?: string\n}): React.FC<IconProps> => {\n\tconst bySlug = new Map(args.adapters.map((adapter) => [adapter.slug, adapter]))\n\tconst defaultLibrary = args.defaultLibrary ?? args.adapters[0]?.slug ?? ''\n\tconst cache = new Map<string, ComponentType<IconRenderProps>>()\n\n\tconst lazyFor = (library: string, name: string): ComponentType<IconRenderProps> | null => {\n\t\tconst adapter = bySlug.get(library)\n\t\tif (!adapter) return null\n\t\tconst key = `${library}:${name}`\n\t\tlet component = cache.get(key)\n\t\tif (!component) {\n\t\t\tcomponent = React.lazy(async () => ({\n\t\t\t\tdefault: (await resolveRenderedIcon(adapter, name)) ?? MissingIcon,\n\t\t\t})) as unknown as ComponentType<IconRenderProps>\n\t\t\tcache.set(key, component)\n\t\t}\n\t\treturn component\n\t}\n\n\tconst Icon: React.FC<IconProps> = ({ className, fallback = null, icon, label, size = 20 }) => {\n\t\tif (!icon) return <>{fallback}</>\n\t\tconst { library, name } = resolveIconValue(icon, defaultLibrary)\n\t\tconst Component = lazyFor(library, name)\n\t\tif (!Component) return <>{fallback}</>\n\t\tconst tree = (\n\t\t\t<Suspense fallback={fallback}>\n\t\t\t\t<Component\n\t\t\t\t\taria-hidden={label ? undefined : true}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tclassName={className}\n\t\t\t\t\trole={label ? 'img' : undefined}\n\t\t\t\t\tsize={size}\n\t\t\t\t/>\n\t\t\t</Suspense>\n\t\t)\n\t\t// Provider only where there is something to carry, so the common decorative\n\t\t// call renders exactly the tree it always did.\n\t\treturn fallback == null ? (\n\t\t\ttree\n\t\t) : (\n\t\t\t<FallbackContext.Provider value={fallback}>{tree}</FallbackContext.Provider>\n\t\t)\n\t}\n\treturn Icon\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,kBAAkB,cAAyB,IAAI;;AAGrD,MAAM,oBAAoD,oBAAA,UAAA,EAAA,UAAG,WAAW,eAAe,EAAI,CAAA;;;;;;;;;;AAW3F,MAAa,cAAc,SAGA;CAC1B,MAAM,SAAS,IAAI,IAAI,KAAK,SAAS,KAAK,YAAY,CAAC,QAAQ,MAAM,OAAO,CAAC,CAAC;CAC9E,MAAM,iBAAiB,KAAK,kBAAkB,KAAK,SAAS,IAAI,QAAQ;CACxE,MAAM,wBAAQ,IAAI,IAA4C;CAE9D,MAAM,WAAW,SAAiB,SAAwD;EACzF,MAAM,UAAU,OAAO,IAAI,OAAO;EAClC,IAAI,CAAC,SAAS,OAAO;EACrB,MAAM,MAAM,GAAG,QAAQ,GAAG;EAC1B,IAAI,YAAY,MAAM,IAAI,GAAG;EAC7B,IAAI,CAAC,WAAW;GACf,YAAY,MAAM,KAAK,aAAa,EACnC,SAAU,MAAM,oBAAoB,SAAS,IAAI,KAAM,YACxD,EAAE;GACF,MAAM,IAAI,KAAK,SAAS;EACzB;EACA,OAAO;CACR;CAEA,MAAM,QAA6B,EAAE,WAAW,WAAW,MAAM,MAAM,OAAO,OAAO,SAAS;EAC7F,IAAI,CAAC,MAAM,OAAO,oBAAA,UAAA,EAAA,UAAG,SAAW,CAAA;EAChC,MAAM,EAAE,SAAS,SAAS,iBAAiB,MAAM,cAAc;EAC/D,MAAM,YAAY,QAAQ,SAAS,IAAI;EACvC,IAAI,CAAC,WAAW,OAAO,oBAAA,UAAA,EAAA,UAAG,SAAW,CAAA;EACrC,MAAM,OACL,oBAAC,UAAD;GAAoB;aACnB,oBAAC,WAAD;IACC,eAAa,QAAQ,KAAA,IAAY;IACjC,cAAY;IACD;IACX,MAAM,QAAQ,QAAQ,KAAA;IAChB;GACN,CAAA;EACQ,CAAA;EAIX,OAAO,YAAY,OAClB,OAEA,oBAAC,gBAAgB,UAAjB;GAA0B,OAAO;aAAW;EAA+B,CAAA;CAE7E;CACA,OAAO;AACR"}
|
|
@@ -4,9 +4,9 @@ import { keys } from "../../../translations/keys.js";
|
|
|
4
4
|
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
5
5
|
import { commitDrafts, draftsFor } from "./editModel.js";
|
|
6
6
|
import { useMeasurementModel } from "./useMeasurementModel.js";
|
|
7
|
-
import { FieldDescription, FieldError, FieldLabel, Popup, RenderCustomComponent, fieldBaseClass } from "@payloadcms/ui";
|
|
7
|
+
import { FieldDescription, FieldError, FieldLabel, MoreIcon, Popup, RenderCustomComponent, fieldBaseClass } from "@payloadcms/ui";
|
|
8
8
|
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
9
|
-
import { Fragment
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
import "./measurementField.css";
|
|
11
11
|
//#region src/fields/measurement/client/MeasurementInput.tsx
|
|
12
12
|
const baseClass = "fields-measurement";
|
|
@@ -21,32 +21,10 @@ const CLEAN = {
|
|
|
21
21
|
* the row into overflow.
|
|
22
22
|
*/
|
|
23
23
|
const draftWidth = (draft) => ({ width: `${Math.min(Math.max(draft.length, 2), 12) + .5}ch` });
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
/** Payload's own "more" glyph, turned upright: a vertical kebab reads as the row's menu. */
|
|
25
|
+
const unitKebab = /* @__PURE__ */ jsx(MoreIcon, {
|
|
26
26
|
className: `${baseClass}__kebab`,
|
|
27
|
-
|
|
28
|
-
viewBox: "0 0 4 16",
|
|
29
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
30
|
-
children: [
|
|
31
|
-
/* @__PURE__ */ jsx("circle", {
|
|
32
|
-
cx: "2",
|
|
33
|
-
cy: "2",
|
|
34
|
-
fill: "currentColor",
|
|
35
|
-
r: "1.6"
|
|
36
|
-
}),
|
|
37
|
-
/* @__PURE__ */ jsx("circle", {
|
|
38
|
-
cx: "2",
|
|
39
|
-
cy: "8",
|
|
40
|
-
fill: "currentColor",
|
|
41
|
-
r: "1.6"
|
|
42
|
-
}),
|
|
43
|
-
/* @__PURE__ */ jsx("circle", {
|
|
44
|
-
cx: "2",
|
|
45
|
-
cy: "14",
|
|
46
|
-
fill: "currentColor",
|
|
47
|
-
r: "1.6"
|
|
48
|
-
})
|
|
49
|
-
]
|
|
27
|
+
size: 24
|
|
50
28
|
});
|
|
51
29
|
/** The row itself, shared by `MeasurementInput` and the form-bound `MeasurementField`. */
|
|
52
30
|
const MeasurementInputView = (props) => {
|
|
@@ -168,11 +146,15 @@ const MeasurementInputView = (props) => {
|
|
|
168
146
|
const isUnitInteractive = units.length > 1 && !isReadOnly;
|
|
169
147
|
const renderUnitPanel = ({ close }) => /* @__PURE__ */ jsx("div", {
|
|
170
148
|
"aria-label": t(keys.selectUnit),
|
|
171
|
-
className: `${baseClass}__unit-panel`,
|
|
149
|
+
className: `${baseClass}__unit-panel popup-button-list`,
|
|
172
150
|
role: "listbox",
|
|
173
151
|
children: units.map((unit) => /* @__PURE__ */ jsxs("button", {
|
|
174
152
|
"aria-selected": unit === displayUnit,
|
|
175
|
-
className:
|
|
153
|
+
className: [
|
|
154
|
+
`${baseClass}__unit-option`,
|
|
155
|
+
"popup-button-list__button",
|
|
156
|
+
unit === displayUnit && "popup-button-list__button--selected"
|
|
157
|
+
].filter(Boolean).join(" "),
|
|
176
158
|
onClick: () => {
|
|
177
159
|
selectUnit(unit);
|
|
178
160
|
close();
|
|
@@ -193,7 +175,7 @@ const MeasurementInputView = (props) => {
|
|
|
193
175
|
if (!isUnitInteractive) return null;
|
|
194
176
|
const shortLabel = engine.unitLabel(displayUnit, locale, "short");
|
|
195
177
|
return /* @__PURE__ */ jsx(Popup, {
|
|
196
|
-
button: /* @__PURE__ */ jsxs(Fragment
|
|
178
|
+
button: /* @__PURE__ */ jsxs(Fragment, { children: [unitKebab, /* @__PURE__ */ jsxs("span", {
|
|
197
179
|
className: `${baseClass}__sr-only`,
|
|
198
180
|
children: [
|
|
199
181
|
t(keys.selectUnit),
|
|
@@ -242,7 +224,11 @@ const MeasurementInputView = (props) => {
|
|
|
242
224
|
}),
|
|
243
225
|
BeforeInput,
|
|
244
226
|
/* @__PURE__ */ jsxs("div", {
|
|
245
|
-
className:
|
|
227
|
+
className: [
|
|
228
|
+
`${baseClass}__container`,
|
|
229
|
+
"form-input-group",
|
|
230
|
+
showError && "form-input-group-error"
|
|
231
|
+
].filter(Boolean).join(" "),
|
|
246
232
|
onMouseDown: focusNearestInput,
|
|
247
233
|
children: [isCompound && compoundDef ? /* @__PURE__ */ jsxs("span", {
|
|
248
234
|
className: `${baseClass}__compound`,
|
|
@@ -281,7 +267,7 @@ const MeasurementInputView = (props) => {
|
|
|
281
267
|
value: drafts.minor
|
|
282
268
|
}), renderUnitSuffix(compoundDef.minor)]
|
|
283
269
|
})]
|
|
284
|
-
}) : /* @__PURE__ */ jsxs(Fragment
|
|
270
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
|
|
285
271
|
className: `${baseClass}__input`,
|
|
286
272
|
id: inputId,
|
|
287
273
|
inputMode: "decimal",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MeasurementInput.js","names":["useTranslation"],"sources":["../../../../src/fields/measurement/client/MeasurementInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n} from '@payloadcms/ui'\nimport type { StaticDescription, StaticLabel } from 'payload'\nimport type React from 'react'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { COMPOUNDS, type MeasurementUnitId } from '../engine/units'\nimport { commitDrafts, type DirtyDrafts, draftsFor, type MeasurementDrafts } from './editModel'\nimport {\n\ttype MeasurementInputOptions,\n\ttype MeasurementModel,\n\tuseMeasurementModel,\n} from './useMeasurementModel'\nimport './measurementField.css'\n\nconst baseClass = 'fields-measurement'\n\nconst CLEAN: DirtyDrafts = { minor: false, primary: false }\n\n/**\n * Every value input sizes to its content so \"5 ft 11 in\" (or a lone scalar)\n * reads as one left-aligned phrase. The half-ch keeps the caret off the edge;\n * the clamp keeps an empty input clickable and a runaway draft from pushing\n * the row into overflow.\n */\nconst draftWidth = (draft: string): React.CSSProperties => ({\n\twidth: `${Math.min(Math.max(draft.length, 2), 12) + 0.5}ch`,\n})\n\nconst unitKebab = (\n\t<svg\n\t\taria-hidden=\"true\"\n\t\tclassName={`${baseClass}__kebab`}\n\t\tfocusable=\"false\"\n\t\tviewBox=\"0 0 4 16\"\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t>\n\t\t<circle cx=\"2\" cy=\"2\" fill=\"currentColor\" r=\"1.6\" />\n\t\t<circle cx=\"2\" cy=\"8\" fill=\"currentColor\" r=\"1.6\" />\n\t\t<circle cx=\"2\" cy=\"14\" fill=\"currentColor\" r=\"1.6\" />\n\t</svg>\n)\n\n/**\n * Props for the form-free measurement input. `value` is the number in\n * `options.storageUnit`, exactly as `measurementField` stores it; the viewer reads and\n * types in their display unit.\n */\nexport type MeasurementInputProps = {\n\tvalue: null | number | undefined\n\t/** Fires on every edit with the value converted back to the storage unit. */\n\tonChange: (value: null | number) => void\n\toptions: MeasurementInputOptions\n\t/** Bounds in the storage unit; a value outside them shows a message in the display unit. */\n\tmin?: number\n\tmax?: number\n\t/** Names the input (`id`, `name`, label `htmlFor`), as on a native field. */\n\tpath?: string\n\tlabel?: StaticLabel\n\tdescription?: StaticDescription\n\tplaceholder?: string\n\trequired?: boolean\n\tlocalized?: boolean\n\treadOnly?: boolean\n\t/** Message shown in the error tooltip. Left unset, the input reports its own bound errors. */\n\terror?: string\n\t/** Forces the error state on or off. Left unset, it follows `error` and the bound check. */\n\tshowError?: boolean\n\tclassName?: string\n\tstyle?: React.CSSProperties\n\tLabel?: React.ReactNode\n\tError?: React.ReactNode\n\tDescription?: React.ReactNode\n\tBeforeInput?: React.ReactNode\n\tAfterInput?: React.ReactNode\n}\n\ntype MeasurementInputViewProps = { model: MeasurementModel } & Omit<\n\tMeasurementInputProps,\n\t'options'\n>\n\n/** The row itself, shared by `MeasurementInput` and the form-bound `MeasurementField`. */\nexport const MeasurementInputView: React.FC<MeasurementInputViewProps> = (props) => {\n\tconst {\n\t\tAfterInput,\n\t\tBeforeInput,\n\t\tclassName,\n\t\tDescription,\n\t\tdescription,\n\t\tError: ErrorComponent,\n\t\terror,\n\t\tLabel,\n\t\tlabel,\n\t\tlocalized,\n\t\tmax,\n\t\tmin,\n\t\tmodel,\n\t\tonChange,\n\t\tpath,\n\t\tplaceholder,\n\t\treadOnly,\n\t\trequired,\n\t\tshowError: showErrorFromProps,\n\t\tstyle,\n\t\tvalue,\n\t} = props\n\tconst {\n\t\tdisplayPrecision,\n\t\tdisplayUnit,\n\t\tengine,\n\t\tfmtBound,\n\t\tlocale,\n\t\tresolvedPrecision,\n\t\tselectUnit: selectModelUnit,\n\t\tstorageUnit,\n\t\tunits,\n\t} = model\n\tconst { t } = useTranslation()\n\tconst isReadOnly = Boolean(readOnly)\n\n\tconst numericValue = typeof value === 'number' && !Number.isNaN(value) ? value : null\n\tconst draftOpts = useMemo(\n\t\t() => ({\n\t\t\tdisplayUnit,\n\t\t\tdraft: resolvedPrecision.draft,\n\t\t\tengine,\n\t\t\tprecision: displayPrecision,\n\t\t\tstorageDigits: resolvedPrecision.storage,\n\t\t\tstorageUnit,\n\t\t}),\n\t\t[displayUnit, engine, displayPrecision, resolvedPrecision, storageUnit]\n\t)\n\n\t// Payload's server-driven form-state refresh (conditional-logic revalidation on\n\t// every change) can replace this field's errorMessage with the server's raw,\n\t// storage-unit message before our own throttled client validate lands. Compute\n\t// the unit-aware bound message independently and pass it straight to FieldError\n\t// so display never depends on winning that race.\n\tconst boundsMessage = useMemo(() => {\n\t\tif (numericValue === null) return undefined\n\t\tif (typeof min === 'number' && numericValue < min) {\n\t\t\treturn t(keys.measurementBelowMin, { min: fmtBound(min) })\n\t\t}\n\t\tif (typeof max === 'number' && numericValue > max) {\n\t\t\treturn t(keys.measurementAboveMax, { max: fmtBound(max) })\n\t\t}\n\t\treturn undefined\n\t}, [numericValue, min, max, fmtBound, t])\n\tconst errorMessage = error ?? boundsMessage\n\tconst showError = showErrorFromProps ?? errorMessage !== undefined\n\n\tconst editingRef = useRef(false)\n\tconst [drafts, setDrafts] = useState<MeasurementDrafts>(() => draftsFor(numericValue, draftOpts))\n\t// The drafts as painted on screen immediately before the current edit, refreshed\n\t// only at a resync (mount, external value, blur, unit switch) and never per\n\t// keystroke. A carry-rounded display (182.5 cm storage paints as 6 ft 0 in even\n\t// though the exact split is 5 ft 11.850394 in) must never be mistaken for the\n\t// exact stored value, so commits diff the typed value against this baseline\n\t// rather than against the exact decompose.\n\tconst paintedDraftsRef = useRef<MeasurementDrafts>(drafts)\n\t// The stored value the painted drafts were derived from, frozen at the same\n\t// resync points as paintedDraftsRef. A mid-edit commit updates the live value\n\t// (and so `numericValue`) before the viewer blurs; diffing the next keystroke's\n\t// delta against that advanced value, instead of this frozen snapshot, would\n\t// re-apply an already-committed delta on top of itself.\n\tconst paintedStoredRef = useRef<number | null>(numericValue)\n\t// Which part the viewer has actually typed into since the last resync: an\n\t// untouched part must commit the value it already holds, never whatever the\n\t// display-policy draft happens to show for it.\n\tconst [dirty, setDirty] = useState<DirtyDrafts>(CLEAN)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) {\n\t\t\tconst resynced = draftsFor(numericValue, draftOpts)\n\t\t\tsetDrafts(resynced)\n\t\t\tpaintedDraftsRef.current = resynced\n\t\t\tpaintedStoredRef.current = numericValue\n\t\t\tsetDirty(CLEAN)\n\t\t}\n\t}, [numericValue, draftOpts])\n\n\tconst onDraftChange = useCallback(\n\t\t(part: keyof MeasurementDrafts) => (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\teditingRef.current = true\n\t\t\tconst next = { ...drafts, [part]: event.target.value }\n\t\t\tconst nextDirty = { ...dirty, [part]: true }\n\t\t\tsetDrafts(next)\n\t\t\tsetDirty(nextDirty)\n\t\t\tonChange(\n\t\t\t\tcommitDrafts(next, {\n\t\t\t\t\t...draftOpts,\n\t\t\t\t\tdirty: nextDirty,\n\t\t\t\t\tentry: resolvedPrecision.entry,\n\t\t\t\t\tpaintedDrafts: paintedDraftsRef.current,\n\t\t\t\t\tstoredValue: paintedStoredRef.current,\n\t\t\t\t})\n\t\t\t)\n\t\t},\n\t\t[dirty, drafts, draftOpts, onChange, resolvedPrecision.entry]\n\t)\n\n\tconst onBlur = useCallback(() => {\n\t\teditingRef.current = false\n\t\tconst resynced = draftsFor(numericValue, draftOpts)\n\t\tsetDrafts(resynced)\n\t\tpaintedDraftsRef.current = resynced\n\t\tpaintedStoredRef.current = numericValue\n\t\tsetDirty(CLEAN)\n\t}, [numericValue, draftOpts])\n\n\tconst selectUnit = useCallback(\n\t\t(unit: MeasurementUnitId) => {\n\t\t\teditingRef.current = false\n\t\t\tsetDirty(CLEAN)\n\t\t\tselectModelUnit(unit)\n\t\t},\n\t\t[selectModelUnit]\n\t)\n\n\tconst isCompound = engine.isCompoundUnit(displayUnit)\n\tconst compoundDef = isCompound ? COMPOUNDS[displayUnit] : null\n\t// Without a path there is no field id to derive, so the label pairs with a generated one\n\tconst generatedId = useId()\n\tconst inputId = path ? `field-${path.replace(/\\./g, '__')}` : generatedId\n\n\tconst primaryInputRef = useRef<HTMLInputElement>(null)\n\tconst minorInputRef = useRef<HTMLInputElement>(null)\n\n\t// Dead-space (or the passive unit suffix, e.g. \"in\") mousedown focuses the nearest\n\t// input like a native control; preventDefault stops an already-focused input from\n\t// blurring, so we never steal focus from it. The suffix is never inside the unit\n\t// trigger button, so this never intercepts opening the unit popup.\n\tconst focusNearestInput = useCallback((event: React.MouseEvent<HTMLElement>) => {\n\t\tconst target = event.target as HTMLElement\n\t\tconst isUnitSuffix = target.closest(`.${baseClass}__unit-static`) !== null\n\t\tif (target !== event.currentTarget && !isUnitSuffix) return\n\t\tevent.preventDefault()\n\t\tconst active = document.activeElement\n\t\tif (active === primaryInputRef.current || active === minorInputRef.current) return\n\t\tconst inputs = [primaryInputRef.current, minorInputRef.current].filter(\n\t\t\t(input): input is HTMLInputElement => input !== null\n\t\t)\n\t\tconst [first, ...rest] = inputs\n\t\tif (!first) return\n\t\tconst distanceFrom = (input: HTMLInputElement) => {\n\t\t\tconst rect = input.getBoundingClientRect()\n\t\t\treturn Math.abs(event.clientX - (rect.left + rect.width / 2))\n\t\t}\n\t\tlet nearest = first\n\t\tlet nearestDistance = distanceFrom(first)\n\t\tfor (const input of rest) {\n\t\t\tconst distance = distanceFrom(input)\n\t\t\tif (distance < nearestDistance) {\n\t\t\t\tnearestDistance = distance\n\t\t\t\tnearest = input\n\t\t\t}\n\t\t}\n\t\tnearest.focus()\n\t}, [])\n\n\tconst isUnitInteractive = units.length > 1 && !isReadOnly\n\n\tconst renderUnitPanel = ({ close }: { close: () => void }) => (\n\t\t<div aria-label={t(keys.selectUnit)} className={`${baseClass}__unit-panel`} role=\"listbox\">\n\t\t\t{units.map((unit) => (\n\t\t\t\t<button\n\t\t\t\t\taria-selected={unit === displayUnit}\n\t\t\t\t\tclassName={`${baseClass}__unit-option`}\n\t\t\t\t\tkey={unit}\n\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\tselectUnit(unit)\n\t\t\t\t\t\tclose()\n\t\t\t\t\t}}\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t>\n\t\t\t\t\t<span>{engine.unitLabel(unit, locale, 'long')}</span>\n\t\t\t\t\t<span className={`${baseClass}__unit-symbol`}>\n\t\t\t\t\t\t{engine.unitLabel(unit, locale, 'short')}\n\t\t\t\t\t</span>\n\t\t\t\t</button>\n\t\t\t))}\n\t\t</div>\n\t)\n\n\tconst renderUnitSuffix = (unit: MeasurementUnitId) => (\n\t\t<span className={`${baseClass}__unit-static`}>{engine.unitLabel(unit, locale, 'short')}</span>\n\t)\n\n\t// One kebab per field, pinned to the row's right edge; the unit text itself\n\t// stays a passive suffix so value and unit read as a single phrase.\n\tconst renderMenuTrigger = () => {\n\t\tif (!isUnitInteractive) return null\n\t\tconst shortLabel = engine.unitLabel(displayUnit, locale, 'short')\n\t\treturn (\n\t\t\t<Popup\n\t\t\t\tbutton={\n\t\t\t\t\t<>\n\t\t\t\t\t\t{unitKebab}\n\t\t\t\t\t\t<span className={`${baseClass}__sr-only`}>\n\t\t\t\t\t\t\t{t(keys.selectUnit)}: {shortLabel}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</>\n\t\t\t\t}\n\t\t\t\tbuttonClassName={`${baseClass}__unit-trigger`}\n\t\t\t\tbuttonType=\"default\"\n\t\t\t\tcaret={false}\n\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\thorizontalAlign=\"right\"\n\t\t\t\trender={renderUnitPanel}\n\t\t\t\tsize=\"fit-content\"\n\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t/>\n\t\t)\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\tshowError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={style}\n\t\t>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel\n\t\t\t\t\t\thtmlFor={path ? undefined : inputId}\n\t\t\t\t\t\tlabel={label}\n\t\t\t\t\t\tlocalized={localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError message={errorMessage} path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t{/* biome-ignore lint/a11y/noStaticElementInteractions: mousedown only refocuses an inner input, it adds no control and changes no semantics */}\n\t\t\t\t<div className={`${baseClass}__container`} onMouseDown={focusNearestInput}>\n\t\t\t\t\t{isCompound && compoundDef ? (\n\t\t\t\t\t\t// biome-ignore lint/a11y/noStaticElementInteractions: same as the container, refocuses whichever inner input is nearest\n\t\t\t\t\t\t<span className={`${baseClass}__compound`} onMouseDown={focusNearestInput}>\n\t\t\t\t\t\t\t<span className={`${baseClass}__part`}>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\t\tonChange={onDraftChange('primary')}\n\t\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\t\tref={primaryInputRef}\n\t\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.primary)}\n\t\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\t\tvalue={drafts.primary}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{renderUnitSuffix(compoundDef.major)}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className={`${baseClass}__part`}>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\taria-label={engine.unitLabel(compoundDef.minor, locale, 'long')}\n\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\t\tmax={compoundDef.ratio - 0.001}\n\t\t\t\t\t\t\t\t\tmin={0}\n\t\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\t\tonChange={onDraftChange('minor')}\n\t\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\t\tref={minorInputRef}\n\t\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.minor)}\n\t\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\t\tvalue={drafts.minor}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{renderUnitSuffix(compoundDef.minor)}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\tonChange={onDraftChange('primary')}\n\t\t\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\tref={primaryInputRef}\n\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.primary || placeholder || '')}\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tvalue={drafts.primary}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{renderUnitSuffix(displayUnit)}\n\t\t\t\t\t\t</>\n\t\t\t\t\t)}\n\t\t\t\t\t{renderMenuTrigger()}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path ?? ''} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\n/**\n * The measurement field's row, unit menu and conversion pipeline with no form behind\n * it, for custom admin views and components. Inside the admin the display unit is the\n * viewer's saved preference for `preferenceKey`, shared with every measurement field\n * on that key; `MeasurementField` is this plus `useField`.\n */\nexport const MeasurementInput: React.FC<MeasurementInputProps> = ({ options, ...props }) => {\n\tconst model = useMeasurementModel(options)\n\treturn <MeasurementInputView model={model} {...props} />\n}\n"],"mappings":";;;;;;;;;;;AAuBA,MAAM,YAAY;AAElB,MAAM,QAAqB;CAAE,OAAO;CAAO,SAAS;AAAM;;;;;;;AAQ1D,MAAM,cAAc,WAAwC,EAC3D,OAAO,GAAG,KAAK,IAAI,KAAK,IAAI,MAA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sB,OADf,oBAAoB,OACM;EAAG,GAAI;CAAQ,CAAA;AACxD"}
|
|
1
|
+
{"version":3,"file":"MeasurementInput.js","names":["useTranslation"],"sources":["../../../../src/fields/measurement/client/MeasurementInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tMoreIcon,\n\tPopup,\n\tRenderCustomComponent,\n} from '@payloadcms/ui'\nimport type { StaticDescription, StaticLabel } from 'payload'\nimport type React from 'react'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { COMPOUNDS, type MeasurementUnitId } from '../engine/units'\nimport { commitDrafts, type DirtyDrafts, draftsFor, type MeasurementDrafts } from './editModel'\nimport {\n\ttype MeasurementInputOptions,\n\ttype MeasurementModel,\n\tuseMeasurementModel,\n} from './useMeasurementModel'\nimport './measurementField.css'\n\nconst baseClass = 'fields-measurement'\n\nconst CLEAN: DirtyDrafts = { minor: false, primary: false }\n\n/**\n * Every value input sizes to its content so \"5 ft 11 in\" (or a lone scalar)\n * reads as one left-aligned phrase. The half-ch keeps the caret off the edge;\n * the clamp keeps an empty input clickable and a runaway draft from pushing\n * the row into overflow.\n */\nconst draftWidth = (draft: string): React.CSSProperties => ({\n\twidth: `${Math.min(Math.max(draft.length, 2), 12) + 0.5}ch`,\n})\n\n/** Payload's own \"more\" glyph, turned upright: a vertical kebab reads as the row's menu. */\nconst unitKebab = <MoreIcon className={`${baseClass}__kebab`} size={24} />\n\n/**\n * Props for the form-free measurement input. `value` is the number in\n * `options.storageUnit`, exactly as `measurementField` stores it; the viewer reads and\n * types in their display unit.\n */\nexport type MeasurementInputProps = {\n\tvalue: null | number | undefined\n\t/** Fires on every edit with the value converted back to the storage unit. */\n\tonChange: (value: null | number) => void\n\toptions: MeasurementInputOptions\n\t/** Bounds in the storage unit; a value outside them shows a message in the display unit. */\n\tmin?: number\n\tmax?: number\n\t/** Names the input (`id`, `name`, label `htmlFor`), as on a native field. */\n\tpath?: string\n\tlabel?: StaticLabel\n\tdescription?: StaticDescription\n\tplaceholder?: string\n\trequired?: boolean\n\tlocalized?: boolean\n\treadOnly?: boolean\n\t/** Message shown in the error tooltip. Left unset, the input reports its own bound errors. */\n\terror?: string\n\t/** Forces the error state on or off. Left unset, it follows `error` and the bound check. */\n\tshowError?: boolean\n\tclassName?: string\n\tstyle?: React.CSSProperties\n\tLabel?: React.ReactNode\n\tError?: React.ReactNode\n\tDescription?: React.ReactNode\n\tBeforeInput?: React.ReactNode\n\tAfterInput?: React.ReactNode\n}\n\ntype MeasurementInputViewProps = { model: MeasurementModel } & Omit<\n\tMeasurementInputProps,\n\t'options'\n>\n\n/** The row itself, shared by `MeasurementInput` and the form-bound `MeasurementField`. */\nexport const MeasurementInputView: React.FC<MeasurementInputViewProps> = (props) => {\n\tconst {\n\t\tAfterInput,\n\t\tBeforeInput,\n\t\tclassName,\n\t\tDescription,\n\t\tdescription,\n\t\tError: ErrorComponent,\n\t\terror,\n\t\tLabel,\n\t\tlabel,\n\t\tlocalized,\n\t\tmax,\n\t\tmin,\n\t\tmodel,\n\t\tonChange,\n\t\tpath,\n\t\tplaceholder,\n\t\treadOnly,\n\t\trequired,\n\t\tshowError: showErrorFromProps,\n\t\tstyle,\n\t\tvalue,\n\t} = props\n\tconst {\n\t\tdisplayPrecision,\n\t\tdisplayUnit,\n\t\tengine,\n\t\tfmtBound,\n\t\tlocale,\n\t\tresolvedPrecision,\n\t\tselectUnit: selectModelUnit,\n\t\tstorageUnit,\n\t\tunits,\n\t} = model\n\tconst { t } = useTranslation()\n\tconst isReadOnly = Boolean(readOnly)\n\n\tconst numericValue = typeof value === 'number' && !Number.isNaN(value) ? value : null\n\tconst draftOpts = useMemo(\n\t\t() => ({\n\t\t\tdisplayUnit,\n\t\t\tdraft: resolvedPrecision.draft,\n\t\t\tengine,\n\t\t\tprecision: displayPrecision,\n\t\t\tstorageDigits: resolvedPrecision.storage,\n\t\t\tstorageUnit,\n\t\t}),\n\t\t[displayUnit, engine, displayPrecision, resolvedPrecision, storageUnit]\n\t)\n\n\t// Payload's server-driven form-state refresh (conditional-logic revalidation on\n\t// every change) can replace this field's errorMessage with the server's raw,\n\t// storage-unit message before our own throttled client validate lands. Compute\n\t// the unit-aware bound message independently and pass it straight to FieldError\n\t// so display never depends on winning that race.\n\tconst boundsMessage = useMemo(() => {\n\t\tif (numericValue === null) return undefined\n\t\tif (typeof min === 'number' && numericValue < min) {\n\t\t\treturn t(keys.measurementBelowMin, { min: fmtBound(min) })\n\t\t}\n\t\tif (typeof max === 'number' && numericValue > max) {\n\t\t\treturn t(keys.measurementAboveMax, { max: fmtBound(max) })\n\t\t}\n\t\treturn undefined\n\t}, [numericValue, min, max, fmtBound, t])\n\tconst errorMessage = error ?? boundsMessage\n\tconst showError = showErrorFromProps ?? errorMessage !== undefined\n\n\tconst editingRef = useRef(false)\n\tconst [drafts, setDrafts] = useState<MeasurementDrafts>(() => draftsFor(numericValue, draftOpts))\n\t// The drafts as painted on screen immediately before the current edit, refreshed\n\t// only at a resync (mount, external value, blur, unit switch) and never per\n\t// keystroke. A carry-rounded display (182.5 cm storage paints as 6 ft 0 in even\n\t// though the exact split is 5 ft 11.850394 in) must never be mistaken for the\n\t// exact stored value, so commits diff the typed value against this baseline\n\t// rather than against the exact decompose.\n\tconst paintedDraftsRef = useRef<MeasurementDrafts>(drafts)\n\t// The stored value the painted drafts were derived from, frozen at the same\n\t// resync points as paintedDraftsRef. A mid-edit commit updates the live value\n\t// (and so `numericValue`) before the viewer blurs; diffing the next keystroke's\n\t// delta against that advanced value, instead of this frozen snapshot, would\n\t// re-apply an already-committed delta on top of itself.\n\tconst paintedStoredRef = useRef<number | null>(numericValue)\n\t// Which part the viewer has actually typed into since the last resync: an\n\t// untouched part must commit the value it already holds, never whatever the\n\t// display-policy draft happens to show for it.\n\tconst [dirty, setDirty] = useState<DirtyDrafts>(CLEAN)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) {\n\t\t\tconst resynced = draftsFor(numericValue, draftOpts)\n\t\t\tsetDrafts(resynced)\n\t\t\tpaintedDraftsRef.current = resynced\n\t\t\tpaintedStoredRef.current = numericValue\n\t\t\tsetDirty(CLEAN)\n\t\t}\n\t}, [numericValue, draftOpts])\n\n\tconst onDraftChange = useCallback(\n\t\t(part: keyof MeasurementDrafts) => (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\teditingRef.current = true\n\t\t\tconst next = { ...drafts, [part]: event.target.value }\n\t\t\tconst nextDirty = { ...dirty, [part]: true }\n\t\t\tsetDrafts(next)\n\t\t\tsetDirty(nextDirty)\n\t\t\tonChange(\n\t\t\t\tcommitDrafts(next, {\n\t\t\t\t\t...draftOpts,\n\t\t\t\t\tdirty: nextDirty,\n\t\t\t\t\tentry: resolvedPrecision.entry,\n\t\t\t\t\tpaintedDrafts: paintedDraftsRef.current,\n\t\t\t\t\tstoredValue: paintedStoredRef.current,\n\t\t\t\t})\n\t\t\t)\n\t\t},\n\t\t[dirty, drafts, draftOpts, onChange, resolvedPrecision.entry]\n\t)\n\n\tconst onBlur = useCallback(() => {\n\t\teditingRef.current = false\n\t\tconst resynced = draftsFor(numericValue, draftOpts)\n\t\tsetDrafts(resynced)\n\t\tpaintedDraftsRef.current = resynced\n\t\tpaintedStoredRef.current = numericValue\n\t\tsetDirty(CLEAN)\n\t}, [numericValue, draftOpts])\n\n\tconst selectUnit = useCallback(\n\t\t(unit: MeasurementUnitId) => {\n\t\t\teditingRef.current = false\n\t\t\tsetDirty(CLEAN)\n\t\t\tselectModelUnit(unit)\n\t\t},\n\t\t[selectModelUnit]\n\t)\n\n\tconst isCompound = engine.isCompoundUnit(displayUnit)\n\tconst compoundDef = isCompound ? COMPOUNDS[displayUnit] : null\n\t// Without a path there is no field id to derive, so the label pairs with a generated one\n\tconst generatedId = useId()\n\tconst inputId = path ? `field-${path.replace(/\\./g, '__')}` : generatedId\n\n\tconst primaryInputRef = useRef<HTMLInputElement>(null)\n\tconst minorInputRef = useRef<HTMLInputElement>(null)\n\n\t// Dead-space (or the passive unit suffix, e.g. \"in\") mousedown focuses the nearest\n\t// input like a native control; preventDefault stops an already-focused input from\n\t// blurring, so we never steal focus from it. The suffix is never inside the unit\n\t// trigger button, so this never intercepts opening the unit popup.\n\tconst focusNearestInput = useCallback((event: React.MouseEvent<HTMLElement>) => {\n\t\tconst target = event.target as HTMLElement\n\t\tconst isUnitSuffix = target.closest(`.${baseClass}__unit-static`) !== null\n\t\tif (target !== event.currentTarget && !isUnitSuffix) return\n\t\tevent.preventDefault()\n\t\tconst active = document.activeElement\n\t\tif (active === primaryInputRef.current || active === minorInputRef.current) return\n\t\tconst inputs = [primaryInputRef.current, minorInputRef.current].filter(\n\t\t\t(input): input is HTMLInputElement => input !== null\n\t\t)\n\t\tconst [first, ...rest] = inputs\n\t\tif (!first) return\n\t\tconst distanceFrom = (input: HTMLInputElement) => {\n\t\t\tconst rect = input.getBoundingClientRect()\n\t\t\treturn Math.abs(event.clientX - (rect.left + rect.width / 2))\n\t\t}\n\t\tlet nearest = first\n\t\tlet nearestDistance = distanceFrom(first)\n\t\tfor (const input of rest) {\n\t\t\tconst distance = distanceFrom(input)\n\t\t\tif (distance < nearestDistance) {\n\t\t\t\tnearestDistance = distance\n\t\t\t\tnearest = input\n\t\t\t}\n\t\t}\n\t\tnearest.focus()\n\t}, [])\n\n\tconst isUnitInteractive = units.length > 1 && !isReadOnly\n\n\tconst renderUnitPanel = ({ close }: { close: () => void }) => (\n\t\t<div\n\t\t\taria-label={t(keys.selectUnit)}\n\t\t\tclassName={`${baseClass}__unit-panel popup-button-list`}\n\t\t\trole=\"listbox\"\n\t\t>\n\t\t\t{units.map((unit) => (\n\t\t\t\t<button\n\t\t\t\t\taria-selected={unit === displayUnit}\n\t\t\t\t\tclassName={[\n\t\t\t\t\t\t`${baseClass}__unit-option`,\n\t\t\t\t\t\t'popup-button-list__button',\n\t\t\t\t\t\tunit === displayUnit && 'popup-button-list__button--selected',\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\tkey={unit}\n\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\tselectUnit(unit)\n\t\t\t\t\t\tclose()\n\t\t\t\t\t}}\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t>\n\t\t\t\t\t<span>{engine.unitLabel(unit, locale, 'long')}</span>\n\t\t\t\t\t<span className={`${baseClass}__unit-symbol`}>\n\t\t\t\t\t\t{engine.unitLabel(unit, locale, 'short')}\n\t\t\t\t\t</span>\n\t\t\t\t</button>\n\t\t\t))}\n\t\t</div>\n\t)\n\n\tconst renderUnitSuffix = (unit: MeasurementUnitId) => (\n\t\t<span className={`${baseClass}__unit-static`}>{engine.unitLabel(unit, locale, 'short')}</span>\n\t)\n\n\t// One kebab per field, pinned to the row's right edge; the unit text itself\n\t// stays a passive suffix so value and unit read as a single phrase.\n\tconst renderMenuTrigger = () => {\n\t\tif (!isUnitInteractive) return null\n\t\tconst shortLabel = engine.unitLabel(displayUnit, locale, 'short')\n\t\treturn (\n\t\t\t// @todo Payload 4's Popup pins its panel to the viewport edge once the field scrolls out of\n\t\t\t// view (v3 let it scroll away with the field). Adopt the option if Payload adds one.\n\t\t\t<Popup\n\t\t\t\tbutton={\n\t\t\t\t\t<>\n\t\t\t\t\t\t{unitKebab}\n\t\t\t\t\t\t<span className={`${baseClass}__sr-only`}>\n\t\t\t\t\t\t\t{t(keys.selectUnit)}: {shortLabel}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</>\n\t\t\t\t}\n\t\t\t\tbuttonClassName={`${baseClass}__unit-trigger`}\n\t\t\t\tbuttonType=\"default\"\n\t\t\t\tcaret={false}\n\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\thorizontalAlign=\"right\"\n\t\t\t\trender={renderUnitPanel}\n\t\t\t\tsize=\"fit-content\"\n\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t/>\n\t\t)\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\tshowError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={style}\n\t\t>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel\n\t\t\t\t\t\thtmlFor={path ? undefined : inputId}\n\t\t\t\t\t\tlabel={label}\n\t\t\t\t\t\tlocalized={localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError message={errorMessage} path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t{/* biome-ignore lint/a11y/noStaticElementInteractions: mousedown only refocuses an inner input, it adds no control and changes no semantics */}\n\t\t\t\t<div\n\t\t\t\t\tclassName={[\n\t\t\t\t\t\t`${baseClass}__container`,\n\t\t\t\t\t\t'form-input-group',\n\t\t\t\t\t\tshowError && 'form-input-group-error',\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\tonMouseDown={focusNearestInput}\n\t\t\t\t>\n\t\t\t\t\t{isCompound && compoundDef ? (\n\t\t\t\t\t\t// biome-ignore lint/a11y/noStaticElementInteractions: same as the container, refocuses whichever inner input is nearest\n\t\t\t\t\t\t<span className={`${baseClass}__compound`} onMouseDown={focusNearestInput}>\n\t\t\t\t\t\t\t<span className={`${baseClass}__part`}>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\t\tonChange={onDraftChange('primary')}\n\t\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\t\tref={primaryInputRef}\n\t\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.primary)}\n\t\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\t\tvalue={drafts.primary}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{renderUnitSuffix(compoundDef.major)}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className={`${baseClass}__part`}>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\taria-label={engine.unitLabel(compoundDef.minor, locale, 'long')}\n\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\t\tmax={compoundDef.ratio - 0.001}\n\t\t\t\t\t\t\t\t\tmin={0}\n\t\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\t\tonChange={onDraftChange('minor')}\n\t\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\t\tref={minorInputRef}\n\t\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.minor)}\n\t\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\t\tvalue={drafts.minor}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{renderUnitSuffix(compoundDef.minor)}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\tonChange={onDraftChange('primary')}\n\t\t\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\tref={primaryInputRef}\n\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.primary || placeholder || '')}\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tvalue={drafts.primary}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{renderUnitSuffix(displayUnit)}\n\t\t\t\t\t\t</>\n\t\t\t\t\t)}\n\t\t\t\t\t{renderMenuTrigger()}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path ?? ''} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\n/**\n * The measurement field's row, unit menu and conversion pipeline with no form behind\n * it, for custom admin views and components. Inside the admin the display unit is the\n * viewer's saved preference for `preferenceKey`, shared with every measurement field\n * on that key; `MeasurementField` is this plus `useField`.\n */\nexport const MeasurementInput: React.FC<MeasurementInputProps> = ({ options, ...props }) => {\n\tconst model = useMeasurementModel(options)\n\treturn <MeasurementInputView model={model} {...props} />\n}\n"],"mappings":";;;;;;;;;;;AAwBA,MAAM,YAAY;AAElB,MAAM,QAAqB;CAAE,OAAO;CAAO,SAAS;AAAM;;;;;;;AAQ1D,MAAM,cAAc,WAAwC,EAC3D,OAA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|
}
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
container reads as one native text input; focus rides :focus-within.
|
|
7
|
-
Dimensions are static px on purpose: Payload compiles scss base() to literal px
|
|
8
|
-
(native inputs stay 40px tall at every breakpoint), while the runtime --base var
|
|
9
|
-
is rem-based and shrinks with the responsive html font-size. Deriving from
|
|
10
|
-
var(--base) made this container 3px shorter than native inputs at <=1024px. */
|
|
11
|
-
.fields-measurement__container {
|
|
5
|
+
.fields-measurement > .field-type__wrap {
|
|
12
6
|
display: flex;
|
|
13
|
-
|
|
14
|
-
gap:
|
|
15
|
-
width: 100%;
|
|
16
|
-
height: 40px;
|
|
17
|
-
padding: 0 8px 0 6px;
|
|
18
|
-
border: 1px solid var(--theme-elevation-150);
|
|
19
|
-
border-radius: var(--style-radius-s);
|
|
20
|
-
background: var(--theme-input-bg);
|
|
21
|
-
color: var(--theme-elevation-800);
|
|
22
|
-
font-family: var(--font-body);
|
|
23
|
-
font-size: 1rem;
|
|
24
|
-
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
|
|
25
|
-
transition-property: border, box-shadow, background-color;
|
|
26
|
-
transition-duration: 100ms, 100ms, 500ms;
|
|
27
|
-
transition-timing-function: cubic-bezier(0, 0.2, 0.2, 1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.fields-measurement__container:hover {
|
|
31
|
-
border-color: var(--theme-elevation-250);
|
|
32
|
-
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.2);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.fields-measurement__container:focus-within {
|
|
36
|
-
border-color: var(--theme-elevation-400);
|
|
37
|
-
outline: 0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
html[data-theme="light"] .fields-measurement.error .fields-measurement__container {
|
|
41
|
-
background-color: var(--theme-error-50);
|
|
42
|
-
border-color: var(--theme-error-500);
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
gap: var(--spacer-2);
|
|
43
9
|
}
|
|
44
10
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
11
|
+
/* Payload's .form-input-group (on the same element) owns the border, background, radius,
|
|
12
|
+
height and the hover, focus, error and disabled states; this only lays out the row. */
|
|
13
|
+
.fields-measurement__container {
|
|
14
|
+
align-items: center;
|
|
15
|
+
gap: var(--spacer-1);
|
|
16
|
+
padding-inline: var(--field-padding-inline) var(--spacer-1);
|
|
17
|
+
color: var(--field-color-text);
|
|
18
|
+
font-family: var(--font-body);
|
|
19
|
+
font-size: var(--text-body-medium-font-size);
|
|
20
|
+
font-weight: var(--text-body-medium-font-weight);
|
|
21
|
+
line-height: var(--text-body-medium-line-height);
|
|
48
22
|
}
|
|
49
23
|
|
|
50
|
-
|
|
51
|
-
|
|
24
|
+
/* Native read-only inputs are disabled inputs on v4, so the row takes the disabled look.
|
|
25
|
+
A read-only input still takes focus here; Payload's .form-input:read-only:focus answers
|
|
26
|
+
that with the hover border, and so does this. */
|
|
27
|
+
.fields-measurement.read-only .fields-measurement__container {
|
|
28
|
+
border-color: var(--field-color-border-disabled);
|
|
29
|
+
background: var(--field-color-bg-disabled);
|
|
30
|
+
color: var(--field-color-text-disabled);
|
|
52
31
|
}
|
|
53
32
|
|
|
54
|
-
.fields-measurement.read-only .fields-measurement__container
|
|
55
|
-
|
|
56
|
-
border-color: var(--theme-elevation-150);
|
|
57
|
-
background: var(--theme-elevation-100);
|
|
58
|
-
color: var(--theme-elevation-400);
|
|
59
|
-
box-shadow: none;
|
|
33
|
+
.fields-measurement.read-only .fields-measurement__container:focus-within {
|
|
34
|
+
border-color: var(--field-color-border-hover);
|
|
60
35
|
}
|
|
61
36
|
|
|
62
37
|
/* Each value hugs its unit; the wider gap separates the pairs, so the row
|
|
@@ -64,32 +39,27 @@ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container
|
|
|
64
39
|
.fields-measurement__compound {
|
|
65
40
|
display: flex;
|
|
66
41
|
flex: 1 1 auto;
|
|
42
|
+
align-self: stretch;
|
|
67
43
|
min-width: 0;
|
|
68
44
|
align-items: center;
|
|
69
|
-
gap:
|
|
70
|
-
height: 100%;
|
|
45
|
+
gap: var(--spacer-2-5);
|
|
71
46
|
}
|
|
72
47
|
|
|
73
48
|
.fields-measurement__part {
|
|
74
49
|
display: flex;
|
|
50
|
+
align-self: stretch;
|
|
75
51
|
align-items: center;
|
|
76
|
-
gap:
|
|
77
|
-
height: 100%;
|
|
52
|
+
gap: var(--spacer-1);
|
|
78
53
|
}
|
|
79
54
|
|
|
80
55
|
/* Width comes from an inline style tracking the draft's length, so every value
|
|
81
56
|
(scalar or compound part) hugs its digits instead of stretching the row */
|
|
82
57
|
.fields-measurement__input {
|
|
83
58
|
flex: 0 1 auto;
|
|
59
|
+
align-self: stretch;
|
|
84
60
|
min-width: 2ch;
|
|
85
|
-
height: 100%;
|
|
86
|
-
padding: 0;
|
|
87
|
-
border: 0;
|
|
88
|
-
background: transparent;
|
|
89
61
|
color: inherit;
|
|
90
|
-
|
|
91
|
-
font-size: inherit;
|
|
92
|
-
appearance: none;
|
|
62
|
+
appearance: textfield;
|
|
93
63
|
-webkit-appearance: none;
|
|
94
64
|
-moz-appearance: textfield;
|
|
95
65
|
}
|
|
@@ -105,13 +75,13 @@ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container
|
|
|
105
75
|
}
|
|
106
76
|
|
|
107
77
|
.fields-measurement__input::placeholder {
|
|
108
|
-
color: var(--
|
|
78
|
+
color: var(--field-color-placeholder);
|
|
109
79
|
}
|
|
110
80
|
|
|
111
|
-
/* margin-
|
|
112
|
-
value-unit phrase
|
|
81
|
+
/* margin-inline-start auto pins the kebab to the row's end, away from the
|
|
82
|
+
value-unit phrase */
|
|
113
83
|
.fields-measurement__popup {
|
|
114
|
-
margin-
|
|
84
|
+
margin-inline-start: auto;
|
|
115
85
|
}
|
|
116
86
|
|
|
117
87
|
.fields-measurement__popup,
|
|
@@ -121,35 +91,30 @@ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container
|
|
|
121
91
|
}
|
|
122
92
|
|
|
123
93
|
/* The trigger is a real button so it keeps native focus/keyboard semantics; the
|
|
124
|
-
kebab is aria-hidden and a sr-only span next to it carries the name
|
|
94
|
+
kebab is aria-hidden and a sr-only span next to it carries the name. Payload's
|
|
95
|
+
.popup-button paints its hover and pressed fills. */
|
|
125
96
|
.fields-measurement__unit-trigger {
|
|
126
|
-
display: inline-flex;
|
|
127
97
|
flex-shrink: 0;
|
|
128
98
|
align-items: center;
|
|
129
99
|
justify-content: center;
|
|
130
|
-
width:
|
|
131
|
-
height:
|
|
132
|
-
|
|
133
|
-
border: 0;
|
|
134
|
-
border-radius: var(--style-radius-s);
|
|
135
|
-
background: transparent;
|
|
136
|
-
color: var(--theme-elevation-500);
|
|
137
|
-
cursor: pointer;
|
|
100
|
+
width: var(--spacer-4);
|
|
101
|
+
height: var(--spacer-4);
|
|
102
|
+
color: var(--color-icon-secondary);
|
|
138
103
|
}
|
|
139
104
|
|
|
140
105
|
.fields-measurement__unit-trigger:hover {
|
|
141
|
-
|
|
142
|
-
color: var(--theme-elevation-800);
|
|
106
|
+
color: var(--color-icon);
|
|
143
107
|
}
|
|
144
108
|
|
|
145
109
|
.fields-measurement__unit-trigger:focus-visible {
|
|
146
110
|
outline: var(--accessibility-outline);
|
|
147
111
|
}
|
|
148
112
|
|
|
113
|
+
/* MoreIcon's three dots sit symmetric about the centre of its box, so a quarter turn makes an
|
|
114
|
+
upright kebab without moving it. */
|
|
149
115
|
.fields-measurement__kebab {
|
|
150
116
|
flex-shrink: 0;
|
|
151
|
-
|
|
152
|
-
height: 14px;
|
|
117
|
+
transform: rotate(90deg);
|
|
153
118
|
}
|
|
154
119
|
|
|
155
120
|
.fields-measurement__sr-only {
|
|
@@ -164,52 +129,40 @@ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container
|
|
|
164
129
|
border-width: 0;
|
|
165
130
|
}
|
|
166
131
|
|
|
167
|
-
/* The unit is always a passive suffix hugging its value
|
|
168
|
-
on the kebab at the row's
|
|
132
|
+
/* The unit is always a passive suffix hugging its value, styled as the native number
|
|
133
|
+
field's suffix; interactivity lives on the kebab at the row's end (absent when there
|
|
134
|
+
is nothing to open) */
|
|
169
135
|
.fields-measurement__unit-static {
|
|
170
136
|
flex-shrink: 0;
|
|
171
|
-
color: var(--
|
|
172
|
-
font-size: 0.85rem;
|
|
137
|
+
color: var(--color-text-secondary);
|
|
173
138
|
white-space: nowrap;
|
|
174
139
|
cursor: default;
|
|
140
|
+
user-select: none;
|
|
175
141
|
}
|
|
176
142
|
|
|
177
|
-
.
|
|
178
|
-
|
|
143
|
+
.fields-measurement.read-only .fields-measurement__unit-static {
|
|
144
|
+
color: inherit;
|
|
179
145
|
}
|
|
180
146
|
|
|
147
|
+
/* Payload's .popup-button-list (on the same element) supplies the list padding, and
|
|
148
|
+
.popup-button-list__button the item type, radius, hover and selected fills. */
|
|
181
149
|
.fields-measurement__unit-panel {
|
|
182
|
-
display: flex;
|
|
183
|
-
flex-direction: column;
|
|
184
|
-
gap: 2px;
|
|
185
150
|
min-width: 180px;
|
|
186
|
-
padding: 4px;
|
|
187
151
|
}
|
|
188
152
|
|
|
189
153
|
.fields-measurement__unit-option {
|
|
190
|
-
display: flex;
|
|
191
154
|
align-items: center;
|
|
192
155
|
justify-content: space-between;
|
|
193
|
-
gap:
|
|
194
|
-
padding:
|
|
195
|
-
border: 0;
|
|
196
|
-
border-radius: var(--style-radius-s);
|
|
197
|
-
background: transparent;
|
|
198
|
-
color: var(--theme-elevation-800);
|
|
199
|
-
font-size: 1rem;
|
|
156
|
+
gap: var(--spacer-2-5);
|
|
157
|
+
padding: var(--spacer-1) var(--spacer-2);
|
|
200
158
|
text-align: start;
|
|
201
|
-
cursor: pointer;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
.fields-measurement__unit-option:hover {
|
|
205
|
-
background: var(--theme-elevation-100);
|
|
206
159
|
}
|
|
207
160
|
|
|
208
|
-
.fields-measurement__unit-
|
|
209
|
-
|
|
161
|
+
.fields-measurement__unit-symbol {
|
|
162
|
+
color: var(--color-text-secondary);
|
|
210
163
|
}
|
|
211
164
|
|
|
212
|
-
.fields-measurement__unit-
|
|
213
|
-
|
|
214
|
-
|
|
165
|
+
.fields-measurement__unit-option:is(:hover, [aria-selected="true"])
|
|
166
|
+
.fields-measurement__unit-symbol {
|
|
167
|
+
color: inherit;
|
|
215
168
|
}
|
|
@@ -6,7 +6,7 @@ const isPreference = (value) => typeof value === "object" && value !== null && !
|
|
|
6
6
|
/**
|
|
7
7
|
* The viewer's saved unit map, one query per request however many measurement
|
|
8
8
|
* fields the document renders. Mirrors Payload's own server-side preference
|
|
9
|
-
* lookup (
|
|
9
|
+
* lookup (getPreferences): find on payload-preferences by key
|
|
10
10
|
* and polymorphic user.
|
|
11
11
|
*/
|
|
12
12
|
const getUserMeasurementUnits = (req) => {
|
|
@@ -18,6 +18,7 @@ const getUserMeasurementUnits = (req) => {
|
|
|
18
18
|
collection: "payload-preferences",
|
|
19
19
|
depth: 0,
|
|
20
20
|
limit: 1,
|
|
21
|
+
overrideAccess: true,
|
|
21
22
|
pagination: false,
|
|
22
23
|
sort: "-updatedAt",
|
|
23
24
|
where: { and: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUserUnits.js","names":[],"sources":["../../../../src/fields/measurement/server/getUserUnits.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { memoForRequest } from '../../../utils/memoForRequest'\nimport { MEASUREMENT_PREFERENCE_KEY, type MeasurementUnitsPreference } from '../options'\n\nconst USER_UNITS_MEMO = Symbol('measurementField:userUnits')\n\nconst isPreference = (value: unknown): value is MeasurementUnitsPreference =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * The viewer's saved unit map, one query per request however many measurement\n * fields the document renders. Mirrors Payload's own server-side preference\n * lookup (
|
|
1
|
+
{"version":3,"file":"getUserUnits.js","names":[],"sources":["../../../../src/fields/measurement/server/getUserUnits.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { memoForRequest } from '../../../utils/memoForRequest'\nimport { MEASUREMENT_PREFERENCE_KEY, type MeasurementUnitsPreference } from '../options'\n\nconst USER_UNITS_MEMO = Symbol('measurementField:userUnits')\n\nconst isPreference = (value: unknown): value is MeasurementUnitsPreference =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * The viewer's saved unit map, one query per request however many measurement\n * fields the document renders. Mirrors Payload's own server-side preference\n * lookup (getPreferences): find on payload-preferences by key\n * and polymorphic user.\n */\nexport const getUserMeasurementUnits = (\n\treq: PayloadRequest\n): Promise<MeasurementUnitsPreference | null> => {\n\tconst { user } = req\n\tif (!user) return Promise.resolve(null)\n\treturn memoForRequest(req, USER_UNITS_MEMO, async () => {\n\t\ttry {\n\t\t\tconst result = await req.payload.find({\n\t\t\t\tcollection: 'payload-preferences',\n\t\t\t\tdepth: 0,\n\t\t\t\tlimit: 1,\n\t\t\t\t// Scoped to req.user by the where below, as Payload's own preference reads are.\n\t\t\t\toverrideAccess: true,\n\t\t\t\tpagination: false,\n\t\t\t\tsort: '-updatedAt',\n\t\t\t\twhere: {\n\t\t\t\t\tand: [\n\t\t\t\t\t\t{ key: { equals: MEASUREMENT_PREFERENCE_KEY } },\n\t\t\t\t\t\t{ 'user.value': { equals: user.id } },\n\t\t\t\t\t\t{ 'user.relationTo': { equals: user.collection } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t})\n\t\t\tconst value = result.docs[0]?.value\n\t\t\treturn isPreference(value) ? value : null\n\t\t} catch (error) {\n\t\t\treq.payload.logger.error({ err: error }, '[fields] measurement preference read failed')\n\t\t\treturn null\n\t\t}\n\t})\n}\n"],"mappings":";;;AAIA,MAAM,kBAAkB,OAAO,4BAA4B;AAE3D,MAAM,gBAAgB,UACrB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;;;;;;AAQpE,MAAa,2BACZ,QACgD;CAChD,MAAM,EAAE,SAAS;CACjB,IAAI,CAAC,MAAM,OAAO,QAAQ,QAAQ,IAAI;CACtC,OAAO,eAAe,KAAK,iBAAiB,YAAY;EACvD,IAAI;GAiBH,MAAM,SAAQ,MAhBO,IAAI,QAAQ,KAAK;IACrC,YAAY;IACZ,OAAO;IACP,OAAO;IAEP,gBAAgB;IAChB,YAAY;IACZ,MAAM;IACN,OAAO,EACN,KAAK;KACJ,EAAE,KAAK,EAAE,QAAQ,2BAA2B,EAAE;KAC9C,EAAE,cAAc,EAAE,QAAQ,KAAK,GAAG,EAAE;KACpC,EAAE,mBAAmB,EAAE,QAAQ,KAAK,WAAW,EAAE;IAClD,EACD;GACD,CAAC,GACoB,KAAK,IAAI;GAC9B,OAAO,aAAa,KAAK,IAAI,QAAQ;EACtC,SAAS,OAAO;GACf,IAAI,QAAQ,OAAO,MAAM,EAAE,KAAK,MAAM,GAAG,6CAA6C;GACtF,OAAO;EACR;CACD,CAAC;AACF"}
|