@coda-console/resource-manager 0.7.0 → 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 +5 -4
- package/package.json +1 -1
- package/view/app.mjs +180 -63
- package/view/file-app.mjs +14 -13
- package/view/file.html +1 -1
- 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/model.mjs +1 -1
- package/view/press.mjs +109 -0
- package/view/preview.mjs +35 -13
- package/view/style.css +27 -13
- package/view/tree.mjs +6 -1
package/README.md
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
Coda 插件:会话旁的文件浏览器。浏览这个会话的工作目录,读文本和图片,把路径交给对话。只读。
|
|
4
4
|
|
|
5
5
|
- **Mac**:在会话侧栏里,和对话并排。
|
|
6
|
-
- **iPhone
|
|
6
|
+
- **iPhone**:在会话右上角菜单里打开,点文件在资源页里切到预览,系统返回(左上「‹」、左边缘侧滑)回到打开它的那一层。iPad 和 iPhone Duo 用同一套界面,没有单独适配。
|
|
7
7
|
|
|
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)。
|
|
@@ -22,7 +23,7 @@ Coda 插件:会话旁的文件浏览器。浏览这个会话的工作目录,
|
|
|
22
23
|
- 属性页:行菜单里选「属性」,在当前页里打开一层,用系统的返回退出。显示种类、大小、链接到、位置、完整路径、修改和创建时间、权限;文件夹的大小在打开后统计,不跟随链接,最多 20 万项或 5 秒,超出时显示下限(如「超过 3.2 GiB(已统计 20 万项)」),一轮结束后已有的结果标「上次统计」,可以重新统计。
|
|
23
24
|
- **写入输入框用的是 Coda 没有公开的接口**,以后可能失效或改变;失效时「添加到聊天」会改为复制路径或文字。**已知风险**:输入框里的附件还在上传时添加,上传完成后,这段时间里打的字和那个附件可能消失;刚打完字的一瞬间添加,也可能丢掉这几个字。
|
|
24
25
|
- Mac:把文件拖到输入框也行;预览可以开到独立窗口;工具栏只有一个「更多」按钮,按下弹出菜单:刷新、显示隐藏文件、「显示」›。鼠标移到「显示」或点它,在菜单左边弹出二级菜单(视图和排序);侧栏太窄放不下时,在菜单里切到下一层,顶上一行「返回」。侧栏预览头部最左边的「返回」回到目录树或图标视图。
|
|
25
|
-
- iPhone
|
|
26
|
+
- iPhone:长按出同样的菜单;目录树页(或图标视图)右上角「⋯」里有刷新、显示隐藏文件和「显示」,点「显示」在菜单里切到下一层(视图和排序),顶上一行「返回」;预览时只有一行标题(预览头部),「⋯」在头部右边,里面只有刷新和「复制路径」。
|
|
26
27
|
- 默认隐藏 `.git`、`.DS_Store`,Mac 在工具栏的「更多」菜单里、iPhone 在目录树页右上角的「⋯」里可切换显示全部。
|
|
27
28
|
|
|
28
29
|
只能读这个会话的工作目录。指向工作目录之外的符号链接只显示,不能打开。
|
|
@@ -46,7 +47,7 @@ Coda 插件:会话旁的文件浏览器。浏览这个会话的工作目录,
|
|
|
46
47
|
# 不进 Coda,用假的 window.coda 在浏览器里看真实页面
|
|
47
48
|
"$CODA_NODE" test/harness/server.mjs <会话A的目录> [会话B的目录] [端口]
|
|
48
49
|
|
|
49
|
-
# 真实布局的断言和截图:无头 Chrome 打开 Mac 侧栏、iPhone
|
|
50
|
+
# 真实布局的断言和截图:无头 Chrome 打开 Mac 侧栏、iPhone 竖屏和横屏的目录树、图标视图与资源页里的预览(浅色、深色),
|
|
50
51
|
# 量行高、工具条、菜单和二级菜单的位置和尺寸,图标视图的单元格和滚动。自己起服务和临时目录,用完删掉;截图在系统临时目录里,路径在最后打印。
|
|
51
52
|
# 失败时退出码非 0。Chrome 不在默认位置时把路径作参数传入
|
|
52
53
|
"$CODA_NODE" test/harness/layout.mjs [Chrome 的路径]
|
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';
|
|
@@ -19,13 +20,12 @@ const coda = window.coda;
|
|
|
19
20
|
const $ = id => document.getElementById(id);
|
|
20
21
|
const quiet = fn => { try { return fn(); } catch { return undefined; } };
|
|
21
22
|
const hasToolbar = typeof coda.toolbar === 'function' && coda.platform === 'mac';
|
|
22
|
-
// iPhone
|
|
23
|
-
// Mac 照 Finder:单击选中、双击打开,键盘接在目录树和图标视图的滚动容器上。
|
|
23
|
+
// 两端都在资源页里打开文件、切到预览(第 16 节):iPhone 轻点打开、系统返回关掉,Mac 照 Finder 单击选中、双击打开,键盘接在目录树和图标视图的滚动容器上。
|
|
24
24
|
const isIOS = coda.platform === 'ios';
|
|
25
25
|
|
|
26
26
|
let persisted = parseState(quiet(() => coda.getState()));
|
|
27
|
-
//
|
|
28
|
-
let pending = { preview: null };
|
|
27
|
+
// 恢复出来的预览滚动位置,等内容到了再用一次;path 是它属于的文件,opened 不是它了就作废。目录树和图标视图的在 restore 里。
|
|
28
|
+
let pending = { preview: null, path: null };
|
|
29
29
|
|
|
30
30
|
const conn = connect(coda, { handlers: { session: onSession, root: onRoot, changed: onChanged }, onStatus: () => schedule() });
|
|
31
31
|
const model = new Model({ link: conn.link, onChange: () => schedule(), onLost: () => hint.show('文件夹已不存在', { warn: false }) });
|
|
@@ -33,7 +33,9 @@ model.showHidden = persisted.hidden;
|
|
|
33
33
|
model.sort = persisted.sort;
|
|
34
34
|
model.view = persisted.view;
|
|
35
35
|
const hint = mountHint($('hint'));
|
|
36
|
-
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 });
|
|
37
39
|
const chat = createChat({ link: conn.link, copy: text => coda.copy(text), hint });
|
|
38
40
|
// 属性页和图标视图的上一层:iPhone 用原生返回(coda.back);Mac 的客户端会替声明了返回的页面画一个带小箭头的导航,
|
|
39
41
|
// 和侧栏标题重复,所以 Mac 和没有 coda.back 的环境一样,头部最左边自己放返回。
|
|
@@ -44,8 +46,8 @@ const tree = mountTree($('tree'), model, {
|
|
|
44
46
|
more: path => model.loadMore(path),
|
|
45
47
|
retry: path => model.retry(path),
|
|
46
48
|
menu: (event, row) => pathMenu(event, row),
|
|
47
|
-
select: isIOS ? null : path =>
|
|
48
|
-
}, { draggable: !isIOS, longPress: isIOS, keyboard: !isIOS });
|
|
49
|
+
select: isIOS ? null : path => mouseSelect(path),
|
|
50
|
+
}, { draggable: !isIOS, longPress: isIOS, keyboard: !isIOS, press, consumed: menu.consumed });
|
|
49
51
|
const grid = mountGrid($('grid'), model, {
|
|
50
52
|
open: openFile,
|
|
51
53
|
enter: path => enterDir(path),
|
|
@@ -53,13 +55,14 @@ const grid = mountGrid($('grid'), model, {
|
|
|
53
55
|
retry: path => model.retry(path),
|
|
54
56
|
menu: (event, cell) => pathMenu(event, cell),
|
|
55
57
|
back: nativeBack ? null : () => leaveDir(),
|
|
56
|
-
select: isIOS ? null : path =>
|
|
57
|
-
}, { draggable: !isIOS, longPress: isIOS, keyboard: !isIOS });
|
|
58
|
+
select: isIOS ? null : path => mouseSelect(path),
|
|
59
|
+
}, { draggable: !isIOS, longPress: isIOS, keyboard: !isIOS, press, consumed: menu.consumed });
|
|
58
60
|
const restore = createRestore(model, { tree, grid });
|
|
59
61
|
const trail = createTrail();
|
|
60
62
|
const preview = mountPreview($('preview'), {
|
|
61
63
|
read: (path, offset) => conn.link.call('read', { path, offset }), copy: text => coda.copy(text),
|
|
62
|
-
|
|
64
|
+
// iPhone 预览头部右边的 ⋯(刷新、复制路径):顶部工具条在预览时只有「返回」,只留头部一行标题
|
|
65
|
+
actions: isIOS ? [{ label: '更多', icon: 'ellipsis', run: (_, button) => toggleMore(button) }] : [{ label: '窗口', icon: 'window', run: openInView }], copyInHead: !isIOS,
|
|
63
66
|
back: isIOS ? null : closePreview,
|
|
64
67
|
// 选中文字的右键菜单只有 Mac:iPhone 用系统的选区菜单。
|
|
65
68
|
selectionMenu: isIOS ? null : (event, selection) => menu.open(event, { items: chat.selectionItems(selection) }),
|
|
@@ -75,35 +78,23 @@ const info = mountInfo($('info'), {
|
|
|
75
78
|
back: nativeBack ? null : () => { backPressed = true; closeInfo(); },
|
|
76
79
|
});
|
|
77
80
|
|
|
78
|
-
// ---- 在独立视图里打开:
|
|
81
|
+
// ---- 在独立视图里打开:Mac 预览头部的「窗口」 ----
|
|
79
82
|
// 会话 ID 放进 args:被打开的视图 context.session 是 null。失败(含同步抛出)在原地提示。
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
let opening = false, unlockTimer = null, epoch = 0;
|
|
83
|
-
const REOPEN_MS = 1000;
|
|
83
|
+
// epoch 每换一次会话加一:旧会话的 open 结果回来时已经作废,不碰新会话的提示。
|
|
84
|
+
let epoch = 0;
|
|
84
85
|
function openInView(path) {
|
|
85
|
-
if (isIOS) opening = true;
|
|
86
86
|
const mine = epoch;
|
|
87
87
|
return Promise.resolve().then(() => coda.open({ view: 'file', args: { session: model.session, path } }))
|
|
88
|
-
.then(() => {
|
|
89
|
-
if (mine
|
|
90
|
-
hint.hide();
|
|
91
|
-
if (isIOS) { clearTimeout(unlockTimer); unlockTimer = setTimeout(() => { opening = false; }, REOPEN_MS); }
|
|
92
|
-
}, error => {
|
|
93
|
-
if (mine !== epoch) return;
|
|
94
|
-
opening = false;
|
|
95
|
-
hint.show(`打不开文件:${error?.message ?? '未知原因'}`);
|
|
88
|
+
.then(() => { if (mine === epoch) hint.hide(); }, error => {
|
|
89
|
+
if (mine === epoch) hint.show(`打不开文件:${error?.message ?? '未知原因'}`);
|
|
96
90
|
});
|
|
97
91
|
}
|
|
92
|
+
// 两端都在页内打开:model.openFile 设 selected 和 opened,经 onChange 切到预览。iPhone 触屏没有键盘焦点,不交焦点;
|
|
93
|
+
// 快速两次轻点:第一次已切到预览,目录树 .off 不接指针事件,第二次落不到条目上。
|
|
98
94
|
function openFile(path) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return model.openFile(path);
|
|
103
|
-
}
|
|
104
|
-
selectEntry(path);
|
|
105
|
-
saveNow(); // 视图随即卸载,这一刻的展开状态、条数和滚动位置先存下
|
|
106
|
-
openInView(path);
|
|
95
|
+
openPressed = !isIOS; // 用户在 Mac 上打开的:render 把焦点交给预览面板
|
|
96
|
+
note({ kind: 'push', from: mode(), to: 'preview' });
|
|
97
|
+
model.openFile(path);
|
|
107
98
|
}
|
|
108
99
|
|
|
109
100
|
// ---- 渲染:同一批变化合并成一次 ----
|
|
@@ -122,6 +113,11 @@ function selectEntry(path) {
|
|
|
122
113
|
queueSave();
|
|
123
114
|
}
|
|
124
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
|
+
}
|
|
125
121
|
|
|
126
122
|
// 预览头部的返回和预览里的 ⌘↑ 是同一个动作:opened 清掉,selected 留着。
|
|
127
123
|
function closePreview() {
|
|
@@ -131,7 +127,7 @@ function closePreview() {
|
|
|
131
127
|
// 用户点了预览头部的返回:render 据此决定焦点要不要交给浏览区,别的模式变化不动焦点。
|
|
132
128
|
let backPressed = false;
|
|
133
129
|
let openPressed = false; // 用户打开了文件:同返回对称,页面持有焦点时 render 把焦点交给预览面板
|
|
134
|
-
const mode = () => (infoOpen ? 'info' : !model.ready ? 'notice' : model.opened !== null
|
|
130
|
+
const mode = () => (infoOpen ? 'info' : !model.ready ? 'notice' : model.opened !== null ? 'preview' : model.view === View.ICONS ? 'grid' : 'tree');
|
|
135
131
|
|
|
136
132
|
// 说明区只在内容变了才重画,免得重试按钮在点击中途被换掉。
|
|
137
133
|
let noticeKey = null;
|
|
@@ -143,23 +139,115 @@ function paintNotice() {
|
|
|
143
139
|
showNotice($('notice'), failed ? { failure: conn.failure, retry: conn.hello } : { text: key });
|
|
144
140
|
}
|
|
145
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
|
+
|
|
146
225
|
function render() {
|
|
147
226
|
const current = mode();
|
|
148
227
|
const refocus = backPressed && document.hasFocus(), handoff = openPressed && document.hasFocus();
|
|
149
228
|
backPressed = openPressed = false;
|
|
150
|
-
|
|
151
|
-
$(id).classList.toggle('off', current !== id);
|
|
152
|
-
$(id).inert = current !== id;
|
|
153
|
-
}
|
|
229
|
+
const slideIn = takeSlide(current);
|
|
154
230
|
if (current === 'notice') paintNotice();
|
|
155
231
|
const browsing = current === 'tree' || current === 'grid';
|
|
156
232
|
(model.view === View.ICONS ? grid : tree).render(); // 只画正在用的视图,另一个留着它的内容和滚动位置
|
|
157
233
|
landed();
|
|
158
234
|
restore.settle();
|
|
235
|
+
// 待恢复的位置只属于它那个文件:opened 清了或换成别的文件,位置作废。
|
|
236
|
+
if (pending.preview !== null && pending.path !== model.opened) pending.preview = null;
|
|
237
|
+
const released = []; // 这次停止的面板:画面的释放等退场结束(有过渡时),否则马上
|
|
159
238
|
if (current === 'preview' && preview.path !== model.opened) {
|
|
160
|
-
|
|
161
|
-
pending.preview
|
|
162
|
-
|
|
239
|
+
// 位置要等内容到了、真的设上才清:之前离开页面或换会话,saveNow 还存它。作废的读取不清,由接替它的读取用上。
|
|
240
|
+
const scroll = pending.preview;
|
|
241
|
+
preview.open(model.opened, scroll).then(used => { if (used && scroll !== null && pending.preview === scroll) pending.preview = null; });
|
|
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;
|
|
163
251
|
// 返回按钮随预览一起 inert,焦点会掉到页面外:用户刚点了返回、页面又持有焦点时交给目录树或网格。
|
|
164
252
|
// 后台刷新、切会话、root 变化造成的切换不动焦点,免得抢走客户端输入框的焦点。
|
|
165
253
|
if (refocus && browsing) browser().focus();
|
|
@@ -168,6 +256,9 @@ function render() {
|
|
|
168
256
|
syncToolbar();
|
|
169
257
|
declareBack();
|
|
170
258
|
}
|
|
259
|
+
// 窗口尺寸变了(旋转)、系统的减弱动态效果改了:正在播的动画结束到终点。
|
|
260
|
+
window.addEventListener('resize', endRunning);
|
|
261
|
+
onMotionChange(endRunning);
|
|
171
262
|
|
|
172
263
|
// ---- 工具栏:Mac 用 coda.toolbar,没有的(iOS、harness)退成页内一条 ----
|
|
173
264
|
// Mac 只有一个原生按钮「更多」:原生菜单带向下的箭头,关不掉,所以按下后由页面弹菜单。返回键在预览头部,不在这里。
|
|
@@ -179,9 +270,10 @@ const toolbarItems = () => infoOpen ? [] : hasToolbar
|
|
|
179
270
|
{ id: 'hidden', label: '显示隐藏文件', icon: 'eye', kind: 'toggle', on: model.showHidden },
|
|
180
271
|
];
|
|
181
272
|
// iPhone 树页顶部:返回(仅横屏)、根目录名、⋯。刷新、显示隐藏文件和排序都在 ⋯ 的菜单里。
|
|
273
|
+
// 预览时和属性页一样只留返回(竖屏整条不显示):标题和 ⋯ 在预览头部,⋯ 里只有刷新和复制路径。
|
|
182
274
|
// 属性页上只留返回:竖屏有原生导航栏,整条工具条不显示;横屏导航栏隐藏,页面自己给返回(显示与否都由 style.css 的横屏媒体查询决定)。
|
|
183
275
|
const MORE = { id: 'more', label: '更多', kind: 'button', glyph: 'ellipsis', iconOnly: true, menu: true };
|
|
184
|
-
const phoneItems = () => infoOpen ? [EXIT] : [EXIT, { kind: 'title', label: model.ready ? dirTitle() : '' }, MORE];
|
|
276
|
+
const phoneItems = () => infoOpen || mode() === 'preview' ? [EXIT] : [EXIT, { kind: 'title', label: model.ready ? dirTitle() : '' }, MORE];
|
|
185
277
|
// 比较键就是要画的项:根目录名变了(换会话)工具条跟着重画。
|
|
186
278
|
let lastItems = '';
|
|
187
279
|
function syncToolbar() {
|
|
@@ -198,7 +290,10 @@ function syncToolbar() {
|
|
|
198
290
|
// 原生按钮没有 DOM 元素可以当锚点:用一个固定在页面右上角的假锚点,同时也是「谁打开的菜单」的标记。
|
|
199
291
|
const TOOLBAR = { getBoundingClientRect: () => ({ right: window.innerWidth, bottom: 0 }) };
|
|
200
292
|
// 「更多」菜单的内容只写这一处,iPhone 的 ⋯ 和 Mac 的原生按钮共用:刷新、显示隐藏文件、「显示」›;「显示」里是视图和排序,当前项有对勾。
|
|
201
|
-
const moreMenu = () => ({ items: [
|
|
293
|
+
const moreMenu = () => isIOS && mode() === 'preview' ? { items: [
|
|
294
|
+
{ label: '刷新', run: () => act('refresh') },
|
|
295
|
+
{ label: '复制路径', run: () => preview.copyPath() }, // 相对路径
|
|
296
|
+
] } : ({ items: [
|
|
202
297
|
{ label: '刷新', run: () => act('refresh') },
|
|
203
298
|
{ label: '显示隐藏文件', checked: model.showHidden, run: () => act('hidden') },
|
|
204
299
|
{ label: '显示', submenu: { items: [
|
|
@@ -240,13 +335,17 @@ function changeView(view) {
|
|
|
240
335
|
schedule();
|
|
241
336
|
}
|
|
242
337
|
|
|
338
|
+
// 键盘激活没有 pointerdown,菜单外点击那条规则不管用:同一个按钮再次激活就关闭。
|
|
339
|
+
function toggleMore(button) {
|
|
340
|
+
if (!menu.hidden && menu.opener === button) menu.hide();
|
|
341
|
+
else menu.open(button, moreMenu());
|
|
342
|
+
}
|
|
343
|
+
|
|
243
344
|
function act(id, button) {
|
|
244
345
|
// 横屏时导航栏隐藏,原生返回看不到:这里的「返回」和原生返回走同一个退层逻辑,在根层才关视图。
|
|
245
346
|
if (id === EXIT.id) { if (goBack(1)) backPressed = true; else quiet(() => coda.close()); }
|
|
246
347
|
else if (id === 'more') {
|
|
247
|
-
|
|
248
|
-
if (!menu.hidden && menu.opener === button) menu.hide();
|
|
249
|
-
else menu.open(button, moreMenu());
|
|
348
|
+
toggleMore(button);
|
|
250
349
|
}
|
|
251
350
|
else if (id === 'hidden') {
|
|
252
351
|
model.setShowHidden(!model.showHidden);
|
|
@@ -283,7 +382,7 @@ function saveNow() {
|
|
|
283
382
|
// setState 超限会同步抛错:再收紧一次,仍失败就放弃这次,不影响界面。
|
|
284
383
|
if (quiet(() => (coda.setState(persisted), true)) === undefined) quiet(() => coda.setState(trimState(persisted, session, STATE_LIMIT / 4)));
|
|
285
384
|
}
|
|
286
|
-
quiet(() => coda.on('visibility', visible => { if (!visible) saveNow(); }));
|
|
385
|
+
quiet(() => coda.on('visibility', visible => { if (!visible) { press.reset(); saveNow(); } }));
|
|
287
386
|
$('tree').addEventListener('scroll', queueSave, { passive: true });
|
|
288
387
|
$('tree').addEventListener('scroll', () => restore.scrolled('tree'), { passive: true });
|
|
289
388
|
grid.onScroll(queueSave);
|
|
@@ -295,6 +394,7 @@ preview.onScroll(menu.hide);
|
|
|
295
394
|
// 行菜单顶上是路径,下面一行 大小 · 完整修改时间(文件夹只有修改时间,读不到就没有这一行);指向外面的链接和不能打开的条目没有元数据,不显示这一行。
|
|
296
395
|
// 不能打开的条目(指向外面或失效的链接、other)没有「添加到聊天」,和不能拖动一致;它们仍有复制路径和属性。
|
|
297
396
|
function pathMenu(event, row) {
|
|
397
|
+
press.reset(); // 长按弹出菜单:按下反馈立即去掉
|
|
298
398
|
const dead = row.kind === EntryKind.LINK || row.kind === EntryKind.OTHER;
|
|
299
399
|
// Mac 的第一项和双击是同一个动作(右键不改选中);文件夹在列表里写展开或收起,别的写打开。iPhone 轻点就是打开,菜单不变。
|
|
300
400
|
const folder = row.kind === EntryKind.DIR, listed = model.view !== View.ICONS;
|
|
@@ -341,16 +441,18 @@ function enterDir(path) {
|
|
|
341
441
|
trail.remember(model.cwd, grid.scroll());
|
|
342
442
|
selectEntry(null); // 进入新的一层:选中清空
|
|
343
443
|
model.enter(path);
|
|
444
|
+
note({ kind: 'fade', to: model.cwd });
|
|
344
445
|
shownCwd = model.cwd;
|
|
345
446
|
restore.drop('grid');
|
|
346
447
|
grid.scrollTo(0);
|
|
347
448
|
declareBack();
|
|
348
449
|
}
|
|
349
|
-
// 退 levels 层(到根为止);已经在根目录返回 false。
|
|
350
|
-
function leaveDir(levels = 1) {
|
|
450
|
+
// 退 levels 层(到根为止);已经在根目录返回 false。record 为假时不记过渡意图(goBack 里的内部调用:意图由它记)。
|
|
451
|
+
function leaveDir(levels = 1, record = true) {
|
|
351
452
|
if (model.cwd === '') return false;
|
|
352
453
|
const from = model.cwd.split('/');
|
|
353
454
|
model.leave(levels);
|
|
455
|
+
if (record) note({ kind: 'fade', to: model.cwd });
|
|
354
456
|
land(trail.take(model.cwd) ?? 0);
|
|
355
457
|
// 选中来时经过的那个文件夹(退到的那一层的直接子项)。目录被删、模型自己退回上层走 landed,不改选中。
|
|
356
458
|
selectEntry(from.slice(0, model.cwd === '' ? 1 : model.cwd.split('/').length + 1).join('/'));
|
|
@@ -368,13 +470,16 @@ function landed() {
|
|
|
368
470
|
}
|
|
369
471
|
|
|
370
472
|
// ---- 上一层:iPhone 用原生返回,路径只在这里声明 ----
|
|
371
|
-
// 路径是上层的标题,由远到近,不含当前页:图标视图在 a/b 是 [根目录名, 'a']
|
|
473
|
+
// 路径是上层的标题,由远到近,不含当前页:图标视图在 a/b 是 [根目录名, 'a'];列表视图没有。属性页、预览各多一层当前页(要回到的那一页):列表视图是 '资源管理器',图标视图是当前目录名。
|
|
474
|
+
// 预览开着是 opened 不为空、且根目录就绪;没就绪时页面是说明区,路径为空。
|
|
372
475
|
// 标题是当前目录名:根目录是根目录名。
|
|
373
476
|
const dirTitle = () => (model.cwd === '' || model.view !== View.ICONS ? rootName(model.root.path) : model.cwd.slice(model.cwd.lastIndexOf('/') + 1));
|
|
477
|
+
const previewOpen = () => model.ready && model.opened !== null;
|
|
374
478
|
function backPath() {
|
|
375
479
|
const icons = model.view === View.ICONS && model.ready;
|
|
376
480
|
const upper = icons && model.cwd !== '' ? [rootName(model.root.path), ...model.cwd.split('/').slice(0, -1)] : [];
|
|
377
|
-
|
|
481
|
+
const here = icons ? dirTitle() : '资源管理器';
|
|
482
|
+
return [...upper, ...(infoOpen ? [here] : []), ...(previewOpen() ? [here] : [])];
|
|
378
483
|
}
|
|
379
484
|
let declared = [];
|
|
380
485
|
// 路径没变不重复声明;force:客户端已经退了一层,路径没变也要重新告诉它现在在哪。
|
|
@@ -385,12 +490,18 @@ function declareBack(force = false) {
|
|
|
385
490
|
declared = path;
|
|
386
491
|
quiet(() => coda.back(path));
|
|
387
492
|
}
|
|
388
|
-
// 退 steps
|
|
493
|
+
// 退 steps 层:先关预览,再关属性页,再退图标视图的目录;返回是不是真的退了。横屏的返回和原生返回共用。
|
|
494
|
+
// 没就绪时页面是说明区,看不见预览和目录层:不消耗它们(保存的 opened、cwd 不变),横屏的返回直接关视图。
|
|
495
|
+
// 一次返回只记一个意图,按它消耗了什么:关了预览或属性页记 pop(目标是退完之后的模式),只退了目录记 fade;内部调用的 closeInfo、leaveDir 不记。
|
|
389
496
|
function goBack(steps) {
|
|
390
|
-
|
|
391
|
-
|
|
497
|
+
if (!model.ready) return false;
|
|
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; }
|
|
392
502
|
const levels = Math.min(steps - used, model.view === View.ICONS && model.cwd !== '' ? model.cwd.split('/').length : 0);
|
|
393
|
-
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 });
|
|
394
505
|
return used > 0;
|
|
395
506
|
}
|
|
396
507
|
if (nativeBack) quiet(() => coda.on('back', event => {
|
|
@@ -399,15 +510,20 @@ if (nativeBack) quiet(() => coda.on('back', event => {
|
|
|
399
510
|
|
|
400
511
|
// ---- 属性页:所有关闭的路径(原生返回、横屏的返回、换会话、根目录变化)都重新声明回上层 ----
|
|
401
512
|
function openInfo(row) {
|
|
513
|
+
note({ kind: 'push', from: mode(), to: 'info' });
|
|
402
514
|
infoOpen = true;
|
|
515
|
+
infoStopped = false;
|
|
403
516
|
info.open(row.path, row);
|
|
404
517
|
declareBack();
|
|
405
518
|
schedule();
|
|
406
519
|
}
|
|
407
|
-
|
|
520
|
+
// 停止是立即的(取消统计、作废在途的读取);画面留到退场结束,由 render 释放。换会话、换根目录要立即释放(immediate),也不记意图。
|
|
521
|
+
function closeInfo(record = true, immediate = false) {
|
|
408
522
|
if (!infoOpen) return;
|
|
409
523
|
infoOpen = false;
|
|
410
|
-
info.close();
|
|
524
|
+
if (immediate) info.close();
|
|
525
|
+
else { info.stop(); infoStopped = true; } // 在统计的一并取消
|
|
526
|
+
if (record) note({ kind: 'pop', from: 'info', to: mode() });
|
|
411
527
|
declareBack();
|
|
412
528
|
schedule();
|
|
413
529
|
}
|
|
@@ -415,17 +531,18 @@ function closeInfo() {
|
|
|
415
531
|
// ---- 模块的消息(代次和握手由 connection 处理)----
|
|
416
532
|
function onSession(data) {
|
|
417
533
|
saveNow(); // 先存旧会话
|
|
534
|
+
intent = null;
|
|
535
|
+
endRunning();
|
|
536
|
+
press.reset();
|
|
418
537
|
preview.close();
|
|
419
|
-
closeInfo();
|
|
538
|
+
closeInfo(false, true);
|
|
420
539
|
menu.hide();
|
|
421
540
|
tree.reset();
|
|
422
541
|
grid.reset();
|
|
423
542
|
epoch++;
|
|
424
|
-
opening = false;
|
|
425
|
-
clearTimeout(unlockTimer);
|
|
426
543
|
hint.hide();
|
|
427
544
|
const saved = persisted.sessions[data.session] ?? null;
|
|
428
|
-
pending =
|
|
545
|
+
pending = saved?.opened ? { preview: { top: saved.scroll.top, left: saved.scroll.left }, path: saved.opened } : { preview: null, path: null };
|
|
429
546
|
model.receive(data, saved);
|
|
430
547
|
trail.clear();
|
|
431
548
|
restore.clear();
|
|
@@ -438,11 +555,11 @@ function onSession(data) {
|
|
|
438
555
|
|
|
439
556
|
function onRoot(data) {
|
|
440
557
|
const before = model.root;
|
|
441
|
-
if (data.state !== before?.state || data.path !== before?.path) menu.hide(); //
|
|
442
|
-
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); // 属性页看的是旧根目录下的路径
|
|
443
560
|
const scope = model.scope;
|
|
444
561
|
const done = model.receive(data);
|
|
445
|
-
if (model.scope !== scope) invalidateScroll(); //
|
|
562
|
+
if (model.scope !== scope) { invalidateScroll(); pending.preview = null; press.reset(); } // 换了根目录(同根重建不算):旧根目录的位置和记录不能给新的用,待恢复的预览位置也是
|
|
446
563
|
if (done && data.state === RootState.READY) {
|
|
447
564
|
if (before?.path !== data.path) { if (model.opened !== null) preview.reload(); } else preview.refresh(); // 换了根目录,opened 已清空:旧预览随即关掉,不再读
|
|
448
565
|
}
|
package/view/file-app.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// 文件视图的页面入口:读一个文件。会话和路径来自 coda.args(启动值),之后的变化走 context 事件;
|
|
2
2
|
// 连接在 connection.mjs,预览在 preview.mjs,这里不创建目录树。设计见 docs/design/phase-2.md 第 7 节。
|
|
3
3
|
// Mac 的独立窗口里选中文字右键可以添加到聊天(第 13.7 节);iPhone 不接,用系统的选区菜单。
|
|
4
|
-
|
|
4
|
+
// iPhone 点文件在资源页里预览(第 16 节),不再进这个视图;别的入口仍可能在 iPhone 上打开它:没有工具条,靠系统返回离开。
|
|
5
|
+
import { paintBar } from './bar.mjs';
|
|
5
6
|
import { createChat } from './chat.mjs';
|
|
6
7
|
import { connect } from './connection.mjs';
|
|
7
8
|
import { mountHint } from './hint.mjs';
|
|
@@ -9,13 +10,14 @@ import { mountMenu } from './menu.mjs';
|
|
|
9
10
|
import { noticeText } from './model.mjs';
|
|
10
11
|
import { showNotice } from './notice.mjs';
|
|
11
12
|
import { mountPreview } from './preview.mjs';
|
|
13
|
+
import { mountPress } from './press.mjs';
|
|
12
14
|
import { RootState } from './protocol.mjs';
|
|
13
15
|
|
|
14
16
|
const coda = window.coda;
|
|
15
17
|
const $ = id => document.getElementById(id);
|
|
16
18
|
const quiet = fn => { try { return fn(); } catch { return undefined; } };
|
|
17
19
|
const hasToolbar = typeof coda.toolbar === 'function' && coda.platform === 'mac';
|
|
18
|
-
const isIOS = coda.platform === 'ios';
|
|
20
|
+
const isIOS = coda.platform === 'ios';
|
|
19
21
|
|
|
20
22
|
// 参数里的会话和路径,形状不对按没有处理。
|
|
21
23
|
const argsOf = args => ({
|
|
@@ -35,9 +37,10 @@ let restore = parseScroll(quiet(() => coda.getState()));
|
|
|
35
37
|
const conn = connect(coda, { handlers: { session: onSession, root: onRoot, changed: onChanged }, onStatus: () => schedule() });
|
|
36
38
|
const hint = mountHint($('hint'));
|
|
37
39
|
const menu = mountMenu($('menu'));
|
|
40
|
+
const press = mountPress({ consumed: menu.consumed }); // 按下反馈:刷新、复制、重试等按钮同资源页(第 17.3 节)
|
|
38
41
|
const chat = createChat({ link: conn.link, copy: text => coda.copy(text), hint });
|
|
39
42
|
const preview = mountPreview($('preview'), {
|
|
40
|
-
read: (path, offset) => conn.link.call('read', { path, offset }), copy: text => coda.copy(text),
|
|
43
|
+
read: (path, offset) => conn.link.call('read', { path, offset }), copy: text => coda.copy(text),
|
|
41
44
|
selectionMenu: isIOS ? null : (event, selection) => menu.open(event, { items: chat.selectionItems(selection) }),
|
|
42
45
|
});
|
|
43
46
|
|
|
@@ -70,7 +73,8 @@ function render() {
|
|
|
70
73
|
function openPreview() {
|
|
71
74
|
const { path } = want, scroll = restore;
|
|
72
75
|
// 没有要恢复的位置就明确从头开始,不靠清空正文后滚动条自己归零。
|
|
73
|
-
|
|
76
|
+
// 位置真正用上才清;读取被刷新、重载作废时,预览自己让接替的那次读取接着用。
|
|
77
|
+
preview.open(path, scroll ?? { top: 0, left: 0 }).then(used => { if (used && preview.path === path && restore === scroll) restore = null; });
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
// 预览收起前记下滚动位置,恢复后接着用;内容还没到时 restore 还没用掉,不覆盖。
|
|
@@ -92,6 +96,7 @@ function paintNotice() {
|
|
|
92
96
|
|
|
93
97
|
// ---- 模块的消息(代次和握手由 connection 处理)----
|
|
94
98
|
function onSession(data) {
|
|
99
|
+
press.reset();
|
|
95
100
|
park();
|
|
96
101
|
preview.close();
|
|
97
102
|
menu.hide();
|
|
@@ -103,6 +108,7 @@ function onSession(data) {
|
|
|
103
108
|
|
|
104
109
|
function onRoot(data) {
|
|
105
110
|
const before = root;
|
|
111
|
+
if (data.state !== before?.state || data.path !== before?.path) press.reset();
|
|
106
112
|
if (data.state !== before?.state || data.path !== before?.path) menu.hide(); // 选区和行号是旧内容上的
|
|
107
113
|
root = { state: data.state, path: data.path };
|
|
108
114
|
if (data.state === RootState.READY) {
|
|
@@ -120,23 +126,18 @@ function onChanged() {
|
|
|
120
126
|
// ---- 参数变了:换文件或换会话,旧文件的滚动位置不带过去 ----
|
|
121
127
|
quiet(() => coda.on('context', ({ args }) => {
|
|
122
128
|
const next = argsOf(args);
|
|
123
|
-
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(); }
|
|
124
130
|
want = next;
|
|
125
131
|
schedule();
|
|
126
132
|
}));
|
|
127
133
|
|
|
128
|
-
// ---- 工具条:Mac 用 coda.toolbar;iPhone
|
|
134
|
+
// ---- 工具条:Mac 用 coda.toolbar;iPhone 没有;其他(harness)退成页内一条 ----
|
|
129
135
|
const refresh = () => { conn.refresh(); preview.refresh(); };
|
|
130
|
-
// 说明区下预览是关着的,复制的是启动值里的路径:模块不可用时也能把路径交给对话。
|
|
131
|
-
const copyPath = () => (preview.path !== null ? preview.copyPath() : want.path !== null && coda.copy(want.path));
|
|
132
136
|
const items = [{ id: 'refresh', label: '刷新', icon: 'arrow.clockwise', kind: 'button' }];
|
|
133
137
|
if (hasToolbar) {
|
|
134
138
|
quiet(() => coda.toolbar(items));
|
|
135
139
|
quiet(() => coda.on('toolbar', ({ id }) => { if (id === 'refresh') refresh(); }));
|
|
136
|
-
} else
|
|
137
|
-
const shown = isIOS ? [EXIT, { ...items[0], glyph: 'refresh' }, { id: 'copy', label: '复制路径', kind: 'button', glyph: 'copy' }] : items;
|
|
138
|
-
paintBar($('bar'), shown, id => (id === EXIT.id ? quiet(() => coda.close()) : id === 'copy' ? copyPath() : refresh()));
|
|
139
|
-
}
|
|
140
|
+
} else if (!isIOS) paintBar($('bar'), items, refresh);
|
|
140
141
|
|
|
141
142
|
// ---- 阅读位置:setState 按视图和 args 隔离,每个文件自然分开 ----
|
|
142
143
|
let saveTimer = null;
|
|
@@ -150,7 +151,7 @@ function saveNow() {
|
|
|
150
151
|
if (at) quiet(() => coda.setState({ v: 1, top: at.top, left: at.left }));
|
|
151
152
|
}
|
|
152
153
|
// visibility: false 之后只保证同步事件处理完,所以同步保存。
|
|
153
|
-
quiet(() => coda.on('visibility', visible => { if (!visible) saveNow(); }));
|
|
154
|
+
quiet(() => coda.on('visibility', visible => { if (!visible) { press.reset(); saveNow(); } }));
|
|
154
155
|
preview.onScroll(queueSave);
|
|
155
156
|
preview.onScroll(menu.hide);
|
|
156
157
|
|
package/view/file.html
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
<link rel="stylesheet" href="style.css">
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
|
+
<div id="bar" class="bar" hidden></div>
|
|
10
11
|
<main id="stage">
|
|
11
12
|
<div id="preview" class="pane preview"></div>
|
|
12
13
|
<div id="notice" class="pane empty secondary"></div>
|
|
13
14
|
</main>
|
|
14
|
-
<div id="bar" class="bar bottom" hidden></div>
|
|
15
15
|
<div id="menu" class="menu" role="menu" hidden></div>
|
|
16
16
|
<div id="hint" class="hint" role="status" hidden></div>
|
|
17
17
|
<script type="module" src="file-app.mjs"></script>
|
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/model.mjs
CHANGED
|
@@ -43,7 +43,7 @@ export class Model {
|
|
|
43
43
|
expanded = new Set(); // 不变量:展开的目录,它的每一级上层也展开
|
|
44
44
|
wanted = new Map(); // 恢复状态时各目录要取够的条数,第一次取用后删掉
|
|
45
45
|
selected = null; // 选中的条目(高亮和键盘移动用,文件夹、不能打开的条目都可以)
|
|
46
|
-
opened = null; //
|
|
46
|
+
opened = null; // 页内预览中的文件(两端一样);null 是在看目录
|
|
47
47
|
showHidden = false;
|
|
48
48
|
sort = DEFAULT_SORT; // 全局一份,由页面存进 persisted
|
|
49
49
|
view = View.LIST; // 全局一份,由页面存进 persisted
|
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
|
@@ -53,9 +53,11 @@ const formatTime = ms => new Date(ms).toLocaleString('zh-CN', { hour12: false })
|
|
|
53
53
|
export const lineCount = text => (text === '' ? 1 : text.split('\n').length - (text.endsWith('\n') ? 1 : 0));
|
|
54
54
|
|
|
55
55
|
// read(path, offset) → Promise<chunk 回答>,会话换了会以 stale 错误拒绝;copy(text) 复制路径。
|
|
56
|
-
// actions:头部在「复制路径」旁额外加的按钮 [{ label, icon, run(path) }]
|
|
57
|
-
// copyInHead:false 时头部不放「复制路径」(iPhone
|
|
56
|
+
// actions:头部在「复制路径」旁额外加的按钮 [{ label, icon, run(path, button) }],button 是被点的按钮(菜单用它定位),预览不知道它们做什么。
|
|
57
|
+
// copyInHead:false 时头部不放「复制路径」(iPhone 的复制路径在 ⋯ 菜单里),由页面调 copyPath()。
|
|
58
58
|
// back:给了就在头部最左边放「返回」(Mac 侧栏预览:原生工具栏项目只能在右侧);文件页和 iPhone 不传。
|
|
59
|
+
// open(path, scroll) 带了要恢复的位置时,返回的 Promise 在「位置用上了」时变 true(正文到了、已设好位置;读取失败不算,位置留着等重试),
|
|
60
|
+
// 在「位置作废」时变 false(预览关了、改看别的文件)。读取被刷新、重载或 changed 作废时位置不丢:接替它的那次读取接着带上,用上才算完。
|
|
59
61
|
// selectionMenu(event, { path, text, startLine, endLine }):给了就接管正文里选中文字的右键(只有 Mac 传);预览不知道菜单里是什么。
|
|
60
62
|
// 选区为空、或裁到正文里之后为空时不接管,走系统默认。内容和行号在这里取好,交出去之后和选区无关。
|
|
61
63
|
export function mountPreview(el, { read, copy, actions = [], copyInHead = true, back = null, selectionMenu = null }) {
|
|
@@ -64,13 +66,16 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
|
|
|
64
66
|
// 图标按钮:可访问名称和 Mac 的悬停提示都是 label;没有图标的退回文字。
|
|
65
67
|
const action = (label, glyph, run) => h('button', { class: glyph ? 'icon' : 'link', 'aria-label': label, title: label, onclick: run }, glyph ? icon(glyph, 18) : label);
|
|
66
68
|
const copyPath = () => path !== null && copy(path);
|
|
67
|
-
const retryButton = h('button', { class: 'link', onclick: () => load(
|
|
69
|
+
const retryButton = h('button', { class: 'link', onclick: () => load(true), hidden: true }, '重试');
|
|
68
70
|
const body = h('div', { class: 'pbody' });
|
|
69
|
-
const extra = actions.map(({ label, icon: glyph, run }) => action(label, glyph, () => path !== null && run(path)));
|
|
71
|
+
const extra = actions.map(({ label, icon: glyph, run }) => { const button = action(label, glyph, () => path !== null && run(path, button)); return button; });
|
|
70
72
|
el.replaceChildren(h('div', { class: 'phead' }, ...(back ? [action('返回', 'back', back)] : []), fileIcon, h('div', { class: 'grow' }, name, meta), retryButton,
|
|
71
73
|
...(copyInHead ? [action('复制路径', 'copy', copyPath)] : []), ...extra), body);
|
|
72
74
|
|
|
73
75
|
let path = null, token = 0, shown = null, objectUrl = null; // shown:当前显示的 { size, mtimeMs }
|
|
76
|
+
let opens = 0, stoppedAt = -1; // 打开次数和上一次停止时的次数:释放只在停止之后没有再打开过时才做(返回的退场还没结束又打开了)
|
|
77
|
+
let carry = null; // 待恢复的位置 { scroll, settle }:open 带进来,读取真正用上或作废后才清
|
|
78
|
+
const settle = used => { const c = carry; carry = null; c?.settle(used); };
|
|
74
79
|
let metaText = ' ', metaTitle = '', stale = null; // stale:后台刷新失败的原因,此时正文还是上次的
|
|
75
80
|
// 更新失败的提示占用元信息那一行,重试按钮在头部,所以正文不会被顶动。
|
|
76
81
|
const paintMeta = () => {
|
|
@@ -129,8 +134,8 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
|
|
|
129
134
|
notice('读不到这个文件', error.message, { label: '重试', run: retry });
|
|
130
135
|
}
|
|
131
136
|
|
|
132
|
-
// silent
|
|
133
|
-
async function load(
|
|
137
|
+
// silent:刷新。没变化不重画;变了就换内容,并尽量留在原来的滚动位置;有待恢复的位置时用它。
|
|
138
|
+
async function load(silent) {
|
|
134
139
|
const mine = ++token, mark = () => mine === token;
|
|
135
140
|
if (!silent) { shown = null; setMeta('读取中…'); revoke(); body.replaceChildren(); }
|
|
136
141
|
try {
|
|
@@ -140,29 +145,46 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
|
|
|
140
145
|
});
|
|
141
146
|
if (!mark() || result.cancelled) return;
|
|
142
147
|
if (result.same) return setStale(null);
|
|
143
|
-
|
|
148
|
+
// 刷新留在原位;整页重读(打开、重载、重试)没有要恢复的位置就明确从头开始,不靠清空正文后滚动条自己归零。
|
|
149
|
+
const keep = carry?.scroll ?? (silent ? { top: body.scrollTop, left: body.scrollLeft } : { top: 0, left: 0 });
|
|
144
150
|
show(result);
|
|
145
151
|
body.scrollTop = keep.top; body.scrollLeft = keep.left;
|
|
152
|
+
settle(true);
|
|
146
153
|
} catch (error) {
|
|
147
|
-
if (mark()) failure(error, silent, () => load(
|
|
154
|
+
if (mark()) failure(error, silent, () => load(false)); // 失败不算用上:待恢复的位置留着,重试或之后的刷新成功才用、才清
|
|
148
155
|
}
|
|
149
156
|
}
|
|
150
157
|
|
|
151
158
|
return {
|
|
152
159
|
open(next, scroll = null) {
|
|
160
|
+
settle(false);
|
|
161
|
+
opens++;
|
|
153
162
|
path = next;
|
|
154
163
|
const base = next.split('/').pop();
|
|
155
164
|
name.textContent = base;
|
|
156
165
|
name.title = next;
|
|
157
166
|
fileIcon.replaceChildren(icon(iconFor({ kind: EntryKind.FILE, name: base }), 22));
|
|
158
|
-
|
|
167
|
+
const used = scroll ? new Promise(done => { carry = { scroll, settle: done }; }) : null;
|
|
168
|
+
const read = load(false);
|
|
169
|
+
return used ?? read;
|
|
159
170
|
},
|
|
160
171
|
copyPath,
|
|
161
|
-
refresh() { return path === null ? undefined : load(
|
|
172
|
+
refresh() { return path === null ? undefined : load(true); },
|
|
162
173
|
// 内容的来源变了(根目录换了位置):旧正文不能留,也不能按元数据判断「没变」。
|
|
163
|
-
reload() { return path === null ? undefined : load(
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
reload() { return path === null ? undefined : load(false); },
|
|
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 }),
|
|
166
188
|
onScroll: fn => body.addEventListener('scroll', fn, { passive: true }),
|
|
167
189
|
get path() { return path; },
|
|
168
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,20 +55,26 @@ 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; } /* 说明区的图标不上色 */
|
|
61
71
|
|
|
62
|
-
/* 页内工具条:iPhone
|
|
72
|
+
/* 页内工具条:iPhone 资源页在顶部(返回、根目录名或文件名、⋯)。没有 coda.toolbar 的其他平台(harness)是一条文字按钮。 */
|
|
63
73
|
.bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
|
|
64
74
|
.bar button { flex: none; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: var(--coda-radius, 6px); color: var(--coda-secondary, #6e6e73); }
|
|
65
75
|
.bar button.on { color: var(--coda-accent, #0a84ff); }
|
|
66
76
|
.bar svg { display: block; flex: none; }
|
|
67
77
|
.bar-title { padding: 0 8px; font-weight: 600; }
|
|
68
|
-
.bar.bottom { padding-bottom: var(--safe-bottom); border-top: 1px solid var(--line); border-bottom: 0; } /* 操作区 44 点(iPhone)之外只加安全区 */
|
|
69
78
|
|
|
70
79
|
/* 树:只画可见的一段,行高固定(tree.mjs 量 .row 的高度)。
|
|
71
80
|
Mac 是侧栏列表:左右缩进 8 点,行有圆角,选中用 --coda-selection。 */
|
|
@@ -104,7 +113,7 @@ p { margin: 0; }
|
|
|
104
113
|
.tail.warn { color: var(--coda-orange, #b25000); }
|
|
105
114
|
|
|
106
115
|
/* 预览:头部永远占一行名字加一行说明,加载和失败只换下面的内容。 */
|
|
107
|
-
.preview { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; } /*
|
|
116
|
+
.preview { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; } /* 底部的安全区归 .pbody(iPhone,见 .coda-ios .pbody) */
|
|
108
117
|
.phead button, .ghead button { flex: none; white-space: nowrap; }
|
|
109
118
|
.phead, .ghead { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
|
|
110
119
|
.pico, .ghico { flex: none; display: grid; place-items: center; color: var(--coda-secondary, #6e6e73); }
|
|
@@ -140,7 +149,7 @@ button.icon svg { display: block; }
|
|
|
140
149
|
/* 键盘焦点:选中的高亮已经表示位置,点击时不画外框;只在键盘操作(:focus-visible)时给容器内边一圈细线。 */
|
|
141
150
|
#tree:focus, .gbody:focus { outline: none; }
|
|
142
151
|
#tree:focus-visible, .gbody:focus-visible { outline: 1px solid var(--coda-accent, #0a84ff); outline-offset: -2px; }
|
|
143
|
-
.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);
|
|
144
153
|
background: var(--coda-card, var(--coda-background, #fff));
|
|
145
154
|
/* 高度有上限:内容多(长路径加五项)时在菜单里滚动,不超出安全区;位置由 menu.mjs 夹在安全区内。 */
|
|
146
155
|
max-height: calc(100vh - var(--safe-top) - var(--safe-bottom) - 8px); overflow-y: auto; overscroll-behavior: contain; }
|
|
@@ -195,7 +204,6 @@ button.icon svg { display: block; }
|
|
|
195
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); }
|
|
196
205
|
.gnote.more, .gnote.retry { color: var(--coda-accent, #0a84ff); cursor: pointer; }
|
|
197
206
|
.coda-ios .cell { -webkit-touch-callout: none; } /* 长按由页面接管,不弹系统菜单 */
|
|
198
|
-
.coda-ios .cell:active { background: var(--hover); } /* 按下:和列表的行一样 */
|
|
199
207
|
|
|
200
208
|
/* 悬停只在有鼠标时:触摸后不会留着。 */
|
|
201
209
|
@media (hover: hover) {
|
|
@@ -205,6 +213,15 @@ button.icon svg { display: block; }
|
|
|
205
213
|
.menu button:hover { background: var(--coda-selection, var(--hover)); }
|
|
206
214
|
}
|
|
207
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
|
+
|
|
208
225
|
/* iPhone:行和按钮至少 44 点;行高 58 点(两行:名字、日期 · 大小)在这里定,tree.mjs 量 .row 得到,不另写一份。
|
|
209
226
|
目录树是 Coda 卡片外形的分组列表:.spacer 就是卡片(高度已等于全部行高),首尾圆角不用逐行判断。 */
|
|
210
227
|
.coda-ios { --row-h: 58px; --indent: 20px; --pad: 16px; }
|
|
@@ -217,7 +234,6 @@ button.icon svg { display: block; }
|
|
|
217
234
|
left: calc(var(--pad) + var(--indent) * var(--d, 0) + 22px + 8px); } /* 从图标之后开始 */
|
|
218
235
|
.coda-ios .row.sel + .row::before, .coda-ios .row.sel::before { background: transparent; }
|
|
219
236
|
.coda-ios .row { -webkit-touch-callout: none; } /* 长按由页面接管,不弹系统菜单;选择和拖动另外已关 */
|
|
220
|
-
.coda-ios .row.entry:active { background: var(--hover); }
|
|
221
237
|
.coda-ios .ico svg { width: 22px; height: 22px; }
|
|
222
238
|
.coda-ios .main { display: flex; flex-direction: column; justify-content: center; } /* 没有第二行的条目,名字垂直居中 */
|
|
223
239
|
.coda-ios .sub { display: block; }
|
|
@@ -230,13 +246,11 @@ button.icon svg { display: block; }
|
|
|
230
246
|
.coda-ios .bar { gap: 0; padding: 0 8px; }
|
|
231
247
|
.coda-ios .bar button { gap: 6px; padding: 0 12px; border-radius: var(--coda-radius, 10px); color: var(--coda-accent, #0a84ff); }
|
|
232
248
|
.coda-ios .bar button.icon { padding: 0; justify-content: center; }
|
|
233
|
-
.coda-ios .bar.bottom { padding: 0 8px var(--safe-bottom); }
|
|
234
|
-
.coda-ios .bar.bottom button { flex: 1 1 0; justify-content: center; } /* 横排单行:横屏只有 390 点高 */
|
|
235
249
|
.coda-ios .phead, .coda-ios .ghead { padding: 4px 12px; gap: 4px; }
|
|
236
250
|
.coda-ios .phead button, .coda-ios .ghead button { padding: 0 8px; }
|
|
251
|
+
.coda-ios .preview:not(.info) .pbody { padding-bottom: var(--safe-bottom); } /* 资源页里没有底部工具条:最后一行不被 Home 指示条盖住 */
|
|
237
252
|
.coda-ios .code { font-size: .8em; } /* 窄屏多看些:17 点下约 13.6 点 */
|
|
238
253
|
.coda-ios .menu button { padding: 0 10px; }
|
|
239
|
-
.coda-ios .menu button:active { background: var(--coda-selection, var(--hover)); }
|
|
240
254
|
.coda-ios .menu-head { padding: 6px 10px 2px; }
|
|
241
255
|
|
|
242
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'); };
|