@abraca/junis 2.81.0 → 2.83.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.
Files changed (59) hide show
  1. package/README.md +31 -15
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +49 -18
  4. package/dist/runtime/assets/css/jun.css +1 -1
  5. package/dist/runtime/components/JunCampfireChat.vue +1 -1
  6. package/dist/runtime/components/JunCampfirePanel.vue +12 -12
  7. package/dist/runtime/components/JunCampfirePresence.client.vue +8 -8
  8. package/dist/runtime/components/JunCampfireRoster.vue +13 -13
  9. package/dist/runtime/components/JunCampfireYou.vue +9 -9
  10. package/dist/runtime/components/JunGlobeEditor.client.vue +396 -183
  11. package/dist/runtime/components/JunGlobeMap.client.vue +1 -0
  12. package/dist/runtime/components/JunHorizontalTimeline.vue +41 -4
  13. package/dist/runtime/components/JunImagePopup.client.vue +1 -1
  14. package/dist/runtime/components/renderers/JunAppsRenderer.vue +5 -5
  15. package/dist/runtime/components/renderers/JunCvRenderer.vue +1 -1
  16. package/dist/runtime/components/renderers/JunEntryRenderer.vue +1 -1
  17. package/dist/runtime/components/renderers/JunGuestbookRenderer.vue +2 -0
  18. package/dist/runtime/components/renderers/JunHomeRenderer.vue +2 -2
  19. package/dist/runtime/components/renderers/JunJournalRenderer.vue +6 -6
  20. package/dist/runtime/components/renderers/JunLiveRenderer.vue +2 -1
  21. package/dist/runtime/components/renderers/JunMovieRenderer.vue +1 -1
  22. package/dist/runtime/components/renderers/JunNowRenderer.vue +39 -0
  23. package/dist/runtime/components/renderers/JunProjectRenderer.vue +2 -2
  24. package/dist/runtime/components/renderers/JunStatsRenderer.vue +293 -74
  25. package/dist/runtime/components/renderers/JunTrackRenderer.vue +44 -0
  26. package/dist/runtime/components/renderers/JunWallRenderer.vue +1 -0
  27. package/dist/runtime/composables/useJunChrome.js +11 -2
  28. package/dist/runtime/composables/useJunTheme.js +9 -0
  29. package/dist/runtime/composables/useJunViewingAccent.d.ts +0 -1
  30. package/dist/runtime/composables/useJunViewingAccent.js +1 -1
  31. package/dist/runtime/plugins/jun-fresh-server.client.d.ts +2 -0
  32. package/dist/runtime/plugins/jun-fresh-server.client.js +42 -0
  33. package/dist/runtime/server/api/stats.get.d.ts +27 -0
  34. package/dist/runtime/server/api/stats.get.js +35 -8
  35. package/dist/runtime/server/janitor/junJanitorChores.d.ts +23 -2
  36. package/dist/runtime/server/janitor/junJanitorChores.js +74 -8
  37. package/dist/runtime/server/janitor/junJanitorMachine.js +16 -2
  38. package/dist/runtime/server/janitor/junJanitorStore.d.ts +35 -1
  39. package/dist/runtime/server/janitor/junJanitorStore.js +62 -4
  40. package/dist/runtime/server/plugins/jun-bootstrap.js +128 -15
  41. package/dist/runtime/server/plugins/jun-doc-cache.js +44 -3
  42. package/dist/runtime/server/tasks/jun-register-tree.d.ts +16 -0
  43. package/dist/runtime/server/tasks/jun-register-tree.js +22 -0
  44. package/dist/runtime/server/utils/junActivity.d.ts +15 -0
  45. package/dist/runtime/server/utils/junActivity.js +71 -0
  46. package/dist/runtime/server/utils/junActivityMath.d.ts +61 -0
  47. package/dist/runtime/server/utils/junActivityMath.js +31 -0
  48. package/dist/runtime/server/utils/junCache.d.ts +15 -0
  49. package/dist/runtime/server/utils/junCache.js +9 -0
  50. package/dist/runtime/server/utils/junRegisterTree.d.ts +59 -0
  51. package/dist/runtime/server/utils/junRegisterTree.js +76 -0
  52. package/dist/runtime/server/utils/junServiceFetch.js +1 -1
  53. package/dist/runtime/server/utils/junVisibility.js +2 -0
  54. package/dist/runtime/types.d.ts +1 -1
  55. package/dist/runtime/utils/junVisibility.js +2 -0
  56. package/package.json +5 -2
  57. package/dist/runtime/components/renderers/JunWindowRenderer.d.vue.ts +0 -10
  58. package/dist/runtime/components/renderers/JunWindowRenderer.vue +0 -516
  59. package/dist/runtime/components/renderers/JunWindowRenderer.vue.d.ts +0 -10
@@ -7,6 +7,33 @@ declare const _default: import("h3").EventHandler<Omit<import("h3").EventHandler
7
7
  appreciations: number;
8
8
  words: number;
9
9
  newestEdit: number;
10
+ oldestPage: number;
11
+ byType: Record<string, number>;
12
+ /**
13
+ * When the ledger last SAW text change.
14
+ *
15
+ * `newestEdit` above is the newest tree-entry `updatedAt`, and that is the
16
+ * blind number this whole ledger exists because of — it moves for a rename
17
+ * or a meta change and never for typing. Reporting it alone as "last edit"
18
+ * would leave the page saying "an hour ago" ten minutes after somebody
19
+ * wrote a paragraph, which is the original bug wearing a new chart. The
20
+ * page takes whichever of the two is more recent.
21
+ *
22
+ * Its resolution is the sweep, so it can lag by up to one interval. That is
23
+ * still far closer to the truth than a number that never moves at all.
24
+ */
25
+ lastActivityAt: number;
26
+ /** Dense, oldest first — one entry per day whether or not anything happened. */
27
+ activity: {
28
+ date: string;
29
+ edits: number;
30
+ words: number;
31
+ }[];
32
+ /**
33
+ * False until the ledger has taken its baseline. The page must say "still
34
+ * measuring" rather than draw thirty empty bars and imply a silent month.
35
+ */
36
+ activityReady: boolean;
10
37
  generatedAt: number;
11
38
  }>>;
12
39
  export default _default;
@@ -1,16 +1,15 @@
1
1
  import { defineCachedEventHandler, useRuntimeConfig, useStorage } from "nitropack/runtime";
2
- import { junDocTree, junRootDocId } from "../utils/junCache.js";
2
+ import { junCountedDocIds, junDocTree, junRootDocId } from "../utils/junCache.js";
3
+ import { junReadActivity } from "../utils/junActivity.js";
4
+ import { junActivitySeries, junCountWords } from "../utils/junActivityMath.js";
3
5
  export default defineCachedEventHandler(async () => {
4
6
  const jun = useRuntimeConfig().public.jun;
5
7
  const types = jun?.typeIds ?? {};
6
8
  const rootDocId = junRootDocId();
7
9
  const tree = await junDocTree();
10
+ const countedIds = junCountedDocIds(tree, rootDocId);
8
11
  const counted = {};
9
- for (const [id, entry] of Object.entries(tree)) {
10
- if (!entry || entry.trashed || id === rootDocId) continue;
11
- if (entry.meta?.seedTest === true || entry.meta?.draft === true) continue;
12
- counted[id] = entry;
13
- }
12
+ for (const id of countedIds) counted[id] = tree[id];
14
13
  let pages = 0;
15
14
  let journalEntries = 0;
16
15
  let livePosts = 0;
@@ -18,10 +17,13 @@ export default defineCachedEventHandler(async () => {
18
17
  let signatures = 0;
19
18
  let appreciations = 0;
20
19
  let newestEdit = 0;
20
+ let oldestPage = 0;
21
+ const byType = {};
21
22
  for (const entry of Object.values(counted)) {
22
23
  pages++;
23
24
  if (types.entry && entry.type === types.entry) journalEntries++;
24
25
  if (types.now && entry.type === types.now) livePosts++;
26
+ if (entry.type) byType[entry.type] = (byType[entry.type] ?? 0) + 1;
25
27
  const parent = entry.parentId ? counted[entry.parentId] ?? tree[entry.parentId] : void 0;
26
28
  if (types.wall && parent?.type === types.wall && entry.meta?.coverUploadId) photos++;
27
29
  if (types.guestbook && parent?.type === types.guestbook && typeof entry.meta?.message === "string") {
@@ -30,6 +32,8 @@ export default defineCachedEventHandler(async () => {
30
32
  if (Array.isArray(entry.meta?.appreciatedBy)) appreciations += entry.meta.appreciatedBy.length;
31
33
  const updated = typeof entry.updatedAt === "number" ? entry.updatedAt : 0;
32
34
  if (updated > newestEdit) newestEdit = updated;
35
+ const created = typeof entry.createdAt === "number" ? entry.createdAt : 0;
36
+ if (created > 0 && (oldestPage === 0 || created < oldestPage)) oldestPage = created;
33
37
  }
34
38
  let words = 0;
35
39
  const storage = useStorage();
@@ -39,9 +43,9 @@ export default defineCachedEventHandler(async () => {
39
43
  if (!counted[docId]) continue;
40
44
  const html = await storage.getItem(key);
41
45
  if (typeof html !== "string" || !html) continue;
42
- const text = html.replace(/<[^>]*>/g, " ").replace(/&[a-z#0-9]+;/gi, " ");
43
- words += text.split(/\s+/).filter(Boolean).length;
46
+ words += junCountWords(html);
44
47
  }
48
+ const ledger = await junReadActivity();
45
49
  return {
46
50
  pages,
47
51
  journalEntries,
@@ -51,6 +55,29 @@ export default defineCachedEventHandler(async () => {
51
55
  appreciations,
52
56
  words,
53
57
  newestEdit,
58
+ oldestPage,
59
+ byType,
60
+ /**
61
+ * When the ledger last SAW text change.
62
+ *
63
+ * `newestEdit` above is the newest tree-entry `updatedAt`, and that is the
64
+ * blind number this whole ledger exists because of — it moves for a rename
65
+ * or a meta change and never for typing. Reporting it alone as "last edit"
66
+ * would leave the page saying "an hour ago" ten minutes after somebody
67
+ * wrote a paragraph, which is the original bug wearing a new chart. The
68
+ * page takes whichever of the two is more recent.
69
+ *
70
+ * Its resolution is the sweep, so it can lag by up to one interval. That is
71
+ * still far closer to the truth than a number that never moves at all.
72
+ */
73
+ lastActivityAt: ledger.lastChangeAt,
74
+ /** Dense, oldest first — one entry per day whether or not anything happened. */
75
+ activity: junActivitySeries(ledger, 30),
76
+ /**
77
+ * False until the ledger has taken its baseline. The page must say "still
78
+ * measuring" rather than draw thirty empty bars and imply a silent month.
79
+ */
80
+ activityReady: ledger.seeded,
54
81
  generatedAt: Date.now()
55
82
  };
56
83
  }, { name: "jun-stats", maxAge: 60, swr: true });
@@ -68,6 +68,13 @@ export type JunChore = (ChoreBase & {
68
68
  kind: 'entry.rename';
69
69
  from: string;
70
70
  to: string;
71
+ }) | (ChoreBase & {
72
+ kind: 'entry.type';
73
+ from: string;
74
+ to: string;
75
+ }) | (ChoreBase & {
76
+ kind: 'entry.move';
77
+ parentId: string | null;
71
78
  }) | (ChoreBase & {
72
79
  kind: 'entry.reorder';
73
80
  order: number;
@@ -100,8 +107,22 @@ export interface JunChorePolicy {
100
107
  backspaceLimit: number;
101
108
  /** Above this, a body edit is not a tidy-up — it collapses to one flat cut. */
102
109
  wholesaleLimit: number;
103
- /** Meta keys the janitor considers part of the page. Everything else is none of its business. */
104
- metaKeys: readonly string[];
110
+ /**
111
+ * Meta keys the janitor must NOT touch. Everything else on a page is content,
112
+ * and content is its business.
113
+ *
114
+ * This is a DENYLIST, and it used to be an allowlist of seven keys
115
+ * (`excerpt`, `icon`, `tags`, `accent`, `description`, `status`, `url`). That
116
+ * was wrong in a way nothing caught: the renderers read **56** distinct meta
117
+ * keys, so a visitor could rewrite `nowPlaying` on a `now` page, `location`
118
+ * on a live entry, an `author`, a `rating`, a `category`, a `place` — any of
119
+ * the forty-nine the list did not name — and the janitor walked straight
120
+ * past it. A custom page type, whose fields are unknowable in advance, was
121
+ * invisible to it ENTIRELY. An allowlist cannot express "put everything
122
+ * back"; only a denylist can, and only a denylist keeps working when a new
123
+ * page type invents a field.
124
+ */
125
+ metaIgnore: readonly string[];
105
126
  /** Never touch these documents, whatever the baseline says. */
106
127
  ignoreDocIds: readonly string[];
107
128
  /** Never remove a document that has at least this many children. */
@@ -2,11 +2,35 @@ import { junDiffText, describeSize, editShape } from "./junJanitorDiff.js";
2
2
  export const JUN_CHORE_POLICY_DEFAULT = {
3
3
  backspaceLimit: 90,
4
4
  wholesaleLimit: 4e3,
5
- // Deliberately short. `date`, `slugAliases`, `appreciatedBy` and the rest are
6
- // either legitimately live or belong to other features — a janitor that
7
- // reverted `appreciatedBy` would be un-hearting visitors' reactions, which is
8
- // not tidying, it is vandalism with a mop.
9
- metaKeys: ["excerpt", "icon", "tags", "accent", "description", "status", "url"],
5
+ // Deliberately short, and every entry has to earn its place — anything left
6
+ // out here IS reverted, which is the point. Four kinds of thing belong:
7
+ //
8
+ // - VISITOR-CONTRIBUTED. `appreciatedBy` is the reaction list the RPC runner
9
+ // appends to. A janitor that reverted it would be un-hearting visitors'
10
+ // reactions, which is not tidying, it is vandalism with a mop.
11
+ // - DERIVED BOOKKEEPING. `slugAliases` is written by `useJunRename` to keep
12
+ // a vacated URL redirecting. Reverting it would break the 301 for a
13
+ // rename the janitor itself is about to undo, and the rename chore already
14
+ // restores the label the alias exists for.
15
+ // - IDENTITY AND TIMESTAMPS. Not content, and `order` has its own chore —
16
+ // comparing it here too would queue two chores for one displacement.
17
+ // - INFRASTRUCTURE FLAGS. The documents carrying these are already excluded
18
+ // wholesale by `isJunOwnerOnlyDoc`; the keys are named again so that a
19
+ // flag appearing on an ordinary page cannot be reverted into a site that
20
+ // hides it, or out of one.
21
+ metaIgnore: [
22
+ "appreciatedBy",
23
+ "slugAliases",
24
+ "createdAt",
25
+ "updatedAt",
26
+ "order",
27
+ "_metaInitialized",
28
+ "janitorBaseline",
29
+ "ownerOnly",
30
+ "siteConfig",
31
+ "campfire",
32
+ "junSite"
33
+ ],
10
34
  ignoreDocIds: [],
11
35
  protectChildCount: 1
12
36
  };
@@ -90,6 +114,7 @@ export function planTreeChores(baseline, live, options = {}) {
90
114
  const policy = options.policy ?? JUN_CHORE_POLICY_DEFAULT;
91
115
  const chores = [];
92
116
  const ignored = new Set(policy.ignoreDocIds);
117
+ const ignoredKeys = new Set(policy.metaIgnore);
93
118
  for (const [id, base] of Object.entries(baseline.docs)) {
94
119
  if (ignored.has(id)) continue;
95
120
  const now = live.docs[id];
@@ -126,7 +151,31 @@ export function planTreeChores(baseline, live, options = {}) {
126
151
  severity: "minor"
127
152
  });
128
153
  }
129
- for (const key of policy.metaKeys) {
154
+ if (now.parentId !== base.parentId) {
155
+ chores.push({
156
+ kind: "entry.move",
157
+ id: `move:${id}`,
158
+ docId: id,
159
+ parentId: base.parentId,
160
+ severity: "notable"
161
+ });
162
+ }
163
+ if (now.type !== base.type) {
164
+ chores.push({
165
+ kind: "entry.type",
166
+ id: `type:${id}`,
167
+ docId: id,
168
+ from: now.type,
169
+ to: base.type,
170
+ severity: "notable"
171
+ });
172
+ }
173
+ const keys = /* @__PURE__ */ new Set([
174
+ ...Object.keys(base.meta ?? {}),
175
+ ...Object.keys(now.meta ?? {})
176
+ ]);
177
+ for (const key of keys) {
178
+ if (ignoredKeys.has(key)) continue;
130
179
  const want = base.meta?.[key];
131
180
  const have = now.meta?.[key];
132
181
  if (stableEqual(want, have)) continue;
@@ -153,14 +202,27 @@ export function planTreeChores(baseline, live, options = {}) {
153
202
  }
154
203
  return chores;
155
204
  }
205
+ function canonical(value) {
206
+ if (Array.isArray(value)) return value.map(canonical);
207
+ if (value && typeof value === "object") {
208
+ return Object.fromEntries(
209
+ Object.entries(value).map(([k, v]) => [k, canonical(v)]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
210
+ );
211
+ }
212
+ return value;
213
+ }
156
214
  function stableEqual(a, b) {
157
215
  if (a === b) return true;
158
216
  if (a == null || b == null) return a == null && b == null;
159
217
  if (Array.isArray(a) && Array.isArray(b)) {
160
- return a.length === b.length && [...a].sort().every((v, i) => stableEqual(v, [...b].sort()[i]));
218
+ if (a.length !== b.length) return false;
219
+ const sortKey = (v) => JSON.stringify(canonical(v));
220
+ const left = a.map(sortKey).sort();
221
+ const right = b.map(sortKey).sort();
222
+ return left.every((v, i) => v === right[i]);
161
223
  }
162
224
  if (typeof a === "object" && typeof b === "object") {
163
- return JSON.stringify(a) === JSON.stringify(b);
225
+ return JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
164
226
  }
165
227
  return false;
166
228
  }
@@ -177,6 +239,10 @@ export function describeChore(chore) {
177
239
  };
178
240
  case "entry.rename":
179
241
  return { what: `the name`, verb: "changed" };
242
+ case "entry.type":
243
+ return { what: "the kind of page", verb: "changed" };
244
+ case "entry.move":
245
+ return { what: "where this lives", verb: "moved" };
180
246
  case "entry.reorder":
181
247
  return { what: "the order", verb: "shuffled" };
182
248
  case "entry.meta":
@@ -18,7 +18,8 @@ import {
18
18
  import { createJunVoice } from "./junJanitorVoice.js";
19
19
  import {
20
20
  JUN_PATROL_POLICY_DEFAULT,
21
- nextPatrolTarget
21
+ nextPatrolTarget,
22
+ scorePatrol
22
23
  } from "./junJanitorPatrol.js";
23
24
  import { junHear } from "./junJanitorListen.js";
24
25
  import { junBlocks, displayToBody, displayToBodyPos, junCursorState, junFragmentText } from "./junJanitorYText.js";
@@ -244,6 +245,12 @@ export function createJunJanitorMachine(options, deps) {
244
245
  case "entry.reorder":
245
246
  await deps.tree.reorder(chore.docId, chore.order);
246
247
  return true;
248
+ case "entry.type":
249
+ await deps.tree.setType(chore.docId, chore.to);
250
+ return true;
251
+ case "entry.move":
252
+ await deps.tree.move(chore.docId, chore.parentId);
253
+ return true;
247
254
  case "entry.meta":
248
255
  await deps.tree.setMeta(chore.docId, chore.key, chore.value);
249
256
  return true;
@@ -456,8 +463,15 @@ export function createJunJanitorMachine(options, deps) {
456
463
  pendingChores: 0
457
464
  };
458
465
  });
466
+ const ranked = scorePatrol(candidates, at, patrolPolicy);
459
467
  const target = nextPatrolTarget(candidates, at, patrolPolicy);
460
- deps.log(`patrol: ${candidates.length} candidates \u2192 ${target?.docId.slice(0, 8) ?? "nowhere"}`);
468
+ const top = ranked.slice(0, 3).map((r) => {
469
+ const why = r.skipped ? r.skipped : r.score.toFixed(1);
470
+ return `${labelOf(live, r.candidate.docId)}=${why}`;
471
+ }).join(" ");
472
+ deps.log(
473
+ `patrol: ${candidates.length} candidates \u2192 ${target?.docId.slice(0, 8) ?? "nowhere"}${top ? ` [${top}]` : ""}`
474
+ );
461
475
  if (!target) {
462
476
  phase = "idle";
463
477
  deps.actor.setStatus(null);
@@ -76,6 +76,24 @@ export declare function createJunTreeWriter(options: JunTreeWriterOptions): {
76
76
  */
77
77
  rename(docId: string, label: string): Promise<void>;
78
78
  reorder(docId: string, order: number): Promise<void>;
79
+ /**
80
+ * Put a page back where it belongs.
81
+ *
82
+ * Slugs are derived from the tree, so this MOVES the page's URL — the same
83
+ * consequence a rename has. The vacated path is not recorded as an alias:
84
+ * `meta.slugAliases` is keyed on labels by `useJunRename`, and inventing a
85
+ * second convention for parents would put two writers on one key.
86
+ */
87
+ move(docId: string, parentId: string | null): Promise<void>;
88
+ /**
89
+ * Put a page's TYPE back.
90
+ *
91
+ * The type and the meta go in one `set`, the same rule the media importer
92
+ * follows: two writes leave a window in which the page is one kind of thing
93
+ * carrying another kind's fields, and that is what every peer renders until
94
+ * the second lands.
95
+ */
96
+ setType(docId: string, type: string): Promise<void>;
79
97
  setMeta(docId: string, key: string, value: unknown): Promise<void>;
80
98
  /**
81
99
  * Trash a page the canonical way: copy the entry into `doc-trash`, then
@@ -86,7 +104,23 @@ export declare function createJunTreeWriter(options: JunTreeWriterOptions): {
86
104
  * appear to have failed. See CLAUDE.md, "Trash documents the canonical way".
87
105
  */
88
106
  trash(docId: string): Promise<void>;
89
- /** Put a trashed page back where it was. */
107
+ /**
108
+ * Put a trashed page back where it was.
109
+ *
110
+ * A page can be gone in TWO shapes, and this used to handle only one. The
111
+ * canonical trash (`useChildTree.deleteEntry`, and this writer's own
112
+ * `trash`) copies the entry into `doc-trash` and DELETES it from
113
+ * `doc-tree`. But an entry can also be flagged `trashed: true` in place —
114
+ * `planTreeChores` raises a `doc.restore` for exactly that case, and
115
+ * `junReadTree` carries the flag for it.
116
+ *
117
+ * The old guard was `if (tree.get(docId)) return`, so the in-place shape
118
+ * fell straight through it and did nothing — while the confirmation
119
+ * (`!!shared().get(docId)`) found the entry still sitting there and
120
+ * reported the chore DONE. A restore that silently declines is the failure
121
+ * this module warns about everywhere else: a write that reports success
122
+ * and did not happen.
123
+ */
90
124
  restore(docId: string, entry: JunTreeEntry): Promise<void>;
91
125
  };
92
126
  export type JunTreeWriter = ReturnType<typeof createJunTreeWriter>;
@@ -120,6 +120,44 @@ export function createJunTreeWriter(options) {
120
120
  ).then(() => {
121
121
  });
122
122
  },
123
+ /**
124
+ * Put a page back where it belongs.
125
+ *
126
+ * Slugs are derived from the tree, so this MOVES the page's URL — the same
127
+ * consequence a rename has. The vacated path is not recorded as an alias:
128
+ * `meta.slugAliases` is keyed on labels by `useJunRename`, and inventing a
129
+ * second convention for parents would put two writers on one key.
130
+ */
131
+ move(docId, parentId) {
132
+ return withTree(
133
+ (tree) => {
134
+ const entry = plain(tree.get(docId));
135
+ if (!entry || entry.parentId === parentId) return;
136
+ tree.set(docId, { ...entry, parentId, updatedAt: Date.now() });
137
+ },
138
+ () => plain(shared().get(docId))?.parentId === parentId
139
+ ).then(() => {
140
+ });
141
+ },
142
+ /**
143
+ * Put a page's TYPE back.
144
+ *
145
+ * The type and the meta go in one `set`, the same rule the media importer
146
+ * follows: two writes leave a window in which the page is one kind of thing
147
+ * carrying another kind's fields, and that is what every peer renders until
148
+ * the second lands.
149
+ */
150
+ setType(docId, type) {
151
+ return withTree(
152
+ (tree) => {
153
+ const entry = plain(tree.get(docId));
154
+ if (!entry || entry.type === type) return;
155
+ tree.set(docId, { ...entry, type, updatedAt: Date.now() });
156
+ },
157
+ () => plain(shared().get(docId))?.type === type
158
+ ).then(() => {
159
+ });
160
+ },
123
161
  setMeta(docId, key, value) {
124
162
  return withTree(
125
163
  (tree) => {
@@ -159,22 +197,42 @@ export function createJunTreeWriter(options) {
159
197
  ).then(() => {
160
198
  });
161
199
  },
162
- /** Put a trashed page back where it was. */
200
+ /**
201
+ * Put a trashed page back where it was.
202
+ *
203
+ * A page can be gone in TWO shapes, and this used to handle only one. The
204
+ * canonical trash (`useChildTree.deleteEntry`, and this writer's own
205
+ * `trash`) copies the entry into `doc-trash` and DELETES it from
206
+ * `doc-tree`. But an entry can also be flagged `trashed: true` in place —
207
+ * `planTreeChores` raises a `doc.restore` for exactly that case, and
208
+ * `junReadTree` carries the flag for it.
209
+ *
210
+ * The old guard was `if (tree.get(docId)) return`, so the in-place shape
211
+ * fell straight through it and did nothing — while the confirmation
212
+ * (`!!shared().get(docId)`) found the entry still sitting there and
213
+ * reported the chore DONE. A restore that silently declines is the failure
214
+ * this module warns about everywhere else: a write that reports success
215
+ * and did not happen.
216
+ */
163
217
  restore(docId, entry) {
164
218
  return withTree(
165
219
  (tree) => {
166
- if (tree.get(docId)) return;
167
220
  const trash = tree.doc.getMap("doc-trash");
221
+ const current = plain(tree.get(docId));
222
+ if (current && current.trashed !== true) return;
168
223
  const stored = plain(trash.get(docId));
169
224
  tree.set(docId, {
170
- ...stored ?? entry,
225
+ ...stored ?? current ?? entry,
171
226
  ...entry,
172
227
  trashed: false,
173
228
  updatedAt: Date.now()
174
229
  });
175
230
  trash.delete(docId);
176
231
  },
177
- () => !!shared().get(docId)
232
+ () => {
233
+ const back = plain(shared().get(docId));
234
+ return !!back && back.trashed !== true;
235
+ }
178
236
  ).then(() => {
179
237
  });
180
238
  }
@@ -245,9 +245,12 @@ function defaultTree(typeIds) {
245
245
  label: "Wall",
246
246
  type: typeIds.wall,
247
247
  icon: "i-lucide-images",
248
- // No children: a wall's items are UPLOADED images, and the seeder has no
249
- // binaries to upload. It seeds the page so the type is reachable and its
250
- // empty state is what a new owner actually sees first.
248
+ // No children. A REAL deployment's wall starts empty on purpose — its
249
+ // items are the owner's photographs, and inventing two would put stock
250
+ // images on somebody's site. The playground seeds a pair (via
251
+ // `seedWallPhoto`, see `seedWallPhotos`) because a demo that cannot show
252
+ // the type is the thing that left the lightbox and this page's presence
253
+ // anchoring unverifiable for a release.
251
254
  meta: { excerpt: "Drop images here to pin them." }
252
255
  });
253
256
  }
@@ -336,15 +339,41 @@ function defaultTree(typeIds) {
336
339
  ]
337
340
  });
338
341
  }
339
- if (typeIds.window) {
342
+ if (typeIds.globe) {
340
343
  nodes.push({
341
- label: "Console",
342
- type: typeIds.window,
343
- icon: "i-lucide-app-window",
344
- meta: {
345
- excerpt: "A pretend app, genuinely multiplayer. Open it in two tabs.",
346
- windowUrl: "example.com/console"
347
- }
344
+ label: "Journey",
345
+ type: typeIds.globe,
346
+ icon: "i-lucide-globe-2",
347
+ meta: { excerpt: "A journey, drawn on a real map. Click a leg to frame both ends." },
348
+ children: [
349
+ {
350
+ label: "Reykjav\xEDk",
351
+ type: "doc",
352
+ meta: { date: "2025-03-02", geoLat: 64.1466, geoLng: -21.9426, icon: "snowflake" }
353
+ },
354
+ {
355
+ label: "Lisbon",
356
+ type: "doc",
357
+ meta: {
358
+ date: "2025-05-19",
359
+ geoLat: 38.7223,
360
+ geoLng: -9.1393,
361
+ transport: "plane",
362
+ icon: "plane"
363
+ }
364
+ },
365
+ {
366
+ label: "Kyoto",
367
+ type: "doc",
368
+ meta: {
369
+ date: "2025-10-11",
370
+ geoLat: 35.0116,
371
+ geoLng: 135.7681,
372
+ transport: "plane",
373
+ icon: "torii-gate"
374
+ }
375
+ }
376
+ ]
348
377
  });
349
378
  }
350
379
  if (typeIds.mosaic) {
@@ -512,14 +541,16 @@ async function bootstrap(ctx, seed) {
512
541
  shared.observe(check);
513
542
  });
514
543
  const flat = [];
515
- const collect = (n) => {
544
+ const parentOf = /* @__PURE__ */ new Map();
545
+ const collect = (n, parentId) => {
516
546
  flat.push(n);
517
- n.children.forEach(collect);
547
+ parentOf.set(n.id, parentId);
548
+ n.children.forEach((c) => collect(c, n.id));
518
549
  };
519
- plan.forEach(collect);
550
+ plan.forEach((n) => collect(n, rootId));
520
551
  for (const node of flat) {
521
552
  try {
522
- await ctx.client.createChild(rootId, {
553
+ await ctx.client.createChild(parentOf.get(node.id) ?? rootId, {
523
554
  child_id: node.id,
524
555
  label: node.label,
525
556
  // The REAL page type. Server-side listings, the admin TUI and every
@@ -535,6 +566,7 @@ async function bootstrap(ctx, seed) {
535
566
  }
536
567
  }
537
568
  await writeBodies(ctx, flat);
569
+ await seedWallPhotos(ctx, flat, tree);
538
570
  console.log(`[jun:bootstrap] seeded ${flat.length} documents \u2014 site is live`);
539
571
  } finally {
540
572
  try {
@@ -543,6 +575,87 @@ async function bootstrap(ctx, seed) {
543
575
  }
544
576
  }
545
577
  }
578
+ function crc32(buf) {
579
+ let c = ~0;
580
+ for (let i = 0; i < buf.length; i++) {
581
+ c ^= buf[i];
582
+ for (let k = 0; k < 8; k++) c = c >>> 1 ^ 3988292384 & -(c & 1);
583
+ }
584
+ return ~c >>> 0;
585
+ }
586
+ function pngChunk(type, data) {
587
+ const typeBytes = new TextEncoder().encode(type);
588
+ const body = new Uint8Array(typeBytes.length + data.length);
589
+ body.set(typeBytes);
590
+ body.set(data, typeBytes.length);
591
+ const out = new Uint8Array(8 + data.length + 4);
592
+ const view = new DataView(out.buffer);
593
+ view.setUint32(0, data.length);
594
+ out.set(body, 4);
595
+ view.setUint32(4 + body.length, crc32(body));
596
+ return out;
597
+ }
598
+ async function makePng(width, height, hue) {
599
+ const { deflateSync } = await import("node:zlib");
600
+ const raw = new Uint8Array(height * (1 + width * 3));
601
+ let p = 0;
602
+ for (let y = 0; y < height; y++) {
603
+ raw[p++] = 0;
604
+ for (let x = 0; x < width; x++) {
605
+ const t = (x / width + y / height) / 2;
606
+ raw[p++] = Math.round(40 + 180 * t * Math.abs(Math.cos(hue)));
607
+ raw[p++] = Math.round(60 + 150 * (1 - t) * Math.abs(Math.sin(hue * 1.7)));
608
+ raw[p++] = Math.round(90 + 140 * t);
609
+ }
610
+ }
611
+ const ihdr = new Uint8Array(13);
612
+ const iv = new DataView(ihdr.buffer);
613
+ iv.setUint32(0, width);
614
+ iv.setUint32(4, height);
615
+ ihdr[8] = 8;
616
+ ihdr[9] = 2;
617
+ const idat = new Uint8Array(deflateSync(Buffer.from(raw)));
618
+ const parts = [
619
+ new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]),
620
+ pngChunk("IHDR", ihdr),
621
+ pngChunk("IDAT", idat),
622
+ pngChunk("IEND", new Uint8Array(0))
623
+ ];
624
+ const total = parts.reduce((n, part) => n + part.length, 0);
625
+ const png = new Uint8Array(total);
626
+ let at = 0;
627
+ for (const part of parts) {
628
+ png.set(part, at);
629
+ at += part.length;
630
+ }
631
+ return png;
632
+ }
633
+ async function seedWallPhotos(ctx, flat, tree) {
634
+ const photos = flat.filter((n) => n.meta?.seedWallPhoto);
635
+ if (!photos.length) return;
636
+ let seeded = 0;
637
+ for (const [index, node] of photos.entries()) {
638
+ try {
639
+ const png = await makePng(1200, 800, 0.7 + index * 1.3);
640
+ const meta = await ctx.client.upload(node.id, new Blob([png], { type: "image/png" }), `${node.id}.png`);
641
+ const uploadId = meta?.id ?? meta?.upload_id;
642
+ if (!uploadId) throw new Error("upload returned no id");
643
+ const entry = tree.get(node.id);
644
+ if (!entry) throw new Error("tree entry vanished");
645
+ const entryMeta = { ...entry.meta ?? {} };
646
+ delete entryMeta.seedWallPhoto;
647
+ tree.set(node.id, {
648
+ ...entry,
649
+ updatedAt: Date.now(),
650
+ meta: { ...entryMeta, coverUploadId: uploadId, coverMimeType: "image/png" }
651
+ });
652
+ seeded++;
653
+ } catch (err) {
654
+ console.warn(`[jun:bootstrap] wall photo "${node.label}" failed:`, err?.message ?? err);
655
+ }
656
+ }
657
+ if (seeded) console.log(`[jun:bootstrap] uploaded ${seeded} wall photo(s)`);
658
+ }
546
659
  function attachJsonNodes(target, nodes) {
547
660
  for (const node of nodes) {
548
661
  if (node.kind === "element") {