@lobb-js/studio 0.4.0 → 0.6.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 (68) 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 -0
  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 +11 -12
  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/richTextEditor.svelte +1 -1
  38. package/dist/components/routes/collections/collection.svelte +8 -6
  39. package/dist/components/routes/collections/collections.svelte +5 -3
  40. package/dist/components/routes/data_model/dataModel.svelte +2 -2
  41. package/dist/components/routes/data_model/flow.svelte +3 -1
  42. package/dist/components/routes/data_model/syncManager.svelte +7 -5
  43. package/dist/components/routes/extensions/extension.svelte +5 -2
  44. package/dist/components/routes/home.svelte +4 -2
  45. package/dist/components/routes/workflows/workflows.svelte +9 -7
  46. package/dist/components/selectRecord.svelte +5 -1
  47. package/dist/components/setServerPage.svelte +4 -2
  48. package/dist/components/singletone.svelte +4 -2
  49. package/dist/components/ui/alert-dialog/alert-dialog-action.svelte +1 -1
  50. package/dist/components/ui/alert-dialog/alert-dialog-cancel.svelte +1 -1
  51. package/dist/components/ui/command/command-dialog.svelte +1 -1
  52. package/dist/components/ui/range-calendar/range-calendar-day.svelte +1 -1
  53. package/dist/components/ui/range-calendar/range-calendar-day.svelte.d.ts +1 -1
  54. package/dist/components/ui/range-calendar/range-calendar-next-button.svelte +1 -1
  55. package/dist/components/ui/range-calendar/range-calendar-prev-button.svelte +1 -1
  56. package/dist/components/ui/select/select-separator.svelte +1 -1
  57. package/dist/components/workflowEditor.svelte +6 -4
  58. package/dist/context.d.ts +10 -0
  59. package/dist/context.js +11 -0
  60. package/dist/eventSystem.d.ts +2 -1
  61. package/dist/eventSystem.js +7 -7
  62. package/dist/extensions/extensionUtils.d.ts +8 -6
  63. package/dist/extensions/extensionUtils.js +10 -11
  64. package/dist/store.svelte.d.ts +1 -3
  65. package/dist/store.svelte.js +19 -36
  66. package/dist/utils.d.ts +3 -2
  67. package/dist/utils.js +2 -3
  68. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
1
  <script lang="ts">
2
- import { lobb, ctx } from "../store.svelte";
2
+ import { getStudioContext } from "../context";
3
3
  import { Brain, LoaderIcon, Send } from "lucide-svelte";
4
+
5
+ const { lobb, ctx } = getStudioContext();
4
6
  import Button, { type ButtonProps } from "./ui/button/button.svelte";
5
7
  import * as Popover from "./ui/popover";
6
8
  import Textarea from "./ui/textarea/textarea.svelte";
@@ -1,15 +1,14 @@
1
1
  <script lang="ts">
2
- import { Toaster } from "./ui/sonner";
2
+ import { Toaster } from "../components/ui/sonner";
3
3
  import { onMount, onDestroy } from "svelte";
4
4
  import { ModeWatcher } from "mode-watcher";
5
- import { lobb, ctx } from "../store.svelte";
6
- import Header from "./header.svelte";
5
+ import { createLobb } from "../store.svelte";
6
+ import { setStudioContext } from "../context";
7
+ import Header from "../components/header.svelte";
7
8
  import { LoaderCircle, ServerOff } from "lucide-svelte";
