ublo-lib 1.16.0 → 1.16.2

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.
@@ -4,99 +4,10 @@ import { useUbloContext } from "ublo/with-ublo";
4
4
  import * as Icons from "dt-design-system/es/icons";
5
5
  import { jsx as _jsx } from "react/jsx-runtime";
6
6
  import { jsxs as _jsxs } from "react/jsx-runtime";
7
+ const TARGETS = "section[data-class]";
7
8
  const UNDRAGGABLE_TAGS = "img, a, button";
8
- const euclideanModulo = (a, b) => {
9
- const m = a % b;
10
- return m < 0 ? b < 0 ? m - b : m + b : m;
11
- };
12
- const preventDrag = element => element.setAttribute("draggable", false);
13
- const enableDrag = element => element.removeAttribute("draggable");
14
- const show = section => {
15
- const propertiesToRemove = ["opacity", "pointer-events", "touch-action"];
16
- propertiesToRemove.forEach(property => section.style.removeProperty(property));
17
- };
18
- function useInterval(callback, delay, current, dragging) {
19
- const savedCallback = React.useRef();
20
- React.useEffect(() => {
21
- savedCallback.current = callback;
22
- }, [callback]);
23
- React.useEffect(() => {
24
- function tick() {
25
- savedCallback.current();
26
- }
27
- if (!dragging && delay !== null && delay !== 0) {
28
- const interval = setInterval(tick, delay);
29
- return () => clearInterval(interval);
30
- }
31
- }, [current, delay, dragging]);
32
- }
33
- const Dots = ({
34
- count,
35
- current,
36
- setCurrent
37
- }) => {
38
- const length = [...new Array(count)];
39
- return _jsx("div", {
40
- className: "carousel__dots",
41
- children: length.map((_, i) => {
42
- const updateCurrent = e => {
43
- e.stopPropagation();
44
- setCurrent(i);
45
- };
46
- const classes = classNames("carousel__dot", {
47
- "carousel__dot--current": i === current
48
- });
49
- return _jsx("button", {
50
- className: classes,
51
- onClick: updateCurrent,
52
- "aria-label": i
53
- }, i);
54
- })
55
- });
56
- };
57
- const Thumbnails = ({
58
- carouselRef,
59
- count,
60
- current,
61
- setCurrent,
62
- targets
63
- }) => {
64
- const [thumbnails, setThumbnails] = React.useState([]);
65
- React.useEffect(() => {
66
- const carousel = carouselRef.current;
67
- if (carousel) {
68
- const sections = carousel.querySelectorAll(targets);
69
- if (sections.length) {
70
- const images = Array.from(sections).reduce((acc, section) => {
71
- const image = section.querySelector("img");
72
- if (!image?.src) return acc;
73
- return [...acc, image.src];
74
- }, []);
75
- setThumbnails(images);
76
- }
77
- }
78
- }, [carouselRef, count, targets]);
79
- if (!count || !thumbnails.length) return null;
80
- return _jsx("div", {
81
- className: "carousel__thumbnails",
82
- children: thumbnails.map((thumbnail, i) => {
83
- const updateCurrent = e => {
84
- e.stopPropagation();
85
- setCurrent(i);
86
- };
87
- const classes = classNames("carousel__thumbnail", {
88
- "carousel__thumbnail--current": i === current
89
- });
90
- return _jsx("input", {
91
- type: "image",
92
- className: classes,
93
- src: thumbnail,
94
- onClick: updateCurrent
95
- }, i);
96
- })
97
- });
98
- };
99
- const Carousel = ({
9
+ export default React.memo(Carousel);
10
+ function Carousel({
100
11
  delay = 4000,
101
12
  fade = false,
102
13
  controls,
@@ -106,18 +17,20 @@ const Carousel = ({
106
17
  allowDragOnDesktop,
107
18
  children,
108
19
  onChange
109
- }) => {
20
+ }) {
110
21
  const carouselRef = React.useRef();
111
22
  const {
112
- cmsMode
23
+ cmsMode,
24
+ lang,
25
+ path
113
26
  } = useUbloContext();
114
- const [count, setCount] = React.useState(0);
27
+ const [sections, setSections] = React.useState([]);
115
28
  const [current, setCurrent] = React.useState(0);
116
29
  const [touchStartPosition, setTouchStartPosition] = React.useState();
117
30
  const [dragging, setDragging] = React.useState(0);
118
31
  const editing = cmsMode === "editing";
119
32
  const draggingAllowed = !editing && allowDragOnDesktop;
120
- const targets = "section[data-class]";
33
+ const count = sections.length;
121
34
  const showNextArrow = current < count - 1;
122
35
  const showPrevArrow = current !== 0;
123
36
  const next = React.useCallback(e => {
@@ -219,30 +132,37 @@ const Carousel = ({
219
132
  if (startX > endX && current < count - 1) next();
220
133
  setTouchStartPosition(undefined);
221
134
  };
222
- const updateSectionCount = React.useCallback(() => {
135
+ const getSections = React.useCallback(() => {
223
136
  const carousel = carouselRef.current;
224
- const sections = carousel.querySelectorAll(targets);
225
- setCount(sections?.length || 0);
226
- }, [targets]);
137
+ const sections = carousel.querySelectorAll(TARGETS);
138
+ const visibleSections = Array.from(sections).filter(section => {
139
+ return window.getComputedStyle(section).display !== "none";
140
+ });
141
+ return visibleSections;
142
+ }, []);
143
+ const updateSections = React.useCallback(() => {
144
+ const sections = getSections();
145
+ setSections(sections);
146
+ }, [getSections]);
227
147
  React.useEffect(() => {
228
148
  const zone = carouselRef.current?.querySelector(".cms");
229
149
  if (zone) {
230
- zone.addEventListener("ublo-section-created", updateSectionCount);
231
- zone.addEventListener("ublo-section-pasted", updateSectionCount);
232
- zone.addEventListener("ublo-section-removed", updateSectionCount);
150
+ zone.addEventListener("ublo-section-created", updateSections);
151
+ zone.addEventListener("ublo-section-pasted", updateSections);
152
+ zone.addEventListener("ublo-section-removed", updateSections);
233
153
  return () => {
234
- zone.removeEventListener("ublo-section-removed", updateSectionCount);
235
- zone.removeEventListener("ublo-section-pasted", updateSectionCount);
236
- zone.removeEventListener("ublo-section-created", updateSectionCount);
154
+ zone.removeEventListener("ublo-section-removed", updateSections);
155
+ zone.removeEventListener("ublo-section-pasted", updateSections);
156
+ zone.removeEventListener("ublo-section-created", updateSections);
237
157
  };
238
158
  }
239
- }, [updateSectionCount]);
159
+ }, [updateSections]);
240
160
  React.useEffect(() => {
241
161
  const carousel = carouselRef.current;
242
162
  const inner = carousel.firstElementChild;
243
- const sections = Array.from(carousel.querySelectorAll(targets));
163
+ const sections = getSections();
244
164
  const undraggableElements = Array.from(carousel.querySelectorAll(UNDRAGGABLE_TAGS));
245
- setCount(sections.length);
165
+ setSections(sections);
246
166
  if (!editing) {
247
167
  sections.forEach((section, index) => {
248
168
  const anchors = Array.from(section.querySelectorAll("a"));
@@ -280,7 +200,7 @@ const Carousel = ({
280
200
  });
281
201
  if (fade) inner.style.removeProperty("transform");
282
202
  }
283
- }, [count, current, editing, fade, targets]);
203
+ }, [current, editing, fade, getSections, lang, path]);
284
204
  const onUndraggableElementClick = React.useCallback(e => {
285
205
  e.preventDefault();
286
206
  e.stopPropagation();
@@ -339,14 +259,107 @@ const Carousel = ({
339
259
  }), dots && _jsx(Dots, {
340
260
  count: count,
341
261
  current: current,
342
- setCurrent: setCurrent
262
+ setCurrent: setCurrent,
263
+ sections: sections
343
264
  }), thumbnails && count > 1 && _jsx(Thumbnails, {
344
265
  carouselRef: carouselRef,
345
266
  count: count,
346
267
  current: current,
347
268
  setCurrent: setCurrent,
348
- targets: targets
269
+ sections: sections
349
270
  })]
350
271
  });
351
- };
352
- export default React.memo(Carousel);
272
+ }
273
+ function Dots({
274
+ count,
275
+ current,
276
+ setCurrent
277
+ }) {
278
+ const length = [...new Array(count)];
279
+ return _jsx("div", {
280
+ className: "carousel__dots",
281
+ children: length.map((_, i) => {
282
+ const updateCurrent = e => {
283
+ e.stopPropagation();
284
+ setCurrent(i);
285
+ };
286
+ const classes = classNames("carousel__dot", {
287
+ "carousel__dot--current": i === current
288
+ });
289
+ return _jsx("button", {
290
+ className: classes,
291
+ onClick: updateCurrent,
292
+ "aria-label": i
293
+ }, i);
294
+ })
295
+ });
296
+ }
297
+ function Thumbnails({
298
+ carouselRef,
299
+ current,
300
+ setCurrent,
301
+ sections
302
+ }) {
303
+ const [thumbnails, setThumbnails] = React.useState([]);
304
+ React.useEffect(() => {
305
+ const carousel = carouselRef.current;
306
+ if (carousel) {
307
+ if (sections.length) {
308
+ const images = Array.from(sections).reduce((acc, section) => {
309
+ const image = section.querySelector("img");
310
+ if (!image?.src) return acc;
311
+ return [...acc, image.src];
312
+ }, []);
313
+ setThumbnails(images);
314
+ }
315
+ }
316
+ }, [carouselRef, sections]);
317
+ if (!thumbnails.length) return null;
318
+ return _jsx("div", {
319
+ className: "carousel__thumbnails",
320
+ children: thumbnails.map((thumbnail, i) => {
321
+ const updateCurrent = e => {
322
+ e.stopPropagation();
323
+ setCurrent(i);
324
+ };
325
+ const classes = classNames("carousel__thumbnail", {
326
+ "carousel__thumbnail--current": i === current
327
+ });
328
+ return _jsx("input", {
329
+ type: "image",
330
+ className: classes,
331
+ src: thumbnail,
332
+ onClick: updateCurrent
333
+ }, i);
334
+ })
335
+ });
336
+ }
337
+ function euclideanModulo(a, b) {
338
+ const m = a % b;
339
+ return m < 0 ? b < 0 ? m - b : m + b : m;
340
+ }
341
+ function preventDrag(element) {
342
+ element.setAttribute("draggable", false);
343
+ }
344
+ function enableDrag(element) {
345
+ element.removeAttribute("draggable");
346
+ }
347
+ function show(section) {
348
+ const propertiesToRemove = ["opacity", "pointer-events", "touch-action"];
349
+ propertiesToRemove.forEach(property => section.style.removeProperty(property));
350
+ }
351
+ function useInterval(callback, delay, current, dragging) {
352
+ const savedCallback = React.useRef();
353
+ React.useEffect(() => {
354
+ savedCallback.current = callback;
355
+ }, [callback]);
356
+ React.useEffect(() => {
357
+ function tick() {
358
+ savedCallback.current();
359
+ }
360
+ if (!dragging && delay !== null && delay !== 0) {
361
+ const interval = setInterval(tick, delay);
362
+ return () => clearInterval(interval);
363
+ }
364
+ }, [current, delay, dragging]);
365
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../../../src/common/components/instant-search/links.tsx"],"names":[],"mappings":";AAMA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGrC,aAAK,KAAK,GAAG;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;IAChD,KAAK,EAAE,GAAG,EAAE,CAAC;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAC5B,IAAI,EACJ,UAAU,EACV,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,iBAAiB,GAClB,EAAE,KAAK,sBAoEP"}
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../../../src/common/components/instant-search/links.tsx"],"names":[],"mappings":";AAMA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGrC,aAAK,KAAK,GAAG;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;IAChD,KAAK,EAAE,GAAG,EAAE,CAAC;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAC5B,IAAI,EACJ,UAAU,EACV,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,iBAAiB,GAClB,EAAE,KAAK,sBAmEP"}
@@ -25,8 +25,6 @@ export default function Links({ icon, linksTitle, links, pageTitleAsTitle, loadi
25
25
  const linkTitle = Utils.getHighlight(titleProperty, link.highlight) ||
26
26
  link.document[titleProperty];
27
27
  const linkText = Utils.getHighlight("text", link.highlight, true) || text;
28
- return (
29
- // @ts-ignore
30
- _jsxs(Link, { href: decodedPath, className: css.link, onClick: sendPlausibleGoal(decodedPath), onMouseDown: createRipple, children: [_jsx(Icon, { className: css.linkIcon }), _jsxs("div", { className: css.linkContent, children: [parentTitle && (_jsx("div", { className: css.linkParent, dangerouslySetInnerHTML: { __html: parentTitle } })), _jsx("div", { className: css.linkTitle, dangerouslySetInnerHTML: { __html: linkTitle } }), linkText && (_jsx("div", { className: css.linkText, dangerouslySetInnerHTML: { __html: linkText } }))] })] }, id));
28
+ return (_jsxs(Link, { href: decodedPath, className: css.link, onClick: sendPlausibleGoal(decodedPath), onMouseDown: createRipple, children: [_jsx(Icon, { className: css.linkIcon }), _jsxs("div", { className: css.linkContent, children: [parentTitle && (_jsx("div", { className: css.linkParent, dangerouslySetInnerHTML: { __html: parentTitle } })), _jsx("div", { className: css.linkTitle, dangerouslySetInnerHTML: { __html: linkTitle } }), linkText && (_jsx("div", { className: css.linkText, dangerouslySetInnerHTML: { __html: linkText } }))] })] }, id));
31
29
  })] })] }));
