@mgdis/mg-components 6.5.0 → 6.6.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.
- package/dist/cjs/{index-ede3b3dc.js → index-019dd5c0.js} +2 -2
- package/dist/cjs/{index-ede3b3dc.js.map → index-019dd5c0.js.map} +1 -1
- package/dist/cjs/index-1a5a1081.js +4 -0
- package/dist/cjs/{index.es-a112f649.js → index.es-903492c5.js} +26 -27
- package/dist/cjs/index.es-903492c5.js.map +1 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/mg-action-more_36.cjs.entry.js +231 -197
- package/dist/cjs/mg-action-more_36.cjs.entry.js.map +1 -1
- package/dist/cjs/mg-alert.cjs.entry.js +4 -4
- package/dist/cjs/mg-components.cjs.js +1 -1
- package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js +16790 -0
- package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js.map +1 -0
- package/dist/cjs/mg-input.conf-5bbcea79.js +23 -0
- package/dist/cjs/mg-input.conf-5bbcea79.js.map +1 -0
- package/dist/cjs/mg-loader.cjs.entry.js +3 -3
- package/dist/cjs/mg-progress.cjs.entry.js +2 -2
- package/dist/collection/assets/icons/index.js +1 -1
- package/dist/collection/assets/icons/index.js.map +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js.map +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +3 -3
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input/mg-input.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input/mg-input.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +2 -2
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/index.js +110 -0
- package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/index.js.map +1 -0
- package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js +846 -0
- package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js.map +1 -0
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +3 -5
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
- package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js +4 -4
- package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js.map +1 -1
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.conf.js +1 -1
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.conf.js.map +1 -1
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +16 -17
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js.map +1 -1
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +8 -6
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js.map +1 -1
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +3 -3
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js.map +1 -1
- package/dist/collection/components/molecules/mg-alert/mg-alert.js +1 -1
- package/dist/collection/components/molecules/mg-details/mg-details.js +1 -1
- package/dist/collection/components/molecules/mg-details/mg-details.js.map +1 -1
- package/dist/collection/components/molecules/mg-form/mg-form.js +2 -2
- package/dist/collection/components/molecules/mg-form/mg-form.js.map +1 -1
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.conf.js +5 -2
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.conf.js.map +1 -1
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +74 -17
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js.map +1 -1
- package/dist/collection/components/molecules/mg-loader/mg-loader.js +1 -1
- package/dist/collection/components/molecules/mg-message/mg-message.js +2 -2
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +2 -2
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +3 -3
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +3 -3
- package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
- package/dist/collection/components/molecules/mg-progress/mg-progress.js +1 -1
- package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +1 -1
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +1 -1
- package/dist/collection/types/index.js.map +1 -1
- package/dist/collection/utils/behaviors.utils.js +4 -1
- package/dist/collection/utils/behaviors.utils.js.map +1 -1
- package/dist/collection/utils/floating-ui.utils.js +1 -6
- package/dist/collection/utils/floating-ui.utils.js.map +1 -1
- package/dist/components/floating-ui.utils.js +1 -6
- package/dist/components/floating-ui.utils.js.map +1 -1
- package/dist/components/index.es.js +24 -25
- package/dist/components/index.es.js.map +1 -1
- package/dist/components/mg-action-more.js +2 -2
- package/dist/components/mg-action-more.js.map +1 -1
- package/dist/components/mg-alert.js +3 -3
- package/dist/components/mg-badge2.js +2 -2
- package/dist/components/mg-button2.js +2 -2
- package/dist/components/mg-card2.js +1 -1
- package/dist/components/mg-card2.js.map +1 -1
- package/dist/components/mg-details.js +1 -1
- package/dist/components/mg-details.js.map +1 -1
- package/dist/components/mg-form.js +4 -4
- package/dist/components/mg-form.js.map +1 -1
- package/dist/components/mg-icon2.js +3 -3
- package/dist/components/mg-icon2.js.map +1 -1
- package/dist/components/mg-illustrated-message.js +69 -16
- package/dist/components/mg-illustrated-message.js.map +1 -1
- package/dist/components/mg-input-checkbox.js +4 -4
- package/dist/components/mg-input-checkbox.js.map +1 -1
- package/dist/components/mg-input-date.js +7 -7
- package/dist/components/mg-input-date.js.map +1 -1
- package/dist/components/mg-input-numeric.js +9 -9
- package/dist/components/mg-input-numeric.js.map +1 -1
- package/dist/components/mg-input-password.js +3 -3
- package/dist/components/mg-input-password.js.map +1 -1
- package/dist/components/mg-input-radio.js +5 -5
- package/dist/components/mg-input-radio.js.map +1 -1
- package/dist/components/mg-input-rich-text-editor.d.ts +11 -0
- package/dist/components/mg-input-rich-text-editor.js +16866 -0
- package/dist/components/mg-input-rich-text-editor.js.map +1 -0
- package/dist/components/mg-input-select2.js +6 -6
- package/dist/components/mg-input-select2.js.map +1 -1
- package/dist/components/mg-input-text2.js +7 -9
- package/dist/components/mg-input-text2.js.map +1 -1
- package/dist/components/mg-input-textarea.js +5 -5
- package/dist/components/mg-input-textarea.js.map +1 -1
- package/dist/components/mg-input-toggle.js +4 -4
- package/dist/components/mg-input2.js +1 -1
- package/dist/components/mg-input2.js.map +1 -1
- package/dist/components/mg-item-more2.js +17 -15
- package/dist/components/mg-item-more2.js.map +1 -1
- package/dist/components/mg-loader.js +1 -1
- package/dist/components/mg-menu-item2.js +11 -9
- package/dist/components/mg-menu-item2.js.map +1 -1
- package/dist/components/mg-message2.js +4 -4
- package/dist/components/mg-modal.js +5 -5
- package/dist/components/mg-modal.js.map +1 -1
- package/dist/components/mg-pagination2.js +3 -3
- package/dist/components/mg-panel.js +3 -3
- package/dist/components/mg-popover-content2.js +4 -4
- package/dist/components/mg-popover2.js +3 -3
- package/dist/components/mg-popover2.js.map +1 -1
- package/dist/components/mg-progress.js +1 -1
- package/dist/components/mg-skip-links.js +1 -1
- package/dist/components/mg-tabs.js +4 -4
- package/dist/components/mg-tag.js +2 -2
- package/dist/components/mg-tooltip2.js +5 -5
- package/dist/components/mg-tooltip2.js.map +1 -1
- package/dist/esm/index-5059254f.js +4 -0
- package/dist/esm/{index-a7c3b5c5.js → index-6b7bdd63.js} +2 -2
- package/dist/esm/{index-a7c3b5c5.js.map → index-6b7bdd63.js.map} +1 -1
- package/dist/esm/{index.es-5e0101ac.js → index.es-b80b758c.js} +25 -26
- package/dist/esm/index.es-b80b758c.js.map +1 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mg-action-more_36.entry.js +182 -148
- package/dist/esm/mg-action-more_36.entry.js.map +1 -1
- package/dist/esm/mg-alert.entry.js +4 -4
- package/dist/esm/mg-components.js +1 -1
- package/dist/esm/mg-input-rich-text-editor.entry.js +16786 -0
- package/dist/esm/mg-input-rich-text-editor.entry.js.map +1 -0
- package/dist/esm/mg-input.conf-712c7bb6.js +16 -0
- package/dist/esm/mg-input.conf-712c7bb6.js.map +1 -0
- package/dist/esm/mg-loader.entry.js +3 -3
- package/dist/esm/mg-progress.entry.js +2 -2
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/mg-components.esm.js.map +1 -1
- package/dist/mg-components/{p-2403e01d.entry.js → p-0ae49cc4.entry.js} +2 -2
- package/dist/mg-components/p-17f0b7eb.entry.js +2 -0
- package/dist/mg-components/p-17f0b7eb.entry.js.map +1 -0
- package/dist/mg-components/p-2884f369.js +2 -0
- package/dist/mg-components/p-2884f369.js.map +1 -0
- package/dist/mg-components/{p-ad64ab4a.entry.js → p-361cc090.entry.js} +2 -2
- package/dist/mg-components/p-3c6710be.js +2 -0
- package/dist/mg-components/p-3c6710be.js.map +1 -0
- package/dist/mg-components/{p-d9731ebc.js → p-4049bd40.js} +2 -2
- package/dist/mg-components/p-8dbb78aa.entry.js +2 -0
- package/dist/mg-components/p-8dbb78aa.entry.js.map +1 -0
- package/dist/mg-components/{p-1a162791.entry.js → p-c4f37d1f.entry.js} +2 -2
- package/dist/types/assets/icons/index.d.ts +1 -0
- package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/editor/index.d.ts +21 -0
- package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.d.ts +202 -0
- package/dist/types/components/molecules/menu/mg-menu/mg-menu.conf.d.ts +2 -6
- package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +3 -2
- package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +4 -3
- package/dist/types/components/molecules/mg-illustrated-message/mg-illustrated-message.conf.d.ts +10 -3
- package/dist/types/components/molecules/mg-illustrated-message/mg-illustrated-message.d.ts +17 -3
- package/dist/types/components.d.ts +217 -8
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/utils/floating-ui.utils.d.ts +1 -1
- package/ide/intellij/web-types.json +374 -17
- package/ide/vscode/css-custom-data.json +4 -0
- package/ide/vscode/html-custom-data.json +289 -4
- package/package.json +22 -21
- package/dist/cjs/index.es-a112f649.js.map +0 -1
- package/dist/esm/index.es-5e0101ac.js.map +0 -1
- package/dist/mg-components/p-6c831a83.entry.js +0 -2
- package/dist/mg-components/p-6c831a83.entry.js.map +0 -1
- package/dist/mg-components/p-b6c1a6ce.js +0 -2
- package/dist/mg-components/p-b6c1a6ce.js.map +0 -1
- /package/dist/mg-components/{p-2403e01d.entry.js.map → p-0ae49cc4.entry.js.map} +0 -0
- /package/dist/mg-components/{p-ad64ab4a.entry.js.map → p-361cc090.entry.js.map} +0 -0
- /package/dist/mg-components/{p-d9731ebc.js.map → p-4049bd40.js.map} +0 -0
- /package/dist/mg-components/{p-1a162791.entry.js.map → p-c4f37d1f.entry.js.map} +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { isValidString } from "@mgdis/stencil-helpers";
|
|
2
|
+
import Quill from "quill";
|
|
3
|
+
/**
|
|
4
|
+
* HTML element type guard
|
|
5
|
+
* @param element - element to test
|
|
6
|
+
* @returns truthy if element is an HTMLElement
|
|
7
|
+
*/
|
|
8
|
+
const isHtmlElement = (element) => Boolean(element.tagName);
|
|
9
|
+
/**
|
|
10
|
+
* Implements the range API properly in Native Shadow
|
|
11
|
+
* @param rootNode - root node
|
|
12
|
+
* @returns selection
|
|
13
|
+
*/
|
|
14
|
+
const getNativeRange = (rootNode) => {
|
|
15
|
+
try {
|
|
16
|
+
if (typeof document.createElement('div').attachShadow({ mode: 'open' }).getSelection === 'function') {
|
|
17
|
+
// In Chromium, the shadow root has a getSelection function which returns the range
|
|
18
|
+
return rootNode.getSelection().getRangeAt(0);
|
|
19
|
+
}
|
|
20
|
+
const selection = window.getSelection();
|
|
21
|
+
// Webkit range retrieval is done with getComposedRanges (see: https://bugs.webkit.org/show_bug.cgi?id=163921)
|
|
22
|
+
if (typeof selection.getComposedRanges === 'function') {
|
|
23
|
+
return selection.getComposedRanges(rootNode)[0];
|
|
24
|
+
}
|
|
25
|
+
// Gecko implements the range API properly in Native Shadow: https://developer.mozilla.org/en-US/docs/Web/API/Selection/getRangeAt
|
|
26
|
+
return selection.getRangeAt(0);
|
|
27
|
+
}
|
|
28
|
+
catch (_a) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Quill overrides to support shadow dom
|
|
34
|
+
* https://github.com/slab/quill/issues/2961#issuecomment-1775999845
|
|
35
|
+
* @param editor - Quill instance
|
|
36
|
+
*/
|
|
37
|
+
const setQuillOverrides = (editor) => {
|
|
38
|
+
const getRootNode = () => editor.root.getRootNode();
|
|
39
|
+
// Original implementation uses document.active element but with an imlplementation in web-component with shadow root we need compare with it.
|
|
40
|
+
editor.selection.hasFocus = () => getRootNode().activeElement === editor.root;
|
|
41
|
+
// Original implementation uses document.getSelection which does not work in Native Shadow.
|
|
42
|
+
// Replace document.getSelection with shadow dom equivalent (different for each browser)
|
|
43
|
+
editor.selection.getNativeRange = () => {
|
|
44
|
+
const nativeRange = getNativeRange(getRootNode());
|
|
45
|
+
return Boolean(nativeRange) ? editor.selection.normalizeNative(nativeRange) : null;
|
|
46
|
+
};
|
|
47
|
+
// Original implementation relies on Selection.addRange to programatically set the range, which does not work in Webkit with Native Shadow. Selection.addRange works fine in Chromium and Gecko.
|
|
48
|
+
editor.selection.setNativeRange = (startContainer, startOffset, endContainer = startContainer, endOffset = startOffset, force = false) => {
|
|
49
|
+
if ([startContainer === null || startContainer === void 0 ? void 0 : startContainer.parentNode, editor.root.parentNode, endContainer === null || endContainer === void 0 ? void 0 : endContainer.parentNode].some(node => node == null)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const selection = window.getSelection();
|
|
53
|
+
if (!editor.selection.hasFocus())
|
|
54
|
+
editor.root.focus();
|
|
55
|
+
const native = (editor.selection.getNativeRange() || {}).native;
|
|
56
|
+
if (!Boolean(native) ||
|
|
57
|
+
force ||
|
|
58
|
+
startContainer !== native.startContainer ||
|
|
59
|
+
startOffset !== native.startOffset ||
|
|
60
|
+
endContainer !== native.endContainer ||
|
|
61
|
+
endOffset !== native.endOffset) {
|
|
62
|
+
if (isHtmlElement(startContainer) && startContainer.tagName === 'BR') {
|
|
63
|
+
startOffset = [].indexOf.call(startContainer.parentNode.childNodes, startContainer);
|
|
64
|
+
startContainer = startContainer.parentNode;
|
|
65
|
+
}
|
|
66
|
+
if (isHtmlElement(endContainer) && endContainer.tagName === 'BR') {
|
|
67
|
+
endOffset = [].indexOf.call(endContainer.parentNode.childNodes, endContainer);
|
|
68
|
+
endContainer = endContainer.parentNode;
|
|
69
|
+
}
|
|
70
|
+
selection.setBaseAndExtent(startContainer, startOffset, endContainer, endOffset);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// Subscribe to selection change separately, because emitter in Quill doesn't catch this event in Shadow DOM
|
|
74
|
+
document.addEventListener('selectionchange', () => {
|
|
75
|
+
editor.selection.update();
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Fixes for handling text selection in Quill when used within the Shadow DOM.
|
|
80
|
+
* - Fixes focus detection
|
|
81
|
+
* - Adapts native range handling to work with the Shadow DOM
|
|
82
|
+
* - Correctly manages text selection across Shadow DOM boundaries
|
|
83
|
+
* - Sets up selection change events
|
|
84
|
+
* @returns Quill instance
|
|
85
|
+
*/
|
|
86
|
+
export const defineEditor = (wrapperElement, { value, modules, readOnly, placeholder, handleTextChange, handleFocus, handleBlur }) => {
|
|
87
|
+
const toolbarOptions = {
|
|
88
|
+
toolbar: [['bold', 'italic', 'underline'], [{ list: 'ordered' }, { list: 'bullet' }], ['link'], ['clean']],
|
|
89
|
+
};
|
|
90
|
+
const editor = new Quill(wrapperElement.querySelector('div'), {
|
|
91
|
+
theme: 'snow',
|
|
92
|
+
modules: modules || toolbarOptions,
|
|
93
|
+
readOnly,
|
|
94
|
+
placeholder,
|
|
95
|
+
});
|
|
96
|
+
if (isValidString(value) && /<[a-z][\s\S]*>/i.test(value)) {
|
|
97
|
+
editor.clipboard.dangerouslyPasteHTML(value);
|
|
98
|
+
}
|
|
99
|
+
else if (isValidString(value)) {
|
|
100
|
+
editor.setText(value);
|
|
101
|
+
}
|
|
102
|
+
const editorContent = wrapperElement.querySelector('.ql-editor');
|
|
103
|
+
editorContent.addEventListener('focus', handleFocus);
|
|
104
|
+
editorContent.addEventListener('blur', handleBlur);
|
|
105
|
+
// Add an event listener for the text-change event
|
|
106
|
+
editor.on('text-change', handleTextChange);
|
|
107
|
+
setQuillOverrides(editor);
|
|
108
|
+
return editor;
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/components/molecules/inputs/mg-input-rich-text-editor/editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAA4B,MAAM,OAAO,CAAC;AAmBjD;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,OAAgB,EAA0B,EAAE,CAAC,OAAO,CAAE,OAAuB,CAAC,OAAO,CAAC,CAAC;AAE9G;;;;GAIG;AACH,MAAM,cAAc,GAAG,CAAC,QAAuC,EAAE,EAAE;IACjE,IAAI,CAAC;QACH,IAAI,OAAQ,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAwB,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;YAC5H,mFAAmF;YACnF,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,SAAS,GAAoB,MAAM,CAAC,YAAY,EAAE,CAAC;QACzD,8GAA8G;QAC9G,IAAI,OAAO,SAAS,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;YACtD,OAAO,SAAS,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,CAAC;QACD,kIAAkI;QAClI,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAAC,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AAE,UAAU,EAAE,EAAE,EAAE;IAClJ,MAAM,cAAc,GAAG;QACrB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;KAC3G,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE;QAC5D,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,OAAO,IAAI,cAAc;QAClC,QAAQ;QACR,WAAW;KACZ,CAAC,CAAC;IAEH,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1D,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;SAAM,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,aAAa,GAAG,cAAc,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IACjE,aAAa,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACrD,aAAa,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAEnD,kDAAkD;IAClD,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;IAE3C,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAE1B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { isValidString } from '@mgdis/stencil-helpers';\nimport Quill, { type QuillOptions } from 'quill';\n\nexport type EditorOptionsType = QuillOptions & {\n value: string;\n handleTextChange: () => void;\n handleFocus: () => void;\n handleBlur: () => void;\n};\n\nexport type EditorType = Quill;\n\ntype ExtendSelection = Selection & { getComposedRanges?: (root: Node) => Range[] };\n\ntype ExtendedShadowRoot = ShadowRoot & { getSelection(): ExtendSelection };\n\ninterface IdefineEditor {\n (wrapperElement: HTMLElement, config: EditorOptionsType): EditorType;\n}\n\n/**\n * HTML element type guard\n * @param element - element to test\n * @returns truthy if element is an HTMLElement\n */\nconst isHtmlElement = (element: unknown): element is HTMLElement => Boolean((element as HTMLElement).tagName);\n\n/**\n * Implements the range API properly in Native Shadow\n * @param rootNode - root node\n * @returns selection\n */\nconst getNativeRange = (rootNode: ExtendedShadowRoot | Document) => {\n try {\n if (typeof (document.createElement('div').attachShadow({ mode: 'open' }) as ExtendedShadowRoot).getSelection === 'function') {\n // In Chromium, the shadow root has a getSelection function which returns the range\n return rootNode.getSelection().getRangeAt(0);\n }\n const selection: ExtendSelection = window.getSelection();\n // Webkit range retrieval is done with getComposedRanges (see: https://bugs.webkit.org/show_bug.cgi?id=163921)\n if (typeof selection.getComposedRanges === 'function') {\n return selection.getComposedRanges(rootNode)[0];\n }\n // Gecko implements the range API properly in Native Shadow: https://developer.mozilla.org/en-US/docs/Web/API/Selection/getRangeAt\n return selection.getRangeAt(0);\n } catch {\n return null;\n }\n};\n\n/**\n * Quill overrides to support shadow dom\n * https://github.com/slab/quill/issues/2961#issuecomment-1775999845\n * @param editor - Quill instance\n */\nconst setQuillOverrides = (editor: EditorType): void => {\n const getRootNode = () => editor.root.getRootNode() as ExtendedShadowRoot;\n\n // Original implementation uses document.active element but with an imlplementation in web-component with shadow root we need compare with it.\n editor.selection.hasFocus = () => getRootNode().activeElement === editor.root;\n\n // Original implementation uses document.getSelection which does not work in Native Shadow.\n // Replace document.getSelection with shadow dom equivalent (different for each browser)\n editor.selection.getNativeRange = () => {\n const nativeRange = getNativeRange(getRootNode());\n return Boolean(nativeRange) ? editor.selection.normalizeNative(nativeRange) : null;\n };\n\n // Original implementation relies on Selection.addRange to programatically set the range, which does not work in Webkit with Native Shadow. Selection.addRange works fine in Chromium and Gecko.\n editor.selection.setNativeRange = (startContainer, startOffset, endContainer = startContainer, endOffset = startOffset, force = false) => {\n if ([startContainer?.parentNode, editor.root.parentNode, endContainer?.parentNode].some(node => node == null)) {\n return;\n }\n\n const selection = window.getSelection();\n\n if (!editor.selection.hasFocus()) editor.root.focus();\n\n const native = (editor.selection.getNativeRange() || {}).native;\n if (\n !Boolean(native) ||\n force ||\n startContainer !== native.startContainer ||\n startOffset !== native.startOffset ||\n endContainer !== native.endContainer ||\n endOffset !== native.endOffset\n ) {\n if (isHtmlElement(startContainer) && startContainer.tagName === 'BR') {\n startOffset = [].indexOf.call(startContainer.parentNode.childNodes, startContainer);\n startContainer = startContainer.parentNode;\n }\n if (isHtmlElement(endContainer) && endContainer.tagName === 'BR') {\n endOffset = [].indexOf.call(endContainer.parentNode.childNodes, endContainer);\n endContainer = endContainer.parentNode;\n }\n\n selection.setBaseAndExtent(startContainer, startOffset, endContainer, endOffset);\n }\n };\n\n // Subscribe to selection change separately, because emitter in Quill doesn't catch this event in Shadow DOM\n document.addEventListener('selectionchange', () => {\n editor.selection.update();\n });\n};\n\n/**\n * Fixes for handling text selection in Quill when used within the Shadow DOM.\n * - Fixes focus detection\n * - Adapts native range handling to work with the Shadow DOM\n * - Correctly manages text selection across Shadow DOM boundaries\n * - Sets up selection change events\n * @returns Quill instance\n */\nexport const defineEditor: IdefineEditor = (wrapperElement, { value, modules, readOnly, placeholder, handleTextChange, handleFocus, handleBlur }) => {\n const toolbarOptions = {\n toolbar: [['bold', 'italic', 'underline'], [{ list: 'ordered' }, { list: 'bullet' }], ['link'], ['clean']],\n };\n const editor = new Quill(wrapperElement.querySelector('div'), {\n theme: 'snow',\n modules: modules || toolbarOptions,\n readOnly,\n placeholder,\n });\n\n if (isValidString(value) && /<[a-z][\\s\\S]*>/i.test(value)) {\n editor.clipboard.dangerouslyPasteHTML(value);\n } else if (isValidString(value)) {\n editor.setText(value);\n }\n\n const editorContent = wrapperElement.querySelector('.ql-editor');\n editorContent.addEventListener('focus', handleFocus);\n editorContent.addEventListener('blur', handleBlur);\n\n // Add an event listener for the text-change event\n editor.on('text-change', handleTextChange);\n\n setQuillOverrides(editor);\n\n return editor;\n};\n"]}
|