@almadar/ui 2.15.7 → 2.15.10
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.
- package/dist/components/atoms/ContentSection.d.ts +16 -0
- package/dist/components/atoms/SectionHeader.d.ts +14 -0
- package/dist/components/atoms/StatCard.d.ts +13 -0
- package/dist/components/atoms/index.d.ts +3 -0
- package/dist/components/atoms/svg/SvgBranch.d.ts +12 -0
- package/dist/components/atoms/svg/SvgConnection.d.ts +13 -0
- package/dist/components/atoms/svg/SvgFlow.d.ts +10 -0
- package/dist/components/atoms/svg/SvgGrid.d.ts +14 -0
- package/dist/components/atoms/svg/SvgLobe.d.ts +13 -0
- package/dist/components/atoms/svg/SvgMesh.d.ts +12 -0
- package/dist/components/atoms/svg/SvgMorph.d.ts +11 -0
- package/dist/components/atoms/svg/SvgNode.d.ts +12 -0
- package/dist/components/atoms/svg/SvgPulse.d.ts +12 -0
- package/dist/components/atoms/svg/SvgRing.d.ts +13 -0
- package/dist/components/atoms/svg/SvgShield.d.ts +11 -0
- package/dist/components/atoms/svg/SvgStack.d.ts +13 -0
- package/dist/components/atoms/svg/index.d.ts +12 -0
- package/dist/{chunk-K43H3ZDY.js → components/index.cjs} +24780 -16651
- package/dist/components/index.js +37757 -889
- package/dist/components/molecules/AnimatedCounter.d.ts +18 -0
- package/dist/components/molecules/ArticleSection.d.ts +18 -0
- package/dist/components/molecules/CTABanner.d.ts +31 -0
- package/dist/components/molecules/CaseStudyCard.d.ts +24 -0
- package/dist/components/molecules/CodeExample.d.ts +23 -0
- package/dist/components/molecules/CommunityLinks.d.ts +25 -0
- package/dist/components/molecules/DocBreadcrumb.d.ts +20 -0
- package/dist/components/molecules/DocCodeBlock.d.ts +13 -0
- package/dist/components/molecules/DocPagination.d.ts +14 -0
- package/dist/components/molecules/DocSearch.d.ts +15 -0
- package/dist/components/molecules/DocSidebar.d.ts +24 -0
- package/dist/components/molecules/DocTOC.d.ts +24 -0
- package/dist/components/molecules/FeatureCard.d.ts +26 -0
- package/dist/components/molecules/FeatureGrid.d.ts +19 -0
- package/dist/components/molecules/GradientDivider.d.ts +14 -0
- package/dist/components/molecules/HeroSection.d.ts +36 -0
- package/dist/components/molecules/InstallBox.d.ts +16 -0
- package/dist/components/molecules/MarketingFooter.d.ts +27 -0
- package/dist/components/molecules/PricingCard.d.ts +21 -0
- package/dist/components/molecules/PricingGrid.d.ts +13 -0
- package/dist/components/molecules/PullQuote.d.ts +14 -0
- package/dist/components/molecules/ServiceCatalog.d.ts +19 -0
- package/dist/components/molecules/ShowcaseCard.d.ts +20 -0
- package/dist/components/molecules/SocialProof.d.ts +25 -0
- package/dist/components/molecules/SplitSection.d.ts +21 -0
- package/dist/components/molecules/StatsGrid.d.ts +17 -0
- package/dist/components/molecules/StepFlow.d.ts +20 -0
- package/dist/components/molecules/TagCloud.d.ts +18 -0
- package/dist/components/molecules/TeamCard.d.ts +18 -0
- package/dist/components/molecules/index.d.ts +19 -0
- package/dist/components/molecules/svg/AIGenerates.d.ts +7 -0
- package/dist/components/molecules/svg/ClosedCircuit.d.ts +7 -0
- package/dist/components/molecules/svg/CommunityOwnership.d.ts +7 -0
- package/dist/components/molecules/svg/CompileAnywhere.d.ts +7 -0
- package/dist/components/molecules/svg/ComposableModels.d.ts +7 -0
- package/dist/components/molecules/svg/DescribeProveDeploy.d.ts +7 -0
- package/dist/components/molecules/svg/DomainGrid.d.ts +7 -0
- package/dist/components/molecules/svg/EventBus.d.ts +7 -0
- package/dist/components/molecules/svg/OrbitalUnit.d.ts +7 -0
- package/dist/components/molecules/svg/PlanVerifyRemember.d.ts +7 -0
- package/dist/components/molecules/svg/ProveCorrect.d.ts +7 -0
- package/dist/components/molecules/svg/ServiceLayers.d.ts +7 -0
- package/dist/components/molecules/svg/SharedReality.d.ts +7 -0
- package/dist/components/molecules/svg/StandardLibrary.d.ts +7 -0
- package/dist/components/molecules/svg/StateMachine.d.ts +7 -0
- package/dist/components/molecules/svg/WorldModel.d.ts +7 -0
- package/dist/components/molecules/svg/index.d.ts +16 -0
- package/dist/components/organisms/CaseStudyOrganism.d.ts +19 -0
- package/dist/components/organisms/FeatureGridOrganism.d.ts +20 -0
- package/dist/components/organisms/HeroOrganism.d.ts +18 -0
- package/dist/components/organisms/PricingOrganism.d.ts +19 -0
- package/dist/components/organisms/ShowcaseOrganism.d.ts +20 -0
- package/dist/components/organisms/StatsOrganism.d.ts +17 -0
- package/dist/components/organisms/StepFlowOrganism.d.ts +20 -0
- package/dist/components/organisms/TeamOrganism.d.ts +18 -0
- package/dist/components/organisms/UISlotRenderer.d.ts +1 -0
- package/dist/components/organisms/game/three/index.cjs +2525 -0
- package/dist/components/organisms/game/three/index.js +1795 -50
- package/dist/components/organisms/index.d.ts +9 -0
- package/dist/components/organisms/marketing-types.d.ts +87 -0
- package/dist/components/templates/AboutPageTemplate.d.ts +26 -0
- package/dist/components/templates/DashboardLayout.d.ts +2 -1
- package/dist/components/templates/FeatureDetailPageTemplate.d.ts +27 -0
- package/dist/components/templates/LandingPageTemplate.d.ts +31 -0
- package/dist/components/templates/PricingPageTemplate.d.ts +26 -0
- package/dist/components/templates/index.d.ts +4 -0
- package/dist/context/index.cjs +550 -0
- package/dist/context/index.js +420 -6
- package/dist/docs/index.cjs +4015 -0
- package/dist/docs/index.d.cts +412 -0
- package/dist/docs/index.d.ts +29 -0
- package/dist/docs/index.js +3977 -0
- package/dist/hooks/index.cjs +2606 -0
- package/dist/hooks/index.js +2535 -8
- package/dist/illustrations/index.cjs +3004 -0
- package/dist/illustrations/index.d.cts +261 -0
- package/dist/illustrations/index.d.ts +35 -0
- package/dist/illustrations/index.js +2971 -0
- package/dist/{chunk-XL7WB2O5.js → lib/index.cjs} +454 -274
- package/dist/lib/index.js +1407 -3
- package/dist/locales/index.cjs +340 -0
- package/dist/locales/index.js +105 -2
- package/dist/marketing/index.cjs +4683 -0
- package/dist/marketing/index.d.cts +831 -0
- package/dist/marketing/index.d.ts +62 -0
- package/dist/marketing/index.js +4626 -0
- package/dist/providers/index.cjs +4811 -0
- package/dist/providers/index.js +4765 -11
- package/dist/{chunk-K2D5D3WK.js → renderer/index.cjs} +101 -42
- package/dist/renderer/index.js +1036 -2
- package/dist/runtime/index.cjs +4400 -0
- package/dist/runtime/index.js +3615 -19
- package/dist/{chunk-N7MVUW4R.js → stores/index.cjs} +24 -1
- package/dist/stores/index.js +194 -2
- package/dist/tsup.config.d.ts +2 -1
- package/package.json +27 -12
- package/tailwind-preset.cjs +27 -2
- package/themes/index.css +22 -20
- package/dist/chunk-3HJHHULT.js +0 -93
- package/dist/chunk-3JGAROCW.js +0 -149
- package/dist/chunk-4N3BAPDB.js +0 -1667
- package/dist/chunk-CDIOHSKG.js +0 -661
- package/dist/chunk-DKQN5FVU.js +0 -279
- package/dist/chunk-GF6RQBO7.js +0 -375
- package/dist/chunk-PKBMQBKP.js +0 -5
- package/dist/chunk-QIABKRCN.js +0 -107
- package/dist/chunk-SD3KVCY6.js +0 -1465
- package/dist/chunk-YXZM3WCF.js +0 -222
|
@@ -0,0 +1,2606 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React3 = require('react');
|
|
4
|
+
require('react/jsx-runtime');
|
|
5
|
+
var reactQuery = require('@tanstack/react-query');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var React3__default = /*#__PURE__*/_interopDefault(React3);
|
|
10
|
+
|
|
11
|
+
function useOrbitalHistory(options) {
|
|
12
|
+
const { appId, authToken, userId, onHistoryChange, onRevertSuccess } = options;
|
|
13
|
+
const getHeaders2 = React3.useCallback(() => {
|
|
14
|
+
const headers = {
|
|
15
|
+
"Content-Type": "application/json"
|
|
16
|
+
};
|
|
17
|
+
if (authToken) {
|
|
18
|
+
headers["Authorization"] = `Bearer ${authToken}`;
|
|
19
|
+
}
|
|
20
|
+
if (userId) {
|
|
21
|
+
headers["x-user-id"] = userId;
|
|
22
|
+
}
|
|
23
|
+
return headers;
|
|
24
|
+
}, [authToken, userId]);
|
|
25
|
+
const [timeline, setTimeline] = React3.useState([]);
|
|
26
|
+
const [currentVersion, setCurrentVersion] = React3.useState(1);
|
|
27
|
+
const [isLoading, setIsLoading] = React3.useState(false);
|
|
28
|
+
const [error, setError] = React3.useState(null);
|
|
29
|
+
const refresh = React3.useCallback(async () => {
|
|
30
|
+
if (!appId) return;
|
|
31
|
+
setIsLoading(true);
|
|
32
|
+
setError(null);
|
|
33
|
+
try {
|
|
34
|
+
const headers = getHeaders2();
|
|
35
|
+
const [changesetsRes, snapshotsRes] = await Promise.all([
|
|
36
|
+
fetch(`/api/graphs/${appId}/history/changesets`, { headers }),
|
|
37
|
+
fetch(`/api/graphs/${appId}/history/snapshots`, { headers })
|
|
38
|
+
]);
|
|
39
|
+
if (!changesetsRes.ok) {
|
|
40
|
+
throw new Error(`Failed to fetch changesets: ${changesetsRes.status}`);
|
|
41
|
+
}
|
|
42
|
+
if (!snapshotsRes.ok) {
|
|
43
|
+
throw new Error(`Failed to fetch snapshots: ${snapshotsRes.status}`);
|
|
44
|
+
}
|
|
45
|
+
const changesetsData = await changesetsRes.json();
|
|
46
|
+
const snapshotsData = await snapshotsRes.json();
|
|
47
|
+
const changesetItems = (changesetsData.changesets || []).map((cs) => ({
|
|
48
|
+
id: cs.id,
|
|
49
|
+
type: "changeset",
|
|
50
|
+
version: cs.version,
|
|
51
|
+
timestamp: cs.timestamp,
|
|
52
|
+
description: `Version ${cs.version}`,
|
|
53
|
+
source: cs.source,
|
|
54
|
+
summary: cs.summary
|
|
55
|
+
}));
|
|
56
|
+
const snapshotItems = (snapshotsData.snapshots || []).map((snap) => ({
|
|
57
|
+
id: snap.id,
|
|
58
|
+
type: "snapshot",
|
|
59
|
+
version: snap.version,
|
|
60
|
+
timestamp: snap.timestamp,
|
|
61
|
+
description: snap.reason || `Snapshot v${snap.version}`,
|
|
62
|
+
reason: snap.reason
|
|
63
|
+
}));
|
|
64
|
+
const mergedTimeline = [...changesetItems, ...snapshotItems].sort(
|
|
65
|
+
(a, b) => b.timestamp - a.timestamp
|
|
66
|
+
);
|
|
67
|
+
setTimeline(mergedTimeline);
|
|
68
|
+
if (mergedTimeline.length > 0) {
|
|
69
|
+
setCurrentVersion(mergedTimeline[0].version);
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error("[useOrbitalHistory] Failed to load history:", err);
|
|
73
|
+
setError(err instanceof Error ? err.message : "Failed to load history");
|
|
74
|
+
} finally {
|
|
75
|
+
setIsLoading(false);
|
|
76
|
+
}
|
|
77
|
+
}, [appId, getHeaders2]);
|
|
78
|
+
const revertToSnapshot = React3.useCallback(async (snapshotId) => {
|
|
79
|
+
if (!appId) {
|
|
80
|
+
return { success: false, error: "No app ID provided" };
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(`/api/graphs/${appId}/history/revert/${snapshotId}`, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: getHeaders2()
|
|
86
|
+
});
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
const errorData = await response.json().catch(() => ({}));
|
|
89
|
+
throw new Error(errorData.error || `Failed to revert: ${response.status}`);
|
|
90
|
+
}
|
|
91
|
+
const data = await response.json();
|
|
92
|
+
if (data.success && data.schema) {
|
|
93
|
+
await refresh();
|
|
94
|
+
onRevertSuccess?.(data.schema);
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
restoredSchema: data.schema
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
error: data.error || "Unknown error during revert"
|
|
103
|
+
};
|
|
104
|
+
} catch (err) {
|
|
105
|
+
console.error("[useOrbitalHistory] Failed to revert:", err);
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: err instanceof Error ? err.message : "Failed to revert"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}, [appId, getHeaders2, refresh, onRevertSuccess]);
|
|
112
|
+
React3.useEffect(() => {
|
|
113
|
+
if (appId && authToken && userId) {
|
|
114
|
+
refresh();
|
|
115
|
+
}
|
|
116
|
+
}, [appId, authToken, userId]);
|
|
117
|
+
React3.useEffect(() => {
|
|
118
|
+
onHistoryChange?.(timeline);
|
|
119
|
+
}, [timeline]);
|
|
120
|
+
return {
|
|
121
|
+
timeline,
|
|
122
|
+
currentVersion,
|
|
123
|
+
isLoading,
|
|
124
|
+
error,
|
|
125
|
+
revertToSnapshot,
|
|
126
|
+
refresh
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function useFileSystem() {
|
|
130
|
+
const [status, setStatus] = React3.useState("idle");
|
|
131
|
+
const [error, setError] = React3.useState(null);
|
|
132
|
+
const [isLoading, setIsLoading] = React3.useState(false);
|
|
133
|
+
const [files, setFiles] = React3.useState([]);
|
|
134
|
+
const [selectedFile, setSelectedFile] = React3.useState(null);
|
|
135
|
+
const [selectedPath, setSelectedPath] = React3.useState(null);
|
|
136
|
+
const [previewUrl, setPreviewUrl] = React3.useState(null);
|
|
137
|
+
const [fileContents, setFileContents] = React3.useState(/* @__PURE__ */ new Map());
|
|
138
|
+
const boot = React3.useCallback(async () => {
|
|
139
|
+
setStatus("booting");
|
|
140
|
+
setError(null);
|
|
141
|
+
setIsLoading(true);
|
|
142
|
+
try {
|
|
143
|
+
console.log("[useFileSystem] Booting WebContainer...");
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
145
|
+
setStatus("ready");
|
|
146
|
+
} catch (err) {
|
|
147
|
+
setError(err instanceof Error ? err.message : "Failed to boot");
|
|
148
|
+
setStatus("error");
|
|
149
|
+
} finally {
|
|
150
|
+
setIsLoading(false);
|
|
151
|
+
}
|
|
152
|
+
}, []);
|
|
153
|
+
const mountFiles = React3.useCallback(async (filesToMount) => {
|
|
154
|
+
setIsLoading(true);
|
|
155
|
+
try {
|
|
156
|
+
let filesArray;
|
|
157
|
+
if (Array.isArray(filesToMount)) {
|
|
158
|
+
filesArray = filesToMount;
|
|
159
|
+
} else {
|
|
160
|
+
filesArray = [];
|
|
161
|
+
const flattenTree = (obj, basePath = "") => {
|
|
162
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
163
|
+
const path = basePath ? `${basePath}/${key}` : key;
|
|
164
|
+
if (value && typeof value === "object" && "file" in value) {
|
|
165
|
+
const fileObj = value;
|
|
166
|
+
filesArray.push({ path, content: fileObj.file.contents || "" });
|
|
167
|
+
} else if (value && typeof value === "object" && "directory" in value) {
|
|
168
|
+
const dirObj = value;
|
|
169
|
+
flattenTree(dirObj.directory, path);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
flattenTree(filesToMount);
|
|
174
|
+
}
|
|
175
|
+
const newContents = /* @__PURE__ */ new Map();
|
|
176
|
+
for (const file of filesArray) {
|
|
177
|
+
newContents.set(file.path, file.content);
|
|
178
|
+
}
|
|
179
|
+
setFileContents(newContents);
|
|
180
|
+
const newTree = [];
|
|
181
|
+
for (const file of filesArray) {
|
|
182
|
+
const parts = file.path.split("/").filter(Boolean);
|
|
183
|
+
let current = newTree;
|
|
184
|
+
for (let i = 0; i < parts.length; i++) {
|
|
185
|
+
const part = parts[i];
|
|
186
|
+
const isFile = i === parts.length - 1;
|
|
187
|
+
const currentPath = "/" + parts.slice(0, i + 1).join("/");
|
|
188
|
+
let node = current.find((n) => n.name === part);
|
|
189
|
+
if (!node) {
|
|
190
|
+
node = {
|
|
191
|
+
path: currentPath,
|
|
192
|
+
name: part,
|
|
193
|
+
type: isFile ? "file" : "directory",
|
|
194
|
+
children: isFile ? void 0 : []
|
|
195
|
+
};
|
|
196
|
+
current.push(node);
|
|
197
|
+
}
|
|
198
|
+
if (!isFile && node && node.children) {
|
|
199
|
+
current = node.children;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
setFiles(newTree);
|
|
204
|
+
setStatus("running");
|
|
205
|
+
} catch (err) {
|
|
206
|
+
console.error("[useFileSystem] Failed to mount files:", err);
|
|
207
|
+
} finally {
|
|
208
|
+
setIsLoading(false);
|
|
209
|
+
}
|
|
210
|
+
}, []);
|
|
211
|
+
const readFile = React3.useCallback(async (path) => {
|
|
212
|
+
return fileContents.get(path) || "";
|
|
213
|
+
}, [fileContents]);
|
|
214
|
+
const writeFile = React3.useCallback(async (path, content) => {
|
|
215
|
+
setFileContents((prev) => {
|
|
216
|
+
const next = new Map(prev);
|
|
217
|
+
next.set(path, content);
|
|
218
|
+
return next;
|
|
219
|
+
});
|
|
220
|
+
}, []);
|
|
221
|
+
const selectFile = React3.useCallback(async (path) => {
|
|
222
|
+
const content = fileContents.get(path) || "";
|
|
223
|
+
const ext = path.split(".").pop()?.toLowerCase() || "";
|
|
224
|
+
const languageMap = {
|
|
225
|
+
ts: "typescript",
|
|
226
|
+
tsx: "typescript",
|
|
227
|
+
js: "javascript",
|
|
228
|
+
jsx: "javascript",
|
|
229
|
+
json: "json",
|
|
230
|
+
md: "markdown",
|
|
231
|
+
css: "css",
|
|
232
|
+
html: "html",
|
|
233
|
+
orb: "json"
|
|
234
|
+
};
|
|
235
|
+
setSelectedPath(path);
|
|
236
|
+
setSelectedFile({
|
|
237
|
+
path,
|
|
238
|
+
content,
|
|
239
|
+
language: languageMap[ext] || "plaintext",
|
|
240
|
+
isDirty: false
|
|
241
|
+
});
|
|
242
|
+
}, [fileContents]);
|
|
243
|
+
const updateContent = React3.useCallback((pathOrContent, contentArg) => {
|
|
244
|
+
const path = contentArg !== void 0 ? pathOrContent : selectedPath;
|
|
245
|
+
const content = contentArg !== void 0 ? contentArg : pathOrContent;
|
|
246
|
+
if (!path) {
|
|
247
|
+
console.warn("[useFileSystem] updateContent called without path and no file selected");
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
setFileContents((prev) => {
|
|
251
|
+
const next = new Map(prev);
|
|
252
|
+
next.set(path, content);
|
|
253
|
+
return next;
|
|
254
|
+
});
|
|
255
|
+
if (selectedPath === path) {
|
|
256
|
+
setSelectedFile((prev) => prev ? { ...prev, content, isDirty: true } : null);
|
|
257
|
+
}
|
|
258
|
+
}, [selectedPath]);
|
|
259
|
+
const updateSelectedContent = React3.useCallback((content) => {
|
|
260
|
+
setSelectedFile((prev) => prev ? { ...prev, content, isDirty: true } : null);
|
|
261
|
+
}, []);
|
|
262
|
+
const refreshTree = React3.useCallback(async () => {
|
|
263
|
+
console.log("[useFileSystem] Refreshing tree");
|
|
264
|
+
}, []);
|
|
265
|
+
const runCommand = React3.useCallback(async (command) => {
|
|
266
|
+
console.log("[useFileSystem] Running command:", command);
|
|
267
|
+
return { exitCode: 0, output: "" };
|
|
268
|
+
}, []);
|
|
269
|
+
const startDevServer = React3.useCallback(async () => {
|
|
270
|
+
console.log("[useFileSystem] Starting dev server");
|
|
271
|
+
setPreviewUrl("http://localhost:5173");
|
|
272
|
+
}, []);
|
|
273
|
+
return {
|
|
274
|
+
status,
|
|
275
|
+
error,
|
|
276
|
+
isLoading,
|
|
277
|
+
files,
|
|
278
|
+
selectedFile,
|
|
279
|
+
selectedPath,
|
|
280
|
+
previewUrl,
|
|
281
|
+
boot,
|
|
282
|
+
mountFiles,
|
|
283
|
+
readFile,
|
|
284
|
+
writeFile,
|
|
285
|
+
selectFile,
|
|
286
|
+
updateContent,
|
|
287
|
+
updateSelectedContent,
|
|
288
|
+
refreshTree,
|
|
289
|
+
runCommand,
|
|
290
|
+
startDevServer
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
var defaultManifest = {
|
|
294
|
+
languages: {
|
|
295
|
+
typescript: { extensions: [".ts", ".tsx"], icon: "ts", color: "#3178c6" },
|
|
296
|
+
javascript: { extensions: [".js", ".jsx"], icon: "js", color: "#f7df1e" },
|
|
297
|
+
json: { extensions: [".json", ".orb"], icon: "json", color: "#000000" },
|
|
298
|
+
css: { extensions: [".css"], icon: "css", color: "#264de4" },
|
|
299
|
+
html: { extensions: [".html"], icon: "html", color: "#e34c26" },
|
|
300
|
+
markdown: { extensions: [".md", ".mdx"], icon: "md", color: "#083fa1" }
|
|
301
|
+
},
|
|
302
|
+
extensions: []
|
|
303
|
+
};
|
|
304
|
+
function useExtensions(options) {
|
|
305
|
+
const { appId, loadOnMount = true } = options;
|
|
306
|
+
const [extensions, setExtensions] = React3.useState([]);
|
|
307
|
+
const [manifest] = React3.useState(defaultManifest);
|
|
308
|
+
const [isLoading, setIsLoading] = React3.useState(false);
|
|
309
|
+
const [error, setError] = React3.useState(null);
|
|
310
|
+
const loadExtension = React3.useCallback(async (extensionId) => {
|
|
311
|
+
console.log("[useExtensions] Loading extension:", extensionId);
|
|
312
|
+
}, []);
|
|
313
|
+
const loadExtensions = React3.useCallback(async () => {
|
|
314
|
+
setIsLoading(true);
|
|
315
|
+
setError(null);
|
|
316
|
+
try {
|
|
317
|
+
const defaultExtensions = [
|
|
318
|
+
{ id: "typescript", name: "TypeScript", language: "typescript", loaded: true },
|
|
319
|
+
{ id: "javascript", name: "JavaScript", language: "javascript", loaded: true },
|
|
320
|
+
{ id: "json", name: "JSON", language: "json", loaded: true },
|
|
321
|
+
{ id: "css", name: "CSS", language: "css", loaded: true },
|
|
322
|
+
{ id: "html", name: "HTML", language: "html", loaded: true },
|
|
323
|
+
{ id: "markdown", name: "Markdown", language: "markdown", loaded: true }
|
|
324
|
+
];
|
|
325
|
+
setExtensions(defaultExtensions);
|
|
326
|
+
} catch (err) {
|
|
327
|
+
setError(err instanceof Error ? err.message : "Failed to load extensions");
|
|
328
|
+
} finally {
|
|
329
|
+
setIsLoading(false);
|
|
330
|
+
}
|
|
331
|
+
}, []);
|
|
332
|
+
const getExtensionForFile = React3.useCallback((filename) => {
|
|
333
|
+
const ext = filename.split(".").pop()?.toLowerCase();
|
|
334
|
+
if (!ext) return null;
|
|
335
|
+
const languageMap = {
|
|
336
|
+
ts: "typescript",
|
|
337
|
+
tsx: "typescript",
|
|
338
|
+
js: "javascript",
|
|
339
|
+
jsx: "javascript",
|
|
340
|
+
json: "json",
|
|
341
|
+
md: "markdown",
|
|
342
|
+
css: "css",
|
|
343
|
+
html: "html",
|
|
344
|
+
orb: "json"
|
|
345
|
+
};
|
|
346
|
+
const language = languageMap[ext];
|
|
347
|
+
if (!language) return null;
|
|
348
|
+
return extensions.find((e) => e.language === language) || null;
|
|
349
|
+
}, [extensions]);
|
|
350
|
+
React3.useEffect(() => {
|
|
351
|
+
if (!appId || !loadOnMount) return;
|
|
352
|
+
const loadExtensions2 = async () => {
|
|
353
|
+
setIsLoading(true);
|
|
354
|
+
setError(null);
|
|
355
|
+
try {
|
|
356
|
+
const defaultExtensions = [
|
|
357
|
+
{ id: "typescript", name: "TypeScript", language: "typescript", loaded: true },
|
|
358
|
+
{ id: "javascript", name: "JavaScript", language: "javascript", loaded: true },
|
|
359
|
+
{ id: "json", name: "JSON", language: "json", loaded: true },
|
|
360
|
+
{ id: "css", name: "CSS", language: "css", loaded: true },
|
|
361
|
+
{ id: "html", name: "HTML", language: "html", loaded: true },
|
|
362
|
+
{ id: "markdown", name: "Markdown", language: "markdown", loaded: true }
|
|
363
|
+
];
|
|
364
|
+
setExtensions(defaultExtensions);
|
|
365
|
+
} catch (err) {
|
|
366
|
+
setError(err instanceof Error ? err.message : "Failed to load extensions");
|
|
367
|
+
} finally {
|
|
368
|
+
setIsLoading(false);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
loadExtensions2();
|
|
372
|
+
}, [appId, loadOnMount]);
|
|
373
|
+
return {
|
|
374
|
+
extensions,
|
|
375
|
+
manifest,
|
|
376
|
+
isLoading,
|
|
377
|
+
error,
|
|
378
|
+
loadExtension,
|
|
379
|
+
loadExtensions,
|
|
380
|
+
getExtensionForFile
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function useFileEditor(options) {
|
|
384
|
+
const { extensions, fileSystem, onSchemaUpdate } = options;
|
|
385
|
+
const [openFiles, setOpenFiles] = React3.useState([]);
|
|
386
|
+
const [activeFilePath, setActiveFilePath] = React3.useState(null);
|
|
387
|
+
const [isSaving, setIsSaving] = React3.useState(false);
|
|
388
|
+
const activeFile = openFiles.find((f) => f.path === activeFilePath) || null;
|
|
389
|
+
const openFile = React3.useCallback(async (path) => {
|
|
390
|
+
const existing = openFiles.find((f) => f.path === path);
|
|
391
|
+
if (existing) {
|
|
392
|
+
setActiveFilePath(path);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
try {
|
|
396
|
+
const content = await fileSystem.readFile(path);
|
|
397
|
+
const ext = extensions.getExtensionForFile(path);
|
|
398
|
+
const newFile = {
|
|
399
|
+
path,
|
|
400
|
+
content,
|
|
401
|
+
isDirty: false,
|
|
402
|
+
language: ext?.language
|
|
403
|
+
};
|
|
404
|
+
setOpenFiles((prev) => [...prev, newFile]);
|
|
405
|
+
setActiveFilePath(path);
|
|
406
|
+
} catch (err) {
|
|
407
|
+
console.error("[useFileEditor] Failed to open file:", err);
|
|
408
|
+
}
|
|
409
|
+
}, [openFiles, fileSystem, extensions]);
|
|
410
|
+
const closeFile = React3.useCallback((path) => {
|
|
411
|
+
setOpenFiles((prev) => prev.filter((f) => f.path !== path));
|
|
412
|
+
if (activeFilePath === path) {
|
|
413
|
+
const remaining = openFiles.filter((f) => f.path !== path);
|
|
414
|
+
setActiveFilePath(remaining.length > 0 ? remaining[0].path : null);
|
|
415
|
+
}
|
|
416
|
+
}, [activeFilePath, openFiles]);
|
|
417
|
+
const setActiveFile = React3.useCallback((path) => {
|
|
418
|
+
setActiveFilePath(path);
|
|
419
|
+
}, []);
|
|
420
|
+
const updateFileContent = React3.useCallback((path, content) => {
|
|
421
|
+
setOpenFiles(
|
|
422
|
+
(prev) => prev.map(
|
|
423
|
+
(f) => f.path === path ? { ...f, content, isDirty: true } : f
|
|
424
|
+
)
|
|
425
|
+
);
|
|
426
|
+
}, []);
|
|
427
|
+
const handleFileEdit = React3.useCallback(async (path, content) => {
|
|
428
|
+
try {
|
|
429
|
+
await fileSystem.writeFile(path, content);
|
|
430
|
+
let action = "saved";
|
|
431
|
+
if (path.endsWith(".orb") || path.endsWith("schema.json")) {
|
|
432
|
+
try {
|
|
433
|
+
const schema = JSON.parse(content);
|
|
434
|
+
await onSchemaUpdate?.(schema);
|
|
435
|
+
action = "updated_schema";
|
|
436
|
+
} catch {
|
|
437
|
+
}
|
|
438
|
+
} else if (path.includes("/extensions/")) {
|
|
439
|
+
action = path.endsWith(".new") ? "converted_extension" : "saved_extension";
|
|
440
|
+
}
|
|
441
|
+
return { success: true, action };
|
|
442
|
+
} catch (err) {
|
|
443
|
+
return {
|
|
444
|
+
success: false,
|
|
445
|
+
error: err instanceof Error ? err.message : "Failed to save file"
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
}, [fileSystem, onSchemaUpdate]);
|
|
449
|
+
const saveFile = React3.useCallback(async (path) => {
|
|
450
|
+
const file = openFiles.find((f) => f.path === path);
|
|
451
|
+
if (!file) return;
|
|
452
|
+
setIsSaving(true);
|
|
453
|
+
try {
|
|
454
|
+
await fileSystem.writeFile(path, file.content);
|
|
455
|
+
setOpenFiles(
|
|
456
|
+
(prev) => prev.map(
|
|
457
|
+
(f) => f.path === path ? { ...f, isDirty: false } : f
|
|
458
|
+
)
|
|
459
|
+
);
|
|
460
|
+
if (path.endsWith(".orb") || path.endsWith("schema.json")) {
|
|
461
|
+
try {
|
|
462
|
+
const schema = JSON.parse(file.content);
|
|
463
|
+
await onSchemaUpdate?.(schema);
|
|
464
|
+
} catch {
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
} catch (err) {
|
|
468
|
+
console.error("[useFileEditor] Failed to save file:", err);
|
|
469
|
+
} finally {
|
|
470
|
+
setIsSaving(false);
|
|
471
|
+
}
|
|
472
|
+
}, [openFiles, fileSystem, onSchemaUpdate]);
|
|
473
|
+
const saveAllFiles = React3.useCallback(async () => {
|
|
474
|
+
setIsSaving(true);
|
|
475
|
+
try {
|
|
476
|
+
const dirtyFiles = openFiles.filter((f) => f.isDirty);
|
|
477
|
+
for (const file of dirtyFiles) {
|
|
478
|
+
await saveFile(file.path);
|
|
479
|
+
}
|
|
480
|
+
} finally {
|
|
481
|
+
setIsSaving(false);
|
|
482
|
+
}
|
|
483
|
+
}, [openFiles, saveFile]);
|
|
484
|
+
return {
|
|
485
|
+
openFiles,
|
|
486
|
+
activeFile,
|
|
487
|
+
isSaving,
|
|
488
|
+
openFile,
|
|
489
|
+
closeFile,
|
|
490
|
+
setActiveFile,
|
|
491
|
+
updateFileContent,
|
|
492
|
+
handleFileEdit,
|
|
493
|
+
saveFile,
|
|
494
|
+
saveAllFiles
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function useCompile() {
|
|
498
|
+
const [isCompiling, setIsCompiling] = React3.useState(false);
|
|
499
|
+
const [stage, setStage] = React3.useState("idle");
|
|
500
|
+
const [lastResult, setLastResult] = React3.useState(null);
|
|
501
|
+
const [error, setError] = React3.useState(null);
|
|
502
|
+
const compileSchema = React3.useCallback(async (schema) => {
|
|
503
|
+
setIsCompiling(true);
|
|
504
|
+
setStage("compiling");
|
|
505
|
+
setError(null);
|
|
506
|
+
try {
|
|
507
|
+
console.log("[useCompile] Compiling schema:", schema.name);
|
|
508
|
+
const result = {
|
|
509
|
+
success: true,
|
|
510
|
+
files: []
|
|
511
|
+
};
|
|
512
|
+
setLastResult(result);
|
|
513
|
+
setStage("done");
|
|
514
|
+
return result;
|
|
515
|
+
} catch (err) {
|
|
516
|
+
const errorMessage = err instanceof Error ? err.message : "Compilation failed";
|
|
517
|
+
setError(errorMessage);
|
|
518
|
+
setStage("error");
|
|
519
|
+
setLastResult({ success: false, errors: [errorMessage] });
|
|
520
|
+
return null;
|
|
521
|
+
} finally {
|
|
522
|
+
setIsCompiling(false);
|
|
523
|
+
}
|
|
524
|
+
}, []);
|
|
525
|
+
return {
|
|
526
|
+
isCompiling,
|
|
527
|
+
stage,
|
|
528
|
+
lastResult,
|
|
529
|
+
error,
|
|
530
|
+
compileSchema
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function usePreview(options) {
|
|
534
|
+
const [previewUrl, setPreviewUrl] = React3.useState(null);
|
|
535
|
+
const [isLoading, setIsLoading] = React3.useState(!!options?.appId);
|
|
536
|
+
const [error, setError] = React3.useState(null);
|
|
537
|
+
const [loadError, setLoadError] = React3.useState(null);
|
|
538
|
+
const [app, setApp] = React3.useState(null);
|
|
539
|
+
const [isFullscreen, setIsFullscreen] = React3.useState(false);
|
|
540
|
+
const [isExecutingEvent, setIsExecutingEvent] = React3.useState(false);
|
|
541
|
+
const [errorToast, setErrorToast] = React3.useState(null);
|
|
542
|
+
const [currentStateName, setCurrentStateName] = React3.useState(null);
|
|
543
|
+
const [notificationsList, setNotificationsList] = React3.useState([]);
|
|
544
|
+
const [isPanelOpen, setIsPanelOpen] = React3.useState(false);
|
|
545
|
+
const notifications = React3.useMemo(() => ({
|
|
546
|
+
notifications: notificationsList,
|
|
547
|
+
isPanelOpen,
|
|
548
|
+
closePanel: () => setIsPanelOpen(false),
|
|
549
|
+
dismissNotification: (id) => {
|
|
550
|
+
setNotificationsList((prev) => prev.filter((n) => n.id !== id));
|
|
551
|
+
},
|
|
552
|
+
markAsRead: (id) => {
|
|
553
|
+
setNotificationsList(
|
|
554
|
+
(prev) => prev.map((n) => n.id === id ? { ...n, read: true } : n)
|
|
555
|
+
);
|
|
556
|
+
},
|
|
557
|
+
clearAll: () => setNotificationsList([])
|
|
558
|
+
}), [notificationsList, isPanelOpen]);
|
|
559
|
+
React3.useEffect(() => {
|
|
560
|
+
const appId = options?.appId;
|
|
561
|
+
if (!appId) {
|
|
562
|
+
setApp(null);
|
|
563
|
+
setIsLoading(false);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
console.log("[usePreview] Setting up preview for app:", appId);
|
|
567
|
+
setPreviewUrl(`/api/orbitals/${appId}`);
|
|
568
|
+
setIsLoading(false);
|
|
569
|
+
}, [options?.appId]);
|
|
570
|
+
const startPreview = React3.useCallback(async () => {
|
|
571
|
+
console.log("[usePreview] startPreview called");
|
|
572
|
+
}, []);
|
|
573
|
+
const stopPreview = React3.useCallback(async () => {
|
|
574
|
+
setIsLoading(true);
|
|
575
|
+
try {
|
|
576
|
+
console.log("[usePreview] Stopping preview server...");
|
|
577
|
+
setPreviewUrl(null);
|
|
578
|
+
setApp(null);
|
|
579
|
+
} finally {
|
|
580
|
+
setIsLoading(false);
|
|
581
|
+
}
|
|
582
|
+
}, []);
|
|
583
|
+
const refresh = React3.useCallback(async () => {
|
|
584
|
+
if (!previewUrl) return;
|
|
585
|
+
console.log("[usePreview] Refreshing preview...");
|
|
586
|
+
setPreviewUrl(`${previewUrl.split("?")[0]}?t=${Date.now()}`);
|
|
587
|
+
}, [previewUrl]);
|
|
588
|
+
const handleRefresh = React3.useCallback(async () => {
|
|
589
|
+
console.log("[usePreview] Handle refresh...");
|
|
590
|
+
await refresh();
|
|
591
|
+
}, [refresh]);
|
|
592
|
+
const handleReset = React3.useCallback(async () => {
|
|
593
|
+
console.log("[usePreview] Resetting preview...");
|
|
594
|
+
setError(null);
|
|
595
|
+
setLoadError(null);
|
|
596
|
+
setErrorToast(null);
|
|
597
|
+
setIsExecutingEvent(false);
|
|
598
|
+
setCurrentStateName(null);
|
|
599
|
+
}, []);
|
|
600
|
+
const toggleFullscreen = React3.useCallback(() => {
|
|
601
|
+
setIsFullscreen((prev) => !prev);
|
|
602
|
+
}, []);
|
|
603
|
+
const dismissErrorToast = React3.useCallback(() => {
|
|
604
|
+
setErrorToast(null);
|
|
605
|
+
}, []);
|
|
606
|
+
return {
|
|
607
|
+
previewUrl,
|
|
608
|
+
isLoading,
|
|
609
|
+
error,
|
|
610
|
+
loadError,
|
|
611
|
+
app,
|
|
612
|
+
isFullscreen,
|
|
613
|
+
isExecutingEvent,
|
|
614
|
+
errorToast,
|
|
615
|
+
currentStateName,
|
|
616
|
+
notifications,
|
|
617
|
+
startPreview,
|
|
618
|
+
stopPreview,
|
|
619
|
+
refresh,
|
|
620
|
+
handleRefresh,
|
|
621
|
+
handleReset,
|
|
622
|
+
toggleFullscreen,
|
|
623
|
+
setErrorToast,
|
|
624
|
+
dismissErrorToast
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
function useAgentChat(options) {
|
|
628
|
+
const [messages, setMessages] = React3.useState([]);
|
|
629
|
+
const [status, setStatus] = React3.useState("idle");
|
|
630
|
+
const [activities, setActivities] = React3.useState([]);
|
|
631
|
+
const [todos, setTodos] = React3.useState([]);
|
|
632
|
+
const [schemaDiffs, setSchemaDiffs] = React3.useState([]);
|
|
633
|
+
const [isLoading, setIsLoading] = React3.useState(false);
|
|
634
|
+
const [error, setError] = React3.useState(null);
|
|
635
|
+
const [threadId] = React3.useState(null);
|
|
636
|
+
const [interrupt, setInterrupt] = React3.useState(null);
|
|
637
|
+
const sendMessage = React3.useCallback(async (content) => {
|
|
638
|
+
setIsLoading(true);
|
|
639
|
+
setStatus("running");
|
|
640
|
+
setError(null);
|
|
641
|
+
try {
|
|
642
|
+
const userMessage = {
|
|
643
|
+
id: Date.now().toString(),
|
|
644
|
+
role: "user",
|
|
645
|
+
content,
|
|
646
|
+
timestamp: Date.now()
|
|
647
|
+
};
|
|
648
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
649
|
+
console.log("[useAgentChat] Sending message:", content);
|
|
650
|
+
const assistantMessage = {
|
|
651
|
+
id: (Date.now() + 1).toString(),
|
|
652
|
+
role: "assistant",
|
|
653
|
+
content: "Agent chat is not yet implemented.",
|
|
654
|
+
timestamp: Date.now()
|
|
655
|
+
};
|
|
656
|
+
setMessages((prev) => [...prev, assistantMessage]);
|
|
657
|
+
setStatus("idle");
|
|
658
|
+
options?.onComplete?.();
|
|
659
|
+
} catch (err) {
|
|
660
|
+
setError(err instanceof Error ? err.message : "Failed to send message");
|
|
661
|
+
setStatus("error");
|
|
662
|
+
} finally {
|
|
663
|
+
setIsLoading(false);
|
|
664
|
+
}
|
|
665
|
+
}, [options]);
|
|
666
|
+
const startGeneration = React3.useCallback(async (skill, prompt, genOptions) => {
|
|
667
|
+
setStatus("running");
|
|
668
|
+
setIsLoading(true);
|
|
669
|
+
setError(null);
|
|
670
|
+
const skillName = Array.isArray(skill) ? skill[0] : skill;
|
|
671
|
+
try {
|
|
672
|
+
console.log("[useAgentChat] Starting generation:", skillName, prompt, genOptions);
|
|
673
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
674
|
+
setStatus("complete");
|
|
675
|
+
options?.onComplete?.();
|
|
676
|
+
} catch (err) {
|
|
677
|
+
setError(err instanceof Error ? err.message : "Generation failed");
|
|
678
|
+
setStatus("error");
|
|
679
|
+
} finally {
|
|
680
|
+
setIsLoading(false);
|
|
681
|
+
}
|
|
682
|
+
}, [options]);
|
|
683
|
+
const continueConversation = React3.useCallback(async (message) => {
|
|
684
|
+
console.log("[useAgentChat] Continue conversation", message);
|
|
685
|
+
}, []);
|
|
686
|
+
const resumeWithDecision = React3.useCallback(async (decisions) => {
|
|
687
|
+
console.log("[useAgentChat] Resume with decision:", decisions);
|
|
688
|
+
setInterrupt(null);
|
|
689
|
+
}, []);
|
|
690
|
+
const cancel = React3.useCallback(() => {
|
|
691
|
+
setStatus("idle");
|
|
692
|
+
setIsLoading(false);
|
|
693
|
+
setInterrupt(null);
|
|
694
|
+
}, []);
|
|
695
|
+
const clearMessages = React3.useCallback(() => {
|
|
696
|
+
setMessages([]);
|
|
697
|
+
}, []);
|
|
698
|
+
const clearHistory = React3.useCallback(() => {
|
|
699
|
+
setMessages([]);
|
|
700
|
+
setActivities([]);
|
|
701
|
+
setTodos([]);
|
|
702
|
+
setSchemaDiffs([]);
|
|
703
|
+
setError(null);
|
|
704
|
+
}, []);
|
|
705
|
+
return {
|
|
706
|
+
messages,
|
|
707
|
+
status,
|
|
708
|
+
activities,
|
|
709
|
+
todos,
|
|
710
|
+
schemaDiffs,
|
|
711
|
+
isLoading,
|
|
712
|
+
error,
|
|
713
|
+
threadId,
|
|
714
|
+
interrupt,
|
|
715
|
+
sendMessage,
|
|
716
|
+
startGeneration,
|
|
717
|
+
continueConversation,
|
|
718
|
+
resumeWithDecision,
|
|
719
|
+
cancel,
|
|
720
|
+
clearMessages,
|
|
721
|
+
clearHistory
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
function useValidation() {
|
|
725
|
+
const [result, setResult] = React3.useState(null);
|
|
726
|
+
const [isValidating, setIsValidating] = React3.useState(false);
|
|
727
|
+
const [error, setError] = React3.useState(null);
|
|
728
|
+
const [stage, setStage] = React3.useState("idle");
|
|
729
|
+
const [isFixing, setIsFixing] = React3.useState(false);
|
|
730
|
+
const [progressMessage, setProgressMessage] = React3.useState(null);
|
|
731
|
+
const validate = React3.useCallback(async (appId) => {
|
|
732
|
+
setIsValidating(true);
|
|
733
|
+
setError(null);
|
|
734
|
+
setStage("validating");
|
|
735
|
+
setProgressMessage("Validating schema...");
|
|
736
|
+
try {
|
|
737
|
+
console.log("[useValidation] Validating app:", appId);
|
|
738
|
+
const validationResult = {
|
|
739
|
+
valid: true,
|
|
740
|
+
errors: [],
|
|
741
|
+
warnings: []
|
|
742
|
+
};
|
|
743
|
+
setResult(validationResult);
|
|
744
|
+
setStage("complete");
|
|
745
|
+
setProgressMessage(null);
|
|
746
|
+
return validationResult;
|
|
747
|
+
} catch (err) {
|
|
748
|
+
const errorMessage = err instanceof Error ? err.message : "Validation failed";
|
|
749
|
+
setError(errorMessage);
|
|
750
|
+
const failedResult = {
|
|
751
|
+
valid: false,
|
|
752
|
+
errors: [{ code: "VALIDATION_ERROR", message: errorMessage, severity: "error" }],
|
|
753
|
+
warnings: []
|
|
754
|
+
};
|
|
755
|
+
setResult(failedResult);
|
|
756
|
+
setStage("complete");
|
|
757
|
+
setProgressMessage(null);
|
|
758
|
+
return failedResult;
|
|
759
|
+
} finally {
|
|
760
|
+
setIsValidating(false);
|
|
761
|
+
}
|
|
762
|
+
}, []);
|
|
763
|
+
const clearResult = React3.useCallback(() => {
|
|
764
|
+
setResult(null);
|
|
765
|
+
setError(null);
|
|
766
|
+
}, []);
|
|
767
|
+
const reset = React3.useCallback(() => {
|
|
768
|
+
setResult(null);
|
|
769
|
+
setError(null);
|
|
770
|
+
setStage("idle");
|
|
771
|
+
setIsFixing(false);
|
|
772
|
+
setProgressMessage(null);
|
|
773
|
+
setIsValidating(false);
|
|
774
|
+
}, []);
|
|
775
|
+
return {
|
|
776
|
+
result,
|
|
777
|
+
isValidating,
|
|
778
|
+
error,
|
|
779
|
+
stage,
|
|
780
|
+
isFixing,
|
|
781
|
+
progressMessage,
|
|
782
|
+
errors: result?.errors ?? [],
|
|
783
|
+
warnings: result?.warnings ?? [],
|
|
784
|
+
isValid: result?.valid ?? false,
|
|
785
|
+
validate,
|
|
786
|
+
clearResult,
|
|
787
|
+
reset
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
function useDeepAgentGeneration() {
|
|
791
|
+
const [requests, setRequests] = React3.useState([]);
|
|
792
|
+
const [currentRequest, setCurrentRequest] = React3.useState(null);
|
|
793
|
+
const [isGenerating, setIsGenerating] = React3.useState(false);
|
|
794
|
+
const [isLoading, setIsLoading] = React3.useState(false);
|
|
795
|
+
const [isComplete, setIsComplete] = React3.useState(false);
|
|
796
|
+
const [progress, setProgress] = React3.useState({ stage: "idle", percent: 0, message: "" });
|
|
797
|
+
const [error, setError] = React3.useState(null);
|
|
798
|
+
const [interrupt, setInterrupt] = React3.useState(null);
|
|
799
|
+
const generate = React3.useCallback(async (prompt) => {
|
|
800
|
+
setIsGenerating(true);
|
|
801
|
+
setIsLoading(true);
|
|
802
|
+
setIsComplete(false);
|
|
803
|
+
setError(null);
|
|
804
|
+
setProgress({ stage: "starting", percent: 0, message: "Starting generation..." });
|
|
805
|
+
const request = {
|
|
806
|
+
id: Date.now().toString(),
|
|
807
|
+
prompt,
|
|
808
|
+
status: "running"
|
|
809
|
+
};
|
|
810
|
+
setCurrentRequest(request);
|
|
811
|
+
setRequests((prev) => [...prev, request]);
|
|
812
|
+
try {
|
|
813
|
+
console.log("[useDeepAgentGeneration] Generating from prompt:", prompt);
|
|
814
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
815
|
+
request.status = "completed";
|
|
816
|
+
setCurrentRequest(request);
|
|
817
|
+
setIsComplete(true);
|
|
818
|
+
setProgress({ stage: "complete", percent: 100, message: "Generation complete" });
|
|
819
|
+
return null;
|
|
820
|
+
} catch (err) {
|
|
821
|
+
const errorMessage = err instanceof Error ? err.message : "Generation failed";
|
|
822
|
+
setError(errorMessage);
|
|
823
|
+
request.status = "failed";
|
|
824
|
+
request.error = errorMessage;
|
|
825
|
+
setCurrentRequest(request);
|
|
826
|
+
return null;
|
|
827
|
+
} finally {
|
|
828
|
+
setIsGenerating(false);
|
|
829
|
+
setIsLoading(false);
|
|
830
|
+
}
|
|
831
|
+
}, []);
|
|
832
|
+
const startGeneration = React3.useCallback(async (skill, prompt, _options) => {
|
|
833
|
+
console.log("[useDeepAgentGeneration] Starting generation with skill:", skill);
|
|
834
|
+
await generate(prompt);
|
|
835
|
+
}, [generate]);
|
|
836
|
+
const cancelGeneration = React3.useCallback(() => {
|
|
837
|
+
if (currentRequest) {
|
|
838
|
+
currentRequest.status = "failed";
|
|
839
|
+
currentRequest.error = "Cancelled by user";
|
|
840
|
+
setCurrentRequest(null);
|
|
841
|
+
}
|
|
842
|
+
setIsGenerating(false);
|
|
843
|
+
setIsLoading(false);
|
|
844
|
+
setIsComplete(false);
|
|
845
|
+
setProgress({ stage: "idle", percent: 0, message: "" });
|
|
846
|
+
}, [currentRequest]);
|
|
847
|
+
const clearRequests = React3.useCallback(() => {
|
|
848
|
+
setRequests([]);
|
|
849
|
+
setCurrentRequest(null);
|
|
850
|
+
setError(null);
|
|
851
|
+
setProgress({ stage: "idle", percent: 0, message: "" });
|
|
852
|
+
setIsComplete(false);
|
|
853
|
+
}, []);
|
|
854
|
+
const submitInterruptDecisions = React3.useCallback((decisions) => {
|
|
855
|
+
console.log("[useDeepAgentGeneration] Submitting interrupt decisions:", decisions);
|
|
856
|
+
setInterrupt(null);
|
|
857
|
+
}, []);
|
|
858
|
+
return {
|
|
859
|
+
requests,
|
|
860
|
+
currentRequest,
|
|
861
|
+
isGenerating,
|
|
862
|
+
isLoading,
|
|
863
|
+
isComplete,
|
|
864
|
+
progress,
|
|
865
|
+
error,
|
|
866
|
+
interrupt,
|
|
867
|
+
generate,
|
|
868
|
+
startGeneration,
|
|
869
|
+
cancelGeneration,
|
|
870
|
+
clearRequests,
|
|
871
|
+
submitInterruptDecisions
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
var EventBusContext = React3.createContext(null);
|
|
875
|
+
|
|
876
|
+
// hooks/useEventBus.ts
|
|
877
|
+
function getGlobalEventBus() {
|
|
878
|
+
if (typeof window !== "undefined") {
|
|
879
|
+
return window.__kflowEventBus ?? null;
|
|
880
|
+
}
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
var fallbackListeners = /* @__PURE__ */ new Map();
|
|
884
|
+
var fallbackAnyListeners = /* @__PURE__ */ new Set();
|
|
885
|
+
var fallbackEventBus = {
|
|
886
|
+
emit: (type, payload) => {
|
|
887
|
+
const event = {
|
|
888
|
+
type,
|
|
889
|
+
payload,
|
|
890
|
+
timestamp: Date.now()
|
|
891
|
+
};
|
|
892
|
+
const handlers = fallbackListeners.get(type);
|
|
893
|
+
if (handlers) {
|
|
894
|
+
handlers.forEach((handler) => {
|
|
895
|
+
try {
|
|
896
|
+
handler(event);
|
|
897
|
+
} catch (error) {
|
|
898
|
+
console.error(`[EventBus] Error in listener for '${type}':`, error);
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
fallbackAnyListeners.forEach((handler) => {
|
|
903
|
+
try {
|
|
904
|
+
handler(event);
|
|
905
|
+
} catch (error) {
|
|
906
|
+
console.error(`[EventBus] Error in onAny listener for '${type}':`, error);
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
},
|
|
910
|
+
on: (type, listener) => {
|
|
911
|
+
if (!fallbackListeners.has(type)) {
|
|
912
|
+
fallbackListeners.set(type, /* @__PURE__ */ new Set());
|
|
913
|
+
}
|
|
914
|
+
fallbackListeners.get(type).add(listener);
|
|
915
|
+
return () => {
|
|
916
|
+
const handlers = fallbackListeners.get(type);
|
|
917
|
+
if (handlers) {
|
|
918
|
+
handlers.delete(listener);
|
|
919
|
+
if (handlers.size === 0) {
|
|
920
|
+
fallbackListeners.delete(type);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
},
|
|
925
|
+
once: (type, listener) => {
|
|
926
|
+
const wrappedListener = (event) => {
|
|
927
|
+
fallbackListeners.get(type)?.delete(wrappedListener);
|
|
928
|
+
listener(event);
|
|
929
|
+
};
|
|
930
|
+
return fallbackEventBus.on(type, wrappedListener);
|
|
931
|
+
},
|
|
932
|
+
hasListeners: (type) => {
|
|
933
|
+
const handlers = fallbackListeners.get(type);
|
|
934
|
+
return handlers !== void 0 && handlers.size > 0;
|
|
935
|
+
},
|
|
936
|
+
onAny: (listener) => {
|
|
937
|
+
fallbackAnyListeners.add(listener);
|
|
938
|
+
return () => {
|
|
939
|
+
fallbackAnyListeners.delete(listener);
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
function useEventBus() {
|
|
944
|
+
const context = React3.useContext(EventBusContext);
|
|
945
|
+
return context ?? getGlobalEventBus() ?? fallbackEventBus;
|
|
946
|
+
}
|
|
947
|
+
function useEventListener(event, handler) {
|
|
948
|
+
const eventBus = useEventBus();
|
|
949
|
+
const handlerRef = React3.useRef(handler);
|
|
950
|
+
handlerRef.current = handler;
|
|
951
|
+
React3.useEffect(() => {
|
|
952
|
+
const wrappedHandler = (evt) => {
|
|
953
|
+
handlerRef.current(evt);
|
|
954
|
+
};
|
|
955
|
+
const unsub = eventBus.on(event, wrappedHandler);
|
|
956
|
+
return () => {
|
|
957
|
+
if (typeof unsub === "function") unsub();
|
|
958
|
+
};
|
|
959
|
+
}, [event, eventBus]);
|
|
960
|
+
}
|
|
961
|
+
function useEmitEvent() {
|
|
962
|
+
const eventBus = useEventBus();
|
|
963
|
+
return React3.useCallback(
|
|
964
|
+
(type, payload) => {
|
|
965
|
+
eventBus.emit(type, payload);
|
|
966
|
+
},
|
|
967
|
+
[eventBus]
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
var DEFAULT_SLOTS = {
|
|
971
|
+
main: null,
|
|
972
|
+
sidebar: null,
|
|
973
|
+
modal: null,
|
|
974
|
+
drawer: null,
|
|
975
|
+
overlay: null,
|
|
976
|
+
center: null,
|
|
977
|
+
toast: null,
|
|
978
|
+
"hud-top": null,
|
|
979
|
+
"hud-bottom": null,
|
|
980
|
+
"hud-left": null,
|
|
981
|
+
"hud-right": null,
|
|
982
|
+
floating: null
|
|
983
|
+
};
|
|
984
|
+
var idCounter = 0;
|
|
985
|
+
function generateId() {
|
|
986
|
+
return `slot-content-${++idCounter}-${Date.now()}`;
|
|
987
|
+
}
|
|
988
|
+
function useUISlotManager() {
|
|
989
|
+
const [slots, setSlots] = React3.useState(DEFAULT_SLOTS);
|
|
990
|
+
const subscribersRef = React3.useRef(/* @__PURE__ */ new Set());
|
|
991
|
+
const timersRef = React3.useRef(/* @__PURE__ */ new Map());
|
|
992
|
+
React3.useEffect(() => {
|
|
993
|
+
return () => {
|
|
994
|
+
timersRef.current.forEach((timer) => clearTimeout(timer));
|
|
995
|
+
timersRef.current.clear();
|
|
996
|
+
};
|
|
997
|
+
}, []);
|
|
998
|
+
const notifySubscribers = React3.useCallback((slot, content) => {
|
|
999
|
+
subscribersRef.current.forEach((callback) => {
|
|
1000
|
+
try {
|
|
1001
|
+
callback(slot, content);
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
console.error("[UISlots] Subscriber error:", error);
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
}, []);
|
|
1007
|
+
const render = React3.useCallback((config) => {
|
|
1008
|
+
const id = generateId();
|
|
1009
|
+
const content = {
|
|
1010
|
+
id,
|
|
1011
|
+
pattern: config.pattern,
|
|
1012
|
+
props: config.props ?? {},
|
|
1013
|
+
priority: config.priority ?? 0,
|
|
1014
|
+
animation: config.animation ?? "fade",
|
|
1015
|
+
onDismiss: config.onDismiss,
|
|
1016
|
+
sourceTrait: config.sourceTrait
|
|
1017
|
+
};
|
|
1018
|
+
if (config.autoDismissMs && config.autoDismissMs > 0) {
|
|
1019
|
+
content.autoDismissAt = Date.now() + config.autoDismissMs;
|
|
1020
|
+
const timer = setTimeout(() => {
|
|
1021
|
+
setSlots((prev) => {
|
|
1022
|
+
if (prev[config.target]?.id === id) {
|
|
1023
|
+
content.onDismiss?.();
|
|
1024
|
+
notifySubscribers(config.target, null);
|
|
1025
|
+
return { ...prev, [config.target]: null };
|
|
1026
|
+
}
|
|
1027
|
+
return prev;
|
|
1028
|
+
});
|
|
1029
|
+
timersRef.current.delete(id);
|
|
1030
|
+
}, config.autoDismissMs);
|
|
1031
|
+
timersRef.current.set(id, timer);
|
|
1032
|
+
}
|
|
1033
|
+
setSlots((prev) => {
|
|
1034
|
+
const existing = prev[config.target];
|
|
1035
|
+
if (existing && existing.priority > content.priority) {
|
|
1036
|
+
console.warn(
|
|
1037
|
+
`[UISlots] Slot "${config.target}" already has higher priority content (${existing.priority} > ${content.priority})`
|
|
1038
|
+
);
|
|
1039
|
+
return prev;
|
|
1040
|
+
}
|
|
1041
|
+
notifySubscribers(config.target, content);
|
|
1042
|
+
return { ...prev, [config.target]: content };
|
|
1043
|
+
});
|
|
1044
|
+
return id;
|
|
1045
|
+
}, [notifySubscribers]);
|
|
1046
|
+
const clear = React3.useCallback((slot) => {
|
|
1047
|
+
setSlots((prev) => {
|
|
1048
|
+
const content = prev[slot];
|
|
1049
|
+
if (content) {
|
|
1050
|
+
const timer = timersRef.current.get(content.id);
|
|
1051
|
+
if (timer) {
|
|
1052
|
+
clearTimeout(timer);
|
|
1053
|
+
timersRef.current.delete(content.id);
|
|
1054
|
+
}
|
|
1055
|
+
content.onDismiss?.();
|
|
1056
|
+
notifySubscribers(slot, null);
|
|
1057
|
+
}
|
|
1058
|
+
return { ...prev, [slot]: null };
|
|
1059
|
+
});
|
|
1060
|
+
}, [notifySubscribers]);
|
|
1061
|
+
const clearById = React3.useCallback((id) => {
|
|
1062
|
+
setSlots((prev) => {
|
|
1063
|
+
const entry = Object.entries(prev).find(([, content]) => content?.id === id);
|
|
1064
|
+
if (entry) {
|
|
1065
|
+
const [slot, content] = entry;
|
|
1066
|
+
const timer = timersRef.current.get(id);
|
|
1067
|
+
if (timer) {
|
|
1068
|
+
clearTimeout(timer);
|
|
1069
|
+
timersRef.current.delete(id);
|
|
1070
|
+
}
|
|
1071
|
+
content.onDismiss?.();
|
|
1072
|
+
notifySubscribers(slot, null);
|
|
1073
|
+
return { ...prev, [slot]: null };
|
|
1074
|
+
}
|
|
1075
|
+
return prev;
|
|
1076
|
+
});
|
|
1077
|
+
}, [notifySubscribers]);
|
|
1078
|
+
const clearAll = React3.useCallback(() => {
|
|
1079
|
+
timersRef.current.forEach((timer) => clearTimeout(timer));
|
|
1080
|
+
timersRef.current.clear();
|
|
1081
|
+
setSlots((prev) => {
|
|
1082
|
+
Object.entries(prev).forEach(([slot, content]) => {
|
|
1083
|
+
if (content) {
|
|
1084
|
+
content.onDismiss?.();
|
|
1085
|
+
notifySubscribers(slot, null);
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
return DEFAULT_SLOTS;
|
|
1089
|
+
});
|
|
1090
|
+
}, [notifySubscribers]);
|
|
1091
|
+
const subscribe2 = React3.useCallback((callback) => {
|
|
1092
|
+
subscribersRef.current.add(callback);
|
|
1093
|
+
return () => {
|
|
1094
|
+
subscribersRef.current.delete(callback);
|
|
1095
|
+
};
|
|
1096
|
+
}, []);
|
|
1097
|
+
const hasContent = React3.useCallback((slot) => {
|
|
1098
|
+
return slots[slot] !== null;
|
|
1099
|
+
}, [slots]);
|
|
1100
|
+
const getContent = React3.useCallback((slot) => {
|
|
1101
|
+
return slots[slot];
|
|
1102
|
+
}, [slots]);
|
|
1103
|
+
return {
|
|
1104
|
+
slots,
|
|
1105
|
+
render,
|
|
1106
|
+
clear,
|
|
1107
|
+
clearById,
|
|
1108
|
+
clearAll,
|
|
1109
|
+
subscribe: subscribe2,
|
|
1110
|
+
hasContent,
|
|
1111
|
+
getContent
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
var SelectionContext = React3.createContext(null);
|
|
1115
|
+
|
|
1116
|
+
// hooks/useUIEvents.ts
|
|
1117
|
+
var UI_EVENT_MAP = {
|
|
1118
|
+
// Form/CRUD events
|
|
1119
|
+
"UI:SAVE": "SAVE",
|
|
1120
|
+
"UI:CANCEL": "CANCEL",
|
|
1121
|
+
"UI:CLOSE": "CLOSE",
|
|
1122
|
+
"UI:VIEW": "VIEW",
|
|
1123
|
+
"UI:EDIT": "EDIT",
|
|
1124
|
+
"UI:DELETE": "DELETE",
|
|
1125
|
+
"UI:CREATE": "CREATE",
|
|
1126
|
+
"UI:SELECT": "SELECT",
|
|
1127
|
+
"UI:DESELECT": "DESELECT",
|
|
1128
|
+
"UI:SUBMIT": "SAVE",
|
|
1129
|
+
"UI:UPDATE_STATUS": "UPDATE_STATUS",
|
|
1130
|
+
"UI:SEARCH": "SEARCH",
|
|
1131
|
+
"UI:CLEAR_SEARCH": "CLEAR_SEARCH",
|
|
1132
|
+
"UI:ADD": "CREATE",
|
|
1133
|
+
// Game events (for closed circuit with GameMenu, GamePauseOverlay, GameOverScreen)
|
|
1134
|
+
"UI:PAUSE": "PAUSE",
|
|
1135
|
+
"UI:RESUME": "RESUME",
|
|
1136
|
+
"UI:RESTART": "RESTART",
|
|
1137
|
+
"UI:GAME_OVER": "GAME_OVER",
|
|
1138
|
+
"UI:START": "START",
|
|
1139
|
+
"UI:QUIT": "QUIT",
|
|
1140
|
+
"UI:INIT": "INIT"
|
|
1141
|
+
};
|
|
1142
|
+
function useUIEvents(dispatch, validEvents, eventBusInstance) {
|
|
1143
|
+
const defaultEventBus = useEventBus();
|
|
1144
|
+
const eventBus = eventBusInstance ?? defaultEventBus;
|
|
1145
|
+
const validEventsKey = validEvents ? validEvents.slice().sort().join(",") : "";
|
|
1146
|
+
const stableValidEvents = React3.useMemo(
|
|
1147
|
+
() => validEvents,
|
|
1148
|
+
[validEventsKey]
|
|
1149
|
+
// intentional — validEventsKey is the stable dep, not validEvents array ref
|
|
1150
|
+
);
|
|
1151
|
+
React3.useEffect(() => {
|
|
1152
|
+
const unsubscribes = [];
|
|
1153
|
+
Object.entries(UI_EVENT_MAP).forEach(([uiEvent, smEvent]) => {
|
|
1154
|
+
const handler = (event) => {
|
|
1155
|
+
if (!stableValidEvents || stableValidEvents.includes(smEvent)) {
|
|
1156
|
+
dispatch(smEvent, event.payload);
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
const unsubscribe = eventBus.on(uiEvent, handler);
|
|
1160
|
+
unsubscribes.push(unsubscribe);
|
|
1161
|
+
});
|
|
1162
|
+
const genericHandler = (event) => {
|
|
1163
|
+
const eventName = event.payload?.event;
|
|
1164
|
+
if (eventName) {
|
|
1165
|
+
const smEvent = eventName;
|
|
1166
|
+
if (!stableValidEvents || stableValidEvents.includes(smEvent)) {
|
|
1167
|
+
dispatch(smEvent, event.payload);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
const genericUnsubscribe = eventBus.on("UI:DISPATCH", genericHandler);
|
|
1172
|
+
unsubscribes.push(genericUnsubscribe);
|
|
1173
|
+
if (stableValidEvents) {
|
|
1174
|
+
stableValidEvents.forEach((smEvent) => {
|
|
1175
|
+
const uiPrefixedEvent = `UI:${smEvent}`;
|
|
1176
|
+
const alreadyMapped = Object.keys(UI_EVENT_MAP).includes(uiPrefixedEvent);
|
|
1177
|
+
if (!alreadyMapped) {
|
|
1178
|
+
const directHandler = (event) => {
|
|
1179
|
+
dispatch(smEvent, event.payload);
|
|
1180
|
+
};
|
|
1181
|
+
const unsubscribePrefixed = eventBus.on(
|
|
1182
|
+
uiPrefixedEvent,
|
|
1183
|
+
directHandler
|
|
1184
|
+
);
|
|
1185
|
+
unsubscribes.push(unsubscribePrefixed);
|
|
1186
|
+
const unsubscribeDirect = eventBus.on(smEvent, directHandler);
|
|
1187
|
+
unsubscribes.push(unsubscribeDirect);
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
return () => {
|
|
1192
|
+
unsubscribes.forEach((unsub) => {
|
|
1193
|
+
if (typeof unsub === "function") unsub();
|
|
1194
|
+
});
|
|
1195
|
+
};
|
|
1196
|
+
}, [eventBus, dispatch, stableValidEvents]);
|
|
1197
|
+
}
|
|
1198
|
+
function useSelectedEntity(eventBusInstance) {
|
|
1199
|
+
const defaultEventBus = useEventBus();
|
|
1200
|
+
const eventBus = eventBusInstance ?? defaultEventBus;
|
|
1201
|
+
const selectionContext = useSelectionContext();
|
|
1202
|
+
const [localSelected, setLocalSelected] = React3.useState(null);
|
|
1203
|
+
const usingContext = selectionContext !== null;
|
|
1204
|
+
React3.useEffect(() => {
|
|
1205
|
+
if (usingContext) return;
|
|
1206
|
+
const handleSelect = (event) => {
|
|
1207
|
+
const row = event.payload?.row;
|
|
1208
|
+
if (row) {
|
|
1209
|
+
setLocalSelected(row);
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
const handleDeselect = () => {
|
|
1213
|
+
setLocalSelected(null);
|
|
1214
|
+
};
|
|
1215
|
+
const unsubSelect = eventBus.on("UI:SELECT", handleSelect);
|
|
1216
|
+
const unsubView = eventBus.on("UI:VIEW", handleSelect);
|
|
1217
|
+
const unsubDeselect = eventBus.on("UI:DESELECT", handleDeselect);
|
|
1218
|
+
const unsubClose = eventBus.on("UI:CLOSE", handleDeselect);
|
|
1219
|
+
const unsubCancel = eventBus.on("UI:CANCEL", handleDeselect);
|
|
1220
|
+
return () => {
|
|
1221
|
+
[unsubSelect, unsubView, unsubDeselect, unsubClose, unsubCancel].forEach(
|
|
1222
|
+
(unsub) => {
|
|
1223
|
+
if (typeof unsub === "function") unsub();
|
|
1224
|
+
}
|
|
1225
|
+
);
|
|
1226
|
+
};
|
|
1227
|
+
}, [eventBus, usingContext]);
|
|
1228
|
+
if (selectionContext) {
|
|
1229
|
+
return [selectionContext.selected, selectionContext.setSelected];
|
|
1230
|
+
}
|
|
1231
|
+
return [localSelected, setLocalSelected];
|
|
1232
|
+
}
|
|
1233
|
+
function useSelectionContext() {
|
|
1234
|
+
const context = React3.useContext(SelectionContext);
|
|
1235
|
+
return context;
|
|
1236
|
+
}
|
|
1237
|
+
var EntityDataContext = React3.createContext(null);
|
|
1238
|
+
function EntityDataProvider({
|
|
1239
|
+
adapter,
|
|
1240
|
+
children
|
|
1241
|
+
}) {
|
|
1242
|
+
return React3__default.default.createElement(
|
|
1243
|
+
EntityDataContext.Provider,
|
|
1244
|
+
{ value: adapter },
|
|
1245
|
+
children
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
function useEntityDataAdapter() {
|
|
1249
|
+
return React3.useContext(EntityDataContext);
|
|
1250
|
+
}
|
|
1251
|
+
var entityDataKeys = {
|
|
1252
|
+
all: ["entities"],
|
|
1253
|
+
lists: () => [...entityDataKeys.all, "list"],
|
|
1254
|
+
list: (entity, filters) => [...entityDataKeys.lists(), entity, filters],
|
|
1255
|
+
details: () => [...entityDataKeys.all, "detail"],
|
|
1256
|
+
detail: (entity, id) => [...entityDataKeys.details(), entity, id]
|
|
1257
|
+
};
|
|
1258
|
+
function useEntityList(entity, options = {}) {
|
|
1259
|
+
const { skip = false } = options;
|
|
1260
|
+
const adapter = React3.useContext(EntityDataContext);
|
|
1261
|
+
const adapterData = React3.useMemo(() => {
|
|
1262
|
+
if (!adapter || !entity || skip) return [];
|
|
1263
|
+
return adapter.getData(entity);
|
|
1264
|
+
}, [adapter, entity, skip, adapter?.isLoading]);
|
|
1265
|
+
const [stubData, setStubData] = React3.useState([]);
|
|
1266
|
+
const [stubLoading, setStubLoading] = React3.useState(!skip && !!entity && !adapter);
|
|
1267
|
+
const [stubError, setStubError] = React3.useState(null);
|
|
1268
|
+
React3.useEffect(() => {
|
|
1269
|
+
if (adapter || skip || !entity) {
|
|
1270
|
+
setStubLoading(false);
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
setStubLoading(true);
|
|
1274
|
+
const t = setTimeout(() => {
|
|
1275
|
+
setStubData([]);
|
|
1276
|
+
setStubLoading(false);
|
|
1277
|
+
}, 100);
|
|
1278
|
+
return () => clearTimeout(t);
|
|
1279
|
+
}, [entity, skip, adapter]);
|
|
1280
|
+
if (adapter) {
|
|
1281
|
+
return {
|
|
1282
|
+
data: adapterData,
|
|
1283
|
+
isLoading: adapter.isLoading,
|
|
1284
|
+
error: adapter.error ? new Error(adapter.error) : null,
|
|
1285
|
+
refetch: () => {
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
return { data: stubData, isLoading: stubLoading, error: stubError, refetch: () => {
|
|
1290
|
+
} };
|
|
1291
|
+
}
|
|
1292
|
+
function useEntity(entity, id) {
|
|
1293
|
+
const adapter = React3.useContext(EntityDataContext);
|
|
1294
|
+
const adapterData = React3.useMemo(() => {
|
|
1295
|
+
if (!adapter || !entity || !id) return null;
|
|
1296
|
+
return adapter.getById(entity, id) ?? null;
|
|
1297
|
+
}, [adapter, entity, id, adapter?.isLoading]);
|
|
1298
|
+
const [stubData, setStubData] = React3.useState(null);
|
|
1299
|
+
const [stubLoading, setStubLoading] = React3.useState(!!entity && !!id && !adapter);
|
|
1300
|
+
const [stubError, setStubError] = React3.useState(null);
|
|
1301
|
+
React3.useEffect(() => {
|
|
1302
|
+
if (adapter || !entity || !id) {
|
|
1303
|
+
setStubLoading(false);
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
setStubLoading(true);
|
|
1307
|
+
const t = setTimeout(() => {
|
|
1308
|
+
setStubData(null);
|
|
1309
|
+
setStubLoading(false);
|
|
1310
|
+
}, 100);
|
|
1311
|
+
return () => clearTimeout(t);
|
|
1312
|
+
}, [entity, id, adapter]);
|
|
1313
|
+
if (adapter) {
|
|
1314
|
+
return {
|
|
1315
|
+
data: adapterData,
|
|
1316
|
+
isLoading: adapter.isLoading,
|
|
1317
|
+
error: adapter.error ? new Error(adapter.error) : null
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
return { data: stubData, isLoading: stubLoading, error: stubError };
|
|
1321
|
+
}
|
|
1322
|
+
function useEntityDetail(entity, id) {
|
|
1323
|
+
const result = useEntity(entity, id);
|
|
1324
|
+
return { ...result, refetch: () => {
|
|
1325
|
+
} };
|
|
1326
|
+
}
|
|
1327
|
+
var suspenseCache = /* @__PURE__ */ new Map();
|
|
1328
|
+
function getSuspenseCacheKey(entity, type, id) {
|
|
1329
|
+
return id ? `${type}:${entity}:${id}` : `${type}:${entity}`;
|
|
1330
|
+
}
|
|
1331
|
+
function useEntityListSuspense(entity) {
|
|
1332
|
+
const adapter = React3.useContext(EntityDataContext);
|
|
1333
|
+
if (adapter) {
|
|
1334
|
+
if (adapter.isLoading) {
|
|
1335
|
+
const cacheKey2 = getSuspenseCacheKey(entity, "list");
|
|
1336
|
+
let entry2 = suspenseCache.get(cacheKey2);
|
|
1337
|
+
if (!entry2 || entry2.status === "resolved") {
|
|
1338
|
+
let resolve;
|
|
1339
|
+
const promise = new Promise((r) => {
|
|
1340
|
+
resolve = r;
|
|
1341
|
+
});
|
|
1342
|
+
entry2 = { promise, status: "pending" };
|
|
1343
|
+
suspenseCache.set(cacheKey2, entry2);
|
|
1344
|
+
const check = setInterval(() => {
|
|
1345
|
+
if (!adapter.isLoading) {
|
|
1346
|
+
clearInterval(check);
|
|
1347
|
+
entry2.status = "resolved";
|
|
1348
|
+
resolve();
|
|
1349
|
+
}
|
|
1350
|
+
}, 50);
|
|
1351
|
+
}
|
|
1352
|
+
if (entry2.status === "pending") {
|
|
1353
|
+
throw entry2.promise;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
if (adapter.error) {
|
|
1357
|
+
throw new Error(adapter.error);
|
|
1358
|
+
}
|
|
1359
|
+
return {
|
|
1360
|
+
data: adapter.getData(entity),
|
|
1361
|
+
refetch: () => {
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
const cacheKey = getSuspenseCacheKey(entity, "list");
|
|
1366
|
+
let entry = suspenseCache.get(cacheKey);
|
|
1367
|
+
if (!entry) {
|
|
1368
|
+
let resolve;
|
|
1369
|
+
const promise = new Promise((r) => {
|
|
1370
|
+
resolve = r;
|
|
1371
|
+
setTimeout(() => {
|
|
1372
|
+
entry.status = "resolved";
|
|
1373
|
+
resolve();
|
|
1374
|
+
}, 100);
|
|
1375
|
+
});
|
|
1376
|
+
entry = { promise, status: "pending" };
|
|
1377
|
+
suspenseCache.set(cacheKey, entry);
|
|
1378
|
+
}
|
|
1379
|
+
if (entry.status === "pending") {
|
|
1380
|
+
throw entry.promise;
|
|
1381
|
+
}
|
|
1382
|
+
return { data: [], refetch: () => {
|
|
1383
|
+
} };
|
|
1384
|
+
}
|
|
1385
|
+
function useEntitySuspense(entity, id) {
|
|
1386
|
+
const adapter = React3.useContext(EntityDataContext);
|
|
1387
|
+
if (adapter) {
|
|
1388
|
+
if (adapter.isLoading) {
|
|
1389
|
+
const cacheKey2 = getSuspenseCacheKey(entity, "detail", id);
|
|
1390
|
+
let entry2 = suspenseCache.get(cacheKey2);
|
|
1391
|
+
if (!entry2 || entry2.status === "resolved") {
|
|
1392
|
+
let resolve;
|
|
1393
|
+
const promise = new Promise((r) => {
|
|
1394
|
+
resolve = r;
|
|
1395
|
+
});
|
|
1396
|
+
entry2 = { promise, status: "pending" };
|
|
1397
|
+
suspenseCache.set(cacheKey2, entry2);
|
|
1398
|
+
const check = setInterval(() => {
|
|
1399
|
+
if (!adapter.isLoading) {
|
|
1400
|
+
clearInterval(check);
|
|
1401
|
+
entry2.status = "resolved";
|
|
1402
|
+
resolve();
|
|
1403
|
+
}
|
|
1404
|
+
}, 50);
|
|
1405
|
+
}
|
|
1406
|
+
if (entry2.status === "pending") {
|
|
1407
|
+
throw entry2.promise;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
if (adapter.error) {
|
|
1411
|
+
throw new Error(adapter.error);
|
|
1412
|
+
}
|
|
1413
|
+
return {
|
|
1414
|
+
data: adapter.getById(entity, id) ?? null,
|
|
1415
|
+
refetch: () => {
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
const cacheKey = getSuspenseCacheKey(entity, "detail", id);
|
|
1420
|
+
let entry = suspenseCache.get(cacheKey);
|
|
1421
|
+
if (!entry) {
|
|
1422
|
+
let resolve;
|
|
1423
|
+
const promise = new Promise((r) => {
|
|
1424
|
+
resolve = r;
|
|
1425
|
+
setTimeout(() => {
|
|
1426
|
+
entry.status = "resolved";
|
|
1427
|
+
resolve();
|
|
1428
|
+
}, 100);
|
|
1429
|
+
});
|
|
1430
|
+
entry = { promise, status: "pending" };
|
|
1431
|
+
suspenseCache.set(cacheKey, entry);
|
|
1432
|
+
}
|
|
1433
|
+
if (entry.status === "pending") {
|
|
1434
|
+
throw entry.promise;
|
|
1435
|
+
}
|
|
1436
|
+
return { data: null, refetch: () => {
|
|
1437
|
+
} };
|
|
1438
|
+
}
|
|
1439
|
+
var queryStores = /* @__PURE__ */ new Map();
|
|
1440
|
+
function getOrCreateStore(query) {
|
|
1441
|
+
if (!queryStores.has(query)) {
|
|
1442
|
+
queryStores.set(query, {
|
|
1443
|
+
search: "",
|
|
1444
|
+
filters: {},
|
|
1445
|
+
sortField: void 0,
|
|
1446
|
+
sortDirection: void 0,
|
|
1447
|
+
listeners: /* @__PURE__ */ new Set()
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
return queryStores.get(query);
|
|
1451
|
+
}
|
|
1452
|
+
function useQuerySingleton(query) {
|
|
1453
|
+
const [, forceUpdate] = React3.useState({});
|
|
1454
|
+
if (!query) {
|
|
1455
|
+
return null;
|
|
1456
|
+
}
|
|
1457
|
+
const store = React3.useMemo(() => getOrCreateStore(query), [query]);
|
|
1458
|
+
React3.useMemo(() => {
|
|
1459
|
+
const listener = () => forceUpdate({});
|
|
1460
|
+
store.listeners.add(listener);
|
|
1461
|
+
return () => {
|
|
1462
|
+
store.listeners.delete(listener);
|
|
1463
|
+
};
|
|
1464
|
+
}, [store]);
|
|
1465
|
+
const notifyListeners = React3.useCallback(() => {
|
|
1466
|
+
store.listeners.forEach((listener) => listener());
|
|
1467
|
+
}, [store]);
|
|
1468
|
+
const setSearch = React3.useCallback((value) => {
|
|
1469
|
+
store.search = value;
|
|
1470
|
+
notifyListeners();
|
|
1471
|
+
}, [store, notifyListeners]);
|
|
1472
|
+
const setFilter = React3.useCallback((key, value) => {
|
|
1473
|
+
store.filters = { ...store.filters, [key]: value };
|
|
1474
|
+
notifyListeners();
|
|
1475
|
+
}, [store, notifyListeners]);
|
|
1476
|
+
const clearFilters = React3.useCallback(() => {
|
|
1477
|
+
store.filters = {};
|
|
1478
|
+
store.search = "";
|
|
1479
|
+
notifyListeners();
|
|
1480
|
+
}, [store, notifyListeners]);
|
|
1481
|
+
const setSort = React3.useCallback((field, direction) => {
|
|
1482
|
+
store.sortField = field;
|
|
1483
|
+
store.sortDirection = direction;
|
|
1484
|
+
notifyListeners();
|
|
1485
|
+
}, [store, notifyListeners]);
|
|
1486
|
+
return {
|
|
1487
|
+
search: store.search,
|
|
1488
|
+
setSearch,
|
|
1489
|
+
filters: store.filters,
|
|
1490
|
+
setFilter,
|
|
1491
|
+
clearFilters,
|
|
1492
|
+
sortField: store.sortField,
|
|
1493
|
+
sortDirection: store.sortDirection,
|
|
1494
|
+
setSort
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
function parseQueryBinding(binding) {
|
|
1498
|
+
const cleaned = binding.startsWith("@") ? binding.slice(1) : binding;
|
|
1499
|
+
const parts = cleaned.split(".");
|
|
1500
|
+
return {
|
|
1501
|
+
query: parts[0],
|
|
1502
|
+
field: parts.length > 1 ? parts.slice(1).join(".") : void 0
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
// lib/api-client.ts
|
|
1507
|
+
var API_BASE_URL = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "/api";
|
|
1508
|
+
var ApiError = class extends Error {
|
|
1509
|
+
constructor(status, statusText, message) {
|
|
1510
|
+
super(message || `API Error: ${status} ${statusText}`);
|
|
1511
|
+
this.status = status;
|
|
1512
|
+
this.statusText = statusText;
|
|
1513
|
+
this.name = "ApiError";
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
async function handleResponse(response) {
|
|
1517
|
+
if (!response.ok) {
|
|
1518
|
+
let message;
|
|
1519
|
+
try {
|
|
1520
|
+
const errorData = await response.json();
|
|
1521
|
+
message = errorData.message || errorData.error;
|
|
1522
|
+
} catch {
|
|
1523
|
+
}
|
|
1524
|
+
throw new ApiError(response.status, response.statusText, message);
|
|
1525
|
+
}
|
|
1526
|
+
const text = await response.text();
|
|
1527
|
+
if (!text) {
|
|
1528
|
+
return void 0;
|
|
1529
|
+
}
|
|
1530
|
+
return JSON.parse(text);
|
|
1531
|
+
}
|
|
1532
|
+
function getHeaders() {
|
|
1533
|
+
const headers = {
|
|
1534
|
+
"Content-Type": "application/json"
|
|
1535
|
+
};
|
|
1536
|
+
const token = typeof localStorage !== "undefined" ? localStorage.getItem("authToken") : null;
|
|
1537
|
+
if (token) {
|
|
1538
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
1539
|
+
}
|
|
1540
|
+
return headers;
|
|
1541
|
+
}
|
|
1542
|
+
var apiClient = {
|
|
1543
|
+
/**
|
|
1544
|
+
* GET request
|
|
1545
|
+
*/
|
|
1546
|
+
async get(endpoint) {
|
|
1547
|
+
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
|
1548
|
+
method: "GET",
|
|
1549
|
+
headers: getHeaders()
|
|
1550
|
+
});
|
|
1551
|
+
return handleResponse(response);
|
|
1552
|
+
},
|
|
1553
|
+
/**
|
|
1554
|
+
* POST request
|
|
1555
|
+
*/
|
|
1556
|
+
async post(endpoint, data) {
|
|
1557
|
+
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
|
1558
|
+
method: "POST",
|
|
1559
|
+
headers: getHeaders(),
|
|
1560
|
+
body: data ? JSON.stringify(data) : void 0
|
|
1561
|
+
});
|
|
1562
|
+
return handleResponse(response);
|
|
1563
|
+
},
|
|
1564
|
+
/**
|
|
1565
|
+
* PUT request
|
|
1566
|
+
*/
|
|
1567
|
+
async put(endpoint, data) {
|
|
1568
|
+
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
|
1569
|
+
method: "PUT",
|
|
1570
|
+
headers: getHeaders(),
|
|
1571
|
+
body: data ? JSON.stringify(data) : void 0
|
|
1572
|
+
});
|
|
1573
|
+
return handleResponse(response);
|
|
1574
|
+
},
|
|
1575
|
+
/**
|
|
1576
|
+
* PATCH request
|
|
1577
|
+
*/
|
|
1578
|
+
async patch(endpoint, data) {
|
|
1579
|
+
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
|
1580
|
+
method: "PATCH",
|
|
1581
|
+
headers: getHeaders(),
|
|
1582
|
+
body: data ? JSON.stringify(data) : void 0
|
|
1583
|
+
});
|
|
1584
|
+
return handleResponse(response);
|
|
1585
|
+
},
|
|
1586
|
+
/**
|
|
1587
|
+
* DELETE request
|
|
1588
|
+
*/
|
|
1589
|
+
async delete(endpoint) {
|
|
1590
|
+
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
|
1591
|
+
method: "DELETE",
|
|
1592
|
+
headers: getHeaders()
|
|
1593
|
+
});
|
|
1594
|
+
return handleResponse(response);
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
var ENTITY_EVENTS = {
|
|
1598
|
+
CREATE: "ENTITY_CREATE",
|
|
1599
|
+
UPDATE: "ENTITY_UPDATE",
|
|
1600
|
+
DELETE: "ENTITY_DELETE"
|
|
1601
|
+
};
|
|
1602
|
+
async function sendOrbitalEvent(orbitalName, eventPayload) {
|
|
1603
|
+
const response = await apiClient.post(
|
|
1604
|
+
`/orbitals/${orbitalName}/events`,
|
|
1605
|
+
eventPayload
|
|
1606
|
+
);
|
|
1607
|
+
return response;
|
|
1608
|
+
}
|
|
1609
|
+
function useOrbitalMutations(entityName, orbitalName, options) {
|
|
1610
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1611
|
+
const events = {
|
|
1612
|
+
create: options?.events?.create || ENTITY_EVENTS.CREATE,
|
|
1613
|
+
update: options?.events?.update || ENTITY_EVENTS.UPDATE,
|
|
1614
|
+
delete: options?.events?.delete || ENTITY_EVENTS.DELETE
|
|
1615
|
+
};
|
|
1616
|
+
const log = (message, data) => {
|
|
1617
|
+
if (options?.debug) {
|
|
1618
|
+
console.log(`[useOrbitalMutations:${orbitalName}] ${message}`, data ?? "");
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
const createMutation = reactQuery.useMutation({
|
|
1622
|
+
mutationFn: async (data) => {
|
|
1623
|
+
log("Creating entity", data);
|
|
1624
|
+
return sendOrbitalEvent(orbitalName, {
|
|
1625
|
+
event: events.create,
|
|
1626
|
+
payload: { data, entityType: entityName }
|
|
1627
|
+
});
|
|
1628
|
+
},
|
|
1629
|
+
onSuccess: (response) => {
|
|
1630
|
+
log("Create succeeded", response);
|
|
1631
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1632
|
+
},
|
|
1633
|
+
onError: (error) => {
|
|
1634
|
+
console.error(`[useOrbitalMutations] Create failed:`, error);
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
const updateMutation = reactQuery.useMutation({
|
|
1638
|
+
mutationFn: async ({
|
|
1639
|
+
id,
|
|
1640
|
+
data
|
|
1641
|
+
}) => {
|
|
1642
|
+
log(`Updating entity ${id}`, data);
|
|
1643
|
+
return sendOrbitalEvent(orbitalName, {
|
|
1644
|
+
event: events.update,
|
|
1645
|
+
entityId: id,
|
|
1646
|
+
payload: { data, entityType: entityName }
|
|
1647
|
+
});
|
|
1648
|
+
},
|
|
1649
|
+
onSuccess: (response, variables) => {
|
|
1650
|
+
log("Update succeeded", response);
|
|
1651
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1652
|
+
queryClient.invalidateQueries({
|
|
1653
|
+
queryKey: entityDataKeys.detail(entityName, variables.id)
|
|
1654
|
+
});
|
|
1655
|
+
},
|
|
1656
|
+
onError: (error) => {
|
|
1657
|
+
console.error(`[useOrbitalMutations] Update failed:`, error);
|
|
1658
|
+
}
|
|
1659
|
+
});
|
|
1660
|
+
const deleteMutation = reactQuery.useMutation({
|
|
1661
|
+
mutationFn: async (id) => {
|
|
1662
|
+
log(`Deleting entity ${id}`);
|
|
1663
|
+
return sendOrbitalEvent(orbitalName, {
|
|
1664
|
+
event: events.delete,
|
|
1665
|
+
entityId: id,
|
|
1666
|
+
payload: { entityType: entityName }
|
|
1667
|
+
});
|
|
1668
|
+
},
|
|
1669
|
+
onSuccess: (response, id) => {
|
|
1670
|
+
log("Delete succeeded", response);
|
|
1671
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1672
|
+
queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
|
|
1673
|
+
},
|
|
1674
|
+
onError: (error) => {
|
|
1675
|
+
console.error(`[useOrbitalMutations] Delete failed:`, error);
|
|
1676
|
+
}
|
|
1677
|
+
});
|
|
1678
|
+
return {
|
|
1679
|
+
// Async functions
|
|
1680
|
+
createEntity: async (data) => {
|
|
1681
|
+
return createMutation.mutateAsync(data);
|
|
1682
|
+
},
|
|
1683
|
+
updateEntity: async (id, data) => {
|
|
1684
|
+
if (!id) {
|
|
1685
|
+
console.warn("[useOrbitalMutations] Cannot update without ID");
|
|
1686
|
+
return;
|
|
1687
|
+
}
|
|
1688
|
+
return updateMutation.mutateAsync({ id, data });
|
|
1689
|
+
},
|
|
1690
|
+
deleteEntity: async (id) => {
|
|
1691
|
+
if (!id) {
|
|
1692
|
+
console.warn("[useOrbitalMutations] Cannot delete without ID");
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
return deleteMutation.mutateAsync(id);
|
|
1696
|
+
},
|
|
1697
|
+
// Mutation objects for fine-grained control
|
|
1698
|
+
createMutation,
|
|
1699
|
+
updateMutation,
|
|
1700
|
+
deleteMutation,
|
|
1701
|
+
// Aggregate states
|
|
1702
|
+
isCreating: createMutation.isPending,
|
|
1703
|
+
isUpdating: updateMutation.isPending,
|
|
1704
|
+
isDeleting: deleteMutation.isPending,
|
|
1705
|
+
isMutating: createMutation.isPending || updateMutation.isPending || deleteMutation.isPending,
|
|
1706
|
+
// Errors
|
|
1707
|
+
createError: createMutation.error,
|
|
1708
|
+
updateError: updateMutation.error,
|
|
1709
|
+
deleteError: deleteMutation.error
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
function useSendOrbitalEvent(orbitalName) {
|
|
1713
|
+
const mutation = reactQuery.useMutation({
|
|
1714
|
+
mutationFn: async (payload) => {
|
|
1715
|
+
return sendOrbitalEvent(orbitalName, payload);
|
|
1716
|
+
}
|
|
1717
|
+
});
|
|
1718
|
+
return {
|
|
1719
|
+
sendEvent: async (event, payload, entityId) => {
|
|
1720
|
+
return mutation.mutateAsync({ event, payload, entityId });
|
|
1721
|
+
},
|
|
1722
|
+
isPending: mutation.isPending,
|
|
1723
|
+
error: mutation.error,
|
|
1724
|
+
data: mutation.data
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
// hooks/useEntityMutations.ts
|
|
1729
|
+
function entityToCollection(entityName) {
|
|
1730
|
+
return entityName.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase() + "-list";
|
|
1731
|
+
}
|
|
1732
|
+
function useCreateEntity(entityName) {
|
|
1733
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1734
|
+
const collection = entityToCollection(entityName);
|
|
1735
|
+
return reactQuery.useMutation({
|
|
1736
|
+
mutationFn: async (data) => {
|
|
1737
|
+
console.log(`[useCreateEntity] Creating ${entityName}:`, data);
|
|
1738
|
+
const response = await apiClient.post(
|
|
1739
|
+
`/${collection}`,
|
|
1740
|
+
data
|
|
1741
|
+
);
|
|
1742
|
+
return response.data;
|
|
1743
|
+
},
|
|
1744
|
+
onSuccess: () => {
|
|
1745
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1746
|
+
},
|
|
1747
|
+
onError: (error) => {
|
|
1748
|
+
console.error(`[useCreateEntity] Failed to create ${entityName}:`, error);
|
|
1749
|
+
}
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
function useUpdateEntity(entityName) {
|
|
1753
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1754
|
+
const collection = entityToCollection(entityName);
|
|
1755
|
+
return reactQuery.useMutation({
|
|
1756
|
+
mutationFn: async ({ id, data }) => {
|
|
1757
|
+
console.log(`[useUpdateEntity] Updating ${entityName} ${id}:`, data);
|
|
1758
|
+
const response = await apiClient.patch(
|
|
1759
|
+
`/${collection}/${id}`,
|
|
1760
|
+
data
|
|
1761
|
+
);
|
|
1762
|
+
return response.data;
|
|
1763
|
+
},
|
|
1764
|
+
onSuccess: (_, variables) => {
|
|
1765
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1766
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.detail(entityName, variables.id) });
|
|
1767
|
+
},
|
|
1768
|
+
onError: (error) => {
|
|
1769
|
+
console.error(`[useUpdateEntity] Failed to update ${entityName}:`, error);
|
|
1770
|
+
}
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
function useDeleteEntity(entityName) {
|
|
1774
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1775
|
+
const collection = entityToCollection(entityName);
|
|
1776
|
+
return reactQuery.useMutation({
|
|
1777
|
+
mutationFn: async (id) => {
|
|
1778
|
+
console.log(`[useDeleteEntity] Deleting ${entityName} ${id}`);
|
|
1779
|
+
await apiClient.delete(`/${collection}/${id}`);
|
|
1780
|
+
return { id };
|
|
1781
|
+
},
|
|
1782
|
+
onSuccess: (_, id) => {
|
|
1783
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1784
|
+
queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
|
|
1785
|
+
},
|
|
1786
|
+
onError: (error) => {
|
|
1787
|
+
console.error(`[useDeleteEntity] Failed to delete ${entityName}:`, error);
|
|
1788
|
+
}
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
async function sendOrbitalMutation(orbitalName, event, entityId, payload) {
|
|
1792
|
+
const response = await apiClient.post(
|
|
1793
|
+
`/orbitals/${orbitalName}/events`,
|
|
1794
|
+
{ event, entityId, payload }
|
|
1795
|
+
);
|
|
1796
|
+
return response;
|
|
1797
|
+
}
|
|
1798
|
+
function useEntityMutations(entityName, options) {
|
|
1799
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1800
|
+
const useOrbitalRoute = !!options?.orbitalName;
|
|
1801
|
+
const events = {
|
|
1802
|
+
create: options?.events?.create || ENTITY_EVENTS.CREATE,
|
|
1803
|
+
update: options?.events?.update || ENTITY_EVENTS.UPDATE,
|
|
1804
|
+
delete: options?.events?.delete || ENTITY_EVENTS.DELETE
|
|
1805
|
+
};
|
|
1806
|
+
const createMutation = useCreateEntity(entityName);
|
|
1807
|
+
const updateMutation = useUpdateEntity(entityName);
|
|
1808
|
+
const deleteMutation = useDeleteEntity(entityName);
|
|
1809
|
+
const orbitalCreateMutation = reactQuery.useMutation({
|
|
1810
|
+
mutationFn: async (data) => {
|
|
1811
|
+
return sendOrbitalMutation(options.orbitalName, events.create, void 0, {
|
|
1812
|
+
data,
|
|
1813
|
+
entityType: entityName
|
|
1814
|
+
});
|
|
1815
|
+
},
|
|
1816
|
+
onSuccess: () => {
|
|
1817
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1818
|
+
}
|
|
1819
|
+
});
|
|
1820
|
+
const orbitalUpdateMutation = reactQuery.useMutation({
|
|
1821
|
+
mutationFn: async ({ id, data }) => {
|
|
1822
|
+
return sendOrbitalMutation(options.orbitalName, events.update, id, {
|
|
1823
|
+
data,
|
|
1824
|
+
entityType: entityName
|
|
1825
|
+
});
|
|
1826
|
+
},
|
|
1827
|
+
onSuccess: (_, variables) => {
|
|
1828
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1829
|
+
queryClient.invalidateQueries({
|
|
1830
|
+
queryKey: entityDataKeys.detail(entityName, variables.id)
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1834
|
+
const orbitalDeleteMutation = reactQuery.useMutation({
|
|
1835
|
+
mutationFn: async (id) => {
|
|
1836
|
+
return sendOrbitalMutation(options.orbitalName, events.delete, id, {
|
|
1837
|
+
entityType: entityName
|
|
1838
|
+
});
|
|
1839
|
+
},
|
|
1840
|
+
onSuccess: (_, id) => {
|
|
1841
|
+
queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
|
|
1842
|
+
queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
const activeMutations = {
|
|
1846
|
+
create: useOrbitalRoute ? orbitalCreateMutation : createMutation,
|
|
1847
|
+
update: useOrbitalRoute ? orbitalUpdateMutation : updateMutation,
|
|
1848
|
+
delete: useOrbitalRoute ? orbitalDeleteMutation : deleteMutation
|
|
1849
|
+
};
|
|
1850
|
+
return {
|
|
1851
|
+
// Async functions that can be called directly
|
|
1852
|
+
// Accepts either (data) or (entityName, data) for compiler compatibility
|
|
1853
|
+
createEntity: async (entityOrData, data) => {
|
|
1854
|
+
const actualData = typeof entityOrData === "string" ? data : entityOrData;
|
|
1855
|
+
if (!actualData) {
|
|
1856
|
+
console.warn("[useEntityMutations] Cannot create entity without data");
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
return activeMutations.create.mutateAsync(actualData);
|
|
1860
|
+
},
|
|
1861
|
+
updateEntity: async (id, data) => {
|
|
1862
|
+
if (!id) {
|
|
1863
|
+
console.warn("[useEntityMutations] Cannot update entity without ID");
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
return activeMutations.update.mutateAsync({ id, data });
|
|
1867
|
+
},
|
|
1868
|
+
deleteEntity: async (id) => {
|
|
1869
|
+
if (!id) {
|
|
1870
|
+
console.warn("[useEntityMutations] Cannot delete entity without ID");
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
return activeMutations.delete.mutateAsync(id);
|
|
1874
|
+
},
|
|
1875
|
+
// Mutation states for UI feedback
|
|
1876
|
+
isCreating: activeMutations.create.isPending,
|
|
1877
|
+
isUpdating: activeMutations.update.isPending,
|
|
1878
|
+
isDeleting: activeMutations.delete.isPending,
|
|
1879
|
+
createError: activeMutations.create.error,
|
|
1880
|
+
updateError: activeMutations.update.error,
|
|
1881
|
+
deleteError: activeMutations.delete.error
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
// stores/entityStore.ts
|
|
1886
|
+
var entities = /* @__PURE__ */ new Map();
|
|
1887
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
1888
|
+
var idCounter2 = 0;
|
|
1889
|
+
function subscribe(listener) {
|
|
1890
|
+
listeners.add(listener);
|
|
1891
|
+
return () => listeners.delete(listener);
|
|
1892
|
+
}
|
|
1893
|
+
function notify() {
|
|
1894
|
+
listeners.forEach((listener) => listener());
|
|
1895
|
+
}
|
|
1896
|
+
function getEntity(id) {
|
|
1897
|
+
return entities.get(id);
|
|
1898
|
+
}
|
|
1899
|
+
function getByType(type) {
|
|
1900
|
+
const types = Array.isArray(type) ? type : [type];
|
|
1901
|
+
return [...entities.values()].filter((e) => types.includes(e.type));
|
|
1902
|
+
}
|
|
1903
|
+
function getAllEntities() {
|
|
1904
|
+
return [...entities.values()];
|
|
1905
|
+
}
|
|
1906
|
+
function getSingleton(type) {
|
|
1907
|
+
return [...entities.values()].find((e) => e.type === type);
|
|
1908
|
+
}
|
|
1909
|
+
function spawnEntity(config) {
|
|
1910
|
+
const id = config.id ?? `entity_${++idCounter2}`;
|
|
1911
|
+
const entity = { ...config, id };
|
|
1912
|
+
entities = new Map(entities);
|
|
1913
|
+
entities.set(id, entity);
|
|
1914
|
+
notify();
|
|
1915
|
+
return id;
|
|
1916
|
+
}
|
|
1917
|
+
function updateEntity(id, updates) {
|
|
1918
|
+
const entity = entities.get(id);
|
|
1919
|
+
if (entity) {
|
|
1920
|
+
entities = new Map(entities);
|
|
1921
|
+
entities.set(id, { ...entity, ...updates });
|
|
1922
|
+
notify();
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
function updateSingleton(type, updates) {
|
|
1926
|
+
const entity = getSingleton(type);
|
|
1927
|
+
if (entity) {
|
|
1928
|
+
updateEntity(entity.id, updates);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
function removeEntity(id) {
|
|
1932
|
+
if (entities.has(id)) {
|
|
1933
|
+
entities = new Map(entities);
|
|
1934
|
+
entities.delete(id);
|
|
1935
|
+
notify();
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
function clearEntities() {
|
|
1939
|
+
entities = /* @__PURE__ */ new Map();
|
|
1940
|
+
notify();
|
|
1941
|
+
}
|
|
1942
|
+
function getSnapshot() {
|
|
1943
|
+
return entities;
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
// hooks/useEntities.ts
|
|
1947
|
+
function useEntities() {
|
|
1948
|
+
const entities2 = React3.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1949
|
+
return {
|
|
1950
|
+
entities: entities2,
|
|
1951
|
+
getEntity,
|
|
1952
|
+
getByType,
|
|
1953
|
+
getAllEntities,
|
|
1954
|
+
getSingleton,
|
|
1955
|
+
spawnEntity,
|
|
1956
|
+
updateEntity,
|
|
1957
|
+
updateSingleton,
|
|
1958
|
+
removeEntity,
|
|
1959
|
+
clearEntities
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
function useEntity2(id) {
|
|
1963
|
+
const entities2 = React3.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1964
|
+
return entities2.get(id);
|
|
1965
|
+
}
|
|
1966
|
+
function useEntitiesByType(type) {
|
|
1967
|
+
const entities2 = React3.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1968
|
+
return [...entities2.values()].filter((e) => e.type === type);
|
|
1969
|
+
}
|
|
1970
|
+
function useSingletonEntity(type) {
|
|
1971
|
+
const entities2 = React3.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1972
|
+
return [...entities2.values()].find((e) => e.type === type);
|
|
1973
|
+
}
|
|
1974
|
+
function usePlayer() {
|
|
1975
|
+
const player = useSingletonEntity("Player");
|
|
1976
|
+
const update = React3.useCallback((updates) => {
|
|
1977
|
+
if (player) updateEntity(player.id, updates);
|
|
1978
|
+
}, [player?.id]);
|
|
1979
|
+
return { player, updatePlayer: update };
|
|
1980
|
+
}
|
|
1981
|
+
function usePhysics() {
|
|
1982
|
+
const physics = useSingletonEntity("Physics");
|
|
1983
|
+
const update = React3.useCallback((updates) => {
|
|
1984
|
+
if (physics) updateEntity(physics.id, updates);
|
|
1985
|
+
}, [physics?.id]);
|
|
1986
|
+
return { physics, updatePhysics: update };
|
|
1987
|
+
}
|
|
1988
|
+
function useInput() {
|
|
1989
|
+
const input = useSingletonEntity("Input");
|
|
1990
|
+
const update = React3.useCallback((updates) => {
|
|
1991
|
+
if (input) updateEntity(input.id, updates);
|
|
1992
|
+
}, [input?.id]);
|
|
1993
|
+
return { input, updateInput: update };
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
// locales/en.json
|
|
1997
|
+
var en_default = {
|
|
1998
|
+
$meta: { locale: "en", direction: "ltr" },
|
|
1999
|
+
"common.save": "Save",
|
|
2000
|
+
"common.cancel": "Cancel",
|
|
2001
|
+
"common.delete": "Delete",
|
|
2002
|
+
"common.close": "Close",
|
|
2003
|
+
"common.confirm": "Are you sure?",
|
|
2004
|
+
"common.create": "Create",
|
|
2005
|
+
"common.edit": "Edit",
|
|
2006
|
+
"common.view": "View",
|
|
2007
|
+
"common.add": "Add",
|
|
2008
|
+
"common.remove": "Remove",
|
|
2009
|
+
"common.search": "Search...",
|
|
2010
|
+
"common.filter": "Filter",
|
|
2011
|
+
"common.actions": "Actions",
|
|
2012
|
+
"common.yes": "Yes",
|
|
2013
|
+
"common.no": "No",
|
|
2014
|
+
"common.selected": "selected",
|
|
2015
|
+
"common.ok": "OK",
|
|
2016
|
+
"common.done": "Done",
|
|
2017
|
+
"common.apply": "Apply",
|
|
2018
|
+
"common.reset": "Reset",
|
|
2019
|
+
"common.refresh": "Refresh",
|
|
2020
|
+
"common.export": "Export",
|
|
2021
|
+
"common.import": "Import",
|
|
2022
|
+
"common.copy": "Copy",
|
|
2023
|
+
"common.settings": "Settings",
|
|
2024
|
+
"nav.previous": "Previous",
|
|
2025
|
+
"nav.next": "Next",
|
|
2026
|
+
"nav.back": "Back",
|
|
2027
|
+
"nav.home": "Home",
|
|
2028
|
+
"form.submit": "Submit",
|
|
2029
|
+
"form.saving": "Saving...",
|
|
2030
|
+
"form.required": "This field is required",
|
|
2031
|
+
"form.invalidEmail": "Enter a valid email address",
|
|
2032
|
+
"form.selectPlaceholder": "Select {{label}}...",
|
|
2033
|
+
"form.searchPlaceholder": "Search {{entity}}...",
|
|
2034
|
+
"table.empty.title": "No items found",
|
|
2035
|
+
"table.empty.description": "No items to display.",
|
|
2036
|
+
"table.search.placeholder": "Search...",
|
|
2037
|
+
"table.pagination.showing": "Showing {{start}} to {{end}} of {{total}} results",
|
|
2038
|
+
"table.pagination.page": "Page {{page}} of {{totalPages}}",
|
|
2039
|
+
"table.bulk.selected": "{{count}} selected",
|
|
2040
|
+
"table.loading": "Loading...",
|
|
2041
|
+
"status.loading": "Loading...",
|
|
2042
|
+
"status.scheduled": "Scheduled",
|
|
2043
|
+
"status.inProgress": "In Progress",
|
|
2044
|
+
"status.completed": "Completed",
|
|
2045
|
+
"status.cancelled": "Cancelled",
|
|
2046
|
+
"status.pending": "Pending",
|
|
2047
|
+
"status.active": "Active",
|
|
2048
|
+
"status.inactive": "Inactive",
|
|
2049
|
+
"status.draft": "Draft",
|
|
2050
|
+
"status.archived": "Archived",
|
|
2051
|
+
"error.generic": "Something went wrong",
|
|
2052
|
+
"error.retry": "Try again",
|
|
2053
|
+
"error.notFound": "Not found",
|
|
2054
|
+
"error.loadFailed": "Failed to load: {{message}}",
|
|
2055
|
+
"error.configMissing": "Configuration not found for: {{id}}",
|
|
2056
|
+
"common.loading": "Loading...",
|
|
2057
|
+
"common.showMore": "Show More",
|
|
2058
|
+
"common.showLess": "Show Less",
|
|
2059
|
+
"common.noResults": "No results found",
|
|
2060
|
+
"common.saveChanges": "Save Changes",
|
|
2061
|
+
"common.retry": "Retry",
|
|
2062
|
+
"common.open": "Open",
|
|
2063
|
+
"common.back": "Back",
|
|
2064
|
+
"empty.noItems": "No items",
|
|
2065
|
+
"empty.noData": "No data available",
|
|
2066
|
+
"empty.noItemsYet": "No items yet",
|
|
2067
|
+
"empty.noItemsAdded": "No items added yet",
|
|
2068
|
+
"empty.noOptionsFound": "No options found",
|
|
2069
|
+
"list.addItemPlaceholder": "Add new item...",
|
|
2070
|
+
"error.occurred": "An error occurred",
|
|
2071
|
+
"error.failedToLoad": "Failed to load data",
|
|
2072
|
+
"wizard.back": "Back",
|
|
2073
|
+
"wizard.next": "Next",
|
|
2074
|
+
"wizard.complete": "Complete",
|
|
2075
|
+
"wizard.stepOf": "Step {{current}} of {{total}}",
|
|
2076
|
+
"pagination.previous": "Previous",
|
|
2077
|
+
"pagination.next": "Next",
|
|
2078
|
+
"pagination.total": "Total:",
|
|
2079
|
+
"pagination.show": "Show:",
|
|
2080
|
+
"pagination.goTo": "Go to:",
|
|
2081
|
+
"pagination.go": "Go",
|
|
2082
|
+
"auth.signIn": "Sign in",
|
|
2083
|
+
"auth.signOut": "Sign out",
|
|
2084
|
+
"dialog.confirm": "Confirm",
|
|
2085
|
+
"dialog.cancel": "Cancel",
|
|
2086
|
+
"dialog.loading": "Loading...",
|
|
2087
|
+
"dialog.delete.title": "Delete {{item}}?",
|
|
2088
|
+
"dialog.delete.message": "This action cannot be undone.",
|
|
2089
|
+
"trait.availableActions": "Available Actions",
|
|
2090
|
+
"trait.transitions": "Transitions",
|
|
2091
|
+
"trait.availableNow": "Available now",
|
|
2092
|
+
"book.startReading": "Start Reading",
|
|
2093
|
+
"book.tableOfContents": "Table of Contents",
|
|
2094
|
+
"book.partNumber": "Part {{number}}",
|
|
2095
|
+
"book.print": "Print",
|
|
2096
|
+
"book.previousPage": "Previous page",
|
|
2097
|
+
"book.nextPage": "Next page",
|
|
2098
|
+
"quiz.showAnswer": "Show answer",
|
|
2099
|
+
"quiz.hideAnswer": "Hide answer"
|
|
2100
|
+
};
|
|
2101
|
+
|
|
2102
|
+
// hooks/useTranslate.ts
|
|
2103
|
+
var { $meta: _meta, ...coreMessages } = en_default;
|
|
2104
|
+
var coreLocale = coreMessages;
|
|
2105
|
+
var I18nContext = React3.createContext({
|
|
2106
|
+
locale: "en",
|
|
2107
|
+
direction: "ltr",
|
|
2108
|
+
t: (key) => coreLocale[key] ?? key
|
|
2109
|
+
// core locale fallback
|
|
2110
|
+
});
|
|
2111
|
+
I18nContext.displayName = "I18nContext";
|
|
2112
|
+
var I18nProvider = I18nContext.Provider;
|
|
2113
|
+
function useTranslate() {
|
|
2114
|
+
return React3.useContext(I18nContext);
|
|
2115
|
+
}
|
|
2116
|
+
function createTranslate(messages) {
|
|
2117
|
+
return (key, params) => {
|
|
2118
|
+
let msg = messages[key] ?? coreLocale[key] ?? key;
|
|
2119
|
+
if (params) {
|
|
2120
|
+
for (const [k, v] of Object.entries(params)) {
|
|
2121
|
+
msg = msg.split(`{{${k}}}`).join(String(v));
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
return msg;
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
function useResolvedEntity(entity, data) {
|
|
2128
|
+
const shouldFetch = !data && !!entity;
|
|
2129
|
+
const fetched = useEntityList(entity, { skip: !shouldFetch });
|
|
2130
|
+
return React3.useMemo(() => {
|
|
2131
|
+
if (data) {
|
|
2132
|
+
return {
|
|
2133
|
+
data,
|
|
2134
|
+
isLocal: true,
|
|
2135
|
+
isLoading: false,
|
|
2136
|
+
error: null
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
return {
|
|
2140
|
+
data: fetched.data,
|
|
2141
|
+
isLocal: false,
|
|
2142
|
+
isLoading: fetched.isLoading,
|
|
2143
|
+
error: fetched.error
|
|
2144
|
+
};
|
|
2145
|
+
}, [data, fetched.data, fetched.isLoading, fetched.error]);
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
// hooks/useAuthContext.ts
|
|
2149
|
+
function useAuthContext() {
|
|
2150
|
+
return {
|
|
2151
|
+
user: null,
|
|
2152
|
+
loading: false,
|
|
2153
|
+
signIn: void 0,
|
|
2154
|
+
signOut: void 0
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
function useSwipeGesture(callbacks, options = {}) {
|
|
2158
|
+
const { threshold = 50, velocityThreshold = 0.3, preventDefault = false } = options;
|
|
2159
|
+
const startX = React3.useRef(0);
|
|
2160
|
+
const startY = React3.useRef(0);
|
|
2161
|
+
const startTime = React3.useRef(0);
|
|
2162
|
+
const currentX = React3.useRef(0);
|
|
2163
|
+
const tracking = React3.useRef(false);
|
|
2164
|
+
const offsetXRef = React3.useRef(0);
|
|
2165
|
+
const isSwipingRef = React3.useRef(false);
|
|
2166
|
+
const onPointerDown = React3.useCallback((e) => {
|
|
2167
|
+
startX.current = e.clientX;
|
|
2168
|
+
startY.current = e.clientY;
|
|
2169
|
+
currentX.current = e.clientX;
|
|
2170
|
+
startTime.current = Date.now();
|
|
2171
|
+
tracking.current = true;
|
|
2172
|
+
isSwipingRef.current = false;
|
|
2173
|
+
offsetXRef.current = 0;
|
|
2174
|
+
e.target.setPointerCapture?.(e.pointerId);
|
|
2175
|
+
}, []);
|
|
2176
|
+
const onPointerMove = React3.useCallback((e) => {
|
|
2177
|
+
if (!tracking.current) return;
|
|
2178
|
+
if (preventDefault) e.preventDefault();
|
|
2179
|
+
currentX.current = e.clientX;
|
|
2180
|
+
const dx = e.clientX - startX.current;
|
|
2181
|
+
const dy = e.clientY - startY.current;
|
|
2182
|
+
if (Math.abs(dx) > 10 && Math.abs(dx) > Math.abs(dy)) {
|
|
2183
|
+
isSwipingRef.current = true;
|
|
2184
|
+
offsetXRef.current = dx;
|
|
2185
|
+
}
|
|
2186
|
+
}, [preventDefault]);
|
|
2187
|
+
const onPointerUp = React3.useCallback((e) => {
|
|
2188
|
+
if (!tracking.current) return;
|
|
2189
|
+
tracking.current = false;
|
|
2190
|
+
const dx = e.clientX - startX.current;
|
|
2191
|
+
const dy = e.clientY - startY.current;
|
|
2192
|
+
const elapsed = Date.now() - startTime.current;
|
|
2193
|
+
const velocity = Math.abs(dx) / Math.max(elapsed, 1);
|
|
2194
|
+
offsetXRef.current = 0;
|
|
2195
|
+
isSwipingRef.current = false;
|
|
2196
|
+
if (Math.abs(dx) < threshold && velocity < velocityThreshold) return;
|
|
2197
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
2198
|
+
if (dx < -threshold) callbacks.onSwipeLeft?.();
|
|
2199
|
+
else if (dx > threshold) callbacks.onSwipeRight?.();
|
|
2200
|
+
} else {
|
|
2201
|
+
if (dy < -threshold) callbacks.onSwipeUp?.();
|
|
2202
|
+
else if (dy > threshold) callbacks.onSwipeDown?.();
|
|
2203
|
+
}
|
|
2204
|
+
}, [threshold, velocityThreshold, callbacks]);
|
|
2205
|
+
const onPointerCancel = React3.useCallback(() => {
|
|
2206
|
+
tracking.current = false;
|
|
2207
|
+
offsetXRef.current = 0;
|
|
2208
|
+
isSwipingRef.current = false;
|
|
2209
|
+
}, []);
|
|
2210
|
+
return {
|
|
2211
|
+
onPointerDown,
|
|
2212
|
+
onPointerMove,
|
|
2213
|
+
onPointerUp,
|
|
2214
|
+
onPointerCancel,
|
|
2215
|
+
offsetX: offsetXRef.current,
|
|
2216
|
+
isSwiping: isSwipingRef.current
|
|
2217
|
+
};
|
|
2218
|
+
}
|
|
2219
|
+
function useLongPress(onLongPress, options = {}) {
|
|
2220
|
+
const { duration = 500, moveThreshold = 10 } = options;
|
|
2221
|
+
const timerRef = React3.useRef(null);
|
|
2222
|
+
const startPos = React3.useRef({ x: 0, y: 0 });
|
|
2223
|
+
const isPressedRef = React3.useRef(false);
|
|
2224
|
+
const firedRef = React3.useRef(false);
|
|
2225
|
+
const cancel = React3.useCallback(() => {
|
|
2226
|
+
if (timerRef.current) {
|
|
2227
|
+
clearTimeout(timerRef.current);
|
|
2228
|
+
timerRef.current = null;
|
|
2229
|
+
}
|
|
2230
|
+
isPressedRef.current = false;
|
|
2231
|
+
}, []);
|
|
2232
|
+
const onPointerDown = React3.useCallback((e) => {
|
|
2233
|
+
firedRef.current = false;
|
|
2234
|
+
startPos.current = { x: e.clientX, y: e.clientY };
|
|
2235
|
+
isPressedRef.current = true;
|
|
2236
|
+
timerRef.current = setTimeout(() => {
|
|
2237
|
+
firedRef.current = true;
|
|
2238
|
+
isPressedRef.current = false;
|
|
2239
|
+
onLongPress();
|
|
2240
|
+
}, duration);
|
|
2241
|
+
}, [duration, onLongPress]);
|
|
2242
|
+
const onPointerMove = React3.useCallback((e) => {
|
|
2243
|
+
if (!isPressedRef.current) return;
|
|
2244
|
+
const dx = e.clientX - startPos.current.x;
|
|
2245
|
+
const dy = e.clientY - startPos.current.y;
|
|
2246
|
+
if (Math.sqrt(dx * dx + dy * dy) > moveThreshold) {
|
|
2247
|
+
cancel();
|
|
2248
|
+
}
|
|
2249
|
+
}, [moveThreshold, cancel]);
|
|
2250
|
+
const onPointerUp = React3.useCallback(() => {
|
|
2251
|
+
cancel();
|
|
2252
|
+
}, [cancel]);
|
|
2253
|
+
const onPointerCancel = React3.useCallback(() => {
|
|
2254
|
+
cancel();
|
|
2255
|
+
}, [cancel]);
|
|
2256
|
+
return {
|
|
2257
|
+
onPointerDown,
|
|
2258
|
+
onPointerMove,
|
|
2259
|
+
onPointerUp,
|
|
2260
|
+
onPointerCancel,
|
|
2261
|
+
isPressed: isPressedRef.current
|
|
2262
|
+
};
|
|
2263
|
+
}
|
|
2264
|
+
function useDragReorder(initialItems, onReorder) {
|
|
2265
|
+
const [items, setItems] = React3.useState(initialItems);
|
|
2266
|
+
const [dragIndex, setDragIndex] = React3.useState(-1);
|
|
2267
|
+
const [dragOverIndex, setDragOverIndex] = React3.useState(-1);
|
|
2268
|
+
const itemsRef = React3.useRef(initialItems);
|
|
2269
|
+
if (initialItems !== itemsRef.current) {
|
|
2270
|
+
itemsRef.current = initialItems;
|
|
2271
|
+
setItems(initialItems);
|
|
2272
|
+
}
|
|
2273
|
+
const isDragging = dragIndex >= 0;
|
|
2274
|
+
const handleDragStart = React3.useCallback((index) => (e) => {
|
|
2275
|
+
e.preventDefault();
|
|
2276
|
+
setDragIndex(index);
|
|
2277
|
+
setDragOverIndex(index);
|
|
2278
|
+
e.target.setPointerCapture?.(e.pointerId);
|
|
2279
|
+
}, []);
|
|
2280
|
+
const handleDragMove = React3.useCallback((index) => (e) => {
|
|
2281
|
+
if (dragIndex < 0) return;
|
|
2282
|
+
const target = document.elementFromPoint(e.clientX, e.clientY);
|
|
2283
|
+
if (!target) return;
|
|
2284
|
+
let el = target;
|
|
2285
|
+
while (el && !el.dataset.dragIndex) {
|
|
2286
|
+
el = el.parentElement;
|
|
2287
|
+
}
|
|
2288
|
+
if (el?.dataset.dragIndex) {
|
|
2289
|
+
const overIndex = parseInt(el.dataset.dragIndex, 10);
|
|
2290
|
+
if (!isNaN(overIndex) && overIndex !== dragOverIndex) {
|
|
2291
|
+
setDragOverIndex(overIndex);
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
}, [dragIndex, dragOverIndex]);
|
|
2295
|
+
const handleDragEnd = React3.useCallback(() => {
|
|
2296
|
+
if (dragIndex >= 0 && dragOverIndex >= 0 && dragIndex !== dragOverIndex) {
|
|
2297
|
+
const newItems = [...items];
|
|
2298
|
+
const [movedItem] = newItems.splice(dragIndex, 1);
|
|
2299
|
+
newItems.splice(dragOverIndex, 0, movedItem);
|
|
2300
|
+
setItems(newItems);
|
|
2301
|
+
onReorder(dragIndex, dragOverIndex, items[dragIndex]);
|
|
2302
|
+
}
|
|
2303
|
+
setDragIndex(-1);
|
|
2304
|
+
setDragOverIndex(-1);
|
|
2305
|
+
}, [dragIndex, dragOverIndex, items, onReorder]);
|
|
2306
|
+
const getDragHandleProps = React3.useCallback((index) => ({
|
|
2307
|
+
onPointerDown: handleDragStart(index),
|
|
2308
|
+
style: { cursor: "grab", touchAction: "none" },
|
|
2309
|
+
"aria-grabbed": dragIndex === index,
|
|
2310
|
+
role: "button"
|
|
2311
|
+
}), [handleDragStart, dragIndex]);
|
|
2312
|
+
const getItemProps = React3.useCallback((index) => ({
|
|
2313
|
+
onPointerMove: handleDragMove(index),
|
|
2314
|
+
onPointerUp: handleDragEnd,
|
|
2315
|
+
"aria-dropeffect": "move",
|
|
2316
|
+
"data-drag-index": String(index),
|
|
2317
|
+
style: {
|
|
2318
|
+
opacity: dragIndex === index ? 0.5 : 1,
|
|
2319
|
+
transition: isDragging ? "transform 150ms ease" : void 0,
|
|
2320
|
+
transform: isDragging && dragOverIndex >= 0 ? index === dragIndex ? "scale(1.02)" : index > dragIndex && index <= dragOverIndex ? "translateY(-100%)" : index < dragIndex && index >= dragOverIndex ? "translateY(100%)" : void 0 : void 0
|
|
2321
|
+
}
|
|
2322
|
+
}), [handleDragMove, handleDragEnd, dragIndex, dragOverIndex, isDragging]);
|
|
2323
|
+
return {
|
|
2324
|
+
items,
|
|
2325
|
+
dragIndex,
|
|
2326
|
+
dragOverIndex,
|
|
2327
|
+
isDragging,
|
|
2328
|
+
getDragHandleProps,
|
|
2329
|
+
getItemProps
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
function useInfiniteScroll(onLoadMore, options = {}) {
|
|
2333
|
+
const { rootMargin = "200px", hasMore = true, isLoading = false } = options;
|
|
2334
|
+
const observerRef = React3.useRef(null);
|
|
2335
|
+
const callbackRef = React3.useRef(onLoadMore);
|
|
2336
|
+
callbackRef.current = onLoadMore;
|
|
2337
|
+
const hasMoreRef = React3.useRef(hasMore);
|
|
2338
|
+
hasMoreRef.current = hasMore;
|
|
2339
|
+
const isLoadingRef = React3.useRef(isLoading);
|
|
2340
|
+
isLoadingRef.current = isLoading;
|
|
2341
|
+
React3.useEffect(() => {
|
|
2342
|
+
return () => {
|
|
2343
|
+
observerRef.current?.disconnect();
|
|
2344
|
+
};
|
|
2345
|
+
}, []);
|
|
2346
|
+
const sentinelRef = React3.useCallback((node) => {
|
|
2347
|
+
observerRef.current?.disconnect();
|
|
2348
|
+
if (!node) return;
|
|
2349
|
+
observerRef.current = new IntersectionObserver(
|
|
2350
|
+
(entries) => {
|
|
2351
|
+
const entry = entries[0];
|
|
2352
|
+
if (entry.isIntersecting && hasMoreRef.current && !isLoadingRef.current) {
|
|
2353
|
+
callbackRef.current();
|
|
2354
|
+
}
|
|
2355
|
+
},
|
|
2356
|
+
{ rootMargin }
|
|
2357
|
+
);
|
|
2358
|
+
observerRef.current.observe(node);
|
|
2359
|
+
}, [rootMargin]);
|
|
2360
|
+
return { sentinelRef };
|
|
2361
|
+
}
|
|
2362
|
+
function usePullToRefresh(onRefresh, options = {}) {
|
|
2363
|
+
const { threshold = 60, maxPull = 120 } = options;
|
|
2364
|
+
const [pullDistance, setPullDistance] = React3.useState(0);
|
|
2365
|
+
const [isPulling, setIsPulling] = React3.useState(false);
|
|
2366
|
+
const [isRefreshing, setIsRefreshing] = React3.useState(false);
|
|
2367
|
+
const startY = React3.useRef(0);
|
|
2368
|
+
const scrollTopRef = React3.useRef(0);
|
|
2369
|
+
const onTouchStart = React3.useCallback((e) => {
|
|
2370
|
+
const container = e.currentTarget;
|
|
2371
|
+
scrollTopRef.current = container.scrollTop;
|
|
2372
|
+
if (scrollTopRef.current <= 0) {
|
|
2373
|
+
startY.current = e.touches[0].clientY;
|
|
2374
|
+
setIsPulling(true);
|
|
2375
|
+
}
|
|
2376
|
+
}, []);
|
|
2377
|
+
const onTouchMove = React3.useCallback((e) => {
|
|
2378
|
+
if (!isPulling || isRefreshing) return;
|
|
2379
|
+
const container = e.currentTarget;
|
|
2380
|
+
if (container.scrollTop > 0) {
|
|
2381
|
+
setPullDistance(0);
|
|
2382
|
+
return;
|
|
2383
|
+
}
|
|
2384
|
+
const dy = e.touches[0].clientY - startY.current;
|
|
2385
|
+
if (dy > 0) {
|
|
2386
|
+
const distance = Math.min(dy * 0.5, maxPull);
|
|
2387
|
+
setPullDistance(distance);
|
|
2388
|
+
}
|
|
2389
|
+
}, [isPulling, isRefreshing, maxPull]);
|
|
2390
|
+
const onTouchEnd = React3.useCallback(() => {
|
|
2391
|
+
if (!isPulling) return;
|
|
2392
|
+
setIsPulling(false);
|
|
2393
|
+
if (pullDistance >= threshold && !isRefreshing) {
|
|
2394
|
+
setIsRefreshing(true);
|
|
2395
|
+
setPullDistance(threshold);
|
|
2396
|
+
onRefresh();
|
|
2397
|
+
} else {
|
|
2398
|
+
setPullDistance(0);
|
|
2399
|
+
}
|
|
2400
|
+
}, [isPulling, pullDistance, threshold, isRefreshing, onRefresh]);
|
|
2401
|
+
const endRefresh = React3.useCallback(() => {
|
|
2402
|
+
setIsRefreshing(false);
|
|
2403
|
+
setPullDistance(0);
|
|
2404
|
+
}, []);
|
|
2405
|
+
const containerProps = {
|
|
2406
|
+
onTouchStart,
|
|
2407
|
+
onTouchMove,
|
|
2408
|
+
onTouchEnd,
|
|
2409
|
+
style: {
|
|
2410
|
+
transform: pullDistance > 0 ? `translateY(${pullDistance}px)` : void 0,
|
|
2411
|
+
transition: isPulling ? "none" : "transform 300ms ease-out"
|
|
2412
|
+
}
|
|
2413
|
+
};
|
|
2414
|
+
return {
|
|
2415
|
+
pullDistance,
|
|
2416
|
+
isPulling,
|
|
2417
|
+
isRefreshing,
|
|
2418
|
+
containerProps,
|
|
2419
|
+
endRefresh
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2422
|
+
function getDistance(touches) {
|
|
2423
|
+
const dx = touches[0].clientX - touches[1].clientX;
|
|
2424
|
+
const dy = touches[0].clientY - touches[1].clientY;
|
|
2425
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
2426
|
+
}
|
|
2427
|
+
function usePinchZoom(options = {}) {
|
|
2428
|
+
const { minScale = 0.5, maxScale = 4 } = options;
|
|
2429
|
+
const [scale, setScale] = React3.useState(1);
|
|
2430
|
+
const [isPinching, setIsPinching] = React3.useState(false);
|
|
2431
|
+
const initialDistance = React3.useRef(0);
|
|
2432
|
+
const initialScale = React3.useRef(1);
|
|
2433
|
+
const onTouchStart = React3.useCallback((e) => {
|
|
2434
|
+
if (e.touches.length === 2) {
|
|
2435
|
+
initialDistance.current = getDistance(e.touches);
|
|
2436
|
+
initialScale.current = scale;
|
|
2437
|
+
setIsPinching(true);
|
|
2438
|
+
}
|
|
2439
|
+
}, [scale]);
|
|
2440
|
+
const onTouchMove = React3.useCallback((e) => {
|
|
2441
|
+
if (e.touches.length !== 2 || !isPinching) return;
|
|
2442
|
+
e.preventDefault();
|
|
2443
|
+
const currentDistance = getDistance(e.touches);
|
|
2444
|
+
const ratio = currentDistance / initialDistance.current;
|
|
2445
|
+
const newScale = Math.min(maxScale, Math.max(minScale, initialScale.current * ratio));
|
|
2446
|
+
setScale(newScale);
|
|
2447
|
+
}, [isPinching, minScale, maxScale]);
|
|
2448
|
+
const onTouchEnd = React3.useCallback(() => {
|
|
2449
|
+
setIsPinching(false);
|
|
2450
|
+
}, []);
|
|
2451
|
+
const resetZoom = React3.useCallback(() => {
|
|
2452
|
+
setScale(1);
|
|
2453
|
+
}, []);
|
|
2454
|
+
return {
|
|
2455
|
+
scale,
|
|
2456
|
+
isPinching,
|
|
2457
|
+
gestureProps: {
|
|
2458
|
+
onTouchStart,
|
|
2459
|
+
onTouchMove,
|
|
2460
|
+
onTouchEnd
|
|
2461
|
+
},
|
|
2462
|
+
resetZoom
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
var API_BASE = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "http://localhost:3000";
|
|
2466
|
+
function getUserId() {
|
|
2467
|
+
return localStorage.getItem("userId") || "anonymous";
|
|
2468
|
+
}
|
|
2469
|
+
async function fetchWithAuth(endpoint, options) {
|
|
2470
|
+
const userId = getUserId();
|
|
2471
|
+
const response = await fetch(`${API_BASE}${endpoint}`, {
|
|
2472
|
+
...options,
|
|
2473
|
+
headers: {
|
|
2474
|
+
"Content-Type": "application/json",
|
|
2475
|
+
"x-user-id": userId,
|
|
2476
|
+
...options?.headers
|
|
2477
|
+
}
|
|
2478
|
+
});
|
|
2479
|
+
if (!response.ok) {
|
|
2480
|
+
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
2481
|
+
throw new Error(error.error || error.message || "Request failed");
|
|
2482
|
+
}
|
|
2483
|
+
return response.json();
|
|
2484
|
+
}
|
|
2485
|
+
function useGitHubStatus() {
|
|
2486
|
+
return reactQuery.useQuery({
|
|
2487
|
+
queryKey: ["github", "status"],
|
|
2488
|
+
queryFn: () => fetchWithAuth("/api/github/status"),
|
|
2489
|
+
staleTime: 6e4,
|
|
2490
|
+
// 1 minute
|
|
2491
|
+
retry: false
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
function useConnectGitHub() {
|
|
2495
|
+
const connectGitHub = React3.useCallback(() => {
|
|
2496
|
+
const userId = getUserId();
|
|
2497
|
+
const state = btoa(JSON.stringify({ userId, returnUrl: window.location.href }));
|
|
2498
|
+
window.location.href = `${API_BASE}/api/github/oauth/authorize?state=${state}`;
|
|
2499
|
+
}, []);
|
|
2500
|
+
return { connectGitHub };
|
|
2501
|
+
}
|
|
2502
|
+
function useDisconnectGitHub() {
|
|
2503
|
+
const queryClient = reactQuery.useQueryClient();
|
|
2504
|
+
return reactQuery.useMutation({
|
|
2505
|
+
mutationFn: () => fetchWithAuth("/api/github/disconnect", { method: "POST" }),
|
|
2506
|
+
onSuccess: () => {
|
|
2507
|
+
queryClient.invalidateQueries({ queryKey: ["github", "status"] });
|
|
2508
|
+
queryClient.removeQueries({ queryKey: ["github", "repos"] });
|
|
2509
|
+
}
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
function useGitHubRepos(page = 1, perPage = 30) {
|
|
2513
|
+
return reactQuery.useQuery({
|
|
2514
|
+
queryKey: ["github", "repos", page, perPage],
|
|
2515
|
+
queryFn: () => fetchWithAuth(`/api/github/repos?page=${page}&per_page=${perPage}`),
|
|
2516
|
+
enabled: true,
|
|
2517
|
+
// Only fetch if user is connected
|
|
2518
|
+
staleTime: 3e5
|
|
2519
|
+
// 5 minutes
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
function useGitHubRepo(owner, repo, enabled = true) {
|
|
2523
|
+
return reactQuery.useQuery({
|
|
2524
|
+
queryKey: ["github", "repo", owner, repo],
|
|
2525
|
+
queryFn: () => fetchWithAuth(`/api/github/repos/${owner}/${repo}`),
|
|
2526
|
+
enabled: enabled && !!owner && !!repo,
|
|
2527
|
+
staleTime: 3e5
|
|
2528
|
+
// 5 minutes
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2531
|
+
function useGitHubBranches(owner, repo, enabled = true) {
|
|
2532
|
+
return reactQuery.useQuery({
|
|
2533
|
+
queryKey: ["github", "branches", owner, repo],
|
|
2534
|
+
queryFn: () => fetchWithAuth(`/api/github/repos/${owner}/${repo}/branches`),
|
|
2535
|
+
enabled: enabled && !!owner && !!repo,
|
|
2536
|
+
staleTime: 6e4
|
|
2537
|
+
// 1 minute
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
exports.DEFAULT_SLOTS = DEFAULT_SLOTS;
|
|
2542
|
+
exports.ENTITY_EVENTS = ENTITY_EVENTS;
|
|
2543
|
+
exports.EntityDataProvider = EntityDataProvider;
|
|
2544
|
+
exports.I18nProvider = I18nProvider;
|
|
2545
|
+
exports.clearEntities = clearEntities;
|
|
2546
|
+
exports.createTranslate = createTranslate;
|
|
2547
|
+
exports.entityDataKeys = entityDataKeys;
|
|
2548
|
+
exports.getAllEntities = getAllEntities;
|
|
2549
|
+
exports.getByType = getByType;
|
|
2550
|
+
exports.getEntity = getEntity;
|
|
2551
|
+
exports.getSingleton = getSingleton;
|
|
2552
|
+
exports.parseQueryBinding = parseQueryBinding;
|
|
2553
|
+
exports.removeEntity = removeEntity;
|
|
2554
|
+
exports.spawnEntity = spawnEntity;
|
|
2555
|
+
exports.updateEntity = updateEntity;
|
|
2556
|
+
exports.updateSingleton = updateSingleton;
|
|
2557
|
+
exports.useAgentChat = useAgentChat;
|
|
2558
|
+
exports.useAuthContext = useAuthContext;
|
|
2559
|
+
exports.useCompile = useCompile;
|
|
2560
|
+
exports.useConnectGitHub = useConnectGitHub;
|
|
2561
|
+
exports.useCreateEntity = useCreateEntity;
|
|
2562
|
+
exports.useDeepAgentGeneration = useDeepAgentGeneration;
|
|
2563
|
+
exports.useDeleteEntity = useDeleteEntity;
|
|
2564
|
+
exports.useDisconnectGitHub = useDisconnectGitHub;
|
|
2565
|
+
exports.useDragReorder = useDragReorder;
|
|
2566
|
+
exports.useEmitEvent = useEmitEvent;
|
|
2567
|
+
exports.useEntities = useEntities;
|
|
2568
|
+
exports.useEntitiesByType = useEntitiesByType;
|
|
2569
|
+
exports.useEntity = useEntity;
|
|
2570
|
+
exports.useEntityById = useEntity2;
|
|
2571
|
+
exports.useEntityDataAdapter = useEntityDataAdapter;
|
|
2572
|
+
exports.useEntityDetail = useEntityDetail;
|
|
2573
|
+
exports.useEntityList = useEntityList;
|
|
2574
|
+
exports.useEntityListSuspense = useEntityListSuspense;
|
|
2575
|
+
exports.useEntityMutations = useEntityMutations;
|
|
2576
|
+
exports.useEntitySuspense = useEntitySuspense;
|
|
2577
|
+
exports.useEventBus = useEventBus;
|
|
2578
|
+
exports.useEventListener = useEventListener;
|
|
2579
|
+
exports.useExtensions = useExtensions;
|
|
2580
|
+
exports.useFileEditor = useFileEditor;
|
|
2581
|
+
exports.useFileSystem = useFileSystem;
|
|
2582
|
+
exports.useGitHubBranches = useGitHubBranches;
|
|
2583
|
+
exports.useGitHubRepo = useGitHubRepo;
|
|
2584
|
+
exports.useGitHubRepos = useGitHubRepos;
|
|
2585
|
+
exports.useGitHubStatus = useGitHubStatus;
|
|
2586
|
+
exports.useInfiniteScroll = useInfiniteScroll;
|
|
2587
|
+
exports.useInput = useInput;
|
|
2588
|
+
exports.useLongPress = useLongPress;
|
|
2589
|
+
exports.useOrbitalHistory = useOrbitalHistory;
|
|
2590
|
+
exports.useOrbitalMutations = useOrbitalMutations;
|
|
2591
|
+
exports.usePhysics = usePhysics;
|
|
2592
|
+
exports.usePinchZoom = usePinchZoom;
|
|
2593
|
+
exports.usePlayer = usePlayer;
|
|
2594
|
+
exports.usePreview = usePreview;
|
|
2595
|
+
exports.usePullToRefresh = usePullToRefresh;
|
|
2596
|
+
exports.useQuerySingleton = useQuerySingleton;
|
|
2597
|
+
exports.useResolvedEntity = useResolvedEntity;
|
|
2598
|
+
exports.useSelectedEntity = useSelectedEntity;
|
|
2599
|
+
exports.useSendOrbitalEvent = useSendOrbitalEvent;
|
|
2600
|
+
exports.useSingletonEntity = useSingletonEntity;
|
|
2601
|
+
exports.useSwipeGesture = useSwipeGesture;
|
|
2602
|
+
exports.useTranslate = useTranslate;
|
|
2603
|
+
exports.useUIEvents = useUIEvents;
|
|
2604
|
+
exports.useUISlotManager = useUISlotManager;
|
|
2605
|
+
exports.useUpdateEntity = useUpdateEntity;
|
|
2606
|
+
exports.useValidation = useValidation;
|