@vonage/vivid 4.19.0 → 4.20.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 (170) hide show
  1. package/custom-elements.json +1648 -525
  2. package/lib/accordion-item/accordion-item.d.ts +332 -5
  3. package/lib/action-group/action-group.d.ts +3 -2
  4. package/lib/alert/alert.d.ts +654 -6
  5. package/lib/audio-player/audio-player.d.ts +330 -5
  6. package/lib/avatar/avatar.d.ts +5 -4
  7. package/lib/badge/badge.d.ts +334 -7
  8. package/lib/banner/banner.d.ts +662 -15
  9. package/lib/button/button.d.ts +335 -8
  10. package/lib/calendar-event/calendar-event.d.ts +3 -2
  11. package/lib/card/card.d.ts +2 -1
  12. package/lib/checkbox/checkbox.d.ts +2 -1
  13. package/lib/combobox/combobox.d.ts +335 -6
  14. package/lib/date-picker/date-picker.d.ts +12 -12
  15. package/lib/date-range-picker/date-range-picker.d.ts +6 -6
  16. package/lib/date-time-picker/date-time-picker.d.ts +12 -12
  17. package/lib/dial-pad/dial-pad.d.ts +328 -4
  18. package/lib/dialog/dialog.d.ts +326 -4
  19. package/lib/empty-state/empty-state.d.ts +3 -2
  20. package/lib/fab/fab.d.ts +333 -6
  21. package/lib/file-picker/file-picker.d.ts +334 -4
  22. package/lib/icon/icon.d.ts +2 -1
  23. package/lib/layout/layout.d.ts +6 -5
  24. package/lib/menu-item/menu-item.d.ts +332 -10
  25. package/lib/nav-disclosure/nav-disclosure.d.ts +330 -6
  26. package/lib/nav-item/nav-item.d.ts +329 -4
  27. package/lib/note/note.d.ts +329 -4
  28. package/lib/number-field/number-field.d.ts +658 -6
  29. package/lib/option/option.d.ts +330 -4
  30. package/lib/pagination/pagination.d.ts +3 -2
  31. package/lib/radio/radio.d.ts +2 -1
  32. package/lib/range-slider/range-slider.d.ts +330 -3
  33. package/lib/rich-text-editor/facades/prose-mirror-vivid.schema.d.ts +3 -2
  34. package/lib/rich-text-editor/facades/vivid-prose-mirror.facade.d.ts +1 -0
  35. package/lib/rich-text-editor/rich-text-editor.d.ts +1 -0
  36. package/lib/searchable-select/option-tag.d.ts +330 -5
  37. package/lib/searchable-select/searchable-select.d.ts +660 -5
  38. package/lib/select/select.d.ts +336 -6
  39. package/lib/slider/slider.d.ts +326 -4
  40. package/lib/split-button/split-button.d.ts +667 -20
  41. package/lib/tab/tab.d.ts +658 -7
  42. package/lib/tabs/tabs.d.ts +2 -1
  43. package/lib/tag/tag.d.ts +333 -7
  44. package/lib/text-anchor/text-anchor.d.ts +331 -5
  45. package/lib/text-field/text-field.d.ts +333 -6
  46. package/lib/time-picker/time-picker.d.ts +6 -6
  47. package/lib/tree-item/tree-item.d.ts +329 -4
  48. package/lib/video-player/video-player.d.ts +328 -4
  49. package/package.json +1 -1
  50. package/shared/_has.cjs +0 -4
  51. package/shared/_has.js +0 -4
  52. package/shared/affix.cjs +25 -19
  53. package/shared/affix.js +26 -20
  54. package/shared/apply-mixins.js +1 -1
  55. package/shared/calendar-picker.template.cjs +1 -1
  56. package/shared/calendar-picker.template.js +1 -1
  57. package/shared/children.js +1 -1
  58. package/shared/definition.cjs +2 -4
  59. package/shared/definition.js +2 -4
  60. package/shared/definition11.cjs +2 -4
  61. package/shared/definition11.js +2 -4
  62. package/shared/definition13.cjs +85 -159
  63. package/shared/definition13.js +85 -159
  64. package/shared/definition15.cjs +1 -1
  65. package/shared/definition15.js +1 -1
  66. package/shared/definition16.cjs +2 -3
  67. package/shared/definition16.js +2 -3
  68. package/shared/definition17.cjs +1 -1
  69. package/shared/definition17.js +1 -1
  70. package/shared/definition21.cjs +2 -4
  71. package/shared/definition21.js +2 -4
  72. package/shared/definition22.cjs +2 -4
  73. package/shared/definition22.js +2 -4
  74. package/shared/definition25.cjs +2 -4
  75. package/shared/definition25.js +2 -4
  76. package/shared/definition26.cjs +3 -3
  77. package/shared/definition26.js +3 -3
  78. package/shared/definition28.cjs +27 -38
  79. package/shared/definition28.js +27 -38
  80. package/shared/definition30.cjs +4 -11
  81. package/shared/definition30.js +4 -11
  82. package/shared/definition31.cjs +2 -4
  83. package/shared/definition31.js +2 -4
  84. package/shared/definition32.cjs +2 -4
  85. package/shared/definition32.js +2 -4
  86. package/shared/definition34.cjs +1 -3
  87. package/shared/definition34.js +1 -3
  88. package/shared/definition35.cjs +6 -6
  89. package/shared/definition35.js +6 -6
  90. package/shared/definition36.cjs +1 -1
  91. package/shared/definition36.js +1 -1
  92. package/shared/definition37.cjs +5 -1
  93. package/shared/definition37.js +5 -1
  94. package/shared/definition4.cjs +1 -7
  95. package/shared/definition4.js +1 -7
  96. package/shared/definition41.cjs +1 -1
  97. package/shared/definition41.js +1 -1
  98. package/shared/definition42.cjs +3 -5
  99. package/shared/definition42.js +3 -5
  100. package/shared/definition43.cjs +219 -28
  101. package/shared/definition43.js +216 -25
  102. package/shared/definition44.cjs +9 -10
  103. package/shared/definition44.js +9 -10
  104. package/shared/definition45.cjs +3 -4
  105. package/shared/definition45.js +3 -4
  106. package/shared/definition46.cjs +1 -1
  107. package/shared/definition46.js +1 -1
  108. package/shared/definition48.cjs +3 -5
  109. package/shared/definition48.js +3 -5
  110. package/shared/definition49.cjs +4 -7
  111. package/shared/definition49.js +4 -7
  112. package/shared/definition5.cjs +1 -3
  113. package/shared/definition5.js +2 -4
  114. package/shared/definition50.cjs +1 -1
  115. package/shared/definition50.js +1 -1
  116. package/shared/definition52.cjs +2 -5
  117. package/shared/definition52.js +2 -5
  118. package/shared/definition55.cjs +2 -4
  119. package/shared/definition55.js +2 -4
  120. package/shared/definition56.cjs +1 -1
  121. package/shared/definition56.js +1 -1
  122. package/shared/definition57.cjs +3 -2
  123. package/shared/definition57.js +3 -2
  124. package/shared/definition61.cjs +2 -4
  125. package/shared/definition61.js +2 -4
  126. package/shared/definition63.cjs +2 -4
  127. package/shared/definition63.js +2 -4
  128. package/shared/definition7.cjs +1 -3
  129. package/shared/definition7.js +1 -3
  130. package/shared/definition8.cjs +2 -5
  131. package/shared/definition8.js +2 -5
  132. package/shared/definition9.cjs +1 -1
  133. package/shared/definition9.js +1 -1
  134. package/shared/form-associated.js +1 -1
  135. package/shared/localized.cjs +10 -4
  136. package/shared/localized.js +10 -4
  137. package/shared/option.cjs +1 -3
  138. package/shared/option.js +2 -4
  139. package/shared/patterns/affix.d.ts +659 -7
  140. package/shared/patterns/localized.d.ts +328 -3
  141. package/shared/patterns/trapped-focus.d.ts +329 -6
  142. package/shared/picker-field/mixins/calendar-picker.d.ts +3 -3
  143. package/shared/picker-field/mixins/calendar-picker.template.d.ts +3 -3
  144. package/shared/picker-field/mixins/inline-time-picker/inline-time-picker.d.ts +328 -4
  145. package/shared/picker-field/mixins/min-max-calendar-picker.d.ts +6 -6
  146. package/shared/picker-field/mixins/single-date-picker.d.ts +9 -9
  147. package/shared/picker-field/mixins/single-value-picker.d.ts +3 -3
  148. package/shared/picker-field/mixins/time-selection-picker.d.ts +6 -6
  149. package/shared/picker-field/mixins/time-selection-picker.template.d.ts +6 -6
  150. package/shared/picker-field/picker-field.d.ts +655 -3
  151. package/shared/picker-field.template.cjs +33 -35
  152. package/shared/picker-field.template.js +33 -35
  153. package/shared/ref.js +1 -1
  154. package/shared/slotted.js +1 -1
  155. package/shared/text-anchor.cjs +2 -2
  156. package/shared/text-anchor.js +2 -2
  157. package/shared/text-field.cjs +1 -1
  158. package/shared/text-field.js +1 -1
  159. package/shared/time-selection-picker.template.cjs +3 -5
  160. package/shared/time-selection-picker.template.js +4 -6
  161. package/shared/utils/enums.d.ts +1 -0
  162. package/shared/vivid-element.cjs +1 -1
  163. package/shared/vivid-element.js +2 -2
  164. package/styles/core/all.css +1 -1
  165. package/styles/core/theme.css +1 -1
  166. package/styles/core/typography.css +1 -1
  167. package/styles/tokens/theme-dark.css +4 -4
  168. package/styles/tokens/theme-light.css +4 -4
  169. package/styles/tokens/vivid-2-compat.css +1 -1
  170. package/vivid.api.json +187 -990
@@ -2,13 +2,15 @@
2
2
 
3
3
  const vividElement = require('./vivid-element.cjs');
4
4
  const definition = require('./definition11.cjs');
5
- const definition$1 = require('./definition30.cjs');
5
+ const definition$3 = require('./definition30.cjs');
6
+ const definition$1 = require('./definition23.cjs');
7
+ const definition$2 = require('./definition60.cjs');
6
8
  const classNames = require('./class-names.cjs');
7
9
  const repeat = require('./repeat.cjs');
8
10
 
9
11
  const styles$1 = "@charset \"UTF-8\";.ProseMirror li{position:relative}.ProseMirror-hideselection *::selection{background:transparent}.ProseMirror-hideselection *::-moz-selection{background:transparent}.ProseMirror-hideselection{caret-color:transparent}.ProseMirror [draggable][contenteditable=false]{user-select:text}.ProseMirror-selectednode{outline:2px solid #8cf}li.ProseMirror-selectednode{outline:none}li.ProseMirror-selectednode:after{content:\"\";position:absolute;inset:-2px -2px -2px -32px;border:2px solid #8cf;pointer-events:none}img.ProseMirror-separator{display:inline!important;border:none!important;margin:0!important}.ProseMirror-textblock-dropdown{min-width:3em}.ProseMirror-menu{margin:0 -4px;line-height:1}.ProseMirror-tooltip .ProseMirror-menu{width:-webkit-fit-content;width:fit-content;white-space:pre}.ProseMirror-menuitem{margin-right:3px;display:inline-block}.ProseMirror-menuseparator{border-right:1px solid #ddd;margin-right:3px}.ProseMirror-menu-dropdown,.ProseMirror-menu-dropdown-menu{font-size:90%;white-space:nowrap}.ProseMirror-menu-dropdown{vertical-align:1px;cursor:pointer;position:relative;padding-right:15px}.ProseMirror-menu-dropdown-wrap{padding:1px 0 1px 4px;display:inline-block;position:relative}.ProseMirror-menu-dropdown:after{content:\"\";border-left:4px solid transparent;border-right:4px solid transparent;border-top:4px solid currentColor;opacity:.6;position:absolute;right:4px;top:calc(50% - 2px)}.ProseMirror-menu-dropdown-menu,.ProseMirror-menu-submenu{position:absolute;background:#fff;color:#666;border:1px solid #aaa;padding:2px}.ProseMirror-menu-dropdown-menu{z-index:15;min-width:6em}.ProseMirror-menu-dropdown-item{cursor:pointer;padding:2px 8px 2px 4px}.ProseMirror-menu-dropdown-item:hover{background:#f2f2f2}.ProseMirror-menu-submenu-wrap{position:relative;margin-right:-4px}.ProseMirror-menu-submenu-label:after{content:\"\";border-top:4px solid transparent;border-bottom:4px solid transparent;border-left:4px solid currentColor;opacity:.6;position:absolute;right:4px;top:calc(50% - 4px)}.ProseMirror-menu-submenu{display:none;min-width:4em;left:100%;top:-3px}.ProseMirror-menu-active{background:#eee;border-radius:4px}.ProseMirror-menu-disabled{opacity:.3}.ProseMirror-menu-submenu-wrap:hover .ProseMirror-menu-submenu,.ProseMirror-menu-submenu-wrap-active .ProseMirror-menu-submenu{display:block}.ProseMirror-menubar{border-top-left-radius:inherit;border-top-right-radius:inherit;position:relative;min-height:1em;color:#666;padding:1px 6px;top:0;left:0;right:0;border-bottom:1px solid silver;background:#fff;z-index:10;-moz-box-sizing:border-box;box-sizing:border-box;overflow:visible}.ProseMirror-icon{display:inline-block;line-height:.8;vertical-align:-2px;padding:2px 8px;cursor:pointer}.ProseMirror-menu-disabled.ProseMirror-icon{cursor:default}.ProseMirror-icon svg{fill:currentColor;height:1em}.ProseMirror-icon span{vertical-align:text-top}.ProseMirror-gapcursor{display:none;pointer-events:none;position:absolute}.ProseMirror-gapcursor:after{content:\"\";display:block;position:absolute;top:-2px;width:20px;border-top:1px solid black;animation:ProseMirror-cursor-blink 1.1s steps(2,start) infinite}@keyframes ProseMirror-cursor-blink{to{visibility:hidden}}.ProseMirror-focused .ProseMirror-gapcursor{display:block}.ProseMirror-example-setup-style hr{padding:2px 10px;border:none;margin:1em 0}.ProseMirror-example-setup-style hr:after{content:\"\";display:block;height:1px;background-color:silver;line-height:2px}.ProseMirror ul,.ProseMirror ol{padding-left:30px}.ProseMirror blockquote{padding-left:1em;border-left:3px solid #eee;margin-left:0;margin-right:0}.ProseMirror-example-setup-style img{cursor:default}.ProseMirror-prompt{background:#fff;padding:5px 10px 5px 15px;border:1px solid silver;position:fixed;border-radius:3px;z-index:11;box-shadow:-.5px 2px 5px #0003}.ProseMirror-prompt h5{margin:0;font-weight:400;font-size:100%;color:#444}.ProseMirror-prompt input[type=text],.ProseMirror-prompt textarea{background:#eee;border:none;outline:none}.ProseMirror-prompt input[type=text]{padding:0 4px}.ProseMirror-prompt-close{position:absolute;left:2px;top:1px;color:#666;border:none;background:transparent;padding:0}.ProseMirror-prompt-close:after{content:\"✕\";font-size:12px}.ProseMirror-invalid{background:#ffc;border:1px solid #cc7;border-radius:4px;padding:5px 10px;position:absolute;min-width:10em}.ProseMirror-prompt-buttons{margin-top:5px;display:none}.editor{box-sizing:border-box;background:var(--vvd-color-canvas);background-clip:padding-box;color:var(--vvd-color-canvas-text)}.ProseMirror{position:relative;box-sizing:border-box;padding:10px 16px;block-size:120px;font:var(--vvd-typography-base);font-feature-settings:\"liga\" 0;font-variant-ligatures:none;line-height:1.2;outline:none;overflow-y:auto;white-space:break-spaces;word-wrap:break-word}.ProseMirror pre{white-space:pre-wrap}.ProseMirror p{margin-bottom:1em}.ProseMirror p:first-child,.ProseMirror h1:first-child,.ProseMirror h2:first-child,.ProseMirror h3:first-child,.ProseMirror h4:first-child,.ProseMirror h5:first-child,.ProseMirror h6:first-child{margin-top:10px}h2{font:var(--vvd-typography-heading-4)}h3{font:var(--vvd-typography-base-extended)}p{font:var(--vvd-typography-base)}";
