@fibrae/semi-ui-svelte 0.1.1 → 0.2.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 (57) hide show
  1. package/dist/feedback/feedback-content.svelte +4 -4
  2. package/dist/feedback/interface.d.ts +4 -4
  3. package/dist/form/field-inner.svelte +9 -3
  4. package/dist/form/field-inner.svelte.d.ts +3 -1
  5. package/dist/form/field.svelte +10 -2
  6. package/dist/form/field.svelte.d.ts +6 -2
  7. package/dist/form/form-auto-complete.svelte +7 -1
  8. package/dist/form/form-auto-complete.svelte.d.ts +3 -1
  9. package/dist/form/form-cascader.svelte +7 -1
  10. package/dist/form/form-cascader.svelte.d.ts +3 -1
  11. package/dist/form/form-checkbox-group.svelte +7 -1
  12. package/dist/form/form-checkbox-group.svelte.d.ts +3 -1
  13. package/dist/form/form-checkbox.svelte +7 -1
  14. package/dist/form/form-checkbox.svelte.d.ts +3 -1
  15. package/dist/form/form-date-picker.svelte +7 -1
  16. package/dist/form/form-date-picker.svelte.d.ts +3 -1
  17. package/dist/form/form-input-number.svelte +7 -1
  18. package/dist/form/form-input-number.svelte.d.ts +3 -1
  19. package/dist/form/form-input.svelte +7 -1
  20. package/dist/form/form-input.svelte.d.ts +3 -1
  21. package/dist/form/form-pin-code.svelte +7 -1
  22. package/dist/form/form-pin-code.svelte.d.ts +3 -1
  23. package/dist/form/form-radio-group.svelte +7 -1
  24. package/dist/form/form-radio-group.svelte.d.ts +3 -1
  25. package/dist/form/form-radio.svelte +7 -1
  26. package/dist/form/form-radio.svelte.d.ts +3 -1
  27. package/dist/form/form-rating.svelte +7 -1
  28. package/dist/form/form-rating.svelte.d.ts +3 -1
  29. package/dist/form/form-select.svelte +7 -1
  30. package/dist/form/form-select.svelte.d.ts +3 -1
  31. package/dist/form/form-slider.svelte +7 -1
  32. package/dist/form/form-slider.svelte.d.ts +3 -1
  33. package/dist/form/form-switch.svelte +7 -1
  34. package/dist/form/form-switch.svelte.d.ts +3 -1
  35. package/dist/form/form-tag-input.svelte +7 -1
  36. package/dist/form/form-tag-input.svelte.d.ts +3 -1
  37. package/dist/form/form-text-area.svelte +7 -1
  38. package/dist/form/form-text-area.svelte.d.ts +3 -1
  39. package/dist/form/form-time-picker.svelte +7 -1
  40. package/dist/form/form-time-picker.svelte.d.ts +3 -1
  41. package/dist/form/form-transfer.svelte +7 -1
  42. package/dist/form/form-transfer.svelte.d.ts +3 -1
  43. package/dist/form/form-tree-select.svelte +7 -1
  44. package/dist/form/form-tree-select.svelte.d.ts +3 -1
  45. package/dist/form/form-upload.svelte +7 -1
  46. package/dist/form/form-upload.svelte.d.ts +3 -1
  47. package/dist/icon-button/icon-button.svelte +6 -2
  48. package/dist/input/input-group.svelte +8 -2
  49. package/dist/navigation/nav.svelte +2 -1
  50. package/dist/pincode/pincode.svelte +4 -2
  51. package/dist/radio/radio-group.svelte +2 -1
  52. package/dist/resizable/resize-group.svelte +30 -13
  53. package/dist/slider/slider.svelte +14 -4
  54. package/dist/tag-input/tag-input.svelte +2 -0
  55. package/dist/transfer/transfer.svelte +3 -2
  56. package/dist/tree/tree.svelte +5 -0
  57. package/package.json +3 -3
@@ -25,8 +25,8 @@
25
25
  </script>
26
26
 
