@lobb-js/studio 0.5.0 → 0.7.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 (71) hide show
  1. package/dist/components/LlmButton.svelte +3 -1
  2. package/dist/components/Studio.svelte +78 -98
  3. package/dist/components/Studio.svelte.d.ts +1 -1
  4. package/dist/components/breadCrumbs.svelte +0 -1
  5. package/dist/components/combobox.svelte +3 -3
  6. package/dist/components/confirmationDialog/confirmationDialog.svelte +1 -1
  7. package/dist/components/createManyButton.svelte +3 -1
  8. package/dist/components/dataTable/childRecords.svelte +4 -2
  9. package/dist/components/dataTable/dataTable.svelte +6 -3
  10. package/dist/components/dataTable/fieldCell.svelte +6 -3
  11. package/dist/components/dataTable/filter.svelte +4 -2
  12. package/dist/components/dataTable/filterButton.svelte +1 -1
  13. package/dist/components/dataTable/header.svelte +3 -1
  14. package/dist/components/dataTable/sort.svelte +5 -3
  15. package/dist/components/dataTable/sortButton.svelte +2 -2
  16. package/dist/components/dataTable/utils.d.ts +7 -6
  17. package/dist/components/dataTable/utils.js +14 -13
  18. package/dist/components/detailView/create/children.svelte +5 -3
  19. package/dist/components/detailView/create/createDetailView.svelte +14 -10
  20. package/dist/components/detailView/create/createDetailViewButton.svelte +15 -10
  21. package/dist/components/detailView/create/createDetailViewButton.svelte.d.ts +1 -1
  22. package/dist/components/detailView/create/createManyView.svelte +8 -6
  23. package/dist/components/detailView/create/subRecords.svelte +3 -1
  24. package/dist/components/detailView/fieldInput.svelte +7 -5
  25. package/dist/components/detailView/fieldInputReplacement.svelte +1 -1
  26. package/dist/components/detailView/store.svelte.d.ts +3 -2
  27. package/dist/components/detailView/store.svelte.js +11 -14
  28. package/dist/components/detailView/update/children.svelte +6 -4
  29. package/dist/components/detailView/update/updateDetailView.svelte +11 -9
  30. package/dist/components/detailView/update/updateDetailViewButton.svelte +35 -11
  31. package/dist/components/detailView/update/updateDetailViewButton.svelte.d.ts +1 -1
  32. package/dist/components/detailView/utils.d.ts +6 -5
  33. package/dist/components/detailView/utils.js +9 -10
  34. package/dist/components/extensionsComponents.svelte +4 -1
  35. package/dist/components/miniSidebar.svelte +9 -21
  36. package/dist/components/rangeCalendarButton.svelte +3 -3
  37. package/dist/components/routes/collections/collection.svelte +8 -6
  38. package/dist/components/routes/collections/collections.svelte +5 -3
  39. package/dist/components/routes/data_model/dataModel.svelte +2 -2
  40. package/dist/components/routes/data_model/flow.svelte +3 -1
  41. package/dist/components/routes/data_model/syncManager.svelte +7 -5
  42. package/dist/components/routes/extensions/extension.svelte +5 -2
  43. package/dist/components/routes/home.svelte +4 -2
  44. package/dist/components/routes/workflows/workflows.svelte +9 -7
  45. package/dist/components/selectRecord.svelte +5 -1
  46. package/dist/components/setServerPage.svelte +4 -2
  47. package/dist/components/singletone.svelte +4 -2
  48. package/dist/components/ui/alert-dialog/alert-dialog-action.svelte +1 -1
  49. package/dist/components/ui/alert-dialog/alert-dialog-cancel.svelte +1 -1
  50. package/dist/components/ui/command/command-dialog.svelte +1 -1
  51. package/dist/components/ui/range-calendar/range-calendar-day.svelte +1 -1
  52. package/dist/components/ui/range-calendar/range-calendar-day.svelte.d.ts +1 -1
  53. package/dist/components/ui/range-calendar/range-calendar-next-button.svelte +1 -1
  54. package/dist/components/ui/range-calendar/range-calendar-prev-button.svelte +1 -1
  55. package/dist/components/ui/select/select-separator.svelte +1 -1
  56. package/dist/components/workflowEditor.svelte +6 -4
  57. package/dist/context.d.ts +10 -0
  58. package/dist/context.js +11 -0
  59. package/dist/eventSystem.d.ts +2 -1
  60. package/dist/eventSystem.js +7 -7
  61. package/dist/extensions/extensionUtils.d.ts +7 -6
  62. package/dist/extensions/extensionUtils.js +17 -60
  63. package/dist/store.svelte.d.ts +1 -3
  64. package/dist/store.svelte.js +19 -36
  65. package/dist/utils.d.ts +3 -2
  66. package/dist/utils.js +2 -3
  67. package/package.json +6 -2
  68. package/vite-plugins/index.d.ts +8 -0
  69. package/vite-plugins/index.js +4 -9
  70. package/vite-plugins/lobb-extensions.js +73 -0
  71. package/vite-plugins/monorepo-workspace.js +138 -0
