@agimon-ai/po-native-components 0.0.0-alpha.2 → 0.0.0-alpha.200
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 +1 -2
- package/README.md +9 -51
- package/dist/components/AgentAvatar.d.mts +19 -0
- package/dist/components/AgentAvatar.d.mts.map +1 -0
- package/dist/components/AgentAvatar.mjs +88 -0
- package/dist/components/AgentAvatar.mjs.map +1 -0
- package/dist/components/AnnotationSurface.d.mts +69 -0
- package/dist/components/AnnotationSurface.d.mts.map +1 -0
- package/dist/components/AnnotationSurface.mjs +431 -0
- package/dist/components/AnnotationSurface.mjs.map +1 -0
- package/dist/components/Badge.d.mts +1 -1
- package/dist/components/Badge.mjs +2 -2
- package/dist/components/Badge.mjs.map +1 -1
- package/dist/components/Button.mjs +4 -4
- package/dist/components/Button.mjs.map +1 -1
- package/dist/components/CodeBlock.d.mts +3 -1
- package/dist/components/CodeBlock.d.mts.map +1 -1
- package/dist/components/CodeBlock.mjs +42 -47
- package/dist/components/CodeBlock.mjs.map +1 -1
- package/dist/components/ComputerRow.d.mts +15 -0
- package/dist/components/ComputerRow.d.mts.map +1 -0
- package/dist/components/ComputerRow.mjs +107 -0
- package/dist/components/ComputerRow.mjs.map +1 -0
- package/dist/components/CopyButton.d.mts +13 -0
- package/dist/components/CopyButton.d.mts.map +1 -0
- package/dist/components/CopyButton.mjs +49 -0
- package/dist/components/CopyButton.mjs.map +1 -0
- package/dist/components/CountBadge.d.mts +15 -0
- package/dist/components/CountBadge.d.mts.map +1 -0
- package/dist/components/CountBadge.mjs +49 -0
- package/dist/components/CountBadge.mjs.map +1 -0
- package/dist/components/CtaCard.d.mts +19 -0
- package/dist/components/CtaCard.d.mts.map +1 -0
- package/dist/components/CtaCard.mjs +92 -0
- package/dist/components/CtaCard.mjs.map +1 -0
- package/dist/components/Dialog.d.mts +2 -2
- package/dist/components/Dialog.d.mts.map +1 -1
- package/dist/components/Dialog.mjs +18 -12
- package/dist/components/Dialog.mjs.map +1 -1
- package/dist/components/Dot.d.mts +1 -1
- package/dist/components/Dot.mjs +3 -3
- package/dist/components/Dot.mjs.map +1 -1
- package/dist/components/DropdownMenu.d.mts +3 -1
- package/dist/components/DropdownMenu.d.mts.map +1 -1
- package/dist/components/DropdownMenu.mjs +21 -14
- package/dist/components/DropdownMenu.mjs.map +1 -1
- package/dist/components/EmptyState.d.mts +31 -3
- package/dist/components/EmptyState.d.mts.map +1 -1
- package/dist/components/EmptyState.mjs +303 -29
- package/dist/components/EmptyState.mjs.map +1 -1
- package/dist/components/FileList.d.mts +46 -0
- package/dist/components/FileList.d.mts.map +1 -0
- package/dist/components/FileList.mjs +727 -0
- package/dist/components/FileList.mjs.map +1 -0
- package/dist/components/FilePreview.d.mts +33 -0
- package/dist/components/FilePreview.d.mts.map +1 -0
- package/dist/components/FilePreview.mjs +102 -0
- package/dist/components/FilePreview.mjs.map +1 -0
- package/dist/components/FileViewer.d.mts +57 -0
- package/dist/components/FileViewer.d.mts.map +1 -0
- package/dist/components/FileViewer.mjs +335 -0
- package/dist/components/FileViewer.mjs.map +1 -0
- package/dist/components/HashlineLines.d.mts +13 -0
- package/dist/components/HashlineLines.d.mts.map +1 -0
- package/dist/components/HashlineLines.mjs +153 -0
- package/dist/components/HashlineLines.mjs.map +1 -0
- package/dist/components/HostFilter.d.mts +17 -0
- package/dist/components/HostFilter.d.mts.map +1 -0
- package/dist/components/HostFilter.mjs +68 -0
- package/dist/components/HostFilter.mjs.map +1 -0
- package/dist/components/HostTag.d.mts +7 -0
- package/dist/components/HostTag.d.mts.map +1 -0
- package/dist/components/HostTag.mjs +48 -0
- package/dist/components/HostTag.mjs.map +1 -0
- package/dist/components/InfoStrip.d.mts +9 -0
- package/dist/components/InfoStrip.d.mts.map +1 -0
- package/dist/components/InfoStrip.mjs +53 -0
- package/dist/components/InfoStrip.mjs.map +1 -0
- package/dist/components/Input.d.mts +3 -1
- package/dist/components/Input.d.mts.map +1 -1
- package/dist/components/Input.mjs +5 -4
- package/dist/components/Input.mjs.map +1 -1
- package/dist/components/Label.mjs +1 -1
- package/dist/components/LinkText.d.mts +13 -0
- package/dist/components/LinkText.d.mts.map +1 -0
- package/dist/components/LinkText.mjs +32 -0
- package/dist/components/LinkText.mjs.map +1 -0
- package/dist/components/List.d.mts.map +1 -1
- package/dist/components/List.mjs +50 -11
- package/dist/components/List.mjs.map +1 -1
- package/dist/components/LiveDuration.d.mts +30 -0
- package/dist/components/LiveDuration.d.mts.map +1 -0
- package/dist/components/LiveDuration.mjs +67 -0
- package/dist/components/LiveDuration.mjs.map +1 -0
- package/dist/components/LoadingState.d.mts +17 -0
- package/dist/components/LoadingState.d.mts.map +1 -0
- package/dist/components/LoadingState.mjs +90 -0
- package/dist/components/LoadingState.mjs.map +1 -0
- package/dist/components/Markdown.d.mts +24 -2
- package/dist/components/Markdown.d.mts.map +1 -1
- package/dist/components/Markdown.mjs +356 -27
- package/dist/components/Markdown.mjs.map +1 -1
- package/dist/components/MessageItem.d.mts +10 -15
- package/dist/components/MessageItem.d.mts.map +1 -1
- package/dist/components/MessageItem.mjs +94 -68
- package/dist/components/MessageItem.mjs.map +1 -1
- package/dist/components/NativeShellState.d.mts +30 -0
- package/dist/components/NativeShellState.d.mts.map +1 -0
- package/dist/components/NativeShellState.mjs +61 -0
- package/dist/components/NativeShellState.mjs.map +1 -0
- package/dist/components/RailItem.d.mts +13 -0
- package/dist/components/RailItem.d.mts.map +1 -0
- package/dist/components/RailItem.mjs +61 -0
- package/dist/components/RailItem.mjs.map +1 -0
- package/dist/components/ReferenceChip.d.mts +18 -0
- package/dist/components/ReferenceChip.d.mts.map +1 -0
- package/dist/components/ReferenceChip.mjs +38 -0
- package/dist/components/ReferenceChip.mjs.map +1 -0
- package/dist/components/SectionLabel.mjs +1 -1
- package/dist/components/SeekBar.d.mts +17 -0
- package/dist/components/SeekBar.d.mts.map +1 -0
- package/dist/components/SeekBar.mjs +97 -0
- package/dist/components/SeekBar.mjs.map +1 -0
- package/dist/components/SegmentedControl.d.mts.map +1 -1
- package/dist/components/SegmentedControl.mjs.map +1 -1
- package/dist/components/Select.d.mts +39 -0
- package/dist/components/Select.d.mts.map +1 -0
- package/dist/components/Select.mjs +288 -0
- package/dist/components/Select.mjs.map +1 -0
- package/dist/components/Sheet.d.mts +17 -2
- package/dist/components/Sheet.d.mts.map +1 -1
- package/dist/components/Sheet.mjs +34 -11
- package/dist/components/Sheet.mjs.map +1 -1
- package/dist/components/SheetFrame.mjs +150 -29
- package/dist/components/SheetFrame.mjs.map +1 -1
- package/dist/components/SheetList.d.mts +14 -0
- package/dist/components/SheetList.d.mts.map +1 -0
- package/dist/components/SheetList.mjs +34 -0
- package/dist/components/SheetList.mjs.map +1 -0
- package/dist/components/ShowMore.d.mts +10 -0
- package/dist/components/ShowMore.d.mts.map +1 -0
- package/dist/components/ShowMore.mjs +44 -0
- package/dist/components/ShowMore.mjs.map +1 -0
- package/dist/components/Spinner.d.mts +1 -1
- package/dist/components/StatusBadge.d.mts +1 -1
- package/dist/components/Switch.d.mts +14 -0
- package/dist/components/Switch.d.mts.map +1 -0
- package/dist/components/Switch.mjs +37 -0
- package/dist/components/Switch.mjs.map +1 -0
- package/dist/components/SyntaxLine.d.mts +19 -0
- package/dist/components/SyntaxLine.d.mts.map +1 -0
- package/dist/components/SyntaxLine.mjs +134 -0
- package/dist/components/SyntaxLine.mjs.map +1 -0
- package/dist/components/Tabs.d.mts.map +1 -1
- package/dist/components/Tabs.mjs +8 -7
- package/dist/components/Tabs.mjs.map +1 -1
- package/dist/components/ToolPathLink.d.mts +10 -0
- package/dist/components/ToolPathLink.d.mts.map +1 -0
- package/dist/components/ToolPathLink.mjs +42 -0
- package/dist/components/ToolPathLink.mjs.map +1 -0
- package/dist/components/ToolResultImage.d.mts +21 -0
- package/dist/components/ToolResultImage.d.mts.map +1 -0
- package/dist/components/ToolResultImage.mjs +60 -0
- package/dist/components/ToolResultImage.mjs.map +1 -0
- package/dist/icons/IconColorContext.d.mts +2 -1
- package/dist/icons/IconColorContext.d.mts.map +1 -1
- package/dist/icons/IconColorContext.mjs.map +1 -1
- package/dist/icons/iconGlyphs.d.mts +206 -54
- package/dist/icons/iconGlyphs.d.mts.map +1 -1
- package/dist/icons/iconGlyphs.mjs +152 -0
- package/dist/icons/iconGlyphs.mjs.map +1 -1
- package/dist/icons/icons.d.mts +153 -1
- package/dist/icons/icons.d.mts.map +1 -1
- package/dist/icons/icons.mjs +40 -2
- package/dist/icons/icons.mjs.map +1 -1
- package/dist/index.d.mts +31 -7
- package/dist/index.mjs +36 -12
- package/dist/lib/fileKindLabel.mjs +17 -0
- package/dist/lib/fileKindLabel.mjs.map +1 -0
- package/dist/lib/fonts.d.mts +3 -1
- package/dist/lib/fonts.d.mts.map +1 -1
- package/dist/lib/fonts.mjs +4 -2
- package/dist/lib/fonts.mjs.map +1 -1
- package/dist/lib/insideSheet.d.mts +10 -0
- package/dist/lib/insideSheet.d.mts.map +1 -0
- package/dist/lib/markdown.mjs +310 -23
- package/dist/lib/markdown.mjs.map +1 -1
- package/dist/lib/reading.mjs +60 -0
- package/dist/lib/reading.mjs.map +1 -0
- package/dist/lib/useControllable.mjs +14 -6
- package/dist/lib/useControllable.mjs.map +1 -1
- package/dist/lib/useReadingPage.mjs +33 -0
- package/dist/lib/useReadingPage.mjs.map +1 -0
- package/dist/po-runtime-identity.json +1 -0
- package/dist/shell.d.mts +6 -0
- package/dist/shell.mjs +7 -0
- package/package.json +41 -31
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { fontOf } from "../lib/fonts.mjs";
|
|
2
|
+
import { Button } from "./Button.mjs";
|
|
3
|
+
import { CloseIcon, DownloadIcon } from "../icons/icons.mjs";
|
|
4
|
+
import { CopyButton } from "./CopyButton.mjs";
|
|
5
|
+
import { fileKindLabel } from "../lib/fileKindLabel.mjs";
|
|
6
|
+
import { FilePreview } from "./FilePreview.mjs";
|
|
7
|
+
import { fileKind, filePreviewMode, modifiedLabel, sizeLabel } from "@agimon-ai/po-web-components/text";
|
|
8
|
+
import { View } from "react-native-unistyles/components/native/View";
|
|
9
|
+
import { Text } from "react-native-unistyles/components/native/Text";
|
|
10
|
+
import { StyleSheet } from "react-native-unistyles";
|
|
11
|
+
import { useEffect, useRef, useState } from "react";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useT } from "@agimon-ai/po-core/native";
|
|
14
|
+
import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
|
|
15
|
+
|
|
16
|
+
//#region src/components/FileViewer.tsx
|
|
17
|
+
/** One file on the phone: header or top-bar download, the bounded preview, and the path strip. */
|
|
18
|
+
function FileViewer(props) {
|
|
19
|
+
const t = useT();
|
|
20
|
+
const { path, item, scopeKey, loadPreview, loadMedia, prepareSave, setTabHeader, unavailable, status } = props;
|
|
21
|
+
const hasStatus = status !== void 0 && status !== null;
|
|
22
|
+
const version = `${item?.modifiedAt ?? ""}:${item?.size ?? ""}`;
|
|
23
|
+
const downloadKey = `${scopeKey}:${path}`;
|
|
24
|
+
const key = `${downloadKey}:${version}`;
|
|
25
|
+
const [loaded, setLoaded] = useState();
|
|
26
|
+
const loaders = useRef({
|
|
27
|
+
loadPreview,
|
|
28
|
+
loadMedia
|
|
29
|
+
});
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
loaders.current = {
|
|
32
|
+
loadPreview,
|
|
33
|
+
loadMedia
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
const showsMedia = props.renderMediaPreview !== void 0;
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (unavailable || hasStatus) return;
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
loaders.current.loadPreview(controller.signal).then(async (preview) => {
|
|
41
|
+
if (controller.signal.aborted) return;
|
|
42
|
+
setLoaded({
|
|
43
|
+
key,
|
|
44
|
+
preview
|
|
45
|
+
});
|
|
46
|
+
const media = loaders.current.loadMedia;
|
|
47
|
+
if (filePreviewMode(path) !== "media" || !showsMedia || !media) return;
|
|
48
|
+
try {
|
|
49
|
+
const bytes = await media(controller.signal);
|
|
50
|
+
if (!controller.signal.aborted) setLoaded({
|
|
51
|
+
key,
|
|
52
|
+
preview,
|
|
53
|
+
media: bytes
|
|
54
|
+
});
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (!controller.signal.aborted) setLoaded({
|
|
57
|
+
key,
|
|
58
|
+
preview,
|
|
59
|
+
mediaError: error instanceof Error ? error.message : String(error)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}).catch((error) => {
|
|
63
|
+
if (!controller.signal.aborted) setLoaded({
|
|
64
|
+
key,
|
|
65
|
+
error: error instanceof Error ? error.message : String(error)
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
return () => controller.abort();
|
|
69
|
+
}, [
|
|
70
|
+
path,
|
|
71
|
+
key,
|
|
72
|
+
showsMedia,
|
|
73
|
+
unavailable,
|
|
74
|
+
hasStatus
|
|
75
|
+
]);
|
|
76
|
+
const current = loaded?.key === key ? loaded : void 0;
|
|
77
|
+
const downloadController = useRef(void 0);
|
|
78
|
+
const [download, setDownload] = useState();
|
|
79
|
+
useEffect(() => () => {
|
|
80
|
+
downloadController.current?.abort();
|
|
81
|
+
downloadController.current = void 0;
|
|
82
|
+
}, [downloadKey]);
|
|
83
|
+
const saving = download?.key === downloadKey && download.saving === true;
|
|
84
|
+
const canSave = props.nativeSaveFile !== void 0 && prepareSave !== void 0;
|
|
85
|
+
const save = async () => {
|
|
86
|
+
if (unavailable || !props.nativeSaveFile || !prepareSave || downloadController.current) return;
|
|
87
|
+
const controller = new AbortController();
|
|
88
|
+
downloadController.current = controller;
|
|
89
|
+
setDownload({
|
|
90
|
+
key: downloadKey,
|
|
91
|
+
saving: true
|
|
92
|
+
});
|
|
93
|
+
try {
|
|
94
|
+
const file = await prepareSave(controller.signal);
|
|
95
|
+
if (controller.signal.aborted || downloadController.current !== controller) return;
|
|
96
|
+
await props.nativeSaveFile(file);
|
|
97
|
+
if (!controller.signal.aborted && downloadController.current === controller) setDownload({
|
|
98
|
+
key: downloadKey,
|
|
99
|
+
note: t("nativeComponents.fileViewer.saved", "Saved.")
|
|
100
|
+
});
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (!controller.signal.aborted && downloadController.current === controller) setDownload({
|
|
103
|
+
key: downloadKey,
|
|
104
|
+
note: error instanceof Error ? error.message : String(error)
|
|
105
|
+
});
|
|
106
|
+
} finally {
|
|
107
|
+
if (downloadController.current === controller) downloadController.current = void 0;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const cancel = () => {
|
|
111
|
+
downloadController.current?.abort();
|
|
112
|
+
downloadController.current = void 0;
|
|
113
|
+
setDownload({
|
|
114
|
+
key: downloadKey,
|
|
115
|
+
note: t("nativeComponents.fileViewer.cancelled", "Download cancelled.")
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const handlers = useRef({
|
|
119
|
+
save,
|
|
120
|
+
cancel
|
|
121
|
+
});
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
handlers.current = {
|
|
124
|
+
save,
|
|
125
|
+
cancel
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
const media = filePreviewMode(path) === "media" && showsMedia && current?.media !== void 0;
|
|
129
|
+
const subtitle = `${fileKindLabel(fileKind(path), t)}${item ? ` · ${sizeLabel(item.size)}` : ""}`;
|
|
130
|
+
const offline = unavailable !== void 0;
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (!setTabHeader || media) return;
|
|
133
|
+
setTabHeader({
|
|
134
|
+
subtitle,
|
|
135
|
+
action: canSave ? /* @__PURE__ */ jsx(Button, {
|
|
136
|
+
variant: "ghost",
|
|
137
|
+
size: "icon",
|
|
138
|
+
disabled: offline,
|
|
139
|
+
accessibilityLabel: saving ? t("nativeComponents.fileViewer.cancelDownload", "Cancel download") : t("nativeComponents.fileViewer.download", "Download"),
|
|
140
|
+
onPress: () => saving ? handlers.current.cancel() : void handlers.current.save(),
|
|
141
|
+
children: saving ? /* @__PURE__ */ jsx(CloseIcon, { color: "hi" }) : /* @__PURE__ */ jsx(DownloadIcon, { color: "hi" })
|
|
142
|
+
}) : void 0
|
|
143
|
+
});
|
|
144
|
+
}, [
|
|
145
|
+
setTabHeader,
|
|
146
|
+
media,
|
|
147
|
+
subtitle,
|
|
148
|
+
canSave,
|
|
149
|
+
saving,
|
|
150
|
+
offline
|
|
151
|
+
]);
|
|
152
|
+
const note = download?.key === downloadKey && download.note ? /* @__PURE__ */ jsx(Text, {
|
|
153
|
+
accessibilityLiveRegion: "polite",
|
|
154
|
+
style: styles.meta,
|
|
155
|
+
children: download.note
|
|
156
|
+
}) : null;
|
|
157
|
+
const body = hasStatus ? status : unavailable ? /* @__PURE__ */ jsx(Text, {
|
|
158
|
+
accessibilityRole: "alert",
|
|
159
|
+
style: styles.error,
|
|
160
|
+
children: unavailable
|
|
161
|
+
}) : current?.error ? /* @__PURE__ */ jsx(Text, {
|
|
162
|
+
accessibilityRole: "alert",
|
|
163
|
+
style: styles.error,
|
|
164
|
+
children: current.error
|
|
165
|
+
}) : current?.preview ? /* @__PURE__ */ jsx(FilePreview, {
|
|
166
|
+
preview: current.preview,
|
|
167
|
+
scopeKey,
|
|
168
|
+
renderFilePreview: props.renderFilePreview,
|
|
169
|
+
renderMediaPreview: props.renderMediaPreview,
|
|
170
|
+
media: current.media,
|
|
171
|
+
mediaError: current.mediaError,
|
|
172
|
+
onOpen: props.onOpenPath
|
|
173
|
+
}) : /* @__PURE__ */ jsx(Text, {
|
|
174
|
+
style: styles.meta,
|
|
175
|
+
children: t("nativeComponents.fileViewer.reading", "Reading this file...")
|
|
176
|
+
});
|
|
177
|
+
return /* @__PURE__ */ jsxs(View, {
|
|
178
|
+
style: styles.screen,
|
|
179
|
+
children: [
|
|
180
|
+
props.actions,
|
|
181
|
+
props.note ? /* @__PURE__ */ jsx(Text, {
|
|
182
|
+
accessibilityLiveRegion: "polite",
|
|
183
|
+
style: styles.meta,
|
|
184
|
+
children: props.note
|
|
185
|
+
}) : null,
|
|
186
|
+
media ? /* @__PURE__ */ jsx(View, {
|
|
187
|
+
style: styles.stage,
|
|
188
|
+
children: body
|
|
189
|
+
}) : /* @__PURE__ */ jsxs(ScrollView, {
|
|
190
|
+
style: styles.stage,
|
|
191
|
+
contentContainerStyle: styles.content,
|
|
192
|
+
children: [
|
|
193
|
+
setTabHeader ? null : /* @__PURE__ */ jsx(FileViewerHeader, {
|
|
194
|
+
path,
|
|
195
|
+
size: item?.size,
|
|
196
|
+
saving,
|
|
197
|
+
canSave,
|
|
198
|
+
disabled: offline,
|
|
199
|
+
onDownload: () => void save(),
|
|
200
|
+
onCancel: cancel
|
|
201
|
+
}),
|
|
202
|
+
note,
|
|
203
|
+
body
|
|
204
|
+
]
|
|
205
|
+
}),
|
|
206
|
+
/* @__PURE__ */ jsx(FilePathStrip, {
|
|
207
|
+
path,
|
|
208
|
+
modifiedAt: item?.modifiedAt
|
|
209
|
+
})
|
|
210
|
+
]
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/** Where the file lives and when it last changed, pinned under the preview. */
|
|
214
|
+
function FilePathStrip({ path, modifiedAt }) {
|
|
215
|
+
const [now] = useState(Date.now);
|
|
216
|
+
const t = useT();
|
|
217
|
+
return /* @__PURE__ */ jsxs(View, {
|
|
218
|
+
style: styles.strip,
|
|
219
|
+
children: [
|
|
220
|
+
/* @__PURE__ */ jsx(Text, {
|
|
221
|
+
selectable: true,
|
|
222
|
+
numberOfLines: 1,
|
|
223
|
+
ellipsizeMode: "middle",
|
|
224
|
+
style: [styles.path, styles.stripPath],
|
|
225
|
+
children: path
|
|
226
|
+
}),
|
|
227
|
+
/* @__PURE__ */ jsx(CopyButton, {
|
|
228
|
+
text: path,
|
|
229
|
+
label: t("nativeComponents.fileViewer.pathLabel", "path")
|
|
230
|
+
}),
|
|
231
|
+
modifiedAt === void 0 ? null : /* @__PURE__ */ jsx(Text, {
|
|
232
|
+
style: styles.meta,
|
|
233
|
+
children: modifiedLabel(modifiedAt, now)
|
|
234
|
+
})
|
|
235
|
+
]
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/** The viewer's quiet header: where the file lives, what it is, and the one action on it. */
|
|
239
|
+
function FileViewerHeader({ path, size, saving, canSave, disabled, onDownload, onCancel }) {
|
|
240
|
+
const t = useT();
|
|
241
|
+
return /* @__PURE__ */ jsxs(View, {
|
|
242
|
+
style: styles.header,
|
|
243
|
+
children: [
|
|
244
|
+
/* @__PURE__ */ jsxs(View, {
|
|
245
|
+
style: styles.label,
|
|
246
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
247
|
+
selectable: true,
|
|
248
|
+
numberOfLines: 1,
|
|
249
|
+
ellipsizeMode: "middle",
|
|
250
|
+
style: styles.path,
|
|
251
|
+
children: path
|
|
252
|
+
}), /* @__PURE__ */ jsxs(Text, {
|
|
253
|
+
style: styles.meta,
|
|
254
|
+
children: [
|
|
255
|
+
fileKindLabel(fileKind(path), t),
|
|
256
|
+
size === void 0 ? "" : ` · ${sizeLabel(size)}`,
|
|
257
|
+
canSave ? "" : ` · ${t("nativeComponents.fileViewer.cannotSave", "This host cannot save downloads.")}`
|
|
258
|
+
]
|
|
259
|
+
})]
|
|
260
|
+
}),
|
|
261
|
+
canSave && saving ? /* @__PURE__ */ jsx(Button, {
|
|
262
|
+
variant: "ghost",
|
|
263
|
+
size: "sm",
|
|
264
|
+
onPress: onCancel,
|
|
265
|
+
children: t("nativeComponents.fileViewer.cancel", "Cancel")
|
|
266
|
+
}) : null,
|
|
267
|
+
canSave ? /* @__PURE__ */ jsx(Button, {
|
|
268
|
+
variant: "outline",
|
|
269
|
+
size: "sm",
|
|
270
|
+
disabled: saving || disabled,
|
|
271
|
+
onPress: onDownload,
|
|
272
|
+
children: t("nativeComponents.fileViewer.download", "Download")
|
|
273
|
+
}) : null
|
|
274
|
+
]
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const styles = StyleSheet.create((theme, rt) => ({
|
|
278
|
+
screen: { flex: 1 },
|
|
279
|
+
stage: { flex: 1 },
|
|
280
|
+
content: {
|
|
281
|
+
padding: theme.spacing(4),
|
|
282
|
+
gap: theme.spacing(3),
|
|
283
|
+
uni__dependencies: [0]
|
|
284
|
+
},
|
|
285
|
+
strip: {
|
|
286
|
+
flexDirection: "row",
|
|
287
|
+
alignItems: "center",
|
|
288
|
+
gap: theme.spacing(2),
|
|
289
|
+
paddingHorizontal: theme.spacing(4),
|
|
290
|
+
paddingTop: theme.spacing(2),
|
|
291
|
+
paddingBottom: theme.spacing(2) + rt.insets.bottom,
|
|
292
|
+
borderTopWidth: 1,
|
|
293
|
+
borderTopColor: theme.colors["border-soft"],
|
|
294
|
+
backgroundColor: theme.colors.bg,
|
|
295
|
+
uni__dependencies: [0, 9]
|
|
296
|
+
},
|
|
297
|
+
stripPath: { flexShrink: 1 },
|
|
298
|
+
header: {
|
|
299
|
+
flexDirection: "row",
|
|
300
|
+
alignItems: "center",
|
|
301
|
+
gap: theme.spacing(2),
|
|
302
|
+
paddingBottom: theme.spacing(3),
|
|
303
|
+
borderBottomWidth: 1,
|
|
304
|
+
borderBottomColor: theme.colors["border-soft"],
|
|
305
|
+
uni__dependencies: [0]
|
|
306
|
+
},
|
|
307
|
+
label: {
|
|
308
|
+
flex: 1,
|
|
309
|
+
minWidth: 0,
|
|
310
|
+
gap: theme.spacing(.5),
|
|
311
|
+
uni__dependencies: [0]
|
|
312
|
+
},
|
|
313
|
+
path: {
|
|
314
|
+
fontFamily: fontOf(theme.fontFamily.mono),
|
|
315
|
+
fontSize: theme.fontSize.sm,
|
|
316
|
+
color: theme.colors.dim,
|
|
317
|
+
uni__dependencies: [0]
|
|
318
|
+
},
|
|
319
|
+
meta: {
|
|
320
|
+
fontFamily: fontOf(theme.fontFamily.sans),
|
|
321
|
+
fontSize: theme.fontSize.sm,
|
|
322
|
+
color: theme.colors.dim,
|
|
323
|
+
uni__dependencies: [0]
|
|
324
|
+
},
|
|
325
|
+
error: {
|
|
326
|
+
fontFamily: fontOf(theme.fontFamily.sans),
|
|
327
|
+
fontSize: theme.fontSize.sm,
|
|
328
|
+
color: theme.colors.red,
|
|
329
|
+
uni__dependencies: [0]
|
|
330
|
+
}
|
|
331
|
+
}));
|
|
332
|
+
|
|
333
|
+
//#endregion
|
|
334
|
+
export { FilePathStrip, FileViewer, FileViewerHeader };
|
|
335
|
+
//# sourceMappingURL=FileViewer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileViewer.mjs","names":["useT","BoundedFileSource","fileKind","filePreviewMode","modifiedLabel","sizeLabel","FileTextPreview","ReactNode","useEffect","useRef","useState","StyleSheet","CloseIcon","DownloadIcon","fileKindLabel","fontOf","Button","CopyButton","FilePreview","FilePreviewProps","Loaded","key","preview","error","media","data","mimeType","mediaError","FileViewerProps","path","item","size","modifiedAt","scopeKey","loadPreview","signal","AbortSignal","Promise","loadMedia","prepareSave","nativeSaveFile","source","renderFilePreview","renderMediaPreview","setTabHeader","header","subtitle","action","onOpenPath","actions","note","unavailable","status","FileViewer","props","t","hasStatus","undefined","version","downloadKey","loaded","setLoaded","loaders","current","showsMedia","controller","AbortController","then","aborted","bytes","Error","message","String","catch","abort","downloadController","download","setDownload","saving","canSave","save","file","cancel","handlers","offline","styles","meta","body","screen","stage","content","FilePathStrip","now","Date","strip","stripPath","FileViewerHeader","disabled","onDownload","onCancel","label","create","theme","rt","flex","padding","spacing","gap","uni__dependencies","flexDirection","alignItems","paddingHorizontal","paddingTop","paddingBottom","insets","bottom","borderTopWidth","borderTopColor","colors","backgroundColor","bg","flexShrink","borderBottomWidth","borderBottomColor","minWidth","fontFamily","mono","fontSize","sm","color","dim","sans","red"],"sources":["../../src/components/FileViewer.tsx"],"sourcesContent":["import { useT } from '@agimon-ai/po-core/native';\nimport {\n type BoundedFileSource,\n fileKind,\n filePreviewMode,\n modifiedLabel,\n sizeLabel,\n type FileTextPreview,\n} from '@agimon-ai/po-web-components/text';\nimport { type ReactNode, useEffect, useRef, useState } from 'react';\nimport { ScrollView, Text, View } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { CloseIcon, DownloadIcon } from '../icons/icons';\nimport { fileKindLabel } from '../lib/fileKindLabel';\nimport { fontOf } from '../lib/fonts';\nimport { Button } from './Button';\nimport { CopyButton } from './CopyButton';\nimport { FilePreview, type FilePreviewProps } from './FilePreview';\n\ninterface Loaded {\n key: string;\n preview?: FileTextPreview;\n error?: string;\n media?: { data: string; mimeType: string };\n mediaError?: string;\n}\n\nexport interface FileViewerProps {\n path: string;\n /** The listed file, for its size and modified time; changes to it reload the preview. */\n item?: { size: number; modifiedAt: number };\n /** Keeps this folder's previews and downloads apart from another folder's file with the same path. */\n scopeKey: string;\n loadPreview: (signal: AbortSignal) => Promise<FileTextPreview>;\n /** Whole small media, base64 encoded by the owner. */\n loadMedia?: (signal: AbortSignal) => Promise<{ data: string; mimeType: string }>;\n /** A bounded source the host saves; without it there is no download. */\n prepareSave?: (signal: AbortSignal) => Promise<BoundedFileSource>;\n nativeSaveFile?: (source: BoundedFileSource) => Promise<void>;\n renderFilePreview?: FilePreviewProps['renderFilePreview'];\n renderMediaPreview?: FilePreviewProps['renderMediaPreview'];\n /** The native top bar of the tab screen; absent in older hosts, where the viewer draws its own header. */\n setTabHeader?: (header: { subtitle?: string; action?: ReactNode }) => void;\n onOpenPath: (path: string) => void;\n /** Above the preview, such as the owner's move action. */\n actions?: ReactNode;\n note?: string;\n /** Shown instead of the preview when the owner cannot read files, such as an unavailable session. */\n unavailable?: string;\n /** Shown instead of the preview, such as an EmptyState for a folder, a missing file or a failed read. */\n status?: ReactNode;\n}\n\n/** One file on the phone: header or top-bar download, the bounded preview, and the path strip. */\nexport function FileViewer(props: FileViewerProps) {\n const t = useT();\n const { path, item, scopeKey, loadPreview, loadMedia, prepareSave, setTabHeader, unavailable, status } = props;\n const hasStatus = status !== undefined && status !== null;\n const version = `${item?.modifiedAt ?? ''}:${item?.size ?? ''}`;\n const downloadKey = `${scopeKey}:${path}`;\n const key = `${downloadKey}:${version}`;\n const [loaded, setLoaded] = useState<Loaded>();\n // The owner's loaders change identity each render; the effect reads the latest through a ref.\n const loaders = useRef({ loadPreview, loadMedia });\n useEffect(() => {\n loaders.current = { loadPreview, loadMedia };\n });\n const showsMedia = props.renderMediaPreview !== undefined;\n useEffect(() => {\n if (unavailable || hasStatus) return;\n const controller = new AbortController();\n void loaders.current\n .loadPreview(controller.signal)\n .then(async (preview) => {\n if (controller.signal.aborted) return;\n setLoaded({ key, preview });\n const media = loaders.current.loadMedia;\n if (filePreviewMode(path) !== 'media' || !showsMedia || !media) return;\n try {\n const bytes = await media(controller.signal);\n if (!controller.signal.aborted) setLoaded({ key, preview, media: bytes });\n } catch (error) {\n if (!controller.signal.aborted)\n setLoaded({ key, preview, mediaError: error instanceof Error ? error.message : String(error) });\n }\n })\n .catch((error: unknown) => {\n if (!controller.signal.aborted)\n setLoaded({ key, error: error instanceof Error ? error.message : String(error) });\n });\n return () => controller.abort();\n }, [path, key, showsMedia, unavailable, hasStatus]);\n const current = loaded?.key === key ? loaded : undefined;\n const downloadController = useRef<AbortController | undefined>(undefined);\n const [download, setDownload] = useState<{ key: string; saving?: boolean; note?: string }>();\n useEffect(\n () => () => {\n downloadController.current?.abort();\n downloadController.current = undefined;\n },\n [downloadKey],\n );\n const saving = download?.key === downloadKey && download.saving === true;\n const canSave = props.nativeSaveFile !== undefined && prepareSave !== undefined;\n const save = async () => {\n if (unavailable || !props.nativeSaveFile || !prepareSave || downloadController.current) return;\n const controller = new AbortController();\n downloadController.current = controller;\n setDownload({ key: downloadKey, saving: true });\n try {\n const file = await prepareSave(controller.signal);\n if (controller.signal.aborted || downloadController.current !== controller) return;\n await props.nativeSaveFile(file);\n if (!controller.signal.aborted && downloadController.current === controller)\n setDownload({ key: downloadKey, note: t('nativeComponents.fileViewer.saved', 'Saved.') });\n } catch (error) {\n if (!controller.signal.aborted && downloadController.current === controller)\n setDownload({ key: downloadKey, note: error instanceof Error ? error.message : String(error) });\n } finally {\n if (downloadController.current === controller) downloadController.current = undefined;\n }\n };\n const cancel = () => {\n downloadController.current?.abort();\n downloadController.current = undefined;\n setDownload({ key: downloadKey, note: t('nativeComponents.fileViewer.cancelled', 'Download cancelled.') });\n };\n // The top bar's control outlives this render; it reaches the latest handlers through a ref synced after commit.\n const handlers = useRef({ save, cancel });\n useEffect(() => {\n handlers.current = { save, cancel };\n });\n // Once the host's media view is showing, it names and saves the media in the top bar; the viewer speaks otherwise.\n const media = filePreviewMode(path) === 'media' && showsMedia && current?.media !== undefined;\n const subtitle = `${fileKindLabel(fileKind(path), t)}${item ? ` · ${sizeLabel(item.size)}` : ''}`;\n const offline = unavailable !== undefined;\n useEffect(() => {\n if (!setTabHeader || media) return;\n setTabHeader({\n subtitle,\n action: canSave ? (\n <Button\n variant=\"ghost\"\n size=\"icon\"\n disabled={offline}\n accessibilityLabel={\n saving\n ? t('nativeComponents.fileViewer.cancelDownload', 'Cancel download')\n : t('nativeComponents.fileViewer.download', 'Download')\n }\n onPress={() => (saving ? handlers.current.cancel() : void handlers.current.save())}\n >\n {saving ? <CloseIcon color=\"hi\" /> : <DownloadIcon color=\"hi\" />}\n </Button>\n ) : undefined,\n });\n }, [setTabHeader, media, subtitle, canSave, saving, offline]);\n const note =\n download?.key === downloadKey && download.note ? (\n <Text accessibilityLiveRegion=\"polite\" style={styles.meta}>\n {download.note}\n </Text>\n ) : null;\n const body = hasStatus ? (\n status\n ) : unavailable ? (\n <Text accessibilityRole=\"alert\" style={styles.error}>\n {unavailable}\n </Text>\n ) : current?.error ? (\n <Text accessibilityRole=\"alert\" style={styles.error}>\n {current.error}\n </Text>\n ) : current?.preview ? (\n <FilePreview\n preview={current.preview}\n scopeKey={scopeKey}\n renderFilePreview={props.renderFilePreview}\n renderMediaPreview={props.renderMediaPreview}\n media={current.media}\n mediaError={current.mediaError}\n onOpen={props.onOpenPath}\n />\n ) : (\n <Text style={styles.meta}>{t('nativeComponents.fileViewer.reading', 'Reading this file...')}</Text>\n );\n return (\n <View style={styles.screen}>\n {props.actions}\n {props.note ? (\n <Text accessibilityLiveRegion=\"polite\" style={styles.meta}>\n {props.note}\n </Text>\n ) : null}\n {media ? (\n <View style={styles.stage}>{body}</View>\n ) : (\n <ScrollView style={styles.stage} contentContainerStyle={styles.content}>\n {setTabHeader ? null : (\n <FileViewerHeader\n path={path}\n size={item?.size}\n saving={saving}\n canSave={canSave}\n disabled={offline}\n onDownload={() => void save()}\n onCancel={cancel}\n />\n )}\n {note}\n {body}\n </ScrollView>\n )}\n <FilePathStrip path={path} modifiedAt={item?.modifiedAt} />\n </View>\n );\n}\n\n/** Where the file lives and when it last changed, pinned under the preview. */\nexport function FilePathStrip({ path, modifiedAt }: { path: string; modifiedAt?: number }) {\n // Read once per mount: a preview left open past midnight keeps its first label, which is still true then.\n const [now] = useState(Date.now);\n const t = useT();\n return (\n <View style={styles.strip}>\n <Text selectable numberOfLines={1} ellipsizeMode=\"middle\" style={[styles.path, styles.stripPath]}>\n {path}\n </Text>\n <CopyButton text={path} label={t('nativeComponents.fileViewer.pathLabel', 'path')} />\n {modifiedAt === undefined ? null : <Text style={styles.meta}>{modifiedLabel(modifiedAt, now)}</Text>}\n </View>\n );\n}\n\n/** The viewer's quiet header: where the file lives, what it is, and the one action on it. */\nexport function FileViewerHeader({\n path,\n size,\n saving,\n canSave,\n disabled,\n onDownload,\n onCancel,\n}: {\n path: string;\n size?: number;\n saving: boolean;\n canSave: boolean;\n disabled: boolean;\n onDownload: () => void;\n onCancel: () => void;\n}) {\n const t = useT();\n return (\n <View style={styles.header}>\n <View style={styles.label}>\n <Text selectable numberOfLines={1} ellipsizeMode=\"middle\" style={styles.path}>\n {path}\n </Text>\n <Text style={styles.meta}>\n {fileKindLabel(fileKind(path), t)}\n {size === undefined ? '' : ` · ${sizeLabel(size)}`}\n {canSave ? '' : ` · ${t('nativeComponents.fileViewer.cannotSave', 'This host cannot save downloads.')}`}\n </Text>\n </View>\n {canSave && saving ? (\n <Button variant=\"ghost\" size=\"sm\" onPress={onCancel}>\n {t('nativeComponents.fileViewer.cancel', 'Cancel')}\n </Button>\n ) : null}\n {canSave ? (\n <Button variant=\"outline\" size=\"sm\" disabled={saving || disabled} onPress={onDownload}>\n {t('nativeComponents.fileViewer.download', 'Download')}\n </Button>\n ) : null}\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme, rt) => ({\n screen: { flex: 1 },\n stage: { flex: 1 },\n content: { padding: theme.spacing(4), gap: theme.spacing(3) },\n strip: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2),\n paddingHorizontal: theme.spacing(4),\n paddingTop: theme.spacing(2),\n paddingBottom: theme.spacing(2) + rt.insets.bottom,\n borderTopWidth: 1,\n borderTopColor: theme.colors['border-soft'],\n backgroundColor: theme.colors.bg,\n },\n stripPath: { flexShrink: 1 },\n header: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2),\n paddingBottom: theme.spacing(3),\n borderBottomWidth: 1,\n borderBottomColor: theme.colors['border-soft'],\n },\n label: { flex: 1, minWidth: 0, gap: theme.spacing(0.5) },\n path: { fontFamily: fontOf(theme.fontFamily.mono), fontSize: theme.fontSize.sm, color: theme.colors.dim },\n meta: { fontFamily: fontOf(theme.fontFamily.sans), fontSize: theme.fontSize.sm, color: theme.colors.dim },\n error: { fontFamily: fontOf(theme.fontFamily.sans), fontSize: theme.fontSize.sm, color: theme.colors.red },\n}));\n"],"mappings":";;;;;;;;;;;;;;;;;AAuDA,SAAgBqD,WAAWC,OAAwB;CACjD,MAAMC,IAAIvD,KAAK;CACf,MAAM,EAAE6B,MAAMC,MAAMG,UAAUC,aAAaI,WAAWC,aAAaK,cAAcO,aAAaC,WAAWE;CACzG,MAAME,YAAYJ,WAAWK,UAAaL,WAAW;CACrD,MAAMM,UAAU,GAAG5B,MAAME,cAAc,GAAE,GAAIF,MAAMC,QAAQ;CAC3D,MAAM4B,cAAc,GAAG1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BC,iBAAiBjB,MAAMgB,OAAOE;EAAEZ,mBAAA,CAAA,GAAA,CAAA;CAClC;CACAb,WAAW,EAAE0B,YAAY,EAAE;CAC3B5E,QAAQ;EACNgE,eAAe;EACfC,YAAY;EACZH,KAAKL,MAAMI,QAAQ,CAAC;EACpBO,eAAeX,MAAMI,QAAQ,CAAC;EAC9BgB,mBAAmB;EACnBC,mBAAmBrB,MAAMgB,OAAO;EAAcV,mBAAA,CAAA,CAAA;CAChD;CACAR,OAAO;EAAEI,MAAM;EAAGoB,UAAU;EAAGjB,KAAKL,MAAMI,QAAQ,EAAG;EAACE,mBAAA,CAAA,CAAA;CAAC;CACvD/E,MAAM;EAAEgG,YAAY9G,OAAOuF,MAAMuB,WAAWC,IAAI;EAAGC,UAAUzB,MAAMyB,SAASC;EAAIC,OAAO3B,MAAMgB,OAAOY;EAAGtB,mBAAA,CAAA,CAAA;CAAC;CACxGtB,MAAM;EAAEuC,YAAY9G,OAAOuF,MAAMuB,WAAWM,IAAI;EAAGJ,UAAUzB,MAAMyB,SAASC;EAAIC,OAAO3B,MAAMgB,OAAOY;EAAGtB,mBAAA,CAAA,CAAA;CAAC;CACxGrF,OAAO;EAAEsG,YAAY9G,OAAOuF,MAAMuB,WAAWM,IAAI;EAAGJ,UAAUzB,MAAMyB,SAASC;EAAIC,OAAO3B,MAAMgB,OAAOc;EAAGxB,mBAAA,CAAA,CAAA;CAAC;AAC3G,EAAE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PresentedLine } from "@agimon-ai/po-web-components/text";
|
|
2
|
+
import { ViewProps } from "react-native";
|
|
3
|
+
//#region src/components/HashlineLines.d.ts
|
|
4
|
+
export interface HashlineLinesProps extends Omit<ViewProps, 'children'> {
|
|
5
|
+
lines: readonly PresentedLine[];
|
|
6
|
+
/** Width of the line-number column, in characters, from `hashlineBody`. */
|
|
7
|
+
gutter: number;
|
|
8
|
+
/** The file a body of bare anchored lines came from, for highlighting. */
|
|
9
|
+
path?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare function HashlineLines({ lines, gutter, path, style, ...props }: HashlineLinesProps): import("react").JSX.Element;
|
|
12
|
+
//#endregion
|
|
13
|
+
//# sourceMappingURL=HashlineLines.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HashlineLines.d.mts","names":[],"sources":["../../src/components/HashlineLines.tsx"],"mappings":";;;iBA8BiB,2BAA2B,KAAK;EAC/C,gBAAgB;;EAEhB;;EAEA;;wBAwCc,gBAAgB,OAAO,QAAQ,MAAM,UAAU,SAAS,qCAAkB,IAAA"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { fontOf } from "../lib/fonts.mjs";
|
|
2
|
+
import { READING } from "../lib/reading.mjs";
|
|
3
|
+
import { useReadingPage } from "../lib/useReadingPage.mjs";
|
|
4
|
+
import { ShowMore } from "./ShowMore.mjs";
|
|
5
|
+
import { SyntaxLine } from "./SyntaxLine.mjs";
|
|
6
|
+
import { detectGrammar, hashlineGroups, hashlineGroupsKey, highlightToLines } from "@agimon-ai/po-web-components/text";
|
|
7
|
+
import { View } from "react-native-unistyles/components/native/View";
|
|
8
|
+
import { Text } from "react-native-unistyles/components/native/Text";
|
|
9
|
+
import { StyleSheet } from "react-native-unistyles";
|
|
10
|
+
import { useEffect, useMemo, useState } from "react";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { useT } from "@agimon-ai/po-core/native";
|
|
13
|
+
|
|
14
|
+
//#region src/components/HashlineLines.tsx
|
|
15
|
+
const NO_SPANS = /* @__PURE__ */ new Map();
|
|
16
|
+
/** Spans per presented-line index, kept with the body they belong to, as the web's hook. */
|
|
17
|
+
function useHashlineSpans(lines, path) {
|
|
18
|
+
const groups = useMemo(() => hashlineGroups(lines, path), [lines, path]);
|
|
19
|
+
const key = hashlineGroupsKey(groups);
|
|
20
|
+
const [done, setDone] = useState();
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let live = true;
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
const next = /* @__PURE__ */ new Map();
|
|
25
|
+
const work = groups.map(async (group) => {
|
|
26
|
+
const grammar = detectGrammar({
|
|
27
|
+
path: group.path,
|
|
28
|
+
text: group.text
|
|
29
|
+
});
|
|
30
|
+
if (grammar === void 0) return;
|
|
31
|
+
const highlighted = await highlightToLines(group.text, grammar, controller.signal);
|
|
32
|
+
if (highlighted === void 0) return;
|
|
33
|
+
for (const [offset, index] of group.indices.entries()) {
|
|
34
|
+
const line = highlighted[offset];
|
|
35
|
+
if (line !== void 0) next.set(index, line);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
Promise.allSettled(work).then(() => {
|
|
39
|
+
if (live && next.size > 0) setDone({
|
|
40
|
+
key,
|
|
41
|
+
spans: next
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return () => {
|
|
45
|
+
live = false;
|
|
46
|
+
controller.abort();
|
|
47
|
+
};
|
|
48
|
+
}, [key]);
|
|
49
|
+
return done?.key === key ? done.spans : NO_SPANS;
|
|
50
|
+
}
|
|
51
|
+
function HashlineLines({ lines, gutter, path, style, ...props }) {
|
|
52
|
+
const t = useT();
|
|
53
|
+
const { page, reveal } = useReadingPage(`${path ?? ""}\n${lines.map((line) => JSON.stringify(line)).join("\n")}`);
|
|
54
|
+
const visible = useMemo(() => lines.slice(0, READING.hashlines * page), [lines, page]);
|
|
55
|
+
const spans = useHashlineSpans(visible, path);
|
|
56
|
+
return /* @__PURE__ */ jsxs(View, {
|
|
57
|
+
style,
|
|
58
|
+
...props,
|
|
59
|
+
children: [visible.map((line, index) => {
|
|
60
|
+
if (line.type === "file") return /* @__PURE__ */ jsx(Text, {
|
|
61
|
+
numberOfLines: 1,
|
|
62
|
+
style: [
|
|
63
|
+
styles.mono,
|
|
64
|
+
styles.faint,
|
|
65
|
+
index > 0 && styles.fileGap
|
|
66
|
+
],
|
|
67
|
+
children: line.path
|
|
68
|
+
}, index);
|
|
69
|
+
if (line.type === "plain") return /* @__PURE__ */ jsx(Text, {
|
|
70
|
+
selectable: true,
|
|
71
|
+
style: [styles.mono, styles.dim],
|
|
72
|
+
children: line.text
|
|
73
|
+
}, index);
|
|
74
|
+
const { value } = line;
|
|
75
|
+
const match = value.marker === "match";
|
|
76
|
+
return /* @__PURE__ */ jsxs(View, {
|
|
77
|
+
style: styles.row,
|
|
78
|
+
children: [
|
|
79
|
+
value.marker !== void 0 ? /* @__PURE__ */ jsx(Text, {
|
|
80
|
+
style: [styles.mono, match ? styles.marker : styles.faint],
|
|
81
|
+
children: match ? ">>" : " "
|
|
82
|
+
}) : null,
|
|
83
|
+
/* @__PURE__ */ jsx(Text, {
|
|
84
|
+
style: [styles.mono, styles.faint],
|
|
85
|
+
children: String(value.line).padStart(gutter)
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ jsx(SyntaxLine, {
|
|
88
|
+
selectable: true,
|
|
89
|
+
spans: spans.get(index),
|
|
90
|
+
text: value.content,
|
|
91
|
+
style: [
|
|
92
|
+
styles.mono,
|
|
93
|
+
styles.content,
|
|
94
|
+
match ? styles.hi : styles.text
|
|
95
|
+
]
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
}, index);
|
|
99
|
+
}), visible.length < lines.length ? /* @__PURE__ */ jsx(ShowMore, {
|
|
100
|
+
label: t("nativeComponents.hashline.showMore", "Show more lines"),
|
|
101
|
+
summary: t("nativeComponents.hashline.summary", "{shown} of {total} lines", {
|
|
102
|
+
shown: visible.length,
|
|
103
|
+
total: lines.length
|
|
104
|
+
}),
|
|
105
|
+
onPress: reveal
|
|
106
|
+
}) : null]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const styles = StyleSheet.create((theme) => ({
|
|
110
|
+
row: {
|
|
111
|
+
flexDirection: "row",
|
|
112
|
+
gap: theme.spacing(2),
|
|
113
|
+
uni__dependencies: [0]
|
|
114
|
+
},
|
|
115
|
+
fileGap: {
|
|
116
|
+
marginTop: theme.spacing(1),
|
|
117
|
+
uni__dependencies: [0]
|
|
118
|
+
},
|
|
119
|
+
mono: {
|
|
120
|
+
fontFamily: fontOf(theme.fontFamily.mono),
|
|
121
|
+
fontSize: theme.fontSize.sm,
|
|
122
|
+
lineHeight: theme.lineHeightRelaxed.sm,
|
|
123
|
+
uni__dependencies: [0]
|
|
124
|
+
},
|
|
125
|
+
content: {
|
|
126
|
+
flex: 1,
|
|
127
|
+
minWidth: 0
|
|
128
|
+
},
|
|
129
|
+
marker: {
|
|
130
|
+
color: theme.colors.blue,
|
|
131
|
+
uni__dependencies: [0]
|
|
132
|
+
},
|
|
133
|
+
faint: {
|
|
134
|
+
color: theme.colors.faint,
|
|
135
|
+
uni__dependencies: [0]
|
|
136
|
+
},
|
|
137
|
+
dim: {
|
|
138
|
+
color: theme.colors.dim,
|
|
139
|
+
uni__dependencies: [0]
|
|
140
|
+
},
|
|
141
|
+
text: {
|
|
142
|
+
color: theme.colors.text,
|
|
143
|
+
uni__dependencies: [0]
|
|
144
|
+
},
|
|
145
|
+
hi: {
|
|
146
|
+
color: theme.colors.hi,
|
|
147
|
+
uni__dependencies: [0]
|
|
148
|
+
}
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
export { HashlineLines };
|
|
153
|
+
//# sourceMappingURL=HashlineLines.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HashlineLines.mjs","names":["useT","detectGrammar","hashlineGroups","hashlineGroupsKey","highlightToLines","PresentedLine","SyntaxSpan","useEffect","useMemo","useState","ViewProps","StyleSheet","fontOf","READING","useReadingPage","ShowMore","SyntaxLine","HashlineLinesProps","Omit","lines","gutter","path","NO_SPANS","ReadonlyMap","Map","useHashlineSpans","groups","key","done","setDone","spans","live","controller","AbortController","next","work","map","group","grammar","text","undefined","highlighted","signal","offset","index","indices","entries","line","set","Promise","allSettled","then","size","abort","HashlineLines","style","props","t","page","reveal","JSON","stringify","join","visible","slice","hashlines","type","styles","mono","faint","fileGap","dim","value","match","marker","row","String","padStart","get","content","hi","length","shown","total","create","theme","flexDirection","gap","spacing","uni__dependencies","marginTop","fontFamily","fontSize","sm","lineHeight","lineHeightRelaxed","flex","minWidth","color","colors","blue"],"sources":["../../src/components/HashlineLines.tsx"],"sourcesContent":["import { useT } from '@agimon-ai/po-core/native';\nimport {\n detectGrammar,\n hashlineGroups,\n hashlineGroupsKey,\n highlightToLines,\n type PresentedLine,\n type SyntaxSpan,\n} from '@agimon-ai/po-web-components/text';\nimport { useEffect, useMemo, useState } from 'react';\nimport { Text, View, type ViewProps } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { fontOf } from '../lib/fonts';\nimport { READING } from '../lib/reading';\nimport { useReadingPage } from '../lib/useReadingPage';\nimport { ShowMore } from './ShowMore';\nimport { SyntaxLine } from './SyntaxLine';\n\n/*\n * The anchored body shared by hashline results, as the web's HashlineLines: a\n * file heading per group, a right-aligned line-number gutter, and a `>>`\n * marker on grep matches. Mono type makes a padded number the gutter, so the\n * column needs no measuring.\n *\n * The anchored lines are coloured with the web's grammars and palette when the\n * body names a file, or when `path` names one. Colour arrives late and never\n * blocks the text: an unhighlighted body is the same body without the colours.\n */\n\nexport interface HashlineLinesProps extends Omit<ViewProps, 'children'> {\n lines: readonly PresentedLine[];\n /** Width of the line-number column, in characters, from `hashlineBody`. */\n gutter: number;\n /** The file a body of bare anchored lines came from, for highlighting. */\n path?: string | undefined;\n}\n\nconst NO_SPANS: ReadonlyMap<number, readonly SyntaxSpan[]> = new Map();\n\n/** Spans per presented-line index, kept with the body they belong to, as the web's hook. */\nfunction useHashlineSpans(lines: readonly PresentedLine[], path: string | undefined) {\n const groups = useMemo(() => hashlineGroups(lines, path), [lines, path]);\n const key = hashlineGroupsKey(groups);\n const [done, setDone] = useState<{ key: string; spans: ReadonlyMap<number, readonly SyntaxSpan[]> }>();\n\n useEffect(() => {\n let live = true;\n const controller = new AbortController();\n const next = new Map<number, readonly SyntaxSpan[]>();\n const work = groups.map(async (group) => {\n const grammar = detectGrammar({ path: group.path, text: group.text });\n if (grammar === undefined) return;\n const highlighted = await highlightToLines(group.text, grammar, controller.signal);\n if (highlighted === undefined) return;\n for (const [offset, index] of group.indices.entries()) {\n const line = highlighted[offset];\n if (line !== undefined) next.set(index, line);\n }\n });\n // A grammar that fails to load leaves its run plain: colour is decoration.\n void Promise.allSettled(work).then(() => {\n if (live && next.size > 0) setDone({ key, spans: next });\n });\n return () => {\n live = false;\n controller.abort();\n };\n // The groups are rebuilt with the lines; their key is what actually changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key]);\n\n return done?.key === key ? done.spans : NO_SPANS;\n}\n\nexport function HashlineLines({ lines, gutter, path, style, ...props }: HashlineLinesProps) {\n const t = useT();\n // Whole anchored lines retain their exact content and line numbers, even above 640 characters.\n const { page, reveal } = useReadingPage(`${path ?? ''}\\n${lines.map((line) => JSON.stringify(line)).join('\\n')}`);\n const visible = useMemo(() => lines.slice(0, READING.hashlines * page), [lines, page]);\n const spans = useHashlineSpans(visible, path);\n return (\n <View style={style} {...props}>\n {visible.map((line, index) => {\n if (line.type === 'file') {\n return (\n <Text key={index} numberOfLines={1} style={[styles.mono, styles.faint, index > 0 && styles.fileGap]}>\n {line.path}\n </Text>\n );\n }\n if (line.type === 'plain') {\n return (\n <Text key={index} selectable style={[styles.mono, styles.dim]}>\n {line.text}\n </Text>\n );\n }\n const { value } = line;\n const match = value.marker === 'match';\n return (\n <View key={index} style={styles.row}>\n {value.marker !== undefined ? (\n <Text style={[styles.mono, match ? styles.marker : styles.faint]}>{match ? '>>' : ' '}</Text>\n ) : null}\n <Text style={[styles.mono, styles.faint]}>{String(value.line).padStart(gutter)}</Text>\n <SyntaxLine\n selectable\n spans={spans.get(index)}\n text={value.content}\n style={[styles.mono, styles.content, match ? styles.hi : styles.text]}\n />\n </View>\n );\n })}\n {visible.length < lines.length ? (\n <ShowMore\n label={t('nativeComponents.hashline.showMore', 'Show more lines')}\n summary={t('nativeComponents.hashline.summary', '{shown} of {total} lines', {\n shown: visible.length,\n total: lines.length,\n })}\n onPress={reveal}\n />\n ) : null}\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n row: { flexDirection: 'row', gap: theme.spacing(2) },\n fileGap: { marginTop: theme.spacing(1) },\n mono: {\n fontFamily: fontOf(theme.fontFamily.mono),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeightRelaxed.sm,\n },\n content: { flex: 1, minWidth: 0 },\n marker: { color: theme.colors.blue },\n faint: { color: theme.colors.faint },\n dim: { color: theme.colors.dim },\n text: { color: theme.colors.text },\n hi: { color: theme.colors.hi },\n}));\n"],"mappings":";;;;;;;;;;;;;;AAsCA,MAAMsB,2BAAuD,IAAIE,IAAI;;AAGrE,SAASC,iBAAiBN,OAAiCE,MAA0B;CACnF,MAAMK,SAASlB,cAAcN,eAAeiB,OAAOE,IAAI,GAAG,CAACF,OAAOE,IAAI,CAAC;CACvE,MAAMM,MAAMxB,kBAAkBuB,MAAM;CACpC,MAAM,CAACE,MAAMC,WAAWpB,SAA6E;CAErGF,gBAAgB;EACd,IAAIwB,OAAO;EACX,MAAMC,aAAa,IAAIC,gBAAgB;EACvC,MAAMC,uBAAO,IAAIV,IAAmC;EACpD,MAAMW,OAAOT,OAAOU,IAAI,OAAOC,UAAU;GACvC,MAAMC,UAAUrC,cAAc;IAAEoB,MAAMgB,MAAMhB;IAAMkB,MAAMF,MAAME;GAAK,CAAC;GACpE,IAAID,YAAYE,QAAW;GAC3B,MAAMC,cAAc,MAAMrC,iBAAiBiC,MAAME,MAAMD,SAASN,WAAWU,MAAM;GACjF,IAAID,gBAAgBD,QAAW;GAC/B,KAAK,MAAM,CAACG,QAAQC,UAAUP,MAAMQ,QAAQC,QAAQ,GAAG;IACrD,MAAMC,OAAON,YAAYE;IACzB,IAAII,SAASP,QAAWN,KAAKc,IAAIJ,OAAOG,IAAI;GAC9C;EACF,CAAC;EAED,AAAK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A,CAAA;CAAC;CACnClB,KAAK;EAAE2B,OAAOb,MAAMc,OAAO5B;EAAGkB,mBAAA,CAAA,CAAA;CAAC;CAC/BlD,MAAM;EAAE2D,OAAOb,MAAMc,OAAO5D;EAAIkD,mBAAA,CAAA,CAAA;CAAC;CACjCT,IAAI;EAAEkB,OAAOb,MAAMc,OAAOnB;EAAES,mBAAA,CAAA,CAAA;CAAC;AAC/B,EAAE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/components/HostFilter.d.ts
|
|
2
|
+
export interface HostFilterProps {
|
|
3
|
+
hosts: readonly {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}[];
|
|
7
|
+
/** null means All. This is presentation only, not a transport selection. */
|
|
8
|
+
value: string | null;
|
|
9
|
+
onChange: (id: string | null) => void;
|
|
10
|
+
/** Off when the choice names where something lives, so exactly one computer is always chosen. */
|
|
11
|
+
includeAll?: boolean;
|
|
12
|
+
accessibilityLabel?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Short names use the native segmented control; long names remain reachable by scrolling. */
|
|
15
|
+
export declare function HostFilter({ hosts, value, onChange, includeAll, accessibilityLabel: accessibilityLabelProp }: HostFilterProps): import("react").JSX.Element;
|
|
16
|
+
//#endregion
|
|
17
|
+
//# sourceMappingURL=HostFilter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostFilter.d.mts","names":[],"sources":["../../src/components/HostFilter.tsx"],"mappings":";iBAQiB;EACf;IAAkB;IAAY;;;EAE9B;EACA,WAAW;;EAEX;EACA;;;wBAOc,aACd,OACA,OACA,UACA,YACA,oBAAoB,0BACnB,kCAAe,IAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { selectionTick } from "../lib/haptics.mjs";
|
|
2
|
+
import { Button } from "./Button.mjs";
|
|
3
|
+
import { SegmentedControl } from "./SegmentedControl.mjs";
|
|
4
|
+
import { View } from "react-native-unistyles/components/native/View";
|
|
5
|
+
import { StyleSheet } from "react-native-unistyles";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { t } from "@agimon-ai/po-core/native";
|
|
8
|
+
import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
|
|
9
|
+
|
|
10
|
+
//#region src/components/HostFilter.tsx
|
|
11
|
+
const ALL = "";
|
|
12
|
+
const MAX_SEGMENTS = 3;
|
|
13
|
+
const MAX_SEGMENT_LABEL = 12;
|
|
14
|
+
/** Short names use the native segmented control; long names remain reachable by scrolling. */
|
|
15
|
+
function HostFilter({ hosts, value, onChange, includeAll = true, accessibilityLabel: accessibilityLabelProp }) {
|
|
16
|
+
const accessibilityLabel = accessibilityLabelProp ?? t("nativeComponents.hostFilter.label", "Filter by computer");
|
|
17
|
+
const options = [...includeAll ? [{
|
|
18
|
+
value: ALL,
|
|
19
|
+
label: t("nativeComponents.hostFilter.all", "All")
|
|
20
|
+
}] : [], ...hosts.map(({ id, label }) => ({
|
|
21
|
+
value: id,
|
|
22
|
+
label
|
|
23
|
+
}))];
|
|
24
|
+
const selected = hosts.some(({ id }) => id === value) ? value : includeAll ? ALL : hosts[0]?.id ?? ALL;
|
|
25
|
+
if (options.length <= MAX_SEGMENTS && options.every(({ label }) => label.length <= MAX_SEGMENT_LABEL)) return /* @__PURE__ */ jsx(SegmentedControl, {
|
|
26
|
+
options,
|
|
27
|
+
value: selected,
|
|
28
|
+
onValueChange: (id) => onChange(id || null),
|
|
29
|
+
accessibilityLabel,
|
|
30
|
+
style: styles.control
|
|
31
|
+
});
|
|
32
|
+
return /* @__PURE__ */ jsx(ScrollView, {
|
|
33
|
+
horizontal: true,
|
|
34
|
+
showsHorizontalScrollIndicator: false,
|
|
35
|
+
accessibilityLabel,
|
|
36
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
37
|
+
style: styles.choices,
|
|
38
|
+
children: options.map(({ value: id, label }) => /* @__PURE__ */ jsx(Button, {
|
|
39
|
+
variant: selected === id ? "subtle" : "ghost",
|
|
40
|
+
accessibilityState: { selected: selected === id },
|
|
41
|
+
style: [styles.choice, selected === id && styles.selected],
|
|
42
|
+
onPress: () => {
|
|
43
|
+
selectionTick();
|
|
44
|
+
onChange(id || null);
|
|
45
|
+
},
|
|
46
|
+
children: label
|
|
47
|
+
}, id))
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const styles = StyleSheet.create((theme) => ({
|
|
52
|
+
control: { minHeight: 44 },
|
|
53
|
+
choices: {
|
|
54
|
+
flexDirection: "row",
|
|
55
|
+
gap: theme.spacing(2),
|
|
56
|
+
uni__dependencies: [0]
|
|
57
|
+
},
|
|
58
|
+
choice: { minHeight: 44 },
|
|
59
|
+
selected: {
|
|
60
|
+
backgroundColor: theme.colors["tint-green"],
|
|
61
|
+
borderColor: theme.colors["edge-green"],
|
|
62
|
+
uni__dependencies: [0]
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { HostFilter };
|
|
68
|
+
//# sourceMappingURL=HostFilter.mjs.map
|