@nldd/design-system 0.13.1 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/NOTICES.md +18 -1
  2. package/README.md +32 -24
  3. package/custom-elements.json +1046 -6
  4. package/dist/components/actions/button-group/button-group.d.ts +22 -7
  5. package/dist/components/actions/button-group/button-group.d.ts.map +1 -1
  6. package/dist/components/actions/button-group/button-group.js +38 -19
  7. package/dist/components/actions/button-group/button-group.js.map +1 -1
  8. package/dist/components/actions/button-group/button-group.styles.d.ts.map +1 -1
  9. package/dist/components/actions/button-group/button-group.styles.js +43 -18
  10. package/dist/components/actions/button-group/button-group.styles.js.map +1 -1
  11. package/dist/components/actions/button-group/button-group.template.js +1 -1
  12. package/dist/components/actions/button-group/button-group.template.js.map +1 -1
  13. package/dist/components/actions/menu/menu.d.ts +14 -0
  14. package/dist/components/actions/menu/menu.d.ts.map +1 -1
  15. package/dist/components/actions/menu/menu.js +41 -0
  16. package/dist/components/actions/menu/menu.js.map +1 -1
  17. package/dist/components/components.js +2432 -97
  18. package/dist/components/content/avatar-group/avatar-group.styles.d.ts.map +1 -1
  19. package/dist/components/content/avatar-group/avatar-group.styles.js +12 -1
  20. package/dist/components/content/avatar-group/avatar-group.styles.js.map +1 -1
  21. package/dist/components/content/icon/icon-aliases.d.ts.map +1 -1
  22. package/dist/components/content/icon/icon-aliases.js +10 -5
  23. package/dist/components/content/icon/icon-aliases.js.map +1 -1
  24. package/dist/components/content/icon/icon-gallery-status.d.ts.map +1 -1
  25. package/dist/components/content/icon/icon-gallery-status.js +4 -0
  26. package/dist/components/content/icon/icon-gallery-status.js.map +1 -1
  27. package/dist/components/content/icon/icon-registry.d.ts.map +1 -1
  28. package/dist/components/content/icon/icon-registry.js +4 -2
  29. package/dist/components/content/icon/icon-registry.js.map +1 -1
  30. package/dist/components/content/text/text.d.ts +1 -1
  31. package/dist/components/content/text/text.js +1 -1
  32. package/dist/components/content/text/text.styles.d.ts.map +1 -1
  33. package/dist/components/content/text/text.styles.js +104 -1
  34. package/dist/components/content/text/text.styles.js.map +1 -1
  35. package/dist/components/content/token/token.styles.d.ts.map +1 -1
  36. package/dist/components/content/token/token.styles.js +2 -1
  37. package/dist/components/content/token/token.styles.js.map +1 -1
  38. package/dist/components/content/tooltip/tooltip.styles.js +7 -7
  39. package/dist/components/forms/form-field/form-field.d.ts +9 -5
  40. package/dist/components/forms/form-field/form-field.d.ts.map +1 -1
  41. package/dist/components/forms/form-field/form-field.js +17 -6
  42. package/dist/components/forms/form-field/form-field.js.map +1 -1
  43. package/dist/components/{icon-DZ1UXCzO.js → icon-DRpTWSIg.js} +12 -6
  44. package/dist/components/{icon-button-984CwkU1.js → icon-button-DUEmWlBD.js} +8 -8
  45. package/dist/components/index.d.ts +2 -0
  46. package/dist/components/index.d.ts.map +1 -1
  47. package/dist/components/index.js +2 -0
  48. package/dist/components/index.js.map +1 -1
  49. package/dist/components/inputs/file-field/file-field.d.ts +12 -0
  50. package/dist/components/inputs/file-field/file-field.d.ts.map +1 -1
  51. package/dist/components/inputs/file-field/file-field.i18n.d.ts +1 -0
  52. package/dist/components/inputs/file-field/file-field.i18n.d.ts.map +1 -1
  53. package/dist/components/inputs/file-field/file-field.i18n.js +1 -0
  54. package/dist/components/inputs/file-field/file-field.i18n.js.map +1 -1
  55. package/dist/components/inputs/file-field/file-field.js +28 -9
  56. package/dist/components/inputs/file-field/file-field.js.map +1 -1
  57. package/dist/components/inputs/file-field/file-field.styles.d.ts.map +1 -1
  58. package/dist/components/inputs/file-field/file-field.styles.js +91 -8
  59. package/dist/components/inputs/file-field/file-field.styles.js.map +1 -1
  60. package/dist/components/inputs/file-field/file-field.template.d.ts +1 -0
  61. package/dist/components/inputs/file-field/file-field.template.d.ts.map +1 -1
  62. package/dist/components/inputs/file-field/file-field.template.js +51 -21
  63. package/dist/components/inputs/file-field/file-field.template.js.map +1 -1
  64. package/dist/components/inputs/slider/slider.d.ts +161 -0
  65. package/dist/components/inputs/slider/slider.d.ts.map +1 -0
  66. package/dist/components/inputs/slider/slider.i18n.d.ts +6 -0
  67. package/dist/components/inputs/slider/slider.i18n.d.ts.map +1 -0
  68. package/dist/components/inputs/slider/slider.i18n.js +5 -0
  69. package/dist/components/inputs/slider/slider.i18n.js.map +1 -0
  70. package/dist/components/inputs/slider/slider.js +436 -0
  71. package/dist/components/inputs/slider/slider.js.map +1 -0
  72. package/dist/components/inputs/slider/slider.styles.d.ts +2 -0
  73. package/dist/components/inputs/slider/slider.styles.d.ts.map +1 -0
  74. package/dist/components/inputs/slider/slider.styles.js +360 -0
  75. package/dist/components/inputs/slider/slider.styles.js.map +1 -0
  76. package/dist/components/inputs/slider/slider.template.d.ts +5 -0
  77. package/dist/components/inputs/slider/slider.template.d.ts.map +1 -0
  78. package/dist/components/inputs/slider/slider.template.js +99 -0
  79. package/dist/components/inputs/slider/slider.template.js.map +1 -0
  80. package/dist/components/layout/task-board/task-board-column.d.ts +80 -0
  81. package/dist/components/layout/task-board/task-board-column.d.ts.map +1 -0
  82. package/dist/components/layout/task-board/task-board-column.js +207 -0
  83. package/dist/components/layout/task-board/task-board-column.js.map +1 -0
  84. package/dist/components/layout/task-board/task-board-column.template.d.ts +3 -0
  85. package/dist/components/layout/task-board/task-board-column.template.d.ts.map +1 -0
  86. package/dist/components/layout/task-board/task-board-column.template.js +45 -0
  87. package/dist/components/layout/task-board/task-board-column.template.js.map +1 -0
  88. package/dist/components/layout/task-board/task-board.d.ts +169 -0
  89. package/dist/components/layout/task-board/task-board.d.ts.map +1 -0
  90. package/dist/components/layout/task-board/task-board.i18n.d.ts +11 -0
  91. package/dist/components/layout/task-board/task-board.i18n.d.ts.map +1 -0
  92. package/dist/components/layout/task-board/task-board.i18n.js +10 -0
  93. package/dist/components/layout/task-board/task-board.i18n.js.map +1 -0
  94. package/dist/components/layout/task-board/task-board.js +701 -0
  95. package/dist/components/layout/task-board/task-board.js.map +1 -0
  96. package/dist/components/layout/task-board/task-board.styles.d.ts +3 -0
  97. package/dist/components/layout/task-board/task-board.styles.d.ts.map +1 -0
  98. package/dist/components/layout/task-board/task-board.styles.js +259 -0
  99. package/dist/components/layout/task-board/task-board.styles.js.map +1 -0
  100. package/dist/components/layout/task-board/task-board.template.d.ts +3 -0
  101. package/dist/components/layout/task-board/task-board.template.d.ts.map +1 -0
  102. package/dist/components/layout/task-board/task-board.template.js +25 -0
  103. package/dist/components/layout/task-board/task-board.template.js.map +1 -0
  104. package/dist/components/navigation/link/link.d.ts +5 -0
  105. package/dist/components/navigation/link/link.d.ts.map +1 -1
  106. package/dist/components/navigation/link/link.js +20 -1
  107. package/dist/components/navigation/link/link.js.map +1 -1
  108. package/dist/components/navigation/link/link.template.d.ts +1 -0
  109. package/dist/components/navigation/link/link.template.d.ts.map +1 -1
  110. package/dist/components/navigation/link/link.template.js +16 -14
  111. package/dist/components/navigation/link/link.template.js.map +1 -1
  112. package/dist/components/navigation/tab-bar/tab-bar.template.js +1 -1
  113. package/dist/css/{global-system-font.css → global-open-font.css} +2 -0
  114. package/dist/css/global.css +1 -0
  115. package/dist/css/inter-font.css +47 -0
  116. package/dist/css/jetbrains-mono-font.css +22 -0
  117. package/dist/css/rijksoverheid-fonts.css +4 -21
  118. package/dist/css/themes/bruin.css +1 -0
  119. package/dist/css/themes/donkerblauw.css +1 -0
  120. package/dist/css/themes/donkerbruin.css +1 -0
  121. package/dist/css/themes/donkergeel.css +1 -0
  122. package/dist/css/themes/donkergroen.css +1 -0
  123. package/dist/css/themes/geel.css +1 -0
  124. package/dist/css/themes/groen.css +1 -0
  125. package/dist/css/themes/hemelblauw.css +1 -0
  126. package/dist/css/themes/lichtblauw.css +1 -0
  127. package/dist/css/themes/mintgroen.css +1 -0
  128. package/dist/css/themes/mosgroen.css +1 -0
  129. package/dist/css/themes/oranje.css +1 -0
  130. package/dist/css/themes/paars.css +1 -0
  131. package/dist/css/themes/robijnrood.css +1 -0
  132. package/dist/css/themes/rood.css +1 -0
  133. package/dist/css/themes/roze.css +1 -0
  134. package/dist/css/themes/violet.css +1 -0
  135. package/dist/css/themes.css +17 -0
  136. package/dist/css/tokens.css +1 -0
  137. package/dist/css/variables.css +27 -5
  138. package/dist/fonts/Inter-Latin-Italic[wght].woff2 +0 -0
  139. package/dist/fonts/Inter-LatinExt-Italic[wght].woff2 +0 -0
  140. package/dist/fonts/Inter-LatinExt[wght].woff2 +0 -0
  141. package/dist/fonts/Inter-Latin[wght].woff2 +0 -0
  142. package/dist/nldd.min.js +1765 -804
  143. package/dist/translations/en-US.d.ts.map +1 -1
  144. package/dist/translations/en-US.js +10 -0
  145. package/dist/translations/en-US.js.map +1 -1
  146. package/dist/translations/nl.generated.d.ts +10 -0
  147. package/dist/translations/nl.generated.d.ts.map +1 -1
  148. package/dist/translations/nl.generated.js +4 -0
  149. package/dist/translations/nl.generated.js.map +1 -1
  150. package/dist/types/vue.d.ts +107 -3
  151. package/dist/utilities/tab-order.d.ts +11 -0
  152. package/dist/utilities/tab-order.d.ts.map +1 -0
  153. package/dist/utilities/tab-order.js +55 -0
  154. package/dist/utilities/tab-order.js.map +1 -0
  155. package/package.json +12 -3
