@payloadcms/richtext-lexical 3.69.0-internal.2883df2 → 3.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cell/rscEntry.d.ts.map +1 -1
- package/dist/cell/rscEntry.js +3 -1
- package/dist/cell/rscEntry.js.map +1 -1
- package/dist/dependencyChecker.spec.js +1 -0
- package/dist/dependencyChecker.spec.js.map +1 -1
- package/dist/exports/client/RelationshipComponent-BG3DPV3T.js +2 -0
- package/dist/exports/client/RelationshipComponent-BG3DPV3T.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/component-YQ22OGQW.js +2 -0
- package/dist/exports/client/component-YQ22OGQW.js.map +7 -0
- package/dist/exports/client/index.js +7 -7
- package/dist/exports/client/index.js.map +3 -3
- package/dist/features/blocks/server/index.d.ts.map +1 -1
- package/dist/features/blocks/server/index.js +11 -2
- package/dist/features/blocks/server/index.js.map +1 -1
- package/dist/features/converters/lexicalToPlaintext/convertLexicalToPlaintext.spec.js +1 -0
- package/dist/features/converters/lexicalToPlaintext/convertLexicalToPlaintext.spec.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +6 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.js +6 -1
- package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
- package/dist/features/upload/client/component/index.js +6 -2
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/lexical/utils/url.spec.js +1 -0
- package/dist/lexical/utils/url.spec.js.map +1 -1
- package/dist/utilities/applyBaseFilterToFields.d.ts +10 -0
- package/dist/utilities/applyBaseFilterToFields.d.ts.map +1 -0
- package/dist/utilities/applyBaseFilterToFields.js +97 -0
- package/dist/utilities/applyBaseFilterToFields.js.map +1 -0
- package/dist/utilities/jsx/jsx.spec.js +1 -0
- package/dist/utilities/jsx/jsx.spec.js.map +1 -1
- package/package.json +6 -6
- package/dist/exports/client/RelationshipComponent-UCIWIEVD.js +0 -2
- package/dist/exports/client/RelationshipComponent-UCIWIEVD.js.map +0 -7
- package/dist/exports/client/component-5IW2M4GH.js +0 -2
- package/dist/exports/client/component-5IW2M4GH.js.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rscEntry.d.ts","sourceRoot":"","sources":["../../src/cell/rscEntry.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAuB3D,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,
|
|
1
|
+
{"version":3,"file":"rscEntry.d.ts","sourceRoot":"","sources":["../../src/cell/rscEntry.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAuB3D,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA4ElE,CAAA"}
|
package/dist/cell/rscEntry.js
CHANGED
|
@@ -39,6 +39,7 @@ export const RscEntryLexicalCell = props => {
|
|
|
39
39
|
const classNameFromConfigContext = admin && 'className' in admin ? admin.className : undefined;
|
|
40
40
|
const className = classNameFromProps || (field.admin && 'className' in field.admin ? field.admin.className : null) || classNameFromConfigContext;
|
|
41
41
|
const adminRoute = payload.config.routes.admin;
|
|
42
|
+
const serverURL = payload.config.serverURL;
|
|
42
43
|
const onClick = onClickFromProps;
|
|
43
44
|
let WrapElement = 'span';
|
|
44
45
|
const wrapElementProps = {
|
|
@@ -49,7 +50,8 @@ export const RscEntryLexicalCell = props => {
|
|
|
49
50
|
WrapElement = Link;
|
|
50
51
|
wrapElementProps.href = collectionConfig?.slug ? formatAdminURL({
|
|
51
52
|
adminRoute,
|
|
52
|
-
path: `/collections/${collectionConfig?.slug}/${rowData.id}
|
|
53
|
+
path: `/collections/${collectionConfig?.slug}/${rowData.id}`,
|
|
54
|
+
serverURL
|
|
53
55
|
}) : '';
|
|
54
56
|
}
|
|
55
57
|
if (typeof onClick === 'function') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rscEntry.js","names":["getTranslation","Link","formatAdminURL","React","recurseEditorState","editorState","textContent","i","node","text","push","_jsxs","type","children","RscEntryLexicalCell","props","cellData","className","classNameFromProps","collectionConfig","field","admin","i18n","link","onClick","onClickFromProps","payload","rowData","classNameFromConfigContext","undefined","adminRoute","config","routes","WrapElement","wrapElementProps","prefetch","href","slug","path","id","collectionSlug","root","length","t","label","_jsx"],"sources":["../../src/cell/rscEntry.tsx"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { Link } from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type { LexicalRichTextCellProps } from '../types.js'\n\nfunction recurseEditorState(\n editorState: SerializedLexicalNode[],\n textContent: React.ReactNode[],\n i: number = 0,\n): React.ReactNode[] {\n for (const node of editorState) {\n i++\n if ('text' in node && node.text) {\n textContent.push(node.text as string)\n } else {\n if (!('children' in node)) {\n textContent.push(<code key={i}> [{node.type}]</code>)\n }\n }\n if ('children' in node && node.children) {\n textContent = recurseEditorState(node.children as SerializedLexicalNode[], textContent, i)\n }\n }\n return textContent\n}\n\nexport const RscEntryLexicalCell: React.FC<LexicalRichTextCellProps> = (props) => {\n const {\n cellData,\n className: classNameFromProps,\n collectionConfig,\n field: { admin },\n field,\n i18n,\n link,\n onClick: onClickFromProps,\n payload,\n rowData,\n } = props\n\n const classNameFromConfigContext = admin && 'className' in admin ? admin.className : undefined\n\n const className =\n classNameFromProps ||\n (field.admin && 'className' in field.admin ? field.admin.className : null) ||\n classNameFromConfigContext\n const adminRoute = payload.config.routes.admin\n\n const onClick = onClickFromProps\n\n let WrapElement: React.ComponentType<any> | string = 'span'\n\n const wrapElementProps: {\n className?: string\n href?: string\n onClick?: () => void\n prefetch?: false\n type?: 'button'\n } = {\n className,\n }\n\n if (link) {\n wrapElementProps.prefetch = false\n WrapElement = Link\n wrapElementProps.href = collectionConfig?.slug\n ? formatAdminURL({\n adminRoute,\n path: `/collections/${collectionConfig?.slug}/${rowData.id}`,\n })\n : ''\n }\n\n if (typeof onClick === 'function') {\n WrapElement = 'button'\n wrapElementProps.type = 'button'\n wrapElementProps.onClick = () => {\n onClick({\n cellData,\n collectionSlug: collectionConfig?.slug,\n rowData,\n })\n }\n }\n\n let textContent: React.ReactNode[] = []\n\n if (cellData?.root?.children) {\n textContent = recurseEditorState(cellData?.root?.children, textContent)\n }\n\n if (!textContent?.length) {\n textContent = [\n i18n.t('general:noLabel', {\n label: getTranslation(('label' in field ? field.label : null) || 'data', i18n),\n }),\n ]\n }\n\n return <WrapElement {...wrapElementProps}>{textContent}</WrapElement>\n}\n"],"mappings":";AAEA,SAASA,cAAc,QAAQ;AAC/B,SAASC,IAAI,QAAQ;AACrB,SAASC,cAAc,QAAQ;AAC/B,OAAOC,KAAA,MAAW;AAIlB,SAASC,mBACPC,WAAoC,EACpCC,WAA8B,EAC9BC,CAAA,GAAY,CAAC;EAEb,KAAK,MAAMC,IAAA,IAAQH,WAAA,EAAa;IAC9BE,CAAA;IACA,IAAI,UAAUC,IAAA,IAAQA,IAAA,CAAKC,IAAI,EAAE;MAC/BH,WAAA,CAAYI,IAAI,CAACF,IAAA,CAAKC,IAAI;IAC5B,OAAO;MACL,IAAI,EAAE,cAAcD,IAAG,GAAI;QACzBF,WAAA,CAAYI,IAAI,cAACC,KAAA,CAAC;qBAAa,MAAOH,IAAA,CAAKI,IAAI,EAAC;WAApBL,CAAA;MAC9B;IACF;IACA,IAAI,cAAcC,IAAA,IAAQA,IAAA,CAAKK,QAAQ,EAAE;MACvCP,WAAA,GAAcF,kBAAA,CAAmBI,IAAA,CAAKK,QAAQ,EAA6BP,WAAA,EAAaC,CAAA;IAC1F;EACF;EACA,OAAOD,WAAA;AACT;AAEA,OAAO,MAAMQ,mBAAA,GAA2DC,KAAA;EACtE,MAAM;IACJC,QAAQ;IACRC,SAAA,EAAWC,kBAAkB;IAC7BC,gBAAgB;IAChBC,KAAA,EAAO;MAAEC;IAAK,CAAE;IAChBD,KAAK;IACLE,IAAI;IACJC,IAAI;IACJC,OAAA,EAASC,gBAAgB;IACzBC,OAAO;IACPC;EAAO,CACR,GAAGZ,KAAA;EAEJ,MAAMa,0BAAA,GAA6BP,KAAA,IAAS,eAAeA,KAAA,GAAQA,KAAA,CAAMJ,SAAS,GAAGY,SAAA;EAErF,MAAMZ,SAAA,GACJC,kBAAA,KACCE,KAAA,CAAMC,KAAK,IAAI,eAAeD,KAAA,CAAMC,KAAK,GAAGD,KAAA,CAAMC,KAAK,CAACJ,SAAS,GAAG,IAAG,KACxEW,0BAAA;EACF,MAAME,UAAA,GAAaJ,OAAA,CAAQK,MAAM,CAACC,MAAM,CAACX,KAAK;
|
|
1
|
+
{"version":3,"file":"rscEntry.js","names":["getTranslation","Link","formatAdminURL","React","recurseEditorState","editorState","textContent","i","node","text","push","_jsxs","type","children","RscEntryLexicalCell","props","cellData","className","classNameFromProps","collectionConfig","field","admin","i18n","link","onClick","onClickFromProps","payload","rowData","classNameFromConfigContext","undefined","adminRoute","config","routes","serverURL","WrapElement","wrapElementProps","prefetch","href","slug","path","id","collectionSlug","root","length","t","label","_jsx"],"sources":["../../src/cell/rscEntry.tsx"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { Link } from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type { LexicalRichTextCellProps } from '../types.js'\n\nfunction recurseEditorState(\n editorState: SerializedLexicalNode[],\n textContent: React.ReactNode[],\n i: number = 0,\n): React.ReactNode[] {\n for (const node of editorState) {\n i++\n if ('text' in node && node.text) {\n textContent.push(node.text as string)\n } else {\n if (!('children' in node)) {\n textContent.push(<code key={i}> [{node.type}]</code>)\n }\n }\n if ('children' in node && node.children) {\n textContent = recurseEditorState(node.children as SerializedLexicalNode[], textContent, i)\n }\n }\n return textContent\n}\n\nexport const RscEntryLexicalCell: React.FC<LexicalRichTextCellProps> = (props) => {\n const {\n cellData,\n className: classNameFromProps,\n collectionConfig,\n field: { admin },\n field,\n i18n,\n link,\n onClick: onClickFromProps,\n payload,\n rowData,\n } = props\n\n const classNameFromConfigContext = admin && 'className' in admin ? admin.className : undefined\n\n const className =\n classNameFromProps ||\n (field.admin && 'className' in field.admin ? field.admin.className : null) ||\n classNameFromConfigContext\n const adminRoute = payload.config.routes.admin\n const serverURL = payload.config.serverURL\n\n const onClick = onClickFromProps\n\n let WrapElement: React.ComponentType<any> | string = 'span'\n\n const wrapElementProps: {\n className?: string\n href?: string\n onClick?: () => void\n prefetch?: false\n type?: 'button'\n } = {\n className,\n }\n\n if (link) {\n wrapElementProps.prefetch = false\n WrapElement = Link\n wrapElementProps.href = collectionConfig?.slug\n ? formatAdminURL({\n adminRoute,\n path: `/collections/${collectionConfig?.slug}/${rowData.id}`,\n serverURL,\n })\n : ''\n }\n\n if (typeof onClick === 'function') {\n WrapElement = 'button'\n wrapElementProps.type = 'button'\n wrapElementProps.onClick = () => {\n onClick({\n cellData,\n collectionSlug: collectionConfig?.slug,\n rowData,\n })\n }\n }\n\n let textContent: React.ReactNode[] = []\n\n if (cellData?.root?.children) {\n textContent = recurseEditorState(cellData?.root?.children, textContent)\n }\n\n if (!textContent?.length) {\n textContent = [\n i18n.t('general:noLabel', {\n label: getTranslation(('label' in field ? field.label : null) || 'data', i18n),\n }),\n ]\n }\n\n return <WrapElement {...wrapElementProps}>{textContent}</WrapElement>\n}\n"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+2,7 @@ import { lexicalTargetVersion } from './index';
|
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs/promises';
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
5
6
|
const filename = fileURLToPath(import.meta.url);
|
|
6
7
|
const dirname = path.dirname(filename);
|
|
7
8
|
describe('Lexical dependency checker', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencyChecker.spec.js","names":["lexicalTargetVersion","fileURLToPath","path","fs","
|
|
1
|
+
{"version":3,"file":"dependencyChecker.spec.js","names":["lexicalTargetVersion","fileURLToPath","path","fs","describe","it","expect","filename","import","meta","url","dirname","packageJsonString","readFile","resolve","packageJson","JSON","parse","packageJsonLexicalVersion","dependencies","toBe"],"sources":["../src/dependencyChecker.spec.ts"],"sourcesContent":["import { lexicalTargetVersion } from './index'\nimport { fileURLToPath } from 'url'\nimport path from 'path'\nimport fs from 'fs/promises'\nimport { describe, it, expect } from 'vitest'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\ndescribe('Lexical dependency checker', () => {\n it('ensure lexical version installed in package.json matches dependency checker version', async () => {\n const packageJsonString = await fs.readFile(path.resolve(dirname, '../package.json'), 'utf-8')\n const packageJson = JSON.parse(packageJsonString)\n const packageJsonLexicalVersion = packageJson.dependencies['lexical']\n\n expect(packageJsonLexicalVersion).toBe(lexicalTargetVersion)\n })\n})\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ;AACrC,SAASC,aAAa,QAAQ;AAC9B,OAAOC,IAAA,MAAU;AACjB,OAAOC,EAAA,MAAQ;AACf,SAASC,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ;AAErC,MAAMC,QAAA,GAAWN,aAAA,CAAcO,MAAA,CAAAC,IAAA,CAAYC,GAAG;AAC9C,MAAMC,OAAA,GAAUT,IAAA,CAAKS,OAAO,CAACJ,QAAA;AAE7BH,QAAA,CAAS,8BAA8B;EACrCC,EAAA,CAAG,uFAAuF;IACxF,MAAMO,iBAAA,GAAoB,MAAMT,EAAA,CAAGU,QAAQ,CAACX,IAAA,CAAKY,OAAO,CAACH,OAAA,EAAS,oBAAoB;IACtF,MAAMI,WAAA,GAAcC,IAAA,CAAKC,KAAK,CAACL,iBAAA;IAC/B,MAAMM,yBAAA,GAA4BH,WAAA,CAAYI,YAAY,CAAC,UAAU;IAErEb,MAAA,CAAOY,yBAAA,EAA2BE,IAAI,CAACpB,oBAAA;EACzC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{a as h}from"./chunk-DBWINSQN.js";import{a as f}from"./chunk-F26IQ5RE.js";import{jsx as o,jsxs as c}from"react/jsx-runtime";import{useLexicalComposerContext as S}from"@lexical/react/LexicalComposerContext.js";import{useLexicalEditable as L}from"@lexical/react/useLexicalEditable";import{getTranslation as j}from"@payloadcms/translations";import{Button as b,useConfig as A,usePayloadAPI as B,useTranslation as I}from"@payloadcms/ui";import{$getNodeByKey as P}from"lexical";import{formatAdminURL as k}from"payload/shared";import H,{useCallback as K,useReducer as M,useRef as O,useState as U}from"react";var _={depth:0},Z=R=>{let{className:e,data:{relationTo:g,value:a},nodeKey:s}=R;if(typeof a=="object")throw new Error("Relationship value should be a string or number. The Lexical Relationship component should not receive the populated value object.");let v=O(null),[l]=S(),i=L(),{config:{routes:{api:C},serverURL:N},getEntityConfig:w}=A(),[t]=U(()=>w({collectionSlug:g})),{i18n:x,t:n}=I(),[u,D]=M(r=>r+1,0),[{data:m},{setParams:d}]=B(k({apiRoute:C,path:`/${t.slug}/${a}`,serverURL:N}),{initialParams:_}),{closeDocumentDrawer:p,DocumentDrawer:$,DocumentDrawerToggler:E}=f({id:a,collectionSlug:t.slug}),T=K(()=>{l.update(()=>{P(s)?.remove()})},[l,s]),y=H.useCallback(()=>{d({..._,cacheBust:u}),p(),D()},[u,d,p]);return c("div",{className:`${e}__contents`,contentEditable:!1,ref:v,children:[c("div",{className:`${e}__wrap`,children:[o("p",{className:`${e}__label`,children:n("fields:labelRelationship",{label:t.labels?.singular?j(t.labels?.singular,x):t.slug})}),o(E,{className:`${e}__doc-drawer-toggler`,children:o("p",{className:`${e}__title`,children:m?m[t?.admin?.useAsTitle||"id"]:a})})]}),i&&c("div",{className:`${e}__actions`,children:[o(b,{buttonStyle:"icon-label",className:`${e}__swapButton`,disabled:!i,el:"button",icon:"swap",onClick:()=>{s&&l.dispatchCommand(h,{replace:{nodeKey:s}})},round:!0,tooltip:n("fields:swapRelationship")}),o(b,{buttonStyle:"icon-label",className:`${e}__removeButton`,disabled:!i,icon:"x",onClick:r=>{r.preventDefault(),T()},round:!0,tooltip:n("fields:removeRelationship")})]}),!!a&&o($,{onSave:y})]})};export{Z as RelationshipComponent};
|
|
2
|
+
//# sourceMappingURL=RelationshipComponent-BG3DPV3T.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/features/relationship/client/components/RelationshipComponent.tsx"],
|
|
4
|
+
"sourcesContent": ["'use client'\nimport type { ElementFormatType } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { getTranslation } from '@payloadcms/translations'\nimport { Button, useConfig, usePayloadAPI, useTranslation } from '@payloadcms/ui'\nimport { $getNodeByKey } from 'lexical'\nimport { formatAdminURL } from 'payload/shared'\nimport React, { useCallback, useReducer, useRef, useState } from 'react'\n\nimport type { RelationshipData } from '../../server/nodes/RelationshipNode.js'\n\nimport './index.scss'\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\n\nconst initialParams = {\n depth: 0,\n}\n\ntype Props = {\n className: string\n data: RelationshipData\n format?: ElementFormatType\n nodeKey?: string\n}\n\nexport const RelationshipComponent: React.FC<Props> = (props) => {\n const {\n className: baseClass,\n data: { relationTo, value },\n nodeKey,\n } = props\n\n if (typeof value === 'object') {\n throw new Error(\n 'Relationship value should be a string or number. The Lexical Relationship component should not receive the populated value object.',\n )\n }\n\n const relationshipElemRef = useRef<HTMLDivElement | null>(null)\n\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n\n const [relatedCollection] = useState(() => getEntityConfig({ collectionSlug: relationTo }))\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n formatAdminURL({ apiRoute: api, path: `/${relatedCollection.slug}/${value}`, serverURL }),\n { initialParams },\n )\n\n const { closeDocumentDrawer, DocumentDrawer, DocumentDrawerToggler } = useLexicalDocumentDrawer({\n id: value,\n collectionSlug: relatedCollection.slug,\n })\n\n const removeRelationship = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey!)?.remove()\n })\n }, [editor, nodeKey])\n\n const updateRelationship = React.useCallback(() => {\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 closeDocumentDrawer()\n dispatchCacheBust()\n }, [cacheBust, setParams, closeDocumentDrawer])\n\n return (\n <div className={`${baseClass}__contents`} contentEditable={false} ref={relationshipElemRef}>\n <div className={`${baseClass}__wrap`}>\n <p className={`${baseClass}__label`}>\n {t('fields:labelRelationship', {\n label: relatedCollection.labels?.singular\n ? getTranslation(relatedCollection.labels?.singular, i18n)\n : relatedCollection.slug,\n })}\n </p>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <p className={`${baseClass}__title`}>\n {data ? data[relatedCollection?.admin?.useAsTitle || 'id'] : value}\n </p>\n </DocumentDrawerToggler>\n </div>\n {isEditable && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swapButton`}\n disabled={!isEditable}\n el=\"button\"\n icon=\"swap\"\n onClick={() => {\n if (nodeKey) {\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={!isEditable}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeRelationship()\n }}\n round\n tooltip={t('fields:removeRelationship')}\n />\n </div>\n )}\n\n {!!value && <DocumentDrawer onSave={updateRelationship} />}\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": "+IAGA,OAASA,6BAAAA,MAAiC,2CAC1C,OAASC,sBAAAA,MAA0B,oCACnC,OAASC,kBAAAA,MAAsB,2BAC/B,OAASC,UAAAA,EAAQC,aAAAA,EAAWC,iBAAAA,EAAeC,kBAAAA,MAAsB,iBACjE,OAASC,iBAAAA,MAAqB,UAC9B,OAASC,kBAAAA,MAAsB,iBAC/B,OAAOC,GAASC,eAAAA,EAAaC,cAAAA,EAAYC,UAAAA,EAAQC,YAAAA,MAAgB,QAQjE,IAAMC,EAAgB,CACpBC,MAAO,CACT,EASaC,EAA0CC,GAAA,CACrD,GAAM,CACJC,UAAWC,EACXC,KAAM,CAAEC,WAAAA,EAAYC,MAAAA,CAAK,EACzBC,QAAAA,CAAO,EACLN,EAEJ,GAAI,OAAOK,GAAU,SACnB,MAAM,IAAIE,MACR,oIAAA,EAIJ,IAAMC,EAAsBC,EAA8B,IAAA,EAEpD,CAACC,CAAA,EAAUC,EAAA,EACXC,EAAaC,EAAA,EACb,CACJC,OAAQ,CACNC,OAAQ,CAAEC,IAAAA,CAAG,EACbC,UAAAA,CAAS,EAEXC,gBAAAA,CAAe,EACbC,EAAA,EAEE,CAACC,CAAA,EAAqBC,EAAS,IAAMH,EAAgB,CAAEI,eAAgBlB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C,YAAc,IAAA,EAAQpD,SAIlEO,GACCoC,EAAC,MAAA,CAAI/C,UAAW,GAAGC,CAAA,sBACjBiD,EAACO,EAAA,CACCC,YAAY,aACZ1D,UAAW,GAAGC,CAAA,eACd0D,SAAU,CAAChD,EACXiD,GAAG,SACHC,KAAK,OACLC,QAASA,IAAA,CACHzD,GACFI,EAAOsD,gBAAgBC,EAAyC,CAC9DC,QAAS,CAAE5D,QAAAA,CAAQ,CACrB,CAAA,CAEJ,EACA6D,MAAK,GACLC,QAAS5C,EAAE,yBAAA,IAEb2B,EAACO,EAAA,CACCC,YAAY,aACZ1D,UAAW,GAAGC,CAAA,iBACd0D,SAAU,CAAChD,EACXkD,KAAK,IACLC,QAAUM,GAAA,CACRA,EAAEC,eAAc,EAChB7B,EAAA,CACF,EACA0B,MAAK,GACLC,QAAS5C,EAAE,2BAAA,OAKhB,CAAC,CAACnB,GAAS8C,EAACd,EAAA,CAAekC,OAAQzB,MAG1C",
|
|
6
|
+
"names": ["useLexicalComposerContext", "useLexicalEditable", "getTranslation", "Button", "useConfig", "usePayloadAPI", "useTranslation", "$getNodeByKey", "formatAdminURL", "React", "useCallback", "useReducer", "useRef", "useState", "initialParams", "depth", "RelationshipComponent", "props", "className", "baseClass", "data", "relationTo", "value", "nodeKey", "Error", "relationshipElemRef", "useRef", "editor", "useLexicalComposerContext", "isEditable", "useLexicalEditable", "config", "routes", "api", "serverURL", "getEntityConfig", "useConfig", "relatedCollection", "useState", "collectionSlug", "i18n", "t", "useTranslation", "cacheBust", "dispatchCacheBust", "useReducer", "state", "setParams", "usePayloadAPI", "formatAdminURL", "apiRoute", "path", "slug", "closeDocumentDrawer", "DocumentDrawer", "DocumentDrawerToggler", "useLexicalDocumentDrawer", "id", "removeRelationship", "useCallback", "update", "$getNodeByKey", "remove", "updateRelationship", "React", "_jsxs", "contentEditable", "ref", "_jsx", "label", "labels", "singular", "getTranslation", "admin", "useAsTitle", "Button", "buttonStyle", "disabled", "el", "icon", "onClick", "dispatchCommand", "INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND", "replace", "round", "tooltip", "e", "preventDefault", "onSave"]
|
|
7
|
+
}
|