@molecule/app-drag-drop-dndkit-svelte 0.0.0-stage → 0.0.1-stage
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/LICENSE +202 -0
- package/README.md +175 -2
- package/dist/ProviderSetup.svelte +38 -0
- package/dist/ProviderSetup.svelte.d.ts +12 -0
- package/dist/ProviderSetup.svelte.d.ts.map +1 -0
- package/dist/SortableList.svelte +90 -0
- package/dist/SortableList.svelte.d.ts +36 -0
- package/dist/SortableList.svelte.d.ts.map +1 -0
- package/dist/components.d.ts +7 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +6 -0
- package/dist/context.d.ts +23 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +10 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/useSortableItem.svelte.d.ts +43 -0
- package/dist/useSortableItem.svelte.d.ts.map +1 -0
- package/dist/useSortableItem.svelte.js +44 -0
- package/package.json +74 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,176 @@
|
|
|
1
|
-
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-11-16T03:38:04.718Z
|
|
7
|
+
-->
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
# @molecule/app-drag-drop-dndkit-svelte
|
|
10
|
+
|
|
11
|
+
Svelte sortable list for `@molecule/app-drag-drop-dndkit`.
|
|
12
|
+
|
|
13
|
+
`SortableList` renders a list the user reorders with the pointer, touch or
|
|
14
|
+
the keyboard, on `@dnd-kit/svelte`. Each row calls `useSortableItem`. The
|
|
15
|
+
options are `@molecule/app-drag-drop-dndkit`'s `SortableListOptions`, the
|
|
16
|
+
same in the React, Vue, Solid, Svelte and Angular bindings, so a list swaps
|
|
17
|
+
between frameworks unchanged.
|
|
18
|
+
|
|
19
|
+
`useSortableItem` returns Svelte attachments for the row element (`ref`) and
|
|
20
|
+
an optional drag handle (`handleRef`), plus the row's `isDragging` and
|
|
21
|
+
`isDropTarget` state as read-only reactive getters. Apply an attachment with
|
|
22
|
+
Svelte's attachment tag on the element, or with `createAttachmentKey()` in a
|
|
23
|
+
spread, as the example below shows.
|
|
24
|
+
|
|
25
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
26
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
27
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```svelte
|
|
32
|
+
<!-- Row.svelte -->
|
|
33
|
+
<script lang="ts">
|
|
34
|
+
import { createAttachmentKey } from 'svelte/attachments'
|
|
35
|
+
|
|
36
|
+
import { useSortableItem } from '@molecule/app-drag-drop-dndkit-svelte'
|
|
37
|
+
|
|
38
|
+
let { task }: { task: Task } = $props()
|
|
39
|
+
|
|
40
|
+
const { ref, isDragging } = useSortableItem({ id: task.id })
|
|
41
|
+
const attach = { [createAttachmentKey()]: ref }
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<li {...attach} data-dragging={isDragging}>{task.title}</li>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```svelte
|
|
48
|
+
<!-- Tasks.svelte -->
|
|
49
|
+
<script lang="ts">
|
|
50
|
+
import { SortableList } from '@molecule/app-drag-drop-dndkit-svelte'
|
|
51
|
+
import Row from './Row.svelte'
|
|
52
|
+
|
|
53
|
+
let { tasks }: { tasks: Task[] } = $props()
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<SortableList
|
|
57
|
+
items={tasks}
|
|
58
|
+
onReorder={(next) => (tasks = next)}
|
|
59
|
+
getItemLabel={(task) => task.title}
|
|
60
|
+
>
|
|
61
|
+
<ul>
|
|
62
|
+
{#each tasks as task (task.id)}
|
|
63
|
+
<Row {task} />
|
|
64
|
+
{/each}
|
|
65
|
+
</ul>
|
|
66
|
+
</SortableList>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Type
|
|
70
|
+
|
|
71
|
+
`feature`
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm install @molecule/app-drag-drop-dndkit-svelte @dnd-kit/svelte @molecule/app-drag-drop @molecule/app-drag-drop-dndkit svelte
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API
|
|
80
|
+
|
|
81
|
+
### Interfaces
|
|
82
|
+
|
|
83
|
+
#### `SortableListProps`
|
|
84
|
+
|
|
85
|
+
Props for `SortableList`: the options every framework's list takes, plus the
|
|
86
|
+
list itself as `children`.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
interface SortableListProps<T extends { id: string }> extends SortableListOptions<T> {
|
|
90
|
+
/** The rendered list, whose rows call `useSortableItem`. */
|
|
91
|
+
children: Snippet
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### `SortableItemState`
|
|
96
|
+
|
|
97
|
+
What {@link useSortableItem} returns for one row.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface SortableItemState {
|
|
101
|
+
/**
|
|
102
|
+
* A Svelte attachment for the row's element: Svelte calls it with the
|
|
103
|
+
* element when the row mounts, and with the returned cleanup when it is
|
|
104
|
+
* removed. dnd-kit makes the element focusable and sets its `role`,
|
|
105
|
+
* `aria-roledescription`, `aria-describedby`, `aria-pressed` and
|
|
106
|
+
* `aria-disabled`.
|
|
107
|
+
*
|
|
108
|
+
* @param node - The row's element.
|
|
109
|
+
* @returns The detach function Svelte calls when the row is removed.
|
|
110
|
+
*/
|
|
111
|
+
ref: (node: HTMLElement) => () => void
|
|
112
|
+
/**
|
|
113
|
+
* A Svelte attachment for a drag handle inside the row (the library's
|
|
114
|
+
* `attachHandle`) so only the handle starts a drag; leave it unused to drag
|
|
115
|
+
* by the whole row.
|
|
116
|
+
*
|
|
117
|
+
* @param node - The handle's element.
|
|
118
|
+
* @returns The detach function Svelte calls when the handle is removed.
|
|
119
|
+
*/
|
|
120
|
+
handleRef: (node: HTMLElement) => () => void
|
|
121
|
+
/** `true` while this row is being dragged. */
|
|
122
|
+
readonly isDragging: boolean
|
|
123
|
+
/** `true` while another dragged row is over this one. */
|
|
124
|
+
readonly isDropTarget: boolean
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Functions
|
|
129
|
+
|
|
130
|
+
#### `useSortableItem(options)`
|
|
131
|
+
|
|
132
|
+
Makes one row of a `SortableList` draggable. Call it during the row
|
|
133
|
+
component's initialization, inside the list.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
function useSortableItem(options: SortableItemOptions): SortableItemState
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- `options` — The row's item id, drag data and disabled flag.
|
|
140
|
+
|
|
141
|
+
**Returns:** The attachments to apply to the row (and its handle) plus its drag state.
|
|
142
|
+
|
|
143
|
+
### Constants
|
|
144
|
+
|
|
145
|
+
#### `SortableList`
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const SortableList: LegacyComponentType
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Injection Notes
|
|
152
|
+
|
|
153
|
+
### Requirements
|
|
154
|
+
|
|
155
|
+
Peer dependencies:
|
|
156
|
+
|
|
157
|
+
- `@molecule/app-drag-drop` ^1.0.1
|
|
158
|
+
- `@molecule/app-drag-drop-dndkit` ^2.0.0
|
|
159
|
+
- `svelte` ^5.29.0
|
|
160
|
+
|
|
161
|
+
### Runtime Dependencies
|
|
162
|
+
|
|
163
|
+
- `@dnd-kit/svelte`
|
|
164
|
+
- `@molecule/app-drag-drop`
|
|
165
|
+
- `@molecule/app-drag-drop-dndkit`
|
|
166
|
+
- `svelte`
|
|
167
|
+
|
|
168
|
+
The screen-reader instructions and announcements use the
|
|
169
|
+
`dragDrop.sortable.*` keys; bond `@molecule/app-locales-drag-drop-dndkit` for
|
|
170
|
+
their translations. Persist the order in `onReorder`; if saving fails,
|
|
171
|
+
restore the previous `items`. Set an item's `disabled` option to pin one row,
|
|
172
|
+
or the list's `disabled` prop to pin the whole list.
|
|
173
|
+
|
|
174
|
+
## Translations
|
|
175
|
+
|
|
176
|
+
Translation strings are provided by `@molecule/app-locales-drag-drop-dndkit`.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Gives the list's manager the list's own plugins, sensors and modifiers.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { getDragDropManager } from '@dnd-kit/svelte'
|
|
9
|
+
|
|
10
|
+
import type { SortableListModifiers, SortableListSensors } from '@molecule/app-drag-drop-dndkit'
|
|
11
|
+
|
|
12
|
+
/** The list's configured sensors and axis modifiers. */
|
|
13
|
+
interface Props {
|
|
14
|
+
/** The list's configured sensors. */
|
|
15
|
+
sensors: SortableListSensors
|
|
16
|
+
/** The list's axis modifiers. */
|
|
17
|
+
modifiers: SortableListModifiers
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let { sensors, modifiers }: Props = $props()
|
|
21
|
+
|
|
22
|
+
const manager = getDragDropManager()
|
|
23
|
+
|
|
24
|
+
// `DragDropProvider` builds its manager with dnd-kit's default plugins, sensors and modifiers and
|
|
25
|
+
// only applies those props afterwards, and dnd-kit keeps an already-registered instance, updating
|
|
26
|
+
// the options that instance read when it was constructed. Emptying the registries here — in a
|
|
27
|
+
// child whose effect runs before the rows' — removes those defaults, so the provider's own
|
|
28
|
+
// assignment builds each from the list's options. The sensors are registered here too: a sensor
|
|
29
|
+
// attaches its listeners when it registers, so it has to be in place before the rows are.
|
|
30
|
+
$effect(() => {
|
|
31
|
+
manager.plugins = []
|
|
32
|
+
manager.sensors = []
|
|
33
|
+
manager.modifiers = []
|
|
34
|
+
// The shared helpers are typed as a list or a function of dnd-kit's defaults; both return a list.
|
|
35
|
+
if (Array.isArray(sensors)) manager.sensors = sensors
|
|
36
|
+
if (Array.isArray(modifiers)) manager.modifiers = modifiers
|
|
37
|
+
})
|
|
38
|
+
</script>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SortableListModifiers, SortableListSensors } from '@molecule/app-drag-drop-dndkit';
|
|
2
|
+
/** The list's configured sensors and axis modifiers. */
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The list's configured sensors. */
|
|
5
|
+
sensors: SortableListSensors;
|
|
6
|
+
/** The list's axis modifiers. */
|
|
7
|
+
modifiers: SortableListModifiers;
|
|
8
|
+
}
|
|
9
|
+
declare const ProviderSetup: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type ProviderSetup = ReturnType<typeof ProviderSetup>;
|
|
11
|
+
export default ProviderSetup;
|
|
12
|
+
//# sourceMappingURL=ProviderSetup.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderSetup.svelte.d.ts","sourceRoot":"","sources":["../src/ProviderSetup.svelte"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAG/F,wDAAwD;AACxD,UAAU,KAAK;IACb,qCAAqC;IACrC,OAAO,EAAE,mBAAmB,CAAA;IAC5B,iCAAiC;IACjC,SAAS,EAAE,qBAAqB,CAAA;CACjC;AA+BH,QAAA,MAAM,aAAa,2CAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends { id: string }">
|
|
2
|
+
/**
|
|
3
|
+
* The Svelte sortable list.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DragDropProvider } from '@dnd-kit/svelte'
|
|
9
|
+
import { setContext } from 'svelte'
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
coreDragOver,
|
|
13
|
+
coreDragStart,
|
|
14
|
+
resolveSortableAxis,
|
|
15
|
+
sortableListDrop,
|
|
16
|
+
sortableListModifiers,
|
|
17
|
+
sortableListPlugins,
|
|
18
|
+
sortableListSensors,
|
|
19
|
+
} from '@molecule/app-drag-drop-dndkit'
|
|
20
|
+
|
|
21
|
+
import type { SortableListState } from './context.js'
|
|
22
|
+
import { SORTABLE_LIST_CONTEXT } from './context.js'
|
|
23
|
+
import ProviderSetup from './ProviderSetup.svelte'
|
|
24
|
+
import type { SortableListProps } from './types.js'
|
|
25
|
+
|
|
26
|
+
let {
|
|
27
|
+
items,
|
|
28
|
+
onReorder,
|
|
29
|
+
axis,
|
|
30
|
+
strategy,
|
|
31
|
+
disabled = false,
|
|
32
|
+
config,
|
|
33
|
+
getItemLabel,
|
|
34
|
+
onDragStart,
|
|
35
|
+
onDragOver,
|
|
36
|
+
onDragEnd,
|
|
37
|
+
children,
|
|
38
|
+
}: SortableListProps<T> = $props()
|
|
39
|
+
|
|
40
|
+
const activationDelay = $derived(config?.activationDelay)
|
|
41
|
+
const activationDistance = $derived(config?.activationDistance)
|
|
42
|
+
const cancelOnEscape = $derived(config?.cancelOnEscape)
|
|
43
|
+
const sensors = $derived(
|
|
44
|
+
sortableListSensors({ activationDelay, activationDistance, cancelOnEscape }),
|
|
45
|
+
)
|
|
46
|
+
const resolvedAxis = $derived(resolveSortableAxis(axis, strategy))
|
|
47
|
+
const modifiers = $derived(sortableListModifiers(resolvedAxis))
|
|
48
|
+
|
|
49
|
+
// Built once per list, as the React binding's `useMemo(…, [])` does: the plugins hold the list's
|
|
50
|
+
// identity and rewrite themselves on a locale change.
|
|
51
|
+
const plugins = sortableListPlugins({
|
|
52
|
+
labelOf: (id) => {
|
|
53
|
+
const item = items.find((candidate) => candidate.id === id)
|
|
54
|
+
return item && getItemLabel ? getItemLabel(item) : id
|
|
55
|
+
},
|
|
56
|
+
count: () => items.length,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// Getter-backed, so rows read the list's current `items` and `disabled`.
|
|
60
|
+
const listState: SortableListState = {
|
|
61
|
+
indexOf: (id) => items.findIndex((item) => item.id === id),
|
|
62
|
+
get disabled() {
|
|
63
|
+
return disabled
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
setContext(SORTABLE_LIST_CONTEXT, listState)
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<DragDropProvider
|
|
70
|
+
{sensors}
|
|
71
|
+
{modifiers}
|
|
72
|
+
{plugins}
|
|
73
|
+
onDragStart={(event) => {
|
|
74
|
+
const started = coreDragStart(event.operation.source)
|
|
75
|
+
if (started) onDragStart?.(started)
|
|
76
|
+
}}
|
|
77
|
+
onDragOver={(event) => {
|
|
78
|
+
const over = coreDragOver(event.operation.source, event.operation.target)
|
|
79
|
+
if (over) onDragOver?.(over)
|
|
80
|
+
}}
|
|
81
|
+
onDragEnd={(event) => {
|
|
82
|
+
const drop = sortableListDrop(items, event, disabled)
|
|
83
|
+
if (drop.event) onDragEnd?.(drop.event)
|
|
84
|
+
if (drop.reordered) onReorder(drop.reordered)
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
<!-- Runs before the rows and hands the manager this list's own plugins, sensors and modifiers. -->
|
|
88
|
+
<ProviderSetup {sensors} {modifiers} />
|
|
89
|
+
{@render children()}
|
|
90
|
+
</DragDropProvider>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SortableListProps } from './types.js';
|
|
2
|
+
declare function $$render<T extends {
|
|
3
|
+
id: string;
|
|
4
|
+
}>(): {
|
|
5
|
+
props: SortableListProps<T>;
|
|
6
|
+
exports: {};
|
|
7
|
+
bindings: "";
|
|
8
|
+
slots: {};
|
|
9
|
+
events: {};
|
|
10
|
+
};
|
|
11
|
+
declare class __sveltets_Render<T extends {
|
|
12
|
+
id: string;
|
|
13
|
+
}> {
|
|
14
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
15
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
16
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
17
|
+
bindings(): "";
|
|
18
|
+
exports(): {};
|
|
19
|
+
}
|
|
20
|
+
interface $$IsomorphicComponent {
|
|
21
|
+
new <T extends {
|
|
22
|
+
id: string;
|
|
23
|
+
}>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
24
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
25
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
26
|
+
<T extends {
|
|
27
|
+
id: string;
|
|
28
|
+
}>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
29
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
30
|
+
}
|
|
31
|
+
declare const SortableList: $$IsomorphicComponent;
|
|
32
|
+
type SortableList<T extends {
|
|
33
|
+
id: string;
|
|
34
|
+
}> = InstanceType<typeof SortableList<T>>;
|
|
35
|
+
export default SortableList;
|
|
36
|
+
//# sourceMappingURL=SortableList.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortableList.svelte.d.ts","sourceRoot":"","sources":["../src/SortableList.svelte"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,iBAAS,QAAQ,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE;WA0Eb,iBAAiB,CAAC,CAAC,CAAC;;;;;EAA4E;AAC7H,cAAM,iBAAiB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE;IAC5C,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,MAAM,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClD,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,QAAQ;IACR,OAAO;CACV;AAED,UAAU,qBAAqB;IAC3B,KAAK,CAAC,SAAS;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;KAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACnZ,CAAC,CAAC,SAAS;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAClJ,YAAY,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACjE;AACD,QAAA,MAAM,YAAY,EAAE,qBAAmC,CAAC;AACtC,KAAK,YAAY,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,IAAI,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AACrF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The context a Svelte `SortableList` gives its items.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** What a sortable item reads from the list around it. */
|
|
7
|
+
export interface SortableListState {
|
|
8
|
+
/**
|
|
9
|
+
* The item's index in the list's current `items`.
|
|
10
|
+
*
|
|
11
|
+
* @param id - The item's id.
|
|
12
|
+
* @returns Its index, or `-1` when the list has no such item.
|
|
13
|
+
*/
|
|
14
|
+
indexOf: (id: string) => number;
|
|
15
|
+
/** Whether the whole list is disabled. */
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The context key for {@link SortableListState}: set by `SortableList`, and
|
|
20
|
+
* absent outside one, where `useSortableItem` refuses to run.
|
|
21
|
+
*/
|
|
22
|
+
export declare const SORTABLE_LIST_CONTEXT: unique symbol;
|
|
23
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,0DAA0D;AAC1D,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAA;IAC/B,0CAA0C;IAC1C,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,eAAmC,CAAA"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The context a Svelte `SortableList` gives its items.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The context key for {@link SortableListState}: set by `SortableList`, and
|
|
8
|
+
* absent outside one, where `useSortableItem` refuses to run.
|
|
9
|
+
*/
|
|
10
|
+
export const SORTABLE_LIST_CONTEXT = Symbol('molecule-sortable-list');
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte sortable list for `@molecule/app-drag-drop-dndkit`.
|
|
3
|
+
*
|
|
4
|
+
* `SortableList` renders a list the user reorders with the pointer, touch or
|
|
5
|
+
* the keyboard, on `@dnd-kit/svelte`. Each row calls `useSortableItem`. The
|
|
6
|
+
* options are `@molecule/app-drag-drop-dndkit`'s `SortableListOptions`, the
|
|
7
|
+
* same in the React, Vue, Solid, Svelte and Angular bindings, so a list swaps
|
|
8
|
+
* between frameworks unchanged.
|
|
9
|
+
*
|
|
10
|
+
* `useSortableItem` returns Svelte attachments for the row element (`ref`) and
|
|
11
|
+
* an optional drag handle (`handleRef`), plus the row's `isDragging` and
|
|
12
|
+
* `isDropTarget` state as read-only reactive getters. Apply an attachment with
|
|
13
|
+
* Svelte's attachment tag on the element, or with `createAttachmentKey()` in a
|
|
14
|
+
* spread, as the example below shows.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```svelte
|
|
18
|
+
* <!-- Row.svelte -->
|
|
19
|
+
* <script lang="ts">
|
|
20
|
+
* import { createAttachmentKey } from 'svelte/attachments'
|
|
21
|
+
*
|
|
22
|
+
* import { useSortableItem } from '@molecule/app-drag-drop-dndkit-svelte'
|
|
23
|
+
*
|
|
24
|
+
* let { task }: { task: Task } = $props()
|
|
25
|
+
*
|
|
26
|
+
* const { ref, isDragging } = useSortableItem({ id: task.id })
|
|
27
|
+
* const attach = { [createAttachmentKey()]: ref }
|
|
28
|
+
* </script>
|
|
29
|
+
*
|
|
30
|
+
* <li {...attach} data-dragging={isDragging}>{task.title}</li>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ```svelte
|
|
34
|
+
* <!-- Tasks.svelte -->
|
|
35
|
+
* <script lang="ts">
|
|
36
|
+
* import { SortableList } from '@molecule/app-drag-drop-dndkit-svelte'
|
|
37
|
+
* import Row from './Row.svelte'
|
|
38
|
+
*
|
|
39
|
+
* let { tasks }: { tasks: Task[] } = $props()
|
|
40
|
+
* </script>
|
|
41
|
+
*
|
|
42
|
+
* <SortableList items={tasks} onReorder={(next) => (tasks = next)} getItemLabel={(task) => task.title}>
|
|
43
|
+
* <ul>
|
|
44
|
+
* {#each tasks as task (task.id)}
|
|
45
|
+
* <Row {task} />
|
|
46
|
+
* {/each}
|
|
47
|
+
* </ul>
|
|
48
|
+
* </SortableList>
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* The screen-reader instructions and announcements use the
|
|
53
|
+
* `dragDrop.sortable.*` keys; bond `@molecule/app-locales-drag-drop-dndkit` for
|
|
54
|
+
* their translations. Persist the order in `onReorder`; if saving fails,
|
|
55
|
+
* restore the previous `items`. Set an item's `disabled` option to pin one row,
|
|
56
|
+
* or the list's `disabled` prop to pin the whole list.
|
|
57
|
+
*
|
|
58
|
+
* @module
|
|
59
|
+
*/
|
|
60
|
+
export * from './components.js';
|
|
61
|
+
export * from './types.js';
|
|
62
|
+
export * from './useSortableItem.svelte.js';
|
|
63
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,6BAA6B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte sortable list for `@molecule/app-drag-drop-dndkit`.
|
|
3
|
+
*
|
|
4
|
+
* `SortableList` renders a list the user reorders with the pointer, touch or
|
|
5
|
+
* the keyboard, on `@dnd-kit/svelte`. Each row calls `useSortableItem`. The
|
|
6
|
+
* options are `@molecule/app-drag-drop-dndkit`'s `SortableListOptions`, the
|
|
7
|
+
* same in the React, Vue, Solid, Svelte and Angular bindings, so a list swaps
|
|
8
|
+
* between frameworks unchanged.
|
|
9
|
+
*
|
|
10
|
+
* `useSortableItem` returns Svelte attachments for the row element (`ref`) and
|
|
11
|
+
* an optional drag handle (`handleRef`), plus the row's `isDragging` and
|
|
12
|
+
* `isDropTarget` state as read-only reactive getters. Apply an attachment with
|
|
13
|
+
* Svelte's attachment tag on the element, or with `createAttachmentKey()` in a
|
|
14
|
+
* spread, as the example below shows.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```svelte
|
|
18
|
+
* <!-- Row.svelte -->
|
|
19
|
+
* <script lang="ts">
|
|
20
|
+
* import { createAttachmentKey } from 'svelte/attachments'
|
|
21
|
+
*
|
|
22
|
+
* import { useSortableItem } from '@molecule/app-drag-drop-dndkit-svelte'
|
|
23
|
+
*
|
|
24
|
+
* let { task }: { task: Task } = $props()
|
|
25
|
+
*
|
|
26
|
+
* const { ref, isDragging } = useSortableItem({ id: task.id })
|
|
27
|
+
* const attach = { [createAttachmentKey()]: ref }
|
|
28
|
+
* </script>
|
|
29
|
+
*
|
|
30
|
+
* <li {...attach} data-dragging={isDragging}>{task.title}</li>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ```svelte
|
|
34
|
+
* <!-- Tasks.svelte -->
|
|
35
|
+
* <script lang="ts">
|
|
36
|
+
* import { SortableList } from '@molecule/app-drag-drop-dndkit-svelte'
|
|
37
|
+
* import Row from './Row.svelte'
|
|
38
|
+
*
|
|
39
|
+
* let { tasks }: { tasks: Task[] } = $props()
|
|
40
|
+
* </script>
|
|
41
|
+
*
|
|
42
|
+
* <SortableList items={tasks} onReorder={(next) => (tasks = next)} getItemLabel={(task) => task.title}>
|
|
43
|
+
* <ul>
|
|
44
|
+
* {#each tasks as task (task.id)}
|
|
45
|
+
* <Row {task} />
|
|
46
|
+
* {/each}
|
|
47
|
+
* </ul>
|
|
48
|
+
* </SortableList>
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* The screen-reader instructions and announcements use the
|
|
53
|
+
* `dragDrop.sortable.*` keys; bond `@molecule/app-locales-drag-drop-dndkit` for
|
|
54
|
+
* their translations. Persist the order in `onReorder`; if saving fails,
|
|
55
|
+
* restore the previous `items`. Set an item's `disabled` option to pin one row,
|
|
56
|
+
* or the list's `disabled` prop to pin the whole list.
|
|
57
|
+
*
|
|
58
|
+
* @module
|
|
59
|
+
*/
|
|
60
|
+
export * from './components.js';
|
|
61
|
+
export * from './types.js';
|
|
62
|
+
export * from './useSortableItem.svelte.js';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The props of the Svelte sortable list.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { Snippet } from 'svelte';
|
|
7
|
+
import type { SortableListOptions } from '@molecule/app-drag-drop-dndkit';
|
|
8
|
+
/**
|
|
9
|
+
* Props for `SortableList`: the options every framework's list takes, plus the
|
|
10
|
+
* list itself as `children`.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The item type. Items must have a stable string `id`.
|
|
13
|
+
*/
|
|
14
|
+
export interface SortableListProps<T extends {
|
|
15
|
+
id: string;
|
|
16
|
+
}> extends SortableListOptions<T> {
|
|
17
|
+
/** The rendered list, whose rows call `useSortableItem`. */
|
|
18
|
+
children: Snippet;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AAEzE;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACzF,4DAA4D;IAC5D,QAAQ,EAAE,OAAO,CAAA;CAClB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Svelte composable for one row of a sortable list.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { SortableItemOptions } from '@molecule/app-drag-drop-dndkit';
|
|
7
|
+
/** What {@link useSortableItem} returns for one row. */
|
|
8
|
+
export interface SortableItemState {
|
|
9
|
+
/**
|
|
10
|
+
* A Svelte attachment for the row's element: Svelte calls it with the
|
|
11
|
+
* element when the row mounts, and with the returned cleanup when it is
|
|
12
|
+
* removed. dnd-kit makes the element focusable and sets its `role`,
|
|
13
|
+
* `aria-roledescription`, `aria-describedby`, `aria-pressed` and
|
|
14
|
+
* `aria-disabled`.
|
|
15
|
+
*
|
|
16
|
+
* @param node - The row's element.
|
|
17
|
+
* @returns The detach function Svelte calls when the row is removed.
|
|
18
|
+
*/
|
|
19
|
+
ref: (node: HTMLElement) => () => void;
|
|
20
|
+
/**
|
|
21
|
+
* A Svelte attachment for a drag handle inside the row (the library's
|
|
22
|
+
* `attachHandle`) so only the handle starts a drag; leave it unused to drag
|
|
23
|
+
* by the whole row.
|
|
24
|
+
*
|
|
25
|
+
* @param node - The handle's element.
|
|
26
|
+
* @returns The detach function Svelte calls when the handle is removed.
|
|
27
|
+
*/
|
|
28
|
+
handleRef: (node: HTMLElement) => () => void;
|
|
29
|
+
/** `true` while this row is being dragged. */
|
|
30
|
+
readonly isDragging: boolean;
|
|
31
|
+
/** `true` while another dragged row is over this one. */
|
|
32
|
+
readonly isDropTarget: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Makes one row of a `SortableList` draggable. Call it during the row
|
|
36
|
+
* component's initialization, inside the list.
|
|
37
|
+
*
|
|
38
|
+
* @param options - The row's item id, drag data and disabled flag.
|
|
39
|
+
* @returns The attachments to apply to the row (and its handle) plus its drag state.
|
|
40
|
+
* @throws {Error} When called outside a `SortableList`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useSortableItem(options: SortableItemOptions): SortableItemState;
|
|
43
|
+
//# sourceMappingURL=useSortableItem.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSortableItem.svelte.d.ts","sourceRoot":"","sources":["../src/useSortableItem.svelte.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AAKzE,wDAAwD;AACxD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;OASG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,MAAM,IAAI,CAAA;IACtC;;;;;;;OAOG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,MAAM,IAAI,CAAA;IAC5C,8CAA8C;IAC9C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;CAC/B;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,iBAAiB,CA0B/E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Svelte composable for one row of a sortable list.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { createSortable } from '@dnd-kit/svelte/sortable';
|
|
7
|
+
import { getContext } from 'svelte';
|
|
8
|
+
import { SORTABLE_LIST_CONTEXT } from './context.js';
|
|
9
|
+
/**
|
|
10
|
+
* Makes one row of a `SortableList` draggable. Call it during the row
|
|
11
|
+
* component's initialization, inside the list.
|
|
12
|
+
*
|
|
13
|
+
* @param options - The row's item id, drag data and disabled flag.
|
|
14
|
+
* @returns The attachments to apply to the row (and its handle) plus its drag state.
|
|
15
|
+
* @throws {Error} When called outside a `SortableList`.
|
|
16
|
+
*/
|
|
17
|
+
export function useSortableItem(options) {
|
|
18
|
+
const list = getContext(SORTABLE_LIST_CONTEXT);
|
|
19
|
+
if (!list)
|
|
20
|
+
throw new Error('useSortableItem must be called inside a <SortableList>.');
|
|
21
|
+
const { id, data, disabled = false } = options;
|
|
22
|
+
// Getters, so dnd-kit reads the row's index and the list's disabled flag
|
|
23
|
+
// reactively: a reorder or a disabled change reaches the sortable instance.
|
|
24
|
+
const sortable = createSortable({
|
|
25
|
+
id,
|
|
26
|
+
get index() {
|
|
27
|
+
return list.indexOf(id);
|
|
28
|
+
},
|
|
29
|
+
data,
|
|
30
|
+
get disabled() {
|
|
31
|
+
return disabled || list.disabled;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
ref: sortable.attach,
|
|
36
|
+
handleRef: sortable.attachHandle,
|
|
37
|
+
get isDragging() {
|
|
38
|
+
return sortable.isDragging;
|
|
39
|
+
},
|
|
40
|
+
get isDropTarget() {
|
|
41
|
+
return sortable.isDropTarget;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-drag-drop-dndkit-svelte",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-stage",
|
|
4
|
+
"description": "Svelte binding for @molecule/app-drag-drop-dndkit — a sortable list that reorders with the pointer, touch and the keyboard, with translated screen-reader announcements.",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-drag-drop-dndkit-svelte",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"svelte": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"!dist/**/__tests__",
|
|
20
|
+
"!dist/**/*.test.*",
|
|
21
|
+
"!dist/**/*.spec.*",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"svelte": "./dist/index.js",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
|
|
27
|
+
"dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"molecule",
|
|
33
|
+
"drag",
|
|
34
|
+
"drop",
|
|
35
|
+
"sortable",
|
|
36
|
+
"dnd-kit",
|
|
37
|
+
"svelte"
|
|
38
|
+
],
|
|
39
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
40
|
+
"license": "Apache-2.0",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
44
|
+
"directory": "packages/app/bonds/drag-drop/dndkit-svelte"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
},
|
|
49
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@molecule/app-drag-drop": "^1.0.1",
|
|
55
|
+
"@molecule/app-drag-drop-dndkit": "^2.0.0",
|
|
56
|
+
"svelte": "^5.29.0"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@dnd-kit/svelte": "0.5.3"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@molecule/app-drag-drop": "1.0.4",
|
|
63
|
+
"@molecule/app-drag-drop-dndkit": "2.0.0",
|
|
64
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
65
|
+
"@molecule/app-i18n": "1.2.2",
|
|
66
|
+
"@sveltejs/package": "3.0.2",
|
|
67
|
+
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
68
|
+
"@types/node": "26.6.5",
|
|
69
|
+
"jsdom": "30.1.3",
|
|
70
|
+
"svelte": "5.57.2",
|
|
71
|
+
"svelte-check": "4.7.7",
|
|
72
|
+
"typescript": "6.0.3",
|
|
73
|
+
"vite": "8.3.5",
|
|
74
|
+
"vitest": "4.1.12"
|
|
75
|
+
}
|
|
76
|
+
}
|