@editora/ui-sortable 0.1.5 → 0.1.7
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 +200 -195
- package/dist/react.cjs.js +1 -1
- package/dist/react.esm.js +71 -71
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,77 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
<h1 align="center">@editora/ui-sortable</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
Drag-and-drop lists and boards as one web component, <code><ui-sortable></code>: reorder within a list, move
|
|
5
|
+
between lists, nest, clone and select several items, with full keyboard support. A small React wrapper is included.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/@editora/ui-sortable"><img src="https://img.shields.io/npm/v/@editora/ui-sortable.svg" alt="npm version"></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/@editora/ui-sortable"><img src="https://img.shields.io/npm/dm/@editora/ui-sortable.svg" alt="npm downloads"></a>
|
|
11
|
+
<a href="https://github.com/ajaykr089/Editora/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@editora/ui-sortable.svg" alt="license"></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@editora/ui-sortable"><img src="https://img.shields.io/npm/types/@editora/ui-sortable.svg" alt="TypeScript types included"></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://editora-ecosystem.netlify.app/docs/ui-react/interactive/sortable">Docs and examples</a> ·
|
|
17
|
+
<a href="https://editora-ecosystem-storybook.netlify.app/">Storybook</a> ·
|
|
18
|
+
<a href="https://github.com/ajaykr089/Editora">GitHub</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/ui-sortable/docs/images/board.png" alt="A board with four lists: Templates, Backlog with a nested item, In Progress and Done, each holding draggable cards with a drag handle" width="900">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- **One component, many layouts.** A single list, several lists side by side (a board), horizontal lists, nested
|
|
28
|
+
hierarchies.
|
|
29
|
+
- **Reorder, transfer, nest and clone.** Drop an item between others, into another list, inside another item, or drag
|
|
30
|
+
a copy out of a template list.
|
|
31
|
+
- **Multi-selection**: select several items and move them together.
|
|
32
|
+
- **Keyboard and screen readers.** Space lifts the focused item, the arrow keys choose the place, Space drops it, and
|
|
33
|
+
the move is announced.
|
|
34
|
+
- **Persistence built in**: a `persist-request` event with the new positions, and a `persistKey` that keeps the positions across reloads.
|
|
35
|
+
- **Small.** The component is 17 KB gzipped (19 KB with the React wrapper), against about 490 KB for the whole
|
|
36
|
+
[`@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.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
23
40
|
|
|
24
41
|
```bash
|
|
25
42
|
npm install @editora/ui-sortable
|
|
26
43
|
```
|
|
27
44
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npm install react react-dom
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Or install the standalone React-ready setup in one step:
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
npm install @editora/ui-sortable react react-dom
|
|
38
|
-
```
|
|
45
|
+
For the React wrapper, React is a peer dependency: `npm install @editora/ui-sortable react react-dom`.
|
|
39
46
|
|
|
40
|
-
## Quick
|
|
47
|
+
## Quick start
|
|
41
48
|
|
|
42
|
-
Import the package once to register the
|
|
49
|
+
Import the package once to register the element, then give it `lists` and `items`:
|
|
43
50
|
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
```html
|
|
52
|
+
<script type="importmap">
|
|
53
|
+
{
|
|
54
|
+
"imports": {
|
|
55
|
+
"@editora/ui-sortable": "https://cdn.jsdelivr.net/npm/@editora/ui-sortable/dist/index.esm.js",
|
|
56
|
+
"@editora/ui-core/sortable": "https://cdn.jsdelivr.net/npm/@editora/ui-core/dist/sortable.esm.js"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
</script>
|
|
60
|
+
<ui-sortable></ui-sortable>
|
|
47
61
|
|
|
48
|
-
|
|
62
|
+
<script type="module">
|
|
63
|
+
import '@editora/ui-sortable';
|
|
49
64
|
|
|
50
|
-
|
|
51
|
-
import '@editora/ui-sortable';
|
|
65
|
+
const sortable = document.querySelector('ui-sortable');
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
sortable.lists = [
|
|
68
|
+
{ id: 'backlog', label: 'Backlog' },
|
|
69
|
+
{ id: 'in-progress', label: 'In Progress' },
|
|
70
|
+
{ id: 'done', label: 'Done' }
|
|
71
|
+
];
|
|
54
72
|
|
|
55
|
-
sortable.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
];
|
|
73
|
+
sortable.items = [
|
|
74
|
+
{ id: 'story-1', label: 'Audit onboarding', listId: 'backlog' },
|
|
75
|
+
{ id: 'story-2', label: 'Ship release notes', listId: 'in-progress' },
|
|
76
|
+
{ id: 'story-3', label: 'Review handoff', listId: 'done' }
|
|
77
|
+
];
|
|
60
78
|
|
|
61
|
-
sortable.
|
|
62
|
-
|
|
63
|
-
{ id: 'story-2', label: 'Ship release notes', listId: 'in-progress' },
|
|
64
|
-
{ id: 'story-3', label: 'Review handoff', listId: 'done' }
|
|
65
|
-
];
|
|
79
|
+
sortable.addEventListener('change', (event) => console.log('order', event.detail.items));
|
|
80
|
+
</script>
|
|
66
81
|
```
|
|
67
82
|
|
|
68
|
-
|
|
69
|
-
<ui-sortable
|
|
70
|
-
|
|
83
|
+
<p align="center">
|
|
84
|
+
<img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/ui-sortable/docs/images/quick-start.png" alt="Three lists, Backlog, In Progress and Done, each with one card" width="900">
|
|
85
|
+
</p>
|
|
71
86
|
|
|
72
|
-
|
|
87
|
+
The element does not move your data: it fires `change` with the new `items`, and you store them. With a bundler, drop the
|
|
88
|
+
import map and `import '@editora/ui-sortable'`; without one, the import map above is all it needs.
|
|
73
89
|
|
|
74
|
-
|
|
90
|
+
## React
|
|
75
91
|
|
|
76
92
|
```tsx
|
|
77
93
|
import { Sortable, type SortableItem, type SortableList } from '@editora/ui-sortable/react';
|
|
@@ -86,7 +102,7 @@ const items: SortableItem[] = [
|
|
|
86
102
|
{ id: 'story-2', label: 'Ship release notes', listId: 'done' }
|
|
87
103
|
];
|
|
88
104
|
|
|
89
|
-
export function Example() {
|
|
105
|
+
export default function Example() {
|
|
90
106
|
return (
|
|
91
107
|
<Sortable
|
|
92
108
|
lists={lists}
|
|
@@ -100,19 +116,12 @@ export function Example() {
|
|
|
100
116
|
}
|
|
101
117
|
```
|
|
102
118
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
If you are using Next.js, App Router, or another SSR/RSC framework, import `@editora/ui-sortable/react` from a client component because it registers the custom element in the browser runtime.
|
|
106
|
-
|
|
107
|
-
```tsx
|
|
108
|
-
'use client';
|
|
109
|
-
|
|
110
|
-
import { Sortable } from '@editora/ui-sortable/react';
|
|
111
|
-
```
|
|
119
|
+
`@editora/ui-sortable/react` is the wrapper on its own, without the rest of `@editora/ui-react`.
|
|
112
120
|
|
|
113
|
-
|
|
121
|
+
### A controlled board
|
|
114
122
|
|
|
115
|
-
|
|
123
|
+
Keep the items, and the selection, in state. This board has a template list that clones what you drag out of it, a
|
|
124
|
+
horizontal list, a nested item and a `persistKey` that remembers the positions:
|
|
116
125
|
|
|
117
126
|
```tsx
|
|
118
127
|
import * as React from 'react';
|
|
@@ -132,7 +141,7 @@ const initialItems: SortableItem[] = [
|
|
|
132
141
|
{ id: 'review', label: 'Design review', listId: 'active' }
|
|
133
142
|
];
|
|
134
143
|
|
|
135
|
-
export function ReleaseBoard() {
|
|
144
|
+
export default function ReleaseBoard() {
|
|
136
145
|
const [items, setItems] = React.useState(initialItems);
|
|
137
146
|
const [selection, setSelection] = React.useState<string[]>(['epic']);
|
|
138
147
|
|
|
@@ -152,7 +161,13 @@ export function ReleaseBoard() {
|
|
|
152
161
|
}
|
|
153
162
|
```
|
|
154
163
|
|
|
155
|
-
|
|
164
|
+
<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">
|
|
166
|
+
</p>
|
|
167
|
+
|
|
168
|
+
### A flat list
|
|
169
|
+
|
|
170
|
+
For a single list that only reorders, turn nesting off:
|
|
156
171
|
|
|
157
172
|
```tsx
|
|
158
173
|
import * as React from 'react';
|
|
@@ -168,7 +183,7 @@ const initialItems: SortableItem[] = [
|
|
|
168
183
|
{ id: 'seo', label: 'SEO metadata', listId: 'queue' }
|
|
169
184
|
];
|
|
170
185
|
|
|
171
|
-
export function FlatSortableQueue() {
|
|
186
|
+
export default function FlatSortableQueue() {
|
|
172
187
|
const [items, setItems] = React.useState(initialItems);
|
|
173
188
|
|
|
174
189
|
return (
|
|
@@ -182,153 +197,143 @@ export function FlatSortableQueue() {
|
|
|
182
197
|
}
|
|
183
198
|
```
|
|
184
199
|
|
|
185
|
-
###
|
|
186
|
-
|
|
187
|
-
```tsx
|
|
188
|
-
import { Sortable, type SortableItem, type SortableList } from '@editora/ui-sortable/react';
|
|
189
|
-
|
|
190
|
-
const lists: SortableList[] = [
|
|
191
|
-
{ id: 'library', label: 'Template Library', cloneOnDrag: true },
|
|
192
|
-
{ id: 'campaign', label: 'Campaign Plan' }
|
|
193
|
-
];
|
|
194
|
-
|
|
195
|
-
const items: SortableItem[] = [
|
|
196
|
-
{ id: 'press-kit', label: 'Press kit template', listId: 'library', cloneOnDrag: true },
|
|
197
|
-
{ id: 'email-series', label: 'Lifecycle email series', listId: 'library', cloneOnDrag: true },
|
|
198
|
-
{ id: 'owner-sync', label: 'Owner sync', listId: 'campaign' }
|
|
199
|
-
];
|
|
200
|
-
|
|
201
|
-
export function CloneLibraryExample() {
|
|
202
|
-
return <Sortable lists={lists} items={items} />;
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### Container Dropzones
|
|
207
|
-
|
|
208
|
-
```tsx
|
|
209
|
-
<Sortable
|
|
210
|
-
lists={lists}
|
|
211
|
-
items={items}
|
|
212
|
-
dropzoneStyle="container"
|
|
213
|
-
/>
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
### Custom Item Rendering
|
|
217
|
-
|
|
218
|
-
```tsx
|
|
219
|
-
<Sortable
|
|
220
|
-
lists={lists}
|
|
221
|
-
items={items}
|
|
222
|
-
selection={selection}
|
|
223
|
-
onItemsChange={setItems}
|
|
224
|
-
renderItem={(item, context) => (
|
|
225
|
-
<div style={{ display: 'grid', gap: 8 }}>
|
|
226
|
-
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 12 }}>
|
|
227
|
-
<strong>{item.label}</strong>
|
|
228
|
-
<span>{context.selected ? 'Selected' : 'Ready'}</span>
|
|
229
|
-
</div>
|
|
230
|
-
{item.description && <div>{item.description}</div>}
|
|
231
|
-
<small>{context.list?.label}</small>
|
|
232
|
-
</div>
|
|
233
|
-
)}
|
|
234
|
-
/>
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
### Custom List Headers And Empty States
|
|
200
|
+
### Your own markup
|
|
238
201
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
lists={lists}
|
|
242
|
-
items={items}
|
|
243
|
-
renderListHeader={(list, context) => (
|
|
244
|
-
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 12 }}>
|
|
245
|
-
<strong>{list.label}</strong>
|
|
246
|
-
<span>{context.itemCount} items</span>
|
|
247
|
-
</div>
|
|
248
|
-
)}
|
|
249
|
-
renderEmptyState={(list) => (
|
|
250
|
-
<div>
|
|
251
|
-
No items in {list.label} yet. Drag something here to get started.
|
|
252
|
-
</div>
|
|
253
|
-
)}
|
|
254
|
-
/>
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### Nested Hierarchy
|
|
202
|
+
`renderItem`, `renderListHeader` and `renderEmptyState` replace the default item, list header and empty message. The
|
|
203
|
+
context says whether the item is selected, how many items a list holds, and so on:
|
|
258
204
|
|
|
259
205
|
```tsx
|
|
206
|
+
import * as React from 'react';
|
|
260
207
|
import { Sortable, type SortableItem, type SortableList } from '@editora/ui-sortable/react';
|
|
261
208
|
|
|
262
209
|
const lists: SortableList[] = [
|
|
263
|
-
{ id: '
|
|
210
|
+
{ id: 'todo', label: 'To do' },
|
|
211
|
+
{ id: 'done', label: 'Done' }
|
|
264
212
|
];
|
|
265
213
|
|
|
266
|
-
const
|
|
267
|
-
{ id: '
|
|
268
|
-
{ id: '
|
|
269
|
-
{ id: 'experiment', label: 'Paywall experiment', listId: 'roadmap' }
|
|
214
|
+
const initialItems: SortableItem[] = [
|
|
215
|
+
{ id: 'brief', label: 'Write the brief', description: 'One page, with the audience.', listId: 'todo' },
|
|
216
|
+
{ id: 'review', label: 'Legal review', listId: 'todo' }
|
|
270
217
|
];
|
|
271
218
|
|
|
272
|
-
export function
|
|
273
|
-
|
|
219
|
+
export default function CustomRendering() {
|
|
220
|
+
const [items, setItems] = React.useState(initialItems);
|
|
221
|
+
const [selection, setSelection] = React.useState<string[]>(['brief']);
|
|
222
|
+
|
|
223
|
+
return (
|
|
224
|
+
<Sortable
|
|
225
|
+
lists={lists}
|
|
226
|
+
items={items}
|
|
227
|
+
selection={selection}
|
|
228
|
+
onItemsChange={setItems}
|
|
229
|
+
onSelectionChange={(detail) => setSelection(detail.selection)}
|
|
230
|
+
renderItem={(item, context) => (
|
|
231
|
+
<div style={{ display: 'grid', gap: 8 }}>
|
|
232
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 12 }}>
|
|
233
|
+
<strong>{item.label}</strong>
|
|
234
|
+
<span>{context.selected ? 'Selected' : 'Ready'}</span>
|
|
235
|
+
</div>
|
|
236
|
+
{item.description && <div>{item.description}</div>}
|
|
237
|
+
<small>{context.list?.label}</small>
|
|
238
|
+
</div>
|
|
239
|
+
)}
|
|
240
|
+
renderListHeader={(list, context) => (
|
|
241
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 12 }}>
|
|
242
|
+
<strong>{list.label}</strong>
|
|
243
|
+
<span>{context.itemCount} items</span>
|
|
244
|
+
</div>
|
|
245
|
+
)}
|
|
246
|
+
renderEmptyState={(list) => (
|
|
247
|
+
<div>
|
|
248
|
+
No items in {list.label} yet. Drag something here to get started.
|
|
249
|
+
</div>
|
|
250
|
+
)}
|
|
251
|
+
/>
|
|
252
|
+
);
|
|
274
253
|
}
|
|
275
254
|
```
|
|
276
255
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
256
|
+
<p align="center">
|
|
257
|
+
<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
|
+
</p>
|
|
259
|
+
|
|
260
|
+
## Items and lists
|
|
261
|
+
|
|
262
|
+
| Item field | |
|
|
263
|
+
| --- | --- |
|
|
264
|
+
| `id`, `label`, `listId` | Required: the item's id, its text and the list it is in. |
|
|
265
|
+
| `parentId` | The id of the item this one is nested under. |
|
|
266
|
+
| `description` | A second line of text. |
|
|
267
|
+
| `cloneOnDrag` | Dragging this item leaves it where it is and drops a copy. |
|
|
268
|
+
| `disabled`, `dragDisabled`, `hidden` | Disable the item, stop it being dragged, or hide it. |
|
|
269
|
+
|
|
270
|
+
| List field | |
|
|
271
|
+
| --- | --- |
|
|
272
|
+
| `id`, `label` | Required. |
|
|
273
|
+
| `description`, `emptyLabel` | A line under the title, and the text of the empty state. |
|
|
274
|
+
| `orientation` | `'vertical'` (the default) or `'horizontal'`. |
|
|
275
|
+
| `cloneOnDrag` | Items dragged out of this list are copied. |
|
|
276
|
+
| `disabled` | Turn the list off. |
|
|
277
|
+
|
|
278
|
+
## Options
|
|
279
|
+
|
|
280
|
+
| React prop | Attribute | |
|
|
281
|
+
| --- | --- | --- |
|
|
282
|
+
| `lists`, `items` | `lists`, `items` | The data. In HTML, set them as properties or as JSON attributes. |
|
|
283
|
+
| `selection` | `selection` | The selected item ids. |
|
|
284
|
+
| `allowNesting` | `allow-nesting` | Allow dropping an item inside another. |
|
|
285
|
+
| `dropzoneStyle` | `dropzone-style` | `indicator` (an insertion rail, the default) or `container` (the whole list highlights). |
|
|
286
|
+
| `dropIndicatorVisibility` | `drop-indicator-visibility` | `active` or `always`. |
|
|
287
|
+
| `dragPreviewSize` | `drag-preview-size` | `match-item` or `compact`. |
|
|
288
|
+
| `dragHandleMode` | `drag-handle-mode` | `handle` (drag by the grip) or `item` (drag anywhere on the card). |
|
|
289
|
+
| `dragHandleSelector` | `drag-handle-selector` | A selector for your own drag handle. |
|
|
290
|
+
| `persistKey` | `persist-key` | Keep where each item is in `localStorage` under this key, and restore it on load. |
|
|
291
|
+
| `filterQuery`, `sort`, `allowFilteredDrag` | `filter-query`, `sort`, `allow-filtered-drag` | Filter the items, sort them (`manual` or `label`), and allow dragging while filtered. |
|
|
292
|
+
| `showSelectionBadge` | `show-selection-badge` | Show the *Selected* badge on selected items. |
|
|
293
|
+
| `disabled` | `disabled` | Turn the whole component off. |
|
|
294
|
+
|
|
295
|
+
The React wrapper also takes `itemRadius`, `handleRadius`, `listGap` and `itemSpacing` for the look.
|
|
280
296
|
|
|
281
|
-
##
|
|
282
|
-
|
|
283
|
-
Use the default insertion rails:
|
|
297
|
+
## Events
|
|
284
298
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
299
|
+
| Event | React prop | `detail` |
|
|
300
|
+
| --- | --- | --- |
|
|
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`. |
|
|
302
|
+
| | `onItemsChange` | The new `items` array. |
|
|
303
|
+
| `selection-change` | `onSelectionChange` | `{ selection, previousSelection }` |
|
|
304
|
+
| `persist-request` | `onPersistRequest` | The same detail as `change`: `persistence.records` is `[{ id, listId, parentId, index }]`, ready to save. |
|
|
288
305
|
|
|
289
|
-
|
|
306
|
+
## Methods
|
|
290
307
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
```
|
|
308
|
+
On the element (or a ref to it): `select(ids)`, `clearSelection()`, `moveSelection({ targetListId, beforeId?, parentId?, mode?, clone? })`,
|
|
309
|
+
`focusItem(id)`, `cancelDrag()` and `getPersistenceSnapshot()`.
|
|
294
310
|
|
|
295
|
-
##
|
|
311
|
+
## Keyboard
|
|
296
312
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
- `drag-handle-mode="handle|item"`
|
|
301
|
-
- `allow-nesting`
|
|
302
|
-
- `persist-key`
|
|
313
|
+
Focus an item, then press **Space** to lift it, the **arrow keys** to choose where it goes, and **Space** again to drop
|
|
314
|
+
it. The result is announced to screen readers ("Item reordered in Editorial Queue."), and a hint above the lists
|
|
315
|
+
explains the keys.
|
|
303
316
|
|
|
304
|
-
##
|
|
317
|
+
## Types
|
|
305
318
|
|
|
306
|
-
|
|
307
|
-
- `
|
|
308
|
-
|
|
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`.
|
|
309
322
|
|
|
310
|
-
|
|
323
|
+
## Server rendering
|
|
311
324
|
|
|
312
|
-
|
|
325
|
+
Both entries can be imported on the server: loading them does not touch the DOM, and the custom element is defined only
|
|
326
|
+
in the browser. On the server `Sortable` from `@editora/ui-sortable/react` renders an empty `<ui-sortable>` tag; the lists
|
|
327
|
+
and items are applied in the browser, once the element is defined and the component has mounted. A `'use client'` file
|
|
328
|
+
that renders it is still rendered on the server first (Next.js does this); that render produces the empty tag and does
|
|
329
|
+
not fail.
|
|
313
330
|
|
|
314
|
-
|
|
315
|
-
- `UISortable`
|
|
316
|
-
- `UISortableList`
|
|
317
|
-
- `UISortableItem`
|
|
318
|
-
- `UISortableChangeDetail`
|
|
319
|
-
- `UISortableDropzoneStyle`
|
|
331
|
+
## Part of Editora
|
|
320
332
|
|
|
321
|
-
|
|
322
|
-
-
|
|
323
|
-
|
|
324
|
-
- `SortableItem`
|
|
325
|
-
- `SortableChangeDetail`
|
|
326
|
-
- `SortableDropzoneStyle`
|
|
333
|
+
This is the sortable of [`@editora/ui-core`](https://www.npmjs.com/package/@editora/ui-core) as its own install. The same
|
|
334
|
+
component is also in [`@editora/ui-react`](https://www.npmjs.com/package/@editora/ui-react) and in the web components
|
|
335
|
+
catalog.
|
|
327
336
|
|
|
328
|
-
##
|
|
337
|
+
## License
|
|
329
338
|
|
|
330
|
-
|
|
331
|
-
cd packages/ui-sortable
|
|
332
|
-
npm run build
|
|
333
|
-
npm run test
|
|
334
|
-
```
|
|
339
|
+
MIT © [Ajay Kumar](https://github.com/ajaykr089)
|
package/dist/react.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
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;
|
package/dist/react.esm.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { jsx as M, jsxs as ft, Fragment as
|
|
2
|
-
import
|
|
1
|
+
import { jsx as M, jsxs as ft, Fragment as bt } from "react/jsx-runtime";
|
|
2
|
+
import b from "react";
|
|
3
3
|
import { createPortal as B } from "react-dom";
|
|
4
4
|
import "@editora/ui-core/sortable";
|
|
5
|
-
const q = typeof window < "u" ?
|
|
6
|
-
function
|
|
5
|
+
const q = typeof window < "u" ? b.useLayoutEffect : b.useEffect;
|
|
6
|
+
function mt(e, s, ...i) {
|
|
7
7
|
if (!s || !("className" in s) || !e.includes("-"))
|
|
8
|
-
return
|
|
9
|
-
const { className:
|
|
10
|
-
return
|
|
8
|
+
return b.createElement(e, s, ...i);
|
|
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);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const s =
|
|
14
|
-
return
|
|
12
|
+
function gt(e) {
|
|
13
|
+
const s = b.useRef(null);
|
|
14
|
+
return b.useImperativeHandle(e, () => s.current), s;
|
|
15
15
|
}
|
|
16
16
|
function pt(e, s, i) {
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
const
|
|
17
|
+
b.useEffect(() => {
|
|
18
|
+
const l = e.current;
|
|
19
|
+
if (!l) return;
|
|
20
|
+
const m = s.filter(
|
|
21
21
|
(o) => typeof o.listener == "function"
|
|
22
22
|
);
|
|
23
|
-
return
|
|
24
|
-
|
|
23
|
+
return m.forEach(({ type: o, listener: n }) => {
|
|
24
|
+
l.addEventListener(o, n);
|
|
25
25
|
}), () => {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
m.forEach(({ type: o, listener: n }) => {
|
|
27
|
+
l.removeEventListener(o, n);
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
}, [e, ...i]);
|
|
31
31
|
}
|
|
32
32
|
function yt(e, s, i) {
|
|
33
33
|
q(() => {
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const l = e.current;
|
|
35
|
+
l && s(l);
|
|
36
36
|
}, [e, ...i]);
|
|
37
37
|
}
|
|
38
38
|
function F(e) {
|
|
39
39
|
return e.detail;
|
|
40
40
|
}
|
|
41
41
|
function y(e, s, i) {
|
|
42
|
-
const
|
|
42
|
+
const l = e.getAttribute(s);
|
|
43
43
|
if (i == null || i === "") {
|
|
44
|
-
|
|
44
|
+
l != null && e.removeAttribute(s);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
l !== i && e.setAttribute(s, i);
|
|
48
48
|
}
|
|
49
49
|
function rt(e, s, i) {
|
|
50
50
|
if (i) {
|
|
@@ -105,15 +105,15 @@ function ht(e) {
|
|
|
105
105
|
return e;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
const At = [], vt = [], wt =
|
|
108
|
+
const At = [], vt = [], wt = b.forwardRef(function(s, i) {
|
|
109
109
|
const {
|
|
110
|
-
lists:
|
|
111
|
-
items:
|
|
110
|
+
lists: l,
|
|
111
|
+
items: m,
|
|
112
112
|
selection: o,
|
|
113
113
|
filterQuery: n,
|
|
114
|
-
sort:
|
|
114
|
+
sort: g,
|
|
115
115
|
persistKey: C,
|
|
116
|
-
allowFilteredDrag:
|
|
116
|
+
allowFilteredDrag: E,
|
|
117
117
|
allowNesting: L,
|
|
118
118
|
dropIndicatorVisibility: D,
|
|
119
119
|
dropzoneStyle: Q,
|
|
@@ -135,9 +135,9 @@ const At = [], vt = [], wt = m.forwardRef(function(s, i) {
|
|
|
135
135
|
onPersistRequest: H,
|
|
136
136
|
children: it,
|
|
137
137
|
...ot
|
|
138
|
-
} = s, f =
|
|
138
|
+
} = s, f = l ?? At, p = m ?? vt, u = gt(i), [x, at] = b.useState(0), K = !!(c || S || R);
|
|
139
139
|
pt(
|
|
140
|
-
|
|
140
|
+
u,
|
|
141
141
|
[
|
|
142
142
|
{
|
|
143
143
|
type: "change",
|
|
@@ -163,24 +163,24 @@ const At = [], vt = [], wt = m.forwardRef(function(s, i) {
|
|
|
163
163
|
],
|
|
164
164
|
[V, $, z, H]
|
|
165
165
|
), yt(
|
|
166
|
-
|
|
166
|
+
u,
|
|
167
167
|
(t) => {
|
|
168
|
-
T(t, "lists", f), T(t, "items", p), T(t, "selection", o ?? null), y(t, "filter-query", n ?? null), y(t, "sort",
|
|
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
169
|
const r = st(k);
|
|
170
170
|
r ? t.style.setProperty("--ui-sortable-item-radius", r) : t.style.removeProperty("--ui-sortable-item-radius");
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
171
|
+
const d = st(G);
|
|
172
|
+
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);
|
|
175
175
|
},
|
|
176
176
|
[
|
|
177
177
|
f,
|
|
178
178
|
p,
|
|
179
179
|
o,
|
|
180
180
|
n,
|
|
181
|
-
|
|
181
|
+
g,
|
|
182
182
|
C,
|
|
183
|
-
|
|
183
|
+
E,
|
|
184
184
|
L,
|
|
185
185
|
D,
|
|
186
186
|
Q,
|
|
@@ -197,42 +197,42 @@ const At = [], vt = [], wt = m.forwardRef(function(s, i) {
|
|
|
197
197
|
]
|
|
198
198
|
), q(() => {
|
|
199
199
|
if (!K) return;
|
|
200
|
-
const t =
|
|
200
|
+
const t = u.current, r = t?.ownerDocument?.defaultView;
|
|
201
201
|
if (!t || !r) return;
|
|
202
|
-
let
|
|
202
|
+
let d = !1, a = !1, P = null, I = null;
|
|
203
203
|
const Z = [
|
|
204
204
|
c && p.length > 0 ? ".item-custom-content[data-item-content-target]" : null,
|
|
205
205
|
S && f.length > 0 ? ".list-custom-header[data-list-header-target]" : null,
|
|
206
206
|
R && f.length > 0 ? ".list-custom-empty[data-list-empty-target]" : null
|
|
207
207
|
].filter(Boolean).join(", "), tt = () => {
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
d || a || (a = !0, queueMicrotask(() => {
|
|
209
|
+
a = !1, !d && at((v) => v + 1);
|
|
210
210
|
}));
|
|
211
211
|
}, dt = () => {
|
|
212
|
-
const v =
|
|
213
|
-
return v ? (
|
|
212
|
+
const v = u.current?.shadowRoot;
|
|
213
|
+
return v ? (I || (I = new MutationObserver(() => tt()), I.observe(v, { childList: !0, subtree: !0 })), !0) : !1;
|
|
214
214
|
}, et = () => {
|
|
215
|
-
if (
|
|
216
|
-
const v =
|
|
215
|
+
if (d) return;
|
|
216
|
+
const v = u.current?.shadowRoot, ct = !Z || !!v?.querySelector(Z);
|
|
217
217
|
if (dt() && ct) {
|
|
218
218
|
tt();
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
221
|
-
|
|
221
|
+
P = r.requestAnimationFrame(et);
|
|
222
222
|
};
|
|
223
223
|
return et(), () => {
|
|
224
|
-
|
|
224
|
+
d = !0, P !== null && r.cancelAnimationFrame(P), I?.disconnect();
|
|
225
225
|
};
|
|
226
226
|
}, [
|
|
227
|
-
|
|
227
|
+
u,
|
|
228
228
|
K,
|
|
229
229
|
p,
|
|
230
230
|
f,
|
|
231
231
|
o,
|
|
232
232
|
n,
|
|
233
|
-
|
|
233
|
+
g,
|
|
234
234
|
C,
|
|
235
|
-
|
|
235
|
+
E,
|
|
236
236
|
L,
|
|
237
237
|
D,
|
|
238
238
|
O,
|
|
@@ -244,27 +244,27 @@ const At = [], vt = [], wt = m.forwardRef(function(s, i) {
|
|
|
244
244
|
S,
|
|
245
245
|
R
|
|
246
246
|
]), q(() => {
|
|
247
|
-
const t =
|
|
247
|
+
const t = u.current, r = t?.shadowRoot;
|
|
248
248
|
if (!t) return;
|
|
249
249
|
if (!c || !r) {
|
|
250
250
|
t.removeAttribute("custom-item-rendering-ready"), t.removeAttribute("custom-item-rendering-pending");
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
}, [
|
|
256
|
-
const t =
|
|
253
|
+
const d = r.querySelectorAll(".item-custom-content[data-item-content-target]"), a = r.querySelectorAll("[data-sortable-custom-item]");
|
|
254
|
+
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(() => {
|
|
256
|
+
const t = u.current?.shadowRoot;
|
|
257
257
|
t && (t.querySelectorAll("[data-sortable-custom-handle]").forEach((r) => {
|
|
258
|
-
r.removeAttribute("data-sortable-custom-handle"), r.removeAttribute("data-drag-trigger"), r.removeAttribute("data-id"), r.removeAttribute("draggable");
|
|
258
|
+
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
259
|
}), !(!c || !h || w === "item") && t.querySelectorAll("[data-sortable-custom-item][data-sortable-item-id]").forEach((r) => {
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
260
|
+
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", ""));
|
|
263
263
|
});
|
|
264
264
|
}));
|
|
265
|
-
}, [
|
|
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 ||
|
|
267
|
-
const r =
|
|
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) => {
|
|
267
|
+
const r = u.current?.shadowRoot?.querySelector(
|
|
268
268
|
`.item-custom-content[data-item-content-target="${j(t.id)}"]`
|
|
269
269
|
);
|
|
270
270
|
return r ? B(
|
|
@@ -289,7 +289,7 @@ const At = [], vt = [], wt = m.forwardRef(function(s, i) {
|
|
|
289
289
|
t.id
|
|
290
290
|
) : null;
|
|
291
291
|
}) : null, ut = S ? f.map((t) => {
|
|
292
|
-
const r =
|
|
292
|
+
const r = u.current?.shadowRoot?.querySelector(
|
|
293
293
|
`.list-custom-header[data-list-header-target="${j(t.id)}"]`
|
|
294
294
|
);
|
|
295
295
|
return r ? B(
|
|
@@ -301,7 +301,7 @@ const At = [], vt = [], wt = m.forwardRef(function(s, i) {
|
|
|
301
301
|
`header-${t.id}`
|
|
302
302
|
) : null;
|
|
303
303
|
}) : null, lt = R ? f.map((t) => {
|
|
304
|
-
const r =
|
|
304
|
+
const r = u.current?.shadowRoot?.querySelector(
|
|
305
305
|
`.list-custom-empty[data-list-empty-target="${j(t.id)}"]`
|
|
306
306
|
);
|
|
307
307
|
return r ? B(
|
|
@@ -313,12 +313,12 @@ const At = [], vt = [], wt = m.forwardRef(function(s, i) {
|
|
|
313
313
|
r,
|
|
314
314
|
`empty-${t.id}`
|
|
315
315
|
) : null;
|
|
316
|
-
}) : null, Y = { ref:
|
|
317
|
-
return c && (Y["custom-item-rendering"] = ""), /* @__PURE__ */ ft(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
|
322
322
|
] });
|
|
323
323
|
});
|
|
324
324
|
wt.displayName = "Sortable";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editora/ui-sortable",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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.
|
|
45
|
+
"@editora/ui-core": "^0.1.23"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": ">=16.8 <21",
|