@contentstack/live-preview-utils 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/legacy/cslp/cslpdata.cjs.map +1 -1
- package/dist/legacy/cslp/cslpdata.js.map +1 -1
- package/dist/legacy/livePreview/editButton/editButton.cjs +2 -2
- package/dist/legacy/livePreview/editButton/editButton.cjs.map +1 -1
- package/dist/legacy/livePreview/editButton/editButton.js +2 -2
- package/dist/legacy/livePreview/editButton/editButton.js.map +1 -1
- package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.cjs +1 -1
- package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.js +1 -1
- package/dist/legacy/preview/contentstack-live-preview-HOC.cjs +1 -1
- package/dist/legacy/preview/contentstack-live-preview-HOC.js +1 -1
- package/dist/legacy/timeline/compare/compare.cjs +2 -1
- package/dist/legacy/timeline/compare/compare.cjs.map +1 -1
- package/dist/legacy/timeline/compare/compare.js +2 -1
- package/dist/legacy/timeline/compare/compare.js.map +1 -1
- package/dist/legacy/visualBuilder/components/FieldRevert/FieldRevertComponent.cjs +2 -2
- package/dist/legacy/visualBuilder/components/FieldRevert/FieldRevertComponent.cjs.map +1 -1
- package/dist/legacy/visualBuilder/components/FieldRevert/FieldRevertComponent.d.cts +1 -1
- package/dist/legacy/visualBuilder/components/FieldRevert/FieldRevertComponent.d.ts +1 -1
- package/dist/legacy/visualBuilder/components/FieldRevert/FieldRevertComponent.js +2 -2
- package/dist/legacy/visualBuilder/components/FieldRevert/FieldRevertComponent.js.map +1 -1
- package/dist/legacy/visualBuilder/components/FieldToolbar.cjs +33 -34
- package/dist/legacy/visualBuilder/components/FieldToolbar.cjs.map +1 -1
- package/dist/legacy/visualBuilder/components/FieldToolbar.js +33 -34
- package/dist/legacy/visualBuilder/components/FieldToolbar.js.map +1 -1
- package/dist/legacy/visualBuilder/components/emptyBlock.cjs +1 -0
- package/dist/legacy/visualBuilder/components/emptyBlock.cjs.map +1 -1
- package/dist/legacy/visualBuilder/components/emptyBlock.js +1 -0
- package/dist/legacy/visualBuilder/components/emptyBlock.js.map +1 -1
- package/dist/legacy/visualBuilder/generators/generateToolbar.cjs +1 -1
- package/dist/legacy/visualBuilder/generators/generateToolbar.cjs.map +1 -1
- package/dist/legacy/visualBuilder/generators/generateToolbar.js +1 -1
- package/dist/legacy/visualBuilder/generators/generateToolbar.js.map +1 -1
- package/dist/legacy/visualBuilder/listeners/index.cjs +8 -2
- package/dist/legacy/visualBuilder/listeners/index.cjs.map +1 -1
- package/dist/legacy/visualBuilder/listeners/index.js +8 -2
- package/dist/legacy/visualBuilder/listeners/index.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/constants.cjs +5 -2
- package/dist/legacy/visualBuilder/utils/constants.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/constants.d.cts +2 -1
- package/dist/legacy/visualBuilder/utils/constants.d.ts +2 -1
- package/dist/legacy/visualBuilder/utils/constants.js +3 -1
- package/dist/legacy/visualBuilder/utils/constants.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/getFieldType.cjs +6 -5
- package/dist/legacy/visualBuilder/utils/getFieldType.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/getFieldType.js +6 -5
- package/dist/legacy/visualBuilder/utils/getFieldType.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/handleFieldMouseDown.cjs +10 -0
- package/dist/legacy/visualBuilder/utils/handleFieldMouseDown.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/handleFieldMouseDown.js +10 -0
- package/dist/legacy/visualBuilder/utils/handleFieldMouseDown.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/handleIndividualFields.cjs +63 -39
- package/dist/legacy/visualBuilder/utils/handleIndividualFields.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/handleIndividualFields.js +53 -39
- package/dist/legacy/visualBuilder/utils/handleIndividualFields.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/insertSpaceAtCursor.cjs +44 -0
- package/dist/legacy/visualBuilder/utils/insertSpaceAtCursor.cjs.map +1 -0
- package/dist/legacy/visualBuilder/utils/insertSpaceAtCursor.d.cts +3 -0
- package/dist/legacy/visualBuilder/utils/insertSpaceAtCursor.d.ts +3 -0
- package/dist/legacy/visualBuilder/utils/insertSpaceAtCursor.js +21 -0
- package/dist/legacy/visualBuilder/utils/insertSpaceAtCursor.js.map +1 -0
- package/dist/legacy/visualBuilder/utils/multipleElementAddButton.cjs +1 -1
- package/dist/legacy/visualBuilder/utils/multipleElementAddButton.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/multipleElementAddButton.js +1 -1
- package/dist/legacy/visualBuilder/utils/multipleElementAddButton.js.map +1 -1
- package/dist/modern/cslp/cslpdata.cjs.map +1 -1
- package/dist/modern/cslp/cslpdata.js.map +1 -1
- package/dist/modern/livePreview/editButton/editButton.cjs +1 -1
- package/dist/modern/livePreview/editButton/editButton.cjs.map +1 -1
- package/dist/modern/livePreview/editButton/editButton.js +1 -1
- package/dist/modern/livePreview/editButton/editButton.js.map +1 -1
- package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.cjs +1 -1
- package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.js +1 -1
- package/dist/modern/preview/contentstack-live-preview-HOC.cjs +1 -1
- package/dist/modern/preview/contentstack-live-preview-HOC.js +1 -1
- package/dist/modern/timeline/compare/compare.cjs +2 -1
- package/dist/modern/timeline/compare/compare.cjs.map +1 -1
- package/dist/modern/timeline/compare/compare.js +2 -1
- package/dist/modern/timeline/compare/compare.js.map +1 -1
- package/dist/modern/visualBuilder/components/FieldRevert/FieldRevertComponent.cjs +2 -2
- package/dist/modern/visualBuilder/components/FieldRevert/FieldRevertComponent.cjs.map +1 -1
- package/dist/modern/visualBuilder/components/FieldRevert/FieldRevertComponent.d.cts +1 -1
- package/dist/modern/visualBuilder/components/FieldRevert/FieldRevertComponent.d.ts +1 -1
- package/dist/modern/visualBuilder/components/FieldRevert/FieldRevertComponent.js +2 -2
- package/dist/modern/visualBuilder/components/FieldRevert/FieldRevertComponent.js.map +1 -1
- package/dist/modern/visualBuilder/components/FieldToolbar.cjs +32 -33
- package/dist/modern/visualBuilder/components/FieldToolbar.cjs.map +1 -1
- package/dist/modern/visualBuilder/components/FieldToolbar.js +32 -33
- package/dist/modern/visualBuilder/components/FieldToolbar.js.map +1 -1
- package/dist/modern/visualBuilder/components/emptyBlock.cjs +1 -0
- package/dist/modern/visualBuilder/components/emptyBlock.cjs.map +1 -1
- package/dist/modern/visualBuilder/components/emptyBlock.js +1 -0
- package/dist/modern/visualBuilder/components/emptyBlock.js.map +1 -1
- package/dist/modern/visualBuilder/generators/generateToolbar.cjs +1 -1
- package/dist/modern/visualBuilder/generators/generateToolbar.cjs.map +1 -1
- package/dist/modern/visualBuilder/generators/generateToolbar.js +1 -1
- package/dist/modern/visualBuilder/generators/generateToolbar.js.map +1 -1
- package/dist/modern/visualBuilder/listeners/index.cjs +8 -2
- package/dist/modern/visualBuilder/listeners/index.cjs.map +1 -1
- package/dist/modern/visualBuilder/listeners/index.js +8 -2
- package/dist/modern/visualBuilder/listeners/index.js.map +1 -1
- package/dist/modern/visualBuilder/utils/constants.cjs +5 -2
- package/dist/modern/visualBuilder/utils/constants.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/constants.d.cts +2 -1
- package/dist/modern/visualBuilder/utils/constants.d.ts +2 -1
- package/dist/modern/visualBuilder/utils/constants.js +3 -1
- package/dist/modern/visualBuilder/utils/constants.js.map +1 -1
- package/dist/modern/visualBuilder/utils/getFieldType.cjs +5 -5
- package/dist/modern/visualBuilder/utils/getFieldType.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/getFieldType.js +5 -5
- package/dist/modern/visualBuilder/utils/getFieldType.js.map +1 -1
- package/dist/modern/visualBuilder/utils/handleFieldMouseDown.cjs +10 -0
- package/dist/modern/visualBuilder/utils/handleFieldMouseDown.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/handleFieldMouseDown.js +10 -0
- package/dist/modern/visualBuilder/utils/handleFieldMouseDown.js.map +1 -1
- package/dist/modern/visualBuilder/utils/handleIndividualFields.cjs +62 -39
- package/dist/modern/visualBuilder/utils/handleIndividualFields.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/handleIndividualFields.js +52 -39
- package/dist/modern/visualBuilder/utils/handleIndividualFields.js.map +1 -1
- package/dist/modern/visualBuilder/utils/insertSpaceAtCursor.cjs +44 -0
- package/dist/modern/visualBuilder/utils/insertSpaceAtCursor.cjs.map +1 -0
- package/dist/modern/visualBuilder/utils/insertSpaceAtCursor.d.cts +3 -0
- package/dist/modern/visualBuilder/utils/insertSpaceAtCursor.d.ts +3 -0
- package/dist/modern/visualBuilder/utils/insertSpaceAtCursor.js +21 -0
- package/dist/modern/visualBuilder/utils/insertSpaceAtCursor.js.map +1 -0
- package/dist/modern/visualBuilder/utils/multipleElementAddButton.cjs +1 -1
- package/dist/modern/visualBuilder/utils/multipleElementAddButton.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/multipleElementAddButton.js +1 -1
- package/dist/modern/visualBuilder/utils/multipleElementAddButton.js.map +1 -1
- package/package.json +1 -1
|
@@ -29,6 +29,7 @@ var import_generateOverlay = require("../generators/generateOverlay.cjs");
|
|
|
29
29
|
var import_constants = require("./constants.cjs");
|
|
30
30
|
var import_types = require("./types/index.types.cjs");
|
|
31
31
|
var import_postMessage = require("./types/postMessage.types.cjs");
|
|
32
|
+
var import_insertSpaceAtCursor = require("./insertSpaceAtCursor.cjs");
|
|
32
33
|
function handleFieldInput(e) {
|
|
33
34
|
const event = e;
|
|
34
35
|
const targetElement = event.target;
|
|
@@ -59,12 +60,21 @@ function handleFieldKeyDown(e) {
|
|
|
59
60
|
const fieldType = targetElement.getAttribute(
|
|
60
61
|
import_constants.VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY
|
|
61
62
|
);
|
|
63
|
+
if (targetElement.tagName === "BUTTON") {
|
|
64
|
+
handleKeyDownOnButton(event);
|
|
65
|
+
}
|
|
62
66
|
if (fieldType === import_types.FieldDataType.NUMBER) {
|
|
63
67
|
handleNumericFieldKeyDown(event);
|
|
64
68
|
} else if (fieldType === import_types.FieldDataType.SINGLELINE) {
|
|
65
69
|
handleSingleLineFieldKeyDown(event);
|
|
66
70
|
}
|
|
67
71
|
}
|
|
72
|
+
function handleKeyDownOnButton(e) {
|
|
73
|
+
if (e.code === "Space" && e.target) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
(0, import_insertSpaceAtCursor.insertSpaceAtCursor)(e.target);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
68
78
|
function handleSingleLineFieldKeyDown(e) {
|
|
69
79
|
if (e.code === "Enter") {
|
|
70
80
|
e.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/visualBuilder/utils/handleFieldMouseDown.ts"],"sourcesContent":["import { throttle } from \"lodash-es\";\nimport { sendFieldEvent } from \"../generators/generateOverlay\";\nimport {\n ALLOWED_INLINE_EDITABLE_FIELD,\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n numericInputRegex,\n} from \"./constants\";\nimport { FieldDataType } from \"./types/index.types\";\nimport { VisualBuilderPostMessageEvents } from \"./types/postMessage.types\";\n\nexport function handleFieldInput(e: Event): void {\n const event = e as InputEvent;\n const targetElement = event.target as HTMLElement;\n const fieldType = targetElement.getAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n ) as FieldDataType | null;\n if (event.type === \"input\"
|
|
1
|
+
{"version":3,"sources":["../../../../src/visualBuilder/utils/handleFieldMouseDown.ts"],"sourcesContent":["import { throttle } from \"lodash-es\";\nimport { sendFieldEvent } from \"../generators/generateOverlay\";\nimport {\n ALLOWED_INLINE_EDITABLE_FIELD,\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n numericInputRegex,\n} from \"./constants\";\nimport { FieldDataType } from \"./types/index.types\";\nimport { VisualBuilderPostMessageEvents } from \"./types/postMessage.types\";\nimport { insertSpaceAtCursor } from \"./insertSpaceAtCursor\";\n\nexport function handleFieldInput(e: Event): void {\n const event = e as InputEvent;\n const targetElement = event.target as HTMLElement;\n const fieldType = targetElement.getAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n ) as FieldDataType | null;\n if (\n event.type === \"input\" &&\n ALLOWED_INLINE_EDITABLE_FIELD.includes(fieldType as FieldDataType)\n ) {\n throttledFieldSync();\n }\n}\nconst throttledFieldSync = throttle(() => {\n try {\n const visualBuilderContainer = document.querySelector(\n \".visual-builder__container\"\n ) as HTMLElement;\n if (!visualBuilderContainer) return;\n sendFieldEvent({\n visualBuilderContainer,\n eventType: VisualBuilderPostMessageEvents.SYNC_FIELD,\n });\n } catch (error) {\n console.error(\"Error in throttledFieldSync\", error);\n }\n}, 300);\n\nexport function handleFieldKeyDown(e: Event): void {\n const event = e as KeyboardEvent;\n const targetElement = event.target as HTMLElement;\n const fieldType = targetElement.getAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n ) as FieldDataType | null;\n\n if (targetElement.tagName === \"BUTTON\") {\n handleKeyDownOnButton(event);\n }\n if (fieldType === FieldDataType.NUMBER) {\n handleNumericFieldKeyDown(event);\n } else if (fieldType === FieldDataType.SINGLELINE) {\n handleSingleLineFieldKeyDown(event);\n }\n}\n\n// spaces do not work inside a button content-editable\n// this adds a space and moves the cursor ahead, the\n// button press event is also prevented\nfunction handleKeyDownOnButton(e: KeyboardEvent) {\n if (e.code === \"Space\" && e.target) {\n e.preventDefault();\n insertSpaceAtCursor(e.target as HTMLElement);\n }\n}\n\nfunction handleSingleLineFieldKeyDown(e: KeyboardEvent) {\n if (e.code === \"Enter\") {\n e.preventDefault();\n }\n}\n\nfunction handleNumericFieldKeyDown(event: KeyboardEvent): void {\n const targetElement = event.target as HTMLElement;\n\n const allowedKeys = [\n \"Backspace\",\n \"Tab\",\n \"Enter\",\n \"End\",\n \"Home\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"Delete\",\n ];\n\n if (\n event.ctrlKey ||\n event.metaKey ||\n event.altKey ||\n allowedKeys.includes(event.code)\n ) {\n // Allow Ctrl, Cmd, Alt, and special keys\n return;\n }\n\n if (event.code.includes(\"Digit\")) {\n return;\n }\n\n const nonNumericAllowedCharacters = [\"-\", \".\", \"e\", \"E\"];\n\n if (!nonNumericAllowedCharacters.includes(event.key)) {\n event.preventDefault();\n return;\n }\n\n const selection = {\n startOffset: window.getSelection()?.getRangeAt(0).startOffset || 0,\n endOffset: window.getSelection()?.getRangeAt(0).endOffset || 0,\n };\n\n const existingInput = targetElement.textContent || \"\";\n const currentOutputArr = existingInput.split(\"\");\n currentOutputArr.splice(\n selection.startOffset,\n selection.endOffset - selection.startOffset,\n event.key\n );\n const currentInput = currentOutputArr.join(\"\");\n\n if (!numericInputRegex.test(currentInput)) {\n event.preventDefault();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB;AACzB,6BAA+B;AAC/B,uBAIO;AACP,mBAA8B;AAC9B,yBAA+C;AAC/C,iCAAoC;AAE7B,SAAS,iBAAiB,GAAgB;AAC7C,QAAM,QAAQ;AACd,QAAM,gBAAgB,MAAM;AAC5B,QAAM,YAAY,cAAc;AAAA,IAC5B;AAAA,EACJ;AACA,MACI,MAAM,SAAS,WACf,+CAA8B,SAAS,SAA0B,GACnE;AACE,uBAAmB;AAAA,EACvB;AACJ;AACA,IAAM,yBAAqB,2BAAS,MAAM;AACtC,MAAI;AACA,UAAM,yBAAyB,SAAS;AAAA,MACpC;AAAA,IACJ;AACA,QAAI,CAAC,uBAAwB;AAC7B,+CAAe;AAAA,MACX;AAAA,MACA,WAAW,kDAA+B;AAAA,IAC9C,CAAC;AAAA,EACL,SAAS,OAAO;AACZ,YAAQ,MAAM,+BAA+B,KA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AAc,eAAe;AACnD,QAAM,mBAAmB,cAAc,MAAM,EAAE;AAC/C,mBAAiB;AAAA,IACb,UAAU;AAAA,IACV,UAAU,YAAY,UAAU;AAAA,IAChC,MAAM;AAAA,EACV;AACA,QAAM,eAAe,iBAAiB,KAAK,EAAE;AAE7C,MAAI,CAAC,mCAAkB,KAAK,YAAY,GAAG;AACvC,UAAM,eAAe;AAAA,EACzB;AACJ;","names":[]}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "./constants.js";
|
|
11
11
|
import { FieldDataType } from "./types/index.types.js";
|
|
12
12
|
import { VisualBuilderPostMessageEvents } from "./types/postMessage.types.js";
|
|
13
|
+
import { insertSpaceAtCursor } from "./insertSpaceAtCursor.js";
|
|
13
14
|
function handleFieldInput(e) {
|
|
14
15
|
const event = e;
|
|
15
16
|
const targetElement = event.target;
|
|
@@ -40,12 +41,21 @@ function handleFieldKeyDown(e) {
|
|
|
40
41
|
const fieldType = targetElement.getAttribute(
|
|
41
42
|
VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY
|
|
42
43
|
);
|
|
44
|
+
if (targetElement.tagName === "BUTTON") {
|
|
45
|
+
handleKeyDownOnButton(event);
|
|
46
|
+
}
|
|
43
47
|
if (fieldType === FieldDataType.NUMBER) {
|
|
44
48
|
handleNumericFieldKeyDown(event);
|
|
45
49
|
} else if (fieldType === FieldDataType.SINGLELINE) {
|
|
46
50
|
handleSingleLineFieldKeyDown(event);
|
|
47
51
|
}
|
|
48
52
|
}
|
|
53
|
+
function handleKeyDownOnButton(e) {
|
|
54
|
+
if (e.code === "Space" && e.target) {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
insertSpaceAtCursor(e.target);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
49
59
|
function handleSingleLineFieldKeyDown(e) {
|
|
50
60
|
if (e.code === "Enter") {
|
|
51
61
|
e.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/visualBuilder/utils/handleFieldMouseDown.ts"],"sourcesContent":["import { throttle } from \"lodash-es\";\nimport { sendFieldEvent } from \"../generators/generateOverlay\";\nimport {\n ALLOWED_INLINE_EDITABLE_FIELD,\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n numericInputRegex,\n} from \"./constants\";\nimport { FieldDataType } from \"./types/index.types\";\nimport { VisualBuilderPostMessageEvents } from \"./types/postMessage.types\";\n\nexport function handleFieldInput(e: Event): void {\n const event = e as InputEvent;\n const targetElement = event.target as HTMLElement;\n const fieldType = targetElement.getAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n ) as FieldDataType | null;\n if (event.type === \"input\"
|
|
1
|
+
{"version":3,"sources":["../../../../src/visualBuilder/utils/handleFieldMouseDown.ts"],"sourcesContent":["import { throttle } from \"lodash-es\";\nimport { sendFieldEvent } from \"../generators/generateOverlay\";\nimport {\n ALLOWED_INLINE_EDITABLE_FIELD,\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n numericInputRegex,\n} from \"./constants\";\nimport { FieldDataType } from \"./types/index.types\";\nimport { VisualBuilderPostMessageEvents } from \"./types/postMessage.types\";\nimport { insertSpaceAtCursor } from \"./insertSpaceAtCursor\";\n\nexport function handleFieldInput(e: Event): void {\n const event = e as InputEvent;\n const targetElement = event.target as HTMLElement;\n const fieldType = targetElement.getAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n ) as FieldDataType | null;\n if (\n event.type === \"input\" &&\n ALLOWED_INLINE_EDITABLE_FIELD.includes(fieldType as FieldDataType)\n ) {\n throttledFieldSync();\n }\n}\nconst throttledFieldSync = throttle(() => {\n try {\n const visualBuilderContainer = document.querySelector(\n \".visual-builder__container\"\n ) as HTMLElement;\n if (!visualBuilderContainer) return;\n sendFieldEvent({\n visualBuilderContainer,\n eventType: VisualBuilderPostMessageEvents.SYNC_FIELD,\n });\n } catch (error) {\n console.error(\"Error in throttledFieldSync\", error);\n }\n}, 300);\n\nexport function handleFieldKeyDown(e: Event): void {\n const event = e as KeyboardEvent;\n const targetElement = event.target as HTMLElement;\n const fieldType = targetElement.getAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n ) as FieldDataType | null;\n\n if (targetElement.tagName === \"BUTTON\") {\n handleKeyDownOnButton(event);\n }\n if (fieldType === FieldDataType.NUMBER) {\n handleNumericFieldKeyDown(event);\n } else if (fieldType === FieldDataType.SINGLELINE) {\n handleSingleLineFieldKeyDown(event);\n }\n}\n\n// spaces do not work inside a button content-editable\n// this adds a space and moves the cursor ahead, the\n// button press event is also prevented\nfunction handleKeyDownOnButton(e: KeyboardEvent) {\n if (e.code === \"Space\" && e.target) {\n e.preventDefault();\n insertSpaceAtCursor(e.target as HTMLElement);\n }\n}\n\nfunction handleSingleLineFieldKeyDown(e: KeyboardEvent) {\n if (e.code === \"Enter\") {\n e.preventDefault();\n }\n}\n\nfunction handleNumericFieldKeyDown(event: KeyboardEvent): void {\n const targetElement = event.target as HTMLElement;\n\n const allowedKeys = [\n \"Backspace\",\n \"Tab\",\n \"Enter\",\n \"End\",\n \"Home\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"Delete\",\n ];\n\n if (\n event.ctrlKey ||\n event.metaKey ||\n event.altKey ||\n allowedKeys.includes(event.code)\n ) {\n // Allow Ctrl, Cmd, Alt, and special keys\n return;\n }\n\n if (event.code.includes(\"Digit\")) {\n return;\n }\n\n const nonNumericAllowedCharacters = [\"-\", \".\", \"e\", \"E\"];\n\n if (!nonNumericAllowedCharacters.includes(event.key)) {\n event.preventDefault();\n return;\n }\n\n const selection = {\n startOffset: window.getSelection()?.getRangeAt(0).startOffset || 0,\n endOffset: window.getSelection()?.getRangeAt(0).endOffset || 0,\n };\n\n const existingInput = targetElement.textContent || \"\";\n const currentOutputArr = existingInput.split(\"\");\n currentOutputArr.splice(\n selection.startOffset,\n selection.endOffset - selection.startOffset,\n event.key\n );\n const current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ACpB,MAAE,eAAe;AAAA,EACrB;AACJ;AAEA,SAAS,0BAA0B,OAA4B;AAxE/D;AAyEI,QAAM,gBAAgB,MAAM;AAE5B,QAAM,cAAc;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AAEA,MACI,MAAM,WACN,MAAM,WACN,MAAM,UACN,YAAY,SAAS,MAAM,IAAI,GACjC;AAEE;AAAA,EACJ;AAEA,MAAI,MAAM,KAAK,SAAS,OAAO,GAAG;AAC9B;AAAA,EACJ;AAEA,QAAM,8BAA8B,CAAC,KAAK,KAAK,KAAK,GAAG;AAEvD,MAAI,CAAC,4BAA4B,SAAS,MAAM,GAAG,GAAG;AAClD,UAAM,eAAe;AACrB;AAAA,EACJ;AAEA,QAAM,YAAY;AAAA,IACd,eAAa,YAAO,aAAa,MAApB,mBAAuB,WAAW,GAAG,gBAAe;AAAA,IACjE,aAAW,YAAO,aAAa,MAApB,mBAAuB,WAAW,GAAG,cAAa;AAAA,EACjE;AAEA,QAAM,gBAAgB,cAAc,eAAe;AACnD,QAAM,mBAAmB,cAAc,MAAM,EAAE;AAC/C,mBAAiB;AAAA,IACb,UAAU;AAAA,IACV,UAAU,YAAY,UAAU;AAAA,IAChC,MAAM;AAAA,EACV;AACA,QAAM,eAAe,iBAAiB,KAAK,EAAE;AAE7C,MAAI,CAAC,kBAAkB,KAAK,YAAY,GAAG;AACvC,UAAM,eAAe;AAAA,EACzB;AACJ;","names":[]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/visualBuilder/utils/handleIndividualFields.ts
|
|
@@ -37,6 +47,8 @@ var import_multipleElementAddButton = require("./multipleElementAddButton.cjs");
|
|
|
37
47
|
var import_updateFocussedState = require("./updateFocussedState.cjs");
|
|
38
48
|
var import_types = require("./types/index.types.cjs");
|
|
39
49
|
var import_getMultilinePlaintext = require("./getMultilinePlaintext.cjs");
|
|
50
|
+
var import_postMessage = require("./types/postMessage.types.cjs");
|
|
51
|
+
var import_visualBuilderPostMessage = __toESM(require("./visualBuilderPostMessage.cjs"), 1);
|
|
40
52
|
async function handleIndividualFields(eventDetails, elements) {
|
|
41
53
|
const { fieldMetadata, editableElement } = eventDetails;
|
|
42
54
|
const { visualBuilderContainer, lastEditedField, resizeObserver } = elements;
|
|
@@ -54,15 +66,13 @@ async function handleIndividualFields(eventDetails, elements) {
|
|
|
54
66
|
fieldPathWithIndex
|
|
55
67
|
)
|
|
56
68
|
]);
|
|
57
|
-
const expectedFieldInstanceData = Array.isArray(expectedFieldData) ? expectedFieldData.at(fieldMetadata.multipleFieldMetadata.index) : void 0;
|
|
58
69
|
const fieldType = (0, import_getFieldType.getFieldType)(fieldSchema);
|
|
59
70
|
const { isDisabled: disabled } = (0, import_isFieldDisabled.isFieldDisabled)(fieldSchema, eventDetails);
|
|
60
71
|
editableElement.setAttribute(
|
|
61
72
|
import_constants.VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,
|
|
62
73
|
fieldType
|
|
63
74
|
);
|
|
64
|
-
if (
|
|
65
|
-
(fieldSchema == null ? void 0 : fieldSchema.field_metadata.ref_multiple))) {
|
|
75
|
+
if (isFieldMultiple(fieldSchema)) {
|
|
66
76
|
if (lastEditedField !== editableElement) {
|
|
67
77
|
const addButtonLabel = fieldSchema.data_type === "blocks" ? (
|
|
68
78
|
// ? `Add ${fieldSchema.display_name ?? "Modular Block"}`
|
|
@@ -83,70 +93,75 @@ async function handleIndividualFields(eventDetails, elements) {
|
|
|
83
93
|
}
|
|
84
94
|
);
|
|
85
95
|
}
|
|
86
|
-
if (eventDetails.fieldMetadata.multipleFieldMetadata.index > -1) {
|
|
87
|
-
handleSingleField(
|
|
88
|
-
{
|
|
89
|
-
editableElement,
|
|
90
|
-
visualBuilderContainer,
|
|
91
|
-
resizeObserver: elements.resizeObserver
|
|
92
|
-
},
|
|
93
|
-
{ expectedFieldData: expectedFieldInstanceData, disabled }
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
handleSingleField(
|
|
98
|
-
{
|
|
99
|
-
editableElement,
|
|
100
|
-
visualBuilderContainer,
|
|
101
|
-
resizeObserver: elements.resizeObserver
|
|
102
|
-
},
|
|
103
|
-
{ expectedFieldData, disabled }
|
|
104
|
-
);
|
|
105
96
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
97
|
+
!disabled && handleInlineEditing();
|
|
98
|
+
function handleInlineEditing() {
|
|
99
|
+
if (!import_constants.ALLOWED_INLINE_EDITABLE_FIELD.includes(fieldType)) return;
|
|
100
|
+
const index = Number(fieldMetadata.instance.fieldPathWithIndex.split(".").at(-1));
|
|
101
|
+
const isInstance = Number.isFinite(index);
|
|
102
|
+
if (isFieldMultiple(fieldSchema)) {
|
|
103
|
+
let expectedFieldInstanceData = null;
|
|
104
|
+
if (Array.isArray(expectedFieldData)) {
|
|
105
|
+
if (!isInstance) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (index >= expectedFieldData.length) {
|
|
109
|
+
} else {
|
|
110
|
+
expectedFieldInstanceData = expectedFieldData.at(index);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
expectedFieldInstanceData = expectedFieldData;
|
|
114
|
+
}
|
|
115
|
+
enableInlineEditing(expectedFieldInstanceData);
|
|
116
|
+
} else {
|
|
117
|
+
let expectedFieldInstanceData = null;
|
|
118
|
+
if (isInstance) {
|
|
119
|
+
if (index !== 0) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
expectedFieldInstanceData = Array.isArray(expectedFieldData) ? expectedFieldData.at(0) : expectedFieldData;
|
|
123
|
+
}
|
|
124
|
+
enableInlineEditing(expectedFieldInstanceData ?? expectedFieldData);
|
|
110
125
|
}
|
|
111
|
-
|
|
112
|
-
let actualEditableField =
|
|
126
|
+
function enableInlineEditing(expectedFieldData2) {
|
|
127
|
+
let actualEditableField = editableElement;
|
|
113
128
|
import__.VisualBuilder.VisualBuilderGlobalState.value.focusFieldValue = actualEditableField == null ? void 0 : actualEditableField.innerText;
|
|
114
129
|
const elementComputedDisplay = window.getComputedStyle(actualEditableField).display;
|
|
115
|
-
let textContent =
|
|
130
|
+
let textContent = editableElement.innerText || editableElement.textContent || "";
|
|
116
131
|
if (fieldType === import_types.FieldDataType.MULTILINE) {
|
|
117
132
|
textContent = (0, import_getMultilinePlaintext.getMultilinePlaintext)(actualEditableField);
|
|
118
133
|
actualEditableField.addEventListener("paste", pasteAsPlainText);
|
|
119
134
|
}
|
|
120
|
-
const expectedTextContent =
|
|
121
|
-
if (textContent !== expectedTextContent || (0, import_generatePseudoEditableField.isEllipsisActive)(
|
|
135
|
+
const expectedTextContent = expectedFieldData2;
|
|
136
|
+
if (expectedTextContent && textContent !== expectedTextContent || (0, import_generatePseudoEditableField.isEllipsisActive)(editableElement)) {
|
|
122
137
|
const pseudoEditableField = (0, import_generatePseudoEditableField.generatePseudoEditableElement)(
|
|
123
|
-
{ editableElement
|
|
124
|
-
{ textContent:
|
|
138
|
+
{ editableElement },
|
|
139
|
+
{ textContent: expectedFieldData2 }
|
|
125
140
|
);
|
|
126
|
-
|
|
141
|
+
editableElement.style.visibility = "hidden";
|
|
127
142
|
pseudoEditableField.setAttribute(
|
|
128
143
|
import_constants.VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,
|
|
129
144
|
fieldType
|
|
130
145
|
);
|
|
131
|
-
|
|
146
|
+
visualBuilderContainer.appendChild(pseudoEditableField);
|
|
132
147
|
actualEditableField = pseudoEditableField;
|
|
133
148
|
if (fieldType === import_types.FieldDataType.MULTILINE)
|
|
134
149
|
actualEditableField.addEventListener(
|
|
135
150
|
"paste",
|
|
136
151
|
pasteAsPlainText
|
|
137
152
|
);
|
|
138
|
-
|
|
153
|
+
elements.resizeObserver.observe(pseudoEditableField);
|
|
139
154
|
} else if (elementComputedDisplay === "inline") {
|
|
140
155
|
const onInlineElementInput = (0, import_lodash_es.throttle)(() => {
|
|
141
|
-
const overlayWrapper =
|
|
156
|
+
const overlayWrapper = visualBuilderContainer.querySelector(
|
|
142
157
|
".visual-builder__overlay__wrapper"
|
|
143
158
|
);
|
|
144
|
-
const focusedToolbar =
|
|
159
|
+
const focusedToolbar = visualBuilderContainer.querySelector(
|
|
145
160
|
".visual-builder__focused-toolbar"
|
|
146
161
|
);
|
|
147
162
|
(0, import_updateFocussedState.updateFocussedState)({
|
|
148
163
|
editableElement: actualEditableField,
|
|
149
|
-
visualBuilderContainer
|
|
164
|
+
visualBuilderContainer,
|
|
150
165
|
overlayWrapper,
|
|
151
166
|
focusedToolbar,
|
|
152
167
|
resizeObserver
|
|
@@ -165,6 +180,10 @@ async function handleIndividualFields(eventDetails, elements) {
|
|
|
165
180
|
}
|
|
166
181
|
}
|
|
167
182
|
}
|
|
183
|
+
function isFieldMultiple(fieldSchema) {
|
|
184
|
+
return fieldSchema && (fieldSchema.multiple || fieldSchema.data_type === "reference" && // @ts-ignore
|
|
185
|
+
fieldSchema.field_metadata.ref_multiple);
|
|
186
|
+
}
|
|
168
187
|
function cleanIndividualFieldResidual(elements) {
|
|
169
188
|
const { overlayWrapper, visualBuilderContainer, focusedToolbar } = elements;
|
|
170
189
|
(0, import_multipleElementAddButton.removeAddInstanceButtons)(
|
|
@@ -210,6 +229,11 @@ function cleanIndividualFieldResidual(elements) {
|
|
|
210
229
|
}
|
|
211
230
|
if (focusedToolbar) {
|
|
212
231
|
focusedToolbar.innerHTML = "";
|
|
232
|
+
const toolbarEvents = [import_postMessage.VisualBuilderPostMessageEvents.DELETE_INSTANCE, import_postMessage.VisualBuilderPostMessageEvents.UPDATE_DISCUSSION_ID];
|
|
233
|
+
toolbarEvents.forEach((event) => {
|
|
234
|
+
var _a, _b;
|
|
235
|
+
(_b = (_a = import_visualBuilderPostMessage.default) == null ? void 0 : _a.unregisterEvent) == null ? void 0 : _b.call(_a, event);
|
|
236
|
+
});
|
|
213
237
|
}
|
|
214
238
|
}
|
|
215
239
|
var pasteAsPlainText = (0, import_lodash_es.debounce)(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/visualBuilder/utils/handleIndividualFields.ts"],"sourcesContent":["import { debounce, throttle } from \"lodash-es\";\nimport { VisualBuilder } from \"..\";\nimport {\n generatePseudoEditableElement,\n isEllipsisActive,\n} from \"../generators/generatePseudoEditableField\";\nimport { VisualBuilderCslpEventDetails } from \"../types/visualBuilder.types\";\nimport {\n ALLOWED_INLINE_EDITABLE_FIELD,\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n} from \"./constants\";\nimport { FieldSchemaMap } from \"./fieldSchemaMap\";\nimport { getFieldData } from \"./getFieldData\";\nimport { getFieldType } from \"./getFieldType\";\nimport { handleFieldInput, handleFieldKeyDown } from \"./handleFieldMouseDown\";\nimport { isFieldDisabled } from \"./isFieldDisabled\";\nimport visualBuilderPostMessage from \"./visualBuilderPostMessage\";\nimport {\n handleAddButtonsForMultiple,\n removeAddInstanceButtons,\n} from \"./multipleElementAddButton\";\nimport { VisualBuilderPostMessageEvents } from \"./types/postMessage.types\";\nimport { updateFocussedState } from \"./updateFocussedState\";\nimport { FieldDataType } from \"./types/index.types\";\nimport { getMultilinePlaintext } from \"./getMultilinePlaintext\";\n\n/**\n * It handles all the fields based on their data type and its \"multiple\" property.\n * @param eventDetails The event details object that contain cslp and field metadata.\n * @param elements The elements object that contain the visual builder wrapper.\n */\nexport async function handleIndividualFields(\n eventDetails: VisualBuilderCslpEventDetails,\n elements: {\n visualBuilderContainer: HTMLDivElement;\n resizeObserver: ResizeObserver;\n lastEditedField: Element | null;\n }\n): Promise<void> {\n const { fieldMetadata, editableElement } = eventDetails;\n const { visualBuilderContainer, lastEditedField, resizeObserver } =\n elements;\n const {\n content_type_uid,\n entry_uid,\n locale,\n fieldPath,\n fieldPathWithIndex,\n } = fieldMetadata;\n\n const [fieldSchema, expectedFieldData] = await Promise.all([\n FieldSchemaMap.getFieldSchema(content_type_uid, fieldPath),\n getFieldData(\n { content_type_uid, entry_uid, locale },\n fieldPathWithIndex\n ),\n ]);\n // if value is an array, get the value for the instance\n const expectedFieldInstanceData = Array.isArray(expectedFieldData)\n ? expectedFieldData.at(fieldMetadata.multipleFieldMetadata.index)\n : undefined;\n\n const fieldType = getFieldType(fieldSchema);\n\n const { isDisabled: disabled } = isFieldDisabled(fieldSchema, eventDetails);\n\n editableElement.setAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n fieldType\n );\n\n if (\n fieldSchema &&\n (fieldSchema?.multiple ||\n (fieldSchema?.data_type === \"reference\" &&\n // @ts-ignore\n fieldSchema?.field_metadata.ref_multiple))\n ) {\n if (lastEditedField !== editableElement) {\n const addButtonLabel =\n fieldSchema.data_type === \"blocks\"\n ? // ? `Add ${fieldSchema.display_name ?? \"Modular Block\"}`\n \"Add Section\"\n : undefined;\n\n handleAddButtonsForMultiple(\n eventDetails,\n {\n editableElement: eventDetails.editableElement,\n visualBuilderContainer: visualBuilderContainer,\n resizeObserver: resizeObserver,\n },\n {\n fieldSchema,\n expectedFieldData,\n disabled,\n label: addButtonLabel,\n }\n );\n }\n\n // * fields could be handled as they are in a single instance\n if (eventDetails.fieldMetadata.multipleFieldMetadata.index > -1) {\n handleSingleField(\n {\n editableElement,\n visualBuilderContainer,\n resizeObserver: elements.resizeObserver,\n },\n { expectedFieldData: expectedFieldInstanceData, disabled }\n );\n }\n } else {\n handleSingleField(\n {\n editableElement,\n visualBuilderContainer,\n resizeObserver: elements.resizeObserver,\n },\n { expectedFieldData, disabled }\n );\n }\n\n /**\n * Handles all the fields based on their data type.\n */\n function handleSingleField(\n elements: {\n editableElement: Element;\n visualBuilderContainer: HTMLDivElement;\n resizeObserver: ResizeObserver;\n },\n config: { expectedFieldData: string; disabled?: boolean }\n ) {\n const { editableElement, visualBuilderContainer } = elements;\n\n if (config.disabled) {\n return;\n }\n\n // * title, single single_line, single multi_line, single number\n if (ALLOWED_INLINE_EDITABLE_FIELD.includes(fieldType)) {\n let actualEditableField = editableElement as HTMLElement;\n\n VisualBuilder.VisualBuilderGlobalState.value.focusFieldValue =\n actualEditableField?.innerText;\n\n const elementComputedDisplay =\n window.getComputedStyle(actualEditableField).display;\n\n let textContent =\n (editableElement as HTMLElement).innerText ||\n editableElement.textContent ||\n \"\";\n\n if (fieldType === FieldDataType.MULTILINE) {\n textContent = getMultilinePlaintext(actualEditableField);\n actualEditableField.addEventListener(\"paste\", pasteAsPlainText);\n }\n const expectedTextContent = config.expectedFieldData;\n if (\n textContent !== expectedTextContent ||\n isEllipsisActive(editableElement as HTMLElement)\n ) {\n // TODO: Testing will be don in the E2E.\n const pseudoEditableField = generatePseudoEditableElement(\n { editableElement: editableElement as HTMLElement },\n { textContent: config.expectedFieldData }\n );\n\n (editableElement as HTMLElement).style.visibility = \"hidden\";\n\n // set field type attribute to the pseudo editable field\n // ensures proper keydown handling similar to the actual editable field\n pseudoEditableField.setAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n fieldType\n );\n visualBuilderContainer.appendChild(pseudoEditableField);\n actualEditableField = pseudoEditableField;\n\n if (fieldType === FieldDataType.MULTILINE)\n actualEditableField.addEventListener(\n \"paste\",\n pasteAsPlainText\n );\n\n // we will unobserve this in hideOverlay\n elements.resizeObserver.observe(pseudoEditableField);\n } else if (elementComputedDisplay === \"inline\") {\n // if the editable field is inline\n const onInlineElementInput = throttle(() => {\n const overlayWrapper = visualBuilderContainer.querySelector(\n \".visual-builder__overlay__wrapper\"\n ) as HTMLDivElement;\n const focusedToolbar = visualBuilderContainer.querySelector(\n \".visual-builder__focused-toolbar\"\n ) as HTMLDivElement;\n updateFocussedState({\n editableElement: actualEditableField,\n visualBuilderContainer,\n overlayWrapper,\n focusedToolbar,\n resizeObserver,\n });\n }, 200);\n actualEditableField.addEventListener(\n \"input\",\n onInlineElementInput\n );\n }\n\n actualEditableField.setAttribute(\"contenteditable\", \"true\");\n actualEditableField.addEventListener(\"input\", handleFieldInput);\n actualEditableField.addEventListener(\"keydown\", handleFieldKeyDown);\n // focus on the contenteditable element to start accepting input\n actualEditableField.focus();\n\n return;\n }\n }\n}\n\nexport function cleanIndividualFieldResidual(elements: {\n overlayWrapper: HTMLDivElement;\n visualBuilderContainer: HTMLDivElement | null;\n focusedToolbar: HTMLDivElement | null;\n resizeObserver: ResizeObserver;\n}): void {\n const { overlayWrapper, visualBuilderContainer, focusedToolbar } = elements;\n\n removeAddInstanceButtons(\n {\n eventTarget: null,\n visualBuilderContainer: visualBuilderContainer,\n overlayWrapper: overlayWrapper,\n },\n true\n );\n\n const previousSelectedEditableDOM =\n VisualBuilder.VisualBuilderGlobalState.value\n .previousSelectedEditableDOM;\n if (previousSelectedEditableDOM) {\n previousSelectedEditableDOM.removeAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n );\n previousSelectedEditableDOM.removeAttribute(\"contenteditable\");\n previousSelectedEditableDOM.removeEventListener(\n \"input\",\n handleFieldInput\n );\n previousSelectedEditableDOM.removeEventListener(\n \"keydown\",\n handleFieldKeyDown\n );\n\n previousSelectedEditableDOM.removeEventListener(\n \"paste\",\n pasteAsPlainText\n );\n // Note - this happens in two places, 1. hideOverlay and 2. here\n // TODO maybe see all usages of both functions and try to do it in one place\n elements.resizeObserver.unobserve(previousSelectedEditableDOM);\n }\n\n const pseudoEditableElement = visualBuilderContainer?.querySelector(\n \".visual-builder__pseudo-editable-element\"\n );\n if (pseudoEditableElement) {\n elements.resizeObserver.unobserve(pseudoEditableElement);\n pseudoEditableElement.removeEventListener(\"paste\", pasteAsPlainText);\n pseudoEditableElement.remove();\n if (previousSelectedEditableDOM) {\n (previousSelectedEditableDOM as HTMLElement).style.removeProperty(\n \"visibility\"\n );\n }\n }\n\n if (focusedToolbar) {\n focusedToolbar.innerHTML = \"\";\n }\n}\n\nconst pasteAsPlainText = debounce(\n (e: Event) => {\n e.preventDefault();\n const clipboardData = (e as ClipboardEvent).clipboardData;\n document.execCommand(\n \"inserttext\",\n false,\n clipboardData?.getData(\"text/plain\")\n );\n },\n 100,\n { leading: true }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmC;AACnC,eAA8B;AAC9B,yCAGO;AAEP,uBAGO;AACP,4BAA+B;AAC/B,0BAA6B;AAC7B,0BAA6B;AAC7B,kCAAqD;AACrD,6BAAgC;AAEhC,sCAGO;AAEP,iCAAoC;AACpC,mBAA8B;AAC9B,mCAAsC;AAOtC,eAAsB,uBAClB,cACA,UAKa;AACb,QAAM,EAAE,eAAe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names":["elements","editableElement","visualBuilderContainer"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/visualBuilder/utils/handleIndividualFields.ts"],"sourcesContent":["import { debounce, throttle } from \"lodash-es\";\nimport { VisualBuilder } from \"..\";\nimport {\n generatePseudoEditableElement,\n isEllipsisActive,\n} from \"../generators/generatePseudoEditableField\";\nimport { VisualBuilderCslpEventDetails } from \"../types/visualBuilder.types\";\nimport {\n ALLOWED_INLINE_EDITABLE_FIELD,\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n} from \"./constants\";\nimport { FieldSchemaMap } from \"./fieldSchemaMap\";\nimport { getFieldData } from \"./getFieldData\";\nimport { getFieldType } from \"./getFieldType\";\nimport { handleFieldInput, handleFieldKeyDown } from \"./handleFieldMouseDown\";\nimport { isFieldDisabled } from \"./isFieldDisabled\";\nimport {\n handleAddButtonsForMultiple,\n removeAddInstanceButtons,\n} from \"./multipleElementAddButton\";\nimport { updateFocussedState } from \"./updateFocussedState\";\nimport { FieldDataType, ISchemaFieldMap } from \"./types/index.types\";\nimport { getMultilinePlaintext } from \"./getMultilinePlaintext\";\nimport { VisualBuilderPostMessageEvents } from \"./types/postMessage.types\";\nimport visualBuilderPostMessage from \"./visualBuilderPostMessage\";\n\n/**\n * It handles all the fields based on their data type and its \"multiple\" property.\n * @param eventDetails The event details object that contain cslp and field metadata.\n * @param elements The elements object that contain the visual builder wrapper.\n */\nexport async function handleIndividualFields(\n eventDetails: VisualBuilderCslpEventDetails,\n elements: {\n visualBuilderContainer: HTMLDivElement;\n resizeObserver: ResizeObserver;\n lastEditedField: Element | null;\n }\n): Promise<void> {\n const { fieldMetadata, editableElement } = eventDetails;\n const { visualBuilderContainer, lastEditedField, resizeObserver } =\n elements;\n const {\n content_type_uid,\n entry_uid,\n locale,\n fieldPath,\n fieldPathWithIndex,\n } = fieldMetadata;\n\n const [fieldSchema, expectedFieldData] = await Promise.all([\n FieldSchemaMap.getFieldSchema(content_type_uid, fieldPath),\n getFieldData(\n { content_type_uid, entry_uid, locale },\n fieldPathWithIndex\n ),\n ]);\n\n const fieldType = getFieldType(fieldSchema);\n\n const { isDisabled: disabled } = isFieldDisabled(fieldSchema, eventDetails);\n\n editableElement.setAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n fieldType\n );\n\n if (isFieldMultiple(fieldSchema)) {\n if (lastEditedField !== editableElement) {\n const addButtonLabel =\n fieldSchema.data_type === \"blocks\"\n ? // ? `Add ${fieldSchema.display_name ?? \"Modular Block\"}`\n \"Add Section\"\n : undefined;\n\n handleAddButtonsForMultiple(\n eventDetails,\n {\n editableElement: eventDetails.editableElement,\n visualBuilderContainer: visualBuilderContainer,\n resizeObserver: resizeObserver,\n },\n {\n fieldSchema,\n expectedFieldData,\n disabled,\n label: addButtonLabel,\n }\n );\n }\n } \n\n !disabled && handleInlineEditing();\n\n /**\n * Handles inline editing for supported fields.\n */\n function handleInlineEditing() {\n\n if (!ALLOWED_INLINE_EDITABLE_FIELD.includes(fieldType)) return;\n\n // Instances of ALLOWED_INLINE_EDITABLE_FIELD will always have index at last\n const index = Number(fieldMetadata.instance.fieldPathWithIndex.split('.').at(-1));\n const isInstance = Number.isFinite(index);\n\n // CASE 1: Handle inline editing for multiple field\n if(isFieldMultiple(fieldSchema)) {\n let expectedFieldInstanceData = null;\n if(Array.isArray(expectedFieldData)) {\n // CASE: Selected element is the multiple field itself.\n // Inline Editing not allowed on field, only allowed on instance.\n // (We recieve unreliable `multipleFieldMetadata` in this case)\n if(!isInstance) {\n return;\n }\n\n // CASE: Value does not exist for the provided instance's index\n if(index >= expectedFieldData.length) {\n // TODO: What should be the behavior here?\n }\n else {\n expectedFieldInstanceData = expectedFieldData.at(index);\n }\n }\n // CASE: ContentType's Field changed from single to multiple, while Entry's Field still single.\n else {\n expectedFieldInstanceData = expectedFieldData;\n }\n\n enableInlineEditing(expectedFieldInstanceData); \n }\n // CASE 2: Handle inline editing for a single field\n else {\n let expectedFieldInstanceData = null;\n // CASE: ContentType's Field changed from multiple to single, while Entry's Field still multiple.\n if(isInstance) {\n if(index !== 0) {\n // TODO: Handle this with UX\n // Let user know, CSLP is invalid due to change in Content Type\n return;\n }\n expectedFieldInstanceData = Array.isArray(expectedFieldData) ? expectedFieldData.at(0) : expectedFieldData;\n }\n enableInlineEditing(expectedFieldInstanceData ?? expectedFieldData);\n }\n\n function enableInlineEditing(expectedFieldData: any) {\n\n let actualEditableField = editableElement as HTMLElement;\n\n VisualBuilder.VisualBuilderGlobalState.value.focusFieldValue =\n actualEditableField?.innerText;\n\n const elementComputedDisplay =\n window.getComputedStyle(actualEditableField).display;\n\n let textContent =\n (editableElement as HTMLElement).innerText ||\n editableElement.textContent ||\n \"\";\n\n if (fieldType === FieldDataType.MULTILINE) {\n textContent = getMultilinePlaintext(actualEditableField);\n actualEditableField.addEventListener(\"paste\", pasteAsPlainText);\n }\n const expectedTextContent = expectedFieldData;\n if (\n (expectedTextContent && textContent !== expectedTextContent) ||\n isEllipsisActive(editableElement as HTMLElement)\n ) {\n \n // TODO: Testing will be done in the E2E.\n const pseudoEditableField = generatePseudoEditableElement(\n { editableElement: editableElement as HTMLElement },\n { textContent: expectedFieldData }\n );\n\n (editableElement as HTMLElement).style.visibility = \"hidden\";\n\n // set field type attribute to the pseudo editable field\n // ensures proper keydown handling similar to the actual editable field\n pseudoEditableField.setAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n fieldType\n );\n visualBuilderContainer.appendChild(pseudoEditableField);\n actualEditableField = pseudoEditableField;\n\n if (fieldType === FieldDataType.MULTILINE)\n actualEditableField.addEventListener(\n \"paste\",\n pasteAsPlainText\n );\n\n // we will unobserve this in hideOverlay\n elements.resizeObserver.observe(pseudoEditableField);\n } else if (elementComputedDisplay === \"inline\") {\n // if the editable field is inline\n const onInlineElementInput = throttle(() => {\n const overlayWrapper = visualBuilderContainer.querySelector(\n \".visual-builder__overlay__wrapper\"\n ) as HTMLDivElement;\n const focusedToolbar = visualBuilderContainer.querySelector(\n \".visual-builder__focused-toolbar\"\n ) as HTMLDivElement;\n updateFocussedState({\n editableElement: actualEditableField,\n visualBuilderContainer,\n overlayWrapper,\n focusedToolbar,\n resizeObserver,\n });\n }, 200);\n actualEditableField.addEventListener(\n \"input\",\n onInlineElementInput\n );\n }\n\n actualEditableField.setAttribute(\"contenteditable\", \"true\");\n actualEditableField.addEventListener(\"input\", handleFieldInput);\n actualEditableField.addEventListener(\"keydown\", handleFieldKeyDown);\n // focus on the contenteditable element to start accepting input\n actualEditableField.focus();\n\n return;\n }\n }\n}\n\nfunction isFieldMultiple(fieldSchema: ISchemaFieldMap): boolean {\n return fieldSchema &&\n (fieldSchema.multiple ||\n (fieldSchema.data_type === \"reference\" &&\n // @ts-ignore\n fieldSchema.field_metadata.ref_multiple));\n}\n\nexport function cleanIndividualFieldResidual(elements: {\n overlayWrapper: HTMLDivElement;\n visualBuilderContainer: HTMLDivElement | null;\n focusedToolbar: HTMLDivElement | null;\n resizeObserver: ResizeObserver;\n}): void {\n const { overlayWrapper, visualBuilderContainer, focusedToolbar } = elements;\n\n removeAddInstanceButtons(\n {\n eventTarget: null,\n visualBuilderContainer: visualBuilderContainer,\n overlayWrapper: overlayWrapper,\n },\n true\n );\n\n const previousSelectedEditableDOM =\n VisualBuilder.VisualBuilderGlobalState.value\n .previousSelectedEditableDOM;\n if (previousSelectedEditableDOM) {\n previousSelectedEditableDOM.removeAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n );\n previousSelectedEditableDOM.removeAttribute(\"contenteditable\");\n previousSelectedEditableDOM.removeEventListener(\n \"input\",\n handleFieldInput\n );\n previousSelectedEditableDOM.removeEventListener(\n \"keydown\",\n handleFieldKeyDown\n );\n\n previousSelectedEditableDOM.removeEventListener(\n \"paste\",\n pasteAsPlainText\n );\n // Note - this happens in two places, 1. hideOverlay and 2. here\n // TODO maybe see all usages of both functions and try to do it in one place\n elements.resizeObserver.unobserve(previousSelectedEditableDOM);\n }\n\n const pseudoEditableElement = visualBuilderContainer?.querySelector(\n \".visual-builder__pseudo-editable-element\"\n );\n if (pseudoEditableElement) {\n elements.resizeObserver.unobserve(pseudoEditableElement);\n pseudoEditableElement.removeEventListener(\"paste\", pasteAsPlainText);\n pseudoEditableElement.remove();\n if (previousSelectedEditableDOM) {\n (previousSelectedEditableDOM as HTMLElement).style.removeProperty(\n \"visibility\"\n );\n }\n }\n\n if (focusedToolbar) {\n focusedToolbar.innerHTML = \"\";\n const toolbarEvents = [VisualBuilderPostMessageEvents.DELETE_INSTANCE, VisualBuilderPostMessageEvents.UPDATE_DISCUSSION_ID]\n toolbarEvents.forEach((event) => {\n //@ts-expect-error - We are accessing private method here, but it is necessary to clean up the event listeners.\n visualBuilderPostMessage?.unregisterEvent?.(event);\n });\n }\n}\n\nconst pasteAsPlainText = debounce(\n (e: Event) => {\n e.preventDefault();\n const clipboardData = (e as ClipboardEvent).clipboardData;\n document.execCommand(\n \"inserttext\",\n false,\n clipboardData?.getData(\"text/plain\")\n );\n },\n 100,\n { leading: true }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmC;AACnC,eAA8B;AAC9B,yCAGO;AAEP,uBAGO;AACP,4BAA+B;AAC/B,0BAA6B;AAC7B,0BAA6B;AAC7B,kCAAqD;AACrD,6BAAgC;AAChC,sCAGO;AACP,iCAAoC;AACpC,mBAA+C;AAC/C,mCAAsC;AACtC,yBAA+C;AAC/C,sCAAqC;AAOrC,eAAsB,uBAClB,cACA,UAKa;AACb,QAAM,EAAE,eAAe,gBAAgB,IAAI;AAC3C,QAAM,EAAE,wBAAwB,iBAAiB,eAAe,IAC5D;AACJ,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI;AAEJ,QAAM,CAAC,aAAa,iBAAiB,IAAI,MAAM,QAAQ,IAAI;AA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jB,UAAM,gBAAiB,EAAqB;AAC5C,aAAS;AAAA,MACL;AAAA,MACA;AAAA,MACA,+CAAe,QAAQ;AAAA,IAC3B;AAAA,EACJ;AAAA,EACA;AAAA,EACA,EAAE,SAAS,KAAK;AACpB;","names":["expectedFieldData","visualBuilderPostMessage"]}
|
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
import { updateFocussedState } from "./updateFocussedState.js";
|
|
24
24
|
import { FieldDataType } from "./types/index.types.js";
|
|
25
25
|
import { getMultilinePlaintext } from "./getMultilinePlaintext.js";
|
|
26
|
+
import { VisualBuilderPostMessageEvents } from "./types/postMessage.types.js";
|
|
27
|
+
import visualBuilderPostMessage from "./visualBuilderPostMessage.js";
|
|
26
28
|
async function handleIndividualFields(eventDetails, elements) {
|
|
27
29
|
const { fieldMetadata, editableElement } = eventDetails;
|
|
28
30
|
const { visualBuilderContainer, lastEditedField, resizeObserver } = elements;
|
|
@@ -40,15 +42,13 @@ async function handleIndividualFields(eventDetails, elements) {
|
|
|
40
42
|
fieldPathWithIndex
|
|
41
43
|
)
|
|
42
44
|
]);
|
|
43
|
-
const expectedFieldInstanceData = Array.isArray(expectedFieldData) ? expectedFieldData.at(fieldMetadata.multipleFieldMetadata.index) : void 0;
|
|
44
45
|
const fieldType = getFieldType(fieldSchema);
|
|
45
46
|
const { isDisabled: disabled } = isFieldDisabled(fieldSchema, eventDetails);
|
|
46
47
|
editableElement.setAttribute(
|
|
47
48
|
VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,
|
|
48
49
|
fieldType
|
|
49
50
|
);
|
|
50
|
-
if (
|
|
51
|
-
(fieldSchema == null ? void 0 : fieldSchema.field_metadata.ref_multiple))) {
|
|
51
|
+
if (isFieldMultiple(fieldSchema)) {
|
|
52
52
|
if (lastEditedField !== editableElement) {
|
|
53
53
|
const addButtonLabel = fieldSchema.data_type === "blocks" ? (
|
|
54
54
|
// ? `Add ${fieldSchema.display_name ?? "Modular Block"}`
|
|
@@ -69,70 +69,75 @@ async function handleIndividualFields(eventDetails, elements) {
|
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
|
-
if (eventDetails.fieldMetadata.multipleFieldMetadata.index > -1) {
|
|
73
|
-
handleSingleField(
|
|
74
|
-
{
|
|
75
|
-
editableElement,
|
|
76
|
-
visualBuilderContainer,
|
|
77
|
-
resizeObserver: elements.resizeObserver
|
|
78
|
-
},
|
|
79
|
-
{ expectedFieldData: expectedFieldInstanceData, disabled }
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
handleSingleField(
|
|
84
|
-
{
|
|
85
|
-
editableElement,
|
|
86
|
-
visualBuilderContainer,
|
|
87
|
-
resizeObserver: elements.resizeObserver
|
|
88
|
-
},
|
|
89
|
-
{ expectedFieldData, disabled }
|
|
90
|
-
);
|
|
91
72
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
73
|
+
!disabled && handleInlineEditing();
|
|
74
|
+
function handleInlineEditing() {
|
|
75
|
+
if (!ALLOWED_INLINE_EDITABLE_FIELD.includes(fieldType)) return;
|
|
76
|
+
const index = Number(fieldMetadata.instance.fieldPathWithIndex.split(".").at(-1));
|
|
77
|
+
const isInstance = Number.isFinite(index);
|
|
78
|
+
if (isFieldMultiple(fieldSchema)) {
|
|
79
|
+
let expectedFieldInstanceData = null;
|
|
80
|
+
if (Array.isArray(expectedFieldData)) {
|
|
81
|
+
if (!isInstance) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (index >= expectedFieldData.length) {
|
|
85
|
+
} else {
|
|
86
|
+
expectedFieldInstanceData = expectedFieldData.at(index);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
expectedFieldInstanceData = expectedFieldData;
|
|
90
|
+
}
|
|
91
|
+
enableInlineEditing(expectedFieldInstanceData);
|
|
92
|
+
} else {
|
|
93
|
+
let expectedFieldInstanceData = null;
|
|
94
|
+
if (isInstance) {
|
|
95
|
+
if (index !== 0) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
expectedFieldInstanceData = Array.isArray(expectedFieldData) ? expectedFieldData.at(0) : expectedFieldData;
|
|
99
|
+
}
|
|
100
|
+
enableInlineEditing(expectedFieldInstanceData ?? expectedFieldData);
|
|
96
101
|
}
|
|
97
|
-
|
|
98
|
-
let actualEditableField =
|
|
102
|
+
function enableInlineEditing(expectedFieldData2) {
|
|
103
|
+
let actualEditableField = editableElement;
|
|
99
104
|
VisualBuilder.VisualBuilderGlobalState.value.focusFieldValue = actualEditableField == null ? void 0 : actualEditableField.innerText;
|
|
100
105
|
const elementComputedDisplay = window.getComputedStyle(actualEditableField).display;
|
|
101
|
-
let textContent =
|
|
106
|
+
let textContent = editableElement.innerText || editableElement.textContent || "";
|
|
102
107
|
if (fieldType === FieldDataType.MULTILINE) {
|
|
103
108
|
textContent = getMultilinePlaintext(actualEditableField);
|
|
104
109
|
actualEditableField.addEventListener("paste", pasteAsPlainText);
|
|
105
110
|
}
|
|
106
|
-
const expectedTextContent =
|
|
107
|
-
if (textContent !== expectedTextContent || isEllipsisActive(
|
|
111
|
+
const expectedTextContent = expectedFieldData2;
|
|
112
|
+
if (expectedTextContent && textContent !== expectedTextContent || isEllipsisActive(editableElement)) {
|
|
108
113
|
const pseudoEditableField = generatePseudoEditableElement(
|
|
109
|
-
{ editableElement
|
|
110
|
-
{ textContent:
|
|
114
|
+
{ editableElement },
|
|
115
|
+
{ textContent: expectedFieldData2 }
|
|
111
116
|
);
|
|
112
|
-
|
|
117
|
+
editableElement.style.visibility = "hidden";
|
|
113
118
|
pseudoEditableField.setAttribute(
|
|
114
119
|
VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,
|
|
115
120
|
fieldType
|
|
116
121
|
);
|
|
117
|
-
|
|
122
|
+
visualBuilderContainer.appendChild(pseudoEditableField);
|
|
118
123
|
actualEditableField = pseudoEditableField;
|
|
119
124
|
if (fieldType === FieldDataType.MULTILINE)
|
|
120
125
|
actualEditableField.addEventListener(
|
|
121
126
|
"paste",
|
|
122
127
|
pasteAsPlainText
|
|
123
128
|
);
|
|
124
|
-
|
|
129
|
+
elements.resizeObserver.observe(pseudoEditableField);
|
|
125
130
|
} else if (elementComputedDisplay === "inline") {
|
|
126
131
|
const onInlineElementInput = throttle(() => {
|
|
127
|
-
const overlayWrapper =
|
|
132
|
+
const overlayWrapper = visualBuilderContainer.querySelector(
|
|
128
133
|
".visual-builder__overlay__wrapper"
|
|
129
134
|
);
|
|
130
|
-
const focusedToolbar =
|
|
135
|
+
const focusedToolbar = visualBuilderContainer.querySelector(
|
|
131
136
|
".visual-builder__focused-toolbar"
|
|
132
137
|
);
|
|
133
138
|
updateFocussedState({
|
|
134
139
|
editableElement: actualEditableField,
|
|
135
|
-
visualBuilderContainer
|
|
140
|
+
visualBuilderContainer,
|
|
136
141
|
overlayWrapper,
|
|
137
142
|
focusedToolbar,
|
|
138
143
|
resizeObserver
|
|
@@ -151,6 +156,10 @@ async function handleIndividualFields(eventDetails, elements) {
|
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
158
|
}
|
|
159
|
+
function isFieldMultiple(fieldSchema) {
|
|
160
|
+
return fieldSchema && (fieldSchema.multiple || fieldSchema.data_type === "reference" && // @ts-ignore
|
|
161
|
+
fieldSchema.field_metadata.ref_multiple);
|
|
162
|
+
}
|
|
154
163
|
function cleanIndividualFieldResidual(elements) {
|
|
155
164
|
const { overlayWrapper, visualBuilderContainer, focusedToolbar } = elements;
|
|
156
165
|
removeAddInstanceButtons(
|
|
@@ -196,6 +205,11 @@ function cleanIndividualFieldResidual(elements) {
|
|
|
196
205
|
}
|
|
197
206
|
if (focusedToolbar) {
|
|
198
207
|
focusedToolbar.innerHTML = "";
|
|
208
|
+
const toolbarEvents = [VisualBuilderPostMessageEvents.DELETE_INSTANCE, VisualBuilderPostMessageEvents.UPDATE_DISCUSSION_ID];
|
|
209
|
+
toolbarEvents.forEach((event) => {
|
|
210
|
+
var _a, _b;
|
|
211
|
+
(_b = (_a = visualBuilderPostMessage) == null ? void 0 : _a.unregisterEvent) == null ? void 0 : _b.call(_a, event);
|
|
212
|
+
});
|
|
199
213
|
}
|
|
200
214
|
}
|
|
201
215
|
var pasteAsPlainText = debounce(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/visualBuilder/utils/handleIndividualFields.ts"],"sourcesContent":["import { debounce, throttle } from \"lodash-es\";\nimport { VisualBuilder } from \"..\";\nimport {\n generatePseudoEditableElement,\n isEllipsisActive,\n} from \"../generators/generatePseudoEditableField\";\nimport { VisualBuilderCslpEventDetails } from \"../types/visualBuilder.types\";\nimport {\n ALLOWED_INLINE_EDITABLE_FIELD,\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n} from \"./constants\";\nimport { FieldSchemaMap } from \"./fieldSchemaMap\";\nimport { getFieldData } from \"./getFieldData\";\nimport { getFieldType } from \"./getFieldType\";\nimport { handleFieldInput, handleFieldKeyDown } from \"./handleFieldMouseDown\";\nimport { isFieldDisabled } from \"./isFieldDisabled\";\nimport visualBuilderPostMessage from \"./visualBuilderPostMessage\";\nimport {\n handleAddButtonsForMultiple,\n removeAddInstanceButtons,\n} from \"./multipleElementAddButton\";\nimport { VisualBuilderPostMessageEvents } from \"./types/postMessage.types\";\nimport { updateFocussedState } from \"./updateFocussedState\";\nimport { FieldDataType } from \"./types/index.types\";\nimport { getMultilinePlaintext } from \"./getMultilinePlaintext\";\n\n/**\n * It handles all the fields based on their data type and its \"multiple\" property.\n * @param eventDetails The event details object that contain cslp and field metadata.\n * @param elements The elements object that contain the visual builder wrapper.\n */\nexport async function handleIndividualFields(\n eventDetails: VisualBuilderCslpEventDetails,\n elements: {\n visualBuilderContainer: HTMLDivElement;\n resizeObserver: ResizeObserver;\n lastEditedField: Element | null;\n }\n): Promise<void> {\n const { fieldMetadata, editableElement } = eventDetails;\n const { visualBuilderContainer, lastEditedField, resizeObserver } =\n elements;\n const {\n content_type_uid,\n entry_uid,\n locale,\n fieldPath,\n fieldPathWithIndex,\n } = fieldMetadata;\n\n const [fieldSchema, expectedFieldData] = await Promise.all([\n FieldSchemaMap.getFieldSchema(content_type_uid, fieldPath),\n getFieldData(\n { content_type_uid, entry_uid, locale },\n fieldPathWithIndex\n ),\n ]);\n // if value is an array, get the value for the instance\n const expectedFieldInstanceData = Array.isArray(expectedFieldData)\n ? expectedFieldData.at(fieldMetadata.multipleFieldMetadata.index)\n : undefined;\n\n const fieldType = getFieldType(fieldSchema);\n\n const { isDisabled: disabled } = isFieldDisabled(fieldSchema, eventDetails);\n\n editableElement.setAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n fieldType\n );\n\n if (\n fieldSchema &&\n (fieldSchema?.multiple ||\n (fieldSchema?.data_type === \"reference\" &&\n // @ts-ignore\n fieldSchema?.field_metadata.ref_multiple))\n ) {\n if (lastEditedField !== editableElement) {\n const addButtonLabel =\n fieldSchema.data_type === \"blocks\"\n ? // ? `Add ${fieldSchema.display_name ?? \"Modular Block\"}`\n \"Add Section\"\n : undefined;\n\n handleAddButtonsForMultiple(\n eventDetails,\n {\n editableElement: eventDetails.editableElement,\n visualBuilderContainer: visualBuilderContainer,\n resizeObserver: resizeObserver,\n },\n {\n fieldSchema,\n expectedFieldData,\n disabled,\n label: addButtonLabel,\n }\n );\n }\n\n // * fields could be handled as they are in a single instance\n if (eventDetails.fieldMetadata.multipleFieldMetadata.index > -1) {\n handleSingleField(\n {\n editableElement,\n visualBuilderContainer,\n resizeObserver: elements.resizeObserver,\n },\n { expectedFieldData: expectedFieldInstanceData, disabled }\n );\n }\n } else {\n handleSingleField(\n {\n editableElement,\n visualBuilderContainer,\n resizeObserver: elements.resizeObserver,\n },\n { expectedFieldData, disabled }\n );\n }\n\n /**\n * Handles all the fields based on their data type.\n */\n function handleSingleField(\n elements: {\n editableElement: Element;\n visualBuilderContainer: HTMLDivElement;\n resizeObserver: ResizeObserver;\n },\n config: { expectedFieldData: string; disabled?: boolean }\n ) {\n const { editableElement, visualBuilderContainer } = elements;\n\n if (config.disabled) {\n return;\n }\n\n // * title, single single_line, single multi_line, single number\n if (ALLOWED_INLINE_EDITABLE_FIELD.includes(fieldType)) {\n let actualEditableField = editableElement as HTMLElement;\n\n VisualBuilder.VisualBuilderGlobalState.value.focusFieldValue =\n actualEditableField?.innerText;\n\n const elementComputedDisplay =\n window.getComputedStyle(actualEditableField).display;\n\n let textContent =\n (editableElement as HTMLElement).innerText ||\n editableElement.textContent ||\n \"\";\n\n if (fieldType === FieldDataType.MULTILINE) {\n textContent = getMultilinePlaintext(actualEditableField);\n actualEditableField.addEventListener(\"paste\", pasteAsPlainText);\n }\n const expectedTextContent = config.expectedFieldData;\n if (\n textContent !== expectedTextContent ||\n isEllipsisActive(editableElement as HTMLElement)\n ) {\n // TODO: Testing will be don in the E2E.\n const pseudoEditableField = generatePseudoEditableElement(\n { editableElement: editableElement as HTMLElement },\n { textContent: config.expectedFieldData }\n );\n\n (editableElement as HTMLElement).style.visibility = \"hidden\";\n\n // set field type attribute to the pseudo editable field\n // ensures proper keydown handling similar to the actual editable field\n pseudoEditableField.setAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n fieldType\n );\n visualBuilderContainer.appendChild(pseudoEditableField);\n actualEditableField = pseudoEditableField;\n\n if (fieldType === FieldDataType.MULTILINE)\n actualEditableField.addEventListener(\n \"paste\",\n pasteAsPlainText\n );\n\n // we will unobserve this in hideOverlay\n elements.resizeObserver.observe(pseudoEditableField);\n } else if (elementComputedDisplay === \"inline\") {\n // if the editable field is inline\n const onInlineElementInput = throttle(() => {\n const overlayWrapper = visualBuilderContainer.querySelector(\n \".visual-builder__overlay__wrapper\"\n ) as HTMLDivElement;\n const focusedToolbar = visualBuilderContainer.querySelector(\n \".visual-builder__focused-toolbar\"\n ) as HTMLDivElement;\n updateFocussedState({\n editableElement: actualEditableField,\n visualBuilderContainer,\n overlayWrapper,\n focusedToolbar,\n resizeObserver,\n });\n }, 200);\n actualEditableField.addEventListener(\n \"input\",\n onInlineElementInput\n );\n }\n\n actualEditableField.setAttribute(\"contenteditable\", \"true\");\n actualEditableField.addEventListener(\"input\", handleFieldInput);\n actualEditableField.addEventListener(\"keydown\", handleFieldKeyDown);\n // focus on the contenteditable element to start accepting input\n actualEditableField.focus();\n\n return;\n }\n }\n}\n\nexport function cleanIndividualFieldResidual(elements: {\n overlayWrapper: HTMLDivElement;\n visualBuilderContainer: HTMLDivElement | null;\n focusedToolbar: HTMLDivElement | null;\n resizeObserver: ResizeObserver;\n}): void {\n const { overlayWrapper, visualBuilderContainer, focusedToolbar } = elements;\n\n removeAddInstanceButtons(\n {\n eventTarget: null,\n visualBuilderContainer: visualBuilderContainer,\n overlayWrapper: overlayWrapper,\n },\n true\n );\n\n const previousSelectedEditableDOM =\n VisualBuilder.VisualBuilderGlobalState.value\n .previousSelectedEditableDOM;\n if (previousSelectedEditableDOM) {\n previousSelectedEditableDOM.removeAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n );\n previousSelectedEditableDOM.removeAttribute(\"contenteditable\");\n previousSelectedEditableDOM.removeEventListener(\n \"input\",\n handleFieldInput\n );\n previousSelectedEditableDOM.removeEventListener(\n \"keydown\",\n handleFieldKeyDown\n );\n\n previousSelectedEditableDOM.removeEventListener(\n \"paste\",\n pasteAsPlainText\n );\n // Note - this happens in two places, 1. hideOverlay and 2. here\n // TODO maybe see all usages of both functions and try to do it in one place\n elements.resizeObserver.unobserve(previousSelectedEditableDOM);\n }\n\n const pseudoEditableElement = visualBuilderContainer?.querySelector(\n \".visual-builder__pseudo-editable-element\"\n );\n if (pseudoEditableElement) {\n elements.resizeObserver.unobserve(pseudoEditableElement);\n pseudoEditableElement.removeEventListener(\"paste\", pasteAsPlainText);\n pseudoEditableElement.remove();\n if (previousSelectedEditableDOM) {\n (previousSelectedEditableDOM as HTMLElement).style.removeProperty(\n \"visibility\"\n );\n }\n }\n\n if (focusedToolbar) {\n focusedToolbar.innerHTML = \"\";\n }\n}\n\nconst pasteAsPlainText = debounce(\n (e: Event) => {\n e.preventDefault();\n const clipboardData = (e as ClipboardEvent).clipboardData;\n document.execCommand(\n \"inserttext\",\n false,\n clipboardData?.getData(\"text/plain\")\n );\n },\n 100,\n { leading: true }\n);\n"],"mappings":";;;AAAA,SAAS,UAAU,gBAAgB;AACnC,SAAS,qBAAqB;AAC9B;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB,0BAA0B;AACrD,SAAS,uBAAuB;AAEhC;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAOtC,eAAsB,uBAClB,cACA,UAKa;AACb,QAAM,EAAE,eAAe,gBAAgB,IAAI;AAC3C,QAAM,EAAE,wBAAwB,iBAAiB,eAAe,IAC5D;AACJ,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI;AAEJ,QAAM,CAAC,aAAa,iBAAiB,IAAI,MAAM,QAAQ,IAAI;AAAA,IACvD,eAAe,eAAe,kBAAkB,SAAS;AAAA,IACzD;AAAA,MACI,EAAE,kBAAkB,WAAW,OAAO;AAAA,MACtC;AAAA,IACJ;AAAA,EACJ,CAAC;AAED,QAAM,4BAA4B,MAAM,QAAQ,iBAAiB,IAC3D,kBAAkB,GAAG,cAAc,sBAAsB,KAAK,IAC9D;AAEN,QAAM,YAAY,aAAa,WAAW;AAE1C,QAAM,EAAE,YAAY,SAAS,IAAI,gBAAgB,aAAa,YAAY;AAE1E,kBAAgB;AAAA,IACZ;AAAA,IACA;AAAA,EACJ;AAEA,MACI,iBACC,2CAAa,cACT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EA,gCAA4B;AAAA,MACxB;AAAA,MACA;AAAA,IACJ;AAGA,aAAS,eAAe,UAAU,2BAA2B;AAAA,EACjE;AAEA,QAAM,wBAAwB,iEAAwB;AAAA,IAClD;AAAA;AAEJ,MAAI,uBAAuB;AACvB,aAAS,eAAe,UAAU,qBAAqB;AACvD,0BAAsB,oBAAoB,SAAS,gBAAgB;AACnE,0BAAsB,OAAO;AAC7B,QAAI,6BAA6B;AAC7B,MAAC,4BAA4C,MAAM;AAAA,QAC/C;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAEA,MAAI,gBAAgB;AAChB,mBAAe,YAAY;AAAA,EAC/B;AACJ;AAEA,IAAM,mBAAmB;AAAA,EACrB,CAAC,MAAa;AACV,MAAE,eAAe;AACjB,UAAM,gBAAiB,EAAqB;AAC5C,aAAS;AAAA,MACL;AAAA,MACA;AAAA,MACA,+CAAe,QAAQ;AAAA,IAC3B;AAAA,EACJ;AAAA,EACA;AAAA,EACA,EAAE,SAAS,KAAK;AACpB;","names":["elements","editableElement","visualBuilderContainer"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/visualBuilder/utils/handleIndividualFields.ts"],"sourcesContent":["import { debounce, throttle } from \"lodash-es\";\nimport { VisualBuilder } from \"..\";\nimport {\n generatePseudoEditableElement,\n isEllipsisActive,\n} from \"../generators/generatePseudoEditableField\";\nimport { VisualBuilderCslpEventDetails } from \"../types/visualBuilder.types\";\nimport {\n ALLOWED_INLINE_EDITABLE_FIELD,\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n} from \"./constants\";\nimport { FieldSchemaMap } from \"./fieldSchemaMap\";\nimport { getFieldData } from \"./getFieldData\";\nimport { getFieldType } from \"./getFieldType\";\nimport { handleFieldInput, handleFieldKeyDown } from \"./handleFieldMouseDown\";\nimport { isFieldDisabled } from \"./isFieldDisabled\";\nimport {\n handleAddButtonsForMultiple,\n removeAddInstanceButtons,\n} from \"./multipleElementAddButton\";\nimport { updateFocussedState } from \"./updateFocussedState\";\nimport { FieldDataType, ISchemaFieldMap } from \"./types/index.types\";\nimport { getMultilinePlaintext } from \"./getMultilinePlaintext\";\nimport { VisualBuilderPostMessageEvents } from \"./types/postMessage.types\";\nimport visualBuilderPostMessage from \"./visualBuilderPostMessage\";\n\n/**\n * It handles all the fields based on their data type and its \"multiple\" property.\n * @param eventDetails The event details object that contain cslp and field metadata.\n * @param elements The elements object that contain the visual builder wrapper.\n */\nexport async function handleIndividualFields(\n eventDetails: VisualBuilderCslpEventDetails,\n elements: {\n visualBuilderContainer: HTMLDivElement;\n resizeObserver: ResizeObserver;\n lastEditedField: Element | null;\n }\n): Promise<void> {\n const { fieldMetadata, editableElement } = eventDetails;\n const { visualBuilderContainer, lastEditedField, resizeObserver } =\n elements;\n const {\n content_type_uid,\n entry_uid,\n locale,\n fieldPath,\n fieldPathWithIndex,\n } = fieldMetadata;\n\n const [fieldSchema, expectedFieldData] = await Promise.all([\n FieldSchemaMap.getFieldSchema(content_type_uid, fieldPath),\n getFieldData(\n { content_type_uid, entry_uid, locale },\n fieldPathWithIndex\n ),\n ]);\n\n const fieldType = getFieldType(fieldSchema);\n\n const { isDisabled: disabled } = isFieldDisabled(fieldSchema, eventDetails);\n\n editableElement.setAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n fieldType\n );\n\n if (isFieldMultiple(fieldSchema)) {\n if (lastEditedField !== editableElement) {\n const addButtonLabel =\n fieldSchema.data_type === \"blocks\"\n ? // ? `Add ${fieldSchema.display_name ?? \"Modular Block\"}`\n \"Add Section\"\n : undefined;\n\n handleAddButtonsForMultiple(\n eventDetails,\n {\n editableElement: eventDetails.editableElement,\n visualBuilderContainer: visualBuilderContainer,\n resizeObserver: resizeObserver,\n },\n {\n fieldSchema,\n expectedFieldData,\n disabled,\n label: addButtonLabel,\n }\n );\n }\n } \n\n !disabled && handleInlineEditing();\n\n /**\n * Handles inline editing for supported fields.\n */\n function handleInlineEditing() {\n\n if (!ALLOWED_INLINE_EDITABLE_FIELD.includes(fieldType)) return;\n\n // Instances of ALLOWED_INLINE_EDITABLE_FIELD will always have index at last\n const index = Number(fieldMetadata.instance.fieldPathWithIndex.split('.').at(-1));\n const isInstance = Number.isFinite(index);\n\n // CASE 1: Handle inline editing for multiple field\n if(isFieldMultiple(fieldSchema)) {\n let expectedFieldInstanceData = null;\n if(Array.isArray(expectedFieldData)) {\n // CASE: Selected element is the multiple field itself.\n // Inline Editing not allowed on field, only allowed on instance.\n // (We recieve unreliable `multipleFieldMetadata` in this case)\n if(!isInstance) {\n return;\n }\n\n // CASE: Value does not exist for the provided instance's index\n if(index >= expectedFieldData.length) {\n // TODO: What should be the behavior here?\n }\n else {\n expectedFieldInstanceData = expectedFieldData.at(index);\n }\n }\n // CASE: ContentType's Field changed from single to multiple, while Entry's Field still single.\n else {\n expectedFieldInstanceData = expectedFieldData;\n }\n\n enableInlineEditing(expectedFieldInstanceData); \n }\n // CASE 2: Handle inline editing for a single field\n else {\n let expectedFieldInstanceData = null;\n // CASE: ContentType's Field changed from multiple to single, while Entry's Field still multiple.\n if(isInstance) {\n if(index !== 0) {\n // TODO: Handle this with UX\n // Let user know, CSLP is invalid due to change in Content Type\n return;\n }\n expectedFieldInstanceData = Array.isArray(expectedFieldData) ? expectedFieldData.at(0) : expectedFieldData;\n }\n enableInlineEditing(expectedFieldInstanceData ?? expectedFieldData);\n }\n\n function enableInlineEditing(expectedFieldData: any) {\n\n let actualEditableField = editableElement as HTMLElement;\n\n VisualBuilder.VisualBuilderGlobalState.value.focusFieldValue =\n actualEditableField?.innerText;\n\n const elementComputedDisplay =\n window.getComputedStyle(actualEditableField).display;\n\n let textContent =\n (editableElement as HTMLElement).innerText ||\n editableElement.textContent ||\n \"\";\n\n if (fieldType === FieldDataType.MULTILINE) {\n textContent = getMultilinePlaintext(actualEditableField);\n actualEditableField.addEventListener(\"paste\", pasteAsPlainText);\n }\n const expectedTextContent = expectedFieldData;\n if (\n (expectedTextContent && textContent !== expectedTextContent) ||\n isEllipsisActive(editableElement as HTMLElement)\n ) {\n \n // TODO: Testing will be done in the E2E.\n const pseudoEditableField = generatePseudoEditableElement(\n { editableElement: editableElement as HTMLElement },\n { textContent: expectedFieldData }\n );\n\n (editableElement as HTMLElement).style.visibility = \"hidden\";\n\n // set field type attribute to the pseudo editable field\n // ensures proper keydown handling similar to the actual editable field\n pseudoEditableField.setAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY,\n fieldType\n );\n visualBuilderContainer.appendChild(pseudoEditableField);\n actualEditableField = pseudoEditableField;\n\n if (fieldType === FieldDataType.MULTILINE)\n actualEditableField.addEventListener(\n \"paste\",\n pasteAsPlainText\n );\n\n // we will unobserve this in hideOverlay\n elements.resizeObserver.observe(pseudoEditableField);\n } else if (elementComputedDisplay === \"inline\") {\n // if the editable field is inline\n const onInlineElementInput = throttle(() => {\n const overlayWrapper = visualBuilderContainer.querySelector(\n \".visual-builder__overlay__wrapper\"\n ) as HTMLDivElement;\n const focusedToolbar = visualBuilderContainer.querySelector(\n \".visual-builder__focused-toolbar\"\n ) as HTMLDivElement;\n updateFocussedState({\n editableElement: actualEditableField,\n visualBuilderContainer,\n overlayWrapper,\n focusedToolbar,\n resizeObserver,\n });\n }, 200);\n actualEditableField.addEventListener(\n \"input\",\n onInlineElementInput\n );\n }\n\n actualEditableField.setAttribute(\"contenteditable\", \"true\");\n actualEditableField.addEventListener(\"input\", handleFieldInput);\n actualEditableField.addEventListener(\"keydown\", handleFieldKeyDown);\n // focus on the contenteditable element to start accepting input\n actualEditableField.focus();\n\n return;\n }\n }\n}\n\nfunction isFieldMultiple(fieldSchema: ISchemaFieldMap): boolean {\n return fieldSchema &&\n (fieldSchema.multiple ||\n (fieldSchema.data_type === \"reference\" &&\n // @ts-ignore\n fieldSchema.field_metadata.ref_multiple));\n}\n\nexport function cleanIndividualFieldResidual(elements: {\n overlayWrapper: HTMLDivElement;\n visualBuilderContainer: HTMLDivElement | null;\n focusedToolbar: HTMLDivElement | null;\n resizeObserver: ResizeObserver;\n}): void {\n const { overlayWrapper, visualBuilderContainer, focusedToolbar } = elements;\n\n removeAddInstanceButtons(\n {\n eventTarget: null,\n visualBuilderContainer: visualBuilderContainer,\n overlayWrapper: overlayWrapper,\n },\n true\n );\n\n const previousSelectedEditableDOM =\n VisualBuilder.VisualBuilderGlobalState.value\n .previousSelectedEditableDOM;\n if (previousSelectedEditableDOM) {\n previousSelectedEditableDOM.removeAttribute(\n VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY\n );\n previousSelectedEditableDOM.removeAttribute(\"contenteditable\");\n previousSelectedEditableDOM.removeEventListener(\n \"input\",\n handleFieldInput\n );\n previousSelectedEditableDOM.removeEventListener(\n \"keydown\",\n handleFieldKeyDown\n );\n\n previousSelectedEditableDOM.removeEventListener(\n \"paste\",\n pasteAsPlainText\n );\n // Note - this happens in two places, 1. hideOverlay and 2. here\n // TODO maybe see all usages of both functions and try to do it in one place\n elements.resizeObserver.unobserve(previousSelectedEditableDOM);\n }\n\n const pseudoEditableElement = visualBuilderContainer?.querySelector(\n \".visual-builder__pseudo-editable-element\"\n );\n if (pseudoEditableElement) {\n elements.resizeObserver.unobserve(pseudoEditableElement);\n pseudoEditableElement.removeEventListener(\"paste\", pasteAsPlainText);\n pseudoEditableElement.remove();\n if (previousSelectedEditableDOM) {\n (previousSelectedEditableDOM as HTMLElement).style.removeProperty(\n \"visibility\"\n );\n }\n }\n\n if (focusedToolbar) {\n focusedToolbar.innerHTML = \"\";\n const toolbarEvents = [VisualBuilderPostMessageEvents.DELETE_INSTANCE, VisualBuilderPostMessageEvents.UPDATE_DISCUSSION_ID]\n toolbarEvents.forEach((event) => {\n //@ts-expect-error - We are accessing private method here, but it is necessary to clean up the event listeners.\n visualBuilderPostMessage?.unregisterEvent?.(event);\n });\n }\n}\n\nconst pasteAsPlainText = debounce(\n (e: Event) => {\n e.preventDefault();\n const clipboardData = (e as ClipboardEvent).clipboardData;\n document.execCommand(\n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