@payloadcms/richtext-lexical 3.0.0-beta.64 → 3.0.0-beta.66

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.
Files changed (103) hide show
  1. package/dist/exports/client/Field-6VQ73D3D.js +2 -0
  2. package/dist/exports/client/Field-6VQ73D3D.js.map +7 -0
  3. package/dist/exports/client/RelationshipComponent-FFJCVTWM.js +2 -0
  4. package/dist/exports/client/RelationshipComponent-FFJCVTWM.js.map +7 -0
  5. package/dist/exports/client/bundled.css +1 -1
  6. package/dist/exports/client/chunk-EBB2CEB6.js +2 -0
  7. package/dist/exports/client/chunk-EBB2CEB6.js.map +7 -0
  8. package/dist/exports/client/{chunk-LGMNC5KQ.js → chunk-HO42U3IJ.js} +2 -2
  9. package/dist/exports/client/chunk-JELGBZLY.js +2 -0
  10. package/dist/exports/client/chunk-JELGBZLY.js.map +7 -0
  11. package/dist/exports/client/component-TYPMHBL7.js +2 -0
  12. package/dist/exports/client/component-TYPMHBL7.js.map +7 -0
  13. package/dist/exports/client/componentInline-FQNXWTOE.js +2 -0
  14. package/dist/exports/client/componentInline-FQNXWTOE.js.map +7 -0
  15. package/dist/exports/client/index.js +7 -7
  16. package/dist/exports/client/index.js.map +4 -4
  17. package/dist/features/blocks/component/BlockContent.d.ts +3 -2
  18. package/dist/features/blocks/component/BlockContent.d.ts.map +1 -1
  19. package/dist/features/blocks/component/BlockContent.js +5 -2
  20. package/dist/features/blocks/component/BlockContent.js.map +1 -1
  21. package/dist/features/blocks/component/index.d.ts +0 -4
  22. package/dist/features/blocks/component/index.d.ts.map +1 -1
  23. package/dist/features/blocks/component/index.js +6 -2
  24. package/dist/features/blocks/component/index.js.map +1 -1
  25. package/dist/features/blocks/componentInline/index.d.ts +10 -0
  26. package/dist/features/blocks/componentInline/index.d.ts.map +1 -0
  27. package/dist/features/blocks/componentInline/index.js +133 -0
  28. package/dist/features/blocks/componentInline/index.js.map +1 -0
  29. package/dist/features/blocks/feature.client.d.ts +6 -1
  30. package/dist/features/blocks/feature.client.d.ts.map +1 -1
  31. package/dist/features/blocks/feature.client.js +70 -8
  32. package/dist/features/blocks/feature.client.js.map +1 -1
  33. package/dist/features/blocks/feature.server.d.ts +2 -1
  34. package/dist/features/blocks/feature.server.d.ts.map +1 -1
  35. package/dist/features/blocks/feature.server.js +99 -34
  36. package/dist/features/blocks/feature.server.js.map +1 -1
  37. package/dist/features/blocks/graphQLPopulationPromise.d.ts +3 -2
  38. package/dist/features/blocks/graphQLPopulationPromise.d.ts.map +1 -1
  39. package/dist/features/blocks/graphQLPopulationPromise.js +2 -2
  40. package/dist/features/blocks/graphQLPopulationPromise.js.map +1 -1
  41. package/dist/features/blocks/i18n.d.ts.map +1 -1
  42. package/dist/features/blocks/i18n.js +192 -0
  43. package/dist/features/blocks/i18n.js.map +1 -1
  44. package/dist/features/blocks/nodes/BlocksNode.d.ts.map +1 -1
  45. package/dist/features/blocks/nodes/BlocksNode.js +0 -1
  46. package/dist/features/blocks/nodes/BlocksNode.js.map +1 -1
  47. package/dist/features/blocks/nodes/InlineBlocksNode.d.ts +39 -0
  48. package/dist/features/blocks/nodes/InlineBlocksNode.d.ts.map +1 -0
  49. package/dist/features/blocks/nodes/InlineBlocksNode.js +93 -0
  50. package/dist/features/blocks/nodes/InlineBlocksNode.js.map +1 -0
  51. package/dist/features/blocks/plugin/commands.d.ts +5 -0
  52. package/dist/features/blocks/plugin/commands.d.ts.map +1 -1
  53. package/dist/features/blocks/plugin/commands.js +2 -0
  54. package/dist/features/blocks/plugin/commands.js.map +1 -1
  55. package/dist/features/blocks/plugin/index.d.ts.map +1 -1
  56. package/dist/features/blocks/plugin/index.js +76 -7
  57. package/dist/features/blocks/plugin/index.js.map +1 -1
  58. package/dist/features/blocks/validate.d.ts +3 -2
  59. package/dist/features/blocks/validate.d.ts.map +1 -1
  60. package/dist/features/blocks/validate.js +2 -2
  61. package/dist/features/blocks/validate.js.map +1 -1
  62. package/dist/features/relationship/nodes/components/RelationshipComponent.d.ts +0 -1
  63. package/dist/features/relationship/nodes/components/RelationshipComponent.d.ts.map +1 -1
  64. package/dist/features/relationship/nodes/components/RelationshipComponent.js +2 -3
  65. package/dist/features/relationship/nodes/components/RelationshipComponent.js.map +1 -1
  66. package/dist/field/index.js +8 -8
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js.map +1 -1
  69. package/dist/lexical/LexicalProvider.js +2 -2
  70. package/dist/lexical/LexicalProvider.js.map +1 -1
  71. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts +4 -4
  72. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
  73. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
  74. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts +0 -1
  75. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts.map +1 -1
  76. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +1 -20
  77. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
  78. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts +2 -2
  79. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts.map +1 -1
  80. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js.map +1 -1
  81. package/dist/lexical/plugins/SlashMenu/index.d.ts.map +1 -1
  82. package/dist/lexical/plugins/SlashMenu/index.js +43 -41
  83. package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
  84. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +1 -1
  85. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
  86. package/dist/lexical/ui/icons/InlineBlocks/index.d.ts +3 -0
  87. package/dist/lexical/ui/icons/InlineBlocks/index.d.ts.map +1 -0
  88. package/dist/lexical/ui/icons/InlineBlocks/index.js +20 -0
  89. package/dist/lexical/ui/icons/InlineBlocks/index.js.map +1 -0
  90. package/package.json +9 -9
  91. package/dist/exports/client/Field-5KHQLTCU.js +0 -2
  92. package/dist/exports/client/Field-5KHQLTCU.js.map +0 -7
  93. package/dist/exports/client/RelationshipComponent-EJB6LBDR.js +0 -2
  94. package/dist/exports/client/RelationshipComponent-EJB6LBDR.js.map +0 -7
  95. package/dist/exports/client/chunk-SVDDFJRT.js +0 -2
  96. package/dist/exports/client/chunk-SVDDFJRT.js.map +0 -7
  97. package/dist/exports/client/component-Z5R2PHH3.js +0 -2
  98. package/dist/exports/client/component-Z5R2PHH3.js.map +0 -7
  99. package/dist/features/blocks/drawer/index.d.ts +0 -9
  100. package/dist/features/blocks/drawer/index.d.ts.map +0 -1
  101. package/dist/features/blocks/drawer/index.js +0 -78
  102. package/dist/features/blocks/drawer/index.js.map +0 -1
  103. /package/dist/exports/client/{chunk-LGMNC5KQ.js.map → chunk-HO42U3IJ.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/features/blocks/nodes/BlocksNode.tsx"],"sourcesContent":["import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport type {\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n ElementFormatType,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n Spread,\n} from 'lexical'\n\nimport { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport ObjectID from 'bson-objectid'\nimport React, { type JSX } from 'react'\n\nexport type BlockFields<TBlockFields extends object = Record<string, unknown>> = {\n /** Block form data */\n blockName: string\n blockType: string\n id: string\n} & TBlockFields\n\nconst BlockComponent = React.lazy(() =>\n import('../component/index.js').then((module) => ({\n default: module.BlockComponent,\n })),\n)\n\nexport type SerializedBlockNode<TBlockFields extends object = Record<string, unknown>> = Spread<\n {\n children?: never // required so that our typed editor state doesn't automatically add children\n fields: BlockFields<TBlockFields>\n type: 'block'\n },\n SerializedDecoratorBlockNode\n>\n\nexport class BlockNode extends DecoratorBlockNode {\n __fields: BlockFields\n\n constructor({\n fields,\n format,\n key,\n }: {\n fields: BlockFields\n format?: ElementFormatType\n key?: NodeKey\n }) {\n super(format, key)\n this.__fields = fields\n }\n\n static clone(node: BlockNode): BlockNode {\n return new BlockNode({\n fields: node.__fields,\n format: node.__format,\n key: node.__key,\n })\n }\n\n static getType(): string {\n return 'block'\n }\n\n static importDOM(): DOMConversionMap<HTMLDivElement> | null {\n return {}\n }\n\n static importJSON(serializedNode: SerializedBlockNode): BlockNode {\n if (serializedNode.version === 1) {\n // Convert (version 1 had the fields wrapped in another, unnecessary data property)\n serializedNode = {\n ...serializedNode,\n fields: {\n ...(serializedNode as any).fields.data,\n },\n version: 2,\n }\n }\n const node = $createBlockNode(serializedNode.fields)\n node.setFormat(serializedNode.format)\n return node\n }\n\n static isInline(): false {\n return false\n }\n decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element {\n // @ts-expect-error\n return <BlockComponent formData={this.getFields()} nodeKey={this.getKey()} />\n }\n\n exportDOM(): DOMExportOutput {\n const element = document.createElement('div')\n\n const text = document.createTextNode(this.getTextContent())\n element.append(text)\n return { element }\n }\n\n exportJSON(): SerializedBlockNode {\n return {\n ...super.exportJSON(),\n type: 'block',\n fields: this.getFields(),\n version: 2,\n }\n }\n\n getFields(): BlockFields {\n return this.getLatest().__fields\n }\n\n getTextContent(): string {\n return `Block Field`\n }\n\n setFields(fields: BlockFields): void {\n const fieldsCopy = JSON.parse(JSON.stringify(fields)) as BlockFields\n\n const writable = this.getWritable()\n writable.__fields = fieldsCopy\n }\n}\n\nexport function $createBlockNode(fields: Exclude<BlockFields, 'id'>): BlockNode {\n return new BlockNode({\n fields: {\n ...fields,\n id: fields?.id || new ObjectID.default().toHexString(),\n },\n })\n}\n\nexport function $isBlockNode(node: BlockNode | LexicalNode | null | undefined): node is BlockNode {\n return node instanceof BlockNode\n}\n"],"names":["DecoratorBlockNode","ObjectID","React","BlockComponent","lazy","then","module","default","BlockNode","__fields","constructor","fields","format","key","clone","node","__format","__key","getType","importDOM","importJSON","serializedNode","version","data","$createBlockNode","setFormat","isInline","decorate","editor","config","formData","getFields","nodeKey","getKey","exportDOM","element","document","createElement","text","createTextNode","getTextContent","append","exportJSON","type","getLatest","setFields","fieldsCopy","JSON","parse","stringify","writable","getWritable","id","toHexString","$isBlockNode"],"mappings":";AAYA,SAASA,kBAAkB,QAAQ,8CAA6C;AAChF,OAAOC,cAAc,gBAAe;AACpC,OAAOC,WAAyB,QAAO;AASvC,MAAMC,+BAAiBD,MAAME,IAAI,CAAC,IAChC,MAAM,CAAC,yBAAyBC,IAAI,CAAC,CAACC,SAAY,CAAA;YAChDC,SAASD,OAAOH,cAAc;QAChC,CAAA;AAYF,OAAO,MAAMK,kBAAkBR;IAC7BS,SAAqB;IAErBC,YAAY,EACVC,MAAM,EACNC,MAAM,EACNC,GAAG,EAKJ,CAAE;QACD,KAAK,CAACD,QAAQC;QACd,IAAI,CAACJ,QAAQ,GAAGE;IAClB;IAEA,OAAOG,MAAMC,IAAe,EAAa;QACvC,OAAO,IAAIP,UAAU;YACnBG,QAAQI,KAAKN,QAAQ;YACrBG,QAAQG,KAAKC,QAAQ;YACrBH,KAAKE,KAAKE,KAAK;QACjB;IACF;IAEA,OAAOC,UAAkB;QACvB,OAAO;IACT;IAEA,OAAOC,YAAqD;QAC1D,OAAO,CAAC;IACV;IAEA,OAAOC,WAAWC,cAAmC,EAAa;QAChE,IAAIA,eAAeC,OAAO,KAAK,GAAG;YAChC,mFAAmF;YACnFD,iBAAiB;gBACf,GAAGA,cAAc;gBACjBV,QAAQ;oBACN,GAAG,AAACU,eAAuBV,MAAM,CAACY,IAAI;gBACxC;gBACAD,SAAS;YACX;QACF;QACA,MAAMP,OAAOS,iBAAiBH,eAAeV,MAAM;QACnDI,KAAKU,SAAS,CAACJ,eAAeT,MAAM;QACpC,OAAOG;IACT;IAEA,OAAOW,WAAkB;QACvB,OAAO;IACT;IACAC,SAASC,MAAqB,EAAEC,MAAoB,EAAe;QACjE,mBAAmB;QACnB,qBAAO,KAAC1B;YAAe2B,UAAU,IAAI,CAACC,SAAS;YAAIC,SAAS,IAAI,CAACC,MAAM;;IACzE;IAEAC,YAA6B;QAC3B,MAAMC,UAAUC,SAASC,aAAa,CAAC;QAEvC,MAAMC,OAAOF,SAASG,cAAc,CAAC,IAAI,CAACC,cAAc;QACxDL,QAAQM,MAAM,CAACH;QACf,OAAO;YAAEH;QAAQ;IACnB;IAEAO,aAAkC;QAChC,OAAO;YACL,GAAG,KAAK,CAACA,YAAY;YACrBC,MAAM;YACNhC,QAAQ,IAAI,CAACoB,SAAS;YACtBT,SAAS;QACX;IACF;IAEAS,YAAyB;QACvB,OAAO,IAAI,CAACa,SAAS,GAAGnC,QAAQ;IAClC;IAEA+B,iBAAyB;QACvB,OAAO,CAAC,WAAW,CAAC;IACtB;IAEAK,UAAUlC,MAAmB,EAAQ;QACnC,MAAMmC,aAAaC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACtC;QAE7C,MAAMuC,WAAW,IAAI,CAACC,WAAW;QACjCD,SAASzC,QAAQ,GAAGqC;IACtB;AACF;AAEA,OAAO,SAAStB,iBAAiBb,MAAkC;IACjE,OAAO,IAAIH,UAAU;QACnBG,QAAQ;YACN,GAAGA,MAAM;YACTyC,IAAIzC,QAAQyC,MAAM,IAAInD,SAASM,OAAO,GAAG8C,WAAW;QACtD;IACF;AACF;AAEA,OAAO,SAASC,aAAavC,IAAgD;IAC3E,OAAOA,gBAAgBP;AACzB"}
1
+ {"version":3,"sources":["../../../../src/features/blocks/nodes/BlocksNode.tsx"],"sourcesContent":["import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport type {\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n ElementFormatType,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n Spread,\n} from 'lexical'\n\nimport { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport ObjectID from 'bson-objectid'\nimport React, { type JSX } from 'react'\n\nexport type BlockFields<TBlockFields extends object = Record<string, unknown>> = {\n /** Block form data */\n blockName: string\n blockType: string\n id: string\n} & TBlockFields\n\nconst BlockComponent = React.lazy(() =>\n import('../component/index.js').then((module) => ({\n default: module.BlockComponent,\n })),\n)\n\nexport type SerializedBlockNode<TBlockFields extends object = Record<string, unknown>> = Spread<\n {\n children?: never // required so that our typed editor state doesn't automatically add children\n fields: BlockFields<TBlockFields>\n type: 'block'\n },\n SerializedDecoratorBlockNode\n>\n\nexport class BlockNode extends DecoratorBlockNode {\n __fields: BlockFields\n\n constructor({\n fields,\n format,\n key,\n }: {\n fields: BlockFields\n format?: ElementFormatType\n key?: NodeKey\n }) {\n super(format, key)\n this.__fields = fields\n }\n\n static clone(node: BlockNode): BlockNode {\n return new BlockNode({\n fields: node.__fields,\n format: node.__format,\n key: node.__key,\n })\n }\n\n static getType(): string {\n return 'block'\n }\n\n static importDOM(): DOMConversionMap<HTMLDivElement> | null {\n return {}\n }\n\n static importJSON(serializedNode: SerializedBlockNode): BlockNode {\n if (serializedNode.version === 1) {\n // Convert (version 1 had the fields wrapped in another, unnecessary data property)\n serializedNode = {\n ...serializedNode,\n fields: {\n ...(serializedNode as any).fields.data,\n },\n version: 2,\n }\n }\n const node = $createBlockNode(serializedNode.fields)\n node.setFormat(serializedNode.format)\n return node\n }\n\n static isInline(): false {\n return false\n }\n decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element {\n return <BlockComponent formData={this.getFields()} nodeKey={this.getKey()} />\n }\n\n exportDOM(): DOMExportOutput {\n const element = document.createElement('div')\n\n const text = document.createTextNode(this.getTextContent())\n element.append(text)\n return { element }\n }\n\n exportJSON(): SerializedBlockNode {\n return {\n ...super.exportJSON(),\n type: 'block',\n fields: this.getFields(),\n version: 2,\n }\n }\n\n getFields(): BlockFields {\n return this.getLatest().__fields\n }\n\n getTextContent(): string {\n return `Block Field`\n }\n\n setFields(fields: BlockFields): void {\n const fieldsCopy = JSON.parse(JSON.stringify(fields)) as BlockFields\n\n const writable = this.getWritable()\n writable.__fields = fieldsCopy\n }\n}\n\nexport function $createBlockNode(fields: Exclude<BlockFields, 'id'>): BlockNode {\n return new BlockNode({\n fields: {\n ...fields,\n id: fields?.id || new ObjectID.default().toHexString(),\n },\n })\n}\n\nexport function $isBlockNode(node: BlockNode | LexicalNode | null | undefined): node is BlockNode {\n return node instanceof BlockNode\n}\n"],"names":["DecoratorBlockNode","ObjectID","React","BlockComponent","lazy","then","module","default","BlockNode","__fields","constructor","fields","format","key","clone","node","__format","__key","getType","importDOM","importJSON","serializedNode","version","data","$createBlockNode","setFormat","isInline","decorate","editor","config","formData","getFields","nodeKey","getKey","exportDOM","element","document","createElement","text","createTextNode","getTextContent","append","exportJSON","type","getLatest","setFields","fieldsCopy","JSON","parse","stringify","writable","getWritable","id","toHexString","$isBlockNode"],"mappings":";AAYA,SAASA,kBAAkB,QAAQ,8CAA6C;AAChF,OAAOC,cAAc,gBAAe;AACpC,OAAOC,WAAyB,QAAO;AASvC,MAAMC,+BAAiBD,MAAME,IAAI,CAAC,IAChC,MAAM,CAAC,yBAAyBC,IAAI,CAAC,CAACC,SAAY,CAAA;YAChDC,SAASD,OAAOH,cAAc;QAChC,CAAA;AAYF,OAAO,MAAMK,kBAAkBR;IAC7BS,SAAqB;IAErBC,YAAY,EACVC,MAAM,EACNC,MAAM,EACNC,GAAG,EAKJ,CAAE;QACD,KAAK,CAACD,QAAQC;QACd,IAAI,CAACJ,QAAQ,GAAGE;IAClB;IAEA,OAAOG,MAAMC,IAAe,EAAa;QACvC,OAAO,IAAIP,UAAU;YACnBG,QAAQI,KAAKN,QAAQ;YACrBG,QAAQG,KAAKC,QAAQ;YACrBH,KAAKE,KAAKE,KAAK;QACjB;IACF;IAEA,OAAOC,UAA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C,IAAIzC,QAAQyC,MAAM,IAAInD,SAASM,OAAO,GAAG8C,WAAW;QACtD;IACF;AACF;AAEA,OAAO,SAASC,aAAavC,IAAgD;IAC3E,OAAOA,gBAAgBP;AACzB"}
@@ -0,0 +1,39 @@
1
+ import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
2
+ import { DecoratorNode } from 'lexical';
3
+ import React, { type JSX } from 'react';
4
+ export type InlineBlockFields = {
5
+ /** Block form data */
6
+ [key: string]: any;
7
+ blockType: string;
8
+ id: string;
9
+ };
10
+ export type SerializedInlineBlockNode = Spread<{
11
+ children?: never;
12
+ fields: InlineBlockFields;
13
+ type: 'inlineBlock';
14
+ }, SerializedLexicalNode>;
15
+ export declare class InlineBlockNode extends DecoratorNode<React.ReactElement> {
16
+ __fields: InlineBlockFields;
17
+ constructor({ fields, key }: {
18
+ fields: InlineBlockFields;
19
+ key?: NodeKey;
20
+ });
21
+ static clone(node: InlineBlockNode): InlineBlockNode;
22
+ static getType(): string;
23
+ static importDOM(): DOMConversionMap<HTMLDivElement> | null;
24
+ static importJSON(serializedNode: SerializedInlineBlockNode): InlineBlockNode;
25
+ static isInline(): false;
26
+ canIndent(): boolean;
27
+ createDOM(): HTMLSpanElement;
28
+ decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element;
29
+ exportDOM(): DOMExportOutput;
30
+ exportJSON(): SerializedInlineBlockNode;
31
+ getFields(): InlineBlockFields;
32
+ getTextContent(): string;
33
+ isInline(): boolean;
34
+ setFields(fields: InlineBlockFields): void;
35
+ updateDOM(): boolean;
36
+ }
37
+ export declare function $createInlineBlockNode(fields: Exclude<InlineBlockFields, 'id'>): InlineBlockNode;
38
+ export declare function $isInlineBlockNode(node: InlineBlockNode | LexicalNode | null | undefined): node is InlineBlockNode;
39
+ //# sourceMappingURL=InlineBlocksNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InlineBlocksNode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E,YAAY,GAAG,GAAG,CAAC,OAAO;IAIlE,SAAS,IAAI,eAAe;IAS5B,UAAU,IAAI,yBAAyB;IAQvC,SAAS,IAAI,iBAAiB;IAI9B,cAAc,IAAI,MAAM;IAIxB,QAAQ;IAIR,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAO1C,SAAS,IAAI,OAAO;CAGrB;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC,GAAG,eAAe,CAOhG;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,eAAe,GAAG,WAAW,GAAG,IAAI,GAAG,SAAS,GACrD,IAAI,IAAI,eAAe,CAEzB"}
@@ -0,0 +1,93 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import ObjectID from 'bson-objectid';
3
+ import { DecoratorNode } from 'lexical';
4
+ import React from 'react';
5
+ const InlineBlockComponent = /*#__PURE__*/ React.lazy(()=>import('../componentInline/index.js').then((module)=>({
6
+ default: module.InlineBlockComponent
7
+ })));
8
+ export class InlineBlockNode extends DecoratorNode {
9
+ __fields;
10
+ constructor({ fields, key }){
11
+ super(key);
12
+ this.__fields = fields;
13
+ }
14
+ static clone(node) {
15
+ return new InlineBlockNode({
16
+ fields: node.__fields,
17
+ key: node.__key
18
+ });
19
+ }
20
+ static getType() {
21
+ return 'inlineBlock';
22
+ }
23
+ static importDOM() {
24
+ return {};
25
+ }
26
+ static importJSON(serializedNode) {
27
+ const node = $createInlineBlockNode(serializedNode.fields);
28
+ return node;
29
+ }
30
+ static isInline() {
31
+ return false;
32
+ }
33
+ canIndent() {
34
+ return true;
35
+ }
36
+ createDOM() {
37
+ const element = document.createElement('span');
38
+ element.classList.add('inline-block-container');
39
+ return element;
40
+ }
41
+ decorate(editor, config) {
42
+ return /*#__PURE__*/ _jsx(InlineBlockComponent, {
43
+ formData: this.getFields(),
44
+ nodeKey: this.getKey()
45
+ });
46
+ }
47
+ exportDOM() {
48
+ const element = document.createElement('span');
49
+ element.classList.add('inline-block-container');
50
+ const text = document.createTextNode(this.getTextContent());
51
+ element.append(text);
52
+ return {
53
+ element
54
+ };
55
+ }
56
+ exportJSON() {
57
+ return {
58
+ type: 'inlineBlock',
59
+ fields: this.getFields(),
60
+ version: 1
61
+ };
62
+ }
63
+ getFields() {
64
+ return this.getLatest().__fields;
65
+ }
66
+ getTextContent() {
67
+ return `Block Field`;
68
+ }
69
+ isInline() {
70
+ return true;
71
+ }
72
+ setFields(fields) {
73
+ const fieldsCopy = JSON.parse(JSON.stringify(fields));
74
+ const writable = this.getWritable();
75
+ writable.__fields = fieldsCopy;
76
+ }
77
+ updateDOM() {
78
+ return false;
79
+ }
80
+ }
81
+ export function $createInlineBlockNode(fields) {
82
+ return new InlineBlockNode({
83
+ fields: {
84
+ ...fields,
85
+ id: fields?.id || new ObjectID.default().toHexString()
86
+ }
87
+ });
88
+ }
89
+ export function $isInlineBlockNode(node) {
90
+ return node instanceof InlineBlockNode;
91
+ }
92
+
93
+ //# sourceMappingURL=InlineBlocksNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/features/blocks/nodes/InlineBlocksNode.tsx"],"sourcesContent":["import type {\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n SerializedLexicalNode,\n Spread,\n} from 'lexical'\n\nimport ObjectID from 'bson-objectid'\nimport { DecoratorNode } from 'lexical'\nimport React, { type JSX } from 'react'\n\nexport type InlineBlockFields = {\n /** Block form data */\n [key: string]: any\n //blockName: string\n blockType: string\n id: string\n}\n\nconst InlineBlockComponent = React.lazy(() =>\n import('../componentInline/index.js').then((module) => ({\n default: module.InlineBlockComponent,\n })),\n)\n\nexport type SerializedInlineBlockNode = Spread<\n {\n children?: never // required so that our typed editor state doesn't automatically add children\n fields: InlineBlockFields\n type: 'inlineBlock'\n },\n SerializedLexicalNode\n>\n\nexport class InlineBlockNode extends DecoratorNode<React.ReactElement> {\n __fields: InlineBlockFields\n\n constructor({ fields, key }: { fields: InlineBlockFields; key?: NodeKey }) {\n super(key)\n this.__fields = fields\n }\n\n static clone(node: InlineBlockNode): InlineBlockNode {\n return new InlineBlockNode({\n fields: node.__fields,\n key: node.__key,\n })\n }\n\n static getType(): string {\n return 'inlineBlock'\n }\n\n static importDOM(): DOMConversionMap<HTMLDivElement> | null {\n return {}\n }\n\n static importJSON(serializedNode: SerializedInlineBlockNode): InlineBlockNode {\n const node = $createInlineBlockNode(serializedNode.fields)\n return node\n }\n\n static isInline(): false {\n return false\n }\n canIndent() {\n return true\n }\n\n createDOM() {\n const element = document.createElement('span')\n element.classList.add('inline-block-container')\n\n return element\n }\n\n decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element {\n return <InlineBlockComponent formData={this.getFields()} nodeKey={this.getKey()} />\n }\n\n exportDOM(): DOMExportOutput {\n const element = document.createElement('span')\n element.classList.add('inline-block-container')\n\n const text = document.createTextNode(this.getTextContent())\n element.append(text)\n return { element }\n }\n\n exportJSON(): SerializedInlineBlockNode {\n return {\n type: 'inlineBlock',\n fields: this.getFields(),\n version: 1,\n }\n }\n\n getFields(): InlineBlockFields {\n return this.getLatest().__fields\n }\n\n getTextContent(): string {\n return `Block Field`\n }\n\n isInline() {\n return true\n }\n\n setFields(fields: InlineBlockFields): void {\n const fieldsCopy = JSON.parse(JSON.stringify(fields)) as InlineBlockFields\n\n const writable = this.getWritable()\n writable.__fields = fieldsCopy\n }\n\n updateDOM(): boolean {\n return false\n }\n}\n\nexport function $createInlineBlockNode(fields: Exclude<InlineBlockFields, 'id'>): InlineBlockNode {\n return new InlineBlockNode({\n fields: {\n ...fields,\n id: fields?.id || new ObjectID.default().toHexString(),\n },\n })\n}\n\nexport function $isInlineBlockNode(\n node: InlineBlockNode | LexicalNode | null | undefined,\n): node is InlineBlockNode {\n return node instanceof InlineBlockNode\n}\n"],"names":["ObjectID","DecoratorNode","React","InlineBlockComponent","lazy","then","module","default","InlineBlockNode","__fields","constructor","fields","key","clone","node","__key","getType","importDOM","importJSON","serializedNode","$createInlineBlockNode","isInline","canIndent","createDOM","element","document","createElement","classList","add","decorate","editor","config","formData","getFields","nodeKey","getKey","exportDOM","text","createTextNode","getTextContent","append","exportJSON","type","version","getLatest","setFields","fieldsCopy","JSON","parse","stringify","writable","getWritable","updateDOM","id","toHexString","$isInlineBlockNode"],"mappings":";AAWA,OAAOA,cAAc,gBAAe;AACpC,SAASC,aAAa,QAAQ,UAAS;AACvC,OAAOC,WAAyB,QAAO;AAUvC,MAAMC,qCAAuBD,MAAME,IAAI,CAAC,IACtC,MAAM,CAAC,+BAA+BC,IAAI,CAAC,CAACC,SAAY,CAAA;YACtDC,SAASD,OAAOH,oBAAoB;QACtC,CAAA;AAYF,OAAO,MAAMK,wBAAwBP;IACnCQ,SAA2B;IAE3BC,YAAY,EAAEC,MAAM,EAAEC,GAAG,EAAgD,CAAE;QACzE,KAAK,CAACA;QACN,IAAI,CAACH,QAAQ,GAAGE;IAClB;IAEA,OAAOE,MAAMC,IAAqB,EAAmB;QACnD,OAAO,IAAIN,gBAAgB;YACzBG,QAAQG,KAAKL,QAAQ;YACrBG,KAAKE,KAAKC,KAAK;QACjB;IACF;IAEA,OAAOC,UAAkB;QACvB,OAAO;IACT;IAEA,OAAOC,YAAqD;QAC1D,OAAO,CAAC;IACV;IAEA,OAAOC,WAAWC,cAAyC,EAAmB;QAC5E,MAAML,OAAOM,uBAAuBD,eAAeR,MAAM;QACzD,OAAOG;IACT;IAEA,OAAOO,WAAkB;QACvB,OAAO;IACT;IACAC,YAAY;QACV,OAAO;IACT;IAEAC,YAAY;QACV,MAAMC,UAAUC,SAASC,aAAa,CAAC;QACvCF,QAAQG,SAAS,CAACC,GAAG,CAAC;QAEtB,OAAOJ;IACT;IAEAK,SAASC,MAAqB,EAAEC,MAAoB,EAAe;QACjE,qBAAO,KAAC5B;YAAqB6B,UAAU,IAAI,CAACC,SAAS;YAAIC,SAAS,IAAI,CAACC,MAAM;;IAC/E;IAEAC,YAA6B;QAC3B,MAAMZ,UAAUC,SAASC,aAAa,CAAC;QACvCF,QAAQG,SAAS,CAACC,GAAG,CAAC;QAEtB,MAAMS,OAAOZ,SAASa,cAAc,CAAC,IAAI,CAACC,cAAc;QACxDf,QAAQgB,MAAM,CAACH;QACf,OAAO;YAAEb;QAAQ;IACnB;IAEAiB,aAAwC;QACtC,OAAO;YACLC,MAAM;YACN/B,QAAQ,IAAI,CAACsB,SAAS;YACtBU,SAAS;QACX;IACF;IAEAV,YAA+B;QAC7B,OAAO,IAAI,CAACW,SAAS,GAAGnC,QAAQ;IAClC;IAEA8B,iBAAyB;QACvB,OAAO,CAAC,WAAW,CAAC;IACtB;IAEAlB,WAAW;QACT,OAAO;IACT;IAEAwB,UAAUlC,MAAyB,EAAQ;QACzC,MAAMmC,aAAaC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACtC;QAE7C,MAAMuC,WAAW,IAAI,CAACC,WAAW;QACjCD,SAASzC,QAAQ,GAAGqC;IACtB;IAEAM,YAAqB;QACnB,OAAO;IACT;AACF;AAEA,OAAO,SAAShC,uBAAuBT,MAAwC;IAC7E,OAAO,IAAIH,gBAAgB;QACzBG,QAAQ;YACN,GAAGA,MAAM;YACT0C,IAAI1C,QAAQ0C,MAAM,IAAIrD,SAASO,OAAO,GAAG+C,WAAW;QACtD;IACF;AACF;AAEA,OAAO,SAASC,mBACdzC,IAAsD;IAEtD,OAAOA,gBAAgBN;AACzB"}
@@ -1,4 +1,9 @@
1
1
  import type { LexicalCommand } from 'lexical';
2
2
  import type { InsertBlockPayload } from './index.js';
3
3
  export declare const INSERT_BLOCK_COMMAND: LexicalCommand<InsertBlockPayload>;
4
+ export declare const INSERT_INLINE_BLOCK_COMMAND: LexicalCommand<Partial<InsertBlockPayload>>;
5
+ export declare const OPEN_INLINE_BLOCK_DRAWER_COMMAND: LexicalCommand<{
6
+ fields: Partial<InsertBlockPayload>;
7
+ nodeKey?: string;
8
+ }>;
4
9
  //# sourceMappingURL=commands.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/plugin/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAAC,kBAAkB,CAC7B,CAAA"}
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/plugin/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAAC,kBAAkB,CAC7B,CAAA;AAEvC,eAAO,MAAM,2BAA2B,EAAE,cAAc,CAAC,OAAO,CAAC,kBAAkB,CAAC,CACtC,CAAA;AAE9C,eAAO,MAAM,gCAAgC,EAAE,cAAc,CAAC;IAC5D,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAqD,CAAA"}
@@ -1,4 +1,6 @@
1
1
  import { createCommand } from 'lexical';
2
2
  export const INSERT_BLOCK_COMMAND = createCommand('INSERT_BLOCK_COMMAND');
3
+ export const INSERT_INLINE_BLOCK_COMMAND = createCommand('INSERT_INLINE_BLOCK_COMMAND');
4
+ export const OPEN_INLINE_BLOCK_DRAWER_COMMAND = createCommand('OPEN_INLINE_BLOCK_DRAWER_COMMAND');
3
5
 
4
6
  //# sourceMappingURL=commands.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/features/blocks/plugin/commands.ts"],"sourcesContent":["import type { LexicalCommand } from 'lexical'\n\nimport { createCommand } from 'lexical'\n\nimport type { InsertBlockPayload } from './index.js'\n\nexport const INSERT_BLOCK_COMMAND: LexicalCommand<InsertBlockPayload> =\n createCommand('INSERT_BLOCK_COMMAND')\n"],"names":["createCommand","INSERT_BLOCK_COMMAND"],"mappings":"AAEA,SAASA,aAAa,QAAQ,UAAS;AAIvC,OAAO,MAAMC,uBACXD,cAAc,wBAAuB"}
1
+ {"version":3,"sources":["../../../../src/features/blocks/plugin/commands.ts"],"sourcesContent":["import type { LexicalCommand } from 'lexical'\n\nimport { createCommand } from 'lexical'\n\nimport type { InsertBlockPayload } from './index.js'\n\nexport const INSERT_BLOCK_COMMAND: LexicalCommand<InsertBlockPayload> =\n createCommand('INSERT_BLOCK_COMMAND')\n\nexport const INSERT_INLINE_BLOCK_COMMAND: LexicalCommand<Partial<InsertBlockPayload>> =\n createCommand('INSERT_INLINE_BLOCK_COMMAND')\n\nexport const OPEN_INLINE_BLOCK_DRAWER_COMMAND: LexicalCommand<{\n fields: Partial<InsertBlockPayload>\n nodeKey?: string\n}> = createCommand('OPEN_INLINE_BLOCK_DRAWER_COMMAND')\n"],"names":["createCommand","INSERT_BLOCK_COMMAND","INSERT_INLINE_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND"],"mappings":"AAEA,SAASA,aAAa,QAAQ,UAAS;AAIvC,OAAO,MAAMC,uBACXD,cAAc,wBAAuB;AAEvC,OAAO,MAAME,8BACXF,cAAc,+BAA8B;AAE9C,OAAO,MAAMG,mCAGRH,cAAc,oCAAmC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/plugin/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAMzD,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;AAE3D,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,wBAAwB,CA8ClE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/plugin/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACjF,OAAO,KAAK,EAAE,wBAAwB,EAAe,MAAM,sBAAsB,CAAA;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAazD,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;AAI3D,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,wBAAwB,CAwIlE,CAAA"}
@@ -1,14 +1,26 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
4
- import { $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils';
5
- import { $getPreviousSelection, $getSelection, $isParagraphNode, $isRangeSelection, COMMAND_PRIORITY_EDITOR } from 'lexical';
6
- import React, { useEffect } from 'react';
7
- import { BlocksDrawerComponent } from '../drawer/index.js';
4
+ import { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils';
5
+ import { getTranslation } from '@payloadcms/translations';
6
+ import { useModal, useTranslation } from '@payloadcms/ui';
7
+ import { $createParagraphNode, $getNodeByKey, $getPreviousSelection, $getSelection, $insertNodes, $isParagraphNode, $isRangeSelection, $isRootOrShadowRoot, COMMAND_PRIORITY_EDITOR } from 'lexical';
8
+ import React, { useEffect, useState } from 'react';
9
+ import { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js';
10
+ import { FieldsDrawer } from '../../../utilities/fieldsDrawer/Drawer.js';
8
11
  import { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js';
9
- import { INSERT_BLOCK_COMMAND } from './commands.js';
12
+ import { $createInlineBlockNode } from '../nodes/InlineBlocksNode.js';
13
+ import { INSERT_BLOCK_COMMAND, INSERT_INLINE_BLOCK_COMMAND, OPEN_INLINE_BLOCK_DRAWER_COMMAND } from './commands.js';
14
+ const drawerSlug = 'lexical-inlineBlocks-create';
10
15
  export const BlocksPlugin = ()=>{
11
16
  const [editor] = useLexicalComposerContext();
17
+ const { closeModal, toggleModal } = useModal();
18
+ const [blockFields, setBlockFields] = useState(null);
19
+ const [blockType, setBlockType] = useState('');
20
+ const [targetNodeKey, setTargetNodeKey] = useState(null);
21
+ const { i18n, t } = useTranslation();
22
+ const { editorConfig } = useEditorConfigContext();
23
+ const reducedBlock = editorConfig?.resolvedFeatureMap?.get('blocks')?.sanitizedClientFeatureProps?.reducedInlineBlocks?.find((block)=>block.slug === blockFields?.blockType);
12
24
  useEffect(()=>{
13
25
  if (!editor.hasNodes([
14
26
  BlockNode
@@ -32,11 +44,68 @@ export const BlocksPlugin = ()=>{
32
44
  }
33
45
  });
34
46
  return true;
47
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_INLINE_BLOCK_COMMAND, (fields)=>{
48
+ if (targetNodeKey) {
49
+ const node = $getNodeByKey(targetNodeKey);
50
+ if (!node) {
51
+ return false;
52
+ }
53
+ node.setFields(fields);
54
+ setTargetNodeKey(null);
55
+ return true;
56
+ }
57
+ const inlineBlockNode = $createInlineBlockNode(fields);
58
+ $insertNodes([
59
+ inlineBlockNode
60
+ ]);
61
+ if ($isRootOrShadowRoot(inlineBlockNode.getParentOrThrow())) {
62
+ $wrapNodeInElement(inlineBlockNode, $createParagraphNode).selectEnd();
63
+ }
64
+ return true;
65
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(OPEN_INLINE_BLOCK_DRAWER_COMMAND, ({ fields, nodeKey })=>{
66
+ setBlockFields(fields ?? null);
67
+ setTargetNodeKey(nodeKey ?? null);
68
+ setBlockType(fields?.blockType ?? '');
69
+ if (nodeKey) {
70
+ toggleModal(drawerSlug);
71
+ return true;
72
+ }
73
+ let rangeSelection = null;
74
+ editor.getEditorState().read(()=>{
75
+ const selection = $getSelection();
76
+ if ($isRangeSelection(selection)) {
77
+ rangeSelection = selection;
78
+ }
79
+ });
80
+ if (rangeSelection) {
81
+ //setLastSelection(rangeSelection)
82
+ toggleModal(drawerSlug);
83
+ }
84
+ return true;
35
85
  }, COMMAND_PRIORITY_EDITOR));
36
86
  }, [
37
- editor
87
+ editor,
88
+ targetNodeKey,
89
+ toggleModal
38
90
  ]);
39
- return /*#__PURE__*/ _jsx(BlocksDrawerComponent, {});
91
+ const blockDisplayName = reducedBlock?.labels?.singular ? getTranslation(reducedBlock?.labels?.singular, i18n) : reducedBlock?.slug;
92
+ return /*#__PURE__*/ _jsx(FieldsDrawer, {
93
+ data: blockFields,
94
+ drawerSlug: drawerSlug,
95
+ drawerTitle: t(`lexical:blocks:inlineBlocks:${blockFields?.id ? 'edit' : 'create'}`, {
96
+ label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label')
97
+ }),
98
+ featureKey: "blocks",
99
+ handleDrawerSubmit: (_fields, data)=>{
100
+ closeModal(drawerSlug);
101
+ if (!data) {
102
+ return;
103
+ }
104
+ data.blockType = blockType;
105
+ editor.dispatchCommand(INSERT_INLINE_BLOCK_COMMAND, data);
106
+ },
107
+ schemaPathSuffix: blockFields?.blockType
108
+ });
40
109
  };
41
110
 
42
111
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/features/blocks/plugin/index.tsx"],"sourcesContent":["'use client'\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils'\nimport {\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n COMMAND_PRIORITY_EDITOR,\n} from 'lexical'\nimport React, { useEffect } from 'react'\n\nimport type { PluginComponent } from '../../typesClient.js'\nimport type { BlocksFeatureClientProps } from '../feature.client.js'\nimport type { BlockFields } from '../nodes/BlocksNode.js'\n\nimport { BlocksDrawerComponent } from '../drawer/index.js'\nimport { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js'\nimport { INSERT_BLOCK_COMMAND } from './commands.js'\n\nexport type InsertBlockPayload = Exclude<BlockFields, 'id'>\n\nexport const BlocksPlugin: PluginComponent<BlocksFeatureClientProps> = () => {\n const [editor] = useLexicalComposerContext()\n\n useEffect(() => {\n if (!editor.hasNodes([BlockNode])) {\n throw new Error('BlocksPlugin: BlocksNode not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand<InsertBlockPayload>(\n INSERT_BLOCK_COMMAND,\n (payload: InsertBlockPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const blockNode = $createBlockNode(payload)\n // Insert blocks node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(blockNode)\n\n const { focus } = selection\n const focusNode = focus.getNode()\n\n // First, delete currently selected node if it's an empty paragraph and if there are sufficient\n // paragraph nodes (more than 1) left in the parent node, so that we don't \"trap\" the user\n if (\n $isParagraphNode(focusNode) &&\n focusNode.getTextContentSize() === 0 &&\n focusNode\n .getParent()\n .getChildren()\n .filter((node) => $isParagraphNode(node)).length > 1\n ) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [editor])\n\n return <BlocksDrawerComponent />\n}\n"],"names":["useLexicalComposerContext","$insertNodeToNearestRoot","mergeRegister","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","COMMAND_PRIORITY_EDITOR","React","useEffect","BlocksDrawerComponent","$createBlockNode","BlockNode","INSERT_BLOCK_COMMAND","BlocksPlugin","editor","hasNodes","Error","registerCommand","payload","update","selection","blockNode","focus","focusNode","getNode","getTextContentSize","getParent","getChildren","filter","node","length","remove"],"mappings":"AAAA;;AACA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,wBAAwB,EAAEC,aAAa,QAAQ,iBAAgB;AACxE,SACEC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,uBAAuB,QAClB,UAAS;AAChB,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAMxC,SAASC,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,yBAAwB;AACpE,SAASC,oBAAoB,QAAQ,gBAAe;AAIpD,OAAO,MAAMC,eAA0D;IACrE,MAAM,CAACC,OAAO,GAAGf;IAEjBS,UAAU;QACR,IAAI,CAACM,OAAOC,QAAQ,CAAC;YAACJ;SAAU,GAAG;YACjC,MAAM,IAAIK,MAAM;QAClB;QAEA,OAAOf,cACLa,OAAOG,eAAe,CACpBL,sBACA,CAACM;YACCJ,OAAOK,MAAM,CAAC;gBACZ,MAAMC,YAAYjB,mBAAmBD;gBAErC,IAAIG,kBAAkBe,YAAY;oBAChC,MAAMC,YAAYX,iBAAiBQ;oBACnC,8HAA8H;oBAC9HlB,yBAAyBqB;oBAEzB,MAAM,EAAEC,KAAK,EAAE,GAAGF;oBAClB,MAAMG,YAAYD,MAAME,OAAO;oBAE/B,+FAA+F;oBAC/F,0FAA0F;oBAC1F,IACEpB,iBAAiBmB,cACjBA,UAAUE,kBAAkB,OAAO,KACnCF,UACGG,SAAS,GACTC,WAAW,GACXC,MAAM,CAAC,CAACC,OAASzB,iBAAiByB,OAAOC,MAAM,GAAG,GACrD;wBACAP,UAAUQ,MAAM;oBAClB;gBACF;YACF;YAEA,OAAO;QACT,GACAzB;IAGN,GAAG;QAACQ;KAAO;IAEX,qBAAO,KAACL;AACV,EAAC"}
1
+ {"version":3,"sources":["../../../../src/features/blocks/plugin/index.tsx"],"sourcesContent":["'use client'\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport { useModal, useTranslation } from '@payloadcms/ui'\nimport {\n $createParagraphNode,\n $getNodeByKey,\n $getPreviousSelection,\n $getSelection,\n $insertNodes,\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_EDITOR,\n type RangeSelection,\n} from 'lexical'\nimport React, { useEffect, useState } from 'react'\n\nimport type { ClientComponentProps, PluginComponent } from '../../typesClient.js'\nimport type { BlocksFeatureClientProps, ClientBlock } from '../feature.client.js'\nimport type { BlockFields } from '../nodes/BlocksNode.js'\nimport type { InlineBlockNode } from '../nodes/InlineBlocksNode.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../utilities/fieldsDrawer/Drawer.js'\nimport { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js'\nimport { $createInlineBlockNode } from '../nodes/InlineBlocksNode.js'\nimport {\n INSERT_BLOCK_COMMAND,\n INSERT_INLINE_BLOCK_COMMAND,\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n} from './commands.js'\n\nexport type InsertBlockPayload = Exclude<BlockFields, 'id'>\n\nconst drawerSlug = 'lexical-inlineBlocks-create'\n\nexport const BlocksPlugin: PluginComponent<BlocksFeatureClientProps> = () => {\n const [editor] = useLexicalComposerContext()\n const { closeModal, toggleModal } = useModal()\n const [blockFields, setBlockFields] = useState<BlockFields>(null)\n const [blockType, setBlockType] = useState<string>('' as any)\n const [targetNodeKey, setTargetNodeKey] = useState<null | string>(null)\n const { i18n, t } = useTranslation<string, any>()\n\n const { editorConfig } = useEditorConfigContext()\n\n const reducedBlock: ClientBlock = (\n editorConfig?.resolvedFeatureMap?.get('blocks')\n ?.sanitizedClientFeatureProps as ClientComponentProps<BlocksFeatureClientProps>\n )?.reducedInlineBlocks?.find((block) => block.slug === blockFields?.blockType)\n\n useEffect(() => {\n if (!editor.hasNodes([BlockNode])) {\n throw new Error('BlocksPlugin: BlocksNode not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand<InsertBlockPayload>(\n INSERT_BLOCK_COMMAND,\n (payload: InsertBlockPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const blockNode = $createBlockNode(payload)\n // Insert blocks node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(blockNode)\n\n const { focus } = selection\n const focusNode = focus.getNode()\n\n // First, delete currently selected node if it's an empty paragraph and if there are sufficient\n // paragraph nodes (more than 1) left in the parent node, so that we don't \"trap\" the user\n if (\n $isParagraphNode(focusNode) &&\n focusNode.getTextContentSize() === 0 &&\n focusNode\n .getParent()\n .getChildren()\n .filter((node) => $isParagraphNode(node)).length > 1\n ) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n INSERT_INLINE_BLOCK_COMMAND,\n (fields) => {\n if (targetNodeKey) {\n const node: InlineBlockNode = $getNodeByKey(targetNodeKey)\n\n if (!node) {\n return false\n }\n node.setFields(fields as BlockFields)\n\n setTargetNodeKey(null)\n return true\n }\n\n const inlineBlockNode = $createInlineBlockNode(fields as BlockFields)\n $insertNodes([inlineBlockNode])\n if ($isRootOrShadowRoot(inlineBlockNode.getParentOrThrow())) {\n $wrapNodeInElement(inlineBlockNode, $createParagraphNode).selectEnd()\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n ({ fields, nodeKey }) => {\n setBlockFields((fields as BlockFields) ?? null)\n setTargetNodeKey(nodeKey ?? null)\n setBlockType((fields as BlockFields)?.blockType ?? ('' as any))\n\n if (nodeKey) {\n toggleModal(drawerSlug)\n return true\n }\n\n let rangeSelection: RangeSelection | null = null\n\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n rangeSelection = selection\n }\n })\n\n if (rangeSelection) {\n //setLastSelection(rangeSelection)\n toggleModal(drawerSlug)\n }\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [editor, targetNodeKey, toggleModal])\n\n const blockDisplayName = reducedBlock?.labels?.singular\n ? getTranslation(reducedBlock?.labels?.singular, i18n)\n : reducedBlock?.slug\n\n return (\n <FieldsDrawer\n data={blockFields}\n drawerSlug={drawerSlug}\n drawerTitle={t(`lexical:blocks:inlineBlocks:${blockFields?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n featureKey=\"blocks\"\n handleDrawerSubmit={(_fields, data) => {\n closeModal(drawerSlug)\n if (!data) {\n return\n }\n\n data.blockType = blockType\n\n editor.dispatchCommand(INSERT_INLINE_BLOCK_COMMAND, data)\n }}\n schemaPathSuffix={blockFields?.blockType}\n />\n )\n}\n"],"names":["useLexicalComposerContext","$insertNodeToNearestRoot","$wrapNodeInElement","mergeRegister","getTranslation","useModal","useTranslation","$createParagraphNode","$getNodeByKey","$getPreviousSelection","$getSelection","$insertNodes","$isParagraphNode","$isRangeSelection","$isRootOrShadowRoot","COMMAND_PRIORITY_EDITOR","React","useEffect","useState","useEditorConfigContext","FieldsDrawer","$createBlockNode","BlockNode","$createInlineBlockNode","INSERT_BLOCK_COMMAND","INSERT_INLINE_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND","drawerSlug","BlocksPlugin","editor","closeModal","toggleModal","blockFields","setBlockFields","blockType","setBlockType","targetNodeKey","setTargetNodeKey","i18n","t","editorConfig","reducedBlock","resolvedFeatureMap","get","sanitizedClientFeatureProps","reducedInlineBlocks","find","block","slug","hasNodes","Error","registerCommand","payload","update","selection","blockNode","focus","focusNode","getNode","getTextContentSize","getParent","getChildren","filter","node","length","remove","fields","setFields","inlineBlockNode","getParentOrThrow","selectEnd","nodeKey","rangeSelection","getEditorState","read","blockDisplayName","labels","singular","data","drawerTitle","id","label","featureKey","handleDrawerSubmit","_fields","dispatchCommand","schemaPathSuffix"],"mappings":"AAAA;;AACA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,wBAAwB,EAAEC,kBAAkB,EAAEC,aAAa,QAAQ,iBAAgB;AAC5F,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,QAAQ,EAAEC,cAAc,QAAQ,iBAAgB;AACzD,SACEC,oBAAoB,EACpBC,aAAa,EACbC,qBAAqB,EACrBC,aAAa,EACbC,YAAY,EACZC,gBAAgB,EAChBC,iBAAiB,EACjBC,mBAAmB,EACnBC,uBAAuB,QAElB,UAAS;AAChB,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAOlD,SAASC,sBAAsB,QAAQ,yDAAwD;AAC/F,SAASC,YAAY,QAAQ,4CAA2C;AACxE,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,yBAAwB;AACpE,SAASC,sBAAsB,QAAQ,+BAA8B;AACrE,SACEC,oBAAoB,EACpBC,2BAA2B,EAC3BC,gCAAgC,QAC3B,gBAAe;AAItB,MAAMC,aAAa;AAEnB,OAAO,MAAMC,eAA0D;IACrE,MAAM,CAACC,OAAO,GAAG7B;IACjB,MAAM,EAAE8B,UAAU,EAAEC,WAAW,EAAE,GAAG1B;IACpC,MAAM,CAAC2B,aAAaC,eAAe,GAAGf,SAAsB;IAC5D,MAAM,CAACgB,WAAWC,aAAa,GAAGjB,SAAiB;IACnD,MAAM,CAACkB,eAAeC,iBAAiB,GAAGnB,SAAwB;IAClE,MAAM,EAAEoB,IAAI,EAAEC,CAAC,EAAE,GAAGjC;IAEpB,MAAM,EAAEkC,YAAY,EAAE,GAAGrB;IAEzB,MAAMsB,eACJD,cAAcE,oBAAoBC,IAAI,WAClCC,6BACHC,qBAAqBC,KAAK,CAACC,QAAUA,MAAMC,IAAI,KAAKhB,aAAaE;IAEpEjB,UAAU;QACR,IAAI,CAACY,OA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BACZ,OAAO;YACT;YAEA,IAAI6C,iBAAwC;YAE5C3C,OAAO4C,cAAc,GAAGC,IAAI,CAAC;gBAC3B,MAAMpB,YAAY5C;gBAClB,IAAIG,kBAAkByC,YAAY;oBAChCkB,iBAAiBlB;gBACnB;YACF;YAEA,IAAIkB,gBAAgB;gBAClB,kCAAkC;gBAClCzC,YAAYJ;YACd;YACA,OAAO;QACT,GACAZ;IAGN,GAAG;QAACc;QAAQO;QAAeL;KAAY;IAEvC,MAAM4C,mBAAmBlC,cAAcmC,QAAQC,WAC3CzE,eAAeqC,cAAcmC,QAAQC,UAAUvC,QAC/CG,cAAcO;IAElB,qBACE,KAAC5B;QACC0D,MAAM9C;QACNL,YAAYA;QACZoD,aAAaxC,EAAE,CAAC,4BAA4B,EAAEP,aAAagD,KAAK,SAAS,SAAS,CAAC,EAAE;YACnFC,OAAON,oBAAoBpC,EAAE;QAC/B;QACA2C,YAAW;QACXC,oBAAoB,CAACC,SAASN;YAC5BhD,WAAWH;YACX,IAAI,CAACmD,MAAM;gBACT;YACF;YAEAA,KAAK5C,SAAS,GAAGA;YAEjBL,OAAOwD,eAAe,CAAC5D,6BAA6BqD;QACtD;QACAQ,kBAAkBtD,aAAaE;;AAGrC,EAAC"}
@@ -1,5 +1,6 @@
1
+ import type { Block } from 'payload';
1
2
  import type { NodeValidation } from '../typesServer.js';
2
- import type { BlocksFeatureProps } from './feature.server.js';
3
3
  import type { SerializedBlockNode } from './nodes/BlocksNode.js';
4
- export declare const blockValidationHOC: (props: BlocksFeatureProps) => NodeValidation<SerializedBlockNode>;
4
+ import type { SerializedInlineBlockNode } from './nodes/InlineBlocksNode.js';
5
+ export declare const blockValidationHOC: (blocks: Block[]) => NodeValidation<SerializedBlockNode | SerializedInlineBlockNode>;
5
6
  //# sourceMappingURL=validate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/features/blocks/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAe,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE7E,eAAO,MAAM,kBAAkB,UACtB,kBAAkB,KACxB,cAAc,CAAC,mBAAmB,CA2CpC,CAAA"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/features/blocks/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAe,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC7E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAE5E,eAAO,MAAM,kBAAkB,WACrB,KAAK,EAAE,KACd,cAAc,CAAC,mBAAmB,GAAG,yBAAyB,CA2ChE,CAAA"}
@@ -1,10 +1,10 @@
1
1
  import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema';
2
- export const blockValidationHOC = (props)=>{
2
+ export const blockValidationHOC = (blocks)=>{
3
3
  return async ({ node, validation })=>{
4
4
  const blockFieldData = node.fields ?? {};
5
5
  const { options: { id, operation, preferences, req } } = validation;
6
6
  // find block
7
- const block = props.blocks.find((block)=>block.slug === blockFieldData.blockType);
7
+ const block = blocks.find((block)=>block.slug === blockFieldData.blockType);
8
8
  // validate block
9
9
  if (!block) {
10
10
  return 'Block not found';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/features/blocks/validate.ts"],"sourcesContent":["import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\n\nimport type { NodeValidation } from '../typesServer.js'\nimport type { BlocksFeatureProps } from './feature.server.js'\nimport type { BlockFields, SerializedBlockNode } from './nodes/BlocksNode.js'\n\nexport const blockValidationHOC = (\n props: BlocksFeatureProps,\n): NodeValidation<SerializedBlockNode> => {\n return async ({ node, validation }) => {\n const blockFieldData = node.fields ?? ({} as BlockFields)\n\n const {\n options: { id, operation, preferences, req },\n } = validation\n\n // find block\n const block = props.blocks.find((block) => block.slug === blockFieldData.blockType)\n\n // validate block\n if (!block) {\n return 'Block not found'\n }\n\n /**\n * Run buildStateFromSchema as that properly validates block and block sub-fields\n */\n\n const result = await buildStateFromSchema({\n id,\n data: blockFieldData,\n fieldSchema: block.fields,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n preferences,\n req,\n siblingData: blockFieldData,\n })\n\n let errorPaths = []\n for (const fieldKey in result) {\n if (result[fieldKey].errorPaths) {\n errorPaths = errorPaths.concat(result[fieldKey].errorPaths)\n }\n }\n\n if (errorPaths.length) {\n return 'The following fields are invalid: ' + errorPaths.join(', ')\n }\n\n return true\n }\n}\n"],"names":["buildStateFromSchema","blockValidationHOC","props","node","validation","blockFieldData","fields","options","id","operation","preferences","req","block","blocks","find","slug","blockType","result","data","fieldSchema","siblingData","errorPaths","fieldKey","concat","length","join"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,4CAA2C;AAMhF,OAAO,MAAMC,qBAAqB,CAChCC;IAEA,OAAO,OAAO,EAAEC,IAAI,EAAEC,UAAU,EAAE;QAChC,MAAMC,iBAAiBF,KAAKG,MAAM,IAAK,CAAC;QAExC,MAAM,EACJC,SAAS,EAAEC,EAAE,EAAEC,SAAS,EAAEC,WAAW,EAAEC,GAAG,EAAE,EAC7C,GAAGP;QAEJ,aAAa;QACb,MAAMQ,QAAQV,MAAMW,MAAM,CAACC,IAAI,CAAC,CAACF,QAAUA,MAAMG,IAAI,KAAKV,eAAeW,SAAS;QAElF,iBAAiB;QACjB,IAAI,CAACJ,OAAO;YACV,OAAO;QACT;QAEA;;KAEC,GAED,MAAMK,SAAS,MAAMjB,qBAAqB;YACxCQ;YACAU,MAAMb;YACNc,aAAaP,MAAMN,MAAM;YACzBG,WAAWA,cAAc,YAAYA,cAAc,WAAWA,YAAY;YAC1EC;YACAC;YACAS,aAAaf;QACf;QAEA,IAAIgB,aAAa,EAAE;QACnB,IAAK,MAAMC,YAAYL,OAAQ;YAC7B,IAAIA,MAAM,CAACK,SAAS,CAACD,UAAU,EAAE;gBAC/BA,aAAaA,WAAWE,MAAM,CAACN,MAAM,CAACK,SAAS,CAACD,UAAU;YAC5D;QACF;QAEA,IAAIA,WAAWG,MAAM,EAAE;YACrB,OAAO,uCAAuCH,WAAWI,IAAI,CAAC;QAChE;QAEA,OAAO;IACT;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/features/blocks/validate.ts"],"sourcesContent":["import type { Block } from 'payload'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\n\nimport type { NodeValidation } from '../typesServer.js'\nimport type { BlockFields, SerializedBlockNode } from './nodes/BlocksNode.js'\nimport type { SerializedInlineBlockNode } from './nodes/InlineBlocksNode.js'\n\nexport const blockValidationHOC = (\n blocks: Block[],\n): NodeValidation<SerializedBlockNode | SerializedInlineBlockNode> => {\n return async ({ node, validation }) => {\n const blockFieldData = node.fields ?? ({} as BlockFields)\n\n const {\n options: { id, operation, preferences, req },\n } = validation\n\n // find block\n const block = blocks.find((block) => block.slug === blockFieldData.blockType)\n\n // validate block\n if (!block) {\n return 'Block not found'\n }\n\n /**\n * Run buildStateFromSchema as that properly validates block and block sub-fields\n */\n\n const result = await buildStateFromSchema({\n id,\n data: blockFieldData,\n fieldSchema: block.fields,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n preferences,\n req,\n siblingData: blockFieldData,\n })\n\n let errorPaths = []\n for (const fieldKey in result) {\n if (result[fieldKey].errorPaths) {\n errorPaths = errorPaths.concat(result[fieldKey].errorPaths)\n }\n }\n\n if (errorPaths.length) {\n return 'The following fields are invalid: ' + errorPaths.join(', ')\n }\n\n return true\n }\n}\n"],"names":["buildStateFromSchema","blockValidationHOC","blocks","node","validation","blockFieldData","fields","options","id","operation","preferences","req","block","find","slug","blockType","result","data","fieldSchema","siblingData","errorPaths","fieldKey","concat","length","join"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,4CAA2C;AAMhF,OAAO,MAAMC,qBAAqB,CAChCC;IAEA,OAAO,OAAO,EAAEC,IAAI,EAAEC,UAAU,EAAE;QAChC,MAAMC,iBAAiBF,KAAKG,MAAM,IAAK,CAAC;QAExC,MAAM,EACJC,SAAS,EAAEC,EAAE,EAAEC,SAAS,EAAEC,WAAW,EAAEC,GAAG,EAAE,EAC7C,GAAGP;QAEJ,aAAa;QACb,MAAMQ,QAAQV,OAAOW,IAAI,CAAC,CAACD,QAAUA,MAAME,IAAI,KAAKT,eAAeU,SAAS;QAE5E,iBAAiB;QACjB,IAAI,CAACH,OAAO;YACV,OAAO;QACT;QAEA;;KAEC,GAED,MAAMI,SAAS,MAAMhB,qBAAqB;YACxCQ;YACAS,MAAMZ;YACNa,aAAaN,MAAMN,MAAM;YACzBG,WAAWA,cAAc,YAAYA,cAAc,WAAWA,YAAY;YAC1EC;YACAC;YACAQ,aAAad;QACf;QAEA,IAAIe,aAAa,EAAE;QACnB,IAAK,MAAMC,YAAYL,OAAQ;YAC7B,IAAIA,MAAM,CAACK,SAAS,CAACD,UAAU,EAAE;gBAC/BA,aAAaA,WAAWE,MAAM,CAACN,MAAM,CAACK,SAAS,CAACD,UAAU;YAC5D;QACF;QAEA,IAAIA,WAAWG,MAAM,EAAE;YACrB,OAAO,uCAAuCH,WAAWI,IAAI,CAAC;QAChE;QAEA,OAAO;IACT;AACF,EAAC"}
@@ -3,7 +3,6 @@ import React from 'react';
3
3
  import type { RelationshipData } from '../RelationshipNode.js';
4
4
  import './index.scss';
5
5
  type Props = {
6
- children?: React.ReactNode;
7
6
  className?: string;
8
7
  data: RelationshipData;
9
8
  format?: ElementFormatType;
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipComponent.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/nodes/components/RelationshipComponent.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAgBhD,OAAO,KAA+D,MAAM,OAAO,CAAA;AAEnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAK9D,OAAO,cAAc,CAAA;AAQrB,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AA8JD,eAAO,MAAM,qBAAqB,UAAW,KAAK,KAAG,KAAK,CAAC,SAE1D,CAAA"}
1
+ {"version":3,"file":"RelationshipComponent.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/nodes/components/RelationshipComponent.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAgBhD,OAAO,KAA+D,MAAM,OAAO,CAAA;AAEnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAK9D,OAAO,cAAc,CAAA;AAQrB,KAAK,KAAK,GAAG;IACX,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AA4JD,eAAO,MAAM,qBAAqB,UAAW,KAAK,KAAG,KAAK,CAAC,SAE1D,CAAA"}
@@ -15,7 +15,7 @@ const initialParams = {
15
15
  depth: 0
16
16
  };
17
17
  const Component = (props)=>{
18
- const { children, data: { relationTo, value: id }, nodeKey } = props;
18
+ const { data: { relationTo, value: id }, nodeKey } = props;
19
19
  const relationshipElemRef = useRef(null);
20
20
  const [editor] = useLexicalComposerContext();
21
21
  const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
@@ -158,8 +158,7 @@ const Component = (props)=>{
158
158
  }),
159
159
  id && /*#__PURE__*/ _jsx(DocumentDrawer, {
160
160
  onSave: updateRelationship
161
- }),
162
- children
161
+ })
163
162
  ]
164
163
  });
165
164
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/features/relationship/nodes/components/RelationshipComponent.tsx"],"sourcesContent":["'use client'\nimport type { ElementFormatType } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport { mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport { Button, useConfig, useDocumentDrawer, usePayloadAPI, useTranslation } from '@payloadcms/ui'\nimport {\n $getNodeByKey,\n $getSelection,\n $isNodeSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_LOW,\n KEY_BACKSPACE_COMMAND,\n KEY_DELETE_COMMAND,\n} from 'lexical'\nimport React, { useCallback, useEffect, useReducer, useRef, useState } from 'react'\n\nimport type { RelationshipData } from '../RelationshipNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../../drawer/commands.js'\nimport { $isRelationshipNode } from '../RelationshipNode.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-relationship'\n\nconst initialParams = {\n depth: 0,\n}\n\ntype Props = {\n children?: React.ReactNode\n className?: string\n data: RelationshipData\n format?: ElementFormatType\n nodeKey?: string\n}\n\nconst Component: React.FC<Props> = (props) => {\n const {\n children,\n data: { relationTo, value: id },\n nodeKey,\n } = props\n\n const relationshipElemRef = useRef<HTMLDivElement | null>(null)\n\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n const { field } = useEditorConfigContext()\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const [relatedCollection, setRelatedCollection] = useState(() =>\n collections.find((coll) => coll.slug === relationTo),\n )\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${id}`,\n { initialParams },\n )\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id,\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 ({ doc }) => {\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 [cacheBust, setParams, closeDrawer],\n )\n\n const $onDelete = useCallback(\n (payload: KeyboardEvent) => {\n if (isSelected && $isNodeSelection($getSelection())) {\n const event: KeyboardEvent = payload\n event.preventDefault()\n const node = $getNodeByKey(nodeKey)\n if ($isRelationshipNode(node)) {\n node.remove()\n return true\n }\n }\n return false\n },\n [isSelected, nodeKey],\n )\n const onClick = useCallback(\n (payload: MouseEvent) => {\n const event = payload\n // Check if relationshipElemRef.target or anything WITHIN relationshipElemRef.target was clicked\n if (\n event.target === relationshipElemRef.current ||\n relationshipElemRef.current?.contains(event.target as Node)\n ) {\n if (event.shiftKey) {\n setSelected(!isSelected)\n } else {\n if (!isSelected) {\n clearSelection()\n setSelected(true)\n }\n }\n return true\n }\n\n return false\n },\n [isSelected, setSelected, clearSelection],\n )\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand<MouseEvent>(CLICK_COMMAND, onClick, COMMAND_PRIORITY_LOW),\n\n editor.registerCommand(KEY_DELETE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_BACKSPACE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n )\n }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected, onClick])\n\n return (\n <div\n className={[baseClass, isSelected && `${baseClass}--selected`].filter(Boolean).join(' ')}\n contentEditable={false}\n ref={relationshipElemRef}\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 ? data[relatedCollection?.admin?.useAsTitle || 'id'] : id}\n </p>\n </DocumentDrawerToggler>\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swapButton`}\n disabled={field?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\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 {id && <DocumentDrawer onSave={updateRelationship} />}\n {children}\n </div>\n )\n}\n\nexport const RelationshipComponent = (props: Props): React.ReactNode => {\n return <Component {...props} />\n}\n"],"names":["useLexicalComposerContext","useLexicalNodeSelection","mergeRegister","getTranslation","Button","useConfig","useDocumentDrawer","usePayloadAPI","useTranslation","$getNodeByKey","$getSelection","$isNodeSelection","CLICK_COMMAND","COMMAND_PRIORITY_LOW","KEY_BACKSPACE_COMMAND","KEY_DELETE_COMMAND","React","useCallback","useEffect","useReducer","useRef","useState","useEditorConfigContext","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","$isRelationshipNode","baseClass","initialParams","depth","Component","props","children","data","relationTo","value","id","nodeKey","relationshipElemRef","editor","isSelected","setSelected","clearSelection","field","collections","routes","api","serverURL","relatedCollection","setRelatedCollection","find","coll","slug","i18n","t","cacheBust","dispatchCacheBust","state","setParams","DocumentDrawer","DocumentDrawerToggler","closeDrawer","collectionSlug","removeRelationship","update","remove","updateRelationship","doc","$onDelete","payload","event","preventDefault","node","onClick","target","current","contains","shiftKey","registerCommand","div","className","filter","Boolean","join","contentEditable","ref","p","label","labels","singular","admin","useAsTitle","isEditable","buttonStyle","disabled","readOnly","el","icon","dispatchCommand","replace","round","tooltip","e","onSave","RelationshipComponent"],"mappings":"AAAA;;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,4CAA2C;AACnF,SAASC,aAAa,QAAQ,iBAAgB;AAC9C,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,MAAM,EAAEC,SAAS,EAAEC,iBAAiB,EAAEC,aAAa,EAAEC,cAAc,QAAQ,iBAAgB;AACpG,SACEC,aAAa,EACbC,aAAa,EACbC,gBAAgB,EAChBC,aAAa,EACbC,oBAAoB,EACpBC,qBAAqB,EACrBC,kBAAkB,QACb,UAAS;AAChB,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAInF,SAASC,sBAAsB,QAAQ,4DAA2D;AAClG,SAASC,uCAAuC,QAAQ,2BAA0B;AAClF,SAASC,mBAAmB,QAAQ,yBAAwB;AAG5D,MAAMC,YAAY;AAElB,MAAMC,gBAAgB;IACpBC,OAAO;AACT;AAUA,MAAMC,YAA6B,CAACC;IAClC,MAAM,EACJC,QAAQ,EACRC,MAAM,EAAEC,UAAU,EAAEC,OAAOC,EAAE,EAAE,EAC/BC,OAAO,EACR,GAAGN;IAEJ,MAAMO,sBAAsBhB,OAA8B;IAE1D,MAAM,CAACiB,OAAO,GAAGrC;IACjB,MAAM,CAACsC,YAAYC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,OAAOC,cAAc,KAAK,GAAGvD;;;;;YAIlEG,OAAOqD,UAAU,oBAChB,MAACb;gBAAIC,WAAW,CAAC,EAAErD,UAAU,SAAS,CAAC;;kCACrC,KAACrB;wBACCuF,aAAY;wBACZb,WAAW,CAAC,EAAErD,UAAU,YAAY,CAAC;wBACrCmE,UAAUnD,OAAOoD;wBACjBC,IAAG;wBACHC,MAAK;wBACLxB,SAAS;4BACPlC,OAAO2D,eAAe,CAACzE,yCAAyC;gCAC9D0E,SAAS;oCAAE9D;gCAAQ;4BACrB;wBACF;wBACA+D,KAAK;wBACLC,SAAS/C,EAAE;;kCAEb,KAAChD;wBACCuF,aAAY;wBACZb,WAAW,CAAC,EAAErD,UAAU,cAAc,CAAC;wBACvCmE,UAAUnD,OAAOoD;wBACjBE,MAAK;wBACLxB,SAAS,CAAC6B;4BACRA,EAAE/B,cAAc;4BAChBR;wBACF;wBACAqC,KAAK;wBACLC,SAAS/C,EAAE;;;;YAKhBlB,oBAAM,KAACuB;gBAAe4C,QAAQrC;;YAC9BlC;;;AAGP;AAEA,OAAO,MAAMwE,wBAAwB,CAACzE;IACpC,qBAAO,KAACD;QAAW,GAAGC,KAAK;;AAC7B,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/features/relationship/nodes/components/RelationshipComponent.tsx"],"sourcesContent":["'use client'\nimport type { ElementFormatType } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport { mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport { Button, useConfig, useDocumentDrawer, usePayloadAPI, useTranslation } from '@payloadcms/ui'\nimport {\n $getNodeByKey,\n $getSelection,\n $isNodeSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_LOW,\n KEY_BACKSPACE_COMMAND,\n KEY_DELETE_COMMAND,\n} from 'lexical'\nimport React, { useCallback, useEffect, useReducer, useRef, useState } from 'react'\n\nimport type { RelationshipData } from '../RelationshipNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../../drawer/commands.js'\nimport { $isRelationshipNode } from '../RelationshipNode.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-relationship'\n\nconst initialParams = {\n depth: 0,\n}\n\ntype Props = {\n className?: string\n data: RelationshipData\n format?: ElementFormatType\n nodeKey?: string\n}\n\nconst Component: React.FC<Props> = (props) => {\n const {\n data: { relationTo, value: id },\n nodeKey,\n } = props\n\n const relationshipElemRef = useRef<HTMLDivElement | null>(null)\n\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n const { field } = useEditorConfigContext()\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const [relatedCollection, setRelatedCollection] = useState(() =>\n collections.find((coll) => coll.slug === relationTo),\n )\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${id}`,\n { initialParams },\n )\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id,\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 ({ doc }) => {\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 [cacheBust, setParams, closeDrawer],\n )\n\n const $onDelete = useCallback(\n (payload: KeyboardEvent) => {\n if (isSelected && $isNodeSelection($getSelection())) {\n const event: KeyboardEvent = payload\n event.preventDefault()\n const node = $getNodeByKey(nodeKey)\n if ($isRelationshipNode(node)) {\n node.remove()\n return true\n }\n }\n return false\n },\n [isSelected, nodeKey],\n )\n const onClick = useCallback(\n (payload: MouseEvent) => {\n const event = payload\n // Check if relationshipElemRef.target or anything WITHIN relationshipElemRef.target was clicked\n if (\n event.target === relationshipElemRef.current ||\n relationshipElemRef.current?.contains(event.target as Node)\n ) {\n if (event.shiftKey) {\n setSelected(!isSelected)\n } else {\n if (!isSelected) {\n clearSelection()\n setSelected(true)\n }\n }\n return true\n }\n\n return false\n },\n [isSelected, setSelected, clearSelection],\n )\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand<MouseEvent>(CLICK_COMMAND, onClick, COMMAND_PRIORITY_LOW),\n\n editor.registerCommand(KEY_DELETE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_BACKSPACE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n )\n }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected, onClick])\n\n return (\n <div\n className={[baseClass, isSelected && `${baseClass}--selected`].filter(Boolean).join(' ')}\n contentEditable={false}\n ref={relationshipElemRef}\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 ? data[relatedCollection?.admin?.useAsTitle || 'id'] : id}\n </p>\n </DocumentDrawerToggler>\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swapButton`}\n disabled={field?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\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 {id && <DocumentDrawer onSave={updateRelationship} />}\n </div>\n )\n}\n\nexport const RelationshipComponent = (props: Props): React.ReactNode => {\n return <Component {...props} />\n}\n"],"names":["useLexicalComposerContext","useLexicalNodeSelection","mergeRegister","getTranslation","Button","useConfig","useDocumentDrawer","usePayloadAPI","useTranslation","$getNodeByKey","$getSelection","$isNodeSelection","CLICK_COMMAND","COMMAND_PRIORITY_LOW","KEY_BACKSPACE_COMMAND","KEY_DELETE_COMMAND","React","useCallback","useEffect","useReducer","useRef","useState","useEditorConfigContext","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","$isRelationshipNode","baseClass","initialParams","depth","Component","props","data","relationTo","value","id","nodeKey","relationshipElemRef","editor","isSelected","setSelected","clearSelection","field","collections","routes","api","serverURL","relatedCollection","setRelatedCollection","find","coll","slug","i18n","t","cacheBust","dispatchCacheBust","state","setParams","DocumentDrawer","DocumentDrawerToggler","closeDrawer","collectionSlug","removeRelationship","update","remove","updateRelationship","doc","$onDelete","payload","event","preventDefault","node","onClick","target","current","contains","shiftKey","registerCommand","div","className","filter","Boolean","join","contentEditable","ref","p","label","labels","singular","admin","useAsTitle","isEditable","buttonStyle","disabled","readOnly","el","icon","dispatchCommand","replace","round","tooltip","e","onSave","RelationshipComponent"],"mappings":"AAAA;;AAGA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,4CAA2C;AACnF,SAASC,aAAa,QAAQ,iBAAgB;AAC9C,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,MAAM,EAAEC,SAAS,EAAEC,iBAAiB,EAAEC,aAAa,EAAEC,cAAc,QAAQ,iBAAgB;AACpG,SACEC,aAAa,EACbC,aAAa,EACbC,gBAAgB,EAChBC,aAAa,EACbC,oBAAoB,EACpBC,qBAAqB,EACrBC,k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