@floegence/floe-webapp-core 0.98.1 → 0.99.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.
@@ -32,6 +32,8 @@ export declare function ContextMenuActions(props: {
32
32
  actions: (request: ContextMenuRequest) => readonly ContextMenuAction[];
33
33
  enabled?: boolean;
34
34
  zIndex?: number;
35
+ /** Only the fallback menu changes scope; contributed local menus keep their owner. */
36
+ portalScope?: 'surface' | 'viewport';
35
37
  editing?: {
36
38
  labels: ContextMenuEditingLabels;
37
39
  onError: (error: unknown) => void;
@@ -1,77 +1,80 @@
1
- import { createComponent as f, insert as b, effect as E, className as k, setAttribute as M, memo as q, template as L, delegateEvents as F } from "solid-js/web";
1
+ import { createComponent as f, insert as b, effect as E, className as k, setAttribute as M, memo as $, template as S, delegateEvents as F } from "solid-js/web";
2
2
  import { useResizeObserver as H } from "../../hooks/useResizeObserver.js";
3
- import { Show as T, useContext as A, For as p, createSignal as D, onMount as R, onCleanup as z, createContext as P, createMemo as K } from "solid-js";
4
- import { SurfaceFloatingLayer as N } from "./SurfaceFloatingLayer.js";
3
+ import { Show as T, useContext as A, For as p, createSignal as D, onMount as R, onCleanup as q, createContext as N, createMemo as P } from "solid-js";
4
+ import { SurfaceFloatingLayer as K } from "./SurfaceFloatingLayer.js";
5
5
  import { handleMenuKeyboardNavigation as _ } from "./menuUtils.js";
6
- var B = /* @__PURE__ */ L("<span aria-hidden=true>"), O = /* @__PURE__ */ L("<button type=button role=menuitem><span>"), X = /* @__PURE__ */ L("<button type=button role=menuitem class=floe-context-action><span>");
7
- const C = P(), W = () => A(C);
8
- function I(e) {
6
+ var B = /* @__PURE__ */ S("<span aria-hidden=true>"), O = /* @__PURE__ */ S("<button type=button role=menuitem><span>"), X = /* @__PURE__ */ S("<button type=button role=menuitem class=floe-context-action><span>");
7
+ const L = N(), W = () => A(L);
8
+ function z(e) {
9
9
  return f(T, {
10
10
  get when() {
11
11
  return e.icon;
12
12
  },
13
- children: (i) => (() => {
14
- var a = B();
15
- return b(a, () => i()()), E(() => k(a, `floe-context-action-icon ${e.class ?? ""}`)), a;
13
+ children: (r) => (() => {
14
+ var s = B();
15
+ return b(s, () => r()()), E(() => k(s, `floe-context-action-icon ${e.class ?? ""}`)), s;
16
16
  })()
17
17
  });
18
18
  }
19
19
  function Z(e) {
20
- let i, a, r;
21
- const c = /* @__PURE__ */ new Set(), [t, o] = D(), u = () => {
22
- const n = i;
23
- return i = void 0, a = void 0, r = void 0, n;
24
- }, s = (n) => {
25
- if (e.enabled === !1 || n.defaultPrevented || n instanceof KeyboardEvent && n.key !== "ContextMenu" && !(n.shiftKey && n.key === "F10")) return;
26
- const l = n.composedPath().find((h) => h instanceof HTMLElement);
27
- if (!l || l.closest('[inert], [hidden], [role="menu"], [data-floe-context-menu-native]')) return;
28
- const g = l.getBoundingClientRect(), d = n instanceof MouseEvent && (n.clientX !== 0 || n.clientY !== 0), v = l instanceof HTMLInputElement || l instanceof HTMLTextAreaElement ? l instanceof HTMLInputElement && l.type === "password" ? "" : l.value.slice(l.selectionStart ?? 0, l.selectionEnd ?? 0) : (() => {
20
+ let r, s, c;
21
+ const i = /* @__PURE__ */ new Set(), [n, o] = D(), u = () => {
22
+ const t = r;
23
+ return r = void 0, s = void 0, c = void 0, t;
24
+ }, l = (t) => {
25
+ if (e.enabled === !1 || t.defaultPrevented || t instanceof KeyboardEvent && t.key !== "ContextMenu" && !(t.shiftKey && t.key === "F10")) return;
26
+ const a = t.composedPath().find((h) => h instanceof HTMLElement);
27
+ if (!a || a.closest('[inert], [hidden], [role="menu"], [data-floe-context-menu-native]')) return;
28
+ const g = a.getBoundingClientRect(), d = t instanceof MouseEvent && (t.clientX !== 0 || t.clientY !== 0), v = a instanceof HTMLInputElement || a instanceof HTMLTextAreaElement ? a instanceof HTMLInputElement && a.type === "password" ? "" : a.value.slice(a.selectionStart ?? 0, a.selectionEnd ?? 0) : (() => {
29
29
  const h = document.getSelection();
30
- return h?.rangeCount && h.getRangeAt(0).intersectsNode(l) ? h.toString() : "";
30
+ return h?.rangeCount && h.getRangeAt(0).intersectsNode(a) ? h.toString() : "";
31
31
  })(), w = {
32
- target: l,
33
- x: d ? n.clientX : g.left + 8,
34
- y: d ? n.clientY : g.bottom,
32
+ target: a,
33
+ x: d ? t.clientX : g.left + 8,
34
+ y: d ? t.clientY : g.bottom,
35
35
  selection: v
36
- }, y = e.actions(w), x = {
36
+ }, C = e.actions(w), x = {
37
37
  origin: w,
38
- actions: y
39
- }, $ = {
38
+ actions: C
39
+ }, I = {
40
40
  origin: w,
41
- actions: [...y, ...e.editing ? j(w, e.editing.labels, e.editing.onError) : []]
41
+ actions: [...C, ...e.editing ? j(w, e.editing.labels, e.editing.onError) : []]
42
42
  };
43
43
  if (!x.actions.length) return;
44
- i = x, a = n, r = $;
45
- const S = setTimeout(() => {
46
- i === x && (i = void 0, a = void 0, r = void 0), c.delete(S);
44
+ r = x, s = t, c = I;
45
+ const y = setTimeout(() => {
46
+ r === x && (r = void 0, s = void 0, c = void 0), i.delete(y);
47
47
  }, 0);
48
- c.add(S);
49
- }, m = (n) => {
50
- i && a === n && !n.defaultPrevented && (n.preventDefault(), o(r), u());
48
+ i.add(y);
49
+ }, m = (t) => {
50
+ r && s === t && !t.defaultPrevented && (t.preventDefault(), o(c), u());
51
51
  };
52
52
  return R(() => {
53
- document.addEventListener("contextmenu", s, !0), document.addEventListener("keydown", s, !0), window.addEventListener("contextmenu", m), window.addEventListener("keydown", m), z(() => {
54
- c.forEach(clearTimeout), i = void 0, a = void 0, r = void 0, document.removeEventListener("contextmenu", s, !0), document.removeEventListener("keydown", s, !0), window.removeEventListener("contextmenu", m), window.removeEventListener("keydown", m);
53
+ document.addEventListener("contextmenu", l, !0), document.addEventListener("keydown", l, !0), window.addEventListener("contextmenu", m), window.addEventListener("keydown", m), q(() => {
54
+ i.forEach(clearTimeout), r = void 0, s = void 0, c = void 0, document.removeEventListener("contextmenu", l, !0), document.removeEventListener("keydown", l, !0), window.removeEventListener("contextmenu", m), window.removeEventListener("keydown", m);
55
55
  });
56
- }), f(C.Provider, {
56
+ }), f(L.Provider, {
57
57
  value: {
58
58
  claim: u,
59
- resolve: (n) => e.enabled === !1 ? [] : e.actions(n)
59
+ resolve: (t) => e.enabled === !1 ? [] : e.actions(t)
60
60
  },
61
61
  get children() {
62
- return [q(() => e.children), f(T, {
62
+ return [$(() => e.children), f(T, {
63
63
  get when() {
64
- return t();
64
+ return n();
65
65
  },
66
66
  keyed: !0,
67
- children: (n) => f(Y, {
68
- request: n,
67
+ children: (t) => f(Y, {
68
+ request: t,
69
69
  get label() {
70
70
  return e.label;
71
71
  },
72
72
  get zIndex() {
73
73
  return e.zIndex;
74
74
  },
75
+ get portalScope() {
76
+ return e.portalScope;
77
+ },
75
78
  onClose: () => o(void 0)
76
79
  })
77
80
  })];
@@ -79,73 +82,78 @@ function Z(e) {
79
82
  });
80
83
  }
81
84
  function ee(e) {
82
- const i = A(C)?.claim(), a = () => i?.actions.filter((r) => !e.excludeIds?.includes(r.id)) ?? [];
85
+ const r = A(L)?.claim(), s = () => r?.actions.filter((c) => !e.excludeIds?.includes(c.id)) ?? [];
83
86
  return f(p, {
84
87
  get each() {
85
- return a();
88
+ return s();
86
89
  },
87
- children: (r) => (() => {
88
- var c = O(), t = c.firstChild;
89
- return c.$$click = () => {
90
- e.onClose(), r.onSelect();
91
- }, b(c, f(I, {
90
+ children: (c) => (() => {
91
+ var i = O(), n = i.firstChild;
92
+ return i.$$click = () => {
93
+ e.onClose(), c.onSelect();
94
+ }, b(i, f(z, {
92
95
  get icon() {
93
- return r.icon;
96
+ return c.icon;
94
97
  }
95
- }), t), b(t, () => r.label), E((o) => {
96
- var u = e.itemClass ?? "floe-context-action", s = r.id, m = r.disabled;
97
- return u !== o.e && k(c, o.e = u), s !== o.t && M(c, "data-context-action-id", o.t = s), m !== o.a && (c.disabled = o.a = m), o;
98
+ }), n), b(n, () => c.label), E((o) => {
99
+ var u = e.itemClass ?? "floe-context-action", l = c.id, m = c.disabled;
100
+ return u !== o.e && k(i, o.e = u), l !== o.t && M(i, "data-context-action-id", o.t = l), m !== o.a && (i.disabled = o.a = m), o;
98
101
  }, {
99
102
  e: void 0,
100
103
  t: void 0,
101
104
  a: void 0
102
- }), c;
105
+ }), i;
103
106
  })()
104
107
  });
105
108
  }
106
109
  function Y(e) {
107
- let i;
108
- const a = H(() => i), r = K(() => {
109
- if (!a() || !i) return {
110
+ let r;
111
+ const s = H(() => r), c = P(() => {
112
+ if (!s() || !r) return {
110
113
  width: 208,
111
114
  height: 8 + e.request.actions.length * 30
112
115
  };
113
- const t = i.getBoundingClientRect();
116
+ const n = r.getBoundingClientRect();
114
117
  return {
115
- width: t.width,
116
- height: t.height
118
+ width: n.width,
119
+ height: n.height
117
120
  };
118
- }), c = (t = !1) => {
119
- e.onClose(), t && e.request.origin.target.isConnected && e.request.origin.target.focus({
121
+ }), i = (n = !1) => {
122
+ e.onClose(), n && e.request.origin.target.isConnected && e.request.origin.target.focus({
120
123
  preventScroll: !0
121
124
  });
122
125
  };
123
126
  return R(() => {
124
- i.querySelector('[role="menuitem"]:not(:disabled)')?.focus({
127
+ r.querySelector('[role="menuitem"]:not(:disabled)')?.focus({
125
128
  preventScroll: !0
126
129
  });
127
- const t = (u) => {
128
- u.target instanceof Node && !i.contains(u.target) && c();
129
- }, o = () => c();
130
- document.addEventListener("pointerdown", t, !0), document.addEventListener("focusin", t, !0), document.addEventListener("scroll", t, !0), window.addEventListener("resize", o), window.addEventListener("blur", o), z(() => {
131
- document.removeEventListener("pointerdown", t, !0), document.removeEventListener("focusin", t, !0), document.removeEventListener("scroll", t, !0), window.removeEventListener("resize", o), window.removeEventListener("blur", o);
130
+ const n = (l) => {
131
+ l.target instanceof Node && !r.contains(l.target) && i();
132
+ }, o = (l) => {
133
+ l.target instanceof Node && l.target.contains(e.request.origin.target) && i();
134
+ }, u = () => i();
135
+ document.addEventListener("pointerdown", n, !0), document.addEventListener("focusin", n, !0), document.addEventListener("scroll", o, !0), window.addEventListener("resize", u), window.addEventListener("blur", u), q(() => {
136
+ document.removeEventListener("pointerdown", n, !0), document.removeEventListener("focusin", n, !0), document.removeEventListener("scroll", o, !0), window.removeEventListener("resize", u), window.removeEventListener("blur", u);
132
137
  });
133
- }), f(N, {
138
+ }), f(K, {
134
139
  get owner() {
135
140
  return e.request.origin.target;
136
141
  },
142
+ get portalScope() {
143
+ return e.portalScope;
144
+ },
137
145
  get position() {
138
146
  return e.request.origin;
139
147
  },
140
148
  get estimatedSize() {
141
- return r();
149
+ return c();
142
150
  },
143
151
  role: "menu",
144
152
  get "aria-label"() {
145
153
  return e.label;
146
154
  },
147
- layerRef: (t) => {
148
- i = t;
155
+ layerRef: (n) => {
156
+ r = n;
149
157
  },
150
158
  class: "floe-context-actions",
151
159
  get style() {
@@ -153,10 +161,10 @@ function Y(e) {
153
161
  "z-index": e.zIndex
154
162
  };
155
163
  },
156
- onContextMenu: (t) => t.preventDefault(),
157
- onKeyDown: (t) => _(t, {
164
+ onContextMenu: (n) => n.preventDefault(),
165
+ onKeyDown: (n) => _(n, {
158
166
  onActivate: (o) => o.click(),
159
- onDismiss: () => c(!0),
167
+ onDismiss: () => i(!0),
160
168
  preventDefaultOnTab: !0
161
169
  }),
162
170
  get children() {
@@ -164,17 +172,17 @@ function Y(e) {
164
172
  get each() {
165
173
  return e.request.actions;
166
174
  },
167
- children: (t) => (() => {
175
+ children: (n) => (() => {
168
176
  var o = X(), u = o.firstChild;
169
177
  return o.$$click = () => {
170
- c(), t.onSelect();
171
- }, b(o, f(I, {
178
+ i(), n.onSelect();
179
+ }, b(o, f(z, {
172
180
  get icon() {
173
- return t.icon;
181
+ return n.icon;
174
182
  }
175
- }), u), b(u, () => t.label), E((s) => {
176
- var m = t.id, n = t.disabled;
177
- return m !== s.e && M(o, "data-context-action-id", s.e = m), n !== s.t && (o.disabled = s.t = n), s;
183
+ }), u), b(u, () => n.label), E((l) => {
184
+ var m = n.id, t = n.disabled;
185
+ return m !== l.e && M(o, "data-context-action-id", l.e = m), t !== l.t && (o.disabled = l.t = t), l;
178
186
  }, {
179
187
  e: void 0,
180
188
  t: void 0
@@ -184,58 +192,58 @@ function Y(e) {
184
192
  }
185
193
  });
186
194
  }
187
- function j(e, i, a) {
188
- const r = e.target.closest('input, textarea, [contenteditable]:not([contenteditable="false"])'), c = r instanceof HTMLInputElement || r instanceof HTMLTextAreaElement ? r : null, t = document.getSelection()?.rangeCount ? document.getSelection().getRangeAt(0).cloneRange() : void 0, o = c?.selectionStart, u = c?.selectionEnd, s = () => {
189
- if (r?.focus({
195
+ function j(e, r, s) {
196
+ const c = e.target.closest('input, textarea, [contenteditable]:not([contenteditable="false"])'), i = c instanceof HTMLInputElement || c instanceof HTMLTextAreaElement ? c : null, n = document.getSelection()?.rangeCount ? document.getSelection().getRangeAt(0).cloneRange() : void 0, o = i?.selectionStart, u = i?.selectionEnd, l = () => {
197
+ if (c?.focus({
190
198
  preventScroll: !0
191
- }), c && o != null && u != null) c.setSelectionRange(o, u);
192
- else if (t) {
199
+ }), i && o != null && u != null) i.setSelectionRange(o, u);
200
+ else if (n) {
193
201
  const d = document.getSelection();
194
- d?.removeAllRanges(), d?.addRange(t);
202
+ d?.removeAllRanges(), d?.addRange(n);
195
203
  }
196
204
  }, m = (d) => () => {
197
205
  try {
198
- Promise.resolve(d()).catch(a);
206
+ Promise.resolve(d()).catch(s);
199
207
  } catch (v) {
200
- a(v);
208
+ s(v);
201
209
  }
202
- }, n = (d) => ({
210
+ }, t = (d) => ({
203
211
  id: `edit.${d}`,
204
- label: i[d],
212
+ label: r[d],
205
213
  onSelect: m(async () => {
206
- if (s(), d === "selectAll" && c) {
207
- c.select();
214
+ if (l(), d === "selectAll" && i) {
215
+ i.select();
208
216
  return;
209
217
  }
210
218
  if (document.execCommand(d) || d !== "paste") return;
211
219
  const v = await navigator.clipboard.readText();
212
- if (r?.isConnected && (s(), !document.execCommand("insertText", !1, v)))
220
+ if (c?.isConnected && (l(), !document.execCommand("insertText", !1, v)))
213
221
  throw new Error("Clipboard insertion is unavailable.");
214
222
  })
215
- }), l = [];
216
- r && l.push(n("undo"), n("redo"), n("cut")), e.selection && l.push({
223
+ }), a = [];
224
+ c && a.push(t("undo"), t("redo"), t("cut")), e.selection && a.push({
217
225
  id: "edit.copy",
218
- label: i.copy,
226
+ label: r.copy,
219
227
  onSelect: m(() => navigator.clipboard.writeText(e.selection))
220
- }), r && l.push(n("paste"), n("selectAll"));
228
+ }), c && a.push(t("paste"), t("selectAll"));
221
229
  const g = e.target.closest("a[href]");
222
230
  if (g && ["http:", "https:", "mailto:"].includes(g.protocol)) {
223
231
  const d = g.href;
224
- l.push({
232
+ a.push({
225
233
  id: "link.open",
226
- label: i.openLink,
234
+ label: r.openLink,
227
235
  onSelect: () => window.open(d, "_blank", "noopener,noreferrer")
228
- }), l.push({
236
+ }), a.push({
229
237
  id: "link.copy",
230
- label: i.copyLink,
238
+ label: r.copyLink,
231
239
  onSelect: m(() => navigator.clipboard.writeText(d))
232
240
  });
233
241
  }
234
- return l;
242
+ return a;
235
243
  }
236
244
  F(["click"]);
237
245
  export {
238
- I as ContextMenuActionIcon,
246
+ z as ContextMenuActionIcon,
239
247
  ee as ContextMenuActionItems,
240
248
  Z as ContextMenuActions,
241
249
  W as useContextMenuActions
@@ -12,6 +12,8 @@ export interface SurfaceFloatingLayerProps extends Omit<JSX.HTMLAttributes<HTMLD
12
12
  position: SurfaceFloatingLayerPosition;
13
13
  /** Stable trigger or anchor used to resolve the owning projected surface. */
14
14
  owner?: Element | null;
15
+ /** Global commands may escape their source surface without changing the owner. */
16
+ portalScope?: 'surface' | 'viewport';
15
17
  boundary?: SurfaceFloatingBoundary;
16
18
  estimatedSize?: SurfaceFloatingLayerSize;
17
19
  clamp?: boolean;
@@ -1,12 +1,12 @@
1
- import { createComponent as S, Portal as v, use as h, spread as g, mergeProps as A, insert as P, template as R } from "solid-js/web";
2
- import { observeViewport as w } from "../../viewport.js";
1
+ import { createComponent as S, Portal as v, use as h, spread as g, mergeProps as w, insert as A, template as P } from "solid-js/web";
2
+ import { observeViewport as R } from "../../viewport.js";
3
3
  import { splitProps as _, createSignal as b, onMount as x, onCleanup as C, createMemo as s } from "solid-js";
4
4
  import { cn as T } from "../../utils/cn.js";
5
5
  import { LOCAL_INTERACTION_SURFACE_ATTR as z } from "./localInteractionSurface.js";
6
6
  import { clampMenuPosition as M } from "./menuUtils.js";
7
- import { readSurfaceSafeArea as F, resolveFloatingBoundary as L } from "./surfaceFloatingBoundary.js";
8
- import { resolveSurfacePortalHost as $, SURFACE_FLOATING_LAYER_ATTR as E, resolveSurfacePortalMount as O, isSurfacePortalMode as B, projectSurfacePortalPosition as I } from "./dialogSurfaceScope.js";
9
- var N = /* @__PURE__ */ R("<div>");
7
+ import { readSurfaceSafeArea as E, resolveFloatingBoundary as F } from "./surfaceFloatingBoundary.js";
8
+ import { resolveSurfacePortalHost as L, SURFACE_FLOATING_LAYER_ATTR as $, resolveSurfacePortalMount as O, isSurfacePortalMode as B, projectSurfacePortalPosition as I } from "./dialogSurfaceScope.js";
9
+ var N = /* @__PURE__ */ P("<div>");
10
10
  function j() {
11
11
  return {
12
12
  left: 0,
@@ -18,11 +18,11 @@ function j() {
18
18
  };
19
19
  }
20
20
  function J(c) {
21
- const [e, f] = _(c, ["position", "owner", "boundary", "estimatedSize", "clamp", "class", "style", "children", "layerRef"]), [a, p] = b();
22
- x(() => C(w(window, p)));
23
- const r = s(() => $({
24
- owner: e.owner ?? null
25
- })), n = () => B(r()), u = s(() => (e.position, a()?.safeArea ?? F())), i = () => L(r(), e.boundary, u()) ?? j(), m = () => e.clamp !== !1 && !!e.estimatedSize, d = s(() => {
21
+ const [e, p] = _(c, ["position", "owner", "portalScope", "boundary", "estimatedSize", "clamp", "class", "style", "children", "layerRef"]), [a, u] = b();
22
+ x(() => C(R(window, u)));
23
+ const r = s(() => L({
24
+ owner: e.portalScope === "viewport" ? document.documentElement : e.owner ?? null
25
+ })), n = () => B(r()), f = s(() => (e.position, a()?.safeArea ?? E())), i = () => F(r(), e.boundary, f()) ?? j(), m = () => e.clamp !== !1 && !!e.estimatedSize, d = s(() => {
26
26
  const t = e.position;
27
27
  return !m() || !e.estimatedSize ? t : M(t, e.estimatedSize, i());
28
28
  }), l = () => {
@@ -46,7 +46,7 @@ function J(c) {
46
46
  },
47
47
  get children() {
48
48
  var t = N(), o = e.layerRef;
49
- return typeof o == "function" ? h(o, t) : e.layerRef = t, g(t, A(f, {
49
+ return typeof o == "function" ? h(o, t) : e.layerRef = t, g(t, w(p, {
50
50
  get class() {
51
51
  return T(n() ? "absolute z-20" : "fixed z-50", e.class);
52
52
  },
@@ -54,10 +54,10 @@ function J(c) {
54
54
  return y();
55
55
  }
56
56
  }, {
57
- [E]: "true"
57
+ [$]: "true"
58
58
  }, () => ({
59
59
  [z]: n() ? "true" : void 0
60
- })), !1, !0), P(t, () => e.children), t;
60
+ })), !1, !0), A(t, () => e.children), t;
61
61
  }
62
62
  });
63
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.98.1",
3
+ "version": "0.99.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",