@sanity/orderable-document-list 0.0.10 → 1.0.0-v3-studio.2

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.
Files changed (61) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +135 -55
  3. package/lib/index.d.ts +31 -0
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +827 -30
  6. package/lib/index.js.map +1 -1
  7. package/lib/index.modern.js +818 -0
  8. package/lib/index.modern.js.map +1 -0
  9. package/package.json +57 -23
  10. package/src/{Document.js → Document.tsx} +30 -27
  11. package/src/{DocumentListQuery.js → DocumentListQuery.tsx} +27 -23
  12. package/src/{DocumentListWrapper.js → DocumentListWrapper.tsx} +24 -29
  13. package/src/DraggableList.tsx +304 -0
  14. package/src/{Feedback.js → Feedback.tsx} +2 -7
  15. package/src/OrderableContext.ts +7 -0
  16. package/src/{OrderableDocumentList.js → OrderableDocumentList.tsx} +23 -12
  17. package/src/desk-structure/{orderableDocumentListDeskItem.js → orderableDocumentListDeskItem.ts} +24 -10
  18. package/src/fields/{orderRankField.js → orderRankField.ts} +12 -10
  19. package/src/fields/{orderRankOrdering.js → orderRankOrdering.ts} +0 -0
  20. package/src/helpers/client.ts +5 -0
  21. package/src/helpers/constants.ts +1 -0
  22. package/src/helpers/{initialRank.js → initialRank.ts} +2 -2
  23. package/src/helpers/{reorderDocuments.js → reorderDocuments.ts} +33 -44
  24. package/src/helpers/{resetOrder.js → resetOrder.ts} +3 -8
  25. package/src/index.ts +9 -0
  26. package/.babelrc +0 -3
  27. package/.eslintignore +0 -1
  28. package/.eslintrc.js +0 -50
  29. package/lib/Document.js +0 -101
  30. package/lib/Document.js.map +0 -1
  31. package/lib/DocumentListQuery.js +0 -163
  32. package/lib/DocumentListQuery.js.map +0 -1
  33. package/lib/DocumentListWrapper.js +0 -107
  34. package/lib/DocumentListWrapper.js.map +0 -1
  35. package/lib/DraggableList.js +0 -314
  36. package/lib/DraggableList.js.map +0 -1
  37. package/lib/Feedback.js +0 -31
  38. package/lib/Feedback.js.map +0 -1
  39. package/lib/OrderableContext.js +0 -15
  40. package/lib/OrderableContext.js.map +0 -1
  41. package/lib/OrderableDocumentList.js +0 -103
  42. package/lib/OrderableDocumentList.js.map +0 -1
  43. package/lib/desk-structure/orderableDocumentListDeskItem.js +0 -57
  44. package/lib/desk-structure/orderableDocumentListDeskItem.js.map +0 -1
  45. package/lib/fields/orderRankField.js +0 -64
  46. package/lib/fields/orderRankField.js.map +0 -1
  47. package/lib/fields/orderRankOrdering.js +0 -19
  48. package/lib/fields/orderRankOrdering.js.map +0 -1
  49. package/lib/helpers/constants.js +0 -9
  50. package/lib/helpers/constants.js.map +0 -1
  51. package/lib/helpers/initialRank.js +0 -18
  52. package/lib/helpers/initialRank.js.map +0 -1
  53. package/lib/helpers/reorderDocuments.js +0 -131
  54. package/lib/helpers/reorderDocuments.js.map +0 -1
  55. package/lib/helpers/resetOrder.js +0 -62
  56. package/lib/helpers/resetOrder.js.map +0 -1
  57. package/sanity.json +0 -7
  58. package/src/DraggableList.js +0 -276
  59. package/src/OrderableContext.js +0 -3
  60. package/src/helpers/constants.js +0 -1
  61. package/src/index.js +0 -5
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Simeon Griggs
3
+ Copyright (c) 2022 Simeon Griggs
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @sanity/orderable-document-list
2
2
 