@@ -1,11 +1,13 @@
1
1
  <script lang="ts">
2
- import DiffViewer from "../../diffViewer.svelte";
3
- import { lobb, ctx } from "../../../store.svelte";
2
+ import DiffViewer from "../../../components/diffViewer.svelte";
3
+ import { getStudioContext } from "../../../context";
4
+
5
+ const { lobb, ctx } = getStudioContext();
4
6
  import { onMount } from "svelte";
5
7
  import stringify from "json-stable-stringify";
6
- import CodeEditor from "../../codeEditor.svelte";
7
- import Table from "../../dataTable/table.svelte";
8
- import Button from "../../ui/button/button.svelte";
8
+ import CodeEditor from "../../../components/codeEditor.svelte";
9
+ import Table from "../../../components/dataTable/table.svelte";
10
+ import Button from "../../../components/ui/button/button.svelte";
9
11
  import { LoaderCircle, SendHorizontal } from "lucide-svelte";
10
12
 
11
13
  let configSchema: string = $state("");
@@ -1,15 +1,18 @@
1
1
  <script>
2
- import ExtensionsComponents from "../../extensionsComponents.svelte";
2
+ import ExtensionsComponents from "../../../components/extensionsComponents.svelte";
3
3
  import { getExtensionUtils } from "../../../extensions/extensionUtils";
4
+ import { getStudioContext } from "../../../context";
4
5
 
5
6
  let { extension, page } = $props();
7
+
8
+ const { lobb, ctx } = getStudioContext();
6
9
  </script>
7
10
 
8
11
  <div class="grid overflow-auto bg-background">
9
12
  {#key extension && page}
10
13
  <ExtensionsComponents
11
14
  name="pages.{page}"
12
- utils={getExtensionUtils()}
15
+ utils={getExtensionUtils(lobb, ctx)}
13
16
  filterByExtensions={[extension]}
14
17
  />
15
18
  {/key}
@@ -1,7 +1,9 @@
1
1
  <script>
2
- import Button from "../ui/button/button.svelte";
3
- import { ctx } from "../../store.svelte";
2
+ import Button from "../../components/ui/button/button.svelte";
3
+ import { getStudioContext } from "../../context";
4
4
  import { location } from "@wjfe/n-savant";
5
+
6
+ const { ctx } = getStudioContext();
5
7
  import { ArrowRight } from "lucide-svelte";
6
8
  </script>
7
9
 
@@ -1,16 +1,18 @@
1
1
  <script lang="ts">
2
- import type { SideBarData } from "../../sidebar/sidebarElements.svelte";
2
+ import type { SideBarData } from "../../../components/sidebar/sidebarElements.svelte";
3
3
  import WorkflowEditor, {
4
4
  type WorkflowEntry,
5
- } from "../../workflowEditor.svelte";
6
- import { lobb, ctx } from "../../../store.svelte";
7
- import Sidebar from "../../sidebar/sidebar.svelte";
8
- import Button from "../../ui/button/button.svelte";
5
+ } from "../../../components/workflowEditor.svelte";
6
+ import { getStudioContext } from "../../../context";
7
+
8
+ const { lobb, ctx } = getStudioContext();
9
+ import Sidebar from "../../../components/sidebar/sidebar.svelte";
10
+ import Button from "../../../components/ui/button/button.svelte";
9
11
  import { location } from "@wjfe/n-savant";
