@rockshin/tao-ui 0.0.48 → 0.0.51

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 (147) hide show
  1. package/dist/components/affix/affix.js +20 -16
  2. package/dist/components/alert/alert.js +114 -99
  3. package/dist/components/app/app-modals.js +134 -96
  4. package/dist/components/app/app-notices.js +39 -23
  5. package/dist/components/auto-complete/auto-complete.js +21 -7
  6. package/dist/components/avatar/avatar.js +31 -11
  7. package/dist/components/badge/badge.css +1 -1
  8. package/dist/components/badge/badge.js +72 -257
  9. package/dist/components/border-beam/border-beam.js +21 -17
  10. package/dist/components/breadcrumb/breadcrumb.js +178 -159
  11. package/dist/components/button/button.css +9 -1
  12. package/dist/components/button/button.js +61 -53
  13. package/dist/components/calendar/calendar.js +6 -4
  14. package/dist/components/card/card.js +24 -8
  15. package/dist/components/carousel/carousel.d.ts +1 -1
  16. package/dist/components/carousel/carousel.js +105 -68
  17. package/dist/components/cascader/cascader.js +54 -19
  18. package/dist/components/checkbox/checkbox.css +13 -2
  19. package/dist/components/checkbox/checkbox.d.ts +2 -0
  20. package/dist/components/checkbox/checkbox.js +320 -229
  21. package/dist/components/collapse/collapse-panels.d.ts +1 -1
  22. package/dist/components/collapse/collapse-panels.js +122 -113
  23. package/dist/components/collapse/collapse.js +98 -63
  24. package/dist/components/color-picker/color-picker.js +539 -441
  25. package/dist/components/color-picker/color.js +1 -1
  26. package/dist/components/context-menu/context-menu.d.ts +1 -1
  27. package/dist/components/context-menu/context-menu.js +108 -68
  28. package/dist/components/date-picker/calendar/calendar-grid.js +42 -39
  29. package/dist/components/date-picker/calendar/month-grid.d.ts +8 -1
  30. package/dist/components/date-picker/calendar/month-grid.js +79 -37
  31. package/dist/components/date-picker/calendar/time-panel.d.ts +2 -1
  32. package/dist/components/date-picker/calendar/time-panel.js +94 -89
  33. package/dist/components/date-picker/calendar/year-grid.d.ts +8 -1
  34. package/dist/components/date-picker/calendar/year-grid.js +66 -35
  35. package/dist/components/date-picker/date-picker.css +24 -1
  36. package/dist/components/date-picker/date-picker.js +99 -53
  37. package/dist/components/date-picker/presets.d.ts +2 -1
  38. package/dist/components/date-picker/presets.js +27 -24
  39. package/dist/components/date-picker/range-picker.js +308 -153
  40. package/dist/components/descriptions/descriptions.js +7 -3
  41. package/dist/components/divider/divider.css +1 -1
  42. package/dist/components/divider/divider.js +1 -1
  43. package/dist/components/drawer/drawer.js +201 -369
  44. package/dist/components/dropdown/dropdown.d.ts +1 -1
  45. package/dist/components/dropdown/dropdown.js +183 -279
  46. package/dist/components/empty/empty.js +57 -78
  47. package/dist/components/float-button/float-button.d.ts +1 -0
  48. package/dist/components/float-button/float-button.js +47 -30
  49. package/dist/components/form/field-control.d.ts +4 -2
  50. package/dist/components/form/field-control.js +17 -9
  51. package/dist/components/form/form-context.d.ts +8 -2
  52. package/dist/components/form/form-context.js +2 -1
  53. package/dist/components/form/form-item.js +85 -63
  54. package/dist/components/form/use-form.d.ts +2 -1
  55. package/dist/components/form/use-form.js +2 -1
  56. package/dist/components/form-field/form-field-view.d.ts +3 -1
  57. package/dist/components/form-field/form-field-view.js +194 -141
  58. package/dist/components/form-section/form-section.d.ts +1 -1
  59. package/dist/components/form-section/form-section.js +52 -45
  60. package/dist/components/image/image.js +585 -477
  61. package/dist/components/input/base-input.js +8 -9
  62. package/dist/components/input/input-shared.d.ts +5 -2
  63. package/dist/components/input/input-shared.js +42 -18
  64. package/dist/components/input/input.css +1 -0
  65. package/dist/components/input/otp.js +236 -217
  66. package/dist/components/input/password.js +2 -1
  67. package/dist/components/input/search.js +8 -7
  68. package/dist/components/list/list-pagination.js +41 -36
  69. package/dist/components/list/list.js +141 -125
  70. package/dist/components/listy/listy.js +175 -106
  71. package/dist/components/masonry/masonry.js +108 -85
  72. package/dist/components/mentions/mentions.js +12 -3
  73. package/dist/components/menu/menu-render.d.ts +9 -3
  74. package/dist/components/menu/menu-render.js +99 -36
  75. package/dist/components/modal/confirm-dialog.js +10 -4
  76. package/dist/components/modal/confirm.js +3 -7
  77. package/dist/components/modal/index.js +9 -3
  78. package/dist/components/modal/modal.js +390 -365
  79. package/dist/components/pagination/pagination.js +105 -96
  80. package/dist/components/popconfirm/popconfirm.d.ts +1 -1
  81. package/dist/components/popconfirm/popconfirm.js +219 -168
  82. package/dist/components/popover/popover.js +330 -243
  83. package/dist/components/progress/progress.css +2 -2
  84. package/dist/components/progress/progress.js +232 -458
  85. package/dist/components/qr-code/qr-code.js +72 -66
  86. package/dist/components/radio/radio.css +15 -4
  87. package/dist/components/radio/radio.d.ts +2 -1
  88. package/dist/components/radio/radio.js +260 -198
  89. package/dist/components/rate/rate.js +173 -113
  90. package/dist/components/scroll-area/scroll-area.js +241 -211
  91. package/dist/components/segmented/segmented.js +73 -41
  92. package/dist/components/select/mobile-select.d.ts +2 -1
  93. package/dist/components/select/mobile-select.js +24 -13
  94. package/dist/components/select/select-searchable-list.d.ts +2 -1
  95. package/dist/components/select/select-searchable-list.js +2 -3
  96. package/dist/components/select/select.css +3 -2
  97. package/dist/components/select/select.js +49 -25
  98. package/dist/components/select/use-select-selection.d.ts +1 -1
  99. package/dist/components/select/use-select-selection.js +7 -4
  100. package/dist/components/skeleton/skeleton.js +56 -48
  101. package/dist/components/slider/slider.js +87 -212
  102. package/dist/components/sonner/sonner.js +109 -93
  103. package/dist/components/spinner/spinner.js +147 -138
  104. package/dist/components/splitter/splitter.js +222 -159
  105. package/dist/components/statistic/statistic.js +7 -6
  106. package/dist/components/steps/steps.js +88 -81
  107. package/dist/components/steps/use-display-steps.js +1 -1
  108. package/dist/components/switch/switch.js +89 -89
  109. package/dist/components/table/table-filter.js +66 -56
  110. package/dist/components/table/table-icons.d.ts +2 -1
  111. package/dist/components/table/table-icons.js +11 -9
  112. package/dist/components/table/table-model.js +1 -1
  113. package/dist/components/table/table.js +107 -83
  114. package/dist/components/table/use-table-data.d.ts +6 -3
  115. package/dist/components/table/use-table-data.js +166 -130
  116. package/dist/components/tabs/tabs.css +1 -1
  117. package/dist/components/tabs/tabs.js +236 -179
  118. package/dist/components/tag/tag.d.ts +2 -2
  119. package/dist/components/tag/tag.js +111 -108
  120. package/dist/components/textarea/textarea.js +22 -17
  121. package/dist/components/time-picker/time-picker.js +5 -3
  122. package/dist/components/timeline/timeline.css +6 -1
  123. package/dist/components/timeline/timeline.js +21 -11
  124. package/dist/components/tooltip/tooltip.d.ts +2 -2
  125. package/dist/components/tooltip/tooltip.js +123 -233
  126. package/dist/components/tour/tour.css +4 -0
  127. package/dist/components/tour/tour.js +400 -331
  128. package/dist/components/transfer/transfer-list.js +31 -12
  129. package/dist/components/transfer/transfer-parts.js +1 -1
  130. package/dist/components/transfer/transfer-types.d.ts +1 -0
  131. package/dist/components/transfer/transfer.css +5 -0
  132. package/dist/components/transfer/transfer.js +29 -14
  133. package/dist/components/tree/tree-keyboard.d.ts +1 -1
  134. package/dist/components/tree/tree-keyboard.js +5 -3
  135. package/dist/components/tree/tree.js +74 -59
  136. package/dist/components/tree-select/select-engine.d.ts +3 -2
  137. package/dist/components/tree-select/select-engine.js +18 -16
  138. package/dist/components/tree-select/tree-select.js +21 -5
  139. package/dist/components/upload/upload.css +8 -0
  140. package/dist/components/upload/upload.js +160 -72
  141. package/dist/components/watermark/watermark.js +36 -29
  142. package/dist/number-input/use-number-input.js +129 -90
  143. package/dist/number-input/validate.js +32 -5
  144. package/dist/provider/merge-locale.js +12 -9
  145. package/dist/provider/tao-provider.d.ts +3 -1
  146. package/dist/provider/tao-provider.js +123 -86
  147. package/package.json +4 -3