10
12
 
11
- const styles = ":host{display:flex;align-items:center;padding:8px;background-color:var(--vvd-color-neutral-50);gap:4px}:host .hide-menubar{display:none}.title{--_text-primary-custom-size: var(--vvd-typography-heading-4)}.subtitle{--_text-primary-custom-size: var(--vvd-typography-base-extended)}.body{--_text-primary-custom-size: var(--vvd-typography-base)}";
13
+ const styles = ":host{display:flex;align-items:center;padding:8px;background-color:var(--vvd-color-neutral-50);gap:4px}:host .hide-menubar{display:none}.title{--_text-primary-custom-size: var(--vvd-typography-heading-4)}.subtitle{--_text-primary-custom-size: var(--vvd-typography-base-extended)}.body{--_text-primary-custom-size: var(--vvd-typography-base)}.divider{align-self:stretch}";
12
14
 
13
15
  var __defProp$1 = Object.defineProperty;
14
16
  var __decorateClass$1 = (decorators, target, key, kind) => {
@@ -29,26 +31,56 @@ function notifyMenuBarChange(menuBar, eventName, payload) {
29
31
  menuBar.$emit(eventName, payload, { bubbles: false, composed: false });
30
32
  return true;
31
33
  }
34
+ const TEXT_DECORATION_ITEMS = [
35
+ {
36
+ text: "Bold",
37
+ icon: "bold-line",
38
+ value: "bold"
39
+ },
40
+ {
41
+ text: "Italic",
42
+ icon: "italic-line",
43
+ value: "italics"
44
+ },
45
+ {
46
+ text: "Underline",
47
+ icon: "underline-line",
48
+ value: "underline"
49
+ },
50
+ {
51
+ text: "Strikethrough",
52
+ icon: "strikethrough-line",
53
+ value: "strikethrough"
54
+ },
55
+ {
56
+ text: "Monospace",
57
+ icon: "monospace-line",
58
+ value: "monospace"
59
+ }
60
+ ];
32
61
  const MENU_BAR_ITEMS = {
33
62
  textSize: function(context) {
34
63
  const buttonTag = context.tagFor(definition.Button);
35
- const menuTag = context.tagFor(definition$1.Menu);
36
- const menuItemTag = context.tagFor(definition$1.MenuItem);
64
+ const menuTag = context.tagFor(definition$3.Menu);
65
+ const menuItemTag = context.tagFor(definition$3.MenuItem);
66
+ const tooltipTag = context.tagFor(definition$2.Tooltip);
37
67
  return vividElement.html`
38
68
  <${menuTag}
39
69
  trigger="auto"
40
70
  id="text-size"
41
- aria-label="Menu example"
71
+ aria-label="Text Size"
42
72
  placement="bottom-end"
43
73
  >
44
- <${buttonTag}
45
- slot="anchor"
46
- aria-label="Open menu"
47
- size="super-condensed"
48
- appearance="ghost-light"
49
- shape="pill"
50
- icon="text-size-line"
51
- ></${buttonTag}>
74
+ <${tooltipTag} slot="anchor" text="Text Size" placement="top">
75
+ <${buttonTag}
76
+ slot="anchor"
77
+ aria-label="Open text size menu"
78
+ size="super-condensed"
79
+ appearance="ghost-light"
80
+ shape="pill"
81
+ icon="text-size-line"
82
+ ></${buttonTag}>
83
+ </${tooltipTag}>
52
84
  <${menuItemTag}
53
85
  text="Title"
54
86
  value="title"
@@ -75,13 +107,42 @@ const MENU_BAR_ITEMS = {
75
107
  ></${menuItemTag}>
76
108
  </${menuTag}>
77
109
  `;
110
+ },
111
+ textDecoration: function(context) {
112
+ const buttonTag = context.tagFor(definition.Button);
113
+ const dividerTag = context.tagFor(definition$1.Divider);
114
+ const tooltipTag = context.tagFor(definition$2.Tooltip);
115
+ return vividElement.html`
116
+ <${dividerTag} class="divider" orientation="vertical"></${dividerTag}>
117
+ ${repeat.repeat(
118
+ (_) => TEXT_DECORATION_ITEMS,
119
+ vividElement.html`
120
+ <${tooltipTag} text="${(x) => x.text}" placement="top">
121
+ <${buttonTag}
122
+ slot="anchor"
123
+ aria-label="${(x) => x.text}"
124
+ size="super-condensed"
125
+ appearance="ghost-light"
126
+ shape="pill"
127
+ icon="${(x) => x.icon}"
128
+ @click="${(x, c) => notifyMenuBarChange(
129
+ c.parentContext.parent,
130
+ "text-decoration-selected",
131
+ x.value
132
+ )}"')}"
133
+ ></${buttonTag}>
134
+ </${tooltipTag}>
135
+ `
136
+ )}
137
+ <${dividerTag} class="divider" orientation="vertical"></${dividerTag}>
138
+ `;
78
139
  }
