@vertexvis/ui 0.1.0-testing.3 → 0.1.0-testing.5

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 (123) hide show
  1. package/dist/cjs/badge-d39ac1fc.js +23 -0
  2. package/dist/cjs/components.cjs.js +1 -1
  3. package/dist/cjs/{icon-53d62a46.js → icon-460fd0f5.js} +1 -1
  4. package/dist/cjs/icon-button-786427d6.js +43 -0
  5. package/dist/cjs/{icon-helper-caf2699e.js → icon-helper-ba408f49.js} +7 -0
  6. package/dist/cjs/index.cjs.js +11 -9
  7. package/dist/cjs/loader.cjs.js +1 -1
  8. package/dist/cjs/{popover-d9ec8e10.js → popover-942209b8.js} +23 -1
  9. package/dist/cjs/{result-list-1e592c3c.js → result-list-241ffe8d.js} +46 -2
  10. package/dist/cjs/search-bar-a321b3e1.js +353 -0
  11. package/dist/cjs/{select-0eb7203f.js → select-5f8aecfe.js} +27 -4
  12. package/dist/cjs/{text-field-0397fb34.js → text-field-bccbde1f.js} +1 -0
  13. package/dist/cjs/{tooltip-31b596f5.js → tooltip-e9f63631.js} +58 -19
  14. package/dist/cjs/vertex-badge.cjs.entry.js +11 -0
  15. package/dist/cjs/vertex-icon-button.cjs.entry.js +2 -2
  16. package/dist/cjs/vertex-icon.cjs.entry.js +2 -2
  17. package/dist/cjs/vertex-popover.cjs.entry.js +1 -1
  18. package/dist/cjs/vertex-result-list.cjs.entry.js +1 -1
  19. package/dist/cjs/vertex-search-bar.cjs.entry.js +1 -1
  20. package/dist/cjs/vertex-select.cjs.entry.js +1 -1
  21. package/dist/cjs/vertex-textfield.cjs.entry.js +1 -1
  22. package/dist/cjs/vertex-tooltip.cjs.entry.js +1 -1
  23. package/dist/collection/collection-manifest.json +1 -0
  24. package/dist/collection/components/badge/badge.css +18 -0
  25. package/dist/collection/components/badge/badge.js +69 -0
  26. package/dist/collection/components/icon/icon-helper.js +3 -0
  27. package/dist/collection/components/icon/icon.js +1 -1
  28. package/dist/collection/components/icon/icons/comment-filled.js +2 -0
  29. package/dist/collection/components/icon-button/icon-button.css +16 -1
  30. package/dist/collection/components/icon-button/icon-button.js +2 -2
  31. package/dist/collection/components/index.js +1 -0
  32. package/dist/collection/components/menu/menu.js +1 -1
  33. package/dist/collection/components/popover/popover.js +51 -0
  34. package/dist/collection/components/result-list/result-list.js +47 -3
  35. package/dist/collection/components/search-bar/dom.js +12 -0
  36. package/dist/collection/components/search-bar/lib.js +23 -15
  37. package/dist/collection/components/search-bar/search-bar.css +2 -29
  38. package/dist/collection/components/search-bar/search-bar.js +352 -326
  39. package/dist/collection/components/select/select.css +16 -0
  40. package/dist/collection/components/select/select.js +49 -2
  41. package/dist/collection/components/text-field/text-field.js +1 -0
  42. package/dist/collection/components/tooltip/tooltip.css +2 -0
  43. package/dist/collection/components/tooltip/tooltip.js +62 -18
  44. package/dist/collection/types/icon.js +1 -0
  45. package/dist/collection/util/templates/element-pool.js +19 -1
  46. package/dist/components/components.css +1 -1
  47. package/dist/components/components.esm.js +1 -1
  48. package/dist/components/index.esm.js +1 -1
  49. package/dist/components/p-03dbb28c.js +1 -0
  50. package/dist/components/p-0b1cdc8a.entry.js +1 -0
  51. package/dist/components/p-0b4406fa.entry.js +1 -0
  52. package/dist/components/p-103249b4.js +1 -0
  53. package/dist/components/p-29d7697f.js +1 -0
  54. package/dist/components/p-406e73da.entry.js +1 -0
  55. package/dist/components/p-43b1b3f9.js +1 -0
  56. package/dist/components/p-606596de.entry.js +1 -0
  57. package/dist/components/p-6b862967.js +1 -0
  58. package/dist/components/p-7cfb3736.entry.js +1 -0
  59. package/dist/components/p-7dba2574.entry.js +1 -0
  60. package/dist/components/p-912f6e24.js +1 -0
  61. package/dist/components/p-92930f2a.js +1 -0
  62. package/dist/components/p-c2706288.js +1 -0
  63. package/dist/components/p-c4518377.entry.js +1 -0
  64. package/dist/components/{p-17b97932.js → p-ca52a423.js} +1 -1
  65. package/dist/components/p-ee496965.entry.js +1 -0
  66. package/dist/components/p-f064f911.js +1 -0
  67. package/dist/components/p-f71fc166.entry.js +1 -0
  68. package/dist/esm/badge-6d27ca92.js +21 -0
  69. package/dist/esm/components.js +1 -1
  70. package/dist/esm/icon-button-aad3c0e7.js +41 -0
  71. package/dist/esm/{icon-2630793d.js → icon-d37150b4.js} +1 -1
  72. package/dist/esm/{icon-helper-10a99d95.js → icon-helper-83f10f73.js} +7 -0
  73. package/dist/esm/index.js +10 -9
  74. package/dist/esm/loader.js +1 -1
  75. package/dist/esm/{popover-67c88e4b.js → popover-6e806354.js} +23 -1
  76. package/dist/esm/{result-list-36cfb08a.js → result-list-16c6afbd.js} +46 -2
  77. package/dist/esm/search-bar-6fad2f2e.js +351 -0
  78. package/dist/esm/{select-75ed5653.js → select-d4e135b7.js} +27 -4
  79. package/dist/esm/{text-field-e542da25.js → text-field-32ac877e.js} +1 -0
  80. package/dist/esm/{tooltip-14b65fb5.js → tooltip-933da261.js} +58 -19
  81. package/dist/esm/vertex-badge.entry.js +3 -0
  82. package/dist/esm/vertex-icon-button.entry.js +2 -2
  83. package/dist/esm/vertex-icon.entry.js +2 -2
  84. package/dist/esm/vertex-popover.entry.js +1 -1
  85. package/dist/esm/vertex-result-list.entry.js +1 -1
  86. package/dist/esm/vertex-search-bar.entry.js +1 -1
  87. package/dist/esm/vertex-select.entry.js +1 -1
  88. package/dist/esm/vertex-textfield.entry.js +1 -1
  89. package/dist/esm/vertex-tooltip.entry.js +1 -1
  90. package/dist/types/components/badge/badge.d.ts +14 -0
  91. package/dist/types/components/icon/icons/comment-filled.d.ts +3 -0
  92. package/dist/types/components/index.d.ts +1 -0
  93. package/dist/types/components/popover/popover.d.ts +7 -0
  94. package/dist/types/components/result-list/result-list.d.ts +9 -1
  95. package/dist/types/components/search-bar/dom.d.ts +3 -0
  96. package/dist/types/components/search-bar/lib.d.ts +12 -6
  97. package/dist/types/components/search-bar/search-bar.d.ts +98 -41
  98. package/dist/types/components/select/select.d.ts +8 -0
  99. package/dist/types/components/tooltip/tooltip.d.ts +7 -0
  100. package/dist/types/components.d.ts +111 -16
  101. package/dist/types/types/icon.d.ts +1 -0
  102. package/dist/types/util/templates/element-pool.d.ts +10 -1
  103. package/package.json +2 -2
  104. package/dist/cjs/icon-button-f868bf06.js +0 -43
  105. package/dist/cjs/search-bar-bb40cfa7.js +0 -290
  106. package/dist/components/p-19318fee.entry.js +0 -1
  107. package/dist/components/p-209db2ba.entry.js +0 -1
  108. package/dist/components/p-4224c2ad.js +0 -1
  109. package/dist/components/p-45cfd66e.entry.js +0 -1
  110. package/dist/components/p-52739247.js +0 -1
  111. package/dist/components/p-552c128f.js +0 -1
  112. package/dist/components/p-6505cdb3.js +0 -1
  113. package/dist/components/p-79fd6fb6.entry.js +0 -1
  114. package/dist/components/p-94168b92.js +0 -1
  115. package/dist/components/p-ae6a3c46.entry.js +0 -1
  116. package/dist/components/p-bd11e7d1.js +0 -1
  117. package/dist/components/p-da0a7b57.js +0 -1
  118. package/dist/components/p-e576818b.entry.js +0 -1
  119. package/dist/components/p-ebabee40.entry.js +0 -1
  120. package/dist/components/p-ee8b96b2.js +0 -1
  121. package/dist/components/p-f900d0f4.entry.js +0 -1
  122. package/dist/esm/icon-button-25edf617.js +0 -41
  123. package/dist/esm/search-bar-59cc151d.js +0 -288
