@payloadcms/richtext-slate 3.17.1 → 3.18.0-canary.030d28e
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/dist/field/elements/link/Button/index.d.ts.map +1 -1
- package/dist/field/elements/link/Button/index.js +4 -2
- package/dist/field/elements/link/Button/index.js.map +1 -1
- package/dist/field/elements/link/Element/index.d.ts.map +1 -1
- package/dist/field/elements/link/Element/index.js +3 -1
- package/dist/field/elements/link/Element/index.js.map +1 -1
- package/dist/field/elements/link/LinkDrawer/index.d.ts.map +1 -1
- package/dist/field/elements/link/LinkDrawer/index.js +5 -4
- package/dist/field/elements/link/LinkDrawer/index.js.map +1 -1
- package/dist/field/elements/upload/Element/UploadDrawer/index.d.ts.map +1 -1
- package/dist/field/elements/upload/Element/UploadDrawer/index.js +9 -7
- package/dist/field/elements/upload/Element/UploadDrawer/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/link/Button/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAA6B,MAAM,OAAO,CAAA;AAkDjD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAA;CACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/link/Button/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAA6B,MAAM,OAAO,CAAA;AAkDjD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAA;CACnB,CAuEA,CAAA"}
|
|
@@ -65,7 +65,7 @@ export const LinkButton = ({ schemaPath })=>{
|
|
|
65
65
|
const { t } = useTranslation();
|
|
66
66
|
const editor = useSlate();
|
|
67
67
|
const { getFormState } = useServerFunctions();
|
|
68
|
-
const { collectionSlug,
|
|
68
|
+
const { collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo();
|
|
69
69
|
const { closeModal, openModal } = useModal();
|
|
70
70
|
const drawerSlug = useDrawerSlug('rich-text-link');
|
|
71
71
|
const { componentMap } = fieldProps;
|
|
@@ -88,7 +88,9 @@ export const LinkButton = ({ schemaPath })=>{
|
|
|
88
88
|
const { state } = await getFormState({
|
|
89
89
|
collectionSlug,
|
|
90
90
|
data,
|
|
91
|
-
docPermissions
|
|
91
|
+
docPermissions: {
|
|
92
|
+
fields: true
|
|
93
|
+
},
|
|
92
94
|
docPreferences: await getDocPreferences(),
|
|
93
95
|
globalSlug,
|
|
94
96
|
operation: 'update',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/elements/link/Button/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormState } from 'payload'\n\nimport {\n useDocumentInfo,\n useDrawerSlug,\n useModal,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { reduceFieldsToValues } from 'payload/shared'\nimport React, { Fragment, useState } from 'react'\nimport { Editor, Range, Transforms } from 'slate'\nimport { ReactEditor, useSlate } from 'slate-react'\n\nimport { LinkIcon } from '../../../icons/Link/index.js'\nimport { useElementButton } from '../../../providers/ElementButtonProvider.js'\nimport { ElementButton } from '../../Button.js'\nimport { isElementActive } from '../../isActive.js'\nimport { LinkDrawer } from '../LinkDrawer/index.js'\nimport { linkFieldsSchemaPath } from '../shared.js'\nimport { unwrapLink } from '../utilities.js'\n\n/**\n * This function is called when a new link is created - not when an existing link is edited.\n */\nconst insertLink = (editor, fields) => {\n const isCollapsed = editor.selection && Range.isCollapsed(editor.selection)\n const data = reduceFieldsToValues(fields, true)\n\n const newLink = {\n type: 'link',\n children: [],\n doc: data.doc,\n fields: data.fields, // Any custom user-added fields are part of data.fields\n linkType: data.linkType,\n newTab: data.newTab,\n url: data.url,\n }\n\n if (isCollapsed || !editor.selection) {\n // If selection anchor and focus are the same,\n // Just inject a new node with children already set\n Transforms.insertNodes(editor, {\n ...newLink,\n children: [{ text: String(data.text) }],\n })\n } else if (editor.selection) {\n // Otherwise we need to wrap the selected node in a link,\n // Delete its old text,\n // Move the selection one position forward into the link,\n // And insert the text back into the new link\n Transforms.wrapNodes(editor, newLink, { split: true })\n Transforms.delete(editor, { at: editor.selection.focus.path, unit: 'word' })\n Transforms.move(editor, { distance: 1, unit: 'offset' })\n Transforms.insertText(editor, String(data.text), { at: editor.selection.focus.path })\n }\n\n ReactEditor.focus(editor)\n}\n\nexport const LinkButton: React.FC<{\n schemaPath: string\n}> = ({ schemaPath }) => {\n const { fieldProps } = useElementButton()\n const [initialState, setInitialState] = useState<FormState>({})\n\n const { t } = useTranslation()\n const editor = useSlate()\n const { getFormState } = useServerFunctions()\n const { collectionSlug,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/elements/link/Button/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormState } from 'payload'\n\nimport {\n useDocumentInfo,\n useDrawerSlug,\n useModal,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { reduceFieldsToValues } from 'payload/shared'\nimport React, { Fragment, useState } from 'react'\nimport { Editor, Range, Transforms } from 'slate'\nimport { ReactEditor, useSlate } from 'slate-react'\n\nimport { LinkIcon } from '../../../icons/Link/index.js'\nimport { useElementButton } from '../../../providers/ElementButtonProvider.js'\nimport { ElementButton } from '../../Button.js'\nimport { isElementActive } from '../../isActive.js'\nimport { LinkDrawer } from '../LinkDrawer/index.js'\nimport { linkFieldsSchemaPath } from '../shared.js'\nimport { unwrapLink } from '../utilities.js'\n\n/**\n * This function is called when a new link is created - not when an existing link is edited.\n */\nconst insertLink = (editor, fields) => {\n const isCollapsed = editor.selection && Range.isCollapsed(editor.selection)\n const data = reduceFieldsToValues(fields, true)\n\n const newLink = {\n type: 'link',\n children: [],\n doc: data.doc,\n fields: data.fields, // Any custom user-added fields are part of data.fields\n linkType: data.linkType,\n newTab: data.newTab,\n url: data.url,\n }\n\n if (isCollapsed || !editor.selection) {\n // If selection anchor and focus are the same,\n // Just inject a new node with children already set\n Transforms.insertNodes(editor, {\n ...newLink,\n children: [{ text: String(data.text) }],\n })\n } else if (editor.selection) {\n // Otherwise we need to wrap the selected node in a link,\n // Delete its old text,\n // Move the selection one position forward into the link,\n // And insert the text back into the new link\n Transforms.wrapNodes(editor, newLink, { split: true })\n Transforms.delete(editor, { at: editor.selection.focus.path, unit: 'word' })\n Transforms.move(editor, { distance: 1, unit: 'offset' })\n Transforms.insertText(editor, String(data.text), { at: editor.selection.focus.path })\n }\n\n ReactEditor.focus(editor)\n}\n\nexport const LinkButton: React.FC<{\n schemaPath: string\n}> = ({ schemaPath }) => {\n const { fieldProps } = useElementButton()\n const [initialState, setInitialState] = useState<FormState>({})\n\n const { t } = useTranslation()\n const editor = useSlate()\n const { getFormState } = useServerFunctions()\n const { collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n\n const { closeModal, openModal } = useModal()\n const drawerSlug = useDrawerSlug('rich-text-link')\n\n const { componentMap } = fieldProps\n\n const fields = componentMap[linkFieldsSchemaPath]\n\n return (\n <Fragment>\n <ElementButton\n className=\"link\"\n format=\"link\"\n onClick={async () => {\n if (isElementActive(editor, 'link')) {\n unwrapLink(editor)\n } else {\n openModal(drawerSlug)\n const isCollapsed = editor.selection && Range.isCollapsed(editor.selection)\n\n if (!isCollapsed) {\n const data = {\n text: editor.selection ? Editor.string(editor, editor.selection) : '',\n }\n\n const { state } = await getFormState({\n collectionSlug,\n data,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n globalSlug,\n operation: 'update',\n renderAllFields: true,\n schemaPath: [...schemaPath.split('.'), ...linkFieldsSchemaPath.split('.')].join(\n '.',\n ),\n })\n\n setInitialState(state)\n }\n }\n }}\n tooltip={t('fields:addLink')}\n >\n <LinkIcon />\n </ElementButton>\n <LinkDrawer\n drawerSlug={drawerSlug}\n fields={Array.isArray(fields) ? fields : []}\n handleClose={() => {\n closeModal(drawerSlug)\n }}\n handleModalSubmit={(fields) => {\n insertLink(editor, fields)\n closeModal(drawerSlug)\n }}\n initialState={initialState}\n schemaPath={schemaPath}\n />\n </Fragment>\n )\n}\n"],"names":["useDocumentInfo","useDrawerSlug","useModal","useServerFunctions","useTranslation","reduceFieldsToValues","React","Fragment","useState","Editor","Range","Transforms","ReactEditor","useSlate","LinkIcon","useElementButton","ElementButton","isElementActive","LinkDrawer","linkFieldsSchemaPath","unwrapLink","insertLink","editor","fields","isCollapsed","selection","data","newLink","type","children","doc","linkType","newTab","url","insertNodes","text","String","wrapNodes","split","delete","at","focus","path","unit","move","distance","insertText","LinkButton","schemaPath","fieldProps","initialState","setInitialState","t","getFormState","collectionSlug","getDocPreferences","globalSlug","closeModal","openModal","drawerSlug","componentMap","className","format","onClick","string","state","docPermissions","docPreferences","operation","renderAllFields","join","tooltip","Array","isArray","handleClose","handleModalSubmit"],"mappings":"AAAA;;AAIA,SACEA,eAAe,EACfC,aAAa,EACbC,QAAQ,EACRC,kBAAkB,EAClBC,cAAc,QACT,iBAAgB;AACvB,SAASC,oBAAoB,QAAQ,iBAAgB;AACrD,OAAOC,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,QAAO;AACjD,SAASC,MAAM,EAAEC,KAAK,EAAEC,UAAU,QAAQ,QAAO;AACjD,SAASC,WAAW,EAAEC,QAAQ,QAAQ,cAAa;AAEnD,SAASC,QAAQ,QAAQ,+BAA8B;AACvD,SAASC,gBAAgB,QAAQ,8CAA6C;AAC9E,SAASC,aAAa,QAAQ,kBAAiB;AAC/C,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,oBAAoB,QAAQ,eAAc;AACnD,SAASC,UAAU,QAAQ,kBAAiB;AAE5C;;CAEC,GACD,MAAMC,aAAa,CAACC,QAAQC;IAC1B,MAAMC,cAAcF,OAAOG,SAAS,IAAIf,MAAMc,WAAW,CAACF,OAAOG,SAAS;IAC1E,MAAMC,O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["../../../../../src/field/elements/link/Element/index.tsx"],"names":[],"mappings":"AA2BA,OAAO,cAAc,CAAA;AAiCrB,eAAO,MAAM,WAAW,+
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/link/Element/index.tsx"],"names":[],"mappings":"AA2BA,OAAO,cAAc,CAAA;AAiCrB,eAAO,MAAM,WAAW,+CAwLvB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/elements/link/Element/index.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Popup,\n Translation,\n useConfig,\n useDocumentInfo,\n useDrawerSlug,\n useLocale,\n useModal,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { deepCopyObject, reduceFieldsToValues } from 'payload/shared'\nimport { useCallback, useEffect, useState } from 'react'\nimport { Editor, Node, Transforms } from 'slate'\nimport { ReactEditor, useSlate } from 'slate-react'\n\nimport type { LinkElementType } from '../types.js'\n\nimport { useElement } from '../../../providers/ElementProvider.js'\nimport { LinkDrawer } from '../LinkDrawer/index.js'\nimport { linkFieldsSchemaPath } from '../shared.js'\nimport { unwrapLink } from '../utilities.js'\nimport './index.scss'\n\nconst baseClass = 'rich-text-link'\n\n/**\n * This function is called when an existing link is edited.\n * When a link is first created, another function is called: {@link ../Button/index.tsx#insertLink}\n */\nconst insertChange = (editor, fields) => {\n const data = reduceFieldsToValues(fields, true)\n\n const [, parentPath] = Editor.above(editor)\n\n const newNode: Record<string, unknown> = {\n doc: data.doc,\n linkType: data.linkType,\n newTab: data.newTab,\n url: data.url,\n }\n\n if (data.fields) {\n newNode.fields = data.fields\n }\n\n Transforms.setNodes(editor, newNode, { at: parentPath })\n\n Transforms.delete(editor, { at: editor.selection.focus.path, unit: 'block' })\n Transforms.move(editor, { distance: 1, unit: 'offset' })\n Transforms.insertText(editor, String(data.text), { at: editor.selection.focus.path })\n\n ReactEditor.focus(editor)\n}\n\nexport const LinkElement = () => {\n const { attributes, children, editorRef, element, fieldProps, schemaPath } =\n useElement<LinkElementType>()\n\n const fieldMapPath = `${schemaPath}.${linkFieldsSchemaPath}`\n\n const { componentMap } = fieldProps\n const fields = componentMap[linkFieldsSchemaPath]\n const { id, collectionSlug, docPermissions, getDocPreferences, globalSlug } = useDocumentInfo()\n\n const editor = useSlate()\n const { config } = useConfig()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n const { closeModal, openModal, toggleModal } = useModal()\n const [renderModal, setRenderModal] = useState(false)\n const [renderPopup, setRenderPopup] = useState(false)\n const [initialState, setInitialState] = useState<FormState>({})\n\n const { getFormState } = useServerFunctions()\n\n const drawerSlug = useDrawerSlug('rich-text-link')\n\n const handleTogglePopup = useCallback((render) => {\n if (!render) {\n setRenderPopup(render)\n }\n }, [])\n\n useEffect(() => {\n const awaitInitialState = async () => {\n const data = {\n doc: element.doc,\n fields: deepCopyObject(element.fields),\n linkType: element.linkType,\n newTab: element.newTab,\n text: Node.string(element),\n url: element.url,\n }\n\n const { state } = await getFormState({\n collectionSlug,\n data,\n docPermissions,\n docPreferences: await getDocPreferences(),\n globalSlug,\n operation: 'update',\n renderAllFields: true,\n schemaPath: fieldMapPath ?? '',\n })\n\n setInitialState(state)\n }\n\n if (renderModal) {\n void awaitInitialState()\n }\n }, [\n renderModal,\n element,\n locale,\n t,\n collectionSlug,\n config,\n id,\n fieldMapPath,\n getFormState,\n globalSlug,\n getDocPreferences,\n docPermissions,\n ])\n\n return (\n <span className={baseClass} {...attributes}>\n <span contentEditable={false} style={{ userSelect: 'none' }}>\n {renderModal && (\n <LinkDrawer\n drawerSlug={drawerSlug}\n fields={Array.isArray(fields) ? fields : []}\n handleClose={() => {\n toggleModal(drawerSlug)\n setRenderModal(false)\n }}\n handleModalSubmit={(fields) => {\n insertChange(editor, fields)\n closeModal(drawerSlug)\n setRenderModal(false)\n }}\n initialState={initialState}\n schemaPath={schemaPath}\n />\n )}\n <Popup\n boundingRef={editorRef}\n buttonType=\"none\"\n forceOpen={renderPopup}\n horizontalAlign=\"left\"\n onToggleOpen={handleTogglePopup}\n render={() => (\n <div className={`${baseClass}__popup`}>\n {element.linkType === 'internal' && element.doc?.relationTo && element.doc?.value && (\n <Translation\n elements={{\n '0': ({ children }) => (\n <a\n className={`${baseClass}__link-label`}\n href={`${config.routes.admin}/collections/${element.doc.relationTo}/${element.doc.value}`}\n rel=\"noreferrer\"\n target=\"_blank\"\n title={`${config.routes.admin}/collections/${element.doc.relationTo}/${element.doc.value}`}\n >\n {children}\n </a>\n ),\n }}\n i18nKey=\"fields:linkedTo\"\n t={t}\n variables={{\n label: getTranslation(\n config.collections.find(({ slug }) => slug === element.doc.relationTo)?.labels\n ?.singular,\n i18n,\n ),\n }}\n />\n )}\n {(element.linkType === 'custom' || !element.linkType) && (\n <a\n className={`${baseClass}__link-label`}\n href={element.url}\n rel=\"noreferrer\"\n target=\"_blank\"\n title={element.url}\n >\n {element.url}\n </a>\n )}\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__link-edit`}\n icon=\"edit\"\n onClick={(e) => {\n e.preventDefault()\n setRenderPopup(false)\n openModal(drawerSlug)\n setRenderModal(true)\n }}\n round\n tooltip={t('general:edit')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__link-close`}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n unwrapLink(editor)\n }}\n round\n tooltip={t('general:remove')}\n />\n </div>\n )}\n size=\"fit-content\"\n verticalAlign=\"bottom\"\n />\n </span>\n <span\n className={[`${baseClass}__popup-toggler`].filter(Boolean).join(' ')}\n onClick={() => setRenderPopup(true)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n setRenderPopup(true)\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </span>\n </span>\n )\n}\n"],"names":["getTranslation","Button","Popup","Translation","useConfig","useDocumentInfo","useDrawerSlug","useLocale","useModal","useServerFunctions","useTranslation","deepCopyObject","reduceFieldsToValues","useCallback","useEffect","useState","Editor","Node","Transforms","ReactEditor","useSlate","useElement","LinkDrawer","linkFieldsSchemaPath","unwrapLink","baseClass","insertChange","editor","fields","data","parentPath","above","newNode","doc","linkType","newTab","url","setNodes","at","delete","selection","focus","path","unit","move","distance","insertText","String","text","LinkElement","attributes","children","editorRef","element","fieldProps","schemaPath","fieldMapPath","componentMap","id","collectionSlug","docPermissions","getDocPreferences","globalSlug","config","code","locale","i18n","t","closeModal","openModal","toggleModal","renderModal","setRenderModal","renderPopup","setRenderPopup","initialState","setInitialState","getFormState","drawerSlug","handleTogglePopup","render","awaitInitialState","string","state","docPreferences","operation","renderAllFields","span","className","contentEditable","style","userSelect","Array","isArray","handleClose","handleModalSubmit","boundingRef","buttonType","forceOpen","horizontalAlign","onToggleOpen","div","relationTo","value","elements","a","href","routes","admin","rel","target","title","i18nKey","variables","label","collections","find","slug","labels","singular","buttonStyle","icon","onClick","e","preventDefault","round","tooltip","size","verticalAlign","filter","Boolean","join","onKeyDown","key","role","tabIndex"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,aAAa,EACbC,SAAS,EACTC,QAAQ,EACRC,kBAAkB,EAClBC,cAAc,QACT,iBAAgB;AACvB,SAASC,cAAc,EAAEC,oBAAoB,QAAQ,iBAAgB;AACrE,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACxD,SAASC,MAAM,EAAEC,IAAI,EAAEC,UAAU,QAAQ,QAAO;AAChD,SAASC,WAAW,EAAEC,QAAQ,QAAQ,cAAa;AAInD,SAASC,UAAU,QAAQ,wCAAuC;AAClE,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,oBAAoB,QAAQ,eAAc;AACnD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,OAAO,eAAc;A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AQ,AAAD,mBACjD,KAACuE;wCACCjB,WAAW,GAAG/D,UAAU,YAAY,CAAC;wCACrCiF,MAAMrD,QAAQjB,GAAG;wCACjByE,KAAI;wCACJC,QAAO;wCACPC,OAAO1D,QAAQjB,GAAG;kDAEjBiB,QAAQjB,GAAG;;kDAGhB,KAACnC;wCACCuH,aAAY;wCACZhC,WAAW,GAAG/D,UAAU,WAAW,CAAC;wCACpCgG,MAAK;wCACLC,SAAS,CAACC;4CACRA,EAAEC,cAAc;4CAChBlD,eAAe;4CACfL,UAAUS;4CACVN,eAAe;wCACjB;wCACAqD,KAAK;wCACLC,SAAS3D,EAAE;;kDAEb,KAAClE;wCACCuH,aAAY;wCACZhC,WAAW,GAAG/D,UAAU,YAAY,CAAC;wCACrCgG,MAAK;wCACLC,SAAS,CAACC;4CACRA,EAAEC,cAAc;4CAChBpG,WAAWG;wCACb;wCACAkG,KAAK;wCACLC,SAAS3D,EAAE;;;;wBAIjB4D,MAAK;wBACLC,eAAc;;;;0BAGlB,KAACzC;gBACCC,WAAW;oBAAC,GAAG/D,UAAU,eAAe,CAAC;iBAAC,CAACwG,MAAM,CAACC,SAASC,IAAI,CAAC;gBAChET,SAAS,IAAMhD,eAAe;gBAC9B0D,WAAW,CAACT;oBACV,IAAIA,EAAEU,GAAG,KAAK,SAAS;wBACrB3D,eAAe;oBACjB;gBACF;gBACA4D,MAAK;gBACLC,UAAU;0BAETpF;;;;AAIT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/elements/link/Element/index.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Popup,\n Translation,\n useConfig,\n useDocumentInfo,\n useDrawerSlug,\n useLocale,\n useModal,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { deepCopyObject, reduceFieldsToValues } from 'payload/shared'\nimport { useCallback, useEffect, useState } from 'react'\nimport { Editor, Node, Transforms } from 'slate'\nimport { ReactEditor, useSlate } from 'slate-react'\n\nimport type { LinkElementType } from '../types.js'\n\nimport { useElement } from '../../../providers/ElementProvider.js'\nimport { LinkDrawer } from '../LinkDrawer/index.js'\nimport { linkFieldsSchemaPath } from '../shared.js'\nimport { unwrapLink } from '../utilities.js'\nimport './index.scss'\n\nconst baseClass = 'rich-text-link'\n\n/**\n * This function is called when an existing link is edited.\n * When a link is first created, another function is called: {@link ../Button/index.tsx#insertLink}\n */\nconst insertChange = (editor, fields) => {\n const data = reduceFieldsToValues(fields, true)\n\n const [, parentPath] = Editor.above(editor)\n\n const newNode: Record<string, unknown> = {\n doc: data.doc,\n linkType: data.linkType,\n newTab: data.newTab,\n url: data.url,\n }\n\n if (data.fields) {\n newNode.fields = data.fields\n }\n\n Transforms.setNodes(editor, newNode, { at: parentPath })\n\n Transforms.delete(editor, { at: editor.selection.focus.path, unit: 'block' })\n Transforms.move(editor, { distance: 1, unit: 'offset' })\n Transforms.insertText(editor, String(data.text), { at: editor.selection.focus.path })\n\n ReactEditor.focus(editor)\n}\n\nexport const LinkElement = () => {\n const { attributes, children, editorRef, element, fieldProps, schemaPath } =\n useElement<LinkElementType>()\n\n const fieldMapPath = `${schemaPath}.${linkFieldsSchemaPath}`\n\n const { componentMap } = fieldProps\n const fields = componentMap[linkFieldsSchemaPath]\n const { id, collectionSlug, docPermissions, getDocPreferences, globalSlug } = useDocumentInfo()\n\n const editor = useSlate()\n const { config } = useConfig()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n const { closeModal, openModal, toggleModal } = useModal()\n const [renderModal, setRenderModal] = useState(false)\n const [renderPopup, setRenderPopup] = useState(false)\n const [initialState, setInitialState] = useState<FormState>({})\n\n const { getFormState } = useServerFunctions()\n\n const drawerSlug = useDrawerSlug('rich-text-link')\n\n const handleTogglePopup = useCallback((render) => {\n if (!render) {\n setRenderPopup(render)\n }\n }, [])\n\n useEffect(() => {\n const awaitInitialState = async () => {\n const data = {\n doc: element.doc,\n fields: deepCopyObject(element.fields),\n linkType: element.linkType,\n newTab: element.newTab,\n text: Node.string(element),\n url: element.url,\n }\n\n const { state } = await getFormState({\n collectionSlug,\n data,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n globalSlug,\n operation: 'update',\n renderAllFields: true,\n schemaPath: fieldMapPath ?? '',\n })\n\n setInitialState(state)\n }\n\n if (renderModal) {\n void awaitInitialState()\n }\n }, [\n renderModal,\n element,\n locale,\n t,\n collectionSlug,\n config,\n id,\n fieldMapPath,\n getFormState,\n globalSlug,\n getDocPreferences,\n docPermissions,\n ])\n\n return (\n <span className={baseClass} {...attributes}>\n <span contentEditable={false} style={{ userSelect: 'none' }}>\n {renderModal && (\n <LinkDrawer\n drawerSlug={drawerSlug}\n fields={Array.isArray(fields) ? fields : []}\n handleClose={() => {\n toggleModal(drawerSlug)\n setRenderModal(false)\n }}\n handleModalSubmit={(fields) => {\n insertChange(editor, fields)\n closeModal(drawerSlug)\n setRenderModal(false)\n }}\n initialState={initialState}\n schemaPath={schemaPath}\n />\n )}\n <Popup\n boundingRef={editorRef}\n buttonType=\"none\"\n forceOpen={renderPopup}\n horizontalAlign=\"left\"\n onToggleOpen={handleTogglePopup}\n render={() => (\n <div className={`${baseClass}__popup`}>\n {element.linkType === 'internal' && element.doc?.relationTo && element.doc?.value && (\n <Translation\n elements={{\n '0': ({ children }) => (\n <a\n className={`${baseClass}__link-label`}\n href={`${config.routes.admin}/collections/${element.doc.relationTo}/${element.doc.value}`}\n rel=\"noreferrer\"\n target=\"_blank\"\n title={`${config.routes.admin}/collections/${element.doc.relationTo}/${element.doc.value}`}\n >\n {children}\n </a>\n ),\n }}\n i18nKey=\"fields:linkedTo\"\n t={t}\n variables={{\n label: getTranslation(\n config.collections.find(({ slug }) => slug === element.doc.relationTo)?.labels\n ?.singular,\n i18n,\n ),\n }}\n />\n )}\n {(element.linkType === 'custom' || !element.linkType) && (\n <a\n className={`${baseClass}__link-label`}\n href={element.url}\n rel=\"noreferrer\"\n target=\"_blank\"\n title={element.url}\n >\n {element.url}\n </a>\n )}\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__link-edit`}\n icon=\"edit\"\n onClick={(e) => {\n e.preventDefault()\n setRenderPopup(false)\n openModal(drawerSlug)\n setRenderModal(true)\n }}\n round\n tooltip={t('general:edit')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__link-close`}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n unwrapLink(editor)\n }}\n round\n tooltip={t('general:remove')}\n />\n </div>\n )}\n size=\"fit-content\"\n verticalAlign=\"bottom\"\n />\n </span>\n <span\n className={[`${baseClass}__popup-toggler`].filter(Boolean).join(' ')}\n onClick={() => setRenderPopup(true)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n setRenderPopup(true)\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </span>\n </span>\n )\n}\n"],"names":["getTranslation","Button","Popup","Translation","useConfig","useDocumentInfo","useDrawerSlug","useLocale","useModal","useServerFunctions","useTranslation","deepCopyObject","reduceFieldsToValues","useCallback","useEffect","useState","Editor","Node","Transforms","ReactEditor","useSlate","useElement","LinkDrawer","linkFieldsSchemaPath","unwrapLink","baseClass","insertChange","editor","fields","data","parentPath","above","newNode","doc","linkType","newTab","url","setNodes","at","delete","selection","focus","path","unit","move","distance","insertText","String","text","LinkElement","attributes","children","editorRef","element","fieldProps","schemaPath","fieldMapPath","componentMap","id","collectionSlug","docPermissions","getDocPreferences","globalSlug","config","code","locale","i18n","t","closeModal","openModal","toggleModal","renderModal","setRenderModal","renderPopup","setRenderPopup","initialState","setInitialState","getFormState","drawerSlug","handleTogglePopup","render","awaitInitialState","string","state","docPreferences","operation","renderAllFields","span","className","contentEditable","style","userSelect","Array","isArray","handleClose","handleModalSubmit","boundingRef","buttonType","forceOpen","horizontalAlign","onToggleOpen","div","relationTo","value","elements","a","href","routes","admin","rel","target","title","i18nKey","variables","label","collections","find","slug","labels","singular","buttonStyle","icon","onClick","e","preventDefault","round","tooltip","size","verticalAlign","filter","Boolean","join","onKeyDown","key","role","tabIndex"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,aAAa,EACbC,SAAS,EACTC,QAAQ,EACRC,kBAAkB,EAClBC,cAAc,QACT,iBAAgB;AACvB,SAASC,cAAc,EAAEC,oBAAoB,QAAQ,iBAAgB;AACrE,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACxD,SAASC,MAAM,EAAEC,IAAI,EAAEC,UAAU,QAAQ,QAAO;AAChD,SAASC,WAAW,EAAEC,QAAQ,QAAQ,cAAa;AAInD,SAASC,UAAU,QAAQ,wCAAuC;AAClE,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,oBAAoB,QAAQ,eAAc;AACnD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB;;;CAGC,GACD,MAAMC,eAAe,CAACC,QAAQC;IAC5B,MAAMC,OAAOjB,qBAAqBgB,QAAQ;IAE1C,MAAM,GAAGE,WAAW,GAAGd,OAAOe,KAAK,CAACJ;IAEpC,MAAMK,UAAmC;QACvCC,KAAKJ,KAAKI,GAAG;QACbC,UAAUL,KAAKK,QAAQ;QACvBC,QAAQN,KAAKM,MAAM;QACnBC,KAAKP,KAAKO,GAAG;IACf;IAEA,IAAIP,KAAKD,MAAM,EAAE;QACfI,QAAQJ,MAAM,GAAGC,KAAKD,MAAM;IAC9B;IAEAV,WAAWmB,QAAQ,CAACV,QAAQK,SAAS;QAAEM,IAAIR;IAAW;IAEtDZ,WAAWqB,MAAM,CAACZ,QAAQ;QAAEW,IAAIX,OAAOa,SAAS,CAACC,KAAK,CAACC,IAAI;QAAEC,MAAM;IAAQ;IAC3EzB,WAAW0B,IAAI,CAACjB,QAAQ;QAAEkB,UA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S3D,EAAE;;;;wBAIjB4D,MAAK;wBACLC,eAAc;;;;0BAGlB,KAACzC;gBACCC,WAAW;oBAAC,GAAG/D,UAAU,eAAe,CAAC;iBAAC,CAACwG,MAAM,CAACC,SAASC,IAAI,CAAC;gBAChET,SAAS,IAAMhD,eAAe;gBAC9B0D,WAAW,CAACT;oBACV,IAAIA,EAAEU,GAAG,KAAK,SAAS;wBACrB3D,eAAe;oBACjB;gBACF;gBACA4D,MAAK;gBACLC,UAAU;0BAETpF;;;;AAIT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/link/LinkDrawer/index.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGvC,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/link/LinkDrawer/index.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGvC,OAAO,cAAc,CAAA;AAIrB,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA2DtC,CAAA"}
|
|
@@ -8,13 +8,15 @@ const baseClass = 'rich-text-link-edit-modal';
|
|
|
8
8
|
export const LinkDrawer = ({ drawerSlug, fields, handleModalSubmit, initialState, schemaPath })=>{
|
|
9
9
|
const { t } = useTranslation();
|
|
10
10
|
const fieldMapPath = `${schemaPath}.${linkFieldsSchemaPath}`;
|
|
11
|
-
const { id, collectionSlug,
|
|
11
|
+
const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo();
|
|
12
12
|
const { getFormState } = useServerFunctions();
|
|
13
13
|
const onChange = useCallback(async ({ formState: prevFormState })=>{
|
|
14
14
|
const { state } = await getFormState({
|
|
15
15
|
id,
|
|
16
16
|
collectionSlug,
|
|
17
|
-
docPermissions
|
|
17
|
+
docPermissions: {
|
|
18
|
+
fields: true
|
|
19
|
+
},
|
|
18
20
|
docPreferences: await getDocPreferences(),
|
|
19
21
|
formState: prevFormState,
|
|
20
22
|
globalSlug,
|
|
@@ -27,7 +29,6 @@ export const LinkDrawer = ({ drawerSlug, fields, handleModalSubmit, initialState
|
|
|
27
29
|
id,
|
|
28
30
|
collectionSlug,
|
|
29
31
|
getDocPreferences,
|
|
30
|
-
docPermissions,
|
|
31
32
|
globalSlug,
|
|
32
33
|
fieldMapPath
|
|
33
34
|
]);
|
|
@@ -53,7 +54,7 @@ export const LinkDrawer = ({ drawerSlug, fields, handleModalSubmit, initialState
|
|
|
53
54
|
parentIndexPath: "",
|
|
54
55
|
parentPath: '',
|
|
55
56
|
parentSchemaPath: "",
|
|
56
|
-
permissions:
|
|
57
|
+
permissions: true,
|
|
57
58
|
readOnly: false
|
|
58
59
|
}),
|
|
59
60
|
/*#__PURE__*/ _jsx(LinkSubmit, {})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/elements/link/LinkDrawer/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormProps } from '@payloadcms/ui'\n\nimport {\n Drawer,\n EditDepthProvider,\n Form,\n FormSubmit,\n RenderFields,\n useDocumentInfo,\n useEditDepth,\n useHotkey,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback, useRef } from 'react'\n\nimport type { Props } from './types.js'\n\nimport { linkFieldsSchemaPath } from '../shared.js'\nimport './index.scss'\n\nconst baseClass = 'rich-text-link-edit-modal'\n\nexport const LinkDrawer: React.FC<Props> = ({\n drawerSlug,\n fields,\n handleModalSubmit,\n initialState,\n schemaPath,\n}) => {\n const { t } = useTranslation()\n const fieldMapPath = `${schemaPath}.${linkFieldsSchemaPath}`\n\n const { id, collectionSlug,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/elements/link/LinkDrawer/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormProps } from '@payloadcms/ui'\n\nimport {\n Drawer,\n EditDepthProvider,\n Form,\n FormSubmit,\n RenderFields,\n useDocumentInfo,\n useEditDepth,\n useHotkey,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback, useRef } from 'react'\n\nimport type { Props } from './types.js'\n\nimport { linkFieldsSchemaPath } from '../shared.js'\nimport './index.scss'\n\nconst baseClass = 'rich-text-link-edit-modal'\n\nexport const LinkDrawer: React.FC<Props> = ({\n drawerSlug,\n fields,\n handleModalSubmit,\n initialState,\n schemaPath,\n}) => {\n const { t } = useTranslation()\n const fieldMapPath = `${schemaPath}.${linkFieldsSchemaPath}`\n\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n\n const { getFormState } = useServerFunctions()\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n formState: prevFormState,\n globalSlug,\n operation: 'update',\n schemaPath: fieldMapPath ?? '',\n })\n\n return state\n },\n\n [getFormState, id, collectionSlug, getDocPreferences, globalSlug, fieldMapPath],\n )\n\n return (\n <EditDepthProvider>\n <Drawer className={baseClass} slug={drawerSlug} title={t('fields:editLink')}>\n <Form\n beforeSubmit={[onChange]}\n disableValidationOnSubmit\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleModalSubmit}\n >\n <RenderFields\n fields={fields}\n forceRender\n parentIndexPath=\"\"\n parentPath={''}\n parentSchemaPath=\"\"\n permissions={true}\n readOnly={false}\n />\n <LinkSubmit />\n </Form>\n </Drawer>\n </EditDepthProvider>\n )\n}\n\nconst LinkSubmit: React.FC = () => {\n const { t } = useTranslation()\n const ref = useRef<HTMLButtonElement>(null)\n const editDepth = useEditDepth()\n\n useHotkey({ cmdCtrlKey: true, editDepth, keyCodes: ['s'] }, (e) => {\n e.preventDefault()\n e.stopPropagation()\n if (ref?.current) {\n ref.current.click()\n }\n })\n\n return <FormSubmit ref={ref}>{t('general:submit')}</FormSubmit>\n}\n"],"names":["Drawer","EditDepthProvider","Form","FormSubmit","RenderFields","useDocumentInfo","useEditDepth","useHotkey","useServerFunctions","useTranslation","React","useCallback","useRef","linkFieldsSchemaPath","baseClass","LinkDrawer","drawerSlug","fields","handleModalSubmit","initialState","schemaPath","t","fieldMapPath","id","collectionSlug","getDocPreferences","globalSlug","getFormState","onChange","formState","prevFormState","state","docPermissions","docPreferences","operation","className","slug","title","beforeSubmit","disableValidationOnSubmit","onSubmit","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","readOnly","LinkSubmit","ref","editDepth","cmdCtrlKey","keyCodes","e","preventDefault","stopPropagation","current","click"],"mappings":"AAAA;;AAIA,SACEA,MAAM,EACNC,iBAAiB,EACjBC,IAAI,EACJC,UAAU,EACVC,YAAY,EACZC,eAAe,EACfC,YAAY,EACZC,SAAS,EACTC,kBAAkB,EAClBC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,EAAEC,MAAM,QAAQ,QAAO;AAIlD,SAASC,oBAAoB,QAAQ,eAAc;AACnD,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,OAAO,MAAMC,aAA8B,CAAC,EAC1CC,UAAU,EACVC,MAAM,EACNC,iBAAiB,EACjBC,YAAY,EACZC,UAAU,EACX;IACC,MAAM,EAAEC,CAAC,EAAE,GAAGZ;IACd,MAAMa,eAAe,GAAGF,WAAW,CAAC,EAAEP,sBAAsB;IAE5D,MAAM,EAAEU,EAAE,EAAEC,cAAc,EAAEC,iBAAiB,EAAEC,UAAU,EAAE,GAAGrB;IAE9D,MAAM,EAAEsB,YAAY,EAAE,GAAGnB;IAEzB,MAAMoB,WAAqCjB,YACzC,OAAO,EAAEkB,WAAWC,aAAa,EAAE;QACjC,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMJ,aAAa;YACnCJ;YACAC;YACAQ,gBAAgB;gBACdf,QAAQ;YACV;YACAgB,gBAAgB,MAAMR;YACtBI,WAAWC;YACXJ;YACAQ,WAAW;YACXd,YAAYE,gBAAgB;QAC9B;QAEA,OAAOS;IACT,GAEA;QAACJ;QAAcJ;QAAIC;QAAgBC;QAAmBC;QAAYJ;KAAa;IAGjF,qBACE,KAACrB;kBACC,cAAA,KAACD;YAAOmC,WAAWrB;YAAWsB,MAAMpB;YAAYqB,OAAOhB,EAAE;sBACvD,cAAA,MAACnB;gBACCoC,cAAc;oBAACV;iBAAS;gBACxBW,yBAAyB;gBACzBpB,cAAcA;gBACdS,UAAU;oBAACA;iBAAS;gBACpBY,UAAUtB;;kCAEV,KAACd;wBACCa,QAAQA;wBACRwB,WAAW;wBACXC,iBAAgB;wBAChBC,YAAY;wBACZC,kBAAiB;wBACjBC,aAAa;wBACbC,UAAU;;kCAEZ,KAACC;;;;;AAKX,EAAC;AAED,MAAMA,aAAuB;IAC3B,MAAM,EAAE1B,CAAC,EAAE,GAAGZ;IACd,MAAMuC,MAAMpC,OAA0B;IACtC,MAAMqC,YAAY3C;IAElBC,UAAU;QAAE2C,YAAY;QAAMD;QAAWE,UAAU;YAAC;SAAI;IAAC,GAAG,CAACC;QAC3DA,EAAEC,cAAc;QAChBD,EAAEE,eAAe;QACjB,IAAIN,KAAKO,SAAS;YAChBP,IAAIO,OAAO,CAACC,KAAK;QACnB;IACF;IAEA,qBAAO,KAACrD;QAAW6C,KAAKA;kBAAM3B,EAAE;;AAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/elements/upload/Element/UploadDrawer/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAiBrD,OAAO,KAA2C,MAAM,OAAO,CAAA;AAI/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAIvD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;IACnC,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAA;IAC1C,QAAQ,CAAC,iBAAiB,EAAE,sBAAsB,CAAA;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/elements/upload/Element/UploadDrawer/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAiBrD,OAAO,KAA2C,MAAM,OAAO,CAAA;AAI/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAIvD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;IACnC,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAA;IAC1C,QAAQ,CAAC,iBAAiB,EAAE,sBAAsB,CAAA;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B,CA+HA,CAAA"}
|
|
@@ -13,7 +13,7 @@ export const UploadDrawer = (props)=>{
|
|
|
13
13
|
const { i18n, t } = useTranslation();
|
|
14
14
|
const { code: locale } = useLocale();
|
|
15
15
|
const { closeModal } = useModal();
|
|
16
|
-
const { id, collectionSlug,
|
|
16
|
+
const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo();
|
|
17
17
|
const { getFormState } = useServerFunctions();
|
|
18
18
|
const [initialState, setInitialState] = useState({});
|
|
19
19
|
const { componentMap } = fieldProps;
|
|
@@ -42,7 +42,9 @@ export const UploadDrawer = (props)=>{
|
|
|
42
42
|
id,
|
|
43
43
|
collectionSlug,
|
|
44
44
|
data,
|
|
45
|
-
docPermissions
|
|
45
|
+
docPermissions: {
|
|
46
|
+
fields: true
|
|
47
|
+
},
|
|
46
48
|
docPreferences: await getDocPreferences(),
|
|
47
49
|
globalSlug,
|
|
48
50
|
operation: 'update',
|
|
@@ -63,14 +65,15 @@ export const UploadDrawer = (props)=>{
|
|
|
63
65
|
relatedCollection.slug,
|
|
64
66
|
getFormState,
|
|
65
67
|
globalSlug,
|
|
66
|
-
getDocPreferences
|
|
67
|
-
docPermissions
|
|
68
|
+
getDocPreferences
|
|
68
69
|
]);
|
|
69
70
|
const onChange = useCallback(async ({ formState: prevFormState })=>{
|
|
70
71
|
const { state } = await getFormState({
|
|
71
72
|
id,
|
|
72
73
|
collectionSlug,
|
|
73
|
-
docPermissions
|
|
74
|
+
docPermissions: {
|
|
75
|
+
fields: true
|
|
76
|
+
},
|
|
74
77
|
docPreferences: await getDocPreferences(),
|
|
75
78
|
formState: prevFormState,
|
|
76
79
|
globalSlug,
|
|
@@ -82,7 +85,6 @@ export const UploadDrawer = (props)=>{
|
|
|
82
85
|
getFormState,
|
|
83
86
|
id,
|
|
84
87
|
collectionSlug,
|
|
85
|
-
docPermissions,
|
|
86
88
|
getDocPreferences,
|
|
87
89
|
globalSlug,
|
|
88
90
|
schemaPath,
|
|
@@ -110,7 +112,7 @@ export const UploadDrawer = (props)=>{
|
|
|
110
112
|
parentIndexPath: "",
|
|
111
113
|
parentPath: "",
|
|
112
114
|
parentSchemaPath: "",
|
|
113
|
-
permissions:
|
|
115
|
+
permissions: true,
|
|
114
116
|
readOnly: false
|
|
115
117
|
}),
|
|
116
118
|
/*#__PURE__*/ _jsx(FormSubmit, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/field/elements/upload/Element/UploadDrawer/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormProps } from '@payloadcms/ui'\nimport type { ClientCollectionConfig } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Drawer,\n EditDepthProvider,\n Form,\n FormSubmit,\n RenderFields,\n useConfig,\n useDocumentInfo,\n useLocale,\n useModal,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { deepCopyObject } from 'payload/shared'\nimport React, { useCallback, useEffect, useState } from 'react'\nimport { Transforms } from 'slate'\nimport { ReactEditor, useSlateStatic } from 'slate-react'\n\nimport type { LoadedSlateFieldProps } from '../../../../types.js'\nimport type { UploadElementType } from '../../types.js'\n\nimport { uploadFieldsSchemaPath } from '../../shared.js'\n\nexport const UploadDrawer: React.FC<{\n readonly drawerSlug: string\n readonly element: UploadElementType\n readonly fieldProps: LoadedSlateFieldProps\n readonly relatedCollection: ClientCollectionConfig\n readonly schemaPath: string\n}> = (props) => {\n const editor = useSlateStatic()\n\n const { drawerSlug, element, fieldProps, relatedCollection, schemaPath } = props\n\n const { i18n, t } = useTranslation()\n const { code: locale } = useLocale()\n const { closeModal } = useModal()\n const { id, collectionSlug,
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/field/elements/upload/Element/UploadDrawer/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormProps } from '@payloadcms/ui'\nimport type { ClientCollectionConfig } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Drawer,\n EditDepthProvider,\n Form,\n FormSubmit,\n RenderFields,\n useConfig,\n useDocumentInfo,\n useLocale,\n useModal,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { deepCopyObject } from 'payload/shared'\nimport React, { useCallback, useEffect, useState } from 'react'\nimport { Transforms } from 'slate'\nimport { ReactEditor, useSlateStatic } from 'slate-react'\n\nimport type { LoadedSlateFieldProps } from '../../../../types.js'\nimport type { UploadElementType } from '../../types.js'\n\nimport { uploadFieldsSchemaPath } from '../../shared.js'\n\nexport const UploadDrawer: React.FC<{\n readonly drawerSlug: string\n readonly element: UploadElementType\n readonly fieldProps: LoadedSlateFieldProps\n readonly relatedCollection: ClientCollectionConfig\n readonly schemaPath: string\n}> = (props) => {\n const editor = useSlateStatic()\n\n const { drawerSlug, element, fieldProps, relatedCollection, schemaPath } = props\n\n const { i18n, t } = useTranslation()\n const { code: locale } = useLocale()\n const { closeModal } = useModal()\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n\n const { getFormState } = useServerFunctions()\n\n const [initialState, setInitialState] = useState({})\n const { componentMap } = fieldProps\n\n const relatedFieldSchemaPath = `${uploadFieldsSchemaPath}.${relatedCollection.slug}`\n const fields = componentMap[relatedFieldSchemaPath]\n\n const { config } = useConfig()\n\n const handleUpdateEditData = useCallback(\n (_, data) => {\n const newNode = {\n fields: data,\n }\n\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.setNodes(editor, newNode, { at: elementPath })\n closeModal(drawerSlug)\n },\n [closeModal, editor, element, drawerSlug],\n )\n\n useEffect(() => {\n const data = deepCopyObject(element?.fields || {})\n\n const awaitInitialState = async () => {\n const { state } = await getFormState({\n id,\n collectionSlug,\n data,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n globalSlug,\n operation: 'update',\n renderAllFields: true,\n schemaPath: `${schemaPath}.${uploadFieldsSchemaPath}.${relatedCollection.slug}`,\n })\n\n setInitialState(state)\n }\n\n void awaitInitialState()\n }, [\n config,\n element?.fields,\n locale,\n t,\n collectionSlug,\n id,\n schemaPath,\n relatedCollection.slug,\n getFormState,\n globalSlug,\n getDocPreferences,\n ])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n formState: prevFormState,\n globalSlug,\n operation: 'update',\n schemaPath: `${schemaPath}.${uploadFieldsSchemaPath}.${relatedCollection.slug}`,\n })\n\n return state\n },\n\n [\n getFormState,\n id,\n collectionSlug,\n getDocPreferences,\n globalSlug,\n schemaPath,\n relatedCollection.slug,\n ],\n )\n\n return (\n <EditDepthProvider>\n <Drawer\n slug={drawerSlug}\n title={t('general:editLabel', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n >\n <Form\n beforeSubmit={[onChange]}\n disableValidationOnSubmit\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleUpdateEditData}\n >\n <RenderFields\n fields={Array.isArray(fields) ? fields : []}\n parentIndexPath=\"\"\n parentPath=\"\"\n parentSchemaPath=\"\"\n permissions={true}\n readOnly={false}\n />\n <FormSubmit>{t('fields:saveChanges')}</FormSubmit>\n </Form>\n </Drawer>\n </EditDepthProvider>\n )\n}\n"],"names":["getTranslation","Drawer","EditDepthProvider","Form","FormSubmit","RenderFields","useConfig","useDocumentInfo","useLocale","useModal","useServerFunctions","useTranslation","deepCopyObject","React","useCallback","useEffect","useState","Transforms","ReactEditor","useSlateStatic","uploadFieldsSchemaPath","UploadDrawer","props","editor","drawerSlug","element","fieldProps","relatedCollection","schemaPath","i18n","t","code","locale","closeModal","id","collectionSlug","getDocPreferences","globalSlug","getFormState","initialState","setInitialState","componentMap","relatedFieldSchemaPath","slug","fields","config","handleUpdateEditData","_","data","newNode","elementPath","findPath","setNodes","at","awaitInitialState","state","docPermissions","docPreferences","operation","renderAllFields","onChange","formState","prevFormState","title","label","labels","singular","beforeSubmit","disableValidationOnSubmit","onSubmit","Array","isArray","parentIndexPath","parentPath","parentSchemaPath","permissions","readOnly"],"mappings":"AAAA;;AAKA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,iBAAiB,EACjBC,IAAI,EACJC,UAAU,EACVC,YAAY,EACZC,SAAS,EACTC,eAAe,EACfC,SAAS,EACTC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B,iBAAgB;wBAChBC,YAAW;wBACXC,kBAAiB;wBACjBC,aAAa;wBACbC,UAAU;;kCAEZ,KAACxE;kCAAY0B,EAAE;;;;;;AAKzB,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/richtext-slate",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0-canary.030d28e",
|
|
4
4
|
"description": "The officially supported Slate richtext adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -46,20 +46,20 @@
|
|
|
46
46
|
"slate-history": "0.86.0",
|
|
47
47
|
"slate-hyperscript": "0.81.3",
|
|
48
48
|
"slate-react": "0.92.0",
|
|
49
|
-
"@payloadcms/ui": "3.
|
|
50
|
-
"@payloadcms/translations": "3.
|
|
49
|
+
"@payloadcms/ui": "3.18.0-canary.030d28e",
|
|
50
|
+
"@payloadcms/translations": "3.18.0-canary.030d28e"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/is-hotkey": "^0.1.10",
|
|
54
54
|
"@types/node": "22.5.4",
|
|
55
55
|
"@types/react": "19.0.1",
|
|
56
56
|
"@types/react-dom": "19.0.1",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
57
|
+
"@payloadcms/eslint-config": "3.9.0",
|
|
58
|
+
"payload": "3.18.0-canary.030d28e"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
62
|
-
"payload": "3.
|
|
62
|
+
"payload": "3.18.0-canary.030d28e"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": "^18.20.2 || >=20.9.0"
|