@spectrum-web-components/truncated 1.7.0 → 1.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/truncated",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -64,10 +64,10 @@
64
64
  "css"
65
65
  ],
66
66
  "dependencies": {
67
- "@spectrum-web-components/base": "1.7.0",
68
- "@spectrum-web-components/overlay": "1.7.0",
69
- "@spectrum-web-components/styles": "1.7.0",
70
- "@spectrum-web-components/tooltip": "1.7.0"
67
+ "@spectrum-web-components/base": "1.8.0",
68
+ "@spectrum-web-components/overlay": "1.8.0",
69
+ "@spectrum-web-components/styles": "1.8.0",
70
+ "@spectrum-web-components/tooltip": "1.8.0"
71
71
  },
72
72
  "types": "./src/index.d.ts",
73
73
  "customElements": "custom-elements.json",
package/sp-truncated.d.ts CHANGED
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Copyright 2025 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
+ */
1
12
  import { Truncated } from './src/Truncated.js';
2
13
  declare global {
3
14
  interface HTMLElementTagNameMap {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["sp-truncated.ts"],
4
- "sourcesContent": ["/*\nCopyright 2024 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 { Truncated } from './src/Truncated.dev.js'\n\ncustomElements.define('sp-truncated', Truncated);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-truncated': Truncated;\n }\n}\n"],
4
+ "sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { Truncated } from './src/Truncated.dev.js'\n\ncustomElements.define('sp-truncated', Truncated);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-truncated': Truncated;\n }\n}\n"],
5
5
  "mappings": ";AAYA,SAAS,iBAAiB;AAE1B,eAAe,OAAO,gBAAgB,SAAS;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["sp-truncated.ts"],
4
- "sourcesContent": ["/*\nCopyright 2024 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 { Truncated } from './src/Truncated.js';\n\ncustomElements.define('sp-truncated', Truncated);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-truncated': Truncated;\n }\n}\n"],
4
+ "sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { Truncated } from './src/Truncated.js';\n\ncustomElements.define('sp-truncated', Truncated);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-truncated': Truncated;\n }\n}\n"],
5
5
  "mappings": "aAYA,OAAS,aAAAA,MAAiB,qBAE1B,eAAe,OAAO,eAAgBA,CAAS",
6
6
  "names": ["Truncated"]
7
7
  }
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Copyright 2025 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
+ */
1
12
  import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
2
13
  import type { Placement } from '@spectrum-web-components/overlay';
3
14
  import '@spectrum-web-components/overlay/sp-overlay.js';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["Truncated.ts"],
