@fibrae/semi-foundation 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/base/index.d.ts +2 -1
  2. package/dist/base/index.js +2 -1
  3. package/dist/base/overlay-session.d.ts +16 -0
  4. package/dist/base/overlay-session.js +36 -0
  5. package/dist/components/audio-player/foundation.js +1 -1
  6. package/dist/components/auto-complete/constants.d.ts +3 -1
  7. package/dist/components/auto-complete/foundation.d.ts +1 -1
  8. package/dist/components/auto-complete/foundation.js +15 -16
  9. package/dist/components/badge/constants.d.ts +3 -1
  10. package/dist/components/button/constants.d.ts +3 -1
  11. package/dist/components/card/constants.d.ts +3 -1
  12. package/dist/components/cascader/constants.d.ts +2 -0
  13. package/dist/components/cascader/foundation.d.ts +2 -4
  14. package/dist/components/cascader/foundation.js +4 -1
  15. package/dist/components/color-picker/foundation.d.ts +2 -0
  16. package/dist/components/color-picker/foundation.js +5 -0
  17. package/dist/components/cropper/constants.d.ts +2 -0
  18. package/dist/components/date-picker/_utils/index.d.ts +1 -2
  19. package/dist/components/date-picker/_utils/index.js +1 -2
  20. package/dist/components/date-picker/_utils/is-timestamp.js +1 -1
  21. package/dist/components/date-picker/_utils/parse-value.js +1 -1
  22. package/dist/components/date-picker/_utils/picker-type.js +1 -1
  23. package/dist/components/date-picker/constants.d.ts +2 -0
  24. package/dist/components/date-picker/foundation.d.ts +3 -4
  25. package/dist/components/date-picker/foundation.js +8 -3
  26. package/dist/components/date-picker/input-foundation.d.ts +1 -0
  27. package/dist/components/date-picker/input-foundation.js +1 -1
  28. package/dist/components/date-picker/month-foundation.d.ts +1 -1
  29. package/dist/components/date-picker/month-foundation.js +1 -0
  30. package/dist/components/date-picker/months-grid-foundation.d.ts +1 -1
  31. package/dist/components/date-picker/months-grid-foundation.js +1 -1
  32. package/dist/components/descriptions/constants.d.ts +3 -1
  33. package/dist/components/dropdown/constants.d.ts +2 -0
  34. package/dist/components/dropdown/menu-foundation.d.ts +1 -1
  35. package/dist/components/empty/constants.d.ts +3 -1
  36. package/dist/components/feedback/constants.d.ts +3 -1
  37. package/dist/components/form/form.css +47 -2
  38. package/dist/components/form/form.scss +44 -2
  39. package/dist/components/form/foundation.d.ts +2 -1
  40. package/dist/components/form/foundation.js +63 -3
  41. package/dist/components/form/interface.d.ts +9 -1
  42. package/dist/components/form/json-schema.d.ts +35 -2
  43. package/dist/components/form/json-schema.js +75 -8
  44. package/dist/components/form/variables.scss +4 -0
  45. package/dist/components/highlight/constants.d.ts +3 -1
  46. package/dist/components/image/constants.d.ts +5 -1
  47. package/dist/components/image/preview-inner-foundation.js +6 -15
  48. package/dist/components/input/constants.d.ts +5 -1
  49. package/dist/components/input-number/constants.d.ts +3 -1
  50. package/dist/components/modal/constants.d.ts +3 -1
  51. package/dist/components/modal/modal-content-foundation.d.ts +3 -3
  52. package/dist/components/modal/modal-content-foundation.js +5 -3
  53. package/dist/components/modal/modal-foundation.d.ts +0 -2
  54. package/dist/components/modal/modal-foundation.js +6 -16
  55. package/dist/components/navigation/constants.d.ts +4 -0
  56. package/dist/components/overflow-list/constants.d.ts +2 -0
  57. package/dist/components/pagination/foundation.d.ts +1 -1
  58. package/dist/components/popconfirm/constants.d.ts +3 -1
  59. package/dist/components/popover/constants.d.ts +2 -0
  60. package/dist/components/radio/constants.d.ts +3 -1
  61. package/dist/components/scroll-list/item-foundation.js +1 -0
  62. package/dist/components/select/constants.d.ts +2 -0
  63. package/dist/components/select/foundation.d.ts +0 -3
  64. package/dist/components/select/foundation.js +31 -56
  65. package/dist/components/select/select.css +3 -3
  66. package/dist/components/select/select.scss +8 -3
  67. package/dist/components/side-sheet/constants.d.ts +2 -0
  68. package/dist/components/side-sheet/side-sheet-foundation.d.ts +6 -4
  69. package/dist/components/side-sheet/side-sheet-foundation.js +33 -23
  70. package/dist/components/slider/constants.d.ts +3 -1
  71. package/dist/components/slider/foundation.d.ts +6 -6
  72. package/dist/components/slider/foundation.js +9 -6
  73. package/dist/components/spin/constants.d.ts +3 -1
  74. package/dist/components/table/constants.d.ts +2 -0
  75. package/dist/components/table/foundation.d.ts +8 -0
  76. package/dist/components/table/foundation.js +12 -0
  77. package/dist/components/table/rtl.scss +5 -0
  78. package/dist/components/table/table.css +123 -0
  79. package/dist/components/table/table.scss +174 -0
  80. package/dist/components/tabs/constants.d.ts +2 -0
  81. package/dist/components/tabs/foundation.js +19 -60
  82. package/dist/components/time-picker/combobox-options.js +1 -1
  83. package/dist/components/time-picker/constants.d.ts +2 -0
  84. package/dist/components/time-picker/foundation.d.ts +3 -1
  85. package/dist/components/time-picker/foundation.js +7 -1
  86. package/dist/components/toast/toast.css +1 -1
  87. package/dist/components/toast/toast.scss +2 -1
  88. package/dist/components/tooltip/constants.d.ts +2 -0
  89. package/dist/components/tooltip/foundation.d.ts +13 -15
  90. package/dist/components/tooltip/foundation.js +54 -15
  91. package/dist/components/tooltip/tooltip.css +1 -1
  92. package/dist/components/tooltip/tooltip.scss +4 -2
  93. package/dist/components/tree/constants.d.ts +2 -0
  94. package/dist/components/tree/foundation.d.ts +17 -3
  95. package/dist/components/tree/foundation.js +37 -2
  96. package/dist/components/tree/shared.d.ts +37 -0
  97. package/dist/components/tree/shared.js +42 -1
  98. package/dist/components/tree-select/constants.d.ts +2 -0
  99. package/dist/components/tree-select/foundation.d.ts +15 -10
  100. package/dist/components/tree-select/foundation.js +44 -7
  101. package/dist/components/upload/constants.d.ts +3 -1
  102. package/dist/components/upload/utils.d.ts +5 -0
  103. package/dist/components/upload/utils.js +8 -2
  104. package/dist/components/video-player/foundation.js +1 -1
  105. package/dist/components/video-player/utils.d.ts +0 -2
  106. package/dist/components/video-player/utils.js +1 -14
  107. package/dist/locale/interface.d.ts +6 -0
  108. package/dist/locale/source/en_US.js +4 -1
  109. package/dist/locale/source/zh_CN.js +4 -1
  110. package/dist/utils/a11y.d.ts +9 -0
  111. package/dist/utils/a11y.js +19 -1
  112. package/dist/utils/date-fns-extra.d.ts +1 -0
  113. package/dist/utils/date-fns-extra.js +4 -1
  114. package/dist/utils/index.d.ts +4 -3
  115. package/dist/utils/index.js +4 -3
  116. package/dist/utils/media.d.ts +2 -0
  117. package/dist/utils/media.js +15 -0
  118. package/dist/utils/scroll-lock.d.ts +4 -3
  119. package/dist/utils/scroll-lock.js +15 -11
  120. package/dist/utils/supports.d.ts +2 -0
  121. package/dist/utils/supports.js +7 -1
  122. package/package.json +2 -2
  123. package/dist/components/date-picker/_utils/is-valid-date.d.ts +0 -1
  124. package/dist/components/date-picker/_utils/is-valid-date.js +0 -5
