sanity-plugin-hotspot-array 3.0.2 → 5.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/dist/index.d.ts +30 -48
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +256 -183
- package/dist/index.js.map +1 -1
- package/package.json +35 -72
- package/dist/index.d.mts +0 -54
- package/dist/index.mjs +0 -308
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/Feedback.tsx +0 -9
- package/src/ImageHotspotArray.tsx +0 -212
- package/src/Spot.tsx +0 -201
- package/src/index.ts +0 -3
- package/src/plugin.tsx +0 -40
- package/src/useDebouncedCallback.ts +0 -102
- package/src/useResizeObserver.ts +0 -123
- package/v2-incompatible.js +0 -11
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
HotspotFields = {
|
|
10
|
-
[key: string]: unknown
|
|
11
|
-
},
|
|
12
|
-
> = {
|
|
13
|
-
_key: string
|
|
14
|
-
_type: string
|
|
15
|
-
x: number
|
|
16
|
-
y: number
|
|
17
|
-
} & HotspotFields
|
|
18
|
-
|
|
19
|
-
export declare interface HotspotTooltipProps<
|
|
20
|
-
HotspotFields = {
|
|
21
|
-
[key: string]: unknown
|
|
22
|
-
},
|
|
23
|
-
> {
|
|
24
|
-
value: HotspotItem<HotspotFields>
|
|
25
|
-
schemaType: ObjectSchemaType
|
|
26
|
-
renderPreview: RenderPreviewCallback
|
|
1
|
+
import { ComponentType, ReactNode } from "react";
|
|
2
|
+
import { ArrayOfObjectsInputProps, ObjectSchemaType, RenderPreviewCallback } from "sanity";
|
|
3
|
+
interface HotspotTooltipProps<HotspotFields = {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}> {
|
|
6
|
+
value: HotspotItem<HotspotFields>;
|
|
7
|
+
schemaType: ObjectSchemaType;
|
|
8
|
+
renderPreview: RenderPreviewCallback;
|
|
27
9
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export declare const imageHotspotArrayPlugin: Plugin_2<void>
|
|
36
|
-
|
|
37
|
-
export declare interface ImageHotspotOptions<
|
|
38
|
-
HotspotFields = {
|
|
39
|
-
[key: string]: unknown
|
|
40
|
-
},
|
|
41
|
-
> {
|
|
42
|
-
pathRoot?: 'document' | 'parent'
|
|
43
|
-
imagePath: string
|
|
44
|
-
descriptionPath?: string
|
|
45
|
-
tooltip?: ComponentType<HotspotTooltipProps<HotspotFields>>
|
|
10
|
+
interface ImageHotspotOptions<HotspotFields = {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}> {
|
|
13
|
+
pathRoot?: 'document' | 'parent';
|
|
14
|
+
imagePath: string;
|
|
15
|
+
descriptionPath?: string;
|
|
16
|
+
tooltip?: ComponentType<HotspotTooltipProps<HotspotFields>>;
|
|
46
17
|
}
|
|
47
|
-
|
|
48
|
-
export {}
|
|
49
|
-
|
|
50
18
|
declare module 'sanity' {
|
|
51
19
|
interface ArrayOptions {
|
|
52
|
-
imageHotspot?: ImageHotspotOptions
|
|
20
|
+
imageHotspot?: ImageHotspotOptions;
|
|
53
21
|
}
|
|
54
22
|
}
|
|
23
|
+
declare const imageHotspotArrayPlugin: import("sanity").Plugin<void>;
|
|
24
|
+
type HotspotItem<HotspotFields = {
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}> = {
|
|
27
|
+
_key: string;
|
|
28
|
+
_type: string;
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
} & HotspotFields;
|
|
32
|
+
declare function ImageHotspotArray(props: ArrayOfObjectsInputProps<HotspotItem> & {
|
|
33
|
+
imageHotspotOptions: ImageHotspotOptions;
|
|
34
|
+
}): ReactNode;
|
|
35
|
+
export { type HotspotItem, type HotspotTooltipProps, ImageHotspotArray, type ImageHotspotOptions, imageHotspotArrayPlugin };
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/Spot.tsx","../src/plugin.tsx","../src/ImageHotspotArray.tsx"],"mappings":";;UA0EiB,mBAAA;EAAA,CAAsC,GAAA;AAAA;EACrD,KAAA,EAAO,WAAA,CAAY,aAAA;EACnB,UAAA,EAAY,gBAAA;EACZ,aAAA,EAAe,qBAAA;AAAA;AAAA,UCvEA,mBAAA;EAAA,CAAsC,GAAA;AAAA;EACrD,QAAA;EACA,SAAA;EACA,eAAA;EACA,OAAA,GAAU,aAAA,CAAc,mBAAA,CAAoB,aAAA;AAAA;AAAA;EAAA,UAI3B,YAAA;IACf,YAAA,GAAe,mBAAmB;EAAA;AAAA;AAAA,cAIzB,uBAAA,mBAAuB,MAAA;AAAA,KCYxB,WAAA;EAAA,CAA8B,GAAA;AAAA;EACxC,IAAA;EACA,KAAA;EACA,CAAA;EACA,CAAA;AAAA,IACE,aAAa;AAAA,iBAED,iBAAA,CACd,KAAA,EAAO,wBAAA,CAAyB,WAAA;EAAgB,mBAAA,EAAqB,mBAAA;AAAA,IACpE,SAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { getImageDimensions } from "@sanity/asset-utils";
|
|
4
|
+
import { createImageUrlBuilder } from "@sanity/image-url";
|
|
5
|
+
import { Card, Text, Box, Tooltip, Flex, Stack } from "@sanity/ui";
|
|
6
|
+
import { randomKey } from "@sanity/util/content";
|
|
7
|
+
import get from "lodash-es/get.js";
|
|
8
|
+
import { useState, useEffect, useRef, useMemo } from "react";
|
|
9
|
+
import { useClient, useFormValue, useResolveInitialValueForType, PatchEvent, setIfMissing, insert, set, definePlugin } from "sanity";
|
|
10
|
+
import { useMotionValue, motion } from "framer-motion";
|
|
11
|
+
function Feedback(t0) {
|
|
12
|
+
const $ = c(2), {
|
|
13
|
+
children
|
|
14
|
+
} = t0;
|
|
15
|
+
let t1;
|
|
16
|
+
return $[0] !== children ? (t1 = /* @__PURE__ */ jsx(Card, { padding: 4, radius: 2, shadow: 1, tone: "caution", children: /* @__PURE__ */ jsx(Text, { children }) }), $[0] = children, $[1] = t1) : t1 = $[1], t1;
|
|
10
17
|
}
|
|
11
18
|
const dragStyle = {
|
|
12
19
|
width: "1.4rem",
|
|
@@ -52,97 +59,132 @@ const dragStyle = {
|
|
|
52
59
|
}, labelStyleWhileActive = {
|
|
53
60
|
visibility: "hidden"
|
|
54
61
|
}, round = (num) => Math.round(num * 100) / 100;
|
|
55
|
-
function Spot({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
function Spot(t0) {
|
|
63
|
+
const $ = c(67), {
|
|
64
|
+
value,
|
|
65
|
+
bounds,
|
|
66
|
+
update,
|
|
67
|
+
hotspotDescriptionPath,
|
|
68
|
+
tooltip: TooltipComponent,
|
|
69
|
+
index,
|
|
70
|
+
schemaType,
|
|
71
|
+
renderPreview
|
|
72
|
+
} = t0, [isDragging, setIsDragging] = useState(!1), [isHovering, setIsHovering] = useState(!1), t1 = bounds.width * (value.x / 100);
|
|
73
|
+
let t2;
|
|
74
|
+
$[0] !== t1 ? (t2 = round(t1), $[0] = t1, $[1] = t2) : t2 = $[1];
|
|
75
|
+
const x = useMotionValue(t2), t3 = bounds.height * (value.y / 100);
|
|
76
|
+
let t4;
|
|
77
|
+
$[2] !== t3 ? (t4 = round(t3), $[2] = t3, $[3] = t4) : t4 = $[3];
|
|
78
|
+
const y = useMotionValue(t4);
|
|
79
|
+
let t5;
|
|
80
|
+
$[4] !== bounds.height || $[5] !== bounds.width || $[6] !== value.x || $[7] !== value.y || $[8] !== x || $[9] !== y ? (t5 = () => {
|
|
67
81
|
x.set(round(bounds.width * (value.x / 100))), y.set(round(bounds.height * (value.y / 100)));
|
|
68
|
-
}, [x, y,
|
|
69
|
-
|
|
82
|
+
}, $[4] = bounds.height, $[5] = bounds.width, $[6] = value.x, $[7] = value.y, $[8] = x, $[9] = y, $[10] = t5) : t5 = $[10];
|
|
83
|
+
let t6;
|
|
84
|
+
$[11] !== bounds || $[12] !== value || $[13] !== x || $[14] !== y ? (t6 = [x, y, value, bounds], $[11] = bounds, $[12] = value, $[13] = x, $[14] = y, $[15] = t6) : t6 = $[15], useEffect(t5, t6);
|
|
85
|
+
let t7;
|
|
86
|
+
$[16] !== bounds.height || $[17] !== bounds.width || $[18] !== update || $[19] !== value._key || $[20] !== x || $[21] !== y ? (t7 = () => {
|
|
70
87
|
setIsDragging(!1);
|
|
71
88
|
const currentX = x.get(), currentY = y.get(), newX = round(currentX * 100 / bounds.width), newY = round(currentY * 100 / bounds.height), safeX = Math.max(0, Math.min(100, newX)), safeY = Math.max(0, Math.min(100, newY));
|
|
72
89
|
update(value._key, safeX, safeY);
|
|
73
|
-
}, [
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
90
|
+
}, $[16] = bounds.height, $[17] = bounds.width, $[18] = update, $[19] = value._key, $[20] = x, $[21] = y, $[22] = t7) : t7 = $[22];
|
|
91
|
+
const handleDragEnd = t7;
|
|
92
|
+
let t8;
|
|
93
|
+
$[23] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t8 = () => setIsDragging(!0), $[23] = t8) : t8 = $[23];
|
|
94
|
+
const handleDragStart = t8;
|
|
95
|
+
let t9;
|
|
96
|
+
$[24] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t9 = () => setIsHovering(!0), $[24] = t9) : t9 = $[24];
|
|
97
|
+
const handleHoverStart = t9;
|
|
98
|
+
let t10;
|
|
99
|
+
$[25] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t10 = () => setIsHovering(!1), $[25] = t10) : t10 = $[25];
|
|
100
|
+
const handleHoverEnd = t10;
|
|
101
|
+
if (!x || !y)
|
|
102
|
+
return null;
|
|
103
|
+
let t11;
|
|
104
|
+
$[26] !== isDragging ? (t11 = isDragging && {
|
|
105
|
+
...dragStyleWhileDrag
|
|
106
|
+
}, $[26] = isDragging, $[27] = t11) : t11 = $[27];
|
|
107
|
+
let t12;
|
|
108
|
+
$[28] !== isHovering ? (t12 = isHovering && {
|
|
109
|
+
...dragStyleWhileHover
|
|
110
|
+
}, $[28] = isHovering, $[29] = t12) : t12 = $[29];
|
|
111
|
+
let t13;
|
|
112
|
+
$[30] !== t11 || $[31] !== t12 || $[32] !== x || $[33] !== y ? (t13 = {
|
|
113
|
+
...dragStyle,
|
|
114
|
+
x,
|
|
115
|
+
y,
|
|
116
|
+
...t11,
|
|
117
|
+
...t12
|
|
118
|
+
}, $[30] = t11, $[31] = t12, $[32] = x, $[33] = y, $[34] = t13) : t13 = $[34];
|
|
119
|
+
let t14;
|
|
120
|
+
$[35] !== TooltipComponent || $[36] !== hotspotDescriptionPath || $[37] !== renderPreview || $[38] !== schemaType || $[39] !== value ? (t14 = TooltipComponent && typeof TooltipComponent == "function" ? /* @__PURE__ */ jsx(TooltipComponent, { value, renderPreview, schemaType }) : /* @__PURE__ */ jsx(Box, { padding: 2, style: {
|
|
121
|
+
maxWidth: 200,
|
|
122
|
+
pointerEvents: "none"
|
|
123
|
+
}, children: /* @__PURE__ */ jsx(Text, { textOverflow: "ellipsis", children: hotspotDescriptionPath ? get(value, hotspotDescriptionPath) : `${value.x}% x ${value.y}%` }) }), $[35] = TooltipComponent, $[36] = hotspotDescriptionPath, $[37] = renderPreview, $[38] = schemaType, $[39] = value, $[40] = t14) : t14 = $[40];
|
|
124
|
+
let t15;
|
|
125
|
+
$[41] !== isDragging || $[42] !== isHovering ? (t15 = (isDragging || isHovering) && {
|
|
126
|
+
...dotStyleWhileActive
|
|
127
|
+
}, $[41] = isDragging, $[42] = isHovering, $[43] = t15) : t15 = $[43];
|
|
128
|
+
let t16;
|
|
129
|
+
$[44] !== t15 ? (t16 = /* @__PURE__ */ jsx(Box, { style: {
|
|
130
|
+
...dotStyle,
|
|
131
|
+
...t15
|
|
132
|
+
} }), $[44] = t15, $[45] = t16) : t16 = $[45];
|
|
133
|
+
let t17;
|
|
134
|
+
$[46] !== isDragging || $[47] !== isHovering ? (t17 = (isDragging || isHovering) && {
|
|
135
|
+
...labelStyleWhileActive
|
|
136
|
+
}, $[46] = isDragging, $[47] = isHovering, $[48] = t17) : t17 = $[48];
|
|
137
|
+
let t18;
|
|
138
|
+
$[49] !== t17 ? (t18 = {
|
|
139
|
+
...labelStyle,
|
|
140
|
+
...t17
|
|
141
|
+
}, $[49] = t17, $[50] = t18) : t18 = $[50];
|
|
142
|
+
const t19 = index + 1;
|
|
143
|
+
let t20;
|
|
144
|
+
$[51] !== t18 || $[52] !== t19 ? (t20 = /* @__PURE__ */ jsx("div", { style: t18, children: t19 }), $[51] = t18, $[52] = t19, $[53] = t20) : t20 = $[53];
|
|
145
|
+
let t21;
|
|
146
|
+
$[54] !== t16 || $[55] !== t20 ? (t21 = /* @__PURE__ */ jsxs("div", { children: [
|
|
147
|
+
t16,
|
|
148
|
+
t20
|
|
149
|
+
] }), $[54] = t16, $[55] = t20, $[56] = t21) : t21 = $[56];
|
|
150
|
+
let t22;
|
|
151
|
+
$[57] !== isDragging || $[58] !== t14 || $[59] !== t21 || $[60] !== value._key ? (t22 = /* @__PURE__ */ jsx(Tooltip, { disabled: isDragging, portal: !0, content: t14, children: t21 }, value._key), $[57] = isDragging, $[58] = t14, $[59] = t21, $[60] = value._key, $[61] = t22) : t22 = $[61];
|
|
152
|
+
let t23;
|
|
153
|
+
return $[62] !== bounds || $[63] !== handleDragEnd || $[64] !== t13 || $[65] !== t22 ? (t23 = /* @__PURE__ */ jsx(motion.div, { drag: !0, dragConstraints: bounds, dragElastic: 0, dragMomentum: !1, onDragEnd: handleDragEnd, onDragStart: handleDragStart, onHoverStart: handleHoverStart, onHoverEnd: handleHoverEnd, style: t13, children: t22 }), $[62] = bounds, $[63] = handleDragEnd, $[64] = t13, $[65] = t22, $[66] = t23) : t23 = $[66], t23;
|
|
124
154
|
}
|
|
125
155
|
function useUnmountEffect(effect) {
|
|
126
|
-
const effectRef =
|
|
127
|
-
|
|
156
|
+
const $ = c(5), effectRef = useRef(effect);
|
|
157
|
+
let t0, t1;
|
|
158
|
+
$[0] !== effect ? (t0 = () => {
|
|
159
|
+
effectRef.current = effect;
|
|
160
|
+
}, t1 = [effect], $[0] = effect, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1);
|
|
161
|
+
let t2, t3;
|
|
162
|
+
$[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = () => () => effectRef.current(), t3 = [], $[3] = t2, $[4] = t3) : (t2 = $[3], t3 = $[4]), useEffect(t2, t3);
|
|
128
163
|
}
|
|
129
164
|
function useDebouncedCallback(callback, deps, delay, maxWait = 0) {
|
|
130
|
-
const timeout =
|
|
165
|
+
const timeout = useRef(void 0), waitTimeout = useRef(void 0), cb = useRef(callback), lastCall = useRef(void 0), clear = () => {
|
|
131
166
|
timeout.current && (clearTimeout(timeout.current), timeout.current = void 0), waitTimeout.current && (clearTimeout(waitTimeout.current), waitTimeout.current = void 0);
|
|
132
167
|
};
|
|
133
|
-
return useUnmountEffect(clear),
|
|
168
|
+
return useUnmountEffect(clear), useEffect(() => {
|
|
134
169
|
cb.current = callback;
|
|
135
|
-
}, deps),
|
|
170
|
+
}, deps), useMemo(() => {
|
|
136
171
|
const execute = () => {
|
|
137
172
|
if (clear(), !lastCall.current) return;
|
|
138
173
|
const context = lastCall.current;
|
|
139
174
|
lastCall.current = void 0, cb.current.apply(context.this, context.args);
|
|
140
175
|
}, wrapped = function(...args) {
|
|
141
|
-
timeout.current && clearTimeout(timeout.current), lastCall.current = {
|
|
176
|
+
timeout.current && clearTimeout(timeout.current), lastCall.current = {
|
|
177
|
+
args,
|
|
178
|
+
this: this
|
|
179
|
+
}, timeout.current = setTimeout(execute, delay), maxWait > 0 && !waitTimeout.current && (waitTimeout.current = setTimeout(execute, maxWait));
|
|
142
180
|
};
|
|
143
181
|
return Object.defineProperties(wrapped, {
|
|
144
|
-
length: {
|
|
145
|
-
|
|
182
|
+
length: {
|
|
183
|
+
value: callback.length
|
|
184
|
+
},
|
|
185
|
+
name: {
|
|
186
|
+
value: `${callback.name || "anonymous"}__debounced__${delay}`
|
|
187
|
+
}
|
|
146
188
|
}), wrapped;
|
|
147
189
|
}, [delay, maxWait, ...deps]);
|
|
148
190
|
}
|
|
@@ -152,12 +194,9 @@ function getResizeObserver() {
|
|
|
152
194
|
if (!isBrowser) return;
|
|
153
195
|
if (observerSingleton) return observerSingleton;
|
|
154
196
|
const callbacks = /* @__PURE__ */ new Map(), observer = new ResizeObserver((entries) => {
|
|
155
|
-
for (const entry of entries)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
cb(entry);
|
|
159
|
-
}, 0)
|
|
160
|
-
);
|
|
197
|
+
for (const entry of entries) callbacks.get(entry.target)?.forEach((cb) => setTimeout(() => {
|
|
198
|
+
cb(entry);
|
|
199
|
+
}, 0));
|
|
161
200
|
});
|
|
162
201
|
return observerSingleton = {
|
|
163
202
|
observer,
|
|
@@ -172,10 +211,12 @@ function getResizeObserver() {
|
|
|
172
211
|
}, observerSingleton;
|
|
173
212
|
}
|
|
174
213
|
function useResizeObserver(target, callback, enabled = !0) {
|
|
175
|
-
const ro = enabled && getResizeObserver(), cb =
|
|
176
|
-
|
|
214
|
+
const ro = enabled && getResizeObserver(), cb = useRef(callback);
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
cb.current = callback;
|
|
217
|
+
}, [callback]);
|
|
177
218
|
const tgt = target && "current" in target ? target.current : target;
|
|
178
|
-
|
|
219
|
+
useEffect(() => {
|
|
179
220
|
const _tgt = target && "current" in target ? target.current : target;
|
|
180
221
|
if (!ro || !_tgt) return;
|
|
181
222
|
let subscribed = !0;
|
|
@@ -187,98 +228,128 @@ function useResizeObserver(target, callback, enabled = !0) {
|
|
|
187
228
|
};
|
|
188
229
|
}, [tgt, ro]);
|
|
189
230
|
}
|
|
190
|
-
const imageStyle = {
|
|
231
|
+
const imageStyle = {
|
|
232
|
+
width: "100%",
|
|
233
|
+
height: "auto"
|
|
234
|
+
}, VALID_ROOT_PATHS = ["document", "parent"];
|
|
191
235
|
function ImageHotspotArray(props) {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
236
|
+
const $ = c(49), {
|
|
237
|
+
value,
|
|
238
|
+
onChange,
|
|
239
|
+
imageHotspotOptions,
|
|
240
|
+
schemaType,
|
|
241
|
+
renderPreview
|
|
242
|
+
} = props;
|
|
243
|
+
let t0;
|
|
244
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
245
|
+
apiVersion: "2022-01-01"
|
|
246
|
+
}, $[0] = t0) : t0 = $[0];
|
|
247
|
+
const sanityClient = useClient(t0), pathRoot = VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot ?? "") ? imageHotspotOptions.pathRoot : "document";
|
|
248
|
+
let t1;
|
|
249
|
+
$[1] !== pathRoot || $[2] !== props.path ? (t1 = pathRoot === "document" ? [] : props.path.slice(0, -1), $[1] = pathRoot, $[2] = props.path, $[3] = t1) : t1 = $[3];
|
|
250
|
+
const rootObject = useFormValue(t1), resolveInitialValueForType = useResolveInitialValueForType();
|
|
251
|
+
let t2;
|
|
252
|
+
$[4] !== resolveInitialValueForType ? (t2 = async (type) => resolveInitialValueForType(type, {}).then(_temp).catch(_temp2), $[4] = resolveInitialValueForType, $[5] = t2) : t2 = $[5];
|
|
253
|
+
const resolveInitialValue = t2;
|
|
254
|
+
let t3;
|
|
255
|
+
$[6] !== imageHotspotOptions.imagePath || $[7] !== rootObject ? (t3 = imageHotspotOptions.imagePath ? get(rootObject, imageHotspotOptions.imagePath) : rootObject, $[6] = imageHotspotOptions.imagePath, $[7] = rootObject, $[8] = t3) : t3 = $[8];
|
|
256
|
+
const hotspotImage = t3;
|
|
257
|
+
let t4;
|
|
258
|
+
if ($[9] !== hotspotImage || $[10] !== sanityClient) {
|
|
259
|
+
bb0: {
|
|
260
|
+
const builder = createImageUrlBuilder(sanityClient).dataset(sanityClient.config().dataset ?? ""), urlFor = (source) => builder.image(source);
|
|
261
|
+
if (hotspotImage?.asset?._ref) {
|
|
262
|
+
let t52;
|
|
263
|
+
$[12] !== hotspotImage.asset._ref ? (t52 = getImageDimensions(hotspotImage.asset._ref), $[12] = hotspotImage.asset._ref, $[13] = t52) : t52 = $[13];
|
|
264
|
+
const {
|
|
265
|
+
aspectRatio
|
|
266
|
+
} = t52;
|
|
267
|
+
let t62;
|
|
268
|
+
$[14] !== aspectRatio ? (t62 = Math.round(1200 / aspectRatio), $[14] = aspectRatio, $[15] = t62) : t62 = $[15];
|
|
269
|
+
const height = t62, url = urlFor(hotspotImage).width(1200).url();
|
|
270
|
+
let t72;
|
|
271
|
+
$[16] !== height || $[17] !== url ? (t72 = {
|
|
272
|
+
width: 1200,
|
|
273
|
+
height,
|
|
274
|
+
url
|
|
275
|
+
}, $[16] = height, $[17] = url, $[18] = t72) : t72 = $[18], t4 = t72;
|
|
276
|
+
break bb0;
|
|
277
|
+
}
|
|
278
|
+
t4 = null;
|
|
201
279
|
}
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
[
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
imageHotspotOptions.pathRoot,
|
|
274
|
-
'" is not valid, falling back to "document". Available values are "',
|
|
275
|
-
VALID_ROOT_PATHS.join(", "),
|
|
276
|
-
'".'
|
|
277
|
-
] }),
|
|
278
|
-
props.renderDefault(props)
|
|
279
|
-
] });
|
|
280
|
+
$[9] = hotspotImage, $[10] = sanityClient, $[11] = t4;
|
|
281
|
+
} else
|
|
282
|
+
t4 = $[11];
|
|
283
|
+
const displayImage = t4;
|
|
284
|
+
let t5;
|
|
285
|
+
$[19] !== imageHotspotOptions.descriptionPath || $[20] !== onChange || $[21] !== resolveInitialValue || $[22] !== schemaType.of[0] ? (t5 = async (event) => {
|
|
286
|
+
const spotType = schemaType.of[0];
|
|
287
|
+
if (!spotType)
|
|
288
|
+
return;
|
|
289
|
+
const {
|
|
290
|
+
nativeEvent,
|
|
291
|
+
currentTarget
|
|
292
|
+
} = event, x = Number((nativeEvent.offsetX * 100 / currentTarget.width).toFixed(2)), y = Number((nativeEvent.offsetY * 100 / currentTarget.height).toFixed(2)), description = `New Hotspot at ${x}% x ${y}%`, initialValues = await resolveInitialValue(spotType.type), newRow = {
|
|
293
|
+
_key: randomKey(12),
|
|
294
|
+
_type: spotType.name,
|
|
295
|
+
...initialValues,
|
|
296
|
+
x,
|
|
297
|
+
y
|
|
298
|
+
};
|
|
299
|
+
imageHotspotOptions?.descriptionPath && (newRow[imageHotspotOptions.descriptionPath] = description), onChange(PatchEvent.from([setIfMissing([]), insert([newRow], "after", [-1])]));
|
|
300
|
+
}, $[19] = imageHotspotOptions.descriptionPath, $[20] = onChange, $[21] = resolveInitialValue, $[22] = schemaType.of[0], $[23] = t5) : t5 = $[23];
|
|
301
|
+
const handleHotspotImageClick = t5;
|
|
302
|
+
let t6;
|
|
303
|
+
$[24] !== onChange ? (t6 = (key, x_0, y_0) => {
|
|
304
|
+
onChange(PatchEvent.from([set(x_0, [{
|
|
305
|
+
_key: key
|
|
306
|
+
}, "x"]), set(y_0, [{
|
|
307
|
+
_key: key
|
|
308
|
+
}, "y"])]));
|
|
309
|
+
}, $[24] = onChange, $[25] = t6) : t6 = $[25];
|
|
310
|
+
const handleHotspotMove = t6, hotspotImageRef = useRef(null), [imageRect, setImageRect] = useState();
|
|
311
|
+
let t7, t8;
|
|
312
|
+
$[26] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t7 = (e) => setImageRect(e.contentRect), t8 = [setImageRect], $[26] = t7, $[27] = t8) : (t7 = $[26], t8 = $[27]), useResizeObserver(hotspotImageRef, useDebouncedCallback(t7, t8, 200));
|
|
313
|
+
let t9;
|
|
314
|
+
$[28] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t9 = [2, 2, 3], $[28] = t9) : t9 = $[28];
|
|
315
|
+
let t10;
|
|
316
|
+
$[29] !== displayImage || $[30] !== handleHotspotImageClick || $[31] !== handleHotspotMove || $[32] !== imageHotspotOptions.descriptionPath || $[33] !== imageHotspotOptions.imagePath || $[34] !== imageHotspotOptions.tooltip || $[35] !== imageRect || $[36] !== renderPreview || $[37] !== schemaType.of[0] || $[38] !== value ? (t10 = displayImage?.url ? /* @__PURE__ */ jsxs("div", { style: {
|
|
317
|
+
position: "relative"
|
|
318
|
+
}, children: [
|
|
319
|
+
imageRect && (value?.length ?? 0) > 0 && value?.map((spot, index) => /* @__PURE__ */ jsx(Spot, { index, value: spot, bounds: imageRect, update: handleHotspotMove, hotspotDescriptionPath: imageHotspotOptions?.descriptionPath, tooltip: imageHotspotOptions?.tooltip, renderPreview, schemaType: schemaType.of[0] }, spot._key)),
|
|
320
|
+
/* @__PURE__ */ jsx(Card, { __unstable_checkered: !0, shadow: 1, children: /* @__PURE__ */ jsx(Flex, { align: "center", justify: "center", children: /* @__PURE__ */ jsx("img", { ref: hotspotImageRef, src: displayImage.url, width: displayImage.width, height: displayImage.height, alt: "", style: imageStyle, onClick: handleHotspotImageClick }) }) })
|
|
321
|
+
] }) : /* @__PURE__ */ jsx(Feedback, { children: imageHotspotOptions.imagePath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
322
|
+
"No Hotspot image found at path ",
|
|
323
|
+
/* @__PURE__ */ jsx("code", { children: imageHotspotOptions.imagePath })
|
|
324
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
325
|
+
"Define a path in this field using to the image field in this document at",
|
|
326
|
+
" ",
|
|
327
|
+
/* @__PURE__ */ jsx("code", { children: "options.hotspotImagePath" })
|
|
328
|
+
] }) }), $[29] = displayImage, $[30] = handleHotspotImageClick, $[31] = handleHotspotMove, $[32] = imageHotspotOptions.descriptionPath, $[33] = imageHotspotOptions.imagePath, $[34] = imageHotspotOptions.tooltip, $[35] = imageRect, $[36] = renderPreview, $[37] = schemaType.of[0], $[38] = value, $[39] = t10) : t10 = $[39];
|
|
329
|
+
let t11;
|
|
330
|
+
$[40] !== imageHotspotOptions.pathRoot ? (t11 = imageHotspotOptions.pathRoot && !VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot) && /* @__PURE__ */ jsxs(Feedback, { children: [
|
|
331
|
+
'The supplied imageHotspotPathRoot "',
|
|
332
|
+
imageHotspotOptions.pathRoot,
|
|
333
|
+
'" is not valid, falling back to "document". Available values are "',
|
|
334
|
+
VALID_ROOT_PATHS.join(", "),
|
|
335
|
+
'".'
|
|
336
|
+
] }), $[40] = imageHotspotOptions.pathRoot, $[41] = t11) : t11 = $[41];
|
|
337
|
+
const t12 = props;
|
|
338
|
+
let t13;
|
|
339
|
+
$[42] !== props.renderDefault || $[43] !== t12 ? (t13 = props.renderDefault(t12), $[42] = props.renderDefault, $[43] = t12, $[44] = t13) : t13 = $[44];
|
|
340
|
+
let t14;
|
|
341
|
+
return $[45] !== t10 || $[46] !== t11 || $[47] !== t13 ? (t14 = /* @__PURE__ */ jsxs(Stack, { gap: t9, children: [
|
|
342
|
+
t10,
|
|
343
|
+
t11,
|
|
344
|
+
t13
|
|
345
|
+
] }), $[45] = t10, $[46] = t11, $[47] = t13, $[48] = t14) : t14 = $[48], t14;
|
|
346
|
+
}
|
|
347
|
+
function _temp2() {
|
|
348
|
+
}
|
|
349
|
+
function _temp(initialValue) {
|
|
350
|
+
return initialValue;
|
|
280
351
|
}
|
|
281
|
-
const imageHotspotArrayPlugin =
|
|
352
|
+
const imageHotspotArrayPlugin = definePlugin({
|
|
282
353
|
name: "image-hotspot-array",
|
|
283
354
|
form: {
|
|
284
355
|
components: {
|
|
@@ -286,7 +357,7 @@ const imageHotspotArrayPlugin = sanity.definePlugin({
|
|
|
286
357
|
if (props.schemaType.jsonType === "array" && props.schemaType.options?.imageHotspot) {
|
|
287
358
|
const imageHotspotOptions = props.schemaType.options?.imageHotspot;
|
|
288
359
|
if (imageHotspotOptions)
|
|
289
|
-
return /* @__PURE__ */
|
|
360
|
+
return /* @__PURE__ */ jsx(
|
|
290
361
|
ImageHotspotArray,
|
|
291
362
|
{
|
|
292
363
|
...props,
|
|
@@ -299,6 +370,8 @@ const imageHotspotArrayPlugin = sanity.definePlugin({
|
|
|
299
370
|
}
|
|
300
371
|
}
|
|
301
372
|
});
|
|
302
|
-
|
|
303
|
-
|
|
373
|
+
export {
|
|
374
|
+
ImageHotspotArray,
|
|
375
|
+
imageHotspotArrayPlugin
|
|
376
|
+
};
|
|
304
377
|
//# sourceMappingURL=index.js.map
|