@duskmoon-dev/components 0.3.1 → 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 (109) hide show
  1. package/README.md +61 -2
  2. package/dist/{chunk-r9wkv7xd.js → chunk-fwjzvsrx.js} +3 -3
  3. package/dist/classes/chat.d.ts +43 -0
  4. package/dist/classes/console-page.d.ts +16 -0
  5. package/dist/classes/dropdown.d.ts +5 -5
  6. package/dist/classes/fab.d.ts +11 -0
  7. package/dist/classes/index.d.ts +6 -0
  8. package/dist/classes/index.js +1443 -1210
  9. package/dist/classes/megamenu.d.ts +10 -0
  10. package/dist/classes/otp-input.d.ts +12 -0
  11. package/dist/classes/popover.d.ts +1 -3
  12. package/dist/classes/swap.d.ts +12 -0
  13. package/dist/classes/tree-select.d.ts +6 -6
  14. package/dist/components/anchor/index.js +2 -2
  15. package/dist/components/app/index.js +211 -151
  16. package/dist/components/avatar/Avatar.types.d.ts +1 -1
  17. package/dist/components/avatar/index.js +2 -1
  18. package/dist/components/badge/index.js +1 -1
  19. package/dist/components/button/Button.d.ts +1 -1
  20. package/dist/components/button/Button.types.d.ts +8 -0
  21. package/dist/components/button/index.js +253 -24
  22. package/dist/components/calendar/index.js +44 -19
  23. package/dist/components/cascader/index.js +2 -2
  24. package/dist/components/chat/Chat.d.ts +22 -0
  25. package/dist/components/chat/Chat.types.d.ts +73 -0
  26. package/dist/components/chat/index.d.ts +2 -0
  27. package/dist/components/chat/index.js +309 -0
  28. package/dist/components/color-picker/ColorPicker.types.d.ts +2 -1
  29. package/dist/components/color-picker/index.js +210 -13
  30. package/dist/components/config-provider/index.js +2 -2
  31. package/dist/components/console-page/ConsolePage.d.ts +2 -0
  32. package/dist/components/console-page/ConsolePage.types.d.ts +29 -0
  33. package/dist/components/console-page/index.d.ts +2 -0
  34. package/dist/components/console-page/index.js +205 -0
  35. package/dist/components/date-picker/DatePicker.types.d.ts +1 -0
  36. package/dist/components/date-picker/index.js +537 -35
  37. package/dist/components/date-picker/usePickerDropdown.d.ts +17 -0
  38. package/dist/components/dm-breadcrumb/index.js +18 -18
  39. package/dist/components/dm-date-picker/index.js +635 -133
  40. package/dist/components/dm-drawer/index.js +269 -40
  41. package/dist/components/dm-layout/index.js +575 -208
  42. package/dist/components/dm-menu/index.js +399 -32
  43. package/dist/components/dm-message/index.js +18 -18
  44. package/dist/components/dm-page-header/index.js +537 -247
  45. package/dist/components/dm-pagination/index.js +39 -39
  46. package/dist/components/dm-pro-table/index.js +2374 -1559
  47. package/dist/components/dm-provider/index.js +94 -94
  48. package/dist/components/dm-query/DmQuery.types.d.ts +1 -1
  49. package/dist/components/dm-query/index.js +955 -210
  50. package/dist/components/dm-search/DmSearch.types.d.ts +4 -0
  51. package/dist/components/dm-search/index.js +937 -183
  52. package/dist/components/dm-splitter/index.js +32 -32
  53. package/dist/components/dm-status/index.js +25 -25
  54. package/dist/components/dm-table/index.js +1430 -676
  55. package/dist/components/dm-tabs/index.js +34 -34
  56. package/dist/components/dm-toolbar/index.js +423 -133
  57. package/dist/components/dm-tree/index.js +92 -92
  58. package/dist/components/dm-truncate/index.js +145 -65
  59. package/dist/components/dropdown/Dropdown.types.d.ts +1 -1
  60. package/dist/components/dropdown/index.js +467 -177
  61. package/dist/components/fab/Fab.d.ts +4 -0
  62. package/dist/components/fab/Fab.types.d.ts +25 -0
  63. package/dist/components/fab/index.d.ts +2 -0
  64. package/dist/components/fab/index.js +480 -0
  65. package/dist/components/form/Form.types.d.ts +1 -0
  66. package/dist/components/form/index.js +16 -5
  67. package/dist/components/grid/index.js +2 -2
  68. package/dist/components/input/index.js +4 -4
  69. package/dist/components/markdown/index.js +1 -1
  70. package/dist/components/megamenu/Megamenu.d.ts +2 -0
  71. package/dist/components/megamenu/Megamenu.types.d.ts +32 -0
  72. package/dist/components/megamenu/index.d.ts +2 -0
  73. package/dist/components/megamenu/index.js +214 -0
  74. package/dist/components/message/index.js +5 -5
  75. package/dist/components/modal/index.js +128 -68
  76. package/dist/components/notification/index.js +2 -2
  77. package/dist/components/otp-input/OtpInput.d.ts +2 -0
  78. package/dist/components/otp-input/OtpInput.types.d.ts +16 -0
  79. package/dist/components/otp-input/index.d.ts +2 -0
  80. package/dist/components/otp-input/index.js +112 -0
  81. package/dist/components/popconfirm/index.js +297 -68
  82. package/dist/components/popover/index.js +24 -4
  83. package/dist/components/skeleton/index.js +5 -5
  84. package/dist/components/spin/index.js +2 -2
  85. package/dist/components/steps/index.js +2 -2
  86. package/dist/components/swap/Swap.d.ts +3 -0
  87. package/dist/components/swap/Swap.types.d.ts +22 -0
  88. package/dist/components/swap/index.d.ts +2 -0
  89. package/dist/components/swap/index.js +109 -0
  90. package/dist/components/table/index.js +2 -2
  91. package/dist/components/tabs/index.js +2 -2
  92. package/dist/components/tag/index.js +2 -2
  93. package/dist/components/time-picker/TimePicker.types.d.ts +1 -0
  94. package/dist/components/time-picker/index.js +167 -29
  95. package/dist/components/tooltip/Tooltip.types.d.ts +4 -0
  96. package/dist/components/tooltip/index.js +107 -27
  97. package/dist/components/tour/index.js +315 -86
  98. package/dist/components/tree-select/index.js +8 -8
  99. package/dist/components/typography/index.js +4 -4
  100. package/dist/components/upload/Upload.types.d.ts +1 -0
  101. package/dist/components/upload/index.js +7 -5
  102. package/dist/generated/version.d.ts +1 -1
  103. package/dist/index.d.ts +6 -0
  104. package/dist/index.js +4023 -2134
  105. package/dist/infrastructure.js +11 -11
  106. package/dist/styles.css +13677 -9811
  107. package/dist/theme/index.js +3 -3
  108. package/dist/utils/index.js +5 -5
  109. package/package.json +30 -6