@@ -3,10 +3,12 @@ import { c as classnames } from './index-9c609209.js';
3
3
  import { g as generateInstanceFromTemplate } from './templates-797420bf.js';
4
4
 
5
5
  class ElementPool {
6
- constructor(container, elementFactory) {
6
+ constructor(container, elementFactory, eventHandlerFactory) {
7
7
  this.container = container;
8
8
  this.elementFactory = elementFactory;
9
+ this.eventHandlerFactory = eventHandlerFactory;
9
10
  this.instanceMap = new Map();
11
+ this.handlerMap = new Map();
10
12
  this.elements = [];
11
13
  }
12
14
  swapHeadToTail(count) {
@@ -58,15 +60,31 @@ class ElementPool {
58
60
  this.elements.push(instance.element);
59
61
  this.instanceMap.set(instance.element, instance);
60
62
  this.container.append(instance.element);
63
+ this.addEventListeners(instance.element);
61
64
  return instance;
62
65
  }
66
+ addEventListeners(element) {
67
+ var _a;
68
+ const handlers = (_a = this.eventHandlerFactory) === null || _a === void 0 ? void 0 : _a.call(this, element);
69
+ handlers === null || handlers === void 0 ? void 0 : handlers.forEach((d) => {
70
+ element.addEventListener(d.type, d.handler);
71
+ });
72
+ this.handlerMap.set(element, handlers !== null && handlers !== void 0 ? handlers : []);
73
+ }
63
74
  deleteElement() {
64
75
  const element = this.elements.pop();
65
76
  if (element != null) {
66
77
  this.instanceMap.delete(element);
67
78
  element.remove();
79
+ this.removeEventListeners(element);
68
80
  }
69
81
  }
82
+ removeEventListeners(element) {
83
+ var _a;
84
+ (_a = this.handlerMap.get(element)) === null || _a === void 0 ? void 0 : _a.forEach((d) => {
85
+ element.removeEventListener(d.type, d.handler);
86
+ });
87
+ }
70
88
  }
71
89
 
72
90
  const getResultListHeight = (el) => {
@@ -86,6 +104,7 @@ const ResultList = class {
86
104
  constructor(hostRef) {
87
105
  registerInstance(this, hostRef);
88
106
  this.enterPressed = createEvent(this, "enterPressed", 7);
107
+ this.resultClick = createEvent(this, "resultClick", 7);
89
108
  this.computeResultHeight = () => {
90
109
  if (this.computedResultHeight == null) {
91
110
  const result = this.hostEl.querySelector('*[slot="result"]');
@@ -110,7 +129,7 @@ const ResultList = class {
110
129
  }
111
130
  };
112
131
  this.createResultPool = () => {
113
- this.stateMap.resultPool = new ElementPool(this.hostEl, () => this.createResultInstance());
132
+ this.stateMap.resultPool = new ElementPool(this.hostEl, () => this.createResultInstance(), () => this.createResultHandlers());
114
133
  };
115
134
  this.createResultInstance = () => {
116
135
  if (this.stateMap.resultTemplate != null) {
@@ -122,6 +141,18 @@ const ResultList = class {
122
141
  throw new Error('Result template not defined.');
123
142
  }
124
143
  };
144
+ this.createResultHandlers = () => {
145
+ return [
146
+ {
147
+ type: 'pointerdown',
148
+ handler: this.handlePointerDown,
149
+ },
150
+ {
151
+ type: 'click',
152
+ handler: this.handleResultClick,
153
+ },
154
+ ];
155
+ };
125
156
  this.layoutResults = () => {
126
157
  var _a, _b, _c, _d;
127
158
  const visibleRowCount = this.viewportEndIndex - this.viewportStartIndex + 1;
@@ -142,6 +173,7 @@ const ResultList = class {
142
173
  el.style.top = `${(this.viewportStartIndex + index) * this.resultHeight}px`;
143
174
  el.style.width = '100%';
144
175
  el.setAttribute('is-focused', `${this.viewportStartIndex + index === this.lastFocusedIndex}`);
176
+ el.setAttribute('data-result-id', result.id);
145
177
  binding.bind(result);
146
178
  }
147
179
  });
@@ -184,6 +216,8 @@ const ResultList = class {
184
216
  this.lastStartIndex = 0;
185
217
  this.lastFocusedIndex = 0;
186
218
  this.stateMap = {};
219
+ this.handleResultClick = this.handleResultClick.bind(this);
220
+ this.handlePointerDown = this.handlePointerDown.bind(this);
187
221
  }
188
222
  handleResultsChanged(results) {
189
223
  if (typeof results === 'string') {
@@ -229,6 +263,16 @@ const ResultList = class {
229
263
  height: `${this.parsedResults.length * this.resultHeight}px`,
230
264
  } }, h("slot", null), h("slot", { name: "result" })))))));
231
265
  }
