@buffcore/admin-shell 0.8.44 → 0.8.46

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 (151) hide show
  1. package/dist/components/Markdown.d.ts +9 -3
  2. package/dist/components/Markdown.js +84 -34
  3. package/dist/components/Sheet.d.ts +5 -1
  4. package/dist/components/Sheet.js +8 -2
  5. package/dist/components/TextArea.d.ts +3 -1
  6. package/dist/components/TextArea.js +3 -3
  7. package/dist/components/icons.d.ts +1 -0
  8. package/dist/components/icons.js +1 -0
  9. package/dist/prototype/SceneSignal.d.ts +2 -1
  10. package/dist/prototype/SceneSignal.js +12 -1
  11. package/dist/prototype/scene-status.d.ts +1 -2
  12. package/dist/prototype/scene-status.js +1 -2
  13. package/dist/prototype/scene.d.ts +1 -1
  14. package/dist/prototype/scene.js +20 -3
  15. package/dist/workbench/app/ServedPrototype.js +5 -0
  16. package/dist/workbench/app/__snapshots__/places-dom.test.tsx.snap +7 -7
  17. package/dist/workbench/app/actions.d.ts +4 -2
  18. package/dist/workbench/app/actions.js +9 -4
  19. package/dist/workbench/app/brief-short.d.ts +14 -0
  20. package/dist/workbench/app/brief-short.js +103 -0
  21. package/dist/workbench/app/chat-session.d.ts +3 -3
  22. package/dist/workbench/app/chat-session.js +8 -3
  23. package/dist/workbench/app/chat.d.ts +15 -2
  24. package/dist/workbench/app/chat.js +9 -4
  25. package/dist/workbench/app/loop.js +2 -18
  26. package/dist/workbench/app/prototype.js +3 -0
  27. package/dist/workbench/app/test/loop-fixture.d.ts +10 -0
  28. package/dist/workbench/app/useStudio.d.ts +2 -1
  29. package/dist/workbench/studio/frame/AgentPanel.js +24 -1
  30. package/dist/workbench/studio/frame/PanelList.js +1 -1
  31. package/dist/workbench/studio/frame/Segmented.d.ts +3 -1
  32. package/dist/workbench/studio/frame/Segmented.js +4 -3
  33. package/dist/workbench/studio/frame/StudioFrame.js +3 -3
  34. package/dist/workbench/studio/frame/StudioRegions.js +4 -1
  35. package/dist/workbench/studio/frame/TurnControls.d.ts +2 -1
  36. package/dist/workbench/studio/frame/TurnControls.js +4 -1
  37. package/dist/workbench/studio/frame/layout.d.ts +2 -0
  38. package/dist/workbench/studio/frame/layout.js +2 -0
  39. package/dist/workbench/studio/frame/panelControls.d.ts +21 -1
  40. package/dist/workbench/studio/frame/scrollbars.d.ts +1 -1
  41. package/dist/workbench/studio/frame/scrollbars.js +5 -3
  42. package/dist/workbench/studio/frame/useTurnDraft.d.ts +20 -2
  43. package/dist/workbench/studio/frame/useTurnDraft.js +39 -10
  44. package/dist/workbench/studio/i18n/index.js +6 -0
  45. package/dist/workbench/studio/i18n/loop.en.d.ts +11 -38
  46. package/dist/workbench/studio/i18n/loop.en.js +11 -38
  47. package/dist/workbench/studio/i18n/loop.es.json +11 -38
  48. package/dist/workbench/studio/i18n/marks.en.d.ts +41 -0
  49. package/dist/workbench/studio/i18n/marks.en.js +42 -0
  50. package/dist/workbench/studio/i18n/marks.es.json +40 -0
  51. package/dist/workbench/studio/i18n/start.en.d.ts +5 -0
  52. package/dist/workbench/studio/i18n/start.en.js +7 -2
  53. package/dist/workbench/studio/i18n/start.es.json +7 -2
  54. package/dist/workbench/studio/i18n/workspace.en.d.ts +45 -0
  55. package/dist/workbench/studio/i18n/workspace.en.js +46 -0
  56. package/dist/workbench/studio/i18n/workspace.es.json +44 -0
  57. package/dist/workbench/studio/loop/BriefDocument.d.ts +9 -6
  58. package/dist/workbench/studio/loop/BriefDocument.js +48 -76
  59. package/dist/workbench/studio/loop/BriefLists.d.ts +11 -0
  60. package/dist/workbench/studio/loop/BriefLists.js +42 -0
  61. package/dist/workbench/studio/loop/BriefPage.d.ts +6 -2
  62. package/dist/workbench/studio/loop/BriefPage.js +32 -4
  63. package/dist/workbench/studio/loop/BriefReading.d.ts +19 -0
  64. package/dist/workbench/studio/loop/BriefReading.js +22 -0
  65. package/dist/workbench/studio/loop/BriefSection.d.ts +22 -0
  66. package/dist/workbench/studio/loop/BriefSection.js +47 -0
  67. package/dist/workbench/studio/loop/BriefWho.d.ts +6 -0
  68. package/dist/workbench/studio/loop/BriefWho.js +56 -0
  69. package/dist/workbench/studio/loop/CanvasBar.d.ts +0 -1
  70. package/dist/workbench/studio/loop/CanvasBar.js +2 -3
  71. package/dist/workbench/studio/loop/ConsoleFrame.d.ts +13 -0
  72. package/dist/workbench/studio/loop/ConsoleFrame.js +29 -0
  73. package/dist/workbench/studio/loop/NotThisCard.d.ts +6 -1
  74. package/dist/workbench/studio/loop/NotThisCard.js +28 -20
  75. package/dist/workbench/studio/loop/ProtoJourneys.d.ts +1 -8
  76. package/dist/workbench/studio/loop/ProtoJourneys.js +0 -14
  77. package/dist/workbench/studio/loop/PrototypeApp.d.ts +3 -1
  78. package/dist/workbench/studio/loop/PrototypeApp.js +24 -9
  79. package/dist/workbench/studio/loop/PrototypeAttempt.js +55 -14
  80. package/dist/workbench/studio/loop/PrototypePage.d.ts +4 -2
  81. package/dist/workbench/studio/loop/PrototypePage.js +25 -1
  82. package/dist/workbench/studio/loop/PrototypePreview.d.ts +35 -6
  83. package/dist/workbench/studio/loop/PrototypePreview.js +126 -80
  84. package/dist/workbench/studio/loop/PrototypePreviewSlot.d.ts +13 -0
  85. package/dist/workbench/studio/loop/PrototypePreviewSlot.js +23 -0
  86. package/dist/workbench/studio/loop/PrototypeScenes.d.ts +1 -1
  87. package/dist/workbench/studio/loop/ServedPlanning.js +1 -1
  88. package/dist/workbench/studio/loop/StudioLoop.d.ts +7 -2
  89. package/dist/workbench/studio/loop/StudioLoop.js +4 -10
  90. package/dist/workbench/studio/loop/WorkspaceBar.d.ts +15 -0
  91. package/dist/workbench/studio/loop/WorkspaceBar.js +52 -0
  92. package/dist/workbench/studio/loop/WorkspaceJourneys.d.ts +17 -0
  93. package/dist/workbench/studio/loop/WorkspaceJourneys.js +99 -0
  94. package/dist/workbench/studio/loop/WorkspaceLeft.d.ts +14 -0
  95. package/dist/workbench/studio/loop/WorkspaceLeft.js +42 -0
  96. package/dist/workbench/studio/loop/WorkspaceStage.d.ts +24 -0
  97. package/dist/workbench/studio/loop/WorkspaceStage.js +142 -0
  98. package/dist/workbench/studio/loop/WorkspaceSteps.d.ts +20 -0
  99. package/dist/workbench/studio/loop/WorkspaceSteps.js +96 -0
  100. package/dist/workbench/studio/loop/moments.js +0 -3
  101. package/dist/workbench/studio/loop/prototype-document.d.ts +2 -0
  102. package/dist/workbench/studio/loop/prototype-document.js +12 -0
  103. package/dist/workbench/studio/loop/prototype-part.d.ts +43 -0
  104. package/dist/workbench/studio/loop/prototype-part.js +104 -0
  105. package/dist/workbench/studio/loop/types.d.ts +26 -26
  106. package/dist/workbench/studio/loop/types.js +0 -3
  107. package/dist/workbench/studio/loop/usePrototypeFrame.d.ts +3 -0
  108. package/dist/workbench/studio/loop/usePrototypeFrame.js +2 -0
  109. package/dist/workbench/studio/loop/workspace-journeys.d.ts +22 -0
  110. package/dist/workbench/studio/loop/workspace-journeys.js +63 -0
  111. package/dist/workbench/studio/loop/workspace-state.d.ts +94 -0
  112. package/dist/workbench/studio/loop/workspace-state.js +50 -0
  113. package/dist/workbench/studio/marks/ChangeList.d.ts +7 -0
  114. package/dist/workbench/studio/marks/ChangeList.js +70 -0
  115. package/dist/workbench/studio/marks/MarkHint.d.ts +18 -0
  116. package/dist/workbench/studio/marks/MarkHint.js +58 -0
  117. package/dist/workbench/studio/marks/MarkNumber.d.ts +6 -0
  118. package/dist/workbench/studio/marks/MarkNumber.js +24 -0
  119. package/dist/workbench/studio/marks/MarksLayer.d.ts +15 -0
  120. package/dist/workbench/studio/marks/MarksLayer.js +144 -0
  121. package/dist/workbench/studio/marks/PinNote.d.ts +13 -0
  122. package/dist/workbench/studio/marks/PinNote.js +49 -0
  123. package/dist/workbench/studio/marks/QueuedChanges.d.ts +6 -0
  124. package/dist/workbench/studio/marks/QueuedChanges.js +51 -0
  125. package/dist/workbench/studio/marks/WorkspaceMarks.d.ts +15 -0
  126. package/dist/workbench/studio/marks/WorkspaceMarks.js +67 -0
  127. package/dist/workbench/studio/marks/marks-message.d.ts +13 -0
  128. package/dist/workbench/studio/marks/marks-message.js +93 -0
  129. package/dist/workbench/studio/marks/marks.d.ts +105 -0
  130. package/dist/workbench/studio/marks/marks.js +133 -0
  131. package/dist/workbench/studio/marks/useMarking.d.ts +36 -0
  132. package/dist/workbench/studio/marks/useMarking.js +111 -0
  133. package/dist/workbench/studio/marks/useSendMarks.d.ts +18 -0
  134. package/dist/workbench/studio/marks/useSendMarks.js +80 -0
  135. package/dist/workbench/studio/work/StudioLater.js +0 -1
  136. package/dist/workbench/studio/work/work-test-data.d.ts +5 -0
  137. package/package.json +6 -6
  138. package/dist/workbench/studio/loop/FsPlan.d.ts +0 -7
  139. package/dist/workbench/studio/loop/FsPlan.js +0 -64
  140. package/dist/workbench/studio/loop/FsStage.d.ts +0 -6
  141. package/dist/workbench/studio/loop/FsStage.js +0 -74
  142. package/dist/workbench/studio/loop/FsToolbar.d.ts +0 -6
  143. package/dist/workbench/studio/loop/FsToolbar.js +0 -61
  144. package/dist/workbench/studio/loop/FullScreen.d.ts +0 -5
  145. package/dist/workbench/studio/loop/FullScreen.js +0 -89
  146. package/dist/workbench/studio/loop/PrototypePreviewMenus.d.ts +0 -18
  147. package/dist/workbench/studio/loop/PrototypePreviewMenus.js +0 -75
  148. package/dist/workbench/studio/loop/PrototypePreviewToolbar.d.ts +0 -27
  149. package/dist/workbench/studio/loop/PrototypePreviewToolbar.js +0 -52
  150. package/dist/workbench/studio/loop/fsViews.d.ts +0 -12
  151. package/dist/workbench/studio/loop/fsViews.js +0 -6
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A message of marks waiting for the turn to end: one card that lists each mark with its note and
3
+ // place and the pictures that go with it, and the queue's own line (Edit, Back to the box).
4
+ import { useT } from '@buffcore/i18n/react';
5
+ import { Button } from '../../../components/Button.js';
6
+ import { Icon } from '../../../components/Icon.js';
7
+ import { captionText } from '../../../components/styles.js';
8
+ import { KIND_ICON, MarkNumber } from './MarkNumber.js';
9
+ import { markWhat, markWhere } from './marks-message.js';
10
+ const row = { display: 'flex', gap: 'var(--space-1)', alignItems: 'center' };
11
+ export function QueuedChanges({ card, agent, onUnqueue, }) {
12
+ const t = useT();
13
+ const title = t('studio.marks.queued.title', {
14
+ count: card.marks.length,
15
+ change: card.change,
16
+ version: card.version,
17
+ });
18
+ return (_jsxs("li", { "data-queued-marks": true, style: { display: 'grid', gap: 'var(--space-1)', justifyItems: 'end' }, children: [_jsxs("section", { "aria-label": title, style: {
19
+ marginInlineStart: 'var(--space-6)',
20
+ display: 'grid',
21
+ gap: 'var(--space-3)',
22
+ padding: 'var(--space-3)',
23
+ background: 'var(--surface-sunken)',
24
+ border: 'var(--border-width-hairline) dashed var(--border-default)',
25
+ borderRadius: 'var(--radius-panel)',
26
+ minWidth: 0,
27
+ justifySelf: 'stretch',
28
+ }, children: [_jsx("strong", { style: { color: 'var(--text-strong)', fontSize: 'var(--font-size-label)' }, children: title }), _jsx("ol", { style: {
29
+ listStyle: 'none',
30
+ margin: 0,
31
+ padding: 0,
32
+ display: 'grid',
33
+ gap: 'var(--space-2)',
34
+ }, children: card.marks.map((mark, i) => (_jsxs("li", { style: {
35
+ display: 'grid',
36
+ gridTemplateColumns: 'auto minmax(0, 1fr)',
37
+ gap: 'var(--space-2)',
38
+ }, children: [_jsx(MarkNumber, { n: i + 1 }), _jsxs("span", { style: { display: 'grid', minWidth: 0, overflowWrap: 'anywhere' }, children: [mark.note.trim() && (_jsx("span", { style: { fontSize: 'var(--font-size-label)', color: 'var(--text-body)' }, children: mark.note })), _jsxs("span", { style: { ...captionText, ...row }, children: [_jsx(Icon, { name: KIND_ICON[mark.kind], size: "var(--icon-sm)" }), markWhat(mark, t), " \u00B7 ", markWhere(mark, t)] })] })] }, mark.id))) }), _jsxs("span", { style: { ...captionText, ...row }, children: [_jsx(Icon, { name: "eye", size: "var(--icon-sm)" }), card.pictures
39
+ ? t('studio.marks.queued.pictures', { count: card.pictures })
40
+ : t('studio.marks.queued.noPictures')] })] }), _jsxs("span", { role: "status", style: {
41
+ ...captionText,
42
+ ...row,
43
+ flexWrap: 'wrap',
44
+ gap: 'var(--space-2)',
45
+ justifyContent: 'end',
46
+ }, children: [_jsx(Icon, { name: "clock", size: "var(--icon-sm)" }), t('studio.marks.queued.status', { agent }), _jsx(Button, { size: "sm", variant: "ghost", icon: "pencil", onClick: () => {
47
+ onUnqueue?.();
48
+ // The marks are listed again above the box: the first note takes the cursor.
49
+ requestAnimationFrame(() => document.querySelector('[data-change-list] textarea')?.focus());
50
+ }, children: t('studio.marks.queued.edit') }), _jsx(Button, { size: "sm", variant: "ghost", onClick: onUnqueue, children: t('studio.frame.turn.unqueue') })] })] }));
51
+ }
@@ -0,0 +1,15 @@
1
+ import { type WorkspaceSetup, type WorkspaceStage } from '../loop/workspace-state.tsx';
2
+ import { type MarkPlace, type MarksPage } from './marks.ts';
3
+ /** The place the stage shows now, as a mark records it. */
4
+ export declare function stagePlace(stage: WorkspaceStage, start: string): MarkPlace;
5
+ /** The marks layer over the stage's screen, for the sheet `sheet`; nothing outside the stage. */
6
+ export declare function MarksOverlay({ sheet }: {
7
+ sheet: string;
8
+ }): import("react").JSX.Element | null;
9
+ /**
10
+ * What marking gives the workspace for a page (a change's version on view): the overlay and the
11
+ * count of marks waiting, for the phone-wide foot bar's Changes. None without a version.
12
+ */
13
+ export declare function useWorkspaceMarks(page: (Pick<MarksPage, 'change' | 'locale' | 'shoot'> & {
14
+ version?: string;
15
+ }) | undefined): Pick<WorkspaceSetup, 'overlay' | 'changes'> | undefined;
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Marking in the prototype workspace: the marks layer drawn over the device's screen (the
3
+ // workspace's overlay), the tool from the workspace's bar and keys, the place each mark is made on
4
+ // (the app, the device, the journey step or sample data shown), and showing a listed mark again.
5
+ import { useT } from '@buffcore/i18n/react';
6
+ import { useEffect, useMemo, useRef } from 'react';
7
+ import { pageMode } from '../frame/layout.js';
8
+ import { useWorkspace, useWorkspaceStage, } from '../loop/workspace-state.js';
9
+ import { useToolKeys } from './MarkHint.js';
10
+ import { MarksLayer } from './MarksLayer.js';
11
+ import { marks, useMarkSheet, useMarksPage, useShownMark, } from './marks.js';
12
+ /** The place the stage shows now, as a mark records it. */
13
+ export function stagePlace(stage, start) {
14
+ const { where } = stage;
15
+ const turned = stage.device === 'tablet' && stage.orientation === 'landscape';
16
+ return {
17
+ app: stage.app,
18
+ screen: where.screen || start,
19
+ device: stage.device,
20
+ ...(turned ? { orientation: 'landscape' } : {}),
21
+ ...(where.journey !== undefined ? { journey: where.journey, step: where.step ?? 0 } : {}),
22
+ ...(where.journey === undefined && where.data && where.data !== 'full'
23
+ ? { data: where.data }
24
+ : {}),
25
+ };
26
+ }
27
+ /** The marks layer over the stage's screen, for the sheet `sheet`; nothing outside the stage. */
28
+ export function MarksOverlay({ sheet }) {
29
+ const t = useT();
30
+ const stage = useWorkspaceStage();
31
+ const space = useWorkspace();
32
+ useToolKeys(space.setTool, space.app === 'console');
33
+ const screen = stage?.screen ?? null;
34
+ const frame = useMemo(() => ({ current: screen }), [screen]);
35
+ const shown = useShownMark();
36
+ const latest = useRef({ stage, space });
37
+ latest.current = { stage, space };
38
+ useEffect(() => {
39
+ if (!shown || shown.key !== sheet)
40
+ return;
41
+ const place = marks.sheet(sheet).marks.find((mark) => mark.id === shown.id)?.place;
42
+ if (!place)
43
+ return;
44
+ const { stage, space } = latest.current;
45
+ space.setApp(place.app ?? 'app');
46
+ if (place.app === 'console')
47
+ space.setConsole({ journey: place.journey, step: place.step ?? 0 });
48
+ else
49
+ stage?.show?.(place);
50
+ }, [shown, sheet]);
51
+ if (!stage)
52
+ return null;
53
+ return (_jsx(MarksLayer, { tool: stage.tool, sheet: sheet, place: stagePlace(stage, t('studio.marks.screen.start')), frame: frame, partAt: stage.app === 'app' ? stage.partAt : undefined }));
54
+ }
55
+ /**
56
+ * What marking gives the workspace for a page (a change's version on view): the overlay and the
57
+ * count of marks waiting, for the phone-wide foot bar's Changes. None without a version.
58
+ */
59
+ export function useWorkspaceMarks(page) {
60
+ const version = page?.version;
61
+ const key = page && version ? `${page.change}:${version}` : undefined;
62
+ const mode = pageMode() === 'dark' ? 'dark' : 'light';
63
+ useMarksPage(page && version && key ? { ...page, version, key, mode } : undefined);
64
+ const count = useMarkSheet(key).marks.length;
65
+ const overlay = useMemo(() => key && _jsx(MarksOverlay, { sheet: key }), [key]);
66
+ return useMemo(() => (key ? { overlay, changes: count } : undefined), [key, overlay, count]);
67
+ }
@@ -0,0 +1,13 @@
1
+ import type { T } from '@buffcore/i18n';
2
+ import type { Mark, MarkSheet } from './marks.ts';
3
+ /** What a mark is, for people: "Comment on Price", "Area", "Drawing". */
4
+ export declare function markWhat(mark: Mark, t: T): string;
5
+ /** Where a mark is, for people: "Plant detail · Desktop". */
6
+ export declare function markWhere(mark: Mark, t: T): string;
7
+ /** The marked screens, one picture each: a mark's screen and device, in the marks' order. */
8
+ export declare function markedScreens(list: readonly Mark[]): Mark[][];
9
+ export declare function marksMessage(sheet: MarkSheet, about: {
10
+ change: string;
11
+ version: string;
12
+ pictures: number;
13
+ }, t: T, locale: string): string;
@@ -0,0 +1,93 @@
1
+ /** What a mark is, for people: "Comment on Price", "Area", "Drawing". */
2
+ export function markWhat(mark, t) {
3
+ if (mark.kind === 'comment')
4
+ return t('studio.marks.mark.comment', { part: mark.part ?? t('studio.marks.mark.spot') });
5
+ return t(mark.kind === 'area' ? 'studio.marks.mark.area' : 'studio.marks.mark.draw');
6
+ }
7
+ /** Where a mark is, for people: "Plant detail · Desktop". */
8
+ export function markWhere(mark, t) {
9
+ return t('studio.marks.mark.where', {
10
+ screen: mark.place.screen,
11
+ device: t(`studio.loop.proto.device.${mark.place.device}`),
12
+ });
13
+ }
14
+ /** The marked screens, one picture each: a mark's screen and device, in the marks' order. */
15
+ export function markedScreens(list) {
16
+ const screens = new Map();
17
+ for (const mark of list) {
18
+ const key = JSON.stringify([mark.place, mark.view, mark.scroll]);
19
+ screens.set(key, [...(screens.get(key) ?? []), mark]);
20
+ }
21
+ return [...screens.values()];
22
+ }
23
+ function box(mark) {
24
+ if (mark.box)
25
+ return mark.box;
26
+ const points = mark.points ?? [];
27
+ const xs = points.map(([x]) => x);
28
+ const ys = points.map(([, y]) => y);
29
+ if (!xs.length)
30
+ return;
31
+ const x = Math.min(...xs);
32
+ const y = Math.min(...ys);
33
+ return { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y };
34
+ }
35
+ /** A mark's box in page terms: on the screen, plus how far the page and its scroller were scrolled. */
36
+ function pageBox(mark) {
37
+ const area = box(mark);
38
+ const scroll = mark.scroll;
39
+ if (!area || !scroll)
40
+ return area;
41
+ return {
42
+ ...area,
43
+ x: area.x + scroll.page.x + scroll.inner.x,
44
+ y: area.y + scroll.page.y + scroll.inner.y,
45
+ };
46
+ }
47
+ function place(mark, t, number) {
48
+ const area = pageBox(mark);
49
+ const size = { width: number(mark.view.width), height: number(mark.view.height) };
50
+ const parts = [
51
+ area &&
52
+ (mark.kind === 'comment'
53
+ ? t('studio.marks.message.point', { x: number(area.x), y: number(area.y), ...size })
54
+ : t('studio.marks.message.box', {
55
+ x: number(area.x),
56
+ y: number(area.y),
57
+ w: number(area.w),
58
+ h: number(area.h),
59
+ ...size,
60
+ })),
61
+ mark.place.journey &&
62
+ t('studio.marks.message.journey', {
63
+ journey: JSON.stringify(mark.place.journey),
64
+ step: number((mark.place.step ?? 0) + 1),
65
+ }),
66
+ mark.place.data && t('studio.marks.message.data', { data: mark.place.data }),
67
+ ];
68
+ return parts.filter(Boolean).join('; ');
69
+ }
70
+ export function marksMessage(sheet, about, t, locale) {
71
+ const format = new Intl.NumberFormat(locale, { maximumFractionDigits: 0 });
72
+ const number = (value) => format.format(value);
73
+ const lines = [
74
+ t('studio.marks.message.head', {
75
+ count: sheet.marks.length,
76
+ change: about.change,
77
+ version: about.version,
78
+ }),
79
+ ...(about.pictures ? [t('studio.marks.message.pictures', { count: about.pictures })] : []),
80
+ '',
81
+ ...sheet.marks.map((mark, i) => t('studio.marks.message.mark', {
82
+ n: number(i + 1),
83
+ what: markWhat(mark, t),
84
+ where: markWhere(mark, t),
85
+ place: place(mark, t, number),
86
+ note: mark.note.trim() || t('studio.marks.message.noNote'),
87
+ })),
88
+ ];
89
+ const more = sheet.more.trim();
90
+ if (more)
91
+ lines.push('', t('studio.marks.message.more', { text: more }));
92
+ return lines.join('\n');
93
+ }
@@ -0,0 +1,105 @@
1
+ import type { Attachment, MarkScroll, MarkShotBody } from '@buffcore/contracts/workbench';
2
+ export type MarkTool = 'select' | 'comment' | 'draw' | 'area';
3
+ export type MarkKind = Exclude<MarkTool, 'select'>;
4
+ export type MarkDevice = 'mobile' | 'tablet' | 'desktop';
5
+ export type MarkBox = {
6
+ x: number;
7
+ y: number;
8
+ w: number;
9
+ h: number;
10
+ };
11
+ /** Where a mark was made: the screen's name for people, and the choice that shows it again. */
12
+ export type MarkApp = 'app' | 'console';
13
+ export interface MarkPlace {
14
+ /** The customer app or the console; none is the customer app. */
15
+ app?: MarkApp;
16
+ screen: string;
17
+ device: MarkDevice;
18
+ /** A tablet turned on its side; none is upright. */
19
+ orientation?: 'landscape';
20
+ journey?: string;
21
+ step?: number;
22
+ data?: string;
23
+ }
24
+ export interface Mark {
25
+ id: number;
26
+ kind: MarkKind;
27
+ note: string;
28
+ /** A comment's part, as the app named it; none for "this spot". */
29
+ part?: string;
30
+ place: MarkPlace;
31
+ /** The app's page size when marked, in its own px: the picture is shot at this size. */
32
+ view: {
33
+ width: number;
34
+ height: number;
35
+ };
36
+ /** A comment's point (w = h = 0) or an area's box, in the app's px. */
37
+ box?: MarkBox;
38
+ /** A drawing's points, in the app's px. */
39
+ points?: readonly (readonly [number, number])[];
40
+ /** How far the app was scrolled (as it said): the px above are on the screen at that scroll. */
41
+ scroll?: MarkScroll;
42
+ }
43
+ export interface MarkSheet {
44
+ marks: readonly Mark[];
45
+ more: string;
46
+ }
47
+ /** The open Prototype page: its sheet, and how it shoots a marked screen. */
48
+ export interface MarksPage {
49
+ key: string;
50
+ change: string;
51
+ version: string;
52
+ locale: string;
53
+ mode: 'light' | 'dark';
54
+ shoot?: (body: MarkShotBody) => Promise<Attachment | undefined>;
55
+ }
56
+ /** The most marks one message carries, and the most points one drawing keeps. */
57
+ export declare const MARKS = 20;
58
+ export declare const DRAWN_POINTS = 400;
59
+ /**
60
+ * The same place: a mark is drawn only on the screen and device it was made on (the journey step
61
+ * or data state that shows it; the screen's name is for people and may arrive later).
62
+ */
63
+ export declare function samePlace(a: MarkPlace, b: MarkPlace): boolean;
64
+ export declare const marks: {
65
+ sheet: (key: string) => MarkSheet;
66
+ add(key: string, mark: Omit<Mark, 'id'>): number | undefined;
67
+ update(key: string, id: number, patch: Partial<Pick<Mark, 'note' | 'part' | 'scroll'>>): void;
68
+ remove(key: string, id: number): void;
69
+ more(key: string, more: string): void;
70
+ /**
71
+ * The marks that went (by id) leave the sheet; marks made or notes changed since stay, and so do
72
+ * the words for anything else unless they are the ones that went.
73
+ */
74
+ sent(key: string, went: MarkSheet): void;
75
+ /** The app's answer for mark `id` is on its way: a Send waits for it. */
76
+ asked(id: number, answer: Promise<unknown>): void;
77
+ /** Once every answer for these marks has come (or given up). */
78
+ answered: (list: readonly Mark[]) => Promise<undefined>;
79
+ /** Sent, or Clear all: the sheet starts again. */
80
+ clear(key: string): void;
81
+ /** The Prototype page that is open names its sheet; the panel lists that one. */
82
+ activate(page: MarksPage | undefined): void;
83
+ active: () => MarksPage | undefined;
84
+ /** A click on a mark in the list asks the page to show its screen and device. */
85
+ show(key: string, id: number): void;
86
+ shown: () => {
87
+ key: string;
88
+ id: number;
89
+ at: number;
90
+ } | undefined;
91
+ /** Tests only: forget every sheet. */
92
+ reset(): void;
93
+ };
94
+ /** The sheet for `key`, kept up to date. */
95
+ export declare function useMarkSheet(key: string | undefined): MarkSheet;
96
+ /** The open Prototype page, for the panel. */
97
+ export declare function useActiveMarks(): MarksPage | undefined;
98
+ /** The latest "show this mark" request. */
99
+ export declare function useShownMark(): {
100
+ key: string;
101
+ id: number;
102
+ at: number;
103
+ } | undefined;
104
+ /** While the page is open, its sheet is the one the panel lists. */
105
+ export declare function useMarksPage(page: MarksPage | undefined): void;
@@ -0,0 +1,133 @@
1
+ import { useEffect, useSyncExternalStore } from 'react';
2
+ /** The most marks one message carries, and the most points one drawing keeps. */
3
+ export const MARKS = 20;
4
+ export const DRAWN_POINTS = 400;
5
+ const empty = { marks: [], more: '' };
6
+ const sheets = new Map();
7
+ const listeners = new Set();
8
+ let active;
9
+ let shown;
10
+ let nextId = 1;
11
+ /** A mark's answer from the app (its part and scroll) that has not come yet; at most 1.5 s. */
12
+ const asking = new Map();
13
+ const emit = () => {
14
+ for (const listener of listeners)
15
+ listener();
16
+ };
17
+ const put = (key, sheet) => {
18
+ sheets.set(key, sheet);
19
+ emit();
20
+ };
21
+ const subscribe = (listener) => {
22
+ listeners.add(listener);
23
+ return () => listeners.delete(listener);
24
+ };
25
+ /**
26
+ * The same place: a mark is drawn only on the screen and device it was made on (the journey step
27
+ * or data state that shows it; the screen's name is for people and may arrive later).
28
+ */
29
+ export function samePlace(a, b) {
30
+ return ((a.app ?? 'app') === (b.app ?? 'app') &&
31
+ a.device === b.device &&
32
+ a.orientation === b.orientation &&
33
+ a.journey === b.journey &&
34
+ a.step === b.step &&
35
+ a.data === b.data);
36
+ }
37
+ export const marks = {
38
+ sheet: (key) => sheets.get(key) ?? empty,
39
+ add(key, mark) {
40
+ const sheet = marks.sheet(key);
41
+ if (sheet.marks.length >= MARKS)
42
+ return;
43
+ const id = nextId++;
44
+ put(key, { ...sheet, marks: [...sheet.marks, { ...mark, id }] });
45
+ return id;
46
+ },
47
+ update(key, id, patch) {
48
+ const sheet = marks.sheet(key);
49
+ put(key, { ...sheet, marks: sheet.marks.map((m) => (m.id === id ? { ...m, ...patch } : m)) });
50
+ },
51
+ remove(key, id) {
52
+ const sheet = marks.sheet(key);
53
+ put(key, { ...sheet, marks: sheet.marks.filter((m) => m.id !== id) });
54
+ },
55
+ more(key, more) {
56
+ put(key, { ...marks.sheet(key), more });
57
+ },
58
+ /**
59
+ * The marks that went (by id) leave the sheet; marks made or notes changed since stay, and so do
60
+ * the words for anything else unless they are the ones that went.
61
+ */
62
+ sent(key, went) {
63
+ const sheet = marks.sheet(key);
64
+ const gone = new Map(went.marks.map((mark) => [mark.id, mark.note]));
65
+ const left = sheet.marks.filter((mark) => gone.get(mark.id) !== mark.note);
66
+ const more = sheet.more === went.more ? '' : sheet.more;
67
+ if (!left.length && !more)
68
+ return marks.clear(key);
69
+ put(key, { marks: left, more });
70
+ },
71
+ /** The app's answer for mark `id` is on its way: a Send waits for it. */
72
+ asked(id, answer) {
73
+ const settled = answer.then(() => undefined, () => undefined);
74
+ asking.set(id, settled);
75
+ void settled.then(() => {
76
+ if (asking.get(id) === settled)
77
+ asking.delete(id);
78
+ });
79
+ },
80
+ /** Once every answer for these marks has come (or given up). */
81
+ answered: (list) => Promise.all(list.map((mark) => asking.get(mark.id))).then(() => undefined),
82
+ /** Sent, or Clear all: the sheet starts again. */
83
+ clear(key) {
84
+ sheets.delete(key);
85
+ emit();
86
+ },
87
+ /** The Prototype page that is open names its sheet; the panel lists that one. */
88
+ activate(page) {
89
+ active = page;
90
+ emit();
91
+ },
92
+ active: () => active,
93
+ /** A click on a mark in the list asks the page to show its screen and device. */
94
+ show(key, id) {
95
+ shown = { key, id, at: (shown?.at ?? 0) + 1 };
96
+ emit();
97
+ },
98
+ shown: () => shown,
99
+ /** Tests only: forget every sheet. */
100
+ reset() {
101
+ sheets.clear();
102
+ asking.clear();
103
+ active = undefined;
104
+ shown = undefined;
105
+ emit();
106
+ },
107
+ };
108
+ /** The sheet for `key`, kept up to date. */
109
+ export function useMarkSheet(key) {
110
+ return useSyncExternalStore(subscribe, () => (key ? marks.sheet(key) : empty), () => empty);
111
+ }
112
+ /** The open Prototype page, for the panel. */
113
+ export function useActiveMarks() {
114
+ return useSyncExternalStore(subscribe, marks.active, () => undefined);
115
+ }
116
+ /** The latest "show this mark" request. */
117
+ export function useShownMark() {
118
+ return useSyncExternalStore(subscribe, marks.shown, () => undefined);
119
+ }
120
+ /** While the page is open, its sheet is the one the panel lists. */
121
+ export function useMarksPage(page) {
122
+ const { key, change, version, locale, mode, shoot } = page ?? {};
123
+ useEffect(() => {
124
+ const next = key && change && version && locale && mode
125
+ ? { key, change, version, locale, mode, shoot }
126
+ : undefined;
127
+ marks.activate(next);
128
+ return () => {
129
+ if (marks.active() === next)
130
+ marks.activate(undefined);
131
+ };
132
+ }, [key, change, version, locale, mode, shoot]);
133
+ }
@@ -0,0 +1,36 @@
1
+ import { type PointerEvent, type RefObject } from 'react';
2
+ import { type Mark, type MarkTool } from './marks.ts';
3
+ export interface FrameGeometry {
4
+ /** The frame's offset inside the layer, in layer px. */
5
+ x: number;
6
+ y: number;
7
+ /** Layer px per app px (the stage may zoom the device to fit). */
8
+ scale: number;
9
+ /** The app's page size, in its own px. */
10
+ width: number;
11
+ height: number;
12
+ }
13
+ /** Follows the frame's place and zoom under the layer as either resizes. */
14
+ export declare function useFrameGeometry(layer: RefObject<HTMLElement | null>, frame: RefObject<HTMLElement | null>): FrameGeometry | undefined;
15
+ type Draft = {
16
+ kind: 'area' | 'draw';
17
+ points: [number, number][];
18
+ };
19
+ export type NewMark = Pick<Mark, 'kind' | 'box' | 'points'>;
20
+ /** The pointer handlers for the chosen tool; a finished shape is handed to `onMark`. */
21
+ export declare function useMarkingPointer(tool: MarkTool, geometry: FrameGeometry | undefined, layer: RefObject<HTMLElement | null>, onMark: (mark: NewMark) => void): {
22
+ draft: Draft | undefined;
23
+ handlers: {
24
+ onPointerDown: (event: PointerEvent<HTMLElement>) => void;
25
+ onPointerMove: (event: PointerEvent<HTMLElement>) => void;
26
+ onPointerUp: () => void;
27
+ onPointerCancel: () => void;
28
+ };
29
+ };
30
+ export declare function draftBox(points: readonly (readonly [number, number])[]): {
31
+ x: number;
32
+ y: number;
33
+ w: number;
34
+ h: number;
35
+ } | undefined;
36
+ export {};
@@ -0,0 +1,111 @@
1
+ // Where the framed app sits under the marks layer, and the pointer work of each tool. Every mark
2
+ // is kept in the app's own px (its page as the frame lays it out), so the layer draws it at any
3
+ // zoom and the snapshot's browser draws it at the device's size.
4
+ import { useLayoutEffect, useRef, useState } from 'react';
5
+ import { DRAWN_POINTS } from './marks.js';
6
+ /** Follows the frame's place and zoom under the layer as either resizes. */
7
+ export function useFrameGeometry(layer, frame) {
8
+ const [geometry, setGeometry] = useState();
9
+ useLayoutEffect(() => {
10
+ const measure = () => {
11
+ const element = frame.current;
12
+ const own = layer.current?.getBoundingClientRect();
13
+ if (!element || !own)
14
+ return setGeometry(undefined);
15
+ const rect = element.getBoundingClientRect();
16
+ const width = element.clientWidth || rect.width;
17
+ const height = element.clientHeight || rect.height;
18
+ const scale = width ? rect.width / width : 1;
19
+ const next = { x: rect.left - own.left, y: rect.top - own.top, scale, width, height };
20
+ setGeometry((current) => current && JSON.stringify(current) === JSON.stringify(next) ? current : next);
21
+ };
22
+ measure();
23
+ if (typeof ResizeObserver === 'undefined')
24
+ return;
25
+ const observer = new ResizeObserver(measure);
26
+ if (frame.current)
27
+ observer.observe(frame.current);
28
+ if (layer.current)
29
+ observer.observe(layer.current);
30
+ window.addEventListener('resize', measure);
31
+ return () => {
32
+ observer.disconnect();
33
+ window.removeEventListener('resize', measure);
34
+ };
35
+ }, [layer, frame]);
36
+ return geometry;
37
+ }
38
+ const SMALLEST = 6;
39
+ const STEP = 3;
40
+ /** The pointer handlers for the chosen tool; a finished shape is handed to `onMark`. */
41
+ export function useMarkingPointer(tool, geometry, layer, onMark) {
42
+ const [draft, setDraft] = useState();
43
+ const drafting = useRef(undefined);
44
+ const toApp = (event) => {
45
+ const own = layer.current?.getBoundingClientRect();
46
+ if (!geometry || !own)
47
+ return;
48
+ const x = (event.clientX - own.left - geometry.x) / geometry.scale;
49
+ const y = (event.clientY - own.top - geometry.y) / geometry.scale;
50
+ if (x < 0 || y < 0 || x > geometry.width || y > geometry.height)
51
+ return;
52
+ return [Math.round(x), Math.round(y)];
53
+ };
54
+ const set = (next) => {
55
+ drafting.current = next;
56
+ setDraft(next);
57
+ };
58
+ const onPointerDown = (event) => {
59
+ const point = toApp(event);
60
+ if (!point || tool === 'select' || event.button !== 0)
61
+ return;
62
+ event.preventDefault();
63
+ if (tool === 'comment')
64
+ return onMark({ kind: 'comment', box: { ...xy(point), w: 0, h: 0 } });
65
+ event.currentTarget.setPointerCapture?.(event.pointerId);
66
+ set({ kind: tool, points: [point] });
67
+ };
68
+ const onPointerMove = (event) => {
69
+ const current = drafting.current;
70
+ const point = current && toApp(event);
71
+ if (!current || !point)
72
+ return;
73
+ if (current.kind === 'area')
74
+ return set({ ...current, points: [current.points[0] ?? point, point] });
75
+ const last = current.points.at(-1) ?? point;
76
+ if (Math.hypot(point[0] - last[0], point[1] - last[1]) < STEP)
77
+ return;
78
+ if (current.points.length < DRAWN_POINTS)
79
+ set({ ...current, points: [...current.points, point] });
80
+ };
81
+ const onPointerUp = () => {
82
+ const current = drafting.current;
83
+ set(undefined);
84
+ if (!current)
85
+ return;
86
+ if (current.kind === 'draw') {
87
+ if (current.points.length >= 2)
88
+ onMark({ kind: 'draw', points: current.points });
89
+ return;
90
+ }
91
+ const box = draftBox(current.points);
92
+ if (box && box.w >= SMALLEST && box.h >= SMALLEST)
93
+ onMark({ kind: 'area', box });
94
+ };
95
+ return {
96
+ draft,
97
+ handlers: { onPointerDown, onPointerMove, onPointerUp, onPointerCancel: () => set(undefined) },
98
+ };
99
+ }
100
+ const xy = ([x, y]) => ({ x, y });
101
+ export function draftBox(points) {
102
+ const [a, b] = [points[0], points.at(-1)];
103
+ if (!a || !b)
104
+ return;
105
+ return {
106
+ x: Math.min(a[0], b[0]),
107
+ y: Math.min(a[1], b[1]),
108
+ w: Math.abs(a[0] - b[0]),
109
+ h: Math.abs(a[1] - b[1]),
110
+ };
111
+ }
@@ -0,0 +1,18 @@
1
+ import type { MarkShotBody } from '@buffcore/contracts/workbench';
2
+ import type { TurnControls } from '../frame/panelControls.ts';
3
+ import { type Mark, type MarkSheet, type MarksPage } from './marks.ts';
4
+ /** A chat message carries at most this many pictures (the send route's limit). */
5
+ export declare const PICTURES = 8;
6
+ /** One marked screen's picture request: where it is, its size, and its marks with their numbers. */
7
+ export declare function shotBody(screen: readonly Mark[], all: readonly Mark[], page: Pick<MarksPage, 'locale' | 'mode'>): MarkShotBody;
8
+ /**
9
+ * Send every mark as one message; `shooting` while the pictures are taken. A picture that could
10
+ * not be taken stops the send and says so (`missing`): the marks stay, Send tries again, and
11
+ * `send(true)` sends without the pictures. Only the marks that went leave the sheet.
12
+ */
13
+ export declare function useSendMarks(page: MarksPage, sheet: MarkSheet, composer: TurnControls['composer']): {
14
+ send: (withoutPictures?: boolean) => Promise<void>;
15
+ shooting: boolean;
16
+ missing: number;
17
+ ready: boolean;
18
+ };