@floegence/floe-webapp-core 0.36.2 → 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,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
  };