@@ -1,5 +1,6 @@
1
1
  @use 'semi:theme' as *;
2
2
  @use 'variables' as *;
3
+ @use '../../base/mixin' as *;
3
4
 
4
5
  $form: #{$prefix}-form;
5
6
  $field: #{$prefix}-form-field;
@@ -102,8 +103,8 @@ $rating: #{$prefix}-rating;
102
103
 
103
104
  &-required {
104
105
  .#{$field}-label-text {
105
- &::after {
106
- margin-inline-start: $spacing-form_label_required-marginLeft;
106
+ &::before {
107
+ margin-inline-end: $spacing-form_label_required-marginLeft;
107
108
  font-weight: $font-form_requiredMark-fontWeight;
108
109
  color: $color-form_requiredMark-text-default;
109
110
  content: '*';
@@ -128,6 +129,31 @@ $rating: #{$prefix}-rating;
128
129
  }
129
130
  }
130
131
 
132
+ // The tooltip button sits beside the label element, not in it: a label's content names the control, and a
133
+ // button must not be nested in a label. The width of the label moves to this wrapper to keep columns aligned.
134
+ &-field-label-with-tooltip {
135
+ display: flex;
136
+ flex-shrink: 0;
137
+ align-items: center;
138
+ max-width: 100%;
139
+ padding-inline-end: $spacing-form_label-paddingRight;
140
+
141
+ .#{$field}-label {
142
+ flex: 0 1 auto;
143
+ min-width: 0;
144
+ padding-inline-end: $spacing-form_label_tooltip-marginLeft;
145
+ }
146
+ }
147
+
148
+ &-field-label-tooltip {
149
+ @include bare-button;
150
+ display: inline-flex;
151
+ flex-shrink: 0;
152
+ align-items: center;
153
+ font-size: $width-form_label_tooltip-icon;
154
+ color: $color-form_label_tooltip-icon-default;
155
+ }
156
+
131
157
  &-field-error-message,
132
158
  &-field-help-text {
133
159
  @include font-size-regular;
@@ -287,6 +313,12 @@ $rating: #{$prefix}-rating;
287
313
  border-bottom: $width-form_section-border solid $color-form_section-border-default;
288
314
  }
289
315
 
316
+ &-extra {
317
+ @include font-size-regular;
318
+ margin-bottom: $spacing-form_section_extra-marginBottom;
319
+ color: $color-form_label_extra-text-default;
320
+ }
321
+
290
322
  &:nth-of-type(1) {
291
323
  margin-top: 0;
292
324
  }
