@spectrum-web-components/shared 0.14.6-devmode.0 → 0.15.0
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 +4 -4
- package/src/first-focusable-in.js +1 -5
- package/src/first-focusable-in.js.map +1 -1
- package/src/focus-visible.js +1 -67
- package/src/focus-visible.js.map +1 -1
- package/src/focusable.js +1 -189
- package/src/focusable.js.map +1 -1
- package/src/get-active-element.js +1 -3
- package/src/get-active-element.js.map +1 -1
- package/src/get-deep-element-from-point.js +1 -11
- package/src/get-deep-element-from-point.js.map +1 -1
- package/src/index.js +1 -9
- package/src/index.js.map +1 -1
- package/src/like-anchor.js +12 -57
- package/src/like-anchor.js.map +1 -1
- package/src/observe-slot-presence.js +1 -51
- package/src/observe-slot-presence.js.map +1 -1
- package/src/observe-slot-text.js +1 -78
- package/src/observe-slot-text.js.map +1 -1
- package/src/platform.js +1 -30
- package/src/platform.js.map +1 -1
- package/src/reparent-children.js +1 -49
- package/src/reparent-children.js.map +1 -1
- package/test/focusable.test.js +2 -20
- package/test/focusable.test.js.map +1 -1
- package/test/observe-slot-presence.test.js +3 -21
- package/test/observe-slot-presence.test.js.map +1 -1
- package/test/observe-slot-text.test.js +3 -21
- package/test/observe-slot-text.test.js.map +1 -1
- package/test/reparent-children.test.js +9 -164
- package/test/reparent-children.test.js.map +1 -1
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.ts"],
|
|
4
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\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 { ReactiveElement } from '@spectrum-web-components/base';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst slotContentIsPresent = Symbol('slotContentIsPresent');\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 SlotPresenceObservingInterface {\n slotContentIsPresent: boolean;\n getSlotContentPresence(selector: string): boolean;\n managePresenceObservedSlot(): void;\n}\n\nexport function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement\n extends constructor\n implements SlotPresenceObservingInterface\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 childList: true,\n subtree: true,\n },\n callback: () => {\n this.managePresenceObservedSlot();\n },\n });\n\n this.managePresenceObservedSlot();\n }\n\n /**\n * @private\n */\n public get slotContentIsPresent(): boolean {\n if (lightDomSelectors.length === 1) {\n return (\n this[slotContentIsPresent].get(lightDomSelectors[0]) ||\n false\n );\n } else {\n throw new Error(\n 'Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.'\n );\n }\n }\n private [slotContentIsPresent]: Map<string, boolean> = new Map();\n\n public getSlotContentPresence(selector: string): boolean {\n if (this[slotContentIsPresent].has(selector)) {\n return this[slotContentIsPresent].get(selector) || false;\n }\n throw new Error(\n `The provided selector \\`${selector}\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n let changes = false;\n lightDomSelectors.forEach((selector) => {\n const nextValue = !!this.querySelector(selector);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n if (changes) {\n this.updateComplete.then(() => {\n this.requestUpdate();\n });\n }\n };\n }\n return SlotPresenceObservingElement;\n}\n"],
|
|
5
|
-
"mappings": "AAWA
|
|
5
|
+
"mappings": "AAWA,gFAEA,KAAM,GAAuB,OAAO,sBAAsB,EAcnD,oCACH,EACA,EAC+C,CA9BnD,MA+BI,KAAM,GAAoB,MAAM,QAAQ,CAAgB,EAClD,EACA,CAAC,CAAgB,EACvB,MAAM,SACM,EAEZ,CAEI,eAAe,EAAa,CACxB,MAAM,CAAI,EA8BL,QAA8C,GAAI,KAWpD,gCAA6B,IAAY,CAC5C,GAAI,GAAU,GACd,EAAkB,QAAQ,AAAC,GAAa,CACpC,KAAM,GAAY,CAAC,CAAC,KAAK,cAAc,CAAQ,EACzC,EACF,KAAK,GAAsB,IAAI,CAAQ,GAAK,GAChD,EAAU,GAAW,IAAkB,EACvC,KAAK,GAAsB,IACvB,EACA,CAAC,CAAC,KAAK,cAAc,CAAQ,CACjC,CACJ,CAAC,EACG,GACA,KAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,cAAc,CACvB,CAAC,CAET,EAxDI,GAAI,GAAmB,KAAM,CACzB,OAAQ,CACJ,UAAW,GACX,QAAS,EACb,EACA,SAAU,IAAM,CACZ,KAAK,2BAA2B,CACpC,CACJ,CAAC,EAED,KAAK,2BAA2B,CACpC,IAKW,uBAAgC,CACvC,GAAI,EAAkB,SAAW,EAC7B,MACI,MAAK,GAAsB,IAAI,EAAkB,EAAE,GACnD,GAGJ,KAAM,IAAI,OACN,8GACJ,CAER,CAGO,uBAAuB,EAA2B,CACrD,GAAI,KAAK,GAAsB,IAAI,CAAQ,EACvC,MAAO,MAAK,GAAsB,IAAI,CAAQ,GAAK,GAEvD,KAAM,IAAI,OACN,2BAA2B,4BAC/B,CACJ,CAoBJ,CAnGJ,MAsEiB,KA8BN,CACX",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/observe-slot-text.js
CHANGED
|
@@ -1,79 +1,2 @@
|
|
|
1
|
-
var
|
|
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");
|
|
18
|
-
export function ObserveSlotText(constructor, slotName) {
|
|
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;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
manageTextObservedSlot() {
|
|
40
|
-
if (!this[assignedNodesList])
|
|
41
|
-
return;
|
|
42
|
-
const assignedNodes = [...this[assignedNodesList]].filter((node) => {
|
|
43
|
-
if (node.tagName) {
|
|
44
|
-
return true;
|
|
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
|
-
});
|
|
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;
|
|
78
|
-
}
|
|
1
|
+
var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=(i,r,o,n)=>{for(var s=n>1?void 0:n?p(r,o):r,t=i.length-1,e;t>=0;t--)(e=i[t])&&(s=(n?e(r,o,s):e(s))||s);return n&&s&&d(r,o,s),s};import{property as f,queryAssignedNodes as m}from"@spectrum-web-components/base/src/decorators.js";import{MutationController as g}from"@lit-labs/observers/mutation_controller.js";const c=Symbol("assignedNodes");export function ObserveSlotText(i,r){var n;class o extends i{constructor(...t){super(t);this.slotHasContent=!1;new g(this,{config:{characterData:!0,subtree:!0},callback:e=>{for(const l of e)if(l.type==="characterData"){this.manageTextObservedSlot();return}}})}manageTextObservedSlot(){if(!this[c])return;const t=[...this[c]].filter(e=>e.tagName?!0:e.textContent?e.textContent.trim():!1);this.slotHasContent=t.length>0}update(t){if(!this.hasUpdated){const{childNodes:e}=this,l=[...e].filter(a=>a.tagName?r?a.getAttribute("slot")===r:!a.hasAttribute("slot"):a.textContent?a.textContent.trim():!1);this.slotHasContent=l.length>0}super.update(t)}firstUpdated(t){super.firstUpdated(t),this.updateComplete.then(()=>{this.manageTextObservedSlot()})}}return n=c,u([f({type:Boolean,attribute:!1})],o.prototype,"slotHasContent",2),u([m(r,!0)],o.prototype,n,2),o}
|
|
79
2
|
//# sourceMappingURL=observe-slot-text.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-text.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": "wMAYA,mGAIA,gFAEA,KAAM,GAAoB,OAAO,eAAe,EAazC,gCACH,EACA,EAC2C,CAlC/C,MAmCI,MAAM,SACM,EAEZ,CAEI,eAAe,EAAa,CACxB,MAAM,CAAI,EAmBP,oBAAiB,GAjBpB,GAAI,GAAmB,KAAM,CACzB,OAAQ,CACJ,cAAe,GACf,QAAS,EACb,EACA,SAAU,AAAC,GAAyC,CAChD,SAAW,KAAY,GACnB,GAAI,EAAS,OAAS,gBAAiB,CACnC,KAAK,uBAAuB,EAC5B,MACJ,CAER,CACJ,CAAC,CACL,CAQO,wBAA+B,CAClC,GAAI,CAAC,KAAK,GAAoB,OAC9B,KAAM,GAAgB,CAAC,GAAG,KAAK,EAAkB,EAAE,OAC/C,AAAC,GACQ,EAAqB,QACf,GAEJ,EAAK,YAAc,EAAK,YAAY,KAAK,EAAI,EAE5D,EACA,KAAK,eAAiB,EAAc,OAAS,CACjD,CAEmB,OAAO,EAAyC,CAC/D,GAAI,CAAC,KAAK,WAAY,CAClB,KAAM,CAAE,cAAe,KACjB,EAAY,CAAC,GAAG,CAAU,EAAE,OAAO,AAAC,GACjC,EAAqB,QACf,EACA,EAAqB,aAAa,MAAM,IACrC,EACJ,CAAE,EAAqB,aAAa,MAAM,EAE7C,EAAK,YAAc,EAAK,YAAY,KAAK,EAAI,EACvD,EACD,KAAK,eAAiB,EAAU,OAAS,CAC7C,CACA,MAAM,OAAO,CAAiB,CAClC,CAEmB,aACf,EACI,CACJ,MAAM,aAAa,CAAiB,EACpC,KAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,uBAAuB,CAChC,CAAC,CACL,CACJ,CAvGJ,MA+DiB,KAHF,GADP,AAAC,EAAS,CAAE,KAAM,QAAS,UAAW,EAAM,CAAC,GACtC,AAzBX,EAyBW,8BAGE,GADT,AAAC,EAAmB,EAAU,EAAI,GACzB,AA5Bb,EA4Ba,eAyCN,CACX",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/platform.js
CHANGED
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
function
|
|
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
|
-
}
|
|
1
|
+
function o(n){return typeof window!="undefined"&&window.navigator!=null?n.test(window.navigator.userAgent):!1}function e(n){return typeof window!="undefined"&&window.navigator!=null?n.test(window.navigator.platform):!1}export function isMac(){return e(/^Mac/)}export function isIPhone(){return e(/^iPhone/)}export function isIPad(){return e(/^iPad/)||isMac()&&navigator.maxTouchPoints>1}export function isIOS(){return isIPhone()||isIPad()}export function isAppleDevice(){return isMac()||isIOS()}export function isWebKit(){return o(/AppleWebKit/)&&!isChrome()}export function isChrome(){return o(/Chrome/)}export function isAndroid(){return o(/Android/)}
|
|
31
2
|
//# sourceMappingURL=platform.js.map
|
package/src/platform.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["platform.ts"],
|
|
4
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,
|
|
5
|
+
"mappings": "AAYA,WAAuB,EAAqB,CACxC,MAAO,OAAO,SAAW,aAAe,OAAO,WAAa,KACtD,EAAG,KAAK,OAAO,UAAU,SAAS,EAClC,EACV,CAEA,WAAsB,EAAqB,CACvC,MAAO,OAAO,SAAW,aAAe,OAAO,WAAa,KACtD,EAAG,KAAK,OAAO,UAAU,QAAQ,EACjC,EACV,CAGO,uBAA0B,CAC7B,MAAO,GAAa,MAAM,CAC9B,CAEO,0BAA6B,CAChC,MAAO,GAAa,SAAS,CACjC,CAEO,wBAA2B,CAC9B,MACI,GAAa,OAAO,GAEnB,MAAM,GAAK,UAAU,eAAiB,CAE/C,CAEO,uBAA0B,CAC7B,MAAO,UAAS,GAAK,OAAO,CAChC,CAGO,+BAAkC,CACrC,MAAO,OAAM,GAAK,MAAM,CAC5B,CAGO,0BAA6B,CAChC,MAAO,GAAc,aAAa,GAAK,CAAC,SAAS,CACrD,CAGO,0BAA6B,CAChC,MAAO,GAAc,QAAQ,CACjC,CAEO,2BAA8B,CACjC,MAAO,GAAc,SAAS,CAClC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/reparent-children.js
CHANGED
|
@@ -1,50 +1,2 @@
|
|
|
1
|
-
function
|
|
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
|
-
};
|
|
1
|
+
function T(o,i,l=[]){for(let e=0;e<i.length;++e){const n=i[e],r=o[e],t=r.parentElement||r.getRootNode();l[e]&&l[e](n),t&&t!==r&&t.replaceChild(n,r),delete o[e]}return i}export const reparentChildren=(o,i,{position:l,prepareCallback:e}={position:"beforeend"})=>{let{length:n}=o;if(n===0)return()=>o;let r=1,t=0;(l==="afterbegin"||l==="afterend")&&(r=-1,t=n-1);const a=new Array(n),c=new Array(n),p=document.createComment("placeholder for reparented element");do{const d=o[t];e&&(c[t]=e(d)),a[t]=p.cloneNode();const m=d.parentElement||d.getRootNode();m&&m!==d&&m.replaceChild(a[t],d),i.insertAdjacentElement(l,d),t+=r}while(--n>0);return function(){return T(a,o,c)}};
|
|
50
2
|
//# sourceMappingURL=reparent-children.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["reparent-children.ts"],
|
|
4
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,
|
|
5
|
+
"mappings": "AAWA,WACI,EACA,EACA,EAAwC,CAAC,EACtC,CACH,OAAS,GAAQ,EAAG,EAAQ,EAAY,OAAQ,EAAE,EAAO,CACrD,KAAM,GAAa,EAAY,GACzB,EAAkB,EAAiB,GACnC,EACF,EAAgB,eAAiB,EAAgB,YAAY,EACjE,AAAI,EAAiB,IACjB,EAAiB,GAAO,CAAU,EAElC,GAAiB,IAAkB,GACnC,EAAc,aAAa,EAAY,CAAe,EAE1D,MAAO,GAAiB,EAC5B,CACA,MAAO,EACX,CAEO,YAAM,kBAAmB,CAC5B,EACA,EACA,CACI,WACA,mBAIA,CAAE,SAAU,WAAY,IACd,CACd,GAAI,CAAE,UAAW,EACjB,GAAI,IAAW,EACX,MAAO,IAAM,EAGjB,GAAI,GAAO,EACP,EAAQ,EAEZ,AAAI,KAAa,cAAgB,IAAa,aAC1C,GAAO,GACP,EAAQ,EAAS,GAGrB,KAAM,GAAmB,GAAI,OAAe,CAAM,EAC5C,EAAmB,GAAI,OAAuB,CAAM,EACpD,EAA+B,SAAS,cAC1C,oCACJ,EAEA,EAAG,CACC,KAAM,GAAa,EAAY,GAC/B,AAAI,GACA,GAAiB,GAAS,EAAgB,CAAU,GAIxD,EAAiB,GAAS,EAAoB,UAAU,EAExD,KAAM,GACF,EAAW,eAAiB,EAAW,YAAY,EACvD,AAAI,GAAiB,IAAkB,GACnC,EAAc,aAAa,EAAiB,GAAQ,CAAU,EAElE,EAAY,sBAAsB,EAAU,CAAU,EAEtD,GAAS,CACb,OAAS,EAAE,EAAS,GAEpB,MAAO,WAAiB,CACpB,MAAO,GACH,EACA,EACA,CACJ,CACJ,CACJ",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/test/focusable.test.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
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`
|
|
1
|
+
import"@spectrum-web-components/shared/src/focusable.js";import{Focusable as o}from"@spectrum-web-components/shared/src/focusable.js";import{elementUpdated as c,expect as t,fixture as l,html as r}from"@open-wc/testing";describe("Focusable",()=>{it("enforces the presense of a `focusElement`",async()=>{customElements.define("focusable-test",class extends o{});try{const e=await l(r`
|
|
10
2
|
<focusable-test></focusable-test>
|
|
11
|
-
`);
|
|
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
|
-
});
|
|
21
|
-
});
|
|
3
|
+
`);await c(e);const s=e.focusElement;t(s).to.exist}catch(e){t(()=>{throw e}).to.throw("Must implement focusElement getter!")}})});
|
|
22
4
|
//# sourceMappingURL=focusable.test.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["focusable.test.ts"],
|
|
4
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
|
|
5
|
+
"mappings": "AAYA,yDACA,6EACA,qFAEA,SAAS,YAAa,IAAM,CACxB,GAAG,4CAA6C,SAAY,CACxD,eAAe,OAAO,iBAAkB,aAAc,EAAU,CAAC,CAAC,EAClE,GAAI,CACA,KAAM,GAAK,KAAM,GACb;AAAA;AAAA,iBAGJ,EACA,KAAM,GAAe,CAAE,EACvB,KAAM,GAAU,EAAG,aACnB,EAAO,CAAO,EAAE,GAAG,KACvB,OAAS,EAAP,CACE,EAAO,IAAM,CACT,KAAM,EACV,CAAC,EAAE,GAAG,MAAM,qCAAqC,CACrD,CACJ,CAAC,CACL,CAAC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { LitElement } from "@spectrum-web-components/base";
|
|
3
|
-
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
4
|
-
class ObserverTest extends ObserveSlotPresence(LitElement, '[slot="test-slot"]') {
|
|
5
|
-
render() {
|
|
6
|
-
return html`
|
|
1
|
+
import{ObserveSlotPresence as n}from"@spectrum-web-components/shared/src/observe-slot-presence.js";import{LitElement as o}from"@spectrum-web-components/base";import{elementUpdated as t,expect as s,fixture as l,html as r}from"@open-wc/testing";class a extends n(o,'[slot="test-slot"]'){render(){return r`
|
|
7
2
|
Test Element
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
customElements.define("observe-presence-test", ObserverTest);
|
|
12
|
-
describe("ObserveSlotPresence", () => {
|
|
13
|
-
it("does no management when slot unavailable", async () => {
|
|
14
|
-
const el = await fixture(html`
|
|
3
|
+
`}}customElements.define("observe-presence-test",a),describe("ObserveSlotPresence",()=>{it("does no management when slot unavailable",async()=>{const e=await l(r`
|
|
15
4
|
<observe-presence-test></observe-presence-test>
|
|
16
|
-
`);
|
|
17
|
-
await elementUpdated(el);
|
|
18
|
-
expect(el.slotContentIsPresent).to.be.false;
|
|
19
|
-
el.innerHTML = '<div slot="test-slot"></div>';
|
|
20
|
-
await elementUpdated(el);
|
|
21
|
-
expect(el.slotContentIsPresent).to.be.true;
|
|
22
|
-
});
|
|
23
|
-
});
|
|
5
|
+
`);await t(e),s(e.slotContentIsPresent).to.be.false,e.innerHTML='<div slot="test-slot"></div>',await t(e),s(e.slotContentIsPresent).to.be.true})});
|
|
24
6
|
//# sourceMappingURL=observe-slot-presence.test.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.test.ts"],
|
|
4
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\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 { ObserveSlotPresence } from '@spectrum-web-components/shared/src/observe-slot-presence.js';\nimport { LitElement, TemplateResult } from '@spectrum-web-components/base';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\nclass ObserverTest extends ObserveSlotPresence(\n LitElement,\n '[slot=\"test-slot\"]'\n) {\n protected override render(): TemplateResult {\n return html`\n Test Element\n `;\n }\n}\n\ncustomElements.define('observe-presence-test', ObserverTest);\n\ndescribe('ObserveSlotPresence', () => {\n it('does no management when slot unavailable', async () => {\n const el = await fixture<ObserverTest>(\n html`\n <observe-presence-test></observe-presence-test>\n `\n );\n await elementUpdated(el);\n\n expect(el.slotContentIsPresent).to.be.false;\n\n el.innerHTML = '<div slot=\"test-slot\"></div>';\n await elementUpdated(el);\n\n expect(el.slotContentIsPresent).to.be.true;\n });\n});\n"],
|
|
5
|
-
"mappings": "AAWA
|
|
5
|
+
"mappings": "AAWA,mGACA,2DACA,qFAEA,MAAM,SAAqB,GACvB,EACA,oBACJ,CAAE,CACqB,QAAyB,CACxC,MAAO;AAAA;AAAA,SAGX,CACJ,CAEA,eAAe,OAAO,wBAAyB,CAAY,EAE3D,SAAS,sBAAuB,IAAM,CAClC,GAAG,2CAA4C,SAAY,CACvD,KAAM,GAAK,KAAM,GACb;AAAA;AAAA,aAGJ,EACA,KAAM,GAAe,CAAE,EAEvB,EAAO,EAAG,oBAAoB,EAAE,GAAG,GAAG,MAEtC,EAAG,UAAY,+BACf,KAAM,GAAe,CAAE,EAEvB,EAAO,EAAG,oBAAoB,EAAE,GAAG,GAAG,IAC1C,CAAC,CACL,CAAC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { LitElement } from "@spectrum-web-components/base";
|
|
3
|
-
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
4
|
-
class ObserverTest extends ObserveSlotText(LitElement) {
|
|
5
|
-
render() {
|
|
6
|
-
return html`
|
|
1
|
+
import{ObserveSlotText as r}from"@spectrum-web-components/shared/src/observe-slot-text.js";import{LitElement as l}from"@spectrum-web-components/base";import{elementUpdated as t,expect as s,fixture as a,html as o}from"@open-wc/testing";class n extends r(l){render(){return o`
|
|
7
2
|
<slot @slotchange=${this.manageTextObservedSlot}></slot>
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
customElements.define("observe-slot-test", ObserverTest);
|
|
12
|
-
describe("ObserveSlotText", () => {
|
|
13
|
-
it("does no management when slot unavailable", async () => {
|
|
14
|
-
const el = await fixture(html`
|
|
3
|
+
`}}customElements.define("observe-slot-test",n),describe("ObserveSlotText",()=>{it("does no management when slot unavailable",async()=>{const e=await a(o`
|
|
15
4
|
<observe-slot-test></observe-slot-test>
|
|
16
|
-
`);
|
|
17
|
-
await elementUpdated(el);
|
|
18
|
-
expect(el.slotHasContent).to.be.false;
|
|
19
|
-
el.textContent = `hi, i'm some text`;
|
|
20
|
-
await elementUpdated(el);
|
|
21
|
-
expect(el.slotHasContent).to.be.true;
|
|
22
|
-
});
|
|
23
|
-
});
|
|
5
|
+
`);await t(e),s(e.slotHasContent).to.be.false,e.textContent="hi, i'm some text",await t(e),s(e.slotHasContent).to.be.true})});
|
|
24
6
|
//# sourceMappingURL=observe-slot-text.test.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-text.test.ts"],
|
|
4
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 { ObserveSlotText } from '@spectrum-web-components/shared/src/observe-slot-text.js';\nimport { LitElement, TemplateResult } from '@spectrum-web-components/base';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\nclass ObserverTest extends ObserveSlotText(LitElement) {\n protected override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.manageTextObservedSlot}></slot>\n `;\n }\n}\n\ncustomElements.define('observe-slot-test', ObserverTest);\n\ndescribe('ObserveSlotText', () => {\n it('does no management when slot unavailable', async () => {\n const el = await fixture<ObserverTest>(\n html`\n <observe-slot-test></observe-slot-test>\n `\n );\n await elementUpdated(el);\n\n expect(el.slotHasContent).to.be.false;\n\n el.textContent = `hi, i'm some text`;\n\n await elementUpdated(el);\n\n expect(el.slotHasContent).to.be.true;\n });\n});\n"],
|
|
5
|
-
"mappings": "AAYA
|
|
5
|
+
"mappings": "AAYA,2FACA,2DACA,qFAEA,MAAM,SAAqB,GAAgB,CAAU,CAAE,CAChC,QAAyB,CACxC,MAAO;AAAA,gCACiB,KAAK;AAAA,SAEjC,CACJ,CAEA,eAAe,OAAO,oBAAqB,CAAY,EAEvD,SAAS,kBAAmB,IAAM,CAC9B,GAAG,2CAA4C,SAAY,CACvD,KAAM,GAAK,KAAM,GACb;AAAA;AAAA,aAGJ,EACA,KAAM,GAAe,CAAE,EAEvB,EAAO,EAAG,cAAc,EAAE,GAAG,GAAG,MAEhC,EAAG,YAAc,oBAEjB,KAAM,GAAe,CAAE,EAEvB,EAAO,EAAG,cAAc,EAAE,GAAG,GAAG,IACpC,CAAC,CACL,CAAC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,48 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
|
|
3
|
-
describe("Reparent Children", () => {
|
|
4
|
-
it("reparents and returns a single child", async () => {
|
|
5
|
-
const context = await fixture(html`
|
|
1
|
+
import{expect as e,fixture as v,html as h}from"@open-wc/testing";import{reparentChildren as u}from"@spectrum-web-components/shared/src/reparent-children.js";describe("Reparent Children",()=>{it("reparents and returns a single child",async()=>{const i=await v(h`
|
|
6
2
|
<div>
|
|
7
3
|
<div class="source">
|
|
8
4
|
<div class="child"></div>
|
|
9
5
|
</div>
|
|
10
6
|
<div class="destination"></div>
|
|
11
7
|
</div>
|
|
12
|
-
`);
|
|
13
|
-
const source = context.querySelector(".source");
|
|
14
|
-
const child = context.querySelector(".child");
|
|
15
|
-
const destination = context.querySelector(".destination");
|
|
16
|
-
expect(source.children.length).to.equal(1);
|
|
17
|
-
expect(destination.children.length).to.equal(0);
|
|
18
|
-
const restore = reparentChildren([child], destination);
|
|
19
|
-
expect(source.children.length).to.equal(0);
|
|
20
|
-
expect(destination.children.length).to.equal(1);
|
|
21
|
-
restore();
|
|
22
|
-
expect(source.children.length).to.equal(1);
|
|
23
|
-
expect(destination.children.length).to.equal(0);
|
|
24
|
-
});
|
|
25
|
-
it("early exits no children", async () => {
|
|
26
|
-
const context = await fixture(html`
|
|
8
|
+
`),t=i.querySelector(".source"),s=i.querySelector(".child"),l=i.querySelector(".destination");e(t.children.length).to.equal(1),e(l.children.length).to.equal(0);const n=u([s],l);e(t.children.length).to.equal(0),e(l.children.length).to.equal(1),n(),e(t.children.length).to.equal(1),e(l.children.length).to.equal(0)}),it("early exits no children",async()=>{const i=await v(h`
|
|
27
9
|
<div>
|
|
28
10
|
<div class="source"></div>
|
|
29
11
|
<div class="destination"></div>
|
|
30
12
|
</div>
|
|
31
|
-
`);
|
|
32
|
-
const source = context.querySelector(".source");
|
|
33
|
-
const children = [...source.children];
|
|
34
|
-
const destination = context.querySelector(".destination");
|
|
35
|
-
expect(source.children.length).to.equal(0);
|
|
36
|
-
expect(destination.children.length).to.equal(0);
|
|
37
|
-
const restore = reparentChildren(children, destination);
|
|
38
|
-
expect(source.children.length).to.equal(0);
|
|
39
|
-
expect(destination.children.length).to.equal(0);
|
|
40
|
-
restore();
|
|
41
|
-
expect(source.children.length).to.equal(0);
|
|
42
|
-
expect(destination.children.length).to.equal(0);
|
|
43
|
-
});
|
|
44
|
-
it("reparents and returns multiple child", async () => {
|
|
45
|
-
const context = await fixture(html`
|
|
13
|
+
`),t=i.querySelector(".source"),s=[...t.children],l=i.querySelector(".destination");e(t.children.length).to.equal(0),e(l.children.length).to.equal(0);const n=u(s,l);e(t.children.length).to.equal(0),e(l.children.length).to.equal(0),n(),e(t.children.length).to.equal(0),e(l.children.length).to.equal(0)}),it("reparents and returns multiple child",async()=>{const i=await v(h`
|
|
46
14
|
<div>
|
|
47
15
|
<div class="source">
|
|
48
16
|
<div class="child"></div>
|
|
@@ -53,48 +21,14 @@ describe("Reparent Children", () => {
|
|
|
53
21
|
</div>
|
|
54
22
|
<div class="destination"></div>
|
|
55
23
|
</div>
|
|
56
|
-
`);
|
|
57
|
-
const source = context.querySelector(".source");
|
|
58
|
-
const { children } = source;
|
|
59
|
-
const destination = context.querySelector(".destination");
|
|
60
|
-
expect(source.children.length).to.equal(5);
|
|
61
|
-
expect(destination.children.length).to.equal(0);
|
|
62
|
-
const restore = reparentChildren([...children], destination);
|
|
63
|
-
expect(source.children.length).to.equal(0);
|
|
64
|
-
expect(destination.children.length).to.equal(5);
|
|
65
|
-
restore();
|
|
66
|
-
expect(source.children.length).to.equal(5);
|
|
67
|
-
expect(destination.children.length).to.equal(0);
|
|
68
|
-
});
|
|
69
|
-
it("augments the child via a callback", async () => {
|
|
70
|
-
const context = await fixture(html`
|
|
24
|
+
`),t=i.querySelector(".source"),{children:s}=t,l=i.querySelector(".destination");e(t.children.length).to.equal(5),e(l.children.length).to.equal(0);const n=u([...s],l);e(t.children.length).to.equal(0),e(l.children.length).to.equal(5),n(),e(t.children.length).to.equal(5),e(l.children.length).to.equal(0)}),it("augments the child via a callback",async()=>{const i=await v(h`
|
|
71
25
|
<div>
|
|
72
26
|
<div class="source">
|
|
73
27
|
<div class="child" slot="slot"></div>
|
|
74
28
|
</div>
|
|
75
29
|
<div class="destination"></div>
|
|
76
30
|
</div>
|
|
77
|
-
`);
|
|
78
|
-
const child = context.querySelector(".child");
|
|
79
|
-
const destination = context.querySelector(".destination");
|
|
80
|
-
expect(child.getAttribute("slot")).to.equal("slot");
|
|
81
|
-
const restore = reparentChildren([child], destination, {
|
|
82
|
-
position: "beforeend",
|
|
83
|
-
prepareCallback: (el) => {
|
|
84
|
-
const slotName = el.slot;
|
|
85
|
-
el.removeAttribute("slot");
|
|
86
|
-
return (el2) => {
|
|
87
|
-
el2.slot = slotName;
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
expect(child.hasAttribute("slot")).to.be.false;
|
|
92
|
-
restore();
|
|
93
|
-
expect(child.getAttribute("slot")).to.equal("slot");
|
|
94
|
-
});
|
|
95
|
-
it("beforeend - reparents and returns multiple children", async () => {
|
|
96
|
-
var _a, _b, _c, _d;
|
|
97
|
-
const context = await fixture(html`
|
|
31
|
+
`),t=i.querySelector(".child"),s=i.querySelector(".destination");e(t.getAttribute("slot")).to.equal("slot");const l=u([t],s,{position:"beforeend",prepareCallback:n=>{const o=n.slot;return n.removeAttribute("slot"),d=>{d.slot=o}}});e(t.hasAttribute("slot")).to.be.false,l(),e(t.getAttribute("slot")).to.equal("slot")}),it("beforeend - reparents and returns multiple children",async()=>{var d,c,a,r;const i=await v(h`
|
|
98
32
|
<div>
|
|
99
33
|
<div class="source">
|
|
100
34
|
<div class="child">1</div>
|
|
@@ -107,30 +41,7 @@ describe("Reparent Children", () => {
|
|
|
107
41
|
<div class="marker"></div>
|
|
108
42
|
</div>
|
|
109
43
|
</div>
|
|
110
|
-
`);
|
|
111
|
-
const source = context.querySelector(".source");
|
|
112
|
-
const { children } = source;
|
|
113
|
-
const destination = context.querySelector(".destination");
|
|
114
|
-
expect(source.children.length).to.equal(5);
|
|
115
|
-
expect(destination.children.length).to.equal(1);
|
|
116
|
-
const restore = reparentChildren([...children], destination, {
|
|
117
|
-
position: "beforeend"
|
|
118
|
-
});
|
|
119
|
-
expect(source.children.length).to.equal(0);
|
|
120
|
-
expect(destination.children.length).to.equal(5 + 1);
|
|
121
|
-
const marker = context.querySelector(".marker");
|
|
122
|
-
expect(marker.previousElementSibling).to.be.null;
|
|
123
|
-
expect((_a = marker.nextElementSibling) == null ? void 0 : _a.textContent).to.equal("1");
|
|
124
|
-
expect((_b = destination.lastElementChild) == null ? void 0 : _b.textContent).to.equal("5");
|
|
125
|
-
restore();
|
|
126
|
-
expect(source.children.length).to.equal(5);
|
|
127
|
-
expect(destination.children.length).to.equal(1);
|
|
128
|
-
expect((_c = source.firstElementChild) == null ? void 0 : _c.textContent).to.equal("1");
|
|
129
|
-
expect((_d = source.lastElementChild) == null ? void 0 : _d.textContent).to.equal("5");
|
|
130
|
-
});
|
|
131
|
-
it("afterbegin - reparents and returns multiple children", async () => {
|
|
132
|
-
var _a, _b, _c, _d;
|
|
133
|
-
const context = await fixture(html`
|
|
44
|
+
`),t=i.querySelector(".source"),{children:s}=t,l=i.querySelector(".destination");e(t.children.length).to.equal(5),e(l.children.length).to.equal(1);const n=u([...s],l,{position:"beforeend"});e(t.children.length).to.equal(0),e(l.children.length).to.equal(5+1);const o=i.querySelector(".marker");e(o.previousElementSibling).to.be.null,e((d=o.nextElementSibling)==null?void 0:d.textContent).to.equal("1"),e((c=l.lastElementChild)==null?void 0:c.textContent).to.equal("5"),n(),e(t.children.length).to.equal(5),e(l.children.length).to.equal(1),e((a=t.firstElementChild)==null?void 0:a.textContent).to.equal("1"),e((r=t.lastElementChild)==null?void 0:r.textContent).to.equal("5")}),it("afterbegin - reparents and returns multiple children",async()=>{var d,c,a,r;const i=await v(h`
|
|
134
45
|
<div>
|
|
135
46
|
<div class="source">
|
|
136
47
|
<div class="child">1</div>
|
|
@@ -143,30 +54,7 @@ describe("Reparent Children", () => {
|
|
|
143
54
|
<div class="marker"></div>
|
|
144
55
|
</div>
|
|
145
56
|
</div>
|
|
146
|
-
`);
|
|
147
|
-
const source = context.querySelector(".source");
|
|
148
|
-
const { children } = source;
|
|
149
|
-
const destination = context.querySelector(".destination");
|
|
150
|
-
expect(source.children.length).to.equal(5);
|
|
151
|
-
expect(destination.children.length).to.equal(1);
|
|
152
|
-
const restore = reparentChildren([...children], destination, {
|
|
153
|
-
position: "afterbegin"
|
|
154
|
-
});
|
|
155
|
-
expect(source.children.length).to.equal(0);
|
|
156
|
-
expect(destination.children.length).to.equal(5 + 1);
|
|
157
|
-
const marker = context.querySelector(".marker");
|
|
158
|
-
expect(marker.nextElementSibling).to.be.null;
|
|
159
|
-
expect((_a = marker.previousElementSibling) == null ? void 0 : _a.textContent).to.equal("5");
|
|
160
|
-
expect((_b = destination.firstElementChild) == null ? void 0 : _b.textContent).to.equal("1");
|
|
161
|
-
restore();
|
|
162
|
-
expect(source.children.length).to.equal(5);
|
|
163
|
-
expect(destination.children.length).to.equal(1);
|
|
164
|
-
expect((_c = source.firstElementChild) == null ? void 0 : _c.textContent).to.equal("1");
|
|
165
|
-
expect((_d = source.lastElementChild) == null ? void 0 : _d.textContent).to.equal("5");
|
|
166
|
-
});
|
|
167
|
-
it("beforebegin - reparents and returns multiple children", async () => {
|
|
168
|
-
var _a, _b, _c, _d;
|
|
169
|
-
const context = await fixture(html`
|
|
57
|
+
`),t=i.querySelector(".source"),{children:s}=t,l=i.querySelector(".destination");e(t.children.length).to.equal(5),e(l.children.length).to.equal(1);const n=u([...s],l,{position:"afterbegin"});e(t.children.length).to.equal(0),e(l.children.length).to.equal(5+1);const o=i.querySelector(".marker");e(o.nextElementSibling).to.be.null,e((d=o.previousElementSibling)==null?void 0:d.textContent).to.equal("5"),e((c=l.firstElementChild)==null?void 0:c.textContent).to.equal("1"),n(),e(t.children.length).to.equal(5),e(l.children.length).to.equal(1),e((a=t.firstElementChild)==null?void 0:a.textContent).to.equal("1"),e((r=t.lastElementChild)==null?void 0:r.textContent).to.equal("5")}),it("beforebegin - reparents and returns multiple children",async()=>{var d,c,a,r;const i=await v(h`
|
|
170
58
|
<div>
|
|
171
59
|
<div class="source">
|
|
172
60
|
<div class="child">1</div>
|
|
@@ -178,29 +66,7 @@ describe("Reparent Children", () => {
|
|
|
178
66
|
<div class="marker"></div>
|
|
179
67
|
<div class="destination"></div>
|
|
180
68
|
</div>
|
|
181
|
-
`);
|
|
182
|
-
const source = context.querySelector(".source");
|
|
183
|
-
const { children } = source;
|
|
184
|
-
const destination = context.querySelector(".destination");
|
|
185
|
-
expect(source.children.length).to.equal(5);
|
|
186
|
-
const restore = reparentChildren([...children], destination, {
|
|
187
|
-
position: "beforebegin"
|
|
188
|
-
});
|
|
189
|
-
expect(source.children.length).to.equal(0);
|
|
190
|
-
expect(destination.children.length).to.equal(0);
|
|
191
|
-
const marker = context.querySelector(".marker");
|
|
192
|
-
expect(marker.previousElementSibling).to.not.be.null;
|
|
193
|
-
expect((_a = marker.nextElementSibling) == null ? void 0 : _a.textContent).to.equal("1");
|
|
194
|
-
expect((_b = destination.previousElementSibling) == null ? void 0 : _b.textContent).to.equal("5");
|
|
195
|
-
restore();
|
|
196
|
-
expect(source.children.length).to.equal(5);
|
|
197
|
-
expect(marker.nextElementSibling).to.equal(destination);
|
|
198
|
-
expect((_c = source.firstElementChild) == null ? void 0 : _c.textContent).to.equal("1");
|
|
199
|
-
expect((_d = source.lastElementChild) == null ? void 0 : _d.textContent).to.equal("5");
|
|
200
|
-
});
|
|
201
|
-
it("afterend - reparents and returns multiple children", async () => {
|
|
202
|
-
var _a, _b, _c, _d;
|
|
203
|
-
const context = await fixture(html`
|
|
69
|
+
`),t=i.querySelector(".source"),{children:s}=t,l=i.querySelector(".destination");e(t.children.length).to.equal(5);const n=u([...s],l,{position:"beforebegin"});e(t.children.length).to.equal(0),e(l.children.length).to.equal(0);const o=i.querySelector(".marker");e(o.previousElementSibling).to.not.be.null,e((d=o.nextElementSibling)==null?void 0:d.textContent).to.equal("1"),e((c=l.previousElementSibling)==null?void 0:c.textContent).to.equal("5"),n(),e(t.children.length).to.equal(5),e(o.nextElementSibling).to.equal(l),e((a=t.firstElementChild)==null?void 0:a.textContent).to.equal("1"),e((r=t.lastElementChild)==null?void 0:r.textContent).to.equal("5")}),it("afterend - reparents and returns multiple children",async()=>{var d,c,a,r;const i=await v(h`
|
|
204
70
|
<div>
|
|
205
71
|
<div class="source">
|
|
206
72
|
<div class="child">1</div>
|
|
@@ -212,26 +78,5 @@ describe("Reparent Children", () => {
|
|
|
212
78
|
<div class="destination"></div>
|
|
213
79
|
<div class="marker"></div>
|
|
214
80
|
</div>
|
|
215
|
-
`);
|
|
216
|
-
const source = context.querySelector(".source");
|
|
217
|
-
const { children } = source;
|
|
218
|
-
const destination = context.querySelector(".destination");
|
|
219
|
-
expect(source.children.length).to.equal(5);
|
|
220
|
-
const marker = context.querySelector(".marker");
|
|
221
|
-
expect(marker.previousElementSibling).to.equal(destination);
|
|
222
|
-
expect(marker.nextElementSibling).to.be.null;
|
|
223
|
-
const restore = reparentChildren([...children], destination, {
|
|
224
|
-
position: "afterend"
|
|
225
|
-
});
|
|
226
|
-
expect(source.children.length).to.equal(0);
|
|
227
|
-
expect(destination.children.length).to.equal(0);
|
|
228
|
-
expect((_a = destination.nextElementSibling) == null ? void 0 : _a.textContent).to.equal("1");
|
|
229
|
-
expect((_b = marker.previousElementSibling) == null ? void 0 : _b.textContent).to.equal("5");
|
|
230
|
-
restore();
|
|
231
|
-
expect(source.children.length).to.equal(5);
|
|
232
|
-
expect(marker.previousElementSibling).to.equal(destination);
|
|
233
|
-
expect((_c = source.firstElementChild) == null ? void 0 : _c.textContent).to.equal("1");
|
|
234
|
-
expect((_d = source.lastElementChild) == null ? void 0 : _d.textContent).to.equal("5");
|
|
235
|
-
});
|
|
236
|
-
});
|
|
81
|
+
`),t=i.querySelector(".source"),{children:s}=t,l=i.querySelector(".destination");e(t.children.length).to.equal(5);const n=i.querySelector(".marker");e(n.previousElementSibling).to.equal(l),e(n.nextElementSibling).to.be.null;const o=u([...s],l,{position:"afterend"});e(t.children.length).to.equal(0),e(l.children.length).to.equal(0),e((d=l.nextElementSibling)==null?void 0:d.textContent).to.equal("1"),e((c=n.previousElementSibling)==null?void 0:c.textContent).to.equal("5"),o(),e(t.children.length).to.equal(5),e(n.previousElementSibling).to.equal(l),e((a=t.firstElementChild)==null?void 0:a.textContent).to.equal("1"),e((r=t.lastElementChild)==null?void 0:r.textContent).to.equal("5")})});
|
|
237
82
|
//# sourceMappingURL=reparent-children.test.js.map
|