@floegence/floe-webapp-core 0.101.16 → 0.101.19

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.
@@ -22,6 +22,7 @@ export interface MarkdownMediaLabels {
22
22
  previewHTMLWindow?: string;
23
23
  linkUnavailable?: string;
24
24
  anchorUnavailable?: string;
25
+ pointerLocked?: string;
25
26
  loading: string;
26
27
  unavailable: string;
27
28
  retry: string;
@@ -58,6 +58,7 @@ const Fe = (e) => {
58
58
  const a = e.onOpenLink, i = B();
59
59
  return a ? (r, t) => a(i, r, t) : void 0;
60
60
  }, G = () => ({
61
+ pointerLocked: e.labels.pointerLocked,
61
62
  linkUnavailable: e.labels.linkUnavailable ?? "Opening links is unavailable in this preview.",
62
63
  anchorUnavailable: e.labels.anchorUnavailable ?? "The linked section was not found."
63
64
  });
@@ -2,6 +2,7 @@ import { type JSX } from 'solid-js';
2
2
  export interface SandboxedHtmlFrameLabels {
3
3
  linkUnavailable: string;
4
4
  anchorUnavailable: string;
5
+ pointerLocked?: string;
5
6
  }
6
7
  export interface SandboxedHtmlSearch {
7
8
  search: (query: string, direction?: -1 | 0 | 1) => void;
@@ -19,7 +20,7 @@ export interface SandboxedHtmlFrameProps {
19
20
  class?: string;
20
21
  style?: JSX.CSSProperties;
21
22
  inert?: boolean;
22
- /** Deactivation pauses native media without restarting it on reactivation. */
23
+ /** Deactivation pauses native media and releases pointer lock; neither resumes automatically. */
23
24
  active?: boolean;
24
25
  /** Localized presentation while this exact document loads and reaches a render opportunity. */
25
26
  renderPending?: () => JSX.Element;
@@ -1,18 +1,38 @@
1
- import { insert as v, createComponent as M, effect as A, setAttribute as f, className as N, style as P, template as S, use as Q } from "solid-js/web";
2
- import { createSignal as w, createMemo as U, createEffect as k, untrack as B, onCleanup as I, onMount as D, Show as H } from "solid-js";
1
+ import { insert as h, createComponent as x, effect as D, setAttribute as v, className as N, style as Q, template as p, use as U } from "solid-js/web";
2
+ import { createSignal as g, createMemo as $, createEffect as T, untrack as j, onCleanup as I, onMount as B, Show as S } from "solid-js";
3
3
  import { sandboxedMarkdownHtml as K } from "../chat/markdown/media.js";
4
- import { findTextRanges as W } from "../ui/textSearch.js";
5
- import { secureRandomUUID as $ } from "../../utils/secureRandom.js";
6
- var j = /* @__PURE__ */ S('<span data-floe-html-pending style="position:absolute;inset:0;z-index:1;background:var(--background, Canvas)">'), z = /* @__PURE__ */ S('<span role=alert class="max-h-24 shrink-0 overflow-auto break-words bg-background px-3 py-2 text-xs text-destructive">'), J = /* @__PURE__ */ S('<span class="relative flex h-full min-h-0 w-full flex-col"><iframe sandbox=allow-scripts referrerpolicy=no-referrer style="display:block;width:100%;min-height:0;flex:1 1 0%;border:0">');
7
- function V(e) {
4
+ import { findTextRanges as _ } from "../ui/textSearch.js";
5
+ import { secureRandomUUID as z } from "../../utils/secureRandom.js";
6
+ var W = /* @__PURE__ */ p('<span data-floe-html-pending style="position:absolute;inset:0;z-index:1;background:var(--background, Canvas)">'), J = /* @__PURE__ */ p('<span role=status class="pointer-events-none absolute inset-x-0 top-3 z-10 flex justify-center px-3"><span class="rounded-md bg-background/95 px-3 py-2 text-xs text-foreground shadow-sm">'), V = /* @__PURE__ */ p('<span role=alert class="max-h-24 shrink-0 overflow-auto break-words bg-background px-3 py-2 text-xs text-destructive">'), X = /* @__PURE__ */ p('<span class="relative flex h-full min-h-0 w-full flex-col"><iframe sandbox="allow-scripts allow-pointer-lock"referrerpolicy=no-referrer style="display:block;width:100%;min-height:0;flex:1 1 0%;border:0">');
7
+ function Y(e) {
8
8
  return `<script>(()=>{
9
9
  const channel=new MessageChannel();
10
10
  const publish=channel.port1.postMessage.bind(channel.port1);
11
11
  const query=document.querySelectorAll.bind(document);
12
12
  const MediaElementType=HTMLMediaElement;
13
13
  const pause=Function.call.bind(MediaElementType.prototype.pause);
14
+ const lockGetter=Object.getOwnPropertyDescriptor(Document.prototype,'pointerLockElement')?.get;
15
+ const locked=lockGetter?Function.call.bind(lockGetter,document):()=>null;
16
+ const exitLock=document.exitPointerLock?.bind(document);
17
+ const hasFocus=document.hasFocus.bind(document);
18
+ let pointerLockAllowed=false,pointerGesture=false;
19
+ const releaseLock=()=>{pointerGesture=false;if(locked())exitLock()};
20
+ window.addEventListener('blur',releaseLock);
21
+ document.addEventListener('visibilitychange',()=>{if(document.hidden)releaseLock()});
22
+ const gesture=event=>{if(event.isTrusted&&pointerLockAllowed)pointerGesture=true};
23
+ window.addEventListener('pointerdown',gesture,true);
24
+ window.addEventListener('keydown',event=>{
25
+ if(event.isTrusted&&event.key==='Escape'&&locked()){event.preventDefault();event.stopImmediatePropagation();releaseLock();return}
26
+ if(event.key==='Enter'||event.key===' ')gesture(event);
27
+ },true);
28
+ document.addEventListener('pointerlockchange',()=>{
29
+ const value=!!locked();
30
+ if(value&&(!pointerLockAllowed||!pointerGesture||!hasFocus()||document.hidden)){releaseLock();return}
31
+ pointerGesture=false;
32
+ publish({type:'pointer-lock',locked:value});
33
+ });
14
34
  let active=true,searchEnabled=false,searchOpen=false,searchQuery='',matches=[],matchIndex=0;
15
- const findRanges=(${W.toString()});
35
+ const findRanges=(${_.toString()});
16
36
  const clearHighlights=()=>{CSS.highlights?.delete('floe-html-find');CSS.highlights?.delete('floe-html-find-current')};
17
37
  const paint=()=>{
18
38
  clearHighlights();
@@ -38,6 +58,8 @@ function V(e) {
38
58
  if(event.data?.type==='clear-search'){searchOpen=false;clearHighlights();return}
39
59
  if(event.data?.type!=='activation')return;
40
60
  active=event.data.active===true;searchEnabled=event.data.searchEnabled===true;
61
+ pointerLockAllowed=event.data.pointerLockAllowed===true;
62
+ if(!pointerLockAllowed)releaseLock();
41
63
  paint();
42
64
  if(!active)for(const media of query('video,audio'))pause(media);
43
65
  };
@@ -86,52 +108,57 @@ function V(e) {
86
108
  parent.postMessage({type:'floe-html-ready',token:${JSON.stringify(e)}},'*',[channel.port2]);
87
109
  })()<\/script><style>::highlight(floe-html-find){background:#fde68a;color:#111}::highlight(floe-html-find-current){background:#2563eb;color:#fff}</style>`;
88
110
  }
89
- function ee(e) {
90
- let y, p;
91
- const [x, h] = w(""), [F, L] = w(""), [R, T] = w(), b = U(() => {
92
- const r = $();
111
+ function ae(e) {
112
+ let y, b;
113
+ const [C, f] = g(""), [A, k] = g(!1), [O, R] = g(""), [P, M] = g(), w = $(() => {
114
+ const a = z();
93
115
  return {
94
- token: r,
95
- html: K(V(r) + e.html)
116
+ token: a,
117
+ html: K(Y(a) + e.html)
96
118
  };
97
- }), o = () => F() === b().token;
98
- k(() => {
99
- const r = o() ? "ready" : "loading";
100
- B(() => e.onPresentationStateChange?.(r));
101
- }), k(() => {
102
- R()?.postMessage({
119
+ }), o = () => O() === w().token;
120
+ T(() => {
121
+ const a = o() ? "ready" : "loading";
122
+ j(() => e.onPresentationStateChange?.(a));
123
+ }), T(() => {
124
+ P()?.postMessage({
103
125
  type: "activation",
104
126
  active: e.active !== !1,
127
+ pointerLockAllowed: e.active !== !1 && !e.inert && o(),
105
128
  searchEnabled: !!e.onSearchRequest
106
129
  });
107
- }), k(() => {
130
+ }), T(() => {
108
131
  const {
109
- token: r
110
- } = b(), a = new AbortController();
111
- let i, t = 0, c = 0, u = !1, l = 0;
112
- h(""), p = (s) => {
113
- !s.isTrusted || s.source !== y.contentWindow || i || s.data?.type !== "floe-html-ready" || s.data?.token !== r || s.ports.length !== 1 || (i = s.ports[0], T(i), e.onSearchReady?.({
114
- search: (d, n = 0) => {
115
- a.signal.aborted || e.inert || e.active === !1 || !o() || i?.postMessage({
132
+ token: a
133
+ } = w(), r = new AbortController();
134
+ let i, t = 0, c = 0, m = !1, l = 0, d;
135
+ f(""), k(!1), b = (s) => {
136
+ !s.isTrusted || s.source !== y.contentWindow || i || s.data?.type !== "floe-html-ready" || s.data?.token !== a || s.ports.length !== 1 || (i = s.ports[0], M(i), e.onSearchReady?.({
137
+ search: (u, n = 0) => {
138
+ r.signal.aborted || e.inert || e.active === !1 || !o() || i?.postMessage({
116
139
  type: "search",
117
- query: d,
140
+ query: u,
118
141
  direction: n,
119
142
  request: ++l
120
143
  });
121
144
  },
122
145
  clear: () => {
123
- a.signal.aborted || (l++, i?.postMessage({
146
+ r.signal.aborted || (l++, i?.postMessage({
124
147
  type: "clear-search"
125
148
  }));
126
149
  }
127
- }), i.onmessage = (d) => {
128
- if (a.signal.aborted) return;
129
- const n = d.data;
150
+ }), i.onmessage = (u) => {
151
+ if (r.signal.aborted) return;
152
+ const n = u.data;
153
+ if (n?.type === "pointer-lock" && typeof n.locked == "boolean") {
154
+ clearTimeout(d), n.locked && (d = setTimeout(() => k(!1), 3e3)), k(n.locked && !e.inert && e.active !== !1 && o());
155
+ return;
156
+ }
130
157
  if (n?.type === "document-loaded") {
131
- if (u) return;
132
- u = !0, c = requestAnimationFrame(() => {
158
+ if (m) return;
159
+ m = !0, c = requestAnimationFrame(() => {
133
160
  c = requestAnimationFrame(() => {
134
- a.signal.aborted || L(r);
161
+ r.signal.aborted || R(a);
135
162
  });
136
163
  });
137
164
  return;
@@ -149,57 +176,65 @@ function ee(e) {
149
176
  return;
150
177
  }
151
178
  if (n?.type === "anchor-opened") {
152
- h("");
179
+ f("");
153
180
  return;
154
181
  }
155
182
  if (n?.type === "anchor-missing") {
156
- h(e.labels?.anchorUnavailable ?? "The linked section was not found.");
183
+ f(e.labels?.anchorUnavailable ?? "The linked section was not found.");
157
184
  return;
158
185
  }
159
186
  if (n?.type !== "open-link" || typeof n.href != "string" || n.href.length > 8192) return;
160
- const m = n.href, g = e.onOpenLink, q = e.labels?.linkUnavailable, O = ++t;
161
- h(""), Promise.resolve().then(() => {
162
- if (!a.signal.aborted) {
163
- if (!g) throw new Error(q ?? "Opening links is unavailable in this preview.");
164
- return g(m, a.signal);
187
+ const E = n.href, F = e.onOpenLink, H = e.labels?.linkUnavailable, G = ++t;
188
+ f(""), Promise.resolve().then(() => {
189
+ if (!r.signal.aborted) {
190
+ if (!F) throw new Error(H ?? "Opening links is unavailable in this preview.");
191
+ return F(E, r.signal);
165
192
  }
166
- }).catch((E) => {
167
- !a.signal.aborted && O === t && h(E instanceof Error && E.message ? E.message : q ?? "This link could not be opened.");
193
+ }).catch((L) => {
194
+ !r.signal.aborted && G === t && f(L instanceof Error && L.message ? L.message : H ?? "This link could not be opened.");
168
195
  });
169
196
  }, i.start());
170
197
  }, I(() => {
171
- a.abort(), cancelAnimationFrame(c), i?.close(), T(void 0), p = void 0, e.onSearchReady?.(void 0);
198
+ clearTimeout(d), r.abort(), cancelAnimationFrame(c), i?.close(), M(void 0), b = void 0, e.onSearchReady?.(void 0);
172
199
  });
173
200
  });
174
- const C = (r) => p?.(r);
175
- return D(() => {
176
- window.addEventListener("message", C), I(() => window.removeEventListener("message", C));
201
+ const q = (a) => b?.(a);
202
+ return B(() => {
203
+ window.addEventListener("message", q), I(() => window.removeEventListener("message", q));
177
204
  }), (() => {
178
- var r = J(), a = r.firstChild;
179
- v(r, M(H, {
205
+ var a = X(), r = a.firstChild;
206
+ h(a, x(S, {
180
207
  get when() {
181
208
  return !o();
182
209
  },
183
210
  get children() {
184
- var t = j();
185
- return v(t, () => e.renderPending?.()), t;
211
+ var t = W();
212
+ return h(t, () => e.renderPending?.()), t;
186
213
  }
187
- }), a);
214
+ }), r);
188
215
  var i = y;
189
- return typeof i == "function" ? Q(i, a) : y = a, v(r, M(H, {
216
+ return typeof i == "function" ? U(i, r) : y = r, h(a, x(S, {
217
+ get when() {
218
+ return A();
219
+ },
220
+ get children() {
221
+ var t = J(), c = t.firstChild;
222
+ return h(c, () => e.labels?.pointerLocked ?? "Mouse locked; press Esc to exit"), t;
223
+ }
224
+ }), null), h(a, x(S, {
190
225
  get when() {
191
- return x();
226
+ return C();
192
227
  },
193
228
  get children() {
194
- var t = z();
195
- return v(t, x), t;
229
+ var t = V();
230
+ return h(t, C), t;
196
231
  }
197
- }), null), A((t) => {
198
- var c = o() ? "ready" : "loading", u = !o(), l = e.class, s = e.title, d = b().html, n = e.inert || e.active === !1 || !o(), m = e.inert || e.active === !1 || !o() ? -1 : e.tabIndex, g = {
232
+ }), null), D((t) => {
233
+ var c = o() ? "ready" : "loading", m = !o(), l = e.class, d = e.title, s = w().html, u = e.inert || e.active === !1 || !o(), n = e.inert || e.active === !1 || !o() ? -1 : e.tabIndex, E = {
199
234
  ...e.style,
200
235
  opacity: o() ? void 0 : "0"
201
236
  };
202
- return c !== t.e && f(r, "data-floe-html-state", t.e = c), u !== t.t && f(r, "aria-busy", t.t = u), l !== t.a && N(a, t.a = l), s !== t.o && f(a, "title", t.o = s), d !== t.i && f(a, "srcdoc", t.i = d), n !== t.n && (a.inert = t.n = n), m !== t.s && f(a, "tabindex", t.s = m), t.h = P(a, g, t.h), t;
237
+ return c !== t.e && v(a, "data-floe-html-state", t.e = c), m !== t.t && v(a, "aria-busy", t.t = m), l !== t.a && N(r, t.a = l), d !== t.o && v(r, "title", t.o = d), s !== t.i && v(r, "srcdoc", t.i = s), u !== t.n && (r.inert = t.n = u), n !== t.s && v(r, "tabindex", t.s = n), t.h = Q(r, E, t.h), t;
203
238
  }, {
204
239
  e: void 0,
205
240
  t: void 0,
@@ -209,9 +244,9 @@ function ee(e) {
209
244
  n: void 0,
210
245
  s: void 0,
211
246
  h: void 0
212
- }), r;
247
+ }), a;
213
248
  })();
214
249
  }
215
250
  export {
216
- ee as SandboxedHtmlFrame
251
+ ae as SandboxedHtmlFrame
217
252
  };
@@ -61,6 +61,8 @@ export type WorkbenchDockAction = Readonly<{
61
61
  /** Places the action before or after components, always before host items in that group. */
62
62
  dockPlacement?: WorkbenchDockItemPlacement;
63
63
  onActivate: (trigger: HTMLButtonElement) => void;
64
+ /** Receives the concrete action button on mount and null on disposal. */
65
+ buttonRef?: (button: HTMLButtonElement | null) => void;
64
66
  }>;
65
67
  export type WorkbenchHostDockItem = Readonly<{
66
68
  id: string;