@zeyolabs/ui 2026.11.41 → 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.
- package/account/AccountPolicies.svelte +43 -69
- package/faq/FAQList.svelte +1 -1
- package/filter/FilterChipGroup.svelte +1 -1
- package/filter/FilterOptionList.svelte +1 -1
- package/form/field-view.svelte.ts +5 -0
- package/form/fields/CheckboxGroupField.svelte +89 -0
- package/form/fields/index.ts +1 -0
- package/form/index.ts +1 -0
- package/form/primitives/IconInputWrapper.svelte +1 -1
- package/form/primitives/Input.svelte +1 -1
- package/form/primitives/TextArea.svelte +1 -1
- package/head/Head.svelte +59 -0
- package/head/context.ts +27 -0
- package/menu/MenuButton.svelte +1 -1
- package/package.json +6 -4
- package/status-row/StatusRow.svelte +4 -4
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
import {
|
|
4
4
|
deletePolicyCmd,
|
|
5
5
|
getAccountMembers,
|
|
6
|
-
|
|
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
|
|
15
|
-
import
|
|
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
|
|
28
|
+
type Editing = { isNew: boolean; key: string; name: string; permissions: string[] };
|
|
27
29
|
|
|
28
|
-
let
|
|
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
|
-
|
|
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 && !
|
|
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
|
|
106
|
-
|
|
107
|
-
<div class="
|
|
108
|
-
<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
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>
|
package/faq/FAQList.svelte
CHANGED
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
tabindex="0"
|
|
89
89
|
>
|
|
90
90
|
{#each visible as option, i (option.value)}
|
|
91
|
-
{
|
|
91
|
+
{const on = $derived(selected.includes(option.value))}
|
|
92
92
|
{#if option.group && option.group !== visible[i - 1]?.group}
|
|
93
93
|
<div class="group">{option.group}</div>
|
|
94
94
|
{/if}
|
|
@@ -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>
|
package/form/fields/index.ts
CHANGED
|
@@ -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/head/Head.svelte
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { page } from '$app/state';
|
|
3
|
+
|
|
4
|
+
import { headContext } from './context';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A page's `<head>` tags: title, description, canonical link and link-preview tags. The site's
|
|
8
|
+
* name, URL and share picture come from `setHeadContext` in the root layout. Renders nothing
|
|
9
|
+
* visible: the page's heading is its own `Title`.
|
|
10
|
+
*/
|
|
11
|
+
let {
|
|
12
|
+
canonical,
|
|
13
|
+
description,
|
|
14
|
+
image,
|
|
15
|
+
title,
|
|
16
|
+
}: {
|
|
17
|
+
/** Path (or absolute URL) search engines should treat as this page. Default: the path, no query. */
|
|
18
|
+
canonical?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
/** This page's link-preview picture, instead of the site's. */
|
|
21
|
+
image?: string;
|
|
22
|
+
/** The page's own title; omitted, the tab shows the site name alone. */
|
|
23
|
+
title?: string;
|
|
24
|
+
} = $props();
|
|
25
|
+
|
|
26
|
+
const site = headContext();
|
|
27
|
+
const fullTitle = $derived(
|
|
28
|
+
title ? `${title}${site.separator ?? ' · '}${site.siteName}` : site.siteName
|
|
29
|
+
);
|
|
30
|
+
const url = $derived.by(() => {
|
|
31
|
+
if (!site.siteUrl) return null;
|
|
32
|
+
const path = canonical ?? page.url.pathname;
|
|
33
|
+
return /^https?:\/\//.test(path) ? path : `${site.siteUrl}${path}`;
|
|
34
|
+
});
|
|
35
|
+
const picture = $derived(image ?? site.shareImage);
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<svelte:head>
|
|
39
|
+
<title>{fullTitle}</title>
|
|
40
|
+
{#if description}
|
|
41
|
+
<meta name="description" content={description} />
|
|
42
|
+
{/if}
|
|
43
|
+
{#if site.noindex}
|
|
44
|
+
<meta name="robots" content="noindex" />
|
|
45
|
+
{/if}
|
|
46
|
+
{#if url}
|
|
47
|
+
<link href={url} rel="canonical" />
|
|
48
|
+
<meta content={site.siteName} property="og:site_name" />
|
|
49
|
+
<meta content={title ?? site.siteName} property="og:title" />
|
|
50
|
+
{#if description}
|
|
51
|
+
<meta content={description} property="og:description" />
|
|
52
|
+
{/if}
|
|
53
|
+
<meta content={url} property="og:url" />
|
|
54
|
+
<meta content="website" property="og:type" />
|
|
55
|
+
{#if picture}
|
|
56
|
+
<meta content={picture} property="og:image" />
|
|
57
|
+
{/if}
|
|
58
|
+
{/if}
|
|
59
|
+
</svelte:head>
|
package/head/context.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
|
|
3
|
+
/** What every page's `<Head>` shares: set once in the app's root layout. */
|
|
4
|
+
export type HeadSite = {
|
|
5
|
+
/** True for apps that must stay out of search results (admins, private tools). */
|
|
6
|
+
noindex?: boolean;
|
|
7
|
+
/** Goes between the page title and the site name. Default `' · '`. */
|
|
8
|
+
separator?: string;
|
|
9
|
+
/** Absolute URL of the picture link previews show, unless a page passes its own. */
|
|
10
|
+
shareImage?: string;
|
|
11
|
+
siteName: string;
|
|
12
|
+
/** The public origin, e.g. `https://www.keycrox.co.uk`. Without it, no canonical or share tags. */
|
|
13
|
+
siteUrl?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const KEY = Symbol.for('@zeyolabs/ui/head');
|
|
17
|
+
|
|
18
|
+
/** The site's `<Head>` settings, for every page below this layout. */
|
|
19
|
+
export function setHeadContext(site: HeadSite): void {
|
|
20
|
+
setContext(KEY, site);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function headContext(): HeadSite {
|
|
24
|
+
const site = getContext<HeadSite | undefined>(KEY);
|
|
25
|
+
if (!site) throw new Error('@zeyolabs/ui/head: call setHeadContext() in the root layout');
|
|
26
|
+
return site;
|
|
27
|
+
}
|
package/menu/MenuButton.svelte
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeyolabs/ui",
|
|
3
|
-
"version": "2026.11.
|
|
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",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"form",
|
|
47
47
|
"gallery",
|
|
48
48
|
"grouped-grid",
|
|
49
|
+
"head",
|
|
49
50
|
"layout",
|
|
50
51
|
"list-row",
|
|
51
52
|
"menu",
|
|
@@ -129,10 +130,11 @@
|
|
|
129
130
|
"./gallery/*": "./gallery/*",
|
|
130
131
|
"./theme/theme.svelte": "./theme/theme.svelte.ts",
|
|
131
132
|
"./theme/*": "./theme/*",
|
|
132
|
-
"./turnstile/*": "./turnstile/*"
|
|
133
|
+
"./turnstile/*": "./turnstile/*",
|
|
134
|
+
"./head/*": "./head/*"
|
|
133
135
|
},
|
|
134
136
|
"peerDependencies": {
|
|
135
|
-
"@zeyolabs/kit": ">=2026.11.
|
|
137
|
+
"@zeyolabs/kit": ">=2026.11.44",
|
|
136
138
|
"@sveltejs/kit": "^3.1.1",
|
|
137
139
|
"svelte": "^5.57.3"
|
|
138
140
|
},
|
|
@@ -153,7 +155,7 @@
|
|
|
153
155
|
"devDependencies": {
|
|
154
156
|
"@eslint/compat": "2.1.1",
|
|
155
157
|
"@eslint/js": "10.0.1",
|
|
156
|
-
"@zeyolabs/kit": "2026.11.
|
|
158
|
+
"@zeyolabs/kit": "2026.11.44",
|
|
157
159
|
"@sveltejs/kit": "3.2.0",
|
|
158
160
|
"@types/flickity": "2.2.12",
|
|
159
161
|
"eslint": "10.15.0",
|
|
@@ -121,11 +121,11 @@
|
|
|
121
121
|
<div>
|
|
122
122
|
<div class="flex {heightClass[height]} items-stretch gap-px">
|
|
123
123
|
{#each range(maxSlots) as index (index)}
|
|
124
|
-
{
|
|
124
|
+
{const slot = $derived(paddedSlots[index])}
|
|
125
125
|
{#if slot}
|
|
126
|
-
{
|
|
127
|
-
{
|
|
128
|
-
{
|
|
126
|
+
{const [key, value] = $derived(slot)}
|
|
127
|
+
{const isDeselected = $derived(selected !== undefined && selected !== key)}
|
|
128
|
+
{const slotColor = $derived(backgroundClass[value.color])}
|
|
129
129
|
{#if onSelect}
|
|
130
130
|
<button
|
|
131
131
|
class="{baseSlotClass} cursor-pointer {slotColor} transition-opacity hover:opacity-80"
|