paseo-plugin-genui 0.0.0-stage → 0.1.0
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/LICENSE +202 -0
- package/OVERVIEW.md +21 -0
- package/README.md +77 -2
- package/assets/fonts/Excalifont-OFL.txt +109 -0
- package/assets/fonts/Excalifont-Regular-latin.woff2 +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +1 -0
- package/assets/screenshot-chat.png +0 -0
- package/assets/screenshot-gallery.png +0 -0
- package/assets/screenshot-playground.png +0 -0
- package/client/components/content.tsx +468 -0
- package/client/components/data.tsx +967 -0
- package/client/components/dev.tsx +998 -0
- package/client/components/diagram.tsx +513 -0
- package/client/components/inputs.tsx +994 -0
- package/client/components/layout.tsx +239 -0
- package/client/components/media.tsx +428 -0
- package/client/components/project.tsx +641 -0
- package/client/components/widgets.tsx +836 -0
- package/client/gallery.tsx +449 -0
- package/client/live-ui.tsx +525 -0
- package/client/loaders.ts +342 -0
- package/client/markdown.tsx +172 -0
- package/client/node-renderer.tsx +149 -0
- package/client/render.tsx +186 -0
- package/client/runtime.ts +103 -0
- package/client/settings.tsx +57 -0
- package/client/web.ts +186 -0
- package/gallery/Acceptance-baseline.ui +1 -0
- package/gallery/Acceptance-checklist.ui +14 -0
- package/gallery/Acceptance-evidence.ui +9 -0
- package/gallery/Acceptance.ui +1 -0
- package/gallery/Badge.ui +3 -0
- package/gallery/Benchmark-context.ui +8 -0
- package/gallery/Benchmark-hyperfine.ui +1 -0
- package/gallery/Benchmark-runs-list.ui +9 -0
- package/gallery/Benchmark-runs.ui +1 -0
- package/gallery/Benchmark-vitest.ui +1 -0
- package/gallery/Benchmark.ui +9 -0
- package/gallery/Board-bb-tasks.ui +1 -0
- package/gallery/Board-gh-issues.ui +1 -0
- package/gallery/Board-gh-prs.ui +1 -0
- package/gallery/Board.ui +12 -0
- package/gallery/Button-destructive.ui +4 -0
- package/gallery/Button.ui +5 -0
- package/gallery/Calendar.ui +15 -0
- package/gallery/CalendarHeatmap-short.ui +11 -0
- package/gallery/CalendarHeatmap.ui +4 -0
- package/gallery/Callout.ui +4 -0
- package/gallery/Card.ui +4 -0
- package/gallery/Carousel.ui +8 -0
- package/gallery/Changes-paths.ui +1 -0
- package/gallery/Changes-uncommitted.ui +1 -0
- package/gallery/Changes.ui +1 -0
- package/gallery/Chart-area.ui +3 -0
- package/gallery/Chart-funnel.ui +3 -0
- package/gallery/Chart-heatmap.ui +11 -0
- package/gallery/Chart-pie.ui +3 -0
- package/gallery/Chart-radar.ui +3 -0
- package/gallery/Chart-scatter.ui +4 -0
- package/gallery/Chart-stacked.ui +5 -0
- package/gallery/Chart.ui +3 -0
- package/gallery/Checklist.ui +6 -0
- package/gallery/Choice.ui +8 -0
- package/gallery/Code.ui +3 -0
- package/gallery/Commits-limit.ui +1 -0
- package/gallery/Commits.ui +1 -0
- package/gallery/Compare-conditions.ui +4 -0
- package/gallery/Compare-three.ui +7 -0
- package/gallery/Compare.ui +4 -0
- package/gallery/Coverage-go.ui +1 -0
- package/gallery/Coverage-lcov.ui +1 -0
- package/gallery/Coverage-python.ui +1 -0
- package/gallery/Coverage.ui +1 -0
- package/gallery/DateInput.ui +5 -0
- package/gallery/Decision-percent.ui +10 -0
- package/gallery/Decision.ui +12 -0
- package/gallery/Dependencies-audit.ui +1 -0
- package/gallery/Dependencies-both.ui +1 -0
- package/gallery/Dependencies-list.ui +7 -0
- package/gallery/Dependencies-pip.ui +1 -0
- package/gallery/Dependencies-pnpm.ui +1 -0
- package/gallery/Dependencies.ui +1 -0
- package/gallery/Details.ui +4 -0
- package/gallery/Diagram-flow.ui +16 -0
- package/gallery/Diagram-sequence.ui +15 -0
- package/gallery/Diagram.ui +16 -0
- package/gallery/Diff.ui +3 -0
- package/gallery/Divider.ui +5 -0
- package/gallery/EditableTable.ui +9 -0
- package/gallery/Entity-list.ui +6 -0
- package/gallery/Entity.ui +8 -0
- package/gallery/Environments.ui +1 -0
- package/gallery/Estimate-points.ui +6 -0
- package/gallery/Estimate.ui +8 -0
- package/gallery/File.ui +4 -0
- package/gallery/Findings-biome.ui +1 -0
- package/gallery/Findings-eslint.ui +1 -0
- package/gallery/Findings-oxlint.ui +1 -0
- package/gallery/Findings-review.ui +1 -0
- package/gallery/Findings-ruff.ui +1 -0
- package/gallery/Findings-sarif.ui +1 -0
- package/gallery/Findings-ship.ui +11 -0
- package/gallery/Findings-tsc.ui +1 -0
- package/gallery/Findings.ui +7 -0
- package/gallery/Flashcards.ui +3 -0
- package/gallery/FollowUps.ui +4 -0
- package/gallery/Form.ui +8 -0
- package/gallery/Gallery-links.ui +8 -0
- package/gallery/Gallery-strip.ui +14 -0
- package/gallery/Gallery.ui +10 -0
- package/gallery/Gauge.ui +7 -0
- package/gallery/Grid.ui +8 -0
- package/gallery/Hotspots-photo.ui +8 -0
- package/gallery/Hotspots.ui +11 -0
- package/gallery/Icon.ui +5 -0
- package/gallery/Image.ui +4 -0
- package/gallery/ImageSearch-aspects.ui +6 -0
- package/gallery/ImageSearch.ui +4 -0
- package/gallery/Input.ui +5 -0
- package/gallery/Json-api.ui +1 -0
- package/gallery/Json.ui +8 -0
- package/gallery/KeyValue.ui +3 -0
- package/gallery/List-dots.ui +8 -0
- package/gallery/List.ui +8 -0
- package/gallery/ListEditor.ui +5 -0
- package/gallery/Logs-jsonl.ui +1 -0
- package/gallery/Logs-lines.ui +11 -0
- package/gallery/Logs-python.ui +1 -0
- package/gallery/Logs.ui +1 -0
- package/gallery/Map-city.ui +8 -0
- package/gallery/Map.ui +8 -0
- package/gallery/Metric.ui +3 -0
- package/gallery/OptionCards-multi.ui +10 -0
- package/gallery/OptionCards.ui +10 -0
- package/gallery/Pipeline-checks.ui +1 -0
- package/gallery/Pipeline-passed.ui +1 -0
- package/gallery/Pipeline-running.ui +1 -0
- package/gallery/Pipeline-stages.ui +13 -0
- package/gallery/Pipeline.ui +1 -0
- package/gallery/Plan.ui +9 -0
- package/gallery/Progress.ui +4 -0
- package/gallery/Provenance-deploy.ui +6 -0
- package/gallery/Provenance-no-receipt.ui +1 -0
- package/gallery/Provenance.ui +1 -0
- package/gallery/PullRequest.ui +1 -0
- package/gallery/Quiz.ui +6 -0
- package/gallery/Radio.ui +5 -0
- package/gallery/Rating.ui +5 -0
- package/gallery/Roadmap-sprint.ui +8 -0
- package/gallery/Roadmap-year.ui +9 -0
- package/gallery/Roadmap.ui +12 -0
- package/gallery/Row.ui +3 -0
- package/gallery/SegmentedBar-status.ui +8 -0
- package/gallery/SegmentedBar.ui +8 -0
- package/gallery/Select.ui +5 -0
- package/gallery/Slider.ui +7 -0
- package/gallery/Snippet.ui +3 -0
- package/gallery/Sources-chips.ui +4 -0
- package/gallery/Sources.ui +8 -0
- package/gallery/Sparkline.ui +6 -0
- package/gallery/Stack.ui +7 -0
- package/gallery/StackTrace-aggregate.ui +1 -0
- package/gallery/StackTrace-browser.ui +1 -0
- package/gallery/StackTrace-go.ui +1 -0
- package/gallery/StackTrace-java.ui +1 -0
- package/gallery/StackTrace-python.ui +1 -0
- package/gallery/StackTrace-rust.ui +1 -0
- package/gallery/StackTrace.ui +1 -0
- package/gallery/Status.ui +9 -0
- package/gallery/Stepper.ui +5 -0
- package/gallery/Steps.ui +8 -0
- package/gallery/Swatches-long-names.ui +4 -0
- package/gallery/Swatches-picker.ui +5 -0
- package/gallery/Swatches.ui +10 -0
- package/gallery/Table.ui +7 -0
- package/gallery/Tabs.ui +8 -0
- package/gallery/Tests-junit.ui +1 -0
- package/gallery/Tests-vitest-junit.ui +1 -0
- package/gallery/Tests-vitest.ui +1 -0
- package/gallery/Tests.ui +9 -0
- package/gallery/Text.ui +4 -0
- package/gallery/TextArea.ui +5 -0
- package/gallery/Threads-ids.ui +1 -0
- package/gallery/Threads.ui +1 -0
- package/gallery/Timeline.ui +8 -0
- package/gallery/Timer.ui +4 -0
- package/gallery/Toggle.ui +5 -0
- package/gallery/Transcript-text.ui +1 -0
- package/gallery/Transcript-untimed.ui +1 -0
- package/gallery/Transcript-whisper.ui +1 -0
- package/gallery/Transcript.ui +1 -0
- package/gallery/Tree.ui +3 -0
- package/gallery/Treemap-du.ui +1 -0
- package/gallery/Treemap-esbuild.ui +1 -0
- package/gallery/Treemap-tree.ui +7 -0
- package/gallery/Treemap.ui +18 -0
- package/gallery/Walkthrough.ui +9 -0
- package/gallery/Waterfall-har.ui +1 -0
- package/gallery/Waterfall-trace.ui +1 -0
- package/gallery/Waterfall.ui +11 -0
- package/gallery/data/acceptance/coil/viewport-lifecycle.json +25 -0
- package/gallery/data/acceptance/coil-gate.json +153 -0
- package/gallery/data/acceptance/orbit-baseline.json +163 -0
- package/gallery/data/acceptance/shots/gate-cell-opened.png +0 -0
- package/gallery/data/acceptance/shots/gate-light.png +0 -0
- package/gallery/data/acceptance/shots/gate-phone-dark.png +0 -0
- package/gallery/data/activity.json +1 -0
- package/gallery/data/bb-tasks-orb.json +420 -0
- package/gallery/data/biome.json +229 -0
- package/gallery/data/compare/status-after.png +0 -0
- package/gallery/data/compare/status-before.png +0 -0
- package/gallery/data/compare/status-dark-2x.png +0 -0
- package/gallery/data/compare/status-rerender.png +0 -0
- package/gallery/data/coverage-py.json +1 -0
- package/gallery/data/coverage-summary.json +1 -0
- package/gallery/data/coverage.out +23 -0
- package/gallery/data/deploys.json +1 -0
- package/gallery/data/device-runs.json +285 -0
- package/gallery/data/du-node-modules.txt +359 -0
- package/gallery/data/esbuild-meta.json +292 -0
- package/gallery/data/eslint.json +266 -0
- package/gallery/data/eslint.sarif +343 -0
- package/gallery/data/findings-review.json +76 -0
- package/gallery/data/gh-issues-nextjs.json +293 -0
- package/gallery/data/gh-pr-checks.json +272 -0
- package/gallery/data/gh-prs-nextjs.json +419 -0
- package/gallery/data/gh-run-failed.json +1 -0
- package/gallery/data/gh-run-passed.json +1 -0
- package/gallery/data/gh-run-running.json +1 -0
- package/gallery/data/github-release.json +57 -0
- package/gallery/data/hyperfine-startup.json +187 -0
- package/gallery/data/lcov.info +234 -0
- package/gallery/data/logs/media-sync.log +127 -0
- package/gallery/data/logs/thumbnailer.jsonl +17 -0
- package/gallery/data/logs/vitest-run.log +89 -0
- package/gallery/data/npm-audit.json +672 -0
- package/gallery/data/npm-outdated.json +179 -0
- package/gallery/data/oxlint.json +156 -0
- package/gallery/data/pip-outdated.json +68 -0
- package/gallery/data/pnpm-outdated.json +58 -0
- package/gallery/data/provenance/devicectl-install.json +35 -0
- package/gallery/data/provenance/install-timeout.log +4 -0
- package/gallery/data/provenance/iphone-install.json +72 -0
- package/gallery/data/provenance/iphone-no-receipt.json +57 -0
- package/gallery/data/provenance/live-home.jpg +0 -0
- package/gallery/data/provenance/live-probe.txt +10 -0
- package/gallery/data/provenance/xcodebuild-2811.log +19 -0
- package/gallery/data/provenance/xcodebuild-4712.log +19 -0
- package/gallery/data/pytest-junit.xml +64 -0
- package/gallery/data/python-org-trace.json +35 -0
- package/gallery/data/python-org.har +31 -0
- package/gallery/data/retry.ts +13 -0
- package/gallery/data/ruff.json +261 -0
- package/gallery/data/src/durations.py +63 -0
- package/gallery/data/src/json-logic.ts +156 -0
- package/gallery/data/src/mapMath.ts +135 -0
- package/gallery/data/src/semver/bump.go +73 -0
- package/gallery/data/traces/browser-error.json +5 -0
- package/gallery/data/traces/go/main.go +27 -0
- package/gallery/data/traces/go-panic.txt +16 -0
- package/gallery/data/traces/java-caused-by.txt +15 -0
- package/gallery/data/traces/node-aggregate.txt +30 -0
- package/gallery/data/traces/node-cause.txt +21 -0
- package/gallery/data/traces/py/deploy.json +5 -0
- package/gallery/data/traces/py/deploy.py +17 -0
- package/gallery/data/traces/py/settings.py +19 -0
- package/gallery/data/traces/python-chain.txt +30 -0
- package/gallery/data/traces/rust/main.rs +11 -0
- package/gallery/data/traces/rust-panic.txt +16 -0
- package/gallery/data/traces/shop/cart.mjs +19 -0
- package/gallery/data/traces/shop/pricing.mjs +12 -0
- package/gallery/data/traces/shop/status.mjs +9 -0
- package/gallery/data/traces/web/app.js +11 -0
- package/gallery/data/traces/web/index.html +1 -0
- package/gallery/data/traces/web/search.js +10 -0
- package/gallery/data/transcript/call-noisy.wav +0 -0
- package/gallery/data/transcript/call.json +362 -0
- package/gallery/data/transcript/call.wav +0 -0
- package/gallery/data/transcript/mlx-whisper-tiny.en-noisy.json +1 -0
- package/gallery/data/transcript/whisper-cpp-base.en-noisy.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.srt +16 -0
- package/gallery/data/transcript/whisper-cpp-tiny.en-noisy.json +619 -0
- package/gallery/data/tsc.txt +4 -0
- package/gallery/data/vitest-bench.json +119 -0
- package/gallery/data/vitest-junit.xml +133 -0
- package/gallery/data/vitest-report.json +612 -0
- package/gallery/images/bell.svg +10 -0
- package/gallery/images/bike.svg +47 -0
- package/gallery/images/footer-planet.webp +0 -0
- package/gallery/images/front-light.svg +13 -0
- package/gallery/images/golden-hour.webp +0 -0
- package/gallery/images/option-flowers.webp +0 -0
- package/gallery/images/option-hilltop.webp +0 -0
- package/gallery/images/option-meadow.webp +0 -0
- package/gallery/images/option-sky.webp +0 -0
- package/gallery/images/u-lock.svg +10 -0
- package/index.client.tsx +164 -0
- package/index.server.ts +216 -0
- package/package.json +50 -4
- package/paseo-plugin.json +14 -0
- package/server/data-source.ts +407 -0
- package/server/project.ts +981 -0
- package/server/web/address.ts +57 -0
- package/server/web/cache.ts +85 -0
- package/server/web/commons.ts +126 -0
- package/server/web/geocode.ts +40 -0
- package/server/web/image.ts +35 -0
- package/server/web/lookups.ts +248 -0
- package/server/web/net.ts +210 -0
- package/shared/core/acceptance.ts +744 -0
- package/shared/core/ast.ts +76 -0
- package/shared/core/benchmark.ts +743 -0
- package/shared/core/catalog.ts +733 -0
- package/shared/core/compare.ts +225 -0
- package/shared/core/coverage.ts +456 -0
- package/shared/core/data.ts +334 -0
- package/shared/core/decisions.ts +527 -0
- package/shared/core/dependencies.ts +604 -0
- package/shared/core/diagnostics.ts +24 -0
- package/shared/core/environments.ts +212 -0
- package/shared/core/evaluate.ts +737 -0
- package/shared/core/fields.ts +66 -0
- package/shared/core/findings.ts +1172 -0
- package/shared/core/form.ts +69 -0
- package/shared/core/index.ts +44 -0
- package/shared/core/junit.ts +252 -0
- package/shared/core/lexer.ts +275 -0
- package/shared/core/logs.ts +496 -0
- package/shared/core/markdown.ts +2374 -0
- package/shared/core/parser.ts +355 -0
- package/shared/core/perf-units.ts +228 -0
- package/shared/core/pipeline.ts +679 -0
- package/shared/core/project.ts +472 -0
- package/shared/core/provenance.ts +725 -0
- package/shared/core/stack-trace.ts +718 -0
- package/shared/core/streaming.ts +136 -0
- package/shared/core/test-results.ts +562 -0
- package/shared/core/thread-activity.ts +203 -0
- package/shared/core/tracking.ts +887 -0
- package/shared/core/transcript.ts +1364 -0
- package/shared/core/treemap.ts +446 -0
- package/shared/core/types.ts +70 -0
- package/shared/core/validate.ts +574 -0
- package/shared/core/waterfall.ts +536 -0
- package/shared/diagram/flowchart.ts +205 -0
- package/shared/diagram/layout.ts +440 -0
- package/shared/diagram/markdown.ts +135 -0
- package/shared/diagram/sequence.ts +122 -0
- package/shared/diagram/zoom.ts +114 -0
- package/shared/fallback.ts +120 -0
- package/shared/genui.test.ts +122 -0
- package/shared/instructions.ts +144 -0
- package/shared/logic/calendarMath.ts +130 -0
- package/shared/logic/chartMath.ts +289 -0
- package/shared/logic/choose-logic.ts +196 -0
- package/shared/logic/compare-logic.ts +270 -0
- package/shared/logic/content-model.ts +227 -0
- package/shared/logic/environments-logic.ts +53 -0
- package/shared/logic/explain-logic.ts +315 -0
- package/shared/logic/fieldLogic.ts +138 -0
- package/shared/logic/gallery-search.ts +71 -0
- package/shared/logic/icons.ts +322 -0
- package/shared/logic/json-logic.ts +153 -0
- package/shared/logic/mapMath.ts +133 -0
- package/shared/logic/project-logic.ts +39 -0
- package/shared/logic/references-model.ts +201 -0
- package/shared/logic/sketch.ts +165 -0
- package/shared/logic/supersession.ts +77 -0
- package/shared/logic/values.ts +133 -0
- package/shared/logic/widget-logic.ts +163 -0
- package/shared/rpc.ts +252 -0
- package/shared/segment.ts +81 -0
- package/shared/settings.ts +12 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { collectLoads, dataKey, type DataRequest, type LoadedData, type Program } from "../shared/core";
|
|
4
|
+
import type { EnvironmentDetailResult } from "../shared/core/environments";
|
|
5
|
+
import type {
|
|
6
|
+
ChangesResult,
|
|
7
|
+
CommitsResult,
|
|
8
|
+
EnvironmentsResult,
|
|
9
|
+
PatchesResult,
|
|
10
|
+
PullRequestResult,
|
|
11
|
+
ThreadsResult,
|
|
12
|
+
} from "../shared/core/project";
|
|
13
|
+
import {
|
|
14
|
+
galleryAudioRpc,
|
|
15
|
+
galleryDataRpc,
|
|
16
|
+
galleryImageRpc,
|
|
17
|
+
loadAudioRpc,
|
|
18
|
+
loadDataRpc,
|
|
19
|
+
loadImageRpc,
|
|
20
|
+
projectChangesRpc,
|
|
21
|
+
projectCommitsRpc,
|
|
22
|
+
projectEnvironmentRpc,
|
|
23
|
+
projectEnvironmentsRpc,
|
|
24
|
+
projectPatchesRpc,
|
|
25
|
+
projectPullRequestRpc,
|
|
26
|
+
projectThreadsRpc,
|
|
27
|
+
webGeocodeRpc,
|
|
28
|
+
webImageRpc,
|
|
29
|
+
webSearchRpc,
|
|
30
|
+
webTileRpc,
|
|
31
|
+
type FoundImage,
|
|
32
|
+
type Located,
|
|
33
|
+
} from "../shared/rpc";
|
|
34
|
+
import type { ImageUrl, TextFile } from "./runtime";
|
|
35
|
+
|
|
36
|
+
export type FileScope = { readonly agentId: string } | "gallery";
|
|
37
|
+
|
|
38
|
+
type LoadedMedia = { ok: true; dataUrl: string } | { ok: false; error: string; off?: boolean };
|
|
39
|
+
|
|
40
|
+
interface Loaders {
|
|
41
|
+
data(path: string, raw: boolean | undefined): Promise<LoadedData>;
|
|
42
|
+
image(path: string): Promise<LoadedMedia>;
|
|
43
|
+
audio(path: string): Promise<LoadedMedia>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const LOADED_CACHE = new Map<string, LoadedData>();
|
|
47
|
+
const MAX_LOADED = 200;
|
|
48
|
+
|
|
49
|
+
function rememberLoaded(key: string, loaded: LoadedData): void {
|
|
50
|
+
if (!loaded.ok) return;
|
|
51
|
+
LOADED_CACHE.delete(key);
|
|
52
|
+
LOADED_CACHE.set(key, loaded);
|
|
53
|
+
if (LOADED_CACHE.size > MAX_LOADED) {
|
|
54
|
+
const first = LOADED_CACHE.keys().next().value;
|
|
55
|
+
if (first !== undefined) LOADED_CACHE.delete(first);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function useLoaders(scope: FileScope): Loaders {
|
|
60
|
+
const loadData = useRpc(loadDataRpc);
|
|
61
|
+
const loadImage = useRpc(loadImageRpc);
|
|
62
|
+
const loadAudio = useRpc(loadAudioRpc);
|
|
63
|
+
const galleryData = useRpc(galleryDataRpc);
|
|
64
|
+
const galleryImage = useRpc(galleryImageRpc);
|
|
65
|
+
const galleryAudio = useRpc(galleryAudioRpc);
|
|
66
|
+
const webImage = useRpc(webImageRpc);
|
|
67
|
+
|
|
68
|
+
const agentId = scope === "gallery" ? null : scope.agentId;
|
|
69
|
+
|
|
70
|
+
return useMemo(() => {
|
|
71
|
+
const fileImage: Loaders["image"] =
|
|
72
|
+
agentId === null
|
|
73
|
+
? (path) => galleryImage({ path })
|
|
74
|
+
: (path) => loadImage({ agentId, path });
|
|
75
|
+
return {
|
|
76
|
+
data:
|
|
77
|
+
agentId === null
|
|
78
|
+
? (path, raw) => galleryData({ path, raw })
|
|
79
|
+
: (path, raw) => loadData({ agentId, path, raw }),
|
|
80
|
+
image: (src) => (/^https?:\/\//i.test(src) ? webImage({ url: src }) : fileImage(src)),
|
|
81
|
+
audio:
|
|
82
|
+
agentId === null
|
|
83
|
+
? (path) => galleryAudio({ path })
|
|
84
|
+
: (path) => loadAudio({ agentId, path }),
|
|
85
|
+
};
|
|
86
|
+
}, [agentId, galleryAudio, galleryData, galleryImage, loadAudio, loadData, loadImage, webImage]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function useLoadedData(scope: FileScope, program: Program | null): ReadonlyMap<string, LoadedData> {
|
|
90
|
+
const loaders = useLoaders(scope);
|
|
91
|
+
const scopeKey = scope === "gallery" ? "gallery" : scope.agentId;
|
|
92
|
+
const requestsKey = useMemo(
|
|
93
|
+
() => (program === null ? "[]" : JSON.stringify(collectLoads(program))),
|
|
94
|
+
[program],
|
|
95
|
+
);
|
|
96
|
+
const [data, setData] = useState<ReadonlyMap<string, LoadedData>>(() => {
|
|
97
|
+
const found = new Map<string, LoadedData>();
|
|
98
|
+
for (const request of JSON.parse(requestsKey) as DataRequest[]) {
|
|
99
|
+
const hit = LOADED_CACHE.get(`${scopeKey}|${dataKey(request)}`);
|
|
100
|
+
if (hit !== undefined) found.set(dataKey(request), hit);
|
|
101
|
+
}
|
|
102
|
+
return found;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const requests = JSON.parse(requestsKey) as DataRequest[];
|
|
107
|
+
const missing = requests.filter((request) => !data.has(dataKey(request)));
|
|
108
|
+
if (missing.length === 0) return;
|
|
109
|
+
let live = true;
|
|
110
|
+
for (const request of missing) {
|
|
111
|
+
const key = dataKey(request);
|
|
112
|
+
loaders.data(request.path, request.raw).then(
|
|
113
|
+
(loaded) => {
|
|
114
|
+
rememberLoaded(`${scopeKey}|${key}`, loaded);
|
|
115
|
+
if (live) setData((previous) => new Map(previous).set(key, loaded));
|
|
116
|
+
},
|
|
117
|
+
(cause: unknown) => {
|
|
118
|
+
const error = cause instanceof Error ? cause.message : String(cause);
|
|
119
|
+
if (live) setData((previous) => new Map(previous).set(key, { ok: false, error }));
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return () => {
|
|
124
|
+
live = false;
|
|
125
|
+
};
|
|
126
|
+
}, [loaders, requestsKey, scopeKey]);
|
|
127
|
+
|
|
128
|
+
return data;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function useImageLoader(scope: FileScope): (src: string) => Promise<ImageUrl> {
|
|
132
|
+
const loaders = useLoaders(scope);
|
|
133
|
+
const images = useRef(new Map<string, Promise<ImageUrl>>());
|
|
134
|
+
return useCallback(
|
|
135
|
+
(src: string) => {
|
|
136
|
+
const cached = images.current.get(src);
|
|
137
|
+
if (cached !== undefined) return cached;
|
|
138
|
+
const pending = loaders.image(src).then(
|
|
139
|
+
(loaded): ImageUrl => (loaded.ok ? { ok: true, url: loaded.dataUrl } : loaded),
|
|
140
|
+
(cause: unknown): ImageUrl => ({
|
|
141
|
+
ok: false,
|
|
142
|
+
error: cause instanceof Error ? cause.message : String(cause),
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
images.current.set(src, pending);
|
|
146
|
+
void pending.then((image) => {
|
|
147
|
+
if (!image.ok) images.current.delete(src);
|
|
148
|
+
});
|
|
149
|
+
return pending;
|
|
150
|
+
},
|
|
151
|
+
[loaders],
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function useAudioLoader(scope: FileScope): (src: string) => Promise<ImageUrl> {
|
|
156
|
+
const loaders = useLoaders(scope);
|
|
157
|
+
const audios = useRef(new Map<string, Promise<ImageUrl>>());
|
|
158
|
+
return useCallback(
|
|
159
|
+
(src: string) => {
|
|
160
|
+
const cached = audios.current.get(src);
|
|
161
|
+
if (cached !== undefined) return cached;
|
|
162
|
+
const pending = loaders.audio(src).then(
|
|
163
|
+
(loaded): ImageUrl => (loaded.ok ? { ok: true, url: loaded.dataUrl } : loaded),
|
|
164
|
+
(cause: unknown): ImageUrl => ({
|
|
165
|
+
ok: false,
|
|
166
|
+
error: cause instanceof Error ? cause.message : String(cause),
|
|
167
|
+
}),
|
|
168
|
+
);
|
|
169
|
+
audios.current.set(src, pending);
|
|
170
|
+
void pending.then((audio) => {
|
|
171
|
+
if (!audio.ok) audios.current.delete(src);
|
|
172
|
+
});
|
|
173
|
+
return pending;
|
|
174
|
+
},
|
|
175
|
+
[loaders],
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function useTextLoader(scope: FileScope): (path: string) => Promise<TextFile> {
|
|
180
|
+
const loaders = useLoaders(scope);
|
|
181
|
+
const scopeKey = scope === "gallery" ? "gallery" : scope.agentId;
|
|
182
|
+
return useCallback(
|
|
183
|
+
async (path: string): Promise<TextFile> => {
|
|
184
|
+
const key = `${scopeKey}|${dataKey({ path, raw: true })}`;
|
|
185
|
+
const toText = (loaded: LoadedData): TextFile =>
|
|
186
|
+
!loaded.ok
|
|
187
|
+
? loaded
|
|
188
|
+
: typeof loaded.value === "string"
|
|
189
|
+
? { ok: true, text: loaded.value }
|
|
190
|
+
: { ok: false, error: `${path} is not a text file` };
|
|
191
|
+
const cached = LOADED_CACHE.get(key);
|
|
192
|
+
if (cached !== undefined) return toText(cached);
|
|
193
|
+
try {
|
|
194
|
+
const loaded = await loaders.data(path, true);
|
|
195
|
+
rememberLoaded(key, loaded);
|
|
196
|
+
return toText(loaded);
|
|
197
|
+
} catch (cause) {
|
|
198
|
+
return { ok: false, error: cause instanceof Error ? cause.message : String(cause) };
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
[loaders, scopeKey],
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export type SearchResult =
|
|
206
|
+
| { readonly ok: true; readonly image: FoundImage }
|
|
207
|
+
| { readonly ok: false; readonly error: string; readonly off?: boolean };
|
|
208
|
+
|
|
209
|
+
const searchCache = new Map<string, Promise<SearchResult>>();
|
|
210
|
+
|
|
211
|
+
export function useImageSearch(query: string): SearchResult | null {
|
|
212
|
+
const webSearch = useRpc(webSearchRpc);
|
|
213
|
+
const key = query.trim().replace(/\s+/g, " ").toLowerCase();
|
|
214
|
+
const [result, setResult] = useState<{ readonly key: string; readonly result: SearchResult } | null>(null);
|
|
215
|
+
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
if (key === "") return;
|
|
218
|
+
let live = true;
|
|
219
|
+
let pending = searchCache.get(key);
|
|
220
|
+
if (!pending) {
|
|
221
|
+
pending = webSearch({ query: key }).catch((cause: unknown) => ({
|
|
222
|
+
ok: false as const,
|
|
223
|
+
error: cause instanceof Error ? cause.message : String(cause),
|
|
224
|
+
}));
|
|
225
|
+
searchCache.set(key, pending);
|
|
226
|
+
void pending.then((res) => {
|
|
227
|
+
if (!res.ok) searchCache.delete(key);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
void pending.then((found) => {
|
|
231
|
+
if (live) setResult({ key, result: found });
|
|
232
|
+
});
|
|
233
|
+
return () => {
|
|
234
|
+
live = false;
|
|
235
|
+
};
|
|
236
|
+
}, [webSearch, key]);
|
|
237
|
+
|
|
238
|
+
return result !== null && result.key === key ? result.result : null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export type PlaceResult =
|
|
242
|
+
| { readonly ok: true; readonly lat: number; readonly lng: number }
|
|
243
|
+
| { readonly ok: false; readonly error: string; readonly off?: boolean };
|
|
244
|
+
|
|
245
|
+
const placeCache = new Map<string, Promise<PlaceResult>>();
|
|
246
|
+
|
|
247
|
+
export function useGeocodePlace() {
|
|
248
|
+
const webGeocode = useRpc(webGeocodeRpc);
|
|
249
|
+
return useCallback(
|
|
250
|
+
(name: string, near: Located | null): Promise<PlaceResult> => {
|
|
251
|
+
const bias = near === null ? "" : `${near.lat.toFixed(1)},${near.lng.toFixed(1)}`;
|
|
252
|
+
const key = `${name.trim().toLowerCase()}|${bias}`;
|
|
253
|
+
const existing = placeCache.get(key);
|
|
254
|
+
if (existing !== undefined) return existing;
|
|
255
|
+
const pending = webGeocode({ name: name.trim(), near }).catch((cause: unknown) => ({
|
|
256
|
+
ok: false as const,
|
|
257
|
+
error: cause instanceof Error ? cause.message : String(cause),
|
|
258
|
+
}));
|
|
259
|
+
placeCache.set(key, pending);
|
|
260
|
+
void pending.then((res) => {
|
|
261
|
+
if (!res.ok) placeCache.delete(key);
|
|
262
|
+
});
|
|
263
|
+
return pending;
|
|
264
|
+
},
|
|
265
|
+
[webGeocode],
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const tileCache = new Map<string, string>();
|
|
270
|
+
const tileRequests = new Map<string, Promise<{ readonly ok: true; readonly dataUrl: string } | { readonly ok: false; readonly error: string; readonly off?: boolean }>>();
|
|
271
|
+
|
|
272
|
+
export function useMapTileLoader() {
|
|
273
|
+
const webTile = useRpc(webTileRpc);
|
|
274
|
+
return useCallback(
|
|
275
|
+
async (z: number, x: number, y: number) => {
|
|
276
|
+
const key = `${z}/${x}/${y}`;
|
|
277
|
+
const known = tileCache.get(key);
|
|
278
|
+
if (known !== undefined) return { ok: true as const, dataUrl: known };
|
|
279
|
+
let pending = tileRequests.get(key);
|
|
280
|
+
if (!pending) {
|
|
281
|
+
pending = webTile({ z, x, y }).catch((cause: unknown) => ({
|
|
282
|
+
ok: false as const,
|
|
283
|
+
error: cause instanceof Error ? cause.message : String(cause),
|
|
284
|
+
}));
|
|
285
|
+
tileRequests.set(key, pending);
|
|
286
|
+
}
|
|
287
|
+
const res = await pending;
|
|
288
|
+
tileRequests.delete(key);
|
|
289
|
+
if (res.ok) {
|
|
290
|
+
tileCache.set(key, res.dataUrl);
|
|
291
|
+
if (tileCache.size > 400) {
|
|
292
|
+
const oldest = tileCache.keys().next().value;
|
|
293
|
+
if (oldest !== undefined) tileCache.delete(oldest);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return res;
|
|
297
|
+
},
|
|
298
|
+
[webTile],
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function useProjectRpc() {
|
|
303
|
+
const changes = useRpc(projectChangesRpc);
|
|
304
|
+
const patches = useRpc(projectPatchesRpc);
|
|
305
|
+
const commits = useRpc(projectCommitsRpc);
|
|
306
|
+
const pullRequest = useRpc(projectPullRequestRpc);
|
|
307
|
+
const threads = useRpc(projectThreadsRpc);
|
|
308
|
+
const environments = useRpc(projectEnvironmentsRpc);
|
|
309
|
+
const environment = useRpc(projectEnvironmentRpc);
|
|
310
|
+
|
|
311
|
+
return useMemo(
|
|
312
|
+
() => ({
|
|
313
|
+
changes: (input: {
|
|
314
|
+
agentId: string;
|
|
315
|
+
target: string | null;
|
|
316
|
+
paths: string[] | null;
|
|
317
|
+
blockKey: string | null;
|
|
318
|
+
refresh: boolean;
|
|
319
|
+
}): Promise<ChangesResult> => changes(input),
|
|
320
|
+
patches: (input: {
|
|
321
|
+
agentId: string;
|
|
322
|
+
target: string | null;
|
|
323
|
+
paths: string[];
|
|
324
|
+
}): Promise<PatchesResult> => patches(input),
|
|
325
|
+
commits: (input: {
|
|
326
|
+
agentId: string;
|
|
327
|
+
blockKey: string | null;
|
|
328
|
+
refresh: boolean;
|
|
329
|
+
}): Promise<CommitsResult> => commits(input),
|
|
330
|
+
pullRequest: (input: { agentId: string }): Promise<PullRequestResult> => pullRequest(input),
|
|
331
|
+
threads: (input: { agentId: string; ids: string[] | null }): Promise<ThreadsResult> =>
|
|
332
|
+
threads(input),
|
|
333
|
+
environments: (input: { agentId: string }): Promise<EnvironmentsResult> =>
|
|
334
|
+
environments(input),
|
|
335
|
+
environment: (input: {
|
|
336
|
+
agentId: string;
|
|
337
|
+
environmentId: string;
|
|
338
|
+
}): Promise<EnvironmentDetailResult> => environment(input),
|
|
339
|
+
}),
|
|
340
|
+
[changes, commits, environment, environments, patches, pullRequest, threads],
|
|
341
|
+
);
|
|
342
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
4
|
+
import { parseMarkdown, type Block, type Inline } from "../shared/diagram/markdown";
|
|
5
|
+
|
|
6
|
+
export function MarkdownText({
|
|
7
|
+
text,
|
|
8
|
+
theme,
|
|
9
|
+
compact = false,
|
|
10
|
+
color,
|
|
11
|
+
}: {
|
|
12
|
+
text: string;
|
|
13
|
+
theme: PluginTheme;
|
|
14
|
+
compact?: boolean;
|
|
15
|
+
color?: string;
|
|
16
|
+
}) {
|
|
17
|
+
const blocks = useMemo(() => parseMarkdown(text), [text]);
|
|
18
|
+
return (
|
|
19
|
+
<View style={{ gap: compact ? 6 : 8 }}>
|
|
20
|
+
{blocks.map((block, index) => (
|
|
21
|
+
<BlockView key={index} block={block} theme={theme} color={color} />
|
|
22
|
+
))}
|
|
23
|
+
</View>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function BlockView({
|
|
28
|
+
block,
|
|
29
|
+
theme,
|
|
30
|
+
color,
|
|
31
|
+
}: {
|
|
32
|
+
block: Block;
|
|
33
|
+
theme: PluginTheme;
|
|
34
|
+
color?: string;
|
|
35
|
+
}) {
|
|
36
|
+
const body = {
|
|
37
|
+
color: color ?? theme.colors.foreground,
|
|
38
|
+
fontSize: 13.5,
|
|
39
|
+
lineHeight: 20,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (block.kind === "rule") {
|
|
43
|
+
return (
|
|
44
|
+
<View
|
|
45
|
+
style={{
|
|
46
|
+
height: StyleSheet.hairlineWidth,
|
|
47
|
+
backgroundColor: theme.colors.border,
|
|
48
|
+
marginVertical: 4,
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (block.kind === "code") {
|
|
55
|
+
return (
|
|
56
|
+
<View
|
|
57
|
+
style={{
|
|
58
|
+
borderRadius: 8,
|
|
59
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
60
|
+
borderColor: theme.colors.border,
|
|
61
|
+
backgroundColor: theme.colors.surface2,
|
|
62
|
+
padding: 10,
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
<Text
|
|
66
|
+
selectable
|
|
67
|
+
style={{
|
|
68
|
+
color: theme.colors.foreground,
|
|
69
|
+
fontFamily: "monospace",
|
|
70
|
+
fontSize: 12,
|
|
71
|
+
lineHeight: 18,
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
{block.text}
|
|
75
|
+
</Text>
|
|
76
|
+
</View>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (block.kind === "heading") {
|
|
81
|
+
return (
|
|
82
|
+
<Text
|
|
83
|
+
selectable
|
|
84
|
+
style={{
|
|
85
|
+
...body,
|
|
86
|
+
fontSize: Math.max(14, 20 - block.level),
|
|
87
|
+
fontWeight: "700",
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
<Spans content={block.content} theme={theme} />
|
|
91
|
+
</Text>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (block.kind === "quote") {
|
|
96
|
+
return (
|
|
97
|
+
<View
|
|
98
|
+
style={{
|
|
99
|
+
borderLeftWidth: 2,
|
|
100
|
+
borderLeftColor: theme.colors.accent,
|
|
101
|
+
paddingLeft: 10,
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
<Text selectable style={{ ...body, color: theme.colors.foregroundMuted }}>
|
|
105
|
+
<Spans content={block.content} theme={theme} />
|
|
106
|
+
</Text>
|
|
107
|
+
</View>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (block.kind === "bullet" || block.kind === "ordered") {
|
|
112
|
+
return (
|
|
113
|
+
<View style={{ gap: 4 }}>
|
|
114
|
+
{block.items.map((item, index) => (
|
|
115
|
+
<View key={index} style={{ flexDirection: "row", gap: 8 }}>
|
|
116
|
+
<Text style={{ ...body, color: theme.colors.foregroundMuted }}>
|
|
117
|
+
{block.kind === "bullet" ? "•" : `${block.start + index}.`}
|
|
118
|
+
</Text>
|
|
119
|
+
<Text selectable style={{ ...body, flex: 1 }}>
|
|
120
|
+
<Spans content={item} theme={theme} />
|
|
121
|
+
</Text>
|
|
122
|
+
</View>
|
|
123
|
+
))}
|
|
124
|
+
</View>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<Text selectable style={body}>
|
|
130
|
+
<Spans content={block.content} theme={theme} />
|
|
131
|
+
</Text>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function Spans({ content, theme }: { content: Inline[]; theme: PluginTheme }) {
|
|
136
|
+
return (
|
|
137
|
+
<>
|
|
138
|
+
{content.map((span, index) => {
|
|
139
|
+
if (span.kind === "bold") {
|
|
140
|
+
return (
|
|
141
|
+
<Text key={index} style={{ fontWeight: "700" }}>
|
|
142
|
+
{span.text}
|
|
143
|
+
</Text>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
if (span.kind === "italic") {
|
|
147
|
+
return (
|
|
148
|
+
<Text key={index} style={{ fontStyle: "italic" }}>
|
|
149
|
+
{span.text}
|
|
150
|
+
</Text>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (span.kind === "code") {
|
|
154
|
+
return (
|
|
155
|
+
<Text
|
|
156
|
+
key={index}
|
|
157
|
+
style={{
|
|
158
|
+
fontFamily: "monospace",
|
|
159
|
+
fontSize: 12,
|
|
160
|
+
color: theme.colors.accent,
|
|
161
|
+
backgroundColor: theme.colors.surface2,
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{span.text}
|
|
165
|
+
</Text>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return <Text key={index}>{span.text}</Text>;
|
|
169
|
+
})}
|
|
170
|
+
</>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import React, { Component, type ComponentType, type ReactNode } from "react";
|
|
2
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import type { ComponentName } from "../shared/core/catalog";
|
|
4
|
+
import type { UiNode } from "../shared/core/types";
|
|
5
|
+
import { text, type Props } from "../shared/logic/values";
|
|
6
|
+
import { useUiRuntime } from "./runtime";
|
|
7
|
+
|
|
8
|
+
export interface GroupedButton {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly props: Props;
|
|
11
|
+
readonly element: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let renderersMap: Record<ComponentName, ComponentType<{ props: Props }>> | null = null;
|
|
15
|
+
let buttonGroupComponent: ComponentType<{ buttons: readonly GroupedButton[] }> | null = null;
|
|
16
|
+
|
|
17
|
+
export function registerRenderers(
|
|
18
|
+
map: Record<ComponentName, ComponentType<{ props: Props }>>,
|
|
19
|
+
buttonGroup: ComponentType<{ buttons: readonly GroupedButton[] }>,
|
|
20
|
+
): void {
|
|
21
|
+
renderersMap = map;
|
|
22
|
+
buttonGroupComponent = buttonGroup;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function ErrorLine({ message }: { message: string }) {
|
|
26
|
+
const { theme } = useUiRuntime();
|
|
27
|
+
return (
|
|
28
|
+
<View
|
|
29
|
+
style={{
|
|
30
|
+
borderRadius: 8,
|
|
31
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
32
|
+
borderColor: theme.colors.statusDanger,
|
|
33
|
+
backgroundColor: theme.colors.surface1,
|
|
34
|
+
paddingHorizontal: 10,
|
|
35
|
+
paddingVertical: 6,
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<Text selectable style={{ color: theme.colors.statusDanger, fontSize: 12 }}>
|
|
39
|
+
{message}
|
|
40
|
+
</Text>
|
|
41
|
+
</View>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function LoadingPlaceholder({
|
|
46
|
+
path,
|
|
47
|
+
component,
|
|
48
|
+
}: {
|
|
49
|
+
path: string;
|
|
50
|
+
component: string | null;
|
|
51
|
+
}) {
|
|
52
|
+
const { theme } = useUiRuntime();
|
|
53
|
+
return (
|
|
54
|
+
<View
|
|
55
|
+
style={{
|
|
56
|
+
borderRadius: 8,
|
|
57
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
58
|
+
borderColor: theme.colors.border,
|
|
59
|
+
backgroundColor: theme.colors.surface1,
|
|
60
|
+
paddingHorizontal: 12,
|
|
61
|
+
paddingVertical: 10,
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>
|
|
65
|
+
{component ? `Loading ${component} (${path})…` : `Loading ${path}…`}
|
|
66
|
+
</Text>
|
|
67
|
+
</View>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function RenderNode({ node }: { node: UiNode }): ReactNode {
|
|
72
|
+
if (node.type === "Error") return <ErrorLine message={text(node.props.message)} />;
|
|
73
|
+
if (node.type === "Loading") {
|
|
74
|
+
return (
|
|
75
|
+
<LoadingPlaceholder
|
|
76
|
+
path={text(node.props.path)}
|
|
77
|
+
component={typeof node.props.component === "string" ? node.props.component : null}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (!renderersMap) return null;
|
|
82
|
+
const Renderer = renderersMap[node.type];
|
|
83
|
+
return <Renderer props={node.props} />;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function RenderNodes({
|
|
87
|
+
nodes,
|
|
88
|
+
isolate = false,
|
|
89
|
+
}: {
|
|
90
|
+
nodes: readonly UiNode[];
|
|
91
|
+
isolate?: boolean;
|
|
92
|
+
}): ReactNode {
|
|
93
|
+
const seen = new Set<string>();
|
|
94
|
+
const out: ReactNode[] = [];
|
|
95
|
+
let run: GroupedButton[] | null = null;
|
|
96
|
+
const Group = buttonGroupComponent;
|
|
97
|
+
|
|
98
|
+
nodes.forEach((node, index) => {
|
|
99
|
+
const key = seen.has(node.key) ? `${node.key}@${index}` : node.key;
|
|
100
|
+
seen.add(node.key);
|
|
101
|
+
const element = isolate ? (
|
|
102
|
+
<NodeBoundary key={key} node={node}>
|
|
103
|
+
<RenderNode node={node} />
|
|
104
|
+
</NodeBoundary>
|
|
105
|
+
) : (
|
|
106
|
+
<RenderNode key={key} node={node} />
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (node.type !== "Button" || !Group) {
|
|
110
|
+
run = null;
|
|
111
|
+
out.push(element);
|
|
112
|
+
} else if (run === null) {
|
|
113
|
+
const buttons: GroupedButton[] = [{ key, props: node.props, element }];
|
|
114
|
+
run = buttons;
|
|
115
|
+
out.push(<Group key={`buttons:${key}`} buttons={buttons} />);
|
|
116
|
+
} else {
|
|
117
|
+
run.push({ key, props: node.props, element });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return <>{out}</>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
interface BoundaryProps {
|
|
125
|
+
node: UiNode;
|
|
126
|
+
children: ReactNode;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export class NodeBoundary extends Component<BoundaryProps, { error: string | null }> {
|
|
130
|
+
override state: { error: string | null } = { error: null };
|
|
131
|
+
|
|
132
|
+
static getDerivedStateFromError(cause: unknown): { error: string } {
|
|
133
|
+
return { error: cause instanceof Error ? cause.message : String(cause) };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
override componentDidUpdate(previous: BoundaryProps): void {
|
|
137
|
+
if (this.state.error !== null && previous.node !== this.props.node) {
|
|
138
|
+
this.setState({ error: null });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
override render(): ReactNode {
|
|
143
|
+
return this.state.error === null ? (
|
|
144
|
+
this.props.children
|
|
145
|
+
) : (
|
|
146
|
+
<ErrorLine message={this.state.error} />
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|