@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/tree.mjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
// 目录树:visibleRows 把模型压成扁平行(纯逻辑);mountTree 只画可见的那一段,上万条也不卡。
|
|
2
2
|
import { EntryKind, SortKey } from './protocol.mjs';
|
|
3
3
|
import { dateText, infoText, sizeText, subText } from './format.mjs';
|
|
4
|
+
import { mountGestures } from './gestures.mjs';
|
|
4
5
|
import { icon, iconFor } from './icons.mjs';
|
|
5
6
|
import { isHidden, joinPath } from './model.mjs';
|
|
6
7
|
|
|
7
8
|
const OVERSCAN = 8;
|
|
8
|
-
// 长按:按住这么久、移动不超过这个距离才算。
|
|
9
|
-
export const HOLD_MS = 500;
|
|
10
|
-
export const HOLD_SLOP = 10;
|
|
11
9
|
|
|
12
10
|
// 行:{ type: 'entry' | 'status' | 'more', path, name, depth, kind, link, size, mtimeMs, open, busy, failed, text };size、mtimeMs 读不到时没有
|
|
13
11
|
export function visibleRows(model) {
|
|
@@ -40,7 +38,7 @@ export function visibleRows(model) {
|
|
|
40
38
|
// 根目录的名字:路径的最后一段,分区标题和 iPhone 的页内工具条共用。
|
|
41
39
|
export const rootName = path => path.split('/').filter(Boolean).pop() ?? path;
|
|
42
40
|
|
|
43
|
-
const TITLES = { [EntryKind.LINK]: '指向工作目录外的链接,不能打开', [EntryKind.OTHER]: '不能打开的文件' };
|
|
41
|
+
export const TITLES = { [EntryKind.LINK]: '指向工作目录外的链接,不能打开', [EntryKind.OTHER]: '不能打开的文件' };
|
|
44
42
|
|
|
45
43
|
// handlers: { open(path), toggle(path), more(path), retry(path), menu(event, row) }
|
|
46
44
|
// menu 收到整行(路径、种类、大小、修改时间)。
|
|
@@ -135,50 +133,18 @@ export function mountTree(el, model, handlers, { draggable = true, longPress = f
|
|
|
135
133
|
return node;
|
|
136
134
|
}
|
|
137
135
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const { clientX: x, clientY: y, pointerId: id } = event;
|
|
151
|
-
hold = { id, x, y, timer: setTimeout(() => {
|
|
152
|
-
hold = null;
|
|
153
|
-
swallow = true;
|
|
154
|
-
handlers.menu({ clientX: x, clientY: y }, row);
|
|
155
|
-
}, HOLD_MS) };
|
|
156
|
-
});
|
|
157
|
-
el.addEventListener('pointermove', event => {
|
|
158
|
-
if (hold && event.pointerId === hold.id && Math.hypot(event.clientX - hold.x, event.clientY - hold.y) > HOLD_SLOP) cancelHold();
|
|
159
|
-
});
|
|
160
|
-
for (const type of ['pointerup', 'pointercancel']) el.addEventListener(type, cancelHold);
|
|
161
|
-
el.addEventListener('scroll', cancelHold, { passive: true });
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
el.addEventListener('click', event => {
|
|
165
|
-
if (swallow) { swallow = false; return; }
|
|
166
|
-
const row = rowOf(event);
|
|
167
|
-
if (!row) return;
|
|
168
|
-
if (row.type === 'more') return handlers.more(row.path);
|
|
169
|
-
if (row.type === 'status') return row.retry ? handlers.retry(row.path) : undefined;
|
|
170
|
-
if (row.kind === EntryKind.DIR) handlers.toggle(row.path);
|
|
171
|
-
else if (row.kind === EntryKind.FILE) handlers.open(row.path);
|
|
172
|
-
});
|
|
173
|
-
el.addEventListener('contextmenu', event => {
|
|
174
|
-
const row = rowOf(event);
|
|
175
|
-
if (row?.type === 'entry') { event.preventDefault(); handlers.menu(event, row); }
|
|
176
|
-
});
|
|
177
|
-
el.addEventListener('dragstart', event => {
|
|
178
|
-
const row = rowOf(event);
|
|
179
|
-
if (row?.type !== 'entry') return event.preventDefault();
|
|
180
|
-
event.dataTransfer.setData('text/plain', row.path); // 相对路径
|
|
181
|
-
event.dataTransfer.effectAllowed = 'copy';
|
|
136
|
+
const gestures = mountGestures(el, {
|
|
137
|
+
hit: event => rows[event.target.closest?.('.row')?.dataset.i],
|
|
138
|
+
pressable: row => row.type === 'entry',
|
|
139
|
+
activate: row => {
|
|
140
|
+
if (row.type === 'more') return handlers.more(row.path);
|
|
141
|
+
if (row.type === 'status') return row.retry ? handlers.retry(row.path) : undefined;
|
|
142
|
+
if (row.kind === EntryKind.DIR) handlers.toggle(row.path);
|
|
143
|
+
else if (row.kind === EntryKind.FILE) handlers.open(row.path);
|
|
144
|
+
},
|
|
145
|
+
menu: (event, row) => handlers.menu(event, row),
|
|
146
|
+
dragText: row => row.path,
|
|
147
|
+
longPress,
|
|
182
148
|
});
|
|
183
149
|
el.addEventListener('scroll', paint, { passive: true });
|
|
184
150
|
new ResizeObserver(paint).observe(el);
|
|
@@ -189,6 +155,6 @@ export function mountTree(el, model, handlers, { draggable = true, longPress = f
|
|
|
189
155
|
scroll: () => el.scrollTop,
|
|
190
156
|
scrollTo(top) { el.scrollTop = top; },
|
|
191
157
|
// 切会话时调用:长按的等待和吞点击的标记都属于上一个会话。
|
|
192
|
-
reset() {
|
|
158
|
+
reset() { gestures.reset(); },
|
|
193
159
|
};
|
|
194
160
|
}
|