peachsim 0.1.2563 → 0.1.2564
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/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +5 -4
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +5 -5
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-6TRDV6GV.mjs → acorn-ATKTRGBC.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-LJ5X3L6Q.mjs → chunk-2TNHD5YC.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WRACAH6T.mjs → chunk-3AJ4PEJW.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-X6DL6VLB.mjs → chunk-3NAKTTKU.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-OJQUPEDV.mjs → chunk-4M2ZY4ZW.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-UI4Q2Y2F.mjs → chunk-5LOA3GZ5.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-A2APYKPJ.mjs → chunk-6NLIASIH.mjs} +12 -12
- package/dist-lib/esm-chunks/{chunk-VLUSSVKC.mjs → chunk-7XBAB4AZ.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-UWTBFK2Q.mjs → chunk-BOXFJKG3.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-TH33GVSD.mjs → chunk-CXPBA242.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-CA5EIHD2.mjs → chunk-CZEW62OH.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-KPBQFLN4.mjs → chunk-D3KCDVEW.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-2P5CSC3P.mjs → chunk-DR56NKJH.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-DOLHETCA.mjs → chunk-E5TVA4S2.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-ZOYVG7OX.mjs → chunk-HRNPUVXK.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-GTOP2SAE.mjs → chunk-JGXROSXH.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-LG7XZOP6.mjs → chunk-LHMCEVNH.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-MRSQ2NLY.mjs → chunk-LKAABC7D.mjs} +4 -4
- package/dist-lib/esm-chunks/chunk-QGJL5Z4W.mjs +10 -0
- package/dist-lib/esm-chunks/{chunk-4IIXA354.mjs → chunk-QT6GM735.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-JMM5OO5X.mjs → chunk-UJZ4QMYX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-C4B2NROS.mjs → chunk-UR5E3JF4.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ORY3UUVZ.mjs → chunk-XJCUPAKO.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-MB23IWM5.mjs → metro-layout-parser-BMT4ABLU.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-URYMEPCF.mjs → swift-package-prebuilt-IDP3F7A5.mjs} +10 -10
- package/dist-lib/esm-chunks/{swift-sdk-app-module-5BJBIXIN.mjs → swift-sdk-app-module-3XVFPUB6.mjs} +14 -13
- package/dist-lib/esm-chunks/{swift-sdk-image-ALW5XBJ5.mjs → swift-sdk-image-CT65HIPH.mjs} +14 -13
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-ILJ6IEZJ.mjs → swift-sdk-image-producer-NCT6LI7J.mjs} +4 -4
- package/dist-lib/expo-swift-bundle.cjs +4 -3
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +1369 -821
- package/dist-lib/host/fetch-proxy-handler.cjs +4 -3
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +1 -1
- package/dist-lib/native-app-identity-project.mjs +16 -15
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +85 -79
- package/dist-lib/public-origins-lib.json +77 -70
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +8 -7
- package/dist-lib/skills.cjs +1932 -1384
- package/dist-lib/swift-compile.cjs +1 -1
- package/dist-lib/swift-compile.mjs +10 -10
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +5 -3
- package/dist-lib/swift-submit.mjs +9 -7
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/bplist-parser.cjs +1 -1
- package/dist-lib/vendor/ignore.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/plist.cjs +1 -1
- package/dist-lib/vendor/smol-toml.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +1 -1
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/package.json +1 -1
- package/src/one-native-controls-package.ts +580 -0
- package/src/one-native-source.ts +39 -5
- package/src/oneNativeControlsContract.ts +5 -0
- package/src/swift-submit.ts +4 -2
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
// builds the Peach Swift package that compiles One v3's unchanged SwiftUI
|
|
2
|
+
// controls against Peach's Swift SDK and exposes them through PeachTypedViews.
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import fs from 'node:fs'
|
|
5
|
+
import { createRequire } from 'node:module'
|
|
6
|
+
import path from 'node:path'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
import {
|
|
9
|
+
ONE_NATIVE_CONTROLS_CONTRACT,
|
|
10
|
+
ONE_NATIVE_CONTROLS_NAVIGATION_STACK_VIEW,
|
|
11
|
+
ONE_NATIVE_CONTROLS_PACKAGE,
|
|
12
|
+
} from './oneNativeControlsContract'
|
|
13
|
+
import { syncSwiftTree } from './swift-compile'
|
|
14
|
+
import { swiftPackageAssets, swiftPackageMetadata } from './swift-host'
|
|
15
|
+
import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from './swift-submit'
|
|
16
|
+
import { privateSwiftDistributionRoot, swiftCacheDir } from './swift-toolchain'
|
|
17
|
+
import type { SwiftEntryModuleArgs } from './swiftContract'
|
|
18
|
+
|
|
19
|
+
// unchanged upstream One SwiftUI sources required by OneNativeNavigationStackView
|
|
20
|
+
// and its toolbar/button/label/text/slot composition closure.
|
|
21
|
+
const ONE_CONTROL_SOURCES = [
|
|
22
|
+
'Generated/OneNativeNavigationStackView.swift',
|
|
23
|
+
'Generated/OneNativeToolbarView.swift',
|
|
24
|
+
'Generated/OneNativeListView.swift',
|
|
25
|
+
'Generated/OneNativeSectionView.swift',
|
|
26
|
+
'Generated/OneNativeFileImporterView.swift',
|
|
27
|
+
'Generated/OneNativeButtonView.swift',
|
|
28
|
+
'Generated/OneNativeLabelView.swift',
|
|
29
|
+
'Generated/OneNativeTextView.swift',
|
|
30
|
+
'Generated/OneNativeSwiftUI.swift',
|
|
31
|
+
'Generated/OneNativeAnimationValues.swift',
|
|
32
|
+
'Generated/OneNativeEnvironment.swift',
|
|
33
|
+
'OneNativeContainerSlotView.swift',
|
|
34
|
+
'OneNativeSyncState.swift',
|
|
35
|
+
'OneNativeAnimators.swift',
|
|
36
|
+
'OneNativeDragBinding.swift',
|
|
37
|
+
'OneNativeAccessibility.swift',
|
|
38
|
+
'OneNativeAsyncAction.swift',
|
|
39
|
+
'OneNativeControlled.swift',
|
|
40
|
+
'OneZoomSources.swift',
|
|
41
|
+
'OneNativeComposition.swift',
|
|
42
|
+
'OneNativeHostingController.swift',
|
|
43
|
+
'OneNativeSlot.swift',
|
|
44
|
+
'OneNativeStyle.swift',
|
|
45
|
+
] as const
|
|
46
|
+
|
|
47
|
+
const BRIDGE_SWIFT = `import SwiftUI
|
|
48
|
+
@_spi(Peach) import UIKit
|
|
49
|
+
import PeachJSON
|
|
50
|
+
|
|
51
|
+
private typealias Spec = [String: Any]
|
|
52
|
+
|
|
53
|
+
private func platformColor(named name: String) -> UIColor? {
|
|
54
|
+
switch name {
|
|
55
|
+
case "label", "-apple-system-label": return UIColor.label
|
|
56
|
+
case "secondaryLabel", "-apple-system-secondary-label": return UIColor.secondaryLabel
|
|
57
|
+
case "tertiaryLabel", "-apple-system-tertiary-label": return UIColor.tertiaryLabel
|
|
58
|
+
case "quaternaryLabel": return UIColor.quaternaryLabel
|
|
59
|
+
case "placeholderText", "-apple-system-placeholder-text": return UIColor.placeholderText
|
|
60
|
+
case "separator", "-apple-system-separator": return UIColor.separator
|
|
61
|
+
case "opaqueSeparator": return UIColor.opaqueSeparator
|
|
62
|
+
case "systemBackground", "-apple-system-background": return UIColor.systemBackground
|
|
63
|
+
case "secondarySystemBackground", "-apple-system-secondary-background": return UIColor.secondarySystemBackground
|
|
64
|
+
case "tertiarySystemBackground", "-apple-system-tertiary-background": return UIColor.tertiarySystemBackground
|
|
65
|
+
case "systemGroupedBackground", "-apple-system-grouped-background": return UIColor.systemGroupedBackground
|
|
66
|
+
case "secondarySystemGroupedBackground", "-apple-system-secondary-grouped-background": return UIColor.secondarySystemGroupedBackground
|
|
67
|
+
case "tertiarySystemGroupedBackground": return UIColor.tertiarySystemGroupedBackground
|
|
68
|
+
case "systemFill": return UIColor.systemFill
|
|
69
|
+
case "secondarySystemFill": return UIColor.secondarySystemFill
|
|
70
|
+
case "tertiarySystemFill", "-apple-system-tertiary-fill": return UIColor.tertiarySystemFill
|
|
71
|
+
case "quaternarySystemFill": return UIColor.quaternarySystemFill
|
|
72
|
+
case "systemBlue", "-apple-system-blue": return UIColor.systemBlue
|
|
73
|
+
case "systemCyan", "-apple-system-cyan": return UIColor.systemCyan
|
|
74
|
+
case "systemGray", "-apple-system-gray": return UIColor.systemGray
|
|
75
|
+
case "systemGray2": return UIColor.systemGray2
|
|
76
|
+
case "systemGray3", "-apple-system-gray-3": return UIColor.systemGray3
|
|
77
|
+
case "systemGray4": return UIColor.systemGray4
|
|
78
|
+
case "systemGray5": return UIColor.systemGray5
|
|
79
|
+
case "systemGray6": return UIColor.systemGray6
|
|
80
|
+
case "systemGreen", "-apple-system-green": return UIColor.systemGreen
|
|
81
|
+
case "systemIndigo", "-apple-system-indigo": return UIColor.systemIndigo
|
|
82
|
+
case "systemOrange", "-apple-system-orange": return UIColor.systemOrange
|
|
83
|
+
case "systemPink", "-apple-system-pink": return UIColor.systemPink
|
|
84
|
+
case "systemPurple", "-apple-system-purple": return UIColor.systemPurple
|
|
85
|
+
case "systemRed", "-apple-system-red": return UIColor.systemRed
|
|
86
|
+
case "systemTeal", "-apple-system-teal": return UIColor.systemTeal
|
|
87
|
+
case "systemYellow", "-apple-system-yellow": return UIColor.systemYellow
|
|
88
|
+
case "clear": return UIColor.clear
|
|
89
|
+
default: return nil
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private func parseColor(_ raw: Any) -> UIColor? {
|
|
94
|
+
if let color = raw as? UIColor { return color }
|
|
95
|
+
if let number = raw as? NSNumber {
|
|
96
|
+
let argb = UInt32(truncatingIfNeeded: number.int64Value)
|
|
97
|
+
let a = CGFloat((argb >> 24) & 0xFF) / 255.0
|
|
98
|
+
let r = CGFloat((argb >> 16) & 0xFF) / 255.0
|
|
99
|
+
let g = CGFloat((argb >> 8) & 0xFF) / 255.0
|
|
100
|
+
let b = CGFloat(argb & 0xFF) / 255.0
|
|
101
|
+
return UIColor(red: r, green: g, blue: b, alpha: a)
|
|
102
|
+
}
|
|
103
|
+
if let text = raw as? String {
|
|
104
|
+
if let named = platformColor(named: text) { return named }
|
|
105
|
+
if text.hasPrefix("#") {
|
|
106
|
+
let hex = String(text.dropFirst())
|
|
107
|
+
if hex.count == 6, let value = UInt64(hex, radix: 16) {
|
|
108
|
+
return UIColor(
|
|
109
|
+
red: CGFloat((value >> 16) & 0xFF) / 255.0,
|
|
110
|
+
green: CGFloat((value >> 8) & 0xFF) / 255.0,
|
|
111
|
+
blue: CGFloat(value & 0xFF) / 255.0,
|
|
112
|
+
alpha: 1.0
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
if hex.count == 8, let value = UInt64(hex, radix: 16) {
|
|
116
|
+
return UIColor(
|
|
117
|
+
red: CGFloat((value >> 24) & 0xFF) / 255.0,
|
|
118
|
+
green: CGFloat((value >> 16) & 0xFF) / 255.0,
|
|
119
|
+
blue: CGFloat((value >> 8) & 0xFF) / 255.0,
|
|
120
|
+
alpha: CGFloat(value & 0xFF) / 255.0
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return nil
|
|
125
|
+
}
|
|
126
|
+
if let dict = raw as? Spec {
|
|
127
|
+
if let semantic = dict["semantic"] as? [String] {
|
|
128
|
+
for name in semantic {
|
|
129
|
+
if let color = platformColor(named: name) { return color }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if let dynamic = dict["dynamic"] as? Spec,
|
|
133
|
+
let light = dynamic["light"].flatMap(parseColor),
|
|
134
|
+
let dark = dynamic["dark"].flatMap(parseColor) {
|
|
135
|
+
return UIColor { traits in
|
|
136
|
+
traits.userInterfaceStyle == .dark ? dark : light
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return nil
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private func normalizeStyle(_ raw: Spec?) -> Spec {
|
|
144
|
+
guard var style = raw else { return [:] }
|
|
145
|
+
for key in ["maxWidth", "maxHeight"] {
|
|
146
|
+
if let value = style[key] as? String, value == "Infinity" {
|
|
147
|
+
style[key] = Double.infinity
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for key in ["foregroundStyle", "tint", "background", "borderColor", "glassEffectTint"] {
|
|
151
|
+
if let value = style[key], let color = parseColor(value) {
|
|
152
|
+
style[key] = color
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if let cssColors = style["cssColors"] as? [String: String] {
|
|
156
|
+
for (field, keyword) in cssColors {
|
|
157
|
+
if let color = platformColor(named: keyword) {
|
|
158
|
+
style[field] = color
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
style.removeValue(forKey: "cssColors")
|
|
162
|
+
}
|
|
163
|
+
return style
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private struct NavigationStackBridge: UIViewRepresentable {
|
|
167
|
+
let spec: Spec
|
|
168
|
+
let emit: (String, String) -> Void
|
|
169
|
+
|
|
170
|
+
final class Coordinator {
|
|
171
|
+
let slot = UIView(frame: .zero)
|
|
172
|
+
var views: [String: UIView] = [:]
|
|
173
|
+
var children: [String: [UIView]] = [:]
|
|
174
|
+
var slots: [String: UIView] = [:]
|
|
175
|
+
var toolbars: [OneNativeToolbarView] = []
|
|
176
|
+
var emit: ((String, String) -> Void)?
|
|
177
|
+
|
|
178
|
+
func send(_ id: String, _ event: String, _ fields: Spec) {
|
|
179
|
+
let payload = try! JSONSerialization.data(withJSONObject: [id, event, fields])
|
|
180
|
+
emit?("dispatch", String(decoding: payload, as: UTF8.self))
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
func reconcile(
|
|
184
|
+
_ next: [UIView],
|
|
185
|
+
previous: [UIView],
|
|
186
|
+
remove: (UIView) -> Void,
|
|
187
|
+
insert: (UIView, Int) -> Void
|
|
188
|
+
) {
|
|
189
|
+
let prefix = zip(previous, next).prefix(while: { $0 === $1 }).count
|
|
190
|
+
for child in previous.dropFirst(prefix).reversed() { remove(child) }
|
|
191
|
+
for (index, child) in next.enumerated().dropFirst(prefix) { insert(child, index) }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
func render(_ node: Spec, visited: inout Set<String>) -> UIView {
|
|
195
|
+
let id = node["id"] as! String
|
|
196
|
+
let spec = node["spec"] as! Spec
|
|
197
|
+
let control = spec["control"] as! String
|
|
198
|
+
let style = normalizeStyle(spec["swiftStyle"] as? Spec)
|
|
199
|
+
let access = spec["accessibility"] as? Spec ?? [:]
|
|
200
|
+
let label = access["label"] as? String ?? ""
|
|
201
|
+
let hint = access["hint"] as? String ?? ""
|
|
202
|
+
let value = access["value"] as? String ?? ""
|
|
203
|
+
let identifier = access["identifier"] as? String ?? spec["testID"] as? String ?? ""
|
|
204
|
+
let visit: (String, String) -> Void = { [weak self] name, value in
|
|
205
|
+
self?.send(id, "onNativeSDKEvent", ["name": name, "value": value])
|
|
206
|
+
}
|
|
207
|
+
let view: UIView
|
|
208
|
+
visited.insert(id)
|
|
209
|
+
switch control {
|
|
210
|
+
case "OneNativeToolbar":
|
|
211
|
+
view = views[id] ?? OneNativeToolbarView()
|
|
212
|
+
case "OneNativeToolbarItem", "OneNativeToolbarItemGroup", "OneNativeToolbarSpacer", "OneNativeToolbarDefaultItem":
|
|
213
|
+
let marker = views[id] as? OneNativeToolbarMarkerView ?? OneNativeToolbarMarkerView()
|
|
214
|
+
let kinds = [
|
|
215
|
+
"OneNativeToolbarItem": "item",
|
|
216
|
+
"OneNativeToolbarItemGroup": "group",
|
|
217
|
+
"OneNativeToolbarSpacer": "spacer",
|
|
218
|
+
"OneNativeToolbarDefaultItem": "defaultItem",
|
|
219
|
+
]
|
|
220
|
+
marker.configure(
|
|
221
|
+
kind: kinds[control]!,
|
|
222
|
+
placement: spec["placement"] as? String ?? "automatic",
|
|
223
|
+
sizing: spec["sizing"] as? String ?? "flexible",
|
|
224
|
+
label: spec["label"] as? String ?? "",
|
|
225
|
+
systemImage: spec["systemImage"] as? String ?? "",
|
|
226
|
+
defaultItem: spec["kind"] as? String ?? ""
|
|
227
|
+
)
|
|
228
|
+
marker.configureStyle(style)
|
|
229
|
+
marker.setOnSDKEvent(visit)
|
|
230
|
+
view = marker
|
|
231
|
+
case "OneNativeButton":
|
|
232
|
+
let button = views[id] as? OneNativeButtonView ?? OneNativeButtonView()
|
|
233
|
+
button.configure(buttonRole: spec["buttonRole"] as? String ?? "")
|
|
234
|
+
button.configureAccessibility(label, hint: hint, value: value, identifier: identifier)
|
|
235
|
+
button.onAction = { [weak self] count in
|
|
236
|
+
self?.send(id, "onNativeButtonPress", ["eventCount": count])
|
|
237
|
+
}
|
|
238
|
+
view = button
|
|
239
|
+
case "OneNativeLabel":
|
|
240
|
+
let labelView = views[id] as? OneNativeLabelView ?? OneNativeLabelView(frame: .zero)
|
|
241
|
+
labelView.configure(spec["label"] as? String ?? "", systemImage: spec["systemImage"] as? String ?? "")
|
|
242
|
+
labelView.configureAccessibility(label, hint: hint, value: value, identifier: identifier)
|
|
243
|
+
labelView.configureStyle(style)
|
|
244
|
+
labelView.onSDKEvent = visit
|
|
245
|
+
view = labelView
|
|
246
|
+
case "OneNativeText":
|
|
247
|
+
let text = views[id] as? OneNativeTextView ?? OneNativeTextView(frame: .zero)
|
|
248
|
+
text.configure(spec["text"] as? String ?? "")
|
|
249
|
+
text.configureAccessibility(label, hint: hint, value: value, identifier: identifier)
|
|
250
|
+
text.configureStyle(style)
|
|
251
|
+
text.onSDKEvent = visit
|
|
252
|
+
view = text
|
|
253
|
+
case "OneNativeContainerSlot":
|
|
254
|
+
let slot = views[id] as? OneNativeContainerSlotView ?? OneNativeContainerSlotView(frame: .zero)
|
|
255
|
+
let host = slots[id] ?? UIView(frame: .zero)
|
|
256
|
+
slots[id] = host
|
|
257
|
+
host._peachReactContentHost = node["contentHost"] as? String
|
|
258
|
+
slot.content = host
|
|
259
|
+
slot.configure(height: spec["height"] as? Double ?? 0, width: spec["width"] as? Double ?? 0)
|
|
260
|
+
slot.configureSwiftStyle(style)
|
|
261
|
+
slot.onSwiftStyleEvent = visit
|
|
262
|
+
view = slot
|
|
263
|
+
default:
|
|
264
|
+
preconditionFailure("unsupported OneNativeNavigationStack toolbar child \\(control)")
|
|
265
|
+
}
|
|
266
|
+
views[id] = view
|
|
267
|
+
if let container = view as? OneNativeContainerView {
|
|
268
|
+
container.configureSwiftStyle(style)
|
|
269
|
+
container.onSwiftStyleEvent = visit
|
|
270
|
+
let nested = (node["children"] as? [Spec] ?? []).map { render($0, visited: &visited) }
|
|
271
|
+
reconcile(
|
|
272
|
+
nested,
|
|
273
|
+
previous: children[id] ?? [],
|
|
274
|
+
remove: container.removeChild,
|
|
275
|
+
insert: container.insertChild
|
|
276
|
+
)
|
|
277
|
+
children[id] = nested
|
|
278
|
+
}
|
|
279
|
+
return view
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
func prune(keeping visited: Set<String>) {
|
|
283
|
+
for (id, view) in views where !visited.contains(id) {
|
|
284
|
+
if let container = view as? OneNativeContainerView { container.reset() }
|
|
285
|
+
views.removeValue(forKey: id)
|
|
286
|
+
children.removeValue(forKey: id)
|
|
287
|
+
slots.removeValue(forKey: id)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
func makeCoordinator() -> Coordinator { Coordinator() }
|
|
293
|
+
|
|
294
|
+
func makeUIView(context: Context) -> OneNativeNavigationStackView {
|
|
295
|
+
let stack = OneNativeNavigationStackView(frame: .zero)
|
|
296
|
+
let state = context.coordinator
|
|
297
|
+
stack.mountContent(state.slot) { [weak state] frame in
|
|
298
|
+
state?.send("", "layout", ["x": frame.minX, "y": frame.minY, "width": frame.width, "height": frame.height])
|
|
299
|
+
}
|
|
300
|
+
return stack
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
func updateUIView(_ stack: OneNativeNavigationStackView, context: Context) {
|
|
304
|
+
let state = context.coordinator
|
|
305
|
+
state.emit = emit
|
|
306
|
+
let root = spec["root"] as! Spec
|
|
307
|
+
let id = root["id"] as! String
|
|
308
|
+
let rootSpec = root["spec"] as! Spec
|
|
309
|
+
state.slot._peachReactContentHost = spec["contentHost"] as? String
|
|
310
|
+
stack.onSDKEvent = { [weak state] name, value in
|
|
311
|
+
state?.send(id, "onNativeSDKEvent", ["name": name, "value": value])
|
|
312
|
+
}
|
|
313
|
+
stack.configureStyle(normalizeStyle(rootSpec["swiftStyle"] as? Spec))
|
|
314
|
+
var visited = Set<String>()
|
|
315
|
+
let next = (root["children"] as? [Spec] ?? []).map {
|
|
316
|
+
state.render($0, visited: &visited) as! OneNativeToolbarView
|
|
317
|
+
}
|
|
318
|
+
state.reconcile(
|
|
319
|
+
next,
|
|
320
|
+
previous: state.toolbars,
|
|
321
|
+
remove: { stack.unmountToolbar($0 as! OneNativeToolbarView) },
|
|
322
|
+
insert: { view, _ in stack.mountToolbar(view as! OneNativeToolbarView) }
|
|
323
|
+
)
|
|
324
|
+
state.toolbars = next
|
|
325
|
+
state.prune(keeping: visited)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static func dismantleUIView(_ view: OneNativeNavigationStackView, coordinator: Coordinator) {
|
|
329
|
+
view.unmountContent(coordinator.slot)
|
|
330
|
+
for toolbar in coordinator.toolbars { view.unmountToolbar(toolbar) }
|
|
331
|
+
coordinator.prune(keeping: [])
|
|
332
|
+
coordinator.toolbars.removeAll()
|
|
333
|
+
view.reset()
|
|
334
|
+
coordinator.emit = nil
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
@_expose(wasm, "peach_register_views")
|
|
339
|
+
@_cdecl("peach_register_views")
|
|
340
|
+
@MainActor public func peach_register_views() {
|
|
341
|
+
PeachTypedViews.register { view, contract, props, emit in
|
|
342
|
+
precondition(
|
|
343
|
+
view == "${ONE_NATIVE_CONTROLS_NAVIGATION_STACK_VIEW}" && contract == "${ONE_NATIVE_CONTROLS_CONTRACT}",
|
|
344
|
+
"unexpected compiled One control request \\(view) / \\(contract)"
|
|
345
|
+
)
|
|
346
|
+
let spec = try! JSONSerialization.jsonObject(with: Data(props.utf8)) as! Spec
|
|
347
|
+
return AnyView(
|
|
348
|
+
NavigationStackBridge(spec: spec, emit: emit)
|
|
349
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// representative tree exercised only when swift-startup-split profiles this package,
|
|
355
|
+
// keeping NavigationStack + Toolbar hot paths in the primary startup chunk instead
|
|
356
|
+
// of deferring them across hundreds of lazy code parts on first sheet open.
|
|
357
|
+
private let startupProfileSpec: [String: Any] = [
|
|
358
|
+
"contentHost": "__one-swift-startup-profile-slot",
|
|
359
|
+
"dispatch": false,
|
|
360
|
+
"root": [
|
|
361
|
+
"id": "profile-root",
|
|
362
|
+
"spec": [
|
|
363
|
+
"control": "OneNativeNavigationStack",
|
|
364
|
+
"swiftStyle": [
|
|
365
|
+
"sdkModifiers": #"[["navigationTitleWithText","Profile"],["navigationBarTitleDisplayMode","inline"]]"#,
|
|
366
|
+
],
|
|
367
|
+
],
|
|
368
|
+
"children": [
|
|
369
|
+
[
|
|
370
|
+
"id": "profile-toolbar",
|
|
371
|
+
"spec": ["control": "OneNativeToolbar"],
|
|
372
|
+
"children": [
|
|
373
|
+
[
|
|
374
|
+
"id": "profile-cancel-item",
|
|
375
|
+
"spec": ["control": "OneNativeToolbarItem", "placement": "cancellationAction"],
|
|
376
|
+
"children": [
|
|
377
|
+
[
|
|
378
|
+
"id": "profile-cancel-btn",
|
|
379
|
+
"spec": ["control": "OneNativeButton", "role": "cancel"],
|
|
380
|
+
"children": [
|
|
381
|
+
[
|
|
382
|
+
"id": "profile-cancel-label",
|
|
383
|
+
"spec": ["control": "OneNativeLabel", "title": "Cancel", "systemImage": "xmark"],
|
|
384
|
+
"children": [] as [Any],
|
|
385
|
+
],
|
|
386
|
+
],
|
|
387
|
+
],
|
|
388
|
+
],
|
|
389
|
+
],
|
|
390
|
+
[
|
|
391
|
+
"id": "profile-spacer",
|
|
392
|
+
"spec": ["control": "OneNativeToolbarSpacer", "placement": "topBarTrailing", "sizing": "fixed"],
|
|
393
|
+
"children": [] as [Any],
|
|
394
|
+
],
|
|
395
|
+
[
|
|
396
|
+
"id": "profile-confirm-group",
|
|
397
|
+
"spec": ["control": "OneNativeToolbarItemGroup", "placement": "confirmationAction"],
|
|
398
|
+
"children": [
|
|
399
|
+
[
|
|
400
|
+
"id": "profile-confirm-btn",
|
|
401
|
+
"spec": ["control": "OneNativeButton", "role": "confirm", "disabled": true],
|
|
402
|
+
"children": [
|
|
403
|
+
[
|
|
404
|
+
"id": "profile-confirm-label",
|
|
405
|
+
"spec": ["control": "OneNativeLabel", "title": "Add", "systemImage": "checkmark"],
|
|
406
|
+
"children": [] as [Any],
|
|
407
|
+
],
|
|
408
|
+
],
|
|
409
|
+
],
|
|
410
|
+
[
|
|
411
|
+
"id": "profile-text",
|
|
412
|
+
"spec": ["control": "OneNativeText", "text": "Item"],
|
|
413
|
+
"children": [] as [Any],
|
|
414
|
+
],
|
|
415
|
+
[
|
|
416
|
+
"id": "profile-slot",
|
|
417
|
+
"contentHost": "__one-swift-startup-profile-inline-slot",
|
|
418
|
+
"spec": ["control": "OneNativeContainerSlot", "width": 20.0, "height": 20.0],
|
|
419
|
+
"children": [] as [Any],
|
|
420
|
+
],
|
|
421
|
+
],
|
|
422
|
+
],
|
|
423
|
+
],
|
|
424
|
+
],
|
|
425
|
+
],
|
|
426
|
+
],
|
|
427
|
+
]
|
|
428
|
+
|
|
429
|
+
@main
|
|
430
|
+
struct OneNativeControlsGuest: PeachPackage {
|
|
431
|
+
func view(props: JSON) -> some View {
|
|
432
|
+
NavigationStackBridge(spec: startupProfileSpec, emit: { _, _ in })
|
|
433
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
`
|
|
437
|
+
|
|
438
|
+
function resolveOneNativeAppleIosDir(appRoot?: string): string {
|
|
439
|
+
if (appRoot && fs.existsSync(path.join(appRoot, 'package.json'))) {
|
|
440
|
+
const appRequire = createRequire(path.join(appRoot, 'package.json'))
|
|
441
|
+
let oneManifest: string | undefined
|
|
442
|
+
try {
|
|
443
|
+
oneManifest = appRequire.resolve('one/package.json')
|
|
444
|
+
} catch (error) {
|
|
445
|
+
if (
|
|
446
|
+
!(error instanceof Error) ||
|
|
447
|
+
!('code' in error) ||
|
|
448
|
+
error.code !== 'MODULE_NOT_FOUND'
|
|
449
|
+
) {
|
|
450
|
+
throw error
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (oneManifest) {
|
|
454
|
+
const installed = path.join(path.dirname(oneManifest), 'native/apple/ios')
|
|
455
|
+
if (
|
|
456
|
+
fs.existsSync(
|
|
457
|
+
path.join(installed, 'Generated/OneNativeNavigationStackView.swift'),
|
|
458
|
+
)
|
|
459
|
+
)
|
|
460
|
+
return installed
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const workspace = path.resolve(
|
|
464
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
465
|
+
'../../one-v3/native/apple/ios',
|
|
466
|
+
)
|
|
467
|
+
if (
|
|
468
|
+
!fs.existsSync(path.join(workspace, 'Generated/OneNativeNavigationStackView.swift'))
|
|
469
|
+
) {
|
|
470
|
+
throw new Error(`One SwiftUI native sources not found at ${workspace}`)
|
|
471
|
+
}
|
|
472
|
+
return workspace
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function defaultSwiftModuleRoot(): string | undefined {
|
|
476
|
+
if (privateSwiftDistributionRoot()) return undefined
|
|
477
|
+
const root = path.resolve(
|
|
478
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
479
|
+
'../../sootsim-swift',
|
|
480
|
+
)
|
|
481
|
+
return fs.existsSync(path.join(root, 'toolchain.json')) ? root : undefined
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export interface OneNativeControlsPackage {
|
|
485
|
+
packagePath: string
|
|
486
|
+
watched: string[]
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export async function oneNativeControlsPackage(
|
|
490
|
+
appRoot?: string,
|
|
491
|
+
): Promise<OneNativeControlsPackage> {
|
|
492
|
+
const iosDir = resolveOneNativeAppleIosDir(appRoot)
|
|
493
|
+
const sdkDir = path.join(iosDir, 'SDK')
|
|
494
|
+
const sdkFiles = fs
|
|
495
|
+
.readdirSync(sdkDir)
|
|
496
|
+
.filter((name) => name.endsWith('.swift'))
|
|
497
|
+
.sort()
|
|
498
|
+
.map((name) => `SDK/${name}`)
|
|
499
|
+
|
|
500
|
+
const files = new Map<string, string>()
|
|
501
|
+
const watched: string[] = []
|
|
502
|
+
const digest = createHash('sha256')
|
|
503
|
+
|
|
504
|
+
for (const relative of [...ONE_CONTROL_SOURCES, ...sdkFiles]) {
|
|
505
|
+
const full = path.join(iosDir, relative)
|
|
506
|
+
const content = fs.readFileSync(full, 'utf8')
|
|
507
|
+
const flatName = path.basename(relative)
|
|
508
|
+
if (files.has(flatName)) {
|
|
509
|
+
throw new Error(`duplicate Swift filename ${flatName} in OneNativeControls`)
|
|
510
|
+
}
|
|
511
|
+
files.set(flatName, content)
|
|
512
|
+
watched.push(full)
|
|
513
|
+
digest.update(flatName).update('\0').update(content).update('\0')
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
files.set('OneNativeControlsBridge.swift', BRIDGE_SWIFT)
|
|
517
|
+
digest.update('OneNativeControlsBridge.swift\0').update(BRIDGE_SWIFT).update('\0')
|
|
518
|
+
|
|
519
|
+
const key = digest.digest('hex').slice(0, 16)
|
|
520
|
+
files.set(
|
|
521
|
+
'Package.swift',
|
|
522
|
+
[
|
|
523
|
+
'// swift-tools-version: 6.2',
|
|
524
|
+
`// OneNativeControls ${key}`,
|
|
525
|
+
'import PackageDescription',
|
|
526
|
+
`let package = Package(name: "${ONE_NATIVE_CONTROLS_PACKAGE}", platforms: [.iOS(.v17)], targets: [`,
|
|
527
|
+
` .executableTarget(name: "${ONE_NATIVE_CONTROLS_PACKAGE}", path: ".", swiftSettings: [.swiftLanguageMode(.v5)]),`,
|
|
528
|
+
'])',
|
|
529
|
+
'',
|
|
530
|
+
].join('\n'),
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
const packagePath = path.join(
|
|
534
|
+
swiftCacheDir(),
|
|
535
|
+
'one-native-controls',
|
|
536
|
+
key,
|
|
537
|
+
ONE_NATIVE_CONTROLS_PACKAGE,
|
|
538
|
+
)
|
|
539
|
+
fs.mkdirSync(packagePath, { recursive: true })
|
|
540
|
+
syncSwiftTree(
|
|
541
|
+
packagePath,
|
|
542
|
+
new Map([...files].map(([file, text]) => [path.join(packagePath, file), text])),
|
|
543
|
+
)
|
|
544
|
+
return { packagePath, watched }
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
export async function stageOneNativeControlsRelease(
|
|
548
|
+
appRoot?: string,
|
|
549
|
+
options?: { moduleRoot?: string; startupRuntimeUrl?: URL },
|
|
550
|
+
): Promise<{
|
|
551
|
+
metadataPath: string
|
|
552
|
+
metadata: SwiftEntryModuleArgs
|
|
553
|
+
files: Map<string, Blob>
|
|
554
|
+
}> {
|
|
555
|
+
const { packagePath } = await oneNativeControlsPackage(appRoot)
|
|
556
|
+
const moduleRoot = options?.moduleRoot ?? defaultSwiftModuleRoot()
|
|
557
|
+
const metadata = await swiftPackageMetadata(
|
|
558
|
+
packagePath,
|
|
559
|
+
ONE_NATIVE_CONTROLS_PACKAGE,
|
|
560
|
+
moduleRoot,
|
|
561
|
+
'',
|
|
562
|
+
undefined,
|
|
563
|
+
undefined,
|
|
564
|
+
[],
|
|
565
|
+
options?.startupRuntimeUrl,
|
|
566
|
+
)
|
|
567
|
+
const assets = await swiftPackageAssets(packagePath, metadata)
|
|
568
|
+
const files = new Map<string, Blob>()
|
|
569
|
+
const metadataPath = `${SWIFT_PACKAGE_PATH}${ONE_NATIVE_CONTROLS_PACKAGE}`
|
|
570
|
+
files.set(
|
|
571
|
+
metadataPath,
|
|
572
|
+
new Blob([JSON.stringify({ ...metadata, hmrPath: SWIFT_HMR_PATH })], {
|
|
573
|
+
type: 'application/json',
|
|
574
|
+
}),
|
|
575
|
+
)
|
|
576
|
+
for (const [assetPath, { bytes, contentType }] of assets) {
|
|
577
|
+
files.set(assetPath, new Blob([new Uint8Array(bytes)], { type: contentType }))
|
|
578
|
+
}
|
|
579
|
+
return { metadataPath, metadata, files }
|
|
580
|
+
}
|
package/src/one-native-source.ts
CHANGED
|
@@ -11,8 +11,10 @@ import { brotliCompress, constants } from 'node:zlib'
|
|
|
11
11
|
import { KOTLIN_PACKAGE_PATH } from '@peach/globals/kotlin-discovery'
|
|
12
12
|
import { WebSocket, WebSocketServer } from 'ws'
|
|
13
13
|
import { isLoopbackHost } from './backend-origin'
|
|
14
|
+
import { oneNativeControlsPackage } from './one-native-controls-package'
|
|
14
15
|
import { configuredOneWidget } from './one-widget-metadata'
|
|
15
16
|
import { ONE_WIDGET_PACKAGE, oneWidgetPackage } from './one-widget-package'
|
|
17
|
+
import { ONE_NATIVE_CONTROLS_PACKAGE } from './oneNativeControlsContract'
|
|
16
18
|
import { ONE_WIDGET_PATH } from './oneWidgetContract'
|
|
17
19
|
import { swiftPackageMetadata, swiftPackageWatchFiles } from './swift-host'
|
|
18
20
|
import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from './swift-submit'
|
|
@@ -91,14 +93,21 @@ async function swiftPackages(root: string): Promise<Map<string, string>> {
|
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
async function packageMetadata(app: App, packageName: string) {
|
|
96
|
+
const builtinControls =
|
|
97
|
+
packageName === ONE_NATIVE_CONTROLS_PACKAGE
|
|
98
|
+
? await oneNativeControlsPackage(app.root || undefined)
|
|
99
|
+
: null
|
|
94
100
|
const widget =
|
|
95
|
-
packageName === ONE_WIDGET_PACKAGE
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
!builtinControls && packageName === ONE_WIDGET_PACKAGE
|
|
102
|
+
? await oneWidgetPackage(app.root)
|
|
103
|
+
: null
|
|
104
|
+
if (!builtinControls && !widget) app.packages ??= await swiftPackages(app.root)
|
|
105
|
+
if (widget && app.packages?.has(packageName))
|
|
98
106
|
throw new Error(
|
|
99
107
|
`swift package ${packageName} conflicts with One's generated widget extension`,
|
|
100
108
|
)
|
|
101
|
-
const packagePath =
|
|
109
|
+
const packagePath =
|
|
110
|
+
builtinControls?.packagePath ?? widget?.packagePath ?? app.packages?.get(packageName)
|
|
102
111
|
if (!packagePath) throw new Error(`swift package ${packageName} was not found`)
|
|
103
112
|
const moduleRoot = swiftModuleRoot()
|
|
104
113
|
const built = await swiftPackageMetadata(
|
|
@@ -110,6 +119,7 @@ async function packageMetadata(app: App, packageName: string) {
|
|
|
110
119
|
if (!app.active.has(packageName)) {
|
|
111
120
|
const files = [
|
|
112
121
|
...(await swiftPackageWatchFiles(packagePath, moduleRoot)),
|
|
122
|
+
...(builtinControls?.watched ?? []),
|
|
113
123
|
...(widget?.watched ?? []),
|
|
114
124
|
]
|
|
115
125
|
app.active.set(packageName, { packagePath, files: new Set(files) })
|
|
@@ -185,7 +195,31 @@ export async function handleOneNativeSourceRequest(
|
|
|
185
195
|
}
|
|
186
196
|
res.setHeader('access-control-allow-origin', req.headers.origin ?? '*')
|
|
187
197
|
res.setHeader('vary', 'origin')
|
|
188
|
-
const
|
|
198
|
+
const builtinControlsName = isSwift
|
|
199
|
+
? decodeURIComponent(url.pathname.slice(SWIFT_PACKAGE_PATH.length))
|
|
200
|
+
: null
|
|
201
|
+
const origin = req.headers.host ? `http://${req.headers.host}` : null
|
|
202
|
+
const app =
|
|
203
|
+
origin &&
|
|
204
|
+
(appFor(url, origin) ??
|
|
205
|
+
(builtinControlsName === ONE_NATIVE_CONTROLS_PACKAGE
|
|
206
|
+
? (() => {
|
|
207
|
+
let shared = apps.get('')
|
|
208
|
+
if (!shared) {
|
|
209
|
+
shared = {
|
|
210
|
+
root: '',
|
|
211
|
+
origin,
|
|
212
|
+
sockets: new WebSocketServer({ noServer: true }),
|
|
213
|
+
watched: new Set(),
|
|
214
|
+
active: new Map(),
|
|
215
|
+
}
|
|
216
|
+
apps.set('', shared)
|
|
217
|
+
} else {
|
|
218
|
+
shared.origin = origin
|
|
219
|
+
}
|
|
220
|
+
return shared
|
|
221
|
+
})()
|
|
222
|
+
: null))
|
|
189
223
|
if (!app) {
|
|
190
224
|
res.writeHead(400)
|
|
191
225
|
res.end('missing absolute app root')
|
package/src/swift-submit.ts
CHANGED
|
@@ -33,8 +33,10 @@ import {
|
|
|
33
33
|
} from './swiftContract'
|
|
34
34
|
|
|
35
35
|
export const SWIFT_COMPILE_PATH = '/api/swift-compile'
|
|
36
|
-
export
|
|
37
|
-
|
|
36
|
+
export {
|
|
37
|
+
SWIFT_HMR_PATH,
|
|
38
|
+
SWIFT_PACKAGE_PATH,
|
|
39
|
+
} from '../../peach-globals/src/swiftDiscoveryContract'
|
|
38
40
|
|
|
39
41
|
// shared with the compile service; collection enforces these before reading.
|
|
40
42
|
export const MAX_SWIFT_COMPILE_FILES = 256
|