@floegence/floe-webapp-core 0.97.3 → 0.98.1

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.
@@ -1,13 +1,14 @@
1
- import { effect as V, className as q, style as U, template as k, use as B } from "solid-js/web";
2
- import { useContextMenuActions as N } from "../ui/ContextMenuActions.js";
3
- import { onMount as P, onCleanup as _, createEffect as M } from "solid-js";
4
- import { useTheme as $ } from "../../context/ThemeContext.js";
5
- import { useResizeObserver as K } from "../../hooks/useResizeObserver.js";
6
- import { resolveCodeEditorLanguageSpec as G } from "./languages.js";
7
- import { applyFloeMonacoTheme as H } from "./monacoTheme.js";
1
+ import { effect as V, className as q, style as U, template as $, use as k } from "solid-js/web";
2
+ import { useContextMenuActions as B } from "../ui/ContextMenuActions.js";
3
+ import { onMount as N, onCleanup as P, createEffect as M } from "solid-js";
4
+ import { useTheme as _ } from "../../context/ThemeContext.js";
5
+ import { useResizeObserver as H } from "../../hooks/useResizeObserver.js";
6
+ import { resolveCodeEditorLanguageSpec as K } from "./languages.js";
7
+ import { applyFloeMonacoTheme as G } from "./monacoTheme.js";
8
8
  import { ensureMonacoEnvironment as X } from "./monacoEnvironment.js";
9
9
  import { loadMonacoEditorApi as Y } from "./monacoStandaloneRuntime.js";
