@cas-smartdesign/list-item 7.3.0 → 7.4.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.
@@ -1,22 +1,22 @@
1
- import { LitElement as m, unsafeCSS as v, css as g, html as a, nothing as f } from "lit";
2
- import { property as n } from "lit/decorators/property.js";
3
- import { unsafeHTML as b } from "lit/directives/unsafe-html.js";
1
+ import { LitElement as m, unsafeCSS as v, css as b, html as a, nothing as f } from "lit";
2
+ import { property as o } from "lit/decorators/property.js";
3
+ import { unsafeHTML as g } from "lit/directives/unsafe-html.js";
4
4
  import { ifDefined as d } from "lit/directives/if-defined.js";
5
- import y from "@cas-smartdesign/image-tools";
6
- const w = ':host{display:block;contain:strict;height:50px}:host([selected]){background-color:#d3e6fa}:host(:not([selected]):hover),:host(:not([selected])[focused]){background-color:#e7f1fa}@media (forced-colors: active){:host([selected]){outline:4px solid}:host(:not([selected]):hover){outline:4px dotted}:host(:not([selected])[focused]){outline:4px dashed}}:host([enable-line-clamp]) .labels>:only-child{display:-webkit-box;overflow:hidden;-webkit-line-clamp:2;-webkit-box-orient:vertical;white-space:normal;overflow-wrap:break-word}.container{display:flex;height:100%;box-sizing:border-box}.container .level-indicator{width:7px;height:100%}.container .level-indicator.level-0{background-color:#a0c3ef}.container .level-indicator.level-1{background-color:#e7c374}.container .level-indicator.level-2{background-color:#bfd596}.container .level-indicator.level-3{background-color:#fd998d}.container .level-indicator.level-4{background-color:#c6e8f5}.container .level-indicator.level-5{background-color:#fde3a4}.container .level-indicator.level-6{background-color:#dcbfe0}.side-content{display:flex;align-items:center;flex-grow:0}.labels{display:flex;flex-direction:column;justify-content:center;flex:1 1 0px;height:100%;line-height:normal;overflow:hidden;padding:var(--sd-list-item-label-content-padding, 0 8px)}.caption,.description{width:100%;font-family:var(--sd-list-item-font-family, "Segoe UI", "Lucida Sans", Arial, sans-serif);font-style:normal;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;-webkit-user-select:none;user-select:none;text-decoration:var(--sd-list-item-text-decoration, inherit)}.caption em,.description em{font-weight:bolder}.caption{font-size:var(--sd-list-item-caption-font-size, 16px);color:var(--sd-list-item-caption-text-color, #111);font-weight:var(--sd-list-item-caption-font-weight, normal)}.description{font-size:var(--sd-list-item-description-font-size, 13px);color:var(--sd-list-item-description-text-color, #767676);font-weight:var(--sd-list-item-description-font-weight, normal)}.icon-wrapper{width:var(--sd-list-item-icon-wrapper-width, 45px);height:100%;display:flex;align-items:center;justify-content:center}.icon-wrapper .icon{min-height:var(--sd-list-item-icon-size, 24px);min-width:var(--sd-list-item-icon-size, 24px);background-repeat:no-repeat;background-position:center;background-size:cover}';
7
- var x = Object.defineProperty, r = (t, i, e, l) => {
5
+ import { placeholderDirective as y } from "@cas-smartdesign/image-tools";
6
+ const x = ':host{display:block;contain:strict;height:50px}:host([selected]){background-color:#d3e6fa}:host(:not([selected]):hover),:host(:not([selected])[focused]){background-color:#e7f1fa}@media (forced-colors: active){:host([selected]){outline:4px solid}:host(:not([selected]):hover){outline:4px dotted}:host(:not([selected])[focused]){outline:4px dashed}}:host([enable-line-clamp]) .labels>:only-child{display:-webkit-box;overflow:hidden;-webkit-line-clamp:2;-webkit-box-orient:vertical;white-space:normal;overflow-wrap:break-word}.container{display:flex;height:100%;box-sizing:border-box}.container .level-indicator{width:7px;height:100%}.container .level-indicator.level-0{background-color:#a0c3ef}.container .level-indicator.level-1{background-color:#e7c374}.container .level-indicator.level-2{background-color:#bfd596}.container .level-indicator.level-3{background-color:#fd998d}.container .level-indicator.level-4{background-color:#c6e8f5}.container .level-indicator.level-5{background-color:#fde3a4}.container .level-indicator.level-6{background-color:#dcbfe0}.side-content{display:flex;align-items:center;flex-grow:0}.labels{display:flex;flex-direction:column;justify-content:center;flex:1 1 0px;height:100%;line-height:normal;overflow:hidden;padding:var(--sd-list-item-label-content-padding, 0 8px)}.caption,.description{width:100%;font-family:var(--sd-list-item-font-family, "Segoe UI", "Lucida Sans", Arial, sans-serif);font-style:normal;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;-webkit-user-select:none;user-select:none;text-decoration:var(--sd-list-item-text-decoration, inherit)}.caption em,.description em{font-weight:bolder}.caption{font-size:var(--sd-list-item-caption-font-size, 16px);color:var(--sd-list-item-caption-text-color, #111);font-weight:var(--sd-list-item-caption-font-weight, normal)}.description{font-size:var(--sd-list-item-description-font-size, 13px);color:var(--sd-list-item-description-text-color, #767676);font-weight:var(--sd-list-item-description-font-weight, normal)}.icon-wrapper{width:var(--sd-list-item-icon-wrapper-width, 45px);height:100%;display:flex;align-items:center;justify-content:center}.icon-wrapper .icon{min-height:var(--sd-list-item-icon-size, 24px);min-width:var(--sd-list-item-icon-size, 24px);background-repeat:no-repeat;background-position:center;background-size:cover}';
7
+ var w = Object.defineProperty, n = (t, r, e, l) => {
8
8
  for (var c = void 0, p = t.length - 1, h; p >= 0; p--)
9
- (h = t[p]) && (c = h(i, e, c) || c);
10
- return c && x(i, e, c), c;
9
+ (h = t[p]) && (c = h(r, e, c) || c);
10
+ return c && w(r, e, c), c;
11
11
  }, s;
12
- const o = (s = class extends m {
12
+ const i = (s = class extends m {
13
13
  constructor() {
14
14
  super(...arguments), this.contentMode = "text", this.role = "option";
15
15
  }
16
16
  static get styles() {
17
17
  return [
18
- g`
19
- ${v(w)}
18
+ b`
19
+ ${v(x)}
20
20
  `
21
21
  ];
22
22
  }
@@ -24,7 +24,7 @@ const o = (s = class extends m {
24
24
  return a`
25
25
  <div class="container">
26
26
  ${this.getLevelIndicators().map(
27
- (i, e) => a` <div class="level-indicator level-${e}"></div> `
27
+ (r, e) => a` <div class="level-indicator level-${e}"></div> `
28
28
  )}
29
29
  <div class="side-content">
30
30
  <slot name="left-content"></slot>
@@ -41,47 +41,41 @@ const o = (s = class extends m {
41
41
  `;
42
42
  }
43
43
  renderIcon() {
44
- if (this.icon || this.iconPlaceholder) {
45
- const i = this.iconBackgroundColor != null ? `background-color:${this.iconBackgroundColor}` : void 0;
46
- return a`
47
- <div
48
- class="icon-wrapper"
49
- @pointerdown="${this.handleIconClick}"
50
- style="${d(i)}"
51
- role="img"
52
- aria-label="${d(this.iconAttrAriaLabel)}"
53
- title="${d(this.iconAttrTitle)}"
54
- >
55
- <div class="icon"></div>
56
- </div>
57
- `;
58
- }
59
- return f;
44
+ return this.icon || this.iconPlaceholder ? a`<div
45
+ class="icon-wrapper"
46
+ @pointerdown="${this.handleIconClick}"
47
+ style="background-color:${d(this.iconBackgroundColor)};"
48
+ role="img"
49
+ aria-label="${d(this.iconAttrAriaLabel)}"
50
+ title="${d(this.iconAttrTitle)}"
51
+ >
52
+ <div class="icon" style="background-image:${y(this.icon, this.iconPlaceholder)}"></div>
53
+ </div> ` : f;
60
54
  }
61
- renderLabel(i, e, l) {
55
+ renderLabel(r, e, l) {
62
56
  return e ? a`
63
- <div class="${i}" title="${d(l)}">
64
- ${this.contentMode === "html" ? b(e) : e}
57
+ <div class="${r}" title="${d(l)}">
58
+ ${this.contentMode === "html" ? g(e) : e}
65
59
  </div>
66
60
  ` : f;
67
61
  }
68
- updated(i) {
69
- super.updated(i), (i.has("icon") || i.has("iconPlaceholder")) && (this.icon || this.iconPlaceholder) && y.showImage(this.shadowRoot.querySelector(".icon"), this.icon, this.iconPlaceholder), i.has("selected") && this.setAttribute("aria-selected", String(this.selected));
62
+ updated(r) {
63
+ super.updated(r), r.has("selected") && this.setAttribute("aria-selected", String(this.selected));
70
64
  }
71
65
  /**
72
66
  * Returns the width in pixel which is missing to show the caption and description without ellipsis.
73
67
  */
74
68
  get missingWidthForTexts() {
75
- const i = this.enableLineClamp;
69
+ const r = this.enableLineClamp;
76
70
  this.removeAttribute("enable-line-clamp");
77
71
  let e = 0;
78
72
  const l = this.shadowRoot.querySelector(".caption");
79
73
  l && (e += l.scrollWidth - l.clientWidth);
80
74
  const c = this.shadowRoot.querySelector(".description");
81
- return c && (e = Math.max(e, c.scrollWidth - c.clientWidth)), e > 0 && e++, i && this.setAttribute("enable-line-clamp", ""), e;
75
+ return c && (e = Math.max(e, c.scrollWidth - c.clientWidth)), e > 0 && e++, r && this.setAttribute("enable-line-clamp", ""), e;
82
76
  }
83
- handleIconClick(i) {
84
- !this.disabled && !this.dispatchEvent(new PointerEvent("list-item-icon-click", i)) && i.preventDefault();
77
+ handleIconClick(r) {
78
+ !this.disabled && !this.dispatchEvent(new PointerEvent("list-item-icon-click", r)) && r.preventDefault();
85
79
  }
86
80
  getLevelIndicators() {
87
81
  return this.level ? Array(Number(this.level)).fill(null) : [];
@@ -89,35 +83,35 @@ const o = (s = class extends m {
89
83
  }, s.ID = "sd-list-item", s.ensureDefined = () => {
90
84
  customElements.get(s.ID) || customElements.define(s.ID, s);
91
85
  }, s);
92
- r([
93
- n({ type: String })
94
- ], o.prototype, "caption");
95
- r([
96
- n({ type: String })
97
- ], o.prototype, "description");
98
- r([
99
- n({ type: Boolean })
100
- ], o.prototype, "selected");
101
- r([
102
- n({ type: String })
103
- ], o.prototype, "icon");
104
- r([
105
- n({ type: String })
106
- ], o.prototype, "iconBackgroundColor");
107
- r([
108
- n({ type: String })
109
- ], o.prototype, "iconPlaceholder");
110
- r([
111
- n({ type: Number })
112
- ], o.prototype, "level");
113
- r([
114
- n()
115
- ], o.prototype, "contentMode");
116
- r([
117
- n({ type: Boolean, reflect: !0, attribute: "enable-line-clamp" })
118
- ], o.prototype, "enableLineClamp");
119
- r([
120
- n({
86
+ n([
87
+ o({ type: String })
88
+ ], i.prototype, "caption");
89
+ n([
90
+ o({ type: String })
91
+ ], i.prototype, "description");
92
+ n([
93
+ o({ type: Boolean })
94
+ ], i.prototype, "selected");
95
+ n([
96
+ o({ type: String })
97
+ ], i.prototype, "icon");
98
+ n([
99
+ o({ type: String })
100
+ ], i.prototype, "iconBackgroundColor");
101
+ n([
102
+ o({ type: String })
103
+ ], i.prototype, "iconPlaceholder");
104
+ n([
105
+ o({ type: Number })
106
+ ], i.prototype, "level");
107
+ n([
108
+ o()
109
+ ], i.prototype, "contentMode");
110
+ n([
111
+ o({ type: Boolean, reflect: !0, attribute: "enable-line-clamp" })
112
+ ], i.prototype, "enableLineClamp");
113
+ n([
114
+ o({
121
115
  converter: {
122
116
  fromAttribute: (t) => t == "true",
123
117
  toAttribute: (t) => t
@@ -125,24 +119,24 @@ r([
125
119
  reflect: !0,
126
120
  attribute: "aria-disabled"
127
121
  })
128
- ], o.prototype, "disabled");
129
- r([
130
- n({ type: String, attribute: "icon-attr-aria-label" })
131
- ], o.prototype, "iconAttrAriaLabel");
132
- r([
133
- n({ type: String, reflect: !0 })
134
- ], o.prototype, "role");
135
- r([
136
- n({ type: String, attribute: "caption-attr-title" })
137
- ], o.prototype, "captionAttrTitle");
138
- r([
139
- n({ type: String, attribute: "description-attr-title" })
140
- ], o.prototype, "descriptionAttrTitle");
141
- r([
142
- n({ type: String, attribute: "icon-attr-title" })
143
- ], o.prototype, "iconAttrTitle");
144
- let u = o;
145
- const L = (t, i) => {
122
+ ], i.prototype, "disabled");
123
+ n([
124
+ o({ type: String, attribute: "icon-attr-aria-label" })
125
+ ], i.prototype, "iconAttrAriaLabel");
126
+ n([
127
+ o({ type: String, reflect: !0 })
128
+ ], i.prototype, "role");
129
+ n([
130
+ o({ type: String, attribute: "caption-attr-title" })
131
+ ], i.prototype, "captionAttrTitle");
132
+ n([
133
+ o({ type: String, attribute: "description-attr-title" })
134
+ ], i.prototype, "descriptionAttrTitle");
135
+ n([
136
+ o({ type: String, attribute: "icon-attr-title" })
137
+ ], i.prototype, "iconAttrTitle");
138
+ let u = i;
139
+ const $ = (t, r) => {
146
140
  const e = document.createElement(u.ID);
147
141
  if (t) {
148
142
  if (e.caption = t.caption, e.description = t.description, e.icon = t.icon, e.iconBackgroundColor = t.iconBackgroundColor, e.iconPlaceholder = t.iconPlaceholder, e.level = t.level, e.disabled = t.disabled, t.contentMode && (e.contentMode = t.contentMode), t.leftContentGenerator) {
@@ -159,6 +153,6 @@ const L = (t, i) => {
159
153
  u.ensureDefined();
160
154
  export {
161
155
  u as default,
162
- L as generator
156
+ $ as generator
163
157
  };
164
158
  //# sourceMappingURL=list-item.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"list-item.mjs","sources":["../list-item.ts"],"sourcesContent":["import { LitElement, html, unsafeCSS, PropertyValues, css, nothing, TemplateResult } from \"lit\";\nimport { property } from \"lit/decorators/property.js\";\nimport { unsafeHTML } from \"lit/directives/unsafe-html.js\";\nimport { ifDefined } from \"lit/directives/if-defined.js\";\nimport ImageTools from \"@cas-smartdesign/image-tools\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n [ListItem.ID]: ListItem;\n }\n}\n\nimport styles from \"./styles.scss?inline\";\n\nexport interface ItemData {\n caption?: string;\n description?: string;\n leftContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;\n rightContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;\n icon?: string;\n iconBackgroundColor?: string;\n iconPlaceholder?: string;\n level?: number;\n contentMode?: ContentMode;\n disabled?: boolean;\n}\n\nexport type ContentMode = \"text\" | \"html\";\n\nexport default class ListItem extends LitElement {\n public static readonly ID = \"sd-list-item\";\n public static ensureDefined = (): void => {\n if (!customElements.get(ListItem.ID)) {\n customElements.define(ListItem.ID, ListItem);\n }\n };\n\n @property({ type: String })\n public caption: string;\n @property({ type: String })\n public description: string;\n @property({ type: Boolean })\n public selected: boolean;\n @property({ type: String })\n public icon: string;\n @property({ type: String })\n public iconBackgroundColor: string;\n @property({ type: String })\n public iconPlaceholder: string;\n @property({ type: Number })\n public level: number;\n @property()\n public contentMode: ContentMode = \"text\";\n @property({ type: Boolean, reflect: true, attribute: \"enable-line-clamp\" })\n public enableLineClamp: boolean;\n @property({\n converter: {\n fromAttribute: (value) => value == \"true\",\n toAttribute: (value) => value,\n },\n reflect: true,\n attribute: \"aria-disabled\",\n })\n public disabled: boolean;\n\n // aria attributes\n @property({ type: String, attribute: \"icon-attr-aria-label\" })\n public iconAttrAriaLabel: string;\n @property({ type: String, reflect: true })\n public role = \"option\";\n\n // title attributes\n @property({ type: String, attribute: \"caption-attr-title\" })\n public captionAttrTitle: string;\n @property({ type: String, attribute: \"description-attr-title\" })\n public descriptionAttrTitle: string;\n @property({ type: String, attribute: \"icon-attr-title\" })\n public iconAttrTitle: string;\n\n static get styles() {\n return [\n css`\n ${unsafeCSS(styles)}\n `,\n ];\n }\n\n public render(): TemplateResult {\n return html`\n <div class=\"container\">\n ${this.getLevelIndicators().map(\n (_, level) => html` <div class=\"level-indicator level-${level}\"></div> `,\n )}\n <div class=\"side-content\">\n <slot name=\"left-content\"></slot>\n ${this.renderIcon()}\n </div>\n <div class=\"labels\">\n ${this.renderLabel(\"caption\", this.caption, this.captionAttrTitle)}\n ${this.renderLabel(\"description\", this.description, this.descriptionAttrTitle)}\n </div>\n <div class=\"side-content\">\n <slot name=\"right-content\"></slot>\n </div>\n </div>\n `;\n }\n\n private renderIcon() {\n if (this.icon || this.iconPlaceholder) {\n const iconBackgroundStyle =\n this.iconBackgroundColor != null ? `background-color:${this.iconBackgroundColor}` : undefined;\n return html`\n <div\n class=\"icon-wrapper\"\n @pointerdown=\"${this.handleIconClick}\"\n style=\"${ifDefined(iconBackgroundStyle)}\"\n role=\"img\"\n aria-label=\"${ifDefined(this.iconAttrAriaLabel)}\"\n title=\"${ifDefined(this.iconAttrTitle)}\"\n >\n <div class=\"icon\"></div>\n </div>\n `;\n }\n return nothing;\n }\n\n private renderLabel(className: string, value: string, title: string) {\n return value\n ? html`\n <div class=\"${className}\" title=\"${ifDefined(title)}\">\n ${this.contentMode === \"html\" ? unsafeHTML(value) : value}\n </div>\n `\n : nothing;\n }\n\n public updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n if (\n (changedProperties.has(\"icon\") || changedProperties.has(\"iconPlaceholder\")) &&\n (this.icon || this.iconPlaceholder)\n ) {\n ImageTools.showImage(this.shadowRoot.querySelector(\".icon\"), this.icon, this.iconPlaceholder);\n }\n if (changedProperties.has(\"selected\")) {\n this.setAttribute(\"aria-selected\", String(this.selected));\n }\n }\n\n /**\n * Returns the width in pixel which is missing to show the caption and description without ellipsis.\n */\n public get missingWidthForTexts(): number {\n const originalLineClamp = this.enableLineClamp;\n this.removeAttribute(\"enable-line-clamp\"); // Need to remove immediately, otherwise the calculation may fail.\n\n let requiredWidth = 0;\n\n const captionElement = this.shadowRoot.querySelector(\".caption\");\n if (captionElement) {\n requiredWidth += captionElement.scrollWidth - captionElement.clientWidth;\n }\n\n const descriptionElement = this.shadowRoot.querySelector(\".description\");\n if (descriptionElement) {\n requiredWidth = Math.max(requiredWidth, descriptionElement.scrollWidth - descriptionElement.clientWidth);\n }\n if (requiredWidth > 0) {\n requiredWidth++; // Additional one pixel to ensure ellipsis is not needed anymore.\n }\n if (originalLineClamp) {\n this.setAttribute(\"enable-line-clamp\", \"\");\n }\n return requiredWidth;\n }\n\n private handleIconClick(event: PointerEvent): void {\n if (!this.disabled && !this.dispatchEvent(new PointerEvent(\"list-item-icon-click\", event))) {\n event.preventDefault();\n }\n }\n\n private getLevelIndicators(): number[] {\n if (!this.level) {\n return [];\n }\n // fill is needed because the ArrayConstructor\n // result an array with \"empty\" values in it\n // which are skipped when iterating\n return Array(Number(this.level)).fill(null);\n }\n}\n\nexport const generator = (data: ItemData, _index: number): ListItem => {\n const listItem = document.createElement(ListItem.ID) as ListItem;\n if (data) {\n listItem.caption = data.caption;\n listItem.description = data.description;\n listItem.icon = data.icon;\n listItem.iconBackgroundColor = data.iconBackgroundColor;\n listItem.iconPlaceholder = data.iconPlaceholder;\n listItem.level = data.level;\n listItem.disabled = data.disabled;\n if (data.contentMode) {\n listItem.contentMode = data.contentMode;\n }\n if (data.leftContentGenerator) {\n const leftContent = data.leftContentGenerator(data, listItem);\n if (leftContent) {\n leftContent.slot = \"left-content\";\n listItem.appendChild(leftContent);\n }\n }\n if (data.rightContentGenerator) {\n const rightContent = data.rightContentGenerator(data, listItem);\n if (rightContent) {\n rightContent.slot = \"right-content\";\n listItem.appendChild(rightContent);\n }\n }\n }\n return listItem;\n};\n\nListItem.ensureDefined();\n"],"names":["_ListItem","_a","LitElement","css","unsafeCSS","styles","html","_","level","iconBackgroundStyle","ifDefined","nothing","className","value","title","unsafeHTML","changedProperties","ImageTools","originalLineClamp","requiredWidth","captionElement","descriptionElement","event","__decorateClass","property","ListItem","generator","data","_index","listItem","leftContent","rightContent"],"mappings":";;;;;;;;;;;AA6BA,MAAqBA,KAArBC,IAAA,cAAsCC,EAAW;AAAA,EAAjD,cAAA;AAAA,UAAA,GAAA,SAAA,GAuBI,KAAO,cAA2B,QAiBlC,KAAO,OAAO;AAAA,EAAA;AAAA,EAUd,WAAW,SAAS;AAChB,WAAO;AAAA,MACHC;AAAA,kBACMC,EAAUC,CAAM,CAAC;AAAA;AAAA,IAAA;AAAA,EAG/B;AAAA,EAEO,SAAyB;AAC5B,WAAOC;AAAA;AAAA,kBAEG,KAAK,qBAAqB;AAAA,MACxB,CAACC,GAAGC,MAAUF,uCAA0CE,CAAK;AAAA,IAAA,CAChE;AAAA;AAAA;AAAA,sBAGK,KAAK,YAAY;AAAA;AAAA;AAAA,sBAGjB,KAAK,YAAY,WAAW,KAAK,SAAS,KAAK,gBAAgB,CAAC;AAAA,sBAChE,KAAK,YAAY,eAAe,KAAK,aAAa,KAAK,oBAAoB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO9F;AAAA,EAEQ,aAAa;AACjB,QAAI,KAAK,QAAQ,KAAK,iBAAiB;AACnC,YAAMC,IACF,KAAK,uBAAuB,OAAO,oBAAoB,KAAK,mBAAmB,KAAK;AACxF,aAAOH;AAAA;AAAA;AAAA,oCAGiB,KAAK,eAAe;AAAA,6BAC3BI,EAAUD,CAAmB,CAAC;AAAA;AAAA,kCAEzBC,EAAU,KAAK,iBAAiB,CAAC;AAAA,6BACtCA,EAAU,KAAK,aAAa,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,IAKlD;AACA,WAAOC;AAAA,EACX;AAAA,EAEQ,YAAYC,GAAmBC,GAAeC,GAA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AE,MAAM,QAAQ,SAAS,IAAM;AAAA,GAvCxBxB,EAwCV,WAAA,MAAA;AAIAuB,EAAA;AAAA,EADNC,EAAS,EAAE,MAAM,QAAQ,WAAW,sBAAsB;AAAA,GA3C1CxB,EA4CV,WAAA,kBAAA;AAEAuB,EAAA;AAAA,EADNC,EAAS,EAAE,MAAM,QAAQ,WAAW,0BAA0B;AAAA,GA7C9CxB,EA8CV,WAAA,sBAAA;AAEAuB,EAAA;AAAA,EADNC,EAAS,EAAE,MAAM,QAAQ,WAAW,mBAAmB;AAAA,GA/CvCxB,EAgDV,WAAA,eAAA;AAhDX,IAAqByB,IAArBzB;AAsKO,MAAM0B,IAAY,CAACC,GAAgBC,MAA6B;AACnE,QAAMC,IAAW,SAAS,cAAcJ,EAAS,EAAE;AACnD,MAAIE,GAAM;AAWN,QAVAE,EAAS,UAAUF,EAAK,SACxBE,EAAS,cAAcF,EAAK,aAC5BE,EAAS,OAAOF,EAAK,MACrBE,EAAS,sBAAsBF,EAAK,qBACpCE,EAAS,kBAAkBF,EAAK,iBAChCE,EAAS,QAAQF,EAAK,OACtBE,EAAS,WAAWF,EAAK,UACrBA,EAAK,gBACLE,EAAS,cAAcF,EAAK,cAE5BA,EAAK,sBAAsB;AAC3B,YAAMG,IAAcH,EAAK,qBAAqBA,GAAME,CAAQ;AAC5D,MAAIC,MACAA,EAAY,OAAO,gBACnBD,EAAS,YAAYC,CAAW;AAAA,IAExC;AACA,QAAIH,EAAK,uBAAuB;AAC5B,YAAMI,IAAeJ,EAAK,sBAAsBA,GAAME,CAAQ;AAC9D,MAAIE,MACAA,EAAa,OAAO,iBACpBF,EAAS,YAAYE,CAAY;AAAA,IAEzC;AAAA,EACJ;AACA,SAAOF;AACX;AAEAJ,EAAS,cAAA;"}
1
+ {"version":3,"file":"list-item.mjs","sources":["../list-item.ts"],"sourcesContent":["import { LitElement, html, unsafeCSS, PropertyValues, css, nothing, TemplateResult } from \"lit\";\nimport { property } from \"lit/decorators/property.js\";\nimport { unsafeHTML } from \"lit/directives/unsafe-html.js\";\nimport { ifDefined } from \"lit/directives/if-defined.js\";\nimport { placeholderDirective as placeholder } from \"@cas-smartdesign/image-tools\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n [ListItem.ID]: ListItem;\n }\n}\n\nimport styles from \"./styles.scss?inline\";\n\nexport interface ItemData {\n caption?: string;\n description?: string;\n leftContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;\n rightContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;\n icon?: string;\n iconBackgroundColor?: string;\n iconPlaceholder?: string;\n level?: number;\n contentMode?: ContentMode;\n disabled?: boolean;\n}\n\nexport type ContentMode = \"text\" | \"html\";\n\nexport default class ListItem extends LitElement {\n public static readonly ID = \"sd-list-item\";\n public static ensureDefined = (): void => {\n if (!customElements.get(ListItem.ID)) {\n customElements.define(ListItem.ID, ListItem);\n }\n };\n\n @property({ type: String })\n public caption: string;\n @property({ type: String })\n public description: string;\n @property({ type: Boolean })\n public selected: boolean;\n @property({ type: String })\n public icon: string;\n @property({ type: String })\n public iconBackgroundColor: string;\n @property({ type: String })\n public iconPlaceholder: string;\n @property({ type: Number })\n public level: number;\n @property()\n public contentMode: ContentMode = \"text\";\n @property({ type: Boolean, reflect: true, attribute: \"enable-line-clamp\" })\n public enableLineClamp: boolean;\n @property({\n converter: {\n fromAttribute: (value) => value == \"true\",\n toAttribute: (value) => value,\n },\n reflect: true,\n attribute: \"aria-disabled\",\n })\n public disabled: boolean;\n\n // aria attributes\n @property({ type: String, attribute: \"icon-attr-aria-label\" })\n public iconAttrAriaLabel: string;\n @property({ type: String, reflect: true })\n public role = \"option\";\n\n // title attributes\n @property({ type: String, attribute: \"caption-attr-title\" })\n public captionAttrTitle: string;\n @property({ type: String, attribute: \"description-attr-title\" })\n public descriptionAttrTitle: string;\n @property({ type: String, attribute: \"icon-attr-title\" })\n public iconAttrTitle: string;\n\n static get styles() {\n return [\n css`\n ${unsafeCSS(styles)}\n `,\n ];\n }\n\n public render(): TemplateResult {\n return html`\n <div class=\"container\">\n ${this.getLevelIndicators().map(\n (_, level) => html` <div class=\"level-indicator level-${level}\"></div> `,\n )}\n <div class=\"side-content\">\n <slot name=\"left-content\"></slot>\n ${this.renderIcon()}\n </div>\n <div class=\"labels\">\n ${this.renderLabel(\"caption\", this.caption, this.captionAttrTitle)}\n ${this.renderLabel(\"description\", this.description, this.descriptionAttrTitle)}\n </div>\n <div class=\"side-content\">\n <slot name=\"right-content\"></slot>\n </div>\n </div>\n `;\n }\n\n private renderIcon() {\n if (this.icon || this.iconPlaceholder) {\n return html`<div\n class=\"icon-wrapper\"\n @pointerdown=\"${this.handleIconClick}\"\n style=\"background-color:${ifDefined(this.iconBackgroundColor)};\"\n role=\"img\"\n aria-label=\"${ifDefined(this.iconAttrAriaLabel)}\"\n title=\"${ifDefined(this.iconAttrTitle)}\"\n >\n <div class=\"icon\" style=\"background-image:${placeholder(this.icon, this.iconPlaceholder)}\"></div>\n </div> `;\n }\n return nothing;\n }\n\n private renderLabel(className: string, value: string, title: string) {\n return value\n ? html`\n <div class=\"${className}\" title=\"${ifDefined(title)}\">\n ${this.contentMode === \"html\" ? unsafeHTML(value) : value}\n </div>\n `\n : nothing;\n }\n\n public updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n if (changedProperties.has(\"selected\")) {\n this.setAttribute(\"aria-selected\", String(this.selected));\n }\n }\n\n /**\n * Returns the width in pixel which is missing to show the caption and description without ellipsis.\n */\n public get missingWidthForTexts(): number {\n const originalLineClamp = this.enableLineClamp;\n this.removeAttribute(\"enable-line-clamp\"); // Need to remove immediately, otherwise the calculation may fail.\n\n let requiredWidth = 0;\n\n const captionElement = this.shadowRoot.querySelector(\".caption\");\n if (captionElement) {\n requiredWidth += captionElement.scrollWidth - captionElement.clientWidth;\n }\n\n const descriptionElement = this.shadowRoot.querySelector(\".description\");\n if (descriptionElement) {\n requiredWidth = Math.max(requiredWidth, descriptionElement.scrollWidth - descriptionElement.clientWidth);\n }\n if (requiredWidth > 0) {\n requiredWidth++; // Additional one pixel to ensure ellipsis is not needed anymore.\n }\n if (originalLineClamp) {\n this.setAttribute(\"enable-line-clamp\", \"\");\n }\n return requiredWidth;\n }\n\n private handleIconClick(event: PointerEvent): void {\n if (!this.disabled && !this.dispatchEvent(new PointerEvent(\"list-item-icon-click\", event))) {\n event.preventDefault();\n }\n }\n\n private getLevelIndicators(): number[] {\n if (!this.level) {\n return [];\n }\n // fill is needed because the ArrayConstructor\n // result an array with \"empty\" values in it\n // which are skipped when iterating\n return Array(Number(this.level)).fill(null);\n }\n}\n\nexport const generator = (data: ItemData, _index: number): ListItem => {\n const listItem = document.createElement(ListItem.ID) as ListItem;\n if (data) {\n listItem.caption = data.caption;\n listItem.description = data.description;\n listItem.icon = data.icon;\n listItem.iconBackgroundColor = data.iconBackgroundColor;\n listItem.iconPlaceholder = data.iconPlaceholder;\n listItem.level = data.level;\n listItem.disabled = data.disabled;\n if (data.contentMode) {\n listItem.contentMode = data.contentMode;\n }\n if (data.leftContentGenerator) {\n const leftContent = data.leftContentGenerator(data, listItem);\n if (leftContent) {\n leftContent.slot = \"left-content\";\n listItem.appendChild(leftContent);\n }\n }\n if (data.rightContentGenerator) {\n const rightContent = data.rightContentGenerator(data, listItem);\n if (rightContent) {\n rightContent.slot = \"right-content\";\n listItem.appendChild(rightContent);\n }\n }\n }\n return listItem;\n};\n\nListItem.ensureDefined();\n"],"names":["_ListItem","_a","LitElement","css","unsafeCSS","styles","html","_","level","ifDefined","placeholder","nothing","className","value","title","unsafeHTML","changedProperties","originalLineClamp","requiredWidth","captionElement","descriptionElement","event","__decorateClass","property","ListItem","generator","data","_index","listItem","leftContent","rightContent"],"mappings":";;;;;;;;;;;AA6BA,MAAqBA,KAArBC,IAAA,cAAsCC,EAAW;AAAA,EAAjD,cAAA;AAAA,UAAA,GAAA,SAAA,GAuBI,KAAO,cAA2B,QAiBlC,KAAO,OAAO;AAAA,EAAA;AAAA,EAUd,WAAW,SAAS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,EAAS,sBAAsBF,EAAK,qBACpCE,EAAS,kBAAkBF,EAAK,iBAChCE,EAAS,QAAQF,EAAK,OACtBE,EAAS,WAAWF,EAAK,UACrBA,EAAK,gBACLE,EAAS,cAAcF,EAAK,cAE5BA,EAAK,sBAAsB;AAC3B,YAAMG,IAAcH,EAAK,qBAAqBA,GAAME,CAAQ;AAC5D,MAAIC,MACAA,EAAY,OAAO,gBACnBD,EAAS,YAAYC,CAAW;AAAA,IAExC;AACA,QAAIH,EAAK,uBAAuB;AAC5B,YAAMI,IAAeJ,EAAK,sBAAsBA,GAAME,CAAQ;AAC9D,MAAIE,MACAA,EAAa,OAAO,iBACpBF,EAAS,YAAYE,CAAY;AAAA,IAEzC;AAAA,EACJ;AACA,SAAOF;AACX;AAEAJ,EAAS,cAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cas-smartdesign/list-item",
3
- "version": "7.3.0",
3
+ "version": "7.4.0",
4
4
  "description": "A list item element based on LitElement",
5
5
  "main": "dist/list-item-with-externals.js",
6
6
  "module": "dist/list-item.mjs",
@@ -8,11 +8,11 @@
8
8
  "types": "dist/list-item.d.ts",
9
9
  "dependencies": {
10
10
  "lit": "^3.3.1",
11
- "@cas-smartdesign/image-tools": "^3.1.0"
11
+ "@cas-smartdesign/image-tools": "^3.2.0"
12
12
  },
13
13
  "devDependencies": {
14
- "@cas-smartdesign/license-generator": "^1.7.0",
15
- "@cas-smartdesign/element-preview": "^0.3.0"
14
+ "@cas-smartdesign/element-preview": "^0.3.0",
15
+ "@cas-smartdesign/license-generator": "^1.7.0"
16
16
  },
17
17
  "files": [
18
18
  "dist",