@webiny/lexical-nodes 6.3.0 → 6.4.0-beta.1

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 (45) hide show
  1. package/FontColorNode.js +94 -119
  2. package/FontColorNode.js.map +1 -1
  3. package/HeadingNode.js +160 -183
  4. package/HeadingNode.js.map +1 -1
  5. package/ImageNode.js +101 -131
  6. package/ImageNode.js.map +1 -1
  7. package/LinkNode.js +228 -315
  8. package/LinkNode.js.map +1 -1
  9. package/ListItemNode.js +249 -320
  10. package/ListItemNode.js.map +1 -1
  11. package/ListNode.js +174 -223
  12. package/ListNode.js.map +1 -1
  13. package/ParagraphNode.js +119 -148
  14. package/ParagraphNode.js.map +1 -1
  15. package/QuoteNode.js +97 -102
  16. package/QuoteNode.js.map +1 -1
  17. package/components/ImageNode/ImageComponent.js +117 -147
  18. package/components/ImageNode/ImageComponent.js.map +1 -1
  19. package/components/ImageNode/ImageResizer.js +167 -194
  20. package/components/ImageNode/ImageResizer.js.map +1 -1
  21. package/generateInitialLexicalValue.js +20 -23
  22. package/generateInitialLexicalValue.js.map +1 -1
  23. package/index.js +38 -26
  24. package/index.js.map +1 -1
  25. package/package.json +4 -4
  26. package/prepareLexicalState.js +30 -43
  27. package/prepareLexicalState.js.map +1 -1
  28. package/types.js +0 -3
  29. package/utils/clearNodeFormating.js +14 -15
  30. package/utils/clearNodeFormating.js.map +1 -1
  31. package/utils/formatList.js +277 -368
  32. package/utils/formatList.js.map +1 -1
  33. package/utils/formatToHeading.js +6 -13
  34. package/utils/formatToHeading.js.map +1 -1
  35. package/utils/formatToParagraph.js +6 -7
  36. package/utils/formatToParagraph.js.map +1 -1
  37. package/utils/formatToQuote.js +6 -13
  38. package/utils/formatToQuote.js.map +1 -1
  39. package/utils/getStyleId.js +6 -11
  40. package/utils/getStyleId.js.map +1 -1
  41. package/utils/listNode.js +60 -84
  42. package/utils/listNode.js.map +1 -1
  43. package/utils/toggleLink.js +67 -118
  44. package/utils/toggleLink.js.map +1 -1
  45. package/types.js.map +0 -1
package/ParagraphNode.js CHANGED
@@ -1,159 +1,130 @@
1
- import { ParagraphNode as BaseParagraphNode, addClassNamesToElement } from "lexical";
1
+ import { ParagraphNode, addClassNamesToElement } from "lexical";
2
2
  import { Theme } from "@webiny/lexical-theme";
3
3
  import { getStyleId } from "./utils/getStyleId.js";
4
4
  function convertParagraphElement(element) {
5
- const node = $createParagraphNode();
6
- if (element.style) {
7
- node.setFormat(element.style.textAlign);
8
- }
9
- return {
10
- node
11
- };
12
- }
13
- export class ParagraphNode extends BaseParagraphNode {
14
- constructor(options = {}) {
15
- const {
16
- styleId,
17
- key,
18
- className
19
- } = options;
20
- super(key);
21
- this.__styleId = styleId;
22
- this.__className = className;
23
- }
24
- getStyleId() {
25
- return this.__styleId;
26
- }
27
- setStyleId(styleId) {
28
- this.__styleId = styleId;
29
- }
30
- setClassName(className) {
31
- this.__className = className;
32
- }
33
- getClassName() {
34
- return this.__className;
35
- }
36
- static getType() {
37
- return "wby-paragraph";
38
- }
39
- static clone(node) {
40
- return new ParagraphNode({
41
- styleId: node.getStyleId(),
42
- className: node.getClassName(),
43
- key: node.__key
44
- });
45
- }
46
- insertNewAfter(rangeSelection, restoreSelection) {
47
- const newElement = $createParagraphNode();
48
- newElement.setTextFormat(rangeSelection.format);
49
- newElement.setTextStyle(rangeSelection.style);
50
- const direction = this.getDirection();
51
- newElement.setDirection(direction);
52
- newElement.setFormat(this.getFormatType());
53
- newElement.setStyle(this.getStyle());
54
- this.insertAfter(newElement, restoreSelection);
55
- return newElement;
56
- }
57
- createDOM(config) {
58
- const element = super.createDOM(config);
59
- return this.updateElementWithThemeClasses(element, Theme.from(config.theme));
60
- }
61
- exportDOM(editor) {
62
- const base = super.exportDOM(editor);
63
- const element = base.element;
64
- if (element && this.__className) {
65
- element.classList.add(this.__className);
66
- }
67
- return {
68
- ...base,
69
- element
70
- };
71
- }
72
- updateDOM(prevNode, dom, config) {
73
- const prevTypoStyleId = prevNode.getStyleId();
74
- const nextTypoStyleId = this.getStyleId();
75
- if (!nextTypoStyleId) {
76
- this.updateElementWithThemeClasses(dom, Theme.from(config.theme));
77
- return false;
78
- }
79
- if (prevTypoStyleId !== nextTypoStyleId && nextTypoStyleId) {
80
- this.updateElementWithThemeClasses(dom, Theme.from(config.theme));
81
- }
82
- // Returning false tells Lexical that this node does not need its
83
- // DOM element replacing with a new copy from createDOM.
84
- return false;
85
- }
86
-
87
- /*
88
- * On copy/paste event this method will be executed in and create a node
89
- * */
90
- static importDOM() {
91
- return {
92
- p: () => ({
93
- conversion: convertParagraphElement,
94
- priority: 0
95
- })
96
- };
97
- }
98
-
99
- /*
100
- * Serialize the JSON data back into a node
101
- */
102
- static importJSON(serializedNode) {
103
5
  const node = $createParagraphNode();
104
- node.setFormat(serializedNode.format);
105
- node.setIndent(serializedNode.indent);
106
- node.setDirection(serializedNode.direction);
107
- const styleId = getStyleId({
108
- styleId: serializedNode.styleId,
109
- styles: serializedNode.styles
110
- });
111
- node.setStyleId(styleId);
112
- node.setClassName(serializedNode.className);
113
- return node;
114
- }
115
-
116
- /*
117
- * Serialize the node to JSON data representation.
118
- * */
119
- exportJSON() {
6
+ if (element.style) node.setFormat(element.style.textAlign);
120
7
  return {
121
- ...super.exportJSON(),
122
- styleId: this.__styleId,
123
- className: this.__className,
124
- type: "wby-paragraph"
8
+ node
125
9
  };
126
- }
127
- updateElementWithThemeClasses(element, theme) {
128
- if (!this.__styleId || !this.__className) {
129
- this.setDefaultTypography(theme, this.__styleId);
130
- }
131
- if (this.__className) {
132
- addClassNamesToElement(element, this.__className);
133
- }
134
- return element;
135
- }
136
- setDefaultTypography(theme, styleId) {
137
- let typographyStyle = theme.getTypographyByTag("p");
138
- if (styleId) {
139
- const byStyleId = theme.getTypographyById(styleId);
140
- if (byStyleId) {
141
- typographyStyle = byStyleId;
142
- }
143
- }
144
- if (typographyStyle) {
145
- this.__styleId = typographyStyle.id;
146
- this.__className = typographyStyle.className;
147
- }
148
- }
149
10
  }
