merong-docs 0.1.11 → 1.0.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/OVERVIEW.md +19 -19
- package/OVERVIEW.zh-CN.md +19 -22
- package/README.md +77 -77
- package/README.zh-CN.md +81 -81
- package/client/android-file-share.ts +25 -25
- package/client/controls.tsx +163 -163
- package/client/document-panel.tsx +166 -166
- package/client/external-file.tsx +78 -78
- package/client/file-reader.tsx +43 -43
- package/client/markdown-panel.tsx +737 -737
- package/client/markdown-scroll.ts +122 -122
- package/client/messages.ts +224 -224
- package/client/native-contacts.ts +145 -145
- package/client/page-render-queue.ts +12 -12
- package/client/page-selection.tsx +227 -227
- package/client/page-tools.tsx +72 -72
- package/client/pdf-geometry.ts +96 -96
- package/client/pdf-panel.tsx +477 -477
- package/client/reader-find.tsx +190 -190
- package/client/reader-notice.tsx +46 -46
- package/client/settings.tsx +143 -143
- package/client/syntax.tsx +55 -55
- package/client/viewport-geometry.ts +61 -61
- package/client/web.ts +462 -462
- package/client/worksheet-panel.tsx +631 -631
- package/client/zoom-controls.tsx +140 -140
- package/index.client.tsx +36 -36
- package/index.server.ts +73 -73
- package/node_modules/markdown-it/bin/markdown-it.mjs +0 -0
- package/node_modules/yaml/bin.mjs +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/scripts/prepare-office.mjs +20 -20
- package/server/engine.ts +89 -89
- package/server/external-file.ts +42 -42
- package/server/generated/document-worker.ts +1 -1
- package/server/generated/rust-reader_bg.wasm +0 -0
- package/server/markdown-index.ts +305 -305
- package/server/markdown-links.ts +51 -51
- package/server/markdown-page.ts +120 -120
- package/server/office-fonts.cjs +824 -824
- package/server/office-location.ts +41 -41
- package/server/office-preview.ts +186 -186
- package/server/office-worker.cjs +49 -49
- package/server/office-xml.ts +79 -79
- package/server/pdf-engine.ts +168 -168
- package/server/pdf-text-geometry.ts +60 -60
- package/server/rust-reader.ts +40 -40
- package/server/structured-document.ts +69 -69
- package/server/text-search.ts +15 -15
- package/server/worker-entry.ts +42 -42
- package/server/worker-protocol.ts +38 -38
- package/server/worksheet.ts +67 -67
- package/server/workspace-file.ts +63 -63
- package/shared/contracts.ts +187 -187
- package/shared/file-limits.ts +5 -5
- package/shared/markdown-constants.ts +4 -4
- package/shared/markdown-math.ts +198 -198
- package/shared/markdown-references.ts +83 -83
- package/shared/markdown-source-location.ts +8 -8
- package/shared/reader-settings.ts +15 -15
- package/shared/reader-shortcuts.ts +132 -132
- package/vendor/office2pdf/office2pdf_bg.wasm +2 -2
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { Platform, Text, View, type FlatList as NativeFlatList } from "react-native";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
import { useRpc, useTranslation, type PluginFilePanelProps } from "@getpaseo/plugin/client";
|
|
5
|
-
import { FlatList, Loading, ScrollView } from "@getpaseo/plugin/client/ui";
|
|
6
|
-
import { readStructuredDocument, type DocumentBlock } from "../shared/contracts";
|
|
7
|
-
import { Control, ReadError, ReaderInput, Toolbar, useFileGeneration, type Theme } from "./controls";
|
|
8
|
-
import { ExternalFileAction } from "./external-file";
|
|
9
|
-
import { messages } from "./messages";
|
|
10
|
-
import { SlideSidebar } from "./page-tools";
|
|
11
|
-
import { ReaderFindPopup, useReaderFindVisibility } from "./reader-find";
|
|
12
|
-
|
|
13
|
-
function DataTable({ rows, theme }: {
|
|
14
|
-
rows: string[][]; theme: Theme;
|
|
15
|
-
}) {
|
|
16
|
-
const widths = useMemo(() => {
|
|
17
|
-
const columns: number[] = [];
|
|
18
|
-
for (const row of rows) {
|
|
19
|
-
for (const [column, value] of row.entries()) {
|
|
20
|
-
const length = value.length + (value.match(/[\u2e80-\uffef]/g)?.length ?? 0);
|
|
21
|
-
columns[column] = Math.max(columns[column] ?? 0, Math.min(240, Math.max(84, 24 + 8 * length)));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return columns;
|
|
25
|
-
}, [rows]);
|
|
26
|
-
const renderRow = (row: string[], index: number) => (
|
|
27
|
-
<View key={index} role="row" style={{
|
|
28
|
-
flexDirection: "row", borderBottomWidth: 1, borderColor: theme.colors.border,
|
|
29
|
-
backgroundColor: index % 2 ? theme.colors.surface1 : theme.colors.surface0,
|
|
30
|
-
}}>
|
|
31
|
-
{widths.map((width, column) => (
|
|
32
|
-
<Text key={column} selectable style={{
|
|
33
|
-
color: theme.colors.foreground, width, paddingHorizontal: 10, paddingVertical: 8,
|
|
34
|
-
borderRightWidth: 1, borderColor: theme.colors.border,
|
|
35
|
-
}}>{row[column] ?? ""}</Text>
|
|
36
|
-
))}
|
|
37
|
-
</View>
|
|
38
|
-
);
|
|
39
|
-
return (
|
|
40
|
-
<ScrollView
|
|
41
|
-
horizontal nestedScrollEnabled testID="merong-document-table"
|
|
42
|
-
style={{ flexGrow: 0, maxWidth: "100%" }}
|
|
43
|
-
contentContainerStyle={{ borderLeftWidth: 1, borderTopWidth: 1, borderColor: theme.colors.border }}
|
|
44
|
-
>
|
|
45
|
-
<View>{rows.map(renderRow)}</View>
|
|
46
|
-
</ScrollView>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function StructuredPanel(props: PluginFilePanelProps) {
|
|
51
|
-
const { file, host, workspaceId, theme, layout: { compact } } = props;
|
|
52
|
-
const { t } = useTranslation(messages);
|
|
53
|
-
const rpc = useRpc(readStructuredDocument);
|
|
54
|
-
const generation = useFileGeneration(file);
|
|
55
|
-
const [selected, setSelected] = useState(0);
|
|
56
|
-
const { findOpen: finding, showFind, hideFind } = useReaderFindVisibility();
|
|
57
|
-
const [slidesOpen, setSlidesOpen] = useState(true);
|
|
58
|
-
const [search, setSearch] = useState("");
|
|
59
|
-
const [jump, setJump] = useState<{ section: number; block: number }>();
|
|
60
|
-
const documentList = useRef<NativeFlatList<DocumentBlock>>(null);
|
|
61
|
-
const retries = useRef(0);
|
|
62
|
-
const retry = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
63
|
-
const result = useQuery({
|
|
64
|
-
queryKey: ["merong-docs", "document", host.id, workspaceId, file.path, file.modifiedAt, generation],
|
|
65
|
-
queryFn: () => rpc({ workspaceId, path: file.path }),
|
|
66
|
-
staleTime: Infinity, gcTime: 30_000, retry: false,
|
|
67
|
-
});
|
|
68
|
-
const sections = result.data?.sections ?? [];
|
|
69
|
-
const index = Math.min(selected, Math.max(0, sections.length - 1));
|
|
70
|
-
const active = sections[index];
|
|
71
|
-
const slides = file.extension === "pptx";
|
|
72
|
-
const goTo = (section: number) => { setSelected(section); setJump(undefined); };
|
|
73
|
-
const matches = useMemo(() => {
|
|
74
|
-
const needle = search.trim().toLowerCase();
|
|
75
|
-
if (!needle || !result.data) return [];
|
|
76
|
-
return result.data.sections.flatMap((section, sectionIndex) => section.blocks.flatMap((block, blockIndex) => {
|
|
77
|
-
const text = block.kind === "table" ? block.rows.flat().join(" · ") : block.text;
|
|
78
|
-
const match = text.toLowerCase().indexOf(needle);
|
|
79
|
-
if (match < 0) return [];
|
|
80
|
-
return [{ section: sectionIndex, block: blockIndex, text: text.slice(Math.max(0, match - 35), match + needle.length + 85) }];
|
|
81
|
-
}));
|
|
82
|
-
}, [result.data, search]);
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (!jump || index !== jump.section || !active || jump.block >= active.blocks.length) return;
|
|
85
|
-
retries.current = 0;
|
|
86
|
-
documentList.current?.scrollToIndex({ index: jump.block, animated: false });
|
|
87
|
-
return () => clearTimeout(retry.current);
|
|
88
|
-
}, [active, index, jump]);
|
|
89
|
-
return (
|
|
90
|
-
<View testID="merong-structured-panel" style={{ flex: 1, minHeight: 0, backgroundColor: theme.colors.surface0 }}>
|
|
91
|
-
<Toolbar theme={theme} filePanel={props}>
|
|
92
|
-
{slides
|
|
93
|
-
? <Control title={t("thumbnails")} icon="PanelLeft" selected={slidesOpen}
|
|
94
|
-
onPress={() => setSlidesOpen((open) => !open)} theme={theme} compact={compact} />
|
|
95
|
-
: <Control title={t("find")} icon="Search" selected={finding} onPress={finding ? hideFind : showFind}
|
|
96
|
-
theme={theme} compact={compact} disabled={!result.data} />}
|
|
97
|
-
<ExternalFileAction {...props} />
|
|
98
|
-
</Toolbar>
|
|
99
|
-
<Text style={{ color: theme.colors.foregroundMuted, paddingHorizontal: 12, paddingVertical: 6 }}>
|
|
100
|
-
{t("officeLayoutUnavailable")}
|
|
101
|
-
</Text>
|
|
102
|
-
{result.isPending && <Loading />}
|
|
103
|
-
{result.isError && (
|
|
104
|
-
<ReadError theme={theme} compact={compact} label={t("textError")} error={result.error}
|
|
105
|
-
retry={t("retry")} onRetry={() => { void result.refetch(); }} />
|
|
106
|
-
)}
|
|
107
|
-
{!slides && sections.length > 1 && (
|
|
108
|
-
<ScrollView horizontal style={{ flexGrow: 0 }} contentContainerStyle={{ padding: 4, gap: 4 }}>
|
|
109
|
-
{sections.map((section, sectionIndex) => (
|
|
110
|
-
<Control key={sectionIndex}
|
|
111
|
-
title={section.title || `${t("sheet")} ${sectionIndex + 1}`} onPress={() => goTo(sectionIndex)}
|
|
112
|
-
selected={index === sectionIndex} theme={theme} compact={compact} />
|
|
113
|
-
))}
|
|
114
|
-
</ScrollView>
|
|
115
|
-
)}
|
|
116
|
-
{result.data?.truncated && (
|
|
117
|
-
<Text style={{ color: theme.colors.foregroundMuted, paddingHorizontal: 12, paddingVertical: 6 }}>{t("documentTruncated")}</Text>
|
|
118
|
-
)}
|
|
119
|
-
<View style={{ flex: 1, minHeight: 0, flexDirection: "row" }}>
|
|
120
|
-
{slides && slidesOpen && <SlideSidebar count={sections.length} page={index + 1}
|
|
121
|
-
goTo={(page) => goTo(page - 1)} theme={theme} compact={compact} />}
|
|
122
|
-
<View style={{ flex: 1, minHeight: 0, minWidth: 0 }}>
|
|
123
|
-
{active && (active.blocks.length > 0 || active.title && slides) ? (
|
|
124
|
-
<FlatList
|
|
125
|
-
ref={documentList} key={index} data={active.blocks} keyExtractor={(_, blockIndex) => String(blockIndex)}
|
|
126
|
-
onScrollToIndexFailed={({ index: target, averageItemLength }) => {
|
|
127
|
-
documentList.current?.scrollToOffset({ offset: target * (averageItemLength || 32), animated: false });
|
|
128
|
-
if (++retries.current > 4) return;
|
|
129
|
-
clearTimeout(retry.current);
|
|
130
|
-
retry.current = setTimeout(() => documentList.current?.scrollToIndex({ index: target, animated: false }), 100);
|
|
131
|
-
}}
|
|
132
|
-
contentContainerStyle={{ padding: compact ? 16 : 24, gap: 12 }}
|
|
133
|
-
ListHeaderComponent={active.title ? (
|
|
134
|
-
<Text selectable accessibilityRole="header" style={{ color: theme.colors.foreground, fontSize: 24, fontWeight: "600" }}>
|
|
135
|
-
{active.title}
|
|
136
|
-
</Text>
|
|
137
|
-
) : null}
|
|
138
|
-
renderItem={({ item }) => item.kind === "table" ? <DataTable rows={item.rows} theme={theme} />
|
|
139
|
-
: (
|
|
140
|
-
<Text selectable accessibilityRole={item.heading ? "header" : undefined} style={{
|
|
141
|
-
color: theme.colors.foreground, fontSize: item.heading ? 21 : 16,
|
|
142
|
-
lineHeight: item.heading ? 28 : 24, fontWeight: item.heading ? "600" : "400",
|
|
143
|
-
}}>{item.text}</Text>
|
|
144
|
-
)}
|
|
145
|
-
/>
|
|
146
|
-
) : result.data && <Text style={{ padding: 16, color: theme.colors.foregroundMuted }}>{t("empty")}</Text>}
|
|
147
|
-
{finding && (
|
|
148
|
-
<ReaderFindPopup testID="merong-structured-find" theme={theme}>
|
|
149
|
-
<View style={{ flexDirection: "row", gap: 4, alignItems: "center" }}>
|
|
150
|
-
<ReaderInput theme={theme} accessibilityLabel={t("find")} placeholder={t("searchPlaceholder")}
|
|
151
|
-
autoFocus={Platform.OS === "web"} value={search} maxLength={256} onChangeText={setSearch} />
|
|
152
|
-
<Control title={t("closeFind")} icon="X" onPress={hideFind} theme={theme} compact={compact} />
|
|
153
|
-
</View>
|
|
154
|
-
{!!search.trim() && <FlatList style={{ maxHeight: 150, flexGrow: 0 }} data={matches}
|
|
155
|
-
keyboardShouldPersistTaps="handled" keyExtractor={({ section, block }) => `${section}:${block}`}
|
|
156
|
-
ListEmptyComponent={<Text style={{ color: theme.colors.foregroundMuted, padding: 8 }}>{t("noMatches")}</Text>}
|
|
157
|
-
renderItem={({ item }) => <Text accessibilityRole="link" numberOfLines={2}
|
|
158
|
-
onPress={() => { setSelected(item.section); setJump(item); hideFind(); }}
|
|
159
|
-
style={{ color: theme.colors.foreground, padding: 8 }}>{item.text}</Text>} />}
|
|
160
|
-
</ReaderFindPopup>
|
|
161
|
-
)}
|
|
162
|
-
</View>
|
|
163
|
-
</View>
|
|
164
|
-
</View>
|
|
165
|
-
);
|
|
166
|
-
}
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { Platform, Text, View, type FlatList as NativeFlatList } from "react-native";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useRpc, useTranslation, type PluginFilePanelProps } from "@getpaseo/plugin/client";
|
|
5
|
+
import { FlatList, Loading, ScrollView } from "@getpaseo/plugin/client/ui";
|
|
6
|
+
import { readStructuredDocument, type DocumentBlock } from "../shared/contracts";
|
|
7
|
+
import { Control, ReadError, ReaderInput, Toolbar, useFileGeneration, type Theme } from "./controls";
|
|
8
|
+
import { ExternalFileAction } from "./external-file";
|
|
9
|
+
import { messages } from "./messages";
|
|
10
|
+
import { SlideSidebar } from "./page-tools";
|
|
11
|
+
import { ReaderFindPopup, useReaderFindVisibility } from "./reader-find";
|
|
12
|
+
|
|
13
|
+
function DataTable({ rows, theme }: {
|
|
14
|
+
rows: string[][]; theme: Theme;
|
|
15
|
+
}) {
|
|
16
|
+
const widths = useMemo(() => {
|
|
17
|
+
const columns: number[] = [];
|
|
18
|
+
for (const row of rows) {
|
|
19
|
+
for (const [column, value] of row.entries()) {
|
|
20
|
+
const length = value.length + (value.match(/[\u2e80-\uffef]/g)?.length ?? 0);
|
|
21
|
+
columns[column] = Math.max(columns[column] ?? 0, Math.min(240, Math.max(84, 24 + 8 * length)));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return columns;
|
|
25
|
+
}, [rows]);
|
|
26
|
+
const renderRow = (row: string[], index: number) => (
|
|
27
|
+
<View key={index} role="row" style={{
|
|
28
|
+
flexDirection: "row", borderBottomWidth: 1, borderColor: theme.colors.border,
|
|
29
|
+
backgroundColor: index % 2 ? theme.colors.surface1 : theme.colors.surface0,
|
|
30
|
+
}}>
|
|
31
|
+
{widths.map((width, column) => (
|
|
32
|
+
<Text key={column} selectable style={{
|
|
33
|
+
color: theme.colors.foreground, width, paddingHorizontal: 10, paddingVertical: 8,
|
|
34
|
+
borderRightWidth: 1, borderColor: theme.colors.border,
|
|
35
|
+
}}>{row[column] ?? ""}</Text>
|
|
36
|
+
))}
|
|
37
|
+
</View>
|
|
38
|
+
);
|
|
39
|
+
return (
|
|
40
|
+
<ScrollView
|
|
41
|
+
horizontal nestedScrollEnabled testID="merong-document-table"
|
|
42
|
+
style={{ flexGrow: 0, maxWidth: "100%" }}
|
|
43
|
+
contentContainerStyle={{ borderLeftWidth: 1, borderTopWidth: 1, borderColor: theme.colors.border }}
|
|
44
|
+
>
|
|
45
|
+
<View>{rows.map(renderRow)}</View>
|
|
46
|
+
</ScrollView>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function StructuredPanel(props: PluginFilePanelProps) {
|
|
51
|
+
const { file, host, workspaceId, theme, layout: { compact } } = props;
|
|
52
|
+
const { t } = useTranslation(messages);
|
|
53
|
+
const rpc = useRpc(readStructuredDocument);
|
|
54
|
+
const generation = useFileGeneration(file);
|
|
55
|
+
const [selected, setSelected] = useState(0);
|
|
56
|
+
const { findOpen: finding, showFind, hideFind } = useReaderFindVisibility();
|
|
57
|
+
const [slidesOpen, setSlidesOpen] = useState(true);
|
|
58
|
+
const [search, setSearch] = useState("");
|
|
59
|
+
const [jump, setJump] = useState<{ section: number; block: number }>();
|
|
60
|
+
const documentList = useRef<NativeFlatList<DocumentBlock>>(null);
|
|
61
|
+
const retries = useRef(0);
|
|
62
|
+
const retry = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
63
|
+
const result = useQuery({
|
|
64
|
+
queryKey: ["merong-docs", "document", host.id, workspaceId, file.path, file.modifiedAt, generation],
|
|
65
|
+
queryFn: () => rpc({ workspaceId, path: file.path }),
|
|
66
|
+
staleTime: Infinity, gcTime: 30_000, retry: false,
|
|
67
|
+
});
|
|
68
|
+
const sections = result.data?.sections ?? [];
|
|
69
|
+
const index = Math.min(selected, Math.max(0, sections.length - 1));
|
|
70
|
+
const active = sections[index];
|
|
71
|
+
const slides = file.extension === "pptx";
|
|
72
|
+
const goTo = (section: number) => { setSelected(section); setJump(undefined); };
|
|
73
|
+
const matches = useMemo(() => {
|
|
74
|
+
const needle = search.trim().toLowerCase();
|
|
75
|
+
if (!needle || !result.data) return [];
|
|
76
|
+
return result.data.sections.flatMap((section, sectionIndex) => section.blocks.flatMap((block, blockIndex) => {
|
|
77
|
+
const text = block.kind === "table" ? block.rows.flat().join(" · ") : block.text;
|
|
78
|
+
const match = text.toLowerCase().indexOf(needle);
|
|
79
|
+
if (match < 0) return [];
|
|
80
|
+
return [{ section: sectionIndex, block: blockIndex, text: text.slice(Math.max(0, match - 35), match + needle.length + 85) }];
|
|
81
|
+
}));
|
|
82
|
+
}, [result.data, search]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!jump || index !== jump.section || !active || jump.block >= active.blocks.length) return;
|
|
85
|
+
retries.current = 0;
|
|
86
|
+
documentList.current?.scrollToIndex({ index: jump.block, animated: false });
|
|
87
|
+
return () => clearTimeout(retry.current);
|
|
88
|
+
}, [active, index, jump]);
|
|
89
|
+
return (
|
|
90
|
+
<View testID="merong-structured-panel" style={{ flex: 1, minHeight: 0, backgroundColor: theme.colors.surface0 }}>
|
|
91
|
+
<Toolbar theme={theme} filePanel={props}>
|
|
92
|
+
{slides
|
|
93
|
+
? <Control title={t("thumbnails")} icon="PanelLeft" selected={slidesOpen}
|
|
94
|
+
onPress={() => setSlidesOpen((open) => !open)} theme={theme} compact={compact} />
|
|
95
|
+
: <Control title={t("find")} icon="Search" selected={finding} onPress={finding ? hideFind : showFind}
|
|
96
|
+
theme={theme} compact={compact} disabled={!result.data} />}
|
|
97
|
+
<ExternalFileAction {...props} />
|
|
98
|
+
</Toolbar>
|
|
99
|
+
<Text style={{ color: theme.colors.foregroundMuted, paddingHorizontal: 12, paddingVertical: 6 }}>
|
|
100
|
+
{t("officeLayoutUnavailable")}
|
|
101
|
+
</Text>
|
|
102
|
+
{result.isPending && <Loading />}
|
|
103
|
+
{result.isError && (
|
|
104
|
+
<ReadError theme={theme} compact={compact} label={t("textError")} error={result.error}
|
|
105
|
+
retry={t("retry")} onRetry={() => { void result.refetch(); }} />
|
|
106
|
+
)}
|
|
107
|
+
{!slides && sections.length > 1 && (
|
|
108
|
+
<ScrollView horizontal style={{ flexGrow: 0 }} contentContainerStyle={{ padding: 4, gap: 4 }}>
|
|
109
|
+
{sections.map((section, sectionIndex) => (
|
|
110
|
+
<Control key={sectionIndex}
|
|
111
|
+
title={section.title || `${t("sheet")} ${sectionIndex + 1}`} onPress={() => goTo(sectionIndex)}
|
|
112
|
+
selected={index === sectionIndex} theme={theme} compact={compact} />
|
|
113
|
+
))}
|
|
114
|
+
</ScrollView>
|
|
115
|
+
)}
|
|
116
|
+
{result.data?.truncated && (
|
|
117
|
+
<Text style={{ color: theme.colors.foregroundMuted, paddingHorizontal: 12, paddingVertical: 6 }}>{t("documentTruncated")}</Text>
|
|
118
|
+
)}
|
|
119
|
+
<View style={{ flex: 1, minHeight: 0, flexDirection: "row" }}>
|
|
120
|
+
{slides && slidesOpen && <SlideSidebar count={sections.length} page={index + 1}
|
|
121
|
+
goTo={(page) => goTo(page - 1)} theme={theme} compact={compact} />}
|
|
122
|
+
<View style={{ flex: 1, minHeight: 0, minWidth: 0 }}>
|
|
123
|
+
{active && (active.blocks.length > 0 || active.title && slides) ? (
|
|
124
|
+
<FlatList
|
|
125
|
+
ref={documentList} key={index} data={active.blocks} keyExtractor={(_, blockIndex) => String(blockIndex)}
|
|
126
|
+
onScrollToIndexFailed={({ index: target, averageItemLength }) => {
|
|
127
|
+
documentList.current?.scrollToOffset({ offset: target * (averageItemLength || 32), animated: false });
|
|
128
|
+
if (++retries.current > 4) return;
|
|
129
|
+
clearTimeout(retry.current);
|
|
130
|
+
retry.current = setTimeout(() => documentList.current?.scrollToIndex({ index: target, animated: false }), 100);
|
|
131
|
+
}}
|
|
132
|
+
contentContainerStyle={{ padding: compact ? 16 : 24, gap: 12 }}
|
|
133
|
+
ListHeaderComponent={active.title ? (
|
|
134
|
+
<Text selectable accessibilityRole="header" style={{ color: theme.colors.foreground, fontSize: 24, fontWeight: "600" }}>
|
|
135
|
+
{active.title}
|
|
136
|
+
</Text>
|
|
137
|
+
) : null}
|
|
138
|
+
renderItem={({ item }) => item.kind === "table" ? <DataTable rows={item.rows} theme={theme} />
|
|
139
|
+
: (
|
|
140
|
+
<Text selectable accessibilityRole={item.heading ? "header" : undefined} style={{
|
|
141
|
+
color: theme.colors.foreground, fontSize: item.heading ? 21 : 16,
|
|
142
|
+
lineHeight: item.heading ? 28 : 24, fontWeight: item.heading ? "600" : "400",
|
|
143
|
+
}}>{item.text}</Text>
|
|
144
|
+
)}
|
|
145
|
+
/>
|
|
146
|
+
) : result.data && <Text style={{ padding: 16, color: theme.colors.foregroundMuted }}>{t("empty")}</Text>}
|
|
147
|
+
{finding && (
|
|
148
|
+
<ReaderFindPopup testID="merong-structured-find" theme={theme}>
|
|
149
|
+
<View style={{ flexDirection: "row", gap: 4, alignItems: "center" }}>
|
|
150
|
+
<ReaderInput theme={theme} accessibilityLabel={t("find")} placeholder={t("searchPlaceholder")}
|
|
151
|
+
autoFocus={Platform.OS === "web"} value={search} maxLength={256} onChangeText={setSearch} />
|
|
152
|
+
<Control title={t("closeFind")} icon="X" onPress={hideFind} theme={theme} compact={compact} />
|
|
153
|
+
</View>
|
|
154
|
+
{!!search.trim() && <FlatList style={{ maxHeight: 150, flexGrow: 0 }} data={matches}
|
|
155
|
+
keyboardShouldPersistTaps="handled" keyExtractor={({ section, block }) => `${section}:${block}`}
|
|
156
|
+
ListEmptyComponent={<Text style={{ color: theme.colors.foregroundMuted, padding: 8 }}>{t("noMatches")}</Text>}
|
|
157
|
+
renderItem={({ item }) => <Text accessibilityRole="link" numberOfLines={2}
|
|
158
|
+
onPress={() => { setSelected(item.section); setJump(item); hideFind(); }}
|
|
159
|
+
style={{ color: theme.colors.foreground, padding: 8 }}>{item.text}</Text>} />}
|
|
160
|
+
</ReaderFindPopup>
|
|
161
|
+
)}
|
|
162
|
+
</View>
|
|
163
|
+
</View>
|
|
164
|
+
</View>
|
|
165
|
+
);
|
|
166
|
+
}
|
package/client/external-file.tsx
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { useRef, useState } from "react";
|
|
2
|
-
import { Alert, Platform, Share } from "react-native";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
import { useRpc, useTranslation, type PluginFilePanelProps } from "@getpaseo/plugin/client";
|
|
5
|
-
import { copyText, useToast } from "@getpaseo/plugin/client/ui";
|
|
6
|
-
import { openWorkspaceFile } from "../shared/contracts";
|
|
7
|
-
import { shareAndroidFile } from "./android-file-share";
|
|
8
|
-
import { Control } from "./controls";
|
|
9
|
-
import { messages } from "./messages";
|
|
10
|
-
import { downloadLocalFile, getDesktopBridge } from "./web";
|
|
11
|
-
|
|
12
|
-
type DesktopBridge = NonNullable<ReturnType<typeof getDesktopBridge>>;
|
|
13
|
-
|
|
14
|
-
async function desktopDaemonId(desktop: DesktopBridge) {
|
|
15
|
-
const status = await desktop.invoke("desktop_daemon_status");
|
|
16
|
-
return typeof status === "object" && status !== null && "status" in status && status.status === "running" &&
|
|
17
|
-
"serverId" in status && typeof status.serverId === "string" ? status.serverId : null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function ExternalFileAction({ file, workspaceId, host, theme, layout }: PluginFilePanelProps) {
|
|
21
|
-
const { t } = useTranslation(messages);
|
|
22
|
-
const toast = useToast();
|
|
23
|
-
const openLocal = useRpc(openWorkspaceFile);
|
|
24
|
-
const [opening, setOpening] = useState(false);
|
|
25
|
-
const handoff = useRef(false);
|
|
26
|
-
const desktop = Platform.OS === "web" ? getDesktopBridge() : undefined;
|
|
27
|
-
const localDaemon = useQuery({
|
|
28
|
-
queryKey: ["merong-docs", "desktop-daemon"],
|
|
29
|
-
queryFn: () => desktopDaemonId(desktop!),
|
|
30
|
-
enabled: typeof desktop?.invoke === "function",
|
|
31
|
-
staleTime: 5_000,
|
|
32
|
-
retry: false,
|
|
33
|
-
});
|
|
34
|
-
const localFile = Boolean(localDaemon.data) && localDaemon.data === host.id;
|
|
35
|
-
const checking = typeof desktop?.invoke === "function" && localDaemon.isPending;
|
|
36
|
-
const download = Platform.OS === "web" && !localFile;
|
|
37
|
-
const showAndroidFallback = () => {
|
|
38
|
-
Alert.alert(t("externalFile"), t("externalAndroid"), [
|
|
39
|
-
{ text: t("cancel"), style: "cancel" },
|
|
40
|
-
{
|
|
41
|
-
text: t("copyFilePath"),
|
|
42
|
-
onPress: () => {
|
|
43
|
-
void copyText(file.path).then(() => toast.show(t("copied"), { variant: "success" }),
|
|
44
|
-
() => toast.error(t("externalError")));
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
], { cancelable: true });
|
|
48
|
-
};
|
|
49
|
-
const open = async () => {
|
|
50
|
-
if (handoff.current || checking) return;
|
|
51
|
-
handoff.current = true;
|
|
52
|
-
setOpening(true);
|
|
53
|
-
try {
|
|
54
|
-
if (Platform.OS === "android") {
|
|
55
|
-
if (!await shareAndroidFile(file, file.name)) showAndroidFallback();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (localFile) {
|
|
59
|
-
await openLocal({ workspaceId, path: file.path });
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const url = await file.url();
|
|
63
|
-
if (Platform.OS === "ios" && url.startsWith("file:")) await Share.share({ url });
|
|
64
|
-
else if (Platform.OS === "web") downloadLocalFile(url, file.name);
|
|
65
|
-
else throw new Error("Unsupported file URL.");
|
|
66
|
-
} catch {
|
|
67
|
-
if (Platform.OS === "android") showAndroidFallback();
|
|
68
|
-
else toast.error(t(localFile ? "externalAppError" : download ? "downloadError" : "externalError"));
|
|
69
|
-
} finally {
|
|
70
|
-
handoff.current = false;
|
|
71
|
-
setOpening(false);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return (
|
|
75
|
-
<Control title={t(download ? "downloadFile" : "externalFile")} icon={download ? "Download" : "ExternalLink"}
|
|
76
|
-
theme={theme} compact={layout.compact} disabled={opening || checking} onPress={() => { void open(); }} />
|
|
77
|
-
);
|
|
78
|
-
}
|
|
1
|
+
import { useRef, useState } from "react";
|
|
2
|
+
import { Alert, Platform, Share } from "react-native";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useRpc, useTranslation, type PluginFilePanelProps } from "@getpaseo/plugin/client";
|
|
5
|
+
import { copyText, useToast } from "@getpaseo/plugin/client/ui";
|
|
6
|
+
import { openWorkspaceFile } from "../shared/contracts";
|
|
7
|
+
import { shareAndroidFile } from "./android-file-share";
|
|
8
|
+
import { Control } from "./controls";
|
|
9
|
+
import { messages } from "./messages";
|
|
10
|
+
import { downloadLocalFile, getDesktopBridge } from "./web";
|
|
11
|
+
|
|
12
|
+
type DesktopBridge = NonNullable<ReturnType<typeof getDesktopBridge>>;
|
|
13
|
+
|
|
14
|
+
async function desktopDaemonId(desktop: DesktopBridge) {
|
|
15
|
+
const status = await desktop.invoke("desktop_daemon_status");
|
|
16
|
+
return typeof status === "object" && status !== null && "status" in status && status.status === "running" &&
|
|
17
|
+
"serverId" in status && typeof status.serverId === "string" ? status.serverId : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function ExternalFileAction({ file, workspaceId, host, theme, layout }: PluginFilePanelProps) {
|
|
21
|
+
const { t } = useTranslation(messages);
|
|
22
|
+
const toast = useToast();
|
|
23
|
+
const openLocal = useRpc(openWorkspaceFile);
|
|
24
|
+
const [opening, setOpening] = useState(false);
|
|
25
|
+
const handoff = useRef(false);
|
|
26
|
+
const desktop = Platform.OS === "web" ? getDesktopBridge() : undefined;
|
|
27
|
+
const localDaemon = useQuery({
|
|
28
|
+
queryKey: ["merong-docs", "desktop-daemon"],
|
|
29
|
+
queryFn: () => desktopDaemonId(desktop!),
|
|
30
|
+
enabled: typeof desktop?.invoke === "function",
|
|
31
|
+
staleTime: 5_000,
|
|
32
|
+
retry: false,
|
|
33
|
+
});
|
|
34
|
+
const localFile = Boolean(localDaemon.data) && localDaemon.data === host.id;
|
|
35
|
+
const checking = typeof desktop?.invoke === "function" && localDaemon.isPending;
|
|
36
|
+
const download = Platform.OS === "web" && !localFile;
|
|
37
|
+
const showAndroidFallback = () => {
|
|
38
|
+
Alert.alert(t("externalFile"), t("externalAndroid"), [
|
|
39
|
+
{ text: t("cancel"), style: "cancel" },
|
|
40
|
+
{
|
|
41
|
+
text: t("copyFilePath"),
|
|
42
|
+
onPress: () => {
|
|
43
|
+
void copyText(file.path).then(() => toast.show(t("copied"), { variant: "success" }),
|
|
44
|
+
() => toast.error(t("externalError")));
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
], { cancelable: true });
|
|
48
|
+
};
|
|
49
|
+
const open = async () => {
|
|
50
|
+
if (handoff.current || checking) return;
|
|
51
|
+
handoff.current = true;
|
|
52
|
+
setOpening(true);
|
|
53
|
+
try {
|
|
54
|
+
if (Platform.OS === "android") {
|
|
55
|
+
if (!await shareAndroidFile(file, file.name)) showAndroidFallback();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (localFile) {
|
|
59
|
+
await openLocal({ workspaceId, path: file.path });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const url = await file.url();
|
|
63
|
+
if (Platform.OS === "ios" && url.startsWith("file:")) await Share.share({ url });
|
|
64
|
+
else if (Platform.OS === "web") downloadLocalFile(url, file.name);
|
|
65
|
+
else throw new Error("Unsupported file URL.");
|
|
66
|
+
} catch {
|
|
67
|
+
if (Platform.OS === "android") showAndroidFallback();
|
|
68
|
+
else toast.error(t(localFile ? "externalAppError" : download ? "downloadError" : "externalError"));
|
|
69
|
+
} finally {
|
|
70
|
+
handoff.current = false;
|
|
71
|
+
setOpening(false);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return (
|
|
75
|
+
<Control title={t(download ? "downloadFile" : "externalFile")} icon={download ? "Download" : "ExternalLink"}
|
|
76
|
+
theme={theme} compact={layout.compact} disabled={opening || checking} onPress={() => { void open(); }} />
|
|
77
|
+
);
|
|
78
|
+
}
|
package/client/file-reader.tsx
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { useEffect, useState, type ComponentType, type ReactNode } from "react";
|
|
2
|
-
import { View } from "react-native";
|
|
3
|
-
import type { PluginFilePanelProps } from "@getpaseo/plugin/client";
|
|
4
|
-
import { Loading } from "@getpaseo/plugin/client/ui";
|
|
5
|
-
import { ReaderNotices } from "./reader-notice";
|
|
6
|
-
|
|
7
|
-
function DeferredReaderBody({ active, children }: { active: boolean; children: ReactNode }) {
|
|
8
|
-
const [shown, setShown] = useState(false);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (!active || shown) return;
|
|
11
|
-
let frame = requestAnimationFrame(() => {
|
|
12
|
-
frame = requestAnimationFrame(() => setShown(true));
|
|
13
|
-
});
|
|
14
|
-
return () => cancelAnimationFrame(frame);
|
|
15
|
-
}, [active, shown]);
|
|
16
|
-
return shown ? children : <Loading />;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function fileReader(Reader: ComponentType<PluginFilePanelProps>) {
|
|
20
|
-
function ReaderPresentation({ props }: { props: PluginFilePanelProps }) {
|
|
21
|
-
const { layout, tab, theme } = props;
|
|
22
|
-
const { active } = tab as typeof tab & { active?: boolean };
|
|
23
|
-
const native = layout.platform !== "web";
|
|
24
|
-
const [nativeLayoutReady, setNativeLayoutReady] = useState(false);
|
|
25
|
-
const canOpen = active !== false && (!native || active === true || nativeLayoutReady);
|
|
26
|
-
const awaitNativeLayout = native && active === undefined && !nativeLayoutReady;
|
|
27
|
-
return (
|
|
28
|
-
<View collapsable={false} style={{ flex: 1, minHeight: 0, backgroundColor: theme.colors.surface0 }}
|
|
29
|
-
onLayout={awaitNativeLayout ? ({ nativeEvent: { layout: bounds } }) => {
|
|
30
|
-
if (bounds.width > 0 && bounds.height > 0) setNativeLayoutReady(true);
|
|
31
|
-
} : undefined}>
|
|
32
|
-
<DeferredReaderBody active={canOpen}>
|
|
33
|
-
<ReaderNotices theme={theme}><Reader {...props} /></ReaderNotices>
|
|
34
|
-
</DeferredReaderBody>
|
|
35
|
-
</View>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return function MerongFileReader(props: PluginFilePanelProps) {
|
|
40
|
-
const fileKey = JSON.stringify([props.host.id, props.workspaceId, props.file.path]);
|
|
41
|
-
return <ReaderPresentation key={fileKey} props={props} />;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
1
|
+
import { useEffect, useState, type ComponentType, type ReactNode } from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import type { PluginFilePanelProps } from "@getpaseo/plugin/client";
|
|
4
|
+
import { Loading } from "@getpaseo/plugin/client/ui";
|
|
5
|
+
import { ReaderNotices } from "./reader-notice";
|
|
6
|
+
|
|
7
|
+
function DeferredReaderBody({ active, children }: { active: boolean; children: ReactNode }) {
|
|
8
|
+
const [shown, setShown] = useState(false);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!active || shown) return;
|
|
11
|
+
let frame = requestAnimationFrame(() => {
|
|
12
|
+
frame = requestAnimationFrame(() => setShown(true));
|
|
13
|
+
});
|
|
14
|
+
return () => cancelAnimationFrame(frame);
|
|
15
|
+
}, [active, shown]);
|
|
16
|
+
return shown ? children : <Loading />;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function fileReader(Reader: ComponentType<PluginFilePanelProps>) {
|
|
20
|
+
function ReaderPresentation({ props }: { props: PluginFilePanelProps }) {
|
|
21
|
+
const { layout, tab, theme } = props;
|
|
22
|
+
const { active } = tab as typeof tab & { active?: boolean };
|
|
23
|
+
const native = layout.platform !== "web";
|
|
24
|
+
const [nativeLayoutReady, setNativeLayoutReady] = useState(false);
|
|
25
|
+
const canOpen = active !== false && (!native || active === true || nativeLayoutReady);
|
|
26
|
+
const awaitNativeLayout = native && active === undefined && !nativeLayoutReady;
|
|
27
|
+
return (
|
|
28
|
+
<View collapsable={false} style={{ flex: 1, minHeight: 0, backgroundColor: theme.colors.surface0 }}
|
|
29
|
+
onLayout={awaitNativeLayout ? ({ nativeEvent: { layout: bounds } }) => {
|
|
30
|
+
if (bounds.width > 0 && bounds.height > 0) setNativeLayoutReady(true);
|
|
31
|
+
} : undefined}>
|
|
32
|
+
<DeferredReaderBody active={canOpen}>
|
|
33
|
+
<ReaderNotices theme={theme}><Reader {...props} /></ReaderNotices>
|
|
34
|
+
</DeferredReaderBody>
|
|
35
|
+
</View>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return function MerongFileReader(props: PluginFilePanelProps) {
|
|
40
|
+
const fileKey = JSON.stringify([props.host.id, props.workspaceId, props.file.path]);
|
|
41
|
+
return <ReaderPresentation key={fileKey} props={props} />;
|
|
42
|
+
};
|
|
43
|
+
}
|