266
+ handlePointerDown(event) {
267
+ event.preventDefault();
268
+ }
269
+ handleResultClick(event) {
270
+ const closestIdElement = event.target.closest('[data-result-id]');
271
+ const result = this.parsedResults.find((r) => r.id === (closestIdElement === null || closestIdElement === void 0 ? void 0 : closestIdElement.getAttribute('data-result-id')));
272
+ if (result != null) {
273
+ this.resultClick.emit(result);
274
+ }
275
+ }
232
276
  computeViewportResults() {
233
277
  const viewportHeight = this.getListHeight();
234
278
  if (viewportHeight != null && this.resultHeight > 0) {
@@ -0,0 +1,351 @@
1
+ import { r as registerInstance, e as createEvent, h, H as Host, g as getElement } from './index-72f28b71.js';
2
+ import { c as classnames } from './index-9c609209.js';
3
+ import { g as generateInstanceFromTemplate } from './templates-797420bf.js';
4
+
5
+ const getWindowSelection = () => {
6
+ if (typeof window !== 'undefined') {
7
+ return window.getSelection();
8
+ }
9
+ return undefined;
10
+ };
11
+ const createDocumentRange = () => {
12
+ return document.createRange();
13
+ };
14
+ const createTextNode = (text) => {
15
+ return new Text(text != null && text !== '' ? text : ' ');
16
+ };
17
+
18
+ const createResultUrn = (result) => {
19
+ return `${result.type}:${result.id}`;
20
+ };
21
+ const createSearchResultReplacement = (result, before, after) => {
22
+ const urn = createResultUrn(result);
23
+ return {
24
+ before: createTextNode(before),
25
+ beforeSpace: createTextNode(createHairSpace()),
26
+ result: createTextNode(urn),
27
+ afterSpace: after != null ? createTextNode(createNoBreakSpace()) : undefined,
28
+ after: after != null ? createTextNode(after) : undefined,
29
+ };
30
+ };
31
+ const getNodesForSearchResultReplacement = (replacement) => {
32
+ const keys = Object.keys(replacement);
33
+ return keys
34
+ .map((key) => replacement[key])
35
+ .filter((node) => node != null);
36
+ };
37
+ const trimNonstandardSpaces = (text) => {
38
+ return text.replace(/[\u200A]/g, '').replace(/[\u00A0]/g, ' ');
39
+ };
40
+ const createHairSpace = () => {
41
+ return String.fromCharCode(8202);
42
+ };
43
+ const createNoBreakSpace = () => {
44
+ return String.fromCharCode(160);
45
+ };
46
+
47
+ const searchBarCss = ".wrapper.sc-vertex-search-bar{display:flex;border:1px solid var(--vertex-ui-neutral-600);border-radius:0.5rem}.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}.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)}";
48
+
49
+ const SearchBar = class {
50
+ constructor(hostRef) {
51
+ registerInstance(this, hostRef);
52
+ this.searchChanged = createEvent(this, "searchChanged", 7);
53
+ this.inputChanged = createEvent(this, "inputChanged", 7);
54
+ this.resultReplaced = createEvent(this, "resultReplaced", 7);
55
+ this.inputFocus = createEvent(this, "inputFocus", 7);
56
+ this.inputBlur = createEvent(this, "inputBlur", 7);
57
+ this.rawElements = [];
58
+ this.isIdenticalElement = (child, other) => {
59
+ return (child === this.triggeredElement ||
60
+ this.getTextContent(child) === this.getTextContent(other));
61
+ };
62
+ this.getTextContent = (node) => {
63
+ var _a;
64
+ if (node instanceof HTMLElement) {
65
+ return node.innerText;
66
+ }
67
+ return (_a = node.textContent) !== null && _a !== void 0 ? _a : '';
68
+ };
69
+ this.handleCursorPositionUpdate = () => {
70
+ var _a, _b, _c;
71
+ const windowRange = (_a = getWindowSelection()) === null || _a === void 0 ? void 0 : _a.getRangeAt(0);
72
+ if (windowRange != null) {
73
+ if (!this.hasTriggered) {
74
+ const triggerText = this.readTriggerValue((_b = windowRange.commonAncestorContainer.textContent) !== null && _b !== void 0 ? _b : '', windowRange.startOffset);
75
+ if (triggerText != null) {
76
+ this.hasTriggered = true;
77
+ this.triggeredRange = windowRange;
78
+ this.triggeredElement = windowRange.commonAncestorContainer;
79
+ this.searchChanged.emit(triggerText.replace(this.triggerCharacter, ''));
80
+ }
81
+ }
82
+ else if (this.hasTriggered) {
83
+ const triggerText = this.readTriggerValue((_c = windowRange.commonAncestorContainer.textContent) !== null && _c !== void 0 ? _c : '', windowRange.startOffset);
84
+ if (triggerText != null) {
85
+ this.triggeredRange = windowRange;
86
+ this.triggeredElement = windowRange.commonAncestorContainer;
87
+ this.searchChanged.emit(triggerText.replace(this.triggerCharacter, ''));
88
+ }
89
+ else {
90
+ this.hasTriggered = false;
91
+ this.triggeredRange = undefined;
92
+ this.triggeredElement = undefined;
93
+ }
94
+ }
95
+ }
96
+ this.cursorPosition = this.getCursorPosition();
97
+ };
98
+ this.readTriggerValue = (value, fromIndex) => {
99
+ const adjustedValue = value.replace(String.fromCharCode(160), ' ');
100
+ const beforeSubstr = adjustedValue.substring(0, fromIndex);
101
+ const afterSubstr = adjustedValue.substring(fromIndex);
102
+ const adjustedBeforeSubstr = beforeSubstr.includes(this.triggerCharacter)
103
+ ? beforeSubstr.substring(beforeSubstr.lastIndexOf(this.triggerCharacter))
104
+ : '';
105
+ const adjustedAfterSubstr = afterSubstr.substring(0, this.firstIndexOfBreakCharacter(afterSubstr));
106
+ const result = `${adjustedBeforeSubstr}${adjustedAfterSubstr}`;
107
+ return result.includes(this.triggerCharacter) &&
108
+ !this.includesBreakCharacter(result)
109
+ ? result
110
+ : undefined;
111
+ };
112
+ this.includesBreakCharacter = (value) => {
113
+ return this.breakCharacters.some((bc) => value.includes(bc));
114
+ };
115
+ this.firstIndexOfBreakCharacter = (value) => {
116
+ const indices = this.breakCharacters
117
+ .map((bc) => value.indexOf(bc))
118
+ .filter((i) => i >= 0);
119
+ return indices.length > 0 ? Math.min(...indices) : value.length;
120
+ };
121
+ this.moveCursorToNodeEnd = (node, collapseToStart = false) => {
122
+ const selection = getWindowSelection();
123
+ if (selection != null) {
124
+ const range = createDocumentRange();
125
+ range.selectNodeContents(node);
126
+ range.collapse(collapseToStart);
127
+ selection.removeAllRanges();
128
+ selection.addRange(range);
129
+ }
130
+ };
131
+ this.getContentAsString = () => {
132
+ if (this.contentEl != null) {
133
+ return trimNonstandardSpaces(Array.from(this.contentEl.childNodes).reduce((res, n) => {
134
+ var _a;
135
+ if (n instanceof HTMLElement &&
136
+ n.getAttribute('data-replaced') === 'true') {
137
+ return `${res}${n.getAttribute('data-original')}`;
138
+ }
139
+ else if (n instanceof HTMLElement) {
140
+ return `${res}${n.innerText}`;
141
+ }
142
+ else {
143
+ return `${res}${(_a = n.textContent) !== null && _a !== void 0 ? _a : ''}`;
144
+ }
145
+ }, ''));
146
+ }
147
+ return '';
148
+ };
149
+ this.createReplacedElement = (original, data) => {
150
+ const template = this.hostEl.querySelector('template[slot="replaced"]');
151
+ if (template != null) {
152
+ const instance = generateInstanceFromTemplate(template);
153
+ instance.bindings.bind(data);
154
+ instance.element.id = data.id;
155
+ instance.element.style.display = 'inline-block';
156
+ instance.element.contentEditable = 'false';
157
+ instance.element.tabIndex = -1;
158
+ instance.element.setAttribute('data-replaced', 'true');
159
+ instance.element.setAttribute('data-original', original);
160
+ return instance.element;
161
+ }
162
+ else {
163
+ throw new Error('Replaced template not defined.');
164
+ }
165
+ };
166
+ this.variant = 'standard';
167
+ this.disabled = false;
168
+ this.triggerCharacter = '@';
169
+ this.breakCharacters = [' ', '\n'];
170
+ this.resultItems = undefined;
171
+ this.placement = 'bottom-start';
172
+ this.value = undefined;
173
+ this.placeholder = undefined;
174
+ this.replacements = [];
175
+ this.cursorPosition = { x: 0, y: 0 };
176
+ this.displayedElements = [];
177
+ this.hasTriggered = false;
178
+ this.handleKeyDown = this.handleKeyDown.bind(this);
179
+ this.handleKeyUp = this.handleKeyUp.bind(this);
180
+ this.handleResultClick = this.handleResultClick.bind(this);
181
+ this.handleClick = this.handleClick.bind(this);
182
+ this.handleWindowClick = this.handleWindowClick.bind(this);
183
+ this.handleInput = this.handleInput.bind(this);
184
+ this.handleBlur = this.handleBlur.bind(this);
185
+ this.handleFocus = this.handleFocus.bind(this);
186
+ this.handleCursorPositionUpdate =
187
+ this.handleCursorPositionUpdate.bind(this);
188
+ this.updateContent = this.updateContent.bind(this);
189
+ this.replaceContent = this.replaceContent.bind(this);
190
+ }
191
+ componentDidLoad() {
192
+ this.replaceContent(this.value);
193
+ }
194
+ connectedCallback() {
195
+ window.addEventListener('click', this.handleWindowClick);
196
+ }
197
+ disconnectedCallback() {
198
+ window.removeEventListener('click', this.handleWindowClick);
199
+ }
200
+ replaceContent(newValue, oldValue) {
201
+ if (newValue != null && newValue !== oldValue) {
202
+ const matches = newValue.match(/[a-z]*:[0-9a-z-]{36}/g);
203
+ const replacementsMap = this.replacements.reduce((map, r) => (Object.assign(Object.assign({}, map), { [createResultUrn(r)]: r })), {});
204
+ let nextSubstr = newValue;
205
+ const parts = matches != null
206
+ ? matches === null || matches === void 0 ? void 0 : matches.reduce((res, m) => {
207
+ if (replacementsMap[m] != null) {
208
+ const urn = createResultUrn(replacementsMap[m]);
209
+ const index = nextSubstr.indexOf(urn);
210
+ const before = nextSubstr.substring(0, index);
211
+ const after = nextSubstr.substring(index + urn.length);
212
+ const replacement = createSearchResultReplacement(replacementsMap[m], before);
213
+ nextSubstr = after;
214
+ return [
215
+ ...res,
216
+ replacement.before,
217
+ replacement.beforeSpace,
218
+ replacement.result,
219
+ ];
220
+ }
221
+ return res;
222
+ }, [])
223
+ : [];
224
+ this.rawElements = [...parts, createTextNode(nextSubstr)];
225
+ this.updateContent();
226
+ }
227
+ }
228
+ updateContent() {
229
+ if (this.contentEl != null) {
230
+ this.contentEl.innerHTML = '';
231
+ this.displayedElements = this.rawElements.map((el) => {
232
+ const raw = el instanceof HTMLElement ? el.innerText : el.textContent;
233
+ const replacement = this.replacements.find((r) => raw === null || raw === void 0 ? void 0 : raw.includes(r.id));
234
+ if (raw != null && replacement != null) {
235
+ const replacementElement = this.createReplacedElement(raw, replacement);
236
+ return replacementElement;
237
+ }
238
+ return el;
239
+ });
240
+ this.displayedElements.forEach((el) => {
241
+ var _a;
242
+ (_a = this.contentEl) === null || _a === void 0 ? void 0 : _a.appendChild(typeof el === 'string' ? createTextNode(el) : el);
243
+ });
244
+ if (this.lastReplacedSpace != null) {
245
+ this.moveCursorToNodeEnd(this.lastReplacedSpace);
246
+ }
247
+ this.inputChanged.emit(this.getContentAsString());
248
+ }
249
+ }
250
+ render() {
251
+ var _a;
252
+ const classes = classnames('wrapper', {
253
+ standard: this.variant === 'standard',
254
+ filled: this.variant === 'filled',
255
+ underlined: this.variant === 'underlined',
256
+ blank: this.variant === 'blank',
257
+ disabled: this.disabled,
258
+ });
259
+ 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.handleCursorPositionUpdate, 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 &&
260
+ this.resultItems != null &&
261
+ 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" })));
262
+ }
263
+ handleKeyDown(event) {
264
+ if (this.hasTriggered && this.breakCharacters.includes(event.key)) {
265
+ this.hasTriggered = false;
266
+ this.triggeredRange = undefined;
267
+ this.triggeredElement = undefined;
268
+ }
269
+ }
270
+ handleKeyUp(event) {
271
+ this.handleCursorPositionUpdate();
272
+ this.cursorPosition = this.getCursorPosition();
273
+ }
274
+ async handleInput() {
275
+ this.inputChanged.emit(this.getContentAsString());
276
+ }
277
+ handleClick() {
278
+ this.handleCursorPositionUpdate();
279
+ }
280
+ handleWindowClick(event) {
281
+ if (event.target instanceof HTMLElement &&
282
+ event.target.getAttribute('data-replaced') === 'true' &&
283
+ event.target.nextSibling != null) {
284
+ this.moveCursorToNodeEnd(event.target.nextSibling, true);
285
+ }
286
+ }
287
+ handleFocus(event) {
288
+ this.inputFocus.emit(event);
289
+ }
290
+ handleBlur(event) {
291
+ this.hasTriggered = false;
292
+ this.inputBlur.emit(event);
293
+ }
294
+ handleResultClick(event) {
295
+ var _a;
296
+ const triggeredRange = this.triggeredRange;
297
+ const triggeredElement = this.triggeredElement;
298
+ const value = triggeredElement instanceof HTMLElement
299
+ ? triggeredElement.innerText
300
+ : triggeredElement === null || triggeredElement === void 0 ? void 0 : triggeredElement.textContent;
301
+ if (this.contentEl != null &&
302
+ triggeredRange != null &&
303
+ triggeredElement != null &&
304
+ value != null) {
305
+ const triggeredValue = (_a = this.readTriggerValue(value, triggeredRange.startOffset)) !== null && _a !== void 0 ? _a : '';
306
+ const split = value.split(triggeredValue);
307
+ const before = split[0];
308
+ const after = split[1];
309
+ const replacement = createSearchResultReplacement(event.detail, before, after);
310
+ this.lastReplacedSpace = replacement.afterSpace;
311
+ this.rawElements = Array.from(this.contentEl.childNodes).reduce((re, e) => {
312
+ // TODO: see if we can do anything about the collapse to single line in safari
313
+ if (this.isIdenticalElement(e, triggeredElement)) {
314
+ return [...re, ...getNodesForSearchResultReplacement(replacement)];
315
+ }
316
+ else {
317
+ return [...re, e];
318
+ }
319
+ }, []);
320
+ this.hasTriggered = false;
321
+ this.replacements = [
322
+ ...this.replacements.filter((r) => r.id !== event.detail.id),
323
+ event.detail,
324
+ ];
325
+ this.resultReplaced.emit(event.detail);
326
+ }
327
+ }
328
+ getCursorPosition() {
329
+ var _a;
330
+ const selection = getWindowSelection();
331
+ if (selection != null && selection.rangeCount > 0) {
332
+ const cursorBounds = selection.getRangeAt(0).getBoundingClientRect();
333
+ const contentBounds = (_a = this.contentEl) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
334
+ const cursorBottom = cursorBounds.bottom || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.bottom) || 0;
335
+ const cursorTop = cursorBounds.top || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.top) || 0;
336
+ return {
337
+ x: cursorBounds.left || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.left) || 0,
338
+ y: this.placement.includes('top') ? cursorTop : cursorBottom,
339
+ };
340
+ }
341
+ throw new Error('Unable to retrieve window selection.');
342
+ }
343
+ get hostEl() { return getElement(this); }
344
+ static get watchers() { return {
345
+ "value": ["replaceContent"],
346
+ "replacements": ["updateContent"]
347
+ }; }
348
+ };
349
+ SearchBar.style = searchBarCss;
350
+
351
+ export { SearchBar as S };
@@ -1,7 +1,7 @@
1
1
  import { r as registerInstance, e as createEvent, h, c as readTask, g as getElement } from './index-72f28b71.js';
