nx-kv 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/package.json +1 -1
- package/src/core/db/migrations/index.js +2 -0
- package/src/core/db/migrations/v3.sql +20 -0
- package/src/core/db/version.js +4 -1
- package/src/modules/localtask/index.js +59 -0
- package/src/modules/localtask/repo/tasks.js +23 -0
- package/src/modules/localtask/task-ops.js +9 -0
- package/src/modules/localtask/task-remove.js +69 -0
- package/src/modules/localtask/task-view.js +4 -0
- package/src/modules/tasktool/plugins/timegoal-store.js +60 -0
- package/src/modules/templates/index.js +65 -9
- package/src/modules/templates/repo/templates.js +24 -2
- package/src/modules/templates/scope.js +107 -0
- package/src/modules/templates/service.js +83 -4
- package/src/runtime/spec.js +6 -1
- package/src/web/frontend/App.jsx +34 -2
- package/src/web/frontend/components/button/index.jsx +34 -7
- package/src/web/frontend/components/button/style.css +1 -1
- package/src/web/frontend/components/doc/doc-head.jsx +164 -48
- package/src/web/frontend/components/icons.jsx +17 -0
- package/src/web/frontend/components/layout/crumbs.js +4 -1
- package/src/web/frontend/components/md/attach-area.jsx +20 -11
- package/src/web/frontend/components/md/attach-modal.jsx +3 -2
- package/src/web/frontend/components/md/attach-picker.jsx +37 -7
- package/src/web/frontend/components/md/md-panes.jsx +102 -23
- package/src/web/frontend/components/md/sel-menu.jsx +11 -0
- package/src/web/frontend/components/md/tool-bar.jsx +153 -91
- package/src/web/frontend/components/sidebar/task-children.jsx +6 -11
- package/src/web/frontend/components/status-tag/index.jsx +30 -0
- package/src/web/frontend/components/status-tag/model.js +53 -0
- package/src/web/frontend/components/tool-acts/bar.jsx +156 -0
- package/src/web/frontend/components/tool-acts/dnd.js +59 -0
- package/src/web/frontend/components/tool-acts/layout-panel.jsx +289 -0
- package/src/web/frontend/components/tool-acts/modules.js +162 -0
- package/src/web/frontend/components/tool-acts/style.css +108 -0
- package/src/web/frontend/components/tool-acts/use-layout.js +27 -0
- package/src/web/frontend/modules/md/attach-mention.js +11 -0
- package/src/web/frontend/modules/md/md-edit-ops.js +10 -7
- package/src/web/frontend/modules/md/md-parse.js +8 -21
- package/src/web/frontend/modules/md/progress-search.js +96 -0
- package/src/web/frontend/modules/md/style.css +124 -14
- package/src/web/frontend/modules/md/use-templates.js +65 -2
- package/src/web/frontend/page/dir/index.jsx +73 -38
- package/src/web/frontend/page/dir/landing.jsx +73 -78
- package/src/web/frontend/page/dir/task.jsx +426 -111
- package/src/web/frontend/page/group/index.jsx +194 -88
- package/src/web/frontend/page/overview/index.jsx +168 -269
- package/src/web/frontend/page/progress/index.jsx +59 -9
- package/src/web/frontend/page/repos/index.jsx +95 -103
- package/src/web/frontend/page/settings/index.jsx +4 -3
- package/src/web/frontend/page/settings/style.css +59 -31
- package/src/web/frontend/page/settings/task-templates-section.jsx +94 -99
- package/src/web/frontend/page/templates/index.jsx +221 -203
- package/src/web/frontend/page/templates/scope-chips.jsx +211 -0
- package/src/web/frontend/panels.jsx +28 -4
- package/src/web/frontend/route-map.js +42 -2
- package/src/web/frontend/style-v2.css +33 -71
- package/src/web/frontend/style.css +127 -319
- package/src/web/frontend/workspace/areas.js +1 -1
- package/src/web/public/assets/Introduction-DU27b_b_.js +1 -0
- package/src/web/public/assets/bar-CNuQf706.js +1 -0
- package/src/web/public/assets/board-view-t8CKtq17.js +1 -0
- package/src/web/public/assets/button-BPYMY-zh.js +1 -0
- package/src/web/public/assets/button-DA4lNJeC.css +1 -0
- package/src/web/public/assets/cloud-DgNCxJsL.js +3 -0
- package/src/web/public/assets/{composer-launch-q1uPzWGo.js → composer-launch-BKeKTPp4.js} +1 -1
- package/src/web/public/assets/composer-panel-DP322mVs.js +1 -0
- package/src/web/public/assets/dag-C4702bOt.js +1 -0
- package/src/web/public/assets/dir-Cipgyv3a.js +5 -0
- package/src/web/public/assets/group-m61-WL4C.js +1 -0
- package/src/web/public/assets/index-BEkITE6q.css +1 -0
- package/src/web/public/assets/index-CeIJd4ee.js +30 -0
- package/src/web/public/assets/md-history-Uo6U7hYS.js +1 -0
- package/src/web/public/assets/md-panes-PS7K93Lg.js +28 -0
- package/src/web/public/assets/md-parse-DN9INgZn.js +25 -0
- package/src/web/public/assets/member-picker--32VkTmv.js +1 -0
- package/src/web/public/assets/overview-BmoTQJuu.js +1 -0
- package/src/web/public/assets/progress-CWy9bYKr.js +3 -0
- package/src/web/public/assets/refs-DAy1kYGf.js +1 -0
- package/src/web/public/assets/repos-D_NT51Dq.js +9 -0
- package/src/web/public/assets/route-crumb-lOriqwxP.js +1 -0
- package/src/web/public/assets/settings-CBrQ3Iz5.css +1 -0
- package/src/web/public/assets/settings-Vp3ZMC1M.js +7 -0
- package/src/web/public/assets/status-tag-DGlwjAg2.js +1 -0
- package/src/web/public/assets/task-CRpctHxx.js +9 -0
- package/src/web/public/assets/task-status-BP6y8MVu.js +1 -0
- package/src/web/public/assets/templates-D900RS5b.js +1 -0
- package/src/web/public/assets/tool-bar-1h2zairf.css +1 -0
- package/src/web/public/assets/tool-bar-C-rnP0vv.js +1 -0
- package/src/web/public/assets/upload-L1g-pfvZ.js +1 -0
- package/src/web/public/index.html +6 -5
- package/src/web/public/assets/Introduction-MAkTZvUX.js +0 -1
- package/src/web/public/assets/attach-Bw0necIf.js +0 -1
- package/src/web/public/assets/cloud-CG_hgVn9.js +0 -3
- package/src/web/public/assets/composer-panel-S2d6A3fG.js +0 -1
- package/src/web/public/assets/dag-CwY66RrZ.js +0 -1
- package/src/web/public/assets/dir-B_ySdQT1.js +0 -5
- package/src/web/public/assets/group-6sWouRDt.js +0 -1
- package/src/web/public/assets/index-DKncYqtS.js +0 -54
- package/src/web/public/assets/index-DO7b1M3E.css +0 -1
- package/src/web/public/assets/md-edit-ops-ZwnwtEax.js +0 -22
- package/src/web/public/assets/md-history-BxbOQtPI.js +0 -1
- package/src/web/public/assets/md-panes-Cso2NHbG.js +0 -7
- package/src/web/public/assets/member-picker-BpB9ZpWx.js +0 -1
- package/src/web/public/assets/overview-Bo8ivqRU.js +0 -1
- package/src/web/public/assets/progress-DPkGjn0P.js +0 -3
- package/src/web/public/assets/refs-CskU6rI7.js +0 -1
- package/src/web/public/assets/repos-B_tskNGw.js +0 -9
- package/src/web/public/assets/route-crumb-BZ6ffDRj.js +0 -1
- package/src/web/public/assets/settings-BMTd_p9Y.js +0 -7
- package/src/web/public/assets/settings-qCi-niJC.css +0 -1
- package/src/web/public/assets/task-Cs-9RNQn.js +0 -7
- package/src/web/public/assets/task-status-Bgo2Nfiw.js +0 -1
- package/src/web/public/assets/template-editor-CRxfV218.js +0 -1
- package/src/web/public/assets/templates-Apc3JKXa.js +0 -2
- package/src/web/public/assets/upload-C83Bwy06.js +0 -1
- /package/src/web/public/assets/{attach-BZrdOH46.css → task-status-BZrdOH46.css} +0 -0
|
@@ -121,6 +121,23 @@ const ICONS = {
|
|
|
121
121
|
</>
|
|
122
122
|
),
|
|
123
123
|
jump: P('M6 18 18 6M9 6h9v9'),
|
|
124
|
+
/** 面板最大化 / 还原(#79 底部信息面板右上角控制钮) */
|
|
125
|
+
expand: (
|
|
126
|
+
<>
|
|
127
|
+
<path d="M4.5 9V4.5H9" />
|
|
128
|
+
<path d="M15 4.5h4.5V9" />
|
|
129
|
+
<path d="M19.5 15v4.5H15" />
|
|
130
|
+
<path d="M9 19.5H4.5V15" />
|
|
131
|
+
</>
|
|
132
|
+
),
|
|
133
|
+
collapse: (
|
|
134
|
+
<>
|
|
135
|
+
<path d="M9.5 4.5v5h-5" />
|
|
136
|
+
<path d="M14.5 4.5v5h5" />
|
|
137
|
+
<path d="M19.5 14.5h-5v5" />
|
|
138
|
+
<path d="M4.5 14.5h5v5" />
|
|
139
|
+
</>
|
|
140
|
+
),
|
|
124
141
|
/** 迁回布局:外框=主布局,左竖线=停靠边,箭头=把浮窗收回去 */
|
|
125
142
|
dock: (
|
|
126
143
|
<>
|
|
@@ -41,8 +41,11 @@ export function crumbsOf(route, ctx = {}) {
|
|
|
41
41
|
return ['云端总览'];
|
|
42
42
|
case 'overview':
|
|
43
43
|
return ['全部目录总览'];
|
|
44
|
-
case 'templates':
|
|
44
|
+
case 'templates': {
|
|
45
|
+
if (route.mode === 'new') return ['新建模板'];
|
|
46
|
+
if (route.mode === 'edit') return ['编辑模板'];
|
|
45
47
|
return ['任务模板'];
|
|
48
|
+
}
|
|
46
49
|
// 文档页(#88):只画**归属**(仓库 / 项目组)——文档名已经在 DocHead 的
|
|
47
50
|
// 标题行里,面包屑再画一遍就是同一行重复两遍。
|
|
48
51
|
case 'doc': {
|
|
@@ -140,17 +140,26 @@ export default function AttachArea({
|
|
|
140
140
|
const emptyAll = !loading && !error && !list.length;
|
|
141
141
|
|
|
142
142
|
return (
|
|
143
|
-
<div
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
143
|
+
<div
|
|
144
|
+
className={`att-area${disabled ? ' is-disabled' : ''}`}
|
|
145
|
+
// 拖放落点是**整个附件区**:空态提示写着「拖文件到这里」,落点只盖头部
|
|
146
|
+
// 一条的话提示区反而是空的(md/pdf 等文件拖上去落空,触发浏览器默认打开文件)。
|
|
147
|
+
onDragOver={(e) => {
|
|
148
|
+
if (disabled || ![...(e.dataTransfer?.types || [])].includes('Files')) return;
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
setDragOver(true);
|
|
151
|
+
}}
|
|
152
|
+
onDragLeave={(e) => {
|
|
153
|
+
if (!e.currentTarget.contains(e.relatedTarget)) setDragOver(false);
|
|
154
|
+
}}
|
|
155
|
+
onDrop={(e) => {
|
|
156
|
+
setDragOver(false);
|
|
157
|
+
if (disabled || ![...(e.dataTransfer?.types || [])].includes('Files')) return;
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
dropFiles(null, e);
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
<div className={'att-area-head' + (dragOver && !disabled ? ' is-over' : '')}>
|
|
154
163
|
<span className="att-area-title">
|
|
155
164
|
附件
|
|
156
165
|
{list.length ? <span className="att-count">{list.length}</span> : null}
|
|
@@ -11,7 +11,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
11
11
|
import { Modal } from '../popup/index.jsx';
|
|
12
12
|
import { api } from '../../api/client.js';
|
|
13
13
|
import { clipboardFiles, droppedFiles, readableName, uploadOne } from '../cloud/upload.js';
|
|
14
|
-
import
|
|
14
|
+
import StatusTag from '../status-tag/index.jsx';
|
|
15
15
|
import {
|
|
16
16
|
attachBodyOf,
|
|
17
17
|
badgeOf,
|
|
@@ -317,7 +317,8 @@ export default function AttachModal({
|
|
|
317
317
|
{taskList.map((t) => (
|
|
318
318
|
<button key={t.id} type="button" className="att-pick-item" onClick={() => addTask(t)}>
|
|
319
319
|
<span className="att-pick-main">#{t.id} {taskTitleOf(t) || '(无标题)'}</span>
|
|
320
|
-
|
|
320
|
+
{/* #121 统一组件:配色由 tstat-* 接管,att-sbadge 只给尺寸 */}
|
|
321
|
+
<StatusTag t={t} className="att-sbadge" />
|
|
321
322
|
</button>
|
|
322
323
|
))}
|
|
323
324
|
</div>
|
|
@@ -27,7 +27,7 @@ import { openBesideMain } from '../../workspace.js';
|
|
|
27
27
|
* onInsert({index, embed, at, caret}):调用方做正文替换(两处编辑器口径不同:
|
|
28
28
|
* 块内替换 vs 全文替换)。
|
|
29
29
|
*/
|
|
30
|
-
export function useAttachPicker({ host, onInsert }) {
|
|
30
|
+
export function useAttachPicker({ host, itemsOverride = null, onInsert }) {
|
|
31
31
|
const [menu, setMenu] = useState(null); // {index, at, caret, x, y, query, active, loading, error}
|
|
32
32
|
const [items, setItems] = useState([]);
|
|
33
33
|
// host 是对象 prop(每次渲染新对象)——依赖用序列化后的**身份字段**(不含
|
|
@@ -38,7 +38,10 @@ export function useAttachPicker({ host, onInsert }) {
|
|
|
38
38
|
|
|
39
39
|
const load = useCallback(async () => {
|
|
40
40
|
if (!host) {
|
|
41
|
+
// 草稿没有 v2 取数描述(清单来自会话 doc 的 itemsOverride)——
|
|
42
|
+
// 但**必须**把 loading 收掉,否则面板永远停在「读取附件…」(#111 实测)。
|
|
41
43
|
setItems([]);
|
|
44
|
+
setMenu((cur) => (cur ? { ...cur, loading: false, error: '' } : cur));
|
|
42
45
|
return;
|
|
43
46
|
}
|
|
44
47
|
try {
|
|
@@ -53,7 +56,7 @@ export function useAttachPicker({ host, onInsert }) {
|
|
|
53
56
|
}, [hostKey]); // host 是对象 prop,用序列化后的 key 做依赖(每次渲染新对象)
|
|
54
57
|
|
|
55
58
|
const open = useCallback(({ index, ta, at, caret }) => {
|
|
56
|
-
if (!
|
|
59
|
+
if (!ta) return;
|
|
57
60
|
const rect = ta.getBoundingClientRect();
|
|
58
61
|
const lineH = 20;
|
|
59
62
|
const line = caretLineCol(ta.value, caret).line;
|
|
@@ -65,11 +68,12 @@ export function useAttachPicker({ host, onInsert }) {
|
|
|
65
68
|
|
|
66
69
|
const close = useCallback(() => setMenu((cur) => (cur ? null : cur)), []);
|
|
67
70
|
|
|
71
|
+
const source = itemsOverride !== undefined && itemsOverride !== null ? itemsOverride : items;
|
|
68
72
|
const filtered = useMemo(() => {
|
|
69
73
|
const q = String(menu?.query || '').trim().toLowerCase();
|
|
70
|
-
if (!q) return
|
|
71
|
-
return
|
|
72
|
-
}, [
|
|
74
|
+
if (!q) return source;
|
|
75
|
+
return source.filter((a) => String(a.name || a.title || a.locator || '').toLowerCase().includes(q));
|
|
76
|
+
}, [source, menu?.query]);
|
|
73
77
|
|
|
74
78
|
const active = filtered.length
|
|
75
79
|
? Math.min(Math.max(0, menu?.active ?? 0), filtered.length - 1)
|
|
@@ -114,9 +118,11 @@ export default function AttachPicker({
|
|
|
114
118
|
position,
|
|
115
119
|
host = null, // 取数描述(含 allow / taskOptions——「添加附件」弹窗要用)
|
|
116
120
|
onReload = null, // 添加附件成功后刷新清单
|
|
121
|
+
onAddFiles = null, // 草稿通道(无 host):文件进会话 doc 附件,插入点由调用方管
|
|
117
122
|
}) {
|
|
118
123
|
const listRef = useRef(null);
|
|
119
124
|
const inputRef = useRef(null);
|
|
125
|
+
const fileRef = useRef(null);
|
|
120
126
|
const app = useApp() || {};
|
|
121
127
|
const [addOpen, setAddOpen] = useState(false);
|
|
122
128
|
|
|
@@ -240,7 +246,7 @@ export default function AttachPicker({
|
|
|
240
246
|
<div className="mdw-atpick-foot">
|
|
241
247
|
<span className="mdw-atpick-cap">↑↓ 选择 · Enter 引用 · Esc 取消</span>
|
|
242
248
|
<span className="grow" />
|
|
243
|
-
{host
|
|
249
|
+
{host ? (
|
|
244
250
|
<button
|
|
245
251
|
type="button"
|
|
246
252
|
className="mdw-atpick-add"
|
|
@@ -250,8 +256,32 @@ export default function AttachPicker({
|
|
|
250
256
|
>
|
|
251
257
|
+ 添加附件
|
|
252
258
|
</button>
|
|
253
|
-
)
|
|
259
|
+
) : onAddFiles ? (
|
|
260
|
+
<button
|
|
261
|
+
type="button"
|
|
262
|
+
className="mdw-atpick-add"
|
|
263
|
+
title="上传本机文件(草稿:先挂进会话草稿,提交任务时一并带上)"
|
|
264
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
265
|
+
onClick={() => fileRef.current?.click()}
|
|
266
|
+
>
|
|
267
|
+
+ 添加附件
|
|
268
|
+
</button>
|
|
269
|
+
) : null}
|
|
254
270
|
</div>
|
|
271
|
+
{onAddFiles && (
|
|
272
|
+
<input
|
|
273
|
+
ref={fileRef}
|
|
274
|
+
type="file"
|
|
275
|
+
multiple
|
|
276
|
+
hidden
|
|
277
|
+
onChange={(e) => {
|
|
278
|
+
// 快照成数组:FileList 是输入框的**活视图**,面板重渲染把它换掉就空了
|
|
279
|
+
const files = Array.from(e.target.files || []);
|
|
280
|
+
if (files.length) onAddFiles(files);
|
|
281
|
+
if (fileRef.current) fileRef.current.value = '';
|
|
282
|
+
}}
|
|
283
|
+
/>
|
|
284
|
+
)}
|
|
255
285
|
{host && (
|
|
256
286
|
<AttachModal
|
|
257
287
|
open={addOpen}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
forwardRef,
|
|
3
|
+
useCallback,
|
|
3
4
|
useEffect,
|
|
4
5
|
useImperativeHandle,
|
|
5
6
|
useLayoutEffect,
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
} from 'react';
|
|
10
11
|
import { createPortal } from 'react-dom';
|
|
11
12
|
import AttachPicker, { useAttachPicker } from './attach-picker.jsx';
|
|
12
|
-
import { atTriggerAt } from '../../modules/md/attach-mention.js';
|
|
13
|
+
import { atTriggerAt, padEmbed } from '../../modules/md/attach-mention.js';
|
|
13
14
|
import {
|
|
14
15
|
isFrontmatterBlock,
|
|
15
16
|
isEmptyBlock,
|
|
@@ -26,7 +27,7 @@ import {
|
|
|
26
27
|
diffIndex,
|
|
27
28
|
filterSlashCmds,
|
|
28
29
|
findMatches,
|
|
29
|
-
|
|
30
|
+
filesFromDataTransfer,
|
|
30
31
|
indentLines,
|
|
31
32
|
insertTextAtCursor,
|
|
32
33
|
isBareListItemLine,
|
|
@@ -63,7 +64,11 @@ function autoSize(el) {
|
|
|
63
64
|
function blockHtml(text, attachments) {
|
|
64
65
|
const raw = normalizeBlockText(text);
|
|
65
66
|
if (!raw.trim()) return '';
|
|
66
|
-
|
|
67
|
+
// 只传**图片**(v1 草稿按名字内嵌的 imgMap 只认图片):文件附件不能整表
|
|
68
|
+
// 下发——本函数是**逐块**调用的,renderMarkdownHtml 会把文件附件拼成 chip
|
|
69
|
+
// 附在每个块末尾,拖一个 md 进来就是「每一行都显示」(#118)。
|
|
70
|
+
const imgs = (attachments || []).filter((a) => a?.type === 'image');
|
|
71
|
+
return renderMarkdownHtml(raw, imgs).replace(
|
|
67
72
|
/<p class="mdw-empty">[\s\S]*?<\/p>/g,
|
|
68
73
|
''
|
|
69
74
|
);
|
|
@@ -102,7 +107,9 @@ function LiveBlock({
|
|
|
102
107
|
}) {
|
|
103
108
|
const taRef = useRef(null);
|
|
104
109
|
const display = normalizeBlockText(text);
|
|
105
|
-
|
|
110
|
+
// frontmatter 块在视图态**渲染为空**(#113:属性卡已撤,元数据不占正文位;
|
|
111
|
+
// 也不显示「(空文档)」占位——点它仍能进编辑态看原 YAML)。
|
|
112
|
+
const html = isFrontmatterBlock(display) ? '' : blockHtml(display, attachments);
|
|
106
113
|
const kind = blockKind(display);
|
|
107
114
|
|
|
108
115
|
useLayoutEffect(() => {
|
|
@@ -152,7 +159,7 @@ function LiveBlock({
|
|
|
152
159
|
onBlur={onBlur}
|
|
153
160
|
onKeyDown={onKeyDown}
|
|
154
161
|
onPaste={(e) => {
|
|
155
|
-
const files =
|
|
162
|
+
const files = filesFromDataTransfer(e.clipboardData);
|
|
156
163
|
if (!files.length) return;
|
|
157
164
|
e.preventDefault();
|
|
158
165
|
onPasteFiles?.(files, taRef.current);
|
|
@@ -471,18 +478,48 @@ function LivePreview({
|
|
|
471
478
|
if (next) applyBlockOp(idx, next);
|
|
472
479
|
};
|
|
473
480
|
|
|
474
|
-
// ── @ 附件选择(#108)──
|
|
481
|
+
// ── @ 附件选择(#108/#111)──
|
|
482
|
+
// 草稿(无 v2 host)数据源 = 会话 doc 的附件(图片按名字内嵌,v1 渲染口径)
|
|
483
|
+
const draftItems = useMemo(
|
|
484
|
+
() => (attachHost ? null : (attachments || [])
|
|
485
|
+
.filter((a) => a.type === 'image')
|
|
486
|
+
// 映射成伪附件(kind/id 对齐 embedForAttachment):草稿的图片按**名字**内嵌
|
|
487
|
+
// (v1 渲染口径:imgMap[name] → dataURL),所以 id 就是名字。
|
|
488
|
+
.map((a) => ({ kind: 'image', id: a.name, name: a.name, sizeText: a.size }))),
|
|
489
|
+
[attachHost, attachments]
|
|
490
|
+
);
|
|
475
491
|
const picker = useAttachPicker({
|
|
476
492
|
host: attachHost,
|
|
493
|
+
itemsOverride: attachHost ? null : draftItems,
|
|
477
494
|
onInsert: ({ index, embed, at, caret }) => {
|
|
478
|
-
// 块内替换:把 '@'
|
|
495
|
+
// 块内替换:把 '@' 那一段换成引用语法,光标落在引用之后;
|
|
496
|
+
// 引用与正文**前后隔一空**(#111:贴着中文会黏连,行内元素需要边界)
|
|
479
497
|
const val = normalizeBlockText(blocks[index] ?? '');
|
|
480
|
-
const
|
|
498
|
+
const padded = padEmbed(embed, at > 0 ? val[at - 1] : '', val[caret] || '');
|
|
499
|
+
const next = val.slice(0, at) + padded.text + val.slice(caret);
|
|
500
|
+
const caretAt = at + padded.caretAt;
|
|
481
501
|
updateAt(index, next);
|
|
482
|
-
pendingSelRef.current = { index, start:
|
|
502
|
+
pendingSelRef.current = { index, start: caretAt, end: caretAt };
|
|
483
503
|
setFocus(index);
|
|
484
504
|
},
|
|
485
505
|
});
|
|
506
|
+
// 草稿「+ 添加附件」:文件走页面附件通道(粘贴同款——传会话 doc 并在插入点
|
|
507
|
+
// 落片段);@ 占位字符先清掉,插入点用 '@' 原位置。
|
|
508
|
+
const onDraftAddFiles = (files) => {
|
|
509
|
+
const m = picker.menu;
|
|
510
|
+
const pos = m ? { index: m.index, at: m.at, caret: m.caret } : { index: focus ?? 0, at: null, caret: null };
|
|
511
|
+
if (m) {
|
|
512
|
+
const val = normalizeBlockText(blocks[m.index] ?? '');
|
|
513
|
+
updateAt(m.index, val.slice(0, m.at) + val.slice(m.caret));
|
|
514
|
+
}
|
|
515
|
+
requestAnimationFrame(() => {
|
|
516
|
+
onFiles?.(files, {
|
|
517
|
+
mode: 'live',
|
|
518
|
+
focusIndex: pos.index,
|
|
519
|
+
...(pos.at != null ? { caretInBlock: pos.at } : {}),
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
};
|
|
486
523
|
|
|
487
524
|
const applyTurn = (index, turnId) => {
|
|
488
525
|
const ta = liveTaRef.current;
|
|
@@ -496,6 +533,27 @@ function LivePreview({
|
|
|
496
533
|
}
|
|
497
534
|
};
|
|
498
535
|
|
|
536
|
+
// ── 跨块选区(#124):块粒度的「统一删除」────────────────────────────
|
|
537
|
+
// 视图块是渲染好的 HTML,选区字符偏移无法精确映射回各块源码(markdown
|
|
538
|
+
// 标记在渲染时被剥掉)——沿用本编辑器一贯的保守口径(#98 同源):**升到
|
|
539
|
+
// 块级映射**。选区两端落在不同视图块上 → 触到的整段块 [lo, hi] 就是操作
|
|
540
|
+
// 单元:删除 = 整段移除(浮层按钮与 Backspace/Delete 走同一实现);
|
|
541
|
+
// 复制 = 整段源码(task.jsx 侧拼好入剪贴板)。单块内选区仍是 #98 的
|
|
542
|
+
// 字符级 indexOf 映射,行为不变。
|
|
543
|
+
const removeBlockRange = useCallback((lo, hi) => {
|
|
544
|
+
if (!Number.isInteger(lo) || !Number.isInteger(hi)) return false;
|
|
545
|
+
if (lo < 0 || hi < lo || hi >= blocks.length) return false;
|
|
546
|
+
const next = blocks.slice();
|
|
547
|
+
next.splice(lo, hi - lo + 1);
|
|
548
|
+
commit(next);
|
|
549
|
+
// 删完落焦到接缝块(原 lo 位置,越界夹回末块),光标在块首——与单块
|
|
550
|
+
// 删除的落点语义一致(删完可以接着打字);op 走历史栈,Ctrl+Z 可撤销。
|
|
551
|
+
const fi = Math.min(lo, Math.max(0, next.length - 1));
|
|
552
|
+
pendingSelRef.current = { index: fi, start: 0, end: 0 };
|
|
553
|
+
setFocus(fi);
|
|
554
|
+
return true;
|
|
555
|
+
}, [blocks, onBody]);
|
|
556
|
+
|
|
499
557
|
useImperativeHandle(editorApiRef, () => ({
|
|
500
558
|
format(op) {
|
|
501
559
|
const ta = liveTaRef.current;
|
|
@@ -535,6 +593,10 @@ function LivePreview({
|
|
|
535
593
|
setFocus(i);
|
|
536
594
|
return true;
|
|
537
595
|
},
|
|
596
|
+
/** 跨块选区的浮层「删除选区」(#124):整段移除 [lo, hi] 块(含端点) */
|
|
597
|
+
deleteBlockRange(lo, hi) {
|
|
598
|
+
return removeBlockRange(lo, hi);
|
|
599
|
+
},
|
|
538
600
|
/** 撤销/重做后把光标放回改动处:把正文偏移换算到具体块与块内偏移 */
|
|
539
601
|
caretFromDiff(prev, next) {
|
|
540
602
|
const prevJ = joinMdBlocks(bodyBlocksOnly(prev));
|
|
@@ -561,7 +623,7 @@ function LivePreview({
|
|
|
561
623
|
start = end + 2;
|
|
562
624
|
}
|
|
563
625
|
},
|
|
564
|
-
}), [focus, onBody, blocks]);
|
|
626
|
+
}), [focus, onBody, blocks, removeBlockRange]);
|
|
565
627
|
|
|
566
628
|
// document 捕获:即使焦点异常也能 ↑↓
|
|
567
629
|
useEffect(() => {
|
|
@@ -580,8 +642,9 @@ function LivePreview({
|
|
|
580
642
|
// document 捕获:预览态划选后按 Backspace/Delete —— 把选中文字删掉(#98)。
|
|
581
643
|
// 视图块是渲染好的 HTML,选区落在不可编辑内容上,浏览器默认对 Backspace
|
|
582
644
|
// 无动于衷(编辑态 textarea 原生行为本来就对,这里只补视图态这一块)。
|
|
583
|
-
//
|
|
584
|
-
//
|
|
645
|
+
// 单块选区按字符级映射(选区文本在块源码里 indexOf 定位;跨 markdown 标记
|
|
646
|
+
// 时 indexOf 不中 → 保守放弃,不做错位改写);跨块选区升到块级(#124,
|
|
647
|
+
// removeBlockRange:触到的整段块全移除)。
|
|
585
648
|
// 删除后进编辑态、光标落接缝(op 走历史栈,Ctrl+Z 可撤)。
|
|
586
649
|
useEffect(() => {
|
|
587
650
|
const onKey = (e) => {
|
|
@@ -594,15 +657,27 @@ function LivePreview({
|
|
|
594
657
|
if (!sel || sel.isCollapsed || sel.rangeCount === 0) return;
|
|
595
658
|
const text = String(sel.toString() || '');
|
|
596
659
|
if (!text.trim()) return;
|
|
597
|
-
const
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const i = Number(blockEl.getAttribute('data-i'));
|
|
660
|
+
const elOf = (n) => (n?.nodeType === 3 ? n.parentElement : n);
|
|
661
|
+
const blockA = elOf(sel.anchorNode)?.closest?.('.mdw-lp-block');
|
|
662
|
+
if (!blockA || !articleRef.current?.contains(blockA)) return;
|
|
663
|
+
const i = Number(blockA.getAttribute('data-i'));
|
|
602
664
|
if (!Number.isInteger(i) || i < 0 || i >= blocks.length) return;
|
|
665
|
+
// 跨块选区(#124):两端落在不同视图块 → 块粒度统一删除。字符级映射
|
|
666
|
+
// 跨块做不到(渲染 HTML 的选区偏移映射不回源码),按 #98 的保守口径
|
|
667
|
+
// 升到块级;浮层上的「删除选区」按钮走同一实现(editorApi.deleteBlockRange)。
|
|
668
|
+
const blockF = elOf(sel.focusNode)?.closest?.('.mdw-lp-block');
|
|
669
|
+
if (blockF && blockF !== blockA && articleRef.current?.contains(blockF)) {
|
|
670
|
+
const iff = Number(blockF.getAttribute('data-i'));
|
|
671
|
+
if (Number.isInteger(iff) && iff >= 0 && iff < blocks.length && iff !== i) {
|
|
672
|
+
e.preventDefault();
|
|
673
|
+
removeBlockRange(Math.min(i, iff), Math.max(i, iff));
|
|
674
|
+
onCloseSelMenu?.();
|
|
675
|
+
}
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
603
678
|
const raw = normalizeBlockText(blocks[i] ?? '');
|
|
604
679
|
const pos = raw.indexOf(text);
|
|
605
|
-
if (pos === -1) return; //
|
|
680
|
+
if (pos === -1) return; // 跨标记:保守放弃,不删
|
|
606
681
|
e.preventDefault();
|
|
607
682
|
updateAt(i, raw.slice(0, pos) + raw.slice(pos + text.length));
|
|
608
683
|
pendingSelRef.current = { index: i, start: pos, end: pos };
|
|
@@ -611,7 +686,7 @@ function LivePreview({
|
|
|
611
686
|
};
|
|
612
687
|
document.addEventListener('keydown', onKey, true);
|
|
613
688
|
return () => document.removeEventListener('keydown', onKey, true);
|
|
614
|
-
}, [blocks, onBody, articleRef, onCloseSelMenu]);
|
|
689
|
+
}, [blocks, onBody, articleRef, onCloseSelMenu, removeBlockRange]);
|
|
615
690
|
|
|
616
691
|
const onKeyDown = (i, e) => {
|
|
617
692
|
const val = normalizeBlockText(blocks[i] ?? '');
|
|
@@ -877,7 +952,7 @@ function LivePreview({
|
|
|
877
952
|
}}
|
|
878
953
|
onDrop={(e) => {
|
|
879
954
|
setDragging(false);
|
|
880
|
-
const files =
|
|
955
|
+
const files = filesFromDataTransfer(e.dataTransfer);
|
|
881
956
|
if (!files.length) return;
|
|
882
957
|
e.preventDefault();
|
|
883
958
|
ingestFiles(files, null);
|
|
@@ -1005,6 +1080,7 @@ function LivePreview({
|
|
|
1005
1080
|
position={{ left: picker.menu.x, top: picker.menu.y }}
|
|
1006
1081
|
host={attachHost}
|
|
1007
1082
|
onReload={picker.reload}
|
|
1083
|
+
onAddFiles={attachHost ? null : onDraftAddFiles}
|
|
1008
1084
|
/>,
|
|
1009
1085
|
document.body
|
|
1010
1086
|
)}
|
|
@@ -1302,7 +1378,10 @@ function SourceEditor({ title, body, onTitle, onBody, editorApiRef, onFiles, onT
|
|
|
1302
1378
|
}}
|
|
1303
1379
|
onDrop={(e) => {
|
|
1304
1380
|
setDragging(false);
|
|
1305
|
-
|
|
1381
|
+
// textarea 自己的 onDrop 已 ingest 过(preventDefault 后事件才冒泡到
|
|
1382
|
+
// 这里)——不查 defaultPrevented 一次拖放会传两遍、传两份附件(#118)。
|
|
1383
|
+
if (e.defaultPrevented) return;
|
|
1384
|
+
const files = filesFromDataTransfer(e.dataTransfer);
|
|
1306
1385
|
if (!files.length) return;
|
|
1307
1386
|
e.preventDefault();
|
|
1308
1387
|
ingestImages(files);
|
|
@@ -1367,14 +1446,14 @@ function SourceEditor({ title, body, onTitle, onBody, editorApiRef, onFiles, onT
|
|
|
1367
1446
|
onSelect={syncCaret}
|
|
1368
1447
|
onScroll={syncGutter}
|
|
1369
1448
|
onPaste={(e) => {
|
|
1370
|
-
const files =
|
|
1449
|
+
const files = filesFromDataTransfer(e.clipboardData);
|
|
1371
1450
|
if (!files.length) return;
|
|
1372
1451
|
e.preventDefault();
|
|
1373
1452
|
ingestImages(files);
|
|
1374
1453
|
}}
|
|
1375
1454
|
onDrop={(e) => {
|
|
1376
1455
|
// 拖文件进来 = 与粘贴同一通道(实时预览态已有拖放,源码态补齐对等能力)
|
|
1377
|
-
const files =
|
|
1456
|
+
const files = filesFromDataTransfer(e.dataTransfer);
|
|
1378
1457
|
if (!files.length) return;
|
|
1379
1458
|
e.preventDefault();
|
|
1380
1459
|
ingestImages(files);
|
|
@@ -19,6 +19,7 @@ export default function SelMenu({
|
|
|
19
19
|
onFormat,
|
|
20
20
|
onCopy,
|
|
21
21
|
onCompose,
|
|
22
|
+
onDelete,
|
|
22
23
|
}) {
|
|
23
24
|
if (!at) return null;
|
|
24
25
|
const kind = at.kind || 'task';
|
|
@@ -70,6 +71,16 @@ export default function SelMenu({
|
|
|
70
71
|
</button>
|
|
71
72
|
<div className="sep" />
|
|
72
73
|
<button type="button" onClick={onCopy}>复制选区</button>
|
|
74
|
+
{/* 跨块选区才有「删除选区」(#124):块粒度整段移除;单块选区维持
|
|
75
|
+
原菜单(字符级删除走 Backspace,#98),不给误删整块的机会 */}
|
|
76
|
+
{onDelete ? (
|
|
77
|
+
<>
|
|
78
|
+
<div className="sep" />
|
|
79
|
+
<button type="button" className="danger" title="删除选区触到的整段块" onClick={onDelete}>
|
|
80
|
+
删除选区
|
|
81
|
+
</button>
|
|
82
|
+
</>
|
|
83
|
+
) : null}
|
|
73
84
|
</>
|
|
74
85
|
)}
|
|
75
86
|
</div>
|