@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,6 +1,6 @@
1
1
  import { useResizeObserver, useDebounceFn, onClickOutside } from '@vueuse/core';
2
2
  import { useFocusTrap } from '@vueuse/integrations/useFocusTrap';
3
- import { defineComponent, ref, onMounted, onBeforeUnmount, computed, watch, nextTick } from 'vue-demi';
3
+ import { defineComponent, ref, computed, onMounted, onBeforeUnmount, watch, nextTick } from 'vue-demi';
4
4
  import { defaultMarkdownSerializer, MarkdownSerializer } from 'prosemirror-markdown';
5
5
  import { DOMParser as DOMParser$1 } from 'prosemirror-model';
6
6
  import Paragraph from '@tiptap/extension-paragraph';
@@ -16,18 +16,19 @@ import Blockquote from '@tiptap/extension-blockquote';
16
16
  import Link from '@tiptap/extension-link';
17
17
  import Highlight from '@tiptap/extension-highlight';
18
18
  import Underline from '@tiptap/extension-underline';
19
- import { _ as __vue_component__$7 } from './OrButton-e4e85817.js';
20
- import './OrButton.vue_rollup-plugin-vue_script-199bb600.js';
21
- import { _ as __vue_component__$1 } from './OrIconButton-5a905423.js';
22
- import { _ as __vue_component__$6 } from './OrInput-a32b517e.js';
23
- import { _ as __vue_component__$2 } from './OrLabel-b0805497.js';
19
+ import { _ as __vue_component__$2 } from './OrIconButton-5a905423.js';
24
20
  import { _ as __vue_component__$3 } from './OrMenuItem-9ccf816f.js';
25
21
  import { _ as __vue_component__$4 } from './OrMenu-b3a9fcfb.js';
26
- import { _ as __vue_component__$5 } from './OrModal-d3f7a508.js';
27
- import { _ as __vue_component__$8 } from './OrPopover-f624356f.js';
22
+ import { _ as __vue_component__$5 } from './OrPopover-f624356f.js';
28
23
  import './dom-53c9635b.js';
24
+ import { n as normalizeComponent } from './normalize-component-6e8e3d80.js';
25
+ import { _ as __vue_component__$8 } from './OrButton-e4e85817.js';
26
+ import './OrButton.vue_rollup-plugin-vue_script-199bb600.js';
27
+ import { _ as __vue_component__$7 } from './OrInput-a32b517e.js';
28
+ import { _ as __vue_component__$6 } from './OrModal-d3f7a508.js';
29
29
  import { _ as __vue_component__$9 } from './OrHint-2fe1157b.js';
30
30
  import { _ as __vue_component__$a } from './OrError-b25d782d.js';
31
+ import { _ as __vue_component__$b } from './OrLabel-b0805497.js';
31
32
  import { Node, Editor, mergeAttributes } from '@tiptap/core';
32
33
  import Heading from '@tiptap/extension-heading';
33
34
  import Placeholder from '@tiptap/extension-placeholder';
@@ -36,7 +37,6 @@ import { C as CodeMirrorView } from './codemirrorView-020fe885.js';
36
37
  import { minimalSetup } from 'codemirror';
37
38
  import { javascript } from '@codemirror/lang-javascript';
38
39
  import { s as styleInject } from './style-inject.es-4c6f2515.js';
39
- import { n as normalizeComponent } from './normalize-component-6e8e3d80.js';
40
40
 
41
41
  const serializerNodes = {
42
42
  ...defaultMarkdownSerializer.nodes,
@@ -163,16 +163,17 @@ const OrRichTextEditor = [
163
163
  // Spacing
164
164
  'gap-xs',
165
165
  // Box
166
- 'max-h-full'];
166
+ 'max-h-full', 'w-full'];
167
167
  const EditorContainer = [
168
168
  // Layout
169
169
  'layout-column',
170
- // Theme (focus)
171
- 'focus-within:theme-background-primary-translucent-1', 'dark:focus-within:theme-background-primary-translucent-1-dark', 'focus-within:theme-border-1-primary', 'dark:focus-within:theme-border-1-primary-dark', 'focus-within:theme-outline-2-primary', 'dark:focus-within:theme-outline-2-primary-dark',
172
170
  // Theme (invalid)
173
171
  'invalid:theme-background-error-translucent-1', 'dark:invalid:theme-background-error-translucent-1-dark', 'invalid:theme-foreground-default', 'dark:invalid:theme-foreground-default-dark', 'invalid:theme-border-1-error', 'dark:invalid:theme-border-1-error-dark', 'invalid:theme-outline-2-transparent', 'dark:invalid:theme-outline-2-transparent',
174
172
  // Box
175
173
  'border-1', 'rounded-md', 'w-full', 'overflow-hidden', 'grow'];
