@creator-notes/cnotes 0.113.0 → 0.113.1

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creator-notes-cli",
3
- "version": "0.113.0",
3
+ "version": "0.113.1",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
@@ -80,10 +80,63 @@ export function applyHead(db, head) {
80
80
  continue;
81
81
  db.run("DELETE FROM canvases WHERE id = ?", [id]);
82
82
  db.run("DELETE FROM placements WHERE canvas_id = ?", [id]);
83
+ clearLayout(db, id);
83
84
  }
84
85
  });
85
86
  return { canvasesToRefresh, dimensionsToRefresh };
86
87
  }
88
+ function clearLayout(db, canvasId) {
89
+ db.run("DELETE FROM layout_nodes WHERE canvas_id = ?", [canvasId]);
90
+ db.run("DELETE FROM layout_edges WHERE canvas_id = ?", [canvasId]);
91
+ }
92
+ /** Replace one board's layout rows (the workspace map's source). */
93
+ function writeLayout(db, canvasId, layout) {
94
+ clearLayout(db, canvasId);
95
+ const node = (id, kind, noteId, x, y, w, h, data) => db.run("INSERT OR REPLACE INTO layout_nodes (canvas_id, node_id, kind, note_id, x, y, w, h, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", [
96
+ canvasId,
97
+ id,
98
+ kind,
99
+ noteId,
100
+ x,
101
+ y,
102
+ w,
103
+ h,
104
+ JSON.stringify(data),
105
+ ]);
106
+ for (const c of layout.cards)
107
+ node(c.id, "card", c.noteId, c.x, c.y, c.w, c.h, { quoteStyle: c.quoteStyle, quoteSize: c.quoteSize });
108
+ for (const s of layout.sections)
109
+ node(s.id, "section", null, s.x, s.y, s.w, s.h, { name: s.name, displayId: s.displayId, colorHex: s.colorHex });
110
+ for (const t of layout.texts)
111
+ node(t.id, "text", null, t.x, t.y, t.w, t.h, { text: t.text, size: t.size, colorHex: t.colorHex });
112
+ for (const l of layout.lists)
113
+ node(l.id, "list", null, l.x, l.y, l.w, l.h, { name: l.name, description: l.description, colorHex: l.colorHex, items: l.items });
114
+ for (const l of layout.links)
115
+ node(l.id, "link", null, l.x, l.y, l.w, l.h, { linkedCanvasId: l.linkedCanvasId });
116
+ for (const e of layout.edges) {
117
+ db.run("INSERT INTO layout_edges (canvas_id, source, target, arrow_start, arrow_end, line_style) VALUES (?, ?, ?, ?, ?, ?)", [
118
+ canvasId,
119
+ e.source,
120
+ e.target,
121
+ e.arrowStart == null ? null : e.arrowStart ? 1 : 0,
122
+ e.arrowEnd == null ? null : e.arrowEnd ? 1 : 0,
123
+ e.lineStyle,
124
+ ]);
125
+ }
126
+ }
127
+ /** Every board's layout joined to its notes, for the workspace map. Branch drafts are left out. */
128
+ export function readWorkspaceLayout(db) {
129
+ const canvases = db.all("SELECT id, display_id AS displayId, name, updated_at AS updatedAt, branch_of AS branchOf, is_default AS isDefault FROM canvases WHERE branch_of IS NULL");
130
+ const nodes = db.all(`SELECT l.canvas_id AS canvasId, l.node_id AS nodeId, l.kind, l.note_id AS noteId, l.x, l.y, l.w, l.h, l.data,
131
+ n.display_id AS displayId, n.title, n.type, n.updated_at AS updatedAt
132
+ FROM layout_nodes l
133
+ JOIN canvases c ON c.id = l.canvas_id AND c.branch_of IS NULL
134
+ LEFT JOIN notes n ON n.id = l.note_id
135
+ WHERE l.kind != 'card' OR n.id IS NOT NULL`);
136
+ const edges = db.all(`SELECT e.canvas_id AS canvasId, e.source, e.target, e.arrow_start AS arrowStart, e.arrow_end AS arrowEnd, e.line_style AS lineStyle
137
+ FROM layout_edges e JOIN canvases c ON c.id = e.canvas_id AND c.branch_of IS NULL`);
138
+ return { canvases, nodes, edges };
139
+ }
87
140
  /** Replace each board's placements, and remember the board fields they were read at. */
