tera-system-ui 0.0.1 → 0.0.3
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/clickOutside.d.ts +6 -0
- package/dist/{components/side-navigation → actions}/clickOutside.js +3 -2
- package/dist/components/button/Button.d.ts +2 -2
- package/dist/components/button/Button.js +5 -5
- package/dist/components/button/Button.svelte +10 -8
- package/dist/components/button/Button.svelte.d.ts +3 -1
- package/dist/components/combobox/Combobox.d.ts +8 -0
- package/dist/components/combobox/Combobox.js +7 -0
- package/dist/components/combobox/Combobox.svelte +8 -0
- package/dist/components/combobox/Combobox.svelte.d.ts +3 -0
- package/dist/components/combobox/index.d.ts +1 -0
- package/dist/components/combobox/index.js +1 -0
- package/dist/components/command/command.d.ts +33 -0
- package/dist/components/command/command.js +512 -0
- package/dist/components/command/command.scss +73 -0
- package/dist/components/command/components/Command.svelte +120 -0
- package/dist/components/command/components/Command.svelte.d.ts +3 -0
- package/dist/components/command/components/CommandEmpty.svelte +30 -0
- package/dist/components/command/components/CommandEmpty.svelte.d.ts +3 -0
- package/dist/components/command/components/CommandGroup.svelte +110 -0
- package/dist/components/command/components/CommandGroup.svelte.d.ts +3 -0
- package/dist/components/command/components/CommandInput.svelte +90 -0
- package/dist/components/command/components/CommandInput.svelte.d.ts +7 -0
- package/dist/components/command/components/CommandItem.svelte +110 -0
- package/dist/components/command/components/CommandItem.svelte.d.ts +3 -0
- package/dist/components/command/components/CommandList.svelte +56 -0
- package/dist/components/command/components/CommandList.svelte.d.ts +5 -0
- package/dist/components/command/components/CommandLoading.svelte +29 -0
- package/dist/components/command/components/CommandLoading.svelte.d.ts +8 -0
- package/dist/components/command/components/CommandSeparator.svelte +21 -0
- package/dist/components/command/components/CommandSeparator.svelte.d.ts +3 -0
- package/dist/components/command/index.d.ts +12 -0
- package/dist/components/command/index.js +19 -0
- package/dist/components/command/types.d.ts +227 -0
- package/dist/components/command/types.js +1 -0
- package/dist/components/dialog/Dialog.svelte +1 -67
- package/dist/components/dialog/Dialog.svelte.d.ts +1 -0
- package/dist/components/dialog/dialog.scss +58 -0
- package/dist/components/icons/IconArrowBigRightFilled.svelte +10 -0
- package/dist/components/icons/IconArrowBigRightFilled.svelte.d.ts +4 -0
- package/dist/components/icons/IconBookmarkPlus.svelte +10 -0
- package/dist/components/icons/IconBookmarkPlus.svelte.d.ts +4 -0
- package/dist/components/icons/IconChevronDown.svelte +10 -0
- package/dist/components/icons/IconChevronDown.svelte.d.ts +4 -0
- package/dist/components/icons/IconCopy.svelte +10 -0
- package/dist/components/icons/IconCopy.svelte.d.ts +4 -0
- package/dist/components/icons/IconCopyCheckFilled.svelte +10 -0
- package/dist/components/icons/IconCopyCheckFilled.svelte.d.ts +4 -0
- package/dist/components/icons/IconLoader2.svelte +10 -0
- package/dist/components/icons/IconLoader2.svelte.d.ts +4 -0
- package/dist/components/icons/IconPointFilled.svelte +10 -0
- package/dist/components/icons/IconPointFilled.svelte.d.ts +4 -0
- package/dist/components/icons/IconSearch.svelte +10 -0
- package/dist/components/icons/IconSearch.svelte.d.ts +4 -0
- package/dist/components/icons/IconSwitchHorizontal.svelte +10 -0
- package/dist/components/icons/IconSwitchHorizontal.svelte.d.ts +4 -0
- package/dist/components/icons/IconSwitchVertical.svelte +10 -0
- package/dist/components/icons/IconSwitchVertical.svelte.d.ts +4 -0
- package/dist/components/icons/index.d.ts +17 -0
- package/dist/components/icons/index.js +17 -0
- package/dist/components/input/Input.d.ts +116 -0
- package/dist/components/input/Input.js +36 -0
- package/dist/components/input/Input.svelte +19 -8
- package/dist/components/input/Input.svelte.d.ts +2 -22
- package/dist/components/language-picker-button/LanguagePickerButton.svelte +13 -10
- package/dist/components/language-picker-button/LanguagePickerButton.svelte.d.ts +0 -2
- package/dist/components/popover/Popover.d.ts +14 -0
- package/dist/components/popover/Popover.js +8 -0
- package/dist/components/popover/Popover.svelte +129 -0
- package/dist/components/popover/Popover.svelte.d.ts +3 -0
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/side-navigation/SideNavigation.js +0 -1
- package/dist/components/side-navigation/SideNavigation.svelte +40 -20
- package/dist/components/tera-ui-context/TeraUiContext.d.ts +11 -0
- package/dist/components/tera-ui-context/TeraUiContext.js +1 -0
- package/dist/components/tera-ui-context/TeraUiContext.svelte +21 -0
- package/dist/components/tera-ui-context/TeraUiContext.svelte.d.ts +3 -0
- package/dist/components/tera-ui-context/global-context.d.ts +3 -0
- package/dist/components/tera-ui-context/global-context.js +15 -0
- package/dist/components/tera-ui-context/index.d.ts +1 -0
- package/dist/components/tera-ui-context/index.js +1 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/language.d.ts +2 -0
- package/dist/i18n/language.js +10 -0
- package/dist/i18n.d.ts +1 -0
- package/dist/i18n.js +4 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +13 -2
- package/dist/internal/command-score.d.ts +1 -0
- package/dist/internal/command-score.js +119 -0
- package/dist/internal/helpers/callbacks.d.ts +12 -0
- package/dist/internal/helpers/callbacks.js +15 -0
- package/dist/internal/helpers/event.d.ts +14 -0
- package/dist/internal/helpers/event.js +17 -0
- package/dist/internal/helpers/id.d.ts +1 -0
- package/dist/internal/helpers/id.js +4 -0
- package/dist/internal/helpers/index.d.ts +8 -0
- package/dist/internal/helpers/index.js +8 -0
- package/dist/internal/helpers/is.d.ts +4 -0
- package/dist/internal/helpers/is.js +10 -0
- package/dist/internal/helpers/kbd.d.ts +35 -0
- package/dist/internal/helpers/kbd.js +35 -0
- package/dist/internal/helpers/object.d.ts +2 -0
- package/dist/internal/helpers/object.js +19 -0
- package/dist/internal/helpers/sleep.d.ts +1 -0
- package/dist/internal/helpers/sleep.js +3 -0
- package/dist/internal/helpers/store.d.ts +29 -0
- package/dist/internal/helpers/store.js +80 -0
- package/dist/internal/helpers/style.d.ts +12 -0
- package/dist/internal/helpers/style.js +18 -0
- package/dist/internal/index.d.ts +3 -0
- package/dist/internal/index.js +3 -0
- package/dist/internal/types.d.ts +18 -0
- package/dist/internal/types.js +1 -0
- package/dist/themes/index.d.ts +1 -0
- package/dist/themes/index.js +1 -0
- package/dist/themes/scrollbar.scss +37 -0
- package/dist/themes/tera-ui-base.css +174 -0
- package/dist/themes/tw-preset.cjs +151 -0
- package/dist/themes/tw-preset.d.cts +149 -0
- package/package.json +41 -19
- package/scripts/generate-ts-index.js +137 -0
- package/dist/components/input/input.d.ts +0 -49
- package/dist/components/input/input.js +0 -14
- package/dist/components/side-navigation/clickOutside.d.ts +0 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {getState} from '../command.js';
|
|
3
|
+
import type {EmptyProps} from '../types.js';
|
|
4
|
+
import {derived} from "svelte/store";
|
|
5
|
+
import {onMount} from "svelte";
|
|
6
|
+
|
|
7
|
+
type $$Props = EmptyProps;
|
|
8
|
+
|
|
9
|
+
let {children, ...restProps}: $$Props = $props()
|
|
10
|
+
|
|
11
|
+
let isFirstRender = $state(true);
|
|
12
|
+
const commandState = getState();
|
|
13
|
+
|
|
14
|
+
let render = derived(commandState, ($commandState) => ($commandState.filtered.count === 0))
|
|
15
|
+
|
|
16
|
+
onMount(() => {
|
|
17
|
+
isFirstRender = false;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const attrs = {
|
|
21
|
+
'data-cmdk-empty': '',
|
|
22
|
+
role: 'presentation'
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
{#if !isFirstRender && $render}
|
|
27
|
+
<div {...attrs} {...restProps}>
|
|
28
|
+
{@render children?.()}
|
|
29
|
+
</div>
|
|
30
|
+
{/if}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {generateId} from '../../../internal/index.js';
|
|
3
|
+
import {derived} from 'svelte/store';
|
|
4
|
+
import {createGroup, getCtx, getState, VALUE_ATTR} from '../command.js';
|
|
5
|
+
import type {GroupProps} from '../types.js';
|
|
6
|
+
import {onMount} from 'svelte';
|
|
7
|
+
|
|
8
|
+
type $$Props = GroupProps;
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
children,
|
|
12
|
+
heading,
|
|
13
|
+
value = '',
|
|
14
|
+
alwaysRender = false,
|
|
15
|
+
...restProps
|
|
16
|
+
}: $$Props = $props()
|
|
17
|
+
|
|
18
|
+
const {id} = createGroup(alwaysRender);
|
|
19
|
+
|
|
20
|
+
const context = getCtx();
|
|
21
|
+
const commandState = getState();
|
|
22
|
+
const headingId = generateId();
|
|
23
|
+
|
|
24
|
+
const render = derived(commandState, ($state) => {
|
|
25
|
+
if (alwaysRender) return true;
|
|
26
|
+
if (context.filter() === false) return true;
|
|
27
|
+
if (!$commandState.search) return true;
|
|
28
|
+
return $commandState.filtered.groups.has(id);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
onMount(() => {
|
|
33
|
+
const unsubGroup = context.group(id);
|
|
34
|
+
return unsubGroup;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function containerAction(node: HTMLElement) {
|
|
39
|
+
|
|
40
|
+
if (value) {
|
|
41
|
+
context.value(id, value);
|
|
42
|
+
node.setAttribute(VALUE_ATTR, value);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (heading) {
|
|
47
|
+
value = heading.trim().toLowerCase();
|
|
48
|
+
} else if (node.textContent) {
|
|
49
|
+
value = node.textContent.trim().toLowerCase();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
context.value(id, value);
|
|
53
|
+
node.setAttribute(VALUE_ATTR, value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let containerAttrs = $state()
|
|
57
|
+
|
|
58
|
+
$effect(() => {
|
|
59
|
+
containerAttrs = {
|
|
60
|
+
'data-cmdk-group': '',
|
|
61
|
+
role: 'presentation',
|
|
62
|
+
hidden: $render ? undefined : true,
|
|
63
|
+
'data-value': value
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
const headingAttrs = {
|
|
69
|
+
'data-cmdk-group-heading': '',
|
|
70
|
+
'aria-hidden': true,
|
|
71
|
+
id: headingId
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
let groupAttrs = $state()
|
|
75
|
+
$effect(() => {
|
|
76
|
+
groupAttrs = {
|
|
77
|
+
'data-cmdk-group-items': '',
|
|
78
|
+
role: 'group',
|
|
79
|
+
'aria-labelledby': heading ? headingId : undefined
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
let container = $state()
|
|
84
|
+
$effect(() => {
|
|
85
|
+
container = {
|
|
86
|
+
action: containerAction,
|
|
87
|
+
attrs: containerAttrs
|
|
88
|
+
};
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
let group = $state()
|
|
93
|
+
$effect(() => {
|
|
94
|
+
group = {
|
|
95
|
+
attrs: groupAttrs
|
|
96
|
+
};
|
|
97
|
+
})
|
|
98
|
+
</script>
|
|
99
|
+
|
|
100
|
+
<div use:containerAction {...containerAttrs} {...restProps}>
|
|
101
|
+
{#if heading}
|
|
102
|
+
<div {...headingAttrs}>
|
|
103
|
+
{heading}
|
|
104
|
+
</div>
|
|
105
|
+
{/if}
|
|
106
|
+
<div {...groupAttrs}>
|
|
107
|
+
<!-- <slot {container} {group} heading={{ attrs: headingAttrs }}/>-->
|
|
108
|
+
{@render children?.()}
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {derived, get} from 'svelte/store';
|
|
3
|
+
import {getCtx, getState, ITEM_SELECTOR, VALUE_ATTR} from '../command.js';
|
|
4
|
+
import {isBrowser} from '../../../internal/index.js';
|
|
5
|
+
import type {InputEvents, InputProps} from '../types.js';
|
|
6
|
+
import {sleep} from '../../../internal/helpers/sleep.js';
|
|
7
|
+
import {styles} from "../../input/Input";
|
|
8
|
+
import {IconSearch} from "../../..";
|
|
9
|
+
|
|
10
|
+
type $$Props = InputProps;
|
|
11
|
+
type $$Events = InputEvents;
|
|
12
|
+
|
|
13
|
+
const {ids, commandEl} = getCtx();
|
|
14
|
+
const commandState = getState();
|
|
15
|
+
|
|
16
|
+
const valueStore = derived(commandState, ($commandState) => $commandState.value);
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
autofocus = undefined,
|
|
20
|
+
value = $bindable(),
|
|
21
|
+
el,
|
|
22
|
+
class: className,
|
|
23
|
+
...restProps
|
|
24
|
+
}: $$Props & {
|
|
25
|
+
el?: HTMLElement
|
|
26
|
+
} = $props()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const selectedItemId = derived([valueStore, commandEl], ([$value, $commandEl]) => {
|
|
30
|
+
if (!isBrowser) return undefined;
|
|
31
|
+
const item = $commandEl?.querySelector(`${ITEM_SELECTOR}[${VALUE_ATTR}="${$value}"]`);
|
|
32
|
+
return item?.getAttribute('id');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function handleValueUpdate(v: string) {
|
|
36
|
+
commandState.updateState('search', v);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function action(node: HTMLInputElement) {
|
|
40
|
+
if (autofocus) {
|
|
41
|
+
sleep(10).then(() => node.focus());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let attrs = $state<Record<string, unknown>>()
|
|
46
|
+
|
|
47
|
+
$effect(() => {
|
|
48
|
+
attrs = {
|
|
49
|
+
type: 'text',
|
|
50
|
+
'data-cmdk-input': '',
|
|
51
|
+
autocomplete: 'off',
|
|
52
|
+
autocorrect: 'off',
|
|
53
|
+
spellcheck: false,
|
|
54
|
+
'aria-autocomplete': 'list',
|
|
55
|
+
role: 'combobox',
|
|
56
|
+
'aria-expanded': true,
|
|
57
|
+
'aria-controls': ids.list,
|
|
58
|
+
'aria-labelledby': ids.label,
|
|
59
|
+
'aria-activedescendant': $selectedItemId ?? undefined,
|
|
60
|
+
id: ids.input
|
|
61
|
+
};
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
$effect(() => {
|
|
65
|
+
return () => {
|
|
66
|
+
value = ''
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<div class="relative">
|
|
72
|
+
<input
|
|
73
|
+
class={styles({
|
|
74
|
+
variant: 'borderless',
|
|
75
|
+
size: 'lg',
|
|
76
|
+
class: className + ' pl-9 border-b border-b-neutral-token-5 rounded-none text-sm',
|
|
77
|
+
})}
|
|
78
|
+
bind:this={el}
|
|
79
|
+
{...attrs}
|
|
80
|
+
bind:value={value}
|
|
81
|
+
use:action
|
|
82
|
+
{...restProps}
|
|
83
|
+
onkeydown={() => {}}
|
|
84
|
+
oninput={() => {handleValueUpdate(value)}}
|
|
85
|
+
onfocus={() => {}}
|
|
86
|
+
onblur={() => {}}
|
|
87
|
+
onchange={() => {}}
|
|
88
|
+
/>
|
|
89
|
+
<IconSearch class="absolute top-1/2 left-2 -translate-y-1/2 size-icon-xs opacity-60"/>
|
|
90
|
+
</div>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {addEventListener, executeCallbacks, generateId, isUndefined} from '../../../internal/index.js';
|
|
3
|
+
import {getCtx, getGroup, getState, VALUE_ATTR} from '../command.js';
|
|
4
|
+
import type {ItemProps} from '../types.js';
|
|
5
|
+
import {derived} from 'svelte/store';
|
|
6
|
+
import {onMount} from "svelte";
|
|
7
|
+
|
|
8
|
+
type $$Props = ItemProps
|
|
9
|
+
let {
|
|
10
|
+
children,
|
|
11
|
+
childrenWithProps,
|
|
12
|
+
id = generateId(),
|
|
13
|
+
alwaysRender = false,
|
|
14
|
+
onSelect,
|
|
15
|
+
value = '',
|
|
16
|
+
disabled = false,
|
|
17
|
+
...restProps
|
|
18
|
+
}: $$Props = $props()
|
|
19
|
+
|
|
20
|
+
const groupContext = getGroup();
|
|
21
|
+
const context = getCtx();
|
|
22
|
+
const commandState = getState();
|
|
23
|
+
|
|
24
|
+
const trueAlwaysRender = alwaysRender ?? groupContext?.alwaysRender;
|
|
25
|
+
|
|
26
|
+
const render = derived(commandState, ($state) => {
|
|
27
|
+
if (trueAlwaysRender || context.filter() === false || !$commandState.search) return true;
|
|
28
|
+
const currentScore = $commandState.filtered.items.get(id);
|
|
29
|
+
if (isUndefined(currentScore)) return false;
|
|
30
|
+
return currentScore > 0;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const selected = derived(commandState, ($state) => $commandState.value === value);
|
|
34
|
+
|
|
35
|
+
let isFirstRender = $state(true);
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
let attrs = derived(selected, ($selected) => (
|
|
39
|
+
{
|
|
40
|
+
'aria-disabled': disabled ? true : undefined,
|
|
41
|
+
'data-disabled': disabled ? true : undefined,
|
|
42
|
+
'aria-selected': $selected ? true : undefined,
|
|
43
|
+
'data-selected': $selected ? true : undefined,
|
|
44
|
+
'data-cmdk-item': '',
|
|
45
|
+
'data-value': value,
|
|
46
|
+
role: 'option',
|
|
47
|
+
id
|
|
48
|
+
}
|
|
49
|
+
));
|
|
50
|
+
|
|
51
|
+
onMount(() => {
|
|
52
|
+
isFirstRender = false;
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
onMount(() => {
|
|
57
|
+
let unsub
|
|
58
|
+
unsub = context.item(id, groupContext?.id);
|
|
59
|
+
return unsub;
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
function action(node: HTMLElement) {
|
|
64
|
+
if (!value && node.textContent) {
|
|
65
|
+
value = node.textContent.trim().toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
context.value(id, value);
|
|
68
|
+
node.setAttribute(VALUE_ATTR, value);
|
|
69
|
+
|
|
70
|
+
const unsubEvents = executeCallbacks(
|
|
71
|
+
addEventListener(node, 'pointerenter', () => {
|
|
72
|
+
if (disabled) return;
|
|
73
|
+
select();
|
|
74
|
+
}),
|
|
75
|
+
addEventListener(node, 'click', () => {
|
|
76
|
+
if (disabled) return;
|
|
77
|
+
handleItemClick();
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
destroy() {
|
|
83
|
+
unsubEvents();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function handleItemClick() {
|
|
89
|
+
select();
|
|
90
|
+
onSelect?.(value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function select() {
|
|
94
|
+
commandState.updateState('value', value, true);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
{#if $render || isFirstRender}
|
|
100
|
+
<div {...$attrs} use:action {...restProps}>
|
|
101
|
+
<!--{@render childrenWithProps?.(-->
|
|
102
|
+
<!-- {-->
|
|
103
|
+
<!-- attrs: attrs,-->
|
|
104
|
+
<!-- action: action-->
|
|
105
|
+
<!-- }-->
|
|
106
|
+
<!--)-->
|
|
107
|
+
<!--}-->
|
|
108
|
+
{@render children?.()}
|
|
109
|
+
</div>
|
|
110
|
+
{/if}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {isHTMLElement} from '../../../internal/index.js';
|
|
3
|
+
import {getCtx, getState} from '../command.js';
|
|
4
|
+
import type {ListProps} from '../types.js';
|
|
5
|
+
|
|
6
|
+
const {ids} = getCtx();
|
|
7
|
+
const commandState = getState();
|
|
8
|
+
|
|
9
|
+
type $$Props = ListProps;
|
|
10
|
+
|
|
11
|
+
let {children, el, ...restProps} = $props()
|
|
12
|
+
|
|
13
|
+
function sizerAction(node: HTMLElement) {
|
|
14
|
+
let animationFrame: number;
|
|
15
|
+
const listEl = node.closest('[data-cmdk-list]');
|
|
16
|
+
if (!isHTMLElement(listEl)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const observer = new ResizeObserver(() => {
|
|
21
|
+
animationFrame = requestAnimationFrame(() => {
|
|
22
|
+
const height = node.offsetHeight;
|
|
23
|
+
listEl.style.setProperty('--cmdk-list-height', height.toFixed(1) + 'px');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
observer.observe(node);
|
|
28
|
+
return {
|
|
29
|
+
destroy() {
|
|
30
|
+
cancelAnimationFrame(animationFrame);
|
|
31
|
+
observer.unobserve(node);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const listAttrs = {
|
|
37
|
+
'data-cmdk-list': '',
|
|
38
|
+
role: 'listbox',
|
|
39
|
+
'aria-label': 'Suggestions',
|
|
40
|
+
id: ids.list,
|
|
41
|
+
'aria-labelledby': ids.input
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const sizerAttrs = {
|
|
45
|
+
'data-cmdk-list-sizer': ''
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<div {...listAttrs} bind:this={el} {...restProps}>
|
|
51
|
+
<div {...sizerAttrs} use:sizerAction>
|
|
52
|
+
{#key $commandState.search === ''}
|
|
53
|
+
{@render children()}
|
|
54
|
+
{/key}
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { LoadingProps } from '../types.js';
|
|
3
|
+
import type {Snippet} from "svelte";
|
|
4
|
+
|
|
5
|
+
type $$Props = LoadingProps;
|
|
6
|
+
|
|
7
|
+
let {childrenWithProps, progress, ...restProps} : $$Props & {
|
|
8
|
+
childrenWithProps: Snippet<[any]>
|
|
9
|
+
} = $props()
|
|
10
|
+
|
|
11
|
+
let attrs = $state<any>()
|
|
12
|
+
|
|
13
|
+
$effect(() => {
|
|
14
|
+
attrs = {
|
|
15
|
+
'data-cmdk-loading': '',
|
|
16
|
+
role: 'progressbar',
|
|
17
|
+
'aria-valuenow': progress,
|
|
18
|
+
'aria-valuemin': 0,
|
|
19
|
+
'aria-valuemax': 100,
|
|
20
|
+
'aria-label': 'Loading...'
|
|
21
|
+
};
|
|
22
|
+
})
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div {...attrs} {...restProps}>
|
|
26
|
+
<div aria-hidden>
|
|
27
|
+
{@render childrenWithProps(attrs)}
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
declare const CommandLoading: import("svelte").Component<{
|
|
3
|
+
progress?: number;
|
|
4
|
+
asChild?: boolean;
|
|
5
|
+
} & import("../../../internal/types.js").HTMLDivAttributes & {
|
|
6
|
+
childrenWithProps: Snippet<[any]>;
|
|
7
|
+
}, {}, "">;
|
|
8
|
+
export default CommandLoading;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { derived } from 'svelte/store';
|
|
3
|
+
import { getState } from '../command.js';
|
|
4
|
+
import type { SeparatorProps } from '../types.js';
|
|
5
|
+
|
|
6
|
+
type $$Props = SeparatorProps;
|
|
7
|
+
|
|
8
|
+
let {alwaysRender,...restProps} :$$Props= $props()
|
|
9
|
+
|
|
10
|
+
const commandState = getState();
|
|
11
|
+
const render = derived(commandState, ($state) => !$commandState.search);
|
|
12
|
+
|
|
13
|
+
const attrs = {
|
|
14
|
+
'data-cmdk-separator': '',
|
|
15
|
+
role: 'separator'
|
|
16
|
+
};
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
{#if $render || alwaysRender}
|
|
20
|
+
<div {...attrs} {...restProps}></div>
|
|
21
|
+
{/if}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { default as Command } from './components/Command.svelte';
|
|
2
|
+
import type { LoadingProps, CommandProps, EmptyProps, ItemProps, GroupProps, ListProps, InputProps, SeparatorProps } from './types.js';
|
|
3
|
+
import Root from './components/Command.svelte';
|
|
4
|
+
import Empty from './components/CommandEmpty.svelte';
|
|
5
|
+
import Group from './components/CommandGroup.svelte';
|
|
6
|
+
import Input from './components/CommandInput.svelte';
|
|
7
|
+
import Item from './components/CommandItem.svelte';
|
|
8
|
+
import List from './components/CommandList.svelte';
|
|
9
|
+
import Loading from './components/CommandLoading.svelte';
|
|
10
|
+
import Separator from './components/CommandSeparator.svelte';
|
|
11
|
+
export { Root, Empty, Group, Input, Item, List, Loading, Separator, Root as CommandRoot, Empty as CommandEmpty, Group as CommandGroup, Input as CommandInput, Item as CommandItem, List as CommandList, Loading as CommandLoading, Separator as CommandSeparator };
|
|
12
|
+
export type { LoadingProps, CommandProps, EmptyProps, ItemProps, GroupProps, ListProps, InputProps, SeparatorProps };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { default as Command } from './components/Command.svelte';
|
|
2
|
+
import Root from './components/Command.svelte';
|
|
3
|
+
// import Dialog from './components/CommandDialog.svelte';
|
|
4
|
+
import Empty from './components/CommandEmpty.svelte';
|
|
5
|
+
import Group from './components/CommandGroup.svelte';
|
|
6
|
+
import Input from './components/CommandInput.svelte';
|
|
7
|
+
import Item from './components/CommandItem.svelte';
|
|
8
|
+
import List from './components/CommandList.svelte';
|
|
9
|
+
import Loading from './components/CommandLoading.svelte';
|
|
10
|
+
import Separator from './components/CommandSeparator.svelte';
|
|
11
|
+
export {
|
|
12
|
+
// Components
|
|
13
|
+
Root,
|
|
14
|
+
// Dialog,
|
|
15
|
+
Empty, Group, Input, Item, List, Loading, Separator,
|
|
16
|
+
//
|
|
17
|
+
Root as CommandRoot,
|
|
18
|
+
// Dialog as CommandDialog,
|
|
19
|
+
Empty as CommandEmpty, Group as CommandGroup, Input as CommandInput, Item as CommandItem, List as CommandList, Loading as CommandLoading, Separator as CommandSeparator };
|