174
+ const EditorContainerFocus = [
175
+ // Theme (focus)
176
+ 'focus-within:theme-background-primary-translucent-1', 'dark:focus-within:theme-background-primary-translucent-1-dark', 'focus-within:theme-border-1-primary', 'dark:focus-within:theme-border-1-primary-dark', 'focus-within:theme-outline-2-primary', 'dark:focus-within:theme-outline-2-primary-dark'];
176
177
  const ToolbarContainer = [
177
178
  // Layout
178
179
  'layout-row',
@@ -203,6 +204,291 @@ const EditorInput = [
203
204
  // Typography
204
205
  'typography-body-2-regular'];
205
206
 
207
+ var script$1 = defineComponent({
208
+ components: {
209
+ OrIconButton: __vue_component__$2,
210
+ OrMenuItem: __vue_component__$3,
211
+ OrMenu: __vue_component__$4,
212
+ OrPopover: __vue_component__$5
213
+ },
214
+ props: {
215
+ toolbar: {
216
+ type: Array,
217
+ default: () => []
218
+ },
219
+ isFocused: {
220
+ type: Boolean,
221
+ default: false
222
+ },
223
+ countOfNotVisibleTools: {
224
+ type: Number,
225
+ default: 0
226
+ },
227
+ activeHeadingLevel: {
228
+ type: Number,
229
+ default: 0
230
+ },
231
+ isActive: {
232
+ type: Object,
233
+ default: () => ({})
234
+ },
235
+ headingLevels: {
236
+ type: Array,
237
+ default: () => [1, 2, 3, 4]
238
+ }
239
+ },
240
+ emits: ['click-tool'],
241
+ setup(props, _ref) {
242
+ let {
243
+ emit
244
+ } = _ref;
245
+ const toolbarRef = ref();
246
+ const moreButtonRef = ref();
247
+ const moreRef = ref();
248
+ const toolbarButtonRef = ref();
249
+ const menuRef = ref();
250
+ const iconsEnum = ref({
251
+ bold: 'format_bold',
252
+ italic: 'format_italic',
253
+ underline: 'format_underlined',
254
+ strike: 'format_strikethrough',
255
+ bulletList: 'format_list_bulleted',
256
+ orderedList: 'format_list_numbered',
257
+ link: 'link',
258
+ highlight: 'highlight',
259
+ redo: 'redo',
260
+ undo: 'undo',
261
+ codeBlock: 'code_blocks',
262
+ blockquote: 'format_quote',
263
+ file: 'attach_file',
264
+ source: 'source_notes'
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
+ file: 'File',
280
+ source: 'Source'
281
+ });
282
+ const notVisibleTools = computed(() => {
283
+ const count = props.countOfNotVisibleTools;
284
+ const toolbar = props.toolbar.flat();
285
+ let notVisible = new Set(toolbar.slice(toolbar.length - count, toolbar.length));
286
+ props.toolbar.forEach(tools => {
287
+ if (tools.some(item => notVisible.has(item))) {
288
+ tools.forEach(item => notVisible.add(item));
289
+ }
290
+ });
291
+ return notVisible;
292
+ });
293
+ const toolbarContainerStyles = computed(() => [...ToolbarContainer]);
294
+ const toolbarStyles = computed(() => [...Toolbar, ...(props.isFocused ? ToolbarButtonFocused : ToolbarButton)]);
295
+ const getIndexOfHeading = computed(() => {
296
+ return props.toolbar.flat().indexOf('heading');
297
+ });
298
+ const headingIcon = computed(() => {
299
+ if (props.activeHeadingLevel && props.isActive.heading) {
300
+ return `format_h${props.activeHeadingLevel}`;
301
+ }
302
+ return 'format_paragraph';
303
+ });
304
+ const isVisible = value => {
305
+ if (Array.isArray(value)) {
306
+ const isHaveNotVisibleTools = value.some(item => notVisibleTools.value.has(item));
307
+ return isHaveNotVisibleTools;
308
+ }
309
+ return !notVisibleTools.value.has(value);
310
+ };
311
+ const handleClick = (item, level) => {
312
+ emit('click-tool', {
313
+ item,
314
+ level
315
+ });
316
+ };
317
+ return {
318
+ toolbarRef,
319
+ moreButtonRef,
320
+ moreRef,
321
+ toolbarButtonRef,
322
+ menuRef,
323
+ toolbarContainerStyles,
324
+ toolbarStyles,
325
+ isVisible,
326
+ handleClick,
327
+ headingIcon,
328
+ getIndexOfHeading,
329
+ notVisibleTools,
330
+ iconsEnum,
331
+ iconTooltipsEnum
332
+ };
333
+ }
334
+ });
335
+
336
+ /* script */
337
+ const __vue_script__$1 = script$1;
338
+
339
+ /* template */
340
+ var __vue_render__$1 = function () {
341
+ var _vm = this;
342
+ var _h = _vm.$createElement;
343
+ var _c = _vm._self._c || _h;
344
+ return _c('div', {
345
+ ref: "toolbarRef",
346
+ class: _vm.toolbarContainerStyles
347
+ }, [_vm._l(_vm.toolbar, function (tools, index) {
348
+ return _c('div', {
349
+ key: index,
350
+ class: _vm.toolbarStyles.concat([{
351
+ 'hidden': _vm.isVisible(tools)
352
+ }])
353
+ }, _vm._l(tools, function (item) {
354
+ return _c('div', {
355
+ key: item,
356
+ class: ['flex gap-md', {
357
+ 'hidden': !_vm.isVisible(item)
358
+ }]
359
+ }, [item === 'heading' ? _c('or-icon-button', {
360
+ ref: "toolbarButtonRef",
361
+ refInFor: true,
362
+ attrs: {
363
+ "selected": _vm.isActive[item],
364
+ "disabled": !_vm.isFocused,
365
+ "tooltip": {
366
+ content: item,
367
+ placement: 'top'
368
+ },
369
+ "icon": {
370
+ icon: _vm.headingIcon,
371
+ variant: 'inherit'
372
+ }
373
+ },
374
+ on: {
375
+ "click": function ($event) {
376
+ _vm.menuRef && _vm.menuRef.toggle();
377
+ }
378
+ }
379
+ }) : _vm.isVisible(item) ? _c('or-icon-button', {
380
+ attrs: {
381
+ "tooltip": {
382
+ content: _vm.iconTooltipsEnum[item],
383
+ placement: 'top'
384
+ },
385
+ "selected": _vm.isActive[item],
386
+ "disabled": !_vm.isFocused,
387
+ "icon": {
388
+ icon: _vm.iconsEnum[item],
389
+ variant: 'inherit'
390
+ }
391
+ },
392
+ on: {
393
+ "click": function ($event) {
394
+ return _vm.handleClick(item);
395
+ }
396
+ }
397
+ }) : _vm._e()], 1);
398
+ }), 0);
399
+ }), _vm._v(" "), _vm.countOfNotVisibleTools > 0 ? _c('or-icon-button', {
400
+ ref: "moreButtonRef",
401
+ staticClass: "px-sm",
402
+ attrs: {
403
+ "disabled": !_vm.isFocused,
404
+ "icon": {
405
+ icon: 'more_horiz',
406
+ variant: 'inherit'
407
+ }
408
+ },
409
+ on: {
410
+ "click": function ($event) {
411
+ _vm.moreRef && _vm.moreRef.open();
412
+ }
413
+ }
414
+ }) : _vm._e(), _vm._v(" "), _vm.moreButtonRef ? _c('or-popover', {
415
+ ref: "moreRef",
416
+ attrs: {
417
+ "trigger": _vm.moreButtonRef && _vm.moreButtonRef.root,
418
+ "placement": "top-end"
419
+ }
420
+ }, [_c('div', {
421
+ staticClass: "flex p-sm gap-md"
422
+ }, _vm._l(_vm.notVisibleTools, function (item) {
423
+ return _c('or-icon-button', {
424
+ key: item,
425
+ attrs: {
426
+ "tooltip": {
427
+ content: _vm.iconTooltipsEnum[item],
428
+ placement: 'top'
429
+ },
430
+ "selected": _vm.isActive[item],
431
+ "icon": {
432
+ icon: _vm.iconsEnum[item],
433
+ variant: 'inherit'
434
+ }
435
+ },
436
+ on: {
437
+ "click": function ($event) {
438
+ return _vm.handleClick(item);
439
+ }
440
+ }
441
+ });
442
+ }), 1)]) : _vm._e(), _vm._v(" "), _vm.toolbarButtonRef ? _c('or-menu', {
443
+ ref: "menuRef",
444
+ attrs: {
445
+ "trigger": _vm.toolbarButtonRef[_vm.getIndexOfHeading] && _vm.toolbarButtonRef[_vm.getIndexOfHeading].root,
446
+ "placement": "bottom-start"
447
+ }
448
+ }, [_vm._l(_vm.headingLevels, function (heading) {
449
+ return _c('or-menu-item', {
450
+ key: heading,
451
+ attrs: {
452
+ "selected": _vm.activeHeadingLevel === heading
453
+ },
454
+ on: {
455
+ "click": function ($event) {
456
+ return _vm.handleClick('heading', heading);
457
+ }
458
+ }
459
+ }, [_vm._v("\n Heading " + _vm._s(heading) + "\n ")]);
460
+ }), _vm._v(" "), _c('or-menu-item', {
461
+ attrs: {
462
+ "selected": !_vm.activeHeadingLevel
463
+ },
464
+ on: {
465
+ "click": function ($event) {
466
+ return _vm.handleClick('heading');
467
+ }
468
+ }
469
+ }, [_vm._v("\n None\n ")])], 2) : _vm._e()], 2);
470
+ };
471
+ var __vue_staticRenderFns__$1 = [];
472
+
473
+ /* style */
474
+ const __vue_inject_styles__$1 = undefined;
475
+ /* scoped */
476
+ const __vue_scope_id__$1 = undefined;
477
+ /* module identifier */
478
+ const __vue_module_identifier__$1 = undefined;
479
+ /* functional template */
480
+ const __vue_is_functional_template__$1 = false;
481
+ /* style inject */
482
+
483
+ /* style inject SSR */
484
+
485
+ /* style inject shadow dom */
486
+
487
+ const __vue_component__$1 = /*#__PURE__*/normalizeComponent({
488
+ render: __vue_render__$1,
489
+ staticRenderFns: __vue_staticRenderFns__$1
490
+ }, __vue_inject_styles__$1, __vue_script__$1, __vue_scope_id__$1, __vue_is_functional_template__$1, __vue_module_identifier__$1, false, undefined, undefined, undefined);
491
+
206
492
  var Formats;
207
493
  (function (Formats) {
208
494
  Formats["Markdown"] = "markdown";
@@ -248,16 +534,13 @@ var codemirrorNode = Node.create({
248
534
  var script = defineComponent({
249
535
  name: 'OrRichTextEditor',
250
536
  components: {
251
- OrIconButton: __vue_component__$1,
252
- OrLabel: __vue_component__$2,
253
- OrMenuItem: __vue_component__$3,
254
- OrMenu: __vue_component__$4,
255
- OrModal: __vue_component__$5,
256
- OrInput: __vue_component__$6,
257
- OrButton: __vue_component__$7,
258
- OrPopover: __vue_component__$8,
537
+ OrModal: __vue_component__$6,
538
+ OrInput: __vue_component__$7,
539
+ OrButton: __vue_component__$8,
259
540
  OrHint: __vue_component__$9,
260
- OrError: __vue_component__$a
541
+ OrError: __vue_component__$a,
542
+ OrLabel: __vue_component__$b,
543
+ EditorToolbar: __vue_component__$1
261
544
  },
262
545
  model: {
263
546
  prop: 'modelValue',
@@ -303,6 +586,10 @@ var script = defineComponent({
303
586
  error: {
304
587
  type: [String, Boolean],
305
588
  default: undefined
589
+ },
590
+ readonly: {
591
+ type: Boolean,
592
+ default: false
306
593
  }
307
594
  },
308
595
  emits: ['update:modelValue', 'input', 'file-upload'],
@@ -314,11 +601,7 @@ var script = defineComponent({
314
601
  const editorRef = ref();
315
602
  const textareaRef = ref();
316
603
  const containerRef = ref();
317
- const toolbarRef = ref();
318
- const moreButtonRef = ref();
319
- const moreRef = ref();
320
- const toolbarButtonRef = ref();
321
- const menuRef = ref();
604
+ const toolbarContainerRef = ref();
322
605
  // isActive should be set with default values for all toolbar buttons, otherwise it will not work in vue2
323
606
  const isActive = ref({
324
607
  bold: false,
@@ -336,7 +619,7 @@ var script = defineComponent({
336
619
  file: false,
337
620
  source: false
338
621
  });
339
- const isFocused = ref(props.autofocus);
622
+ const isFocused = ref(!props.readonly ? props.autofocus : false);
340
623
  const headingLevels = [1, 2, 3, 4];
341
624
  const activeHeadingLevel = ref(0);
342
625
  const markdownOutput = ref('');
@@ -351,49 +634,19 @@ var script = defineComponent({
351
634
  fallbackFocus: '.container',
352
635
  allowOutsideClick: true
353
636
  });
354
- const iconsEnum = ref({
355
- bold: 'format_bold',
356
- italic: 'format_italic',
357
- underline: 'format_underlined',
358
- strike: 'format_strikethrough',
359
- bulletList: 'format_list_bulleted',
360
- orderedList: 'format_list_numbered',
361
- link: 'link',
362
- highlight: 'highlight',
363
- redo: 'redo',
364
- undo: 'undo',
365
- codeBlock: 'code_blocks',
366
- blockquote: 'format_quote',
367
- file: 'attach_file',
368
- source: 'source_notes'
369
- });
370
- const iconTooltipsEnum = ref({
371
- bold: 'Bold',
372
- italic: 'Italic',
373
- underline: 'Underline',
374
- strike: 'Strike',
375
- bulletList: 'Bulleted List',
376
- orderedList: 'Numbered List',
377
- link: 'Link',
378
- highlight: 'Highlight',
379
- redo: 'Redo',
380
- undo: 'Undo',
381
- codeBlock: 'Code Block',
382
- blockquote: 'Quote',
383
- file: 'File',
384
- source: 'Source'
385
- });
386
637
  useResizeObserver(root, useDebounceFn(entries => {
387
638
  var _a, _b;
388
639
  const entry = entries[0];
389
640
  const {
390
641
  width
391
642
  } = entry.contentRect;
392
- if (containerRef.value && toolbarRef.value && toolbarLength.value) {
643
+ const toolbarLength = props.toolbar.flat().length;
644
+ if (containerRef.value && toolbarContainerRef.value && toolbarLength) {
393
645
  let lengthOfItem = 0;
394
- lengthOfItem = ((_b = (_a = toolbarRef.value.firstElementChild) === null || _a === void 0 ? void 0 : _a.firstElementChild) === null || _b === void 0 ? void 0 : _b.offsetWidth) + 16;
646
+ const toolbarRef = toolbarContainerRef.value.$refs.toolbarRef;
647
+ 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;
395
648
  const count = width / lengthOfItem - 2;
396
- countOfNotVisibleTools.value = Math.round(toolbarLength.value - count);
649
+ countOfNotVisibleTools.value = Math.round(toolbarLength - count);
397
650
  }
398
651
  }, 10));
399
652
  onMounted(() => {
@@ -425,7 +678,8 @@ var script = defineComponent({
425
678
  }
426
679
  },
427
680
  element: editorRef.value,
428
- autofocus: props.autofocus,
681
+ autofocus: !props.readonly ? props.autofocus : false,
682
+ editable: !props.readonly,
429
683
  enableInputRules: true,
430
684
  enablePasteRules: true,
431
685
  extensions: [codemirrorNode, StarterKit.configure({
@@ -506,43 +760,15 @@ var script = defineComponent({
506
760
  context.emit('update:modelValue', value);
507
761
  }
508
762
  });
509
- const getIndexOfHeading = computed(() => {
510
- return props.toolbar.flat().indexOf('heading');
511
- });
512
- const headingIcon = computed(() => {
513
- if (activeHeadingLevel.value && isActive.value.heading) {
514
- return `format_h${activeHeadingLevel.value}`;
515
- }
516
- return 'format_paragraph';
517
- });
518
- const toolbarLength = computed(() => {
519
- return props.toolbar.flat().length;
520
- });
521
- const notVisibleTools = computed(() => {
522
- const count = countOfNotVisibleTools.value;
523
- const toolbar = props.toolbar.flat();
524
- let notVisible = new Set(toolbar.slice(toolbar.length - count, toolbar.length));
525
- props.toolbar.forEach(tools => {
526
- if (tools.some(item => notVisible.has(item))) {
527
- tools.forEach(item => notVisible.add(item));
528
- }
529
- });
530
- return notVisible;
531
- });
532
763
  //Methods
533
764
  const handleEditorClick = () => {
534
765
  var _a;
535
766
  setActiveFormats();
536
- isFocused.value = true;
537
- editor === null || editor === void 0 ? void 0 : editor.commands.focus();
538
- activeHeadingLevel.value = ((_a = editor === null || editor === void 0 ? void 0 : editor.getAttributes('heading')) === null || _a === void 0 ? void 0 : _a.level) || 0;
539
- };
540
- const isVisible = value => {
541
- if (Array.isArray(value)) {
542
- const isHaveNotVisibleTools = value.some(item => notVisibleTools.value.has(item));
543
- return isHaveNotVisibleTools;
767
+ if (!props.readonly) {
768
+ isFocused.value = true;
769
+ editor === null || editor === void 0 ? void 0 : editor.commands.focus();
544
770
  }
545
- return !notVisibleTools.value.has(value);
771
+ activeHeadingLevel.value = ((_a = editor === null || editor === void 0 ? void 0 : editor.getAttributes('heading')) === null || _a === void 0 ? void 0 : _a.level) || 0;
546
772
  };
547
773
  const handleInput = event => {
548
774
  const target = event.target;
@@ -551,7 +777,11 @@ var script = defineComponent({
551
777
  markdownOutput.value = serialize(editor === null || editor === void 0 ? void 0 : editor.schema, editor === null || editor === void 0 ? void 0 : editor.getJSON());
552
778
  proxyModelValue.value = markdownOutput.value;
553
779
  };
554
- const handleToolbarClick = (item, level) => {
780
+ const handleToolbarClick = _ref4 => {
781
+ let {
782
+ item,
783
+ level
784
+ } = _ref4;
555
785
  var _a, _b, _c, _d;
556
786
  switch (item) {
557
787
  case 'source':
@@ -631,10 +861,10 @@ var script = defineComponent({
631
861
  editor === null || editor === void 0 ? void 0 : editor.chain().focus().setMark('link', {
632
862
  href: link.value,
633
863
  target: '__blank'
634
- }).command(_ref4 => {
864
+ }).command(_ref5 => {
635
865
  let {
636
866
  tr
637
- } = _ref4;
867
+ } = _ref5;
638
868
  const preparedValue = text.value[text.value.length - 1] === ' ' ? text.value : `${text.value} `;
639
869
  tr.insertText(preparedValue);
640
870
  return true;
@@ -670,11 +900,7 @@ var script = defineComponent({
670
900
  };
671
901
  // Styles
672
902
  const rootStyles = computed(() => ['or-rich-text-editor-v3', ...OrRichTextEditor]);
673
- const containerStyles = computed(() => [...EditorContainer]);
674
- const toolbarContainerStyles = computed(() => [...ToolbarContainer]);
675
- const toolbarStyles = computed(() => [...Toolbar,
676
- // 'overflow-x-hidden',
677
- ...(isFocused.value ? ToolbarButtonFocused : ToolbarButton)]);
903
+ const containerStyles = computed(() => [...EditorContainer, ...(isFocused.value ? EditorContainerFocus : [])]);
678
904
  const editorInputStyles = computed(() => ['tiptap-editor-v3', ...EditorInput]);
679
905
  //Effects
680
906
  watch(proxyModelValue, value => {
@@ -682,43 +908,38 @@ var script = defineComponent({
682
908
  editor === null || editor === void 0 ? void 0 : editor.commands.setContent(value);
683
909
  }
684
910
  if (props.format === 'markdown' && value !== markdownOutput.value) {
685
- //TODO: const deserialized = deserialize(editor?.schema, value);
686
- editor === null || editor === void 0 ? void 0 : editor.commands.setContent(value);
911
+ const deserialized = deserialize(editor === null || editor === void 0 ? void 0 : editor.schema, value);
912
+ editor === null || editor === void 0 ? void 0 : editor.commands.setContent(deserialized);
687
913
  }
688
914
  });
915
+ watch(props, _ref6 => {
916
+ let {
917
+ readonly
918
+ } = _ref6;
919
+ isFocused.value = !readonly;
920
+ editor === null || editor === void 0 ? void 0 : editor.setEditable(!readonly);
921
+ });
689
922
  return {
690
923
  editor,
691
924
  editorRef,
692
- toolbarRef,
925
+ toolbarContainerRef,
693
926
  containerRef,
694
- toolbarButtonRef,
695
- moreButtonRef,
696
927
  textareaRef,
697
- moreRef,
698
- menuRef,
699
- iconsEnum,
700
928
  handleToolbarClick,
701
929
  handleEditorClick,
702
930
  isActive,
703
- iconTooltipsEnum,
704
931
  containerStyles,
705
- toolbarContainerStyles,
706
- toolbarStyles,
707
932
  rootStyles,
708
933
  root,
709
934
  editorInputStyles,
710
- getIndexOfHeading,
711
935
  headingLevels,
712
- headingIcon,
713
936
  attachLink,
714
937
  discardLink,
715
938
  isOpenLinkModal,
716
939
  text,
717
940
  link,
718
941
  isFocused,
719
- isVisible,
720
942
  countOfNotVisibleTools,
721
- notVisibleTools,
722
943
  handleInput,
723
944
  proxyModelValue,
724
945
  disableMarkdown,
@@ -755,7 +976,7 @@ var __vue_render__ = function () {
755
976
  }, [_vm._t("label", function () {
756
977
  return [_vm._v("\n " + _vm._s(_vm.label) + "\n ")];
757
978
  })], 2)] : _vm._e(), _vm._v(" "), _c('div', {
758
- ref: 'containerRef',
979
+ ref: "containerRef",
759
980
  class: _vm.containerStyles,
760
981
  attrs: {
761
982
  "invalid": !!_vm.error
@@ -765,77 +986,20 @@ var __vue_render__ = function () {
765
986
  return _vm.handleEditorClick();
766
987
  }
767
988
  }
768
- }, [_c('div', {
769
- ref: 'toolbarRef',
770
- class: _vm.toolbarContainerStyles
771
- }, [_vm._l(_vm.toolbar, function (tools, index) {
772
- return _c('div', {
773
- key: index,
774
- class: _vm.toolbarStyles.concat([{
775
- 'hidden': _vm.isVisible(tools)
776
- }])
777
- }, _vm._l(tools, function (item) {
778
- return _c('div', {
779
- key: item,
780
- class: ['flex gap-md', {
781
- 'hidden': !_vm.isVisible(item)
782
- }]
783
- }, [item === 'heading' ? _c('or-icon-button', {
784
- ref: 'toolbarButtonRef',
785
- refInFor: true,
786
- attrs: {
787
- "selected": _vm.isActive[item],
788
- "disabled": !_vm.isFocused,
789
- "tooltip": {
790
- content: item,
791
- placement: 'top'
792
- },
793
- "icon": {
794
- icon: _vm.headingIcon,
795
- variant: 'inherit'
796
- }
797
- },
798
- on: {
799
- "click": function ($event) {
800
- _vm.menuRef && _vm.menuRef.toggle();
801
- }
802
- }
803
- }) : _vm.isVisible(item) ? _c('or-icon-button', {
804
- attrs: {
805
- "tooltip": {
806
- content: _vm.iconTooltipsEnum[item],
807
- placement: 'top'
808
- },
809
- "selected": _vm.isActive[item],
810
- "disabled": !_vm.isFocused,
811
- "icon": {
812
- icon: _vm.iconsEnum[item],
813
- variant: 'inherit'
814
- }
815
- },
816
- on: {
817
- "click": function ($event) {
818
- return _vm.handleToolbarClick(item);
819
- }
820
- }
821
- }) : _vm._e()], 1);
822
- }), 0);
823
- }), _vm._v(" "), _vm.countOfNotVisibleTools > 0 ? _c('or-icon-button', {
824
- ref: 'moreButtonRef',
825
- staticClass: "px-sm",
989
+ }, [!_vm.readonly ? _c('editor-toolbar', {
990
+ ref: "toolbarContainerRef",
826
991
  attrs: {
827
- "disabled": !_vm.isFocused,
828
- "icon": {
829
- icon: 'more_horiz',
830
- variant: 'inherit'
831
- }
992
+ "count-of-not-visible-tools": _vm.countOfNotVisibleTools,
993
+ "toolbar": _vm.toolbar,
994
+ "is-focused": _vm.isFocused,
995
+ "active-heading-level": _vm.activeHeadingLevel,
996
+ "is-active": _vm.isActive,
997
+ "heading-levels": _vm.headingLevels
832
998
  },
833
999
  on: {
834
- "click": function ($event) {
835
- _vm.moreRef && _vm.moreRef.open();
836
- }
1000
+ "click-tool": _vm.handleToolbarClick
837
1001
  }
838
- }) : _vm._e()], 2), _vm._v(" "), _c('div', {
1002
+ }) : _vm._e(), _vm._v(" "), _c('div', {
839
1003
  class: ['p-sm', 'overflow-auto', 'min-h-[88px]']
840
1004
  }, [_c('textarea', {
841
1005
  directives: [{
@@ -872,9 +1036,9 @@ var __vue_render__ = function () {
872
1036
  value: !_vm.disableMarkdown,
873
1037
  expression: "!disableMarkdown"
874
1038
  }],
875
- ref: 'editorRef',
1039
+ ref: "editorRef",
876
1040
  class: _vm.editorInputStyles
877
- }), _vm._v(" "), _vm._t("files")], 2)]), _vm._v(" "), !_vm.error ? [_vm.$slots.hint || _vm.hint ? [_c('OrHint', {
1041
+ }), _vm._v(" "), _vm._t("files")], 2)], 1), _vm._v(" "), !_vm.error ? [_vm.$slots.hint || _vm.hint ? [_c('OrHint', {
878
1042
  attrs: {
879
1043
  "disabled": _vm.disabled
880
1044
  }
@@ -884,62 +1048,7 @@ var __vue_render__ = function () {
884
1048
  attrs: {
885
1049
  "disabled": _vm.disabled
886
1050
  }
887
- }, [_vm._v("\n " + _vm._s(_vm.error) + "\n ")])] : _vm._e(), _vm._v(" "), _vm.moreButtonRef ? _c('or-popover', {
888
- ref: 'moreRef',
889
- attrs: {
890
- "trigger": _vm.moreButtonRef && _vm.moreButtonRef.root,
891
- "placement": "top-end"
892
- }
893
- }, [_c('div', {
894
- staticClass: "flex p-sm gap-md"
895
- }, _vm._l(_vm.notVisibleTools, function (item) {
896
- return _c('or-icon-button', {
897
- key: item,
898
- attrs: {
899
- "tooltip": {
900
- content: _vm.iconTooltipsEnum[item],
901
- placement: 'top'
902
- },
903
- "selected": _vm.isActive[item],
904
- "icon": {
905
- icon: _vm.iconsEnum[item],
906
- variant: 'inherit'
907
- }
908
- },
909
- on: {
910
- "click": function ($event) {
911
- return _vm.handleToolbarClick(item);
912
- }
913
- }
914
- });
915
- }), 1)]) : _vm._e(), _vm._v(" "), _vm.toolbarButtonRef ? _c('or-menu', {
916
- ref: 'menuRef',
917
- attrs: {
918
- "trigger": _vm.toolbarButtonRef[_vm.getIndexOfHeading] && _vm.toolbarButtonRef[_vm.getIndexOfHeading].root,
919
- "placement": "bottom-start"
920
- }
921
- }, [_vm._l(_vm.headingLevels, function (heading) {
922
- return _c('or-menu-item', {
923
- key: heading,
924
- attrs: {
925
- "selected": _vm.activeHeadingLevel === heading
926
- },
927
- on: {
928
- "click": function ($event) {
929
- return _vm.handleToolbarClick('heading', heading);
930
- }
931
- }
932
- }, [_vm._v("\n Heading " + _vm._s(heading) + "\n ")]);
933
- }), _vm._v(" "), _c('or-menu-item', {
934
- attrs: {
935
- "selected": !_vm.activeHeadingLevel
936
- },
937
- on: {
938
- "click": function ($event) {
939
- return _vm.handleToolbarClick('heading');
940
- }
941
- }
942
- }, [_vm._v("\n None\n ")])], 2) : _vm._e(), _vm._v(" "), _c('or-modal', {
1051
+ }, [_vm._v("\n " + _vm._s(_vm.error) + "\n ")])] : _vm._e(), _vm._v(" "), _c('or-modal', {
943
1052
  attrs: {
944
1053
  "is-open": _vm.isOpenLinkModal,
945
1054
  "size": "s"