@svadmin/lite 0.3.0 → 0.3.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/lite",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "SSR-compatible lightweight admin UI for @svadmin — zero client-side JS, works in IE11",
5
5
  "type": "module",
6
6
  "files": [
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "peerDependencies": {
23
23
  "svelte": "^5.0.0",
24
- "@svadmin/core": "^0.19.5",
24
+ "@svadmin/core": "^0.21.2",
25
25
  "@sveltejs/kit": "^2.0.0"
26
26
  },
27
27
  "dependencies": {
@@ -21,10 +21,10 @@
21
21
  canEdit = true,
22
22
  }: Props = $props();
23
23
 
24
- const pk = resource.primaryKey ?? 'id';
25
- const id = record[pk];
24
+ let pk = $derived(resource.primaryKey ?? 'id');
25
+ let id = $derived(record[pk]);
26
26
  const showFields = $derived(
27
- resource.fields.filter(f => f.showInShow !== false && f.showInList !== false)
27
+ resource.fields.filter(f => f.showInShow !== false)
28
28
  );
29
29
  </script>
30
30
 
@@ -29,7 +29,7 @@
29
29
  canDelete = true,
30
30
  }: Props = $props();
31
31
 
32
- const pk = resource.primaryKey ?? 'id';
32
+ let pk = $derived(resource.primaryKey ?? 'id');
33
33
  const listFields = $derived(
34
34
  resource.fields.filter(f => f.showInList !== false)
35
35
  );
@@ -22,7 +22,7 @@
22
22
  </script>
23
23
 
24
24
  <a
25
- href="{basePath}/{resource}/create?cloneId={recordItemId}"
25
+ href="{basePath}/{resource}/clone/{recordItemId}"
26
26
  class="lite-btn {size === 'sm' ? 'lite-btn-sm' : ''} {className}"
27
27
  title={t('common.clone') || 'Clone'}
28
28
  >
@@ -16,7 +16,7 @@
16
16
  </script>
17
17
 
18
18
  <a
19
- href="?"
19
+ href=""
20
20
  class="lite-btn {size === 'sm' ? 'lite-btn-sm' : ''} {className}"
21
21
  title={t('common.refresh') || 'Refresh'}
22
22
  >
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
  </script>
14
14
 
