@lobb-js/studio 0.42.0 → 0.44.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 (38) hide show
  1. package/dist/components/confirmationDialog/confirmationDialog.svelte +1 -1
  2. package/dist/components/dataTable/dataTable.svelte +49 -17
  3. package/dist/components/dataTable/filter.svelte +26 -23
  4. package/dist/components/dataTable/header.svelte +17 -13
  5. package/dist/components/dataTable/header.svelte.d.ts +1 -0
  6. package/dist/components/dataTable/listViewChildren.svelte +60 -77
  7. package/dist/components/dataTable/listViewChildren.svelte.d.ts +1 -1
  8. package/dist/components/dataTable/table.svelte +20 -61
  9. package/dist/components/dataTable/table.svelte.d.ts +2 -2
  10. package/dist/components/detailView/changeTreeUtils.d.ts +7 -0
  11. package/dist/components/detailView/changeTreeUtils.js +47 -0
  12. package/dist/components/detailView/create/createDetailView.svelte +17 -13
  13. package/dist/components/detailView/detailView.svelte +7 -2
  14. package/dist/components/detailView/detailView.svelte.d.ts +1 -0
  15. package/dist/components/detailView/fieldInput.svelte +10 -9
  16. package/dist/components/detailView/fieldInput.svelte.d.ts +1 -0
  17. package/dist/components/detailView/update/updateDetailView.svelte +22 -18
  18. package/dist/components/drawer.svelte +15 -2
  19. package/dist/components/foreingKeyInput.svelte +32 -60
  20. package/dist/components/foreingKeyInput.svelte.d.ts +1 -1
  21. package/dist/components/polymorphicInput.svelte +42 -66
  22. package/dist/components/polymorphicInput.svelte.d.ts +1 -0
  23. package/package.json +2 -2
  24. package/src/app.css +2 -2
  25. package/src/lib/components/confirmationDialog/confirmationDialog.svelte +1 -1
  26. package/src/lib/components/dataTable/dataTable.svelte +49 -17
  27. package/src/lib/components/dataTable/filter.svelte +26 -23
  28. package/src/lib/components/dataTable/header.svelte +17 -13
  29. package/src/lib/components/dataTable/listViewChildren.svelte +60 -77
  30. package/src/lib/components/dataTable/table.svelte +20 -61
  31. package/src/lib/components/detailView/changeTreeUtils.ts +39 -0
  32. package/src/lib/components/detailView/create/createDetailView.svelte +17 -13
  33. package/src/lib/components/detailView/detailView.svelte +7 -2
  34. package/src/lib/components/detailView/fieldInput.svelte +10 -9
  35. package/src/lib/components/detailView/update/updateDetailView.svelte +22 -18
  36. package/src/lib/components/drawer.svelte +15 -2
  37. package/src/lib/components/foreingKeyInput.svelte +32 -60
  38. package/src/lib/components/polymorphicInput.svelte +42 -66
@@ -0,0 +1,7 @@
1
+ import type { Changes } from "./utils";
2
+ export interface TreeNode {
3
+ label: string;
4
+ children: TreeNode[];
5
+ }
6
+ export declare function buildChangeTree(c: Changes, fieldLabel?: string): TreeNode[];
7
+ export declare function renderTree(nodes: TreeNode[], prefix?: string): string[];
@@ -0,0 +1,47 @@
1
+ export function buildChangeTree(c, fieldLabel = 'changed') {
2
+ const nodes = [];
3
+ let fieldCount = 0;
4
+ for (const [fieldName, val] of Object.entries(c.data ?? {})) {
5
+ if (val && typeof val === 'object' && !Array.isArray(val)) {
6
+ const v = val;
7
+ const t = v.collection ?? fieldName;
8
+ if (v.delete === true)
9
+ nodes.push({ label: `${t}: inline delete`, children: [] });
10
+ else if (v.update)
11
+ nodes.push({ label: `${t}: inline edit`, children: [] });
12
+ else if (v.create)
13
+ nodes.push({ label: `${t}: inline create`, children: [] });
14
+ }
15
+ else {
16
+ fieldCount++;
17
+ }
18
+ }
19
+ if (fieldCount > 0)
20
+ nodes.unshift({ label: `${fieldCount} field${fieldCount > 1 ? 's' : ''} ${fieldLabel}`, children: [] });
21
+ for (const [col, ch] of Object.entries(c.children ?? {})) {
22
+ const kids = [];
23
+ for (let i = 0; i < ch.created.length; i++)
24
+ kids.push({ label: 'new record', children: [] });
25
+ for (const r of ch.linked)
26
+ kids.push({ label: `#${r.id} linked`, children: [] });
27
+ for (const u of ch.updated)
28
+ kids.push({ label: `#${u.id}`, children: buildChangeTree(u.changes) });
29
+ for (const r of ch.deleted)
30
+ kids.push({ label: `#${r.id} deleted`, children: [] });
31
+ for (const r of ch.unlinked)
32
+ kids.push({ label: `#${r.id} unlinked`, children: [] });
33
+ if (kids.length)
34
+ nodes.push({ label: col, children: kids });
35
+ }
36
+ return nodes;
37
+ }
38
+ export function renderTree(nodes, prefix = '') {
39
+ const lines = [];
40
+ nodes.forEach((node, i) => {
41
+ const last = i === nodes.length - 1;
42
+ lines.push(`${prefix}${last ? '└── ' : '├── '}${node.label}`);
43
+ if (node.children.length)
44
+ lines.push(...renderTree(node.children, prefix + (last ? ' ' : '│ ')));
45
+ });
46
+ return lines;
47
+ }
@@ -61,19 +61,15 @@
61
61
  const hasChildChanges = $derived(
62
62
  Object.values(changes.children).some((ch: ChildrenChanges) =>
63
63
  ch.created.length || ch.linked.length
64
+ ) ||
65
+ Object.values(changes.data).some((val: any) =>
66
+ val && typeof val === 'object' && !Array.isArray(val) && (val.create || val.update || val.delete)
64
67
  )
65
68
  );
66
69
 
67
- const changeSummaryLines = $derived.by(() => {
68
- const lines: string[] = [];
69
- const fieldCount = Object.keys(changes.data).length;
70
- if (fieldCount > 0) lines.push(`${fieldCount} field${fieldCount > 1 ? 's' : ''} filled`);
71
- for (const [col, ch] of Object.entries(changes.children) as [string, ChildrenChanges][]) {
72
- if (ch.created.length) lines.push(`${ch.created.length} created in ${col}`);
73
- if (ch.linked.length) lines.push(`${ch.linked.length} linked in ${col}`);
74
- }
75
- return lines;
76
- });
70
+ import { buildChangeTree, renderTree } from "../changeTreeUtils";
71
+
72
+ const changeSummaryLines = $derived(renderTree(buildChangeTree(changes, 'filled')));
77
73
 
78
74
  const fieldNames = Object.keys(ctx.meta.collections[collectionName].fields);
79
75
  let values = $state(getDefaultEntry(ctx, fieldNames, collectionName, passedValues));
@@ -92,7 +88,15 @@
92
88
  });
93
89
  });
94
90
 
91
+ function cleanFkField(val: any): any {
92
+ if (!val || typeof val !== 'object' || Array.isArray(val)) return val;
93
+ if (val.id && val.update) return { ...(val.collection ? { collection: val.collection } : {}), update: val.update };
94
+ return val;
95
+ }
96
+
95
97
  function buildPayload(changes: Changes): { data: Record<string, any>; children?: Record<string, any> } {
98
+ const data: Record<string, any> = {};
99
+ for (const [key, val] of Object.entries(changes.data)) data[key] = cleanFkField(val);
96
100
  const result: Record<string, any> = {};
97
101
  for (const [collection, ops] of Object.entries(changes.children)) {
98
102
  const hasOps = ops.created.length || ops.linked.length;
@@ -103,7 +107,7 @@
103
107
  };
104
108
  }
105
109
  const children = Object.keys(result).length ? result : undefined;
106
- return { data: changes.data, ...(children ? { children } : {}) };
110
+ return { data, ...(children ? { children } : {}) };
107
111
  }
108
112
 