32
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"products.d.ts","sourceRoot":"","sources":["../../../../src/common/components/instant-search/products.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGrC,aAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACjD,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,mBAAmB,GACpB,EAAE,KAAK,eA6HP"}
1
+ {"version":3,"file":"products.d.ts","sourceRoot":"","sources":["../../../../src/common/components/instant-search/products.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGrC,aAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACjD,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,mBAAmB,GACpB,EAAE,KAAK,eA4HP"}
@@ -37,8 +37,6 @@ export default function Products({ lang, products, weekNumber, loading, sendPlau
37
37
  const productText = Utils.getHighlight("text", product.highlight) || text;
38
38
  const showPrice = price !== undefined && weekNumber !== null;
39
39
  const imagePlaceholderStategy = imagePlaceholder ? "blur" : "empty";
40
- return (
41
- // @ts-ignore
42
- _jsxs(Link, { className: css.product, href: decodedPath, onClick: sendPlausibleGoal(decodedPath), onMouseDown: createRipple, children: [_jsx(Image, { className: css.productImage, src: image, alt: title, width: 220, height: 180, placeholder: imagePlaceholderStategy, blurDataURL: imagePlaceholder }), _jsxs("div", { className: css.productContent, children: [parentTitle && (_jsx("div", { className: css.productParent, dangerouslySetInnerHTML: { __html: parentTitle } })), _jsx("div", { className: css.productPageTitle, dangerouslySetInnerHTML: { __html: productPageTitle } }), _jsx("div", { className: css.productTitle, dangerouslySetInnerHTML: { __html: productTitle } }), _jsx("div", { className: css.productTime, dangerouslySetInnerHTML: { __html: productTime } }), _jsx("div", { className: css.productText, dangerouslySetInnerHTML: { __html: productText } }), showPrice && (_jsx("div", { className: css.productPrice, dangerouslySetInnerHTML: { __html: price } }))] })] }, id));
40
+ return (_jsxs(Link, { className: css.product, href: decodedPath, onClick: sendPlausibleGoal(decodedPath), onMouseDown: createRipple, children: [_jsx(Image, { className: css.productImage, src: image, alt: title, width: 220, height: 180, placeholder: imagePlaceholderStategy, blurDataURL: imagePlaceholder }), _jsxs("div", { className: css.productContent, children: [parentTitle && (_jsx("div", { className: css.productParent, dangerouslySetInnerHTML: { __html: parentTitle } })), _jsx("div", { className: css.productPageTitle, dangerouslySetInnerHTML: { __html: productPageTitle } }), _jsx("div", { className: css.productTitle, dangerouslySetInnerHTML: { __html: productTitle } }), _jsx("div", { className: css.productTime, dangerouslySetInnerHTML: { __html: productTime } }), _jsx("div", { className: css.productText, dangerouslySetInnerHTML: { __html: productText } }), showPrice && (_jsx("div", { className: css.productPrice, dangerouslySetInnerHTML: { __html: price } }))] })] }, id));
43
41
  }), !noProduct && !isOtherResultsEmpty && (_jsx("div", { className: css.otherProducts, children: _jsxs(Button, { className: css.otherProductsButton, onClick: scrollToOtherResults, children: [message(lang, "showOtherResults"), _jsx(Icons.ArrowDown, {})] }) }))] }));
44
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.16.0",
3
+ "version": "1.16.2",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^2.9.0",
6
6
  "leaflet": "^1.9.1",