@spectrum-web-components/shared 0.14.4 → 0.14.5
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 +52 -6
- package/src/first-focusable-in.dev.js +6 -0
- package/src/first-focusable-in.dev.js.map +7 -0
- package/src/first-focusable-in.js +3 -14
- package/src/first-focusable-in.js.map +7 -1
- package/src/focus-visible.dev.js +68 -0
- package/src/focus-visible.dev.js.map +7 -0
- package/src/focus-visible.js +59 -105
- package/src/focus-visible.js.map +7 -1
- package/src/focusable.dev.js +190 -0
- package/src/focusable.dev.js.map +7 -0
- package/src/focusable.js +185 -244
- package/src/focusable.js.map +7 -1
- package/src/get-active-element.dev.js +4 -0
- package/src/get-active-element.dev.js.map +7 -0
- package/src/get-active-element.js +2 -14
- package/src/get-active-element.js.map +7 -1
- package/src/get-deep-element-from-point.dev.js +12 -0
- package/src/get-deep-element-from-point.dev.js.map +7 -0
- package/src/get-deep-element-from-point.js +9 -20
- package/src/get-deep-element-from-point.js.map +7 -1
- package/src/index.dev.js +10 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +10 -21
- package/src/index.js.map +7 -1
- package/src/like-anchor.dev.js +58 -0
- package/src/like-anchor.dev.js.map +7 -0
- package/src/like-anchor.js +45 -40
- package/src/like-anchor.js.map +7 -1
- package/src/observe-slot-presence.dev.js +52 -0
- package/src/observe-slot-presence.dev.js.map +7 -0
- package/src/observe-slot-presence.js +47 -55
- package/src/observe-slot-presence.js.map +7 -1
- package/src/observe-slot-text.dev.js +79 -0
- package/src/observe-slot-text.dev.js.map +7 -0
- package/src/observe-slot-text.js +73 -64
- package/src/observe-slot-text.js.map +7 -1
- package/src/platform.dev.js +31 -0
- package/src/platform.dev.js.map +7 -0
- package/src/platform.js +11 -32
- package/src/platform.js.map +7 -1
- package/src/reparent-children.dev.js +50 -0
- package/src/reparent-children.dev.js.map +7 -0
- package/src/reparent-children.js +44 -52
- package/src/reparent-children.js.map +7 -1
- package/test/focusable.test.js +19 -31
- package/test/focusable.test.js.map +7 -1
- package/test/observe-slot-presence.test.js +17 -27
- package/test/observe-slot-presence.test.js.map +7 -1
- package/test/observe-slot-text.test.js +17 -28
- package/test/observe-slot-text.test.js.map +7 -1
- package/test/reparent-children.test.js +151 -162
- package/test/reparent-children.test.js.map +7 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["observe-slot-text.ts"],
|
|
4
|
+
"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 '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst assignedNodesList = Symbol('assignedNodes');\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 SlotTextObservingInterface {\n slotHasContent: boolean;\n manageTextObservedSlot(): void;\n}\n\nexport function ObserveSlotText<T extends Constructor<ReactiveElement>>(\n constructor: T,\n slotName?: string\n): T & Constructor<SlotTextObservingInterface> {\n class SlotTextObservingElement\n extends constructor\n implements SlotTextObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n characterData: true,\n subtree: true,\n },\n callback: (mutationsList: Array<MutationRecord>) => {\n for (const mutation of mutationsList) {\n if (mutation.type === 'characterData') {\n this.manageTextObservedSlot();\n return;\n }\n }\n },\n });\n }\n\n @property({ type: Boolean, attribute: false })\n public slotHasContent = false;\n\n @queryAssignedNodes(slotName, true)\n private [assignedNodesList]!: NodeListOf<HTMLElement>;\n\n public manageTextObservedSlot(): void {\n if (!this[assignedNodesList]) return;\n const assignedNodes = [...this[assignedNodesList]].filter(\n (node) => {\n if ((node as HTMLElement).tagName) {\n return true;\n }\n return node.textContent ? node.textContent.trim() : false;\n }\n );\n this.slotHasContent = assignedNodes.length > 0;\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (!this.hasUpdated) {\n const { childNodes } = this;\n const textNodes = [...childNodes].filter((node) => {\n if ((node as HTMLElement).tagName) {\n return slotName\n ? (node as HTMLElement).getAttribute('slot') ===\n slotName\n : !(node as HTMLElement).hasAttribute('slot');\n }\n return node.textContent ? node.textContent.trim() : false;\n });\n this.slotHasContent = textNodes.length > 0;\n }\n super.update(changedProperties);\n }\n\n protected override firstUpdated(\n changedProperties: PropertyValues\n ): void {\n super.firstUpdated(changedProperties);\n this.updateComplete.then(() => {\n this.manageTextObservedSlot();\n });\n }\n }\n return SlotTextObservingElement;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAAA;AAIA;AAEA,MAAM,oBAAoB,OAAO,eAAe;AAazC,gCACH,aACA,UAC2C;AAlC/C;AAmCI,QAAM,iCACM,YAEZ;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AAmBP,4BAAiB;AAjBpB,UAAI,mBAAmB,MAAM;AAAA,QACzB,QAAQ;AAAA,UACJ,eAAe;AAAA,UACf,SAAS;AAAA,QACb;AAAA,QACA,UAAU,CAAC,kBAAyC;AAChD,qBAAW,YAAY,eAAe;AAClC,gBAAI,SAAS,SAAS,iBAAiB;AACnC,mBAAK,uBAAuB;AAC5B;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,IAQO,yBAA+B;AAClC,UAAI,CAAC,KAAK;AAAoB;AAC9B,YAAM,gBAAgB,CAAC,GAAG,KAAK,kBAAkB,EAAE,OAC/C,CAAC,SAAS;AACN,YAAK,KAAqB,SAAS;AAC/B,iBAAO;AAAA,QACX;AACA,eAAO,KAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAAA,MACxD,CACJ;AACA,WAAK,iBAAiB,cAAc,SAAS;AAAA,IACjD;AAAA,IAEmB,OAAO,mBAAyC;AAC/D,UAAI,CAAC,KAAK,YAAY;AAClB,cAAM,EAAE,eAAe;AACvB,cAAM,YAAY,CAAC,GAAG,UAAU,EAAE,OAAO,CAAC,SAAS;AAC/C,cAAK,KAAqB,SAAS;AAC/B,mBAAO,WACA,KAAqB,aAAa,MAAM,MACrC,WACJ,CAAE,KAAqB,aAAa,MAAM;AAAA,UACpD;AACA,iBAAO,KAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAAA,QACxD,CAAC;AACD,aAAK,iBAAiB,UAAU,SAAS;AAAA,MAC7C;AACA,YAAM,OAAO,iBAAiB;AAAA,IAClC;AAAA,IAEmB,aACf,mBACI;AACJ,YAAM,aAAa,iBAAiB;AACpC,WAAK,eAAe,KAAK,MAAM;AAC3B,aAAK,uBAAuB;AAAA,MAChC,CAAC;AAAA,IACL;AAAA,EACJ;AAvGJ,EA+DiB;AAHF;AAAA,IADP,AAAC,SAAS,EAAE,MAAM,SAAS,WAAW,MAAM,CAAC;AAAA,KACtC,AAzBX,yBAyBW;AAGE;AAAA,IADT,AAAC,mBAAmB,UAAU,IAAI;AAAA,KACzB,AA5Bb,yBA4Ba;AAyCb,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/observe-slot-text.js
CHANGED
|
@@ -1,70 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
property,
|
|
14
|
+
queryAssignedNodes
|
|
15
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
16
|
+
import { MutationController } from "@lit-labs/observers/mutation_controller.js";
|
|
17
|
+
const assignedNodesList = Symbol("assignedNodes");
|
|
5
18
|
export function ObserveSlotText(constructor, slotName) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
manageTextObservedSlot() {
|
|
28
|
-
if (!this[assignedNodesList])
|
|
29
|
-
return;
|
|
30
|
-
const assignedNodes = [...this[assignedNodesList]].filter((node) => {
|
|
31
|
-
if (node.tagName) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return node.textContent ? node.textContent.trim() : false;
|
|
35
|
-
});
|
|
36
|
-
this.slotHasContent = assignedNodes.length > 0;
|
|
37
|
-
}
|
|
38
|
-
update(changedProperties) {
|
|
39
|
-
if (!this.hasUpdated) {
|
|
40
|
-
const { childNodes } = this;
|
|
41
|
-
const textNodes = [...childNodes].filter((node) => {
|
|
42
|
-
if (node.tagName) {
|
|
43
|
-
return slotName
|
|
44
|
-
? node.getAttribute('slot') ===
|
|
45
|
-
slotName
|
|
46
|
-
: !node.hasAttribute('slot');
|
|
47
|
-
}
|
|
48
|
-
return node.textContent ? node.textContent.trim() : false;
|
|
49
|
-
});
|
|
50
|
-
this.slotHasContent = textNodes.length > 0;
|
|
19
|
+
var _a;
|
|
20
|
+
class SlotTextObservingElement extends constructor {
|
|
21
|
+
constructor(...args) {
|
|
22
|
+
super(args);
|
|
23
|
+
this.slotHasContent = false;
|
|
24
|
+
new MutationController(this, {
|
|
25
|
+
config: {
|
|
26
|
+
characterData: true,
|
|
27
|
+
subtree: true
|
|
28
|
+
},
|
|
29
|
+
callback: (mutationsList) => {
|
|
30
|
+
for (const mutation of mutationsList) {
|
|
31
|
+
if (mutation.type === "characterData") {
|
|
32
|
+
this.manageTextObservedSlot();
|
|
33
|
+
return;
|
|
51
34
|
}
|
|
52
|
-
|
|
35
|
+
}
|
|
53
36
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
manageTextObservedSlot() {
|
|
40
|
+
if (!this[assignedNodesList])
|
|
41
|
+
return;
|
|
42
|
+
const assignedNodes = [...this[assignedNodesList]].filter((node) => {
|
|
43
|
+
if (node.tagName) {
|
|
44
|
+
return true;
|
|
59
45
|
}
|
|
46
|
+
return node.textContent ? node.textContent.trim() : false;
|
|
47
|
+
});
|
|
48
|
+
this.slotHasContent = assignedNodes.length > 0;
|
|
49
|
+
}
|
|
50
|
+
update(changedProperties) {
|
|
51
|
+
if (!this.hasUpdated) {
|
|
52
|
+
const { childNodes } = this;
|
|
53
|
+
const textNodes = [...childNodes].filter((node) => {
|
|
54
|
+
if (node.tagName) {
|
|
55
|
+
return slotName ? node.getAttribute("slot") === slotName : !node.hasAttribute("slot");
|
|
56
|
+
}
|
|
57
|
+
return node.textContent ? node.textContent.trim() : false;
|
|
58
|
+
});
|
|
59
|
+
this.slotHasContent = textNodes.length > 0;
|
|
60
|
+
}
|
|
61
|
+
super.update(changedProperties);
|
|
62
|
+
}
|
|
63
|
+
firstUpdated(changedProperties) {
|
|
64
|
+
super.firstUpdated(changedProperties);
|
|
65
|
+
this.updateComplete.then(() => {
|
|
66
|
+
this.manageTextObservedSlot();
|
|
67
|
+
});
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
}
|
|
70
|
+
_a = assignedNodesList;
|
|
71
|
+
__decorateClass([
|
|
72
|
+
property({ type: Boolean, attribute: false })
|
|
73
|
+
], SlotTextObservingElement.prototype, "slotHasContent", 2);
|
|
74
|
+
__decorateClass([
|
|
75
|
+
queryAssignedNodes(slotName, true)
|
|
76
|
+
], SlotTextObservingElement.prototype, _a, 2);
|
|
77
|
+
return SlotTextObservingElement;
|
|
69
78
|
}
|
|
70
|
-
//# sourceMappingURL=observe-slot-text.js.map
|
|
79
|
+
//# sourceMappingURL=observe-slot-text.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["observe-slot-text.ts"],
|
|
4
|
+
"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 '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst assignedNodesList = Symbol('assignedNodes');\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 SlotTextObservingInterface {\n slotHasContent: boolean;\n manageTextObservedSlot(): void;\n}\n\nexport function ObserveSlotText<T extends Constructor<ReactiveElement>>(\n constructor: T,\n slotName?: string\n): T & Constructor<SlotTextObservingInterface> {\n class SlotTextObservingElement\n extends constructor\n implements SlotTextObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n characterData: true,\n subtree: true,\n },\n callback: (mutationsList: Array<MutationRecord>) => {\n for (const mutation of mutationsList) {\n if (mutation.type === 'characterData') {\n this.manageTextObservedSlot();\n return;\n }\n }\n },\n });\n }\n\n @property({ type: Boolean, attribute: false })\n public slotHasContent = false;\n\n @queryAssignedNodes(slotName, true)\n private [assignedNodesList]!: NodeListOf<HTMLElement>;\n\n public manageTextObservedSlot(): void {\n if (!this[assignedNodesList]) return;\n const assignedNodes = [...this[assignedNodesList]].filter(\n (node) => {\n if ((node as HTMLElement).tagName) {\n return true;\n }\n return node.textContent ? node.textContent.trim() : false;\n }\n );\n this.slotHasContent = assignedNodes.length > 0;\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (!this.hasUpdated) {\n const { childNodes } = this;\n const textNodes = [...childNodes].filter((node) => {\n if ((node as HTMLElement).tagName) {\n return slotName\n ? (node as HTMLElement).getAttribute('slot') ===\n slotName\n : !(node as HTMLElement).hasAttribute('slot');\n }\n return node.textContent ? node.textContent.trim() : false;\n });\n this.slotHasContent = textNodes.length > 0;\n }\n super.update(changedProperties);\n }\n\n protected override firstUpdated(\n changedProperties: PropertyValues\n ): void {\n super.firstUpdated(changedProperties);\n this.updateComplete.then(() => {\n this.manageTextObservedSlot();\n });\n }\n }\n return SlotTextObservingElement;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAAA;AAIA;AAEA,MAAM,oBAAoB,OAAO,eAAe;AAazC,gCACH,aACA,UAC2C;AAlC/C;AAmCI,QAAM,iCACM,YAEZ;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AAmBP,4BAAiB;AAjBpB,UAAI,mBAAmB,MAAM;AAAA,QACzB,QAAQ;AAAA,UACJ,eAAe;AAAA,UACf,SAAS;AAAA,QACb;AAAA,QACA,UAAU,CAAC,kBAAyC;AAChD,qBAAW,YAAY,eAAe;AAClC,gBAAI,SAAS,SAAS,iBAAiB;AACnC,mBAAK,uBAAuB;AAC5B;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,IAQO,yBAA+B;AAClC,UAAI,CAAC,KAAK;AAAoB;AAC9B,YAAM,gBAAgB,CAAC,GAAG,KAAK,kBAAkB,EAAE,OAC/C,CAAC,SAAS;AACN,YAAK,KAAqB,SAAS;AAC/B,iBAAO;AAAA,QACX;AACA,eAAO,KAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAAA,MACxD,CACJ;AACA,WAAK,iBAAiB,cAAc,SAAS;AAAA,IACjD;AAAA,IAEmB,OAAO,mBAAyC;AAC/D,UAAI,CAAC,KAAK,YAAY;AAClB,cAAM,EAAE,eAAe;AACvB,cAAM,YAAY,CAAC,GAAG,UAAU,EAAE,OAAO,CAAC,SAAS;AAC/C,cAAK,KAAqB,SAAS;AAC/B,mBAAO,WACA,KAAqB,aAAa,MAAM,MACrC,WACJ,CAAE,KAAqB,aAAa,MAAM;AAAA,UACpD;AACA,iBAAO,KAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAAA,QACxD,CAAC;AACD,aAAK,iBAAiB,UAAU,SAAS;AAAA,MAC7C;AACA,YAAM,OAAO,iBAAiB;AAAA,IAClC;AAAA,IAEmB,aACf,mBACI;AACJ,YAAM,aAAa,iBAAiB;AACpC,WAAK,eAAe,KAAK,MAAM;AAC3B,aAAK,uBAAuB;AAAA,MAChC,CAAC;AAAA,IACL;AAAA,EACJ;AAvGJ,EA+DiB;AAHF;AAAA,IADP,AAAC,SAAS,EAAE,MAAM,SAAS,WAAW,MAAM,CAAC;AAAA,KACtC,AAzBX,yBAyBW;AAGE;AAAA,IADT,AAAC,mBAAmB,UAAU,IAAI;AAAA,KACzB,AA5Bb,yBA4Ba;AAyCb,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function testUserAgent(re) {
|
|
2
|
+
return typeof window !== "undefined" && window.navigator != null ? re.test(window.navigator.userAgent) : false;
|
|
3
|
+
}
|
|
4
|
+
function testPlatform(re) {
|
|
5
|
+
return typeof window !== "undefined" && window.navigator != null ? re.test(window.navigator.platform) : false;
|
|
6
|
+
}
|
|
7
|
+
export function isMac() {
|
|
8
|
+
return testPlatform(/^Mac/);
|
|
9
|
+
}
|
|
10
|
+
export function isIPhone() {
|
|
11
|
+
return testPlatform(/^iPhone/);
|
|
12
|
+
}
|
|
13
|
+
export function isIPad() {
|
|
14
|
+
return testPlatform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
|
|
15
|
+
}
|
|
16
|
+
export function isIOS() {
|
|
17
|
+
return isIPhone() || isIPad();
|
|
18
|
+
}
|
|
19
|
+
export function isAppleDevice() {
|
|
20
|
+
return isMac() || isIOS();
|
|
21
|
+
}
|
|
22
|
+
export function isWebKit() {
|
|
23
|
+
return testUserAgent(/AppleWebKit/) && !isChrome();
|
|
24
|
+
}
|
|
25
|
+
export function isChrome() {
|
|
26
|
+
return testUserAgent(/Chrome/);
|
|
27
|
+
}
|
|
28
|
+
export function isAndroid() {
|
|
29
|
+
return testUserAgent(/Android/);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=platform.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["platform.ts"],
|
|
4
|
+
"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\nfunction testUserAgent(re: RegExp): boolean {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator.userAgent)\n : false;\n}\n\nfunction testPlatform(re: RegExp): boolean {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator.platform)\n : false;\n}\n\n/* c8 ignore next 3 */\nexport function isMac(): boolean {\n return testPlatform(/^Mac/);\n}\n\nexport function isIPhone(): boolean {\n return testPlatform(/^iPhone/);\n}\n\nexport function isIPad(): boolean {\n return (\n testPlatform(/^iPad/) ||\n // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.\n (isMac() && navigator.maxTouchPoints > 1)\n );\n}\n\nexport function isIOS(): boolean {\n return isIPhone() || isIPad();\n}\n\n/* c8 ignore next 3 */\nexport function isAppleDevice(): boolean {\n return isMac() || isIOS();\n}\n\n/* c8 ignore next 3 */\nexport function isWebKit(): boolean {\n return testUserAgent(/AppleWebKit/) && !isChrome();\n}\n\n/* c8 ignore next 3 */\nexport function isChrome(): boolean {\n return testUserAgent(/Chrome/);\n}\n\nexport function isAndroid(): boolean {\n return testUserAgent(/Android/);\n}\n"],
|
|
5
|
+
"mappings": "AAYA,uBAAuB,IAAqB;AACxC,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa,OACtD,GAAG,KAAK,OAAO,UAAU,SAAS,IAClC;AACV;AAEA,sBAAsB,IAAqB;AACvC,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa,OACtD,GAAG,KAAK,OAAO,UAAU,QAAQ,IACjC;AACV;AAGO,wBAA0B;AAC7B,SAAO,aAAa,MAAM;AAC9B;AAEO,2BAA6B;AAChC,SAAO,aAAa,SAAS;AACjC;AAEO,yBAA2B;AAC9B,SACI,aAAa,OAAO,KAEnB,MAAM,KAAK,UAAU,iBAAiB;AAE/C;AAEO,wBAA0B;AAC7B,SAAO,SAAS,KAAK,OAAO;AAChC;AAGO,gCAAkC;AACrC,SAAO,MAAM,KAAK,MAAM;AAC5B;AAGO,2BAA6B;AAChC,SAAO,cAAc,aAAa,KAAK,CAAC,SAAS;AACrD;AAGO,2BAA6B;AAChC,SAAO,cAAc,QAAQ;AACjC;AAEO,4BAA8B;AACjC,SAAO,cAAc,SAAS;AAClC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/platform.js
CHANGED
|
@@ -1,52 +1,31 @@
|
|
|
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
1
|
function testUserAgent(re) {
|
|
13
|
-
|
|
14
|
-
? re.test(window.navigator.userAgent)
|
|
15
|
-
: false;
|
|
2
|
+
return typeof window !== "undefined" && window.navigator != null ? re.test(window.navigator.userAgent) : false;
|
|
16
3
|
}
|
|
17
4
|
function testPlatform(re) {
|
|
18
|
-
|
|
19
|
-
? re.test(window.navigator.platform)
|
|
20
|
-
: false;
|
|
5
|
+
return typeof window !== "undefined" && window.navigator != null ? re.test(window.navigator.platform) : false;
|
|
21
6
|
}
|
|
22
|
-
/* c8 ignore next 3 */
|
|
23
7
|
export function isMac() {
|
|
24
|
-
|
|
8
|
+
return testPlatform(/^Mac/);
|
|
25
9
|
}
|
|
26
10
|
export function isIPhone() {
|
|
27
|
-
|
|
11
|
+
return testPlatform(/^iPhone/);
|
|
28
12
|
}
|
|
29
13
|
export function isIPad() {
|
|
30
|
-
|
|
31
|
-
// iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
|
|
32
|
-
(isMac() && navigator.maxTouchPoints > 1));
|
|
14
|
+
return testPlatform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
|
|
33
15
|
}
|
|
34
16
|
export function isIOS() {
|
|
35
|
-
|
|
17
|
+
return isIPhone() || isIPad();
|
|
36
18
|
}
|
|
37
|
-
/* c8 ignore next 3 */
|
|
38
19
|
export function isAppleDevice() {
|
|
39
|
-
|
|
20
|
+
return isMac() || isIOS();
|
|
40
21
|
}
|
|
41
|
-
/* c8 ignore next 3 */
|
|
42
22
|
export function isWebKit() {
|
|
43
|
-
|
|
23
|
+
return testUserAgent(/AppleWebKit/) && !isChrome();
|
|
44
24
|
}
|
|
45
|
-
/* c8 ignore next 3 */
|
|
46
25
|
export function isChrome() {
|
|
47
|
-
|
|
26
|
+
return testUserAgent(/Chrome/);
|
|
48
27
|
}
|
|
49
28
|
export function isAndroid() {
|
|
50
|
-
|
|
29
|
+
return testUserAgent(/Android/);
|
|
51
30
|
}
|
|
52
|
-
//# sourceMappingURL=platform.js.map
|
|
31
|
+
//# sourceMappingURL=platform.js.map
|
package/src/platform.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["platform.ts"],
|
|
4
|
+
"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\nfunction testUserAgent(re: RegExp): boolean {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator.userAgent)\n : false;\n}\n\nfunction testPlatform(re: RegExp): boolean {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator.platform)\n : false;\n}\n\n/* c8 ignore next 3 */\nexport function isMac(): boolean {\n return testPlatform(/^Mac/);\n}\n\nexport function isIPhone(): boolean {\n return testPlatform(/^iPhone/);\n}\n\nexport function isIPad(): boolean {\n return (\n testPlatform(/^iPad/) ||\n // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.\n (isMac() && navigator.maxTouchPoints > 1)\n );\n}\n\nexport function isIOS(): boolean {\n return isIPhone() || isIPad();\n}\n\n/* c8 ignore next 3 */\nexport function isAppleDevice(): boolean {\n return isMac() || isIOS();\n}\n\n/* c8 ignore next 3 */\nexport function isWebKit(): boolean {\n return testUserAgent(/AppleWebKit/) && !isChrome();\n}\n\n/* c8 ignore next 3 */\nexport function isChrome(): boolean {\n return testUserAgent(/Chrome/);\n}\n\nexport function isAndroid(): boolean {\n return testUserAgent(/Android/);\n}\n"],
|
|
5
|
+
"mappings": "AAYA,uBAAuB,IAAqB;AACxC,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa,OACtD,GAAG,KAAK,OAAO,UAAU,SAAS,IAClC;AACV;AAEA,sBAAsB,IAAqB;AACvC,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa,OACtD,GAAG,KAAK,OAAO,UAAU,QAAQ,IACjC;AACV;AAGO,wBAA0B;AAC7B,SAAO,aAAa,MAAM;AAC9B;AAEO,2BAA6B;AAChC,SAAO,aAAa,SAAS;AACjC;AAEO,yBAA2B;AAC9B,SACI,aAAa,OAAO,KAEnB,MAAM,KAAK,UAAU,iBAAiB;AAE/C;AAEO,wBAA0B;AAC7B,SAAO,SAAS,KAAK,OAAO;AAChC;AAGO,gCAAkC;AACrC,SAAO,MAAM,KAAK,MAAM;AAC5B;AAGO,2BAA6B;AAChC,SAAO,cAAc,aAAa,KAAK,CAAC,SAAS;AACrD;AAGO,2BAA6B;AAChC,SAAO,cAAc,QAAQ;AACjC;AAEO,4BAA8B;AACjC,SAAO,cAAc,SAAS;AAClC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function restoreChildren(placeholderItems, srcElements, cleanupCallbacks = []) {
|
|
2
|
+
for (let index = 0; index < srcElements.length; ++index) {
|
|
3
|
+
const srcElement = srcElements[index];
|
|
4
|
+
const placeholderItem = placeholderItems[index];
|
|
5
|
+
const parentElement = placeholderItem.parentElement || placeholderItem.getRootNode();
|
|
6
|
+
if (cleanupCallbacks[index]) {
|
|
7
|
+
cleanupCallbacks[index](srcElement);
|
|
8
|
+
}
|
|
9
|
+
if (parentElement && parentElement !== placeholderItem) {
|
|
10
|
+
parentElement.replaceChild(srcElement, placeholderItem);
|
|
11
|
+
}
|
|
12
|
+
delete placeholderItems[index];
|
|
13
|
+
}
|
|
14
|
+
return srcElements;
|
|
15
|
+
}
|
|
16
|
+
export const reparentChildren = (srcElements, destination, {
|
|
17
|
+
position,
|
|
18
|
+
prepareCallback
|
|
19
|
+
} = { position: "beforeend" }) => {
|
|
20
|
+
let { length } = srcElements;
|
|
21
|
+
if (length === 0) {
|
|
22
|
+
return () => srcElements;
|
|
23
|
+
}
|
|
24
|
+
let step = 1;
|
|
25
|
+
let index = 0;
|
|
26
|
+
if (position === "afterbegin" || position === "afterend") {
|
|
27
|
+
step = -1;
|
|
28
|
+
index = length - 1;
|
|
29
|
+
}
|
|
30
|
+
const placeholderItems = new Array(length);
|
|
31
|
+
const cleanupCallbacks = new Array(length);
|
|
32
|
+
const placeholderTemplate = document.createComment("placeholder for reparented element");
|
|
33
|
+
do {
|
|
34
|
+
const srcElement = srcElements[index];
|
|
35
|
+
if (prepareCallback) {
|
|
36
|
+
cleanupCallbacks[index] = prepareCallback(srcElement);
|
|
37
|
+
}
|
|
38
|
+
placeholderItems[index] = placeholderTemplate.cloneNode();
|
|
39
|
+
const parentElement = srcElement.parentElement || srcElement.getRootNode();
|
|
40
|
+
if (parentElement && parentElement !== srcElement) {
|
|
41
|
+
parentElement.replaceChild(placeholderItems[index], srcElement);
|
|
42
|
+
}
|
|
43
|
+
destination.insertAdjacentElement(position, srcElement);
|
|
44
|
+
index += step;
|
|
45
|
+
} while (--length > 0);
|
|
46
|
+
return function() {
|
|
47
|
+
return restoreChildren(placeholderItems, srcElements, cleanupCallbacks);
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=reparent-children.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["reparent-children.ts"],
|
|
4
|
+
"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*/\nfunction restoreChildren<T extends Element>(\n placeholderItems: Comment[],\n srcElements: T[],\n cleanupCallbacks: ((el: T) => void)[] = []\n): T[] {\n for (let index = 0; index < srcElements.length; ++index) {\n const srcElement = srcElements[index];\n const placeholderItem = placeholderItems[index];\n const parentElement =\n placeholderItem.parentElement || placeholderItem.getRootNode();\n if (cleanupCallbacks[index]) {\n cleanupCallbacks[index](srcElement);\n }\n if (parentElement && parentElement !== placeholderItem) {\n parentElement.replaceChild(srcElement, placeholderItem);\n }\n delete placeholderItems[index];\n }\n return srcElements;\n}\n\nexport const reparentChildren = <T extends Element>(\n srcElements: T[],\n destination: Element,\n {\n position,\n prepareCallback,\n }: {\n position: InsertPosition;\n prepareCallback?: (el: T) => ((el: T) => void) | void;\n } = { position: 'beforeend' }\n): (() => T[]) => {\n let { length } = srcElements;\n if (length === 0) {\n return () => srcElements;\n }\n\n let step = 1;\n let index = 0;\n\n if (position === 'afterbegin' || position === 'afterend') {\n step = -1;\n index = length - 1;\n }\n\n const placeholderItems = new Array<Comment>(length);\n const cleanupCallbacks = new Array<(el: T) => void>(length);\n const placeholderTemplate: Comment = document.createComment(\n 'placeholder for reparented element'\n );\n\n do {\n const srcElement = srcElements[index];\n if (prepareCallback) {\n cleanupCallbacks[index] = prepareCallback(srcElement) as (\n el: T\n ) => void;\n }\n placeholderItems[index] = placeholderTemplate.cloneNode() as Comment;\n\n const parentElement =\n srcElement.parentElement || srcElement.getRootNode();\n if (parentElement && parentElement !== srcElement) {\n parentElement.replaceChild(placeholderItems[index], srcElement);\n }\n destination.insertAdjacentElement(position, srcElement);\n\n index += step;\n } while (--length > 0);\n\n return function (): T[] {\n return restoreChildren<T>(\n placeholderItems,\n srcElements,\n cleanupCallbacks\n );\n };\n};\n"],
|
|
5
|
+
"mappings": "AAWA,yBACI,kBACA,aACA,mBAAwC,CAAC,GACtC;AACH,WAAS,QAAQ,GAAG,QAAQ,YAAY,QAAQ,EAAE,OAAO;AACrD,UAAM,aAAa,YAAY;AAC/B,UAAM,kBAAkB,iBAAiB;AACzC,UAAM,gBACF,gBAAgB,iBAAiB,gBAAgB,YAAY;AACjE,QAAI,iBAAiB,QAAQ;AACzB,uBAAiB,OAAO,UAAU;AAAA,IACtC;AACA,QAAI,iBAAiB,kBAAkB,iBAAiB;AACpD,oBAAc,aAAa,YAAY,eAAe;AAAA,IAC1D;AACA,WAAO,iBAAiB;AAAA,EAC5B;AACA,SAAO;AACX;AAEO,aAAM,mBAAmB,CAC5B,aACA,aACA;AAAA,EACI;AAAA,EACA;AAAA,IAIA,EAAE,UAAU,YAAY,MACd;AACd,MAAI,EAAE,WAAW;AACjB,MAAI,WAAW,GAAG;AACd,WAAO,MAAM;AAAA,EACjB;AAEA,MAAI,OAAO;AACX,MAAI,QAAQ;AAEZ,MAAI,aAAa,gBAAgB,aAAa,YAAY;AACtD,WAAO;AACP,YAAQ,SAAS;AAAA,EACrB;AAEA,QAAM,mBAAmB,IAAI,MAAe,MAAM;AAClD,QAAM,mBAAmB,IAAI,MAAuB,MAAM;AAC1D,QAAM,sBAA+B,SAAS,cAC1C,oCACJ;AAEA,KAAG;AACC,UAAM,aAAa,YAAY;AAC/B,QAAI,iBAAiB;AACjB,uBAAiB,SAAS,gBAAgB,UAAU;AAAA,IAGxD;AACA,qBAAiB,SAAS,oBAAoB,UAAU;AAExD,UAAM,gBACF,WAAW,iBAAiB,WAAW,YAAY;AACvD,QAAI,iBAAiB,kBAAkB,YAAY;AAC/C,oBAAc,aAAa,iBAAiB,QAAQ,UAAU;AAAA,IAClE;AACA,gBAAY,sBAAsB,UAAU,UAAU;AAEtD,aAAS;AAAA,EACb,SAAS,EAAE,SAAS;AAEpB,SAAO,WAAiB;AACpB,WAAO,gBACH,kBACA,aACA,gBACJ;AAAA,EACJ;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/reparent-children.js
CHANGED
|
@@ -1,58 +1,50 @@
|
|
|
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
1
|
function restoreChildren(placeholderItems, srcElements, cleanupCallbacks = []) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
if (parentElement && parentElement !== placeholderItem) {
|
|
21
|
-
parentElement.replaceChild(srcElement, placeholderItem);
|
|
22
|
-
}
|
|
23
|
-
delete placeholderItems[index];
|
|
2
|
+
for (let index = 0; index < srcElements.length; ++index) {
|
|
3
|
+
const srcElement = srcElements[index];
|
|
4
|
+
const placeholderItem = placeholderItems[index];
|
|
5
|
+
const parentElement = placeholderItem.parentElement || placeholderItem.getRootNode();
|
|
6
|
+
if (cleanupCallbacks[index]) {
|
|
7
|
+
cleanupCallbacks[index](srcElement);
|
|
24
8
|
}
|
|
25
|
-
|
|
9
|
+
if (parentElement && parentElement !== placeholderItem) {
|
|
10
|
+
parentElement.replaceChild(srcElement, placeholderItem);
|
|
11
|
+
}
|
|
12
|
+
delete placeholderItems[index];
|
|
13
|
+
}
|
|
14
|
+
return srcElements;
|
|
26
15
|
}
|
|
27
|
-
export const reparentChildren = (srcElements, destination, {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
export const reparentChildren = (srcElements, destination, {
|
|
17
|
+
position,
|
|
18
|
+
prepareCallback
|
|
19
|
+
} = { position: "beforeend" }) => {
|
|
20
|
+
let { length } = srcElements;
|
|
21
|
+
if (length === 0) {
|
|
22
|
+
return () => srcElements;
|
|
23
|
+
}
|
|
24
|
+
let step = 1;
|
|
25
|
+
let index = 0;
|
|
26
|
+
if (position === "afterbegin" || position === "afterend") {
|
|
27
|
+
step = -1;
|
|
28
|
+
index = length - 1;
|
|
29
|
+
}
|
|
30
|
+
const placeholderItems = new Array(length);
|
|
31
|
+
const cleanupCallbacks = new Array(length);
|
|
32
|
+
const placeholderTemplate = document.createComment("placeholder for reparented element");
|
|
33
|
+
do {
|
|
34
|
+
const srcElement = srcElements[index];
|
|
35
|
+
if (prepareCallback) {
|
|
36
|
+
cleanupCallbacks[index] = prepareCallback(srcElement);
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
index = length - 1;
|
|
38
|
+
placeholderItems[index] = placeholderTemplate.cloneNode();
|
|
39
|
+
const parentElement = srcElement.parentElement || srcElement.getRootNode();
|
|
40
|
+
if (parentElement && parentElement !== srcElement) {
|
|
41
|
+
parentElement.replaceChild(placeholderItems[index], srcElement);
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
cleanupCallbacks[index] = prepareCallback(srcElement);
|
|
45
|
-
}
|
|
46
|
-
placeholderItems[index] = placeholderTemplate.cloneNode();
|
|
47
|
-
const parentElement = srcElement.parentElement || srcElement.getRootNode();
|
|
48
|
-
if (parentElement && parentElement !== srcElement) {
|
|
49
|
-
parentElement.replaceChild(placeholderItems[index], srcElement);
|
|
50
|
-
}
|
|
51
|
-
destination.insertAdjacentElement(position, srcElement);
|
|
52
|
-
index += step;
|
|
53
|
-
} while (--length > 0);
|
|
54
|
-
return function () {
|
|
55
|
-
return restoreChildren(placeholderItems, srcElements, cleanupCallbacks);
|
|
56
|
-
};
|
|
43
|
+
destination.insertAdjacentElement(position, srcElement);
|
|
44
|
+
index += step;
|
|
45
|
+
} while (--length > 0);
|
|
46
|
+
return function() {
|
|
47
|
+
return restoreChildren(placeholderItems, srcElements, cleanupCallbacks);
|
|
48
|
+
};
|
|
57
49
|
};
|
|
58
|
-
//# sourceMappingURL=reparent-children.js.map
|
|
50
|
+
//# sourceMappingURL=reparent-children.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["reparent-children.ts"],
|
|
4
|
+
"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*/\nfunction restoreChildren<T extends Element>(\n placeholderItems: Comment[],\n srcElements: T[],\n cleanupCallbacks: ((el: T) => void)[] = []\n): T[] {\n for (let index = 0; index < srcElements.length; ++index) {\n const srcElement = srcElements[index];\n const placeholderItem = placeholderItems[index];\n const parentElement =\n placeholderItem.parentElement || placeholderItem.getRootNode();\n if (cleanupCallbacks[index]) {\n cleanupCallbacks[index](srcElement);\n }\n if (parentElement && parentElement !== placeholderItem) {\n parentElement.replaceChild(srcElement, placeholderItem);\n }\n delete placeholderItems[index];\n }\n return srcElements;\n}\n\nexport const reparentChildren = <T extends Element>(\n srcElements: T[],\n destination: Element,\n {\n position,\n prepareCallback,\n }: {\n position: InsertPosition;\n prepareCallback?: (el: T) => ((el: T) => void) | void;\n } = { position: 'beforeend' }\n): (() => T[]) => {\n let { length } = srcElements;\n if (length === 0) {\n return () => srcElements;\n }\n\n let step = 1;\n let index = 0;\n\n if (position === 'afterbegin' || position === 'afterend') {\n step = -1;\n index = length - 1;\n }\n\n const placeholderItems = new Array<Comment>(length);\n const cleanupCallbacks = new Array<(el: T) => void>(length);\n const placeholderTemplate: Comment = document.createComment(\n 'placeholder for reparented element'\n );\n\n do {\n const srcElement = srcElements[index];\n if (prepareCallback) {\n cleanupCallbacks[index] = prepareCallback(srcElement) as (\n el: T\n ) => void;\n }\n placeholderItems[index] = placeholderTemplate.cloneNode() as Comment;\n\n const parentElement =\n srcElement.parentElement || srcElement.getRootNode();\n if (parentElement && parentElement !== srcElement) {\n parentElement.replaceChild(placeholderItems[index], srcElement);\n }\n destination.insertAdjacentElement(position, srcElement);\n\n index += step;\n } while (--length > 0);\n\n return function (): T[] {\n return restoreChildren<T>(\n placeholderItems,\n srcElements,\n cleanupCallbacks\n );\n };\n};\n"],
|
|
5
|
+
"mappings": "AAWA,yBACI,kBACA,aACA,mBAAwC,CAAC,GACtC;AACH,WAAS,QAAQ,GAAG,QAAQ,YAAY,QAAQ,EAAE,OAAO;AACrD,UAAM,aAAa,YAAY;AAC/B,UAAM,kBAAkB,iBAAiB;AACzC,UAAM,gBACF,gBAAgB,iBAAiB,gBAAgB,YAAY;AACjE,QAAI,iBAAiB,QAAQ;AACzB,uBAAiB,OAAO,UAAU;AAAA,IACtC;AACA,QAAI,iBAAiB,kBAAkB,iBAAiB;AACpD,oBAAc,aAAa,YAAY,eAAe;AAAA,IAC1D;AACA,WAAO,iBAAiB;AAAA,EAC5B;AACA,SAAO;AACX;AAEO,aAAM,mBAAmB,CAC5B,aACA,aACA;AAAA,EACI;AAAA,EACA;AAAA,IAIA,EAAE,UAAU,YAAY,MACd;AACd,MAAI,EAAE,WAAW;AACjB,MAAI,WAAW,GAAG;AACd,WAAO,MAAM;AAAA,EACjB;AAEA,MAAI,OAAO;AACX,MAAI,QAAQ;AAEZ,MAAI,aAAa,gBAAgB,aAAa,YAAY;AACtD,WAAO;AACP,YAAQ,SAAS;AAAA,EACrB;AAEA,QAAM,mBAAmB,IAAI,MAAe,MAAM;AAClD,QAAM,mBAAmB,IAAI,MAAuB,MAAM;AAC1D,QAAM,sBAA+B,SAAS,cAC1C,oCACJ;AAEA,KAAG;AACC,UAAM,aAAa,YAAY;AAC/B,QAAI,iBAAiB;AACjB,uBAAiB,SAAS,gBAAgB,UAAU;AAAA,IAGxD;AACA,qBAAiB,SAAS,oBAAoB,UAAU;AAExD,UAAM,gBACF,WAAW,iBAAiB,WAAW,YAAY;AACvD,QAAI,iBAAiB,kBAAkB,YAAY;AAC/C,oBAAc,aAAa,iBAAiB,QAAQ,UAAU;AAAA,IAClE;AACA,gBAAY,sBAAsB,UAAU,UAAU;AAEtD,aAAS;AAAA,EACb,SAAS,EAAE,SAAS;AAEpB,SAAO,WAAiB;AACpB,WAAO,gBACH,kBACA,aACA,gBACJ;AAAA,EACJ;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/test/focusable.test.js
CHANGED
|
@@ -1,34 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import '../src/focusable.js';
|
|
13
|
-
import { Focusable } from '../src/focusable.js';
|
|
14
|
-
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
|
15
|
-
describe('Focusable', () => {
|
|
16
|
-
it('enforces the presense of a `focusElement`', async () => {
|
|
17
|
-
customElements.define('focusable-test', class extends Focusable {
|
|
18
|
-
});
|
|
19
|
-
try {
|
|
20
|
-
const el = await fixture(html `
|
|
1
|
+
import "@spectrum-web-components/shared/src/focusable.js";
|
|
2
|
+
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
3
|
+
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
4
|
+
describe("Focusable", () => {
|
|
5
|
+
it("enforces the presense of a `focusElement`", async () => {
|
|
6
|
+
customElements.define("focusable-test", class extends Focusable {
|
|
7
|
+
});
|
|
8
|
+
try {
|
|
9
|
+
const el = await fixture(html`
|
|
21
10
|
<focusable-test></focusable-test>
|
|
22
11
|
`);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
12
|
+
await elementUpdated(el);
|
|
13
|
+
const focusEl = el.focusElement;
|
|
14
|
+
expect(focusEl).to.exist;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
expect(() => {
|
|
17
|
+
throw error;
|
|
18
|
+
}).to.throw("Must implement focusElement getter!");
|
|
19
|
+
}
|
|
20
|
+
});
|
|
33
21
|
});
|
|
34
|
-
//# sourceMappingURL=focusable.test.js.map
|
|
22
|
+
//# sourceMappingURL=focusable.test.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["focusable.test.ts"],
|
|
4
|
+
"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 '@spectrum-web-components/shared/src/focusable.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\ndescribe('Focusable', () => {\n it('enforces the presense of a `focusElement`', async () => {\n customElements.define('focusable-test', class extends Focusable {});\n try {\n const el = await fixture<Focusable>(\n html`\n <focusable-test></focusable-test>\n `\n );\n await elementUpdated(el);\n const focusEl = el.focusElement;\n expect(focusEl).to.exist;\n } catch (error) {\n expect(() => {\n throw error;\n }).to.throw('Must implement focusElement getter!');\n }\n });\n});\n"],
|
|
5
|
+
"mappings": "AAYA;AACA;AACA;AAEA,SAAS,aAAa,MAAM;AACxB,KAAG,6CAA6C,YAAY;AACxD,mBAAe,OAAO,kBAAkB,cAAc,UAAU;AAAA,IAAC,CAAC;AAClE,QAAI;AACA,YAAM,KAAK,MAAM,QACb;AAAA;AAAA,iBAGJ;AACA,YAAM,eAAe,EAAE;AACvB,YAAM,UAAU,GAAG;AACnB,aAAO,OAAO,EAAE,GAAG;AAAA,IACvB,SAAS,OAAP;AACE,aAAO,MAAM;AACT,cAAM;AAAA,MACV,CAAC,EAAE,GAAG,MAAM,qCAAqC;AAAA,IACrD;AAAA,EACJ,CAAC;AACL,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|