@tnotesjs/core 0.6.0 → 0.7.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/config/templates.ts +0 -5
- package/dist/{chunk-IHFUHB4J.cjs → chunk-7FEANCT6.cjs} +17 -8
- package/dist/chunk-AGVER5MX.cjs +1746 -0
- package/dist/{chunk-TJ4527KA.cjs → chunk-BL22KD4V.cjs} +324 -950
- package/dist/{chunk-UNFSW5C2.js → chunk-GWG75A5M.js} +14 -5
- package/dist/{chunk-DUTS75WQ.js → chunk-XNO3PCEH.js} +374 -1000
- package/dist/chunk-ZEQS64PE.js +1746 -0
- package/dist/cli/index.cjs +76 -155
- package/dist/cli/index.js +10 -89
- package/dist/markdown/index.cjs +2 -3
- package/dist/markdown/index.d.cts +1 -1
- package/dist/markdown/index.d.ts +1 -1
- package/dist/markdown/index.js +1 -2
- package/dist/{types-CwBWwNVv.d.ts → types-C_d0fFeD.d.ts} +8 -1
- package/dist/{types-CpsEy8lA.d.cts → types-MRBGgJTX.d.cts} +8 -1
- package/dist/vitepress/config/index.cjs +200 -132
- package/dist/vitepress/config/index.js +187 -119
- package/dist/workspace/index.cjs +4 -1202
- package/dist/workspace/index.d.cts +2 -2
- package/dist/workspace/index.d.ts +2 -2
- package/dist/workspace/index.js +4 -1202
- package/package.json +2 -2
- package/services/file-watcher/folderChangeHandler.ts +19 -15
- package/services/file-watcher/globalUpdateCoordinator.ts +21 -27
- package/services/file-watcher/service.ts +1 -6
- package/services/index.ts +0 -1
- package/services/note/service.ts +4 -6
- package/services/readme/service.ts +11 -18
- package/services/reconcileToc.ts +20 -0
- package/utils/index.ts +0 -9
- package/{services/toc → utils}/moveTocInside.test.ts +1 -1
- package/vitepress/components/constants.ts +2 -2
- package/vitepress/components/sidebar.data.ts +8 -5
- package/vitepress/plugins/sidebarStructurePlugin.ts +242 -145
- package/dist/chunk-3R7QSABB.cjs +0 -502
- package/dist/chunk-CZXRQPFJ.js +0 -11
- package/dist/chunk-HXED7KVT.cjs +0 -11
- package/dist/chunk-U6IBLREL.js +0 -502
- package/services/toc/index.ts +0 -5
- package/services/toc/service.ts +0 -759
- package/utils/migrateReadmeToToc.test.ts +0 -111
- package/utils/migrateReadmeToToc.ts +0 -135
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
var _chunkTJ4527KAcjs = require('../../chunk-TJ4527KA.cjs');
|
|
8
|
+
var _chunkBL22KD4Vcjs = require('../../chunk-BL22KD4V.cjs');
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
var _chunkMZIXIY2Ycjs = require('../../chunk-MZIXIY2Y.cjs');
|
|
13
|
-
require('../../chunk-3R7QSABB.cjs');
|
|
14
12
|
|
|
15
13
|
|
|
16
|
-
var
|
|
14
|
+
var _chunkAGVER5MXcjs = require('../../chunk-AGVER5MX.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunk7FEANCT6cjs = require('../../chunk-7FEANCT6.cjs');
|
|
17
18
|
|
|
18
19
|
// vitepress/config/index.ts
|
|
19
20
|
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
@@ -267,7 +268,7 @@ function getMarkdownConfig() {
|
|
|
267
268
|
configureSwiperContainer(md);
|
|
268
269
|
},
|
|
269
270
|
anchor: {
|
|
270
|
-
slugify:
|
|
271
|
+
slugify: _chunk7FEANCT6cjs.generateAnchor
|
|
271
272
|
},
|
|
272
273
|
image: {
|
|
273
274
|
lazyLoading: true
|
|
@@ -688,7 +689,7 @@ function getNoteByConfigIdPlugin() {
|
|
|
688
689
|
);
|
|
689
690
|
return;
|
|
690
691
|
}
|
|
691
|
-
const noteIndexCache =
|
|
692
|
+
const noteIndexCache = _chunkBL22KD4Vcjs.NoteIndexCache.getInstance();
|
|
692
693
|
if (!noteIndexCache.isInitialized()) {
|
|
693
694
|
res.statusCode = 503;
|
|
694
695
|
res.setHeader("Content-Type", "application/json");
|
|
@@ -729,11 +730,11 @@ function getNoteByConfigIdPlugin() {
|
|
|
729
730
|
}
|
|
730
731
|
})
|
|
731
732
|
);
|
|
732
|
-
|
|
733
|
+
_chunkBL22KD4Vcjs.logger.debug(
|
|
733
734
|
`\u67E5\u8BE2\u7B14\u8BB0: configId=${configId}, noteIndex=${noteItem.noteIndex}`
|
|
734
735
|
);
|
|
735
736
|
} catch (error) {
|
|
736
|
-
|
|
737
|
+
_chunkBL22KD4Vcjs.logger.error("\u67E5\u8BE2\u7B14\u8BB0\u5931\u8D25:", error);
|
|
737
738
|
res.statusCode = 500;
|
|
738
739
|
res.setHeader("Content-Type", "application/json");
|
|
739
740
|
res.end(
|
|
@@ -1172,7 +1173,7 @@ function localSearchReindexPlugin() {
|
|
|
1172
1173
|
|
|
1173
1174
|
// vitepress/plugins/renameNotePlugin.ts
|
|
1174
1175
|
function renameNotePlugin() {
|
|
1175
|
-
const renameCommand = new (0,
|
|
1176
|
+
const renameCommand = new (0, _chunkBL22KD4Vcjs.RenameNoteCommand)();
|
|
1176
1177
|
return {
|
|
1177
1178
|
name: "tnotes-rename-note",
|
|
1178
1179
|
configureServer(server) {
|
|
@@ -1249,24 +1250,11 @@ function normalizeCount(value) {
|
|
|
1249
1250
|
}
|
|
1250
1251
|
return count;
|
|
1251
1252
|
}
|
|
1252
|
-
function
|
|
1253
|
-
return notes
|
|
1254
|
-
index: note.index,
|
|
1255
|
-
dirName: note.dirName,
|
|
1256
|
-
link: `/notes/${encodeURIComponent(note.dirName)}/README`
|
|
1257
|
-
}));
|
|
1258
|
-
}
|
|
1259
|
-
function buildNoteReadmeLink(note) {
|
|
1260
|
-
return `/notes/${encodeURIComponent(note.dirName)}/README`;
|
|
1261
|
-
}
|
|
1262
|
-
function resolveDeleteRedirectUrl(noteService, previousNoteIndex) {
|
|
1263
|
-
if (!previousNoteIndex) return "/";
|
|
1264
|
-
const previousNote = noteService.getNoteByIndex(previousNoteIndex);
|
|
1265
|
-
if (!previousNote) return "/";
|
|
1266
|
-
return buildNoteReadmeLink(previousNote);
|
|
1253
|
+
function buildNoteReadmeLink(dirName) {
|
|
1254
|
+
return `/notes/${encodeURIComponent(dirName)}/README`;
|
|
1267
1255
|
}
|
|
1268
1256
|
async function withSuspendedWatcher(task) {
|
|
1269
|
-
const watcher =
|
|
1257
|
+
const watcher = _chunkBL22KD4Vcjs.FileWatcherService.getInstance();
|
|
1270
1258
|
try {
|
|
1271
1259
|
_optionalChain([watcher, 'optionalAccess', _35 => _35.suspend, 'call', _36 => _36()]);
|
|
1272
1260
|
return await task();
|
|
@@ -1274,33 +1262,78 @@ async function withSuspendedWatcher(task) {
|
|
|
1274
1262
|
_optionalChain([watcher, 'optionalAccess', _37 => _37.unsuspend, 'call', _38 => _38()]);
|
|
1275
1263
|
}
|
|
1276
1264
|
}
|
|
1277
|
-
function
|
|
1278
|
-
const
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
const
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
usedIndexes.add(index);
|
|
1265
|
+
function collectRefs(snapshot) {
|
|
1266
|
+
const byLine = /* @__PURE__ */ new Map();
|
|
1267
|
+
const orderedIndexes = [];
|
|
1268
|
+
let order = 0;
|
|
1269
|
+
const walk = (nodes) => {
|
|
1270
|
+
for (const node of nodes) {
|
|
1271
|
+
if (node.kind === "folder") {
|
|
1272
|
+
walk(node.children);
|
|
1273
|
+
continue;
|
|
1287
1274
|
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1275
|
+
const subtree = [];
|
|
1276
|
+
const collect = (n) => {
|
|
1277
|
+
if (n.kind === "note") subtree.push(n.noteIndex);
|
|
1278
|
+
for (const child of n.children) collect(child);
|
|
1279
|
+
};
|
|
1280
|
+
collect(node);
|
|
1281
|
+
byLine.set(node.tocLineIndex, {
|
|
1282
|
+
tocLineIndex: node.tocLineIndex,
|
|
1283
|
+
ref: { type: "note", noteUuid: "" },
|
|
1284
|
+
subtreeIndexes: subtree,
|
|
1285
|
+
orderIndex: order
|
|
1293
1286
|
});
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
usedIndexes.add(index);
|
|
1297
|
-
}
|
|
1298
|
-
notes.push(note);
|
|
1287
|
+
orderedIndexes.push(...subtree);
|
|
1288
|
+
order += 1;
|
|
1299
1289
|
}
|
|
1300
|
-
|
|
1290
|
+
};
|
|
1291
|
+
walk(snapshot.toc);
|
|
1292
|
+
return { byLine, orderedIndexes };
|
|
1293
|
+
}
|
|
1294
|
+
function noteUuidForIndex(snapshot, index) {
|
|
1295
|
+
const note = snapshot.notes.find((item) => item.index === index);
|
|
1296
|
+
if (!note) throw new Error(`\u672A\u627E\u5230\u7B14\u8BB0: ${index}`);
|
|
1297
|
+
return note.uuid;
|
|
1298
|
+
}
|
|
1299
|
+
function previousNoteIndex(snapshot, entry) {
|
|
1300
|
+
if (!entry) return null;
|
|
1301
|
+
const entries = [...collectRefs(snapshot).byLine.values()].sort(
|
|
1302
|
+
(a, b) => a.orderIndex - b.orderIndex
|
|
1303
|
+
);
|
|
1304
|
+
let cursor = 0;
|
|
1305
|
+
for (const item of entries) {
|
|
1306
|
+
if (item === entry) return cursor > 0 ? collectRefs(snapshot).orderedIndexes[cursor - 1] : null;
|
|
1307
|
+
cursor += item.subtreeIndexes.length;
|
|
1301
1308
|
}
|
|
1309
|
+
return null;
|
|
1310
|
+
}
|
|
1311
|
+
function isNoteInSubtree(snapshot, lineIndex, noteIndex) {
|
|
1312
|
+
const entry = collectRefs(snapshot).byLine.get(lineIndex);
|
|
1313
|
+
return entry ? entry.subtreeIndexes.includes(noteIndex) : false;
|
|
1314
|
+
}
|
|
1315
|
+
function folderPathAtLine(snapshot, lineIndex) {
|
|
1316
|
+
const result = [];
|
|
1317
|
+
const walk = (nodes, path6) => {
|
|
1318
|
+
for (const node of nodes) {
|
|
1319
|
+
if (node.kind === "folder") {
|
|
1320
|
+
if (node.tocLineIndex === lineIndex) {
|
|
1321
|
+
result.push(...[...path6, node.title]);
|
|
1322
|
+
return true;
|
|
1323
|
+
}
|
|
1324
|
+
if (walk(node.children, [...path6, node.title])) return true;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
return false;
|
|
1328
|
+
};
|
|
1329
|
+
walk(snapshot.toc, []);
|
|
1330
|
+
if (result.length === 0) throw new Error(`\u672A\u627E\u5230\u76EE\u5F55\u884C: ${lineIndex}`);
|
|
1331
|
+
return result;
|
|
1332
|
+
}
|
|
1333
|
+
function sidebarStructurePlugin() {
|
|
1334
|
+
const workspace = _chunkAGVER5MXcjs.createWorkspace.call(void 0, { rootPath: _chunkBL22KD4Vcjs.ROOT_DIR_PATH });
|
|
1302
1335
|
async function refreshTocAndSidebar() {
|
|
1303
|
-
await
|
|
1336
|
+
await workspace.toc.reconcileFromFiles();
|
|
1304
1337
|
}
|
|
1305
1338
|
return {
|
|
1306
1339
|
name: "tnotes-sidebar-structure",
|
|
@@ -1327,22 +1360,27 @@ function sidebarStructurePlugin() {
|
|
|
1327
1360
|
try {
|
|
1328
1361
|
const data = await readJsonBody(req);
|
|
1329
1362
|
const result = await withSuspendedWatcher(async () => {
|
|
1363
|
+
const snapshot = await workspace.inspect();
|
|
1330
1364
|
if (pathname === "/__tnotes_sidebar_delete_note") {
|
|
1331
1365
|
const noteIndex = String(data.noteIndex || "");
|
|
1332
1366
|
if (!noteIndex) throw new Error("Missing noteIndex");
|
|
1333
|
-
const
|
|
1334
|
-
|
|
1335
|
-
|
|
1367
|
+
const refs = collectRefs(snapshot);
|
|
1368
|
+
const deletedRef = [...refs.byLine.values()].find(
|
|
1369
|
+
(item) => item.subtreeIndexes.includes(noteIndex)
|
|
1370
|
+
);
|
|
1371
|
+
const previous = previousNoteIndex(snapshot, deletedRef);
|
|
1372
|
+
await workspace.toc.deleteEntry({
|
|
1373
|
+
entry: { type: "note", noteUuid: noteUuidForIndex(snapshot, noteIndex) },
|
|
1374
|
+
expectedSnapshotRevision: snapshot.revision
|
|
1375
|
+
});
|
|
1336
1376
|
await refreshTocAndSidebar();
|
|
1337
1377
|
scheduleNoteSearchReindex("api:delete-note");
|
|
1378
|
+
const redirectDir = previous ? _optionalChain([snapshot, 'access', _39 => _39.notes, 'access', _40 => _40.find, 'call', _41 => _41((item) => item.index === previous), 'optionalAccess', _42 => _42.dirName]) : void 0;
|
|
1338
1379
|
return {
|
|
1339
1380
|
success: true,
|
|
1340
1381
|
sidebarChanged: true,
|
|
1341
|
-
redirectUrl:
|
|
1342
|
-
|
|
1343
|
-
previousNoteIndex
|
|
1344
|
-
),
|
|
1345
|
-
redirectNoteIndex: previousNoteIndex,
|
|
1382
|
+
redirectUrl: redirectDir ? buildNoteReadmeLink(redirectDir) : "/",
|
|
1383
|
+
redirectNoteIndex: previous,
|
|
1346
1384
|
deletedNoteIndexes: [noteIndex],
|
|
1347
1385
|
message: "\u7B14\u8BB0\u5DF2\u5220\u9664"
|
|
1348
1386
|
};
|
|
@@ -1353,22 +1391,26 @@ function sidebarStructurePlugin() {
|
|
|
1353
1391
|
throw new Error("Missing tocLineIndex");
|
|
1354
1392
|
}
|
|
1355
1393
|
const currentNoteIndex = String(data.currentNoteIndex || "");
|
|
1356
|
-
const
|
|
1394
|
+
const inSubtree = currentNoteIndex ? isNoteInSubtree(snapshot, tocLineIndex, currentNoteIndex) : false;
|
|
1395
|
+
const entry = collectRefs(snapshot).byLine.get(tocLineIndex);
|
|
1396
|
+
const previous = previousNoteIndex(snapshot, entry);
|
|
1397
|
+
const preview = await workspace.toc.previewDelete({
|
|
1398
|
+
type: "line",
|
|
1357
1399
|
tocLineIndex
|
|
1358
|
-
);
|
|
1359
|
-
|
|
1360
|
-
tocLineIndex,
|
|
1361
|
-
|
|
1362
|
-
);
|
|
1363
|
-
const deletedNoteIndexes = await tocService.deleteTocEntryCascade(tocLineIndex);
|
|
1400
|
+
});
|
|
1401
|
+
await workspace.toc.deleteEntry({
|
|
1402
|
+
entry: { type: "line", tocLineIndex },
|
|
1403
|
+
expectedSnapshotRevision: snapshot.revision
|
|
1404
|
+
});
|
|
1364
1405
|
await refreshTocAndSidebar();
|
|
1365
1406
|
scheduleNoteSearchReindex("api:delete-entry");
|
|
1407
|
+
const redirectDir = inSubtree && previous ? _optionalChain([snapshot, 'access', _43 => _43.notes, 'access', _44 => _44.find, 'call', _45 => _45((item) => item.index === previous), 'optionalAccess', _46 => _46.dirName]) : void 0;
|
|
1366
1408
|
return {
|
|
1367
1409
|
success: true,
|
|
1368
1410
|
sidebarChanged: true,
|
|
1369
|
-
redirectUrl:
|
|
1370
|
-
redirectNoteIndex: inSubtree ?
|
|
1371
|
-
deletedNoteIndexes,
|
|
1411
|
+
redirectUrl: redirectDir ? buildNoteReadmeLink(redirectDir) : void 0,
|
|
1412
|
+
redirectNoteIndex: inSubtree ? previous : null,
|
|
1413
|
+
deletedNoteIndexes: preview.notes.map((note) => note.index),
|
|
1372
1414
|
message: "\u5DF2\u5220\u9664"
|
|
1373
1415
|
};
|
|
1374
1416
|
}
|
|
@@ -1378,7 +1420,11 @@ function sidebarStructurePlugin() {
|
|
|
1378
1420
|
if (!Number.isInteger(tocLineIndex) || tocLineIndex < 0) {
|
|
1379
1421
|
throw new Error("Missing tocLineIndex");
|
|
1380
1422
|
}
|
|
1381
|
-
await
|
|
1423
|
+
await workspace.toc.renameGroup({
|
|
1424
|
+
folderPath: folderPathAtLine(snapshot, tocLineIndex),
|
|
1425
|
+
title: newTitle,
|
|
1426
|
+
expectedSnapshotRevision: snapshot.revision
|
|
1427
|
+
});
|
|
1382
1428
|
await refreshTocAndSidebar();
|
|
1383
1429
|
return {
|
|
1384
1430
|
success: true,
|
|
@@ -1387,8 +1433,20 @@ function sidebarStructurePlugin() {
|
|
|
1387
1433
|
};
|
|
1388
1434
|
}
|
|
1389
1435
|
if (pathname === "/__tnotes_sidebar_reorder") {
|
|
1390
|
-
|
|
1391
|
-
await
|
|
1436
|
+
const awaitMove = async (source2, target, placement2) => {
|
|
1437
|
+
await workspace.toc.move({
|
|
1438
|
+
source: source2,
|
|
1439
|
+
target,
|
|
1440
|
+
placement: placement2,
|
|
1441
|
+
expectedSnapshotRevision: snapshot.revision
|
|
1442
|
+
});
|
|
1443
|
+
};
|
|
1444
|
+
if (typeof data.node_uuid === "string" && data.action === "prependChild" && !data.target_uuid) {
|
|
1445
|
+
await awaitMove(
|
|
1446
|
+
{ type: "note", noteUuid: data.node_uuid },
|
|
1447
|
+
{ type: "line", tocLineIndex: 0 },
|
|
1448
|
+
data.placement === "after" ? "after" : "before"
|
|
1449
|
+
);
|
|
1392
1450
|
await refreshTocAndSidebar();
|
|
1393
1451
|
return {
|
|
1394
1452
|
success: true,
|
|
@@ -1396,18 +1454,12 @@ function sidebarStructurePlugin() {
|
|
|
1396
1454
|
message: "\u6392\u5E8F\u5DF2\u66F4\u65B0"
|
|
1397
1455
|
};
|
|
1398
1456
|
}
|
|
1399
|
-
if (data.node_uuid && data.target_uuid && (data.action === "moveAfter" || data.action === "prependChild")) {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
} else {
|
|
1406
|
-
await tocService.prependChildByNodeId(
|
|
1407
|
-
String(data.node_uuid),
|
|
1408
|
-
String(data.target_uuid)
|
|
1409
|
-
);
|
|
1410
|
-
}
|
|
1457
|
+
if (typeof data.node_uuid === "string" && typeof data.target_uuid === "string" && (data.action === "moveAfter" || data.action === "prependChild")) {
|
|
1458
|
+
await awaitMove(
|
|
1459
|
+
{ type: "note", noteUuid: data.node_uuid },
|
|
1460
|
+
{ type: "note", noteUuid: data.target_uuid },
|
|
1461
|
+
data.action === "prependChild" ? "inside" : "after"
|
|
1462
|
+
);
|
|
1411
1463
|
await refreshTocAndSidebar();
|
|
1412
1464
|
return {
|
|
1413
1465
|
success: true,
|
|
@@ -1420,27 +1472,32 @@ function sidebarStructurePlugin() {
|
|
|
1420
1472
|
throw new Error("Missing dragTocLineIndex");
|
|
1421
1473
|
}
|
|
1422
1474
|
const placement = data.targetType === "group" || data.placement === "inside" ? "inside" : data.placement === "after" ? "after" : "before";
|
|
1475
|
+
const source = { type: "line", tocLineIndex: dragTocLineIndex };
|
|
1423
1476
|
if (data.targetTocLineIndex !== void 0 && data.targetTocLineIndex !== null) {
|
|
1424
|
-
await
|
|
1425
|
-
|
|
1477
|
+
await awaitMove(
|
|
1478
|
+
source,
|
|
1479
|
+
{ type: "line", tocLineIndex: Number(data.targetTocLineIndex) },
|
|
1426
1480
|
placement
|
|
1427
|
-
|
|
1481
|
+
);
|
|
1428
1482
|
} else if (Array.isArray(data.targetFolderPath) && data.targetFolderPath.length > 0) {
|
|
1429
|
-
await
|
|
1430
|
-
|
|
1431
|
-
|
|
1483
|
+
await awaitMove(
|
|
1484
|
+
source,
|
|
1485
|
+
{
|
|
1486
|
+
type: "folder",
|
|
1487
|
+
folderPath: data.targetFolderPath.map(String)
|
|
1488
|
+
},
|
|
1432
1489
|
placement
|
|
1433
|
-
|
|
1490
|
+
);
|
|
1434
1491
|
} else {
|
|
1435
|
-
const
|
|
1492
|
+
const targetNoteIndex2 = String(
|
|
1436
1493
|
data.targetNoteIndex || data.targetGroupNoteIndex || ""
|
|
1437
1494
|
);
|
|
1438
|
-
if (!
|
|
1439
|
-
await
|
|
1440
|
-
|
|
1441
|
-
|
|
1495
|
+
if (!targetNoteIndex2) throw new Error("Missing targetNoteIndex");
|
|
1496
|
+
await awaitMove(
|
|
1497
|
+
source,
|
|
1498
|
+
{ type: "note", noteUuid: noteUuidForIndex(snapshot, targetNoteIndex2) },
|
|
1442
1499
|
placement
|
|
1443
|
-
|
|
1500
|
+
);
|
|
1444
1501
|
}
|
|
1445
1502
|
await refreshTocAndSidebar();
|
|
1446
1503
|
return {
|
|
@@ -1455,10 +1512,13 @@ function sidebarStructurePlugin() {
|
|
|
1455
1512
|
if (!Number.isInteger(parentTocLineIndex) || parentTocLineIndex < 0) {
|
|
1456
1513
|
throw new Error("Missing parentTocLineIndex");
|
|
1457
1514
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1515
|
+
const sibling = collectRefs(snapshot).byLine.get(parentTocLineIndex);
|
|
1516
|
+
if (!sibling) throw new Error("\u672A\u627E\u5230\u76EE\u5F55\u884C");
|
|
1517
|
+
await workspace.toc.createGroup({
|
|
1518
|
+
title,
|
|
1519
|
+
placement: sibling.ref.type === "note" ? { type: "note", targetNoteUuid: sibling.ref.noteUuid, placement: "inside" } : { type: "root", placement: "end" },
|
|
1520
|
+
expectedSnapshotRevision: snapshot.revision
|
|
1521
|
+
});
|
|
1462
1522
|
await refreshTocAndSidebar();
|
|
1463
1523
|
return {
|
|
1464
1524
|
success: true,
|
|
@@ -1467,40 +1527,48 @@ function sidebarStructurePlugin() {
|
|
|
1467
1527
|
};
|
|
1468
1528
|
}
|
|
1469
1529
|
const count = normalizeCount(data.count);
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
)
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
);
|
|
1493
|
-
} else {
|
|
1494
|
-
for (const note of notes) {
|
|
1495
|
-
await tocService.appendNoteToToc(note.index);
|
|
1530
|
+
const targetNoteIndex = String(
|
|
1531
|
+
data.targetNoteIndex || data.targetGroupNoteIndex || ""
|
|
1532
|
+
);
|
|
1533
|
+
const parentLine = data.parentTocLineIndex !== void 0 && data.parentTocLineIndex !== null ? Number(data.parentTocLineIndex) : null;
|
|
1534
|
+
const created = [];
|
|
1535
|
+
for (let i = 0; i < count; i++) {
|
|
1536
|
+
let placement;
|
|
1537
|
+
if (targetNoteIndex) {
|
|
1538
|
+
placement = {
|
|
1539
|
+
type: "note",
|
|
1540
|
+
targetNoteUuid: noteUuidForIndex(snapshot, targetNoteIndex),
|
|
1541
|
+
placement: data.placement === "after" ? "after" : "before"
|
|
1542
|
+
};
|
|
1543
|
+
} else if (parentLine !== null) {
|
|
1544
|
+
const sibling = collectRefs(snapshot).byLine.get(parentLine);
|
|
1545
|
+
if (sibling && sibling.ref.type === "note") {
|
|
1546
|
+
placement = {
|
|
1547
|
+
type: "note",
|
|
1548
|
+
targetNoteUuid: sibling.ref.noteUuid,
|
|
1549
|
+
placement: "inside"
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1496
1552
|
}
|
|
1553
|
+
const result2 = await workspace.notes.create({
|
|
1554
|
+
title: "new",
|
|
1555
|
+
placement,
|
|
1556
|
+
expectedSnapshotRevision: snapshot.revision
|
|
1557
|
+
});
|
|
1558
|
+
created.push({
|
|
1559
|
+
index: result2.value.index,
|
|
1560
|
+
dirName: result2.value.dirName
|
|
1561
|
+
});
|
|
1497
1562
|
}
|
|
1498
1563
|
await refreshTocAndSidebar();
|
|
1499
1564
|
scheduleNoteSearchReindex("api:create-notes");
|
|
1500
1565
|
return {
|
|
1501
1566
|
success: true,
|
|
1502
1567
|
sidebarChanged: true,
|
|
1503
|
-
createdNotes:
|
|
1568
|
+
createdNotes: created.map((note) => ({
|
|
1569
|
+
...note,
|
|
1570
|
+
link: buildNoteReadmeLink(note.dirName)
|
|
1571
|
+
})),
|
|
1504
1572
|
message: "\u7B14\u8BB0\u5DF2\u521B\u5EFA"
|
|
1505
1573
|
};
|
|
1506
1574
|
});
|
|
@@ -1523,7 +1591,7 @@ function updateConfigPlugin() {
|
|
|
1523
1591
|
return {
|
|
1524
1592
|
name: "tnotes-update-config",
|
|
1525
1593
|
configureServer(server) {
|
|
1526
|
-
updateCommand = new (0,
|
|
1594
|
+
updateCommand = new (0, _chunkBL22KD4Vcjs.UpdateNoteConfigCommand)();
|
|
1527
1595
|
server.middlewares.use(async (req, res, next) => {
|
|
1528
1596
|
if (req.url === "/__tnotes_update_config" && req.method === "POST") {
|
|
1529
1597
|
let body = "";
|
|
@@ -1603,7 +1671,7 @@ function defineNotesConfig(overrides = {}) {
|
|
|
1603
1671
|
getNoteByConfigIdPlugin(),
|
|
1604
1672
|
fileWatcherBridgePlugin(),
|
|
1605
1673
|
localSearchReindexPlugin(),
|
|
1606
|
-
..._optionalChain([overrideVite, 'optionalAccess',
|
|
1674
|
+
..._optionalChain([overrideVite, 'optionalAccess', _47 => _47.plugins]) || []
|
|
1607
1675
|
],
|
|
1608
1676
|
server: {
|
|
1609
1677
|
// 显式同时监听 IPv4 / IPv6,避免 Node 18+ 在 Windows 下偶发只绑定 ::1
|
|
@@ -1612,7 +1680,7 @@ function defineNotesConfig(overrides = {}) {
|
|
|
1612
1680
|
watch: {
|
|
1613
1681
|
ignored: IGNORE_LIST
|
|
1614
1682
|
},
|
|
1615
|
-
..._optionalChain([overrideVite, 'optionalAccess',
|
|
1683
|
+
..._optionalChain([overrideVite, 'optionalAccess', _48 => _48.server])
|
|
1616
1684
|
},
|
|
1617
1685
|
css: {
|
|
1618
1686
|
preprocessorOptions: {
|
|
@@ -1620,26 +1688,26 @@ function defineNotesConfig(overrides = {}) {
|
|
|
1620
1688
|
silenceDeprecations: ["legacy-js-api"]
|
|
1621
1689
|
}
|
|
1622
1690
|
},
|
|
1623
|
-
..._optionalChain([overrideVite, 'optionalAccess',
|
|
1691
|
+
..._optionalChain([overrideVite, 'optionalAccess', _49 => _49.css])
|
|
1624
1692
|
},
|
|
1625
1693
|
build: {
|
|
1626
1694
|
chunkSizeWarningLimit: 1e3,
|
|
1627
|
-
..._optionalChain([overrideVite, 'optionalAccess',
|
|
1695
|
+
..._optionalChain([overrideVite, 'optionalAccess', _50 => _50.build])
|
|
1628
1696
|
},
|
|
1629
1697
|
define: {
|
|
1630
1698
|
__TNOTES_REPO_NAME__: JSON.stringify(config.repoName),
|
|
1631
1699
|
__TNOTES_AUTHOR__: JSON.stringify(config.author),
|
|
1632
1700
|
__TNOTES_IGNORE_DIRS__: JSON.stringify(config.ignore_dirs),
|
|
1633
1701
|
__TNOTES_ROOT_ITEM__: JSON.stringify(config.root_item),
|
|
1634
|
-
..._optionalChain([overrideVite, 'optionalAccess',
|
|
1702
|
+
..._optionalChain([overrideVite, 'optionalAccess', _51 => _51.define])
|
|
1635
1703
|
},
|
|
1636
1704
|
resolve: {
|
|
1637
1705
|
dedupe: ["vue", "vitepress"],
|
|
1638
|
-
..._optionalChain([overrideVite, 'optionalAccess',
|
|
1706
|
+
..._optionalChain([overrideVite, 'optionalAccess', _52 => _52.resolve])
|
|
1639
1707
|
},
|
|
1640
1708
|
optimizeDeps: {
|
|
1641
1709
|
include: [...DEFAULT_OPTIMIZE_DEPS_INCLUDE],
|
|
1642
|
-
..._optionalChain([overrideVite, 'optionalAccess',
|
|
1710
|
+
..._optionalChain([overrideVite, 'optionalAccess', _53 => _53.optimizeDeps])
|
|
1643
1711
|
}
|
|
1644
1712
|
},
|
|
1645
1713
|
transformPageData(pageData, ctx) {
|