@@ -310,3 +342,13 @@ $rating: #{$prefix}-rating;
310
342
  // aligns the buttons with the control of the row's last field, not with the field's bottom padding
311
343
  padding-block-end: $spacing-form_field_vertical-paddingBottom;
312
344
  }
345
+
346
+ // a single-value row has no label: the buttons align with the control's top, so an error message below the control
347
+ // only grows the row downward
348
+ .#{$form}-schema-array-row-single {
349
+ align-items: flex-start;
350
+
351
+ .#{$form}-schema-array-row-actions {
352
+ padding-block: $spacing-form_field_vertical-paddingTop 0;
353
+ }
354
+ }
@@ -65,7 +65,8 @@ export default class FormFoundation<E = unknown> extends BaseFoundation<BaseForm
65
65
  setValues: (values: any, opts?: SetValuesConfig) => void;
66
66
  submitForm: () => void;
67
67
  getFieldExist: (field: string) => boolean;
68
- scrollToField: (field: string, scrollOpts?: Options) => void;
68
+ scrollToField: (field: string, scrollOpts?: Options) => Promise<void>;
69
+ focusField: (field: string, scrollOpts?: Options) => Promise<void>;
69
70
  scrollToError: (opts?: ScrollToErrorOpts) => void;
70
71
  setValue: (field: string, value: any, opts?: CallOpts) => void;
71
72
  setError: (field: string, error: unknown, opts?: CallOpts) => void;
@@ -1,4 +1,5 @@
1
1
  import BaseFoundation from "../../base/foundation.js";
2
+ import FocusTrapHandle from "../../base/focus-handle.js";
2
3
  import isPromise from "../../utils/is-promise.js";
3
4
  import warning from "../../utils/warning.js";
4
5
  import { get as get$1, has as has$1, isEmpty, remove, set as set$1 } from "../../utils/object.js";
@@ -15,6 +16,8 @@ const SILENT = {
15
16
  skipNotify: true,
16
17
  skipRender: true
17
18
  };
19
+ const REVEAL_TIMEOUT = 1e3;
20
+ const HIDDEN_SELECTOR = "[inert], [hidden]";
18
21
  const prefix = cssClasses.PREFIX;
19
22
  const ERROR_SELECTOR = `.${prefix}-field-error-message`;
20
23
  const errorField = (errorDOM) => errorDOM.closest(`.${prefix}-field, .${prefix}-field-group`);
@@ -61,6 +64,7 @@ var FormFoundation = class extends BaseFoundation {
61
64
  #pendingSchemaRun;
62
65
  #latestSchemaRun;
63
66
  #detachedErrorPaths = [];
67
+ #cancelReveal;
64
68
  constructor(adapter) {
65
69
  super(adapter);
66
70
  let { initValues } = this.adapter.getProps();
@@ -959,12 +963,64 @@ var FormFoundation = class extends BaseFoundation {
959
963
  const errorDOM = this.#getFieldDOM(field)?.querySelector(ERROR_SELECTOR);
960
964
  return errorDOM && errorField(errorDOM);
961
965
  }
966
+ /**
967
+ * A field root, or the element a SchemaField renderer gave the `x-field-id` of an array or object node. One inside
968
+ * collapsed content kept in the DOM (Collapsible keepDOM marks it inert) counts as not rendered.
969
+ */
970
+ #findRendered(field) {
971
+ const element = this.adapter.getFormElement()?.querySelector(`[x-field-id="${CSS.escape(field)}"]`);
972
+ return element && !element.closest(HIDDEN_SELECTOR) ? element : null;
973
+ }
974
+ /**
975
+ * Asks the caller to reveal `field` (expand a collapsed card) and resolves with its element once mounted, or null
976
+ * after REVEAL_TIMEOUT; a newer call or unmounting cancels the wait.
977
+ * shortcut: the element is scrolled to as soon as it mounts, so a container still running an expand animation can
978
+ * leave it short of the target; wait for transitionend if callers report that.
979
+ */
980
+ #reveal(field) {
981
+ const formElement = this.adapter.getFormElement();
982
+ if (!formElement) return Promise.resolve(null);
983
+ return new Promise((resolve) => {
984
+ const finish = (element) => {
985
+ observer.disconnect();
986
+ clearTimeout(timer);
987
+ this.#cancelReveal = void 0;
988
+ resolve(element);
989
+ };
990
+ const observer = new MutationObserver(() => {
991
+ const element = this.#findRendered(field);
992
+ if (element) finish(element);
993
+ });
994
+ const timer = setTimeout(() => finish(null), REVEAL_TIMEOUT);
995
+ this.#cancelReveal = () => finish(null);
996
+ observer.observe(formElement, {
997
+ childList: true,
998
+ subtree: true,
999
+ attributes: true,
1000
+ attributeFilter: [
1001
+ "x-field-id",
1002
+ "inert",
1003
+ "hidden"
1004
+ ]
1005
+ });
1006
+ this.adapter.notifyRevealField(field);
1007
+ });
1008
+ }
962
1009
  #scrollToField(field, scrollOpts = {
963
1010
  behavior: "smooth",
964
1011
  block: "start"
