@draftbit/core 48.0.3-f27950.2 → 48.0.3-fd9d4e.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/components/SwipeableItem/SwipeableItem.js +4 -7
- package/lib/src/components/SwipeableItem/SwipeableItem.js.map +1 -1
- package/lib/src/components/TabView/TabView.js +2 -6
- package/lib/src/components/TabView/TabView.js.map +1 -1
- package/lib/src/components/TabView/TabViewItem.d.ts +1 -1
- package/lib/src/components/TabView/TabViewItem.js.map +1 -1
- package/lib/src/index.d.ts +0 -1
- package/lib/src/index.js +0 -1
- package/lib/src/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/SwipeableItem/SwipeableItem.js +4 -7
- package/src/components/SwipeableItem/SwipeableItem.js.map +1 -1
- package/src/components/SwipeableItem/SwipeableItem.tsx +6 -11
- package/src/components/TabView/TabView.js +2 -6
- package/src/components/TabView/TabView.js.map +1 -1
- package/src/components/TabView/TabView.tsx +2 -11
- package/src/components/TabView/TabViewItem.js.map +1 -1
- package/src/components/TabView/TabViewItem.tsx +1 -2
- package/src/index.js +0 -1
- package/src/index.js.map +1 -1
- package/src/index.tsx +0 -1
- package/lib/src/components/SectionList/SectionHeader.d.ts +0 -15
- package/lib/src/components/SectionList/SectionHeader.js +0 -14
- package/lib/src/components/SectionList/SectionHeader.js.map +0 -1
- package/lib/src/components/SectionList/SectionList.d.ts +0 -19
- package/lib/src/components/SectionList/SectionList.js +0 -88
- package/lib/src/components/SectionList/SectionList.js.map +0 -1
- package/lib/src/components/SectionList/index.d.ts +0 -2
- package/lib/src/components/SectionList/index.js +0 -3
- package/lib/src/components/SectionList/index.js.map +0 -1
- package/src/components/SectionList/SectionHeader.js +0 -14
- package/src/components/SectionList/SectionHeader.js.map +0 -1
- package/src/components/SectionList/SectionHeader.tsx +0 -36
- package/src/components/SectionList/SectionList.js +0 -88
- package/src/components/SectionList/SectionList.js.map +0 -1
- package/src/components/SectionList/SectionList.tsx +0 -159
- package/src/components/SectionList/index.js +0 -3
- package/src/components/SectionList/index.js.map +0 -1
- package/src/components/SectionList/index.tsx +0 -2
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { FlashListProps, FlashList } from "@shopify/flash-list";
|
|
3
|
-
import { FlatListProps, FlatList } from "react-native";
|
|
4
|
-
import SectionHeader, { DefaultSectionHeader } from "./SectionHeader";
|
|
5
|
-
|
|
6
|
-
type ListComponentType = "FlatList" | "FlashList";
|
|
7
|
-
|
|
8
|
-
interface AdditionalSectionListProps<T> {
|
|
9
|
-
sectionKey: string;
|
|
10
|
-
renderItem: (itemInfo: {
|
|
11
|
-
item?: T;
|
|
12
|
-
index: number;
|
|
13
|
-
section: string;
|
|
14
|
-
}) => JSX.Element;
|
|
15
|
-
listComponent?: ListComponentType;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type FlatListSectionListProps<T> = Omit<FlatListProps<T>, "renderItem"> &
|
|
19
|
-
AdditionalSectionListProps<T>;
|
|
20
|
-
|
|
21
|
-
type FlashListSectionListProps<T> = Omit<FlashListProps<T>, "renderItem"> &
|
|
22
|
-
AdditionalSectionListProps<T>;
|
|
23
|
-
|
|
24
|
-
interface SectionListDataItem<T> {
|
|
25
|
-
type: "DATA_ITEM";
|
|
26
|
-
data: T;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface SectionListSectionItem {
|
|
30
|
-
type: "SECTION_ITEM";
|
|
31
|
-
title: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type SectionListItem<T> = SectionListDataItem<T> | SectionListSectionItem;
|
|
35
|
-
|
|
36
|
-
const SectionList = <T extends { [key: string]: any }>({
|
|
37
|
-
sectionKey,
|
|
38
|
-
listComponent = "FlatList",
|
|
39
|
-
data: dataProp,
|
|
40
|
-
renderItem: renderItemProp,
|
|
41
|
-
...rest
|
|
42
|
-
}: FlatListSectionListProps<T> | FlashListSectionListProps<T>) => {
|
|
43
|
-
const data = React.useMemo(() => (dataProp || []) as T[], [dataProp]);
|
|
44
|
-
|
|
45
|
-
const dataWithSections = React.useMemo(() => {
|
|
46
|
-
const result: SectionListItem<T>[] = [];
|
|
47
|
-
const sectionDataItems: { [key: string]: T[] } = {};
|
|
48
|
-
|
|
49
|
-
for (const item of data) {
|
|
50
|
-
const section = item[sectionKey]?.toString() || "Uncategorized";
|
|
51
|
-
if (sectionDataItems[section]) {
|
|
52
|
-
sectionDataItems[section].push(item);
|
|
53
|
-
} else {
|
|
54
|
-
sectionDataItems[section] = [item];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
for (const section in sectionDataItems) {
|
|
59
|
-
result.push({ type: "SECTION_ITEM", title: section });
|
|
60
|
-
const sectionItems: SectionListDataItem<T>[] = sectionDataItems[
|
|
61
|
-
section
|
|
62
|
-
].map((item) => ({ type: "DATA_ITEM", data: item }));
|
|
63
|
-
result.push(...sectionItems);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return result;
|
|
67
|
-
}, [data, sectionKey]);
|
|
68
|
-
|
|
69
|
-
const extractSectionHeader = (element: JSX.Element): JSX.Element | null => {
|
|
70
|
-
const props = element?.props || {};
|
|
71
|
-
const children = React.Children.toArray(props.children).map(
|
|
72
|
-
(child) => child as React.ReactElement
|
|
73
|
-
);
|
|
74
|
-
if (element.type === SectionHeader) {
|
|
75
|
-
return element;
|
|
76
|
-
} else {
|
|
77
|
-
for (const child of children) {
|
|
78
|
-
if (child.type === SectionHeader) {
|
|
79
|
-
return child;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const extractRemainingNonSectionHeader = (
|
|
87
|
-
element: JSX.Element
|
|
88
|
-
): JSX.Element | null => {
|
|
89
|
-
const props = element?.props || {};
|
|
90
|
-
const children = React.Children.toArray(props.children).map(
|
|
91
|
-
(child) => child as React.ReactElement
|
|
92
|
-
);
|
|
93
|
-
if (element.type === SectionHeader) {
|
|
94
|
-
return null;
|
|
95
|
-
} else {
|
|
96
|
-
const newChildren = [];
|
|
97
|
-
for (const child of children) {
|
|
98
|
-
if (child.type !== SectionHeader) {
|
|
99
|
-
newChildren.push(child);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return React.cloneElement(element, {
|
|
103
|
-
...props,
|
|
104
|
-
children: newChildren,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const renderItem = ({
|
|
110
|
-
item,
|
|
111
|
-
index,
|
|
112
|
-
}: {
|
|
113
|
-
item: SectionListItem<T>;
|
|
114
|
-
index: number;
|
|
115
|
-
}) => {
|
|
116
|
-
switch (item.type) {
|
|
117
|
-
case "SECTION_ITEM": {
|
|
118
|
-
const renderedItem = renderItemProp({
|
|
119
|
-
index,
|
|
120
|
-
section: item.title,
|
|
121
|
-
});
|
|
122
|
-
return (
|
|
123
|
-
extractSectionHeader(renderedItem) || (
|
|
124
|
-
<DefaultSectionHeader title={item.title} />
|
|
125
|
-
)
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
case "DATA_ITEM": {
|
|
129
|
-
const renderedItem = renderItemProp({
|
|
130
|
-
item: item.data,
|
|
131
|
-
index,
|
|
132
|
-
section: item.data[sectionKey],
|
|
133
|
-
});
|
|
134
|
-
return extractRemainingNonSectionHeader(renderedItem);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
switch (listComponent) {
|
|
140
|
-
case "FlatList":
|
|
141
|
-
return (
|
|
142
|
-
<FlatList
|
|
143
|
-
{...(rest as FlatListProps<SectionListItem<T>>)}
|
|
144
|
-
data={dataWithSections}
|
|
145
|
-
renderItem={renderItem}
|
|
146
|
-
/>
|
|
147
|
-
);
|
|
148
|
-
case "FlashList":
|
|
149
|
-
return (
|
|
150
|
-
<FlashList
|
|
151
|
-
{...(rest as FlashListProps<SectionListItem<T>>)}
|
|
152
|
-
data={dataWithSections}
|
|
153
|
-
renderItem={renderItem}
|
|
154
|
-
/>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export default SectionList;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|