@fibrae/semi-ui-svelte 0.6.0 → 0.8.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 (124) hide show
  1. package/dist/components/auto-complete/auto-complete.svelte +12 -21
  2. package/dist/components/auto-complete/interface.d.ts +3 -2
  3. package/dist/components/badge/badge.svelte +4 -4
  4. package/dist/components/badge/interface.d.ts +4 -3
  5. package/dist/components/button/button.svelte +3 -2
  6. package/dist/components/button/interface.d.ts +4 -2
  7. package/dist/components/card/card.svelte +9 -10
  8. package/dist/components/card/interface.d.ts +4 -4
  9. package/dist/components/cascader/cascader.svelte +11 -18
  10. package/dist/components/cascader/interface.d.ts +3 -2
  11. package/dist/components/cascader/item.svelte +1 -1
  12. package/dist/components/color-picker/color-picker.svelte +16 -1
  13. package/dist/components/cropper/cropper.svelte +4 -4
  14. package/dist/components/cropper/interface.d.ts +4 -3
  15. package/dist/components/date-picker/date-input.svelte +3 -1
  16. package/dist/components/date-picker/date-picker.svelte +9 -10
  17. package/dist/components/date-picker/interface.d.ts +5 -4
  18. package/dist/components/date-picker/internal.d.ts +2 -0
  19. package/dist/components/descriptions/descriptions.svelte +2 -2
  20. package/dist/components/descriptions/interface.d.ts +4 -2
  21. package/dist/components/dropdown/dropdown-popup.svelte +2 -1
  22. package/dist/components/dropdown/dropdown-popup.svelte.d.ts +2 -1
  23. package/dist/components/dropdown/dropdown.svelte +4 -5
  24. package/dist/components/dropdown/interface.d.ts +6 -4
  25. package/dist/components/empty/empty.svelte +2 -2
  26. package/dist/components/empty/interface.d.ts +4 -3
  27. package/dist/components/feedback/feedback.svelte +6 -0
  28. package/dist/components/feedback/interface.d.ts +5 -0
  29. package/dist/components/form/form.svelte +3 -1
  30. package/dist/components/form/index.d.ts +4 -2
  31. package/dist/components/form/index.js +3 -1
  32. package/dist/components/form/interface.d.ts +57 -10
  33. package/dist/components/form/label.svelte +37 -13
  34. package/dist/components/form/schema-form/schema-field.svelte +4 -6
  35. package/dist/components/form/schema-form/schema-form.svelte +2 -2
  36. package/dist/components/form/schema-form/schema-node.svelte +73 -91
  37. package/dist/components/form/schema-form/schema-node.svelte.d.ts +2 -3
  38. package/dist/components/form/schema-form/semi-array.svelte +47 -0
  39. package/dist/components/form/schema-form/semi-array.svelte.d.ts +7 -0
  40. package/dist/components/form/schema-form/semi-field.svelte +42 -0
  41. package/dist/components/form/schema-form/semi-field.svelte.d.ts +8 -0
  42. package/dist/components/form/schema-form/semi-renderers.svelte +24 -0
  43. package/dist/components/form/schema-form/semi-renderers.svelte.d.ts +24 -0
  44. package/dist/components/form/schema-form/semi-section.svelte +22 -0
  45. package/dist/components/form/schema-form/semi-section.svelte.d.ts +10 -0
  46. package/dist/components/form/section.svelte +8 -2
  47. package/dist/components/highlight/highlight.svelte +6 -7
  48. package/dist/components/highlight/interface.d.ts +4 -3
  49. package/dist/components/icon-button/icon-button.svelte +4 -3
  50. package/dist/components/image/image.svelte +4 -4
  51. package/dist/components/image/interface.d.ts +6 -5
  52. package/dist/components/image/preview/preview-image.svelte +1 -1
  53. package/dist/components/image/preview/preview-inner.svelte +10 -18
  54. package/dist/components/image/preview/preview.svelte +4 -4
  55. package/dist/components/input/input.svelte +4 -2
  56. package/dist/components/input/interface.d.ts +6 -5
  57. package/dist/components/input/textarea.svelte +6 -6
  58. package/dist/components/input-number/input-number.svelte +4 -2
  59. package/dist/components/input-number/interface.d.ts +5 -1
  60. package/dist/components/modal/interface.d.ts +5 -3
  61. package/dist/components/modal/modal-content.svelte +26 -32
  62. package/dist/components/modal/modal-content.svelte.d.ts +5 -4
  63. package/dist/components/modal/modal.svelte +4 -4
  64. package/dist/components/navigation/interface.d.ts +8 -4
  65. package/dist/components/navigation/nav-items.svelte +1 -1
  66. package/dist/components/navigation/nav.svelte +3 -2
  67. package/dist/components/navigation/sub-nav.svelte +5 -4
  68. package/dist/components/overflow-list/interface.d.ts +4 -3
  69. package/dist/components/overflow-list/overflow-list.svelte +3 -3
  70. package/dist/components/pagination/interface.d.ts +1 -1
  71. package/dist/components/pagination/pagination.svelte +63 -61
  72. package/dist/components/popconfirm/interface.d.ts +3 -0
  73. package/dist/components/popconfirm/popconfirm.svelte +4 -4
  74. package/dist/components/popover/arrow.svelte +2 -2
  75. package/dist/components/popover/interface.d.ts +8 -3
  76. package/dist/components/popover/popover.svelte +4 -4
  77. package/dist/components/radio/interface.d.ts +6 -5
  78. package/dist/components/radio/radio-group.svelte +2 -2
  79. package/dist/components/radio/radio.svelte +4 -4
  80. package/dist/components/select/interface.d.ts +3 -2
  81. package/dist/components/select/option.svelte +1 -1
  82. package/dist/components/select/select.svelte +9 -14
  83. package/dist/components/side-sheet/interface.d.ts +6 -5
  84. package/dist/components/side-sheet/side-sheet.svelte +31 -29
  85. package/dist/components/slider/interface.d.ts +4 -2
  86. package/dist/components/slider/slider.svelte +3 -2
  87. package/dist/components/spin/icon.svelte +1 -1
  88. package/dist/components/spin/interface.d.ts +4 -3
  89. package/dist/components/spin/spin.svelte +2 -3
  90. package/dist/components/switch/switch.svelte +1 -1
  91. package/dist/components/table/body/body.svelte +21 -8
  92. package/dist/components/table/context.d.ts +2 -1
  93. package/dist/components/table/interface.d.ts +4 -3
  94. package/dist/components/table/table-header/table-header-row.svelte +15 -3
  95. package/dist/components/table/table.svelte +38 -8
  96. package/dist/components/tabs/interface.d.ts +8 -7
  97. package/dist/components/tabs/tab-bar.svelte +12 -2
  98. package/dist/components/tabs/tabs.svelte +7 -8
  99. package/dist/components/time-picker/interface.d.ts +4 -4
  100. package/dist/components/time-picker/time-input.svelte +2 -2
  101. package/dist/components/time-picker/time-picker.svelte +10 -11
  102. package/dist/components/tooltip/interface.d.ts +5 -2
  103. package/dist/components/tooltip/tooltip.svelte +13 -38
  104. package/dist/components/tree/interface.d.ts +4 -3
  105. package/dist/components/tree/node-arrow.svelte +1 -1
  106. package/dist/components/tree/tree-node.svelte +1 -1
  107. package/dist/components/tree/tree.svelte +23 -74
  108. package/dist/components/tree-select/interface.d.ts +4 -5
  109. package/dist/components/tree-select/tree-select.svelte +28 -67
  110. package/dist/components/typography/base.svelte +1 -1
  111. package/dist/components/upload/file-card.svelte +1 -1
  112. package/dist/components/upload/interface.d.ts +5 -3
  113. package/dist/components/upload/upload.svelte +6 -4
  114. package/dist/components/user-guide/user-guide.svelte +15 -1
  115. package/dist/hooks/index.d.ts +1 -0
  116. package/dist/hooks/index.js +1 -0
  117. package/dist/hooks/use-overlay-resources.svelte.d.ts +13 -0
  118. package/dist/hooks/use-overlay-resources.svelte.js +20 -0
  119. package/dist/internal/virtual-list.svelte +11 -1
  120. package/dist/internal/virtual-list.svelte.d.ts +7 -0
  121. package/dist/styles.css +1 -1
  122. package/package.json +3 -3
  123. package/dist/components/tree/use-tree-keyboard.svelte.d.ts +0 -29
  124. package/dist/components/tree/use-tree-keyboard.svelte.js +0 -61