27
27
  {#if type === 'text'}
28
- <!-- the handler comes last: the foundation calls the caller's own onChange -->
29
- <TextArea placeholder={locale().locale.placeholder} value={typeof value === 'string' ? value : ''} {...textAreaProps} onChange={onTextChange} />
28
+ <!-- the value and handler come last: the foundation calls the caller's own onChange -->
29
+ <TextArea placeholder={locale().locale.placeholder} {...textAreaProps} onChange={onTextChange} value={typeof value === 'string' ? value : ''} />
30
30
  {:else if type === 'emoji'}
31
31
  <!-- APG radio group: native radios provide the arrow keys, single Tab stop and checked state -->
32
32
  <div aria-label={locale().locale.rating} class={`${prefix}-emoji-container`} role="radiogroup">
@@ -42,11 +42,11 @@
42
42
  {/if}
43
43
  {:else if type === 'radio'}
44
44
  <div class={`${prefix}-radio-container`}>
45
- <RadioGroup direction="vertical" extra={radioExtra} label={radioLabel} value={radioValue} {...radioGroupProps} onChange={onRadioChange} />
45
+ <RadioGroup direction="vertical" extra={radioExtra} label={radioLabel} {...radioGroupProps} onChange={onRadioChange} value={radioValue} />
46
46
  </div>
47
47
  {:else if type === 'checkbox'}
48
48
  <div class={`${prefix}-checkbox-container`}>
49
- <CheckboxGroup direction="vertical" extra={checkboxExtra} label={checkboxLabel} value={Array.isArray(value) ? value : []} {...checkboxGroupProps} onChange={onCheckboxChange} />
49
+ <CheckboxGroup direction="vertical" extra={checkboxExtra} label={checkboxLabel} {...checkboxGroupProps} onChange={onCheckboxChange} value={Array.isArray(value) ? value : []} />
50
50
  </div>
51
51
  {:else}
52
52
  {@render children?.()}
@@ -11,10 +11,10 @@ export type FeedbackMode = 'modal' | 'popup';
11
11
  export type FeedbackType = 'text' | 'emoji' | 'radio' | 'checkbox' | 'custom';
12
12
  /** Same shape as the Modal footer buttons; `onclick` runs before the built-in ok or cancel handling. */
13
13
  export type FeedbackButtonProps = ModalButtonProps;
14
- /** `onChange` is called by Feedback itself, so it does not replace the built-in handling. */
15
- export type FeedbackTextAreaProps = TextAreaProps;
16
- export type FeedbackRadioGroupProps = RadioGroupProps;
17
- export type FeedbackCheckboxGroupProps = CheckboxGroupProps;
14
+ /** `value` is Feedback's own; `onChange` is called after Feedback has handled the change. */
15
+ export type FeedbackTextAreaProps = Omit<TextAreaProps, 'value'>;
16
+ export type FeedbackRadioGroupProps = Omit<RadioGroupProps, 'value'>;
17
+ export type FeedbackCheckboxGroupProps = Omit<CheckboxGroupProps, 'value'>;
18
18
  export type FeedbackRadioSnippetProps = RadioGroupOptionSnippetParams;
19
19
  export type FeedbackCheckboxSnippetProps = CheckboxGroupOptionSnippetProps;
20
20
  export interface FeedbackContentSnippetProps {
@@ -69,6 +69,7 @@
69
69
  const uid = $props.id();
70
70
  let extraKind = $state<SlotKind>();
71
71
  let registered: { field: string; registration: FieldRegistration; leaveGroup?: () => void } | undefined;
72
+ let controlInstance = $state.raw<Record<string, any>>();
72
73
 
73
74
  const Control = $derived(component as Component<Record<string, any>, object, string>);
74
75
  const valueKey = $derived(fieldOptions.valueKey ?? 'value');
@@ -250,6 +251,11 @@
250
251
  }
251
252
  return unregister;
252
253
  });
254
+
255
+ // Svelte exports are static, so the wrapped control's own methods (focus, open ...) cannot be re-exported by name
256
+ export function getControl() {
257
+ return controlInstance;
258
+ }
253
259
  </script>
254
260
 
255
261
  {#snippet insetText()}
@@ -271,11 +277,11 @@
271
277
  ...(blurKey && { [blurKey]: handleBlur }),
272
278
  }}
273
279
  {#if valueKey === 'checked'}
274
- <Control {...injected} bind:checked={() => snapshot().value, () => {}} />
280
+ <Control {...injected} bind:checked={() => snapshot().value, () => {}} bind:this={controlInstance} />
275
281
  {:else if valueKey === 'fileList'}
276
- <Control {...injected} bind:fileList={() => snapshot().value, () => {}} />
282
+ <Control {...injected} bind:fileList={() => snapshot().value, () => {}} bind:this={controlInstance} />
277
283
  {:else}
278
- <Control {...injected} bind:value={() => snapshot().value, () => {}} />
284
+ <Control {...injected} bind:this={controlInstance} bind:value={() => snapshot().value, () => {}} />
279
285
  {/if}
280
286
  {/snippet}
281
287
 
@@ -7,6 +7,8 @@ type InnerProps = Omit<CommonFieldProps, 'field'> & {
7
7
  triggerContent?: Snippet<any[]>;
8
8
  [key: string]: unknown;
9
9
  };
10
- declare const FieldInner: Component<InnerProps, {}, "">;
10
+ declare const FieldInner: Component<InnerProps, {
11
+ getControl: () => Record<string, any> | undefined;
12
+ }, "">;
11
13
  type FieldInner = ReturnType<typeof FieldInner>;
12
14
  export default FieldInner;
@@ -8,6 +8,9 @@
8
8
 
9
9
  let props: FormFieldProps<C> = $props();
10
10
 
11
+ let bareControl = $state.raw<Record<string, any>>();
12
+ let inner = $state.raw<{ getControl: () => Record<string, any> | undefined }>();
13
+
11
14
  const inForm = Boolean(getFormContext());
12
15
  const shouldInject = $derived(props.fieldOptions?.shouldInject ?? true);
13
16
 
@@ -24,10 +27,15 @@
24
27
  warning(props.field === undefined && shouldInject, "[Semi Form]: 'field' is required, please check your props of Field Component");
25
28
  warning(!bare && !inForm, '[Semi Form]: Field Component must be use inside the Form, please check your dom declaration');
26
29
  });
