@vertexvis/ui 0.1.2-canary.0 → 0.1.2-canary.2

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 (124) hide show
  1. package/dist/cjs/index.cjs.js +3 -3
  2. package/dist/cjs/{menu-d1ecf43b.js → menu-25f83cd7.js} +13 -3
  3. package/dist/cjs/{resizable-e4248256.js → resizable-c0a69532.js} +22 -4
  4. package/dist/cjs/vertex-menu.cjs.entry.js +1 -1
  5. package/dist/cjs/vertex-resizable.cjs.entry.js +2 -1
  6. package/dist/collection/components/menu/menu.js +13 -3
  7. package/dist/collection/components/resizable/resizable.js +23 -5
  8. package/dist/components/auto-resize-textarea.js +157 -0
  9. package/dist/components/color-swatch.js +124 -0
  10. package/dist/components/components.esm.js +1 -1
  11. package/dist/components/dom.js +13 -0
  12. package/dist/components/expandable.js +100 -0
  13. package/dist/components/icon-button.js +63 -0
  14. package/dist/components/icon-helper.js +722 -0
  15. package/dist/components/icon.js +43 -0
  16. package/dist/components/index.d.ts +71 -0
  17. package/dist/components/index.esm.js +1 -1
  18. package/dist/components/index.js +52 -0
  19. package/dist/components/index2.js +89 -0
  20. package/dist/components/menu.js +99 -0
  21. package/dist/components/p-1b85c1d1.entry.js +1 -0
  22. package/dist/components/p-95358d00.entry.js +1 -0
  23. package/dist/components/p-c9a967d9.js +1 -0
  24. package/dist/components/p-ee5c8bd3.js +1 -0
  25. package/dist/components/popover.js +1737 -0
  26. package/dist/components/result-list.js +565 -0
  27. package/dist/components/slots.js +26 -0
  28. package/dist/components/text-field.js +171 -0
  29. package/dist/components/tooltip.js +360 -0
  30. package/dist/components/tslib.es6.js +65 -0
  31. package/dist/components/vertex-auto-resize-textarea.d.ts +11 -0
  32. package/dist/components/vertex-auto-resize-textarea.js +6 -0
  33. package/dist/components/vertex-avatar-group.d.ts +11 -0
  34. package/dist/components/vertex-avatar-group.js +34 -0
  35. package/dist/components/vertex-avatar.d.ts +11 -0
  36. package/dist/components/vertex-avatar.js +68 -0
  37. package/dist/components/vertex-badge.d.ts +11 -0
  38. package/dist/components/vertex-badge.js +43 -0
  39. package/dist/components/vertex-banner.d.ts +11 -0
  40. package/dist/components/vertex-banner.js +141 -0
  41. package/dist/components/vertex-button.d.ts +11 -0
  42. package/dist/components/vertex-button.js +96 -0
  43. package/dist/components/vertex-card-group.d.ts +11 -0
  44. package/dist/components/vertex-card-group.js +51 -0
  45. package/dist/components/vertex-card.d.ts +11 -0
  46. package/dist/components/vertex-card.js +49 -0
  47. package/dist/components/vertex-chip.d.ts +11 -0
  48. package/dist/components/vertex-chip.js +45 -0
  49. package/dist/components/vertex-click-to-edit-textfield.d.ts +11 -0
  50. package/dist/components/vertex-click-to-edit-textfield.js +156 -0
  51. package/dist/components/vertex-collapsible.d.ts +11 -0
  52. package/dist/components/vertex-collapsible.js +63 -0
  53. package/dist/components/vertex-color-circle-picker.d.ts +11 -0
  54. package/dist/components/vertex-color-circle-picker.js +104 -0
  55. package/dist/components/vertex-color-picker.d.ts +11 -0
  56. package/dist/components/vertex-color-picker.js +75 -0
  57. package/dist/components/vertex-color-swatch.d.ts +11 -0
  58. package/dist/components/vertex-color-swatch.js +6 -0
  59. package/dist/components/vertex-context-menu.d.ts +11 -0
  60. package/dist/components/vertex-context-menu.js +125 -0
  61. package/dist/components/vertex-dialog.d.ts +11 -0
  62. package/dist/components/vertex-dialog.js +263 -0
  63. package/dist/components/vertex-draggable-popover.d.ts +11 -0
  64. package/dist/components/vertex-draggable-popover.js +119 -0
  65. package/dist/components/vertex-dropdown-menu.d.ts +11 -0
  66. package/dist/components/vertex-dropdown-menu.js +64 -0
  67. package/dist/components/vertex-expandable.d.ts +11 -0
  68. package/dist/components/vertex-expandable.js +6 -0
  69. package/dist/components/vertex-help-tooltip.d.ts +11 -0
  70. package/dist/components/vertex-help-tooltip.js +67 -0
  71. package/dist/components/vertex-icon-button.d.ts +11 -0
  72. package/dist/components/vertex-icon-button.js +6 -0
  73. package/dist/components/vertex-icon.d.ts +11 -0
  74. package/dist/components/vertex-icon.js +6 -0
  75. package/dist/components/vertex-logo-loading.d.ts +11 -0
  76. package/dist/components/vertex-logo-loading.js +34 -0
  77. package/dist/components/vertex-menu-divider.d.ts +11 -0
  78. package/dist/components/vertex-menu-divider.js +34 -0
  79. package/dist/components/vertex-menu-item.d.ts +11 -0
  80. package/dist/components/vertex-menu-item.js +44 -0
  81. package/dist/components/vertex-menu.d.ts +11 -0
  82. package/dist/components/vertex-menu.js +6 -0
  83. package/dist/components/vertex-popover.d.ts +11 -0
  84. package/dist/components/vertex-popover.js +6 -0
  85. package/dist/components/vertex-radio-group.d.ts +11 -0
  86. package/dist/components/vertex-radio-group.js +88 -0
  87. package/dist/components/vertex-radio.d.ts +11 -0
  88. package/dist/components/vertex-radio.js +56 -0
  89. package/dist/components/vertex-resizable.d.ts +11 -0
  90. package/dist/components/vertex-resizable.js +463 -0
  91. package/dist/components/vertex-result-list.d.ts +11 -0
  92. package/dist/components/vertex-result-list.js +6 -0
  93. package/dist/components/vertex-search-bar.d.ts +11 -0
  94. package/dist/components/vertex-search-bar.js +568 -0
  95. package/dist/components/vertex-select.d.ts +11 -0
  96. package/dist/components/vertex-select.js +200 -0
  97. package/dist/components/vertex-slider.d.ts +11 -0
  98. package/dist/components/vertex-slider.js +81 -0
  99. package/dist/components/vertex-spinner.d.ts +11 -0
  100. package/dist/components/vertex-spinner.js +49 -0
  101. package/dist/components/vertex-tab.d.ts +11 -0
  102. package/dist/components/vertex-tab.js +46 -0
  103. package/dist/components/vertex-tabs.d.ts +11 -0
  104. package/dist/components/vertex-tabs.js +133 -0
  105. package/dist/components/vertex-textfield.d.ts +11 -0
  106. package/dist/components/vertex-textfield.js +6 -0
  107. package/dist/components/vertex-toast.d.ts +11 -0
  108. package/dist/components/vertex-toast.js +127 -0
  109. package/dist/components/vertex-toggle.d.ts +11 -0
  110. package/dist/components/vertex-toggle.js +67 -0
  111. package/dist/components/vertex-tooltip.d.ts +11 -0
  112. package/dist/components/vertex-tooltip.js +6 -0
  113. package/dist/esm/index.js +3 -3
  114. package/dist/esm/{menu-daa7f9c9.js → menu-b8ff7d6a.js} +13 -3
  115. package/dist/esm/{resizable-a147709b.js → resizable-833336bf.js} +23 -5
  116. package/dist/esm/vertex-menu.entry.js +1 -1
  117. package/dist/esm/vertex-resizable.entry.js +2 -1
  118. package/dist/types/components/menu/menu.d.ts +2 -0
  119. package/dist/types/components/resizable/resizable.d.ts +1 -0
  120. package/package.json +2 -2
  121. package/dist/components/p-0517ca62.entry.js +0 -1
  122. package/dist/components/p-6ec189d2.js +0 -1
  123. package/dist/components/p-7b75e004.js +0 -1
  124. package/dist/components/p-ea4a2f74.entry.js +0 -1