10
- var j = /* @__PURE__ */ k("<div>");
10
+ import { ensureFloeMonacoHover as j } from "./monacoHover.js";
11
+ var J = /* @__PURE__ */ $("<div>");
11
12
  const A = {
12
13
  readOnly: !0,
13
14
  automaticLayout: !1,
@@ -20,8 +21,8 @@ const A = {
20
21
  tabSize: 2,
21
22
  fontFamily: "var(--font-mono)"
22
23
  };
23
- let J = 0;
24
- function Q(t, f, c) {
24
+ let Q = 0;
25
+ function W(t, f, c) {
25
26
  return t.Uri.parse(`inmemory://model/${f}/${encodeURIComponent(c)}`);
26
27
  }
27
28
  function R(t, f) {
@@ -29,14 +30,14 @@ function R(t, f) {
29
30
  const c = t.getSelection();
30
31
  return !c || c.isEmpty() ? "" : f.getValueInRange(c);
31
32
  }
32
- function se(t) {
33
- const f = $(), c = N();
33
+ function ue(t) {
34
+ const f = _(), c = B();
34
35
  let m;
35
- const O = ++J;
36
- let s, o, i, h, p = null, E = 0;
37
- const F = K(() => m), S = () => {
36
+ const F = ++Q;
37
+ let s, o, i, h, S = null, E = 0;
38
+ const O = H(() => m), p = () => {
38
39
  const e = f.resolvedTheme(), a = f.shellPreset();
39
- s && H(s.editor, e, a);
40
+ s && G(s.editor, e, a);
40
41
  }, y = () => !o || !i ? null : {
41
42
  editor: o,
42
43
  model: i,
@@ -47,13 +48,13 @@ function se(t) {
47
48
  const e = y();
48
49
  if (!e) return;
49
50
  const a = e.model.uri.toString();
50
- a !== p && (p = a, t.onReady?.(e));
51
+ a !== S && (S = a, t.onReady?.(e));
51
52
  }, b = () => {
52
53
  const e = y();
53
54
  e && t.onSelectionChange?.(e.getSelectedText(), e);
54
55
  }, I = async () => {
55
56
  if (!o || !s) return;
56
- const e = ++E, a = G(t.language);
57
+ const e = ++E, a = K(t.language);
57
58
  let l = a.id;
58
59
  try {
59
60
  await a.load?.();
@@ -62,7 +63,7 @@ function se(t) {
62
63
  l = "plaintext";
63
64
  }
64
65
  if (!o || e !== E) return;
65
- const u = Q(s, O, t.path);
66
+ const u = W(s, F, t.path);
66
67
  if (i && i.uri.toString() === u.toString()) {
67
68
  i.getLanguageId() !== l && s.editor.setModelLanguage(i, l), i.getValue() !== t.value && i.setValue(t.value), L(), b();
68
69
  return;
@@ -70,10 +71,10 @@ function se(t) {
70
71
  const g = s.editor.createModel(t.value, l, u);
71
72
  i?.dispose(), i = g, o.setModel(i), L(), b();
72
73
  };
73
- return P(() => {
74
+ return N(() => {
74
75
  let e = !1, a, l, u, g = [], x = [];
75
76
  (async () => {
76
- if (!m || (X(), s = await Y(t.runtimeOptions), e || !m)) return;
77
+ if (!m || (X(), j(), s = await Y(t.runtimeOptions), e || !m)) return;
77
78
  o = s.editor.create(m, {
78
79
  model: null,
79
80
  ...A,
@@ -107,7 +108,7 @@ function se(t) {
107
108
  };
108
109
  if (r.addEventListener("pointerdown", v, !0), r.addEventListener("contextmenu", v, !0), r.addEventListener("keydown", v, !0), u = () => {
109
110
  x = [], r.removeEventListener("pointerdown", v, !0), r.removeEventListener("contextmenu", v, !0), r.removeEventListener("keydown", v, !0);
110
- }, S(), await I(), e || !o) return;
111
+ }, p(), await I(), e || !o) return;
111
112
  const z = t.onContentChange, w = t.onChange, D = t.onSelectionChange;
112
113
  a = o.onDidChangeModelContent((n) => {
113
114
  const d = y();
@@ -118,11 +119,11 @@ function se(t) {
118
119
  });
119
120
  })().catch((r) => {
120
121
  console.error("Failed to initialize Monaco editor runtime", r);
121
- }), _(() => {
122
+ }), P(() => {
122
123
  e = !0, a?.dispose(), l?.dispose(), u?.(), g.forEach((r) => r.dispose()), h && cancelAnimationFrame(h), o?.dispose(), i?.dispose(), s = void 0, o = void 0, i = void 0;
123
124
  });
124
125
  }), M(() => {
125
- S();
126
+ p();
126
127
  }), M(() => {
127
128
  o && o.updateOptions({
128
129
  ...A,
@@ -131,7 +132,7 @@ function se(t) {
131
132
  }), M(() => {
132
133
  t.path, t.language, t.value, I();
133
134
  }), M(() => {
134
- const e = F();
135
+ const e = O();
135
136
  !e || !o || (h && cancelAnimationFrame(h), h = requestAnimationFrame(() => {
136
137
  o?.layout({
137
138
  width: e.width,
@@ -139,9 +140,9 @@ function se(t) {
139
140
  });
140
141
  }));
141
142
  }), (() => {
142
- var e = j(), a = m;
143
- return typeof a == "function" ? B(a, e) : m = e, V((l) => {
144
- var u = t.class, g = t.style;
143
+ var e = J(), a = m;
144
+ return typeof a == "function" ? k(a, e) : m = e, V((l) => {
145
+ var u = `floe-code-editor${t.class ? ` ${t.class}` : ""}`, g = t.style;
145
146
  return u !== l.e && q(e, l.e = u), l.t = U(e, g, l.t), l;
146
147
  }, {
147
148
  e: void 0,
@@ -150,5 +151,5 @@ function se(t) {
150
151
  })();
151
152
  }
152
153
  export {
153
- se as CodeEditor
154
+ ue as CodeEditor
154
155
  };
@@ -0,0 +1 @@
1
+ export declare function ensureFloeMonacoHover(): void;
@@ -0,0 +1,32 @@
1
+ import { HoverService as s } from "monaco-editor/platform/hover/browser/hoverService.js";
2
+ import { IHoverService as c } from "monaco-editor/platform/hover/browser/hover.js";
3
+ import { registerSingleton as l } from "monaco-editor/platform/instantiation/common/extensions.js";
4
+ class a extends s {
5
+ scopeOptions(e) {
6
+ const r = e.target instanceof HTMLElement ? e.target : e.target.targetElements[0], t = r?.closest(".floe-code-editor");
7
+ if (!t) return e;
8
+ const o = t.getBoundingClientRect(), n = r.getBoundingClientRect();
9
+ return {
10
+ ...e,
11
+ container: t,
12
+ ...e.style === 1 || e.appearance?.showPointer ? { position: {
13
+ ...e.position,
14
+ hoverPosition: 2,
15
+ anchorAlignment: n.left + n.width / 2 > o.left + o.width / 2 ? 1 : 0
16
+ } } : {}
17
+ };
18
+ }
19
+ showInstantHover(...e) {
20
+ return e[0] = this.scopeOptions(e[0]), super.showInstantHover(...e);
21
+ }
22
+ showDelayedHover(...e) {
23
+ return e[0] = this.scopeOptions(e[0]), super.showDelayedHover(...e);
24
+ }
25
+ }
26
+ let i = !1;
27
+ function f() {
28
+ i || (i = !0, l(c, a, !0));
29
+ }
30
+ export {
31
+ f as ensureFloeMonacoHover
32
+ };
@@ -20,6 +20,7 @@ function c(i) {
20
20
  "min-width": "0",
21
21
  "min-height": "0",
22
22
  visibility: e.active ? "visible" : "hidden",
23
+ opacity: e.active ? "1" : "0",
23
24
  "pointer-events": e.active ? void 0 : "none"
24
25
  };
25
26
  }
@@ -0,0 +1,13 @@
1
+ import type { TextSearchController } from './textSearch';
2
+ export interface TextSearchLabels {
3
+ find: string;
4
+ previous: string;
5
+ next: string;
6
+ close: string;
7
+ noMatches: string;
8
+ matches: (current: number, total: number) => string;
9
+ }
10
+ export declare function TextSearchBar(props: {
11
+ search: TextSearchController;
12
+ labels: TextSearchLabels;
13
+ }): import("solid-js").JSX.Element;
@@ -0,0 +1,39 @@
1
+ import { createComponent as u, use as q, insert as v, memo as S, effect as C, setAttribute as a, template as D, delegateEvents as I } from "solid-js/web";
2
+ import { Show as T } from "solid-js";
3
+ import { ChevronUp as A, ChevronDown as B, X as E } from "../icons/index.js";
4
+ var K = /* @__PURE__ */ D("<div class=floe-text-search role=search><input type=search><span role=status aria-live=polite aria-atomic=true></span><button type=button></button><button type=button></button><button type=button>");
5
+ function X(t) {
6
+ return u(T, {
7
+ get when() {
8
+ return t.search.open();
9
+ },
10
+ get children() {
11
+ var r = K(), l = r.firstChild, o = l.nextSibling, n = o.nextSibling, i = n.nextSibling, c = i.nextSibling;
12
+ r.$$keydown = (e) => t.search.onKeyDown(e), l.$$input = (e) => t.search.setQuery(e.currentTarget.value);
13
+ var b = t.search.bindInput;
14
+ return typeof b == "function" ? q(b, l) : t.search.bindInput = l, v(o, (() => {
15
+ var e = S(() => !!t.search.query());
16
+ return () => e() ? S(() => !!t.search.count())() ? t.labels.matches(t.search.current(), t.search.count()) : t.labels.noMatches : "";
17
+ })()), n.$$click = () => t.search.previous(), v(n, u(A, {})), i.$$click = () => t.search.next(), v(i, u(B, {})), c.$$click = () => t.search.close(), v(c, u(E, {})), C((e) => {
18
+ var h = t.labels.find, d = t.labels.find, s = t.labels.find, f = t.labels.previous, m = t.labels.previous, y = !t.search.count(), x = t.labels.next, g = t.labels.next, $ = !t.search.count(), k = t.labels.close, w = t.labels.close;
19
+ return h !== e.e && a(r, "aria-label", e.e = h), d !== e.t && a(l, "aria-label", e.t = d), s !== e.a && a(l, "placeholder", e.a = s), f !== e.o && a(n, "title", e.o = f), m !== e.i && a(n, "aria-label", e.i = m), y !== e.n && (n.disabled = e.n = y), x !== e.s && a(i, "title", e.s = x), g !== e.h && a(i, "aria-label", e.h = g), $ !== e.r && (i.disabled = e.r = $), k !== e.d && a(c, "title", e.d = k), w !== e.l && a(c, "aria-label", e.l = w), e;
20
+ }, {
21
+ e: void 0,
22
+ t: void 0,
23
+ a: void 0,
24
+ o: void 0,
25
+ i: void 0,
26
+ n: void 0,
27
+ s: void 0,
28
+ h: void 0,
29
+ r: void 0,
30
+ d: void 0,
31
+ l: void 0
32
+ }), C(() => l.value = t.search.query()), r;
33
+ }
34
+ });
35
+ }
36
+ I(["keydown", "input", "click"]);
37
+ export {
38
+ X as TextSearchBar
39
+ };
@@ -0,0 +1,23 @@
1
+ import { type Accessor } from 'solid-js';
2
+ /** Literal rendered-text matching; inline markup can split a match, blocks cannot. */
3
+ export declare function findTextRanges(root: HTMLElement, query: string): Range[];
4
+ export interface TextSearchOptions {
5
+ content: Accessor<HTMLElement | undefined>;
6
+ viewport?: Accessor<HTMLElement | undefined>;
7
+ active?: Accessor<boolean>;
8
+ identity?: Accessor<unknown>;
9
+ }
10
+ export declare function createTextSearch(options: TextSearchOptions): {
11
+ open: Accessor<boolean>;
12
+ query: Accessor<string>;
13
+ setQuery: import("solid-js").Setter<string>;
14
+ show: (trigger?: HTMLElement) => void;
15
+ close: () => void;
16
+ next: () => void;
17
+ previous: () => void;
18
+ count: () => number;
19
+ current: () => number;
20
+ bindInput: (element: HTMLInputElement) => void;
21
+ onKeyDown: (event: KeyboardEvent) => void;
22
+ };
23
+ export type TextSearchController = ReturnType<typeof createTextSearch>;
@@ -0,0 +1,113 @@
1
+ import { createSignal as C, createUniqueId as K, createEffect as E, batch as k, onCleanup as D, on as L, untrack as M } from "solid-js";
2
+ function N(l, s) {
3
+ if (!s) return [];
4
+ const x = new RegExp(s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "giu"), y = [];
5
+ let f = "", c = [];
6
+ const b = () => {
7
+ let i = 0, a = 0;
8
+ for (const g of f.matchAll(x)) {
9
+ const r = g.index, u = r + g[0].length;
10
+ for (; c[i].end <= r; ) i++;
11
+ for (a = Math.max(i, a); c[a].end < u; ) a++;
12
+ const m = c[i], p = c[a], h = l.ownerDocument.createRange();
13
+ h.setStart(m.node, r - m.start), h.setEnd(p.node, u - p.start), y.push(h);
14
+ }
15
+ f = "", c = [];
16
+ }, w = (i) => {
17
+ if (i.nodeType === Node.TEXT_NODE) {
18
+ const r = i.textContent ?? "";
19
+ r && (c.push({ node: i, start: f.length, end: f.length + r.length }), f += r);
20
+ return;
21
+ }
22
+ if (!(i instanceof HTMLElement)) return;
23
+ if (i.matches('script,style,button,input,textarea,select,[hidden],[aria-hidden="true"],[data-floe-text-search-exclude]')) {
24
+ b();
25
+ return;
26
+ }
27
+ const a = getComputedStyle(i);
28
+ if (a.display === "none" || a.visibility === "hidden") return;
29
+ const g = !["inline", "contents"].includes(a.display) || i.tagName === "BR";
30
+ g && b(), i.childNodes.forEach(w), g && b();
31
+ };
32
+ return l.childNodes.forEach(w), b(), y;
33
+ }
34
+ function $(l) {
35
+ const [s, x] = C(!1), [y, f] = C(""), [c, b] = C([]), [w, i] = C(0), [a, g] = C(0), r = "floe-find-" + K().replace(/[^a-zA-Z0-9-]/g, "");
36
+ let u, m, p = 0, h;
37
+ const A = () => l.identity?.(), d = () => l.active?.() !== !1, S = () => {
38
+ globalThis.CSS?.highlights?.delete(r), globalThis.CSS?.highlights?.delete(r + "-current");
39
+ }, H = (t) => {
40
+ const n = l.viewport?.() ?? l.content();
41
+ if (!t || !n || !d()) return;
42
+ const e = n.getBoundingClientRect(), o = t.getBoundingClientRect(), F = e.width / n.offsetWidth || 1, I = e.height / n.offsetHeight || 1;
43
+ (o.top < e.top + 8 || o.bottom > e.bottom - 8) && (n.scrollTop += (o.top - e.top - e.height / 2) / I), (o.left < e.left || o.right > e.right) && (n.scrollLeft += (o.left - e.left - e.width / 2) / F);
44
+ }, T = () => {
45
+ x(!1), S(), d() && m?.isConnected && !m.closest("[inert]") && m.focus({ preventScroll: !0 });
46
+ }, R = (t) => {
47
+ d() && (s() || (m = t ?? (document.activeElement instanceof HTMLElement ? document.activeElement : void 0)), x(!0), queueMicrotask(() => {
48
+ M(s) && M(d) && u?.isConnected && (u.focus(), u.select());
49
+ }));
50
+ }, v = (t) => {
51
+ const n = c().length;
52
+ n && i((e) => (e + t + n) % n);
53
+ };
54
+ return E(() => {
55
+ A(), k(() => {
56
+ x(!1), f(""), i(0);
57
+ });
58
+ }), E(() => {
59
+ const t = l.content();
60
+ if (!t || !s() || !d()) return;
61
+ const n = new MutationObserver(() => {
62
+ cancelAnimationFrame(p), p = requestAnimationFrame(() => g((e) => e + 1));
63
+ });
64
+ n.observe(t, { childList: !0, characterData: !0, subtree: !0 }), D(() => {
65
+ n.disconnect(), cancelAnimationFrame(p);
66
+ });
67
+ }), E(() => {
68
+ const t = l.content();
69
+ a();
70
+ const n = y();
71
+ if (!s() || !d()) return;
72
+ const e = t ? N(t, n) : [];
73
+ k(() => {
74
+ b(e), i((o) => Math.min(o, Math.max(0, e.length - 1)));
75
+ });
76
+ }), E(L(y, () => i(0))), E(() => {
77
+ S();
78
+ const t = c(), n = t[w()];
79
+ if (!(!s() || !d())) {
80
+ if (typeof Highlight < "u" && CSS.highlights) {
81
+ h || (h = document.createElement("style"), h.textContent = `::highlight(${r}){background:color-mix(in srgb,var(--warning,#eab308) 35%,transparent);color:inherit}::highlight(${r}-current){background:var(--primary,#2563eb);color:var(--primary-foreground,#fff)}`, document.head.append(h));
82
+ const e = new Highlight();
83
+ if (t.forEach((o) => e.add(o)), CSS.highlights.set(r, e), n) {
84
+ const o = new Highlight(n);
85
+ o.priority = 1, CSS.highlights.set(r + "-current", o);
86
+ }
87
+ }
88
+ H(n);
89
+ }
90
+ }), D(() => {
91
+ S(), h?.remove(), cancelAnimationFrame(p);
92
+ }), {
93
+ open: s,
94
+ query: y,
95
+ setQuery: f,
96
+ show: R,
97
+ close: T,
98
+ next: () => v(1),
99
+ previous: () => v(-1),
100
+ count: () => c().length,
101
+ current: () => c().length ? w() + 1 : 0,
102
+ bindInput: (t) => {
103
+ u = t;
104
+ },
105
+ onKeyDown: (t) => {
106
+ !d() || t.isComposing || t.defaultPrevented || ((t.ctrlKey || t.metaKey) && !t.altKey && t.key.toLowerCase() === "f" ? (t.preventDefault(), t.stopPropagation(), R()) : s() && t.key === "Escape" ? (t.preventDefault(), t.stopPropagation(), T()) : s() && t.target === u && t.key === "Enter" && (t.preventDefault(), t.stopPropagation(), v(t.shiftKey ? -1 : 1)));
107
+ }
108
+ };
109
+ }
110
+ export {
111
+ $ as createTextSearch,
112
+ N as findTextRanges
113
+ };
@@ -0,0 +1,7 @@
1
+ /* Monaco measures a hover before moving its context view to the anchor. Keep
2
+ * the measured intrinsic width at the editor edge, so wrapping cannot enlarge
3
+ * the tooltip over its trigger and repeatedly retrigger pointer enter/leave. */
4
+ .floe-code-editor .workbench-hover-container {
5
+ width: max-content;
6
+ max-width: calc(100vw - 8px);
7
+ }
package/dist/floe.css CHANGED
@@ -1,3 +1,5 @@
1
+ @import './editor.css';
2
+ @import './text-search.css';
1
3
  @import './progress-shimmer.css';
2
4
  @import './primitives.css';
3
5
  @import './language.css';