109
113
  function handleCancel() {
@@ -114,7 +118,7 @@
114
118
  if (!isRecordingMode && hasChildChanges && changeSummaryLines.length > 0) {
115
119
  const confirmed = await showDialog(
116
120
  "Confirm changes",
117
- changeSummaryLines.map(l => `• ${l}`).join('\n')
121
+ changeSummaryLines.join('\n')
118
122
  );
119
123
  if (!confirmed) return;
120
124
  }
@@ -126,7 +130,7 @@
126
130
  onChanges?.(snap);
127
131
  if (onSuccessfullSave) await onSuccessfullSave(snap);
128
132
  await onCreated?.(snap.data);
129
- toast.success(`The record was successfully created`);
133
+ if (!isRecordingMode) toast.success(`The record was successfully created`);
130
134
  handleCancel();
131
135
  return;
132
136
  }
@@ -12,12 +12,14 @@
12
12
  collectionName: string;
13
13
  entry: Record<string, any>;
14
14
  fieldsErrors?: Record<string, string[]>;
15
+ changedFields?: string[];
15
16
  }
16
17
 
17
18
  let {
18
19
  collectionName,
19
20
  entry = $bindable(),
20
21
  fieldsErrors = {},
22
+ changedFields = [],
21
23
  }: Props = $props();
22
24
 
23
25
  const { lobb, ctx } = getStudioContext();
@@ -31,13 +33,15 @@
31
33
  );
32
34
  </script>
33
35
 
34
- <div class="flex flex-col gap-4 p-4">
36
+ <div class="grid grid-cols-2 gap-4 p-4">
35
37
  {#each fieldNames as fieldName}
36
38
  {#if !ctx.meta.collections[collectionName].fields[fieldName]?.ui?.hidden}
37
39
  {@const field = getField(ctx, fieldName, collectionName)}
38
40
  {@const FieldIcon = getFieldIcon(ctx, fieldName, collectionName)}
39
41
  {@const description = ctx.meta.collections[collectionName].fields[fieldName]?.description}
40
- <div class="flex flex-col gap-2">
42
+ {@const fieldDef = ctx.meta.collections[collectionName].fields[fieldName]}
43
+ {@const isFullWidth = field.type === "text" || field.type === "polymorphic" || fieldDef?.ui?.input?.type === "richtext" || fieldDef?.ui?.span === 2}
44
+ <div class="flex flex-col gap-2 {isFullWidth ? 'col-span-2' : 'col-span-1'}">
41
45
  <div class="flex flex-1 items-end justify-between gap-2 text-xs">
42
46
  <div class="flex items-center gap-1.5">
43
47
  <ExtensionsComponents
@@ -80,6 +84,7 @@
80
84
  bind:value={entry[fieldName]}
81
85
  bind:entry
82
86
  errorMessages={fieldsErrors[fieldName]}
87
+ changed={changedFields.includes(fieldName)}
83
88
  />
84
89
  </div>
85
90
  {/if}
@@ -2,6 +2,7 @@ interface Props {
2
2
  collectionName: string;
3
3
  entry: Record<string, any>;
4
4
  fieldsErrors?: Record<string, string[]>;
5
+ changedFields?: string[];
5
6
  }
6
7
  declare const DetailView: import("svelte").Component<Props, {}, "entry">;
7
8
  type DetailView = ReturnType<typeof DetailView>;
@@ -24,6 +24,7 @@
24
24
  value: any;
25
25
  errorMessages?: string[];
26
26
  entry?: Record<string, any>;
27
+ changed?: boolean;
27
28
  }
28
29
 
29
30
  let {
@@ -32,6 +33,7 @@
32
33
  value = $bindable(),
33
34
  errorMessages = [],
34
35
  entry = $bindable(),
36
+ changed = false,
35
37
  }: Props = $props();
36
38
 
37
39
  const ui_input =
@@ -44,6 +46,7 @@
44
46
  const isDisabled = field.key === 'id' || Boolean(ui?.disabled)
45
47
  const disabledClasses = "pointer-events-none opacity-50";
46
48
  const destructive: boolean = $derived(!isDisabled && Boolean(errorMessages.length));
49
+ const changedClass = $derived(changed && !destructive ? '!bg-orange-500/5' : '');
47
50
 
48
51
  </script>
49
52
 
@@ -72,6 +75,7 @@
72
75
  <PolymorphicInput
73
76
  collectionField={polymorphicRelation.from.collection_field}
74
77
  idField={polymorphicRelation.from.id_field}
78
+ virtualField={polymorphicRelation.from.virtual_field ?? ''}
75
79
  targetCollections={polymorphicRelation.to}
76
80
  bind:entry
77
81
  {destructive}
@@ -87,7 +91,7 @@
87
91
  {:else if field.label === "id"}
88
92
  <Input
89
93
  placeholder="AUTO GENERATED"
90
- class="bg-muted text-xs"
94
+ class="bg-muted text-xs {changedClass}"
91
95
  bind:value
92
96
  />
93
97
  {:else if fieldRelationTarget && entry}
@@ -126,10 +130,7 @@
126
130
  }
