@elliemae/ds-shuttle-v2 3.53.0-beta.8 → 3.53.0-next.10

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.
@@ -1,149 +0,0 @@
1
- import * as React from "react";
2
- import { jsx } from "react/jsx-runtime";
3
- import React2, { useMemo, useState, useCallback } from "react";
4
- import { DSBreadcrumb } from "@elliemae/ds-breadcrumb";
5
- import { useDSTree } from "@elliemae/ds-tree-model";
6
- import { uid } from "uid";
7
- const genTreeOfData = ({ prefix, depth = 0, parent = null, childIndex = 0, finalDepth = 2 }) => {
8
- const node = {
9
- id: uid(),
10
- label: parent ? `${parent.label}.${childIndex}` : `${prefix} 0`,
11
- parent: parent ? parent.id : null
12
- };
13
- if (depth <= finalDepth) {
14
- node.subitems = Array.from(
15
- { length: 2 },
16
- (_, i) => genTreeOfData({ prefix, depth: depth + 1, parent: node, childIndex: i, finalDepth })
17
- );
18
- }
19
- return node;
20
- };
21
- const options = {
22
- getUniqueId: (item) => item.id
23
- };
24
- const startingSourceData = genTreeOfData({ prefix: "Source" });
25
- const startingDestinationData = genTreeOfData({ prefix: "Destination" });
26
- const BreadCrumb = (props) => {
27
- const { breadCrumbPath, setCurrentNode, ...rest } = props;
28
- return /* @__PURE__ */ jsx(DSBreadcrumb, { isTitle: true, ...rest, children: breadCrumbPath.map((node) => /* @__PURE__ */ jsx(DSBreadcrumb.Item, { label: node.plainItem.label, onClick: () => setCurrentNode(node) }, `${node.dsId}`)) });
29
- };
30
- const BreadCrumbHoc = ({ path, setCurrentNode }) => {
31
- const WrappedBreadCrumb = (props) => /* @__PURE__ */ jsx(BreadCrumb, { ...props, breadCrumbPath: path, setCurrentNode });
32
- return WrappedBreadCrumb;
33
- };
34
- const useListData = (startingData) => {
35
- const { hash, getRoot, getNode, getPath, addNode, replaceNode, removeNode } = useDSTree(startingData, options);
36
- const [currentNode, setCurrentNode] = useState(getRoot());
37
- const [selection, setSelection] = useState({});
38
- const [isLoadingMore, setIsLoadingMore] = useState(false);
39
- const breadcrumbPath = useMemo(() => getPath(currentNode.dsId), [currentNode, getPath]);
40
- const displayedData = useMemo(
41
- () => currentNode.children.map((node) => node.getJson()),
42
- // eslint-disable-next-line react-hooks/exhaustive-deps
43
- [currentNode, hash]
44
- );
45
- const onDrilldown = useCallback((item) => setCurrentNode(getNode(item.id)), [getNode]);
46
- const onLoadMore = useCallback(() => {
47
- setIsLoadingMore(true);
48
- setTimeout(() => {
49
- const newChildren = Array.from(
50
- { length: 1 },
51
- (_, i) => genTreeOfData({ parent: currentNode.plainItem, childIndex: currentNode.children.length + i })
52
- );
53
- newChildren.forEach((child) => addNode(child, { parent: currentNode }));
54
- setIsLoadingMore(false);
55
- }, 1e3);
56
- }, [addNode, currentNode]);
57
- return {
58
- getNode,
59
- addNode,
60
- replaceNode,
61
- removeNode,
62
- currentNode,
63
- setCurrentNode,
64
- selection,
65
- setSelection,
66
- isLoadingMore,
67
- onLoadMore,
68
- breadcrumbPath,
69
- displayedData,
70
- onDrilldown
71
- };
72
- };
73
- const useShuttle = () => {
74
- const {
75
- currentNode: currentSourceNode,
76
- setCurrentNode: setCurrentSourceNode,
77
- selection: sourceSelection,
78
- setSelection: setSourceSelection,
79
- breadcrumbPath: sourceBreadCrumbPath,
80
- displayedData: sourceDisplayedData,
81
- onDrilldown: onSourceDrilldown,
82
- getNode: getSourceNode,
83
- addNode: addSourceNode,
84
- removeNode: removeSourceNode,
85
- isLoadingMore: isSourceLoadingMore,
86
- onLoadMore: onLoadMoreSource
87
- } = useListData(startingSourceData, "S");
88
- const {
89
- currentNode: currentDestinationNode,
90
- setCurrentNode: setCurrentDestinationNode,
91
- selection: destinationSelection,
92
- setSelection: setDestinationSelection,
93
- breadcrumbPath: destinationBreadCrumbPath,
94
- displayedData: destinationDisplayedData,
95
- onDrilldown: onDestinationDrilldown,
96
- getNode: getDestinationNode,
97
- addNode: addDestinationNode,
98
- removeNode: removeDestinationNode,
99
- isLoadingMore: isDestinationLoadingMore,
100
- onLoadMore: onLoadMoreDestination
101
- } = useListData(startingDestinationData, "D");
102
- const onSourceAdd = useCallback(
103
- (items) => items.forEach((item) => addSourceNode(item, { parent: getSourceNode(item.parent) ?? currentSourceNode })),
104
- [addSourceNode, currentSourceNode, getSourceNode]
105
- );
106
- const onSourceRemove = useCallback(
107
- (items) => items.forEach((item) => removeSourceNode(item.id, item)),
108
- [removeSourceNode]
109
- );
110
- const onDestinationAdd = useCallback(
111
- (items) => items.forEach(
112
- (item) => addDestinationNode(item, { parent: getDestinationNode(item.parent) ?? currentDestinationNode })
113
- ),
114
- [addDestinationNode, currentDestinationNode, getDestinationNode]
115
- );
116
- const onDestinationRemove = useCallback(
117
- (items) => items.forEach((item) => removeDestinationNode(item.id)),
118
- [removeDestinationNode]
119
- );
120
- return {
121
- setCurrentSourceNode,
122
- setCurrentDestinationNode,
123
- sourceDisplayedData,
124
- destinationDisplayedData,
125
- sourceSelection,
126
- destinationSelection,
127
- setSourceSelection,
128
- setDestinationSelection,
129
- onSourceDrilldown,
130
- onDestinationDrilldown,
131
- onSourceAdd,
132
- onSourceRemove,
133
- onDestinationAdd,
134
- onDestinationRemove,
135
- sourceBreadCrumbPath,
136
- destinationBreadCrumbPath,
137
- isSourceLoadingMore,
138
- onLoadMoreSource,
139
- isDestinationLoadingMore,
140
- onLoadMoreDestination,
141
- currentSourceNode,
142
- currentDestinationNode
143
- };
144
- };
145
- export {
146
- BreadCrumbHoc,
147
- useShuttle
148
- };
149
- //# sourceMappingURL=loadMore.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/tests/configs/loadMore.js"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\nimport React, { useMemo, useState, useCallback } from 'react';\nimport { DSBreadcrumb } from '@elliemae/ds-breadcrumb';\nimport { useDSTree } from '@elliemae/ds-tree-model';\nimport { uid } from 'uid';\n\nconst genTreeOfData = ({ prefix, depth = 0, parent = null, childIndex = 0, finalDepth = 2 }) => {\n const node = {\n id: uid(),\n label: parent ? `${parent.label}.${childIndex}` : `${prefix} 0`,\n parent: parent ? parent.id : null,\n };\n\n if (depth <= finalDepth) {\n node.subitems = Array.from({ length: 2 }, (_, i) =>\n genTreeOfData({ prefix, depth: depth + 1, parent: node, childIndex: i, finalDepth }),\n );\n }\n return node;\n};\n\nconst options = {\n getUniqueId: (item) => item.id,\n};\n\nconst startingSourceData = genTreeOfData({ prefix: 'Source' });\nconst startingDestinationData = genTreeOfData({ prefix: 'Destination' });\n\nconst BreadCrumb = (props) => {\n const { breadCrumbPath, setCurrentNode, ...rest } = props;\n\n return (\n <DSBreadcrumb isTitle {...rest}>\n {breadCrumbPath.map((node) => (\n <DSBreadcrumb.Item key={`${node.dsId}`} label={node.plainItem.label} onClick={() => setCurrentNode(node)} />\n ))}\n </DSBreadcrumb>\n );\n};\n\nexport const BreadCrumbHoc = ({ path, setCurrentNode }) => {\n const WrappedBreadCrumb = (props) => <BreadCrumb {...props} breadCrumbPath={path} setCurrentNode={setCurrentNode} />;\n return WrappedBreadCrumb;\n};\n\nconst useListData = (startingData) => {\n const { hash, getRoot, getNode, getPath, addNode, replaceNode, removeNode } = useDSTree(startingData, options);\n const [currentNode, setCurrentNode] = useState(getRoot());\n const [selection, setSelection] = useState({});\n const [isLoadingMore, setIsLoadingMore] = useState(false);\n\n const breadcrumbPath = useMemo(() => getPath(currentNode.dsId), [currentNode, getPath]);\n\n const displayedData = useMemo(\n () => currentNode.children.map((node) => node.getJson()),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [currentNode, hash],\n );\n\n const onDrilldown = useCallback((item) => setCurrentNode(getNode(item.id)), [getNode]);\n\n const onLoadMore = useCallback(() => {\n setIsLoadingMore(true);\n setTimeout(() => {\n const newChildren = Array.from({ length: 1 }, (_, i) =>\n genTreeOfData({ parent: currentNode.plainItem, childIndex: currentNode.children.length + i }),\n );\n newChildren.forEach((child) => addNode(child, { parent: currentNode }));\n setIsLoadingMore(false);\n }, 1000);\n }, [addNode, currentNode]);\n\n return {\n getNode,\n addNode,\n replaceNode,\n removeNode,\n currentNode,\n setCurrentNode,\n selection,\n setSelection,\n isLoadingMore,\n onLoadMore,\n breadcrumbPath,\n displayedData,\n onDrilldown,\n };\n};\n\nexport const useShuttle = () => {\n const {\n currentNode: currentSourceNode,\n setCurrentNode: setCurrentSourceNode,\n selection: sourceSelection,\n setSelection: setSourceSelection,\n breadcrumbPath: sourceBreadCrumbPath,\n displayedData: sourceDisplayedData,\n onDrilldown: onSourceDrilldown,\n getNode: getSourceNode,\n addNode: addSourceNode,\n removeNode: removeSourceNode,\n isLoadingMore: isSourceLoadingMore,\n onLoadMore: onLoadMoreSource,\n } = useListData(startingSourceData, 'S');\n\n const {\n currentNode: currentDestinationNode,\n setCurrentNode: setCurrentDestinationNode,\n selection: destinationSelection,\n setSelection: setDestinationSelection,\n breadcrumbPath: destinationBreadCrumbPath,\n displayedData: destinationDisplayedData,\n onDrilldown: onDestinationDrilldown,\n getNode: getDestinationNode,\n addNode: addDestinationNode,\n removeNode: removeDestinationNode,\n isLoadingMore: isDestinationLoadingMore,\n onLoadMore: onLoadMoreDestination,\n } = useListData(startingDestinationData, 'D');\n\n const onSourceAdd = useCallback(\n (items) =>\n items.forEach((item) => addSourceNode(item, { parent: getSourceNode(item.parent) ?? currentSourceNode })),\n [addSourceNode, currentSourceNode, getSourceNode],\n );\n\n const onSourceRemove = useCallback(\n (items) => items.forEach((item) => removeSourceNode(item.id, item)),\n [removeSourceNode],\n );\n\n const onDestinationAdd = useCallback(\n (items) =>\n items.forEach((item) =>\n addDestinationNode(item, { parent: getDestinationNode(item.parent) ?? currentDestinationNode }),\n ),\n [addDestinationNode, currentDestinationNode, getDestinationNode],\n );\n\n const onDestinationRemove = useCallback(\n (items) => items.forEach((item) => removeDestinationNode(item.id)),\n [removeDestinationNode],\n );\n\n return {\n setCurrentSourceNode,\n setCurrentDestinationNode,\n sourceDisplayedData,\n destinationDisplayedData,\n sourceSelection,\n destinationSelection,\n setSourceSelection,\n setDestinationSelection,\n onSourceDrilldown,\n onDestinationDrilldown,\n onSourceAdd,\n onSourceRemove,\n onDestinationAdd,\n onDestinationRemove,\n sourceBreadCrumbPath,\n destinationBreadCrumbPath,\n isSourceLoadingMore,\n onLoadMoreSource,\n isDestinationLoadingMore,\n onLoadMoreDestination,\n\n currentSourceNode,\n currentDestinationNode,\n };\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACkCf;AAjCR,OAAOA,UAAS,SAAS,UAAU,mBAAmB;AACtD,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAC1B,SAAS,WAAW;AAEpB,MAAM,gBAAgB,CAAC,EAAE,QAAQ,QAAQ,GAAG,SAAS,MAAM,aAAa,GAAG,aAAa,EAAE,MAAM;AAC9F,QAAM,OAAO;AAAA,IACX,IAAI,IAAI;AAAA,IACR,OAAO,SAAS,GAAG,OAAO,KAAK,IAAI,UAAU,KAAK,GAAG,MAAM;AAAA,IAC3D,QAAQ,SAAS,OAAO,KAAK;AAAA,EAC/B;AAEA,MAAI,SAAS,YAAY;AACvB,SAAK,WAAW,MAAM;AAAA,MAAK,EAAE,QAAQ,EAAE;AAAA,MAAG,CAAC,GAAG,MAC5C,cAAc,EAAE,QAAQ,OAAO,QAAQ,GAAG,QAAQ,MAAM,YAAY,GAAG,WAAW,CAAC;AAAA,IACrF;AAAA,EACF;AACA,SAAO;AACT;AAEA,MAAM,UAAU;AAAA,EACd,aAAa,CAAC,SAAS,KAAK;AAC9B;AAEA,MAAM,qBAAqB,cAAc,EAAE,QAAQ,SAAS,CAAC;AAC7D,MAAM,0BAA0B,cAAc,EAAE,QAAQ,cAAc,CAAC;AAEvE,MAAM,aAAa,CAAC,UAAU;AAC5B,QAAM,EAAE,gBAAgB,gBAAgB,GAAG,KAAK,IAAI;AAEpD,SACE,oBAAC,gBAAa,SAAO,MAAE,GAAG,MACvB,yBAA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