@spectrum-web-components/truncated 1.1.0 → 1.1.2

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.1.0",
3
+ "version": "1.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -58,10 +58,10 @@
58
58
  "lit-html"
59
59
  ],
60
60
  "dependencies": {
61
- "@spectrum-web-components/base": "^1.1.0",
62
- "@spectrum-web-components/overlay": "^1.1.0",
63
- "@spectrum-web-components/styles": "^1.1.0",
64
- "@spectrum-web-components/tooltip": "^1.1.0"
61
+ "@spectrum-web-components/base": "^1.1.2",
62
+ "@spectrum-web-components/overlay": "^1.1.2",
63
+ "@spectrum-web-components/styles": "^1.1.2",
64
+ "@spectrum-web-components/tooltip": "^1.1.2"
65
65
  },
66
66
  "types": "./src/index.d.ts",
67
67
  "customElements": "custom-elements.json",
@@ -69,5 +69,5 @@
69
69
  "./sp-*.js",
70
70
  "./**/*.dev.js"
71
71
  ],
72
- "gitHead": "e3c6e52501451acc6fa85b10dd718267b80a01ab"
72
+ "gitHead": "9ee45f2dfd3ac1939072726d00195c6c05d9a562"
73
73
  }
@@ -0,0 +1,6 @@
1
+ import { Truncated } from './src/Truncated.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'sp-truncated': Truncated;
5
+ }
6
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ import { Truncated } from "./src/Truncated.dev.js";
3
+ customElements.define("sp-truncated", Truncated);
4
+ //# sourceMappingURL=sp-truncated.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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"],
5
+ "mappings": ";AAYA,SAAS,iBAAiB;AAE1B,eAAe,OAAO,gBAAgB,SAAS;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";import{Truncated as e}from"./src/Truncated.js";customElements.define("sp-truncated",e);
2
+ //# sourceMappingURL=sp-truncated.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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"],
5
+ "mappings": "aAYA,OAAS,aAAAA,MAAiB,qBAE1B,eAAe,OAAO,eAAgBA,CAAS",
6
+ "names": ["Truncated"]
7
+ }
@@ -0,0 +1,33 @@
1
+ import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
2
+ import type { Placement } from '@spectrum-web-components/overlay';
3
+ import '@spectrum-web-components/overlay/sp-overlay.js';
4
+ import '@spectrum-web-components/tooltip/sp-tooltip.js';
5
+ /**
6
+ * @element sp-truncated
7
+ */
8
+ export declare class Truncated extends SpectrumElement {
9
+ static get styles(): CSSResultArray;
10
+ /**
11
+ * @type {"top" | "top-start" | "top-end" | "right" | "right-start" | "right-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end"}
12
+ */
13
+ placement: Placement;
14
+ successMessage: string;
15
+ hasCopied: boolean;
16
+ private fullText;
17
+ private overflowing;
18
+ private content;
19
+ private overlayEl?;
20
+ private slottedContent;
21
+ private slottedOverflow;
22
+ get hasCustomOverflow(): boolean;
23
+ private resizeObserver;
24
+ private mutationObserver;
25
+ render(): TemplateResult;
26
+ private renderTooltip;
27
+ protected firstUpdated(_changedProperties: PropertyValues<this>): void;
28
+ protected updated(changedProperties: PropertyValues<this>): void;
29
+ private handleOverflowSlotchange;
30
+ private handleClick;
31
+ private measureOverflow;
32
+ private copyText;
33
+ }
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __decorateClass = (decorators, target, key, kind) => {
5
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
6
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7
+ if (decorator = decorators[i])
8
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9
+ if (kind && result) __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import {
13
+ html,
14
+ SpectrumElement
15
+ } from "@spectrum-web-components/base";
16
+ import "@spectrum-web-components/overlay/sp-overlay.js";
17
+ import "@spectrum-web-components/tooltip/sp-tooltip.js";
18
+ import {
19
+ property,
20
+ query,
21
+ queryAssignedElements,
22
+ queryAssignedNodes,
23
+ state
24
+ } from "@spectrum-web-components/base/src/decorators.js";
25
+ import styles from "./truncated.css.js";
26
+ export class Truncated extends SpectrumElement {
27
+ constructor() {
28
+ super(...arguments);
29
+ this.placement = "top-start";
30
+ this.successMessage = "Copied to clipboard";
31
+ this.hasCopied = false;
32
+ this.fullText = "";
33
+ this.overflowing = false;
34
+ this.resizeObserver = new ResizeObserver(() => {
35
+ this.measureOverflow();
36
+ });
37
+ this.mutationObserver = new MutationObserver(() => {
38
+ this.copyText();
39
+ });
40
+ }
41
+ static get styles() {
42
+ return [styles];
43
+ }
44
+ get hasCustomOverflow() {
45
+ return this.slottedOverflow.length > 0;
46
+ }
47
+ render() {
48
+ return html`
49
+ <span id="content" @click=${this.handleClick}>
50
+ <slot></slot>
51
+ </span>
52
+ ${this.renderTooltip()}
53
+ `;
54
+ }
55
+ renderTooltip() {
56
+ if (!this.overflowing) {
57
+ return html`
58
+ <slot
59
+ name="overflow"
60
+ style="display: none"
61
+ @slotchange=${this.handleOverflowSlotchange}
62
+ ></slot>
63
+ `;
64
+ }
65
+ return html`
66
+ <sp-overlay
67
+ id="overlay"
68
+ .triggerElement=${this}
69
+ .triggerInteraction=${"hover"}
70
+ type="hint"
71
+ placement=${this.placement}
72
+ >
73
+ <sp-tooltip name="tooltip">
74
+ ${!this.hasCopied ? html`
75
+ <slot
76
+ name="overflow"
77
+ @slotchange=${this.handleOverflowSlotchange}
78
+ >
79
+ ${this.fullText}
80
+ </slot>
81
+ ` : this.successMessage}
82
+ </sp-tooltip>
83
+ </sp-overlay>
84
+ `;
85
+ }
86
+ firstUpdated(_changedProperties) {
87
+ this.resizeObserver.observe(this);
88
+ this.resizeObserver.observe(this.content);
89
+ this.copyText();
90
+ this.measureOverflow();
91
+ }
92
+ updated(changedProperties) {
93
+ super.updated(changedProperties);
94
+ if (changedProperties.has("hasCopied") && this.hasCopied && this.overlayEl) {
95
+ this.overlayEl.open = true;
96
+ }
97
+ }
98
+ handleOverflowSlotchange() {
99
+ this.mutationObserver.disconnect();
100
+ if (!this.hasCustomOverflow) {
101
+ this.mutationObserver.observe(this.content, {
102
+ subtree: true,
103
+ childList: true,
104
+ characterData: true
105
+ });
106
+ }
107
+ }
108
+ handleClick() {
109
+ if (!this.overflowing) return;
110
+ const textToCopy = this.slottedContent.map((node) => {
111
+ var _a;
112
+ return (_a = node.textContent) != null ? _a : "";
113
+ }).join("").trim();
114
+ navigator.clipboard.writeText(textToCopy);
115
+ this.hasCopied = true;
116
+ setTimeout(() => {
117
+ this.hasCopied = false;
118
+ }, 6e3);
119
+ }
120
+ measureOverflow() {
121
+ this.overflowing = this.content.offsetWidth > this.clientWidth + 1;
122
+ }
123
+ // Copies just the textContent of slotted nodes into the tooltip to avoid duplicating the user's DOM
124
+ copyText() {
125
+ if (this.hasCustomOverflow) return;
126
+ this.fullText = this.slottedContent.map((node) => {
127
+ var _a;
128
+ return (_a = node.textContent) != null ? _a : "";
129
+ }).join("");
130
+ }
131
+ }
132
+ __decorateClass([
133
+ property()
134
+ ], Truncated.prototype, "placement", 2);
135
+ __decorateClass([
136
+ property({ type: String, attribute: "success-message" })
137
+ ], Truncated.prototype, "successMessage", 2);
138
+ __decorateClass([
139
+ state()
140
+ ], Truncated.prototype, "hasCopied", 2);
141
+ __decorateClass([
142
+ state()
143
+ ], Truncated.prototype, "fullText", 2);
144
+ __decorateClass([
145
+ state()
146
+ ], Truncated.prototype, "overflowing", 2);
147
+ __decorateClass([
148
+ query("#content")
149
+ ], Truncated.prototype, "content", 2);
150
+ __decorateClass([
151
+ query("#overlay")
152
+ ], Truncated.prototype, "overlayEl", 2);
153
+ __decorateClass([
154
+ queryAssignedNodes({ flatten: true })
155
+ ], Truncated.prototype, "slottedContent", 2);
156
+ __decorateClass([
157
+ queryAssignedElements({ slot: "overflow", flatten: true })
158
+ ], Truncated.prototype, "slottedOverflow", 2);
159
+ //# sourceMappingURL=Truncated.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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"],
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,WAAW;AAAA;AAAA;AAAA,cAG1C,KAAK,cAAc,CAAC;AAAA;AAAA,EAG9B;AAAA,EAEQ,gBAA4C;AAChD,QAAI,CAAC,KAAK,aAAa;AACnB,aAAO;AAAA;AAAA;AAAA;AAAA,kCAIe,KAAK,wBAAwB;AAAA;AAAA;AAAA,IAGvD;AACA,WAAO;AAAA;AAAA;AAAA,kCAGmB,IAAmB;AAAA,sCACf,OAAO;AAAA;AAAA,4BAEjB,KAAK,SAAS;AAAA;AAAA;AAAA,sBAGpB,CAAC,KAAK,YACF;AAAA;AAAA;A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ADC,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
+ "names": []
7
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var s=(l,o,e,r)=>{for(var t=r>1?void 0:r?m(o,e):o,a=l.length-1,n;a>=0;a--)(n=l[a])&&(t=(r?n(o,e,t):n(t))||t);return r&&t&&d(o,e,t),t};import{html as i,SpectrumElement as u}from"@spectrum-web-components/base";import"@spectrum-web-components/overlay/sp-overlay.js";import"@spectrum-web-components/tooltip/sp-tooltip.js";import{property as h,query as v,queryAssignedElements as c,queryAssignedNodes as f,state as p}from"@spectrum-web-components/base/src/decorators.js";import y from"./truncated.css.js";export class Truncated extends u{constructor(){super(...arguments);this.placement="top-start";this.successMessage="Copied to clipboard";this.hasCopied=!1;this.fullText="";this.overflowing=!1;this.resizeObserver=new ResizeObserver(()=>{this.measureOverflow()});this.mutationObserver=new MutationObserver(()=>{this.copyText()})}static get styles(){return[y]}get hasCustomOverflow(){return this.slottedOverflow.length>0}render(){return i`
2
+ <span id="content" @click=${this.handleClick}>
3
+ <slot></slot>
4
+ </span>
5
+ ${this.renderTooltip()}
6
+ `}renderTooltip(){return this.overflowing?i`
7
+ <sp-overlay
8
+ id="overlay"
9
+ .triggerElement=${this}
10
+ .triggerInteraction=${"hover"}
11
+ type="hint"
12
+ placement=${this.placement}
13
+ >
14
+ <sp-tooltip name="tooltip">
15
+ ${this.hasCopied?this.successMessage:i`
16
+ <slot
17
+ name="overflow"
18
+ @slotchange=${this.handleOverflowSlotchange}
19
+ >
20
+ ${this.fullText}
21
+ </slot>
22
+ `}
23
+ </sp-tooltip>
24
+ </sp-overlay>
25
+ `:i`
26
+ <slot
27
+ name="overflow"
28
+ style="display: none"
29
+ @slotchange=${this.handleOverflowSlotchange}
30
+ ></slot>
31
+ `}firstUpdated(e){this.resizeObserver.observe(this),this.resizeObserver.observe(this.content),this.copyText(),this.measureOverflow()}updated(e){super.updated(e),e.has("hasCopied")&&this.hasCopied&&this.overlayEl&&(this.overlayEl.open=!0)}handleOverflowSlotchange(){this.mutationObserver.disconnect(),this.hasCustomOverflow||this.mutationObserver.observe(this.content,{subtree:!0,childList:!0,characterData:!0})}handleClick(){if(!this.overflowing)return;const e=this.slottedContent.map(r=>{var t;return(t=r.textContent)!=null?t:""}).join("").trim();navigator.clipboard.writeText(e),this.hasCopied=!0,setTimeout(()=>{this.hasCopied=!1},6e3)}measureOverflow(){this.overflowing=this.content.offsetWidth>this.clientWidth+1}copyText(){this.hasCustomOverflow||(this.fullText=this.slottedContent.map(e=>{var r;return(r=e.textContent)!=null?r:""}).join(""))}}s([h()],Truncated.prototype,"placement",2),s([h({type:String,attribute:"success-message"})],Truncated.prototype,"successMessage",2),s([p()],Truncated.prototype,"hasCopied",2),s([p()],Truncated.prototype,"fullText",2),s([p()],Truncated.prototype,"overflowing",2),s([v("#content")],Truncated.prototype,"content",2),s([v("#overlay")],Truncated.prototype,"overlayEl",2),s([f({flatten:!0})],Truncated.prototype,"slottedContent",2),s([c({slot:"overflow",flatten:!0})],Truncated.prototype,"slottedOverflow",2);
32
+ //# sourceMappingURL=Truncated.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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"],
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;AAAA;AAAA,oCAEzC,KAAK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AGQO,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
+ "names": ["html", "SpectrumElement", "property", "query", "queryAssignedElements", "queryAssignedNodes", "state", "styles", "_changedProperties", "changedProperties", "textToCopy", "node", "_a", "__decorateClass"]
7
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './Truncated.js';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ export * from "./Truncated.dev.js";
3
+ //# sourceMappingURL=index.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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"],
5
+ "mappings": ";AAWA,cAAc;",
6
+ "names": []
7
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";export*from"./Truncated.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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"],
5
+ "mappings": "aAWA,WAAc",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ declare const styles: import("@spectrum-web-components/base").CSSResult;
2
+ export default styles;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ import { css } from "@spectrum-web-components/base";
3
+ const styles = css`
4
+ :host{min-width:0;max-width:100%;white-space:nowrap;text-overflow:ellipsis;display:inline-block;overflow:hidden}
5
+ `;
6
+ export default styles;
7
+ //# sourceMappingURL=truncated.css.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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;"],
5
+ "mappings": ";AAWA,SAAS,WAAW;AACpB,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
6
+ "names": []
7
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";import{css as e}from"@spectrum-web-components/base";const i=e`
2
+ :host{min-width:0;max-width:100%;white-space:nowrap;text-overflow:ellipsis;display:inline-block;overflow:hidden}
3
+ `;export default i;
4
+ //# sourceMappingURL=truncated.css.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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;"],
5
+ "mappings": "aAWA,OAAS,OAAAA,MAAW,gCACpB,MAAMC,EAASD;AAAA;AAAA,EAGf,eAAeC",
6
+ "names": ["css", "styles"]
7
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ import { html } from "@spectrum-web-components/base";
3
+ import "../sp-truncated.js";
4
+ const Dog = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAspBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAAyADIDASIAAhEBAxEB/8QAHAAAAgIDAQEAAAAAAAAAAAAAAAcFCAMEBgIJ/8QAMhAAAgEDBAEBBgYABwAAAAAAAQIDBAURAAYSITEHEyJBUWGBFBUjMnGhCCU1QmKisf/EABkBAAMBAQEAAAAAAAAAAAAAAAMEBQIGAf/EACoRAAICAAMHAwUBAAAA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920gpalIZZIlZHftSx8D+8arts66xbv3beLFUpBFVUE0sdX7dVxD7NirZJOMch0frrjbhvK5VE8Iot61Vtio0RY6aCjVlXjkoSpYYx5HWNczW2e3124btfpd03SnrbpwNU9FBGgbgFxhWZgP2g+PPeqL31vmwz94pXsrpkDr6S59o29Y9p2eoijlgo5qoiNZKciKVip59Fck4yTj/l9dRz7krbWGSpm/NqRcKs0aFahBjsuv8Av/le/pqtm0tx0ez7cYjuK83andhKkdUqHDAceWfJJHnJ7+wxmuvrbSqrLHBUP0R2qdfXsHU67F2xXACNV1FBhmY85fU7bcUro13iRlYgqzEEHPgg9jRqsTeuKcm/y1z35Pse/wDro0vwt3ENyz2iltrt+EzyPw+Op+2uzA5YnKjOT/OjRoo0jXWbZRVZiAAWPZA86xVk8kdSeMjr+zwxHnlnRo1hpoaTetsryUhDOzAeATnUTe2IY9nyR5/nRo0NZ71kYigqCQPHy0aNGgxif//Z";
5
+ export default {
6
+ title: "Truncated",
7
+ component: "sp-truncated"
8
+ };
9
+ export const Default = () => {
10
+ return html`
11
+ <p
12
+ style="width: 200px; color: #000; border: solid 1px #ccc; overflow: hidden; resize: both;"
13
+ >
14
+ <sp-truncated>
15
+ This is a
16
+ <strong>very long</strong>
17
+ 🦋 sentence that 🦋 should be truncated
18
+ </sp-truncated>
19
+ <sp-truncated>
20
+ ThisIsAVeryLongWordThatShouldBeTruncated
21
+ </sp-truncated>
22
+ <sp-truncated>
23
+ We can even
24
+ <img src=${Dog} alt="kitten" />
25
+ truncate around a picture
26
+ </sp-truncated>
27
+ <sp-truncated>
28
+ Custom overflow content can also be provided for the tooltip
29
+ <span slot="overflow">
30
+ <span style="font-size: 24px;">Like this!</span>
31
+ </span>
32
+ </sp-truncated>
33
+ <sp-truncated placement="right">
34
+ Alternative placements can be specified
35
+ </sp-truncated>
36
+ <sp-truncated>Should have no tooltip</sp-truncated>
37
+ </p>
38
+ `;
39
+ };
40
+ //# sourceMappingURL=truncated.stories.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["truncated.stories.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 { html, TemplateResult } from '@spectrum-web-components/base';\nimport '../sp-truncated.js';\n\nconst Dog =\n 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAspBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAAyADIDASIAAhEBAxEB/8QAHAAAAgIDAQEAAAAAAAAAAAAAAAcFCAMEBgIJ/8QAMhAAAgEDBAEBBgYABwAAAAAAAQIDBAURAAYSITEHEyJBUWGBFBUjMnGhCCU1QmKisf/EABkBAAMBAQEAAAAAAAAAAAAAAAMEBQIGAf/EACoRAAICAAMHAwUBAAAAAAAAAAECAAMRITEEBRITQVGhYXHwFBUiY5Gx/9oADAMBAAIRAxEAPwD6b0VwFTIQYXUD4ka3I5AwOAcZ+OldD6+2H9BI6iB5JDjgHGdbq+uu3BKEkqUhfOG5Hr7agV7y2XTmgwmUZI4YyM68kjj40urr6x0dMjR0UXt5mAKs59zB7z0e9chQ+sNw3JE1TR1oSBWZAY4woYqxBODk+R/WriVs6gjrF3uRNY8SyY94gfLUfcHqWXjTFQR5JOk5UeodfDVwQT1rNLNyaMMAOZAyQCB5x3j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UP0R2qdfXsHU67F2xXACNV1FBhmY85fU7bcUro13iRlYgqzEEHPgg9jRqsTeuKcm/y1z35Pse/wDro0vwt3ENyz2iltrt+EzyPw+Op+2uzA5YnKjOT/OjRoo0jXWbZRVZiAAWPZA86xVk8kdSeMjr+zwxHnlnRo1hpoaTetsryUhDOzAeATnUTe2IY9nyR5/nRo0NZ71kYigqCQPHy0aNGgxif//Z';\n\nexport default {\n title: 'Truncated',\n component: 'sp-truncated',\n};\n\nexport const Default = (): TemplateResult => {\n return html`\n <p\n style=\"width: 200px; color: #000; border: solid 1px #ccc; overflow: hidden; resize: both;\"\n >\n <sp-truncated>\n This is a\n <strong>very long</strong>\n \uD83E\uDD8B sentence that \uD83E\uDD8B should be truncated\n </sp-truncated>\n <sp-truncated>\n ThisIsAVeryLongWordThatShouldBeTruncated\n </sp-truncated>\n <sp-truncated>\n We can even\n <img src=${Dog} alt=\"kitten\" />\n truncate around a picture\n </sp-truncated>\n <sp-truncated>\n Custom overflow content can also be provided for the tooltip\n <span slot=\"overflow\">\n <span style=\"font-size: 24px;\">Like this!</span>\n </span>\n </sp-truncated>\n <sp-truncated placement=\"right\">\n Alternative placements can be specified\n </sp-truncated>\n <sp-truncated>Should have no tooltip</sp-truncated>\n </p>\n `;\n};\n"],
5
+ "mappings": ";AAYA,SAAS,YAA4B;AACrC,OAAO;AAEP,MAAM,MACF;AAEJ,eAAe;AAAA,EACX,OAAO;AAAA,EACP,WAAW;AACf;AAEO,aAAM,UAAU,MAAsB;AACzC,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAcgB,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAe9B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ import "@spectrum-web-components/truncated/sp-truncated.js";
3
+ import { html } from "@spectrum-web-components/base";
4
+ import { measureFixtureCreation } from "../../../../test/benchmark/helpers.js";
5
+ measureFixtureCreation(html`
6
+ <p style="width: 200px">
7
+ <sp-truncated>
8
+ This is a very long text that will overflow into a tooltip with the
9
+ help of sp-truncated.
10
+ </sp-truncated>
11
+ </p>
12
+ `);
13
+ //# sourceMappingURL=basic-test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["basic-test.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*/\nimport '@spectrum-web-components/truncated/sp-truncated.js';\nimport { html } from '@spectrum-web-components/base';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <p style=\"width: 200px\">\n <sp-truncated>\n This is a very long text that will overflow into a tooltip with the\n help of sp-truncated.\n </sp-truncated>\n </p>\n`);\n"],
5
+ "mappings": ";AAWA,OAAO;AACP,SAAS,YAAY;AACrB,SAAS,8BAA8B;AAEvC,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAOtB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ import * as stories from "../stories/truncated.stories.js";
3
+ import { regressVisuals } from "../../../test/visual/test.js";
4
+ regressVisuals("TruncatedStories", stories);
5
+ //# sourceMappingURL=truncated.test-vrt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["truncated.test-vrt.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/truncated.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\nimport type { TestsType } from '../../../test/visual/test.js';\n\nregressVisuals('TruncatedStories', stories as unknown as TestsType);\n"],
5
+ "mappings": ";AAYA,YAAY,aAAa;AACzB,SAAS,sBAAsB;AAG/B,eAAe,oBAAoB,OAA+B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ import { expect, fixture, html, oneEvent } from "@open-wc/testing";
3
+ import { sendMouse } from "@web/test-runner-commands";
4
+ import "../sp-truncated.js";
5
+ describe("Truncated", () => {
6
+ it("loads default truncated accessibly", async () => {
7
+ const el = await fixture(
8
+ html`
9
+ <sp-truncated></sp-truncated>
10
+ `
11
+ );
12
+ await expect(el).to.be.accessible();
13
+ });
14
+ it("renders a tooltip when overflowing", async () => {
15
+ const p = await fixture(html`
16
+ <p style="width: 20px">
17
+ <sp-truncated>This will overflow into a tooltip</sp-truncated>
18
+ </p>
19
+ `);
20
+ const el = p.querySelector("sp-truncated");
21
+ const tooltip = el.shadowRoot.querySelector("sp-tooltip");
22
+ const rect = el.getBoundingClientRect();
23
+ await sendMouse({
24
+ type: "move",
25
+ position: [Math.round(rect.left + 2), Math.round(rect.top + 2)]
26
+ });
27
+ const opened = oneEvent(el, "sp-opened");
28
+ await opened;
29
+ expect(tooltip.open).to.be.true;
30
+ });
31
+ it("does not render a tooltip when content fits", async () => {
32
+ const p = await fixture(html`
33
+ <p style="width: 200px">
34
+ <sp-truncated>Short</sp-truncated>
35
+ </p>
36
+ `);
37
+ const el = p.querySelector("sp-truncated");
38
+ const tooltip = el.shadowRoot.querySelector(
39
+ "sp-tooltip"
40
+ );
41
+ const rect = el.getBoundingClientRect();
42
+ await sendMouse({
43
+ type: "move",
44
+ position: [Math.round(rect.left + 2), Math.round(rect.top + 2)]
45
+ });
46
+ expect(tooltip).to.be.null;
47
+ });
48
+ it("detects whether or not custom overflow is specified for optimization", async () => {
49
+ const defaultOverflow = await fixture(
50
+ html`
51
+ <sp-truncated>This will overflow into a tooltip</sp-truncated>
52
+ `
53
+ );
54
+ const customOverflow = await fixture(
55
+ html`
56
+ <sp-truncated>
57
+ Default
58
+ <span slot="overflow">Custom</span>
59
+ </sp-truncated>
60
+ `
61
+ );
62
+ expect(defaultOverflow.hasCustomOverflow).to.be.false;
63
+ expect(customOverflow.hasCustomOverflow).to.be.true;
64
+ });
65
+ it("copies the text when clicked", async () => {
66
+ const text = "This will overflow into a tooltiptooltiptooltiptooltipmtooltipv tooltip tooltiptooltip";
67
+ const defaultOverflow = await fixture(
68
+ html`
69
+ <p style="width: 200px">
70
+ <sp-truncated>${text}</sp-truncated>
71
+ </p>
72
+ `
73
+ );
74
+ const truncated = defaultOverflow.querySelector("sp-truncated");
75
+ const content = truncated == null ? void 0 : truncated.shadowRoot.querySelector(
76
+ "#content"
77
+ );
78
+ content.click();
79
+ expect(truncated == null ? void 0 : truncated.hasCopied).to.be.true;
80
+ });
81
+ });
82
+ //# sourceMappingURL=truncated.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["truncated.test.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*/\nimport { expect, fixture, html, oneEvent } from '@open-wc/testing';\nimport { Tooltip } from '@spectrum-web-components/tooltip/src/Tooltip.js';\nimport { sendMouse } from '@web/test-runner-commands';\n\nimport { Truncated } from '../src/index.js';\nimport '../sp-truncated.js';\n\ndescribe('Truncated', () => {\n it('loads default truncated accessibly', async () => {\n const el = await fixture<Truncated>(\n html`\n <sp-truncated></sp-truncated>\n `\n );\n\n await expect(el).to.be.accessible();\n });\n it('renders a tooltip when overflowing', async () => {\n const p = await fixture(html`\n <p style=\"width: 20px\">\n <sp-truncated>This will overflow into a tooltip</sp-truncated>\n </p>\n `);\n const el = p.querySelector('sp-truncated') as Truncated;\n const tooltip = el.shadowRoot!.querySelector('sp-tooltip') as Tooltip;\n const rect = el.getBoundingClientRect();\n\n await sendMouse({\n type: 'move',\n position: [Math.round(rect.left + 2), Math.round(rect.top + 2)],\n });\n const opened = oneEvent(el, 'sp-opened');\n\n await opened;\n expect(tooltip.open).to.be.true;\n });\n it('does not render a tooltip when content fits', async () => {\n const p = await fixture(html`\n <p style=\"width: 200px\">\n <sp-truncated>Short</sp-truncated>\n </p>\n `);\n const el = p.querySelector('sp-truncated') as Truncated;\n const tooltip = el.shadowRoot!.querySelector(\n 'sp-tooltip'\n ) as Tooltip | null;\n const rect = el.getBoundingClientRect();\n await sendMouse({\n type: 'move',\n position: [Math.round(rect.left + 2), Math.round(rect.top + 2)],\n });\n\n expect(tooltip).to.be.null;\n });\n it('detects whether or not custom overflow is specified for optimization', async () => {\n const defaultOverflow = await fixture<Truncated>(\n html`\n <sp-truncated>This will overflow into a tooltip</sp-truncated>\n `\n );\n const customOverflow = await fixture<Truncated>(\n html`\n <sp-truncated>\n Default\n <span slot=\"overflow\">Custom</span>\n </sp-truncated>\n `\n );\n\n expect(defaultOverflow.hasCustomOverflow).to.be.false;\n expect(customOverflow.hasCustomOverflow).to.be.true;\n });\n it('copies the text when clicked', async () => {\n const text =\n 'This will overflow into a tooltiptooltiptooltiptooltipmtooltipv tooltip tooltiptooltip';\n\n const defaultOverflow = await fixture<Truncated>(\n html`\n <p style=\"width: 200px\">\n <sp-truncated>${text}</sp-truncated>\n </p>\n `\n );\n\n const truncated = defaultOverflow.querySelector('sp-truncated');\n const content = truncated?.shadowRoot.querySelector(\n '#content'\n ) as Truncated;\n content.click();\n expect(truncated?.hasCopied).to.be.true;\n });\n});\n"],
5
+ "mappings": ";AAWA,SAAS,QAAQ,SAAS,MAAM,gBAAgB;AAEhD,SAAS,iBAAiB;AAG1B,OAAO;AAEP,SAAS,aAAa,MAAM;AACxB,KAAG,sCAAsC,YAAY;AACjD,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;AAAA,IAGJ;AAEA,UAAM,OAAO,EAAE,EAAE,GAAG,GAAG,WAAW;AAAA,EACtC,CAAC;AACD,KAAG,sCAAsC,YAAY;AACjD,UAAM,IAAI,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA,SAIvB;AACD,UAAM,KAAK,EAAE,cAAc,cAAc;AACzC,UAAM,UAAU,GAAG,WAAY,cAAc,YAAY;AACzD,UAAM,OAAO,GAAG,sBAAsB;AAEtC,UAAM,UAAU;AAAA,MACZ,MAAM;AAAA,MACN,UAAU,CAAC,KAAK,MAAM,KAAK,OAAO,CAAC,GAAG,KAAK,MAAM,KAAK,MAAM,CAAC,CAAC;AAAA,IAClE,CAAC;AACD,UAAM,SAAS,SAAS,IAAI,WAAW;AAEvC,UAAM;AACN,WAAO,QAAQ,IAAI,EAAE,GAAG,GAAG;AAAA,EAC/B,CAAC;AACD,KAAG,+CAA+C,YAAY;AAC1D,UAAM,IAAI,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA,SAIvB;AACD,UAAM,KAAK,EAAE,cAAc,cAAc;AACzC,UAAM,UAAU,GAAG,WAAY;AAAA,MAC3B;AAAA,IACJ;AACA,UAAM,OAAO,GAAG,sBAAsB;AACtC,UAAM,UAAU;AAAA,MACZ,MAAM;AAAA,MACN,UAAU,CAAC,KAA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