@haklex/rich-ext-gallery 0.0.79 → 0.0.81
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/GalleryNode-CXLSG7vE.js +313 -0
- package/dist/index.mjs +391 -320
- package/dist/rich-ext-gallery.css +2 -1
- package/dist/static.mjs +5 -11
- package/package.json +4 -4
- package/dist/GalleryNode-CV8DRu_G.js +0 -349
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { createRendererDecoration, decodeThumbHash } from "@haklex/rich-editor/renderers";
|
|
2
|
+
import { DecoratorNode } from "lexical";
|
|
3
|
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
4
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import "react-photo-view/dist/react-photo-view.css";
|
|
6
|
+
import { useInView } from "react-intersection-observer";
|
|
7
|
+
import { PhotoProvider, PhotoView } from "react-photo-view";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
//#region src/styles.css.ts
|
|
10
|
+
var gallery = "_10ydd1n0";
|
|
11
|
+
var galleryGrid = "_10ydd1n1";
|
|
12
|
+
var galleryMasonry = "_10ydd1n2";
|
|
13
|
+
var galleryCarousel = "_10ydd1n3";
|
|
14
|
+
var galleryContainer = "_10ydd1n4";
|
|
15
|
+
var galleryItem = "_10ydd1n5";
|
|
16
|
+
var galleryIndicators = "_10ydd1n9";
|
|
17
|
+
var galleryIndicator = "_10ydd1na";
|
|
18
|
+
var galleryEditContainer = "_10ydd1nc";
|
|
19
|
+
var galleryEditOverlay = "_10ydd1nd";
|
|
20
|
+
var galleryEditLabel = "_10ydd1ne";
|
|
21
|
+
var galleryEmptyState = "_10ydd1nf";
|
|
22
|
+
var galleryDialogPopup = "_10ydd1ng";
|
|
23
|
+
var galleryDialogHeader = "_10ydd1nh";
|
|
24
|
+
var galleryDialogTitle = "_10ydd1ni";
|
|
25
|
+
var galleryHeaderActions = "_10ydd1nj";
|
|
26
|
+
var galleryHeaderClose = "_10ydd1nk";
|
|
27
|
+
var galleryDialogBody = "_10ydd1nl";
|
|
28
|
+
var galleryImageList = "_10ydd1nm";
|
|
29
|
+
var galleryImageCard = "_10ydd1nn";
|
|
30
|
+
var galleryImageDragHandle = "_10ydd1no";
|
|
31
|
+
var galleryImageThumb = "_10ydd1np";
|
|
32
|
+
var galleryImageThumbPlaceholder = "_10ydd1nq";
|
|
33
|
+
var galleryImageFields = "_10ydd1nr";
|
|
34
|
+
var galleryImageInput = "_10ydd1ns";
|
|
35
|
+
var galleryImageActions = "_10ydd1nt";
|
|
36
|
+
var galleryImageDeleteBtn = "_10ydd1nu";
|
|
37
|
+
var galleryAddBtn = "_10ydd1nv";
|
|
38
|
+
var galleryDialogFooter = "_10ydd1nw";
|
|
39
|
+
var galleryFooterInfo = "_10ydd1nx";
|
|
40
|
+
var galleryFooterActions = "_10ydd1ny";
|
|
41
|
+
var galleryFooterBtnCancel = "_10ydd1n10 _10ydd1nz";
|
|
42
|
+
var galleryFooterBtnSave = "_10ydd1n11 _10ydd1nz";
|
|
43
|
+
var galleryDialogEmpty = "_10ydd1n12";
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/GalleryRenderer.tsx
|
|
46
|
+
var IMAGE_CONTAINER_MARGIN_INSET = 60;
|
|
47
|
+
var CHILD_GAP = 15;
|
|
48
|
+
var AUTOPLAY_DURATION = 5e3;
|
|
49
|
+
function throttle(func, wait) {
|
|
50
|
+
let timeout = null;
|
|
51
|
+
return ((...args) => {
|
|
52
|
+
if (!timeout) timeout = setTimeout(() => {
|
|
53
|
+
func(...args);
|
|
54
|
+
timeout = null;
|
|
55
|
+
}, wait);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function clsx(...classes) {
|
|
59
|
+
return classes.filter(Boolean).join(" ");
|
|
60
|
+
}
|
|
61
|
+
function useThumbhashStyle(image) {
|
|
62
|
+
return useMemo(() => {
|
|
63
|
+
if (!image.thumbhash) return;
|
|
64
|
+
const url = decodeThumbHash(image.thumbhash);
|
|
65
|
+
if (!url) return;
|
|
66
|
+
return {
|
|
67
|
+
backgroundImage: `url(${url})`,
|
|
68
|
+
backgroundSize: "cover"
|
|
69
|
+
};
|
|
70
|
+
}, [image.thumbhash]);
|
|
71
|
+
}
|
|
72
|
+
var GalleryRenderer = ({ images, layout }) => {
|
|
73
|
+
const [containerRef, setContainerRef] = useState(null);
|
|
74
|
+
const [, setUpdated] = useState({});
|
|
75
|
+
const memoedChildContainerWidthRef = useRef(0);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!containerRef) return;
|
|
78
|
+
const ob = new ResizeObserver(() => {
|
|
79
|
+
setUpdated({});
|
|
80
|
+
calChild(containerRef);
|
|
81
|
+
});
|
|
82
|
+
function calChild(containerRef) {
|
|
83
|
+
const $child = containerRef.children.item(0);
|
|
84
|
+
if ($child) memoedChildContainerWidthRef.current = $child.clientWidth;
|
|
85
|
+
}
|
|
86
|
+
calChild(containerRef);
|
|
87
|
+
ob.observe(containerRef);
|
|
88
|
+
return () => {
|
|
89
|
+
ob.disconnect();
|
|
90
|
+
};
|
|
91
|
+
}, [containerRef]);
|
|
92
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
93
|
+
const handleOnScroll = useCallback(throttle((e) => {
|
|
94
|
+
const $ = e.target;
|
|
95
|
+
setCurrentIndex(Math.floor(($.scrollLeft + IMAGE_CONTAINER_MARGIN_INSET + 15) / memoedChildContainerWidthRef.current));
|
|
96
|
+
}, 60), []);
|
|
97
|
+
const handleScrollTo = useCallback((i) => {
|
|
98
|
+
if (!containerRef) return;
|
|
99
|
+
containerRef.scrollTo({
|
|
100
|
+
left: memoedChildContainerWidthRef.current * i,
|
|
101
|
+
behavior: "smooth"
|
|
102
|
+
});
|
|
103
|
+
}, [containerRef]);
|
|
104
|
+
const autoplayTimerRef = useRef(null);
|
|
105
|
+
const isForward = useRef(true);
|
|
106
|
+
const autoplayRef = useRef(true);
|
|
107
|
+
const handleCancelAutoplay = useCallback(() => {
|
|
108
|
+
if (!autoplayRef.current) return;
|
|
109
|
+
autoplayRef.current = false;
|
|
110
|
+
if (autoplayTimerRef.current) clearInterval(autoplayTimerRef.current);
|
|
111
|
+
}, []);
|
|
112
|
+
const { ref } = useInView({
|
|
113
|
+
initialInView: false,
|
|
114
|
+
triggerOnce: images.length < 2,
|
|
115
|
+
onChange(inView) {
|
|
116
|
+
if (images.length < 2 || !autoplayRef.current) return;
|
|
117
|
+
if (inView) autoplayTimerRef.current = setInterval(() => {
|
|
118
|
+
setCurrentIndex((prev) => {
|
|
119
|
+
if (prev + 1 > images.length - 1 && isForward.current) isForward.current = false;
|
|
120
|
+
if (prev - 1 < 0 && !isForward.current) isForward.current = true;
|
|
121
|
+
const index = prev + (isForward.current ? 1 : -1);
|
|
122
|
+
handleScrollTo(index);
|
|
123
|
+
return index;
|
|
124
|
+
});
|
|
125
|
+
}, AUTOPLAY_DURATION);
|
|
126
|
+
else if (autoplayTimerRef.current) clearInterval(autoplayTimerRef.current);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
useEffect(() => () => {
|
|
130
|
+
if (autoplayTimerRef.current) clearInterval(autoplayTimerRef.current);
|
|
131
|
+
}, []);
|
|
132
|
+
if (images.length === 0) return null;
|
|
133
|
+
const layoutClass = layout === "masonry" ? galleryMasonry : layout === "carousel" ? galleryCarousel : galleryGrid;
|
|
134
|
+
if (images.length === 1 || layout === "grid" || layout === "masonry") return /* @__PURE__ */ jsx(PhotoProvider, { children: /* @__PURE__ */ jsx("div", {
|
|
135
|
+
className: clsx(gallery, layoutClass),
|
|
136
|
+
children: images.map((image, index) => /* @__PURE__ */ jsx(GalleryFigure, { image }, index))
|
|
137
|
+
}) });
|
|
138
|
+
return /* @__PURE__ */ jsx(PhotoProvider, { children: /* @__PURE__ */ jsxs("div", {
|
|
139
|
+
className: clsx(gallery, galleryCarousel),
|
|
140
|
+
ref,
|
|
141
|
+
onTouchMove: handleCancelAutoplay,
|
|
142
|
+
onWheel: handleCancelAutoplay,
|
|
143
|
+
children: [
|
|
144
|
+
/* @__PURE__ */ jsx("div", {
|
|
145
|
+
className: galleryContainer,
|
|
146
|
+
ref: setContainerRef,
|
|
147
|
+
onScroll: handleOnScroll,
|
|
148
|
+
onTouchStart: handleCancelAutoplay,
|
|
149
|
+
children: images.map((image, index) => /* @__PURE__ */ jsx(GalleryFigure, {
|
|
150
|
+
image,
|
|
151
|
+
style: {
|
|
152
|
+
width: `calc(100% - ${IMAGE_CONTAINER_MARGIN_INSET}px)`,
|
|
153
|
+
marginRight: `${CHILD_GAP}px`
|
|
154
|
+
}
|
|
155
|
+
}, index))
|
|
156
|
+
}),
|
|
157
|
+
currentIndex > 0 && /* @__PURE__ */ jsx("button", {
|
|
158
|
+
className: clsx("_10ydd1n6", "_10ydd1n7"),
|
|
159
|
+
onClick: () => handleScrollTo(currentIndex - 1),
|
|
160
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { size: 18 })
|
|
161
|
+
}),
|
|
162
|
+
currentIndex < images.length - 1 && /* @__PURE__ */ jsx("button", {
|
|
163
|
+
className: clsx("_10ydd1n6", "_10ydd1n8"),
|
|
164
|
+
onClick: () => handleScrollTo(currentIndex + 1),
|
|
165
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { size: 18 })
|
|
166
|
+
}),
|
|
167
|
+
/* @__PURE__ */ jsx("div", {
|
|
168
|
+
className: galleryIndicators,
|
|
169
|
+
children: images.map((_, i) => /* @__PURE__ */ jsx("div", {
|
|
170
|
+
className: clsx(galleryIndicator, currentIndex === i && "_10ydd1nb"),
|
|
171
|
+
onClick: () => handleScrollTo(i)
|
|
172
|
+
}, i))
|
|
173
|
+
})
|
|
174
|
+
]
|
|
175
|
+
}) });
|
|
176
|
+
};
|
|
177
|
+
var GalleryFigure = memo(({ image, style }) => {
|
|
178
|
+
const thumbStyle = useThumbhashStyle(image);
|
|
179
|
+
return /* @__PURE__ */ jsx(PhotoView, {
|
|
180
|
+
src: image.src,
|
|
181
|
+
children: /* @__PURE__ */ jsx("figure", {
|
|
182
|
+
className: galleryItem,
|
|
183
|
+
style: {
|
|
184
|
+
...thumbStyle,
|
|
185
|
+
...style
|
|
186
|
+
},
|
|
187
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
188
|
+
alt: image.alt || "",
|
|
189
|
+
height: image.height,
|
|
190
|
+
loading: "lazy",
|
|
191
|
+
src: image.src,
|
|
192
|
+
style: {
|
|
193
|
+
maxWidth: "100%",
|
|
194
|
+
height: "auto"
|
|
195
|
+
},
|
|
196
|
+
width: image.width
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
var GalleryRenderer_default = memo(GalleryRenderer);
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/typeof.js
|
|
204
|
+
function _typeof(o) {
|
|
205
|
+
"@babel/helpers - typeof";
|
|
206
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
207
|
+
return typeof o;
|
|
208
|
+
} : function(o) {
|
|
209
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
210
|
+
}, _typeof(o);
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/toPrimitive.js
|
|
214
|
+
function toPrimitive(t, r) {
|
|
215
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
216
|
+
var e = t[Symbol.toPrimitive];
|
|
217
|
+
if (void 0 !== e) {
|
|
218
|
+
var i = e.call(t, r || "default");
|
|
219
|
+
if ("object" != _typeof(i)) return i;
|
|
220
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
221
|
+
}
|
|
222
|
+
return ("string" === r ? String : Number)(t);
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/toPropertyKey.js
|
|
226
|
+
function toPropertyKey(t) {
|
|
227
|
+
var i = toPrimitive(t, "string");
|
|
228
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/defineProperty.js
|
|
232
|
+
function _defineProperty(e, r, t) {
|
|
233
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
234
|
+
value: t,
|
|
235
|
+
enumerable: !0,
|
|
236
|
+
configurable: !0,
|
|
237
|
+
writable: !0
|
|
238
|
+
}) : e[r] = t, e;
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/GalleryNode.ts
|
|
242
|
+
var GalleryNode = class GalleryNode extends DecoratorNode {
|
|
243
|
+
static getType() {
|
|
244
|
+
return "gallery";
|
|
245
|
+
}
|
|
246
|
+
static clone(node) {
|
|
247
|
+
return new GalleryNode({
|
|
248
|
+
images: node.__images.map((img) => ({ ...img })),
|
|
249
|
+
layout: node.__layout
|
|
250
|
+
}, node.__key);
|
|
251
|
+
}
|
|
252
|
+
constructor(payload, key) {
|
|
253
|
+
super(key);
|
|
254
|
+
_defineProperty(this, "__images", void 0);
|
|
255
|
+
_defineProperty(this, "__layout", void 0);
|
|
256
|
+
this.__images = payload.images;
|
|
257
|
+
this.__layout = payload.layout || "grid";
|
|
258
|
+
}
|
|
259
|
+
createDOM(_config) {
|
|
260
|
+
const div = document.createElement("div");
|
|
261
|
+
div.className = `rich-gallery rich-gallery-${this.__layout}`;
|
|
262
|
+
return div;
|
|
263
|
+
}
|
|
264
|
+
updateDOM() {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
isInline() {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
static importJSON(serializedNode) {
|
|
271
|
+
return $createGalleryNode({
|
|
272
|
+
images: serializedNode.images,
|
|
273
|
+
layout: serializedNode.layout
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
exportJSON() {
|
|
277
|
+
return {
|
|
278
|
+
...super.exportJSON(),
|
|
279
|
+
type: "gallery",
|
|
280
|
+
images: this.__images,
|
|
281
|
+
layout: this.__layout,
|
|
282
|
+
version: 1
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
getImages() {
|
|
286
|
+
return this.getLatest().__images;
|
|
287
|
+
}
|
|
288
|
+
setImages(images) {
|
|
289
|
+
const writable = this.getWritable();
|
|
290
|
+
writable.__images = images;
|
|
291
|
+
}
|
|
292
|
+
getLayout() {
|
|
293
|
+
return this.getLatest().__layout;
|
|
294
|
+
}
|
|
295
|
+
setLayout(layout) {
|
|
296
|
+
const writable = this.getWritable();
|
|
297
|
+
writable.__layout = layout;
|
|
298
|
+
}
|
|
299
|
+
decorate(_editor, _config) {
|
|
300
|
+
return createRendererDecoration("Gallery", GalleryRenderer, {
|
|
301
|
+
images: this.__images,
|
|
302
|
+
layout: this.__layout
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
function $createGalleryNode(payload) {
|
|
307
|
+
return new GalleryNode(payload);
|
|
308
|
+
}
|
|
309
|
+
function $isGalleryNode(node) {
|
|
310
|
+
return node instanceof GalleryNode;
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
export { galleryImageList as A, galleryHeaderClose as C, galleryImageDragHandle as D, galleryImageDeleteBtn as E, galleryImageThumbPlaceholder as M, galleryImageFields as O, galleryHeaderActions as S, galleryImageCard as T, galleryEmptyState as _, GalleryRenderer as a, galleryFooterBtnSave as b, galleryDialogBody as c, galleryDialogHeader as d, galleryDialogPopup as f, galleryEditOverlay as g, galleryEditLabel as h, _defineProperty as i, galleryImageThumb as j, galleryImageInput as k, galleryDialogEmpty as l, galleryEditContainer as m, $isGalleryNode as n, GalleryRenderer_default as o, galleryDialogTitle as p, GalleryNode as r, galleryAddBtn as s, $createGalleryNode as t, galleryDialogFooter as u, galleryFooterActions as v, galleryImageActions as w, galleryFooterInfo as x, galleryFooterBtnCancel as y };
|