@@ -0,0 +1,701 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ /**
8
+ * Nederlandse Digitale Dienst Task Board Component (Lit + TypeScript)
9
+ *
10
+ * Columns side by side, with items you move between them: a kanban board, or
11
+ * any board where an item's column is one of its values, such as a status or a
12
+ * team. Put `nldd-task-board-column`s in it, and the items in those, usually an
13
+ * `nldd-card` each. The board scrolls sideways once its columns do not fit, and
14
+ * a column scrolls on its own once its items do not fit the height you give the
15
+ * board.
16
+ *
17
+ * An item moves in three ways, and all three fire the same `nldd-move`:
18
+ *
19
+ * - **Dragging.** Pick up the whole item and drop it in a column. A press that
20
+ * does not move is still a click, so an item that is a link or a button keeps
21
+ * working. Released outside the board, the item goes back to its place, which
22
+ * a note above it says once it stays out a moment. On a touch screen you hold the item a moment before it lifts, so a
23
+ * swipe still scrolls.
24
+ * - **Keyboard.** With focus on an item, or on something inside it, Alt with
25
+ * the up or down arrow moves it within its column, and Alt with the left or
26
+ * right arrow to the column beside it.
27
+ * - **`moveItem()`.** WCAG 2.5.7 asks for a way that does not drag. Give each
28
+ * item a menu "Verplaatsen naar" with the other columns (`columns` lists them)
29
+ * and call `moveItem()` from it. The menu is yours; the board only moves.
30
+ *
31
+ * With `readonly` nothing moves: no dragging and no Alt with the arrows, while
32
+ * the items still work, so a card still opens. Use it for someone who may only
33
+ * look, or a board that is closed. `moveItem()` still moves, so your app can
34
+ * still show a move someone else made. An attempt to move an item, dragging it
35
+ * past a click or Alt with an arrow, shows "Dit bord is alleen-lezen" at the
36
+ * item, says it to a screen reader and fires `nldd-move-denied`, so your app
37
+ * can say why in an `nldd-notification`. Say it above the board too: only
38
+ * your app knows the reason, and then nobody has to try.
39
+ *
40
+ * The board moves nothing itself. `nldd-move` says which item goes where, and
41
+ * your app moves it in its data, or in the DOM, in the handler: the app owns the
42
+ * order, so a framework that renders the columns never fights the board over
43
+ * them. `toIndex` is the place the item takes in `toColumn`, counted without
44
+ * the item itself, so `splice(fromIndex, 1)` on the one list and
45
+ * `splice(toIndex, 0, item)` on the other is the whole move. Move it
46
+ * synchronously in the handler: the board puts focus back on the item right
47
+ * after, and a screen reader hears where it landed.
48
+ *
49
+ * @element nldd-task-board
50
+ * @attr {string} accessible-label - Accessible name of the board (default: "Takenbord")
51
+ * @attr {string} height - Fixed height as a CSS length (e.g. '480px'): every column takes it, and scrolls its items once they do not fit. To fill a page or a pane, set the height in your layout instead (flex, or `height: 100%`)
52
+ * @attr {boolean} readonly - Items cannot be dragged or moved with the keyboard; they still work, and `moveItem()` still moves
53
+ * @attr {object} translations - Override translation keys; unset keys fall back to Dutch
54
+ *
55
+ * @slot - The columns: `nldd-task-board-column`
56
+ *
57
+ * @fires nldd-move - An item moves: `{ item, fromColumn, fromIndex, toColumn, toIndex }`, where a column is its `value` (or its `text` without one)
58
+ * @fires nldd-move-denied - An item a `readonly` board does not move was dragged or moved with the keyboard: `{ item }`
59
+ *
60
+ * @method moveItem(item, toColumn, toIndex?) - Moves an item to a column, given as its `value` or as the element, at `toIndex` or at the end; fires `nldd-move` and says where it landed. Returns whether it moved.
61
+ */
62
+ import { LitElement } from 'lit';
63
+ import { customElement, property, query, state } from 'lit/decorators.js';
64
+ import { withTranslations } from '../../../utilities/with-translations.js';
65
+ import { nlddTaskBoardTranslations } from './task-board.i18n.js';
66
+ import { taskBoardStyles } from './task-board.styles.js';
67
+ import { taskBoardTemplate } from './task-board.template.js';
68
+ import { NLDDTaskBoardColumn } from './task-board-column.js';
69
+ export { NLDDTaskBoardColumn };
70
+ /** How far a mouse or pen moves before a press becomes a drag, in pixels. */
71
+ const DRAG_THRESHOLD = 4;
72
+ /** How far a finger may wander while it holds an item, and how long it holds. */
73
+ const TOUCH_SLOP = 8;
74
+ const TOUCH_HOLD_MS = 300;
75
+ /** How close to an edge the pointer scrolls the board or a column, and how fast. */
76
+ const SCROLL_EDGE = 48;
77
+ const SCROLL_SPEED = 12;
78
+ /** How long the note at an item a readonly board did not move stays. */
79
+ const DENIED_MS = 1500;
80
+ /** How long the pointer stays outside the board before the copy says it goes back. */
81
+ const RETURN_NOTE_DELAY_MS = 300;
82
+ let NLDDTaskBoard = class NLDDTaskBoard extends withTranslations(LitElement, nlddTaskBoardTranslations) {
83
+ constructor() {
84
+ super(...arguments);
85
+ this.accessibleLabel = '';
86
+ this.height = '';
87
+ this.readonly = false;
88
+ /** @internal Whether there is more to scroll to on that side, for the fades. */
89
+ this._canScrollLeft = false;
90
+ this._canScrollRight = false;
91
+ /** @internal While an item is dragged. */
92
+ this._dragging = false;
93
+ this._scrollObserver = null;
94
+ this._press = null;
95
+ this._drag = null;
96
+ /** The layer that shows the grabbing cursor wherever the pointer is. */
97
+ this._grabbing = null;
98
+ /** The note at an item a readonly board did not move, and its own cursor layer. */
99
+ this._deniedNote = null;
100
+ this._deniedCursor = null;
101
+ this._deniedTimer = 0;
102
+ /** @internal Which sides have more to scroll to, by the physical side, so a
103
+ * right-to-left page fades the right one first. */
104
+ this._updateScroll = () => {
105
+ const el = this._scroller;
106
+ if (!el)
107
+ return;
108
+ const max = el.scrollWidth - el.clientWidth;
109
+ const position = Math.abs(el.scrollLeft);
110
+ const rtl = getComputedStyle(this).direction === 'rtl';
111
+ const before = position > 1;
112
+ const after = position < max - 1;
113
+ this._canScrollLeft = rtl ? after : before;
114
+ this._canScrollRight = rtl ? before : after;
115
+ };
116
+ // — Keyboard ————————————————————————————————————————————————————————
117
+ this._onKeyDown = (event) => {
118
+ if (this._drag || !event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
119
+ return;
120
+ if (!['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key))
121
+ return;
122
+ const origin = event.composedPath()[0];
123
+ if (origin instanceof HTMLElement && (origin.isContentEditable || origin.matches('input, textarea, select')))
124
+ return;
125
+ const item = this._itemFrom(event);
126
+ const from = item && this._columnOf(item);
127
+ if (!item || !from)
128
+ return;
129
+ event.preventDefault();
130
+ if (this.readonly) {
131
+ this._deny(item);
132
+ this._deniedTimer = window.setTimeout(() => this._hideDenied(), DENIED_MS);
133
+ return;
134
+ }
135
+ const columns = this.columns;
136
+ const fromIndex = from.items.indexOf(item);
137
+ const rtl = getComputedStyle(this).direction === 'rtl';
138
+ const step = { ArrowUp: 0, ArrowDown: 0, ArrowLeft: rtl ? 1 : -1, ArrowRight: rtl ? -1 : 1 }[event.key] ?? 0;
139
+ if (step === 0) {
140
+ const toIndex = fromIndex + (event.key === 'ArrowUp' ? -1 : 1);
141
+ if (toIndex < 0 || toIndex > from.items.length - 1) {
142
+ this._announce(this._t('components.task-board.edge-text'));
143
+ return;
144
+ }
145
+ this._move(item, from, fromIndex, from, toIndex);
146
+ return;
147
+ }
148
+ const to = columns[columns.indexOf(from) + step];
149
+ if (!to) {
150
+ this._announce(this._t('components.task-board.edge-text'));
151
+ return;
152
+ }
153
+ this._move(item, from, fromIndex, to, Math.min(fromIndex, to.items.length));
154
+ };
155
+ // — Pointer —————————————————————————————————————————————————————————
156
+ this._onPointerDown = (event) => {
157
+ if (this._press || this._drag || !event.isPrimary || event.button !== 0)
158
+ return;
159
+ const origin = event.composedPath()[0];
160
+ if (origin instanceof HTMLElement && (origin.isContentEditable || origin.matches('input, textarea, select')))
161
+ return;
162
+ const item = this._itemFrom(event);
163
+ if (!item)
164
+ return;
165
+ this._press = {
166
+ item,
167
+ pointerId: event.pointerId,
168
+ pointerType: event.pointerType,
169
+ startX: event.clientX,
170
+ startY: event.clientY,
171
+ timer: event.pointerType === 'touch'
172
+ ? window.setTimeout(() => this._startDrag(this._press.startX, this._press.startY), TOUCH_HOLD_MS)
173
+ : 0,
174
+ };
175
+ window.addEventListener('pointermove', this._onPointerMove);
176
+ window.addEventListener('pointerup', this._onPointerUp);
177
+ window.addEventListener('pointercancel', this._onPointerCancel);
178
+ // A mouse that moves with its button down selects text before it reaches
179
+ // the drag threshold, and that selection would run over the dragged copy.
180
+ window.addEventListener('selectstart', this._preventSelect);
181
+ };
182
+ this._preventSelect = (event) => {
183
+ event.preventDefault();
184
+ };
185
+ this._onPointerMove = (event) => {
186
+ const press = this._press;
187
+ if (press && event.pointerId === press.pointerId && !this._drag && !press.denied) {
188
+ const distance = Math.hypot(event.clientX - press.startX, event.clientY - press.startY);
189
+ if (press.pointerType === 'touch') {
190
+ // A finger that moves before the hold is up is scrolling.
191
+ if (distance > TOUCH_SLOP)
192
+ this._endPress();
193
+ return;
194
+ }
195
+ if (distance > DRAG_THRESHOLD)
196
+ this._startDrag(event.clientX, event.clientY);
197
+ }
198
+ const drag = this._drag;
199
+ if (!drag)
200
+ return;
201
+ drag.x = event.clientX;
202
+ drag.y = event.clientY;
203
+ this._follow();
204
+ };
205
+ this._onPointerUp = (event) => {
206
+ const dragged = !!this._drag;
207
+ const denied = this._press?.pointerId === event.pointerId && !!this._press.denied;
208
+ if (dragged)
209
+ this._drop();
210
+ if (dragged || denied)
211
+ this._swallowNextClick();
212
+ if (this._press?.pointerId === event.pointerId)
213
+ this._endPress();
214
+ };
215
+ this._onPointerCancel = () => {
216
+ if (this._drag)
217
+ this._cancelDrag();
218
+ this._endPress();
219
+ };
220
+ this._swallowClick = (event) => {
221
+ event.preventDefault();
222
+ event.stopPropagation();
223
+ };
224
+ /** While a finger holds an item, the page must not scroll under it. */
225
+ this._holdTouch = (event) => {
226
+ event.preventDefault();
227
+ };
228
+ this._preventContextMenu = (event) => {
229
+ event.preventDefault();
230
+ };
231
+ /** Escape drops nothing, wherever focus is while dragging. */
232
+ this._onDragKeyDown = (event) => {
233
+ if (event.key !== 'Escape')
234
+ return;
235
+ event.preventDefault();
236
+ event.stopPropagation();
237
+ this._cancelDrag();
238
+ };
239
+ /** Scrolls the board sideways, and the column under the pointer, while the
240
+ * pointer is near an edge. */
241
+ this._scrollLoop = () => {
242
+ const drag = this._drag;
243
+ if (!drag)
244
+ return;
245
+ const board = this._scroller.getBoundingClientRect();
246
+ const dx = drag.x < board.left + SCROLL_EDGE ? -SCROLL_SPEED : drag.x > board.right - SCROLL_EDGE ? SCROLL_SPEED : 0;
247
+ if (dx)
248
+ this._scroller.scrollBy({ left: dx, behavior: 'instant' });
249
+ const main = drag.target?._main;
250
+ if (main) {
251
+ const rect = main.getBoundingClientRect();
252
+ const dy = drag.y < rect.top + SCROLL_EDGE ? -SCROLL_SPEED : drag.y > rect.bottom - SCROLL_EDGE ? SCROLL_SPEED : 0;
253
+ if (dy)
254
+ main.scrollTop += dy;
255
+ }
256
+ if (dx || main)
257
+ this._follow();
258
+ drag.frame = requestAnimationFrame(this._scrollLoop);
259
+ };
260
+ }
261
+ /** The columns, in order. */
262
+ get columns() {
263
+ return Array.from(this.children).filter((el) => el instanceof NLDDTaskBoardColumn && !el.hidden);
264
+ }
265
+ connectedCallback() {
266
+ super.connectedCallback();
267
+ this.addEventListener('pointerdown', this._onPointerDown);
268
+ this.addEventListener('keydown', this._onKeyDown);
269
+ }
270
+ disconnectedCallback() {
271
+ super.disconnectedCallback();
272
+ this.removeEventListener('pointerdown', this._onPointerDown);
273
+ this.removeEventListener('keydown', this._onKeyDown);
274
+ this._scrollObserver?.disconnect();
275
+ this._scrollObserver = null;
276
+ this._endPress();
277
+ this._endDrag();
278
+ this._hideDenied();
279
+ }
280
+ updated(changed) {
281
+ if (changed.has('height')) {
282
+ const height = this.height;
283
+ if (height && CSS.supports('height', height))
284
+ this.style.setProperty('--_task-board-height', height);
285
+ else
286
+ this.style.removeProperty('--_task-board-height');
287
+ }
288
+ if (changed.has('readonly')) {
289
+ this._endPress();
290
+ this._cancelDrag();
291
+ this._hideDenied();
292
+ }
293
+ if (!this._scrollObserver && this._scroller) {
294
+ this._scrollObserver = new ResizeObserver(() => this._updateScroll());
295
+ this._scrollObserver.observe(this._scroller);
296
+ for (const column of this.columns)
297
+ this._scrollObserver.observe(column);
298
+ }
299
+ }
300
+ moveItem(item, toColumn, toIndex) {
301
+ const from = this._columnOf(item);
302
+ const to = typeof toColumn === 'string'
303
+ ? this.columns.find((column) => this._columnKey(column) === toColumn)
304
+ : toColumn;
305
+ if (!from || !to || !this.columns.includes(to)) {
306
+ if (import.meta.env?.DEV)
307
+ console.warn('nldd-task-board: moveItem() needs an item in one of the board\'s columns and a column of the board.');
308
+ return false;
309
+ }
310
+ const fromIndex = from.items.indexOf(item);
311
+ const room = to.items.filter((el) => el !== item).length;
312
+ const index = Math.max(0, Math.min(toIndex ?? room, room));
313
+ if (from === to && index === fromIndex) {
314
+ this._announce(this._t('components.task-board.no-change-text'));
315
+ return false;
316
+ }
317
+ return this._move(item, from, fromIndex, to, index);
318
+ }
319
+ /** Fires nldd-move, says where the item landed and puts focus back on what
320
+ * had it, once the app has moved the item in the handler. */
321
+ _move(item, from, fromIndex, to, toIndex) {
322
+ const focused = this._deepActiveElement();
323
+ const hadFocus = !!focused && this._holds(item, focused);
324
+ this.dispatchEvent(new CustomEvent('nldd-move', {
325
+ detail: { item, fromColumn: this._columnKey(from), fromIndex, toColumn: this._columnKey(to), toIndex },
326
+ bubbles: true,
327
+ composed: true,
328
+ }));
329
+ const total = to.items.filter((el) => el !== item).length + 1;
330
+ this._announce(this._t('components.task-board.moved-text', { column: to.label, position: toIndex + 1, total }));
331
+ if (hadFocus) {
332
+ // The app moved the item in the handler, which takes focus off it.
333
+ requestAnimationFrame(() => {
334
+ if (focused.isConnected)
335
+ focused.focus();
336
+ });
337
+ }
338
+ return true;
339
+ }
340
+ _columnKey(column) {
341
+ return column.value || column.text;
342
+ }
343
+ /** The column an element sits in as an item, if it is one in this board. */
344
+ _columnOf(item) {
345
+ const parent = item.parentElement;
346
+ return parent instanceof NLDDTaskBoardColumn && parent.parentElement === this && !item.slot ? parent : null;
347
+ }
348
+ /** The item an event happened in: the child of a column it came through. */
349
+ _itemFrom(event) {
350
+ for (const node of event.composedPath()) {
351
+ if (node instanceof HTMLElement && this._columnOf(node))
352
+ return node;
353
+ if (node === this)
354
+ break;
355
+ }
356
+ return null;
357
+ }
358
+ /** Whether `node` is in `item`, also inside the shadow root of an item such
359
+ * as an nldd-card, where its own button takes the focus. */
360
+ _holds(item, node) {
361
+ let current = node;
362
+ while (current) {
363
+ if (current === item)
364
+ return true;
365
+ current = current.parentNode ?? (current instanceof ShadowRoot ? current.host : null);
366
+ }
367
+ return false;
368
+ }
369
+ _deepActiveElement() {
370
+ let active = document.activeElement;
371
+ while (active?.shadowRoot?.activeElement)
372
+ active = active.shadowRoot.activeElement;
373
+ return active instanceof HTMLElement ? active : null;
374
+ }
375
+ _announce(message) {
376
+ const region = this.shadowRoot?.querySelector('.task-board__announcer');
377
+ if (!region)
378
+ return;
379
+ region.textContent = '';
380
+ // Two frames, so a screen reader registers the change even for the same text.
381
+ requestAnimationFrame(() => requestAnimationFrame(() => {
382
+ region.textContent = message;
383
+ }));
384
+ }
385
+ /** The release ends a drag, or an attempt at one, not a click on the item. */
386
+ _swallowNextClick() {
387
+ window.addEventListener('click', this._swallowClick, { capture: true, once: true });
388
+ setTimeout(() => window.removeEventListener('click', this._swallowClick, { capture: true }), 0);
389
+ }
390
+ _endPress() {
391
+ if (this._press?.timer)
392
+ clearTimeout(this._press.timer);
393
+ if (this._press?.denied) {
394
+ this._deniedCursor?.remove();
395
+ this._deniedCursor = null;
396
+ this._deniedTimer = window.setTimeout(() => this._hideDenied(), DENIED_MS);
397
+ }
398
+ this._press = null;
399
+ if (!this._drag)
400
+ this._stopListening();
401
+ }
402
+ _stopListening() {
403
+ window.removeEventListener('selectstart', this._preventSelect);
404
+ window.removeEventListener('pointermove', this._onPointerMove);
405
+ window.removeEventListener('pointerup', this._onPointerUp);
406
+ window.removeEventListener('pointercancel', this._onPointerCancel);
407
+ }
408
+ _startDrag(x, y) {
409
+ const press = this._press;
410
+ const from = press && this._columnOf(press.item);
411
+ if (!press || !from)
412
+ return;
413
+ if (this.readonly) {
414
+ press.denied = true;
415
+ this._deny(press.item);
416
+ this._deniedCursor = this._cursorLayer('not-allowed');
417
+ return;
418
+ }
419
+ const item = press.item;
420
+ const rect = item.getBoundingClientRect();
421
+ const ghost = item.cloneNode(true);
422
+ ghost.removeAttribute('id');
423
+ // A copy carries the state attributes of the item, such as the focus ring
424
+ // and the pressed fill an nldd-card draws from them; the ghost is its rest.
425
+ for (const name of ghost.getAttributeNames()) {
426
+ if (/focus|press|hover|active/i.test(name))
427
+ ghost.removeAttribute(name);
428
+ }
429
+ ghost.setAttribute('aria-hidden', 'true');
430
+ ghost.inert = true;
431
+ Object.assign(ghost.style, {
432
+ position: 'fixed',
433
+ top: '0',
434
+ left: '0',
435
+ zIndex: '2147483647',
436
+ width: `${rect.width}px`,
437
+ height: `${rect.height}px`,
438
+ margin: '0',
439
+ boxSizing: 'border-box',
440
+ pointerEvents: 'none',
441
+ userSelect: 'none',
442
+ boxShadow: 'var(--semantics-overlays-box-shadow)',
443
+ borderRadius: this._cornerRadius(item),
444
+ });
445
+ document.body.append(ghost);
446
+ item.setAttribute('data-task-board-dragging', '');
447
+ document.getSelection()?.removeAllRanges();
448
+ document.documentElement.style.setProperty('user-select', 'none');
449
+ document.documentElement.style.setProperty('-webkit-user-select', 'none');
450
+ window.addEventListener('touchmove', this._holdTouch, { passive: false });
451
+ window.addEventListener('contextmenu', this._preventContextMenu);
452
+ window.addEventListener('keydown', this._onDragKeyDown, true);
453
+ for (const column of this.columns)
454
+ column._dropState = 'available';
455
+ from._placeholder = item;
456
+ this._grabbing = this._cursorLayer('grabbing');
457
+ this._dragging = true;
458
+ this._drag = {
459
+ item,
460
+ from,
461
+ fromIndex: from.items.indexOf(item),
462
+ ghost,
463
+ offsetX: press.startX - rect.left,
464
+ offsetY: press.startY - rect.top,
465
+ x,
466
+ y,
467
+ target: null,
468
+ index: 0,
469
+ frame: requestAnimationFrame(this._scrollLoop),
470
+ note: null,
471
+ noteTimer: 0,
472
+ };
473
+ this._follow();
474
+ }
475
+ /** The rounding of what an item draws: its own, or that of the first element
476
+ * in its shadow root, where an nldd-card draws its surface. */
477
+ _cornerRadius(item) {
478
+ const own = getComputedStyle(item).borderRadius;
479
+ const surface = item.shadowRoot?.firstElementChild;
480
+ if (parseFloat(own) > 0 || !surface)
481
+ return own;
482
+ return getComputedStyle(surface).borderRadius;
483
+ }
484
+ /** Moves the ghost with the pointer and shows where it would land. */
485
+ _follow() {
486
+ const drag = this._drag;
487
+ if (!drag)
488
+ return;
489
+ drag.ghost.style.transform = `translate(${drag.x - drag.offsetX}px, ${drag.y - drag.offsetY}px) rotate(2deg)`;
490
+ const columns = this.columns;
491
+ let target = null;
492
+ let nearest = Infinity;
493
+ // Outside the board nothing takes the item: a release there puts it back.
494
+ const board = this._scroller.getBoundingClientRect();
495
+ const inside = drag.x >= board.left && drag.x <= board.right && drag.y >= board.top && drag.y <= board.bottom;
496
+ for (const column of inside ? columns : []) {
497
+ const rect = column.getBoundingClientRect();
498
+ const distance = drag.x < rect.left ? rect.left - drag.x : drag.x > rect.right ? drag.x - rect.right : 0;
499
+ if (distance < nearest) {
500
+ nearest = distance;
501
+ target = column;
502
+ }
503
+ }
504
+ // A place among all the column's items, the dragged one included, so the
505
+ // line shows above or below its own place as the pointer crosses its middle.
506
+ const items = target ? target.items : [];
507
+ let index = items.findIndex((el) => {
508
+ const rect = el.getBoundingClientRect();
509
+ return drag.y < rect.top + rect.height / 2;
510
+ });
511
+ if (index === -1)
512
+ index = items.length;
513
+ if (drag.target && drag.target !== target) {
514
+ drag.target._dropIndex = null;
515
+ drag.target._dropState = 'available';
516
+ }
517
+ drag.target = target;
518
+ drag.index = index;
519
+ // Outside the board, or just above or below its own place, a release puts
520
+ // the item back where it was: the placeholder says so, not a line.
521
+ const returning = !target || (target === drag.from && (index === drag.fromIndex || index === drag.fromIndex + 1));
522
+ drag.from._returning = returning;
523
+ if (target) {
524
+ target._dropIndex = returning ? null : index;
525
+ target._dropState = 'over';
526
+ }
527
+ this._followReturnNote(inside);
528
+ }
529
+ /** Outside the board, after a moment, a note above the copy says a release
530
+ * puts the item back; the placeholder that says so may be out of view. */
531
+ _followReturnNote(inside) {
532
+ const drag = this._drag;
533
+ if (!drag)
534
+ return;
535
+ if (inside) {
536
+ clearTimeout(drag.noteTimer);
537
+ drag.noteTimer = 0;
538
+ drag.note?.remove();
539
+ drag.note = null;
540
+ return;
541
+ }
542
+ if (!drag.note && !drag.noteTimer) {
543
+ drag.noteTimer = window.setTimeout(() => {
544
+ if (this._drag !== drag)
545
+ return;
546
+ drag.note = this._note(this._t('components.task-board.drag-return-text'));
547
+ this._followReturnNote(false);
548
+ }, RETURN_NOTE_DELAY_MS);
549
+ }
550
+ if (!drag.note)
551
+ return;
552
+ const x = drag.x - drag.offsetX + drag.ghost.offsetWidth / 2;
553
+ const y = drag.y - drag.offsetY;
554
+ drag.note.style.transform = `translate(${x}px, ${y}px) translate(-50%, calc(-100% - var(--primitives-space-8)))`;
555
+ }
556
+ _drop() {
557
+ const drag = this._drag;
558
+ if (!drag)
559
+ return;
560
+ const { item, from, fromIndex, target, index } = drag;
561
+ this._endDrag();
562
+ if (!target) {
563
+ this._announce(this._t('components.task-board.drag-canceled-text'));
564
+ return;
565
+ }
566
+ // Just above or just below its own place is where it already is.
567
+ if (target === from && (index === fromIndex || index === fromIndex + 1)) {
568
+ this._announce(this._t('components.task-board.no-change-text'));
569
+ return;
570
+ }
571
+ this._move(item, from, fromIndex, target, target === from && index > fromIndex ? index - 1 : index);
572
+ }
573
+ _cancelDrag() {
574
+ if (!this._drag)
575
+ return;
576
+ this._endDrag();
577
+ this._announce(this._t('components.task-board.drag-canceled-text'));
578
+ }
579
+ _endDrag() {
580
+ const drag = this._drag;
581
+ if (!drag)
582
+ return;
583
+ cancelAnimationFrame(drag.frame);
584
+ clearTimeout(drag.noteTimer);
585
+ drag.note?.remove();
586
+ drag.ghost.remove();
587
+ drag.item.removeAttribute('data-task-board-dragging');
588
+ if (drag.target)
589
+ drag.target._dropIndex = null;
590
+ for (const column of this.columns)
591
+ column._dropState = null;
592
+ drag.from._placeholder = null;
593
+ drag.from._returning = false;
594
+ this._grabbing?.remove();
595
+ this._grabbing = null;
596
+ document.documentElement.style.removeProperty('user-select');
597
+ document.documentElement.style.removeProperty('-webkit-user-select');
598
+ window.removeEventListener('touchmove', this._holdTouch);
599
+ window.removeEventListener('contextmenu', this._preventContextMenu);
600
+ window.removeEventListener('keydown', this._onDragKeyDown, true);
601
+ this._dragging = false;
602
+ this._drag = null;
603
+ if (!this._press)
604
+ this._stopListening();
605
+ }
606
+ /** A style in the document does not reach into shadow roots, where a
607
+ * button or a link sets its own cursor. A layer over the whole viewport
608
+ * does: the pointer is always over it. */
609
+ _cursorLayer(cursor) {
610
+ const layer = document.createElement('div');
611
+ layer.setAttribute('aria-hidden', 'true');
612
+ Object.assign(layer.style, {
613
+ position: 'fixed',
614
+ inset: '0',
615
+ zIndex: '2147483646',
616
+ cursor,
617
+ });
618
+ document.body.append(layer);
619
+ return layer;
620
+ }
621
+ // — Readonly ————————————————————————————————————————————————————————
622
+ /** Says at the item, and to a screen reader, that the board moves nothing,
623
+ * and tells the app. */
624
+ _deny(item) {
625
+ this._hideDenied();
626
+ const text = this._t('components.task-board.readonly-text');
627
+ this._announce(text);
628
+ const rect = item.getBoundingClientRect();
629
+ const below = rect.top < SCROLL_EDGE;
630
+ const note = this._note(text);
631
+ Object.assign(note.style, {
632
+ top: `${below ? rect.bottom : rect.top}px`,
633
+ left: `${rect.left + rect.width / 2}px`,
634
+ transform: `translate(-50%, ${below ? 'var(--primitives-space-8)' : 'calc(-100% - var(--primitives-space-8))'})`,
635
+ maxWidth: `${rect.width}px`,
636
+ });
637
+ this._deniedNote = note;
638
+ this.dispatchEvent(new CustomEvent('nldd-move-denied', { detail: { item }, bubbles: true, composed: true }));
639
+ }
640
+ /** A note in the look of a tooltip, over everything, for the eye only: what
641
+ * it says, the board also says to a screen reader or in its own way. */
642
+ _note(text) {
643
+ const note = document.createElement('div');
644
+ note.setAttribute('aria-hidden', 'true');
645
+ note.textContent = text;
646
+ Object.assign(note.style, {
647
+ position: 'fixed',
648
+ top: '0',
649
+ left: '0',
650
+ zIndex: '2147483647',
651
+ boxSizing: 'border-box',
652
+ width: 'max-content',
653
+ padding: 'var(--semantics-tooltips-padding-block) var(--semantics-tooltips-padding-inline)',
654
+ borderRadius: 'var(--semantics-tooltips-corner-radius)',
655
+ boxShadow: 'var(--semantics-tooltips-box-shadow)',
656
+ backgroundColor: 'var(--semantics-tooltips-background-color)',
657
+ color: 'var(--semantics-tooltips-content-color)',
658
+ font: 'var(--semantics-tooltips-font)',
659
+ pointerEvents: 'none',
660
+ });
661
+ document.body.append(note);
662
+ return note;
663
+ }
664
+ _hideDenied() {
665
+ clearTimeout(this._deniedTimer);
666
+ this._deniedNote?.remove();
667
+ this._deniedNote = null;
668
+ this._deniedCursor?.remove();
669
+ this._deniedCursor = null;
670
+ }
671
+ render() {
672
+ return taskBoardTemplate(this);
673
+ }
674
+ };
675
+ NLDDTaskBoard.styles = taskBoardStyles;
676
+ __decorate([
677
+ property({ type: String, attribute: 'accessible-label' })
678
+ ], NLDDTaskBoard.prototype, "accessibleLabel", void 0);
679
+ __decorate([
680
+ property({ type: String, reflect: true })
681
+ ], NLDDTaskBoard.prototype, "height", void 0);
682
+ __decorate([
683
+ property({ type: Boolean, reflect: true })
684
+ ], NLDDTaskBoard.prototype, "readonly", void 0);
685
+ __decorate([
686
+ query('.task-board')
687
+ ], NLDDTaskBoard.prototype, "_scroller", void 0);
688
+ __decorate([
689
+ state()
690
+ ], NLDDTaskBoard.prototype, "_canScrollLeft", void 0);
691
+ __decorate([
692
+ state()
693
+ ], NLDDTaskBoard.prototype, "_canScrollRight", void 0);
694
+ __decorate([
695
+ state()
696
+ ], NLDDTaskBoard.prototype, "_dragging", void 0);
697
+ NLDDTaskBoard = __decorate([
698
+ customElement('nldd-task-board')
699
+ ], NLDDTaskBoard);
700
+ export { NLDDTaskBoard };
701
+ //# sourceMappingURL=task-board.js.map