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
package/client/reader-find.tsx
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState, type ReactNode, type RefObject } from "react";
|
|
2
|
-
import { Keyboard, Platform, Text, View } from "react-native";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
5
|
-
import { useRpc, useTranslation } from "@getpaseo/plugin/client";
|
|
6
|
-
import { markdownSearchPageSize, searchMarkdownFile, type MarkdownSearchOptions } from "../shared/contracts";
|
|
7
|
-
import { Control, ReaderInput, useReaderShortcuts, type Theme } from "./controls";
|
|
8
|
-
import { messages } from "./messages";
|
|
9
|
-
import { bindReaderFind, focusWebReader } from "./web";
|
|
10
|
-
|
|
11
|
-
type SearchTarget = Pick<RpcInput<typeof searchMarkdownFile>, "workspaceId" | "path">;
|
|
12
|
-
export type MarkdownMatch = RpcOutput<typeof searchMarkdownFile>["hits"][number];
|
|
13
|
-
const empty: never[] = [];
|
|
14
|
-
|
|
15
|
-
type FindActions = Omit<Parameters<typeof bindReaderFind>[3], "focusReader">;
|
|
16
|
-
|
|
17
|
-
export function useReaderFindVisibility() {
|
|
18
|
-
const [findOpen, setFindOpen] = useState(false);
|
|
19
|
-
const showFind = useCallback(() => setFindOpen(true), []);
|
|
20
|
-
const hideFind = useCallback(() => {
|
|
21
|
-
if (Platform.OS !== "web") Keyboard.dismiss();
|
|
22
|
-
setFindOpen(false);
|
|
23
|
-
}, []);
|
|
24
|
-
return { findOpen, showFind, hideFind };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function useReaderFindShortcuts(root: RefObject<View | null>, testID: string, enabled: boolean, actions: FindActions,
|
|
28
|
-
viewport?: RefObject<View | null>) {
|
|
29
|
-
const current = useRef(actions);
|
|
30
|
-
const shortcuts = useReaderShortcuts();
|
|
31
|
-
current.current = actions;
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!enabled) return;
|
|
34
|
-
return bindReaderFind(root.current, testID, () => shortcuts.current, {
|
|
35
|
-
open: () => current.current.open(), close: () => current.current.close(),
|
|
36
|
-
move: (step) => current.current.move(step), isOpen: () => current.current.isOpen(),
|
|
37
|
-
focusReader: viewport ? () => focusWebReader(viewport.current) : undefined,
|
|
38
|
-
});
|
|
39
|
-
}, [root, testID, enabled, viewport, shortcuts]);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function useFindCriteria(open: boolean) {
|
|
43
|
-
const [criteria, setCriteria] = useState({
|
|
44
|
-
query: "", options: { matchCase: false, wholeWord: false, regex: false },
|
|
45
|
-
});
|
|
46
|
-
const [settled, setSettled] = useState(criteria);
|
|
47
|
-
const [index, setIndex] = useState(0);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (!open || settled === criteria) return;
|
|
50
|
-
const timeout = setTimeout(() => setSettled(criteria), 180);
|
|
51
|
-
return () => clearTimeout(timeout);
|
|
52
|
-
}, [criteria, open, settled]);
|
|
53
|
-
const ready = open && !!settled.query && criteria === settled;
|
|
54
|
-
return {
|
|
55
|
-
criteria, settled, ready, index, setIndex,
|
|
56
|
-
changeQuery: (query: string) => {
|
|
57
|
-
if (query === criteria.query) return;
|
|
58
|
-
setIndex(0);
|
|
59
|
-
setCriteria((prior) => ({ ...prior, query }));
|
|
60
|
-
},
|
|
61
|
-
toggle: (option: keyof MarkdownSearchOptions) => {
|
|
62
|
-
setIndex(0);
|
|
63
|
-
setCriteria((prior) => ({ ...prior, options: { ...prior.options, [option]: !prior.options[option] } }));
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function useMarkdownFind(target: SearchTarget, fileKey: readonly unknown[], open: boolean) {
|
|
69
|
-
const search = useRpc(searchMarkdownFile);
|
|
70
|
-
const { criteria, settled, ready, index, setIndex, changeQuery, toggle } = useFindCriteria(open);
|
|
71
|
-
const queryPage = (offset: number) => ({
|
|
72
|
-
queryKey: [...fileKey, "find", settled, offset],
|
|
73
|
-
queryFn: () => search({ ...target, ...settled, offset }),
|
|
74
|
-
staleTime: Infinity,
|
|
75
|
-
gcTime: 30_000,
|
|
76
|
-
retry: false,
|
|
77
|
-
});
|
|
78
|
-
const first = useQuery({ ...queryPage(0), enabled: ready });
|
|
79
|
-
const total = ready ? first.data?.total ?? 0 : 0;
|
|
80
|
-
const selected = Math.min(index, Math.max(0, total - 1));
|
|
81
|
-
const offset = Math.floor(selected / markdownSearchPageSize) * markdownSearchPageSize;
|
|
82
|
-
const later = useQuery({ ...queryPage(offset), enabled: ready && !!offset });
|
|
83
|
-
const page = offset ? later : first;
|
|
84
|
-
const hits: MarkdownMatch[] = ready ? page.data?.hits ?? empty : empty;
|
|
85
|
-
return {
|
|
86
|
-
...criteria, hits, active: hits[selected - offset], index: selected, total,
|
|
87
|
-
changeQuery, toggle,
|
|
88
|
-
move: (step: number) => {
|
|
89
|
-
if (total && !page.isFetching) setIndex((prior) => (Math.min(prior, total - 1) + step + total) % total);
|
|
90
|
-
},
|
|
91
|
-
error: ready && page.isError,
|
|
92
|
-
invalid: ready && first.data?.invalidPattern === true,
|
|
93
|
-
pending: !!criteria.query && (!ready || first.isPending || page.isPending),
|
|
94
|
-
retry: () => { void page.refetch(); },
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
type FindCriteria = { query: string; options: MarkdownSearchOptions };
|
|
99
|
-
type FindResults<Match> = { matches: Match[]; limited: boolean; invalidPattern: boolean };
|
|
100
|
-
|
|
101
|
-
export function useFindResults<Match>(fileKey: readonly unknown[], open: boolean,
|
|
102
|
-
search: (criteria: FindCriteria) => Promise<FindResults<Match> | null>) {
|
|
103
|
-
const { criteria, settled, ready, index, setIndex, changeQuery, toggle } = useFindCriteria(open);
|
|
104
|
-
const result = useQuery({
|
|
105
|
-
queryKey: [...fileKey, "find", settled],
|
|
106
|
-
queryFn: () => search(settled),
|
|
107
|
-
enabled: ready, staleTime: Infinity, gcTime: 30_000, retry: false,
|
|
108
|
-
});
|
|
109
|
-
const matches = ready ? result.data?.matches ?? empty : empty;
|
|
110
|
-
const total = matches.length;
|
|
111
|
-
const selected = Math.min(index, Math.max(0, total - 1));
|
|
112
|
-
return {
|
|
113
|
-
...criteria, matches, active: matches[selected], index: selected, total,
|
|
114
|
-
changeQuery, toggle, reset: () => setIndex(0),
|
|
115
|
-
move: (step: number) => {
|
|
116
|
-
if (total) setIndex((prior) => (Math.min(prior, total - 1) + step + total) % total);
|
|
117
|
-
},
|
|
118
|
-
limited: ready && result.data?.limited === true,
|
|
119
|
-
invalid: ready && result.data?.invalidPattern === true,
|
|
120
|
-
error: ready && result.isError,
|
|
121
|
-
pending: !!criteria.query && (!ready || result.isPending),
|
|
122
|
-
retry: () => { void result.refetch(); },
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function ReaderFindPopup({ theme, testID, children }: {
|
|
127
|
-
theme: Theme; testID?: string; children: ReactNode;
|
|
128
|
-
}) {
|
|
129
|
-
return (
|
|
130
|
-
<View pointerEvents="box-none" style={{ position: "absolute", top: 4, left: 4, right: 4, zIndex: 2 }}>
|
|
131
|
-
<View testID={testID} style={{
|
|
132
|
-
alignSelf: "flex-end", width: "100%", maxWidth: 520,
|
|
133
|
-
backgroundColor: theme.colors.surface1, borderColor: theme.colors.border, borderWidth: 1,
|
|
134
|
-
padding: 4, borderRadius: 6, gap: 4,
|
|
135
|
-
}}>{children}</View>
|
|
136
|
-
</View>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function ReaderFindBar({ find, theme, compact, close, testID, option, placeholder, textOptions = true }: {
|
|
141
|
-
find: Omit<ReturnType<typeof useMarkdownFind>, "hits" | "active"> & { limited?: boolean };
|
|
142
|
-
theme: Theme; compact: boolean; close: () => void; testID: string;
|
|
143
|
-
option?: ReactNode; placeholder?: string; textOptions?: boolean;
|
|
144
|
-
}) {
|
|
145
|
-
const { t } = useTranslation(messages);
|
|
146
|
-
const web = Platform.OS === "web";
|
|
147
|
-
const status = !find.query ? "" : find.invalid ? t("invalidPattern") : find.error ? t("findFailed")
|
|
148
|
-
: find.pending ? t("searching") : !find.total ? t(find.limited ? "findLimited" : "noMatches") : "";
|
|
149
|
-
return (
|
|
150
|
-
<ReaderFindPopup theme={theme} testID={testID}>
|
|
151
|
-
<View style={{ flexDirection: "row", alignItems: "center", gap: 3, flexWrap: "wrap" }}>
|
|
152
|
-
<View style={{ flexBasis: 178, flexGrow: 1, flexShrink: 1, flexDirection: "row", alignItems: "center",
|
|
153
|
-
borderWidth: 1, borderColor: find.invalid ? theme.colors.statusDanger : theme.colors.border, borderRadius: 4 }}>
|
|
154
|
-
<ReaderInput theme={theme} value={find.query} onChangeText={find.changeQuery} autoFocus={web}
|
|
155
|
-
autoCorrect={false} autoCapitalize="none" selectTextOnFocus
|
|
156
|
-
accessibilityLabel={t("find")} placeholder={placeholder ?? t("searchPlaceholder")}
|
|
157
|
-
returnKeyType="search" submitBehavior="submit" onSubmitEditing={web ? undefined : () => find.move(1)} maxLength={256}
|
|
158
|
-
style={{ borderWidth: 0, minWidth: 48, paddingHorizontal: 6, minHeight: 28, fontSize: 13 }} />
|
|
159
|
-
<Control title={t("matchCase")} label="Aa" theme={theme} compact={compact} small
|
|
160
|
-
selected={textOptions && find.options.matchCase} disabled={!textOptions} onPress={() => find.toggle("matchCase")} />
|
|
161
|
-
<Control title={t("wholeWord")} label="ab" theme={theme} compact={compact} small
|
|
162
|
-
selected={textOptions && find.options.wholeWord} disabled={!textOptions} onPress={() => find.toggle("wholeWord")} />
|
|
163
|
-
<Control title={t("useRegex")} label=".*" theme={theme} compact={compact} small
|
|
164
|
-
selected={textOptions && find.options.regex} disabled={!textOptions} onPress={() => find.toggle("regex")} />
|
|
165
|
-
{option}
|
|
166
|
-
</View>
|
|
167
|
-
<View style={{ flexDirection: "row", alignItems: "center", gap: 2, marginLeft: "auto" }}>
|
|
168
|
-
{find.total > 0 && (
|
|
169
|
-
<Text testID={`${testID.replace(/-find$/, "")}-match-count`} accessibilityLiveRegion="polite" numberOfLines={1}
|
|
170
|
-
style={{ color: theme.colors.foregroundMuted, fontSize: 12, fontVariant: ["tabular-nums"], paddingHorizontal: 4 }}>
|
|
171
|
-
{find.index + 1} / {find.total}{find.limited ? "+" : ""}
|
|
172
|
-
</Text>
|
|
173
|
-
)}
|
|
174
|
-
<Control title={t("previousMatch")} icon="ArrowUp" theme={theme} compact={compact} small
|
|
175
|
-
disabled={!find.total || find.pending || find.error} onPress={() => find.move(-1)} />
|
|
176
|
-
<Control title={t("nextMatch")} icon="ArrowDown" theme={theme} compact={compact} small
|
|
177
|
-
disabled={!find.total || find.pending || find.error} onPress={() => find.move(1)} />
|
|
178
|
-
<Control title={t("closeFind")} icon="X" theme={theme} compact={compact} small onPress={close} />
|
|
179
|
-
</View>
|
|
180
|
-
</View>
|
|
181
|
-
{!!status && (
|
|
182
|
-
<View style={{ flexDirection: "row", alignItems: "center", gap: 4, paddingHorizontal: 3 }}>
|
|
183
|
-
<Text accessibilityLiveRegion="polite" style={{ flex: 1, fontSize: 12,
|
|
184
|
-
color: find.invalid || find.error ? theme.colors.statusDanger : theme.colors.foregroundMuted }}>{status}</Text>
|
|
185
|
-
{find.error && <Control title={t("retry")} onPress={find.retry} small theme={theme} compact={compact} />}
|
|
186
|
-
</View>
|
|
187
|
-
)}
|
|
188
|
-
</ReaderFindPopup>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
1
|
+
import { useCallback, useEffect, useRef, useState, type ReactNode, type RefObject } from "react";
|
|
2
|
+
import { Keyboard, Platform, Text, View } from "react-native";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
5
|
+
import { useRpc, useTranslation } from "@getpaseo/plugin/client";
|
|
6
|
+
import { markdownSearchPageSize, searchMarkdownFile, type MarkdownSearchOptions } from "../shared/contracts";
|
|
7
|
+
import { Control, ReaderInput, useReaderShortcuts, type Theme } from "./controls";
|
|
8
|
+
import { messages } from "./messages";
|
|
9
|
+
import { bindReaderFind, focusWebReader } from "./web";
|
|
10
|
+
|
|
11
|
+
type SearchTarget = Pick<RpcInput<typeof searchMarkdownFile>, "workspaceId" | "path">;
|
|
12
|
+
export type MarkdownMatch = RpcOutput<typeof searchMarkdownFile>["hits"][number];
|
|
13
|
+
const empty: never[] = [];
|
|
14
|
+
|
|
15
|
+
type FindActions = Omit<Parameters<typeof bindReaderFind>[3], "focusReader">;
|
|
16
|
+
|
|
17
|
+
export function useReaderFindVisibility() {
|
|
18
|
+
const [findOpen, setFindOpen] = useState(false);
|
|
19
|
+
const showFind = useCallback(() => setFindOpen(true), []);
|
|
20
|
+
const hideFind = useCallback(() => {
|
|
21
|
+
if (Platform.OS !== "web") Keyboard.dismiss();
|
|
22
|
+
setFindOpen(false);
|
|
23
|
+
}, []);
|
|
24
|
+
return { findOpen, showFind, hideFind };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useReaderFindShortcuts(root: RefObject<View | null>, testID: string, enabled: boolean, actions: FindActions,
|
|
28
|
+
viewport?: RefObject<View | null>) {
|
|
29
|
+
const current = useRef(actions);
|
|
30
|
+
const shortcuts = useReaderShortcuts();
|
|
31
|
+
current.current = actions;
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!enabled) return;
|
|
34
|
+
return bindReaderFind(root.current, testID, () => shortcuts.current, {
|
|
35
|
+
open: () => current.current.open(), close: () => current.current.close(),
|
|
36
|
+
move: (step) => current.current.move(step), isOpen: () => current.current.isOpen(),
|
|
37
|
+
focusReader: viewport ? () => focusWebReader(viewport.current) : undefined,
|
|
38
|
+
});
|
|
39
|
+
}, [root, testID, enabled, viewport, shortcuts]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function useFindCriteria(open: boolean) {
|
|
43
|
+
const [criteria, setCriteria] = useState({
|
|
44
|
+
query: "", options: { matchCase: false, wholeWord: false, regex: false },
|
|
45
|
+
});
|
|
46
|
+
const [settled, setSettled] = useState(criteria);
|
|
47
|
+
const [index, setIndex] = useState(0);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!open || settled === criteria) return;
|
|
50
|
+
const timeout = setTimeout(() => setSettled(criteria), 180);
|
|
51
|
+
return () => clearTimeout(timeout);
|
|
52
|
+
}, [criteria, open, settled]);
|
|
53
|
+
const ready = open && !!settled.query && criteria === settled;
|
|
54
|
+
return {
|
|
55
|
+
criteria, settled, ready, index, setIndex,
|
|
56
|
+
changeQuery: (query: string) => {
|
|
57
|
+
if (query === criteria.query) return;
|
|
58
|
+
setIndex(0);
|
|
59
|
+
setCriteria((prior) => ({ ...prior, query }));
|
|
60
|
+
},
|
|
61
|
+
toggle: (option: keyof MarkdownSearchOptions) => {
|
|
62
|
+
setIndex(0);
|
|
63
|
+
setCriteria((prior) => ({ ...prior, options: { ...prior.options, [option]: !prior.options[option] } }));
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function useMarkdownFind(target: SearchTarget, fileKey: readonly unknown[], open: boolean) {
|
|
69
|
+
const search = useRpc(searchMarkdownFile);
|
|
70
|
+
const { criteria, settled, ready, index, setIndex, changeQuery, toggle } = useFindCriteria(open);
|
|
71
|
+
const queryPage = (offset: number) => ({
|
|
72
|
+
queryKey: [...fileKey, "find", settled, offset],
|
|
73
|
+
queryFn: () => search({ ...target, ...settled, offset }),
|
|
74
|
+
staleTime: Infinity,
|
|
75
|
+
gcTime: 30_000,
|
|
76
|
+
retry: false,
|
|
77
|
+
});
|
|
78
|
+
const first = useQuery({ ...queryPage(0), enabled: ready });
|
|
79
|
+
const total = ready ? first.data?.total ?? 0 : 0;
|
|
80
|
+
const selected = Math.min(index, Math.max(0, total - 1));
|
|
81
|
+
const offset = Math.floor(selected / markdownSearchPageSize) * markdownSearchPageSize;
|
|
82
|
+
const later = useQuery({ ...queryPage(offset), enabled: ready && !!offset });
|
|
83
|
+
const page = offset ? later : first;
|
|
84
|
+
const hits: MarkdownMatch[] = ready ? page.data?.hits ?? empty : empty;
|
|
85
|
+
return {
|
|
86
|
+
...criteria, hits, active: hits[selected - offset], index: selected, total,
|
|
87
|
+
changeQuery, toggle,
|
|
88
|
+
move: (step: number) => {
|
|
89
|
+
if (total && !page.isFetching) setIndex((prior) => (Math.min(prior, total - 1) + step + total) % total);
|
|
90
|
+
},
|
|
91
|
+
error: ready && page.isError,
|
|
92
|
+
invalid: ready && first.data?.invalidPattern === true,
|
|
93
|
+
pending: !!criteria.query && (!ready || first.isPending || page.isPending),
|
|
94
|
+
retry: () => { void page.refetch(); },
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type FindCriteria = { query: string; options: MarkdownSearchOptions };
|
|
99
|
+
type FindResults<Match> = { matches: Match[]; limited: boolean; invalidPattern: boolean };
|
|
100
|
+
|
|
101
|
+
export function useFindResults<Match>(fileKey: readonly unknown[], open: boolean,
|
|
102
|
+
search: (criteria: FindCriteria) => Promise<FindResults<Match> | null>) {
|
|
103
|
+
const { criteria, settled, ready, index, setIndex, changeQuery, toggle } = useFindCriteria(open);
|
|
104
|
+
const result = useQuery({
|
|
105
|
+
queryKey: [...fileKey, "find", settled],
|
|
106
|
+
queryFn: () => search(settled),
|
|
107
|
+
enabled: ready, staleTime: Infinity, gcTime: 30_000, retry: false,
|
|
108
|
+
});
|
|
109
|
+
const matches = ready ? result.data?.matches ?? empty : empty;
|
|
110
|
+
const total = matches.length;
|
|
111
|
+
const selected = Math.min(index, Math.max(0, total - 1));
|
|
112
|
+
return {
|
|
113
|
+
...criteria, matches, active: matches[selected], index: selected, total,
|
|
114
|
+
changeQuery, toggle, reset: () => setIndex(0),
|
|
115
|
+
move: (step: number) => {
|
|
116
|
+
if (total) setIndex((prior) => (Math.min(prior, total - 1) + step + total) % total);
|
|
117
|
+
},
|
|
118
|
+
limited: ready && result.data?.limited === true,
|
|
119
|
+
invalid: ready && result.data?.invalidPattern === true,
|
|
120
|
+
error: ready && result.isError,
|
|
121
|
+
pending: !!criteria.query && (!ready || result.isPending),
|
|
122
|
+
retry: () => { void result.refetch(); },
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function ReaderFindPopup({ theme, testID, children }: {
|
|
127
|
+
theme: Theme; testID?: string; children: ReactNode;
|
|
128
|
+
}) {
|
|
129
|
+
return (
|
|
130
|
+
<View pointerEvents="box-none" style={{ position: "absolute", top: 4, left: 4, right: 4, zIndex: 2 }}>
|
|
131
|
+
<View testID={testID} style={{
|
|
132
|
+
alignSelf: "flex-end", width: "100%", maxWidth: 520,
|
|
133
|
+
backgroundColor: theme.colors.surface1, borderColor: theme.colors.border, borderWidth: 1,
|
|
134
|
+
padding: 4, borderRadius: 6, gap: 4,
|
|
135
|
+
}}>{children}</View>
|
|
136
|
+
</View>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function ReaderFindBar({ find, theme, compact, close, testID, option, placeholder, textOptions = true }: {
|
|
141
|
+
find: Omit<ReturnType<typeof useMarkdownFind>, "hits" | "active"> & { limited?: boolean };
|
|
142
|
+
theme: Theme; compact: boolean; close: () => void; testID: string;
|
|
143
|
+
option?: ReactNode; placeholder?: string; textOptions?: boolean;
|
|
144
|
+
}) {
|
|
145
|
+
const { t } = useTranslation(messages);
|
|
146
|
+
const web = Platform.OS === "web";
|
|
147
|
+
const status = !find.query ? "" : find.invalid ? t("invalidPattern") : find.error ? t("findFailed")
|
|
148
|
+
: find.pending ? t("searching") : !find.total ? t(find.limited ? "findLimited" : "noMatches") : "";
|
|
149
|
+
return (
|
|
150
|
+
<ReaderFindPopup theme={theme} testID={testID}>
|
|
151
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 3, flexWrap: "wrap" }}>
|
|
152
|
+
<View style={{ flexBasis: 178, flexGrow: 1, flexShrink: 1, flexDirection: "row", alignItems: "center",
|
|
153
|
+
borderWidth: 1, borderColor: find.invalid ? theme.colors.statusDanger : theme.colors.border, borderRadius: 4 }}>
|
|
154
|
+
<ReaderInput theme={theme} value={find.query} onChangeText={find.changeQuery} autoFocus={web}
|
|
155
|
+
autoCorrect={false} autoCapitalize="none" selectTextOnFocus
|
|
156
|
+
accessibilityLabel={t("find")} placeholder={placeholder ?? t("searchPlaceholder")}
|
|
157
|
+
returnKeyType="search" submitBehavior="submit" onSubmitEditing={web ? undefined : () => find.move(1)} maxLength={256}
|
|
158
|
+
style={{ borderWidth: 0, minWidth: 48, paddingHorizontal: 6, minHeight: 28, fontSize: 13 }} />
|
|
159
|
+
<Control title={t("matchCase")} label="Aa" theme={theme} compact={compact} small
|
|
160
|
+
selected={textOptions && find.options.matchCase} disabled={!textOptions} onPress={() => find.toggle("matchCase")} />
|
|
161
|
+
<Control title={t("wholeWord")} label="ab" theme={theme} compact={compact} small
|
|
162
|
+
selected={textOptions && find.options.wholeWord} disabled={!textOptions} onPress={() => find.toggle("wholeWord")} />
|
|
163
|
+
<Control title={t("useRegex")} label=".*" theme={theme} compact={compact} small
|
|
164
|
+
selected={textOptions && find.options.regex} disabled={!textOptions} onPress={() => find.toggle("regex")} />
|
|
165
|
+
{option}
|
|
166
|
+
</View>
|
|
167
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 2, marginLeft: "auto" }}>
|
|
168
|
+
{find.total > 0 && (
|
|
169
|
+
<Text testID={`${testID.replace(/-find$/, "")}-match-count`} accessibilityLiveRegion="polite" numberOfLines={1}
|
|
170
|
+
style={{ color: theme.colors.foregroundMuted, fontSize: 12, fontVariant: ["tabular-nums"], paddingHorizontal: 4 }}>
|
|
171
|
+
{find.index + 1} / {find.total}{find.limited ? "+" : ""}
|
|
172
|
+
</Text>
|
|
173
|
+
)}
|
|
174
|
+
<Control title={t("previousMatch")} icon="ArrowUp" theme={theme} compact={compact} small
|
|
175
|
+
disabled={!find.total || find.pending || find.error} onPress={() => find.move(-1)} />
|
|
176
|
+
<Control title={t("nextMatch")} icon="ArrowDown" theme={theme} compact={compact} small
|
|
177
|
+
disabled={!find.total || find.pending || find.error} onPress={() => find.move(1)} />
|
|
178
|
+
<Control title={t("closeFind")} icon="X" theme={theme} compact={compact} small onPress={close} />
|
|
179
|
+
</View>
|
|
180
|
+
</View>
|
|
181
|
+
{!!status && (
|
|
182
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 4, paddingHorizontal: 3 }}>
|
|
183
|
+
<Text accessibilityLiveRegion="polite" style={{ flex: 1, fontSize: 12,
|
|
184
|
+
color: find.invalid || find.error ? theme.colors.statusDanger : theme.colors.foregroundMuted }}>{status}</Text>
|
|
185
|
+
{find.error && <Control title={t("retry")} onPress={find.retry} small theme={theme} compact={compact} />}
|
|
186
|
+
</View>
|
|
187
|
+
)}
|
|
188
|
+
</ReaderFindPopup>
|
|
189
|
+
);
|
|
190
|
+
}
|
package/client/reader-notice.tsx
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { createContext, useCallback, useContext, useEffect, useRef, useState, type ReactNode } from "react";
|
|
2
|
-
import { Platform, Text, View } from "react-native";
|
|
3
|
-
import { useTranslation } from "@getpaseo/plugin/client";
|
|
4
|
-
import { Icon } from "@getpaseo/plugin/client/ui";
|
|
5
|
-
import type { Theme } from "./controls";
|
|
6
|
-
import { messages } from "./messages";
|
|
7
|
-
import { bindReaderCopy } from "./web";
|
|
8
|
-
|
|
9
|
-
const NoticeContext = createContext<((text: string, error?: boolean) => void) | undefined>(undefined);
|
|
10
|
-
|
|
11
|
-
export function useReaderNotice() {
|
|
12
|
-
return useContext(NoticeContext);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function ReaderNotices({ children, theme }: { children: ReactNode; theme: Theme }) {
|
|
16
|
-
const { t } = useTranslation(messages);
|
|
17
|
-
const root = useRef<View>(null);
|
|
18
|
-
const [notice, setNotice] = useState<{ text: string; error: boolean }>();
|
|
19
|
-
const notify = useCallback((text: string, error = false) => setNotice({ text, error }), []);
|
|
20
|
-
const copied = t("copied");
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (!notice) return;
|
|
23
|
-
const timer = setTimeout(() => setNotice(undefined), 2200);
|
|
24
|
-
return () => clearTimeout(timer);
|
|
25
|
-
}, [notice]);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (Platform.OS === "web") return bindReaderCopy(root.current, () => notify(copied));
|
|
28
|
-
}, [copied, notify]);
|
|
29
|
-
return (
|
|
30
|
-
<View ref={root} style={{ flex: 1, minHeight: 0 }}>
|
|
31
|
-
<NoticeContext.Provider value={notify}>{children}</NoticeContext.Provider>
|
|
32
|
-
{!!notice && (
|
|
33
|
-
<View pointerEvents="none" testID="merong-reader-notice"
|
|
34
|
-
style={{ position: "absolute", left: 0, right: 0, top: 8, alignItems: "center" }}>
|
|
35
|
-
<View style={{ borderRadius: 16, borderWidth: 1, borderColor: theme.colors.border,
|
|
36
|
-
paddingHorizontal: 12, paddingVertical: 8, flexDirection: "row", alignItems: "center", gap: 8,
|
|
37
|
-
backgroundColor: theme.colors.surface0 }}>
|
|
38
|
-
<Icon name={notice.error ? "CircleAlert" : "CheckCircle2"} size={18}
|
|
39
|
-
color={notice.error ? theme.colors.statusDanger : theme.colors.accent} />
|
|
40
|
-
<Text accessibilityLiveRegion="polite" style={{ color: theme.colors.foreground }}>{notice.text}</Text>
|
|
41
|
-
</View>
|
|
42
|
-
</View>
|
|
43
|
-
)}
|
|
44
|
-
</View>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
1
|
+
import { createContext, useCallback, useContext, useEffect, useRef, useState, type ReactNode } from "react";
|
|
2
|
+
import { Platform, Text, View } from "react-native";
|
|
3
|
+
import { useTranslation } from "@getpaseo/plugin/client";
|
|
4
|
+
import { Icon } from "@getpaseo/plugin/client/ui";
|
|
5
|
+
import type { Theme } from "./controls";
|
|
6
|
+
import { messages } from "./messages";
|
|
7
|
+
import { bindReaderCopy } from "./web";
|
|
8
|
+
|
|
9
|
+
const NoticeContext = createContext<((text: string, error?: boolean) => void) | undefined>(undefined);
|
|
10
|
+
|
|
11
|
+
export function useReaderNotice() {
|
|
12
|
+
return useContext(NoticeContext);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function ReaderNotices({ children, theme }: { children: ReactNode; theme: Theme }) {
|
|
16
|
+
const { t } = useTranslation(messages);
|
|
17
|
+
const root = useRef<View>(null);
|
|
18
|
+
const [notice, setNotice] = useState<{ text: string; error: boolean }>();
|
|
19
|
+
const notify = useCallback((text: string, error = false) => setNotice({ text, error }), []);
|
|
20
|
+
const copied = t("copied");
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!notice) return;
|
|
23
|
+
const timer = setTimeout(() => setNotice(undefined), 2200);
|
|
24
|
+
return () => clearTimeout(timer);
|
|
25
|
+
}, [notice]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (Platform.OS === "web") return bindReaderCopy(root.current, () => notify(copied));
|
|
28
|
+
}, [copied, notify]);
|
|
29
|
+
return (
|
|
30
|
+
<View ref={root} style={{ flex: 1, minHeight: 0 }}>
|
|
31
|
+
<NoticeContext.Provider value={notify}>{children}</NoticeContext.Provider>
|
|
32
|
+
{!!notice && (
|
|
33
|
+
<View pointerEvents="none" testID="merong-reader-notice"
|
|
34
|
+
style={{ position: "absolute", left: 0, right: 0, top: 8, alignItems: "center" }}>
|
|
35
|
+
<View style={{ borderRadius: 16, borderWidth: 1, borderColor: theme.colors.border,
|
|
36
|
+
paddingHorizontal: 12, paddingVertical: 8, flexDirection: "row", alignItems: "center", gap: 8,
|
|
37
|
+
backgroundColor: theme.colors.surface0 }}>
|
|
38
|
+
<Icon name={notice.error ? "CircleAlert" : "CheckCircle2"} size={18}
|
|
39
|
+
color={notice.error ? theme.colors.statusDanger : theme.colors.accent} />
|
|
40
|
+
<Text accessibilityLiveRegion="polite" style={{ color: theme.colors.foreground }}>{notice.text}</Text>
|
|
41
|
+
</View>
|
|
42
|
+
</View>
|
|
43
|
+
)}
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
}
|