30
+
31
+ // The wrapped control's instance, for calling its own methods (focus, open ...)
32
+ export function getControl() {
33
+ return bareControl ?? inner?.getControl();
34
+ }
27
35
  </script>
28
36
 
29
37
  {#if bare}
30
- <Control {...bareProps} />
38
+ <Control {...bareProps} bind:this={bareControl} />
31
39
  {:else if inForm}
32
- <FieldInner {...props} />
40
+ <FieldInner {...props} bind:this={inner} />
33
41
  {/if}
@@ -2,7 +2,9 @@ import { type Component } from 'svelte';
2
2
  import type { FormFieldProps } from './interface.js';
3
3
  declare function $$render<C extends Component<any, any, any>>(): {
4
4
  props: FormFieldProps<C>;
5
- exports: {};
5
+ exports: {
6
+ getControl: () => Record<string, any> | undefined;
7
+ };
6
8
  bindings: "";
7
9
  slots: {};
8
10
  events: {};
@@ -12,7 +14,9 @@ declare class __sveltets_Render<C extends Component<any, any, any>> {
12
14
  events(): ReturnType<typeof $$render<C>>['events'];
13
15
  slots(): ReturnType<typeof $$render<C>>['slots'];
14
16
  bindings(): "";
15
- exports(): {};
17
+ exports(): {
18
+ getControl: () => Record<string, any> | undefined;
19
+ };
16
20
  }
17
21
  interface $$IsomorphicComponent {
18
22
  new <C extends Component<any, any, any>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<C>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<C>['props']>, ReturnType<__sveltets_Render<C>['events']>, ReturnType<__sveltets_Render<C>['slots']>> & {
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<AutoCompleteProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={AutoComplete} />
16
+ <Field bind:this={field} {...props} component={AutoComplete} />
@@ -1,5 +1,7 @@
1
1
  import type { AutoCompleteProps } from '../auto-complete/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormAutoComplete: import("svelte").Component<FieldProps<AutoCompleteProps<import("..").AutoCompleteItems>>, {}, "">;
3
+ declare const FormAutoComplete: import("svelte").Component<FieldProps<AutoCompleteProps<import("..").AutoCompleteItems>>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormAutoComplete = ReturnType<typeof FormAutoComplete>;
5
7
  export default FormAutoComplete;
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<CascaderProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={Cascader} />
16
+ <Field bind:this={field} {...props} component={Cascader} />
@@ -1,5 +1,7 @@
1
1
  import type { CascaderProps } from '../cascader/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormCascader: import("svelte").Component<FieldProps<CascaderProps>, {}, "">;
3
+ declare const FormCascader: import("svelte").Component<FieldProps<CascaderProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormCascader = ReturnType<typeof FormCascader>;
5
7
  export default FormCascader;
@@ -6,7 +6,13 @@
6
6
 
7
7
  let props: FieldProps<CheckboxGroupProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  const fieldOptions: WithFieldOption = { insetLabel: false, validateStatus: false };
12
+
13
+ export function getControl() {
14
+ return field?.getControl();
15
+ }
10
16
  </script>
11
17
 
12
- <Field {...props} component={CheckboxGroup} {fieldOptions} />
18
+ <Field bind:this={field} {...props} component={CheckboxGroup} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { CheckboxGroupProps } from '../checkbox/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormCheckboxGroup: import("svelte").Component<FieldProps<CheckboxGroupProps>, {}, "">;
3
+ declare const FormCheckboxGroup: import("svelte").Component<FieldProps<CheckboxGroupProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormCheckboxGroup = ReturnType<typeof FormCheckboxGroup>;
5
7
  export default FormCheckboxGroup;
@@ -6,8 +6,14 @@
6
6
 
7
7
  let props: OptionalFieldProps<CheckboxProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  // Checkbox forwards native focus listeners to its input
10
12
  const fieldOptions: WithFieldOption = { valueKey: 'checked', valuePath: 'target.checked', shouldInject: false, onBlurFnName: 'onblur', insetLabel: false, validateStatus: false };
13
+
14
+ export function getControl() {
15
+ return field?.getControl();
16
+ }
11
17
  </script>
12
18
 
13
- <Field {...props as OptionalFieldProps<CheckboxProps> & { field: string }} component={Checkbox} {fieldOptions} />
19
+ <Field bind:this={field} {...props as OptionalFieldProps<CheckboxProps> & { field: string }} component={Checkbox} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { CheckboxProps } from '../checkbox/interface.js';
2
2
  import type { OptionalFieldProps } from './interface.js';
3
- declare const FormCheckbox: import("svelte").Component<OptionalFieldProps<CheckboxProps>, {}, "">;
3
+ declare const FormCheckbox: import("svelte").Component<OptionalFieldProps<CheckboxProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormCheckbox = ReturnType<typeof FormCheckbox>;
5
7
  export default FormCheckbox;
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<DatePickerProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={DatePicker} />
16
+ <Field bind:this={field} {...props} component={DatePicker} />
@@ -1,5 +1,7 @@
1
1
  import type { DatePickerProps } from '../date-picker/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormDatePicker: import("svelte").Component<FieldProps<DatePickerProps>, {}, "">;
3
+ declare const FormDatePicker: import("svelte").Component<FieldProps<DatePickerProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormDatePicker = ReturnType<typeof FormDatePicker>;
5
7
  export default FormDatePicker;
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<InputNumberProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={InputNumber} />
16
+ <Field bind:this={field} {...props} component={InputNumber} />
@@ -1,5 +1,7 @@
1
1
  import type { InputNumberProps } from '../input-number/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormInputNumber: import("svelte").Component<FieldProps<InputNumberProps>, {}, "">;
3
+ declare const FormInputNumber: import("svelte").Component<FieldProps<InputNumberProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormInputNumber = ReturnType<typeof FormInputNumber>;
5
7
  export default FormInputNumber;
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<InputProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={Input} />
16
+ <Field bind:this={field} {...props} component={Input} />
@@ -1,5 +1,7 @@
1
1
  import type { InputProps } from '../input/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormInput: import("svelte").Component<FieldProps<InputProps>, {}, "">;
3
+ declare const FormInput: import("svelte").Component<FieldProps<InputProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormInput = ReturnType<typeof FormInput>;
5
7
  export default FormInput;
@@ -6,7 +6,13 @@
6
6
 
7
7
  let props: FieldProps<PinCodeProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  const fieldOptions: WithFieldOption = { insetLabel: false };
12
+
13
+ export function getControl() {
14
+ return field?.getControl();
15
+ }
10
16
  </script>
11
17
 
12
- <Field {...props} component={PinCode} {fieldOptions} />
18
+ <Field bind:this={field} {...props} component={PinCode} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { PinCodeProps } from '../pincode/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormPinCode: import("svelte").Component<FieldProps<PinCodeProps>, {}, "">;
3
+ declare const FormPinCode: import("svelte").Component<FieldProps<PinCodeProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormPinCode = ReturnType<typeof FormPinCode>;
5
7
  export default FormPinCode;
@@ -6,7 +6,13 @@
6
6
 
7
7
  let props: FieldProps<RadioGroupProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  const fieldOptions: WithFieldOption = { valuePath: 'target.value', insetLabel: false, validateStatus: false };
12
+
13
+ export function getControl() {
14
+ return field?.getControl();
15
+ }
10
16
  </script>
11
17
 
12
- <Field {...props} component={RadioGroup} {fieldOptions} />
18
+ <Field bind:this={field} {...props} component={RadioGroup} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { RadioGroupProps } from '../radio/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormRadioGroup: import("svelte").Component<FieldProps<RadioGroupProps>, {}, "">;
3
+ declare const FormRadioGroup: import("svelte").Component<FieldProps<RadioGroupProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormRadioGroup = ReturnType<typeof FormRadioGroup>;
5
7
  export default FormRadioGroup;
@@ -6,8 +6,14 @@
6
6
 
7
7
  let props: OptionalFieldProps<RadioProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  // Radio forwards native focus listeners to its input
10
12
  const fieldOptions: WithFieldOption = { valueKey: 'checked', valuePath: 'target.checked', shouldInject: false, onBlurFnName: 'onblur', insetLabel: false, validateStatus: false };
13
+
14
+ export function getControl() {
15
+ return field?.getControl();
16
+ }
11
17
  </script>
12
18
 
13
- <Field {...props as OptionalFieldProps<RadioProps> & { field: string }} component={Radio} {fieldOptions} />
19
+ <Field bind:this={field} {...props as OptionalFieldProps<RadioProps> & { field: string }} component={Radio} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { RadioProps } from '../radio/interface.js';
2
2
  import type { OptionalFieldProps } from './interface.js';
3
- declare const FormRadio: import("svelte").Component<OptionalFieldProps<RadioProps>, {}, "">;
3
+ declare const FormRadio: import("svelte").Component<OptionalFieldProps<RadioProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormRadio = ReturnType<typeof FormRadio>;
5
7
  export default FormRadio;
@@ -6,7 +6,13 @@
6
6
 
7
7
  let props: FieldProps<RatingProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  const fieldOptions: WithFieldOption = { insetLabel: false, validateStatus: false };
12
+
13
+ export function getControl() {
14
+ return field?.getControl();
15
+ }
10
16
  </script>
11
17
 
12
- <Field {...props} component={Rating} {fieldOptions} />
18
+ <Field bind:this={field} {...props} component={Rating} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { RatingProps } from '../rating/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormRating: import("svelte").Component<FieldProps<RatingProps>, {}, "">;
3
+ declare const FormRating: import("svelte").Component<FieldProps<RatingProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormRating = ReturnType<typeof FormRating>;
5
7
  export default FormRating;
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<SelectProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={Select} />
16
+ <Field bind:this={field} {...props} component={Select} />
@@ -1,5 +1,7 @@
1
1
  import type { SelectProps } from '../select/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormSelect: import("svelte").Component<FieldProps<SelectProps>, {}, "">;
3
+ declare const FormSelect: import("svelte").Component<FieldProps<SelectProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormSelect = ReturnType<typeof FormSelect>;
5
7
  export default FormSelect;
@@ -6,7 +6,13 @@
6
6
 
7
7
  let props: FieldProps<SliderProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  const fieldOptions: WithFieldOption = { insetLabel: false, validateStatus: false };
12
+
13
+ export function getControl() {
14
+ return field?.getControl();
15
+ }
10
16
  </script>
11
17
 
12
- <Field {...props} component={Slider} {fieldOptions} />
18
+ <Field bind:this={field} {...props} component={Slider} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { SliderProps } from '../slider/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormSlider: import("svelte").Component<FieldProps<SliderProps>, {}, "">;
3
+ declare const FormSlider: import("svelte").Component<FieldProps<SliderProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormSlider = ReturnType<typeof FormSlider>;
5
7
  export default FormSlider;
@@ -6,8 +6,14 @@
6
6
 
7
7
  let props: FieldProps<SwitchProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  // Switch forwards native focus listeners to its input
10
12
  const fieldOptions: WithFieldOption = { valueKey: 'checked', onBlurFnName: 'onblur', insetLabel: false, validateStatus: false };
13
+
14
+ export function getControl() {
15
+ return field?.getControl();
16
+ }
11
17
  </script>
12
18
 
13
- <Field {...props} component={Switch} {fieldOptions} />
19
+ <Field bind:this={field} {...props} component={Switch} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { SwitchProps } from '../switch/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormSwitch: import("svelte").Component<FieldProps<SwitchProps>, {}, "">;
3
+ declare const FormSwitch: import("svelte").Component<FieldProps<SwitchProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormSwitch = ReturnType<typeof FormSwitch>;
5
7
  export default FormSwitch;
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<TagInputProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={TagInput} />
16
+ <Field bind:this={field} {...props} component={TagInput} />
@@ -1,5 +1,7 @@
1
1
  import type { TagInputProps } from '../tag-input/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormTagInput: import("svelte").Component<FieldProps<TagInputProps>, {}, "">;
3
+ declare const FormTagInput: import("svelte").Component<FieldProps<TagInputProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormTagInput = ReturnType<typeof FormTagInput>;
5
7
  export default FormTagInput;
@@ -6,7 +6,13 @@
6
6
 
7
7
  let props: FieldProps<TextAreaProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  const fieldOptions: WithFieldOption = { insetLabel: false };
12
+
13
+ export function getControl() {
14
+ return field?.getControl();
15
+ }
10
16
  </script>
11
17
 
12
- <Field {...props} component={TextArea} {fieldOptions} />
18
+ <Field bind:this={field} {...props} component={TextArea} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { TextAreaProps } from '../input/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormTextArea: import("svelte").Component<FieldProps<TextAreaProps>, {}, "">;
3
+ declare const FormTextArea: import("svelte").Component<FieldProps<TextAreaProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormTextArea = ReturnType<typeof FormTextArea>;
5
7
  export default FormTextArea;
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<TimePickerProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={TimePicker} />
16
+ <Field bind:this={field} {...props} component={TimePicker} />
@@ -1,5 +1,7 @@
1
1
  import type { TimePickerProps } from '../time-picker/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormTimePicker: import("svelte").Component<FieldProps<TimePickerProps>, {}, "">;
3
+ declare const FormTimePicker: import("svelte").Component<FieldProps<TimePickerProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormTimePicker = ReturnType<typeof FormTimePicker>;
5
7
  export default FormTimePicker;
@@ -6,8 +6,14 @@
6
6
 
7
7
  let props: FieldProps<TransferProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  // Transfer has no inset label or validateStatus
10
12
  const fieldOptions: WithFieldOption = { insetLabel: false, validateStatus: false };
13
+
14
+ export function getControl() {
15
+ return field?.getControl();
16
+ }
11
17
  </script>
12
18
 
13
- <Field {...props} component={Transfer} {fieldOptions} />
19
+ <Field bind:this={field} {...props} component={Transfer} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { TransferProps } from '../transfer/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormTransfer: import("svelte").Component<FieldProps<TransferProps>, {}, "">;
3
+ declare const FormTransfer: import("svelte").Component<FieldProps<TransferProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormTransfer = ReturnType<typeof FormTransfer>;
5
7
  export default FormTransfer;
@@ -5,6 +5,12 @@
5
5
  import type { FieldProps } from './interface.js';
6
6
 
7
7
  let props: FieldProps<TreeSelectProps> = $props();
8
+
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
11
+ export function getControl() {
12
+ return field?.getControl();
13
+ }
8
14
  </script>
9
15
 
10
- <Field {...props} component={TreeSelect} />
16
+ <Field bind:this={field} {...props} component={TreeSelect} />
@@ -1,5 +1,7 @@
1
1
  import type { TreeSelectProps } from '../tree-select/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormTreeSelect: import("svelte").Component<FieldProps<TreeSelectProps>, {}, "">;
3
+ declare const FormTreeSelect: import("svelte").Component<FieldProps<TreeSelectProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormTreeSelect = ReturnType<typeof FormTreeSelect>;
5
7
  export default FormTreeSelect;
@@ -6,8 +6,14 @@
6
6
 
7
7
  let props: FieldProps<UploadProps> = $props();
8
8
 
9
+ let field: ReturnType<typeof Field> | undefined;
10
+
9
11
  // Upload reports `{ fileList, ... }`, so the value is read from it; it has no blur callback
10
12
  const fieldOptions: WithFieldOption = { valueKey: 'fileList', valuePath: 'fileList', onBlurFnName: '', insetLabel: false };
13
+
14
+ export function getControl() {
15
+ return field?.getControl();
16
+ }
11
17
  </script>
12
18
 
13
- <Field {...props} component={Upload} {fieldOptions} />
19
+ <Field bind:this={field} {...props} component={Upload} {fieldOptions} />
@@ -1,5 +1,7 @@
1
1
  import type { UploadProps } from '../upload/interface.js';
2
2
  import type { FieldProps } from './interface.js';
3
- declare const FormUpload: import("svelte").Component<FieldProps<UploadProps>, {}, "">;
3
+ declare const FormUpload: import("svelte").Component<FieldProps<UploadProps>, {
4
+ getControl: () => Record<string, any> | undefined;
5
+ }, "">;
4
6
  type FormUpload = ReturnType<typeof FormUpload>;
5
7
  export default FormUpload;
@@ -4,6 +4,7 @@
4
4
  import useDefaultProps from '../_base/use-default-props.js';
5
5
  import Button from '../button/button.svelte';
6
6
  import { getButtonGroupContext } from '../button/context.js';
7
+ import { getInputGroupInScope } from '../input/context.js';
7
8
  import type { IconButtonProps } from './interface.js';
8
9
 
9
10
  const defaults = useDefaultProps('IconButton');
@@ -25,9 +26,12 @@
25
26
 
26
27
  const group = getButtonGroupContext();
27
28
 
28
- // Resolved here so the inner Button reads the IconButton global key, never its own
29
+ const inputGroup = getInputGroupInScope();
30
+
31
+ // Resolved here so the inner Button reads the IconButton global key, never its own.
32
+ // The resolved looks are passed down as own values, so the InputGroup must be folded in here too.
29
33
  const looks = $derived(
30
- resolveButtonLooks({ disabled, size, type, theme, colorful }, group, {
34
+ resolveButtonLooks({ disabled, size, type, theme, colorful }, group ?? inputGroup, {
31
35
  disabled: defaults('disabled'),
32
36
  size: defaults('size'),
33
37
  type: defaults('type'),
@@ -40,8 +40,14 @@
40
40
  role="group"
41
41
  {...rest}
42
42
  class={[`${prefixCls}-group`, rest.class, { [`${prefixCls}-${size}`]: size !== undefined && size !== 'default' }]}
43
- onfocusin={onFocus}
44
- onfocusout={onBlur}
43
+ onfocusin={(event) => {
44
+ rest.onfocusin?.(event);
45
+ onFocus?.(event);
46
+ }}
47
+ onfocusout={(event) => {
48
+ rest.onfocusout?.(event);
49
+ onBlur?.(event);
50
+ }}
45
51
  >
46
52
  {@render children?.()}
47
53
  </span>
@@ -175,7 +175,8 @@
175
175
  };
176
176
 
177
177
  // $state.snapshot: a parent mutating its own array in place still shows up as a change
178
- const snapshot = () => ({ items, selectedKeys: $state.snapshot(selectedKeys), openKeys: $state.snapshot(openKeys) });
178
+ // children is part of it so the foundation compares the previous props with the same shape, otherwise every change looks like a new tree
179
+ const snapshot = () => ({ children: foundationProps.children, items, selectedKeys: $state.snapshot(selectedKeys), openKeys: $state.snapshot(openKeys) });
179
180
 
180
181
  let previous = untrack(snapshot);
181
182
 
@@ -88,13 +88,15 @@
88
88
  // moving between the digits is not entering or leaving the code: Form's blur validation waits until focus is outside
89
89
  const isOutside = (event: FocusEvent & { currentTarget: HTMLElement }) => !(event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget));
90
90
 
91
- const handleFocusIn = (event: FocusEvent & { currentTarget: HTMLElement }) => {
91
+ const handleFocusIn = (event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) => {
92
+ rest.onfocusin?.(event);
92
93
  if (isOutside(event)) {
93
94
  onFocus?.(event);
94
95
  }
95
96
  };
96
97
 
97
- const handleFocusOut = (event: FocusEvent & { currentTarget: HTMLElement }) => {
98
+ const handleFocusOut = (event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) => {
99
+ rest.onfocusout?.(event);
98
100
  if (isOutside(event)) {
99
101
  onBlur?.(event);
100
102
  }
@@ -110,7 +110,8 @@
110
110
  });
111
111
 
112
112
  // Moving between the radios is not leaving the group: a form's blur validation waits until focus is outside.
113
- const handleFocusout = (event: FocusEvent & { currentTarget: HTMLElement }) => {
113
+ const handleFocusout = (event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) => {
114
+ rest.onfocusout?.(event);
114
115
  if (!(event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget))) {
115
116
  onBlur?.(event);
116
117
  }
@@ -21,8 +21,9 @@
21
21
 
22
22
  const prefix = cssClasses.PREFIX;
23
23
 
24
- // Items and handlers register when they mount, children before the group in tree order: index = layout order. The
25
- // foundation reads them only after mount, so they need not be reactive.
24
+ // Items and handlers register when they mount: tree order on mount, but one inserted later registers last. Index =
25
+ // layout order, which is DOM order; it is read on use because items can come and go. The foundation reads them only
26
+ // after mount, so they need not be reactive.
26
27
  const items: ResizeItemEntry[] = [];
27
28
  const handlers: HTMLDivElement[] = [];
28
29
 
@@ -43,19 +44,31 @@
43
44
  }),
44
45
  () => ({
45
46
  getGroupRef: () => group ?? null,
46
- getItem: (index) => items[index].el,
47
+ getItem: (index) => orderedItems()[index].el,
47
48
  getItemCount: () => items.length,
48
- getHandler: (index) => handlers[index],
49
+ getHandler: (index) => orderedHandlers()[index],
49
50
  getHandlerCount: () => handlers.length,
50
- getItemMin: (index) => items[index].min(),
51
- getItemMax: (index) => items[index].max(),
52
- getItemStart: (index) => items[index].start,
53
- getItemChange: (index) => items[index].change,
54
- getItemEnd: (index) => items[index].end,
55
- getItemDefaultSize: (index) => items[index].defaultSize(),
51
+ getItemMin: (index) => orderedItems()[index].min(),
52
+ getItemMax: (index) => orderedItems()[index].max(),
53
+ getItemStart: (index) => orderedItems()[index].start,
54
+ getItemChange: (index) => orderedItems()[index].change,
55
+ getItemEnd: (index) => orderedItems()[index].end,
56
+ getItemDefaultSize: (index) => orderedItems()[index].defaultSize(),
56
57
  })
57
58
  );
58
59
 
60
+ function inDocumentOrder(a: Node, b: Node) {
61
+ return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
62
+ }
63
+
64
+ function orderedItems() {
65
+ return items.toSorted((a, b) => inDocumentOrder(a.el, b.el));
66
+ }
67
+
68
+ function orderedHandlers() {
69
+ return handlers.toSorted(inDocumentOrder);
70
+ }
71
+
59
72
  const remove =
60
73
  <T>(list: T[], value: T) =>
61
74
  () => {
@@ -76,8 +89,9 @@
76
89
  },
77
90
  // a handler that left the group (unmounted mid-drag) can still send events: those are ignored
78
91
  notifyResizeStart: (handler, e) => {
79
- if (handlers.includes(handler)) {
80
- foundation.onResizeStart(handlers.indexOf(handler), e);
92
+ const index = orderedHandlers().indexOf(handler);
93
+ if (index >= 0) {
94
+ foundation.onResizeStart(index, e);
81
95
  }
82
96
  },
83
97
  notifyResizing: (handler, e) => {
@@ -90,7 +104,10 @@
90
104
  foundation.onResizeEnd(e);
91
105
  }
92
106
  },
93
- notifyKeyDown: (handler, e) => handlers.includes(handler) && foundation.resizeByKey(handlers.indexOf(handler), e),
107
+ notifyKeyDown: (handler, e) => {
108
+ const index = orderedHandlers().indexOf(handler);
109
+ return index >= 0 && foundation.resizeByKey(index, e);
110
+ },
94
111
  });
95
112
 
96
113
  const observeResize = (node: HTMLDivElement) => {
@@ -211,7 +211,8 @@
211
211
  event.currentTarget.value = String(handleValue(pos));
212
212
  };
213
213
 
214
- const onFocusout = (event: FocusEvent & { currentTarget: HTMLElement }) => {
214
+ const onFocusout = (event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) => {
215
+ rest.onfocusout?.(event);
215
216
  if (!(event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget))) {
216
217
  onBlur?.(event);
217
218
  }
@@ -322,10 +323,19 @@
322
323
  [`${prefix}-reverse`]: vertical && verticalReverse,
323
324
  },
324
325
  ]}
325
- onfocusin={(event) => onFocus?.(event)}
326
+ onfocusin={(event) => {
327
+ rest.onfocusin?.(event);
328
+ onFocus?.(event);
329
+ }}
326
330
  onfocusout={onFocusout}
327
- onmouseenter={foundation.handleWrapperEnter}
328
- onmouseleave={foundation.handleWrapperLeave}
331
+ onmouseenter={(event) => {
332
+ rest.onmouseenter?.(event);
333
+ foundation.handleWrapperEnter();
334
+ }}
335
+ onmouseleave={(event) => {
336
+ rest.onmouseleave?.(event);
337
+ foundation.handleWrapperLeave();
338
+ }}
329
339
  >
330
340
  <div class={`${prefix}-rail`} style={railStyle} onclick={foundation.handleWrapClick}></div>
331
341
  <div class={cssClasses.TRACK} style={trackStyle} onclick={foundation.handleWrapClick}></div>
@@ -239,12 +239,14 @@
239
239
  };
240
240
 
241
241
  const handleFocusIn = (event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) => {
242
+ rest.onfocusin?.(event);
242
243
  if (!(event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget))) {
243
244
  foundation.handleInputFocus(event);
244
245
  }
245
246
  };
