@mittwald/flow-react-components 1.6.0-next.20 → 1.6.0-next.21
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/assets/component-index.json +1 -1
- package/dist/assets/doc-properties.json +1 -1
- package/dist/js/default.mjs +1 -1
- package/dist/js/packages/components/src/components/List/components/Items/Items.mjs +3 -0
- package/dist/js/packages/components/src/components/List/components/Items/Items.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/components/Items/components/Item/Item.mjs +1 -1
- package/dist/js/packages/components/src/components/List/components/Items/components/Item/Item.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/components/Items/components/Item/hooks/useGridItemProps.mjs +1 -2
- package/dist/js/packages/components/src/components/List/components/Items/components/Item/hooks/useGridItemProps.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/components/Table/Table.mjs +8 -12
- package/dist/js/packages/components/src/components/List/components/Table/Table.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/components/Table/components/Row.mjs +31 -0
- package/dist/js/packages/components/src/components/List/components/Table/components/Row.mjs.map +1 -0
- package/dist/js/packages/components/src/components/List/hooks/useLatestOnAction.mjs +21 -0
- package/dist/js/packages/components/src/components/List/hooks/useLatestOnAction.mjs.map +1 -0
- package/dist/js/packages/components/src/components/List/model/List.mjs +1 -0
- package/dist/js/packages/components/src/components/List/model/List.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/model/item/ItemView.mjs +20 -7
- package/dist/js/packages/components/src/components/List/model/item/ItemView.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/model/table/TableCell.mjs +1 -1
- package/dist/js/packages/components/src/components/List/model/table/TableCell.mjs.map +1 -1
- package/dist/js/packages/components/src/components/List/model/table/TableRow.mjs +28 -1
- package/dist/js/packages/components/src/components/List/model/table/TableRow.mjs.map +1 -1
- package/dist/types/components/List/components/Items/components/Item/Item.d.ts +2 -0
- package/dist/types/components/List/components/Items/components/Item/hooks/useGridItemProps.d.ts +1 -0
- package/dist/types/components/List/components/Table/components/Row.d.ts +13 -0
- package/dist/types/components/List/hooks/useLatestOnAction.d.ts +7 -0
- package/dist/types/components/List/model/item/ItemView.d.ts +34 -11
- package/dist/types/components/List/model/table/TableRow.d.ts +14 -0
- package/dist/types/components/List/model/table/types.d.ts +17 -1
- package/dist/types/components/List/typedList.d.ts +1 -0
- package/package.json +10 -10
package/dist/js/default.mjs
CHANGED
|
@@ -299,8 +299,8 @@ import { Skeleton } from "./packages/components/src/components/Skeleton/Skeleton
|
|
|
299
299
|
import { Table } from "./packages/components/src/components/Table/Table.mjs";
|
|
300
300
|
import { TableHeader } from "./packages/components/src/components/Table/components/TableHeader/TableHeader.mjs";
|
|
301
301
|
import { TableBody } from "./packages/components/src/components/Table/components/TableBody/TableBody.mjs";
|
|
302
|
-
import { TableRow } from "./packages/components/src/components/Table/components/TableRow/TableRow.mjs";
|
|
303
302
|
import { TableColumn } from "./packages/components/src/components/Table/components/TableColumn/TableColumn.mjs";
|
|
303
|
+
import { TableRow } from "./packages/components/src/components/Table/components/TableRow/TableRow.mjs";
|
|
304
304
|
import { TableCell } from "./packages/components/src/components/Table/components/TableCell/TableCell.mjs";
|
|
305
305
|
import { SettingsProvider } from "./packages/components/src/components/SettingsProvider/SettingsProvider.mjs";
|
|
306
306
|
import { ListFilter, TypedListFilter } from "./packages/components/src/components/List/setupComponents/ListFilter.mjs";
|
|
@@ -7,6 +7,7 @@ import { Item } from "./components/Item/Item.mjs";
|
|
|
7
7
|
import ItemsGridListView from "../../../../views/ItemsGridListView.mjs";
|
|
8
8
|
import { FallbackItems } from "./components/FallbackItems/FallbackItems.mjs";
|
|
9
9
|
import { useInfiniteScrollTrigger } from "../../hooks/useInfiniteScrollTrigger.mjs";
|
|
10
|
+
import { useLatestOnAction } from "../../hooks/useLatestOnAction.mjs";
|
|
10
11
|
import clsx from "clsx";
|
|
11
12
|
import { jsx } from "react/jsx-runtime";
|
|
12
13
|
//#region src/components/List/components/Items/Items.tsx
|
|
@@ -17,11 +18,13 @@ var Items = () => {
|
|
|
17
18
|
const isInitiallyLoading = list.loader.useIsInitiallyLoading();
|
|
18
19
|
const isLoadingMore = list.loader.useIsLoadingMore();
|
|
19
20
|
const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();
|
|
21
|
+
const onAction = useLatestOnAction(list);
|
|
20
22
|
if (!list.itemView) return null;
|
|
21
23
|
const items = list.items.entries.map((item, index) => /* @__PURE__ */ jsx(Item, {
|
|
22
24
|
data: item.data,
|
|
23
25
|
id: item.id,
|
|
24
26
|
list,
|
|
27
|
+
onAction,
|
|
25
28
|
isTile: tiles,
|
|
26
29
|
triggerRef: index === triggerIndex ? triggerRef : void 0
|
|
27
30
|
}, item.id));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Items.mjs","names":["styles"],"sources":["../../../../../../../../../src/components/List/components/Items/Items.tsx"],"sourcesContent":["import Item from \"@/components/List/components/Items/components/Item/Item\";\nimport { useList } from \"@/components/List/hooks/useList\";\nimport DivView from \"@/views/DivView\";\nimport ItemsGridListView from \"@/views/ItemsGridListView\";\nimport clsx from \"clsx\";\nimport type { FC } from \"react\";\nimport styles from \"./Items.module.scss\";\nimport { FallbackItems } from \"./components/FallbackItems\";\nimport { useInfiniteScrollTrigger } from \"@/components/List/hooks/useInfiniteScrollTrigger\";\n\nexport const Items: FC = () => {\n const list = useList();\n const tiles = list.viewMode.isTiles;\n const isLoading = list.loader.useIsLoading();\n const isInitiallyLoading = list.loader.useIsInitiallyLoading();\n const isLoadingMore = list.loader.useIsLoadingMore();\n\n const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();\n\n if (!list.itemView) {\n return null;\n }\n\n const items = list.items.entries.map((item, index) => (\n <Item\n key={item.id}\n data={item.data}\n id={item.id}\n list={list}\n isTile={tiles}\n triggerRef={index === triggerIndex ? triggerRef : undefined}\n />\n ));\n\n const rootClassName = clsx(\n styles.items,\n isLoading && !(list.infiniteScroll && isLoadingMore) && styles.isLoading,\n tiles && styles.tiles,\n );\n\n const {\n \"aria-labelledby\": ariaLabelledby,\n \"aria-label\": ariaLabel,\n ...rest\n } = list.componentProps;\n\n return (\n <DivView aria-hidden={isInitiallyLoading} aria-busy={isLoading}>\n <ItemsGridListView\n className={rootClassName}\n {...rest}\n aria-labelledby={ariaLabel ? undefined : ariaLabelledby}\n aria-label={ariaLabel}\n layout={tiles ? \"grid\" : \"stack\"}\n tileMaxWidth={list.itemView.tileMaxWidth}\n >\n {items.length === 0 && isInitiallyLoading ? <FallbackItems /> : items}\n </ItemsGridListView>\n </DivView>\n );\n};\n\nexport default Items;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Items.mjs","names":["styles"],"sources":["../../../../../../../../../src/components/List/components/Items/Items.tsx"],"sourcesContent":["import Item from \"@/components/List/components/Items/components/Item/Item\";\nimport { useList } from \"@/components/List/hooks/useList\";\nimport DivView from \"@/views/DivView\";\nimport ItemsGridListView from \"@/views/ItemsGridListView\";\nimport clsx from \"clsx\";\nimport type { FC } from \"react\";\nimport styles from \"./Items.module.scss\";\nimport { FallbackItems } from \"./components/FallbackItems\";\nimport { useInfiniteScrollTrigger } from \"@/components/List/hooks/useInfiniteScrollTrigger\";\nimport { useLatestOnAction } from \"@/components/List/hooks/useLatestOnAction\";\n\nexport const Items: FC = () => {\n const list = useList();\n const tiles = list.viewMode.isTiles;\n const isLoading = list.loader.useIsLoading();\n const isInitiallyLoading = list.loader.useIsInitiallyLoading();\n const isLoadingMore = list.loader.useIsLoadingMore();\n\n const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();\n\n const onAction = useLatestOnAction(list);\n\n if (!list.itemView) {\n return null;\n }\n\n const items = list.items.entries.map((item, index) => (\n <Item\n key={item.id}\n data={item.data}\n id={item.id}\n list={list}\n onAction={onAction}\n isTile={tiles}\n triggerRef={index === triggerIndex ? triggerRef : undefined}\n />\n ));\n\n const rootClassName = clsx(\n styles.items,\n isLoading && !(list.infiniteScroll && isLoadingMore) && styles.isLoading,\n tiles && styles.tiles,\n );\n\n const {\n \"aria-labelledby\": ariaLabelledby,\n \"aria-label\": ariaLabel,\n ...rest\n } = list.componentProps;\n\n return (\n <DivView aria-hidden={isInitiallyLoading} aria-busy={isLoading}>\n <ItemsGridListView\n className={rootClassName}\n {...rest}\n aria-labelledby={ariaLabel ? undefined : ariaLabelledby}\n aria-label={ariaLabel}\n layout={tiles ? \"grid\" : \"stack\"}\n tileMaxWidth={list.itemView.tileMaxWidth}\n >\n {items.length === 0 && isInitiallyLoading ? <FallbackItems /> : items}\n </ItemsGridListView>\n </DivView>\n );\n};\n\nexport default Items;\n"],"mappings":";;;;;;;;;;;;;AAWA,IAAa,cAAkB;CAC7B,MAAM,OAAO,QAAQ;CACrB,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,YAAY,KAAK,OAAO,aAAa;CAC3C,MAAM,qBAAqB,KAAK,OAAO,sBAAsB;CAC7D,MAAM,gBAAgB,KAAK,OAAO,iBAAiB;CAEnD,MAAM,EAAE,YAAY,iBAAiB,yBAAyB;CAE9D,MAAM,WAAW,kBAAkB,IAAI;CAEvC,IAAI,CAAC,KAAK,UACR,OAAO;CAGT,MAAM,QAAQ,KAAK,MAAM,QAAQ,KAAK,MAAM,UAC1C,oBAAC,MAAD;EAEE,MAAM,KAAK;EACX,IAAI,KAAK;EACH;EACI;EACV,QAAQ;EACR,YAAY,UAAU,eAAe,aAAa,KAAA;CACnD,GAPM,KAAK,EAOX,CACF;CAED,MAAM,gBAAgB,KACpBA,qBAAO,OACP,aAAa,EAAE,KAAK,kBAAkB,kBAAkBA,qBAAO,WAC/D,SAASA,qBAAO,KAClB;CAEA,MAAM,EACJ,mBAAmB,gBACnB,cAAc,WACd,GAAG,SACD,KAAK;CAET,OACE,oBAAC,SAAD;EAAS,eAAa;EAAoB,aAAW;EACnD,UAAA,oBAAC,mBAAD;GACE,WAAW;GACX,GAAI;GACJ,mBAAiB,YAAY,KAAA,IAAY;GACzC,cAAY;GACZ,QAAQ,QAAQ,SAAS;GACzB,cAAc,KAAK,SAAS;GAE3B,UAAA,MAAM,WAAW,KAAK,qBAAqB,oBAAC,eAAD,CAAgB,CAAA,IAAI;EAC/C,CAAA;CACZ,CAAA;AAEb"}
|
package/dist/js/packages/components/src/components/List/components/Items/components/Item/Item.mjs
CHANGED
|
@@ -36,7 +36,7 @@ var ItemImpl = (props) => {
|
|
|
36
36
|
})
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
|
-
var Item = memo(ItemImpl, (prev, next) => prev.id === next.id && prev.data === next.data && prev.triggerRef === next.triggerRef && prev.isTile === next.isTile && prev.
|
|
39
|
+
var Item = memo(ItemImpl, (prev, next) => prev.id === next.id && prev.data === next.data && prev.triggerRef === next.triggerRef && prev.isTile === next.isTile && !!prev.onAction === !!next.onAction && prev.list.accordion === next.list.accordion && !!prev.list.itemView?.rendersSameFor(next.list.itemView, next.data));
|
|
40
40
|
Item.displayName = "Item";
|
|
41
41
|
var ItemContainer = (props) => {
|
|
42
42
|
const list = useList();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.mjs","names":["styles"],"sources":["../../../../../../../../../../../src/components/List/components/Items/components/Item/Item.tsx"],"sourcesContent":["import { useGridItemProps } from \"@/components/List/components/Items/components/Item/hooks/useGridItemProps\";\nimport { useList } from \"@/components/List/hooks/useList\";\nimport type ListModel from \"@/components/List/model/List\";\nimport ItemsGridListItemView from \"@/views/ItemsGridListItemView\";\nimport { mergeRefs } from \"@react-aria/utils\";\nimport type { FC, PropsWithChildren, Ref } from \"react\";\nimport { memo, Suspense } from \"react\";\nimport type { Key } from \"react-aria-components\";\nimport styles from \"./Item.module.scss\";\nimport { ItemLoadingView } from \"./components/ItemLoadingView/ItemLoadingView\";\n\ninterface Props extends PropsWithChildren {\n id: Key;\n data: never;\n triggerRef?: Ref<HTMLDivElement>;\n list: ListModel<never>;\n isTile: boolean;\n}\n\nconst ItemImpl = (props: Props) => {\n const { id, data, triggerRef, list, isTile } = props;\n\n const itemView = list.itemView;\n\n const { gridItemProps, children } = useGridItemProps(props, list);\n\n if (!itemView) {\n return null;\n }\n\n const textValue = itemView.textValue ? itemView.textValue(data) : undefined;\n const href = itemView.href ? itemView.href(data) : undefined;\n const hasAction = !!gridItemProps.onAction || !!href;\n\n const existingRef = \"ref\" in gridItemProps ? gridItemProps.ref : undefined;\n const gridItemPropsWithRef = triggerRef\n ? { ...gridItemProps, ref: mergeRefs(existingRef, triggerRef) }\n : gridItemProps;\n\n return (\n <ItemsGridListItemView\n id={id}\n textValue={textValue}\n href={href}\n target={itemView.target}\n hasAction={hasAction}\n isTile={isTile}\n {...gridItemPropsWithRef}\n >\n <Suspense fallback={<ItemLoadingView />}>{children}</Suspense>\n </ItemsGridListItemView>\n );\n};\n\n// The list model is rebuilt on every render, so it cannot be compared by\n// identity — but everything an item renders from it can.
|
|
1
|
+
{"version":3,"file":"Item.mjs","names":["styles"],"sources":["../../../../../../../../../../../src/components/List/components/Items/components/Item/Item.tsx"],"sourcesContent":["import { useGridItemProps } from \"@/components/List/components/Items/components/Item/hooks/useGridItemProps\";\nimport { useList } from \"@/components/List/hooks/useList\";\nimport type ListModel from \"@/components/List/model/List\";\nimport ItemsGridListItemView from \"@/views/ItemsGridListItemView\";\nimport { mergeRefs } from \"@react-aria/utils\";\nimport type { FC, PropsWithChildren, Ref } from \"react\";\nimport { memo, Suspense } from \"react\";\nimport type { Key } from \"react-aria-components\";\nimport styles from \"./Item.module.scss\";\nimport { ItemLoadingView } from \"./components/ItemLoadingView/ItemLoadingView\";\n\ninterface Props extends PropsWithChildren {\n id: Key;\n data: never;\n triggerRef?: Ref<HTMLDivElement>;\n list: ListModel<never>;\n isTile: boolean;\n /** Stable invoker of the list's latest `onAction` */\n onAction?: (data: never) => void;\n}\n\nconst ItemImpl = (props: Props) => {\n const { id, data, triggerRef, list, isTile } = props;\n\n const itemView = list.itemView;\n\n const { gridItemProps, children } = useGridItemProps(props, list);\n\n if (!itemView) {\n return null;\n }\n\n const textValue = itemView.textValue ? itemView.textValue(data) : undefined;\n const href = itemView.href ? itemView.href(data) : undefined;\n const hasAction = !!gridItemProps.onAction || !!href;\n\n const existingRef = \"ref\" in gridItemProps ? gridItemProps.ref : undefined;\n const gridItemPropsWithRef = triggerRef\n ? { ...gridItemProps, ref: mergeRefs(existingRef, triggerRef) }\n : gridItemProps;\n\n return (\n <ItemsGridListItemView\n id={id}\n textValue={textValue}\n href={href}\n target={itemView.target}\n hasAction={hasAction}\n isTile={isTile}\n {...gridItemPropsWithRef}\n >\n <Suspense fallback={<ItemLoadingView />}>{children}</Suspense>\n </ItemsGridListItemView>\n );\n};\n\n// The list model is rebuilt on every render, so it cannot be compared by\n// identity — but everything an item renders from it can. The render function\n// counts by its `renderDependencies`, or else by its identity: an inline one\n// changes whenever the consumer re-renders, so parent state no longer leaves\n// an item frozen on the values it first saw (#3065), while loading more still\n// skips the re-render. `onAction` arrives as a stable invoker of the latest\n// handler, and `textValue`/`href` count by their result.\nexport const Item = memo(\n ItemImpl,\n (prev, next) =>\n prev.id === next.id &&\n prev.data === next.data &&\n prev.triggerRef === next.triggerRef &&\n prev.isTile === next.isTile &&\n !!prev.onAction === !!next.onAction &&\n prev.list.accordion === next.list.accordion &&\n !!prev.list.itemView?.rendersSameFor(next.list.itemView, next.data),\n);\nItem.displayName = \"Item\";\n\ninterface ItemContainerProps extends PropsWithChildren {\n id?: Key;\n data?: never;\n}\n\nexport const ItemContainer: FC<ItemContainerProps> = (props) => {\n const list = useList();\n return (\n <ItemsGridListItemView\n textValue=\"-\"\n className={styles.item}\n isTile={list.viewMode.isTiles}\n >\n {props.children}\n </ItemsGridListItemView>\n );\n};\n\nexport default Item;\n"],"mappings":";;;;;;;;;;;AAqBA,IAAM,YAAY,UAAiB;CACjC,MAAM,EAAE,IAAI,MAAM,YAAY,MAAM,WAAW;CAE/C,MAAM,WAAW,KAAK;CAEtB,MAAM,EAAE,eAAe,aAAa,iBAAiB,OAAO,IAAI;CAEhE,IAAI,CAAC,UACH,OAAO;CAGT,MAAM,YAAY,SAAS,YAAY,SAAS,UAAU,IAAI,IAAI,KAAA;CAClE,MAAM,OAAO,SAAS,OAAO,SAAS,KAAK,IAAI,IAAI,KAAA;CACnD,MAAM,YAAY,CAAC,CAAC,cAAc,YAAY,CAAC,CAAC;CAEhD,MAAM,cAAc,SAAS,gBAAgB,cAAc,MAAM,KAAA;CACjE,MAAM,uBAAuB,aACzB;EAAE,GAAG;EAAe,KAAK,UAAU,aAAa,UAAU;CAAE,IAC5D;CAEJ,OACE,oBAAC,uBAAD;EACM;EACO;EACL;EACN,QAAQ,SAAS;EACN;EACH;EACR,GAAI;EAEJ,UAAA,oBAAC,UAAD;GAAU,UAAU,oBAAC,iBAAD,CAAkB,CAAA;GAAI;EAAmB,CAAA;CACxC,CAAA;AAE3B;AASA,IAAa,OAAO,KAClB,WACC,MAAM,SACL,KAAK,OAAO,KAAK,MACjB,KAAK,SAAS,KAAK,QACnB,KAAK,eAAe,KAAK,cACzB,KAAK,WAAW,KAAK,UACrB,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,KAAK,YAC3B,KAAK,KAAK,cAAc,KAAK,KAAK,aAClC,CAAC,CAAC,KAAK,KAAK,UAAU,eAAe,KAAK,KAAK,UAAU,KAAK,IAAI,CACtE;AACA,KAAK,cAAc;AAOnB,IAAa,iBAAyC,UAAU;CAC9D,MAAM,OAAO,QAAQ;CACrB,OACE,oBAAC,uBAAD;EACE,WAAU;EACV,WAAWA,oBAAO;EAClB,QAAQ,KAAK,SAAS;EAErB,UAAA,MAAM;CACc,CAAA;AAE3B"}
|
|
@@ -7,9 +7,8 @@ import { useEffect, useId, useRef, useState } from "react";
|
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
//#region src/components/List/components/Items/components/Item/hooks/useGridItemProps.tsx
|
|
9
9
|
var useGridItemProps = (props, list) => {
|
|
10
|
-
const { data, children: childrenFromProps } = props;
|
|
10
|
+
const { data, onAction, children: childrenFromProps } = props;
|
|
11
11
|
const itemView = list.itemView;
|
|
12
|
-
const onAction = list.onAction;
|
|
13
12
|
const [isExpanded, setIsExpanded] = useState(itemView?.defaultExpanded?.(data) ?? false);
|
|
14
13
|
const contentElementId = useId();
|
|
15
14
|
const itemRef = useRef(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGridItemProps.mjs","names":[],"sources":["../../../../../../../../../../../../src/components/List/components/Items/components/Item/hooks/useGridItemProps.tsx"],"sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type List from \"@/components/List/model/List\";\nimport type { PropsContext } from \"@/lib/propsContext\";\nimport { dynamic, PropsContextProvider } from \"@/lib/propsContext\";\nimport { AccordionButton } from \"@/components/List/components/Items/components/Item/components/AccordionButton\";\n\ninterface P extends PropsWithChildren {\n data: never;\n}\n\nexport const useGridItemProps = (props: P, list: List<never>) => {\n const { data, children: childrenFromProps } = props;\n const itemView = list.itemView;\n
|
|
1
|
+
{"version":3,"file":"useGridItemProps.mjs","names":[],"sources":["../../../../../../../../../../../../src/components/List/components/Items/components/Item/hooks/useGridItemProps.tsx"],"sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type List from \"@/components/List/model/List\";\nimport type { PropsContext } from \"@/lib/propsContext\";\nimport { dynamic, PropsContextProvider } from \"@/lib/propsContext\";\nimport { AccordionButton } from \"@/components/List/components/Items/components/Item/components/AccordionButton\";\n\ninterface P extends PropsWithChildren {\n data: never;\n onAction?: (data: never) => void;\n}\n\nexport const useGridItemProps = (props: P, list: List<never>) => {\n const { data, onAction, children: childrenFromProps } = props;\n const itemView = list.itemView;\n\n const [isExpanded, setIsExpanded] = useState(\n itemView?.defaultExpanded?.(data) ?? false,\n );\n const contentElementId = useId();\n const itemRef = useRef<HTMLDivElement>(null);\n\n const accordion = list.accordion;\n const children = childrenFromProps ?? itemView?.render(data);\n\n useEffect(() => {\n if (accordion) {\n itemRef.current?.setAttribute(\"aria-expanded\", String(isExpanded));\n itemRef.current?.setAttribute(\"aria-controls\", contentElementId);\n }\n }, [isExpanded, contentElementId, itemRef.current, accordion]);\n\n if (!accordion) {\n return {\n gridItemProps: {\n onAction: onAction\n ? () => {\n onAction?.(data);\n }\n : undefined,\n },\n children,\n };\n }\n\n const toggleAccordion = () => {\n setIsExpanded((current) => !current);\n onAction?.(data);\n };\n\n const propsContext: PropsContext = {\n Content: {\n id: dynamic((p) => (p.slot === \"bottom\" ? contentElementId : undefined)),\n wrapWith: dynamic((p) =>\n p.slot === \"bottom\" ? (\n <AccordionButton\n contentElementId={contentElementId}\n toggle={toggleAccordion}\n isExpanded={isExpanded}\n />\n ) : undefined,\n ),\n },\n };\n\n return {\n gridItemProps: {\n ref: itemRef,\n onAction: toggleAccordion,\n },\n children: (\n <PropsContextProvider\n props={propsContext}\n dependencies={[contentElementId, isExpanded]}\n >\n {children}\n </PropsContextProvider>\n ),\n };\n};\n"],"mappings":";;;;;;;;AAYA,IAAa,oBAAoB,OAAU,SAAsB;CAC/D,MAAM,EAAE,MAAM,UAAU,UAAU,sBAAsB;CACxD,MAAM,WAAW,KAAK;CAEtB,MAAM,CAAC,YAAY,iBAAiB,SAClC,UAAU,kBAAkB,IAAI,KAAK,KACvC;CACA,MAAM,mBAAmB,MAAM;CAC/B,MAAM,UAAU,OAAuB,IAAI;CAE3C,MAAM,YAAY,KAAK;CACvB,MAAM,WAAW,qBAAqB,UAAU,OAAO,IAAI;CAE3D,gBAAgB;EACd,IAAI,WAAW;GACb,QAAQ,SAAS,aAAa,iBAAiB,OAAO,UAAU,CAAC;GACjE,QAAQ,SAAS,aAAa,iBAAiB,gBAAgB;EACjE;CACF,GAAG;EAAC;EAAY;EAAkB,QAAQ;EAAS;CAAS,CAAC;CAE7D,IAAI,CAAC,WACH,OAAO;EACL,eAAe,EACb,UAAU,iBACA;GACJ,WAAW,IAAI;EACjB,IACA,KAAA,EACN;EACA;CACF;CAGF,MAAM,wBAAwB;EAC5B,eAAe,YAAY,CAAC,OAAO;EACnC,WAAW,IAAI;CACjB;CAEA,MAAM,eAA6B,EACjC,SAAS;EACP,IAAI,SAAS,MAAO,EAAE,SAAS,WAAW,mBAAmB,KAAA,CAAU;EACvE,UAAU,SAAS,MACjB,EAAE,SAAS,WACT,oBAAC,iBAAD;GACoB;GAClB,QAAQ;GACI;EACb,CAAA,IACC,KAAA,CACN;CACF,EACF;CAEA,OAAO;EACL,eAAe;GACb,KAAK;GACL,UAAU;EACZ;EACA,UACE,oBAAC,sBAAD;GACE,OAAO;GACP,cAAc,CAAC,kBAAkB,UAAU;GAE1C;EACmB,CAAA;CAE1B;AACF"}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
/* */
|
|
3
3
|
import { useList } from "../../hooks/useList.mjs";
|
|
4
4
|
import { useInfiniteScrollTrigger } from "../../hooks/useInfiniteScrollTrigger.mjs";
|
|
5
|
+
import { useLatestOnAction } from "../../hooks/useLatestOnAction.mjs";
|
|
5
6
|
import Table_module_default from "./Table.module.mjs";
|
|
6
7
|
import TableView from "../../../../views/TableView.mjs";
|
|
7
8
|
import TableHeaderView from "../../../../views/TableHeaderView.mjs";
|
|
8
9
|
import TableBodyView from "../../../../views/TableBodyView.mjs";
|
|
9
|
-
import TableRowView from "../../../../views/TableRowView.mjs";
|
|
10
|
-
import TableCellView from "../../../../views/TableCellView.mjs";
|
|
11
10
|
import TableColumnView from "../../../../views/TableColumnView.mjs";
|
|
12
11
|
import { TableBodyLoadingView } from "./components/TableBodyLoadingView.mjs";
|
|
12
|
+
import { Row } from "./components/Row.mjs";
|
|
13
13
|
import clsx from "clsx";
|
|
14
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
15
|
//#region src/components/List/components/Table/Table.tsx
|
|
@@ -21,19 +21,15 @@ var Table = () => {
|
|
|
21
21
|
const isInitiallyLoading = list.loader.useIsInitiallyLoading();
|
|
22
22
|
const isLoadingMore = list.loader.useIsLoadingMore();
|
|
23
23
|
const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();
|
|
24
|
+
const onAction = useLatestOnAction(list);
|
|
24
25
|
if (!table || listIsEmpty) return null;
|
|
25
|
-
const rowAction = table.list.onAction;
|
|
26
26
|
const tableClassName = clsx(Table_module_default.table, isLoading && !(list.infiniteScroll && isLoadingMore) && Table_module_default.isLoading, table.componentProps.className);
|
|
27
|
-
const rows = list.items.entries.map((item, index) => /* @__PURE__ */ jsx(
|
|
28
|
-
className: clsx(Table_module_default.row, rowAction && Table_module_default.hasAction, table.body.row.componentProps.className),
|
|
27
|
+
const rows = list.items.entries.map((item, index) => /* @__PURE__ */ jsx(Row, {
|
|
29
28
|
id: item.id,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
...cell.componentProps,
|
|
35
|
-
children: cell.renderFn ? cell.renderFn(item.data, list) : void 0
|
|
36
|
-
}, i))
|
|
29
|
+
data: item.data,
|
|
30
|
+
list,
|
|
31
|
+
onAction,
|
|
32
|
+
triggerRef: index === triggerIndex ? triggerRef : void 0
|
|
37
33
|
}, item.id));
|
|
38
34
|
return /* @__PURE__ */ jsxs(TableView, {
|
|
39
35
|
...list.componentProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.mjs","names":["styles"],"sources":["../../../../../../../../../src/components/List/components/Table/Table.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { useList } from \"@/components/List\";\nimport styles from \"./Table.module.scss\";\nimport clsx from \"clsx\";\nimport TableView from \"@/views/TableView\";\nimport TableHeaderView from \"@/views/TableHeaderView\";\nimport TableBodyView from \"@/views/TableBodyView\";\nimport
|
|
1
|
+
{"version":3,"file":"Table.mjs","names":["styles"],"sources":["../../../../../../../../../src/components/List/components/Table/Table.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { useList } from \"@/components/List\";\nimport styles from \"./Table.module.scss\";\nimport clsx from \"clsx\";\nimport TableView from \"@/views/TableView\";\nimport TableHeaderView from \"@/views/TableHeaderView\";\nimport TableBodyView from \"@/views/TableBodyView\";\nimport TableColumnView from \"@/views/TableColumnView\";\nimport { TableBodyLoadingView } from \"@/components/List/components/Table/components/TableBodyLoadingView\";\nimport { useInfiniteScrollTrigger } from \"@/components/List/hooks/useInfiniteScrollTrigger\";\nimport { useLatestOnAction } from \"@/components/List/hooks/useLatestOnAction\";\nimport { Row } from \"@/components/List/components/Table/components/Row\";\n\nexport const Table: FC = () => {\n const list = useList();\n const table = list.table;\n const listIsEmpty = list.useIsEmpty();\n\n const isLoading = list.loader.useIsLoading();\n const isInitiallyLoading = list.loader.useIsInitiallyLoading();\n const isLoadingMore = list.loader.useIsLoadingMore();\n\n const { triggerRef, triggerIndex } = useInfiniteScrollTrigger();\n const onAction = useLatestOnAction(list);\n\n if (!table || listIsEmpty) {\n return null;\n }\n\n const tableClassName = clsx(\n styles.table,\n isLoading && !(list.infiniteScroll && isLoadingMore) && styles.isLoading,\n table.componentProps.className,\n );\n\n const rows = list.items.entries.map((item, index) => (\n <Row\n key={item.id}\n id={item.id}\n data={item.data}\n list={list}\n onAction={onAction}\n triggerRef={index === triggerIndex ? triggerRef : undefined}\n />\n ));\n\n return (\n <TableView\n {...list.componentProps}\n {...table.componentProps}\n className={tableClassName}\n aria-hidden={isInitiallyLoading}\n aria-busy={isLoading}\n >\n <TableHeaderView {...table.header.componentProps}>\n {table.header.columns.map((col, i) => (\n <TableColumnView key={i} {...col.componentProps} />\n ))}\n </TableHeaderView>\n <TableBodyView {...table.body.componentProps}>\n {isInitiallyLoading ? <TableBodyLoadingView /> : rows}\n </TableBodyView>\n </TableView>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,cAAkB;CAC7B,MAAM,OAAO,QAAQ;CACrB,MAAM,QAAQ,KAAK;CACnB,MAAM,cAAc,KAAK,WAAW;CAEpC,MAAM,YAAY,KAAK,OAAO,aAAa;CAC3C,MAAM,qBAAqB,KAAK,OAAO,sBAAsB;CAC7D,MAAM,gBAAgB,KAAK,OAAO,iBAAiB;CAEnD,MAAM,EAAE,YAAY,iBAAiB,yBAAyB;CAC9D,MAAM,WAAW,kBAAkB,IAAI;CAEvC,IAAI,CAAC,SAAS,aACZ,OAAO;CAGT,MAAM,iBAAiB,KACrBA,qBAAO,OACP,aAAa,EAAE,KAAK,kBAAkB,kBAAkBA,qBAAO,WAC/D,MAAM,eAAe,SACvB;CAEA,MAAM,OAAO,KAAK,MAAM,QAAQ,KAAK,MAAM,UACzC,oBAAC,KAAD;EAEE,IAAI,KAAK;EACT,MAAM,KAAK;EACL;EACI;EACV,YAAY,UAAU,eAAe,aAAa,KAAA;CACnD,GANM,KAAK,EAMX,CACF;CAED,OACE,qBAAC,WAAD;EACE,GAAI,KAAK;EACT,GAAI,MAAM;EACV,WAAW;EACX,eAAa;EACb,aAAW;EALb,UAAA,CAOE,oBAAC,iBAAD;GAAiB,GAAI,MAAM,OAAO;GAC/B,UAAA,MAAM,OAAO,QAAQ,KAAK,KAAK,MAC9B,oBAAC,iBAAD,EAAyB,GAAI,IAAI,eAAiB,GAA5B,CAA4B,CACnD;EACc,CAAA,GACjB,oBAAC,eAAD;GAAe,GAAI,MAAM,KAAK;GAC3B,UAAA,qBAAqB,oBAAC,sBAAD,CAAuB,CAAA,IAAI;EACpC,CAAA,CACN;;AAEf"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
/* */
|
|
3
|
+
import Table_module_default from "../Table.module.mjs";
|
|
4
|
+
import TableRowView from "../../../../../views/TableRowView.mjs";
|
|
5
|
+
import TableCellView from "../../../../../views/TableCellView.mjs";
|
|
6
|
+
import clsx from "clsx";
|
|
7
|
+
import { memo } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
//#region src/components/List/components/Table/components/Row.tsx
|
|
10
|
+
var RowImpl = (props) => {
|
|
11
|
+
const { id, data, list, onAction, triggerRef } = props;
|
|
12
|
+
const row = list.table?.body.row;
|
|
13
|
+
if (!row) return null;
|
|
14
|
+
return /* @__PURE__ */ jsx(TableRowView, {
|
|
15
|
+
...row.componentProps,
|
|
16
|
+
className: clsx(Table_module_default.row, onAction && Table_module_default.hasAction, row.componentProps.className),
|
|
17
|
+
id,
|
|
18
|
+
onAction: onAction ? () => onAction(data) : void 0,
|
|
19
|
+
...triggerRef ? { ref: triggerRef } : {},
|
|
20
|
+
children: row.cells.map((cell, i) => /* @__PURE__ */ jsx(TableCellView, {
|
|
21
|
+
...cell.componentProps,
|
|
22
|
+
children: cell.renderFn ? cell.renderFn(data, list) : void 0
|
|
23
|
+
}, i))
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var Row = memo(RowImpl, (prev, next) => prev.id === next.id && prev.data === next.data && prev.triggerRef === next.triggerRef && !!prev.onAction === !!next.onAction && !!prev.list.table?.body.row.rendersSameAs(next.list.table?.body.row));
|
|
27
|
+
Row.displayName = "Row";
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Row, Row as default };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=Row.mjs.map
|
package/dist/js/packages/components/src/components/List/components/Table/components/Row.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Row.mjs","names":["styles"],"sources":["../../../../../../../../../../src/components/List/components/Table/components/Row.tsx"],"sourcesContent":["import type { Ref } from \"react\";\nimport { memo } from \"react\";\nimport clsx from \"clsx\";\nimport type { Key } from \"react-aria-components\";\nimport type ListModel from \"@/components/List/model/List\";\nimport TableRowView from \"@/views/TableRowView\";\nimport TableCellView from \"@/views/TableCellView\";\nimport styles from \"../Table.module.scss\";\n\ninterface Props {\n id: Key;\n data: never;\n list: ListModel<never>;\n /** Stable invoker of the list's latest `onAction` */\n onAction?: (data: never) => void;\n triggerRef?: Ref<HTMLTableRowElement>;\n}\n\nconst RowImpl = (props: Props) => {\n const { id, data, list, onAction, triggerRef } = props;\n const row = list.table?.body.row;\n\n if (!row) {\n return null;\n }\n\n return (\n <TableRowView\n {...row.componentProps}\n className={clsx(\n styles.row,\n onAction && styles.hasAction,\n row.componentProps.className,\n )}\n id={id}\n onAction={onAction ? () => onAction(data) : undefined}\n {...(triggerRef ? { ref: triggerRef } : {})}\n >\n {row.cells.map((cell, i) => (\n <TableCellView key={i} {...cell.componentProps}>\n {cell.renderFn ? cell.renderFn(data, list) : undefined}\n </TableCellView>\n ))}\n </TableRowView>\n );\n};\n\n// The list model is rebuilt on every render, so it cannot be compared by\n// identity. A row that declares `renderDependencies` re-renders only when its data,\n// those dependencies or a cell's props change — the cells' render functions\n// count by the dependencies. Without them, rows re-render with the list.\nexport const Row = memo(\n RowImpl,\n (prev, next) =>\n prev.id === next.id &&\n prev.data === next.data &&\n prev.triggerRef === next.triggerRef &&\n !!prev.onAction === !!next.onAction &&\n !!prev.list.table?.body.row.rendersSameAs(next.list.table?.body.row),\n);\nRow.displayName = \"Row\";\n\nexport default Row;\n"],"mappings":";;;;;;;;;AAkBA,IAAM,WAAW,UAAiB;CAChC,MAAM,EAAE,IAAI,MAAM,MAAM,UAAU,eAAe;CACjD,MAAM,MAAM,KAAK,OAAO,KAAK;CAE7B,IAAI,CAAC,KACH,OAAO;CAGT,OACE,oBAAC,cAAD;EACE,GAAI,IAAI;EACR,WAAW,KACTA,qBAAO,KACP,YAAYA,qBAAO,WACnB,IAAI,eAAe,SACrB;EACI;EACJ,UAAU,iBAAiB,SAAS,IAAI,IAAI,KAAA;EAC5C,GAAK,aAAa,EAAE,KAAK,WAAW,IAAI,CAAC;EAExC,UAAA,IAAI,MAAM,KAAK,MAAM,MACpB,oBAAC,eAAD;GAAuB,GAAI,KAAK;GAC7B,UAAA,KAAK,WAAW,KAAK,SAAS,MAAM,IAAI,IAAI,KAAA;EAChC,GAFK,CAEL,CAChB;CACW,CAAA;AAElB;AAMA,IAAa,MAAM,KACjB,UACC,MAAM,SACL,KAAK,OAAO,KAAK,MACjB,KAAK,SAAS,KAAK,QACnB,KAAK,eAAe,KAAK,cACzB,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,KAAK,YAC3B,CAAC,CAAC,KAAK,KAAK,OAAO,KAAK,IAAI,cAAc,KAAK,KAAK,OAAO,KAAK,GAAG,CACvE;AACA,IAAI,cAAc"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
/* */
|
|
3
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
4
|
+
//#region src/components/List/hooks/useLatestOnAction.ts
|
|
5
|
+
/**
|
|
6
|
+
* A stable invoker of the list's latest `onAction`, or `undefined` without one.
|
|
7
|
+
* An event handler only ever needs to be the latest one, so items and rows do
|
|
8
|
+
* not re-render for an inline `onAction`.
|
|
9
|
+
*/
|
|
10
|
+
var useLatestOnAction = (list) => {
|
|
11
|
+
const onActionRef = useRef(list.onAction);
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
onActionRef.current = list.onAction;
|
|
14
|
+
});
|
|
15
|
+
const invokeOnAction = useCallback((data) => onActionRef.current?.(data), []);
|
|
16
|
+
return list.onAction ? invokeOnAction : void 0;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useLatestOnAction };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=useLatestOnAction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLatestOnAction.mjs","names":[],"sources":["../../../../../../../../src/components/List/hooks/useLatestOnAction.ts"],"sourcesContent":["import { useCallback, useLayoutEffect, useRef } from \"react\";\nimport type List from \"@/components/List/model/List\";\n\n/**\n * A stable invoker of the list's latest `onAction`, or `undefined` without one.\n * An event handler only ever needs to be the latest one, so items and rows do\n * not re-render for an inline `onAction`.\n */\nexport const useLatestOnAction = (list: List<never>) => {\n const onActionRef = useRef(list.onAction);\n useLayoutEffect(() => {\n onActionRef.current = list.onAction;\n });\n const invokeOnAction = useCallback(\n (data: never) => onActionRef.current?.(data),\n [],\n );\n return list.onAction ? invokeOnAction : undefined;\n};\n"],"mappings":";;;;;;;;;AAQA,IAAa,qBAAqB,SAAsB;CACtD,MAAM,cAAc,OAAO,KAAK,QAAQ;CACxC,sBAAsB;EACpB,YAAY,UAAU,KAAK;CAC7B,CAAC;CACD,MAAM,iBAAiB,aACpB,SAAgB,YAAY,UAAU,IAAI,GAC3C,CAAC,CACH;CACA,OAAO,KAAK,WAAW,iBAAiB,KAAA;AAC1C"}
|
|
@@ -43,6 +43,7 @@ var List = class List {
|
|
|
43
43
|
const { settingStorageKey, itemView, table, filters = [], sorting = [], batchesController, onChange, loader, search, onAction, getItemId, defaultViewMode, accordion = false, infiniteScroll = false, loadingItemsCount = 5, settingsStorageDefaults, emptyView, emptySearchResultView, ...componentProps } = shape;
|
|
44
44
|
const warnDeprecation = useWarnDeprecation();
|
|
45
45
|
if (itemView?.fallback !== void 0) warnDeprecation("The 'fallback' prop is deprecated and will be removed in a future release. Use 'loadingView' instead.");
|
|
46
|
+
if (itemView?.dependencies !== void 0) warnDeprecation("The 'dependencies' prop of 'List.Item' is deprecated and will be removed in a future release. Use 'renderDependencies' instead.");
|
|
46
47
|
this.settingsStorageDefaults = settingsStorageDefaults;
|
|
47
48
|
const generalSettingsStore = useSettings();
|
|
48
49
|
this.settingsStorage = settingStorageKey && generalSettingsStore ? new ListSettingsStore(this, generalSettingsStore, { storageKey: settingStorageKey }) : void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.mjs","names":["BatchesController"],"sources":["../../../../../../../../src/components/List/model/List.ts"],"sourcesContent":["import { ItemCollection } from \"@/components/List/model/item/ItemCollection\";\nimport { BatchesController } from \"@/components/List/model/pagination/BatchesController\";\nimport { Filter } from \"./filter/Filter\";\nimport { Sorting } from \"@/components/List/model/sorting/Sorting\";\nimport ReactTable from \"@/components/List/model/ReactTable\";\nimport type {\n EmptyViewType,\n GetItemId,\n ItemActionFn,\n ListSettingsStorageDefaults,\n ListShape,\n ListSupportedComponentProps,\n} from \"@/components/List/model/types\";\nimport { IncrementalLoader } from \"@/components/List/model/loading/IncrementalLoader\";\nimport invariant from \"invariant\";\nimport { Search } from \"@/components/List/model/search/Search\";\nimport { ItemView } from \"@/components/List/model/item/ItemView\";\nimport { Table } from \"@/components/List/model/table/Table\";\nimport { useEffect, type ReactNode } from \"react\";\nimport { ListSettingsStore } from \"./ListSettingsStore\";\nimport { ListViewMode } from \"./ListViewMode\";\nimport { useSettings } from \"@/components/SettingsProvider/SettingsProvider\";\nimport { DateRangeFilter } from \"@/components/List/model/filter/DateRangeFilter\";\nimport { useWarnDeprecation } from \"@/components/DeprecationWarningProvider\";\nimport type {\n ListModelContext,\n ListSettingsPort,\n} from \"@mittwald/flow-components-base\";\nimport type { Table as ReactTableInstance } from \"@tanstack/table-core\";\n\nexport class List<T = unknown, TMeta = unknown> implements ListModelContext<T> {\n public readonly filters: (\n Filter<T, never, never> | DateRangeFilter<T, never>\n )[];\n public readonly itemView?: ItemView<T>;\n public readonly table?: Table<T>;\n public readonly search?: Search<T>;\n public readonly sorting: Sorting<T>[];\n public readonly items: ItemCollection<T>;\n public readonly reactTable: ReactTable<T>;\n public readonly batches: BatchesController<T>;\n public readonly loader: IncrementalLoader<T>;\n public readonly onAction?: ItemActionFn<T>;\n public readonly accordion: boolean;\n public readonly infiniteScroll: boolean;\n public readonly getItemId?: GetItemId<T>;\n public readonly componentProps: ListSupportedComponentProps;\n public metadata?: TMeta;\n public readonly settingsStorage?: ListSettingsStore<T>;\n public readonly loadingItemsCount;\n public readonly viewMode: ListViewMode<T>;\n public readonly emptyView?: ReactNode;\n public readonly emptySearchResultView?: ReactNode;\n public readonly settingsStorageDefaults?: ListSettingsStorageDefaults;\n\n public constructor(shape: ListShape<T, TMeta>) {\n const {\n settingStorageKey,\n itemView,\n table,\n filters = [],\n sorting = [],\n batchesController,\n onChange,\n loader,\n search,\n onAction,\n getItemId,\n defaultViewMode,\n accordion = false,\n infiniteScroll = false,\n loadingItemsCount = 5,\n settingsStorageDefaults,\n emptyView,\n emptySearchResultView,\n ...componentProps\n } = shape;\n\n const warnDeprecation = useWarnDeprecation();\n if (itemView?.fallback !== undefined) {\n warnDeprecation(\n \"The 'fallback' prop is deprecated and will be removed in a future release. Use 'loadingView' instead.\",\n );\n }\n\n this.settingsStorageDefaults = settingsStorageDefaults;\n const generalSettingsStore = useSettings();\n\n this.settingsStorage =\n settingStorageKey && generalSettingsStore\n ? new ListSettingsStore(this, generalSettingsStore, {\n storageKey: settingStorageKey,\n })\n : undefined;\n\n this.items = new ItemCollection(this);\n this.filters = filters.map((shape) =>\n shape.mode === \"dateRange\"\n ? new DateRangeFilter(this, shape)\n : new Filter(this, shape),\n );\n this.sorting = sorting.map((shape) => new Sorting<T>(this, shape));\n this.search = search ? new Search(this, search) : undefined;\n this.itemView = itemView ? new ItemView(this, itemView) : undefined;\n this.accordion = accordion;\n this.infiniteScroll = infiniteScroll;\n this.table = table ? new Table(this, table) : undefined;\n this.batches = new BatchesController(this, batchesController);\n\n /*\n * The controller no longer subscribes itself: the filters and the search\n * are this list's, and handing a list of concrete filters to a shared\n * model is the `Table<never>` variance trap. `IncrementalLoader` still\n * subscribes in its own constructor, which runs right after this, so the\n * order of the two resets is unchanged.\n */\n this.filters.forEach((f) => f.onFilterUpdated(() => this.batches.reset()));\n this.search?.onUpdated(() => this.batches.reset());\n this.componentProps = componentProps;\n /*\n * Before the loader: its state takes `getItemId` over in its constructor,\n * and a loader built first would never deduplicate.\n */\n this.getItemId = getItemId;\n this.loader = IncrementalLoader.useNew<T>(this, loader);\n this.onAction = onAction;\n this.loadingItemsCount = loadingItemsCount;\n this.reactTable = ReactTable.useNew(this, onChange, {\n manualFiltering: this.loader.manualFiltering,\n manualPagination: this.loader.manualPagination,\n manualSorting: this.loader.manualSorting,\n });\n this.viewMode = ListViewMode.useNew(this, { defaultViewMode });\n this.emptyView = emptyView;\n this.emptySearchResultView = emptySearchResultView;\n\n useEffect(() => {\n this.filters.forEach((f) => f.deleteUnknownFilterValues());\n }, [this.filters]);\n }\n\n /*\n * `ListModelContext` — what the shared model in\n * `@mittwald/flow-components-base` reaches for, so `Sorting` and `Search` can\n * keep being handed the list itself. Getters, because the model is built\n * before the table is.\n */\n public get dataTable(): ReactTableInstance<T> {\n return this.reactTable.table;\n }\n\n public get settings(): ListSettingsPort | undefined {\n return this.settingsStorage;\n }\n\n public get settingsDefaults(): ListSettingsStorageDefaults | undefined {\n return this.settingsStorageDefaults;\n }\n\n public getEmptyViewType(): EmptyViewType {\n return this.hasActiveFilters || this.search?.isSet ? \"search\" : \"list\";\n }\n\n public get hasActiveFilters(): boolean {\n return this.filters.some((f) => f.isActive());\n }\n\n public get visibleSorting() {\n return this.sorting.filter((s) => s.initialEnabled !== \"hidden\");\n }\n\n public static useNew<T, TMeta = unknown>(\n shape: ListShape<T, TMeta>,\n ): List<T, TMeta> {\n return new List<T, TMeta>(shape);\n }\n\n public getSorting(id: string): Sorting<T> {\n const sorting = this.sorting.find((s) => s.id === id);\n invariant(!!sorting, `Could not get Sorting (ID: ${id})`);\n return sorting;\n }\n\n public clearSorting(): void {\n return this.sorting.forEach((s) => s.clear());\n }\n\n public resetFilters(): void {\n return this.filters.forEach((f) => f.resetValues());\n }\n\n public clearFilters(): void {\n return this.filters.forEach((f) => f.clear());\n }\n\n public useIsEmpty(): boolean {\n return !this.loader.useIsLoading() && this.items.entries.length === 0;\n }\n}\n\nexport default List;\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"List.mjs","names":["BatchesController"],"sources":["../../../../../../../../src/components/List/model/List.ts"],"sourcesContent":["import { ItemCollection } from \"@/components/List/model/item/ItemCollection\";\nimport { BatchesController } from \"@/components/List/model/pagination/BatchesController\";\nimport { Filter } from \"./filter/Filter\";\nimport { Sorting } from \"@/components/List/model/sorting/Sorting\";\nimport ReactTable from \"@/components/List/model/ReactTable\";\nimport type {\n EmptyViewType,\n GetItemId,\n ItemActionFn,\n ListSettingsStorageDefaults,\n ListShape,\n ListSupportedComponentProps,\n} from \"@/components/List/model/types\";\nimport { IncrementalLoader } from \"@/components/List/model/loading/IncrementalLoader\";\nimport invariant from \"invariant\";\nimport { Search } from \"@/components/List/model/search/Search\";\nimport { ItemView } from \"@/components/List/model/item/ItemView\";\nimport { Table } from \"@/components/List/model/table/Table\";\nimport { useEffect, type ReactNode } from \"react\";\nimport { ListSettingsStore } from \"./ListSettingsStore\";\nimport { ListViewMode } from \"./ListViewMode\";\nimport { useSettings } from \"@/components/SettingsProvider/SettingsProvider\";\nimport { DateRangeFilter } from \"@/components/List/model/filter/DateRangeFilter\";\nimport { useWarnDeprecation } from \"@/components/DeprecationWarningProvider\";\nimport type {\n ListModelContext,\n ListSettingsPort,\n} from \"@mittwald/flow-components-base\";\nimport type { Table as ReactTableInstance } from \"@tanstack/table-core\";\n\nexport class List<T = unknown, TMeta = unknown> implements ListModelContext<T> {\n public readonly filters: (\n Filter<T, never, never> | DateRangeFilter<T, never>\n )[];\n public readonly itemView?: ItemView<T>;\n public readonly table?: Table<T>;\n public readonly search?: Search<T>;\n public readonly sorting: Sorting<T>[];\n public readonly items: ItemCollection<T>;\n public readonly reactTable: ReactTable<T>;\n public readonly batches: BatchesController<T>;\n public readonly loader: IncrementalLoader<T>;\n public readonly onAction?: ItemActionFn<T>;\n public readonly accordion: boolean;\n public readonly infiniteScroll: boolean;\n public readonly getItemId?: GetItemId<T>;\n public readonly componentProps: ListSupportedComponentProps;\n public metadata?: TMeta;\n public readonly settingsStorage?: ListSettingsStore<T>;\n public readonly loadingItemsCount;\n public readonly viewMode: ListViewMode<T>;\n public readonly emptyView?: ReactNode;\n public readonly emptySearchResultView?: ReactNode;\n public readonly settingsStorageDefaults?: ListSettingsStorageDefaults;\n\n public constructor(shape: ListShape<T, TMeta>) {\n const {\n settingStorageKey,\n itemView,\n table,\n filters = [],\n sorting = [],\n batchesController,\n onChange,\n loader,\n search,\n onAction,\n getItemId,\n defaultViewMode,\n accordion = false,\n infiniteScroll = false,\n loadingItemsCount = 5,\n settingsStorageDefaults,\n emptyView,\n emptySearchResultView,\n ...componentProps\n } = shape;\n\n const warnDeprecation = useWarnDeprecation();\n if (itemView?.fallback !== undefined) {\n warnDeprecation(\n \"The 'fallback' prop is deprecated and will be removed in a future release. Use 'loadingView' instead.\",\n );\n }\n if (itemView?.dependencies !== undefined) {\n warnDeprecation(\n \"The 'dependencies' prop of 'List.Item' is deprecated and will be removed in a future release. Use 'renderDependencies' instead.\",\n );\n }\n\n this.settingsStorageDefaults = settingsStorageDefaults;\n const generalSettingsStore = useSettings();\n\n this.settingsStorage =\n settingStorageKey && generalSettingsStore\n ? new ListSettingsStore(this, generalSettingsStore, {\n storageKey: settingStorageKey,\n })\n : undefined;\n\n this.items = new ItemCollection(this);\n this.filters = filters.map((shape) =>\n shape.mode === \"dateRange\"\n ? new DateRangeFilter(this, shape)\n : new Filter(this, shape),\n );\n this.sorting = sorting.map((shape) => new Sorting<T>(this, shape));\n this.search = search ? new Search(this, search) : undefined;\n this.itemView = itemView ? new ItemView(this, itemView) : undefined;\n this.accordion = accordion;\n this.infiniteScroll = infiniteScroll;\n this.table = table ? new Table(this, table) : undefined;\n this.batches = new BatchesController(this, batchesController);\n\n /*\n * The controller no longer subscribes itself: the filters and the search\n * are this list's, and handing a list of concrete filters to a shared\n * model is the `Table<never>` variance trap. `IncrementalLoader` still\n * subscribes in its own constructor, which runs right after this, so the\n * order of the two resets is unchanged.\n */\n this.filters.forEach((f) => f.onFilterUpdated(() => this.batches.reset()));\n this.search?.onUpdated(() => this.batches.reset());\n this.componentProps = componentProps;\n /*\n * Before the loader: its state takes `getItemId` over in its constructor,\n * and a loader built first would never deduplicate.\n */\n this.getItemId = getItemId;\n this.loader = IncrementalLoader.useNew<T>(this, loader);\n this.onAction = onAction;\n this.loadingItemsCount = loadingItemsCount;\n this.reactTable = ReactTable.useNew(this, onChange, {\n manualFiltering: this.loader.manualFiltering,\n manualPagination: this.loader.manualPagination,\n manualSorting: this.loader.manualSorting,\n });\n this.viewMode = ListViewMode.useNew(this, { defaultViewMode });\n this.emptyView = emptyView;\n this.emptySearchResultView = emptySearchResultView;\n\n useEffect(() => {\n this.filters.forEach((f) => f.deleteUnknownFilterValues());\n }, [this.filters]);\n }\n\n /*\n * `ListModelContext` — what the shared model in\n * `@mittwald/flow-components-base` reaches for, so `Sorting` and `Search` can\n * keep being handed the list itself. Getters, because the model is built\n * before the table is.\n */\n public get dataTable(): ReactTableInstance<T> {\n return this.reactTable.table;\n }\n\n public get settings(): ListSettingsPort | undefined {\n return this.settingsStorage;\n }\n\n public get settingsDefaults(): ListSettingsStorageDefaults | undefined {\n return this.settingsStorageDefaults;\n }\n\n public getEmptyViewType(): EmptyViewType {\n return this.hasActiveFilters || this.search?.isSet ? \"search\" : \"list\";\n }\n\n public get hasActiveFilters(): boolean {\n return this.filters.some((f) => f.isActive());\n }\n\n public get visibleSorting() {\n return this.sorting.filter((s) => s.initialEnabled !== \"hidden\");\n }\n\n public static useNew<T, TMeta = unknown>(\n shape: ListShape<T, TMeta>,\n ): List<T, TMeta> {\n return new List<T, TMeta>(shape);\n }\n\n public getSorting(id: string): Sorting<T> {\n const sorting = this.sorting.find((s) => s.id === id);\n invariant(!!sorting, `Could not get Sorting (ID: ${id})`);\n return sorting;\n }\n\n public clearSorting(): void {\n return this.sorting.forEach((s) => s.clear());\n }\n\n public resetFilters(): void {\n return this.filters.forEach((f) => f.resetValues());\n }\n\n public clearFilters(): void {\n return this.filters.forEach((f) => f.clear());\n }\n\n public useIsEmpty(): boolean {\n return !this.loader.useIsLoading() && this.items.entries.length === 0;\n }\n}\n\nexport default List;\n"],"mappings":"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"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
/* */
|
|
3
3
|
import { createElement } from "react";
|
|
4
|
+
import { isShallowEqual } from "remeda";
|
|
4
5
|
//#region src/components/List/model/item/ItemView.ts
|
|
5
|
-
var dependenciesAreEqual = (a, b) => a === b || !!a && !!b && a.length === b.length && a.every((dependency, index) => Object.is(dependency, b[index]));
|
|
6
6
|
var ItemView = class ItemView {
|
|
7
7
|
list;
|
|
8
8
|
textValue;
|
|
@@ -13,10 +13,12 @@ var ItemView = class ItemView {
|
|
|
13
13
|
showTiles;
|
|
14
14
|
showList;
|
|
15
15
|
tileMaxWidth;
|
|
16
|
+
renderDependencies;
|
|
16
17
|
dependencies;
|
|
17
18
|
renderFn;
|
|
19
|
+
lastComparison;
|
|
18
20
|
constructor(list, shape = {}) {
|
|
19
|
-
const { fallback, loadingView = fallback, textValue, href, target, defaultExpanded, renderFn, showTiles, showList = true, tileMaxWidth = 230, dependencies } = shape;
|
|
21
|
+
const { fallback, loadingView = fallback, textValue, href, target, defaultExpanded, renderFn, showTiles, showList = true, tileMaxWidth = 230, renderDependencies, dependencies } = shape;
|
|
20
22
|
this.list = list;
|
|
21
23
|
this.textValue = textValue;
|
|
22
24
|
this.renderFn = renderFn;
|
|
@@ -27,16 +29,27 @@ var ItemView = class ItemView {
|
|
|
27
29
|
this.showTiles = showTiles;
|
|
28
30
|
this.showList = showList;
|
|
29
31
|
this.tileMaxWidth = tileMaxWidth;
|
|
32
|
+
this.renderDependencies = renderDependencies;
|
|
30
33
|
this.dependencies = dependencies;
|
|
31
34
|
}
|
|
32
35
|
static fallbackRenderItemFn = (item) => createElement("pre", void 0, JSON.stringify(item));
|
|
33
36
|
/**
|
|
34
|
-
* Whether `other` would render
|
|
35
|
-
*
|
|
36
|
-
* and the dependencies
|
|
37
|
+
* Whether `other` would render the item holding `data` identically. The
|
|
38
|
+
* render function counts by its `renderDependencies` where given, otherwise
|
|
39
|
+
* by its identity and the deprecated `dependencies`. `textValue` and `href`
|
|
40
|
+
* count by what they return for `data`, so inline functions do not re-render
|
|
41
|
+
* the item. `defaultExpanded` is read on mount only, so it does not count at
|
|
42
|
+
* all.
|
|
37
43
|
*/
|
|
38
|
-
|
|
39
|
-
return !!other &&
|
|
44
|
+
rendersSameFor(other, data) {
|
|
45
|
+
return !!other && this.rendersSameContentAs(other) && this.textValue?.(data) === other.textValue?.(data) && this.href?.(data) === other.href?.(data) && this.target === other.target;
|
|
46
|
+
}
|
|
47
|
+
rendersSameContentAs(other) {
|
|
48
|
+
if (this.lastComparison?.other !== other) this.lastComparison = {
|
|
49
|
+
other,
|
|
50
|
+
result: this.renderDependencies || other.renderDependencies ? isShallowEqual(this.renderDependencies, other.renderDependencies) : this.renderFn === other.renderFn && isShallowEqual(this.dependencies, other.dependencies)
|
|
51
|
+
};
|
|
52
|
+
return this.lastComparison.result;
|
|
40
53
|
}
|
|
41
54
|
render(data) {
|
|
42
55
|
return (this.renderFn ?? ItemView.fallbackRenderItemFn)(data, this.list);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemView.mjs","names":[],"sources":["../../../../../../../../../src/components/List/model/item/ItemView.ts"],"sourcesContent":["import type {\n DependencyList,\n HTMLAttributeAnchorTarget,\n ReactElement,\n ReactNode,\n} from \"react\";\nimport { createElement } from \"react\";\nimport type { RenderItemFn } from \"@/components/List/model/item/types\";\nimport type List from \"@/components/List/model/List\";\n\nexport interface ItemViewShape<T> {\n textValue?: (data: T) => string;\n href?: (data: T) => string;\n target?: HTMLAttributeAnchorTarget;\n defaultExpanded?: (data: T) => boolean;\n renderFn?: RenderItemFn<T>;\n /** @deprecated Use loadingView instead */\n fallback?: ReactElement;\n loadingView?: ReactElement;\n showList?: boolean;\n showTiles?: boolean;\n tileMaxWidth?: number;\n /**\n *
|
|
1
|
+
{"version":3,"file":"ItemView.mjs","names":[],"sources":["../../../../../../../../../src/components/List/model/item/ItemView.ts"],"sourcesContent":["import type {\n DependencyList,\n HTMLAttributeAnchorTarget,\n ReactElement,\n ReactNode,\n} from \"react\";\nimport { createElement } from \"react\";\nimport type { RenderItemFn } from \"@/components/List/model/item/types\";\nimport type List from \"@/components/List/model/List\";\nimport { isShallowEqual } from \"remeda\";\n\nexport interface ItemViewShape<T> {\n /**\n * Runs on every render of the list to tell whether the item changed, so it\n * should be cheap and pure.\n */\n textValue?: (data: T) => string;\n /**\n * Runs on every render of the list to tell whether the item changed, so it\n * should be cheap and pure.\n */\n href?: (data: T) => string;\n target?: HTMLAttributeAnchorTarget;\n defaultExpanded?: (data: T) => boolean;\n renderFn?: RenderItemFn<T>;\n /** @deprecated Use loadingView instead */\n fallback?: ReactElement;\n loadingView?: ReactElement;\n showList?: boolean;\n showTiles?: boolean;\n tileMaxWidth?: number;\n /**\n * Everything the render function reads besides the item's data.\n *\n * With `renderDependencies`, an item re-renders only when its data or one of\n * these values changes. The render function's identity no longer counts, so a\n * function written inline in JSX keeps the item from re-rendering on every\n * render of its parent. List every value it reads from outside the item,\n * including state read through the `list` argument — one left out keeps the\n * item on the value it last rendered.\n *\n * Without it, an item re-renders whenever its render function changes\n * identity, which an inline function does on every render of its parent.\n */\n renderDependencies?: DependencyList;\n /**\n * @deprecated Use `renderDependencies` instead. `dependencies` only adds to\n * the render function's identity, so an inline render function still\n * re-renders the item on every render of its parent.\n */\n dependencies?: DependencyList;\n}\n\nexport class ItemView<T> {\n public readonly list: List<T>;\n public readonly textValue?: (data: T) => string;\n public readonly href?: (data: T) => string;\n public readonly target?: HTMLAttributeAnchorTarget;\n public readonly defaultExpanded?: (data: T) => boolean;\n public readonly loadingView?: ReactElement;\n public readonly showTiles?: boolean;\n public readonly showList?: boolean;\n public readonly tileMaxWidth: number;\n public readonly renderDependencies?: DependencyList;\n public readonly dependencies?: DependencyList;\n private readonly renderFn?: RenderItemFn<T>;\n private lastComparison?: { other: ItemView<T>; result: boolean };\n\n public constructor(list: List<T>, shape: ItemViewShape<T> = {}) {\n const {\n fallback,\n loadingView = fallback,\n textValue,\n href,\n target,\n defaultExpanded,\n renderFn,\n showTiles,\n showList = true,\n tileMaxWidth = 230,\n renderDependencies,\n dependencies,\n } = shape;\n this.list = list;\n this.textValue = textValue;\n this.renderFn = renderFn;\n this.href = href;\n this.target = target;\n this.defaultExpanded = defaultExpanded;\n this.loadingView = loadingView;\n this.showTiles = showTiles;\n this.showList = showList;\n this.tileMaxWidth = tileMaxWidth;\n this.renderDependencies = renderDependencies;\n this.dependencies = dependencies;\n }\n\n private static fallbackRenderItemFn: RenderItemFn<never> = (item) =>\n createElement(\"pre\", undefined, JSON.stringify(item));\n\n /**\n * Whether `other` would render the item holding `data` identically. The\n * render function counts by its `renderDependencies` where given, otherwise\n * by its identity and the deprecated `dependencies`. `textValue` and `href`\n * count by what they return for `data`, so inline functions do not re-render\n * the item. `defaultExpanded` is read on mount only, so it does not count at\n * all.\n */\n public rendersSameFor(other: ItemView<T> | undefined, data: T): boolean {\n return (\n !!other &&\n this.rendersSameContentAs(other) &&\n this.textValue?.(data) === other.textValue?.(data) &&\n this.href?.(data) === other.href?.(data) &&\n this.target === other.target\n );\n }\n\n // Every item of a render shares one item view, so the result is cached for\n // the last `other`.\n private rendersSameContentAs(other: ItemView<T>): boolean {\n if (this.lastComparison?.other !== other) {\n this.lastComparison = {\n other,\n result:\n this.renderDependencies || other.renderDependencies\n ? isShallowEqual(this.renderDependencies, other.renderDependencies)\n : this.renderFn === other.renderFn &&\n isShallowEqual(this.dependencies, other.dependencies),\n };\n }\n return this.lastComparison.result;\n }\n\n public render(data: T): ReactNode {\n const renderFn = (this.renderFn ??\n ItemView.fallbackRenderItemFn) as RenderItemFn<T>;\n return renderFn(data as never, this.list);\n }\n}\n"],"mappings":";;;;;AAqDA,IAAa,WAAb,MAAa,SAAY;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAmB,MAAe,QAA0B,CAAC,GAAG;EAC9D,MAAM,EACJ,UACA,cAAc,UACd,WACA,MACA,QACA,iBACA,UACA,WACA,WAAW,MACX,eAAe,KACf,oBACA,iBACE;EACJ,KAAK,OAAO;EACZ,KAAK,YAAY;EACjB,KAAK,WAAW;EAChB,KAAK,OAAO;EACZ,KAAK,SAAS;EACd,KAAK,kBAAkB;EACvB,KAAK,cAAc;EACnB,KAAK,YAAY;EACjB,KAAK,WAAW;EAChB,KAAK,eAAe;EACpB,KAAK,qBAAqB;EAC1B,KAAK,eAAe;CACtB;CAEA,OAAe,wBAA6C,SAC1D,cAAc,OAAO,KAAA,GAAW,KAAK,UAAU,IAAI,CAAC;;;;;;;;;CAUtD,eAAsB,OAAgC,MAAkB;EACtE,OACE,CAAC,CAAC,SACF,KAAK,qBAAqB,KAAK,KAC/B,KAAK,YAAY,IAAI,MAAM,MAAM,YAAY,IAAI,KACjD,KAAK,OAAO,IAAI,MAAM,MAAM,OAAO,IAAI,KACvC,KAAK,WAAW,MAAM;CAE1B;CAIA,qBAA6B,OAA6B;EACxD,IAAI,KAAK,gBAAgB,UAAU,OACjC,KAAK,iBAAiB;GACpB;GACA,QACE,KAAK,sBAAsB,MAAM,qBAC7B,eAAe,KAAK,oBAAoB,MAAM,kBAAkB,IAChE,KAAK,aAAa,MAAM,YACxB,eAAe,KAAK,cAAc,MAAM,YAAY;EAC5D;EAEF,OAAO,KAAK,eAAe;CAC7B;CAEA,OAAc,MAAoB;EAGhC,QAFkB,KAAK,YACrB,SAAS,qBAAA,CACK,MAAe,KAAK,IAAI;CAC1C;AACF"}
|
|
@@ -7,7 +7,7 @@ var TableCell = class {
|
|
|
7
7
|
componentProps;
|
|
8
8
|
loadingView;
|
|
9
9
|
constructor(row, shape = {}) {
|
|
10
|
-
const { renderFn, loadingView, ...rest } = shape;
|
|
10
|
+
const { renderFn, loadingView, children: ignoredChildren, ...rest } = shape;
|
|
11
11
|
this.row = row;
|
|
12
12
|
this.renderFn = renderFn;
|
|
13
13
|
this.componentProps = rest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableCell.mjs","names":[],"sources":["../../../../../../../../../src/components/List/model/table/TableCell.ts"],"sourcesContent":["import type {\n TableCellShape,\n TableCellSupportedComponentProps,\n} from \"@/components/List/model/table/types\";\nimport type { TableRow } from \"@/components/List/model/table/TableRow\";\nimport type { RenderItemFn } from \"@/components/List\";\nimport type { ReactElement } from \"react\";\n\nexport class TableCell<T> {\n public readonly row: TableRow<T>;\n public readonly renderFn?: RenderItemFn<T>;\n public readonly componentProps: TableCellSupportedComponentProps;\n loadingView?: ReactElement;\n\n public constructor(row: TableRow<T>, shape: TableCellShape<T> = {}) {\n const {
|
|
1
|
+
{"version":3,"file":"TableCell.mjs","names":[],"sources":["../../../../../../../../../src/components/List/model/table/TableCell.ts"],"sourcesContent":["import type {\n TableCellShape,\n TableCellSupportedComponentProps,\n} from \"@/components/List/model/table/types\";\nimport type { TableRow } from \"@/components/List/model/table/TableRow\";\nimport type { RenderItemFn } from \"@/components/List\";\nimport type { ReactElement } from \"react\";\n\nexport class TableCell<T> {\n public readonly row: TableRow<T>;\n public readonly renderFn?: RenderItemFn<T>;\n public readonly componentProps: TableCellSupportedComponentProps;\n loadingView?: ReactElement;\n\n public constructor(row: TableRow<T>, shape: TableCellShape<T> = {}) {\n // `children` is the render function, which arrives as `renderFn`.\n const {\n renderFn,\n loadingView,\n children: ignoredChildren,\n ...rest\n } = shape as TableCellShape<T> & { children?: unknown };\n this.row = row;\n this.renderFn = renderFn;\n this.componentProps = rest;\n this.loadingView = loadingView;\n }\n}\n"],"mappings":";;;AAQA,IAAa,YAAb,MAA0B;CACxB;CACA;CACA;CACA;CAEA,YAAmB,KAAkB,QAA2B,CAAC,GAAG;EAElE,MAAM,EACJ,UACA,aACA,UAAU,iBACV,GAAG,SACD;EACJ,KAAK,MAAM;EACX,KAAK,WAAW;EAChB,KAAK,iBAAiB;EACtB,KAAK,cAAc;CACrB;AACF"}
|
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
/* */
|
|
3
3
|
import { TableCell } from "./TableCell.mjs";
|
|
4
|
+
import { isShallowEqual } from "remeda";
|
|
4
5
|
//#region src/components/List/model/table/TableRow.ts
|
|
5
6
|
var TableRow = class {
|
|
6
7
|
tableBody;
|
|
7
8
|
cells;
|
|
8
9
|
componentProps;
|
|
10
|
+
renderDependencies;
|
|
11
|
+
lastComparison;
|
|
9
12
|
constructor(tableBody, shape = {}) {
|
|
10
|
-
const { cells = [], ...rest } = shape;
|
|
13
|
+
const { cells = [], renderDependencies, children: ignoredChildren, ...rest } = shape;
|
|
11
14
|
this.tableBody = tableBody;
|
|
12
15
|
this.cells = cells.map((cellShape) => new TableCell(this, cellShape));
|
|
13
16
|
this.componentProps = rest;
|
|
17
|
+
this.renderDependencies = renderDependencies;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether `other` would render a row identically. Only rows that declare
|
|
21
|
+
* `renderDependencies` can tell, since the cells' render functions count by
|
|
22
|
+
* those instead of their identity. Rows without them always re-render. Row
|
|
23
|
+
* and cell props count by identity, one by one.
|
|
24
|
+
*
|
|
25
|
+
* Every row of a render shares one model, so the result is cached for the
|
|
26
|
+
* last `other`.
|
|
27
|
+
*/
|
|
28
|
+
rendersSameAs(other) {
|
|
29
|
+
if (!other) return false;
|
|
30
|
+
if (this.lastComparison?.other !== other) this.lastComparison = {
|
|
31
|
+
other,
|
|
32
|
+
result: this.compareWith(other)
|
|
33
|
+
};
|
|
34
|
+
return this.lastComparison.result;
|
|
35
|
+
}
|
|
36
|
+
compareWith(other) {
|
|
37
|
+
return !!this.renderDependencies && isShallowEqual(this.renderDependencies, other.renderDependencies) && isShallowEqual(this.componentProps, other.componentProps) && this.cells.length === other.cells.length && this.cells.every((cell, index) => {
|
|
38
|
+
const otherCell = other.cells[index];
|
|
39
|
+
return !!otherCell && isShallowEqual(cell.componentProps, otherCell.componentProps);
|
|
40
|
+
});
|
|
14
41
|
}
|
|
15
42
|
};
|
|
16
43
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableRow.mjs","names":[],"sources":["../../../../../../../../../src/components/List/model/table/TableRow.ts"],"sourcesContent":["import type {\n TableRowShape,\n TableRowSupportedComponentProps,\n} from \"@/components/List/model/table/types\";\nimport { TableCell } from \"@/components/List/model/table/TableCell\";\nimport type { TableBody } from \"@/components/List/model/table/TableBody\";\n\nexport class TableRow<T> {\n public readonly tableBody: TableBody<T>;\n public readonly cells: TableCell<T>[];\n public readonly componentProps: TableRowSupportedComponentProps;\n\n public constructor(tableBody: TableBody<T>, shape: TableRowShape<T> = {}) {\n const {
|
|
1
|
+
{"version":3,"file":"TableRow.mjs","names":[],"sources":["../../../../../../../../../src/components/List/model/table/TableRow.ts"],"sourcesContent":["import type {\n TableRowShape,\n TableRowSupportedComponentProps,\n} from \"@/components/List/model/table/types\";\nimport { TableCell } from \"@/components/List/model/table/TableCell\";\nimport type { TableBody } from \"@/components/List/model/table/TableBody\";\nimport type { DependencyList } from \"react\";\nimport { isShallowEqual } from \"remeda\";\n\nexport class TableRow<T> {\n public readonly tableBody: TableBody<T>;\n public readonly cells: TableCell<T>[];\n public readonly componentProps: TableRowSupportedComponentProps;\n public readonly renderDependencies?: DependencyList;\n private lastComparison?: { other: TableRow<T>; result: boolean };\n\n public constructor(tableBody: TableBody<T>, shape: TableRowShape<T> = {}) {\n // `children` holds the cell elements, which arrive as `cells`.\n const {\n cells = [],\n renderDependencies,\n children: ignoredChildren,\n ...rest\n } = shape;\n this.tableBody = tableBody;\n this.cells = cells.map((cellShape) => new TableCell(this, cellShape));\n this.componentProps = rest;\n this.renderDependencies = renderDependencies;\n }\n\n /**\n * Whether `other` would render a row identically. Only rows that declare\n * `renderDependencies` can tell, since the cells' render functions count by\n * those instead of their identity. Rows without them always re-render. Row\n * and cell props count by identity, one by one.\n *\n * Every row of a render shares one model, so the result is cached for the\n * last `other`.\n */\n public rendersSameAs(other?: TableRow<T>): boolean {\n if (!other) {\n return false;\n }\n if (this.lastComparison?.other !== other) {\n this.lastComparison = { other, result: this.compareWith(other) };\n }\n return this.lastComparison.result;\n }\n\n private compareWith(other: TableRow<T>): boolean {\n return (\n !!this.renderDependencies &&\n isShallowEqual(this.renderDependencies, other.renderDependencies) &&\n isShallowEqual(this.componentProps, other.componentProps) &&\n this.cells.length === other.cells.length &&\n this.cells.every((cell, index) => {\n const otherCell = other.cells[index];\n return (\n !!otherCell &&\n isShallowEqual(cell.componentProps, otherCell.componentProps)\n );\n })\n );\n }\n}\n"],"mappings":";;;;;AASA,IAAa,WAAb,MAAyB;CACvB;CACA;CACA;CACA;CACA;CAEA,YAAmB,WAAyB,QAA0B,CAAC,GAAG;EAExE,MAAM,EACJ,QAAQ,CAAC,GACT,oBACA,UAAU,iBACV,GAAG,SACD;EACJ,KAAK,YAAY;EACjB,KAAK,QAAQ,MAAM,KAAK,cAAc,IAAI,UAAU,MAAM,SAAS,CAAC;EACpE,KAAK,iBAAiB;EACtB,KAAK,qBAAqB;CAC5B;;;;;;;;;;CAWA,cAAqB,OAA8B;EACjD,IAAI,CAAC,OACH,OAAO;EAET,IAAI,KAAK,gBAAgB,UAAU,OACjC,KAAK,iBAAiB;GAAE;GAAO,QAAQ,KAAK,YAAY,KAAK;EAAE;EAEjE,OAAO,KAAK,eAAe;CAC7B;CAEA,YAAoB,OAA6B;EAC/C,OACE,CAAC,CAAC,KAAK,sBACP,eAAe,KAAK,oBAAoB,MAAM,kBAAkB,KAChE,eAAe,KAAK,gBAAgB,MAAM,cAAc,KACxD,KAAK,MAAM,WAAW,MAAM,MAAM,UAClC,KAAK,MAAM,OAAO,MAAM,UAAU;GAChC,MAAM,YAAY,MAAM,MAAM;GAC9B,OACE,CAAC,CAAC,aACF,eAAe,KAAK,gBAAgB,UAAU,cAAc;EAEhE,CAAC;CAEL;AACF"}
|
|
@@ -7,6 +7,8 @@ interface Props extends PropsWithChildren {
|
|
|
7
7
|
triggerRef?: Ref<HTMLDivElement>;
|
|
8
8
|
list: ListModel<never>;
|
|
9
9
|
isTile: boolean;
|
|
10
|
+
/** Stable invoker of the list's latest `onAction` */
|
|
11
|
+
onAction?: (data: never) => void;
|
|
10
12
|
}
|
|
11
13
|
export declare const Item: import('react').MemoExoticComponent<(props: Props) => import('react').JSX.Element | null>;
|
|
12
14
|
interface ItemContainerProps extends PropsWithChildren {
|
package/dist/types/components/List/components/Items/components/Item/hooks/useGridItemProps.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { PropsWithChildren } from 'react';
|
|
|
2
2
|
import { default as List } from '../../../../../model/List';
|
|
3
3
|
interface P extends PropsWithChildren {
|
|
4
4
|
data: never;
|
|
5
|
+
onAction?: (data: never) => void;
|
|
5
6
|
}
|
|
6
7
|
export declare const useGridItemProps: (props: P, list: List<never>) => {
|
|
7
8
|
gridItemProps: {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { Key } from 'react-aria-components';
|
|
3
|
+
import { default as ListModel } from '../../../model/List';
|
|
4
|
+
interface Props {
|
|
5
|
+
id: Key;
|
|
6
|
+
data: never;
|
|
7
|
+
list: ListModel<never>;
|
|
8
|
+
/** Stable invoker of the list's latest `onAction` */
|
|
9
|
+
onAction?: (data: never) => void;
|
|
10
|
+
triggerRef?: Ref<HTMLTableRowElement>;
|
|
11
|
+
}
|
|
12
|
+
export declare const Row: import('react').MemoExoticComponent<(props: Props) => import('react').JSX.Element | null>;
|
|
13
|
+
export default Row;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { default as List } from '../model/List';
|
|
2
|
+
/**
|
|
3
|
+
* A stable invoker of the list's latest `onAction`, or `undefined` without one.
|
|
4
|
+
* An event handler only ever needs to be the latest one, so items and rows do
|
|
5
|
+
* not re-render for an inline `onAction`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useLatestOnAction: (list: List<never>) => ((data: never) => void | undefined) | undefined;
|