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