10
12
  import { CircleSlash2, Plus, Trash2 } from "lucide-svelte";
11
13
  import { onMount } from "svelte";
12
- import { showDialog } from "../../confirmationDialog/store.svelte";
13
- import SidebarTrigger from "../../sidebar/sidebarTrigger.svelte";
14
+ import { showDialog } from "../../../components/confirmationDialog/store.svelte";
15
+ import SidebarTrigger from "../../../components/sidebar/sidebarTrigger.svelte";
14
16
 
15
17
  let { workflowName } = $props();
16
18
 
@@ -4,8 +4,11 @@
4
4
  import DataTable from "./dataTable/dataTable.svelte";
5
5
  import { getCollectionPrimaryField } from "./dataTable/utils";
6
6
  import { emitEvent } from "../eventSystem";
7
+ import { getStudioContext } from "../context";
7
8
  import Drawer from "./drawer.svelte";
8
9
 
10
+ const { ctx, lobb } = getStudioContext();
11
+
9
12
  interface LocalProps extends ButtonProps {
10
13
  collectionName: string;
11
14
  parentCollectionName?: string;
@@ -36,6 +39,7 @@
36
39
  async function handleButtonClick() {
37
40
  try {
38
41
  const eventResult = await emitEvent(
42
+ { lobb, ctx },
39
43
  "studio.collections.preForeignKeySelect",
40
44
  {
41
45
  parentCollectionName,
@@ -55,7 +59,7 @@
55
59
  }
56
60
 
57
61
  async function onSelectHandler(entry: any) {
58
- const primaryFieldName = getCollectionPrimaryField(collectionName);
62
+ const primaryFieldName = getCollectionPrimaryField(ctx, collectionName);
59
63
  const localValue: any = {
60
64
  id: entry.id,
61
65
  };
@@ -1,8 +1,10 @@
1
1
  <script lang="ts">
2
2
  import { toast } from "svelte-sonner";
3
3
  import Button from "./ui/button/button.svelte";
4
- import { ctx } from "../store.svelte";
5
- import { Input } from "./ui/input";
4
+ import { getStudioContext } from "../context";
5
+ import { Input } from "../components/ui/input";
6
+
7
+ const { ctx } = getStudioContext();
6
8
 
7
9
  let formData = {
8
10
  server: "",
@@ -5,7 +5,9 @@
5
5
  import SidebarTrigger from "./sidebar/sidebarTrigger.svelte";
6
6
  import Button from "./ui/button/button.svelte";
7
7
  import { onMount } from "svelte";
8
- import { lobb } from "../store.svelte";
8
+ import { getStudioContext } from "../context";
9
+
10
+ const { lobb, ctx } = getStudioContext();
9
11
  import { toast } from "svelte-sonner";
10
12
  import Skeleton from "./ui/skeleton/skeleton.svelte";
11
13
 
@@ -20,7 +22,7 @@
20
22
  let entry = $state({});
21
23
  let loading = $state(true);
22
24
  let singletonExists = $state(true);
23
- const formFields = getCollectionFields(collectionName);
25
+ const formFields = getCollectionFields(ctx, collectionName);
24
26
 
25
27
  onMount(async () => {
26
28
  const result = await lobb.readSingleton(collectionName);
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { AlertDialog as AlertDialogPrimitive } from "bits-ui";
3
- import { buttonVariants } from "../button/index.js";
3
+ import { buttonVariants } from "../../../components/ui/button/index.js";
4
4
  import { cn } from "../../../utils.js";
5
5
 
6
6
  let {
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { AlertDialog as AlertDialogPrimitive } from "bits-ui";
3
- import { buttonVariants } from "../button/index.js";
3
+ import { buttonVariants } from "../../../components/ui/button/index.js";
4
4
  import { cn } from "../../../utils.js";
5
5
 
6
6
  let {
@@ -6,7 +6,7 @@
6
6
  } from "bits-ui";
7
7
  import type { Snippet } from "svelte";
8
8
  import Command from "./command.svelte";
9
- import * as Dialog from "../dialog/index.js";
9
+ import * as Dialog from "../../../components/ui/dialog/index.js";
10
10
 
11
11
  let {
12
12
  open = $bindable(false),
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { RangeCalendar as RangeCalendarPrimitive } from "bits-ui";
3
- import { buttonVariants } from "../button/index.js";
3
+ import { buttonVariants } from "../../../components/ui/button/index.js";
4
4
  import { cn } from "../../../utils.js";
5
5
 
6
6
  let {
@@ -1,6 +1,6 @@
1
1
  import { RangeCalendar as RangeCalendarPrimitive } from "bits-ui";
2
2
  declare const RangeCalendarDay: import("svelte").Component<RangeCalendarPrimitive.DayProps, {
3
- class: import("svelte/elements").ClassValue;
3
+ class: import("svelte/elements.js").ClassValue;
4
4
  }, "ref">;
5
5
  type RangeCalendarDay = ReturnType<typeof RangeCalendarDay>;
6
6
  export default RangeCalendarDay;
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { RangeCalendar as RangeCalendarPrimitive } from "bits-ui";
3
3
  import ChevronRight from "@lucide/svelte/icons/chevron-right";
4
- import { buttonVariants } from "../button/index.js";
4
+ import { buttonVariants } from "../../../components/ui/button/index.js";
5
5
  import { cn } from "../../../utils.js";
6
6
  let {
7
7
  ref = $bindable(null),
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { RangeCalendar as RangeCalendarPrimitive } from "bits-ui";
3
3
  import ChevronLeft from "@lucide/svelte/icons/chevron-left";
4
- import { buttonVariants } from "../button/index.js";
4
+ import { buttonVariants } from "../../../components/ui/button/index.js";
5
5
  import { cn } from "../../../utils.js";
6
6
  let {
7
7
  ref = $bindable(null),
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { Separator as SeparatorPrimitive } from "bits-ui";
3
- import { Separator } from "../separator/index.js";
3
+ import { Separator } from "../../../components/ui/separator/index.js";
4
4
  import { cn } from "../../../utils.js";
5
5
 
6
6
  let {
@@ -11,10 +11,12 @@
11
11
  </script>
12
12
 
13
13
  <script lang="ts">
14
- import { lobb, ctx } from "../store.svelte";
15
- import CodeEditor from "./codeEditor.svelte";
16
- import Button from "./ui/button/button.svelte";
17
- import Input from "./ui/input/input.svelte";
14
+ import { getStudioContext } from "../context";
15
+ import CodeEditor from "../components/codeEditor.svelte";
16
+
17
+ const { lobb, ctx } = getStudioContext();
18
+ import Button from "../components/ui/button/button.svelte";
19
+ import Input from "../components/ui/input/input.svelte";
18
20
  import { location } from "@wjfe/n-savant";
19
21
  import { Edit, Plus } from "lucide-svelte";
20
22
  import { toast } from "svelte-sonner";
@@ -0,0 +1,10 @@
1
+ import type { LobbClient } from '@lobb-js/sdk';
2
+ import type { CTX } from './store.types';
3
+ export interface StudioContext {
4
+ ctx: CTX;
5
+ lobb: LobbClient;
6
+ }
7
+ export declare const STUDIO_CONTEXT_KEY: unique symbol;
8
+ export declare function setStudioContext(context: StudioContext): void;
9
+ export declare function getStudioContext(): StudioContext;
10
+ export declare function createStudioContextMap(context: StudioContext): Map<symbol, StudioContext>;
@@ -0,0 +1,11 @@
1
+ import { setContext, getContext } from 'svelte';
2
+ export var STUDIO_CONTEXT_KEY = Symbol('studio');
3
+ export function setStudioContext(context) {
4
+ setContext(STUDIO_CONTEXT_KEY, context);
5
+ }
6
+ export function getStudioContext() {
7
+ return getContext(STUDIO_CONTEXT_KEY);
8
+ }
9
+ export function createStudioContextMap(context) {
10
+ return new Map([[STUDIO_CONTEXT_KEY, context]]);
11
+ }
@@ -1 +1,2 @@
1
- export declare function emitEvent(eventName: string, input: Record<string, any>): Promise<Record<string, any>>;
1
+ import type { StudioContext } from "./context";
2
+ export declare function emitEvent(studioContext: StudioContext, eventName: string, input: Record<string, any>): Promise<Record<string, any>>;
@@ -35,14 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import { toast } from "svelte-sonner";
38
- import { ctx } from "./store.svelte";
39
38
  import { openCreateDetailView, openUpdateDetailView } from "./components/detailView/store.svelte";
40
- export function emitEvent(eventName, input) {
39
+ export function emitEvent(studioContext, eventName, input) {
41
40
  return __awaiter(this, void 0, void 0, function () {
42
- var workflows, index, workflow, localOutput, _a, _b, _c, error_1;
41
+ var ctx, workflows, index, workflow, localOutput, _a, _b, _c, error_1;
43
42
  return __generator(this, function (_d) {
44
43
  switch (_d.label) {
45
44
  case 0:
45
+ ctx = studioContext.ctx;
46
46
  workflows = ctx.meta.studio_workflows.filter(function (workflow) {
47
47
  return eventName.startsWith(workflow.eventName);
48
48
  });
@@ -56,7 +56,7 @@ export function emitEvent(eventName, input) {
56
56
  _d.trys.push([2, 5, , 6]);
57
57
  _b = (_a = workflow).handler;
58
58
  _c = [input];
59
- return [4 /*yield*/, getEventContext()];
59
+ return [4 /*yield*/, getEventContext(studioContext)];
60
60
  case 3: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent()]))];
61
61
  case 4:
62
62
  localOutput = _d.sent();
@@ -76,13 +76,13 @@ export function emitEvent(eventName, input) {
76
76
  });
77
77
  });
78
78
  }
79
- function getEventContext() {
79
+ function getEventContext(studioContext) {
80
80
  return __awaiter(this, void 0, void 0, function () {
81
81
  return __generator(this, function (_a) {
82
82
  return [2 /*return*/, {
83
83
  toast: toast,
84
- openCreateDetailView: openCreateDetailView,
85
- openUpdateDetailView: openUpdateDetailView,
84
+ openCreateDetailView: function (props) { return openCreateDetailView(studioContext, props); },
85
+ openUpdateDetailView: function (props) { return openUpdateDetailView(studioContext, props); },
86
86
  }];
87
87
  });
88
88
  });
@@ -1,8 +1,9 @@
1
1
  import type { Components, DashboardNavs, Extension, ExtensionUtils } from "./extension.types";
2
+ import type { LobbClient } from "@lobb-js/sdk";
3
+ import type { CTX } from "../store.types";
2
4
  export declare function getComponents(): Components;
3
- export declare function getExtensionUtils(): ExtensionUtils;
4
- export declare function getExtensionsThatHasDash(): string[];
5
- export declare function loadExtensions(studioExtensions?: any[]): Promise<Record<string, Extension>>;
6
- export declare function loadExtensionComponents(name: string, filterByExtensions?: string[]): any[];
7
- export declare function executeExtensionsOnStartup(): Promise<void>;
8
- export declare function getDashboardNavs(): DashboardNavs;
5
+ export declare function getExtensionUtils(lobb: LobbClient, ctx: CTX): ExtensionUtils;
6
+ export declare function loadExtensions(lobb: LobbClient, ctx: CTX, extensionMap?: Record<string, any>): Promise<Record<string, Extension>>;
7
+ export declare function loadExtensionComponents(ctx: CTX, name: string, filterByExtensions?: string[]): any[];
8
+ export declare function executeExtensionsOnStartup(lobb: LobbClient, ctx: CTX): Promise<void>;
9
+ export declare function getDashboardNavs(ctx: CTX): DashboardNavs;
@@ -43,7 +43,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
43
43
  }
44
44
  return to.concat(ar || Array.prototype.slice.call(from));
45
45
  };
46
- import { lobb, ctx } from "../store.svelte";
47
46
  import { toast } from "svelte-sonner";
48
47
  import { showDialog } from "../components/confirmationDialog/store.svelte";
49
48
  import { Button } from "../components/ui/button";
@@ -93,7 +92,7 @@ export function getComponents() {
93
92
  Switch: Switch,
94
93
  };
95
94
  }
96
- export function getExtensionUtils() {
95
+ export function getExtensionUtils(lobb, ctx) {
97
96
  return {
98
97
  ctx: ctx,
99
98
  lobb: lobb,
@@ -105,65 +104,23 @@ export function getExtensionUtils() {
105
104
  intlDate: intlDate,
106
105
  };
107
106
  }
108
- export function getExtensionsThatHasDash() {
109
- var extensionNames = Object.keys(ctx.meta.extensions);
110
- var extensionsWithDashExt = [];
111
- for (var index = 0; index < extensionNames.length; index++) {
112
- var extensionName = extensionNames[index];
113
- var extensionMeta = ctx.meta.extensions[extensionName];
114
- if (extensionMeta.hasDashboardExtension) {
115
- extensionsWithDashExt.push(extensionName);
116
- }
117
- }
118
- return extensionsWithDashExt;
119
- }
120
- export function loadExtensions(studioExtensions) {
121
- return __awaiter(this, void 0, Promise, function () {
122
- var extensions, index, studioExtension, extensionsThatHasDash, index, extensionName, _a, _b, error_1;
123
- var _c;
124
- return __generator(this, function (_d) {
125
- switch (_d.label) {
126
- case 0:
127
- extensions = {};
128
- if (studioExtensions) {
129
- for (index = 0; index < studioExtensions.length; index++) {
130
- studioExtension = studioExtensions[index](getExtensionUtils());
131
- extensions[studioExtension.name] = studioExtension;
132
- }
133
- }
134
- extensionsThatHasDash = getExtensionsThatHasDash();
135
- index = 0;
136
- _d.label = 1;
137
- case 1:
138
- if (!(index < extensionsThatHasDash.length)) return [3 /*break*/, 6];
139
- extensionName = extensionsThatHasDash[index];
140
- // Try to import locally-installed extension by name first
141
- if (extensionName && extensions[extensionName]) {
142
- return [3 /*break*/, 5];
143
- }
144
- _d.label = 2;
145
- case 2:
146
- _d.trys.push([2, 4, , 5]);
147
- _a = extensions;
148
- _b = extensionName;
149
- return [4 /*yield*/, import(
150
- /* @vite-ignore */ "".concat(ctx.lobbUrl, "/api/extensions/").concat(extensionName, "/dashboard?v=").concat((_c = ctx.meta.extensions[extensionName]) === null || _c === void 0 ? void 0 : _c.version))];
151
- case 3:
152
- _a[_b] = (_d.sent()).extension(getExtensionUtils());
153
- return [3 /*break*/, 5];
154
- case 4:
155
- error_1 = _d.sent();
156
- console.warn("Failed to load remote extension ".concat(extensionName), error_1);
157
- return [3 /*break*/, 5];
158
- case 5:
159
- index++;
160
- return [3 /*break*/, 1];
161
- case 6: return [2 /*return*/, extensions];
107
+ export function loadExtensions(lobb_1, ctx_1) {
108
+ return __awaiter(this, arguments, Promise, function (lobb, ctx, extensionMap) {
109
+ var extensions, extensionNames, index, extensionName, studioExtension;
110
+ if (extensionMap === void 0) { extensionMap = {}; }
111
+ return __generator(this, function (_a) {
112
+ extensions = {};
113
+ extensionNames = Object.keys(extensionMap).filter(function (name) { return ctx.meta.extensions[name] != null; });
114
+ for (index = 0; index < extensionNames.length; index++) {
115
+ extensionName = extensionNames[index];
116
+ studioExtension = extensionMap[extensionName](getExtensionUtils(lobb, ctx));
117
+ extensions[studioExtension.name] = studioExtension;
162
118
  }
119
+ return [2 /*return*/, extensions];
163
120
  });
164
121
  });
165
122
  }
166
- export function loadExtensionComponents(name, filterByExtensions) {
123
+ export function loadExtensionComponents(ctx, name, filterByExtensions) {
167
124
  var components = [];
168
125
  for (var _i = 0, _a = Object.entries(ctx.extensions); _i < _a.length; _i++) {
169
126
  var _b = _a[_i], extensionName = _b[0], extensionValue = _b[1];
@@ -181,7 +138,7 @@ export function loadExtensionComponents(name, filterByExtensions) {
181
138
  }
182
139
  return components;
183
140
  }
184
- export function executeExtensionsOnStartup() {
141
+ export function executeExtensionsOnStartup(lobb, ctx) {
185
142
  return __awaiter(this, void 0, void 0, function () {
186
143
  var extensionNames, index, extensionName, extension;
187
144
  return __generator(this, function (_a) {
@@ -196,7 +153,7 @@ export function executeExtensionsOnStartup() {
196
153
  extension = ctx.extensions[extensionName];
197
154
  if (!extension) return [3 /*break*/, 3];
198
155
  if (!extension.onStartup) return [3 /*break*/, 3];
199
- return [4 /*yield*/, extension.onStartup(getExtensionUtils())];
156
+ return [4 /*yield*/, extension.onStartup(getExtensionUtils(lobb, ctx))];
200
157
  case 2:
201
158
  _a.sent();
202
159
  _a.label = 3;
@@ -208,7 +165,7 @@ export function executeExtensionsOnStartup() {
208
165
  });
209
166
  });
210
167
  }
211
- export function getDashboardNavs() {
168
+ export function getDashboardNavs(ctx) {
212
169
  var navs = {
213
170
  top: [],
214
171
  middle: [],
@@ -1,3 +1 @@
1
- import type { CTX } from './store.types';
2
- export declare const ctx: CTX;
3
- export declare const lobb: any;
1
+ export declare function createLobb(url: string): any;
@@ -36,40 +36,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import { LobbClient } from '@lobb-js/sdk';
38
38
  import { toast } from 'svelte-sonner';
39
- if (!window.APP_ENV) {
40
- window.APP_ENV = {};
41
- }
42
- if (window.APP_ENV.LOBB_URL === '%LOBB_URL%') {
43
- window.APP_ENV.LOBB_URL = null;
39
+ export function createLobb(url) {
40
+ var _this = this;
41
+ var client = new LobbClient(url);
42
+ client.onResponse(function (response) { return __awaiter(_this, void 0, void 0, function () {
43
+ var body;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ if (!(response.status >= 400)) return [3 /*break*/, 2];
48
+ return [4 /*yield*/, response.json()];
49
+ case 1:
50
+ body = _a.sent();
51
+ toast.error(body.message);
52
+ _a.label = 2;
53
+ case 2: return [2 /*return*/];
54
+ }
55
+ });
56
+ }); });
57
+ return client;
44
58
  }
45
- // TODO: this state should be passed to the Studio component in the App.svelte it should be its paramters
46
- // TODO: using a global variable is not good to pass data to children components. using the context api is better for only components builder or wrappers
47
- // TODO: you should totally remove this file
48
- // TODO: when you finish doind that add the studioVersion back
49
- export var ctx = $state.raw({
50
- // studioVersion: pkg.version,
51
- lobbUrl: window.APP_ENV.LOBB_URL || localStorage.getItem("lobb_url"),
52
- extensions: {},
53
- meta: {
54
- collections: null,
55
- extensions: null,
56
- filter: null
57
- },
58
- });
59
- export var lobb = new LobbClient(ctx.lobbUrl);
60
- // logging the message if got any bad responses
61
- lobb.onResponse(function (response) { return __awaiter(void 0, void 0, void 0, function () {
62
- var body;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0:
66
- if (!(response.status >= 400)) return [3 /*break*/, 2];
67
- return [4 /*yield*/, response.json()];
68
- case 1:
69
- body = _a.sent();
70
- toast.error(body.message);
71
- _a.label = 2;
72
- case 2: return [2 /*return*/];
73
- }
74
- });
75
- }); });
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type ClassValue } from "clsx";
2
2
  import { MediaQuery } from 'svelte/reactivity';
3
+ import type { CTX } from "./store.types";
3
4
  export declare function cn(...inputs: ClassValue[]): string;
4
5
  export type WithoutChild<T> = T extends {
5
6
  child?: any;
@@ -18,8 +19,8 @@ export declare const mediaQueries: {
18
19
  xl: MediaQuery;
19
20
  '2xl': MediaQuery;
20
21
  };
21
- export declare function getFieldRelation(collectionName: string, fieldName: string): any;
22
- export declare function recordHasChildrean(collectionName: string): boolean;
22
+ export declare function getFieldRelation(ctx: CTX, collectionName: string, fieldName: string): any;
23
+ export declare function recordHasChildrean(ctx: CTX, collectionName: string): boolean;
23
24
  export declare function calculateDrawerWidth(): number;
24
25
  export declare function getChangedProperties(oldObj: Record<string, any>, newObj: Record<string, any>): Record<string, any>;
25
26
  export declare function parseFunction(functionString: string): any;
package/dist/utils.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { clsx } from "clsx";
2
2
  import { twMerge } from "tailwind-merge";
3
3
  import { MediaQuery } from 'svelte/reactivity';
4
- import { ctx } from "./store.svelte";
5
4
  export function cn() {
6
5
  var inputs = [];
7
6
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -16,7 +15,7 @@ export var mediaQueries = {
16
15
  xl: new MediaQuery('min-width: 1280px'),
17
16
  '2xl': new MediaQuery('min-width: 1536px'),
18
17
  };
19
- export function getFieldRelation(collectionName, fieldName) {
18
+ export function getFieldRelation(ctx, collectionName, fieldName) {
20
19
  var relations = ctx.meta.relations;
21
20
  for (var index = 0; index < relations.length; index++) {
22
21
  var relation = relations[index];
@@ -27,7 +26,7 @@ export function getFieldRelation(collectionName, fieldName) {
27
26
  return null;
28
27
  }
29
28
  ;
30
- export function recordHasChildrean(collectionName) {
29
+ export function recordHasChildrean(ctx, collectionName) {
31
30
  for (var index = 0; index < ctx.meta.relations.length; index++) {
32
31
  var relation = ctx.meta.relations[index];
33
32
  if (relation.to.collection === collectionName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobb-js/studio",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,7 +14,11 @@
14
14
  "svelte": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts"
16
16
  },
17
- "./vite-plugins": "./vite-plugins/index.js"
17
+ "./app.css": "./src/app.css",
18
+ "./vite-plugins": {
19
+ "types": "./vite-plugins/index.d.ts",
20
+ "default": "./vite-plugins/index.js"
21
+ }
18
22
  },
19
23
  "scripts": {
20
24
  "dev": "vite",
@@ -0,0 +1,8 @@
1
+ declare module "virtual:lobb-studio-extensions" {
2
+ const extensions: Record<string, (utils: any) => any>;
3
+ export default extensions;
4
+ }
5
+
6
+ // Returns an array of Vite plugins. Typed as any[] to avoid version conflicts
7
+ // between the vite version used by packages/studio and the consumer's vite version.
8
+ export function lobbStudioPlugins(): any[];
@@ -1,16 +1,11 @@
1
1
  import { contextualLibAlias } from "./contextual-lib-alias.js";
2
+ import { lobbWorkspaceOptimize } from "./monorepo-workspace.js";
3
+ import { lobbExtensionsPlugin } from "./lobb-extensions.js";
2
4
 
3
- /**
4
- * Returns an array of Vite plugins needed for Lobb Studio integration.
5
- *
6
- * Includes:
7
- * - monorepoImportResolver: Resolves @lobb-js/studio to /internal (monorepo) or default (standalone)
8
- * - contextualLibAlias: Resolves $lib imports contextually
9
- *
10
- * @returns {import('vite').Plugin[]}
11
- */
12
5
  export function lobbStudioPlugins() {
13
6
  return [
14
7
  contextualLibAlias(),
8
+ lobbWorkspaceOptimize(),
9
+ lobbExtensionsPlugin(),
15
10
  ];
16
11
  }