@onereach/ui-components 10.2.0 → 10.2.1-beta.4272.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 (42) hide show
  1. package/dist/bundled/v2/components/OrRichTextEditorV3/OrRichTextEditor.js +382 -252
  2. package/dist/bundled/v2/components/OrRichTextEditorV3/OrRichTextEditor.vue.d.ts +21 -68
  3. package/dist/bundled/v2/components/OrRichTextEditorV3/styles.d.ts +1 -0
  4. package/dist/bundled/v2/components/OrRichTextEditorV3/styles.js +5 -4
  5. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +1 -1
  6. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +1 -1
  7. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/markdown.js +2 -2
  8. package/dist/bundled/v2/{index-02a897ac.js → index-0e9c2b43.js} +1 -1
  9. package/dist/bundled/v2/{index-7516cf60.js → index-f379c836.js} +258 -173
  10. package/dist/bundled/v2/{markdown-fe3bfb01.js → markdown-2d22cf16.js} +66 -113
  11. package/dist/bundled/v3/components/OrRichTextEditorV3/OrRichTextEditor.js +1 -1
  12. package/dist/bundled/v3/components/OrRichTextEditorV3/OrRichTextEditor.vue.d.ts +14 -18
  13. package/dist/bundled/v3/components/OrRichTextEditorV3/index.js +1 -1
  14. package/dist/bundled/v3/components/OrRichTextEditorV3/props.js +1 -1
  15. package/dist/bundled/v3/components/OrRichTextEditorV3/styles.d.ts +1 -0
  16. package/dist/bundled/v3/components/OrRichTextEditorV3/styles.js +1 -1
  17. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +1 -1
  18. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +1 -1
  19. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/index.js +1 -1
  20. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/theme.js +1 -1
  21. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/markdown.js +1 -1
  22. package/dist/bundled/v3/components/{OrRichTextEditorV3-358d7df2.js → OrRichTextEditorV3-45e64a85.js} +673 -531
  23. package/dist/bundled/v3/components/index.js +1 -1
  24. package/dist/bundled/v3/index.js +1 -1
  25. package/dist/esm/v2/{OrRichTextEditor-734b8b27.js → OrRichTextEditor-fbcc33fd.js} +353 -244
  26. package/dist/esm/v2/components/index.js +1 -1
  27. package/dist/esm/v2/components/or-rich-text-editor-v3/OrRichTextEditor.vue.d.ts +21 -68
  28. package/dist/esm/v2/components/or-rich-text-editor-v3/index.js +7 -7
  29. package/dist/esm/v2/components/or-rich-text-editor-v3/partials/EditorToolbar.vue.d.ts +160 -0
  30. package/dist/esm/v2/components/or-rich-text-editor-v3/styles.d.ts +1 -0
  31. package/dist/esm/v2/index.js +1 -1
  32. package/dist/esm/v3/{OrRichTextEditor-b5684aab.js → OrRichTextEditor-cdd9e3e4.js} +325 -242
  33. package/dist/esm/v3/components/index.js +1 -1
  34. package/dist/esm/v3/components/or-rich-text-editor-v3/OrRichTextEditor.vue.d.ts +14 -18
  35. package/dist/esm/v3/components/or-rich-text-editor-v3/index.js +6 -6
  36. package/dist/esm/v3/components/or-rich-text-editor-v3/partials/EditorToolbar.vue.d.ts +89 -0
  37. package/dist/esm/v3/components/or-rich-text-editor-v3/styles.d.ts +1 -0
  38. package/dist/esm/v3/index.js +1 -1
  39. package/package.json +19 -20
  40. package/src/components/or-rich-text-editor-v3/OrRichTextEditor.vue +48 -203
  41. package/src/components/or-rich-text-editor-v3/partials/EditorToolbar.vue +238 -0
  42. package/src/components/or-rich-text-editor-v3/styles.ts +13 -10
@@ -1,25 +1,311 @@
1
1
  import { g as useResizeObserver, o as onClickOutside } from '../../index-13c63b4c.js';
2
2
  import { u as useFocusTrap } from '../../useFocusTrap-c1b303f8.js';
3
- import { defineComponent, ref, onMounted, onBeforeUnmount, computed, watch, nextTick } from 'vue-demi';
4
- 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, U as Underline, c as Link, e as Highlight } from '../../markdown-fe3bfb01.js';
5
- import { OrRichTextEditor, EditorContainer, ToolbarContainer, Toolbar, ToolbarButtonFocused, ToolbarButton, EditorInput } from './styles.js';
6
- import { Formats } from './props.js';
7
- import { N as Node, m as mergeAttributes, t as textblockTypeInputRule, E as Extension, D as Decoration, a as DecorationSet, M as Mark, b as markInputRule, c as markPasteRule, k as keydownHandler, d as callOrReturn, g as getExtensionField, n as nodeInputRule, e as Editor } from '../../index-7516cf60.js';
8
- import { P as Plugin, a as PluginKey, d as dropPoint, S as Selection, N as NodeSelection, F as Fragment, b as Slice, T as TextSelection, M as Mapping } from '../../index-02a897ac.js';
9
- import codemirrorNode from './utils/codemirror/codemirrorNode.js';
10
- import __vue_component__$1 from '../OrIconButtonV3/OrIconButton.js';
11
- import __vue_component__$2 from '../OrLabelV3/OrLabel.js';
3
+ import { defineComponent, ref, computed, onMounted, onBeforeUnmount, watch, nextTick } from 'vue-demi';
4
+ 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, U as Underline, c as Link, e as Highlight } from '../../markdown-2d22cf16.js';
5
+ import { ToolbarContainer, Toolbar, ToolbarButtonFocused, ToolbarButton, OrRichTextEditor, EditorContainer, EditorContainerFocus, EditorInput } from './styles.js';
6
+ import __vue_component__$2 from '../OrIconButtonV3/OrIconButton.js';
12
7
  import __vue_component__$3 from '../OrMenuItemV3/OrMenuItem.js';
