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/zoom-controls.tsx
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
-
import { Keyboard, Platform, Text, TextInput, View, type GestureResponderEvent, type ViewStyle } from "react-native";
|
|
3
|
-
import { useTranslation } from "@getpaseo/plugin/client";
|
|
4
|
-
import { Control, useWebTitle, type Theme } from "./controls";
|
|
5
|
-
import { messages } from "./messages";
|
|
6
|
-
import { clamp, maxZoomPercent, minZoomPercent } from "./viewport-geometry";
|
|
7
|
-
import { bindWebSliderKeys } from "./web";
|
|
8
|
-
|
|
9
|
-
const trackInset = 8;
|
|
10
|
-
|
|
11
|
-
function sliderPosition(percent: number) {
|
|
12
|
-
return percent <= 100
|
|
13
|
-
? (percent - minZoomPercent) / (100 - minZoomPercent) / 2
|
|
14
|
-
: 0.5 + (percent - 100) / (maxZoomPercent - 100) / 2;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function ZoomSlider({ value, disabled, compact, theme, change }: {
|
|
18
|
-
value: number; disabled: boolean; compact: boolean; theme: Theme; change: (percent: number) => void;
|
|
19
|
-
}) {
|
|
20
|
-
const { t } = useTranslation(messages);
|
|
21
|
-
const label = t("zoomSlider");
|
|
22
|
-
const slider = useWebTitle(label);
|
|
23
|
-
const width = useRef(0);
|
|
24
|
-
const left = useRef(0);
|
|
25
|
-
const changeRef = useRef(change);
|
|
26
|
-
const web = Platform.OS === "web";
|
|
27
|
-
const percent = clamp(value, minZoomPercent, maxZoomPercent);
|
|
28
|
-
const position = `${sliderPosition(percent) * 100}%` as const;
|
|
29
|
-
useLayoutEffect(() => { changeRef.current = change; }, [change]);
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (web && !disabled) return bindWebSliderKeys(slider.current, (value) => changeRef.current(value));
|
|
32
|
-
}, [web, disabled, slider]);
|
|
33
|
-
|
|
34
|
-
const move = ({ nativeEvent }: GestureResponderEvent) => {
|
|
35
|
-
if (width.current <= trackInset * 2) return;
|
|
36
|
-
const fraction = clamp((nativeEvent.pageX - left.current - trackInset) / (width.current - trackInset * 2), 0, 1);
|
|
37
|
-
const next = fraction <= 0.5
|
|
38
|
-
? minZoomPercent + fraction * 2 * (100 - minZoomPercent)
|
|
39
|
-
: 100 + (fraction - 0.5) * 2 * (maxZoomPercent - 100);
|
|
40
|
-
change(Math.round(next));
|
|
41
|
-
};
|
|
42
|
-
return (
|
|
43
|
-
<View
|
|
44
|
-
ref={slider}
|
|
45
|
-
testID="merong-zoom-slider"
|
|
46
|
-
accessible
|
|
47
|
-
role="slider"
|
|
48
|
-
accessibilityRole="adjustable"
|
|
49
|
-
accessibilityLabel={label}
|
|
50
|
-
aria-valuemin={minZoomPercent}
|
|
51
|
-
aria-valuemax={maxZoomPercent}
|
|
52
|
-
aria-valuenow={percent}
|
|
53
|
-
aria-valuetext={`${value}%`}
|
|
54
|
-
accessibilityState={{ disabled }}
|
|
55
|
-
accessibilityActions={[{ name: "increment" }, { name: "decrement" }]}
|
|
56
|
-
onAccessibilityAction={({ nativeEvent }) => {
|
|
57
|
-
if (!disabled) change(percent + (nativeEvent.actionName === "increment" ? 5 : -5));
|
|
58
|
-
}}
|
|
59
|
-
tabIndex={web ? disabled ? -1 : 0 : undefined}
|
|
60
|
-
onLayout={({ nativeEvent }) => { width.current = nativeEvent.layout.width; }}
|
|
61
|
-
onStartShouldSetResponder={() => !disabled}
|
|
62
|
-
onResponderGrant={(event) => {
|
|
63
|
-
const { pageX, locationX } = event.nativeEvent;
|
|
64
|
-
left.current = pageX - locationX;
|
|
65
|
-
move(event);
|
|
66
|
-
}}
|
|
67
|
-
onResponderMove={move}
|
|
68
|
-
onResponderTerminationRequest={() => false}
|
|
69
|
-
style={[
|
|
70
|
-
{
|
|
71
|
-
width: compact ? 104 : 116, minWidth: web ? 64 : 28, flexShrink: 1,
|
|
72
|
-
height: web && compact ? 40 : 32, justifyContent: "center", opacity: disabled ? 0.45 : 1,
|
|
73
|
-
},
|
|
74
|
-
web && ({ touchAction: "none", cursor: disabled ? "default" : "pointer" } as ViewStyle),
|
|
75
|
-
]}
|
|
76
|
-
>
|
|
77
|
-
<View pointerEvents="none" style={{
|
|
78
|
-
marginHorizontal: trackInset, height: 4, borderRadius: 2, backgroundColor: theme.colors.border,
|
|
79
|
-
}}>
|
|
80
|
-
<View style={{ position: "absolute", left: "50%", top: -3, width: 1, height: 10, backgroundColor: theme.colors.foregroundMuted }} />
|
|
81
|
-
<View style={{
|
|
82
|
-
position: "absolute", left: position, top: -5, width: 14, height: 14, marginLeft: -7,
|
|
83
|
-
borderRadius: 7, backgroundColor: theme.colors.foreground,
|
|
84
|
-
}} />
|
|
85
|
-
</View>
|
|
86
|
-
</View>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function ZoomControls({ scale, disabled, compact, theme, stepZoom, setZoom }: {
|
|
91
|
-
scale: number; disabled: boolean; compact: boolean; theme: Theme;
|
|
92
|
-
stepZoom: (factor: number) => void; setZoom: (scale: number) => void;
|
|
93
|
-
}) {
|
|
94
|
-
const { t } = useTranslation(messages);
|
|
95
|
-
const label = t("zoomPercent");
|
|
96
|
-
const field = useWebTitle(label);
|
|
97
|
-
const [draft, setDraft] = useState<string>();
|
|
98
|
-
const web = Platform.OS === "web";
|
|
99
|
-
const percent = Math.round(scale * 100);
|
|
100
|
-
const apply = (percent: number) => setZoom(clamp(percent, minZoomPercent, maxZoomPercent) / 100);
|
|
101
|
-
const commit = () => {
|
|
102
|
-
const value = draft?.trim().replace(/%$/, "").trim();
|
|
103
|
-
if (value && /^\d+$/.test(value)) apply(Number(value));
|
|
104
|
-
setDraft(undefined);
|
|
105
|
-
};
|
|
106
|
-
return (
|
|
107
|
-
<View style={{ flexDirection: "row", flexShrink: 1, alignItems: "center", gap: 3 }}>
|
|
108
|
-
<Control title={t("zoomOut")} icon="Minus" small={!web} disabled={disabled || percent <= minZoomPercent}
|
|
109
|
-
onPress={() => stepZoom(1 / 1.25)} theme={theme} compact={compact} />
|
|
110
|
-
<ZoomSlider value={percent} change={apply} disabled={disabled} compact={compact} theme={theme} />
|
|
111
|
-
{!web && draft !== undefined
|
|
112
|
-
? <Control title={t("applyZoom")} icon="Check" theme={theme} compact={compact} small disabled={disabled}
|
|
113
|
-
onPress={() => { commit(); Keyboard.dismiss(); }} />
|
|
114
|
-
: <Control title={t("zoomIn")} icon="Plus" small={!web} disabled={disabled || percent >= maxZoomPercent}
|
|
115
|
-
onPress={() => stepZoom(1.25)} theme={theme} compact={compact} />}
|
|
116
|
-
<View ref={field} style={{
|
|
117
|
-
flexDirection: "row", alignItems: "center", gap: 4, height: web && compact ? 36 : 28, width: 62,
|
|
118
|
-
borderWidth: 1, borderRadius: 5, borderColor: theme.colors.border, paddingRight: 5,
|
|
119
|
-
opacity: disabled ? 0.45 : 1,
|
|
120
|
-
}}>
|
|
121
|
-
<TextInput
|
|
122
|
-
accessibilityLabel={label}
|
|
123
|
-
testID="merong-pdf-zoom"
|
|
124
|
-
value={draft ?? (disabled ? "" : String(percent))}
|
|
125
|
-
editable={!disabled}
|
|
126
|
-
inputMode="numeric"
|
|
127
|
-
keyboardType="number-pad"
|
|
128
|
-
returnKeyType="done"
|
|
129
|
-
maxLength={7}
|
|
130
|
-
selectTextOnFocus
|
|
131
|
-
onChangeText={setDraft}
|
|
132
|
-
onSubmitEditing={commit}
|
|
133
|
-
onBlur={commit}
|
|
134
|
-
style={{ flex: 1, minWidth: 0, color: theme.colors.foreground, textAlign: "right", fontSize: 13, paddingVertical: 0 }}
|
|
135
|
-
/>
|
|
136
|
-
<Text importantForAccessibility="no" style={{ fontSize: 13, color: theme.colors.foregroundMuted }}>%</Text>
|
|
137
|
-
</View>
|
|
138
|
-
</View>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { Keyboard, Platform, Text, TextInput, View, type GestureResponderEvent, type ViewStyle } from "react-native";
|
|
3
|
+
import { useTranslation } from "@getpaseo/plugin/client";
|
|
4
|
+
import { Control, useWebTitle, type Theme } from "./controls";
|
|
5
|
+
import { messages } from "./messages";
|
|
6
|
+
import { clamp, maxZoomPercent, minZoomPercent } from "./viewport-geometry";
|
|
7
|
+
import { bindWebSliderKeys } from "./web";
|
|
8
|
+
|
|
9
|
+
const trackInset = 8;
|
|
10
|
+
|
|
11
|
+
function sliderPosition(percent: number) {
|
|
12
|
+
return percent <= 100
|
|
13
|
+
? (percent - minZoomPercent) / (100 - minZoomPercent) / 2
|
|
14
|
+
: 0.5 + (percent - 100) / (maxZoomPercent - 100) / 2;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function ZoomSlider({ value, disabled, compact, theme, change }: {
|
|
18
|
+
value: number; disabled: boolean; compact: boolean; theme: Theme; change: (percent: number) => void;
|
|
19
|
+
}) {
|
|
20
|
+
const { t } = useTranslation(messages);
|
|
21
|
+
const label = t("zoomSlider");
|
|
22
|
+
const slider = useWebTitle(label);
|
|
23
|
+
const width = useRef(0);
|
|
24
|
+
const left = useRef(0);
|
|
25
|
+
const changeRef = useRef(change);
|
|
26
|
+
const web = Platform.OS === "web";
|
|
27
|
+
const percent = clamp(value, minZoomPercent, maxZoomPercent);
|
|
28
|
+
const position = `${sliderPosition(percent) * 100}%` as const;
|
|
29
|
+
useLayoutEffect(() => { changeRef.current = change; }, [change]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (web && !disabled) return bindWebSliderKeys(slider.current, (value) => changeRef.current(value));
|
|
32
|
+
}, [web, disabled, slider]);
|
|
33
|
+
|
|
34
|
+
const move = ({ nativeEvent }: GestureResponderEvent) => {
|
|
35
|
+
if (width.current <= trackInset * 2) return;
|
|
36
|
+
const fraction = clamp((nativeEvent.pageX - left.current - trackInset) / (width.current - trackInset * 2), 0, 1);
|
|
37
|
+
const next = fraction <= 0.5
|
|
38
|
+
? minZoomPercent + fraction * 2 * (100 - minZoomPercent)
|
|
39
|
+
: 100 + (fraction - 0.5) * 2 * (maxZoomPercent - 100);
|
|
40
|
+
change(Math.round(next));
|
|
41
|
+
};
|
|
42
|
+
return (
|
|
43
|
+
<View
|
|
44
|
+
ref={slider}
|
|
45
|
+
testID="merong-zoom-slider"
|
|
46
|
+
accessible
|
|
47
|
+
role="slider"
|
|
48
|
+
accessibilityRole="adjustable"
|
|
49
|
+
accessibilityLabel={label}
|
|
50
|
+
aria-valuemin={minZoomPercent}
|
|
51
|
+
aria-valuemax={maxZoomPercent}
|
|
52
|
+
aria-valuenow={percent}
|
|
53
|
+
aria-valuetext={`${value}%`}
|
|
54
|
+
accessibilityState={{ disabled }}
|
|
55
|
+
accessibilityActions={[{ name: "increment" }, { name: "decrement" }]}
|
|
56
|
+
onAccessibilityAction={({ nativeEvent }) => {
|
|
57
|
+
if (!disabled) change(percent + (nativeEvent.actionName === "increment" ? 5 : -5));
|
|
58
|
+
}}
|
|
59
|
+
tabIndex={web ? disabled ? -1 : 0 : undefined}
|
|
60
|
+
onLayout={({ nativeEvent }) => { width.current = nativeEvent.layout.width; }}
|
|
61
|
+
onStartShouldSetResponder={() => !disabled}
|
|
62
|
+
onResponderGrant={(event) => {
|
|
63
|
+
const { pageX, locationX } = event.nativeEvent;
|
|
64
|
+
left.current = pageX - locationX;
|
|
65
|
+
move(event);
|
|
66
|
+
}}
|
|
67
|
+
onResponderMove={move}
|
|
68
|
+
onResponderTerminationRequest={() => false}
|
|
69
|
+
style={[
|
|
70
|
+
{
|
|
71
|
+
width: compact ? 104 : 116, minWidth: web ? 64 : 28, flexShrink: 1,
|
|
72
|
+
height: web && compact ? 40 : 32, justifyContent: "center", opacity: disabled ? 0.45 : 1,
|
|
73
|
+
},
|
|
74
|
+
web && ({ touchAction: "none", cursor: disabled ? "default" : "pointer" } as ViewStyle),
|
|
75
|
+
]}
|
|
76
|
+
>
|
|
77
|
+
<View pointerEvents="none" style={{
|
|
78
|
+
marginHorizontal: trackInset, height: 4, borderRadius: 2, backgroundColor: theme.colors.border,
|
|
79
|
+
}}>
|
|
80
|
+
<View style={{ position: "absolute", left: "50%", top: -3, width: 1, height: 10, backgroundColor: theme.colors.foregroundMuted }} />
|
|
81
|
+
<View style={{
|
|
82
|
+
position: "absolute", left: position, top: -5, width: 14, height: 14, marginLeft: -7,
|
|
83
|
+
borderRadius: 7, backgroundColor: theme.colors.foreground,
|
|
84
|
+
}} />
|
|
85
|
+
</View>
|
|
86
|
+
</View>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function ZoomControls({ scale, disabled, compact, theme, stepZoom, setZoom }: {
|
|
91
|
+
scale: number; disabled: boolean; compact: boolean; theme: Theme;
|
|
92
|
+
stepZoom: (factor: number) => void; setZoom: (scale: number) => void;
|
|
93
|
+
}) {
|
|
94
|
+
const { t } = useTranslation(messages);
|
|
95
|
+
const label = t("zoomPercent");
|
|
96
|
+
const field = useWebTitle(label);
|
|
97
|
+
const [draft, setDraft] = useState<string>();
|
|
98
|
+
const web = Platform.OS === "web";
|
|
99
|
+
const percent = Math.round(scale * 100);
|
|
100
|
+
const apply = (percent: number) => setZoom(clamp(percent, minZoomPercent, maxZoomPercent) / 100);
|
|
101
|
+
const commit = () => {
|
|
102
|
+
const value = draft?.trim().replace(/%$/, "").trim();
|
|
103
|
+
if (value && /^\d+$/.test(value)) apply(Number(value));
|
|
104
|
+
setDraft(undefined);
|
|
105
|
+
};
|
|
106
|
+
return (
|
|
107
|
+
<View style={{ flexDirection: "row", flexShrink: 1, alignItems: "center", gap: 3 }}>
|
|
108
|
+
<Control title={t("zoomOut")} icon="Minus" small={!web} disabled={disabled || percent <= minZoomPercent}
|
|
109
|
+
onPress={() => stepZoom(1 / 1.25)} theme={theme} compact={compact} />
|
|
110
|
+
<ZoomSlider value={percent} change={apply} disabled={disabled} compact={compact} theme={theme} />
|
|
111
|
+
{!web && draft !== undefined
|
|
112
|
+
? <Control title={t("applyZoom")} icon="Check" theme={theme} compact={compact} small disabled={disabled}
|
|
113
|
+
onPress={() => { commit(); Keyboard.dismiss(); }} />
|
|
114
|
+
: <Control title={t("zoomIn")} icon="Plus" small={!web} disabled={disabled || percent >= maxZoomPercent}
|
|
115
|
+
onPress={() => stepZoom(1.25)} theme={theme} compact={compact} />}
|
|
116
|
+
<View ref={field} style={{
|
|
117
|
+
flexDirection: "row", alignItems: "center", gap: 4, height: web && compact ? 36 : 28, width: 62,
|
|
118
|
+
borderWidth: 1, borderRadius: 5, borderColor: theme.colors.border, paddingRight: 5,
|
|
119
|
+
opacity: disabled ? 0.45 : 1,
|
|
120
|
+
}}>
|
|
121
|
+
<TextInput
|
|
122
|
+
accessibilityLabel={label}
|
|
123
|
+
testID="merong-pdf-zoom"
|
|
124
|
+
value={draft ?? (disabled ? "" : String(percent))}
|
|
125
|
+
editable={!disabled}
|
|
126
|
+
inputMode="numeric"
|
|
127
|
+
keyboardType="number-pad"
|
|
128
|
+
returnKeyType="done"
|
|
129
|
+
maxLength={7}
|
|
130
|
+
selectTextOnFocus
|
|
131
|
+
onChangeText={setDraft}
|
|
132
|
+
onSubmitEditing={commit}
|
|
133
|
+
onBlur={commit}
|
|
134
|
+
style={{ flex: 1, minWidth: 0, color: theme.colors.foreground, textAlign: "right", fontSize: 13, paddingVertical: 0 }}
|
|
135
|
+
/>
|
|
136
|
+
<Text importantForAccessibility="no" style={{ fontSize: 13, color: theme.colors.foregroundMuted }}>%</Text>
|
|
137
|
+
</View>
|
|
138
|
+
</View>
|
|
139
|
+
);
|
|
140
|
+
}
|
package/index.client.tsx
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
-
import { fileReader } from "./client/file-reader";
|
|
3
|
-
import { messages } from "./client/messages";
|
|
4
|
-
import { OfficePanel, PdfPanel } from "./client/pdf-panel";
|
|
5
|
-
import { MarkdownPanel } from "./client/markdown-panel";
|
|
6
|
-
import { ReaderSettings } from "./client/settings";
|
|
7
|
-
import { WorksheetPanel } from "./client/worksheet-panel";
|
|
8
|
-
import { markdownExtensions, officeExtensions } from "./shared/contracts";
|
|
9
|
-
|
|
10
|
-
const pdfReader = fileReader(PdfPanel);
|
|
11
|
-
const documentReader = fileReader((props) =>
|
|
12
|
-
props.file.extension === "xlsx" ? <WorksheetPanel {...props} /> : <OfficePanel {...props} />);
|
|
13
|
-
const markdownReader = fileReader(MarkdownPanel);
|
|
14
|
-
const defaultReader = { preferByDefault: true };
|
|
15
|
-
const markdownNavigation = { handlesLineNavigation: true };
|
|
16
|
-
|
|
17
|
-
export default function contribute(client: PluginClientContext) {
|
|
18
|
-
const registrations = [
|
|
19
|
-
client.addSettingsScreen({
|
|
20
|
-
id: "reader", title: messages.message("readerSettings"), icon: "BookOpenText", Component: ReaderSettings,
|
|
21
|
-
}),
|
|
22
|
-
client.addFilePanel({
|
|
23
|
-
id: "pdf", title: messages.message("pdf"), icon: "FileText",
|
|
24
|
-
...defaultReader, files: { extensions: ["pdf"] }, Component: pdfReader,
|
|
25
|
-
}),
|
|
26
|
-
client.addFilePanel({
|
|
27
|
-
id: "document", title: messages.message("document"), icon: "FileText",
|
|
28
|
-
...defaultReader, files: { extensions: officeExtensions }, Component: documentReader,
|
|
29
|
-
}),
|
|
30
|
-
client.addFilePanel({
|
|
31
|
-
id: "markdown", title: messages.message("markdown"), icon: "BookOpenText",
|
|
32
|
-
...defaultReader, ...markdownNavigation, files: { extensions: markdownExtensions }, Component: markdownReader,
|
|
33
|
-
}),
|
|
34
|
-
];
|
|
35
|
-
return () => { for (const remove of registrations.reverse()) remove(); };
|
|
36
|
-
}
|
|
1
|
+
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
import { fileReader } from "./client/file-reader";
|
|
3
|
+
import { messages } from "./client/messages";
|
|
4
|
+
import { OfficePanel, PdfPanel } from "./client/pdf-panel";
|
|
5
|
+
import { MarkdownPanel } from "./client/markdown-panel";
|
|
6
|
+
import { ReaderSettings } from "./client/settings";
|
|
7
|
+
import { WorksheetPanel } from "./client/worksheet-panel";
|
|
8
|
+
import { markdownExtensions, officeExtensions } from "./shared/contracts";
|
|
9
|
+
|
|
10
|
+
const pdfReader = fileReader(PdfPanel);
|
|
11
|
+
const documentReader = fileReader((props) =>
|
|
12
|
+
props.file.extension === "xlsx" ? <WorksheetPanel {...props} /> : <OfficePanel {...props} />);
|
|
13
|
+
const markdownReader = fileReader(MarkdownPanel);
|
|
14
|
+
const defaultReader = { preferByDefault: true };
|
|
15
|
+
const markdownNavigation = { handlesLineNavigation: true };
|
|
16
|
+
|
|
17
|
+
export default function contribute(client: PluginClientContext) {
|
|
18
|
+
const registrations = [
|
|
19
|
+
client.addSettingsScreen({
|
|
20
|
+
id: "reader", title: messages.message("readerSettings"), icon: "BookOpenText", Component: ReaderSettings,
|
|
21
|
+
}),
|
|
22
|
+
client.addFilePanel({
|
|
23
|
+
id: "pdf", title: messages.message("pdf"), icon: "FileText",
|
|
24
|
+
...defaultReader, files: { extensions: ["pdf"] }, Component: pdfReader,
|
|
25
|
+
}),
|
|
26
|
+
client.addFilePanel({
|
|
27
|
+
id: "document", title: messages.message("document"), icon: "FileText",
|
|
28
|
+
...defaultReader, files: { extensions: officeExtensions }, Component: documentReader,
|
|
29
|
+
}),
|
|
30
|
+
client.addFilePanel({
|
|
31
|
+
id: "markdown", title: messages.message("markdown"), icon: "BookOpenText",
|
|
32
|
+
...defaultReader, ...markdownNavigation, files: { extensions: markdownExtensions }, Component: markdownReader,
|
|
33
|
+
}),
|
|
34
|
+
];
|
|
35
|
+
return () => { for (const remove of registrations.reverse()) remove(); };
|
|
36
|
+
}
|
package/index.server.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { extname } from "node:path";
|
|
2
|
-
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
3
|
-
import {
|
|
4
|
-
findDocumentText, findWorksheetText, openWorkspaceFile, readDocumentLayout, readDocumentText, readMarkdownInfo, readMarkdownPage, readMarkdownSource,
|
|
5
|
-
readStructuredDocument, readWorksheet, renderOfficePage, renderPdfPage, searchMarkdownFile,
|
|
6
|
-
} from "./shared/contracts";
|
|
7
|
-
import { readerSettings } from "./shared/reader-settings";
|
|
8
|
-
import { createEngine } from "./server/engine";
|
|
9
|
-
import { createOfficePreview } from "./server/office-preview";
|
|
10
|
-
import { openWithDefaultApp } from "./server/external-file";
|
|
11
|
-
import { loadMarkdownInfo, loadMarkdownSource } from "./server/markdown-index";
|
|
12
|
-
import { loadMarkdownPage } from "./server/markdown-page";
|
|
13
|
-
import { workspaceDirectory } from "./server/workspace-file";
|
|
14
|
-
|
|
15
|
-
const isPdf = (path: string) => extname(path).toLowerCase() === ".pdf";
|
|
16
|
-
|
|
17
|
-
export default function contribute(server: PluginServerContext) {
|
|
18
|
-
server.registerSettings(readerSettings);
|
|
19
|
-
const engine = createEngine();
|
|
20
|
-
const office = createOfficePreview(engine);
|
|
21
|
-
server.handle(openWorkspaceFile, async ({ workspaceId, path }, { paseo }) => {
|
|
22
|
-
await openWithDefaultApp(await workspaceDirectory(paseo, workspaceId), path);
|
|
23
|
-
return { opened: true as const };
|
|
24
|
-
});
|
|
25
|
-
server.handle(readMarkdownPage, async ({ workspaceId, path, offset, revision, fence, table, firstLine, atLine }, { paseo }) =>
|
|
26
|
-
loadMarkdownPage(await workspaceDirectory(paseo, workspaceId), path, offset, revision, fence, table, firstLine, atLine),
|
|
27
|
-
);
|
|
28
|
-
server.handle(readMarkdownInfo, async ({ workspaceId, path }, { paseo }) =>
|
|
29
|
-
loadMarkdownInfo(await workspaceDirectory(paseo, workspaceId), path),
|
|
30
|
-
);
|
|
31
|
-
server.handle(readMarkdownSource, async ({ workspaceId, path, line, through }, { paseo }) =>
|
|
32
|
-
loadMarkdownSource(await workspaceDirectory(paseo, workspaceId), path, line, through),
|
|
33
|
-
);
|
|
34
|
-
server.handle(searchMarkdownFile, async ({ workspaceId, path, ...input }, { paseo }) =>
|
|
35
|
-
engine.dispatch({ kind: "markdown-search", root: await workspaceDirectory(paseo, workspaceId), path, ...input }),
|
|
36
|
-
);
|
|
37
|
-
server.handle(readDocumentLayout, async ({ workspaceId, path }, { paseo }) => {
|
|
38
|
-
const root = await workspaceDirectory(paseo, workspaceId);
|
|
39
|
-
return isPdf(path)
|
|
40
|
-
? engine.dispatch({ kind: "pdf-layout", root, path })
|
|
41
|
-
: office.layoutStatus(root, path);
|
|
42
|
-
});
|
|
43
|
-
server.handle(renderPdfPage, async ({ workspaceId, path, page, pixels }, { paseo }) =>
|
|
44
|
-
engine.dispatch({ kind: "pdf", root: await workspaceDirectory(paseo, workspaceId), path, page, pixels }),
|
|
45
|
-
);
|
|
46
|
-
server.handle(renderOfficePage, async ({ workspaceId, path, page, pixels }, { paseo }) =>
|
|
47
|
-
office.page(await workspaceDirectory(paseo, workspaceId), path, page, pixels),
|
|
48
|
-
);
|
|
49
|
-
server.handle(readDocumentText, async ({ workspaceId, path, page }, { paseo }) => {
|
|
50
|
-
const root = await workspaceDirectory(paseo, workspaceId);
|
|
51
|
-
return isPdf(path)
|
|
52
|
-
? engine.dispatch({ kind: "pdf-text", root, path, page }) : office.text(root, path, page);
|
|
53
|
-
});
|
|
54
|
-
server.handle(findDocumentText, async ({ workspaceId, path, query, options }, { paseo }) => {
|
|
55
|
-
const root = await workspaceDirectory(paseo, workspaceId);
|
|
56
|
-
return isPdf(path)
|
|
57
|
-
? engine.dispatch({ kind: "pdf-search", root, path, query, options })
|
|
58
|
-
: office.search(root, path, query, options);
|
|
59
|
-
});
|
|
60
|
-
server.handle(readStructuredDocument, async ({ workspaceId, path }, { paseo }) =>
|
|
61
|
-
engine.dispatch({ kind: "document", root: await workspaceDirectory(paseo, workspaceId), path }),
|
|
62
|
-
);
|
|
63
|
-
server.handle(readWorksheet, async ({ workspaceId, path, sheet }, { paseo }) =>
|
|
64
|
-
engine.dispatch({ kind: "worksheet", root: await workspaceDirectory(paseo, workspaceId), path, sheet }),
|
|
65
|
-
);
|
|
66
|
-
server.handle(findWorksheetText, async ({ workspaceId, path, ...input }, { paseo }) =>
|
|
67
|
-
engine.dispatch({ kind: "worksheet-search", root: await workspaceDirectory(paseo, workspaceId), path, ...input }),
|
|
68
|
-
);
|
|
69
|
-
return () => {
|
|
70
|
-
office.stop();
|
|
71
|
-
engine.stop();
|
|
72
|
-
};
|
|
73
|
-
}
|
|
1
|
+
import { extname } from "node:path";
|
|
2
|
+
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
3
|
+
import {
|
|
4
|
+
findDocumentText, findWorksheetText, openWorkspaceFile, readDocumentLayout, readDocumentText, readMarkdownInfo, readMarkdownPage, readMarkdownSource,
|
|
5
|
+
readStructuredDocument, readWorksheet, renderOfficePage, renderPdfPage, searchMarkdownFile,
|
|
6
|
+
} from "./shared/contracts";
|
|
7
|
+
import { readerSettings } from "./shared/reader-settings";
|
|
8
|
+
import { createEngine } from "./server/engine";
|
|
9
|
+
import { createOfficePreview } from "./server/office-preview";
|
|
10
|
+
import { openWithDefaultApp } from "./server/external-file";
|
|
11
|
+
import { loadMarkdownInfo, loadMarkdownSource } from "./server/markdown-index";
|
|
12
|
+
import { loadMarkdownPage } from "./server/markdown-page";
|
|
13
|
+
import { workspaceDirectory } from "./server/workspace-file";
|
|
14
|
+
|
|
15
|
+
const isPdf = (path: string) => extname(path).toLowerCase() === ".pdf";
|
|
16
|
+
|
|
17
|
+
export default function contribute(server: PluginServerContext) {
|
|
18
|
+
server.registerSettings(readerSettings);
|
|
19
|
+
const engine = createEngine();
|
|
20
|
+
const office = createOfficePreview(engine);
|
|
21
|
+
server.handle(openWorkspaceFile, async ({ workspaceId, path }, { paseo }) => {
|
|
22
|
+
await openWithDefaultApp(await workspaceDirectory(paseo, workspaceId), path);
|
|
23
|
+
return { opened: true as const };
|
|
24
|
+
});
|
|
25
|
+
server.handle(readMarkdownPage, async ({ workspaceId, path, offset, revision, fence, table, firstLine, atLine }, { paseo }) =>
|
|
26
|
+
loadMarkdownPage(await workspaceDirectory(paseo, workspaceId), path, offset, revision, fence, table, firstLine, atLine),
|
|
27
|
+
);
|
|
28
|
+
server.handle(readMarkdownInfo, async ({ workspaceId, path }, { paseo }) =>
|
|
29
|
+
loadMarkdownInfo(await workspaceDirectory(paseo, workspaceId), path),
|
|
30
|
+
);
|
|
31
|
+
server.handle(readMarkdownSource, async ({ workspaceId, path, line, through }, { paseo }) =>
|
|
32
|
+
loadMarkdownSource(await workspaceDirectory(paseo, workspaceId), path, line, through),
|
|
33
|
+
);
|
|
34
|
+
server.handle(searchMarkdownFile, async ({ workspaceId, path, ...input }, { paseo }) =>
|
|
35
|
+
engine.dispatch({ kind: "markdown-search", root: await workspaceDirectory(paseo, workspaceId), path, ...input }),
|
|
36
|
+
);
|
|
37
|
+
server.handle(readDocumentLayout, async ({ workspaceId, path }, { paseo }) => {
|
|
38
|
+
const root = await workspaceDirectory(paseo, workspaceId);
|
|
39
|
+
return isPdf(path)
|
|
40
|
+
? engine.dispatch({ kind: "pdf-layout", root, path })
|
|
41
|
+
: office.layoutStatus(root, path);
|
|
42
|
+
});
|
|
43
|
+
server.handle(renderPdfPage, async ({ workspaceId, path, page, pixels }, { paseo }) =>
|
|
44
|
+
engine.dispatch({ kind: "pdf", root: await workspaceDirectory(paseo, workspaceId), path, page, pixels }),
|
|
45
|
+
);
|
|
46
|
+
server.handle(renderOfficePage, async ({ workspaceId, path, page, pixels }, { paseo }) =>
|
|
47
|
+
office.page(await workspaceDirectory(paseo, workspaceId), path, page, pixels),
|
|
48
|
+
);
|
|
49
|
+
server.handle(readDocumentText, async ({ workspaceId, path, page }, { paseo }) => {
|
|
50
|
+
const root = await workspaceDirectory(paseo, workspaceId);
|
|
51
|
+
return isPdf(path)
|
|
52
|
+
? engine.dispatch({ kind: "pdf-text", root, path, page }) : office.text(root, path, page);
|
|
53
|
+
});
|
|
54
|
+
server.handle(findDocumentText, async ({ workspaceId, path, query, options }, { paseo }) => {
|
|
55
|
+
const root = await workspaceDirectory(paseo, workspaceId);
|
|
56
|
+
return isPdf(path)
|
|
57
|
+
? engine.dispatch({ kind: "pdf-search", root, path, query, options })
|
|
58
|
+
: office.search(root, path, query, options);
|
|
59
|
+
});
|
|
60
|
+
server.handle(readStructuredDocument, async ({ workspaceId, path }, { paseo }) =>
|
|
61
|
+
engine.dispatch({ kind: "document", root: await workspaceDirectory(paseo, workspaceId), path }),
|
|
62
|
+
);
|
|
63
|
+
server.handle(readWorksheet, async ({ workspaceId, path, sheet }, { paseo }) =>
|
|
64
|
+
engine.dispatch({ kind: "worksheet", root: await workspaceDirectory(paseo, workspaceId), path, sheet }),
|
|
65
|
+
);
|
|
66
|
+
server.handle(findWorksheetText, async ({ workspaceId, path, ...input }, { paseo }) =>
|
|
67
|
+
engine.dispatch({ kind: "worksheet-search", root: await workspaceDirectory(paseo, workspaceId), path, ...input }),
|
|
68
|
+
);
|
|
69
|
+
return () => {
|
|
70
|
+
office.stop();
|
|
71
|
+
engine.stop();
|
|
72
|
+
};
|
|
73
|
+
}
|
|
File without changes
|
|
File without changes
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "merong-docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "merong-docs",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "1.0.0",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@xmldom/xmldom",
|
|
12
12
|
"markdown-it",
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { access, readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import { dirname } from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
const root = new URL("../", import.meta.url);
|
|
6
|
-
const generated = new URL("server/generated/", root);
|
|
7
|
-
const location = new URL("office-location.ts", generated);
|
|
8
|
-
const directory = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
9
|
-
const source = `export default ${JSON.stringify(directory)};\n`;
|
|
10
|
-
|
|
11
|
-
await Promise.all([
|
|
12
|
-
access(new URL("server/office-worker.cjs", root)),
|
|
13
|
-
access(new URL("server/office-fonts.cjs", root)),
|
|
14
|
-
access(new URL("server/generated/rust-reader.cjs", root)),
|
|
15
|
-
access(new URL("server/generated/rust-reader_bg.wasm", root)),
|
|
16
|
-
access(new URL("server/generated/NotoSansSC-Regular.otf", root)),
|
|
17
|
-
access(new URL("vendor/office2pdf/office2pdf.cjs", root)),
|
|
18
|
-
access(new URL("vendor/office2pdf/office2pdf_bg.wasm", root)),
|
|
19
|
-
]);
|
|
20
|
-
if ((await readFile(location, "utf8").catch(() => null)) !== source) await writeFile(location, source);
|
|
1
|
+
import { access, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const root = new URL("../", import.meta.url);
|
|
6
|
+
const generated = new URL("server/generated/", root);
|
|
7
|
+
const location = new URL("office-location.ts", generated);
|
|
8
|
+
const directory = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
9
|
+
const source = `export default ${JSON.stringify(directory)};\n`;
|
|
10
|
+
|
|
11
|
+
await Promise.all([
|
|
12
|
+
access(new URL("server/office-worker.cjs", root)),
|
|
13
|
+
access(new URL("server/office-fonts.cjs", root)),
|
|
14
|
+
access(new URL("server/generated/rust-reader.cjs", root)),
|
|
15
|
+
access(new URL("server/generated/rust-reader_bg.wasm", root)),
|
|
16
|
+
access(new URL("server/generated/NotoSansSC-Regular.otf", root)),
|
|
17
|
+
access(new URL("vendor/office2pdf/office2pdf.cjs", root)),
|
|
18
|
+
access(new URL("vendor/office2pdf/office2pdf_bg.wasm", root)),
|
|
19
|
+
]);
|
|
20
|
+
if ((await readFile(location, "utf8").catch(() => null)) !== source) await writeFile(location, source);
|