@editora/ui-sortable 0.1.7 → 0.1.9

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/README.md CHANGED
@@ -29,12 +29,20 @@
29
29
  - **Reorder, transfer, nest and clone.** Drop an item between others, into another list, inside another item, or drag
30
30
  a copy out of a template list.
31
31
  - **Multi-selection**: select several items and move them together.
32
+ - **A drag that is always a reorder**: nesting takes a deliberate gesture (hold Alt, or drop on the far side of a card),
33
+ so a plain drag never nests by accident. On touch a card is lifted by holding it, so the page still scrolls.
34
+ - **Guard rails**: `maxItems` per list, a `canDrop` function, and a cancelable `before-change` event, so your app has
35
+ the last word on a move.
32
36
  - **Keyboard and screen readers.** Space lifts the focused item, the arrow keys choose the place, Space drops it, and
33
37
  the move is announced.
34
38
  - **Persistence built in**: a `persist-request` event with the new positions, and a `persistKey` that keeps the positions across reloads.
35
39
  - **Small.** The component is 17 KB gzipped (19 KB with the React wrapper), against about 490 KB for the whole
36
40
  [`@editora/ui-core`](https://www.npmjs.com/package/@editora/ui-core) catalog it comes from.
37
- - Custom item, list-header and empty-state rendering in React.
41
+ - **More than one board**: sortables with the same `group` take each other's cards, and a list can have a height of its
42
+ own and scroll by itself.
43
+ - **Your own markup, with or without React**: custom cards, list headers and empty states, and a free `data` field on
44
+ every item and list.
45
+ - **Translatable and quiet**: every text it shows or announces can be replaced (`labels`), and the hint line can be hidden.
38
46
 
39
47
  ## Install
40
48
 
@@ -162,7 +170,7 @@ export default function ReleaseBoard() {
162
170
  ```
163
171
 
164
172
  <p align="center">
165
- <img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/ui-sortable/docs/images/dragging.png" alt="The board while an item is dragged: a dashed drop preview shows where the card will land, and a Moving item label follows the pointer" width="900">
173
+ <img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/ui-sortable/docs/images/dragging.png" alt="The board while an item is dragged: the card is lifted under the pointer, its place in Backlog is an empty dashed slot, and a blue line in In Progress shows where it will land" width="900">
166
174
  </p>
167
175
 
168
176
  ### A flat list
@@ -257,6 +265,162 @@ export default function CustomRendering() {
257
265
  <img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/ui-sortable/docs/images/custom.png" alt="Two lists with custom markup: a header showing the item count, cards showing Selected or Ready, and a custom message in the empty list" width="900">
258
266
  </p>
259
267
 
268
+ ### Refusing moves
269
+
270
+ A list can hold a limited number of items (`maxItems`, counted at every nesting level), `canDrop` decides whether items
271
+ may go somewhere, and `onBeforeChange` is the last word before anything changes. A place that is refused is never
272
+ highlighted, the keyboard skips it, and the card you are holding turns red over it:
273
+
274
+ ```tsx
275
+ import * as React from 'react';
276
+ import { Sortable, type SortableItem, type SortableList } from '@editora/ui-sortable/react';
277
+
278
+ type Task = { reviewed: boolean };
279
+
280
+ const lists: SortableList[] = [
281
+ { id: 'todo', label: 'To do' },
282
+ { id: 'doing', label: 'Doing', maxItems: 2 },
283
+ { id: 'done', label: 'Done' }
284
+ ];
285
+
286
+ const initialItems: SortableItem[] = [
287
+ { id: 'brief', label: 'Write the brief', listId: 'todo', data: { reviewed: true } },
288
+ { id: 'budget', label: 'Approve the budget', listId: 'todo', data: { reviewed: false } },
289
+ { id: 'launch', label: 'Plan the launch', listId: 'todo', data: { reviewed: true } },
290
+ { id: 'assets', label: 'Collect the assets', listId: 'doing', data: { reviewed: true } }
291
+ ];
292
+
293
+ export default function GuardedBoard() {
294
+ const [items, setItems] = React.useState(initialItems);
295
+
296
+ return (
297
+ <Sortable
298
+ lists={lists}
299
+ items={items}
300
+ allowNesting={false}
301
+ // Only reviewed work goes to Done: over it the lifted card turns red, and a drop does nothing.
302
+ canDrop={(drop) =>
303
+ drop.targetListId !== 'done' || drop.items.every((item) => (item.data as Task).reviewed)
304
+ }
305
+ // The last word before anything changes: return false to cancel (here, at most two cards at a time).
306
+ onBeforeChange={(detail) => detail.movedIds.length <= 2}
307
+ onItemsChange={setItems}
308
+ />
309
+ );
310
+ }
311
+ ```
312
+
313
+ <p align="center">
314
+ <img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/ui-sortable/docs/images/guard.png" alt="A board where Doing shows 1/2 and a card that was not reviewed is held over Done: the lifted card is outlined in red because Done will not take it" width="900">
315
+ </p>
316
+
317
+ `before-change` is a cancelable event (`detail` is what `change` will report, plus `target` and `clone`):
318
+ `event.preventDefault()` cancels the move, puts a dragged card back, and fires no `change`. `moveSelection()` returns
319
+ `false` when a move did not happen.
320
+
321
+ ### Without React
322
+
323
+ `renderItem`, `renderListHeader` and `renderEmptyState` are properties of the element too. Each returns a new DOM node, a
324
+ string of HTML (escape anything that came from a user), or nothing to keep the built-in markup. A card is drawn again when
325
+ its `data` changes and when it is selected or deselected:
326
+
327
+ ```html
328
+ <script type="importmap">
329
+ {
330
+ "imports": {
331
+ "@editora/ui-sortable": "https://cdn.jsdelivr.net/npm/@editora/ui-sortable/dist/index.esm.js",
332
+ "@editora/ui-core/sortable": "https://cdn.jsdelivr.net/npm/@editora/ui-core/dist/sortable.esm.js"
333
+ }
334
+ }
335
+ </script>
336
+ <ui-sortable></ui-sortable>
337
+
338
+ <script type="module">
339
+ import '@editora/ui-sortable';
340
+
341
+ const board = document.querySelector('ui-sortable');
342
+
343
+ board.lists = [
344
+ { id: 'todo', label: 'To do', maxItems: 3 },
345
+ { id: 'done', label: 'Done' }
346
+ ];
347
+
348
+ board.items = [
349
+ { id: 'acme', label: 'Invoice Acme', listId: 'todo', data: { amount: 1200 } },
350
+ { id: 'globex', label: 'Quote Globex', listId: 'todo', data: { amount: 450 } },
351
+ { id: 'initech', label: 'Chase Initech', listId: 'done', data: { amount: 80 } }
352
+ ];
353
+
354
+ // Draw each card yourself. Return a new DOM node (or a string of HTML you have escaped).
355
+ board.renderItem = (item, { selected }) => {
356
+ const row = document.createElement('div');
357
+ row.style.cssText = 'display: flex; justify-content: space-between; gap: 12px';
358
+
359
+ const name = document.createElement('strong');
360
+ name.textContent = item.label;
361
+
362
+ const amount = document.createElement('span');
363
+ amount.textContent = `$${item.data.amount}${selected ? ' (selected)' : ''}`;
364
+
365
+ row.append(name, amount);
366
+ return row;
367
+ };
368
+
369
+ // Say no before a move happens: nothing over $1,000 goes to Done.
370
+ board.canDrop = ({ targetListId, items }) =>
371
+ targetListId !== 'done' || items.every((item) => item.data.amount <= 1000);
372
+
373
+ board.addEventListener('change', (event) => console.log('moved', event.detail.movedIds));
374
+ </script>
375
+ ```
376
+
377
+ <p align="center">
378
+ <img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/ui-sortable/docs/images/vanilla.png" alt="Two lists whose cards were drawn by a JavaScript function, each showing a name and an amount, and a To do header counting 2/3" width="900">
379
+ </p>
380
+
381
+ ### Two boards
382
+
383
+ Give two sortables the same `group` and a card held over one of them can be dropped in the other. Each one reports its own
384
+ `change` (the one it left with `external.direction === 'out'`, the one it reached with `'in'`), so each keeps its own state;
385
+ `onBeforeChange` on either can cancel the move, and the other one's `canDrop` and `maxItems` apply:
386
+
387
+ ```tsx
388
+ import * as React from 'react';
389
+ import { Sortable, type SortableItem, type SortableList } from '@editora/ui-sortable/react';
390
+
391
+ const backlogLists: SortableList[] = [{ id: 'backlog', label: 'Backlog' }];
392
+ const sprintLists: SortableList[] = [{ id: 'sprint', label: 'This sprint', maxItems: 3, maxHeight: 280 }];
393
+
394
+ export default function TwoBoards() {
395
+ const [backlog, setBacklog] = React.useState<SortableItem[]>([
396
+ { id: 'audit', label: 'Audit onboarding', listId: 'backlog' },
397
+ { id: 'notes', label: 'Ship release notes', listId: 'backlog' },
398
+ { id: 'handoff', label: 'Review handoff', listId: 'backlog' }
399
+ ]);
400
+ const [sprint, setSprint] = React.useState<SortableItem[]>([
401
+ { id: 'login', label: 'Fix login', listId: 'sprint' },
402
+ { id: 'docs', label: 'Write docs', listId: 'sprint' }
403
+ ]);
404
+
405
+ // Sortables with the same group take each other's cards. Each one reports its own change,
406
+ // so each keeps its own state.
407
+ return (
408
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24, alignItems: 'start' }}>
409
+ <Sortable lists={backlogLists} items={backlog} group="planning" allowNesting={false} onItemsChange={setBacklog} />
410
+ <Sortable lists={sprintLists} items={sprint} group="planning" allowNesting={false} onItemsChange={setSprint} />
411
+ </div>
412
+ );
413
+ }
414
+ ```
415
+
416
+ <p align="center">
417
+ <img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/ui-sortable/docs/images/two-boards.png" alt="Two sortables side by side: a card of the Backlog is held over This sprint, which marks with a blue line the place between its cards where it would land" width="900">
418
+ </p>
419
+
420
+ Ids must be unique across the group (a drop onto a board that already has one of the ids is refused; a copy gets a fresh
421
+ id there). Dragging between boards is for the pointer: for the keyboard and for code there is
422
+ `moveSelectionTo(otherSortable, { targetListId, beforeId?, parentId?, clone? })`.
423
+
260
424
  ## Items and lists
261
425
 
262
426
  | Item field | |
@@ -266,6 +430,7 @@ export default function CustomRendering() {
266
430
  | `description` | A second line of text. |
267
431
  | `cloneOnDrag` | Dragging this item leaves it where it is and drops a copy. |
268
432
  | `disabled`, `dragDisabled`, `hidden` | Disable the item, stop it being dragged, or hide it. |
433
+ | `data` | Anything of yours that can be written as JSON. It travels with the item through moves and copies and comes back in every event, so you do not need a side table. What you get back is a copy. |
269
434
 
270
435
  | List field | |
271
436
  | --- | --- |
@@ -274,6 +439,10 @@ export default function CustomRendering() {
274
439
  | `orientation` | `'vertical'` (the default) or `'horizontal'`. |
275
440
  | `cloneOnDrag` | Items dragged out of this list are copied. |
276
441
  | `disabled` | Turn the list off. |
442
+ | `accepts` | The ids of the lists it takes items from (the lists of another sortable count too). |
443
+ | `maxHeight` | The tallest its cards can be before the list scrolls by itself: a number of px or a CSS length such as `"20rem"`. Holding a card at its edge scrolls it, and the keyboard keeps the focused card in view. |
444
+ | `maxItems` | The most items it can hold. A move or copy that would go past it is refused; the header shows `3/5`. |
445
+ | `data` | Anything of yours that can be written as JSON, as on items. |
277
446
 
278
447
  ## Options
279
448
 
@@ -282,9 +451,16 @@ export default function CustomRendering() {
282
451
  | `lists`, `items` | `lists`, `items` | The data. In HTML, set them as properties or as JSON attributes. |
283
452
  | `selection` | `selection` | The selected item ids. |
284
453
  | `allowNesting` | `allow-nesting` | Allow dropping an item inside another. |
454
+ | `group` | `group` | Sortables with the same group take each other's cards (see Two boards). |
455
+ | `listMaxHeight` | `list-max-height` | `maxHeight` for every list that does not set its own. |
456
+ | `nestTrigger` | `nest-trigger` | What it takes to nest with the pointer: `gutter` (the default: hold Alt, or drop on the far side of a card), `modifier` (hold Alt) or `area` (the middle of any card, as before). Without it the top half of a card is "before it" and the bottom half "after it". |
457
+ | `touchHoldDelay` | `touch-hold-delay` | Milliseconds a finger must rest on a card before it lifts (for cards dragged by their body); `0` lifts at once. Default `350`. The built-in handle always lifts at once. |
458
+ | `labels` | `labels` | Replacements for any of its texts: `{ hintHandle, selectedMany, badgeSelected, announceMovedOne, listFull, ... }`. `{count}`, `{label}`, `{list}` and `{max}` are filled in. |
459
+ | `hideToolbar` | `hide-toolbar` | Hide the hint and the selection count from sight (screen readers still get the hint). |
460
+ | `canDrop` | `canDrop` (property) | A function that is given `{ items, movedIds, targetListId, parentId, beforeId, mode, clone, from? }` (`from` is the other sortable, for a card that comes from one) and returns whether they may go there. |
285
461
  | `dropzoneStyle` | `dropzone-style` | `indicator` (an insertion rail, the default) or `container` (the whole list highlights). |
286
462
  | `dropIndicatorVisibility` | `drop-indicator-visibility` | `active` or `always`. |
287
- | `dragPreviewSize` | `drag-preview-size` | `match-item` or `compact`. |
463
+ | `dragPreviewSize` | `drag-preview-size` | The card that follows the pointer: `match-item` (the card's own size) or `compact` (narrower, title only). |
288
464
  | `dragHandleMode` | `drag-handle-mode` | `handle` (drag by the grip) or `item` (drag anywhere on the card). |
289
465
  | `dragHandleSelector` | `drag-handle-selector` | A selector for your own drag handle. |
290
466
  | `persistKey` | `persist-key` | Keep where each item is in `localStorage` under this key, and restore it on load. |
@@ -294,19 +470,52 @@ export default function CustomRendering() {
294
470
 
295
471
  The React wrapper also takes `itemRadius`, `handleRadius`, `listGap` and `itemSpacing` for the look.
296
472
 
473
+ ## Nesting, touch and keyboard
474
+
475
+ With nesting on (the default), the top half of a card is "before it" and the bottom half "after it", so dragging onto a
476
+ card always reorders. To drop an item *inside* another, hold **Alt** (Option) or drop on the far side of the card (its
477
+ right, in a left-to-right page): the card highlights before you let go. Set `nestTrigger="area"` for the old rule, where the
478
+ middle of a card nests, or `allowNesting={false}` to turn it off. The keyboard has an explicit "Nest inside" destination, so it
479
+ needs none of this.
480
+
481
+ A card dragged by its body (`dragHandleMode="item"`, or your own handle) is lifted on touch by holding it for a third of a
482
+ second; a finger that moves first scrolls the page, and a tap still selects. The built-in handle lifts at once.
483
+
484
+ ## Look and layout
485
+
486
+ Lists sit side by side and the board scrolls sideways when they do not fit (each list is at least 260px wide;
487
+ change it with `--ui-sortable-list-min-size`). Holding a card at the edge of the board scrolls it. A card you pick up is
488
+ lifted under the pointer, its place stays as an empty slot, and a thin line shows where it will land.
489
+
490
+ The colours come from `--ui-color-primary`, `--ui-color-surface`, `--ui-color-text`, `--ui-color-muted` and
491
+ `--ui-color-border`; set them on the element or a parent to theme it, dark included. The parts `root`, `toolbar`,
492
+ `lists`, `list`, `items`, `item`, `handle`, `dropzone` and `drag-ghost` can be styled from outside:
493
+
494
+ ```css
495
+ /* Stack the lists instead of scrolling them sideways. */
496
+ ui-sortable::part(lists) {
497
+ grid-auto-flow: row;
498
+ overflow: visible;
499
+ }
500
+ ```
501
+
502
+ A list can scroll by itself instead: `maxHeight` on a list, or `listMaxHeight` for all of them.
503
+
297
504
  ## Events
298
505
 
299
506
  | Event | React prop | `detail` |
300
507
  | --- | --- | --- |
301
- | `change` | `onChange` | `{ items, lists, selection, previousSelection, movedIds, source, operation, persistence }`. `source` is `pointer`, `keyboard`, `api` or `restore`; `operation` is `reorder`, `transfer`, `nest` or `clone`. |
508
+ | `before-change` | `onBeforeChange` | Cancelable. The same as `change`, before it is applied, plus `target` and `clone`. In React return `false` to cancel. |
509
+ | `change` | `onChange` | `{ items, lists, selection, previousSelection, movedIds, source, operation, persistence, external? }`. `external` (`{ direction, peer }`, where `direction` is `'in'` or `'out'`) is only there when the items crossed between two sortables. `source` is `pointer`, `keyboard`, `api` or `restore`; `operation` is `reorder`, `transfer`, `nest` or `clone`. |
302
510
  | | `onItemsChange` | The new `items` array. |
303
511
  | `selection-change` | `onSelectionChange` | `{ selection, previousSelection }` |
304
512
  | `persist-request` | `onPersistRequest` | The same detail as `change`: `persistence.records` is `[{ id, listId, parentId, index }]`, ready to save. |
305
513
 
306
514
  ## Methods
307
515
 
308
- On the element (or a ref to it): `select(ids)`, `clearSelection()`, `moveSelection({ targetListId, beforeId?, parentId?, mode?, clone? })`,
309
- `focusItem(id)`, `cancelDrag()` and `getPersistenceSnapshot()`.
516
+ On the element (or a ref to it): `select(ids)`, `clearSelection()`, `moveSelection({ targetListId, beforeId?, parentId?, mode?, clone? })`
517
+ (which returns whether anything moved), `moveSelectionTo(otherSortable, options)` (the same into another sortable), `focusItem(id)`, `cancelDrag()` and `getPersistenceSnapshot()`. The properties
518
+ `canDrop`, `labels`, `renderItem`, `renderListHeader` and `renderEmptyState` can be set on it as well.
310
519
 
311
520
  ## Keyboard
312
521
 
@@ -316,9 +525,11 @@ explains the keys.
316
525
 
317
526
  ## Types
318
527
 
319
- `@editora/ui-sortable` re-exports `UISortable`, `UISortableList`, `UISortableItem`, `UISortableChangeDetail` and
320
- `UISortableDropzoneStyle`. `@editora/ui-sortable/react` exports `Sortable`, `SortableList`, `SortableItem`,
321
- `SortableChangeDetail` and `SortableDropzoneStyle`.
528
+ `@editora/ui-sortable` re-exports `UISortable`, `UISortableList`, `UISortableItem`, `UISortableChangeDetail`,
529
+ `UISortableBeforeChangeDetail`, `UISortableDropInfo`, `UISortableLabels`, `UISortableNestTrigger` and
530
+ `UISortableDropzoneStyle`, among others. `@editora/ui-sortable/react` exports `Sortable`, `SortableList`, `SortableItem`,
531
+ `SortableChangeDetail`, `SortableBeforeChangeDetail`, `SortableDropInfo`, `SortableLabels`, `SortableNestTrigger` and
532
+ `SortableDropzoneStyle`.
322
533
 
323
534
  ## Server rendering
324
535
 
package/dist/react.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E=require("react/jsx-runtime"),bt=require("react"),z=require("react-dom");require("@editora/ui-core/sortable");const gt=e=>e&&e.__esModule?e:{default:e},b=gt(bt),C=typeof window<"u"?b.default.useLayoutEffect:b.default.useEffect;function mt(e,s,...i){if(!s||!("className"in s)||!e.includes("-"))return b.default.createElement(e,s,...i);const{className:l,...g}=s,o=[g.class,l].filter(n=>typeof n=="string"&&n!=="").join(" ");return b.default.createElement(e,o?{...g,class:o}:g,...i)}function pt(e){const s=b.default.useRef(null);return b.default.useImperativeHandle(e,()=>s.current),s}function yt(e,s,i){b.default.useEffect(()=>{const l=e.current;if(!l)return;const g=s.filter(o=>typeof o.listener=="function");return g.forEach(({type:o,listener:n})=>{l.addEventListener(o,n)}),()=>{g.forEach(({type:o,listener:n})=>{l.removeEventListener(o,n)})}},[e,...i])}function ht(e,s,i){C(()=>{const l=e.current;l&&s(l)},[e,...i])}function H(e){return e.detail}function y(e,s,i){const l=e.getAttribute(s);if(i==null||i===""){l!=null&&e.removeAttribute(s);return}l!==i&&e.setAttribute(s,i)}function st(e,s,i){if(i){e.hasAttribute(s)||e.setAttribute(s,"");return}e.hasAttribute(s)&&e.removeAttribute(s)}function T(e,s,i){if(i==null){y(e,s,null);return}try{y(e,s,JSON.stringify(i))}catch{y(e,s,null)}}function B(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/"/g,'\\"')}function it(e){if(e==null||e==="")return null;if(typeof e=="number")return`${e}px`;switch(e){case"none":return"0px";case"sm":return"10px";case"md":return"16px";case"lg":return"20px";case"xl":return"28px";case"full":return"999px";default:return e}}function At(e){if(e==null||e==="")return null;if(typeof e=="number")return`${e}px`;switch(e){case"xs":return"6px";case"sm":return"8px";case"md":return"10px";case"lg":return"14px";case"xl":return"18px";default:return e}}const vt=[],St=[],F=b.default.forwardRef(function(s,i){const{lists:l,items:g,selection:o,filterQuery:n,sort:m,persistKey:L,allowFilteredDrag:P,allowNesting:D,dropIndicatorVisibility:M,dropzoneStyle:Q,dragPreviewSize:O,dragHandleMode:S,dragHandleSelector:h,itemRadius:k,handleRadius:G,listGap:J,itemSpacing:K,showSelectionBadge:_,disabled:A,renderItem:c,renderListHeader:w,renderEmptyState:R,onChange:j,onItemsChange:N,onSelectionChange:V,onPersistRequest:$,children:ot,...at}=s,f=l??vt,p=g??St,u=pt(i),[x,nt]=b.default.useState(0),U=!!(c||w||R);yt(u,[{type:"change",listener:j||N?(t=>{const r=H(t);r&&(j?.(r),N?.(r.items))}):void 0},{type:"selection-change",listener:V?(t=>{const r=H(t);r&&V(r)}):void 0},{type:"persist-request",listener:$?(t=>{const r=H(t);r&&$(r)}):void 0}],[j,N,V,$]),ht(u,t=>{T(t,"lists",f),T(t,"items",p),T(t,"selection",o??null),y(t,"filter-query",n??null),y(t,"sort",m&&m!=="manual"?m:null),y(t,"persist-key",L??null),st(t,"allow-filtered-drag",P),D===!1?t.setAttribute("allow-nesting","false"):t.removeAttribute("allow-nesting"),M==="always"?t.setAttribute("drop-indicator-visibility","always"):t.removeAttribute("drop-indicator-visibility"),Q==="container"?t.setAttribute("dropzone-style","container"):t.removeAttribute("dropzone-style"),O==="compact"?t.setAttribute("drag-preview-size","compact"):t.removeAttribute("drag-preview-size"),S==="item"?t.setAttribute("drag-handle-mode","item"):t.removeAttribute("drag-handle-mode"),y(t,"drag-handle-selector",h??null);const r=it(k);r?t.style.setProperty("--ui-sortable-item-radius",r):t.style.removeProperty("--ui-sortable-item-radius");const d=it(G);d?t.style.setProperty("--ui-sortable-handle-radius",d):t.style.removeProperty("--ui-sortable-handle-radius");const a=At(J??K);a?t.style.setProperty("--ui-sortable-list-gap",a):t.style.removeProperty("--ui-sortable-list-gap"),c?t.setAttribute("custom-item-rendering","true"):t.removeAttribute("custom-item-rendering"),_===!1?t.setAttribute("show-selection-badge","false"):t.removeAttribute("show-selection-badge"),st(t,"disabled",A)},[f,p,o,n,m,L,P,D,M,Q,O,S,h,k,G,J,K,c,_,A]),C(()=>{if(!U)return;const t=u.current,r=t?.ownerDocument?.defaultView;if(!t||!r)return;let d=!1,a=!1,q=null,I=null;const tt=[c&&p.length>0?".item-custom-content[data-item-content-target]":null,w&&f.length>0?".list-custom-header[data-list-header-target]":null,R&&f.length>0?".list-custom-empty[data-list-empty-target]":null].filter(Boolean).join(", "),et=()=>{d||a||(a=!0,queueMicrotask(()=>{a=!1,!d&&nt(v=>v+1)}))},ct=()=>{const v=u.current?.shadowRoot;return v?(I||(I=new MutationObserver(()=>et()),I.observe(v,{childList:!0,subtree:!0})),!0):!1},rt=()=>{if(d)return;const v=u.current?.shadowRoot,ft=!tt||!!v?.querySelector(tt);if(ct()&&ft){et();return}q=r.requestAnimationFrame(rt)};return rt(),()=>{d=!0,q!==null&&r.cancelAnimationFrame(q),I?.disconnect()}},[u,U,p,f,o,n,m,L,P,D,M,O,S,h,_,A,c,w,R]),C(()=>{const t=u.current,r=t?.shadowRoot;if(!t)return;if(!c||!r){t.removeAttribute("custom-item-rendering-ready"),t.removeAttribute("custom-item-rendering-pending");return}const d=r.querySelectorAll(".item-custom-content[data-item-content-target]"),a=r.querySelectorAll("[data-sortable-custom-item]");d.length>0&&a.length>=d.length?(t.setAttribute("custom-item-rendering-ready","true"),t.removeAttribute("custom-item-rendering-pending")):(t.removeAttribute("custom-item-rendering-ready"),t.setAttribute("custom-item-rendering-pending","true"))},[u,c,x,p,o,n,m,A]),C(()=>{const t=u.current?.shadowRoot;t&&(t.querySelectorAll("[data-sortable-custom-handle]").forEach(r=>{r.removeAttribute("data-sortable-custom-handle"),r.removeAttribute("data-drag-trigger"),r.removeAttribute("data-id"),r.removeAttribute("draggable"),r.hasAttribute("data-sortable-handle-tabindex")&&(r.removeAttribute("data-sortable-handle-tabindex"),r.removeAttribute("tabindex"))}),!(!c||!h||S==="item")&&t.querySelectorAll("[data-sortable-custom-item][data-sortable-item-id]").forEach(r=>{const d=r.getAttribute("data-sortable-item-id");d&&r.querySelectorAll(h).forEach(a=>{a.setAttribute("data-sortable-custom-handle",""),a.setAttribute("data-drag-trigger","custom"),a.setAttribute("data-id",d),a.setAttribute("draggable","true"),a.hasAttribute("tabindex")||(a.setAttribute("tabindex","-1"),a.setAttribute("data-sortable-handle-tabindex",""))})}))},[u,c,h,S,x,p,o,n,m,A]);const W=new Map(f.map(t=>[t.id,t])),X=new Map(f.map(t=>[t.id,p.filter(r=>r.listId===t.id).length])),Y=!!A||m==="label"||!!n&&!P,ut=c?p.map(t=>{const r=u.current?.shadowRoot?.querySelector(`.item-custom-content[data-item-content-target="${B(t.id)}"]`);return r?z.createPortal(E.jsx("div",{"data-sortable-custom-item":"","data-sortable-item-id":t.id,"data-selected":o?.includes(t.id)?"true":"false","data-disabled":t.disabled?"true":"false","data-drag-disabled":t.dragDisabled?"true":"false",children:c(t,{selected:o?.includes(t.id)??!1,disabled:!!t.disabled,dragDisabled:!!t.dragDisabled,cloneOnDrag:!!t.cloneOnDrag||!!W.get(t.listId)?.cloneOnDrag,list:W.get(t.listId)})}),r,t.id):null}):null,lt=w?f.map(t=>{const r=u.current?.shadowRoot?.querySelector(`.list-custom-header[data-list-header-target="${B(t.id)}"]`);return r?z.createPortal(E.jsx("div",{"data-sortable-custom-list-header":"","data-sortable-list-id":t.id,children:w(t,{itemCount:X.get(t.id)??0,dragLocked:Y})}),r,`header-${t.id}`):null}):null,dt=R?f.map(t=>{const r=u.current?.shadowRoot?.querySelector(`.list-custom-empty[data-list-empty-target="${B(t.id)}"]`);return r?z.createPortal(E.jsx("div",{"data-sortable-custom-empty":"","data-sortable-list-id":t.id,children:R(t,{itemCount:X.get(t.id)??0,dragLocked:Y,filterQuery:n??""})}),r,`empty-${t.id}`):null}):null,Z={ref:u,...at};return c&&(Z["custom-item-rendering"]=""),E.jsxs(E.Fragment,{children:[mt("ui-sortable",Z,ot),x>=0?ut:null,x>=0?lt:null,x>=0?dt:null]})});F.displayName="Sortable";exports.Sortable=F;exports.default=F;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E=require("react/jsx-runtime"),St=require("react"),G=require("react-dom");require("@editora/ui-core/sortable");const wt=e=>e&&e.__esModule?e:{default:e},g=wt(St),_=typeof window<"u"?g.default.useLayoutEffect:g.default.useEffect;function xt(e,s,...i){if(!s||!("className"in s)||!e.includes("-"))return g.default.createElement(e,s,...i);const{className:l,...m}=s,o=[m.class,l].filter(n=>typeof n=="string"&&n!=="").join(" ");return g.default.createElement(e,o?{...m,class:o}:m,...i)}function Rt(e){const s=g.default.useRef(null);return g.default.useImperativeHandle(e,()=>s.current),s}function Et(e,s,i){g.default.useEffect(()=>{const l=e.current;if(!l)return;const m=s.filter(o=>typeof o.listener=="function");return m.forEach(({type:o,listener:n})=>{l.addEventListener(o,n)}),()=>{m.forEach(({type:o,listener:n})=>{l.removeEventListener(o,n)})}},[e,...i])}function Pt(e,s,i){_(()=>{const l=e.current;l&&s(l)},[e,...i])}function O(e){return e.detail}function f(e,s,i){const l=e.getAttribute(s);if(i==null||i===""){l!=null&&e.removeAttribute(s);return}l!==i&&e.setAttribute(s,i)}function J(e,s,i){if(i){e.hasAttribute(s)||e.setAttribute(s,"");return}e.hasAttribute(s)&&e.removeAttribute(s)}function j(e,s,i){if(i==null){f(e,s,null);return}try{f(e,s,JSON.stringify(i))}catch{f(e,s,null)}}function K(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/"/g,'\\"')}function ft(e){if(e==null||e==="")return null;if(typeof e=="number")return`${e}px`;switch(e){case"none":return"0px";case"sm":return"10px";case"md":return"16px";case"lg":return"20px";case"xl":return"28px";case"full":return"999px";default:return e}}function qt(e){if(e==null||e==="")return null;if(typeof e=="number")return`${e}px`;switch(e){case"xs":return"6px";case"sm":return"8px";case"md":return"10px";case"lg":return"14px";case"xl":return"18px";default:return e}}const It=[],Dt=[],U=g.default.forwardRef(function(s,i){const{lists:l,items:m,selection:o,filterQuery:n,sort:p,persistKey:H,allowFilteredDrag:P,allowNesting:N,nestTrigger:q,group:W,touchHoldDelay:I,listMaxHeight:D,dropIndicatorVisibility:T,dropzoneStyle:X,dragPreviewSize:V,dragHandleMode:S,dragHandleSelector:y,itemRadius:Y,handleRadius:Z,listGap:tt,itemSpacing:et,canDrop:rt,showSelectionBadge:$,labels:C,hideToolbar:st,disabled:A,renderItem:c,renderListHeader:w,renderEmptyState:x,onBeforeChange:z,onChange:B,onItemsChange:F,onSelectionChange:k,onPersistRequest:Q,children:bt,...gt}=s,b=l??It,h=m??Dt,u=Rt(i),[R,mt]=g.default.useState(0),it=!!(c||w||x);Et(u,[{type:"before-change",listener:z?(t=>{const r=O(t);r&&z(r,t)===!1&&t.preventDefault()}):void 0},{type:"change",listener:B||F?(t=>{const r=O(t);r&&(B?.(r),F?.(r.items))}):void 0},{type:"selection-change",listener:k?(t=>{const r=O(t);r&&k(r)}):void 0},{type:"persist-request",listener:Q?(t=>{const r=O(t);r&&Q(r)}):void 0}],[z,B,F,k,Q]),Pt(u,t=>{j(t,"lists",b),j(t,"items",h),j(t,"selection",o??null),f(t,"filter-query",n??null),f(t,"sort",p&&p!=="manual"?p:null),f(t,"persist-key",H??null),J(t,"allow-filtered-drag",P),N===!1?t.setAttribute("allow-nesting","false"):t.removeAttribute("allow-nesting"),f(t,"nest-trigger",q&&q!=="gutter"?q:null),f(t,"list-max-height",typeof D=="number"?String(D)+"px":D??null),f(t,"group",W??null),f(t,"touch-hold-delay",typeof I=="number"&&Number.isFinite(I)?String(I):null),T==="always"?t.setAttribute("drop-indicator-visibility","always"):t.removeAttribute("drop-indicator-visibility"),X==="container"?t.setAttribute("dropzone-style","container"):t.removeAttribute("dropzone-style"),V==="compact"?t.setAttribute("drag-preview-size","compact"):t.removeAttribute("drag-preview-size"),S==="item"?t.setAttribute("drag-handle-mode","item"):t.removeAttribute("drag-handle-mode"),f(t,"drag-handle-selector",y??null);const r=ft(Y);r?t.style.setProperty("--ui-sortable-item-radius",r):t.style.removeProperty("--ui-sortable-item-radius");const d=ft(Z);d?t.style.setProperty("--ui-sortable-handle-radius",d):t.style.removeProperty("--ui-sortable-handle-radius");const a=qt(tt??et);a?t.style.setProperty("--ui-sortable-list-gap",a):t.style.removeProperty("--ui-sortable-list-gap"),c?t.setAttribute("custom-item-rendering","true"):t.removeAttribute("custom-item-rendering"),$===!1?t.setAttribute("show-selection-badge","false"):t.removeAttribute("show-selection-badge"),t.canDrop=rt??null,j(t,"labels",C&&Object.keys(C).length?C:null),J(t,"hide-toolbar",st),J(t,"disabled",A)},[b,h,o,n,p,H,P,N,q,W,I,D,T,X,V,S,y,Y,Z,tt,et,c,$,rt,C,st,A]),_(()=>{if(!it)return;const t=u.current,r=t?.ownerDocument?.defaultView;if(!t||!r)return;let d=!1,a=!1,L=null,M=null;const lt=[c&&h.length>0?".item-custom-content[data-item-content-target]":null,w&&b.length>0?".list-custom-header[data-list-header-target]":null,x&&b.length>0?".list-custom-empty[data-list-empty-target]":null].filter(Boolean).join(", "),dt=()=>{d||a||(a=!0,queueMicrotask(()=>{a=!1,!d&&mt(v=>v+1)}))},At=()=>{const v=u.current?.shadowRoot;return v?(M||(M=new MutationObserver(()=>dt()),M.observe(v,{childList:!0,subtree:!0})),!0):!1},ct=()=>{if(d)return;const v=u.current?.shadowRoot,vt=!lt||!!v?.querySelector(lt);if(At()&&vt){dt();return}L=r.requestAnimationFrame(ct)};return ct(),()=>{d=!0,L!==null&&r.cancelAnimationFrame(L),M?.disconnect()}},[u,it,h,b,o,n,p,H,P,N,T,V,S,y,$,A,c,w,x]),_(()=>{const t=u.current,r=t?.shadowRoot;if(!t)return;if(!c||!r){t.removeAttribute("custom-item-rendering-ready"),t.removeAttribute("custom-item-rendering-pending");return}const d=r.querySelectorAll(".item-custom-content[data-item-content-target]"),a=r.querySelectorAll("[data-sortable-custom-item]");d.length>0&&a.length>=d.length?(t.setAttribute("custom-item-rendering-ready","true"),t.removeAttribute("custom-item-rendering-pending")):(t.removeAttribute("custom-item-rendering-ready"),t.setAttribute("custom-item-rendering-pending","true"))},[u,c,R,h,o,n,p,A]),_(()=>{const t=u.current?.shadowRoot;t&&(t.querySelectorAll("[data-sortable-custom-handle]").forEach(r=>{r.removeAttribute("data-sortable-custom-handle"),r.removeAttribute("data-drag-trigger"),r.removeAttribute("data-id"),r.removeAttribute("draggable"),r.hasAttribute("data-sortable-handle-tabindex")&&(r.removeAttribute("data-sortable-handle-tabindex"),r.removeAttribute("tabindex"))}),!(!c||!y||S==="item")&&t.querySelectorAll("[data-sortable-custom-item][data-sortable-item-id]").forEach(r=>{const d=r.getAttribute("data-sortable-item-id");d&&r.querySelectorAll(y).forEach(a=>{a.setAttribute("data-sortable-custom-handle",""),a.setAttribute("data-drag-trigger","custom"),a.setAttribute("data-id",d),a.hasAttribute("tabindex")||(a.setAttribute("tabindex","-1"),a.setAttribute("data-sortable-handle-tabindex",""))})}))},[u,c,y,S,R,h,o,n,p,A]);const ot=new Map(b.map(t=>[t.id,t])),at=new Map(b.map(t=>[t.id,h.filter(r=>r.listId===t.id).length])),nt=!!A||p==="label"||!!n&&!P,pt=c?h.map(t=>{const r=u.current?.shadowRoot?.querySelector(`.item-custom-content[data-item-content-target="${K(t.id)}"]`);return r?G.createPortal(E.jsx("div",{"data-sortable-custom-item":"","data-sortable-item-id":t.id,"data-selected":o?.includes(t.id)?"true":"false","data-disabled":t.disabled?"true":"false","data-drag-disabled":t.dragDisabled?"true":"false",children:c(t,{selected:o?.includes(t.id)??!1,disabled:!!t.disabled,dragDisabled:!!t.dragDisabled,cloneOnDrag:!!t.cloneOnDrag||!!ot.get(t.listId)?.cloneOnDrag,list:ot.get(t.listId)})}),r,t.id):null}):null,ht=w?b.map(t=>{const r=u.current?.shadowRoot?.querySelector(`.list-custom-header[data-list-header-target="${K(t.id)}"]`);return r?G.createPortal(E.jsx("div",{"data-sortable-custom-list-header":"","data-sortable-list-id":t.id,children:w(t,{itemCount:at.get(t.id)??0,dragLocked:nt})}),r,`header-${t.id}`):null}):null,yt=x?b.map(t=>{const r=u.current?.shadowRoot?.querySelector(`.list-custom-empty[data-list-empty-target="${K(t.id)}"]`);return r?G.createPortal(E.jsx("div",{"data-sortable-custom-empty":"","data-sortable-list-id":t.id,children:x(t,{itemCount:at.get(t.id)??0,dragLocked:nt,filterQuery:n??""})}),r,`empty-${t.id}`):null}):null,ut={ref:u,...gt};return c&&(ut["custom-item-rendering"]=""),E.jsxs(E.Fragment,{children:[xt("ui-sortable",ut,bt),R>=0?pt:null,R>=0?ht:null,R>=0?yt:null]})});U.displayName="Sortable";exports.Sortable=U;exports.default=U;
package/dist/react.esm.js CHANGED
@@ -1,20 +1,20 @@
1
- import { jsx as M, jsxs as ft, Fragment as bt } from "react/jsx-runtime";
2
- import b from "react";
3
- import { createPortal as B } from "react-dom";
1
+ import { jsx as G, jsxs as vt, Fragment as St } from "react/jsx-runtime";
2
+ import g from "react";
3
+ import { createPortal as J } from "react-dom";
4
4
  import "@editora/ui-core/sortable";
5
- const q = typeof window < "u" ? b.useLayoutEffect : b.useEffect;
6
- function mt(e, s, ...i) {
5
+ const N = typeof window < "u" ? g.useLayoutEffect : g.useEffect;
6
+ function wt(e, s, ...i) {
7
7
  if (!s || !("className" in s) || !e.includes("-"))
8
- return b.createElement(e, s, ...i);
8
+ return g.createElement(e, s, ...i);
9
9
  const { className: l, ...m } = s, o = [m.class, l].filter((n) => typeof n == "string" && n !== "").join(" ");
10
- return b.createElement(e, o ? { ...m, class: o } : m, ...i);
10
+ return g.createElement(e, o ? { ...m, class: o } : m, ...i);
11
11
  }
12
- function gt(e) {
13
- const s = b.useRef(null);
14
- return b.useImperativeHandle(e, () => s.current), s;
12
+ function xt(e) {
13
+ const s = g.useRef(null);
14
+ return g.useImperativeHandle(e, () => s.current), s;
15
15
  }
16
- function pt(e, s, i) {
17
- b.useEffect(() => {
16
+ function Rt(e, s, i) {
17
+ g.useEffect(() => {
18
18
  const l = e.current;
19
19
  if (!l) return;
20
20
  const m = s.filter(
@@ -29,16 +29,16 @@ function pt(e, s, i) {
29
29
  };
30
30
  }, [e, ...i]);
31
31
  }
32
- function yt(e, s, i) {
33
- q(() => {
32
+ function Et(e, s, i) {
33
+ N(() => {
34
34
  const l = e.current;
35
35
  l && s(l);
36
36
  }, [e, ...i]);
37
37
  }
38
- function F(e) {
38
+ function O(e) {
39
39
  return e.detail;
40
40
  }
41
- function y(e, s, i) {
41
+ function f(e, s, i) {
42
42
  const l = e.getAttribute(s);
43
43
  if (i == null || i === "") {
44
44
  l != null && e.removeAttribute(s);
@@ -46,28 +46,28 @@ function y(e, s, i) {
46
46
  }
47
47
  l !== i && e.setAttribute(s, i);
48
48
  }
49
- function rt(e, s, i) {
49
+ function _(e, s, i) {
50
50
  if (i) {
51
51
  e.hasAttribute(s) || e.setAttribute(s, "");
52
52
  return;
53
53
  }
54
54
  e.hasAttribute(s) && e.removeAttribute(s);
55
55
  }
56
- function T(e, s, i) {
56
+ function H(e, s, i) {
57
57
  if (i == null) {
58
- y(e, s, null);
58
+ f(e, s, null);
59
59
  return;
60
60
  }
61
61
  try {
62
- y(e, s, JSON.stringify(i));
62
+ f(e, s, JSON.stringify(i));
63
63
  } catch {
64
- y(e, s, null);
64
+ f(e, s, null);
65
65
  }
66
66
  }
67
- function j(e) {
67
+ function K(e) {
68
68
  return typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(e) : e.replace(/"/g, '\\"');
69
69
  }
70
- function st(e) {
70
+ function ct(e) {
71
71
  if (e == null || e === "") return null;
72
72
  if (typeof e == "number") return `${e}px`;
73
73
  switch (e) {
@@ -87,7 +87,7 @@ function st(e) {
87
87
  return e;
88
88
  }
89
89
  }
90
- function ht(e) {
90
+ function Pt(e) {
91
91
  if (e == null || e === "") return null;
92
92
  if (typeof e == "number") return `${e}px`;
93
93
  switch (e) {
@@ -105,145 +105,167 @@ function ht(e) {
105
105
  return e;
106
106
  }
107
107
  }
108
- const At = [], vt = [], wt = b.forwardRef(function(s, i) {
108
+ const It = [], qt = [], Ct = g.forwardRef(function(s, i) {
109
109
  const {
110
110
  lists: l,
111
111
  items: m,
112
112
  selection: o,
113
113
  filterQuery: n,
114
- sort: g,
115
- persistKey: C,
114
+ sort: p,
115
+ persistKey: M,
116
116
  allowFilteredDrag: E,
117
- allowNesting: L,
118
- dropIndicatorVisibility: D,
119
- dropzoneStyle: Q,
120
- dragPreviewSize: O,
121
- dragHandleMode: w,
122
- dragHandleSelector: h,
123
- itemRadius: k,
124
- handleRadius: G,
125
- listGap: J,
126
- itemSpacing: _,
127
- showSelectionBadge: N,
117
+ allowNesting: T,
118
+ nestTrigger: P,
119
+ group: U,
120
+ touchHoldDelay: I,
121
+ listMaxHeight: q,
122
+ dropIndicatorVisibility: V,
123
+ dropzoneStyle: W,
124
+ dragPreviewSize: $,
125
+ dragHandleMode: S,
126
+ dragHandleSelector: y,
127
+ itemRadius: X,
128
+ handleRadius: Y,
129
+ listGap: Z,
130
+ itemSpacing: tt,
131
+ canDrop: et,
132
+ showSelectionBadge: z,
133
+ labels: C,
134
+ hideToolbar: rt,
128
135
  disabled: A,
129
136
  renderItem: c,
130
- renderListHeader: S,
131
- renderEmptyState: R,
132
- onChange: V,
133
- onItemsChange: $,
134
- onSelectionChange: z,
135
- onPersistRequest: H,
136
- children: it,
137
- ...ot
138
- } = s, f = l ?? At, p = m ?? vt, u = gt(i), [x, at] = b.useState(0), K = !!(c || S || R);
139
- pt(
137
+ renderListHeader: w,
138
+ renderEmptyState: x,
139
+ onBeforeChange: B,
140
+ onChange: F,
141
+ onItemsChange: j,
142
+ onSelectionChange: k,
143
+ onPersistRequest: Q,
144
+ children: ft,
145
+ ...bt
146
+ } = s, b = l ?? It, h = m ?? qt, u = xt(i), [R, gt] = g.useState(0), st = !!(c || w || x);
147
+ Rt(
140
148
  u,
141
149
  [
150
+ {
151
+ type: "before-change",
152
+ listener: B ? ((t) => {
153
+ const r = O(t);
154
+ r && B(r, t) === !1 && t.preventDefault();
155
+ }) : void 0
156
+ },
142
157
  {
143
158
  type: "change",
144
- listener: V || $ ? ((t) => {
145
- const r = F(t);
146
- r && (V?.(r), $?.(r.items));
159
+ listener: F || j ? ((t) => {
160
+ const r = O(t);
161
+ r && (F?.(r), j?.(r.items));
147
162
  }) : void 0
148
163
  },
149
164
  {
150
165
  type: "selection-change",
151
- listener: z ? ((t) => {
152
- const r = F(t);
153
- r && z(r);
166
+ listener: k ? ((t) => {
167
+ const r = O(t);
168
+ r && k(r);
154
169
  }) : void 0
155
170
  },
156
171
  {
157
172
  type: "persist-request",
158
- listener: H ? ((t) => {
159
- const r = F(t);
160
- r && H(r);
173
+ listener: Q ? ((t) => {
174
+ const r = O(t);
175
+ r && Q(r);
161
176
  }) : void 0
162
177
  }
163
178
  ],
164
- [V, $, z, H]
165
- ), yt(
179
+ [B, F, j, k, Q]
180
+ ), Et(
166
181
  u,
167
182
  (t) => {
168
- T(t, "lists", f), T(t, "items", p), T(t, "selection", o ?? null), y(t, "filter-query", n ?? null), y(t, "sort", g && g !== "manual" ? g : null), y(t, "persist-key", C ?? null), rt(t, "allow-filtered-drag", E), L === !1 ? t.setAttribute("allow-nesting", "false") : t.removeAttribute("allow-nesting"), D === "always" ? t.setAttribute("drop-indicator-visibility", "always") : t.removeAttribute("drop-indicator-visibility"), Q === "container" ? t.setAttribute("dropzone-style", "container") : t.removeAttribute("dropzone-style"), O === "compact" ? t.setAttribute("drag-preview-size", "compact") : t.removeAttribute("drag-preview-size"), w === "item" ? t.setAttribute("drag-handle-mode", "item") : t.removeAttribute("drag-handle-mode"), y(t, "drag-handle-selector", h ?? null);
169
- const r = st(k);
183
+ H(t, "lists", b), H(t, "items", h), H(t, "selection", o ?? null), f(t, "filter-query", n ?? null), f(t, "sort", p && p !== "manual" ? p : null), f(t, "persist-key", M ?? null), _(t, "allow-filtered-drag", E), T === !1 ? t.setAttribute("allow-nesting", "false") : t.removeAttribute("allow-nesting"), f(t, "nest-trigger", P && P !== "gutter" ? P : null), f(t, "list-max-height", typeof q == "number" ? String(q) + "px" : q ?? null), f(t, "group", U ?? null), f(t, "touch-hold-delay", typeof I == "number" && Number.isFinite(I) ? String(I) : null), V === "always" ? t.setAttribute("drop-indicator-visibility", "always") : t.removeAttribute("drop-indicator-visibility"), W === "container" ? t.setAttribute("dropzone-style", "container") : t.removeAttribute("dropzone-style"), $ === "compact" ? t.setAttribute("drag-preview-size", "compact") : t.removeAttribute("drag-preview-size"), S === "item" ? t.setAttribute("drag-handle-mode", "item") : t.removeAttribute("drag-handle-mode"), f(t, "drag-handle-selector", y ?? null);
184
+ const r = ct(X);
170
185
  r ? t.style.setProperty("--ui-sortable-item-radius", r) : t.style.removeProperty("--ui-sortable-item-radius");
171
- const d = st(G);
186
+ const d = ct(Y);
172
187
  d ? t.style.setProperty("--ui-sortable-handle-radius", d) : t.style.removeProperty("--ui-sortable-handle-radius");
173
- const a = ht(J ?? _);
174
- a ? t.style.setProperty("--ui-sortable-list-gap", a) : t.style.removeProperty("--ui-sortable-list-gap"), c ? t.setAttribute("custom-item-rendering", "true") : t.removeAttribute("custom-item-rendering"), N === !1 ? t.setAttribute("show-selection-badge", "false") : t.removeAttribute("show-selection-badge"), rt(t, "disabled", A);
188
+ const a = Pt(Z ?? tt);
189
+ a ? t.style.setProperty("--ui-sortable-list-gap", a) : t.style.removeProperty("--ui-sortable-list-gap"), c ? t.setAttribute("custom-item-rendering", "true") : t.removeAttribute("custom-item-rendering"), z === !1 ? t.setAttribute("show-selection-badge", "false") : t.removeAttribute("show-selection-badge"), t.canDrop = et ?? null, H(t, "labels", C && Object.keys(C).length ? C : null), _(t, "hide-toolbar", rt), _(t, "disabled", A);
175
190
  },
176
191
  [
177
- f,
178
- p,
192
+ b,
193
+ h,
179
194
  o,
180
195
  n,
181
- g,
182
- C,
196
+ p,
197
+ M,
183
198
  E,
184
- L,
185
- D,
186
- Q,
187
- O,
188
- w,
189
- h,
190
- k,
191
- G,
192
- J,
193
- _,
199
+ T,
200
+ P,
201
+ U,
202
+ I,
203
+ q,
204
+ V,
205
+ W,
206
+ $,
207
+ S,
208
+ y,
209
+ X,
210
+ Y,
211
+ Z,
212
+ tt,
194
213
  c,
195
- N,
214
+ z,
215
+ et,
216
+ C,
217
+ rt,
196
218
  A
197
219
  ]
198
- ), q(() => {
199
- if (!K) return;
220
+ ), N(() => {
221
+ if (!st) return;
200
222
  const t = u.current, r = t?.ownerDocument?.defaultView;
201
223
  if (!t || !r) return;
202
- let d = !1, a = !1, P = null, I = null;
203
- const Z = [
204
- c && p.length > 0 ? ".item-custom-content[data-item-content-target]" : null,
205
- S && f.length > 0 ? ".list-custom-header[data-list-header-target]" : null,
206
- R && f.length > 0 ? ".list-custom-empty[data-list-empty-target]" : null
207
- ].filter(Boolean).join(", "), tt = () => {
224
+ let d = !1, a = !1, D = null, L = null;
225
+ const ut = [
226
+ c && h.length > 0 ? ".item-custom-content[data-item-content-target]" : null,
227
+ w && b.length > 0 ? ".list-custom-header[data-list-header-target]" : null,
228
+ x && b.length > 0 ? ".list-custom-empty[data-list-empty-target]" : null
229
+ ].filter(Boolean).join(", "), lt = () => {
208
230
  d || a || (a = !0, queueMicrotask(() => {
209
- a = !1, !d && at((v) => v + 1);
231
+ a = !1, !d && gt((v) => v + 1);
210
232
  }));
211
- }, dt = () => {
233
+ }, yt = () => {
212
234
  const v = u.current?.shadowRoot;
213
- return v ? (I || (I = new MutationObserver(() => tt()), I.observe(v, { childList: !0, subtree: !0 })), !0) : !1;
214
- }, et = () => {
235
+ return v ? (L || (L = new MutationObserver(() => lt()), L.observe(v, { childList: !0, subtree: !0 })), !0) : !1;
236
+ }, dt = () => {
215
237
  if (d) return;
216
- const v = u.current?.shadowRoot, ct = !Z || !!v?.querySelector(Z);
217
- if (dt() && ct) {
218
- tt();
238
+ const v = u.current?.shadowRoot, At = !ut || !!v?.querySelector(ut);
239
+ if (yt() && At) {
240
+ lt();
219
241
  return;
220
242
  }
221
- P = r.requestAnimationFrame(et);
243
+ D = r.requestAnimationFrame(dt);
222
244
  };
223
- return et(), () => {
224
- d = !0, P !== null && r.cancelAnimationFrame(P), I?.disconnect();
245
+ return dt(), () => {
246
+ d = !0, D !== null && r.cancelAnimationFrame(D), L?.disconnect();
225
247
  };
226
248
  }, [
227
249
  u,
228
- K,
229
- p,
230
- f,
250
+ st,
251
+ h,
252
+ b,
231
253
  o,
232
254
  n,
233
- g,
234
- C,
255
+ p,
256
+ M,
235
257
  E,
236
- L,
237
- D,
238
- O,
239
- w,
240
- h,
241
- N,
258
+ T,
259
+ V,
260
+ $,
261
+ S,
262
+ y,
263
+ z,
242
264
  A,
243
265
  c,
244
- S,
245
- R
246
- ]), q(() => {
266
+ w,
267
+ x
268
+ ]), N(() => {
247
269
  const t = u.current, r = t?.shadowRoot;
248
270
  if (!t) return;
249
271
  if (!c || !r) {
@@ -252,23 +274,23 @@ const At = [], vt = [], wt = b.forwardRef(function(s, i) {
252
274
  }
253
275
  const d = r.querySelectorAll(".item-custom-content[data-item-content-target]"), a = r.querySelectorAll("[data-sortable-custom-item]");
254
276
  d.length > 0 && a.length >= d.length ? (t.setAttribute("custom-item-rendering-ready", "true"), t.removeAttribute("custom-item-rendering-pending")) : (t.removeAttribute("custom-item-rendering-ready"), t.setAttribute("custom-item-rendering-pending", "true"));
255
- }, [u, c, x, p, o, n, g, A]), q(() => {
277
+ }, [u, c, R, h, o, n, p, A]), N(() => {
256
278
  const t = u.current?.shadowRoot;
257
279
  t && (t.querySelectorAll("[data-sortable-custom-handle]").forEach((r) => {
258
280
  r.removeAttribute("data-sortable-custom-handle"), r.removeAttribute("data-drag-trigger"), r.removeAttribute("data-id"), r.removeAttribute("draggable"), r.hasAttribute("data-sortable-handle-tabindex") && (r.removeAttribute("data-sortable-handle-tabindex"), r.removeAttribute("tabindex"));
259
- }), !(!c || !h || w === "item") && t.querySelectorAll("[data-sortable-custom-item][data-sortable-item-id]").forEach((r) => {
281
+ }), !(!c || !y || S === "item") && t.querySelectorAll("[data-sortable-custom-item][data-sortable-item-id]").forEach((r) => {
260
282
  const d = r.getAttribute("data-sortable-item-id");
261
- d && r.querySelectorAll(h).forEach((a) => {
262
- a.setAttribute("data-sortable-custom-handle", ""), a.setAttribute("data-drag-trigger", "custom"), a.setAttribute("data-id", d), a.setAttribute("draggable", "true"), a.hasAttribute("tabindex") || (a.setAttribute("tabindex", "-1"), a.setAttribute("data-sortable-handle-tabindex", ""));
283
+ d && r.querySelectorAll(y).forEach((a) => {
284
+ a.setAttribute("data-sortable-custom-handle", ""), a.setAttribute("data-drag-trigger", "custom"), a.setAttribute("data-id", d), a.hasAttribute("tabindex") || (a.setAttribute("tabindex", "-1"), a.setAttribute("data-sortable-handle-tabindex", ""));
263
285
  });
264
286
  }));
265
- }, [u, c, h, w, x, p, o, n, g, A]);
266
- const U = new Map(f.map((t) => [t.id, t])), W = new Map(f.map((t) => [t.id, p.filter((r) => r.listId === t.id).length])), X = !!A || g === "label" || !!n && !E, nt = c ? p.map((t) => {
287
+ }, [u, c, y, S, R, h, o, n, p, A]);
288
+ const it = new Map(b.map((t) => [t.id, t])), ot = new Map(b.map((t) => [t.id, h.filter((r) => r.listId === t.id).length])), at = !!A || p === "label" || !!n && !E, mt = c ? h.map((t) => {
267
289
  const r = u.current?.shadowRoot?.querySelector(
268
- `.item-custom-content[data-item-content-target="${j(t.id)}"]`
290
+ `.item-custom-content[data-item-content-target="${K(t.id)}"]`
269
291
  );
270
- return r ? B(
271
- /* @__PURE__ */ M(
292
+ return r ? J(
293
+ /* @__PURE__ */ G(
272
294
  "div",
273
295
  {
274
296
  "data-sortable-custom-item": "",
@@ -280,49 +302,49 @@ const At = [], vt = [], wt = b.forwardRef(function(s, i) {
280
302
  selected: o?.includes(t.id) ?? !1,
281
303
  disabled: !!t.disabled,
282
304
  dragDisabled: !!t.dragDisabled,
283
- cloneOnDrag: !!t.cloneOnDrag || !!U.get(t.listId)?.cloneOnDrag,
284
- list: U.get(t.listId)
305
+ cloneOnDrag: !!t.cloneOnDrag || !!it.get(t.listId)?.cloneOnDrag,
306
+ list: it.get(t.listId)
285
307
  })
286
308
  }
287
309
  ),
288
310
  r,
289
311
  t.id
290
312
  ) : null;
291
- }) : null, ut = S ? f.map((t) => {
313
+ }) : null, pt = w ? b.map((t) => {
292
314
  const r = u.current?.shadowRoot?.querySelector(
293
- `.list-custom-header[data-list-header-target="${j(t.id)}"]`
315
+ `.list-custom-header[data-list-header-target="${K(t.id)}"]`
294
316
  );
295
- return r ? B(
296
- /* @__PURE__ */ M("div", { "data-sortable-custom-list-header": "", "data-sortable-list-id": t.id, children: S(t, {
297
- itemCount: W.get(t.id) ?? 0,
298
- dragLocked: X
317
+ return r ? J(
318
+ /* @__PURE__ */ G("div", { "data-sortable-custom-list-header": "", "data-sortable-list-id": t.id, children: w(t, {
319
+ itemCount: ot.get(t.id) ?? 0,
320
+ dragLocked: at
299
321
  }) }),
300
322
  r,
301
323
  `header-${t.id}`
302
324
  ) : null;
303
- }) : null, lt = R ? f.map((t) => {
325
+ }) : null, ht = x ? b.map((t) => {
304
326
  const r = u.current?.shadowRoot?.querySelector(
305
- `.list-custom-empty[data-list-empty-target="${j(t.id)}"]`
327
+ `.list-custom-empty[data-list-empty-target="${K(t.id)}"]`
306
328
  );
307
- return r ? B(
308
- /* @__PURE__ */ M("div", { "data-sortable-custom-empty": "", "data-sortable-list-id": t.id, children: R(t, {
309
- itemCount: W.get(t.id) ?? 0,
310
- dragLocked: X,
329
+ return r ? J(
330
+ /* @__PURE__ */ G("div", { "data-sortable-custom-empty": "", "data-sortable-list-id": t.id, children: x(t, {
331
+ itemCount: ot.get(t.id) ?? 0,
332
+ dragLocked: at,
311
333
  filterQuery: n ?? ""
312
334
  }) }),
313
335
  r,
314
336
  `empty-${t.id}`
315
337
  ) : null;
316
- }) : null, Y = { ref: u, ...ot };
317
- return c && (Y["custom-item-rendering"] = ""), /* @__PURE__ */ ft(bt, { children: [
318
- mt("ui-sortable", Y, it),
319
- x >= 0 ? nt : null,
320
- x >= 0 ? ut : null,
321
- x >= 0 ? lt : null
338
+ }) : null, nt = { ref: u, ...bt };
339
+ return c && (nt["custom-item-rendering"] = ""), /* @__PURE__ */ vt(St, { children: [
340
+ wt("ui-sortable", nt, ft),
341
+ R >= 0 ? mt : null,
342
+ R >= 0 ? pt : null,
343
+ R >= 0 ? ht : null
322
344
  ] });
323
345
  });
324
- wt.displayName = "Sortable";
346
+ Ct.displayName = "Sortable";
325
347
  export {
326
- wt as Sortable,
327
- wt as default
348
+ Ct as Sortable,
349
+ Ct as default
328
350
  };
package/index.d.ts CHANGED
@@ -14,5 +14,14 @@ export type {
14
14
  UISortableDropIndicatorVisibility,
15
15
  UISortableDropzoneStyle,
16
16
  UISortableDragHandleMode,
17
- UISortableListOrientation
17
+ UISortableListOrientation,
18
+ UISortableLabels,
19
+ UISortableNestTrigger,
20
+ UISortableDropInfo,
21
+ UISortableBeforeChangeDetail,
22
+ UISortableRenderItemContext,
23
+ UISortableRenderListHeaderContext,
24
+ UISortableRenderEmptyStateContext,
25
+ UISortableRenderResult,
26
+ UISortableExternalMove
18
27
  } from '@editora/ui-core/sortable';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@editora/ui-sortable",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Standalone install for the Editora sortable web component, with reordering, transfer, hierarchy, cloning, and keyboard-accessible drag and drop.",
5
5
  "homepage": "https://editora-ecosystem.netlify.app/docs/ui-react/interactive/sortable",
6
6
  "bugs": {
@@ -42,7 +42,7 @@
42
42
  "prepare": "npm run build"
43
43
  },
44
44
  "dependencies": {
45
- "@editora/ui-core": "^0.1.23"
45
+ "@editora/ui-core": "^0.2.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": ">=16.8 <21",
package/react.d.ts CHANGED
@@ -15,7 +15,12 @@ import type {
15
15
  UISortableDropIndicatorVisibility,
16
16
  UISortableDropzoneStyle,
17
17
  UISortableDragHandleMode,
18
- UISortableListOrientation
18
+ UISortableListOrientation,
19
+ UISortableLabels,
20
+ UISortableNestTrigger,
21
+ UISortableDropInfo,
22
+ UISortableBeforeChangeDetail,
23
+ UISortableExternalMove
19
24
  } from '@editora/ui-core/sortable';
20
25
 
21
26
  export type SortableListOrientation = UISortableListOrientation;
@@ -27,6 +32,8 @@ export type SortableDropIndicatorVisibility = UISortableDropIndicatorVisibility;
27
32
  export type SortableDropzoneStyle = UISortableDropzoneStyle;
28
33
  export type SortableDragPreviewSize = 'match-item' | 'compact';
29
34
  export type SortableDragHandleMode = UISortableDragHandleMode;
35
+ export type SortableLabels = Partial<UISortableLabels>;
36
+ export type SortableNestTrigger = UISortableNestTrigger;
30
37
  export type SortableRadiusPreset = 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
31
38
  export type SortableRadius = SortableRadiusPreset | number | string;
32
39
  export type SortableSpacePreset = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
@@ -38,6 +45,9 @@ export type SortableSelectionChangeDetail = UISortableSelectionChangeDetail;
38
45
  export type SortablePersistenceRecord = UISortablePersistenceRecord;
39
46
  export type SortablePersistenceSnapshot = UISortablePersistenceSnapshot;
40
47
  export type SortableChangeDetail = UISortableChangeDetail;
48
+ export type SortableBeforeChangeDetail = UISortableBeforeChangeDetail;
49
+ export type SortableDropInfo = UISortableDropInfo;
50
+ export type SortableExternalMove = UISortableExternalMove;
41
51
  export type SortableMoveOptions = UISortableMoveOptions;
42
52
  export type SortableElement = UISortable;
43
53
 
@@ -69,6 +79,13 @@ export type SortableProps = Omit<React.HTMLAttributes<SortableElement>, 'onChang
69
79
  persistKey?: string;
70
80
  allowFilteredDrag?: boolean;
71
81
  allowNesting?: boolean;
82
+ nestTrigger?: SortableNestTrigger;
83
+ /** Sortables with the same group can exchange items: drop a card on another one and both report it (`change`'s `external`). Ids must be unique across the group. */
84
+ group?: string;
85
+ /** Milliseconds a finger must rest on a card before it lifts (touch, dragging by the card). 0 lifts at once. Default 350. */
86
+ touchHoldDelay?: number;
87
+ /** The tallest the cards of a list can be before the list scrolls on its own: a number of px or a CSS length such as "20rem". A list's own `maxHeight` overrides it. */
88
+ listMaxHeight?: number | string;
72
89
  dropIndicatorVisibility?: SortableDropIndicatorVisibility;
73
90
  dropzoneStyle?: SortableDropzoneStyle;
74
91
  dragPreviewSize?: SortableDragPreviewSize;
@@ -78,11 +95,20 @@ export type SortableProps = Omit<React.HTMLAttributes<SortableElement>, 'onChang
78
95
  handleRadius?: SortableRadius;
79
96
  listGap?: SortableSpace;
80
97
  itemSpacing?: SortableSpace;
98
+ /** Decides whether items may go somewhere; return false to refuse. Asked on every pointer move, so keep it quick. */
99
+ canDrop?: (info: SortableDropInfo) => boolean;
81
100
  showSelectionBadge?: boolean;
101
+ labels?: SortableLabels;
102
+ hideToolbar?: boolean;
82
103
  disabled?: boolean;
83
104
  renderItem?: (item: SortableItem, context: SortableRenderItemContext) => React.ReactNode;
84
105
  renderListHeader?: (list: SortableList, context: SortableRenderListHeaderContext) => React.ReactNode;
85
106
  renderEmptyState?: (list: SortableList, context: SortableRenderEmptyStateContext) => React.ReactNode;
107
+ /**
108
+ * Called just before a move is applied, with the result it would have. Return `false` (or call
109
+ * `event.preventDefault()`) to cancel it: nothing changes and `onChange` does not fire.
110
+ */
111
+ onBeforeChange?: (detail: SortableBeforeChangeDetail, event: Event) => boolean | void;
86
112
  onChange?: (detail: SortableChangeDetail) => void;
87
113
  onItemsChange?: (items: SortableItem[]) => void;
88
114
  onSelectionChange?: (detail: SortableSelectionChangeDetail) => void;