@duskmoon-dev/components 0.3.3 → 0.4.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 (82) hide show
  1. package/README.md +61 -2
  2. package/dist/classes/chat.d.ts +9 -1
  3. package/dist/classes/console-page.d.ts +16 -0
  4. package/dist/classes/dropdown.d.ts +5 -5
  5. package/dist/classes/fab.d.ts +11 -0
  6. package/dist/classes/index.d.ts +5 -0
  7. package/dist/classes/index.js +180 -34
  8. package/dist/classes/megamenu.d.ts +10 -0
  9. package/dist/classes/otp-input.d.ts +12 -0
  10. package/dist/classes/popover.d.ts +1 -3
  11. package/dist/classes/swap.d.ts +12 -0
  12. package/dist/classes/tree-select.d.ts +6 -6
  13. package/dist/components/app/index.js +128 -68
  14. package/dist/components/avatar/Avatar.types.d.ts +1 -1
  15. package/dist/components/avatar/index.js +2 -1
  16. package/dist/components/badge/index.js +1 -1
  17. package/dist/components/button/Button.d.ts +1 -1
  18. package/dist/components/button/Button.types.d.ts +8 -0
  19. package/dist/components/button/index.js +253 -24
  20. package/dist/components/calendar/index.js +44 -19
  21. package/dist/components/chat/Chat.d.ts +9 -1
  22. package/dist/components/chat/Chat.types.d.ts +26 -0
  23. package/dist/components/chat/index.js +92 -3
  24. package/dist/components/color-picker/ColorPicker.types.d.ts +2 -1
  25. package/dist/components/color-picker/index.js +206 -9
  26. package/dist/components/console-page/ConsolePage.d.ts +2 -0
  27. package/dist/components/console-page/ConsolePage.types.d.ts +29 -0
  28. package/dist/components/console-page/index.d.ts +2 -0
  29. package/dist/components/console-page/index.js +205 -0
  30. package/dist/components/date-picker/DatePicker.types.d.ts +1 -0
  31. package/dist/components/date-picker/index.js +537 -35
  32. package/dist/components/date-picker/usePickerDropdown.d.ts +17 -0
  33. package/dist/components/dm-date-picker/index.js +545 -43
  34. package/dist/components/dm-drawer/index.js +253 -24
  35. package/dist/components/dm-layout/index.js +391 -24
  36. package/dist/components/dm-menu/index.js +380 -13
  37. package/dist/components/dm-page-header/index.js +404 -114
  38. package/dist/components/dm-pro-table/index.js +1183 -368
  39. package/dist/components/dm-query/DmQuery.types.d.ts +1 -1
  40. package/dist/components/dm-query/index.js +931 -188
  41. package/dist/components/dm-search/DmSearch.types.d.ts +4 -0
  42. package/dist/components/dm-search/index.js +917 -163
  43. package/dist/components/dm-table/index.js +1001 -247
  44. package/dist/components/dm-toolbar/index.js +400 -110
  45. package/dist/components/dm-truncate/index.js +115 -35
  46. package/dist/components/dropdown/Dropdown.types.d.ts +1 -1
  47. package/dist/components/dropdown/index.js +400 -110
  48. package/dist/components/fab/Fab.d.ts +4 -0
  49. package/dist/components/fab/Fab.types.d.ts +25 -0
  50. package/dist/components/fab/index.d.ts +2 -0
  51. package/dist/components/fab/index.js +480 -0
  52. package/dist/components/form/Form.types.d.ts +1 -0
  53. package/dist/components/form/index.js +14 -3
  54. package/dist/components/megamenu/Megamenu.d.ts +2 -0
  55. package/dist/components/megamenu/Megamenu.types.d.ts +32 -0
  56. package/dist/components/megamenu/index.d.ts +2 -0
  57. package/dist/components/megamenu/index.js +214 -0
  58. package/dist/components/modal/index.js +128 -68
  59. package/dist/components/otp-input/OtpInput.d.ts +2 -0
  60. package/dist/components/otp-input/OtpInput.types.d.ts +16 -0
  61. package/dist/components/otp-input/index.d.ts +2 -0
  62. package/dist/components/otp-input/index.js +112 -0
  63. package/dist/components/popconfirm/index.js +255 -26
  64. package/dist/components/popover/index.js +24 -4
  65. package/dist/components/swap/Swap.d.ts +3 -0
  66. package/dist/components/swap/Swap.types.d.ts +22 -0
  67. package/dist/components/swap/index.d.ts +2 -0
  68. package/dist/components/swap/index.js +109 -0
  69. package/dist/components/time-picker/TimePicker.types.d.ts +1 -0
  70. package/dist/components/time-picker/index.js +167 -29
  71. package/dist/components/tooltip/Tooltip.types.d.ts +4 -0
  72. package/dist/components/tooltip/index.js +107 -27
  73. package/dist/components/tour/index.js +253 -24
  74. package/dist/components/tree-select/index.js +8 -8
  75. package/dist/components/upload/Upload.types.d.ts +1 -0
  76. package/dist/components/upload/index.js +2 -0
  77. package/dist/generated/version.d.ts +1 -1
  78. package/dist/index.d.ts +5 -0
  79. package/dist/index.js +3330 -1632
  80. package/dist/infrastructure.js +1 -1
  81. package/dist/styles.css +1190 -906
  82. package/package.json +23 -3