150
- export function $createParagraphNode(styleId) {
151
- return new ParagraphNode({
152
- styleId
153
- });
11
+ class ParagraphNode_ParagraphNode extends ParagraphNode {
12
+ constructor(options = {}){
13
+ const { styleId, key, className } = options;
14
+ super(key);
15
+ this.__styleId = styleId;
16
+ this.__className = className;
17
+ }
18
+ getStyleId() {
19
+ return this.__styleId;
20
+ }
21
+ setStyleId(styleId) {
22
+ this.__styleId = styleId;
23
+ }
24
+ setClassName(className) {
25
+ this.__className = className;
26
+ }
27
+ getClassName() {
28
+ return this.__className;
29
+ }
30
+ static getType() {
31
+ return "wby-paragraph";
32
+ }
33
+ static clone(node) {
34
+ return new ParagraphNode_ParagraphNode({
35
+ styleId: node.getStyleId(),
36
+ className: node.getClassName(),
37
+ key: node.__key
38
+ });
39
+ }
40
+ insertNewAfter(rangeSelection, restoreSelection) {
41
+ const newElement = $createParagraphNode();
42
+ newElement.setTextFormat(rangeSelection.format);
43
+ newElement.setTextStyle(rangeSelection.style);
44
+ const direction = this.getDirection();
45
+ newElement.setDirection(direction);
46
+ newElement.setFormat(this.getFormatType());
47
+ newElement.setStyle(this.getStyle());
48
+ this.insertAfter(newElement, restoreSelection);
49
+ return newElement;
50
+ }
51
+ createDOM(config) {
52
+ const element = super.createDOM(config);
53
+ return this.updateElementWithThemeClasses(element, Theme.from(config.theme));
54
+ }
55
+ exportDOM(editor) {
56
+ const base = super.exportDOM(editor);
57
+ const element = base.element;
58
+ if (element && this.__className) element.classList.add(this.__className);
59
+ return {
60
+ ...base,
61
+ element
62
+ };
63
+ }
64
+ updateDOM(prevNode, dom, config) {
65
+ const prevTypoStyleId = prevNode.getStyleId();
66
+ const nextTypoStyleId = this.getStyleId();
67
+ if (!nextTypoStyleId) {
68
+ this.updateElementWithThemeClasses(dom, Theme.from(config.theme));
69
+ return false;
70
+ }
71
+ if (prevTypoStyleId !== nextTypoStyleId && nextTypoStyleId) this.updateElementWithThemeClasses(dom, Theme.from(config.theme));
72
+ return false;
73
+ }
74
+ static importDOM() {
75
+ return {
76
+ p: ()=>({
77
+ conversion: convertParagraphElement,
78
+ priority: 0
79
+ })
80
+ };
81
+ }
82
+ static importJSON(serializedNode) {
83
+ const node = $createParagraphNode();
84
+ node.setFormat(serializedNode.format);
85
+ node.setIndent(serializedNode.indent);
86
+ node.setDirection(serializedNode.direction);
87
+ const styleId = getStyleId({
88
+ styleId: serializedNode.styleId,
89
+ styles: serializedNode.styles
90
+ });
91
+ node.setStyleId(styleId);
92
+ node.setClassName(serializedNode.className);
93
+ return node;
94
+ }
95
+ exportJSON() {
96
+ return {
97
+ ...super.exportJSON(),
98
+ styleId: this.__styleId,
99
+ className: this.__className,
100
+ type: "wby-paragraph"
101
+ };
102
+ }
103
+ updateElementWithThemeClasses(element, theme) {
104
+ if (!this.__styleId || !this.__className) this.setDefaultTypography(theme, this.__styleId);
105
+ if (this.__className) addClassNamesToElement(element, this.__className);
106
+ return element;
107
+ }
108
+ setDefaultTypography(theme, styleId) {
109
+ let typographyStyle = theme.getTypographyByTag("p");
110
+ if (styleId) {
111
+ const byStyleId = theme.getTypographyById(styleId);
112
+ if (byStyleId) typographyStyle = byStyleId;
113
+ }
114
+ if (typographyStyle) {
115
+ this.__styleId = typographyStyle.id;
116
+ this.__className = typographyStyle.className;
117
+ }
118
+ }
119
+ }
120
+ function $createParagraphNode(styleId) {
121
+ return new ParagraphNode_ParagraphNode({
122
+ styleId
123
+ });
154
124
  }
155
- export function $isParagraphNode(node) {
156
- return node instanceof ParagraphNode;
125
+ function $isParagraphNode(node) {
126
+ return node instanceof ParagraphNode_ParagraphNode;
157
127
  }
128
+ export { $createParagraphNode, $isParagraphNode, ParagraphNode_ParagraphNode as ParagraphNode };
158
129
 
159
130
  //# sourceMappingURL=ParagraphNode.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ParagraphNode","BaseParagraphNode","addClassNamesToElement","Theme","getStyleId","convertParagraphElement","element","node","$createParagraphNode","style","setFormat","textAlign","constructor","options","styleId","key","className","__styleId","__className","setStyleId","setClassName","getClassName","getType","clone","__key","insertNewAfter","rangeSelection","restoreSelection","newElement","setTextFormat","format","setTextStyle","direction","getDirection","setDirection","getFormatType","setStyle","getStyle","insertAfter","createDOM","config","updateElementWithThemeClasses","from","theme","exportDOM","editor","base","classList","add","updateDOM","prevNode","dom","prevTypoStyleId","nextTypoStyleId","importDOM","p","conversion","priority","importJSON","serializedNode","setIndent","indent","styles","exportJSON","type","setDefaultTypography","typographyStyle","getTypographyByTag","byStyleId","getTypographyById","id","$isParagraphNode"],"sources":["ParagraphNode.ts"],"sourcesContent":["import type {\n DOMConversionMap,\n DOMConversionOutput,\n ElementFormatType,\n LexicalNode,\n NodeKey,\n SerializedParagraphNode as SerializedBaseParagraphNode,\n Spread,\n LexicalEditor,\n DOMExportOutput,\n RangeSelection\n} from \"lexical\";\nimport { ParagraphNode as BaseParagraphNode, addClassNamesToElement } from \"lexical\";\nimport type { EditorConfig } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\nimport type { TypographyStylesNode, ThemeStyleValue } from \"~/types.js\";\nimport { getStyleId } from \"./utils/getStyleId.js\";\n\nfunction convertParagraphElement(element: HTMLElement): DOMConversionOutput {\n const node = $createParagraphNode();\n if (element.style) {\n node.setFormat(element.style.textAlign as ElementFormatType);\n }\n\n return { node };\n}\n\nexport type SerializeParagraphNode = Spread<\n {\n styles?: ThemeStyleValue[];\n styleId?: string;\n className?: string;\n type: \"wby-paragraph\";\n },\n SerializedBaseParagraphNode\n>;\n\ninterface ParagraphNodeOptions {\n className?: string;\n styleId?: string;\n key?: NodeKey;\n}\n\nexport class ParagraphNode extends BaseParagraphNode implements TypographyStylesNode {\n private __styleId: string | undefined;\n private __className: string | undefined;\n\n constructor(options: ParagraphNodeOptions = {}) {\n const { styleId, key, className } = options;\n super(key);\n\n this.__styleId = styleId;\n this.__className = className;\n }\n\n getStyleId(): string | undefined {\n return this.__styleId;\n }\n\n setStyleId(styleId: string | undefined) {\n this.__styleId = styleId;\n }\n\n setClassName(className: string | undefined) {\n this.__className = className;\n }\n\n getClassName(): string | undefined {\n return this.__className;\n }\n\n static override getType(): string {\n return \"wby-paragraph\";\n }\n\n static override clone(node: ParagraphNode): ParagraphNode {\n return new ParagraphNode({\n styleId: node.getStyleId(),\n className: node.getClassName(),\n key: node.__key\n });\n }\n\n override insertNewAfter(\n rangeSelection: RangeSelection,\n restoreSelection: boolean\n ): ParagraphNode {\n const newElement = $createParagraphNode();\n newElement.setTextFormat(rangeSelection.format);\n newElement.setTextStyle(rangeSelection.style);\n const direction = this.getDirection();\n newElement.setDirection(direction);\n newElement.setFormat(this.getFormatType());\n newElement.setStyle(this.getStyle());\n this.insertAfter(newElement, restoreSelection);\n return newElement;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.updateElementWithThemeClasses(element, Theme.from(config.theme));\n }\n\n override exportDOM(editor: LexicalEditor): DOMExportOutput {\n const base = super.exportDOM(editor);\n\n const element = base.element as HTMLElement;\n if (element && this.__className) {\n element.classList.add(this.__className);\n }\n\n return { ...base, element };\n }\n\n override updateDOM(prevNode: ParagraphNode, dom: HTMLElement, config: EditorConfig): boolean {\n const prevTypoStyleId = prevNode.getStyleId();\n const nextTypoStyleId = this.getStyleId();\n\n if (!nextTypoStyleId) {\n this.updateElementWithThemeClasses(dom, Theme.from(config.theme));\n return false;\n }\n\n if (prevTypoStyleId !== nextTypoStyleId && nextTypoStyleId) {\n this.updateElementWithThemeClasses(dom, Theme.from(config.theme));\n }\n // Returning false tells Lexical that this node does not need its\n // DOM element replacing with a new copy from createDOM.\n return false;\n }\n\n /*\n * On copy/paste event this method will be executed in and create a node\n * */\n static override importDOM(): DOMConversionMap | null {\n return {\n p: () => ({\n conversion: convertParagraphElement,\n priority: 0\n })\n };\n }\n\n /*\n * Serialize the JSON data back into a node\n */\n static override importJSON(serializedNode: SerializeParagraphNode): BaseParagraphNode {\n const node = $createParagraphNode();\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n\n const styleId = getStyleId({\n styleId: serializedNode.styleId,\n styles: serializedNode.styles\n });\n\n node.setStyleId(styleId);\n node.setClassName(serializedNode.className);\n return node;\n }\n\n /*\n * Serialize the node to JSON data representation.\n * */\n override exportJSON(): SerializeParagraphNode {\n return {\n ...super.exportJSON(),\n styleId: this.__styleId,\n className: this.__className,\n type: \"wby-paragraph\"\n };\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: Theme): HTMLElement {\n if (!this.__styleId || !this.__className) {\n this.setDefaultTypography(theme, this.__styleId);\n }\n\n if (this.__className) {\n addClassNamesToElement(element, this.__className);\n }\n\n return element;\n }\n\n private setDefaultTypography(theme: Theme, styleId?: string) {\n let typographyStyle = theme.getTypographyByTag(\"p\");\n if (styleId) {\n const byStyleId = theme.getTypographyById(styleId);\n if (byStyleId) {\n typographyStyle = byStyleId;\n }\n }\n\n if (typographyStyle) {\n this.__styleId = typographyStyle.id;\n this.__className = typographyStyle.className;\n }\n }\n}\n\nexport function $createParagraphNode(styleId?: string): ParagraphNode {\n return new ParagraphNode({ styleId });\n}\n\nexport function $isParagraphNode(node: LexicalNode | null | undefined): node is ParagraphNode {\n return node instanceof ParagraphNode;\n}\n"],"mappings":"AAYA,SAASA,aAAa,IAAIC,iBAAiB,EAAEC,sBAAsB,QAAQ,SAAS;AAEpF,SAASC,KAAK,QAAQ,uBAAuB;AAE7C,SAASC,UAAU;AAEnB,SAASC,uBAAuBA,CAACC,OAAoB,EAAuB;EACxE,MAAMC,IAAI,GAAGC,oBAAoB,CAAC,CAAC;EACnC,IAAIF,OAAO,CAACG,KAAK,EAAE;IACfF,IAAI,CAACG,SAAS,CAACJ,OAAO,CAACG,KAAK,CAACE,SAA8B,CAAC;EAChE;EAEA,OAAO;IAAEJ;EAAK,CAAC;AACnB;AAkBA,OAAO,MAAMP,aAAa,SAASC,iBAAiB,CAAiC;EAIjFW,WAAWA,CAACC,OAA6B,GAAG,C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KAAY,EAAE7B,OAAgB,EAAE;IACzD,IAAIoD,eAAe,GAAGvB,KAAK,CAACwB,kBAAkB,CAAC,GAAG,CAAC;IACnD,IAAIrD,OAAO,EAAE;MACT,MAAMsD,SAAS,GAAGzB,KAAK,CAAC0B,iBAAiB,CAACvD,OAAO,CAAC;MAClD,IAAIsD,SAAS,EAAE;QACXF,eAAe,GAAGE,SAAS;MAC/B;IACJ;IAEA,IAAIF,eAAe,EAAE;MACjB,IAAI,CAACjD,SAAS,GAAGiD,eAAe,CAACI,EAAE;MACnC,IAAI,CAACpD,WAAW,GAAGgD,eAAe,CAAClD,SAAS;IAChD;EACJ;AACJ;AAEA,OAAO,SAASR,oBAAoBA,CAACM,OAAgB,EAAiB;EAClE,OAAO,IAAId,aAAa,CAAC;IAAEc;EAAQ,CAAC,CAAC;AACzC;AAEA,OAAO,SAASyD,gBAAgBA,CAAChE,IAAoC,EAAyB;EAC1F,OAAOA,IAAI,YAAYP,aAAa;AACxC","ignoreList":[]}
1
+ {"version":3,"file":"ParagraphNode.js","sources":["../src/ParagraphNode.ts"],"sourcesContent":["import type {\n DOMConversionMap,\n DOMConversionOutput,\n ElementFormatType,\n LexicalNode,\n NodeKey,\n SerializedParagraphNode as SerializedBaseParagraphNode,\n Spread,\n LexicalEditor,\n DOMExportOutput,\n RangeSelection\n} from \"lexical\";\nimport { ParagraphNode as BaseParagraphNode, addClassNamesToElement } from \"lexical\";\nimport type { EditorConfig } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\nimport type { TypographyStylesNode, ThemeStyleValue } from \"~/types.js\";\nimport { getStyleId } from \"./utils/getStyleId.js\";\n\nfunction convertParagraphElement(element: HTMLElement): DOMConversionOutput {\n const node = $createParagraphNode();\n if (element.style) {\n node.setFormat(element.style.textAlign as ElementFormatType);\n }\n\n return { node };\n}\n\nexport type SerializeParagraphNode = Spread<\n {\n styles?: ThemeStyleValue[];\n styleId?: string;\n className?: string;\n type: \"wby-paragraph\";\n },\n SerializedBaseParagraphNode\n>;\n\ninterface ParagraphNodeOptions {\n className?: string;\n styleId?: string;\n key?: NodeKey;\n}\n\nexport class ParagraphNode extends BaseParagraphNode implements TypographyStylesNode {\n private __styleId: string | undefined;\n private __className: string | undefined;\n\n constructor(options: ParagraphNodeOptions = {}) {\n const { styleId, key, className } = options;\n super(key);\n\n this.__styleId = styleId;\n this.__className = className;\n }\n\n getStyleId(): string | undefined {\n return this.__styleId;\n }\n\n setStyleId(styleId: string | undefined) {\n this.__styleId = styleId;\n }\n\n setClassName(className: string | undefined) {\n this.__className = className;\n }\n\n getClassName(): string | undefined {\n return this.__className;\n }\n\n static override getType(): string {\n return \"wby-paragraph\";\n }\n\n static override clone(node: ParagraphNode): ParagraphNode {\n return new ParagraphNode({\n styleId: node.getStyleId(),\n className: node.getClassName(),\n key: node.__key\n });\n }\n\n override insertNewAfter(\n rangeSelection: RangeSelection,\n restoreSelection: boolean\n ): ParagraphNode {\n const newElement = $createParagraphNode();\n newElement.setTextFormat(rangeSelection.format);\n newElement.setTextStyle(rangeSelection.style);\n const direction = this.getDirection();\n newElement.setDirection(direction);\n newElement.setFormat(this.getFormatType());\n newElement.setStyle(this.getStyle());\n this.insertAfter(newElement, restoreSelection);\n return newElement;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.updateElementWithThemeClasses(element, Theme.from(config.theme));\n }\n\n override exportDOM(editor: LexicalEditor): DOMExportOutput {\n const base = super.exportDOM(editor);\n\n const element = base.element as HTMLElement;\n if (element && this.__className) {\n element.classList.add(this.__className);\n }\n\n return { ...base, element };\n }\n\n override updateDOM(prevNode: ParagraphNode, dom: HTMLElement, config: EditorConfig): boolean {\n const prevTypoStyleId = prevNode.getStyleId();\n const nextTypoStyleId = this.getStyleId();\n\n if (!nextTypoStyleId) {\n this.updateElementWithThemeClasses(dom, Theme.from(config.theme));\n return false;\n }\n\n if (prevTypoStyleId !== nextTypoStyleId && nextTypoStyleId) {\n this.updateElementWithThemeClasses(dom, Theme.from(config.theme));\n }\n // Returning false tells Lexical that this node does not need its\n // DOM element replacing with a new copy from createDOM.\n return false;\n }\n\n /*\n * On copy/paste event this method will be executed in and create a node\n * */\n static override importDOM(): DOMConversionMap | null {\n return {\n p: () => ({\n conversion: convertParagraphElement,\n priority: 0\n })\n };\n }\n\n /*\n * Serialize the JSON data back into a node\n */\n static override importJSON(serializedNode: SerializeParagraphNode): BaseParagraphNode {\n const node = $createParagraphNode();\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n\n const styleId = getStyleId({\n styleId: serializedNode.styleId,\n styles: serializedNode.styles\n });\n\n node.setStyleId(styleId);\n node.setClassName(serializedNode.className);\n return node;\n }\n\n /*\n * Serialize the node to JSON data representation.\n * */\n override exportJSON(): SerializeParagraphNode {\n return {\n ...super.exportJSON(),\n styleId: this.__styleId,\n className: this.__className,\n type: \"wby-paragraph\"\n };\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: Theme): HTMLElement {\n if (!this.__styleId || !this.__className) {\n this.setDefaultTypography(theme, this.__styleId);\n }\n\n if (this.__className) {\n addClassNamesToElement(element, this.__className);\n }\n\n return element;\n }\n\n private setDefaultTypography(theme: Theme, styleId?: string) {\n let typographyStyle = theme.getTypographyByTag(\"p\");\n if (styleId) {\n const byStyleId = theme.getTypographyById(styleId);\n if (byStyleId) {\n typographyStyle = byStyleId;\n }\n }\n\n if (typographyStyle) {\n this.__styleId = typographyStyle.id;\n this.__className = typographyStyle.className;\n }\n }\n}\n\nexport function $createParagraphNode(styleId?: string): ParagraphNode {\n return new ParagraphNode({ styleId });\n}\n\nexport function $isParagraphNode(node: LexicalNode | null | undefined): node is ParagraphNode {\n return node instanceof ParagraphNode;\n}\n"],"names":["convertParagraphElement","element","node","$createParagraphNode","ParagraphNode","BaseParagraphNode","options","styleId","key","className","rangeSelection","restoreSelection","newElement","direction","config","Theme","editor","base","prevNode","dom","prevTypoStyleId","nextTypoStyleId","ser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;YACrB,SAAS,IAAI,CAAC,SAAS;YACvB,WAAW,IAAI,CAAC,WAAW;YAC3B,MAAM;QACV;IACJ;IAEU,8BAA8BD,OAAoB,EAAEuB,KAAY,EAAe;QACrF,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,WAAW,EACpC,IAAI,CAAC,oBAAoB,CAACA,OAAO,IAAI,CAAC,SAAS;QAGnD,IAAI,IAAI,CAAC,WAAW,EAChBC,uBAAuBxB,SAAS,IAAI,CAAC,WAAW;QAGpD,OAAOA;IACX;IAEQ,qBAAqBuB,KAAY,EAAEjB,OAAgB,EAAE;QACzD,IAAImB,kBAAkBF,MAAM,kBAAkB,CAAC;QAC/C,IAAIjB,SAAS;YACT,MAAMoB,YAAYH,MAAM,iBAAiB,CAACjB;YAC1C,IAAIoB,WACAD,kBAAkBC;QAE1B;QAEA,IAAID,iBAAiB;YACjB,IAAI,CAAC,SAAS,GAAGA,gBAAgB,EAAE;YACnC,IAAI,CAAC,WAAW,GAAGA,gBAAgB,SAAS;QAChD;IACJ;AACJ;AAEO,SAASvB,qBAAqBI,OAAgB;IACjD,OAAO,IAAIH,4BAAc;QAAEG;IAAQ;AACvC;AAEO,SAASqB,iBAAiB1B,IAAoC;IACjE,OAAOA,gBAAgBE;AAC3B"}
package/QuoteNode.js CHANGED
@@ -1,116 +1,111 @@
1
1
  import { $applyNodeReplacement, addClassNamesToElement } from "lexical";
2
2
  import { Theme } from "@webiny/lexical-theme";
3
- import { QuoteNode as BaseQuoteNode } from "@lexical/rich-text";
3
+ import { QuoteNode } from "@lexical/rich-text";
4
4
  import { getStyleId } from "./utils/getStyleId.js";
5
- export class QuoteNode extends BaseQuoteNode {
6
- constructor(options = {}) {
7
- super(options.key);
8
- this.__styleId = options?.styleId;
9
- this.__className = options?.className;
10
- }
11
- getStyleId() {
12
- return this.__styleId;
13
- }
14
- setStyleId(styleId) {
15
- this.__styleId = styleId;
16
- }
17
- setClassName(className) {
18
- this.__className = className;
19
- }
20
- getClassName() {
21
- return this.__className;
22
- }
23
- setDefaultTypography(theme) {
24
- // For some time in v5 we had `quoteblock` as tag name :facepalm: We must not break it.
25
- const typographyStyle = theme.getTypographyByTag(["blockquote", "quoteblock"]);
26
- if (typographyStyle) {
27
- this.__styleId = typographyStyle.id;
28
- this.__className = typographyStyle.className;
5
+ class QuoteNode_QuoteNode extends QuoteNode {
6
+ constructor(options = {}){
7
+ super(options.key);
8
+ this.__styleId = options?.styleId;
9
+ this.__className = options?.className;
29
10
  }
30
- }
31
- static getType() {
32
- return "wby-quote";
33
- }
34
- static clone(node) {
35
- return new QuoteNode({
36
- styleId: node.getStyleId(),
37
- className: node.getClassName(),
38
- key: node.getKey()
39
- });
40
- }
41
- createDOM(config) {
42
- const element = super.createDOM(config);
43
- return this.updateElementWithThemeClasses(element, Theme.from(config.theme));
44
- }
45
- exportDOM(editor) {
46
- const base = super.exportDOM(editor);
47
- const element = base.element;
48
- if (element && this.__className) {
49
- element.classList.add(this.__className);
11
+ getStyleId() {
12
+ return this.__styleId;
50
13
  }
51
- return {
52
- ...base,
53
- element
54
- };
55
- }
56
- static importDomConversionMap() {
57
- return {
58
- conversion: convertBlockquoteElement,
59
- priority: 0
60
- };
61
- }
62
- static importDOM() {
63
- return {
64
- blockquote: () => {
65
- return this.importDomConversionMap();
66
- }
67
- };
68
- }
69
- static importJSON(serializedNode) {
70
- const node = $createQuoteNode();
71
- node.setFormat(serializedNode.format);
72
- node.setIndent(serializedNode.indent);
73
- node.setDirection(serializedNode.direction);
74
- const styleId = getStyleId({
75
- styleId: serializedNode.styleId,
76
- styles: serializedNode.styles
77
- });
78
- node.setStyleId(styleId);
79
- node.setClassName(serializedNode.className);
80
- return node;
81
- }
82
- exportJSON() {
83
- return {
84
- ...super.exportJSON(),
85
- type: "wby-quote",
86
- className: this.__className,
87
- styleId: this.__styleId
88
- };
89
- }
90
- updateElementWithThemeClasses(element, theme) {
91
- if (!this.__styleId || !this.__className) {
92
- this.setDefaultTypography(theme);
14
+ setStyleId(styleId) {
15
+ this.__styleId = styleId;
16
+ }
17
+ setClassName(className) {
18
+ this.__className = className;
19
+ }
20
+ getClassName() {
21
+ return this.__className;
22
+ }
23
+ setDefaultTypography(theme) {
24
+ const typographyStyle = theme.getTypographyByTag([
25
+ "blockquote",
26
+ "quoteblock"
27
+ ]);
28
+ if (typographyStyle) {
29
+ this.__styleId = typographyStyle.id;
30
+ this.__className = typographyStyle.className;
31
+ }
93
32
  }
94
- if (this.__className) {
95
- addClassNamesToElement(element, this.__className);
33
+ static getType() {
34
+ return "wby-quote";
35
+ }
36
+ static clone(node) {
37
+ return new QuoteNode_QuoteNode({
38
+ styleId: node.getStyleId(),
39
+ className: node.getClassName(),
40
+ key: node.getKey()
41
+ });
42
+ }
43
+ createDOM(config) {
44
+ const element = super.createDOM(config);
45
+ return this.updateElementWithThemeClasses(element, Theme.from(config.theme));
46
+ }
47
+ exportDOM(editor) {
48
+ const base = super.exportDOM(editor);
49
+ const element = base.element;
50
+ if (element && this.__className) element.classList.add(this.__className);
51
+ return {
52
+ ...base,
53
+ element
54
+ };
55
+ }
56
+ static importDomConversionMap() {
57
+ return {
58
+ conversion: convertBlockquoteElement,
59
+ priority: 0
60
+ };
61
+ }
62
+ static importDOM() {
63
+ return {
64
+ blockquote: ()=>this.importDomConversionMap()
65
+ };
66
+ }
67
+ static importJSON(serializedNode) {
68
+ const node = $createQuoteNode();
69
+ node.setFormat(serializedNode.format);
70
+ node.setIndent(serializedNode.indent);
71
+ node.setDirection(serializedNode.direction);
72
+ const styleId = getStyleId({
73
+ styleId: serializedNode.styleId,
74
+ styles: serializedNode.styles
75
+ });
76
+ node.setStyleId(styleId);
77
+ node.setClassName(serializedNode.className);
78
+ return node;
79
+ }
80
+ exportJSON() {
81
+ return {
82
+ ...super.exportJSON(),
83
+ type: "wby-quote",
84
+ className: this.__className,
85
+ styleId: this.__styleId
86
+ };
87
+ }
88
+ updateElementWithThemeClasses(element, theme) {
89
+ if (!this.__styleId || !this.__className) this.setDefaultTypography(theme);
90
+ if (this.__className) addClassNamesToElement(element, this.__className);
91
+ return element;
96
92
  }
97
- return element;
98
- }
99
93
  }
100
94
  function convertBlockquoteElement() {
101
- const node = $createQuoteNode();
102
- return {
103
- node
104
- };
95
+ const node = $createQuoteNode();
96
+ return {
97
+ node
98
+ };
105
99
  }
106
- export function $createQuoteNode(styleId, key) {
107
- return $applyNodeReplacement(new QuoteNode({
108
- styleId,
109
- key
110
- }));
100
+ function $createQuoteNode(styleId, key) {
101
+ return $applyNodeReplacement(new QuoteNode_QuoteNode({
102
+ styleId,
103
+ key
104
+ }));
111
105
  }
112
- export function $isQuoteNode(node) {
113
- return node instanceof QuoteNode;
106
+ function $isQuoteNode(node) {
107
+ return node instanceof QuoteNode_QuoteNode;
114
108
  }
109
+ export { $createQuoteNode, $isQuoteNode, QuoteNode_QuoteNode as QuoteNode };
115
110
 
116
111
  //# sourceMappingURL=QuoteNode.js.map
package/QuoteNode.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["$applyNodeReplacement","addClassNamesToElement","Theme","QuoteNode","BaseQuoteNode","getStyleId","constructor","options","key","__styleId","styleId","__className","className","setStyleId","setClassName","getClassName","setDefaultTypography","theme","typographyStyle","getTypographyByTag","id","getType","clone","node","getKey","createDOM","config","element","updateElementWithThemeClasses","from","exportDOM","editor","base","classList","add","importDomConversionMap","conversion","convertBlockquoteElement","priority","importDOM","blockquote","importJSON","serializedNode","$createQuoteNode","setFormat","format","setIndent","indent","setDirection","direction","styles","exportJSON","type","$isQuoteNode"],"sources":["QuoteNode.ts"],"sourcesContent":["import type {\n DOMConversion,\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n Spread\n} from \"lexical\";\nimport { $applyNodeReplacement, addClassNamesToElement } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\nimport type { SerializedQuoteNode as BaseSerializedQuoteNode } from \"@lexical/rich-text\";\nimport { QuoteNode as BaseQuoteNode } from \"@lexical/rich-text\";\nimport type { ThemeStyleValue, TypographyStylesNode } from \"~/types.js\";\nimport { getStyleId } from \"~/utils/getStyleId.js\";\n\nexport type SerializedQuoteNode = Spread<\n {\n styleId?: string;\n styles?: ThemeStyleValue[];\n className?: string;\n type: \"wby-quote\";\n },\n BaseSerializedQuoteNode\n>;\n\ninterface QuoteNodeOptions {\n className?: string;\n styleId?: string;\n key?: NodeKey;\n}\n\nexport class QuoteNode extends BaseQuoteNode implements TypographyStylesNode {\n private __styleId: string | undefined;\n private __className: string | undefined;\n\n constructor(options: QuoteNodeOptions = {}) {\n super(options.key);\n this.__styleId = options?.styleId;\n this.__className = options?.className;\n }\n\n getStyleId(): string | undefined {\n return this.__styleId;\n }\n\n setStyleId(styleId: string | undefined) {\n this.__styleId = styleId;\n }\n\n setClassName(className: string | undefined) {\n this.__className = className;\n }\n\n getClassName(): string | undefined {\n return this.__className;\n }\n\n private setDefaultTypography(theme: Theme) {\n // For some time in v5 we had `quoteblock` as tag name :facepalm: We must not break it.\n const typographyStyle = theme.getTypographyByTag([\"blockquote\", \"quoteblock\"]);\n\n if (typographyStyle) {\n this.__styleId = typographyStyle.id;\n this.__className = typographyStyle.className;\n }\n }\n\n static override getType(): string {\n return \"wby-quote\";\n }\n\n static override clone(node: QuoteNode): QuoteNode {\n return new QuoteNode({\n styleId: node.getStyleId(),\n className: node.getClassName(),\n key: node.getKey()\n });\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.updateElementWithThemeClasses(element, Theme.from(config.theme));\n }\n\n override exportDOM(editor: LexicalEditor): DOMExportOutput {\n const base = super.exportDOM(editor);\n\n const element = base.element as HTMLElement;\n if (element && this.__className) {\n element.classList.add(this.__className);\n }\n\n return { ...base, element };\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertBlockquoteElement,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n blockquote: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n static override importJSON(serializedNode: SerializedQuoteNode): QuoteNode {\n const node = $createQuoteNode();\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n\n const styleId = getStyleId({\n styleId: serializedNode.styleId,\n styles: serializedNode.styles\n });\n\n node.setStyleId(styleId);\n node.setClassName(serializedNode.className);\n\n return node;\n }\n\n override exportJSON(): SerializedQuoteNode {\n return {\n ...super.exportJSON(),\n type: \"wby-quote\",\n className: this.__className,\n styleId: this.__styleId\n };\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: Theme): HTMLElement {\n if (!this.__styleId || !this.__className) {\n this.setDefaultTypography(theme);\n }\n\n if (this.__className) {\n addClassNamesToElement(element, this.__className);\n }\n\n return element;\n }\n}\n\nfunction convertBlockquoteElement() {\n const node = $createQuoteNode();\n return {\n node\n };\n}\n\nexport function $createQuoteNode(styleId?: string, key?: NodeKey): QuoteNode {\n return $applyNodeReplacement(new QuoteNode({ styleId, key }));\n}\n\nexport function $isQuoteNode(node: LexicalNode | null | undefined): node is QuoteNode {\n return node instanceof QuoteNode;\n}\n"],"mappings":"AAUA,SAASA,qBAAqB,EAAEC,sBAAsB,QAAQ,SAAS;AACvE,SAASC,KAAK,QAAQ,uBAAuB;AAE7C,SAASC,SAAS,IAAIC,aAAa,QAAQ,oBAAoB;AAE/D,SAASC,UAAU;AAkBnB,OAAO,MAAMF,SAAS,SAASC,aAAa,CAAiC;EAIzEE,WAAWA,CAACC,OAAyB,GAAG,CAAC,CAAC,EAAE;IACxC,KAAK,CAACA,OAAO,CAACC,GAAG,CAAC;IAClB,IAAI,CAACC,SAAS,GAAGF,OAAO,EAAEG,OAAO;IACjC,IAAI,CAACC,WAAW,GAAGJ,OAAO,EAAEK,SAAS;EACzC;EAEAP,UAAUA,CAAA,EAAuB;IAC7B,OAAO,IAAI,CAACI,SAAS;EACzB;EAEAI,UAAUA,CAACH,OAA2B,E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,IAAI,IAAI,CAACN,WAAW,EAAE;MAClBV,sBAAsB,CAAC0B,OAAO,EAAE,IAAI,CAAChB,WAAW,CAAC;IACrD;IAEA,OAAOgB,OAAO;EAClB;AACJ;AAEA,SAASU,wBAAwBA,CAAA,EAAG;EAChC,MAAMd,IAAI,GAAGoB,gBAAgB,CAAC,CAAC;EAC/B,OAAO;IACHpB;EACJ,CAAC;AACL;AAEA,OAAO,SAASoB,gBAAgBA,CAACjC,OAAgB,EAAEF,GAAa,EAAa;EACzE,OAAOR,qBAAqB,CAAC,IAAIG,SAAS,CAAC;IAAEO,OAAO;IAAEF;EAAI,CAAC,CAAC,CAAC;AACjE;AAEA,OAAO,SAAS6C,YAAYA,CAAC9B,IAAoC,EAAqB;EAClF,OAAOA,IAAI,YAAYpB,SAAS;AACpC","ignoreList":[]}
1
+ {"version":3,"file":"QuoteNode.js","sources":["../src/QuoteNode.ts"],"sourcesContent":["import type {\n DOMConversion,\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n Spread\n} from \"lexical\";\nimport { $applyNodeReplacement, addClassNamesToElement } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\nimport type { SerializedQuoteNode as BaseSerializedQuoteNode } from \"@lexical/rich-text\";\nimport { QuoteNode as BaseQuoteNode } from \"@lexical/rich-text\";\nimport type { ThemeStyleValue, TypographyStylesNode } from \"~/types.js\";\nimport { getStyleId } from \"~/utils/getStyleId.js\";\n\nexport type SerializedQuoteNode = Spread<\n {\n styleId?: string;\n styles?: ThemeStyleValue[];\n className?: string;\n type: \"wby-quote\";\n },\n BaseSerializedQuoteNode\n>;\n\ninterface QuoteNodeOptions {\n className?: string;\n styleId?: string;\n key?: NodeKey;\n}\n\nexport class QuoteNode extends BaseQuoteNode implements TypographyStylesNode {\n private __styleId: string | undefined;\n private __className: string | undefined;\n\n constructor(options: QuoteNodeOptions = {}) {\n super(options.key);\n this.__styleId = options?.styleId;\n this.__className = options?.className;\n }\n\n getStyleId(): string | undefined {\n return this.__styleId;\n }\n\n setStyleId(styleId: string | undefined) {\n this.__styleId = styleId;\n }\n\n setClassName(className: string | undefined) {\n this.__className = className;\n }\n\n getClassName(): string | undefined {\n return this.__className;\n }\n\n private setDefaultTypography(theme: Theme) {\n // For some time in v5 we had `quoteblock` as tag name :facepalm: We must not break it.\n const typographyStyle = theme.getTypographyByTag([\"blockquote\", \"quoteblock\"]);\n\n if (typographyStyle) {\n this.__styleId = typographyStyle.id;\n this.__className = typographyStyle.className;\n }\n }\n\n static override getType(): string {\n return \"wby-quote\";\n }\n\n static override clone(node: QuoteNode): QuoteNode {\n return new QuoteNode({\n styleId: node.getStyleId(),\n className: node.getClassName(),\n key: node.getKey()\n });\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n return this.updateElementWithThemeClasses(element, Theme.from(config.theme));\n }\n\n override exportDOM(editor: LexicalEditor): DOMExportOutput {\n const base = super.exportDOM(editor);\n\n const element = base.element as HTMLElement;\n if (element && this.__className) {\n element.classList.add(this.__className);\n }\n\n return { ...base, element };\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertBlockquoteElement,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n blockquote: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n static override importJSON(serializedNode: SerializedQuoteNode): QuoteNode {\n const node = $createQuoteNode();\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n\n const styleId = getStyleId({\n styleId: serializedNode.styleId,\n styles: serializedNode.styles\n });\n\n node.setStyleId(styleId);\n node.setClassName(serializedNode.className);\n\n return node;\n }\n\n override exportJSON(): SerializedQuoteNode {\n return {\n ...super.exportJSON(),\n type: \"wby-quote\",\n className: this.__className,\n styleId: this.__styleId\n };\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: Theme): HTMLElement {\n if (!this.__styleId || !this.__className) {\n this.setDefaultTypography(theme);\n }\n\n if (this.__className) {\n addClassNamesToElement(element, this.__className);\n }\n\n return element;\n }\n}\n\nfunction convertBlockquoteElement() {\n const node = $createQuoteNode();\n return {\n node\n };\n}\n\nexport function $createQuoteNode(styleId?: string, key?: NodeKey): QuoteNode {\n return $applyNodeReplacement(new QuoteNode({ styleId, key }));\n}\n\nexport function $isQuoteNode(node: LexicalNode | null | undefined): node is QuoteNode {\n return node instanceof QuoteNode;\n}\n"],"names":["QuoteNode","BaseQuoteNode","options","styleId","className","theme","typographyStyle","node","config","element","Theme","editor","base","convertBlockquoteElement","serializedNode","$createQuoteNode","getStyleId","addClassNamesToElement","key","$applyNodeReplacement","$isQuoteNode"],"mappings":";;;;AAiCO,MAAMA,4BAAkBC;IAI3B,YAAYC,UAA4B,CAAC,CAAC,CAAE;QACxC,KAAK,CAACA,QAAQ,GAAG;QACjB,IAAI,CAAC,SAAS,GAAGA,SAAS;QAC1B,IAAI,CAAC,WAAW,GAAGA,SAAS;IAChC;IAEA,aAAiC;QAC7B,OAAO,IAAI,CAAC,SAAS;IACzB;IAEA,WAAWC,OAA2B,EAAE;QACpC,IAAI,CAAC,SAAS,GAAGA;IACrB;IAEA,aAAaC,SAA6B,EAAE;QACxC,IAAI,CAAC,WAAW,GAAGA;IACvB;IAEA,eAAmC;QAC/B,OAAO,IAAI,CAAC,WAAW;IAC3B;IAEQ,qBAAqBC,KAAY,EAAE;QAEvC,MAAMC,kBAAkBD,MAAM,kBAAkB,CAAC;YAAC;YAAc;SAAa;QAE7E,IAAIC,iBAAiB;YACjB,IAAI,CAAC,SAAS,GAAGA,gBAAgB,EAAE;YACnC,IAAI,CAAC,WAAW,GAAGA,gBAAgB,SAAS;QAChD;IACJ;IAEA,OAAgB,UAAkB;QAC9B,OAAO;IACX;IAEA,OAAgB,MAAMC,IAAe,EAAa;QAC9C,OAAO,IAAIP,oBAAU;YACjB,SAASO,KAAK,UAAU;YACxB,WAAWA,KAAK,YAAY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