@onekeyfe/react-native-native-list 3.0.105
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/README.md +342 -0
- package/android/CMakeLists.txt +20 -0
- package/android/build.gradle +105 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +125 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +165 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +147 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListPackage.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRowView.kt +2939 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1794 -0
- package/common/fonts/Roobert-Bold.ttf +0 -0
- package/common/fonts/Roobert-Medium.ttf +0 -0
- package/common/fonts/Roobert-Regular.ttf +0 -0
- package/common/fonts/Roobert-SemiBold.ttf +0 -0
- package/docs/DESIGN.md +129 -0
- package/ios/HybridNativeList.swift +131 -0
- package/ios/NativeListCell.swift +2858 -0
- package/ios/NativeListDesignAssets.swift +110 -0
- package/ios/NativeListModels.swift +215 -0
- package/ios/RNCNativeListView.swift +1737 -0
- package/ios/Resources/NativeListIcons.xcassets/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/icon.svg +1 -0
- package/lib/module/NativeList.js +183 -0
- package/lib/module/NativeList.nitro.js +4 -0
- package/lib/module/NativeList.types.js +4 -0
- package/lib/module/NativeList.web.js +167 -0
- package/lib/module/index.js +6 -0
- package/lib/module/models.js +2 -0
- package/lib/module/package.json +1 -0
- package/lib/module/scrolling.js +121 -0
- package/lib/module/selection.js +85 -0
- package/lib/module/validation.js +562 -0
- package/lib/module/web/NativeListWebEngine.js +2238 -0
- package/lib/nitrogen/generated/.gitattributes +1 -0
- package/lib/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +201 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +84 -0
- package/lib/nitrogen/generated/android/c++/JNativeListScrollAlignment.hpp +64 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +104 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.hpp +54 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_std__string.kt +78 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +177 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollAlignment.kt +25 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/nativelistOnLoad.kt +35 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +96 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListStateUpdater.kt +23 -0
- package/lib/nitrogen/generated/android/nativelist+autolinking.cmake +83 -0
- package/lib/nitrogen/generated/android/nativelist+autolinking.gradle +27 -0
- package/lib/nitrogen/generated/android/nativelistOnLoad.cpp +58 -0
- package/lib/nitrogen/generated/android/nativelistOnLoad.hpp +34 -0
- package/lib/nitrogen/generated/ios/NativeListModule+autolinking.rb +62 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +41 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +91 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +49 -0
- package/lib/nitrogen/generated/ios/NativeListModuleAutolinking.mm +33 -0
- package/lib/nitrogen/generated/ios/NativeListModuleAutolinking.swift +26 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.cpp +11 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +180 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +180 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +69 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +447 -0
- package/lib/nitrogen/generated/ios/swift/NativeListScrollAlignment.swift +48 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +43 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +87 -0
- package/lib/nitrogen/generated/shared/c++/NativeListScrollAlignment.hpp +84 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +46 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +103 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +16 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeList.d.ts +18 -0
- package/lib/typescript/src/NativeList.nitro.d.ts +29 -0
- package/lib/typescript/src/NativeList.types.d.ts +87 -0
- package/lib/typescript/src/NativeList.web.d.ts +19 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/lib/typescript/src/models.d.ts +456 -0
- package/lib/typescript/src/scrolling.d.ts +32 -0
- package/lib/typescript/src/selection.d.ts +27 -0
- package/lib/typescript/src/validation.d.ts +7 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +203 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +201 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +84 -0
- package/nitrogen/generated/android/c++/JNativeListScrollAlignment.hpp +64 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +104 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_std__string.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +177 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollAlignment.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/nativelistOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListStateUpdater.kt +23 -0
- package/nitrogen/generated/android/nativelist+autolinking.cmake +83 -0
- package/nitrogen/generated/android/nativelist+autolinking.gradle +27 -0
- package/nitrogen/generated/android/nativelistOnLoad.cpp +58 -0
- package/nitrogen/generated/android/nativelistOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/NativeListModule+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +41 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +91 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +49 -0
- package/nitrogen/generated/ios/NativeListModuleAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NativeListModuleAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +180 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +180 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +69 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +447 -0
- package/nitrogen/generated/ios/swift/NativeListScrollAlignment.swift +48 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +43 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +87 -0
- package/nitrogen/generated/shared/c++/NativeListScrollAlignment.hpp +84 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +46 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +103 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +16 -0
- package/package.json +126 -0
- package/react-native-native-list.podspec +38 -0
- package/react-native.config.js +19 -0
- package/src/NativeList.nitro.ts +48 -0
- package/src/NativeList.tsx +298 -0
- package/src/NativeList.types.ts +125 -0
- package/src/NativeList.web.tsx +258 -0
- package/src/index.ts +35 -0
- package/src/models.ts +604 -0
- package/src/scrolling.ts +189 -0
- package/src/selection.ts +159 -0
- package/src/validation.ts +877 -0
- package/src/web/NativeListWebEngine.ts +3767 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function assertNonNegativeInteger(value, name) {
|
|
4
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
5
|
+
throw new Error(`NativeList ${name} must be a non-negative integer`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function assertFiniteNumber(value, name) {
|
|
9
|
+
if (!Number.isFinite(value)) {
|
|
10
|
+
throw new Error(`NativeList ${name} must be a finite number`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function positionForAlignment(alignment) {
|
|
14
|
+
switch (alignment) {
|
|
15
|
+
case 'center':
|
|
16
|
+
return 0.5;
|
|
17
|
+
case 'end':
|
|
18
|
+
return 1;
|
|
19
|
+
default:
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function normalizePositionScroll(options, defaultAlignment) {
|
|
24
|
+
const alignment = options.alignment ?? defaultAlignment;
|
|
25
|
+
if (options.alignment !== undefined && options.viewPosition !== undefined) {
|
|
26
|
+
throw new Error('NativeList alignment and viewPosition cannot be used together');
|
|
27
|
+
}
|
|
28
|
+
const viewPosition = options.viewPosition ?? positionForAlignment(alignment);
|
|
29
|
+
if (!Number.isFinite(viewPosition) || viewPosition < 0 || viewPosition > 1) {
|
|
30
|
+
throw new Error('NativeList viewPosition must be between 0 and 1');
|
|
31
|
+
}
|
|
32
|
+
const viewOffset = options.viewOffset ?? 0;
|
|
33
|
+
assertFiniteNumber(viewOffset, 'viewOffset');
|
|
34
|
+
return {
|
|
35
|
+
animated: options.animated ?? true,
|
|
36
|
+
alignment: options.viewPosition === undefined ? alignment : 'start',
|
|
37
|
+
viewPosition,
|
|
38
|
+
viewOffset
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function normalizeIndexScroll(paramsOrIndex, animated, alignment) {
|
|
42
|
+
if (typeof paramsOrIndex === 'number') {
|
|
43
|
+
assertNonNegativeInteger(paramsOrIndex, 'scrollToIndex index');
|
|
44
|
+
return {
|
|
45
|
+
index: paramsOrIndex,
|
|
46
|
+
scroll: normalizePositionScroll({
|
|
47
|
+
animated,
|
|
48
|
+
alignment
|
|
49
|
+
}, 'nearest')
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
assertNonNegativeInteger(paramsOrIndex.index, 'scrollToIndex index');
|
|
53
|
+
return {
|
|
54
|
+
index: paramsOrIndex.index,
|
|
55
|
+
scroll: normalizePositionScroll(paramsOrIndex, 'start')
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function normalizeKeyScroll(paramsOrKey, animated, alignment) {
|
|
59
|
+
if (typeof paramsOrKey === 'string') {
|
|
60
|
+
return {
|
|
61
|
+
key: paramsOrKey,
|
|
62
|
+
scroll: normalizePositionScroll({
|
|
63
|
+
animated,
|
|
64
|
+
alignment
|
|
65
|
+
}, 'nearest')
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
key: paramsOrKey.key,
|
|
70
|
+
scroll: normalizePositionScroll(paramsOrKey, 'start')
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function validateOffset(offset) {
|
|
74
|
+
assertFiniteNumber(offset, 'scroll offset');
|
|
75
|
+
if (offset < 0) {
|
|
76
|
+
throw new Error('NativeList scroll offset must be non-negative');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function resolveLocationIndex(rows, params) {
|
|
80
|
+
assertNonNegativeInteger(params.sectionIndex, 'scrollToLocation sectionIndex');
|
|
81
|
+
assertNonNegativeInteger(params.itemIndex, 'scrollToLocation itemIndex');
|
|
82
|
+
const headers = rows.map((row, index) => ({
|
|
83
|
+
row,
|
|
84
|
+
index
|
|
85
|
+
})).filter(entry => entry.row.type === 'sectionHeader' && entry.row.variant !== 'summary');
|
|
86
|
+
const section = headers[params.sectionIndex];
|
|
87
|
+
if (!section || section.row.type !== 'sectionHeader') return undefined;
|
|
88
|
+
const end = headers[params.sectionIndex + 1]?.index ?? rows.length;
|
|
89
|
+
const items = rows.slice(section.index + 1, end).map((row, offset) => ({
|
|
90
|
+
row,
|
|
91
|
+
index: section.index + 1 + offset
|
|
92
|
+
})).filter(entry => entry.row.type !== 'sectionHeader' && entry.row.sectionKey === section.row.sectionKey);
|
|
93
|
+
return items[params.itemIndex]?.index;
|
|
94
|
+
}
|
|
95
|
+
export function scrollFailure(rows, index, reason, averageItemLength = 0) {
|
|
96
|
+
return {
|
|
97
|
+
index,
|
|
98
|
+
itemCount: rows.length,
|
|
99
|
+
highestMeasuredFrameIndex: rows.length - 1,
|
|
100
|
+
averageItemLength,
|
|
101
|
+
reason
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function calculateAlignedScrollOffset({
|
|
105
|
+
itemOffset,
|
|
106
|
+
itemLength,
|
|
107
|
+
viewportLength,
|
|
108
|
+
contentLength,
|
|
109
|
+
currentOffset,
|
|
110
|
+
alignment,
|
|
111
|
+
viewPosition,
|
|
112
|
+
viewOffset
|
|
113
|
+
}) {
|
|
114
|
+
let resolvedPosition = viewPosition;
|
|
115
|
+
if (alignment === 'nearest') {
|
|
116
|
+
if (itemOffset < currentOffset) resolvedPosition = 0;else if (itemOffset + itemLength > currentOffset + viewportLength) resolvedPosition = 1;else return currentOffset;
|
|
117
|
+
}
|
|
118
|
+
const target = itemOffset - resolvedPosition * Math.max(0, viewportLength - itemLength) - viewOffset;
|
|
119
|
+
return Math.min(Math.max(0, target), Math.max(0, contentLength - viewportLength));
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=scrolling.js.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function isSelectableRow(row) {
|
|
4
|
+
return !row.disabled && (row.type === 'identity' || row.type === 'rail' || row.type === 'activity' || row.type === 'message' || row.type === 'dataRow' || row.type === 'mediaTile' || row.type === 'metricCard');
|
|
5
|
+
}
|
|
6
|
+
function deltaBetween(before, after, source, sourceKey) {
|
|
7
|
+
return {
|
|
8
|
+
addedKeys: [...after].filter(key => !before.has(key)),
|
|
9
|
+
removedKeys: [...before].filter(key => !after.has(key)),
|
|
10
|
+
source,
|
|
11
|
+
sourceKey
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function targetKeys(action, rows) {
|
|
15
|
+
switch (action.scope) {
|
|
16
|
+
case 'row':
|
|
17
|
+
return rows.some(row => row.key === action.key && isSelectableRow(row)) ? [action.key] : [];
|
|
18
|
+
case 'section':
|
|
19
|
+
return rows.filter(row => row.sectionKey === action.sectionKey && isSelectableRow(row)).map(row => row.key);
|
|
20
|
+
case 'list':
|
|
21
|
+
return rows.filter(isSelectableRow).map(row => row.key);
|
|
22
|
+
case 'replace':
|
|
23
|
+
return action.selectedKeys.filter(key => rows.some(row => row.key === key && isSelectableRow(row)));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function reduceSelection(state, action, rows) {
|
|
27
|
+
const before = new Set(state.selectedKeys);
|
|
28
|
+
if (state.mode === 'none') {
|
|
29
|
+
return {
|
|
30
|
+
state,
|
|
31
|
+
delta: {
|
|
32
|
+
addedKeys: [],
|
|
33
|
+
removedKeys: [],
|
|
34
|
+
source: 'list'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const targets = targetKeys(action, rows);
|
|
39
|
+
const source = action.scope === 'replace' ? 'list' : action.scope;
|
|
40
|
+
const sourceKey = action.scope === 'row' ? action.key : action.scope === 'section' ? action.sectionKey : undefined;
|
|
41
|
+
if (targets.length === 0 && action.scope !== 'replace') {
|
|
42
|
+
return {
|
|
43
|
+
state,
|
|
44
|
+
delta: deltaBetween(before, before, source, sourceKey)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const after = new Set(before);
|
|
48
|
+
if (action.scope === 'replace') {
|
|
49
|
+
after.clear();
|
|
50
|
+
const replacement = state.mode === 'single' ? targets.slice(0, 1) : targets;
|
|
51
|
+
replacement.forEach(key => after.add(key));
|
|
52
|
+
} else if (state.mode === 'single') {
|
|
53
|
+
const key = targets[0];
|
|
54
|
+
after.clear();
|
|
55
|
+
if (key && !before.has(key)) after.add(key);
|
|
56
|
+
} else {
|
|
57
|
+
const allSelected = targets.length > 0 && targets.every(key => before.has(key));
|
|
58
|
+
targets.forEach(key => allSelected ? after.delete(key) : after.add(key));
|
|
59
|
+
}
|
|
60
|
+
const nextState = {
|
|
61
|
+
mode: state.mode,
|
|
62
|
+
selectedKeys: after
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
state: nextState,
|
|
66
|
+
delta: deltaBetween(before, after, source, sourceKey)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function checkboxStateForKeys(keys, selectedKeys) {
|
|
70
|
+
if (keys.length === 0) return 'unchecked';
|
|
71
|
+
const selectedCount = keys.reduce((count, key) => count + (selectedKeys.has(key) ? 1 : 0), 0);
|
|
72
|
+
if (selectedCount === 0) return 'unchecked';
|
|
73
|
+
if (selectedCount === keys.length) return 'checked';
|
|
74
|
+
return 'indeterminate';
|
|
75
|
+
}
|
|
76
|
+
export function checkboxStateForSection(sectionKey, rows, selectedKeys) {
|
|
77
|
+
return checkboxStateForKeys(rows.filter(row => row.sectionKey === sectionKey && isSelectableRow(row)).map(row => row.key), selectedKeys);
|
|
78
|
+
}
|
|
79
|
+
export function selectionStateFromSnapshot(snapshot) {
|
|
80
|
+
return {
|
|
81
|
+
mode: snapshot.selection?.mode ?? 'none',
|
|
82
|
+
selectedKeys: new Set(snapshot.selection?.selectedKeys ?? [])
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=selection.js.map
|