bleam 0.0.6 → 0.0.8
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/ai.cjs +3984 -25
- package/dist/ai.d.cts +503 -20
- package/dist/ai.d.ts +503 -20
- package/dist/ai.js +3946 -26
- package/dist/animated.cjs +1 -1
- package/dist/animated.js +1 -1
- package/dist/app.cjs +92 -0
- package/dist/app.js +92 -0
- package/dist/cli.cjs +653 -86
- package/dist/cli.d.cts +89 -1
- package/dist/cli.d.ts +89 -1
- package/dist/cli.js +654 -88
- package/dist/{config-ClDGHNb3.d.ts → config-Cms0rvqg.d.ts} +1 -0
- package/dist/{config-D3gPaVMb.d.cts → config-CufOVJV3.d.cts} +1 -0
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/crypto.d.cts +0 -2
- package/dist/crypto.d.ts +1 -1
- package/dist/dev-protocol.d.cts +14 -1
- package/dist/dev-protocol.d.ts +14 -1
- package/dist/files-Bo7h9fik.cjs +468 -0
- package/dist/files-Ds1wT8C2.js +445 -0
- package/dist/files-DwA7pzr3.d.cts +99 -0
- package/dist/files-VrkQlKIT.d.ts +99 -0
- package/dist/files.cjs +7 -0
- package/dist/files.d.cts +2 -0
- package/dist/files.d.ts +2 -0
- package/dist/files.js +4 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/native-sqlite-xcGdamRD.js +64 -0
- package/dist/native-sqlite-yQLD5s9i.cjs +66 -0
- package/dist/platform.cjs +27 -0
- package/dist/platform.d.cts +39 -0
- package/dist/platform.d.ts +39 -0
- package/dist/platform.js +21 -0
- package/dist/runtime.d.cts +1 -6
- package/dist/runtime.d.ts +1 -6
- package/dist/{schema-ipsECAso.d.ts → schema-DOOjfXvs.d.ts} +1 -1
- package/dist/{schema-BOuUHcqo.d.cts → schema-ENSMX_1t.d.cts} +1 -1
- package/dist/schema.cjs +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/dist/state-Bx0VlTlO.cjs +852 -0
- package/dist/state-CAwe-Vw1.js +767 -0
- package/dist/state.cjs +17 -763
- package/dist/state.d.cts +107 -77
- package/dist/state.d.ts +107 -77
- package/dist/state.js +4 -745
- package/dist/ui-1WepaMS4.d.cts +92 -0
- package/dist/ui-Ce-pnUUA.d.ts +92 -0
- package/dist/ui.cjs +286 -35
- package/dist/ui.d.cts +2 -30
- package/dist/ui.d.ts +2 -30
- package/dist/ui.js +283 -36
- package/dist/window.cjs +596 -0
- package/dist/window.d.cts +63 -0
- package/dist/window.d.ts +63 -0
- package/dist/window.js +589 -0
- package/package.json +16 -14
- package/templates/basic/app/index.tsx +8 -5
- package/templates/foundation-models/app/index.tsx +32 -0
- package/templates/foundation-models/app.config.ts +5 -0
- package/templates/image-generation/app/index.tsx +39 -0
- package/templates/image-generation/app.config.ts +5 -0
- package/templates/state/app/index.tsx +30 -0
- package/templates/state/app.config.ts +5 -0
- package/dist/chrome.cjs +0 -265
- package/dist/chrome.d.cts +0 -19
- package/dist/chrome.d.ts +0 -19
- package/dist/chrome.js +0 -262
- package/dist/fs.cjs +0 -13
- package/dist/fs.d.cts +0 -8
- package/dist/fs.d.ts +0 -8
- package/dist/fs.js +0 -12
- package/dist/native-macos-D6p2SmUj.js +0 -20
- package/dist/native-macos-DLwo_ii9.cjs +0 -31
- package/dist/native-runtime-CbPzrs8j.d.cts +0 -33
- package/dist/native-runtime-DxHSrsTX.d.ts +0 -33
- package/dist/native.cjs +0 -135
- package/dist/native.d.cts +0 -34
- package/dist/native.d.ts +0 -34
- package/dist/native.js +0 -135
- /package/dist/{schema-DVmoD9JL.js → schema-Bo5Jvqus.js} +0 -0
- /package/dist/{schema-bxeeCyLn.cjs → schema-rQ13mrpD.cjs} +0 -0
package/dist/window.cjs
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_native_runtime = require('./native-runtime-CsXnXkQn.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
react = require_chunk.__toESM(react);
|
|
5
|
+
let react_native = require("react-native");
|
|
6
|
+
react_native = require_chunk.__toESM(react_native);
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
react_jsx_runtime = require_chunk.__toESM(react_jsx_runtime);
|
|
9
|
+
|
|
10
|
+
//#region src/native-macos.ts
|
|
11
|
+
function macOSApplication() {
|
|
12
|
+
return require_native_runtime.ensureNativeScript().getClass("NSApplication")?.sharedApplication;
|
|
13
|
+
}
|
|
14
|
+
function createMacOSToolbar(identifier) {
|
|
15
|
+
const toolbarClass = require_native_runtime.ensureNativeScript().getClass("NSToolbar");
|
|
16
|
+
if (!toolbarClass) return;
|
|
17
|
+
try {
|
|
18
|
+
const toolbar = toolbarClass.alloc?.().initWithIdentifier?.(identifier);
|
|
19
|
+
if (toolbar) return toolbar;
|
|
20
|
+
} catch {}
|
|
21
|
+
try {
|
|
22
|
+
return toolbarClass.new?.();
|
|
23
|
+
} catch {}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/safe-area.ts
|
|
28
|
+
const emptyInsets = {
|
|
29
|
+
top: 0,
|
|
30
|
+
right: 0,
|
|
31
|
+
bottom: 0,
|
|
32
|
+
left: 0
|
|
33
|
+
};
|
|
34
|
+
const contributions = /* @__PURE__ */ new Map();
|
|
35
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
36
|
+
let currentInsets = emptyInsets;
|
|
37
|
+
function mergeInsets() {
|
|
38
|
+
const nextInsets = { ...emptyInsets };
|
|
39
|
+
for (const contribution of contributions.values()) {
|
|
40
|
+
nextInsets.top += contribution.top ?? 0;
|
|
41
|
+
nextInsets.right += contribution.right ?? 0;
|
|
42
|
+
nextInsets.bottom += contribution.bottom ?? 0;
|
|
43
|
+
nextInsets.left += contribution.left ?? 0;
|
|
44
|
+
}
|
|
45
|
+
return nextInsets;
|
|
46
|
+
}
|
|
47
|
+
function areInsetsEqual(a, b) {
|
|
48
|
+
return a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left;
|
|
49
|
+
}
|
|
50
|
+
function emitIfChanged(nextInsets) {
|
|
51
|
+
if (areInsetsEqual(currentInsets, nextInsets)) return;
|
|
52
|
+
currentInsets = nextInsets;
|
|
53
|
+
for (const listener of listeners) listener();
|
|
54
|
+
}
|
|
55
|
+
function subscribe(listener) {
|
|
56
|
+
listeners.add(listener);
|
|
57
|
+
return () => {
|
|
58
|
+
listeners.delete(listener);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function snapshot() {
|
|
62
|
+
return currentInsets;
|
|
63
|
+
}
|
|
64
|
+
function setSafeAreaContribution(source, contribution) {
|
|
65
|
+
contributions.set(source, contribution);
|
|
66
|
+
emitIfChanged(mergeInsets());
|
|
67
|
+
}
|
|
68
|
+
function clearSafeAreaContribution(source) {
|
|
69
|
+
contributions.delete(source);
|
|
70
|
+
emitIfChanged(mergeInsets());
|
|
71
|
+
}
|
|
72
|
+
function useSafeAreaInsets() {
|
|
73
|
+
return (0, react.useSyncExternalStore)(subscribe, snapshot, snapshot);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/chrome.tsx
|
|
78
|
+
const toolbarStyleValues = {
|
|
79
|
+
automatic: 0,
|
|
80
|
+
expanded: 1,
|
|
81
|
+
preference: 2,
|
|
82
|
+
unified: 3,
|
|
83
|
+
unifiedCompact: 4
|
|
84
|
+
};
|
|
85
|
+
const toolbarSafeAreaHeights = {
|
|
86
|
+
automatic: 52,
|
|
87
|
+
expanded: 52,
|
|
88
|
+
preference: 52,
|
|
89
|
+
unified: 52,
|
|
90
|
+
unifiedCompact: 38
|
|
91
|
+
};
|
|
92
|
+
const toolbarSafeAreaSource = "toolbar";
|
|
93
|
+
const titleVisibilityValues = {
|
|
94
|
+
visible: 0,
|
|
95
|
+
hidden: 1
|
|
96
|
+
};
|
|
97
|
+
const userInterfaceStyleValues = {
|
|
98
|
+
automatic: 0,
|
|
99
|
+
light: 1,
|
|
100
|
+
dark: 2
|
|
101
|
+
};
|
|
102
|
+
function nativeRecord(value) {
|
|
103
|
+
if (!value || typeof value !== "object") return;
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
function macOSScene(value) {
|
|
107
|
+
return nativeRecord(value);
|
|
108
|
+
}
|
|
109
|
+
function macOSWindow(value) {
|
|
110
|
+
return nativeRecord(value);
|
|
111
|
+
}
|
|
112
|
+
function selectorTarget(value) {
|
|
113
|
+
return nativeRecord(value);
|
|
114
|
+
}
|
|
115
|
+
function setNativeValue(value, key, nextValue) {
|
|
116
|
+
const record = nativeRecord(value);
|
|
117
|
+
if (!record) return false;
|
|
118
|
+
record[key] = nextValue;
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
function colorFromHex(hex) {
|
|
122
|
+
const value = hex.trim().replace(/^#/, "");
|
|
123
|
+
const normalized = value.length === 3 ? value.split("").map((part) => `${part}${part}`).join("") : value;
|
|
124
|
+
if (!/^[\da-f]{6}$/i.test(normalized)) throw new Error(`Invalid color: ${hex}`);
|
|
125
|
+
const number = Number.parseInt(normalized, 16);
|
|
126
|
+
const red = (number >> 16 & 255) / 255;
|
|
127
|
+
const green = (number >> 8 & 255) / 255;
|
|
128
|
+
const blue = (number & 255) / 255;
|
|
129
|
+
return UIColor.colorWithRedGreenBlueAlpha(red, green, blue, 1);
|
|
130
|
+
}
|
|
131
|
+
function forEachNativeObject(collection, callback) {
|
|
132
|
+
const values = collection?.allObjects ?? collection;
|
|
133
|
+
if (Array.isArray(values)) {
|
|
134
|
+
values.forEach(callback);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const iterableValues = values;
|
|
138
|
+
const count = Number(iterableValues?.count ?? 0);
|
|
139
|
+
for (let index = 0; index < count; index += 1) callback(iterableValues?.objectAtIndex?.(index));
|
|
140
|
+
}
|
|
141
|
+
function runOnUIWithRetry(apply) {
|
|
142
|
+
const run = () => require_native_runtime.ensureNativeScript().runOnUI(apply).catch(() => {});
|
|
143
|
+
run();
|
|
144
|
+
const timeout = setTimeout(() => {
|
|
145
|
+
run();
|
|
146
|
+
}, 250);
|
|
147
|
+
return () => {
|
|
148
|
+
clearTimeout(timeout);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function applyWindowTitle(title) {
|
|
152
|
+
const application = UIApplication.sharedApplication;
|
|
153
|
+
forEachNativeObject(application?.connectedScenes, (scene) => {
|
|
154
|
+
setNativeValue(scene, "title", title);
|
|
155
|
+
});
|
|
156
|
+
const appKitApplication = macOSApplication();
|
|
157
|
+
const appKitWindow = appKitApplication?.keyWindow ?? appKitApplication?.mainWindow;
|
|
158
|
+
if (appKitWindow) setNativeValue(appKitWindow, "title", title);
|
|
159
|
+
}
|
|
160
|
+
function clearRootView(window) {
|
|
161
|
+
const rootView = (macOSWindow(window)?.rootViewController)?.view;
|
|
162
|
+
if (!rootView) return;
|
|
163
|
+
setNativeValue(rootView, "backgroundColor", UIColor.clearColor);
|
|
164
|
+
setNativeValue(rootView, "opaque", false);
|
|
165
|
+
}
|
|
166
|
+
function forEachApplicationWindow(callback) {
|
|
167
|
+
const application = UIApplication.sharedApplication;
|
|
168
|
+
callback(application.keyWindow);
|
|
169
|
+
forEachNativeObject(application?.windows, callback);
|
|
170
|
+
forEachNativeObject(application?.connectedScenes, (scene) => {
|
|
171
|
+
callback(macOSScene(scene)?.keyWindow);
|
|
172
|
+
forEachNativeObject(macOSScene(scene)?.windows, callback);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function applyWindowTint(tint) {
|
|
176
|
+
const tintColor = colorFromHex(tint);
|
|
177
|
+
function applyTint(window) {
|
|
178
|
+
if (!window) return;
|
|
179
|
+
setNativeValue(window, "tintColor", tintColor);
|
|
180
|
+
clearRootView(window);
|
|
181
|
+
const rootView = (macOSWindow(window)?.rootViewController)?.view;
|
|
182
|
+
if (rootView) setNativeValue(rootView, "tintColor", tintColor);
|
|
183
|
+
}
|
|
184
|
+
forEachApplicationWindow(applyTint);
|
|
185
|
+
}
|
|
186
|
+
function applyWindowBackgroundColor(backgroundColor) {
|
|
187
|
+
const color = colorFromHex(backgroundColor);
|
|
188
|
+
forEachApplicationWindow((window) => {
|
|
189
|
+
if (!window) return;
|
|
190
|
+
setNativeValue(window, "backgroundColor", color);
|
|
191
|
+
clearRootView(window);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function applyWindowUserInterfaceStyle(userInterfaceStyle) {
|
|
195
|
+
const value = userInterfaceStyleValues[userInterfaceStyle];
|
|
196
|
+
forEachApplicationWindow((window) => {
|
|
197
|
+
if (!window) return;
|
|
198
|
+
setNativeValue(window, "overrideUserInterfaceStyle", value);
|
|
199
|
+
const rootViewController = macOSWindow(window)?.rootViewController;
|
|
200
|
+
if (rootViewController) setNativeValue(rootViewController, "overrideUserInterfaceStyle", value);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function applyWindowRootTransparency() {
|
|
204
|
+
forEachApplicationWindow((window) => {
|
|
205
|
+
if (window) clearRootView(window);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function invokeNativeValue(target, selector, ...values) {
|
|
209
|
+
const invoke = selectorTarget(target)?.invoke;
|
|
210
|
+
if (typeof invoke !== "function") return;
|
|
211
|
+
return invoke.call(target, selector, ...values);
|
|
212
|
+
}
|
|
213
|
+
function titlebarForScene(scene) {
|
|
214
|
+
try {
|
|
215
|
+
const titlebar = invokeNativeValue(scene, "titlebar");
|
|
216
|
+
if (titlebar) return titlebar;
|
|
217
|
+
} catch {}
|
|
218
|
+
try {
|
|
219
|
+
const target = selectorTarget(scene);
|
|
220
|
+
if (target?.valueForKey) {
|
|
221
|
+
const titlebar = target.valueForKey("titlebar");
|
|
222
|
+
if (titlebar) return titlebar;
|
|
223
|
+
}
|
|
224
|
+
} catch {}
|
|
225
|
+
return macOSScene(scene)?.titlebar;
|
|
226
|
+
}
|
|
227
|
+
function setNativeNumber(target, key, value) {
|
|
228
|
+
const selector = `set${key[0]?.toUpperCase()}${key.slice(1)}:`;
|
|
229
|
+
try {
|
|
230
|
+
if (invokeNativeValue(target, selector, value) !== void 0) return;
|
|
231
|
+
} catch {}
|
|
232
|
+
try {
|
|
233
|
+
if (setNativeValue(target, key, value)) return;
|
|
234
|
+
} catch {}
|
|
235
|
+
try {
|
|
236
|
+
const selector$1 = selectorTarget(target);
|
|
237
|
+
if (selector$1?.setValueForKey) {
|
|
238
|
+
selector$1.setValueForKey(NSNumber.numberWithInteger(value), key);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
} catch {}
|
|
242
|
+
}
|
|
243
|
+
function applyTitleVisibility(titleVisibility) {
|
|
244
|
+
if (!macOSApplication()) return;
|
|
245
|
+
const value = titleVisibilityValues[titleVisibility];
|
|
246
|
+
const application = UIApplication.sharedApplication;
|
|
247
|
+
forEachNativeObject(application?.connectedScenes, (scene) => {
|
|
248
|
+
const titlebar = titlebarForScene(scene);
|
|
249
|
+
if (!titlebar) return;
|
|
250
|
+
setNativeNumber(titlebar, "titleVisibility", value);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function toolbarForTitlebar(titlebar) {
|
|
254
|
+
let toolbar;
|
|
255
|
+
try {
|
|
256
|
+
toolbar = invokeNativeValue(titlebar, "toolbar");
|
|
257
|
+
} catch {}
|
|
258
|
+
try {
|
|
259
|
+
toolbar ??= titlebar.toolbar;
|
|
260
|
+
} catch {}
|
|
261
|
+
try {
|
|
262
|
+
if (!toolbar && titlebar.valueForKey) toolbar = titlebar.valueForKey("toolbar");
|
|
263
|
+
} catch {}
|
|
264
|
+
if (toolbar) return toolbar;
|
|
265
|
+
toolbar = createMacOSToolbar("BleamToolbar");
|
|
266
|
+
if (!toolbar) return;
|
|
267
|
+
try {
|
|
268
|
+
if (invokeNativeValue(titlebar, "setToolbar:", toolbar) !== void 0) return toolbar;
|
|
269
|
+
} catch {}
|
|
270
|
+
try {
|
|
271
|
+
if (setNativeValue(titlebar, "toolbar", toolbar)) return toolbar;
|
|
272
|
+
} catch {}
|
|
273
|
+
try {
|
|
274
|
+
if (titlebar.setValueForKey) {
|
|
275
|
+
titlebar.setValueForKey(toolbar, "toolbar");
|
|
276
|
+
return toolbar;
|
|
277
|
+
}
|
|
278
|
+
} catch {}
|
|
279
|
+
}
|
|
280
|
+
function applyToolbarStyle(toolbarStyle) {
|
|
281
|
+
if (!macOSApplication()) return;
|
|
282
|
+
const value = toolbarStyleValues[toolbarStyle];
|
|
283
|
+
const application = UIApplication.sharedApplication;
|
|
284
|
+
forEachNativeObject(application?.connectedScenes, (scene) => {
|
|
285
|
+
const titlebar = titlebarForScene(scene);
|
|
286
|
+
if (!titlebar) return;
|
|
287
|
+
toolbarForTitlebar(titlebar);
|
|
288
|
+
setNativeNumber(titlebar, "toolbarStyle", value);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
function Window(props) {
|
|
292
|
+
const { title, tint, backgroundColor, userInterfaceStyle, titleVisibility } = props;
|
|
293
|
+
(0, react.useLayoutEffect)(() => {
|
|
294
|
+
return runOnUIWithRetry(() => {
|
|
295
|
+
applyWindowRootTransparency();
|
|
296
|
+
});
|
|
297
|
+
}, []);
|
|
298
|
+
(0, react.useEffect)(() => {
|
|
299
|
+
if (title === void 0) return;
|
|
300
|
+
require_native_runtime.ensureNativeScript().runOnUI(() => {
|
|
301
|
+
applyWindowTitle(title);
|
|
302
|
+
}).catch(() => {});
|
|
303
|
+
}, [title]);
|
|
304
|
+
(0, react.useLayoutEffect)(() => {
|
|
305
|
+
if (tint === void 0) return;
|
|
306
|
+
return runOnUIWithRetry(() => {
|
|
307
|
+
applyWindowTint(tint);
|
|
308
|
+
});
|
|
309
|
+
}, [tint]);
|
|
310
|
+
(0, react.useLayoutEffect)(() => {
|
|
311
|
+
if (backgroundColor === void 0) return;
|
|
312
|
+
return runOnUIWithRetry(() => {
|
|
313
|
+
applyWindowBackgroundColor(backgroundColor);
|
|
314
|
+
});
|
|
315
|
+
}, [backgroundColor]);
|
|
316
|
+
(0, react.useLayoutEffect)(() => {
|
|
317
|
+
if (userInterfaceStyle === void 0) return;
|
|
318
|
+
return runOnUIWithRetry(() => {
|
|
319
|
+
applyWindowUserInterfaceStyle(userInterfaceStyle);
|
|
320
|
+
});
|
|
321
|
+
}, [userInterfaceStyle]);
|
|
322
|
+
(0, react.useEffect)(() => {
|
|
323
|
+
if (titleVisibility === void 0) return;
|
|
324
|
+
require_native_runtime.ensureNativeScript().runOnUI(() => {
|
|
325
|
+
applyTitleVisibility(titleVisibility);
|
|
326
|
+
}).catch(() => {});
|
|
327
|
+
}, [titleVisibility]);
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
function Toolbar(props) {
|
|
331
|
+
const { toolbarStyle } = props;
|
|
332
|
+
(0, react.useEffect)(() => {
|
|
333
|
+
if (toolbarStyle === void 0) {
|
|
334
|
+
clearSafeAreaContribution(toolbarSafeAreaSource);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
setSafeAreaContribution(toolbarSafeAreaSource, { top: toolbarSafeAreaHeights[toolbarStyle] });
|
|
338
|
+
require_native_runtime.ensureNativeScript().runOnUI(() => {
|
|
339
|
+
applyToolbarStyle(toolbarStyle);
|
|
340
|
+
}).catch(() => {});
|
|
341
|
+
return () => {
|
|
342
|
+
clearSafeAreaContribution(toolbarSafeAreaSource);
|
|
343
|
+
};
|
|
344
|
+
}, [toolbarStyle]);
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/navigation.tsx
|
|
350
|
+
const stateKey = Symbol.for("bleam.navigation.sidebar");
|
|
351
|
+
const sectionIdentifier = "sidebar";
|
|
352
|
+
const splitIdentifier = "bleam.navigation.sidebar.split";
|
|
353
|
+
const defaultMinimumSidebarWidth = 180;
|
|
354
|
+
const defaultSidebarWidth = 240;
|
|
355
|
+
const defaultMaximumSidebarWidth = 320;
|
|
356
|
+
const MissingContext = Symbol("MissingContext");
|
|
357
|
+
const sidebarSafeAreaSource = "sidebar";
|
|
358
|
+
function sidebarState() {
|
|
359
|
+
const globalState = globalThis;
|
|
360
|
+
globalState[stateKey] ??= {
|
|
361
|
+
items: [],
|
|
362
|
+
titleById: /* @__PURE__ */ new Map(),
|
|
363
|
+
symbolById: /* @__PURE__ */ new Map(),
|
|
364
|
+
sidebarWidth: defaultSidebarWidth,
|
|
365
|
+
minimumSidebarWidth: defaultMinimumSidebarWidth,
|
|
366
|
+
maximumSidebarWidth: defaultMaximumSidebarWidth
|
|
367
|
+
};
|
|
368
|
+
return globalState[stateKey];
|
|
369
|
+
}
|
|
370
|
+
function isClassAvailable(name) {
|
|
371
|
+
const nativeScript = require_native_runtime.ensureNativeScript();
|
|
372
|
+
return nativeScript.isClassAvailable?.(name) ?? Boolean(nativeScript.getClass(name));
|
|
373
|
+
}
|
|
374
|
+
function requiredNativeClassesAvailable() {
|
|
375
|
+
return [
|
|
376
|
+
"UISplitViewController",
|
|
377
|
+
"UICollectionLayoutListConfiguration",
|
|
378
|
+
"UICollectionViewCompositionalLayout",
|
|
379
|
+
"UICollectionView",
|
|
380
|
+
"UICollectionViewListCell",
|
|
381
|
+
"UICollectionViewCellRegistration",
|
|
382
|
+
"UICollectionViewDiffableDataSource",
|
|
383
|
+
"NSDiffableDataSourceSnapshot"
|
|
384
|
+
].every(isClassAvailable);
|
|
385
|
+
}
|
|
386
|
+
function createSidebarController(state) {
|
|
387
|
+
const listConfiguration = UICollectionLayoutListConfiguration.alloc().initWithAppearance(UICollectionLayoutListAppearance.Sidebar);
|
|
388
|
+
listConfiguration.showsSeparators = false;
|
|
389
|
+
const layout = UICollectionViewCompositionalLayout.layoutWithListConfiguration(listConfiguration);
|
|
390
|
+
const collectionView = UICollectionView.alloc().initWithFrameCollectionViewLayout(CGRectZero, layout);
|
|
391
|
+
collectionView.backgroundColor = UIColor.clearColor;
|
|
392
|
+
collectionView.allowsMultipleSelection = false;
|
|
393
|
+
collectionView.allowsFocus = false;
|
|
394
|
+
collectionView.remembersLastFocusedIndexPath = false;
|
|
395
|
+
collectionView.selectionFollowsFocus = false;
|
|
396
|
+
const sidebarController = UIViewController.new();
|
|
397
|
+
sidebarController.title = "Sidebar";
|
|
398
|
+
sidebarController.view = collectionView;
|
|
399
|
+
const cellRegistration = UICollectionViewCellRegistration.registrationWithCellClassConfigurationHandler(UICollectionViewListCell, (cell, _indexPath, item) => {
|
|
400
|
+
const listCell = cell;
|
|
401
|
+
const content = listCell.defaultContentConfiguration();
|
|
402
|
+
const itemId = String(item);
|
|
403
|
+
const symbol = state.symbolById.get(itemId);
|
|
404
|
+
content.text = state.titleById.get(itemId) ?? itemId;
|
|
405
|
+
content.image = symbol ? UIImage.systemImageNamed(symbol) : null;
|
|
406
|
+
listCell.contentConfiguration = content;
|
|
407
|
+
listCell.accessories = [];
|
|
408
|
+
});
|
|
409
|
+
const dataSource = UICollectionViewDiffableDataSource.alloc().initWithCollectionViewCellProvider(collectionView, (nextCollectionView, indexPath, item) => nextCollectionView.dequeueConfiguredReusableCellWithRegistrationForIndexPathItem(cellRegistration, indexPath, item));
|
|
410
|
+
const delegate = require_native_runtime.ensureNativeScript().createDelegate(UICollectionViewDelegate, { collectionViewDidSelectItemAtIndexPath(_collectionView, indexPath) {
|
|
411
|
+
const item = state.items[indexPath.item];
|
|
412
|
+
if (!item) return;
|
|
413
|
+
state.selectedId = item.id;
|
|
414
|
+
state.emitSelect?.(item.id);
|
|
415
|
+
} });
|
|
416
|
+
collectionView.dataSource = dataSource;
|
|
417
|
+
collectionView.delegate = delegate;
|
|
418
|
+
state.sidebarViewController = sidebarController;
|
|
419
|
+
state.collectionView = collectionView;
|
|
420
|
+
state.dataSource = dataSource;
|
|
421
|
+
state.delegate = delegate;
|
|
422
|
+
state.cellRegistration = cellRegistration;
|
|
423
|
+
return sidebarController;
|
|
424
|
+
}
|
|
425
|
+
function isSidebarSplitController(viewController) {
|
|
426
|
+
if (!viewController) return false;
|
|
427
|
+
return viewController.restorationIdentifier === splitIdentifier && viewController.isKindOfClass(UISplitViewController);
|
|
428
|
+
}
|
|
429
|
+
function reuseExistingSidebarSplit(state, splitViewController) {
|
|
430
|
+
const contentViewController = splitViewController.viewControllerForColumn(UISplitViewControllerColumn.Secondary);
|
|
431
|
+
const sidebarController = createSidebarController(state);
|
|
432
|
+
splitViewController.minimumPrimaryColumnWidth = state.minimumSidebarWidth;
|
|
433
|
+
splitViewController.preferredPrimaryColumnWidth = state.sidebarWidth;
|
|
434
|
+
splitViewController.maximumPrimaryColumnWidth = state.maximumSidebarWidth;
|
|
435
|
+
splitViewController.setViewControllerForColumn(sidebarController, UISplitViewControllerColumn.Primary);
|
|
436
|
+
state.originalRootViewController = contentViewController;
|
|
437
|
+
state.splitViewController = splitViewController;
|
|
438
|
+
}
|
|
439
|
+
function installSidebarNavigator(state) {
|
|
440
|
+
if (state.splitViewController) return;
|
|
441
|
+
if (!requiredNativeClassesAvailable()) return;
|
|
442
|
+
const window = UIApplication.sharedApplication.keyWindow;
|
|
443
|
+
const rootViewController = window?.rootViewController;
|
|
444
|
+
if (!window || !rootViewController) return;
|
|
445
|
+
if (isSidebarSplitController(rootViewController)) {
|
|
446
|
+
reuseExistingSidebarSplit(state, rootViewController);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const sidebarController = createSidebarController(state);
|
|
450
|
+
const splitViewController = UISplitViewController.alloc().initWithStyle(UISplitViewControllerStyle.DoubleColumn);
|
|
451
|
+
splitViewController.restorationIdentifier = splitIdentifier;
|
|
452
|
+
splitViewController.primaryBackgroundStyle = UISplitViewControllerBackgroundStyle.Sidebar;
|
|
453
|
+
splitViewController.preferredSplitBehavior = UISplitViewControllerSplitBehavior.Tile;
|
|
454
|
+
splitViewController.preferredDisplayMode = UISplitViewControllerDisplayMode.OneBesideSecondary;
|
|
455
|
+
splitViewController.displayModeButtonVisibility = UISplitViewControllerDisplayModeButtonVisibility.Always;
|
|
456
|
+
splitViewController.minimumPrimaryColumnWidth = state.minimumSidebarWidth;
|
|
457
|
+
splitViewController.preferredPrimaryColumnWidth = state.sidebarWidth;
|
|
458
|
+
splitViewController.maximumPrimaryColumnWidth = state.maximumSidebarWidth;
|
|
459
|
+
splitViewController.setViewControllerForColumn(sidebarController, UISplitViewControllerColumn.Primary);
|
|
460
|
+
splitViewController.setViewControllerForColumn(rootViewController, UISplitViewControllerColumn.Secondary);
|
|
461
|
+
state.originalRootViewController = rootViewController;
|
|
462
|
+
state.splitViewController = splitViewController;
|
|
463
|
+
window.rootViewController = splitViewController;
|
|
464
|
+
window.makeKeyAndVisible();
|
|
465
|
+
}
|
|
466
|
+
function applySidebarSnapshot(state) {
|
|
467
|
+
const { dataSource } = state;
|
|
468
|
+
if (!dataSource) return;
|
|
469
|
+
const snapshot$1 = NSDiffableDataSourceSnapshot.alloc().init();
|
|
470
|
+
snapshot$1.appendSectionsWithIdentifiers([sectionIdentifier]);
|
|
471
|
+
snapshot$1.appendItemsWithIdentifiersIntoSectionWithIdentifier(state.items.map((item) => item.id), sectionIdentifier);
|
|
472
|
+
dataSource.applySnapshotAnimatingDifferences(snapshot$1, true);
|
|
473
|
+
}
|
|
474
|
+
function applySidebarSelection(state) {
|
|
475
|
+
const { collectionView, selectedId } = state;
|
|
476
|
+
if (!collectionView || selectedId === void 0) return;
|
|
477
|
+
const itemIndex = state.items.findIndex((item) => item.id === selectedId);
|
|
478
|
+
if (itemIndex < 0) return;
|
|
479
|
+
const indexPath = NSIndexPath.indexPathForItemInSection(itemIndex, 0);
|
|
480
|
+
collectionView.selectItemAtIndexPathAnimatedScrollPosition(indexPath, false, UICollectionViewScrollPosition.None);
|
|
481
|
+
}
|
|
482
|
+
function applySidebarNavigator(props, ctx) {
|
|
483
|
+
const state = sidebarState();
|
|
484
|
+
state.items = props.items;
|
|
485
|
+
state.selectedId = props.selectedId;
|
|
486
|
+
state.emitSelect = props.onSelect ? (id) => ctx?.emit("onSelect", id) : void 0;
|
|
487
|
+
state.sidebarWidth = props.sidebarWidth ?? defaultSidebarWidth;
|
|
488
|
+
state.minimumSidebarWidth = props.minimumSidebarWidth ?? defaultMinimumSidebarWidth;
|
|
489
|
+
state.maximumSidebarWidth = props.maximumSidebarWidth ?? defaultMaximumSidebarWidth;
|
|
490
|
+
state.titleById = new Map(props.items.map((item) => [item.id, item.title]));
|
|
491
|
+
state.symbolById = new Map(props.items.filter((item) => Boolean(item.symbol)).map((item) => [item.id, item.symbol]));
|
|
492
|
+
installSidebarNavigator(state);
|
|
493
|
+
applySidebarSnapshot(state);
|
|
494
|
+
applySidebarSelection(state);
|
|
495
|
+
}
|
|
496
|
+
const NativeSidebarNavigator = require_native_runtime.ensureNativeScript().defineUIKitView({
|
|
497
|
+
name: "NativeSidebarNavigator",
|
|
498
|
+
layout: {
|
|
499
|
+
sizing: "fill",
|
|
500
|
+
defaultSize: {
|
|
501
|
+
width: 0,
|
|
502
|
+
height: 0
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
create(ctx) {
|
|
506
|
+
const view = UIView.new();
|
|
507
|
+
view.hidden = true;
|
|
508
|
+
applySidebarNavigator(ctx, ctx);
|
|
509
|
+
return view;
|
|
510
|
+
},
|
|
511
|
+
update(_view, props, _previousProps, ctx) {
|
|
512
|
+
applySidebarNavigator(props, ctx);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
function screenComponent(config) {
|
|
516
|
+
return typeof config === "function" ? config : config.screen;
|
|
517
|
+
}
|
|
518
|
+
function screenTitle(name, config) {
|
|
519
|
+
return typeof config === "function" ? name : config.title ?? name;
|
|
520
|
+
}
|
|
521
|
+
function screenSymbol(config) {
|
|
522
|
+
return typeof config === "function" ? void 0 : config.symbol;
|
|
523
|
+
}
|
|
524
|
+
function createSidebarNavigator(config) {
|
|
525
|
+
const context = (0, react.createContext)(MissingContext);
|
|
526
|
+
const items = Object.entries(config.screens).map(([name, screen]) => ({
|
|
527
|
+
id: name,
|
|
528
|
+
title: screenTitle(name, screen),
|
|
529
|
+
symbol: screenSymbol(screen)
|
|
530
|
+
}));
|
|
531
|
+
const sidebarWidth = config.sidebarWidth ?? defaultSidebarWidth;
|
|
532
|
+
function useNavigatorContext() {
|
|
533
|
+
const value = (0, react.useContext)(context);
|
|
534
|
+
if (value === MissingContext) throw new Error("Expected a Bleam sidebar navigation context");
|
|
535
|
+
return value;
|
|
536
|
+
}
|
|
537
|
+
function Navigator() {
|
|
538
|
+
const [routeName, setRouteName] = (0, react.useState)(config.initialRouteName);
|
|
539
|
+
const navigate = (0, react.useCallback)((name) => {
|
|
540
|
+
if (name in config.screens) setRouteName(name);
|
|
541
|
+
}, []);
|
|
542
|
+
const route = (0, react.useMemo)(() => ({ name: routeName }), [routeName]);
|
|
543
|
+
const navigation = (0, react.useMemo)(() => ({
|
|
544
|
+
route,
|
|
545
|
+
navigate
|
|
546
|
+
}), [route, navigate]);
|
|
547
|
+
const value = (0, react.useMemo)(() => ({
|
|
548
|
+
route,
|
|
549
|
+
navigation
|
|
550
|
+
}), [route, navigation]);
|
|
551
|
+
const activeScreen = config.screens[routeName];
|
|
552
|
+
const ActiveScreen = activeScreen ? screenComponent(activeScreen) : void 0;
|
|
553
|
+
(0, react.useEffect)(() => {
|
|
554
|
+
setSafeAreaContribution(sidebarSafeAreaSource, { left: sidebarWidth });
|
|
555
|
+
return () => {
|
|
556
|
+
clearSafeAreaContribution(sidebarSafeAreaSource);
|
|
557
|
+
};
|
|
558
|
+
}, []);
|
|
559
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(context.Provider, {
|
|
560
|
+
value,
|
|
561
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
|
|
562
|
+
style: [{
|
|
563
|
+
flex: 1,
|
|
564
|
+
paddingLeft: sidebarWidth
|
|
565
|
+
}, config.style],
|
|
566
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(NativeSidebarNavigator, {
|
|
567
|
+
items,
|
|
568
|
+
selectedId: routeName,
|
|
569
|
+
sidebarWidth,
|
|
570
|
+
minimumSidebarWidth: config.minimumSidebarWidth,
|
|
571
|
+
maximumSidebarWidth: config.maximumSidebarWidth,
|
|
572
|
+
onSelect: (name) => {
|
|
573
|
+
if (name in config.screens) navigate(name);
|
|
574
|
+
}
|
|
575
|
+
}), ActiveScreen ? (0, react.createElement)(ActiveScreen, {}) : null]
|
|
576
|
+
})
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
function useNavigation() {
|
|
580
|
+
return useNavigatorContext().navigation;
|
|
581
|
+
}
|
|
582
|
+
function useRoute() {
|
|
583
|
+
return useNavigatorContext().route;
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
Navigator,
|
|
587
|
+
useNavigation,
|
|
588
|
+
useRoute
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
//#endregion
|
|
593
|
+
exports.Toolbar = Toolbar;
|
|
594
|
+
exports.Window = Window;
|
|
595
|
+
exports.createSidebarNavigator = createSidebarNavigator;
|
|
596
|
+
exports.useSafeAreaInsets = useSafeAreaInsets;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { p as SymbolName } from "./ui-1WepaMS4.cjs";
|
|
2
|
+
import * as react3 from "react";
|
|
3
|
+
import { ComponentType } from "react";
|
|
4
|
+
import { StyleProp, ViewStyle } from "react-native";
|
|
5
|
+
|
|
6
|
+
//#region src/chrome.d.ts
|
|
7
|
+
type HexColor = `#${string}`;
|
|
8
|
+
type WindowToolbarStyle = 'automatic' | 'unified' | 'unifiedCompact' | 'preference' | 'expanded';
|
|
9
|
+
type WindowTitleVisibility = 'visible' | 'hidden';
|
|
10
|
+
type WindowUserInterfaceStyle = 'automatic' | 'light' | 'dark';
|
|
11
|
+
type WindowProps = {
|
|
12
|
+
title?: string;
|
|
13
|
+
tint?: HexColor;
|
|
14
|
+
backgroundColor?: HexColor;
|
|
15
|
+
userInterfaceStyle?: WindowUserInterfaceStyle;
|
|
16
|
+
titleVisibility?: WindowTitleVisibility;
|
|
17
|
+
};
|
|
18
|
+
type ToolbarProps = {
|
|
19
|
+
toolbarStyle?: WindowToolbarStyle;
|
|
20
|
+
};
|
|
21
|
+
declare function Window(props: WindowProps): null;
|
|
22
|
+
declare function Toolbar(props: ToolbarProps): null;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/safe-area.d.ts
|
|
25
|
+
type SafeAreaInsets = {
|
|
26
|
+
top: number;
|
|
27
|
+
right: number;
|
|
28
|
+
bottom: number;
|
|
29
|
+
left: number;
|
|
30
|
+
};
|
|
31
|
+
declare function useSafeAreaInsets(): SafeAreaInsets;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/navigation.d.ts
|
|
34
|
+
type RouteName = string;
|
|
35
|
+
type ScreenComponent = ComponentType<Record<string, never>>;
|
|
36
|
+
type SidebarScreenConfig = ScreenComponent | {
|
|
37
|
+
screen: ScreenComponent;
|
|
38
|
+
title?: string;
|
|
39
|
+
symbol?: SymbolName;
|
|
40
|
+
};
|
|
41
|
+
type SidebarScreenMap = Record<RouteName, SidebarScreenConfig>;
|
|
42
|
+
type SidebarRouteState<Routes extends SidebarScreenMap> = {
|
|
43
|
+
name: Extract<keyof Routes, string>;
|
|
44
|
+
};
|
|
45
|
+
type SidebarNavigation<Routes extends SidebarScreenMap> = {
|
|
46
|
+
route: SidebarRouteState<Routes>;
|
|
47
|
+
navigate(name: Extract<keyof Routes, string>): void;
|
|
48
|
+
};
|
|
49
|
+
type SidebarNavigatorConfig<Routes extends SidebarScreenMap> = {
|
|
50
|
+
initialRouteName: Extract<keyof Routes, string>;
|
|
51
|
+
screens: Routes;
|
|
52
|
+
sidebarWidth?: number;
|
|
53
|
+
minimumSidebarWidth?: number;
|
|
54
|
+
maximumSidebarWidth?: number;
|
|
55
|
+
style?: StyleProp<ViewStyle>;
|
|
56
|
+
};
|
|
57
|
+
declare function createSidebarNavigator<const Routes extends SidebarScreenMap>(config: SidebarNavigatorConfig<Routes>): {
|
|
58
|
+
Navigator: () => react3.JSX.Element;
|
|
59
|
+
useNavigation: () => SidebarNavigation<Routes>;
|
|
60
|
+
useRoute: () => SidebarRouteState<Routes>;
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { type HexColor, type SafeAreaInsets, type SidebarNavigatorConfig, Toolbar, type ToolbarProps, Window, type WindowProps, type WindowTitleVisibility, type WindowToolbarStyle, type WindowUserInterfaceStyle, createSidebarNavigator, useSafeAreaInsets };
|