88
141
  export function applyPlacements(db, rows) {
89
142
  db.transaction(() => {
@@ -91,8 +144,11 @@ export function applyPlacements(db, rows) {
91
144
  db.run("DELETE FROM placements WHERE canvas_id = ?", [row.canvasId]);
92
145
  if (row.removed) {
93
146
  db.run("DELETE FROM canvases WHERE id = ?", [row.canvasId]);
147
+ clearLayout(db, row.canvasId);
94
148
  continue;
95
149
  }
150
+ if (row.layout)
151
+ writeLayout(db, row.canvasId, row.layout);
96
152
  for (const noteId of row.cards) {
97
153
  db.run("INSERT OR IGNORE INTO placements (canvas_id, note_id, via) VALUES (?, ?, 'card')", [row.canvasId, noteId]);
98
154
  }
@@ -10,7 +10,7 @@
10
10
  * on `node:sqlite` under its config directory. Opening, forgetting and wiping
11
11
  * files stay with the storage, so they are not here.
12
12
  */
13
- import { applyAnswers, applyHead, applyNotes, applyPlacements, countRows, getMeta, reconcileNotes, setMeta } from "./apply.js";
13
+ import { applyAnswers, applyHead, applyNotes, applyPlacements, countRows, getMeta, readWorkspaceLayout, reconcileNotes, setMeta } from "./apply.js";
14
14
  import { buildCountQuery, buildFacetQuery, buildGroupCountsQuery, buildResultsQuery, checkReadOnlySql } from "./query.js";
15
15
  import { ensureSchema } from "./schema.js";
16
16
  export const NEWEST_KEY = "newest_note_updated_at";
@@ -88,6 +88,10 @@ export function createLocalDbOps(db) {
88
88
  const groups = groupBy === "none" ? [] : db.all(groupsQuery.sql, groupsQuery.params);
89
89
  return { rows, total, groups, ms: now() - start };
90
90
  },
91
+ workspaceLayout: () => {
92
+ const start = now();
93
+ return { ...readWorkspaceLayout(db), ms: now() - start };
94
+ },
91
95
  facets: ({ filter, fields, limit }) => {
92
96
  const start = now();
93
97
  const facets = {};
@@ -1,5 +1,5 @@
1
- export const SCHEMA_VERSION = 2;
2
- const TABLES = ["notes", "note_tags", "canvases", "placements", "members", "dimensions", "answers", "meta"];
1
+ export const SCHEMA_VERSION = 3;
2
+ const TABLES = ["notes", "note_tags", "canvases", "placements", "layout_nodes", "layout_edges", "members", "dimensions", "answers", "meta"];
3
3
  const CREATE = [
4
4
  `CREATE TABLE notes (
5
5
  id TEXT PRIMARY KEY,
@@ -29,6 +29,30 @@ const CREATE = [
29
29
  via TEXT NOT NULL,
30
30
  PRIMARY KEY (canvas_id, note_id, via)
31
31
  ) WITHOUT ROWID`,
32
+ // Where everything on each board sits, for the WebGL workspace map. `data`
33
+ // is the rest of the row as JSON (a frame's name and SECTION id, a text
34
+ // card's words, a quote card's look, a portal's target, a list's count).
35
+ `CREATE TABLE layout_nodes (
36
+ canvas_id TEXT NOT NULL,
37
+ node_id TEXT NOT NULL,
38
+ kind TEXT NOT NULL,
39
+ note_id TEXT,
40
+ x REAL NOT NULL,
41
+ y REAL NOT NULL,
42
+ w REAL,
43
+ h REAL,
44
+ data TEXT NOT NULL,
45
+ PRIMARY KEY (canvas_id, node_id)
46
+ ) WITHOUT ROWID`,
47
+ `CREATE TABLE layout_edges (
48
+ canvas_id TEXT NOT NULL,
49
+ source TEXT NOT NULL,
50
+ target TEXT NOT NULL,
51
+ arrow_start INTEGER,
52
+ arrow_end INTEGER,
53
+ line_style TEXT
54
+ )`,
55
+ `CREATE INDEX layout_edges_by_canvas ON layout_edges (canvas_id)`,
32
56
  `CREATE TABLE members (user_id TEXT PRIMARY KEY, name TEXT)`,
33
57
  `CREATE TABLE dimensions (
34
58
  type TEXT NOT NULL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.113.0",
3
+ "version": "0.113.1",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {