@spectrum-web-components/shared 0.13.6 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/focus-visible.d.ts +0 -2
- package/src/focus-visible.js +5 -3
- package/src/focus-visible.js.map +1 -1
- package/src/reparent-children.d.ts +4 -1
- package/src/reparent-children.js +21 -13
- package/src/reparent-children.js.map +1 -1
- package/test/focusable.test.js +34 -0
- package/test/focusable.test.js.map +1 -0
- package/test/observe-slot-presence.test.js +34 -0
- package/test/observe-slot-presence.test.js.map +1 -0
- package/test/observe-slot-text.test.js +35 -0
- package/test/observe-slot-text.test.js.map +1 -0
- package/test/reparent-children.test.js +248 -0
- package/test/reparent-children.test.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"lit-html"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@spectrum-web-components/base": "^0.5.
|
|
45
|
+
"@spectrum-web-components/base": "^0.5.6",
|
|
46
46
|
"focus-visible": "^5.1.0",
|
|
47
47
|
"tslib": "^2.0.0"
|
|
48
48
|
},
|
|
49
49
|
"types": "./src/index.d.ts",
|
|
50
50
|
"customElements": "custom-elements.json",
|
|
51
51
|
"sideEffects": false,
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "32e049a0da090ffc1a54cfe3234be4d5efc73339"
|
|
53
53
|
}
|
package/src/focus-visible.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import 'focus-visible';
|
|
2
1
|
declare global {
|
|
3
2
|
interface Window {
|
|
4
3
|
applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;
|
|
@@ -14,7 +13,6 @@ interface OptionalLifecycleCallbacks {
|
|
|
14
13
|
manageAutoFocus?(): void;
|
|
15
14
|
}
|
|
16
15
|
declare type MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;
|
|
17
|
-
import 'focus-visible';
|
|
18
16
|
/**
|
|
19
17
|
* This mixin function is designed to be applied to a class that inherits
|
|
20
18
|
* from HTMLElement. It makes it easy for a custom element to coordinate with
|
package/src/focus-visible.js
CHANGED
|
@@ -9,14 +9,15 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
|
|
|
9
9
|
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import 'focus-visible';
|
|
13
|
-
import 'focus-visible';
|
|
14
12
|
let hasFocusVisible = true;
|
|
15
13
|
try {
|
|
16
14
|
document.body.querySelector(':focus-visible');
|
|
17
15
|
}
|
|
18
16
|
catch (error) {
|
|
19
17
|
hasFocusVisible = false;
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
import('focus-visible');
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* This mixin function is designed to be applied to a class that inherits
|
|
@@ -86,7 +87,8 @@ export const FocusVisiblePolyfillMixin = (SuperClass) => {
|
|
|
86
87
|
if (!hasFocusVisible) {
|
|
87
88
|
requestAnimationFrame(() => {
|
|
88
89
|
if (this[$endPolyfillCoordination] == null) {
|
|
89
|
-
this[$endPolyfillCoordination] =
|
|
90
|
+
this[$endPolyfillCoordination] =
|
|
91
|
+
coordinateWithPolyfill(this);
|
|
90
92
|
}
|
|
91
93
|
});
|
|
92
94
|
}
|
package/src/focus-visible.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-visible.js","sourceRoot":"","sources":["focus-visible.ts"],"names":[],"mappings":"AAAA;;;;;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QACL,CAAC;KACJ;SA/BY,wBAAwB;IAiCrC,OAAO,uBAAuB,CAAC;AACnC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\ndeclare global {\n interface Window {\n applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;\n }\n}\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ninterface OptionalLifecycleCallbacks {\n connectedCallback?(): void;\n disconnectedCallback?(): void;\n manageAutoFocus?(): void;\n}\n\ntype MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;\n\ntype EndPolyfillCoordinationCallback = () => void;\n\nlet hasFocusVisible = true;\n\ntry {\n document.body.querySelector(':focus-visible');\n} catch (error) {\n hasFocusVisible = false;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n import('focus-visible');\n}\n\n/**\n * This mixin function is designed to be applied to a class that inherits\n * from HTMLElement. It makes it easy for a custom element to coordinate with\n * the :focus-visible polyfill.\n *\n * NOTE(cdata): The code here was adapted from an example proposed with the\n * introduction of ShadowDOM support in the :focus-visible polyfill.\n *\n * @see https://github.com/WICG/focus-visible/pull/196\n * @param {Function} SuperClass The base class implementation to decorate with\n * implementation that coordinates with the :focus-visible polyfill\n */\nexport const FocusVisiblePolyfillMixin = <\n T extends Constructor<MixableBaseClass>\n>(\n SuperClass: T\n): T => {\n const coordinateWithPolyfill = (\n instance: MixableBaseClass\n ): EndPolyfillCoordinationCallback => {\n // If there is no shadow root, there is no need to coordinate with\n // the polyfill. If we already coordinated with the polyfill, we can\n // skip subsequent invokcations:\n if (\n instance.shadowRoot == null ||\n instance.hasAttribute('data-js-focus-visible')\n ) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n // The polyfill might already be loaded. If so, we can apply it to\n // the shadow root immediately:\n if (self.applyFocusVisiblePolyfill) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n } else {\n const coordinationHandler = (): void => {\n if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n }\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n };\n // Otherwise, wait for the polyfill to be loaded lazily. It might\n // never be loaded, but if it is then we can apply it to the\n // shadow root at the appropriate time by waiting for the ready\n // event:\n self.addEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler,\n { once: true }\n );\n\n return () => {\n self.removeEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler\n );\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n };\n\n const $endPolyfillCoordination = Symbol('endPolyfillCoordination');\n\n // IE11 doesn't natively support custom elements or JavaScript class\n // syntax The mixin implementation assumes that the user will take the\n // appropriate steps to support both:\n class FocusVisibleCoordinator extends SuperClass {\n private [$endPolyfillCoordination]: EndPolyfillCoordinationCallback | null =\n null;\n\n // Attempt to coordinate with the polyfill when connected to the\n // document:\n connectedCallback(): void {\n super.connectedCallback && super.connectedCallback();\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] == null) {\n this[$endPolyfillCoordination] =\n coordinateWithPolyfill(this);\n }\n });\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback && super.disconnectedCallback();\n // It's important to remove the polyfill event listener when we\n // disconnect, otherwise we will leak the whole element via window:\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] != null) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this[$endPolyfillCoordination]!();\n this[$endPolyfillCoordination] = null;\n }\n });\n }\n }\n }\n\n return FocusVisibleCoordinator;\n};\n"]}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export declare const reparentChildren: <T extends Element>(srcElements: T[],
|
|
1
|
+
export declare const reparentChildren: <T extends Element>(srcElements: T[], destination: Element, { position, prepareCallback, }?: {
|
|
2
|
+
position: InsertPosition;
|
|
3
|
+
prepareCallback?: ((el: T) => void | ((el: T) => void)) | undefined;
|
|
4
|
+
}) => () => T[];
|
package/src/reparent-children.js
CHANGED
|
@@ -24,25 +24,33 @@ function restoreChildren(placeholderItems, srcElements, cleanupCallbacks = []) {
|
|
|
24
24
|
}
|
|
25
25
|
return srcElements;
|
|
26
26
|
}
|
|
27
|
-
export const reparentChildren = (srcElements,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
export const reparentChildren = (srcElements, destination, { position, prepareCallback, } = { position: 'beforeend' }) => {
|
|
28
|
+
let { length } = srcElements;
|
|
29
|
+
if (length === 0) {
|
|
30
|
+
return () => srcElements;
|
|
31
|
+
}
|
|
32
|
+
let step = 1;
|
|
33
|
+
let index = 0;
|
|
34
|
+
if (position === 'afterbegin' || position === 'afterend') {
|
|
35
|
+
step = -1;
|
|
36
|
+
index = length - 1;
|
|
37
|
+
}
|
|
38
|
+
const placeholderItems = new Array(length);
|
|
39
|
+
const cleanupCallbacks = new Array(length);
|
|
40
|
+
const placeholderTemplate = document.createComment('placeholder for reparented element');
|
|
41
|
+
do {
|
|
31
42
|
const srcElement = srcElements[index];
|
|
32
43
|
if (prepareCallback) {
|
|
33
|
-
cleanupCallbacks
|
|
34
|
-
(() => {
|
|
35
|
-
return;
|
|
36
|
-
}));
|
|
44
|
+
cleanupCallbacks[index] = prepareCallback(srcElement);
|
|
37
45
|
}
|
|
38
|
-
|
|
39
|
-
placeholderItems.push(placeholderItem);
|
|
46
|
+
placeholderItems[index] = placeholderTemplate.cloneNode();
|
|
40
47
|
const parentElement = srcElement.parentElement || srcElement.getRootNode();
|
|
41
48
|
if (parentElement && parentElement !== srcElement) {
|
|
42
|
-
parentElement.replaceChild(
|
|
49
|
+
parentElement.replaceChild(placeholderItems[index], srcElement);
|
|
43
50
|
}
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
destination.insertAdjacentElement(position, srcElement);
|
|
52
|
+
index += step;
|
|
53
|
+
} while (--length > 0);
|
|
46
54
|
return function () {
|
|
47
55
|
return restoreChildren(placeholderItems, srcElements, cleanupCallbacks);
|
|
48
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reparent-children.js","sourceRoot":"","sources":["reparent-children.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,SAAS,eAAe,CACpB,gBAA2B,EAC3B,WAAgB,EAChB,mBAAwC,EAAE;IAE1C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,WAAW,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE;QACrD,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QACtC,MAAM,eAAe,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAChD,MAAM,aAAa,GACf,eAAe,CAAC,aAAa,IAAI,eAAe,CAAC,WAAW,EAAE,CAAC;QACnE,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;YACzB,gBAAgB,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,CAAC;SACvC;QACD,IAAI,aAAa,IAAI,aAAa,KAAK,eAAe,EAAE;YACpD,aAAa,CAAC,YAAY,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;SAC3D;QACD,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;KAClC;IACD,OAAO,WAAW,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC5B,WA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,GAAG,CAAC,CAAC;KACtB;IAED,MAAM,gBAAgB,GAAG,IAAI,KAAK,CAAU,MAAM,CAAC,CAAC;IACpD,MAAM,gBAAgB,GAAG,IAAI,KAAK,CAAkB,MAAM,CAAC,CAAC;IAC5D,MAAM,mBAAmB,GAAY,QAAQ,CAAC,aAAa,CACvD,oCAAoC,CACvC,CAAC;IAEF,GAAG;QACC,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,eAAe,EAAE;YACjB,gBAAgB,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC,UAAU,CAE3C,CAAC;SACb;QACD,gBAAgB,CAAC,KAAK,CAAC,GAAG,mBAAmB,CAAC,SAAS,EAAa,CAAC;QAErE,MAAM,aAAa,GACf,UAAU,CAAC,aAAa,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QACzD,IAAI,aAAa,IAAI,aAAa,KAAK,UAAU,EAAE;YAC/C,aAAa,CAAC,YAAY,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC;SACnE;QACD,WAAW,CAAC,qBAAqB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAExD,KAAK,IAAI,IAAI,CAAC;KACjB,QAAQ,EAAE,MAAM,GAAG,CAAC,EAAE;IAEvB,OAAO;QACH,OAAO,eAAe,CAClB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,CACnB,CAAC;IACN,CAAC,CAAC;AACN,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\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"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
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 `
|
|
21
|
+
<focusable-test></focusable-test>
|
|
22
|
+
`);
|
|
23
|
+
await elementUpdated(el);
|
|
24
|
+
const focusEl = el.focusElement;
|
|
25
|
+
expect(focusEl).to.exist;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
expect(() => {
|
|
29
|
+
throw error;
|
|
30
|
+
}).to.throw('Must implement focusElement getter!');
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=focusable.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focusable.test.js","sourceRoot":"","sources":["focusable.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QACvD,cAAc,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAM,SAAQ,SAAS;SAAG,CAAC,CAAC;QACpE,IAAI;YACA,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;iBAEH,CACJ,CAAC;YACF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;YACzB,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC;YAChC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC;SAC5B;QAAC,OAAO,KAAK,EAAE;YACZ,MAAM,CAAC,GAAG,EAAE;gBACR,MAAM,KAAK,CAAC;YAChB,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;SACtD;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '../src/focusable.js';\nimport { Focusable } from '../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"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
7
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
8
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
9
|
+
governing permissions and limitations under the License.
|
|
10
|
+
*/
|
|
11
|
+
import { ObserveSlotPresence } from '../src/observe-slot-presence.js';
|
|
12
|
+
import { LitElement } from '@spectrum-web-components/base';
|
|
13
|
+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
|
14
|
+
class ObserverTest extends ObserveSlotPresence(LitElement, '[slot="test-slot"]') {
|
|
15
|
+
render() {
|
|
16
|
+
return html `
|
|
17
|
+
Test Element
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
customElements.define('observe-presence-test', ObserverTest);
|
|
22
|
+
describe('ObserveSlotPresence', () => {
|
|
23
|
+
it('does no management when slot unavailable', async () => {
|
|
24
|
+
const el = await fixture(html `
|
|
25
|
+
<observe-presence-test></observe-presence-test>
|
|
26
|
+
`);
|
|
27
|
+
await elementUpdated(el);
|
|
28
|
+
expect(el.slotContentIsPresent).to.be.false;
|
|
29
|
+
el.innerHTML = '<div slot="test-slot"></div>';
|
|
30
|
+
await elementUpdated(el);
|
|
31
|
+
expect(el.slotContentIsPresent).to.be.true;
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=observe-slot-presence.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-slot-presence.test.js","sourceRoot":"","sources":["observe-slot-presence.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AAEF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAkB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,YAAa,SAAQ,mBAAmB,CAC1C,UAAU,EACV,oBAAoB,CACvB;IACa,MAAM;QACZ,OAAO,IAAI,CAAA;;SAEV,CAAC;IACN,CAAC;CACJ;AAED,cAAc,CAAC,MAAM,CAAC,uBAAuB,EAAE,YAAY,CAAC,CAAC;AAE7D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;aAEH,CACJ,CAAC;QACF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAE5C,EAAE,CAAC,SAAS,GAAG,8BAA8B,CAAC;QAC9C,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\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 '../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 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"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
import { ObserveSlotText } from '../src/observe-slot-text.js';
|
|
13
|
+
import { LitElement } from '@spectrum-web-components/base';
|
|
14
|
+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
|
15
|
+
class ObserverTest extends ObserveSlotText(LitElement) {
|
|
16
|
+
render() {
|
|
17
|
+
return html `
|
|
18
|
+
<slot @slotchange=${this.manageTextObservedSlot}></slot>
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
customElements.define('observe-slot-test', ObserverTest);
|
|
23
|
+
describe('ObserveSlotText', () => {
|
|
24
|
+
it('does no management when slot unavailable', async () => {
|
|
25
|
+
const el = await fixture(html `
|
|
26
|
+
<observe-slot-test></observe-slot-test>
|
|
27
|
+
`);
|
|
28
|
+
await elementUpdated(el);
|
|
29
|
+
expect(el.slotHasContent).to.be.false;
|
|
30
|
+
el.textContent = `hi, i'm some text`;
|
|
31
|
+
await elementUpdated(el);
|
|
32
|
+
expect(el.slotHasContent).to.be.true;
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=observe-slot-text.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-slot-text.test.js","sourceRoot":"","sources":["observe-slot-text.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAkB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,YAAa,SAAQ,eAAe,CAAC,UAAU,CAAC;IACxC,MAAM;QACZ,OAAO,IAAI,CAAA;gCACa,IAAI,CAAC,sBAAsB;SAClD,CAAC;IACN,CAAC;CACJ;AAED,cAAc,CAAC,MAAM,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;aAEH,CACJ,CAAC;QACF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAEtC,EAAE,CAAC,WAAW,GAAG,mBAAmB,CAAC;QAErC,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACzC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { ObserveSlotText } from '../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 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"]}
|
|
@@ -0,0 +1,248 @@
|
|
|
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
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
|
13
|
+
import { reparentChildren } from '../src/reparent-children.js';
|
|
14
|
+
describe('Reparent Children', () => {
|
|
15
|
+
it('reparents and returns a single child', async () => {
|
|
16
|
+
const context = await fixture(html `
|
|
17
|
+
<div>
|
|
18
|
+
<div class="source">
|
|
19
|
+
<div class="child"></div>
|
|
20
|
+
</div>
|
|
21
|
+
<div class="destination"></div>
|
|
22
|
+
</div>
|
|
23
|
+
`);
|
|
24
|
+
const source = context.querySelector('.source');
|
|
25
|
+
const child = context.querySelector('.child');
|
|
26
|
+
const destination = context.querySelector('.destination');
|
|
27
|
+
expect(source.children.length).to.equal(1);
|
|
28
|
+
expect(destination.children.length).to.equal(0);
|
|
29
|
+
const restore = reparentChildren([child], destination);
|
|
30
|
+
expect(source.children.length).to.equal(0);
|
|
31
|
+
expect(destination.children.length).to.equal(1);
|
|
32
|
+
restore();
|
|
33
|
+
expect(source.children.length).to.equal(1);
|
|
34
|
+
expect(destination.children.length).to.equal(0);
|
|
35
|
+
});
|
|
36
|
+
it('early exits no children', async () => {
|
|
37
|
+
const context = await fixture(html `
|
|
38
|
+
<div>
|
|
39
|
+
<div class="source"></div>
|
|
40
|
+
<div class="destination"></div>
|
|
41
|
+
</div>
|
|
42
|
+
`);
|
|
43
|
+
const source = context.querySelector('.source');
|
|
44
|
+
const children = [...source.children];
|
|
45
|
+
const destination = context.querySelector('.destination');
|
|
46
|
+
expect(source.children.length).to.equal(0);
|
|
47
|
+
expect(destination.children.length).to.equal(0);
|
|
48
|
+
const restore = reparentChildren(children, destination);
|
|
49
|
+
expect(source.children.length).to.equal(0);
|
|
50
|
+
expect(destination.children.length).to.equal(0);
|
|
51
|
+
restore();
|
|
52
|
+
expect(source.children.length).to.equal(0);
|
|
53
|
+
expect(destination.children.length).to.equal(0);
|
|
54
|
+
});
|
|
55
|
+
it('reparents and returns multiple child', async () => {
|
|
56
|
+
const context = await fixture(html `
|
|
57
|
+
<div>
|
|
58
|
+
<div class="source">
|
|
59
|
+
<div class="child"></div>
|
|
60
|
+
<div class="child"></div>
|
|
61
|
+
<div class="child"></div>
|
|
62
|
+
<div class="child"></div>
|
|
63
|
+
<div class="child"></div>
|
|
64
|
+
</div>
|
|
65
|
+
<div class="destination"></div>
|
|
66
|
+
</div>
|
|
67
|
+
`);
|
|
68
|
+
const source = context.querySelector('.source');
|
|
69
|
+
const { children } = source;
|
|
70
|
+
const destination = context.querySelector('.destination');
|
|
71
|
+
expect(source.children.length).to.equal(5);
|
|
72
|
+
expect(destination.children.length).to.equal(0);
|
|
73
|
+
const restore = reparentChildren([...children], destination);
|
|
74
|
+
expect(source.children.length).to.equal(0);
|
|
75
|
+
expect(destination.children.length).to.equal(5);
|
|
76
|
+
restore();
|
|
77
|
+
expect(source.children.length).to.equal(5);
|
|
78
|
+
expect(destination.children.length).to.equal(0);
|
|
79
|
+
});
|
|
80
|
+
it('augments the child via a callback', async () => {
|
|
81
|
+
const context = await fixture(html `
|
|
82
|
+
<div>
|
|
83
|
+
<div class="source">
|
|
84
|
+
<div class="child" slot="slot"></div>
|
|
85
|
+
</div>
|
|
86
|
+
<div class="destination"></div>
|
|
87
|
+
</div>
|
|
88
|
+
`);
|
|
89
|
+
const child = context.querySelector('.child');
|
|
90
|
+
const destination = context.querySelector('.destination');
|
|
91
|
+
expect(child.getAttribute('slot')).to.equal('slot');
|
|
92
|
+
const restore = reparentChildren([child], destination, {
|
|
93
|
+
position: 'beforeend',
|
|
94
|
+
prepareCallback: (el) => {
|
|
95
|
+
const slotName = el.slot;
|
|
96
|
+
el.removeAttribute('slot');
|
|
97
|
+
return (el) => {
|
|
98
|
+
el.slot = slotName;
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
expect(child.hasAttribute('slot')).to.be.false;
|
|
103
|
+
restore();
|
|
104
|
+
expect(child.getAttribute('slot')).to.equal('slot');
|
|
105
|
+
});
|
|
106
|
+
it('beforeend - reparents and returns multiple children', async () => {
|
|
107
|
+
var _a, _b, _c, _d;
|
|
108
|
+
const context = await fixture(html `
|
|
109
|
+
<div>
|
|
110
|
+
<div class="source">
|
|
111
|
+
<div class="child">1</div>
|
|
112
|
+
<div class="child">2</div>
|
|
113
|
+
<div class="child">3</div>
|
|
114
|
+
<div class="child">4</div>
|
|
115
|
+
<div class="child">5</div>
|
|
116
|
+
</div>
|
|
117
|
+
<div class="destination">
|
|
118
|
+
<div class="marker"></div>
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
`);
|
|
122
|
+
const source = context.querySelector('.source');
|
|
123
|
+
const { children } = source;
|
|
124
|
+
const destination = context.querySelector('.destination');
|
|
125
|
+
expect(source.children.length).to.equal(5);
|
|
126
|
+
expect(destination.children.length).to.equal(1);
|
|
127
|
+
const restore = reparentChildren([...children], destination, {
|
|
128
|
+
position: 'beforeend',
|
|
129
|
+
});
|
|
130
|
+
expect(source.children.length).to.equal(0);
|
|
131
|
+
expect(destination.children.length).to.equal(5 + 1);
|
|
132
|
+
const marker = context.querySelector('.marker');
|
|
133
|
+
expect(marker.previousElementSibling).to.be.null;
|
|
134
|
+
expect((_a = marker.nextElementSibling) === null || _a === void 0 ? void 0 : _a.textContent).to.equal('1');
|
|
135
|
+
expect((_b = destination.lastElementChild) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('5');
|
|
136
|
+
restore();
|
|
137
|
+
expect(source.children.length).to.equal(5);
|
|
138
|
+
expect(destination.children.length).to.equal(1);
|
|
139
|
+
expect((_c = source.firstElementChild) === null || _c === void 0 ? void 0 : _c.textContent).to.equal('1');
|
|
140
|
+
expect((_d = source.lastElementChild) === null || _d === void 0 ? void 0 : _d.textContent).to.equal('5');
|
|
141
|
+
});
|
|
142
|
+
it('afterbegin - reparents and returns multiple children', async () => {
|
|
143
|
+
var _a, _b, _c, _d;
|
|
144
|
+
const context = await fixture(html `
|
|
145
|
+
<div>
|
|
146
|
+
<div class="source">
|
|
147
|
+
<div class="child">1</div>
|
|
148
|
+
<div class="child">2</div>
|
|
149
|
+
<div class="child">3</div>
|
|
150
|
+
<div class="child">4</div>
|
|
151
|
+
<div class="child">5</div>
|
|
152
|
+
</div>
|
|
153
|
+
<div class="destination">
|
|
154
|
+
<div class="marker"></div>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
`);
|
|
158
|
+
const source = context.querySelector('.source');
|
|
159
|
+
const { children } = source;
|
|
160
|
+
const destination = context.querySelector('.destination');
|
|
161
|
+
expect(source.children.length).to.equal(5);
|
|
162
|
+
expect(destination.children.length).to.equal(1);
|
|
163
|
+
const restore = reparentChildren([...children], destination, {
|
|
164
|
+
position: 'afterbegin',
|
|
165
|
+
});
|
|
166
|
+
expect(source.children.length).to.equal(0);
|
|
167
|
+
expect(destination.children.length).to.equal(5 + 1);
|
|
168
|
+
const marker = context.querySelector('.marker');
|
|
169
|
+
expect(marker.nextElementSibling).to.be.null;
|
|
170
|
+
expect((_a = marker.previousElementSibling) === null || _a === void 0 ? void 0 : _a.textContent).to.equal('5');
|
|
171
|
+
expect((_b = destination.firstElementChild) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('1');
|
|
172
|
+
restore();
|
|
173
|
+
expect(source.children.length).to.equal(5);
|
|
174
|
+
expect(destination.children.length).to.equal(1);
|
|
175
|
+
expect((_c = source.firstElementChild) === null || _c === void 0 ? void 0 : _c.textContent).to.equal('1');
|
|
176
|
+
expect((_d = source.lastElementChild) === null || _d === void 0 ? void 0 : _d.textContent).to.equal('5');
|
|
177
|
+
});
|
|
178
|
+
it('beforebegin - reparents and returns multiple children', async () => {
|
|
179
|
+
var _a, _b, _c, _d;
|
|
180
|
+
const context = await fixture(html `
|
|
181
|
+
<div>
|
|
182
|
+
<div class="source">
|
|
183
|
+
<div class="child">1</div>
|
|
184
|
+
<div class="child">2</div>
|
|
185
|
+
<div class="child">3</div>
|
|
186
|
+
<div class="child">4</div>
|
|
187
|
+
<div class="child">5</div>
|
|
188
|
+
</div>
|
|
189
|
+
<div class="marker"></div>
|
|
190
|
+
<div class="destination"></div>
|
|
191
|
+
</div>
|
|
192
|
+
`);
|
|
193
|
+
const source = context.querySelector('.source');
|
|
194
|
+
const { children } = source;
|
|
195
|
+
const destination = context.querySelector('.destination');
|
|
196
|
+
expect(source.children.length).to.equal(5);
|
|
197
|
+
const restore = reparentChildren([...children], destination, {
|
|
198
|
+
position: 'beforebegin',
|
|
199
|
+
});
|
|
200
|
+
expect(source.children.length).to.equal(0);
|
|
201
|
+
expect(destination.children.length).to.equal(0);
|
|
202
|
+
const marker = context.querySelector('.marker');
|
|
203
|
+
expect(marker.previousElementSibling).to.not.be.null;
|
|
204
|
+
expect((_a = marker.nextElementSibling) === null || _a === void 0 ? void 0 : _a.textContent).to.equal('1');
|
|
205
|
+
expect((_b = destination.previousElementSibling) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('5');
|
|
206
|
+
restore();
|
|
207
|
+
expect(source.children.length).to.equal(5);
|
|
208
|
+
expect(marker.nextElementSibling).to.equal(destination);
|
|
209
|
+
expect((_c = source.firstElementChild) === null || _c === void 0 ? void 0 : _c.textContent).to.equal('1');
|
|
210
|
+
expect((_d = source.lastElementChild) === null || _d === void 0 ? void 0 : _d.textContent).to.equal('5');
|
|
211
|
+
});
|
|
212
|
+
it('afterend - reparents and returns multiple children', async () => {
|
|
213
|
+
var _a, _b, _c, _d;
|
|
214
|
+
const context = await fixture(html `
|
|
215
|
+
<div>
|
|
216
|
+
<div class="source">
|
|
217
|
+
<div class="child">1</div>
|
|
218
|
+
<div class="child">2</div>
|
|
219
|
+
<div class="child">3</div>
|
|
220
|
+
<div class="child">4</div>
|
|
221
|
+
<div class="child">5</div>
|
|
222
|
+
</div>
|
|
223
|
+
<div class="destination"></div>
|
|
224
|
+
<div class="marker"></div>
|
|
225
|
+
</div>
|
|
226
|
+
`);
|
|
227
|
+
const source = context.querySelector('.source');
|
|
228
|
+
const { children } = source;
|
|
229
|
+
const destination = context.querySelector('.destination');
|
|
230
|
+
expect(source.children.length).to.equal(5);
|
|
231
|
+
const marker = context.querySelector('.marker');
|
|
232
|
+
expect(marker.previousElementSibling).to.equal(destination);
|
|
233
|
+
expect(marker.nextElementSibling).to.be.null;
|
|
234
|
+
const restore = reparentChildren([...children], destination, {
|
|
235
|
+
position: 'afterend',
|
|
236
|
+
});
|
|
237
|
+
expect(source.children.length).to.equal(0);
|
|
238
|
+
expect(destination.children.length).to.equal(0);
|
|
239
|
+
expect((_a = destination.nextElementSibling) === null || _a === void 0 ? void 0 : _a.textContent).to.equal('1');
|
|
240
|
+
expect((_b = marker.previousElementSibling) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('5');
|
|
241
|
+
restore();
|
|
242
|
+
expect(source.children.length).to.equal(5);
|
|
243
|
+
expect(marker.previousElementSibling).to.equal(destination);
|
|
244
|
+
expect((_c = source.firstElementChild) === null || _c === void 0 ? void 0 : _c.textContent).to.equal('1');
|
|
245
|
+
expect((_d = source.lastElementChild) === null || _d === void 0 ? void 0 : _d.textContent).to.equal('5');
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
//# sourceMappingURL=reparent-children.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reparent-children.test.js","sourceRoot":"","sources":["reparent-children.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAiB,IAAI,CAAA;;;;;;;SAOjD,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,SAAS,CAAmB,CAAC;QAClE,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GAAG,gBAAgB,CAAC,CAAC,GAAG,QAAQ,CAAC,EAAE,WAAW,EAAE;YACzD,QAAQ,EAAE,UAAU;SACvB,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAEhD,MAAM,CAAC,MAAA,WAAW,CAAC,kBAAkB,0CAAE,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClE,MAAM,CAAC,MAAA,MAAM,CAAC,sBAAsB,0CAAE,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEjE,OAAO,EAAE,CAAC;QACV,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAE5D,MAAM,CAAC,MAAA,MAAM,CAAC,iBAAiB,0CAAE,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5D,MAAM,CAAC,MAAA,MAAM,CAAC,gBAAgB,0CAAE,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { expect, fixture, html } from '@open-wc/testing';\nimport { reparentChildren } from '../src/reparent-children.js';\n\ndescribe('Reparent Children', () => {\n it('reparents and returns a single child', async () => {\n const context = await fixture<HTMLDivElement>(html`\n <div>\n <div class=\"source\">\n <div class=\"child\"></div>\n </div>\n <div class=\"destination\"></div>\n </div>\n `);\n\n const source = context.querySelector('.source') as HTMLDivElement;\n const child = context.querySelector('.child') as HTMLDivElement;\n const destination = context.querySelector(\n '.destination'\n ) as HTMLDivElement;\n\n expect(source.children.length).to.equal(1);\n expect(destination.children.length).to.equal(0);\n const restore = reparentChildren([child], destination);\n\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(1);\n\n restore();\n expect(source.children.length).to.equal(1);\n expect(destination.children.length).to.equal(0);\n });\n\n it('early exits no children', async () => {\n const context = await fixture<HTMLDivElement>(html`\n <div>\n <div class=\"source\"></div>\n <div class=\"destination\"></div>\n </div>\n `);\n\n const source = context.querySelector('.source') as HTMLDivElement;\n const children = [...source.children] as HTMLDivElement[];\n const destination = context.querySelector(\n '.destination'\n ) as HTMLDivElement;\n\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(0);\n const restore = reparentChildren(children, destination);\n\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(0);\n\n restore();\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(0);\n });\n\n it('reparents and returns multiple child', async () => {\n const context = await fixture<HTMLDivElement>(html`\n <div>\n <div class=\"source\">\n <div class=\"child\"></div>\n <div class=\"child\"></div>\n <div class=\"child\"></div>\n <div class=\"child\"></div>\n <div class=\"child\"></div>\n </div>\n <div class=\"destination\"></div>\n </div>\n `);\n\n const source = context.querySelector('.source') as HTMLDivElement;\n const { children } = source;\n const destination = context.querySelector(\n '.destination'\n ) as HTMLDivElement;\n\n expect(source.children.length).to.equal(5);\n expect(destination.children.length).to.equal(0);\n const restore = reparentChildren([...children], destination);\n\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(5);\n\n restore();\n expect(source.children.length).to.equal(5);\n expect(destination.children.length).to.equal(0);\n });\n\n it('augments the child via a callback', async () => {\n const context = await fixture<HTMLDivElement>(html`\n <div>\n <div class=\"source\">\n <div class=\"child\" slot=\"slot\"></div>\n </div>\n <div class=\"destination\"></div>\n </div>\n `);\n\n const child = context.querySelector('.child') as HTMLDivElement;\n const destination = context.querySelector(\n '.destination'\n ) as HTMLDivElement;\n\n expect(child.getAttribute('slot')).to.equal('slot');\n const restore = reparentChildren([child], destination, {\n position: 'beforeend',\n prepareCallback: (el: Element) => {\n const slotName = el.slot;\n el.removeAttribute('slot');\n return (el: Element) => {\n el.slot = slotName;\n };\n },\n });\n\n expect(child.hasAttribute('slot')).to.be.false;\n\n restore();\n expect(child.getAttribute('slot')).to.equal('slot');\n });\n\n it('beforeend - reparents and returns multiple children', async () => {\n const context = await fixture<HTMLDivElement>(html`\n <div>\n <div class=\"source\">\n <div class=\"child\">1</div>\n <div class=\"child\">2</div>\n <div class=\"child\">3</div>\n <div class=\"child\">4</div>\n <div class=\"child\">5</div>\n </div>\n <div class=\"destination\">\n <div class=\"marker\"></div>\n </div>\n </div>\n `);\n\n const source = context.querySelector('.source') as HTMLDivElement;\n const { children } = source;\n const destination = context.querySelector(\n '.destination'\n ) as HTMLDivElement;\n\n expect(source.children.length).to.equal(5);\n expect(destination.children.length).to.equal(1);\n const restore = reparentChildren([...children], destination, {\n position: 'beforeend',\n });\n\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(5 + 1);\n\n const marker = context.querySelector('.marker') as HTMLDivElement;\n expect(marker.previousElementSibling).to.be.null;\n expect(marker.nextElementSibling?.textContent).to.equal('1');\n expect(destination.lastElementChild?.textContent).to.equal('5');\n\n restore();\n expect(source.children.length).to.equal(5);\n expect(destination.children.length).to.equal(1);\n\n expect(source.firstElementChild?.textContent).to.equal('1');\n expect(source.lastElementChild?.textContent).to.equal('5');\n });\n\n it('afterbegin - reparents and returns multiple children', async () => {\n const context = await fixture<HTMLDivElement>(html`\n <div>\n <div class=\"source\">\n <div class=\"child\">1</div>\n <div class=\"child\">2</div>\n <div class=\"child\">3</div>\n <div class=\"child\">4</div>\n <div class=\"child\">5</div>\n </div>\n <div class=\"destination\">\n <div class=\"marker\"></div>\n </div>\n </div>\n `);\n\n const source = context.querySelector('.source') as HTMLDivElement;\n const { children } = source;\n const destination = context.querySelector(\n '.destination'\n ) as HTMLDivElement;\n\n expect(source.children.length).to.equal(5);\n expect(destination.children.length).to.equal(1);\n const restore = reparentChildren([...children], destination, {\n position: 'afterbegin',\n });\n\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(5 + 1);\n\n const marker = context.querySelector('.marker') as HTMLDivElement;\n expect(marker.nextElementSibling).to.be.null;\n expect(marker.previousElementSibling?.textContent).to.equal('5');\n expect(destination.firstElementChild?.textContent).to.equal('1');\n\n restore();\n expect(source.children.length).to.equal(5);\n expect(destination.children.length).to.equal(1);\n\n expect(source.firstElementChild?.textContent).to.equal('1');\n expect(source.lastElementChild?.textContent).to.equal('5');\n });\n\n it('beforebegin - reparents and returns multiple children', async () => {\n const context = await fixture<HTMLDivElement>(html`\n <div>\n <div class=\"source\">\n <div class=\"child\">1</div>\n <div class=\"child\">2</div>\n <div class=\"child\">3</div>\n <div class=\"child\">4</div>\n <div class=\"child\">5</div>\n </div>\n <div class=\"marker\"></div>\n <div class=\"destination\"></div>\n </div>\n `);\n\n const source = context.querySelector('.source') as HTMLDivElement;\n const { children } = source;\n const destination = context.querySelector(\n '.destination'\n ) as HTMLDivElement;\n\n expect(source.children.length).to.equal(5);\n const restore = reparentChildren([...children], destination, {\n position: 'beforebegin',\n });\n\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(0);\n\n const marker = context.querySelector('.marker') as HTMLDivElement;\n expect(marker.previousElementSibling).to.not.be.null;\n expect(marker.nextElementSibling?.textContent).to.equal('1');\n expect(destination.previousElementSibling?.textContent).to.equal('5');\n\n restore();\n expect(source.children.length).to.equal(5);\n expect(marker.nextElementSibling).to.equal(destination);\n\n expect(source.firstElementChild?.textContent).to.equal('1');\n expect(source.lastElementChild?.textContent).to.equal('5');\n });\n\n it('afterend - reparents and returns multiple children', async () => {\n const context = await fixture<HTMLDivElement>(html`\n <div>\n <div class=\"source\">\n <div class=\"child\">1</div>\n <div class=\"child\">2</div>\n <div class=\"child\">3</div>\n <div class=\"child\">4</div>\n <div class=\"child\">5</div>\n </div>\n <div class=\"destination\"></div>\n <div class=\"marker\"></div>\n </div>\n `);\n\n const source = context.querySelector('.source') as HTMLDivElement;\n const { children } = source;\n const destination = context.querySelector(\n '.destination'\n ) as HTMLDivElement;\n\n expect(source.children.length).to.equal(5);\n\n const marker = context.querySelector('.marker') as HTMLDivElement;\n expect(marker.previousElementSibling).to.equal(destination);\n expect(marker.nextElementSibling).to.be.null;\n\n const restore = reparentChildren([...children], destination, {\n position: 'afterend',\n });\n\n expect(source.children.length).to.equal(0);\n expect(destination.children.length).to.equal(0);\n\n expect(destination.nextElementSibling?.textContent).to.equal('1');\n expect(marker.previousElementSibling?.textContent).to.equal('5');\n\n restore();\n expect(source.children.length).to.equal(5);\n expect(marker.previousElementSibling).to.equal(destination);\n\n expect(source.firstElementChild?.textContent).to.equal('1');\n expect(source.lastElementChild?.textContent).to.equal('5');\n });\n});\n"]}
|