@vertexvis/ui 0.1.0-canary.7 → 0.1.0-canary.8
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/cjs/components.cjs.js +1 -1
- package/dist/cjs/index.cjs.js +2 -2
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{result-list-1e592c3c.js → result-list-241ffe8d.js} +46 -2
- package/dist/cjs/search-bar-91cbcd07.js +421 -0
- package/dist/cjs/vertex-result-list.cjs.entry.js +1 -1
- package/dist/cjs/vertex-search-bar.cjs.entry.js +1 -1
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/result-list/result-list.js +52 -5
- package/dist/collection/components/result-list/types.js +1 -0
- package/dist/collection/components/search-bar/dom.js +12 -0
- package/dist/collection/components/search-bar/lib.js +35 -15
- package/dist/collection/components/search-bar/search-bar.css +0 -16
- package/dist/collection/components/search-bar/search-bar.js +380 -324
- package/dist/collection/util/templates/element-pool.js +19 -1
- package/dist/components/components.esm.js +1 -1
- package/dist/components/index.esm.js +1 -1
- package/dist/components/p-6b862967.js +1 -0
- package/dist/components/p-cfe369bf.entry.js +1 -0
- package/dist/components/p-db34f10c.js +1 -0
- package/dist/components/p-ee496965.entry.js +1 -0
- package/dist/esm/components.js +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{result-list-36cfb08a.js → result-list-16c6afbd.js} +46 -2
- package/dist/esm/search-bar-f12a3599.js +419 -0
- package/dist/esm/vertex-result-list.entry.js +1 -1
- package/dist/esm/vertex-search-bar.entry.js +1 -1
- package/dist/types/components/result-list/result-list.d.ts +6 -1
- package/dist/types/components/result-list/types.d.ts +4 -0
- package/dist/types/components/search-bar/dom.d.ts +3 -0
- package/dist/types/components/search-bar/lib.d.ts +24 -6
- package/dist/types/components/search-bar/search-bar.d.ts +124 -42
- package/dist/types/components.d.ts +81 -20
- package/dist/types/util/templates/element-pool.d.ts +10 -1
- package/package.json +4 -3
- package/dist/cjs/search-bar-bb40cfa7.js +0 -290
- package/dist/components/p-19318fee.entry.js +0 -1
- package/dist/components/p-4224c2ad.js +0 -1
- package/dist/components/p-52739247.js +0 -1
- package/dist/components/p-ae6a3c46.entry.js +0 -1
- package/dist/esm/search-bar-59cc151d.js +0 -288
|
@@ -0,0 +1,419 @@
|
|
|
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
|
+
// do not edit .js files directly - edit src/index.jst
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var fastDeepEqual = function equal(a, b) {
|
|
10
|
+
if (a === b) return true;
|
|
11
|
+
|
|
12
|
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
13
|
+
if (a.constructor !== b.constructor) return false;
|
|
14
|
+
|
|
15
|
+
var length, i, keys;
|
|
16
|
+
if (Array.isArray(a)) {
|
|
17
|
+
length = a.length;
|
|
18
|
+
if (length != b.length) return false;
|
|
19
|
+
for (i = length; i-- !== 0;)
|
|
20
|
+
if (!equal(a[i], b[i])) return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
27
|
+
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
28
|
+
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
29
|
+
|
|
30
|
+
keys = Object.keys(a);
|
|
31
|
+
length = keys.length;
|
|
32
|
+
if (length !== Object.keys(b).length) return false;
|
|
33
|
+
|
|
34
|
+
for (i = length; i-- !== 0;)
|
|
35
|
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
36
|
+
|
|
37
|
+
for (i = length; i-- !== 0;) {
|
|
38
|
+
var key = keys[i];
|
|
39
|
+
|
|
40
|
+
if (!equal(a[key], b[key])) return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// true if both NaN, false otherwise
|
|
47
|
+
return a!==a && b!==b;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getWindowSelection = () => {
|
|
51
|
+
if (typeof window !== 'undefined') {
|
|
52
|
+
return window.getSelection();
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
};
|
|
56
|
+
const createDocumentRange = () => {
|
|
57
|
+
return document.createRange();
|
|
58
|
+
};
|
|
59
|
+
const createTextNode = (text) => {
|
|
60
|
+
return new Text(text);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const createResultUri = (result) => {
|
|
64
|
+
return `${result.type}:${result.id}`;
|
|
65
|
+
};
|
|
66
|
+
const createSearchResultReplacement = (result, before, after) => {
|
|
67
|
+
const urn = createResultUri(result);
|
|
68
|
+
return {
|
|
69
|
+
before: createTextNode(before),
|
|
70
|
+
beforeSpace: createTextNode(createHairSpace()),
|
|
71
|
+
result: createTextNode(urn),
|
|
72
|
+
afterSpace: after != null ? createTextNode(createNoBreakSpace()) : undefined,
|
|
73
|
+
after: after != null ? createTextNode(after) : undefined,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const getNodesForSearchResultReplacement = (replacement) => {
|
|
77
|
+
const keys = Object.keys(replacement);
|
|
78
|
+
return keys
|
|
79
|
+
.map((key) => replacement[key])
|
|
80
|
+
.filter((node) => node != null);
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* We leverage a couple unique spaces to represent mentions, allowing for
|
|
84
|
+
* correct cursor movement when using arrow keys. As these characters are
|
|
85
|
+
* purely for functional behavior of the input, `trimNonstandardSpaces`
|
|
86
|
+
* will remove them so the input is suitable for emitting.
|
|
87
|
+
*
|
|
88
|
+
* U+200A is a "Hair Space" which acts as a space, but is not visually
|
|
89
|
+
* represented as one.
|
|
90
|
+
*
|
|
91
|
+
* U+00A0 is a "No-Break Space" which is commonly added by browsers
|
|
92
|
+
* when interacting with a contenteditable element.
|
|
93
|
+
*/
|
|
94
|
+
const trimNonstandardSpaces = (text) => {
|
|
95
|
+
return text.replace(/[\u200A]/g, '').replace(/[\u00A0]/g, ' ');
|
|
96
|
+
};
|
|
97
|
+
const createHairSpace = () => {
|
|
98
|
+
return String.fromCharCode(8202);
|
|
99
|
+
};
|
|
100
|
+
const createNoBreakSpace = () => {
|
|
101
|
+
return String.fromCharCode(160);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
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)}";
|
|
105
|
+
|
|
106
|
+
const SearchBar = class {
|
|
107
|
+
constructor(hostRef) {
|
|
108
|
+
registerInstance(this, hostRef);
|
|
109
|
+
this.searchChanged = createEvent(this, "searchChanged", 7);
|
|
110
|
+
this.inputChanged = createEvent(this, "inputChanged", 7);
|
|
111
|
+
this.resultReplaced = createEvent(this, "resultReplaced", 7);
|
|
112
|
+
this.inputFocus = createEvent(this, "inputFocus", 7);
|
|
113
|
+
this.inputBlur = createEvent(this, "inputBlur", 7);
|
|
114
|
+
this.rawElements = [];
|
|
115
|
+
this.isIdenticalElement = (child, other) => {
|
|
116
|
+
return (child === this.triggeredElement ||
|
|
117
|
+
this.getTextContent(child) === this.getTextContent(other));
|
|
118
|
+
};
|
|
119
|
+
this.getTextContent = (node) => {
|
|
120
|
+
var _a;
|
|
121
|
+
if (node instanceof HTMLElement) {
|
|
122
|
+
return node.innerText;
|
|
123
|
+
}
|
|
124
|
+
return (_a = node.textContent) !== null && _a !== void 0 ? _a : '';
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Inspects the cursor position for the following conditions:
|
|
128
|
+
*
|
|
129
|
+
* 1. The cursor has moved to text that contains a valid string
|
|
130
|
+
* and trigger character, indicating we need to dispatch a
|
|
131
|
+
* `searchChanged` event and display the results.
|
|
132
|
+
*
|
|
133
|
+
* 2. The cursor has moved within text that contains a valid string
|
|
134
|
+
* and trigger character, indicating we need to dispatch a
|
|
135
|
+
* `searchChanged` event to update the currently displayed results.
|
|
136
|
+
*
|
|
137
|
+
* 3. The cursor has moved to text that does not contain a valid
|
|
138
|
+
* string and trigger character, indicating we need to hide any
|
|
139
|
+
* displayed search results.
|
|
140
|
+
*/
|
|
141
|
+
this.handleCursorPositionUpdate = () => {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
const windowRange = (_a = getWindowSelection()) === null || _a === void 0 ? void 0 : _a.getRangeAt(0);
|
|
144
|
+
if (windowRange != null) {
|
|
145
|
+
const triggerText = this.readTriggerValue((_b = windowRange.commonAncestorContainer.textContent) !== null && _b !== void 0 ? _b : '', windowRange.startOffset);
|
|
146
|
+
if (!this.hasTriggered && triggerText != null) {
|
|
147
|
+
this.hasTriggered = true;
|
|
148
|
+
this.triggeredRange = windowRange;
|
|
149
|
+
this.triggeredElement = windowRange.commonAncestorContainer;
|
|
150
|
+
this.searchChanged.emit(triggerText.replace(this.triggerCharacter, ''));
|
|
151
|
+
}
|
|
152
|
+
else if (this.hasTriggered && triggerText != null) {
|
|
153
|
+
this.triggeredRange = windowRange;
|
|
154
|
+
this.triggeredElement = windowRange.commonAncestorContainer;
|
|
155
|
+
this.searchChanged.emit(triggerText.replace(this.triggerCharacter, ''));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.hasTriggered = false;
|
|
159
|
+
this.triggeredRange = undefined;
|
|
160
|
+
this.triggeredElement = undefined;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
this.cursorPosition = this.getCursorPosition();
|
|
164
|
+
};
|
|
165
|
+
this.readTriggerValue = (value, fromIndex) => {
|
|
166
|
+
const adjustedValue = value.replace(String.fromCharCode(160), ' ');
|
|
167
|
+
const beforeSubstr = adjustedValue.substring(0, fromIndex);
|
|
168
|
+
const afterSubstr = adjustedValue.substring(fromIndex);
|
|
169
|
+
const adjustedBeforeSubstr = beforeSubstr.includes(this.triggerCharacter)
|
|
170
|
+
? beforeSubstr.substring(beforeSubstr.lastIndexOf(this.triggerCharacter))
|
|
171
|
+
: '';
|
|
172
|
+
const adjustedAfterSubstr = afterSubstr.substring(0, this.firstIndexOfBreakCharacter(afterSubstr));
|
|
173
|
+
const result = `${adjustedBeforeSubstr}${adjustedAfterSubstr}`;
|
|
174
|
+
return result.includes(this.triggerCharacter) &&
|
|
175
|
+
!this.includesBreakCharacter(result)
|
|
176
|
+
? result
|
|
177
|
+
: undefined;
|
|
178
|
+
};
|
|
179
|
+
this.includesBreakCharacter = (value) => {
|
|
180
|
+
return this.breakCharacters.some((bc) => value.includes(bc));
|
|
181
|
+
};
|
|
182
|
+
this.firstIndexOfBreakCharacter = (value) => {
|
|
183
|
+
const indices = this.breakCharacters
|
|
184
|
+
.map((bc) => value.indexOf(bc))
|
|
185
|
+
.filter((i) => i >= 0);
|
|
186
|
+
return indices.length > 0 ? Math.min(...indices) : value.length;
|
|
187
|
+
};
|
|
188
|
+
this.moveCursorToNodeEnd = (node, collapseToStart = false) => {
|
|
189
|
+
const selection = getWindowSelection();
|
|
190
|
+
if (selection != null) {
|
|
191
|
+
const range = createDocumentRange();
|
|
192
|
+
range.selectNodeContents(node);
|
|
193
|
+
range.collapse(collapseToStart);
|
|
194
|
+
selection.removeAllRanges();
|
|
195
|
+
selection.addRange(range);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
this.getContentAsString = () => {
|
|
199
|
+
if (this.contentEl != null) {
|
|
200
|
+
return trimNonstandardSpaces(Array.from(this.contentEl.childNodes).reduce((res, n) => {
|
|
201
|
+
var _a;
|
|
202
|
+
if (n instanceof HTMLElement &&
|
|
203
|
+
n.getAttribute('data-replaced') === 'true') {
|
|
204
|
+
return `${res}${n.getAttribute('data-original')}`;
|
|
205
|
+
}
|
|
206
|
+
else if (n instanceof HTMLElement) {
|
|
207
|
+
return `${res}${n.innerText}`;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
return `${res}${(_a = n.textContent) !== null && _a !== void 0 ? _a : ''}`;
|
|
211
|
+
}
|
|
212
|
+
}, ''));
|
|
213
|
+
}
|
|
214
|
+
return '';
|
|
215
|
+
};
|
|
216
|
+
this.createReplacedElement = (original, data) => {
|
|
217
|
+
const template = this.hostEl.querySelector('template[slot="replaced"]');
|
|
218
|
+
if (template != null) {
|
|
219
|
+
const instance = generateInstanceFromTemplate(template);
|
|
220
|
+
instance.bindings.bind(data);
|
|
221
|
+
instance.element.id = data.id;
|
|
222
|
+
instance.element.style.display = 'inline-block';
|
|
223
|
+
instance.element.contentEditable = 'false';
|
|
224
|
+
instance.element.tabIndex = -1;
|
|
225
|
+
instance.element.setAttribute('data-replaced', 'true');
|
|
226
|
+
instance.element.setAttribute('data-original', original);
|
|
227
|
+
return instance.element;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
throw new Error('Replaced template not defined.');
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
this.variant = 'standard';
|
|
234
|
+
this.disabled = false;
|
|
235
|
+
this.triggerCharacter = '@';
|
|
236
|
+
this.breakCharacters = [' ', '\n'];
|
|
237
|
+
this.resultItems = undefined;
|
|
238
|
+
this.placement = 'bottom-start';
|
|
239
|
+
this.value = undefined;
|
|
240
|
+
this.placeholder = undefined;
|
|
241
|
+
this.replacements = [];
|
|
242
|
+
this.replacementUriType = 'user';
|
|
243
|
+
this.cursorPosition = undefined;
|
|
244
|
+
this.displayedElements = [];
|
|
245
|
+
this.hasTriggered = false;
|
|
246
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
247
|
+
this.handleKeyUp = this.handleKeyUp.bind(this);
|
|
248
|
+
this.handleResultClick = this.handleResultClick.bind(this);
|
|
249
|
+
this.handleClick = this.handleClick.bind(this);
|
|
250
|
+
this.handleWindowClick = this.handleWindowClick.bind(this);
|
|
251
|
+
this.handleInput = this.handleInput.bind(this);
|
|
252
|
+
this.handleBlur = this.handleBlur.bind(this);
|
|
253
|
+
this.handleFocus = this.handleFocus.bind(this);
|
|
254
|
+
this.handleCursorPositionUpdate =
|
|
255
|
+
this.handleCursorPositionUpdate.bind(this);
|
|
256
|
+
this.updateContent = this.updateContent.bind(this);
|
|
257
|
+
this.replaceContent = this.replaceContent.bind(this);
|
|
258
|
+
}
|
|
259
|
+
componentDidLoad() {
|
|
260
|
+
this.replaceContent(this.value);
|
|
261
|
+
}
|
|
262
|
+
connectedCallback() {
|
|
263
|
+
window.addEventListener('click', this.handleWindowClick);
|
|
264
|
+
}
|
|
265
|
+
disconnectedCallback() {
|
|
266
|
+
window.removeEventListener('click', this.handleWindowClick);
|
|
267
|
+
}
|
|
268
|
+
replaceContent(newValue, oldValue) {
|
|
269
|
+
if (newValue != null && newValue !== oldValue) {
|
|
270
|
+
const pattern = `${this.replacementUriType}:[0-9a-z-]{36}`;
|
|
271
|
+
const matches = newValue.match(new RegExp(pattern, 'g'));
|
|
272
|
+
const replacementsMap = this.replacements.reduce((map, r) => (Object.assign(Object.assign({}, map), { [createResultUri(r)]: r })), {});
|
|
273
|
+
let nextSubstr = newValue;
|
|
274
|
+
const parts = matches != null
|
|
275
|
+
? matches === null || matches === void 0 ? void 0 : matches.reduce((res, m) => {
|
|
276
|
+
if (replacementsMap[m] != null) {
|
|
277
|
+
const urn = createResultUri(replacementsMap[m]);
|
|
278
|
+
const index = nextSubstr.indexOf(urn);
|
|
279
|
+
const before = nextSubstr.substring(0, index);
|
|
280
|
+
const after = nextSubstr.substring(index + urn.length);
|
|
281
|
+
const replacement = createSearchResultReplacement(replacementsMap[m], before);
|
|
282
|
+
nextSubstr = after;
|
|
283
|
+
return [
|
|
284
|
+
...res,
|
|
285
|
+
replacement.before,
|
|
286
|
+
replacement.beforeSpace,
|
|
287
|
+
replacement.result,
|
|
288
|
+
];
|
|
289
|
+
}
|
|
290
|
+
return res;
|
|
291
|
+
}, [])
|
|
292
|
+
: [];
|
|
293
|
+
this.rawElements = [...parts, createTextNode(nextSubstr)];
|
|
294
|
+
this.updateContent(this.replacements);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
updateContent(newValue, oldValue) {
|
|
298
|
+
if (this.contentEl != null && !fastDeepEqual(newValue, oldValue)) {
|
|
299
|
+
this.contentEl.innerHTML = '';
|
|
300
|
+
this.displayedElements = this.rawElements.map((el) => {
|
|
301
|
+
const raw = el instanceof HTMLElement ? el.innerText : el.textContent;
|
|
302
|
+
const replacement = this.replacements.find((r) => raw === null || raw === void 0 ? void 0 : raw.includes(createResultUri(r)));
|
|
303
|
+
if (raw != null && replacement != null) {
|
|
304
|
+
const replacementElement = this.createReplacedElement(raw, replacement);
|
|
305
|
+
return replacementElement;
|
|
306
|
+
}
|
|
307
|
+
return el;
|
|
308
|
+
});
|
|
309
|
+
this.displayedElements.forEach((el) => {
|
|
310
|
+
var _a;
|
|
311
|
+
(_a = this.contentEl) === null || _a === void 0 ? void 0 : _a.appendChild(typeof el === 'string' ? createTextNode(el) : el);
|
|
312
|
+
});
|
|
313
|
+
if (this.lastReplacedSpace != null) {
|
|
314
|
+
this.moveCursorToNodeEnd(this.lastReplacedSpace);
|
|
315
|
+
}
|
|
316
|
+
this.inputChanged.emit(this.getContentAsString());
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
render() {
|
|
320
|
+
var _a;
|
|
321
|
+
const classes = classnames('wrapper', {
|
|
322
|
+
standard: this.variant === 'standard',
|
|
323
|
+
filled: this.variant === 'filled',
|
|
324
|
+
underlined: this.variant === 'underlined',
|
|
325
|
+
blank: this.variant === 'blank',
|
|
326
|
+
disabled: this.disabled,
|
|
327
|
+
});
|
|
328
|
+
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 &&
|
|
329
|
+
this.resultItems != null &&
|
|
330
|
+
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" })));
|
|
331
|
+
}
|
|
332
|
+
handleKeyDown(event) {
|
|
333
|
+
if (this.hasTriggered && this.breakCharacters.includes(event.key)) {
|
|
334
|
+
this.hasTriggered = false;
|
|
335
|
+
this.triggeredRange = undefined;
|
|
336
|
+
this.triggeredElement = undefined;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
handleKeyUp(event) {
|
|
340
|
+
this.handleCursorPositionUpdate();
|
|
341
|
+
this.cursorPosition = this.getCursorPosition();
|
|
342
|
+
}
|
|
343
|
+
async handleInput() {
|
|
344
|
+
this.inputChanged.emit(this.getContentAsString());
|
|
345
|
+
}
|
|
346
|
+
handleClick() {
|
|
347
|
+
this.handleCursorPositionUpdate();
|
|
348
|
+
}
|
|
349
|
+
handleWindowClick(event) {
|
|
350
|
+
if (event.target instanceof HTMLElement &&
|
|
351
|
+
event.target.getAttribute('data-replaced') === 'true' &&
|
|
352
|
+
event.target.nextSibling != null) {
|
|
353
|
+
this.moveCursorToNodeEnd(event.target.nextSibling, true);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
handleFocus(event) {
|
|
357
|
+
this.inputFocus.emit(event);
|
|
358
|
+
}
|
|
359
|
+
handleBlur(event) {
|
|
360
|
+
this.hasTriggered = false;
|
|
361
|
+
this.inputBlur.emit(event);
|
|
362
|
+
}
|
|
363
|
+
handleResultClick(event) {
|
|
364
|
+
var _a;
|
|
365
|
+
const triggeredRange = this.triggeredRange;
|
|
366
|
+
const triggeredElement = this.triggeredElement;
|
|
367
|
+
const value = triggeredElement instanceof HTMLElement
|
|
368
|
+
? triggeredElement.innerText
|
|
369
|
+
: triggeredElement === null || triggeredElement === void 0 ? void 0 : triggeredElement.textContent;
|
|
370
|
+
if (this.contentEl != null &&
|
|
371
|
+
triggeredRange != null &&
|
|
372
|
+
triggeredElement != null &&
|
|
373
|
+
value != null) {
|
|
374
|
+
const triggeredValue = (_a = this.readTriggerValue(value, triggeredRange.startOffset)) !== null && _a !== void 0 ? _a : '';
|
|
375
|
+
const split = value.split(triggeredValue);
|
|
376
|
+
const before = split[0];
|
|
377
|
+
const after = split[1];
|
|
378
|
+
const replacement = createSearchResultReplacement(event.detail, before, after);
|
|
379
|
+
this.lastReplacedSpace = replacement.afterSpace;
|
|
380
|
+
this.rawElements = Array.from(this.contentEl.childNodes).reduce((re, e) => {
|
|
381
|
+
if (this.isIdenticalElement(e, triggeredElement)) {
|
|
382
|
+
return [...re, ...getNodesForSearchResultReplacement(replacement)];
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
return [...re, e];
|
|
386
|
+
}
|
|
387
|
+
}, []);
|
|
388
|
+
this.hasTriggered = false;
|
|
389
|
+
this.resultReplaced.emit(event.detail);
|
|
390
|
+
this.replacements = [
|
|
391
|
+
...this.replacements.filter((r) => r.id !== event.detail.id),
|
|
392
|
+
event.detail,
|
|
393
|
+
];
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
getCursorPosition() {
|
|
397
|
+
var _a;
|
|
398
|
+
const selection = getWindowSelection();
|
|
399
|
+
if (selection != null && selection.rangeCount > 0) {
|
|
400
|
+
const cursorBounds = selection.getRangeAt(0).getBoundingClientRect();
|
|
401
|
+
const contentBounds = (_a = this.contentEl) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
402
|
+
const cursorBottom = cursorBounds.bottom || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.bottom) || 0;
|
|
403
|
+
const cursorTop = cursorBounds.top || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.top) || 0;
|
|
404
|
+
return {
|
|
405
|
+
x: cursorBounds.left || (contentBounds === null || contentBounds === void 0 ? void 0 : contentBounds.left) || 0,
|
|
406
|
+
y: this.placement.includes('top') ? cursorTop : cursorBottom,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
throw new Error('Unable to retrieve window selection.');
|
|
410
|
+
}
|
|
411
|
+
get hostEl() { return getElement(this); }
|
|
412
|
+
static get watchers() { return {
|
|
413
|
+
"value": ["replaceContent"],
|
|
414
|
+
"replacements": ["updateContent"]
|
|
415
|
+
}; }
|
|
416
|
+
};
|
|
417
|
+
SearchBar.style = searchBarCss;
|
|
418
|
+
|
|
419
|
+
export { SearchBar as S };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter, h } from '../../stencil-public-runtime';
|
|
2
2
|
import { Point } from '../../types/point';
|
|
3
3
|
import { PopoverPlacement } from '../popover/popover';
|
|
4
|
-
|
|
4
|
+
import { Result } from './types';
|
|
5
5
|
export declare class ResultList {
|
|
6
6
|
items: Result[];
|
|
7
7
|
itemsJson?: string;
|
|
@@ -20,9 +20,11 @@ export declare class ResultList {
|
|
|
20
20
|
private lastFocusedIndex;
|
|
21
21
|
private stateMap;
|
|
22
22
|
private hostEl;
|
|
23
|
+
private resultClick;
|
|
23
24
|
private resizeObserver;
|
|
24
25
|
private computedResultHeight?;
|
|
25
26
|
private resultsScrollEl?;
|
|
27
|
+
constructor();
|
|
26
28
|
handleResultsChanged(results: Array<Result> | string | undefined): void;
|
|
27
29
|
handleOpenChanged(): void;
|
|
28
30
|
protected componentWillLoad(): void;
|
|
@@ -35,7 +37,10 @@ export declare class ResultList {
|
|
|
35
37
|
private ensureTemplateDefined;
|
|
36
38
|
private createResultPool;
|
|
37
39
|
private createResultInstance;
|
|
40
|
+
private createResultHandlers;
|
|
38
41
|
private layoutResults;
|
|
42
|
+
private handlePointerDown;
|
|
43
|
+
private handleResultClick;
|
|
39
44
|
private computeViewportResults;
|
|
40
45
|
private getListHeight;
|
|
41
46
|
private handleScroll;
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Result } from '../result-list/types';
|
|
2
|
+
export interface SearchResultReplacement {
|
|
3
|
+
before: Text;
|
|
4
|
+
beforeSpace: Text;
|
|
5
|
+
result: Text;
|
|
6
|
+
afterSpace?: Text;
|
|
7
|
+
after?: Text;
|
|
8
|
+
}
|
|
9
|
+
export declare const createResultUri: (result: Result) => string;
|
|
10
|
+
export declare const createSearchResultReplacement: (result: Result, before: string, after?: string) => SearchResultReplacement;
|
|
11
|
+
export declare const getNodesForSearchResultReplacement: (replacement: SearchResultReplacement) => Text[];
|
|
12
|
+
/**
|
|
13
|
+
* We leverage a couple unique spaces to represent mentions, allowing for
|
|
14
|
+
* correct cursor movement when using arrow keys. As these characters are
|
|
15
|
+
* purely for functional behavior of the input, `trimNonstandardSpaces`
|
|
16
|
+
* will remove them so the input is suitable for emitting.
|
|
17
|
+
*
|
|
18
|
+
* U+200A is a "Hair Space" which acts as a space, but is not visually
|
|
19
|
+
* represented as one.
|
|
20
|
+
*
|
|
21
|
+
* U+00A0 is a "No-Break Space" which is commonly added by browsers
|
|
22
|
+
* when interacting with a contenteditable element.
|
|
23
|
+
*/
|
|
24
|
+
export declare const trimNonstandardSpaces: (text: string) => string;
|