@lobb-js/studio 0.1.34 → 0.1.36
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/package.json +2 -2
- package/src/lib/Lobb.d.ts +30 -0
- package/src/lib/Lobb.ts +241 -0
- package/src/lib/components/Studio.svelte +5 -5
- package/src/lib/components/routes/collections/collection.svelte +46 -0
- package/src/lib/components/routes/collections/collections.svelte +43 -0
- package/src/lib/components/routes/collections/collections.svelte.d.ts +5 -0
- package/src/lib/components/routes/data_model/dataModel.svelte +40 -0
- package/src/lib/components/routes/data_model/dataModel.svelte.d.ts +3 -0
- package/src/lib/components/routes/data_model/flow.css +22 -0
- package/src/lib/components/routes/data_model/flow.svelte +82 -0
- package/src/lib/components/routes/data_model/flow.svelte.d.ts +5 -0
- package/src/lib/components/routes/data_model/syncManager.svelte +93 -0
- package/src/lib/components/routes/data_model/syncManager.svelte.d.ts +3 -0
- package/src/lib/components/routes/data_model/utils.d.ts +4 -0
- package/src/lib/components/routes/data_model/utils.ts +35 -0
- package/src/lib/components/routes/extensions/extension.svelte +16 -0
- package/src/lib/components/routes/home.svelte +36 -0
- package/src/lib/components/routes/workflows/workflows.svelte +135 -0
- package/src/lib/components/routes/workflows/workflows.svelte.d.ts +5 -0
- package/src/lib/eventSystem.d.ts +1 -0
- package/src/lib/eventSystem.ts +38 -0
- package/src/lib/extensions/extension.types.d.ts +83 -0
- package/src/lib/extensions/extension.types.ts +93 -0
- package/src/lib/extensions/extensionUtils.d.ts +8 -0
- package/src/lib/extensions/extensionUtils.ts +192 -0
- package/src/lib/index.d.ts +9 -0
- package/src/lib/index.ts +36 -0
- package/src/lib/store.svelte.d.ts +4 -0
- package/src/lib/store.svelte.ts +33 -0
- package/src/lib/store.types.d.ts +26 -0
- package/src/lib/store.types.ts +28 -0
- package/src/lib/utils.d.ts +27 -0
- package/src/lib/utils.ts +84 -0
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Main Studio component
|
|
2
|
+
export { default as Studio } from "./components/Studio.svelte";
|
|
3
|
+
|
|
4
|
+
// Lobb client and utilities
|
|
5
|
+
export { Lobb } from "./Lobb";
|
|
6
|
+
export * from "./utils";
|
|
7
|
+
export * from "./eventSystem";
|
|
8
|
+
export { ctx, lobb } from "./store.svelte";
|
|
9
|
+
export type * from "./store.types";
|
|
10
|
+
|
|
11
|
+
export function createSet(lastNumber: number): Set<number> {
|
|
12
|
+
const set = new Set() as Set<number>;
|
|
13
|
+
for (let i = 0; i <= lastNumber; i++) {
|
|
14
|
+
set.add(i);
|
|
15
|
+
}
|
|
16
|
+
return set;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function moveElement<T>(array: T[], fromIndex: number, toIndex: number) {
|
|
20
|
+
if (
|
|
21
|
+
fromIndex < 0 || fromIndex >= array.length || toIndex < 0 ||
|
|
22
|
+
toIndex >= array.length
|
|
23
|
+
) {
|
|
24
|
+
throw new Error("Index out of bounds");
|
|
25
|
+
}
|
|
26
|
+
const [element] = array.splice(fromIndex, 1);
|
|
27
|
+
array.splice(toIndex, 0, element);
|
|
28
|
+
return array;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function pxToRem(px: number) {
|
|
32
|
+
const rootFontSize = parseFloat(
|
|
33
|
+
getComputedStyle(document.documentElement).fontSize,
|
|
34
|
+
);
|
|
35
|
+
return px / rootFontSize;
|
|
36
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CTX } from './store.types';
|
|
2
|
+
import { Lobb } from './Lobb';
|
|
3
|
+
import { toast } from 'svelte-sonner';
|
|
4
|
+
import pkg from '../../package.json';
|
|
5
|
+
|
|
6
|
+
if (!window.APP_ENV) {
|
|
7
|
+
window.APP_ENV = {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (window.APP_ENV.LOBB_URL === '%LOBB_URL%') {
|
|
11
|
+
window.APP_ENV.LOBB_URL = null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ctx: CTX = $state.raw({
|
|
15
|
+
studioVersion: pkg.version,
|
|
16
|
+
lobbUrl: window.APP_ENV.LOBB_URL || localStorage.getItem("lobb_url"),
|
|
17
|
+
extensions: {},
|
|
18
|
+
meta: {
|
|
19
|
+
collections: null,
|
|
20
|
+
extensions: null,
|
|
21
|
+
filter: null
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const lobb = new Lobb(ctx.lobbUrl);
|
|
26
|
+
|
|
27
|
+
// logging the message if got any bad responses
|
|
28
|
+
lobb.onResponse(async (response) => {
|
|
29
|
+
if (response.status >= 400) {
|
|
30
|
+
const body = await response.json();
|
|
31
|
+
toast.error(body.message);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Extension } from "../extensions/extension.types";
|
|
2
|
+
interface Collection {
|
|
3
|
+
category: string;
|
|
4
|
+
owner: string;
|
|
5
|
+
fields: Record<string, any>;
|
|
6
|
+
singleton: boolean;
|
|
7
|
+
}
|
|
8
|
+
type Collections = Record<string, Collection>;
|
|
9
|
+
interface Meta {
|
|
10
|
+
version: string;
|
|
11
|
+
relations: Array<any>;
|
|
12
|
+
collections: Collections;
|
|
13
|
+
extensions: Record<string, any>;
|
|
14
|
+
filter: any;
|
|
15
|
+
events: any[];
|
|
16
|
+
event_context_type: string;
|
|
17
|
+
studio_workflows: any[];
|
|
18
|
+
}
|
|
19
|
+
export interface CTX {
|
|
20
|
+
studioVersion: string;
|
|
21
|
+
lobbUrl: string | null;
|
|
22
|
+
extensions: Record<string, Extension>;
|
|
23
|
+
meta: Meta;
|
|
24
|
+
currentUrl: URL;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Extension } from "../extensions/extension.types";
|
|
2
|
+
|
|
3
|
+
interface Collection {
|
|
4
|
+
category: string;
|
|
5
|
+
owner: string;
|
|
6
|
+
fields: Record<string, any>;
|
|
7
|
+
singleton: boolean;
|
|
8
|
+
}
|
|
9
|
+
type Collections = Record<string, Collection>;
|
|
10
|
+
|
|
11
|
+
interface Meta {
|
|
12
|
+
version: string;
|
|
13
|
+
relations: Array<any>;
|
|
14
|
+
collections: Collections;
|
|
15
|
+
extensions: Record<string, any>;
|
|
16
|
+
filter: any;
|
|
17
|
+
events: any[];
|
|
18
|
+
event_context_type: string;
|
|
19
|
+
studio_workflows: any[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CTX {
|
|
23
|
+
studioVersion: string;
|
|
24
|
+
lobbUrl: string | null;
|
|
25
|
+
extensions: Record<string, Extension>;
|
|
26
|
+
meta: Meta;
|
|
27
|
+
currentUrl: URL;
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ClassValue } from "clsx";
|
|
2
|
+
import { MediaQuery } from 'svelte/reactivity';
|
|
3
|
+
export declare function cn(...inputs: ClassValue[]): string;
|
|
4
|
+
export type WithoutChild<T> = T extends {
|
|
5
|
+
child?: any;
|
|
6
|
+
} ? Omit<T, "child"> : T;
|
|
7
|
+
export type WithoutChildren<T> = T extends {
|
|
8
|
+
children?: any;
|
|
9
|
+
} ? Omit<T, "children"> : T;
|
|
10
|
+
export type WithoutChildrenOrChild<T> = WithoutChildren<WithoutChild<T>>;
|
|
11
|
+
export type WithElementRef<T, U extends HTMLElement = HTMLElement> = T & {
|
|
12
|
+
ref?: U | null;
|
|
13
|
+
};
|
|
14
|
+
export declare const mediaQueries: {
|
|
15
|
+
sm: MediaQuery;
|
|
16
|
+
md: MediaQuery;
|
|
17
|
+
lg: MediaQuery;
|
|
18
|
+
xl: MediaQuery;
|
|
19
|
+
'2xl': MediaQuery;
|
|
20
|
+
};
|
|
21
|
+
export declare function getFileFromUser(): Promise<import("browser-fs-access").FileWithHandle>;
|
|
22
|
+
export declare function getFieldRelation(collectionName: string, fieldName: string): any;
|
|
23
|
+
export declare function getDiscriminatorFieldRelation(collectionName: string, fieldName: string): any;
|
|
24
|
+
export declare function recordHasChildrean(collectionName: string): boolean;
|
|
25
|
+
export declare function calculateDrawerWidth(): number;
|
|
26
|
+
export declare function getChangedProperties(oldObj: Record<string, any>, newObj: Record<string, any>): Record<string, any>;
|
|
27
|
+
export declare function parseFunction(functionString: string): any;
|
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { clsx, type ClassValue } from "clsx";
|
|
2
|
+
import { twMerge } from "tailwind-merge";
|
|
3
|
+
|
|
4
|
+
import { fileOpen } from 'browser-fs-access';
|
|
5
|
+
import { MediaQuery } from 'svelte/reactivity';
|
|
6
|
+
import { ctx } from "./store.svelte";
|
|
7
|
+
|
|
8
|
+
export function cn(...inputs: ClassValue[]) {
|
|
9
|
+
return twMerge(clsx(inputs));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
export type WithoutChild<T> = T extends { child?: any } ? Omit<T, "child"> : T;
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
export type WithoutChildren<T> = T extends { children?: any } ? Omit<T, "children"> : T;
|
|
16
|
+
export type WithoutChildrenOrChild<T> = WithoutChildren<WithoutChild<T>>;
|
|
17
|
+
export type WithElementRef<T, U extends HTMLElement = HTMLElement> = T & { ref?: U | null };
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export const mediaQueries = {
|
|
21
|
+
sm: new MediaQuery('min-width: 640px'),
|
|
22
|
+
md: new MediaQuery('min-width: 768px'),
|
|
23
|
+
lg: new MediaQuery('min-width: 1024px'),
|
|
24
|
+
xl: new MediaQuery('min-width: 1280px'),
|
|
25
|
+
'2xl': new MediaQuery('min-width: 1536px'),
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function getFileFromUser() {
|
|
29
|
+
return await fileOpen()
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function getFieldRelation(collectionName: string, fieldName: string) {
|
|
33
|
+
const relations = ctx.meta.relations;
|
|
34
|
+
for (let index = 0; index < relations.length; index++) {
|
|
35
|
+
const relation = relations[index];
|
|
36
|
+
if (relation.from.collection === collectionName && relation.from.field === fieldName) {
|
|
37
|
+
return relation;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function getDiscriminatorFieldRelation(collectionName: string, fieldName: string) {
|
|
44
|
+
const relations = ctx.meta.relations;
|
|
45
|
+
for (let index = 0; index < relations.length; index++) {
|
|
46
|
+
const relation = relations[index];
|
|
47
|
+
if (relation.from.collection === collectionName && relation.from.discriminator === fieldName) {
|
|
48
|
+
return relation;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export function recordHasChildrean(collectionName: string) {
|
|
55
|
+
for (let index = 0; index < ctx.meta.relations.length; index++) {
|
|
56
|
+
const relation = ctx.meta.relations[index];
|
|
57
|
+
if (relation.to.collection === collectionName) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export function calculateDrawerWidth() {
|
|
65
|
+
const backgroundDrawerButtons = document.querySelectorAll(".backgroundDrawerButton");
|
|
66
|
+
const drawersCount = Array.from(backgroundDrawerButtons).length;
|
|
67
|
+
const width = 672 - (30 * drawersCount);
|
|
68
|
+
return width;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export function getChangedProperties(oldObj: Record<string, any>, newObj: Record<string, any>) {
|
|
72
|
+
const changes: Record<string, any> = {};
|
|
73
|
+
for (const key of Object.keys(newObj)) {
|
|
74
|
+
if (oldObj[key] !== newObj[key]) {
|
|
75
|
+
changes[key] = newObj[key];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return changes;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function parseFunction(functionString: string) {
|
|
82
|
+
const functionObj = new Function("return " + functionString)();
|
|
83
|
+
return functionObj;
|
|
84
|
+
};
|