@wix/editor-react-components 1.2252.0 → 1.2253.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.
@@ -2,7 +2,7 @@ import { default as React } from 'react';
2
2
  type Props = {
3
3
  itemCount: number;
4
4
  hasMore: boolean;
5
- onLoadMore: (() => void) | undefined;
5
+ onLoadMore: (() => Promise<void>) | undefined;
6
6
  itemsLoadedLabel?: string;
7
7
  endOfListLabel?: string;
8
8
  debounceMs?: number;
@@ -1,6 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
  type Props = {
3
- onLoadMore: () => void;
3
+ onLoadMore: () => Promise<void>;
4
4
  isLoading: boolean;
5
5
  label?: string;
6
6
  };
@@ -4,22 +4,35 @@ import { f as convertA11yKeysToHtmlFormat } from "../chunks/a11y.js";
4
4
  import { d as directionStyles } from "../chunks/direction.module.js";
5
5
  import { p as presetWrapperStyles } from "../chunks/presetWrapper.module.js";
6
6
  import { D as DEFAULT_ITEMS_PER_ROW, C as COLUMN_COUNT_CSS_VAR, T as TestIds, s as semanticClassNames } from "../chunks/constants20.js";
7
- import React__default, { useRef, useState, useEffect, forwardRef } from "react";
8
- const useItemsPerRow = (shouldMeasure) => {
9
- const ref = useRef(null);
10
- const [count, setCount] = useState(DEFAULT_ITEMS_PER_ROW);
7
+ import React__default, { useState, useRef, useEffect, useCallback, forwardRef } from "react";
8
+ const useAsyncLoadMore = (onLoadMore, itemsLength) => {
9
+ const [isLoading, setIsLoading] = useState(false);
10
+ const [hasMore, setHasMore] = useState(true);
11
+ const itemsLengthAtLastLoad = useRef(null);
11
12
  useEffect(() => {
12
- if (!shouldMeasure || !ref.current) {
13
- return;
14
- }
15
- const value = Number(
16
- getComputedStyle(ref.current).getPropertyValue(COLUMN_COUNT_CSS_VAR)
17
- );
18
- if (value > 0) {
19
- setCount(value);
13
+ setHasMore(true);
14
+ itemsLengthAtLastLoad.current = null;
15
+ }, [onLoadMore]);
16
+ useEffect(() => {
17
+ if (itemsLengthAtLastLoad.current === null) return;
18
+ setHasMore(itemsLength > itemsLengthAtLastLoad.current);
19
+ itemsLengthAtLastLoad.current = null;
20
+ }, [itemsLength]);
21
+ const handleLoadMore = useCallback(async () => {
22
+ itemsLengthAtLastLoad.current = itemsLength;
23
+ setIsLoading(true);
24
+ try {
25
+ await (onLoadMore == null ? void 0 : onLoadMore());
26
+ } catch {
27
+ } finally {
28
+ setIsLoading(false);
29
+ if (itemsLengthAtLastLoad.current !== null) {
30
+ setHasMore(false);
31
+ itemsLengthAtLastLoad.current = null;
32
+ }
20
33
  }
21
- }, [shouldMeasure]);
22
- return [ref, count];
34
+ }, [onLoadMore, itemsLength]);
35
+ return { isLoading, handleLoadMore, hasMore };
23
36
  };
24
37
  const useLoadMoreObserver = ({
25
38
  enabled,
@@ -51,6 +64,22 @@ const useLoadMoreObserver = ({
51
64
  }, [enabled]);
52
65
  return sentinelRef;
53
66
  };
67
+ const useItemsPerRow = (shouldMeasure) => {
68
+ const ref = useRef(null);
69
+ const [count, setCount] = useState(DEFAULT_ITEMS_PER_ROW);
70
+ useEffect(() => {
71
+ if (!shouldMeasure || !ref.current) {
72
+ return;
73
+ }
74
+ const value = Number(
75
+ getComputedStyle(ref.current).getPropertyValue(COLUMN_COUNT_CSS_VAR)
76
+ );
77
+ if (value > 0) {
78
+ setCount(value);
79
+ }
80
+ }, [shouldMeasure]);
81
+ return [ref, count];
82
+ };
54
83
  function createStateClass(namespace, stateName, stateValue) {
55
84
  if (stateValue === false || stateValue === void 0 || stateValue === null || stateValue !== stateValue) {
56
85
  return "";
@@ -403,18 +432,19 @@ const Repeater = (props) => {
403
432
  a11y,
404
433
  renderItem = () => /* @__PURE__ */ jsx(Fragment, {}),
405
434
  items = DEFAULT_ITEMS,
406
- isLoading = false,
407
- hasMore = false,
408
435
  onLoadMore,
409
436
  emptyState
410
437
  } = props;
411
438
  const presetsWrapperProps = ((_a = props.wix) == null ? void 0 : _a.presetsWrapperProps) || {};
412
- const loadMoreEnabled = !!onLoadMore;
439
+ const { isLoading, handleLoadMore, hasMore } = useAsyncLoadMore(
440
+ onLoadMore,
441
+ items.length
442
+ );
443
+ const [ulRef, itemsPerRow] = useItemsPerRow(!!onLoadMore);
413
444
  const sentinelRef = useLoadMoreObserver({
414
- enabled: loadMoreEnabled && !isLoading && hasMore,
415
- onLoadMore
445
+ enabled: !!onLoadMore && hasMore,
446
+ onLoadMore: onLoadMore ? handleLoadMore : void 0
416
447
  });
417
- const [itemsContainerRef, itemsPerRow] = useItemsPerRow(isLoading);
418
448
  if (!items.length && emptyState) {
419
449
  return null;
420
450
  }
@@ -433,10 +463,10 @@ const Repeater = (props) => {
433
463
  /* @__PURE__ */ jsxs(
434
464
  "ul",
435
465
  {
436
- ref: itemsContainerRef,
466
+ ref: ulRef,
437
467
  ...a11y && convertA11yKeysToHtmlFormat(a11y),
438
468
  role: "list",
439
- "aria-busy": isLoading || void 0,
469
+ "aria-busy": isLoading,
440
470
  className: clsx(
441
471
  semanticClassNames.itemsContainer,
442
472
  styles.itemsContainer
@@ -468,8 +498,8 @@ const Repeater = (props) => {
468
498
  ]
469
499
  }
470
500
  ),
471
- loadMoreEnabled && hasMore && onLoadMore && /* @__PURE__ */ jsxs(Fragment, { children: [
472
- /* @__PURE__ */ jsx(LoadMoreButton, { onLoadMore, isLoading }),
501
+ !!onLoadMore && hasMore && /* @__PURE__ */ jsxs(Fragment, { children: [
502
+ /* @__PURE__ */ jsx(LoadMoreButton, { onLoadMore: handleLoadMore, isLoading }),
473
503
  /* @__PURE__ */ jsx(
474
504
  "div",
475
505
  {
@@ -0,0 +1,5 @@
1
+ export declare const useAsyncLoadMore: (onLoadMore: (() => Promise<void>) | undefined, itemsLength: number) => {
2
+ isLoading: boolean;
3
+ handleLoadMore: () => Promise<void>;
4
+ hasMore: boolean;
5
+ };
@@ -39,6 +39,8 @@ const manifest = {
39
39
  "emptyState",
40
40
  "direction",
41
41
  "renderItem",
42
+ "isLoading",
43
+ "hasMore",
42
44
  "isLoadingFunc",
43
45
  "hasMoreFunc",
44
46
  "onLoadMoreFunc",
@@ -88,7 +90,9 @@ const manifest = {
88
90
  onLoadMore: {
89
91
  displayName: DisplayNames.root.data.loadMore,
90
92
  dataType: DATA.DATA_TYPE.function,
91
- [DATA.DATA_TYPE.function]: {}
93
+ [DATA.DATA_TYPE.function]: {
94
+ async: true
95
+ }
92
96
  },
93
97
  isLoadingFunc: {
94
98
  displayName: DisplayNames.root.data.isLoading,
@@ -10,9 +10,7 @@ export interface RepeaterProps {
10
10
  a11y?: A11y;
11
11
  renderItem?: (itemId: string, itemIndex: number) => React.JSX.Element;
12
12
  items?: Array<string>;
13
- isLoading?: boolean;
14
- hasMore?: boolean;
15
- onLoadMore?: () => void;
13
+ onLoadMore?: () => Promise<void>;
16
14
  emptyState?: EmptyState;
17
15
  wix?: {
18
16
  presetsWrapperProps?: Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/editor-react-components",
3
- "version": "1.2252.0",
3
+ "version": "1.2253.0",
4
4
  "description": "React components for the Wix Editor",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -197,5 +197,5 @@
197
197
  "registry": "https://registry.npmjs.org/",
198
198
  "access": "public"
199
199
  },
200
- "falconPackageHash": "7d557f7e3d84c00f6c199cbe0d050b9565163aacaba151c295b34a4d"
200
+ "falconPackageHash": "eb421f36fe8a21d0bbb4d7e52203e00d5026eee1dabdc62bc3822650"
201
201
  }