965
1012
  }) {
966
- const fieldDOM = this.#getFieldExist(field) ? this.#getFieldDOM(field) : null;
967
- if (fieldDOM) scrollIntoView$1(fieldDOM, scrollOpts);
1013
+ this.#cancelReveal?.();
1014
+ const scroll = (element) => {
1015
+ if (element) scrollIntoView$1(element, scrollOpts);
1016
+ return element;
1017
+ };
1018
+ const found = this.#findRendered(field);
1019
+ return found ? Promise.resolve(scroll(found)) : this.#reveal(field).then(scroll);
1020
+ }
1021
+ async #focusField(field, scrollOpts) {
1022
+ const element = await this.#scrollToField(field, scrollOpts);
1023
+ (element && FocusTrapHandle.getFocusableElements(element).find((candidate) => !candidate.closest(`.${prefix}-field-label, .${prefix}-field-label-with-tooltip`)))?.focus({ preventScroll: true });
968
1024
  }
969
1025
  #scrollToError(config) {
970
1026
  const { field, index, scrollOpts = {
@@ -1004,6 +1060,7 @@ var FormFoundation = class extends BaseFoundation {
1004
1060
  }
1005
1061
  destroy() {
1006
1062
  this.#destroyed = true;
1063
+ this.#cancelReveal?.();
1007
1064
  this.#cancelDebouncedValidation();
1008
1065
  this.#unregistered = [];
1009
1066
  }
@@ -1100,7 +1157,10 @@ var FormFoundation = class extends BaseFoundation {
1100
1157
  setValues: (values, opts) => this.#setValues(values, opts ?? { isOverride: false }),
1101
1158
  submitForm: () => this.submit(),
1102
1159
  getFieldExist: (field) => this.#getFieldExist(field),
1103
- scrollToField: (field, scrollOpts) => this.#scrollToField(field, scrollOpts),
1160
+ scrollToField: async (field, scrollOpts) => {
1161
+ await this.#scrollToField(field, scrollOpts);
1162
+ },
1163
+ focusField: (field, scrollOpts) => this.#focusField(field, scrollOpts),
1104
1164
  scrollToError: (opts) => this.#scrollToError(opts)
1105
1165
  };
1106
1166
  };
@@ -78,6 +78,8 @@ export interface BaseFormAdapter<P = Record<string, any>, Values extends object
78
78
  notifyValueChange: (values: any, changedValues: any) => void;
79
79
  notifyErrorChange: (errors: any, changedError: any) => void;
80
80
  notifyReset: () => void;
81
+ /** scrollToField or focusField found nothing rendered at `field`: the caller expands what hides it */
82
+ notifyRevealField: (field: string) => void;
81
83
  /** The rendered form element; null before mount and after unmount */
82
84
  getFormElement: () => Element | null;
83
85
  }
@@ -150,7 +152,13 @@ export interface BaseFormApi<T extends object = any, O = T> {
150
152
  getInitValues: () => any;
151
153
  getValues: () => T;
152
154
  setValues: (fieldsValue: Partial<T>, config?: SetValuesConfig) => void;
153
- scrollToField: <K extends FieldPath<T>>(field: K, scrollConfig?: Options) => void;
155
+ /**
156
+ * Scrolls to the field, ArrayField container or SchemaField node at `field`. When nothing is rendered there, calls
157
+ * the Form's onRevealField and waits up to a second for it to mount.
158
+ */
159
+ scrollToField: <K extends FieldPath<T>>(field: K, scrollConfig?: Options) => Promise<void>;
160
+ /** scrollToField, then focuses the first focusable element inside, a tooltip trigger in a label excepted */
161
+ focusField: <K extends FieldPath<T>>(field: K, scrollConfig?: Options) => Promise<void>;
154
162
  scrollToError: <K extends FieldPath<T>>(config?: ScrollToErrorOptions<K>) => void;
155
163
  }
