@coda-console/resource-manager 0.4.0 → 0.6.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/README.md +12 -6
- package/lib/draft.mjs +57 -0
- package/lib/info.mjs +137 -0
- package/lib/paths.mjs +5 -11
- package/lib/tree.mjs +2 -2
- package/main.mjs +50 -15
- package/package.json +1 -1
- package/view/app.mjs +222 -111
- package/view/chat.mjs +49 -0
- package/view/connection.mjs +50 -24
- package/view/dom.mjs +9 -0
- package/view/file-app.mjs +19 -3
- package/view/file.html +2 -0
- package/view/format.mjs +27 -0
- package/view/gestures.mjs +62 -0
- package/view/grid.mjs +213 -0
- package/view/hint.mjs +20 -0
- package/view/icons.mjs +139 -22
- package/view/index.html +3 -0
- package/view/info.mjs +117 -0
- package/view/menu.mjs +195 -0
- package/view/model.mjs +120 -14
- package/view/preview.mjs +15 -11
- package/view/protocol.mjs +28 -2
- package/view/restore.mjs +57 -0
- package/view/selection.mjs +33 -0
- package/view/style.css +85 -24
- package/view/tree.mjs +15 -49
package/view/model.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 页面的纯状态:目录树、状态保留。不碰 DOM,请求与代次在 connection.mjs,设计见 docs/design/phase-1.md 第 6、7 节。
|
|
2
|
-
import { DEFAULT_SORT, ErrorCode, RootState, Type, parseSort } from './protocol.mjs';
|
|
2
|
+
import { DEFAULT_SORT, ErrorCode, RootState, Type, parseSort, splitRelative } from './protocol.mjs';
|
|
3
3
|
|
|
4
4
|
export const STATE_LIMIT = 96 * 1024;
|
|
5
5
|
export const MAX_PARALLEL = 8;
|
|
@@ -11,8 +11,13 @@ const MAX_LOADED_DIRS = 500;
|
|
|
11
11
|
const HIDDEN = new Set(['.git', '.DS_Store']);
|
|
12
12
|
export const isHidden = name => HIDDEN.has(name);
|
|
13
13
|
export const joinPath = (dir, name) => (dir ? `${dir}/${name}` : name);
|
|
14
|
+
export const parentOf = path => (path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : '');
|
|
14
15
|
const inside = (path, dir) => path === dir || path.startsWith(`${dir}/`);
|
|
15
16
|
|
|
17
|
+
// 两种视图:列表(目录树,可以展开多层)和图标(一次看一层,看的那一层是 cwd)。全局一份,和排序一样。
|
|
18
|
+
export const View = Object.freeze({ LIST: 'list', ICONS: 'icons' });
|
|
19
|
+
export const parseView = raw => (raw === View.ICONS ? View.ICONS : View.LIST);
|
|
20
|
+
|
|
16
21
|
async function pool(items, limit, fn) {
|
|
17
22
|
let index = 0;
|
|
18
23
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
@@ -40,9 +45,19 @@ export class Model {
|
|
|
40
45
|
selected = null;
|
|
41
46
|
showHidden = false;
|
|
42
47
|
sort = DEFAULT_SORT; // 全局一份,由页面存进 persisted
|
|
48
|
+
view = View.LIST; // 全局一份,由页面存进 persisted
|
|
49
|
+
cwd = ''; // 图标视图正在看的目录,'' 是根目录;每个会话一份,连同当时的根目录存进会话状态
|
|
50
|
+
scope = 0; // 根目录的身份:这个会话认定「换了根目录」时加一,依赖根目录的东西(待恢复的滚动)据此作废
|
|
43
51
|
#round = 0; // refresh 的轮次:新一轮开始后,旧一轮不再派发排队的目录
|
|
52
|
+
#nav = 0; // 导航上下文:进入、返回、换会话、回到根目录、回退各加一;一次请求只有发出时的上下文还在,才能改 cwd
|
|
53
|
+
#savedRoot = null; // 会话状态里存的根目录;收到这个会话第一条就绪的 root 之前,是否「同一个根目录」靠它比
|
|
54
|
+
#resolved = false; // 这个会话已经收到过就绪的 root
|
|
55
|
+
#rootPath = null; // 就绪的根目录路径,之后的变化靠它比
|
|
56
|
+
#quiet = false; // cwd 是从保存的状态里恢复的,还没确认过:它没了不提示
|
|
57
|
+
#noticed = -1; // 提示过「文件夹已不存在」的轮次,一轮只提示一次
|
|
44
58
|
|
|
45
|
-
|
|
59
|
+
// onLost(path):cwd 没了、已经退到上一层时调用一次(恢复时不调用)。
|
|
60
|
+
constructor({ link, onChange = () => {}, onLost = () => {} }) { Object.assign(this, { link, onChange, onLost }); }
|
|
46
61
|
|
|
47
62
|
get ready() { return this.root?.state === RootState.READY; }
|
|
48
63
|
|
|
@@ -63,6 +78,12 @@ export class Model {
|
|
|
63
78
|
this.session = session ?? null;
|
|
64
79
|
this.root = null;
|
|
65
80
|
this.dirs = new Map();
|
|
81
|
+
this.#nav++;
|
|
82
|
+
this.#resolved = false;
|
|
83
|
+
this.#rootPath = null;
|
|
84
|
+
this.#savedRoot = typeof saved?.root === 'string' ? saved.root : null;
|
|
85
|
+
this.cwd = typeof saved?.cwd === 'string' ? saved.cwd : '';
|
|
86
|
+
this.#quiet = this.cwd !== '';
|
|
66
87
|
this.wanted = new Map(Object.entries(saved?.loaded ?? {}).map(([path, count]) => [path, Math.min(count, RESTORE_LIMIT)]));
|
|
67
88
|
const paths = (saved?.expanded ?? []).filter(path => path !== '');
|
|
68
89
|
this.expanded = new Set(paths.filter(path => !path.includes('/') || paths.includes(path.slice(0, path.lastIndexOf('/')))));
|
|
@@ -73,11 +94,26 @@ export class Model {
|
|
|
73
94
|
// 只换根目录状态,不动会话状态;ready 时重新取全部。
|
|
74
95
|
onRoot({ generation, state, path }) {
|
|
75
96
|
if (generation !== this.link.generation) return null;
|
|
97
|
+
if (state === RootState.READY) this.#identify(path);
|
|
76
98
|
this.root = { state, path };
|
|
77
99
|
this.onChange();
|
|
78
100
|
return state === RootState.READY ? this.refresh() : Promise.resolve();
|
|
79
101
|
}
|
|
80
102
|
|
|
103
|
+
// 根目录有没有换:重建页面后 model.root 是 null,不能靠「路径变了」,否则每次重建都算换了。
|
|
104
|
+
// 这个会话第一条就绪的 root 和保存的根目录比(没存根目录的旧状态当作没换),之后的 root 和上一次比。换了就全部回到根目录。
|
|
105
|
+
#identify(path) {
|
|
106
|
+
const changed = this.#resolved ? this.#rootPath !== path : this.#savedRoot !== null && this.#savedRoot !== path;
|
|
107
|
+
this.#resolved = true;
|
|
108
|
+
this.#rootPath = path;
|
|
109
|
+
if (!changed) return;
|
|
110
|
+
this.scope++;
|
|
111
|
+
this.#nav++;
|
|
112
|
+
this.cwd = '';
|
|
113
|
+
this.#quiet = false;
|
|
114
|
+
this.wanted = new Map();
|
|
115
|
+
}
|
|
116
|
+
|
|
81
117
|
onChanged({ generation }) {
|
|
82
118
|
return generation === this.link.generation && this.ready ? this.refresh() : null;
|
|
83
119
|
}
|
|
@@ -87,7 +123,40 @@ export class Model {
|
|
|
87
123
|
refresh({ cap = Infinity } = {}) {
|
|
88
124
|
if (!this.ready) return Promise.resolve();
|
|
89
125
|
const { generation } = this.link, round = ++this.#round;
|
|
90
|
-
return pool(
|
|
126
|
+
return pool(this.requested(), MAX_PARALLEL, path => (round === this.#round ? this.#reload(path, generation, { cap }) : undefined));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 一轮要取的目录:列表是根和展开的,图标是根和 cwd;同一路径只取一次。
|
|
130
|
+
requested() { return this.view === View.ICONS ? [...new Set(['', this.cwd])] : ['', ...this.expanded]; }
|
|
131
|
+
|
|
132
|
+
// 换视图:马上按新的集合刷新,作废旧的排队轮次;回来之前显示已有的内容,没有就显示读取中。展开状态不动。
|
|
133
|
+
setView(view) {
|
|
134
|
+
const next = parseView(view);
|
|
135
|
+
if (next === this.view) return Promise.resolve();
|
|
136
|
+
this.view = next;
|
|
137
|
+
this.onChange();
|
|
138
|
+
return this.refresh();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 图标视图进入一层:cwd 换成它并加载。返回 levels 层(缺省一层,到根为止)。
|
|
142
|
+
enter(path) {
|
|
143
|
+
this.cwd = path;
|
|
144
|
+
return this.#go();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
leave(levels = 1) {
|
|
148
|
+
let next = this.cwd;
|
|
149
|
+
for (let i = 0; i < levels && next !== ''; i++) next = parentOf(next);
|
|
150
|
+
if (next === this.cwd) return Promise.resolve();
|
|
151
|
+
this.cwd = next;
|
|
152
|
+
return this.#go();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#go() {
|
|
156
|
+
this.#nav++;
|
|
157
|
+
this.#quiet = false;
|
|
158
|
+
this.onChange();
|
|
159
|
+
return this.retry(this.cwd);
|
|
91
160
|
}
|
|
92
161
|
|
|
93
162
|
// 换排序:已加载的目录按新顺序重新取,取够现在的条数,这次最多 RESTORE_LIMIT 条;每个目录一次替换。
|
|
@@ -105,7 +174,7 @@ export class Model {
|
|
|
105
174
|
if (this.link.generation !== generation) return; // 排队时会话已换,旧任务不碰新会话
|
|
106
175
|
let dir = this.dirs.get(path);
|
|
107
176
|
if (!dir) this.dirs.set(path, dir = { entries: [], next: null, loaded: false, loading: false, error: null, token: 0, pages: 0, sortFallback: false });
|
|
108
|
-
const token = ++dir.token, { sort } = this;
|
|
177
|
+
const token = ++dir.token, { sort } = this, nav = this.#nav;
|
|
109
178
|
const want = more ? dir.entries.length + 1 : Math.min(Math.max(dir.entries.length, this.wanted.get(path) ?? 0), cap);
|
|
110
179
|
dir.loading = true;
|
|
111
180
|
this.onChange();
|
|
@@ -130,27 +199,50 @@ export class Model {
|
|
|
130
199
|
pages++;
|
|
131
200
|
} while (pages === 0 || (next && entries.length < want));
|
|
132
201
|
if (!current()) return;
|
|
133
|
-
Object.assign(dir, { entries, next, loaded: true, error: null, pages, sortFallback });
|
|
202
|
+
Object.assign(dir, { entries, next, loaded: true, error: null, pages, sortFallback, sort });
|
|
134
203
|
this.wanted.delete(path); // 成功后才删:取页失败后重试还要取够保存的条数
|
|
204
|
+
if (path === this.cwd) this.#quiet = false;
|
|
135
205
|
} catch (error) {
|
|
136
206
|
if (error.stale || !current()) return;
|
|
137
|
-
if (error.code === ErrorCode.NOT_FOUND && path !== '') this.#
|
|
138
|
-
else if (error.code !== ErrorCode.NO_ROOT)
|
|
207
|
+
if (error.code === ErrorCode.NOT_FOUND && path !== '') this.#lost(path, nav);
|
|
208
|
+
else if (error.code !== ErrorCode.NO_ROOT) {
|
|
209
|
+
dir.error = { code: error.code, message: error.message };
|
|
210
|
+
if (path === this.cwd) this.#quiet = false;
|
|
211
|
+
}
|
|
139
212
|
} finally {
|
|
140
213
|
if (current()) dir.loading = false;
|
|
141
214
|
this.onChange();
|
|
142
215
|
}
|
|
143
216
|
}
|
|
144
217
|
|
|
145
|
-
|
|
146
|
-
|
|
218
|
+
// 目录没了(not_found):所有列目录入口都走这里。先清掉失效的子树;cwd 在里面、而且发出请求以来没有导航过,就退到上一层。
|
|
219
|
+
// 退到哪一层靠新发的请求:它再 not_found 又走到这里,所以每级只试一次;别的错误停在那一级,显示失败行和重试。
|
|
220
|
+
// 清掉子树后原目录对象没了,原请求的检查必然为假,但回退不靠它:回退看的是导航上下文,每一级有自己的请求。
|
|
221
|
+
#lost(path, nav) {
|
|
222
|
+
const covers = nav === this.#nav && inside(this.cwd, path);
|
|
223
|
+
// 迟到的上层失败(发出后用户已经进了别处):清它的子树,但正在加载的 cwd 的条目留着,不然它的回答提交不上。
|
|
224
|
+
this.#drop(path, covers ? null : this.cwd);
|
|
225
|
+
if (!covers) return;
|
|
226
|
+
this.#nav++;
|
|
227
|
+
this.cwd = parentOf(path);
|
|
228
|
+
if (!this.#quiet && this.#noticed !== this.#round && this.view === View.ICONS) {
|
|
229
|
+
this.#noticed = this.#round;
|
|
230
|
+
this.onLost(path);
|
|
231
|
+
}
|
|
232
|
+
this.onChange();
|
|
233
|
+
this.retry(this.cwd);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#drop(path, keep = null) {
|
|
237
|
+
for (const key of [...this.dirs.keys()]) if (key !== keep && inside(key, path)) this.dirs.delete(key);
|
|
147
238
|
for (const key of [...this.expanded]) if (inside(key, path)) this.expanded.delete(key);
|
|
148
239
|
}
|
|
149
240
|
|
|
150
241
|
toggle(path) {
|
|
151
242
|
if (this.expanded.has(path)) {
|
|
152
243
|
for (const key of [...this.expanded]) if (inside(key, path)) this.expanded.delete(key);
|
|
153
|
-
|
|
244
|
+
// cwd 的条目留着:图标视图还在看它
|
|
245
|
+
for (const key of [...this.dirs.keys()]) if (key !== '' && key !== this.cwd && inside(key, path)) this.dirs.delete(key);
|
|
154
246
|
this.onChange();
|
|
155
247
|
} else {
|
|
156
248
|
this.expanded.add(path);
|
|
@@ -164,7 +256,9 @@ export class Model {
|
|
|
164
256
|
async loadMore(path) {
|
|
165
257
|
const dir = this.dirs.get(path), { generation } = this.link;
|
|
166
258
|
if (!dir?.next || dir.loading || !this.ready) return;
|
|
167
|
-
|
|
259
|
+
// 游标是按另一种排序取的(换排序时这个目录没重建过):不用它,从第一页重取,条数比现在多一条。
|
|
260
|
+
if (dir.sort !== this.sort) return this.#reload(path, generation, { more: true, expired: true });
|
|
261
|
+
const token = ++dir.token, nav = this.#nav;
|
|
168
262
|
dir.loading = true;
|
|
169
263
|
this.onChange();
|
|
170
264
|
const current = () => this.link.generation === generation && this.dirs.get(path) === dir && dir.token === token;
|
|
@@ -177,6 +271,7 @@ export class Model {
|
|
|
177
271
|
if (error.stale || !current()) return;
|
|
178
272
|
// 游标过期:从第一页重取,条数比现在多一条,所以还会接着往下取。重取自己管 loading。
|
|
179
273
|
if (error.code === ErrorCode.CURSOR_EXPIRED) return this.#reload(path, generation, { more: true, expired: true });
|
|
274
|
+
if (error.code === ErrorCode.NOT_FOUND && path !== '') return this.#lost(path, nav);
|
|
180
275
|
dir.error = { code: error.code, message: error.message };
|
|
181
276
|
} finally {
|
|
182
277
|
if (current()) dir.loading = false;
|
|
@@ -190,7 +285,9 @@ export class Model {
|
|
|
190
285
|
snapshot() {
|
|
191
286
|
const loaded = {};
|
|
192
287
|
for (const [path, dir] of this.dirs) if (dir.pages > 1 && dir.entries.length > 0) loaded[path] = dir.entries.length;
|
|
193
|
-
|
|
288
|
+
// 还没收到这个会话就绪的 root 时,cwd 和根目录还是保存的那一份,原样存回去,不能被重建途中的一次保存冲掉。
|
|
289
|
+
const root = this.#resolved ? this.#rootPath : this.#savedRoot;
|
|
290
|
+
return { expanded: [...this.expanded], selected: this.selected, loaded, cwd: this.cwd, ...(root === null ? {} : { root }) };
|
|
194
291
|
}
|
|
195
292
|
}
|
|
196
293
|
|
|
@@ -203,12 +300,16 @@ const strings = (value, max) => (Array.isArray(value) ? value.filter(s => typeof
|
|
|
203
300
|
const parseLoaded = raw => Object.fromEntries(Object.entries(raw && typeof raw === 'object' ? raw : {})
|
|
204
301
|
.filter(([path, count]) => path.length <= 1024 && Number.isSafeInteger(count) && count > 0 && count <= MAX_LOADED).slice(0, MAX_LOADED_DIRS));
|
|
205
302
|
|
|
303
|
+
// cwd 要是后端认的相对路径(规则同 lib/paths.mjs),而且写法规整:model 里的路径都是 joinPath 拼出来的,不带空段和 `.`。
|
|
304
|
+
const cleanRelative = path => { const { segments } = splitRelative(path); return segments !== undefined && segments.join('/') === path; };
|
|
305
|
+
|
|
206
306
|
// 读回来的值可能是别的版本或坏的,只认自己的形状。
|
|
207
307
|
export function parseState(raw) {
|
|
208
|
-
const state = { v: 1, seq: 0, hidden: false, sort: DEFAULT_SORT, sessions: {} };
|
|
308
|
+
const state = { v: 1, seq: 0, hidden: false, sort: DEFAULT_SORT, view: View.LIST, sessions: {} };
|
|
209
309
|
if (!raw || typeof raw !== 'object' || raw.v !== 1) return state;
|
|
210
310
|
state.hidden = raw.hidden === true;
|
|
211
311
|
state.sort = parseSort(raw.sort) ?? DEFAULT_SORT;
|
|
312
|
+
state.view = parseView(raw.view);
|
|
212
313
|
state.seq = Number.isSafeInteger(raw.seq) ? raw.seq : 0;
|
|
213
314
|
for (const [id, item] of Object.entries(raw.sessions ?? {})) {
|
|
214
315
|
if (!item || typeof item !== 'object') continue;
|
|
@@ -217,8 +318,13 @@ export function parseState(raw) {
|
|
|
217
318
|
at: Number.isSafeInteger(item.at) ? item.at : 0, expanded: strings(item.expanded, 5000),
|
|
218
319
|
selected: typeof item.selected === 'string' && item.selected.length <= 1024 ? item.selected : null,
|
|
219
320
|
// 滚动位置是按当时的排序存的;旧版本没有这个字段,那时一定是默认排序。
|
|
220
|
-
|
|
321
|
+
// 两种视图各存各的位置和当时的排序:tree 和 sort 是列表的,grid 和 gridSort 是图标的(旧版本没有后两个)。
|
|
322
|
+
scroll: { tree: num(scroll.tree), top: num(scroll.top), left: num(scroll.left), sort: parseSort(scroll.sort) ?? DEFAULT_SORT,
|
|
323
|
+
grid: num(scroll.grid), gridSort: parseSort(scroll.gridSort) ?? DEFAULT_SORT },
|
|
221
324
|
};
|
|
325
|
+
// cwd 和存它时的根目录:超长或形状不对当作没有,回到根目录。旧版本没有这两个字段。
|
|
326
|
+
const path = value => (typeof value === 'string' && value.length <= 1024 ? value : undefined);
|
|
327
|
+
if (path(item.cwd) !== undefined && path(item.root) !== undefined && cleanRelative(item.cwd)) Object.assign(state.sessions[id], { cwd: item.cwd, root: item.root });
|
|
222
328
|
const loaded = parseLoaded(item.loaded);
|
|
223
329
|
if (Object.keys(loaded).length > 0) state.sessions[id].loaded = loaded;
|
|
224
330
|
}
|
package/view/preview.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// 文件预览:只接收路径和读块的能力,不依赖树的状态。readFile 是纯逻辑;mountPreview 才碰 DOM。
|
|
2
|
+
import { h } from './dom.mjs';
|
|
2
3
|
import { formatSize } from './format.mjs';
|
|
3
4
|
import { icon, iconFor } from './icons.mjs';
|
|
4
5
|
import { ContentKind, EntryKind, ErrorCode, IMAGE_LIMIT, TEXT_LIMIT, imageType } from './protocol.mjs';
|
|
6
|
+
import { clippedSelection, linesOf } from './selection.mjs';
|
|
5
7
|
|
|
6
8
|
function fromBase64(data) {
|
|
7
9
|
const binary = atob(data), bytes = new Uint8Array(binary.length);
|
|
@@ -48,20 +50,13 @@ export async function readFile(read, { prev = null, onProgress = () => {}, cance
|
|
|
48
50
|
const formatTime = ms => new Date(ms).toLocaleString('zh-CN', { hour12: false });
|
|
49
51
|
export const lineCount = text => (text === '' ? 1 : text.split('\n').length - (text.endsWith('\n') ? 1 : 0));
|
|
50
52
|
|
|
51
|
-
const h = (tag, attributes = {}, ...children) => {
|
|
52
|
-
const node = document.createElement(tag);
|
|
53
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
54
|
-
if (key.startsWith('on')) node.addEventListener(key.slice(2), value); else if (value != null && value !== false) node.setAttribute(key, value);
|
|
55
|
-
}
|
|
56
|
-
node.append(...children.flat().filter(child => child != null));
|
|
57
|
-
return node;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
53
|
// read(path, offset) → Promise<chunk 回答>,会话换了会以 stale 错误拒绝;copy(text) 复制路径。
|
|
61
54
|
// actions:头部在「复制路径」旁额外加的按钮 [{ label, icon, run(path) }],预览不知道它们做什么。
|
|
62
55
|
// copyInHead:false 时头部不放「复制路径」(iPhone 放在底部工具条),由页面调 copyPath()。
|
|
63
56
|
// back:给了就在头部最左边放「返回」(Mac 侧栏预览:原生工具栏项目只能在右侧);文件页和 iPhone 不传。
|
|
64
|
-
|
|
57
|
+
// selectionMenu(event, { path, text, startLine, endLine }):给了就接管正文里选中文字的右键(只有 Mac 传);预览不知道菜单里是什么。
|
|
58
|
+
// 选区为空、或裁到正文里之后为空时不接管,走系统默认。内容和行号在这里取好,交出去之后和选区无关。
|
|
59
|
+
export function mountPreview(el, { read, copy, actions = [], copyInHead = true, back = null, selectionMenu = null }) {
|
|
65
60
|
const name = h('div', { class: 'pname truncate' }), meta = h('div', { class: 'pmeta caption secondary truncate' }, ' ');
|
|
66
61
|
const fileIcon = h('span', { class: 'pico', 'aria-hidden': 'true' });
|
|
67
62
|
// 图标按钮:可访问名称和 Mac 的悬停提示都是 label;没有图标的退回文字。
|
|
@@ -99,7 +94,9 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
|
|
|
99
94
|
setMeta([dir, lines, formatSize(result.size), note].filter(Boolean).join(' · '), `修改于 ${formatTime(result.mtimeMs)}`);
|
|
100
95
|
if (result.kind === ContentKind.TEXT) {
|
|
101
96
|
const gutter = h('pre', { class: 'gutter', 'aria-hidden': 'true' }, Array.from({ length: lineCount(result.text) }, (_, i) => i + 1).join('\n'));
|
|
102
|
-
|
|
97
|
+
const text = h('pre', { class: 'text selectable' }, result.text);
|
|
98
|
+
if (selectionMenu) text.addEventListener('contextmenu', event => onSelect(event, text));
|
|
99
|
+
body.replaceChildren(h('div', { class: 'code' }, gutter, text));
|
|
103
100
|
} else if (result.kind === ContentKind.IMAGE && result.bytes.length > 0) {
|
|
104
101
|
objectUrl = URL.createObjectURL(new Blob([result.bytes], { type: imageType(path) }));
|
|
105
102
|
body.replaceChildren(h('div', { class: 'image' }, h('img', { src: objectUrl, alt: path, draggable: 'false' })));
|
|
@@ -109,6 +106,13 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
|
|
|
109
106
|
}
|
|
110
107
|
}
|
|
111
108
|
|
|
109
|
+
function onSelect(event, text) {
|
|
110
|
+
const picked = clippedSelection(text);
|
|
111
|
+
if (!picked) return;
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
selectionMenu(event, { path, text: picked.text, ...linesOf(text.textContent, picked.start, picked.start + picked.text.length) });
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
function failure(error, silent, retry) {
|
|
113
117
|
if (error.stale) return;
|
|
114
118
|
if (error.code === ErrorCode.NOT_FOUND) { shown = null; setMeta(' '); return notice('文件已不存在', path); }
|
package/view/protocol.mjs
CHANGED
|
@@ -11,18 +11,30 @@ export const IMAGE_LIMIT = 8 * 1024 * 1024;
|
|
|
11
11
|
// 前这么多字节里有 NUL 就当二进制(照 Coda 判断二进制的惯例)。
|
|
12
12
|
export const SNIFF_BYTES = 8000;
|
|
13
13
|
export const REQUEST_ID_MAX = 64;
|
|
14
|
+
// 输入框草稿的文字上限(UTF-16 单元);拼完超过就不写。
|
|
15
|
+
export const DRAFT_LIMIT = 100_000;
|
|
14
16
|
|
|
15
17
|
export const Type = Object.freeze({
|
|
16
|
-
HELLO: 'hello', REFRESH: 'refresh', LIST: 'list', READ: 'read',
|
|
17
|
-
|
|
18
|
+
HELLO: 'hello', REFRESH: 'refresh', LIST: 'list', READ: 'read', STAT: 'stat', DIR_SIZE: 'dir_size', ADD_TEXT: 'add_text',
|
|
19
|
+
DIR_SIZE_CANCEL: 'dir_size_cancel', // 没有回答
|
|
20
|
+
SESSION: 'session', ROOT: 'root', CHANGED: 'changed',
|
|
21
|
+
LISTED: 'listed', CHUNK: 'chunk', STATTED: 'statted', SIZED: 'sized', ADDED: 'added',
|
|
18
22
|
});
|
|
19
23
|
|
|
24
|
+
// 请求 → 回答的类型。模块回答、页面分发都查这一张。
|
|
25
|
+
export const ReplyOf = Object.freeze({
|
|
26
|
+
[Type.LIST]: Type.LISTED, [Type.READ]: Type.CHUNK, [Type.STAT]: Type.STATTED,
|
|
27
|
+
[Type.DIR_SIZE]: Type.SIZED, [Type.ADD_TEXT]: Type.ADDED,
|
|
28
|
+
});
|
|
29
|
+
export const isReply = type => Object.values(ReplyOf).includes(type);
|
|
30
|
+
|
|
20
31
|
export const RootState = Object.freeze({ READY: 'ready', NONE: 'none', PREPARING: 'preparing', GONE: 'gone' });
|
|
21
32
|
|
|
22
33
|
export const ErrorCode = Object.freeze({
|
|
23
34
|
NO_ROOT: 'no_root', INVALID_PATH: 'invalid_path', OUTSIDE_ROOT: 'outside_root', NOT_FOUND: 'not_found',
|
|
24
35
|
NOT_DIR: 'not_dir', NOT_FILE: 'not_file', DENIED: 'denied', CURSOR_EXPIRED: 'cursor_expired',
|
|
25
36
|
INVALID_OFFSET: 'invalid_offset', INVALID_SORT: 'invalid_sort', TOO_LARGE: 'too_large', IO: 'io_error',
|
|
37
|
+
DRAFT_FAILED: 'draft_failed', DRAFT_TOO_LONG: 'draft_too_long',
|
|
26
38
|
});
|
|
27
39
|
|
|
28
40
|
// 目录排序:值是下面四种之一,缺省(请求不带 sort)是名称。方向由排序键决定,只在 lib/tree.mjs 里定义一处。
|
|
@@ -48,6 +60,20 @@ export function imageType(name) {
|
|
|
48
60
|
return dot < 0 ? null : IMAGE_TYPES[name.slice(dot + 1).toLowerCase()] ?? null;
|
|
49
61
|
}
|
|
50
62
|
|
|
63
|
+
// 相对路径的规则只在这一处:模块(lib/paths.mjs)校验请求,页面恢复保存的 cwd 时用同一个函数。
|
|
64
|
+
// 空串是根目录;拒绝过长、控制字符、绝对路径和 `..`。返回 { segments }(去掉空段和 `.`)或 { problem }(给人看的原因)。
|
|
65
|
+
export const MAX_PATH = 4096;
|
|
66
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
67
|
+
export const hasControl = text => CONTROL.test(text);
|
|
68
|
+
export function splitRelative(path) {
|
|
69
|
+
if (typeof path !== 'string' || path.length > MAX_PATH) return { problem: '路径无效' };
|
|
70
|
+
if (hasControl(path)) return { problem: '路径含控制字符' };
|
|
71
|
+
if (path.startsWith('/')) return { problem: '只接受相对路径' };
|
|
72
|
+
const segments = path.split('/').filter(part => part !== '' && part !== '.');
|
|
73
|
+
if (segments.includes('..')) return { problem: '路径不能含 ..' };
|
|
74
|
+
return { segments };
|
|
75
|
+
}
|
|
76
|
+
|
|
51
77
|
export const messageSize = message => JSON.stringify({ message }).length;
|
|
52
78
|
|
|
53
79
|
// 带 code 的错误,模块里到处抛,主模块转成回答里的 error。
|
package/view/restore.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// 滚动位置的两样记录:待恢复的位置(页面重建、换会话、返回上一层之后,等内容到了才用)和上层的位置(图标视图进入子目录前的位置,只在内存里)。
|
|
2
|
+
// 不碰 DOM:滚动的元素由页面通过 panes 给。设计见 docs/design/phase-3.md 第 14.5 节。
|
|
3
|
+
import { View } from './model.mjs';
|
|
4
|
+
|
|
5
|
+
export const TRAIL_LIMIT = 32;
|
|
6
|
+
|
|
7
|
+
// 图标视图进入子目录之前,上层的滚动位置:按目录存,最多 limit 层,满了丢最久没用的。不存进 setState:页面卸载后就没了。
|
|
8
|
+
export function createTrail(limit = TRAIL_LIMIT) {
|
|
9
|
+
const tops = new Map();
|
|
10
|
+
return {
|
|
11
|
+
remember(dir, top) { tops.delete(dir); tops.set(dir, top); while (tops.size > limit) tops.delete(tops.keys().next().value); },
|
|
12
|
+
// 取出并删掉:回到上一层时用一次。
|
|
13
|
+
take(dir) { const top = tops.get(dir); tops.delete(dir); return top; },
|
|
14
|
+
clear() { tops.clear(); },
|
|
15
|
+
get size() { return tops.size; },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const VIEW = { tree: View.LIST, grid: View.ICONS };
|
|
20
|
+
|
|
21
|
+
// 待恢复的滚动:每个视图(tree、grid)最多一份。不能只等一次 refresh() 完成:旧的一轮完成不等于内容到了,太早设置会被夹回顶部。
|
|
22
|
+
// 一份恢复绑定会话、根目录的身份(model.scope)、排序和目录(图标视图是 cwd),任何一个对不上就作废;
|
|
23
|
+
// 绑定的视图不是正在看的视图时等着,切过去才用。目标目录的内容到了才用,条数不够时浏览器夹到能到的最大值;加载失败就结束;用户自己滚动了就放弃。
|
|
24
|
+
// panes:{ tree, grid },各有 scroll() 和 scrollTo(top)。
|
|
25
|
+
export function createRestore(model, panes) {
|
|
26
|
+
const plans = { tree: null, grid: null };
|
|
27
|
+
// 内容到了:列表是根和展开的目录,图标是 cwd;每个都已经加载(或失败了,失败也算有结果),空着的、没发出的不算。
|
|
28
|
+
const dirsOf = key => (key === 'grid' ? [model.cwd] : ['', ...model.expanded]);
|
|
29
|
+
const bound = (key, plan) => plan.session === model.session && plan.scope === model.scope && plan.sort === model.sort && (key === 'tree' || plan.dir === model.cwd);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
// 现在的滚动位置就是用户没动过的基准:调用前页面先把滚动元素滚到顶部。
|
|
33
|
+
plan(key, top) {
|
|
34
|
+
plans[key] = { session: model.session, scope: model.scope, sort: model.sort, dir: key === 'grid' ? model.cwd : '', top, at: panes[key].scroll() };
|
|
35
|
+
},
|
|
36
|
+
drop(key) { plans[key] = null; },
|
|
37
|
+
clear() { plans.tree = plans.grid = null; },
|
|
38
|
+
// 还在等的位置(保存状态时用它,别存成还没恢复的 0);对不上的不算。
|
|
39
|
+
top(key) { return plans[key] && bound(key, plans[key]) ? plans[key].top : null; },
|
|
40
|
+
// 滚动事件:位置不是计划时的基准,就是用户自己滚的,不再跳回去。
|
|
41
|
+
scrolled(key) { if (plans[key] && panes[key].scroll() !== plans[key].at) plans[key] = null; },
|
|
42
|
+
// 每次重画之后调用。
|
|
43
|
+
settle() {
|
|
44
|
+
for (const key of Object.keys(plans)) {
|
|
45
|
+
const plan = plans[key];
|
|
46
|
+
if (!plan) continue;
|
|
47
|
+
if (!bound(key, plan)) { plans[key] = null; continue; }
|
|
48
|
+
if (model.view !== VIEW[key]) continue;
|
|
49
|
+
const states = dirsOf(key).map(dir => model.dirs.get(dir));
|
|
50
|
+
if (key === 'grid' && states[0] && !states[0].loaded && states[0].error) { plans[key] = null; continue; }
|
|
51
|
+
if (!states.every(state => state && (state.loaded || state.error))) continue;
|
|
52
|
+
plans[key] = null;
|
|
53
|
+
panes[key].scrollTo(plan.top);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// 预览里选中的文字:裁到正文元素里面,算出覆盖的行。DOM 的部分只用 Range 的标准方法,行号是纯函数。
|
|
2
|
+
const START_TO_START = 0, END_TO_END = 2; // Range.START_TO_START、Range.END_TO_END
|
|
3
|
+
|
|
4
|
+
// el 是正文(一个 pre 加一个文本节点)。选区为空或和 el 不相交返回 null;
|
|
5
|
+
// 否则把选区裁到 el 里,返回 { text, start }:裁剪后的文字和它在 el 文字里的起点(UTF-16 偏移)。裁剪后为空也返回 null。
|
|
6
|
+
// 选区的起点或终点落在 el 外面(跨出正文、从行号列开始拖)时,裁掉外面的部分。
|
|
7
|
+
export function clippedSelection(el, selection = globalThis.getSelection?.()) {
|
|
8
|
+
if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null;
|
|
9
|
+
const range = selection.getRangeAt(0);
|
|
10
|
+
if (!range.intersectsNode(el)) return null;
|
|
11
|
+
const whole = document.createRange();
|
|
12
|
+
whole.selectNodeContents(el);
|
|
13
|
+
const clipped = range.cloneRange();
|
|
14
|
+
if (range.compareBoundaryPoints(START_TO_START, whole) < 0) clipped.setStart(whole.startContainer, whole.startOffset);
|
|
15
|
+
if (range.compareBoundaryPoints(END_TO_END, whole) > 0) clipped.setEnd(whole.endContainer, whole.endOffset);
|
|
16
|
+
const text = clipped.toString();
|
|
17
|
+
if (text === '') return null;
|
|
18
|
+
const before = whole.cloneRange();
|
|
19
|
+
before.setEnd(clipped.startContainer, clipped.startOffset);
|
|
20
|
+
return { text, start: before.toString().length };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const lineAt = (text, offset) => {
|
|
24
|
+
let line = 1;
|
|
25
|
+
for (let at = text.indexOf('\n'); at !== -1 && at < offset; at = text.indexOf('\n', at + 1)) line++;
|
|
26
|
+
return line;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// 选中 text[start, end) 覆盖的行(从 1 数)。选区的结尾正好在行首时(如三击选行,选区包含那一行的换行)不算下一行。
|
|
30
|
+
export function linesOf(text, start, end) {
|
|
31
|
+
const last = end > start && text[end - 1] === '\n' ? end - 1 : end;
|
|
32
|
+
return { startLine: lineAt(text, start), endLine: lineAt(text, Math.max(start, last)) };
|
|
33
|
+
}
|
package/view/style.css
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/* 资源管理器的页面,颜色、字体、字号只用 App 给的 --coda-* 变量(插件视图的主题变量)。
|
|
1
|
+
/* 资源管理器的页面,颜色、字体、字号只用 App 给的 --coda-* 变量(插件视图的主题变量)。
|
|
2
|
+
唯一的例外是下面的 --tone-*:种类图标的色调,主题变量里没有这一组。 */
|
|
2
3
|
:root {
|
|
3
4
|
--hover: var(--coda-hover, var(--coda-fill, rgba(0,0,0,.05)));
|
|
4
5
|
--line: var(--coda-separator, rgba(0,0,0,.1));
|
|
@@ -10,6 +11,20 @@
|
|
|
10
11
|
font: var(--coda-font-size, 13px)/1.45 var(--coda-font, -apple-system, system-ui, sans-serif);
|
|
11
12
|
color: var(--coda-foreground, #1d1d1f); background: transparent;
|
|
12
13
|
}
|
|
14
|
+
/* 种类图标的色调。图标是 currentColor,.tone-* 把颜色给到 svg 上;文件夹用强调色,链接和特殊文件没有色调,跟随三级文字色。
|
|
15
|
+
两种外观下,在 --coda-background 和 --coda-card 上的对比度都不低于 3:1(harness 读真实计算值检查);改色值要重新跑。 */
|
|
16
|
+
:root {
|
|
17
|
+
--tone-gray: #6b6b72; --tone-blue: #2a68b8; --tone-yellow: #946a00; --tone-green: #26803f; --tone-teal: #12788f;
|
|
18
|
+
--tone-orange: #b85a14; --tone-red: #c0303a; --tone-purple: #7447bd; --tone-pink: #b8326f;
|
|
19
|
+
}
|
|
20
|
+
:root.coda-dark {
|
|
21
|
+
--tone-gray: #a3a3a9; --tone-blue: #6aa9ec; --tone-yellow: #e3b63e; --tone-green: #63c77f; --tone-teal: #58c3dd;
|
|
22
|
+
--tone-orange: #f0964f; --tone-red: #f0717a; --tone-purple: #ac87ec; --tone-pink: #ee77ac;
|
|
23
|
+
}
|
|
24
|
+
.tone-accent { color: var(--coda-accent, #0a84ff); }
|
|
25
|
+
.tone-gray { color: var(--tone-gray); } .tone-blue { color: var(--tone-blue); } .tone-yellow { color: var(--tone-yellow); }
|
|
26
|
+
.tone-green { color: var(--tone-green); } .tone-teal { color: var(--tone-teal); } .tone-orange { color: var(--tone-orange); }
|
|
27
|
+
.tone-red { color: var(--tone-red); } .tone-purple { color: var(--tone-purple); } .tone-pink { color: var(--tone-pink); }
|
|
13
28
|
* { box-sizing: border-box; }
|
|
14
29
|
html, body { margin: 0; height: 100%; }
|
|
15
30
|
body { display: flex; flex-direction: column; overflow: hidden; -webkit-user-select: none; user-select: none;
|
|
@@ -25,13 +40,13 @@ p { margin: 0; }
|
|
|
25
40
|
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
26
41
|
[hidden] { display: none !important; }
|
|
27
42
|
|
|
28
|
-
/*
|
|
43
|
+
/* 面板(目录树、图标、预览、说明、属性页)叠在同一处,只切可见性:隐藏的树保留滚动位置,切换不改变布局。 */
|
|
29
44
|
#stage { position: relative; flex: 1 1 auto; min-height: 0; }
|
|
30
45
|
.pane { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; padding-bottom: var(--safe-bottom); }
|
|
31
46
|
.pane.off { visibility: hidden; pointer-events: none; }
|
|
32
47
|
.empty { display: grid; align-content: start; justify-items: center; gap: 6px; padding: 32px 20px; text-align: center; }
|
|
33
48
|
.notice-icon { display: grid; place-items: center; margin-bottom: 6px; color: var(--coda-secondary, #6e6e73); }
|
|
34
|
-
.notice-icon svg { display: block; }
|
|
49
|
+
.notice-icon svg { display: block; color: inherit; } /* 说明区的图标不上色 */
|
|
35
50
|
|
|
36
51
|
/* 页内工具条:iPhone 树页在顶部(返回、根目录名、⋯),文件页在底部(.bottom:返回、刷新、复制路径)。没有 coda.toolbar 的其他平台(harness)是一条文字按钮。 */
|
|
37
52
|
.bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
|
|
@@ -53,6 +68,10 @@ p { margin: 0; }
|
|
|
53
68
|
.row { position: relative; display: flex; align-items: center; gap: 4px; height: var(--row-h); padding: 0 8px 0 calc(var(--indent) * var(--d, 0) + var(--pad));
|
|
54
69
|
border-radius: var(--coda-radius, 6px); white-space: nowrap; cursor: default; }
|
|
55
70
|
.row.sel { background: var(--coda-selection, var(--hover)); }
|
|
71
|
+
/* Mac 的缩进线:每一层一条,在祖先箭头(14 点宽)的中心,按行的 --d 画重复渐变,不增加 DOM。
|
|
72
|
+
用 ::after(::before 是 iPhone 的分隔线),画在行背景的上面,悬停、选中的 background 盖不掉。 */
|
|
73
|
+
.coda-mac .row::after { content: ''; position: absolute; top: 0; bottom: 0; left: calc(var(--pad) + 6.5px); width: calc(var(--indent) * var(--d, 0)); pointer-events: none;
|
|
74
|
+
background: repeating-linear-gradient(to right, var(--coda-separator, var(--line)) 0 1px, transparent 1px var(--indent)); }
|
|
56
75
|
.row.more, .row.retry { color: var(--coda-accent, #0a84ff); cursor: pointer; }
|
|
57
76
|
.row.status { display: block; overflow: hidden; text-overflow: ellipsis; line-height: var(--row-h); color: var(--coda-secondary, #6e6e73); }
|
|
58
77
|
.row.dead .name, .row.dead .ico { color: var(--coda-tertiary, #a1a1a6); }
|
|
@@ -75,13 +94,13 @@ p { margin: 0; }
|
|
|
75
94
|
|
|
76
95
|
/* 预览:头部永远占一行名字加一行说明,加载和失败只换下面的内容。 */
|
|
77
96
|
.preview { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; } /* 底部的安全区归文件页的工具条 */
|
|
78
|
-
.phead button { flex: none; white-space: nowrap; }
|
|
79
|
-
.phead { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
|
|
80
|
-
.pico { flex: none; display: grid; place-items: center; color: var(--coda-secondary, #6e6e73); }
|
|
81
|
-
.pico svg { display: block; }
|
|
97
|
+
.phead button, .ghead button { flex: none; white-space: nowrap; }
|
|
98
|
+
.phead, .ghead { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
|
|
99
|
+
.pico, .ghico { flex: none; display: grid; place-items: center; color: var(--coda-secondary, #6e6e73); }
|
|
100
|
+
.pico svg, .ghico svg { display: block; }
|
|
82
101
|
button.icon { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0; border-radius: var(--coda-radius, 6px); color: var(--coda-secondary, #6e6e73); }
|
|
83
102
|
button.icon svg { display: block; }
|
|
84
|
-
.pname { font-weight: 600; }
|
|
103
|
+
.pname, .gname-head { font-weight: 600; }
|
|
85
104
|
.pbody { flex: 1 1 auto; min-height: 0; overflow: auto; }
|
|
86
105
|
.code { display: flex; width: max-content; min-width: 100%; font: .9em/1.55 var(--coda-mono, ui-monospace, Menlo, monospace); }
|
|
87
106
|
.code pre { margin: 0; font: inherit; }
|
|
@@ -93,26 +112,67 @@ button.icon svg { display: block; }
|
|
|
93
112
|
|
|
94
113
|
#notice:focus { outline: none; }
|
|
95
114
|
.menu { position: fixed; z-index: 10; width: max-content; max-width: min(280px, calc(100vw - var(--safe-left) - var(--safe-right) - 8px)); padding: 4px; border: 1px solid var(--coda-outline, var(--line)); border-radius: var(--coda-radius-card, 10px);
|
|
96
|
-
background: var(--coda-card, var(--coda-background, #fff));
|
|
97
|
-
|
|
98
|
-
|
|
115
|
+
background: var(--coda-card, var(--coda-background, #fff));
|
|
116
|
+
/* 高度有上限:内容多(长路径加五项)时在菜单里滚动,不超出安全区;位置由 menu.mjs 夹在安全区内。 */
|
|
117
|
+
max-height: calc(100vh - var(--safe-top) - var(--safe-bottom) - 8px); overflow-y: auto; overscroll-behavior: contain; }
|
|
118
|
+
.menu button { display: flex; align-items: center; gap: 4px; width: 100%; padding: 5px 8px; border-radius: var(--coda-radius, 6px); }
|
|
119
|
+
.check { flex: none; display: grid; place-items: center; width: 14px; color: var(--coda-accent, #0a84ff); }
|
|
99
120
|
.check svg { display: block; }
|
|
121
|
+
.check.back { color: var(--coda-secondary, #6e6e73); }
|
|
122
|
+
/* 带二级菜单的项:右边的箭头;展开着的和悬停同色。 */
|
|
123
|
+
.sub-arrow { flex: none; display: grid; place-items: center; margin-left: auto; padding-left: 12px; color: var(--coda-secondary, #6e6e73); }
|
|
124
|
+
.sub-arrow svg { display: block; }
|
|
125
|
+
.menu button[aria-expanded="true"] { background: var(--coda-selection, var(--hover)); }
|
|
100
126
|
/* 菜单宽度随内容,上限见 .menu:路径超过上限折行,大小 · 完整修改时间不折。 */
|
|
101
|
-
.menu-path { padding: 4px
|
|
102
|
-
.menu-info { padding: 0
|
|
127
|
+
.menu-path { padding: 4px 8px 6px; overflow-wrap: anywhere; }
|
|
128
|
+
.menu-info { padding: 0 8px 6px; margin-top: -4px; white-space: nowrap; }
|
|
103
129
|
.menu-sep { margin: 4px 6px; border: 0; border-top: 1px solid var(--line); }
|
|
104
|
-
.menu-head { padding: 4px
|
|
130
|
+
.menu-head { padding: 4px 8px 2px; font-weight: 600; }
|
|
105
131
|
.pmeta.warn { color: var(--coda-orange, #b25000); }
|
|
106
132
|
|
|
133
|
+
/* 底部的短提示:普通的是前景色(成功),.warn 是橙色(失败)。 */
|
|
107
134
|
.hint { position: fixed; left: calc(8px + var(--safe-left)); right: calc(8px + var(--safe-right)); bottom: calc(8px + var(--safe-bottom)); z-index: 10;
|
|
108
135
|
padding: 8px 12px; border: 1px solid var(--coda-outline, var(--line)); border-radius: var(--coda-radius-card, 10px);
|
|
109
|
-
background: var(--coda-card, var(--coda-background, #fff)); color: var(--coda-
|
|
136
|
+
background: var(--coda-card, var(--coda-background, #fff)); color: var(--coda-foreground, #1d1d1f); }
|
|
137
|
+
.hint.warn { color: var(--coda-orange, #b25000); }
|
|
138
|
+
|
|
139
|
+
/* 属性页:头部和正文同预览(.preview 的 .phead、.pbody);正文是 标签 值 两列,值可以折行、可以选中。 */
|
|
140
|
+
.ibody { padding: 8px 12px calc(12px + var(--safe-bottom)); }
|
|
141
|
+
.irow { display: flex; gap: 12px; padding: 5px 0; }
|
|
142
|
+
.ilabel { flex: none; width: 5.5em; text-align: right; }
|
|
143
|
+
.ivalue { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
|
|
144
|
+
.ivalue .warn { color: var(--coda-orange, #b25000); }
|
|
145
|
+
.coda-ios .irow { flex-direction: column; gap: 0; padding: 8px 4px; }
|
|
146
|
+
.coda-ios .ilabel { width: auto; text-align: left; font-size: .85em; }
|
|
147
|
+
|
|
148
|
+
/* 图标视图:头部同预览(样式和 .phead 一样,类名另取,页面和 harness 里按 .phead 查预览头部的不会撞上),下面一个滚动的 .gbody,只画可见的一段(grid.mjs 量 .cell 的宽和高)。
|
|
149
|
+
单元格宽度固定,Mac 约 72 点、iPhone 约 88 点;列数按容器宽度算,每列的宽度平分余下的空间,单元格在列里居中。说明项占满一整行。 */
|
|
150
|
+
:root { --cell-w: 72px; --gico: 32px; --gname-h: calc(var(--coda-font-size, 13px) * 2.4); --note-h: calc(var(--coda-font-size, 13px) * 2.4); }
|
|
151
|
+
.coda-ios { --cell-w: 88px; --gico: 40px; --note-h: 44px; }
|
|
152
|
+
.grid { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; } /* 底部的安全区归 .gbody */
|
|
153
|
+
.gbody { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; padding-bottom: var(--safe-bottom); }
|
|
154
|
+
.gspacer { position: relative; margin: 8px 0; }
|
|
155
|
+
.gwin { position: absolute; left: 0; right: 0; top: 0; display: grid; justify-items: center; }
|
|
156
|
+
.gi { cursor: default; }
|
|
157
|
+
/* 单元格是固定高度:图标、两行名字(.gname 的行高 1.3、字号 .92em,两行 2.392 个字号,--gname-h 取 2.4)、上下各 4 点,刚好放下,只有一行名字时不多留空白。 */
|
|
158
|
+
.cell { display: flex; flex-direction: column; align-items: center; gap: 2px; width: var(--cell-w); height: calc(var(--gico) + 2px + var(--gname-h) + 8px); padding: 4px; border-radius: var(--coda-radius, 6px); }
|
|
159
|
+
.cell.sel { background: var(--coda-selection, var(--hover)); }
|
|
160
|
+
.cell .gico { flex: none; display: grid; place-items: center; color: var(--coda-secondary, #6e6e73); }
|
|
161
|
+
.cell .gico svg { display: block; width: var(--gico); height: var(--gico); }
|
|
162
|
+
.cell.dir .gico { color: var(--coda-accent, #0a84ff); }
|
|
163
|
+
.cell.dead .gname, .cell.dead .gico { color: var(--coda-tertiary, #a1a1a6); }
|
|
164
|
+
.gname { max-width: 100%; text-align: center; font-size: .92em; line-height: 1.3; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
|
|
165
|
+
/* 说明行(空目录、读取中……)一行高,比单元格矮;grid.mjs 分别量两种高度,布局映射按两种算。 */
|
|
166
|
+
.gnote { grid-column: 1 / -1; justify-self: stretch; height: var(--note-h); line-height: var(--note-h); padding: 0 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; color: var(--coda-secondary, #6e6e73); }
|
|
167
|
+
.gnote.more, .gnote.retry { color: var(--coda-accent, #0a84ff); cursor: pointer; }
|
|
168
|
+
.coda-ios .cell { -webkit-touch-callout: none; } /* 长按由页面接管,不弹系统菜单 */
|
|
169
|
+
.coda-ios .cell:active { background: var(--hover); } /* 按下:和列表的行一样 */
|
|
110
170
|
|
|
111
171
|
/* 悬停只在有鼠标时:触摸后不会留着。 */
|
|
112
172
|
@media (hover: hover) {
|
|
113
173
|
.bar button:hover, button.icon:hover { background: var(--hover); }
|
|
114
|
-
.row.entry:hover { background: var(--hover); }
|
|
115
|
-
.row.entry.sel:hover { background: var(--coda-selection, var(--hover)); }
|
|
174
|
+
.row.entry:hover, .cell:hover { background: var(--hover); }
|
|
175
|
+
.row.entry.sel:hover, .cell.sel:hover { background: var(--coda-selection, var(--hover)); }
|
|
116
176
|
.menu button:hover { background: var(--coda-selection, var(--hover)); }
|
|
117
177
|
}
|
|
118
178
|
|
|
@@ -135,7 +195,7 @@ button.icon svg { display: block; }
|
|
|
135
195
|
.coda-ios .meta { display: none; }
|
|
136
196
|
.coda-ios .chev { order: 9; width: 14px; }
|
|
137
197
|
.coda-ios .row.dir .chev { color: var(--coda-accent, #0a84ff); }
|
|
138
|
-
.coda-ios .row.file .chev svg { visibility:
|
|
198
|
+
.coda-ios .row.file .chev svg { visibility: inherit; } /* 不写 visible:目录树被属性页盖住(visibility: hidden)时,箭头不能透出来 */
|
|
139
199
|
.coda-ios .row.dead .chev { display: none; }
|
|
140
200
|
.coda-ios button { min-height: 44px; min-width: 44px; }
|
|
141
201
|
.coda-ios .bar { gap: 0; padding: 0 8px; }
|
|
@@ -143,12 +203,13 @@ button.icon svg { display: block; }
|
|
|
143
203
|
.coda-ios .bar button.icon { padding: 0; justify-content: center; }
|
|
144
204
|
.coda-ios .bar.bottom { padding: 0 8px var(--safe-bottom); }
|
|
145
205
|
.coda-ios .bar.bottom button { flex: 1 1 0; justify-content: center; } /* 横排单行:横屏只有 390 点高 */
|
|
146
|
-
.coda-ios .phead { padding: 4px 12px; gap: 4px; }
|
|
147
|
-
.coda-ios .phead button { padding: 0 8px; }
|
|
206
|
+
.coda-ios .phead, .coda-ios .ghead { padding: 4px 12px; gap: 4px; }
|
|
207
|
+
.coda-ios .phead button, .coda-ios .ghead button { padding: 0 8px; }
|
|
148
208
|
.coda-ios .code { font-size: .8em; } /* 窄屏多看些:17 点下约 13.6 点 */
|
|
149
|
-
.coda-ios .menu button { padding: 0
|
|
150
|
-
.coda-ios .menu
|
|
209
|
+
.coda-ios .menu button { padding: 0 10px; }
|
|
210
|
+
.coda-ios .menu button:active { background: var(--coda-selection, var(--hover)); }
|
|
211
|
+
.coda-ios .menu-head { padding: 6px 10px 2px; }
|
|
151
212
|
|
|
152
213
|
/* 横屏:客户端隐藏导航栏,页面自己给返回。近似 verticalSizeClass 的判断,不等价(iPad、Duo 不单独适配)。 */
|
|
153
|
-
.bar .exit { display: none; }
|
|
154
|
-
@media (orientation: landscape) and (max-height: 500px) { .coda-ios .bar .exit { display: inline-flex; } }
|
|
214
|
+
.bar .exit, .bar.exit-only { display: none; } /* 只有返回的工具条(属性页):返回不显示,整条也不占高度 */
|
|
215
|
+
@media (orientation: landscape) and (max-height: 500px) { .coda-ios .bar .exit { display: inline-flex; } .coda-ios .bar.exit-only { display: flex; } }
|