@floegence/floe-webapp-core 0.94.1 → 0.95.0

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.
@@ -0,0 +1,238 @@
1
+ import { createComponent as f, insert as g, effect as k, className as q, setAttribute as M, memo as I, template as E, delegateEvents as F } from "solid-js/web";
2
+ import { useResizeObserver as H } from "../../hooks/useResizeObserver.js";
3
+ import { useContext as T, For as p, Show as L, createSignal as D, onMount as A, onCleanup as R, createContext as P, createMemo as _ } from "solid-js";
4
+ import { SurfaceFloatingLayer as K } from "./SurfaceFloatingLayer.js";
5
+ import { handleMenuKeyboardNavigation as N } from "./menuUtils.js";
6
+ var B = /* @__PURE__ */ E("<button type=button role=menuitem><span>"), z = /* @__PURE__ */ E("<span aria-hidden=true>"), O = /* @__PURE__ */ E("<button type=button role=menuitem class=floe-context-action><span>");
7
+ const y = P(), V = () => T(y);
8
+ function W(n) {
9
+ let c, m, i;
10
+ const r = /* @__PURE__ */ new Set(), [e, o] = D(), s = () => {
11
+ const t = c;
12
+ return c = void 0, m = void 0, i = void 0, t;
13
+ }, a = (t) => {
14
+ if (n.enabled === !1 || t.defaultPrevented || t instanceof KeyboardEvent && t.key !== "ContextMenu" && !(t.shiftKey && t.key === "F10")) return;
15
+ const l = t.composedPath().find((b) => b instanceof HTMLElement);
16
+ if (!l || l.closest('[inert], [hidden], [role="menu"], [data-floe-context-menu-native]')) return;
17
+ const v = l.getBoundingClientRect(), u = t instanceof MouseEvent && (t.clientX !== 0 || t.clientY !== 0), h = l instanceof HTMLInputElement || l instanceof HTMLTextAreaElement ? l instanceof HTMLInputElement && l.type === "password" ? "" : l.value.slice(l.selectionStart ?? 0, l.selectionEnd ?? 0) : (() => {
18
+ const b = document.getSelection();
19
+ return b?.rangeCount && b.getRangeAt(0).intersectsNode(l) ? b.toString() : "";
20
+ })(), w = {
21
+ target: l,
22
+ x: u ? t.clientX : v.left + 8,
23
+ y: u ? t.clientY : v.bottom,
24
+ selection: h
25
+ }, C = n.actions(w), x = {
26
+ origin: w,
27
+ actions: C
28
+ }, $ = {
29
+ origin: w,
30
+ actions: [...C, ...n.editing ? Y(w, n.editing.labels, n.editing.onError) : []]
31
+ };
32
+ if (!x.actions.length) return;
33
+ c = x, m = t, i = $;
34
+ const S = setTimeout(() => {
35
+ c === x && (c = void 0, m = void 0, i = void 0), r.delete(S);
36
+ }, 0);
37
+ r.add(S);
38
+ }, d = (t) => {
39
+ c && m === t && !t.defaultPrevented && (t.preventDefault(), o(i), s());
40
+ };
41
+ return A(() => {
42
+ document.addEventListener("contextmenu", a, !0), document.addEventListener("keydown", a, !0), window.addEventListener("contextmenu", d), window.addEventListener("keydown", d), R(() => {
43
+ r.forEach(clearTimeout), c = void 0, m = void 0, i = void 0, document.removeEventListener("contextmenu", a, !0), document.removeEventListener("keydown", a, !0), window.removeEventListener("contextmenu", d), window.removeEventListener("keydown", d);
44
+ });
45
+ }), f(y.Provider, {
46
+ value: {
47
+ claim: s,
48
+ resolve: (t) => n.enabled === !1 ? [] : n.actions(t)
49
+ },
50
+ get children() {
51
+ return [I(() => n.children), f(L, {
52
+ get when() {
53
+ return e();
54
+ },
55
+ keyed: !0,
56
+ children: (t) => f(X, {
57
+ request: t,
58
+ get label() {
59
+ return n.label;
60
+ },
61
+ get zIndex() {
62
+ return n.zIndex;
63
+ },
64
+ onClose: () => o(void 0)
65
+ })
66
+ })];
67
+ }
68
+ });
69
+ }
70
+ function Z(n) {
71
+ const c = T(y)?.claim(), m = () => c?.actions.filter((i) => !n.excludeIds?.includes(i.id)) ?? [];
72
+ return f(p, {
73
+ get each() {
74
+ return m();
75
+ },
76
+ children: (i) => (() => {
77
+ var r = B(), e = r.firstChild;
78
+ return r.$$click = () => {
79
+ n.onClose(), i.onSelect();
80
+ }, g(r, f(L, {
81
+ get when() {
82
+ return i.icon;
83
+ },
84
+ children: (o) => (() => {
85
+ var s = z();
86
+ return g(s, () => o()()), s;
87
+ })()
88
+ }), e), g(e, () => i.label), k((o) => {
89
+ var s = n.itemClass ?? "floe-context-action", a = i.id, d = i.disabled;
90
+ return s !== o.e && q(r, o.e = s), a !== o.t && M(r, "data-context-action-id", o.t = a), d !== o.a && (r.disabled = o.a = d), o;
91
+ }, {
92
+ e: void 0,
93
+ t: void 0,
94
+ a: void 0
95
+ }), r;
96
+ })()
97
+ });
98
+ }
99
+ function X(n) {
100
+ let c;
101
+ const m = H(() => c), i = _(() => {
102
+ if (!m() || !c) return {
103
+ width: 208,
104
+ height: 8 + n.request.actions.length * 30
105
+ };
106
+ const e = c.getBoundingClientRect();
107
+ return {
108
+ width: e.width,
109
+ height: e.height
110
+ };
111
+ }), r = (e = !1) => {
112
+ n.onClose(), e && n.request.origin.target.isConnected && n.request.origin.target.focus({
113
+ preventScroll: !0
114
+ });
115
+ };
116
+ return A(() => {
117
+ c.querySelector('[role="menuitem"]:not(:disabled)')?.focus({
118
+ preventScroll: !0
119
+ });
120
+ const e = (s) => {
121
+ s.target instanceof Node && !c.contains(s.target) && r();
122
+ }, o = () => r();
123
+ document.addEventListener("pointerdown", e, !0), document.addEventListener("focusin", e, !0), document.addEventListener("scroll", e, !0), window.addEventListener("resize", o), window.addEventListener("blur", o), R(() => {
124
+ document.removeEventListener("pointerdown", e, !0), document.removeEventListener("focusin", e, !0), document.removeEventListener("scroll", e, !0), window.removeEventListener("resize", o), window.removeEventListener("blur", o);
125
+ });
126
+ }), f(K, {
127
+ get owner() {
128
+ return n.request.origin.target;
129
+ },
130
+ get position() {
131
+ return n.request.origin;
132
+ },
133
+ get estimatedSize() {
134
+ return i();
135
+ },
136
+ role: "menu",
137
+ get "aria-label"() {
138
+ return n.label;
139
+ },
140
+ layerRef: (e) => {
141
+ c = e;
142
+ },
143
+ class: "floe-context-actions",
144
+ get style() {
145
+ return {
146
+ "z-index": n.zIndex
147
+ };
148
+ },
149
+ onContextMenu: (e) => e.preventDefault(),
150
+ onKeyDown: (e) => N(e, {
151
+ onActivate: (o) => o.click(),
152
+ onDismiss: () => r(!0),
153
+ preventDefaultOnTab: !0
154
+ }),
155
+ get children() {
156
+ return f(p, {
157
+ get each() {
158
+ return n.request.actions;
159
+ },
160
+ children: (e) => (() => {
161
+ var o = O(), s = o.firstChild;
162
+ return o.$$click = () => {
163
+ r(), e.onSelect();
164
+ }, g(o, f(L, {
165
+ get when() {
166
+ return e.icon;
167
+ },
168
+ children: (a) => (() => {
169
+ var d = z();
170
+ return g(d, () => a()()), d;
171
+ })()
172
+ }), s), g(s, () => e.label), k((a) => {
173
+ var d = e.id, t = e.disabled;
174
+ return d !== a.e && M(o, "data-context-action-id", a.e = d), t !== a.t && (o.disabled = a.t = t), a;
175
+ }, {
176
+ e: void 0,
177
+ t: void 0
178
+ }), o;
179
+ })()
180
+ });
181
+ }
182
+ });
183
+ }
184
+ function Y(n, c, m) {
185
+ const i = n.target.closest('input, textarea, [contenteditable]:not([contenteditable="false"])'), r = i instanceof HTMLInputElement || i instanceof HTMLTextAreaElement ? i : null, e = document.getSelection()?.rangeCount ? document.getSelection().getRangeAt(0).cloneRange() : void 0, o = r?.selectionStart, s = r?.selectionEnd, a = () => {
186
+ if (i?.focus({
187
+ preventScroll: !0
188
+ }), r && o != null && s != null) r.setSelectionRange(o, s);
189
+ else if (e) {
190
+ const u = document.getSelection();
191
+ u?.removeAllRanges(), u?.addRange(e);
192
+ }
193
+ }, d = (u) => () => {
194
+ try {
195
+ Promise.resolve(u()).catch(m);
196
+ } catch (h) {
197
+ m(h);
198
+ }
199
+ }, t = (u) => ({
200
+ id: `edit.${u}`,
201
+ label: c[u],
202
+ onSelect: d(async () => {
203
+ if (a(), u === "selectAll" && r) {
204
+ r.select();
205
+ return;
206
+ }
207
+ if (document.execCommand(u) || u !== "paste") return;
208
+ const h = await navigator.clipboard.readText();
209
+ if (i?.isConnected && (a(), !document.execCommand("insertText", !1, h)))
210
+ throw new Error("Clipboard insertion is unavailable.");
211
+ })
212
+ }), l = [];
213
+ i && l.push(t("undo"), t("redo"), t("cut")), n.selection && l.push({
214
+ id: "edit.copy",
215
+ label: c.copy,
216
+ onSelect: d(() => navigator.clipboard.writeText(n.selection))
217
+ }), i && l.push(t("paste"), t("selectAll"));
218
+ const v = n.target.closest("a[href]");
219
+ if (v && ["http:", "https:", "mailto:"].includes(v.protocol)) {
220
+ const u = v.href;
221
+ l.push({
222
+ id: "link.open",
223
+ label: c.openLink,
224
+ onSelect: () => window.open(u, "_blank", "noopener,noreferrer")
225
+ }), l.push({
226
+ id: "link.copy",
227
+ label: c.copyLink,
228
+ onSelect: d(() => navigator.clipboard.writeText(u))
229
+ });
230
+ }
231
+ return l;
232
+ }
233
+ F(["click"]);
234
+ export {
235
+ Z as ContextMenuActionItems,
236
+ W as ContextMenuActions,
237
+ V as useContextMenuActions
238
+ };
@@ -1,6 +1,7 @@
1
- export { createContextSourceRegistry, type ContextSource, type ContextSourceSnapshot } from './contextSource';
1
+ export { ContextMenuActions, ContextMenuActionItems, useContextMenuActions, type ContextMenuEditingLabels, type ContextMenuActionRequest, type ContextMenuAction, type ContextMenuRequest, } from './ContextMenuActions';
2
+ export { createContextSourceRegistry, type ContextSource, type ContextSourceSnapshot, } from './contextSource';
2
3
  export { PromptCard, capturePromptCardAnchor, type PromptCardProps } from './PromptCard';
