@draftbit/core 48.0.3-924ae9.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.
Files changed (40) hide show
  1. package/lib/src/components/SwipeableItem/SwipeableItem.js +4 -7
  2. package/lib/src/components/SwipeableItem/SwipeableItem.js.map +1 -1
  3. package/lib/src/components/TabView/TabView.js +2 -6
  4. package/lib/src/components/TabView/TabView.js.map +1 -1
  5. package/lib/src/components/TabView/TabViewItem.d.ts +1 -1
  6. package/lib/src/components/TabView/TabViewItem.js.map +1 -1
  7. package/lib/src/index.d.ts +0 -1
  8. package/lib/src/index.js +0 -1
  9. package/lib/src/index.js.map +1 -1
  10. package/lib/tsconfig.tsbuildinfo +1 -1
  11. package/package.json +3 -3
  12. package/src/components/SwipeableItem/SwipeableItem.js +4 -7
  13. package/src/components/SwipeableItem/SwipeableItem.js.map +1 -1
  14. package/src/components/SwipeableItem/SwipeableItem.tsx +6 -11
  15. package/src/components/TabView/TabView.js +2 -6
  16. package/src/components/TabView/TabView.js.map +1 -1
  17. package/src/components/TabView/TabView.tsx +2 -11
  18. package/src/components/TabView/TabViewItem.js.map +1 -1
  19. package/src/components/TabView/TabViewItem.tsx +1 -2
  20. package/src/index.js +0 -1
  21. package/src/index.js.map +1 -1
  22. package/src/index.tsx +0 -1
  23. package/lib/src/components/SectionList/SectionHeader.d.ts +0 -15
  24. package/lib/src/components/SectionList/SectionHeader.js +0 -14
  25. package/lib/src/components/SectionList/SectionHeader.js.map +0 -1
  26. package/lib/src/components/SectionList/SectionList.d.ts +0 -19
  27. package/lib/src/components/SectionList/SectionList.js +0 -95
  28. package/lib/src/components/SectionList/SectionList.js.map +0 -1
  29. package/lib/src/components/SectionList/index.d.ts +0 -2
  30. package/lib/src/components/SectionList/index.js +0 -3
  31. package/lib/src/components/SectionList/index.js.map +0 -1
  32. package/src/components/SectionList/SectionHeader.js +0 -14
  33. package/src/components/SectionList/SectionHeader.js.map +0 -1
  34. package/src/components/SectionList/SectionHeader.tsx +0 -36
  35. package/src/components/SectionList/SectionList.js +0 -95
  36. package/src/components/SectionList/SectionList.js.map +0 -1
  37. package/src/components/SectionList/SectionList.tsx +0 -171
  38. package/src/components/SectionList/index.js +0 -3
  39. package/src/components/SectionList/index.js.map +0 -1
  40. package/src/components/SectionList/index.tsx +0 -2
@@ -1,171 +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 DEFAULT_SECTION = "Uncategorized";
37
-
38
- const SectionList = <T extends { [key: string]: any }>({
39
- sectionKey,
40
- listComponent = "FlatList",
41
- data: dataProp,
42
- renderItem: renderItemProp,
43
- ...rest
44
- }: FlatListSectionListProps<T> | FlashListSectionListProps<T>) => {
45
- const data = React.useMemo(() => (dataProp || []) as T[], [dataProp]);
46
-
47
- const dataWithSections = React.useMemo(() => {
48
- const result: SectionListItem<T>[] = [];
49
- const sectionDataItems: { [key: string]: T[] } = {};
50
-
51
- for (const item of data) {
52
- const section = item[sectionKey]?.toString() || DEFAULT_SECTION;
53
- if (sectionDataItems[section]) {
54
- sectionDataItems[section].push(item);
55
- } else {
56
- sectionDataItems[section] = [item];
57
- }
58
- }
59
-
60
- for (const section in sectionDataItems) {
61
- result.push({ type: "SECTION_ITEM", title: section });
62
- const sectionItems: SectionListDataItem<T>[] = sectionDataItems[
63
- section
64
- ].map((item) => ({ type: "DATA_ITEM", data: item }));
65
- result.push(...sectionItems);
66
- }
67
-
68
- return result;
69
- }, [data, sectionKey]);
70
-
71
- const extractSectionHeader = (
72
- element: JSX.Element | null
73
- ): JSX.Element | null => {
74
- if (!element) {
75
- return null;
76
- }
77
-
78
- const props = element.props || {};
79
- const children = React.Children.toArray(props.children).map(
80
- (child) => child as React.ReactElement
81
- );
82
- if (element.type === SectionHeader) {
83
- return element;
84
- } else {
85
- for (const child of children) {
86
- if (child.type === SectionHeader) {
87
- return child;
88
- }
89
- }
90
- }
91
- return null;
92
- };
93
-
94
- const extractRemainingNonSectionHeader = (
95
- element: JSX.Element | null
96
- ): JSX.Element | null => {
97
- if (!element) {
98
- return null;
99
- }
100
-
101
- const props = element.props || {};
102
- const children = React.Children.toArray(props.children).map(
103
- (child) => child as React.ReactElement
104
- );
105
- if (element.type === SectionHeader) {
106
- return null;
107
- } else {
108
- const newChildren = [];
109
- for (const child of children) {
110
- if (child.type !== SectionHeader) {
111
- newChildren.push(child);
112
- }
113
- }
114
- return React.cloneElement(element, {
115
- ...props,
116
- children: newChildren,
117
- });
118
- }
119
- };
120
-
121
- const renderItem = ({
122
- item,
123
- index,
124
- }: {
125
- item: SectionListItem<T>;
126
- index: number;
127
- }) => {
128
- switch (item.type) {
129
- case "SECTION_ITEM": {
130
- const renderedItem = renderItemProp({
131
- index,
132
- section: item.title,
133
- });
134
- return (
135
- extractSectionHeader(renderedItem) || (
136
- <DefaultSectionHeader title={item.title} />
137
- )
138
- );
139
- }
140
- case "DATA_ITEM": {
141
- const renderedItem = renderItemProp({
142
- item: item.data,
143
- index,
144
- section: item.data[sectionKey] || DEFAULT_SECTION,
145
- });
146
- return extractRemainingNonSectionHeader(renderedItem);
147
- }
148
- }
149
- };
150
-
151
- switch (listComponent) {
152
- case "FlatList":
153
- return (
154
- <FlatList
155
- {...(rest as FlatListProps<SectionListItem<T>>)}
156
- data={dataWithSections}
157
- renderItem={renderItem}
158
- />
159
- );
160
- case "FlashList":
161
- return (
162
- <FlashList
163
- {...(rest as FlashListProps<SectionListItem<T>>)}
164
- data={dataWithSections}
165
- renderItem={renderItem}
166
- />
167
- );
168
- }
169
- };
170
-
171
- export default SectionList;
@@ -1,3 +0,0 @@
1
- export { default as SectionList } from "./SectionList";
2
- export { default as SectionHeader } from "./SectionHeader";
3
- //# sourceMappingURL=index.js.map
@@ -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"}
@@ -1,2 +0,0 @@
1
- export { default as SectionList } from "./SectionList";
2
- export { default as SectionHeader } from "./SectionHeader";