@payloadcms/richtext-slate 3.24.0 → 3.25.0-canary.36940b2
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/relationship/Button/index.d.ts.map +1 -1
- package/dist/field/elements/relationship/Button/index.js +2 -2
- package/dist/field/elements/relationship/Button/index.js.map +1 -1
- package/dist/field/elements/relationship/Element/index.d.ts.map +1 -1
- package/dist/field/elements/relationship/Element/index.js +2 -2
- package/dist/field/elements/relationship/Element/index.js.map +1 -1
- package/dist/field/elements/upload/Button/index.d.ts.map +1 -1
- package/dist/field/elements/upload/Button/index.js +2 -2
- package/dist/field/elements/upload/Button/index.js.map +1 -1
- package/dist/field/elements/upload/Element/index.d.ts.map +1 -1
- package/dist/field/elements/upload/Element/index.js +3 -3
- package/dist/field/elements/upload/Element/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/relationship/Button/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/relationship/Button/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA0C,MAAM,OAAO,CAAA;AAO9D,OAAO,cAAc,CAAA;AAmBrB,KAAK,KAAK,GAAG;IACX,sBAAsB,EAAE,MAAM,EAAE,CAAA;IAChC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AA2CD,eAAO,MAAM,kBAAkB,UAAW,KAAK,KAAG,KAAK,CAAC,SAMvD,CAAA"}
|
|
@@ -27,8 +27,8 @@ const insertRelationship = (editor, { relationTo, value })=>{
|
|
|
27
27
|
const RelationshipButtonComponent = ({ enabledCollectionSlugs })=>{
|
|
28
28
|
const { t } = useTranslation();
|
|
29
29
|
const editor = useSlate();
|
|
30
|
-
const [selectedCollectionSlug
|
|
31
|
-
const [ListDrawer, ListDrawerToggler, { closeDrawer
|
|
30
|
+
const [selectedCollectionSlug] = useState(()=>enabledCollectionSlugs[0]);
|
|
31
|
+
const [ListDrawer, ListDrawerToggler, { closeDrawer }] = useListDrawer({
|
|
32
32
|
collectionSlugs: enabledCollectionSlugs,
|
|
33
33
|
selectedCollection: selectedCollectionSlug
|
|
34
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/elements/relationship/Button/index.tsx"],"sourcesContent":["'use client'\n\nimport { useListDrawer, useTranslation } from '@payloadcms/ui'\nimport React, { Fragment, useCallback,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/elements/relationship/Button/index.tsx"],"sourcesContent":["'use client'\nimport type { ListDrawerProps } from '@payloadcms/ui'\n\nimport { useListDrawer, useTranslation } from '@payloadcms/ui'\nimport React, { Fragment, useCallback, useState } from 'react'\nimport { ReactEditor, useSlate } from 'slate-react'\n\nimport { RelationshipIcon } from '../../../icons/Relationship/index.js'\nimport { ElementButton } from '../../Button.js'\nimport { EnabledRelationshipsCondition } from '../../EnabledRelationshipsCondition.js'\nimport { injectVoidElement } from '../../injectVoid.js'\nimport './index.scss'\n\nconst baseClass = 'relationship-rich-text-button'\n\nconst insertRelationship = (editor, { relationTo, value }) => {\n const text = { text: ' ' }\n\n const relationship = {\n type: 'relationship',\n children: [text],\n relationTo,\n value,\n }\n\n injectVoidElement(editor, relationship)\n\n ReactEditor.focus(editor)\n}\n\ntype Props = {\n enabledCollectionSlugs: string[]\n path: string\n}\nconst RelationshipButtonComponent: React.FC<Props> = ({ enabledCollectionSlugs }) => {\n const { t } = useTranslation()\n const editor = useSlate()\n const [selectedCollectionSlug] = useState(() => enabledCollectionSlugs[0])\n const [ListDrawer, ListDrawerToggler, { closeDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n selectedCollection: selectedCollectionSlug,\n })\n\n const onSelect = useCallback<NonNullable<ListDrawerProps['onSelect']>>(\n ({ collectionSlug, docID }) => {\n insertRelationship(editor, {\n relationTo: collectionSlug,\n value: {\n id: docID,\n },\n })\n closeDrawer()\n },\n [editor, closeDrawer],\n )\n\n return (\n <Fragment>\n <ListDrawerToggler>\n <ElementButton\n className={baseClass}\n el=\"div\"\n format=\"relationship\"\n onClick={() => {\n // do nothing\n }}\n tooltip={t('fields:addRelationship')}\n >\n <RelationshipIcon />\n </ElementButton>\n </ListDrawerToggler>\n <ListDrawer onSelect={onSelect} />\n </Fragment>\n )\n}\n\nexport const RelationshipButton = (props: Props): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props}>\n <RelationshipButtonComponent {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["useListDrawer","useTranslation","React","Fragment","useCallback","useState","ReactEditor","useSlate","RelationshipIcon","ElementButton","EnabledRelationshipsCondition","injectVoidElement","baseClass","insertRelationship","editor","relationTo","value","text","relationship","type","children","focus","RelationshipButtonComponent","enabledCollectionSlugs","t","selectedCollectionSlug","ListDrawer","ListDrawerToggler","closeDrawer","collectionSlugs","selectedCollection","onSelect","collectionSlug","docID","id","className","el","format","onClick","tooltip","RelationshipButton","props"],"mappings":"AAAA;;AAGA,SAASA,aAAa,EAAEC,cAAc,QAAQ,iBAAgB;AAC9D,OAAOC,SAASC,QAAQ,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,QAAO;AAC9D,SAASC,WAAW,EAAEC,QAAQ,QAAQ,cAAa;AAEnD,SAASC,gBAAgB,QAAQ,uCAAsC;AACvE,SAASC,aAAa,QAAQ,kBAAiB;AAC/C,SAASC,6BAA6B,QAAQ,yCAAwC;AACtF,SAASC,iBAAiB,QAAQ,sBAAqB;AACvD,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,MAAMC,qBAAqB,CAACC,QAAQ,EAAEC,UAAU,EAAEC,KAAK,EAAE;IACvD,MAAMC,OAAO;QAAEA,MAAM;IAAI;IAEzB,MAAMC,eAAe;QACnBC,MAAM;QACNC,UAAU;YAACH;SAAK;QAChBF;QACAC;IACF;IAEAL,kBAAkBG,QAAQI;IAE1BZ,YAAYe,KAAK,CAACP;AACpB;AAMA,MAAMQ,8BAA+C,CAAC,EAAEC,sBAAsB,EAAE;IAC9E,MAAM,EAAEC,CAAC,EAAE,GAAGvB;IACd,MAAMa,SAASP;IACf,MAAM,CAACkB,uBAAuB,GAAGpB,SAAS,IAAMkB,sBAAsB,CAAC,EAAE;IACzE,MAAM,CAACG,YAAYC,mBAAmB,EAAEC,WAAW,EAAE,CAAC,GAAG5B,cAAc;QACrE6B,iBAAiBN;QACjBO,oBAAoBL;IACtB;IAEA,MAAMM,WAAW3B,YACf,CAAC,EAAE4B,cAAc,EAAEC,KAAK,EAAE;QACxBpB,mBAAmBC,QAAQ;YACzBC,YAAYiB;YACZhB,OAAO;gBACLkB,IAAID;YACN;QACF;QACAL;IACF,GACA;QAACd;QAAQc;KAAY;IAGvB,qBACE,MAACzB;;0BACC,KAACwB;0BACC,cAAA,KAAClB;oBACC0B,WAAWvB;oBACXwB,IAAG;oBACHC,QAAO;oBACPC,SAAS;oBACP,aAAa;oBACf;oBACAC,SAASf,EAAE;8BAEX,cAAA,KAAChB;;;0BAGL,KAACkB;gBAAWK,UAAUA;;;;AAG5B;AAEA,OAAO,MAAMS,qBAAqB,CAACC;IACjC,qBACE,KAAC/B;QAA+B,GAAG+B,KAAK;kBACtC,cAAA,KAACnB;YAA6B,GAAGmB,KAAK;;;AAG5C,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/relationship/Element/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/relationship/Element/index.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA4C,MAAM,OAAO,CAAA;AAQhE,OAAO,cAAc,CAAA;AA2KrB,eAAO,MAAM,mBAAmB,UAAW,GAAG,KAAG,KAAK,CAAC,SAMtD,CAAA"}
|
|
@@ -74,7 +74,7 @@ const RelationshipElementComponent = ()=>{
|
|
|
74
74
|
setParams,
|
|
75
75
|
closeDrawer
|
|
76
76
|
]);
|
|
77
|
-
const swapRelationship =
|
|
77
|
+
const swapRelationship = useCallback(({ collectionSlug, doc })=>{
|
|
78
78
|
const elementPath = ReactEditor.findPath(editor, element);
|
|
79
79
|
Transforms.setNodes(editor, {
|
|
80
80
|
type: 'relationship',
|
|
@@ -85,7 +85,7 @@ const RelationshipElementComponent = ()=>{
|
|
|
85
85
|
],
|
|
86
86
|
relationTo: collectionSlug,
|
|
87
87
|
value: {
|
|
88
|
-
id:
|
|
88
|
+
id: doc.id
|
|
89
89
|
}
|
|
90
90
|
}, {
|
|
91
91
|
at: elementPath
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/elements/relationship/Element/index.tsx"],"sourcesContent":["'use client'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n useConfig,\n useDocumentDrawer,\n useListDrawer,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback, useReducer, useState } from 'react'\nimport { Transforms } from 'slate'\nimport { ReactEditor, useFocused, useSelected, useSlateStatic } from 'slate-react'\n\nimport type { RelationshipElementType } from '../types.js'\n\nimport { useElement } from '../../../providers/ElementProvider.js'\nimport { EnabledRelationshipsCondition } from '../../EnabledRelationshipsCondition.js'\nimport './index.scss'\n\nconst baseClass = 'rich-text-relationship'\n\nconst initialParams = {\n depth: 0,\n}\n\nconst RelationshipElementComponent: React.FC = () => {\n const {\n attributes,\n children,\n element,\n element: { relationTo, value },\n fieldProps,\n } = useElement<RelationshipElementType>()\n\n const {\n config: {\n collections,\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n const [enabledCollectionSlugs] = useState(() =>\n collections\n .filter(({ admin: { enableRichTextRelationship } }) => enableRichTextRelationship)\n .map(({ slug }) => slug),\n )\n const [relatedCollection, setRelatedCollection] = useState(() =>\n getEntityConfig({ collectionSlug: relationTo }),\n )\n\n const selected = useSelected()\n const focused = useFocused()\n const { i18n, t } = useTranslation()\n const editor = useSlateStatic()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value?.id}`,\n { initialParams },\n )\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id: value?.id,\n collectionSlug: relatedCollection.slug,\n })\n\n const [ListDrawer, ListDrawerToggler, { closeDrawer: closeListDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n selectedCollection: relatedCollection.slug,\n })\n\n const removeRelationship = useCallback(() => {\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.removeNodes(editor, { at: elementPath })\n }, [editor, element])\n\n const updateRelationship = React.useCallback(\n ({ doc }) => {\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.setNodes(\n editor,\n {\n type: 'relationship',\n children: [{ text: ' ' }],\n relationTo: relatedCollection.slug,\n value: { id: doc.id },\n },\n { at: elementPath },\n )\n\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n closeDrawer()\n dispatchCacheBust()\n },\n [editor, element, relatedCollection, cacheBust, setParams, closeDrawer],\n )\n\n const swapRelationship = React.useCallback(\n ({ collectionSlug, docID }) => {\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.setNodes(\n editor,\n {\n type: 'relationship',\n children: [{ text: ' ' }],\n relationTo: collectionSlug,\n value: { id: docID },\n },\n { at: elementPath },\n )\n\n setRelatedCollection(getEntityConfig({ collectionSlug }))\n\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n closeListDrawer()\n dispatchCacheBust()\n },\n [closeListDrawer, editor, element, cacheBust, setParams, getEntityConfig],\n )\n\n return (\n <div\n className={[baseClass, selected && focused && `${baseClass}--selected`]\n .filter(Boolean)\n .join(' ')}\n contentEditable={false}\n {...attributes}\n >\n <div className={`${baseClass}__wrap`}>\n <p className={`${baseClass}__label`}>\n {t('fields:labelRelationship', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n </p>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <p className={`${baseClass}__title`}>\n {data[relatedCollection?.admin?.useAsTitle || 'id']}\n </p>\n </DocumentDrawerToggler>\n </div>\n <div className={`${baseClass}__actions`}>\n <ListDrawerToggler\n className={`${baseClass}__list-drawer-toggler`}\n disabled={fieldProps?.field?.admin?.readOnly}\n >\n <Button\n buttonStyle=\"icon-label\"\n disabled={fieldProps?.field?.admin?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n // do nothing\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n </ListDrawerToggler>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={fieldProps?.field?.admin?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeRelationship()\n }}\n round\n tooltip={t('fields:removeRelationship')}\n />\n </div>\n {value?.id && <DocumentDrawer onSave={updateRelationship} />}\n <ListDrawer onSelect={swapRelationship} />\n {children}\n </div>\n )\n}\n\nexport const RelationshipElement = (props: any): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props}>\n <RelationshipElementComponent {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["getTranslation","Button","useConfig","useDocumentDrawer","useListDrawer","usePayloadAPI","useTranslation","React","useCallback","useReducer","useState","Transforms","ReactEditor","useFocused","useSelected","useSlateStatic","useElement","EnabledRelationshipsCondition","baseClass","initialParams","depth","RelationshipElementComponent","attributes","children","element","relationTo","value","fieldProps","config","collections","routes","api","serverURL","getEntityConfig","enabledCollectionSlugs","filter","admin","enableRichTextRelationship","map","slug","relatedCollection","setRelatedCollection","collectionSlug","selected","focused","i18n","t","editor","cacheBust","dispatchCacheBust","state","data","setParams","id","DocumentDrawer","DocumentDrawerToggler","closeDrawer","ListDrawer","ListDrawerToggler","closeListDrawer","collectionSlugs","selectedCollection","removeRelationship","elementPath","findPath","removeNodes","at","updateRelationship","doc","setNodes","type","text","swapRelationship","docID","div","className","Boolean","join","contentEditable","p","label","labels","singular","useAsTitle","disabled","field","readOnly","buttonStyle","el","icon","onClick","round","tooltip","e","preventDefault","onSave","onSelect","RelationshipElement","props"],"mappings":"AAAA;;AAEA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,SAAS,EACTC,iBAAiB,EACjBC,aAAa,EACbC,aAAa,EACbC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,QAAO;AAChE,SAASC,UAAU,QAAQ,QAAO;AAClC,SAASC,WAAW,EAAEC,UAAU,EAAEC,WAAW,EAAEC,cAAc,QAAQ,cAAa;AAIlF,SAASC,UAAU,QAAQ,wCAAuC;AAClE,SAASC,6BAA6B,QAAQ,yCAAwC;AACtF,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,MAAMC,gBAAgB;IACpBC,OAAO;AACT;AAEA,MAAMC,+BAAyC;IAC7C,MAAM,EACJC,UAAU,EACVC,QAAQ,EACRC,OAAO,EACPA,SAAS,EAAEC,UAAU,EAAEC,KAAK,EAAE,EAC9BC,UAAU,EACX,GAAGX;IAEJ,MAAM,EACJY,QAAQ,EACNC,WAAW,EACXC,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,EACDC,eAAe,EAChB,GAAG/B;IACJ,MAAM,CAACgC,uBAAuB,GAAGxB,SAAS,IACxCmB,YACGM,MAAM,CAAC,CAAC,EAAEC,OAAO,EAAEC,0BAA0B,EAAE,EAAE,GAAKA,4BACtDC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA;IAEvB,MAAM,CAACC,mBAAmBC,qBAAqB,GAAG/B,SAA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KAACwC;wBACCiB,WAAW,GAAGzD,UAAU,qBAAqB,CAAC;wBAC9CkE,UAAUzD,YAAY0D,OAAOjD,OAAOkD;kCAEpC,cAAA,KAACrF;4BACCsF,aAAY;4BACZH,UAAUzD,YAAY0D,OAAOjD,OAAOkD;4BACpCE,IAAG;4BACHC,MAAK;4BACLC,SAAS;4BACP,aAAa;4BACf;4BACAC,KAAK;4BACLC,SAAS9C,EAAE;;;kCAGf,KAAC7C;wBACCsF,aAAY;wBACZZ,WAAW,GAAGzD,UAAU,cAAc,CAAC;wBACvCkE,UAAUzD,YAAY0D,OAAOjD,OAAOkD;wBACpCG,MAAK;wBACLC,SAAS,CAACG;4BACRA,EAAEC,cAAc;4BAChBhC;wBACF;wBACA6B,KAAK;wBACLC,SAAS9C,EAAE;;;;YAGdpB,OAAO2B,oBAAM,KAACC;gBAAeyC,QAAQ5B;;0BACtC,KAACV;gBAAWuC,UAAUxB;;YACrBjD;;;AAGP;AAEA,OAAO,MAAM0E,sBAAsB,CAACC;IAClC,qBACE,KAACjF;QAA+B,GAAGiF,KAAK;kBACtC,cAAA,KAAC7E;YAA8B,GAAG6E,KAAK;;;AAG7C,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/elements/relationship/Element/index.tsx"],"sourcesContent":["'use client'\n\nimport type { ListDrawerProps } from '@payloadcms/ui'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n useConfig,\n useDocumentDrawer,\n useListDrawer,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback, useReducer, useState } from 'react'\nimport { Transforms } from 'slate'\nimport { ReactEditor, useFocused, useSelected, useSlateStatic } from 'slate-react'\n\nimport type { RelationshipElementType } from '../types.js'\n\nimport { useElement } from '../../../providers/ElementProvider.js'\nimport { EnabledRelationshipsCondition } from '../../EnabledRelationshipsCondition.js'\nimport './index.scss'\n\nconst baseClass = 'rich-text-relationship'\n\nconst initialParams = {\n depth: 0,\n}\n\nconst RelationshipElementComponent: React.FC = () => {\n const {\n attributes,\n children,\n element,\n element: { relationTo, value },\n fieldProps,\n } = useElement<RelationshipElementType>()\n\n const {\n config: {\n collections,\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n const [enabledCollectionSlugs] = useState(() =>\n collections\n .filter(({ admin: { enableRichTextRelationship } }) => enableRichTextRelationship)\n .map(({ slug }) => slug),\n )\n const [relatedCollection, setRelatedCollection] = useState(() =>\n getEntityConfig({ collectionSlug: relationTo }),\n )\n\n const selected = useSelected()\n const focused = useFocused()\n const { i18n, t } = useTranslation()\n const editor = useSlateStatic()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value?.id}`,\n { initialParams },\n )\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id: value?.id,\n collectionSlug: relatedCollection.slug,\n })\n\n const [ListDrawer, ListDrawerToggler, { closeDrawer: closeListDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n selectedCollection: relatedCollection.slug,\n })\n\n const removeRelationship = useCallback(() => {\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.removeNodes(editor, { at: elementPath })\n }, [editor, element])\n\n const updateRelationship = React.useCallback(\n ({ doc }) => {\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.setNodes(\n editor,\n {\n type: 'relationship',\n children: [{ text: ' ' }],\n relationTo: relatedCollection.slug,\n value: { id: doc.id },\n },\n { at: elementPath },\n )\n\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n closeDrawer()\n dispatchCacheBust()\n },\n [editor, element, relatedCollection, cacheBust, setParams, closeDrawer],\n )\n\n const swapRelationship = useCallback<NonNullable<ListDrawerProps['onSelect']>>(\n ({ collectionSlug, doc }) => {\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.setNodes(\n editor,\n {\n type: 'relationship',\n children: [{ text: ' ' }],\n relationTo: collectionSlug,\n value: { id: doc.id },\n },\n { at: elementPath },\n )\n\n setRelatedCollection(getEntityConfig({ collectionSlug }))\n\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n closeListDrawer()\n dispatchCacheBust()\n },\n [closeListDrawer, editor, element, cacheBust, setParams, getEntityConfig],\n )\n\n return (\n <div\n className={[baseClass, selected && focused && `${baseClass}--selected`]\n .filter(Boolean)\n .join(' ')}\n contentEditable={false}\n {...attributes}\n >\n <div className={`${baseClass}__wrap`}>\n <p className={`${baseClass}__label`}>\n {t('fields:labelRelationship', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n </p>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <p className={`${baseClass}__title`}>\n {data[relatedCollection?.admin?.useAsTitle || 'id']}\n </p>\n </DocumentDrawerToggler>\n </div>\n <div className={`${baseClass}__actions`}>\n <ListDrawerToggler\n className={`${baseClass}__list-drawer-toggler`}\n disabled={fieldProps?.field?.admin?.readOnly}\n >\n <Button\n buttonStyle=\"icon-label\"\n disabled={fieldProps?.field?.admin?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n // do nothing\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n </ListDrawerToggler>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={fieldProps?.field?.admin?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeRelationship()\n }}\n round\n tooltip={t('fields:removeRelationship')}\n />\n </div>\n {value?.id && <DocumentDrawer onSave={updateRelationship} />}\n <ListDrawer onSelect={swapRelationship} />\n {children}\n </div>\n )\n}\n\nexport const RelationshipElement = (props: any): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props}>\n <RelationshipElementComponent {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["getTranslation","Button","useConfig","useDocumentDrawer","useListDrawer","usePayloadAPI","useTranslation","React","useCallback","useReducer","useState","Transforms","ReactEditor","useFocused","useSelected","useSlateStatic","useElement","EnabledRelationshipsCondition","baseClass","initialParams","depth","RelationshipElementComponent","attributes","children","element","relationTo","value","fieldProps","config","collections","routes","api","serverURL","getEntityConfig","enabledCollectionSlugs","filter","admin","enableRichTextRelationship","map","slug","relatedCollection","setRelatedCollection","collectionSlug","selected","focused","i18n","t","editor","cacheBust","dispatchCacheBust","state","data","setParams","id","DocumentDrawer","DocumentDrawerToggler","closeDrawer","ListDrawer","ListDrawerToggler","closeListDrawer","collectionSlugs","selectedCollection","removeRelationship","elementPath","findPath","removeNodes","at","updateRelationship","doc","setNodes","type","text","swapRelationship","div","className","Boolean","join","contentEditable","p","label","labels","singular","useAsTitle","disabled","field","readOnly","buttonStyle","el","icon","onClick","round","tooltip","e","preventDefault","onSave","onSelect","RelationshipElement","props"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,SAAS,EACTC,iBAAiB,EACjBC,aAAa,EACbC,aAAa,EACbC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,QAAO;AAChE,SAASC,UAAU,QAAQ,QAAO;AAClC,SAASC,WAAW,EAAEC,UAAU,EAAEC,WAAW,EAAEC,cAAc,QAAQ,cAAa;AAIlF,SAASC,UAAU,QAAQ,wCAAuC;AAClE,SAASC,6BAA6B,QAAQ,yCAAwC;AACtF,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,MAAMC,gBAAgB;IACpBC,OAAO;AACT;AAEA,MAAMC,+BAAyC;IAC7C,MAAM,EACJC,UAAU,EACVC,QAAQ,EACRC,OAAO,EACPA,SAAS,EAAEC,UAAU,EAAEC,KAAK,EAAE,EAC9BC,UAAU,EACX,GAAGX;IAEJ,MAAM,EACJY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B;4BAC7BiC,OAAO/E,eAAewC,kBAAkBwC,MAAM,CAACC,QAAQ,EAAEpC;wBAC3D;;kCAEF,KAACU;wBAAsBmB,WAAW,GAAGxD,UAAU,oBAAoB,CAAC;kCAClE,cAAA,KAAC4D;4BAAEJ,WAAW,GAAGxD,UAAU,OAAO,CAAC;sCAChCiC,IAAI,CAACX,mBAAmBJ,OAAO8C,cAAc,KAAK;;;;;0BAIzD,MAACT;gBAAIC,WAAW,GAAGxD,UAAU,SAAS,CAAC;;kCACrC,KAACwC;wBACCgB,WAAW,GAAGxD,UAAU,qBAAqB,CAAC;wBAC9CiE,UAAUxD,YAAYyD,OAAOhD,OAAOiD;kCAEpC,cAAA,KAACpF;4BACCqF,aAAY;4BACZH,UAAUxD,YAAYyD,OAAOhD,OAAOiD;4BACpCE,IAAG;4BACHC,MAAK;4BACLC,SAAS;4BACP,aAAa;4BACf;4BACAC,KAAK;4BACLC,SAAS7C,EAAE;;;kCAGf,KAAC7C;wBACCqF,aAAY;wBACZZ,WAAW,GAAGxD,UAAU,cAAc,CAAC;wBACvCiE,UAAUxD,YAAYyD,OAAOhD,OAAOiD;wBACpCG,MAAK;wBACLC,SAAS,CAACG;4BACRA,EAAEC,cAAc;4BAChB/B;wBACF;wBACA4B,KAAK;wBACLC,SAAS7C,EAAE;;;;YAGdpB,OAAO2B,oBAAM,KAACC;gBAAewC,QAAQ3B;;0BACtC,KAACV;gBAAWsC,UAAUvB;;YACrBjD;;;AAGP;AAEA,OAAO,MAAMyE,sBAAsB,CAACC;IAClC,qBACE,KAAChF;QAA+B,GAAGgF,KAAK;kBACtC,cAAA,KAAC5E;YAA8B,GAAG4E,KAAK;;;AAG7C,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/upload/Button/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/upload/Button/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAgC,MAAM,OAAO,CAAA;AAOpD,OAAO,cAAc,CAAA;AAmBrB,KAAK,WAAW,GAAG;IACjB,sBAAsB,EAAE,MAAM,EAAE,CAAA;IAChC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AA4CD,eAAO,MAAM,mBAAmB,UAAW,WAAW,KAAG,KAAK,CAAC,SAM9D,CAAA"}
|
|
@@ -31,11 +31,11 @@ const UploadButton = ({ enabledCollectionSlugs })=>{
|
|
|
31
31
|
collectionSlugs: enabledCollectionSlugs,
|
|
32
32
|
uploads: true
|
|
33
33
|
});
|
|
34
|
-
const onSelect = useCallback(({ collectionSlug,
|
|
34
|
+
const onSelect = useCallback(({ collectionSlug, doc })=>{
|
|
35
35
|
insertUpload(editor, {
|
|
36
36
|
relationTo: collectionSlug,
|
|
37
37
|
value: {
|
|
38
|
-
id:
|
|
38
|
+
id: doc.id
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
closeDrawer();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/elements/upload/Button/index.tsx"],"sourcesContent":["'use client'\n\nimport { useListDrawer, useTranslation } from '@payloadcms/ui'\nimport React, { Fragment, useCallback } from 'react'\nimport { ReactEditor, useSlate } from 'slate-react'\n\nimport { UploadIcon } from '../../../icons/Upload/index.js'\nimport { ElementButton } from '../../Button.js'\nimport { EnabledRelationshipsCondition } from '../../EnabledRelationshipsCondition.js'\nimport { injectVoidElement } from '../../injectVoid.js'\nimport './index.scss'\n\nconst baseClass = 'upload-rich-text-button'\n\nconst insertUpload = (editor, { relationTo, value }) => {\n const text = { text: ' ' }\n\n const upload = {\n type: 'upload',\n children: [text],\n relationTo,\n value,\n }\n\n injectVoidElement(editor, upload)\n\n ReactEditor.focus(editor)\n}\n\ntype ButtonProps = {\n enabledCollectionSlugs: string[]\n path: string\n}\n\nconst UploadButton: React.FC<ButtonProps> = ({ enabledCollectionSlugs }) => {\n const { t } = useTranslation()\n const editor = useSlate()\n\n const [ListDrawer, ListDrawerToggler, { closeDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n uploads: true,\n })\n\n const onSelect = useCallback(\n ({ collectionSlug,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/elements/upload/Button/index.tsx"],"sourcesContent":["'use client'\n\nimport type { ListDrawerProps } from '@payloadcms/ui'\n\nimport { useListDrawer, useTranslation } from '@payloadcms/ui'\nimport React, { Fragment, useCallback } from 'react'\nimport { ReactEditor, useSlate } from 'slate-react'\n\nimport { UploadIcon } from '../../../icons/Upload/index.js'\nimport { ElementButton } from '../../Button.js'\nimport { EnabledRelationshipsCondition } from '../../EnabledRelationshipsCondition.js'\nimport { injectVoidElement } from '../../injectVoid.js'\nimport './index.scss'\n\nconst baseClass = 'upload-rich-text-button'\n\nconst insertUpload = (editor, { relationTo, value }) => {\n const text = { text: ' ' }\n\n const upload = {\n type: 'upload',\n children: [text],\n relationTo,\n value,\n }\n\n injectVoidElement(editor, upload)\n\n ReactEditor.focus(editor)\n}\n\ntype ButtonProps = {\n enabledCollectionSlugs: string[]\n path: string\n}\n\nconst UploadButton: React.FC<ButtonProps> = ({ enabledCollectionSlugs }) => {\n const { t } = useTranslation()\n const editor = useSlate()\n\n const [ListDrawer, ListDrawerToggler, { closeDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n uploads: true,\n })\n\n const onSelect = useCallback<NonNullable<ListDrawerProps['onSelect']>>(\n ({ collectionSlug, doc }) => {\n insertUpload(editor, {\n relationTo: collectionSlug,\n value: {\n id: doc.id,\n },\n })\n closeDrawer()\n },\n [editor, closeDrawer],\n )\n\n return (\n <Fragment>\n <ListDrawerToggler>\n <ElementButton\n className={baseClass}\n el=\"div\"\n format=\"upload\"\n onClick={() => {\n // do nothing\n }}\n tooltip={t('fields:addUpload')}\n >\n <UploadIcon />\n </ElementButton>\n </ListDrawerToggler>\n <ListDrawer onSelect={onSelect} />\n </Fragment>\n )\n}\n\nexport const UploadElementButton = (props: ButtonProps): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <UploadButton {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["useListDrawer","useTranslation","React","Fragment","useCallback","ReactEditor","useSlate","UploadIcon","ElementButton","EnabledRelationshipsCondition","injectVoidElement","baseClass","insertUpload","editor","relationTo","value","text","upload","type","children","focus","UploadButton","enabledCollectionSlugs","t","ListDrawer","ListDrawerToggler","closeDrawer","collectionSlugs","uploads","onSelect","collectionSlug","doc","id","className","el","format","onClick","tooltip","UploadElementButton","props"],"mappings":"AAAA;;AAIA,SAASA,aAAa,EAAEC,cAAc,QAAQ,iBAAgB;AAC9D,OAAOC,SAASC,QAAQ,EAAEC,WAAW,QAAQ,QAAO;AACpD,SAASC,WAAW,EAAEC,QAAQ,QAAQ,cAAa;AAEnD,SAASC,UAAU,QAAQ,iCAAgC;AAC3D,SAASC,aAAa,QAAQ,kBAAiB;AAC/C,SAASC,6BAA6B,QAAQ,yCAAwC;AACtF,SAASC,iBAAiB,QAAQ,sBAAqB;AACvD,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,MAAMC,eAAe,CAACC,QAAQ,EAAEC,UAAU,EAAEC,KAAK,EAAE;IACjD,MAAMC,OAAO;QAAEA,MAAM;IAAI;IAEzB,MAAMC,SAAS;QACbC,MAAM;QACNC,UAAU;YAACH;SAAK;QAChBF;QACAC;IACF;IAEAL,kBAAkBG,QAAQI;IAE1BZ,YAAYe,KAAK,CAACP;AACpB;AAOA,MAAMQ,eAAsC,CAAC,EAAEC,sBAAsB,EAAE;IACrE,MAAM,EAAEC,CAAC,EAAE,GAAGtB;IACd,MAAMY,SAASP;IAEf,MAAM,CAACkB,YAAYC,mBAAmB,EAAEC,WAAW,EAAE,CAAC,GAAG1B,cAAc;QACrE2B,iBAAiBL;QACjBM,SAAS;IACX;IAEA,MAAMC,WAAWzB,YACf,CAAC,EAAE0B,cAAc,EAAEC,GAAG,EAAE;QACtBnB,aAAaC,QAAQ;YACnBC,YAAYgB;YACZf,OAAO;gBACLiB,IAAID,IAAIC,EAAE;YACZ;QACF;QACAN;IACF,GACA;QAACb;QAAQa;KAAY;IAGvB,qBACE,MAACvB;;0BACC,KAACsB;0BACC,cAAA,KAACjB;oBACCyB,WAAWtB;oBACXuB,IAAG;oBACHC,QAAO;oBACPC,SAAS;oBACP,aAAa;oBACf;oBACAC,SAASd,EAAE;8BAEX,cAAA,KAAChB;;;0BAGL,KAACiB;gBAAWK,UAAUA;;;;AAG5B;AAEA,OAAO,MAAMS,sBAAsB,CAACC;IAClC,qBACE,KAAC9B;QAA+B,GAAG8B,KAAK;QAAEX,OAAO;kBAC/C,cAAA,KAACP;YAAc,GAAGkB,KAAK;;;AAG7B,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/upload/Element/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/elements/upload/Element/index.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAA4C,MAAM,OAAO,CAAA;AAUhE,OAAO,cAAc,CAAA;AAoMrB,eAAO,MAAM,aAAa,UAAW,GAAG,KAAG,KAAK,CAAC,SAMhD,CAAA"}
|
|
@@ -8,8 +8,8 @@ import { ReactEditor, useFocused, useSelected, useSlateStatic } from 'slate-reac
|
|
|
8
8
|
import { useElement } from '../../../providers/ElementProvider.js';
|
|
9
9
|
import { EnabledRelationshipsCondition } from '../../EnabledRelationshipsCondition.js';
|
|
10
10
|
import { uploadFieldsSchemaPath, uploadName } from '../shared.js';
|
|
11
|
-
import './index.scss';
|
|
12
11
|
import { UploadDrawer } from './UploadDrawer/index.js';
|
|
12
|
+
import './index.scss';
|
|
13
13
|
const baseClass = 'rich-text-upload';
|
|
14
14
|
const initialParams = {
|
|
15
15
|
depth: 0
|
|
@@ -70,7 +70,7 @@ const UploadElementComponent = ({ enabledCollectionSlugs })=>{
|
|
|
70
70
|
cacheBust,
|
|
71
71
|
closeDrawer
|
|
72
72
|
]);
|
|
73
|
-
const swapUpload =
|
|
73
|
+
const swapUpload = useCallback(({ collectionSlug, doc })=>{
|
|
74
74
|
const newNode = {
|
|
75
75
|
type: uploadName,
|
|
76
76
|
children: [
|
|
@@ -80,7 +80,7 @@ const UploadElementComponent = ({ enabledCollectionSlugs })=>{
|
|
|
80
80
|
],
|
|
81
81
|
relationTo: collectionSlug,
|
|
82
82
|
value: {
|
|
83
|
-
id:
|
|
83
|
+
id: doc.id
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
const elementPath = ReactEditor.findPath(editor, element);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/elements/upload/Element/index.tsx"],"sourcesContent":["'use client'\n\nimport type { ClientCollectionConfig } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n DrawerToggler,\n File,\n useConfig,\n useDocumentDrawer,\n useDrawerSlug,\n useListDrawer,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback, useReducer, useState } from 'react'\nimport { Transforms } from 'slate'\nimport { ReactEditor, useFocused, useSelected, useSlateStatic } from 'slate-react'\n\nimport type { UploadElementType } from '../types.js'\n\nimport { useElement } from '../../../providers/ElementProvider.js'\nimport { EnabledRelationshipsCondition } from '../../EnabledRelationshipsCondition.js'\nimport { uploadFieldsSchemaPath, uploadName } from '../shared.js'\nimport './index.scss'\nimport { UploadDrawer } from './UploadDrawer/index.js'\n\nconst baseClass = 'rich-text-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nconst UploadElementComponent: React.FC<{ enabledCollectionSlugs?: string[] }> = ({\n enabledCollectionSlugs,\n}) => {\n const {\n attributes,\n children,\n element: { relationTo, value },\n element,\n fieldProps,\n schemaPath,\n } = useElement<UploadElementType>()\n\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection, setRelatedCollection] = useState<ClientCollectionConfig>(() =>\n getEntityConfig({ collectionSlug: relationTo }),\n )\n\n const drawerSlug = useDrawerSlug('upload-drawer')\n\n const [ListDrawer, ListDrawerToggler, { closeDrawer: closeListDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n selectedCollection: relatedCollection.slug,\n })\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id: value?.id,\n collectionSlug: relatedCollection.slug,\n })\n\n const editor = useSlateStatic()\n const selected = useSelected()\n const focused = useFocused()\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value?.id}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.removeNodes(editor, { at: elementPath })\n }, [editor, element])\n\n const updateUpload = useCallback(\n (json) => {\n const { doc } = json\n\n const newNode = {\n fields: doc,\n }\n\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.setNodes(editor, newNode, { at: elementPath })\n\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDrawer()\n },\n [editor, element, setParams, cacheBust, closeDrawer],\n )\n\n const swapUpload = React.useCallback(\n ({ collectionSlug, docID }) => {\n const newNode = {\n type: uploadName,\n children: [{ text: ' ' }],\n relationTo: collectionSlug,\n value: { id: docID },\n }\n\n const elementPath = ReactEditor.findPath(editor, element)\n\n setRelatedCollection(getEntityConfig({ collectionSlug }))\n\n Transforms.setNodes(editor, newNode, { at: elementPath })\n\n dispatchCacheBust()\n closeListDrawer()\n },\n [closeListDrawer, editor, element, getEntityConfig],\n )\n\n const relatedFieldSchemaPath = `${uploadFieldsSchemaPath}.${relatedCollection.slug}`\n const customFieldsMap = fieldProps.componentMap[relatedFieldSchemaPath]\n\n return (\n <div\n className={[baseClass, selected && focused && `${baseClass}--selected`]\n .filter(Boolean)\n .join(' ')}\n contentEditable={false}\n {...attributes}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__topRow`}>\n {/* TODO: migrate to use Thumbnail component */}\n <div className={`${baseClass}__thumbnail`}>\n {thumbnailSRC ? <img alt={data?.filename} src={thumbnailSRC} /> : <File />}\n </div>\n <div className={`${baseClass}__topRowRightPanel`}>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n <div className={`${baseClass}__actions`}>\n {Boolean(customFieldsMap) && (\n <>\n <DrawerToggler\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={fieldProps?.field?.admin?.readOnly}\n slug={drawerSlug}\n >\n <Button\n buttonStyle=\"icon-label\"\n el=\"div\"\n icon=\"edit\"\n onClick={(e) => {\n e.preventDefault()\n }}\n round\n tooltip={t('fields:editRelationship')}\n />\n </DrawerToggler>\n <UploadDrawer\n {...{ drawerSlug, element, fieldProps, relatedCollection, schemaPath }}\n />\n </>\n )}\n <ListDrawerToggler\n className={`${baseClass}__list-drawer-toggler`}\n disabled={fieldProps?.field?.admin?.readOnly}\n >\n <Button\n buttonStyle=\"icon-label\"\n disabled={fieldProps?.field?.admin?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n // do nothing\n }}\n round\n tooltip={t('fields:swapUpload')}\n />\n </ListDrawerToggler>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={fieldProps?.field?.admin?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n tooltip={t('fields:removeUpload')}\n />\n </div>\n </div>\n </div>\n <div className={`${baseClass}__bottomRow`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong>{data?.filename}</strong>\n </DocumentDrawerToggler>\n </div>\n </div>\n {children}\n {value?.id && <DocumentDrawer onSave={updateUpload} />}\n <ListDrawer onSelect={swapUpload} />\n </div>\n )\n}\n\nexport const UploadElement = (props: any): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <UploadElementComponent {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["getTranslation","Button","DrawerToggler","File","useConfig","useDocumentDrawer","useDrawerSlug","useListDrawer","usePayloadAPI","useTranslation","React","useCallback","useReducer","useState","Transforms","ReactEditor","useFocused","useSelected","useSlateStatic","useElement","EnabledRelationshipsCondition","uploadFieldsSchemaPath","uploadName","UploadDrawer","baseClass","initialParams","depth","UploadElementComponent","enabledCollectionSlugs","attributes","children","element","relationTo","value","fieldProps","schemaPath","config","routes","api","serverURL","getEntityConfig","i18n","t","cacheBust","dispatchCacheBust","state","relatedCollection","setRelatedCollection","collectionSlug","drawerSlug","ListDrawer","ListDrawerToggler","closeDrawer","closeListDrawer","collectionSlugs","selectedCollection","slug","DocumentDrawer","DocumentDrawerToggler","id","editor","selected","focused","data","setParams","thumbnailSRC","thumbnailURL","url","removeUpload","elementPath","findPath","removeNodes","at","updateUpload","json","doc","newNode","fields","setNodes","swapUpload","docID","type","text","relatedFieldSchemaPath","customFieldsMap","componentMap","div","className","filter","Boolean","join","contentEditable","img","alt","filename","src","labels","singular","disabled","field","admin","readOnly","buttonStyle","el","icon","onClick","e","preventDefault","round","tooltip","strong","onSave","onSelect","UploadElement","props","uploads"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,aAAa,EACbC,IAAI,EACJC,SAAS,EACTC,iBAAiB,EACjBC,aAAa,EACbC,aAAa,EACbC,aAAa,EACbC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,QAA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OC;0DAEpC,cAAA,KAACpG;oDACCqG,aAAY;oDACZJ,UAAUhE,YAAYiE,OAAOC,OAAOC;oDACpCE,IAAG;oDACHC,MAAK;oDACLC,SAAS;oDACP,aAAa;oDACf;oDACAG,KAAK;oDACLC,SAASnE,EAAE;;;0DAGf,KAACzC;gDACCqG,aAAY;gDACZf,WAAW,GAAG/D,UAAU,cAAc,CAAC;gDACvC0E,UAAUhE,YAAYiE,OAAOC,OAAOC;gDACpCG,MAAK;gDACLC,SAAS,CAACC;oDACRA,EAAEC,cAAc;oDAChBvC;gDACF;gDACAwC,KAAK;gDACLC,SAASnE,EAAE;;;;;;;;kCAKnB,KAAC4C;wBAAIC,WAAW,GAAG/D,UAAU,WAAW,CAAC;kCACvC,cAAA,KAACkC;4BAAsB6B,WAAW,GAAG/D,UAAU,oBAAoB,CAAC;sCAClE,cAAA,KAACsF;0CAAQ/C,MAAM+B;;;;;;YAIpBhE;YACAG,OAAO0B,oBAAM,KAACF;gBAAesD,QAAQtC;;0BACtC,KAACvB;gBAAW8D,UAAUjC;;;;AAG5B;AAEA,OAAO,MAAMkC,gBAAgB,CAACC;IAC5B,qBACE,KAAC9F;QAA+B,GAAG8F,KAAK;QAAEC,OAAO;kBAC/C,cAAA,KAACxF;YAAwB,GAAGuF,KAAK;;;AAGvC,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/elements/upload/Element/index.tsx"],"sourcesContent":["'use client'\n\nimport type { ListDrawerProps } from '@payloadcms/ui'\nimport type { ClientCollectionConfig } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n DrawerToggler,\n File,\n useConfig,\n useDocumentDrawer,\n useDrawerSlug,\n useListDrawer,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport React, { useCallback, useReducer, useState } from 'react'\nimport { Transforms } from 'slate'\nimport { ReactEditor, useFocused, useSelected, useSlateStatic } from 'slate-react'\n\nimport type { UploadElementType } from '../types.js'\n\nimport { useElement } from '../../../providers/ElementProvider.js'\nimport { EnabledRelationshipsCondition } from '../../EnabledRelationshipsCondition.js'\nimport { uploadFieldsSchemaPath, uploadName } from '../shared.js'\nimport { UploadDrawer } from './UploadDrawer/index.js'\nimport './index.scss'\n\nconst baseClass = 'rich-text-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nconst UploadElementComponent: React.FC<{ enabledCollectionSlugs?: string[] }> = ({\n enabledCollectionSlugs,\n}) => {\n const {\n attributes,\n children,\n element: { relationTo, value },\n element,\n fieldProps,\n schemaPath,\n } = useElement<UploadElementType>()\n\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection, setRelatedCollection] = useState<ClientCollectionConfig>(() =>\n getEntityConfig({ collectionSlug: relationTo }),\n )\n\n const drawerSlug = useDrawerSlug('upload-drawer')\n\n const [ListDrawer, ListDrawerToggler, { closeDrawer: closeListDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n selectedCollection: relatedCollection.slug,\n })\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id: value?.id,\n collectionSlug: relatedCollection.slug,\n })\n\n const editor = useSlateStatic()\n const selected = useSelected()\n const focused = useFocused()\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value?.id}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.removeNodes(editor, { at: elementPath })\n }, [editor, element])\n\n const updateUpload = useCallback(\n (json) => {\n const { doc } = json\n\n const newNode = {\n fields: doc,\n }\n\n const elementPath = ReactEditor.findPath(editor, element)\n\n Transforms.setNodes(editor, newNode, { at: elementPath })\n\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDrawer()\n },\n [editor, element, setParams, cacheBust, closeDrawer],\n )\n\n const swapUpload = useCallback<NonNullable<ListDrawerProps['onSelect']>>(\n ({ collectionSlug, doc }) => {\n const newNode = {\n type: uploadName,\n children: [{ text: ' ' }],\n relationTo: collectionSlug,\n value: { id: doc.id },\n }\n\n const elementPath = ReactEditor.findPath(editor, element)\n\n setRelatedCollection(getEntityConfig({ collectionSlug }))\n\n Transforms.setNodes(editor, newNode, { at: elementPath })\n\n dispatchCacheBust()\n closeListDrawer()\n },\n [closeListDrawer, editor, element, getEntityConfig],\n )\n\n const relatedFieldSchemaPath = `${uploadFieldsSchemaPath}.${relatedCollection.slug}`\n const customFieldsMap = fieldProps.componentMap[relatedFieldSchemaPath]\n\n return (\n <div\n className={[baseClass, selected && focused && `${baseClass}--selected`]\n .filter(Boolean)\n .join(' ')}\n contentEditable={false}\n {...attributes}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__topRow`}>\n {/* TODO: migrate to use Thumbnail component */}\n <div className={`${baseClass}__thumbnail`}>\n {thumbnailSRC ? <img alt={data?.filename} src={thumbnailSRC} /> : <File />}\n </div>\n <div className={`${baseClass}__topRowRightPanel`}>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n <div className={`${baseClass}__actions`}>\n {Boolean(customFieldsMap) && (\n <>\n <DrawerToggler\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={fieldProps?.field?.admin?.readOnly}\n slug={drawerSlug}\n >\n <Button\n buttonStyle=\"icon-label\"\n el=\"div\"\n icon=\"edit\"\n onClick={(e) => {\n e.preventDefault()\n }}\n round\n tooltip={t('fields:editRelationship')}\n />\n </DrawerToggler>\n <UploadDrawer\n {...{ drawerSlug, element, fieldProps, relatedCollection, schemaPath }}\n />\n </>\n )}\n <ListDrawerToggler\n className={`${baseClass}__list-drawer-toggler`}\n disabled={fieldProps?.field?.admin?.readOnly}\n >\n <Button\n buttonStyle=\"icon-label\"\n disabled={fieldProps?.field?.admin?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n // do nothing\n }}\n round\n tooltip={t('fields:swapUpload')}\n />\n </ListDrawerToggler>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={fieldProps?.field?.admin?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n tooltip={t('fields:removeUpload')}\n />\n </div>\n </div>\n </div>\n <div className={`${baseClass}__bottomRow`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong>{data?.filename}</strong>\n </DocumentDrawerToggler>\n </div>\n </div>\n {children}\n {value?.id && <DocumentDrawer onSave={updateUpload} />}\n <ListDrawer onSelect={swapUpload} />\n </div>\n )\n}\n\nexport const UploadElement = (props: any): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <UploadElementComponent {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["getTranslation","Button","DrawerToggler","File","useConfig","useDocumentDrawer","useDrawerSlug","useListDrawer","usePayloadAPI","useTranslation","React","useCallback","useReducer","useState","Transforms","ReactEditor","useFocused","useSelected","useSlateStatic","useElement","EnabledRelationshipsCondition","uploadFieldsSchemaPath","uploadName","UploadDrawer","baseClass","initialParams","depth","UploadElementComponent","enabledCollectionSlugs","attributes","children","element","relationTo","value","fieldProps","schemaPath","config","routes","api","serverURL","getEntityConfig","i18n","t","cacheBust","dispatchCacheBust","state","relatedCollection","setRelatedCollection","collectionSlug","drawerSlug","ListDrawer","ListDrawerToggler","closeDrawer","closeListDrawer","collectionSlugs","selectedCollection","slug","DocumentDrawer","DocumentDrawerToggler","id","editor","selected","focused","data","setParams","thumbnailSRC","thumbnailURL","url","removeUpload","elementPath","findPath","removeNodes","at","updateUpload","json","doc","newNode","fields","setNodes","swapUpload","type","text","relatedFieldSchemaPath","customFieldsMap","componentMap","div","className","filter","Boolean","join","contentEditable","img","alt","filename","src","labels","singular","disabled","field","admin","readOnly","buttonStyle","el","icon","onClick","e","preventDefault","round","tooltip","strong","onSave","onSelect","UploadElement","props","uploads"],"mappings":"AAAA;;AAKA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SACEC,MAAM,EACNC,aAAa,EACbC,IAAI,EACJC,SAAS,EACTC,iBAAiB,EACjBC,aAAa,EACbC,aAAa,EACbC,aAAa,EACbC,cAAc,QACT,iBAAgB;AACvB,OAAOC,SAASC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,QAAO;AAChE,SAASC,UAAU,QAAQ,QAAO;AAClC,SAASC,WAAW,EAAEC,UAAU,EAAEC,WAAW,EAAEC,cAAc,QAAQ,cAAa;AAIlF,SAASC,UAAU,QAAQ,wCAAuC;AAClE,SAASC,6BAA6B,QAAQ,yCAAwC;AACtF,SAASC,sBAAsB,EAAEC,UAAU,QAAQ,eAAc;AACjE,SAASC,YAAY,QAAQ,0BAAyB;AACtD,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,MAAMC,gBAAgB;IACpBC,OAAO;AACT;AAEA,MAAMC,yBAA0E,CAAC,EAC/EC,sBAAsB,EACvB;IACC,MAAM,EACJC,UAAU,EACVC,QAAQ,EACRC,SAAS,EAAEC,UAAU,EAAEC,KAAK,EAAE,EAC9BF,OAAO,EACPG,UAAU,EACVC,UAAU,EACX,GAAGhB;IAEJ,MAAM,EACJiB,QAAQ,EACNC,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,EACDC,eAAe,EAChB,GAAGpC;IACJ,MAAM,EAAEqC,IAAI,EAAEC,CAAC,EAAE,GAAGjC;IACpB,MAAM,CAACkC,WAAWC,kBAAkB,GAAGhC,WAAW,CAACiC,QAAUA,QAAQ,GAAG;IACxE,MAAM,CAACC,mBAAmBC,qBAAqB,GAAGlC,SAAiC,IACjF2B,gBAAgB;YAAEQ,gB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
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/richtext-slate",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.25.0-canary.36940b2",
|
|
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/translations": "3.
|
|
50
|
-
"@payloadcms/ui": "3.
|
|
49
|
+
"@payloadcms/translations": "3.25.0-canary.36940b2",
|
|
50
|
+
"@payloadcms/ui": "3.25.0-canary.36940b2"
|
|
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
|
+
"payload": "3.25.0-canary.36940b2",
|
|
58
|
+
"@payloadcms/eslint-config": "3.9.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
62
|
-
"payload": "3.
|
|
62
|
+
"payload": "3.25.0-canary.36940b2"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": "^18.20.2 || >=20.9.0"
|