@lobb-js/studio 0.1.42 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/components/LlmButton.svelte +1 -2
  2. package/dist/components/Studio.svelte +1 -2
  3. package/dist/components/codeEditor.svelte +1 -1
  4. package/dist/components/createManyButton.svelte +1 -1
  5. package/dist/components/dataTable/childRecords.svelte +1 -1
  6. package/dist/components/dataTable/childRecords.svelte.d.ts +1 -1
  7. package/dist/components/dataTable/dataTable.svelte +2 -3
  8. package/dist/components/dataTable/dataTable.svelte.d.ts +1 -1
  9. package/dist/components/dataTable/header.svelte +1 -2
  10. package/dist/components/dataTable/table.svelte +4 -4
  11. package/dist/components/dataTable/table.svelte.d.ts +1 -1
  12. package/dist/components/detailView/create/children.svelte +1 -1
  13. package/dist/components/detailView/create/createDetailView.svelte +1 -2
  14. package/dist/components/detailView/create/createManyView.svelte +4 -4
  15. package/dist/components/detailView/fieldInput.svelte +11 -42
  16. package/dist/components/detailView/fieldInputReplacement.svelte +7 -7
  17. package/dist/components/detailView/store.svelte.js +1 -1
  18. package/dist/components/detailView/update/children.svelte +3 -3
  19. package/dist/components/detailView/update/updateDetailView.svelte +1 -2
  20. package/dist/components/diffViewer.svelte +1 -1
  21. package/dist/components/foreingKeyInput.svelte +2 -2
  22. package/dist/components/rangeCalendarButton.svelte +10 -10
  23. package/dist/components/routes/data_model/syncManager.svelte +1 -2
  24. package/dist/components/routes/workflows/workflows.svelte +1 -2
  25. package/dist/components/sidebar/sidebar.svelte +1 -1
  26. package/dist/components/sidebar/sidebarElements.svelte +1 -1
  27. package/dist/components/singletone.svelte +1 -1
  28. package/dist/components/ui/input/input.svelte +2 -2
  29. package/dist/components/ui/range-calendar/range-calendar-day.svelte.d.ts +6 -0
  30. package/dist/components/ui/select/select-content.svelte +1 -1
  31. package/dist/components/ui/select/select-trigger.svelte +1 -1
  32. package/dist/components/ui/textarea/textarea.svelte +1 -1
  33. package/dist/components/workflowEditor.svelte +1 -2
  34. package/dist/extensions/extension.types.d.ts +2 -2
  35. package/dist/extensions/extensionUtils.js +1 -2
  36. package/dist/index.d.ts +22 -8
  37. package/dist/index.js +21 -26
  38. package/dist/store.svelte.d.ts +1 -2
  39. package/dist/store.svelte.js +2 -2
  40. package/dist/utils.d.ts +0 -1
  41. package/dist/utils.js +0 -11
  42. package/package.json +11 -15
  43. package/vite-plugins/contextual-lib-alias.js +39 -38
  44. package/vite-plugins/index.js +0 -2
  45. package/dist/Lobb.d.ts +0 -30
  46. package/dist/Lobb.js +0 -358
  47. package/dist/Studio.svelte +0 -150
  48. package/dist/Studio.svelte.d.ts +0 -6
  49. package/vite-plugins/monorepo-import-resolver.js +0 -92