13
8
  import __vue_component__$4 from '../OrMenuV3/OrMenu.js';
14
- import __vue_component__$5 from '../OrModalV3/OrModal.js';
15
- import { _ as __vue_component__$6 } from '../../OrInput-b477f1d1.js';
16
- import __vue_component__$7 from '../OrButtonV3/OrButton.js';
17
- import __vue_component__$8 from '../OrPopoverV3/OrPopover.js';
9
+ import __vue_component__$5 from '../OrPopoverV3/OrPopover.js';
10
+ import { n as normalizeComponent } from '../../normalize-component-6e8e3d80.js';
11
+ import { Formats } from './props.js';
12
+ import { N as Node, m as mergeAttributes, t as textblockTypeInputRule, E as Extension, D as Decoration, a as DecorationSet, M as Mark, b as markInputRule, c as markPasteRule, k as keydownHandler, d as callOrReturn, g as getExtensionField, n as nodeInputRule, e as Editor } from '../../index-f379c836.js';
13
+ import { P as Plugin, a as PluginKey, d as dropPoint, S as Selection, N as NodeSelection, F as Fragment, b as Slice, T as TextSelection, M as Mapping } from '../../index-0e9c2b43.js';
14
+ import codemirrorNode from './utils/codemirror/codemirrorNode.js';
15
+ import __vue_component__$6 from '../OrModalV3/OrModal.js';
16
+ import { _ as __vue_component__$7 } from '../../OrInput-b477f1d1.js';
17
+ import __vue_component__$8 from '../OrButtonV3/OrButton.js';
18
18
  import __vue_component__$9 from '../OrHintV3/OrHint.js';
19
19
  import __vue_component__$a from '../OrErrorV3/OrError.js';
20
+ import __vue_component__$b from '../OrLabelV3/OrLabel.js';
20
21
  import { a as useDebounceFn } from '../../index-279e78b9.js';
21
22
  import { s as styleInject } from '../../style-inject.es-4c6f2515.js';
