@lynx-js/lynx-ui-sortable 0.0.0 → 3.130.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE +201 -0
- package/README.md +57 -0
- package/dist/Sortable.d.ts +6 -0
- package/dist/Sortable.d.ts.map +1 -0
- package/dist/Sortable.jsx +153 -0
- package/dist/Sortable.jsx.map +1 -0
- package/dist/SortableContext.d.ts +19 -0
- package/dist/SortableContext.d.ts.map +1 -0
- package/dist/SortableContext.jsx +15 -0
- package/dist/SortableContext.jsx.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.docs.d.ts +123 -0
- package/dist/types/index.docs.d.ts.map +1 -0
- package/dist/types/index.jsx +0 -0
- package/dist/useSortable.d.ts +21 -0
- package/dist/useSortable.d.ts.map +1 -0
- package/dist/useSortable.jsx +219 -0
- package/dist/useSortable.jsx.map +1 -0
- package/package.json +46 -4
- package/src/Sortable.tsx +272 -0
- package/src/SortableContext.ts +50 -0
- package/src/index.tsx +11 -0
- package/src/types/index.docs.ts +129 -0
- package/src/types/index.ts +5 -0
- package/src/useSortable.tsx +354 -0
- package/tsconfig.docs.json +7 -0
- package/tsconfig.json +9 -0
- /package/{index.js → dist/types/index.docs.jsx} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @lynx-js/lynx-ui-sortable
|
|
2
|
+
|
|
3
|
+
## 3.130.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Update files field in all packages to include LICENSE file. ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520)]:
|
|
10
|
+
- @lynx-js/lynx-ui-common@3.130.0
|
|
11
|
+
- @lynx-js/lynx-ui-draggable@3.130.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @lynx-js/lynx-ui-sortable
|
|
2
|
+
|
|
3
|
+
A headless Sortable list component for ReactLynx. It provides list reordering primitives via main-thread animations.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
We strongly recommend installing and using this component through the main `@lynx-js/lynx-ui` package:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# pnpm (recommended)
|
|
11
|
+
pnpm add @lynx-js/lynx-ui
|
|
12
|
+
|
|
13
|
+
# npm
|
|
14
|
+
npm install @lynx-js/lynx-ui
|
|
15
|
+
|
|
16
|
+
# yarn
|
|
17
|
+
yarn add @lynx-js/lynx-ui
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
_(If necessary, you can still install the standalone package via `pnpm add @lynx-js/lynx-ui-sortable`)_
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
The `lynx-ui-sortable` follows a headless composition pattern.
|
|
25
|
+
|
|
26
|
+
[View Full Examples](https://github.com/lynx-family/lynx-ui/tree/main/apps/examples/Sortable)
|
|
27
|
+
|
|
28
|
+
## Component Structure
|
|
29
|
+
|
|
30
|
+
The `Sortable` component is composed of the following sub-components:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
<SortableRoot>
|
|
34
|
+
{(item) => (
|
|
35
|
+
<SortableItem
|
|
36
|
+
key={item.getSortingKey()}
|
|
37
|
+
sortingKey={item.getSortingKey()}
|
|
38
|
+
>
|
|
39
|
+
<SortableItemArea>
|
|
40
|
+
{/* Your item content */}
|
|
41
|
+
</SortableItemArea>
|
|
42
|
+
</SortableItem>
|
|
43
|
+
)}
|
|
44
|
+
</SortableRoot>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- **`SortableRoot`**: The root container that manages the sortable state.
|
|
48
|
+
- **`SortableItem`**: An individual sortable item.
|
|
49
|
+
- **`SortableItemArea`**: The draggable area within a sortable item.
|
|
50
|
+
|
|
51
|
+
## About @lynx-js/lynx-ui
|
|
52
|
+
|
|
53
|
+
This component is part of `@lynx-js/lynx-ui`, a headless UI library officially maintained by the Lynx team, provided as a reference for building flexible, universal, and high-performance ReactLynx components.
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
[**lynx-ui**](https://github.com/lynx-family/lynx-ui) is [**Apache License 2.0**](./LICENSE) licensed.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DraggableArea } from '@lynx-js/lynx-ui-draggable';
|
|
2
|
+
import type { SortableItemProps, SortableRootProps } from './types';
|
|
3
|
+
export { DraggableArea as SortableItemArea };
|
|
4
|
+
export declare function SortableRoot<T>(props: SortableRootProps<T>): import("react").JSX.Element;
|
|
5
|
+
export declare function SortableItem(props: SortableItemProps): import("react").JSX.Element;
|
|
6
|
+
//# sourceMappingURL=Sortable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sortable.d.ts","sourceRoot":"","sources":["../src/Sortable.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAEL,aAAa,EAEd,MAAM,4BAA4B,CAAA;AAKnC,OAAO,KAAK,EAEV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,aAAa,IAAI,gBAAgB,EAAE,CAAA;AAE5C,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,+BAqF1D;AAWD,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,+BA4IpD"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { runOnMainThread, useCallback, useContext, useEffect, useMainThreadRef, useMemo, useRef, useState } from "@lynx-js/react";
|
|
2
|
+
import { Draggable, DraggableArea, DraggableRoot } from "@lynx-js/lynx-ui-draggable";
|
|
3
|
+
import { SortableContext } from "./SortableContext.jsx";
|
|
4
|
+
import { useSortable } from "./useSortable.jsx";
|
|
5
|
+
function SortableRoot(props) {
|
|
6
|
+
const { children, data, debugLog = false, boundaryId, onSortEnd, onSortStart, enableSorting = true } = props;
|
|
7
|
+
const sizeMap = useMainThreadRef({});
|
|
8
|
+
const childrenRefMap = useMainThreadRef({});
|
|
9
|
+
const childrenMTSRefMap = useMainThreadRef({});
|
|
10
|
+
const updateItemSize = useCallback((sortingKey, size)=>{
|
|
11
|
+
'main thread';
|
|
12
|
+
sizeMap.current[sortingKey] = size;
|
|
13
|
+
}, []);
|
|
14
|
+
const setChildrenRef = useCallback((refI, key)=>{
|
|
15
|
+
'main thread';
|
|
16
|
+
childrenRefMap.current[key] = refI.current;
|
|
17
|
+
}, []);
|
|
18
|
+
const setChildrenMTSRef = useCallback((refI, key)=>{
|
|
19
|
+
'main thread';
|
|
20
|
+
childrenMTSRefMap.current[key] = refI.current;
|
|
21
|
+
}, []);
|
|
22
|
+
const { handleDragEnd, handleDragMove, handleDragStart } = useSortable({
|
|
23
|
+
data: data,
|
|
24
|
+
sizeMap: sizeMap,
|
|
25
|
+
itemRefMap: childrenRefMap,
|
|
26
|
+
itemMTSRefMap: childrenMTSRefMap,
|
|
27
|
+
onDragEnd: onSortEnd,
|
|
28
|
+
onDragStart: onSortStart,
|
|
29
|
+
debugLog
|
|
30
|
+
});
|
|
31
|
+
const sortableContextValue = useMemo(()=>({
|
|
32
|
+
data,
|
|
33
|
+
enableSorting,
|
|
34
|
+
boundaryId,
|
|
35
|
+
updateItemSize,
|
|
36
|
+
setChildrenRef,
|
|
37
|
+
setChildrenMTSRef,
|
|
38
|
+
handleDragEnd,
|
|
39
|
+
handleDragMove,
|
|
40
|
+
handleDragStart
|
|
41
|
+
}), [
|
|
42
|
+
data,
|
|
43
|
+
enableSorting,
|
|
44
|
+
boundaryId,
|
|
45
|
+
updateItemSize,
|
|
46
|
+
setChildrenRef,
|
|
47
|
+
setChildrenMTSRef,
|
|
48
|
+
handleDragEnd,
|
|
49
|
+
handleDragMove,
|
|
50
|
+
handleDragStart
|
|
51
|
+
]);
|
|
52
|
+
const renderedChildren = useMemo(()=>data?.map((item)=>children(item)), [
|
|
53
|
+
data,
|
|
54
|
+
children
|
|
55
|
+
]);
|
|
56
|
+
return <SortableContext.Provider value={sortableContextValue}>
|
|
57
|
+
{renderedChildren}
|
|
58
|
+
</SortableContext.Provider>;
|
|
59
|
+
}
|
|
60
|
+
function SortableItem(props) {
|
|
61
|
+
const { className, children, sortingKey, as = 'Draggable' } = props;
|
|
62
|
+
const { data, enableSorting, boundaryId, updateItemSize, setChildrenRef, setChildrenMTSRef, handleDragStart, handleDragEnd, handleDragMove } = useContext(SortableContext);
|
|
63
|
+
const MTSRef = useMainThreadRef(null);
|
|
64
|
+
const ref = useRef(null);
|
|
65
|
+
const [itemRect, setItemRect] = useState({
|
|
66
|
+
height: 0,
|
|
67
|
+
width: 0,
|
|
68
|
+
top: 0,
|
|
69
|
+
left: 0,
|
|
70
|
+
bottom: 0,
|
|
71
|
+
right: 0
|
|
72
|
+
});
|
|
73
|
+
const [boundaryRect, setBoundaryRect] = useState({
|
|
74
|
+
height: 0,
|
|
75
|
+
width: 0,
|
|
76
|
+
top: 0,
|
|
77
|
+
left: 0,
|
|
78
|
+
bottom: 0,
|
|
79
|
+
right: 0
|
|
80
|
+
});
|
|
81
|
+
useEffect(()=>{
|
|
82
|
+
runOnMainThread(setChildrenMTSRef)(MTSRef, sortingKey);
|
|
83
|
+
if (boundaryId) {
|
|
84
|
+
ref?.current?.invoke({
|
|
85
|
+
method: 'boundingClientRect',
|
|
86
|
+
params: {},
|
|
87
|
+
success: (res)=>{
|
|
88
|
+
setItemRect(res);
|
|
89
|
+
}
|
|
90
|
+
}).exec();
|
|
91
|
+
lynx.createSelectorQuery().select(`#${boundaryId}`)?.invoke({
|
|
92
|
+
method: 'boundingClientRect',
|
|
93
|
+
params: {},
|
|
94
|
+
success: (res)=>{
|
|
95
|
+
setBoundaryRect(res);
|
|
96
|
+
}
|
|
97
|
+
}).exec();
|
|
98
|
+
}
|
|
99
|
+
}, [
|
|
100
|
+
setChildrenRef,
|
|
101
|
+
setChildrenMTSRef,
|
|
102
|
+
sortingKey,
|
|
103
|
+
data,
|
|
104
|
+
boundaryId
|
|
105
|
+
]);
|
|
106
|
+
const handleMTSLayoutChange = (e)=>{
|
|
107
|
+
'main thread';
|
|
108
|
+
updateItemSize(sortingKey, e.detail.height);
|
|
109
|
+
};
|
|
110
|
+
const itemDragStart = (pagePoint, event)=>{
|
|
111
|
+
'main thread';
|
|
112
|
+
handleDragStart?.(pagePoint, sortingKey, event);
|
|
113
|
+
};
|
|
114
|
+
const itemDragging = (translate, event)=>{
|
|
115
|
+
'main thread';
|
|
116
|
+
handleDragMove?.(translate, sortingKey, event);
|
|
117
|
+
};
|
|
118
|
+
const itemDragEnd = (_pagePoint, event)=>{
|
|
119
|
+
'main thread';
|
|
120
|
+
handleDragEnd?.(sortingKey, event);
|
|
121
|
+
};
|
|
122
|
+
const resetStyle = useMemo(()=>({
|
|
123
|
+
transform: 'translate(0, 0)',
|
|
124
|
+
zIndex: '0'
|
|
125
|
+
}), [
|
|
126
|
+
data
|
|
127
|
+
]);
|
|
128
|
+
if ('Draggable' === as) return <Draggable MTSRef={MTSRef} ref={ref} trigger='immediate' style={resetStyle} className={className} enableDragging={enableSorting} draggableProps={{
|
|
129
|
+
'main-thread:bindlayoutchange': handleMTSLayoutChange
|
|
130
|
+
}} onMTSDragStart={itemDragStart} onMTSDragEnd={itemDragEnd} onMTSDragging={itemDragging} allowedDirection={[
|
|
131
|
+
'up',
|
|
132
|
+
'down'
|
|
133
|
+
]} {...boundaryId && {
|
|
134
|
+
minTranslateY: -(itemRect?.top - boundaryRect?.top),
|
|
135
|
+
maxTranslateY: boundaryRect?.bottom - itemRect?.bottom
|
|
136
|
+
}}>
|
|
137
|
+
{children}
|
|
138
|
+
</Draggable>;
|
|
139
|
+
return <DraggableRoot MTSRef={MTSRef} ref={ref} trigger='immediate' style={resetStyle} className={className} draggableProps={{
|
|
140
|
+
'main-thread:bindlayoutchange': handleMTSLayoutChange
|
|
141
|
+
}} onMTSDragStart={itemDragStart} onMTSDragEnd={itemDragEnd} onMTSDragging={itemDragging} enableDragging={enableSorting} {...boundaryId && {
|
|
142
|
+
minTranslateY: -(itemRect?.top - boundaryRect?.top),
|
|
143
|
+
maxTranslateY: boundaryRect?.bottom - itemRect?.bottom
|
|
144
|
+
}} allowedDirection={[
|
|
145
|
+
'up',
|
|
146
|
+
'down'
|
|
147
|
+
]}>
|
|
148
|
+
{children}
|
|
149
|
+
</DraggableRoot>;
|
|
150
|
+
}
|
|
151
|
+
export { SortableItem, DraggableArea as SortableItemArea, SortableRoot };
|
|
152
|
+
|
|
153
|
+
//# sourceMappingURL=Sortable.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sortable.jsx","sources":["webpack://@lynx-js/lynx-ui-sortable/./src/Sortable.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport {\n runOnMainThread,\n useCallback,\n useContext,\n useEffect,\n useMainThreadRef,\n useMemo,\n useRef,\n useState,\n} from '@lynx-js/react'\nimport type { RefObject } from '@lynx-js/react'\n\nimport type { Point } from '@lynx-js/lynx-ui-common'\nimport {\n Draggable,\n DraggableArea,\n DraggableRoot,\n} from '@lynx-js/lynx-ui-draggable'\nimport type { DraggableRef } from '@lynx-js/lynx-ui-draggable'\nimport type { MainThread, NodesRef } from '@lynx-js/types'\n\nimport { SortableContext } from './SortableContext'\nimport type {\n SortableData,\n SortableItemProps,\n SortableRootProps,\n} from './types'\nimport { useSortable } from './useSortable'\n\nexport { DraggableArea as SortableItemArea }\n\nexport function SortableRoot<T>(props: SortableRootProps<T>) {\n const {\n children,\n data,\n debugLog = false,\n boundaryId,\n onSortEnd,\n onSortStart,\n enableSorting = true,\n } = props\n const sizeMap = useMainThreadRef<Record<string, number>>({})\n const childrenRefMap = useMainThreadRef<\n Record<string, DraggableRef | null>\n >(\n {},\n )\n const childrenMTSRefMap = useMainThreadRef<\n Record<string, DraggableRef | null>\n >(\n {},\n )\n const updateItemSize = useCallback((sortingKey: string, size: number) => {\n 'main thread'\n sizeMap.current[sortingKey] = size\n }, [])\n\n const setChildrenRef = useCallback(\n (refI: RefObject<DraggableRef>, key: string) => {\n 'main thread'\n childrenRefMap.current[key] = refI.current\n },\n [],\n )\n\n const setChildrenMTSRef = useCallback((\n refI: RefObject<DraggableRef>,\n key: string,\n ) => {\n 'main thread'\n childrenMTSRefMap.current[key] = refI.current\n }, [])\n\n const { handleDragEnd, handleDragMove, handleDragStart } = useSortable({\n data: data as SortableData<unknown>[],\n sizeMap: sizeMap,\n itemRefMap: childrenRefMap,\n itemMTSRefMap: childrenMTSRefMap,\n onDragEnd: onSortEnd as (sortedData: SortableData<unknown>[]) => void,\n onDragStart: onSortStart,\n debugLog,\n })\n const sortableContextValue = useMemo(() => ({\n data,\n enableSorting,\n boundaryId,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n handleDragEnd,\n handleDragMove,\n handleDragStart,\n }), [\n data,\n enableSorting,\n boundaryId,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n handleDragEnd,\n handleDragMove,\n handleDragStart,\n ])\n\n const renderedChildren = useMemo(\n () => data?.map(item => children(item)),\n [data, children],\n )\n\n return (\n <SortableContext.Provider\n value={sortableContextValue}\n >\n {renderedChildren}\n </SortableContext.Provider>\n )\n}\n\ninterface boundingClientRectRes {\n height: number\n width: number\n top: number\n left: number\n bottom: number\n right: number\n}\n\nexport function SortableItem(props: SortableItemProps) {\n const { className, children, sortingKey, as = 'Draggable' } = props\n const {\n data,\n enableSorting,\n boundaryId,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n handleDragStart,\n handleDragEnd,\n handleDragMove,\n } = useContext(SortableContext)\n\n const MTSRef = useMainThreadRef<DraggableRef>(null)\n const ref = useRef<NodesRef>(null)\n const [itemRect, setItemRect] = useState<boundingClientRectRes>({\n height: 0,\n width: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n })\n const [boundaryRect, setBoundaryRect] = useState<boundingClientRectRes>({\n height: 0,\n width: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n })\n useEffect(() => {\n runOnMainThread(setChildrenMTSRef)(MTSRef, sortingKey)\n if (boundaryId) {\n ref?.current\n ?.invoke({\n method: 'boundingClientRect',\n params: {},\n success: (res) => {\n setItemRect(res as boundingClientRectRes)\n },\n })\n .exec()\n lynx.createSelectorQuery().select(`#${boundaryId}`)?.invoke({\n method: 'boundingClientRect',\n params: {},\n success: (res) => {\n setBoundaryRect(res as boundingClientRectRes)\n },\n })\n .exec()\n }\n }, [setChildrenRef, setChildrenMTSRef, sortingKey, data, boundaryId])\n\n const handleMTSLayoutChange = (e: MainThread.LayoutChangeEvent) => {\n 'main thread'\n updateItemSize(sortingKey, e.detail.height)\n }\n\n const itemDragStart = (\n pagePoint: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n handleDragStart?.(pagePoint, sortingKey, event)\n }\n\n const itemDragging = (\n translate: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n handleDragMove?.(translate, sortingKey, event)\n }\n\n const itemDragEnd = (\n _pagePoint: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n handleDragEnd?.(sortingKey, event)\n }\n\n const resetStyle = useMemo(\n () => ({ transform: 'translate(0, 0)', zIndex: '0' }),\n [data],\n )\n\n if (as === 'Draggable') {\n return (\n <Draggable\n MTSRef={MTSRef}\n ref={ref}\n trigger='immediate'\n style={resetStyle}\n className={className}\n enableDragging={enableSorting}\n draggableProps={{\n 'main-thread:bindlayoutchange': handleMTSLayoutChange,\n }}\n onMTSDragStart={itemDragStart}\n onMTSDragEnd={itemDragEnd}\n onMTSDragging={itemDragging}\n allowedDirection={['up', 'down']}\n {...(boundaryId\n && {\n minTranslateY: -(itemRect?.top - boundaryRect?.top),\n maxTranslateY: boundaryRect?.bottom - itemRect?.bottom,\n })}\n >\n {children}\n </Draggable>\n )\n } else {\n return (\n <DraggableRoot\n MTSRef={MTSRef}\n ref={ref}\n trigger='immediate'\n style={resetStyle}\n className={className}\n draggableProps={{\n 'main-thread:bindlayoutchange': handleMTSLayoutChange,\n }}\n onMTSDragStart={itemDragStart}\n onMTSDragEnd={itemDragEnd}\n onMTSDragging={itemDragging}\n enableDragging={enableSorting}\n {...(boundaryId\n && {\n minTranslateY: -(itemRect?.top - boundaryRect?.top),\n maxTranslateY: boundaryRect?.bottom - itemRect?.bottom,\n })}\n allowedDirection={['up', 'down']}\n >\n {children}\n </DraggableRoot>\n )\n }\n}\n"],"names":["SortableRoot","props","children","data","debugLog","boundaryId","onSortEnd","onSortStart","enableSorting","sizeMap","useMainThreadRef","childrenRefMap","childrenMTSRefMap","updateItemSize","useCallback","sortingKey","size","setChildrenRef","refI","key","setChildrenMTSRef","handleDragEnd","handleDragMove","handleDragStart","useSortable","sortableContextValue","useMemo","renderedChildren","item","SortableContext","SortableItem","className","as","useContext","MTSRef","ref","useRef","itemRect","setItemRect","useState","boundaryRect","setBoundaryRect","useEffect","runOnMainThread","res","lynx","handleMTSLayoutChange","e","itemDragStart","pagePoint","event","itemDragging","translate","itemDragEnd","_pagePoint","resetStyle","Draggable","DraggableRoot"],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RefObject } from '@lynx-js/react';
|
|
2
|
+
import type { Point } from '@lynx-js/lynx-ui-common';
|
|
3
|
+
import type { DraggableRef } from '@lynx-js/lynx-ui-draggable';
|
|
4
|
+
import type { MainThread } from '@lynx-js/types';
|
|
5
|
+
import type { SortableData } from './types';
|
|
6
|
+
interface SortableContextType<T = unknown> {
|
|
7
|
+
data: SortableData<T>[];
|
|
8
|
+
boundaryId?: string;
|
|
9
|
+
enableSorting: boolean;
|
|
10
|
+
updateItemSize: (sortingKey: string, size: number) => void;
|
|
11
|
+
setChildrenRef: (refI: RefObject<DraggableRef>, key: string) => void;
|
|
12
|
+
setChildrenMTSRef: (refI: RefObject<DraggableRef>, key: string) => void;
|
|
13
|
+
handleDragStart: (pagePoint: Point, sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => void;
|
|
14
|
+
handleDragMove: (delta: Point, sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => void;
|
|
15
|
+
handleDragEnd: (sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare const SortableContext: import("react").Context<SortableContextType<unknown>>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=SortableContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortableContext.d.ts","sourceRoot":"","sources":["../src/SortableContext.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,UAAU,mBAAmB,CAAC,CAAC,GAAG,OAAO;IACvC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,OAAO,CAAA;IACtB,cAAc,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1D,cAAc,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACpE,iBAAiB,EAAE,CACjB,IAAI,EAAE,SAAS,CAAC,YAAY,CAAC,EAC7B,GAAG,EAAE,MAAM,KACR,IAAI,CAAA;IACT,eAAe,EAAE,CACf,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,KACjD,IAAI,CAAA;IACT,cAAc,EAAE,CACd,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,KACjD,IAAI,CAAA;IACT,aAAa,EAAE,CACb,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,KACjD,IAAI,CAAA;CACV;AAED,eAAO,MAAM,eAAe,uDAS1B,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext } from "@lynx-js/react";
|
|
2
|
+
import { noop } from "@lynx-js/lynx-ui-common";
|
|
3
|
+
const SortableContext = createContext({
|
|
4
|
+
data: [],
|
|
5
|
+
enableSorting: true,
|
|
6
|
+
updateItemSize: noop,
|
|
7
|
+
setChildrenRef: noop,
|
|
8
|
+
setChildrenMTSRef: noop,
|
|
9
|
+
handleDragStart: noop,
|
|
10
|
+
handleDragMove: noop,
|
|
11
|
+
handleDragEnd: noop
|
|
12
|
+
});
|
|
13
|
+
export { SortableContext };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=SortableContext.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortableContext.jsx","sources":["webpack://@lynx-js/lynx-ui-sortable/./src/SortableContext.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext } from '@lynx-js/react'\nimport type { RefObject } from '@lynx-js/react'\n\nimport { noop } from '@lynx-js/lynx-ui-common'\nimport type { Point } from '@lynx-js/lynx-ui-common'\nimport type { DraggableRef } from '@lynx-js/lynx-ui-draggable'\nimport type { MainThread } from '@lynx-js/types'\n\nimport type { SortableData } from './types'\n\ninterface SortableContextType<T = unknown> {\n data: SortableData<T>[]\n boundaryId?: string\n enableSorting: boolean\n updateItemSize: (sortingKey: string, size: number) => void\n setChildrenRef: (refI: RefObject<DraggableRef>, key: string) => void\n setChildrenMTSRef: (\n refI: RefObject<DraggableRef>,\n key: string,\n ) => void\n handleDragStart: (\n pagePoint: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n handleDragMove: (\n delta: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n handleDragEnd: (\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n}\n\nexport const SortableContext = createContext<SortableContextType>({\n data: [],\n enableSorting: true,\n updateItemSize: noop,\n setChildrenRef: noop,\n setChildrenMTSRef: noop,\n handleDragStart: noop,\n handleDragMove: noop,\n handleDragEnd: noop,\n})\n"],"names":["SortableContext","createContext","noop"],"mappings":";;AAwCO,MAAMA,kBAAkBC,cAAmC;IAChE,MAAM,EAAE;IACR,eAAe;IACf,gBAAgBC;IAChB,gBAAgBA;IAChB,mBAAmBA;IACnB,iBAAiBA;IACjB,gBAAgBA;IAChB,eAAeA;AACjB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAEzE,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,GACb,MAAM,SAAS,CAAA"}
|
package/dist/index.jsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,mBAAmB,cAAc,CAAA"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
/**
|
|
3
|
+
* The data structure for each item in the Sortable component.
|
|
4
|
+
* @zh Sortable 组件中每个项目的数据结构。
|
|
5
|
+
*/
|
|
6
|
+
export interface SortableData<T> {
|
|
7
|
+
/**
|
|
8
|
+
* A function that returns the unique key for sorting.
|
|
9
|
+
* @Android
|
|
10
|
+
* @iOS
|
|
11
|
+
* @Harmony
|
|
12
|
+
* @zh 返回子节点用于排序的唯一键的函数。
|
|
13
|
+
*/
|
|
14
|
+
getSortingKey: () => string;
|
|
15
|
+
/**
|
|
16
|
+
* The original data item.
|
|
17
|
+
* @Android
|
|
18
|
+
* @iOS
|
|
19
|
+
* @Harmony
|
|
20
|
+
* @zh 原始数据项。
|
|
21
|
+
*/
|
|
22
|
+
dataItem: T;
|
|
23
|
+
}
|
|
24
|
+
export interface SortableRootProps<T> {
|
|
25
|
+
/**
|
|
26
|
+
* Whether to enable sorting.
|
|
27
|
+
* @defaultValue true
|
|
28
|
+
* @Android
|
|
29
|
+
* @iOS
|
|
30
|
+
* @Harmony
|
|
31
|
+
* @zh 是否启用排序。
|
|
32
|
+
*/
|
|
33
|
+
enableSorting?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Children, which is a function that receives an item and returns a ReactNode.
|
|
36
|
+
* @Android
|
|
37
|
+
* @iOS
|
|
38
|
+
* @Harmony
|
|
39
|
+
* @zh 子节点,是一个接收 item 并返回 ReactNode 的函数。
|
|
40
|
+
*/
|
|
41
|
+
children: (item: SortableData<T>) => ReactNode;
|
|
42
|
+
/**
|
|
43
|
+
* The data for the sortable list.
|
|
44
|
+
* @Android
|
|
45
|
+
* @iOS
|
|
46
|
+
* @Harmony
|
|
47
|
+
* @zh 拖拽列表的数据。
|
|
48
|
+
*/
|
|
49
|
+
data: SortableData<T>[];
|
|
50
|
+
/**
|
|
51
|
+
* The unique key of the item that acts as the boundary. If the item is dragged out of the boundary, the sorting will be canceled.
|
|
52
|
+
* @Android
|
|
53
|
+
* @iOS
|
|
54
|
+
* @Harmony
|
|
55
|
+
* @zh 作为边界限制的项的唯一键。如果项被拖出边界,排序将被取消。
|
|
56
|
+
*/
|
|
57
|
+
boundaryId?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Callback function that is triggered when sorting ends. The parameter is the sorted data.
|
|
60
|
+
* @Android
|
|
61
|
+
* @iOS
|
|
62
|
+
* @Harmony
|
|
63
|
+
* @zh 排序结束时触发的回调函数。参数为排序后的`data`。
|
|
64
|
+
*/
|
|
65
|
+
onSortEnd: (sortedData: SortableData<T>[]) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Callback function that is triggered when sorting starts.
|
|
68
|
+
* @Android
|
|
69
|
+
* @iOS
|
|
70
|
+
* @Harmony
|
|
71
|
+
* @zh 拖拽排序开始时触发的回调函数。
|
|
72
|
+
*/
|
|
73
|
+
onSortStart?: () => void;
|
|
74
|
+
/**
|
|
75
|
+
* Display debug logs. Open it when you find a bug.
|
|
76
|
+
* @defaultValue false
|
|
77
|
+
* @Android
|
|
78
|
+
* @iOS
|
|
79
|
+
* @Harmony
|
|
80
|
+
* @zh 显示调试日志,发现问题时开启。
|
|
81
|
+
*/
|
|
82
|
+
debugLog?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The item inside Sortable.
|
|
86
|
+
* @zh Sortable 的子项。
|
|
87
|
+
*/
|
|
88
|
+
export interface SortableItemProps {
|
|
89
|
+
/**
|
|
90
|
+
* className
|
|
91
|
+
* @zh 类名
|
|
92
|
+
* @Android
|
|
93
|
+
* @iOS
|
|
94
|
+
* @Harmony
|
|
95
|
+
*/
|
|
96
|
+
className?: string;
|
|
97
|
+
/**
|
|
98
|
+
* The unique key for sorting.
|
|
99
|
+
* @Android
|
|
100
|
+
* @iOS
|
|
101
|
+
* @Harmony
|
|
102
|
+
* @zh 用于排序的唯一键。
|
|
103
|
+
*/
|
|
104
|
+
sortingKey: string;
|
|
105
|
+
/**
|
|
106
|
+
* Children.
|
|
107
|
+
* @Android
|
|
108
|
+
* @iOS
|
|
109
|
+
* @Harmony
|
|
110
|
+
* @zh 子节点。
|
|
111
|
+
*/
|
|
112
|
+
children: ReactNode;
|
|
113
|
+
/**
|
|
114
|
+
* Specifies the underlying component to be used.
|
|
115
|
+
* @defaultValue 'Draggable'
|
|
116
|
+
* @Android
|
|
117
|
+
* @iOS
|
|
118
|
+
* @Harmony
|
|
119
|
+
* @zh 指定底层组件。若整个子节点区域均可拖动,使用默认值 'Draggable';否则使用 'DraggableRoot','DraggableRoot' 需与子节点 'DraggableArea' 一起使用。仅触摸其子节点 'DraggableArea' 时可拖动。
|
|
120
|
+
*/
|
|
121
|
+
as?: 'Draggable' | 'DraggableRoot';
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=index.docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../../src/types/index.docs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,MAAM,CAAA;IAC3B;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,CAAA;CACZ;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,SAAS,CAAA;IAC9C;;;;;;OAMG;IACH,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAA;IACvB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAA;IAClD;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;;;;OAOG;IACH,EAAE,CAAC,EAAE,WAAW,GAAG,eAAe,CAAA;CACnC"}
|
|
File without changes
|