127
131
  >
128
132
  <Select.Trigger
129
- class="
130
- h-9 w-full bg-muted pr-8
131
- {destructive ? 'border-destructive bg-destructive/10' : ''}
132
- "
133
+ class="h-9 w-full bg-muted pr-8 {changedClass} {destructive ? 'border-destructive !bg-destructive/10' : ''}"
133
134
  >
134
135
  {#if value != null && enumOptions}
135
136
  <EnumBadge value={String(value)} enum={enumOptions} />
@@ -159,7 +160,7 @@
159
160
  placeholder={ui?.placeholder ? ui.placeholder : "NULL"}
160
161
  type="text"
161
162
  class="
162
- bg-muted text-xs
163
+ bg-muted text-xs {changedClass}
163
164
  {destructive ? 'border-destructive bg-destructive/10' : ''}
164
165
  "
165
166
  bind:value
@@ -169,7 +170,7 @@
169
170
  placeholder={ui?.placeholder ? ui.placeholder : value === "" ? "EMPTY STRING" : "NULL"}
170
171
  rows={5}
171
172
  class="
172
- bg-muted text-xs
173
+ bg-muted text-xs {changedClass}
173
174
  {destructive ? 'border-destructive bg-destructive/10' : ''}
174
175
  "
175
176
  bind:value
@@ -265,7 +266,7 @@
265
266
  scale={isFloat ? 20 : 0}
266
267
  groupDigits={ui?.groupDigits ?? false}
267
268
  class="
268
- bg-muted text-xs
269
+ bg-muted text-xs {changedClass}
269
270
  {destructive ? 'border-destructive bg-destructive/10' : ''}
270
271
  "
271
272
  bind:value
@@ -275,7 +276,7 @@
275
276
  placeholder={ui?.placeholder ? ui.placeholder : "NULL"}
276
277
  type="text"
277
278
  class="
278
- bg-muted text-xs
279
+ bg-muted text-xs {changedClass}
279
280
  {destructive ? 'border-destructive bg-destructive/10' : ''}
280
281
  "
281
282
  bind:value
@@ -4,6 +4,7 @@ interface Props {
4
4
  value: any;
5
5
  errorMessages?: string[];
6
6
  entry?: Record<string, any>;
7
+ changed?: boolean;
7
8
  }
8
9
  declare const FieldInput: import("svelte").Component<Props, {}, "value" | "entry">;
9
10
  type FieldInput = ReturnType<typeof FieldInput>;
@@ -29,6 +29,7 @@
29
29
  import { untrack } from "svelte";
30
30
  import { showDialog } from "../../../actions";
31
31
 
32
+
32
33
  const { lobb, ctx } = getStudioContext();
33
34
  import { getChangedProperties } from "../../../utils";
34
35
  import UpdateDetailViewChildren from "./updateDetailViewChildren.svelte";
@@ -81,22 +82,15 @@
81
82
  const hasChildChanges = $derived(
82
83
  Object.values(localChanges.children).some((ch: ChildrenChanges) =>
83
84
  ch.created.length || ch.updated.length || ch.deleted.length || ch.linked.length || ch.unlinked.length
85
+ ) ||
86
+ Object.values(localChanges.data).some((val: any) =>
87
+ val && typeof val === 'object' && !Array.isArray(val) && (val.create || val.update || val.delete)
84
88
  )
85
89
  );
86
90
 
87
- const changeSummaryLines = $derived.by(() => {
88
- const lines: string[] = [];
89
- const fieldCount = Object.keys(localChanges.data).length;
90
- if (fieldCount > 0) lines.push(`${fieldCount} field${fieldCount > 1 ? 's' : ''} changed`);
91
- for (const [col, ch] of Object.entries(localChanges.children) as [string, ChildrenChanges][]) {
92
- if (ch.created.length) lines.push(`${ch.created.length} created in ${col}`);
93
- if (ch.linked.length) lines.push(`${ch.linked.length} linked in ${col}`);
94
- if (ch.updated.length) lines.push(`${ch.updated.length} edited in ${col}`);
95
- if (ch.deleted.length) lines.push(`${ch.deleted.length} deleted from ${col}`);
96
- if (ch.unlinked.length) lines.push(`${ch.unlinked.length} unlinked from ${col}`);
97
- }
98
- return lines;
99
- });
91
+ import { buildChangeTree, renderTree } from "../changeTreeUtils";
92
+
93
+ const changeSummaryLines = $derived(renderTree(buildChangeTree(localChanges)));
100
94
 
101
95
  $effect(() => {
102
96
  const currentEntrySnap = $state.snapshot(values);
@@ -106,8 +100,18 @@
106
100
  });
107
101
  });