@@ -0,0 +1,568 @@
1
+ import { proxyCustomElement, HTMLElement as HTMLElement$1, createEvent, h, Host } from '@stencil/core/internal/client';
2
+ import { c as classnames } from './index2.js';
3
+ import { g as generateInstanceFromTemplate, d as defineCustomElement$2 } from './result-list.js';
4
+ import { d as defineCustomElement$3 } from './popover.js';
5
+
6
+ // do not edit .js files directly - edit src/index.jst
7
+
8
+
9
+
10
+ var fastDeepEqual = function equal(a, b) {
11
+ if (a === b) return true;
12
+
13
+ if (a && b && typeof a == 'object' && typeof b == 'object') {
14
+ if (a.constructor !== b.constructor) return false;
15
+
16
+ var length, i, keys;
17
+ if (Array.isArray(a)) {
18
+ length = a.length;
19
+ if (length != b.length) return false;
20
+ for (i = length; i-- !== 0;)
21
+ if (!equal(a[i], b[i])) return false;
22
+ return true;
23
+ }
24
+
25
+
26
+
27
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
28
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
29
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
30
+
31
+ keys = Object.keys(a);
32
+ length = keys.length;
33
+ if (length !== Object.keys(b).length) return false;
34
+
35
+ for (i = length; i-- !== 0;)
36
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
37
+
38
+ for (i = length; i-- !== 0;) {
39
+ var key = keys[i];
40
+
41
+ if (!equal(a[key], b[key])) return false;
42
+ }
43
+
44
+ return true;
45
+ }
46
+
47
+ // true if both NaN, false otherwise
48
+ return a!==a && b!==b;
49
+ };
50
+
51
+ const getWindowSelection = () => {
52
+ if (typeof window !== 'undefined') {
53
+ return window.getSelection();
54
+ }
55
+ return undefined;
56
+ };
57
+ const nodeHasChildNodes = (node) => {
58
+ return node.hasChildNodes();
59
+ };
60
+ const createDocumentRange = () => {
61
+ return document.createRange();
62
+ };
63
+ const createTextNode = (text) => {
64
+ return new Text(text);
65
+ };
66
+ const createBreak = () => {
67
+ return document.createElement('br');
68
+ };
69
+ const isHtmlElement = (node) => {
70
+ return node instanceof HTMLElement;
71
+ };
72
+ const isBrElement = (node) => {
73
+ return node instanceof HTMLBRElement;
74
+ };
75
+
76
+ const createResultUri = (result) => {
77
+ return `${result.type}:${result.id}`;
78
+ };
79
+ const createSearchResultReplacement = (result, before, after) => {
80
+ const urn = createResultUri(result);
81
+ return {
82
+ before: createTextNode(before),
83
+ beforeSpace: createTextNode(createHairSpace()),
84
+ result: createTextNode(urn),
85
+ afterSpace: after != null
86
+ ? createTextNode(createNoBreakSpace())
87
+ : createTextNode(createHairSpace()),
88
+ after: after != null ? createTextNode(after) : undefined,
89
+ };
90
+ };
91
+ /**
92
+ * Newline characters and spaces are represented slightly differently within a
93
+ * content editable element between browsers. This method standardizes the
94
+ * representation of those characters to avoid having to write branching logic
95
+ * to support each individual browser.
96
+ */
97
+ const standardizeNewlinesAndSpaces = (node) => {
98
+ const content = node.textContent;
99
+ if (content === '\n') {
100
+ return [createBreak()];
101
+ }
102
+ else if (content != null && content.includes('\n')) {
103
+ const split = content.split('\n');
104
+ return split.reduce((res, substr, i) => {
105
+ const previous = split[i - 1];
106
+ // Ignore the empty string if the prior element was converted
107
+ // to a breaking element to prevent duplication of newlines.
108
+ if (substr === '' && previous !== '') {
109
+ return res;
110
+ }
111
+ return [
112
+ ...res,
113
+ // Standard spaces are not always respected with in `Text`
114
+ // elements when appended to a contenteditable element. This
115
+ // conversion preserves that spacing.
116
+ createTextNode(substr.replace(/ /g, createNoBreakSpace())),
117
+ createBreak(),
118
+ ];
119
+ }, []);
120
+ }
121
+ return [node];
122
+ };
123
+ const getNodesForSearchResultReplacement = (replacement, isBreaking = false) => {
124
+ const keys = Object.keys(replacement);
125
+ const replacementElements = keys
126
+ .map((key) => replacement[key])
127
+ .filter((node) => node != null);
128
+ // If the element is intended to replace a breaking element such
129
+ // as a `<div>` wrapper, a newline is required alongside the standard
130
+ // replacement elements.
131
+ if (isBreaking) {
132
+ return [createTextNode('\n'), ...replacementElements];
133
+ }
134
+ return replacementElements;
135
+ };
136
+ /**
137
+ * We leverage a couple unique spaces to represent mentions, allowing for
138
+ * correct cursor movement when using arrow keys. As these characters are
139
+ * purely for functional behavior of the input, `trimNonstandardSpaces`
140
+ * will remove them so the input is suitable for emitting.
141
+ *
142
+ * U+200A is a "Hair Space" which acts as a space, but is not visually
143
+ * represented as one.
144
+ *
145
+ * U+00A0 is a "No-Break Space" which is commonly added by browsers
146
+ * when interacting with a contenteditable element.
147
+ */
148
+ const trimNonstandardSpaces = (text) => {
149
+ return text.replace(/[\u200A]/g, '').replace(/[\u00A0]/g, ' ');
150
+ };
151
+ const createHairSpace = () => {
152
+ return String.fromCharCode(8202);
153
+ };
154
+ const createNoBreakSpace = () => {
155
+ return String.fromCharCode(160);
156
+ };
157
+
158
+ const searchBarCss = ".wrapper.sc-vertex-search-bar{display:flex;align-items:center;width:100%;box-sizing:border-box;background:none;border:1px solid transparent;border-radius:4px;font-family:var(--vertex-ui-font-family);font-size:0.875rem;line-height:1.4}.content-input.sc-vertex-search-bar{width:100%;box-sizing:border-box;padding:6px 0.5em 7px;border:1px solid transparent;background:none;font-family:var(--vertex-ui-font-family);font-weight:var(--vertex-ui-font-weight-base);font-size:0.875rem;line-height:1.4;white-space:pre-line}.content-input.sc-vertex-search-bar:focus{outline:none}.standard.sc-vertex-search-bar{border-color:var(--vertex-ui-neutral-400);color:var(--vertex-ui-neutral-800)}.standard.sc-vertex-search-bar .content-input.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-500)}.standard.sc-vertex-search-bar:hover:not(.disabled),.standard.sc-vertex-search-bar:focus{border-color:var(--vertex-ui-neutral-500)}.standard.disabled.sc-vertex-search-bar{border-color:var(--vertex-ui-neutral-200)}.standard.disabled.sc-vertex-search-bar,.standard.disabled.sc-vertex-search-bar .content-input.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-400)}.blank.sc-vertex-search-bar{color:var(--vertex-ui-neutral-800)}.blank.sc-vertex-search-bar:not(:hover) .content-input.sc-vertex-search-bar:focus{border-color:var(--vertex-ui-neutral-400);border-radius:4px}.blank.sc-vertex-search-bar .content-input.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-500)}.blank.sc-vertex-search-bar:hover:not(.disabled) .content-input.sc-vertex-search-bar{border-color:var(--vertex-ui-neutral-400);border-radius:4px}.blank.disabled.sc-vertex-search-bar{border-color:var(--vertex-ui-neutral-200)}.blank.disabled.sc-vertex-search-bar,.blank.disabled.sc-vertex-search-bar .content-input.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-400)}.filled.sc-vertex-search-bar{background-color:var(--vertex-ui-neutral-200);border-color:var(--vertex-ui-neutral-200);color:var(--vertex-ui-neutral-800)}.filled.disabled.sc-vertex-search-bar,.filled.disabled.sc-vertex-search-bar .content-input.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-400)}.filled.sc-vertex-search-bar .content-input.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-700)}.filled.sc-vertex-search-bar:hover:not(.disabled),.filled.sc-vertex-search-bar:focus{border-bottom-color:var(--vertex-ui-blue-600)}.filled.disabled.sc-vertex-search-bar{border-color:var(--vertex-ui-neutral-100)}.filled.disabled.sc-vertex-search-bar,.filled.disabled.sc-vertex-search-bar .content-input.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-400)}.underlined.sc-vertex-search-bar{background-color:var(--vertex-ui-white);border-color:var(--vertex-ui-white) var(--vertex-ui-white) var(--vertex-ui-neutral-400) var(--vertex-ui-white);color:var(--vertex-ui-neutral-800)}.underlined.disabled.sc-vertex-search-bar,.underlined.disabled.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-400)}.underlined.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-700)}.underlined.sc-vertex-search-bar:hover:not(.disabled),.underlined.sc-vertex-search-bar:focus{background-color:var(--vertex-ui-neutral-200);border-color:var(--vertex-ui-neutral-200);border-bottom-color:var(--vertex-ui-blue-600)}.underlined.disabled.sc-vertex-search-bar{border-bottom-color:var(--vertex-ui-neutral-200)}.underlined.disabled.sc-vertex-search-bar,.underlined.disabled.sc-vertex-search-bar .content-input.sc-vertex-search-bar:empty::before{content:attr(data-placeholder);color:var(--vertex-ui-neutral-400)}.underlined.has-error.sc-vertex-search-bar{border-bottom-color:var(--vertex-ui-red-600)}";
159
+
160
+ const SearchBar = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement$1 {
161
+ constructor() {
162
+ super();
163
+ this.__registerHost();
164
+ this.searchChanged = createEvent(this, "searchChanged", 7);
165
+ this.inputChanged = createEvent(this, "inputChanged", 7);
166
+ this.resultReplaced = createEvent(this, "resultReplaced", 7);
167
+ this.inputFocus = createEvent(this, "inputFocus", 7);
168
+ this.inputBlur = createEvent(this, "inputBlur", 7);
169
+ this.rawElements = [];
170
+ this.attemptReplaceElement = (child, other, replacement, isBreaking = false) => {
171
+ // In the case that the child we're evaluating has its own children
172
+ // (often a wrapper `<div>`), we want to evaluate whether any of its
173
+ // children is the target to replace.
174
+ if (nodeHasChildNodes(child) &&
175
+ Array.from(child.childNodes).some((c) => nodeHasChildNodes(c) || this.isIdenticalElement(c, other))) {
176
+ return Array.from(child.childNodes).reduce((res, c) => [
177
+ ...res,
178
+ ...this.attemptReplaceElement(c, other, replacement,
179
+ // If the element we're evaluating is a wrapper, we want to
180
+ // consider it a breaking element and add a newline to the
181
+ // replaced element only if the previous node is a `Text` node.
182
+ !isHtmlElement(child.previousSibling)),
183
+ ], []);
184
+ }
185
+ else {
186
+ return this.isIdenticalElement(child, other)
187
+ ? getNodesForSearchResultReplacement(replacement, isBreaking)
188
+ : [child];
189
+ }
190
+ };
191
+ this.isIdenticalElement = (child, other) => {
192
+ return (child === this.triggeredElement ||
193
+ this.getTextContent(child) === this.getTextContent(other));
194
+ };
195
+ this.getTextContent = (node) => {
196
+ var _a;
197
+ if (isHtmlElement(node)) {
198
+ return node.innerText;
199
+ }
200
+ return (_a = node.textContent) !== null && _a !== void 0 ? _a : '';
201
+ };
202
+ /**
203
+ * Inspects the cursor position for the following conditions:
204
+ *
205
+ * 1. The cursor has moved to text that contains a valid string
206
+ * and trigger character, indicating we need to dispatch a
207
+ * `searchChanged` event and display the results.
208
+ *
209
+ * 2. The cursor has moved within text that contains a valid string
210
+ * and trigger character, indicating we need to dispatch a
211
+ * `searchChanged` event to update the currently displayed results.
212
+ *
213
+ * 3. The cursor has moved to text that does not contain a valid
214
+ * string and trigger character, indicating we need to hide any
215
+ * displayed search results.
216
+ */
217
+ this.handleCursorPositionUpdate = () => {
218
+ var _a, _b;
219
+ const windowRange = (_a = getWindowSelection()) === null || _a === void 0 ? void 0 : _a.getRangeAt(0);
220
+ if (windowRange != null) {
221
+ const triggerText = this.readTriggerValue((_b = windowRange.commonAncestorContainer.textContent) !== null && _b !== void 0 ? _b : '', windowRange.startOffset);
222
+ if (!this.hasTriggered && triggerText != null) {
223
+ this.hasTriggered = true;
224
+ this.triggeredRange = windowRange;
225
+ this.triggeredElement = windowRange.commonAncestorContainer;
226
+ this.searchChanged.emit(triggerText.replace(this.triggerCharacter, ''));
227
+ }
228
+ else if (this.hasTriggered && triggerText != null) {
229
+ this.triggeredRange = windowRange;
230
+ this.triggeredElement = windowRange.commonAncestorContainer;
231
+ this.searchChanged.emit(triggerText.replace(this.triggerCharacter, ''));
232
+ }
233
+ else {
234
+ this.hasTriggered = false;
235
+ this.triggeredRange = undefined;
236
+ this.triggeredElement = undefined;
237
+ }
238
+ }
239
+ this.cursorPosition = this.getCursorPosition();
240
+ };
241
+ this.readTriggerValue = (value, fromIndex) => {
242
+ const adjustedValue = value.replace(String.fromCharCode(160), ' ');
243
+ const beforeSubstr = adjustedValue.substring(0, fromIndex);
244
+ const afterSubstr = adjustedValue.substring(fromIndex);
245
+ const adjustedBeforeSubstr = beforeSubstr.includes(this.triggerCharacter)
246
+ ? beforeSubstr.substring(beforeSubstr.lastIndexOf(this.triggerCharacter))
247
+ : '';
248
+ const adjustedAfterSubstr = afterSubstr.substring(0, this.firstIndexOfBreakCharacter(afterSubstr));
249
+ const result = `${adjustedBeforeSubstr}${adjustedAfterSubstr}`;
250
+ return result.includes(this.triggerCharacter) &&
251
+ !this.includesBreakCharacter(result)
252
+ ? result
253
+ : undefined;
254
+ };
255
+ this.includesBreakCharacter = (value) => {
256
+ return this.breakCharacters.some((bc) => value.includes(bc));
257
+ };
258
+ this.firstIndexOfBreakCharacter = (value) => {
259
+ const indices = this.breakCharacters
260
+ .map((bc) => value.indexOf(bc))
261
+ .filter((i) => i >= 0);
262
+ return indices.length > 0 ? Math.min(...indices) : value.length;
263
+ };
264
+ this.moveCursorToNodeEnd = (node, collapseToStart = false) => {
265
+ const selection = getWindowSelection();
266
+ if (selection != null) {
267
+ const range = createDocumentRange();
268
+ range.selectNodeContents(node);
269
+ range.collapse(collapseToStart);
270
+ selection.removeAllRanges();
271
+ selection.addRange(range);
272
+ }
273
+ };
274
+ this.getContentAsString = (element) => {
275
+ if (element != null) {
276
+ const res = trimNonstandardSpaces(Array.from(element.childNodes).reduce((res, n) => {
277
+ var _a;
278
+ const previousSiblingIsBlock = n.previousSibling == null || isHtmlElement(n.previousSibling);
279
+ if (isHtmlElement(n) && n.getAttribute('data-replaced') === 'true') {
280
+ /**
281
+ * If an element has been replaced visually, append the original
282
+ * value prior to being replaced.
283
+ */
284
+ return `${res}${n.getAttribute('data-original')}`;
285
+ }
286
+ else if (isHtmlElement(n) && n.childElementCount > 0) {
287
+ /**
288
+ * If an element is a wrapper, we want to treat it as a block element,
289
+ * ensuring newlines before and after the content.
290
+ * Additionally, we want to evaluate each of its children independently.
291
+ * Some browsers will conditionally wrap content in additional wrapper
292
+ * elements we need to unravel.
293
+ */
294
+ return `${res}${previousSiblingIsBlock ? '' : '\n'}${this.getContentAsString(n)}`;
295
+ }
296
+ else if (isBrElement(n)) {
297
+ /**
298
+ * If an element is a `<br>` element, we want to simply represent
299
+ * it as a newline in the returned string.
300
+ */
301
+ return `${res}\n`;
302
+ }
303
+ else if (isHtmlElement(n)) {
304
+ /**
305
+ * If an element is a wrapper, we want to treat it as a block element,
306
+ * ensuring newlines before and after the content.
307
+ * If the prior element is also to be treated as a block format, we
308
+ * will omit the newline before the content to avoid duplicating the
309
+ * behavior.
310
+ */
311
+ return `${res}${previousSiblingIsBlock ? '' : '\n'}${n.innerText}\n`;
312
+ }
313
+ else {
314
+ /**
315
+ * If a node is simply a `Text` node, we just want to append the text
316
+ * if defined.
317
+ */
318
+ return `${res}${(_a = n.textContent) !== null && _a !== void 0 ? _a : ''}`;
319
+ }
320
+ }, ''));
321
+ return res;
322
+ }
323
+ return '';
324
+ };
325
+ this.createReplacedElement = (original, data) => {
326
+ const template = this.hostEl.querySelector('template[slot="replaced"]');
327
+ if (template != null) {
328
+ const instance = generateInstanceFromTemplate(template);
329
+ instance.bindings.bind(data);
330
+ instance.element.id = data.id;
331
+ instance.element.style.display = 'inline-block';
332
+ instance.element.contentEditable = 'false';
333
+ instance.element.tabIndex = -1;
334
+ instance.element.setAttribute('data-replaced', 'true');
335
+ instance.element.setAttribute('data-original', original);
336
+ return instance.element;
337
+ }
338
+ else {
339
+ throw new Error('Replaced template not defined.');
340
+ }
341
+ };
342
+ this.variant = 'standard';
343
+ this.disabled = false;
344
+ this.triggerCharacter = '@';
345
+ this.breakCharacters = [' ', '\n'];
346
+ this.resultItems = undefined;
347
+ this.placement = 'bottom-start';
348
+ this.value = undefined;
349
+ this.placeholder = undefined;
350
+ this.replacements = [];
351
+ this.replacementUriType = 'user';
352
+ this.cursorPosition = undefined;
353
+ this.displayedElements = [];
354
+ this.hasTriggered = false;
355
+ this.handleKeyDown = this.handleKeyDown.bind(this);
356
+ this.handleKeyUp = this.handleKeyUp.bind(this);
357
+ this.handleResultClick = this.handleResultClick.bind(this);
358
+ this.handleClick = this.handleClick.bind(this);
359
+ this.handleWindowClick = this.handleWindowClick.bind(this);
360
+ this.handleInput = this.handleInput.bind(this);
361
+ this.handleBlur = this.handleBlur.bind(this);
362
+ this.handleFocus = this.handleFocus.bind(this);
363
+ this.handleCursorPositionUpdate =
364
+ this.handleCursorPositionUpdate.bind(this);
365
+ this.updateContent = this.updateContent.bind(this);
366
+ this.replaceContent = this.replaceContent.bind(this);
367
+ }
368
+ componentDidLoad() {
369
+ this.replaceContent(this.value);
370
+ }
371
+ connectedCallback() {
372
+ window.addEventListener('click', this.handleWindowClick);
373
+ }
374
+ disconnectedCallback() {
375
+ window.removeEventListener('click', this.handleWindowClick);
376
+ }
377
+ replaceContent(newValue, oldValue) {
378
+ if (newValue != null && newValue !== oldValue) {
379
+ const pattern = `${this.replacementUriType}:[0-9a-z-]{36}`;
380
+ const matches = newValue.match(new RegExp(pattern, 'g'));
381
+ const replacementsMap = this.replacements.reduce((map, r) => (Object.assign(Object.assign({}, map), { [createResultUri(r)]: r })), {});
382
+ let nextSubstr = newValue;
383
+ const parts = matches != null
384
+ ? matches === null || matches === void 0 ? void 0 : matches.reduce((res, m) => {
385
+ if (replacementsMap[m] != null) {
386
+ const urn = createResultUri(replacementsMap[m]);
387
+ const index = nextSubstr.indexOf(urn);
388
+ const before = nextSubstr.substring(0, index);
389
+ const after = nextSubstr.substring(index + urn.length);
390
+ const replacement = createSearchResultReplacement(replacementsMap[m], before);
391
+ nextSubstr = after;
392
+ return [
393
+ ...res,
394
+ replacement.before,
395
+ replacement.beforeSpace,
396
+ replacement.result,
397
+ replacement.afterSpace,
398
+ ];
399
+ }
400
+ return res;
401
+ }, [])
402
+ : [];
403
+ this.rawElements = [...parts, createTextNode(nextSubstr)].reduce((res, p) => [...res, ...standardizeNewlinesAndSpaces(p)], []);
404
+ this.updateContent(this.replacements);
405
+ }
406
+ }
407
+ updateContent(newValue, oldValue) {
408
+ if (this.contentEl != null && !fastDeepEqual(newValue, oldValue)) {
409
+ this.contentEl.innerHTML = '';
410
+ this.displayedElements = this.rawElements.map((el) => {
411
+ const raw = isHtmlElement(el) ? el.innerText : el.textContent;
412
+ const replacement = this.replacements.find((r) => raw === null || raw === void 0 ? void 0 : raw.includes(createResultUri(r)));
413
+ if (raw != null && replacement != null) {
414
+ const replacementElement = this.createReplacedElement(raw, replacement);
415
+ return replacementElement;
416
+ }
417
+ return el;
418
+ });
419
+ this.displayedElements.forEach((el) => {
420
+ var _a;
421
+ (_a = this.contentEl) === null || _a === void 0 ? void 0 : _a.appendChild(typeof el === 'string' ? createTextNode(el) : el);
422
+ });
423
+ if (this.lastReplacedSpace != null) {
424
+ this.moveCursorToNodeEnd(this.lastReplacedSpace);
425
+ }
426
+ this.inputChanged.emit(this.getContentAsString(this.contentEl));
427
+ }
428
+ }
429
+ render() {
430
+ var _a;
431
+ const classes = classnames('wrapper', {
432
+ standard: this.variant === 'standard',
433
+ filled: this.variant === 'filled',
434
+ underlined: this.variant === 'underlined',
435
+ blank: this.variant === 'blank',
436
+ disabled: this.disabled,
437
+ });
438
+ return (h(Host, null, h("div", { class: classes }, h("span", { class: "content-input", role: "textbox", contentEditable: "true", "aria-multiline": "true", "data-placeholder": this.placeholder, ref: (el) => (this.contentEl = el), onKeyDown: this.handleKeyDown, onKeyUp: this.handleKeyUp, onClick: this.handleCursorPositionUpdate, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur })), h("vertex-result-list", { position: this.cursorPosition, placement: this.placement, open: this.hasTriggered &&
439
+ this.resultItems != null &&
440
+ this.resultItems.length > 0, items: (_a = this.resultItems) !== null && _a !== void 0 ? _a : [], onEnterPressed: this.handleResultClick, onResultClick: this.handleResultClick }, h("slot", { name: "results" })), h("slot", { name: "replaced" })));
441
+ }
442
+ handleKeyDown(event) {
443
+ if (this.hasTriggered && this.breakCharacters.includes(event.key)) {
444
+ this.hasTriggered = false;
445
+ this.triggeredRange = undefined;
446
+ this.triggeredElement = undefined;
447
+ }
448
+ }
449
+ handleKeyUp(event) {
450
+ this.handleCursorPositionUpdate();
451
+ this.cursorPosition = this.getCursorPosition();
452
+ }
453
+ async handleInput() {
454
+ this.inputChanged.emit(this.getContentAsString(this.contentEl));
455
+ }
456
+ handleClick() {
457
+ this.handleCursorPositionUpdate();
458
+ }
459
+ handleWindowClick(event) {
460
+ if (isHtmlElement(event.target) &&
461
+ event.target.getAttribute('data-replaced') === 'true' &&
462
+ event.target.nextSibling != null) {
463
+ this.moveCursorToNodeEnd(event.target.nextSibling, true);
464
+ }
465
+ }
466
+ handleFocus(event) {
467
+ this.inputFocus.emit(event);
468
+ }
469
+ handleBlur(event) {
470
+ this.hasTriggered = false;
471
+ this.inputBlur.emit(event);
472
+ }
473
+ handleResultClick(event) {
474
+ var _a;
475
+ const triggeredRange = this.triggeredRange;
476
+ const triggeredElement = this.triggeredElement;
477
+ const value = isHtmlElement(triggeredElement)
478
+ ? triggeredElement.innerText
479
+ : triggeredElement === null || triggeredElement === void 0 ? void 0 : triggeredElement.textContent;
480
+ if (this.contentEl != null &&
481
+ triggeredRange != null &&
482
+ triggeredElement != null &&
483
+ value != null) {
484
+ const triggeredValue = (_a = this.readTriggerValue(value, triggeredRange.startOffset)) !== null && _a !== void 0 ? _a : '';
485
+ const split = value.split(triggeredValue);
486
+ const before = split[0];
487
+ const after = split[1];
488
+ const replacement = createSearchResultReplacement(event.detail, before, after);
489
+ this.lastReplacedSpace = replacement.afterSpace;
490
+ this.rawElements = Array.from(this.contentEl.childNodes).reduce((re, e) => {
491
+ return [
492
+ ...re,
493
+ ...this.attemptReplaceElement(e, triggeredElement, replacement),
494
+ ];
495
+ }, []);
496
+ this.hasTriggered = false;
497
+ this.resultReplaced.emit(event.detail);
498
+ this.replacements = [
499
+ ...this.replacements.filter((r) => r.id !== event.detail.id),
500
+ event.detail,
501
+ ];
502
+ }
503
+ }
504
+ getCursorPosition() {
505
+ var _a;
506
+ const selection = getWindowSelection();
507
+ if (selection != null && selection.rangeCount > 0) {
508
+ const cursorBounds = selection.getRangeAt(0).getBoundingClientRect();
509
+ const contentBounds = (_a = this.contentEl) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
510
+ const cursorBottom = cursorBounds.bottom || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.bottom) || 0;
511
+ const cursorTop = cursorBounds.top || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.top) || 0;
512
+ return {
513
+ x: cursorBounds.left || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.left) || 0,
514
+ y: this.placement.includes('top') ? cursorTop : cursorBottom,
515
+ };
516
+ }
517
+ throw new Error('Unable to retrieve window selection.');
518
+ }
519
+ get hostEl() { return this; }
520
+ static get watchers() { return {
521
+ "value": ["replaceContent"],
522
+ "replacements": ["updateContent"]
523
+ }; }
524
+ static get style() { return searchBarCss; }
525
+ }, [6, "vertex-search-bar", {
526
+ "variant": [1],
527
+ "disabled": [4],
528
+ "triggerCharacter": [1, "trigger-character"],
529
+ "breakCharacters": [16],
530
+ "resultItems": [16],
531
+ "placement": [1],
532
+ "value": [1],
533
+ "placeholder": [1],
534
+ "replacements": [1040],
535
+ "replacementUriType": [1, "replacement-uri-type"],
536
+ "cursorPosition": [32],
537
+ "displayedElements": [32],
538
+ "hasTriggered": [32]
539
+ }]);
540
+ function defineCustomElement$1() {
541
+ if (typeof customElements === "undefined") {
542
+ return;
543
+ }
544
+ const components = ["vertex-search-bar", "vertex-popover", "vertex-result-list"];
545
+ components.forEach(tagName => { switch (tagName) {
546
+ case "vertex-search-bar":
547
+ if (!customElements.get(tagName)) {
548
+ customElements.define(tagName, SearchBar);
549
+ }
550
+ break;
551
+ case "vertex-popover":
552
+ if (!customElements.get(tagName)) {
553
+ defineCustomElement$3();
554
+ }
555
+ break;
556
+ case "vertex-result-list":
557
+ if (!customElements.get(tagName)) {
558
+ defineCustomElement$2();
559
+ }
560
+ break;
561
+ } });
562
+ }
563
+ defineCustomElement$1();
564
+
565
+ const VertexSearchBar = SearchBar;
566
+ const defineCustomElement = defineCustomElement$1;
567
+
568
+ export { SearchBar as S, VertexSearchBar, defineCustomElement };
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface VertexSelect extends Components.VertexSelect, HTMLElement {}
4
+ export const VertexSelect: {
5
+ prototype: VertexSelect;
6
+ new (): VertexSelect;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;