package/dist/Lobb.js DELETED
@@ -1,358 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- import qs from "qs";
49
- import { parseFunction } from "./utils";
50
- var Lobb = /** @class */ (function () {
51
- function Lobb(lobbUrl) {
52
- this.headers = [];
53
- this.onResponseHandlers = [];
54
- this.lobbUrl = lobbUrl;
55
- }
56
- Lobb.prototype.onResponse = function (callback) {
57
- return __awaiter(this, void 0, void 0, function () {
58
- return __generator(this, function (_a) {
59
- this.onResponseHandlers.push(callback);
60
- return [2 /*return*/];
61
- });
62
- });
63
- };
64
- Lobb.prototype.setHeaders = function (headers) {
65
- this.headers = headers;
66
- };
67
- Lobb.prototype.getHeaders = function () {
68
- return this.headers;
69
- };
70
- Lobb.prototype.getMeta = function () {
71
- return __awaiter(this, void 0, void 0, function () {
72
- var response, metaResponse, meta;
73
- return __generator(this, function (_a) {
74
- switch (_a.label) {
75
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/meta"), {
76
- headers: this.headers,
77
- })];
78
- case 1:
79
- response = _a.sent();
80
- return [4 /*yield*/, this.handleResponse(response)];
81
- case 2:
82
- metaResponse = _a.sent();
83
- return [4 /*yield*/, metaResponse.json()];
84
- case 3:
85
- meta = _a.sent();
86
- meta.studio_workflows = meta.studio_workflows.map(function (workflow) {
87
- return __assign(__assign({}, workflow), { handler: parseFunction(workflow.handler) });
88
- });
89
- return [2 /*return*/, meta];
90
- }
91
- });
92
- });
93
- };
94
- // CRUD methods
95
- Lobb.prototype.findAll = function (collectionName, params) {
96
- return __awaiter(this, void 0, void 0, function () {
97
- var response;
98
- return __generator(this, function (_a) {
99
- switch (_a.label) {
100
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName, "/search"), {
101
- method: "POST",
102
- headers: this.headers,
103
- body: JSON.stringify(params),
104
- })];
105
- case 1:
106
- response = _a.sent();
107
- return [4 /*yield*/, this.handleResponse(response)];
108
- case 2: return [2 /*return*/, _a.sent()];
109
- }
110
- });
111
- });
112
- };
113
- Lobb.prototype.findOne = function (collectionName, id, queryParams) {
114
- return __awaiter(this, void 0, void 0, function () {
115
- var response;
116
- return __generator(this, function (_a) {
117
- switch (_a.label) {
118
- case 0:
119
- queryParams = queryParams ? "?".concat(qs.stringify(queryParams)) : "";
120
- return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName, "/").concat(id).concat(queryParams), {
121
- method: "GET",
122
- headers: this.headers,
123
- })];
124
- case 1:
125
- response = _a.sent();
126
- return [4 /*yield*/, this.handleResponse(response)];
127
- case 2: return [2 /*return*/, _a.sent()];
128
- }
129
- });
130
- });
131
- };
132
- Lobb.prototype.createOne = function (collectionName, body, file) {
133
- return __awaiter(this, void 0, void 0, function () {
134
- var formData_1, response;
135
- return __generator(this, function (_a) {
136
- switch (_a.label) {
137
- case 0:
138
- if (file) {
139
- formData_1 = new FormData();
140
- Object.keys(body).forEach(function (key) {
141
- formData_1.append(key, body[key]);
142
- });
143
- formData_1.append("file", file, file.name);
144
- formData_1.append("payload", JSON.stringify({
145
- data: body,
146
- }));
147
- body = formData_1;
148
- }
149
- else {
150
- body = JSON.stringify({
151
- data: body,
152
- });
153
- }
154
- return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName), {
155
- method: "POST",
156
- headers: this.headers,
157
- body: body,
158
- })];
159
- case 1:
160
- response = _a.sent();
161
- return [4 /*yield*/, this.handleResponse(response)];
162
- case 2: return [2 /*return*/, _a.sent()];
163
- }
164
- });
165
- });
166
- };
167
- Lobb.prototype.updateOne = function (collectionName, id, body) {
168
- return __awaiter(this, void 0, void 0, function () {
169
- var response;
170
- return __generator(this, function (_a) {
171
- switch (_a.label) {
172
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName, "/").concat(id), {
173
- method: "PATCH",
174
- headers: this.headers,
175
- body: JSON.stringify({
176
- data: body,
177
- }),
178
- })];
179
- case 1:
180
- response = _a.sent();
181
- return [4 /*yield*/, this.handleResponse(response)];
182
- case 2: return [2 /*return*/, _a.sent()];
183
- }
184
- });
185
- });
186
- };
187
- Lobb.prototype.readSingleton = function (collectionName) {
188
- return __awaiter(this, void 0, void 0, function () {
189
- var response;
190
- return __generator(this, function (_a) {
191
- switch (_a.label) {
192
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName, "/singleton"), {
193
- method: "GET",
194
- headers: this.headers,
195
- })];
196
- case 1:
197
- response = _a.sent();
198
- return [4 /*yield*/, this.handleResponse(response)];
199
- case 2: return [2 /*return*/, _a.sent()];
200
- }
201
- });
202
- });
203
- };
204
- Lobb.prototype.updateSingleton = function (collectionName, body) {
205
- return __awaiter(this, void 0, void 0, function () {
206
- var response;
207
- return __generator(this, function (_a) {
208
- switch (_a.label) {
209
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName, "/singleton"), {
210
- method: "PATCH",
211
- headers: this.headers,
212
- body: JSON.stringify({
213
- data: body,
214
- }),
215
- })];
216
- case 1:
217
- response = _a.sent();
218
- return [4 /*yield*/, this.handleResponse(response)];
219
- case 2: return [2 /*return*/, _a.sent()];
220
- }
221
- });
222
- });
223
- };
224
- Lobb.prototype.deleteOne = function (collectionName_1, id_1) {
225
- return __awaiter(this, arguments, void 0, function (collectionName, id, force) {
226
- var response;
227
- if (force === void 0) { force = false; }
228
- return __generator(this, function (_a) {
229
- switch (_a.label) {
230
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName, "/").concat(id).concat(force ? "?force" : ""), {
231
- method: "DELETE",
232
- headers: this.headers,
233
- })];
234
- case 1:
235
- response = _a.sent();
236
- return [4 /*yield*/, this.handleResponse(response)];
237
- case 2: return [2 /*return*/, _a.sent()];
238
- }
239
- });
240
- });
241
- };
242
- Lobb.prototype.deleteMany = function (collectionName_1, filter_1) {
243
- return __awaiter(this, arguments, void 0, function (collectionName, filter, force) {
244
- var response;
245
- if (force === void 0) { force = false; }
246
- return __generator(this, function (_a) {
247
- switch (_a.label) {
248
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName).concat(force ? "?force" : ""), {
249
- method: "DELETE",
250
- headers: this.headers,
251
- body: JSON.stringify({
252
- filter: filter,
253
- }),
254
- })];
255
- case 1:
256
- response = _a.sent();
257
- return [4 /*yield*/, this.handleResponse(response)];
258
- case 2: return [2 /*return*/, _a.sent()];
259
- }
260
- });
261
- });
262
- };
263
- Lobb.prototype.createMany = function (collectionName, body) {
264
- return __awaiter(this, void 0, void 0, function () {
265
- var response;
266
- return __generator(this, function (_a) {
267
- switch (_a.label) {
268
- case 0:
269
- body = JSON.stringify({
270
- data: body,
271
- });
272
- return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName), {
273
- method: "POST",
274
- headers: this.headers,
275
- body: body,
276
- })];
277
- case 1:
278
- response = _a.sent();
279
- return [4 /*yield*/, this.handleResponse(response)];
280
- case 2: return [2 /*return*/, _a.sent()];
281
- }
282
- });
283
- });
284
- };
285
- Lobb.prototype.updateMany = function (collectionName, body, filter) {
286
- return __awaiter(this, void 0, void 0, function () {
287
- var response;
288
- return __generator(this, function (_a) {
289
- switch (_a.label) {
290
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/").concat(collectionName), {
291
- method: "PATCH",
292
- headers: this.headers,
293
- body: JSON.stringify({
294
- filter: filter,
295
- data: body,
296
- }),
297
- })];
298
- case 1:
299
- response = _a.sent();
300
- return [4 /*yield*/, this.handleResponse(response)];
301
- case 2: return [2 /*return*/, _a.sent()];
302
- }
303
- });
304
- });
305
- };
306
- Lobb.prototype.transactions = function (body, rollback) {
307
- return __awaiter(this, void 0, void 0, function () {
308
- var response;
309
- return __generator(this, function (_a) {
310
- switch (_a.label) {
311
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl, "/api/collections/transactions").concat(rollback ? "?rollback" : ""), {
312
- method: "POST",
313
- headers: this.headers,
314
- body: JSON.stringify(body),
315
- })];
316
- case 1:
317
- response = _a.sent();
318
- return [4 /*yield*/, this.handleResponse(response)];
319
- case 2: return [2 /*return*/, _a.sent()];
320
- }
321
- });
322
- });
323
- };
324
- // CUSTOM REQUEST methods
325
- Lobb.prototype.request = function (params) {
326
- return __awaiter(this, void 0, void 0, function () {
327
- var response;
328
- return __generator(this, function (_a) {
329
- switch (_a.label) {
330
- case 0: return [4 /*yield*/, fetch("".concat(this.lobbUrl).concat(params.route), {
331
- method: params.method,
332
- headers: this.headers,
333
- body: JSON.stringify(params.payload),
334
- })];
335
- case 1:
336
- response = _a.sent();
337
- return [4 /*yield*/, this.handleResponse(response)];
338
- case 2: return [2 /*return*/, _a.sent()];
339
- }
340
- });
341
- });
342
- };
343
- // HELPER methods
344
- Lobb.prototype.handleResponse = function (response) {
345
- return __awaiter(this, void 0, Promise, function () {
346
- var index, handler;
347
- return __generator(this, function (_a) {
348
- for (index = 0; index < this.onResponseHandlers.length; index++) {
349
- handler = this.onResponseHandlers[index];
350
- handler(response.clone());
351
- }
352
- return [2 /*return*/, response];
353
- });
354
- });
355
- };
356
- return Lobb;
357
- }());
358
- export { Lobb };
@@ -1,150 +0,0 @@
1
- <script lang="ts">
2
- import { Toaster } from "./components/ui/sonner";
3
- import { onMount, onDestroy } from "svelte";
4
- import { ModeWatcher } from "mode-watcher";
5
- import { ctx } from "./store.svelte";
6
- import { lobb } from "./";
7
- import Header from "./components/header.svelte";
8
- import { LoaderCircle, ServerOff } from "lucide-svelte";
9
- import Dialog from "./components/confirmationDialog/confirmationDialog.svelte";
10
- import MiniSidebar from "./components/miniSidebar.svelte";
11
- import SetServerPage from "./components/setServerPage.svelte";
12
- import * as Tooltip from "./components/ui/tooltip";
13
- import { Router, Route, Fallback, init as initRouter, } from "@wjfe/n-savant";
14
- import {
15
- executeExtensionsOnStartup,
16
- loadExtensions,
17
- } from "./extensions/extensionUtils";
18
- import { mediaQueries } from "./utils";
19
- import Home from "../../routes/home.svelte";
20
- import DataModel from "../../routes/data_model/dataModel.svelte";
21
- import Collections from "../../routes/collections/collections.svelte";
22
- import Workflows from "../../routes/workflows/workflows.svelte";
23
- import Extension from "../../routes/extensions/extension.svelte";
24
-
25
- interface StudioProps {
26
- extensions?: any[];
27
- }
28
-
29
- const props: StudioProps = $props()
30
-
31
- let error: string | null = $state(null);
32
- let loaded = $state(false);
33
- let isSmallScreen = $derived(!mediaQueries.sm.current);
34
- let cleanupRouter: (() => void) | undefined;
35
-
36
- onMount(async () => {
37
- cleanupRouter = initRouter();
38
-
39
- if (ctx.lobbUrl) {
40
- try {
41
- ctx.meta = await lobb.getMeta();
42
- ctx.extensions = await loadExtensions(props.extensions);
43
- await executeExtensionsOnStartup();
44
- } catch (err) {
45
- console.error(err);
46
- error = "CANT_CONNECT";
47
- }
48
- }
49
- loaded = true;
50
- });
51
-
52
- onDestroy(() => {
53
- if (cleanupRouter) {
54
- cleanupRouter();
55
- }
56
- });
57
- </script>
58
-
59
- <ModeWatcher defaultMode="light" />
60
- <Toaster position="top-right" class="z-50" />
61
- {#if loaded}
62
- {#if ctx.lobbUrl}
63
- <Tooltip.Provider delayDuration={0} disableHoverableContent={true}>
64
- <main
65
- class="bg-muted h-screen w-screen"
66
- style="display: grid; grid-template-columns: {isSmallScreen
67
- ? '1fr'
68
- : '3.5rem 1fr'};"
69
- >
70
- <MiniSidebar />
71
- <div class="second_grid">
72
- <Header />
73
- <Router id="root-router">
74
- <Route key="home" path="/">
75
- {#snippet children(params)}
76
- <Home />
77
- {/snippet}
78
- </Route>
79
- <Route
80
- key="collections"
81
- path="/collections/:collection?"
82
- >
83
- {#snippet children(params)}
84
- <Collections
85
- collectionName={params?.collection}
86
- />
87
- {/snippet}
88
- </Route>
89
- <Route key="datamodel" path="/datamodel/*">
90
- {#snippet children(params)}
91
- <DataModel />
92
- {/snippet}
93
- </Route>
94
- <Route key="workflows" path="/workflows/:workflow?">
95
- {#snippet children(params)}
96
- <Workflows workflowName={params?.workflow} />
97
- {/snippet}
98
- </Route>
99
- <Route
100
- key="extensions"
101
- path="/extensions/:extension?/:page?/*"
102
- >
103
- {#snippet children(params)}
104
- <Extension
105
- extension={params?.extension}
106
- page={params?.page}
107
- />
108
- {/snippet}
109
- </Route>
110
- <Fallback>Not Found</Fallback>
111
- </Router>
112
- </div>
113
- </main>
114
- </Tooltip.Provider>
115
- {:else}
116
- <SetServerPage />
117
- {/if}
118
- {:else if !error}
119
- <div
120
- class="flex h-screen w-full flex-col items-center justify-center gap-4 text-muted-foreground"
121
- >
122
- <LoaderCircle class="animate-spin opacity-50" size="50" />
123
- <div class="flex flex-col items-center justify-center">
124
- <div>Loading the dashboard, please wait...</div>
125
- <div class="text-xs">
126
- Loading and importing all necessary data and components from the
127
- lobb server.
128
- </div>
129
- </div>
130
- </div>
131
- {:else}
132
- <div
133
- class="flex h-full w-full flex-col items-center justify-center gap-4 text-muted-foreground"
134
- >
135
- <ServerOff class="opacity-50" size="50" />
136
- <div class="flex flex-col items-center justify-center">
137
- <div>Could not connect to the server</div>
138
- <div class="text-xs">
139
- Could not connect to the lobb server at this endpoint ({ctx.lobbUrl})
140
- </div>
141
- </div>
142
- </div>
143
- {/if}
144
-
145
- <style>
146
- .second_grid {
147
- display: grid;
148
- grid-template-rows: 2.5rem 1fr;
149
- }
150
- </style>
@@ -1,6 +0,0 @@
1
- interface StudioProps {
2
- extensions?: any[];
3
- }
4
- declare const Studio: import("svelte").Component<StudioProps, {}, "">;
5
- type Studio = ReturnType<typeof Studio>;
6
- export default Studio;
@@ -1,92 +0,0 @@
1
- import path from "path";
2
- import fs from "fs";
3
-
4
- /**
5
- * Detects if the current project is inside a monorepo workspace.
6
- *
7
- * Checks for workspace configuration files in parent directories:
8
- * - pnpm-workspace.yaml (pnpm)
9
- * - package.json with "workspaces" field (npm/yarn)
10
- *
11
- * @param {string} startDir - Directory to start searching from
12
- * @returns {boolean} True if inside a monorepo workspace
13
- */
14
- function isInMonorepo(startDir) {
15
- let currentDir = startDir;
16
- const root = path.parse(currentDir).root;
17
-
18
- while (currentDir !== root) {
19
- // Check for pnpm-workspace.yaml
20
- if (fs.existsSync(path.join(currentDir, 'pnpm-workspace.yaml'))) {
21
- return true;
22
- }
23
-
24
- // Check for package.json with workspaces field
25
- const pkgPath = path.join(currentDir, 'package.json');
26
- if (fs.existsSync(pkgPath)) {
27
- try {
28
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
29
- if (pkg.workspaces) {
30
- return true;
31
- }
32
- } catch (e) {
33
- // Ignore parse errors
34
- }
35
- }
36
-
37
- // Move up one directory
38
- currentDir = path.dirname(currentDir);
39
- }
40
-
41
- return false;
42
- }
43
-
44
- /**
45
- * Vite plugin that resolves @lobb-js/studio imports contextually.
46
- *
47
- * - Inside monorepo: Rewrites to @lobb-js/studio/internal (uses source files from /src for fast HMR)
48
- * - Outside monorepo: Uses default export (uses built files from /dist)
49
- *
50
- * This allows consuming projects to use identical import syntax everywhere:
51
- * `import Studio from '@lobb-js/studio'`
52
- *
53
- * The plugin automatically optimizes the resolution based on the environment.
54
- *
55
- * @returns {import('vite').Plugin}
56
- */
57
- export function monorepoImportResolver() {
58
- let isMonorepo = false;
59
-
60
- return {
61
- name: "monorepo-import-resolver",
62
- enforce: "pre",
63
-
64
- configResolved(config) {
65
- // Detect monorepo once during config resolution
66
- isMonorepo = isInMonorepo(config.root);
67
-
68
- if (isMonorepo) {
69
- console.log('🎯 Lobb Studio: Running in monorepo mode - using source files for fast HMR');
70
- } else {
71
- console.log('📦 Lobb Studio: Running in standalone mode - using built distribution files');
72
- }
73
- },
74
-
75
- async resolveId(source, importer, options) {
76
- // Handle @lobb-js/studio imports (and subpaths like @lobb-js/studio/*)
77
- if (!source.startsWith("@lobb-js/studio")) return null;
78
-
79
- // Don't rewrite if already using /internal path
80
- if (source.startsWith("@lobb-js/studio/internal")) return null;
81
-
82
- // In monorepo, rewrite to /internal path which points to source files
83
- if (isMonorepo) {
84
- const rewrittenSource = source.replace("@lobb-js/studio", "@lobb-js/studio/internal");
85
- return this.resolve(rewrittenSource, importer, { skipSelf: true, ...options });
86
- }
87
-
88
- // Not in monorepo - let default resolution handle it (uses dist/ from node_modules)
89
- return null;
90
- }
91
- };
92
- }