@sanity/orderable-document-list 1.0.4 → 1.1.1
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 +1 -1
- package/README.md +56 -51
- package/lib/{src/index.d.ts → index.d.ts} +3 -0
- package/lib/index.esm.js +774 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +787 -1
- package/lib/index.js.map +1 -1
- package/package.json +42 -39
- package/src/Document.tsx +72 -40
- package/src/DocumentListQuery.tsx +75 -66
- package/src/DocumentListWrapper.tsx +10 -4
- package/src/DraggableList.tsx +37 -24
- package/src/OrderableDocumentList.tsx +3 -3
- package/src/desk-structure/orderableDocumentListDeskItem.ts +18 -7
- package/src/fields/orderRankOrdering.ts +1 -1
- package/src/helpers/reorderDocuments.ts +32 -10
- package/src/types.ts +3 -3
- package/v2-incompatible.js +2 -2
- package/src/Feedback.tsx +0 -12
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# @sanity/orderable-document-list
|
|
2
2
|
|
|
3
|
-
>This is a **Sanity Studio v3** plugin.
|
|
3
|
+
> This is a **Sanity Studio v3** plugin.
|
|
4
4
|
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/orderable-document-list/tree/studio-v2).
|
|
5
5
|
|
|
6
6
|
# What is it?
|
|
7
|
+
|
|
7
8
|
Drag-and-drop Document Ordering without leaving the Editing surface.
|
|
8
9
|
|
|
9
10
|

