@milesroxas/design-hub 0.7.0 → 0.8.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.
@@ -3,7 +3,10 @@ import { test } from 'node:test';
3
3
  import {
4
4
  type Draft,
5
5
  draftOf,
6
+ filtered,
7
+ filterNote,
6
8
  initialView,
9
+ lensOf,
7
10
  roundOf,
8
11
  scopeOf,
9
12
  stepFrom,
@@ -18,8 +21,16 @@ const run = (start: View, ...actions: ViewAction[]) => actions.reduce(view, star
18
21
  const wholePage: Draft = { target: null, offset: null };
19
22
 
20
23
  test('the layer starts with comment mode off, hidden or not as it was left', () => {
21
- assert.deepEqual(initialView(false), { hidden: false, commenting: false, card: null, resolved: false });
24
+ assert.deepEqual(initialView(false), {
25
+ hidden: false,
26
+ commenting: false,
27
+ card: null,
28
+ resolved: false,
29
+ filter: 'all',
30
+ clientView: false,
31
+ });
22
32
  assert.equal(initialView(true).hidden, true);
33
+ assert.equal(initialView(false, true).clientView, true);
23
34
  });
24
35
 
25
36
  test('start turns comment mode on with no card; stop turns it off and drops the card', () => {
@@ -153,3 +164,64 @@ test('the toggle reads Page only while a page comment is being written', () => {
153
164
  assert.equal(scopeOf({ type: 'draft', draft: { target: {} as Element, offset: { x: 0, y: 0 } } }), 'pin');
154
165
  assert.equal(scopeOf({ type: 'thread', id: 'x' }), 'pin');
155
166
  });
167
+
168
+ test('the filter narrows by audience and survives the mode turning off and on', () => {
169
+ const state = run(
170
+ initialView(false),
171
+ { type: 'filter', filter: 'internal' },
172
+ { type: 'start' },
173
+ { type: 'open', id: 'c1' },
174
+ { type: 'stop' },
175
+ );
176
+ assert.equal(state.filter, 'internal');
177
+ assert.equal(view(state, { type: 'filter', filter: 'all' }).filter, 'all');
178
+ });
179
+
180
+ test('Client view turns on and off, closes the card and sets the filter back to all', () => {
181
+ const on = run(
182
+ initialView(false),
183
+ { type: 'start' },
184
+ { type: 'filter', filter: 'client' },
185
+ { type: 'open', id: 'c1' },
186
+ { type: 'clientView', on: true },
187
+ );
188
+ assert.deepEqual([on.clientView, on.card, on.filter, on.commenting], [true, null, 'all', true]);
189
+ const off = view(on, { type: 'clientView', on: false });
190
+ assert.deepEqual([off.clientView, off.card], [false, null]);
191
+ // Hiding comments leaves Client view as it was.
192
+ assert.equal(run(on, { type: 'hide' }, { type: 'show' }).clientView, true);
193
+ });
194
+
195
+ test('the lens: Studio sees as Studio until Client view; a Client never does, whatever was stored', () => {
196
+ assert.deepEqual(lensOf(true, { clientView: false }), { asStudio: true, clientView: false });
197
+ assert.deepEqual(lensOf(true, { clientView: true }), { asStudio: false, clientView: true });
198
+ assert.deepEqual(lensOf(false, { clientView: true }), { asStudio: false, clientView: false });
199
+ assert.deepEqual(lensOf(false, { clientView: false }), { asStudio: false, clientView: false });
200
+ });
201
+
202
+ test('filtered lets through all, one audience, or everything the server sent in Client view', () => {
203
+ const threads = [
204
+ { id: 'i', audience: 'internal' },
205
+ { id: 'k', audience: 'client' },
206
+ ];
207
+ const ids = (cs: { id: string }[]) => cs.map((c) => c.id);
208
+ assert.deepEqual(ids(filtered(threads, { filter: 'all', clientView: false })), ['i', 'k']);
209
+ assert.deepEqual(ids(filtered(threads, { filter: 'internal', clientView: false })), ['i']);
210
+ assert.deepEqual(ids(filtered(threads, { filter: 'client', clientView: false })), ['k']);
211
+ assert.deepEqual(ids(filtered(threads, { filter: 'internal', clientView: true })), ['i', 'k']);
212
+ });
213
+
214
+ test('the bar names a narrowing filter, and says nothing with All or in Client view', () => {
215
+ assert.equal(filterNote({ filter: 'all', clientView: false }), null);
216
+ assert.equal(filterNote({ filter: 'internal', clientView: false }), 'Internal only');
217
+ assert.equal(filterNote({ filter: 'client', clientView: false }), 'Client-facing only');
218
+ assert.equal(filterNote({ filter: 'internal', clientView: true }), null);
219
+ // Turning Client view on sets the filter back to All, so leaving it shows no stale note.
220
+ const left = run(
221
+ initialView(false),
222
+ { type: 'filter', filter: 'client' },
223
+ { type: 'clientView', on: true },
224
+ { type: 'clientView', on: false },
225
+ );
226
+ assert.equal(filterNote(left), null);
227
+ });
@@ -4,6 +4,9 @@
4
4
  /** A new comment being placed: the element it is about and where on it, as fractions of its box, or neither for the whole page. */
5
5
  export type Draft = { target: Element | null; offset: { x: number; y: number } | null };
6
6
 
7
+ /** Which threads Studio lists: every one, or one audience. Matches core's Audience values. */
8
+ export type Filter = 'all' | 'internal' | 'client';
9
+
7
10
  /** The one card on screen: a thread, a comment being written, or the people. */
8
11
  export type Card = { type: 'thread'; id: string } | { type: 'draft'; draft: Draft } | { type: 'people' };
9
12
 
@@ -12,13 +15,18 @@ export type Card = { type: 'thread'; id: string } | { type: 'draft'; draft: Draf
12
15
  * field it touches at once and no two fields can disagree. `commenting` is
13
16
  * comment mode: pins on the page and a click anywhere starts a comment. Off,
14
17
  * the page carries only the button. `hidden` tucks even the button into the
15
- * screen's edge; it is the one field that outlives the page (kit/prefs.ts).
18
+ * screen's edge. `filter` narrows Studio's list by audience, in memory like
19
+ * `resolved`. `clientView` is Studio looking as a Client does: the list is
20
+ * fetched as a Client's and Studio's controls step aside. `hidden` and
21
+ * `clientView` outlive the page (kit/prefs.ts).
16
22
  */
17
23
  export type View = {
18
24
  hidden: boolean;
19
25
  commenting: boolean;
20
26
  card: Card | null;
21
27
  resolved: boolean;
28
+ filter: Filter;
29
+ clientView: boolean;
22
30
  };
23
31
 
24
32
  export type ViewAction =
@@ -31,13 +39,17 @@ export type ViewAction =
31
39
  | { type: 'escape' }
32
40
  | { type: 'resolved' }
33
41
  | { type: 'hide' }
34
- | { type: 'show' };
42
+ | { type: 'show' }
43
+ | { type: 'filter'; filter: Filter }
44
+ | { type: 'clientView'; on: boolean };
35
45
 
36
- export const initialView = (hidden: boolean): View => ({
46
+ export const initialView = (hidden: boolean, clientView = false): View => ({
37
47
  hidden,
38
48
  commenting: false,
39
49
  card: null,
40
50
  resolved: false,
51
+ filter: 'all',
52
+ clientView,
41
53
  });
42
54
 
43
55
  export function view(state: View, action: ViewAction): View {
@@ -64,9 +76,43 @@ export function view(state: View, action: ViewAction): View {
64
76
  return { ...state, hidden: true, commenting: false, card: null };
65
77
  case 'show':
66
78
  return { ...state, hidden: false };
79
+ case 'filter':
80
+ return { ...state, filter: action.filter };
81
+ // The other view holds other threads: the card closes, and the filter goes back to all, as a Client has none.
82
+ case 'clientView':
83
+ return { ...state, clientView: action.on, filter: 'all', card: null };
67
84
  }
68
85
  }
69
86
 
87
+ /**
88
+ * How the layer looks to this person. `studio` is whether the policy gives
89
+ * them Studio's view. As Studio: audience marks, the filter and the choice on
90
+ * a new thread. In Client view, Studio sees none of that, as a Client does.
91
+ */
92
+ export function lensOf(studio: boolean, v: Pick<View, 'clientView'>) {
93
+ return { asStudio: studio && !v.clientView, clientView: studio && v.clientView };
94
+ }
95
+
96
+ const FILTER_NOTE = { internal: 'Internal only', client: 'Client-facing only' } as const;
97
+
98
+ /**
99
+ * What the bar says while the filter narrows the list, so Studio never
100
+ * forgets a thread is out of sight; null with All, and in Client view, which
101
+ * has no filter.
102
+ */
103
+ export function filterNote(v: Pick<View, 'filter' | 'clientView'>): string | null {
104
+ return v.clientView || v.filter === 'all' ? null : FILTER_NOTE[v.filter];
105
+ }
106
+
107
+ /** The threads the filter lets through; in Client view, the list is already a Client's. */
108
+ export function filtered<T extends { audience: string }>(
109
+ roots: T[],
110
+ v: Pick<View, 'filter' | 'clientView'>,
111
+ ): T[] {
112
+ if (v.clientView || v.filter === 'all') return roots;
113
+ return roots.filter((c) => c.audience === v.filter);
114
+ }
115
+
70
116
  type Thread = { id: string; status: 'open' | 'resolved' };
71
117
 
72
118
  /** The threads comment mode steps through: the open ones, the resolved too when shown, and always the open card's, so resolving it never pulls the card away. */
@@ -7,6 +7,8 @@ description: "Work from review comments on the deployed prototypes: pull them in
7
7
 
8
8
  Each comment is pinned to a prototype, its state (the URL and every dial value) and, usually, an element. The repo gets them as `docs/sprints/<feature>/comments.md`, grouped by README state, then by kind. That file is generated: read it, never edit it, and close comments in the store.
9
9
 
10
+ Each thread line starts with its number, as the panel shows it, and its audience: `- #3 (internal) Ed (Studio): ...` or `- #4 (client-facing) Rae (Acme): ...`. A number is fixed and never reused, so gaps are normal. An internal thread is the studio's own note and no client ever sees it; a client-facing one is read by everyone, Studio's replies in it included.
11
+
10
12
  ## Working from comments
11
13
 
12
14
  1. **Pull**, from the project root: `pnpm comments pull`. The JSON's `store` says which store it read: `deployed` when `.env` holds the store's credentials, `local` otherwise. Say which to the user, because local comments are only yours.
@@ -24,11 +26,11 @@ Each comment is pinned to a prototype, its state (the URL and every dial value)
24
26
  ```
25
27
  Why taste waits: one reviewer's preference, built at once, overwrites a decision the team made and the next reviewer argues the other way. The user decides taste; bugs and copy are not taste.
26
28
  4. **Resolve** with `pnpm comments resolve <id>`, or in the panel, only once the change is live. Why: a reviewer who opens a resolved comment and still sees the old state stops trusting the list.
27
- 5. **Report** to the user: what was fixed, by comment id; the taste calls waiting for them; any comment with no state.
29
+ 5. **Report** to the user: what was fixed, by number and comment id; the taste calls waiting for them; any comment with no state. Say which threads were internal, because the client never saw those.
28
30
 
29
31
  ## People
30
32
 
31
- - Every person is **Studio** or **Client**. Both comment, reply, edit their own words, and resolve or reopen any thread. Studio also deletes any comment, sorts comments and manages people; a Client deletes only their own. The studio's team are Studio; everyone on the client's side is Client, the default.
33
+ - Every person is **Studio** or **Client**. Both comment, reply, edit their own words, and resolve or reopen any thread they can see. A Client sees client-facing threads only; Studio sees all, internal ones included. A thread's audience never changes: to tell the client what an internal thread says, Studio writes a new client-facing comment in the panel. Never paste internal words into a client-facing one without the user's say. Studio also deletes any comment, sorts comments and manages people; a Client deletes only their own. The studio's team are Studio; everyone on the client's side is Client, the default.
32
34
  - **Team** is the company: `Studio`, or the client's name. It shows beside every name, so a reviewer reads who said what.
33
35
  - The first Studio person comes from `pnpm people add --name <n> --team <t> --kind studio --site <url>`; after that, Studio adds people from the People tab.
34
36
  - A link signs in one device, then stops working; unused, it lasts 14 days. `pnpm people link <id>` gives another for another device, `sign-out <id>` ends every session and gives one new link, and `revoke <id>` ends their access everywhere within five minutes. `miles-deploy` holds the rest: access length, the handover.