@onereach/ui-components 4.0.2 → 4.1.0-beta.2508.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 (106) hide show
  1. package/dist/bundled/v2/components/OrCode/OrCode.js +6 -3727
  2. package/dist/bundled/v2/components/OrCode/index.js +6 -2
  3. package/dist/bundled/v2/components/OrCode/lang.js +3898 -3
  4. package/dist/bundled/v2/components/OrCode/theme.js +3 -1
  5. package/dist/bundled/v2/components/OrRichTextEditorV3/OrRichTextEditor.js +2033 -0
  6. package/dist/bundled/v2/components/OrRichTextEditorV3/OrRichTextEditor.vue.d.ts +181 -0
  7. package/dist/bundled/v2/components/OrRichTextEditorV3/index.d.ts +1 -0
  8. package/dist/bundled/v2/components/OrRichTextEditorV3/index.js +67 -0
  9. package/dist/bundled/v2/components/OrRichTextEditorV3/styles.d.ts +7 -0
  10. package/dist/bundled/v2/components/OrRichTextEditorV3/styles.js +43 -0
  11. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.d.ts +3 -0
  12. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +45 -0
  13. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.d.ts +27 -0
  14. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +183 -0
  15. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/index.d.ts +1 -0
  16. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/index.js +4 -0
  17. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/types.d.ts +19 -0
  18. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/types.js +1 -0
  19. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/markdown.d.ts +3 -0
  20. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/markdown.js +5 -0
  21. package/dist/bundled/v2/components/index.d.ts +1 -0
  22. package/dist/bundled/v2/components/index.js +14 -2
  23. package/dist/bundled/v2/index-62c3221b.js +6956 -0
  24. package/dist/bundled/v2/index-62e39ec2.js +4534 -0
  25. package/dist/bundled/{v3/OrCode.vue_vue_type_script_lang-c5a9adb7.js → v2/index-92e69736.js} +15 -234
  26. package/dist/bundled/v2/{index-6976c52a.js → index-c76372bb.js} +16 -4659
  27. package/dist/bundled/{v3/lang-02d2bb2d.js → v2/index-db5e8c99.js} +74 -3965
  28. package/dist/bundled/v2/index.es-3f39f316.js +115 -0
  29. package/dist/bundled/v2/index.js +17 -5
  30. package/dist/bundled/v2/markdown-00716a39.js +18683 -0
  31. package/dist/bundled/v2/tiptap-core.esm-f85402b1.js +9360 -0
  32. package/dist/bundled/v3/OrCode.vue_vue_type_script_lang-0c5e41b0.js +236 -0
  33. package/dist/bundled/v3/OrRichTextEditor.vue_vue_type_script_lang-33b56bd6.js +1815 -0
  34. package/dist/bundled/v3/components/OrCode/OrCode.js +9 -5
  35. package/dist/bundled/v3/components/OrCode/index.js +7 -3
  36. package/dist/bundled/v3/components/OrCode/lang.js +3898 -3
  37. package/dist/bundled/v3/components/OrCode/theme.js +3 -1
  38. package/dist/bundled/v3/components/OrRichTextEditorV3/OrRichTextEditor.js +219 -0
  39. package/dist/bundled/v3/components/OrRichTextEditorV3/OrRichTextEditor.vue.d.ts +181 -0
  40. package/dist/bundled/v3/components/OrRichTextEditorV3/index.d.ts +1 -0
  41. package/dist/bundled/v3/components/OrRichTextEditorV3/index.js +83 -0
  42. package/dist/bundled/v3/components/OrRichTextEditorV3/styles.d.ts +7 -0
  43. package/dist/bundled/v3/components/OrRichTextEditorV3/styles.js +43 -0
  44. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.d.ts +3 -0
  45. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +45 -0
  46. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.d.ts +27 -0
  47. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +183 -0
  48. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/index.d.ts +1 -0
  49. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/index.js +4 -0
  50. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/types.d.ts +19 -0
  51. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/types.js +1 -0
  52. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/markdown.d.ts +3 -0
  53. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/markdown.js +5 -0
  54. package/dist/bundled/v3/components/index.d.ts +1 -0
  55. package/dist/bundled/v3/components/index.js +16 -3
  56. package/dist/bundled/v3/index-62c3221b.js +6956 -0
  57. package/dist/bundled/v3/index-62e39ec2.js +4534 -0
  58. package/dist/bundled/v3/index-92e69736.js +3741 -0
  59. package/dist/bundled/v3/{index-6976c52a.js → index-c76372bb.js} +16 -4659
  60. package/dist/bundled/{v2/lang-02d2bb2d.js → v3/index-db5e8c99.js} +74 -3965
  61. package/dist/bundled/v3/index.es-3f39f316.js +115 -0
  62. package/dist/bundled/v3/index.js +20 -7
  63. package/dist/bundled/v3/markdown-00716a39.js +18683 -0
  64. package/dist/bundled/v3/tiptap-core.esm-f85402b1.js +9360 -0
  65. package/dist/esm/v2/OrRichTextEditor-45fb1867.js +718 -0
  66. package/dist/esm/v2/codemirrorView-2e87c938.js +184 -0
  67. package/dist/esm/v2/components/index.d.ts +1 -0
  68. package/dist/esm/v2/components/index.js +24 -0
  69. package/dist/esm/v2/components/or-rich-text-editor-v3/OrRichTextEditor.vue.d.ts +181 -0
  70. package/dist/esm/v2/components/or-rich-text-editor-v3/index.d.ts +1 -0
  71. package/dist/esm/v2/components/or-rich-text-editor-v3/index.js +56 -0
  72. package/dist/esm/v2/components/or-rich-text-editor-v3/styles.d.ts +7 -0
  73. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/codemirrorNode.d.ts +3 -0
  74. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/codemirrorView.d.ts +27 -0
  75. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/index.d.ts +1 -0
  76. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/index.js +5 -0
  77. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/types.d.ts +19 -0
  78. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/markdown.d.ts +3 -0
  79. package/dist/esm/v2/index.js +24 -0
  80. package/dist/esm/v3/OrRichTextEditor-4c0b6030.js +680 -0
  81. package/dist/esm/v3/codemirrorView-2e87c938.js +184 -0
  82. package/dist/esm/v3/components/index.d.ts +1 -0
  83. package/dist/esm/v3/components/index.js +24 -0
  84. package/dist/esm/v3/components/or-rich-text-editor-v3/OrRichTextEditor.vue.d.ts +181 -0
  85. package/dist/esm/v3/components/or-rich-text-editor-v3/index.d.ts +1 -0
  86. package/dist/esm/v3/components/or-rich-text-editor-v3/index.js +54 -0
  87. package/dist/esm/v3/components/or-rich-text-editor-v3/styles.d.ts +7 -0
  88. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/codemirrorNode.d.ts +3 -0
  89. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/codemirrorView.d.ts +27 -0
  90. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/index.d.ts +1 -0
  91. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/index.js +5 -0
  92. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/types.d.ts +19 -0
  93. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/markdown.d.ts +3 -0
  94. package/dist/esm/v3/index.js +24 -0
  95. package/package.json +25 -5
  96. package/src/components/index.ts +1 -0
  97. package/src/components/or-rich-text-editor-v3/OrRichTextEditor.docs.mdx +7 -0
  98. package/src/components/or-rich-text-editor-v3/OrRichTextEditor.stories3.ts +79 -0
  99. package/src/components/or-rich-text-editor-v3/OrRichTextEditor.vue +622 -0
  100. package/src/components/or-rich-text-editor-v3/index.ts +1 -0
  101. package/src/components/or-rich-text-editor-v3/styles.ts +72 -0
  102. package/src/components/or-rich-text-editor-v3/utils/codemirror/codemirrorNode.ts +40 -0
  103. package/src/components/or-rich-text-editor-v3/utils/codemirror/codemirrorView.ts +252 -0
  104. package/src/components/or-rich-text-editor-v3/utils/codemirror/index.ts +1 -0
  105. package/src/components/or-rich-text-editor-v3/utils/codemirror/types.ts +22 -0
  106. package/src/components/or-rich-text-editor-v3/utils/markdown.ts +110 -0
