@floegence/floe-webapp-core 0.86.31 → 0.86.33
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/dist/chat.css +36 -0
- package/dist/components/chat/blocks/HtmlPreviewCanvas.d.ts +16 -0
- package/dist/components/chat/blocks/HtmlPreviewCanvas.js +153 -0
- package/dist/components/chat/blocks/MarkdownMedia.d.ts +17 -0
- package/dist/components/chat/blocks/MarkdownMedia.js +309 -216
- package/dist/components/html-preview/SandboxedHtmlFrame.d.ts +18 -0
- package/dist/components/html-preview/SandboxedHtmlFrame.js +118 -0
- package/dist/html-preview.d.ts +1 -0
- package/dist/html-preview.js +4 -0
- package/dist/styles.css +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { insert as y, createComponent as x, effect as T, className as F, setAttribute as p, style as M, template as E, use as L } from "solid-js/web";
|
|
2
|
+
import { createSignal as C, createMemo as H, createEffect as I, onCleanup as w, onMount as O, Show as S } from "solid-js";
|
|
3
|
+
import { sandboxedMarkdownHtml as U } from "../chat/markdown/media.js";
|
|
4
|
+
import { secureRandomUUID as A } from "../../utils/secureRandom.js";
|
|
5
|
+
var B = /* @__PURE__ */ E('<span role=alert class="max-h-24 shrink-0 overflow-auto break-words bg-background px-3 py-2 text-xs text-destructive">'), D = /* @__PURE__ */ E('<span class="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">');
|
|
6
|
+
function N(n) {
|
|
7
|
+
return `<script>(()=>{
|
|
8
|
+
const channel=new MessageChannel();
|
|
9
|
+
const publish=channel.port1.postMessage.bind(channel.port1);
|
|
10
|
+
const stop=Function.call.bind(Event.prototype.stopImmediatePropagation);
|
|
11
|
+
const prevent=Function.call.bind(Event.prototype.preventDefault);
|
|
12
|
+
const eventTarget=Function.call.bind(Object.getOwnPropertyDescriptor(Event.prototype,'target').get);
|
|
13
|
+
const closest=Function.call.bind(Element.prototype.closest);
|
|
14
|
+
const attribute=Function.call.bind(Element.prototype.getAttribute);
|
|
15
|
+
const find=document.getElementById.bind(document);
|
|
16
|
+
const named=document.getElementsByName.bind(document);
|
|
17
|
+
const scroll=Function.call.bind(Element.prototype.scrollIntoView);
|
|
18
|
+
const focus=Function.call.bind(HTMLElement.prototype.focus);
|
|
19
|
+
const decode=decodeURIComponent;
|
|
20
|
+
const ElementType=Element,HtmlElementType=HTMLElement;
|
|
21
|
+
window.addEventListener('click',activate,true);
|
|
22
|
+
window.addEventListener('auxclick',activate,true);
|
|
23
|
+
function activate(event){
|
|
24
|
+
const target=eventTarget(event);
|
|
25
|
+
if(!(target instanceof ElementType))return;
|
|
26
|
+
const anchor=closest(target,'a[href],area[href]');
|
|
27
|
+
if(!anchor)return;
|
|
28
|
+
prevent(event);stop(event);
|
|
29
|
+
if(!event.isTrusted)return;
|
|
30
|
+
if(event.type==='auxclick'&&event.button!==1)return;
|
|
31
|
+
const href=attribute(anchor,'href');
|
|
32
|
+
if(typeof href!=='string'||href.length>8192)return;
|
|
33
|
+
if(href.startsWith('#')){
|
|
34
|
+
let fragment;try{fragment=decode(href.slice(1))}catch{publish({type:'anchor-missing'});return}
|
|
35
|
+
const target=fragment?(find(fragment)||named(fragment)[0]):document.documentElement;
|
|
36
|
+
if(!target){publish({type:'anchor-missing'});return}
|
|
37
|
+
scroll(target,{block:'start'});
|
|
38
|
+
if(target instanceof HtmlElementType)focus(target,{preventScroll:true});
|
|
39
|
+
publish({type:'anchor-opened'});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
publish({type:'open-link',href});
|
|
43
|
+
}
|
|
44
|
+
parent.postMessage({type:'floe-html-ready',token:${JSON.stringify(n)}},'*',[channel.port2]);
|
|
45
|
+
})()<\/script>`;
|
|
46
|
+
}
|
|
47
|
+
function q(n) {
|
|
48
|
+
let f, m;
|
|
49
|
+
const [g, l] = C(""), v = H(() => {
|
|
50
|
+
const r = A();
|
|
51
|
+
return {
|
|
52
|
+
token: r,
|
|
53
|
+
html: U(N(r) + n.html)
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
I(() => {
|
|
57
|
+
const {
|
|
58
|
+
token: r
|
|
59
|
+
} = v(), t = new AbortController();
|
|
60
|
+
let i, e = 0;
|
|
61
|
+
l(""), m = (o) => {
|
|
62
|
+
!o.isTrusted || o.source !== f.contentWindow || i || o.data?.type !== "floe-html-ready" || o.data?.token !== r || o.ports.length !== 1 || (i = o.ports[0], i.onmessage = (c) => {
|
|
63
|
+
if (t.signal.aborted || n.inert) return;
|
|
64
|
+
const a = c.data;
|
|
65
|
+
if (a?.type === "anchor-opened") {
|
|
66
|
+
l("");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (a?.type === "anchor-missing") {
|
|
70
|
+
l(n.labels?.anchorUnavailable ?? "The linked section was not found.");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (a?.type !== "open-link" || typeof a.href != "string" || a.href.length > 8192) return;
|
|
74
|
+
const d = a.href, s = n.onOpenLink, u = n.labels?.linkUnavailable, k = ++e;
|
|
75
|
+
l(""), Promise.resolve().then(() => {
|
|
76
|
+
if (!t.signal.aborted) {
|
|
77
|
+
if (!s) throw new Error(u ?? "Opening links is unavailable in this preview.");
|
|
78
|
+
return s(d, t.signal);
|
|
79
|
+
}
|
|
80
|
+
}).catch((h) => {
|
|
81
|
+
!t.signal.aborted && k === e && l(h instanceof Error && h.message ? h.message : u ?? "This link could not be opened.");
|
|
82
|
+
});
|
|
83
|
+
}, i.start());
|
|
84
|
+
}, w(() => {
|
|
85
|
+
t.abort(), i?.close(), m = void 0;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
const b = (r) => m?.(r);
|
|
89
|
+
return O(() => {
|
|
90
|
+
window.addEventListener("message", b), w(() => window.removeEventListener("message", b));
|
|
91
|
+
}), (() => {
|
|
92
|
+
var r = D(), t = r.firstChild, i = f;
|
|
93
|
+
return typeof i == "function" ? L(i, t) : f = t, y(r, x(S, {
|
|
94
|
+
get when() {
|
|
95
|
+
return g();
|
|
96
|
+
},
|
|
97
|
+
get children() {
|
|
98
|
+
var e = B();
|
|
99
|
+
return y(e, g), e;
|
|
100
|
+
}
|
|
101
|
+
}), null), T((e) => {
|
|
102
|
+
var o = n.class, c = n.title, a = v().html, d = n.inert, s = n.tabIndex, u = {
|
|
103
|
+
...n.style
|
|
104
|
+
};
|
|
105
|
+
return o !== e.e && F(t, e.e = o), c !== e.t && p(t, "title", e.t = c), a !== e.a && p(t, "srcdoc", e.a = a), d !== e.o && (t.inert = e.o = d), s !== e.i && p(t, "tabindex", e.i = s), e.n = M(t, u, e.n), e;
|
|
106
|
+
}, {
|
|
107
|
+
e: void 0,
|
|
108
|
+
t: void 0,
|
|
109
|
+
a: void 0,
|
|
110
|
+
o: void 0,
|
|
111
|
+
i: void 0,
|
|
112
|
+
n: void 0
|
|
113
|
+
}), r;
|
|
114
|
+
})();
|
|
115
|
+
}
|
|
116
|
+
export {
|
|
117
|
+
q as SandboxedHtmlFrame
|
|
118
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SandboxedHtmlFrame, type SandboxedHtmlFrameProps, type SandboxedHtmlFrameLabels } from './components/html-preview/SandboxedHtmlFrame';
|