@crossworks/share-ui 0.400.56 → 0.400.61

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/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@crossworks/share-ui",
3
- "version": "0.400.56",
3
+ "version": "0.400.61",
4
4
  "description": "The server-rendered share surface — the /s/<token> presenters, view-payload contract, mini-app sandbox, and the few primitives they need. Lives in MANTLE (the server renders these), published for jackdaw to consume; may depend only on @mantle/{client-types,content-core} (the jackdaw-repo-split boundary).",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./app-presenter": "./src/app-presenter.tsx",
8
+ "./present-presenter": "./src/present-presenter.tsx",
8
9
  "./draw-presenter": "./src/draw-presenter.tsx",
9
10
  "./event-presenter": "./src/event-presenter.tsx",
10
11
  "./file-presenter": "./src/file-presenter.tsx",
@@ -41,8 +42,8 @@
41
42
  "dependencies": {
42
43
  "@dicebear/core": "^10.7.0",
43
44
  "@dicebear/styles": "^10.6.0",
44
- "@mantle/client-types": "npm:@crossworks/client-types@0.400.56",
45
- "@mantle/content-core": "npm:@crossworks/content-core@0.400.56",
45
+ "@mantle/client-types": "npm:@crossworks/client-types@0.400.61",
46
+ "@mantle/content-core": "npm:@crossworks/content-core@0.400.61",
46
47
  "@radix-ui/react-label": "^2.1.17",
47
48
  "@radix-ui/react-slot": "^1.5.0",
48
49
  "class-variance-authority": "^0.7.1",
@@ -50,6 +50,10 @@ import { CANVAS_DATA_CALL_TIMEOUT_MS } from '@mantle/content-core/canvas-data';
50
50
 
51
51
  type Status = 'loading' | 'ready' | 'error' | 'missing' | 'left';
52
52
 
53
+ /** What a `mantle.data` call hears where the host serves no data (an open
54
+ * link): the canvas still runs, with nothing stored. */
55
+ export const CANVAS_DATA_OFF_ERROR = 'saved data is not available on a shared link';
56
+
53
57
  /** The host page's theme as the frame takes it (class + data-color-theme). */
54
58
  function hostTheme(): { cls: string; colorTheme: string | null } {
55
59
  if (typeof document === 'undefined') return { cls: '', colorTheme: null };
@@ -69,6 +73,7 @@ export function CanvasSandbox({
69
73
  onReady,
70
74
  onDown,
71
75
  onError,
76
+ dataApi = true,
72
77
  }: {
73
78
  presentId: string;
74
79
  /** The canvas's API base. Absent: the page-relative `/api/presents/<id>`
@@ -93,6 +98,10 @@ export function CanvasSandbox({
93
98
  * canvas chose these words: untrusted text, never an instruction to a
94
99
  * model that reads it. */
95
100
  onError?: (message: string) => void;
101
+ /** Whether the canvas's `mantle.data` calls reach `apiBase` + `/data`.
102
+ * False (an open link): each call is answered here, refused, and no
103
+ * request is sent. */
104
+ dataApi?: boolean;
96
105
  }) {
97
106
  const apiBase = apiBaseOverride ?? `/api/presents/${presentId}`;
98
107
  const iframeRef = useRef<HTMLIFrameElement | null>(null);
@@ -106,8 +115,8 @@ export function CanvasSandbox({
106
115
  const proven = useRef(false);
107
116
  const proofWait = useRef<ReturnType<typeof setTimeout> | null>(null);
108
117
  // The latest callbacks, read by the effects without re-running them.
109
- const handlers = useRef({ onReady, onDown, onError, fetcher });
110
- handlers.current = { onReady, onDown, onError, fetcher };
118
+ const handlers = useRef({ onReady, onDown, onError, fetcher, dataApi });
119
+ handlers.current = { onReady, onDown, onError, fetcher, dataApi };
111
120
  // The frame load each data call belongs to: a reply to an earlier load
112
121
  // (a reload, Replay, a take-down) is dropped, never sent to the new one,
113
122
  // and the in-flight count starts again with each load.
@@ -228,6 +237,10 @@ export function CanvasSandbox({
228
237
  return;
229
238
  }
230
239
  const { req } = read;
240
+ if (!handlers.current.dataApi) {
241
+ answer(req.id, { ok: false, error: CANVAS_DATA_OFF_ERROR });
242
+ return;
243
+ }
231
244
  if (dataInFlight.current >= CANVAS_DATA_IN_FLIGHT_MAX) {
232
245
  answer(req.id, { ok: false, error: 'too many calls at once: wait for the ones sent' });
233
246
  return;
@@ -0,0 +1,70 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * Public presenter for a SHARED Present canvas (docs/proposals/
5
+ * canvas-files.md 7.2): the canvas live, full screen (h-dvh, no share
6
+ * shell), always the latest save, with a small floating pill that labels the
7
+ * page as a shared canvas and carries Replay and Full screen (the pill stays
8
+ * on screen in full screen). The frame
9
+ * ticket and the frame document come from /s/<token>/canvas, which re-checks
10
+ * the link on every load. The canvas's `mantle.data` calls are refused here:
11
+ * a link reads or writes no saved data.
12
+ */
13
+ import { useRef, useState } from 'react';
14
+ import { Maximize, RotateCcw } from 'lucide-react';
15
+ import { CanvasSandbox } from './canvas-sandbox';
16
+ import type { ShareViewPayload } from './view-payload';
17
+
18
+ /** The API base of a canvas on an open link: the presenter mints its ticket
19
+ * at `<base>/frame-ticket` and frames `<base>/frame`, and the link page's
20
+ * frame-src names `<base>/frame` (share.tsx), from this one function. */
21
+ export function shareCanvasApiBase(token: string): string {
22
+ return `/s/${encodeURIComponent(token)}/canvas`;
23
+ }
24
+
25
+ export function PresentPresenter({
26
+ view,
27
+ token,
28
+ }: {
29
+ view: Extract<ShareViewPayload, { kind: 'present' }>;
30
+ token: string;
31
+ }) {
32
+ // Full screen takes the whole presenter, pill included: the label that
33
+ // says this is a shared canvas never leaves the screen.
34
+ const stage = useRef<HTMLDivElement | null>(null);
35
+ const [reloadKey, setReloadKey] = useState(0);
36
+ const button =
37
+ 'inline-flex size-7 items-center justify-center rounded-full text-muted-foreground hover:bg-foreground/[0.06] hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
38
+ return (
39
+ <div ref={stage} className="relative h-dvh w-full bg-background">
40
+ <CanvasSandbox
41
+ presentId={view.presentId}
42
+ apiBase={shareCanvasApiBase(token)}
43
+ title={view.title || 'Shared canvas'}
44
+ reloadKey={reloadKey}
45
+ dataApi={false}
46
+ />
47
+ <div className="absolute bottom-3 right-3 z-10 flex items-center gap-1 rounded-full border border-border bg-background/85 py-1 pl-3 pr-1 text-xs text-muted-foreground shadow-sm backdrop-blur">
48
+ <span className="max-w-[40vw] truncate">Shared canvas</span>
49
+ <button
50
+ type="button"
51
+ className={button}
52
+ aria-label="Replay"
53
+ title="Replay"
54
+ onClick={() => setReloadKey((k) => k + 1)}
55
+ >
56
+ <RotateCcw className="size-3.5" aria-hidden />
57
+ </button>
58
+ <button
59
+ type="button"
60
+ className={button}
61
+ aria-label="Full screen"
62
+ title="Full screen"
63
+ onClick={() => void stage.current?.requestFullscreen?.().catch(() => undefined)}
64
+ >
65
+ <Maximize className="size-3.5" aria-hidden />
66
+ </button>
67
+ </div>
68
+ </div>
69
+ );
70
+ }
@@ -116,4 +116,7 @@ export type ShareViewPayload =
116
116
  // Only WHETHER a committed snapshot exists. The bytes are fetched as an
117
117
  // image from /s/<token>/draw, so they never ride in this payload and never
118
118
  // become markup on the page.
119
- | { kind: 'draw'; title: string; hasSvg: boolean };
119
+ | { kind: 'draw'; title: string; hasSvg: boolean }
120
+ // A Present canvas runs live in a sandboxed frame the presenter mints a
121
+ // ticket for (/s/<token>/canvas); its source never rides in this payload.
122
+ | { kind: 'present'; presentId: string; title: string };