@mgdis/mg-components 6.5.0 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/dist/cjs/{index-ede3b3dc.js → index-019dd5c0.js} +2 -2
  2. package/dist/cjs/{index-ede3b3dc.js.map → index-019dd5c0.js.map} +1 -1
  3. package/dist/cjs/index-1a5a1081.js +4 -0
  4. package/dist/cjs/{index.es-a112f649.js → index.es-903492c5.js} +26 -27
  5. package/dist/cjs/index.es-903492c5.js.map +1 -0
  6. package/dist/cjs/loader.cjs.js +1 -1
  7. package/dist/cjs/mg-action-more_36.cjs.entry.js +230 -196
  8. package/dist/cjs/mg-action-more_36.cjs.entry.js.map +1 -1
  9. package/dist/cjs/mg-alert.cjs.entry.js +4 -4
  10. package/dist/cjs/mg-components.cjs.js +1 -1
  11. package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js +16790 -0
  12. package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js.map +1 -0
  13. package/dist/cjs/mg-input.conf-5bbcea79.js +23 -0
  14. package/dist/cjs/mg-input.conf-5bbcea79.js.map +1 -0
  15. package/dist/cjs/mg-loader.cjs.entry.js +3 -3
  16. package/dist/cjs/mg-progress.cjs.entry.js +2 -2
  17. package/dist/collection/assets/icons/index.js +1 -1
  18. package/dist/collection/assets/icons/index.js.map +1 -1
  19. package/dist/collection/collection-manifest.json +1 -0
  20. package/dist/collection/components/atoms/mg-icon/mg-icon.js +1 -1
  21. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.conf.js.map +1 -1
  22. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +3 -3
  23. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
  24. package/dist/collection/components/molecules/inputs/mg-input/mg-input.js +1 -1
  25. package/dist/collection/components/molecules/inputs/mg-input/mg-input.js.map +1 -1
  26. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +1 -1
  27. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
  28. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +1 -1
  29. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js.map +1 -1
  30. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +2 -2
  31. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
  32. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +1 -1
  33. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js.map +1 -1
  34. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +1 -1
  35. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js.map +1 -1
  36. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/index.js +110 -0
  37. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/index.js.map +1 -0
  38. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js +846 -0
  39. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js.map +1 -0
  40. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +1 -1
  41. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js.map +1 -1
  42. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +3 -5
  43. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js.map +1 -1
  44. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +1 -1
  45. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js.map +1 -1
  46. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
  47. package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js +4 -4
  48. package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js.map +1 -1
  49. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.conf.js +1 -1
  50. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.conf.js.map +1 -1
  51. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +16 -17
  52. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js.map +1 -1
  53. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +8 -6
  54. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js.map +1 -1
  55. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +3 -3
  56. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js.map +1 -1
  57. package/dist/collection/components/molecules/mg-alert/mg-alert.js +1 -1
  58. package/dist/collection/components/molecules/mg-details/mg-details.js +1 -1
  59. package/dist/collection/components/molecules/mg-details/mg-details.js.map +1 -1
  60. package/dist/collection/components/molecules/mg-form/mg-form.js +2 -2
  61. package/dist/collection/components/molecules/mg-form/mg-form.js.map +1 -1
  62. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.conf.js +5 -2
  63. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.conf.js.map +1 -1
  64. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +74 -17
  65. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js.map +1 -1
  66. package/dist/collection/components/molecules/mg-loader/mg-loader.js +1 -1
  67. package/dist/collection/components/molecules/mg-message/mg-message.js +2 -2
  68. package/dist/collection/components/molecules/mg-modal/mg-modal.js +2 -2
  69. package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +3 -3
  70. package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -1
  71. package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +1 -1
  72. package/dist/collection/components/molecules/mg-popover/mg-popover.conf.js.map +1 -1
  73. package/dist/collection/components/molecules/mg-popover/mg-popover.js +3 -3
  74. package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
  75. package/dist/collection/components/molecules/mg-progress/mg-progress.js +1 -1
  76. package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +1 -1
  77. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +1 -1
  78. package/dist/collection/types/index.js.map +1 -1
  79. package/dist/collection/utils/behaviors.utils.js +4 -1
  80. package/dist/collection/utils/behaviors.utils.js.map +1 -1
  81. package/dist/collection/utils/floating-ui.utils.js +1 -6
  82. package/dist/collection/utils/floating-ui.utils.js.map +1 -1
  83. package/dist/components/floating-ui.utils.js +1 -6
  84. package/dist/components/floating-ui.utils.js.map +1 -1
  85. package/dist/components/index.es.js +24 -25
  86. package/dist/components/index.es.js.map +1 -1
  87. package/dist/components/mg-action-more.js +2 -2
  88. package/dist/components/mg-action-more.js.map +1 -1
  89. package/dist/components/mg-alert.js +3 -3
  90. package/dist/components/mg-badge2.js +2 -2
  91. package/dist/components/mg-button2.js +2 -2
  92. package/dist/components/mg-card2.js +1 -1
  93. package/dist/components/mg-card2.js.map +1 -1
  94. package/dist/components/mg-details.js +1 -1
  95. package/dist/components/mg-details.js.map +1 -1
  96. package/dist/components/mg-form.js +4 -4
  97. package/dist/components/mg-form.js.map +1 -1
  98. package/dist/components/mg-icon2.js +3 -3
  99. package/dist/components/mg-icon2.js.map +1 -1
  100. package/dist/components/mg-illustrated-message.js +69 -16
  101. package/dist/components/mg-illustrated-message.js.map +1 -1
  102. package/dist/components/mg-input-checkbox.js +4 -4
  103. package/dist/components/mg-input-checkbox.js.map +1 -1
  104. package/dist/components/mg-input-date.js +7 -7
  105. package/dist/components/mg-input-date.js.map +1 -1
  106. package/dist/components/mg-input-numeric.js +9 -9
  107. package/dist/components/mg-input-numeric.js.map +1 -1
  108. package/dist/components/mg-input-password.js +3 -3
  109. package/dist/components/mg-input-password.js.map +1 -1
  110. package/dist/components/mg-input-radio.js +5 -5
  111. package/dist/components/mg-input-radio.js.map +1 -1
  112. package/dist/components/mg-input-rich-text-editor.d.ts +11 -0
  113. package/dist/components/mg-input-rich-text-editor.js +16866 -0
  114. package/dist/components/mg-input-rich-text-editor.js.map +1 -0
  115. package/dist/components/mg-input-select2.js +6 -6
  116. package/dist/components/mg-input-select2.js.map +1 -1
  117. package/dist/components/mg-input-text2.js +7 -9
  118. package/dist/components/mg-input-text2.js.map +1 -1
  119. package/dist/components/mg-input-textarea.js +5 -5
  120. package/dist/components/mg-input-textarea.js.map +1 -1
  121. package/dist/components/mg-input-toggle.js +4 -4
  122. package/dist/components/mg-input2.js +1 -1
  123. package/dist/components/mg-input2.js.map +1 -1
  124. package/dist/components/mg-item-more2.js +17 -15
  125. package/dist/components/mg-item-more2.js.map +1 -1
  126. package/dist/components/mg-loader.js +1 -1
  127. package/dist/components/mg-menu-item2.js +11 -9
  128. package/dist/components/mg-menu-item2.js.map +1 -1
  129. package/dist/components/mg-message2.js +4 -4
  130. package/dist/components/mg-modal.js +4 -4
  131. package/dist/components/mg-pagination2.js +3 -3
  132. package/dist/components/mg-panel.js +3 -3
  133. package/dist/components/mg-popover-content2.js +4 -4
  134. package/dist/components/mg-popover2.js +3 -3
  135. package/dist/components/mg-popover2.js.map +1 -1
  136. package/dist/components/mg-progress.js +1 -1
  137. package/dist/components/mg-skip-links.js +1 -1
  138. package/dist/components/mg-tabs.js +4 -4
  139. package/dist/components/mg-tag.js +2 -2
  140. package/dist/components/mg-tooltip2.js +5 -5
  141. package/dist/components/mg-tooltip2.js.map +1 -1
  142. package/dist/esm/index-5059254f.js +4 -0
  143. package/dist/esm/{index-a7c3b5c5.js → index-6b7bdd63.js} +2 -2
  144. package/dist/esm/{index-a7c3b5c5.js.map → index-6b7bdd63.js.map} +1 -1
  145. package/dist/esm/{index.es-5e0101ac.js → index.es-b80b758c.js} +25 -26
  146. package/dist/esm/index.es-b80b758c.js.map +1 -0
  147. package/dist/esm/loader.js +1 -1
  148. package/dist/esm/mg-action-more_36.entry.js +181 -147
  149. package/dist/esm/mg-action-more_36.entry.js.map +1 -1
  150. package/dist/esm/mg-alert.entry.js +4 -4
  151. package/dist/esm/mg-components.js +1 -1
  152. package/dist/esm/mg-input-rich-text-editor.entry.js +16786 -0
  153. package/dist/esm/mg-input-rich-text-editor.entry.js.map +1 -0
  154. package/dist/esm/mg-input.conf-712c7bb6.js +16 -0
  155. package/dist/esm/mg-input.conf-712c7bb6.js.map +1 -0
  156. package/dist/esm/mg-loader.entry.js +3 -3
  157. package/dist/esm/mg-progress.entry.js +2 -2
  158. package/dist/mg-components/mg-components.esm.js +1 -1
  159. package/dist/mg-components/mg-components.esm.js.map +1 -1
  160. package/dist/mg-components/{p-2403e01d.entry.js → p-0ae49cc4.entry.js} +2 -2
  161. package/dist/mg-components/p-17f0b7eb.entry.js +2 -0
  162. package/dist/mg-components/p-17f0b7eb.entry.js.map +1 -0
  163. package/dist/mg-components/p-1c126a81.entry.js +2 -0
  164. package/dist/mg-components/p-1c126a81.entry.js.map +1 -0
  165. package/dist/mg-components/p-2884f369.js +2 -0
  166. package/dist/mg-components/p-2884f369.js.map +1 -0
  167. package/dist/mg-components/{p-ad64ab4a.entry.js → p-361cc090.entry.js} +2 -2
  168. package/dist/mg-components/p-3c6710be.js +2 -0
  169. package/dist/mg-components/p-3c6710be.js.map +1 -0
  170. package/dist/mg-components/{p-d9731ebc.js → p-4049bd40.js} +2 -2
  171. package/dist/mg-components/{p-1a162791.entry.js → p-c4f37d1f.entry.js} +2 -2
  172. package/dist/types/assets/icons/index.d.ts +1 -0
  173. package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/editor/index.d.ts +21 -0
  174. package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.d.ts +202 -0
  175. package/dist/types/components/molecules/menu/mg-menu/mg-menu.conf.d.ts +2 -6
  176. package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +3 -2
  177. package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +4 -3
  178. package/dist/types/components/molecules/mg-illustrated-message/mg-illustrated-message.conf.d.ts +10 -3
  179. package/dist/types/components/molecules/mg-illustrated-message/mg-illustrated-message.d.ts +17 -3
  180. package/dist/types/components.d.ts +217 -8
  181. package/dist/types/types/index.d.ts +4 -0
  182. package/dist/types/utils/floating-ui.utils.d.ts +1 -1
  183. package/ide/intellij/web-types.json +374 -17
  184. package/ide/vscode/css-custom-data.json +4 -0
  185. package/ide/vscode/html-custom-data.json +289 -4
  186. package/package.json +21 -20
  187. package/dist/cjs/index.es-a112f649.js.map +0 -1
  188. package/dist/esm/index.es-5e0101ac.js.map +0 -1
  189. package/dist/mg-components/p-6c831a83.entry.js +0 -2
  190. package/dist/mg-components/p-6c831a83.entry.js.map +0 -1
  191. package/dist/mg-components/p-b6c1a6ce.js +0 -2
  192. package/dist/mg-components/p-b6c1a6ce.js.map +0 -1
  193. /package/dist/mg-components/{p-2403e01d.entry.js.map → p-0ae49cc4.entry.js.map} +0 -0
  194. /package/dist/mg-components/{p-ad64ab4a.entry.js.map → p-361cc090.entry.js.map} +0 -0
  195. /package/dist/mg-components/{p-d9731ebc.js.map → p-4049bd40.js.map} +0 -0
  196. /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
@@ -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,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ClC,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"]}