2
2
  import { c as classnames } from './index-9c609209.js';
3
3
 
4
- const selectCss = ":host{--select-width:100%}.root{display:inline-block;color:var(--vertex-ui-neutral-700);width:var(--select-width);font-family:var(--vertex-ui-font-family);font-size:var(--vertex-ui-text-base);overflow:hidden;user-select:none}.root:not(.disabled):hover{color:var(--vertex-ui-neutral-800)}.root.disabled{color:var(--vertex-ui-neutral-400)}.target,.selected-option{background-color:var(--vertex-ui-neutral-200);width:100%;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;padding:0.375rem 0.75rem 0.375rem 0.75rem}.target.hidden{box-shadow:0px 2px 4px -1px rgb(0 0 0 / 20%),\n 0px 4px 5px 0px rgb(0 0 0 / 14%), 0px 1px 10px 0px rgb(0 0 0 / 12%)}.selected-option.disabled,.target.disabled{background-color:var(--vertex-ui-neutral-100);cursor:default}.target{border-radius:4px}.icon{padding-left:1rem;margin-left:auto}.options{position:relative;cursor:pointer;background-color:var(--vertex-ui-white);border-radius:4px;padding:0.25rem 0;top:-0.25rem;box-shadow:0px 2px 4px -1px rgb(0 0 0 / 20%),\n 0px 4px 5px 0px rgb(0 0 0 / 14%), 0px 1px 10px 0px rgb(0 0 0 / 12%)}.options.animated{transition:opacity 0.1s ease-in 0.05s;opacity:0}.options.hidden{background-color:transparent}.options.visible{opacity:1}.options>*,.options>slot::slotted(*){padding:0.375rem 0.75rem 0.375rem 0.75rem}.options.hidden>*,.options.hidden>slot::slotted(*){opacity:0}.options>slot::slotted(:hover){background-color:var(--vertex-ui-neutral-200)}vertex-popover{--transform-origin:top left;--open-animation-name:open-scale-y;--close-animation-name:close-scale-y}";
4
+ const selectCss = ":host{--select-width:100%;--select-option-white-space:normal}.root{display:inline-block;color:var(--vertex-ui-neutral-700);width:var(--select-width);font-family:var(--vertex-ui-font-family);font-size:var(--vertex-ui-text-base);overflow:hidden;user-select:none}.root:not(.disabled):hover{color:var(--vertex-ui-neutral-800)}.root.disabled{color:var(--vertex-ui-neutral-400)}.target,.selected-option{background-color:var(--vertex-ui-neutral-200);width:100%;box-sizing:border-box;cursor:pointer;display:flex;align-items:center;padding:0.375rem 0.75rem 0.375rem 0.75rem}.target.hidden{box-shadow:0px 2px 4px -1px rgb(0 0 0 / 20%),\n 0px 4px 5px 0px rgb(0 0 0 / 14%), 0px 1px 10px 0px rgb(0 0 0 / 12%)}.selected-option.disabled,.target.disabled{background-color:var(--vertex-ui-neutral-100);cursor:default}.target{border-radius:4px}.text{white-space:var(--select-option-white-space);overflow:hidden;text-overflow:ellipsis}.icon{padding-left:1rem;margin-left:auto}.options{position:relative;cursor:pointer;background-color:var(--vertex-ui-white);border-radius:4px;padding:0.25rem 0;top:-0.25rem;box-shadow:0px 2px 4px -1px rgb(0 0 0 / 20%),\n 0px 4px 5px 0px rgb(0 0 0 / 14%), 0px 1px 10px 0px rgb(0 0 0 / 12%)}.options.animated{transition:opacity 0.1s ease-in 0.05s;opacity:0}.options.hidden{background-color:transparent}.options.visible{opacity:1}.options>*,.options>slot::slotted(*){padding:0.375rem 0.75rem 0.375rem 0.75rem}.options.hidden>*,.options.hidden>slot::slotted(*){opacity:0}.options>slot::slotted(:hover){background-color:var(--vertex-ui-neutral-200)}.options>slot::slotted([data-selected=\"true\"]){display:none}vertex-popover{--transform-origin:top left;--open-animation-name:open-scale-y;--close-animation-name:close-scale-y}";
5
5
 
