@vetorzero/pts-custom-elements 0.0.20 → 0.1.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/cjs/{index-Df852Um2.js → index-BryBJQdA.js} +214 -50
- package/dist/cjs/index.cjs.js +0 -5
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/{pts.cjs.js → pts-custom-elements.cjs.js} +4 -4
- package/dist/cjs/pts-remote-picker.cjs.entry.js +14669 -4
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/pts-remote-picker/providers/abstract.js +8 -0
- package/dist/collection/components/pts-remote-picker/providers/pts.js +70 -0
- package/dist/collection/components/pts-remote-picker/providers/tvmaze.js +86 -0
- package/dist/collection/components/pts-remote-picker/pts-remote-picker.css +90 -3
- package/dist/collection/components/pts-remote-picker/pts-remote-picker.js +380 -2
- package/dist/collection/index.js +1 -10
- package/dist/components/index.js +1 -1
- package/dist/components/pts-remote-picker.js +1 -1
- package/dist/esm/{index-DlRnKzBQ.js → index-SqK44lUQ.js} +214 -51
- package/dist/esm/index.js +0 -4
- package/dist/esm/loader.js +3 -3
- package/dist/esm/pts-custom-elements.js +21 -0
- package/dist/esm/pts-remote-picker.entry.js +14668 -3
- package/dist/pts-custom-elements/index.esm.js +0 -0
- package/dist/pts-custom-elements/p-14d77698.entry.js +1 -0
- package/dist/pts-custom-elements/p-SqK44lUQ.js +2 -0
- package/dist/pts-custom-elements/pts-custom-elements.esm.js +1 -0
- package/dist/types/components/pts-remote-picker/providers/abstract.d.ts +30 -0
- package/dist/types/components/pts-remote-picker/providers/pts.d.ts +8 -0
- package/dist/types/components/pts-remote-picker/providers/tvmaze.d.ts +1 -0
- package/dist/types/components/pts-remote-picker/pts-remote-picker.d.ts +33 -0
- package/dist/types/components.d.ts +23 -32
- package/dist/types/index.d.ts +1 -2
- package/package.json +46 -42
- package/dist/cjs/my-component.cjs.entry.js +0 -33
- package/dist/collection/components/my-component/my-component.css +0 -6
- package/dist/collection/components/my-component/my-component.js +0 -95
- package/dist/collection/utils/utils.js +0 -3
- package/dist/components/my-component.d.ts +0 -11
- package/dist/components/my-component.js +0 -1
- package/dist/components/p-uzTLmlCN.js +0 -1
- package/dist/esm/my-component.entry.js +0 -31
- package/dist/esm/pts.js +0 -21
- package/dist/pts/index.esm.js +0 -1
- package/dist/pts/p-391b0294.entry.js +0 -1
- package/dist/pts/p-DlRnKzBQ.js +0 -2
- package/dist/pts/p-d3b2a5c5.entry.js +0 -1
- package/dist/pts/pts.esm.js +0 -1
- package/dist/types/components/my-component/my-component.d.ts +0 -16
- package/dist/types/utils/utils.d.ts +0 -1
- /package/dist/{pts → pts-custom-elements}/p-DQuL1Twl.js +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"entries": [
|
|
3
|
-
"components/my-component/my-component.js",
|
|
4
3
|
"components/pts-remote-picker/pts-remote-picker.js"
|
|
5
4
|
],
|
|
5
|
+
"mixins": [],
|
|
6
6
|
"compiler": {
|
|
7
7
|
"name": "@stencil/core",
|
|
8
|
-
"version": "4.43.
|
|
8
|
+
"version": "4.43.2",
|
|
9
9
|
"typescriptVersion": "5.8.3"
|
|
10
10
|
},
|
|
11
11
|
"collections": [],
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import AbstractProvider from "./abstract";
|
|
3
|
+
const optionSchema = z.object({
|
|
4
|
+
value: z.string().nonempty(),
|
|
5
|
+
caption: z.string().nonempty(),
|
|
6
|
+
summary: z.string().nullish(),
|
|
7
|
+
});
|
|
8
|
+
const queryResultSchema = z.object({
|
|
9
|
+
options: optionSchema.array(),
|
|
10
|
+
});
|
|
11
|
+
export default class PTSProvider extends AbstractProvider {
|
|
12
|
+
#abortController;
|
|
13
|
+
#debounceTimeout = 0;
|
|
14
|
+
abort = () => {
|
|
15
|
+
this.#abortController?.abort(AbstractProvider.abortSymbol);
|
|
16
|
+
};
|
|
17
|
+
query(q) {
|
|
18
|
+
this.abort();
|
|
19
|
+
if (q.length < this.minChars)
|
|
20
|
+
return;
|
|
21
|
+
this.onStateChange?.('waiting');
|
|
22
|
+
// debounce
|
|
23
|
+
window.clearTimeout(this.#debounceTimeout);
|
|
24
|
+
this.#debounceTimeout = window.setTimeout(() => {
|
|
25
|
+
this.onStateChange?.('loading');
|
|
26
|
+
this.#runQuery(q)
|
|
27
|
+
.then(options => options && this.onQueryResult?.(options))
|
|
28
|
+
.finally(() => this.onStateChange?.('idle'));
|
|
29
|
+
}, this.debounceMs);
|
|
30
|
+
}
|
|
31
|
+
async resolve(value) {
|
|
32
|
+
const url = new URL(this.endpoint);
|
|
33
|
+
url.searchParams.set('value', value);
|
|
34
|
+
try {
|
|
35
|
+
return this.#fetchJson(url).then(optionSchema.parseAsync);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async #runQuery(q) {
|
|
42
|
+
const url = new URL(this.endpoint);
|
|
43
|
+
url.searchParams.set('q', q);
|
|
44
|
+
try {
|
|
45
|
+
const result = await this.#fetchJson(url).then(queryResultSchema.parseAsync);
|
|
46
|
+
return result.options;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
console.log('Validation error', err);
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async #fetchJson(url) {
|
|
54
|
+
this.onStateChange?.('loading');
|
|
55
|
+
this.abort();
|
|
56
|
+
// create new abort controller
|
|
57
|
+
this.#abortController = new AbortController();
|
|
58
|
+
const signal = this.#abortController.signal;
|
|
59
|
+
return fetch(url, { signal })
|
|
60
|
+
.then(r => r.json())
|
|
61
|
+
.catch(err => {
|
|
62
|
+
// ignore abort error
|
|
63
|
+
if (err === AbstractProvider.abortSymbol)
|
|
64
|
+
return undefined;
|
|
65
|
+
else
|
|
66
|
+
throw err;
|
|
67
|
+
})
|
|
68
|
+
.finally(() => this.onStateChange?.('idle'));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import AbstractProvider from "./abstract";
|
|
3
|
+
const showSchema = z.object({
|
|
4
|
+
id: z.coerce.string(),
|
|
5
|
+
name: z.string(),
|
|
6
|
+
summary: z
|
|
7
|
+
.string()
|
|
8
|
+
.transform(val => (val ? getTextFromHTML(val) : null))
|
|
9
|
+
.nullable(),
|
|
10
|
+
});
|
|
11
|
+
const queryResultSchema = z.array(z.object({
|
|
12
|
+
score: z.number(),
|
|
13
|
+
show: showSchema,
|
|
14
|
+
}));
|
|
15
|
+
class TVProvider extends AbstractProvider {
|
|
16
|
+
searchURL = '/search/shows';
|
|
17
|
+
resolveURL = '/shows/:id';
|
|
18
|
+
baseUrl = 'https://api.tvmaze.com';
|
|
19
|
+
#abortController;
|
|
20
|
+
#debounceTimeout = 0;
|
|
21
|
+
abort = () => {
|
|
22
|
+
this.#abortController?.abort(AbstractProvider.abortSymbol);
|
|
23
|
+
};
|
|
24
|
+
query(q) {
|
|
25
|
+
if (q.length < this.minChars)
|
|
26
|
+
return;
|
|
27
|
+
this.onStateChange?.('waiting');
|
|
28
|
+
// debounce
|
|
29
|
+
window.clearTimeout(this.#debounceTimeout);
|
|
30
|
+
this.#debounceTimeout = window.setTimeout(() => {
|
|
31
|
+
this.onStateChange?.('loading');
|
|
32
|
+
this.#runQuery(q)
|
|
33
|
+
.then(options => options && this.onQueryResult?.(options))
|
|
34
|
+
.finally(() => this.onStateChange?.('idle'));
|
|
35
|
+
}, this.debounceMs);
|
|
36
|
+
}
|
|
37
|
+
async resolve(value) {
|
|
38
|
+
const url = new URL(this.resolveURL.replace(':id', encodeURIComponent(value)), this.baseUrl);
|
|
39
|
+
try {
|
|
40
|
+
const result = await this.#fetchJson(url).then(showSchema.parseAsync);
|
|
41
|
+
return { value: result.id, caption: result.name, summary: result.summary || undefined };
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
#runQuery = async (q) => {
|
|
48
|
+
// fetch the data
|
|
49
|
+
const url = new URL(this.searchURL, this.baseUrl);
|
|
50
|
+
url.searchParams.append('q', q);
|
|
51
|
+
try {
|
|
52
|
+
const result = await this.#fetchJson(url).then(queryResultSchema.parseAsync);
|
|
53
|
+
return result.map(r => ({
|
|
54
|
+
value: r.show.id,
|
|
55
|
+
caption: r.show.name,
|
|
56
|
+
summary: r.show.summary || undefined,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.log('Validation error', err);
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
#fetchJson = async (url) => {
|
|
65
|
+
this.onStateChange?.('loading');
|
|
66
|
+
// abort previous request (if in flight)
|
|
67
|
+
this.#abortController?.abort(AbstractProvider.abortSymbol);
|
|
68
|
+
// create new abort controller
|
|
69
|
+
this.#abortController = new AbortController();
|
|
70
|
+
const signal = this.#abortController.signal;
|
|
71
|
+
return fetch(url, { signal })
|
|
72
|
+
.then(r => r.json())
|
|
73
|
+
.catch(err => {
|
|
74
|
+
if (err === AbstractProvider.abortSymbol)
|
|
75
|
+
return undefined;
|
|
76
|
+
else
|
|
77
|
+
throw err;
|
|
78
|
+
})
|
|
79
|
+
.finally(() => this.onStateChange?.('idle'));
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function getTextFromHTML(html) {
|
|
83
|
+
const el = document.createElement('fragment');
|
|
84
|
+
el.innerHTML = html;
|
|
85
|
+
return el.innerText ?? el.textContent;
|
|
86
|
+
}
|
|
@@ -1,5 +1,92 @@
|
|
|
1
1
|
:host {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
--highlighted-option-bg: #fff;
|
|
3
|
+
--listbox-bg: #eeeeee;
|
|
4
|
+
|
|
5
|
+
display: block;
|
|
6
|
+
position: relative;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* Layout */
|
|
10
|
+
|
|
11
|
+
#controls {
|
|
12
|
+
display: flex;
|
|
13
|
+
/* height: 25px; */
|
|
14
|
+
align-items: stretch;
|
|
15
|
+
gap: 0.5rem;
|
|
16
|
+
}
|
|
17
|
+
#q {
|
|
18
|
+
flex-grow: 1;
|
|
19
|
+
}
|
|
20
|
+
.listbox {
|
|
21
|
+
position: absolute;
|
|
22
|
+
inset: 100% 0 auto;
|
|
23
|
+
max-height: 20rem;
|
|
24
|
+
overflow-y: auto;
|
|
25
|
+
z-index: 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Appearance */
|
|
29
|
+
|
|
30
|
+
:host {
|
|
31
|
+
background: lightgray;
|
|
32
|
+
/* &:focus {
|
|
33
|
+
outline: 2px solid deeppink;
|
|
34
|
+
outline-offset: 4px;
|
|
35
|
+
} */
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
input,
|
|
39
|
+
button {
|
|
40
|
+
appearance: none;
|
|
41
|
+
background: none;
|
|
42
|
+
border: none;
|
|
43
|
+
padding: 0.5rem;
|
|
44
|
+
font: inherit;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.listbox {
|
|
49
|
+
background: var(--listbox-bg);
|
|
50
|
+
}
|
|
51
|
+
.listbox-option {
|
|
52
|
+
padding: 0.5rem;
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
transition: 200ms background-color;
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-flow: column;
|
|
57
|
+
gap: 0.25rem;
|
|
58
|
+
&:hover {
|
|
59
|
+
background-color: hsl(from var(--highlighted-option-bg) h s l / 50%);
|
|
60
|
+
}
|
|
61
|
+
&[aria-selected='true'] {
|
|
62
|
+
background: var(--highlighted-option-bg);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
.option-caption {
|
|
66
|
+
font-size: small;
|
|
67
|
+
font-weight: 500;
|
|
68
|
+
}
|
|
69
|
+
.option-summary {
|
|
70
|
+
font-size: x-small;
|
|
71
|
+
opacity: 50%;
|
|
72
|
+
text-overflow: ellipsis;
|
|
73
|
+
|
|
74
|
+
white-space: nowrap;
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
text-overflow: ellipsis;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Icons */
|
|
80
|
+
|
|
81
|
+
.status-icon {
|
|
82
|
+
width: 1rem;
|
|
83
|
+
:host([state='idle']) & {
|
|
84
|
+
background: oklch(59.6% 0.145 163.225);
|
|
85
|
+
}
|
|
86
|
+
:host([state='waiting']) & {
|
|
87
|
+
background: oklch(68.1% 0.162 75.834);
|
|
88
|
+
}
|
|
89
|
+
:host([state='loading']) & {
|
|
90
|
+
background: oklch(58.6% 0.253 17.585);
|
|
91
|
+
}
|
|
5
92
|
}
|
|
@@ -1,8 +1,221 @@
|
|
|
1
|
-
import { Host,
|
|
1
|
+
import { h, Host, } from "@stencil/core";
|
|
2
|
+
import PTSProvider from "./providers/pts";
|
|
2
3
|
export class PtsRemotePicker {
|
|
4
|
+
el;
|
|
5
|
+
// @ts-ignore -- O decorator injeta
|
|
6
|
+
internals;
|
|
7
|
+
value = "";
|
|
8
|
+
displayValue = "";
|
|
9
|
+
endpoint = "";
|
|
10
|
+
_state = "idle";
|
|
11
|
+
_query = "";
|
|
12
|
+
_querying = false;
|
|
13
|
+
_expanded = false;
|
|
14
|
+
_options = [];
|
|
15
|
+
_focusedIndex = -1;
|
|
16
|
+
#provider;
|
|
17
|
+
constructor() {
|
|
18
|
+
this.#provider = new PTSProvider();
|
|
19
|
+
this.#provider.endpoint = this.endpoint;
|
|
20
|
+
this.#provider.onQueryResult = (options) => {
|
|
21
|
+
if (options) {
|
|
22
|
+
this._options = options;
|
|
23
|
+
this._focusedIndex = -1;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
this.#provider.onStateChange = (state) => (this._state = state);
|
|
27
|
+
}
|
|
28
|
+
// callbacks
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
window.addEventListener("click", this.handleWindowClick);
|
|
31
|
+
// window.addEventListener('focusin', this.handleWindowFocus);
|
|
32
|
+
}
|
|
33
|
+
disconnectedCallback() {
|
|
34
|
+
window.removeEventListener("click", this.handleWindowClick);
|
|
35
|
+
// window.removeEventListener('focusin', this.handleWindowFocus);
|
|
36
|
+
}
|
|
37
|
+
componentWillLoad() {
|
|
38
|
+
if (this.value && !this.displayValue) {
|
|
39
|
+
this.resolveDisplayValue();
|
|
40
|
+
}
|
|
41
|
+
this.internals.setFormValue(this.value);
|
|
42
|
+
}
|
|
43
|
+
formResetCallback() {
|
|
44
|
+
this.value = this.el.getAttribute("value") ?? "";
|
|
45
|
+
this.displayValue = this.el.getAttribute("displayValue") ?? "";
|
|
46
|
+
if (this.value && !this.displayValue) {
|
|
47
|
+
this.resolveDisplayValue();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
3
50
|
render() {
|
|
4
|
-
|
|
51
|
+
// const debugObject = {
|
|
52
|
+
// _expanded: this._expanded,
|
|
53
|
+
// _loading: this._loading,
|
|
54
|
+
// _query: this._query,
|
|
55
|
+
// _querying: this._querying,
|
|
56
|
+
// // _options: this._options,
|
|
57
|
+
// value: this.value,
|
|
58
|
+
// displayValue: this.displayValue,
|
|
59
|
+
// };
|
|
60
|
+
const options = this._options.map((o, idx) => (h("div", { role: "option", class: "listbox-option", "data-index": idx, "aria-selected": this._focusedIndex === idx ? "true" : "false", tabindex: "-1", onClick: () => this.setValue(o.value, o.caption) }, h("div", { class: "option-caption" }, o.caption), o.summary ? h("div", { class: "option-summary" }, o.summary) : null)));
|
|
61
|
+
return (h(Host, { key: '65681df5904c0a95d54f5f12db1fad13ec8c1f66', state: this._state, onKeyDown: this.handleKeyDown, onBlur: this.handleBlur }, h("div", { key: 'b4f224463334c29a114acdf0a3e5ca8294f79462', id: "controls" }, h("div", { key: '1dd778250dd76b8ecae8bb1d4fceeeac280ced0f', class: "status-icon", part: "status-icon" }), h("input", { key: 'd4e845370e2320a22bb4f0e3fec51bf4be6a72d0', part: "q", type: "text", id: "q", spellcheck: false, autoCapitalize: "none", autoComplete: "off", autoCorrect: "off", inputMode: "none", value: this._querying ? this._query : this.displayValue, onFocus: this.handleQueryFocus, onInput: this.handleQueryInput }), h("button", { key: 'e640b0c7b2756f32e6513f9a657ca1ee258d33c1', type: "button", id: "toggle", onClick: this.handleToggle, "aria-label": "Expandir" }, "Toggle"), h("button", { key: '55e2b1846df075f2b4f8906fd1dbc1cd67b3994f', type: "button", id: "clear", onClick: this.handleClear, "aria-label": "Limpar" }, "Clear")), h("div", { key: '16df6bb0bac3bdafae1f4e815e3dbbc5bca8641a', role: "listbox", class: "listbox", hidden: !this._expanded || this._options.length < 1 }, h("div", { key: 'dec2c25fbb902bebbde16962682824961b120056', class: "scroller" }, h("div", { key: '1966b8f63e4f2a3fd21835612ac9fa9acd2c6e82', class: "scroller__marker scroller__marker--before" }), h("div", { key: '932c460391dfff774a1a1c6bc171d47c737bf7dd', class: "scroller__content", tabindex: -1 }, options), h("div", { key: '1057d3a4f64a51981424e5dd04ea13f839f1f6f1', class: "scroller__marker scroller__marker--after" })))));
|
|
62
|
+
}
|
|
63
|
+
// element methods
|
|
64
|
+
#shouldResolve = true;
|
|
65
|
+
async resolveDisplayValue() {
|
|
66
|
+
if (!this.#shouldResolve)
|
|
67
|
+
return;
|
|
68
|
+
if (!this.value) {
|
|
69
|
+
this.displayValue = "";
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const resolved = await this.#provider.resolve(this.value);
|
|
73
|
+
if (resolved) {
|
|
74
|
+
this.setValue(resolved.value, resolved.caption); // ISSO PODE DAR LOOP INFINITO
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.value = "";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async handleSetValue() {
|
|
81
|
+
this.internals.setFormValue(this.value);
|
|
82
|
+
await this.resolveDisplayValue();
|
|
83
|
+
this.el.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
|
|
84
|
+
}
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
async handleSetBaseUrl(...x) {
|
|
87
|
+
console.log("set endpoint", x);
|
|
88
|
+
this.#provider.endpoint = this.endpoint;
|
|
89
|
+
}
|
|
90
|
+
async setValue(value, displayValue) {
|
|
91
|
+
this.#shouldResolve = !displayValue;
|
|
92
|
+
this.displayValue = String(displayValue ?? "");
|
|
93
|
+
this.value = value;
|
|
94
|
+
this.collapse();
|
|
95
|
+
this.el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
96
|
+
this.#shouldResolve = true;
|
|
97
|
+
}
|
|
98
|
+
async expand() {
|
|
99
|
+
this._expanded = true;
|
|
100
|
+
}
|
|
101
|
+
async collapse() {
|
|
102
|
+
this._expanded = false;
|
|
103
|
+
this._querying = false;
|
|
104
|
+
this._focusedIndex = -1;
|
|
5
105
|
}
|
|
106
|
+
async clear() {
|
|
107
|
+
this.#provider.abort();
|
|
108
|
+
this._query = "";
|
|
109
|
+
this._querying = false;
|
|
110
|
+
this._expanded = false;
|
|
111
|
+
this._options = [];
|
|
112
|
+
this._focusedIndex = -1;
|
|
113
|
+
this.setValue("", "");
|
|
114
|
+
}
|
|
115
|
+
// event handlers
|
|
116
|
+
handleKeyDown = (e) => {
|
|
117
|
+
const optionsCount = this._options.length;
|
|
118
|
+
const input = e.target;
|
|
119
|
+
switch (e.key) {
|
|
120
|
+
case "ArrowDown":
|
|
121
|
+
{
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
// If closed, open it.
|
|
124
|
+
if (!this._expanded && optionsCount > 0) {
|
|
125
|
+
this.expand();
|
|
126
|
+
}
|
|
127
|
+
if (optionsCount > 0) {
|
|
128
|
+
const next = this._focusedIndex + 1;
|
|
129
|
+
this._focusedIndex = next % optionsCount;
|
|
130
|
+
this.ensureOptionInView(this._focusedIndex);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
case "ArrowUp":
|
|
135
|
+
{
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
if (!this._expanded && optionsCount > 0) {
|
|
138
|
+
this.expand();
|
|
139
|
+
}
|
|
140
|
+
if (optionsCount > 0) {
|
|
141
|
+
const isUnselected = this._focusedIndex < 0;
|
|
142
|
+
if (isUnselected) {
|
|
143
|
+
this._focusedIndex = optionsCount - 1;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const prev = this._focusedIndex - 1;
|
|
147
|
+
this._focusedIndex = (prev + optionsCount) % optionsCount;
|
|
148
|
+
}
|
|
149
|
+
this.ensureOptionInView(this._focusedIndex);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
case "Enter":
|
|
154
|
+
{
|
|
155
|
+
if (this._expanded &&
|
|
156
|
+
this._focusedIndex >= 0 &&
|
|
157
|
+
this._focusedIndex < optionsCount) {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
const option = this._options[this._focusedIndex];
|
|
160
|
+
this.setValue(option.value, option.caption);
|
|
161
|
+
this.collapse();
|
|
162
|
+
input.blur();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
case "Escape":
|
|
167
|
+
{
|
|
168
|
+
if (this._expanded) {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
this.collapse();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
ensureOptionInView(index) {
|
|
177
|
+
// wait for render
|
|
178
|
+
requestAnimationFrame(() => {
|
|
179
|
+
const listbox = this.el.shadowRoot?.querySelector(".listbox");
|
|
180
|
+
const option = listbox?.querySelector(`[data-index="${index}"]`);
|
|
181
|
+
console.log({ option, listbox });
|
|
182
|
+
option.scrollIntoView({
|
|
183
|
+
behavior: "instant",
|
|
184
|
+
block: "nearest",
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
handleQueryInput = (e) => {
|
|
189
|
+
const q = e.target.value;
|
|
190
|
+
this._query = q;
|
|
191
|
+
this.#provider.query(q);
|
|
192
|
+
};
|
|
193
|
+
handleQueryFocus = () => {
|
|
194
|
+
this._querying = true;
|
|
195
|
+
this.expand();
|
|
196
|
+
};
|
|
197
|
+
handleBlur = () => {
|
|
198
|
+
this._querying = false;
|
|
199
|
+
this._expanded = false;
|
|
200
|
+
};
|
|
201
|
+
handleToggle = () => {
|
|
202
|
+
this._expanded ? this.collapse() : this.expand();
|
|
203
|
+
};
|
|
204
|
+
handleClear = () => {
|
|
205
|
+
this.clear();
|
|
206
|
+
};
|
|
207
|
+
handleWindowFocus = (e) => {
|
|
208
|
+
const target = e.target;
|
|
209
|
+
if (target instanceof HTMLElement && !this.el.contains(target)) {
|
|
210
|
+
this.collapse();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
handleWindowClick = (e) => {
|
|
214
|
+
const target = e.target;
|
|
215
|
+
if (target instanceof HTMLElement && !this.el.contains(target)) {
|
|
216
|
+
this.collapse();
|
|
217
|
+
}
|
|
218
|
+
};
|
|
6
219
|
static get is() { return "pts-remote-picker"; }
|
|
7
220
|
static get encapsulation() { return "shadow"; }
|
|
8
221
|
static get originalStyleUrls() {
|
|
@@ -15,4 +228,169 @@ export class PtsRemotePicker {
|
|
|
15
228
|
"$": ["pts-remote-picker.css"]
|
|
16
229
|
};
|
|
17
230
|
}
|
|
231
|
+
static get properties() {
|
|
232
|
+
return {
|
|
233
|
+
"value": {
|
|
234
|
+
"type": "string",
|
|
235
|
+
"mutable": true,
|
|
236
|
+
"complexType": {
|
|
237
|
+
"original": "string",
|
|
238
|
+
"resolved": "string",
|
|
239
|
+
"references": {}
|
|
240
|
+
},
|
|
241
|
+
"required": false,
|
|
242
|
+
"optional": false,
|
|
243
|
+
"docs": {
|
|
244
|
+
"tags": [],
|
|
245
|
+
"text": ""
|
|
246
|
+
},
|
|
247
|
+
"getter": false,
|
|
248
|
+
"setter": false,
|
|
249
|
+
"reflect": false,
|
|
250
|
+
"attribute": "value",
|
|
251
|
+
"defaultValue": "\"\""
|
|
252
|
+
},
|
|
253
|
+
"displayValue": {
|
|
254
|
+
"type": "string",
|
|
255
|
+
"mutable": true,
|
|
256
|
+
"complexType": {
|
|
257
|
+
"original": "string",
|
|
258
|
+
"resolved": "string",
|
|
259
|
+
"references": {}
|
|
260
|
+
},
|
|
261
|
+
"required": false,
|
|
262
|
+
"optional": false,
|
|
263
|
+
"docs": {
|
|
264
|
+
"tags": [],
|
|
265
|
+
"text": ""
|
|
266
|
+
},
|
|
267
|
+
"getter": false,
|
|
268
|
+
"setter": false,
|
|
269
|
+
"reflect": false,
|
|
270
|
+
"attribute": "display-value",
|
|
271
|
+
"defaultValue": "\"\""
|
|
272
|
+
},
|
|
273
|
+
"endpoint": {
|
|
274
|
+
"type": "string",
|
|
275
|
+
"mutable": false,
|
|
276
|
+
"complexType": {
|
|
277
|
+
"original": "string",
|
|
278
|
+
"resolved": "string",
|
|
279
|
+
"references": {}
|
|
280
|
+
},
|
|
281
|
+
"required": false,
|
|
282
|
+
"optional": false,
|
|
283
|
+
"docs": {
|
|
284
|
+
"tags": [],
|
|
285
|
+
"text": ""
|
|
286
|
+
},
|
|
287
|
+
"getter": false,
|
|
288
|
+
"setter": false,
|
|
289
|
+
"reflect": false,
|
|
290
|
+
"attribute": "endpoint",
|
|
291
|
+
"defaultValue": "\"\""
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
static get states() {
|
|
296
|
+
return {
|
|
297
|
+
"_state": {},
|
|
298
|
+
"_query": {},
|
|
299
|
+
"_querying": {},
|
|
300
|
+
"_expanded": {},
|
|
301
|
+
"_options": {},
|
|
302
|
+
"_focusedIndex": {}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
static get methods() {
|
|
306
|
+
return {
|
|
307
|
+
"setValue": {
|
|
308
|
+
"complexType": {
|
|
309
|
+
"signature": "(value: string, displayValue?: string) => Promise<void>",
|
|
310
|
+
"parameters": [{
|
|
311
|
+
"name": "value",
|
|
312
|
+
"type": "string",
|
|
313
|
+
"docs": ""
|
|
314
|
+
}, {
|
|
315
|
+
"name": "displayValue",
|
|
316
|
+
"type": "string",
|
|
317
|
+
"docs": ""
|
|
318
|
+
}],
|
|
319
|
+
"references": {
|
|
320
|
+
"Promise": {
|
|
321
|
+
"location": "global",
|
|
322
|
+
"id": "global::Promise"
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
"return": "Promise<void>"
|
|
326
|
+
},
|
|
327
|
+
"docs": {
|
|
328
|
+
"text": "",
|
|
329
|
+
"tags": []
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
"expand": {
|
|
333
|
+
"complexType": {
|
|
334
|
+
"signature": "() => Promise<void>",
|
|
335
|
+
"parameters": [],
|
|
336
|
+
"references": {
|
|
337
|
+
"Promise": {
|
|
338
|
+
"location": "global",
|
|
339
|
+
"id": "global::Promise"
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
"return": "Promise<void>"
|
|
343
|
+
},
|
|
344
|
+
"docs": {
|
|
345
|
+
"text": "",
|
|
346
|
+
"tags": []
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
"collapse": {
|
|
350
|
+
"complexType": {
|
|
351
|
+
"signature": "() => Promise<void>",
|
|
352
|
+
"parameters": [],
|
|
353
|
+
"references": {
|
|
354
|
+
"Promise": {
|
|
355
|
+
"location": "global",
|
|
356
|
+
"id": "global::Promise"
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
"return": "Promise<void>"
|
|
360
|
+
},
|
|
361
|
+
"docs": {
|
|
362
|
+
"text": "",
|
|
363
|
+
"tags": []
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
"clear": {
|
|
367
|
+
"complexType": {
|
|
368
|
+
"signature": "() => Promise<void>",
|
|
369
|
+
"parameters": [],
|
|
370
|
+
"references": {
|
|
371
|
+
"Promise": {
|
|
372
|
+
"location": "global",
|
|
373
|
+
"id": "global::Promise"
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
"return": "Promise<void>"
|
|
377
|
+
},
|
|
378
|
+
"docs": {
|
|
379
|
+
"text": "",
|
|
380
|
+
"tags": []
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
static get elementRef() { return "el"; }
|
|
386
|
+
static get watchers() {
|
|
387
|
+
return [{
|
|
388
|
+
"propName": "value",
|
|
389
|
+
"methodName": "handleSetValue"
|
|
390
|
+
}, {
|
|
391
|
+
"propName": "endpoint",
|
|
392
|
+
"methodName": "handleSetBaseUrl"
|
|
393
|
+
}];
|
|
394
|
+
}
|
|
395
|
+
static get attachInternalsMemberName() { return "internals"; }
|
|
18
396
|
}
|
package/dist/collection/index.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @fileoverview entry point for your component library
|
|
3
|
-
*
|
|
4
|
-
* This is the entry point for your component library. Use this file to export utilities,
|
|
5
|
-
* constants or data structure that accompany your components.
|
|
6
|
-
*
|
|
7
|
-
* DO NOT use this file to export your components. Instead, use the recommended approaches
|
|
8
|
-
* to consume components of this package as outlined in the `README.md`.
|
|
9
|
-
*/
|
|
10
|
-
export { format } from './utils/utils';
|
|
1
|
+
export {};
|