4
- "sourcesContent": ["/*\nCopyright 2021 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 {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport type { Overlay, Placement } from '@spectrum-web-components/overlay';\nimport '@spectrum-web-components/overlay/sp-overlay.js';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport {\n property,\n query,\n queryAssignedElements,\n queryAssignedNodes,\n state,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport styles from './truncated.css.js';\n\n/**\n * @element sp-truncated\n */\nexport class Truncated extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n /**\n * @type {\"top\" | \"top-start\" | \"top-end\" | \"right\" | \"right-start\" | \"right-end\" | \"bottom\" | \"bottom-start\" | \"bottom-end\" | \"left\" | \"left-start\" | \"left-end\"}\n */\n @property()\n placement: Placement = 'top-start';\n\n /*\n * @type {String}\n * @attr success-message\n * @description The message to display when the text is copied to the clipboard after clicking on the truncated text\n */\n @property({ type: String, attribute: 'success-message' })\n successMessage = 'Copied to clipboard';\n\n @state()\n hasCopied = false;\n\n @state()\n private fullText = '';\n\n @state()\n private overflowing = false;\n\n @query('#content')\n private content!: HTMLElement;\n\n @query('#overlay')\n private overlayEl?: Overlay;\n\n @queryAssignedNodes({ flatten: true })\n private slottedContent!: Node[];\n\n // elements instead of nodes because, according to spec,\n // flattened assignedNodes will return a slot's *children* if there are no assigned nodes.\n // \u00AF\\_(\u30C4)_/\u00AF\n @queryAssignedElements({ slot: 'overflow', flatten: true })\n private slottedOverflow!: HTMLElement[];\n\n get hasCustomOverflow(): boolean {\n return this.slottedOverflow.length > 0;\n }\n\n private resizeObserver = new ResizeObserver(() => {\n this.measureOverflow();\n });\n\n private mutationObserver = new MutationObserver(() => {\n this.copyText();\n });\n\n override render(): TemplateResult {\n /* eslint-disable lit-a11y/click-events-have-key-events */\n return html`\n <span id=\"content\" @click=${this.handleClick}>\n <slot></slot>\n </span>\n ${this.renderTooltip()}\n `;\n /* eslint-enable lit-a11y/click-events-have-key-events */\n }\n\n private renderTooltip(): TemplateResult | undefined {\n if (!this.overflowing) {\n return html`\n <slot\n name=\"overflow\"\n style=\"display: none\"\n @slotchange=${this.handleOverflowSlotchange}\n ></slot>\n `;\n }\n return html`\n <sp-overlay\n id=\"overlay\"\n .triggerElement=${this as HTMLElement}\n .triggerInteraction=${'hover'}\n type=\"hint\"\n placement=${this.placement}\n >\n <sp-tooltip name=\"tooltip\">\n ${!this.hasCopied\n ? html`\n <slot\n name=\"overflow\"\n @slotchange=${this.handleOverflowSlotchange}\n >\n ${this.fullText}\n </slot>\n `\n : this.successMessage}\n </sp-tooltip>\n </sp-overlay>\n `;\n }\n\n protected override firstUpdated(\n _changedProperties: PropertyValues<this>\n ): void {\n this.resizeObserver.observe(this);\n this.resizeObserver.observe(this.content);\n this.copyText();\n this.measureOverflow();\n }\n\n protected override updated(changedProperties: PropertyValues<this>): void {\n super.updated(changedProperties);\n if (\n changedProperties.has('hasCopied') &&\n this.hasCopied &&\n this.overlayEl\n ) {\n // we know overlayEl exists because it couldn't copy the text otherwise\n this.overlayEl.open = true;\n }\n }\n\n private handleOverflowSlotchange(): void {\n this.mutationObserver.disconnect();\n if (!this.hasCustomOverflow) {\n /* c8 ignore next 5 */\n this.mutationObserver.observe(this.content, {\n subtree: true,\n childList: true,\n characterData: true,\n });\n }\n }\n\n private handleClick(): void {\n if (!this.overflowing) return;\n\n const textToCopy = this.slottedContent\n .map((node) => node.textContent ?? '')\n .join('')\n .trim();\n navigator.clipboard.writeText(textToCopy);\n this.hasCopied = true;\n /* c8 ignore next 3 */\n setTimeout(() => {\n this.hasCopied = false;\n }, 6000);\n }\n\n private measureOverflow(): void {\n // Add 1 because Safari sometimes rounds by 1px, breaking the calculation otherwise\n this.overflowing = this.content.offsetWidth > this.clientWidth + 1;\n }\n\n // Copies just the textContent of slotted nodes into the tooltip to avoid duplicating the user's DOM\n private copyText(): void {\n if (this.hasCustomOverflow) return;\n this.fullText = this.slottedContent\n .map((node) => node.textContent ?? '')\n .join('');\n }\n}\n"],
4
+ "sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport type { Overlay, Placement } from '@spectrum-web-components/overlay';\nimport '@spectrum-web-components/overlay/sp-overlay.js';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport {\n property,\n query,\n queryAssignedElements,\n queryAssignedNodes,\n state,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport styles from './truncated.css.js';\n\n/**\n * @element sp-truncated\n */\nexport class Truncated extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n /**\n * @type {\"top\" | \"top-start\" | \"top-end\" | \"right\" | \"right-start\" | \"right-end\" | \"bottom\" | \"bottom-start\" | \"bottom-end\" | \"left\" | \"left-start\" | \"left-end\"}\n */\n @property()\n placement: Placement = 'top-start';\n\n /*\n * @type {String}\n * @attr success-message\n * @description The message to display when the text is copied to the clipboard after clicking on the truncated text\n */\n @property({ type: String, attribute: 'success-message' })\n successMessage = 'Copied to clipboard';\n\n @state()\n hasCopied = false;\n\n @state()\n private fullText = '';\n\n @state()\n private overflowing = false;\n\n @query('#content')\n private content!: HTMLElement;\n\n @query('#overlay')\n private overlayEl?: Overlay;\n\n @queryAssignedNodes({ flatten: true })\n private slottedContent!: Node[];\n\n // elements instead of nodes because, according to spec,\n // flattened assignedNodes will return a slot's *children* if there are no assigned nodes.\n // \u00AF\\_(\u30C4)_/\u00AF\n @queryAssignedElements({ slot: 'overflow', flatten: true })\n private slottedOverflow!: HTMLElement[];\n\n get hasCustomOverflow(): boolean {\n return this.slottedOverflow.length > 0;\n }\n\n private resizeObserver = new ResizeObserver(() => {\n this.measureOverflow();\n });\n\n private mutationObserver = new MutationObserver(() => {\n this.copyText();\n });\n\n override render(): TemplateResult {\n /* eslint-disable lit-a11y/click-events-have-key-events */\n return html`\n <span id=\"content\" @click=${this.handleClick}>\n <slot></slot>\n </span>\n ${this.renderTooltip()}\n `;\n /* eslint-enable lit-a11y/click-events-have-key-events */\n }\n\n private renderTooltip(): TemplateResult | undefined {\n if (!this.overflowing) {\n return html`\n <slot\n name=\"overflow\"\n style=\"display: none\"\n @slotchange=${this.handleOverflowSlotchange}\n ></slot>\n `;\n }\n return html`\n <sp-overlay\n id=\"overlay\"\n .triggerElement=${this as HTMLElement}\n .triggerInteraction=${'hover'}\n type=\"hint\"\n placement=${this.placement}\n >\n <sp-tooltip name=\"tooltip\">\n ${!this.hasCopied\n ? html`\n <slot\n name=\"overflow\"\n @slotchange=${this.handleOverflowSlotchange}\n >\n ${this.fullText}\n </slot>\n `\n : this.successMessage}\n </sp-tooltip>\n </sp-overlay>\n `;\n }\n\n protected override firstUpdated(\n _changedProperties: PropertyValues<this>\n ): void {\n this.resizeObserver.observe(this);\n this.resizeObserver.observe(this.content);\n this.copyText();\n this.measureOverflow();\n }\n\n protected override updated(changedProperties: PropertyValues<this>): void {\n super.updated(changedProperties);\n if (\n changedProperties.has('hasCopied') &&\n this.hasCopied &&\n this.overlayEl\n ) {\n // we know overlayEl exists because it couldn't copy the text otherwise\n this.overlayEl.open = true;\n }\n }\n\n private handleOverflowSlotchange(): void {\n this.mutationObserver.disconnect();\n if (!this.hasCustomOverflow) {\n /* c8 ignore next 5 */\n this.mutationObserver.observe(this.content, {\n subtree: true,\n childList: true,\n characterData: true,\n });\n }\n }\n\n private handleClick(): void {\n if (!this.overflowing) return;\n\n const textToCopy = this.slottedContent\n .map((node) => node.textContent ?? '')\n .join('')\n .trim();\n navigator.clipboard.writeText(textToCopy);\n this.hasCopied = true;\n /* c8 ignore next 3 */\n setTimeout(() => {\n this.hasCopied = false;\n }, 6000);\n }\n\n private measureOverflow(): void {\n // Add 1 because Safari sometimes rounds by 1px, breaking the calculation otherwise\n this.overflowing = this.content.offsetWidth > this.clientWidth + 1;\n }\n\n // Copies just the textContent of slotted nodes into the tooltip to avoid duplicating the user's DOM\n private copyText(): void {\n if (this.hasCustomOverflow) return;\n this.fullText = this.slottedContent\n .map((node) => node.textContent ?? '')\n .join('');\n }\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EAEA;AAAA,OAEG;AAEP,OAAO;AACP,OAAO;AACP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,OAAO,YAAY;AAKZ,aAAM,kBAAkB,gBAAgB;AAAA,EAAxC;AAAA;AASH,qBAAuB;AAQvB,0BAAiB;AAGjB,qBAAY;AAGZ,SAAQ,WAAW;AAGnB,SAAQ,cAAc;AAqBtB,SAAQ,iBAAiB,IAAI,eAAe,MAAM;AAC9C,WAAK,gBAAgB;AAAA,IACzB,CAAC;AAED,SAAQ,mBAAmB,IAAI,iBAAiB,MAAM;AAClD,WAAK,SAAS;AAAA,IAClB,CAAC;AAAA;AAAA,EApDD,WAA2B,SAAyB;AAChD,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,EAwCA,IAAI,oBAA6B;AAC7B,WAAO,KAAK,gBAAgB,SAAS;AAAA,EACzC;AAAA,EAUS,SAAyB;AAE9B,WAAO;AAAA,wCACyB,KAAK,WA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,eAAW,MAAM;AACb,WAAK,YAAY;AAAA,IACrB,GAAG,GAAI;AAAA,EACX;AAAA,EAEQ,kBAAwB;AAE5B,SAAK,cAAc,KAAK,QAAQ,cAAc,KAAK,cAAc;AAAA,EACrE;AAAA;AAAA,EAGQ,WAAiB;AACrB,QAAI,KAAK,kBAAmB;AAC5B,SAAK,WAAW,KAAK,eAChB,IAAI,CAAC,SAAM;AAhMxB;AAgM2B,wBAAK,gBAAL,YAAoB;AAAA,KAAE,EACpC,KAAK,EAAE;AAAA,EAChB;AACJ;AAvJI;AAAA,EADC,SAAS;AAAA,GARD,UAST;AAQA;AAAA,EADC,SAAS,EAAE,MAAM,QAAQ,WAAW,kBAAkB,CAAC;AAAA,GAhB/C,UAiBT;AAGA;AAAA,EADC,MAAM;AAAA,GAnBE,UAoBT;AAGQ;AAAA,EADP,MAAM;AAAA,GAtBE,UAuBD;AAGA;AAAA,EADP,MAAM;AAAA,GAzBE,UA0BD;AAGA;AAAA,EADP,MAAM,UAAU;AAAA,GA5BR,UA6BD;AAGA;AAAA,EADP,MAAM,UAAU;AAAA,GA/BR,UAgCD;AAGA;AAAA,EADP,mBAAmB,EAAE,SAAS,KAAK,CAAC;AAAA,GAlC5B,UAmCD;AAMA;AAAA,EADP,sBAAsB,EAAE,MAAM,YAAY,SAAS,KAAK,CAAC;AAAA,GAxCjD,UAyCD;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["Truncated.ts"],
4
- "sourcesContent": ["/*\nCopyright 2021 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 {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport type { Overlay, Placement } from '@spectrum-web-components/overlay';\nimport '@spectrum-web-components/overlay/sp-overlay.js';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport {\n property,\n query,\n queryAssignedElements,\n queryAssignedNodes,\n state,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport styles from './truncated.css.js';\n\n/**\n * @element sp-truncated\n */\nexport class Truncated extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n /**\n * @type {\"top\" | \"top-start\" | \"top-end\" | \"right\" | \"right-start\" | \"right-end\" | \"bottom\" | \"bottom-start\" | \"bottom-end\" | \"left\" | \"left-start\" | \"left-end\"}\n */\n @property()\n placement: Placement = 'top-start';\n\n /*\n * @type {String}\n * @attr success-message\n * @description The message to display when the text is copied to the clipboard after clicking on the truncated text\n */\n @property({ type: String, attribute: 'success-message' })\n successMessage = 'Copied to clipboard';\n\n @state()\n hasCopied = false;\n\n @state()\n private fullText = '';\n\n @state()\n private overflowing = false;\n\n @query('#content')\n private content!: HTMLElement;\n\n @query('#overlay')\n private overlayEl?: Overlay;\n\n @queryAssignedNodes({ flatten: true })\n private slottedContent!: Node[];\n\n // elements instead of nodes because, according to spec,\n // flattened assignedNodes will return a slot's *children* if there are no assigned nodes.\n // \u00AF\\_(\u30C4)_/\u00AF\n @queryAssignedElements({ slot: 'overflow', flatten: true })\n private slottedOverflow!: HTMLElement[];\n\n get hasCustomOverflow(): boolean {\n return this.slottedOverflow.length > 0;\n }\n\n private resizeObserver = new ResizeObserver(() => {\n this.measureOverflow();\n });\n\n private mutationObserver = new MutationObserver(() => {\n this.copyText();\n });\n\n override render(): TemplateResult {\n /* eslint-disable lit-a11y/click-events-have-key-events */\n return html`\n <span id=\"content\" @click=${this.handleClick}>\n <slot></slot>\n </span>\n ${this.renderTooltip()}\n `;\n /* eslint-enable lit-a11y/click-events-have-key-events */\n }\n\n private renderTooltip(): TemplateResult | undefined {\n if (!this.overflowing) {\n return html`\n <slot\n name=\"overflow\"\n style=\"display: none\"\n @slotchange=${this.handleOverflowSlotchange}\n ></slot>\n `;\n }\n return html`\n <sp-overlay\n id=\"overlay\"\n .triggerElement=${this as HTMLElement}\n .triggerInteraction=${'hover'}\n type=\"hint\"\n placement=${this.placement}\n >\n <sp-tooltip name=\"tooltip\">\n ${!this.hasCopied\n ? html`\n <slot\n name=\"overflow\"\n @slotchange=${this.handleOverflowSlotchange}\n >\n ${this.fullText}\n </slot>\n `\n : this.successMessage}\n </sp-tooltip>\n </sp-overlay>\n `;\n }\n\n protected override firstUpdated(\n _changedProperties: PropertyValues<this>\n ): void {\n this.resizeObserver.observe(this);\n this.resizeObserver.observe(this.content);\n this.copyText();\n this.measureOverflow();\n }\n\n protected override updated(changedProperties: PropertyValues<this>): void {\n super.updated(changedProperties);\n if (\n changedProperties.has('hasCopied') &&\n this.hasCopied &&\n this.overlayEl\n ) {\n // we know overlayEl exists because it couldn't copy the text otherwise\n this.overlayEl.open = true;\n }\n }\n\n private handleOverflowSlotchange(): void {\n this.mutationObserver.disconnect();\n if (!this.hasCustomOverflow) {\n /* c8 ignore next 5 */\n this.mutationObserver.observe(this.content, {\n subtree: true,\n childList: true,\n characterData: true,\n });\n }\n }\n\n private handleClick(): void {\n if (!this.overflowing) return;\n\n const textToCopy = this.slottedContent\n .map((node) => node.textContent ?? '')\n .join('')\n .trim();\n navigator.clipboard.writeText(textToCopy);\n this.hasCopied = true;\n /* c8 ignore next 3 */\n setTimeout(() => {\n this.hasCopied = false;\n }, 6000);\n }\n\n private measureOverflow(): void {\n // Add 1 because Safari sometimes rounds by 1px, breaking the calculation otherwise\n this.overflowing = this.content.offsetWidth > this.clientWidth + 1;\n }\n\n // Copies just the textContent of slotted nodes into the tooltip to avoid duplicating the user's DOM\n private copyText(): void {\n if (this.hasCustomOverflow) return;\n this.fullText = this.slottedContent\n .map((node) => node.textContent ?? '')\n .join('');\n }\n}\n"],
4
+ "sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport type { Overlay, Placement } from '@spectrum-web-components/overlay';\nimport '@spectrum-web-components/overlay/sp-overlay.js';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport {\n property,\n query,\n queryAssignedElements,\n queryAssignedNodes,\n state,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport styles from './truncated.css.js';\n\n/**\n * @element sp-truncated\n */\nexport class Truncated extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n /**\n * @type {\"top\" | \"top-start\" | \"top-end\" | \"right\" | \"right-start\" | \"right-end\" | \"bottom\" | \"bottom-start\" | \"bottom-end\" | \"left\" | \"left-start\" | \"left-end\"}\n */\n @property()\n placement: Placement = 'top-start';\n\n /*\n * @type {String}\n * @attr success-message\n * @description The message to display when the text is copied to the clipboard after clicking on the truncated text\n */\n @property({ type: String, attribute: 'success-message' })\n successMessage = 'Copied to clipboard';\n\n @state()\n hasCopied = false;\n\n @state()\n private fullText = '';\n\n @state()\n private overflowing = false;\n\n @query('#content')\n private content!: HTMLElement;\n\n @query('#overlay')\n private overlayEl?: Overlay;\n\n @queryAssignedNodes({ flatten: true })\n private slottedContent!: Node[];\n\n // elements instead of nodes because, according to spec,\n // flattened assignedNodes will return a slot's *children* if there are no assigned nodes.\n // \u00AF\\_(\u30C4)_/\u00AF\n @queryAssignedElements({ slot: 'overflow', flatten: true })\n private slottedOverflow!: HTMLElement[];\n\n get hasCustomOverflow(): boolean {\n return this.slottedOverflow.length > 0;\n }\n\n private resizeObserver = new ResizeObserver(() => {\n this.measureOverflow();\n });\n\n private mutationObserver = new MutationObserver(() => {\n this.copyText();\n });\n\n override render(): TemplateResult {\n /* eslint-disable lit-a11y/click-events-have-key-events */\n return html`\n <span id=\"content\" @click=${this.handleClick}>\n <slot></slot>\n </span>\n ${this.renderTooltip()}\n `;\n /* eslint-enable lit-a11y/click-events-have-key-events */\n }\n\n private renderTooltip(): TemplateResult | undefined {\n if (!this.overflowing) {\n return html`\n <slot\n name=\"overflow\"\n style=\"display: none\"\n @slotchange=${this.handleOverflowSlotchange}\n ></slot>\n `;\n }\n return html`\n <sp-overlay\n id=\"overlay\"\n .triggerElement=${this as HTMLElement}\n .triggerInteraction=${'hover'}\n type=\"hint\"\n placement=${this.placement}\n >\n <sp-tooltip name=\"tooltip\">\n ${!this.hasCopied\n ? html`\n <slot\n name=\"overflow\"\n @slotchange=${this.handleOverflowSlotchange}\n >\n ${this.fullText}\n </slot>\n `\n : this.successMessage}\n </sp-tooltip>\n </sp-overlay>\n `;\n }\n\n protected override firstUpdated(\n _changedProperties: PropertyValues<this>\n ): void {\n this.resizeObserver.observe(this);\n this.resizeObserver.observe(this.content);\n this.copyText();\n this.measureOverflow();\n }\n\n protected override updated(changedProperties: PropertyValues<this>): void {\n super.updated(changedProperties);\n if (\n changedProperties.has('hasCopied') &&\n this.hasCopied &&\n this.overlayEl\n ) {\n // we know overlayEl exists because it couldn't copy the text otherwise\n this.overlayEl.open = true;\n }\n }\n\n private handleOverflowSlotchange(): void {\n this.mutationObserver.disconnect();\n if (!this.hasCustomOverflow) {\n /* c8 ignore next 5 */\n this.mutationObserver.observe(this.content, {\n subtree: true,\n childList: true,\n characterData: true,\n });\n }\n }\n\n private handleClick(): void {\n if (!this.overflowing) return;\n\n const textToCopy = this.slottedContent\n .map((node) => node.textContent ?? '')\n .join('')\n .trim();\n navigator.clipboard.writeText(textToCopy);\n this.hasCopied = true;\n /* c8 ignore next 3 */\n setTimeout(() => {\n this.hasCopied = false;\n }, 6000);\n }\n\n private measureOverflow(): void {\n // Add 1 because Safari sometimes rounds by 1px, breaking the calculation otherwise\n this.overflowing = this.content.offsetWidth > this.clientWidth + 1;\n }\n\n // Copies just the textContent of slotted nodes into the tooltip to avoid duplicating the user's DOM\n private copyText(): void {\n if (this.hasCustomOverflow) return;\n this.fullText = this.slottedContent\n .map((node) => node.textContent ?? '')\n .join('');\n }\n}\n"],
5
5
  "mappings": "qNAYA,OAEI,QAAAA,EAEA,mBAAAC,MAEG,gCAEP,MAAO,iDACP,MAAO,iDACP,OACI,YAAAC,EACA,SAAAC,EACA,yBAAAC,EACA,sBAAAC,EACA,SAAAC,MACG,kDAEP,OAAOC,MAAY,qBAKZ,aAAM,kBAAkBN,CAAgB,CAAxC,kCASH,eAAuB,YAQvB,oBAAiB,sBAGjB,eAAY,GAGZ,KAAQ,SAAW,GAGnB,KAAQ,YAAc,GAqBtB,KAAQ,eAAiB,IAAI,eAAe,IAAM,CAC9C,KAAK,gBAAgB,CACzB,CAAC,EAED,KAAQ,iBAAmB,IAAI,iBAAiB,IAAM,CAClD,KAAK,SAAS,CAClB,CAAC,EApDD,WAA2B,QAAyB,CAChD,MAAO,CAACM,CAAM,CAClB,CAwCA,IAAI,mBAA6B,CAC7B,OAAO,KAAK,gBAAgB,OAAS,CACzC,CAUS,QAAyB,CAE9B,OAAOP;AAAA,wCACyB,KAAK,WAAW;AAAA;AAAA;AAAA,cAG1C,KAAK,cAAc,CAAC;AAAA,SAG9B,CAEQ,eAA4C,CAChD,OAAK,KAAK,YASHA;AAAA;AAAA;AAAA,kCAGmB,IAAmB;AAAA,sCACf,OAAO;AAAA;AAAA,4BAEjB,KAAK,SAAS;AAAA;AAAA;AAAA,sBAGnB,KAAK,UASF,KAAK,eARLA;AAAA;AAAA;AAAA,gDAGsB,KAAK,wBAAwB;AA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EAAM,GAnBE,UAoBT,yBAGQO,EAAA,CADPP,EAAM,GAtBE,UAuBD,wBAGAO,EAAA,CADPP,EAAM,GAzBE,UA0BD,2BAGAO,EAAA,CADPV,EAAM,UAAU,GA5BR,UA6BD,uBAGAU,EAAA,CADPV,EAAM,UAAU,GA/BR,UAgCD,yBAGAU,EAAA,CADPR,EAAmB,CAAE,QAAS,EAAK,CAAC,GAlC5B,UAmCD,8BAMAQ,EAAA,CADPT,EAAsB,CAAE,KAAM,WAAY,QAAS,EAAK,CAAC,GAxCjD,UAyCD",