246
247
 
247
248
  const handleFocusOut = (event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) => {
249
+ rest.onfocusout?.(event);
248
250
  // Chromium blurs the picked-up handle when dnd-kit moves it; ending the active state would unmount the list
249
251
  if (dragging) {
250
252
  return;
@@ -192,8 +192,9 @@
192
192
  // replace the search handle. `class` and `style` merge with Transfer's own below.
193
193
  const treeBindings = $derived(omit((treeProps ?? {}) as Record<string, unknown>, ['class', 'style', 'value', 'onChange', 'keyMaps', 'treeData', 'treeDataSimpleJson', 'onChangeWithObject', 'search', 'label']));
194
194
 
195
- // the root is not a focus target: a tabindex (one injected by a wrapping Tooltip included) goes to the search box
196
- const attrs = $derived(splitControlAttrs(rest, (key) => key === 'tabindex'));
195
+ // the root is not a focus target: a tabindex (one injected by a wrapping Tooltip included) goes to the search box;
196
+ // role="group" does not support aria-required
197
+ const attrs = $derived(splitControlAttrs(omit(rest, ['aria-required']), (key) => key === 'tabindex'));
197
198
 
198
199
  const onInputChange = (input: string) => {
199
200
  foundation.handleInputChange(input, true);
@@ -381,6 +381,11 @@
381
381
  watch(
382
382
  () => [value, expandedKeys, loadedKeys] as const,
383
383
  (current) => {
384
+ // The foundation never saw its own echo as the prop, so clearing the prop back to undefined is no change to
385
+ // it: the selection is emptied here
386
+ if (current[0] === undefined && echoes.value && echoes.value.value !== undefined) {
387
+ foundation.syncDerivedState({ selectedKeys: [], checkedKeys: new Set(), halfCheckedKeys: new Set(), realCheckedKeys: new Set() });
388
+ }
384
389
  (['value', 'expandedKeys', 'loadedKeys'] as const).forEach((name, i) => {
385
390
  if (echoes[name] && !isEqual(current[i], echoes[name].value)) {
386
391
  echoes[name] = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibrae/semi-ui-svelte",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Semi Design Next Svelte components",
5
5
  "license": "MIT",
6
6
  "homepage": "https://semi-design-next.pages.dev",
@@ -52,8 +52,8 @@
52
52
  "dependencies": {
53
53
  "@dnd-kit/dom": "~0.5.1",
54
54
  "@dnd-kit/svelte": "~0.5.1",
55
- "@fibrae/semi-foundation": "0.1.1",
56
- "@fibrae/semi-icons-svelte": "0.1.1",
55
+ "@fibrae/semi-foundation": "0.2.0",
56
+ "@fibrae/semi-icons-svelte": "0.2.0",
57
57
  "@tanstack/svelte-virtual": "^3.13.49",
58
58
  "async-validator": "^4.2.5",
59
59
  "date-fns": "^4.4.0",