sanity-plugin-workflow 1.0.0-beta.8 → 1.0.0-beta.9
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/lib/index.esm.js +68 -41
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +68 -41
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/DocumentCard/index.tsx +2 -4
- package/src/components/DocumentList.tsx +98 -55
- package/src/components/WorkflowTool.tsx +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-workflow",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "A demonstration of a custom content publishing workflow using Sanity.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -85,8 +85,8 @@
|
|
|
85
85
|
"react-dom": "^18.2.0",
|
|
86
86
|
"react-is": "^18.2.0",
|
|
87
87
|
"rimraf": "^4.1.2",
|
|
88
|
-
"sanity": "^3.
|
|
89
|
-
"semantic-release": "^20.1.
|
|
88
|
+
"sanity": "^3.9.1",
|
|
89
|
+
"semantic-release": "^20.1.3",
|
|
90
90
|
"typescript": "^5.0.0"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
@@ -141,10 +141,8 @@ export function DocumentCard(props: DocumentCardProps) {
|
|
|
141
141
|
<Flex align="center" justify="space-between" gap={1}>
|
|
142
142
|
<Box flex={1}>
|
|
143
143
|
<Preview
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// Like in the PTE, with no loading state
|
|
147
|
-
layout="block"
|
|
144
|
+
layout="default"
|
|
145
|
+
skipVisibilityCheck
|
|
148
146
|
value={item}
|
|
149
147
|
schemaType={schema.get(item._type) as SchemaType}
|
|
150
148
|
/>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {Draggable} from '@hello-pangea/dnd'
|
|
2
|
-
import {useVirtualizer} from '@tanstack/react-virtual'
|
|
3
|
-
import {useMemo, useRef} from 'react'
|
|
1
|
+
import {Draggable, DraggableStyle} from '@hello-pangea/dnd'
|
|
2
|
+
import {useVirtualizer, VirtualItem} from '@tanstack/react-virtual'
|
|
3
|
+
import {CSSProperties, useMemo, useRef} from 'react'
|
|
4
4
|
import {CurrentUser} from 'sanity'
|
|
5
5
|
import {UserExtended} from 'sanity-plugin-utils'
|
|
6
6
|
|
|
@@ -25,6 +25,35 @@ type DocumentListProps = {
|
|
|
25
25
|
userRoleCanDrop: boolean
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
function getStyle(
|
|
29
|
+
draggableStyle: DraggableStyle | undefined,
|
|
30
|
+
virtualItem: VirtualItem
|
|
31
|
+
): CSSProperties {
|
|
32
|
+
// Default transform required by tanstack virtual for positioning
|
|
33
|
+
let transform = `translateY(${virtualItem.start}px)`
|
|
34
|
+
|
|
35
|
+
// If a card is being dragged over, this card needs to move up or down
|
|
36
|
+
if (draggableStyle && draggableStyle.transform) {
|
|
37
|
+
// So get the transform value from beautiful-dnd
|
|
38
|
+
const draggableTransformY = parseInt(
|
|
39
|
+
draggableStyle.transform.split(',')[1].split('px')[0],
|
|
40
|
+
10
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
// And apply it to the card
|
|
44
|
+
transform = `translateY(${virtualItem.start + draggableTransformY}px)`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
position: 'absolute',
|
|
49
|
+
top: 0,
|
|
50
|
+
left: 0,
|
|
51
|
+
width: '100%',
|
|
52
|
+
height: `${virtualItem.size}px`,
|
|
53
|
+
transform,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
28
57
|
export default function DocumentList(props: DocumentListProps) {
|
|
29
58
|
const {
|
|
30
59
|
data = [],
|
|
@@ -48,15 +77,18 @@ export default function DocumentList(props: DocumentListProps) {
|
|
|
48
77
|
|
|
49
78
|
const parentRef = useRef(null)
|
|
50
79
|
|
|
51
|
-
const
|
|
52
|
-
count:
|
|
80
|
+
const virtualizer = useVirtualizer({
|
|
81
|
+
count: dataFiltered.length,
|
|
53
82
|
getScrollElement: () => parentRef.current,
|
|
54
83
|
getItemKey: (index) => dataFiltered[index]?._metadata?.documentId ?? index,
|
|
55
|
-
estimateSize: () =>
|
|
56
|
-
overscan:
|
|
84
|
+
estimateSize: () => 115,
|
|
85
|
+
overscan: 7,
|
|
86
|
+
measureElement: (element) => {
|
|
87
|
+
return element.getBoundingClientRect().height || 115
|
|
88
|
+
},
|
|
57
89
|
})
|
|
58
90
|
|
|
59
|
-
if (!data.length) {
|
|
91
|
+
if (!data.length || !dataFiltered.length) {
|
|
60
92
|
return null
|
|
61
93
|
}
|
|
62
94
|
|
|
@@ -66,61 +98,72 @@ export default function DocumentList(props: DocumentListProps) {
|
|
|
66
98
|
style={{
|
|
67
99
|
height: `100%`,
|
|
68
100
|
overflow: 'auto',
|
|
69
|
-
paddingTop: 1,
|
|
70
101
|
// Smooths scrollbar behaviour
|
|
71
102
|
overflowAnchor: 'none',
|
|
72
103
|
scrollBehavior: 'auto',
|
|
104
|
+
paddingTop: 1,
|
|
73
105
|
}}
|
|
74
106
|
>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
107
|
+
<div
|
|
108
|
+
style={{
|
|
109
|
+
height: `${virtualizer.getTotalSize()}px`,
|
|
110
|
+
width: '100%',
|
|
111
|
+
position: 'relative',
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
{virtualizer.getVirtualItems().map((virtualItem) => {
|
|
115
|
+
const item = dataFiltered[virtualItem.index]
|
|
79
116
|
|
|
80
|
-
|
|
81
|
-
return null
|
|
82
|
-
}
|
|
117
|
+
const {documentId, assignees} = item?._metadata ?? {}
|
|
83
118
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
119
|
+
const isInvalid = invalidDocumentIds.includes(documentId)
|
|
120
|
+
const meInAssignees = user?.id ? assignees?.includes(user.id) : false
|
|
121
|
+
const isDragDisabled =
|
|
122
|
+
patchingIds.includes(documentId) ||
|
|
123
|
+
!userRoleCanDrop ||
|
|
124
|
+
isInvalid ||
|
|
125
|
+
!(state.requireAssignment
|
|
126
|
+
? state.requireAssignment && meInAssignees
|
|
127
|
+
: true)
|
|
93
128
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
return (
|
|
130
|
+
<Draggable
|
|
131
|
+
key={virtualItem.key}
|
|
132
|
+
draggableId={documentId}
|
|
133
|
+
index={virtualItem.index}
|
|
134
|
+
isDragDisabled={isDragDisabled}
|
|
135
|
+
>
|
|
136
|
+
{(draggableProvided, draggableSnapshot) => (
|
|
137
|
+
<div
|
|
138
|
+
ref={draggableProvided.innerRef}
|
|
139
|
+
{...draggableProvided.draggableProps}
|
|
140
|
+
{...draggableProvided.dragHandleProps}
|
|
141
|
+
style={getStyle(
|
|
142
|
+
draggableProvided.draggableProps.style,
|
|
143
|
+
virtualItem
|
|
144
|
+
)}
|
|
145
|
+
>
|
|
146
|
+
<div
|
|
147
|
+
ref={virtualizer.measureElement}
|
|
148
|
+
data-index={virtualItem.index}
|
|
149
|
+
>
|
|
150
|
+
<DocumentCard
|
|
151
|
+
userRoleCanDrop={userRoleCanDrop}
|
|
152
|
+
isDragDisabled={isDragDisabled}
|
|
153
|
+
isPatching={patchingIds.includes(documentId)}
|
|
154
|
+
isDragging={draggableSnapshot.isDragging}
|
|
155
|
+
item={item}
|
|
156
|
+
toggleInvalidDocumentId={toggleInvalidDocumentId}
|
|
157
|
+
userList={userList}
|
|
158
|
+
states={states}
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
)}
|
|
163
|
+
</Draggable>
|
|
164
|
+
)
|
|
165
|
+
})}
|
|
166
|
+
</div>
|
|
124
167
|
</div>
|
|
125
168
|
)
|
|
126
169
|
}
|