8
- import Dialog from "./confirmationDialog/confirmationDialog.svelte";
9
- import MiniSidebar from "./miniSidebar.svelte";
10
- import SetServerPage from "./setServerPage.svelte";
11
- import * as Tooltip from "./ui/tooltip";
12
- import { Router, Route, Fallback, init as initRouter, } from "@wjfe/n-savant";
9
+ import MiniSidebar from "../components/miniSidebar.svelte";
10
+ import * as Tooltip from "../components/ui/tooltip";
11
+ import { Router, Route, Fallback, init as initRouter } from "@wjfe/n-savant";
13
12
  import {
14
13
  executeExtensionsOnStartup,
15
14
  loadExtensions,
@@ -22,123 +21,104 @@
22
21
  import Extension from "./routes/extensions/extension.svelte";
23
22
 
24
23
  interface StudioProps {
25
- extensions?: any[];
24
+ extensions?: any[];
25
+ lobbUrl?: string;
26
26
  }
27
27
 
28
- const props: StudioProps = $props()
28
+ const { lobbUrl, extensions }: StudioProps = $props();
29
29
 
30
- let error: string | null = $state(null);
31
- let loaded = $state(false);
30
+ const ctx = $state({
31
+ lobbUrl: lobbUrl ?? "",
32
+ extensions: {},
33
+ meta: null,
34
+ currentUrl: new URL(window.location.href),
35
+ });
36
+
37
+ const lobb = createLobb(lobbUrl ?? "");
38
+
39
+ setStudioContext({ ctx, lobb });
40
+
41
+ let status: "loading" | "error" | "ready" = $state("loading");
32
42
  let isSmallScreen = $derived(!mediaQueries.sm.current);
33
43
  let cleanupRouter: (() => void) | undefined;
34
44
 
35
45
  onMount(async () => {
36
46
  cleanupRouter = initRouter();
37
-
38
- if (ctx.lobbUrl) {
39
- try {
40
- ctx.meta = await lobb.getMeta();
41
- ctx.extensions = await loadExtensions(props.extensions);
42
- await executeExtensionsOnStartup();
43
- } catch (err) {
44
- console.error(err);
45
- error = "CANT_CONNECT";
46
- }
47
+ try {
48
+ ctx.meta = await lobb.getMeta();
49
+ ctx.extensions = await loadExtensions(lobb, ctx, extensions);
50
+ await executeExtensionsOnStartup(lobb, ctx);
51
+ status = "ready";
52
+ } catch (err) {
53
+ console.error(err);
54
+ status = "error";
47
55
  }
48
- loaded = true;
49
56
  });
50
57
 
51
58
  onDestroy(() => {
52
- if (cleanupRouter) {
53
- cleanupRouter();
54
- }
59
+ if (cleanupRouter) cleanupRouter();
55
60
  });
56
61
  </script>
57
62
 
58
63
  <ModeWatcher defaultMode="light" />
59
64
  <Toaster position="top-right" class="z-50" />
60
- {#if loaded}
61
- {#if ctx.lobbUrl}
62
- <Tooltip.Provider delayDuration={0} disableHoverableContent={true}>
63
- <main
64
- class="bg-muted h-screen w-screen"
65
- style="display: grid; grid-template-columns: {isSmallScreen
66
- ? '1fr'
67
- : '3.5rem 1fr'};"
68
- >
69
- <MiniSidebar />
70
- <div class="second_grid">
71
- <Header />
72
- <Router id="root-router" basePath="/studio">
73
- <Route key="home" path="/">
74
- {#snippet children(params)}
75
- <Home />
76
- {/snippet}
77
- </Route>
78
- <Route
79
- key="collections"
80
- path="/collections/:collection?"
81
- >
82
- {#snippet children(params)}
83
- <Collections
84
- collectionName={params?.collection}
85
- />
86
- {/snippet}
87
- </Route>
88
- <Route key="datamodel" path="/datamodel/*">
89
- {#snippet children(params)}
90
- <DataModel />
91
- {/snippet}
92
- </Route>
93
- <Route key="workflows" path="/workflows/:workflow?">
94
- {#snippet children(params)}
95
- <Workflows workflowName={params?.workflow} />
96
- {/snippet}
97
- </Route>
98
- <Route
99
- key="extensions"
100
- path="/extensions/:extension?/:page?/*"
101
- >
102
- {#snippet children(params)}
103
- <Extension
104
- extension={params?.extension}
105
- page={params?.page}
106
- />
107
- {/snippet}
108
- </Route>
109
- <Fallback>Not Found</Fallback>
110
- </Router>
111
- </div>
112
- </main>
113
- </Tooltip.Provider>
114
- {:else}
115
- <SetServerPage />
116
- {/if}
117
- {:else if !error}
118
- <div
119
- class="flex h-screen w-full flex-col items-center justify-center gap-4 text-muted-foreground"
120
- >
65
+
66
+ {#if status === "loading"}
67
+ <div class="flex h-screen w-full flex-col items-center justify-center gap-4 text-muted-foreground">
121
68
  <LoaderCircle class="animate-spin opacity-50" size="50" />
122
69
  <div class="flex flex-col items-center justify-center">
123
70
  <div>Loading the dashboard, please wait...</div>
124
- <div class="text-xs">
125
- Loading and importing all necessary data and components from the
126
- lobb server.
127
- </div>
71
+ <div class="text-xs">Loading and importing all necessary data and components from the lobb server.</div>
128
72
  </div>
129
73
  </div>
130
- {:else}
131
- <div
132
- class="flex h-full w-full flex-col items-center justify-center gap-4 text-muted-foreground"
133
- >
74
+ {:else if status === "error"}
75
+ <div class="flex h-screen w-full flex-col items-center justify-center gap-4 text-muted-foreground">
134
76
  <ServerOff class="opacity-50" size="50" />
135
77
  <div class="flex flex-col items-center justify-center">
136
78
  <div>Could not connect to the server</div>
137
- <div class="text-xs">
138
- Could not connect to the lobb server at this endpoint ({ctx.lobbUrl})
139
- </div>
79
+ <div class="text-xs">Could not connect to the lobb server at this endpoint ({ctx.lobbUrl})</div>
140
80
  </div>
141
81
  </div>
82
+ {:else}
83
+ <Tooltip.Provider delayDuration={0} disableHoverableContent={true}>
84
+ <main
85
+ class="bg-muted h-screen w-screen"
86
+ style="display: grid; grid-template-columns: {isSmallScreen ? '1fr' : '3.5rem 1fr'};"
87
+ >
88
+ <MiniSidebar />
89
+ <div class="second_grid">
90
+ <Header />
91
+ <Router id="root-router" basePath="/studio">
92
+ <Route key="home" path="/">
93
+ {#snippet children(params)}
94
+ <Home />
95
+ {/snippet}
96
+ </Route>
97
+ <Route key="collections" path="/collections/:collection?">
98
+ {#snippet children(params)}
99
+ <Collections collectionName={params?.collection} />
100
+ {/snippet}
101
+ </Route>
102
+ <Route key="datamodel" path="/datamodel/*">
103
+ {#snippet children(params)}
104
+ <DataModel />
105
+ {/snippet}
106
+ </Route>
107
+ <Route key="workflows" path="/workflows/:workflow?">
108
+ {#snippet children(params)}
109
+ <Workflows workflowName={params?.workflow} />
110
+ {/snippet}
111
+ </Route>
112
+ <Route key="extensions" path="/extensions/:extension?/:page?/*">
113
+ {#snippet children(params)}
114
+ <Extension extension={params?.extension} page={params?.page} />
115
+ {/snippet}
116
+ </Route>
117
+ <Fallback>Not Found</Fallback>
118
+ </Router>
119
+ </div>
120
+ </main>
121
+ </Tooltip.Provider>
142
122
  {/if}
143
123
 
144
124
  <style>
@@ -1,5 +1,6 @@
1
1
  interface StudioProps {
2
2
  extensions?: any[];
3
+ lobbUrl?: string;
3
4
  }
4
5
  declare const Studio: import("svelte").Component<StudioProps, {}, "">;
5
6
  type Studio = ReturnType<typeof Studio>;
@@ -1,6 +1,5 @@
1
1
  <script lang="ts">
2
2
  import * as Breadcrumb from "./ui/breadcrumb";
3
- import { ctx } from "../store.svelte";
4
3
  import { mediaQueries } from "../utils";
5
4
  import { location } from "@wjfe/n-savant";
6
5
 
@@ -2,9 +2,9 @@
2
2
  import CheckIcon from "@lucide/svelte/icons/check";
3
3
  import ChevronsUpDownIcon from "@lucide/svelte/icons/chevrons-up-down";
4
4
  import { tick } from "svelte";
5
- import * as Command from "./ui/command/index.js";
6
- import * as Popover from "./ui/popover/index.js";
7
- import { Button } from "./ui/button/index.js";
5
+ import * as Command from "../components/ui/command/index.js";
6
+ import * as Popover from "../components/ui/popover/index.js";
7
+ import { Button } from "../components/ui/button/index.js";
8
8
  import { cn } from "../utils.js";
9
9
  import type { HTMLButtonAttributes } from "svelte/elements";
10
10
 
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import * as AlertDialog from "../ui/alert-dialog/index";
2
+ import * as AlertDialog from "../../components/ui/alert-dialog/index";
3
3
  import { Check, X } from "lucide-svelte";
4
4
  import Button from "../ui/button/button.svelte";
5
5
 
@@ -4,8 +4,10 @@
4
4
  import Button, { type ButtonProps } from "./ui/button/button.svelte";
5
5
  import { toast } from "svelte-sonner";
6
6
  import CodeEditor from "./codeEditor.svelte";
7
- import { lobb } from "../store.svelte";
7
+ import { getStudioContext } from "../context";
8
8
  import { calculateDrawerWidth } from "../utils";
9
+
10
+ const { lobb } = getStudioContext();
9
11
  import Drawer from "./drawer.svelte";
10
12
 
11
13
  interface LocalProps extends ButtonProps {
@@ -1,11 +1,13 @@
1
1
  <script lang="ts">
2
- import { ctx } from "../../store.svelte";
2
+ import { getStudioContext } from "../../context";
3
3
  import { ChevronRight, Plus, Smartphone, Table } from "lucide-svelte";
4
4
  import DataTable from "./dataTable.svelte";
5
5
  import CreateDetailViewButton from "../detailView/create/createDetailViewButton.svelte";
6
6
  import ExtensionsComponents from "../extensionsComponents.svelte";
7
7
  import { getExtensionUtils } from "../../extensions/extensionUtils";
8
8
 
9
+ const { ctx, lobb } = getStudioContext();
10
+
9
11
  interface Props {
10
12
  collectionName: string;
11
13
  recordId: string;
@@ -112,7 +114,7 @@
112
114
  filter={{
113
115
  [fromField]: recordId,
114
116
  }}
115
- utils={getExtensionUtils()}
117
+ utils={getExtensionUtils(lobb, ctx)}
116
118
  >
117
119
  <DataTable
118
120
  collectionName={fromCollection}
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import _ from "lodash";
3
- import { lobb, ctx } from "../../store.svelte";
3
+ import { getStudioContext } from "../../context";
4
4
  import Footer from "./footer.svelte";
5
5
  import Header from "./header.svelte";
6
6
  import Table, { type TableProps } from "./table.svelte";
@@ -16,6 +16,8 @@
16
16
  import { emitEvent } from "../../eventSystem";
17
17
  import type { Snippet } from "svelte";
18
18
 
19
+ const { lobb, ctx } = getStudioContext();
20
+
19
21
  interface Props {
20
22
  collectionName: string;
21
23
  filter?: any;
@@ -38,7 +40,7 @@
38
40
  headerLeft,
39
41
  }: Props = $props();
40
42
 
41
- const fields = getCollectionParamsFields(collectionName);
43
+ const fields = getCollectionParamsFields(ctx, collectionName);
42
44
  let params = $state({
43
45
  fields: fields,
44
46
  filter: filter ?? {},
@@ -52,7 +54,7 @@
52
54
  let data: TableProps["data"] = $state([]);
53
55
  let loading = $state(true);
54
56
  const columns: TableProps["columns"] = $state(
55
- getCollectionColumns(collectionName),
57
+ getCollectionColumns(ctx, collectionName),
56
58
  );
57
59
  let dataTableContainerWidth: number = $state(0);
58
60
  let dataTableWidth: number = $state(0);
@@ -105,6 +107,7 @@
105
107
  ): Promise<any[]> {
106
108
  // TODO: instead of firing the events like this. get them all the fire them one by one to get their results
107
109
  const eventResult = await emitEvent(
110
+ { lobb, ctx },
108
111
  "studio.collections.listView.tools",
109
112
  {
110
113
  collectionName,
@@ -4,6 +4,9 @@
4
4
  import UpdateDetailViewButton from "../detailView/update/updateDetailViewButton.svelte";
5
5
  import { getField } from "./utils";
6
6
  import _ from "lodash";
7
+ import { getStudioContext } from "../../context";
8
+
9
+ const { ctx } = getStudioContext();
7
10
 
8
11
  interface Props {
9
12
  collectionName: string;
@@ -21,10 +24,10 @@
21
24
  tableParams = $bindable(),
22
25
  }: Props = $props();
23
26
 
24
- const field = getField(fieldName, collectionName);
25
- const relation = getFieldRelation(collectionName, fieldName);
27
+ const field = getField(ctx, fieldName, collectionName);
28
+ const relation = getFieldRelation(ctx, collectionName, fieldName);
26
29
  const isRefrenceField = Boolean(
27
- getFieldRelation(collectionName, fieldName),
30
+ getFieldRelation(ctx, collectionName, fieldName),
28
31
  );
29
32
  </script>
30
33
 
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import * as Popover from "../ui/popover/index.js";
2
+ import * as Popover from "../../components/ui/popover/index.js";
3
3
  import Filter from "./filter.svelte";
4
4
  import {
5
5
  Plus,
@@ -11,9 +11,11 @@
11
11
  } from "lucide-svelte";
12
12
  import { buttonVariants } from "../ui/button";
13
13
  import _ from "lodash";
14
- import { ctx } from "../../store.svelte";
14
+ import { getStudioContext } from "../../context";
15
15
  import Button from "../ui/button/button.svelte";
16
16
 
17
+ const { ctx } = getStudioContext();
18
+
17
19
  interface Props {
18
20
  filter: any;
19
21
  collectionName: string;
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import * as Popover from "../ui/popover/index.js";
2
+ import * as Popover from "../../components/ui/popover/index.js";
3
3
  import { ListFilter } from "lucide-svelte";
4
4
  import { buttonVariants } from "../ui/button";
5
5
  import Filter from "./filter.svelte";
@@ -1,5 +1,7 @@
1
1
  <script lang="ts">
2
- import { lobb, ctx } from "../../store.svelte";
2
+ import { getStudioContext } from "../../context";
3
+
4
+ const { lobb, ctx } = getStudioContext();
3
5
  import { ListRestart, Plus, SquareStack, Trash } from "lucide-svelte";
4
6
  import LlmButton from "../LlmButton.svelte";
5
7
  import FilterButton from "./filterButton.svelte";
@@ -1,14 +1,16 @@
1
1
  <script lang="ts">
2
2
  import _ from "lodash";
3
3
 
4
- import * as Popover from "../ui/popover/index.js";
4
+ import * as Popover from "../../components/ui/popover/index.js";
5
5
  import { ArrowDown, ArrowUp, GripVertical, Plus, X } from "lucide-svelte";
6
6
  import Button, { buttonVariants } from "../ui/button/button.svelte";
7
7
  import Label from "../ui/label/label.svelte";
8
8
  import Switch from "../ui/switch/switch.svelte";
9
- import { ctx } from "../../store.svelte";
9
+ import { getStudioContext } from "../../context";
10
10
  import { getFieldIcon } from "./utils";
11
11
 
12
+ const { ctx } = getStudioContext();
13
+
12
14
  interface Props {
13
15
  collectionName: string;
14
16
  sort: Record<string, "asc" | "desc">;
@@ -149,7 +151,7 @@
149
151
  </Popover.Trigger>
150
152
  <Popover.Content class="flex w-48 flex-col p-2">
151
153
  {#each getFieldNames() as fieldName}
152
- {@const FieldIcon = getFieldIcon(fieldName, collectionName)}
154
+ {@const FieldIcon = getFieldIcon(ctx, fieldName, collectionName)}
153
155
  <button
154
156
  onclick={() => {
155
157
  sort[fieldName] = "asc";
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
- import * as Popover from "../ui/popover/index.js";
2
+ import * as Popover from "../../components/ui/popover/index.js";
3
3
  import { ArrowDownWideNarrow } from "lucide-svelte";
4
- import { buttonVariants } from "../ui/button";
4
+ import { buttonVariants } from "../../components/ui/button";
5
5
  import Sort from "./sort.svelte";
6
6
 
7
7
  interface Props {
@@ -1,7 +1,8 @@
1
1
  import type { TableProps } from "./table.svelte";
2
- export declare function getCollectionColumns(collectionName: string): TableProps['columns'];
3
- export declare function getFieldIcon(fieldName: string, collectionName: string): any;
4
- export declare function getFields(collectionName: string): Record<string, any>;
5
- export declare function getField(fieldName: string, collectionName: string): any;
6
- export declare function getCollectionPrimaryField(collectionName: string): string | undefined;
7
- export declare function getCollectionParamsFields(collectionName: string, allFields?: boolean): string;
2
+ import type { CTX } from "../../store.types";
3
+ export declare function getCollectionColumns(ctx: CTX, collectionName: string): TableProps['columns'];
4
+ export declare function getFieldIcon(ctx: CTX, fieldName: string, collectionName: string): any;
5
+ export declare function getFields(ctx: CTX, collectionName: string): Record<string, any>;
6
+ export declare function getField(ctx: CTX, fieldName: string, collectionName: string): any;
7
+ export declare function getCollectionPrimaryField(ctx: CTX, collectionName: string): string | undefined;
8
+ export declare function getCollectionParamsFields(ctx: CTX, collectionName: string, allFields?: boolean): string;
@@ -1,20 +1,19 @@
1
- import { ctx } from "../../store.svelte";
2
1
  import { Binary, Braces, Brackets, Calendar, CalendarClock, Clock, Hash, Key, Text, Type, } from "lucide-svelte/icons";
3
- export function getCollectionColumns(collectionName) {
4
- var collectionFields = getFields(collectionName);
2
+ export function getCollectionColumns(ctx, collectionName) {
3
+ var collectionFields = getFields(ctx, collectionName);
5
4
  var headers = [];
6
5
  for (var fieldName in collectionFields) {
7
6
  var field = collectionFields[fieldName];
8
7
  headers.push({
9
8
  id: field.key,
10
9
  subtext: field.type,
11
- icon: getFieldIcon(fieldName, collectionName),
10
+ icon: getFieldIcon(ctx, fieldName, collectionName),
12
11
  });
13
12
  }
14
13
  return headers;
15
14
  }
16
- export function getFieldIcon(fieldName, collectionName) {
17
- var field = getField(fieldName, collectionName);
15
+ export function getFieldIcon(ctx, fieldName, collectionName) {
16
+ var field = getField(ctx, fieldName, collectionName);
18
17
  if (fieldName === "id") {
19
18
  return Key;
20
19
  }
@@ -56,13 +55,13 @@ export function getFieldIcon(fieldName, collectionName) {
56
55
  }
57
56
  throw new Error("(".concat(field.type, ") doesnt have an icon"));
58
57
  }
59
- export function getFields(collectionName) {
58
+ export function getFields(ctx, collectionName) {
60
59
  return ctx.meta.collections[collectionName].fields;
61
60
  }
62
- export function getField(fieldName, collectionName) {
63
- return getFields(collectionName)[fieldName];
61
+ export function getField(ctx, fieldName, collectionName) {
62
+ return getFields(ctx, collectionName)[fieldName];
64
63
  }
65
- export function getCollectionPrimaryField(collectionName) {
64
+ export function getCollectionPrimaryField(ctx, collectionName) {
66
65
  var collectionFields = ctx.meta.collections[collectionName].fields;
67
66
  var primaryFieldObject = Object.values(collectionFields).find(function (field) { return field.type === "string"; });
68
67
  if (primaryFieldObject &&
@@ -72,7 +71,7 @@ export function getCollectionPrimaryField(collectionName) {
72
71
  return fieldName;
73
72
  }
74
73
  }
75
- export function getCollectionParamsFields(collectionName, allFields) {
74
+ export function getCollectionParamsFields(ctx, collectionName, allFields) {
76
75
  if (allFields === void 0) { allFields = false; }
77
76
  var relations = ctx.meta.relations;
78
77
  var foreignFields = relations
@@ -93,7 +92,7 @@ export function getCollectionParamsFields(collectionName, allFields) {
93
92
  }
94
93
  columns.push("".concat(foreignField.field, ".id"));
95
94
  if (!allFields) {
96
- var primaryField = getCollectionPrimaryField(foreignField.collection);
95
+ var primaryField = getCollectionPrimaryField(ctx, foreignField.collection);
97
96
  if (primaryField) {
98
97
  columns.push("".concat(foreignField.field, ".").concat(primaryField));
99
98
  }
@@ -1,10 +1,12 @@
1
1
  <script lang="ts">
2
- import { ctx } from "../../../store.svelte";
2
+ import { getStudioContext } from "../../../context";
3
3
  import { Link } from "lucide-svelte";
4
4
  import CreateManyView from "./createManyView.svelte";
5
- import ExtensionsComponents from "../../extensionsComponents.svelte";
5
+ import ExtensionsComponents from "../../../components/extensionsComponents.svelte";
6
6
  import { getExtensionUtils } from "../../../extensions/extensionUtils";
7
7
 
8
+ const { ctx, lobb } = getStudioContext();
9
+
8
10
  interface LocalProp {
9
11
  collectionName: string;
10
12
  entry: any;
@@ -42,7 +44,7 @@
42
44
  {@const childCollection = relation.from.collection}
43
45
  <ExtensionsComponents
44
46
  name="detailView.create.subRecords.{childCollection}"
45
- utils={getExtensionUtils()}
47
+ utils={getExtensionUtils(lobb, ctx)}
46
48
  parentCollectionName={collectionName}
47
49
  collectionName={childCollection}
48
50
  parentRecord={{
@@ -18,9 +18,11 @@
18
18
 
19
19
  <script lang="ts">
20
20
  import { ArrowLeft, Plus, X } from "lucide-svelte";
21
- import Button from "../../ui/button/button.svelte";
22
- import { lobb, ctx } from "../../../store.svelte";
21
+ import Button from "../../../components/ui/button/button.svelte";
22
+ import { getStudioContext } from "../../../context";
23
23
  import { toast } from "svelte-sonner";
24
+
25
+ const { lobb, ctx } = getStudioContext();
24
26
  import ExtensionsComponents from "../../extensionsComponents.svelte";
25
27
  import { getExtensionUtils } from "../../../extensions/extensionUtils";
26
28
  import { getField, getFieldIcon } from "../../dataTable/utils";
@@ -34,7 +36,7 @@
34
36
  import type { Snippet } from "svelte";
35
37
  import FieldInput from "../fieldInput.svelte";
36
38
  import { emitEvent } from "../../../eventSystem";
37
- import Drawer from "../../drawer.svelte";
39
+ import Drawer from "../../../components/drawer.svelte";
38
40
 
39
41
  let {
40
42
  collectionName,
@@ -47,11 +49,11 @@
47
49
  submitButton,
48
50
  }: CreateDetailViewProp = $props();
49
51
 
50
- parseDetailViewValues(collectionName, values)
52
+ parseDetailViewValues(ctx, collectionName, values)
51
53
 
52
54
  const fieldNames = Object.keys(ctx.meta.collections[collectionName].fields);
53
55
  let entry: Record<string, any> = $state(
54
- getDefaultEntry(fieldNames, collectionName, values),
56
+ getDefaultEntry(ctx, fieldNames, collectionName, values),
55
57
  );
56
58
  let fieldsErrors: Record<string, any> = $state({});
57
59
  const subCollections = ctx.meta.relations.filter((relation) => relation.to.collection === collectionName).map((relation) => relation.from.collection);
@@ -66,7 +68,7 @@
66
68
  async function handleSave() {
67
69
  let localEntry = $state.snapshot(entry);
68
70
 
69
- await emitEvent("studio.collections.preCreate", {
71
+ await emitEvent({ lobb, ctx }, "studio.collections.preCreate", {
70
72
  collectionName,
71
73
  entry: localEntry,
72
74
  });
@@ -79,6 +81,7 @@
79
81
  }
80
82
 
81
83
  const serializedEntry = serializeEntry(
84
+ ctx,
82
85
  collectionName,
83
86
  localEntry,
84
87
  rollback,
@@ -94,6 +97,7 @@
94
97
  ];
95
98
  } else {
96
99
  transactionBody = generateTransactionBody(
100
+ ctx,
97
101
  collectionName,
98
102
  serializedEntry,
99
103
  );
@@ -102,7 +106,7 @@
102
106
  // create the record
103
107
  let response = await lobb.transactions(transactionBody, rollback);
104
108
 
105
- await emitEvent("studio.collections.create", {
109
+ await emitEvent({ lobb, ctx }, "studio.collections.create", {
106
110
  collectionName,
107
111
  entry: localEntry,
108
112
  response: response,
@@ -155,8 +159,8 @@
155
159
  <div class="flex-1 overflow-y-auto">
156
160
  <div class="flex flex-col gap-4 p-4">
157
161
  {#each fieldNames as fieldName}
158
- {@const field = getField(fieldName, collectionName)}
159
- {@const FieldIcon = getFieldIcon(fieldName, collectionName)}
162
+ {@const field = getField(ctx, fieldName, collectionName)}
163
+ {@const FieldIcon = getFieldIcon(ctx, fieldName, collectionName)}
160
164
  <div
161
165
  class="flex flex-col gap-2"
162
166
  >
@@ -175,7 +179,7 @@
175
179
  <div>
176
180
  <ExtensionsComponents
177
181
  name="dvFields.topRight.{collectionName}.{fieldName}"
178
- utils={getExtensionUtils()}
182
+ utils={getExtensionUtils(lobb, ctx)}
179
183
  bind:value={entry[fieldName]}
180
184
  />
181
185
  </div>