@duskmoon-dev/components 0.3.3 → 0.4.1

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 (89) hide show
  1. package/README.md +142 -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 +1195 -368
  39. package/dist/components/dm-query/DmQuery.types.d.ts +1 -1
  40. package/dist/components/dm-query/index.js +943 -188
  41. package/dist/components/dm-search/DmSearch.types.d.ts +4 -0
  42. package/dist/components/dm-search/index.js +929 -163
  43. package/dist/components/dm-table/index.js +1013 -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/json-schema-form/JsonSchemaForm.d.ts +19 -0
  55. package/dist/components/json-schema-form/JsonSchemaWidget.d.ts +14 -0
  56. package/dist/components/json-schema-form/index.d.ts +8 -0
  57. package/dist/components/json-schema-form/index.js +7661 -0
  58. package/dist/components/json-schema-form/json-form-widgets.d.ts +26 -0
  59. package/dist/components/json-schema-form/json-schema-form.d.ts +50 -0
  60. package/dist/components/megamenu/Megamenu.d.ts +2 -0
  61. package/dist/components/megamenu/Megamenu.types.d.ts +32 -0
  62. package/dist/components/megamenu/index.d.ts +2 -0
  63. package/dist/components/megamenu/index.js +214 -0
  64. package/dist/components/modal/index.js +128 -68
  65. package/dist/components/otp-input/OtpInput.d.ts +2 -0
  66. package/dist/components/otp-input/OtpInput.types.d.ts +16 -0
  67. package/dist/components/otp-input/index.d.ts +2 -0
  68. package/dist/components/otp-input/index.js +112 -0
  69. package/dist/components/popconfirm/index.js +255 -26
  70. package/dist/components/popover/index.js +24 -4
  71. package/dist/components/select/index.js +12 -0
  72. package/dist/components/swap/Swap.d.ts +3 -0
  73. package/dist/components/swap/Swap.types.d.ts +22 -0
  74. package/dist/components/swap/index.d.ts +2 -0
  75. package/dist/components/swap/index.js +109 -0
  76. package/dist/components/time-picker/TimePicker.types.d.ts +1 -0
  77. package/dist/components/time-picker/index.js +167 -29
  78. package/dist/components/tooltip/Tooltip.types.d.ts +4 -0
  79. package/dist/components/tooltip/index.js +107 -27
  80. package/dist/components/tour/index.js +253 -24
  81. package/dist/components/tree-select/index.js +8 -8
  82. package/dist/components/upload/Upload.types.d.ts +1 -0
  83. package/dist/components/upload/index.js +2 -0
  84. package/dist/generated/version.d.ts +1 -1
  85. package/dist/index.d.ts +5 -0
  86. package/dist/index.js +3343 -1633
  87. package/dist/infrastructure.js +1 -1
  88. package/dist/styles.css +1359 -865
  89. package/package.json +31 -5
@@ -41,6 +41,10 @@ function getDmDrawerFooterClasses({
41
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
42
  }
43
43
 
44
+ // src/components/button/Button.tsx
45
+ import React from "react";
46
+ import { createPortal } from "react-dom";
47
+
44
48
  // src/classes/button.ts
45
49
  var buttonBaseClass = "btn";
46
50
  var buttonColorClasses = {
@@ -64,7 +68,7 @@ var buttonAppearanceClasses = {
64
68
  };
65
69
  var buttonShapeClasses = {
66
70
  rect: "",
67
- circle: "btn-circle",
71
+ circle: "btn-circle btn-icon",
68
72
  square: "btn-square"
69
73
  };
70
74
  var buttonSizeClasses = {
@@ -84,11 +88,14 @@ function getButtonClasses({
84
88
  isLoading,
85
89
  className
86
90
  }) {
87
- 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);
88
92
  }
89
93
 
90
94
  // src/components/button/Button.tsx
91
- 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
+ }
92
99
  function Button({
93
100
  color = "primary",
94
101
  appearance = "filled",
@@ -102,8 +109,155 @@ function Button({
102
109
  children,
103
110
  disabled,
104
111
  ref,
112
+ confirm,
113
+ onClick,
105
114
  ...props
106
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
+ }
107
261
  const classes = getButtonClasses({
108
262
  color,
109
263
  appearance,
@@ -113,29 +267,104 @@ function Button({
113
267
  isLoading,
114
268
  className
115
269
  });
116
- return /* @__PURE__ */ jsxs("button", {
117
- ref,
118
- className: classes,
119
- disabled: disabled || isLoading,
120
- "aria-busy": isLoading,
121
- "aria-disabled": disabled || isLoading,
122
- ...props,
270
+ const confirmClasses = getButtonClasses({
271
+ color,
272
+ size: "sm",
273
+ isLoading: confirmLoading
274
+ });
275
+ return /* @__PURE__ */ jsxs(Fragment, {
123
276
  children: [
124
- isLoading && /* @__PURE__ */ jsx("span", {
125
- className: "btn-spinner"
126
- }),
127
- !isLoading && leftIcon && /* @__PURE__ */ jsx("span", {
128
- className: "btn-icon-left",
129
- children: leftIcon
130
- }),
131
- /* @__PURE__ */ jsx("span", {
132
- className: "btn-content",
133
- 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
+ ]
134
305
  }),
135
- !isLoading && rightIcon && /* @__PURE__ */ jsx("span", {
136
- className: "btn-icon-right",
137
- children: rightIcon
138
- })
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)
139
368
  ]
140
369
  });
141
370
  }