nitro-ui-macos 0.0.0-stage → 0.0.1
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/CONTRIBUTING.md +56 -0
- package/LICENSE +21 -0
- package/PARITY.md +373 -0
- package/README.md +147 -2
- package/native/nitro-core/Package.swift +78 -0
- package/native/nitro-ui-core/Package.swift +112 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/AnimationFrameDisplayLink.swift +127 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridAnimationFrameScheduler.swift +91 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridLinking.swift +18 -0
- package/native/nitro-ui-dev/Package.swift +102 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoad.swift +14 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoader.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevLauncher.swift +192 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevMenu.swift +172 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevServerBrowser.swift +86 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevSession.swift +151 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevShortcuts.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevToast.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevTools.swift +141 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorModels.swift +97 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorOverlay.swift +698 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevBundles.swift +64 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevErrors.swift +56 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevLoadingView.swift +27 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevMenu.swift +40 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevToast.swift +19 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LauncherWindowController.swift +217 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LoadingOverlay.swift +104 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/RegisterDevLoader.swift +22 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/SavedBundles.swift +70 -0
- package/native/nitro-ui-glass/Package.swift +103 -0
- package/native/nitro-ui-glass/macos/HybridLiquidGlass.swift +5 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassContainerView.swift +40 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassView.swift +80 -0
- package/native/nitro-ui-glass/macos/LiquidGlassEffectView.swift +181 -0
- package/native/nitro-ui-glass/macos/LiquidGlassSupport.swift +17 -0
- package/native/nitro-ui-navigation/Package.swift +105 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationScreen.swift +199 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSharedElement.swift +17 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSplit.swift +889 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationStack.swift +404 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationTabs.swift +186 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/MacStackContainerController.swift +260 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/NavigationSharedElementView.swift +28 -0
- package/native/nitro-ui-renderer/Package.swift +105 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/HybridAnimator.swift +502 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/NitroAnimationContext.swift +54 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/View+Animations.swift +35 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/AssetFonts.swift +36 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/FlippedView.swift +360 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridContainerView.swift +28 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridFonts.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridLabel.swift +127 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridMaskedView.swift +185 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollView.swift +255 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollViewContent.swift +22 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridView.swift +18 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImage.swift +281 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageFactory.swift +132 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageLoader.swift +149 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageView.swift +601 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/ImagePixelSupport.swift +418 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/LabelView.swift +198 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/HybridListView.swift +177 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListCell.swift +98 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListContentView.swift +12 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListFenwickTree.swift +94 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListScrollView.swift +1100 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListSnapshot.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListUpdate.swift +11 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListView.swift +260 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NativeContainerView.swift +443 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NitroViewProtocols.swift +275 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/ShadowLayers.swift +338 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/HybridTextInput.swift +252 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/NitroTextInputView.swift +447 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/View.swift +660 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/CustomViewController.swift +254 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/DesktopHostDelegate.swift +14 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Extensions.swift +102 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/GestureRecognizerDelegate.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridGestureRecognizer.swift +41 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridLongPressGestureRecognizer.swift +172 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridPanGestureRecognizer.swift +193 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridTapGestureRecognizer.swift +165 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridAppearance.swift +75 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridApplication.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridKeyboard.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridScreen.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridViewController.swift +232 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindow.swift +61 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindowScene.swift +17 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/LayoutNode.swift +73 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/NSColor+rgba.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RegisterRootCallback.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RuntimeReloadableAppDelegate.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SafeAreaInsetsListeners.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SizeListeners.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/UIErrorHandler.swift +15 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/ViewController.swift +6 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Window.swift +156 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/WindowScene.swift +23 -0
- package/native/nitro-ui-runtime/Package.swift +67 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/DevLoader.swift +16 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/NitroUIAppDelegate.swift +253 -0
- package/package.json +59 -4
- package/src/Platform.ts +43 -0
- package/src/bin.js +18 -0
- package/src/build.ts +453 -0
- package/src/bundleWorker.ts +80 -0
- package/src/cli.ts +157 -0
- package/src/config.ts +233 -0
- package/src/create.ts +67 -0
- package/src/files.ts +70 -0
- package/src/index.ts +1 -0
- package/src/init.ts +301 -0
- package/src/inlinePlatform.ts +140 -0
- package/src/modules.ts +385 -0
- package/src/packageApp.ts +103 -0
- package/src/packageDirectory.ts +61 -0
- package/src/preload.ts +40 -0
- package/src/prepare.ts +433 -0
- package/src/run.ts +41 -0
- package/src/runApp.ts +81 -0
- package/src/start.ts +152 -0
- package/src/toolchain.ts +83 -0
- package/src/versions.ts +103 -0
- package/templates/AppIcon.icns +0 -0
package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/HybridListView.swift
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
internal import AppKit
|
|
2
|
+
internal import NitroModules
|
|
3
|
+
|
|
4
|
+
final class HybridListView: HybridListViewSpec {
|
|
5
|
+
typealias AllowedChildrenType = Never
|
|
6
|
+
|
|
7
|
+
let view = NativeListView(frame: .zero)
|
|
8
|
+
let layoutNode = LayoutNode()
|
|
9
|
+
var parentReference: (any HybridViewSpec)?
|
|
10
|
+
var gestureRecognizers: [any HybridGestureRecognizerSpec] = []
|
|
11
|
+
|
|
12
|
+
private static let defaultEstimatedItemSize = 44.0
|
|
13
|
+
private var estimatedItemSize = defaultEstimatedItemSize
|
|
14
|
+
private var contentPadding = NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
|
|
15
|
+
private var onRefresh: (any Callback<(), Void>)?
|
|
16
|
+
private var pendingUpdate: NativeListUpdate?
|
|
17
|
+
private let queueMicrotask: any Callback<any Callback<(), Void>, Void>
|
|
18
|
+
private var isApplyScheduled = false
|
|
19
|
+
private lazy var applyUpdates: any Callback<(), Void> = .native { [weak self] in
|
|
20
|
+
self?.applyPendingUpdates()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var showsVerticalScrollIndicator: Bool {
|
|
24
|
+
get { view.scrollView.hasVerticalScroller }
|
|
25
|
+
set { view.scrollView.hasVerticalScroller = newValue }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var showsHorizontalScrollIndicator: Bool {
|
|
29
|
+
get { view.scrollView.hasHorizontalScroller }
|
|
30
|
+
set { view.scrollView.hasHorizontalScroller = newValue }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
init(queueMicrotask: any Callback<any Callback<(), Void>, Void>) throws {
|
|
34
|
+
self.queueMicrotask = queueMicrotask
|
|
35
|
+
try super.init()
|
|
36
|
+
view.onLayoutNeeded = { [weak self] in
|
|
37
|
+
do {
|
|
38
|
+
try self?.scheduleApply()
|
|
39
|
+
} catch {
|
|
40
|
+
UIErrorHandler.report(error)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
view.onRefreshTriggered = { [weak self] in
|
|
44
|
+
do {
|
|
45
|
+
try self?.onRefresh?.callSync(())
|
|
46
|
+
} catch {
|
|
47
|
+
UIErrorHandler.report(error)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
func setHorizontal(horizontal: Bool) throws {
|
|
53
|
+
view.scrollView.setHorizontal(horizontal)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
func setAnchorItemId(id: String?, alignment: Double?) throws {
|
|
57
|
+
let fraction = CGFloat(alignment ?? 0)
|
|
58
|
+
view.scrollView.setAnchorItemId(id, alignment: fraction)
|
|
59
|
+
// This runs inside a React commit, where binding rows with `flushSync` is not allowed.
|
|
60
|
+
try scheduleApply()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// Configures macOS trackpad pull-to-refresh overscroll and a native `NSProgressIndicator`
|
|
64
|
+
/// overlay on vertical lists, firing `onRefresh` when pulled past the overscroll threshold.
|
|
65
|
+
func setRefreshControl(
|
|
66
|
+
onRefresh: any Callback<(), Void>,
|
|
67
|
+
refreshing: Bool,
|
|
68
|
+
offset: Double,
|
|
69
|
+
tint: Double?
|
|
70
|
+
) throws {
|
|
71
|
+
guard view.scrollView.isHorizontal == false else { return }
|
|
72
|
+
guard offset.isFinite else {
|
|
73
|
+
throw RuntimeError("List refresh indicator offset must be finite.")
|
|
74
|
+
}
|
|
75
|
+
let tintColor: NSColor?
|
|
76
|
+
if let tint {
|
|
77
|
+
guard let rgba = UInt32(exactly: tint) else {
|
|
78
|
+
throw RuntimeError("Invalid refresh indicator color.")
|
|
79
|
+
}
|
|
80
|
+
tintColor = NSColor(rgba: rgba)
|
|
81
|
+
} else {
|
|
82
|
+
tintColor = nil
|
|
83
|
+
}
|
|
84
|
+
self.onRefresh = onRefresh
|
|
85
|
+
view.updateRefreshIndicator(
|
|
86
|
+
configured: true,
|
|
87
|
+
refreshing: refreshing,
|
|
88
|
+
offset: CGFloat(offset),
|
|
89
|
+
tint: tintColor
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
func clearRefreshControl() throws {
|
|
94
|
+
onRefresh = nil
|
|
95
|
+
view.clearRefreshIndicator()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
func setEstimatedItemSize(size: Double?) throws {
|
|
99
|
+
let estimate = size ?? Self.defaultEstimatedItemSize
|
|
100
|
+
guard estimatedItemSize != estimate else { return }
|
|
101
|
+
estimatedItemSize = estimate
|
|
102
|
+
try scheduleApply()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
func setContentPadding(padding: EdgeInsets) throws {
|
|
106
|
+
guard padding.top.isFinite, padding.top >= 0,
|
|
107
|
+
padding.right.isFinite, padding.right >= 0,
|
|
108
|
+
padding.bottom.isFinite, padding.bottom >= 0,
|
|
109
|
+
padding.left.isFinite, padding.left >= 0 else {
|
|
110
|
+
throw RuntimeError("List contentPadding edges must be finite and non-negative.")
|
|
111
|
+
}
|
|
112
|
+
let insets = NSEdgeInsets(
|
|
113
|
+
top: CGFloat(padding.top),
|
|
114
|
+
left: CGFloat(padding.left),
|
|
115
|
+
bottom: CGFloat(padding.bottom),
|
|
116
|
+
right: CGFloat(padding.right)
|
|
117
|
+
)
|
|
118
|
+
let unchanged =
|
|
119
|
+
contentPadding.top == insets.top
|
|
120
|
+
&& contentPadding.left == insets.left
|
|
121
|
+
&& contentPadding.bottom == insets.bottom
|
|
122
|
+
&& contentPadding.right == insets.right
|
|
123
|
+
guard !unchanged else { return }
|
|
124
|
+
contentPadding = insets
|
|
125
|
+
try scheduleApply()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
func applySnapshot(
|
|
129
|
+
items: [ListItemDescriptor],
|
|
130
|
+
animated: Bool,
|
|
131
|
+
renderer: any Callback<(Double, any HybridViewSpec, String, Double), Void>,
|
|
132
|
+
onApplied: any Callback<(), Void>
|
|
133
|
+
) throws {
|
|
134
|
+
let snapshot = try NativeListSnapshot(items: items)
|
|
135
|
+
pendingUpdate = .snapshot(snapshot, animated: animated, renderer: renderer, onApplied: onApplied)
|
|
136
|
+
try scheduleApply()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
func clearDataSource() throws {
|
|
140
|
+
view.scrollView.disconnectRenderer()
|
|
141
|
+
pendingUpdate = .clear
|
|
142
|
+
try scheduleApply()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
func setFrame(frame: Frame) throws {
|
|
146
|
+
let baseView: any View = self
|
|
147
|
+
try baseView.setFrame(frame: frame)
|
|
148
|
+
try scheduleApply()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private func scheduleApply() throws {
|
|
152
|
+
guard isApplyScheduled == false else { return }
|
|
153
|
+
isApplyScheduled = true
|
|
154
|
+
do {
|
|
155
|
+
try queueMicrotask.callSync(applyUpdates)
|
|
156
|
+
} catch {
|
|
157
|
+
isApplyScheduled = false
|
|
158
|
+
throw error
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private func applyPendingUpdates() {
|
|
163
|
+
isApplyScheduled = false
|
|
164
|
+
let scrollView = view.scrollView
|
|
165
|
+
let crossAxisChanged = scrollView.updateFrame(
|
|
166
|
+
view.bounds,
|
|
167
|
+
estimatedItemSize: estimatedItemSize,
|
|
168
|
+
contentPadding: contentPadding
|
|
169
|
+
)
|
|
170
|
+
if let update = pendingUpdate {
|
|
171
|
+
pendingUpdate = nil
|
|
172
|
+
scrollView.apply(update, crossAxisChanged: crossAxisChanged)
|
|
173
|
+
} else {
|
|
174
|
+
scrollView.updateContentLayout(crossAxisChanged: crossAxisChanged)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListCell.swift
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
internal import AppKit
|
|
2
|
+
internal import NitroLayout
|
|
3
|
+
|
|
4
|
+
final class NativeListCellView: FlippedView {
|
|
5
|
+
override var isFlipped: Bool { true }
|
|
6
|
+
|
|
7
|
+
override func isAccessibilityElement() -> Bool {
|
|
8
|
+
return !isHidden
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
override func accessibilityRole() -> NSAccessibility.Role? {
|
|
12
|
+
return nitroAccessibilityRole ?? .row
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override func accessibilityChildren() -> [Any]? {
|
|
16
|
+
return NSAccessibility.unignoredChildren(from: subviews)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
final class NativeListCell {
|
|
21
|
+
let cellId: Double
|
|
22
|
+
let itemType: String
|
|
23
|
+
let cellView: NativeListCellView
|
|
24
|
+
let container: HybridView
|
|
25
|
+
let contentHost: NativeListContentView
|
|
26
|
+
|
|
27
|
+
var itemId: String?
|
|
28
|
+
var boundIndex: Int?
|
|
29
|
+
var boundVersion: Double?
|
|
30
|
+
var boundCrossAxisSize: CGFloat = -1
|
|
31
|
+
var boundExplicitWidth: Double?
|
|
32
|
+
var boundExplicitHeight: Double?
|
|
33
|
+
private var appliedConstraintWidth: Double?
|
|
34
|
+
private var appliedConstraintHeight: Double?
|
|
35
|
+
private var hasAppliedConstraints = false
|
|
36
|
+
weak var scrollView: NativeListScrollView?
|
|
37
|
+
|
|
38
|
+
init(cellId: Double, itemType: String) {
|
|
39
|
+
self.cellId = cellId
|
|
40
|
+
self.itemType = itemType
|
|
41
|
+
self.cellView = NativeListCellView(frame: .zero)
|
|
42
|
+
let host = NativeListContentView(frame: .zero)
|
|
43
|
+
self.contentHost = host
|
|
44
|
+
self.container = HybridView(view: host)
|
|
45
|
+
host.cell = self
|
|
46
|
+
cellView.addSubview(host)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
func setLayoutConstraints(width: Double?, height: Double?) {
|
|
50
|
+
if hasAppliedConstraints && appliedConstraintWidth == width && appliedConstraintHeight == height {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
hasAppliedConstraints = true
|
|
54
|
+
appliedConstraintWidth = width
|
|
55
|
+
appliedConstraintHeight = height
|
|
56
|
+
|
|
57
|
+
let node = container.layoutNode.ref
|
|
58
|
+
var size = contentHost.frame.size
|
|
59
|
+
if let width {
|
|
60
|
+
NLSetWidth(node, Float(width), NLPoint)
|
|
61
|
+
size.width = CGFloat(width)
|
|
62
|
+
} else {
|
|
63
|
+
NLSetWidth(node, .nan, NLPoint)
|
|
64
|
+
}
|
|
65
|
+
if let height {
|
|
66
|
+
NLSetHeight(node, Float(height), NLPoint)
|
|
67
|
+
size.height = CGFloat(height)
|
|
68
|
+
} else {
|
|
69
|
+
NLSetHeight(node, .nan, NLPoint)
|
|
70
|
+
}
|
|
71
|
+
if contentHost.frame.size != size || contentHost.frame.origin != .zero {
|
|
72
|
+
NitroAnimationContext.performWithoutImplicitAnimations {
|
|
73
|
+
self.contentHost.frame = NSRect(origin: .zero, size: size)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func contentSizeChanged(from previousSize: CGSize, to size: CGSize) {
|
|
79
|
+
scrollView?.contentSizeChanged(in: self, from: previousSize, to: size)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func resetForReuse() {
|
|
83
|
+
itemId = nil
|
|
84
|
+
boundIndex = nil
|
|
85
|
+
boundVersion = nil
|
|
86
|
+
boundCrossAxisSize = -1
|
|
87
|
+
boundExplicitWidth = nil
|
|
88
|
+
boundExplicitHeight = nil
|
|
89
|
+
cellView.alphaValue = 1
|
|
90
|
+
cellView.isHidden = true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
func dispose() {
|
|
94
|
+
scrollView = nil
|
|
95
|
+
contentHost.cell = nil
|
|
96
|
+
cellView.removeFromSuperview()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
internal import AppKit
|
|
2
|
+
|
|
3
|
+
final class NativeListContentView: FlippedView {
|
|
4
|
+
weak var cell: NativeListCell?
|
|
5
|
+
|
|
6
|
+
override func setFrameSize(_ newSize: NSSize) {
|
|
7
|
+
let previousSize = frame.size
|
|
8
|
+
super.setFrameSize(newSize)
|
|
9
|
+
guard newSize != previousSize else { return }
|
|
10
|
+
cell?.contentSizeChanged(from: previousSize, to: newSize)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
internal import Foundation
|
|
2
|
+
|
|
3
|
+
/// Binary Indexed Tree (Fenwick tree) storing per-row main-axis extents for O(log N)
|
|
4
|
+
/// offset lookup, O(log N) prefix sums, and O(log N) dynamic size updates across 100k+ rows.
|
|
5
|
+
struct NativeListFenwickTree {
|
|
6
|
+
private(set) var values: [Double]
|
|
7
|
+
private var tree: [Double]
|
|
8
|
+
private(set) var total: Double
|
|
9
|
+
|
|
10
|
+
var count: Int {
|
|
11
|
+
values.count
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
init() {
|
|
15
|
+
values = []
|
|
16
|
+
tree = [0.0]
|
|
17
|
+
total = 0.0
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
init(values: [Double]) {
|
|
21
|
+
let n = values.count
|
|
22
|
+
self.values = values
|
|
23
|
+
var bit = [Double](repeating: 0.0, count: n + 1)
|
|
24
|
+
var sum = 0.0
|
|
25
|
+
if n > 0 {
|
|
26
|
+
for i in 1 ... n {
|
|
27
|
+
let v = max(0.0, values[i - 1])
|
|
28
|
+
sum += v
|
|
29
|
+
bit[i] += v
|
|
30
|
+
let parent = i + (i & -i)
|
|
31
|
+
if parent <= n {
|
|
32
|
+
bit[parent] += bit[i]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
self.tree = bit
|
|
37
|
+
self.total = sum
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
mutating func set(at index: Int, to newValue: Double) {
|
|
41
|
+
guard index >= 0 && index < values.count else { return }
|
|
42
|
+
let sanitized = max(0.0, newValue)
|
|
43
|
+
let delta = sanitized - values[index]
|
|
44
|
+
guard delta != 0.0 else { return }
|
|
45
|
+
values[index] = sanitized
|
|
46
|
+
total += delta
|
|
47
|
+
let n = values.count
|
|
48
|
+
var i = index + 1
|
|
49
|
+
while i <= n {
|
|
50
|
+
tree[i] += delta
|
|
51
|
+
i += i & -i
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Sum of extents in `0 ..< index`.
|
|
56
|
+
func prefixSum(before index: Int) -> Double {
|
|
57
|
+
let clamped = min(max(0, index), values.count)
|
|
58
|
+
var i = clamped
|
|
59
|
+
var sum = 0.0
|
|
60
|
+
while i > 0 {
|
|
61
|
+
sum += tree[i]
|
|
62
|
+
i -= i & -i
|
|
63
|
+
}
|
|
64
|
+
return sum
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Smallest index `i` in `0 ..< count` whose trailing edge `prefixSum(before: i + 1)`
|
|
68
|
+
/// exceeds `offset`, or `count - 1` if `offset >= total`. Returns `nil` when empty.
|
|
69
|
+
func index(atOffset offset: Double) -> Int? {
|
|
70
|
+
let n = values.count
|
|
71
|
+
guard n > 0 else { return nil }
|
|
72
|
+
if offset <= 0.0 {
|
|
73
|
+
return 0
|
|
74
|
+
}
|
|
75
|
+
if offset >= total {
|
|
76
|
+
return n - 1
|
|
77
|
+
}
|
|
78
|
+
var idx = 0
|
|
79
|
+
var bit = 1
|
|
80
|
+
while (bit << 1) <= n {
|
|
81
|
+
bit <<= 1
|
|
82
|
+
}
|
|
83
|
+
var remaining = offset
|
|
84
|
+
while bit > 0 {
|
|
85
|
+
let next = idx + bit
|
|
86
|
+
if next <= n && tree[next] <= remaining {
|
|
87
|
+
remaining -= tree[next]
|
|
88
|
+
idx = next
|
|
89
|
+
}
|
|
90
|
+
bit >>= 1
|
|
91
|
+
}
|
|
92
|
+
return min(idx, n - 1)
|
|
93
|
+
}
|
|
94
|
+
}
|