ublo-lib 1.16.0 → 1.16.1

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,18 @@ const Carousel = ({
106
17
  allowDragOnDesktop,
107
18
  children,
108
19
  onChange
109
- }) => {
20
+ }) {
110
21
  const carouselRef = React.useRef();
111
22
  const {
112
23
  cmsMode
113
24
  } = useUbloContext();
114
- const [count, setCount] = React.useState(0);
25
+ const [sections, setSections] = React.useState([]);
115
26
  const [current, setCurrent] = React.useState(0);
116
27
  const [touchStartPosition, setTouchStartPosition] = React.useState();
117
28
  const [dragging, setDragging] = React.useState(0);
118
29
  const editing = cmsMode === "editing";
119
30
  const draggingAllowed = !editing && allowDragOnDesktop;
120
- const targets = "section[data-class]";
31
+ const count = sections.length;
121
32
  const showNextArrow = current < count - 1;
122
33
  const showPrevArrow = current !== 0;
123
34
  const next = React.useCallback(e => {
@@ -219,30 +130,37 @@ const Carousel = ({
219
130
  if (startX > endX && current < count - 1) next();
220
131
  setTouchStartPosition(undefined);
221
132
  };
222
- const updateSectionCount = React.useCallback(() => {
133
+ const getSections = React.useCallback(() => {
223
134
  const carousel = carouselRef.current;
224
- const sections = carousel.querySelectorAll(targets);
225
- setCount(sections?.length || 0);
226
- }, [targets]);
135
+ const sections = carousel.querySelectorAll(TARGETS);
136
+ const visibleSections = Array.from(sections).filter(section => {
137
+ return window.getComputedStyle(section).display !== "none";
138
+ });
139
+ return visibleSections;
140
+ }, []);
141
+ const updateSections = React.useCallback(() => {
142
+ const sections = getSections();
143
+ setSections(sections);
144
+ }, [getSections]);
227
145
  React.useEffect(() => {
228
146
  const zone = carouselRef.current?.querySelector(".cms");
229
147
  if (zone) {
230
- zone.addEventListener("ublo-section-created", updateSectionCount);
231
- zone.addEventListener("ublo-section-pasted", updateSectionCount);
232
- zone.addEventListener("ublo-section-removed", updateSectionCount);
148
+ zone.addEventListener("ublo-section-created", updateSections);
149
+ zone.addEventListener("ublo-section-pasted", updateSections);
150
+ zone.addEventListener("ublo-section-removed", updateSections);
233
151
  return () => {
234
- zone.removeEventListener("ublo-section-removed", updateSectionCount);
235
- zone.removeEventListener("ublo-section-pasted", updateSectionCount);
236
- zone.removeEventListener("ublo-section-created", updateSectionCount);
152
+ zone.removeEventListener("ublo-section-removed", updateSections);
153
+ zone.removeEventListener("ublo-section-pasted", updateSections);
154
+ zone.removeEventListener("ublo-section-created", updateSections);
237
155
  };
238
156
  }
239
- }, [updateSectionCount]);
157
+ }, [updateSections]);
240
158
  React.useEffect(() => {
241
159
  const carousel = carouselRef.current;
242
160
  const inner = carousel.firstElementChild;
243
- const sections = Array.from(carousel.querySelectorAll(targets));
161
+ const sections = getSections();
244
162
  const undraggableElements = Array.from(carousel.querySelectorAll(UNDRAGGABLE_TAGS));
245
- setCount(sections.length);
163
+ setSections(sections);
246
164
  if (!editing) {
247
165
  sections.forEach((section, index) => {
248
166
  const anchors = Array.from(section.querySelectorAll("a"));
@@ -280,7 +198,7 @@ const Carousel = ({
280
198
  });
281
199
  if (fade) inner.style.removeProperty("transform");
282
200
  }
283
- }, [count, current, editing, fade, targets]);
201
+ }, [current, editing, fade, getSections]);
284
202
  const onUndraggableElementClick = React.useCallback(e => {
285
203
  e.preventDefault();
286
204
  e.stopPropagation();
@@ -339,14 +257,107 @@ const Carousel = ({
339
257
  }), dots && _jsx(Dots, {
340
258
  count: count,
341
259
  current: current,
342
- setCurrent: setCurrent
260
+ setCurrent: setCurrent,
261
+ sections: sections
343
262
  }), thumbnails && count > 1 && _jsx(Thumbnails, {
344
263
  carouselRef: carouselRef,
345
264
  count: count,
346
265
  current: current,
347
266
  setCurrent: setCurrent,
348
- targets: targets
267
+ sections: sections
349
268
  })]
350
269
  });
351
- };
352
- export default React.memo(Carousel);
270
+ }
271
+ function Dots({
272
+ count,
273
+ current,
274
+ setCurrent
275
+ }) {
276
+ const length = [...new Array(count)];
277
+ return _jsx("div", {
278
+ className: "carousel__dots",
279
+ children: length.map((_, i) => {
280
+ const updateCurrent = e => {
281
+ e.stopPropagation();
282
+ setCurrent(i);
283
+ };
284
+ const classes = classNames("carousel__dot", {
285
+ "carousel__dot--current": i === current
286
+ });
287
+ return _jsx("button", {
288
+ className: classes,
289
+ onClick: updateCurrent,
290
+ "aria-label": i
291
+ }, i);
292
+ })
293
+ });
294
+ }
295
+ function Thumbnails({
296
+ carouselRef,
297
+ current,
298
+ setCurrent,
299
+ sections
300
+ }) {
301
+ const [thumbnails, setThumbnails] = React.useState([]);
302
+ React.useEffect(() => {
303
+ const carousel = carouselRef.current;
304
+ if (carousel) {
305
+ if (sections.length) {
306
+ const images = Array.from(sections).reduce((acc, section) => {
307
+ const image = section.querySelector("img");
308
+ if (!image?.src) return acc;
309
+ return [...acc, image.src];
310
+ }, []);
311
+ setThumbnails(images);
312
+ }
313
+ }
314
+ }, [carouselRef, sections]);
315
+ if (!thumbnails.length) return null;
316
+ return _jsx("div", {
317
+ className: "carousel__thumbnails",
318
+ children: thumbnails.map((thumbnail, i) => {
319
+ const updateCurrent = e => {
320
+ e.stopPropagation();
321
+ setCurrent(i);
322
+ };
323
+ const classes = classNames("carousel__thumbnail", {
324
+ "carousel__thumbnail--current": i === current
325
+ });
326
+ return _jsx("input", {
327
+ type: "image",
328
+ className: classes,
329
+ src: thumbnail,
330
+ onClick: updateCurrent
331
+ }, i);
332
+ })
333
+ });
334
+ }
335
+ function euclideanModulo(a, b) {
336
+ const m = a % b;
337
+ return m < 0 ? b < 0 ? m - b : m + b : m;
338
+ }
339
+ function preventDrag(element) {
340
+ element.setAttribute("draggable", false);
341
+ }
342
+ function enableDrag(element) {
343
+ element.removeAttribute("draggable");
344
+ }
345
+ function show(section) {
346
+ const propertiesToRemove = ["opacity", "pointer-events", "touch-action"];
347
+ propertiesToRemove.forEach(property => section.style.removeProperty(property));
348
+ }
349
+ function useInterval(callback, delay, current, dragging) {
350
+ const savedCallback = React.useRef();
351
+ React.useEffect(() => {
352
+ savedCallback.current = callback;
353
+ }, [callback]);
354
+ React.useEffect(() => {
355
+ function tick() {
356
+ savedCallback.current();
357
+ }
358
+ if (!dragging && delay !== null && delay !== 0) {
359
+ const interval = setInterval(tick, delay);
360
+ return () => clearInterval(interval);
361
+ }
362
+ }, [current, delay, dragging]);
363
+ }
@@ -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.1",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^2.9.0",
6
6
  "leaflet": "^1.9.1",