@vertexvis/ui 0.1.2-canary.0 → 0.1.2-canary.1
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.
- package/dist/components/auto-resize-textarea.js +157 -0
- package/dist/components/color-swatch.js +124 -0
- package/dist/components/dom.js +13 -0
- package/dist/components/expandable.js +100 -0
- package/dist/components/icon-button.js +63 -0
- package/dist/components/icon-helper.js +722 -0
- package/dist/components/icon.js +43 -0
- package/dist/components/index.d.ts +71 -0
- package/dist/components/index.js +52 -0
- package/dist/components/index2.js +89 -0
- package/dist/components/menu.js +89 -0
- package/dist/components/popover.js +1737 -0
- package/dist/components/result-list.js +565 -0
- package/dist/components/slots.js +26 -0
- package/dist/components/text-field.js +171 -0
- package/dist/components/tooltip.js +360 -0
- package/dist/components/tslib.es6.js +65 -0
- package/dist/components/vertex-auto-resize-textarea.d.ts +11 -0
- package/dist/components/vertex-auto-resize-textarea.js +6 -0
- package/dist/components/vertex-avatar-group.d.ts +11 -0
- package/dist/components/vertex-avatar-group.js +34 -0
- package/dist/components/vertex-avatar.d.ts +11 -0
- package/dist/components/vertex-avatar.js +68 -0
- package/dist/components/vertex-badge.d.ts +11 -0
- package/dist/components/vertex-badge.js +43 -0
- package/dist/components/vertex-banner.d.ts +11 -0
- package/dist/components/vertex-banner.js +141 -0
- package/dist/components/vertex-button.d.ts +11 -0
- package/dist/components/vertex-button.js +96 -0
- package/dist/components/vertex-card-group.d.ts +11 -0
- package/dist/components/vertex-card-group.js +51 -0
- package/dist/components/vertex-card.d.ts +11 -0
- package/dist/components/vertex-card.js +49 -0
- package/dist/components/vertex-chip.d.ts +11 -0
- package/dist/components/vertex-chip.js +45 -0
- package/dist/components/vertex-click-to-edit-textfield.d.ts +11 -0
- package/dist/components/vertex-click-to-edit-textfield.js +156 -0
- package/dist/components/vertex-collapsible.d.ts +11 -0
- package/dist/components/vertex-collapsible.js +63 -0
- package/dist/components/vertex-color-circle-picker.d.ts +11 -0
- package/dist/components/vertex-color-circle-picker.js +104 -0
- package/dist/components/vertex-color-picker.d.ts +11 -0
- package/dist/components/vertex-color-picker.js +75 -0
- package/dist/components/vertex-color-swatch.d.ts +11 -0
- package/dist/components/vertex-color-swatch.js +6 -0
- package/dist/components/vertex-context-menu.d.ts +11 -0
- package/dist/components/vertex-context-menu.js +125 -0
- package/dist/components/vertex-dialog.d.ts +11 -0
- package/dist/components/vertex-dialog.js +263 -0
- package/dist/components/vertex-draggable-popover.d.ts +11 -0
- package/dist/components/vertex-draggable-popover.js +119 -0
- package/dist/components/vertex-dropdown-menu.d.ts +11 -0
- package/dist/components/vertex-dropdown-menu.js +64 -0
- package/dist/components/vertex-expandable.d.ts +11 -0
- package/dist/components/vertex-expandable.js +6 -0
- package/dist/components/vertex-help-tooltip.d.ts +11 -0
- package/dist/components/vertex-help-tooltip.js +67 -0
- package/dist/components/vertex-icon-button.d.ts +11 -0
- package/dist/components/vertex-icon-button.js +6 -0
- package/dist/components/vertex-icon.d.ts +11 -0
- package/dist/components/vertex-icon.js +6 -0
- package/dist/components/vertex-logo-loading.d.ts +11 -0
- package/dist/components/vertex-logo-loading.js +34 -0
- package/dist/components/vertex-menu-divider.d.ts +11 -0
- package/dist/components/vertex-menu-divider.js +34 -0
- package/dist/components/vertex-menu-item.d.ts +11 -0
- package/dist/components/vertex-menu-item.js +44 -0
- package/dist/components/vertex-menu.d.ts +11 -0
- package/dist/components/vertex-menu.js +6 -0
- package/dist/components/vertex-popover.d.ts +11 -0
- package/dist/components/vertex-popover.js +6 -0
- package/dist/components/vertex-radio-group.d.ts +11 -0
- package/dist/components/vertex-radio-group.js +88 -0
- package/dist/components/vertex-radio.d.ts +11 -0
- package/dist/components/vertex-radio.js +56 -0
- package/dist/components/vertex-resizable.d.ts +11 -0
- package/dist/components/vertex-resizable.js +445 -0
- package/dist/components/vertex-result-list.d.ts +11 -0
- package/dist/components/vertex-result-list.js +6 -0
- package/dist/components/vertex-search-bar.d.ts +11 -0
- package/dist/components/vertex-search-bar.js +568 -0
- package/dist/components/vertex-select.d.ts +11 -0
- package/dist/components/vertex-select.js +200 -0
- package/dist/components/vertex-slider.d.ts +11 -0
- package/dist/components/vertex-slider.js +81 -0
- package/dist/components/vertex-spinner.d.ts +11 -0
- package/dist/components/vertex-spinner.js +49 -0
- package/dist/components/vertex-tab.d.ts +11 -0
- package/dist/components/vertex-tab.js +46 -0
- package/dist/components/vertex-tabs.d.ts +11 -0
- package/dist/components/vertex-tabs.js +133 -0
- package/dist/components/vertex-textfield.d.ts +11 -0
- package/dist/components/vertex-textfield.js +6 -0
- package/dist/components/vertex-toast.d.ts +11 -0
- package/dist/components/vertex-toast.js +127 -0
- package/dist/components/vertex-toggle.d.ts +11 -0
- package/dist/components/vertex-toggle.js +67 -0
- package/dist/components/vertex-tooltip.d.ts +11 -0
- package/dist/components/vertex-tooltip.js +6 -0
- package/package.json +2 -2
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
|
|
2
|
+
import { c as classnames } from './index2.js';
|
|
3
|
+
import { _ as __assign } from './tslib.es6.js';
|
|
4
|
+
import { d as defineCustomElement$1 } from './popover.js';
|
|
5
|
+
|
|
6
|
+
class ElementPool {
|
|
7
|
+
constructor(container, elementFactory, eventHandlerFactory) {
|
|
8
|
+
this.container = container;
|
|
9
|
+
this.elementFactory = elementFactory;
|
|
10
|
+
this.eventHandlerFactory = eventHandlerFactory;
|
|
11
|
+
this.instanceMap = new Map();
|
|
12
|
+
this.handlerMap = new Map();
|
|
13
|
+
this.elements = [];
|
|
14
|
+
}
|
|
15
|
+
swapHeadToTail(count) {
|
|
16
|
+
const sliced = this.elements.splice(0, count);
|
|
17
|
+
this.elements.splice(this.elements.length, 0, ...sliced);
|
|
18
|
+
return this.elements.concat();
|
|
19
|
+
}
|
|
20
|
+
swapTailToHead(count) {
|
|
21
|
+
const sliced = this.elements.splice(-count, count);
|
|
22
|
+
this.elements.splice(0, 0, ...sliced);
|
|
23
|
+
return this.elements.concat();
|
|
24
|
+
}
|
|
25
|
+
updateElements(count) {
|
|
26
|
+
const diff = count - this.elements.length;
|
|
27
|
+
if (diff > 0) {
|
|
28
|
+
for (let i = 0; i < diff; i++) {
|
|
29
|
+
this.createElement();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
for (let i = 0; i < -diff; i++) {
|
|
34
|
+
this.deleteElement();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return this.elements.concat();
|
|
38
|
+
}
|
|
39
|
+
updateData(f) {
|
|
40
|
+
this.elements.forEach((el, i) => {
|
|
41
|
+
const instance = this.instanceMap.get(el);
|
|
42
|
+
const data = f(i);
|
|
43
|
+
instance === null || instance === void 0 ? void 0 : instance.bindings.bind(data);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
updateElementFactory(elementFactory) {
|
|
47
|
+
this.elementFactory = elementFactory;
|
|
48
|
+
this.updateElements(0);
|
|
49
|
+
}
|
|
50
|
+
iterateElements(f) {
|
|
51
|
+
this.elements.forEach((el, i) => {
|
|
52
|
+
const instance = this.instanceMap.get(el);
|
|
53
|
+
if (instance == null) {
|
|
54
|
+
throw new Error('Binding not found for element.');
|
|
55
|
+
}
|
|
56
|
+
f(el, instance.bindings, i);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
createElement() {
|
|
60
|
+
const instance = this.elementFactory();
|
|
61
|
+
this.elements.push(instance.element);
|
|
62
|
+
this.instanceMap.set(instance.element, instance);
|
|
63
|
+
this.container.append(instance.element);
|
|
64
|
+
this.addEventListeners(instance.element);
|
|
65
|
+
return instance;
|
|
66
|
+
}
|
|
67
|
+
addEventListeners(element) {
|
|
68
|
+
var _a;
|
|
69
|
+
const handlers = (_a = this.eventHandlerFactory) === null || _a === void 0 ? void 0 : _a.call(this, element);
|
|
70
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.forEach((d) => {
|
|
71
|
+
element.addEventListener(d.type, d.handler);
|
|
72
|
+
});
|
|
73
|
+
this.handlerMap.set(element, handlers !== null && handlers !== void 0 ? handlers : []);
|
|
74
|
+
}
|
|
75
|
+
deleteElement() {
|
|
76
|
+
const element = this.elements.pop();
|
|
77
|
+
if (element != null) {
|
|
78
|
+
this.instanceMap.delete(element);
|
|
79
|
+
element.remove();
|
|
80
|
+
this.removeEventListeners(element);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
removeEventListeners(element) {
|
|
84
|
+
var _a;
|
|
85
|
+
(_a = this.handlerMap.get(element)) === null || _a === void 0 ? void 0 : _a.forEach((d) => {
|
|
86
|
+
element.removeEventListener(d.type, d.handler);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Lower case as a function.
|
|
96
|
+
*/
|
|
97
|
+
function lowerCase(str) {
|
|
98
|
+
return str.toLowerCase();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
|
|
102
|
+
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
103
|
+
// Remove all non-word characters.
|
|
104
|
+
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
105
|
+
/**
|
|
106
|
+
* Normalize the string into something other libraries can manipulate easier.
|
|
107
|
+
*/
|
|
108
|
+
function noCase(input, options) {
|
|
109
|
+
if (options === void 0) { options = {}; }
|
|
110
|
+
var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
|
|
111
|
+
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
112
|
+
var start = 0;
|
|
113
|
+
var end = result.length;
|
|
114
|
+
// Trim the delimiter from around the output string.
|
|
115
|
+
while (result.charAt(start) === "\0")
|
|
116
|
+
start++;
|
|
117
|
+
while (result.charAt(end - 1) === "\0")
|
|
118
|
+
end--;
|
|
119
|
+
// Transform each token independently.
|
|
120
|
+
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Replace `re` in the input string with the replacement value.
|
|
124
|
+
*/
|
|
125
|
+
function replace(input, re, value) {
|
|
126
|
+
if (re instanceof RegExp)
|
|
127
|
+
return input.replace(re, value);
|
|
128
|
+
return re.reduce(function (input, re) { return input.replace(re, value); }, input);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function pascalCaseTransform(input, index) {
|
|
132
|
+
var firstChar = input.charAt(0);
|
|
133
|
+
var lowerChars = input.substr(1).toLowerCase();
|
|
134
|
+
if (index > 0 && firstChar >= "0" && firstChar <= "9") {
|
|
135
|
+
return "_" + firstChar + lowerChars;
|
|
136
|
+
}
|
|
137
|
+
return "" + firstChar.toUpperCase() + lowerChars;
|
|
138
|
+
}
|
|
139
|
+
function pascalCase(input, options) {
|
|
140
|
+
if (options === void 0) { options = {}; }
|
|
141
|
+
return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function camelCaseTransform(input, index) {
|
|
145
|
+
if (index === 0)
|
|
146
|
+
return input.toLowerCase();
|
|
147
|
+
return pascalCaseTransform(input, index);
|
|
148
|
+
}
|
|
149
|
+
function camelCase(input, options) {
|
|
150
|
+
if (options === void 0) { options = {}; }
|
|
151
|
+
return pascalCase(input, __assign({ transform: camelCaseTransform }, options));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const bindingRegEx = /{{(.+)}}/;
|
|
155
|
+
class CollectionBinding {
|
|
156
|
+
constructor(bindings) {
|
|
157
|
+
this.bindings = bindings;
|
|
158
|
+
}
|
|
159
|
+
bind(data) {
|
|
160
|
+
this.bindings.forEach((binding) => binding.bind(data));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
class NodeBinding {
|
|
164
|
+
constructor(node, expr) {
|
|
165
|
+
this.node = node;
|
|
166
|
+
this.expr = expr;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
class TextNodeBinding extends NodeBinding {
|
|
170
|
+
constructor(node, expr) {
|
|
171
|
+
super(node, expr);
|
|
172
|
+
}
|
|
173
|
+
bind(data) {
|
|
174
|
+
const newContent = replaceBindingString(data, this.expr);
|
|
175
|
+
if (newContent !== this.node.textContent) {
|
|
176
|
+
this.node.textContent = newContent;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
class AttributeBinding extends NodeBinding {
|
|
181
|
+
constructor(node, expr, attr) {
|
|
182
|
+
super(node, expr);
|
|
183
|
+
this.attr = attr;
|
|
184
|
+
}
|
|
185
|
+
bind(data) {
|
|
186
|
+
const newValue = replaceBindingString(data, this.expr);
|
|
187
|
+
const oldValue = this.node.getAttribute(this.attr);
|
|
188
|
+
if (oldValue !== newValue) {
|
|
189
|
+
this.node.setAttribute(this.attr, newValue);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
class PropertyBinding extends NodeBinding {
|
|
194
|
+
constructor(node, expr, prop) {
|
|
195
|
+
super(node, expr);
|
|
196
|
+
this.prop = prop;
|
|
197
|
+
}
|
|
198
|
+
bind(data) {
|
|
199
|
+
const newValue = replaceBinding(data, this.expr);
|
|
200
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
201
|
+
const oldValue = this.node[this.prop];
|
|
202
|
+
if (oldValue !== newValue) {
|
|
203
|
+
this.node[this.prop] = newValue;
|
|
204
|
+
}
|
|
205
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
class EventHandlerBinding extends NodeBinding {
|
|
209
|
+
constructor(node, expr, eventName) {
|
|
210
|
+
super(node, expr);
|
|
211
|
+
this.eventName = eventName;
|
|
212
|
+
}
|
|
213
|
+
bind(data) {
|
|
214
|
+
var _a;
|
|
215
|
+
const path = extractBindingPath(this.expr);
|
|
216
|
+
if (path != null) {
|
|
217
|
+
(_a = this.disposable) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
218
|
+
const listener = getBindableValue(data, path, true);
|
|
219
|
+
this.node.addEventListener(this.eventName, listener);
|
|
220
|
+
this.disposable = {
|
|
221
|
+
dispose: () => {
|
|
222
|
+
this.node.removeEventListener(this.eventName, listener);
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function generateBindings(node) {
|
|
229
|
+
const bindings = [];
|
|
230
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
231
|
+
const el = node;
|
|
232
|
+
const bindableAttributes = getBindableAttributes(el);
|
|
233
|
+
bindableAttributes.forEach((attr) => {
|
|
234
|
+
if (attr.name.startsWith('event:')) {
|
|
235
|
+
const eventName = camelCase(attr.name.replace('event:', ''));
|
|
236
|
+
bindings.push(new EventHandlerBinding(el, attr.value, eventName));
|
|
237
|
+
}
|
|
238
|
+
else if (attr.name.startsWith('attr:')) {
|
|
239
|
+
bindings.push(new AttributeBinding(el, attr.value, attr.name.replace('attr:', '')));
|
|
240
|
+
}
|
|
241
|
+
else if (attr.name.startsWith('prop:')) {
|
|
242
|
+
const propName = camelCase(attr.name.replace('prop:', ''));
|
|
243
|
+
bindings.push(new PropertyBinding(el, attr.value, propName));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
else if (node.nodeType === Node.TEXT_NODE &&
|
|
248
|
+
node.textContent != null &&
|
|
249
|
+
bindingRegEx.test(node.textContent)) {
|
|
250
|
+
bindings.push(new TextNodeBinding(node, node.textContent));
|
|
251
|
+
}
|
|
252
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
253
|
+
bindings.push(...generateBindings(node.childNodes[i]));
|
|
254
|
+
}
|
|
255
|
+
return bindings;
|
|
256
|
+
}
|
|
257
|
+
function getBindableAttributes(element) {
|
|
258
|
+
return Array.from(element.attributes).filter((attr) => bindingRegEx.test(attr.value));
|
|
259
|
+
}
|
|
260
|
+
function extractBindingPath(expr) {
|
|
261
|
+
const result = bindingRegEx.exec(expr);
|
|
262
|
+
return result != null ? result[1] : undefined;
|
|
263
|
+
}
|
|
264
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
265
|
+
function replaceBindingString(data, expr) {
|
|
266
|
+
const path = extractBindingPath(expr);
|
|
267
|
+
if (path != null) {
|
|
268
|
+
const value = getBindableValue(data, path, true);
|
|
269
|
+
return expr.replace(`{{${path}}}`, value === null || value === void 0 ? void 0 : value.toString());
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
return expr;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
276
|
+
function replaceBinding(data, expr) {
|
|
277
|
+
const path = extractBindingPath(expr);
|
|
278
|
+
if (path != null) {
|
|
279
|
+
const value = getBindableValue(data, path, true);
|
|
280
|
+
return value;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
return expr;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function getBindableValue(
|
|
287
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
288
|
+
data, path, isHead = false
|
|
289
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
290
|
+
) {
|
|
291
|
+
const [head, ...tail] = path.split('.');
|
|
292
|
+
if (isHead && tail.length === 0) {
|
|
293
|
+
return data;
|
|
294
|
+
}
|
|
295
|
+
else if (isHead && tail.length > 0) {
|
|
296
|
+
return getBindableValue(data, tail.join('.'), false);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
const value = data[head];
|
|
300
|
+
if (tail.length > 0) {
|
|
301
|
+
return getBindableValue(value, tail.join('.'), false);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
return value;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function generateInstanceFromTemplate(template) {
|
|
310
|
+
const fragment = template.content.cloneNode(true);
|
|
311
|
+
const element = fragment.firstElementChild;
|
|
312
|
+
const bindings = new CollectionBinding(generateBindings(fragment));
|
|
313
|
+
return { element, bindings };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const getResultListHeight = (el) => {
|
|
317
|
+
return el.clientHeight;
|
|
318
|
+
};
|
|
319
|
+
const scrollToResult = (el, lastFocusedIndex, resultHeight) => {
|
|
320
|
+
el === null || el === void 0 ? void 0 : el.scrollTo({
|
|
321
|
+
top: lastFocusedIndex != null && resultHeight != null
|
|
322
|
+
? lastFocusedIndex * resultHeight
|
|
323
|
+
: 0,
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const resultListCss = ":host{--max-height:300px;--width:500px;--box-shadow:0 2px 5px rgba(0, 0, 0, 0.5)}.hidden{visibility:hidden;position:fixed;pointer-events:none}.results{position:relative;height:100%}.results-scroll{overflow-y:auto;max-height:var(--max-height);width:var(--width);box-shadow:var(--box-shadow);background-color:white}";
|
|
328
|
+
|
|
329
|
+
const ResultList = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
330
|
+
constructor() {
|
|
331
|
+
super();
|
|
332
|
+
this.__registerHost();
|
|
333
|
+
this.__attachShadow();
|
|
334
|
+
this.enterPressed = createEvent(this, "enterPressed", 7);
|
|
335
|
+
this.resultClick = createEvent(this, "resultClick", 7);
|
|
336
|
+
this.computeResultHeight = () => {
|
|
337
|
+
if (this.computedResultHeight == null) {
|
|
338
|
+
const result = this.hostEl.querySelector('*[slot="result"]');
|
|
339
|
+
if (result != null) {
|
|
340
|
+
this.resultHeight = result.clientHeight;
|
|
341
|
+
this.computedResultHeight = result.clientHeight;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
this.ensureTemplateDefined = () => {
|
|
346
|
+
const template = this.hostEl.querySelector('template');
|
|
347
|
+
if (template == null) {
|
|
348
|
+
const defaultTemplate = document.createElement('template');
|
|
349
|
+
defaultTemplate.innerHTML = `
|
|
350
|
+
<div class="result">{{data.value}}</div>
|
|
351
|
+
`;
|
|
352
|
+
this.hostEl.appendChild(defaultTemplate);
|
|
353
|
+
this.stateMap.resultTemplate = defaultTemplate;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
this.stateMap.resultTemplate = template;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
this.createResultPool = () => {
|
|
360
|
+
this.stateMap.resultPool = new ElementPool(this.hostEl, () => this.createResultInstance(), () => this.createResultHandlers());
|
|
361
|
+
};
|
|
362
|
+
this.createResultInstance = () => {
|
|
363
|
+
if (this.stateMap.resultTemplate != null) {
|
|
364
|
+
const instance = generateInstanceFromTemplate(this.stateMap.resultTemplate);
|
|
365
|
+
instance.element.slot = 'result';
|
|
366
|
+
return instance;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
throw new Error('Result template not defined.');
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
this.createResultHandlers = () => {
|
|
373
|
+
return [
|
|
374
|
+
{
|
|
375
|
+
type: 'pointerdown',
|
|
376
|
+
handler: this.handlePointerDown,
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
type: 'click',
|
|
380
|
+
handler: this.handleResultClick,
|
|
381
|
+
},
|
|
382
|
+
];
|
|
383
|
+
};
|
|
384
|
+
this.layoutResults = () => {
|
|
385
|
+
var _a, _b, _c, _d;
|
|
386
|
+
const visibleRowCount = this.viewportEndIndex - this.viewportStartIndex + 1;
|
|
387
|
+
const diff = this.viewportStartIndex - this.lastStartIndex;
|
|
388
|
+
this.lastStartIndex = this.viewportStartIndex;
|
|
389
|
+
(_a = this.stateMap.resultPool) === null || _a === void 0 ? void 0 : _a.updateElements(visibleRowCount);
|
|
390
|
+
if (diff > 0) {
|
|
391
|
+
(_b = this.stateMap.resultPool) === null || _b === void 0 ? void 0 : _b.swapHeadToTail(diff);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
(_c = this.stateMap.resultPool) === null || _c === void 0 ? void 0 : _c.swapTailToHead(-diff);
|
|
395
|
+
}
|
|
396
|
+
(_d = this.stateMap.resultPool) === null || _d === void 0 ? void 0 : _d.iterateElements((el, binding, index) => {
|
|
397
|
+
const result = this.parsedResults[index + this.viewportStartIndex];
|
|
398
|
+
if (result != null) {
|
|
399
|
+
el.style.position = 'absolute';
|
|
400
|
+
el.style.boxSizing = 'border-box';
|
|
401
|
+
el.style.top = `${(this.viewportStartIndex + index) * this.resultHeight}px`;
|
|
402
|
+
el.style.width = '100%';
|
|
403
|
+
el.setAttribute('is-focused', `${this.viewportStartIndex + index === this.lastFocusedIndex}`);
|
|
404
|
+
el.setAttribute('data-result-id', result.id);
|
|
405
|
+
binding.bind(result);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
this.handleScroll = (event) => {
|
|
410
|
+
this.scrollTop = event.target.scrollTop;
|
|
411
|
+
};
|
|
412
|
+
this.handleKeyDown = (event) => {
|
|
413
|
+
if (this.open) {
|
|
414
|
+
if (event.key === 'ArrowUp') {
|
|
415
|
+
event.preventDefault();
|
|
416
|
+
this.lastFocusedIndex = Math.min(0, this.lastFocusedIndex - 1);
|
|
417
|
+
scrollToResult(this.resultsScrollEl, this.lastFocusedIndex, this.resultHeight);
|
|
418
|
+
}
|
|
419
|
+
else if (event.key === 'ArrowDown') {
|
|
420
|
+
event.preventDefault();
|
|
421
|
+
this.lastFocusedIndex = Math.min(this.lastFocusedIndex + 1, this.items.length);
|
|
422
|
+
scrollToResult(this.resultsScrollEl, this.lastFocusedIndex, this.resultHeight);
|
|
423
|
+
}
|
|
424
|
+
if (event.key === 'Enter' && this.lastFocusedIndex != null) {
|
|
425
|
+
event.preventDefault();
|
|
426
|
+
this.enterPressed.emit(this.items[this.lastFocusedIndex]);
|
|
427
|
+
this.lastFocusedIndex = 0;
|
|
428
|
+
scrollToResult(this.resultsScrollEl);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
this.items = [];
|
|
433
|
+
this.itemsJson = undefined;
|
|
434
|
+
this.viewportStartIndex = 0;
|
|
435
|
+
this.viewportEndIndex = 0;
|
|
436
|
+
this.resultHeight = 32;
|
|
437
|
+
this.overScanCount = 25;
|
|
438
|
+
this.placement = 'bottom-start';
|
|
439
|
+
this.position = undefined;
|
|
440
|
+
this.open = false;
|
|
441
|
+
this.listHeight = undefined;
|
|
442
|
+
this.parsedResults = [];
|
|
443
|
+
this.scrollTop = 0;
|
|
444
|
+
this.lastStartIndex = 0;
|
|
445
|
+
this.lastFocusedIndex = 0;
|
|
446
|
+
this.stateMap = {};
|
|
447
|
+
this.handleResultClick = this.handleResultClick.bind(this);
|
|
448
|
+
this.handlePointerDown = this.handlePointerDown.bind(this);
|
|
449
|
+
}
|
|
450
|
+
handleResultsChanged(results) {
|
|
451
|
+
if (typeof results === 'string') {
|
|
452
|
+
this.parsedResults = JSON.parse(results);
|
|
453
|
+
}
|
|
454
|
+
else if (results != null) {
|
|
455
|
+
this.parsedResults = results;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
handleOpenChanged() {
|
|
459
|
+
if (!this.open && this.scrollTop !== 0) {
|
|
460
|
+
scrollToResult(this.resultsScrollEl);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
componentWillLoad() {
|
|
464
|
+
var _a;
|
|
465
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
466
|
+
this.listHeight = undefined;
|
|
467
|
+
});
|
|
468
|
+
window.addEventListener('keydown', this.handleKeyDown);
|
|
469
|
+
this.ensureTemplateDefined();
|
|
470
|
+
this.createResultPool();
|
|
471
|
+
this.handleResultsChanged((_a = this.itemsJson) !== null && _a !== void 0 ? _a : this.items);
|
|
472
|
+
}
|
|
473
|
+
componentDidLoad() {
|
|
474
|
+
this.resizeObserver.observe(this.hostEl);
|
|
475
|
+
}
|
|
476
|
+
componentWillRender() {
|
|
477
|
+
this.computeViewportResults();
|
|
478
|
+
}
|
|
479
|
+
componentDidRender() {
|
|
480
|
+
this.layoutResults();
|
|
481
|
+
this.computeResultHeight();
|
|
482
|
+
}
|
|
483
|
+
disconnectedCallback() {
|
|
484
|
+
this.resizeObserver.disconnect();
|
|
485
|
+
window.removeEventListener('keydown', this.handleKeyDown);
|
|
486
|
+
}
|
|
487
|
+
render() {
|
|
488
|
+
return (h(Host, null, h("div", { class: classnames('wrapper', {
|
|
489
|
+
hidden: !this.open || this.computedResultHeight == null,
|
|
490
|
+
}) }, h("vertex-popover", { position: this.position, placement: this.placement, open: this.open, backdrop: false }, h("div", { class: "results-scroll", ref: (ref) => (this.resultsScrollEl = ref), onScroll: this.handleScroll }, h("div", { class: "results", style: {
|
|
491
|
+
height: `${this.parsedResults.length * this.resultHeight}px`,
|
|
492
|
+
} }, h("slot", null), h("slot", { name: "result" })))))));
|
|
493
|
+
}
|
|
494
|
+
handlePointerDown(event) {
|
|
495
|
+
event.preventDefault();
|
|
496
|
+
}
|
|
497
|
+
handleResultClick(event) {
|
|
498
|
+
const closestIdElement = event.target.closest('[data-result-id]');
|
|
499
|
+
const result = this.parsedResults.find((r) => r.id === (closestIdElement === null || closestIdElement === void 0 ? void 0 : closestIdElement.getAttribute('data-result-id')));
|
|
500
|
+
if (result != null) {
|
|
501
|
+
this.resultClick.emit(result);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
computeViewportResults() {
|
|
505
|
+
const viewportHeight = this.getListHeight();
|
|
506
|
+
if (viewportHeight != null && this.resultHeight > 0) {
|
|
507
|
+
const viewportCount = Math.ceil(viewportHeight / this.resultHeight);
|
|
508
|
+
const viewportStartIndex = Math.floor(this.scrollTop / this.resultHeight);
|
|
509
|
+
const viewportEndIndex = viewportStartIndex + viewportCount;
|
|
510
|
+
const startIndex = Math.max(0, viewportStartIndex - this.overScanCount);
|
|
511
|
+
const endIndex = Math.min(this.parsedResults.length - 1, viewportEndIndex + this.overScanCount);
|
|
512
|
+
this.viewportStartIndex = startIndex;
|
|
513
|
+
this.viewportEndIndex = endIndex;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
getListHeight() {
|
|
517
|
+
if (this.listHeight == null) {
|
|
518
|
+
this.listHeight = getResultListHeight(this.hostEl);
|
|
519
|
+
}
|
|
520
|
+
return this.listHeight;
|
|
521
|
+
}
|
|
522
|
+
get hostEl() { return this; }
|
|
523
|
+
static get watchers() { return {
|
|
524
|
+
"items": ["handleResultsChanged"],
|
|
525
|
+
"open": ["handleOpenChanged"]
|
|
526
|
+
}; }
|
|
527
|
+
static get style() { return resultListCss; }
|
|
528
|
+
}, [1, "vertex-result-list", {
|
|
529
|
+
"items": [16],
|
|
530
|
+
"itemsJson": [1, "items"],
|
|
531
|
+
"viewportStartIndex": [1026, "viewport-start-index"],
|
|
532
|
+
"viewportEndIndex": [1026, "viewport-end-index"],
|
|
533
|
+
"resultHeight": [1026, "result-height"],
|
|
534
|
+
"overScanCount": [2, "over-scan-count"],
|
|
535
|
+
"placement": [1],
|
|
536
|
+
"position": [1],
|
|
537
|
+
"open": [4],
|
|
538
|
+
"listHeight": [32],
|
|
539
|
+
"parsedResults": [32],
|
|
540
|
+
"scrollTop": [32],
|
|
541
|
+
"lastStartIndex": [32],
|
|
542
|
+
"lastFocusedIndex": [32],
|
|
543
|
+
"stateMap": [32]
|
|
544
|
+
}]);
|
|
545
|
+
function defineCustomElement() {
|
|
546
|
+
if (typeof customElements === "undefined") {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
const components = ["vertex-result-list", "vertex-popover"];
|
|
550
|
+
components.forEach(tagName => { switch (tagName) {
|
|
551
|
+
case "vertex-result-list":
|
|
552
|
+
if (!customElements.get(tagName)) {
|
|
553
|
+
customElements.define(tagName, ResultList);
|
|
554
|
+
}
|
|
555
|
+
break;
|
|
556
|
+
case "vertex-popover":
|
|
557
|
+
if (!customElements.get(tagName)) {
|
|
558
|
+
defineCustomElement$1();
|
|
559
|
+
}
|
|
560
|
+
break;
|
|
561
|
+
} });
|
|
562
|
+
}
|
|
563
|
+
defineCustomElement();
|
|
564
|
+
|
|
565
|
+
export { ResultList as R, defineCustomElement as d, generateInstanceFromTemplate as g };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function getFirstSlottedElement({ hostElement, slotName, selector, }) {
|
|
2
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3
|
+
if (selector != null) {
|
|
4
|
+
return ((_c = (_b = (_a = hostElement.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(selector)) !== null && _b !== void 0 ? _b : hostElement.querySelector(selector)) !== null && _c !== void 0 ? _c : undefined);
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
const slotted = (_e = (_d = hostElement.shadowRoot) === null || _d === void 0 ? void 0 : _d.querySelector(slotName != null ? `slot[name="${slotName}"]` : 'slot')) !== null && _e !== void 0 ? _e : undefined;
|
|
8
|
+
if ((_g = (_f = slotted === null || slotted === void 0 ? void 0 : slotted.assignedElements) === null || _f === void 0 ? void 0 : _f.call(slotted).length) !== null && _g !== void 0 ? _g : 0 > 0) {
|
|
9
|
+
return slotted === null || slotted === void 0 ? void 0 : slotted.assignedElements()[0];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function getSlottedContent(slotOrParentElement) {
|
|
14
|
+
const slot = isSlotElement(slotOrParentElement)
|
|
15
|
+
? slotOrParentElement
|
|
16
|
+
: slotOrParentElement === null || slotOrParentElement === void 0 ? void 0 : slotOrParentElement.querySelector('slot');
|
|
17
|
+
if (slot != null) {
|
|
18
|
+
return slot.assignedElements()[0];
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
function isSlotElement(element) {
|
|
23
|
+
return (element === null || element === void 0 ? void 0 : element.tagName) === 'SLOT';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { getSlottedContent as a, getFirstSlottedElement as g };
|