sanity-plugin-hotspot-array 4.0.0 → 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/dist/index.d.ts CHANGED
@@ -1,54 +1,36 @@
1
- import {ArrayOfObjectsInputProps} from 'sanity'
2
- import {ComponentType} from 'react'
3
- import {ObjectSchemaType} from 'sanity'
4
- import {Plugin as Plugin_2} from 'sanity'
5
- import {ReactNode} from 'react'
6
- import {RenderPreviewCallback} from 'sanity'
7
-
8
- export declare type HotspotItem<
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
- export declare function ImageHotspotArray(
30
- props: ArrayOfObjectsInputProps<HotspotItem> & {
31
- imageHotspotOptions: ImageHotspotOptions
32
- },
33
- ): ReactNode
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,14 +1,19 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { c } from "react/compiler-runtime";
2
3
  import { getImageDimensions } from "@sanity/asset-utils";
3
- import imageUrlBuilder from "@sanity/image-url";
4
- import { Card, Text, Tooltip, Box, Stack, Flex } from "@sanity/ui";
4
+ import { createImageUrlBuilder } from "@sanity/image-url";
5
+ import { Card, Text, Box, Tooltip, Flex, Stack } from "@sanity/ui";
5
6
  import { randomKey } from "@sanity/util/content";
6
- import { get } from "lodash-es";
7
- import { useState, useEffect, useCallback, createElement, useRef, useMemo } from "react";
7
+ import get from "lodash-es/get.js";
8
+ import { useState, useEffect, useRef, useMemo } from "react";
8
9
  import { useClient, useFormValue, useResolveInitialValueForType, PatchEvent, setIfMissing, insert, set, definePlugin } from "sanity";
9
10
  import { useMotionValue, motion } from "framer-motion";
10
- function Feedback({ children }) {
11
- return /* @__PURE__ */ jsx(Card, { padding: 4, radius: 2, shadow: 1, tone: "caution", children: /* @__PURE__ */ jsx(Text, { children }) });
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;
12
17
  }
13
18
  const dragStyle = {
14
19
  width: "1.4rem",
@@ -54,79 +59,107 @@ const dragStyle = {
54
59
  }, labelStyleWhileActive = {
55
60
  visibility: "hidden"
56
61
  }, round = (num) => Math.round(num * 100) / 100;
57
- function Spot({
58
- value,
59
- bounds,
60
- update,
61
- hotspotDescriptionPath,
62
- tooltip,
63
- index,
64
- schemaType,
65
- renderPreview
66
- }) {
67
- const [isDragging, setIsDragging] = useState(!1), [isHovering, setIsHovering] = useState(!1), x = useMotionValue(round(bounds.width * (value.x / 100))), y = useMotionValue(round(bounds.height * (value.y / 100)));
68
- useEffect(() => {
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 = () => {
69
81
  x.set(round(bounds.width * (value.x / 100))), y.set(round(bounds.height * (value.y / 100)));
70
- }, [x, y, value, bounds]);
71
- const handleDragEnd = useCallback(() => {
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 = () => {
72
87
  setIsDragging(!1);
73
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));
74
89
  update(value._key, safeX, safeY);
75
- }, [x, y, value, update, bounds]), handleDragStart = useCallback(() => setIsDragging(!0), []), handleHoverStart = useCallback(() => setIsHovering(!0), []), handleHoverEnd = useCallback(() => setIsHovering(!1), []);
76
- return !x || !y ? null : /* @__PURE__ */ jsx(
77
- motion.div,
78
- {
79
- drag: !0,
80
- dragConstraints: bounds,
81
- dragElastic: 0,
82
- dragMomentum: !1,
83
- onDragEnd: handleDragEnd,
84
- onDragStart: handleDragStart,
85
- onHoverStart: handleHoverStart,
86
- onHoverEnd: handleHoverEnd,
87
- style: {
88
- ...dragStyle,
89
- x,
90
- y,
91
- ...isDragging && { ...dragStyleWhileDrag },
92
- ...isHovering && { ...dragStyleWhileHover }
93
- },
94
- children: /* @__PURE__ */ jsx(
95
- Tooltip,
96
- {
97
- disabled: isDragging,
98
- portal: !0,
99
- content: tooltip && typeof tooltip == "function" ? createElement(tooltip, { value, renderPreview, schemaType }) : /* @__PURE__ */ jsx(Box, { padding: 2, style: { maxWidth: 200, pointerEvents: "none" }, children: /* @__PURE__ */ jsx(Text, { textOverflow: "ellipsis", children: hotspotDescriptionPath ? get(value, hotspotDescriptionPath) : `${value.x}% x ${value.y}%` }) }),
100
- children: /* @__PURE__ */ jsxs("div", { children: [
101
- /* @__PURE__ */ jsx(
102
- Box,
103
- {
104
- style: {
105
- ...dotStyle,
106
- ...(isDragging || isHovering) && { ...dotStyleWhileActive }
107
- }
108
- }
109
- ),
110
- /* @__PURE__ */ jsx(
111
- "div",
112
- {
113
- style: {
114
- ...labelStyle,
115
- ...(isDragging || isHovering) && { ...labelStyleWhileActive }
116
- },
117
- children: index + 1
118
- }
119
- )
120
- ] })
121
- },
122
- value._key
123
- )
124
- }
125
- );
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;
126
154
  }
127
155
  function useUnmountEffect(effect) {
128
- const effectRef = useRef(effect);
129
- effectRef.current = effect, useEffect(() => () => effectRef.current(), []);
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);
130
163
  }
131
164
  function useDebouncedCallback(callback, deps, delay, maxWait = 0) {
132
165
  const timeout = useRef(void 0), waitTimeout = useRef(void 0), cb = useRef(callback), lastCall = useRef(void 0), clear = () => {
@@ -140,11 +173,18 @@ function useDebouncedCallback(callback, deps, delay, maxWait = 0) {
140
173
  const context = lastCall.current;
141
174
  lastCall.current = void 0, cb.current.apply(context.this, context.args);
142
175
  }, wrapped = function(...args) {
143
- timeout.current && clearTimeout(timeout.current), lastCall.current = { args, this: this }, timeout.current = setTimeout(execute, delay), maxWait > 0 && !waitTimeout.current && (waitTimeout.current = setTimeout(execute, maxWait));
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));
144
180
  };
145
181
  return Object.defineProperties(wrapped, {
146
- length: { value: callback.length },
147
- name: { value: `${callback.name || "anonymous"}__debounced__${delay}` }
182
+ length: {
183
+ value: callback.length
184
+ },
185
+ name: {
186
+ value: `${callback.name || "anonymous"}__debounced__${delay}`
187
+ }
148
188
  }), wrapped;
149
189
  }, [delay, maxWait, ...deps]);
150
190
  }
@@ -154,12 +194,9 @@ function getResizeObserver() {
154
194
  if (!isBrowser) return;
155
195
  if (observerSingleton) return observerSingleton;
156
196
  const callbacks = /* @__PURE__ */ new Map(), observer = new ResizeObserver((entries) => {
157
- for (const entry of entries)
158
- callbacks.get(entry.target)?.forEach(
159
- (cb) => setTimeout(() => {
160
- cb(entry);
161
- }, 0)
162
- );
197
+ for (const entry of entries) callbacks.get(entry.target)?.forEach((cb) => setTimeout(() => {
198
+ cb(entry);
199
+ }, 0));
163
200
  });
164
201
  return observerSingleton = {
165
202
  observer,
@@ -175,7 +212,9 @@ function getResizeObserver() {
175
212
  }
176
213
  function useResizeObserver(target, callback, enabled = !0) {
177
214
  const ro = enabled && getResizeObserver(), cb = useRef(callback);
178
- cb.current = callback;
215
+ useEffect(() => {
216
+ cb.current = callback;
217
+ }, [callback]);
179
218
  const tgt = target && "current" in target ? target.current : target;
180
219
  useEffect(() => {
181
220
  const _tgt = target && "current" in target ? target.current : target;
@@ -189,96 +228,126 @@ function useResizeObserver(target, callback, enabled = !0) {
189
228
  };
190
229
  }, [tgt, ro]);
191
230
  }
192
- const imageStyle = { width: "100%", height: "auto" }, VALID_ROOT_PATHS = ["document", "parent"];
231
+ const imageStyle = {
232
+ width: "100%",
233
+ height: "auto"
234
+ }, VALID_ROOT_PATHS = ["document", "parent"];
193
235
  function ImageHotspotArray(props) {
194
- const { value, onChange, imageHotspotOptions, schemaType, renderPreview } = props, sanityClient = useClient({ apiVersion: "2022-01-01" }), imageHotspotPathRoot = useMemo(() => (VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot ?? "") ? imageHotspotOptions.pathRoot : "document") === "document" ? [] : props.path.slice(0, -1), [imageHotspotOptions.pathRoot, props.path]), rootObject = useFormValue(imageHotspotPathRoot), resolveInitialValueForType = useResolveInitialValueForType(), resolveInitialValue = useCallback(
195
- async (type) => resolveInitialValueForType(type, {}).then((initialValue) => initialValue).catch(() => {
196
- }),
197
- [resolveInitialValueForType]
198
- ), hotspotImage = useMemo(() => imageHotspotOptions.imagePath ? get(rootObject, imageHotspotOptions.imagePath) : rootObject, [rootObject, imageHotspotOptions.imagePath]), displayImage = useMemo(() => {
199
- const builder = imageUrlBuilder(sanityClient).dataset(sanityClient.config().dataset ?? ""), urlFor = (source) => builder.image(source);
200
- if (hotspotImage?.asset?._ref) {
201
- const { aspectRatio } = getImageDimensions(hotspotImage.asset._ref), width = 1200, height = Math.round(width / aspectRatio), url = urlFor(hotspotImage).width(width).url();
202
- return { width, height, url };
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;
203
279
  }
204
- return null;
205
- }, [hotspotImage, sanityClient]), handleHotspotImageClick = useCallback(
206
- async (event) => {
207
- const { nativeEvent, currentTarget } = 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(schemaType.of[0].type), newRow = {
208
- _key: randomKey(12),
209
- _type: schemaType.of[0].name,
210
- ...initialValues,
211
- x,
212
- y
213
- };
214
- imageHotspotOptions?.descriptionPath && (newRow[imageHotspotOptions.descriptionPath] = description), onChange(PatchEvent.from([setIfMissing([]), insert([newRow], "after", [-1])]));
215
- },
216
- [imageHotspotOptions, onChange, resolveInitialValue, schemaType]
217
- ), handleHotspotMove = useCallback(
218
- (key, x, y) => {
219
- onChange(
220
- PatchEvent.from([
221
- // Set the `x` value of this array key item
222
- set(x, [{ _key: key }, "x"]),
223
- // Set the `y` value of this array key item
224
- set(y, [{ _key: key }, "y"])
225
- ])
226
- );
227
- },
228
- [onChange]
229
- ), hotspotImageRef = useRef(null), [imageRect, setImageRect] = useState();
230
- return useResizeObserver(
231
- hotspotImageRef,
232
- useDebouncedCallback(
233
- (e) => setImageRect(e.contentRect),
234
- [setImageRect],
235
- 200
236
- )
237
- ), /* @__PURE__ */ jsxs(Stack, { space: [2, 2, 3], children: [
238
- displayImage?.url ? /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
239
- imageRect && (value?.length ?? 0) > 0 && value?.map((spot, index) => /* @__PURE__ */ jsx(
240
- Spot,
241
- {
242
- index,
243
- value: spot,
244
- bounds: imageRect,
245
- update: handleHotspotMove,
246
- hotspotDescriptionPath: imageHotspotOptions?.descriptionPath,
247
- tooltip: imageHotspotOptions?.tooltip,
248
- renderPreview,
249
- schemaType: schemaType.of[0]
250
- },
251
- spot._key
252
- )),
253
- /* @__PURE__ */ jsx(Card, { __unstable_checkered: !0, shadow: 1, children: /* @__PURE__ */ jsx(Flex, { align: "center", justify: "center", children: /* @__PURE__ */ jsx(
254
- "img",
255
- {
256
- ref: hotspotImageRef,
257
- src: displayImage.url,
258
- width: displayImage.width,
259
- height: displayImage.height,
260
- alt: "",
261
- style: imageStyle,
262
- onClick: handleHotspotImageClick
263
- }
264
- ) }) })
265
- ] }) : /* @__PURE__ */ jsx(Feedback, { children: imageHotspotOptions.imagePath ? /* @__PURE__ */ jsxs(Fragment, { children: [
266
- "No Hotspot image found at path ",
267
- /* @__PURE__ */ jsx("code", { children: imageHotspotOptions.imagePath })
268
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
269
- "Define a path in this field using to the image field in this document at",
270
- " ",
271
- /* @__PURE__ */ jsx("code", { children: "options.hotspotImagePath" })
272
- ] }) }),
273
- imageHotspotOptions.pathRoot && !VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot) && /* @__PURE__ */ jsxs(Feedback, { children: [
274
- 'The supplied imageHotspotPathRoot "',
275
- imageHotspotOptions.pathRoot,
276
- '" is not valid, falling back to "document". Available values are "',
277
- VALID_ROOT_PATHS.join(", "),
278
- '".'
279
- ] }),
280
- props.renderDefault(props)
281
- ] });
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;
282
351
  }
283
352
  const imageHotspotArrayPlugin = definePlugin({
284
353
  name: "image-hotspot-array",