@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
|
@@ -1,26 +1,49 @@
|
|
|
1
|
+
import { formatHint } from "../hint.js";
|
|
1
2
|
import { keys } from "../../../translations/keys.js";
|
|
2
3
|
import { clampMaskDots } from "../maskDots.js";
|
|
3
4
|
import { asTranslate } from "../../../translations/server.js";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
//#region src/fields/encrypted/components/ProtectedCell.tsx
|
|
6
7
|
/**
|
|
7
|
-
* List cell for masked encrypted fields. Never renders cellData:
|
|
8
|
-
* been decrypted by afterRead
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* List cell for masked and write-only encrypted fields. Never renders cellData:
|
|
9
|
+
* list data has been decrypted by afterRead (masked) or stripped (write-only),
|
|
10
|
+
* and the list surface must not leak it. Server cell, so it translates the
|
|
11
|
+
* accessible label per the admin's locale. The dot count mirrors the field's
|
|
12
|
+
* `maskDots` (forwarded via clientProps) for list consistency, defaulting to
|
|
13
|
+
* the same 8 as the field. `setName` (write-only fields) points at the virtual
|
|
14
|
+
* set-indicator sibling in rowData; an unset secret renders an em dash instead
|
|
15
|
+
* of dots that would imply a stored value. `hintName` points at the stored
|
|
16
|
+
* identification hint, which replaces the dots when present.
|
|
12
17
|
*/
|
|
13
|
-
const ProtectedCell = ({ i18n, maskDots }) =>
|
|
18
|
+
const ProtectedCell = ({ hintName, i18n, maskDots, rowData, setName }) => {
|
|
19
|
+
const row = rowData;
|
|
20
|
+
if (setName && row?.[setName] !== true) return /* @__PURE__ */ jsx("span", {
|
|
21
|
+
"aria-label": asTranslate(i18n.t)(keys.secretNotSet),
|
|
22
|
+
className: "tenx-protected-cell",
|
|
23
|
+
role: "img",
|
|
24
|
+
children: "—"
|
|
25
|
+
});
|
|
26
|
+
const hint = hintName ? row?.[hintName] : void 0;
|
|
27
|
+
return renderLocked({
|
|
28
|
+
i18n,
|
|
29
|
+
text: typeof hint === "string" && hint.length > 0 ? formatHint(hint, clampMaskDots(maskDots)) : void 0,
|
|
30
|
+
maskDots
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const renderLocked = ({ i18n, maskDots, text }) => /* @__PURE__ */ jsxs("span", {
|
|
14
34
|
className: "tenx-protected-cell",
|
|
15
35
|
style: {
|
|
16
36
|
alignItems: "center",
|
|
17
37
|
display: "inline-flex",
|
|
18
|
-
gap: "0.4em"
|
|
38
|
+
gap: "0.4em",
|
|
39
|
+
maxWidth: "100%",
|
|
40
|
+
minWidth: 0
|
|
19
41
|
},
|
|
20
42
|
children: [/* @__PURE__ */ jsxs("svg", {
|
|
21
43
|
"aria-hidden": "true",
|
|
22
44
|
fill: "none",
|
|
23
45
|
height: "12",
|
|
46
|
+
style: { flexShrink: 0 },
|
|
24
47
|
stroke: "currentColor",
|
|
25
48
|
strokeWidth: "2",
|
|
26
49
|
viewBox: "0 0 24 24",
|
|
@@ -35,7 +58,13 @@ const ProtectedCell = ({ i18n, maskDots }) => /* @__PURE__ */ jsxs("span", {
|
|
|
35
58
|
}), /* @__PURE__ */ jsx("span", {
|
|
36
59
|
"aria-label": asTranslate(i18n.t)(keys.encryptedValue),
|
|
37
60
|
role: "img",
|
|
38
|
-
|
|
61
|
+
style: {
|
|
62
|
+
minWidth: 0,
|
|
63
|
+
overflow: "hidden",
|
|
64
|
+
textOverflow: "ellipsis",
|
|
65
|
+
whiteSpace: "nowrap"
|
|
66
|
+
},
|
|
67
|
+
children: text ?? "•".repeat(clampMaskDots(maskDots))
|
|
39
68
|
})]
|
|
40
69
|
});
|
|
41
70
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtectedCell.js","names":[],"sources":["../../../../src/fields/encrypted/components/ProtectedCell.tsx"],"sourcesContent":["import type { DefaultServerCellComponentProps } from 'payload'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate } from '../../../translations/server'\nimport { clampMaskDots } from '../maskDots'\n\n/**\n * List cell for masked encrypted fields. Never renders cellData
|
|
1
|
+
{"version":3,"file":"ProtectedCell.js","names":[],"sources":["../../../../src/fields/encrypted/components/ProtectedCell.tsx"],"sourcesContent":["import type { DefaultServerCellComponentProps } from 'payload'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate } from '../../../translations/server'\nimport { formatHint } from '../hint'\nimport { clampMaskDots } from '../maskDots'\n\n/**\n * List cell for masked and write-only encrypted fields. Never renders cellData:\n * list data has been decrypted by afterRead (masked) or stripped (write-only),\n * and the list surface must not leak it. Server cell, so it translates the\n * accessible label per the admin's locale. The dot count mirrors the field's\n * `maskDots` (forwarded via clientProps) for list consistency, defaulting to\n * the same 8 as the field. `setName` (write-only fields) points at the virtual\n * set-indicator sibling in rowData; an unset secret renders an em dash instead\n * of dots that would imply a stored value. `hintName` points at the stored\n * identification hint, which replaces the dots when present.\n */\nexport const ProtectedCell = ({\n\thintName,\n\ti18n,\n\tmaskDots,\n\trowData,\n\tsetName,\n}: DefaultServerCellComponentProps & {\n\thintName?: string\n\tmaskDots?: number\n\tsetName?: string\n}) => {\n\tconst row = rowData as Record<string, unknown> | undefined\n\tif (setName && row?.[setName] !== true) {\n\t\treturn (\n\t\t\t<span\n\t\t\t\taria-label={asTranslate(i18n.t)(keys.secretNotSet)}\n\t\t\t\tclassName=\"tenx-protected-cell\"\n\t\t\t\trole=\"img\"\n\t\t\t>\n\t\t\t\t—\n\t\t\t</span>\n\t\t)\n\t}\n\tconst hint = hintName ? row?.[hintName] : undefined\n\treturn renderLocked({\n\t\ti18n,\n\t\ttext:\n\t\t\ttypeof hint === 'string' && hint.length > 0\n\t\t\t\t? formatHint(hint, clampMaskDots(maskDots))\n\t\t\t\t: undefined,\n\t\tmaskDots,\n\t})\n}\n\nconst renderLocked = ({\n\ti18n,\n\tmaskDots,\n\ttext,\n}: Pick<DefaultServerCellComponentProps, 'i18n'> & { maskDots?: number; text?: string }) => (\n\t// Styled inline rather than through ProtectedField.css: that stylesheet is\n\t// imported by the field components, and a list view renders this cell\n\t// without mounting one, so a rule living there would not be loaded here.\n\t<span\n\t\tclassName=\"tenx-protected-cell\"\n\t\tstyle={{\n\t\t\talignItems: 'center',\n\t\t\tdisplay: 'inline-flex',\n\t\t\tgap: '0.4em',\n\t\t\tmaxWidth: '100%',\n\t\t\tminWidth: 0,\n\t\t}}\n\t>\n\t\t<svg\n\t\t\taria-hidden=\"true\"\n\t\t\tfill=\"none\"\n\t\t\theight=\"12\"\n\t\t\t// Without this the badge squashes to a sliver before the text yields.\n\t\t\tstyle={{ flexShrink: 0 }}\n\t\t\tstroke=\"currentColor\"\n\t\t\tstrokeWidth=\"2\"\n\t\t\tviewBox=\"0 0 24 24\"\n\t\t\twidth=\"12\"\n\t\t>\n\t\t\t<rect height=\"10\" rx=\"2\" width=\"14\" x=\"5\" y=\"11\" />\n\t\t\t<path d=\"M8 11V7a4 4 0 0 1 8 0v4\" />\n\t\t</svg>\n\t\t<span\n\t\t\taria-label={asTranslate(i18n.t)(keys.encryptedValue)}\n\t\t\trole=\"img\"\n\t\t\tstyle={{ minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}\n\t\t>\n\t\t\t{text ?? '•'.repeat(clampMaskDots(maskDots))}\n\t\t</span>\n\t</span>\n)\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,iBAAiB,EAC7B,UACA,MACA,UACA,SACA,cAKK;CACL,MAAM,MAAM;CACZ,IAAI,WAAW,MAAM,aAAa,MACjC,OACC,oBAAC,QAAD;EACC,cAAY,YAAY,KAAK,CAAC,EAAE,KAAK,YAAY;EACjD,WAAU;EACV,MAAK;YACL;CAEK,CAAA;CAGR,MAAM,OAAO,WAAW,MAAM,YAAY,KAAA;CAC1C,OAAO,aAAa;EACnB;EACA,MACC,OAAO,SAAS,YAAY,KAAK,SAAS,IACvC,WAAW,MAAM,cAAc,QAAQ,CAAC,IACxC,KAAA;EACJ;CACD,CAAC;AACF;AAEA,MAAM,gBAAgB,EACrB,MACA,UACA,WAKA,qBAAC,QAAD;CACC,WAAU;CACV,OAAO;EACN,YAAY;EACZ,SAAS;EACT,KAAK;EACL,UAAU;EACV,UAAU;CACX;WARD,CAUC,qBAAC,OAAD;EACC,eAAY;EACZ,MAAK;EACL,QAAO;EAEP,OAAO,EAAE,YAAY,EAAE;EACvB,QAAO;EACP,aAAY;EACZ,SAAQ;EACR,OAAM;YATP,CAWC,oBAAC,QAAD;GAAM,QAAO;GAAK,IAAG;GAAI,OAAM;GAAK,GAAE;GAAI,GAAE;EAAM,CAAA,GAClD,oBAAC,QAAD,EAAM,GAAE,0BAA2B,CAAA,CAC/B;KACL,oBAAC,QAAD;EACC,cAAY,YAAY,KAAK,CAAC,EAAE,KAAK,cAAc;EACnD,MAAK;EACL,OAAO;GAAE,UAAU;GAAG,UAAU;GAAU,cAAc;GAAY,YAAY;EAAS;YAExF,QAAQ,IAAI,OAAO,cAAc,QAAQ,CAAC;CACtC,CAAA,CACD"}
|
|
@@ -21,62 +21,106 @@
|
|
|
21
21
|
color: var(--theme-elevation-800);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
/* Attached
|
|
25
|
-
the
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
to match the native input: Payload compiles its formInput mixin to literal px,
|
|
29
|
-
while var(--base) is rem-derived and shrinks below 1024px, so a base-derived
|
|
30
|
-
height renders ~37px next to a 40px input. The doubled class outranks Payload's
|
|
31
|
-
own `.btn { height: base(2) }`, which otherwise wins by cascade order. */
|
|
24
|
+
/* Attached action buttons (eye and write-only actions): borderless indicators
|
|
25
|
+
inside the bordered cluster wrap (below), react-select style, muted until
|
|
26
|
+
hovered. The doubled class outranks Payload's own `.btn { height: base(2) }`,
|
|
27
|
+
which otherwise wins by cascade order. */
|
|
32
28
|
.tenx-protected-field__eye.tenx-protected-field__eye--attached {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
margin: 0 0 0 -1px;
|
|
29
|
+
height: 100%;
|
|
30
|
+
margin: 0;
|
|
36
31
|
padding: 0 calc(var(--base) / 2);
|
|
37
|
-
border:
|
|
38
|
-
border-
|
|
39
|
-
|
|
40
|
-
border-top-left-radius: 0;
|
|
41
|
-
border-bottom-left-radius: 0;
|
|
42
|
-
background: var(--theme-input-bg);
|
|
32
|
+
border: 0;
|
|
33
|
+
border-radius: 0;
|
|
34
|
+
background: none;
|
|
43
35
|
box-shadow: none;
|
|
44
|
-
color: var(--theme-elevation-
|
|
45
|
-
transition:
|
|
36
|
+
color: var(--theme-elevation-500);
|
|
37
|
+
transition: color 100ms cubic-bezier(0, 0.2, 0.2, 1);
|
|
46
38
|
}
|
|
47
39
|
|
|
48
40
|
.tenx-protected-field__eye--attached:hover {
|
|
49
|
-
background:
|
|
41
|
+
background: none;
|
|
42
|
+
color: var(--theme-elevation-800);
|
|
50
43
|
}
|
|
51
44
|
|
|
52
|
-
/*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
.tenx-protected-field__attached-row:hover .tenx-protected-field__eye--attached {
|
|
58
|
-
border-color: var(--theme-elevation-250);
|
|
45
|
+
/* Neighbouring actions halve their facing paddings: icons sit close while
|
|
46
|
+
every pixel of the cluster stays clickable, the hit boundary just moves to
|
|
47
|
+
the midpoint. Outer edges keep the full padding. */
|
|
48
|
+
.tenx-protected-field__eye-wrap--attached .tenx-protected-field__eye:not(:first-child) {
|
|
49
|
+
padding-left: calc(var(--base) / 4);
|
|
59
50
|
}
|
|
60
51
|
|
|
61
|
-
.tenx-protected-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
.tenx-protected-field__eye-wrap--attached .tenx-protected-field__eye:not(:last-child) {
|
|
53
|
+
padding-right: calc(var(--base) / 4);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* The cluster is a plain flex container: no border, no background of its own.
|
|
57
|
+
ALL chrome lives on the row (below), so the icons literally sit inside the
|
|
58
|
+
input's box and no state can ever render them behind a different border. */
|
|
59
|
+
.tenx-protected-field__eye-wrap--attached {
|
|
60
|
+
display: flex;
|
|
61
|
+
align-self: stretch;
|
|
62
|
+
align-items: center;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
/* Attached placement:
|
|
65
|
+
/* Attached placement: the ROW is the input. It carries the single border,
|
|
66
|
+
radius, background, shadow, and formInput's exact transition set; the
|
|
67
|
+
native input inside is stripped of all chrome (rule below), so there is
|
|
68
|
+
exactly one border around input text and action icons alike, and no
|
|
69
|
+
combination of states can ever make them differ. */
|
|
67
70
|
.tenx-protected-field__attached-row {
|
|
68
71
|
display: flex;
|
|
69
72
|
align-items: center;
|
|
73
|
+
height: 40px;
|
|
74
|
+
border: 1px solid var(--theme-elevation-150);
|
|
75
|
+
border-radius: var(--style-radius-s);
|
|
76
|
+
background: var(--theme-input-bg);
|
|
77
|
+
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
|
|
78
|
+
transition-property: border, box-shadow, background-color;
|
|
79
|
+
transition-duration: 100ms, 100ms, 500ms;
|
|
80
|
+
transition-timing-function: cubic-bezier(0, 0.2, 0.2, 1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* The row border follows the input's states, replicating formInput's own
|
|
84
|
+
precedence: hover lights it (the browser sets :hover on the input while
|
|
85
|
+
its <label> is hovered, and :has() reads that off the input, so hovering
|
|
86
|
+
an action never lights the border), focus outranks hover (declared later,
|
|
87
|
+
specificity flattened by :where), and focus-within keeps the control lit
|
|
88
|
+
while an action button holds focus, the way a clearable select keeps its
|
|
89
|
+
ring through an indicator click. The row's own shadow deepens on input
|
|
90
|
+
hover exactly as formInput's inputShadow does. */
|
|
91
|
+
.tenx-protected-field__attached-row:where(:has(input:hover)) {
|
|
92
|
+
border-color: var(--theme-elevation-250);
|
|
93
|
+
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.2);
|
|
70
94
|
}
|
|
71
95
|
|
|
96
|
+
.tenx-protected-field__attached-row:where(:focus-within) {
|
|
97
|
+
border-color: var(--theme-elevation-400);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* The native input inside the row loses every piece of its own chrome; its
|
|
101
|
+
hover/focus/active styles from formInput now paint nothing, so they cannot
|
|
102
|
+
disagree with the row. height 100% (38px inside the bordered 40px row)
|
|
103
|
+
keeps the control at native input height. */
|
|
72
104
|
.tenx-protected-field--attached .tenx-protected-field__attached-row input {
|
|
73
|
-
|
|
74
|
-
border
|
|
105
|
+
height: 100%;
|
|
106
|
+
border: 0;
|
|
107
|
+
border-radius: 0;
|
|
108
|
+
background: transparent;
|
|
109
|
+
box-shadow: none;
|
|
75
110
|
}
|
|
76
111
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
112
|
+
/* Validation error, mirrored from Payload's light/darkInputError mixins onto
|
|
113
|
+
the row (the input's own error chrome is stripped with the rest). Declared
|
|
114
|
+
last and more specific than the state rules, so error wins over hover and
|
|
115
|
+
focus exactly as it does on a native input. */
|
|
116
|
+
html[data-theme="light"] .tenx-protected-field--attached.error .tenx-protected-field__attached-row {
|
|
117
|
+
border-color: var(--theme-error-500);
|
|
118
|
+
background-color: var(--theme-error-50);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
html[data-theme="dark"] .tenx-protected-field--attached.error .tenx-protected-field__attached-row {
|
|
122
|
+
border-color: var(--theme-error-400);
|
|
123
|
+
background-color: var(--theme-error-100);
|
|
80
124
|
}
|
|
81
125
|
|
|
82
126
|
/* Corner placement: eye pinned to the top-right of the textarea wrap. */
|
|
@@ -118,9 +162,60 @@
|
|
|
118
162
|
display: none;
|
|
119
163
|
}
|
|
120
164
|
|
|
121
|
-
/*
|
|
165
|
+
/* Write-only: one always-editable input; a stored value is only a placeholder
|
|
166
|
+
(hint or dots), and every action is an attached segment or label-row icon,
|
|
167
|
+
so the field never grows past its native height. */
|
|
168
|
+
.tenx-protected-field__wo-input {
|
|
169
|
+
flex: 1 1 auto;
|
|
170
|
+
width: 100%;
|
|
171
|
+
/* Flex min-width:auto would refuse to shrink below the placeholder's width
|
|
172
|
+
and push the attached actions out of narrow containers. */
|
|
173
|
+
min-width: 0;
|
|
174
|
+
/* A rendered hint can be wider than a narrow field; browsers clip the
|
|
175
|
+
placeholder flush by default, which reads as a value that ends there.
|
|
176
|
+
On the input, not ::placeholder: that is where browsers read it from
|
|
177
|
+
for placeholder text. */
|
|
178
|
+
text-overflow: ellipsis;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* With a stored value, the "placeholder" is not a prompt but the concealed
|
|
182
|
+
face of real data, so it renders in the input's TEXT color, exactly as
|
|
183
|
+
typed characters would. Only the unset state shows a true placeholder,
|
|
184
|
+
which keeps formInput's native muted styling untouched. */
|
|
185
|
+
.tenx-protected-field__wo-input--set::placeholder {
|
|
186
|
+
color: var(--theme-elevation-800);
|
|
187
|
+
font-size: 1rem;
|
|
188
|
+
letter-spacing: 0.15em;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* Corner placement (textarea) rows its actions horizontally where the eye sits. */
|
|
192
|
+
.tenx-protected-field__actions--corner {
|
|
193
|
+
display: flex;
|
|
194
|
+
gap: 2px;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* Staged-removal notice in the structural face: a prompt about a pending
|
|
198
|
+
action, so it carries placeholder tone, unmistakably distinct from the
|
|
199
|
+
text-colored concealed dots. */
|
|
200
|
+
.tenx-protected-field__wo-face-msg {
|
|
201
|
+
color: var(--theme-elevation-400);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/* Structural face box: an input-rhythm well the label-row dots sit in. */
|
|
205
|
+
.tenx-protected-field__wo-face-box {
|
|
206
|
+
display: flex;
|
|
207
|
+
align-items: center;
|
|
208
|
+
min-height: 40px;
|
|
209
|
+
padding: 0 calc(var(--base) * 0.75);
|
|
210
|
+
border: 1px solid var(--theme-elevation-150);
|
|
211
|
+
border-radius: var(--style-radius-s);
|
|
212
|
+
background: var(--theme-input-bg);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/* Concealed dots stand in for real stored data, so they carry the input's
|
|
216
|
+
text color, not a muted placeholder tone. */
|
|
122
217
|
.tenx-protected-field__dots {
|
|
123
|
-
color: var(--theme-elevation-
|
|
218
|
+
color: var(--theme-elevation-800);
|
|
124
219
|
letter-spacing: 0.15em;
|
|
125
220
|
user-select: none;
|
|
126
221
|
white-space: nowrap;
|
|
@@ -128,7 +223,7 @@
|
|
|
128
223
|
|
|
129
224
|
.tenx-protected-field__masked-input,
|
|
130
225
|
.tenx-protected-field__masked-textarea {
|
|
131
|
-
color: var(--theme-elevation-
|
|
226
|
+
color: var(--theme-elevation-800);
|
|
132
227
|
letter-spacing: 0.15em;
|
|
133
228
|
cursor: default;
|
|
134
229
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { EncryptedFieldPatch, EncryptedProtection } from "../types.js";
|
|
2
|
+
import { NormalizedGenerate } from "../generateSecret.js";
|
|
2
3
|
import { TextFieldClientProps } from "payload";
|
|
3
4
|
import React from "react";
|
|
4
5
|
//#region src/fields/encrypted/components/ProtectedField.d.ts
|
|
5
6
|
interface ProtectedFieldProps extends TextFieldClientProps {
|
|
7
|
+
clearable?: boolean;
|
|
6
8
|
componentKey: string;
|
|
7
9
|
fieldPatch: EncryptedFieldPatch;
|
|
10
|
+
generate?: NormalizedGenerate;
|
|
8
11
|
maskDots?: number;
|
|
9
12
|
protection: EncryptedProtection;
|
|
10
13
|
}
|
|
@@ -4,6 +4,7 @@ import { EncryptedInput } from "./EncryptedInput.js";
|
|
|
4
4
|
import { EncryptedTextarea } from "./EncryptedTextarea.js";
|
|
5
5
|
import { placementFor } from "./placement.js";
|
|
6
6
|
import { StructuralField } from "./StructuralField.js";
|
|
7
|
+
import { WriteOnlyField } from "./WriteOnlyField.js";
|
|
7
8
|
import { CheckboxField, CodeField, DateTimeField, EmailField, JSONField, NumberField, PointField, RadioGroupField, SelectField, TextField, TextareaField, useFormFields } from "@payloadcms/ui";
|
|
8
9
|
import { useMemo, useState } from "react";
|
|
9
10
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -66,6 +67,19 @@ const ProtectedField = (props) => {
|
|
|
66
67
|
...props,
|
|
67
68
|
field: patchedField
|
|
68
69
|
};
|
|
70
|
+
if (protection === "writeOnly") return /* @__PURE__ */ jsx(WriteOnlyField, {
|
|
71
|
+
clearable: props.clearable !== false,
|
|
72
|
+
componentKey,
|
|
73
|
+
field: patchedField,
|
|
74
|
+
generate: props.generate,
|
|
75
|
+
hintPath: `${path}_hint`,
|
|
76
|
+
maskDots,
|
|
77
|
+
Native,
|
|
78
|
+
nativeProps,
|
|
79
|
+
path,
|
|
80
|
+
placement: placementFor(componentKey, fieldPatch.hasMany === true),
|
|
81
|
+
setPath: `${path}_set`
|
|
82
|
+
});
|
|
69
83
|
if (protection === "none" || startedEmpty) return /* @__PURE__ */ jsx(Native, { ...nativeProps });
|
|
70
84
|
const faceField = patchedField;
|
|
71
85
|
const placement = placementFor(componentKey, fieldPatch.hasMany === true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtectedField.js","names":[],"sources":["../../../../src/fields/encrypted/components/ProtectedField.tsx"],"sourcesContent":["'use client'\nimport {\n\tCheckboxField,\n\tCodeField,\n\tDateTimeField,\n\tEmailField,\n\tJSONField,\n\tNumberField,\n\tPointField,\n\tRadioGroupField,\n\tSelectField,\n\tTextareaField,\n\tTextField,\n\tuseFormFields,\n} from '@payloadcms/ui'\nimport type { TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport { clampMaskDots } from '../maskDots'\nimport type { EncryptedFieldPatch, EncryptedProtection } from '../types'\nimport { EncryptedInput } from './EncryptedInput'\nimport { EncryptedTextarea } from './EncryptedTextarea'\nimport type { EncryptedFieldConfig } from './placement'\nimport { placementFor } from './placement'\nimport { StructuralField } from './StructuralField'\nimport './ProtectedField.css'\n\n/**\n * Native components accept per-type client props; dispatch is by runtime\n * componentKey, so the map is typed at the erased component boundary.\n */\ntype AnyFieldComponent = React.ComponentType<Record<string, unknown>>\n\nconst NATIVE: Record<string, AnyFieldComponent> = {\n\tcheckbox: CheckboxField as AnyFieldComponent,\n\tcode: CodeField as AnyFieldComponent,\n\tdate: DateTimeField as AnyFieldComponent,\n\temail: EmailField as AnyFieldComponent,\n\tjson: JSONField as AnyFieldComponent,\n\tnumber: NumberField as AnyFieldComponent,\n\tpoint: PointField as AnyFieldComponent,\n\tradio: RadioGroupField as AnyFieldComponent,\n\tselect: SelectField as AnyFieldComponent,\n\ttext: TextField as AnyFieldComponent,\n\ttextarea: TextareaField as AnyFieldComponent,\n}\n\nexport interface ProtectedFieldProps extends TextFieldClientProps {\n\tcomponentKey: string\n\tfieldPatch: EncryptedFieldPatch\n\tmaskDots?: number\n\tprotection: EncryptedProtection\n}\n\n/**\n * A field with no stored content has nothing to conceal, so it renders unmasked\n * (the plain native control). Captured once at mount, so characters typed into a\n * field that started empty stay visible and the field never flips to masked\n * mid-entry; a field that already holds content is masked until revealed.\n */\nconst isEmptyValue = (value: unknown): boolean => {\n\tif (value == null || value === '') {\n\t\treturn true\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.length === 0 || value.every((item) => item == null)\n\t}\n\treturn false\n}\n\n/**\n * Single admin dispatcher for scalar and structural encrypted fields (richText\n * is its own virtual-editor field pair, wired to ProtectedRichText). Each type\n * renders as its native variant with a fixed run of dots while concealed, and an\n * inline eye toggle that swaps to the real editable native component on reveal.\n * The fieldPatch restores type-specific config (options, hasMany, date admin) on\n * the revealed component.\n *\n * Masking is visual-only by design. afterRead decrypts server-side, so the\n * field's form value is already plaintext regardless of the mask, and no masked\n * facsimile binds to that value. Two accepted consequences: (a) the plaintext\n * reaches an authorized admin's browser, since that admin already has field read\n * access and masking only stops casual over-the-shoulder display; (b) saving an\n * unchanged document re-seals with a fresh IV (version churn), because the form\n * holds plaintext, not the stored ciphertext.\n */\nexport const ProtectedField: React.FC<ProtectedFieldProps> = (props) => {\n\tconst { componentKey, field, fieldPatch, path, protection } = props\n\tconst maskDots = clampMaskDots(props.maskDots)\n\tconst startedEmptyNow = useFormFields(([fields]) => isEmptyValue(fields?.[path]?.value))\n\tconst [startedEmpty] = useState(startedEmptyNow)\n\n\tconst patchedField = useMemo(\n\t\t() => ({\n\t\t\t...field,\n\t\t\t...fieldPatch,\n\t\t\tadmin: { ...field.admin, ...fieldPatch.admin },\n\t\t}),\n\t\t[field, fieldPatch]\n\t)\n\n\tconst Native = NATIVE[componentKey] ?? (TextField as AnyFieldComponent)\n\tconst nativeProps = { ...(props as unknown as Record<string, unknown>), field: patchedField }\n\n\tif (protection === 'none' || startedEmpty) {\n\t\treturn <Native {...nativeProps} />\n\t}\n\n\tconst faceField = patchedField as unknown as EncryptedFieldConfig\n\tconst hasMany = fieldPatch.hasMany === true\n\tconst placement = placementFor(componentKey, hasMany)\n\n\tif (placement === 'attached') {\n\t\treturn (\n\t\t\t<EncryptedInput\n\t\t\t\tfield={faceField}\n\t\t\t\tkind={componentKey as 'email' | 'number' | 'text'}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tpath={path}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (placement === 'corner') {\n\t\treturn <EncryptedTextarea field={faceField} maskDots={maskDots} path={path} />\n\t}\n\n\treturn (\n\t\t<StructuralField\n\t\t\tcomponentKey={componentKey}\n\t\t\tfield={faceField}\n\t\t\tmaskDots={maskDots}\n\t\t\tNative={Native}\n\t\t\tnativeProps={nativeProps}\n\t\t\tpath={path}\n\t\t/>\n\t)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProtectedField.js","names":[],"sources":["../../../../src/fields/encrypted/components/ProtectedField.tsx"],"sourcesContent":["'use client'\nimport {\n\tCheckboxField,\n\tCodeField,\n\tDateTimeField,\n\tEmailField,\n\tJSONField,\n\tNumberField,\n\tPointField,\n\tRadioGroupField,\n\tSelectField,\n\tTextareaField,\n\tTextField,\n\tuseFormFields,\n} from '@payloadcms/ui'\nimport type { TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport type { NormalizedGenerate } from '../generateSecret'\nimport { clampMaskDots } from '../maskDots'\nimport type { EncryptedFieldPatch, EncryptedProtection } from '../types'\nimport { EncryptedInput } from './EncryptedInput'\nimport { EncryptedTextarea } from './EncryptedTextarea'\nimport type { EncryptedFieldConfig } from './placement'\nimport { placementFor } from './placement'\nimport { StructuralField } from './StructuralField'\nimport { WriteOnlyField } from './WriteOnlyField'\nimport './ProtectedField.css'\n\n/**\n * Native components accept per-type client props; dispatch is by runtime\n * componentKey, so the map is typed at the erased component boundary.\n */\ntype AnyFieldComponent = React.ComponentType<Record<string, unknown>>\n\nconst NATIVE: Record<string, AnyFieldComponent> = {\n\tcheckbox: CheckboxField as AnyFieldComponent,\n\tcode: CodeField as AnyFieldComponent,\n\tdate: DateTimeField as AnyFieldComponent,\n\temail: EmailField as AnyFieldComponent,\n\tjson: JSONField as AnyFieldComponent,\n\tnumber: NumberField as AnyFieldComponent,\n\tpoint: PointField as AnyFieldComponent,\n\tradio: RadioGroupField as AnyFieldComponent,\n\tselect: SelectField as AnyFieldComponent,\n\ttext: TextField as AnyFieldComponent,\n\ttextarea: TextareaField as AnyFieldComponent,\n}\n\nexport interface ProtectedFieldProps extends TextFieldClientProps {\n\tclearable?: boolean\n\tcomponentKey: string\n\tfieldPatch: EncryptedFieldPatch\n\tgenerate?: NormalizedGenerate\n\tmaskDots?: number\n\tprotection: EncryptedProtection\n}\n\n/**\n * A field with no stored content has nothing to conceal, so it renders unmasked\n * (the plain native control). Captured once at mount, so characters typed into a\n * field that started empty stay visible and the field never flips to masked\n * mid-entry; a field that already holds content is masked until revealed.\n */\nconst isEmptyValue = (value: unknown): boolean => {\n\tif (value == null || value === '') {\n\t\treturn true\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.length === 0 || value.every((item) => item == null)\n\t}\n\treturn false\n}\n\n/**\n * Single admin dispatcher for scalar and structural encrypted fields (richText\n * is its own virtual-editor field pair, wired to ProtectedRichText). Each type\n * renders as its native variant with a fixed run of dots while concealed, and an\n * inline eye toggle that swaps to the real editable native component on reveal.\n * The fieldPatch restores type-specific config (options, hasMany, date admin) on\n * the revealed component.\n *\n * Masking is visual-only by design. afterRead decrypts server-side, so the\n * field's form value is already plaintext regardless of the mask, and no masked\n * facsimile binds to that value. Two accepted consequences: (a) the plaintext\n * reaches an authorized admin's browser, since that admin already has field read\n * access and masking only stops casual over-the-shoulder display; (b) saving an\n * unchanged document re-seals with a fresh IV (version churn), because the form\n * holds plaintext, not the stored ciphertext.\n */\nexport const ProtectedField: React.FC<ProtectedFieldProps> = (props) => {\n\tconst { componentKey, field, fieldPatch, path, protection } = props\n\tconst maskDots = clampMaskDots(props.maskDots)\n\tconst startedEmptyNow = useFormFields(([fields]) => isEmptyValue(fields?.[path]?.value))\n\tconst [startedEmpty] = useState(startedEmptyNow)\n\n\tconst patchedField = useMemo(\n\t\t() => ({\n\t\t\t...field,\n\t\t\t...fieldPatch,\n\t\t\tadmin: { ...field.admin, ...fieldPatch.admin },\n\t\t}),\n\t\t[field, fieldPatch]\n\t)\n\n\tconst Native = NATIVE[componentKey] ?? (TextField as AnyFieldComponent)\n\tconst nativeProps = { ...(props as unknown as Record<string, unknown>), field: patchedField }\n\n\tif (protection === 'writeOnly') {\n\t\treturn (\n\t\t\t<WriteOnlyField\n\t\t\t\tclearable={props.clearable !== false}\n\t\t\t\tcomponentKey={componentKey}\n\t\t\t\tfield={patchedField as unknown as EncryptedFieldConfig}\n\t\t\t\tgenerate={props.generate}\n\t\t\t\thintPath={`${path}_hint`}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tNative={Native}\n\t\t\t\tnativeProps={nativeProps}\n\t\t\t\tpath={path}\n\t\t\t\tplacement={placementFor(componentKey, fieldPatch.hasMany === true)}\n\t\t\t\tsetPath={`${path}_set`}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (protection === 'none' || startedEmpty) {\n\t\treturn <Native {...nativeProps} />\n\t}\n\n\tconst faceField = patchedField as unknown as EncryptedFieldConfig\n\tconst hasMany = fieldPatch.hasMany === true\n\tconst placement = placementFor(componentKey, hasMany)\n\n\tif (placement === 'attached') {\n\t\treturn (\n\t\t\t<EncryptedInput\n\t\t\t\tfield={faceField}\n\t\t\t\tkind={componentKey as 'email' | 'number' | 'text'}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tpath={path}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (placement === 'corner') {\n\t\treturn <EncryptedTextarea field={faceField} maskDots={maskDots} path={path} />\n\t}\n\n\treturn (\n\t\t<StructuralField\n\t\t\tcomponentKey={componentKey}\n\t\t\tfield={faceField}\n\t\t\tmaskDots={maskDots}\n\t\t\tNative={Native}\n\t\t\tnativeProps={nativeProps}\n\t\t\tpath={path}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;AAmCA,MAAM,SAA4C;CACjD,UAAU;CACV,MAAM;CACN,MAAM;CACN,OAAO;CACP,MAAM;CACN,QAAQ;CACR,OAAO;CACP,OAAO;CACP,QAAQ;CACR,MAAM;CACN,UAAU;AACX;;;;;;;AAiBA,MAAM,gBAAgB,UAA4B;CACjD,IAAI,SAAS,QAAQ,UAAU,IAC9B,OAAO;CAER,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,WAAW,KAAK,MAAM,OAAO,SAAS,QAAQ,IAAI;CAEhE,OAAO;AACR;;;;;;;;;;;;;;;;;AAkBA,MAAa,kBAAiD,UAAU;CACvE,MAAM,EAAE,cAAc,OAAO,YAAY,MAAM,eAAe;CAC9D,MAAM,WAAW,cAAc,MAAM,QAAQ;CAE7C,MAAM,CAAC,gBAAgB,SADC,eAAe,CAAC,YAAY,aAAa,SAAS,OAAO,KAAK,CACxC,CAAC;CAE/C,MAAM,eAAe,eACb;EACN,GAAG;EACH,GAAG;EACH,OAAO;GAAE,GAAG,MAAM;GAAO,GAAG,WAAW;EAAM;CAC9C,IACA,CAAC,OAAO,UAAU,CACnB;CAEA,MAAM,SAAS,OAAO,iBAAkB;CACxC,MAAM,cAAc;EAAE,GAAI;EAA8C,OAAO;CAAa;CAE5F,IAAI,eAAe,aAClB,OACC,oBAAC,gBAAD;EACC,WAAW,MAAM,cAAc;EACjB;EACd,OAAO;EACP,UAAU,MAAM;EAChB,UAAU,GAAG,KAAK;EACR;EACF;EACK;EACP;EACN,WAAW,aAAa,cAAc,WAAW,YAAY,IAAI;EACjE,SAAS,GAAG,KAAK;CACjB,CAAA;CAIH,IAAI,eAAe,UAAU,cAC5B,OAAO,oBAAC,QAAD,EAAQ,GAAI,YAAc,CAAA;CAGlC,MAAM,YAAY;CAElB,MAAM,YAAY,aAAa,cADf,WAAW,YAAY,IACa;CAEpD,IAAI,cAAc,YACjB,OACC,oBAAC,gBAAD;EACC,OAAO;EACP,MAAM;EACI;EACJ;CACN,CAAA;CAIH,IAAI,cAAc,UACjB,OAAO,oBAAC,mBAAD;EAAmB,OAAO;EAAqB;EAAgB;CAAO,CAAA;CAG9E,OACC,oBAAC,iBAAD;EACe;EACd,OAAO;EACG;EACF;EACK;EACP;CACN,CAAA;AAEH"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Button } from "@payloadcms/ui";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/fields/encrypted/components/WriteOnlyActions.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Thin-stroke glyphs on the eye's 16x12 canvas, each drawn centered on
|
|
7
|
+
* (8, 6) so the mark sits in the middle of its clickable area, matching the
|
|
8
|
+
* eye beside which they render.
|
|
9
|
+
*/
|
|
10
|
+
const GLYPHS = {
|
|
11
|
+
clear: /* @__PURE__ */ jsx("path", {
|
|
12
|
+
className: "stroke",
|
|
13
|
+
d: "M4.5 2.5L11.5 9.5M11.5 2.5L4.5 9.5"
|
|
14
|
+
}),
|
|
15
|
+
edit: /* @__PURE__ */ jsx("path", {
|
|
16
|
+
className: "stroke",
|
|
17
|
+
d: "M3.2 11.5L3.7 9L10.2 2.5C10.75 1.95 11.65 1.95 12.2 2.5C12.75 3.05 12.75 3.95 12.2 4.5L5.7 11L3.2 11.5Z",
|
|
18
|
+
strokeLinejoin: "round"
|
|
19
|
+
}),
|
|
20
|
+
generate: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", {
|
|
21
|
+
className: "stroke",
|
|
22
|
+
d: "M13 6A5 5 0 0 0 4.5 2.8M3 6A5 5 0 0 0 11.5 9.2"
|
|
23
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
24
|
+
className: "stroke",
|
|
25
|
+
d: "M4.5 0.8V3H6.7M11.5 11.2V9H9.3",
|
|
26
|
+
strokeLinejoin: "round"
|
|
27
|
+
})] }),
|
|
28
|
+
undo: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", {
|
|
29
|
+
className: "stroke",
|
|
30
|
+
d: "M3.5 3.75H9A3.5 3.5 0 0 1 9 10.75H5"
|
|
31
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
32
|
+
className: "stroke",
|
|
33
|
+
d: "M6 1.25L3.5 3.75L6 6.25",
|
|
34
|
+
strokeLinejoin: "round"
|
|
35
|
+
})] })
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* One write-only action, rendered with the same Button shell, icon canvas, and
|
|
39
|
+
* (for attached placement) input-segment chrome as the reveal eye, so a row of
|
|
40
|
+
* actions reads as part of the input and never changes the field's height.
|
|
41
|
+
*/
|
|
42
|
+
const ActionButton = ({ attached, kind, label, onClick, pressed }) => /* @__PURE__ */ jsx(Button, {
|
|
43
|
+
"aria-label": label,
|
|
44
|
+
buttonStyle: "none",
|
|
45
|
+
className: [
|
|
46
|
+
"tenx-protected-field__eye",
|
|
47
|
+
attached ? "tenx-protected-field__eye--attached" : "tenx-protected-field__eye--floating",
|
|
48
|
+
"tenx-protected-field__action"
|
|
49
|
+
].filter(Boolean).join(" "),
|
|
50
|
+
extraButtonProps: pressed === void 0 ? void 0 : { "aria-pressed": pressed },
|
|
51
|
+
icon: /* @__PURE__ */ jsx("svg", {
|
|
52
|
+
"aria-hidden": "true",
|
|
53
|
+
className: "tenx-protected-field__eye-icon",
|
|
54
|
+
viewBox: "0 0 16 12",
|
|
55
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
56
|
+
children: GLYPHS[kind]
|
|
57
|
+
}),
|
|
58
|
+
margin: false,
|
|
59
|
+
onClick,
|
|
60
|
+
tooltip: label
|
|
61
|
+
});
|
|
62
|
+
//#endregion
|
|
63
|
+
export { ActionButton };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=WriteOnlyActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WriteOnlyActions.js","names":[],"sources":["../../../../src/fields/encrypted/components/WriteOnlyActions.tsx"],"sourcesContent":["'use client'\nimport { Button } from '@payloadcms/ui'\nimport type React from 'react'\n\nexport type ActionKind = 'clear' | 'edit' | 'generate' | 'undo'\n\n/**\n * Thin-stroke glyphs on the eye's 16x12 canvas, each drawn centered on\n * (8, 6) so the mark sits in the middle of its clickable area, matching the\n * eye beside which they render.\n */\nconst GLYPHS: Record<ActionKind, React.ReactNode> = {\n\t// × matching react-select's clear indicator.\n\tclear: <path className=\"stroke\" d=\"M4.5 2.5L11.5 9.5M11.5 2.5L4.5 9.5\" />,\n\t// Pencil.\n\tedit: (\n\t\t<path\n\t\t\tclassName=\"stroke\"\n\t\t\td=\"M3.2 11.5L3.7 9L10.2 2.5C10.75 1.95 11.65 1.95 12.2 2.5C12.75 3.05 12.75 3.95 12.2 4.5L5.7 11L3.2 11.5Z\"\n\t\t\tstrokeLinejoin=\"round\"\n\t\t/>\n\t),\n\t// Circular arrows, the rotate/regenerate convention.\n\tgenerate: (\n\t\t<>\n\t\t\t<path className=\"stroke\" d=\"M13 6A5 5 0 0 0 4.5 2.8M3 6A5 5 0 0 0 11.5 9.2\" />\n\t\t\t<path className=\"stroke\" d=\"M4.5 0.8V3H6.7M11.5 11.2V9H9.3\" strokeLinejoin=\"round\" />\n\t\t</>\n\t),\n\t// Counter-clockwise undo arrow.\n\tundo: (\n\t\t<>\n\t\t\t<path className=\"stroke\" d=\"M3.5 3.75H9A3.5 3.5 0 0 1 9 10.75H5\" />\n\t\t\t<path className=\"stroke\" d=\"M6 1.25L3.5 3.75L6 6.25\" strokeLinejoin=\"round\" />\n\t\t</>\n\t),\n}\n\n/**\n * One write-only action, rendered with the same Button shell, icon canvas, and\n * (for attached placement) input-segment chrome as the reveal eye, so a row of\n * actions reads as part of the input and never changes the field's height.\n */\nexport const ActionButton: React.FC<{\n\tattached?: boolean\n\tkind: ActionKind\n\tlabel: string\n\tonClick: () => void\n\tpressed?: boolean\n}> = ({ attached, kind, label, onClick, pressed }) => (\n\t<Button\n\t\taria-label={label}\n\t\tbuttonStyle=\"none\"\n\t\tclassName={[\n\t\t\t'tenx-protected-field__eye',\n\t\t\tattached ? 'tenx-protected-field__eye--attached' : 'tenx-protected-field__eye--floating',\n\t\t\t'tenx-protected-field__action',\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(' ')}\n\t\textraButtonProps={pressed === undefined ? undefined : { 'aria-pressed': pressed }}\n\t\ticon={\n\t\t\t<svg\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tclassName=\"tenx-protected-field__eye-icon\"\n\t\t\t\tviewBox=\"0 0 16 12\"\n\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t>\n\t\t\t\t{GLYPHS[kind]}\n\t\t\t</svg>\n\t\t}\n\t\tmargin={false}\n\t\tonClick={onClick}\n\t\ttooltip={label}\n\t/>\n)\n"],"mappings":";;;;;;;;;AAWA,MAAM,SAA8C;CAEnD,OAAO,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAsC,CAAA;CAExE,MACC,oBAAC,QAAD;EACC,WAAU;EACV,GAAE;EACF,gBAAe;CACf,CAAA;CAGF,UACC,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAkD,CAAA,GAC7E,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;EAAiC,gBAAe;CAAS,CAAA,CACnF,EAAA,CAAA;CAGH,MACC,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAuC,CAAA,GAClE,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;EAA0B,gBAAe;CAAS,CAAA,CAC5E,EAAA,CAAA;AAEJ;;;;;;AAOA,MAAa,gBAMP,EAAE,UAAU,MAAM,OAAO,SAAS,cACvC,oBAAC,QAAD;CACC,cAAY;CACZ,aAAY;CACZ,WAAW;EACV;EACA,WAAW,wCAAwC;EACnD;CACD,EACE,OAAO,OAAO,EACd,KAAK,GAAG;CACV,kBAAkB,YAAY,KAAA,IAAY,KAAA,IAAY,EAAE,gBAAgB,QAAQ;CAChF,MACC,oBAAC,OAAD;EACC,eAAY;EACZ,WAAU;EACV,SAAQ;EACR,OAAM;YAEL,OAAO;CACJ,CAAA;CAEN,QAAQ;CACC;CACT,SAAS;AACT,CAAA"}
|