|
|
@@ -15,18 +16,19 @@ This plugin aims to be OS-like in that you can select and move multiple document
|
|
|
15
16
|
A Sanity Studio with [Desk Structure](https://www.sanity.io/docs/structure-builder-introduction) configured:
|
|
16
17
|
|
|
17
18
|
```ts
|
|
18
|
-
import {defineConfig} from
|
|
19
|
-
import {deskTool, StructureBuilder} from
|
|
19
|
+
import {defineConfig} from 'sanity'
|
|
20
|
+
import {deskTool, StructureBuilder} from 'sanity/desk'
|
|
20
21
|
|
|
21
22
|
export default defineConfig({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
//...
|
|
24
|
+
plugins: [
|
|
25
|
+
deskTool({
|
|
26
|
+
structure: (S, context) => {
|
|
27
|
+
/* Structure code */
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
28
31
|
})
|
|
29
|
-
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
## Installation
|
|
@@ -51,43 +53,45 @@ The config parameter requires `type`, `S` and `context`. It also accepts `title`
|
|
|
51
53
|
`S` and `context` are available in desk-tool structure callback, and should be forwarded as is:
|
|
52
54
|
|
|
53
55
|
```ts
|
|
54
|
-
import {defineConfig} from
|
|
55
|
-
import {deskTool, StructureBuilder} from
|
|
56
|
+
import {defineConfig} from 'sanity'
|
|
57
|
+
import {deskTool, StructureBuilder} from 'sanity/desk'
|
|
56
58
|
import {orderableDocumentListDeskItem} from '@sanity/orderable-document-list'
|
|
57
59
|
|
|
58
60
|
export default defineConfig({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
61
|
+
//...
|
|
62
|
+
plugins: [
|
|
63
|
+
deskTool({
|
|
64
|
+
structure: (S, context) => {
|
|
65
|
+
return S.list()
|
|
66
|
+
.title('Content')
|
|
67
|
+
.items([
|
|
68
|
+
// Minimum required configuration
|
|
69
|
+
orderableDocumentListDeskItem({type: 'category', S, context}),
|
|
70
|
+
|
|
71
|
+
// Optional configuration
|
|
72
|
+
orderableDocumentListDeskItem({
|
|
73
|
+
type: 'project',
|
|
74
|
+
title: 'Projects',
|
|
75
|
+
icon: Paint,
|
|
76
|
+
// Required if using multiple lists of the same 'type'
|
|
77
|
+
id: 'orderable-en-projects',
|
|
78
|
+
// See notes on adding a `filter` below
|
|
79
|
+
filter: `__i18n_lang == $lang`,
|
|
80
|
+
params: {
|
|
81
|
+
lang: 'en_US',
|
|
82
|
+
},
|
|
83
|
+
createIntent: false, // do not add an option for item creation
|
|
84
|
+
menuItems: [], // allow an array of `S.menuItem()` to be injected to orderable document list menu
|
|
85
|
+
// pass from the structure callback params above
|
|
86
|
+
S,
|
|
87
|
+
context,
|
|
88
|
+
}),
|
|
89
|
+
|
|
90
|
+
// ... all other desk items
|
|
91
|
+
])
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
91
95
|
})
|
|
92
96
|
```
|
|
93
97
|
|
|
@@ -120,7 +124,7 @@ export default defineConfig({
|
|
|
120
124
|
schema: {
|
|
121
125
|
types: (previousTypes) => {
|
|
122
126
|
return [
|
|
123
|
-
...previousTypes,
|
|
127
|
+
...previousTypes,
|
|
124
128
|
{
|
|
125
129
|
name: "category",
|
|
126
130
|
title: "Category",
|
|
@@ -146,10 +150,10 @@ export default defineConfig({
|
|
|
146
150
|
|
|
147
151
|
### 3. Generate initial Ranks
|
|
148
152
|
|
|
149
|
-
On first load, your Document list will not have any Order. You can select "Reset Order" from the menu in the top right of the list.
|
|
153
|
+
On first load, your Document list will not have any Order. You can select "Reset Order" from the menu in the top right of the list.
|
|
150
154
|
You can also re-run this at any time.
|
|
151
155
|
|
|
152
|
-
The `orderRankField` will query the last Document to set an `initialValue` to come after it.
|
|
156
|
+
The `orderRankField` will query the last Document to set an `initialValue` to come after it.
|
|
153
157
|
New Documents always start at the end of the Ordered list.
|
|
154
158
|
|
|
155
159
|
## Querying Ordered Documents
|
|
@@ -176,6 +180,7 @@ To get this first version out the door there are few configuration settings and
|
|
|
176
180
|
Feedback and PRs welcome :)
|
|
177
181
|
|
|
178
182
|
### Breaking change in the v3 version
|
|
183
|
+
|
|
179
184
|
`orderableDocumentListDeskItem` requires context from sanity config now.
|
|
180
185
|
See the examples above.
|
|
181
186
|
|
|
@@ -185,10 +190,6 @@ Uses [kvandakes](https://github.com/kvandake)'s [TypeScript implementation](http
|
|
|
185
190
|
|
|
186
191
|
Put simply it updates the position of an individual – or many – Documents in an ordered list without updating any others. It's fast.
|
|
187
192
|
|
|
188
|
-
## License
|
|
189
|
-
|
|
190
|
-
MIT-licensed. See LICENSE.
|
|
191
|
-
|
|
192
193
|
## Develop & test
|
|
193
194
|
|
|
194
195
|
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
|
|
@@ -203,3 +204,7 @@ Run ["CI & Release" workflow](https://github.com/sanity-io/orderable-document-li
|
|
|
203
204
|
Make sure to select the v3 branch and check "Release new version".
|
|
204
205
|
|
|
205
206
|
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
[MIT](LICENSE) © Sanity.io
|
|
@@ -2,6 +2,7 @@ import {ComponentType} from 'react'
|
|
|
2
2
|
import type {ConfigContext} from 'sanity'
|
|
3
3
|
import {FieldDefinitionBase} from 'sanity'
|
|
4
4
|
import {ListItem} from 'sanity/desk'
|
|
5
|
+
import {MenuItem} from 'sanity/desk'
|
|
5
6
|
import {SortOrdering} from 'sanity'
|
|
6
7
|
import {StringDefinition} from 'sanity'
|
|
7
8
|
import {StructureBuilder} from 'sanity/desk'
|
|
@@ -17,6 +18,8 @@ export declare interface OrderableListConfig {
|
|
|
17
18
|
icon?: ComponentType
|
|
18
19
|
params?: Record<string, unknown>
|
|
19
20
|
filter?: string
|
|
21
|
+
menuItems?: MenuItem[]
|
|
22
|
+
createIntent?: boolean
|
|
20
23
|
context: ConfigContext
|
|
21
24
|
S: StructureBuilder
|
|
22
25
|
}
|