22
- import { n as normalizeComponent } from '../../normalize-component-6e8e3d80.js';
23
+
24
+ var script$1 = defineComponent({
25
+ components: {
26
+ OrIconButton: __vue_component__$2,
27
+ OrMenuItem: __vue_component__$3,
28
+ OrMenu: __vue_component__$4,
29
+ OrPopover: __vue_component__$5
30
+ },
31
+ props: {
32
+ toolbar: {
33
+ type: Array,
34
+ default: () => []
35
+ },
36
+ isFocused: {
37
+ type: Boolean,
38
+ default: false
39
+ },
40
+ countOfNotVisibleTools: {
41
+ type: Number,
42
+ default: 0
43
+ },
44
+ activeHeadingLevel: {
45
+ type: Number,
46
+ default: 0
47
+ },
48
+ isActive: {
49
+ type: Object,
50
+ default: () => ({})
51
+ },
52
+ headingLevels: {
53
+ type: Array,
54
+ default: () => [1, 2, 3, 4]
55
+ }
56
+ },
57
+ emits: ['click-tool'],
58
+ setup(props, _ref) {
59
+ let {
60
+ emit
61
+ } = _ref;
62
+ const toolbarRef = ref();
63
+ const moreButtonRef = ref();
64
+ const moreRef = ref();
65
+ const toolbarButtonRef = ref();
66
+ const menuRef = ref();
67
+ const iconsEnum = ref({
68
+ bold: 'format_bold',
69
+ italic: 'format_italic',
70
+ underline: 'format_underlined',
71
+ strike: 'format_strikethrough',
72
+ bulletList: 'format_list_bulleted',
73
+ orderedList: 'format_list_numbered',
74
+ link: 'link',
75
+ highlight: 'highlight',
76
+ redo: 'redo',
77
+ undo: 'undo',
78
+ codeBlock: 'code_blocks',
79
+ blockquote: 'format_quote',
80
+ file: 'attach_file',
81
+ source: 'source_notes'
82
+ });
83
+ const iconTooltipsEnum = ref({
84
+ bold: 'Bold',
85
+ italic: 'Italic',
86
+ underline: 'Underline',
87
+ strike: 'Strike',
88
+ bulletList: 'Bulleted List',
89
+ orderedList: 'Numbered List',
90
+ link: 'Link',
91
+ highlight: 'Highlight',
92
+ redo: 'Redo',
93
+ undo: 'Undo',
94
+ codeBlock: 'Code Block',
95
+ blockquote: 'Quote',
96
+ file: 'File',
97
+ source: 'Source'
98
+ });
99
+ const notVisibleTools = computed(() => {
100
+ const count = props.countOfNotVisibleTools;
101
+ const toolbar = props.toolbar.flat();
102
+ let notVisible = new Set(toolbar.slice(toolbar.length - count, toolbar.length));
103
+ props.toolbar.forEach(tools => {
104
+ if (tools.some(item => notVisible.has(item))) {
105
+ tools.forEach(item => notVisible.add(item));
106
+ }
107
+ });
108
+ return notVisible;
109
+ });
110
+ const toolbarContainerStyles = computed(() => [...ToolbarContainer]);
111
+ const toolbarStyles = computed(() => [...Toolbar, ...(props.isFocused ? ToolbarButtonFocused : ToolbarButton)]);
112
+ const getIndexOfHeading = computed(() => {
113
+ return props.toolbar.flat().indexOf('heading');
114
+ });
115
+ const headingIcon = computed(() => {
116
+ if (props.activeHeadingLevel && props.isActive.heading) {
117
+ return `format_h${props.activeHeadingLevel}`;
118
+ }
119
+ return 'format_paragraph';
120
+ });
121
+ const isVisible = value => {
122
+ if (Array.isArray(value)) {
123
+ const isHaveNotVisibleTools = value.some(item => notVisibleTools.value.has(item));
124
+ return isHaveNotVisibleTools;
125
+ }
126
+ return !notVisibleTools.value.has(value);
127
+ };
128
+ const handleClick = (item, level) => {
129
+ emit('click-tool', {
130
+ item,
131
+ level
132
+ });
133
+ };
134
+ return {
135
+ toolbarRef,
136
+ moreButtonRef,
137
+ moreRef,
138
+ toolbarButtonRef,
139
+ menuRef,
140
+ toolbarContainerStyles,
141
+ toolbarStyles,
142
+ isVisible,
143
+ handleClick,
144
+ headingIcon,
145
+ getIndexOfHeading,
146
+ notVisibleTools,
147
+ iconsEnum,
148
+ iconTooltipsEnum
149
+ };
150
+ }
151
+ });
152
+
153
+ /* script */
154
+ const __vue_script__$1 = script$1;
155
+
156
+ /* template */
157
+ var __vue_render__$1 = function () {
158
+ var _vm = this;
159
+ var _h = _vm.$createElement;
160
+ var _c = _vm._self._c || _h;
161
+ return _c('div', {
162
+ ref: "toolbarRef",
163
+ class: _vm.toolbarContainerStyles
164
+ }, [_vm._l(_vm.toolbar, function (tools, index) {
165
+ return _c('div', {
166
+ key: index,
167
+ class: _vm.toolbarStyles.concat([{
168
+ 'hidden': _vm.isVisible(tools)
169
+ }])
170
+ }, _vm._l(tools, function (item) {
171
+ return _c('div', {
172
+ key: item,
173
+ class: ['flex gap-md', {
174
+ 'hidden': !_vm.isVisible(item)
175
+ }]
176
+ }, [item === 'heading' ? _c('or-icon-button', {
177
+ ref: "toolbarButtonRef",
178
+ refInFor: true,
179
+ attrs: {
180
+ "selected": _vm.isActive[item],
181
+ "disabled": !_vm.isFocused,
182
+ "tooltip": {
183
+ content: item,
184
+ placement: 'top'
185
+ },
186
+ "icon": {
187
+ icon: _vm.headingIcon,
188
+ variant: 'inherit'
189
+ }
190
+ },
191
+ on: {
192
+ "click": function ($event) {
193
+ _vm.menuRef && _vm.menuRef.toggle();
194
+ }
195
+ }
196
+ }) : _vm.isVisible(item) ? _c('or-icon-button', {
197
+ attrs: {
198
+ "tooltip": {
199
+ content: _vm.iconTooltipsEnum[item],
200
+ placement: 'top'
201
+ },
202
+ "selected": _vm.isActive[item],
203
+ "disabled": !_vm.isFocused,
204
+ "icon": {
205
+ icon: _vm.iconsEnum[item],
206
+ variant: 'inherit'
207
+ }
208
+ },
209
+ on: {
210
+ "click": function ($event) {
211
+ return _vm.handleClick(item);
212
+ }
213
+ }
214
+ }) : _vm._e()], 1);
215
+ }), 0);
216
+ }), _vm._v(" "), _vm.countOfNotVisibleTools > 0 ? _c('or-icon-button', {
217
+ ref: "moreButtonRef",
218
+ staticClass: "px-sm",
219
+ attrs: {
220
+ "disabled": !_vm.isFocused,
221
+ "icon": {
222
+ icon: 'more_horiz',
223
+ variant: 'inherit'
224
+ }
225
+ },
226
+ on: {
227
+ "click": function ($event) {
228
+ _vm.moreRef && _vm.moreRef.open();
229
+ }
230
+ }
231
+ }) : _vm._e(), _vm._v(" "), _vm.moreButtonRef ? _c('or-popover', {
232
+ ref: "moreRef",
233
+ attrs: {
234
+ "trigger": _vm.moreButtonRef && _vm.moreButtonRef.root,
235
+ "placement": "top-end"
236
+ }
237
+ }, [_c('div', {
238
+ staticClass: "flex p-sm gap-md"
239
+ }, _vm._l(_vm.notVisibleTools, function (item) {
240
+ return _c('or-icon-button', {
241
+ key: item,
242
+ attrs: {
243
+ "tooltip": {
244
+ content: _vm.iconTooltipsEnum[item],
245
+ placement: 'top'
246
+ },
247
+ "selected": _vm.isActive[item],
248
+ "icon": {
249
+ icon: _vm.iconsEnum[item],
250
+ variant: 'inherit'
251
+ }
252
+ },
253
+ on: {
254
+ "click": function ($event) {
255
+ return _vm.handleClick(item);
256
+ }
257
+ }
258
+ });
259
+ }), 1)]) : _vm._e(), _vm._v(" "), _vm.toolbarButtonRef ? _c('or-menu', {
260
+ ref: "menuRef",
261
+ attrs: {
262
+ "trigger": _vm.toolbarButtonRef[_vm.getIndexOfHeading] && _vm.toolbarButtonRef[_vm.getIndexOfHeading].root,
263
+ "placement": "bottom-start"
264
+ }
265
+ }, [_vm._l(_vm.headingLevels, function (heading) {
266
+ return _c('or-menu-item', {
267
+ key: heading,
268
+ attrs: {
269
+ "selected": _vm.activeHeadingLevel === heading
270
+ },
271
+ on: {
272
+ "click": function ($event) {
273
+ return _vm.handleClick('heading', heading);
274
+ }
275
+ }
276
+ }, [_vm._v("\n Heading " + _vm._s(heading) + "\n ")]);
277
+ }), _vm._v(" "), _c('or-menu-item', {
278
+ attrs: {
279
+ "selected": !_vm.activeHeadingLevel
280
+ },
281
+ on: {
282
+ "click": function ($event) {
283
+ return _vm.handleClick('heading');
284
+ }
285
+ }
286
+ }, [_vm._v("\n None\n ")])], 2) : _vm._e()], 2);
287
+ };
288
+ var __vue_staticRenderFns__$1 = [];
289
+
290
+ /* style */
291
+ const __vue_inject_styles__$1 = undefined;
292
+ /* scoped */
293
+ const __vue_scope_id__$1 = undefined;
294
+ /* module identifier */
295
+ const __vue_module_identifier__$1 = undefined;
296
+ /* functional template */
297
+ const __vue_is_functional_template__$1 = false;
298
+ /* style inject */
299
+
300
+ /* style inject SSR */
301
+
302
+ /* style inject shadow dom */
303
+
304
+ const __vue_component__$1 = /*#__PURE__*/normalizeComponent({
305
+ render: __vue_render__$1,
306
+ staticRenderFns: __vue_staticRenderFns__$1
307
+ }, __vue_inject_styles__$1, __vue_script__$1, __vue_scope_id__$1, __vue_is_functional_template__$1, __vue_module_identifier__$1, false, undefined, undefined, undefined);
308
+ var EditorToolbar = __vue_component__$1;
23
309
 
