@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,718 @@
1
+ import { defineComponent, ref, onMounted, onBeforeUnmount, computed, watch } from 'vue-demi';
2
+ import { onClickOutside } from '@vueuse/core';
3
+ import { defaultMarkdownSerializer, MarkdownSerializer } from 'prosemirror-markdown';
4
+ import { DOMParser as DOMParser$1 } from 'prosemirror-model';
5
+ import { marked } from 'marked';
6
+ import Paragraph from '@tiptap/extension-paragraph';
7
+ import BulletList from '@tiptap/extension-bullet-list';
8
+ import ListItem from '@tiptap/extension-list-item';
9
+ import OrderedList from '@tiptap/extension-ordered-list';
10
+ import Strike from '@tiptap/extension-strike';
11
+ import Italic from '@tiptap/extension-italic';
12
+ import HardBreak from '@tiptap/extension-hard-break';
13
+ import Bold from '@tiptap/extension-bold';
14
+ import CodeBlock from '@tiptap/extension-code-block';
15
+ import Blockquote from '@tiptap/extension-blockquote';
16
+ import Link from '@tiptap/extension-link';
17
+ import Highlight from '@tiptap/extension-highlight';
18
+ import { _ as __vue_component__$1 } from './OrIconButton-a9db16fa.js';
19
+ import { _ as __vue_component__$2 } from './OrLabel-63380256.js';
20
+ import { _ as __vue_component__$4 } from './OrMenu-47b319a6.js';
21
+ import './OrPopover-83c885d0.js';
22
+ import { _ as __vue_component__$3 } from './OrMenuItem-6f9b8a93.js';
23
+ import { _ as __vue_component__$5 } from './OrModal-fa99b102.js';
24
+ import { _ as __vue_component__$6 } from './OrInput-044a9c85.js';
25
+ import { _ as __vue_component__$7 } from './OrButton-236d9c2e.js';
26
+ import { Node, Editor, mergeAttributes } from '@tiptap/core';
27
+ import StarterKit from '@tiptap/starter-kit';
28
+ import Underline from '@tiptap/extension-underline';
29
+ import Heading from '@tiptap/extension-heading';
30
+ import Placeholder from '@tiptap/extension-placeholder';
31
+ import { C as CodeMirrorView } from './codemirrorView-2e87c938.js';
32
+ import { minimalSetup } from 'codemirror';
33
+ import { javascript } from '@codemirror/lang-javascript';
34
+ import { s as styleInject } from './style-inject.es-4c6f2515.js';
35
+ import { n as normalizeComponent } from './normalize-component-6e8e3d80.js';
36
+
37
+ const serializerNodes = {
38
+ ...defaultMarkdownSerializer.nodes,
39
+ [Paragraph.name]: defaultMarkdownSerializer.nodes.paragraph,
40
+ [BulletList.name]: defaultMarkdownSerializer.nodes.bullet_list,
41
+ [ListItem.name]: defaultMarkdownSerializer.nodes.list_item,
42
+ [OrderedList.name]: defaultMarkdownSerializer.nodes.ordered_list,
43
+ [HardBreak.name]: defaultMarkdownSerializer.nodes.hard_break,
44
+ [CodeBlock.name]: defaultMarkdownSerializer.nodes.code_block,
45
+ [Blockquote.name]: defaultMarkdownSerializer.nodes.blockquote
46
+ };
47
+ const serializerMarks = {
48
+ ...defaultMarkdownSerializer.marks,
49
+ [Bold.name]: defaultMarkdownSerializer.marks.strong,
50
+ [Strike.name]: {
51
+ open: '~~',
52
+ close: '~~',
53
+ mixable: true,
54
+ expelEnclosingWhitespace: true
55
+ },
56
+ [Italic.name]: {
57
+ open: '_',
58
+ close: '_',
59
+ mixable: true,
60
+ expelEnclosingWhitespace: true
61
+ },
62
+ [Highlight.name]: {
63
+ open: '==',
64
+ close: '==',
65
+ mixable: true,
66
+ expelEnclosingWhitespace: true
67
+ },
68
+ [Link.name]: {
69
+ open(state, mark, parent, index) {
70
+ return isPlainURL(mark, parent, index, 1) ? '<' : '[';
71
+ },
72
+ close(state, mark, parent, index) {
73
+ const href = mark.attrs.canonicalSrc || mark.attrs.href;
74
+ return isPlainURL(mark, parent, index, -1) ? '>' : `](${state.esc(href)}${mark.attrs.title ? ` ${state.quote(mark.attrs.title)}` : ''})`;
75
+ }
76
+ }
77
+ };
78
+ const isPlainURL = (link, parent, index, side) => {
79
+ if (link.attrs.title || !/^\w+:/.test(link.attrs.href)) return false;
80
+ const content = parent.child(index + (side < 0 ? -1 : 0));
81
+ if (!content.isText || content.text !== link.attrs.href || content.marks[content.marks.length - 1] !== link) return false;
82
+ if (index === (side < 0 ? 1 : parent.childCount - 1)) return true;
83
+ const next = parent.child(index + (side < 0 ? -2 : 1));
84
+ return !link.isInSet(next.marks);
85
+ };
86
+ const serialize = (schema, content) => {
87
+ const proseMirrorDocument = schema.nodeFromJSON(content);
88
+ const serializer = new MarkdownSerializer(serializerNodes, serializerMarks);
89
+ return serializer.serialize(proseMirrorDocument);
90
+ };
91
+ const deserialize = (schema, content) => {
92
+ if (!content) return null;
93
+ const html = marked.parse(content);
94
+ if (!html) return null;
95
+ const parser = new DOMParser();
96
+ const {
97
+ body
98
+ } = parser.parseFromString(html, 'text/html');
99
+ // append original source as a comment that nodes can access
100
+ body.append(document.createComment(content));
101
+ const state = DOMParser$1.fromSchema(schema).parse(body);
102
+ return state.toJSON();
103
+ };
104
+
105
+ const EditorContainer = [
106
+ // Colors
107
+ 'border-outline', 'dark:border-outline-dark', 'focus-within:theme-border-1-primary', 'dark:focus-within:theme-border-1-primary-dark', 'focus-within:bg-primary-opacity-0-08', 'dark:focus-within:bg-primary-opacity-0-08-dark', 'focus-within:theme-outline-primary', 'dark:focus-within:theme-outline-primary-dark',
108
+ // Sizing
109
+ 'border-1', 'rounded-md', 'w-full'];
110
+ const ToolbarContainer = [
111
+ // Layout
112
+ 'flex',
113
+ //Spacing
114
+ 'py-sm',
115
+ //Sizing
116
+ 'border-b-1',
117
+ //Colors
118
+ 'border-b-outline', 'dark:border-b-outline-dark'];
119
+ const Toolbar = [
120
+ // Layout
121
+ 'flex',
122
+ // Spacing
123
+ 'px-sm', 'gap-md',
124
+ // Sizing
125
+ 'border-r-1',
126
+ //Colors
127
+ 'border-r-disabled', 'dark:border-r-outline-dark',
128
+ // Last child
129
+ 'last-of-type:border-none'];
130
+ const ToolbarButton = [
131
+ // Typography
132
+ 'text-on-disabled', 'dark:text-on-disabled-dark'];
133
+ const ToolbarButtonFocused = [
134
+ // Typography
135
+ 'text-outline', 'dark:text-outline-dark'];
136
+ const ToolbarButtonActive = [
137
+ // Typography
138
+ 'text-on-background', 'dark:text-on-background-dark'];
139
+ const EditorInput = [
140
+ // Spacing
141
+ 'p-sm',
142
+ // Typography
143
+ 'typography-body-2-regular', 'text-on-background', 'dark:text-on-background-dark',
144
+ // Sizing
145
+ 'min-h-[88px]'];
146
+
147
+ var codemirrorNode = Node.create({
148
+ name: 'codeBlock',
149
+ content: 'text*',
150
+ marks: '',
151
+ group: 'block',
152
+ code: true,
153
+ defining: true,
154
+ isolating: true,
155
+ parseHTML() {
156
+ return [{
157
+ tag: 'pre',
158
+ preserveWhitespace: 'full'
159
+ }];
160
+ },
161
+ renderHTML() {
162
+ return ['pre', ['code', 0]];
163
+ },
164
+ addNodeView() {
165
+ return ({
166
+ node,
167
+ editor,
168
+ getPos
169
+ }) => {
170
+ return new CodeMirrorView({
171
+ node,
172
+ view: editor.view,
173
+ getPos: getPos,
174
+ cmOptions: {
175
+ extensions: [minimalSetup, javascript()]
176
+ }
177
+ });
178
+ };
179
+ }
180
+ });
181
+
182
+ var script = defineComponent({
183
+ name: 'OrRichTextEditor',
184
+ components: {
185
+ OrIconButton: __vue_component__$1,
186
+ OrLabel: __vue_component__$2,
187
+ OrMenuItem: __vue_component__$3,
188
+ OrMenu: __vue_component__$4,
189
+ OrModal: __vue_component__$5,
190
+ OrInput: __vue_component__$6,
191
+ OrButton: __vue_component__$7
192
+ },
193
+ inheritAttrs: false,
194
+ props: {
195
+ modelValue: {
196
+ type: String,
197
+ default: undefined
198
+ },
199
+ value: {
200
+ type: String,
201
+ default: undefined
202
+ },
203
+ toolbar: {
204
+ type: Array,
205
+ default: () => [['heading'], ['bold', 'italic', 'strike'], ['underline', 'highlight'], ['link'], ['blockquote', 'codeBlock'], ['bulletList', 'orderedList'], ['undo', 'redo']]
206
+ },
207
+ description: {
208
+ type: String,
209
+ default: ''
210
+ },
211
+ placeholder: {
212
+ type: String,
213
+ default: 'Write something...'
214
+ },
215
+ autofocus: {
216
+ type: Boolean,
217
+ default: false
218
+ },
219
+ markdownFormat: {
220
+ type: Boolean,
221
+ default: false
222
+ },
223
+ fullHeight: {
224
+ type: Boolean,
225
+ default: false
226
+ }
227
+ },
228
+ emits: ['update:modelValue', 'input'],
229
+ expose: ['root'],
230
+ setup(props, context) {
231
+ // Refs
232
+ const root = ref();
233
+ let editor = null;
234
+ const editorRef = ref();
235
+ const containerRef = ref();
236
+ const toolbarButtonRef = ref();
237
+ const menuRef = ref();
238
+ const isActive = ref({});
239
+ const isFocused = ref(props.autofocus);
240
+ const headingLevels = [1, 2, 3, 4];
241
+ const previousHeadingLevel = ref();
242
+ const activeHeadingLevel = ref(0);
243
+ const markdownOutput = ref('');
244
+ const isOpenLinkModal = ref(false);
245
+ const text = ref('');
246
+ const link = ref('');
247
+ // let trap: UseFocusTrapReturn = useFocusTrap(editorRef, {
248
+ // immediate: true,
249
+ // fallbackFocus: '.container',
250
+ // allowOutsideClick: true,
251
+ // });
252
+ const iconsEnum = ref({
253
+ bold: 'format_bold',
254
+ italic: 'format_italic',
255
+ underline: 'format_underlined',
256
+ strike: 'format_strikethrough',
257
+ bulletList: 'format_list_bulleted',
258
+ orderedList: 'format_list_numbered',
259
+ link: 'link',
260
+ highlight: 'highlight',
261
+ redo: 'redo',
262
+ undo: 'undo',
263
+ codeBlock: 'code_blocks',
264
+ blockquote: 'format_quote'
265
+ });
266
+ const iconTooltipsEnum = ref({
267
+ bold: 'Bold',
268
+ italic: 'Italic',
269
+ underline: 'Underline',
270
+ strike: 'Strike',
271
+ bulletList: 'Bulleted List',
272
+ orderedList: 'Numbered List',
273
+ link: 'Link',
274
+ highlight: 'Highlight',
275
+ redo: 'Redo',
276
+ undo: 'Undo',
277
+ codeBlock: 'Code Block',
278
+ blockquote: 'Quote'
279
+ });
280
+ onMounted(() => {
281
+ editor = new Editor({
282
+ onUpdate: ({
283
+ editor
284
+ }) => {
285
+ isFocused.value = true;
286
+ setActiveFormats();
287
+ const html = editor.getHTML();
288
+ const text = editor.getText();
289
+ if (props.markdownFormat) {
290
+ markdownOutput.value = serialize(editor.schema, editor.getJSON());
291
+ proxyModelValue.value = markdownOutput.value;
292
+ } else {
293
+ proxyModelValue.value = text === '' ? text : html;
294
+ }
295
+ },
296
+ onCreate: ({
297
+ editor
298
+ }) => {
299
+ if (props.markdownFormat) {
300
+ const deserialized = deserialize(editor.schema, proxyModelValue.value);
301
+ editor.commands.setContent(deserialized);
302
+ } else {
303
+ editor.commands.setContent(proxyModelValue.value);
304
+ }
305
+ },
306
+ element: editorRef.value,
307
+ autofocus: props.autofocus,
308
+ extensions: [codemirrorNode, StarterKit.configure({
309
+ heading: false,
310
+ codeBlock: false
311
+ }), Heading.configure({
312
+ levels: headingLevels
313
+ }).extend({
314
+ levels: headingLevels,
315
+ renderHTML({
316
+ node,
317
+ HTMLAttributes
318
+ }) {
319
+ return ['h' + node.attrs.level, mergeAttributes(HTMLAttributes, {
320
+ class: `typography-headline-${node.attrs.level}`
321
+ }), 0];
322
+ }
323
+ }), Underline, Link.configure({
324
+ openOnClick: true,
325
+ linkOnPaste: true,
326
+ autolink: false,
327
+ protocols: ['ftp', 'mailto', 'http', 'https'],
328
+ validate: href => /^https?:\/\//.test(href),
329
+ HTMLAttributes: {
330
+ class: 'text-primary cursor-pointer'
331
+ }
332
+ }), Highlight, Placeholder.configure({
333
+ placeholder: props.placeholder,
334
+ emptyEditorClass: 'is-editor-empty text-outline'
335
+ })],
336
+ editorProps: {
337
+ attributes: {
338
+ class: 'focus:outline-none'
339
+ }
340
+ }
341
+ });
342
+ setActiveFormats();
343
+ });
344
+ onBeforeUnmount(() => {
345
+ editor === null || editor === void 0 ? void 0 : editor.destroy();
346
+ });
347
+ onClickOutside(root, () => {
348
+ isFocused.value = false;
349
+ // trap.deactivate();
350
+ });
351
+ // Computed
352
+ const proxyModelValue = computed({
353
+ get: () => {
354
+ var _a;
355
+ return (_a = props.modelValue) !== null && _a !== void 0 ? _a : props.value; // TODO: Remove Vue 2 fallback
356
+ },
357
+
358
+ set: value => {
359
+ context.emit('input', value);
360
+ context.emit('update:modelValue', value);
361
+ }
362
+ });
363
+ const getIndexOfHeading = computed(() => {
364
+ return props.toolbar.flat().indexOf('heading');
365
+ });
366
+ const headingIcon = computed(() => {
367
+ if (activeHeadingLevel.value && isActive.value.heading) {
368
+ return `format_h${activeHeadingLevel.value}`;
369
+ }
370
+ return 'format_paragraph';
371
+ });
372
+ //Methods
373
+ const handleEditorClick = () => {
374
+ setActiveFormats();
375
+ isFocused.value = true;
376
+ editor === null || editor === void 0 ? void 0 : editor.commands.focus();
377
+ };
378
+ const handleToolbarClick = (item, level) => {
379
+ var _a, _b;
380
+ switch (item) {
381
+ case 'bulletList':
382
+ case 'orderedList':
383
+ item === 'bulletList' ? editor === null || editor === void 0 ? void 0 : editor.commands.toggleBulletList() : editor === null || editor === void 0 ? void 0 : editor.commands.toggleOrderedList();
384
+ break;
385
+ case 'link':
386
+ if (editor) {
387
+ const cursorPosition = (editor === null || editor === void 0 ? void 0 : editor.state.selection.$anchor.pos) || 0;
388
+ const {
389
+ from,
390
+ to,
391
+ empty
392
+ } = editor.state.selection;
393
+ const isLink = (_a = editor.view.state.doc.nodeAt(cursorPosition)) === null || _a === void 0 ? void 0 : _a.marks.filter(mark => mark.type.name === 'link');
394
+ 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) || '' : '';
395
+ text.value = empty ? existedText : editor.state.doc.textBetween(from, to, ' ');
396
+ link.value = editor.getAttributes('link').href || '';
397
+ }
398
+ isOpenLinkModal.value = !isOpenLinkModal.value;
399
+ break;
400
+ case 'blockquote':
401
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().toggleBlockquote().run();
402
+ break;
403
+ case 'codeBlock':
404
+ if (!isActive.value['codeBlock']) {
405
+ editor === null || editor === void 0 ? void 0 : editor.commands.setNode(item, {
406
+ language: 'javascript'
407
+ });
408
+ } else {
409
+ editor === null || editor === void 0 ? void 0 : editor.commands.setNode('paragraph');
410
+ }
411
+ break;
412
+ case 'heading':
413
+ if (!level) {
414
+ editor === null || editor === void 0 ? void 0 : editor.commands.toggleHeading({
415
+ level: previousHeadingLevel.value
416
+ });
417
+ activeHeadingLevel.value = 0;
418
+ } else {
419
+ activeHeadingLevel.value = level;
420
+ previousHeadingLevel.value = level;
421
+ editor === null || editor === void 0 ? void 0 : editor.commands.toggleHeading({
422
+ level: level
423
+ });
424
+ }
425
+ editor === null || editor === void 0 ? void 0 : editor.commands.focus();
426
+ break;
427
+ case 'undo':
428
+ case 'redo':
429
+ item === 'undo' ? editor === null || editor === void 0 ? void 0 : editor.commands.undo() : editor === null || editor === void 0 ? void 0 : editor.commands.redo();
430
+ break;
431
+ default:
432
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().toggleMark(item).run();
433
+ break;
434
+ }
435
+ };
436
+ const attachLink = async () => {
437
+ var _a, _b;
438
+ // empty
439
+ if (link.value === '') {
440
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().extendMarkRange('link').unsetLink().run();
441
+ }
442
+ const isEmptySelection = editor === null || editor === void 0 ? void 0 : editor.state.selection.empty;
443
+ const cursorPosition = (editor === null || editor === void 0 ? void 0 : editor.state.selection.$anchor.pos) || 0;
444
+ 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');
445
+ 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 : '';
446
+ if (link.value && isEmptySelection && !existedText) {
447
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().setMark('link', {
448
+ href: link.value,
449
+ target: '__blank'
450
+ }).command(({
451
+ tr
452
+ }) => {
453
+ const preparedValue = text.value[text.value.length - 1] === ' ' ? text.value : `${text.value} `;
454
+ tr.insertText(preparedValue);
455
+ return true;
456
+ }).run();
457
+ }
458
+ if (link.value && existedText === text.value && isEmptySelection) {
459
+ editor === null || editor === void 0 ? void 0 : editor.chain().extendMarkRange('link').updateAttributes('link', {
460
+ href: link.value
461
+ }).run();
462
+ }
463
+ if (link.value && !isEmptySelection) {
464
+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().setMark('link', {
465
+ href: link.value,
466
+ target: '__blank'
467
+ }).run();
468
+ }
469
+ text.value = '';
470
+ link.value = '';
471
+ isOpenLinkModal.value = false;
472
+ };
473
+ const discardLink = () => {
474
+ isOpenLinkModal.value = false;
475
+ };
476
+ const setActiveFormats = () => {
477
+ const toolbarList = props.toolbar.flat();
478
+ toolbarList.forEach(item => {
479
+ isActive.value[item] = (editor === null || editor === void 0 ? void 0 : editor.isActive(item)) || false;
480
+ });
481
+ };
482
+ // Styles
483
+ const rootStyles = computed(() => {
484
+ return ['or-rich-text-editor', ...(props.fullHeight ? ['h-full'] : [])];
485
+ });
486
+ const containerStyles = computed(() => {
487
+ return [...EditorContainer, ...(props.fullHeight ? ['h-full'] : [])];
488
+ });
489
+ const toolbarContainerStyles = computed(() => {
490
+ return [...ToolbarContainer];
491
+ });
492
+ const toolbarStyles = computed(() => {
493
+ return [...Toolbar, ...(isFocused.value ? ToolbarButtonFocused : ToolbarButton)];
494
+ });
495
+ const editorInputStyles = computed(() => {
496
+ return ['tiptap-editor', ...(props.fullHeight ? ['h-full'] : []), ...EditorInput];
497
+ });
498
+ const toolbarButtonStyles = item => {
499
+ return [
500
+ // Layout
501
+ 'flex',
502
+ // Spacing
503
+ 'gap-md', ...(isActive.value[item] ? ToolbarButtonActive : [])];
504
+ };
505
+ //Effects
506
+ watch(proxyModelValue, value => {
507
+ if (value !== (editor === null || editor === void 0 ? void 0 : editor.getHTML()) && !props.markdownFormat) {
508
+ editor === null || editor === void 0 ? void 0 : editor.commands.setContent(value);
509
+ }
510
+ if (props.markdownFormat && value !== markdownOutput.value) {
511
+ const deserialized = deserialize(editor === null || editor === void 0 ? void 0 : editor.schema, value);
512
+ editor === null || editor === void 0 ? void 0 : editor.commands.setContent(deserialized);
513
+ }
514
+ });
515
+ return {
516
+ editor,
517
+ editorRef,
518
+ containerRef,
519
+ toolbarButtonRef,
520
+ menuRef,
521
+ iconsEnum,
522
+ handleToolbarClick,
523
+ handleEditorClick,
524
+ isActive,
525
+ iconTooltipsEnum,
526
+ containerStyles,
527
+ toolbarContainerStyles,
528
+ toolbarStyles,
529
+ rootStyles,
530
+ root,
531
+ toolbarButtonStyles,
532
+ editorInputStyles,
533
+ getIndexOfHeading,
534
+ headingLevels,
535
+ headingIcon,
536
+ attachLink,
537
+ discardLink,
538
+ isOpenLinkModal,
539
+ text,
540
+ link
541
+ };
542
+ }
543
+ });
544
+
545
+ var css_248z = ".tiptap-editor ol{margin:0 24px;list-style:decimal}.tiptap-editor ul{margin:0 24px;list-style:initial}.tiptap-editor pre{background-color:rgba(186,209,236,.3);padding:4px 8px;margin:4px 0;width:100%;border-radius:4px}.tiptap-editor blockquote{margin:8px 24px;padding:0 24px;border-left:4px solid #bad1ec}.tiptap-editor .is-editor-empty::before{content:attr(data-placeholder);height:0;pointer-events:none;float:left}.tiptap-editor .cm-editor{border:none;border-radius:4px}.tiptap-editor .cm-editor .cm-scroller{border-radius:4px}.tiptap-editor .cm-editor.cm-focused{outline:0}.tiptap-editor .cm-editor .cm-gutters{background-color:rgba(0,95,177,.08);border:none}.tiptap-editor .cm-editor .cm-gutters .cm-gutterElement{padding:0 10px}.tiptap-editor .cm-editor .cm-gutters .cm-gutterElement.cm-activeLineGutter{background-color:rgba(0,95,177,.07)}";
546
+ styleInject(css_248z);
547
+
548
+ /* script */
549
+ const __vue_script__ = script;
550
+ /* template */
551
+ var __vue_render__ = function () {
552
+ var _vm = this;
553
+ var _h = _vm.$createElement;
554
+ var _c = _vm._self._c || _h;
555
+ return _c('div', {
556
+ ref: "root",
557
+ class: _vm.rootStyles
558
+ }, [_c('or-label', [_vm._v("\n " + _vm._s(_vm.description) + "\n ")]), _vm._v(" "), _c('div', {
559
+ ref: "containerRef",
560
+ class: _vm.containerStyles,
561
+ on: {
562
+ "click": function ($event) {
563
+ return _vm.handleEditorClick();
564
+ }
565
+ }
566
+ }, [_c('div', {
567
+ class: _vm.toolbarContainerStyles
568
+ }, _vm._l(_vm.toolbar, function (tool, index) {
569
+ return _c('div', {
570
+ key: index,
571
+ class: _vm.toolbarStyles
572
+ }, _vm._l(tool, function (item) {
573
+ return _c('div', {
574
+ key: item,
575
+ staticClass: "-my-xs",
576
+ class: _vm.toolbarButtonStyles(item)
577
+ }, [item === 'heading' ? _c('or-icon-button', {
578
+ ref: "toolbarButtonRef",
579
+ refInFor: true,
580
+ attrs: {
581
+ "tooltip": {
582
+ text: item,
583
+ placement: 'top'
584
+ },
585
+ "icon": {
586
+ icon: _vm.headingIcon,
587
+ variant: 'inherit',
588
+ size: 'm'
589
+ }
590
+ },
591
+ on: {
592
+ "click": function ($event) {
593
+ return _vm.menuRef.open();
594
+ }
595
+ }
596
+ }) : _c('or-icon-button', {
597
+ attrs: {
598
+ "tooltip": {
599
+ text: _vm.iconTooltipsEnum[item],
600
+ placement: 'top'
601
+ },
602
+ "icon": {
603
+ icon: _vm.iconsEnum[item],
604
+ variant: 'inherit',
605
+ size: 'm'
606
+ }
607
+ },
608
+ on: {
609
+ "click": function ($event) {
610
+ return _vm.handleToolbarClick(item);
611
+ }
612
+ }
613
+ })], 1);
614
+ }), 0);
615
+ }), 0), _vm._v(" "), _c('div', {
616
+ ref: "editorRef",
617
+ class: _vm.editorInputStyles
618
+ })]), _vm._v(" "), _vm.toolbarButtonRef ? _c('or-menu', {
619
+ ref: "menuRef",
620
+ attrs: {
621
+ "trigger": _vm.toolbarButtonRef[_vm.getIndexOfHeading].root,
622
+ "placement": "bottom-start"
623
+ }
624
+ }, [_vm._l(_vm.headingLevels, function (heading) {
625
+ return _c('or-menu-item', {
626
+ key: heading,
627
+ on: {
628
+ "click": function ($event) {
629
+ return _vm.handleToolbarClick('heading', heading);
630
+ }
631
+ }
632
+ }, [_vm._v("\n Heading " + _vm._s(heading) + "\n ")]);
633
+ }), _vm._v(" "), _c('or-menu-item', {
634
+ on: {
635
+ "click": function ($event) {
636
+ return _vm.handleToolbarClick('heading');
637
+ }
638
+ }
639
+ }, [_vm._v("\n None\n ")])], 2) : _vm._e(), _vm._v(" "), _c('or-modal', {
640
+ attrs: {
641
+ "is-open": _vm.isOpenLinkModal,
642
+ "size": "s"
643
+ },
644
+ scopedSlots: _vm._u([{
645
+ key: "header",
646
+ fn: function () {
647
+ return [_c('p', {
648
+ staticClass: "text-headline-2"
649
+ }, [_vm._v("\n Add Link\n ")])];
650
+ },
651
+ proxy: true
652
+ }, {
653
+ key: "footer",
654
+ fn: function () {
655
+ return [_c('div', {
656
+ staticClass: "flex ml-auto gap-md"
657
+ }, [_c('or-button', {
658
+ attrs: {
659
+ "variant": "outlined"
660
+ },
661
+ on: {
662
+ "click": _vm.discardLink
663
+ }
664
+ }, [_c('p', [_vm._v("Cancel")])]), _vm._v(" "), _c('or-button', {
665
+ on: {
666
+ "click": _vm.attachLink
667
+ }
668
+ }, [_c('p', [_vm._v("Save")])])], 1)];
669
+ },
670
+ proxy: true
671
+ }])
672
+ }, [_vm._v(" "), _c('div', [_c('or-label', [_vm._v("\n Text\n ")]), _vm._v(" "), _c('or-input', {
673
+ staticClass: "pb-md",
674
+ attrs: {
675
+ "placeholder": "Placeholder"
676
+ },
677
+ model: {
678
+ value: _vm.text,
679
+ callback: function ($$v) {
680
+ _vm.text = $$v;
681
+ },
682
+ expression: "text"
683
+ }
684
+ }), _vm._v(" "), _c('or-label', [_vm._v("\n Link\n ")]), _vm._v(" "), _c('or-input', {
685
+ attrs: {
686
+ "placeholder": "Placeholder"
687
+ },
688
+ model: {
689
+ value: _vm.link,
690
+ callback: function ($$v) {
691
+ _vm.link = $$v;
692
+ },
693
+ expression: "link"
694
+ }
695
+ })], 1)])], 1);
696
+ };
697
+ var __vue_staticRenderFns__ = [];
698
+
699
+ /* style */
700
+ const __vue_inject_styles__ = undefined;
701
+ /* scoped */
702
+ const __vue_scope_id__ = undefined;
703
+ /* module identifier */
704
+ const __vue_module_identifier__ = undefined;
705
+ /* functional template */
706
+ const __vue_is_functional_template__ = false;
707
+ /* style inject */
708
+
709
+ /* style inject SSR */
710
+
711
+ /* style inject shadow dom */
712
+
713
+ const __vue_component__ = /*#__PURE__*/normalizeComponent({
714
+ render: __vue_render__,
715
+ staticRenderFns: __vue_staticRenderFns__
716
+ }, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);
717
+
718
+ export { __vue_component__ as _ };