@commmerce/ui 1.1.1 → 1.3.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/dist/calendar.d.ts +38 -0
- package/dist/calendar.js +109 -0
- package/dist/cdn.js +1010 -533
- package/dist/components/board.d.ts +338 -0
- package/dist/components/board.js +1017 -0
- package/dist/components/button.d.ts +10 -0
- package/dist/components/button.js +25 -0
- package/dist/components/card.d.ts +7 -1
- package/dist/components/card.js +58 -7
- package/dist/components/color-field.d.ts +153 -0
- package/dist/components/color-field.js +369 -0
- package/dist/components/combobox.d.ts +17 -4
- package/dist/components/combobox.js +55 -23
- package/dist/components/date-picker.d.ts +49 -5
- package/dist/components/date-picker.js +211 -48
- package/dist/components/empty-state.d.ts +19 -4
- package/dist/components/empty-state.js +59 -5
- package/dist/components/file-upload.d.ts +33 -0
- package/dist/components/file-upload.js +80 -9
- package/dist/components/global-search.js +2 -7
- package/dist/components/metric.d.ts +97 -0
- package/dist/components/metric.js +168 -0
- package/dist/components/nested-list.d.ts +33 -1
- package/dist/components/nested-list.js +197 -18
- package/dist/components/option-group.d.ts +15 -6
- package/dist/components/option-group.js +25 -6
- package/dist/components/page-header.js +3 -2
- package/dist/components/resource-list.d.ts +14 -2
- package/dist/components/resource-list.js +48 -6
- package/dist/components/select.d.ts +20 -3
- package/dist/components/select.js +35 -11
- package/dist/components/table-header.d.ts +14 -0
- package/dist/components/table-header.js +21 -0
- package/dist/components/text-field.d.ts +36 -2
- package/dist/components/text-field.js +86 -14
- package/dist/components/timeline.d.ts +210 -0
- package/dist/components/timeline.js +380 -0
- package/dist/custom-elements.json +9371 -4963
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -0
- package/dist/move-model.d.ts +93 -0
- package/dist/move-model.js +169 -0
- package/dist/popover.d.ts +24 -0
- package/dist/popover.js +59 -0
- package/package.json +3 -3
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _CmTimelineItem_instances, _CmTimelineItem_id, _CmTimelineItem_resize, _CmTimelineItem_measure, _CmTimelineItem_has, _CmTimelineItem_toggle, _CmTimeline_instances, _CmTimeline_observer, _CmTimeline_moreFocused, _CmTimeline_read, _CmTimeline_more;
|
|
13
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
14
|
+
import { base, define, nextId } from '../base.js';
|
|
15
|
+
import { CmLocalizedElement, defineStrings, formatDate } from '../localize.js';
|
|
16
|
+
import './icon.js';
|
|
17
|
+
import './button.js';
|
|
18
|
+
import './skeleton.js';
|
|
19
|
+
import './tooltip.js';
|
|
20
|
+
const itemStrings = defineStrings('timelineItem', {
|
|
21
|
+
/** When it happened, relative to now. `{count}` is a whole number; past and future wording are separate keys. */
|
|
22
|
+
justNow: 'Just now',
|
|
23
|
+
minutesAgo: { one: '{count} minute ago', other: '{count} minutes ago' },
|
|
24
|
+
hoursAgo: { one: '{count} hour ago', other: '{count} hours ago' },
|
|
25
|
+
daysAgo: { one: '{count} day ago', other: '{count} days ago' },
|
|
26
|
+
inMinutes: { one: 'In {count} minute', other: 'In {count} minutes' },
|
|
27
|
+
inHours: { one: 'In {count} hour', other: 'In {count} hours' },
|
|
28
|
+
inDays: { one: 'In {count} day', other: 'In {count} days' },
|
|
29
|
+
/** The button under a clamped body. */
|
|
30
|
+
showAll: 'Show all',
|
|
31
|
+
showLess: 'Show less',
|
|
32
|
+
});
|
|
33
|
+
const strings = defineStrings('timeline', {
|
|
34
|
+
/** Accessible name of the list. */
|
|
35
|
+
label: 'Activity',
|
|
36
|
+
/** The button at the end that asks for older events. */
|
|
37
|
+
showMore: 'Show more',
|
|
38
|
+
/** Announced while `loading`. */
|
|
39
|
+
loading: 'Loading activity',
|
|
40
|
+
});
|
|
41
|
+
/** Times older (or further ahead) than this many days show as a date instead of "N days ago". */
|
|
42
|
+
const RELATIVE_DAYS = 7;
|
|
43
|
+
// One timer for every item on the page, so "2 minutes ago" moves on while the page is open.
|
|
44
|
+
const ticking = new Set();
|
|
45
|
+
let timer;
|
|
46
|
+
function tick(el, on) {
|
|
47
|
+
if (on)
|
|
48
|
+
ticking.add(el);
|
|
49
|
+
else
|
|
50
|
+
ticking.delete(el);
|
|
51
|
+
if (ticking.size && !timer)
|
|
52
|
+
timer = setInterval(() => ticking.forEach((e) => e.requestUpdate()), 60_000);
|
|
53
|
+
if (!ticking.size && timer) {
|
|
54
|
+
clearInterval(timer);
|
|
55
|
+
timer = undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* One event in a `cm-timeline`: an icon for its kind, a title, when it happened, a meta line, an optional badge,
|
|
60
|
+
* an optional body (clamped to a few lines with Show all / Show less) and optional actions.
|
|
61
|
+
*
|
|
62
|
+
* The time is shown relative to now ("2 hours ago", then a date after a week), with the full date and time in a
|
|
63
|
+
* tooltip on hover and keyboard focus, and read out to screen readers after the relative time.
|
|
64
|
+
* @element cm-timeline-item
|
|
65
|
+
* @slot - The body: an email excerpt, a note, a call summary. Clamped to `lines` lines.
|
|
66
|
+
* @slot heading - Rich title (e.g. with a link), instead of `heading`.
|
|
67
|
+
* @slot meta - Rich meta line, instead of `meta`.
|
|
68
|
+
* @slot badge - A `cm-badge` for the kind or state, after the title.
|
|
69
|
+
* @slot actions - Links or buttons under the body, e.g. "Read email".
|
|
70
|
+
* @csspart icon - The round icon.
|
|
71
|
+
* @csspart title - The title.
|
|
72
|
+
* @csspart time - The `<time>` element.
|
|
73
|
+
* @csspart meta - The meta line.
|
|
74
|
+
* @csspart body - The body.
|
|
75
|
+
* @csspart toggle - The Show all / Show less button.
|
|
76
|
+
*/
|
|
77
|
+
export class CmTimelineItem extends CmLocalizedElement {
|
|
78
|
+
constructor() {
|
|
79
|
+
super(...arguments);
|
|
80
|
+
_CmTimelineItem_instances.add(this);
|
|
81
|
+
/** Icon name from `@commmerce/icons` for the kind of event ("mail", "note", "edit", "chat"). Empty shows a small dot. */
|
|
82
|
+
this.icon = '';
|
|
83
|
+
/** Colours the icon: `neutral` (default), `information`, `attention`, `success` or `critical`. */
|
|
84
|
+
this.tone = 'neutral';
|
|
85
|
+
/** What happened: "Email sent", "Status changed". Use the `heading` slot for a link. */
|
|
86
|
+
this.heading = '';
|
|
87
|
+
/** When it happened, as an ISO date-time (`2026-11-16T10:30:00+05:30`). Shown relative to now; used for `<time datetime>`. */
|
|
88
|
+
this.datetime = '';
|
|
89
|
+
/** The time as shown, instead of the relative time worked out from `datetime` (which still gives the full date on hover). */
|
|
90
|
+
this.time = '';
|
|
91
|
+
/** A line under the title: "by Rahul Kumar · sent". Use the `meta` slot for links. */
|
|
92
|
+
this.meta = '';
|
|
93
|
+
/** Lines of body shown before "Show all". 0 shows the whole body. */
|
|
94
|
+
this.lines = 3;
|
|
95
|
+
/** The whole body is shown (after "Show all"). */
|
|
96
|
+
this.expanded = false;
|
|
97
|
+
this._overflow = false;
|
|
98
|
+
this._body = false;
|
|
99
|
+
this._meta = false;
|
|
100
|
+
this._actions = false;
|
|
101
|
+
_CmTimelineItem_id.set(this, nextId('cm-tl'));
|
|
102
|
+
_CmTimelineItem_resize.set(this, void 0);
|
|
103
|
+
}
|
|
104
|
+
connectedCallback() {
|
|
105
|
+
super.connectedCallback();
|
|
106
|
+
tick(this, true);
|
|
107
|
+
}
|
|
108
|
+
disconnectedCallback() {
|
|
109
|
+
super.disconnectedCallback();
|
|
110
|
+
tick(this, false);
|
|
111
|
+
__classPrivateFieldGet(this, _CmTimelineItem_resize, "f")?.disconnect();
|
|
112
|
+
__classPrivateFieldSet(this, _CmTimelineItem_resize, undefined, "f");
|
|
113
|
+
}
|
|
114
|
+
firstUpdated() {
|
|
115
|
+
const body = this.renderRoot.querySelector('.body');
|
|
116
|
+
if (body && typeof ResizeObserver !== 'undefined') {
|
|
117
|
+
__classPrivateFieldSet(this, _CmTimelineItem_resize, new ResizeObserver(() => __classPrivateFieldGet(this, _CmTimelineItem_instances, "m", _CmTimelineItem_measure).call(this)), "f");
|
|
118
|
+
__classPrivateFieldGet(this, _CmTimelineItem_resize, "f").observe(body);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
updated(changed) {
|
|
122
|
+
if (changed.has('lines') || changed.has('_body') || changed.has('expanded'))
|
|
123
|
+
__classPrivateFieldGet(this, _CmTimelineItem_instances, "m", _CmTimelineItem_measure).call(this);
|
|
124
|
+
}
|
|
125
|
+
/** The `datetime` as a Date, or undefined when missing or invalid. */
|
|
126
|
+
get date() {
|
|
127
|
+
if (!this.datetime)
|
|
128
|
+
return undefined;
|
|
129
|
+
const d = new Date(this.datetime);
|
|
130
|
+
return Number.isNaN(d.getTime()) ? undefined : d;
|
|
131
|
+
}
|
|
132
|
+
/** The time as shown: `time`, or `datetime` relative to now ("2 hours ago"), or a date when over a week away. */
|
|
133
|
+
get relativeTime() {
|
|
134
|
+
if (this.time)
|
|
135
|
+
return this.time;
|
|
136
|
+
const d = this.date;
|
|
137
|
+
if (!d)
|
|
138
|
+
return this.datetime;
|
|
139
|
+
const diff = Date.now() - d.getTime();
|
|
140
|
+
const future = diff < 0;
|
|
141
|
+
const min = Math.floor(Math.abs(diff) / 60_000);
|
|
142
|
+
if (min < 1)
|
|
143
|
+
return this.t('justNow');
|
|
144
|
+
if (min < 60)
|
|
145
|
+
return this.t(future ? 'inMinutes' : 'minutesAgo', { count: min });
|
|
146
|
+
const hours = Math.floor(min / 60);
|
|
147
|
+
if (hours < 24)
|
|
148
|
+
return this.t(future ? 'inHours' : 'hoursAgo', { count: hours });
|
|
149
|
+
const days = Math.floor(hours / 24);
|
|
150
|
+
if (days < RELATIVE_DAYS)
|
|
151
|
+
return this.t(future ? 'inDays' : 'daysAgo', { count: days });
|
|
152
|
+
return formatDate(d, { dateStyle: 'medium' }, this.locale);
|
|
153
|
+
}
|
|
154
|
+
/** The full date and time, for the tooltip and screen readers. */
|
|
155
|
+
get fullTime() {
|
|
156
|
+
const d = this.date;
|
|
157
|
+
return d ? formatDate(d, { dateStyle: 'full', timeStyle: 'short' }, this.locale) : '';
|
|
158
|
+
}
|
|
159
|
+
render() {
|
|
160
|
+
const shown = this.relativeTime;
|
|
161
|
+
const full = this.fullTime;
|
|
162
|
+
const tone = this.tone && this.tone !== 'neutral' ? this.tone : '';
|
|
163
|
+
const clamp = this.lines > 0 && !this.expanded;
|
|
164
|
+
const timeEl = shown
|
|
165
|
+
? full
|
|
166
|
+
? html `<cm-tooltip class="when" content=${full} visual-only placement="top"><time part="time" tabindex="0" datetime=${this.datetime}>${shown}<span class="sr">, ${full}</span></time></cm-tooltip>`
|
|
167
|
+
: html `<time class="when" part="time" datetime=${this.datetime || nothing}>${shown}</time>`
|
|
168
|
+
: nothing;
|
|
169
|
+
return html `<div class="item">
|
|
170
|
+
<span class="icon ${tone}" part="icon" aria-hidden="true">${this.icon
|
|
171
|
+
? html `<cm-icon name=${this.icon} size="16"></cm-icon>` : html `<span class="dot"></span>`}</span>
|
|
172
|
+
<div class="main">
|
|
173
|
+
<div class="head">
|
|
174
|
+
<span class="title" part="title"><slot name="heading">${this.heading}</slot></span>
|
|
175
|
+
<slot name="badge"></slot>
|
|
176
|
+
${timeEl}
|
|
177
|
+
</div>
|
|
178
|
+
<div class="meta" part="meta" ?hidden=${!this.meta && !this._meta}><slot name="meta" @slotchange=${(e) => __classPrivateFieldGet(this, _CmTimelineItem_instances, "m", _CmTimelineItem_has).call(this, e, '_meta')}>${this.meta}</slot></div>
|
|
179
|
+
<div class="body ${clamp ? 'clamp' : ''}" id="${__classPrivateFieldGet(this, _CmTimelineItem_id, "f")}-body" part="body" ?hidden=${!this._body}
|
|
180
|
+
style="--_lines: ${Math.max(1, this.lines || 1)}"><slot @slotchange=${(e) => __classPrivateFieldGet(this, _CmTimelineItem_instances, "m", _CmTimelineItem_has).call(this, e, '_body')}></slot></div>
|
|
181
|
+
${this._body && this._overflow
|
|
182
|
+
? html `<button type="button" class="toggle" part="toggle" aria-expanded=${this.expanded ? 'true' : 'false'}
|
|
183
|
+
aria-controls="${__classPrivateFieldGet(this, _CmTimelineItem_id, "f")}-body" @click=${__classPrivateFieldGet(this, _CmTimelineItem_instances, "m", _CmTimelineItem_toggle)}>${this.expanded ? this.t('showLess') : this.t('showAll')}</button>`
|
|
184
|
+
: nothing}
|
|
185
|
+
<div class="actions" part="actions" ?hidden=${!this._actions}><slot name="actions" @slotchange=${(e) => __classPrivateFieldGet(this, _CmTimelineItem_instances, "m", _CmTimelineItem_has).call(this, e, '_actions')}></slot></div>
|
|
186
|
+
</div>
|
|
187
|
+
</div>`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
_CmTimelineItem_id = new WeakMap(), _CmTimelineItem_resize = new WeakMap(), _CmTimelineItem_instances = new WeakSet(), _CmTimelineItem_measure = function _CmTimelineItem_measure() {
|
|
191
|
+
const body = this.renderRoot.querySelector('.body');
|
|
192
|
+
if (!body || !this._body || !(this.lines > 0)) {
|
|
193
|
+
this._overflow = false;
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const lh = parseFloat(getComputedStyle(body).lineHeight) || 20;
|
|
197
|
+
this._overflow = body.scrollHeight > this.lines * lh + 1;
|
|
198
|
+
}, _CmTimelineItem_has = function _CmTimelineItem_has(e, prop) {
|
|
199
|
+
const nodes = e.target.assignedNodes({ flatten: true });
|
|
200
|
+
this[prop] = nodes.some((n) => n.nodeType === Node.ELEMENT_NODE || (n.textContent ?? '').trim());
|
|
201
|
+
}, _CmTimelineItem_toggle = function _CmTimelineItem_toggle() {
|
|
202
|
+
this.expanded = !this.expanded;
|
|
203
|
+
};
|
|
204
|
+
CmTimelineItem.properties = {
|
|
205
|
+
icon: { reflect: true },
|
|
206
|
+
tone: { reflect: true },
|
|
207
|
+
heading: {},
|
|
208
|
+
datetime: { reflect: true },
|
|
209
|
+
time: {},
|
|
210
|
+
meta: {},
|
|
211
|
+
lines: { type: Number },
|
|
212
|
+
expanded: { type: Boolean, reflect: true },
|
|
213
|
+
_overflow: { state: true },
|
|
214
|
+
_body: { state: true },
|
|
215
|
+
_meta: { state: true },
|
|
216
|
+
_actions: { state: true },
|
|
217
|
+
};
|
|
218
|
+
CmTimelineItem.styles = [
|
|
219
|
+
base,
|
|
220
|
+
css `
|
|
221
|
+
:host { display: block; min-width: 0; font-size: 14px; line-height: 20px; }
|
|
222
|
+
.item { display: flex; gap: var(--cm-space-15); align-items: flex-start; }
|
|
223
|
+
.icon {
|
|
224
|
+
position: relative; z-index: 1; display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: var(--cm-radius-full);
|
|
225
|
+
background: var(--cm-bg-inset); color: var(--cm-icon-default); border: var(--cm-border-1) solid var(--cm-border-default);
|
|
226
|
+
}
|
|
227
|
+
.icon.information { background: var(--cm-bg-information-soft); color: var(--cm-text-information); border-color: transparent; }
|
|
228
|
+
.icon.attention { background: var(--cm-bg-attention); color: var(--cm-text-attention); border-color: transparent; }
|
|
229
|
+
.icon.success { background: var(--cm-bg-success-soft); color: var(--cm-text-success); border-color: transparent; }
|
|
230
|
+
.icon.critical { background: var(--cm-bg-critical); color: var(--cm-text-critical); border-color: transparent; }
|
|
231
|
+
.dot { width: 10px; height: 10px; border-radius: var(--cm-radius-full); background: currentColor; }
|
|
232
|
+
.main { flex: 1; min-width: 0; padding-block-start: 6px; }
|
|
233
|
+
.head { display: flex; flex-wrap: wrap; align-items: center; column-gap: var(--cm-space-10); row-gap: 4px; }
|
|
234
|
+
.title { min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
|
|
235
|
+
.when { margin-inline-start: auto; }
|
|
236
|
+
time {
|
|
237
|
+
position: relative; display: inline-block; font-size: 12px; line-height: 16px; color: var(--cm-text-tertiary); white-space: nowrap;
|
|
238
|
+
border-radius: var(--cm-radius-xs);
|
|
239
|
+
}
|
|
240
|
+
time:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
241
|
+
.meta { margin-block-start: 2px; font-size: 12px; line-height: 16px; color: var(--cm-text-tertiary); overflow-wrap: anywhere; }
|
|
242
|
+
.body { margin-block-start: var(--cm-space-10); overflow-wrap: anywhere; }
|
|
243
|
+
.body.clamp {
|
|
244
|
+
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--_lines); overflow: hidden;
|
|
245
|
+
max-height: calc(var(--_lines) * 20px);
|
|
246
|
+
}
|
|
247
|
+
.toggle {
|
|
248
|
+
margin-block-start: 4px; padding: 2px 0; font: inherit; font-size: 12px; font-weight: 500; line-height: 16px; color: var(--cm-text-default);
|
|
249
|
+
text-decoration: underline; background: none; border: 0; cursor: pointer; min-height: 24px;
|
|
250
|
+
}
|
|
251
|
+
.toggle:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; border-radius: var(--cm-radius-xs); }
|
|
252
|
+
.actions { display: flex; flex-wrap: wrap; gap: var(--cm-space-10); margin-block-start: var(--cm-space-10); }
|
|
253
|
+
[hidden] { display: none !important; }
|
|
254
|
+
.sr { position: absolute; inset-block-start: 0; inset-inline-start: 0; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
255
|
+
::slotted([slot='badge']) { flex: none; }
|
|
256
|
+
`,
|
|
257
|
+
];
|
|
258
|
+
define('cm-timeline-item', CmTimelineItem);
|
|
259
|
+
/**
|
|
260
|
+
* An activity feed for a record page: one `cm-timeline-item` per event (emails, calls, notes, field changes,
|
|
261
|
+
* system events), newest first, joined by a vertical line, with "Show more" at the end for older events.
|
|
262
|
+
*
|
|
263
|
+
* It is an ordered list: the component renders the `<ol>` and one `<li>` per item, and each item is shown inside its
|
|
264
|
+
* `<li>`. The line between icons is decoration only.
|
|
265
|
+
* @element cm-timeline
|
|
266
|
+
* @slot - `cm-timeline-item` elements, in the order to show them. Other children are not shown.
|
|
267
|
+
* @slot empty - Shown when there are no items and nothing is loading, e.g. a `cm-empty-state`.
|
|
268
|
+
* @fires cm-load-more - When "Show more" is pressed. Fetch the next page, append the items and clear `loading`; clear `has-more` on the last page.
|
|
269
|
+
* @csspart list - The `<ol>`.
|
|
270
|
+
* @csspart more - The Show more button.
|
|
271
|
+
*/
|
|
272
|
+
export class CmTimeline extends CmLocalizedElement {
|
|
273
|
+
constructor() {
|
|
274
|
+
super(...arguments);
|
|
275
|
+
_CmTimeline_instances.add(this);
|
|
276
|
+
/** There are older events: shows the "Show more" button, which fires `cm-load-more`. */
|
|
277
|
+
this.hasMore = false;
|
|
278
|
+
/** Events are loading: the Show more button shows a spinner, or placeholder rows show when there are no items yet. Announced politely. */
|
|
279
|
+
this.loading = false;
|
|
280
|
+
this._items = [];
|
|
281
|
+
this._empty = [];
|
|
282
|
+
_CmTimeline_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmTimeline_instances, "m", _CmTimeline_read).call(this)));
|
|
283
|
+
_CmTimeline_moreFocused.set(this, false);
|
|
284
|
+
}
|
|
285
|
+
connectedCallback() {
|
|
286
|
+
super.connectedCallback();
|
|
287
|
+
__classPrivateFieldGet(this, _CmTimeline_instances, "m", _CmTimeline_read).call(this);
|
|
288
|
+
__classPrivateFieldGet(this, _CmTimeline_observer, "f").observe(this, { childList: true, attributes: true, attributeFilter: ['slot'] });
|
|
289
|
+
}
|
|
290
|
+
disconnectedCallback() {
|
|
291
|
+
super.disconnectedCallback();
|
|
292
|
+
__classPrivateFieldGet(this, _CmTimeline_observer, "f").disconnect();
|
|
293
|
+
}
|
|
294
|
+
/** The `cm-timeline-item` children, in order. */
|
|
295
|
+
get items() {
|
|
296
|
+
return [...this.children].filter((c) => c.localName === 'cm-timeline-item' && !c.hasAttribute('slot'));
|
|
297
|
+
}
|
|
298
|
+
willUpdate() {
|
|
299
|
+
__classPrivateFieldSet(this, _CmTimeline_moreFocused, this.renderRoot?.activeElement?.localName === 'cm-button', "f");
|
|
300
|
+
}
|
|
301
|
+
updated() {
|
|
302
|
+
// Manual slot assignment: each item goes into the slot inside its own <li>, so the list is a real <ol> of <li>s.
|
|
303
|
+
const slots = this.renderRoot.querySelectorAll('li > slot');
|
|
304
|
+
slots.forEach((s, i) => { if (this._items[i])
|
|
305
|
+
s.assign(this._items[i]); });
|
|
306
|
+
const empty = this.renderRoot.querySelector('slot.empty');
|
|
307
|
+
if (empty)
|
|
308
|
+
empty.assign(...this._empty);
|
|
309
|
+
// "Show more" went away while focused (the last page arrived): keep focus in the timeline.
|
|
310
|
+
if (__classPrivateFieldGet(this, _CmTimeline_moreFocused, "f") && !this.renderRoot.querySelector('.more cm-button')) {
|
|
311
|
+
__classPrivateFieldSet(this, _CmTimeline_moreFocused, false, "f");
|
|
312
|
+
this.renderRoot.querySelector('ol')?.focus();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
render() {
|
|
316
|
+
const items = this._items;
|
|
317
|
+
const busy = this.loading;
|
|
318
|
+
const skeleton = busy && !items.length
|
|
319
|
+
? html `<div class="loading" aria-hidden="true">${[0, 1, 2].map(() => html `<div class="sk">
|
|
320
|
+
<cm-skeleton class="ic" variant="block"></cm-skeleton><cm-skeleton class="tx" lines="2"></cm-skeleton></div>`)}</div>`
|
|
321
|
+
: nothing;
|
|
322
|
+
return html `
|
|
323
|
+
${items.length
|
|
324
|
+
? html `<ol part="list" aria-label=${this.label} aria-busy=${busy ? 'true' : 'false'} tabindex="-1">
|
|
325
|
+
${items.map(() => html `<li><slot></slot></li>`)}
|
|
326
|
+
</ol>`
|
|
327
|
+
: nothing}
|
|
328
|
+
${skeleton}
|
|
329
|
+
${!items.length && !busy ? html `<slot class="empty"></slot>` : nothing}
|
|
330
|
+
${this.hasMore && items.length
|
|
331
|
+
? html `<div class="more"><cm-button part="more" size="medium" ?loading=${busy} @click=${__classPrivateFieldGet(this, _CmTimeline_instances, "m", _CmTimeline_more)}>${this.moreLabel}</cm-button></div>`
|
|
332
|
+
: nothing}
|
|
333
|
+
<span class="sr" role="status">${busy ? this.t('loading') : ''}</span>
|
|
334
|
+
`;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
_CmTimeline_observer = new WeakMap(), _CmTimeline_moreFocused = new WeakMap(), _CmTimeline_instances = new WeakSet(), _CmTimeline_read = function _CmTimeline_read() {
|
|
338
|
+
this._items = this.items;
|
|
339
|
+
this._empty = [...this.children].filter((c) => c.getAttribute('slot') === 'empty');
|
|
340
|
+
}, _CmTimeline_more = function _CmTimeline_more() {
|
|
341
|
+
if (this.loading)
|
|
342
|
+
return;
|
|
343
|
+
this.dispatchEvent(new CustomEvent('cm-load-more', { bubbles: true, composed: true }));
|
|
344
|
+
};
|
|
345
|
+
CmTimeline.shadowRootOptions = { ...LitElement.shadowRootOptions, slotAssignment: 'manual' };
|
|
346
|
+
CmTimeline.properties = {
|
|
347
|
+
label: { string: 'label' },
|
|
348
|
+
hasMore: { type: Boolean, attribute: 'has-more', reflect: true },
|
|
349
|
+
loading: { type: Boolean, reflect: true },
|
|
350
|
+
moreLabel: { attribute: 'more-label', string: 'showMore' },
|
|
351
|
+
_items: { state: true },
|
|
352
|
+
_empty: { state: true },
|
|
353
|
+
};
|
|
354
|
+
CmTimeline.styles = [
|
|
355
|
+
base,
|
|
356
|
+
css `
|
|
357
|
+
:host { display: block; }
|
|
358
|
+
ol { margin: 0; padding: 0; list-style: none; }
|
|
359
|
+
ol:focus { outline: none; }
|
|
360
|
+
li { position: relative; padding-block-end: var(--cm-space-20); }
|
|
361
|
+
/* The line joining the icons (16px is half the 32px icon). Decorative: a pseudo-element, nothing to read. */
|
|
362
|
+
li::before {
|
|
363
|
+
content: ''; position: absolute; inset-inline-start: 15px; inset-block: 32px 0; width: 2px; background: var(--cm-border-default);
|
|
364
|
+
}
|
|
365
|
+
li:last-child::before { display: none; }
|
|
366
|
+
:host([has-more]) li:last-child::before { display: block; }
|
|
367
|
+
li:last-child { padding-block-end: 0; }
|
|
368
|
+
:host([has-more]) li:last-child { padding-block-end: var(--cm-space-20); }
|
|
369
|
+
.more { display: flex; padding-inline-start: 47px; }
|
|
370
|
+
.loading { display: grid; gap: var(--cm-space-20); }
|
|
371
|
+
.sk { display: flex; gap: var(--cm-space-15); align-items: flex-start; }
|
|
372
|
+
.sk .ic { flex: none; width: 32px; --cm-skeleton-height: 32px; }
|
|
373
|
+
.sk .tx { flex: 1; }
|
|
374
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
375
|
+
@media (max-width: 640px) {
|
|
376
|
+
.more { padding-inline-start: 0; }
|
|
377
|
+
}
|
|
378
|
+
`,
|
|
379
|
+
];
|
|
380
|
+
define('cm-timeline', CmTimeline);
|