@@ -1,4 +1,4 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
3
  import { TaoPortalScope, useTaoConfig } from "../../provider/tao-provider.js";
4
4
  import { cx } from "../../utils/semantic.js";
@@ -32,7 +32,7 @@ function clearRuntimeTimers(runtime) {
32
32
  }
33
33
  function beginExit(id) {
34
34
  const runtime = runtimes.get(id);
35
- if (!runtime || !state.toasts.some((toast)=>toast.id === id)) return;
35
+ if (!runtime || !state.toasts.some((toast)=>toast.id === id && 'active' === toast.phase)) return;
36
36
  clearRuntimeTimers(runtime);
37
37
  state = {
38
38
  toasts: state.toasts.map((toast)=>toast.id === id ? {
@@ -53,21 +53,21 @@ function beginExit(id) {
53
53
  }, REMOVE_DELAY);
54
54
  }
55
55
  function dismiss(id) {
56
- if (id) return void beginExit(id);
56
+ if (void 0 !== id) return void beginExit(id);
57
57
  for (const toast of state.toasts)beginExit(toast.id);
58
58
  }
59
59
  function scheduleDismiss(id, duration) {
60
60
  const runtime = runtimes.get(id);
61
61
  if (!runtime) return;
62
62
  if (runtime.dismissTimer) clearTimeout(runtime.dismissTimer);
63
- if (null == duration || duration <= 0) return;
63
+ if (null == duration || !Number.isFinite(duration) || duration <= 0) return;
64
64
  const generation = runtime.generation;
65
65
  runtime.dismissTimer = setTimeout(()=>{
66
66
  if (runtimes.get(id)?.generation === generation) beginExit(id);
67
67
  }, duration);
68
68
  }
69
69
  function isToastOptions(value) {
70
- return null != value && 'object' == typeof value && !Array.isArray(value) && !('$$typeof' in value);
70
+ return null != value && 'object' == typeof value && !(Symbol.iterator in value) && !('$$typeof' in value);
71
71
  }
72
72
  function normalizeOptions(options) {
73
73
  return isToastOptions(options) ? options : {
@@ -101,9 +101,18 @@ function create(type, options, custom) {
101
101
  scheduleDismiss(id, normalized.duration);
102
102
  return id;
103
103
  }
104
- function settlePromiseToast(id, generation, type, options) {
105
- if (runtimes.get(id)?.generation !== generation || !state.toasts.some((toast)=>toast.id === id && 'active' === toast.phase)) return;
106
- if (!options) return void dismiss(id);
104
+ function settlePromiseToast(id, generation, type, renderOptions) {
105
+ const isActive = ()=>runtimes.get(id)?.generation === generation && state.toasts.some((toast)=>toast.id === id && 'active' === toast.phase);
106
+ if (!isActive()) return;
107
+ let options;
108
+ try {
109
+ options = renderOptions();
110
+ } catch (error) {
111
+ if (isActive()) dismiss(id);
112
+ throw error;
113
+ }
114
+ if (!isActive()) return;
115
+ if (!options && 0 !== options) return void dismiss(id);
107
116
  const normalized = normalizeOptions(options);
108
117
  create(type, {
109
118
  ...normalized,
@@ -133,7 +142,7 @@ function getAriaLabel(type, messages) {
133
142
  }
134
143
  }
135
144
  function renderPromiseState(stateValue, payload) {
136
- if (!stateValue) return;
145
+ if (!stateValue && 0 !== stateValue) return;
137
146
  if ('function' == typeof stateValue) return stateValue(payload);
138
147
  return stateValue;
139
148
  }
@@ -150,11 +159,9 @@ function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap
150
159
  snapshot.toasts
151
160
  ]);
152
161
  const visible = useMemo(()=>{
153
- const toasts = snapshot.toasts;
154
- const sliced = expand ? toasts : toasts.slice(-visibleToasts);
155
- return sliced.slice(-visibleToasts).reverse();
162
+ const count = Math.floor(visibleToasts);
163
+ return count > 0 ? snapshot.toasts.slice(-count).reverse() : [];
156
164
  }, [
157
- expand,
158
165
  snapshot.toasts,
159
166
  visibleToasts
160
167
  ]);
@@ -198,14 +205,14 @@ function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap
198
205
  function ToastView({ toast, richColors, showClose, yPosition, index, visibleToasts, expanded, offset, frontToastHeight, setHeights, classNames, styles }) {
199
206
  const { locale: { messages } } = useTaoConfig();
200
207
  const [mounted, setMounted] = useState(false);
201
- const [offsetBeforeRemove, setOffsetBeforeRemove] = useState(0);
208
+ const offsetBeforeRemove = useRef(offset);
202
209
  const ref = useRef(null);
203
210
  useEffect(()=>{
204
211
  const frame = requestAnimationFrame(()=>setMounted(true));
205
212
  return ()=>cancelAnimationFrame(frame);
206
213
  }, []);
207
- useEffect(()=>{
208
- if ('exiting' === toast.phase) setOffsetBeforeRemove(offset);
214
+ useLayoutEffect(()=>{
215
+ if ('active' === toast.phase) offsetBeforeRemove.current = offset;
209
216
  }, [
210
217
  offset,
211
218
  toast.phase
@@ -213,14 +220,23 @@ function ToastView({ toast, richColors, showClose, yPosition, index, visibleToas
213
220
  useLayoutEffect(()=>{
214
221
  const node = ref.current;
215
222
  if (!node) return;
216
- const nextHeight = node.getBoundingClientRect().height;
217
- setHeights((current)=>{
218
- if (current.get(toast.id) === nextHeight) return current;
219
- const next = new Map(current);
220
- next.set(toast.id, nextHeight);
221
- return next;
223
+ const updateHeight = (nextHeight)=>{
224
+ setHeights((current)=>{
225
+ if (current.get(toast.id) === nextHeight) return current;
226
+ const next = new Map(current);
227
+ next.set(toast.id, nextHeight);
228
+ return next;
229
+ });
230
+ };
231
+ updateHeight(node.getBoundingClientRect().height);
232
+ const observer = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(([entry])=>{
233
+ updateHeight(entry.borderBoxSize?.[0]?.blockSize ?? node.getBoundingClientRect().height);
234
+ });
235
+ observer?.observe(node, {
236
+ box: 'border-box'
222
237
  });
223
238
  return ()=>{
239
+ observer?.disconnect();
224
240
  setHeights((current_0)=>{
225
241
  if (!current_0.has(toast.id)) return current_0;
226
242
  const next_0 = new Map(current_0);
@@ -239,8 +255,14 @@ function ToastView({ toast, richColors, showClose, yPosition, index, visibleToas
239
255
  ]);
240
256
  const isFront = 0 === index;
241
257
  const isVisible = index < visibleToasts;
242
- const activeOffset = 'exiting' === toast.phase ? offsetBeforeRemove : offset;
243
- return /*#__PURE__*/ jsx("div", {
258
+ const exiting = 'exiting' === toast.phase;
259
+ const activeOffset = exiting ? offsetBeforeRemove.current : offset;
260
+ function dismissAfterAction(action) {
261
+ if (exiting || !state.toasts.includes(toast)) return;
262
+ action?.onClick?.();
263
+ if (state.toasts.includes(toast)) dismiss(toast.id);
264
+ }
265
+ return /*#__PURE__*/ jsxs("div", {
244
266
  ref: ref,
245
267
  className: cx(classNames?.toast),
246
268
  role: "status",
@@ -250,7 +272,7 @@ function ToastView({ toast, richColors, showClose, yPosition, index, visibleToas
250
272
  "data-tao-type": resolveDataType(toast.type, richColors),
251
273
  "data-tao-mounted": mounted,
252
274
  "data-tao-y-position": yPosition,
253
- "data-tao-removing": 'exiting' === toast.phase ? 'true' : 'false',
275
+ "data-tao-removing": exiting ? 'true' : 'false',
254
276
  "data-tao-front": isFront ? 'true' : 'false',
255
277
  "data-tao-expanded": expanded ? 'true' : 'false',
256
278
  "data-tao-visible": isVisible ? 'true' : 'false',
@@ -261,68 +283,63 @@ function ToastView({ toast, richColors, showClose, yPosition, index, visibleToas
261
283
  ['--tao-sonner-front-height']: `${frontToastHeight}px`,
262
284
  ['--tao-sonner-z-index']: String(visibleToasts - index)
263
285
  },
264
- children: toast.custom ? toast.custom : /*#__PURE__*/ jsxs(Fragment, {
265
- children: [
266
- /*#__PURE__*/ jsxs("div", {
267
- className: cx(classNames?.content),
268
- style: styles?.content,
269
- "data-tao-sonner-content": "",
270
- children: [
271
- toast.title ? /*#__PURE__*/ jsx("div", {
272
- className: cx(classNames?.title),
273
- style: styles?.title,
274
- "data-tao-sonner-title": "",
275
- children: toast.title
276
- }) : null,
277
- toast.description ? /*#__PURE__*/ jsx("div", {
278
- className: cx(classNames?.description),
279
- style: styles?.description,
280
- "data-tao-sonner-description": "",
281
- children: toast.description
282
- }) : null
283
- ]
284
- }),
285
- (toast.action || toast.cancel || showClose) && /*#__PURE__*/ jsxs("div", {
286
- className: cx(classNames?.actions),
287
- style: styles?.actions,
288
- "data-tao-sonner-actions": "",
289
- "data-tao-close-only": toast.action || toast.cancel || !showClose ? void 0 : '',
290
- children: [
291
- toast.cancel ? /*#__PURE__*/ jsx(Button, {
292
- variant: "ghost",
293
- size: "small",
294
- className: cx(classNames?.cancel),
295
- style: styles?.cancel,
296
- onClick: ()=>{
297
- toast.cancel?.onClick?.();
298
- dismiss(toast.id);
299
- },
300
- children: toast.cancel.label
301
- }) : null,
302
- toast.action ? /*#__PURE__*/ jsx(Button, {
303
- variant: "secondary",
304
- size: "small",
305
- className: cx(classNames?.action),
306
- style: styles?.action,
307
- onClick: ()=>{
308
- toast.action?.onClick?.();
309
- dismiss(toast.id);
310
- },
311
- children: toast.action.label
312
- }) : null,
313
- showClose ? /*#__PURE__*/ jsx("button", {
314
- type: "button",
315
- "aria-label": messages.closeNotification,
316
- className: cx(classNames?.close),
317
- style: styles?.close,
318
- "data-tao-sonner-close": "",
319
- onClick: ()=>dismiss(toast.id),
320
- children: "\xd7"
321
- }) : null
322
- ]
323
- })
324
- ]
325
- })
286
+ children: [
287
+ toast.custom || 0 === toast.custom ? toast.custom : /*#__PURE__*/ jsxs("div", {
288
+ className: cx(classNames?.content),
289
+ style: styles?.content,
290
+ "data-tao-sonner-content": "",
291
+ children: [
292
+ toast.title || 0 === toast.title ? /*#__PURE__*/ jsx("div", {
293
+ className: cx(classNames?.title),
294
+ style: styles?.title,
295
+ "data-tao-sonner-title": "",
296
+ children: toast.title
297
+ }) : null,
298
+ toast.description || 0 === toast.description ? /*#__PURE__*/ jsx("div", {
299
+ className: cx(classNames?.description),
300
+ style: styles?.description,
301
+ "data-tao-sonner-description": "",
302
+ children: toast.description
303
+ }) : null
304
+ ]
305
+ }),
306
+ (toast.action || toast.cancel || showClose) && /*#__PURE__*/ jsxs("div", {
307
+ className: cx(classNames?.actions),
308
+ style: styles?.actions,
309
+ "data-tao-sonner-actions": "",
310
+ "data-tao-close-only": toast.action || toast.cancel || !showClose ? void 0 : '',
311
+ children: [
312
+ toast.cancel ? /*#__PURE__*/ jsx(Button, {
313
+ variant: "ghost",
314
+ size: "small",
315
+ className: cx(classNames?.cancel),
316
+ style: styles?.cancel,
317
+ disabled: exiting,
318
+ onClick: ()=>dismissAfterAction(toast.cancel),
319
+ children: toast.cancel.label
320
+ }) : null,
321
+ toast.action ? /*#__PURE__*/ jsx(Button, {
322
+ variant: "secondary",
323
+ size: "small",
324
+ className: cx(classNames?.action),
325
+ style: styles?.action,
326
+ disabled: exiting,
327
+ onClick: ()=>dismissAfterAction(toast.action),
328
+ children: toast.action.label
329
+ }) : null,
330
+ showClose ? /*#__PURE__*/ jsx("button", {
331
+ type: "button",
332
+ "aria-label": messages.closeNotification,
333
+ className: cx(classNames?.close),
334
+ style: styles?.close,
335
+ disabled: exiting,
336
+ "data-tao-sonner-close": "",
337
+ onClick: ()=>dismissAfterAction(),
338
+ children: "\xd7"
339
+ }) : null
340
+ ]
341
+ })
342
+ ]
326
343
  });
327
344
  }
328
345
  const baseToast = (options)=>create('default', options);
@@ -348,16 +365,15 @@ const sonner_toast = Object.assign(baseToast, {
348
365
  duration: 0
349
366
  });
350
367
  const generation = runtimes.get(id)?.generation;
368
+ let value;
351
369
  try {
352
- const value = await promise;
353
- const success = renderPromiseState(messages.success, value);
354
- settlePromiseToast(id, generation, 'success', success);
355
- return value;
370
+ value = await promise;
356
371
  } catch (error) {
357
- const failure = renderPromiseState(messages.error, error);
358
- settlePromiseToast(id, generation, 'error', failure);
372
+ settlePromiseToast(id, generation, 'error', ()=>renderPromiseState(messages.error, error));
359
373
  throw error;
360
374
  }
375
+ settlePromiseToast(id, generation, 'success', ()=>renderPromiseState(messages.success, value));
376
+ return value;
361
377
  },
362
378
  dismiss: dismiss
363
379
  });