6
6
  const GET_BOUNDS_DEBOUNCE_THRESHOLD = 200;
7
7
  const Select = class {
@@ -14,6 +14,7 @@ const Select = class {
14
14
  this.placeholder = 'Select an option...';
15
15
  this.disabled = false;
16
16
  this.animated = true;
17
+ this.hideSelected = true;
17
18
  this.open = false;
18
19
  this.position = undefined;
19
20
  this.displayValue = undefined;
@@ -33,6 +34,9 @@ const Select = class {
33
34
  if (this.value != null) {
34
35
  this.handleUpdateValue(this.value);
35
36
  }
37
+ else {
38
+ this.handleUpdateDisplayValue();
39
+ }
36
40
  }
37
41
  connectedCallback() {
38
42
  window.addEventListener('resize', this.getBounds);
@@ -50,6 +54,13 @@ const Select = class {
50
54
  }
51
55
  this.controlled = value != null;
52
56
  }
57
+ handleUpdateDisplayValue() {
58
+ var _a;
59
+ this.clearSelectedOptionFlag();
60
+ if (this.hideSelected) {
61
+ (_a = this.getSelectedOption()) === null || _a === void 0 ? void 0 : _a.setAttribute('data-selected', 'true');
62
+ }
63
+ }
53
64
  render() {
54
65
  return (h("div", { class: classnames('root', {
55
66
  disabled: this.disabled,
@@ -58,7 +69,7 @@ const Select = class {
58
69
  }, onClick: !this.open && !this.disabled ? this.handleOpen : undefined }, h("div", { class: classnames('target', {
59
70
  hidden: this.open,
60
71
  disabled: this.disabled,
61
- }) }, this.displayValue || this.placeholder, h("div", { class: "icon" }, h("vertex-icon", { name: "chevron-down", size: "sm" }))), h("vertex-popover", { position: this.position, open: this.open, animated: this.animated, resizeBehavior: "fixed", onDismissed: this.handleDismiss }, h("div", { class: classnames('options', {
72
+ }) }, h("div", { class: "text" }, this.displayValue || this.placeholder), h("div", { class: "icon" }, h("vertex-icon", { name: "chevron-down", size: "sm" }))), h("vertex-popover", { position: this.position, open: this.open, animated: this.animated, resizeBehavior: "fixed", onDismissed: this.handleDismiss }, h("div", { class: classnames('options', {
62
73
  hidden: !this.open,
63
74
  visible: this.open,
64
75
  animated: this.animated,
@@ -66,7 +77,7 @@ const Select = class {
66
77
  minWidth: this.width != null ? `${this.width}px` : 'var(--select-width)',
67
78
  } }, h("div", { class: classnames('selected-option', {
68
79
  disabled: this.disabled,
69
- }), onClick: this.handleDismiss }, this.displayValue || this.placeholder, h("div", { class: "icon" }, h("vertex-icon", { name: "chevron-down", size: "sm" }))), h("slot", null)))));
80
+ }), onClick: this.handleDismiss }, h("div", { class: "text" }, this.displayValue || this.placeholder), h("div", { class: "icon" }, h("vertex-icon", { name: "chevron-down", size: "sm" }))), h("slot", null)))));
70
81
  }
