@zeyolabs/ui 2026.11.42 → 2026.11.43

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.
@@ -3,16 +3,18 @@
3
3
  import {
4
4
  deletePolicyCmd,
5
5
  getAccountMembers,
6
- savePolicyCmd,
6
+ savePolicyForm,
7
7
  } from '@zeyolabs/kit/auth/accounts/accounts.remote';
8
+ import { AccountSchemas } from '@zeyolabs/kit/auth/accounts/schemas';
8
9
  import { toast } from 'svelte-sonner';
9
10
 
10
11
  import Badge from '../badge/Badge.svelte';
11
12
  import Boundary from '../boundary/Boundary.svelte';
12
13
  import Card from '../card/Card.svelte';
13
14
  import Button from '../form/Button.svelte';
14
- import Checkbox from '../form/primitives/Checkbox.svelte';
15
- import Input from '../form/primitives/Input.svelte';
15
+ import CheckboxGroupField from '../form/fields/CheckboxGroupField.svelte';
16
+ import TextField from '../form/fields/TextField.svelte';
17
+ import Form from '../form/Form.svelte';
16
18
  import SkeletonText from '../skeleton/SkeletonText.svelte';
17
19
  import Span from '../text/Span.svelte';
18
20
  import Title from '../text/Title.svelte';
@@ -23,39 +25,16 @@
23
25
  */
24
26
  let { title = 'Policies' }: { title?: string } = $props();
25
27
 
26
- type Draft = { isNew: boolean; key: string; name: string; permissions: string[] };
28
+ type Editing = { isNew: boolean; key: string; name: string; permissions: string[] };
27
29
 
28
- let draft = $state<Draft | null>(null);
29
- let saving = $state(false);
30
+ let editing = $state<Editing | null>(null);
30
31
 
31
32
  function edit(policy?: { key: string; name: string; permissions: readonly string[] }) {
32
- draft = policy
33
+ editing = policy
33
34
  ? { isNew: false, key: policy.key, name: policy.name, permissions: [...policy.permissions] }
34
35
  : { isNew: true, key: '', name: '', permissions: [] };
35
36
  }
36
37
 