3
+ > **NOTE**
4
+ >
5
+ > This is the **Sanity Studio v3 version** of @sanity/orderable-document-list.
6
+ >
7
+ > For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/orderable-document-list).
8
+
9
+ ## What is it?
3
10
  Drag-and-drop Document Ordering without leaving the Editing surface.
4
11
 
5
12
  ![2022-04-26 12 23 39](https://user-images.githubusercontent.com/9684022/165289621-dbd9d841-028e-40c7-be14-7398fcdb1210.gif)
@@ -8,46 +15,83 @@ This plugin aims to be OS-like in that you can select and move multiple document
8
15
 
9
16
  ## Requirements
10
17
 
11
- A Sanity Studio with [Desk Structure](https://www.sanity.io/docs/structure-builder-introduction) configured.
18
+ A Sanity Studio with [Desk Structure](https://www.sanity.io/docs/structure-builder-introduction) configured:
19
+
20
+ ```ts
21
+ import {createConfig} from "sanity";
22
+ import {deskTool, StructureBuilder} from "sanity/desk";
23
+
24
+ export default createConfig({
25
+ //...
26
+ plugins: [
27
+ deskTool({
28
+ structure: (S, context) => { /* Strucure code */},
29
+ })
30
+ ]
31
+ })
32
+
33
+ ```
12
34
 
13
35
  ## Installation
14
36
 
37
+ Run the following command in your studio directory
38
+
39
+ ```sh
40
+ npm install --save @sanity/orderable-document-list@studio-v3
15
41
  ```
16
- sanity install @sanity/orderable-document-list
42
+
43
+ or
44
+
45
+ ```sh
46
+ yarn add @sanity/orderable-document-list@studio-v3
17
47
  ```
18
48
 
19
- ### 1. Import the Document List into your Desk Structure
49
+ ## Usage
20
50
 
21
- The config parameter requires `type` and also accepts `title` and `icon`.
51
+ ### 1. Import the Document List into your Desk Structure
22
52
 
23
- ```js
24
- // ./src/desk-structure/index.js (or similar)
53
+ The config parameter requires `type`, `S` and `context`. It also accepts `title`, `icon`, `filter` and `params`.
54
+ `S` and `context` are available in desk-tool structure callback, and should be forwarded as is:
25
55
 
26
- import S from '@sanity/desk-tool/structure-builder'
56
+ ```ts
57
+ import {createConfig} from "sanity";
58
+ import {deskTool, StructureBuilder} from "sanity/desk";
27
59
  import {orderableDocumentListDeskItem} from '@sanity/orderable-document-list'
28
60
 
29
- export default () =>
30
- S.list()
31
- .title('Content')
32
- .items([
33
- // Minimum required configuration
34
- orderableDocumentListDeskItem({type: 'category'}),
35
-
36
- // Optional configuration
37
- orderableDocumentListDeskItem({
38
- type: 'project',
39
- title: 'Projects',
40
- icon: Paint
41
- // Required if using multiple lists of the same 'type'
42
- id: 'orderable-en-projects',
43
- // See notes on adding a `filter` below
44
- filter: `__i18n_lang == $lang`,
45
- params: {
46
- lang: 'en_US'
47
- },
48
- }),
49
-
50
- // ... all other desk items
61
+ export default createConfig({
62
+ //...
63
+ plugins: [
64
+ deskTool({
65
+ structure: (S, context) => {
66
+ return S.list()
67
+ .title('Content')
68
+ .items([
69
+ // Minimum required configuration
70
+ orderableDocumentListDeskItem({type: 'category', S, context}),
71
+
72
+ // Optional configuration
73
+ orderableDocumentListDeskItem({
74
+ type: 'project',
75
+ title: 'Projects',
76
+ icon: Paint,
77
+ // Required if using multiple lists of the same 'type'
78
+ id: 'orderable-en-projects',
79
+ // See notes on adding a `filter` below
80
+ filter: `__i18n_lang == $lang`,
81
+ params: {
82
+ lang: 'en_US'
83
+ },
84
+ // pass from the structure callback params above
85
+ S,
86
+ context
87
+ }),
88
+
89
+ // ... all other desk items
90
+ ])
91
+ },
92
+ })
93
+ ]
94
+ })
51
95
  ```
52
96
 
53
97
  **Caution: Adding a `filter`**
@@ -58,43 +102,58 @@ However, order ranks are still computed based on _all_ documents of the same `ty
58
102
 
59
103
  ### 2. Add the `orderRank` field to your schema(s).
60
104
 
61
- You must pass in the `type` of the schema, to create an `initialValue` value.
105
+ You must pass in the `type` of the schema and the schema `context`, to create an `initialValue` value.
106
+ Context is available in the schema callback, and should be forwarded as is.
62
107
 
63
108
  Additionally, pass in overrides for the field, such as making it visible by passing `hidden: false`.
64
109
 
65
110
  You cannot override the `name`, `type` or `initialValue` attributes.
66
111
 
67
- Example:
68
-
69
112
  ```js
70
- // ./src/schema/category.js (or similar)
71
-
72
- import {
73
- orderRankField,
74
- orderRankOrdering,
75
- } from '@sanity/orderable-document-list';
76
-
77
- export default {
78
- name: 'category',
79
- title: 'Category',
80
- type: 'document',
81
- // Optional: The plugin also exports a set of 'orderings' for use in other Document Lists
82
- orderings: [orderRankOrdering],
83
- fields: [
84
- // Minimum required configuration
85
- orderRankField({ type: 'category' }),
86
-
87
- // OR you can override _some_ of the field settings
88
- orderRankField({ type: 'category', hidden: false }),
89
-
90
- // ...all other fields
113
+ // sanity.config.js
114
+ import {createConfig} from "sanity";
115
+ import {deskTool, StructureBuilder} from "sanity/desk";
116
+ import {orderableDocumentListDeskItem} from '@sanity/orderable-document-list'
117
+
118
+ export default createConfig({
119
+ //...
120
+ plugins: [
121
+ deskTool({structure: (S, context) => {/* snip */}})
122
+ ],
123
+ schema: {
124
+ types: (previousTypes) => {
125
+ return [
126
+ ...previousTypes,
127
+ {
128
+ name: "category",
129
+ title: "Category",
130
+ type: "document",
131
+ // Optional: The plugin also exports a set of 'orderings' for use in other Document Lists
132
+ // https://www.sanity.io/docs/sort-orders
133
+ orderings: [orderRankOrdering],
134
+ fields: [
135
+ // Minimum required configuration
136
+ orderRankField({ type: "category" }),
137
+
138
+ // OR you can override _some_ of the field settings
139
+ orderRankField({ type: 'category', hidden: false }),
140
+
141
+ // ...all other fields
142
+ ],
143
+ },
144
+ ]
145
+ }
146
+ }
147
+ }
91
148
  ```
92
149
 
93
150
  ### 3. Generate initial Ranks
94
151
 
95
- 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. You can also re-run this at any time.
152
+ 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
+ You can also re-run this at any time.
96
154
 
97
- The `orderRankField` will query the last Document to set an `initialValue` to come after it. New Documents always start at the end of the Ordered list.
155
+ The `orderRankField` will query the last Document to set an `initialValue` to come after it.
156
+ New Documents always start at the end of the Ordered list.
98
157
 
99
158
  ## Querying Ordered Documents
100
159
 
@@ -113,6 +172,10 @@ To get this first version out the door there are few configuration settings and
113
172
 
114
173
  Feedback and PRs welcome :)
115
174
 
175
+ ### Breaking change in the v3 version
176
+ `orderableDocumentListDeskItem` requires context from sanity config now.
177
+ See the examples above.
178
+
116
179
  ## How it works
117
180
 
118
181
  Uses [kvandakes](https://github.com/kvandake)'s [TypeScript implementation](https://github.com/kvandake/lexorank-ts) of [Jira's Lexorank](https://www.youtube.com/watch?v=OjQv9xMoFbg) to create a "lexographical" Document order.
@@ -123,3 +186,20 @@ Put simply it updates the position of an individual – or many – Documents in
123
186
 
124
187
  MIT © Simeon Griggs
125
188
  See LICENSE
189
+
190
+ ## Develop & test
191
+
192
+ This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
193
+ with default configuration for build & watch scripts.
194
+
195
+ See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
196
+ on how to run this plugin with hotreload in the studio.d & watch
197
+
198
+ ## Release new version
199
+
200
+ Run ["CI & Release" workflow](https://github.com/sanity-io/orderable-document-list/actions).
201
+ Make sure to select the `v3` branch and check "Release new version".
202
+
203
+ Version will be automatically bumped based on [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) since the last release.
204
+
205
+ Semantic release will only release on configured branches, so it is safe to run release on any branch.
package/lib/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { ConfigContext } from "sanity";
2
+ import { ComponentType } from "react";
3
+ import { StructureBuilder } from "sanity/desk";
4
+ export interface RankFieldConfig {
5
+ type: string;
6
+ }
7
+ export const orderRankField: (config: RankFieldConfig) => {
8
+ type: "string";
9
+ name: "orderRank";
10
+ } & Omit<import("sanity").Schema.StringDefinition, "preview"> & import("sanity").Schema.FieldBase & import("@sanity/types/lib/dts/src/schema/defineTypes").WidenValidation & import("@sanity/types/lib/dts/src/schema/defineTypes").WidenInitialValue;
11
+ export const orderRankOrdering: {
12
+ title: string;
13
+ name: string;
14
+ by: {
15
+ field: "orderRank";
16
+ direction: string;
17
+ }[];
18
+ };
19
+ export interface OrderableListConfig {
20
+ type: string;
21
+ id?: string;
22
+ title?: string;
23
+ icon?: ComponentType;
24
+ params?: Record<string, unknown>;
25
+ filter?: string;
26
+ context: ConfigContext;
27
+ S: StructureBuilder;
28
+ }
29
+ export function orderableDocumentListDeskItem(config: OrderableListConfig): import("sanity/desk").ListItem;
30
+
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AEMA;IACE,IAAI,EAAE,MAAM,CAAA;CACb;AAED,OAAO,MAAM,yBAA0B,eAAe;;;qPA0BrD,CAAA;AClCD,OAAO,MAAM;;;;;;;CAIZ,CAAA;AWCD;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,aAAa,CAAA;IACtB,CAAC,EAAE,gBAAgB,CAAA;CACpB;AAED,8CAA8C,MAAM,EAAE,mBAAmB,kCA2CxE","sources":["src/src/helpers/constants.ts","src/src/helpers/initialRank.ts","src/src/fields/orderRankField.ts","src/src/fields/orderRankOrdering.ts","src/src/OrderableContext.ts","src/src/Document.tsx","src/src/helpers/reorderDocuments.ts","src/src/helpers/client.ts","src/src/DraggableList.tsx","src/src/Feedback.tsx","src/src/DocumentListQuery.tsx","src/src/DocumentListWrapper.tsx","src/src/helpers/resetOrder.ts","src/src/OrderableDocumentList.tsx","src/src/desk-structure/orderableDocumentListDeskItem.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"import {orderRankField, RankFieldConfig} from './fields/orderRankField'\nimport {orderRankOrdering} from './fields/orderRankOrdering'\nimport {\n orderableDocumentListDeskItem,\n type OrderableListConfig,\n} from './desk-structure/orderableDocumentListDeskItem'\n\nexport type {OrderableListConfig, RankFieldConfig}\nexport {orderRankField, orderRankOrdering, orderableDocumentListDeskItem}\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../"}