79
140
  };
80
141
  const getClasses$1 = (menuBar) => classNames.classNames("control", [
81
142
  "hide-menubar",
82
143
  getValidMenuItems(menuBar).length === 0
83
144
  ]);
84
- const validItems = ["textSize"];
145
+ const validItems = ["textSize", "textDecoration"];
85
146
  function createMenuItem(item) {
86
147
  return MENU_BAR_ITEMS[item];
87
148
  }
@@ -104,7 +165,13 @@ const menuBarDefinition = vividElement.defineVividComponent(
104
165
  "menubar",
105
166
  MenuBar,
106
167
  MenuBarTemplate,
107
- [definition.buttonDefinition, definition$1.menuDefinition, definition$1.menuItemDefinition],
168
+ [
169
+ definition.buttonDefinition,
170
+ definition$3.menuDefinition,
171
+ definition$3.menuItemDefinition,
172
+ definition$1.dividerDefinition,
173
+ definition$2.tooltipDefinition
174
+ ],
108
175
  {
109
176
  styles,
110
177
  shadowOptions: {
@@ -13235,6 +13302,68 @@ const selectTextblockStart = selectTextblockSide(-1);
13235
13302
  Moves the cursor to the end of current text block.
13236
13303
  */
13237
13304
  const selectTextblockEnd = selectTextblockSide(1);
13305
+ function markApplies(doc, ranges, type, enterAtoms) {
13306
+ for (let i = 0; i < ranges.length; i++) {
13307
+ let { $from, $to } = ranges[i];
13308
+ let can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) : false;
13309
+ doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
13310
+ if (can || false)
13311
+ return false;
13312
+ can = node.inlineContent && node.type.allowsMarkType(type);
13313
+ });
13314
+ if (can)
13315
+ return true;
13316
+ }
13317
+ return false;
13318
+ }
13319
+ /**
13320
+ Create a command function that toggles the given mark with the
13321
+ given attributes. Will return `false` when the current selection
13322
+ doesn't support that mark. This will remove the mark if any marks
13323
+ of that type exist in the selection, or add it otherwise. If the
13324
+ selection is empty, this applies to the [stored
13325
+ marks](https://prosemirror.net/docs/ref/#state.EditorState.storedMarks) instead of a range of the
13326
+ document.
13327
+ */
13328
+ function toggleMark(markType, attrs = null, options) {
13329
+ return function (state, dispatch) {
13330
+ let { empty, $cursor, ranges } = state.selection;
13331
+ if ((empty && !$cursor) || !markApplies(state.doc, ranges, markType))
13332
+ return false;
13333
+ if (dispatch) {
13334
+ if ($cursor) {
13335
+ if (markType.isInSet(state.storedMarks || $cursor.marks()))
13336
+ dispatch(state.tr.removeStoredMark(markType));
13337
+ else
13338
+ dispatch(state.tr.addStoredMark(markType.create(attrs)));
13339
+ }
13340
+ else {
13341
+ let add, tr = state.tr;
13342
+ {
13343
+ add = !ranges.some(r => state.doc.rangeHasMark(r.$from.pos, r.$to.pos, markType));
13344
+ }
13345
+ for (let i = 0; i < ranges.length; i++) {
13346
+ let { $from, $to } = ranges[i];
13347
+ if (!add) {
13348
+ tr.removeMark($from.pos, $to.pos, markType);
13349
+ }
13350
+ else {
13351
+ let from = $from.pos, to = $to.pos, start = $from.nodeAfter, end = $to.nodeBefore;
13352
+ let spaceStart = start && start.isText ? /^\s*/.exec(start.text)[0].length : 0;
13353
+ let spaceEnd = end && end.isText ? /\s*$/.exec(end.text)[0].length : 0;
13354
+ if (from + spaceStart < to) {
13355
+ from += spaceStart;
13356
+ to -= spaceEnd;
13357
+ }
13358
+ tr.addMark(from, to, markType.create(attrs));
13359
+ }
13360
+ }
13361
+ dispatch(tr.scrollIntoView());
13362
+ }
13363
+ }
13364
+ return true;
13365
+ };
13366
+ }
13238
13367
  /**
13239
13368
  Combine a number of command functions into a single function (which
13240
13369
  calls them one by one until one returns true).
@@ -13479,6 +13608,34 @@ To reuse elements from this schema, extend or read from its
13479
13608
  */