24
310
  const Heading = Node.create({
25
311
  name: 'heading',
@@ -1282,8 +1568,11 @@ const History = Extension.create({
1282
1568
  addKeyboardShortcuts() {
1283
1569
  return {
1284
1570
  'Mod-z': () => this.editor.commands.undo(),
1571
+ 'Mod-Z': () => this.editor.commands.undo(),
1285
1572
  'Mod-y': () => this.editor.commands.redo(),
1573
+ 'Mod-Y': () => this.editor.commands.redo(),
1286
1574
  'Shift-Mod-z': () => this.editor.commands.redo(),
1575
+ 'Shift-Mod-Z': () => this.editor.commands.redo(),
1287
1576
  // Russian keyboard layouts
1288
1577
  'Mod-я': () => this.editor.commands.undo(),
1289
1578
  'Shift-Mod-я': () => this.editor.commands.redo()
@@ -1314,11 +1603,23 @@ const HorizontalRule = Node.create({
1314
1603
  return {
1315
1604
  setHorizontalRule: () => _ref2 => {
1316
1605
  let {
1317
- chain
1606
+ chain,
1607
+ state
1318
1608
  } = _ref2;
1319
- return chain().insertContent({
1320
- type: this.name
1321
- })
1609
+ const {
1610
+ $to: $originTo
1611
+ } = state.selection;
1612
+ const currentChain = chain();
1613
+ if ($originTo.parentOffset === 0) {
1614
+ currentChain.insertContentAt(Math.max($originTo.pos - 2, 0), {
1615
+ type: this.name
1616
+ });
1617
+ } else {
1618
+ currentChain.insertContent({
1619
+ type: this.name
1620
+ });
1621
+ }
1622
+ return currentChain
1322
1623
  // set cursor after horizontal rule
1323
1624
  .command(_ref3 => {
1324
1625
  let {
@@ -1332,13 +1633,19 @@ const HorizontalRule = Node.create({
1332
1633
  } = tr.selection;
1333
1634
  const posAfter = $to.end();
1334
1635
  if ($to.nodeAfter) {
1335
- tr.setSelection(TextSelection.create(tr.doc, $to.pos));
1636
+ if ($to.nodeAfter.isTextblock) {
1637
+ tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1));
1638
+ } else if ($to.nodeAfter.isBlock) {
1639
+ tr.setSelection(NodeSelection.create(tr.doc, $to.pos));
1640
+ } else {
1641
+ tr.setSelection(TextSelection.create(tr.doc, $to.pos));
1642
+ }
1336
1643
  } else {
1337
1644
  // add node after horizontal rule if it’s the end of the document
1338
1645
  const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create();
1339
1646
  if (node) {
1340
1647
  tr.insert(posAfter, node);
1341
- tr.setSelection(TextSelection.create(tr.doc, posAfter));
1648
+ tr.setSelection(TextSelection.create(tr.doc, posAfter + 1));
1342
1649
  }
1343
1650
  }
1344
1651
  tr.scrollIntoView();
@@ -1427,16 +1734,13 @@ const StarterKit = Extension.create({
1427
1734
  var script = defineComponent({
1428
1735
  name: 'OrRichTextEditor',
1429
1736
  components: {
1430
- OrIconButton: __vue_component__$1,
1431
- OrLabel: __vue_component__$2,
1432
- OrMenuItem: __vue_component__$3,
1433
- OrMenu: __vue_component__$4,
1434
- OrModal: __vue_component__$5,
1435
- OrInput: __vue_component__$6,
1436
- OrButton: __vue_component__$7,
1437
- OrPopover: __vue_component__$8,
1737
+ OrModal: __vue_component__$6,
1738
+ OrInput: __vue_component__$7,
1739
+ OrButton: __vue_component__$8,
1438
1740
  OrHint: __vue_component__$9,
1439
- OrError: __vue_component__$a
1741
+ OrError: __vue_component__$a,
1742
+ OrLabel: __vue_component__$b,
1743
+ EditorToolbar
1440
1744
  },
1441
1745
  model: {
1442
1746
  prop: 'modelValue',
@@ -1482,6 +1786,10 @@ var script = defineComponent({
1482
1786
  error: {
1483
1787
  type: [String, Boolean],
1484
1788
  default: undefined
1789
+ },
1790
+ readonly: {
1791
+ type: Boolean,
1792
+ default: false
1485
1793
  }
1486
1794
  },
1487
1795
  emits: ['update:modelValue', 'input', 'file-upload'],
@@ -1493,11 +1801,7 @@ var script = defineComponent({
1493
1801
  const editorRef = ref();
1494
1802
  const textareaRef = ref();
1495
1803
  const containerRef = ref();
1496
- const toolbarRef = ref();
1497
- const moreButtonRef = ref();
1498
- const moreRef = ref();
1499
- const toolbarButtonRef = ref();
1500
- const menuRef = ref();
1804
+ const toolbarContainerRef = ref();
1501
1805
  // isActive should be set with default values for all toolbar buttons, otherwise it will not work in vue2
1502
1806
  const isActive = ref({
1503
1807
  bold: false,
@@ -1515,7 +1819,7 @@ var script = defineComponent({
1515
1819
  file: false,
1516
1820
  source: false
1517
1821
  });
1518
- const isFocused = ref(props.autofocus);
1822
+ const isFocused = ref(!props.readonly ? props.autofocus : false);
1519
1823
  const headingLevels = [1, 2, 3, 4];
1520
1824
  const activeHeadingLevel = ref(0);
1521
1825
  const markdownOutput = ref('');
@@ -1530,49 +1834,19 @@ var script = defineComponent({
1530
1834
  fallbackFocus: '.container',
1531
1835
  allowOutsideClick: true
1532
1836
  });
1533
- const iconsEnum = ref({
1534
- bold: 'format_bold',
1535
- italic: 'format_italic',
1536
- underline: 'format_underlined',
1537
- strike: 'format_strikethrough',
1538
- bulletList: 'format_list_bulleted',
1539
- orderedList: 'format_list_numbered',
1540
- link: 'link',
1541
- highlight: 'highlight',
1542
- redo: 'redo',
1543
- undo: 'undo',
1544
- codeBlock: 'code_blocks',
1545
- blockquote: 'format_quote',
1546
- file: 'attach_file',
1547
- source: 'source_notes'
1548
- });
1549
- const iconTooltipsEnum = ref({
1550
- bold: 'Bold',
1551
- italic: 'Italic',
1552
- underline: 'Underline',
1553
- strike: 'Strike',
1554
- bulletList: 'Bulleted List',
1555
- orderedList: 'Numbered List',
1556
- link: 'Link',
1557
- highlight: 'Highlight',
1558
- redo: 'Redo',
1559
- undo: 'Undo',
1560
- codeBlock: 'Code Block',
1561
- blockquote: 'Quote',
1562
- file: 'File',
1563
- source: 'Source'
1564
- });
1565
1837
  useResizeObserver(root, useDebounceFn(entries => {
1566
1838
  var _a, _b;
1567
1839
  const entry = entries[0];
1568
1840
  const {
1569
1841
  width
1570
1842
  } = entry.contentRect;
1571
- if (containerRef.value && toolbarRef.value && toolbarLength.value) {
1843
+ const toolbarLength = props.toolbar.flat().length;
1844
+ if (containerRef.value && toolbarContainerRef.value && toolbarLength) {
1572
1845
  let lengthOfItem = 0;
1573
- lengthOfItem = ((_b = (_a = toolbarRef.value.firstElementChild) === null || _a === void 0 ? void 0 : _a.firstElementChild) === null || _b === void 0 ? void 0 : _b.offsetWidth) + 16;
1846
+ const toolbarRef = toolbarContainerRef.value.$refs.toolbarRef;
1847
+ lengthOfItem = ((_b = (_a = toolbarRef === null || toolbarRef === void 0 ? void 0 : toolbarRef.firstElementChild) === null || _a === void 0 ? void 0 : _a.firstElementChild) === null || _b === void 0 ? void 0 : _b.offsetWidth) + 16;
1574
1848
  const count = width / lengthOfItem - 2;
1575
- countOfNotVisibleTools.value = Math.round(toolbarLength.value - count);
1849
+ countOfNotVisibleTools.value = Math.round(toolbarLength - count);
1576
1850
  }
1577
1851
  }, 10));
1578
1852
  onMounted(() => {
@@ -1604,7 +1878,8 @@ var script = defineComponent({
1604
1878
  }
1605
1879
  },
1606
1880
  element: editorRef.value,
1607
- autofocus: props.autofocus,
1881
+ autofocus: !props.readonly ? props.autofocus : false,
1882
+ editable: !props.readonly,
1608
1883
  enableInputRules: true,
1609
1884
  enablePasteRules: true,
1610
1885
  extensions: [codemirrorNode, StarterKit.configure({
@@ -1685,43 +1960,15 @@ var script = defineComponent({
1685
1960
  context.emit('update:modelValue', value);
1686
1961
  }
1687
1962
  });
1688
- const getIndexOfHeading = computed(() => {
1689
- return props.toolbar.flat().indexOf('heading');
1690
- });
1691
- const headingIcon = computed(() => {
1692
- if (activeHeadingLevel.value && isActive.value.heading) {
1693
- return `format_h${activeHeadingLevel.value}`;
1694
- }
1695
- return 'format_paragraph';
1696
- });
1697
- const toolbarLength = computed(() => {
1698
- return props.toolbar.flat().length;
1699
- });
1700
- const notVisibleTools = computed(() => {
1701
- const count = countOfNotVisibleTools.value;
1702
- const toolbar = props.toolbar.flat();
1703
- let notVisible = new Set(toolbar.slice(toolbar.length - count, toolbar.length));
1704
- props.toolbar.forEach(tools => {
1705
- if (tools.some(item => notVisible.has(item))) {
1706
- tools.forEach(item => notVisible.add(item));
1707
- }
1708
- });
1709
- return notVisible;
1710
- });
1711
1963
  //Methods
1712
1964
  const handleEditorClick = () => {
1713
1965
  var _a;
1714
1966
  setActiveFormats();
1715
- isFocused.value = true;
1716
- editor === null || editor === void 0 ? void 0 : editor.commands.focus();
1717
- activeHeadingLevel.value = ((_a = editor === null || editor === void 0 ? void 0 : editor.getAttributes('heading')) === null || _a === void 0 ? void 0 : _a.level) || 0;
1718
- };
1719
- const isVisible = value => {
1720
- if (Array.isArray(value)) {
1721
- const isHaveNotVisibleTools = value.some(item => notVisibleTools.value.has(item));
1722
- return isHaveNotVisibleTools;
1967
+ if (!props.readonly) {
1968
+ isFocused.value = true;
1969
+ editor === null || editor === void 0 ? void 0 : editor.commands.focus();
1723
1970
  }
1724
- return !notVisibleTools.value.has(value);
1971
+ activeHeadingLevel.value = ((_a = editor === null || editor === void 0 ? void 0 : editor.getAttributes('heading')) === null || _a === void 0 ? void 0 : _a.level) || 0;
1725
1972
  };
1726
1973
  const handleInput = event => {
1727
1974
  const target = event.target;
@@ -1730,7 +1977,11 @@ var script = defineComponent({
1730
1977
  markdownOutput.value = serialize(editor === null || editor === void 0 ? void 0 : editor.schema, editor === null || editor === void 0 ? void 0 : editor.getJSON());
1731
1978
  proxyModelValue.value = markdownOutput.value;
1732
1979
  };
1733
- const handleToolbarClick = (item, level) => {
1980
+ const handleToolbarClick = _ref4 => {
1981
+ let {
1982
+ item,
1983
+ level
1984
+ } = _ref4;
1734
1985
  var _a, _b, _c, _d;
1735
1986
  switch (item) {
1736
1987
  case 'source':
@@ -1810,10 +2061,10 @@ var script = defineComponent({
1810
2061
  editor === null || editor === void 0 ? void 0 : editor.chain().focus().setMark('link', {
1811
2062
  href: link.value,
1812
2063
  target: '__blank'
1813
- }).command(_ref4 => {
2064
+ }).command(_ref5 => {
1814
2065
  let {
1815
2066
  tr
1816
- } = _ref4;
2067
+ } = _ref5;
1817
2068
  const preparedValue = text.value[text.value.length - 1] === ' ' ? text.value : `${text.value} `;
1818
2069
  tr.insertText(preparedValue);
1819
2070
  return true;
@@ -1849,11 +2100,7 @@ var script = defineComponent({
1849
2100
  };
1850
2101
  // Styles
1851
2102
  const rootStyles = computed(() => ['or-rich-text-editor-v3', ...OrRichTextEditor]);
1852
- const containerStyles = computed(() => [...EditorContainer]);
1853
- const toolbarContainerStyles = computed(() => [...ToolbarContainer]);
1854
- const toolbarStyles = computed(() => [...Toolbar,
1855
- // 'overflow-x-hidden',
1856
- ...(isFocused.value ? ToolbarButtonFocused : ToolbarButton)]);
2103
+ const containerStyles = computed(() => [...EditorContainer, ...(isFocused.value ? EditorContainerFocus : [])]);
1857
2104
  const editorInputStyles = computed(() => ['tiptap-editor-v3', ...EditorInput]);
1858
2105
  //Effects
1859
2106
  watch(proxyModelValue, value => {
@@ -1861,43 +2108,38 @@ var script = defineComponent({
1861
2108
  editor === null || editor === void 0 ? void 0 : editor.commands.setContent(value);
1862
2109
  }
1863
2110
  if (props.format === 'markdown' && value !== markdownOutput.value) {
1864
- //TODO: const deserialized = deserialize(editor?.schema, value);
1865
- editor === null || editor === void 0 ? void 0 : editor.commands.setContent(value);
2111
+ const deserialized = deserialize(editor === null || editor === void 0 ? void 0 : editor.schema, value);
2112
+ editor === null || editor === void 0 ? void 0 : editor.commands.setContent(deserialized);
1866
2113
  }
1867
2114
  });
2115
+ watch(props, _ref6 => {
2116
+ let {
2117
+ readonly
2118
+ } = _ref6;
2119
+ isFocused.value = !readonly;
2120
+ editor === null || editor === void 0 ? void 0 : editor.setEditable(!readonly);
2121
+ });
1868
2122
  return {
1869
2123
  editor,
1870
2124
  editorRef,
1871
- toolbarRef,
2125
+ toolbarContainerRef,
1872
2126
  containerRef,
1873
- toolbarButtonRef,
1874
- moreButtonRef,
1875
2127
  textareaRef,
1876
- moreRef,
1877
- menuRef,
1878
- iconsEnum,
1879
2128
  handleToolbarClick,
1880
2129
  handleEditorClick,
1881
2130
  isActive,
1882
- iconTooltipsEnum,
1883
2131
  containerStyles,
1884
- toolbarContainerStyles,
1885
- toolbarStyles,
1886
2132
  rootStyles,
1887
2133
  root,
1888
2134
  editorInputStyles,
1889
- getIndexOfHeading,
1890
2135
  headingLevels,
1891
- headingIcon,
1892
2136
  attachLink,
1893
2137
  discardLink,
1894
2138
  isOpenLinkModal,
1895
2139
  text,
1896
2140
  link,
1897
2141
  isFocused,
1898
- isVisible,
1899
2142
  countOfNotVisibleTools,
1900
- notVisibleTools,
1901
2143
  handleInput,
1902
2144
  proxyModelValue,
1903
2145
  disableMarkdown,
@@ -1934,7 +2176,7 @@ var __vue_render__ = function () {
1934
2176
  }, [_vm._t("label", function () {
1935
2177
  return [_vm._v("\n " + _vm._s(_vm.label) + "\n ")];
1936
2178
  })], 2)] : _vm._e(), _vm._v(" "), _c('div', {
1937
- ref: 'containerRef',
2179
+ ref: "containerRef",
1938
2180
  class: _vm.containerStyles,
1939
2181
  attrs: {
1940
2182
  "invalid": !!_vm.error
@@ -1944,77 +2186,20 @@ var __vue_render__ = function () {
1944
2186
  return _vm.handleEditorClick();
1945
2187
  }
1946
2188
  }
1947
- }, [_c('div', {
1948
- ref: 'toolbarRef',
1949
- class: _vm.toolbarContainerStyles
1950
- }, [_vm._l(_vm.toolbar, function (tools, index) {
1951
- return _c('div', {
1952
- key: index,
1953
- class: _vm.toolbarStyles.concat([{
1954
- 'hidden': _vm.isVisible(tools)
1955
- }])
1956
- }, _vm._l(tools, function (item) {
1957
- return _c('div', {
1958
- key: item,
1959
- class: ['flex gap-md', {
1960
- 'hidden': !_vm.isVisible(item)
1961
- }]
1962
- }, [item === 'heading' ? _c('or-icon-button', {
1963
- ref: 'toolbarButtonRef',
1964
- refInFor: true,
1965
- attrs: {
1966
- "selected": _vm.isActive[item],
1967
- "disabled": !_vm.isFocused,
1968
- "tooltip": {
1969
- content: item,
1970
- placement: 'top'
1971
- },
1972
- "icon": {
1973
- icon: _vm.headingIcon,
1974
- variant: 'inherit'
1975
- }
1976
- },
1977
- on: {
1978
- "click": function ($event) {
1979
- _vm.menuRef && _vm.menuRef.toggle();
1980
- }
1981
- }
1982
- }) : _vm.isVisible(item) ? _c('or-icon-button', {
1983
- attrs: {
1984
- "tooltip": {
1985
- content: _vm.iconTooltipsEnum[item],
1986
- placement: 'top'
1987
- },
1988
- "selected": _vm.isActive[item],
1989
- "disabled": !_vm.isFocused,
1990
- "icon": {
1991
- icon: _vm.iconsEnum[item],
1992
- variant: 'inherit'
1993
- }
1994
- },
1995
- on: {
1996
- "click": function ($event) {
1997
- return _vm.handleToolbarClick(item);
1998
- }
1999
- }
2000
- }) : _vm._e()], 1);
2001
- }), 0);
2002
- }), _vm._v(" "), _vm.countOfNotVisibleTools > 0 ? _c('or-icon-button', {
2003
- ref: 'moreButtonRef',
2004
- staticClass: "px-sm",
2189
+ }, [!_vm.readonly ? _c('editor-toolbar', {
2190
+ ref: "toolbarContainerRef",
2005
2191
  attrs: {
2006
- "disabled": !_vm.isFocused,
2007
- "icon": {
2008
- icon: 'more_horiz',
2009
- variant: 'inherit'
2010
- }
2192
+ "count-of-not-visible-tools": _vm.countOfNotVisibleTools,
2193
+ "toolbar": _vm.toolbar,
2194
+ "is-focused": _vm.isFocused,
2195
+ "active-heading-level": _vm.activeHeadingLevel,
2196
+ "is-active": _vm.isActive,
2197
+ "heading-levels": _vm.headingLevels
2011
2198
  },
2012
2199
  on: {
2013
- "click": function ($event) {
2014
- _vm.moreRef && _vm.moreRef.open();
2015
- }
2200
+ "click-tool": _vm.handleToolbarClick
2016
2201
  }
2017
- }) : _vm._e()], 2), _vm._v(" "), _c('div', {
2202
+ }) : _vm._e(), _vm._v(" "), _c('div', {
2018
2203
  class: ['p-sm', 'overflow-auto', 'min-h-[88px]']
2019
2204
  }, [_c('textarea', {
2020
2205
  directives: [{
@@ -2051,9 +2236,9 @@ var __vue_render__ = function () {
2051
2236
  value: !_vm.disableMarkdown,
2052
2237
  expression: "!disableMarkdown"
2053
2238
  }],
2054
- ref: 'editorRef',
2239
+ ref: "editorRef",
2055
2240
  class: _vm.editorInputStyles
2056
- }), _vm._v(" "), _vm._t("files")], 2)]), _vm._v(" "), !_vm.error ? [_vm.$slots.hint || _vm.hint ? [_c('OrHint', {
2241
+ }), _vm._v(" "), _vm._t("files")], 2)], 1), _vm._v(" "), !_vm.error ? [_vm.$slots.hint || _vm.hint ? [_c('OrHint', {
2057
2242
  attrs: {
2058
2243
  "disabled": _vm.disabled
2059
2244
  }
@@ -2063,62 +2248,7 @@ var __vue_render__ = function () {
2063
2248
  attrs: {
2064
2249
  "disabled": _vm.disabled
2065
2250
  }
2066
- }, [_vm._v("\n " + _vm._s(_vm.error) + "\n ")])] : _vm._e(), _vm._v(" "), _vm.moreButtonRef ? _c('or-popover', {
2067
- ref: 'moreRef',
2068
- attrs: {
2069
- "trigger": _vm.moreButtonRef && _vm.moreButtonRef.root,
2070
- "placement": "top-end"
2071
- }
2072
- }, [_c('div', {
2073
- staticClass: "flex p-sm gap-md"
2074
- }, _vm._l(_vm.notVisibleTools, function (item) {
2075
- return _c('or-icon-button', {
2076
- key: item,
2077
- attrs: {
2078
- "tooltip": {
2079
- content: _vm.iconTooltipsEnum[item],
2080
- placement: 'top'
2081
- },
2082
- "selected": _vm.isActive[item],
2083
- "icon": {
2084
- icon: _vm.iconsEnum[item],
2085
- variant: 'inherit'
2086
- }
2087
- },
2088
- on: {
2089
- "click": function ($event) {
2090
- return _vm.handleToolbarClick(item);
2091
- }
2092
- }
2093
- });
2094
- }), 1)]) : _vm._e(), _vm._v(" "), _vm.toolbarButtonRef ? _c('or-menu', {
2095
- ref: 'menuRef',
2096
- attrs: {
2097
- "trigger": _vm.toolbarButtonRef[_vm.getIndexOfHeading] && _vm.toolbarButtonRef[_vm.getIndexOfHeading].root,
2098
- "placement": "bottom-start"
2099
- }
2100
- }, [_vm._l(_vm.headingLevels, function (heading) {
2101
- return _c('or-menu-item', {
2102
- key: heading,
2103
- attrs: {
2104
- "selected": _vm.activeHeadingLevel === heading
2105
- },
2106
- on: {
2107
- "click": function ($event) {
2108
- return _vm.handleToolbarClick('heading', heading);
2109
- }
2110
- }
2111
- }, [_vm._v("\n Heading " + _vm._s(heading) + "\n ")]);
2112
- }), _vm._v(" "), _c('or-menu-item', {
2113
- attrs: {
2114
- "selected": !_vm.activeHeadingLevel
2115
- },
2116
- on: {
2117
- "click": function ($event) {
2118
- return _vm.handleToolbarClick('heading');
2119
- }
2120
- }
2121
- }, [_vm._v("\n None\n ")])], 2) : _vm._e(), _vm._v(" "), _c('or-modal', {
2251
+ }, [_vm._v("\n " + _vm._s(_vm.error) + "\n ")])] : _vm._e(), _vm._v(" "), _c('or-modal', {
2122
2252
  attrs: {
2123
2253
  "is-open": _vm.isOpenLinkModal,
2124
2254
  "size": "s"