@spectrum-web-components/shared 0.14.3 → 0.14.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/shared",
3
- "version": "0.14.3",
3
+ "version": "0.14.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -50,5 +50,5 @@
50
50
  "types": "./src/index.d.ts",
51
51
  "customElements": "custom-elements.json",
52
52
  "sideEffects": false,
53
- "gitHead": "e5cd4a0db2201b8126eb9133ac3c24172d086359"
53
+ "gitHead": "3be62133721efba844cd7032566a2c49ed6d9875"
54
54
  }
@@ -18,8 +18,11 @@ export function ObserveSlotPresence(constructor, lightDomSelector) {
18
18
  changes = changes || previousValue !== nextValue;
19
19
  this[slotContentIsPresent].set(selector, !!this.querySelector(selector));
20
20
  });
21
- if (changes)
22
- this.requestUpdate();
21
+ if (changes) {
22
+ this.updateComplete.then(() => {
23
+ this.requestUpdate();
24
+ });
25
+ }
23
26
  };
24
27
  new MutationController(this, {
25
28
  config: {
@@ -1 +1 @@
1
- {"version":3,"file":"observe-slot-presence.js","sourceRoot":"","sources":["observe-slot-presence.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAc5D,MAAM,UAAU,mBAAmB,CAC/B,WAAc,EACd,gBAAmC;;IAEnC,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACrD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACzB,MAAM,4BACF,SAAQ,WAAW;QAGnB,8DAA8D;QAC9D,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,IAAI,CAAC,CAAC;YA8BR,QAAsB,GAAyB,IAAI,G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CAAC,QAAQ,CAAC,EAAE;gBAC1C,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC;aAC5D;YACD,MAAM,IAAI,KAAK,CACX,2BAA2B,QAAQ,2BAA2B,CACjE,CAAC;QACN,CAAC;KAgBJ;SAzBY,oBAAoB;IA0BjC,OAAO,4BAA4B,CAAC;AACxC,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*/\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) this.requestUpdate();\n };\n }\n return SlotPresenceObservingElement;\n}\n"]}
1
+ {"version":3,"file":"observe-slot-presence.js","sourceRoot":"","sources":["observe-slot-presence.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAc5D,MAAM,UAAU,mBAAmB,CAC/B,WAAc,EACd,gBAAmC;;IAEnC,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACrD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACzB,MAAM,4BACF,SAAQ,WAAW;QAGnB,8DAA8D;QAC9D,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,IAAI,CAAC,CAAC;YA8BR,QAAsB,GAAyB,IAAI,GAAG,EAAE,CAAC;YAW1D,+BAA0B,GAAG,GAAS,EAAE;gBAC3C,IAAI,OAAO,GAAG,KAAK,CAAC;gBACpB,iBAAiB,CAAC,OA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AAE;gBAC1C,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC;aAC5D;YACD,MAAM,IAAI,KAAK,CACX,2BAA2B,QAAQ,2BAA2B,CACjE,CAAC;QACN,CAAC;KAoBJ;SA7BY,oBAAoB;IA8BjC,OAAO,4BAA4B,CAAC;AACxC,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*/\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"]}
@@ -53,7 +53,9 @@ export function ObserveSlotText(constructor, slotName) {
53
53
  }
54
54
  firstUpdated(changedProperties) {
55
55
  super.firstUpdated(changedProperties);
56
- this.manageTextObservedSlot();
56
+ this.updateComplete.then(() => {
57
+ this.manageTextObservedSlot();
58
+ });
57
59
  }
58
60
  }
59
61
  _a = assignedNodesList;
@@ -1 +1 @@
1
- {"version":3,"file":"observe-slot-text.js","sourceRoot":"","sources":["observe-slot-text.ts"],"names":[],"mappings":";AAYA,OAAO,EACH,QAAQ,EACR,kBAAkB,GACrB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,MAAM,iBAAiB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAalD,MAAM,UAAU,eAAe,CAC3B,WAAc,EACd,QAAiB;;IAEjB,MAAM,wBACF,SAAQ,WAAW;QAGnB,8DAA8D;QAC9D,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,IAAI,CAA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CAAC,CAAE,IAAoB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;qBACrD;oBACD,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;gBAC9D,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;aAC9C;YACD,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACpC,CAAC;QAEkB,YAAY,CAC3B,iBAAiC;YAEjC,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;YACtC,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAClC,CAAC;KACJ;SAtCY,iBAAiB;IAH1B;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oEAChB;IAG9B;QADC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,CAAC;sDACmB;IAuC1D,OAAO,wBAAwB,CAAC;AACpC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { PropertyValues, ReactiveElement } from '@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.manageTextObservedSlot();\n }\n }\n return SlotTextObservingElement;\n}\n"]}
1
+ {"version":3,"file":"observe-slot-text.js","sourceRoot":"","sources":["observe-slot-text.ts"],"names":[],"mappings":";AAYA,OAAO,EACH,QAAQ,EACR,kBAAkB,GACrB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,kBAAkB,E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BAC5B,MAAM,SAAS,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;oBAC9C,IAAK,IAAoB,CAAC,OAAO,EAAE;wBAC/B,OAAO,QAAQ;4BACX,CAAC,CAAE,IAAoB,CAAC,YAAY,CAAC,MAAM,CAAC;gCACtC,QAAQ;4BACd,CAAC,CAAC,CAAE,IAAoB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;qBACrD;oBACD,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;gBAC9D,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;aAC9C;YACD,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACpC,CAAC;QAEkB,YAAY,CAC3B,iBAAiC;YAEjC,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;YACtC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC1B,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAClC,CAAC,CAAC,CAAC;QACP,CAAC;KACJ;SAxCY,iBAAiB;IAH1B;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oEAChB;IAG9B;QADC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,CAAC;sDACmB;IAyC1D,OAAO,wBAAwB,CAAC;AACpC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { PropertyValues, ReactiveElement } from '@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"]}