dsh-document-view 1.1.1 → 1.2.1
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/CHANGELOG.md +37 -0
- package/README.md +152 -77
- package/README.zh.md +225 -0
- package/SECURITY.md +7 -6
- package/client.js +1245 -13
- package/docs/COMPATIBILITY.md +18 -9
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +1 -1
- package/docs/PUBLISHING.md +15 -11
- package/docs/screenshots/01-overview.png +0 -0
- package/docs/screenshots/02-annotations.png +0 -0
- package/docs/screenshots/03-settings.png +0 -0
- package/docs/screenshots/archive/01-overview-illustration-20261115.png +0 -0
- package/docs/screenshots/preview.png +0 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +6 -3
- package/scripts/build.mjs +2 -0
- package/scripts/verify.mjs +164 -2
- package/src/annotations.mjs +375 -0
- package/src/collaboration.mjs +807 -9
- package/src/model.mjs +62 -4
- package/README.en.md +0 -134
- /package/docs/screenshots/{02-settings.png → archive/02-settings-illustration-20261115.png} +0 -0
- /package/docs/screenshots/{03-narrow.png → archive/03-narrow-illustration-20261115.png} +0 -0
package/src/model.mjs
CHANGED
|
@@ -2,7 +2,13 @@ const STORAGE_KEY = 'dsh.document-view.v1';
|
|
|
2
2
|
const clampRatio = value => Number.isFinite(value) ? Math.max(0.2, Math.min(0.65, value)) : 0.35;
|
|
3
3
|
|
|
4
4
|
export function isDocument(address) {
|
|
5
|
-
|
|
5
|
+
if (typeof address !== 'string' || !address) return false;
|
|
6
|
+
if (address.startsWith('dsh-resource://file/')) return true;
|
|
7
|
+
// HTML previews may open under a viewer address that is not a session file
|
|
8
|
+
// address (absolute path, http URL, blob URL, ...). Recognize them by the
|
|
9
|
+
// .html/.htm extension anywhere in the address so the split layout applies.
|
|
10
|
+
const clean = address.split(/[?#]/, 1)[0];
|
|
11
|
+
return /\.(?:html|htm)$/i.test(clean) || /\.(?:html|htm)[\\/]/i.test(clean);
|
|
6
12
|
}
|
|
7
13
|
|
|
8
14
|
export function solveColumns(width, sidebar, ratio) {
|
|
@@ -20,6 +26,7 @@ export class CollaborationState {
|
|
|
20
26
|
this.auto = false;
|
|
21
27
|
this.sessions = Object.create(null);
|
|
22
28
|
this.counts = new Map();
|
|
29
|
+
this.dirty = new Set();
|
|
23
30
|
try {
|
|
24
31
|
const saved = JSON.parse(storage?.getItem(STORAGE_KEY) || '{}');
|
|
25
32
|
this.auto = saved.auto === true;
|
|
@@ -36,14 +43,61 @@ export class CollaborationState {
|
|
|
36
43
|
session(id) {
|
|
37
44
|
return this.sessions[id] ||= { enabled: false, ratio: 0.35, suppressed: '' };
|
|
38
45
|
}
|
|
46
|
+
// Merge with what other windows already saved: only the flags this window
|
|
47
|
+
// changed override the stored value, so two windows on different sessions
|
|
48
|
+
// no longer erase each other.
|
|
39
49
|
save() {
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
if (!this.storage) return false;
|
|
51
|
+
try {
|
|
52
|
+
let remote = {};
|
|
53
|
+
try { remote = JSON.parse(this.storage.getItem(STORAGE_KEY) || '{}'); } catch { /* treat as empty */ }
|
|
54
|
+
const sessions = { ...(remote.sessions || {}) };
|
|
55
|
+
let auto = remote.auto === true;
|
|
56
|
+
if (this.dirty.has('auto')) auto = this.auto;
|
|
57
|
+
for (const id of this.dirty) {
|
|
58
|
+
if (id === 'auto') continue;
|
|
59
|
+
sessions[id] = this.session(id);
|
|
60
|
+
}
|
|
61
|
+
for (const [id, value] of Object.entries(this.sessions)) {
|
|
62
|
+
if (!(id in sessions)) sessions[id] = value;
|
|
63
|
+
}
|
|
64
|
+
for (const [id, value] of Object.entries(remote.sessions || {})) {
|
|
65
|
+
if (this.dirty.has(id) || !value || typeof value !== 'object') continue;
|
|
66
|
+
this.sessions[id] = {
|
|
67
|
+
enabled: value.enabled === true,
|
|
68
|
+
ratio: clampRatio(value.ratio),
|
|
69
|
+
suppressed: typeof value.suppressed === 'string' ? value.suppressed : '',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
this.storage.setItem(STORAGE_KEY, JSON.stringify({ auto, sessions }));
|
|
73
|
+
this.dirty.clear();
|
|
74
|
+
return true;
|
|
75
|
+
} catch { return false; }
|
|
76
|
+
}
|
|
77
|
+
// Adopt another window's write without dropping this window's pending edits.
|
|
78
|
+
reload() {
|
|
79
|
+
try {
|
|
80
|
+
const remote = JSON.parse(this.storage?.getItem(STORAGE_KEY) || '{}');
|
|
81
|
+
if (!this.dirty.has('auto')) this.auto = remote.auto === true;
|
|
82
|
+
const sessions = {};
|
|
83
|
+
for (const [id, value] of Object.entries(remote.sessions || {})) {
|
|
84
|
+
if (!value || typeof value !== 'object') continue;
|
|
85
|
+
sessions[id] = {
|
|
86
|
+
enabled: value.enabled === true,
|
|
87
|
+
ratio: clampRatio(value.ratio),
|
|
88
|
+
suppressed: typeof value.suppressed === 'string' ? value.suppressed : '',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
for (const id of this.dirty) if (id !== 'auto') sessions[id] = this.session(id);
|
|
92
|
+
for (const [id, value] of Object.entries(this.sessions)) if (!(id in sessions)) sessions[id] = value;
|
|
93
|
+
this.sessions = sessions;
|
|
94
|
+
} catch { /* keep the current in-memory state */ }
|
|
42
95
|
}
|
|
43
96
|
toggle(id, address) {
|
|
44
97
|
const session = this.session(id);
|
|
45
98
|
session.enabled = !session.enabled;
|
|
46
99
|
session.suppressed = session.enabled ? '' : address || '';
|
|
100
|
+
this.dirty.add(id);
|
|
47
101
|
this.save();
|
|
48
102
|
}
|
|
49
103
|
observe(id, address, userGesture) {
|
|
@@ -51,6 +105,7 @@ export class CollaborationState {
|
|
|
51
105
|
if (this.auto && userGesture && isDocument(address) && session.suppressed !== address && !session.enabled) {
|
|
52
106
|
session.enabled = true;
|
|
53
107
|
session.suppressed = '';
|
|
108
|
+
this.dirty.add(id);
|
|
54
109
|
this.save();
|
|
55
110
|
}
|
|
56
111
|
}
|
|
@@ -59,14 +114,17 @@ export class CollaborationState {
|
|
|
59
114
|
this.counts.set(id, count);
|
|
60
115
|
if (previous > 0 && count === 0) {
|
|
61
116
|
this.session(id).enabled = false;
|
|
117
|
+
this.dirty.add(id);
|
|
62
118
|
this.save();
|
|
63
119
|
}
|
|
64
120
|
}
|
|
65
|
-
setAuto(value) { this.auto = value === true; this.save(); }
|
|
121
|
+
setAuto(value) { this.auto = value === true; this.dirty.add('auto'); this.save(); }
|
|
66
122
|
setRatio(id, value, persist = true) {
|
|
67
123
|
const session = this.session(id), ratio = clampRatio(value);
|
|
68
124
|
if (session.ratio === ratio) return;
|
|
69
125
|
session.ratio = ratio;
|
|
126
|
+
// Dragging commits on pointer-up, so the id must stay dirty until then.
|
|
127
|
+
this.dirty.add(id);
|
|
70
128
|
if (persist) this.save();
|
|
71
129
|
}
|
|
72
130
|
}
|
package/README.en.md
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
# dsh-document-view
|
|
2
|
-
|
|
3
|
-
**Read your document and talk to your AI at the same time.** A split document view for [DeepSeek Harness](https://github.com/deepseek-ai/DeepSeek-Harness): the document stays in the center, the current conversation stays on the right — no more tab hopping.
|
|
4
|
-
|
|
5
|
-
[](LICENSE)
|
|
6
|
-
[](https://www.npmjs.com/package/dsh-document-view)
|
|
7
|
-
[](https://github.com/deepseek-ai/DeepSeek-Harness/releases/tag/dsh-v0.2.2-rc.3)
|
|
8
|
-
|
|
9
|
-

|
|
10
|
-
|
|
11
|
-
> Screenshots are **desensitized illustrations** with generic placeholder content. They contain no real sessions, file names, accounts, or personal data.
|
|
12
|
-
|
|
13
|
-
[中文说明 →](README.md) · [Marketplace submission guide →](docs/PUBLISHING.md) · [Compatibility & security →](docs/COMPATIBILITY.md)
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## The problem
|
|
18
|
-
|
|
19
|
-
Open a file in DSH and it takes over the right sidebar, pushing your conversation away. Asking the AI to explain, summarize or rewrite against that document means constantly switching between "reading" and "chatting" — and losing context every time.
|
|
20
|
-
|
|
21
|
-
`dsh-document-view` does exactly one thing: **keeps both on screen**. It does not take over the editor, change save behavior, or touch your files. It only rearranges the window so DSH's native document / Office preview and the chat panel work side by side.
|
|
22
|
-
|
|
23
|
-
| | Default | Document view on |
|
|
24
|
-
| --- | --- | --- |
|
|
25
|
-
| Document | Takes the right sidebar | Center area |
|
|
26
|
-
| Conversation | Pushed away | Always visible on the right |
|
|
27
|
-
| Ask AI about the document | Switch back and forth | Same screen |
|
|
28
|
-
| Editing / saving / preview | Native | **Still native** |
|
|
29
|
-
|
|
30
|
-
## Features
|
|
31
|
-
|
|
32
|
-
### 1. Document and chat, side by side
|
|
33
|
-
|
|
34
|
-

|
|
35
|
-
|
|
36
|
-
Open any file, then click **Document view** in the conversation header actions or the file tab actions. Drag the divider to resize; `←` / `→` nudge it, `Home` resets the ratio, and double-clicking the divider restores the default. The toggle and ratio are **saved per session**.
|
|
37
|
-
|
|
38
|
-
### 2. Settings and auto-enter
|
|
39
|
-
|
|
40
|
-

|
|
41
|
-
|
|
42
|
-
The arrow next to the toggle opens settings:
|
|
43
|
-
|
|
44
|
-
- **Auto-enter on document view** (off by default) — fires only when *you* click a file or file tab; background file operations never open it. After you exit manually, the same file won't re-open repeatedly.
|
|
45
|
-
- **Document-first / Balanced / Chat-first** presets, saved per session.
|
|
46
|
-
- **Auto update / Paused** — reuses the host's native file watcher. Pause when you want to read carefully; resuming shows the latest content while preserving the native viewer's page and zoom state.
|
|
47
|
-
|
|
48
|
-
### 3. Works in narrow windows
|
|
49
|
-
|
|
50
|
-

|
|
51
|
-
|
|
52
|
-
When the window is too narrow it switches to a single-column **Document / Chat** toggle. **Unsent input is preserved**, and focus moves to the visible switch if the current focus would be hidden.
|
|
53
|
-
|
|
54
|
-
### 4. Native all the way down
|
|
55
|
-
|
|
56
|
-
Rendering, editing, saving and preview of Markdown, PDF, Word, Excel and PowerPoint remain entirely with DSH's own viewers and Office engine. The plugin **never reads, writes or uploads your files** and reimplements no editing feature. Disable it and the default layout returns.
|
|
57
|
-
|
|
58
|
-
## Privacy & security
|
|
59
|
-
|
|
60
|
-
- **No network calls** — no `fetch`, `XMLHttpRequest`, `WebSocket`, no external URLs in the code.
|
|
61
|
-
- **No file access** — no filesystem or editor read/write APIs.
|
|
62
|
-
- **No credentials** — no API keys, tokens, passwords, cookies, `.env` or config files ship in the package.
|
|
63
|
-
- **One preference only** — browser `localStorage` holds the auto-enter toggle and per-session ratios under `dsh.document-view.v1`; no document content, paths, file names or chat content.
|
|
64
|
-
- **Narrow CSS scope** — all styles are scoped to the plugin's own `[data-fdc-*]` attributes. No host components are moved, cloned or remounted; only the window grid geometry changes.
|
|
65
|
-
|
|
66
|
-
See [SECURITY.md](SECURITY.md) and [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md).
|
|
67
|
-
|
|
68
|
-
## Requirements
|
|
69
|
-
|
|
70
|
-
- [DeepSeek Harness](https://github.com/deepseek-ai/DeepSeek-Harness) Desktop / Web, verified on **v0.2.2-rc.3** (the current official release).
|
|
71
|
-
- Node.js >= 20 — **only for rebuilding from source**; not needed to install or use.
|
|
72
|
-
- No `engines.dsh` hard constraint: a wrong constraint blocks installation outright, so compatibility is documented instead.
|
|
73
|
-
|
|
74
|
-
> The plugin relies on the host's DOM structure and slot names. If a DSH upgrade changes them, the plugin **disables itself safely and the page keeps working** (no white screen). Re-verify with the [upgrade checklist](docs/COMPATIBILITY.md).
|
|
75
|
-
|
|
76
|
-
## Install
|
|
77
|
-
|
|
78
|
-
**Option 1 — local directory (easiest)**
|
|
79
|
-
|
|
80
|
-
```sh
|
|
81
|
-
git clone https://github.com/Frank-Fan-1058/dsh-document-view.git
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Then in DSH: **Plugins → Add plugin**, pick the `dsh-document-view` directory, enable it, and refresh the page (or restart DSH).
|
|
85
|
-
|
|
86
|
-
**Option 2 — tarball**
|
|
87
|
-
|
|
88
|
-
```sh
|
|
89
|
-
npm pack
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Extract `dsh-document-view-1.1.0.tgz` anywhere, then point step 2 of Option 1 at that directory.
|
|
93
|
-
|
|
94
|
-
**Option 3 — build from source**
|
|
95
|
-
|
|
96
|
-
```sh
|
|
97
|
-
node scripts/build.mjs
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
`src/` is the source; `client.js` is the self-contained build artifact (all CSS inlined, no runtime dependencies). **Rebuild `client.js` after any `src/` change** — don't hand-edit the artifact.
|
|
101
|
-
|
|
102
|
-
> `file:` dependencies are physical copies: after editing source, remove `node_modules/<package>` and reinstall so the running copy updates.
|
|
103
|
-
|
|
104
|
-
## Usage
|
|
105
|
-
|
|
106
|
-
1. Open a file in the right sidebar (Markdown / PDF / Office).
|
|
107
|
-
2. Click **Document view** in the conversation header or file tab actions.
|
|
108
|
-
3. Drag the divider; `←` / `→` to nudge, `Home` or double-click to reset.
|
|
109
|
-
4. Open settings via the arrow for auto-enter and layout presets.
|
|
110
|
-
5. Click the toggle again (or the exit entry in the session / file header) to return to the default layout.
|
|
111
|
-
|
|
112
|
-
## FAQ
|
|
113
|
-
|
|
114
|
-
**Will it affect my editors or Office plugins?** No. It changes layout only — Univer, Office converters and native editors are untouched.
|
|
115
|
-
|
|
116
|
-
**Are my files read or uploaded?** No. No network requests, no file I/O, only the toggle and ratios are stored.
|
|
117
|
-
|
|
118
|
-
**Does anything remain after disabling?** No. All injected styles, attributes, the divider and listeners are removed on teardown.
|
|
119
|
-
|
|
120
|
-
**What if a DSH upgrade breaks it?** It disables itself safely and the page stays usable. Open an [Issue](https://github.com/Frank-Fan-1058/dsh-document-view/issues) with your DSH version.
|
|
121
|
-
|
|
122
|
-
**Which file types are supported?** Whatever the host supports natively — Markdown, PDF, Word, Excel, PowerPoint, etc. The plugin adds no format restrictions.
|
|
123
|
-
|
|
124
|
-
## Get listed in plugin marketplaces
|
|
125
|
-
|
|
126
|
-
See **[docs/PUBLISHING.md](docs/PUBLISHING.md)** for the full playbook (1024 Store, dsh-market, the `dsh-plugin` GitHub topic, npm publishing, and a ready-to-use [catalog entry](docs/awesome-dsh-catalog-entry.json)).
|
|
127
|
-
|
|
128
|
-
## Contributing
|
|
129
|
-
|
|
130
|
-
Issues and PRs welcome. Rebuild `client.js` when changing `src/`; update both `locale/en.json` and `locale/zh.json` when changing UI copy. Never put real sessions, file names, accounts or personal data into illustrations or examples.
|
|
131
|
-
|
|
132
|
-
## License
|
|
133
|
-
|
|
134
|
-
[MIT](LICENSE) © 2026 dsh-document-view contributors
|
|
File without changes
|
|
File without changes
|