@universal-material/web 3.0.74 → 3.0.76
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/button/button.d.ts +1 -1
- package/button/button.js.map +1 -1
- package/chip-field/chip-field.d.ts +18 -1
- package/chip-field/chip-field.d.ts.map +1 -1
- package/chip-field/chip-field.js +20 -7
- package/chip-field/chip-field.js.map +1 -1
- package/custom-elements.json +5117 -5038
- package/field/field-base.d.ts +18 -2
- package/field/field-base.d.ts.map +1 -1
- package/field/field-base.js +14 -8
- package/field/field-base.js.map +1 -1
- package/navigation/drawer.d.ts.map +1 -1
- package/navigation/drawer.js +5 -1
- package/navigation/drawer.js.map +1 -1
- package/navigation/drawer.styles.d.ts.map +1 -1
- package/navigation/drawer.styles.js +6 -1
- package/navigation/drawer.styles.js.map +1 -1
- package/package.json +1 -1
- package/select/option.js +2 -2
- package/select/option.js.map +1 -1
- package/select/select-navigation-controller.js +8 -8
- package/select/select-navigation-controller.js.map +1 -1
- package/select/select.d.ts +15 -7
- package/select/select.d.ts.map +1 -1
- package/select/select.js +50 -42
- package/select/select.js.map +1 -1
- package/shared/button-wrapper.js +1 -1
- package/shared/button-wrapper.js.map +1 -1
- package/shared/menu-field/menu-field-navigation-controller.js +7 -7
- package/shared/menu-field/menu-field-navigation-controller.js.map +1 -1
- package/shared/menu-field/menu-field.d.ts +2 -2
- package/shared/menu-field/menu-field.d.ts.map +1 -1
- package/shared/menu-field/menu-field.js.map +1 -1
- package/shared/text-field-base/text-field-base.d.ts +3 -0
- package/shared/text-field-base/text-field-base.d.ts.map +1 -1
- package/shared/text-field-base/text-field-base.js +3 -0
- package/shared/text-field-base/text-field-base.js.map +1 -1
- package/tab-bar/tab.js +2 -2
- package/tab-bar/tab.js.map +1 -1
- package/tab-bar/tab.styles.d.ts.map +1 -1
- package/tab-bar/tab.styles.js +6 -2
- package/tab-bar/tab.styles.js.map +1 -1
- package/typeahead/typeahead.d.ts +45 -3
- package/typeahead/typeahead.d.ts.map +1 -1
- package/typeahead/typeahead.js +37 -6
- package/typeahead/typeahead.js.map +1 -1
- package/shared/redispatch-event.d.ts +0 -2
- package/shared/redispatch-event.d.ts.map +0 -1
- package/shared/redispatch-event.js +0 -14
- package/shared/redispatch-event.js.map +0 -1
package/typeahead/typeahead.d.ts
CHANGED
|
@@ -11,26 +11,68 @@ export declare class UmTypeahead extends LitElement {
|
|
|
11
11
|
static readonly formAssociated = true;
|
|
12
12
|
static styles: import("lit").CSSResult;
|
|
13
13
|
private target;
|
|
14
|
-
results
|
|
14
|
+
private results;
|
|
15
|
+
/**
|
|
16
|
+
* The datasource of the typeahead. Accepts an `Array` or a `Promise<[]>`.
|
|
17
|
+
*/
|
|
15
18
|
source: (any[] | ((term: string) => Promise<any[]>)) | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* A function return a string based on a result from the `source`. Useful when the source results are objects.
|
|
21
|
+
*/
|
|
16
22
|
formatter: ((value: any) => string) | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* A string representing an HTML to be rendered inside the menu item. If set, it will replace the `u-highlight`.
|
|
25
|
+
*
|
|
26
|
+
* _Note:_ Subject to signature change
|
|
27
|
+
*/
|
|
17
28
|
template: ((term: string, value: any) => string) | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The time in milliseconds before triggering an update in the results.
|
|
31
|
+
*/
|
|
18
32
|
debounce: number;
|
|
33
|
+
/**
|
|
34
|
+
* The number of suggestions to show
|
|
35
|
+
*/
|
|
19
36
|
limit: number;
|
|
37
|
+
/**
|
|
38
|
+
* How many characters must be typed before show suggestions
|
|
39
|
+
*
|
|
40
|
+
* _Note:_ Not used when the source is a `Promise`
|
|
41
|
+
*/
|
|
20
42
|
minLength: number;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the menu will be show when the target get focus.
|
|
45
|
+
*
|
|
46
|
+
* _Note:_ The `minLength` will still be applied
|
|
47
|
+
*/
|
|
21
48
|
openOnFocus: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* If `true`, model values will not be restricted only to items selected from the menu.
|
|
51
|
+
*/
|
|
22
52
|
editable: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The value for the `autocomplete` attribute for the target element.
|
|
55
|
+
*/
|
|
23
56
|
autocomplete: 'on' | 'off' | string;
|
|
57
|
+
/**
|
|
58
|
+
* The value for the `spellcheck` attribute for the target element.
|
|
59
|
+
*/
|
|
24
60
|
spellcheck: boolean;
|
|
25
61
|
get form(): HTMLFormElement | null;
|
|
62
|
+
/**
|
|
63
|
+
* Gets or sets the current value of the typeahead.
|
|
64
|
+
*/
|
|
26
65
|
get value(): any;
|
|
27
66
|
set value(value: any);
|
|
28
67
|
focus(): void;
|
|
29
68
|
clear(): void;
|
|
69
|
+
/**
|
|
70
|
+
* The id of the target element to attach the typeahead.
|
|
71
|
+
*/
|
|
30
72
|
get targetId(): string | undefined;
|
|
31
73
|
set targetId(value: string | undefined);
|
|
32
|
-
|
|
33
|
-
|
|
74
|
+
_menu: UmMenu;
|
|
75
|
+
_menuItems: UmMenuItem[];
|
|
34
76
|
constructor();
|
|
35
77
|
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
36
78
|
connectedCallback(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeahead.d.ts","sourceRoot":"","sources":["../../src/typeahead/typeahead.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,kBAAkB,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAM3D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAIzC,OAAO,gBAAgB,CAAC;AAExB,MAAM,WAAW,IAAI;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,qBACa,WAAY,SAAQ,UAAU;;IACzC,MAAM,CAAC,QAAQ,CAAC,cAAc,QAAQ;IAEtC,OAAgB,M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,UAAS;IAEvD,IAAI,IAAI,IAAI,eAAe,GAAG,IAAI,CAEjC;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,GAAG,CAEf;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,GAAG,EAOnB;IAEQ,KAAK;IAId,KAAK;IASL;;OAEG;IACH,IACI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAEjC;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAMrC;IAEgB,KAAK,EAAG,MAAM,CAAC;IACP,UAAU,EAAG,UAAU,EAAE,CAAC;;IAO1C,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAYhF,iBAAiB;IAQjB,oBAAoB;cAiGV,MAAM,IAAI,kBAAkB;IAuG/C,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,YAAY;CAarB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,WAAW,CAAC;KAC5B;CACF"}
|
package/typeahead/typeahead.js
CHANGED
|
@@ -25,6 +25,9 @@ let UmTypeahead = class UmTypeahead extends LitElement {
|
|
|
25
25
|
get form() {
|
|
26
26
|
return this.#elementInternals.form;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Gets or sets the current value of the typeahead.
|
|
30
|
+
*/
|
|
28
31
|
get value() {
|
|
29
32
|
return this.#value;
|
|
30
33
|
}
|
|
@@ -45,6 +48,9 @@ let UmTypeahead = class UmTypeahead extends LitElement {
|
|
|
45
48
|
this.#termNormalized = '';
|
|
46
49
|
this.setTargetValue('');
|
|
47
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The id of the target element to attach the typeahead.
|
|
53
|
+
*/
|
|
48
54
|
get targetId() {
|
|
49
55
|
return this.#targetId;
|
|
50
56
|
}
|
|
@@ -62,12 +68,37 @@ let UmTypeahead = class UmTypeahead extends LitElement {
|
|
|
62
68
|
this.#navigationController = new MenuFieldNavigationController(this);
|
|
63
69
|
this.#termNormalized = '';
|
|
64
70
|
this.#debounceTimeout = null;
|
|
71
|
+
/**
|
|
72
|
+
* The time in milliseconds before triggering an update in the results.
|
|
73
|
+
*/
|
|
65
74
|
this.debounce = 300;
|
|
75
|
+
/**
|
|
76
|
+
* The number of suggestions to show
|
|
77
|
+
*/
|
|
66
78
|
this.limit = 10;
|
|
79
|
+
/**
|
|
80
|
+
* How many characters must be typed before show suggestions
|
|
81
|
+
*
|
|
82
|
+
* _Note:_ Not used when the source is a `Promise`
|
|
83
|
+
*/
|
|
67
84
|
this.minLength = 2;
|
|
85
|
+
/**
|
|
86
|
+
* Whether the menu will be show when the target get focus.
|
|
87
|
+
*
|
|
88
|
+
* _Note:_ The `minLength` will still be applied
|
|
89
|
+
*/
|
|
68
90
|
this.openOnFocus = false;
|
|
91
|
+
/**
|
|
92
|
+
* If `true`, model values will not be restricted only to items selected from the menu.
|
|
93
|
+
*/
|
|
69
94
|
this.editable = false;
|
|
95
|
+
/**
|
|
96
|
+
* The value for the `autocomplete` attribute for the target element.
|
|
97
|
+
*/
|
|
70
98
|
this.autocomplete = 'off';
|
|
99
|
+
/**
|
|
100
|
+
* The value for the `spellcheck` attribute for the target element.
|
|
101
|
+
*/
|
|
71
102
|
this.spellcheck = false;
|
|
72
103
|
this.#handleFocus = async () => {
|
|
73
104
|
if (this.openOnFocus) {
|
|
@@ -170,8 +201,8 @@ let UmTypeahead = class UmTypeahead extends LitElement {
|
|
|
170
201
|
return html ``;
|
|
171
202
|
}
|
|
172
203
|
setTimeout(() => {
|
|
173
|
-
this.
|
|
174
|
-
this.
|
|
204
|
+
this._menu.anchorElement = this.getMenuAnchor();
|
|
205
|
+
this._menu.open = true;
|
|
175
206
|
});
|
|
176
207
|
return html `
|
|
177
208
|
<u-menu manualFocus anchor-corner="auto-start">
|
|
@@ -189,7 +220,7 @@ let UmTypeahead = class UmTypeahead extends LitElement {
|
|
|
189
220
|
async #updateResults(lazy = false) {
|
|
190
221
|
const term = this.getTargetValue();
|
|
191
222
|
const termNormalized = normalizeText(term).toLowerCase();
|
|
192
|
-
if (lazy && termNormalized === this.#termNormalized && this.
|
|
223
|
+
if (lazy && termNormalized === this.#termNormalized && this._menu?.open === true) {
|
|
193
224
|
return;
|
|
194
225
|
}
|
|
195
226
|
this.#termNormalized = termNormalized;
|
|
@@ -282,7 +313,7 @@ __decorate([
|
|
|
282
313
|
state()
|
|
283
314
|
], UmTypeahead.prototype, "results", void 0);
|
|
284
315
|
__decorate([
|
|
285
|
-
|
|
316
|
+
state()
|
|
286
317
|
], UmTypeahead.prototype, "source", void 0);
|
|
287
318
|
__decorate([
|
|
288
319
|
property({ type: Number, reflect: true })
|
|
@@ -310,10 +341,10 @@ __decorate([
|
|
|
310
341
|
], UmTypeahead.prototype, "targetId", null);
|
|
311
342
|
__decorate([
|
|
312
343
|
query('u-menu')
|
|
313
|
-
], UmTypeahead.prototype, "
|
|
344
|
+
], UmTypeahead.prototype, "_menu", void 0);
|
|
314
345
|
__decorate([
|
|
315
346
|
queryAll('u-menu-item')
|
|
316
|
-
], UmTypeahead.prototype, "
|
|
347
|
+
], UmTypeahead.prototype, "_menuItems", void 0);
|
|
317
348
|
UmTypeahead = __decorate([
|
|
318
349
|
customElement('u-typeahead')
|
|
319
350
|
], UmTypeahead);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeahead.js","sourceRoot":"","sources":["../../src/typeahead/typeahead.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAsB,UAAU,EAAE,MAAM,KAAK,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CA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UQ;IAAR,KAAK,EAAE;4CAAiB;AAEb;IAAX,QAAQ,EAAE;2CAAkE;AAIpC;IAAxC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CAAgB;AACf;IAAxC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;0CAAY;AACX;IAAxC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;8CAAe;AACe;IAArE,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gDAAqB;AAChD;IAAzC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CAAkB;AAChC;IAA1B,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;iDAA6C;AACnC;IAAnC,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;+CAA6B;AAgCvD;IADC,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAC,CAAC;2CAGjD;AASgB;IAAhB,KAAK,CAAC,QAAQ,CAAC;yCAAe;AACN;IAAxB,QAAQ,CAAC,aAAa,CAAC;8CAA0B;AAzEvC,WAAW;IADvB,aAAa,CAAC,aAAa,CAAC;GAChB,WAAW,CAqVvB","sourcesContent":["import { html, HTMLTemplateResult, LitElement } from 'lit';\nimport { unsafeHTML } from 'lit-html/directives/unsafe-html.js';\nimport { customElement, property, query, queryAll, state } from 'lit/decorators.js';\n\nimport { styles } from './typeahead.styles.js';\n\nimport { UmMenuItem } from '../menu/menu-item.js';\nimport { UmMenu } from '../menu/menu.js';\nimport { MenuFieldNavigationController } from '../shared/menu-field/menu-field-navigation-controller.js';\nimport { normalizeText } from '../shared/normalize-text.js';\n\nimport './highlight.js';\n\nexport interface Data {\n label: string;\n value: any;\n}\n\n@customElement('u-typeahead')\nexport class UmTypeahead extends LitElement {\n static readonly formAssociated = true;\n\n static override styles = styles;\n\n #targetId: string | undefined;\n\n #connected = false;\n private target: HTMLElement & {autocomplete: 'on' | 'off' | string | null; input?: HTMLInputElement; container?: HTMLElement; value: string} | null = null;\n #documentMutationObserver: MutationObserver | null = null;\n #navigationController = new MenuFieldNavigationController(this);\n #termNormalized: string = '';\n #debounceTimeout: number | null = null;\n #value: any;\n readonly #elementInternals: ElementInternals;\n\n // @ts-ignore\n @state() results: Data[];\n\n @property() source: (any[] | ((term: string) => Promise<any[]>)) | undefined;\n formatter: ((value: any) => string) | undefined;\n template: ((term: string, value: any) => string) | undefined;\n\n @property({type: Number, reflect: true}) debounce = 300;\n @property({type: Number, reflect: true}) limit = 10;\n @property({type: Number, reflect: true}) minLength = 2;\n @property({type: Boolean, attribute: 'open-on-focus', reflect: true}) openOnFocus = false;\n @property({type: Boolean, reflect: true}) editable = false;\n @property({reflect: true}) autocomplete: 'on' | 'off' | string = 'off';\n @property({reflect: true}) override spellcheck = false;\n\n get form(): HTMLFormElement | null {\n return this.#elementInternals.form;\n }\n\n get value(): any {\n return this.#value;\n }\n set value(value: any) {\n this.#value = value;\n this.#elementInternals.setFormValue(value);\n\n if (this.#connected) {\n this.#setValueOnTarget();\n }\n }\n\n override focus() {\n this.target?.focus();\n }\n\n clear() {\n if (!this.target) {\n return;\n }\n\n this.#termNormalized = '';\n this.setTargetValue('');\n }\n\n @property({reflect: true, attribute: \"target-id\"})\n get targetId(): string | undefined {\n return this.#targetId;\n }\n set targetId(value: string | undefined) {\n this.#targetId = value;\n\n if (this.#connected) {\n this.#attach();\n }\n }\n\n @query('u-menu') menu!: UmMenu;\n @queryAll('u-menu-item') menuItems!: UmMenuItem[];\n\n constructor() {\n super();\n this.#elementInternals = this.attachInternals();\n }\n\n override attributeChangedCallback(name: string, _old: string | null, value: string | null) {\n super.attributeChangedCallback(name, _old, value);\n\n if (name === 'autocomplete') {\n this.target!.autocomplete = value;\n }\n\n if (name === 'spellcheck') {\n this.target!.spellcheck = value === 'true';\n }\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this.#connected = true;\n this.#attach();\n this.#documentMutationObserver = new MutationObserver(() => this.#attach())\n this.#documentMutationObserver.observe(document, {attributes: true, childList: true});\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.#connected = false;\n this.#detach();\n this.#documentMutationObserver!.disconnect();\n this.#documentMutationObserver = null;\n }\n\n #attach() {\n if (!this.targetId) {\n this.#detach();\n return;\n }\n\n const newTarget = document.getElementById(this.targetId) as HTMLInputElement;\n\n if (newTarget === this.target) {\n return;\n }\n\n this.#detach();\n\n if (!newTarget) {\n return;\n }\n\n // @ts-ignore\n this.target = newTarget;\n newTarget.role = \"combobox\";\n newTarget.autocomplete = <any>this.autocomplete;\n newTarget.spellcheck = this.spellcheck;\n newTarget.autocapitalize = 'off';\n\n newTarget.addEventListener('click', this.#handleClick);\n newTarget.addEventListener('input', this.#handleInput);\n this.#navigationController.attach(newTarget);\n newTarget.addEventListener('focus', this.#handleFocus);\n\n if (this.value) {\n this.#setValueOnTarget();\n }\n }\n\n #detach() {\n this.target?.removeEventListener('click', this.#handleClick);\n this.target?.removeEventListener('input', this.#handleInput);\n this.#navigationController.detach();\n this.target?.removeEventListener('focus', this.#handleFocus);\n }\n\n #handleFocus = async () => {\n if (this.openOnFocus) {\n await this.#updateResults();\n }\n }\n\n #handleInput = () => {\n\n if (this.#debounceTimeout) {\n clearTimeout(this.#debounceTimeout);\n }\n\n this.#setValueAndDispatchEvents(this.editable ? this.getTargetValue() : null, true);\n\n this.#debounceTimeout = setTimeout(async () => await this.#updateResults(true), this.debounce);\n }\n\n #getItemClickHandler(data: Data) {\n return () => {\n const selectedEvent = new CustomEvent('selected', {\n cancelable: true,\n detail: data.value\n });\n\n this.dispatchEvent(selectedEvent);\n\n if (selectedEvent.defaultPrevented) {\n return;\n }\n\n this.#setValueAndDispatchEvents(data.value);\n }\n }\n\n #setValueAndDispatchEvents(value: any, direct = false) {\n\n if (!direct) {\n this.value = value;\n } else {\n this.#value = value;\n this.#elementInternals.setFormValue(value);\n }\n\n this.dispatchEvent(new InputEvent('input', {bubbles: true, composed: true}));\n this.dispatchEvent(new Event('change', {bubbles: true}));\n }\n\n protected override render(): HTMLTemplateResult {\n\n if (!this.results?.length) {\n return html``;\n }\n\n setTimeout(() => {\n this.menu.anchorElement = this.getMenuAnchor();\n this.menu.open = true;\n });\n\n return html`\n <u-menu manualFocus anchor-corner=\"auto-start\">\n ${this.results\n .map(result => {\n const content = this.template\n ? unsafeHTML(this.template(this.#termNormalized, result.value))\n : html`<u-highlight .term=${this.#termNormalized} .result=${result.label}></u-highlight>`;\n \n return html`\n <u-menu-item @click=${this.#getItemClickHandler(result)} tabindex=\"-1\">${content}</u-menu-item>`;\n })}\n </u-menu>\n `;\n }\n\n async #updateResults(lazy = false) {\n\n const term = this.getTargetValue();\n\n const termNormalized = normalizeText(term).toLowerCase();\n\n if (lazy && termNormalized === this.#termNormalized && this.menu?.open === true) {\n return;\n }\n\n this.#termNormalized = termNormalized;\n\n if (termNormalized.length < this.minLength) {\n this.results = [];\n return;\n }\n\n this.results = await this.#getData();\n this.results = this.results.slice(0, this.limit || this.results.length);\n }\n\n async #getData(): Promise<Data[]> {\n if (!this.source) {\n return [];\n }\n\n let values: any[]\n\n let filter = false;\n\n if (this.source instanceof Array) {\n values = this.source;\n filter = true;\n } else {\n const source = this.source as ((term: string) => Promise<any[]>);\n values = await source(this.#termNormalized);\n }\n\n const result = values\n .map(source => ({\n label: this.formatter\n ? this.formatter(source)\n : source.toString(),\n value: source\n }));\n\n if (!filter) {\n return result;\n }\n\n return result\n .filter(t => normalizeText(t.label)\n .toLowerCase()\n .includes(this.#termNormalized))\n }\n\n #setValueOnTarget() {\n if (!this.target) {\n return;\n }\n\n const textValue = this.getTextValue();\n this.#termNormalized = normalizeText(textValue)?.toLowerCase();\n\n if (this.target.tagName === 'U-TEXT-FIELD') {\n this.target.value = textValue;\n return;\n }\n\n if (this.target.input) {\n this.target.input.value = textValue;\n return;\n }\n \n this.target.value = textValue;\n }\n\n private getTargetValue(): string {\n return this.target!.input?.value ?? this.target!.value;\n }\n\n private setTargetValue(value: string): void {\n const targetInput = this.target?.input ?? this.target;\n\n if (targetInput) {\n targetInput.value = value;\n }\n }\n\n private getMenuAnchor() {\n if (!this.target) {\n return null;\n }\n\n if (this.target.tagName === 'U-CHIP-FIELD') {\n return this.target.input;\n }\n\n if (this.target.tagName === 'U-TEXT-FIELD') {\n return this.target.container;\n }\n\n return this.target;\n }\n\n private getTextValue(): string {\n if (!this.value) {\n return '';\n }\n\n return this.formatter\n ? this.formatter(this.value)\n : this.value\n }\n\n #handleClick(e: Event) {\n e.stopPropagation();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'u-typeahead': UmTypeahead;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"typeahead.js","sourceRoot":"","sources":["../../src/typeahead/typeahead.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAsB,UAAU,EAAE,MAAM,KAAK,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpF,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,0DAA0D,CAAC;AACzG,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,gBAAgB,CAAC;AAQjB,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU;aACzB,mBAAc,GAAG,IAAI,AAAP,CAAQ;aAEtB,WAAM,GAAG,MAAM,AAAT,CAAU;IAEhC,SAAS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,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;0CAAY;AAOX;IAAxC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;8CAAe;AAOe;IAArE,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gDAAqB;AAKhD;IAAzC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CAAkB;AAKhC;IAA1B,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;iDAA6C;AAKnC;IAAnC,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;+CAA6B;AAsCvD;IADC,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAC,CAAC;2CAGjD;AASgB;IAAhB,KAAK,CAAC,QAAQ,CAAC;0CAAgB;AACP;IAAxB,QAAQ,CAAC,aAAa,CAAC;+CAA2B;AA3HxC,WAAW;IADvB,aAAa,CAAC,aAAa,CAAC;GAChB,WAAW,CAuYvB","sourcesContent":["import { html, HTMLTemplateResult, LitElement } from 'lit';\nimport { unsafeHTML } from 'lit-html/directives/unsafe-html.js';\nimport { customElement, property, query, queryAll, state } from 'lit/decorators.js';\n\nimport { styles } from './typeahead.styles.js';\n\nimport { UmMenuItem } from '../menu/menu-item.js';\nimport { UmMenu } from '../menu/menu.js';\nimport { MenuFieldNavigationController } from '../shared/menu-field/menu-field-navigation-controller.js';\nimport { normalizeText } from '../shared/normalize-text.js';\n\nimport './highlight.js';\n\nexport interface Data {\n label: string;\n value: any;\n}\n\n@customElement('u-typeahead')\nexport class UmTypeahead extends LitElement {\n static readonly formAssociated = true;\n\n static override styles = styles;\n\n #targetId: string | undefined;\n\n #connected = false;\n private target: HTMLElement & {autocomplete: 'on' | 'off' | string | null; input?: HTMLInputElement; container?: HTMLElement; value: string} | null = null;\n #documentMutationObserver: MutationObserver | null = null;\n #navigationController = new MenuFieldNavigationController(this);\n #termNormalized: string = '';\n #debounceTimeout: number | null = null;\n #value: any;\n readonly #elementInternals: ElementInternals;\n\n // @ts-ignore\n @state() private results: Data[];\n\n /**\n * The datasource of the typeahead. Accepts an `Array` or a `Promise<[]>`.\n */\n @state() source: (any[] | ((term: string) => Promise<any[]>)) | undefined;\n\n /**\n * A function return a string based on a result from the `source`. Useful when the source results are objects.\n */\n formatter: ((value: any) => string) | undefined;\n\n /**\n * A string representing an HTML to be rendered inside the menu item. If set, it will replace the `u-highlight`.\n *\n * _Note:_ Subject to signature change\n */\n template: ((term: string, value: any) => string) | undefined;\n\n /**\n * The time in milliseconds before triggering an update in the results.\n */\n @property({type: Number, reflect: true}) debounce = 300;\n\n /**\n * The number of suggestions to show\n */\n @property({type: Number, reflect: true}) limit = 10;\n\n /**\n * How many characters must be typed before show suggestions\n *\n * _Note:_ Not used when the source is a `Promise`\n */\n @property({type: Number, reflect: true}) minLength = 2;\n\n /**\n * Whether the menu will be show when the target get focus.\n *\n * _Note:_ The `minLength` will still be applied\n */\n @property({type: Boolean, attribute: 'open-on-focus', reflect: true}) openOnFocus = false;\n\n /**\n * If `true`, model values will not be restricted only to items selected from the menu.\n */\n @property({type: Boolean, reflect: true}) editable = false;\n\n /**\n * The value for the `autocomplete` attribute for the target element.\n */\n @property({reflect: true}) autocomplete: 'on' | 'off' | string = 'off';\n\n /**\n * The value for the `spellcheck` attribute for the target element.\n */\n @property({reflect: true}) override spellcheck = false;\n\n get form(): HTMLFormElement | null {\n return this.#elementInternals.form;\n }\n\n /**\n * Gets or sets the current value of the typeahead.\n */\n get value(): any {\n return this.#value;\n }\n set value(value: any) {\n this.#value = value;\n this.#elementInternals.setFormValue(value);\n\n if (this.#connected) {\n this.#setValueOnTarget();\n }\n }\n\n override focus() {\n this.target?.focus();\n }\n\n clear() {\n if (!this.target) {\n return;\n }\n\n this.#termNormalized = '';\n this.setTargetValue('');\n }\n\n /**\n * The id of the target element to attach the typeahead.\n */\n @property({reflect: true, attribute: \"target-id\"})\n get targetId(): string | undefined {\n return this.#targetId;\n }\n set targetId(value: string | undefined) {\n this.#targetId = value;\n\n if (this.#connected) {\n this.#attach();\n }\n }\n\n @query('u-menu') _menu!: UmMenu;\n @queryAll('u-menu-item') _menuItems!: UmMenuItem[];\n\n constructor() {\n super();\n this.#elementInternals = this.attachInternals();\n }\n\n override attributeChangedCallback(name: string, _old: string | null, value: string | null) {\n super.attributeChangedCallback(name, _old, value);\n\n if (name === 'autocomplete') {\n this.target!.autocomplete = value;\n }\n\n if (name === 'spellcheck') {\n this.target!.spellcheck = value === 'true';\n }\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this.#connected = true;\n this.#attach();\n this.#documentMutationObserver = new MutationObserver(() => this.#attach())\n this.#documentMutationObserver.observe(document, {attributes: true, childList: true});\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.#connected = false;\n this.#detach();\n this.#documentMutationObserver!.disconnect();\n this.#documentMutationObserver = null;\n }\n\n #attach() {\n if (!this.targetId) {\n this.#detach();\n return;\n }\n\n const newTarget = document.getElementById(this.targetId) as HTMLInputElement;\n\n if (newTarget === this.target) {\n return;\n }\n\n this.#detach();\n\n if (!newTarget) {\n return;\n }\n\n // @ts-ignore\n this.target = newTarget;\n newTarget.role = \"combobox\";\n newTarget.autocomplete = <any>this.autocomplete;\n newTarget.spellcheck = this.spellcheck;\n newTarget.autocapitalize = 'off';\n\n newTarget.addEventListener('click', this.#handleClick);\n newTarget.addEventListener('input', this.#handleInput);\n this.#navigationController.attach(newTarget);\n newTarget.addEventListener('focus', this.#handleFocus);\n\n if (this.value) {\n this.#setValueOnTarget();\n }\n }\n\n #detach() {\n this.target?.removeEventListener('click', this.#handleClick);\n this.target?.removeEventListener('input', this.#handleInput);\n this.#navigationController.detach();\n this.target?.removeEventListener('focus', this.#handleFocus);\n }\n\n #handleFocus = async () => {\n if (this.openOnFocus) {\n await this.#updateResults();\n }\n }\n\n #handleInput = () => {\n\n if (this.#debounceTimeout) {\n clearTimeout(this.#debounceTimeout);\n }\n\n this.#setValueAndDispatchEvents(this.editable ? this.getTargetValue() : null, true);\n\n this.#debounceTimeout = setTimeout(async () => await this.#updateResults(true), this.debounce);\n }\n\n #getItemClickHandler(data: Data) {\n return () => {\n const selectedEvent = new CustomEvent('selected', {\n cancelable: true,\n detail: data.value\n });\n\n this.dispatchEvent(selectedEvent);\n\n if (selectedEvent.defaultPrevented) {\n return;\n }\n\n this.#setValueAndDispatchEvents(data.value);\n }\n }\n\n #setValueAndDispatchEvents(value: any, direct = false) {\n\n if (!direct) {\n this.value = value;\n } else {\n this.#value = value;\n this.#elementInternals.setFormValue(value);\n }\n\n this.dispatchEvent(new InputEvent('input', {bubbles: true, composed: true}));\n this.dispatchEvent(new Event('change', {bubbles: true}));\n }\n\n protected override render(): HTMLTemplateResult {\n\n if (!this.results?.length) {\n return html``;\n }\n\n setTimeout(() => {\n this._menu.anchorElement = this.getMenuAnchor();\n this._menu.open = true;\n });\n\n return html`\n <u-menu manualFocus anchor-corner=\"auto-start\">\n ${this.results\n .map(result => {\n const content = this.template\n ? unsafeHTML(this.template(this.#termNormalized, result.value))\n : html`<u-highlight .term=${this.#termNormalized} .result=${result.label}></u-highlight>`;\n \n return html`\n <u-menu-item @click=${this.#getItemClickHandler(result)} tabindex=\"-1\">${content}</u-menu-item>`;\n })}\n </u-menu>\n `;\n }\n\n async #updateResults(lazy = false) {\n\n const term = this.getTargetValue();\n\n const termNormalized = normalizeText(term).toLowerCase();\n\n if (lazy && termNormalized === this.#termNormalized && this._menu?.open === true) {\n return;\n }\n\n this.#termNormalized = termNormalized;\n\n if (termNormalized.length < this.minLength) {\n this.results = [];\n return;\n }\n\n this.results = await this.#getData();\n this.results = this.results.slice(0, this.limit || this.results.length);\n }\n\n async #getData(): Promise<Data[]> {\n if (!this.source) {\n return [];\n }\n\n let values: any[]\n\n let filter = false;\n\n if (this.source instanceof Array) {\n values = this.source;\n filter = true;\n } else {\n const source = this.source as ((term: string) => Promise<any[]>);\n values = await source(this.#termNormalized);\n }\n\n const result = values\n .map(source => ({\n label: this.formatter\n ? this.formatter(source)\n : source.toString(),\n value: source\n }));\n\n if (!filter) {\n return result;\n }\n\n return result\n .filter(t => normalizeText(t.label)\n .toLowerCase()\n .includes(this.#termNormalized))\n }\n\n #setValueOnTarget() {\n if (!this.target) {\n return;\n }\n\n const textValue = this.getTextValue();\n this.#termNormalized = normalizeText(textValue)?.toLowerCase();\n\n if (this.target.tagName === 'U-TEXT-FIELD') {\n this.target.value = textValue;\n return;\n }\n\n if (this.target.input) {\n this.target.input.value = textValue;\n return;\n }\n \n this.target.value = textValue;\n }\n\n private getTargetValue(): string {\n return this.target!.input?.value ?? this.target!.value;\n }\n\n private setTargetValue(value: string): void {\n const targetInput = this.target?.input ?? this.target;\n\n if (targetInput) {\n targetInput.value = value;\n }\n }\n\n private getMenuAnchor() {\n if (!this.target) {\n return null;\n }\n\n if (this.target.tagName === 'U-CHIP-FIELD') {\n return this.target.input;\n }\n\n if (this.target.tagName === 'U-TEXT-FIELD') {\n return this.target.container;\n }\n\n return this.target;\n }\n\n private getTextValue(): string {\n if (!this.value) {\n return '';\n }\n\n return this.formatter\n ? this.formatter(this.value)\n : this.value\n }\n\n #handleClick(e: Event) {\n e.stopPropagation();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'u-typeahead': UmTypeahead;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redispatch-event.d.ts","sourceRoot":"","sources":["../../src/shared/redispatch-event.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,WAe7D"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function redispatchEvent(element, event) {
|
|
2
|
-
// For bubbling events in SSR light DOM (or composed), stop their propagation
|
|
3
|
-
// and dispatch the copy.
|
|
4
|
-
if (event.bubbles && (!element.shadowRoot || event.composed)) {
|
|
5
|
-
event.stopPropagation();
|
|
6
|
-
}
|
|
7
|
-
const copy = Reflect.construct(event.constructor, [event.type, event]);
|
|
8
|
-
const dispatched = element.dispatchEvent(copy);
|
|
9
|
-
if (!dispatched) {
|
|
10
|
-
event.preventDefault();
|
|
11
|
-
}
|
|
12
|
-
return dispatched;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=redispatch-event.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redispatch-event.js","sourceRoot":"","sources":["../../src/shared/redispatch-event.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,OAAgB,EAAE,KAAY;IAC5D,6EAA6E;IAC7E,yBAAyB;IACzB,IAAI,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7D,KAAK,CAAC,eAAe,EAAE,CAAC;IAC1B,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAE/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,KAAK,CAAC,cAAc,EAAE,CAAC;IACzB,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["export function redispatchEvent(element: Element, event: Event) {\n // For bubbling events in SSR light DOM (or composed), stop their propagation\n // and dispatch the copy.\n if (event.bubbles && (!element.shadowRoot || event.composed)) {\n event.stopPropagation();\n }\n\n const copy = Reflect.construct(event.constructor, [event.type, event]);\n const dispatched = element.dispatchEvent(copy);\n\n if (!dispatched) {\n event.preventDefault();\n }\n\n return dispatched;\n}\n"]}
|