13480
13609
  const schema = new Schema({ nodes, marks });
13481
13610
 
13611
+ const customMarks = {
13612
+ u: {
13613
+ parseDOM: [{ tag: "u" }],
13614
+ toDOM() {
13615
+ return ["u", 0];
13616
+ }
13617
+ },
13618
+ s: {
13619
+ parseDOM: [{ tag: "s" }, { tag: "del" }],
13620
+ toDOM() {
13621
+ return ["s", 0];
13622
+ }
13623
+ },
13624
+ tt: {
13625
+ parseDOM: [{ tag: "tt" }, { tag: "code" }],
13626
+ toDOM() {
13627
+ return ["tt", 0];
13628
+ }
13629
+ }
13630
+ };
13631
+ const extendedSchema = new Schema({
13632
+ nodes: schema.spec.nodes,
13633
+ marks: {
13634
+ ...schema.spec.marks.toObject(),
13635
+ ...customMarks
13636
+ }
13637
+ });
13638
+
13482
13639
  const NEGATIVE_SELECTION = {
13483
13640
  start: -1,
13484
13641
  end: -1
@@ -13528,6 +13685,13 @@ function convertSelectionToVividFormat({
13528
13685
  class ProseMirrorFacade {
13529
13686
  #userContentChange = false;
13530
13687
  #view;
13688
+ #verifyViewInitiation() {
13689
+ if (!this.#view) {
13690
+ throw new Error(
13691
+ "ProseMirror was not initiated. Please use the `init` method first."
13692
+ );
13693
+ }
13694
+ }
13531
13695
  #onSelectionChange = () => {
13532
13696
  this.#dispatchEvent("selection-changed");
13533
13697
  };
@@ -13553,7 +13717,7 @@ class ProseMirrorFacade {
13553
13717
  keymap(baseKeymap)
13554
13718
  ];
13555
13719
  const state = EditorState.create({
13556
- schema: schema,
13720
+ schema: extendedSchema,
13557
13721
  plugins
13558
13722
  });
13559
13723
  this.#view = new EditorView(element, { state });
@@ -13561,12 +13725,8 @@ class ProseMirrorFacade {
13561
13725
  this.#view.dom.addEventListener("blur", this.#handleChangeEvent);
13562
13726
  }
13563
13727
  replaceContent(content) {
13564
- if (!this.#view) {
13565
- throw new Error(
13566
- "ProseMirror was not initiated. Please use the `init` method first."
13567
- );
13568
- }
13569
- const parser = DOMParser.fromSchema(schema);
13728
+ this.#verifyViewInitiation();
13729
+ const parser = DOMParser.fromSchema(extendedSchema);
13570
13730
  const doc = parser.parse(
13571
13731
  new window.DOMParser().parseFromString(content, "text/html").body
13572
13732
  );
@@ -13594,11 +13754,7 @@ class ProseMirrorFacade {
13594
13754
  this.#eventHandler.dispatchEvent(new CustomEvent(eventName, { detail }));
13595
13755
  };
13596
13756
  setSelectionTag(tag) {
13597
- if (!this.#view) {
13598
- throw new Error(
13599
- "ProseMirror was not initiated. Please use the `init` method first."
13600
- );
13601
- }
13757
+ this.#verifyViewInitiation();
13602
13758
  const nodeDefinitions = TagToSchemaMap[tag] ?? {
13603
13759
  type: tag
13604
13760
  };
@@ -13617,6 +13773,23 @@ class ProseMirrorFacade {
13617
13773
  });
13618
13774
  dispatch(tr);
13619
13775
  }
13776
+ setSelectionDecoration(decoration) {
13777
+ const SUPPORTED_DECORATIONS = {
13778
+ bold: "strong",
13779
+ italics: "em",
13780
+ underline: "u",
13781
+ strikethrough: "s",
13782
+ monospace: "tt"
13783
+ };
13784
+ this.#verifyViewInitiation();
13785
+ const { state, dispatch } = this.#view;
13786
+ const decorationKey = decoration;
13787
+ const markType = state.schema.marks[SUPPORTED_DECORATIONS[decorationKey]];
13788
+ if (!markType) {
13789
+ throw new Error(`${decoration} is not a supported decoration`);
13790
+ }
13791
+ toggleMark(markType)(state, dispatch);
13792
+ }
13620
13793
  }
13621
13794
 
13622
13795
  var __defProp = Object.defineProperty;
@@ -13729,6 +13902,13 @@ class RichTextEditor extends vividElement.VividElement {
13729
13902
  console.warn(`Invalid text size: ${size}`);
13730
13903
  }
13731
13904
  }