108
102
 
103
+ function cleanFkField(val: any): any {
104
+ if (!val || typeof val !== 'object' || Array.isArray(val)) return val;
105
+ // strip internal id from pending edit (server reads from DB)
106
+ if (val.id && val.update) return { ...(val.collection ? { collection: val.collection } : {}), update: val.update };
107
+ // { delete: true } — pass through as-is (no id needed)
108
+ return val;
109
+ }
110
+
109
111
  function buildPayload(changes: Changes): { data: Record<string, any>; children?: Record<string, any> } {
110
- const { id: _id, ...data } = changes.data;
112
+ const { id: _id, ...rawData } = changes.data;
113
+ const data: Record<string, any> = {};
114
+ for (const [key, val] of Object.entries(rawData)) data[key] = cleanFkField(val);
111
115
  const children = buildChildren(changes.children);
112
116
  return { data, ...(children ? { children } : {}) };
113
117
  }
@@ -140,7 +144,7 @@
140
144
  if (!isRecordingMode && hasChildChanges && changeSummaryLines.length > 0) {
141
145
  const confirmed = await showDialog(
142
146
  "Confirm changes",
143
- changeSummaryLines.map(l => `• ${l}`).join('\n')
147
+ changeSummaryLines.join('\n')
144
148
  );
145
149
  if (!confirmed) return;
146
150
  }
@@ -151,7 +155,7 @@
151
155
  if (response.status === 204) {
152
156
  onChanges?.(snap);
153
157
  if (onSuccessfullSave) await onSuccessfullSave(snap);
154
- toast.success(`The record was successfully updated`);
158
+ if (!isRecordingMode) toast.success(`The record was successfully updated`);
155
159
  onCancel?.();
156
160
  return;
157
161
  }
@@ -171,7 +175,7 @@
171
175
 
172
176
  onChanges?.(snap);
173
177
  if (onSuccessfullSave) await onSuccessfullSave(snap);
174
- toast.success(`The record was successfully updated`);
178
+ if (!isRecordingMode) toast.success(`The record was successfully updated`);
175
179
  onCancel?.();
176
180
  }
177
181
  </script>
@@ -196,7 +200,7 @@
196
200
  </div>
197
201
  </div>
198
202
  <div class="flex-1 overflow-y-auto">