71
82
  handleOpen() {
72
83
  var _a, _b;
@@ -105,6 +116,15 @@ const Select = class {
105
116
  this.removeListeners.forEach((l) => l());
106
117
  this.removeListeners = [];
107
118
  }
119
+ clearSelectedOptionFlag() {
120
+ var _a, _b;
121
+ (_b = (_a = this.slotElement) === null || _a === void 0 ? void 0 : _a.assignedElements) === null || _b === void 0 ? void 0 : _b.call(_a).forEach((e) => e.removeAttribute('data-selected'));
122
+ }
123
+ getSelectedOption() {
124
+ var _a, _b, _c;
125
+ const value = (_a = this.displayValue) !== null && _a !== void 0 ? _a : this.placeholder;
126
+ return (_c = (_b = this.slotElement) === null || _b === void 0 ? void 0 : _b.assignedElements) === null || _c === void 0 ? void 0 : _c.call(_b).find((e) => e.getAttribute('data-value') === value || e.innerHTML === value);
127
+ }
108
128
  getBounds() {
109
129
  if (this.getBoundsTimeout != null) {
110
130
  clearTimeout(this.getBoundsTimeout);
@@ -128,7 +148,10 @@ const Select = class {
128
148
  }
129
149
  get hostElement() { return getElement(this); }
130
150
  static get watchers() { return {
131
- "value": ["handleUpdateValue"]
151
+ "value": ["handleUpdateValue"],
152
+ "displayValue": ["handleUpdateDisplayValue"],
153
+ "hideSelected": ["handleUpdateDisplayValue"],
154
+ "placeholder": ["handleUpdateDisplayValue"]
132
155
  }; }
133
156
  };
134
157
  Select.style = selectCss;
@@ -79,6 +79,7 @@ const TextField = class {
79
79
  render() {
80
80
  var _a;
81
81
  const classes = classnames('txt-wrapper', {
82
+ 'txt-wrapper-border': !this.multiline,
82
83
  'txt-standard': this.variant === 'standard',
83
84
  'txt-filled': this.variant === 'filled',
84
85
  'txt-underlined': this.variant === 'underlined',