37
- function toggle(permission: string, on: boolean) {
38
- if (!draft) return;
39
- draft.permissions = on
40
- ? [...draft.permissions, permission]
41
- : draft.permissions.filter((p) => p !== permission);
42
- }
43
-
44
- async function save() {
45
- if (!draft) return;
46
- saving = true;
47
- try {
48
- const { key, name, permissions } = draft;
49
- await savePolicyCmd({ key: key.trim(), name, permissions });
50
- toast.success(`Saved ${name}`);
51
- draft = null;
52
- } catch (err) {
53
- toast.error(err instanceof Error ? err.message : 'Could not save the policy');
54
- } finally {
55
- saving = false;
56
- }
57
- }
58
-
59
38
  async function remove(key: string) {
60
39
  try {
61
40
  await deletePolicyCmd({ key });
@@ -72,7 +51,7 @@
72
51
  <Card gap="sm" padding="md">
73
52
  <div class="head">
74
53
  <Title level={2} size="xs">{title}</Title>
75
- {#if data.can.managePolicies && !draft}
54
+ {#if data.can.managePolicies && !editing}
76
55
  <Button onclick={() => edit()} size="sm" variant="secondary">
77
56
  <Plus size={13} /> New policy
78
57
  </Button>
@@ -102,42 +81,42 @@
102
81
  {/each}
103
82
  </ul>
104
83
 
105
- {#if draft}
106
- <div class="editor">
107
- <div class="row">
108
- <Input
109
- aria-label="Policy name"
110
- placeholder="Name, e.g. Support"
111
- bind:value={draft.name}
112
- />
113
- <Input
114
- aria-label="Policy key"
115
- disabled={!draft.isNew}
116
- placeholder="key, e.g. support"
117
- bind:value={draft.key}
118
- />
119
- </div>
120
- <div class="grants">
121
- {#each data.permissions as permission (permission)}
122
- <Checkbox
123
- checked={draft.permissions.includes(permission)}
124
- onCheckedChange={(on) => toggle(permission, on)}
125
- >
126
- {permission}
127
- </Checkbox>
128
- {/each}
129
- </div>
130
- <div class="row">
131
- <Button
132
- disabled={saving || !draft.name.trim() || !draft.key.trim()}
133
- onclick={save}
134
- size="sm"
84
+ {#if editing}
85
+ {#key editing.key || 'new'}
86
+ <div class="editor">
87
+ <Form
88
+ defaults={{ key: editing.key, name: editing.name, permissions: editing.permissions }}
89
+ form={savePolicyForm}
90
+ hidden={editing.isNew ? undefined : { key: editing.key }}
91
+ onSuccess={() => (editing = null)}
92
+ schema={AccountSchemas.PolicyForm}
135
93
  >
136
- {saving ? 'Saving…' : 'Save policy'}
137
- </Button>
138
- <Button onclick={() => (draft = null)} size="sm" variant="ghost">Cancel</Button>
94
+ <div class="row">
95
+ <TextField name="name" form={savePolicyForm} placeholder="Name, e.g. Support">
96
+ Name
97
+ </TextField>
98
+ {#if editing.isNew}
99
+ <TextField name="key" form={savePolicyForm} placeholder="key, e.g. support">
100
+ Key
101
+ </TextField>
102
+ {/if}
103
+ </div>
104
+ <CheckboxGroupField
105
+ name="permissions"
106
+ form={savePolicyForm}
107
+ getKey={(p) => p}
108
+ getLabel={(p) => p}
109
+ getValue={(p) => p}
110
+ items={data.permissions}
111
+ label="Permissions"
112
+ />
113
+ <div class="row">
114
+ <Button form={savePolicyForm} size="sm">Save policy</Button>
115
+ <Button onclick={() => (editing = null)} size="sm" variant="ghost">Cancel</Button>
116
+ </div>
117
+ </Form>
139
118
  </div>
140
- </div>
119
+ {/key}
141
120
  {/if}
142
121
  </Card>
143
122
 
@@ -183,9 +162,4 @@
183
162
  display: flex;
184
163
  gap: 8px;
185
164
  }
186
- .grants {
187
- display: grid;
188
- grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
189
- gap: 6px;
190
- }
191
165
  </style>
@@ -21,6 +21,11 @@ export function setFormChangeListener(listener: () => void): void {
21
21
  setContext(FORM_CHANGE_KEY, listener);
22
22
  }
23
23
 
24
+ /** The enclosing `<Form>`'s change listener, for a field that sets its value itself. Call at init. */
25
+ export function formChangeListener(): (() => void) | undefined {
26
+ return getContext<(() => void) | undefined>(FORM_CHANGE_KEY);
27
+ }
28
+
24
29
  /**
25
30
  * The surface every field template consumes. Produced either from a `RemoteForm`
26
31
  * field (`createFormView`) or from local `$bindable` state (`createLocal*View`).
@@ -0,0 +1,89 @@
1
+ <script generics="Input extends RemoteFormInput, T" lang="ts">
2
+ import type { RemoteForm, RemoteFormInput } from '$app/server';
3
+
4
+ import CheckIcon from '@lucide/svelte/icons/check';
5
+ import { Checkbox } from 'bits-ui';
6
+
7
+ import { type FieldIssue, formChangeListener } from '../field-view.svelte.js';
8
+ import FieldLabel from '../FieldLabel.svelte';
9
+
10
+ /**
11
+ * A list of checkboxes for one `string[]` field of a remote form: the ticked items' values are
12
+ * submitted as the list (none ticked: the field is absent, so give the schema a `.default([])`).
13
+ */
14
+ interface Props {
15
+ description?: string;
16
+ disabled?: boolean;
17
+ form: Omit<RemoteForm<Input, unknown>, 'for'> | RemoteForm<Input, unknown>;
18
+ getKey: (item: T) => string;
19
+ getLabel: (item: T) => string;
20
+ getValue: (item: T) => string;
21
+ items: readonly T[];
22
+ label?: string;
23
+ name: keyof Input & string;
24
+ }
25
+
26
+ let { description, disabled, form, getKey, getLabel, getValue, items, label, name }: Props =
27
+ $props();
28
+
29
+ type ListField = {
30
+ as(type: 'checkbox', value: string): Record<string, unknown> & { name: string };
31
+ issues(): FieldIssue[] | undefined;
32
+ set(input: string[]): unknown;
33
+ value(): string[] | undefined;
34
+ };
35
+
36
+ const field = $derived((form.fields as unknown as Record<string, ListField>)[name]);
37
+ const notifyChange = formChangeListener();
38
+
39
+ function toggle(value: string, on: boolean) {
40
+ const current = field.value() ?? [];
41
+ field.set(on ? [...new Set([...current, value])] : current.filter((v) => v !== value));
42
+ notifyChange?.();
43
+ }
44
+ </script>
45
+
46
+ <fieldset class="form-checkbox-group" {disabled}>
47
+ {#if label}
48
+ <legend class="form-label">{label}</legend>
49
+ {/if}
50
+ {#each items as item (getKey(item))}
51
+ {const value = $derived(getValue(item))}
52
+ {const attrs = $derived(field.as('checkbox', value))}
53
+ {const id = $derived(`${attrs.name}-${getKey(item)}`)}
54
+ <div class="form-checkbox-row">
55
+ <Checkbox.Root
56
+ {id}
57
+ name={attrs.name}
58
+ class="form-checkbox"
59
+ checked={attrs.checked as boolean}
60
+ {disabled}
61
+ onCheckedChange={(v) => toggle(value, v === true)}
62
+ {value}
63
+ >
64
+ {#snippet children({ checked })}
65
+ {#if checked}
66
+ <CheckIcon class="form-checkbox-icon" />
67
+ {/if}
68
+ {/snippet}
69
+ </Checkbox.Root>
70
+ <FieldLabel class="form-checkbox-label" for={id}>{getLabel(item)}</FieldLabel>
71
+ </div>
72
+ {/each}
73
+ {#if description}
74
+ <p class="form-description">{description}</p>
75
+ {/if}
76
+ {#each field.issues() ?? [] as issue (`${issue.path}`)}
77
+ <p class="form-error">{issue.message}</p>
78
+ {/each}
79
+ </fieldset>
80
+
81
+ <style>
82
+ .form-checkbox-group {
83
+ display: grid;
84
+ gap: 6px;
85
+ border: 0;
86
+ margin: 0;
87
+ padding: 0;
88
+ }
89
+ </style>
@@ -1,4 +1,5 @@
1
1
  export { default as CheckboxField } from './CheckboxField.svelte';
2
+ export { default as CheckboxGroupField } from './CheckboxGroupField.svelte';
2
3
  export { default as Combobox } from './Combobox.svelte';
3
4
  export { default as ComboboxAction } from './ComboboxAction.svelte';
4
5
  export { default as DateField } from './DateField.svelte';
package/form/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as Button } from './Button.svelte';
2
2
  export { default as CheckboxField } from './fields/CheckboxField.svelte';
3
+ export { default as CheckboxGroupField } from './fields/CheckboxGroupField.svelte';
3
4
  export { default as Combobox } from './fields/Combobox.svelte';
4
5
  export { default as ComboboxAction } from './fields/ComboboxAction.svelte';
5
6
  export { default as DateField } from './fields/DateField.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeyolabs/ui",
3
- "version": "2026.11.42",
3
+ "version": "2026.11.43",
4
4
  "description": "Shared Svelte 5 components, form fields and design tokens for SvelteKit 3 apps.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -134,7 +134,7 @@
134
134
  "./head/*": "./head/*"
135
135
  },
136
136
  "peerDependencies": {
137
- "@zeyolabs/kit": ">=2026.11.6",
137
+ "@zeyolabs/kit": ">=2026.11.44",
138
138
  "@sveltejs/kit": "^3.1.1",
139
139
  "svelte": "^5.57.3"
140
140
  },
@@ -155,7 +155,7 @@
155
155
  "devDependencies": {
156
156
  "@eslint/compat": "2.1.1",
157
157
  "@eslint/js": "10.0.1",
158
- "@zeyolabs/kit": "2026.11.42",
158
+ "@zeyolabs/kit": "2026.11.44",
159
159
  "@sveltejs/kit": "3.2.0",
160
160
  "@types/flickity": "2.2.12",
161
161
  "eslint": "10.15.0",