@@ -0,0 +1,1815 @@
1
+ import { defineComponent, ref, onMounted, onBeforeUnmount, computed, watch } from 'vue-demi';
2
+ import { onClickOutside } from '@vueuse/core';
3
+ import { B as Blockquote, a as Bold, b as BulletList, C as CodeBlock, H as HardBreak, I as Italic, L as ListItem, O as OrderedList, P as Paragraph, S as Strike, s as serialize, d as deserialize, c as Link, e as Highlight } from './markdown-00716a39.js';
4
+ import { EditorContainer, ToolbarContainer, Toolbar, ToolbarButtonFocused, ToolbarButton, EditorInput, ToolbarButtonActive } from './components/OrRichTextEditorV3/styles.js';
5
+ import { M as Mark, m as mergeAttributes, a as markInputRule, b as markPasteRule, N as Node, E as Extension, k as keydownHandler, D as DecorationSet, c as Decoration, d as callOrReturn, g as getExtensionField, t as textblockTypeInputRule, n as nodeInputRule, e as Editor } from './tiptap-core.esm-f85402b1.js';
6
+ import { P as Plugin, d as dropPoint, S as Selection, N as NodeSelection, F as Fragment, a as Slice, T as TextSelection, b as PluginKey, M as Mapping } from './index-62c3221b.js';
7
+ import codemirrorNode from './components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js';
8
+ import './components/OrIconButtonV3/OrIconButton.js';
9
+ import './components/OrLabelV3/OrLabel.js';
10
+ import './components/OrMenuItemV3/OrMenuItem.js';
11
+ import './components/OrMenuV3/OrMenu.js';
12
+ import './components/OrModalV3/OrModal.js';
13
+ import { s as script$5 } from './OrModal.vue_vue_type_script_lang-9ed0d5c2.js';
14
+ import './components/OrInputV3/OrInput.js';
15
+ import './components/OrButtonV3/OrButton.js';
16
+ import { s as script$1 } from './OrIconButton.vue_vue_type_script_lang-42a8285c.js';
17
+ import { s as script$2 } from './OrLabel.vue_vue_type_script_lang-3e11ab8a.js';
18
+ import { s as script$3 } from './OrMenuItem.vue_vue_type_script_lang-b338d68a.js';
19
+ import { s as script$4 } from './OrMenu.vue_vue_type_script_lang-2676b9cc.js';
20
+ import { s as script$6 } from './OrInput.vue_vue_type_script_lang-60b49ebd.js';
21
+ import { s as script$7 } from './OrButton.vue_vue_type_script_lang-fe412ca5.js';
22
+
23
+ const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/;
24
+ const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/g;
25
+ const Code = Mark.create({
26
+ name: 'code',
27
+ addOptions() {
28
+ return {
29
+ HTMLAttributes: {}
30
+ };
31
+ },
32
+ excludes: '_',
33
+ code: true,
34
+ exitable: true,
35
+ parseHTML() {
36
+ return [{
37
+ tag: 'code'
38
+ }];
39
+ },
40
+ renderHTML({
41
+ HTMLAttributes
42
+ }) {
43
+ return ['code', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
44
+ },
45
+ addCommands() {
46
+ return {
47
+ setCode: () => ({
48
+ commands
49
+ }) => {
50
+ return commands.setMark(this.name);
51
+ },
52
+ toggleCode: () => ({
53
+ commands
54
+ }) => {
55
+ return commands.toggleMark(this.name);
56
+ },
57
+ unsetCode: () => ({
58
+ commands
59
+ }) => {
60
+ return commands.unsetMark(this.name);
61
+ }
62
+ };
63
+ },
64
+ addKeyboardShortcuts() {
65
+ return {
66
+ 'Mod-e': () => this.editor.commands.toggleCode()
67
+ };
68
+ },
69
+ addInputRules() {
70
+ return [markInputRule({
71
+ find: inputRegex,
72
+ type: this.type
73
+ })];
74
+ },
75
+ addPasteRules() {
76
+ return [markPasteRule({
77
+ find: pasteRegex,
78
+ type: this.type
79
+ })];
80
+ }
81
+ });
82
+
83
+ const Document = Node.create({
84
+ name: 'doc',
85
+ topNode: true,
86
+ content: 'block+'
87
+ });
88
+
89
+ /**
90
+ Create a plugin that, when added to a ProseMirror instance,
91
+ causes a decoration to show up at the drop position when something
92
+ is dragged over the editor.
93
+
94
+ Nodes may add a `disableDropCursor` property to their spec to
95
+ control the showing of a drop cursor inside them. This may be a
96
+ boolean or a function, which will be called with a view and a
97
+ position, and should return a boolean.
98
+ */
99
+ function dropCursor(options = {}) {
100
+ return new Plugin({
101
+ view(editorView) {
102
+ return new DropCursorView(editorView, options);
103
+ }
104
+ });
105
+ }
106
+ class DropCursorView {
107
+ constructor(editorView, options) {
108
+ var _a;
109
+ this.editorView = editorView;
110
+ this.cursorPos = null;
111
+ this.element = null;
112
+ this.timeout = -1;
113
+ this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1;
114
+ this.color = options.color === false ? undefined : options.color || "black";
115
+ this.class = options.class;
116
+ this.handlers = ["dragover", "dragend", "drop", "dragleave"].map(name => {
117
+ let handler = e => {
118
+ this[name](e);
119
+ };
120
+ editorView.dom.addEventListener(name, handler);
121
+ return {
122
+ name,
123
+ handler
124
+ };
125
+ });
126
+ }
127
+ destroy() {
128
+ this.handlers.forEach(({
129
+ name,
130
+ handler
131
+ }) => this.editorView.dom.removeEventListener(name, handler));
132
+ }
133
+ update(editorView, prevState) {
134
+ if (this.cursorPos != null && prevState.doc != editorView.state.doc) {
135
+ if (this.cursorPos > editorView.state.doc.content.size) this.setCursor(null);else this.updateOverlay();
136
+ }
137
+ }
138
+ setCursor(pos) {
139
+ if (pos == this.cursorPos) return;
140
+ this.cursorPos = pos;
141
+ if (pos == null) {
142
+ this.element.parentNode.removeChild(this.element);
143
+ this.element = null;
144
+ } else {
145
+ this.updateOverlay();
146
+ }
147
+ }
148
+ updateOverlay() {
149
+ let $pos = this.editorView.state.doc.resolve(this.cursorPos);
150
+ let isBlock = !$pos.parent.inlineContent,
151
+ rect;
152
+ if (isBlock) {
153
+ let before = $pos.nodeBefore,
154
+ after = $pos.nodeAfter;
155
+ if (before || after) {
156
+ let node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0));
157
+ if (node) {
158
+ let nodeRect = node.getBoundingClientRect();
159
+ let top = before ? nodeRect.bottom : nodeRect.top;
160
+ if (before && after) top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2;
161
+ rect = {
162
+ left: nodeRect.left,
163
+ right: nodeRect.right,
164
+ top: top - this.width / 2,
165
+ bottom: top + this.width / 2
166
+ };
167
+ }
168
+ }
169
+ }
170
+ if (!rect) {
171
+ let coords = this.editorView.coordsAtPos(this.cursorPos);
172
+ rect = {
173
+ left: coords.left - this.width / 2,
174
+ right: coords.left + this.width / 2,
175
+ top: coords.top,
176
+ bottom: coords.bottom
177
+ };
178
+ }
179
+ let parent = this.editorView.dom.offsetParent;
180
+ if (!this.element) {
181
+ this.element = parent.appendChild(document.createElement("div"));
182
+ if (this.class) this.element.className = this.class;
183
+ this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;";
184
+ if (this.color) {
185
+ this.element.style.backgroundColor = this.color;
186
+ }
187
+ }
188
+ this.element.classList.toggle("prosemirror-dropcursor-block", isBlock);
189
+ this.element.classList.toggle("prosemirror-dropcursor-inline", !isBlock);
190
+ let parentLeft, parentTop;
191
+ if (!parent || parent == document.body && getComputedStyle(parent).position == "static") {
192
+ parentLeft = -pageXOffset;
193
+ parentTop = -pageYOffset;
194
+ } else {
195
+ let rect = parent.getBoundingClientRect();
196
+ parentLeft = rect.left - parent.scrollLeft;
197
+ parentTop = rect.top - parent.scrollTop;
198
+ }
199
+ this.element.style.left = rect.left - parentLeft + "px";
200
+ this.element.style.top = rect.top - parentTop + "px";
201
+ this.element.style.width = rect.right - rect.left + "px";
202
+ this.element.style.height = rect.bottom - rect.top + "px";
203
+ }
204
+ scheduleRemoval(timeout) {
205
+ clearTimeout(this.timeout);
206
+ this.timeout = setTimeout(() => this.setCursor(null), timeout);
207
+ }
208
+ dragover(event) {
209
+ if (!this.editorView.editable) return;
210
+ let pos = this.editorView.posAtCoords({
211
+ left: event.clientX,
212
+ top: event.clientY
213
+ });
214
+ let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);
215
+ let disableDropCursor = node && node.type.spec.disableDropCursor;
216
+ let disabled = typeof disableDropCursor == "function" ? disableDropCursor(this.editorView, pos, event) : disableDropCursor;
217
+ if (pos && !disabled) {
218
+ let target = pos.pos;
219
+ if (this.editorView.dragging && this.editorView.dragging.slice) {
220
+ let point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);
221
+ if (point != null) target = point;
222
+ }
223
+ this.setCursor(target);
224
+ this.scheduleRemoval(5000);
225
+ }
226
+ }
227
+ dragend() {
228
+ this.scheduleRemoval(20);
229
+ }
230
+ drop() {
231
+ this.scheduleRemoval(20);
232
+ }
233
+ dragleave(event) {
234
+ if (event.target == this.editorView.dom || !this.editorView.dom.contains(event.relatedTarget)) this.setCursor(null);
235
+ }
236
+ }
237
+
238
+ const Dropcursor = Extension.create({
239
+ name: 'dropCursor',
240
+ addOptions() {
241
+ return {
242
+ color: 'currentColor',
243
+ width: 1,
244
+ class: undefined
245
+ };
246
+ },
247
+ addProseMirrorPlugins() {
248
+ return [dropCursor(this.options)];
249
+ }
250
+ });
251
+
252
+ /**
253
+ Gap cursor selections are represented using this class. Its
254
+ `$anchor` and `$head` properties both point at the cursor position.
255
+ */
256
+ class GapCursor extends Selection {
257
+ /**
258
+ Create a gap cursor.
259
+ */
260
+ constructor($pos) {
261
+ super($pos, $pos);
262
+ }
263
+ map(doc, mapping) {
264
+ let $pos = doc.resolve(mapping.map(this.head));
265
+ return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);
266
+ }
267
+ content() {
268
+ return Slice.empty;
269
+ }
270
+ eq(other) {
271
+ return other instanceof GapCursor && other.head == this.head;
272
+ }
273
+ toJSON() {
274
+ return {
275
+ type: "gapcursor",
276
+ pos: this.head
277
+ };
278
+ }
279
+ /**
280
+ @internal
281
+ */
282
+ static fromJSON(doc, json) {
283
+ if (typeof json.pos != "number") throw new RangeError("Invalid input for GapCursor.fromJSON");
284
+ return new GapCursor(doc.resolve(json.pos));
285
+ }
286
+ /**
287
+ @internal
288
+ */
289
+ getBookmark() {
290
+ return new GapBookmark(this.anchor);
291
+ }
292
+ /**
293
+ @internal
294
+ */
295
+ static valid($pos) {
296
+ let parent = $pos.parent;
297
+ if (parent.isTextblock || !closedBefore($pos) || !closedAfter($pos)) return false;
298
+ let override = parent.type.spec.allowGapCursor;
299
+ if (override != null) return override;
300
+ let deflt = parent.contentMatchAt($pos.index()).defaultType;
301
+ return deflt && deflt.isTextblock;
302
+ }
303
+ /**
304
+ @internal
305
+ */
306
+ static findGapCursorFrom($pos, dir, mustMove = false) {
307
+ search: for (;;) {
308
+ if (!mustMove && GapCursor.valid($pos)) return $pos;
309
+ let pos = $pos.pos,
310
+ next = null;
311
+ // Scan up from this position
312
+ for (let d = $pos.depth;; d--) {
313
+ let parent = $pos.node(d);
314
+ if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) {
315
+ next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1);
316
+ break;
317
+ } else if (d == 0) {
318
+ return null;
319
+ }
320
+ pos += dir;
321
+ let $cur = $pos.doc.resolve(pos);
322
+ if (GapCursor.valid($cur)) return $cur;
323
+ }
324
+ // And then down into the next node
325
+ for (;;) {
326
+ let inside = dir > 0 ? next.firstChild : next.lastChild;
327
+ if (!inside) {
328
+ if (next.isAtom && !next.isText && !NodeSelection.isSelectable(next)) {
329
+ $pos = $pos.doc.resolve(pos + next.nodeSize * dir);
330
+ mustMove = false;
331
+ continue search;
332
+ }
333
+ break;
334
+ }
335
+ next = inside;
336
+ pos += dir;
337
+ let $cur = $pos.doc.resolve(pos);
338
+ if (GapCursor.valid($cur)) return $cur;
339
+ }
340
+ return null;
341
+ }
342
+ }
343
+ }
344
+ GapCursor.prototype.visible = false;
345
+ GapCursor.findFrom = GapCursor.findGapCursorFrom;
346
+ Selection.jsonID("gapcursor", GapCursor);
347
+ class GapBookmark {
348
+ constructor(pos) {
349
+ this.pos = pos;
350
+ }
351
+ map(mapping) {
352
+ return new GapBookmark(mapping.map(this.pos));
353
+ }
354
+ resolve(doc) {
355
+ let $pos = doc.resolve(this.pos);
356
+ return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);
357
+ }
358
+ }
359
+ function closedBefore($pos) {
360
+ for (let d = $pos.depth; d >= 0; d--) {
361
+ let index = $pos.index(d),
362
+ parent = $pos.node(d);
363
+ // At the start of this parent, look at next one
364
+ if (index == 0) {
365
+ if (parent.type.spec.isolating) return true;
366
+ continue;
367
+ }
368
+ // See if the node before (or its first ancestor) is closed
369
+ for (let before = parent.child(index - 1);; before = before.lastChild) {
370
+ if (before.childCount == 0 && !before.inlineContent || before.isAtom || before.type.spec.isolating) return true;
371
+ if (before.inlineContent) return false;
372
+ }
373
+ }
374
+ // Hit start of document
375
+ return true;
376
+ }
377
+ function closedAfter($pos) {
378
+ for (let d = $pos.depth; d >= 0; d--) {
379
+ let index = $pos.indexAfter(d),
380
+ parent = $pos.node(d);
381
+ if (index == parent.childCount) {
382
+ if (parent.type.spec.isolating) return true;
383
+ continue;
384
+ }
385
+ for (let after = parent.child(index);; after = after.firstChild) {
386
+ if (after.childCount == 0 && !after.inlineContent || after.isAtom || after.type.spec.isolating) return true;
387
+ if (after.inlineContent) return false;
388
+ }
389
+ }
390
+ return true;
391
+ }
392
+
393
+ /**
394
+ Create a gap cursor plugin. When enabled, this will capture clicks
395
+ near and arrow-key-motion past places that don't have a normally
396
+ selectable position nearby, and create a gap cursor selection for
397
+ them. The cursor is drawn as an element with class
398
+ `ProseMirror-gapcursor`. You can either include
399
+ `style/gapcursor.css` from the package's directory or add your own
400
+ styles to make it visible.
401
+ */
402
+ function gapCursor() {
403
+ return new Plugin({
404
+ props: {
405
+ decorations: drawGapCursor,
406
+ createSelectionBetween(_view, $anchor, $head) {
407
+ return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null;
408
+ },
409
+ handleClick,
410
+ handleKeyDown,
411
+ handleDOMEvents: {
412
+ beforeinput: beforeinput
413
+ }
414
+ }
415
+ });
416
+ }
417
+ const handleKeyDown = keydownHandler({
418
+ "ArrowLeft": arrow("horiz", -1),
419
+ "ArrowRight": arrow("horiz", 1),
420
+ "ArrowUp": arrow("vert", -1),
421
+ "ArrowDown": arrow("vert", 1)
422
+ });
423
+ function arrow(axis, dir) {
424
+ const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
425
+ return function (state, dispatch, view) {
426
+ let sel = state.selection;
427
+ let $start = dir > 0 ? sel.$to : sel.$from,
428
+ mustMove = sel.empty;
429
+ if (sel instanceof TextSelection) {
430
+ if (!view.endOfTextblock(dirStr) || $start.depth == 0) return false;
431
+ mustMove = false;
432
+ $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before());
433
+ }
434
+ let $found = GapCursor.findGapCursorFrom($start, dir, mustMove);
435
+ if (!$found) return false;
436
+ if (dispatch) dispatch(state.tr.setSelection(new GapCursor($found)));
437
+ return true;
438
+ };
439
+ }
440
+ function handleClick(view, pos, event) {
441
+ if (!view || !view.editable) return false;
442
+ let $pos = view.state.doc.resolve(pos);
443
+ if (!GapCursor.valid($pos)) return false;
444
+ let clickPos = view.posAtCoords({
445
+ left: event.clientX,
446
+ top: event.clientY
447
+ });
448
+ if (clickPos && clickPos.inside > -1 && NodeSelection.isSelectable(view.state.doc.nodeAt(clickPos.inside))) return false;
449
+ view.dispatch(view.state.tr.setSelection(new GapCursor($pos)));
450
+ return true;
451
+ }
452
+ // This is a hack that, when a composition starts while a gap cursor
453
+ // is active, quickly creates an inline context for the composition to
454
+ // happen in, to avoid it being aborted by the DOM selection being
455
+ // moved into a valid position.
456
+ function beforeinput(view, event) {
457
+ if (event.inputType != "insertCompositionText" || !(view.state.selection instanceof GapCursor)) return false;
458
+ let {
459
+ $from
460
+ } = view.state.selection;
461
+ let insert = $from.parent.contentMatchAt($from.index()).findWrapping(view.state.schema.nodes.text);
462
+ if (!insert) return false;
463
+ let frag = Fragment.empty;
464
+ for (let i = insert.length - 1; i >= 0; i--) frag = Fragment.from(insert[i].createAndFill(null, frag));
465
+ let tr = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0));
466
+ tr.setSelection(TextSelection.near(tr.doc.resolve($from.pos + 1)));
467
+ view.dispatch(tr);
468
+ return false;
469
+ }
470
+ function drawGapCursor(state) {
471
+ if (!(state.selection instanceof GapCursor)) return null;
472
+ let node = document.createElement("div");
473
+ node.className = "ProseMirror-gapcursor";
474
+ return DecorationSet.create(state.doc, [Decoration.widget(state.selection.head, node, {
475
+ key: "gapcursor"
476
+ })]);
477
+ }
478
+
479
+ const Gapcursor = Extension.create({
480
+ name: 'gapCursor',
481
+ addProseMirrorPlugins() {
482
+ return [gapCursor()];
483
+ },
484
+ extendNodeSchema(extension) {
485
+ var _a;
486
+ const context = {
487
+ name: extension.name,
488
+ options: extension.options,
489
+ storage: extension.storage
490
+ };
491
+ return {
492
+ allowGapCursor: (_a = callOrReturn(getExtensionField(extension, 'allowGapCursor', context))) !== null && _a !== void 0 ? _a : null
493
+ };
494
+ }
495
+ });
496
+
497
+ const Heading = Node.create({
498
+ name: 'heading',
499
+ addOptions() {
500
+ return {
501
+ levels: [1, 2, 3, 4, 5, 6],
502
+ HTMLAttributes: {}
503
+ };
504
+ },
505
+ content: 'inline*',
506
+ group: 'block',
507
+ defining: true,
508
+ addAttributes() {
509
+ return {
510
+ level: {
511
+ default: 1,
512
+ rendered: false
513
+ }
514
+ };
515
+ },
516
+ parseHTML() {
517
+ return this.options.levels.map(level => ({
518
+ tag: `h${level}`,
519
+ attrs: {
520
+ level
521
+ }
522
+ }));
523
+ },
524
+ renderHTML({
525
+ node,
526
+ HTMLAttributes
527
+ }) {
528
+ const hasLevel = this.options.levels.includes(node.attrs.level);
529
+ const level = hasLevel ? node.attrs.level : this.options.levels[0];
530
+ return [`h${level}`, mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
531
+ },
532
+ addCommands() {
533
+ return {
534
+ setHeading: attributes => ({
535
+ commands
536
+ }) => {
537
+ if (!this.options.levels.includes(attributes.level)) {
538
+ return false;
539
+ }
540
+ return commands.setNode(this.name, attributes);
541
+ },
542
+ toggleHeading: attributes => ({
543
+ commands
544
+ }) => {
545
+ if (!this.options.levels.includes(attributes.level)) {
546
+ return false;
547
+ }
548
+ return commands.toggleNode(this.name, 'paragraph', attributes);
549
+ }
550
+ };
551
+ },
552
+ addKeyboardShortcuts() {
553
+ return this.options.levels.reduce((items, level) => ({
554
+ ...items,
555
+ ...{
556
+ [`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({
557
+ level
558
+ })
559
+ }
560
+ }), {});
561
+ },
562
+ addInputRules() {
563
+ return this.options.levels.map(level => {
564
+ return textblockTypeInputRule({
565
+ find: new RegExp(`^(#{1,${level}})\\s$`),
566
+ type: this.type,
567
+ getAttributes: {
568
+ level
569
+ }
570
+ });
571
+ });
572
+ }
573
+ });
574
+
575
+ var GOOD_LEAF_SIZE = 200;
576
+
577
+ // :: class<T> A rope sequence is a persistent sequence data structure
578
+ // that supports appending, prepending, and slicing without doing a
579
+ // full copy. It is represented as a mostly-balanced tree.
580
+ var RopeSequence = function RopeSequence() {};
581
+ RopeSequence.prototype.append = function append(other) {
582
+ if (!other.length) {
583
+ return this;
584
+ }
585
+ other = RopeSequence.from(other);
586
+ return !this.length && other || other.length < GOOD_LEAF_SIZE && this.leafAppend(other) || this.length < GOOD_LEAF_SIZE && other.leafPrepend(this) || this.appendInner(other);
587
+ };
588
+
589
+ // :: (union<[T], RopeSequence<T>>) → RopeSequence<T>
590
+ // Prepend an array or other rope to this one, returning a new rope.
591
+ RopeSequence.prototype.prepend = function prepend(other) {
592
+ if (!other.length) {
593
+ return this;
594
+ }
595
+ return RopeSequence.from(other).append(this);
596
+ };
597
+ RopeSequence.prototype.appendInner = function appendInner(other) {
598
+ return new Append(this, other);
599
+ };
600
+
601
+ // :: (?number, ?number) → RopeSequence<T>
602
+ // Create a rope repesenting a sub-sequence of this rope.
603
+ RopeSequence.prototype.slice = function slice(from, to) {
604
+ if (from === void 0) from = 0;
605
+ if (to === void 0) to = this.length;
606
+ if (from >= to) {
607
+ return RopeSequence.empty;
608
+ }
609
+ return this.sliceInner(Math.max(0, from), Math.min(this.length, to));
610
+ };
611
+
612
+ // :: (number) → T
613
+ // Retrieve the element at the given position from this rope.
614
+ RopeSequence.prototype.get = function get(i) {
615
+ if (i < 0 || i >= this.length) {
616
+ return undefined;
617
+ }
618
+ return this.getInner(i);
619
+ };
620
+
621
+ // :: ((element: T, index: number) → ?bool, ?number, ?number)
622
+ // Call the given function for each element between the given
623
+ // indices. This tends to be more efficient than looping over the
624
+ // indices and calling `get`, because it doesn't have to descend the
625
+ // tree for every element.
626
+ RopeSequence.prototype.forEach = function forEach(f, from, to) {
627
+ if (from === void 0) from = 0;
628
+ if (to === void 0) to = this.length;
629
+ if (from <= to) {
630
+ this.forEachInner(f, from, to, 0);
631
+ } else {
632
+ this.forEachInvertedInner(f, from, to, 0);
633
+ }
634
+ };
635
+
636
+ // :: ((element: T, index: number) → U, ?number, ?number) → [U]
637
+ // Map the given functions over the elements of the rope, producing
638
+ // a flat array.
639
+ RopeSequence.prototype.map = function map(f, from, to) {
640
+ if (from === void 0) from = 0;
641
+ if (to === void 0) to = this.length;
642
+ var result = [];
643
+ this.forEach(function (elt, i) {
644
+ return result.push(f(elt, i));
645
+ }, from, to);
646
+ return result;
647
+ };
648
+
649
+ // :: (?union<[T], RopeSequence<T>>) → RopeSequence<T>
650
+ // Create a rope representing the given array, or return the rope
651
+ // itself if a rope was given.
652
+ RopeSequence.from = function from(values) {
653
+ if (values instanceof RopeSequence) {
654
+ return values;
655
+ }
656
+ return values && values.length ? new Leaf(values) : RopeSequence.empty;
657
+ };
658
+ var Leaf = /*@__PURE__*/function (RopeSequence) {
659
+ function Leaf(values) {
660
+ RopeSequence.call(this);
661
+ this.values = values;
662
+ }
663
+ if (RopeSequence) Leaf.__proto__ = RopeSequence;
664
+ Leaf.prototype = Object.create(RopeSequence && RopeSequence.prototype);
665
+ Leaf.prototype.constructor = Leaf;
666
+ var prototypeAccessors = {
667
+ length: {
668
+ configurable: true
669
+ },
670
+ depth: {
671
+ configurable: true
672
+ }
673
+ };
674
+ Leaf.prototype.flatten = function flatten() {
675
+ return this.values;
676
+ };
677
+ Leaf.prototype.sliceInner = function sliceInner(from, to) {
678
+ if (from == 0 && to == this.length) {
679
+ return this;
680
+ }
681
+ return new Leaf(this.values.slice(from, to));
682
+ };
683
+ Leaf.prototype.getInner = function getInner(i) {
684
+ return this.values[i];
685
+ };
686
+ Leaf.prototype.forEachInner = function forEachInner(f, from, to, start) {
687
+ for (var i = from; i < to; i++) {
688
+ if (f(this.values[i], start + i) === false) {
689
+ return false;
690
+ }
691
+ }
692
+ };
693
+ Leaf.prototype.forEachInvertedInner = function forEachInvertedInner(f, from, to, start) {
694
+ for (var i = from - 1; i >= to; i--) {
695
+ if (f(this.values[i], start + i) === false) {
696
+ return false;
697
+ }
698
+ }
699
+ };
700
+ Leaf.prototype.leafAppend = function leafAppend(other) {
701
+ if (this.length + other.length <= GOOD_LEAF_SIZE) {
702
+ return new Leaf(this.values.concat(other.flatten()));
703
+ }
704
+ };
705
+ Leaf.prototype.leafPrepend = function leafPrepend(other) {
706
+ if (this.length + other.length <= GOOD_LEAF_SIZE) {
707
+ return new Leaf(other.flatten().concat(this.values));
708
+ }
709
+ };
710
+ prototypeAccessors.length.get = function () {
711
+ return this.values.length;
712
+ };
713
+ prototypeAccessors.depth.get = function () {
714
+ return 0;
715
+ };
716
+ Object.defineProperties(Leaf.prototype, prototypeAccessors);
717
+ return Leaf;
718
+ }(RopeSequence);
719
+
720
+ // :: RopeSequence
721
+ // The empty rope sequence.
722
+ RopeSequence.empty = new Leaf([]);
723
+ var Append = /*@__PURE__*/function (RopeSequence) {
724
+ function Append(left, right) {
725
+ RopeSequence.call(this);
726
+ this.left = left;
727
+ this.right = right;
728
+ this.length = left.length + right.length;
729
+ this.depth = Math.max(left.depth, right.depth) + 1;
730
+ }
731
+ if (RopeSequence) Append.__proto__ = RopeSequence;
732
+ Append.prototype = Object.create(RopeSequence && RopeSequence.prototype);
733
+ Append.prototype.constructor = Append;
734
+ Append.prototype.flatten = function flatten() {
735
+ return this.left.flatten().concat(this.right.flatten());
736
+ };
737
+ Append.prototype.getInner = function getInner(i) {
738
+ return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length);
739
+ };
740
+ Append.prototype.forEachInner = function forEachInner(f, from, to, start) {
741
+ var leftLen = this.left.length;
742
+ if (from < leftLen && this.left.forEachInner(f, from, Math.min(to, leftLen), start) === false) {
743
+ return false;
744
+ }
745
+ if (to > leftLen && this.right.forEachInner(f, Math.max(from - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) {
746
+ return false;
747
+ }
748
+ };
749
+ Append.prototype.forEachInvertedInner = function forEachInvertedInner(f, from, to, start) {
750
+ var leftLen = this.left.length;
751
+ if (from > leftLen && this.right.forEachInvertedInner(f, from - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) {
752
+ return false;
753
+ }
754
+ if (to < leftLen && this.left.forEachInvertedInner(f, Math.min(from, leftLen), to, start) === false) {
755
+ return false;
756
+ }
757
+ };
758
+ Append.prototype.sliceInner = function sliceInner(from, to) {
759
+ if (from == 0 && to == this.length) {
760
+ return this;
761
+ }
762
+ var leftLen = this.left.length;
763
+ if (to <= leftLen) {
764
+ return this.left.slice(from, to);
765
+ }
766
+ if (from >= leftLen) {
767
+ return this.right.slice(from - leftLen, to - leftLen);
768
+ }
769
+ return this.left.slice(from, leftLen).append(this.right.slice(0, to - leftLen));
770
+ };
771
+ Append.prototype.leafAppend = function leafAppend(other) {
772
+ var inner = this.right.leafAppend(other);
773
+ if (inner) {
774
+ return new Append(this.left, inner);
775
+ }
776
+ };
777
+ Append.prototype.leafPrepend = function leafPrepend(other) {
778
+ var inner = this.left.leafPrepend(other);
779
+ if (inner) {
780
+ return new Append(inner, this.right);
781
+ }
782
+ };
783
+ Append.prototype.appendInner = function appendInner(other) {
784
+ if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) {
785
+ return new Append(this.left, new Append(this.right, other));
786
+ }
787
+ return new Append(this, other);
788
+ };
789
+ return Append;
790
+ }(RopeSequence);
791
+ var ropeSequence = RopeSequence;
792
+
793
+ // ProseMirror's history isn't simply a way to roll back to a previous
794
+ // state, because ProseMirror supports applying changes without adding
795
+ // them to the history (for example during collaboration).
796
+ //
797
+ // To this end, each 'Branch' (one for the undo history and one for
798
+ // the redo history) keeps an array of 'Items', which can optionally
799
+ // hold a step (an actual undoable change), and always hold a position
800
+ // map (which is needed to move changes below them to apply to the
801
+ // current document).
802
+ //
803
+ // An item that has both a step and a selection bookmark is the start
804
+ // of an 'event' — a group of changes that will be undone or redone at
805
+ // once. (It stores only the bookmark, since that way we don't have to
806
+ // provide a document until the selection is actually applied, which
807
+ // is useful when compressing.)
808
+ // Used to schedule history compression
809
+ const max_empty_items = 500;
810
+ class Branch {
811
+ constructor(items, eventCount) {
812
+ this.items = items;
813
+ this.eventCount = eventCount;
814
+ }
815
+ // Pop the latest event off the branch's history and apply it
816
+ // to a document transform.
817
+ popEvent(state, preserveItems) {
818
+ if (this.eventCount == 0) return null;
819
+ let end = this.items.length;
820
+ for (;; end--) {
821
+ let next = this.items.get(end - 1);
822
+ if (next.selection) {
823
+ --end;
824
+ break;
825
+ }
826
+ }
827
+ let remap, mapFrom;
828
+ if (preserveItems) {
829
+ remap = this.remapping(end, this.items.length);
830
+ mapFrom = remap.maps.length;
831
+ }
832
+ let transform = state.tr;
833
+ let selection, remaining;
834
+ let addAfter = [],
835
+ addBefore = [];
836
+ this.items.forEach((item, i) => {
837
+ if (!item.step) {
838
+ if (!remap) {
839
+ remap = this.remapping(end, i + 1);
840
+ mapFrom = remap.maps.length;
841
+ }
842
+ mapFrom--;
843
+ addBefore.push(item);
844
+ return;
845
+ }
846
+ if (remap) {
847
+ addBefore.push(new Item(item.map));
848
+ let step = item.step.map(remap.slice(mapFrom)),
849
+ map;
850
+ if (step && transform.maybeStep(step).doc) {
851
+ map = transform.mapping.maps[transform.mapping.maps.length - 1];
852
+ addAfter.push(new Item(map, undefined, undefined, addAfter.length + addBefore.length));
853
+ }
854
+ mapFrom--;
855
+ if (map) remap.appendMap(map, mapFrom);
856
+ } else {
857
+ transform.maybeStep(item.step);
858
+ }
859
+ if (item.selection) {
860
+ selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection;
861
+ remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1);
862
+ return false;
863
+ }
864
+ }, this.items.length, 0);
865
+ return {
866
+ remaining: remaining,
867
+ transform,
868
+ selection: selection
869
+ };
870
+ }
871
+ // Create a new branch with the given transform added.
872
+ addTransform(transform, selection, histOptions, preserveItems) {
873
+ let newItems = [],
874
+ eventCount = this.eventCount;
875
+ let oldItems = this.items,
876
+ lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;
877
+ for (let i = 0; i < transform.steps.length; i++) {
878
+ let step = transform.steps[i].invert(transform.docs[i]);
879
+ let item = new Item(transform.mapping.maps[i], step, selection),
880
+ merged;
881
+ if (merged = lastItem && lastItem.merge(item)) {
882
+ item = merged;
883
+ if (i) newItems.pop();else oldItems = oldItems.slice(0, oldItems.length - 1);
884
+ }
885
+ newItems.push(item);
886
+ if (selection) {
887
+ eventCount++;
888
+ selection = undefined;
889
+ }
890
+ if (!preserveItems) lastItem = item;
891
+ }
892
+ let overflow = eventCount - histOptions.depth;
893
+ if (overflow > DEPTH_OVERFLOW) {
894
+ oldItems = cutOffEvents(oldItems, overflow);
895
+ eventCount -= overflow;
896
+ }
897
+ return new Branch(oldItems.append(newItems), eventCount);
898
+ }
899
+ remapping(from, to) {
900
+ let maps = new Mapping();
901
+ this.items.forEach((item, i) => {
902
+ let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from ? maps.maps.length - item.mirrorOffset : undefined;
903
+ maps.appendMap(item.map, mirrorPos);
904
+ }, from, to);
905
+ return maps;
906
+ }
907
+ addMaps(array) {
908
+ if (this.eventCount == 0) return this;
909
+ return new Branch(this.items.append(array.map(map => new Item(map))), this.eventCount);
910
+ }
911
+ // When the collab module receives remote changes, the history has
912
+ // to know about those, so that it can adjust the steps that were
913
+ // rebased on top of the remote changes, and include the position
914
+ // maps for the remote changes in its array of items.
915
+ rebased(rebasedTransform, rebasedCount) {
916
+ if (!this.eventCount) return this;
917
+ let rebasedItems = [],
918
+ start = Math.max(0, this.items.length - rebasedCount);
919
+ let mapping = rebasedTransform.mapping;
920
+ let newUntil = rebasedTransform.steps.length;
921
+ let eventCount = this.eventCount;
922
+ this.items.forEach(item => {
923
+ if (item.selection) eventCount--;
924
+ }, start);
925
+ let iRebased = rebasedCount;
926
+ this.items.forEach(item => {
927
+ let pos = mapping.getMirror(--iRebased);
928
+ if (pos == null) return;
929
+ newUntil = Math.min(newUntil, pos);
930
+ let map = mapping.maps[pos];
931
+ if (item.step) {
932
+ let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]);
933
+ let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos));
934
+ if (selection) eventCount++;
935
+ rebasedItems.push(new Item(map, step, selection));
936
+ } else {
937
+ rebasedItems.push(new Item(map));
938
+ }
939
+ }, start);
940
+ let newMaps = [];
941
+ for (let i = rebasedCount; i < newUntil; i++) newMaps.push(new Item(mapping.maps[i]));
942
+ let items = this.items.slice(0, start).append(newMaps).append(rebasedItems);
943
+ let branch = new Branch(items, eventCount);
944
+ if (branch.emptyItemCount() > max_empty_items) branch = branch.compress(this.items.length - rebasedItems.length);
945
+ return branch;
946
+ }
947
+ emptyItemCount() {
948
+ let count = 0;
949
+ this.items.forEach(item => {
950
+ if (!item.step) count++;
951
+ });
952
+ return count;
953
+ }
954
+ // Compressing a branch means rewriting it to push the air (map-only
955
+ // items) out. During collaboration, these naturally accumulate
956
+ // because each remote change adds one. The `upto` argument is used
957
+ // to ensure that only the items below a given level are compressed,
958
+ // because `rebased` relies on a clean, untouched set of items in
959
+ // order to associate old items with rebased steps.
960
+ compress(upto = this.items.length) {
961
+ let remap = this.remapping(0, upto),
962
+ mapFrom = remap.maps.length;
963
+ let items = [],
964
+ events = 0;
965
+ this.items.forEach((item, i) => {
966
+ if (i >= upto) {
967
+ items.push(item);
968
+ if (item.selection) events++;
969
+ } else if (item.step) {
970
+ let step = item.step.map(remap.slice(mapFrom)),
971
+ map = step && step.getMap();
972
+ mapFrom--;
973
+ if (map) remap.appendMap(map, mapFrom);
974
+ if (step) {
975
+ let selection = item.selection && item.selection.map(remap.slice(mapFrom));
976
+ if (selection) events++;
977
+ let newItem = new Item(map.invert(), step, selection),
978
+ merged,
979
+ last = items.length - 1;
980
+ if (merged = items.length && items[last].merge(newItem)) items[last] = merged;else items.push(newItem);
981
+ }
982
+ } else if (item.map) {
983
+ mapFrom--;
984
+ }
985
+ }, this.items.length, 0);
986
+ return new Branch(ropeSequence.from(items.reverse()), events);
987
+ }
988
+ }
989
+ Branch.empty = new Branch(ropeSequence.empty, 0);
990
+ function cutOffEvents(items, n) {
991
+ let cutPoint;
992
+ items.forEach((item, i) => {
993
+ if (item.selection && n-- == 0) {
994
+ cutPoint = i;
995
+ return false;
996
+ }
997
+ });
998
+ return items.slice(cutPoint);
999
+ }
1000
+ class Item {
1001
+ constructor(
1002
+ // The (forward) step map for this item.
1003
+ map,
1004
+ // The inverted step
1005
+ step,
1006
+ // If this is non-null, this item is the start of a group, and
1007
+ // this selection is the starting selection for the group (the one
1008
+ // that was active before the first step was applied)
1009
+ selection,
1010
+ // If this item is the inverse of a previous mapping on the stack,
1011
+ // this points at the inverse's offset
1012
+ mirrorOffset) {
1013
+ this.map = map;
1014
+ this.step = step;
1015
+ this.selection = selection;
1016
+ this.mirrorOffset = mirrorOffset;
1017
+ }
1018
+ merge(other) {
1019
+ if (this.step && other.step && !other.selection) {
1020
+ let step = other.step.merge(this.step);
1021
+ if (step) return new Item(step.getMap().invert(), step, this.selection);
1022
+ }
1023
+ }
1024
+ }
1025
+ // The value of the state field that tracks undo/redo history for that
1026
+ // state. Will be stored in the plugin state when the history plugin
1027
+ // is active.
1028
+ class HistoryState {
1029
+ constructor(done, undone, prevRanges, prevTime) {
1030
+ this.done = done;
1031
+ this.undone = undone;
1032
+ this.prevRanges = prevRanges;
1033
+ this.prevTime = prevTime;
1034
+ }
1035
+ }
1036
+ const DEPTH_OVERFLOW = 20;
1037
+ // Record a transformation in undo history.
1038
+ function applyTransaction(history, state, tr, options) {
1039
+ let historyTr = tr.getMeta(historyKey),
1040
+ rebased;
1041
+ if (historyTr) return historyTr.historyState;
1042
+ if (tr.getMeta(closeHistoryKey)) history = new HistoryState(history.done, history.undone, null, 0);
1043
+ let appended = tr.getMeta("appendedTransaction");
1044
+ if (tr.steps.length == 0) {
1045
+ return history;
1046
+ } else if (appended && appended.getMeta(historyKey)) {
1047
+ if (appended.getMeta(historyKey).redo) return new HistoryState(history.done.addTransform(tr, undefined, options, mustPreserveItems(state)), history.undone, rangesFor(tr.mapping.maps[tr.steps.length - 1]), history.prevTime);else return new HistoryState(history.done, history.undone.addTransform(tr, undefined, options, mustPreserveItems(state)), null, history.prevTime);
1048
+ } else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
1049
+ // Group transforms that occur in quick succession into one event.
1050
+ let newGroup = history.prevTime == 0 || !appended && (history.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history.prevRanges));
1051
+ let prevRanges = appended ? mapRanges(history.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps[tr.steps.length - 1]);
1052
+ return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : undefined, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time);
1053
+ } else if (rebased = tr.getMeta("rebased")) {
1054
+ // Used by the collab module to tell the history that some of its
1055
+ // content has been rebased.
1056
+ return new HistoryState(history.done.rebased(tr, rebased), history.undone.rebased(tr, rebased), mapRanges(history.prevRanges, tr.mapping), history.prevTime);
1057
+ } else {
1058
+ return new HistoryState(history.done.addMaps(tr.mapping.maps), history.undone.addMaps(tr.mapping.maps), mapRanges(history.prevRanges, tr.mapping), history.prevTime);
1059
+ }
1060
+ }
1061
+ function isAdjacentTo(transform, prevRanges) {
1062
+ if (!prevRanges) return false;
1063
+ if (!transform.docChanged) return true;
1064
+ let adjacent = false;
1065
+ transform.mapping.maps[0].forEach((start, end) => {
1066
+ for (let i = 0; i < prevRanges.length; i += 2) if (start <= prevRanges[i + 1] && end >= prevRanges[i]) adjacent = true;
1067
+ });
1068
+ return adjacent;
1069
+ }
1070
+ function rangesFor(map) {
1071
+ let result = [];
1072
+ map.forEach((_from, _to, from, to) => result.push(from, to));
1073
+ return result;
1074
+ }
1075
+ function mapRanges(ranges, mapping) {
1076
+ if (!ranges) return null;
1077
+ let result = [];
1078
+ for (let i = 0; i < ranges.length; i += 2) {
1079
+ let from = mapping.map(ranges[i], 1),
1080
+ to = mapping.map(ranges[i + 1], -1);
1081
+ if (from <= to) result.push(from, to);
1082
+ }
1083
+ return result;
1084
+ }
1085
+ // Apply the latest event from one branch to the document and shift the event
1086
+ // onto the other branch.
1087
+ function histTransaction(history, state, dispatch, redo) {
1088
+ let preserveItems = mustPreserveItems(state);
1089
+ let histOptions = historyKey.get(state).spec.config;
1090
+ let pop = (redo ? history.undone : history.done).popEvent(state, preserveItems);
1091
+ if (!pop) return;
1092
+ let selection = pop.selection.resolve(pop.transform.doc);
1093
+ let added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems);
1094
+ let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0);
1095
+ dispatch(pop.transform.setSelection(selection).setMeta(historyKey, {
1096
+ redo,
1097
+ historyState: newHist
1098
+ }).scrollIntoView());
1099
+ }
1100
+ let cachedPreserveItems = false,
1101
+ cachedPreserveItemsPlugins = null;
1102
+ // Check whether any plugin in the given state has a
1103
+ // `historyPreserveItems` property in its spec, in which case we must
1104
+ // preserve steps exactly as they came in, so that they can be
1105
+ // rebased.
1106
+ function mustPreserveItems(state) {
1107
+ let plugins = state.plugins;
1108
+ if (cachedPreserveItemsPlugins != plugins) {
1109
+ cachedPreserveItems = false;
1110
+ cachedPreserveItemsPlugins = plugins;
1111
+ for (let i = 0; i < plugins.length; i++) if (plugins[i].spec.historyPreserveItems) {
1112
+ cachedPreserveItems = true;
1113
+ break;
1114
+ }
1115
+ }
1116
+ return cachedPreserveItems;
1117
+ }
1118
+ const historyKey = new PluginKey("history");
1119
+ const closeHistoryKey = new PluginKey("closeHistory");
1120
+ /**
1121
+ Returns a plugin that enables the undo history for an editor. The
1122
+ plugin will track undo and redo stacks, which can be used with the
1123
+ [`undo`](https://prosemirror.net/docs/ref/#history.undo) and [`redo`](https://prosemirror.net/docs/ref/#history.redo) commands.
1124
+
1125
+ You can set an `"addToHistory"` [metadata
1126
+ property](https://prosemirror.net/docs/ref/#state.Transaction.setMeta) of `false` on a transaction
1127
+ to prevent it from being rolled back by undo.
1128
+ */
1129
+ function history(config = {}) {
1130
+ config = {
1131
+ depth: config.depth || 100,
1132
+ newGroupDelay: config.newGroupDelay || 500
1133
+ };
1134
+ return new Plugin({
1135
+ key: historyKey,
1136
+ state: {
1137
+ init() {
1138
+ return new HistoryState(Branch.empty, Branch.empty, null, 0);
1139
+ },
1140
+ apply(tr, hist, state) {
1141
+ return applyTransaction(hist, state, tr, config);
1142
+ }
1143
+ },
1144
+ config,
1145
+ props: {
1146
+ handleDOMEvents: {
1147
+ beforeinput(view, e) {
1148
+ let inputType = e.inputType;
1149
+ let command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
1150
+ if (!command) return false;
1151
+ e.preventDefault();
1152
+ return command(view.state, view.dispatch);
1153
+ }
1154
+ }
1155
+ }
1156
+ });
1157
+ }
1158
+ /**
1159
+ A command function that undoes the last change, if any.
1160
+ */
1161
+ const undo = (state, dispatch) => {
1162
+ let hist = historyKey.getState(state);
1163
+ if (!hist || hist.done.eventCount == 0) return false;
1164
+ if (dispatch) histTransaction(hist, state, dispatch, false);
1165
+ return true;
1166
+ };
1167
+ /**
1168
+ A command function that redoes the last undone change, if any.
1169
+ */
1170
+ const redo = (state, dispatch) => {
1171
+ let hist = historyKey.getState(state);
1172
+ if (!hist || hist.undone.eventCount == 0) return false;
1173
+ if (dispatch) histTransaction(hist, state, dispatch, true);
1174
+ return true;
1175
+ };
1176
+
1177
+ const History = Extension.create({
1178
+ name: 'history',
1179
+ addOptions() {
1180
+ return {
1181
+ depth: 100,
1182
+ newGroupDelay: 500
1183
+ };
1184
+ },
1185
+ addCommands() {
1186
+ return {
1187
+ undo: () => ({
1188
+ state,
1189
+ dispatch
1190
+ }) => {
1191
+ return undo(state, dispatch);
1192
+ },
1193
+ redo: () => ({
1194
+ state,
1195
+ dispatch
1196
+ }) => {
1197
+ return redo(state, dispatch);
1198
+ }
1199
+ };
1200
+ },
1201
+ addProseMirrorPlugins() {
1202
+ return [history(this.options)];
1203
+ },
1204
+ addKeyboardShortcuts() {
1205
+ return {
1206
+ 'Mod-z': () => this.editor.commands.undo(),
1207
+ 'Mod-y': () => this.editor.commands.redo(),
1208
+ 'Shift-Mod-z': () => this.editor.commands.redo(),
1209
+ // Russian keyboard layouts
1210
+ 'Mod-я': () => this.editor.commands.undo(),
1211
+ 'Shift-Mod-я': () => this.editor.commands.redo()
1212
+ };
1213
+ }
1214
+ });
1215
+
1216
+ const HorizontalRule = Node.create({
1217
+ name: 'horizontalRule',
1218
+ addOptions() {
1219
+ return {
1220
+ HTMLAttributes: {}
1221
+ };
1222
+ },
1223
+ group: 'block',
1224
+ parseHTML() {
1225
+ return [{
1226
+ tag: 'hr'
1227
+ }];
1228
+ },
1229
+ renderHTML({
1230
+ HTMLAttributes
1231
+ }) {
1232
+ return ['hr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];
1233
+ },
1234
+ addCommands() {
1235
+ return {
1236
+ setHorizontalRule: () => ({
1237
+ chain
1238
+ }) => {
1239
+ return chain().insertContent({
1240
+ type: this.name
1241
+ })
1242
+ // set cursor after horizontal rule
1243
+ .command(({
1244
+ tr,
1245
+ dispatch
1246
+ }) => {
1247
+ var _a;
1248
+ if (dispatch) {
1249
+ const {
1250
+ $to
1251
+ } = tr.selection;
1252
+ const posAfter = $to.end();
1253
+ if ($to.nodeAfter) {
1254
+ tr.setSelection(TextSelection.create(tr.doc, $to.pos));
1255
+ } else {
1256
+ // add node after horizontal rule if it’s the end of the document
1257
+ const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create();
1258
+ if (node) {
1259
+ tr.insert(posAfter, node);
1260
+ tr.setSelection(TextSelection.create(tr.doc, posAfter));
1261
+ }
1262
+ }
1263
+ tr.scrollIntoView();
1264
+ }
1265
+ return true;
1266
+ }).run();
1267
+ }
1268
+ };
1269
+ },
1270
+ addInputRules() {
1271
+ return [nodeInputRule({
1272
+ find: /^(?:---|—-|___\s|\*\*\*\s)$/,
1273
+ type: this.type
1274
+ })];
1275
+ }
1276
+ });
1277
+
1278
+ const Text = Node.create({
1279
+ name: 'text',
1280
+ group: 'inline'
1281
+ });
1282
+
1283
+ const StarterKit = Extension.create({
1284
+ name: 'starterKit',
1285
+ addExtensions() {
1286
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
1287
+ const extensions = [];
1288
+ if (this.options.blockquote !== false) {
1289
+ extensions.push(Blockquote.configure((_a = this.options) === null || _a === void 0 ? void 0 : _a.blockquote));
1290
+ }
1291
+ if (this.options.bold !== false) {
1292
+ extensions.push(Bold.configure((_b = this.options) === null || _b === void 0 ? void 0 : _b.bold));
1293
+ }
1294
+ if (this.options.bulletList !== false) {
1295
+ extensions.push(BulletList.configure((_c = this.options) === null || _c === void 0 ? void 0 : _c.bulletList));
1296
+ }
1297
+ if (this.options.code !== false) {
1298
+ extensions.push(Code.configure((_d = this.options) === null || _d === void 0 ? void 0 : _d.code));
1299
+ }
1300
+ if (this.options.codeBlock !== false) {
1301
+ extensions.push(CodeBlock.configure((_e = this.options) === null || _e === void 0 ? void 0 : _e.codeBlock));
1302
+ }
1303
+ if (this.options.document !== false) {
1304
+ extensions.push(Document.configure((_f = this.options) === null || _f === void 0 ? void 0 : _f.document));
1305
+ }
1306
+ if (this.options.dropcursor !== false) {
1307
+ extensions.push(Dropcursor.configure((_g = this.options) === null || _g === void 0 ? void 0 : _g.dropcursor));
1308
+ }
1309
+ if (this.options.gapcursor !== false) {
1310
+ extensions.push(Gapcursor.configure((_h = this.options) === null || _h === void 0 ? void 0 : _h.gapcursor));
1311
+ }
1312
+ if (this.options.hardBreak !== false) {
1313
+ extensions.push(HardBreak.configure((_j = this.options) === null || _j === void 0 ? void 0 : _j.hardBreak));
1314
+ }
1315
+ if (this.options.heading !== false) {
1316
+ extensions.push(Heading.configure((_k = this.options) === null || _k === void 0 ? void 0 : _k.heading));
1317
+ }
1318
+ if (this.options.history !== false) {
1319
+ extensions.push(History.configure((_l = this.options) === null || _l === void 0 ? void 0 : _l.history));
1320
+ }
1321
+ if (this.options.horizontalRule !== false) {
1322
+ extensions.push(HorizontalRule.configure((_m = this.options) === null || _m === void 0 ? void 0 : _m.horizontalRule));
1323
+ }
1324
+ if (this.options.italic !== false) {
1325
+ extensions.push(Italic.configure((_o = this.options) === null || _o === void 0 ? void 0 : _o.italic));
1326
+ }
1327
+ if (this.options.listItem !== false) {
1328
+ extensions.push(ListItem.configure((_p = this.options) === null || _p === void 0 ? void 0 : _p.listItem));
1329
+ }
1330
+ if (this.options.orderedList !== false) {
1331
+ extensions.push(OrderedList.configure((_q = this.options) === null || _q === void 0 ? void 0 : _q.orderedList));
1332
+ }
1333
+ if (this.options.paragraph !== false) {
1334
+ extensions.push(Paragraph.configure((_r = this.options) === null || _r === void 0 ? void 0 : _r.paragraph));
1335
+ }
1336
+ if (this.options.strike !== false) {
1337
+ extensions.push(Strike.configure((_s = this.options) === null || _s === void 0 ? void 0 : _s.strike));
1338
+ }
1339
+ if (this.options.text !== false) {
1340
+ extensions.push(Text.configure((_t = this.options) === null || _t === void 0 ? void 0 : _t.text));
1341
+ }
1342
+ return extensions;
1343
+ }
1344
+ });
1345
+
1346
+ const Underline = Mark.create({
1347
+ name: 'underline',
1348
+ addOptions() {
1349
+ return {
1350
+ HTMLAttributes: {}
1351
+ };
1352
+ },
1353
+ parseHTML() {
1354
+ return [{
1355
+ tag: 'u'
1356
+ }, {
1357
+ style: 'text-decoration',
1358
+ consuming: false,
1359
+ getAttrs: style => style.includes('underline') ? {} : false
1360
+ }];
1361
+ },
1362
+ renderHTML({
1363
+ HTMLAttributes
1364
+ }) {
1365
+ return ['u', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
1366
+ },
1367
+ addCommands() {
1368
+ return {
1369
+ setUnderline: () => ({
1370
+ commands
1371
+ }) => {
1372
+ return commands.setMark(this.name);
1373
+ },
1374
+ toggleUnderline: () => ({
1375
+ commands
1376
+ }) => {
1377
+ return commands.toggleMark(this.name);
1378
+ },
1379
+ unsetUnderline: () => ({
1380
+ commands
1381
+ }) => {
1382
+ return commands.unsetMark(this.name);
1383
+ }
1384
+ };
1385
+ },
1386
+ addKeyboardShortcuts() {
1387
+ return {
1388
+ 'Mod-u': () => this.editor.commands.toggleUnderline(),
1389
+ 'Mod-U': () => this.editor.commands.toggleUnderline()
1390
+ };
1391
+ }
1392
+ });
1393
+
1394
+ const Placeholder = Extension.create({
1395
+ name: 'placeholder',
1396
+ addOptions() {
1397
+ return {
1398
+ emptyEditorClass: 'is-editor-empty',
1399
+ emptyNodeClass: 'is-empty',
1400
+ placeholder: 'Write something …',
1401
+ showOnlyWhenEditable: true,
1402
+ showOnlyCurrent: true,
1403
+ includeChildren: false
1404
+ };
1405
+ },
1406
+ addProseMirrorPlugins() {
1407
+ return [new Plugin({
1408
+ props: {
1409
+ decorations: ({
1410
+ doc,
1411
+ selection
1412
+ }) => {
1413
+ const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
1414
+ const {
1415
+ anchor
1416
+ } = selection;
1417
+ const decorations = [];
1418
+ if (!active) {
1419
+ return null;
1420
+ }
1421
+ // only calculate isEmpty once due to its performance impacts (see issue #3360)
1422
+ const emptyDocInstance = doc.type.createAndFill();
1423
+ const isEditorEmpty = (emptyDocInstance === null || emptyDocInstance === void 0 ? void 0 : emptyDocInstance.sameMarkup(doc)) && emptyDocInstance.content.findDiffStart(doc.content) === null;
1424
+ doc.descendants((node, pos) => {
1425
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
1426
+ const isEmpty = !node.isLeaf && !node.childCount;
1427
+ if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
1428
+ const classes = [this.options.emptyNodeClass];
1429
+ if (isEditorEmpty) {
1430
+ classes.push(this.options.emptyEditorClass);
1431
+ }
1432
+ const decoration = Decoration.node(pos, pos + node.nodeSize, {
1433
+ class: classes.join(' '),
1434
+ 'data-placeholder': typeof this.options.placeholder === 'function' ? this.options.placeholder({
1435
+ editor: this.editor,
1436
+ node,
1437
+ pos,
1438
+ hasAnchor
1439
+ }) : this.options.placeholder
1440
+ });
1441
+ decorations.push(decoration);
1442
+ }
1443
+ return this.options.includeChildren;
1444
+ });
1445
+ return DecorationSet.create(doc, decorations);
1446
+ }
1447
+ }
1448
+ })];
1449
+ }
1450
+ });
1451
+
1452
+ var script = defineComponent({
1453
+ name: 'OrRichTextEditor',
1454
+ components: {
1455
+ OrIconButton: script$1,
1456
+ OrLabel: script$2,
1457
+ OrMenuItem: script$3,
1458
+ OrMenu: script$4,
1459
+ OrModal: script$5,
1460
+ OrInput: script$6,
1461
+ OrButton: script$7
1462
+ },
1463
+ inheritAttrs: false,
1464
+ props: {
1465
+ modelValue: {
1466
+ type: String,
1467
+ default: undefined
1468
+ },
1469
+ value: {
1470
+ type: String,
1471
+ default: undefined
1472
+ },
1473
+ toolbar: {
1474
+ type: Array,
1475
+ default: () => [['heading'], ['bold', 'italic', 'strike'], ['underline', 'highlight'], ['link'], ['blockquote', 'codeBlock'], ['bulletList', 'orderedList'], ['undo', 'redo']]
1476
+ },
1477
+ description: {
1478
+ type: String,
1479
+ default: ''
1480
+ },
1481
+ placeholder: {
1482
+ type: String,
1483
+ default: 'Write something...'
1484
+ },
1485
+ autofocus: {
1486
+ type: Boolean,
1487
+ default: false
1488
+ },
1489
+ markdownFormat: {
1490
+ type: Boolean,
1491
+ default: false
1492
+ },
1493
+ fullHeight: {
1494
+ type: Boolean,
1495
+ default: false
1496
+ }
1497
+ },
1498
+ emits: ['update:modelValue', 'input'],
1499
+ expose: ['root'],
1500
+ setup(props, context) {
1501
+ // Refs
1502
+ const root = ref();
1503
+ let editor = null;
1504
+ const editorRef = ref();
1505
+ const containerRef = ref();
1506
+ const toolbarButtonRef = ref();
1507
+ const menuRef = ref();
1508
+ const isActive = ref({});
1509
+ const isFocused = ref(props.autofocus);
1510
+ const headingLevels = [1, 2, 3, 4];
1511
+ const previousHeadingLevel = ref();
1512
+ const activeHeadingLevel = ref(0);
1513
+ const markdownOutput = ref('');
1514
+ const isOpenLinkModal = ref(false);
1515
+ const text = ref('');
1516
+ const link = ref('');
1517
+ // let trap: UseFocusTrapReturn = useFocusTrap(editorRef, {
1518
+ // immediate: true,
1519
+ // fallbackFocus: '.container',
1520
+ // allowOutsideClick: true,
1521
+ // });
1522
+ const iconsEnum = ref({
1523
+ bold: 'format_bold',
1524
+ italic: 'format_italic',
1525
+ underline: 'format_underlined',
1526
+ strike: 'format_strikethrough',
1527
+ bulletList: 'format_list_bulleted',
1528
+ orderedList: 'format_list_numbered',
1529
+ link: 'link',
1530
+ highlight: 'highlight',
1531
+ redo: 'redo',
1532
+ undo: 'undo',
1533
+ codeBlock: 'code_blocks',
1534
+ blockquote: 'format_quote'
1535
+ });
1536
+ const iconTooltipsEnum = ref({
1537
+ bold: 'Bold',
1538
+ italic: 'Italic',
1539
+ underline: 'Underline',
1540
+ strike: 'Strike',
1541
+ bulletList: 'Bulleted List',
1542
+ orderedList: 'Numbered List',
1543
+ link: 'Link',
1544
+ highlight: 'Highlight',
1545
+ redo: 'Redo',
1546
+ undo: 'Undo',
1547
+ codeBlock: 'Code Block',
1548
+ blockquote: 'Quote'
1549
+ });
1550
+ onMounted(() => {
1551
+ editor = new Editor({
1552
+ onUpdate: ({
1553
+ editor
1554
+ }) => {
1555
+ isFocused.value = true;
1556
+ setActiveFormats();
1557
+ const html = editor.getHTML();
1558
+ const text = editor.getText();
1559
+ if (props.markdownFormat) {
1560
+ markdownOutput.value = serialize(editor.schema, editor.getJSON());
1561
+ proxyModelValue.value = markdownOutput.value;
1562
+ } else {
1563
+ proxyModelValue.value = text === '' ? text : html;
1564
+ }
1565
+ },
1566
+ onCreate: ({
1567
+ editor
1568
+ }) => {
1569
+ if (props.markdownFormat) {
1570
+ const deserialized = deserialize(editor.schema, proxyModelValue.value);
1571
+ editor.commands.setContent(deserialized);
1572
+ } else {
1573
+ editor.commands.setContent(proxyModelValue.value);
1574
+ }
1575
+ },
1576
+ element: editorRef.value,
1577
+ autofocus: props.autofocus,
1578
+ extensions: [codemirrorNode, StarterKit.configure({
1579
+ heading: false,
1580
+ codeBlock: false
1581
+ }), Heading.configure({
1582
+ levels: headingLevels
1583
+ }).extend({
1584
+ levels: headingLevels,
1585
+ renderHTML({
1586
+ node,
1587
+ HTMLAttributes
1588
+ }) {
1589
+ return ['h' + node.attrs.level, mergeAttributes(HTMLAttributes, {
1590
+ class: `typography-headline-${node.attrs.level}`
1591
+ }), 0];
1592
+ }
1593
+ }), Underline, Link.configure({
1594
+ openOnClick: true,
1595
+ linkOnPaste: true,
1596
+ autolink: false,
1597
+ protocols: ['ftp', 'mailto', 'http', 'https'],
1598
+ validate: href => /^https?:\/\//.test(href),
1599
+ HTMLAttributes: {
1600
+ class: 'text-primary cursor-pointer'
1601
+ }
1602
+ }), Highlight, Placeholder.configure({
1603
+ placeholder: props.placeholder,
1604
+ emptyEditorClass: 'is-editor-empty text-outline'
1605
+ })],
1606
+ editorProps: {
1607
+ attributes: {
1608
+ class: 'focus:outline-none'
1609
+ }
1610
+ }
1611
+ });
1612
+ setActiveFormats();
1613
+ });
1614
+ onBeforeUnmount(() => {
1615
+ editor === null || editor === void 0 ? void 0 : editor.destroy();
1616
+ });
1617
+ onClickOutside(root, () => {
1618
+ isFocused.value = false;
1619
+ // trap.deactivate();
1620
+ });
1621
+ // Computed
1622
+ const proxyModelValue = computed({
1623
+ get: () => {
1624
+ var _a;
1625
+ return (_a = props.modelValue) !== null && _a !== void 0 ? _a : props.value; // TODO: Remove Vue 2 fallback
1626
+ },
1627
+
1628
+ set: value => {
1629
+ context.emit('input', value);
1630
+ context.emit('update:modelValue', value);
1631
+ }
1632
+ });
1633
+ const getIndexOfHeading = computed(() => {
1634
+ return props.toolbar.flat().indexOf('heading');
1635
+ });
1636
+ const headingIcon = computed(() => {
1637
+ if (activeHeadingLevel.value && isActive.value.heading) {
1638
+ return `format_h${activeHeadingLevel.value}`;
1639
+ }
1640
+ return 'format_paragraph';
1641
+ });
1642
+ //Methods
1643
+ const handleEditorClick = () => {
1644
+ setActiveFormats();
1645
+ isFocused.value = true;
1646
+ editor === null || editor === void 0 ? void 0 : editor.commands.focus();
1647
+ };
1648
+ const handleToolbarClick = (item, level) => {
1649
+ var _a, _b;
1650
+ switch (item) {
1651
+ case 'bulletList':
1652
+ case 'orderedList':
1653
+ item === 'bulletList' ? editor === null || editor === void 0 ? void 0 : editor.commands.toggleBulletList() : editor === null || editor === void 0 ? void 0 : editor.commands.toggleOrderedList();
1654
+ break;
1655
+ case 'link':
1656
+ if (editor) {
1657
+ const cursorPosition = (editor === null || editor === void 0 ? void 0 : editor.state.selection.$anchor.pos) || 0;
1658
+ const {
1659
+ from,
1660
+ to,
1661
+ empty
1662
+ } = editor.state.selection;
1663
+ const isLink = (_a = editor.view.state.doc.nodeAt(cursorPosition)) === null || _a === void 0 ? void 0 : _a.marks.filter(mark => mark.type.name === 'link');
1664
+ const existedText = (isLink === null || isLink === void 0 ? void 0 : isLink.length) ? ((_b = editor.view.state.doc.nodeAt(cursorPosition)) === null || _b === void 0 ? void 0 : _b.text) || '' : '';
1665
+ text.value = empty ? existedText : editor.state.doc.textBetween(from, to, ' ');
1666
+ link.value = editor.getAttributes('link').href || '';
1667
+ }
1668
+ isOpenLinkModal.value = !isOpenLinkModal.value;
1669
+ break;
1670
+ case 'blockquote':
1671
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().toggleBlockquote().run();
1672
+ break;
1673
+ case 'codeBlock':
1674
+ if (!isActive.value['codeBlock']) {
1675
+ editor === null || editor === void 0 ? void 0 : editor.commands.setNode(item, {
1676
+ language: 'javascript'
1677
+ });
1678
+ } else {
1679
+ editor === null || editor === void 0 ? void 0 : editor.commands.setNode('paragraph');
1680
+ }
1681
+ break;
1682
+ case 'heading':
1683
+ if (!level) {
1684
+ editor === null || editor === void 0 ? void 0 : editor.commands.toggleHeading({
1685
+ level: previousHeadingLevel.value
1686
+ });
1687
+ activeHeadingLevel.value = 0;
1688
+ } else {
1689
+ activeHeadingLevel.value = level;
1690
+ previousHeadingLevel.value = level;
1691
+ editor === null || editor === void 0 ? void 0 : editor.commands.toggleHeading({
1692
+ level: level
1693
+ });
1694
+ }
1695
+ editor === null || editor === void 0 ? void 0 : editor.commands.focus();
1696
+ break;
1697
+ case 'undo':
1698
+ case 'redo':
1699
+ item === 'undo' ? editor === null || editor === void 0 ? void 0 : editor.commands.undo() : editor === null || editor === void 0 ? void 0 : editor.commands.redo();
1700
+ break;
1701
+ default:
1702
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().toggleMark(item).run();
1703
+ break;
1704
+ }
1705
+ };
1706
+ const attachLink = async () => {
1707
+ var _a, _b;
1708
+ // empty
1709
+ if (link.value === '') {
1710
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().extendMarkRange('link').unsetLink().run();
1711
+ }
1712
+ const isEmptySelection = editor === null || editor === void 0 ? void 0 : editor.state.selection.empty;
1713
+ const cursorPosition = (editor === null || editor === void 0 ? void 0 : editor.state.selection.$anchor.pos) || 0;
1714
+ const isLink = (_a = editor === null || editor === void 0 ? void 0 : editor.view.state.doc.nodeAt(cursorPosition)) === null || _a === void 0 ? void 0 : _a.marks.filter(mark => mark.type.name === 'link');
1715
+ const existedText = (isLink === null || isLink === void 0 ? void 0 : isLink.length) ? (_b = editor === null || editor === void 0 ? void 0 : editor.view.state.doc.nodeAt(cursorPosition)) === null || _b === void 0 ? void 0 : _b.text : '';
1716
+ if (link.value && isEmptySelection && !existedText) {
1717
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().setMark('link', {
1718
+ href: link.value,
1719
+ target: '__blank'
1720
+ }).command(({
1721
+ tr
1722
+ }) => {
1723
+ const preparedValue = text.value[text.value.length - 1] === ' ' ? text.value : `${text.value} `;
1724
+ tr.insertText(preparedValue);
1725
+ return true;
1726
+ }).run();
1727
+ }
1728
+ if (link.value && existedText === text.value && isEmptySelection) {
1729
+ editor === null || editor === void 0 ? void 0 : editor.chain().extendMarkRange('link').updateAttributes('link', {
1730
+ href: link.value
1731
+ }).run();
1732
+ }
1733
+ if (link.value && !isEmptySelection) {
1734
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().setMark('link', {
1735
+ href: link.value,
1736
+ target: '__blank'
1737
+ }).run();
1738
+ }
1739
+ text.value = '';
1740
+ link.value = '';
1741
+ isOpenLinkModal.value = false;
1742
+ };
1743
+ const discardLink = () => {
1744
+ isOpenLinkModal.value = false;
1745
+ };
1746
+ const setActiveFormats = () => {
1747
+ const toolbarList = props.toolbar.flat();
1748
+ toolbarList.forEach(item => {
1749
+ isActive.value[item] = (editor === null || editor === void 0 ? void 0 : editor.isActive(item)) || false;
1750
+ });
1751
+ };
1752
+ // Styles
1753
+ const rootStyles = computed(() => {
1754
+ return ['or-rich-text-editor', ...(props.fullHeight ? ['h-full'] : [])];
1755
+ });
1756
+ const containerStyles = computed(() => {
1757
+ return [...EditorContainer, ...(props.fullHeight ? ['h-full'] : [])];
1758
+ });
1759
+ const toolbarContainerStyles = computed(() => {
1760
+ return [...ToolbarContainer];
1761
+ });
1762
+ const toolbarStyles = computed(() => {
1763
+ return [...Toolbar, ...(isFocused.value ? ToolbarButtonFocused : ToolbarButton)];
1764
+ });
1765
+ const editorInputStyles = computed(() => {
1766
+ return ['tiptap-editor', ...(props.fullHeight ? ['h-full'] : []), ...EditorInput];
1767
+ });
1768
+ const toolbarButtonStyles = item => {
1769
+ return [
1770
+ // Layout
1771
+ 'flex',
1772
+ // Spacing
1773
+ 'gap-md', ...(isActive.value[item] ? ToolbarButtonActive : [])];
1774
+ };
1775
+ //Effects
1776
+ watch(proxyModelValue, value => {
1777
+ if (value !== (editor === null || editor === void 0 ? void 0 : editor.getHTML()) && !props.markdownFormat) {
1778
+ editor === null || editor === void 0 ? void 0 : editor.commands.setContent(value);
1779
+ }
1780
+ if (props.markdownFormat && value !== markdownOutput.value) {
1781
+ const deserialized = deserialize(editor === null || editor === void 0 ? void 0 : editor.schema, value);
1782
+ editor === null || editor === void 0 ? void 0 : editor.commands.setContent(deserialized);
1783
+ }
1784
+ });
1785
+ return {
1786
+ editor,
1787
+ editorRef,
1788
+ containerRef,
1789
+ toolbarButtonRef,
1790
+ menuRef,
1791
+ iconsEnum,
1792
+ handleToolbarClick,
1793
+ handleEditorClick,
1794
+ isActive,
1795
+ iconTooltipsEnum,
1796
+ containerStyles,
1797
+ toolbarContainerStyles,
1798
+ toolbarStyles,
1799
+ rootStyles,
1800
+ root,
1801
+ toolbarButtonStyles,
1802
+ editorInputStyles,
1803
+ getIndexOfHeading,
1804
+ headingLevels,
1805
+ headingIcon,
1806
+ attachLink,
1807
+ discardLink,
1808
+ isOpenLinkModal,
1809
+ text,
1810
+ link
1811
+ };
1812
+ }
1813
+ });
1814
+
1815
+ export { script as s };