@spectrum-web-components/base 0.4.6 → 0.5.2
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/package.json +11 -4
- package/src/Base.d.ts +2 -2
- package/src/Base.js +2 -1
- package/src/Base.js.map +1 -1
- package/src/condition-attribute-with-id.d.ts +2 -0
- package/src/condition-attribute-with-id.js +36 -0
- package/src/condition-attribute-with-id.js.map +1 -0
- package/src/decorators.d.ts +1 -0
- package/src/decorators.js +13 -0
- package/src/decorators.js.map +1 -0
- package/src/directives.d.ts +7 -0
- package/src/directives.js +18 -0
- package/src/directives.js.map +1 -0
- package/src/html.d.ts +1 -0
- package/src/html.js +13 -0
- package/src/html.js.map +1 -0
- package/src/index.d.ts +1 -8
- package/src/index.js +1 -8
- package/src/index.js.map +1 -1
- package/src/sizedMixin.d.ts +5 -3
- package/src/sizedMixin.js +7 -22
- package/src/sizedMixin.js.map +1 -1
- package/src/streaming-listener.d.ts +42 -10
- package/src/streaming-listener.js +104 -86
- package/src/streaming-listener.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
".": "./src/index.js",
|
|
24
24
|
"./src/*": "./src/*",
|
|
25
|
+
"./condition-attribute-with-id": "./src/condition-attribute-with-id.js",
|
|
26
|
+
"./condition-attribute-with-id.js": "./src/condition-attribute-with-id.js",
|
|
27
|
+
"./decorators": "./src/decorators.js",
|
|
28
|
+
"./decorators.js": "./src/decorators.js",
|
|
29
|
+
"./directives": "./src/directives.js",
|
|
30
|
+
"./directives.js": "./src/directives.js",
|
|
31
|
+
"./html": "./src/html.js",
|
|
32
|
+
"./html.js": "./src/html.js",
|
|
25
33
|
"./streaming-listener": "./src/streaming-listener.js",
|
|
26
34
|
"./streaming-listener.js": "./src/streaming-listener.js",
|
|
27
35
|
"./package.json": "./package.json"
|
|
@@ -44,12 +52,11 @@
|
|
|
44
52
|
"lit-html"
|
|
45
53
|
],
|
|
46
54
|
"dependencies": {
|
|
47
|
-
"lit
|
|
48
|
-
"lit-html": "^1.0.0",
|
|
55
|
+
"lit": "^2.0.0",
|
|
49
56
|
"tslib": "^2.0.0"
|
|
50
57
|
},
|
|
51
58
|
"types": "./src/index.d.ts",
|
|
52
59
|
"customElements": "custom-elements.json",
|
|
53
60
|
"sideEffects": false,
|
|
54
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "bb5308b9be01cc7c5bbab289312042256bdcc740"
|
|
55
62
|
}
|
package/src/Base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement,
|
|
1
|
+
import { LitElement, ReactiveElement } from 'lit';
|
|
2
2
|
declare type Constructor<T = Record<string, unknown>> = {
|
|
3
3
|
new (...args: any[]): T;
|
|
4
4
|
prototype: T;
|
|
@@ -9,7 +9,7 @@ export interface SpectrumInterface {
|
|
|
9
9
|
hasVisibleFocusInTree(): boolean;
|
|
10
10
|
dir: 'ltr' | 'rtl';
|
|
11
11
|
}
|
|
12
|
-
export declare function SpectrumMixin<T extends Constructor<
|
|
12
|
+
export declare function SpectrumMixin<T extends Constructor<ReactiveElement>>(constructor: T): T & Constructor<SpectrumInterface>;
|
|
13
13
|
declare const SpectrumElement_base: typeof LitElement & Constructor<SpectrumInterface>;
|
|
14
14
|
export declare class SpectrumElement extends SpectrumElement_base {
|
|
15
15
|
}
|
package/src/Base.js
CHANGED
|
@@ -10,7 +10,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import { __decorate } from "tslib";
|
|
13
|
-
import { LitElement
|
|
13
|
+
import { LitElement } from 'lit';
|
|
14
|
+
import { property } from 'lit/decorators.js';
|
|
14
15
|
const observedForElements = new Set();
|
|
15
16
|
const updateRTL = () => {
|
|
16
17
|
const dir = document.documentElement.dir === 'rtl'
|
package/src/Base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base.js","sourceRoot":"","sources":["Base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAAE,UAAU,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"Base.js","sourceRoot":"","sources":["Base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAmB7C,MAAM,mBAAmB,GAAqB,IAAI,GAAG,EAAE,CAAC;AAExD,MAAM,SAAS,GAAG,GAAS,EAAE;IACzB,MAAM,GAAG,GACL,QAAQ,CAAC,eAAe,CAAC,GAAG,KAAK,KAAK;QAClC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,GAAG;QAC9B,CAAC,CAAC,KAAK,CAAC;IAChB,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAC/B,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAEpD,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE;IAC1C,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,CAAC,KAAK,CAAC;CAC3B,CAAC,CAAC;AAMH,MAAM,yBAAyB,GAAG,CAAC,EAA2B,EAAW,EAAE,CACvE,OAAO,EAAE,CAAC,6BAA6B,KAAK,WAAW;IACvD,EAAE,CAAC,OAAO,KAAK,UAAU,CAAC;AAE9B,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AK,QAAQ,CAAC,eAAe,EAAE;oBACxC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;iBACjC;qBAAM;oBACH,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;oBAChC,IACI,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBAC1B,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAChC;wBACE,cAAc,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;4BAExC,SACH,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;wBAC1C,CAAC,CAAC,CAAC;qBACN;yBAAM;wBACF,SAAuB,CAAC,6BAA6B,CAClD,IAAI,CACP,CAAC;qBACL;iBACJ;gBACD,IAAI,CAAC,UAAU,GAAG,SAAwB,CAAC;aAC9C;YACD,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC9B,CAAC;QAEM,oBAAoB;YACvB,KAAK,CAAC,oBAAoB,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjB,IAAI,IAAI,CAAC,UAAU,KAAK,QAAQ,CAAC,eAAe,EAAE;oBAC9C,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;iBACpC;qBAAM;oBACF,IAAI,CAAC,UAAwB,CAAC,4BAA4B,CACvD,IAAI,CACP,CAAC;iBACL;gBACD,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;aAC/B;QACL,CAAC;KACJ;IAnFG;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yDACM;IAoFtC,OAAO,wBAAwB,CAAC;AACpC,CAAC;AAED,MAAM,OAAO,eAAgB,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { LitElement, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\ntype ThemeRoot = HTMLElement & {\n startManagingContentDirection: (el: HTMLElement) => void;\n stopManagingContentDirection: (el: HTMLElement) => void;\n};\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SpectrumInterface {\n shadowRoot: ShadowRoot;\n isLTR: boolean;\n hasVisibleFocusInTree(): boolean;\n dir: 'ltr' | 'rtl';\n}\n\nconst observedForElements: Set<HTMLElement> = new Set();\n\nconst updateRTL = (): void => {\n const dir =\n document.documentElement.dir === 'rtl'\n ? document.documentElement.dir\n : 'ltr';\n observedForElements.forEach((el) => {\n el.setAttribute('dir', dir);\n });\n};\n\nconst rtlObserver = new MutationObserver(updateRTL);\n\nrtlObserver.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['dir'],\n});\n\ntype ContentDirectionManager = HTMLElement & {\n startManagingContentDirection?(): void;\n};\n\nconst canManageContentDirection = (el: ContentDirectionManager): boolean =>\n typeof el.startManagingContentDirection !== 'undefined' ||\n el.tagName === 'SP-THEME';\n\nexport function SpectrumMixin<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<SpectrumInterface> {\n class SlotTextObservingElement extends constructor {\n /**\n * @private\n */\n public shadowRoot!: ShadowRoot;\n private _dirParent?: HTMLElement;\n\n /**\n * @private\n */\n @property({ reflect: true })\n public dir: 'ltr' | 'rtl' = 'ltr';\n\n /**\n * @private\n */\n public get isLTR(): boolean {\n return this.dir === 'ltr';\n }\n\n public hasVisibleFocusInTree(): boolean {\n const activeElement = (this.getRootNode() as Document)\n .activeElement as HTMLElement;\n if (!activeElement) {\n return false;\n }\n // Browsers without support for the `:focus-visible`\n // selector will throw on the following test (Safari, older things).\n // Some won't throw, but will be focusing item rather than the menu and\n // will rely on the polyfill to know whether focus is \"visible\" or not.\n try {\n return (\n activeElement.matches(':focus-visible') ||\n activeElement.matches('.focus-visible')\n );\n } catch (error) {\n return activeElement.matches('.focus-visible');\n }\n }\n\n public connectedCallback(): void {\n if (!this.hasAttribute('dir')) {\n let dirParent = ((this as HTMLElement).assignedSlot ||\n this.parentNode) as HTMLElement;\n while (\n dirParent !== document.documentElement &&\n !canManageContentDirection(\n dirParent as ContentDirectionManager\n )\n ) {\n dirParent = ((dirParent as HTMLElement).assignedSlot || // step into the shadow DOM of the parent of a slotted node\n dirParent.parentNode || // DOM Element detected\n (dirParent as unknown as ShadowRoot)\n .host) as HTMLElement;\n }\n this.dir =\n dirParent.dir === 'rtl' ? dirParent.dir : this.dir || 'ltr';\n if (dirParent === document.documentElement) {\n observedForElements.add(this);\n } else {\n const { localName } = dirParent;\n if (\n localName.search('-') > -1 &&\n !customElements.get(localName)\n ) {\n customElements.whenDefined(localName).then(() => {\n (\n dirParent as ThemeRoot\n ).startManagingContentDirection(this);\n });\n } else {\n (dirParent as ThemeRoot).startManagingContentDirection(\n this\n );\n }\n }\n this._dirParent = dirParent as HTMLElement;\n }\n super.connectedCallback();\n }\n\n public disconnectedCallback(): void {\n super.disconnectedCallback();\n if (this._dirParent) {\n if (this._dirParent === document.documentElement) {\n observedForElements.delete(this);\n } else {\n (this._dirParent as ThemeRoot).stopManagingContentDirection(\n this\n );\n }\n this.removeAttribute('dir');\n }\n }\n }\n return SlotTextObservingElement;\n}\n\nexport class SpectrumElement extends SpectrumMixin(LitElement) {}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export function conditionAttributeWithoutId(el, attribute, ids) {
|
|
13
|
+
const ariaDescribedby = el.getAttribute(attribute);
|
|
14
|
+
let descriptors = ariaDescribedby ? ariaDescribedby.split(/\s+/) : [];
|
|
15
|
+
descriptors = descriptors.filter((descriptor) => !ids.find((id) => descriptor === id));
|
|
16
|
+
if (descriptors.length) {
|
|
17
|
+
el.setAttribute(attribute, descriptors.join(' '));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
el.removeAttribute(attribute);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function conditionAttributeWithId(el, attribute, id) {
|
|
24
|
+
const ids = Array.isArray(id) ? id : [id];
|
|
25
|
+
const ariaDescribedby = el.getAttribute(attribute);
|
|
26
|
+
const descriptors = ariaDescribedby ? ariaDescribedby.split(/\s+/) : [];
|
|
27
|
+
const hadIds = ids.every((id) => descriptors.indexOf(id) > -1);
|
|
28
|
+
if (hadIds)
|
|
29
|
+
return () => {
|
|
30
|
+
return;
|
|
31
|
+
};
|
|
32
|
+
descriptors.push(...ids);
|
|
33
|
+
el.setAttribute(attribute, descriptors.join(' '));
|
|
34
|
+
return () => conditionAttributeWithoutId(el, attribute, ids);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=condition-attribute-with-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-attribute-with-id.js","sourceRoot":"","sources":["condition-attribute-with-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,MAAM,UAAU,2BAA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B,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,OAAO,GAAG,EAAE,CAAC,2BAA2B,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;AACjE,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport function conditionAttributeWithoutId(\n el: HTMLElement,\n attribute: string,\n ids: string[]\n): void {\n const ariaDescribedby = el.getAttribute(attribute);\n let descriptors = ariaDescribedby ? ariaDescribedby.split(/\\s+/) : [];\n descriptors = descriptors.filter(\n (descriptor) => !ids.find((id) => descriptor === id)\n );\n if (descriptors.length) {\n el.setAttribute(attribute, descriptors.join(' '));\n } else {\n el.removeAttribute(attribute);\n }\n}\n\nexport function conditionAttributeWithId(\n el: HTMLElement,\n attribute: string,\n id: string | string[]\n): () => void {\n const ids = Array.isArray(id) ? id : [id];\n const ariaDescribedby = el.getAttribute(attribute);\n const descriptors = ariaDescribedby ? ariaDescribedby.split(/\\s+/) : [];\n const hadIds = ids.every((id) => descriptors.indexOf(id) > -1);\n if (hadIds)\n return (): void => {\n return;\n };\n descriptors.push(...ids);\n el.setAttribute(attribute, descriptors.join(' '));\n return () => conditionAttributeWithoutId(el, attribute, ids);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'lit/decorators.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export * from 'lit/decorators.js';
|
|
13
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,mBAAmB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from 'lit/decorators.js';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ifDefined } from 'lit/directives/if-defined.js';
|
|
2
|
+
export { repeat } from 'lit/directives/repeat.js';
|
|
3
|
+
export { classMap } from 'lit/directives/class-map.js';
|
|
4
|
+
export { styleMap } from 'lit/directives/style-map.js';
|
|
5
|
+
export type { StyleInfo } from 'lit/directives/style-map.js';
|
|
6
|
+
export { until } from 'lit/directives/until.js';
|
|
7
|
+
export { live } from 'lit/directives/live.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export { ifDefined } from 'lit/directives/if-defined.js';
|
|
13
|
+
export { repeat } from 'lit/directives/repeat.js';
|
|
14
|
+
export { classMap } from 'lit/directives/class-map.js';
|
|
15
|
+
export { styleMap } from 'lit/directives/style-map.js';
|
|
16
|
+
export { until } from 'lit/directives/until.js';
|
|
17
|
+
export { live } from 'lit/directives/live.js';
|
|
18
|
+
//# sourceMappingURL=directives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directives.js","sourceRoot":"","sources":["directives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport { ifDefined } from 'lit/directives/if-defined.js';\nexport { repeat } from 'lit/directives/repeat.js';\nexport { classMap } from 'lit/directives/class-map.js';\nexport { styleMap } from 'lit/directives/style-map.js';\nexport type { StyleInfo } from 'lit/directives/style-map.js';\nexport { until } from 'lit/directives/until.js';\nexport { live } from 'lit/directives/live.js';\n"]}
|
package/src/html.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { nothing, render } from 'lit/html.js';
|
package/src/html.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export { nothing, render } from 'lit/html.js';
|
|
13
|
+
//# sourceMappingURL=html.js.map
|
package/src/html.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport { nothing, render } from 'lit/html.js';\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
export * from './Base.js';
|
|
2
2
|
export * from './sizedMixin.js';
|
|
3
|
-
export * from 'lit
|
|
4
|
-
export { nothing } from 'lit-html';
|
|
5
|
-
export { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
6
|
-
export { repeat } from 'lit-html/directives/repeat.js';
|
|
7
|
-
export { classMap } from 'lit-html/directives/class-map.js';
|
|
8
|
-
export { styleMap } from 'lit-html/directives/style-map.js';
|
|
9
|
-
export { until } from 'lit-html/directives/until.js';
|
|
10
|
-
export { live } from 'lit-html/directives/live.js';
|
|
3
|
+
export * from 'lit';
|
package/src/index.js
CHANGED
|
@@ -11,12 +11,5 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
export * from './Base.js';
|
|
13
13
|
export * from './sizedMixin.js';
|
|
14
|
-
export * from 'lit
|
|
15
|
-
export { nothing } from 'lit-html';
|
|
16
|
-
export { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
17
|
-
export { repeat } from 'lit-html/directives/repeat.js';
|
|
18
|
-
export { classMap } from 'lit-html/directives/class-map.js';
|
|
19
|
-
export { styleMap } from 'lit-html/directives/style-map.js';
|
|
20
|
-
export { until } from 'lit-html/directives/until.js';
|
|
21
|
-
export { live } from 'lit-html/directives/live.js';
|
|
14
|
+
export * from 'lit';
|
|
22
15
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,KAAK,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './Base.js';\nexport * from './sizedMixin.js';\nexport * from 'lit';\n"]}
|
package/src/sizedMixin.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactiveElement } from 'lit';
|
|
2
2
|
declare type Constructor<T = Record<string, unknown>> = {
|
|
3
3
|
new (...args: any[]): T;
|
|
4
4
|
prototype: T;
|
|
5
5
|
};
|
|
6
|
-
export declare type ElementSize = 's' | 'm' | 'l' | 'xl' | 'xxl';
|
|
6
|
+
export declare type ElementSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';
|
|
7
|
+
export declare type DefaultElementSize = Exclude<ElementSize, 'xxs' | 'xs' | 'xxl'>;
|
|
7
8
|
export interface SizedElementInterface {
|
|
8
9
|
size: ElementSize;
|
|
9
10
|
}
|
|
10
|
-
export declare function SizedMixin<T extends Constructor<
|
|
11
|
+
export declare function SizedMixin<T extends Constructor<ReactiveElement>>(constructor: T, { validSizes, noDefaultSize, defaultSize, }?: {
|
|
11
12
|
validSizes?: ElementSize[];
|
|
12
13
|
noDefaultSize?: boolean;
|
|
14
|
+
defaultSize?: ElementSize;
|
|
13
15
|
}): T & Constructor<SizedElementInterface>;
|
|
14
16
|
export {};
|
package/src/sizedMixin.js
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
6
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
|
|
8
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
9
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
10
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
11
|
-
governing permissions and limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
import { property } from 'lit-element';
|
|
14
|
-
export function SizedMixin(constructor, { validSizes = ['s', 'm', 'l', 'xl'], noDefaultSize, } = {}) {
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
|
+
export function SizedMixin(constructor, { validSizes = ['s', 'm', 'l', 'xl'], noDefaultSize, defaultSize = 'm', } = {}) {
|
|
15
4
|
class SizedElement extends constructor {
|
|
16
5
|
constructor() {
|
|
17
6
|
super(...arguments);
|
|
18
|
-
this._size =
|
|
7
|
+
this._size = defaultSize;
|
|
19
8
|
}
|
|
20
9
|
get size() {
|
|
21
|
-
return this._size ||
|
|
10
|
+
return this._size || defaultSize;
|
|
22
11
|
}
|
|
23
12
|
set size(value) {
|
|
24
|
-
const
|
|
25
|
-
const size = (value
|
|
26
|
-
|
|
27
|
-
: value);
|
|
28
|
-
const validSize = (validSizes.includes(size)
|
|
29
|
-
? size
|
|
30
|
-
: defaultSize);
|
|
13
|
+
const fallbackSize = noDefaultSize ? null : defaultSize;
|
|
14
|
+
const size = (value ? value.toLocaleLowerCase() : value);
|
|
15
|
+
const validSize = (validSizes.includes(size) ? size : fallbackSize);
|
|
31
16
|
if (validSize) {
|
|
32
17
|
this.setAttribute('size', validSize);
|
|
33
18
|
}
|
package/src/sizedMixin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sizedMixin.js","sourceRoot":"","sources":["sizedMixin.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"sizedMixin.js","sourceRoot":"","sources":["sizedMixin.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAe7C,MAAM,UAAU,UAAU,CACtB,WAAc,EACd,EACI,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAClC,aAAa,EACb,WAAW,GAAG,GAAG,MAKjB,EAAE;IAEN,MAAM,YAAa,SAAQ,WAAW;QAAtC;;YAyBY,UAAK,GAAuB,WAAW,CAAC;QAQpD,CAAC;QA/BG,IAAW,IAAI;YACX,OAAO,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC;QACrC,CAAC;QAED,IAAW,IAAI,CAAC,KAAkB;YAC9B,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;YACxD,MAAM,IAAI,GAAG,CACT,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,KAAK,CAC7B,CAAC;YACjB,MAAM,SAAS,GAAG,CACd,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CACnC,CAAC;YACjB,IAAI,SAAS,EAAE;gBACX,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;aACxC;YACD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;gBAC1B,OAAO;aACV;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QAIS,YAAY,CAAC,OAAuB;YAC1C,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE;gBAC9C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aACxC;QACL,CAAC;KACJ;IA/BG;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CAGzC;IA8BL,OAAO,YAAY,CAAC;AACxB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport type ElementSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';\nexport type DefaultElementSize = Exclude<ElementSize, 'xxs' | 'xs' | 'xxl'>;\n\nexport interface SizedElementInterface {\n size: ElementSize;\n}\n\nexport function SizedMixin<T extends Constructor<ReactiveElement>>(\n constructor: T,\n {\n validSizes = ['s', 'm', 'l', 'xl'],\n noDefaultSize,\n defaultSize = 'm',\n }: {\n validSizes?: ElementSize[];\n noDefaultSize?: boolean;\n defaultSize?: ElementSize;\n } = {}\n): T & Constructor<SizedElementInterface> {\n class SizedElement extends constructor {\n @property({ type: String, reflect: true })\n public get size(): ElementSize {\n return this._size || defaultSize;\n }\n\n public set size(value: ElementSize) {\n const fallbackSize = noDefaultSize ? null : defaultSize;\n const size = (\n value ? value.toLocaleLowerCase() : value\n ) as ElementSize;\n const validSize = (\n validSizes.includes(size) ? size : fallbackSize\n ) as ElementSize;\n if (validSize) {\n this.setAttribute('size', validSize);\n }\n if (this._size === validSize) {\n return;\n }\n const oldSize = this._size;\n this._size = validSize;\n this.requestUpdate('size', oldSize);\n }\n\n private _size: ElementSize | null = defaultSize;\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (!this.hasAttribute('size') && !noDefaultSize) {\n this.setAttribute('size', this.size);\n }\n }\n }\n return SizedElement;\n}\n"]}
|
|
@@ -1,13 +1,45 @@
|
|
|
1
|
-
import { Part } from 'lit
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { nothing, Part } from 'lit';
|
|
2
|
+
import { AsyncDirective } from 'lit/async-directive.js';
|
|
3
|
+
import type { DirectiveResult } from 'lit/directive.js';
|
|
4
|
+
declare type ListenerConfig = [string | string[], (event?: any) => void];
|
|
5
|
+
declare type ListenerConfigGroup = {
|
|
6
|
+
start: ListenerConfig;
|
|
7
|
+
end: ListenerConfig;
|
|
8
|
+
streamInside?: ListenerConfig;
|
|
9
|
+
streamOutside?: ListenerConfig;
|
|
5
10
|
};
|
|
6
11
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
12
|
+
* Performantly manage listening to event in a series, like:
|
|
13
|
+
* - `input[type="range"]`: input, input, etc. => change
|
|
14
|
+
* - `sp-color-area`: pointerdown => pointermove, pointermove, etc. => pointerup
|
|
15
|
+
* Lazily bind events to the specific part of the series while
|
|
16
|
+
* throttling streamed events to 1/frame.
|
|
11
17
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
declare class StreamingListenerDirective extends AsyncDirective {
|
|
19
|
+
host: EventTarget | Record<string, unknown> | Element;
|
|
20
|
+
element: Element;
|
|
21
|
+
start: ListenerConfig;
|
|
22
|
+
streamInside: ListenerConfig;
|
|
23
|
+
end: ListenerConfig;
|
|
24
|
+
streamOutside: ListenerConfig;
|
|
25
|
+
state: 'off' | 'on';
|
|
26
|
+
render(_configGroup: ListenerConfigGroup): typeof nothing;
|
|
27
|
+
update(part: Part, [{ start, end, streamInside, streamOutside, },]: Parameters<this['render']>): void;
|
|
28
|
+
addListeners(state?: 'on' | 'off'): void;
|
|
29
|
+
callHandler(value: (event: Event) => void | EventListenerObject, event: Event): void;
|
|
30
|
+
handleStart: (event: Event) => void;
|
|
31
|
+
handleStream: (event: Event) => void;
|
|
32
|
+
handleEnd: (event: Event) => void;
|
|
33
|
+
handleBetween: (event: Event) => void;
|
|
34
|
+
addListener(type: string | string[], fn: (event: Event) => void): void;
|
|
35
|
+
removeListener(type: string | string[], fn: (event: Event) => void): void;
|
|
36
|
+
removeListeners(): void;
|
|
37
|
+
disconnected(): void;
|
|
38
|
+
reconnected(): void;
|
|
39
|
+
}
|
|
40
|
+
export declare const streamingListener: (_configGroup: ListenerConfigGroup) => DirectiveResult<typeof StreamingListenerDirective>;
|
|
41
|
+
/**
|
|
42
|
+
* The type of the class that powers this directive. Necessary for naming the
|
|
43
|
+
* directive's return type.
|
|
44
|
+
*/
|
|
45
|
+
export type { StreamingListenerDirective };
|
|
@@ -10,102 +10,120 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
10
10
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
11
11
|
governing permissions and limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
import { nothing } from 'lit';
|
|
14
|
+
import { AsyncDirective, directive } from 'lit/async-directive.js';
|
|
15
|
+
/* c8 ignore next 6 */
|
|
16
|
+
const defaultListener = [
|
|
17
|
+
'',
|
|
18
|
+
() => {
|
|
19
|
+
return;
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Performantly manage listening to event in a series, like:
|
|
24
|
+
* - `input[type="range"]`: input, input, etc. => change
|
|
25
|
+
* - `sp-color-area`: pointerdown => pointermove, pointermove, etc. => pointerup
|
|
26
|
+
* Lazily bind events to the specific part of the series while
|
|
27
|
+
* throttling streamed events to 1/frame.
|
|
28
|
+
*/
|
|
29
|
+
class StreamingListenerDirective extends AsyncDirective {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.start = defaultListener;
|
|
33
|
+
this.streamInside = defaultListener;
|
|
34
|
+
this.end = defaultListener;
|
|
35
|
+
this.streamOutside = defaultListener;
|
|
36
|
+
this.state = 'off';
|
|
37
|
+
this.handleStart = (event) => {
|
|
38
|
+
this.callHandler(this.start[1], event);
|
|
39
|
+
if (event.defaultPrevented) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.removeListeners();
|
|
43
|
+
this.addListeners('on');
|
|
44
|
+
};
|
|
45
|
+
this.handleStream = (event) => {
|
|
46
|
+
this.callHandler(this.streamInside[1], event);
|
|
47
|
+
};
|
|
48
|
+
this.handleEnd = (event) => {
|
|
49
|
+
this.callHandler(this.end[1], event);
|
|
50
|
+
this.removeListeners();
|
|
51
|
+
this.addListeners('off');
|
|
52
|
+
};
|
|
53
|
+
this.handleBetween = (event) => {
|
|
54
|
+
this.callHandler(this.streamOutside[1], event);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/* c8 ignore next 4 */
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
|
+
render(_configGroup) {
|
|
60
|
+
return nothing;
|
|
21
61
|
}
|
|
22
|
-
|
|
23
|
-
|
|
62
|
+
update(part, [{ start, end, streamInside = defaultListener, streamOutside = defaultListener, },]) {
|
|
63
|
+
var _a;
|
|
64
|
+
if (this.element !== part.element) {
|
|
65
|
+
this.element = part.element;
|
|
66
|
+
this.removeListeners();
|
|
67
|
+
}
|
|
68
|
+
this.host =
|
|
69
|
+
((_a = part.options) === null || _a === void 0 ? void 0 : _a.host) || this.element;
|
|
70
|
+
this.start = start;
|
|
71
|
+
this.end = end;
|
|
72
|
+
this.streamInside = streamInside;
|
|
73
|
+
this.streamOutside = streamOutside;
|
|
74
|
+
this.addListeners();
|
|
24
75
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
76
|
+
addListeners(state) {
|
|
77
|
+
this.state = state || this.state;
|
|
78
|
+
if (this.state === 'off') {
|
|
79
|
+
this.addListener(this.streamOutside[0], this.handleBetween);
|
|
80
|
+
this.addListener(this.start[0], this.handleStart);
|
|
81
|
+
}
|
|
82
|
+
else if (this.state === 'on') {
|
|
83
|
+
this.addListener(this.streamInside[0], this.handleStream);
|
|
84
|
+
this.addListener(this.end[0], this.handleEnd);
|
|
85
|
+
}
|
|
31
86
|
}
|
|
32
|
-
|
|
33
|
-
|
|
87
|
+
callHandler(value, event) {
|
|
88
|
+
if (typeof value === 'function') {
|
|
89
|
+
value.call(this.host, event);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
value.handleEvent(event);
|
|
93
|
+
}
|
|
34
94
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let handledStream = false;
|
|
40
|
-
const handleStream = (event) => {
|
|
41
|
-
if (!handledStream) {
|
|
42
|
-
handledStream = true;
|
|
43
|
-
stream.fn.call(eventContext || element, event);
|
|
44
|
-
requestAnimationFrame(() => {
|
|
45
|
-
handledStream = false;
|
|
95
|
+
addListener(type, fn) {
|
|
96
|
+
if (Array.isArray(type)) {
|
|
97
|
+
type.map((eventName) => {
|
|
98
|
+
this.element.addEventListener(eventName, fn);
|
|
46
99
|
});
|
|
47
100
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
addListener(element, start.type, handleStart);
|
|
51
|
-
removeListener(element, stream.type, handleStream);
|
|
52
|
-
removeListener(element, end.type, handleEnd);
|
|
53
|
-
stateMap.set(part, false);
|
|
54
|
-
end.fn.call(eventContext || element, event);
|
|
55
|
-
};
|
|
56
|
-
const handleStart = (event) => {
|
|
57
|
-
start.fn.call(eventContext || element, event);
|
|
58
|
-
if (event.defaultPrevented) {
|
|
59
|
-
return;
|
|
101
|
+
else {
|
|
102
|
+
this.element.addEventListener(type, fn);
|
|
60
103
|
}
|
|
61
|
-
removeListener(element, start.type, handleStart);
|
|
62
|
-
addListener(element, stream.type, handleStream);
|
|
63
|
-
addListener(element, end.type, handleEnd);
|
|
64
|
-
stateMap.set(part, true);
|
|
65
|
-
};
|
|
66
|
-
if (!isStreaming) {
|
|
67
|
-
addListener(element, start.type, handleStart);
|
|
68
104
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
105
|
+
removeListener(type, fn) {
|
|
106
|
+
if (Array.isArray(type)) {
|
|
107
|
+
type.map((eventName) => {
|
|
108
|
+
this.element.removeEventListener(eventName, fn);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.element.removeEventListener(type, fn);
|
|
113
|
+
}
|
|
72
114
|
}
|
|
73
|
-
|
|
74
|
-
removeListener(
|
|
75
|
-
removeListener(
|
|
76
|
-
removeListener(
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* For AttributeParts, sets the attribute if the value is defined and removes
|
|
81
|
-
* the attribute if the value is undefined.
|
|
82
|
-
*
|
|
83
|
-
* For other part types, this directive is a no-op.
|
|
84
|
-
*/
|
|
85
|
-
export const streamingListener = directive((start, stream, end) => (part) => {
|
|
86
|
-
if (!(part instanceof EventPart)) {
|
|
87
|
-
return;
|
|
115
|
+
removeListeners() {
|
|
116
|
+
this.removeListener(this.start[0], this.handleStart);
|
|
117
|
+
this.removeListener(this.streamInside[0], this.handleStream);
|
|
118
|
+
this.removeListener(this.end[0], this.handleEnd);
|
|
119
|
+
this.removeListener(this.streamOutside[0], this.handleBetween);
|
|
88
120
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (start.type === previous.start.type &&
|
|
92
|
-
stream.type === previous.stream.type &&
|
|
93
|
-
end.type === previous.end.type &&
|
|
94
|
-
start.fn === previous.start.fn &&
|
|
95
|
-
stream.fn === previous.stream.fn &&
|
|
96
|
-
end.fn === previous.end.fn) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
previous.removeEventListeners();
|
|
121
|
+
disconnected() {
|
|
122
|
+
this.removeListeners();
|
|
100
123
|
}
|
|
101
|
-
|
|
102
|
-
|
|
124
|
+
reconnected() {
|
|
125
|
+
this.addListeners();
|
|
103
126
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
stream,
|
|
107
|
-
end,
|
|
108
|
-
removeEventListeners: addEventListeners(part, start, stream, end),
|
|
109
|
-
});
|
|
110
|
-
});
|
|
127
|
+
}
|
|
128
|
+
export const streamingListener = directive(StreamingListenerDirective);
|
|
111
129
|
//# sourceMappingURL=streaming-listener.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming-listener.js","sourceRoot":"","sources":["streaming-listener.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD;;;;;;;;;;EAUE;AACF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"streaming-listener.js","sourceRoot":"","sources":["streaming-listener.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD;;;;;;;;;;EAUE;AACF,OAAO,EAAe,OAAO,EAAQ,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAWnE,sBAAsB;AACtB,MAAM,eAAe,GAAmB;IACpC,EAAE;IACF,GAAS,EAAE;QACP,OAAO;IACX,CAAC;CACJ,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,0BAA2B,SAAQ,cAAc;IAAvD;;QAII,UAAK,GAA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AC,eAAe,EAAE,CAAC;IAC3B,CAAC;IAED,WAAW;QACP,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,iBAAiB,GAE4B,SAAS,CAC/D,0BAA0B,CAC7B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ElementPart, nothing, Part } from 'lit';\nimport { AsyncDirective, directive } from 'lit/async-directive.js';\nimport type { DirectiveResult } from 'lit/directive.js';\n\ntype ListenerConfig = [string | string[], (event?: any) => void];\ntype ListenerConfigGroup = {\n start: ListenerConfig;\n end: ListenerConfig;\n streamInside?: ListenerConfig;\n streamOutside?: ListenerConfig;\n};\n\n/* c8 ignore next 6 */\nconst defaultListener: ListenerConfig = [\n '',\n (): void => {\n return;\n },\n];\n\n/**\n * Performantly manage listening to event in a series, like:\n * - `input[type=\"range\"]`: input, input, etc. => change\n * - `sp-color-area`: pointerdown => pointermove, pointermove, etc. => pointerup\n * Lazily bind events to the specific part of the series while\n * throttling streamed events to 1/frame.\n */\nclass StreamingListenerDirective extends AsyncDirective {\n host!: EventTarget | Record<string, unknown> | Element;\n element!: Element;\n\n start: ListenerConfig = defaultListener;\n streamInside: ListenerConfig = defaultListener;\n end: ListenerConfig = defaultListener;\n streamOutside: ListenerConfig = defaultListener;\n\n state: 'off' | 'on' = 'off';\n\n /* c8 ignore next 4 */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n render(_configGroup: ListenerConfigGroup): typeof nothing {\n return nothing;\n }\n\n update(\n part: Part,\n [\n {\n start,\n end,\n streamInside = defaultListener,\n streamOutside = defaultListener,\n },\n ]: Parameters<this['render']>\n ): void {\n if (this.element !== (part as ElementPart).element) {\n this.element = (part as ElementPart).element;\n this.removeListeners();\n }\n this.host =\n (part.options?.host as Record<string, unknown>) || this.element;\n this.start = start;\n this.end = end;\n this.streamInside = streamInside;\n this.streamOutside = streamOutside;\n this.addListeners();\n }\n\n addListeners(state?: 'on' | 'off'): void {\n this.state = state || this.state;\n if (this.state === 'off') {\n this.addListener(this.streamOutside[0], this.handleBetween);\n this.addListener(this.start[0], this.handleStart);\n } else if (this.state === 'on') {\n this.addListener(this.streamInside[0], this.handleStream);\n this.addListener(this.end[0], this.handleEnd);\n }\n }\n\n callHandler(\n value: (event: Event) => void | EventListenerObject,\n event: Event\n ): void {\n if (typeof value === 'function') {\n (value as (event: Event) => void).call(this.host, event);\n } else {\n (value as EventListenerObject).handleEvent(event);\n }\n }\n\n handleStart = (event: Event): void => {\n this.callHandler(this.start[1], event);\n if (event.defaultPrevented) {\n return;\n }\n this.removeListeners();\n this.addListeners('on');\n };\n\n handleStream = (event: Event): void => {\n this.callHandler(this.streamInside[1], event);\n };\n\n handleEnd = (event: Event): void => {\n this.callHandler(this.end[1], event);\n this.removeListeners();\n this.addListeners('off');\n };\n\n handleBetween = (event: Event): void => {\n this.callHandler(this.streamOutside[1], event);\n };\n\n addListener(type: string | string[], fn: (event: Event) => void): void {\n if (Array.isArray(type)) {\n type.map((eventName) => {\n this.element.addEventListener(eventName, fn);\n });\n } else {\n this.element.addEventListener(type, fn);\n }\n }\n\n removeListener(type: string | string[], fn: (event: Event) => void): void {\n if (Array.isArray(type)) {\n type.map((eventName) => {\n this.element.removeEventListener(eventName, fn);\n });\n } else {\n this.element.removeEventListener(type, fn);\n }\n }\n\n removeListeners(): void {\n this.removeListener(this.start[0], this.handleStart);\n this.removeListener(this.streamInside[0], this.handleStream);\n this.removeListener(this.end[0], this.handleEnd);\n this.removeListener(this.streamOutside[0], this.handleBetween);\n }\n\n disconnected(): void {\n this.removeListeners();\n }\n\n reconnected(): void {\n this.addListeners();\n }\n}\n\nexport const streamingListener: (\n _configGroup: ListenerConfigGroup\n) => DirectiveResult<typeof StreamingListenerDirective> = directive(\n StreamingListenerDirective\n);\n\n/**\n * The type of the class that powers this directive. Necessary for naming the\n * directive's return type.\n */\nexport type { StreamingListenerDirective };\n"]}
|