@lobb-js/studio 0.20.0 → 0.22.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.
- package/dist/actions.d.ts +1 -0
- package/dist/components/dataTable/utils.js +8 -14
- package/dist/components/dataTableDrawer/dataTableDrawer.svelte +14 -10
- package/dist/components/dataTableDrawer/dataTableDrawer.svelte.d.ts +1 -0
- package/dist/components/detailView/create/children.svelte +13 -30
- package/dist/components/detailView/create/createDetailView.svelte +9 -32
- package/dist/components/detailView/update/children.svelte +122 -35
- package/dist/components/detailView/utils.d.ts +5 -2
- package/dist/components/detailView/utils.js +28 -71
- package/dist/components/drawer.svelte +24 -8
- package/dist/components/drawer.svelte.d.ts +1 -0
- package/dist/extensions/extension.types.d.ts +2 -0
- package/dist/extensions/extensionUtils.js +2 -0
- package/dist/store.types.d.ts +13 -0
- package/package.json +2 -2
- package/src/lib/actions.ts +1 -0
- package/src/lib/components/dataTable/utils.ts +7 -16
- package/src/lib/components/dataTableDrawer/dataTableDrawer.svelte +14 -10
- package/src/lib/components/detailView/create/children.svelte +13 -30
- package/src/lib/components/detailView/create/createDetailView.svelte +9 -32
- package/src/lib/components/detailView/update/children.svelte +122 -35
- package/src/lib/components/detailView/utils.ts +24 -76
- package/src/lib/components/drawer.svelte +24 -8
- package/src/lib/extensions/extension.types.ts +2 -1
- package/src/lib/extensions/extensionUtils.ts +2 -0
- package/src/lib/store.types.ts +7 -0
package/dist/actions.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface OpenDataTableDrawerProps {
|
|
|
7
7
|
title?: string;
|
|
8
8
|
showHeader?: boolean;
|
|
9
9
|
showFooter?: boolean;
|
|
10
|
+
position?: "side" | "bottom";
|
|
10
11
|
}
|
|
11
12
|
export declare function showDialog(title: string, description: string): Promise<boolean>;
|
|
12
13
|
export declare function openCreateDetailView(studioContext: StudioContext, props: CreateDetailViewProp): void;
|
|
@@ -103,24 +103,18 @@ export function getCollectionParamsFields(ctx, collectionName, allFields) {
|
|
|
103
103
|
};
|
|
104
104
|
});
|
|
105
105
|
var columns = [];
|
|
106
|
-
for (var
|
|
107
|
-
var foreignField =
|
|
108
|
-
if (!foreignField.collection || !ctx.meta.collections[foreignField.collection])
|
|
106
|
+
for (var _i = 0, foreignFields_1 = foreignFields; _i < foreignFields_1.length; _i++) {
|
|
107
|
+
var foreignField = foreignFields_1[_i];
|
|
108
|
+
if (!foreignField.collection || !ctx.meta.collections[foreignField.collection])
|
|
109
109
|
continue;
|
|
110
|
+
if (allFields) {
|
|
111
|
+
columns.push("".concat(foreignField.field, ".*"));
|
|
110
112
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
else {
|
|
114
|
+
columns.push("".concat(foreignField.field, ".id"));
|
|
113
115
|
var primaryField = getCollectionPrimaryField(ctx, foreignField.collection);
|
|
114
|
-
if (primaryField)
|
|
116
|
+
if (primaryField)
|
|
115
117
|
columns.push("".concat(foreignField.field, ".").concat(primaryField));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
var fieldNames = Object.keys(ctx.meta.collections[foreignField.collection].fields);
|
|
120
|
-
for (var index_1 = 0; index_1 < fieldNames.length; index_1++) {
|
|
121
|
-
var fieldName = fieldNames[index_1];
|
|
122
|
-
columns.push("".concat(foreignField.field, ".").concat(fieldName));
|
|
123
|
-
}
|
|
124
118
|
}
|
|
125
119
|
}
|
|
126
120
|
var foreignColumns = columns.join(",");
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
showHeader?: boolean;
|
|
13
13
|
showFooter?: boolean;
|
|
14
14
|
tableProps?: Partial<TableProps>;
|
|
15
|
+
position?: "side" | "bottom";
|
|
15
16
|
onClose?: () => void;
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -22,20 +23,23 @@
|
|
|
22
23
|
showHeader = true,
|
|
23
24
|
showFooter = true,
|
|
24
25
|
tableProps,
|
|
26
|
+
position = "side",
|
|
25
27
|
onClose,
|
|
26
28
|
}: Props = $props();
|
|
27
29
|
</script>
|
|
28
30
|
|
|
29
|
-
<Drawer onHide={async () => onClose?.()}>
|
|
30
|
-
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
<Drawer onHide={async () => onClose?.()} {position}>
|
|
32
|
+
{#if position !== "bottom"}
|
|
33
|
+
<div class="flex h-12 shrink-0 items-center gap-4 border-b px-4">
|
|
34
|
+
<Button
|
|
35
|
+
variant="outline"
|
|
36
|
+
onclick={() => onClose?.()}
|
|
37
|
+
class="h-8 w-8 rounded-full text-xs font-normal"
|
|
38
|
+
Icon={ArrowLeft}
|
|
39
|
+
/>
|
|
40
|
+
<div class="text-sm font-medium">{title ?? collectionName}</div>
|
|
41
|
+
</div>
|
|
42
|
+
{/if}
|
|
39
43
|
<div class="min-h-0 flex-1 overflow-auto">
|
|
40
44
|
<DataTable
|
|
41
45
|
{collectionName}
|
|
@@ -15,53 +15,36 @@
|
|
|
15
15
|
|
|
16
16
|
let { collectionName, entry = $bindable(), values = {} }: LocalProp = $props();
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
(
|
|
20
|
-
);
|
|
18
|
+
const fkChildren = (ctx.meta.collections[collectionName]?.children ?? [])
|
|
19
|
+
.filter((c) => c.type === "fk") as { type: "fk"; collection: string; field: string }[];
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const relation = childrenRelations[index];
|
|
25
|
-
const childCollection = relation.from.collection;
|
|
26
|
-
entry[childCollection] = [];
|
|
27
|
-
if (values[childCollection]) {
|
|
28
|
-
entry[childCollection] = [
|
|
29
|
-
...entry[childCollection],
|
|
30
|
-
...values[childCollection],
|
|
31
|
-
];
|
|
32
|
-
}
|
|
21
|
+
for (const child of fkChildren) {
|
|
22
|
+
entry[child.collection] = values[child.collection] ? [...values[child.collection]] : [];
|
|
33
23
|
}
|
|
34
24
|
</script>
|
|
35
25
|
|
|
36
|
-
{#if
|
|
26
|
+
{#if fkChildren.length}
|
|
37
27
|
<div class="flex flex-col gap-4 border-t p-4">
|
|
38
28
|
<div class="flex items-center gap-2">
|
|
39
29
|
<Link size="17.5" />
|
|
40
30
|
<div>Sub Records</div>
|
|
41
31
|
</div>
|
|
42
32
|
<div class="flex flex-col gap-4">
|
|
43
|
-
{#each
|
|
44
|
-
{@const childCollection = relation.from.collection}
|
|
33
|
+
{#each fkChildren as child}
|
|
45
34
|
<ExtensionsComponents
|
|
46
|
-
name="detailView.create.subRecords.{
|
|
35
|
+
name="detailView.create.subRecords.{child.collection}"
|
|
47
36
|
utils={getExtensionUtils(lobb, ctx)}
|
|
48
37
|
parentCollectionName={collectionName}
|
|
49
|
-
collectionName={
|
|
50
|
-
parentRecord={{
|
|
51
|
-
id: entry.id,
|
|
52
|
-
collectionName: collectionName,
|
|
53
|
-
}}
|
|
38
|
+
collectionName={child.collection}
|
|
39
|
+
parentRecord={{ id: entry.id, collectionName }}
|
|
54
40
|
class="bg-muted/30 border rounded-md overflow-hidden"
|
|
55
|
-
bind:value={entry[
|
|
41
|
+
bind:value={entry[child.collection]}
|
|
56
42
|
>
|
|
57
43
|
<CreateManyView
|
|
58
44
|
parentCollectionName={collectionName}
|
|
59
|
-
collectionName={
|
|
60
|
-
parentRecord={{
|
|
61
|
-
|
|
62
|
-
collectionName: collectionName,
|
|
63
|
-
}}
|
|
64
|
-
bind:entries={entry[childCollection]}
|
|
45
|
+
collectionName={child.collection}
|
|
46
|
+
parentRecord={{ id: entry.id, collectionName }}
|
|
47
|
+
bind:entries={entry[child.collection]}
|
|
65
48
|
/>
|
|
66
49
|
</ExtensionsComponents>
|
|
67
50
|
{/each}
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
import { getField, getFieldIcon } from "../../dataTable/utils";
|
|
29
29
|
import Children from "./children.svelte";
|
|
30
30
|
import {
|
|
31
|
-
|
|
31
|
+
buildChildren,
|
|
32
32
|
getDefaultEntry,
|
|
33
33
|
parseDetailViewValues,
|
|
34
34
|
serializeEntry,
|
|
@@ -82,31 +82,15 @@
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
const serializedEntry = serializeEntry(
|
|
86
|
-
ctx,
|
|
87
|
-
collectionName,
|
|
88
|
-
localEntry,
|
|
89
|
-
rollback,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
let transactionBody;
|
|
93
85
|
if (rollback) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
props: { collectionName: collectionName, data: serializedEntry },
|
|
98
|
-
},
|
|
99
|
-
];
|
|
100
|
-
} else {
|
|
101
|
-
transactionBody = generateTransactionBody(
|
|
102
|
-
ctx,
|
|
103
|
-
collectionName,
|
|
104
|
-
serializedEntry,
|
|
105
|
-
);
|
|
86
|
+
if (onSuccessfullSave) await onSuccessfullSave(localEntry);
|
|
87
|
+
onCancel?.();
|
|
88
|
+
return;
|
|
106
89
|
}
|
|
107
90
|
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
const serializedEntry = serializeEntry(ctx, collectionName, localEntry);
|
|
92
|
+
const children = buildChildren(ctx, collectionName, localEntry);
|
|
93
|
+
const response = await lobb.createOne(collectionName, serializedEntry, children);
|
|
110
94
|
|
|
111
95
|
await emitEvent({ lobb, ctx }, "studio.collections.create", {
|
|
112
96
|
collectionName,
|
|
@@ -126,15 +110,8 @@
|
|
|
126
110
|
}
|
|
127
111
|
}
|
|
128
112
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
await onSuccessfullSave(localEntry);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!rollback) {
|
|
135
|
-
toast.success(`The record was successfully created`);
|
|
136
|
-
}
|
|
137
|
-
|
|
113
|
+
if (onSuccessfullSave) await onSuccessfullSave(localEntry);
|
|
114
|
+
toast.success(`The record was successfully created`);
|
|
138
115
|
onCancel?.();
|
|
139
116
|
}
|
|
140
117
|
</script>
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import DataTable from "../../../components/dataTable/dataTable.svelte";
|
|
3
3
|
import { getStudioContext } from "../../../context";
|
|
4
|
-
import { Link, Plus, TableIcon } from "lucide-svelte";
|
|
4
|
+
import { Link, Plus, TableIcon, Unlink } from "lucide-svelte";
|
|
5
5
|
import CreateDetailViewButton from "../create/createDetailViewButton.svelte";
|
|
6
6
|
import ExtensionsComponents from "../../../components/extensionsComponents.svelte";
|
|
7
7
|
import { getExtensionUtils } from "../../../extensions/extensionUtils";
|
|
8
|
+
import SelectRecord from "../../../components/selectRecord.svelte";
|
|
9
|
+
import { getCollectionColumns } from "../../dataTable/utils";
|
|
10
|
+
import Table from "../../../components/dataTable/table.svelte";
|
|
11
|
+
import Button from "../../../components/ui/button/button.svelte";
|
|
8
12
|
|
|
9
13
|
const { ctx, lobb } = getStudioContext();
|
|
10
14
|
|
|
@@ -15,67 +19,92 @@
|
|
|
15
19
|
|
|
16
20
|
let { collectionName, entry }: LocalProp = $props();
|
|
17
21
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const allChildren = ctx.meta.collections[collectionName]?.children ?? [];
|
|
23
|
+
const fkChildren = allChildren.filter((c) => c.type === "fk") as { type: "fk"; collection: string; field: string }[];
|
|
24
|
+
const relationalChildren = allChildren.filter((c) => c.type === "m2m" || c.type === "polymorphic") as { type: string; collection: string }[];
|
|
25
|
+
|
|
26
|
+
const fkRefresh: boolean[] = $state(new Array(fkChildren.length).fill(true));
|
|
27
|
+
|
|
28
|
+
let relationalRecords: Record<string, any[]> = $state({});
|
|
29
|
+
let relationalLoading = $state(false);
|
|
30
|
+
|
|
31
|
+
async function fetchRelational() {
|
|
32
|
+
if (!relationalChildren.length || !entry?.id) return;
|
|
33
|
+
relationalLoading = true;
|
|
34
|
+
const childrenParam: Record<string, any> = {};
|
|
35
|
+
for (const child of relationalChildren) {
|
|
36
|
+
childrenParam[child.collection] = { fields: ["*"] };
|
|
37
|
+
}
|
|
38
|
+
const response = await lobb.findAll(collectionName, {
|
|
39
|
+
filter: { id: entry.id },
|
|
40
|
+
limit: 1,
|
|
41
|
+
children: childrenParam,
|
|
42
|
+
});
|
|
43
|
+
const result = await response.json();
|
|
44
|
+
const record = result.data?.[0];
|
|
45
|
+
if (record) {
|
|
46
|
+
for (const child of relationalChildren) {
|
|
47
|
+
relationalRecords[child.collection] = record[child.collection] ?? [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
relationalLoading = false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function linkRecord(childCollection: string, selected: any) {
|
|
54
|
+
await lobb.updateOne(collectionName, entry.id, {}, { [childCollection]: { link: [selected.id] } });
|
|
55
|
+
await fetchRelational();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function unlinkRecord(childCollection: string, id: any) {
|
|
59
|
+
await lobb.updateOne(collectionName, entry.id, {}, { [childCollection]: { unlink: [id] } });
|
|
60
|
+
await fetchRelational();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
$effect(() => {
|
|
64
|
+
fetchRelational();
|
|
65
|
+
});
|
|
24
66
|
</script>
|
|
25
67
|
|
|
26
|
-
{#if
|
|
68
|
+
{#if allChildren.length}
|
|
27
69
|
<div class="flex flex-col gap-4 border-t p-4">
|
|
28
70
|
<div class="flex items-center gap-2">
|
|
29
71
|
<Link size="17.5" />
|
|
30
72
|
<div>Sub Records</div>
|
|
31
73
|
</div>
|
|
32
74
|
<div class="flex flex-col gap-4">
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
75
|
+
|
|
76
|
+
<!-- FK children -->
|
|
77
|
+
{#each fkChildren as child, index}
|
|
36
78
|
<ExtensionsComponents
|
|
37
|
-
name="detailView.update.subRecords.{
|
|
79
|
+
name="detailView.update.subRecords.{child.collection}"
|
|
38
80
|
utils={getExtensionUtils(lobb, ctx)}
|
|
39
|
-
collectionName={
|
|
40
|
-
filter={{
|
|
41
|
-
[childField]: entry.id,
|
|
42
|
-
}}
|
|
81
|
+
collectionName={child.collection}
|
|
82
|
+
filter={{ [child.field]: entry.id }}
|
|
43
83
|
class="bg-muted/30 border rounded-md overflow-hidden"
|
|
44
84
|
>
|
|
45
85
|
<div class="border rounded-md overflow-clip">
|
|
46
|
-
<div
|
|
47
|
-
class="flex items-center justify-between px-2 h-10 bg-muted/30 border-b"
|
|
48
|
-
>
|
|
86
|
+
<div class="flex items-center justify-between px-2 h-10 bg-muted/30 border-b">
|
|
49
87
|
<div class="flex-1 flex h-full items-center gap-2">
|
|
50
|
-
<TableIcon
|
|
51
|
-
|
|
52
|
-
size="17.5"
|
|
53
|
-
/>
|
|
54
|
-
<div class="text-sm text-muted-foreground">
|
|
55
|
-
{childCollection}
|
|
56
|
-
</div>
|
|
88
|
+
<TableIcon class="text-muted-foreground" size="17.5" />
|
|
89
|
+
<div class="text-sm text-muted-foreground">{child.collection}</div>
|
|
57
90
|
</div>
|
|
58
91
|
<div class="flex gap-2">
|
|
59
92
|
<CreateDetailViewButton
|
|
60
93
|
variant="ghost"
|
|
61
94
|
class="h-7 px-2 font-normal text-xs"
|
|
62
95
|
Icon={Plus}
|
|
63
|
-
collectionName={
|
|
64
|
-
onSuccessfullSave={async () => {
|
|
65
|
-
refresh[index] = !refresh[index];
|
|
66
|
-
}}
|
|
96
|
+
collectionName={child.collection}
|
|
97
|
+
onSuccessfullSave={async () => { fkRefresh[index] = !fkRefresh[index]; }}
|
|
67
98
|
>
|
|
68
99
|
Create
|
|
69
100
|
</CreateDetailViewButton>
|
|
70
101
|
</div>
|
|
71
102
|
</div>
|
|
72
103
|
<div class="max-h-72 overflow-auto rounded-md">
|
|
73
|
-
{#key
|
|
104
|
+
{#key fkRefresh[index]}
|
|
74
105
|
<DataTable
|
|
75
|
-
collectionName={
|
|
76
|
-
filter={{
|
|
77
|
-
[childField]: entry.id,
|
|
78
|
-
}}
|
|
106
|
+
collectionName={child.collection}
|
|
107
|
+
filter={{ [child.field]: entry.id }}
|
|
79
108
|
unifiedBgColor="bg-muted/30"
|
|
80
109
|
showHeader={false}
|
|
81
110
|
showFooter={false}
|
|
@@ -91,6 +120,64 @@
|
|
|
91
120
|
</div>
|
|
92
121
|
</ExtensionsComponents>
|
|
93
122
|
{/each}
|
|
123
|
+
|
|
124
|
+
<!-- M2M and polymorphic children -->
|
|
125
|
+
{#each relationalChildren as child}
|
|
126
|
+
{@const columns = getCollectionColumns(ctx, child.collection)}
|
|
127
|
+
{@const linkedIds = new Set((relationalRecords[child.collection] ?? []).map((r: any) => String(r.id)))}
|
|
128
|
+
<div class="border rounded-md overflow-clip">
|
|
129
|
+
<div class="flex items-center justify-between px-2 h-10 bg-muted/30 border-b">
|
|
130
|
+
<div class="flex-1 flex h-full items-center gap-2">
|
|
131
|
+
<TableIcon class="text-muted-foreground" size="17.5" />
|
|
132
|
+
<div class="text-sm text-muted-foreground">{child.collection}</div>
|
|
133
|
+
</div>
|
|
134
|
+
<div class="flex gap-2">
|
|
135
|
+
<CreateDetailViewButton
|
|
136
|
+
variant="ghost"
|
|
137
|
+
class="h-7 px-2 font-normal text-xs"
|
|
138
|
+
Icon={Plus}
|
|
139
|
+
collectionName={child.collection}
|
|
140
|
+
onSuccessfullSave={async (newEntry) => { await linkRecord(child.collection, newEntry); }}
|
|
141
|
+
>
|
|
142
|
+
Create & link
|
|
143
|
+
</CreateDetailViewButton>
|
|
144
|
+
<SelectRecord
|
|
145
|
+
collectionName={child.collection}
|
|
146
|
+
text="Link existing"
|
|
147
|
+
onSelect={(selected) => linkRecord(child.collection, selected)}
|
|
148
|
+
filter={{ id: { $nin: [...linkedIds] } }}
|
|
149
|
+
variant="ghost"
|
|
150
|
+
class="h-7 px-2 font-normal text-xs"
|
|
151
|
+
/>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
<div class="max-h-72 overflow-auto bg-muted/30">
|
|
155
|
+
{#if relationalLoading}
|
|
156
|
+
<div class="p-4 text-sm text-muted-foreground">Loading...</div>
|
|
157
|
+
{:else}
|
|
158
|
+
<Table
|
|
159
|
+
data={relationalRecords[child.collection] ?? []}
|
|
160
|
+
{columns}
|
|
161
|
+
unifiedBgColor="bg-muted/30"
|
|
162
|
+
showLastRowBorder={false}
|
|
163
|
+
showLastColumnBorder={false}
|
|
164
|
+
showCheckboxes={false}
|
|
165
|
+
>
|
|
166
|
+
{#snippet tools(record, _index)}
|
|
167
|
+
<Button
|
|
168
|
+
class="h-6 w-6 text-muted-foreground hover:bg-transparent"
|
|
169
|
+
variant="ghost"
|
|
170
|
+
size="icon"
|
|
171
|
+
onclick={() => unlinkRecord(child.collection, record.id)}
|
|
172
|
+
Icon={Unlink}
|
|
173
|
+
/>
|
|
174
|
+
{/snippet}
|
|
175
|
+
</Table>
|
|
176
|
+
{/if}
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
{/each}
|
|
180
|
+
|
|
94
181
|
</div>
|
|
95
182
|
</div>
|
|
96
183
|
{/if}
|
|
@@ -3,7 +3,10 @@ import type { DetailFormField } from "./detailViewForm.svelte";
|
|
|
3
3
|
export declare function getDefaultEntry(ctx: CTX, fieldNames: string[], collectionName: string, values?: Record<string, any>): {
|
|
4
4
|
[k: string]: any;
|
|
5
5
|
};
|
|
6
|
-
export declare function serializeEntry(ctx: CTX, collectionName: string, entry: Record<string, any
|
|
7
|
-
export declare function
|
|
6
|
+
export declare function serializeEntry(ctx: CTX, collectionName: string, entry: Record<string, any>): Record<string, any>;
|
|
7
|
+
export declare function buildChildren(ctx: CTX, collectionName: string, entry: Record<string, any>): Record<string, {
|
|
8
|
+
create?: any[];
|
|
9
|
+
link?: any[];
|
|
10
|
+
}> | undefined;
|
|
8
11
|
export declare function parseDetailViewValues(ctx: CTX, collectionName: string, values: Record<string, any>): void;
|
|
9
12
|
export declare function getCollectionFields(ctx: CTX, collectionName: string): DetailFormField[];
|
|
@@ -33,11 +33,9 @@ export function getDefaultEntry(ctx, fieldNames, collectionName, values) {
|
|
|
33
33
|
return [fieldName, value];
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
|
-
export function serializeEntry(ctx, collectionName, entry
|
|
37
|
-
if (rollback === void 0) { rollback = false; }
|
|
38
|
-
// deep clone the object
|
|
36
|
+
export function serializeEntry(ctx, collectionName, entry) {
|
|
39
37
|
entry = __assign({}, entry);
|
|
40
|
-
//
|
|
38
|
+
// extract FK object fields → ID
|
|
41
39
|
for (var _i = 0, _a = Object.entries(entry); _i < _a.length; _i++) {
|
|
42
40
|
var _b = _a[_i], fieldName = _b[0], fieldValue = _b[1];
|
|
43
41
|
var isRefrenceField = isRelationField(ctx, collectionName, fieldName);
|
|
@@ -45,7 +43,7 @@ export function serializeEntry(ctx, collectionName, entry, rollback) {
|
|
|
45
43
|
entry[fieldName] = fieldValue.id;
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
|
-
//
|
|
46
|
+
// extract polymorphic id_field objects → ID
|
|
49
47
|
for (var _c = 0, _d = ctx.meta.relations; _c < _d.length; _c++) {
|
|
50
48
|
var relation = _d[_c];
|
|
51
49
|
if (relation.type !== "polymorphic")
|
|
@@ -58,76 +56,35 @@ export function serializeEntry(ctx, collectionName, entry, rollback) {
|
|
|
58
56
|
entry[idField] = fieldValue.id;
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
|
-
// check for related collections properties and serialize them too
|
|
62
|
-
if (!rollback) {
|
|
63
|
-
var childrenRelations = ctx.meta.relations.filter(function (relation) { return relation.to.collection === collectionName; });
|
|
64
|
-
var childrenCollectionNames = childrenRelations.map(function (relation) { return relation.from.collection; });
|
|
65
|
-
for (var index = 0; index < childrenCollectionNames.length; index++) {
|
|
66
|
-
var childrenCollectionName = childrenCollectionNames[index];
|
|
67
|
-
var childrenEntries = entry[childrenCollectionName];
|
|
68
|
-
if (childrenEntries) {
|
|
69
|
-
for (var index_1 = 0; index_1 < childrenEntries.length; index_1++) {
|
|
70
|
-
childrenEntries[index_1] = serializeEntry(ctx, childrenCollectionName, childrenEntries[index_1]);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
59
|
return entry;
|
|
76
60
|
}
|
|
77
|
-
export function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var localPayload = (_a = {},
|
|
98
|
-
_a[foreignKeyFieldName] = payload[foreignKeyFieldName],
|
|
99
|
-
_a);
|
|
100
|
-
transactionBody.push({
|
|
101
|
-
method: "updateMany",
|
|
102
|
-
props: {
|
|
103
|
-
collectionName: collectionName,
|
|
104
|
-
data: localPayload,
|
|
105
|
-
filter: { id: payload.id },
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
transactionBody.push({
|
|
111
|
-
method: "createOne",
|
|
112
|
-
props: { collectionName: collectionName, data: payload },
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
var childrenRelations = ctx.meta.relations.filter(function (relation) { return relation.to.collection === collectionName; });
|
|
116
|
-
var childrenCollectionNames = childrenRelations.map(function (relation) { return relation.from.collection; });
|
|
117
|
-
for (var index = 0; index < childrenCollectionNames.length; index++) {
|
|
118
|
-
var childrenCollectionName = childrenCollectionNames[index];
|
|
119
|
-
var childrenEntries = entry[childrenCollectionName];
|
|
120
|
-
if (childrenEntries) {
|
|
121
|
-
for (var index_2 = 0; index_2 < childrenEntries.length; index_2++) {
|
|
122
|
-
var childrenEntry = childrenEntries[index_2];
|
|
123
|
-
handleEntryRecursive(transactionBody, childrenCollectionName, childrenEntry, localTransactionIndex);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
61
|
+
export function buildChildren(ctx, collectionName, entry) {
|
|
62
|
+
var childrenRelations = ctx.meta.relations.filter(function (relation) { return relation.type !== "polymorphic" && relation.to.collection === collectionName; });
|
|
63
|
+
var children = {};
|
|
64
|
+
var _loop_1 = function (relation) {
|
|
65
|
+
var childCollection = relation.from.collection;
|
|
66
|
+
var childEntries = entry[childCollection];
|
|
67
|
+
if (!(childEntries === null || childEntries === void 0 ? void 0 : childEntries.length))
|
|
68
|
+
return "continue";
|
|
69
|
+
var toCreate = childEntries
|
|
70
|
+
.filter(function (e) { return !e.id; })
|
|
71
|
+
.map(function (e) { return serializeEntry(ctx, childCollection, e); });
|
|
72
|
+
var toLink = childEntries
|
|
73
|
+
.filter(function (e) { return e.id; })
|
|
74
|
+
.map(function (e) { return e.id; });
|
|
75
|
+
if (toCreate.length || toLink.length) {
|
|
76
|
+
children[childCollection] = {};
|
|
77
|
+
if (toCreate.length)
|
|
78
|
+
children[childCollection].create = toCreate;
|
|
79
|
+
if (toLink.length)
|
|
80
|
+
children[childCollection].link = toLink;
|
|
126
81
|
}
|
|
82
|
+
};
|
|
83
|
+
for (var _i = 0, childrenRelations_1 = childrenRelations; _i < childrenRelations_1.length; _i++) {
|
|
84
|
+
var relation = childrenRelations_1[_i];
|
|
85
|
+
_loop_1(relation);
|
|
127
86
|
}
|
|
128
|
-
|
|
129
|
-
handleEntryRecursive(transactionBody, collectionName, entry);
|
|
130
|
-
return transactionBody;
|
|
87
|
+
return Object.keys(children).length ? children : undefined;
|
|
131
88
|
}
|
|
132
89
|
export function parseDetailViewValues(ctx, collectionName, values) {
|
|
133
90
|
var forignFieldNames = ctx.meta.relations
|
|
@@ -1,30 +1,46 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { calculateDrawerWidth } from "../utils";
|
|
3
3
|
import type { Snippet } from "svelte";
|
|
4
|
-
import { fade
|
|
4
|
+
import { fade } from "svelte/transition";
|
|
5
|
+
import { cubicOut } from "svelte/easing";
|
|
5
6
|
import Portal from "svelte-portal";
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
children?: Snippet<[]>;
|
|
9
10
|
onHide?: () => Promise<void>;
|
|
11
|
+
position?: "side" | "bottom";
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
let { onHide, children }: Props = $props();
|
|
14
|
+
let { onHide, children, position = "side" }: Props = $props();
|
|
15
|
+
|
|
16
|
+
function slide(_node: Element, { duration = 250, axis }: { duration?: number; axis: "x" | "y" }) {
|
|
17
|
+
return {
|
|
18
|
+
duration,
|
|
19
|
+
easing: cubicOut,
|
|
20
|
+
css: (t: number) => {
|
|
21
|
+
const offset = (1 - t) * 100;
|
|
22
|
+
return axis === "y"
|
|
23
|
+
? `transform: translateY(${offset}%)`
|
|
24
|
+
: `transform: translateX(${offset}%)`;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
13
28
|
</script>
|
|
14
29
|
|
|
15
30
|
<Portal target="body">
|
|
16
31
|
<button
|
|
17
|
-
transition:fade={{ duration:
|
|
32
|
+
transition:fade={{ duration: 200 }}
|
|
18
33
|
onclick={() => onHide?.()}
|
|
19
|
-
class="backgroundDrawerButton fixed left-0 top-0 z-40 h-screen w-screen bg-
|
|
34
|
+
class="backgroundDrawerButton fixed left-0 top-0 z-40 h-screen w-screen bg-black/50 cursor-default"
|
|
20
35
|
aria-label="background used to hide the background"
|
|
21
36
|
></button>
|
|
22
37
|
|
|
23
|
-
<!-- the drawer -->
|
|
24
38
|
<div
|
|
25
|
-
transition:
|
|
26
|
-
class=
|
|
27
|
-
|
|
39
|
+
transition:slide={{ axis: position === "bottom" ? "y" : "x" }}
|
|
40
|
+
class={position === "bottom"
|
|
41
|
+
? "fixed bottom-0 left-0 z-40 flex h-[60vh] w-full flex-col border-t bg-background"
|
|
42
|
+
: "fixed right-0 top-0 z-40 flex h-full w-full flex-col border-l bg-background"}
|
|
43
|
+
style={position === "side" ? `max-width: ${calculateDrawerWidth()}px;` : ""}
|
|
28
44
|
>
|
|
29
45
|
{@render children?.()}
|
|
30
46
|
</div>
|
|
@@ -59,7 +59,9 @@ export interface ExtensionUtils {
|
|
|
59
59
|
title?: string;
|
|
60
60
|
showHeader?: boolean;
|
|
61
61
|
showFooter?: boolean;
|
|
62
|
+
position?: "side" | "bottom";
|
|
62
63
|
}) => void;
|
|
64
|
+
emitEvent: (eventName: string, input: Record<string, any>) => Promise<Record<string, any>>;
|
|
63
65
|
components: Components;
|
|
64
66
|
mediaQueries: typeof mediaQueries;
|
|
65
67
|
intlDate: typeof intlDate;
|