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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Sanity.io
3
+ Copyright (c) 2026 Sanity.io
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/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,12 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var jsxRuntime = require("react/jsx-runtime"), assetUtils = require("@sanity/asset-utils"), imageUrlBuilder = require("@sanity/image-url"), ui = require("@sanity/ui"), content = require("@sanity/util/content"), lodashEs = require("lodash-es"), react = require("react"), sanity = require("sanity"), framerMotion = require("framer-motion");
4
- function _interopDefaultCompat(e) {
5
- return e && typeof e == "object" && "default" in e ? e : { default: e };
6
- }
7
- var imageUrlBuilder__default = /* @__PURE__ */ _interopDefaultCompat(imageUrlBuilder);
8
- function Feedback({ children }) {
9
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 4, radius: 2, shadow: 1, tone: "caution", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children }) });
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
- value,
57
- bounds,
58
- update,
59
- hotspotDescriptionPath,
60
- tooltip,
61
- index,
62
- schemaType,
63
- renderPreview
64
- }) {
65
- const [isDragging, setIsDragging] = react.useState(!1), [isHovering, setIsHovering] = react.useState(!1), x = framerMotion.useMotionValue(round(bounds.width * (value.x / 100))), y = framerMotion.useMotionValue(round(bounds.height * (value.y / 100)));
66
- react.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 = () => {
67
81
  x.set(round(bounds.width * (value.x / 100))), y.set(round(bounds.height * (value.y / 100)));
68
- }, [x, y, value, bounds]);
69
- const handleDragEnd = react.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 = () => {
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
- }, [x, y, value, update, bounds]), handleDragStart = react.useCallback(() => setIsDragging(!0), []), handleHoverStart = react.useCallback(() => setIsHovering(!0), []), handleHoverEnd = react.useCallback(() => setIsHovering(!1), []);
74
- return !x || !y ? null : /* @__PURE__ */ jsxRuntime.jsx(
75
- framerMotion.motion.div,
76
- {
77
- drag: !0,
78
- dragConstraints: bounds,
79
- dragElastic: 0,
80
- dragMomentum: !1,
81
- onDragEnd: handleDragEnd,
82
- onDragStart: handleDragStart,
83
- onHoverStart: handleHoverStart,
84
- onHoverEnd: handleHoverEnd,
85
- style: {
86
- ...dragStyle,
87
- x,
88
- y,
89
- ...isDragging && { ...dragStyleWhileDrag },
90
- ...isHovering && { ...dragStyleWhileHover }
91
- },
92
- children: /* @__PURE__ */ jsxRuntime.jsx(
93
- ui.Tooltip,
94
- {
95
- disabled: isDragging,
96
- portal: !0,
97
- content: tooltip && typeof tooltip == "function" ? react.createElement(tooltip, { value, renderPreview, schemaType }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, style: { maxWidth: 200, pointerEvents: "none" }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { textOverflow: "ellipsis", children: hotspotDescriptionPath ? lodashEs.get(value, hotspotDescriptionPath) : `${value.x}% x ${value.y}%` }) }),
98
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
99
- /* @__PURE__ */ jsxRuntime.jsx(
100
- ui.Box,
101
- {
102
- style: {
103
- ...dotStyle,
104
- ...(isDragging || isHovering) && { ...dotStyleWhileActive }
105
- }
106
- }
107
- ),
108
- /* @__PURE__ */ jsxRuntime.jsx(
109
- "div",
110
- {
111
- style: {
112
- ...labelStyle,
113
- ...(isDragging || isHovering) && { ...labelStyleWhileActive }
114
- },
115
- children: index + 1
116
- }
117
- )
118
- ] })
119
- },
120
- value._key
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 = react.useRef(effect);
127
- effectRef.current = effect, react.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);
128
163
  }
129
164
  function useDebouncedCallback(callback, deps, delay, maxWait = 0) {
130
- const timeout = react.useRef(void 0), waitTimeout = react.useRef(void 0), cb = react.useRef(callback), lastCall = react.useRef(void 0), clear = () => {
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), react.useEffect(() => {
168
+ return useUnmountEffect(clear), useEffect(() => {
134
169
  cb.current = callback;
135
- }, deps), react.useMemo(() => {
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 = { 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));
142
180
  };
143
181
  return Object.defineProperties(wrapped, {
144
- length: { value: callback.length },
145
- name: { value: `${callback.name || "anonymous"}__debounced__${delay}` }
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
- callbacks.get(entry.target)?.forEach(
157
- (cb) => setTimeout(() => {
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 = react.useRef(callback);
176
- cb.current = callback;
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
- react.useEffect(() => {
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 = { width: "100%", height: "auto" }, VALID_ROOT_PATHS = ["document", "parent"];
231
+ const imageStyle = {
232
+ width: "100%",
233
+ height: "auto"
234
+ }, VALID_ROOT_PATHS = ["document", "parent"];
191
235
  function ImageHotspotArray(props) {
192
- const { value, onChange, imageHotspotOptions, schemaType, renderPreview } = props, sanityClient = sanity.useClient({ apiVersion: "2022-01-01" }), imageHotspotPathRoot = react.useMemo(() => (VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot ?? "") ? imageHotspotOptions.pathRoot : "document") === "document" ? [] : props.path.slice(0, -1), [imageHotspotOptions.pathRoot, props.path]), rootObject = sanity.useFormValue(imageHotspotPathRoot), resolveInitialValueForType = sanity.useResolveInitialValueForType(), resolveInitialValue = react.useCallback(
193
- async (type) => resolveInitialValueForType(type, {}).then((initialValue) => initialValue).catch(() => {
194
- }),
195
- [resolveInitialValueForType]
196
- ), hotspotImage = react.useMemo(() => imageHotspotOptions.imagePath ? lodashEs.get(rootObject, imageHotspotOptions.imagePath) : rootObject, [rootObject, imageHotspotOptions.imagePath]), displayImage = react.useMemo(() => {
197
- const builder = imageUrlBuilder__default.default(sanityClient).dataset(sanityClient.config().dataset ?? ""), urlFor = (source) => builder.image(source);
198
- if (hotspotImage?.asset?._ref) {
199
- const { aspectRatio } = assetUtils.getImageDimensions(hotspotImage.asset._ref), width = 1200, height = Math.round(width / aspectRatio), url = urlFor(hotspotImage).width(width).url();
200
- 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;
201
279
  }
202
- return null;
203
- }, [hotspotImage, sanityClient]), handleHotspotImageClick = react.useCallback(
204
- async (event) => {
205
- 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 = {
206
- _key: content.randomKey(12),
207
- _type: schemaType.of[0].name,
208
- ...initialValues,
209
- x,
210
- y
211
- };
212
- imageHotspotOptions?.descriptionPath && (newRow[imageHotspotOptions.descriptionPath] = description), onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert([newRow], "after", [-1])]));
213
- },
214
- [imageHotspotOptions, onChange, resolveInitialValue, schemaType]
215
- ), handleHotspotMove = react.useCallback(
216
- (key, x, y) => {
217
- onChange(
218
- sanity.PatchEvent.from([
219
- // Set the `x` value of this array key item
220
- sanity.set(x, [{ _key: key }, "x"]),
221
- // Set the `y` value of this array key item
222
- sanity.set(y, [{ _key: key }, "y"])
223
- ])
224
- );
225
- },
226
- [onChange]
227
- ), hotspotImageRef = react.useRef(null), [imageRect, setImageRect] = react.useState();
228
- return useResizeObserver(
229
- hotspotImageRef,
230
- useDebouncedCallback(
231
- (e) => setImageRect(e.contentRect),
232
- [setImageRect],
233
- 200
234
- )
235
- ), /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: [2, 2, 3], children: [
236
- displayImage?.url ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
237
- imageRect && (value?.length ?? 0) > 0 && value?.map((spot, index) => /* @__PURE__ */ jsxRuntime.jsx(
238
- Spot,
239
- {
240
- index,
241
- value: spot,
242
- bounds: imageRect,
243
- update: handleHotspotMove,
244
- hotspotDescriptionPath: imageHotspotOptions?.descriptionPath,
245
- tooltip: imageHotspotOptions?.tooltip,
246
- renderPreview,
247
- schemaType: schemaType.of[0]
248
- },
249
- spot._key
250
- )),
251
- /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { __unstable_checkered: !0, shadow: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", justify: "center", children: /* @__PURE__ */ jsxRuntime.jsx(
252
- "img",
253
- {
254
- ref: hotspotImageRef,
255
- src: displayImage.url,
256
- width: displayImage.width,
257
- height: displayImage.height,
258
- alt: "",
259
- style: imageStyle,
260
- onClick: handleHotspotImageClick
261
- }
262
- ) }) })
263
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(Feedback, { children: imageHotspotOptions.imagePath ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
264
- "No Hotspot image found at path ",
265
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: imageHotspotOptions.imagePath })
266
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
267
- "Define a path in this field using to the image field in this document at",
268
- " ",
269
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: "options.hotspotImagePath" })
270
- ] }) }),
271
- imageHotspotOptions.pathRoot && !VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot) && /* @__PURE__ */ jsxRuntime.jsxs(Feedback, { children: [
272
- 'The supplied imageHotspotPathRoot "',
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 = sanity.definePlugin({
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__ */ jsxRuntime.jsx(
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
- exports.ImageHotspotArray = ImageHotspotArray;
303
- exports.imageHotspotArrayPlugin = imageHotspotArrayPlugin;
373
+ export {
374
+ ImageHotspotArray,
375
+ imageHotspotArrayPlugin
376
+ };
304
377
  //# sourceMappingURL=index.js.map