@@ -23,7 +23,7 @@
23
23
  {#snippet cells(item: DescriptionsData, index: number, span: number | undefined)}
24
24
  {#if align === 'plain'}
25
25
  <td class={`${prefixCls}-item`} colspan={span || 1}>
26
- <span class={`${prefixCls}-key`} style={item.keyStyle}>
26
+ <span class={[`${prefixCls}-key`, item.classNames?.key]} style={item.styles?.key}>
27
27
  {#if itemKey}{@render itemKey({ item, index })}{:else}{item.key}{/if}:</span
28
28
  >
29
29
  <span class={`${prefixCls}-value`}>
@@ -32,7 +32,7 @@
32
32
  </td>
33
33
  {:else}
34
34
  <th class={[`${prefixCls}-item`, `${prefixCls}-item-th`]}>
35
- <span class={`${prefixCls}-key`} style={item.keyStyle}>
35
+ <span class={[`${prefixCls}-key`, item.classNames?.key]} style={item.styles?.key}>
36
36
  {#if itemKey}{@render itemKey({ item, index })}{:else}{item.key}{/if}
37
37
  </span>
38
38
  </th>
@@ -1,5 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { ClassValue, HTMLAttributes } from 'svelte/elements';
3
+ import type { DescriptionsItemPart } from '@fibrae/semi-foundation/components/descriptions/constants';
3
4
  export type DescriptionsAlign = 'center' | 'justify' | 'left' | 'plain';
4
5
  export type DescriptionsLayout = 'horizontal' | 'vertical';
5
6
  export type DescriptionsSize = 'small' | 'medium' | 'large';
@@ -8,7 +9,8 @@ export interface DescriptionsData {
8
9
  value?: string | number;
9
10
  hidden?: boolean;
10
11
  span?: number;
11
- keyStyle?: string;
12
+ classNames?: Partial<Record<DescriptionsItemPart, ClassValue>>;
13
+ styles?: Partial<Record<DescriptionsItemPart, string>>;
12
14
  }
13
15
  export interface DescriptionsSnippetArgs {
14
16
  item: DescriptionsData;
@@ -1,12 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { onMount, type Snippet } from 'svelte';
3
+ import type { ClassValue } from 'svelte/elements';
3
4
  import type { FocusTarget, RenderContentProps } from '../tooltip/index.js';
4
5
  import { type DropdownContext, setDropdownContext } from './context.js';
5
6
 
6
7
  interface Props {
7
8
  context: DropdownContext;
8
9
  prefixCls: string;
9
- contentClass?: string;
10
+ contentClass?: ClassValue;
10
11
  style?: string;
11
12
  initialFocusRef: RenderContentProps['initialFocusRef'];
12
13
  focusTarget: FocusTarget;
@@ -1,10 +1,11 @@
1
1
  import { type Snippet } from 'svelte';
2
+ import type { ClassValue } from 'svelte/elements';
2
3
  import type { FocusTarget, RenderContentProps } from '../tooltip/index.js';
3
4
  import { type DropdownContext } from './context.js';
4
5
  interface Props {
5
6
  context: DropdownContext;
6
7
  prefixCls: string;
7
- contentClass?: string;
8
+ contentClass?: ClassValue;
8
9
  style?: string;
9
10
  initialFocusRef: RenderContentProps['initialFocusRef'];
10
11
  focusTarget: FocusTarget;
@@ -35,7 +35,8 @@
35
35
  menu = defaults('menu'),
36
36
  class: className = defaults('class'),
37
37
  style = defaults('style'),
38
- contentClassName = defaults('contentClassName'),
38
+ classNames = defaults('classNames'),
39
+ styles = defaults('styles'),
39
40
  selectionMode = defaults('selectionMode'),
40
41
  showTick = defaults('showTick', false),
41
42
  motion = defaults('motion', true),
@@ -58,7 +59,6 @@
58
59
  stopPropagation = defaults('stopPropagation'),
59
60
  preventScroll = defaults('preventScroll'),
60
61
  wrapperId,
61
- wrapperClassName = defaults('wrapperClassName'),
62
62
  'aria-label': ariaLabel = defaults('aria-label'),
63
63
  'aria-labelledby': ariaLabelledby = defaults('aria-labelledby'),
64
64
  'aria-describedby': ariaDescribedby = defaults('aria-describedby'),
@@ -140,7 +140,6 @@
140
140
  stopPropagation,
141
141
  preventScroll,
142
142
  wrapperId,
143
- wrapperClassName,
144
143
  'aria-label': ariaLabel,
145
144
  'aria-labelledby': ariaLabelledby,
146
145
  'aria-describedby': ariaDescribedby,
@@ -246,14 +245,14 @@
246
245
  {@render child({ props })}
247
246
  {:else}
248
247
  <!-- Tooltip's own span would be out of reach of the keydown listener -->
249
- <span {...props} class={[`${tooltipClasses.PREFIX}-trigger-wrapper`, wrapperClassName, props.class]} style:display={textOnly ? undefined : 'inline-block'} tabindex={focusableInside ? -1 : 0}>
248
+ <span {...props} class={[`${tooltipClasses.PREFIX}-trigger-wrapper`, classNames?.wrapper, props.class]} style={[textOnly ? undefined : 'display: inline-block', styles?.wrapper].filter(Boolean).join('; ') || undefined} tabindex={focusableInside ? -1 : 0}>
250
249
  {@render children?.()}
251
250
  </span>
252
251
  {/if}
253
252
  {/snippet}
254
253
 
255
254
  {#snippet popup({ initialFocusRef }: RenderContentProps)}
256
- <DropdownPopup contentClass={contentClassName} {context} {focusTarget} {initialFocusRef} {prefixCls} {style}>
255
+ <DropdownPopup contentClass={classNames?.content} {context} {focusTarget} {initialFocusRef} {prefixCls} style={[style, styles?.content].filter(Boolean).join('; ') || undefined}>
257
256
  {#if content}
258
257
  {@render content()}
259
258
  {:else if menu}
@@ -1,5 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { ClassValue, HTMLAttributes } from 'svelte/elements';
3
+ import type { DropdownPart } from '@fibrae/semi-foundation/components/dropdown/constants';
3
4
  import type { DropdownSelectionMode } from '@fibrae/semi-foundation/components/dropdown/menu-foundation';
4
5
  import type { TooltipProps, TooltipTriggerProps } from '../tooltip/index.js';
5
6
  /**
@@ -19,7 +20,7 @@ export interface DropdownMenuIconArgs {
19
20
  * No arrow and no arrow-key option: the Dropdown alone moves focus with Up and Down. No `wrapWhenSpecial`: Tooltip
20
21
  * wraps a special trigger only in its own span, and Dropdown always renders the trigger itself. No element props: F11.
21
22
  */
22
- export interface DropdownProps extends Omit<TooltipProps, 'showArrow' | 'arrowPointAtCenter' | 'disableArrowKeyDown' | 'arrow' | 'child' | 'children' | 'content' | 'wrapWhenSpecial'> {
23
+ export interface DropdownProps extends Omit<TooltipProps, 'showArrow' | 'arrowPointAtCenter' | 'disableArrowKeyDown' | 'arrow' | 'child' | 'children' | 'classNames' | 'content' | 'styles' | 'wrapWhenSpecial'> {
23
24
  children?: Snippet;
24
25
  /** Renders the trigger element itself, which takes `props`; use it for a button, a link or a parent `DropdownItem` */
25
26
  child?: Snippet<[{
@@ -29,8 +30,8 @@ export interface DropdownProps extends Omit<TooltipProps, 'showArrow' | 'arrowPo
29
30
  content?: Snippet;
30
31
  /** Icon of each `node: 'item'` entry of `menu`; the icon container is rendered even when the snippet outputs nothing */
31
32
  menuIcon?: Snippet<[DropdownMenuIconArgs]>;
32
- /** On the menu container `.semi-dropdown`; `class` goes on the popup `.semi-dropdown-wrapper` */
33
- contentClassName?: string;
33
+ /** `content` is the menu container `.semi-dropdown`, as `style` is; `class` goes on the popup `.semi-dropdown-wrapper` */
34
+ classNames?: Partial<Record<DropdownPart, ClassValue>>;
34
35
  menu?: DropdownMenuItem[];
35
36
  /**
36
37
  * How the items of this menu are selected (a submenu takes its own Dropdown's value); `active` marks the selected
@@ -41,6 +42,7 @@ export interface DropdownProps extends Omit<TooltipProps, 'showArrow' | 'arrowPo
41
42
  */
42
43
  selectionMode?: DropdownSelectionMode;
43
44
  showTick?: boolean;
45
+ styles?: Partial<Record<DropdownPart, string>>;
44
46
  }
45
47
  export interface DropdownHandle {
46
48
  focusTrigger: () => void;
@@ -6,7 +6,7 @@
6
6
  import type { EmptyProps } from './interface.js';
7
7
 
8
8
  const defaults = useDefaultProps('Empty');
9
- const { layout = defaults('layout', 'vertical'), imageStyle = defaults('imageStyle'), title = defaults('title'), image = defaults('image'), darkModeImage = defaults('darkModeImage'), description, children, ...rest }: EmptyProps = $props();
9
+ const { layout = defaults('layout', 'vertical'), classNames = defaults('classNames'), styles = defaults('styles'), title = defaults('title'), image = defaults('image'), darkModeImage = defaults('darkModeImage'), description, children, ...rest }: EmptyProps = $props();
10
10
 
11
11
  // Read after mount only: server render and hydration see null, so the markup matches
12
12
  let themeMode = $state<string | null>(null);
@@ -33,7 +33,7 @@
33
33
  </script>
34
34
 
35
35
  <div {...rest} class={[prefixCls, rest.class, { [`${prefixCls}-${layout}`]: layout }]}>
36
- <div class={`${prefixCls}-image`} style={imageStyle} x-semi-prop="image,darkModeImage">
36
+ <div class={[`${prefixCls}-image`, classNames?.image]} style={styles?.image} x-semi-prop="image,darkModeImage">
37
37
  {#if shownSnippet}
38
38
  {@render shownSnippet()}
39
39
  {:else if src}
@@ -1,6 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes } from 'svelte/elements';
3
- import type { strings } from '@fibrae/semi-foundation/components/empty/constants';
2
+ import type { ClassValue, HTMLAttributes } from 'svelte/elements';
3
+ import type { EmptyPart, strings } from '@fibrae/semi-foundation/components/empty/constants';
4
4
  export type EmptyLayout = (typeof strings.LAYOUT)[number];
5
5
  export interface EmptySvgNode {
6
6
  id: string;
@@ -9,7 +9,8 @@ export interface EmptySvgNode {
9
9
  export type EmptyImage = string | EmptySvgNode | Snippet;
10
10
  export interface EmptyProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
11
11
  layout?: EmptyLayout;
12
- imageStyle?: string;
12
+ classNames?: Partial<Record<EmptyPart, ClassValue>>;
13
+ styles?: Partial<Record<EmptyPart, string>>;
13
14
  title?: string | Snippet;
14
15
  image?: EmptyImage;
15
16
  /** Shown instead of `image` while the page is in dark mode */
@@ -27,12 +27,14 @@
27
27
  afterVisibleChange = defaults('afterVisibleChange'),
28
28
  cancelButtonProps = defaults('cancelButtonProps'),
29
29
  checkboxGroupProps = defaults('checkboxGroupProps'),
30
+ classNames = defaults('classNames'),
30
31
  mode = defaults('mode', 'popup'),
31
32
  okButtonProps = defaults('okButtonProps'),
32
33
  onCancel = defaults('onCancel'),
33
34
  onOk = defaults('onOk'),
34
35
  onValueChange = defaults('onValueChange'),
35
36
  radioGroupProps = defaults('radioGroupProps'),
37
+ styles = defaults('styles'),
36
38
  textAreaProps = defaults('textAreaProps'),
37
39
  title = defaults('title'),
38
40
  type = defaults('type', 'emoji'),
@@ -185,6 +187,7 @@
185
187
  cancelButtonProps={modalCancelProps}
186
188
  children={body}
187
189
  class={[prefix, `${prefix}-${type}`, rest.class]}
190
+ {classNames}
188
191
  {closeIcon}
189
192
  {footer}
190
193
  {header}
@@ -193,6 +196,7 @@
193
196
  okButtonProps={modalOkProps}
194
197
  onCancel={foundation.handleModalCancel}
195
198
  onOk={foundation.handleModalOk}
199
+ {styles}
196
200
  {title}
197
201
  />
198
202
  {:else}
@@ -209,9 +213,11 @@
209
213
  bind:visible={() => open, () => {}}
210
214
  children={body}
211
215
  class={[prefix, `${prefix}-${type}`, rest.class]}
216
+ {classNames}
212
217
  {closeIcon}
213
218
  footer={footer === undefined ? popupFooter : (footer ?? undefined)}
214
219
  onCancel={foundation.handleCancel}
220
+ {styles}
215
221
  {title}
216
222
  />
217
223
  {/if}
@@ -1,5 +1,7 @@
1
1
  import type { Snippet } from 'svelte';
2
+ import type { ClassValue } from 'svelte/elements';
2
3
  import type { CheckboxValue } from '@fibrae/semi-foundation/components/checkbox/checkbox-group-foundation';
4
+ import type { FeedbackPart } from '@fibrae/semi-foundation/components/feedback/constants';
3
5
  import type { EmojiResult, FeedbackValue } from '@fibrae/semi-foundation/components/feedback/foundation';
4
6
  import type { CheckboxGroupOptionSnippetProps, CheckboxGroupProps } from '../checkbox/interface.js';
5
7
  import type { TextAreaChangeEvent, TextAreaProps } from '../input/interface.js';
@@ -23,6 +25,9 @@ export interface FeedbackContentSnippetProps {
23
25
  export interface FeedbackOwnProps {
24
26
  mode?: FeedbackMode;
25
27
  type?: FeedbackType;
28
+ /** Forwarded to the Modal or SideSheet of the current mode. */
29
+ classNames?: Partial<Record<FeedbackPart, ClassValue>>;
30
+ styles?: Partial<Record<FeedbackPart, string>>;
26
31
  /** Bindable. The cancel paths (cancel button, close button, Escape, and for a modal the mask click) write `false`; the ok button never closes. */
27
32
  visible?: boolean;
28
33
  /** Plain text or a snippet. A string is declared here so `title="x"` is not a native tooltip. */
@@ -3,7 +3,7 @@
3
3
  import { cssClasses } from '@fibrae/semi-foundation/components/form/constants';
4
4
  import { getFormApiProxyInternals } from '@fibrae/semi-foundation/components/form/form-api-proxy';
5
5
  import FormFoundation from '@fibrae/semi-foundation/components/form/foundation';
6
- import type { BaseFormAdapter, FormFoundationState, FormState } from '@fibrae/semi-foundation/components/form/interface';
6
+ import type { BaseFormAdapter, FieldPath, FormFoundationState, FormState } from '@fibrae/semi-foundation/components/form/interface';
7
7
  import '@fibrae/semi-foundation/components/form/form.css';
8
8
  import { useDefaultProps, useFoundation } from '../../base/index.js';
9
9
  import useLocale from '../locale/use-locale.svelte.js';
@@ -43,6 +43,7 @@
43
43
  onChange,
44
44
  onValueChange,
45
45
  onErrorChange,
46
+ onRevealField,
46
47
  getFormApi: notifyFormApi,
47
48
  children,
48
49
  ...rest
@@ -132,6 +133,7 @@
132
133
  notifyValueChange: (values, changedValues) => onValueChange?.(values, changedValues),
133
134
  notifyErrorChange: (errors, changedError) => onErrorChange?.(errors, changedError),
134
135
  notifyReset: () => onReset?.(),
136
+ notifyRevealField: (field) => onRevealField?.(field as FieldPath<Values>),
135
137
  getFormElement: () => formElement ?? null,
136
138
  })
137
139
  );
@@ -27,8 +27,10 @@ import FormInputGroup from './input-group.svelte';
27
27
  import FormLabel from './label.svelte';
28
28
  import SchemaField from './schema-form/schema-field.svelte';
29
29
  import SchemaForm from './schema-form/schema-form.svelte';
30
+ import { semiRenderers } from './schema-form/semi-renderers.svelte';
30
31
  import FormSection from './section.svelte';
31
32
  import FormSlot from './slot.svelte';
32
- export { ArrayField, Form, FormAutoComplete, FormCascader, FormCheckbox, FormCheckboxGroup, FormDatePicker, FormErrorMessage, FormField, FormInput, FormInputGroup, FormInputNumber, FormLabel, FormPinCode, FormRadio, FormRadioGroup, FormRating, FormSection, FormSelect, FormSlider, FormSlot, FormSwitch, FormTagInput, FormTextArea, FormTimePicker, FormTransfer, FormTreeSelect, FormUpload, SchemaField, SchemaForm, useForm, };
33
+ export { ArrayField, Form, FormAutoComplete, FormCascader, FormCheckbox, FormCheckboxGroup, FormDatePicker, FormErrorMessage, FormField, FormInput, FormInputGroup, FormInputNumber, FormLabel, FormPinCode, FormRadio, FormRadioGroup, FormRating, FormSection, FormSelect, FormSlider, FormSlot, FormSwitch, FormTagInput, FormTextArea, FormTimePicker, FormTransfer, FormTreeSelect, FormUpload, SchemaField, SchemaForm, semiRenderers, useForm, };
34
+ export { blankRow } from '@fibrae/semi-foundation/components/form/json-schema';
33
35
  export { useFieldApi, useFieldState, useFormApi, useFormState } from './hooks/index.js';
34
- export type { ArrayFieldItem, ArrayFieldProps, ArrayFieldSnippetProps, CommonFieldProps, ErrorMessageProps as FormErrorMessageProps, FieldError, FieldErrorInput, FieldLabel, FieldProps, FieldValidateTriggerType, FieldValidator, FormApi, FormFieldProps, FormProps, FormRenderProps, FormState, FormValidator, InputGroupProps as FormInputGroupProps, JsonSchema, LabelProps as FormLabelProps, OptionalFieldProps, RuleItem, RuleType, SchemaFieldKind, SchemaFieldNode, SchemaFieldProps, SchemaFieldRenderProps, SchemaFormProps, ScrollOptions, SectionProps as FormSectionProps, SlotProps as FormSlotProps, WithFieldOption, } from './interface.js';
36
+ export type { ArrayFieldItem, ArrayFieldProps, ArrayFieldSnippetProps, CommonFieldProps, ErrorMessageProps as FormErrorMessageProps, FieldError, FieldErrorInput, FieldLabel, FieldProps, FieldValidateTriggerType, FieldValidator, FormApi, FormFieldProps, FormProps, FormRenderProps, FormState, FormValidator, InputGroupProps as FormInputGroupProps, JsonSchema, LabelProps as FormLabelProps, OptionalFieldProps, RuleItem, RuleType, SchemaArrayContext, SchemaArrayItem, SchemaFieldContext, SchemaFieldKind, SchemaFieldNode, SchemaFieldProps, SchemaFieldRenderers, SchemaFormProps, SchemaLeafContext, SchemaObjectContext, ScrollOptions, SectionProps as FormSectionProps, SlotProps as FormSlotProps, WithFieldOption, } from './interface.js';
@@ -27,7 +27,9 @@ import FormInputGroup from './input-group.svelte';
27
27
  import FormLabel from './label.svelte';
28
28
  import SchemaField from './schema-form/schema-field.svelte';
29
29
  import SchemaForm from './schema-form/schema-form.svelte';
30
+ import { semiRenderers } from './schema-form/semi-renderers.svelte';
30
31
  import FormSection from './section.svelte';
31
32
  import FormSlot from './slot.svelte';
32
- export { ArrayField, Form, FormAutoComplete, FormCascader, FormCheckbox, FormCheckboxGroup, FormDatePicker, FormErrorMessage, FormField, FormInput, FormInputGroup, FormInputNumber, FormLabel, FormPinCode, FormRadio, FormRadioGroup, FormRating, FormSection, FormSelect, FormSlider, FormSlot, FormSwitch, FormTagInput, FormTextArea, FormTimePicker, FormTransfer, FormTreeSelect, FormUpload, SchemaField, SchemaForm, useForm, };
33
+ export { ArrayField, Form, FormAutoComplete, FormCascader, FormCheckbox, FormCheckboxGroup, FormDatePicker, FormErrorMessage, FormField, FormInput, FormInputGroup, FormInputNumber, FormLabel, FormPinCode, FormRadio, FormRadioGroup, FormRating, FormSection, FormSelect, FormSlider, FormSlot, FormSwitch, FormTagInput, FormTextArea, FormTimePicker, FormTransfer, FormTreeSelect, FormUpload, SchemaField, SchemaForm, semiRenderers, useForm, };
34
+ export { blankRow } from '@fibrae/semi-foundation/components/form/json-schema';
33
35
  export { useFieldApi, useFieldState, useFormApi, useFormState } from './hooks/index.js';
@@ -3,7 +3,7 @@ import type { HTMLAttributes, HTMLFieldsetAttributes, HTMLFormAttributes, HTMLLa
3
3
  import type { Options as ScrollIntoViewOptions } from 'scroll-into-view-if-needed';
4
4
  import type { FieldError } from '@fibrae/semi-foundation/components/form/errors';
5
5
  import type { AllErrors, BaseFormApi, DeepPartial, ExclusiveFieldValidation, ExclusiveFormValidation, FieldPath, FieldValidateTriggerType, FieldValidator, FormState, FormValidator, StandardSchema } from '@fibrae/semi-foundation/components/form/interface';
6
- import type { JsonSchema, SchemaFieldNode } from '@fibrae/semi-foundation/components/form/json-schema';
6
+ import type { arrayState, JsonSchema, SchemaFieldNode } from '@fibrae/semi-foundation/components/form/json-schema';
7
7
  import type { RuleItem } from '@fibrae/semi-foundation/components/form/rules';
8
8
  import type { ColProps } from '../grid/interface.js';
9
9
  import type { InputGroupProps as BaseInputGroupProps, ValidateStatus } from '../input/interface.js';
@@ -27,9 +27,13 @@ export interface LabelProps extends Omit<HTMLLabelAttributes, 'children'> {
27
27
  width?: number | string;
28
28
  children?: Snippet;
29
29
  extra?: Snippet;
30
+ /** Shown in a Tooltip by a help button beside the label, which is not part of the field's name */
31
+ tooltip?: Snippet | string | number;
30
32
  }
31
33
  /** A label configured by data; nodes go in the `fieldLabel` and `labelExtra` snippets */
32
34
  export interface FieldLabel {
35
+ /** Shown in a Tooltip by a help button beside the label, which is not part of the field's name */
36
+ tooltip?: string | number;
33
37
  /** The id of the label element, which the control's aria-labelledby references; generated when missing */
34
38
  id?: string;
35
39
  text?: string | number;
@@ -85,6 +89,8 @@ export interface AllFormProps<Values extends Record<string, any> = any, Output =
85
89
  onChange?: (formState: FormState<Values>) => void;
86
90
  onValueChange?: (values: Values, changedValues: Partial<Values>) => void;
87
91
  onErrorChange?: (errors: AllErrors<Values>, changedError?: Partial<Record<FieldPath<Values>, FieldError>>) => void;
92
+ /** scrollToField or focusField found nothing rendered at `field`: expand the collapsed container that holds it */
93
+ onRevealField?: (field: FieldPath<Values>) => void;
88
94
  /** Called once when the Form mounts, to save the formApi reference */
89
95
  getFormApi?: (formApi: FormApi<Values, Output>) => void;
90
96
  children?: Snippet<[FormRenderProps<Values, Output>]>;
@@ -222,6 +228,8 @@ export interface ErrorMessageProps extends Omit<HTMLAttributes<HTMLDivElement>,
222
228
  }
223
229
  export interface SectionProps extends Omit<HTMLFieldsetAttributes, 'children'> {
224
230
  text?: Snippet;
231
+ /** Shown below the title and describes the fieldset */
232
+ extraText?: Snippet;
225
233
  children?: Snippet;
226
234
  }
227
235
  export interface SlotProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
@@ -243,21 +251,60 @@ export interface InputGroupProps extends Omit<BaseInputGroupProps, 'label'> {
243
251
  extraTextPosition?: 'bottom' | 'middle';
244
252
  extraText?: Snippet;
245
253
  }
246
- export interface SchemaFieldRenderProps {
254
+ interface SchemaNodeContext {
247
255
  node: SchemaFieldNode;
256
+ /** Renders the node at `field` through the same renderers; key the result when rendering a list */
257
+ render: Snippet<[string]>;
258
+ }
259
+ export interface SchemaObjectContext extends SchemaNodeContext {
260
+ kind: 'object';
261
+ /** The property nodes rendered in schema order */
262
+ content: Snippet;
263
+ }
264
+ export interface SchemaArrayItem {
265
+ /** Stable across moves: key the row with it, not with `index` */
266
+ key: string;
248
267
  field: string;
268
+ index: number;
269
+ node: SchemaFieldNode;
270
+ /** The row's current value, such as the field a card title reads */
271
+ value: unknown;
272
+ remove: () => void;
273
+ }
274
+ export interface SchemaArrayContext extends SchemaNodeContext, ReturnType<typeof arrayState> {
275
+ kind: 'array';
276
+ items: SchemaArrayItem[];
277
+ /** Inserts the schema's blank row before `index`, or appends it; an event argument counts as no index */
278
+ add: (index?: number | Event) => void;
279
+ addWithInitValue: (value: Record<string, any>, index?: number) => void;
280
+ move: (from: number, to: number) => void;
281
+ /** The error of the array itself (a schema's minItems), not those of its rows */
282
+ error?: FieldError;
283
+ /** Spread on the element that contains the rows, so scrollToField and focusField reach the array */
284
+ fieldProps: {
285
+ 'x-field-id': string;
286
+ };
287
+ }
288
+ /** Any node that is neither an object nor an array: `node.item` is set when it is a row of an array */
289
+ export interface SchemaLeafContext extends SchemaNodeContext {
290
+ kind: 'field';
291
+ }
292
+ export type SchemaFieldContext = SchemaObjectContext | SchemaArrayContext | SchemaLeafContext;
293
+ export interface SchemaFieldRenderers {
294
+ /** Without it an object renders its properties with no wrapper */
295
+ object?: Snippet<[SchemaObjectContext]>;
296
+ array?: Snippet<[SchemaArrayContext]>;
297
+ /** Also receives the nodes of kind `unsupported` */
298
+ field?: Snippet<[SchemaLeafContext]>;
249
299
  }
250
300
  export interface SchemaFieldProps {
251
- /** Path of the node to render; the root by default, which renders without a Section */
301
+ /** Path of the node to render; '' is the root */
252
302
  field?: string;
253
303
  /** Takes precedence over the JSON Schema exported from the Form's `schema` */
254
304
  jsonSchema?: JsonSchema;
255
- /**
256
- * Field components by `format`, then by kind (`input`, `number`, `select` ...); they receive the props of the built-in
257
- * control they replace
258
- */
259
- widgets?: Record<string, Component<any, any, any>>;
260
- /** Snippets by node pattern (`contacts[].email`); one renders the node and everything under it */
261
- renderField?: Record<string, Snippet<[SchemaFieldRenderProps]>>;
305
+ /** How each kind of node renders; SchemaField itself renders no UI. `semiRenderers` renders Semi Form controls */
306
+ renderers?: SchemaFieldRenderers;
307
+ /** Replaces the renderer of the node whose `pattern` (array rows as `[]`) is the key */
308
+ renderField?: Record<string, Snippet<[SchemaFieldContext]>>;
262
309
  }
263
310
  export type SchemaFormProps<Values extends Record<string, any> = any, Output = Values> = FormProps<Values, Output> & Omit<SchemaFieldProps, 'field'>;
@@ -2,27 +2,51 @@
2
2
  import { cssClasses } from '@fibrae/semi-foundation/components/form/constants';
3
3
  import { toCssLength } from '@fibrae/semi-foundation/utils';
4
4
  import '@fibrae/semi-foundation/components/form/form.css';
5
+ import { IconHelpCircle } from '@fibrae/semi-icons-svelte';
5
6
  import useLocale from '../locale/use-locale.svelte.js';
7
+ import type { TooltipTriggerProps } from '../tooltip/interface.js';
8
+ import Tooltip from '../tooltip/tooltip.svelte';
6
9
  import type { LabelProps } from './interface.js';
7
10
 
8
- let { text, align = 'left', disabled, required = false, optional = false, name, width, children, extra, ...rest }: LabelProps = $props();
11
+ let { text, align = 'left', disabled, required = false, optional = false, name, width, children, extra, tooltip, ...rest }: LabelProps = $props();
9
12
 
10
13
  const locale = useLocale('Form');
11
14
 
12
15
  const prefix = `${cssClasses.PREFIX}-field-label`;
13
16
  const hasExtra = $derived(Boolean(extra));
17
+ const hasTooltip = $derived(tooltip !== undefined && tooltip !== '');
14
18
  </script>
15
19
 
16
- <label
17
- {...rest}
18
- class={[prefix, rest.class, { [`${prefix}-left`]: align === 'left', [`${prefix}-right`]: align === 'right', [`${prefix}-required`]: required && !optional, [`${prefix}-disabled`]: disabled, [`${prefix}-with-extra`]: hasExtra }]}
19
- for={name || rest.for || undefined}
20
- style={[rest.style, width !== undefined && `width: ${toCssLength(width)}`].filter(Boolean).join(';') || undefined}
21
- >
22
- <div class={`${prefix}-text`} x-semi-prop="label">
23
- {#if children}{@render children()}{:else}{text}{/if}{#if optional}<span class={`${prefix}-optional-text`}>{locale().locale.optional}</span>{/if}
20
+ {#snippet labelView()}
21
+ <label
22
+ {...rest}
23
+ class={[prefix, rest.class, { [`${prefix}-left`]: align === 'left', [`${prefix}-right`]: align === 'right', [`${prefix}-required`]: required && !optional, [`${prefix}-disabled`]: disabled, [`${prefix}-with-extra`]: hasExtra }]}
24
+ for={name || rest.for || undefined}
25
+ style={[rest.style, width !== undefined && !hasTooltip && `width: ${toCssLength(width)}`].filter(Boolean).join(';') || undefined}
26
+ >
27
+ <div class={`${prefix}-text`} x-semi-prop="label">
28
+ {#if children}{@render children()}{:else}{text}{/if}{#if optional}<span class={`${prefix}-optional-text`}>{locale().locale.optional}</span>{/if}
29
+ </div>
30
+ {#if hasExtra}
31
+ <div class={`${prefix}-extra`}>{@render extra?.()}</div>
32
+ {/if}
33
+ </label>
34
+ {/snippet}
35
+
36
+ {#snippet tooltipButton(triggerProps: Partial<TooltipTriggerProps>)}
37
+ <button {...triggerProps} aria-label={locale().locale.labelTooltip} class={`${prefix}-tooltip`} type="button">
38
+ <IconHelpCircle />
39
+ </button>
40
+ {/snippet}
41
+
42
+ {#if hasTooltip}
43
+ <div class={`${prefix}-with-tooltip`} style={width === undefined ? undefined : `width: ${toCssLength(width)}`}>
44
+ {@render labelView()}
45
+ <Tooltip>
46
+ {#snippet child({ props })}{@render tooltipButton(props)}{/snippet}
47
+ {#snippet content()}{#if typeof tooltip === 'function'}{@render tooltip()}{:else}{tooltip}{/if}{/snippet}
48
+ </Tooltip>
24
49
  </div>
25
- {#if hasExtra}
26
- <div class={`${prefix}-extra`}>{@render extra?.()}</div>
27
- {/if}
28
- </label>
50
+ {:else}
51
+ {@render labelView()}
52
+ {/if}
@@ -1,6 +1,5 @@
1
1
  <script lang="ts">
2
- import { untrack } from 'svelte';
3
- import { describeSchemaField, resolveJsonSchema } from '@fibrae/semi-foundation/components/form/json-schema';
2
+ import { describeSchemaField, resolveJsonSchema, schemaFieldWarnings } from '@fibrae/semi-foundation/components/form/json-schema';
4
3
  import { warning } from '@fibrae/semi-foundation/utils';
5
4
  import { useDefaultProps } from '../../../base/index.js';
6
5
  import { getFormContext } from '../context.js';
@@ -8,7 +7,7 @@
8
7
  import SchemaNode from './schema-node.svelte';
9
8
 
10
9
  const defaults = useDefaultProps('SchemaField');
11
- let { field = defaults('field', ''), jsonSchema = defaults('jsonSchema'), widgets = defaults('widgets'), renderField = defaults('renderField') }: SchemaFieldProps = $props();
10
+ let { field = defaults('field', ''), jsonSchema = defaults('jsonSchema'), renderers = defaults('renderers'), renderField = defaults('renderField') }: SchemaFieldProps = $props();
12
11
 
13
12
  const form = getFormContext();
14
13
 
@@ -21,11 +20,10 @@
21
20
  const node = $derived(root && describeSchemaField(root, field));
22
21
 
23
22
  $effect(() => {
24
- const missing = !root;
25
- untrack(() => warning(missing, '[Semi Form] SchemaField has no JSON Schema to render: pass jsonSchema, or give the Form a schema that exports one'));
23
+ warning(!root, schemaFieldWarnings.noSchema);
26
24
  });
27
25
  </script>
28
26
 
29
27
  {#if root && node}
30
- <SchemaNode {node} {renderField} {root} {widgets} />
28
+ <SchemaNode {node} {renderField} {renderers} {root} />
31
29
  {/if}
@@ -5,7 +5,7 @@
5
5
  import SchemaField from './schema-field.svelte';
6
6
 
7
7
  const defaults = useDefaultProps('SchemaForm');
8
- let { jsonSchema = defaults('jsonSchema'), widgets = defaults('widgets'), renderField = defaults('renderField'), children: content, ...rest }: SchemaFormProps<Values, Output> = $props();
8
+ let { jsonSchema = defaults('jsonSchema'), renderers = defaults('renderers'), renderField = defaults('renderField'), children: content, ...rest }: SchemaFormProps<Values, Output> = $props();
9
9
 
10
10
  let form = $state.raw<{ getFormApi: () => FormApi<Values, Output> }>();
11
11
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  <Form bind:this={form} {...rest}>
18
18
  {#snippet children(renderProps)}
19
- <SchemaField {jsonSchema} {renderField} {widgets} />
19
+ <SchemaField {jsonSchema} {renderField} {renderers} />
20
20
  {@render content?.(renderProps)}
21
21
  {/snippet}
22
22
  </Form>