@sanity/assist 5.0.4 → 6.0.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/LICENSE +1 -1
- package/README.md +28 -254
- package/dist/index.d.ts +322 -410
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3181 -2649
- package/dist/index.js.map +1 -1
- package/package.json +38 -78
- package/dist/index.cjs +0 -4239
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -791
- package/sanity.json +0 -8
- package/src/_lib/connector/ConnectFromRegion.tsx +0 -25
- package/src/_lib/connector/ConnectToRegion.tsx +0 -23
- package/src/_lib/connector/ConnectorRegion.tsx +0 -24
- package/src/_lib/connector/ConnectorsProvider.tsx +0 -20
- package/src/_lib/connector/ConnectorsStore.ts +0 -122
- package/src/_lib/connector/ConnectorsStoreContext.ts +0 -5
- package/src/_lib/connector/helpers.ts +0 -5
- package/src/_lib/connector/index.ts +0 -9
- package/src/_lib/connector/mapConnectorToLine.ts +0 -83
- package/src/_lib/connector/types.ts +0 -56
- package/src/_lib/connector/useConnectorsStore.ts +0 -14
- package/src/_lib/connector/useRegionRects.ts +0 -142
- package/src/_lib/fixedListenQuery.ts +0 -101
- package/src/_lib/form/DocumentForm.tsx +0 -201
- package/src/_lib/form/constants.ts +0 -1
- package/src/_lib/form/helpers.ts +0 -32
- package/src/_lib/form/index.ts +0 -1
- package/src/_lib/randomKey.ts +0 -29
- package/src/_lib/useListeningQuery.ts +0 -62
- package/src/_lib/usePrevious.ts +0 -9
- package/src/assistConnectors/AssistConnectorsOverlay.tsx +0 -133
- package/src/assistConnectors/ConnectorPath.tsx +0 -63
- package/src/assistConnectors/draw/arrowPath.ts +0 -9
- package/src/assistConnectors/draw/connectorPath.ts +0 -142
- package/src/assistConnectors/index.ts +0 -1
- package/src/assistDocument/AssistDocumentContext.tsx +0 -51
- package/src/assistDocument/AssistDocumentContextProvider.tsx +0 -17
- package/src/assistDocument/AssistDocumentInput.tsx +0 -61
- package/src/assistDocument/AssistDocumentLayout.tsx +0 -12
- package/src/assistDocument/RequestRunInstructionProvider.tsx +0 -61
- package/src/assistDocument/components/AssistDocumentForm.tsx +0 -287
- package/src/assistDocument/components/AssistTypeContext.tsx +0 -7
- package/src/assistDocument/components/FieldRefPreview.tsx +0 -26
- package/src/assistDocument/components/InstructionsArrayField.tsx +0 -8
- package/src/assistDocument/components/InstructionsArrayInput.tsx +0 -27
- package/src/assistDocument/components/SelectedFieldContext.tsx +0 -10
- package/src/assistDocument/components/generic/HiddenFieldTitle.tsx +0 -5
- package/src/assistDocument/components/helpers.ts +0 -21
- package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +0 -32
- package/src/assistDocument/components/instruction/FieldRefInput.tsx +0 -54
- package/src/assistDocument/components/instruction/InstructionInput.tsx +0 -89
- package/src/assistDocument/components/instruction/InstructionOutputField.tsx +0 -46
- package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +0 -206
- package/src/assistDocument/components/instruction/PromptInput.tsx +0 -59
- package/src/assistDocument/components/instruction/appearance/IconInput.tsx +0 -46
- package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +0 -37
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +0 -127
- package/src/assistDocument/hooks/useDocumentState.ts +0 -6
- package/src/assistDocument/hooks/useInstructionToaster.tsx +0 -75
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +0 -99
- package/src/assistDocument/index.ts +0 -1
- package/src/assistFormComponents/AssistField.tsx +0 -63
- package/src/assistFormComponents/AssistFormBlock.tsx +0 -31
- package/src/assistFormComponents/AssistInlineFormBlock.tsx +0 -13
- package/src/assistFormComponents/AssistItem.tsx +0 -21
- package/src/assistFormComponents/validation/listItem.tsx +0 -63
- package/src/assistFormComponents/validation/validationList.tsx +0 -90
- package/src/assistInspector/AssistInspector.tsx +0 -419
- package/src/assistInspector/FieldAutocomplete.tsx +0 -146
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +0 -262
- package/src/assistInspector/constants.ts +0 -1
- package/src/assistInspector/helpers.ts +0 -211
- package/src/assistInspector/index.ts +0 -27
- package/src/assistLayout/AiAssistanceConfigContext.tsx +0 -32
- package/src/assistLayout/AiAssistanceConfigProvider.tsx +0 -98
- package/src/assistLayout/AssistLayout.tsx +0 -39
- package/src/assistLayout/RunInstructionProvider.tsx +0 -278
- package/src/assistLayout/fieldRefCache.tsx +0 -34
- package/src/assistTypes.ts +0 -83
- package/src/components/AssistFeatureBadge.tsx +0 -9
- package/src/components/FadeInContent.tsx +0 -40
- package/src/components/HideReferenceChangedBannerInput.tsx +0 -25
- package/src/components/ImageContext.tsx +0 -85
- package/src/components/SafeValueInput.tsx +0 -74
- package/src/components/TimeAgo.tsx +0 -18
- package/src/constants.ts +0 -20
- package/src/fieldActions/PrivateIcon.tsx +0 -20
- package/src/fieldActions/assistFieldActions.tsx +0 -320
- package/src/fieldActions/customFieldActions.tsx +0 -333
- package/src/fieldActions/generateCaptionActions.tsx +0 -77
- package/src/fieldActions/generateImageActions.tsx +0 -58
- package/src/fieldActions/useUserInput.ts +0 -107
- package/src/globals.d.ts +0 -4
- package/src/helpers/assistSupported.ts +0 -49
- package/src/helpers/conditionalMembers.test.ts +0 -319
- package/src/helpers/conditionalMembers.ts +0 -134
- package/src/helpers/ids.test.ts +0 -28
- package/src/helpers/ids.ts +0 -23
- package/src/helpers/misc.ts +0 -25
- package/src/helpers/styleguide.ts +0 -24
- package/src/helpers/typeUtils.ts +0 -60
- package/src/helpers/useAssistSupported.ts +0 -8
- package/src/index.ts +0 -26
- package/src/onboarding/FirstAssistedPathProvider.tsx +0 -30
- package/src/onboarding/InspectorOnboarding.tsx +0 -47
- package/src/onboarding/onboardingStore.ts +0 -32
- package/src/plugin.tsx +0 -162
- package/src/presence/AiFieldPresence.tsx +0 -28
- package/src/presence/AssistAvatar.tsx +0 -96
- package/src/presence/AssistDocumentPresence.tsx +0 -50
- package/src/presence/useAssistPresence.ts +0 -64
- package/src/schemas/assistDocumentSchema.tsx +0 -497
- package/src/schemas/contextDocumentSchema.tsx +0 -57
- package/src/schemas/index.ts +0 -69
- package/src/schemas/serialize/SchemTypeTool.tsx +0 -103
- package/src/schemas/serialize/schemaUtils.ts +0 -38
- package/src/schemas/serialize/serializeSchema.test.ts +0 -819
- package/src/schemas/serialize/serializeSchema.ts +0 -224
- package/src/schemas/serializedSchemaTypeSchema.ts +0 -60
- package/src/schemas/typeDefExtensions.ts +0 -127
- package/src/translate/FieldTranslationProvider.tsx +0 -382
- package/src/translate/getLanguageParams.ts +0 -26
- package/src/translate/languageStore.ts +0 -18
- package/src/translate/paths.test.ts +0 -181
- package/src/translate/paths.ts +0 -183
- package/src/translate/translateActions.tsx +0 -205
- package/src/translate/types.ts +0 -197
- package/src/types.ts +0 -220
- package/src/useApiClient.ts +0 -338
- package/v2-incompatible.js +0 -11
package/sanity.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {HTMLProps, useEffect, useState} from 'react'
|
|
2
|
-
|
|
3
|
-
import {ConnectorRegion} from './ConnectorRegion'
|
|
4
|
-
import {ConnectorRegionRects} from './types'
|
|
5
|
-
import {useConnectorsStore} from './useConnectorsStore'
|
|
6
|
-
|
|
7
|
-
export function ConnectFromRegion(
|
|
8
|
-
props: {_key: string; zIndex: number} & HTMLProps<HTMLDivElement>,
|
|
9
|
-
) {
|
|
10
|
-
const {children, _key: key, zIndex, ...restProps} = props
|
|
11
|
-
const store = useConnectorsStore()
|
|
12
|
-
const [rects, setRects] = useState<ConnectorRegionRects | null>(null)
|
|
13
|
-
|
|
14
|
-
useEffect(() => store.from.subscribe(key, {zIndex}), [key, store, zIndex])
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (rects) store.from.next(key, rects)
|
|
18
|
-
}, [key, rects, store])
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<ConnectorRegion {...restProps} onRectsChange={setRects}>
|
|
22
|
-
{children}
|
|
23
|
-
</ConnectorRegion>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {HTMLProps, useEffect, useState} from 'react'
|
|
2
|
-
|
|
3
|
-
import {ConnectorRegion} from './ConnectorRegion'
|
|
4
|
-
import {ConnectorRegionRects} from './types'
|
|
5
|
-
import {useConnectorsStore} from './useConnectorsStore'
|
|
6
|
-
|
|
7
|
-
export function ConnectToRegion(props: {_key: string} & HTMLProps<HTMLDivElement>) {
|
|
8
|
-
const {children, _key: key, ...restProps} = props
|
|
9
|
-
const aiConnectors = useConnectorsStore()
|
|
10
|
-
const [rects, setRects] = useState<ConnectorRegionRects | null>(null)
|
|
11
|
-
|
|
12
|
-
useEffect(() => aiConnectors.to.subscribe(key), [aiConnectors, key])
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (rects) aiConnectors.to.next(key, rects)
|
|
16
|
-
}, [aiConnectors, key, rects])
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<ConnectorRegion {...restProps} onRectsChange={setRects}>
|
|
20
|
-
{children}
|
|
21
|
-
</ConnectorRegion>
|
|
22
|
-
)
|
|
23
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {HTMLProps, useEffect} from 'react'
|
|
2
|
-
|
|
3
|
-
import {ConnectorRegionRects} from './types'
|
|
4
|
-
import {useRegionRects} from './useRegionRects'
|
|
5
|
-
|
|
6
|
-
export function ConnectorRegion(
|
|
7
|
-
props: {
|
|
8
|
-
onRectsChange?: (rects: ConnectorRegionRects | null) => void
|
|
9
|
-
} & HTMLProps<HTMLDivElement>,
|
|
10
|
-
) {
|
|
11
|
-
const {children, onRectsChange, ...restProps} = props
|
|
12
|
-
|
|
13
|
-
const {bounds, element, ref} = useRegionRects()
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
onRectsChange?.(bounds && element ? {bounds, element} : null)
|
|
17
|
-
}, [bounds, element, onRectsChange])
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<div {...restProps} ref={ref}>
|
|
21
|
-
{children}
|
|
22
|
-
</div>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {ReactNode, useEffect, useMemo} from 'react'
|
|
2
|
-
|
|
3
|
-
import {ConnectorsStore, createConnectorsStore} from './ConnectorsStore'
|
|
4
|
-
import {ConnectorsStoreContext} from './ConnectorsStoreContext'
|
|
5
|
-
import {Connector} from './types'
|
|
6
|
-
|
|
7
|
-
export function ConnectorsProvider(props: {
|
|
8
|
-
children?: ReactNode
|
|
9
|
-
onConnectorsChange?: (connectors: Connector[]) => void
|
|
10
|
-
}) {
|
|
11
|
-
const {children, onConnectorsChange} = props
|
|
12
|
-
const store: ConnectorsStore = useMemo(() => createConnectorsStore(), [])
|
|
13
|
-
|
|
14
|
-
useEffect(
|
|
15
|
-
() => onConnectorsChange && store.connectors.subscribe(onConnectorsChange),
|
|
16
|
-
[onConnectorsChange, store],
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
return <ConnectorsStoreContext.Provider value={store}>{children}</ConnectorsStoreContext.Provider>
|
|
20
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {Connector, ConnectorRegionRects} from './types'
|
|
2
|
-
|
|
3
|
-
export interface ConnectorsStore {
|
|
4
|
-
connectors: {
|
|
5
|
-
subscribe: (observer: (connectors: Connector[]) => void) => () => void
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
from: {
|
|
9
|
-
subscribe: (key: string, payload?: Record<string, unknown>) => () => void
|
|
10
|
-
next: (key: string, rects: ConnectorRegionRects) => void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
to: {
|
|
14
|
-
subscribe: (key: string, payload?: Record<string, unknown>) => () => void
|
|
15
|
-
next: (key: string, rects: ConnectorRegionRects) => void
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function createConnectorsStore(): ConnectorsStore {
|
|
20
|
-
const configKeys: string[] = []
|
|
21
|
-
const fieldKeys: string[] = []
|
|
22
|
-
|
|
23
|
-
const channels = {
|
|
24
|
-
from: new Map<string, ConnectorRegionRects | null>(),
|
|
25
|
-
to: new Map<string, ConnectorRegionRects | null>(),
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const payloads = {
|
|
29
|
-
from: new Map<string, Record<string, unknown> | undefined>(),
|
|
30
|
-
to: new Map<string, Record<string, unknown> | undefined>(),
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const observers: ((connectors: Connector[]) => void)[] = []
|
|
34
|
-
|
|
35
|
-
function notifyObservers() {
|
|
36
|
-
const connectors: Connector[] = []
|
|
37
|
-
|
|
38
|
-
for (const key of configKeys) {
|
|
39
|
-
const toRects = channels.to.get(key)
|
|
40
|
-
const toPayload = payloads.from.get(key)
|
|
41
|
-
|
|
42
|
-
const fromRects = channels.from.get(key)
|
|
43
|
-
const fromPayload = payloads.from.get(key)
|
|
44
|
-
|
|
45
|
-
if (toRects && fromRects) {
|
|
46
|
-
connectors.push({
|
|
47
|
-
key,
|
|
48
|
-
from: {...fromRects, payload: fromPayload},
|
|
49
|
-
to: {...toRects, payload: toPayload},
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
for (const observer of observers) {
|
|
55
|
-
observer(connectors)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
to: {
|
|
61
|
-
subscribe(key, payload) {
|
|
62
|
-
channels.to.set(key, null)
|
|
63
|
-
payloads.to.set(key, payload)
|
|
64
|
-
|
|
65
|
-
configKeys.push(key)
|
|
66
|
-
|
|
67
|
-
return () => {
|
|
68
|
-
channels.to.delete(key)
|
|
69
|
-
payloads.to.delete(key)
|
|
70
|
-
|
|
71
|
-
const idx = configKeys.indexOf(key)
|
|
72
|
-
|
|
73
|
-
if (idx > -1) configKeys.splice(idx, 1)
|
|
74
|
-
|
|
75
|
-
notifyObservers()
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
next(key, rects) {
|
|
79
|
-
channels.to.set(key, rects)
|
|
80
|
-
|
|
81
|
-
if (fieldKeys.includes(key)) notifyObservers()
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
connectors: {
|
|
86
|
-
subscribe(observer) {
|
|
87
|
-
observers.push(observer)
|
|
88
|
-
|
|
89
|
-
return () => {
|
|
90
|
-
const idx = observers.indexOf(observer)
|
|
91
|
-
|
|
92
|
-
if (idx > -1) observers.splice(idx, 1)
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
from: {
|
|
98
|
-
subscribe(key, payload) {
|
|
99
|
-
channels.from.set(key, null)
|
|
100
|
-
payloads.from.set(key, payload)
|
|
101
|
-
|
|
102
|
-
fieldKeys.push(key)
|
|
103
|
-
|
|
104
|
-
return () => {
|
|
105
|
-
channels.from.delete(key)
|
|
106
|
-
payloads.from.delete(key)
|
|
107
|
-
|
|
108
|
-
const idx = fieldKeys.indexOf(key)
|
|
109
|
-
|
|
110
|
-
if (idx > -1) fieldKeys.splice(idx, 1)
|
|
111
|
-
|
|
112
|
-
notifyObservers()
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
next(key, rects) {
|
|
116
|
-
channels.from.set(key, rects)
|
|
117
|
-
|
|
118
|
-
if (configKeys.includes(key)) notifyObservers()
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './ConnectFromRegion'
|
|
2
|
-
export * from './ConnectorRegion'
|
|
3
|
-
export * from './ConnectorsProvider'
|
|
4
|
-
export * from './ConnectorsStore'
|
|
5
|
-
export * from './ConnectorsStoreContext'
|
|
6
|
-
export * from './ConnectToRegion'
|
|
7
|
-
export * from './mapConnectorToLine'
|
|
8
|
-
export * from './types'
|
|
9
|
-
export * from './useConnectorsStore'
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConnectorLine,
|
|
3
|
-
ConnectorLinePoint,
|
|
4
|
-
ConnectorOptions,
|
|
5
|
-
ConnectorRegionRects,
|
|
6
|
-
Rect,
|
|
7
|
-
} from './types'
|
|
8
|
-
|
|
9
|
-
function getConnectorLinePoint(
|
|
10
|
-
options: ConnectorOptions,
|
|
11
|
-
rect: Rect,
|
|
12
|
-
bounds: Rect,
|
|
13
|
-
): ConnectorLinePoint {
|
|
14
|
-
const centerY = rect.y + rect.h / 2
|
|
15
|
-
const isAbove = rect.y + rect.h < bounds.y + options.arrow.marginY
|
|
16
|
-
const isBelow = rect.y > bounds.y + bounds.h - options.arrow.marginY
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
bounds,
|
|
20
|
-
x: rect.x,
|
|
21
|
-
y: centerY,
|
|
22
|
-
centerY,
|
|
23
|
-
startY: rect.y + options.path.marginY,
|
|
24
|
-
endY: rect.y + rect.h - options.path.marginY,
|
|
25
|
-
isAbove,
|
|
26
|
-
isBelow,
|
|
27
|
-
outOfBounds: isAbove || isBelow,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function mapConnectorToLine(
|
|
32
|
-
options: ConnectorOptions,
|
|
33
|
-
connector: {from: ConnectorRegionRects; to: ConnectorRegionRects},
|
|
34
|
-
): ConnectorLine {
|
|
35
|
-
const fromBounds: Rect = {
|
|
36
|
-
y: connector.from.bounds.y + options.arrow.threshold,
|
|
37
|
-
// bottom: connector.from.bounds.y + connector.from.bounds.h - options.arrow.threshold,
|
|
38
|
-
x: connector.from.bounds.x,
|
|
39
|
-
// right: connector.from.bounds.x + connector.from.bounds.w,
|
|
40
|
-
w: connector.from.bounds.w,
|
|
41
|
-
h: connector.from.bounds.h - options.arrow.threshold * 2,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const from = getConnectorLinePoint(options, connector.from.element, fromBounds)
|
|
45
|
-
from.x = connector.from.element.x + connector.from.element.w // + 1
|
|
46
|
-
|
|
47
|
-
const fromBottom = fromBounds.y + fromBounds.h
|
|
48
|
-
|
|
49
|
-
const toBounds: Rect = {
|
|
50
|
-
y: connector.to.bounds.y + options.arrow.threshold,
|
|
51
|
-
// bottom: connector.to.bounds.y + connector.to.bounds.h - options.arrow.threshold,
|
|
52
|
-
x: connector.to.bounds.x,
|
|
53
|
-
// right: connector.to.bounds.x + connector.to.bounds.w,
|
|
54
|
-
w: connector.to.bounds.w,
|
|
55
|
-
h: connector.to.bounds.h - options.arrow.threshold * 2,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const toBottom = toBounds.y + toBounds.h
|
|
59
|
-
|
|
60
|
-
const to = getConnectorLinePoint(options, connector.to.element, toBounds)
|
|
61
|
-
|
|
62
|
-
const maxStartY = Math.max(to.startY, from.startY)
|
|
63
|
-
|
|
64
|
-
// Align from <-> to vertically
|
|
65
|
-
from.y = Math.min(maxStartY, from.endY)
|
|
66
|
-
if (from.y < toBounds.y) {
|
|
67
|
-
from.y = Math.min(toBounds.y, from.endY)
|
|
68
|
-
} else if (from.y > toBottom) {
|
|
69
|
-
from.y = Math.max(toBottom, from.startY)
|
|
70
|
-
}
|
|
71
|
-
to.y = Math.min(maxStartY, to.endY)
|
|
72
|
-
if (to.y < fromBounds.y) {
|
|
73
|
-
to.y = Math.min(fromBounds.y, to.endY)
|
|
74
|
-
} else if (to.y > fromBottom) {
|
|
75
|
-
to.y = Math.max(fromBottom, to.startY)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Keep within bounds
|
|
79
|
-
from.y = Math.min(Math.max(from.y, fromBounds.y), fromBottom)
|
|
80
|
-
to.y = Math.min(Math.max(to.y, toBounds.y), toBottom)
|
|
81
|
-
|
|
82
|
-
return {from, to}
|
|
83
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export interface Rect {
|
|
2
|
-
x: number
|
|
3
|
-
y: number
|
|
4
|
-
w: number
|
|
5
|
-
h: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface Scroll {
|
|
9
|
-
x: number
|
|
10
|
-
y: number
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface ConnectorLinePoint {
|
|
14
|
-
bounds: Rect
|
|
15
|
-
x: number
|
|
16
|
-
y: number
|
|
17
|
-
startY: number
|
|
18
|
-
centerY: number
|
|
19
|
-
endY: number
|
|
20
|
-
isAbove: boolean
|
|
21
|
-
isBelow: boolean
|
|
22
|
-
outOfBounds: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface ConnectorLine {
|
|
26
|
-
from: ConnectorLinePoint
|
|
27
|
-
to: ConnectorLinePoint
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface ConnectorOptions {
|
|
31
|
-
arrow: {
|
|
32
|
-
marginX: number
|
|
33
|
-
marginY: number
|
|
34
|
-
size: number
|
|
35
|
-
threshold: number
|
|
36
|
-
}
|
|
37
|
-
divider: {
|
|
38
|
-
offsetX: number
|
|
39
|
-
}
|
|
40
|
-
path: {
|
|
41
|
-
cornerRadius: number
|
|
42
|
-
marginY: number
|
|
43
|
-
strokeWidth: number
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface ConnectorRegionRects {
|
|
48
|
-
bounds: Rect
|
|
49
|
-
element: Rect
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface Connector {
|
|
53
|
-
key: string
|
|
54
|
-
from: ConnectorRegionRects & {payload?: Record<string, unknown>}
|
|
55
|
-
to: ConnectorRegionRects & {payload?: Record<string, unknown>}
|
|
56
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {useContext} from 'react'
|
|
2
|
-
|
|
3
|
-
import {ConnectorsStore} from './ConnectorsStore'
|
|
4
|
-
import {ConnectorsStoreContext} from './ConnectorsStoreContext'
|
|
5
|
-
|
|
6
|
-
export function useConnectorsStore(): ConnectorsStore {
|
|
7
|
-
const store = useContext(ConnectorsStoreContext)
|
|
8
|
-
|
|
9
|
-
if (!store) {
|
|
10
|
-
throw new Error('Missing connectors store context')
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return store
|
|
14
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import {useEffect, useMemo, useRef, useState} from 'react'
|
|
2
|
-
|
|
3
|
-
import {hasOverflowScroll} from './helpers'
|
|
4
|
-
import {Rect, Scroll} from './types'
|
|
5
|
-
|
|
6
|
-
export function useRegionRects() {
|
|
7
|
-
const ref = useRef<HTMLDivElement>(null)
|
|
8
|
-
|
|
9
|
-
const [relativeBoundsRect, setRelativeBoundsRect] = useState<Rect | null>(null)
|
|
10
|
-
const [relativeElementRect, setRelativeElementRect] = useState<Rect | null>(null)
|
|
11
|
-
const [boundsScroll, setBoundsScroll] = useState<Scroll>({x: 0, y: 0})
|
|
12
|
-
const [scroll, setScroll] = useState<Scroll>({x: 0, y: 0})
|
|
13
|
-
|
|
14
|
-
const boundsScrollXRef = useRef(0)
|
|
15
|
-
const boundsScrollYRef = useRef(0)
|
|
16
|
-
|
|
17
|
-
const elementScrollXRef = useRef(0)
|
|
18
|
-
const elementScrollYRef = useRef(0)
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
const el = ref.current
|
|
22
|
-
|
|
23
|
-
if (!el) return undefined
|
|
24
|
-
|
|
25
|
-
const scrollParents: HTMLElement[] = []
|
|
26
|
-
let parent = el.parentElement
|
|
27
|
-
|
|
28
|
-
while (parent && parent !== document.body) {
|
|
29
|
-
if (
|
|
30
|
-
hasOverflowScroll(parent)
|
|
31
|
-
// || parent.scrollHeight > parent.clientHeight
|
|
32
|
-
) {
|
|
33
|
-
scrollParents.push(parent)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
parent = parent.parentElement
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function handleResize() {
|
|
40
|
-
const scrollParent = scrollParents[0]
|
|
41
|
-
|
|
42
|
-
const boundsRect = scrollParent?.getBoundingClientRect() || {
|
|
43
|
-
x: 0,
|
|
44
|
-
y: 0,
|
|
45
|
-
width: window.innerWidth,
|
|
46
|
-
height: window.innerHeight,
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const domRect = el!.getBoundingClientRect()
|
|
50
|
-
|
|
51
|
-
setRelativeBoundsRect({
|
|
52
|
-
x: boundsRect.x + boundsScrollXRef.current,
|
|
53
|
-
y: boundsRect.y + boundsScrollYRef.current,
|
|
54
|
-
w: boundsRect.width,
|
|
55
|
-
h: boundsRect.height,
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
setRelativeElementRect({
|
|
59
|
-
x: domRect.x + elementScrollXRef.current,
|
|
60
|
-
y: domRect.y + elementScrollYRef.current,
|
|
61
|
-
w: domRect.width,
|
|
62
|
-
h: domRect.height,
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function handleScroll() {
|
|
67
|
-
let scrollX = window.scrollX
|
|
68
|
-
let scrollY = window.scrollY
|
|
69
|
-
|
|
70
|
-
for (const scrollParent of scrollParents) {
|
|
71
|
-
scrollX += scrollParent.scrollLeft
|
|
72
|
-
scrollY += scrollParent.scrollTop
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const scrollParent = scrollParents[0]
|
|
76
|
-
|
|
77
|
-
boundsScrollXRef.current = scrollX - (scrollParent?.scrollLeft || window.scrollX)
|
|
78
|
-
|
|
79
|
-
boundsScrollYRef.current = scrollY - (scrollParent?.scrollTop || window.scrollY)
|
|
80
|
-
|
|
81
|
-
setBoundsScroll({
|
|
82
|
-
x: boundsScrollXRef.current,
|
|
83
|
-
y: boundsScrollYRef.current,
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
elementScrollXRef.current = scrollX
|
|
87
|
-
elementScrollYRef.current = scrollY
|
|
88
|
-
|
|
89
|
-
setScroll({x: scrollX, y: scrollY})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
window.addEventListener('scroll', handleScroll, {passive: true})
|
|
93
|
-
|
|
94
|
-
const ro = new ResizeObserver(handleResize)
|
|
95
|
-
|
|
96
|
-
ro.observe(el)
|
|
97
|
-
|
|
98
|
-
for (const scrollParent of scrollParents) {
|
|
99
|
-
scrollParent.addEventListener('scroll', handleScroll, {passive: true})
|
|
100
|
-
ro.observe(scrollParent)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
handleScroll()
|
|
104
|
-
|
|
105
|
-
return () => {
|
|
106
|
-
ro.unobserve(el)
|
|
107
|
-
|
|
108
|
-
for (const scrollParent of scrollParents) {
|
|
109
|
-
ro.unobserve(scrollParent)
|
|
110
|
-
scrollParent.removeEventListener('scroll', handleScroll)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
ro.disconnect()
|
|
114
|
-
|
|
115
|
-
window.removeEventListener('scroll', handleScroll)
|
|
116
|
-
}
|
|
117
|
-
}, [])
|
|
118
|
-
|
|
119
|
-
const bounds: Rect | null = useMemo(
|
|
120
|
-
() =>
|
|
121
|
-
relativeBoundsRect && {
|
|
122
|
-
x: relativeBoundsRect.x - boundsScroll.x,
|
|
123
|
-
y: relativeBoundsRect.y - boundsScroll.y,
|
|
124
|
-
w: relativeBoundsRect.w,
|
|
125
|
-
h: relativeBoundsRect.h,
|
|
126
|
-
},
|
|
127
|
-
[relativeBoundsRect, boundsScroll],
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
const element: Rect | null = useMemo(
|
|
131
|
-
() =>
|
|
132
|
-
relativeElementRect && {
|
|
133
|
-
x: relativeElementRect.x - scroll.x,
|
|
134
|
-
y: relativeElementRect.y - scroll.y,
|
|
135
|
-
w: relativeElementRect.w,
|
|
136
|
-
h: relativeElementRect.h,
|
|
137
|
-
},
|
|
138
|
-
[relativeElementRect, scroll],
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
return {bounds, element, ref}
|
|
142
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type {SanityClient} from '@sanity/client'
|
|
2
|
-
import {defer, delay, merge, Observable, of, partition, switchMap, throwError} from 'rxjs'
|
|
3
|
-
import {filter, mergeMap, share, take} from 'rxjs/operators'
|
|
4
|
-
import {exhaustMapToWithTrailing} from 'rxjs-exhaustmap-with-trailing'
|
|
5
|
-
import {MutationEvent, ReconnectEvent, WelcomeEvent} from 'sanity'
|
|
6
|
-
|
|
7
|
-
/** @internal */
|
|
8
|
-
export type ListenQueryParams = Record<string, string | number | boolean | string[]>
|
|
9
|
-
|
|
10
|
-
/** @beta */
|
|
11
|
-
export interface ListenQueryOptions {
|
|
12
|
-
tag?: string
|
|
13
|
-
apiVersion?: string
|
|
14
|
-
throttleTime?: number
|
|
15
|
-
transitions?: ('update' | 'appear' | 'disappear')[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const fetch = (
|
|
19
|
-
client: SanityClient,
|
|
20
|
-
query: string,
|
|
21
|
-
params: ListenQueryParams,
|
|
22
|
-
options: ListenQueryOptions,
|
|
23
|
-
) =>
|
|
24
|
-
defer(() =>
|
|
25
|
-
// getVersionedClient(options.apiVersion)
|
|
26
|
-
client.observable.fetch(query, params, {
|
|
27
|
-
tag: options.tag,
|
|
28
|
-
filterResponse: true,
|
|
29
|
-
}),
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
const listen = (
|
|
33
|
-
client: SanityClient,
|
|
34
|
-
query: string,
|
|
35
|
-
params: ListenQueryParams,
|
|
36
|
-
options: ListenQueryOptions,
|
|
37
|
-
) =>
|
|
38
|
-
defer(() =>
|
|
39
|
-
// getVersionedClient(options.apiVersion)
|
|
40
|
-
client.listen(query, params, {
|
|
41
|
-
events: ['welcome', 'mutation', 'reconnect'],
|
|
42
|
-
includeResult: false,
|
|
43
|
-
visibility: 'query',
|
|
44
|
-
tag: options.tag,
|
|
45
|
-
}),
|
|
46
|
-
) as Observable<ReconnectEvent | WelcomeEvent | MutationEvent>
|
|
47
|
-
|
|
48
|
-
function isWelcomeEvent(
|
|
49
|
-
event: MutationEvent | ReconnectEvent | WelcomeEvent,
|
|
50
|
-
): event is WelcomeEvent {
|
|
51
|
-
return event.type === 'welcome'
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** @internal */
|
|
55
|
-
export const listenQuery = (
|
|
56
|
-
client: SanityClient,
|
|
57
|
-
query: string | {fetch: string; listen: string},
|
|
58
|
-
params: ListenQueryParams = {},
|
|
59
|
-
options: ListenQueryOptions = {},
|
|
60
|
-
) => {
|
|
61
|
-
const fetchQuery = typeof query === 'string' ? query : query.fetch
|
|
62
|
-
const listenerQuery = typeof query === 'string' ? query : query.listen
|
|
63
|
-
|
|
64
|
-
const fetchOnce$ = fetch(client, fetchQuery, params, options)
|
|
65
|
-
|
|
66
|
-
const events$ = listen(client, listenerQuery, params, options).pipe(
|
|
67
|
-
mergeMap((ev, i) => {
|
|
68
|
-
const isFirst = i === 0
|
|
69
|
-
if (isFirst && !isWelcomeEvent(ev)) {
|
|
70
|
-
// if the first event is not welcome, it is most likely a reconnect and
|
|
71
|
-
// if it's not a reconnect something is very wrong
|
|
72
|
-
return throwError(
|
|
73
|
-
new Error(
|
|
74
|
-
ev.type === 'reconnect'
|
|
75
|
-
? 'Could not establish EventSource connection'
|
|
76
|
-
: `Received unexpected type of first event "${ev.type}"`,
|
|
77
|
-
),
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
return of(ev)
|
|
81
|
-
}),
|
|
82
|
-
share(),
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
const [welcome$, mutationAndReconnect$] = partition(events$, isWelcomeEvent)
|
|
86
|
-
const isRelevantEvent = (event: MutationEvent | ReconnectEvent | WelcomeEvent): boolean => {
|
|
87
|
-
if (!options.transitions || event.type !== 'mutation') {
|
|
88
|
-
return true
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return options.transitions.includes(event.transition)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return merge(
|
|
95
|
-
welcome$.pipe(take(1)),
|
|
96
|
-
mutationAndReconnect$.pipe(
|
|
97
|
-
filter(isRelevantEvent),
|
|
98
|
-
switchMap((event) => merge(of(event), of(event).pipe(delay(options.throttleTime || 1000)))),
|
|
99
|
-
),
|
|
100
|
-
).pipe(exhaustMapToWithTrailing(fetchOnce$))
|
|
101
|
-
}
|