@coda-console/resource-manager 0.7.1 → 0.7.2
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 +2 -1
- package/package.json +1 -1
- package/view/app.mjs +138 -23
- package/view/file-app.mjs +6 -2
- package/view/gestures.mjs +12 -6
- package/view/grid.mjs +8 -2
- package/view/info.mjs +9 -1
- package/view/menu.mjs +31 -1
- package/view/press.mjs +109 -0
- package/view/preview.mjs +15 -2
- package/view/style.css +24 -8
- package/view/tree.mjs +6 -1
package/README.md
CHANGED
|
@@ -8,7 +8,8 @@ Coda 插件:会话旁的文件浏览器。浏览这个会话的工作目录,
|
|
|
8
8
|
## 功能
|
|
9
9
|
|
|
10
10
|
- 两种视图:**列表**(目录树,按需展开,超大目录分页显示)和**图标**(一次看一层,每个条目是类型图标加名字,名字最多两行,`package.json` 这样的名字优先在扩展名前折行)。在「更多」菜单(Mac)或「⋯」菜单(iPhone)的「显示」›「视图」里切换,全局一份,两种视图各自保留滚动位置。
|
|
11
|
-
- **Mac 照 Finder
|
|
11
|
+
- **Mac 照 Finder**:**按下**就选中(不等松开),**双击**打开——文件在侧栏里切到预览,文件夹在列表里展开或收起、在图标视图里进入;单击展开箭头只展开,选中不变;按下空白取消选中;右键和按住 Control 的左键不改选中;右键菜单第一项是「打开」(文件夹在列表里写「展开」「收起」),不能打开的条目没有。**iPhone** 轻点就打开(文件夹展开或进入,文件在页内切到预览,不另开页面)。
|
|
12
|
+
- **按键的质感**(`0.7.2`):两端按下就有底色反馈(页面自己加状态,不靠 `:active`;快点一下也看得到,滑动时不闪;菜单开着时点外面那一下只关菜单),Mac 的按钮是箭头光标;菜单有阴影,iPhone 的菜单出现时有淡入加缩放;iPhone 打开文件、属性页和返回(含侧滑)是滑动过渡,图标视图进出目录是淡入。系统打开「减弱动态效果」后所有动画和过渡都不做,按下反馈照常。没有触感(契约没有这个接口)。
|
|
12
13
|
- 图标视图回上一层:iPhone 用系统的返回,Mac 点头部最左边的返回键或按 ⌘↑,退回的那一层里选中刚才进去的文件夹。**没有预览面板**:只有一个侧栏,也没有面包屑。
|
|
13
14
|
- **Mac 的键盘**:点一下目录树或图标视图让它拿到焦点(Tab 也能进来),↑ ↓ 移动选中(图标视图按行列走),列表里 → 展开、← 收起或选中所在的文件夹,图标视图里 ← → 选左右的条目;⌘↓ 同双击(打开、展开、进入);⌘↑ 在图标视图里回上一层,在预览里返回目录树或图标视图。不做多选、按字母跳转,Return 和空格也没绑定。读屏的 `aria-activedescendant` 没做(见 `docs/backlog.md`)。
|
|
14
15
|
- 文本预览(带行号,可跨行选中复制,最多读 1 MiB)和图片预览(PNG、JPEG、GIF、WebP、SVG,最多 8 MiB)。
|
package/package.json
CHANGED
package/view/app.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { mountMenu } from './menu.mjs';
|
|
|
10
10
|
import { Model, STATE_LIMIT, View, noticeText, parseState, putSession, trimState } from './model.mjs';
|
|
11
11
|
import { showNotice } from './notice.mjs';
|
|
12
12
|
import { mountPreview } from './preview.mjs';
|
|
13
|
+
import { mountPress, onMotionChange, reducedMotion } from './press.mjs';
|
|
13
14
|
import { EntryKind, RootState, SortKey, Type } from './protocol.mjs';
|
|
14
15
|
import { createRestore, createTrail } from './restore.mjs';
|
|
15
16
|
import { browseAction, previewAction } from './keys.mjs';
|
|
@@ -32,7 +33,9 @@ model.showHidden = persisted.hidden;
|
|
|
32
33
|
model.sort = persisted.sort;
|
|
33
34
|
model.view = persisted.view;
|
|
34
35
|
const hint = mountHint($('hint'));
|
|
35
|
-
const menu = mountMenu($('menu'), $('submenu'), { flyout: !isIOS }); // Mac 的二级菜单在左边弹出,iPhone
|
|
36
|
+
const menu = mountMenu($('menu'), $('submenu'), { flyout: !isIOS, animate: isIOS }); // Mac 的二级菜单在左边弹出,iPhone 在菜单里切到下一层,菜单出现时有动画
|
|
37
|
+
// 按下反馈:页面里只有一份(press.mjs);菜单开着时点外面的那一下已被菜单消费,不加反馈、不选中。
|
|
38
|
+
const press = mountPress({ identity: () => `${model.session}\n${model.scope}`, consumed: menu.consumed });
|
|
36
39
|
const chat = createChat({ link: conn.link, copy: text => coda.copy(text), hint });
|
|
37
40
|
// 属性页和图标视图的上一层:iPhone 用原生返回(coda.back);Mac 的客户端会替声明了返回的页面画一个带小箭头的导航,
|
|
38
41
|
// 和侧栏标题重复,所以 Mac 和没有 coda.back 的环境一样,头部最左边自己放返回。
|
|
@@ -43,8 +46,8 @@ const tree = mountTree($('tree'), model, {
|
|
|
43
46
|
more: path => model.loadMore(path),
|
|
44
47
|
retry: path => model.retry(path),
|
|
45
48
|
menu: (event, row) => pathMenu(event, row),
|
|
46
|
-
select: isIOS ? null : path =>
|
|
47
|
-
}, { draggable: !isIOS, longPress: isIOS, keyboard: !isIOS });
|
|
49
|
+
select: isIOS ? null : path => mouseSelect(path),
|
|
50
|
+
}, { draggable: !isIOS, longPress: isIOS, keyboard: !isIOS, press, consumed: menu.consumed });
|
|
48
51
|
const grid = mountGrid($('grid'), model, {
|
|
49
52
|
open: openFile,
|
|
50
53
|
enter: path => enterDir(path),
|
|
@@ -52,8 +55,8 @@ const grid = mountGrid($('grid'), model, {
|
|
|
52
55
|
retry: path => model.retry(path),
|
|
53
56
|
menu: (event, cell) => pathMenu(event, cell),
|
|
54
57
|
back: nativeBack ? null : () => leaveDir(),
|
|
55
|
-
select: isIOS ? null : path =>
|
|
56
|
-
}, { draggable: !isIOS, longPress: isIOS, keyboard: !isIOS });
|
|
58
|
+
select: isIOS ? null : path => mouseSelect(path),
|
|
59
|
+
}, { draggable: !isIOS, longPress: isIOS, keyboard: !isIOS, press, consumed: menu.consumed });
|
|
57
60
|
const restore = createRestore(model, { tree, grid });
|
|
58
61
|
const trail = createTrail();
|
|
59
62
|
const preview = mountPreview($('preview'), {
|
|
@@ -90,6 +93,7 @@ function openInView(path) {
|
|
|
90
93
|
// 快速两次轻点:第一次已切到预览,目录树 .off 不接指针事件,第二次落不到条目上。
|
|
91
94
|
function openFile(path) {
|
|
92
95
|
openPressed = !isIOS; // 用户在 Mac 上打开的:render 把焦点交给预览面板
|
|
96
|
+
note({ kind: 'push', from: mode(), to: 'preview' });
|
|
93
97
|
model.openFile(path);
|
|
94
98
|
}
|
|
95
99
|
|
|
@@ -109,6 +113,11 @@ function selectEntry(path) {
|
|
|
109
113
|
queueSave();
|
|
110
114
|
}
|
|
111
115
|
const browser = () => (model.view === View.ICONS ? grid : tree);
|
|
116
|
+
// Mac 在按下时选中(选中条目或在空白处取消):和键盘一样算用户接管,这个视图还在等的滚动恢复作废,免得恢复到达时把刚选中的条目滚走。
|
|
117
|
+
function mouseSelect(path) {
|
|
118
|
+
restore.drop(model.view === View.ICONS ? 'grid' : 'tree');
|
|
119
|
+
selectEntry(path);
|
|
120
|
+
}
|
|
112
121
|
|
|
113
122
|
// 预览头部的返回和预览里的 ⌘↑ 是同一个动作:opened 清掉,selected 留着。
|
|
114
123
|
function closePreview() {
|
|
@@ -130,14 +139,94 @@ function paintNotice() {
|
|
|
130
139
|
showNotice($('notice'), failed ? { failure: conn.failure, retry: conn.hello } : { text: key });
|
|
131
140
|
}
|
|
132
141
|
|
|
142
|
+
// ---- iPhone 层级切换的过渡(第 17.6 节)----
|
|
143
|
+
// 只在用户操作引起时做:入口(openFile、openInfo、goBack、enterDir、leaveDir)在改模型之前记一个一次性的「过渡意图」,render 消费它:
|
|
144
|
+
// 前后对得上就播,对不上就丢掉。换会话、换根目录、恢复、notice、changed 的刷新都没有意图,不播。意图由最外层的入口记,goBack 内部调用的 closeInfo、leaveDir 不记。
|
|
145
|
+
// 层级的深浅:浏览区(tree、grid)浅,预览和属性页深。深的一层永远在上:打开时滑入盖住浅层,返回时滑出、露出浅层。
|
|
146
|
+
const PANES = ['tree', 'grid', 'preview', 'notice', 'info'];
|
|
147
|
+
const DEEP = new Set(['preview', 'info']);
|
|
148
|
+
const SLIDE_MS = 280, FADE_IN_MS = 150;
|
|
149
|
+
let intent = null; // { kind: 'push' | 'pop' | 'fade', from?, to }:from、to 是模式;fade 的 to 是目标 cwd
|
|
150
|
+
let lastMode = null; // 上一次画出的模式
|
|
151
|
+
let running = null; // 正在播的过渡:{ leaving, after, end }
|
|
152
|
+
const note = next => { if (isIOS) intent = next; };
|
|
153
|
+
|
|
154
|
+
// 结束正在播的过渡到终点,立刻。结束和自然播完走同一个函数,幂等:强制结束之后迟到的 finish 事件什么都不做。
|
|
155
|
+
function endRunning() { running?.end(); }
|
|
156
|
+
function begin(anims, { ids = [], leaving = null, after = [] } = {}) {
|
|
157
|
+
let ended = false, pending = anims.length;
|
|
158
|
+
const slides = ids.length > 0; // 滑动期间整页不响应点按(同 iOS 原生的导航切换);目录淡入不算
|
|
159
|
+
if (slides) document.documentElement?.classList.add('moving');
|
|
160
|
+
const mine = running = { leaving, after, end() {
|
|
161
|
+
if (ended) return;
|
|
162
|
+
ended = true;
|
|
163
|
+
if (slides) document.documentElement?.classList.remove('moving');
|
|
164
|
+
for (const anim of anims) anim.cancel();
|
|
165
|
+
for (const id of ids) $(id).classList.remove('layer');
|
|
166
|
+
if (running === mine) running = null;
|
|
167
|
+
for (const fn of mine.after) fn();
|
|
168
|
+
applyPanes(mode());
|
|
169
|
+
} };
|
|
170
|
+
// 浏览器自己取消一条动画时只触发 cancel、不触发 finish:任一动画取消都结束整次过渡(end 幂等,它自己 cancel 引出的 oncancel 回来什么都不做)。
|
|
171
|
+
for (const anim of anims) { anim.onfinish = () => { if (--pending === 0) mine.end(); }; anim.oncancel = () => mine.end(); }
|
|
172
|
+
return mine;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 面板的可见和可操作:只有当前的一层能操作;离开的那一层在退场期间还看得见,但 inert 且不接指针。
|
|
176
|
+
function applyPanes(current) {
|
|
177
|
+
const leaving = running?.leaving ?? null;
|
|
178
|
+
for (const id of PANES) {
|
|
179
|
+
$(id).classList.toggle('off', current !== id && leaving !== id);
|
|
180
|
+
$(id).classList.toggle('leaving', leaving === id);
|
|
181
|
+
$(id).inert = current !== id;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 这次 render 要不要播层级切换:消费意图。fade 要等内容到了,不在这里。
|
|
186
|
+
function takeSlide(current) {
|
|
187
|
+
const taken = intent;
|
|
188
|
+
if (!taken || taken.kind === 'fade') return null;
|
|
189
|
+
intent = null;
|
|
190
|
+
if (!isIOS || reducedMotion() || taken.from !== lastMode || taken.to !== current || lastMode === current) return null;
|
|
191
|
+
if (DEEP.has(taken.from) === DEEP.has(taken.to) || typeof $(current).animate !== 'function') return null;
|
|
192
|
+
return taken;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function slide({ kind, from, to }, after) {
|
|
196
|
+
const leaving = $(from), entering = $(to), deep = kind === 'push' ? entering : leaving, shallow = kind === 'push' ? leaving : entering;
|
|
197
|
+
const options = { duration: SLIDE_MS, easing: 'cubic-bezier(.2,.8,.2,1)' };
|
|
198
|
+
const shift = kind === 'push' ? ['translateX(0)', 'translateX(-25%)'] : ['translateX(-25%)', 'translateX(0)'];
|
|
199
|
+
const dim = kind === 'push' ? ['brightness(1)', 'brightness(.9)'] : ['brightness(.9)', 'brightness(1)'];
|
|
200
|
+
const away = ['translateX(100%)', 'translateX(0)'];
|
|
201
|
+
// 参与过渡的两层都要不透明,否则透出对面(只在过渡期间);变暗不加遮罩元素,不挡指针。
|
|
202
|
+
leaving.classList.add('layer');
|
|
203
|
+
entering.classList.add('layer');
|
|
204
|
+
begin([
|
|
205
|
+
deep.animate({ transform: kind === 'push' ? away : [...away].reverse() }, options),
|
|
206
|
+
shallow.animate({ transform: shift, filter: dim }, options),
|
|
207
|
+
], { ids: [from, to], leaving: from, after });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 图标视图进出目录:内容到了才播,只给内容播,不给「正在读取」播。
|
|
211
|
+
function takeFade(current) {
|
|
212
|
+
if (intent?.kind !== 'fade') return;
|
|
213
|
+
if (current !== 'grid' || model.cwd !== intent.to) { intent = null; return; } // 中途换了目录、或打开了文件:作废
|
|
214
|
+
const state = model.dirs.get(model.cwd);
|
|
215
|
+
if (!state || !(state.loaded || state.error)) return; // 还在读取:意图留着,内容到了的那次 render 播
|
|
216
|
+
intent = null;
|
|
217
|
+
if (reducedMotion()) return;
|
|
218
|
+
const anim = grid.fadeIn(FADE_IN_MS);
|
|
219
|
+
if (anim) { endRunning(); begin([anim]); }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 属性页是逻辑上关了但画面还在(退场期间):render 决定什么时候释放。
|
|
223
|
+
let infoStopped = false;
|
|
224
|
+
|
|
133
225
|
function render() {
|
|
134
226
|
const current = mode();
|
|
135
227
|
const refocus = backPressed && document.hasFocus(), handoff = openPressed && document.hasFocus();
|
|
136
228
|
backPressed = openPressed = false;
|
|
137
|
-
|
|
138
|
-
$(id).classList.toggle('off', current !== id);
|
|
139
|
-
$(id).inert = current !== id;
|
|
140
|
-
}
|
|
229
|
+
const slideIn = takeSlide(current);
|
|
141
230
|
if (current === 'notice') paintNotice();
|
|
142
231
|
const browsing = current === 'tree' || current === 'grid';
|
|
143
232
|
(model.view === View.ICONS ? grid : tree).render(); // 只画正在用的视图,另一个留着它的内容和滚动位置
|
|
@@ -145,11 +234,20 @@ function render() {
|
|
|
145
234
|
restore.settle();
|
|
146
235
|
// 待恢复的位置只属于它那个文件:opened 清了或换成别的文件,位置作废。
|
|
147
236
|
if (pending.preview !== null && pending.path !== model.opened) pending.preview = null;
|
|
237
|
+
const released = []; // 这次停止的面板:画面的释放等退场结束(有过渡时),否则马上
|
|
148
238
|
if (current === 'preview' && preview.path !== model.opened) {
|
|
149
239
|
// 位置要等内容到了、真的设上才清:之前离开页面或换会话,saveNow 还存它。作废的读取不清,由接替它的读取用上。
|
|
150
240
|
const scroll = pending.preview;
|
|
151
241
|
preview.open(model.opened, scroll).then(used => { if (used && scroll !== null && pending.preview === scroll) pending.preview = null; });
|
|
152
|
-
} else if ((browsing || current === 'notice') && preview.path !== null) preview.
|
|
242
|
+
} else if ((browsing || current === 'notice') && preview.path !== null) { preview.stop(); released.push(() => preview.release()); } // 属性页和预览一样只切可见性,不动别的面板的内容
|
|
243
|
+
if (infoStopped && current !== 'info') { infoStopped = false; released.push(() => info.release()); }
|
|
244
|
+
// 上一个过渡:模式变了或又有新的过渡就立刻结束到终点(它的释放比对打开次数,又打开过就不释放)。
|
|
245
|
+
if (running && (slideIn || current !== lastMode)) endRunning();
|
|
246
|
+
if (slideIn) slide(slideIn, slideIn.kind === 'pop' ? released.splice(0) : []); // 返回:被停止的那层到退场结束才释放
|
|
247
|
+
for (const fn of released) fn();
|
|
248
|
+
applyPanes(current);
|
|
249
|
+
takeFade(current);
|
|
250
|
+
lastMode = current;
|
|
153
251
|
// 返回按钮随预览一起 inert,焦点会掉到页面外:用户刚点了返回、页面又持有焦点时交给目录树或网格。
|
|
154
252
|
// 后台刷新、切会话、root 变化造成的切换不动焦点,免得抢走客户端输入框的焦点。
|
|
155
253
|
if (refocus && browsing) browser().focus();
|
|
@@ -158,6 +256,9 @@ function render() {
|
|
|
158
256
|
syncToolbar();
|
|
159
257
|
declareBack();
|
|
160
258
|
}
|
|
259
|
+
// 窗口尺寸变了(旋转)、系统的减弱动态效果改了:正在播的动画结束到终点。
|
|
260
|
+
window.addEventListener('resize', endRunning);
|
|
261
|
+
onMotionChange(endRunning);
|
|
161
262
|
|
|
162
263
|
// ---- 工具栏:Mac 用 coda.toolbar,没有的(iOS、harness)退成页内一条 ----
|
|
163
264
|
// Mac 只有一个原生按钮「更多」:原生菜单带向下的箭头,关不掉,所以按下后由页面弹菜单。返回键在预览头部,不在这里。
|
|
@@ -281,7 +382,7 @@ function saveNow() {
|
|
|
281
382
|
// setState 超限会同步抛错:再收紧一次,仍失败就放弃这次,不影响界面。
|
|
282
383
|
if (quiet(() => (coda.setState(persisted), true)) === undefined) quiet(() => coda.setState(trimState(persisted, session, STATE_LIMIT / 4)));
|
|
283
384
|
}
|
|
284
|
-
quiet(() => coda.on('visibility', visible => { if (!visible) saveNow(); }));
|
|
385
|
+
quiet(() => coda.on('visibility', visible => { if (!visible) { press.reset(); saveNow(); } }));
|
|
285
386
|
$('tree').addEventListener('scroll', queueSave, { passive: true });
|
|
286
387
|
$('tree').addEventListener('scroll', () => restore.scrolled('tree'), { passive: true });
|
|
287
388
|
grid.onScroll(queueSave);
|
|
@@ -293,6 +394,7 @@ preview.onScroll(menu.hide);
|
|
|
293
394
|
// 行菜单顶上是路径,下面一行 大小 · 完整修改时间(文件夹只有修改时间,读不到就没有这一行);指向外面的链接和不能打开的条目没有元数据,不显示这一行。
|
|
294
395
|
// 不能打开的条目(指向外面或失效的链接、other)没有「添加到聊天」,和不能拖动一致;它们仍有复制路径和属性。
|
|
295
396
|
function pathMenu(event, row) {
|
|
397
|
+
press.reset(); // 长按弹出菜单:按下反馈立即去掉
|
|
296
398
|
const dead = row.kind === EntryKind.LINK || row.kind === EntryKind.OTHER;
|
|
297
399
|
// Mac 的第一项和双击是同一个动作(右键不改选中);文件夹在列表里写展开或收起,别的写打开。iPhone 轻点就是打开,菜单不变。
|
|
298
400
|
const folder = row.kind === EntryKind.DIR, listed = model.view !== View.ICONS;
|
|
@@ -339,16 +441,18 @@ function enterDir(path) {
|
|
|
339
441
|
trail.remember(model.cwd, grid.scroll());
|
|
340
442
|
selectEntry(null); // 进入新的一层:选中清空
|
|
341
443
|
model.enter(path);
|
|
444
|
+
note({ kind: 'fade', to: model.cwd });
|
|
342
445
|
shownCwd = model.cwd;
|
|
343
446
|
restore.drop('grid');
|
|
344
447
|
grid.scrollTo(0);
|
|
345
448
|
declareBack();
|
|
346
449
|
}
|
|
347
|
-
// 退 levels 层(到根为止);已经在根目录返回 false。
|
|
348
|
-
function leaveDir(levels = 1) {
|
|
450
|
+
// 退 levels 层(到根为止);已经在根目录返回 false。record 为假时不记过渡意图(goBack 里的内部调用:意图由它记)。
|
|
451
|
+
function leaveDir(levels = 1, record = true) {
|
|
349
452
|
if (model.cwd === '') return false;
|
|
350
453
|
const from = model.cwd.split('/');
|
|
351
454
|
model.leave(levels);
|
|
455
|
+
if (record) note({ kind: 'fade', to: model.cwd });
|
|
352
456
|
land(trail.take(model.cwd) ?? 0);
|
|
353
457
|
// 选中来时经过的那个文件夹(退到的那一层的直接子项)。目录被删、模型自己退回上层走 landed,不改选中。
|
|
354
458
|
selectEntry(from.slice(0, model.cwd === '' ? 1 : model.cwd.split('/').length + 1).join('/'));
|
|
@@ -388,13 +492,16 @@ function declareBack(force = false) {
|
|
|
388
492
|
}
|
|
389
493
|
// 退 steps 层:先关预览,再关属性页,再退图标视图的目录;返回是不是真的退了。横屏的返回和原生返回共用。
|
|
390
494
|
// 没就绪时页面是说明区,看不见预览和目录层:不消耗它们(保存的 opened、cwd 不变),横屏的返回直接关视图。
|
|
495
|
+
// 一次返回只记一个意图,按它消耗了什么:关了预览或属性页记 pop(目标是退完之后的模式),只退了目录记 fade;内部调用的 closeInfo、leaveDir 不记。
|
|
391
496
|
function goBack(steps) {
|
|
392
497
|
if (!model.ready) return false;
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (
|
|
498
|
+
const from = mode();
|
|
499
|
+
let used = 0, layer = false;
|
|
500
|
+
if (previewOpen() && steps > used) { model.closeFile(); used++; layer = true; } // 走和 Mac 一样的 closeFile:opened 清,selected 留着
|
|
501
|
+
if (infoOpen && steps > used) { closeInfo(false); used++; layer = true; }
|
|
396
502
|
const levels = Math.min(steps - used, model.view === View.ICONS && model.cwd !== '' ? model.cwd.split('/').length : 0);
|
|
397
|
-
if (levels > 0) { leaveDir(levels); used += levels; }
|
|
503
|
+
if (levels > 0) { leaveDir(levels, false); used += levels; }
|
|
504
|
+
if (used > 0) note(layer ? { kind: 'pop', from, to: mode() } : { kind: 'fade', to: model.cwd });
|
|
398
505
|
return used > 0;
|
|
399
506
|
}
|
|
400
507
|
if (nativeBack) quiet(() => coda.on('back', event => {
|
|
@@ -403,15 +510,20 @@ if (nativeBack) quiet(() => coda.on('back', event => {
|
|
|
403
510
|
|
|
404
511
|
// ---- 属性页:所有关闭的路径(原生返回、横屏的返回、换会话、根目录变化)都重新声明回上层 ----
|
|
405
512
|
function openInfo(row) {
|
|
513
|
+
note({ kind: 'push', from: mode(), to: 'info' });
|
|
406
514
|
infoOpen = true;
|
|
515
|
+
infoStopped = false;
|
|
407
516
|
info.open(row.path, row);
|
|
408
517
|
declareBack();
|
|
409
518
|
schedule();
|
|
410
519
|
}
|
|
411
|
-
|
|
520
|
+
// 停止是立即的(取消统计、作废在途的读取);画面留到退场结束,由 render 释放。换会话、换根目录要立即释放(immediate),也不记意图。
|
|
521
|
+
function closeInfo(record = true, immediate = false) {
|
|
412
522
|
if (!infoOpen) return;
|
|
413
523
|
infoOpen = false;
|
|
414
|
-
info.close();
|
|
524
|
+
if (immediate) info.close();
|
|
525
|
+
else { info.stop(); infoStopped = true; } // 在统计的一并取消
|
|
526
|
+
if (record) note({ kind: 'pop', from: 'info', to: mode() });
|
|
415
527
|
declareBack();
|
|
416
528
|
schedule();
|
|
417
529
|
}
|
|
@@ -419,8 +531,11 @@ function closeInfo() {
|
|
|
419
531
|
// ---- 模块的消息(代次和握手由 connection 处理)----
|
|
420
532
|
function onSession(data) {
|
|
421
533
|
saveNow(); // 先存旧会话
|
|
534
|
+
intent = null;
|
|
535
|
+
endRunning();
|
|
536
|
+
press.reset();
|
|
422
537
|
preview.close();
|
|
423
|
-
closeInfo();
|
|
538
|
+
closeInfo(false, true);
|
|
424
539
|
menu.hide();
|
|
425
540
|
tree.reset();
|
|
426
541
|
grid.reset();
|
|
@@ -440,11 +555,11 @@ function onSession(data) {
|
|
|
440
555
|
|
|
441
556
|
function onRoot(data) {
|
|
442
557
|
const before = model.root;
|
|
443
|
-
if (data.state !== before?.state || data.path !== before?.path) menu.hide(); //
|
|
444
|
-
if (data.state !== RootState.READY || before?.path !== data.path) closeInfo(); // 属性页看的是旧根目录下的路径
|
|
558
|
+
if (data.state !== before?.state || data.path !== before?.path) { menu.hide(); intent = null; endRunning(); } // 开着的菜单里的路径是旧根目录下的;换根目录不播过渡
|
|
559
|
+
if (data.state !== RootState.READY || before?.path !== data.path) closeInfo(false, true); // 属性页看的是旧根目录下的路径
|
|
445
560
|
const scope = model.scope;
|
|
446
561
|
const done = model.receive(data);
|
|
447
|
-
if (model.scope !== scope) { invalidateScroll(); pending.preview = null; } // 换了根目录(同根重建不算):旧根目录的位置和记录不能给新的用,待恢复的预览位置也是
|
|
562
|
+
if (model.scope !== scope) { invalidateScroll(); pending.preview = null; press.reset(); } // 换了根目录(同根重建不算):旧根目录的位置和记录不能给新的用,待恢复的预览位置也是
|
|
448
563
|
if (done && data.state === RootState.READY) {
|
|
449
564
|
if (before?.path !== data.path) { if (model.opened !== null) preview.reload(); } else preview.refresh(); // 换了根目录,opened 已清空:旧预览随即关掉,不再读
|
|
450
565
|
}
|
package/view/file-app.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { mountMenu } from './menu.mjs';
|
|
|
10
10
|
import { noticeText } from './model.mjs';
|
|
11
11
|
import { showNotice } from './notice.mjs';
|
|
12
12
|
import { mountPreview } from './preview.mjs';
|
|
13
|
+
import { mountPress } from './press.mjs';
|
|
13
14
|
import { RootState } from './protocol.mjs';
|
|
14
15
|
|
|
15
16
|
const coda = window.coda;
|
|
@@ -36,6 +37,7 @@ let restore = parseScroll(quiet(() => coda.getState()));
|
|
|
36
37
|
const conn = connect(coda, { handlers: { session: onSession, root: onRoot, changed: onChanged }, onStatus: () => schedule() });
|
|
37
38
|
const hint = mountHint($('hint'));
|
|
38
39
|
const menu = mountMenu($('menu'));
|
|
40
|
+
const press = mountPress({ consumed: menu.consumed }); // 按下反馈:刷新、复制、重试等按钮同资源页(第 17.3 节)
|
|
39
41
|
const chat = createChat({ link: conn.link, copy: text => coda.copy(text), hint });
|
|
40
42
|
const preview = mountPreview($('preview'), {
|
|
41
43
|
read: (path, offset) => conn.link.call('read', { path, offset }), copy: text => coda.copy(text),
|
|
@@ -94,6 +96,7 @@ function paintNotice() {
|
|
|
94
96
|
|
|
95
97
|
// ---- 模块的消息(代次和握手由 connection 处理)----
|
|
96
98
|
function onSession(data) {
|
|
99
|
+
press.reset();
|
|
97
100
|
park();
|
|
98
101
|
preview.close();
|
|
99
102
|
menu.hide();
|
|
@@ -105,6 +108,7 @@ function onSession(data) {
|
|
|
105
108
|
|
|
106
109
|
function onRoot(data) {
|
|
107
110
|
const before = root;
|
|
111
|
+
if (data.state !== before?.state || data.path !== before?.path) press.reset();
|
|
108
112
|
if (data.state !== before?.state || data.path !== before?.path) menu.hide(); // 选区和行号是旧内容上的
|
|
109
113
|
root = { state: data.state, path: data.path };
|
|
110
114
|
if (data.state === RootState.READY) {
|
|
@@ -122,7 +126,7 @@ function onChanged() {
|
|
|
122
126
|
// ---- 参数变了:换文件或换会话,旧文件的滚动位置不带过去 ----
|
|
123
127
|
quiet(() => coda.on('context', ({ args }) => {
|
|
124
128
|
const next = argsOf(args);
|
|
125
|
-
if (next.path !== want.path || next.session !== want.session) { restore = null; preview.close(); menu.hide(); hint.hide(); }
|
|
129
|
+
if (next.path !== want.path || next.session !== want.session) { press.reset(); restore = null; preview.close(); menu.hide(); hint.hide(); }
|
|
126
130
|
want = next;
|
|
127
131
|
schedule();
|
|
128
132
|
}));
|
|
@@ -147,7 +151,7 @@ function saveNow() {
|
|
|
147
151
|
if (at) quiet(() => coda.setState({ v: 1, top: at.top, left: at.left }));
|
|
148
152
|
}
|
|
149
153
|
// visibility: false 之后只保证同步事件处理完,所以同步保存。
|
|
150
|
-
quiet(() => coda.on('visibility', visible => { if (!visible) saveNow(); }));
|
|
154
|
+
quiet(() => coda.on('visibility', visible => { if (!visible) { press.reset(); saveNow(); } }));
|
|
151
155
|
preview.onScroll(queueSave);
|
|
152
156
|
preview.onScroll(menu.hide);
|
|
153
157
|
|
package/view/gestures.mjs
CHANGED
|
@@ -7,10 +7,11 @@ export const HOLD_SLOP = 10;
|
|
|
7
7
|
// hit(event) → 点到的那一项或 undefined;pressable(item):能不能弹菜单、拖动、长按(目录树的说明行、「再显示」不能);
|
|
8
8
|
// activate(item):点击(iPhone);Mac 给了 select 就按 Finder 的规则:单击条目只 select(item),单击空白 select(null),双击条目才 activate(item);
|
|
9
9
|
// 说明行、「再显示」这类不能选的项单击就 activate,direct(event, item) 为真的点击(展开箭头)也直接 activate、不选中,双击它不再重复激活。
|
|
10
|
+
// Mac 的选中在按下时做(左键,同 Finder),不等松开:右键、按住 Control 的左键(Mac 上是右键菜单)、被菜单消费的按下(consumed(event):菜单开着时点外面只关菜单)都不选中。
|
|
10
11
|
// 双击靠浏览器的 dblclick,要求派发时目标节点还在容器里,所以 select 不能重画。menu(event, item):右键,长按到点时收到 { clientX, clientY };dragText(item):拖动时带的文字(元素是否可拖由调用方设 draggable);
|
|
11
12
|
// longPress:触屏上按住一项打开 menu,不设 touch-action,滚动照旧,滚动接管时收到 pointercancel 作废。
|
|
12
13
|
// 返回 { reset, dispose }:reset 在切会话时调用,长按的等待和吞点击的标记都属于上一个会话;dispose 摘掉全部监听。
|
|
13
|
-
export function mountGestures(el, { hit, pressable, activate, select, direct = () => false, menu, dragText, longPress = false, scroller = el }) {
|
|
14
|
+
export function mountGestures(el, { hit, pressable, activate, select, direct = () => false, menu, dragText, longPress = false, consumed = () => false, scroller = el }) {
|
|
14
15
|
const listeners = [];
|
|
15
16
|
const on = (target, type, fn, options) => { target.addEventListener(type, fn, options); listeners.push([target, type, fn]); };
|
|
16
17
|
|
|
@@ -23,7 +24,7 @@ export function mountGestures(el, { hit, pressable, activate, select, direct = (
|
|
|
23
24
|
cancelHold();
|
|
24
25
|
swallow = false;
|
|
25
26
|
const item = hit(event);
|
|
26
|
-
if (event.isPrimary === false || !item || !pressable(item)) return;
|
|
27
|
+
if (event.isPrimary === false || !item || !pressable(item) || consumed(event)) return;
|
|
27
28
|
const { clientX: x, clientY: y, pointerId: id } = event;
|
|
28
29
|
hold = { id, x, y, timer: setTimeout(() => {
|
|
29
30
|
hold = null;
|
|
@@ -38,13 +39,18 @@ export function mountGestures(el, { hit, pressable, activate, select, direct = (
|
|
|
38
39
|
on(scroller, 'scroll', cancelHold, { passive: true });
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
if (select) on(el, 'pointerdown', event => {
|
|
43
|
+
if (event.button > 0 || event.ctrlKey || event.isPrimary === false || consumed(event)) return;
|
|
44
|
+
// 按在滚动条上(目标是滚动容器自己,点的位置在内容区之外):不是点空白,不取消选中。
|
|
45
|
+
if (event.target === scroller && (event.offsetX >= scroller.clientWidth || event.offsetY >= scroller.clientHeight)) return;
|
|
46
|
+
const item = hit(event);
|
|
47
|
+
if (!item) select(null);
|
|
48
|
+
else if (pressable(item) && !direct(event, item)) select(item);
|
|
49
|
+
});
|
|
41
50
|
on(el, 'click', event => {
|
|
42
51
|
if (swallow) { swallow = false; return; }
|
|
43
52
|
const item = hit(event);
|
|
44
|
-
if (!select)
|
|
45
|
-
if (!item) select(null);
|
|
46
|
-
else if (!pressable(item) || direct(event, item)) activate(item);
|
|
47
|
-
else select(item);
|
|
53
|
+
if (item && (!select || !pressable(item) || direct(event, item))) activate(item); // 选中已在按下时做过
|
|
48
54
|
});
|
|
49
55
|
if (select) on(el, 'dblclick', event => {
|
|
50
56
|
const item = hit(event);
|
package/view/grid.mjs
CHANGED
|
@@ -122,9 +122,9 @@ export function stepCells(cells, layout, selected, action) {
|
|
|
122
122
|
// handlers: { open(path), enter(path), more(path), retry(path), menu(event, cell), back?, select?(path | null) }
|
|
123
123
|
// select 是 Mac 单击选中,不给就是 iPhone 的轻点打开。
|
|
124
124
|
// back 给了就在头部最左边放「返回」(Mac,和没有原生返回的环境);不给就没有头部,iPhone 用原生返回,标题在工具条上。
|
|
125
|
-
// draggable、longPress 同 mountTree。
|
|
125
|
+
// draggable、longPress、press、consumed 同 mountTree。
|
|
126
126
|
// keyboard:滚动容器(.gbody)可以获得焦点,键盘才接得上(Mac)。
|
|
127
|
-
export function mountGrid(el, model, handlers, { draggable = true, longPress = false, keyboard = false } = {}) {
|
|
127
|
+
export function mountGrid(el, model, handlers, { draggable = true, longPress = false, keyboard = false, press = null, consumed = () => false } = {}) {
|
|
128
128
|
const head = h('div', { class: 'ghead' }), body = h('div', { class: 'gbody' }), spacer = h('div', { class: 'gspacer' }), win = h('div', { class: 'gwin' });
|
|
129
129
|
head.hidden = true;
|
|
130
130
|
if (keyboard) body.tabIndex = 0;
|
|
@@ -172,14 +172,17 @@ export function mountGrid(el, model, handlers, { draggable = true, longPress = f
|
|
|
172
172
|
function cellNode(cell, index) {
|
|
173
173
|
const node = h('div', { class: 'gi' });
|
|
174
174
|
node.dataset.i = index;
|
|
175
|
+
node.dataset.path = cell.path; // 按下反馈认的身份
|
|
175
176
|
if (cell.type !== 'entry') {
|
|
176
177
|
node.className = `gi gnote ${cell.type}`;
|
|
177
178
|
node.textContent = cell.text;
|
|
178
179
|
if (cell.retry) { node.classList.add('retry'); node.title = cell.text; } // 长原因在行里被截断,Mac 悬停看全
|
|
180
|
+
if (cell.retry || cell.type === 'more') press?.paint(node, 'grid', cell.retry ? 'retry' : 'more', cell.path);
|
|
179
181
|
return node;
|
|
180
182
|
}
|
|
181
183
|
const dead = cell.kind === EntryKind.LINK || cell.kind === EntryKind.OTHER;
|
|
182
184
|
node.className = `gi cell ${cell.kind}${dead ? ' dead' : ''}${cell.path === model.selected ? ' sel' : ''}`;
|
|
185
|
+
press?.paint(node, 'grid', 'entry', cell.path);
|
|
183
186
|
if (!dead && draggable) node.draggable = true;
|
|
184
187
|
// 扩展名前给一个优先断点:package.json 折成 package / .json,不在字母中间断;没有点(或点在最前面)、太长时 overflow-wrap 才在任意位置断。
|
|
185
188
|
const dot = cell.name.lastIndexOf('.');
|
|
@@ -219,6 +222,7 @@ export function mountGrid(el, model, handlers, { draggable = true, longPress = f
|
|
|
219
222
|
menu: (event, cell) => handlers.menu(event, cell),
|
|
220
223
|
dragText: cell => cell.path,
|
|
221
224
|
longPress,
|
|
225
|
+
consumed,
|
|
222
226
|
scroller: body,
|
|
223
227
|
});
|
|
224
228
|
// 选中变了只在现有节点上切 .sel,不重建:双击的 dblclick 要落在还在容器里的节点上。
|
|
@@ -244,6 +248,8 @@ export function mountGrid(el, model, handlers, { draggable = true, longPress = f
|
|
|
244
248
|
},
|
|
245
249
|
remeasure() { measuredWidth = body.clientWidth; measure(); this.render(); },
|
|
246
250
|
scroll: () => body.scrollTop,
|
|
251
|
+
// 进出目录的淡入:只给内容(win),头部和滚动条不动;返回动画,由页面记着并在需要时结束。
|
|
252
|
+
fadeIn(duration) { return typeof win.animate === 'function' ? win.animate([{ opacity: 0 }, { opacity: 1 }], { duration, easing: 'ease-out' }) : null; },
|
|
247
253
|
scrollTo(top) { body.scrollTop = top; paint(); }, // 浏览器的滚动事件随后还会画一次;这里先画,位置才马上对
|
|
248
254
|
onScroll(fn) { body.addEventListener('scroll', fn, { passive: true }); },
|
|
249
255
|
get layout() { return layout; },
|
package/view/info.mjs
CHANGED
|
@@ -17,6 +17,7 @@ export function mountInfo(el, { stat, size, rootPath, round, back = null }) {
|
|
|
17
17
|
let reply = null, failure = null; // 属性的回答;取属性失败的原因
|
|
18
18
|
let sizing = null; // 文件夹大小这一次统计:{ abort, round, phase: 'running' | 'done' | 'failed', result, message }
|
|
19
19
|
let token = 0; // 取属性的序号:新的取代旧的,旧的回答不再用
|
|
20
|
+
let opens = 0, stoppedAt = -1; // 同预览:释放只在停止之后没有再打开过时才做
|
|
20
21
|
|
|
21
22
|
const entry = () => reply ?? seed;
|
|
22
23
|
// 指向工作目录内的链接按目标显示:种类和图标看目标的名字(链接自己叫什么不管),没有目标的(外链接)看自己。
|
|
@@ -98,20 +99,27 @@ export function mountInfo(el, { stat, size, rootPath, round, back = null }) {
|
|
|
98
99
|
// seed:目录树里这一行(名字、种类),属性回来之前先画头部。
|
|
99
100
|
open(next, row) {
|
|
100
101
|
this.close();
|
|
102
|
+
opens++;
|
|
101
103
|
path = next;
|
|
102
104
|
seed = { name: row.name, kind: row.kind };
|
|
103
105
|
load();
|
|
104
106
|
},
|
|
105
107
|
// 一轮结束:重取属性,不自动重新统计;已有的统计结果马上标成上次统计(页面的数据轮次变了)。
|
|
106
108
|
refresh() { if (path !== null) { if (reply !== null) paint(); load(); } },
|
|
107
|
-
|
|
109
|
+
// 停止(逻辑关闭,立即):取消统计、作废在途的回答;画面留着,由 release 在退场结束时清掉。
|
|
110
|
+
stop() {
|
|
108
111
|
sizing?.abort.abort();
|
|
109
112
|
sizing = null;
|
|
110
113
|
token++;
|
|
111
114
|
path = seed = reply = failure = null;
|
|
115
|
+
stoppedAt = opens;
|
|
116
|
+
},
|
|
117
|
+
release() {
|
|
118
|
+
if (stoppedAt !== opens) return;
|
|
112
119
|
head.replaceChildren();
|
|
113
120
|
body.replaceChildren();
|
|
114
121
|
},
|
|
122
|
+
close() { this.stop(); this.release(); },
|
|
115
123
|
get path() { return path; },
|
|
116
124
|
};
|
|
117
125
|
}
|
package/view/menu.mjs
CHANGED
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
// 菜单可以有一层二级菜单(项里写 submenu)。「整次菜单」(current)和「当前层」(layer、fly)分开记:
|
|
4
4
|
// 在面板里切到下一层、退回来,整次菜单还是同一次,但上一层的按钮不再响应。第二个面板(sub)也算菜单里面,点它不是点外面。
|
|
5
5
|
import { icon } from './icons.mjs';
|
|
6
|
+
import { onMotionChange, reducedMotion } from './press.mjs';
|
|
6
7
|
|
|
7
8
|
const CLOSE_MS = 150; // 鼠标移到别的项之后,侧面板收起前等多久:斜着移过去不会误关
|
|
8
9
|
const GAP = 2; // 侧面板和根面板之间留的空隙
|
|
10
|
+
const APPEAR_MS = 150; // iPhone 菜单出现:透明度 0→1,根层同时缩放 0.96→1;换层只淡入
|
|
9
11
|
|
|
10
12
|
// el:页面里的 #menu。sub:侧面板(#submenu),没有就不能弹出,二级菜单总是在 el 里切到下一层。
|
|
11
13
|
// flyout:true 时(Mac)鼠标移上去或点击「显示」这类项,侧面板在根面板左边弹出;放不下就退成切到下一层(iPhone 总是这样)。
|
|
12
14
|
// open 之后的位置按安全区夹住(横屏时客户端不替页面留);offsetWidth 在显示后才量得到。
|
|
13
15
|
// 高度有上限(style.css 的 .menu):内容多时在菜单里滚动,不超出安全区。
|
|
14
|
-
|
|
16
|
+
// animate:iPhone 的出现动画(Mac 的原生菜单立刻出现,不做);关闭不做动画。减弱动态效果时也不做。
|
|
17
|
+
export function mountMenu(el, sub = null, { flyout = false, animate = false } = {}) {
|
|
15
18
|
let opener = null; // 打开菜单的按钮;用点打开的没有
|
|
16
19
|
let current = null; // 这一次打开的标记:关闭之后留在手里的按钮不再响应
|
|
17
20
|
let layer = 0; // el 里现在是哪一层:每次换层(进下一层、退回、重新打开、关闭)加一,旧层的按钮据此作废
|
|
@@ -19,6 +22,25 @@ export function mountMenu(el, sub = null, { flyout = false } = {}) {
|
|
|
19
22
|
let spec = null, anchor = null; // 根层的内容和锚点:退回根层、换层后重新定位要用
|
|
20
23
|
let flyButton = null; // 展开着侧面板的那个项
|
|
21
24
|
let closeTimer = null;
|
|
25
|
+
let playing = null; // 正在播的出现动画
|
|
26
|
+
|
|
27
|
+
// 出现动画:scale 为真是根层(从锚点那一侧缩放),否则只淡入。开着的动画先停在终点,免得叠在一起。
|
|
28
|
+
function appear(scale) {
|
|
29
|
+
settle();
|
|
30
|
+
if (!animate || reducedMotion() || typeof el.animate !== 'function') return;
|
|
31
|
+
const frames = scale ? [{ opacity: 0, transform: 'scale(.96)' }, { opacity: 1, transform: 'scale(1)' }] : [{ opacity: 0 }, { opacity: 1 }];
|
|
32
|
+
if (scale) {
|
|
33
|
+
// 缩放原点按夹进安全区之后的最终位置定:菜单在锚点下方从上沿缩放,在上方从下沿;横向贴着锚点的右边或点的位置。
|
|
34
|
+
const box = el.getBoundingClientRect(), at = anchor.getBoundingClientRect?.();
|
|
35
|
+
const below = box.top >= (at ? at.bottom : anchor.clientY) - 1;
|
|
36
|
+
el.style.transformOrigin = `${at ? 'right' : `${Math.max(0, Math.min(box.width, anchor.clientX - box.left))}px`} ${below ? 'top' : 'bottom'}`;
|
|
37
|
+
}
|
|
38
|
+
const mine = playing = el.animate(frames, { duration: APPEAR_MS, easing: 'ease-out' });
|
|
39
|
+
mine.onfinish = mine.oncancel = () => { if (playing === mine) playing = null; };
|
|
40
|
+
}
|
|
41
|
+
// 停止开着的动画:没有 fill,取消就是停在终点;根层的出现动画还没播完就换层、或关闭时调用。
|
|
42
|
+
function settle() { const mine = playing; playing = null; mine?.cancel(); }
|
|
43
|
+
onMotionChange(settle); // 设置在动画进行中变成减弱:结束到终点
|
|
22
44
|
|
|
23
45
|
// items:[{ label, run, checked?, radio? } | { label, submenu: { items } } | { separator: true } | { heading }],checked 不是 undefined 的带对勾(radio 的是单选,其余是开关);
|
|
24
46
|
// 分隔线和小标题不是菜单项,不可点。hover:这一层的项在鼠标移上去时管侧面板(只有根层,且 flyout)。
|
|
@@ -99,6 +121,7 @@ export function mountMenu(el, sub = null, { flyout = false } = {}) {
|
|
|
99
121
|
paintRoot();
|
|
100
122
|
el.hidden = false;
|
|
101
123
|
place();
|
|
124
|
+
appear(true);
|
|
102
125
|
if (at.getBoundingClientRect) { opener = at; opener.setAttribute?.('aria-expanded', 'true'); }
|
|
103
126
|
}
|
|
104
127
|
|
|
@@ -144,10 +167,12 @@ export function mountMenu(el, sub = null, { flyout = false } = {}) {
|
|
|
144
167
|
if (!alive()) return;
|
|
145
168
|
paintRoot();
|
|
146
169
|
place();
|
|
170
|
+
appear(false);
|
|
147
171
|
});
|
|
148
172
|
el.replaceChildren(back, Object.assign(document.createElement('hr'), { className: 'menu-sep' }), ...build(item.submenu.items, alive, false));
|
|
149
173
|
el.scrollTop = 0;
|
|
150
174
|
place();
|
|
175
|
+
appear(false);
|
|
151
176
|
}
|
|
152
177
|
|
|
153
178
|
// 鼠标回到「显示」或侧面板:取消正在等的收起。
|
|
@@ -169,6 +194,7 @@ export function mountMenu(el, sub = null, { flyout = false } = {}) {
|
|
|
169
194
|
const safeLeft = () => { const px = parseFloat(globalThis.getComputedStyle?.(document.body)?.paddingLeft); return Number.isFinite(px) ? px : 0; };
|
|
170
195
|
|
|
171
196
|
function hide() {
|
|
197
|
+
settle();
|
|
172
198
|
current = null;
|
|
173
199
|
layer++;
|
|
174
200
|
collapse();
|
|
@@ -179,9 +205,12 @@ export function mountMenu(el, sub = null, { flyout = false } = {}) {
|
|
|
179
205
|
|
|
180
206
|
// 两个面板都算菜单里面。菜单开着时点菜单外:只关菜单,紧接着的那次点击不交给页面。
|
|
181
207
|
const inside = target => el.contains(target) || (sub !== null && sub.contains(target));
|
|
208
|
+
// 关菜单的那一下按下标成「已消费」:按下反馈和 Mac 的按下即选中都先看它(consumed),消费过的不加反馈、不选中。
|
|
182
209
|
let dismissed = false;
|
|
210
|
+
const eaten = new WeakSet();
|
|
183
211
|
document.addEventListener('pointerdown', event => {
|
|
184
212
|
dismissed = !el.hidden && !inside(event.target);
|
|
213
|
+
if (dismissed) eaten.add(event);
|
|
185
214
|
if (!inside(event.target)) hide();
|
|
186
215
|
}, true);
|
|
187
216
|
document.addEventListener('click', event => {
|
|
@@ -195,6 +224,7 @@ export function mountMenu(el, sub = null, { flyout = false } = {}) {
|
|
|
195
224
|
return {
|
|
196
225
|
open, hide,
|
|
197
226
|
get hidden() { return el.hidden; },
|
|
227
|
+
consumed: event => eaten.has(event),
|
|
198
228
|
// 谁打开的菜单:同一个按钮再次激活就关闭(键盘激活没有 pointerdown,上面那条规则管不到)。
|
|
199
229
|
get opener() { return opener; },
|
|
200
230
|
};
|
package/view/press.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// 按下反馈:页面里只有一份按下状态,两端共用(设计见 docs/design/phase-3.md 第 17.3 节)。
|
|
2
|
+
// 不靠 :active(WebKit 对滚动区域里的触摸会延迟它):文档上监听 pointerdown,给最近的可按元素加 .pressed,样子在 style.css。
|
|
3
|
+
// 虚拟列表重画会换掉节点,所以列表的行由 tree.mjs、grid.mjs 画行时问 paint() 是不是正在按下的那一行。
|
|
4
|
+
import { HOLD_SLOP } from './gestures.mjs';
|
|
5
|
+
|
|
6
|
+
export const SHOW_MS = 80; // 触摸按下后这么久没移动、没取消才亮:一滑动就闪不好看
|
|
7
|
+
export const MIN_MS = 100; // 正常抬起:从亮起算至少显示这么久
|
|
8
|
+
export const FADE_MS = 200; // iPhone 正常抬起后的淡出(样式在 style.css 的 .fade)
|
|
9
|
+
|
|
10
|
+
const QUERY = '(prefers-reduced-motion: reduce)';
|
|
11
|
+
// 系统「减弱动态效果」:按下的淡出、菜单、层级过渡、目录淡入都按它统一判断。读不到按「减弱」算,宁可不动。
|
|
12
|
+
export const reducedMotion = () => { const query = globalThis.matchMedia?.(QUERY); return !query || query.matches; };
|
|
13
|
+
// 设置在动画进行中变了:调用 fn,让正在播的动画结束到终点。
|
|
14
|
+
export const onMotionChange = fn => globalThis.matchMedia?.(QUERY)?.addEventListener?.('change', fn);
|
|
15
|
+
|
|
16
|
+
// 点到的可按元素:{ node, key }。key 是列表里一行的身份(视图、种类、路径),按钮没有(按节点记)。
|
|
17
|
+
// 可按:没有 disabled 的 button、.row.entry、.row.more、.row.retry、.cell、.gnote.more、.gnote.retry;.dead 的条目也算(它们能选中、能右键)。
|
|
18
|
+
function targetOf(event) {
|
|
19
|
+
const node = event.target?.closest?.('.row, .cell, .gnote, button');
|
|
20
|
+
if (!node) return null;
|
|
21
|
+
if (node.tagName === 'BUTTON') return node.disabled || node.getAttribute('disabled') !== null ? null : { node, key: null };
|
|
22
|
+
const has = name => node.classList.contains(name), path = node.dataset.path;
|
|
23
|
+
const kind = has('cell') || has('entry') ? 'entry' : has('retry') ? 'retry' : has('more') ? 'more' : null;
|
|
24
|
+
return kind === null || path === undefined ? null : { node, key: `${has('row') ? 'tree' : 'grid'}\n${kind}\n${path}` };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// identity():会话和根目录的身份(model.session、model.scope 拼成的字符串);换了就不是同一个按下。
|
|
28
|
+
// consumed(event):这次 pointerdown 已经被别人用掉了(菜单开着时点外面只关菜单):不加反馈。
|
|
29
|
+
export function mountPress({ identity = () => '', consumed = () => false, doc = document } = {}) {
|
|
30
|
+
let state = null; // { id, x, y, key, base, node, shown, released, minDone, timers }
|
|
31
|
+
const tagged = new Set(); // 加过 .pressed 的节点:去掉时一并清掉,不靠记住的旧节点
|
|
32
|
+
const fading = new Map(); // 正在淡出的节点 → 它的定时器
|
|
33
|
+
|
|
34
|
+
const unfade = () => { for (const [node, timer] of fading) { clearTimeout(timer); node.classList.remove('fade'); } fading.clear(); };
|
|
35
|
+
const strip = () => { for (const node of tagged) node.classList.remove('pressed'); tagged.clear(); };
|
|
36
|
+
const tag = node => { node.classList.add('pressed'); tagged.add(node); };
|
|
37
|
+
const stop = () => { if (state) { clearTimeout(state.showTimer); clearTimeout(state.minTimer); } };
|
|
38
|
+
|
|
39
|
+
// 作废:立即去掉,不淡出,不受最短时间限制;还没亮的之后也不会补亮。
|
|
40
|
+
function clear() {
|
|
41
|
+
stop();
|
|
42
|
+
state = null;
|
|
43
|
+
strip();
|
|
44
|
+
unfade();
|
|
45
|
+
}
|
|
46
|
+
// 正常结束:iPhone 淡出(减弱动态效果时不淡)。
|
|
47
|
+
function finish() {
|
|
48
|
+
stop();
|
|
49
|
+
state = null;
|
|
50
|
+
const nodes = [...tagged];
|
|
51
|
+
strip();
|
|
52
|
+
if (reducedMotion()) return;
|
|
53
|
+
for (const node of nodes) {
|
|
54
|
+
node.classList.add('fade');
|
|
55
|
+
fading.set(node, setTimeout(() => { node.classList.remove('fade'); fading.delete(node); }, FADE_MS));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function show() {
|
|
59
|
+
const mine = state;
|
|
60
|
+
mine.shown = true;
|
|
61
|
+
tag(mine.node);
|
|
62
|
+
mine.minTimer = setTimeout(() => { mine.minDone = true; if (mine.released && state === mine) finish(); }, MIN_MS);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const on = (type, fn, target = doc, capture = true) => { target.addEventListener(type, fn, capture); return () => target.removeEventListener(type, fn, capture); };
|
|
66
|
+
onMotionChange(unfade); // 设置在淡出进行中变成减弱:淡出结束到终点;仍按着的反馈保留
|
|
67
|
+
const offs = [
|
|
68
|
+
on('pointerdown', event => {
|
|
69
|
+
if (event.isPrimary === false) return clear(); // 第二根手指
|
|
70
|
+
clear();
|
|
71
|
+
if (consumed(event) || (event.pointerType === 'mouse' || event.pointerType === undefined) && (event.button > 0 || event.ctrlKey)) return; // 右键、Control 左键是菜单
|
|
72
|
+
const target = targetOf(event);
|
|
73
|
+
if (!target) return;
|
|
74
|
+
state = { id: event.pointerId, x: event.clientX, y: event.clientY, key: target.key, base: identity(), node: target.node, shown: false, released: false, minDone: false };
|
|
75
|
+
if (event.pointerType === 'touch') {
|
|
76
|
+
const mine = state;
|
|
77
|
+
state.showTimer = setTimeout(() => { if (state === mine) show(); }, SHOW_MS);
|
|
78
|
+
} else show();
|
|
79
|
+
}),
|
|
80
|
+
on('pointermove', event => {
|
|
81
|
+
if (state && event.pointerId === state.id && Math.hypot(event.clientX - state.x, event.clientY - state.y) > HOLD_SLOP) clear();
|
|
82
|
+
}),
|
|
83
|
+
on('pointerup', event => {
|
|
84
|
+
if (!state || event.pointerId !== state.id) return;
|
|
85
|
+
if (!state.shown) { clearTimeout(state.showTimer); show(); } // 快点一下:在抬起时补上
|
|
86
|
+
state.released = true;
|
|
87
|
+
if (state.minDone) finish();
|
|
88
|
+
}),
|
|
89
|
+
on('pointercancel', clear),
|
|
90
|
+
on('scroll', clear), // 滚动事件不冒泡,捕获才收得到
|
|
91
|
+
on('dragstart', clear),
|
|
92
|
+
on('contextmenu', clear),
|
|
93
|
+
on('blur', clear, globalThis.window ?? doc, false), // 窗口失焦。不能用捕获:元素失焦(点按钮时焦点从目录树移走)的 blur 也会经过 window 的捕获阶段
|
|
94
|
+
on('visibilitychange', () => { if (doc.hidden) clear(); }),
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
// 画行时问:这一行是不是正在按下的(会话和根目录、视图、种类、路径都对得上),是就带上 .pressed。
|
|
99
|
+
paint(node, view, kind, path) {
|
|
100
|
+
if (!state || state.key !== `${view}\n${kind}\n${path}` || state.base !== identity()) return;
|
|
101
|
+
state.node = node; // 还没亮(触摸等待期间)重画了:show() 要给新节点加,旧节点已经脱离
|
|
102
|
+
if (state.shown) tag(node);
|
|
103
|
+
},
|
|
104
|
+
// 正在亮着的:{ key },没有就是 null。测试用。
|
|
105
|
+
current: () => (state?.shown ? { key: state.key } : null),
|
|
106
|
+
reset: clear,
|
|
107
|
+
dispose() { clear(); for (const off of offs.splice(0)) off(); },
|
|
108
|
+
};
|
|
109
|
+
}
|
package/view/preview.mjs
CHANGED
|
@@ -73,6 +73,7 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
|
|
|
73
73
|
...(copyInHead ? [action('复制路径', 'copy', copyPath)] : []), ...extra), body);
|
|
74
74
|
|
|
75
75
|
let path = null, token = 0, shown = null, objectUrl = null; // shown:当前显示的 { size, mtimeMs }
|
|
76
|
+
let opens = 0, stoppedAt = -1; // 打开次数和上一次停止时的次数:释放只在停止之后没有再打开过时才做(返回的退场还没结束又打开了)
|
|
76
77
|
let carry = null; // 待恢复的位置 { scroll, settle }:open 带进来,读取真正用上或作废后才清
|
|
77
78
|
const settle = used => { const c = carry; carry = null; c?.settle(used); };
|
|
78
79
|
let metaText = ' ', metaTitle = '', stale = null; // stale:后台刷新失败的原因,此时正文还是上次的
|
|
@@ -157,6 +158,7 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
|
|
|
157
158
|
return {
|
|
158
159
|
open(next, scroll = null) {
|
|
159
160
|
settle(false);
|
|
161
|
+
opens++;
|
|
160
162
|
path = next;
|
|
161
163
|
const base = next.split('/').pop();
|
|
162
164
|
name.textContent = base;
|
|
@@ -170,8 +172,19 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
|
|
|
170
172
|
refresh() { return path === null ? undefined : load(true); },
|
|
171
173
|
// 内容的来源变了(根目录换了位置):旧正文不能留,也不能按元数据判断「没变」。
|
|
172
174
|
reload() { return path === null ? undefined : load(false); },
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
// 停止(逻辑关闭,立即):不再读、不再刷新,待恢复的位置结算;画面(正文、图片的 URL)留着,由 release 在退场结束时清掉。
|
|
176
|
+
stop() { settle(false); token++; path = null; shown = null; stoppedAt = opens; },
|
|
177
|
+
// 释放(画面):停止之后又打开过就什么都不做。
|
|
178
|
+
release() {
|
|
179
|
+
if (stoppedAt !== opens) return; // 停止之后又打开过(打开次数变了):这一屏是新的,不是退场的旧页
|
|
180
|
+
setMeta(' ');
|
|
181
|
+
revoke();
|
|
182
|
+
body.replaceChildren();
|
|
183
|
+
},
|
|
184
|
+
// 停止并立即释放:换会话、换根目录、Mac,以及没有过渡的所有关闭。
|
|
185
|
+
close() { this.stop(); this.release(); },
|
|
186
|
+
// 已停止的预览没有位置:保存状态时按 0 算,同关闭后清空正文的结果。
|
|
187
|
+
scroll: () => (path === null ? { top: 0, left: 0 } : { top: body.scrollTop, left: body.scrollLeft }),
|
|
175
188
|
onScroll: fn => body.addEventListener('scroll', fn, { passive: true }),
|
|
176
189
|
get path() { return path; },
|
|
177
190
|
};
|
package/view/style.css
CHANGED
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
--tone-gray: #a3a3a9; --tone-blue: #6aa9ec; --tone-yellow: #e3b63e; --tone-green: #63c77f; --tone-teal: #58c3dd;
|
|
24
24
|
--tone-orange: #f0964f; --tone-red: #f0717a; --tone-purple: #ac87ec; --tone-pink: #ee77ac;
|
|
25
25
|
}
|
|
26
|
+
/* 菜单的阴影(第 9 节第 1 条的第三个例外):主题变量里没有阴影,深浅各一套,深色更重才看得出。 */
|
|
27
|
+
:root { --shadow-menu: 0 6px 20px rgba(0,0,0,.18), 0 1px 3px rgba(0,0,0,.12); }
|
|
28
|
+
:root.coda-dark { --shadow-menu: 0 8px 24px rgba(0,0,0,.55), 0 1px 3px rgba(0,0,0,.4); }
|
|
26
29
|
/* 代码高亮的颜色,深浅各一套;自己定的,不照搬任何现成主题。每个 token 的最终颜色在代码区底色上不低于 4.5:1(harness 读真实计算值检查);改色值要重新跑。 */
|
|
27
30
|
:root {
|
|
28
31
|
--hl-keyword: #a2218f; --hl-string: #b82a1f; --hl-comment: #5f6b76; --hl-number: #2d3fc4; --hl-title: #0b62a0; --hl-type: #1b7280; --hl-attr: #7a5200;
|
|
@@ -38,12 +41,12 @@
|
|
|
38
41
|
.tone-red { color: var(--tone-red); } .tone-purple { color: var(--tone-purple); } .tone-pink { color: var(--tone-pink); }
|
|
39
42
|
* { box-sizing: border-box; }
|
|
40
43
|
html, body { margin: 0; height: 100%; }
|
|
41
|
-
body { display: flex; flex-direction: column; overflow: hidden; -webkit-user-select: none; user-select: none;
|
|
44
|
+
body { display: flex; flex-direction: column; overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; /* 系统默认的点击闪烁是不带圆角的灰块:按下反馈归 .pressed */
|
|
42
45
|
padding: var(--safe-top) var(--safe-right) 0 var(--safe-left); }
|
|
43
46
|
.selectable { -webkit-user-select: text; user-select: text; }
|
|
44
|
-
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-align: inherit; cursor:
|
|
47
|
+
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-align: inherit; cursor: default; } /* 原生 Mac 应用的按钮是箭头 */
|
|
45
48
|
button:focus-visible { outline: 2px solid var(--coda-accent, #0a84ff); outline-offset: 2px; border-radius: 6px; }
|
|
46
|
-
button.link { color: var(--coda-accent, #0a84ff); }
|
|
49
|
+
button.link { color: var(--coda-accent, #0a84ff); border-radius: var(--coda-radius, 6px); }
|
|
47
50
|
p { margin: 0; }
|
|
48
51
|
.secondary { color: var(--coda-secondary, #6e6e73); }
|
|
49
52
|
.caption { font-size: .85em; }
|
|
@@ -52,9 +55,16 @@ p { margin: 0; }
|
|
|
52
55
|
[hidden] { display: none !important; }
|
|
53
56
|
|
|
54
57
|
/* 面板(目录树、图标、预览、说明、属性页)叠在同一处,只切可见性:隐藏的树保留滚动位置,切换不改变布局。 */
|
|
55
|
-
#stage { position: relative; flex: 1 1 auto; min-height: 0; }
|
|
58
|
+
#stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; } /* 裁掉层级过渡时横向溢出的那一层;菜单、提示是它的兄弟节点,不受裁切 */
|
|
56
59
|
.pane { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; padding-bottom: var(--safe-bottom); }
|
|
57
60
|
.pane.off { visibility: hidden; pointer-events: none; }
|
|
61
|
+
/* iPhone 层级切换(第 17.6 节):深的一层(预览、属性页)永远在上,打开时它滑入盖住浅层,返回时它滑出露出浅层。
|
|
62
|
+
.layer 只在过渡期间加:两层都要不透明,否则透出对面;.leaving 是离开的那一层,不接指针,点在它上面等于点在下面的目标页。 */
|
|
63
|
+
#preview, #info { z-index: 1; }
|
|
64
|
+
.pane.layer { background: var(--coda-background, #fff); }
|
|
65
|
+
.pane.leaving { pointer-events: none; }
|
|
66
|
+
/* 滑动期间(约 280 毫秒)整页不响应点按;app.mjs 在过渡开始和结束(含强制结束)时加上和去掉。 */
|
|
67
|
+
html.moving, html.moving body, html.moving #stage { pointer-events: none; }
|
|
58
68
|
.empty { display: grid; align-content: start; justify-items: center; gap: 6px; padding: 32px 20px; text-align: center; }
|
|
59
69
|
.notice-icon { display: grid; place-items: center; margin-bottom: 6px; color: var(--coda-secondary, #6e6e73); }
|
|
60
70
|
.notice-icon svg { display: block; color: inherit; } /* 说明区的图标不上色 */
|
|
@@ -139,7 +149,7 @@ button.icon svg { display: block; }
|
|
|
139
149
|
/* 键盘焦点:选中的高亮已经表示位置,点击时不画外框;只在键盘操作(:focus-visible)时给容器内边一圈细线。 */
|
|
140
150
|
#tree:focus, .gbody:focus { outline: none; }
|
|
141
151
|
#tree:focus-visible, .gbody:focus-visible { outline: 1px solid var(--coda-accent, #0a84ff); outline-offset: -2px; }
|
|
142
|
-
.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);
|
|
152
|
+
.menu { position: fixed; z-index: 10; box-shadow: var(--shadow-menu); 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);
|
|
143
153
|
background: var(--coda-card, var(--coda-background, #fff));
|
|
144
154
|
/* 高度有上限:内容多(长路径加五项)时在菜单里滚动,不超出安全区;位置由 menu.mjs 夹在安全区内。 */
|
|
145
155
|
max-height: calc(100vh - var(--safe-top) - var(--safe-bottom) - 8px); overflow-y: auto; overscroll-behavior: contain; }
|
|
@@ -194,7 +204,6 @@ button.icon svg { display: block; }
|
|
|
194
204
|
.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); }
|
|
195
205
|
.gnote.more, .gnote.retry { color: var(--coda-accent, #0a84ff); cursor: pointer; }
|
|
196
206
|
.coda-ios .cell { -webkit-touch-callout: none; } /* 长按由页面接管,不弹系统菜单 */
|
|
197
|
-
.coda-ios .cell:active { background: var(--hover); } /* 按下:和列表的行一样 */
|
|
198
207
|
|
|
199
208
|
/* 悬停只在有鼠标时:触摸后不会留着。 */
|
|
200
209
|
@media (hover: hover) {
|
|
@@ -204,6 +213,15 @@ button.icon svg { display: block; }
|
|
|
204
213
|
.menu button:hover { background: var(--coda-selection, var(--hover)); }
|
|
205
214
|
}
|
|
206
215
|
|
|
216
|
+
/* 按下(press.mjs 加 .pressed,第 17.3 节):只改底色,不改尺寸和文字色。最终的颜色是原底色上再叠一层 --hover:
|
|
217
|
+
普通的行和按钮是两层 --hover,选中的是 --coda-selection 加一层 --hover。第二层用内阴影而不是 background-image,淡出时两层都能过渡。
|
|
218
|
+
放在悬停之后、选择器的优先级不低于悬停:按在悬停着的元素上也是这个颜色。 */
|
|
219
|
+
.row.entry.pressed, .row.more.pressed, .row.retry.pressed, .cell.pressed, .gnote.pressed, button.pressed, .bar button.pressed, button.icon.pressed {
|
|
220
|
+
background-color: var(--hover); box-shadow: inset 0 0 0 100vmax var(--hover); }
|
|
221
|
+
.row.entry.sel.pressed, .cell.sel.pressed, .menu button.pressed { background-color: var(--coda-selection, var(--hover)); }
|
|
222
|
+
/* iPhone 正常抬起时约 200 毫秒淡出(.fade 由 press.mjs 在去掉 .pressed 的同时加上,减弱动态效果时不加);Mac 立刻去掉。 */
|
|
223
|
+
.coda-ios .fade { transition: background-color .2s ease-out, box-shadow .2s ease-out; }
|
|
224
|
+
|
|
207
225
|
/* iPhone:行和按钮至少 44 点;行高 58 点(两行:名字、日期 · 大小)在这里定,tree.mjs 量 .row 得到,不另写一份。
|
|
208
226
|
目录树是 Coda 卡片外形的分组列表:.spacer 就是卡片(高度已等于全部行高),首尾圆角不用逐行判断。 */
|
|
209
227
|
.coda-ios { --row-h: 58px; --indent: 20px; --pad: 16px; }
|
|
@@ -216,7 +234,6 @@ button.icon svg { display: block; }
|
|
|
216
234
|
left: calc(var(--pad) + var(--indent) * var(--d, 0) + 22px + 8px); } /* 从图标之后开始 */
|
|
217
235
|
.coda-ios .row.sel + .row::before, .coda-ios .row.sel::before { background: transparent; }
|
|
218
236
|
.coda-ios .row { -webkit-touch-callout: none; } /* 长按由页面接管,不弹系统菜单;选择和拖动另外已关 */
|
|
219
|
-
.coda-ios .row.entry:active { background: var(--hover); }
|
|
220
237
|
.coda-ios .ico svg { width: 22px; height: 22px; }
|
|
221
238
|
.coda-ios .main { display: flex; flex-direction: column; justify-content: center; } /* 没有第二行的条目,名字垂直居中 */
|
|
222
239
|
.coda-ios .sub { display: block; }
|
|
@@ -234,7 +251,6 @@ button.icon svg { display: block; }
|
|
|
234
251
|
.coda-ios .preview:not(.info) .pbody { padding-bottom: var(--safe-bottom); } /* 资源页里没有底部工具条:最后一行不被 Home 指示条盖住 */
|
|
235
252
|
.coda-ios .code { font-size: .8em; } /* 窄屏多看些:17 点下约 13.6 点 */
|
|
236
253
|
.coda-ios .menu button { padding: 0 10px; }
|
|
237
|
-
.coda-ios .menu button:active { background: var(--coda-selection, var(--hover)); }
|
|
238
254
|
.coda-ios .menu-head { padding: 6px 10px 2px; }
|
|
239
255
|
|
|
240
256
|
/* 横屏:客户端隐藏导航栏,页面自己给返回。近似 verticalSizeClass 的判断,不等价(iPad、Duo 不单独适配)。 */
|
package/view/tree.mjs
CHANGED
|
@@ -66,7 +66,8 @@ export const TITLES = { [EntryKind.LINK]: '指向工作目录外的链接,不
|
|
|
66
66
|
// draggable:触屏上拖行没有用处,还会抢滚动,关掉。now:当前时间,日期的相对格式用,测试可注入。
|
|
67
67
|
// longPress:触屏上按住一行打开 handlers.menu(Mac 用右键)。不设 touch-action,滚动照旧,滚动接管时收到 pointercancel 作废。
|
|
68
68
|
// keyboard:滚动容器可以获得焦点,键盘才接得上(Mac)。
|
|
69
|
-
|
|
69
|
+
// press:按下反馈(press.mjs),画行时问它这一行是不是正在按下的;consumed(event):菜单消费掉的按下(gestures.mjs)。
|
|
70
|
+
export function mountTree(el, model, handlers, { draggable = true, longPress = false, keyboard = false, now = Date.now, press = null, consumed = () => false } = {}) {
|
|
70
71
|
const title = document.createElement('div'), spacer = document.createElement('div'), win = document.createElement('div');
|
|
71
72
|
title.className = 'section truncate'; spacer.className = 'spacer'; win.className = 'win';
|
|
72
73
|
title.hidden = true;
|
|
@@ -107,11 +108,14 @@ export function mountTree(el, model, handlers, { draggable = true, longPress = f
|
|
|
107
108
|
node.className = `row ${row.type}`;
|
|
108
109
|
node.dataset.i = index;
|
|
109
110
|
node.style.cssText = `--d: ${row.depth}`; // 缩进由 CSS 按 --d 算,分隔线的起点也用它
|
|
111
|
+
node.dataset.path = row.path; // 按下反馈认的身份:同一路径的条目、「重试」说明行、「再显示」靠种类区分
|
|
110
112
|
if (row.type !== 'entry') {
|
|
111
113
|
node.textContent = row.text;
|
|
112
114
|
if (row.retry) { node.classList.add('retry'); node.title = row.text; } // 长原因在行里被截断,Mac 悬停看全
|
|
115
|
+
if (row.retry || row.type === 'more') press?.paint(node, 'tree', row.retry ? 'retry' : 'more', row.path);
|
|
113
116
|
return node;
|
|
114
117
|
}
|
|
118
|
+
press?.paint(node, 'tree', 'entry', row.path);
|
|
115
119
|
const dead = row.kind === EntryKind.LINK || row.kind === EntryKind.OTHER;
|
|
116
120
|
node.classList.add(row.kind);
|
|
117
121
|
if (dead) node.classList.add('dead');
|
|
@@ -172,6 +176,7 @@ export function mountTree(el, model, handlers, { draggable = true, longPress = f
|
|
|
172
176
|
menu: (event, row) => handlers.menu(event, row),
|
|
173
177
|
dragText: row => row.path,
|
|
174
178
|
longPress,
|
|
179
|
+
consumed,
|
|
175
180
|
});
|
|
176
181
|
// 选中变了只在现有节点上切 .sel,不重建:双击的 dblclick 要落在还在容器里的节点上。
|
|
177
182
|
const mark = () => { for (const node of win.children) node.classList.toggle('sel', rows[node.dataset.i]?.path === model.selected && rows[node.dataset.i]?.type === 'entry'); };
|