hdoc-tools 0.57.4 → 0.57.5

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.
@@ -5,8 +5,8 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>hdoc edit</title>
8
- <script type="module" crossorigin src="/assets/index-DxjRqh9o.js"></script>
9
- <link rel="stylesheet" crossorigin href="/assets/index-pnesp9iy.css">
8
+ <script type="module" crossorigin src="/assets/index-BtxvGZHW.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-Blewr90z.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
package/hdoc-edit.js CHANGED
@@ -474,6 +474,26 @@
474
474
  }
475
475
  });
476
476
 
477
+ // Update editable node properties (text/link/expand/newId). Returns the
478
+ // fresh tree.
479
+ app.post("/api/toc/update", (req, res) => {
480
+ const body = req.body || {};
481
+ if (typeof body.id !== "string" || !body.id) {
482
+ return res.status(400).json({ error: "Missing id" });
483
+ }
484
+ try {
485
+ toc.update_node(body.id, {
486
+ text: body.text,
487
+ link: body.link,
488
+ expand: body.expand,
489
+ newId: body.newId,
490
+ });
491
+ res.json(toc.to_dto());
492
+ } catch (e) {
493
+ res.status(400).json({ error: String((e && e.message) || e) });
494
+ }
495
+ });
496
+
477
497
  // Remove a nav node (unlink). With { deleteFile: true } also delete its
478
498
  // backing page file. Returns { tree, fileDeleted }.
479
499
  app.delete("/api/toc/:id", (req, res) => {
package/hdoc-toc.js CHANGED
@@ -384,6 +384,55 @@ class TocModel {
384
384
  return node.id;
385
385
  }
386
386
 
387
+ // Update editable node properties in one shot. `patch` may carry:
388
+ // text - display label (any node)
389
+ // link - leaf target path without extension (leaves only)
390
+ // expand - open-by-default flag (branches only; false clears it)
391
+ // newId - replace the opaque id (must be unique, url/json-safe charset)
392
+ // Unrecognised/undefined fields are ignored. Returns the updated node.
393
+ update_node(id, patch = {}) {
394
+ const node = this.find_node(id);
395
+ if (!node) throw new Error(`Unknown node id: ${id}`);
396
+ const isBranch = Array.isArray(node.items);
397
+
398
+ if (typeof patch.text === "string") {
399
+ node.text = patch.text;
400
+ }
401
+
402
+ if (patch.link !== undefined) {
403
+ if (isBranch) throw new Error("A section has no link");
404
+ if (typeof patch.link !== "string" || !patch.link.trim()) {
405
+ throw new Error("Link cannot be empty");
406
+ }
407
+ node.link = patch.link.trim();
408
+ }
409
+
410
+ if (patch.expand !== undefined) {
411
+ if (!isBranch) throw new Error("Only a section has an expand flag");
412
+ if (patch.expand) node.expand = true;
413
+ else delete node.expand; // default is collapsed; keep the JSON clean
414
+ }
415
+
416
+ if (patch.newId !== undefined && patch.newId !== node.id) {
417
+ const newId = String(patch.newId).trim();
418
+ if (!newId) throw new Error("Id cannot be empty");
419
+ if (!/^[A-Za-z0-9._-]+$/.test(newId)) {
420
+ throw new Error(
421
+ "Id may only contain letters, numbers, dot, underscore or hyphen",
422
+ );
423
+ }
424
+ if (this.used_ids.has(newId)) {
425
+ throw new Error(`Id already in use: ${newId}`);
426
+ }
427
+ this.used_ids.delete(node.id);
428
+ this.used_ids.add(newId);
429
+ node.id = newId;
430
+ }
431
+
432
+ this.persist();
433
+ return node;
434
+ }
435
+
387
436
  // Remove a nav node (unlink). Returns the removed node so the caller can
388
437
  // optionally delete its backing file.
389
438
  remove_node(id) {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.57.4",
3
+ "version": "0.57.5",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "hdoc-tools",
9
- "version": "0.57.4",
9
+ "version": "0.57.5",
10
10
  "hasInstallScript": true,
11
11
  "license": "ISC",
12
12
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.57.4",
3
+ "version": "0.57.5",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {