@skillre/dsh-plugin-sticky-wall 0.4.0 → 0.5.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/lib/store.d.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  * with zod record schemas.
17
17
  */
18
18
  import { z } from 'zod';
19
- import { type Note, type NoteInput, type NoteLayout, type NotePatch } from './types.js';
19
+ import { type CentreReserve, type Note, type NoteInput, type NoteLayout, type NotePatch } from './types.js';
20
20
  /** Failure carrying a stable code the transport maps onto the RPC envelope. */
21
21
  export declare class WallError extends Error {
22
22
  readonly code: string;
@@ -120,8 +120,18 @@ export declare class StickyWallStore {
120
120
  private seedWelcomeNote;
121
121
  /** Every stored note, newest-relevant first; archived ones only on request. */
122
122
  list(includeArchived?: boolean, sort?: 'pinned' | 'created' | 'updated'): Note[];
123
- /** Create one note from a Client or agent submission. */
124
- create(input: NoteInput, id?: string): Promise<Note>;
123
+ /**
124
+ * Create one note from a Client or agent submission.
125
+ *
126
+ * `options.centreReserve` is the Client's zoom-corrected version of the clear
127
+ * rectangle around the wall's centrepiece. It only affects a note created
128
+ * WITHOUT a layout: the Host places that note in the nearest free gap, which
129
+ * is what makes a capture from the centre field appear right next to the field
130
+ * instead of wherever an index-derived spiral happened to reach.
131
+ */
132
+ create(input: NoteInput, id?: string, options?: {
133
+ centreReserve?: CentreReserve | undefined;
134
+ }): Promise<Note>;
125
135
  private createNow;
126
136
  /** Apply one patch; `updatedAt` moves only when a field actually changed. */
127
137
  update(id: string, patch: NotePatch): Promise<Note>;
@@ -162,7 +172,9 @@ export declare class StickyWallStore {
162
172
  * without refetching the whole wall, and pressing tidy on an already-tidy
163
173
  * wall is a no-op instead of a write storm.
164
174
  */
165
- arrange(): Promise<Note[]>;
175
+ arrange(options?: {
176
+ centreReserve?: CentreReserve | undefined;
177
+ }): Promise<Note[]>;
166
178
  private arrangeNow;
167
179
  /**
168
180
  * Permanently remove every archived note.
package/lib/store.js CHANGED
@@ -16,8 +16,8 @@
16
16
  * with zod record schemas.
17
17
  */
18
18
  import { z } from 'zod';
19
- import { arrangeLayouts, clampLayout, normalizeWidth, sameLayout } from './layout.js';
20
- import { COLORS, WIDTHS, DOMAIN_NAME, DOMAIN_VERSION, LIMITS, } from './types.js';
19
+ import { arrangeLayouts, clampLayout, findFreeLayout, normalizeReserve, normalizeWidth, sameLayout } from './layout.js';
20
+ import { CENTRE_RESERVE, COLORS, WIDTHS, DOMAIN_NAME, DOMAIN_VERSION, LIMITS, } from './types.js';
21
21
  /** Failure carrying a stable code the transport maps onto the RPC envelope. */
22
22
  export class WallError extends Error {
23
23
  code;
@@ -239,7 +239,13 @@ export class StickyWallStore {
239
239
  updatedAt: stamp,
240
240
  // The one note the plugin places itself, so a brand-new wall opens with a
241
241
  // card that is obviously meant to be dragged.
242
- layout: { x: 120, y: 96, rotate: -1.6, width: 'md' },
242
+ //
243
+ // The position is chosen to be OUTSIDE the centrepiece reserve. It used to
244
+ // be {120, 96}, which is squarely inside the reserved rectangle: a brand-new
245
+ // wall therefore opened with the welcome note sitting on top of the capture
246
+ // field, and every overlap assertion had to special-case it. Placing it in
247
+ // the first ring keeps the invariant true from the very first note.
248
+ layout: { x: 300, y: -420, rotate: -1.6, width: 'md' },
243
249
  };
244
250
  await this.notes.put(note.id, note);
245
251
  }
@@ -255,12 +261,20 @@ export class StickyWallStore {
255
261
  }
256
262
  return notes.sort(compareNotes(sort));
257
263
  }
258
- /** Create one note from a Client or agent submission. */
259
- async create(input, id) {
264
+ /**
265
+ * Create one note from a Client or agent submission.
266
+ *
267
+ * `options.centreReserve` is the Client's zoom-corrected version of the clear
268
+ * rectangle around the wall's centrepiece. It only affects a note created
269
+ * WITHOUT a layout: the Host places that note in the nearest free gap, which
270
+ * is what makes a capture from the centre field appear right next to the field
271
+ * instead of wherever an index-derived spiral happened to reach.
272
+ */
273
+ async create(input, id, options = {}) {
260
274
  this.assertOpen();
261
- return this.mutate(() => this.createNow(input, id));
275
+ return this.mutate(() => this.createNow(input, id, options));
262
276
  }
263
- async createNow(input, id) {
277
+ async createNow(input, id, options = {}) {
264
278
  const body = normalizeBody(input?.body);
265
279
  const title = normalizeTitle(input?.title);
266
280
  this.assertRoom(1);
@@ -279,6 +293,13 @@ export class StickyWallStore {
279
293
  };
280
294
  if (this.notes.get(note.id) !== undefined)
281
295
  throw new WallError('duplicate-id', `A note with id ${JSON.stringify(note.id)} already exists.`);
296
+ // A note with no explicit placement gets the nearest free spot on the wall,
297
+ // not `null`. `null` means "derive a position from my index", and that spiral
298
+ // grows outward — so the user's tenth capture could land a screen away from
299
+ // where they were looking, which reads as the capture having failed.
300
+ if (note.layout === null) {
301
+ note.layout = findFreeLayout(note, this.list(true, 'pinned'), { centreReserve: normalizeReserve(options.centreReserve ?? CENTRE_RESERVE) });
302
+ }
282
303
  await this.notes.put(note.id, note);
283
304
  return note;
284
305
  }
@@ -399,17 +420,17 @@ export class StickyWallStore {
399
420
  * without refetching the whole wall, and pressing tidy on an already-tidy
400
421
  * wall is a no-op instead of a write storm.
401
422
  */
402
- async arrange() {
423
+ async arrange(options = {}) {
403
424
  this.assertOpen();
404
- return this.mutate(() => this.arrangeNow());
425
+ return this.mutate(() => this.arrangeNow(options));
405
426
  }
406
- async arrangeNow() {
427
+ async arrangeNow(options = {}) {
407
428
  // Every note, archived ones included. Packing only the live set left an
408
429
  // archived-but-visible card at its dragged position, on top of the freshly
409
430
  // tidied ones — the wall has to be tidy in every filter, not just the
410
431
  // default one.
411
432
  const current = this.list(true, 'pinned');
412
- const planned = arrangeLayouts(current);
433
+ const planned = arrangeLayouts(current, { centreReserve: normalizeReserve(options.centreReserve ?? CENTRE_RESERVE) });
413
434
  const changed = [];
414
435
  for (const note of current) {
415
436
  const target = planned.get(note.id);
@@ -11,7 +11,7 @@
11
11
  * `{ type: 'server-response', rpcId, result: { ok: true, value } | { ok: false, error } }`
12
12
  * out. A non-owner Peer is rejected by Connection before this handler runs.
13
13
  */
14
- import { type Note, type NoteInput, type NoteLayout, type NotePatch, type NoteSort, type WallResult } from './types.js';
14
+ import { type CentreReserve, type Note, type NoteInput, type NoteLayout, type NotePatch, type NoteSort, type WallResult } from './types.js';
15
15
  /** Path of the exact route, under the shared `/api` channel. */
16
16
  export declare const EXECUTE_PATH = "/api/skillre-sticky-wall/execute";
17
17
  /** One buffered exact Fetch route as the Connection registry accepts it. */
@@ -36,7 +36,12 @@ export interface WallActions {
36
36
  remove(ids: string[]): Promise<string[]>;
37
37
  clearArchived(): Promise<string[]>;
38
38
  move(id: string, layout: NoteLayout): Promise<Note>;
39
- arrange(): Promise<Note[]>;
39
+ arrange(options?: {
40
+ centreReserve?: CentreReserve | undefined;
41
+ }): Promise<Note[]>;
42
+ create(input: NoteInput, id?: string, options?: {
43
+ centreReserve?: CentreReserve | undefined;
44
+ }): Promise<Note>;
40
45
  }
41
46
  /**
42
47
  * Build the exact route Connection registers; every failure stays inside the
package/lib/transport.js CHANGED
@@ -42,6 +42,17 @@ const layoutSchema = z
42
42
  width: z.enum(WIDTHS),
43
43
  })
44
44
  .strict();
45
+ /**
46
+ * The clear rectangle the Client reserves around the wall's centrepiece.
47
+ *
48
+ * Bounds are NOT enforced here for the same reason the layout's are not: the
49
+ * store normalizes with `normalizeReserve`, which caps an absurd value instead of
50
+ * erroring, so a deeply zoomed-out wall still gets a wall. Non-finite values are
51
+ * refused, because there is no sensible clamp for NaN.
52
+ */
53
+ const reserveSchema = z
54
+ .object({ halfWidth: z.number().finite(), halfHeight: z.number().finite() })
55
+ .strict();
45
56
  const requestSchema = z.discriminatedUnion('action', [
46
57
  z.object({ action: z.literal('list'), includeArchived: z.boolean().optional(), sort: sortSchema.optional() }).strict(),
47
58
  z
@@ -57,6 +68,9 @@ const requestSchema = z.discriminatedUnion('action', [
57
68
  layout: layoutSchema.nullable().optional(),
58
69
  })
59
70
  .strict(),
71
+ // The Client's zoom-corrected centre reserve, so a note created without a
72
+ // layout is placed in a gap that is genuinely free on screen.
73
+ centreReserve: reserveSchema.optional(),
60
74
  })
61
75
  .strict(),
62
76
  z
@@ -79,7 +93,7 @@ const requestSchema = z.discriminatedUnion('action', [
79
93
  z.object({ action: z.literal('delete'), ids: idsSchema }).strict(),
80
94
  z.object({ action: z.literal('clear-archived') }).strict(),
81
95
  z.object({ action: z.literal('move'), id: idSchema, layout: layoutSchema }).strict(),
82
- z.object({ action: z.literal('arrange') }).strict(),
96
+ z.object({ action: z.literal('arrange'), centreReserve: reserveSchema.optional() }).strict(),
83
97
  ]);
84
98
  /** A JSON response with no-store caching; the wall is always live state. */
85
99
  function json(body, status = 200) {
@@ -103,7 +117,7 @@ async function dispatch(actions, request) {
103
117
  case 'list':
104
118
  return { notes: actions.list(request.includeArchived, request.sort) };
105
119
  case 'create':
106
- return { action: 'create', changed: [await actions.create(request.note)], removed: [] };
120
+ return { action: 'create', changed: [await actions.create(request.note, undefined, { centreReserve: request.centreReserve })], removed: [] };
107
121
  case 'update':
108
122
  return { action: 'update', changed: [await actions.update(request.id, request.patch)], removed: [] };
109
123
  case 'archive':
@@ -115,7 +129,7 @@ async function dispatch(actions, request) {
115
129
  case 'move':
116
130
  return { action: 'move', changed: [await actions.move(request.id, request.layout)], removed: [] };
117
131
  case 'arrange':
118
- return { action: 'arrange', changed: await actions.arrange(), removed: [] };
132
+ return { action: 'arrange', changed: await actions.arrange({ centreReserve: request.centreReserve }), removed: [] };
119
133
  }
120
134
  }
121
135
  /**
package/lib/types.d.ts CHANGED
@@ -48,14 +48,31 @@ export type NoteWidth = (typeof WIDTHS)[number];
48
48
  /** Rendered card width for each preset, in world pixels at zoom 1. */
49
49
  export declare const WIDTH_PX: Readonly<Record<NoteWidth, number>>;
50
50
  /**
51
- * Radius of the clear disc the tidy pass leaves at the wall's centre, in world
52
- * pixels at zoom 1.
51
+ * The clear RECTANGLE the wall leaves around its centrepiece.
53
52
  *
54
- * The centre of the wall is its centrepiece: the greeting, the running tally and
55
- * the quick-capture field live there. Packing a card on top of them would make
56
- * the wall fight its own middle, so tidy starts every card outside this radius.
53
+ * The middle of the wall is not empty space — it holds the greeting, the running
54
+ * tally and the quick-capture field. Those three are one stacked block, roughly
55
+ * twice as wide as it is tall, so a circular reserve was the wrong shape: it
56
+ * wasted a tall column of paper above and below the field while still letting a
57
+ * wide card reach in from the side.
58
+ *
59
+ * The numbers are the shipped centrepiece at zoom 1 (560px wide, ~140px tall)
60
+ * plus a margin, in world pixels. The Client re-derives a zoom-corrected version
61
+ * of this rectangle from the rendered DOM before it asks the Host to tidy, so a
62
+ * zoomed-out wall reserves proportionally more world space — see
63
+ * `WallPage.centreReserve`.
57
64
  */
58
- export declare const CENTRE_RADIUS = 300;
65
+ export declare const CENTRE_RESERVE: Readonly<{
66
+ halfWidth: 330;
67
+ halfHeight: 136;
68
+ }>;
69
+ /** Half-extents of a clear rectangle around the wall's centrepiece. */
70
+ export interface CentreReserve {
71
+ /** Half-width in world pixels. */
72
+ halfWidth: number;
73
+ /** Half-height in world pixels. */
74
+ halfHeight: number;
75
+ }
59
76
  /** Bounds of the free canvas: a note may sit anywhere inside this square. */
60
77
  export declare const LAYOUT_LIMITS: Readonly<{
61
78
  /** Absolute value of x and y, in world pixels. */
@@ -121,6 +138,7 @@ export type WallRequest = {
121
138
  } | {
122
139
  action: 'create';
123
140
  note: NoteInput;
141
+ centreReserve?: CentreReserve;
124
142
  } | {
125
143
  action: 'update';
126
144
  id: string;
@@ -140,6 +158,7 @@ export type WallRequest = {
140
158
  layout: NoteLayout;
141
159
  } | {
142
160
  action: 'arrange';
161
+ centreReserve?: CentreReserve;
143
162
  };
144
163
  /** The fields a Client may submit when creating a note. */
145
164
  export interface NoteInput {
package/lib/types.js CHANGED
@@ -56,14 +56,21 @@ export const WIDTH_PX = Object.freeze({
56
56
  lg: 276,
57
57
  });
58
58
  /**
59
- * Radius of the clear disc the tidy pass leaves at the wall's centre, in world
60
- * pixels at zoom 1.
59
+ * The clear RECTANGLE the wall leaves around its centrepiece.
61
60
  *
62
- * The centre of the wall is its centrepiece: the greeting, the running tally and
63
- * the quick-capture field live there. Packing a card on top of them would make
64
- * the wall fight its own middle, so tidy starts every card outside this radius.
61
+ * The middle of the wall is not empty space — it holds the greeting, the running
62
+ * tally and the quick-capture field. Those three are one stacked block, roughly
63
+ * twice as wide as it is tall, so a circular reserve was the wrong shape: it
64
+ * wasted a tall column of paper above and below the field while still letting a
65
+ * wide card reach in from the side.
66
+ *
67
+ * The numbers are the shipped centrepiece at zoom 1 (560px wide, ~140px tall)
68
+ * plus a margin, in world pixels. The Client re-derives a zoom-corrected version
69
+ * of this rectangle from the rendered DOM before it asks the Host to tidy, so a
70
+ * zoomed-out wall reserves proportionally more world space — see
71
+ * `WallPage.centreReserve`.
65
72
  */
66
- export const CENTRE_RADIUS = 300;
73
+ export const CENTRE_RESERVE = Object.freeze({ halfWidth: 330, halfHeight: 136 });
67
74
  /** Bounds of the free canvas: a note may sit anywhere inside this square. */
68
75
  export const LAYOUT_LIMITS = Object.freeze({
69
76
  /** Absolute value of x and y, in world pixels. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillre/dsh-plugin-sticky-wall",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "便签墙:DSH 侧栏的自由画布便签板,可拖动摆放、一键整理,正文按 Markdown 渲染",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",