@coda-console/resource-manager 0.3.0 → 0.5.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 +10 -2
- package/lib/content.mjs +15 -2
- package/lib/draft.mjs +57 -0
- package/lib/info.mjs +137 -0
- package/lib/snapshots.mjs +52 -0
- package/lib/tree.mjs +237 -48
- package/main.mjs +69 -14
- package/package.json +1 -1
- package/view/app.mjs +104 -82
- package/view/chat.mjs +45 -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 +67 -0
- package/view/hint.mjs +20 -0
- package/view/icons.mjs +139 -22
- package/view/index.html +1 -0
- package/view/info.mjs +117 -0
- package/view/menu.mjs +76 -0
- package/view/model.mjs +48 -19
- package/view/preview.mjs +16 -18
- package/view/protocol.mjs +24 -5
- package/view/selection.mjs +33 -0
- package/view/style.css +60 -13
- package/view/tree.mjs +39 -14
package/view/tree.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// 目录树:visibleRows 把模型压成扁平行(纯逻辑);mountTree 只画可见的那一段,上万条也不卡。
|
|
2
|
-
import { EntryKind } from './protocol.mjs';
|
|
2
|
+
import { EntryKind, SortKey } from './protocol.mjs';
|
|
3
|
+
import { dateText, infoText, sizeText, subText } from './format.mjs';
|
|
3
4
|
import { icon, iconFor } from './icons.mjs';
|
|
4
5
|
import { isHidden, joinPath } from './model.mjs';
|
|
5
6
|
|
|
@@ -8,7 +9,7 @@ const OVERSCAN = 8;
|
|
|
8
9
|
export const HOLD_MS = 500;
|
|
9
10
|
export const HOLD_SLOP = 10;
|
|
10
11
|
|
|
11
|
-
// 行:{ type: 'entry' | 'status' | 'more', path, name, depth, kind, link, open, busy, failed, text }
|
|
12
|
+
// 行:{ type: 'entry' | 'status' | 'more', path, name, depth, kind, link, size, mtimeMs, open, busy, failed, text };size、mtimeMs 读不到时没有
|
|
12
13
|
export function visibleRows(model) {
|
|
13
14
|
const rows = [];
|
|
14
15
|
const walk = (dir, depth) => {
|
|
@@ -17,12 +18,14 @@ export function visibleRows(model) {
|
|
|
17
18
|
if (!state.loaded) return rows.push({ type: 'status', path: dir, depth, text: `读取失败:${state.error.message}`, retry: true });
|
|
18
19
|
// 刷新失败:旧条目保留,最上方加一行原因,点它重试。这一行不算内容,空目录的判断在它之后。
|
|
19
20
|
if (state.error) rows.push({ type: 'status', path: dir, depth, text: `更新失败:${state.error.message}`, retry: true });
|
|
21
|
+
// 条目太多按名称排了:说明行固定行高,不算内容,不影响「空目录」的判断。
|
|
22
|
+
if (state.sortFallback) rows.push({ type: 'status', path: dir, depth, text: '条目太多,只能按名称排列' });
|
|
20
23
|
const before = rows.length;
|
|
21
24
|
for (const entry of state.entries) {
|
|
22
25
|
if (!model.showHidden && isHidden(entry.name)) continue;
|
|
23
26
|
const path = joinPath(dir, entry.name), open = entry.kind === EntryKind.DIR && model.expanded.has(path);
|
|
24
27
|
rows.push({
|
|
25
|
-
type: 'entry', path, name: entry.name, depth, kind: entry.kind, link: entry.link === true, open,
|
|
28
|
+
type: 'entry', path, name: entry.name, depth, kind: entry.kind, link: entry.link === true, size: entry.size, mtimeMs: entry.mtimeMs, open,
|
|
26
29
|
busy: open && model.dirs.get(path)?.loading === true, failed: open ? model.dirs.get(path)?.error?.message : undefined,
|
|
27
30
|
});
|
|
28
31
|
if (open) walk(path, depth + 1);
|
|
@@ -39,10 +42,11 @@ export const rootName = path => path.split('/').filter(Boolean).pop() ?? path;
|
|
|
39
42
|
|
|
40
43
|
const TITLES = { [EntryKind.LINK]: '指向工作目录外的链接,不能打开', [EntryKind.OTHER]: '不能打开的文件' };
|
|
41
44
|
|
|
42
|
-
// handlers: { open(path), toggle(path), more(path), retry(path), menu(event,
|
|
43
|
-
//
|
|
45
|
+
// handlers: { open(path), toggle(path), more(path), retry(path), menu(event, row) }
|
|
46
|
+
// menu 收到整行(路径、种类、大小、修改时间)。
|
|
47
|
+
// draggable:触屏上拖行没有用处,还会抢滚动,关掉。now:当前时间,日期的相对格式用,测试可注入。
|
|
44
48
|
// longPress:触屏上按住一行打开 handlers.menu(Mac 用右键)。不设 touch-action,滚动照旧,滚动接管时收到 pointercancel 作废。
|
|
45
|
-
export function mountTree(el, model, handlers, { draggable = true, longPress = false } = {}) {
|
|
49
|
+
export function mountTree(el, model, handlers, { draggable = true, longPress = false, now = Date.now } = {}) {
|
|
46
50
|
const title = document.createElement('div'), spacer = document.createElement('div'), win = document.createElement('div');
|
|
47
51
|
title.className = 'section truncate'; spacer.className = 'spacer'; win.className = 'win';
|
|
48
52
|
title.hidden = true;
|
|
@@ -73,10 +77,11 @@ export function mountTree(el, model, handlers, { draggable = true, longPress = f
|
|
|
73
77
|
const first = Math.max(0, Math.floor(top / rowH) - OVERSCAN);
|
|
74
78
|
const last = Math.min(rows.length, Math.ceil((top + el.clientHeight) / rowH) + OVERSCAN);
|
|
75
79
|
win.style.transform = `translateY(${first * rowH}px)`;
|
|
76
|
-
|
|
80
|
+
const time = now();
|
|
81
|
+
win.replaceChildren(...rows.slice(first, last).map((row, i) => rowNode(row, first + i, time)));
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
function rowNode(row, index) {
|
|
84
|
+
function rowNode(row, index, time) {
|
|
80
85
|
const node = document.createElement('div');
|
|
81
86
|
node.className = `row ${row.type}`;
|
|
82
87
|
node.dataset.i = index;
|
|
@@ -92,21 +97,41 @@ export function mountTree(el, model, handlers, { draggable = true, longPress = f
|
|
|
92
97
|
if (row.path === model.selected) node.classList.add('sel');
|
|
93
98
|
if (row.kind === EntryKind.DIR) node.setAttribute('aria-expanded', row.open);
|
|
94
99
|
if (!dead && draggable) node.draggable = true;
|
|
95
|
-
// 一份 DOM
|
|
96
|
-
const chevron = document.createElement('span'), glyph = document.createElement('span'), label = document.createElement('span'), tail = document.createElement('span');
|
|
100
|
+
// 一份 DOM:箭头、图标、名字(iPhone 下面跟日期 · 大小)、Mac 的 meta、尾标;iPhone 的箭头用 CSS order 排到最后,两端各用 CSS 藏起另一端的那段。
|
|
101
|
+
const chevron = document.createElement('span'), glyph = document.createElement('span'), main = document.createElement('span'), label = document.createElement('span'), tail = document.createElement('span');
|
|
97
102
|
chevron.className = 'chev';
|
|
98
103
|
if (row.busy) chevron.textContent = '…';
|
|
99
104
|
else if (!dead) chevron.append(icon('chevron', 12)); // 文件的箭头 Mac 上由 CSS 藏起来,只占位
|
|
100
105
|
if (row.open) node.classList.add('open');
|
|
101
106
|
glyph.className = 'ico';
|
|
102
107
|
glyph.append(icon(iconFor(row)));
|
|
108
|
+
main.className = 'main';
|
|
103
109
|
label.className = 'name truncate';
|
|
104
110
|
label.textContent = row.name;
|
|
111
|
+
main.append(label);
|
|
112
|
+
const parts = [chevron, glyph, main];
|
|
113
|
+
if (!dead) {
|
|
114
|
+
// 能打开的条目带信息;link、other 没有。文件夹没有的部分整个不画:iPhone 名字垂直居中,Mac 右侧不留空位。
|
|
115
|
+
const subContent = subText(row, time), metaContent = model.sort === SortKey.DATE ? dateText(row, time) : sizeText(row);
|
|
116
|
+
if (subContent) {
|
|
117
|
+
const sub = document.createElement('span');
|
|
118
|
+
sub.className = 'sub caption secondary truncate';
|
|
119
|
+
sub.textContent = subContent;
|
|
120
|
+
main.append(sub);
|
|
121
|
+
}
|
|
122
|
+
if (metaContent) {
|
|
123
|
+
const meta = document.createElement('span');
|
|
124
|
+
meta.className = 'meta caption secondary';
|
|
125
|
+
meta.textContent = metaContent;
|
|
126
|
+
parts.push(meta);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
105
129
|
tail.className = row.failed ? 'tail warn' : 'tail';
|
|
106
130
|
if (row.failed) tail.append(icon('warning', 14));
|
|
107
131
|
else if (row.link) tail.append(icon('turn', 14));
|
|
108
|
-
|
|
109
|
-
node.
|
|
132
|
+
const info = row.failed || TITLES[row.kind] ? '' : infoText(row);
|
|
133
|
+
node.title = row.failed ? `${row.path}\n读取失败:${row.failed}` : TITLES[row.kind] ? `${row.path}\n${TITLES[row.kind]}` : info ? `${row.path}\n${info}` : row.path;
|
|
134
|
+
node.append(...parts, tail);
|
|
110
135
|
return node;
|
|
111
136
|
}
|
|
112
137
|
|
|
@@ -126,7 +151,7 @@ export function mountTree(el, model, handlers, { draggable = true, longPress = f
|
|
|
126
151
|
hold = { id, x, y, timer: setTimeout(() => {
|
|
127
152
|
hold = null;
|
|
128
153
|
swallow = true;
|
|
129
|
-
handlers.menu({ clientX: x, clientY: y }, row
|
|
154
|
+
handlers.menu({ clientX: x, clientY: y }, row);
|
|
130
155
|
}, HOLD_MS) };
|
|
131
156
|
});
|
|
132
157
|
el.addEventListener('pointermove', event => {
|
|
@@ -147,7 +172,7 @@ export function mountTree(el, model, handlers, { draggable = true, longPress = f
|
|
|
147
172
|
});
|
|
148
173
|
el.addEventListener('contextmenu', event => {
|
|
149
174
|
const row = rowOf(event);
|
|
150
|
-
if (row?.type === 'entry') { event.preventDefault(); handlers.menu(event, row
|
|
175
|
+
if (row?.type === 'entry') { event.preventDefault(); handlers.menu(event, row); }
|
|
151
176
|
});
|
|
152
177
|
el.addEventListener('dragstart', event => {
|
|
153
178
|
const row = rowOf(event);
|