payload-intl 1.3.2 → 1.4.0
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/README.md +23 -3
- package/dist/components/MessagesField.d.ts +12 -0
- package/dist/components/MessagesField.d.ts.map +1 -0
- package/dist/components/MessagesField.js +36 -0
- package/dist/components/MessagesField.js.map +1 -0
- package/dist/components/MessagesImport.d.ts +2 -0
- package/dist/components/MessagesImport.d.ts.map +1 -0
- package/dist/components/MessagesImport.js +68 -0
- package/dist/components/MessagesImport.js.map +1 -0
- package/dist/components/MessagesImport.module.css +8 -0
- package/dist/components/input/LexicalInput.d.ts +8 -0
- package/dist/components/input/LexicalInput.d.ts.map +1 -0
- package/dist/components/input/LexicalInput.js +21 -0
- package/dist/components/input/LexicalInput.js.map +1 -0
- package/dist/components/input/MessageInput.d.ts +12 -0
- package/dist/components/input/MessageInput.d.ts.map +1 -0
- package/dist/components/{inputs → input}/MessageInput.js +31 -38
- package/dist/components/input/MessageInput.js.map +1 -0
- package/dist/components/{inputs → input}/MessageInput.module.css +14 -19
- package/dist/components/{inputs → input}/ReferencePopover.d.ts +1 -1
- package/dist/components/input/ReferencePopover.d.ts.map +1 -0
- package/dist/components/{inputs → input}/ReferencePopover.js +20 -5
- package/dist/components/input/ReferencePopover.js.map +1 -0
- package/dist/components/input/SingleLinePlugin.d.ts.map +1 -0
- package/dist/components/input/SingleLinePlugin.js.map +1 -0
- package/dist/components/{hooks → input}/useHtmlLexicalAdapter.d.ts.map +1 -1
- package/dist/components/{hooks → input}/useHtmlLexicalAdapter.js.map +1 -1
- package/dist/{utils/format.d.ts → components/input/utils.d.ts} +2 -2
- package/dist/components/input/utils.d.ts.map +1 -0
- package/dist/{utils/format.js → components/input/utils.js} +2 -2
- package/dist/components/input/utils.js.map +1 -0
- package/dist/components/input/variables/VariableChip.d.ts.map +1 -0
- package/dist/components/{inputs → input}/variables/VariableChip.js +1 -2
- package/dist/components/input/variables/VariableChip.js.map +1 -0
- package/dist/components/input/variables/VariableIcon.d.ts.map +1 -0
- package/dist/components/input/variables/VariableIcon.js.map +1 -0
- package/dist/components/input/variables/VariableNode.d.ts.map +1 -0
- package/dist/components/input/variables/VariableNode.js.map +1 -0
- package/dist/components/input/variables/VariableSuggestion.d.ts.map +1 -0
- package/dist/components/input/variables/VariableSuggestion.js.map +1 -0
- package/dist/components/input/variables/editors/PluralVariableEditor.d.ts.map +1 -0
- package/dist/components/{inputs → input}/variables/editors/PluralVariableEditor.js +1 -1
- package/dist/components/input/variables/editors/PluralVariableEditor.js.map +1 -0
- package/dist/components/input/variables/editors/SelectVariableEditor.d.ts.map +1 -0
- package/dist/components/{inputs → input}/variables/editors/SelectVariableEditor.js +1 -1
- package/dist/components/input/variables/editors/SelectVariableEditor.js.map +1 -0
- package/dist/components/input/variables/editors/TagVariableEditor.d.ts.map +1 -0
- package/dist/components/{inputs → input}/variables/editors/TagVariableEditor.js +1 -1
- package/dist/components/input/variables/editors/TagVariableEditor.js.map +1 -0
- package/dist/components/input/variables/editors/TemporalVariableEditor.d.ts.map +1 -0
- package/dist/components/input/variables/editors/TemporalVariableEditor.js.map +1 -0
- package/dist/components/input/variables/pickers/NumericVariableEditor.d.ts.map +1 -0
- package/dist/components/{inputs → input}/variables/pickers/NumericVariableEditor.js +1 -1
- package/dist/components/input/variables/pickers/NumericVariableEditor.js.map +1 -0
- package/dist/components/input/variables/pickers/TemporalVariablePicker.d.ts.map +1 -0
- package/dist/components/{inputs → input}/variables/pickers/TemporalVariablePicker.js +1 -1
- package/dist/components/input/variables/pickers/TemporalVariablePicker.js.map +1 -0
- package/dist/components/layout/MessageField.d.ts +5 -4
- package/dist/components/layout/MessageField.d.ts.map +1 -1
- package/dist/components/layout/MessageField.js +44 -51
- package/dist/components/layout/MessageField.js.map +1 -1
- package/dist/components/layout/MessageField.module.css +17 -5
- package/dist/components/layout/MessagesTabs.d.ts.map +1 -1
- package/dist/components/layout/MessagesTabs.js +9 -19
- package/dist/components/layout/MessagesTabs.js.map +1 -1
- package/dist/components/layout/MessagesTree.d.ts +7 -5
- package/dist/components/layout/MessagesTree.d.ts.map +1 -1
- package/dist/components/layout/MessagesTree.js +12 -22
- package/dist/components/layout/MessagesTree.js.map +1 -1
- package/dist/components/layout/MessagesTree.module.css +7 -3
- package/dist/{utils/config.d.ts → config.d.ts} +1 -1
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js.map +1 -0
- package/dist/const.d.ts +3 -9
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +3 -12
- package/dist/const.js.map +1 -1
- package/dist/exports/client.d.ts +3 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +3 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/fetchMessages.d.ts +4 -0
- package/dist/exports/fetchMessages.d.ts.map +1 -0
- package/dist/exports/fetchMessages.js +18 -0
- package/dist/exports/fetchMessages.js.map +1 -0
- package/dist/exports/rsc.d.ts +0 -2
- package/dist/exports/rsc.d.ts.map +1 -1
- package/dist/exports/rsc.js +0 -2
- package/dist/exports/rsc.js.map +1 -1
- package/dist/file-storage-hooks.d.ts +17 -0
- package/dist/file-storage-hooks.d.ts.map +1 -0
- package/dist/file-storage-hooks.js +37 -0
- package/dist/file-storage-hooks.js.map +1 -0
- package/dist/hooks.d.ts +19 -3
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +41 -20
- package/dist/hooks.js.map +1 -1
- package/dist/icu/guards.d.ts.map +1 -0
- package/dist/icu/guards.js.map +1 -0
- package/dist/icu/index.d.ts +6 -0
- package/dist/icu/index.d.ts.map +1 -0
- package/dist/icu/index.js +7 -0
- package/dist/icu/index.js.map +1 -0
- package/dist/{utils/icu-tranform.d.ts → icu/lexical.d.ts} +1 -10
- package/dist/icu/lexical.d.ts.map +1 -0
- package/dist/{utils/icu-tranform.js → icu/lexical.js} +4 -44
- package/dist/icu/lexical.js.map +1 -0
- package/dist/icu/schema.d.ts +4 -0
- package/dist/icu/schema.d.ts.map +1 -0
- package/dist/icu/schema.js +43 -0
- package/dist/icu/schema.js.map +1 -0
- package/dist/icu/serialize.d.ts +11 -0
- package/dist/icu/serialize.d.ts.map +1 -0
- package/dist/icu/serialize.js +45 -0
- package/dist/icu/serialize.js.map +1 -0
- package/dist/icu/validate.d.ts.map +1 -0
- package/dist/icu/validate.js.map +1 -0
- package/dist/index.d.ts +23 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +181 -37
- package/dist/index.js.map +1 -1
- package/dist/payload-types.d.ts +43 -16
- package/dist/payload-types.d.ts.map +1 -1
- package/dist/types.d.ts +24 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/file-storage.d.ts +26 -0
- package/dist/utils/file-storage.d.ts.map +1 -0
- package/dist/utils/file-storage.js +61 -0
- package/dist/utils/file-storage.js.map +1 -0
- package/dist/utils/sanitize.d.ts +5 -3
- package/dist/utils/sanitize.d.ts.map +1 -1
- package/dist/utils/sanitize.js +4 -2
- package/dist/utils/sanitize.js.map +1 -1
- package/dist/utils/schema.d.ts +5 -7
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +11 -39
- package/dist/utils/schema.js.map +1 -1
- package/dist/utils/scopes.d.ts +3 -0
- package/dist/utils/scopes.d.ts.map +1 -0
- package/dist/utils/scopes.js +24 -0
- package/dist/utils/scopes.js.map +1 -0
- package/package.json +5 -5
- package/dist/components/MessageFormField.d.ts +0 -14
- package/dist/components/MessageFormField.d.ts.map +0 -1
- package/dist/components/MessageFormField.js +0 -28
- package/dist/components/MessageFormField.js.map +0 -1
- package/dist/components/MessagesForm.d.ts +0 -13
- package/dist/components/MessagesForm.d.ts.map +0 -1
- package/dist/components/MessagesForm.js +0 -120
- package/dist/components/MessagesForm.js.map +0 -1
- package/dist/components/MessagesForm.module.css +0 -41
- package/dist/components/MessagesFormProvider.d.ts +0 -33
- package/dist/components/MessagesFormProvider.d.ts.map +0 -1
- package/dist/components/MessagesFormProvider.js +0 -34
- package/dist/components/MessagesFormProvider.js.map +0 -1
- package/dist/components/MessagesLink.d.ts +0 -8
- package/dist/components/MessagesLink.d.ts.map +0 -1
- package/dist/components/MessagesLink.js +0 -22
- package/dist/components/MessagesLink.js.map +0 -1
- package/dist/components/MessagesView.d.ts +0 -10
- package/dist/components/MessagesView.d.ts.map +0 -1
- package/dist/components/MessagesView.js +0 -57
- package/dist/components/MessagesView.js.map +0 -1
- package/dist/components/actions/CopyMessages.d.ts +0 -2
- package/dist/components/actions/CopyMessages.d.ts.map +0 -1
- package/dist/components/actions/CopyMessages.js +0 -41
- package/dist/components/actions/CopyMessages.js.map +0 -1
- package/dist/components/actions/CopyMessages.module.css +0 -8
- package/dist/components/actions/JsonImport.d.ts +0 -5
- package/dist/components/actions/JsonImport.d.ts.map +0 -1
- package/dist/components/actions/JsonImport.js +0 -52
- package/dist/components/actions/JsonImport.js.map +0 -1
- package/dist/components/actions/JsonImport.module.css +0 -14
- package/dist/components/hooks/useMessagesFormSubmit.d.ts +0 -11
- package/dist/components/hooks/useMessagesFormSubmit.d.ts.map +0 -1
- package/dist/components/hooks/useMessagesFormSubmit.js +0 -44
- package/dist/components/hooks/useMessagesFormSubmit.js.map +0 -1
- package/dist/components/inputs/FieldWrapper.d.ts +0 -8
- package/dist/components/inputs/FieldWrapper.d.ts.map +0 -1
- package/dist/components/inputs/FieldWrapper.js +0 -24
- package/dist/components/inputs/FieldWrapper.js.map +0 -1
- package/dist/components/inputs/FieldWrapper.module.css +0 -24
- package/dist/components/inputs/LexicalInput.d.ts +0 -9
- package/dist/components/inputs/LexicalInput.d.ts.map +0 -1
- package/dist/components/inputs/LexicalInput.js +0 -26
- package/dist/components/inputs/LexicalInput.js.map +0 -1
- package/dist/components/inputs/MessageInput.d.ts +0 -14
- package/dist/components/inputs/MessageInput.d.ts.map +0 -1
- package/dist/components/inputs/MessageInput.js.map +0 -1
- package/dist/components/inputs/ReferencePopover.d.ts.map +0 -1
- package/dist/components/inputs/ReferencePopover.js.map +0 -1
- package/dist/components/inputs/SingleLinePlugin.d.ts.map +0 -1
- package/dist/components/inputs/SingleLinePlugin.js.map +0 -1
- package/dist/components/inputs/variables/VariableChip.d.ts.map +0 -1
- package/dist/components/inputs/variables/VariableChip.js.map +0 -1
- package/dist/components/inputs/variables/VariableIcon.d.ts.map +0 -1
- package/dist/components/inputs/variables/VariableIcon.js.map +0 -1
- package/dist/components/inputs/variables/VariableNode.d.ts.map +0 -1
- package/dist/components/inputs/variables/VariableNode.js.map +0 -1
- package/dist/components/inputs/variables/VariableSuggestion.d.ts.map +0 -1
- package/dist/components/inputs/variables/VariableSuggestion.js.map +0 -1
- package/dist/components/inputs/variables/editors/PluralVariableEditor.d.ts.map +0 -1
- package/dist/components/inputs/variables/editors/PluralVariableEditor.js.map +0 -1
- package/dist/components/inputs/variables/editors/SelectVariableEditor.d.ts.map +0 -1
- package/dist/components/inputs/variables/editors/SelectVariableEditor.js.map +0 -1
- package/dist/components/inputs/variables/editors/TagVariableEditor.d.ts.map +0 -1
- package/dist/components/inputs/variables/editors/TagVariableEditor.js.map +0 -1
- package/dist/components/inputs/variables/editors/TemporalVariableEditor.d.ts.map +0 -1
- package/dist/components/inputs/variables/editors/TemporalVariableEditor.js.map +0 -1
- package/dist/components/inputs/variables/pickers/NumericVariableEditor.d.ts.map +0 -1
- package/dist/components/inputs/variables/pickers/NumericVariableEditor.js.map +0 -1
- package/dist/components/inputs/variables/pickers/TemporalVariablePicker.d.ts.map +0 -1
- package/dist/components/inputs/variables/pickers/TemporalVariablePicker.js.map +0 -1
- package/dist/components/layout/GroupStatusDot.d.ts +0 -6
- package/dist/components/layout/GroupStatusDot.d.ts.map +0 -1
- package/dist/components/layout/GroupStatusDot.js +0 -24
- package/dist/components/layout/GroupStatusDot.js.map +0 -1
- package/dist/components/layout/StatusDot.d.ts +0 -7
- package/dist/components/layout/StatusDot.d.ts.map +0 -1
- package/dist/components/layout/StatusDot.js +0 -12
- package/dist/components/layout/StatusDot.js.map +0 -1
- package/dist/components/layout/StatusDot.module.css +0 -16
- package/dist/endpoints/set-messages.d.ts +0 -3
- package/dist/endpoints/set-messages.d.ts.map +0 -1
- package/dist/endpoints/set-messages.js +0 -105
- package/dist/endpoints/set-messages.js.map +0 -1
- package/dist/entities.d.ts +0 -5
- package/dist/entities.d.ts.map +0 -1
- package/dist/entities.js +0 -42
- package/dist/entities.js.map +0 -1
- package/dist/requests/fetchMessages.d.ts +0 -3
- package/dist/requests/fetchMessages.d.ts.map +0 -1
- package/dist/requests/fetchMessages.js +0 -40
- package/dist/requests/fetchMessages.js.map +0 -1
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/guards.d.ts.map +0 -1
- package/dist/utils/guards.js.map +0 -1
- package/dist/utils/icu-tranform.d.ts.map +0 -1
- package/dist/utils/icu-tranform.js.map +0 -1
- package/dist/utils/validate.d.ts.map +0 -1
- package/dist/utils/validate.js.map +0 -1
- /package/dist/components/{inputs → input}/ReferencePopover.module.css +0 -0
- /package/dist/components/{inputs → input}/SingleLinePlugin.d.ts +0 -0
- /package/dist/components/{inputs → input}/SingleLinePlugin.js +0 -0
- /package/dist/components/{hooks → input}/useHtmlLexicalAdapter.d.ts +0 -0
- /package/dist/components/{hooks → input}/useHtmlLexicalAdapter.js +0 -0
- /package/dist/components/{inputs → input}/variables/VariableChip.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/VariableChip.module.css +0 -0
- /package/dist/components/{inputs → input}/variables/VariableIcon.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/VariableIcon.js +0 -0
- /package/dist/components/{inputs → input}/variables/VariableNode.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/VariableNode.js +0 -0
- /package/dist/components/{inputs → input}/variables/VariableSuggestion.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/VariableSuggestion.js +0 -0
- /package/dist/components/{inputs → input}/variables/VariableSuggestion.module.css +0 -0
- /package/dist/components/{inputs → input}/variables/editors/PluralVariableEditor.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/editors/PluralVariableEditor.module.css +0 -0
- /package/dist/components/{inputs → input}/variables/editors/SelectVariableEditor.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/editors/SelectVariableEditor.module.css +0 -0
- /package/dist/components/{inputs → input}/variables/editors/TagVariableEditor.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/editors/TagVariableEditor.module.css +0 -0
- /package/dist/components/{inputs → input}/variables/editors/TemporalVariableEditor.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/editors/TemporalVariableEditor.js +0 -0
- /package/dist/components/{inputs → input}/variables/pickers/NumericVariableEditor.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/pickers/NumericVariableEditor.module.css +0 -0
- /package/dist/components/{inputs → input}/variables/pickers/TemporalVariablePicker.d.ts +0 -0
- /package/dist/components/{inputs → input}/variables/pickers/TemporalVariablePicker.module.css +0 -0
- /package/dist/{utils/config.js → config.js} +0 -0
- /package/dist/{utils → icu}/guards.d.ts +0 -0
- /package/dist/{utils → icu}/guards.js +0 -0
- /package/dist/{utils → icu}/validate.d.ts +0 -0
- /package/dist/{utils → icu}/validate.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/layout/MessagesTree.tsx"],"sourcesContent":["import { Collapsible } from '@payloadcms/ui';\nimport
|
|
1
|
+
{"version":3,"sources":["../../../src/components/layout/MessagesTree.tsx"],"sourcesContent":["import { Collapsible } from '@payloadcms/ui';\nimport { memo } from 'react';\nimport type { Control } from 'react-hook-form';\nimport { toWords } from '@/components/input/utils';\nimport type { Messages, MessagesSchema } from '@/types';\nimport { MessageField } from './MessageField';\nimport styles from './MessagesTree.module.css';\n\ninterface MessagesTreeProps {\n path: string;\n nestingLevel?: number;\n schema: MessagesSchema;\n control: Control<Messages>;\n defaultValues?: Messages | undefined;\n hiddenGroups?: string[];\n}\n\nexport const MessagesTree = memo(function MessagesTree({\n path,\n schema,\n nestingLevel = 0,\n control,\n defaultValues,\n hiddenGroups = [],\n}: MessagesTreeProps): React.ReactNode {\n return (\n <div className={styles.root}>\n {Object.entries(schema).map(([key, value]) => {\n if (hiddenGroups.includes(key)) return null;\n const fullPath = path ? [path, key].join('.') : key;\n\n return typeof value === 'string' ? (\n <MessageField\n control={control}\n key={key}\n messageKey={key}\n path={path}\n reference={\n typeof defaultValues?.[key] === 'string'\n ? defaultValues[key]\n : undefined\n }\n schema={value}\n />\n ) : (\n <div\n className={styles.item}\n key={key}\n style={\n {\n '--nesting-level': nestingLevel,\n } as React.CSSProperties\n }\n >\n <Collapsible\n className={styles.collapsible}\n header={<span className={styles.header}>{toWords(key)}</span>}\n >\n <MessagesTree\n control={control}\n defaultValues={\n typeof defaultValues?.[key] === 'object'\n ? defaultValues[key]\n : undefined\n }\n nestingLevel={nestingLevel + 1}\n path={fullPath}\n schema={value}\n />\n </Collapsible>\n </div>\n );\n })}\n </div>\n );\n});\n"],"names":["Collapsible","memo","toWords","MessageField","styles","MessagesTree","path","schema","nestingLevel","control","defaultValues","hiddenGroups","div","className","root","Object","entries","map","key","value","includes","fullPath","join","messageKey","reference","undefined","item","style","collapsible","header","span"],"mappings":";AAAA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,IAAI,QAAQ,QAAQ;AAE7B,SAASC,OAAO,QAAQ,2BAA2B;AAEnD,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,OAAOC,YAAY,4BAA4B;AAW/C,OAAO,MAAMC,6BAAeJ,KAAK,SAASI,aAAa,EACrDC,IAAI,EACJC,MAAM,EACNC,eAAe,CAAC,EAChBC,OAAO,EACPC,aAAa,EACbC,eAAe,EAAE,EACC;IAClB,qBACE,KAACC;QAAIC,WAAWT,OAAOU,IAAI;kBACxBC,OAAOC,OAAO,CAACT,QAAQU,GAAG,CAAC,CAAC,CAACC,KAAKC,MAAM;YACvC,IAAIR,aAAaS,QAAQ,CAACF,MAAM,OAAO;YACvC,MAAMG,WAAWf,OAAO;gBAACA;gBAAMY;aAAI,CAACI,IAAI,CAAC,OAAOJ;YAEhD,OAAO,OAAOC,UAAU,yBACtB,KAAChB;gBACCM,SAASA;gBAETc,YAAYL;gBACZZ,MAAMA;gBACNkB,WACE,OAAOd,eAAe,CAACQ,IAAI,KAAK,WAC5BR,aAAa,CAACQ,IAAI,GAClBO;gBAENlB,QAAQY;eARHD,qBAWP,KAACN;gBACCC,WAAWT,OAAOsB,IAAI;gBAEtBC,OACE;oBACE,mBAAmBnB;gBACrB;0BAGF,cAAA,KAACR;oBACCa,WAAWT,OAAOwB,WAAW;oBAC7BC,sBAAQ,KAACC;wBAAKjB,WAAWT,OAAOyB,MAAM;kCAAG3B,QAAQgB;;8BAEjD,cAAA,KAACb;wBACCI,SAASA;wBACTC,eACE,OAAOA,eAAe,CAACQ,IAAI,KAAK,WAC5BR,aAAa,CAACQ,IAAI,GAClBO;wBAENjB,cAAcA,eAAe;wBAC7BF,MAAMe;wBACNd,QAAQY;;;eApBPD;QAyBX;;AAGN,GAAG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.
|
|
1
|
+
.root {
|
|
2
2
|
display: grid;
|
|
3
3
|
gap: 1rem;
|
|
4
4
|
}
|
|
@@ -21,11 +21,15 @@
|
|
|
21
21
|
.collapsible > :global(.collapsible__toggle-wrap) {
|
|
22
22
|
position: sticky;
|
|
23
23
|
border-bottom: 1px solid var(--theme-border-color);
|
|
24
|
-
top: calc(var(--nesting-level) * 36px
|
|
25
|
-
z-index: calc(
|
|
24
|
+
top: calc(var(--nesting-level) * 36px + 55px);
|
|
25
|
+
z-index: calc(4 - var(--nesting-level));
|
|
26
26
|
padding-block: 0.5rem;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
.collapsible > :global(.collapsible__toggle) {
|
|
30
|
+
position: relative;
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
.collapsible :global(.collapsible__content) {
|
|
30
34
|
padding: 1rem;
|
|
31
35
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAO,MAAM,mBAAmB,iBAChB,MAAM,CAAC,cAAc,CAAC,KACnC,MAAM,EAaR,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["import type { Config } from 'payload';\nimport type { Locale } from './types';\n\nexport const getSupportedLocales = (\n localization: Config['localization'],\n): Locale[] => {\n if (!localization) {\n return [];\n }\n if (localization.locales.length === 0) {\n return [localization.defaultLocale];\n }\n return localization.locales.map((locale) => {\n if (typeof locale === 'string') {\n return locale;\n }\n return locale.code;\n });\n};\n"],"names":["getSupportedLocales","localization","locales","length","defaultLocale","map","locale","code"],"mappings":"AAGA,OAAO,MAAMA,sBAAsB,CACjCC;IAEA,IAAI,CAACA,cAAc;QACjB,OAAO,EAAE;IACX;IACA,IAAIA,aAAaC,OAAO,CAACC,MAAM,KAAK,GAAG;QACrC,OAAO;YAACF,aAAaG,aAAa;SAAC;IACrC;IACA,OAAOH,aAAaC,OAAO,CAACG,GAAG,CAAC,CAACC;QAC/B,IAAI,OAAOA,WAAW,UAAU;YAC9B,OAAOA;QACT;QACA,OAAOA,OAAOC,IAAI;IACpB;AACF,EAAE"}
|
package/dist/const.d.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
+
export declare const VIRTUAL_MESSAGES_FIELD_NAME = "_inlt_scoped_messages";
|
|
1
2
|
export declare const PLUGIN_CONTEXT: {
|
|
2
3
|
set: (config: import("payload").Config, context: {
|
|
3
|
-
|
|
4
|
-
storage: "db" | "upload";
|
|
4
|
+
globalSlug: string;
|
|
5
5
|
}) => void;
|
|
6
6
|
get: (config: {
|
|
7
7
|
custom?: Record<string, unknown>;
|
|
8
8
|
}) => {
|
|
9
|
-
|
|
10
|
-
storage: "db" | "upload";
|
|
9
|
+
globalSlug: string;
|
|
11
10
|
} | null;
|
|
12
11
|
};
|
|
13
|
-
export declare const ENDPOINTS: {
|
|
14
|
-
setMessages: import("@davincicoding/payload-plugin-kit").Procedure<void, {
|
|
15
|
-
success: boolean;
|
|
16
|
-
}>;
|
|
17
|
-
};
|
|
18
12
|
//# sourceMappingURL=const.d.ts.map
|
package/dist/const.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AAEnE,eAAO,MAAM,cAAc;;;;;cAMoY,CAAC;;;;CAD/Z,CAAC"}
|
package/dist/const.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import { createPluginContext
|
|
1
|
+
import { createPluginContext } from '@davincicoding/payload-plugin-kit';
|
|
2
2
|
import { z } from 'zod/v4-mini';
|
|
3
|
+
export const VIRTUAL_MESSAGES_FIELD_NAME = '_inlt_scoped_messages';
|
|
3
4
|
export const PLUGIN_CONTEXT = createPluginContext('payload-intl', z.object({
|
|
4
|
-
|
|
5
|
-
storage: z.enum([
|
|
6
|
-
'db',
|
|
7
|
-
'upload'
|
|
8
|
-
])
|
|
5
|
+
globalSlug: z.string()
|
|
9
6
|
}));
|
|
10
|
-
export const ENDPOINTS = {
|
|
11
|
-
setMessages: defineProcedure({
|
|
12
|
-
path: '/intl-plugin',
|
|
13
|
-
method: 'put'
|
|
14
|
-
}).returns()
|
|
15
|
-
};
|
|
16
7
|
|
|
17
8
|
//# sourceMappingURL=const.js.map
|
package/dist/const.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/const.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/const.ts"],"sourcesContent":["import { createPluginContext } from '@davincicoding/payload-plugin-kit';\nimport { z } from 'zod/v4-mini';\n\nexport const VIRTUAL_MESSAGES_FIELD_NAME = '_inlt_scoped_messages';\n\nexport const PLUGIN_CONTEXT = createPluginContext(\n 'payload-intl',\n z.object({\n globalSlug: z.string(),\n }),\n);\n"],"names":["createPluginContext","z","VIRTUAL_MESSAGES_FIELD_NAME","PLUGIN_CONTEXT","object","globalSlug","string"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,oCAAoC;AACxE,SAASC,CAAC,QAAQ,cAAc;AAEhC,OAAO,MAAMC,8BAA8B,wBAAwB;AAEnE,OAAO,MAAMC,iBAAiBH,oBAC5B,gBACAC,EAAEG,MAAM,CAAC;IACPC,YAAYJ,EAAEK,MAAM;AACtB,IACA"}
|
package/dist/exports/client.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { DefaultEditView as MessagesRootView } from '@payloadcms/ui';
|
|
2
|
+
export { MessagesField, type MessagesFieldProps, } from '../components/MessagesField';
|
|
3
|
+
export { MessagesImport } from '../components/MessagesImport';
|
|
2
4
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/exports/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export {};\n"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { DefaultEditView as MessagesRootView } from '@payloadcms/ui';\nexport {\n MessagesField,\n type MessagesFieldProps,\n} from '../components/MessagesField';\nexport { MessagesImport } from '../components/MessagesImport';\n"],"names":["DefaultEditView","MessagesRootView","MessagesField","MessagesImport"],"mappings":"AAAA,SAASA,mBAAmBC,gBAAgB,QAAQ,iBAAiB;AACrE,SACEC,aAAa,QAER,8BAA8B;AACrC,SAASC,cAAc,QAAQ,+BAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchMessages.d.ts","sourceRoot":"","sources":["../../src/exports/fetchMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,wBAAsB,aAAa,CACjC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,CAAC,CAgBzB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PLUGIN_CONTEXT } from '../const';
|
|
2
|
+
export async function fetchMessages(payload, locale) {
|
|
3
|
+
const ctx = PLUGIN_CONTEXT.get(payload.config);
|
|
4
|
+
if (!ctx) {
|
|
5
|
+
throw new Error('[payload-intl] Plugin context not found. Is the plugin registered?');
|
|
6
|
+
}
|
|
7
|
+
const { data: messages } = await payload.findGlobal({
|
|
8
|
+
slug: ctx.globalSlug,
|
|
9
|
+
// @ts-expect-error FIXME
|
|
10
|
+
locale,
|
|
11
|
+
select: {
|
|
12
|
+
data: true
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return messages;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=fetchMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/fetchMessages.ts"],"sourcesContent":["import type { BasePayload } from 'payload';\nimport { PLUGIN_CONTEXT } from '@/const';\nimport type { MessagesSchema } from '@/types';\n\nexport async function fetchMessages(\n payload: BasePayload,\n locale: string,\n): Promise<MessagesSchema> {\n const ctx = PLUGIN_CONTEXT.get(payload.config);\n if (!ctx) {\n throw new Error(\n '[payload-intl] Plugin context not found. Is the plugin registered?',\n );\n }\n\n const { data: messages } = await payload.findGlobal({\n slug: ctx.globalSlug as 'messages',\n // @ts-expect-error FIXME\n locale,\n select: { data: true },\n });\n\n return messages;\n}\n"],"names":["PLUGIN_CONTEXT","fetchMessages","payload","locale","ctx","get","config","Error","data","messages","findGlobal","slug","globalSlug","select"],"mappings":"AACA,SAASA,cAAc,QAAQ,UAAU;AAGzC,OAAO,eAAeC,cACpBC,OAAoB,EACpBC,MAAc;IAEd,MAAMC,MAAMJ,eAAeK,GAAG,CAACH,QAAQI,MAAM;IAC7C,IAAI,CAACF,KAAK;QACR,MAAM,IAAIG,MACR;IAEJ;IAEA,MAAM,EAAEC,MAAMC,QAAQ,EAAE,GAAG,MAAMP,QAAQQ,UAAU,CAAC;QAClDC,MAAMP,IAAIQ,UAAU;QACpB,yBAAyB;QACzBT;QACAU,QAAQ;YAAEL,MAAM;QAAK;IACvB;IAEA,OAAOC;AACT"}
|
package/dist/exports/rsc.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../src/exports/rsc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../src/exports/rsc.ts"],"names":[],"mappings":""}
|
package/dist/exports/rsc.js
CHANGED
package/dist/exports/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/rsc.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GlobalAfterReadHook, GlobalBeforeChangeHook } from 'payload';
|
|
2
|
+
interface FileHookOptions {
|
|
3
|
+
readonly uploadCollection: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `GlobalAfterReadHook` that reads the upload file
|
|
7
|
+
* referenced by `doc.file` and populates the virtual `data` field.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createPopulateDataFromFileHook: ({ uploadCollection }: FileHookOptions) => GlobalAfterReadHook;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a `GlobalBeforeChangeHook` that serializes the incoming
|
|
12
|
+
* `data` field to a JSON file in the upload collection and stores
|
|
13
|
+
* the resulting file ID on `data.file`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const createPersistDataToFileHook: ({ uploadCollection }: FileHookOptions) => GlobalBeforeChangeHook;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=file-storage-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-storage-hooks.d.ts","sourceRoot":"","sources":["../src/file-storage-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAI3E,UAAU,eAAe;IACvB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AAED;;;GAGG;AACH,eAAO,MAAM,8BAA8B,yBAClB,eAAe,KAAG,mBAUxC,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,yBACf,eAAe,KAAG,sBAexC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { persistDataToFile, readDataFromFile } from './utils/file-storage';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a `GlobalAfterReadHook` that reads the upload file
|
|
4
|
+
* referenced by `doc.file` and populates the virtual `data` field.
|
|
5
|
+
*/ export const createPopulateDataFromFileHook = ({ uploadCollection })=>async ({ doc, req: { payload } })=>{
|
|
6
|
+
console.log(doc);
|
|
7
|
+
const data = await readDataFromFile({
|
|
8
|
+
payload,
|
|
9
|
+
collection: uploadCollection,
|
|
10
|
+
fileId: doc.file
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
...doc,
|
|
14
|
+
data
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Creates a `GlobalBeforeChangeHook` that serializes the incoming
|
|
19
|
+
* `data` field to a JSON file in the upload collection and stores
|
|
20
|
+
* the resulting file ID on `data.file`.
|
|
21
|
+
*/ export const createPersistDataToFileHook = ({ uploadCollection })=>async ({ data, originalDoc, req: { payload, locale } })=>{
|
|
22
|
+
if (!data.data) return data;
|
|
23
|
+
const existingFileId = originalDoc?.file ?? data.file;
|
|
24
|
+
const fileId = await persistDataToFile({
|
|
25
|
+
payload,
|
|
26
|
+
collection: uploadCollection,
|
|
27
|
+
data: data.data,
|
|
28
|
+
locale: locale ?? 'en',
|
|
29
|
+
existingFileId: existingFileId ?? undefined
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
...data,
|
|
33
|
+
file: fileId
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=file-storage-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/file-storage-hooks.ts"],"sourcesContent":["import type { GlobalAfterReadHook, GlobalBeforeChangeHook } from 'payload';\n\nimport { persistDataToFile, readDataFromFile } from './utils/file-storage';\n\ninterface FileHookOptions {\n readonly uploadCollection: string;\n}\n\n/**\n * Creates a `GlobalAfterReadHook` that reads the upload file\n * referenced by `doc.file` and populates the virtual `data` field.\n */\nexport const createPopulateDataFromFileHook =\n ({ uploadCollection }: FileHookOptions): GlobalAfterReadHook =>\n async ({ doc, req: { payload } }) => {\n console.log(doc);\n const data = await readDataFromFile({\n payload,\n collection: uploadCollection,\n fileId: doc.file,\n });\n\n return { ...doc, data };\n };\n\n/**\n * Creates a `GlobalBeforeChangeHook` that serializes the incoming\n * `data` field to a JSON file in the upload collection and stores\n * the resulting file ID on `data.file`.\n */\nexport const createPersistDataToFileHook =\n ({ uploadCollection }: FileHookOptions): GlobalBeforeChangeHook =>\n async ({ data, originalDoc, req: { payload, locale } }) => {\n if (!data.data) return data;\n\n const existingFileId = originalDoc?.file ?? data.file;\n\n const fileId = await persistDataToFile({\n payload,\n collection: uploadCollection,\n data: data.data,\n locale: locale ?? 'en',\n existingFileId: existingFileId ?? undefined,\n });\n\n return { ...data, file: fileId };\n };\n"],"names":["persistDataToFile","readDataFromFile","createPopulateDataFromFileHook","uploadCollection","doc","req","payload","console","log","data","collection","fileId","file","createPersistDataToFileHook","originalDoc","locale","existingFileId","undefined"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,gBAAgB,QAAQ,uBAAuB;AAM3E;;;CAGC,GACD,OAAO,MAAMC,iCACX,CAAC,EAAEC,gBAAgB,EAAmB,GACtC,OAAO,EAAEC,GAAG,EAAEC,KAAK,EAAEC,OAAO,EAAE,EAAE;QAC9BC,QAAQC,GAAG,CAACJ;QACZ,MAAMK,OAAO,MAAMR,iBAAiB;YAClCK;YACAI,YAAYP;YACZQ,QAAQP,IAAIQ,IAAI;QAClB;QAEA,OAAO;YAAE,GAAGR,GAAG;YAAEK;QAAK;IACxB,EAAE;AAEJ;;;;CAIC,GACD,OAAO,MAAMI,8BACX,CAAC,EAAEV,gBAAgB,EAAmB,GACtC,OAAO,EAAEM,IAAI,EAAEK,WAAW,EAAET,KAAK,EAAEC,OAAO,EAAES,MAAM,EAAE,EAAE;QACpD,IAAI,CAACN,KAAKA,IAAI,EAAE,OAAOA;QAEvB,MAAMO,iBAAiBF,aAAaF,QAAQH,KAAKG,IAAI;QAErD,MAAMD,SAAS,MAAMX,kBAAkB;YACrCM;YACAI,YAAYP;YACZM,MAAMA,KAAKA,IAAI;YACfM,QAAQA,UAAU;YAClBC,gBAAgBA,kBAAkBC;QACpC;QAEA,OAAO;YAAE,GAAGR,IAAI;YAAEG,MAAMD;QAAO;IACjC,EAAE"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { FieldHook } from 'payload';
|
|
2
|
+
import type { Messages } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Populates the virtual `_intlMessages` field with scoped
|
|
5
|
+
* translations from the messages collection after read.
|
|
6
|
+
*/
|
|
7
|
+
export declare const createPopulateScopedMessagesHook: ({ globalSlug, scope, }: {
|
|
8
|
+
globalSlug: "messages";
|
|
9
|
+
scope: string;
|
|
10
|
+
}) => FieldHook<any, Messages>;
|
|
11
|
+
/**
|
|
12
|
+
* Extracts `_intlMessages` from the incoming data,
|
|
13
|
+
* merges each locale's scoped key back into the messages
|
|
14
|
+
* collection, and strips the virtual field before persistence.
|
|
15
|
+
*/
|
|
16
|
+
export declare const createExtractScopedMessagesHook: ({ globalSlug, scope, }: {
|
|
17
|
+
globalSlug: "messages";
|
|
18
|
+
scope: string;
|
|
19
|
+
}) => FieldHook<any, Messages>;
|
|
4
20
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,gCAAgC,2BAIxC;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf,KAAG,SAAS,CAAC,GAAG,EAAE,QAAQ,CAU1B,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,2BAIvC;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf,KAAG,SAAS,CAAC,GAAG,EAAE,QAAQ,CAwB1B,CAAC"}
|
package/dist/hooks.js
CHANGED
|
@@ -1,24 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
/**
|
|
3
|
+
* Populates the virtual `_intlMessages` field with scoped
|
|
4
|
+
* translations from the messages collection after read.
|
|
5
|
+
*/ export const createPopulateScopedMessagesHook = ({ globalSlug, scope })=>async ({ req: { locale, payload } })=>{
|
|
6
|
+
if (!locale) return {};
|
|
7
|
+
const { data: messages = {} } = await payload.findGlobal({
|
|
8
|
+
slug: globalSlug,
|
|
9
|
+
locale,
|
|
10
|
+
select: {
|
|
11
|
+
data: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return messages[scope];
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Extracts `_intlMessages` from the incoming data,
|
|
18
|
+
* merges each locale's scoped key back into the messages
|
|
19
|
+
* collection, and strips the virtual field before persistence.
|
|
20
|
+
*/ export const createExtractScopedMessagesHook = ({ globalSlug, scope })=>async ({ value, previousValue, req: { payload, locale } })=>{
|
|
21
|
+
if (!value) return {};
|
|
22
|
+
// TODO check if this can be derived from the FieldHook args instead
|
|
23
|
+
if (isEqual(value, previousValue)) return value;
|
|
24
|
+
const { data: allMessages = {} } = await payload.findGlobal({
|
|
25
|
+
slug: globalSlug,
|
|
26
|
+
locale,
|
|
27
|
+
select: {
|
|
28
|
+
data: true
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const updatedMessages = {
|
|
32
|
+
...allMessages,
|
|
33
|
+
[scope]: value
|
|
34
|
+
};
|
|
35
|
+
await payload.updateGlobal({
|
|
36
|
+
slug: globalSlug,
|
|
37
|
+
locale,
|
|
38
|
+
data: {
|
|
39
|
+
data: updatedMessages
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return value;
|
|
21
43
|
};
|
|
22
|
-
};
|
|
23
44
|
|
|
24
45
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/hooks.ts"],"sourcesContent":["import { isEqual } from 'lodash-es';\nimport type { FieldHook } from 'payload';\nimport type { Messages } from './types';\n\n/**\n * Populates the virtual `_intlMessages` field with scoped\n * translations from the messages collection after read.\n */\nexport const createPopulateScopedMessagesHook =\n ({\n globalSlug,\n scope,\n }: {\n globalSlug: 'messages';\n scope: string;\n }): FieldHook<any, Messages> =>\n async ({ req: { locale, payload } }) => {\n if (!locale) return {};\n const { data: messages = {} } = await payload.findGlobal({\n slug: globalSlug,\n locale,\n select: { data: true },\n });\n\n return messages[scope] as Messages;\n };\n\n/**\n * Extracts `_intlMessages` from the incoming data,\n * merges each locale's scoped key back into the messages\n * collection, and strips the virtual field before persistence.\n */\nexport const createExtractScopedMessagesHook =\n ({\n globalSlug,\n scope,\n }: {\n globalSlug: 'messages';\n scope: string;\n }): FieldHook<any, Messages> =>\n async ({ value, previousValue, req: { payload, locale } }) => {\n if (!value) return {};\n // TODO check if this can be derived from the FieldHook args instead\n if (isEqual(value, previousValue)) return value;\n\n const { data: allMessages = {} } = await payload.findGlobal({\n slug: globalSlug as 'messages',\n locale,\n select: { data: true },\n });\n\n const updatedMessages = {\n ...allMessages,\n [scope]: value,\n };\n\n await payload.updateGlobal({\n slug: globalSlug as 'messages',\n locale,\n data: { data: updatedMessages },\n });\n\n return value;\n };\n"],"names":["isEqual","createPopulateScopedMessagesHook","globalSlug","scope","req","locale","payload","data","messages","findGlobal","slug","select","createExtractScopedMessagesHook","value","previousValue","allMessages","updatedMessages","updateGlobal"],"mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AAIpC;;;CAGC,GACD,OAAO,MAAMC,mCACX,CAAC,EACCC,UAAU,EACVC,KAAK,EAIN,GACD,OAAO,EAAEC,KAAK,EAAEC,MAAM,EAAEC,OAAO,EAAE,EAAE;QACjC,IAAI,CAACD,QAAQ,OAAO,CAAC;QACrB,MAAM,EAAEE,MAAMC,WAAW,CAAC,CAAC,EAAE,GAAG,MAAMF,QAAQG,UAAU,CAAC;YACvDC,MAAMR;YACNG;YACAM,QAAQ;gBAAEJ,MAAM;YAAK;QACvB;QAEA,OAAOC,QAAQ,CAACL,MAAM;IACxB,EAAE;AAEJ;;;;CAIC,GACD,OAAO,MAAMS,kCACX,CAAC,EACCV,UAAU,EACVC,KAAK,EAIN,GACD,OAAO,EAAEU,KAAK,EAAEC,aAAa,EAAEV,KAAK,EAAEE,OAAO,EAAED,MAAM,EAAE,EAAE;QACvD,IAAI,CAACQ,OAAO,OAAO,CAAC;QACpB,oEAAoE;QACpE,IAAIb,QAAQa,OAAOC,gBAAgB,OAAOD;QAE1C,MAAM,EAAEN,MAAMQ,cAAc,CAAC,CAAC,EAAE,GAAG,MAAMT,QAAQG,UAAU,CAAC;YAC1DC,MAAMR;YACNG;YACAM,QAAQ;gBAAEJ,MAAM;YAAK;QACvB;QAEA,MAAMS,kBAAkB;YACtB,GAAGD,WAAW;YACd,CAACZ,MAAM,EAAEU;QACX;QAEA,MAAMP,QAAQW,YAAY,CAAC;YACzBP,MAAMR;YACNG;YACAE,MAAM;gBAAEA,MAAMS;YAAgB;QAChC;QAEA,OAAOH;IACT,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/icu/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,WAAW,EACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,YAAY,EACZ,aAAa,EACd,MAAM,oCAAoC,CAAC;AAE5C,eAAO,MAAM,gBAAgB,YAClB,oBAAoB,KAC5B,OAAO,IAAI,aAAa,GAAG,aACwB,CAAC;AAEvD,eAAO,MAAM,iBAAiB,YACnB,oBAAoB,KAC5B,OAAO,IAAI,WAAW,GAAG,WACsB,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,eAAe,EACf,aAAa,EACb,aAAa,EACb,YAAY,GACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/icu/guards.ts"],"sourcesContent":["import type {\n DateElement,\n MessageFormatElement,\n NumberElement,\n PluralElement,\n TimeElement,\n} from '@formatjs/icu-messageformat-parser';\nimport {\n isArgumentElement,\n isDateElement,\n isLiteralElement,\n isNumberElement,\n isPluralElement,\n isSelectElement,\n isTagElement,\n isTimeElement,\n} from '@formatjs/icu-messageformat-parser';\n\nexport const isNumericElement = (\n element: MessageFormatElement,\n): element is NumberElement | PluralElement =>\n isNumberElement(element) || isPluralElement(element);\n\nexport const isTemporalElement = (\n element: MessageFormatElement,\n): element is DateElement | TimeElement =>\n isDateElement(element) || isTimeElement(element);\n\nexport {\n isLiteralElement,\n isArgumentElement,\n isNumberElement,\n isSelectElement,\n isPluralElement,\n isDateElement,\n isTimeElement,\n isTagElement,\n};\n"],"names":["isArgumentElement","isDateElement","isLiteralElement","isNumberElement","isPluralElement","isSelectElement","isTagElement","isTimeElement","isNumericElement","element","isTemporalElement"],"mappings":"AAOA,SACEA,iBAAiB,EACjBC,aAAa,EACbC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,aAAa,QACR,qCAAqC;AAE5C,OAAO,MAAMC,mBAAmB,CAC9BC,UAEAN,gBAAgBM,YAAYL,gBAAgBK,SAAS;AAEvD,OAAO,MAAMC,oBAAoB,CAC/BD,UAEAR,cAAcQ,YAAYF,cAAcE,SAAS;AAEnD,SACEP,gBAAgB,EAChBF,iBAAiB,EACjBG,eAAe,EACfE,eAAe,EACfD,eAAe,EACfH,aAAa,EACbM,aAAa,EACbD,YAAY,GACZ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isNumericElement, isPluralElement, isSelectElement, isTagElement, isTemporalElement, isTimeElement, } from './guards';
|
|
2
|
+
export { parseIcuToLexicalState } from './lexical';
|
|
3
|
+
export { extractTemplateVariables, parseMessageSchema } from './schema';
|
|
4
|
+
export { parseICUMessage, serializeICUMessage } from './serialize';
|
|
5
|
+
export { createValidator, type MessageValidator, validateMessage, } from './validate';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/icu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EACL,eAAe,EACf,KAAK,gBAAgB,EACrB,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isNumericElement, isPluralElement, isSelectElement, isTagElement, isTemporalElement, isTimeElement } from './guards';
|
|
2
|
+
export { parseIcuToLexicalState } from './lexical';
|
|
3
|
+
export { extractTemplateVariables, parseMessageSchema } from './schema';
|
|
4
|
+
export { parseICUMessage, serializeICUMessage } from './serialize';
|
|
5
|
+
export { createValidator, validateMessage } from './validate';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/icu/index.ts"],"sourcesContent":["export {\n isArgumentElement,\n isDateElement,\n isLiteralElement,\n isNumberElement,\n isNumericElement,\n isPluralElement,\n isSelectElement,\n isTagElement,\n isTemporalElement,\n isTimeElement,\n} from './guards';\nexport { parseIcuToLexicalState } from './lexical';\nexport { extractTemplateVariables, parseMessageSchema } from './schema';\nexport { parseICUMessage, serializeICUMessage } from './serialize';\nexport {\n createValidator,\n type MessageValidator,\n validateMessage,\n} from './validate';\n"],"names":["isArgumentElement","isDateElement","isLiteralElement","isNumberElement","isNumericElement","isPluralElement","isSelectElement","isTagElement","isTemporalElement","isTimeElement","parseIcuToLexicalState","extractTemplateVariables","parseMessageSchema","parseICUMessage","serializeICUMessage","createValidator","validateMessage"],"mappings":"AAAA,SACEA,iBAAiB,EACjBC,aAAa,EACbC,gBAAgB,EAChBC,eAAe,EACfC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,iBAAiB,EACjBC,aAAa,QACR,WAAW;AAClB,SAASC,sBAAsB,QAAQ,YAAY;AACnD,SAASC,wBAAwB,EAAEC,kBAAkB,QAAQ,WAAW;AACxE,SAASC,eAAe,EAAEC,mBAAmB,QAAQ,cAAc;AACnE,SACEC,eAAe,EAEfC,eAAe,QACV,aAAa"}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import type { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
|
2
1
|
import type { SerializedParagraphNode } from '@payloadcms/richtext-lexical/lexical';
|
|
3
|
-
/**
|
|
4
|
-
* Parse an ICU message string into a AST array
|
|
5
|
-
*/
|
|
6
|
-
export declare const parseICUMessage: (message: string) => MessageFormatElement[];
|
|
7
|
-
/**
|
|
8
|
-
* Serialize an ICU message AST array into a ICU message string
|
|
9
|
-
*/
|
|
10
|
-
export declare const serializeICUMessage: (elements: MessageFormatElement[]) => string;
|
|
11
2
|
type SerializedICUEditorState = {
|
|
12
3
|
root: {
|
|
13
4
|
type: 'root';
|
|
@@ -23,4 +14,4 @@ type SerializedICUEditorState = {
|
|
|
23
14
|
*/
|
|
24
15
|
export declare const parseIcuToLexicalState: (icuMessage: string) => SerializedICUEditorState;
|
|
25
16
|
export {};
|
|
26
|
-
//# sourceMappingURL=
|
|
17
|
+
//# sourceMappingURL=lexical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexical.d.ts","sourceRoot":"","sources":["../../src/icu/lexical.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,uBAAuB,EAExB,MAAM,sCAAsC,CAAC;AA+B9C,KAAK,wBAAwB,GAAG;IAC9B,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,CAAC,CAAC;QACX,SAAS,EAAE,IAAI,CAAC;QAChB,MAAM,EAAE,EAAE,CAAC;QACX,MAAM,EAAE,CAAC,CAAC;QACV,QAAQ,EAAE,CAAC,uBAAuB,CAAC,CAAC;KACrC,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,eACrB,MAAM,KACjB,wBAwEF,CAAC"}
|
|
@@ -1,47 +1,7 @@
|
|
|
1
1
|
import { uncaughtSwitchCase } from '@davincicoding/payload-plugin-kit';
|
|
2
|
-
import {
|
|
3
|
-
import { formatVariableLabel } from '
|
|
4
|
-
|
|
5
|
-
* Parse an ICU message string into a AST array
|
|
6
|
-
*/ export const parseICUMessage = (message)=>parse(message);
|
|
7
|
-
/**
|
|
8
|
-
* Serialize an ICU message AST array into a ICU message string
|
|
9
|
-
*/ export const serializeICUMessage = (elements)=>elements.map((element)=>{
|
|
10
|
-
switch(element.type){
|
|
11
|
-
case TYPE.literal:
|
|
12
|
-
return element.value;
|
|
13
|
-
case TYPE.argument:
|
|
14
|
-
return stringifyElement(element.value);
|
|
15
|
-
case TYPE.number:
|
|
16
|
-
// TODO serialize element.style
|
|
17
|
-
return stringifyElement(element.value, 'number');
|
|
18
|
-
case TYPE.select:
|
|
19
|
-
return stringifyElement(element.value, 'select', Object.entries(element.options).map(([key, option])=>`${key} {${option.value.length > 0 ? serializeICUMessage(option.value) : key}}`));
|
|
20
|
-
case TYPE.plural:
|
|
21
|
-
return stringifyElement(element.value, 'plural', [
|
|
22
|
-
element.offset < 0 && `offset:${element.offset}`,
|
|
23
|
-
...Object.entries(element.options).map(([key, option])=>`${key} {${option.value.length > 0 ? serializeICUMessage(option.value) : key}}`)
|
|
24
|
-
]);
|
|
25
|
-
case TYPE.tag:
|
|
26
|
-
return `<${element.value}>${serializeICUMessage(element.children)}</${element.value}>`;
|
|
27
|
-
case TYPE.date:
|
|
28
|
-
// TODO serialize element.style
|
|
29
|
-
return stringifyElement(element.value, 'date');
|
|
30
|
-
case TYPE.time:
|
|
31
|
-
// TODO serialize element.style
|
|
32
|
-
return stringifyElement(element.value, 'time');
|
|
33
|
-
case TYPE.pound:
|
|
34
|
-
return '#';
|
|
35
|
-
default:
|
|
36
|
-
return uncaughtSwitchCase(element);
|
|
37
|
-
}
|
|
38
|
-
}).join('');
|
|
39
|
-
const stringifyElement = (name, type, options = [])=>{
|
|
40
|
-
if (type === undefined) return `{${name}}`;
|
|
41
|
-
const filteredOptions = options.filter((option)=>typeof option === 'string' && option.length > 0);
|
|
42
|
-
if (filteredOptions.length === 0) return `{${name}, ${type}}`;
|
|
43
|
-
return `{${name}, ${type}, ${filteredOptions.join(' ')}}`;
|
|
44
|
-
};
|
|
2
|
+
import { TYPE } from '@formatjs/icu-messageformat-parser';
|
|
3
|
+
import { formatVariableLabel } from '../components/input/utils';
|
|
4
|
+
import { parseICUMessage, serializeICUMessage } from './serialize';
|
|
45
5
|
function serializeTextNode(text) {
|
|
46
6
|
return {
|
|
47
7
|
type: 'text',
|
|
@@ -144,4 +104,4 @@ function serializeMentionNode(name, label, icu) {
|
|
|
144
104
|
}
|
|
145
105
|
};
|
|
146
106
|
|
|
147
|
-
//# sourceMappingURL=
|
|
107
|
+
//# sourceMappingURL=lexical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/icu/lexical.ts"],"sourcesContent":["import { uncaughtSwitchCase } from '@davincicoding/payload-plugin-kit';\nimport { TYPE } from '@formatjs/icu-messageformat-parser';\nimport type {\n SerializedLexicalNode,\n SerializedParagraphNode,\n SerializedTextNode,\n} from '@payloadcms/richtext-lexical/lexical';\nimport type { SerializedBeautifulMentionNode } from 'lexical-beautiful-mentions';\nimport { formatVariableLabel } from '../components/input/utils';\nimport { parseICUMessage, serializeICUMessage } from './serialize';\n\nfunction serializeTextNode(text: string): SerializedTextNode {\n return {\n type: 'text',\n version: 1,\n text,\n detail: 0,\n format: 0,\n mode: 'normal',\n style: '',\n };\n}\n\nfunction serializeMentionNode(\n name: string,\n label: string,\n icu: string,\n): SerializedBeautifulMentionNode {\n return {\n type: 'variableMention',\n version: 1,\n trigger: '@',\n value: name,\n data: { label, icu },\n };\n}\n\ntype SerializedICUEditorState = {\n root: {\n type: 'root';\n version: 1;\n direction: null;\n format: '';\n indent: 0;\n children: [SerializedParagraphNode];\n };\n};\n\n/**\n * Parse an ICU message string into a Lexical serialized editor state\n */\nexport const parseIcuToLexicalState = (\n icuMessage: string,\n): SerializedICUEditorState => {\n try {\n const elements = parseICUMessage(icuMessage);\n const children = elements.flatMap<SerializedLexicalNode>((element) => {\n switch (element.type) {\n case TYPE.literal:\n return [serializeTextNode(element.value)];\n case TYPE.pound:\n return [serializeTextNode('#')];\n case TYPE.argument:\n case TYPE.number:\n case TYPE.date:\n case TYPE.time:\n case TYPE.select:\n case TYPE.plural:\n case TYPE.tag:\n return [\n serializeMentionNode(\n element.value,\n formatVariableLabel(element),\n serializeICUMessage([element]),\n ),\n ];\n default:\n return uncaughtSwitchCase(element);\n }\n });\n\n return {\n root: {\n type: 'root',\n version: 1,\n direction: null,\n format: '',\n indent: 0,\n children: [\n {\n type: 'paragraph',\n version: 1,\n direction: null,\n format: '',\n indent: 0,\n textFormat: 0,\n textStyle: '',\n children,\n },\n ],\n },\n };\n } catch {\n return {\n root: {\n type: 'root',\n version: 1,\n direction: null,\n format: '',\n indent: 0,\n children: [\n {\n type: 'paragraph',\n version: 1,\n direction: null,\n format: '',\n indent: 0,\n textFormat: 0,\n textStyle: '',\n children: [serializeTextNode(icuMessage)],\n },\n ],\n },\n };\n }\n};\n"],"names":["uncaughtSwitchCase","TYPE","formatVariableLabel","parseICUMessage","serializeICUMessage","serializeTextNode","text","type","version","detail","format","mode","style","serializeMentionNode","name","label","icu","trigger","value","data","parseIcuToLexicalState","icuMessage","elements","children","flatMap","element","literal","pound","argument","number","date","time","select","plural","tag","root","direction","indent","textFormat","textStyle"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,oCAAoC;AACvE,SAASC,IAAI,QAAQ,qCAAqC;AAO1D,SAASC,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,eAAe,EAAEC,mBAAmB,QAAQ,cAAc;AAEnE,SAASC,kBAAkBC,IAAY;IACrC,OAAO;QACLC,MAAM;QACNC,SAAS;QACTF;QACAG,QAAQ;QACRC,QAAQ;QACRC,MAAM;QACNC,OAAO;IACT;AACF;AAEA,SAASC,qBACPC,IAAY,EACZC,KAAa,EACbC,GAAW;IAEX,OAAO;QACLT,MAAM;QACNC,SAAS;QACTS,SAAS;QACTC,OAAOJ;QACPK,MAAM;YAAEJ;YAAOC;QAAI;IACrB;AACF;AAaA;;CAEC,GACD,OAAO,MAAMI,yBAAyB,CACpCC;IAEA,IAAI;QACF,MAAMC,WAAWnB,gBAAgBkB;QACjC,MAAME,WAAWD,SAASE,OAAO,CAAwB,CAACC;YACxD,OAAQA,QAAQlB,IAAI;gBAClB,KAAKN,KAAKyB,OAAO;oBACf,OAAO;wBAACrB,kBAAkBoB,QAAQP,KAAK;qBAAE;gBAC3C,KAAKjB,KAAK0B,KAAK;oBACb,OAAO;wBAACtB,kBAAkB;qBAAK;gBACjC,KAAKJ,KAAK2B,QAAQ;gBAClB,KAAK3B,KAAK4B,MAAM;gBAChB,KAAK5B,KAAK6B,IAAI;gBACd,KAAK7B,KAAK8B,IAAI;gBACd,KAAK9B,KAAK+B,MAAM;gBAChB,KAAK/B,KAAKgC,MAAM;gBAChB,KAAKhC,KAAKiC,GAAG;oBACX,OAAO;wBACLrB,qBACEY,QAAQP,KAAK,EACbhB,oBAAoBuB,UACpBrB,oBAAoB;4BAACqB;yBAAQ;qBAEhC;gBACH;oBACE,OAAOzB,mBAAmByB;YAC9B;QACF;QAEA,OAAO;YACLU,MAAM;gBACJ5B,MAAM;gBACNC,SAAS;gBACT4B,WAAW;gBACX1B,QAAQ;gBACR2B,QAAQ;gBACRd,UAAU;oBACR;wBACEhB,MAAM;wBACNC,SAAS;wBACT4B,WAAW;wBACX1B,QAAQ;wBACR2B,QAAQ;wBACRC,YAAY;wBACZC,WAAW;wBACXhB;oBACF;iBACD;YACH;QACF;IACF,EAAE,OAAM;QACN,OAAO;YACLY,MAAM;gBACJ5B,MAAM;gBACNC,SAAS;gBACT4B,WAAW;gBACX1B,QAAQ;gBACR2B,QAAQ;gBACRd,UAAU;oBACR;wBACEhB,MAAM;wBACNC,SAAS;wBACT4B,WAAW;wBACX1B,QAAQ;wBACR2B,QAAQ;wBACRC,YAAY;wBACZC,WAAW;wBACXhB,UAAU;4BAAClB,kBAAkBgB;yBAAY;oBAC3C;iBACD;YACH;QACF;IACF;AACF,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/icu/schema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,wBAAwB,WAAY,MAAM,KAAG,gBAAgB,EACjC,CAAC;AA8B1C,eAAO,MAAM,kBAAkB,WAAY,MAAM,KAAG,aAUnD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { parse, TYPE } from '@formatjs/icu-messageformat-parser';
|
|
2
|
+
export const extractTemplateVariables = (schema)=>collectTemplateVariables(parse(schema));
|
|
3
|
+
const collectTemplateVariables = (parts)=>parts.flatMap((part)=>{
|
|
4
|
+
switch(part.type){
|
|
5
|
+
case TYPE.literal:
|
|
6
|
+
case TYPE.pound:
|
|
7
|
+
return [];
|
|
8
|
+
case TYPE.argument:
|
|
9
|
+
case TYPE.number:
|
|
10
|
+
case TYPE.date:
|
|
11
|
+
case TYPE.time:
|
|
12
|
+
return [
|
|
13
|
+
part
|
|
14
|
+
];
|
|
15
|
+
case TYPE.plural:
|
|
16
|
+
case TYPE.select:
|
|
17
|
+
return [
|
|
18
|
+
part,
|
|
19
|
+
...collectTemplateVariables(Object.values(part.options).flatMap(({ value })=>value))
|
|
20
|
+
];
|
|
21
|
+
case TYPE.tag:
|
|
22
|
+
return [
|
|
23
|
+
part,
|
|
24
|
+
...collectTemplateVariables(part.children)
|
|
25
|
+
];
|
|
26
|
+
default:
|
|
27
|
+
return [
|
|
28
|
+
part
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export const parseMessageSchema = (schema)=>{
|
|
33
|
+
const description = schema.match(/^\[.+\]/)?.[0];
|
|
34
|
+
// TODO add support for variables description
|
|
35
|
+
// const withoutDescription = schema.replace(description || "", "").trim();
|
|
36
|
+
// const withoutOptional = withoutDescription.split(" | ")[0]?.trim();
|
|
37
|
+
return {
|
|
38
|
+
description: description?.slice(1, -1),
|
|
39
|
+
variables: extractTemplateVariables(schema)
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/icu/schema.ts"],"sourcesContent":["import type { MessageFormatElement } from '@formatjs/icu-messageformat-parser';\nimport { parse, TYPE } from '@formatjs/icu-messageformat-parser';\nimport type { MessageConfig, TemplateVariable } from '@/types';\n\nexport const extractTemplateVariables = (schema: string): TemplateVariable[] =>\n collectTemplateVariables(parse(schema));\n\nconst collectTemplateVariables = (\n parts: MessageFormatElement[],\n): TemplateVariable[] =>\n parts.flatMap<TemplateVariable>((part) => {\n switch (part.type) {\n case TYPE.literal:\n case TYPE.pound:\n return [];\n case TYPE.argument:\n case TYPE.number:\n case TYPE.date:\n case TYPE.time:\n return [part];\n case TYPE.plural:\n case TYPE.select:\n return [\n part,\n ...collectTemplateVariables(\n Object.values(part.options).flatMap(({ value }) => value),\n ),\n ];\n case TYPE.tag:\n return [part, ...collectTemplateVariables(part.children)];\n default:\n return [part];\n }\n });\n\nexport const parseMessageSchema = (schema: string): MessageConfig => {\n const description = schema.match(/^\\[.+\\]/)?.[0];\n // TODO add support for variables description\n // const withoutDescription = schema.replace(description || \"\", \"\").trim();\n // const withoutOptional = withoutDescription.split(\" | \")[0]?.trim();\n\n return {\n description: description?.slice(1, -1),\n variables: extractTemplateVariables(schema),\n };\n};\n"],"names":["parse","TYPE","extractTemplateVariables","schema","collectTemplateVariables","parts","flatMap","part","type","literal","pound","argument","number","date","time","plural","select","Object","values","options","value","tag","children","parseMessageSchema","description","match","slice","variables"],"mappings":"AACA,SAASA,KAAK,EAAEC,IAAI,QAAQ,qCAAqC;AAGjE,OAAO,MAAMC,2BAA2B,CAACC,SACvCC,yBAAyBJ,MAAMG,SAAS;AAE1C,MAAMC,2BAA2B,CAC/BC,QAEAA,MAAMC,OAAO,CAAmB,CAACC;QAC/B,OAAQA,KAAKC,IAAI;YACf,KAAKP,KAAKQ,OAAO;YACjB,KAAKR,KAAKS,KAAK;gBACb,OAAO,EAAE;YACX,KAAKT,KAAKU,QAAQ;YAClB,KAAKV,KAAKW,MAAM;YAChB,KAAKX,KAAKY,IAAI;YACd,KAAKZ,KAAKa,IAAI;gBACZ,OAAO;oBAACP;iBAAK;YACf,KAAKN,KAAKc,MAAM;YAChB,KAAKd,KAAKe,MAAM;gBACd,OAAO;oBACLT;uBACGH,yBACDa,OAAOC,MAAM,CAACX,KAAKY,OAAO,EAAEb,OAAO,CAAC,CAAC,EAAEc,KAAK,EAAE,GAAKA;iBAEtD;YACH,KAAKnB,KAAKoB,GAAG;gBACX,OAAO;oBAACd;uBAASH,yBAAyBG,KAAKe,QAAQ;iBAAE;YAC3D;gBACE,OAAO;oBAACf;iBAAK;QACjB;IACF;AAEF,OAAO,MAAMgB,qBAAqB,CAACpB;IACjC,MAAMqB,cAAcrB,OAAOsB,KAAK,CAAC,YAAY,CAAC,EAAE;IAChD,6CAA6C;IAC7C,2EAA2E;IAC3E,sEAAsE;IAEtE,OAAO;QACLD,aAAaA,aAAaE,MAAM,GAAG,CAAC;QACpCC,WAAWzB,yBAAyBC;IACtC;AACF,EAAE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
|
|
2
|
+
import { parse } from '@formatjs/icu-messageformat-parser';
|
|
3
|
+
/**
|
|
4
|
+
* Parse an ICU message string into a AST array
|
|
5
|
+
*/
|
|
6
|
+
export declare const parseICUMessage: typeof parse;
|
|
7
|
+
/**
|
|
8
|
+
* Serialize an ICU message AST array into a ICU message string
|
|
9
|
+
*/
|
|
10
|
+
export declare const serializeICUMessage: (elements: MessageFormatElement[]) => string;
|
|
11
|
+
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/icu/serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAQ,MAAM,oCAAoC,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,eAAe,cAAQ,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,mBAAmB,aAAc,oBAAoB,EAAE,KAAG,MA8C1D,CAAC"}
|