3
- export { FeedbackIndicator, type FeedbackIndicatorProps, type FeedbackIndicatorEntry } from './FeedbackIndicator';
4
+ export { FeedbackIndicator, type FeedbackIndicatorProps, type FeedbackIndicatorEntry, } from './FeedbackIndicator';
4
5
  export { Button, type ButtonProps, type ButtonVariant, type ButtonSize } from './Button';
5
6
  export { StableText, type StableTextProps } from './StableText';
6
7
  export { StatusRegion, type StatusRegionProps } from './StatusRegion';
@@ -49,20 +50,20 @@ export { MobileKeyboard, type MobileKeyboardProps, type MobileKeyboardSuggestion
49
50
  export { LinearProgress, CircularProgress, SegmentedProgress, StepsProgress, type LinearProgressProps, type CircularProgressProps, type SegmentedProgressProps, type StepsProgressProps, type ProgressSize, type ProgressColor, } from './Progress';
50
51
  export { SurfaceAnchoredLayer, type SurfaceAnchoredLayerProps } from './SurfaceAnchoredLayer';
51
52
  export { WindowTabs } from './WindowTabs';
52
- export { PersistentHorizontalScrollbar, type PersistentHorizontalScrollbarProps } from './PersistentHorizontalScrollbar';
53
+ export { PersistentHorizontalScrollbar, type PersistentHorizontalScrollbarProps, } from './PersistentHorizontalScrollbar';
53
54
  export { SettingsLayout, SettingsNavigation, SettingsSection, SettingsList, SettingRow, type SettingsNavigationItem, type SettingsNavigationGroup, type SettingsNavigationProps, type SettingsSectionProps, type SettingRowProps, } from './Settings';
54
55
  export { KeyedFor, type KeyedForProps } from './KeyedFor';
55
56
  export { DirectoryFavoriteButton } from './picker/DirectoryFavorites';
56
57
  export type { DirectoryFavorites } from './picker/DirectoryFavorites';
57
- export { useFormControl, useFormField, joinAriaIds, type FormFieldBinding } from './formFieldContext';
58
+ export { useFormControl, useFormField, joinAriaIds, type FormFieldBinding, } from './formFieldContext';
58
59
  export { createControllableValue } from './controllable';
59
- export { Combobox, MultiSelect, type SelectOption, type SelectBaseProps, type MultiSelectProps } from './Select';
60
- export { Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption } from './Table';
60
+ export { Combobox, MultiSelect, type SelectOption, type SelectBaseProps, type MultiSelectProps, } from './Select';
61
+ export { Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption, } from './Table';
61
62
  export { DataTable, type DataTableProps, type DataTableColumn } from './DataTable';
62
63
  export { createTableModel, type TableSort, type TableModelOptions } from './dataTableModel';
63
64
  export { Breadcrumb, type BreadcrumbProps, type BreadcrumbItem } from './Breadcrumb';
64
65
  export { Accordion, type AccordionProps, type AccordionItem } from './Accordion';
65
66
  export { Slider, type SliderProps } from './Slider';
66
67
  export { Calendar, type CalendarProps } from './Calendar';
67
- export { DatePicker, DateRangePicker, type DatePickerProps, type DateRangePickerProps, type DateRange } from './DatePicker';
68
- export { parseCalendarDate, formatCalendarDate, addCalendarDays, addCalendarMonths, calendarDays } from './calendarModel';
68
+ export { DatePicker, DateRangePicker, type DatePickerProps, type DateRangePickerProps, type DateRange, } from './DatePicker';
69
+ export { parseCalendarDate, formatCalendarDate, addCalendarDays, addCalendarMonths, calendarDays, } from './calendarModel';