156
164
  export interface CallOpts {
@@ -1,3 +1,4 @@
1
+ import { Locale } from "../../locale/interface.js";
1
2
  import { StandardSchema } from "./interface.js";
2
3
  export type JsonSchema = Record<string, any>;
3
4
  export type SchemaFieldKind = 'input' | 'textarea' | 'number' | 'switch' | 'select' | 'object' | 'array' | 'unsupported';
@@ -12,6 +13,14 @@ export interface SchemaFieldNode {
12
13
  /** `title`, else the property name; undefined for an array item */
13
14
  title?: string;
14
15
  description?: string;
16
+ /** Path segments from the schema root: 0 for the root, also when SchemaField starts below it */
17
+ depth: number;
18
+ /** Set on an array item: its row index and the array's title (undefined for an untitled array item) and key */
19
+ item?: {
20
+ index: number;
21
+ arrayTitle?: string;
22
+ arrayKey: string | number;
23
+ };
15
24
  required: boolean;
16
25
  format?: string;
17
26
  default?: unknown;
@@ -38,5 +47,29 @@ export interface SchemaFieldNode {
38
47
  export declare function resolveJsonSchema(jsonSchema?: JsonSchema, schema?: StandardSchema): JsonSchema | undefined;
39
48
  /** The node at `field` ('' = root), walking properties and items; throws when the path is not in the schema */
40
49
  export declare function describeSchemaField(root: JsonSchema, field?: string): SchemaFieldNode;
41
- /** Value of a new array row: object -> {} with required nested objects and arrays prefilled (arrays with minItems blank rows), other -> undefined */
42
- export declare function blankRow(root: JsonSchema, arrayNode: SchemaFieldNode): unknown;
50
+ /**
51
+ * The semiRenderers name of a single-value array row, undefined for any other node. Such a row shows no label or
52
+ * description: the array's Section shows them once, and the row is named "<array title> item N".
53
+ */
54
+ export declare function singleItemName({ item, kind }: SchemaFieldNode, messages: Pick<Locale['Form'], 'item' | 'arrayItem'>): string;
55
+ /** What an array node allows with `count` rows; a fixed array (minItems === maxItems) neither adds nor removes */
56
+ export declare function arrayState(node: SchemaFieldNode, count: number): {
57
+ count: number;
58
+ minItems: number;
59
+ maxItems: number;
60
+ fixed: boolean;
61
+ canAdd: boolean;
62
+ canRemove: boolean;
63
+ };
64
+ /** The props semiRenderers gives the Form control of a leaf node, by kind */
65
+ export declare function controlProps(node: SchemaFieldNode): Record<string, unknown>;
66
+ export declare const schemaFieldWarnings: {
67
+ noSchema: string;
68
+ noRenderer: (field: string, kind: string) => string;
69
+ unsupported: (field: string) => string;
70
+ };
71
+ /**
72
+ * Value of a new row of the array at `arrayField`: object -> {} with required nested objects and arrays prefilled
73
+ * (arrays with minItems blank rows), other -> undefined
74
+ */
75
+ export declare function blankRow(root: JsonSchema, arrayField: string): unknown;
@@ -1,3 +1,4 @@
1
+ import { formatLocale } from "../../locale/format.js";
1
2
  import { toPath } from "es-toolkit/compat";
2
3
  // src/components/form/json-schema.ts
3
4
  const SINGLE_LINE_MAX_LENGTH = 160;
@@ -77,13 +78,15 @@ const bound = (values, pick) => {
77
78
  };
78
79
  const childPath = (field, name) => IDENTIFIER.test(name) ? field ? `${field}.${name}` : name : `${field}[${JSON.stringify(name)}]`;
79
80
  const isRequired = (parent, name) => Array.isArray(parent.required) && parent.required.includes(name);
80
- function buildNode(root, { schema, seen }, field, key, required, fallbackTitle) {
81
+ function buildNode(root, { schema, seen }, field, key, required, fallbackTitle, item) {
81
82
  const base = {
82
83
  field,
83
84
  pattern: field.replaceAll(/\[\d+\]/g, "[]"),
84
85
  key,
85
86
  title: schema.title ?? fallbackTitle,
86
87
  description: schema.description,
88
+ depth: field === "" ? 0 : toPath(field).length,
89
+ item,
87
90
  required,
88
91
  format: schema.format,
89
92
  default: schema.default,
@@ -155,8 +158,15 @@ function buildNode(root, { schema, seen }, field, key, required, fallbackTitle)
155
158
  }
156
159
  /** Explicit wins; otherwise the Form schema's Standard JSON Schema input (target draft-2020-12); undefined when neither exists */
157
160
  function resolveJsonSchema(jsonSchema, schema) {
158
- return jsonSchema ?? schema?.["~standard"].jsonSchema?.input({ target: "draft-2020-12" });
161
+ if (jsonSchema || !schema) return jsonSchema;
162
+ let converted = convertedSchemas.get(schema);
163
+ if (!converted) {
164
+ converted = schema["~standard"].jsonSchema?.input({ target: "draft-2020-12" });
165
+ if (converted) convertedSchemas.set(schema, converted);
166
+ }
167
+ return converted;
159
168
  }
169
+ const convertedSchemas = /* @__PURE__ */ new WeakMap();
160
170
  /** The node at `field` ('' = root), walking properties and items; throws when the path is not in the schema */
161
171
  function describeSchemaField(root, field = "") {
162
172
  const fail = () => /* @__PURE__ */ new Error(`Schema has no field "${field}"`);
@@ -164,16 +174,23 @@ function describeSchemaField(root, field = "") {
164
174
  let key = "";
165
175
  let required = false;
166
176
  let fallbackTitle;
177
+ let item;
167
178
  for (const segment of field === "" ? [] : toPath(field)) {
168
179
  const parent = current.schema;
169
180
  let child;
170
181
  if (parent.type === "array") {
171
182
  if (!/^\d+$/.test(segment)) throw fail();
172
183
  child = parent.items;
173
- key = Number(segment);
184
+ item = {
185
+ index: Number(segment),
186
+ arrayTitle: parent.title ?? fallbackTitle,
187
+ arrayKey: key
188
+ };
189
+ key = item.index;
174
190
  required = false;
175
191
  fallbackTitle = void 0;
176
192
  } else {
193
+ item = void 0;
177
194
  if (parent.type !== "object" || !isObject(parent.properties) || !Object.hasOwn(parent.properties, segment)) throw fail();
178
195
  child = parent.properties[segment];
179
196
  key = segment;
@@ -183,8 +200,55 @@ function describeSchemaField(root, field = "") {
183
200
  if (!isObject(child)) throw fail();
184
201
  current = resolve(root, child, current.seen);
185
202
  }
186
- return buildNode(root, current, field, key, required, fallbackTitle);
203
+ return buildNode(root, current, field, key, required, fallbackTitle, item);
204
+ }
205
+ /**
206
+ * The semiRenderers name of a single-value array row, undefined for any other node. Such a row shows no label or
207
+ * description: the array's Section shows them once, and the row is named "<array title> item N".
208
+ */
209
+ function singleItemName({ item, kind }, messages) {
210
+ if (!item || kind === "object" || kind === "array") return void 0;
211
+ const index = item.index + 1;
212
+ return item.arrayTitle === void 0 ? formatLocale(messages.item, { index }) : formatLocale(messages.arrayItem, {
213
+ title: item.arrayTitle,
214
+ index
215
+ });
216
+ }
217
+ /** What an array node allows with `count` rows; a fixed array (minItems === maxItems) neither adds nor removes */
218
+ function arrayState(node, count) {
219
+ const { minItems, maxItems } = node;
220
+ const fixed = Boolean(node.fixed);
221
+ return {
222
+ count,
223
+ minItems,
224
+ maxItems,
225
+ fixed,
226
+ canAdd: !fixed && (maxItems === void 0 || count < maxItems),
227
+ canRemove: !fixed && count > (minItems ?? 0)
228
+ };
187
229
  }
230
+ /** The props semiRenderers gives the Form control of a leaf node, by kind */
231
+ function controlProps(node) {
232
+ switch (node.kind) {
233
+ case "input": return { maxLength: node.maxLength };
234
+ case "textarea": return { maxCount: node.maxLength };
235
+ case "number": return {
236
+ max: node.maximum,
237
+ min: node.minimum,
238
+ precision: node.integer ? 0 : void 0
239
+ };
240
+ case "select": return {
241
+ multiple: node.multiple,
242
+ optionList: node.options
243
+ };
244
+ default: return {};
245
+ }
246
+ }
247
+ const schemaFieldWarnings = {
248
+ noSchema: "[Semi Form] SchemaField has no JSON Schema: pass jsonSchema, or give the Form a schema that exports one",
249
+ noRenderer: (field, kind) => `[Semi Form] SchemaField renders nothing for "${field}": renderers has no ${kind} entry`,
250
+ unsupported: (field) => `[Semi Form] SchemaField renders nothing for "${field}": its schema maps to no control`
251
+ };
188
252
  function blankValue(root, { schema, seen }) {
189
253
  if (schema.type === "object") {
190
254
  const row = {};
@@ -200,9 +264,12 @@ function blankValue(root, { schema, seen }) {
200
264
  return Array.from({ length: schema.minItems ?? 0 }, () => items && blankValue(root, items));
201
265
  }
202
266
  }
203
- /** Value of a new array row: object -> {} with required nested objects and arrays prefilled (arrays with minItems blank rows), other -> undefined */
204
- function blankRow(root, arrayNode) {
205
- const { items } = arrayNode.schema;
267
+ /**
268
+ * Value of a new row of the array at `arrayField`: object -> {} with required nested objects and arrays prefilled
269
+ * (arrays with minItems blank rows), other -> undefined
270
+ */
271
+ function blankRow(root, arrayField) {
272
+ const { items } = describeSchemaField(root, arrayField).schema;
206
273
  return isObject(items) ? blankValue(root, resolve(root, items, [])) : void 0;
207
274
  }
208
- export { blankRow, describeSchemaField, resolveJsonSchema };
275
+ export { arrayState, blankRow, controlProps, describeSchemaField, resolveJsonSchema, schemaFieldWarnings, singleItemName };
@@ -32,6 +32,9 @@ $font-form_label-fontWeight: $font-weight-bold; // 表单项标签字重
32
32
  $color-form_label-text-default: var(--semi-color-text-0); // 表单项标签文字颜色
33
33
  $color-form_label_optional-text-default: var(--semi-color-tertiary); // 表单项标签可选标记颜色
34
34
  $color-form_label_extra-text-default: var(--semi-color-tertiary); // 表单项标签图标颜色
35
+ $color-form_label_tooltip-icon-default: var(--semi-color-tertiary); // 表单项标签提示图标颜色
36
+ $spacing-form_label_tooltip-marginLeft: $spacing-extra-tight; // 表单项标签与提示图标的间距
37
+ $width-form_label_tooltip-icon: $width-icon-small; // 表单项标签提示图标大小
35
38
  $color-form_requiredMark-text-default: var(--semi-color-danger); // 必填标记颜色
36
39
  $font-form_requiredMark-fontWeight: $font-weight-bold; // 表单必填标识字重
37
40
 
@@ -48,5 +51,6 @@ $spacing-form_section_text-paddingBottom: $spacing-tight; // 表单分组标题
48
51
  $spacing-form_section_text-marginBottom: $spacing-extra-tight; // 表单分组标题底部外边距
49
52
  $spacing-form_section_text-paddingTop: 0px; // 表单分组标题顶部内边距
50
53
  $spacing-form_section_text-marginTop: 0px; // 表单分组标题顶部外边距
54
+ $spacing-form_section_extra-marginBottom: $spacing-extra-tight; // 表单分组说明文字底部外边距
51
55
  $spacing-form_schema_array_row-gap: $spacing-tight; // SchemaField 数组行内容与操作按钮的间距
52
56
  $spacing-form_schema_array_row_actions-gap: $spacing-extra-tight; // SchemaField 数组行操作按钮之间的间距
@@ -1,3 +1,5 @@
1
1
  export declare const cssClasses: {
2
2
  readonly PREFIX: "semi-highlight";
3
- };
3
+ };
4
+ /** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
5
+ export type HighlightPart = 'highlight';
@@ -3,4 +3,8 @@ export declare const cssClasses: {
3
3
  };
4
4
  export declare const numbers: {
5
5
  DEFAULT_Z_INDEX: number;
6
- };
6
+ };
7
+ /** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
8
+ export type ImagePart = 'img';
9
+ /** Keys of `classNames` and `styles` of an image preview; the group root takes `className` and `style` */
10
+ export type ImagePreviewPart = 'preview';
@@ -1,6 +1,7 @@
1
1
  import FocusTrapHandle from "../../base/focus-handle.js";
2
2
  import BaseFoundation from "../../base/foundation.js";
3
3
  import ModalResources from "../../base/modal-resources.js";
4
+ import OverlaySession from "../../base/overlay-session.js";
4
5
  import { handlePrevent } from "../../utils/a11y.js";
5
6
  import { coversPage, resolvePopupContainer } from "../../utils/dom.js";
6
7
  import "../../utils/key-code.js";
@@ -21,8 +22,7 @@ var PreviewInnerFoundation = class PreviewInnerFoundation extends BaseFoundation
21
22
  y: 0
22
23
  };
23
24
  #resources = new ModalResources();
24
- #shown = false;
25
- #resume = false;
25
+ #session = new OverlaySession();
26
26
  static propKeys = ["src", "currentIndex"];
27
27
  static propEquals = { src: isEqual };
28
28
  #getImgSrc() {
@@ -52,7 +52,6 @@ var PreviewInnerFoundation = class PreviewInnerFoundation extends BaseFoundation
52
52
  return true;
53
53
  };
54
54
  #release() {
55
- this.#shown = false;
56
55
  window.removeEventListener("keydown", this.handleKeyDown);
57
56
  this.#resources.release();
58
57
  this.#clearTimer();
@@ -129,8 +128,7 @@ var PreviewInnerFoundation = class PreviewInnerFoundation extends BaseFoundation
129
128
  }
130
129
  /** Hosts call this once the dialog is in the document and displayed, after `recordFocus` */
131
130
  beforeShow = () => {
132
- if (this.#shown) return;
133
- this.#shown = true;
131
+ if (!this.#session.begin()) return;
134
132
  window.addEventListener("keydown", this.handleKeyDown);
135
133
  const wrap = this.adapter.getWrap();
136
134
  if (wrap && !wrap.contains(FocusTrapHandle.getActiveElement(wrap))) FocusTrapHandle.findAutofocus(wrap)?.focus({ preventScroll: true });
@@ -146,8 +144,7 @@ var PreviewInnerFoundation = class PreviewInnerFoundation extends BaseFoundation
146
144
  this.updateTimer();
147
145
  };
148
146
  afterHide = () => {
149
- this.#resume = false;
150
- if (!this.#shown) return;
147
+ if (!this.#session.end()) return;
151
148
  this.#release();
152
149
  this.setState({
153
150
  controlsVisible: true,
@@ -168,17 +165,11 @@ var PreviewInnerFoundation = class PreviewInnerFoundation extends BaseFoundation
168
165
  if (!isEqual(prev.src, this.getProp("src"))) this.updateTimer();
169
166
  }
170
167
  init() {
171
- if (this.#resume) {
172
- this.#resume = false;
173
- this.beforeShow();
174
- }
168
+ if (this.#session.resume()) this.beforeShow();
175
169
  }
176
170
  destroy() {
177
171
  this.#mouseMoveHandler.cancel();
178
- if (this.#shown) {
179
- this.#release();
180
- this.#resume = true;
181
- }
172
+ if (this.#session.suspend()) this.#release();
182
173
  }
183
174
  handleMouseMove = (e) => {
184
175
  this.#mouseMoveHandler(e);
@@ -5,4 +5,8 @@ export declare const strings: {
5
5
  readonly SIZE: readonly ["small", "large", "default"];
6
6
  readonly DEFAULT_SIZE: "default";
7
7
  };
8
- export declare const numbers: {};
8
+ export declare const numbers: {};
9
+ /** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
10
+ export type InputPart = 'input';
11
+ /** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
12
+ export type TextAreaPart = 'textarea' | 'lineNumber';
@@ -11,4 +11,6 @@ export declare const numbers: {
11
11
  export declare const strings: {
12
12
  SIZE: readonly ["small", "large", "default"];
13
13
  DEFAULT_SIZE: "default";
14
- };
14
+ };
15
+ /** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
16
+ export type InputNumberPart = 'input';
@@ -1,3 +1,5 @@
1
1
  export declare const cssClasses: {
2
2
  DIALOG: string;
3
- };
3
+ };
4
+ /** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
5
+ export type ModalPart = 'mask' | 'content' | 'header' | 'body' | 'footer';
@@ -26,9 +26,9 @@ export default class ModalContentFoundation<P extends ModalContentProps = ModalC
26
26
  /** Remembers the element to return focus to; hosts call it on opening, before anything inside the dialog takes focus */
27
27
  recordFocus: () => void;
28
28
  /** Called when the dialog is shown: joins the overlay stack and moves focus into the dialog (Modal holds the scroll lock) */
29
- show: () => void;
30
- /** The reverse of `show`; the focus returns to the element recorded on opening */
31
- hide: () => void;
29
+ beforeShow: () => void;
30
+ /** The reverse of `beforeShow`; the focus returns to the element recorded on opening */
31
+ afterHide: () => void;
32
32
  /** Returns focus again, for a host whose framework refocuses the previously focused element after the close */
33
33
  restoreFocus: () => void;
34
34
  handleDialogMouseDown: () => void;
@@ -1,6 +1,7 @@
1
1
  import FocusTrapHandle from "../../base/focus-handle.js";
2
2
  import BaseFoundation from "../../base/foundation.js";
3
3
  import ModalResources from "../../base/modal-resources.js";
4
+ import { warnIfDialogUnnamed } from "../../utils/a11y.js";
4
5
  import { cssClasses } from "./constants.js";
5
6
  // src/components/modal/modal-content-foundation.ts
6
7
  function isModal({ mask, maskFixed, inBody }) {
@@ -21,7 +22,7 @@ var ModalContentFoundation = class extends BaseFoundation {
21
22
  this.#resources.record();
22
23
  };
23
24
  /** Called when the dialog is shown: joins the overlay stack and moves focus into the dialog (Modal holds the scroll lock) */
24
- show = () => {
25
+ beforeShow = () => {
25
26
  const dialog = this.adapter.getDialog();
26
27
  if (!dialog) return;
27
28
  const { preventScroll, initialFocus } = this.getProps();
@@ -43,9 +44,10 @@ var ModalContentFoundation = class extends BaseFoundation {
43
44
  focus: dialog,
44
45
  preventScroll
45
46
  });
47
+ warnIfDialogUnnamed(dialog, "Modal");
46
48
  };
47
- /** The reverse of `show`; the focus returns to the element recorded on opening */
48
- hide = () => {
49
+ /** The reverse of `beforeShow`; the focus returns to the element recorded on opening */
50
+ afterHide = () => {
49
51
  clearTimeout(this.#mouseUpTimer);
50
52
  this.#dialogMouseDown = false;
51
53
  this.adapter.getDialog()?.blur();
@@ -16,7 +16,6 @@ export interface ModalAdapter<P extends ModalProps = ModalProps, CE = unknown, O
16
16
  }
17
17
  export interface ModalProps {
18
18
  afterClose?: () => void;
19
- bodyStyle?: Record<string, any>;
20
19
  cancelButtonProps?: any;
21
20
  cancelText?: string;
22
21
  centered?: boolean;
@@ -32,7 +31,6 @@ export interface ModalProps {
32
31
  height?: string | number;
33
32
  mask?: boolean;
34
33
  maskClosable?: boolean;
35
- maskStyle?: Record<string, any>;
36
34
  maskFixed?: boolean;
37
35
  motion?: boolean;
38
36
  okButtonProps?: any;
@@ -1,5 +1,6 @@
1
1
  import BaseFoundation from "../../base/foundation.js";
2
2
  import ModalResources from "../../base/modal-resources.js";
3
+ import OverlaySession from "../../base/overlay-session.js";
3
4
  import PopupLifecycle from "../../base/popup-lifecycle.js";
4
5
  import { coversPage, resolvePopupContainer } from "../../utils/dom.js";
5
6
  import isPromise from "../../utils/is-promise.js";
@@ -9,8 +10,7 @@ import { debounce } from "es-toolkit";
9
10
  var ModalFoundation = class extends BaseFoundation {
10
11
  #lastCancelTarget = null;
11
12
  #lastOkTarget = null;
12
- #shown = false;
13
- #resume = false;
13
+ #session = new OverlaySession();
14
14
  #lifecycle = new PopupLifecycle();
15
15
  #resources = new ModalResources();
16
16
  constructor(adapter) {
@@ -60,18 +60,12 @@ var ModalFoundation = class extends BaseFoundation {
60
60
  return hasCancel && cancelButtonProps?.autoFocus !== false ? "cancel" : void 0;
61
61
  }
62
62
  init() {
63
- if (this.#resume) {
64
- this.#resume = false;
65
- this.beforeShow();
66
- }
63
+ if (this.#session.resume()) this.beforeShow();
67
64
  }
68
65
  destroy() {
69
66
  this.#debouncedOk.cancel();
70
67
  this.#debouncedCancel.cancel();
71
- if (this.#shown) {
72
- this.afterHide();
73
- this.#resume = true;
74
- }
68
+ if (this.#session.suspend()) this.#resources.release();
75
69
  }
76
70
  handleCancel = (e) => {
77
71
  if (!this.getProp("visible")) return;
@@ -87,8 +81,7 @@ var ModalFoundation = class extends BaseFoundation {
87
81
  this.#debouncedOk(e);
88
82
  };
89
83
  beforeShow = () => {
90
- if (this.#shown) return;
91
- this.#shown = true;
84
+ if (!this.#session.begin()) return;
92
85
  this.#lifecycle.show();
93
86
  const { mask, maskFixed, getPopupContainer } = this.getProps();
94
87
  const container = resolvePopupContainer(getPopupContainer ?? this.getContext("getPopupContainer"));
@@ -100,10 +93,7 @@ var ModalFoundation = class extends BaseFoundation {
100
93
  }) });
101
94
  };
102
95
  afterHide = () => {
103
- this.#resume = false;
104
- if (!this.#shown) return;
105
- this.#shown = false;
106
- this.#resources.release();
96
+ if (this.#session.end()) this.#resources.release();
107
97
  };
108
98
  /**
109
99
  * Hosts call this when the wrap is hidden (the leave animation ended) and when the modal unmounts for good: