@vonage/vivid 4.19.0-preview.0 → 4.19.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 (90) hide show
  1. package/custom-elements.json +922 -742
  2. package/index.cjs +5 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +2 -2
  5. package/lib/action-group/action-group.d.ts +0 -118
  6. package/lib/banner/banner.d.ts +0 -118
  7. package/lib/breadcrumb-item/breadcrumb-item.d.ts +0 -118
  8. package/lib/checkbox/checkbox.d.ts +0 -118
  9. package/lib/date-picker/date-picker.d.ts +0 -472
  10. package/lib/date-range-picker/date-range-picker.d.ts +0 -236
  11. package/lib/date-time-picker/date-time-picker.d.ts +0 -472
  12. package/lib/date-time-picker/definition.d.ts +2 -0
  13. package/lib/dialog/dialog.d.ts +0 -118
  14. package/lib/divider/divider.d.ts +0 -118
  15. package/lib/menu/menu.d.ts +0 -236
  16. package/lib/nav-disclosure/nav-disclosure.d.ts +0 -118
  17. package/lib/number-field/number-field.d.ts +0 -118
  18. package/lib/option/option.d.ts +2 -3
  19. package/lib/pagination/pagination.d.ts +1 -0
  20. package/lib/progress/progress.d.ts +0 -118
  21. package/lib/progress-ring/progress-ring.d.ts +0 -118
  22. package/lib/rich-text-editor/definition.d.ts +2 -0
  23. package/lib/rich-text-editor/facades/vivid-prose-mirror.facade.d.ts +1 -0
  24. package/lib/rich-text-editor/menubar/definition.d.ts +2 -0
  25. package/lib/rich-text-editor/menubar/menubar.d.ts +4 -0
  26. package/lib/rich-text-editor/menubar/menubar.template.d.ts +4 -0
  27. package/lib/rich-text-editor/rich-text-editor.d.ts +7 -0
  28. package/lib/searchable-select/locale.d.ts +1 -0
  29. package/lib/searchable-select/searchable-select.d.ts +1 -1
  30. package/lib/selectable-box/selectable-box.d.ts +0 -118
  31. package/lib/slider/slider.d.ts +0 -118
  32. package/lib/split-button/split-button.d.ts +0 -118
  33. package/lib/switch/switch.d.ts +0 -118
  34. package/lib/tag-group/tag-group.d.ts +0 -118
  35. package/lib/tag-name-map.d.ts +73 -0
  36. package/lib/text-anchor/text-anchor.d.ts +0 -118
  37. package/lib/text-area/text-area.d.ts +0 -118
  38. package/lib/text-field/text-field.d.ts +0 -118
  39. package/lib/time-picker/time-picker.d.ts +0 -236
  40. package/lib/toggletip/toggletip.d.ts +0 -118
  41. package/lib/tooltip/tooltip.d.ts +0 -118
  42. package/locales/de-DE.cjs +1 -0
  43. package/locales/de-DE.js +1 -0
  44. package/locales/en-GB.cjs +1 -0
  45. package/locales/en-GB.js +1 -0
  46. package/locales/en-US.cjs +1 -0
  47. package/locales/en-US.js +1 -0
  48. package/locales/ja-JP.cjs +1 -0
  49. package/locales/ja-JP.js +1 -0
  50. package/locales/zh-CN.cjs +1 -0
  51. package/locales/zh-CN.js +1 -0
  52. package/package.json +1 -1
  53. package/shared/aria/delegates-aria.d.ts +0 -118
  54. package/shared/definition20.cjs +10 -10
  55. package/shared/definition20.js +1 -1
  56. package/shared/definition30.cjs +1 -1
  57. package/shared/definition30.js +1 -1
  58. package/shared/definition36.cjs +7 -7
  59. package/shared/definition36.js +7 -7
  60. package/shared/definition37.cjs +15 -1
  61. package/shared/definition37.js +15 -1
  62. package/shared/definition4.cjs +13 -12
  63. package/shared/definition4.js +13 -12
  64. package/shared/definition43.cjs +221 -12
  65. package/shared/definition43.js +222 -14
  66. package/shared/definition44.cjs +35 -39
  67. package/shared/definition44.js +35 -39
  68. package/shared/definition63.cjs +232 -157
  69. package/shared/definition63.js +232 -157
  70. package/shared/foundation/button/button.d.ts +0 -118
  71. package/shared/option.cjs +16 -19
  72. package/shared/option.js +16 -19
  73. package/shared/patterns/anchored.d.ts +0 -236
  74. package/shared/picker-field/mixins/calendar-picker.d.ts +0 -118
  75. package/shared/picker-field/mixins/calendar-picker.template.d.ts +0 -118
  76. package/shared/picker-field/mixins/min-max-calendar-picker.d.ts +0 -236
  77. package/shared/picker-field/mixins/single-date-picker.d.ts +0 -354
  78. package/shared/picker-field/mixins/single-value-picker.d.ts +0 -118
  79. package/shared/picker-field/mixins/time-selection-picker.d.ts +0 -236
  80. package/shared/picker-field/mixins/time-selection-picker.template.d.ts +0 -236
  81. package/shared/picker-field.template.js +1 -1
  82. package/shared/vivid-element.cjs +1 -1
  83. package/shared/vivid-element.js +1 -1
  84. package/styles/core/all.css +1 -1
  85. package/styles/core/theme.css +1 -1
  86. package/styles/core/typography.css +1 -1
  87. package/styles/tokens/theme-dark.css +4 -4
  88. package/styles/tokens/theme-light.css +4 -4
  89. package/styles/tokens/vivid-2-compat.css +1 -1
  90. package/vivid.api.json +1260 -556
