@floegence/floe-webapp-core 0.36.3 → 0.36.4

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,178 +1,192 @@
1
- import { insert as u, createComponent as v, memo as E, effect as B, setAttribute as G, setStyleProperty as m, template as A, delegateEvents as N } from "solid-js/web";
2
- import { createSignal as R, onCleanup as O, untrack as I, createMemo as H } from "solid-js";
3
- import { startHotInteraction as P } from "../../utils/hotInteraction.js";
4
- import { GripVertical as q, X as V } from "../icons/index.js";
5
- var Z = /* @__PURE__ */ A('<article class=workbench-widget data-floe-dialog-surface-host=true><header class=workbench-widget__header><button type=button class=workbench-widget__drag aria-label="Drag widget"data-floe-canvas-interactive=true></button><div class=workbench-widget__title-area><span class=workbench-widget__title></span></div><button type=button class=workbench-widget__close aria-label="Remove widget"data-floe-canvas-interactive=true></button></header><div class=workbench-widget__body data-floe-canvas-interactive=true>'), j = /* @__PURE__ */ A('<div class=workbench-widget__resize aria-label="Resize widget"data-floe-canvas-interactive=true><svg class=workbench-widget__resize-glyph viewBox="0 0 12 12"aria-hidden=true><path d="M12 0 L0 12"></path><path d="M12 4 L4 12"></path><path d="M12 8 L8 12">');
6
- const J = 220, K = 160;
7
- function et(e) {
8
- const [b, x] = R(null), [f, C] = R(null);
9
- let h, w;
10
- O(() => {
11
- h?.abort(), h = void 0, w?.abort(), w = void 0, I(b)?.stopInteraction(), I(f)?.stopInteraction();
1
+ import { spread as G, insert as u, createComponent as I, memo as K, effect as V, setAttribute as q, setStyleProperty as m, template as P, use as U, delegateEvents as j } from "solid-js/web";
2
+ import { createSignal as H, onCleanup as J, untrack as _, createMemo as A } from "solid-js";
3
+ import { startHotInteraction as O } from "../../utils/hotInteraction.js";
4
+ import { GripVertical as Q, X as Z } from "../icons/index.js";
5
+ import { WORKBENCH_WIDGET_SHELL_ATTR as p, resolveWorkbenchWidgetEventOwnership as tt } from "../ui/localInteractionSurface.js";
6
+ var et = /* @__PURE__ */ P('<article class=workbench-widget data-floe-dialog-surface-host=true tabindex=0><header class=workbench-widget__header><button type=button class=workbench-widget__drag aria-label="Drag widget"data-floe-canvas-interactive=true></button><div class=workbench-widget__title-area><span class=workbench-widget__title></span></div><button type=button class=workbench-widget__close aria-label="Remove widget"data-floe-canvas-interactive=true></button></header><div class=workbench-widget__body data-floe-canvas-interactive=true>'), it = /* @__PURE__ */ P('<div class=workbench-widget__resize aria-label="Resize widget"data-floe-canvas-interactive=true><svg class=workbench-widget__resize-glyph viewBox="0 0 12 12"aria-hidden=true><path d="M12 0 L0 12"></path><path d="M12 4 L4 12"></path><path d="M12 8 L8 12">');
7
+ const nt = 220, ot = 160, at = '[data-floe-canvas-interactive="true"]', rt = '[data-floe-canvas-pan-surface="true"]';
8
+ function ht(i) {
9
+ const [f, C] = H(null), [v, x] = H(null);
10
+ let h, w, b;
11
+ J(() => {
12
+ h?.abort(), h = void 0, w?.abort(), w = void 0, _(f)?.stopInteraction(), _(v)?.stopInteraction();
12
13
  });
13
- const M = () => b() !== null, k = () => f() !== null, y = H(() => {
14
- const i = b();
15
- return i ? {
16
- x: i.worldX,
17
- y: i.worldY
14
+ const S = () => f() !== null, y = () => v() !== null, E = (e) => tt({
15
+ target: e,
16
+ widgetRoot: b ?? null,
17
+ interactiveSelector: at,
18
+ panSurfaceSelector: rt
19
+ }), N = (e) => {
20
+ e.button === 0 && (i.onSelect(i.widgetId), i.onCommitFront(i.widgetId), E(e.target) === "widget_shell" && b?.focus({
21
+ preventScroll: !0
22
+ }));
23
+ }, W = A(() => {
24
+ const e = f();
25
+ return e ? {
26
+ x: e.worldX,
27
+ y: e.worldY
18
28
  } : {
19
- x: e.x,
20
- y: e.y
29
+ x: i.x,
30
+ y: i.y
21
31
  };
22
- }), _ = H(() => {
23
- const i = f();
24
- return i ? {
25
- width: i.width,
26
- height: i.height
27
- } : {
32
+ }), M = A(() => {
33
+ const e = v();
34
+ return e ? {
28
35
  width: e.width,
29
36
  height: e.height
37
+ } : {
38
+ width: i.width,
39
+ height: i.height
30
40
  };
31
- }), $ = (i) => {
32
- const o = I(b);
33
- if (!o) return;
41
+ }), $ = (e) => {
42
+ const n = _(f);
43
+ if (!n) return;
34
44
  const a = {
35
- x: o.worldX,
36
- y: o.worldY
45
+ x: n.worldX,
46
+ y: n.worldY
37
47
  }, r = {
38
- x: o.startWorldX,
39
- y: o.startWorldY
40
- }, l = i && (Math.abs(a.x - r.x) > 1 || Math.abs(a.y - r.y) > 1);
41
- e.onCommitFront(e.widgetId), l && e.onCommitMove(e.widgetId, a), o.stopInteraction(), x(null), h?.abort(), h = void 0;
42
- }, F = (i) => {
43
- if (i.button !== 0 || e.locked) return;
44
- i.preventDefault(), i.stopPropagation(), h?.abort(), e.onStartOptimisticFront(e.widgetId);
45
- const o = P({
48
+ x: n.startWorldX,
49
+ y: n.startWorldY
50
+ }, s = e && (Math.abs(a.x - r.x) > 1 || Math.abs(a.y - r.y) > 1);
51
+ i.onCommitFront(i.widgetId), s && i.onCommitMove(i.widgetId, a), n.stopInteraction(), C(null), h?.abort(), h = void 0;
52
+ }, F = (e) => {
53
+ if (e.button !== 0 || i.locked) return;
54
+ e.preventDefault(), e.stopPropagation(), h?.abort(), i.onStartOptimisticFront(i.widgetId);
55
+ const n = O({
46
56
  kind: "drag",
47
57
  cursor: "grabbing"
48
- }), a = Math.max(e.viewportScale, 1e-3);
49
- x({
50
- pointerId: i.pointerId,
51
- startClientX: i.clientX,
52
- startClientY: i.clientY,
53
- startWorldX: e.x,
54
- startWorldY: e.y,
55
- worldX: e.x,
56
- worldY: e.y,
58
+ }), a = Math.max(i.viewportScale, 1e-3);
59
+ C({
60
+ pointerId: e.pointerId,
61
+ startClientX: e.clientX,
62
+ startClientY: e.clientY,
63
+ startWorldX: i.x,
64
+ startWorldY: i.y,
65
+ worldX: i.x,
66
+ worldY: i.y,
57
67
  moved: !1,
58
68
  scale: a,
59
- stopInteraction: o
69
+ stopInteraction: n
60
70
  });
61
- const r = (t) => {
62
- x((n) => {
63
- if (!n || n.pointerId !== t.pointerId) return n;
64
- const c = n.startWorldX + (t.clientX - n.startClientX) / n.scale, g = n.startWorldY + (t.clientY - n.startClientY) / n.scale;
71
+ const r = (o) => {
72
+ C((t) => {
73
+ if (!t || t.pointerId !== o.pointerId) return t;
74
+ const d = t.startWorldX + (o.clientX - t.startClientX) / t.scale, g = t.startWorldY + (o.clientY - t.startClientY) / t.scale;
65
75
  return {
66
- ...n,
67
- worldX: c,
76
+ ...t,
77
+ worldX: d,
68
78
  worldY: g,
69
- moved: n.moved || Math.abs(c - n.startWorldX) > 2 || Math.abs(g - n.startWorldY) > 2
79
+ moved: t.moved || Math.abs(d - t.startWorldX) > 2 || Math.abs(g - t.startWorldY) > 2
70
80
  };
71
81
  });
72
- }, l = (t) => {
73
- t.pointerId === i.pointerId && $(!0);
74
- }, s = (t) => {
75
- t.pointerId === i.pointerId && $(!1);
76
- }, d = new AbortController();
77
- h = d, window.addEventListener("pointermove", r, {
78
- signal: d.signal
79
- }), window.addEventListener("pointerup", l, {
82
+ }, s = (o) => {
83
+ o.pointerId === e.pointerId && $(!0);
84
+ }, c = (o) => {
85
+ o.pointerId === e.pointerId && $(!1);
86
+ }, l = new AbortController();
87
+ h = l, window.addEventListener("pointermove", r, {
88
+ signal: l.signal
89
+ }), window.addEventListener("pointerup", s, {
80
90
  once: !0,
81
- signal: d.signal
82
- }), window.addEventListener("pointercancel", s, {
91
+ signal: l.signal
92
+ }), window.addEventListener("pointercancel", c, {
83
93
  once: !0,
84
- signal: d.signal
94
+ signal: l.signal
85
95
  });
86
- }, S = (i) => {
87
- const o = I(f);
88
- if (!o) return;
96
+ }, k = (e) => {
97
+ const n = _(v);
98
+ if (!n) return;
89
99
  const a = {
90
- width: o.width,
91
- height: o.height
92
- }, r = Math.abs(o.width - o.startWidth) > 1 || Math.abs(o.height - o.startHeight) > 1;
93
- i && r && e.onCommitResize(e.widgetId, a), o.stopInteraction(), C(null), w?.abort(), w = void 0;
94
- }, T = (i) => {
95
- if (i.button !== 0 || e.locked) return;
96
- i.preventDefault(), i.stopPropagation(), w?.abort(), e.onStartOptimisticFront(e.widgetId);
97
- const o = P({
100
+ width: n.width,
101
+ height: n.height
102
+ }, r = Math.abs(n.width - n.startWidth) > 1 || Math.abs(n.height - n.startHeight) > 1;
103
+ e && r && i.onCommitResize(i.widgetId, a), n.stopInteraction(), x(null), w?.abort(), w = void 0;
104
+ }, B = (e) => {
105
+ if (e.button !== 0 || i.locked) return;
106
+ e.preventDefault(), e.stopPropagation(), w?.abort(), i.onStartOptimisticFront(i.widgetId);
107
+ const n = O({
98
108
  kind: "drag",
99
109
  cursor: "nwse-resize"
100
- }), a = Math.max(e.viewportScale, 1e-3);
101
- C({
102
- pointerId: i.pointerId,
103
- startClientX: i.clientX,
104
- startClientY: i.clientY,
105
- startWidth: e.width,
106
- startHeight: e.height,
107
- width: e.width,
108
- height: e.height,
110
+ }), a = Math.max(i.viewportScale, 1e-3);
111
+ x({
112
+ pointerId: e.pointerId,
113
+ startClientX: e.clientX,
114
+ startClientY: e.clientY,
115
+ startWidth: i.width,
116
+ startHeight: i.height,
117
+ width: i.width,
118
+ height: i.height,
109
119
  scale: a,
110
- stopInteraction: o
120
+ stopInteraction: n
111
121
  });
112
- const r = (t) => {
113
- C((n) => {
114
- if (!n || n.pointerId !== t.pointerId) return n;
115
- const c = Math.max(J, n.startWidth + (t.clientX - n.startClientX) / n.scale), g = Math.max(K, n.startHeight + (t.clientY - n.startClientY) / n.scale);
122
+ const r = (o) => {
123
+ x((t) => {
124
+ if (!t || t.pointerId !== o.pointerId) return t;
125
+ const d = Math.max(nt, t.startWidth + (o.clientX - t.startClientX) / t.scale), g = Math.max(ot, t.startHeight + (o.clientY - t.startClientY) / t.scale);
116
126
  return {
117
- ...n,
118
- width: c,
127
+ ...t,
128
+ width: d,
119
129
  height: g
120
130
  };
121
131
  });
122
- }, l = (t) => {
123
- t.pointerId === i.pointerId && S(!0);
124
- }, s = (t) => {
125
- t.pointerId === i.pointerId && S(!1);
126
- }, d = new AbortController();
127
- w = d, window.addEventListener("pointermove", r, {
128
- signal: d.signal
129
- }), window.addEventListener("pointerup", l, {
132
+ }, s = (o) => {
133
+ o.pointerId === e.pointerId && k(!0);
134
+ }, c = (o) => {
135
+ o.pointerId === e.pointerId && k(!1);
136
+ }, l = new AbortController();
137
+ w = l, window.addEventListener("pointermove", r, {
138
+ signal: l.signal
139
+ }), window.addEventListener("pointerup", s, {
130
140
  once: !0,
131
- signal: d.signal
132
- }), window.addEventListener("pointercancel", s, {
141
+ signal: l.signal
142
+ }), window.addEventListener("pointercancel", c, {
133
143
  once: !0,
134
- signal: d.signal
144
+ signal: l.signal
135
145
  });
136
146
  };
137
147
  return (() => {
138
- var i = Z(), o = i.firstChild, a = o.firstChild, r = a.nextSibling, l = r.firstChild, s = r.nextSibling, d = o.nextSibling;
139
- return i.$$click = () => {
140
- e.onSelect(e.widgetId), e.onCommitFront(e.widgetId);
141
- }, i.$$contextmenu = (t) => {
142
- t.preventDefault(), t.stopPropagation(), e.onContextMenu(t, e.itemSnapshot());
143
- }, a.$$pointerdown = F, u(a, v(q, {
148
+ var e = et(), n = e.firstChild, a = n.firstChild, r = a.nextSibling, s = r.firstChild, c = r.nextSibling, l = n.nextSibling;
149
+ e.$$contextmenu = (t) => {
150
+ E(t.target) === "widget_shell" && (t.preventDefault(), t.stopPropagation(), i.onContextMenu(t, i.itemSnapshot()));
151
+ }, e.addEventListener("focus", () => {
152
+ i.onSelect(i.widgetId);
153
+ }), e.$$pointerdown = N;
154
+ var o = b;
155
+ return typeof o == "function" ? U(o, e) : b = e, G(n, {
156
+ [p]: "true"
157
+ }, !1, !0), a.$$pointerdown = F, u(a, I(Q, {
144
158
  class: "w-3.5 h-3.5"
145
159
  })), u(r, () => {
146
- const t = e.definition.icon;
147
- return v(t, {
160
+ const t = i.definition.icon;
161
+ return I(t, {
148
162
  class: "w-3.5 h-3.5"
149
163
  });
150
- }, l), u(l, () => e.widgetTitle), s.$$click = (t) => {
151
- t.stopPropagation(), t.preventDefault(), e.onRequestDelete(e.widgetId);
152
- }, s.$$pointerdown = (t) => t.stopPropagation(), u(s, v(V, {
164
+ }, s), u(s, () => i.widgetTitle), c.$$click = (t) => {
165
+ t.stopPropagation(), t.preventDefault(), i.onRequestDelete(i.widgetId);
166
+ }, c.$$pointerdown = (t) => t.stopPropagation(), u(c, I(Z, {
153
167
  class: "w-3 h-3"
154
- })), u(d, () => {
155
- const t = e.definition.body;
156
- return v(t, {
168
+ })), u(l, () => {
169
+ const t = i.definition.body;
170
+ return I(t, {
157
171
  get widgetId() {
158
- return e.widgetId;
172
+ return i.widgetId;
159
173
  },
160
174
  get title() {
161
- return e.widgetTitle;
175
+ return i.widgetTitle;
162
176
  },
163
177
  get type() {
164
- return e.widgetType;
178
+ return i.widgetType;
165
179
  }
166
180
  });
167
- }), u(i, (() => {
168
- var t = E(() => !!e.locked);
181
+ }), u(e, (() => {
182
+ var t = K(() => !!i.locked);
169
183
  return () => t() ? null : (() => {
170
- var n = j();
171
- return n.$$pointerdown = T, n;
184
+ var d = it();
185
+ return d.$$pointerdown = B, d;
172
186
  })();
173
- })(), null), B((t) => {
174
- var n = !!e.selected, c = !!M(), g = !!k(), X = !!e.filtered, z = e.widgetId, Y = `translate(${y().x}px, ${y().y}px)`, W = `${_().width}px`, L = `${_().height}px`, D = M() || k() || e.optimisticFront ? `${e.topZIndex + 1}` : `${e.zIndex}`;
175
- return n !== t.e && i.classList.toggle("is-selected", t.e = n), c !== t.t && i.classList.toggle("is-dragging", t.t = c), g !== t.a && i.classList.toggle("is-resizing", t.a = g), X !== t.o && i.classList.toggle("is-filtered-out", t.o = X), z !== t.i && G(i, "data-floe-workbench-widget-id", t.i = z), Y !== t.n && m(i, "transform", t.n = Y), W !== t.s && m(i, "width", t.s = W), L !== t.h && m(i, "height", t.h = L), D !== t.r && m(i, "z-index", t.r = D), t;
187
+ })(), null), V((t) => {
188
+ var d = !!i.selected, g = !!S(), L = !!y(), R = !!i.filtered, X = i.widgetId, Y = `translate(${W().x}px, ${W().y}px)`, z = `${M().width}px`, D = `${M().height}px`, T = S() || y() || i.optimisticFront ? `${i.topRenderLayer + 1}` : `${i.renderLayer}`;
189
+ return d !== t.e && e.classList.toggle("is-selected", t.e = d), g !== t.t && e.classList.toggle("is-dragging", t.t = g), L !== t.a && e.classList.toggle("is-resizing", t.a = L), R !== t.o && e.classList.toggle("is-filtered-out", t.o = R), X !== t.i && q(e, "data-floe-workbench-widget-id", t.i = X), Y !== t.n && m(e, "transform", t.n = Y), z !== t.s && m(e, "width", t.s = z), D !== t.h && m(e, "height", t.h = D), T !== t.r && m(e, "z-index", t.r = T), t;
176
190
  }, {
177
191
  e: void 0,
178
192
  t: void 0,
@@ -183,10 +197,10 @@ function et(e) {
183
197
  s: void 0,
184
198
  h: void 0,
185
199
  r: void 0
186
- }), i;
200
+ }), e;
187
201
  })();
188
202
  }
189
- N(["contextmenu", "click", "pointerdown"]);
203
+ j(["pointerdown", "contextmenu", "click"]);
190
204
  export {
191
- et as WorkbenchWidget
205
+ ht as WorkbenchWidget
192
206
  };
@@ -4,4 +4,4 @@ export { WorkbenchContextMenu, type WorkbenchContextMenuItem, type WorkbenchCont
4
4
  export { useWorkbenchModel, type UseWorkbenchModelOptions } from './useWorkbenchModel';
5
5
  export { WIDGET_REGISTRY, createWorkbenchFilterState, getWidgetEntry, isValidWorkbenchWidgetType, resolveWorkbenchWidgetDefinitions, type WidgetRegistryEntry, } from './widgets/widgetRegistry';
6
6
  export * from './types';
7
- export { sanitizeWorkbenchState, createDefaultWorkbenchState, createWorkbenchId, } from './workbenchHelpers';
7
+ export { sanitizeWorkbenchState, createDefaultWorkbenchState, createWorkbenchId, createWorkbenchRenderLayerMap, type WorkbenchRenderLayerMap, } from './workbenchHelpers';
@@ -10,6 +10,11 @@ export declare function sanitizeWorkbenchState(input: unknown, options?: Sanitiz
10
10
  export declare function createDefaultWorkbenchState(widgetDefinitions?: readonly WorkbenchWidgetDefinition[]): WorkbenchState;
11
11
  export declare const WORKBENCH_CANVAS_ZOOM_STEP = 1.18;
12
12
  export declare const WORKBENCH_CONTEXT_MENU_WIDTH_PX = 200;
13
+ export interface WorkbenchRenderLayerMap {
14
+ byWidgetId: ReadonlyMap<string, number>;
15
+ topRenderLayer: number;
16
+ }
17
+ export declare function createWorkbenchRenderLayerMap(widgets: readonly WorkbenchWidgetItem[]): WorkbenchRenderLayerMap;
13
18
  export declare function createContextMenuPosition(options: {
14
19
  clientX: number;
15
20
  clientY: number;
@@ -1,5 +1,5 @@
1
- import { DEFAULT_WORKBENCH_VIEWPORT as g } from "./types.js";
2
- import { resolveWorkbenchWidgetDefinitions as m, getWidgetEntry as x, createWorkbenchFilterState as b, isValidWorkbenchWidgetType as W } from "./widgets/widgetRegistry.js";
1
+ import { DEFAULT_WORKBENCH_VIEWPORT as m } from "./types.js";
2
+ import { resolveWorkbenchWidgetDefinitions as x, getWidgetEntry as g, createWorkbenchFilterState as _, isValidWorkbenchWidgetType as W } from "./widgets/widgetRegistry.js";
3
3
  function F() {
4
4
  const e = globalThis.crypto;
5
5
  return e && typeof e.randomUUID == "function" ? `wb-${e.randomUUID()}` : `wb-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
@@ -9,19 +9,19 @@ function M(e) {
9
9
  x: Number.isFinite(e.x) ? e.x : 0,
10
10
  y: Number.isFinite(e.y) ? e.y : 0,
11
11
  scale: Number.isFinite(e.scale) && e.scale > 0 ? e.scale : 1
12
- } : { ...g };
12
+ } : { ...m };
13
13
  }
14
- function k(e, n) {
15
- return b(n, e);
14
+ function k(e, i) {
15
+ return _(i, e);
16
16
  }
17
- function z(e, n = {}) {
18
- const r = m(n.widgetDefinitions), a = n.createFallbackState ?? (() => N(r)), i = e;
19
- if (!i || i.version !== 1 || !Array.isArray(i.widgets))
20
- return a();
21
- const s = i.widgets.filter(
17
+ function D(e, i = {}) {
18
+ const r = x(i.widgetDefinitions), s = i.createFallbackState ?? (() => z(r)), n = e;
19
+ if (!n || n.version !== 1 || !Array.isArray(n.widgets))
20
+ return s();
21
+ const a = n.widgets.filter(
22
22
  (t) => !!t && typeof t.id == "string" && W(t.type, r) && typeof t.title == "string"
23
23
  ).map((t) => {
24
- const u = x(t.type, r);
24
+ const u = g(t.type, r);
25
25
  return {
26
26
  id: t.id,
27
27
  type: t.type,
@@ -33,107 +33,120 @@ function z(e, n = {}) {
33
33
  z_index: Number.isFinite(t.z_index) && t.z_index >= 0 ? t.z_index : 1,
34
34
  created_at_unix_ms: Number.isFinite(t.created_at_unix_ms) ? t.created_at_unix_ms : Date.now()
35
35
  };
36
- }), c = typeof i.selectedWidgetId == "string" && s.some((t) => t.id === i.selectedWidgetId) ? i.selectedWidgetId : null;
36
+ }), d = typeof n.selectedWidgetId == "string" && a.some((t) => t.id === n.selectedWidgetId) ? n.selectedWidgetId : null;
37
37
  return {
38
38
  version: 1,
39
- widgets: s,
40
- viewport: M(i.viewport),
41
- locked: typeof i.locked == "boolean" ? i.locked : !1,
42
- filters: k(i.filters, r),
43
- selectedWidgetId: c
39
+ widgets: a,
40
+ viewport: M(n.viewport),
41
+ locked: typeof n.locked == "boolean" ? n.locked : !1,
42
+ filters: k(n.filters, r),
43
+ selectedWidgetId: d
44
44
  };
45
45
  }
46
- function N(e) {
47
- const n = m(e), r = Date.now(), a = [
46
+ function z(e) {
47
+ const i = x(e), r = Date.now(), s = [
48
48
  { type: "terminal", title: "dev · terminal", x: 80, y: 80 },
49
49
  { type: "file-browser", title: "project · files", x: 600, y: 80 },
50
50
  { type: "system-monitor", title: "host · system monitor", x: 80, y: 420 },
51
51
  { type: "log-viewer", title: "services · logs", x: 540, y: 500 },
52
52
  { type: "code-editor", title: "Counter.tsx", x: 1e3, y: 180 }
53
- ], i = a.filter((s) => n.some((c) => c.type === s.type)).map((s, c) => {
54
- const t = x(s.type, n);
53
+ ], n = s.filter((a) => i.some((d) => d.type === a.type)).map((a, d) => {
54
+ const t = g(a.type, i);
55
55
  return {
56
- id: `wb-seed-${c + 1}`,
57
- type: s.type,
58
- title: s.title,
59
- x: s.x,
60
- y: s.y,
56
+ id: `wb-seed-${d + 1}`,
57
+ type: a.type,
58
+ title: a.title,
59
+ x: a.x,
60
+ y: a.y,
61
61
  width: t.defaultSize.width,
62
62
  height: t.defaultSize.height,
63
- z_index: c + 1,
64
- created_at_unix_ms: r - (a.length - c) * 6e5
63
+ z_index: d + 1,
64
+ created_at_unix_ms: r - (s.length - d) * 6e5
65
65
  };
66
66
  });
67
67
  return {
68
68
  version: 1,
69
- widgets: i,
70
- viewport: { ...g },
69
+ widgets: n,
70
+ viewport: { ...m },
71
71
  locked: !1,
72
- filters: b(n),
73
- selectedWidgetId: i[0]?.id ?? null
72
+ filters: _(i),
73
+ selectedWidgetId: n[0]?.id ?? null
74
74
  };
75
75
  }
76
- const D = 1.18, I = 200;
76
+ const I = 1.18, C = 200;
77
+ function w(e, i) {
78
+ return e.z_index !== i.z_index ? e.z_index - i.z_index : e.created_at_unix_ms !== i.created_at_unix_ms ? e.created_at_unix_ms - i.created_at_unix_ms : e.id.localeCompare(i.id);
79
+ }
77
80
  function E(e) {
78
- const n = typeof window < "u" ? window.innerWidth : 1280, r = typeof window < "u" ? window.innerHeight : 800;
79
- let a = e.clientX, i = e.clientY;
80
- return a + e.menuWidth > n && (a = Math.max(0, n - e.menuWidth - 8)), i + e.menuHeight > r && (i = Math.max(0, r - e.menuHeight - 8)), { left: a, top: i };
81
+ const i = [...e].sort(w), r = /* @__PURE__ */ new Map();
82
+ for (const [s, n] of i.entries())
83
+ r.set(n.id, s + 1);
84
+ return {
85
+ byWidgetId: r,
86
+ topRenderLayer: Math.max(i.length, 1)
87
+ };
81
88
  }
82
89
  function H(e) {
83
- return e.reduce((n, r) => Math.max(n, r.z_index), 1);
90
+ const i = typeof window < "u" ? window.innerWidth : 1280, r = typeof window < "u" ? window.innerHeight : 800;
91
+ let s = e.clientX, n = e.clientY;
92
+ return s + e.menuWidth > i && (s = Math.max(0, i - e.menuWidth - 8)), n + e.menuHeight > r && (n = Math.max(0, r - e.menuHeight - 8)), { left: s, top: n };
93
+ }
94
+ function T(e) {
95
+ return e.reduce((i, r) => Math.max(i, r.z_index), 1);
84
96
  }
85
- function T(e, n, r, a) {
86
- const i = e.filter((o) => a[o.type]);
87
- if (i.length === 0) return null;
88
- if (!n) return i[0] ?? null;
89
- const s = i.find((o) => o.id === n);
90
- if (!s) return i[0] ?? null;
91
- const c = s.x + s.width / 2, t = s.y + s.height / 2;
92
- let u = null, f = 1 / 0;
93
- for (const o of i) {
94
- if (o.id === n) continue;
95
- const d = o.x + o.width / 2 - c, l = o.y + o.height / 2 - t;
96
- let h = !1;
97
+ function O(e, i, r, s) {
98
+ const n = e.filter((o) => s[o.type]);
99
+ if (n.length === 0) return null;
100
+ if (!i) return n[0] ?? null;
101
+ const a = n.find((o) => o.id === i);
102
+ if (!a) return n[0] ?? null;
103
+ const d = a.x + a.width / 2, t = a.y + a.height / 2;
104
+ let u = null, h = 1 / 0;
105
+ for (const o of n) {
106
+ if (o.id === i) continue;
107
+ const c = o.x + o.width / 2 - d, l = o.y + o.height / 2 - t;
108
+ let f = !1;
97
109
  switch (r) {
98
110
  case "up":
99
- h = l < -10;
111
+ f = l < -10;
100
112
  break;
101
113
  case "down":
102
- h = l > 10;
114
+ f = l > 10;
103
115
  break;
104
116
  case "left":
105
- h = d < -10;
117
+ f = c < -10;
106
118
  break;
107
119
  case "right":
108
- h = d > 10;
120
+ f = c > 10;
109
121
  break;
110
122
  }
111
- if (!h) continue;
112
- const p = Math.sqrt(d * d + l * l), _ = Math.atan2(
113
- Math.abs(r === "up" || r === "down" ? d : l),
114
- Math.abs(r === "up" || r === "down" ? l : d)
115
- ), y = p * (1 + _ * 1.5);
116
- y < f && (f = y, u = o);
123
+ if (!f) continue;
124
+ const b = Math.sqrt(c * c + l * l), p = Math.atan2(
125
+ Math.abs(r === "up" || r === "down" ? c : l),
126
+ Math.abs(r === "up" || r === "down" ? l : c)
127
+ ), y = b * (1 + p * 1.5);
128
+ y < h && (h = y, u = o);
117
129
  }
118
130
  return u;
119
131
  }
120
- function C(e, n = 0.45, r = 2.2) {
121
- return Math.max(n, Math.min(r, e));
132
+ function R(e, i = 0.45, r = 2.2) {
133
+ return Math.max(i, Math.min(r, e));
122
134
  }
123
- function O(e, n = 0) {
124
- return 16 + Math.max(1, e) * 32 + Math.max(0, n) * 9;
135
+ function v(e, i = 0) {
136
+ return 16 + Math.max(1, e) * 32 + Math.max(0, i) * 9;
125
137
  }
126
138
  export {
127
- D as WORKBENCH_CANVAS_ZOOM_STEP,
128
- I as WORKBENCH_CONTEXT_MENU_WIDTH_PX,
129
- C as clampScale,
130
- E as createContextMenuPosition,
131
- N as createDefaultWorkbenchState,
139
+ I as WORKBENCH_CANVAS_ZOOM_STEP,
140
+ C as WORKBENCH_CONTEXT_MENU_WIDTH_PX,
141
+ R as clampScale,
142
+ H as createContextMenuPosition,
143
+ z as createDefaultWorkbenchState,
132
144
  F as createWorkbenchId,
133
- O as estimateContextMenuHeight,
134
- T as findNearestWidget,
135
- H as getTopZIndex,
145
+ E as createWorkbenchRenderLayerMap,
146
+ v as estimateContextMenuHeight,
147
+ O as findNearestWidget,
148
+ T as getTopZIndex,
136
149
  k as sanitizeFilters,
137
150
  M as sanitizeViewport,
138
- z as sanitizeWorkbenchState
151
+ D as sanitizeWorkbenchState
139
152
  };