15
15
  {#if mode === 'show'}
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
 
14
14
  function formatDate(v: unknown): string {
15
15
  if (!v) return '';
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
  </script>
14
14
 
15
15
  {#if mode === 'show'}
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
 
14
14
  function getFiles(v: unknown): string[] {
15
15
  if (!v) return [];
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
 
14
14
  function getUrls(v: unknown): string[] {
15
15
  if (!v) return [];
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
 
14
14
  function getJsonString(v: unknown): string {
15
15
  if (v == null) return '';
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
  </script>
14
14
 
15
15
  {#if mode === 'show'}
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
 
14
14
  function displayOptions(valuesRaw: unknown): string[] {
15
15
  if (!valuesRaw || !Array.isArray(valuesRaw)) return [];
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
  </script>
14
14
 
15
15
  {#if mode === 'show'}
@@ -10,7 +10,7 @@
10
10
  }
11
11
 
12
12
  let { field, value, error = [], mode = 'show' }: Props = $props();
13
- const hasError = error.length > 0;
13
+ let hasError = $derived(error.length > 0);
14
14
 
15
15
  // In Lite version, relations might need to be rendered via server-side joined data
16
16
  // passed through options, or just standard inputs requesting ID.
@@ -10,7 +10,7 @@
10
10
  }
11
11
 
12
12
  let { field, value, error = [], mode = 'show' }: Props = $props();
13
- const hasError = error.length > 0;
13
+ let hasError = $derived(error.length > 0);
14
14
 
15
15
  function displaySelect(v: unknown): string {
16
16
  if (v == null) return '—';
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
  const tags = $derived(Array.isArray(value) ? value.map(String) : []);
14
14
  </script>
15
15
 
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
  </script>
14
14
 
15
15
  {#if mode === 'show'}
@@ -9,7 +9,7 @@
9
9
  }
10
10
 
11
11
  let { field, value, error = [], mode = 'show' }: Props = $props();
12
- const hasError = error.length > 0;
12
+ let hasError = $derived(error.length > 0);
13
13
  </script>
14
14
 
15
15
  {#if mode === 'show'}
@@ -24,8 +24,8 @@
24
24
  canShow = true,
25
25
  }: Props = $props();
26
26
 
27
- const pk = resource.primaryKey ?? 'id';
28
- const idStr = String(record[pk]);
27
+ let pk = $derived(resource.primaryKey ?? 'id');
28
+ let idStr = $derived(String(record[pk]));
29
29
  </script>
30
30
 
31
31
  <div class="lite-page">
@@ -70,6 +70,11 @@
70
70
  <LitePagination
71
71
  page={pagination.page}
72
72
  totalPages={Math.ceil(total / pagination.perPage)}
73
+ preserveParams={{
74
+ ...(currentSort ? { sort: currentSort } : {}),
75
+ ...(currentOrder ? { order: currentOrder } : {}),
76
+ ...(currentSearch ? { q: currentSearch } : {})
77
+ }}
73
78
  />
74
79
  {/if}
75
80
  </div>
@@ -22,8 +22,8 @@
22
22
  canDelete = true,
23
23
  }: Props = $props();
24
24
 
25
- const pk = resource.primaryKey ?? 'id';
26
- const idStr = String(record[pk]);
25
+ let pk = $derived(resource.primaryKey ?? 'id');
26
+ let idStr = $derived(String(record[pk]));
27
27
 
28
28
  const showFields = $derived(
29
29
  resource.fields.filter(f => f.showInShow !== false)
@@ -48,9 +48,9 @@
48
48
  <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px;">
49
49
  {#each showFields as field}
50
50
  <div>
51
- <label style="display: block; font-size: 13px; font-weight: 500; color: #64748b; margin-bottom: 8px;">
51
+ <div style="display: block; font-size: 13px; font-weight: 500; color: #64748b; margin-bottom: 8px;">
52
52
  {field.label}
53
- </label>
53
+ </div>
54
54
  <div style="color: #0f172a; font-size: 14px;">
55
55
  <LiteShowField {field} value={record[field.key]} />
56
56
  </div>
@@ -43,6 +43,8 @@ function fieldToZod(field: FieldDefinition): z.ZodTypeAny {
43
43
  }
44
44
  break;
45
45
  case 'multiselect':
46
+ schema = z.array(z.string()).default([]);
47
+ break;
46
48
  case 'tags':
47
49
  schema = z.string().transform((v: string) => v ? v.split(',').map((s: string) => s.trim()) : []);
48
50
  break;
@@ -9,7 +9,7 @@ import type {
9
9
  ResourceDefinition, FieldDefinition,
10
10
  Sort, Filter,
11
11
  } from '@svadmin/core';
12
- import type { RequestEvent } from '@sveltejs/kit';
12
+ import { fail, redirect, type RequestEvent } from '@sveltejs/kit';
13
13
 
14
14
  // ─── List Loader ──────────────────────────────────────────────
15
15
 
@@ -127,8 +127,10 @@ export function createCrudActions(
127
127
  delete: async ({ request }: RequestEvent) => {
128
128
  const formData = await request.formData();
129
129
  const id = formData.get('id') as string;
130
+ const redirectTo = formData.get('redirect') as string | undefined;
130
131
  try {
131
132
  await dp.deleteOne({ resource: resource.name, id });
133
+ if (redirectTo) throw redirect(303, redirectTo);
132
134
  return { success: true };
133
135
  } catch (e) {
134
136
  return { success: false, error: (e as Error).message };
@@ -190,7 +192,7 @@ export function createAuthActions(authProvider: AuthProvider) {
190
192
  sameSite: 'lax',
191
193
  maxAge: 60 * 60 * 24 * 7, // 7 days
192
194
  });
193
- return { success: true, redirectTo: result.redirectTo ?? '/lite' };
195
+ throw redirect(303, result.redirectTo ?? '/lite');
194
196
  }
195
197
  return { success: false, error: result.error?.message ?? 'Login failed' };
196
198
  } catch (e) {