@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,1017 @@
|
|
|
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 _CmBoardCard_instances, _CmBoardCard_id, _CmBoardCard_slotted, _CmBoardColumn_instances, _CmBoardColumn_collapsed, _CmBoardColumn_observer, _CmBoardColumn_id, _CmBoardColumn_moreFocused, _CmBoardColumn_read, _CmBoardColumn_more, _CmBoard_instances, _CmBoard_announcer, _CmBoard_model, _CmBoard_held, _CmBoard_history, _CmBoard_drag, _CmBoard_say, _CmBoard_place, _CmBoard_focusHandle, _CmBoard_release, _CmBoard_showTarget, _CmBoard_reveal, _CmBoard_keyboardDrop, _CmBoard_handleOf, _CmBoard_onKey, _CmBoard_neighbour, _CmBoard_onFocusOut, _CmBoard_shown, _CmBoard_insert, _CmBoard_adjustTotals, _CmBoard_commit, _CmBoard_refocus, _CmBoard_onNativeDrag, _CmBoard_onPointerDown, _CmBoard_onTouchMove, _CmBoard_onContextMenu, _CmBoard_onPointerMove, _CmBoard_onPointerUp, _CmBoard_onPointerCancel, _CmBoard_startDrag, _CmBoard_moveGhost, _CmBoard_updateTarget, _CmBoard_autoScroll, _CmBoard_endDrag;
|
|
13
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
14
|
+
import { repeat } from 'lit/directives/repeat.js';
|
|
15
|
+
import { base, define, logicalKey, nextId } from '../base.js';
|
|
16
|
+
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
17
|
+
import { MoveModel, Announcer } from '../move-model.js';
|
|
18
|
+
import './button.js';
|
|
19
|
+
import './skeleton.js';
|
|
20
|
+
import './spinner.js';
|
|
21
|
+
const cardStrings = defineStrings('boardCard', {
|
|
22
|
+
/** What screen readers call a card, after its name: "Ravi Stores, movable card". */
|
|
23
|
+
roleDescription: 'movable card',
|
|
24
|
+
/** Read after the card's name and role (its description). */
|
|
25
|
+
instructions: 'Press Space to pick up. Then use the arrow keys to choose a column and a position, Space or Enter to drop, and Escape to cancel.',
|
|
26
|
+
/** Added before `instructions` when the card opens a record (`href`, or a link or button in the `heading` slot). */
|
|
27
|
+
openHint: 'Press Enter to open.',
|
|
28
|
+
/** Read while the move is being saved (`pending`). */
|
|
29
|
+
saving: 'Saving',
|
|
30
|
+
});
|
|
31
|
+
const columnStrings = defineStrings('boardColumn', {
|
|
32
|
+
/** Read after the column heading: "Contacted, 12 cards". `{count}` is `total`, or the number of cards loaded. */
|
|
33
|
+
count: { one: '{count} card', other: '{count} cards' },
|
|
34
|
+
/** The button at the end of a column that has more cards to load. */
|
|
35
|
+
loadMore: 'Load more',
|
|
36
|
+
/** Announced while `loading`. `{column}` is the heading. */
|
|
37
|
+
loading: 'Loading {column}',
|
|
38
|
+
/** Shown in a column with no cards (when nothing is in the `empty` slot). */
|
|
39
|
+
empty: 'No cards',
|
|
40
|
+
});
|
|
41
|
+
const boardStrings = defineStrings('board', {
|
|
42
|
+
/** Accessible name of the board. */
|
|
43
|
+
label: 'Board',
|
|
44
|
+
/** Announced on pick up. `{card}` card name, `{column}` heading, `{position}` and `{count}` the place in the column. */
|
|
45
|
+
pickedUp: 'Picked up {card}. Column {column}, position {position} of {count}.',
|
|
46
|
+
/** Announced as the arrow keys move the card. */
|
|
47
|
+
over: 'Column {column}, position {position} of {count}.',
|
|
48
|
+
/** Announced after a drop that moved the card. */
|
|
49
|
+
moved: 'Moved {card} to {column}, position {position} of {count}.',
|
|
50
|
+
/** Announced after a drop where the card started. */
|
|
51
|
+
sameSpot: '{card} dropped where it started.',
|
|
52
|
+
/** Announced after Escape (or focus leaving the card) while it is picked up. */
|
|
53
|
+
cancelled: 'Move cancelled. {card} is back in {column}.',
|
|
54
|
+
/** Announced when the app cancels `cm-move` (`preventDefault()`). */
|
|
55
|
+
refused: '{card} can\'t be moved to {column}.',
|
|
56
|
+
/** Announced when a move fails and the card goes back (`revert()`, or a rejected `waitUntil()` promise). `{column}` is where it went back to. */
|
|
57
|
+
reverted: 'Couldn\'t move {card}. It is back in {column}.',
|
|
58
|
+
});
|
|
59
|
+
const INTERACTIVE = 'a[href], button, input, select, textarea, label, summary, [contenteditable], [tabindex]:not([tabindex="-1"]), cm-button, cm-action-menu, cm-checkbox, cm-toggle, cm-select';
|
|
60
|
+
const NO_DRAG = 'input, select, textarea, [contenteditable], cm-action-menu, cm-select, cm-text-field, [data-no-drag]';
|
|
61
|
+
/**
|
|
62
|
+
* One record on a `cm-board`: a title (`heading`, or a link in the `heading` slot), secondary lines, badges and an
|
|
63
|
+
* avatar. The whole card is the move handle: drag it, or focus it and press Space to move it with the keyboard.
|
|
64
|
+
* With `href` the title is a link and Enter on the card opens it.
|
|
65
|
+
* @element cm-board-card
|
|
66
|
+
* @slot - Secondary lines under the title (owner, phone, city), one element per line.
|
|
67
|
+
* @slot heading - Rich title instead of `heading`, e.g. a link. A link here is a second Tab stop; prefer `href`.
|
|
68
|
+
* @slot badges - `cm-badge`s (grade, tags) under the lines.
|
|
69
|
+
* @slot avatar - A `cm-avatar` for the owner, at the end of the title line.
|
|
70
|
+
* @slot actions - A small control at the end of the title line, e.g. a `cm-action-menu` with "Move to…". Pressing it never starts a drag.
|
|
71
|
+
* @csspart card - The card's box.
|
|
72
|
+
* @csspart handle - The focusable layer under the content that carries the card's name and instructions.
|
|
73
|
+
* @csspart title - The title.
|
|
74
|
+
*/
|
|
75
|
+
export class CmBoardCard extends CmLocalizedElement {
|
|
76
|
+
constructor() {
|
|
77
|
+
super(...arguments);
|
|
78
|
+
_CmBoardCard_instances.add(this);
|
|
79
|
+
/** Identifies the record in `cm-move` (e.g. its id). Defaults to the card's name. */
|
|
80
|
+
this.value = '';
|
|
81
|
+
/** The card's name, read by screen readers and in announcements ("Picked up Ravi Stores"). Defaults to `heading` or the `heading` slot's text. */
|
|
82
|
+
this.label = '';
|
|
83
|
+
/** The title: the record's name. */
|
|
84
|
+
this.heading = '';
|
|
85
|
+
/** Makes the title a link to the record. Enter on the focused card opens it too. */
|
|
86
|
+
this.href = '';
|
|
87
|
+
/** The card can't be moved (e.g. no permission). It can still be opened. */
|
|
88
|
+
this.locked = false;
|
|
89
|
+
/** The move is being saved: the card is greyed with a spinner and can't be moved again until it is cleared. Set by `waitUntil()` in `cm-move`, or by you. */
|
|
90
|
+
this.pending = false;
|
|
91
|
+
/** Set by the board while the card is picked up or dragged; it then marks where the card came from. Read it for styling; don't set it. */
|
|
92
|
+
this.moving = false;
|
|
93
|
+
this._badges = false;
|
|
94
|
+
this._slottedTitle = '';
|
|
95
|
+
_CmBoardCard_id.set(this, nextId('cm-bc'));
|
|
96
|
+
}
|
|
97
|
+
/** The card's name: `label`, `heading`, the `heading` slot's text, or its first line of text. */
|
|
98
|
+
get name() {
|
|
99
|
+
const text = (s) => (s ?? '').replace(/\s+/g, ' ').trim();
|
|
100
|
+
if (this.label)
|
|
101
|
+
return this.label;
|
|
102
|
+
if (this.heading)
|
|
103
|
+
return this.heading;
|
|
104
|
+
const slotted = this.querySelector(':scope > [slot="heading"]');
|
|
105
|
+
if (slotted)
|
|
106
|
+
return text(slotted.textContent);
|
|
107
|
+
return text(this.textContent).slice(0, 80);
|
|
108
|
+
}
|
|
109
|
+
/** The value used in `cm-move`: `value`, or the name. */
|
|
110
|
+
get key() { return this.value || this.name; }
|
|
111
|
+
/** The link or button that opens the record: the `href` title, or the first link or button in the `heading` slot. */
|
|
112
|
+
get opener() {
|
|
113
|
+
if (this.href)
|
|
114
|
+
return this.renderRoot?.querySelector('.title a') ?? null;
|
|
115
|
+
const h = this.querySelector(':scope > [slot="heading"]');
|
|
116
|
+
if (!h)
|
|
117
|
+
return null;
|
|
118
|
+
return (h.matches('a[href], button, cm-button') ? h : h.querySelector('a[href], button, cm-button'));
|
|
119
|
+
}
|
|
120
|
+
/** Focuses the card's handle (its single Tab stop), even when a control inside the card has focus. */
|
|
121
|
+
focusHandle(options) {
|
|
122
|
+
const h = this.renderRoot?.querySelector('.handle');
|
|
123
|
+
if (h)
|
|
124
|
+
h.focus(options);
|
|
125
|
+
else
|
|
126
|
+
this.focus(options);
|
|
127
|
+
}
|
|
128
|
+
/** Opens the record: clicks the `href` title or the link or button in the `heading` slot. Returns false when there is none. */
|
|
129
|
+
open() {
|
|
130
|
+
const o = this.opener;
|
|
131
|
+
if (!o)
|
|
132
|
+
return false;
|
|
133
|
+
o.click();
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
render() {
|
|
137
|
+
const openable = !!(this.href || this.querySelector(':scope > [slot="heading"] a[href], :scope > [slot="heading"] button, :scope > a[slot="heading"][href], :scope > button[slot="heading"]'));
|
|
138
|
+
const busy = this.pending;
|
|
139
|
+
return html `<div class="card" part="card">
|
|
140
|
+
${this.locked
|
|
141
|
+
? nothing
|
|
142
|
+
: html `<div class="handle" part="handle" tabindex="0" role="button" aria-roledescription=${this.t('roleDescription')}
|
|
143
|
+
aria-label=${busy ? `${this.name}, ${this.t('saving')}` : this.name} aria-describedby="${__classPrivateFieldGet(this, _CmBoardCard_id, "f")}-help"></div>`}
|
|
144
|
+
<div class="content">
|
|
145
|
+
<div class="head">
|
|
146
|
+
<div class="title" part="title"><slot name="heading" @slotchange=${() => this.requestUpdate()}>${this.href
|
|
147
|
+
? html `<a href=${this.href} tabindex="-1">${this.heading}</a>` : this.heading}</slot></div>
|
|
148
|
+
<slot name="avatar"></slot>
|
|
149
|
+
<slot name="actions"></slot>
|
|
150
|
+
</div>
|
|
151
|
+
<div class="lines"><slot></slot></div>
|
|
152
|
+
<div class="badges" ?hidden=${!this._badges}><slot name="badges" @slotchange=${(e) => __classPrivateFieldGet(this, _CmBoardCard_instances, "m", _CmBoardCard_slotted).call(this, e, '_badges')}></slot></div>
|
|
153
|
+
</div>
|
|
154
|
+
${busy ? html `<cm-spinner class="spin" size="small" accessible-label=${this.t('saving')} aria-hidden="true"></cm-spinner>` : nothing}
|
|
155
|
+
<span id="${__classPrivateFieldGet(this, _CmBoardCard_id, "f")}-help" hidden>${openable ? `${this.t('openHint')} ` : ''}${this.t('instructions')}</span>
|
|
156
|
+
</div>`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
_CmBoardCard_id = new WeakMap(), _CmBoardCard_instances = new WeakSet(), _CmBoardCard_slotted = function _CmBoardCard_slotted(e, prop) {
|
|
160
|
+
this[prop] = e.target.assignedElements({ flatten: true }).length > 0;
|
|
161
|
+
};
|
|
162
|
+
CmBoardCard.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
163
|
+
CmBoardCard.properties = {
|
|
164
|
+
value: { reflect: true },
|
|
165
|
+
label: {},
|
|
166
|
+
heading: {},
|
|
167
|
+
href: {},
|
|
168
|
+
locked: { type: Boolean, reflect: true },
|
|
169
|
+
pending: { type: Boolean, reflect: true },
|
|
170
|
+
moving: { type: Boolean, reflect: true },
|
|
171
|
+
_badges: { state: true },
|
|
172
|
+
_slottedTitle: { state: true },
|
|
173
|
+
};
|
|
174
|
+
CmBoardCard.styles = [
|
|
175
|
+
base,
|
|
176
|
+
css `
|
|
177
|
+
:host { display: block; position: relative; -webkit-touch-callout: none; font-size: 14px; line-height: 20px; }
|
|
178
|
+
.card {
|
|
179
|
+
position: relative; display: block; padding: var(--cm-space-12) var(--cm-space-15); background: var(--cm-bg-surface);
|
|
180
|
+
border: var(--cm-border-1) solid var(--cm-border-card); border-radius: var(--cm-radius-md); cursor: grab;
|
|
181
|
+
}
|
|
182
|
+
:host([locked]) .card { cursor: default; }
|
|
183
|
+
.handle { position: absolute; inset: 0; z-index: 0; border-radius: inherit; outline: none; }
|
|
184
|
+
.handle:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
185
|
+
.content { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
186
|
+
.head { display: flex; align-items: flex-start; gap: var(--cm-space-10); }
|
|
187
|
+
.title { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
|
|
188
|
+
.title a { color: inherit; text-decoration: none; }
|
|
189
|
+
.title a:hover { text-decoration: underline; }
|
|
190
|
+
.lines { display: flex; flex-direction: column; font-size: 12px; line-height: 16px; color: var(--cm-text-tertiary); overflow-wrap: anywhere; }
|
|
191
|
+
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-block-start: 6px; }
|
|
192
|
+
.badges[hidden] { display: none; }
|
|
193
|
+
::slotted([slot='avatar']), ::slotted([slot='actions']) { flex: none; }
|
|
194
|
+
.spin { position: absolute; z-index: 2; inset-block-start: var(--cm-space-10); inset-inline-end: var(--cm-space-10); }
|
|
195
|
+
:host([pending]) .card { background: var(--cm-bg-page); cursor: progress; }
|
|
196
|
+
:host([pending]) .content { padding-inline-end: 24px; }
|
|
197
|
+
:host([moving]) .card { border-style: dashed; border-color: var(--cm-border-strong); background: var(--cm-bg-page); }
|
|
198
|
+
:host([moving]) .content { opacity: 0.5; }
|
|
199
|
+
:host([ghost]) .card { cursor: grabbing; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); border-color: var(--cm-border-default); }
|
|
200
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
201
|
+
`,
|
|
202
|
+
];
|
|
203
|
+
define('cm-board-card', CmBoardCard);
|
|
204
|
+
/**
|
|
205
|
+
* One column of a `cm-board`: a heading with its count, the cards as a list, and "Load more" when there are more
|
|
206
|
+
* cards than are loaded.
|
|
207
|
+
* @element cm-board-column
|
|
208
|
+
* @slot - `cm-board-card` elements, in order. Other children are not shown.
|
|
209
|
+
* @slot actions - A small control at the end of the heading row, e.g. an icon-only "Add" button.
|
|
210
|
+
* @slot empty - Shown in a column with no cards, instead of "No cards".
|
|
211
|
+
* @fires cm-load-more - When "Load more" is pressed. `detail: { column, value }`. Set `loading`, append the cards, then clear `loading` (and `has-more` on the last page).
|
|
212
|
+
* @csspart header - The heading row.
|
|
213
|
+
* @csspart count - The count.
|
|
214
|
+
* @csspart list - The `<ul>` of cards.
|
|
215
|
+
* @csspart more - The Load more button.
|
|
216
|
+
*/
|
|
217
|
+
export class CmBoardColumn extends CmLocalizedElement {
|
|
218
|
+
constructor() {
|
|
219
|
+
super(...arguments);
|
|
220
|
+
_CmBoardColumn_instances.add(this);
|
|
221
|
+
/** Identifies the column in `cm-move` (e.g. the status id). Defaults to `heading`. */
|
|
222
|
+
this.value = '';
|
|
223
|
+
/** The column's name, e.g. the status "Contacted". */
|
|
224
|
+
this.heading = '';
|
|
225
|
+
/** Shows "Load more", which fires `cm-load-more`. Also shown when `total` is more than the cards loaded. */
|
|
226
|
+
this.hasMore = false;
|
|
227
|
+
/** Cards are loading: Load more shows a spinner, or placeholder cards show in an empty column. Announced politely. */
|
|
228
|
+
this.loading = false;
|
|
229
|
+
/** Level of the heading for screen readers (2 to 6). */
|
|
230
|
+
this.headingLevel = 3;
|
|
231
|
+
_CmBoardColumn_collapsed.set(this, false);
|
|
232
|
+
this._cards = [];
|
|
233
|
+
/** @internal The drop placeholder, set by the board while a card is moved. */
|
|
234
|
+
this._drop = null;
|
|
235
|
+
_CmBoardColumn_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmBoardColumn_instances, "m", _CmBoardColumn_read).call(this)));
|
|
236
|
+
_CmBoardColumn_id.set(this, nextId('cm-col'));
|
|
237
|
+
_CmBoardColumn_moreFocused.set(this, false);
|
|
238
|
+
}
|
|
239
|
+
/** Whether the column is shown as a narrow rail: the board has `hide-empty` and the column is empty. Also the `collapsed` attribute, for styling. */
|
|
240
|
+
get collapsed() { return __classPrivateFieldGet(this, _CmBoardColumn_collapsed, "f"); }
|
|
241
|
+
connectedCallback() {
|
|
242
|
+
super.connectedCallback();
|
|
243
|
+
__classPrivateFieldGet(this, _CmBoardColumn_instances, "m", _CmBoardColumn_read).call(this);
|
|
244
|
+
__classPrivateFieldGet(this, _CmBoardColumn_observer, "f").observe(this, { childList: true, attributes: true, attributeFilter: ['slot'] });
|
|
245
|
+
}
|
|
246
|
+
disconnectedCallback() {
|
|
247
|
+
super.disconnectedCallback();
|
|
248
|
+
__classPrivateFieldGet(this, _CmBoardColumn_observer, "f").disconnect();
|
|
249
|
+
}
|
|
250
|
+
/** The `cm-board-card` children, in order. */
|
|
251
|
+
get cards() {
|
|
252
|
+
return [...this.children].filter((c) => c.localName === 'cm-board-card' && !c.hasAttribute('slot'));
|
|
253
|
+
}
|
|
254
|
+
/** The column's `value`, or its heading. */
|
|
255
|
+
get key() { return this.value || this.heading; }
|
|
256
|
+
/** The number shown in the heading: `total`, or the cards loaded. */
|
|
257
|
+
get count() {
|
|
258
|
+
return typeof this.total === 'number' && !Number.isNaN(this.total) ? this.total : this._cards.length;
|
|
259
|
+
}
|
|
260
|
+
/** @internal The element that scrolls the cards. */
|
|
261
|
+
get scrollElement() { return this.renderRoot?.querySelector('.scroll') ?? null; }
|
|
262
|
+
/** @internal Reads the cards now (after the board moved one) and resolves once they are shown. */
|
|
263
|
+
_sync() {
|
|
264
|
+
__classPrivateFieldGet(this, _CmBoardColumn_instances, "m", _CmBoardColumn_read).call(this);
|
|
265
|
+
return this.updateComplete;
|
|
266
|
+
}
|
|
267
|
+
willUpdate() {
|
|
268
|
+
const board = this.closest('cm-board');
|
|
269
|
+
__classPrivateFieldSet(this, _CmBoardColumn_collapsed, !!board?.hideEmpty && !this._cards.length && !this.loading && !(this.count > 0), "f");
|
|
270
|
+
this.toggleAttribute('collapsed', __classPrivateFieldGet(this, _CmBoardColumn_collapsed, "f"));
|
|
271
|
+
__classPrivateFieldSet(this, _CmBoardColumn_moreFocused, this.renderRoot?.activeElement?.localName === 'cm-button', "f");
|
|
272
|
+
}
|
|
273
|
+
updated() {
|
|
274
|
+
// Manual slot assignment: each card goes into the slot inside its own <li>, so the column is a real list.
|
|
275
|
+
const slots = this.renderRoot.querySelectorAll('li > slot');
|
|
276
|
+
slots.forEach((s) => { const c = this._cards[Number(s.dataset.i)]; if (c)
|
|
277
|
+
s.assign(c);
|
|
278
|
+
else
|
|
279
|
+
s.assign(); });
|
|
280
|
+
const named = (name) => [...this.children].filter((c) => c.getAttribute('slot') === name);
|
|
281
|
+
this.renderRoot.querySelector('slot.actions')?.assign(...named('actions'));
|
|
282
|
+
this.renderRoot.querySelector('slot.empty')?.assign(...named('empty'));
|
|
283
|
+
if (__classPrivateFieldGet(this, _CmBoardColumn_moreFocused, "f") && !this.renderRoot.querySelector('.more cm-button')) {
|
|
284
|
+
__classPrivateFieldSet(this, _CmBoardColumn_moreFocused, false, "f");
|
|
285
|
+
this.renderRoot.querySelector('ul')?.focus();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
render() {
|
|
289
|
+
const cards = this._cards;
|
|
290
|
+
const drop = this._drop;
|
|
291
|
+
const count = this.count;
|
|
292
|
+
const others = drop ? cards.filter((c) => c !== drop.card) : cards;
|
|
293
|
+
// No placeholder where the card already is: its own (dimmed) place marks the spot.
|
|
294
|
+
const from = drop ? cards.indexOf(drop.card) : -1;
|
|
295
|
+
const showDrop = !!drop && !this.collapsed && !(from >= 0 && drop.index === from);
|
|
296
|
+
const rows = [];
|
|
297
|
+
cards.forEach((c, i) => {
|
|
298
|
+
if (showDrop && c !== drop.card && others.indexOf(c) === drop.index)
|
|
299
|
+
rows.push({ key: 'drop' });
|
|
300
|
+
rows.push({ key: c, card: c, i });
|
|
301
|
+
});
|
|
302
|
+
if (showDrop && drop.index >= others.length)
|
|
303
|
+
rows.push({ key: 'drop' });
|
|
304
|
+
const more = this.hasMore || count > cards.length;
|
|
305
|
+
const busy = this.loading;
|
|
306
|
+
const level = Math.min(6, Math.max(2, Math.round(this.headingLevel) || 3));
|
|
307
|
+
const countText = this.t('count', { count });
|
|
308
|
+
return html `<section aria-labelledby="${__classPrivateFieldGet(this, _CmBoardColumn_id, "f")}-h" class=${drop && this.collapsed ? 'over' : ''}>
|
|
309
|
+
<header part="header">
|
|
310
|
+
<div class="title" id="${__classPrivateFieldGet(this, _CmBoardColumn_id, "f")}-h" role="heading" aria-level=${level}>${this.heading}<span class="sr">, ${countText}</span></div>
|
|
311
|
+
<span class="count" part="count" aria-hidden="true">${this.formatNumber(count)}</span>
|
|
312
|
+
<span class="actions"><slot class="actions"></slot></span>
|
|
313
|
+
</header>
|
|
314
|
+
<div class="scroll">
|
|
315
|
+
<ul part="list" role="list" aria-labelledby="${__classPrivateFieldGet(this, _CmBoardColumn_id, "f")}-h" aria-busy=${busy ? 'true' : 'false'} tabindex="-1" ?hidden=${this.collapsed}>
|
|
316
|
+
${repeat(rows, (r) => r.key, (r) => r.card
|
|
317
|
+
? html `<li><slot data-i=${r.i}></slot></li>`
|
|
318
|
+
: html `<li class="drop" aria-hidden="true"><div style="min-height:${Math.max(40, drop.height)}px">${drop.card.name}</div></li>`)}
|
|
319
|
+
</ul>
|
|
320
|
+
${busy && !cards.length && !this.collapsed
|
|
321
|
+
? html `<div class="loading" aria-hidden="true"><cm-skeleton variant="block"></cm-skeleton><cm-skeleton variant="block"></cm-skeleton></div>`
|
|
322
|
+
: nothing}
|
|
323
|
+
<div class="empty" ?hidden=${cards.length > 0 || busy || more || this.collapsed || showDrop}><slot class="empty">${this.t('empty')}</slot></div>
|
|
324
|
+
${more && !this.collapsed
|
|
325
|
+
? html `<div class="more"><cm-button part="more" size="medium" ?loading=${busy} @click=${__classPrivateFieldGet(this, _CmBoardColumn_instances, "m", _CmBoardColumn_more)}>${this.t('loadMore')}</cm-button></div>`
|
|
326
|
+
: nothing}
|
|
327
|
+
</div>
|
|
328
|
+
<span class="sr" role="status">${busy ? this.t('loading', { column: this.heading }) : ''}</span>
|
|
329
|
+
</section>`;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
_CmBoardColumn_collapsed = new WeakMap(), _CmBoardColumn_observer = new WeakMap(), _CmBoardColumn_id = new WeakMap(), _CmBoardColumn_moreFocused = new WeakMap(), _CmBoardColumn_instances = new WeakSet(), _CmBoardColumn_read = function _CmBoardColumn_read() {
|
|
333
|
+
this._cards = this.cards;
|
|
334
|
+
}, _CmBoardColumn_more = function _CmBoardColumn_more() {
|
|
335
|
+
if (this.loading)
|
|
336
|
+
return;
|
|
337
|
+
this.dispatchEvent(new CustomEvent('cm-load-more', { detail: { column: this, value: this.key }, bubbles: true, composed: true }));
|
|
338
|
+
};
|
|
339
|
+
CmBoardColumn.shadowRootOptions = { ...LitElement.shadowRootOptions, slotAssignment: 'manual' };
|
|
340
|
+
CmBoardColumn.properties = {
|
|
341
|
+
value: { reflect: true },
|
|
342
|
+
heading: {},
|
|
343
|
+
total: { type: Number },
|
|
344
|
+
hasMore: { type: Boolean, attribute: 'has-more', reflect: true },
|
|
345
|
+
loading: { type: Boolean, reflect: true },
|
|
346
|
+
headingLevel: { type: Number, attribute: 'heading-level' },
|
|
347
|
+
_cards: { state: true },
|
|
348
|
+
_drop: { state: true },
|
|
349
|
+
};
|
|
350
|
+
CmBoardColumn.styles = [
|
|
351
|
+
base,
|
|
352
|
+
css `
|
|
353
|
+
:host {
|
|
354
|
+
display: flex; flex-direction: column; flex: none; min-height: 0; max-height: 100%;
|
|
355
|
+
inline-size: var(--cm-board-column-width, 272px);
|
|
356
|
+
}
|
|
357
|
+
:host([collapsed]) { inline-size: 48px; }
|
|
358
|
+
section {
|
|
359
|
+
position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; background: var(--cm-bg-page);
|
|
360
|
+
border: var(--cm-border-1) solid var(--cm-border-card); border-radius: var(--cm-radius-md);
|
|
361
|
+
}
|
|
362
|
+
header { display: flex; align-items: center; gap: var(--cm-space-10); min-height: 48px; padding: var(--cm-space-10) var(--cm-space-15); }
|
|
363
|
+
.title { flex: 1; min-width: 0; margin: 0; font-size: 14px; line-height: 20px; font-weight: 500; overflow-wrap: anywhere; }
|
|
364
|
+
.count {
|
|
365
|
+
flex: none; min-width: 24px; padding: 0 8px; font-size: 12px; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums;
|
|
366
|
+
background: var(--cm-bg-surface); color: var(--cm-text-default); border-radius: var(--cm-radius-full);
|
|
367
|
+
}
|
|
368
|
+
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--cm-space-10) var(--cm-space-10); }
|
|
369
|
+
ul { display: flex; flex-direction: column; gap: var(--cm-space-10); margin: 0; padding: 0; list-style: none; }
|
|
370
|
+
ul:focus { outline: none; }
|
|
371
|
+
li { display: block; min-width: 0; }
|
|
372
|
+
.drop > div {
|
|
373
|
+
display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 var(--cm-space-15);
|
|
374
|
+
border: 2px dashed var(--cm-border-strong); border-radius: var(--cm-radius-md); background: var(--cm-bg-surface);
|
|
375
|
+
color: var(--cm-text-tertiary); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
|
|
376
|
+
}
|
|
377
|
+
.empty { padding: var(--cm-space-15) var(--cm-space-10); font-size: 12px; color: var(--cm-text-tertiary); text-align: center; }
|
|
378
|
+
.loading { display: grid; gap: var(--cm-space-10); }
|
|
379
|
+
.loading cm-skeleton { --cm-skeleton-height: 72px; }
|
|
380
|
+
.more { display: flex; justify-content: center; padding-block-start: var(--cm-space-10); }
|
|
381
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
382
|
+
[hidden] { display: none !important; }
|
|
383
|
+
/* Rail: the heading turned on its side, the count on top. Still a drop target. */
|
|
384
|
+
:host([collapsed]) header { flex-direction: column; justify-content: flex-start; padding: var(--cm-space-10) 0; gap: var(--cm-space-10); }
|
|
385
|
+
:host([collapsed]) .title { flex: none; writing-mode: vertical-rl; white-space: nowrap; overflow-wrap: normal; }
|
|
386
|
+
:host([collapsed]) .scroll { padding: 0; overflow: hidden; }
|
|
387
|
+
:host([collapsed]) .actions { display: none; }
|
|
388
|
+
:host([collapsed]) section.over { outline: 2px dashed var(--cm-border-strong); outline-offset: -2px; }
|
|
389
|
+
`,
|
|
390
|
+
];
|
|
391
|
+
define('cm-board-column', CmBoardColumn);
|
|
392
|
+
/**
|
|
393
|
+
* A board of records by status (Kanban): one `cm-board-column` per status with its count, and `cm-board-card`s
|
|
394
|
+
* that move between columns, with a pointer (mouse, touch, pen) or with the keyboard.
|
|
395
|
+
*
|
|
396
|
+
* Moving: drag a card (on touch, press and hold first), or focus it and press Space, choose a column and position
|
|
397
|
+
* with the arrow keys, and drop with Space or Enter (Escape cancels). Every step is announced. Each move fires
|
|
398
|
+
* `cm-move`, which you can cancel. By default the board then moves the card element itself; with `controlled` it
|
|
399
|
+
* leaves the DOM to you (React, Vue, anything that renders from data).
|
|
400
|
+
*
|
|
401
|
+
* Columns are fixed-width side by side and the board scrolls sideways; when the board is 480px wide or less each
|
|
402
|
+
* column takes nearly the whole width and the board snaps from column to column. Give the board a height (CSS
|
|
403
|
+
* `height` or `block-size`) to make columns scroll on their own.
|
|
404
|
+
* @element cm-board
|
|
405
|
+
* @slot - `cm-board-column` elements, in order.
|
|
406
|
+
* @fires cm-move - Before a card moves. Cancelable: `preventDefault()` keeps it where it was. `detail: { value, card, from, to, fromColumn, toColumn, fromIndex, toIndex, source, waitUntil }` (see `BoardMoveDetail`). Pass the save request to `detail.waitUntil(promise)` to show the card as saving and put it back if the promise rejects.
|
|
407
|
+
* @fires cm-load-more - From a column's Load more button (bubbles from `cm-board-column`). `detail: { column, value }`.
|
|
408
|
+
* @csspart columns - The scrolling row of columns.
|
|
409
|
+
* @cssprop --cm-board-column-width - Width of each column on wide boards. Default 272px.
|
|
410
|
+
*/
|
|
411
|
+
export class CmBoard extends CmLocalizedElement {
|
|
412
|
+
constructor() {
|
|
413
|
+
super();
|
|
414
|
+
_CmBoard_instances.add(this);
|
|
415
|
+
/** Empty columns shrink to a narrow rail (heading on its side and the count). Rails still take cards: drop on them or move to them with the keyboard. */
|
|
416
|
+
this.hideEmpty = false;
|
|
417
|
+
/**
|
|
418
|
+
* You move the cards: the board fires `cm-move` but never moves card elements or changes `total`. Re-render the
|
|
419
|
+
* card into its new column (and update totals) in your `cm-move` listener. Use it with React, Vue and other
|
|
420
|
+
* frameworks that render from data. `preventDefault()` still means the move was refused.
|
|
421
|
+
*/
|
|
422
|
+
this.controlled = false;
|
|
423
|
+
/** Set while a card is being dragged with a pointer. Read it for styling; don't set it. */
|
|
424
|
+
this.dragging = false;
|
|
425
|
+
_CmBoard_announcer.set(this, new Announcer());
|
|
426
|
+
_CmBoard_model.set(this, void 0);
|
|
427
|
+
_CmBoard_held.set(this, null);
|
|
428
|
+
_CmBoard_history.set(this, new WeakMap());
|
|
429
|
+
_CmBoard_drag.set(this, null);
|
|
430
|
+
_CmBoard_onKey.set(this, (e) => {
|
|
431
|
+
if (__classPrivateFieldGet(this, _CmBoard_drag, "f")?.started && e.key === 'Escape') {
|
|
432
|
+
e.preventDefault();
|
|
433
|
+
this.cancelMove();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const key = logicalKey(e, this);
|
|
437
|
+
if (__classPrivateFieldGet(this, _CmBoard_model, "f").active) {
|
|
438
|
+
if (__classPrivateFieldGet(this, _CmBoard_model, "f").handleKey(e, key)) {
|
|
439
|
+
e.preventDefault();
|
|
440
|
+
e.stopPropagation();
|
|
441
|
+
}
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const card = __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_handleOf).call(this, e.composedPath());
|
|
445
|
+
if (!card || e.altKey || e.ctrlKey || e.metaKey)
|
|
446
|
+
return;
|
|
447
|
+
if (e.key === ' ') {
|
|
448
|
+
e.preventDefault();
|
|
449
|
+
this.pickUp(card);
|
|
450
|
+
}
|
|
451
|
+
else if (e.key === 'Enter') {
|
|
452
|
+
if (card.open())
|
|
453
|
+
e.preventDefault();
|
|
454
|
+
}
|
|
455
|
+
else if (key.startsWith('Arrow')) {
|
|
456
|
+
const next = __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_neighbour).call(this, card, key);
|
|
457
|
+
if (next) {
|
|
458
|
+
e.preventDefault();
|
|
459
|
+
next.focusHandle();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
_CmBoard_onFocusOut.set(this, (e) => {
|
|
464
|
+
if (!__classPrivateFieldGet(this, _CmBoard_model, "f").active || !__classPrivateFieldGet(this, _CmBoard_held, "f"))
|
|
465
|
+
return;
|
|
466
|
+
// Focus left the held card (a click elsewhere, the window lost focus while still on it is fine).
|
|
467
|
+
const to = e.relatedTarget;
|
|
468
|
+
if (to && (to === __classPrivateFieldGet(this, _CmBoard_held, "f").card || __classPrivateFieldGet(this, _CmBoard_held, "f").card.contains(to)))
|
|
469
|
+
return;
|
|
470
|
+
if (!to && document.hasFocus() === false)
|
|
471
|
+
return;
|
|
472
|
+
queueMicrotask(() => {
|
|
473
|
+
if (__classPrivateFieldGet(this, _CmBoard_model, "f").active && __classPrivateFieldGet(this, _CmBoard_held, "f") && !__classPrivateFieldGet(this, _CmBoard_held, "f").card.matches(':focus-within'))
|
|
474
|
+
__classPrivateFieldGet(this, _CmBoard_model, "f").cancel();
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
/* ---------- Pointer drag ---------- */
|
|
478
|
+
_CmBoard_onNativeDrag.set(this, (e) => {
|
|
479
|
+
if (e.composedPath().some((n) => n.localName === 'cm-board-card'))
|
|
480
|
+
e.preventDefault();
|
|
481
|
+
});
|
|
482
|
+
_CmBoard_onPointerDown.set(this, (e) => {
|
|
483
|
+
if (__classPrivateFieldGet(this, _CmBoard_drag, "f") || !e.isPrimary || (e.pointerType === 'mouse' && e.button !== 0))
|
|
484
|
+
return;
|
|
485
|
+
const path = e.composedPath();
|
|
486
|
+
const card = path.find((n) => n.localName === 'cm-board-card');
|
|
487
|
+
if (!card || card.locked || card.pending)
|
|
488
|
+
return;
|
|
489
|
+
if (path.some((n) => n instanceof Element && n !== card && n.matches?.(NO_DRAG)))
|
|
490
|
+
return;
|
|
491
|
+
const at = __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_place).call(this, card);
|
|
492
|
+
if (!at)
|
|
493
|
+
return;
|
|
494
|
+
if (__classPrivateFieldGet(this, _CmBoard_model, "f").active)
|
|
495
|
+
__classPrivateFieldGet(this, _CmBoard_model, "f").cancel();
|
|
496
|
+
const r = card.getBoundingClientRect();
|
|
497
|
+
__classPrivateFieldSet(this, _CmBoard_drag, {
|
|
498
|
+
card, pointerId: e.pointerId, type: e.pointerType, x0: e.clientX, y0: e.clientY, x: e.clientX, y: e.clientY, started: false,
|
|
499
|
+
dx: e.clientX - r.left, dy: e.clientY - r.top, width: r.width, height: r.height, from: at.column, fromIndex: at.index,
|
|
500
|
+
}, "f");
|
|
501
|
+
if (e.pointerType !== 'mouse') {
|
|
502
|
+
// Touch and pen: press and hold to pick up, so a swipe still scrolls.
|
|
503
|
+
__classPrivateFieldGet(this, _CmBoard_drag, "f").timer = setTimeout(() => { if (__classPrivateFieldGet(this, _CmBoard_drag, "f") && !__classPrivateFieldGet(this, _CmBoard_drag, "f").started)
|
|
504
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_startDrag).call(this); }, 300);
|
|
505
|
+
}
|
|
506
|
+
window.addEventListener('pointermove', __classPrivateFieldGet(this, _CmBoard_onPointerMove, "f"), true);
|
|
507
|
+
window.addEventListener('pointerup', __classPrivateFieldGet(this, _CmBoard_onPointerUp, "f"), true);
|
|
508
|
+
window.addEventListener('pointercancel', __classPrivateFieldGet(this, _CmBoard_onPointerCancel, "f"), true);
|
|
509
|
+
window.addEventListener('touchmove', __classPrivateFieldGet(this, _CmBoard_onTouchMove, "f"), { capture: true, passive: false });
|
|
510
|
+
window.addEventListener('contextmenu', __classPrivateFieldGet(this, _CmBoard_onContextMenu, "f"), true);
|
|
511
|
+
});
|
|
512
|
+
_CmBoard_onTouchMove.set(this, (e) => { if (__classPrivateFieldGet(this, _CmBoard_drag, "f")?.started && e.cancelable)
|
|
513
|
+
e.preventDefault(); });
|
|
514
|
+
_CmBoard_onContextMenu.set(this, (e) => { if (__classPrivateFieldGet(this, _CmBoard_drag, "f"))
|
|
515
|
+
e.preventDefault(); });
|
|
516
|
+
_CmBoard_onPointerMove.set(this, (e) => {
|
|
517
|
+
const d = __classPrivateFieldGet(this, _CmBoard_drag, "f");
|
|
518
|
+
if (!d || e.pointerId !== d.pointerId)
|
|
519
|
+
return;
|
|
520
|
+
d.x = e.clientX;
|
|
521
|
+
d.y = e.clientY;
|
|
522
|
+
if (!d.started) {
|
|
523
|
+
const dist = Math.hypot(d.x - d.x0, d.y - d.y0);
|
|
524
|
+
if (d.type === 'mouse' ? dist > 4 : dist > 8) {
|
|
525
|
+
if (d.type === 'mouse')
|
|
526
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_startDrag).call(this);
|
|
527
|
+
else
|
|
528
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_endDrag).call(this, false); // moved before the hold: it's a scroll
|
|
529
|
+
}
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
e.preventDefault();
|
|
533
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_moveGhost).call(this);
|
|
534
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_updateTarget).call(this);
|
|
535
|
+
});
|
|
536
|
+
_CmBoard_onPointerUp.set(this, (e) => {
|
|
537
|
+
const d = __classPrivateFieldGet(this, _CmBoard_drag, "f");
|
|
538
|
+
if (!d || e.pointerId !== d.pointerId)
|
|
539
|
+
return;
|
|
540
|
+
if (!d.started) {
|
|
541
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_endDrag).call(this, false);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
// The click that follows a drag must not open the card.
|
|
545
|
+
const swallow = (ev) => { ev.stopPropagation(); ev.preventDefault(); };
|
|
546
|
+
window.addEventListener('click', swallow, { capture: true, once: true });
|
|
547
|
+
setTimeout(() => window.removeEventListener('click', swallow, true), 0);
|
|
548
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_endDrag).call(this, true);
|
|
549
|
+
});
|
|
550
|
+
_CmBoard_onPointerCancel.set(this, (e) => {
|
|
551
|
+
if (__classPrivateFieldGet(this, _CmBoard_drag, "f") && e.pointerId === __classPrivateFieldGet(this, _CmBoard_drag, "f").pointerId)
|
|
552
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_endDrag).call(this, false);
|
|
553
|
+
});
|
|
554
|
+
__classPrivateFieldSet(this, _CmBoard_model, new MoveModel({
|
|
555
|
+
groupCount: () => this.columns.length,
|
|
556
|
+
slotCount: (g) => {
|
|
557
|
+
const col = this.columns[g];
|
|
558
|
+
if (!col || !__classPrivateFieldGet(this, _CmBoard_held, "f"))
|
|
559
|
+
return 0;
|
|
560
|
+
return col.cards.filter((c) => c !== __classPrivateFieldGet(this, _CmBoard_held, "f").card).length + 1;
|
|
561
|
+
},
|
|
562
|
+
onTarget: (at) => __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_showTarget).call(this, at),
|
|
563
|
+
onDrop: (from, to) => __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_keyboardDrop).call(this, from, to),
|
|
564
|
+
onCancel: () => __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_release).call(this),
|
|
565
|
+
messages: {
|
|
566
|
+
pickedUp: (at) => __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_say).call(this, 'pickedUp', at),
|
|
567
|
+
over: (at) => __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_say).call(this, 'over', at),
|
|
568
|
+
cancelled: (from) => this.t('cancelled', { card: __classPrivateFieldGet(this, _CmBoard_held, "f")?.card.name ?? '', column: this.columns[from.group]?.heading ?? '' }),
|
|
569
|
+
},
|
|
570
|
+
announce: (text) => __classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(text),
|
|
571
|
+
}), "f");
|
|
572
|
+
}
|
|
573
|
+
/** The `cm-board-column` children, in order. */
|
|
574
|
+
get columns() {
|
|
575
|
+
return [...this.children].filter((c) => c.localName === 'cm-board-column');
|
|
576
|
+
}
|
|
577
|
+
/** The column with this `value` (or heading). */
|
|
578
|
+
column(value) {
|
|
579
|
+
return this.columns.find((c) => c.key === value);
|
|
580
|
+
}
|
|
581
|
+
/** The card with this `value` (or name), in any column. */
|
|
582
|
+
card(value) {
|
|
583
|
+
for (const col of this.columns) {
|
|
584
|
+
const c = col.cards.find((x) => x.key === value);
|
|
585
|
+
if (c)
|
|
586
|
+
return c;
|
|
587
|
+
}
|
|
588
|
+
return undefined;
|
|
589
|
+
}
|
|
590
|
+
/** The card picked up with the keyboard, if any. */
|
|
591
|
+
get heldCard() { return __classPrivateFieldGet(this, _CmBoard_held, "f")?.card ?? null; }
|
|
592
|
+
connectedCallback() {
|
|
593
|
+
super.connectedCallback();
|
|
594
|
+
this.addEventListener('keydown', __classPrivateFieldGet(this, _CmBoard_onKey, "f"));
|
|
595
|
+
this.addEventListener('focusout', __classPrivateFieldGet(this, _CmBoard_onFocusOut, "f"));
|
|
596
|
+
this.addEventListener('pointerdown', __classPrivateFieldGet(this, _CmBoard_onPointerDown, "f"));
|
|
597
|
+
this.addEventListener('dragstart', __classPrivateFieldGet(this, _CmBoard_onNativeDrag, "f"));
|
|
598
|
+
}
|
|
599
|
+
disconnectedCallback() {
|
|
600
|
+
super.disconnectedCallback();
|
|
601
|
+
this.removeEventListener('keydown', __classPrivateFieldGet(this, _CmBoard_onKey, "f"));
|
|
602
|
+
this.removeEventListener('focusout', __classPrivateFieldGet(this, _CmBoard_onFocusOut, "f"));
|
|
603
|
+
this.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmBoard_onPointerDown, "f"));
|
|
604
|
+
this.removeEventListener('dragstart', __classPrivateFieldGet(this, _CmBoard_onNativeDrag, "f"));
|
|
605
|
+
__classPrivateFieldGet(this, _CmBoard_model, "f").cancel(true);
|
|
606
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_endDrag).call(this, false);
|
|
607
|
+
}
|
|
608
|
+
firstUpdated() {
|
|
609
|
+
this.renderRoot.appendChild(__classPrivateFieldGet(this, _CmBoard_announcer, "f").element);
|
|
610
|
+
}
|
|
611
|
+
updated(changed) {
|
|
612
|
+
if (changed.has('hideEmpty'))
|
|
613
|
+
this.columns.forEach((c) => c.requestUpdate());
|
|
614
|
+
}
|
|
615
|
+
/** The last message announced (for tests and logging). */
|
|
616
|
+
get announcement() { return __classPrivateFieldGet(this, _CmBoard_announcer, "f").text; }
|
|
617
|
+
/** Announces a message in the board's live region, e.g. after your own "Move to" menu. */
|
|
618
|
+
announce(text) { __classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(text); }
|
|
619
|
+
/* ---------- Keyboard ---------- */
|
|
620
|
+
/** Picks up a card for moving with the arrow keys, as Space does: e.g. from a "Move" item in your own menu. Focuses the card. */
|
|
621
|
+
pickUp(card) {
|
|
622
|
+
const c = typeof card === 'string' ? this.card(card) : card;
|
|
623
|
+
if (!c || c.locked || c.pending)
|
|
624
|
+
return false;
|
|
625
|
+
const at = __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_place).call(this, c);
|
|
626
|
+
if (!at)
|
|
627
|
+
return false;
|
|
628
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_endDrag).call(this, false);
|
|
629
|
+
__classPrivateFieldGet(this, _CmBoard_model, "f").cancel(true);
|
|
630
|
+
__classPrivateFieldSet(this, _CmBoard_held, { card: c, column: at.column, index: at.index }, "f");
|
|
631
|
+
c.moving = true;
|
|
632
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_focusHandle).call(this, c);
|
|
633
|
+
__classPrivateFieldGet(this, _CmBoard_model, "f").pickUp({ group: at.group, index: at.index });
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
/** Cancels a keyboard move or a drag in progress: the card stays where it was. */
|
|
637
|
+
cancelMove() {
|
|
638
|
+
const d = __classPrivateFieldGet(this, _CmBoard_drag, "f");
|
|
639
|
+
if (d?.started) {
|
|
640
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_endDrag).call(this, false);
|
|
641
|
+
__classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(this.t('cancelled', { card: d.card.name, column: d.from.heading }));
|
|
642
|
+
}
|
|
643
|
+
__classPrivateFieldGet(this, _CmBoard_model, "f").cancel();
|
|
644
|
+
}
|
|
645
|
+
/* ---------- Moving ---------- */
|
|
646
|
+
/**
|
|
647
|
+
* Moves a card to a column and position (default: the end), as a drop would: fires `cm-move`, and unless it is
|
|
648
|
+
* cancelled (or the board is `controlled`) moves the element. Use it for your own "Move to" menu. Returns false
|
|
649
|
+
* when the move was cancelled or the card or column was not found.
|
|
650
|
+
*/
|
|
651
|
+
moveCard(card, to, index) {
|
|
652
|
+
const c = typeof card === 'string' ? this.card(card) : card;
|
|
653
|
+
const col = typeof to === 'string' ? this.column(to) : to;
|
|
654
|
+
if (!c || !col)
|
|
655
|
+
return false;
|
|
656
|
+
const at = __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_place).call(this, c);
|
|
657
|
+
if (!at)
|
|
658
|
+
return false;
|
|
659
|
+
const room = col.cards.filter((x) => x !== c).length;
|
|
660
|
+
const toIndex = Math.max(0, Math.min(index ?? room, room));
|
|
661
|
+
return __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_commit).call(this, c, at.column, at.index, col, toIndex, 'api');
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Puts a card back where it was before its last move by the board, restores the two columns' `total`, clears
|
|
665
|
+
* `pending` and announces it. Call it when saving the move failed (a rejected `waitUntil()` promise does this
|
|
666
|
+
* for you). Does nothing with `controlled` (put it back in your data) or when the card has not moved. Returns
|
|
667
|
+
* whether the card went back.
|
|
668
|
+
*/
|
|
669
|
+
revert(card) {
|
|
670
|
+
const c = typeof card === 'string' ? this.card(card) : card;
|
|
671
|
+
if (!c)
|
|
672
|
+
return false;
|
|
673
|
+
c.pending = false;
|
|
674
|
+
const m = __classPrivateFieldGet(this, _CmBoard_history, "f").get(c);
|
|
675
|
+
if (this.controlled || !m)
|
|
676
|
+
return false;
|
|
677
|
+
__classPrivateFieldGet(this, _CmBoard_history, "f").delete(c);
|
|
678
|
+
if (!m.from.isConnected || !this.contains(m.from))
|
|
679
|
+
return false;
|
|
680
|
+
const hadFocus = c.matches(':focus-within');
|
|
681
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_insert).call(this, c, m.from, m.fromIndex);
|
|
682
|
+
if (m.totals)
|
|
683
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_adjustTotals).call(this, m.to, m.from);
|
|
684
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_shown).call(this, m.to, m.from, hadFocus ? c : null);
|
|
685
|
+
__classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(this.t('reverted', { card: c.name, column: m.from.heading }));
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
render() {
|
|
689
|
+
return html `<div class="board" role="group" aria-label=${this.label}>
|
|
690
|
+
<div class="columns" part="columns"><slot @slotchange=${() => this.requestUpdate()}></slot></div>
|
|
691
|
+
</div>`;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
_CmBoard_announcer = new WeakMap(), _CmBoard_model = new WeakMap(), _CmBoard_held = new WeakMap(), _CmBoard_history = new WeakMap(), _CmBoard_drag = new WeakMap(), _CmBoard_onKey = new WeakMap(), _CmBoard_onFocusOut = new WeakMap(), _CmBoard_onNativeDrag = new WeakMap(), _CmBoard_onPointerDown = new WeakMap(), _CmBoard_onTouchMove = new WeakMap(), _CmBoard_onContextMenu = new WeakMap(), _CmBoard_onPointerMove = new WeakMap(), _CmBoard_onPointerUp = new WeakMap(), _CmBoard_onPointerCancel = new WeakMap(), _CmBoard_instances = new WeakSet(), _CmBoard_say = function _CmBoard_say(key, at) {
|
|
695
|
+
const col = this.columns[at.group];
|
|
696
|
+
return this.t(key, { card: __classPrivateFieldGet(this, _CmBoard_held, "f")?.card.name ?? '', column: col?.heading ?? '', position: at.index + 1, count: __classPrivateFieldGet(this, _CmBoard_model, "f").slotCount(at.group) });
|
|
697
|
+
}, _CmBoard_place = function _CmBoard_place(card) {
|
|
698
|
+
const columns = this.columns;
|
|
699
|
+
const group = columns.findIndex((c) => c.contains(card) && card.parentElement === c);
|
|
700
|
+
if (group < 0)
|
|
701
|
+
return null;
|
|
702
|
+
return { column: columns[group], group, index: columns[group].cards.indexOf(card) };
|
|
703
|
+
}, _CmBoard_focusHandle = function _CmBoard_focusHandle(c) {
|
|
704
|
+
const onHandle = () => !!c.shadowRoot?.activeElement?.classList.contains('handle');
|
|
705
|
+
c.focusHandle({ preventScroll: true });
|
|
706
|
+
requestAnimationFrame(() => { if (__classPrivateFieldGet(this, _CmBoard_held, "f")?.card === c && !onHandle())
|
|
707
|
+
c.focusHandle({ preventScroll: true }); });
|
|
708
|
+
}, _CmBoard_release = function _CmBoard_release() {
|
|
709
|
+
if (__classPrivateFieldGet(this, _CmBoard_held, "f"))
|
|
710
|
+
__classPrivateFieldGet(this, _CmBoard_held, "f").card.moving = false;
|
|
711
|
+
__classPrivateFieldSet(this, _CmBoard_held, null, "f");
|
|
712
|
+
}, _CmBoard_showTarget = function _CmBoard_showTarget(at) {
|
|
713
|
+
const held = __classPrivateFieldGet(this, _CmBoard_held, "f");
|
|
714
|
+
this.columns.forEach((col, g) => {
|
|
715
|
+
col._drop = held && at && g === at.group ? { card: held.card, index: at.index, height: held.card.getBoundingClientRect().height } : null;
|
|
716
|
+
});
|
|
717
|
+
if (at) {
|
|
718
|
+
const col = this.columns[at.group];
|
|
719
|
+
col?.updateComplete.then(() => {
|
|
720
|
+
const el = col.renderRoot.querySelector('li.drop') ?? (held && held.column === col ? held.card : col);
|
|
721
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_reveal).call(this, col, el);
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}, _CmBoard_reveal = function _CmBoard_reveal(col, el) {
|
|
725
|
+
const scroller = this.renderRoot.querySelector('.columns');
|
|
726
|
+
if (scroller) {
|
|
727
|
+
const s = scroller.getBoundingClientRect(), c = col.getBoundingClientRect();
|
|
728
|
+
if (c.left < s.left)
|
|
729
|
+
scroller.scrollLeft -= s.left - c.left + 8;
|
|
730
|
+
else if (c.right > s.right)
|
|
731
|
+
scroller.scrollLeft += c.right - s.right + 8;
|
|
732
|
+
}
|
|
733
|
+
const list = col.scrollElement;
|
|
734
|
+
if (list) {
|
|
735
|
+
const l = list.getBoundingClientRect(), r = el.getBoundingClientRect();
|
|
736
|
+
if (r.top < l.top)
|
|
737
|
+
list.scrollTop -= l.top - r.top + 8;
|
|
738
|
+
else if (r.bottom > l.bottom)
|
|
739
|
+
list.scrollTop += r.bottom - l.bottom + 8;
|
|
740
|
+
}
|
|
741
|
+
}, _CmBoard_keyboardDrop = function _CmBoard_keyboardDrop(from, to) {
|
|
742
|
+
const held = __classPrivateFieldGet(this, _CmBoard_held, "f");
|
|
743
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_release).call(this);
|
|
744
|
+
if (!held)
|
|
745
|
+
return;
|
|
746
|
+
const toCol = this.columns[to.group];
|
|
747
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_commit).call(this, held.card, held.column, from.index, toCol, to.index, 'keyboard');
|
|
748
|
+
}, _CmBoard_handleOf = function _CmBoard_handleOf(path) {
|
|
749
|
+
// The key came from a card's own handle (not a link or control inside it).
|
|
750
|
+
const first = path[0];
|
|
751
|
+
if (!(first instanceof HTMLElement) || !first.classList?.contains('handle'))
|
|
752
|
+
return null;
|
|
753
|
+
const card = path.find((n) => n.localName === 'cm-board-card');
|
|
754
|
+
return card && __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_place).call(this, card) ? card : null;
|
|
755
|
+
}, _CmBoard_neighbour = function _CmBoard_neighbour(card, key) {
|
|
756
|
+
const at = __classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_place).call(this, card);
|
|
757
|
+
if (!at)
|
|
758
|
+
return null;
|
|
759
|
+
const cards = at.column.cards;
|
|
760
|
+
if (key === 'ArrowDown')
|
|
761
|
+
return cards[at.index + 1] ?? null;
|
|
762
|
+
if (key === 'ArrowUp')
|
|
763
|
+
return cards[at.index - 1] ?? null;
|
|
764
|
+
const dir = key === 'ArrowRight' ? 1 : -1;
|
|
765
|
+
const columns = this.columns;
|
|
766
|
+
for (let g = at.group + dir; g >= 0 && g < columns.length; g += dir) {
|
|
767
|
+
const list = columns[g].cards;
|
|
768
|
+
if (list.length)
|
|
769
|
+
return list[Math.min(at.index, list.length - 1)];
|
|
770
|
+
}
|
|
771
|
+
return null;
|
|
772
|
+
}, _CmBoard_shown = function _CmBoard_shown(from, to, focus) {
|
|
773
|
+
from._sync();
|
|
774
|
+
to._sync().then(() => { if (focus?.isConnected)
|
|
775
|
+
focus.focusHandle({ preventScroll: true }); });
|
|
776
|
+
}, _CmBoard_insert = function _CmBoard_insert(card, col, index) {
|
|
777
|
+
const others = col.cards.filter((x) => x !== card);
|
|
778
|
+
const ref = others[index];
|
|
779
|
+
if (ref)
|
|
780
|
+
ref.before(card);
|
|
781
|
+
else if (others.length)
|
|
782
|
+
others[others.length - 1].after(card);
|
|
783
|
+
else
|
|
784
|
+
col.append(card);
|
|
785
|
+
}, _CmBoard_adjustTotals = function _CmBoard_adjustTotals(from, to) {
|
|
786
|
+
if (from === to)
|
|
787
|
+
return;
|
|
788
|
+
if (typeof from.total === 'number')
|
|
789
|
+
from.total = Math.max(0, from.total - 1);
|
|
790
|
+
if (typeof to.total === 'number')
|
|
791
|
+
to.total = to.total + 1;
|
|
792
|
+
}, _CmBoard_commit = function _CmBoard_commit(card, from, fromIndex, to, toIndex, source) {
|
|
793
|
+
const name = card.name;
|
|
794
|
+
if (from === to && fromIndex === toIndex) {
|
|
795
|
+
if (source !== 'api')
|
|
796
|
+
__classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(this.t('sameSpot', { card: name }));
|
|
797
|
+
if (source === 'keyboard')
|
|
798
|
+
card.focusHandle({ preventScroll: true });
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
const waits = [];
|
|
802
|
+
const detail = {
|
|
803
|
+
value: card.key, card, from: from.key, to: to.key, fromColumn: from, toColumn: to, fromIndex, toIndex, source,
|
|
804
|
+
waitUntil: (p) => { waits.push(Promise.resolve(p)); },
|
|
805
|
+
};
|
|
806
|
+
const ok = this.dispatchEvent(new CustomEvent('cm-move', { detail, bubbles: true, composed: true, cancelable: true }));
|
|
807
|
+
if (!ok) {
|
|
808
|
+
__classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(this.t('refused', { card: name, column: to.heading }));
|
|
809
|
+
if (source === 'keyboard')
|
|
810
|
+
card.focusHandle({ preventScroll: true });
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
const count = to.cards.filter((x) => x !== card).length + 1;
|
|
814
|
+
if (!this.controlled) {
|
|
815
|
+
const hadFocus = source === 'keyboard' || card.matches(':focus-within');
|
|
816
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_insert).call(this, card, to, toIndex);
|
|
817
|
+
const totals = from !== to;
|
|
818
|
+
if (totals)
|
|
819
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_adjustTotals).call(this, from, to);
|
|
820
|
+
__classPrivateFieldGet(this, _CmBoard_history, "f").set(card, { card, from, fromIndex, to, toIndex, totals });
|
|
821
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_shown).call(this, from, to, hadFocus ? card : null);
|
|
822
|
+
}
|
|
823
|
+
else if (source === 'keyboard') {
|
|
824
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_refocus).call(this, card.key, to);
|
|
825
|
+
}
|
|
826
|
+
__classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(this.t('moved', { card: name, column: to.heading, position: toIndex + 1, count }));
|
|
827
|
+
if (waits.length) {
|
|
828
|
+
card.pending = true;
|
|
829
|
+
Promise.all(waits).then(() => { card.pending = false; if (!this.controlled)
|
|
830
|
+
__classPrivateFieldGet(this, _CmBoard_history, "f").delete(card); }, () => {
|
|
831
|
+
card.pending = false;
|
|
832
|
+
if (!this.controlled)
|
|
833
|
+
this.revert(card);
|
|
834
|
+
else
|
|
835
|
+
__classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(this.t('reverted', { card: name, column: from.heading }));
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
return true;
|
|
839
|
+
}, _CmBoard_refocus = function _CmBoard_refocus(value, col) {
|
|
840
|
+
const find = () => col.isConnected ? col.cards.find((c) => c.key === value) : undefined;
|
|
841
|
+
const tryFocus = () => {
|
|
842
|
+
const c = find();
|
|
843
|
+
const lost = !document.activeElement || document.activeElement === document.body || !document.activeElement.isConnected;
|
|
844
|
+
if (!c || !(lost || this.contains(document.activeElement)))
|
|
845
|
+
return false;
|
|
846
|
+
col._sync().then(() => c.updateComplete).then(() => { if (c.isConnected)
|
|
847
|
+
c.focusHandle({ preventScroll: true }); });
|
|
848
|
+
return true;
|
|
849
|
+
};
|
|
850
|
+
const mo = new MutationObserver(() => { if (tryFocus())
|
|
851
|
+
mo.disconnect(); });
|
|
852
|
+
mo.observe(this, { childList: true, subtree: true });
|
|
853
|
+
setTimeout(() => mo.disconnect(), 1000);
|
|
854
|
+
}, _CmBoard_startDrag = function _CmBoard_startDrag() {
|
|
855
|
+
const d = __classPrivateFieldGet(this, _CmBoard_drag, "f");
|
|
856
|
+
d.started = true;
|
|
857
|
+
clearTimeout(d.timer);
|
|
858
|
+
getSelection()?.removeAllRanges();
|
|
859
|
+
const ghost = d.card.cloneNode(true);
|
|
860
|
+
ghost.removeAttribute('id');
|
|
861
|
+
ghost.removeAttribute('moving');
|
|
862
|
+
ghost.setAttribute('ghost', '');
|
|
863
|
+
ghost.setAttribute('aria-hidden', 'true');
|
|
864
|
+
ghost.setAttribute('inert', '');
|
|
865
|
+
Object.assign(ghost.style, {
|
|
866
|
+
position: 'fixed', zIndex: '2147483000', left: '0', top: '0', width: `${d.width}px`, margin: '0', pointerEvents: 'none',
|
|
867
|
+
willChange: 'transform',
|
|
868
|
+
});
|
|
869
|
+
// In the document so the page's own styles for the card's content still apply.
|
|
870
|
+
(this.ownerDocument.body ?? this.ownerDocument.documentElement).appendChild(ghost);
|
|
871
|
+
d.ghost = ghost;
|
|
872
|
+
d.card.moving = true;
|
|
873
|
+
this.dragging = true;
|
|
874
|
+
d.to = d.from;
|
|
875
|
+
d.toIndex = d.fromIndex;
|
|
876
|
+
__classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(this.t('pickedUp', {
|
|
877
|
+
card: d.card.name, column: d.from.heading, position: d.fromIndex + 1, count: d.from.cards.length,
|
|
878
|
+
}));
|
|
879
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_moveGhost).call(this);
|
|
880
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_updateTarget).call(this);
|
|
881
|
+
const tick = () => {
|
|
882
|
+
if (!__classPrivateFieldGet(this, _CmBoard_drag, "f")?.started)
|
|
883
|
+
return;
|
|
884
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_autoScroll).call(this);
|
|
885
|
+
__classPrivateFieldGet(this, _CmBoard_drag, "f").raf = requestAnimationFrame(tick);
|
|
886
|
+
};
|
|
887
|
+
d.raf = requestAnimationFrame(tick);
|
|
888
|
+
}, _CmBoard_moveGhost = function _CmBoard_moveGhost() {
|
|
889
|
+
const d = __classPrivateFieldGet(this, _CmBoard_drag, "f");
|
|
890
|
+
if (d?.ghost)
|
|
891
|
+
d.ghost.style.transform = `translate(${d.x - d.dx}px, ${d.y - d.dy}px)`;
|
|
892
|
+
}, _CmBoard_updateTarget = function _CmBoard_updateTarget() {
|
|
893
|
+
const d = __classPrivateFieldGet(this, _CmBoard_drag, "f");
|
|
894
|
+
if (!d)
|
|
895
|
+
return;
|
|
896
|
+
const columns = this.columns;
|
|
897
|
+
if (!columns.length)
|
|
898
|
+
return;
|
|
899
|
+
let best = columns[0], bestDist = Infinity;
|
|
900
|
+
for (const col of columns) {
|
|
901
|
+
const r = col.getBoundingClientRect();
|
|
902
|
+
const dist = d.x < r.left ? r.left - d.x : d.x > r.right ? d.x - r.right : 0;
|
|
903
|
+
if (dist < bestDist) {
|
|
904
|
+
best = col;
|
|
905
|
+
bestDist = dist;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
const others = best.cards.filter((c) => c !== d.card);
|
|
909
|
+
let index = others.length;
|
|
910
|
+
if (!best.collapsed) {
|
|
911
|
+
for (let i = 0; i < others.length; i++) {
|
|
912
|
+
const r = others[i].getBoundingClientRect();
|
|
913
|
+
if (d.y < r.top + r.height / 2) {
|
|
914
|
+
index = i;
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
else
|
|
920
|
+
index = 0;
|
|
921
|
+
if (best === d.to && index === d.toIndex)
|
|
922
|
+
return;
|
|
923
|
+
const changedColumn = best !== d.to;
|
|
924
|
+
d.to = best;
|
|
925
|
+
d.toIndex = index;
|
|
926
|
+
columns.forEach((col) => { col._drop = col === best ? { card: d.card, index, height: d.height } : null; });
|
|
927
|
+
if (changedColumn) {
|
|
928
|
+
__classPrivateFieldGet(this, _CmBoard_announcer, "f").announce(this.t('over', { column: best.heading, position: index + 1, count: others.length + 1 }));
|
|
929
|
+
}
|
|
930
|
+
}, _CmBoard_autoScroll = function _CmBoard_autoScroll() {
|
|
931
|
+
const d = __classPrivateFieldGet(this, _CmBoard_drag, "f");
|
|
932
|
+
if (!d)
|
|
933
|
+
return;
|
|
934
|
+
const EDGE = 48, MAX = 16;
|
|
935
|
+
const speed = (dist) => (dist < EDGE ? Math.ceil(((EDGE - Math.max(dist, 0)) / EDGE) * MAX) : 0);
|
|
936
|
+
let scrolled = false;
|
|
937
|
+
const scroller = this.renderRoot.querySelector('.columns');
|
|
938
|
+
if (scroller) {
|
|
939
|
+
const r = scroller.getBoundingClientRect();
|
|
940
|
+
const left = speed(d.x - r.left), right = speed(r.right - d.x);
|
|
941
|
+
const before = scroller.scrollLeft;
|
|
942
|
+
if (left)
|
|
943
|
+
scroller.scrollLeft -= left;
|
|
944
|
+
else if (right)
|
|
945
|
+
scroller.scrollLeft += right;
|
|
946
|
+
scrolled ||= scroller.scrollLeft !== before;
|
|
947
|
+
}
|
|
948
|
+
const list = d.to?.scrollElement;
|
|
949
|
+
if (list && list.scrollHeight > list.clientHeight) {
|
|
950
|
+
const r = list.getBoundingClientRect();
|
|
951
|
+
if (d.x >= r.left && d.x <= r.right) {
|
|
952
|
+
const up = speed(d.y - r.top), down = speed(r.bottom - d.y);
|
|
953
|
+
const before = list.scrollTop;
|
|
954
|
+
if (up)
|
|
955
|
+
list.scrollTop -= up;
|
|
956
|
+
else if (down)
|
|
957
|
+
list.scrollTop += down;
|
|
958
|
+
scrolled ||= list.scrollTop !== before;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
// A board without a height grows with its cards: scroll the window instead.
|
|
962
|
+
const vh = window.innerHeight;
|
|
963
|
+
const up = speed(d.y), down = speed(vh - d.y);
|
|
964
|
+
if (up || down) {
|
|
965
|
+
const before = window.scrollY;
|
|
966
|
+
window.scrollBy(0, up ? -up : down);
|
|
967
|
+
scrolled ||= window.scrollY !== before;
|
|
968
|
+
}
|
|
969
|
+
if (scrolled)
|
|
970
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_updateTarget).call(this);
|
|
971
|
+
}, _CmBoard_endDrag = function _CmBoard_endDrag(drop) {
|
|
972
|
+
const d = __classPrivateFieldGet(this, _CmBoard_drag, "f");
|
|
973
|
+
if (!d)
|
|
974
|
+
return;
|
|
975
|
+
__classPrivateFieldSet(this, _CmBoard_drag, null, "f");
|
|
976
|
+
clearTimeout(d.timer);
|
|
977
|
+
if (d.raf)
|
|
978
|
+
cancelAnimationFrame(d.raf);
|
|
979
|
+
window.removeEventListener('pointermove', __classPrivateFieldGet(this, _CmBoard_onPointerMove, "f"), true);
|
|
980
|
+
window.removeEventListener('pointerup', __classPrivateFieldGet(this, _CmBoard_onPointerUp, "f"), true);
|
|
981
|
+
window.removeEventListener('pointercancel', __classPrivateFieldGet(this, _CmBoard_onPointerCancel, "f"), true);
|
|
982
|
+
window.removeEventListener('touchmove', __classPrivateFieldGet(this, _CmBoard_onTouchMove, "f"), true);
|
|
983
|
+
window.removeEventListener('contextmenu', __classPrivateFieldGet(this, _CmBoard_onContextMenu, "f"), true);
|
|
984
|
+
d.ghost?.remove();
|
|
985
|
+
if (!d.started)
|
|
986
|
+
return;
|
|
987
|
+
d.card.moving = false;
|
|
988
|
+
this.dragging = false;
|
|
989
|
+
this.columns.forEach((c) => { c._drop = null; });
|
|
990
|
+
if (drop && d.to && d.toIndex !== undefined)
|
|
991
|
+
__classPrivateFieldGet(this, _CmBoard_instances, "m", _CmBoard_commit).call(this, d.card, d.from, d.fromIndex, d.to, d.toIndex, 'pointer');
|
|
992
|
+
};
|
|
993
|
+
CmBoard.properties = {
|
|
994
|
+
label: { string: 'label' },
|
|
995
|
+
hideEmpty: { type: Boolean, attribute: 'hide-empty', reflect: true },
|
|
996
|
+
controlled: { type: Boolean, reflect: true },
|
|
997
|
+
dragging: { type: Boolean, reflect: true },
|
|
998
|
+
};
|
|
999
|
+
CmBoard.styles = [
|
|
1000
|
+
base,
|
|
1001
|
+
css `
|
|
1002
|
+
:host { position: relative; display: block; container-type: inline-size; container-name: cm-board; min-width: 0; }
|
|
1003
|
+
.board { height: 100%; }
|
|
1004
|
+
.columns {
|
|
1005
|
+
position: relative; display: flex; align-items: stretch; gap: var(--cm-space-15); height: 100%; overflow-x: auto; overflow-y: hidden;
|
|
1006
|
+
padding-block-end: var(--cm-space-10); overscroll-behavior-x: contain;
|
|
1007
|
+
}
|
|
1008
|
+
:host([dragging]) .columns { scroll-snap-type: none !important; }
|
|
1009
|
+
:host([dragging]) { cursor: grabbing; user-select: none; -webkit-user-select: none; }
|
|
1010
|
+
@container cm-board (max-width: 480px) {
|
|
1011
|
+
.columns { scroll-snap-type: x mandatory; scroll-padding-inline: 0; gap: var(--cm-space-10); }
|
|
1012
|
+
::slotted(cm-board-column) { inline-size: calc(100% - 40px); scroll-snap-align: start; }
|
|
1013
|
+
::slotted(cm-board-column[collapsed]) { inline-size: 48px; }
|
|
1014
|
+
}
|
|
1015
|
+
`,
|
|
1016
|
+
];
|
|
1017
|
+
define('cm-board', CmBoard);
|