@crossworks/share-ui 0.234.5 → 0.234.9
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 +3 -3
- package/src/app-bridge-protocol.ts +2 -10
- package/src/app-frame-html.ts +6 -69
- package/src/app-sandbox.tsx +2 -35
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossworks/share-ui",
|
|
3
|
-
"version": "0.234.
|
|
3
|
+
"version": "0.234.9",
|
|
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
|
"exports": {
|
|
6
6
|
"./app-presenter": "./src/app-presenter.tsx",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@dicebear/core": "^10.7.0",
|
|
39
39
|
"@dicebear/styles": "^10.6.0",
|
|
40
40
|
"@firecms/neat": "1.0.2",
|
|
41
|
-
"@mantle/client-types": "npm:@crossworks/client-types@0.234.
|
|
42
|
-
"@mantle/content-core": "npm:@crossworks/content-core@0.234.
|
|
41
|
+
"@mantle/client-types": "npm:@crossworks/client-types@0.234.9",
|
|
42
|
+
"@mantle/content-core": "npm:@crossworks/content-core@0.234.9",
|
|
43
43
|
"@radix-ui/react-label": "^2.1.15",
|
|
44
44
|
"@radix-ui/react-slot": "^1.3.3",
|
|
45
45
|
"class-variance-authority": "^0.7.1",
|
|
@@ -45,11 +45,6 @@ export type BridgeEvt =
|
|
|
45
45
|
| { v: 1; kind: 'ready.release' }
|
|
46
46
|
| { v: 1; kind: 'resize'; height: number }
|
|
47
47
|
| { v: 1; kind: 'error'; message: string; stack?: string }
|
|
48
|
-
// Inspect mode (host-injected overlay → host): the user locked/cleared a
|
|
49
|
-
// selection (regionId = a data-app-region value, or null when cleared), or
|
|
50
|
-
// exited inspect via Esc (`inspect` with on:false).
|
|
51
|
-
| { v: 1; kind: 'select'; regionId: string | null; label?: string }
|
|
52
|
-
| { v: 1; kind: 'inspect'; on: boolean }
|
|
53
48
|
// Team-hub surface only; ignored anywhere else.
|
|
54
49
|
| { v: 1; kind: 'hub.nav'; target: HubNavTarget };
|
|
55
50
|
|
|
@@ -57,13 +52,10 @@ export type BridgeEvt =
|
|
|
57
52
|
export type BridgeRes =
|
|
58
53
|
{ v: 1; id: string; ok: true; output: unknown } | { v: 1; id: string; ok: false; error: string };
|
|
59
54
|
|
|
60
|
-
/** Control messages the host pushes DOWN unprompted: agent region annotations
|
|
61
|
-
* and
|
|
62
|
-
* from the host side, e.g. when the user clears the focus chip). */
|
|
55
|
+
/** Control messages the host pushes DOWN unprompted: agent region annotations
|
|
56
|
+
* and the live theme. */
|
|
63
57
|
export type BridgeCtl =
|
|
64
58
|
| { v: 1; kind: 'annotate'; regions: { id: string; note?: string; severity?: 'info' | 'warn' }[] }
|
|
65
|
-
| { v: 1; kind: 'inspect'; on: boolean }
|
|
66
|
-
| { v: 1; kind: 'select'; regionId: string | null }
|
|
67
59
|
// Live theme: the host's <html> class + data-color-theme, mirrored onto the
|
|
68
60
|
// iframe's <html> so a dark/light or colour-theme switch restyles a RUNNING
|
|
69
61
|
// app (every theme's tokens are already in the linked stylesheet).
|
package/src/app-frame-html.ts
CHANGED
|
@@ -50,80 +50,17 @@ export function buildAppFrameCsp(origin: string): string {
|
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// Host-injected
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
// parent feeds it to Appsmith as focusRegionIds. Esc exits. Pure DOM, defensive.
|
|
59
|
-
// It also applies parent-posted {kind:'theme'} updates so a live theme switch
|
|
60
|
-
// restyles a running app without a reload.
|
|
61
|
-
const INSPECTOR = `
|
|
53
|
+
// Host-injected live-theme sync. Lives in the iframe but is NOT part of the
|
|
54
|
+
// app bundle, so it works on every app with no rebuild. It applies
|
|
55
|
+
// parent-posted {kind:'theme'} updates so a live theme switch restyles a
|
|
56
|
+
// running app without a reload. Pure DOM, defensive.
|
|
57
|
+
const THEME_SYNC = `
|
|
62
58
|
(function(){
|
|
63
|
-
var on=false, locked=null, hovered=null, lbl=null;
|
|
64
|
-
function regionOf(el){
|
|
65
|
-
while(el && el.nodeType===1 && el!==document.body){
|
|
66
|
-
if(el.getAttribute && el.hasAttribute('data-app-region')) return el;
|
|
67
|
-
el=el.parentElement;
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
function q(id){ try{ return id ? document.querySelector('[data-app-region="'+(window.CSS&&CSS.escape?CSS.escape(id):id)+'"]') : null; }catch(e){ return null; } }
|
|
72
|
-
function label(){
|
|
73
|
-
if(!lbl){
|
|
74
|
-
lbl=document.createElement('div');
|
|
75
|
-
lbl.style.cssText='position:fixed;z-index:2147483647;pointer-events:none;display:none;font:500 11px/1.4 ui-sans-serif,system-ui,sans-serif;padding:2px 6px;border-radius:4px;background:var(--ring,#3b82f6);color:#fff;box-shadow:0 1px 4px rgba(0,0,0,.35);white-space:nowrap;';
|
|
76
|
-
document.body.appendChild(lbl);
|
|
77
|
-
}
|
|
78
|
-
return lbl;
|
|
79
|
-
}
|
|
80
|
-
function paintLocked(){
|
|
81
|
-
var prev=document.querySelectorAll('[data-app-locked]');
|
|
82
|
-
for(var i=0;i<prev.length;i++){ prev[i].removeAttribute('data-app-locked'); prev[i].style.outline=''; prev[i].style.outlineOffset=''; }
|
|
83
|
-
var el=q(locked);
|
|
84
|
-
if(el){ el.setAttribute('data-app-locked','1'); el.style.outline='2px solid var(--ring,#3b82f6)'; el.style.outlineOffset='1px'; }
|
|
85
|
-
}
|
|
86
|
-
function clearHover(){
|
|
87
|
-
if(hovered && !hovered.hasAttribute('data-app-locked')){ hovered.style.outline=''; hovered.style.outlineOffset=''; }
|
|
88
|
-
hovered=null;
|
|
89
|
-
if(lbl) lbl.style.display='none';
|
|
90
|
-
}
|
|
91
|
-
function onMove(e){
|
|
92
|
-
if(!on) return;
|
|
93
|
-
var el=regionOf(e.target);
|
|
94
|
-
if(el===hovered) return;
|
|
95
|
-
clearHover();
|
|
96
|
-
if(!el) return;
|
|
97
|
-
hovered=el;
|
|
98
|
-
if(!el.hasAttribute('data-app-locked')){ el.style.outline='2px dashed var(--ring,#3b82f6)'; el.style.outlineOffset='1px'; }
|
|
99
|
-
var r=el.getBoundingClientRect(), L=label();
|
|
100
|
-
L.textContent=el.getAttribute('data-app-region');
|
|
101
|
-
L.style.display='block';
|
|
102
|
-
L.style.left=Math.max(2,r.left)+'px';
|
|
103
|
-
L.style.top=Math.max(2,r.top-20)+'px';
|
|
104
|
-
}
|
|
105
|
-
function onClick(e){
|
|
106
|
-
if(!on) return;
|
|
107
|
-
var el=regionOf(e.target);
|
|
108
|
-
if(!el) return;
|
|
109
|
-
e.preventDefault(); e.stopPropagation(); if(e.stopImmediatePropagation) e.stopImmediatePropagation();
|
|
110
|
-
var id=el.getAttribute('data-app-region');
|
|
111
|
-
locked=(locked===id)?null:id;
|
|
112
|
-
clearHover(); paintLocked();
|
|
113
|
-
window.parent.postMessage({ v:1, kind:'select', regionId:locked, label:locked }, '*');
|
|
114
|
-
onMove(e);
|
|
115
|
-
}
|
|
116
|
-
function setOn(v){ on=v; document.body.style.cursor=v?'crosshair':''; if(!v) clearHover(); }
|
|
117
59
|
window.addEventListener('message', function(e){
|
|
118
60
|
if(e.source!==window.parent) return;
|
|
119
61
|
var m=e.data; if(!m||m.v!==1) return;
|
|
120
|
-
if(m.kind==='inspect'){ setOn(!!m.on); return; }
|
|
121
|
-
if(m.kind==='select'){ locked=m.regionId||null; clearHover(); paintLocked(); return; }
|
|
122
62
|
if(m.kind==='theme'){ var h=document.documentElement; h.className=m.cls||''; if(m.colorTheme){ h.setAttribute('data-color-theme', m.colorTheme); } else { h.removeAttribute('data-color-theme'); } return; }
|
|
123
63
|
});
|
|
124
|
-
document.addEventListener('mousemove', onMove, true);
|
|
125
|
-
document.addEventListener('click', onClick, true);
|
|
126
|
-
document.addEventListener('keydown', function(e){ if(on && e.key==='Escape'){ setOn(false); window.parent.postMessage({v:1,kind:'inspect',on:false},'*'); } });
|
|
127
64
|
})();
|
|
128
65
|
`;
|
|
129
66
|
|
|
@@ -315,7 +252,7 @@ ${
|
|
|
315
252
|
}<div id="root"></div>
|
|
316
253
|
<script>${ERROR_REPORTER}</script>
|
|
317
254
|
${viewerScript(opts.viewer)}<script type="module">${opts.bundleCode}</script>
|
|
318
|
-
<script>${
|
|
255
|
+
<script>${THEME_SYNC}</script>
|
|
319
256
|
${opts.neatSpec ? `<script type="module" src="/share-runtime/share-page.js"></script>\n` : ''}</body>
|
|
320
257
|
</html>`;
|
|
321
258
|
}
|
package/src/app-sandbox.tsx
CHANGED
|
@@ -78,10 +78,6 @@ export function AppSandbox({
|
|
|
78
78
|
frame = 'card',
|
|
79
79
|
reloadKey = 0,
|
|
80
80
|
onError,
|
|
81
|
-
inspect = false,
|
|
82
|
-
selectedRegionId = null,
|
|
83
|
-
onSelect,
|
|
84
|
-
onInspectChange,
|
|
85
81
|
hub,
|
|
86
82
|
apiBase: apiBaseOverride,
|
|
87
83
|
fetcher,
|
|
@@ -104,16 +100,6 @@ export function AppSandbox({
|
|
|
104
100
|
/** Bump to force a re-fetch + re-render (e.g. after a build/publish). */
|
|
105
101
|
reloadKey?: number;
|
|
106
102
|
onError?: (message: string) => void;
|
|
107
|
-
/** When true, hovering the preview outlines [data-app-region]s and clicking
|
|
108
|
-
* one locks it (inspect mode). */
|
|
109
|
-
inspect?: boolean;
|
|
110
|
-
/** The host-held locked selection — pushed down to keep the iframe's outline
|
|
111
|
-
* in sync (e.g. cleared when the user dismisses the focus chip). */
|
|
112
|
-
selectedRegionId?: string | null;
|
|
113
|
-
/** The user locked or cleared a region in the preview (null = cleared). */
|
|
114
|
-
onSelect?: (regionId: string | null) => void;
|
|
115
|
-
/** The iframe changed inspect state itself (e.g. Esc to exit). */
|
|
116
|
-
onInspectChange?: (on: boolean) => void;
|
|
117
103
|
/** Team-hub host API — passed ONLY by the /team shell. `getData` answers the
|
|
118
104
|
* app's `hub.get` locally from the payload the shell already fetched (no new
|
|
119
105
|
* server surface); `onNav` handles the app's validated `hub.nav` intents
|
|
@@ -190,10 +176,10 @@ export function AppSandbox({
|
|
|
190
176
|
// re-ran the bundle-fetch effect below and reloaded the iframe (white flash).
|
|
191
177
|
// `fetcher` rides along for the same reason (the split hub passes an inline
|
|
192
178
|
// bearer-attaching wrapper); the default stays a plain window-bound fetch.
|
|
193
|
-
const cbRef = useRef({ onError,
|
|
179
|
+
const cbRef = useRef({ onError, hub, onLoadFailure, confirmTool });
|
|
194
180
|
/** A tool confirmation is open (one at a time). */
|
|
195
181
|
const confirmOpenRef = useRef(false);
|
|
196
|
-
cbRef.current = { onError,
|
|
182
|
+
cbRef.current = { onError, hub, onLoadFailure, confirmTool };
|
|
197
183
|
const fetcherRef = useRef(fetcher);
|
|
198
184
|
fetcherRef.current = fetcher;
|
|
199
185
|
const doFetch = useCallback(
|
|
@@ -202,17 +188,6 @@ export function AppSandbox({
|
|
|
202
188
|
[],
|
|
203
189
|
);
|
|
204
190
|
|
|
205
|
-
// Push inspect-mode + the locked selection down whenever they change or the
|
|
206
|
-
// app (re)becomes ready, so a fresh iframe inherits the current state.
|
|
207
|
-
useEffect(() => {
|
|
208
|
-
if (status !== 'ready') return;
|
|
209
|
-
postToFrame({ v: 1, kind: 'inspect', on: inspect });
|
|
210
|
-
}, [inspect, status, postToFrame]);
|
|
211
|
-
useEffect(() => {
|
|
212
|
-
if (status !== 'ready') return;
|
|
213
|
-
postToFrame({ v: 1, kind: 'select', regionId: selectedRegionId });
|
|
214
|
-
}, [selectedRegionId, status, postToFrame]);
|
|
215
|
-
|
|
216
191
|
// Mirror the host's live theme (the <html> class + data-color-theme) into the
|
|
217
192
|
// iframe so a dark/light or colour-theme switch restyles a RUNNING app without
|
|
218
193
|
// a reload — the frame document only baked in the theme as of mint. Sync once
|
|
@@ -375,14 +350,6 @@ export function AppSandbox({
|
|
|
375
350
|
}
|
|
376
351
|
return;
|
|
377
352
|
}
|
|
378
|
-
if (m.kind === 'select') {
|
|
379
|
-
cbRef.current.onSelect?.(m.regionId);
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
if (m.kind === 'inspect') {
|
|
383
|
-
cbRef.current.onInspectChange?.(m.on);
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
353
|
if (m.kind === 'hub.nav') {
|
|
387
354
|
// Validate before navigating — never act on a malformed message from a
|
|
388
355
|
// (possibly buggy) app bundle. Ignored off the /team surface.
|