@creator-notes/cnotes 0.93.1 → 0.95.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/.claude-plugin/plugin.json +1 -1
- package/dist/commands/canvas.d.ts.map +1 -1
- package/dist/commands/canvas.js +207 -40
- package/dist/commands/canvas.js.map +1 -1
- package/dist/commands/draft.d.ts.map +1 -1
- package/dist/commands/draft.js +120 -64
- package/dist/commands/draft.js.map +1 -1
- package/dist/commands/workspace.d.ts.map +1 -1
- package/dist/commands/workspace.js +53 -10
- package/dist/commands/workspace.js.map +1 -1
- package/dist/lib/auth-store.d.ts +25 -0
- package/dist/lib/auth-store.d.ts.map +1 -1
- package/dist/lib/auth-store.js +25 -0
- package/dist/lib/auth-store.js.map +1 -1
- package/dist/lib/canvas-layout.d.ts +15 -0
- package/dist/lib/canvas-layout.d.ts.map +1 -1
- package/dist/lib/canvas-layout.js +26 -0
- package/dist/lib/canvas-layout.js.map +1 -1
- package/dist/lib/config.d.ts +30 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +45 -3
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/draft-view.d.ts +10 -6
- package/dist/lib/draft-view.d.ts.map +1 -1
- package/dist/lib/draft-view.js +18 -9
- package/dist/lib/draft-view.js.map +1 -1
- package/dist/mcp-server.js +77 -36
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/skills/cnotes/SKILL.md +1 -1
- package/skills/cnotes/references/canvas-layout.md +33 -2
- package/skills/cnotes/references/canvas.md +21 -11
- package/skills/cnotes/references/drafts.md +26 -19
- package/skills/cnotes/references/operations.md +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/commands/canvas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAyB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/commands/canvas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AAqCxE;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,SAAS,EACd,GAAG,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAC/C,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWxB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,SAAS,EACd,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,MAAM,EAAE,CAAC,CAuBnB;AAsJD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA0vG7D"}
|
package/dist/commands/canvas.js
CHANGED
|
@@ -12,7 +12,7 @@ import { readHeadlineWarnings, reportHeadlineWarnings } from "../lib/headline-wa
|
|
|
12
12
|
import { parseSharedCanvasLink, sameServerOrigin } from "../lib/share-link.js";
|
|
13
13
|
import { resolveAgentSession } from "../lib/claude-session.js";
|
|
14
14
|
import { WARN, dim } from "../lib/style.js";
|
|
15
|
-
import { findOverlaps, layoutItemsFrom, parseSize, resolveAnchor, suggestFreeSpot, } from "../lib/canvas-layout.js";
|
|
15
|
+
import { findOverlaps, findFrameSpills, layoutItemsFrom, parseSize, resolveAnchor, suggestFreeSpot, } from "../lib/canvas-layout.js";
|
|
16
16
|
import { canvasUrl, canvasLinkForRef } from "../lib/urls.js";
|
|
17
17
|
import { canvasActionPath, commentsListPath, parseCommentStatus, } from "../lib/canvas-paths.js";
|
|
18
18
|
import { registerCanvasMilestoneCommands } from "./canvas-milestone.js";
|
|
@@ -428,6 +428,7 @@ Examples:
|
|
|
428
428
|
});
|
|
429
429
|
const items = layoutItemsFrom(data);
|
|
430
430
|
const overlaps = findOverlaps(items);
|
|
431
|
+
const spills = findFrameSpills(items);
|
|
431
432
|
let freeSpot = null;
|
|
432
433
|
if (opts.near) {
|
|
433
434
|
const anchor = resolveAnchor(items, opts.near);
|
|
@@ -442,6 +443,7 @@ Examples:
|
|
|
442
443
|
outputJson({
|
|
443
444
|
items,
|
|
444
445
|
overlaps: overlaps.map((o) => ({ a: o.a.ref, b: o.b.ref, area: o.area })),
|
|
446
|
+
spills: spills.map((s) => ({ item: s.item.ref, section: s.section.ref, overhang: s.overhang })),
|
|
445
447
|
...(opts.near ? { freeSpot } : {}),
|
|
446
448
|
});
|
|
447
449
|
return;
|
|
@@ -449,7 +451,7 @@ Examples:
|
|
|
449
451
|
const canvas = data.canvas;
|
|
450
452
|
console.log(`Canvas: ${canvas?.title ?? canvasId} · ${items.length} items`);
|
|
451
453
|
outputTable(["KIND", "REF", "LABEL", "X", "Y", "W", "H"], items.map((i) => [
|
|
452
|
-
i.kind,
|
|
454
|
+
i.arranged ? "section (arranged)" : i.kind,
|
|
453
455
|
truncate(i.ref, 28),
|
|
454
456
|
truncate(i.label, 36),
|
|
455
457
|
String(Math.round(i.x)),
|
|
@@ -467,6 +469,13 @@ Examples:
|
|
|
467
469
|
}
|
|
468
470
|
console.log(" Fix with `canvas arrange`, or move one to a free spot from `--near`.");
|
|
469
471
|
}
|
|
472
|
+
if (spills.length > 0) {
|
|
473
|
+
console.log(`\n${WARN} ${spills.length} item${spills.length === 1 ? "" : "s"} run${spills.length === 1 ? "s" : ""} past the edge of ${spills.length === 1 ? "its" : "their"} section:`);
|
|
474
|
+
for (const s of spills) {
|
|
475
|
+
console.log(` ${s.item.ref} (${s.item.kind}) runs ${s.overhang}px past ${s.section.ref} "${s.section.label}"`);
|
|
476
|
+
}
|
|
477
|
+
console.log(" Fix with `canvas arrange <canvas> --section <SECTION-n>`: it lays the section out and sizes the frame to fit.");
|
|
478
|
+
}
|
|
470
479
|
if (opts.near) {
|
|
471
480
|
if (freeSpot) {
|
|
472
481
|
console.log(`\nFree ${size.width}x${size.height} spot near ${opts.near}: x=${freeSpot.x} y=${freeSpot.y}`);
|
|
@@ -864,31 +873,76 @@ Examples:
|
|
|
864
873
|
handleError(error, cfg.json);
|
|
865
874
|
}
|
|
866
875
|
});
|
|
876
|
+
/**
|
|
877
|
+
* `--x/--y` are an escape hatch now: without them an add goes through the
|
|
878
|
+
* solver (`placeLayout`), landing clear of everything, or INTO a section with
|
|
879
|
+
* `--section`, where it is appended to the section's layout and the section
|
|
880
|
+
* re-arranges itself. Returns null when neither was passed.
|
|
881
|
+
*/
|
|
882
|
+
const rawPosition = (opts) => {
|
|
883
|
+
if (opts.x === undefined && opts.y === undefined)
|
|
884
|
+
return null;
|
|
885
|
+
if (opts.x === undefined || opts.y === undefined) {
|
|
886
|
+
throw new ValidationError("Pass both --x and --y, or neither to let the solver place it");
|
|
887
|
+
}
|
|
888
|
+
return { x: parseInt(opts.x, 10), y: parseInt(opts.y, 10) };
|
|
889
|
+
};
|
|
890
|
+
const placeSingleItem = async (api, canvasId, workspaceId, leaf, intoSection) => {
|
|
891
|
+
const data = await api.post(canvasActionPath(canvasId, workspaceId), {
|
|
892
|
+
action: "placeLayout",
|
|
893
|
+
doc: { root: { kind: "item", ...leaf } },
|
|
894
|
+
...(intoSection ? { intoSection } : {}),
|
|
895
|
+
});
|
|
896
|
+
const item = data.items?.[0];
|
|
897
|
+
if (!item?.id || item.error) {
|
|
898
|
+
throw new ValidationError(String(item?.error ?? "The item could not be placed"));
|
|
899
|
+
}
|
|
900
|
+
const arrangeError = data.arrangedSections?.find((a) => a.error)?.error;
|
|
901
|
+
if (arrangeError) {
|
|
902
|
+
console.error(`⚠ Placed below ${intoSection}, but the section could not arrange itself: ${arrangeError}`);
|
|
903
|
+
}
|
|
904
|
+
return { data, item };
|
|
905
|
+
};
|
|
906
|
+
const placedWhere = (section) => section ? `into ${section} (the section re-arranged itself)` : "below existing content, clear of everything";
|
|
867
907
|
canvas
|
|
868
908
|
.command("add-node")
|
|
869
|
-
.description("
|
|
870
|
-
"
|
|
909
|
+
.description("Add one note card. The solver places it clear of everything, or INTO a section with --section " +
|
|
910
|
+
"(appended to the section's layout, which re-arranges itself). --x/--y place it at raw coordinates " +
|
|
911
|
+
"with no collision check (warns when it lands on something).")
|
|
871
912
|
.argument("<canvasId>", "Canvas ID")
|
|
872
913
|
.requiredOption("--note <noteId>", "Note display ID or Convex ID")
|
|
873
|
-
.option("--
|
|
874
|
-
.option("--
|
|
914
|
+
.option("--section <id>", "Put the card INTO this section (SECTION-<n> or id); the section arranges itself around it")
|
|
915
|
+
.option("--x <n>", "Raw X position (escape hatch: no collision check)")
|
|
916
|
+
.option("--y <n>", "Raw Y position (escape hatch: no collision check)")
|
|
875
917
|
.addHelpText("after", `
|
|
876
|
-
Prefer \`canvas place\` for new cards. If you do pick x/y yourself, check the
|
|
877
|
-
spot first: \`cnotes canvas status <canvasId> --near <ref>\` lists every item's
|
|
878
|
-
box and suggests a free one.
|
|
879
|
-
|
|
880
918
|
Examples:
|
|
881
|
-
$ cnotes canvas add-node <canvasId> --note MEETING-12
|
|
919
|
+
$ cnotes canvas add-node <canvasId> --note MEETING-12 # solver places it
|
|
920
|
+
$ cnotes canvas add-node <canvasId> --note MEETING-12 --section SECTION-13 # into a section
|
|
921
|
+
$ cnotes canvas add-node <canvasId> --note MEETING-12 --x 200 --y 300 # raw, unchecked
|
|
882
922
|
`)
|
|
883
923
|
.action(async (canvasId, opts) => {
|
|
884
924
|
const cfg = resolveConfig(program.opts());
|
|
885
925
|
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
886
926
|
try {
|
|
927
|
+
const position = rawPosition(opts);
|
|
928
|
+
if (!position) {
|
|
929
|
+
const { data, item } = await placeSingleItem(api, canvasId, cfg.workspaceId, { type: "note", noteId: opts.note }, opts.section);
|
|
930
|
+
if (cfg.quiet) {
|
|
931
|
+
outputQuiet(String(item.id));
|
|
932
|
+
}
|
|
933
|
+
else if (cfg.json) {
|
|
934
|
+
outputJson(data);
|
|
935
|
+
}
|
|
936
|
+
else {
|
|
937
|
+
console.log(`Added note ${opts.note} ${placedWhere(opts.section)}`);
|
|
938
|
+
}
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
887
941
|
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
888
942
|
action: "addNode",
|
|
889
943
|
noteId: opts.note,
|
|
890
|
-
positionX:
|
|
891
|
-
positionY:
|
|
944
|
+
positionX: position.x,
|
|
945
|
+
positionY: position.y,
|
|
892
946
|
});
|
|
893
947
|
if (cfg.quiet) {
|
|
894
948
|
outputQuiet(String(data.nodeId || data._id || ""));
|
|
@@ -956,13 +1010,22 @@ Examples:
|
|
|
956
1010
|
colorHex = opts.color.startsWith("#") ? opts.color : `#${opts.color}`;
|
|
957
1011
|
}
|
|
958
1012
|
try {
|
|
1013
|
+
const position = rawPosition(opts);
|
|
1014
|
+
if (!position) {
|
|
1015
|
+
const { data } = await placeSingleItem(api, canvasId, cfg.workspaceId, { type: "richtext", content, ...(opts.size ? { size: opts.size } : {}), ...(colorHex ? { colorHex } : {}) }, opts.section);
|
|
1016
|
+
if (cfg.json)
|
|
1017
|
+
outputJson(data);
|
|
1018
|
+
else
|
|
1019
|
+
console.log(`Added text element ${placedWhere(opts.section)}`);
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
959
1022
|
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
960
1023
|
action: "addRichtextNode",
|
|
961
1024
|
content,
|
|
962
1025
|
size: opts.size,
|
|
963
1026
|
colorHex,
|
|
964
|
-
positionX:
|
|
965
|
-
positionY:
|
|
1027
|
+
positionX: position.x,
|
|
1028
|
+
positionY: position.y,
|
|
966
1029
|
...(opts.ripple === false ? { ripple: false } : {}),
|
|
967
1030
|
});
|
|
968
1031
|
if (cfg.json) {
|
|
@@ -1000,17 +1063,23 @@ Examples:
|
|
|
1000
1063
|
.option("--content-file <path>", "Read text content (markdown) from a file")
|
|
1001
1064
|
.addOption(new Option("--size <size>", "Display size: small (560px), medium (1120px), large (1680px billboard)").choices(["small", "medium", "large"]))
|
|
1002
1065
|
.option("--color <hex>", "Background tint — DEFAULT IS NO BACKGROUND. Pass a ROLE hex: #3B82F6 evidence · #22C55E commitment · #EC4899 insight · #F59E0B warning · #EF4444 danger · #8B5CF6 people. Any other hex is snapped to the nearest of these at render, so an off-palette color just picks a role imprecisely. Reuse one role per meaning; omit it entirely unless the tint means something.")
|
|
1003
|
-
.option("--
|
|
1004
|
-
.option("--
|
|
1005
|
-
.option("--
|
|
1066
|
+
.option("--section <id>", "Put the text INTO this section (SECTION-<n> or id); the section arranges itself around it")
|
|
1067
|
+
.option("--x <n>", "Raw X position (escape hatch; without --x/--y the solver places it)")
|
|
1068
|
+
.option("--y <n>", "Raw Y position")
|
|
1069
|
+
.option("--no-ripple", "With --x/--y: do not move what sits below the card when it runs into it; only warn")
|
|
1006
1070
|
.addHelpText("after", `
|
|
1071
|
+
Without --x/--y the solver places the card clear of everything; with --section it
|
|
1072
|
+
goes INTO that section, appended to its layout, and the section re-arranges itself.
|
|
1073
|
+
|
|
1007
1074
|
Examples:
|
|
1008
1075
|
$ cnotes canvas add-text <canvasId> --content '# Q1 Goals' # a heading: markdown h1, untinted
|
|
1076
|
+
$ cnotes canvas add-text <canvasId> --content 'Open risk' --section SECTION-4 # into a section
|
|
1009
1077
|
$ cnotes canvas add-text <canvasId> --content-file ./banner.md --size medium # orientation banner
|
|
1010
1078
|
$ cnotes canvas add-text <canvasId> --content 'Ships behind a flag.' --color '#F59E0B' # warning role
|
|
1011
1079
|
|
|
1012
|
-
Height follows content: replacing a text element (remove-node + add-text) with
|
|
1013
|
-
content makes a TALLER card at the same x/y.
|
|
1080
|
+
Height follows content: replacing a text element (remove-node + add-text --x/--y) with
|
|
1081
|
+
longer content makes a TALLER card at the same x/y. (In an arranged section, edit the
|
|
1082
|
+
text instead: the section moves its other cards to fit.) When that card reaches down into what sits
|
|
1014
1083
|
below it (notes, lists, section frames and their title chips), the server moves that whole
|
|
1015
1084
|
band down so it clears the card, and the response carries ripple {delta, movedNodeCount}.
|
|
1016
1085
|
Anything it could not move (a column beside the card, siblings in the frame the card sits
|
|
@@ -1023,17 +1092,17 @@ and only warns.
|
|
|
1023
1092
|
defineAddTextCommand("add-richtext", "[DEPRECATED — use `add-text`] Alias of `add-text`: adds the same Text element (richtext) with the same flags. Kept for existing scripts; prefer `add-text`.");
|
|
1024
1093
|
canvas
|
|
1025
1094
|
.command("add-section")
|
|
1026
|
-
.description("Add a section frame — a named background region (Miro-style). Whatever sits inside moves with the frame when dragged; notes inside stay individually draggable. Mints a SECTION-<n> id: mention it from notes as [[SECTION-<n>]] to deep-link readers to that region, so name frames like places (\"Shaping\", \"Open Questions\"), not sentences. With --notes the frame is created WITH those notes laid out inside it (collision-aware, no coordinate math — the preferred way to build a populated section).")
|
|
1095
|
+
.description("Add a section frame — a named background region (Miro-style). Whatever sits inside moves with the frame when dragged; notes inside stay individually draggable. Mints a SECTION-<n> id: mention it from notes as [[SECTION-<n>]] to deep-link readers to that region, so name frames like places (\"Shaping\", \"Open Questions\"), not sentences. With --notes the frame is created WITH those notes laid out inside it (collision-aware, no coordinate math — the preferred way to build a populated section), and it stays ARRANGED: adding, editing or removing its cards re-lays it out, until someone moves a card by hand.")
|
|
1027
1096
|
.argument("<canvasId>", "Canvas ID")
|
|
1028
1097
|
.requiredOption("--name <name>", "Frame title (shown on the floating chip; title case)")
|
|
1029
1098
|
.option("--notes <ids>", "Note IDs (comma-separated, display IDs like TASK-6 or Convex IDs) to lay out INSIDE the frame; the frame sizes itself around them")
|
|
1030
1099
|
.option("--columns <n>", "Grid columns for the --notes layout", "3")
|
|
1031
|
-
.option("--x <n>", "X position (top-left). With --notes this seeds the layout origin (still de-collides); omit for auto placement below existing content"
|
|
1032
|
-
.option("--y <n>", "Y position (top-left)"
|
|
1100
|
+
.option("--x <n>", "X position (top-left). With --notes this seeds the layout origin (still de-collides); omit for auto placement below existing content")
|
|
1101
|
+
.option("--y <n>", "Y position (top-left)")
|
|
1033
1102
|
.option("--width <n>", "Frame width in px (empty frame only — with --notes the frame sizes to its contents)", "560")
|
|
1034
1103
|
.option("--height <n>", "Frame height in px (empty frame only)", "360")
|
|
1035
1104
|
.option("--color <hex>", "Frame tint — omit unless it encodes a role. Role hexes: #3B82F6 evidence · #22C55E commitment · #EC4899 insight · #F59E0B warning · #EF4444 danger · #8B5CF6 people; anything else snaps to the nearest of these at render")
|
|
1036
|
-
.action(async (canvasId, opts
|
|
1105
|
+
.action(async (canvasId, opts) => {
|
|
1037
1106
|
const cfg = resolveConfig(program.opts());
|
|
1038
1107
|
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
1039
1108
|
try {
|
|
@@ -1045,12 +1114,12 @@ and only warns.
|
|
|
1045
1114
|
// out in a grid, sizes the frame around them (section container),
|
|
1046
1115
|
// and lands the whole block collision-aware. Explicit --x/--y seed
|
|
1047
1116
|
// the origin; omitting them places below existing content.
|
|
1048
|
-
const explicitOrigin =
|
|
1117
|
+
const explicitOrigin = opts.x !== undefined || opts.y !== undefined;
|
|
1049
1118
|
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
1050
1119
|
action: "placeLayout",
|
|
1051
1120
|
doc: {
|
|
1052
1121
|
...(explicitOrigin
|
|
1053
|
-
? { origin: { x: parseInt(opts.x, 10), y: parseInt(opts.y, 10) }, placement: "auto" }
|
|
1122
|
+
? { origin: { x: parseInt(opts.x ?? "100", 10), y: parseInt(opts.y ?? "100", 10) }, placement: "auto" }
|
|
1054
1123
|
: {}),
|
|
1055
1124
|
root: {
|
|
1056
1125
|
kind: "section",
|
|
@@ -1081,11 +1150,30 @@ and only warns.
|
|
|
1081
1150
|
}
|
|
1082
1151
|
return;
|
|
1083
1152
|
}
|
|
1153
|
+
const position = rawPosition(opts);
|
|
1154
|
+
if (!position) {
|
|
1155
|
+
const { data, item } = await placeSingleItem(api, canvasId, cfg.workspaceId, {
|
|
1156
|
+
type: "section",
|
|
1157
|
+
name: opts.name,
|
|
1158
|
+
width: parseInt(opts.width, 10),
|
|
1159
|
+
height: parseInt(opts.height, 10),
|
|
1160
|
+
...(opts.color ? { colorHex: opts.color } : {}),
|
|
1161
|
+
});
|
|
1162
|
+
if (cfg.json) {
|
|
1163
|
+
outputJson(data);
|
|
1164
|
+
}
|
|
1165
|
+
else {
|
|
1166
|
+
console.log(`Added section ${item.displayId} "${opts.name}" below existing content, ${opts.width}×${opts.height}` +
|
|
1167
|
+
`\n Mention it from notes as [[${item.displayId}]] to deep-link readers to this region.` +
|
|
1168
|
+
`\n Put cards in it with --section ${item.displayId} on add-node / add-text / add-list / add-link, or place --into.`);
|
|
1169
|
+
}
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1084
1172
|
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
1085
1173
|
action: "addSectionNode",
|
|
1086
1174
|
name: opts.name,
|
|
1087
|
-
positionX:
|
|
1088
|
-
positionY:
|
|
1175
|
+
positionX: position.x,
|
|
1176
|
+
positionY: position.y,
|
|
1089
1177
|
width: parseInt(opts.width, 10),
|
|
1090
1178
|
height: parseInt(opts.height, 10),
|
|
1091
1179
|
colorHex: opts.color,
|
|
@@ -1194,8 +1282,9 @@ Examples:
|
|
|
1194
1282
|
.requiredOption("--description <markdown>", "Rich-text description (markdown). Required. First paragraph derives the searchable title.")
|
|
1195
1283
|
.option("--notes <ids>", "Note IDs (comma-separated, display IDs like TASK-6 or Convex IDs)")
|
|
1196
1284
|
.option("--view <mode>", "View mode: list or grid", "list")
|
|
1197
|
-
.option("--
|
|
1198
|
-
.option("--
|
|
1285
|
+
.option("--section <id>", "Put the list INTO this section (SECTION-<n> or id); the section arranges itself around it")
|
|
1286
|
+
.option("--x <n>", "Raw X position (escape hatch; without --x/--y the solver places it)")
|
|
1287
|
+
.option("--y <n>", "Raw Y position")
|
|
1199
1288
|
.action(async (canvasId, opts) => {
|
|
1200
1289
|
const cfg = resolveConfig(program.opts());
|
|
1201
1290
|
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
@@ -1205,13 +1294,27 @@ Examples:
|
|
|
1205
1294
|
}
|
|
1206
1295
|
const noteIds = opts.notes ? opts.notes.split(",").map((id) => id.trim()) : [];
|
|
1207
1296
|
warnListItemMisuse(opts.description, noteIds.length);
|
|
1297
|
+
const position = rawPosition(opts);
|
|
1298
|
+
if (!position) {
|
|
1299
|
+
const { data } = await placeSingleItem(api, canvasId, cfg.workspaceId, {
|
|
1300
|
+
type: "list",
|
|
1301
|
+
description: opts.description,
|
|
1302
|
+
viewMode: opts.view,
|
|
1303
|
+
...(noteIds.length > 0 ? { noteIds } : {}),
|
|
1304
|
+
}, opts.section);
|
|
1305
|
+
if (cfg.json)
|
|
1306
|
+
outputJson(data);
|
|
1307
|
+
else
|
|
1308
|
+
console.log(`Added list (${opts.view}) with ${noteIds.length} notes ${placedWhere(opts.section)}`);
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1208
1311
|
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
1209
1312
|
action: "addListNode",
|
|
1210
1313
|
description: opts.description,
|
|
1211
1314
|
noteIds: noteIds.length > 0 ? noteIds : undefined,
|
|
1212
1315
|
viewMode: opts.view,
|
|
1213
|
-
positionX:
|
|
1214
|
-
positionY:
|
|
1316
|
+
positionX: position.x,
|
|
1317
|
+
positionY: position.y,
|
|
1215
1318
|
});
|
|
1216
1319
|
if (cfg.json) {
|
|
1217
1320
|
outputJson(data);
|
|
@@ -1230,17 +1333,29 @@ Examples:
|
|
|
1230
1333
|
.description("Add a link to another canvas")
|
|
1231
1334
|
.argument("<canvasId>", "Canvas ID")
|
|
1232
1335
|
.requiredOption("--target <canvasId>", "Target canvas ID to link to")
|
|
1233
|
-
.option("--
|
|
1234
|
-
.option("--
|
|
1336
|
+
.option("--section <id>", "Put the link INTO this section (SECTION-<n> or id); the section arranges itself around it")
|
|
1337
|
+
.option("--x <n>", "Raw X position (escape hatch; without --x/--y the solver places it)")
|
|
1338
|
+
.option("--y <n>", "Raw Y position")
|
|
1235
1339
|
.action(async (canvasId, opts) => {
|
|
1236
1340
|
const cfg = resolveConfig(program.opts());
|
|
1237
1341
|
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
1238
1342
|
try {
|
|
1343
|
+
const position = rawPosition(opts);
|
|
1344
|
+
if (!position) {
|
|
1345
|
+
const { data, item } = await placeSingleItem(api, canvasId, cfg.workspaceId, { type: "canvas", linkedCanvasId: opts.target }, opts.section);
|
|
1346
|
+
if (cfg.quiet)
|
|
1347
|
+
outputQuiet(String(item.id));
|
|
1348
|
+
else if (cfg.json)
|
|
1349
|
+
outputJson(data);
|
|
1350
|
+
else
|
|
1351
|
+
console.log(`Added link to canvas ${opts.target} ${placedWhere(opts.section)}`);
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1239
1354
|
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
1240
1355
|
action: "addCanvasLink",
|
|
1241
1356
|
linkedCanvasId: opts.target,
|
|
1242
|
-
positionX:
|
|
1243
|
-
positionY:
|
|
1357
|
+
positionX: position.x,
|
|
1358
|
+
positionY: position.y,
|
|
1244
1359
|
});
|
|
1245
1360
|
if (cfg.quiet) {
|
|
1246
1361
|
outputQuiet(String(data.nodeId || data._id || ""));
|
|
@@ -1345,14 +1460,21 @@ Examples:
|
|
|
1345
1460
|
.option("--spec-stdin", "Read the layout document from stdin")
|
|
1346
1461
|
.option("--spec-inline <json>", "Pass the layout document inline as a JSON string (short specs only)")
|
|
1347
1462
|
.option("--dry-run", "Validate the spec and return solved positions without mutating the canvas")
|
|
1463
|
+
.option("--into <section>", "Put the placed items INTO this section (SECTION-<n> or id). They're appended to its layout (end of its shortest column, or the next grid cell) and the section arranges itself to fit. The spec may not contain sections; origin and placement are ignored.")
|
|
1348
1464
|
.option("--placement <mode>", "Where to drop the layout vs existing content: auto (default, lands in a clear band below existing nodes / de-collides), append (always below everything), or exact (honor origin verbatim). Overrides any placement in the spec.")
|
|
1349
1465
|
.addHelpText("after", `
|
|
1350
1466
|
Examples:
|
|
1351
1467
|
$ cnotes canvas place <canvasId> --spec ./layout.json
|
|
1352
1468
|
$ cnotes canvas place <canvasId> --spec ./layout.json --placement append
|
|
1469
|
+
$ cnotes canvas place <canvasId> --spec ./cards.json --into SECTION-13
|
|
1353
1470
|
$ echo '{"root":{"type":"stack","items":[...]}}' | cnotes canvas place <canvasId> --spec-stdin
|
|
1354
1471
|
$ cnotes canvas place <canvasId> --spec ./layout.json --dry-run --json
|
|
1355
1472
|
|
|
1473
|
+
Sections: a section container in the spec ({"kind":"section","name":…,"child":…})
|
|
1474
|
+
creates an ARRANGED section. It keeps its cards laid out as they are added, edited
|
|
1475
|
+
or removed, until someone moves a card by hand. Put more cards in it later with
|
|
1476
|
+
--into SECTION-<n>; never by picking coordinates inside the frame.
|
|
1477
|
+
|
|
1356
1478
|
Placement (relative to nodes already on the canvas):
|
|
1357
1479
|
auto default — lands below existing content when no origin is set, and
|
|
1358
1480
|
slides the whole block down if it would overlap. You never have to
|
|
@@ -1405,6 +1527,7 @@ Placement (relative to nodes already on the canvas):
|
|
|
1405
1527
|
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
1406
1528
|
action: "placeLayout",
|
|
1407
1529
|
doc,
|
|
1530
|
+
...(opts.into ? { intoSection: opts.into } : {}),
|
|
1408
1531
|
...(opts.dryRun ? { dryRun: true } : {}),
|
|
1409
1532
|
});
|
|
1410
1533
|
// No canvas was mutated on a dry run, so don't surface a "here's what I
|
|
@@ -1458,6 +1581,13 @@ Placement (relative to nodes already on the canvas):
|
|
|
1458
1581
|
if (bbox?.width && bbox?.height) {
|
|
1459
1582
|
console.log(`Layout bounding box: ${Math.round(bbox.width)} × ${Math.round(bbox.height)}px`);
|
|
1460
1583
|
}
|
|
1584
|
+
const arranged = (data.arrangedSections || []);
|
|
1585
|
+
for (const a of arranged) {
|
|
1586
|
+
if (a.error)
|
|
1587
|
+
console.log(` ✗ section ${a.displayId ?? a.sectionId} could not arrange itself: ${a.error}`);
|
|
1588
|
+
else
|
|
1589
|
+
console.log(` Arranged ${a.displayId} (${a.width} × ${a.height}px); it keeps itself laid out`);
|
|
1590
|
+
}
|
|
1461
1591
|
// Surface item-level errors so the user doesn't have to re-run with --json
|
|
1462
1592
|
for (const item of items) {
|
|
1463
1593
|
if (item.error)
|
|
@@ -1481,9 +1611,11 @@ Placement (relative to nodes already on the canvas):
|
|
|
1481
1611
|
canvas
|
|
1482
1612
|
.command("arrange")
|
|
1483
1613
|
.description("Reflow EXISTING canvas nodes with the layout solver (no coordinate math). " +
|
|
1484
|
-
"
|
|
1485
|
-
"
|
|
1486
|
-
"
|
|
1614
|
+
"`arrange --section SECTION-<n>` on its own tidies everything already inside that frame " +
|
|
1615
|
+
"(keeping the columns and rows it is roughly in), sizes the frame to fit, and leaves the " +
|
|
1616
|
+
"section ARRANGED: it re-lays itself out as cards are added, edited or removed, until someone " +
|
|
1617
|
+
"moves a card by hand. With --nodes or --spec, packs exactly those nodes (mixed kinds welcome) " +
|
|
1618
|
+
"into the frame, which then stays arranged the same way.")
|
|
1487
1619
|
.argument("<canvasId>", "Canvas ID")
|
|
1488
1620
|
.option("--section <id>", "Target SECTION-<n> (or raw id) to pack into; auto-resizes the frame around the new layout")
|
|
1489
1621
|
.option("--nodes <json>", 'JSON array of {nodeId, nodeType} to rearrange, e.g. \'[{"nodeId":"…","nodeType":"canvas"}]\'')
|
|
@@ -1498,8 +1630,11 @@ Placement (relative to nodes already on the canvas):
|
|
|
1498
1630
|
.option("--spec-inline <json>", "Full layout document as a JSON string")
|
|
1499
1631
|
.option("--spec-stdin", "Read a full layout document from stdin")
|
|
1500
1632
|
.option("--dry-run", "Solve and preview positions without moving anything")
|
|
1633
|
+
.option("--stop", "With --section and no --nodes/--spec: stop arranging the section. Nothing moves.")
|
|
1501
1634
|
.addHelpText("after", `
|
|
1502
1635
|
Examples:
|
|
1636
|
+
$ cnotes canvas arrange CANVAS-265 --section SECTION-90 # tidy what's inside, keep it tidy
|
|
1637
|
+
$ cnotes canvas arrange CANVAS-265 --section SECTION-90 --stop # back to freeform
|
|
1503
1638
|
$ cnotes canvas arrange CANVAS-265 --section SECTION-90 \\
|
|
1504
1639
|
--nodes '[{"nodeId":"abc","nodeType":"canvas"},{"nodeId":"NOTE-3","nodeType":"note"}]' \\
|
|
1505
1640
|
--layout grid --columns 4 --gap medium
|
|
@@ -1521,8 +1656,40 @@ Examples:
|
|
|
1521
1656
|
if (specMode && nodesMode) {
|
|
1522
1657
|
throw new ValidationError("Use either --nodes / --nodes-stdin OR a full --spec, not both");
|
|
1523
1658
|
}
|
|
1659
|
+
// --section alone: the section arranges what is already inside it.
|
|
1660
|
+
if (!specMode && !nodesMode && opts.section) {
|
|
1661
|
+
if (opts.dryRun) {
|
|
1662
|
+
throw new ValidationError("--dry-run needs --nodes or --spec; arranging a section as it stands has no preview");
|
|
1663
|
+
}
|
|
1664
|
+
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
1665
|
+
action: "arrangeSection",
|
|
1666
|
+
sectionId: opts.section,
|
|
1667
|
+
...(opts.stop ? { stop: true } : {}),
|
|
1668
|
+
});
|
|
1669
|
+
if (cfg.json) {
|
|
1670
|
+
outputJson(data);
|
|
1671
|
+
}
|
|
1672
|
+
else if (opts.stop) {
|
|
1673
|
+
console.log(data.stopped
|
|
1674
|
+
? `${opts.section} is freeform now. Nothing moved.`
|
|
1675
|
+
: `${opts.section} was not arranged. Nothing changed.`);
|
|
1676
|
+
}
|
|
1677
|
+
else if (data.skipped === "empty") {
|
|
1678
|
+
console.log(`${opts.section} has no cards yet. It is arranged: cards placed into it will be laid out.`);
|
|
1679
|
+
}
|
|
1680
|
+
else {
|
|
1681
|
+
console.log(`Arranged ${data.cardCount} card${data.cardCount === 1 ? "" : "s"} in ${data.displayId ?? opts.section}: ` +
|
|
1682
|
+
`${data.movedCount} moved, frame ${data.width} × ${data.height}px` +
|
|
1683
|
+
(data.rippledCount ? `, ${data.rippledCount} item${data.rippledCount === 1 ? "" : "s"} below pushed down` : "") +
|
|
1684
|
+
". It keeps itself laid out until a card is moved by hand.");
|
|
1685
|
+
}
|
|
1686
|
+
return;
|
|
1687
|
+
}
|
|
1688
|
+
if (opts.stop) {
|
|
1689
|
+
throw new ValidationError("--stop goes with --section alone (no --nodes or --spec)");
|
|
1690
|
+
}
|
|
1524
1691
|
if (!specMode && !nodesMode) {
|
|
1525
|
-
throw new ValidationError("Provide --nodes (or --nodes-stdin), or a full --spec / --spec-inline / --spec-stdin");
|
|
1692
|
+
throw new ValidationError("Provide --section to arrange a section as it stands, or --nodes (or --nodes-stdin), or a full --spec / --spec-inline / --spec-stdin");
|
|
1526
1693
|
}
|
|
1527
1694
|
let doc;
|
|
1528
1695
|
if (specMode) {
|