@@ -73,8 +73,9 @@ class Pagination extends VividElement {
73
73
  totalChanged(_, newValue) {
74
74
  if (newValue < 0) {
75
75
  this.total = 0;
76
+ return;
76
77
  }
77
- this.selectedIndex = 0;
78
+ this.#constrainSelectedIndex();
78
79
  }
79
80
  selectedIndexChanged(oldValue, newValue) {
80
81
  if (oldValue === void 0) return;
@@ -83,12 +84,25 @@ class Pagination extends VividElement {
83
84
  total: this.total,
84
85
  oldIndex: oldValue
85
86
  });
87
+ this.#constrainSelectedIndex();
86
88
  }
87
89
  paginationButtonsChanged(_, newValue) {
88
90
  newValue.forEach((button) => {
89
91
  button.shadowRoot.querySelector("button").setAttribute("part", "button");
90
92
  });
91
93
  }
94
+ get #constrainedSelectedIndex() {
95
+ return Math.max(0, Math.min(this.selectedIndex ?? 0, this.total - 1));
96
+ }
97
+ #constrainSelectedIndex() {
98
+ if (this.selectedIndex !== this.#constrainedSelectedIndex) {
99
+ window.queueMicrotask(() => {
100
+ if (this.selectedIndex !== this.#constrainedSelectedIndex) {
101
+ this.selectedIndex = this.#constrainedSelectedIndex;
102
+ }
103
+ });
104
+ }
105
+ }
92
106
  }
93
107
  __decorateClass([
94
108
  attr
@@ -60,13 +60,11 @@ class Alert extends vividElement.VividElement {
60
60
  this.#setupTimeout();
61
61
  if (newValue) {
62
62
  this.style.display = "contents";
63
- const alertText = this.shadowRoot.querySelector(
64
- ".alert-text"
63
+ const closeBtn = this.shadowRoot.querySelector(
64
+ ".dismiss-button"
65
65
  );
66
- if (this.removable && alertText) {
67
- alertText.setAttribute("tabindex", "0");
68
- alertText.focus();
69
- alertText.removeAttribute("tabindex");
66
+ if (this.removable && closeBtn) {
67
+ closeBtn.focus();
70
68
  }
71
69
  } else {
72
70
  this.style.display = "none";
@@ -156,6 +154,7 @@ function renderDismissButton(buttonTag) {
156
154
  <${buttonTag}
157
155
  aria-label="${(x) => x.dismissButtonAriaLabel || x.locale.alert.dismissButtonLabel}"
158
156
  size="condensed"
157
+ type="button"
159
158
  class="dismiss-button"
160
159
  icon="close-line"
161
160
  @click="${(x) => x.open = false}">
@@ -166,12 +165,14 @@ const AlertTemplate = (context) => {
166
165
  const buttonTag = context.tagFor(definition$1.Button);
167
166
  return vividElement.html`
168
167
  <${elevationTag} class="elevation" dp='8' exportparts="vvd-theme-alternate">
169
- <div
170
- class="${getControlClasses}"
171
- role="${(x) => x.removable ? "alertdialog" : "alert"}"
172
- aria-live="assertive"
173
- >
174
- <div part="vvd-theme-alternate" class="${getClasses}">
168
+ <div class="${getControlClasses}">
169
+ <div
170
+ part="vvd-theme-alternate"
171
+ class="${getClasses}"
172
+ role="alert"
173
+ aria-hidden="${(x) => x.open ? "false" : "true"}"
174
+ ${(x) => !x.open ? "hidden" : ""}
175
+ >
175
176
  ${renderIcon(context)}
176
177
  <div class="alert-text">
177
178
  ${when.when(
@@ -58,13 +58,11 @@ class Alert extends VividElement {
58
58
  this.#setupTimeout();
59
59
  if (newValue) {
60
60
  this.style.display = "contents";
61
- const alertText = this.shadowRoot.querySelector(
62
- ".alert-text"
61
+ const closeBtn = this.shadowRoot.querySelector(
62
+ ".dismiss-button"
63
63
  );
64
- if (this.removable && alertText) {
65
- alertText.setAttribute("tabindex", "0");
66
- alertText.focus();
67
- alertText.removeAttribute("tabindex");
64
+ if (this.removable && closeBtn) {
65
+ closeBtn.focus();
68
66
  }
69
67
  } else {
70
68
  this.style.display = "none";
@@ -154,6 +152,7 @@ function renderDismissButton(buttonTag) {
154
152
  <${buttonTag}
155
153
  aria-label="${(x) => x.dismissButtonAriaLabel || x.locale.alert.dismissButtonLabel}"
156
154
  size="condensed"
155
+ type="button"
157
156
  class="dismiss-button"
158
157
  icon="close-line"
159
158
  @click="${(x) => x.open = false}">
@@ -164,12 +163,14 @@ const AlertTemplate = (context) => {
164
163
  const buttonTag = context.tagFor(Button);
165
164
  return html`
166
165
  <${elevationTag} class="elevation" dp='8' exportparts="vvd-theme-alternate">
167
- <div
168
- class="${getControlClasses}"
169
- role="${(x) => x.removable ? "alertdialog" : "alert"}"
170
- aria-live="assertive"
171
- >
172
- <div part="vvd-theme-alternate" class="${getClasses}">
166
+ <div class="${getControlClasses}">
167
+ <div
168
+ part="vvd-theme-alternate"
169
+ class="${getClasses}"
170
+ role="alert"
171
+ aria-hidden="${(x) => x.open ? "false" : "true"}"
172
+ ${(x) => !x.open ? "hidden" : ""}
173
+ >
173
174
  ${renderIcon(context)}
174
175
  <div class="alert-text">
175
176
  ${when(
@@ -1,9 +1,117 @@
1
1
  'use strict';
2
2
 
3
3
  const vividElement = require('./vivid-element.cjs');
4
+ const definition = require('./definition11.cjs');
5
+ const definition$1 = require('./definition30.cjs');
4
6
  const classNames = require('./class-names.cjs');
7
+ const repeat = require('./repeat.cjs');
5
8
 
6
- const styles = "@charset \"UTF-8\";#editor,.editor{box-sizing:border-box;background:var(--vvd-color-canvas);color:var(--vvd-color-canvas-text);background-clip:padding-box;border:1px solid rgba(0,0,0,.2)}.ProseMirror{position:relative;word-wrap:break-word;white-space:pre-wrap;white-space:break-spaces;-webkit-font-variant-ligatures:none;font-variant-ligatures:none;font-feature-settings:\"liga\" 0;font:var(--vvd-typography-base);padding:10px 16px;line-height:1.2;outline:none;min-height:120px;box-sizing:border-box}.ProseMirror pre{white-space:pre-wrap}.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}.ProseMirror p{margin-block:0 1em}.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}";
9
+ 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
+
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)}";
12
+
13
+ var __defProp$1 = Object.defineProperty;
14
+ var __decorateClass$1 = (decorators, target, key, kind) => {
15
+ var result = void 0 ;
16
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
17
+ if (decorator = decorators[i])
18
+ result = (decorator(target, key, result) ) || result;
19
+ if (result) __defProp$1(target, key, result);
20
+ return result;
21
+ };
22
+ class MenuBar extends vividElement.VividElement {
23
+ }
24
+ __decorateClass$1([
25
+ vividElement.attr({ attribute: "menu-items" })
26
+ ], MenuBar.prototype, "menuItems");
27
+
28
+ function notifyMenuBarChange(menuBar, eventName, payload) {
29
+ menuBar.$emit(eventName, payload, { bubbles: false, composed: false });
30
+ return true;
31
+ }
32
+ const MENU_BAR_ITEMS = {
33
+ textSize: function(context) {
34
+ const buttonTag = context.tagFor(definition.Button);
35
+ const menuTag = context.tagFor(definition$1.Menu);
36
+ const menuItemTag = context.tagFor(definition$1.MenuItem);
37
+ return vividElement.html`
38
+ <${menuTag}
39
+ trigger="auto"
40
+ id="text-size"
41
+ aria-label="Menu example"
42
+ placement="bottom-end"
43
+ >
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}>
52
+ <${menuItemTag}
53
+ text="Title"
54
+ value="title"
55
+ internal-part
56
+ class="title"
57
+ connotation="cta"
58
+ @click="${(_, { parent }) => notifyMenuBarChange(parent, "text-size-selected", "title")}"
59
+ ></${menuItemTag}>
60
+ <${menuItemTag}
61
+ text="Subtitle"
62
+ value="subtitle"
63
+ internal-part
64
+ class="subtitle"
65
+ connotation="cta"
66
+ @click="${(_, { parent }) => notifyMenuBarChange(parent, "text-size-selected", "subtitle")}"
67
+ ></${menuItemTag}>
68
+ <${menuItemTag}
69
+ text="Body"
70
+ value="body"
71
+ internal-part
72
+ class="body"
73
+ connotation="cta"
74
+ @click="${(_, { parent }) => notifyMenuBarChange(parent, "text-size-selected", "body")}"
75
+ ></${menuItemTag}>
76
+ </${menuTag}>
77
+ `;
78
+ }
79
+ };
80
+ const getClasses$1 = (menuBar) => classNames.classNames("control", [
81
+ "hide-menubar",
82
+ getValidMenuItems(menuBar).length === 0
83
+ ]);
84
+ const validItems = ["textSize"];
85
+ function createMenuItem(item) {
86
+ return MENU_BAR_ITEMS[item];
87
+ }
88
+ function getValidMenuItems({ menuItems }) {
89
+ return menuItems ? menuItems.split(" ").filter((item) => validItems.includes(item)) : [];
90
+ }
91
+ function renderMenuItems(context) {
92
+ return () => vividElement.html`${repeat.repeat(
93
+ getValidMenuItems,
94
+ vividElement.html`${(menuItemName) => createMenuItem(menuItemName)(context)}`
95
+ )}`;
96
+ }
97
+ const MenuBarTemplate = (context) => {
98
+ return vividElement.html`<template class="${getClasses$1}">
99
+ ${renderMenuItems(context)}
100
+ </template>`;
101
+ };
102
+
103
+ const menuBarDefinition = vividElement.defineVividComponent(
104
+ "menubar",
105
+ MenuBar,
106
+ MenuBarTemplate,
107
+ [definition.buttonDefinition, definition$1.menuDefinition, definition$1.menuItemDefinition],
108
+ {
109
+ styles,
110
+ shadowOptions: {
111
+ delegatesFocus: true
112
+ }
113
+ }
114
+ );
7
115
 
8
116
  // ::- Persistent data structure representing an ordered mapping from
9
117
  // strings to values, with some convenient update methods.
@@ -1291,7 +1399,7 @@ structure between the old and new data as much as possible, which a
1291
1399
  tree shape like this (without back pointers) makes easy.
1292
1400
 
1293
1401
  **Do not** directly mutate the properties of a `Node` object. See
1294
- [the guide](/docs/guide/#doc) for more information.
1402
+ [the guide](https://prosemirror.net/docs/guide/#doc) for more information.
1295
1403
  */
1296
1404
  class Node {
1297
1405
  /**
@@ -1326,7 +1434,7 @@ class Node {
1326
1434
  get children() { return this.content.content; }
1327
1435
  /**
1328
1436
  The size of this node, as defined by the integer-based [indexing
1329
- scheme](/docs/guide/#doc.indexing). For text nodes, this is the
1437
+ scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
1330
1438
  amount of characters. For other leaf nodes, it is one. For
1331
1439
  non-leaf nodes, it is the size of the content plus two (the
1332
1440
  start and end token).
@@ -6852,11 +6960,13 @@ function clientRect(node) {
6852
6960
  function scrollRectIntoView(view, rect, startDOM) {
6853
6961
  let scrollThreshold = view.someProp("scrollThreshold") || 0, scrollMargin = view.someProp("scrollMargin") || 5;
6854
6962
  let doc = view.dom.ownerDocument;
6855
- for (let parent = startDOM || view.dom;; parent = parentNode(parent)) {
6963
+ for (let parent = startDOM || view.dom;;) {
6856
6964
  if (!parent)
6857
6965
  break;
6858
- if (parent.nodeType != 1)
6966
+ if (parent.nodeType != 1) {
6967
+ parent = parentNode(parent);
6859
6968
  continue;
6969
+ }
6860
6970
  let elt = parent;
6861
6971
  let atTop = elt == doc.body;
6862
6972
  let bounding = atTop ? windowRect(doc) : clientRect(elt);
@@ -6885,8 +6995,10 @@ function scrollRectIntoView(view, rect, startDOM) {
6885
6995
  rect = { left: rect.left - dX, top: rect.top - dY, right: rect.right - dX, bottom: rect.bottom - dY };
6886
6996
  }
6887
6997
  }
6888
- if (atTop || /^(fixed|sticky)$/.test(getComputedStyle(parent).position))
6998
+ let pos = atTop ? "fixed" : getComputedStyle(parent).position;
6999
+ if (/^(fixed|sticky)$/.test(pos))
6889
7000
  break;
7001
+ parent = pos == "absolute" ? parent.offsetParent : parentNode(parent);
6890
7002
  }
6891
7003
  }
6892
7004
  // Store the scroll position of the editor's parent nodes, along with
@@ -11355,6 +11467,7 @@ class DOMObserver {
11355
11467
  view.input.lastFocus = 0;
11356
11468
  selectionToDOM(view);
11357
11469
  this.currentSelection.set(sel);
11470
+ view.scrollToSelection();
11358
11471
  }
11359
11472
  else if (from > -1 || newSel) {
11360
11473
  if (from > -1) {
@@ -13350,6 +13463,7 @@ const marks = {
13350
13463
  Code font mark. Represented as a `<code>` element.
13351
13464
  */
13352
13465
  code: {
13466
+ code: true,
13353
13467
  parseDOM: [{ tag: "code" }],
13354
13468
  toDOM() { return codeDOM; }
13355
13469
  }
@@ -13369,6 +13483,26 @@ const NEGATIVE_SELECTION = {
13369
13483
  start: -1,
13370
13484
  end: -1
13371
13485
  };
13486
+ class TagToSchemaMap {
13487
+ static get h2() {
13488
+ return {
13489
+ type: "heading",
13490
+ attrs: { level: 2 }
13491
+ };
13492
+ }
13493
+ static get h3() {
13494
+ return {
13495
+ type: "heading",
13496
+ attrs: { level: 3 }
13497
+ };
13498
+ }
13499
+ static get p() {
13500
+ return {
13501
+ type: "paragraph",
13502
+ attrs: {}
13503
+ };
13504
+ }
13505
+ }
13372
13506
  function createSelectionChangePlugin(onSelectionChange) {
13373
13507
  return new Plugin({
13374
13508
  view: () => ({
@@ -13397,10 +13531,12 @@ class ProseMirrorFacade {
13397
13531
  #onSelectionChange = () => {
13398
13532
  this.#dispatchEvent("selection-changed");
13399
13533
  };
13400
- #handleInputEvent = () => {
13534
+ #handleInputEvent = (e) => {
13535
+ e.stopPropagation();
13401
13536
  this.#userContentChange = true;
13537
+ this.#dispatchEvent("input");
13402
13538
  };
13403
- #handleBlueEvent = () => {
13539
+ #handleChangeEvent = () => {
13404
13540
  if (!this.#userContentChange) {
13405
13541
  return;
13406
13542
  }
@@ -13422,7 +13558,7 @@ class ProseMirrorFacade {
13422
13558
  });
13423
13559
  this.#view = new EditorView(element, { state });
13424
13560
  this.#view.dom.addEventListener("input", this.#handleInputEvent);
13425
- this.#view.dom.addEventListener("blur", this.#handleBlueEvent);
13561
+ this.#view.dom.addEventListener("blur", this.#handleChangeEvent);
13426
13562
  }
13427
13563
  replaceContent(content) {
13428
13564
  if (!this.#view) {
@@ -13457,6 +13593,30 @@ class ProseMirrorFacade {
13457
13593
  #dispatchEvent = (eventName, detail) => {
13458
13594
  this.#eventHandler.dispatchEvent(new CustomEvent(eventName, { detail }));
13459
13595
  };
13596
+ setSelectionTag(tag) {
13597
+ if (!this.#view) {
13598
+ throw new Error(
13599
+ "ProseMirror was not initiated. Please use the `init` method first."
13600
+ );
13601
+ }
13602
+ const nodeDefinitions = TagToSchemaMap[tag] ?? {
13603
+ type: tag
13604
+ };
13605
+ const { state, dispatch } = this.#view;
13606
+ const { from, to } = state.selection;
13607
+ const tr = state.tr;
13608
+ state.doc.nodesBetween(from, to, (node) => {
13609
+ const nodeType = state.schema.nodes[nodeDefinitions.type];
13610
+ if (!nodeType) {
13611
+ throw new Error("Node type tag does not exist in the schema");
13612
+ }
13613
+ if (node.type === nodeType) {
13614
+ return;
13615
+ }
13616
+ tr.setBlockType(from, to, nodeType, nodeDefinitions.attrs);
13617
+ });
13618
+ dispatch(tr);
13619
+ }
13460
13620
  }
13461
13621
 
13462
13622
  var __defProp = Object.defineProperty;
@@ -13468,6 +13628,11 @@ var __decorateClass = (decorators, target, key, kind) => {
13468
13628
  if (result) __defProp(target, key, result);
13469
13629
  return result;
13470
13630
  };
13631
+ const RichTextEditorTextSizes = {
13632
+ title: "h2",
13633
+ subtitle: "h3",
13634
+ body: "p"
13635
+ };
13471
13636
  class RichTextEditor extends vividElement.VividElement {
13472
13637
  constructor() {
13473
13638
  super();
@@ -13483,11 +13648,13 @@ class RichTextEditor extends vividElement.VividElement {
13483
13648
  }
13484
13649
  };
13485
13650
  this.selectionEnd = null;
13651
+ this.#selectionChangedByUser = false;
13486
13652
  this.#handleSelectionChange = () => {
13487
13653
  if (!this.#editor.selection()) {
13488
13654
  return;
13489
13655
  }
13490
13656
  const { start, end } = this.#editor.selection();
13657
+ this.#selectionChangedByUser = true;
13491
13658
  this.selectionStart = start;
13492
13659
  this.selectionEnd = end;
13493
13660
  this.$emit("selection-changed");
@@ -13495,6 +13662,9 @@ class RichTextEditor extends vividElement.VividElement {
13495
13662
  this.#handleChange = () => {
13496
13663
  this.$emit("change");
13497
13664
  };
13665
+ this.#handleInput = () => {
13666
+ this.$emit("input");
13667
+ };
13498
13668
  }
13499
13669
  /**
13500
13670
  * Indicates the rich text editor's value.
@@ -13516,6 +13686,9 @@ class RichTextEditor extends vividElement.VividElement {
13516
13686
  return this.shadowRoot.querySelector("#editor");
13517
13687
  }
13518
13688
  selectionStartChanged() {
13689
+ if (this.#selectionChangedByUser) {
13690
+ return;
13691
+ }
13519
13692
  if (!this.selectionStart || this.selectionEnd && this.selectionStart > this.selectionEnd) {
13520
13693
  return;
13521
13694
  }
@@ -13523,13 +13696,19 @@ class RichTextEditor extends vividElement.VividElement {
13523
13696
  }
13524
13697
  #updateEditorSelection;
13525
13698
  selectionEndChanged() {
13699
+ if (this.#selectionChangedByUser) {
13700
+ this.#selectionChangedByUser = false;
13701
+ return;
13702
+ }
13526
13703
  if (this.selectionEnd && !this.selectionStart) {
13527
13704
  this.selectionStart = 1;
13528
13705
  }
13529
13706
  this.#updateEditorSelection();
13530
13707
  }
13708
+ #selectionChangedByUser;
13531
13709
  #handleSelectionChange;
13532
13710
  #handleChange;
13711
+ #handleInput;
13533
13712
  connectedCallback() {
13534
13713
  super.connectedCallback();
13535
13714
  if (!this.#editor) {
@@ -13540,6 +13719,14 @@ class RichTextEditor extends vividElement.VividElement {
13540
13719
  this.#handleSelectionChange
13541
13720
  );
13542
13721
  this.#editor.addEventListener("change", this.#handleChange);
13722
+ this.#editor.addEventListener("input", this.#handleInput);
13723
+ }
13724
+ }
13725
+ setTextSize(size) {
13726
+ try {
13727
+ this.#editor?.setSelectionTag(RichTextEditorTextSizes[size]);
13728
+ } catch (e) {
13729
+ console.warn(`Invalid text size: ${size}`);
13543
13730
  }
13544
13731
  }
13545
13732
  }
@@ -13551,9 +13738,30 @@ __decorateClass([
13551
13738
  ], RichTextEditor.prototype, "selectionEnd");
13552
13739
 
13553
13740
  const getClasses = (_) => classNames.classNames("control");
13741
+ const VALID_MENU_ELEMEMENT_SUFFIX = "menubar";
13742
+ function textSizeSelectedHandler(event) {
13743
+ this.setTextSize(event.detail);
13744
+ }
13745
+ function handleMenuBarSlotChange(richTextEditor, { event }) {
13746
+ const slot = event.target;
13747
+ const assignedElements = slot.assignedElements({ flatten: true });
13748
+ const menuBar = assignedElements.find(
13749
+ (element) => element.tagName.toLowerCase().endsWith(VALID_MENU_ELEMEMENT_SUFFIX)
13750
+ );
13751
+ assignedElements.forEach((element) => {
13752
+ element.style.display = element === menuBar ? "block" : "none";
13753
+ });
13754
+ if (menuBar) {
13755
+ menuBar.addEventListener(
13756
+ "text-size-selected",
13757
+ textSizeSelectedHandler.bind(richTextEditor)
13758
+ );
13759
+ }
13760
+ }
13554
13761
  const RichTextEditorTemplate = (_) => {
13555
13762
  return vividElement.html`<template class="${getClasses}">
13556
- <div id="editor"></div>
13763
+ <div id="editor" class="editor"></div>
13764
+ <slot name="menu-bar" @slotchange="${handleMenuBarSlotChange}"></slot>
13557
13765
  </template>`;
13558
13766
  };
13559
13767
 
@@ -13561,9 +13769,9 @@ const richTextEditorDefinition = vividElement.defineVividComponent(
13561
13769
  "rich-text-editor",
13562
13770
  RichTextEditor,
13563
13771
  RichTextEditorTemplate,
13564
- [],
13772
+ [menuBarDefinition],
13565
13773
  {
13566
- styles,
13774
+ styles: styles$1,
13567
13775
  shadowOptions: {
13568
13776
  delegatesFocus: true
13569
13777
  }
@@ -13573,5 +13781,6 @@ const registerRichTextEditor = vividElement.createRegisterFunction(
13573
13781
  richTextEditorDefinition
13574
13782
  );
13575
13783
 
13784
+ exports.RichTextEditor = RichTextEditor;
13576
13785
  exports.registerRichTextEditor = registerRichTextEditor;
13577
13786
  exports.richTextEditorDefinition = richTextEditorDefinition;