@@ -1,5 +1,8 @@
1
1
  "use client";
2
2
 
3
+ // src/components/dm-drawer/DmDrawer.tsx
4
+ import { forwardRef as forwardRef2 } from "react";
5
+
3
6
  // ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
4
7
  function r(e) {
5
8
  var t, f, n = "";
@@ -25,6 +28,23 @@ function clsx() {
25
28
  function cn(...inputs) {
26
29
  return clsx(inputs);
27
30
  }
31
+ // src/classes/dm-drawer.ts
32
+ var dmDrawerBaseClass = "dm-drawer";
33
+ var dmDrawerFooterActionClass = "dm-drawer-footer-action";
34
+ function getDmDrawerClasses({ className }) {
35
+ return cn(dmDrawerBaseClass, className);
36
+ }
37
+ function getDmDrawerFooterClasses({
38
+ align = "right",
39
+ className
40
+ }) {
41
+ return cn("dm-drawer-footer", align === "left" && "dm-drawer-footer-left", align === "center" && "dm-drawer-footer-center", align === "right" && "dm-drawer-footer-right", className);
42
+ }
43
+
44
+ // src/components/button/Button.tsx
45
+ import React from "react";
46
+ import { createPortal } from "react-dom";
47
+
28
48
  // src/classes/button.ts
29
49
  var buttonBaseClass = "btn";
30
50
  var buttonColorClasses = {
@@ -48,7 +68,7 @@ var buttonAppearanceClasses = {
48
68
  };
49
69
  var buttonShapeClasses = {
50
70
  rect: "",
51
- circle: "btn-circle",
71
+ circle: "btn-circle btn-icon",
52
72
  square: "btn-square"
53
73
  };
54
74
  var buttonSizeClasses = {
@@ -68,11 +88,14 @@ function getButtonClasses({
68
88
  isLoading,
69
89
  className
70
90
  }) {
71
- return cn(buttonBaseClass, buttonColorClasses[color], buttonAppearanceClasses[appearance], buttonShapeClasses[shape], buttonSizeClasses[size], block && buttonBlockClass, isLoading && buttonIsLoadingClass, className);
91
+ 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);
72
92
  }
73
93
 
74
94
  // src/components/button/Button.tsx
75
- import { jsx, jsxs } from "react/jsx-runtime";
95
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
96
+ function isPromiseLike(value) {
97
+ return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
98
+ }
76
99
  function Button({
77
100
  color = "primary",
78
101
  appearance = "filled",
@@ -86,8 +109,155 @@ function Button({
86
109
  children,
87
110
  disabled,
88
111
  ref,
112
+ confirm,
113
+ onClick,
89
114
  ...props
90
115
  }) {
116
+ const buttonRef = React.useRef(null);
117
+ const popoverRef = React.useRef(null);
118
+ const cancelRef = React.useRef(null);
119
+ const approvalRef = React.useRef("idle");
120
+ const pendingRef = React.useRef(false);
121
+ const actionRef = React.useRef(0);
122
+ const operationRef = React.useRef(0);
123
+ const mountedRef = React.useRef(false);
124
+ const [portalTarget, setPortalTarget] = React.useState(null);
125
+ const [confirmLoading, setConfirmLoading] = React.useState(false);
126
+ const [confirmError, setConfirmError] = React.useState(false);
127
+ const generatedId = React.useId().replace(/:/g, "");
128
+ const popoverId = `button-confirm-${generatedId}`;
129
+ const titleId = `${popoverId}-title`;
130
+ const descriptionId = `${popoverId}-description`;
131
+ const anchor = `--${popoverId}-anchor`;
132
+ const hasConfirm = Boolean(confirm);
133
+ const confirmation = confirm && typeof confirm === "object" ? confirm : undefined;
134
+ const title = confirmation ? confirmation.title : "Confirm action";
135
+ const hasTitle = title !== undefined && title !== null && title !== false && title !== "";
136
+ const content = confirmation?.component ?? confirmation?.message ?? confirmation?.description;
137
+ const hasContent = content !== undefined && content !== null && content !== false && content !== "";
138
+ const mergedRef = React.useCallback((node) => {
139
+ buttonRef.current = node;
140
+ if (!node) {
141
+ if (typeof ref === "function")
142
+ ref(null);
143
+ else if (ref)
144
+ ref.current = null;
145
+ return;
146
+ }
147
+ const cleanup = typeof ref === "function" ? ref(node) : undefined;
148
+ if (ref && typeof ref !== "function")
149
+ ref.current = node;
150
+ return () => {
151
+ buttonRef.current = null;
152
+ if (typeof cleanup === "function")
153
+ cleanup();
154
+ else if (typeof ref === "function")
155
+ ref(null);
156
+ else if (ref)
157
+ ref.current = null;
158
+ };
159
+ }, [ref]);
160
+ React.useEffect(() => {
161
+ mountedRef.current = true;
162
+ return () => {
163
+ mountedRef.current = false;
164
+ operationRef.current += 1;
165
+ };
166
+ }, []);
167
+ React.useEffect(() => {
168
+ operationRef.current += 1;
169
+ approvalRef.current = "idle";
170
+ setConfirmError(false);
171
+ setPortalTarget(hasConfirm ? document.body : null);
172
+ }, [hasConfirm]);
173
+ function closePopover() {
174
+ if (popoverRef.current?.matches(":popover-open")) {
175
+ popoverRef.current.hidePopover();
176
+ }
177
+ buttonRef.current?.focus();
178
+ }
179
+ function handleClick(event) {
180
+ if (!confirm) {
181
+ onClick?.(event);
182
+ return;
183
+ }
184
+ if (approvalRef.current === "native") {
185
+ approvalRef.current = "idle";
186
+ return;
187
+ }
188
+ if (approvalRef.current === "action") {
189
+ approvalRef.current = "idle";
190
+ let result;
191
+ try {
192
+ result = onClick?.(event);
193
+ } catch {
194
+ event.preventDefault();
195
+ pendingRef.current = false;
196
+ setConfirmError(true);
197
+ return;
198
+ }
199
+ if (!isPromiseLike(result)) {
200
+ pendingRef.current = false;
201
+ closePopover();
202
+ return;
203
+ }
204
+ const userPreventedDefault = event.defaultPrevented;
205
+ event.preventDefault();
206
+ setConfirmLoading(true);
207
+ const action = actionRef.current;
208
+ const operation = operationRef.current;
209
+ Promise.resolve(result).then(() => {
210
+ if (!mountedRef.current || action !== actionRef.current)
211
+ return;
212
+ pendingRef.current = false;
213
+ setConfirmLoading(false);
214
+ if (operation !== operationRef.current)
215
+ return;
216
+ closePopover();
217
+ if (!userPreventedDefault && !buttonRef.current?.disabled) {
218
+ approvalRef.current = "native";
219
+ buttonRef.current?.click();
220
+ approvalRef.current = "idle";
221
+ }
222
+ }, () => {
223
+ if (!mountedRef.current || action !== actionRef.current)
224
+ return;
225
+ pendingRef.current = false;
226
+ setConfirmLoading(false);
227
+ if (operation !== operationRef.current)
228
+ return;
229
+ setConfirmError(true);
230
+ cancelRef.current?.focus();
231
+ });
232
+ return;
233
+ }
234
+ event.preventDefault();
235
+ if (disabled || isLoading || pendingRef.current)
236
+ return;
237
+ if (popoverRef.current?.matches(":popover-open")) {
238
+ closePopover();
239
+ return;
240
+ }
241
+ setConfirmError(false);
242
+ popoverRef.current?.showPopover();
243
+ cancelRef.current?.focus();
244
+ }
245
+ function handleConfirm(event) {
246
+ event.preventDefault();
247
+ event.stopPropagation();
248
+ const trigger = buttonRef.current;
249
+ if (disabled || isLoading || pendingRef.current || !trigger || trigger.disabled || !event.currentTarget.matches(":popover-open"))
250
+ return;
251
+ setConfirmError(false);
252
+ pendingRef.current = true;
253
+ actionRef.current += 1;
254
+ approvalRef.current = "action";
255
+ trigger.click();
256
+ if (approvalRef.current === "action") {
257
+ approvalRef.current = "idle";
258
+ pendingRef.current = false;
259
+ }
260
+ }
91
261
  const classes = getButtonClasses({
92
262
  color,
93
263
  appearance,
@@ -97,29 +267,104 @@ function Button({
97
267
  isLoading,
98
268
  className
99
269
  });
100
- return /* @__PURE__ */ jsxs("button", {
101
- ref,
102
- className: classes,
103
- disabled: disabled || isLoading,
104
- "aria-busy": isLoading,
105
- "aria-disabled": disabled || isLoading,
106
- ...props,
270
+ const confirmClasses = getButtonClasses({
271
+ color,
272
+ size: "sm",
273
+ isLoading: confirmLoading
274
+ });
275
+ return /* @__PURE__ */ jsxs(Fragment, {
107
276
  children: [
108
- isLoading && /* @__PURE__ */ jsx("span", {
109
- className: "btn-spinner"
110
- }),
111
- !isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
112
- className: "btn-icon-left",
113
- children: leftIcon
114
- }),
115
- /* @__PURE__ */ jsx("span", {
116
- className: "btn-content",
117
- children
277
+ /* @__PURE__ */ jsxs("button", {
278
+ ref: confirm ? mergedRef : ref,
279
+ className: classes,
280
+ disabled: disabled || isLoading,
281
+ "aria-busy": isLoading,
282
+ "aria-disabled": disabled || isLoading,
283
+ ...props,
284
+ style: confirm ? { ...props.style, anchorName: anchor } : props.style,
285
+ "aria-haspopup": confirm ? "dialog" : props["aria-haspopup"],
286
+ "aria-controls": confirm ? popoverId : props["aria-controls"],
287
+ onClick: confirm ? handleClick : onClick,
288
+ children: [
289
+ isLoading && /* @__PURE__ */ jsx("span", {
290
+ className: "btn-spinner"
291
+ }),
292
+ !isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
293
+ className: "btn-icon-left",
294
+ children: leftIcon
295
+ }),
296
+ /* @__PURE__ */ jsx("span", {
297
+ className: "btn-content",
298
+ children
299
+ }),
300
+ !isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
301
+ className: "btn-icon-right",
302
+ children: rightIcon
303
+ })
304
+ ]
118
305
  }),
119
- !isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
120
- className: "btn-icon-right",
121
- children: rightIcon
122
- })
306
+ confirm && portalTarget && createPortal(/* @__PURE__ */ jsxs("form", {
307
+ id: popoverId,
308
+ ref: popoverRef,
309
+ popover: "auto",
310
+ role: "dialog",
311
+ "aria-labelledby": hasTitle ? titleId : undefined,
312
+ "aria-label": hasTitle ? undefined : "Confirm action",
313
+ "aria-describedby": hasContent ? descriptionId : undefined,
314
+ className: "popover popover-confirm popover-bottom",
315
+ style: { positionAnchor: anchor },
316
+ onSubmit: handleConfirm,
317
+ onClick: (event) => event.stopPropagation(),
318
+ onToggle: (event) => {
319
+ if (!event.currentTarget.matches(":popover-open")) {
320
+ operationRef.current += 1;
321
+ if (event.currentTarget.contains(document.activeElement) || document.activeElement === document.body) {
322
+ buttonRef.current?.focus();
323
+ }
324
+ }
325
+ },
326
+ children: [
327
+ hasTitle && /* @__PURE__ */ jsx("div", {
328
+ className: "popover-header",
329
+ children: /* @__PURE__ */ jsx("h3", {
330
+ id: titleId,
331
+ className: "popover-title",
332
+ children: title
333
+ })
334
+ }),
335
+ hasContent && /* @__PURE__ */ jsx("div", {
336
+ id: descriptionId,
337
+ className: "popover-body",
338
+ children: content
339
+ }),
340
+ confirmError && /* @__PURE__ */ jsx("div", {
341
+ role: "alert",
342
+ className: "popover-body",
343
+ children: "The action failed. Please try again."
344
+ }),
345
+ /* @__PURE__ */ jsxs("div", {
346
+ className: "popover-footer",
347
+ children: [
348
+ /* @__PURE__ */ jsx("button", {
349
+ ref: cancelRef,
350
+ type: "button",
351
+ className: "btn btn-text btn-sm",
352
+ popoverTarget: popoverId,
353
+ popoverTargetAction: "hide",
354
+ disabled: confirmLoading,
355
+ children: confirmation?.cancelText ?? "Cancel"
356
+ }),
357
+ /* @__PURE__ */ jsx("button", {
358
+ type: "submit",
359
+ className: confirmClasses,
360
+ disabled: disabled || isLoading || confirmLoading,
361
+ "aria-busy": confirmLoading,
362
+ children: confirmation?.confirmText ?? "Confirm"
363
+ })
364
+ ]
365
+ })
366
+ ]
367
+ }), portalTarget)
123
368
  ]
124
369
  });
125
370
  }
@@ -225,22 +470,6 @@ var Drawer = forwardRef(({
225
470
  });
226
471
  });
227
472
  Drawer.displayName = "Drawer";
228
- // src/components/dm-drawer/DmDrawer.tsx
229
- import { forwardRef as forwardRef2 } from "react";
230
-
231
- // src/classes/dm-drawer.ts
232
- var dmDrawerBaseClass = "dm-drawer";
233
- var dmDrawerFooterActionClass = "dm-drawer-footer-action";
234
- function getDmDrawerClasses({ className }) {
235
- return cn(dmDrawerBaseClass, className);
236
- }
237
- function getDmDrawerFooterClasses({
238
- align = "right",
239
- className
240
- }) {
241
- return cn("dm-drawer-footer", align === "left" && "dm-drawer-footer-left", align === "center" && "dm-drawer-footer-center", align === "right" && "dm-drawer-footer-right", className);
242
- }
243
-
244
473
  // src/components/dm-drawer/DmDrawer.tsx
245
474
  import { jsx as jsx3 } from "react/jsx-runtime";
246
475
  function renderFooter({