6
6
  "names": ["html", "SpectrumElement", "property", "query", "queryAssignedElements", "queryAssignedNodes", "state", "styles", "_changedProperties", "changedProperties", "textToCopy", "node", "_a", "__decorateClass"]
7
7
  }
package/src/index.d.ts CHANGED
@@ -1 +1,12 @@
1
+ /**
2
+ * Copyright 2025 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
+ */
1
12
  export * from './Truncated.js';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["index.ts"],
4
- "sourcesContent": ["/*\nCopyright 2024 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*/\nexport * from './Truncated.dev.js'\n"],
4
+ "sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport * from './Truncated.dev.js'\n"],
5
5
  "mappings": ";AAWA,cAAc;",
6
6
  "names": []
7
7
  }
package/src/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["index.ts"],
4
- "sourcesContent": ["/*\nCopyright 2024 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*/\nexport * from './Truncated.js';\n"],
4
+ "sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport * from './Truncated.js';\n"],
5
5
  "mappings": "aAWA,WAAc",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["truncated.css.ts"],
4
- "sourcesContent": ["/*\nCopyright 2025 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 { css } from '@spectrum-web-components/base';\nconst styles = css`\n :host{min-width:0;max-width:100%;white-space:nowrap;text-overflow:ellipsis;display:inline-block;overflow:hidden}\n`;\nexport default styles;"],
4
+ "sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n :host{min-width:0;max-width:100%;white-space:nowrap;text-overflow:ellipsis;display:inline-block;overflow:hidden}\n`;\nexport default styles;"],
5
5
  "mappings": ";AAWA,SAAS,WAAW;AACpB,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["truncated.css.ts"],
4
- "sourcesContent": ["/*\nCopyright 2025 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 { css } from '@spectrum-web-components/base';\nconst styles = css`\n :host{min-width:0;max-width:100%;white-space:nowrap;text-overflow:ellipsis;display:inline-block;overflow:hidden}\n`;\nexport default styles;"],
4
+ "sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n :host{min-width:0;max-width:100%;white-space:nowrap;text-overflow:ellipsis;display:inline-block;overflow:hidden}\n`;\nexport default styles;"],
5
5
  "mappings": "aAWA,OAAS,OAAAA,MAAW,gCACpB,MAAMC,EAASD;AAAA;AAAA,EAGf,eAAeC",
6
6
  "names": ["css", "styles"]
7
7
  }