199
- <DetailView {collectionName} bind:entry={values} {fieldsErrors} />
203
+ <DetailView {collectionName} bind:entry={values} {fieldsErrors} changedFields={Object.keys(localChanges.data)} />
200
204
  {#if showRelatedRecords}
201
205
  <UpdateDetailViewChildren {collectionName} entry={values} changes={localChanges} onChanges={(children) => { localChanges.children = children; }} />
202
206
  {/if}
@@ -4,6 +4,7 @@
4
4
  import { fade } from "svelte/transition";
5
5
  import { cubicOut } from "svelte/easing";
6
6
  import Portal from "svelte-portal";
7
+ import { getContext, setContext, onDestroy } from "svelte";
7
8
 
8
9
  interface Props {
9
10
  children?: Snippet<[]>;
@@ -13,6 +14,16 @@
13
14
 
14
15
  let { onHide, children, position = "side" }: Props = $props();
15
16
 
17
+ // Track nesting depth for stacking effect
18
+ const DEPTH_KEY = 'drawer-depth';
19
+ const parentDepth: number = getContext(DEPTH_KEY) ?? 0;
20
+ const depth = parentDepth + 1;
21
+ setContext(DEPTH_KEY, depth);
22
+
23
+ // Side drawers get narrower, bottom drawers get shorter — both offset by 48px per level
24
+ const sideWidth = $derived(calculateDrawerWidth() - (depth - 1) * 48);
25
+ const bottomOffset = $derived((depth - 1) * 48);
26
+
16
27
  function slide(_node: Element, { duration = 250, axis }: { duration?: number; axis: "x" | "y" }) {
17
28
  return {
18
29
  duration,
@@ -39,9 +50,11 @@
39
50
  role="dialog"
40
51
  transition:slide={{ axis: position === "bottom" ? "y" : "x" }}
41
52
  class={position === "bottom"
42
- ? "fixed bottom-0 left-0 z-40 flex h-[60vh] w-full flex-col border-t bg-card"
53
+ ? "fixed bottom-0 left-0 z-40 flex w-full flex-col border-t bg-card"
43
54
  : "fixed right-0 top-0 z-40 flex h-full w-full flex-col border-l bg-card"}
44
- style={position === "side" ? `max-width: ${calculateDrawerWidth()}px;` : ""}
55
+ style={position === "side"
56
+ ? `max-width: ${sideWidth}px;`
57
+ : `height: calc(60vh - ${bottomOffset}px);`}
45
58
  >
46
59
  {@render children?.()}
47
60
  </div>
@@ -2,20 +2,15 @@
2
2
  import { onMount } from "svelte";
3
3
  import Input from "./ui/input/input.svelte";
4
4
  import SelectRecord from "./selectRecord.svelte";
5
- import UpdateDetailViewButton from "./detailView/update/updateDetailViewButton.svelte";
6
5
  import CreateDetailView from "./detailView/create/createDetailView.svelte";
7
- import { getCollectionPrimaryField } from "./dataTable/utils";
8
- import { getStudioContext } from "../context";
9
- import { ExternalLink, Plus } from "lucide-svelte";
6
+ import { Plus } from "lucide-svelte";
10
7
  import Button from "./ui/button/button.svelte";
11
8
 
12
- const { lobb, ctx } = getStudioContext();
13
-
14
9
  interface LocalProps {
15
10
  parentCollectionName: string;
16
11
  collectionName: string;
17
12
  fieldName: string;
18
- value?: number | null;
13
+ value?: any;
19
14
  destructive?: boolean;
20
15
  entry: Record<string, any>;
21
16
  }
@@ -29,57 +24,39 @@
29
24
  entry,
30
25
  }: LocalProps = $props();
31
26
 
32
- let displayName = $state<string | null>(null);
33
27
  let createDrawerOpen = $state(false);
28
+ let initialValue = $state<any>(undefined);
34
29
 
35
- onMount(async () => {
36
- if (value == null) return;
37
- try {
38
- const res = await lobb.findOne(collectionName, value);
39
- const record = (await res.json()).data;
40
- const primaryFieldName = getCollectionPrimaryField(ctx, collectionName);
41
- displayName = primaryFieldName ? String(record[primaryFieldName]) : null;
42
- } catch {
43
- displayName = null;
44
- }
45
- });
30
+ onMount(() => { initialValue = value; });
46
31
 
47
- $effect(() => {
48
- if (value == null) displayName = null;
49
- });
32
+ const isPendingCreate = $derived(value && typeof value === 'object' && value.create);
33
+ const hasRealId = $derived(value != null && typeof value === 'number');
34
+ const isEmpty = $derived(value == null || value === 0);
35
+ const isZeroPlaceholder = $derived(value === 0);
36
+ const isChanged = $derived(initialValue !== undefined && value !== initialValue && !isPendingCreate);
50
37
 
51
- function handleSelect(selectedEntry: any) {
52
- const primaryFieldName = getCollectionPrimaryField(ctx, collectionName);
53
- value = selectedEntry.id;
54
- displayName = primaryFieldName ? String(selectedEntry[primaryFieldName]) : null;
55
- }
38
+ const bgClass = $derived(
39
+ isPendingCreate ? '!bg-green-500/5 border-green-500/40' :
40
+ isChanged ? '!bg-orange-500/5' :
41
+ ''
42
+ );
56
43
 
57
44
  async function handleCreated(record: any) {
58
- const primaryFieldName = getCollectionPrimaryField(ctx, collectionName);
59
- value = record.id;
60
- displayName = primaryFieldName ? String(record[primaryFieldName]) : null;
45
+ if (!record.id) {
46
+ value = { create: record };
47
+ } else {
48
+ value = record.id;
49
+ }
61
50
  }
62
51
 
63
- const idIsZero = $derived(value === 0);
52
+ function handleSelect(selectedEntry: any) {
53
+ value = selectedEntry.id;
54
+ }
64
55
  </script>
65
56
 
66
- {#if !idIsZero}
57
+ {#if !isZeroPlaceholder}
67
58
  <div class="relative">
68
- <div class="flex gap-2 absolute right-0 top-0 mr-9 h-full items-center text-xs">
69
- {#if value != null}
70
- <UpdateDetailViewButton
71
- collectionName={collectionName}
72
- recordId={value}
73
- variant="ghost"
74
- class="h-5 w-5 px-0 py-0 text-muted-foreground hover:bg-transparent"
75
- Icon={ExternalLink}
76
- ></UpdateDetailViewButton>
77
- {/if}
78
- {#if displayName}
79
- <div class="flex items-center bg-background rounded-full border h-6 px-3 shadow-sm">
80
- {displayName}
81
- </div>
82
- {/if}
59
+ <div class="flex gap-1 absolute right-0 top-0 mr-9 h-full items-center text-xs">
83
60
  <Button
84
61
  class="h-6 px-2 font-normal text-xs"
85
62
  variant="outline"
@@ -95,30 +72,24 @@
95
72
  {collectionName}
96
73
  {fieldName}
97
74
  onSelect={handleSelect}
98
- text="Select"
75
+ text="Link"
99
76
  {entry}
100
77
  />
101
78
  </div>
79
+
102
80
  <Input
103
- placeholder={"NULL"}
81
+ placeholder={isPendingCreate ? "AUTO GENERATED" : isEmpty ? "NULL" : ""}
104
82
  type="number"
105
- class="
106
- bg-muted text-xs
107
- {destructive ? 'border-destructive bg-destructive/10' : ''}
108
- "
83
+ class="bg-muted text-xs {bgClass} {destructive ? '!bg-destructive/10 border-destructive' : ''}"
109
84
  bind:value={
110
- () => value ?? "",
111
- (v) => (value = (v === "" || v == null) ? null : Number(v))
85
+ () => hasRealId ? value : "",
86
+ (v) => { value = (v === "" || v == null) ? null : Number(v); }
112
87
  }
113
88
  />
114
89
  </div>
115
90
  {:else}
116
91
  <div class="relative z-10">
117
- <Input
118
- placeholder={"PARENT ID"}
119
- class="bg-muted text-xs"
120
- disabled={true}
121
- />
92
+ <Input placeholder="PARENT ID" class="bg-muted text-xs" disabled={true} />
122
93
  </div>
123
94
  {/if}
124
95
 
@@ -126,6 +97,7 @@
126
97
  <CreateDetailView
127
98
  collectionName={collectionName}
128
99
  onCreated={handleCreated}
100
+ onChanges={() => {}}
129
101
  onCancel={async () => { createDrawerOpen = false; }}
130
102
  />
131
103
  {/if}
@@ -2,7 +2,7 @@ interface LocalProps {
2
2
  parentCollectionName: string;
3
3
  collectionName: string;
4
4
  fieldName: string;
5
- value?: number | null;
5
+ value?: any;
6
6
  destructive?: boolean;
7
7
  entry: Record<string, any>;
8
8
  }