@@ -87,6 +87,10 @@ function getTourIndicatorClasses({ active }) {
87
87
  return cn(tourIndicatorClass, active && tourIndicatorActiveClass);
88
88
  }
89
89
 
90
+ // src/components/button/Button.tsx
91
+ import React from "react";
92
+ import { createPortal } from "react-dom";
93
+
90
94
  // src/classes/button.ts
91
95
  var buttonBaseClass = "btn";
92
96
  var buttonColorClasses = {
@@ -110,7 +114,7 @@ var buttonAppearanceClasses = {
110
114
  };
111
115
  var buttonShapeClasses = {
112
116
  rect: "",
113
- circle: "btn-circle",
117
+ circle: "btn-circle btn-icon",
114
118
  square: "btn-square"
115
119
  };
116
120
  var buttonSizeClasses = {
@@ -130,11 +134,14 @@ function getButtonClasses({
130
134
  isLoading,
131
135
  className
132
136
  }) {
133
- return cn(buttonBaseClass, buttonColorClasses[color], buttonAppearanceClasses[appearance], buttonShapeClasses[shape], buttonSizeClasses[size], block && buttonBlockClass, isLoading && buttonIsLoadingClass, className);
137
+ return cn(buttonBaseClass, buttonColorClasses[color], buttonAppearanceClasses[appearance], buttonShapeClasses[shape], buttonSizeClasses[size], shape === "circle" && size === "xs" && "btn-icon-sm", shape === "circle" && size === "sm" && "btn-icon-sm", shape === "circle" && size === "lg" && "btn-icon-lg", block && buttonBlockClass, isLoading && buttonIsLoadingClass, className);
134
138
  }
135
139
 
136
140
  // src/components/button/Button.tsx
137
- import { jsx, jsxs } from "react/jsx-runtime";
141
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
142
+ function isPromiseLike(value) {
143
+ return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
144
+ }
138
145
  function Button({
139
146
  color = "primary",
140
147
  appearance = "filled",
@@ -148,8 +155,155 @@ function Button({
148
155
  children,
149
156
  disabled,
150
157
  ref,
158
+ confirm,
159
+ onClick,
151
160
  ...props
152
161
  }) {
162
+ const buttonRef = React.useRef(null);
163
+ const popoverRef = React.useRef(null);
164
+ const cancelRef = React.useRef(null);
165
+ const approvalRef = React.useRef("idle");
166
+ const pendingRef = React.useRef(false);
167
+ const actionRef = React.useRef(0);
168
+ const operationRef = React.useRef(0);
169
+ const mountedRef = React.useRef(false);
170
+ const [portalTarget, setPortalTarget] = React.useState(null);
171
+ const [confirmLoading, setConfirmLoading] = React.useState(false);
172
+ const [confirmError, setConfirmError] = React.useState(false);
173
+ const generatedId = React.useId().replace(/:/g, "");
174
+ const popoverId = `button-confirm-${generatedId}`;
175
+ const titleId = `${popoverId}-title`;
176
+ const descriptionId = `${popoverId}-description`;
177
+ const anchor = `--${popoverId}-anchor`;
178
+ const hasConfirm = Boolean(confirm);
179
+ const confirmation = confirm && typeof confirm === "object" ? confirm : undefined;
180
+ const title = confirmation ? confirmation.title : "Confirm action";
181
+ const hasTitle = title !== undefined && title !== null && title !== false && title !== "";
182
+ const content = confirmation?.component ?? confirmation?.message ?? confirmation?.description;
183
+ const hasContent = content !== undefined && content !== null && content !== false && content !== "";
184
+ const mergedRef = React.useCallback((node) => {
185
+ buttonRef.current = node;
186
+ if (!node) {
187
+ if (typeof ref === "function")
188
+ ref(null);
189
+ else if (ref)
190
+ ref.current = null;
191
+ return;
192
+ }
193
+ const cleanup = typeof ref === "function" ? ref(node) : undefined;
194
+ if (ref && typeof ref !== "function")
195
+ ref.current = node;
196
+ return () => {
197
+ buttonRef.current = null;
198
+ if (typeof cleanup === "function")
199
+ cleanup();
200
+ else if (typeof ref === "function")
201
+ ref(null);
202
+ else if (ref)
203
+ ref.current = null;
204
+ };
205
+ }, [ref]);
206
+ React.useEffect(() => {
207
+ mountedRef.current = true;
208
+ return () => {
209
+ mountedRef.current = false;
210
+ operationRef.current += 1;
211
+ };
212
+ }, []);
213
+ React.useEffect(() => {
214
+ operationRef.current += 1;
215
+ approvalRef.current = "idle";
216
+ setConfirmError(false);
217
+ setPortalTarget(hasConfirm ? document.body : null);
218
+ }, [hasConfirm]);
219
+ function closePopover() {
220
+ if (popoverRef.current?.matches(":popover-open")) {
221
+ popoverRef.current.hidePopover();
222
+ }
223
+ buttonRef.current?.focus();
224
+ }
225
+ function handleClick(event) {
226
+ if (!confirm) {
227
+ onClick?.(event);
228
+ return;
229
+ }
230
+ if (approvalRef.current === "native") {
231
+ approvalRef.current = "idle";
232
+ return;
233
+ }
234
+ if (approvalRef.current === "action") {
235
+ approvalRef.current = "idle";
236
+ let result;
237
+ try {
238
+ result = onClick?.(event);
239
+ } catch {
240
+ event.preventDefault();
241
+ pendingRef.current = false;
242
+ setConfirmError(true);
243
+ return;
244
+ }
245
+ if (!isPromiseLike(result)) {
246
+ pendingRef.current = false;
247
+ closePopover();
248
+ return;
249
+ }
250
+ const userPreventedDefault = event.defaultPrevented;
251
+ event.preventDefault();
252
+ setConfirmLoading(true);
253
+ const action = actionRef.current;
254
+ const operation = operationRef.current;
255
+ Promise.resolve(result).then(() => {
256
+ if (!mountedRef.current || action !== actionRef.current)
257
+ return;
258
+ pendingRef.current = false;
259
+ setConfirmLoading(false);
260
+ if (operation !== operationRef.current)
261
+ return;
262
+ closePopover();
263
+ if (!userPreventedDefault && !buttonRef.current?.disabled) {
264
+ approvalRef.current = "native";
265
+ buttonRef.current?.click();
266
+ approvalRef.current = "idle";
267
+ }
268
+ }, () => {
269
+ if (!mountedRef.current || action !== actionRef.current)
270
+ return;
271
+ pendingRef.current = false;
272
+ setConfirmLoading(false);
273
+ if (operation !== operationRef.current)
274
+ return;
275
+ setConfirmError(true);
276
+ cancelRef.current?.focus();
277
+ });
278
+ return;
279
+ }
280
+ event.preventDefault();
281
+ if (disabled || isLoading || pendingRef.current)
282
+ return;
283
+ if (popoverRef.current?.matches(":popover-open")) {
284
+ closePopover();
285
+ return;
286
+ }
287
+ setConfirmError(false);
288
+ popoverRef.current?.showPopover();
289
+ cancelRef.current?.focus();
290
+ }
291
+ function handleConfirm(event) {
292
+ event.preventDefault();
293
+ event.stopPropagation();
294
+ const trigger = buttonRef.current;
295
+ if (disabled || isLoading || pendingRef.current || !trigger || trigger.disabled || !event.currentTarget.matches(":popover-open"))
296
+ return;
297
+ setConfirmError(false);
298
+ pendingRef.current = true;
299
+ actionRef.current += 1;
300
+ approvalRef.current = "action";
301
+ trigger.click();
302
+ if (approvalRef.current === "action") {
303
+ approvalRef.current = "idle";
304
+ pendingRef.current = false;
305
+ }
306
+ }
153
307
  const classes = getButtonClasses({
154
308
  color,
155
309
  appearance,
@@ -159,29 +313,104 @@ function Button({
159
313
  isLoading,
160
314
  className
161
315
  });
162
- return /* @__PURE__ */ jsxs("button", {
163
- ref,
164
- className: classes,
165
- disabled: disabled || isLoading,
166
- "aria-busy": isLoading,
167
- "aria-disabled": disabled || isLoading,
168
- ...props,
316
+ const confirmClasses = getButtonClasses({
317
+ color,
318
+ size: "sm",
319
+ isLoading: confirmLoading
320
+ });
321
+ return /* @__PURE__ */ jsxs(Fragment, {
169
322
  children: [
170
- isLoading && /* @__PURE__ */ jsx("span", {
171
- className: "btn-spinner"
172
- }),
173
- !isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
174
- className: "btn-icon-left",
175
- children: leftIcon
176
- }),
177
- /* @__PURE__ */ jsx("span", {
178
- className: "btn-content",
179
- children
323
+ /* @__PURE__ */ jsxs("button", {
324
+ ref: confirm ? mergedRef : ref,
325
+ className: classes,
326
+ disabled: disabled || isLoading,
327
+ "aria-busy": isLoading,
328
+ "aria-disabled": disabled || isLoading,
329
+ ...props,
330
+ style: confirm ? { ...props.style, anchorName: anchor } : props.style,
331
+ "aria-haspopup": confirm ? "dialog" : props["aria-haspopup"],
332
+ "aria-controls": confirm ? popoverId : props["aria-controls"],
333
+ onClick: confirm ? handleClick : onClick,
334
+ children: [
335
+ isLoading && /* @__PURE__ */ jsx("span", {
336
+ className: "btn-spinner"
337
+ }),
338
+ !isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
339
+ className: "btn-icon-left",
340
+ children: leftIcon
341
+ }),
342
+ /* @__PURE__ */ jsx("span", {
343
+ className: "btn-content",
344
+ children
345
+ }),
346
+ !isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
347
+ className: "btn-icon-right",
348
+ children: rightIcon
349
+ })
350
+ ]
180
351
  }),
181
- !isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
182
- className: "btn-icon-right",
183
- children: rightIcon
184
- })
352
+ confirm && portalTarget && createPortal(/* @__PURE__ */ jsxs("form", {
353
+ id: popoverId,
354
+ ref: popoverRef,
355
+ popover: "auto",
356
+ role: "dialog",
357
+ "aria-labelledby": hasTitle ? titleId : undefined,
358
+ "aria-label": hasTitle ? undefined : "Confirm action",
359
+ "aria-describedby": hasContent ? descriptionId : undefined,
360
+ className: "popover popover-confirm popover-bottom",
361
+ style: { positionAnchor: anchor },
362
+ onSubmit: handleConfirm,
363
+ onClick: (event) => event.stopPropagation(),
364
+ onToggle: (event) => {
365
+ if (!event.currentTarget.matches(":popover-open")) {
366
+ operationRef.current += 1;
367
+ if (event.currentTarget.contains(document.activeElement) || document.activeElement === document.body) {
368
+ buttonRef.current?.focus();
369
+ }
370
+ }
371
+ },
372
+ children: [
373
+ hasTitle && /* @__PURE__ */ jsx("div", {
374
+ className: "popover-header",
375
+ children: /* @__PURE__ */ jsx("h3", {
376
+ id: titleId,
377
+ className: "popover-title",
378
+ children: title
379
+ })
380
+ }),
381
+ hasContent && /* @__PURE__ */ jsx("div", {
382
+ id: descriptionId,
383
+ className: "popover-body",
384
+ children: content
385
+ }),
386
+ confirmError && /* @__PURE__ */ jsx("div", {
387
+ role: "alert",
388
+ className: "popover-body",
389
+ children: "The action failed. Please try again."
390
+ }),
391
+ /* @__PURE__ */ jsxs("div", {
392
+ className: "popover-footer",
393
+ children: [
394
+ /* @__PURE__ */ jsx("button", {
395
+ ref: cancelRef,
396
+ type: "button",
397
+ className: "btn btn-text btn-sm",
398
+ popoverTarget: popoverId,
399
+ popoverTargetAction: "hide",
400
+ disabled: confirmLoading,
401
+ children: confirmation?.cancelText ?? "Cancel"
402
+ }),
403
+ /* @__PURE__ */ jsx("button", {
404
+ type: "submit",
405
+ className: confirmClasses,
406
+ disabled: disabled || isLoading || confirmLoading,
407
+ "aria-busy": confirmLoading,
408
+ children: confirmation?.confirmText ?? "Confirm"
409
+ })
410
+ ]
411
+ })
412
+ ]
413
+ }), portalTarget)
185
414
  ]
186
415
  });
187
416
  }
@@ -34,36 +34,36 @@ var treeSelectBaseClass = "tree-select";
34
34
  var treeSelectOpenClass = "tree-select-open";
35
35
  var treeSelectDisabledClass = "tree-select-disabled";
36
36
  var treeSelectMultipleClass = "tree-select-multiple";
37
- var treeSelectSelectionClass = "tree-select-selection";
37
+ var treeSelectSelectionClass = "tree-select-selection tree-select-value";
38
38
  var treeSelectPlaceholderClass = "tree-select-placeholder";
39
39
  var treeSelectTagClass = "tree-select-tag";
40
40
  var treeSelectClearClass = "tree-select-clear";
41
- var treeSelectIconClass = "tree-select-icon";
41
+ var treeSelectIconClass = "tree-select-icon tree-select-arrow";
42
42
  var treeSelectDropdownClass = "tree-select-dropdown";
43
- var treeSelectSearchClass = "tree-select-search";
44
- var treeSelectListClass = "tree-select-list";
43
+ var treeSelectSearchClass = "tree-select-search-input";
44
+ var treeSelectListClass = "tree-select-list tree-select-options";
45
45
  var treeSelectEmptyClass = "tree-select-empty";
46
46
  var treeSelectNodeClass = "tree-select-node";
47
47
  var treeSelectNodeSelectedClass = "tree-select-node-selected";
48
48
  var treeSelectNodeCheckedClass = "tree-select-node-checked";
49
49
  var treeSelectNodeExpandedClass = "tree-select-node-expanded";
50
50
  var treeSelectNodeDisabledClass = "tree-select-node-disabled";
51
- var treeSelectSwitcherClass = "tree-select-switcher";
51
+ var treeSelectSwitcherClass = "tree-select-switcher tree-select-node-toggle";
52
52
  var treeSelectCheckboxClass = "tree-select-checkbox";
53
- var treeSelectTitleClass = "tree-select-title";
53
+ var treeSelectTitleClass = "tree-select-title tree-select-node-label";
54
54
  function getTreeSelectContainerClasses({
55
55
  open,
56
56
  disabled,
57
57
  multiple,
58
58
  className
59
59
  }) {
60
- return cn(treeSelectContainerClass, open && treeSelectOpenClass, disabled && treeSelectDisabledClass, multiple && treeSelectMultipleClass, className);
60
+ return cn(treeSelectContainerClass, treeSelectBaseClass, open && treeSelectOpenClass, disabled && treeSelectDisabledClass, multiple && treeSelectMultipleClass, className);
61
61
  }
62
62
  function getTreeSelectClasses({
63
63
  disabled,
64
64
  className
65
65
  }) {
66
- return cn(treeSelectBaseClass, disabled && treeSelectDisabledClass, className);
66
+ return cn("tree-select-trigger", disabled && treeSelectDisabledClass, className);
67
67
  }
68
68
  function getTreeSelectNodeClasses({
69
69
  selected,
@@ -34,6 +34,7 @@ export interface UploadRequestOption<T = unknown> {
34
34
  export type UploadBeforeUploadResult = boolean | File | Blob | UploadListIgnore | Promise<boolean | File | Blob | UploadListIgnore>;
35
35
  export type UploadListIgnore = symbol;
36
36
  export interface UploadProps extends Omit<ComponentProps<"div">, "children" | "defaultValue" | "onChange"> {
37
+ inputProps?: ComponentProps<"input">;
37
38
  accept?: string;
38
39
  action?: string;
39
40
  beforeUpload?: (file: File, fileList: File[]) => UploadBeforeUploadResult;
@@ -118,6 +118,7 @@ function UploadRoot({
118
118
  disabled,
119
119
  fileList,
120
120
  listType = "text",
121
+ inputProps,
121
122
  multiple,
122
123
  onChange,
123
124
  onPreview,
@@ -302,6 +303,7 @@ function UploadRoot({
302
303
  }),
303
304
  children: [
304
305
  /* @__PURE__ */ jsx("input", {
306
+ ...inputProps,
305
307
  ref: inputRef,
306
308
  className: uploadInputClass,
307
309
  type: "file",
@@ -1 +1 @@
1
- export declare const version = "0.3.3";
1
+ export declare const version = "0.4.0";
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export * from "./components/button";
9
9
  export * from "./components/calendar";
10
10
  export * from "./components/card";
11
11
  export * from "./components/chat";
12
+ export * from "./components/console-page";
12
13
  export * from "./components/carousel";
13
14
  export * from "./components/cascader";
14
15
  export * from "./components/badge";
@@ -54,6 +55,7 @@ export * from "./components/dropdown";
54
55
  export * from "./components/empty";
55
56
  export * from "./components/flex";
56
57
  export * from "./components/float-button";
58
+ export * from "./components/fab";
57
59
  export * from "./components/form";
58
60
  export * from "./components/grid";
59
61
  export * from "./components/image";
@@ -63,9 +65,11 @@ export * from "./components/layout";
63
65
  export * from "./components/list";
64
66
  export * from "./components/mentions";
65
67
  export * from "./components/menu";
68
+ export * from "./components/megamenu";
66
69
  export * from "./components/message";
67
70
  export * from "./components/modal";
68
71
  export * from "./components/notification";
72
+ export * from "./components/otp-input";
69
73
  export * from "./components/pagination";
70
74
  export * from "./components/popover";
71
75
  export * from "./components/popconfirm";
@@ -85,6 +89,7 @@ export * from "./components/splitter";
85
89
  export * from "./components/statistic";
86
90
  export * from "./components/steps";
87
91
  export * from "./components/switch";
92
+ export * from "./components/swap";
88
93
  export * from "./components/tabs";
89
94
  export * from "./components/tag";
90
95
  export * from "./components/table";