sanity-plugin-hotspot-array 1.0.1 → 2.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 +2 -2
- package/dist/index.d.mts +54 -0
- package/{lib/src → dist}/index.d.ts +10 -11
- package/dist/index.js +310 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +314 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -38
- package/src/Feedback.tsx +2 -2
- package/src/ImageHotspotArray.tsx +28 -25
- package/src/Spot.tsx +20 -12
- package/src/index.ts +1 -2
- package/src/plugin.tsx +4 -3
- package/src/useDebouncedCallback.ts +102 -0
- package/src/useResizeObserver.ts +123 -0
- package/lib/index.esm.js +0 -2
- package/lib/index.esm.js.map +0 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -27,12 +27,12 @@ yarn add sanity-plugin-hotspot-array
|
|
|
27
27
|
Add it as a plugin in sanity.config.ts (or .js):
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
|
-
import {
|
|
30
|
+
import { imageHotspotArrayPlugin } from "sanity-plugin-hotspot-array";
|
|
31
31
|
|
|
32
32
|
export default defineConfig({
|
|
33
33
|
// ...
|
|
34
34
|
plugins: [
|
|
35
|
-
|
|
35
|
+
imageHotspotArrayPlugin(),
|
|
36
36
|
]
|
|
37
37
|
})
|
|
38
38
|
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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
|
|
27
|
+
}
|
|
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>>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {}
|
|
49
|
+
|
|
50
|
+
declare module '@sanity/types' {
|
|
51
|
+
interface ArrayOptions {
|
|
52
|
+
imageHotspot?: ImageHotspotOptions
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
|
|
3
1
|
import {ArrayOfObjectsInputProps} from 'sanity'
|
|
4
2
|
import {ComponentType} from 'react'
|
|
5
3
|
import {ObjectSchemaType} from 'sanity'
|
|
6
4
|
import {Plugin as Plugin_2} from 'sanity'
|
|
5
|
+
import {ReactNode} from 'react'
|
|
7
6
|
import {RenderPreviewCallback} from 'sanity'
|
|
8
7
|
|
|
9
8
|
export declare type HotspotItem<
|
|
10
9
|
HotspotFields = {
|
|
11
10
|
[key: string]: unknown
|
|
12
|
-
}
|
|
11
|
+
},
|
|
13
12
|
> = {
|
|
14
13
|
_key: string
|
|
15
14
|
_type: string
|
|
@@ -20,7 +19,7 @@ export declare type HotspotItem<
|
|
|
20
19
|
export declare interface HotspotTooltipProps<
|
|
21
20
|
HotspotFields = {
|
|
22
21
|
[key: string]: unknown
|
|
23
|
-
}
|
|
22
|
+
},
|
|
24
23
|
> {
|
|
25
24
|
value: HotspotItem<HotspotFields>
|
|
26
25
|
schemaType: ObjectSchemaType
|
|
@@ -30,15 +29,15 @@ export declare interface HotspotTooltipProps<
|
|
|
30
29
|
export declare function ImageHotspotArray(
|
|
31
30
|
props: ArrayOfObjectsInputProps<HotspotItem> & {
|
|
32
31
|
imageHotspotOptions: ImageHotspotOptions
|
|
33
|
-
}
|
|
34
|
-
):
|
|
32
|
+
},
|
|
33
|
+
): ReactNode
|
|
35
34
|
|
|
36
35
|
export declare const imageHotspotArrayPlugin: Plugin_2<void>
|
|
37
36
|
|
|
38
37
|
export declare interface ImageHotspotOptions<
|
|
39
38
|
HotspotFields = {
|
|
40
39
|
[key: string]: unknown
|
|
41
|
-
}
|
|
40
|
+
},
|
|
42
41
|
> {
|
|
43
42
|
pathRoot?: 'document' | 'parent'
|
|
44
43
|
imagePath: string
|
|
@@ -49,7 +48,7 @@ export declare interface ImageHotspotOptions<
|
|
|
49
48
|
export {}
|
|
50
49
|
|
|
51
50
|
declare module '@sanity/types' {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
51
|
+
interface ArrayOptions {
|
|
52
|
+
imageHotspot?: ImageHotspotOptions
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
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 }) });
|
|
10
|
+
}
|
|
11
|
+
const dragStyle = {
|
|
12
|
+
width: "1.4rem",
|
|
13
|
+
height: "1.4rem",
|
|
14
|
+
position: "absolute",
|
|
15
|
+
boxSizing: "border-box",
|
|
16
|
+
top: 0,
|
|
17
|
+
left: 0,
|
|
18
|
+
margin: "-0.7rem 0 0 -0.7rem",
|
|
19
|
+
cursor: "pointer",
|
|
20
|
+
display: "flex",
|
|
21
|
+
justifyContent: "center",
|
|
22
|
+
alignItems: "center",
|
|
23
|
+
borderRadius: "50%",
|
|
24
|
+
background: "#000",
|
|
25
|
+
color: "white"
|
|
26
|
+
}, dragStyleWhileDrag = {
|
|
27
|
+
background: "rgba(0, 0, 0, 0.1)",
|
|
28
|
+
border: "1px solid #fff",
|
|
29
|
+
cursor: "none"
|
|
30
|
+
}, dragStyleWhileHover = {
|
|
31
|
+
background: "rgba(0, 0, 0, 0.1)",
|
|
32
|
+
border: "1px solid #fff"
|
|
33
|
+
}, dotStyle = {
|
|
34
|
+
position: "absolute",
|
|
35
|
+
left: "50%",
|
|
36
|
+
top: "50%",
|
|
37
|
+
height: "0.2rem",
|
|
38
|
+
width: "0.2rem",
|
|
39
|
+
margin: "-0.1rem 0 0 -0.1rem",
|
|
40
|
+
background: "#fff",
|
|
41
|
+
visibility: "hidden",
|
|
42
|
+
borderRadius: "50%",
|
|
43
|
+
// make sure pointer events only run on the parent
|
|
44
|
+
pointerEvents: "none"
|
|
45
|
+
}, dotStyleWhileActive = {
|
|
46
|
+
visibility: "visible"
|
|
47
|
+
}, labelStyle = {
|
|
48
|
+
color: "white",
|
|
49
|
+
fontSize: "0.7rem",
|
|
50
|
+
fontWeight: 600,
|
|
51
|
+
lineHeight: "1"
|
|
52
|
+
}, labelStyleWhileActive = {
|
|
53
|
+
visibility: "hidden"
|
|
54
|
+
}, 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(() => {
|
|
67
|
+
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(() => {
|
|
70
|
+
setIsDragging(!1);
|
|
71
|
+
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
|
+
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
|
+
ui.Tooltip,
|
|
76
|
+
{
|
|
77
|
+
disabled: isDragging,
|
|
78
|
+
portal: !0,
|
|
79
|
+
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}%` }) }),
|
|
80
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
81
|
+
framerMotion.motion.div,
|
|
82
|
+
{
|
|
83
|
+
drag: !0,
|
|
84
|
+
dragConstraints: bounds,
|
|
85
|
+
dragElastic: 0,
|
|
86
|
+
dragMomentum: !1,
|
|
87
|
+
onDragEnd: handleDragEnd,
|
|
88
|
+
onDragStart: handleDragStart,
|
|
89
|
+
onHoverStart: handleHoverStart,
|
|
90
|
+
onHoverEnd: handleHoverEnd,
|
|
91
|
+
style: {
|
|
92
|
+
...dragStyle,
|
|
93
|
+
x,
|
|
94
|
+
y,
|
|
95
|
+
...isDragging && { ...dragStyleWhileDrag },
|
|
96
|
+
...isHovering && { ...dragStyleWhileHover }
|
|
97
|
+
},
|
|
98
|
+
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
|
+
)
|
|
121
|
+
},
|
|
122
|
+
value._key
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
function useUnmountEffect(effect) {
|
|
126
|
+
const effectRef = react.useRef(effect);
|
|
127
|
+
effectRef.current = effect, react.useEffect(() => () => effectRef.current(), []);
|
|
128
|
+
}
|
|
129
|
+
function useDebouncedCallback(callback, deps, delay, maxWait = 0) {
|
|
130
|
+
const timeout = react.useRef(), waitTimeout = react.useRef(), cb = react.useRef(callback), lastCall = react.useRef(), clear = () => {
|
|
131
|
+
timeout.current && (clearTimeout(timeout.current), timeout.current = void 0), waitTimeout.current && (clearTimeout(waitTimeout.current), waitTimeout.current = void 0);
|
|
132
|
+
};
|
|
133
|
+
return useUnmountEffect(clear), react.useEffect(() => {
|
|
134
|
+
cb.current = callback;
|
|
135
|
+
}, deps), react.useMemo(() => {
|
|
136
|
+
const execute = () => {
|
|
137
|
+
if (clear(), !lastCall.current)
|
|
138
|
+
return;
|
|
139
|
+
const context = lastCall.current;
|
|
140
|
+
lastCall.current = void 0, cb.current.apply(context.this, context.args);
|
|
141
|
+
}, wrapped = function(...args) {
|
|
142
|
+
timeout.current && clearTimeout(timeout.current), lastCall.current = { args, this: this }, timeout.current = setTimeout(execute, delay), maxWait > 0 && !waitTimeout.current && (waitTimeout.current = setTimeout(execute, maxWait));
|
|
143
|
+
};
|
|
144
|
+
return Object.defineProperties(wrapped, {
|
|
145
|
+
length: { value: callback.length },
|
|
146
|
+
name: { value: `${callback.name || "anonymous"}__debounced__${delay}` }
|
|
147
|
+
}), wrapped;
|
|
148
|
+
}, [delay, maxWait, ...deps]);
|
|
149
|
+
}
|
|
150
|
+
const isBrowser = typeof window < "u" && typeof navigator < "u" && typeof document < "u";
|
|
151
|
+
let observerSingleton;
|
|
152
|
+
function getResizeObserver() {
|
|
153
|
+
if (!isBrowser)
|
|
154
|
+
return;
|
|
155
|
+
if (observerSingleton)
|
|
156
|
+
return observerSingleton;
|
|
157
|
+
const callbacks = /* @__PURE__ */ new Map(), observer = new ResizeObserver((entries) => {
|
|
158
|
+
var _a;
|
|
159
|
+
for (const entry of entries)
|
|
160
|
+
(_a = callbacks.get(entry.target)) == null || _a.forEach(
|
|
161
|
+
(cb) => setTimeout(() => {
|
|
162
|
+
cb(entry);
|
|
163
|
+
}, 0)
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
return observerSingleton = {
|
|
167
|
+
observer,
|
|
168
|
+
subscribe(target, callback) {
|
|
169
|
+
let cbs = callbacks.get(target);
|
|
170
|
+
cbs || (cbs = /* @__PURE__ */ new Set(), callbacks.set(target, cbs), observer.observe(target)), cbs.add(callback);
|
|
171
|
+
},
|
|
172
|
+
unsubscribe(target, callback) {
|
|
173
|
+
const cbs = callbacks.get(target);
|
|
174
|
+
cbs && (cbs.delete(callback), cbs.size === 0 && (callbacks.delete(target), observer.unobserve(target)));
|
|
175
|
+
}
|
|
176
|
+
}, observerSingleton;
|
|
177
|
+
}
|
|
178
|
+
function useResizeObserver(target, callback, enabled = !0) {
|
|
179
|
+
const ro = enabled && getResizeObserver(), cb = react.useRef(callback);
|
|
180
|
+
cb.current = callback;
|
|
181
|
+
const tgt = target && "current" in target ? target.current : target;
|
|
182
|
+
react.useEffect(() => {
|
|
183
|
+
const _tgt = target && "current" in target ? target.current : target;
|
|
184
|
+
if (!ro || !_tgt)
|
|
185
|
+
return;
|
|
186
|
+
let subscribed = !0;
|
|
187
|
+
const handler = (...args) => {
|
|
188
|
+
subscribed && cb.current(...args);
|
|
189
|
+
};
|
|
190
|
+
return ro.subscribe(_tgt, handler), () => {
|
|
191
|
+
subscribed = !1, ro.unsubscribe(_tgt, handler);
|
|
192
|
+
};
|
|
193
|
+
}, [tgt, ro]);
|
|
194
|
+
}
|
|
195
|
+
const imageStyle = { width: "100%", height: "auto" }, VALID_ROOT_PATHS = ["document", "parent"];
|
|
196
|
+
function ImageHotspotArray(props) {
|
|
197
|
+
var _a;
|
|
198
|
+
const { value, onChange, imageHotspotOptions, schemaType, renderPreview } = props, sanityClient = sanity.useClient({ apiVersion: "2022-01-01" }), imageHotspotPathRoot = react.useMemo(() => {
|
|
199
|
+
var _a2;
|
|
200
|
+
return (VALID_ROOT_PATHS.includes((_a2 = imageHotspotOptions.pathRoot) != null ? _a2 : "") ? imageHotspotOptions.pathRoot : "document") === "document" ? [] : props.path.slice(0, -1);
|
|
201
|
+
}, [imageHotspotOptions.pathRoot, props.path]), rootObject = sanity.useFormValue(imageHotspotPathRoot), hotspotImage = react.useMemo(() => lodashEs.get(rootObject, imageHotspotOptions.imagePath), [rootObject, imageHotspotOptions.imagePath]), displayImage = react.useMemo(() => {
|
|
202
|
+
var _a2, _b;
|
|
203
|
+
const builder = imageUrlBuilder__default.default(sanityClient).dataset((_a2 = sanityClient.config().dataset) != null ? _a2 : ""), urlFor = (source) => builder.image(source);
|
|
204
|
+
if ((_b = hotspotImage == null ? void 0 : hotspotImage.asset) != null && _b._ref) {
|
|
205
|
+
const { aspectRatio } = assetUtils.getImageDimensions(hotspotImage.asset._ref), width = 1200, height = Math.round(width / aspectRatio), url = urlFor(hotspotImage).width(width).url();
|
|
206
|
+
return { width, height, url };
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
}, [hotspotImage, sanityClient]), handleHotspotImageClick = react.useCallback(
|
|
210
|
+
(event) => {
|
|
211
|
+
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}%`, newRow = {
|
|
212
|
+
_key: content.randomKey(12),
|
|
213
|
+
_type: schemaType.of[0].name,
|
|
214
|
+
x,
|
|
215
|
+
y
|
|
216
|
+
};
|
|
217
|
+
imageHotspotOptions != null && imageHotspotOptions.descriptionPath && (newRow[imageHotspotOptions.descriptionPath] = description), onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert([newRow], "after", [-1])]));
|
|
218
|
+
},
|
|
219
|
+
[imageHotspotOptions, onChange, schemaType]
|
|
220
|
+
), handleHotspotMove = react.useCallback(
|
|
221
|
+
(key, x, y) => {
|
|
222
|
+
onChange(
|
|
223
|
+
sanity.PatchEvent.from([
|
|
224
|
+
// Set the `x` value of this array key item
|
|
225
|
+
sanity.set(x, [{ _key: key }, "x"]),
|
|
226
|
+
// Set the `y` value of this array key item
|
|
227
|
+
sanity.set(y, [{ _key: key }, "y"])
|
|
228
|
+
])
|
|
229
|
+
);
|
|
230
|
+
},
|
|
231
|
+
[onChange]
|
|
232
|
+
), hotspotImageRef = react.useRef(null), [imageRect, setImageRect] = react.useState();
|
|
233
|
+
return useResizeObserver(
|
|
234
|
+
hotspotImageRef,
|
|
235
|
+
useDebouncedCallback(
|
|
236
|
+
(e) => setImageRect(e.contentRect),
|
|
237
|
+
[setImageRect],
|
|
238
|
+
200
|
|
239
|
+
)
|
|
240
|
+
), /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: [2, 2, 3], children: [
|
|
241
|
+
displayImage != null && displayImage.url ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
|
|
242
|
+
imageRect && ((_a = value == null ? void 0 : value.length) != null ? _a : 0) > 0 && (value == null ? void 0 : value.map((spot, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
243
|
+
Spot,
|
|
244
|
+
{
|
|
245
|
+
index,
|
|
246
|
+
value: spot,
|
|
247
|
+
bounds: imageRect,
|
|
248
|
+
update: handleHotspotMove,
|
|
249
|
+
hotspotDescriptionPath: imageHotspotOptions == null ? void 0 : imageHotspotOptions.descriptionPath,
|
|
250
|
+
tooltip: imageHotspotOptions == null ? void 0 : imageHotspotOptions.tooltip,
|
|
251
|
+
renderPreview,
|
|
252
|
+
schemaType: schemaType.of[0]
|
|
253
|
+
},
|
|
254
|
+
spot._key
|
|
255
|
+
))),
|
|
256
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Card, { __unstable_checkered: !0, shadow: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", justify: "center", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
257
|
+
"img",
|
|
258
|
+
{
|
|
259
|
+
ref: hotspotImageRef,
|
|
260
|
+
src: displayImage.url,
|
|
261
|
+
width: displayImage.width,
|
|
262
|
+
height: displayImage.height,
|
|
263
|
+
alt: "",
|
|
264
|
+
style: imageStyle,
|
|
265
|
+
onClick: handleHotspotImageClick
|
|
266
|
+
}
|
|
267
|
+
) }) })
|
|
268
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(Feedback, { children: imageHotspotOptions.imagePath ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
269
|
+
"No Hotspot image found at path ",
|
|
270
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: imageHotspotOptions.imagePath })
|
|
271
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
272
|
+
"Define a path in this field using to the image field in this document at",
|
|
273
|
+
" ",
|
|
274
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: "options.hotspotImagePath" })
|
|
275
|
+
] }) }),
|
|
276
|
+
imageHotspotOptions.pathRoot && !VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot) && /* @__PURE__ */ jsxRuntime.jsxs(Feedback, { children: [
|
|
277
|
+
'The supplied imageHotspotPathRoot "',
|
|
278
|
+
imageHotspotOptions.pathRoot,
|
|
279
|
+
'" is not valid, falling back to "document". Available values are "',
|
|
280
|
+
VALID_ROOT_PATHS.join(", "),
|
|
281
|
+
'".'
|
|
282
|
+
] }),
|
|
283
|
+
props.renderDefault(props)
|
|
284
|
+
] });
|
|
285
|
+
}
|
|
286
|
+
const imageHotspotArrayPlugin = sanity.definePlugin({
|
|
287
|
+
name: "image-hotspot-array",
|
|
288
|
+
form: {
|
|
289
|
+
components: {
|
|
290
|
+
input: (props) => {
|
|
291
|
+
var _a, _b;
|
|
292
|
+
if (props.schemaType.jsonType === "array" && (_a = props.schemaType.options) != null && _a.imageHotspot) {
|
|
293
|
+
const imageHotspotOptions = (_b = props.schemaType.options) == null ? void 0 : _b.imageHotspot;
|
|
294
|
+
if (imageHotspotOptions)
|
|
295
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
296
|
+
ImageHotspotArray,
|
|
297
|
+
{
|
|
298
|
+
...props,
|
|
299
|
+
imageHotspotOptions
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return props.renderDefault(props);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
exports.ImageHotspotArray = ImageHotspotArray;
|
|
309
|
+
exports.imageHotspotArrayPlugin = imageHotspotArrayPlugin;
|
|
310
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Feedback.tsx","../src/Spot.tsx","../src/useDebouncedCallback.ts","../src/useResizeObserver.ts","../src/ImageHotspotArray.tsx","../src/plugin.tsx"],"sourcesContent":["import {Card, Text} from '@sanity/ui'\nimport {type ReactNode} from 'react'\n\nexport default function Feedback({children}: {children: ReactNode}): ReactNode {\n return (\n <Card padding={4} radius={2} shadow={1} tone=\"caution\">\n <Text>{children}</Text>\n </Card>\n )\n}\n","import {Box, Text, Tooltip} from '@sanity/ui'\nimport {motion, useMotionValue} from 'framer-motion'\nimport {get} from 'lodash-es'\nimport {\n ComponentType,\n createElement,\n CSSProperties,\n ReactNode,\n useCallback,\n useEffect,\n useState,\n} from 'react'\nimport {type ObjectSchemaType, type RenderPreviewCallback} from 'sanity'\n\nimport {FnHotspotMove, HotspotItem} from './ImageHotspotArray'\n\nconst dragStyle: CSSProperties = {\n width: '1.4rem',\n height: '1.4rem',\n position: 'absolute',\n boxSizing: 'border-box',\n top: 0,\n left: 0,\n margin: '-0.7rem 0 0 -0.7rem',\n cursor: 'pointer',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n borderRadius: '50%',\n background: '#000',\n color: 'white',\n}\n\nconst dragStyleWhileDrag: CSSProperties = {\n background: 'rgba(0, 0, 0, 0.1)',\n border: '1px solid #fff',\n cursor: 'none',\n}\n\nconst dragStyleWhileHover: CSSProperties = {\n background: 'rgba(0, 0, 0, 0.1)',\n border: '1px solid #fff',\n}\n\nconst dotStyle: CSSProperties = {\n position: 'absolute',\n left: '50%',\n top: '50%',\n height: '0.2rem',\n width: '0.2rem',\n margin: '-0.1rem 0 0 -0.1rem',\n background: '#fff',\n visibility: 'hidden',\n borderRadius: '50%',\n // make sure pointer events only run on the parent\n pointerEvents: 'none',\n}\n\nconst dotStyleWhileActive: CSSProperties = {\n visibility: 'visible',\n}\n\nconst labelStyle: CSSProperties = {\n color: 'white',\n fontSize: '0.7rem',\n fontWeight: 600,\n lineHeight: '1',\n}\n\nconst labelStyleWhileActive: CSSProperties = {\n visibility: 'hidden',\n}\n\nconst round = (num: number) => Math.round(num * 100) / 100\n\nexport interface HotspotTooltipProps<HotspotFields = {[key: string]: unknown}> {\n value: HotspotItem<HotspotFields>\n schemaType: ObjectSchemaType\n renderPreview: RenderPreviewCallback\n}\n\ninterface HotspotProps<HotspotFields = {[key: string]: unknown}> {\n value: HotspotItem\n bounds: DOMRectReadOnly\n update: FnHotspotMove\n hotspotDescriptionPath?: string\n tooltip?: ComponentType<HotspotTooltipProps<HotspotFields>>\n index: number\n schemaType: ObjectSchemaType\n renderPreview: RenderPreviewCallback\n}\n\nexport default function Spot({\n value,\n bounds,\n update,\n hotspotDescriptionPath,\n tooltip,\n index,\n schemaType,\n renderPreview,\n}: HotspotProps): ReactNode {\n const [isDragging, setIsDragging] = useState(false)\n const [isHovering, setIsHovering] = useState(false)\n\n // x/y are stored as % but need to be converted to px\n const x = useMotionValue(round(bounds.width * (value.x / 100)))\n const y = useMotionValue(round(bounds.height * (value.y / 100)))\n\n /**\n * update x/y if the bounds change when resizing the window\n */\n useEffect(() => {\n x.set(round(bounds.width * (value.x / 100)))\n y.set(round(bounds.height * (value.y / 100)))\n }, [x, y, value, bounds])\n\n const handleDragEnd = useCallback(() => {\n setIsDragging(false)\n\n // get current values for x/y in px\n const currentX = x.get()\n const currentY = y.get()\n\n // Which we need to convert back to `%` to patch the document\n const newX = round((currentX * 100) / bounds.width)\n const newY = round((currentY * 100) / bounds.height)\n\n // Don't go below 0 or above 100\n const safeX = Math.max(0, Math.min(100, newX))\n const safeY = Math.max(0, Math.min(100, newY))\n\n update(value._key, safeX, safeY)\n }, [x, y, value, update, bounds])\n const handleDragStart = useCallback(() => setIsDragging(true), [])\n\n const handleHoverStart = useCallback(() => setIsHovering(true), [])\n const handleHoverEnd = useCallback(() => setIsHovering(false), [])\n\n if (!x || !y) {\n return null\n }\n\n return (\n <Tooltip\n key={value._key}\n disabled={isDragging}\n portal\n content={\n tooltip && typeof tooltip === 'function' ? (\n createElement(tooltip, {value, renderPreview, schemaType})\n ) : (\n <Box padding={2} style={{maxWidth: 200, pointerEvents: `none`}}>\n <Text textOverflow=\"ellipsis\">\n {hotspotDescriptionPath\n ? (get(value, hotspotDescriptionPath) as string)\n : `${value.x}% x ${value.y}%`}\n </Text>\n </Box>\n )\n }\n >\n <motion.div\n drag\n dragConstraints={bounds}\n dragElastic={0}\n dragMomentum={false}\n onDragEnd={handleDragEnd}\n onDragStart={handleDragStart}\n onHoverStart={handleHoverStart}\n onHoverEnd={handleHoverEnd}\n style={{\n ...dragStyle,\n x,\n y,\n ...(isDragging && {...dragStyleWhileDrag}),\n ...(isHovering && {...dragStyleWhileHover}),\n }}\n >\n {/* Dot */}\n <Box\n style={{\n ...dotStyle,\n ...((isDragging || isHovering) && {...dotStyleWhileActive}),\n }}\n />\n {/* Label */}\n <div\n style={{\n ...labelStyle,\n ...((isDragging || isHovering) && {...labelStyleWhileActive}),\n }}\n >\n {index + 1}\n </div>\n </motion.div>\n </Tooltip>\n )\n}\n","// copied from react-hookz/web\n// https://github.com/react-hookz/web/blob/579a445fcc9f4f4bb5b9d5e670b2e57448b4ee50/src/useDebouncedCallback/index.ts\nimport {type DependencyList, useEffect, useMemo, useRef} from 'react'\n\n/**\n * Run effect only when component is unmounted.\n *\n * @param effect Effector to run on unmount\n */\nexport function useUnmountEffect(effect: CallableFunction): void {\n const effectRef = useRef(effect)\n effectRef.current = effect\n useEffect(() => () => effectRef.current(), [])\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DebouncedFunction<Fn extends (...args: any[]) => any> = (\n this: ThisParameterType<Fn>,\n ...args: Parameters<Fn>\n) => void\n\n/**\n * Makes passed function debounced, otherwise acts like `useCallback`.\n *\n * @param callback Function that will be debounced.\n * @param deps Dependencies list when to update callback. It also replaces invoked\n * \tcallback for scheduled debounced invocations.\n * @param delay Debounce delay.\n * @param maxWait The maximum time `callback` is allowed to be delayed before\n * it's invoked. 0 means no max wait.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useDebouncedCallback<Fn extends (...args: any[]) => any>(\n callback: Fn,\n deps: DependencyList,\n delay: number,\n maxWait = 0,\n): DebouncedFunction<Fn> {\n const timeout = useRef<ReturnType<typeof setTimeout>>()\n const waitTimeout = useRef<ReturnType<typeof setTimeout>>()\n const cb = useRef(callback)\n const lastCall = useRef<{args: Parameters<Fn>; this: ThisParameterType<Fn>}>()\n\n const clear = () => {\n if (timeout.current) {\n clearTimeout(timeout.current)\n timeout.current = undefined\n }\n\n if (waitTimeout.current) {\n clearTimeout(waitTimeout.current)\n waitTimeout.current = undefined\n }\n }\n\n // Cancel scheduled execution on unmount\n useUnmountEffect(clear)\n\n useEffect(() => {\n cb.current = callback\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps)\n\n return useMemo(() => {\n const execute = () => {\n clear()\n\n // Barely possible to test this line\n /* istanbul ignore next */\n if (!lastCall.current) return\n\n const context = lastCall.current\n lastCall.current = undefined\n\n cb.current.apply(context.this, context.args)\n }\n\n const wrapped = function (this, ...args) {\n if (timeout.current) {\n clearTimeout(timeout.current)\n }\n\n lastCall.current = {args, this: this}\n\n // Plan regular execution\n timeout.current = setTimeout(execute, delay)\n\n // Plan maxWait execution if required\n if (maxWait > 0 && !waitTimeout.current) {\n waitTimeout.current = setTimeout(execute, maxWait)\n }\n } as DebouncedFunction<Fn>\n\n Object.defineProperties(wrapped, {\n length: {value: callback.length},\n name: {value: `${callback.name || 'anonymous'}__debounced__${delay}`},\n })\n\n return wrapped\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [delay, maxWait, ...deps])\n}\n","// copied from react-hookz/web\n// https://github.com/react-hookz/web/blob/579a445fcc9f4f4bb5b9d5e670b2e57448b4ee50/src/useResizeObserver/index.ts\nimport {type RefObject, useEffect, useRef} from 'react'\n\nconst isBrowser =\n typeof window !== 'undefined' &&\n typeof navigator !== 'undefined' &&\n typeof document !== 'undefined'\n\nexport type UseResizeObserverCallback = (entry: ResizeObserverEntry) => void\n\ntype ResizeObserverSingleton = {\n observer: ResizeObserver\n subscribe: (target: Element, callback: UseResizeObserverCallback) => void\n unsubscribe: (target: Element, callback: UseResizeObserverCallback) => void\n}\n\nlet observerSingleton: ResizeObserverSingleton\n\nfunction getResizeObserver(): ResizeObserverSingleton | undefined {\n if (!isBrowser) return undefined\n\n if (observerSingleton) return observerSingleton\n\n const callbacks = new Map<Element, Set<UseResizeObserverCallback>>()\n\n const observer = new ResizeObserver((entries) => {\n for (const entry of entries)\n callbacks.get(entry.target)?.forEach((cb) =>\n setTimeout(() => {\n cb(entry)\n }, 0),\n )\n })\n\n observerSingleton = {\n observer,\n subscribe(target, callback) {\n let cbs = callbacks.get(target)\n\n if (!cbs) {\n // If target has no observers yet - register it\n cbs = new Set<UseResizeObserverCallback>()\n callbacks.set(target, cbs)\n observer.observe(target)\n }\n\n // As Set is duplicate-safe - simply add callback on each call\n cbs.add(callback)\n },\n unsubscribe(target, callback) {\n const cbs = callbacks.get(target)\n\n // Else branch should never occur in case of normal execution\n // because callbacks map is hidden in closure - it is impossible to\n // simulate situation with non-existent `cbs` Set\n /* istanbul ignore else */\n if (cbs) {\n // Remove current observer\n cbs.delete(callback)\n\n if (cbs.size === 0) {\n // If no observers left unregister target completely\n callbacks.delete(target)\n observer.unobserve(target)\n }\n }\n },\n }\n\n return observerSingleton\n}\n\n/**\n * Invokes a callback whenever ResizeObserver detects a change to target's size.\n *\n * @param target React reference or Element to track.\n * @param callback Callback that will be invoked on resize.\n * @param enabled Whether resize observer is enabled or not.\n */\nexport function useResizeObserver<T extends Element>(\n target: RefObject<T> | T | null,\n callback: UseResizeObserverCallback,\n enabled = true,\n): void {\n const ro = enabled && getResizeObserver()\n const cb = useRef(callback)\n cb.current = callback\n\n const tgt = target && 'current' in target ? target.current : target\n\n useEffect(() => {\n // This secondary target resolve required for case when we receive ref object, which, most\n // likely, contains null during render stage, but already populated with element during\n // effect stage.\n\n const _tgt = target && 'current' in target ? target.current : target\n\n if (!ro || !_tgt) return undefined\n\n // As unsubscription in internals of our ResizeObserver abstraction can\n // happen a bit later than effect cleanup invocation - we need a marker,\n // that this handler should not be invoked anymore\n let subscribed = true\n\n const handler: UseResizeObserverCallback = (...args) => {\n // It is reinsurance for the highly asynchronous invocations, almost\n // impossible to achieve in tests, thus excluding from LOC\n /* istanbul ignore else */\n if (subscribed) {\n cb.current(...args)\n }\n }\n\n ro.subscribe(_tgt, handler)\n\n return () => {\n subscribed = false\n ro.unsubscribe(_tgt, handler)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tgt, ro])\n}\n","import {getImageDimensions} from '@sanity/asset-utils'\nimport imageUrlBuilder from '@sanity/image-url'\nimport {Card, Flex, Stack} from '@sanity/ui'\nimport {randomKey} from '@sanity/util/content'\nimport {get} from 'lodash-es'\nimport {type MouseEvent, type ReactNode, useCallback, useMemo, useRef, useState} from 'react'\nimport {\n ArrayOfObjectsInputProps,\n ImageValue,\n insert,\n ObjectSchemaType,\n PatchEvent,\n set,\n setIfMissing,\n useClient,\n useFormValue,\n} from 'sanity'\n\nimport Feedback from './Feedback'\nimport {ImageHotspotOptions} from './plugin'\nimport Spot from './Spot'\nimport {useDebouncedCallback} from './useDebouncedCallback'\nimport {useResizeObserver} from './useResizeObserver'\n\nconst imageStyle = {width: `100%`, height: `auto`}\n\nconst VALID_ROOT_PATHS = ['document', 'parent']\n\nexport type FnHotspotMove = (key: string, x: number, y: number) => void\n\nexport type HotspotItem<HotspotFields = {[key: string]: unknown}> = {\n _key: string\n _type: string\n x: number\n y: number\n} & HotspotFields\n\nexport function ImageHotspotArray(\n props: ArrayOfObjectsInputProps<HotspotItem> & {imageHotspotOptions: ImageHotspotOptions},\n): ReactNode {\n const {value, onChange, imageHotspotOptions, schemaType, renderPreview} = props\n\n const sanityClient = useClient({apiVersion: '2022-01-01'})\n\n const imageHotspotPathRoot = useMemo(() => {\n const pathRoot = VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot ?? '')\n ? imageHotspotOptions.pathRoot\n : 'document'\n return pathRoot === 'document' ? [] : props.path.slice(0, -1)\n }, [imageHotspotOptions.pathRoot, props.path])\n\n const rootObject = useFormValue(imageHotspotPathRoot)\n\n /**\n * Finding the image from the imageHotspotPathRoot (defaults to document),\n * using the path from the hotspot's `options` field\n *\n * when changes in imageHotspotPathRoot (e.g. document) occur,\n * check if there are any changes to the hotspotImage and update the reference\n */\n const hotspotImage = useMemo(() => {\n return get(rootObject, imageHotspotOptions.imagePath) as ImageValue | undefined\n }, [rootObject, imageHotspotOptions.imagePath])\n\n const displayImage = useMemo(() => {\n const builder = imageUrlBuilder(sanityClient).dataset(sanityClient.config().dataset ?? '')\n const urlFor = (source: ImageValue) => builder.image(source)\n\n if (hotspotImage?.asset?._ref) {\n const {aspectRatio} = getImageDimensions(hotspotImage.asset._ref)\n const width = 1200\n const height = Math.round(width / aspectRatio)\n const url = urlFor(hotspotImage).width(width).url()\n\n return {width, height, url}\n }\n\n return null\n }, [hotspotImage, sanityClient])\n\n const handleHotspotImageClick = useCallback(\n (event: MouseEvent<HTMLImageElement>) => {\n const {nativeEvent, currentTarget} = event\n\n // Calculate the x/y percentage of the click position\n const x = Number(((nativeEvent.offsetX * 100) / currentTarget.width).toFixed(2))\n const y = Number(((nativeEvent.offsetY * 100) / currentTarget.height).toFixed(2))\n const description = `New Hotspot at ${x}% x ${y}%`\n\n const newRow: HotspotItem = {\n _key: randomKey(12),\n _type: schemaType.of[0].name,\n x,\n y,\n }\n\n if (imageHotspotOptions?.descriptionPath) {\n newRow[imageHotspotOptions.descriptionPath] = description\n }\n\n onChange(PatchEvent.from([setIfMissing([]), insert([newRow], 'after', [-1])]))\n },\n [imageHotspotOptions, onChange, schemaType],\n )\n\n const handleHotspotMove: FnHotspotMove = useCallback(\n (key, x, y) => {\n onChange(\n PatchEvent.from([\n // Set the `x` value of this array key item\n set(x, [{_key: key}, 'x']),\n // Set the `y` value of this array key item\n set(y, [{_key: key}, 'y']),\n ]),\n )\n },\n [onChange],\n )\n\n const hotspotImageRef = useRef<HTMLImageElement | null>(null)\n\n const [imageRect, setImageRect] = useState<DOMRectReadOnly>()\n\n useResizeObserver(\n hotspotImageRef,\n useDebouncedCallback(\n (e: ResizeObserverEntry) => setImageRect(e.contentRect),\n [setImageRect],\n 200,\n ),\n )\n\n return (\n <Stack space={[2, 2, 3]}>\n {displayImage?.url ? (\n <div style={{position: `relative`}}>\n {imageRect &&\n (value?.length ?? 0) > 0 &&\n value?.map((spot, index) => (\n <Spot\n index={index}\n key={spot._key}\n value={spot}\n bounds={imageRect}\n update={handleHotspotMove}\n hotspotDescriptionPath={imageHotspotOptions?.descriptionPath}\n tooltip={imageHotspotOptions?.tooltip}\n renderPreview={renderPreview}\n schemaType={schemaType.of[0] as ObjectSchemaType}\n />\n ))}\n\n <Card __unstable_checkered shadow={1}>\n <Flex align=\"center\" justify=\"center\">\n <img\n ref={hotspotImageRef}\n src={displayImage.url}\n width={displayImage.width}\n height={displayImage.height}\n alt=\"\"\n style={imageStyle}\n onClick={handleHotspotImageClick}\n />\n </Flex>\n </Card>\n </div>\n ) : (\n <Feedback>\n {imageHotspotOptions.imagePath ? (\n <>\n No Hotspot image found at path <code>{imageHotspotOptions.imagePath}</code>\n </>\n ) : (\n <>\n Define a path in this field using to the image field in this document at{' '}\n <code>options.hotspotImagePath</code>\n </>\n )}\n </Feedback>\n )}\n {imageHotspotOptions.pathRoot && !VALID_ROOT_PATHS.includes(imageHotspotOptions.pathRoot) && (\n <Feedback>\n The supplied imageHotspotPathRoot "{imageHotspotOptions.pathRoot}" is not valid,\n falling back to "document". Available values are "\n {VALID_ROOT_PATHS.join(', ')}".\n </Feedback>\n )}\n {props.renderDefault(props as unknown as ArrayOfObjectsInputProps)}\n </Stack>\n )\n}\n","import {ComponentType} from 'react'\nimport {type ArrayOfObjectsInputProps, definePlugin} from 'sanity'\n\nimport {type HotspotItem, ImageHotspotArray} from './ImageHotspotArray'\nimport {type HotspotTooltipProps} from './Spot'\n\nexport interface ImageHotspotOptions<HotspotFields = {[key: string]: unknown}> {\n pathRoot?: 'document' | 'parent'\n imagePath: string\n descriptionPath?: string\n tooltip?: ComponentType<HotspotTooltipProps<HotspotFields>>\n}\n\ndeclare module '@sanity/types' {\n export interface ArrayOptions {\n imageHotspot?: ImageHotspotOptions\n }\n}\n\nexport const imageHotspotArrayPlugin = definePlugin({\n name: 'image-hotspot-array',\n form: {\n components: {\n input: (props) => {\n if (props.schemaType.jsonType === 'array' && props.schemaType.options?.imageHotspot) {\n const imageHotspotOptions = props.schemaType.options?.imageHotspot\n if (imageHotspotOptions) {\n return (\n <ImageHotspotArray\n {...(props as unknown as ArrayOfObjectsInputProps<HotspotItem>)}\n imageHotspotOptions={imageHotspotOptions}\n />\n )\n }\n }\n return props.renderDefault(props)\n },\n },\n },\n})\n"],"names":["jsx","Card","Text","useState","useMotionValue","useEffect","useCallback","Tooltip","createElement","Box","get","jsxs","motion","useRef","useMemo","useClient","_a","useFormValue","imageUrlBuilder","getImageDimensions","randomKey","PatchEvent","setIfMissing","insert","set","Stack","Flex","Fragment","definePlugin"],"mappings":";;;;;;;AAGwB,SAAA,SAAS,EAAC,YAA6C;AAC7E,SACGA,2BAAAA,IAAAC,GAAAA,MAAA,EAAK,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAK,WAC3C,UAACD,2BAAA,IAAAE,GAAA,MAAA,EAAM,UAAS,EAClB,CAAA;AAEJ;ACOA,MAAM,YAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,WAAW;AAAA,EACX,KAAK;AAAA,EACL,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,OAAO;AACT,GAEM,qBAAoC;AAAA,EACxC,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,QAAQ;AACV,GAEM,sBAAqC;AAAA,EACzC,YAAY;AAAA,EACZ,QAAQ;AACV,GAEM,WAA0B;AAAA,EAC9B,UAAU;AAAA,EACV,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAAA;AAAA,EAEd,eAAe;AACjB,GAEM,sBAAqC;AAAA,EACzC,YAAY;AACd,GAEM,aAA4B;AAAA,EAChC,OAAO;AAAA,EACP,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,YAAY;AACd,GAEM,wBAAuC;AAAA,EAC3C,YAAY;AACd,GAEM,QAAQ,CAAC,QAAgB,KAAK,MAAM,MAAM,GAAG,IAAI;AAmBvD,SAAwB,K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