13905
+ setSelectionDecoration(decoration) {
13906
+ try {
13907
+ this.#editor?.setSelectionDecoration(decoration);
13908
+ } catch (e) {
13909
+ console.warn(`Invalid decoration: ${decoration}`);
13910
+ }
13911
+ }
13732
13912
  }
13733
13913
  __decorateClass([
13734
13914
  vividElement.attr({ converter: vividElement.nullableNumberConverter, attribute: "selection-start" })
@@ -13742,6 +13922,9 @@ const VALID_MENU_ELEMEMENT_SUFFIX = "menubar";
13742
13922
  function textSizeSelectedHandler(event) {
13743
13923
  this.setTextSize(event.detail);
13744
13924
  }
13925
+ function selectionDecorationSelectedHandler(event) {
13926
+ this.setSelectionDecoration(event.detail);
13927
+ }
13745
13928
  function handleMenuBarSlotChange(richTextEditor, { event }) {
13746
13929
  const slot = event.target;
13747
13930
  const assignedElements = slot.assignedElements({ flatten: true });
@@ -13749,13 +13932,21 @@ function handleMenuBarSlotChange(richTextEditor, { event }) {
13749
13932
  (element) => element.tagName.toLowerCase().endsWith(VALID_MENU_ELEMEMENT_SUFFIX)
13750
13933
  );
13751
13934
  assignedElements.forEach((element) => {
13752
- element.style.display = element === menuBar ? "block" : "none";
13935
+ if (element === menuBar) {
13936
+ element.style.removeProperty("display");
13937
+ } else {
13938
+ element.style.display = "none";
13939
+ }
13753
13940
  });
13754
13941
  if (menuBar) {
13755
13942
  menuBar.addEventListener(
13756
13943
  "text-size-selected",
13757
13944
  textSizeSelectedHandler.bind(richTextEditor)
13758
13945
  );
13946
+ menuBar.addEventListener(
13947
+ "text-decoration-selected",
13948
+ selectionDecorationSelectedHandler.bind(richTextEditor)
13949
+ );
13759
13950
  }
13760
13951
  }
13761
13952
  const RichTextEditorTemplate = (_) => {