@inf-monkeys-tech/monkeys-design 0.4.33 → 0.4.35

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.
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ var jsxRuntime = require('react/jsx-runtime');
5
5
  var ContextMenu = require('@radix-ui/react-context-menu');
6
6
  var DropdownMenu3 = require('@radix-ui/react-dropdown-menu');
7
7
  var core = require('@dnd-kit/core');
8
+ var sonner = require('sonner');
8
9
  var Tooltip = require('@radix-ui/react-tooltip');
9
10
 
10
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -749,7 +750,7 @@ var require_lodash = __commonJS({
749
750
  }
750
751
  var runInContext = (function runInContext2(context) {
751
752
  context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
752
- var Array2 = context.Array, Date = context.Date, Error2 = context.Error, Function2 = context.Function, Math2 = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String2 = context.String, TypeError2 = context.TypeError;
753
+ var Array2 = context.Array, Date2 = context.Date, Error2 = context.Error, Function2 = context.Function, Math2 = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String2 = context.String, TypeError2 = context.TypeError;
753
754
  var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
754
755
  var coreJsData = context["__core-js_shared__"];
755
756
  var funcToString = funcProto.toString;
@@ -774,8 +775,8 @@ var require_lodash = __commonJS({
774
775
  } catch (e) {
775
776
  }
776
777
  })();
777
- var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date && Date.now !== root.Date.now && Date.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
778
- var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
778
+ var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
779
+ var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
779
780
  var DataView = getNative(context, "DataView"), Map2 = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set2 = getNative(context, "Set"), WeakMap = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
780
781
  var metaMap = WeakMap && new WeakMap();
781
782
  var realNames = {};
@@ -24143,7 +24144,271 @@ function WorkbenchLaneView({
24143
24144
  }) }) : null })
24144
24145
  ] });
24145
24146
  }
24146
- function cn4(...inputs) {
24147
+ var DEFAULT_TOAST_DURATION = 5200;
24148
+ var TOAST_DEDUPE_WINDOW = 1200;
24149
+ var DEFAULT_MESSAGES = {
24150
+ errorTitle: "Error",
24151
+ warningTitle: "Warning",
24152
+ defaultErrorDescription: "Something went wrong.",
24153
+ defaultWarningDescription: "Please check and try again."
24154
+ };
24155
+ var ACTIONABLE_TOAST_PATTERNS = [
24156
+ /^(please|select|enter|provide|write|choose|confirm|fill)\b/i,
24157
+ /^(请|请选择|请先|请输入|请填写|请确认|请留意)/
24158
+ ];
24159
+ var DEFAULT_TOAST_CLASS_NAMES = {
24160
+ toast: "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
24161
+ description: "group-[.toast]:text-muted-foreground",
24162
+ actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
24163
+ cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"
24164
+ };
24165
+ var recentToastSignatures = /* @__PURE__ */ new Map();
24166
+ function cn4(...classNames) {
24167
+ return classNames.filter(Boolean).join(" ");
24168
+ }
24169
+ function isToastInput(input) {
24170
+ if (!input || typeof input !== "object" || React.isValidElement(input)) {
24171
+ return false;
24172
+ }
24173
+ return "title" in input || "description" in input || "variant" in input;
24174
+ }
24175
+ function isEmptyToastContent(value) {
24176
+ return value == null || typeof value === "string" && !value.trim();
24177
+ }
24178
+ function normalizeToastInput(input, variant, options) {
24179
+ const { description: _description, ...baseOptions } = options ?? {};
24180
+ if (isToastInput(input)) {
24181
+ return {
24182
+ ...baseOptions,
24183
+ ...input,
24184
+ variant: input.variant ?? variant
24185
+ };
24186
+ }
24187
+ return {
24188
+ ...baseOptions,
24189
+ title: input,
24190
+ variant
24191
+ };
24192
+ }
24193
+ function resolveValue(candidate, value) {
24194
+ if (typeof candidate === "function") {
24195
+ return candidate(value);
24196
+ }
24197
+ return candidate;
24198
+ }
24199
+ function shouldEmitToast(signature) {
24200
+ const now = Date.now();
24201
+ for (const [key, timestamp] of recentToastSignatures.entries()) {
24202
+ if (now - timestamp > TOAST_DEDUPE_WINDOW) {
24203
+ recentToastSignatures.delete(key);
24204
+ }
24205
+ }
24206
+ const previousTimestamp = recentToastSignatures.get(signature);
24207
+ if (previousTimestamp && now - previousTimestamp < TOAST_DEDUPE_WINDOW) {
24208
+ return false;
24209
+ }
24210
+ recentToastSignatures.set(signature, now);
24211
+ return true;
24212
+ }
24213
+ function translateMessage(translate, value) {
24214
+ return translate ? translate(value, { defaultValue: value }) : value;
24215
+ }
24216
+ function getDefaultMessage(messages, key) {
24217
+ return messages?.[key] ?? DEFAULT_MESSAGES[key];
24218
+ }
24219
+ function emitToast(input) {
24220
+ const { title, description, duration, variant = "info", ...options } = input;
24221
+ const message = isEmptyToastContent(title) ? description : title;
24222
+ if (isEmptyToastContent(message)) {
24223
+ return void 0;
24224
+ }
24225
+ const descriptionValue = !isEmptyToastContent(description) && description !== message ? description : void 0;
24226
+ const sonnerOptions = {
24227
+ ...options,
24228
+ description: descriptionValue,
24229
+ duration: duration ?? DEFAULT_TOAST_DURATION
24230
+ };
24231
+ switch (variant) {
24232
+ case "error":
24233
+ return sonner.toast.error(message, sonnerOptions);
24234
+ case "warning":
24235
+ return sonner.toast.warning(message, sonnerOptions);
24236
+ case "success":
24237
+ return sonner.toast.success(message, sonnerOptions);
24238
+ default:
24239
+ return sonner.toast(message, sonnerOptions);
24240
+ }
24241
+ }
24242
+ function extractToastMessage(value, fallback = "") {
24243
+ if (!value) return fallback;
24244
+ if (typeof value === "string") {
24245
+ const nextMessage = value.trim();
24246
+ return nextMessage || fallback;
24247
+ }
24248
+ if (value instanceof Error) {
24249
+ const nextMessage = String(value.message || "").trim();
24250
+ return nextMessage || fallback;
24251
+ }
24252
+ if (typeof value === "object" && typeof value.message === "string") {
24253
+ const nextMessage = value.message.trim();
24254
+ if (nextMessage) return nextMessage;
24255
+ }
24256
+ if (typeof value === "object" && typeof value.title === "string") {
24257
+ const nextTitle = value.title.trim();
24258
+ if (nextTitle) return nextTitle;
24259
+ }
24260
+ return fallback;
24261
+ }
24262
+ function resolveToastVariantForMessage(value) {
24263
+ const message = extractToastMessage(value);
24264
+ if (ACTIONABLE_TOAST_PATTERNS.some((pattern) => pattern.test(message))) {
24265
+ return "warning";
24266
+ }
24267
+ return "error";
24268
+ }
24269
+ function MonkeysToaster({
24270
+ className,
24271
+ closeButton = true,
24272
+ position = "bottom-right",
24273
+ richColors = true,
24274
+ toastOptions,
24275
+ useThemeClassNames = true,
24276
+ visibleToasts = 10,
24277
+ ...props
24278
+ }) {
24279
+ return /* @__PURE__ */ jsxRuntime.jsx(
24280
+ sonner.Toaster,
24281
+ {
24282
+ className: cn4("pointer-events-auto toaster group", className),
24283
+ closeButton,
24284
+ position,
24285
+ richColors,
24286
+ toastOptions: {
24287
+ ...toastOptions,
24288
+ classNames: useThemeClassNames ? {
24289
+ ...DEFAULT_TOAST_CLASS_NAMES,
24290
+ ...toastOptions?.classNames
24291
+ } : toastOptions?.classNames
24292
+ },
24293
+ visibleToasts,
24294
+ ...props
24295
+ }
24296
+ );
24297
+ }
24298
+ function MonkeysToastProvider({ children, toasterProps }) {
24299
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
24300
+ children,
24301
+ /* @__PURE__ */ jsxRuntime.jsx(MonkeysToaster, { ...toasterProps })
24302
+ ] });
24303
+ }
24304
+ function useToastOnValue(value, options = {}) {
24305
+ const previousSignatureRef = React.useRef(null);
24306
+ const translate = options.translate;
24307
+ React.useEffect(() => {
24308
+ if (!value) {
24309
+ previousSignatureRef.current = null;
24310
+ return;
24311
+ }
24312
+ const variant = resolveValue(options.variant, value) ?? "error";
24313
+ const rawTitle = resolveValue(options.title, value);
24314
+ const rawFallbackDescription = resolveValue(options.fallbackDescription, value);
24315
+ const rawDescription = resolveValue(options.description, value) ?? extractToastMessage(value, rawFallbackDescription || "");
24316
+ const title = translateMessage(
24317
+ translate,
24318
+ rawTitle || getDefaultMessage(options.messages, variant === "warning" ? "warningTitle" : "errorTitle")
24319
+ );
24320
+ const description = translateMessage(
24321
+ translate,
24322
+ rawDescription || getDefaultMessage(
24323
+ options.messages,
24324
+ variant === "warning" ? "defaultWarningDescription" : "defaultErrorDescription"
24325
+ )
24326
+ );
24327
+ const signature = resolveValue(options.signature, value) || [variant, title, description].join("|");
24328
+ if (previousSignatureRef.current === signature) {
24329
+ return;
24330
+ }
24331
+ previousSignatureRef.current = signature;
24332
+ if (!shouldEmitToast(signature)) {
24333
+ return;
24334
+ }
24335
+ toast.show({
24336
+ variant,
24337
+ title,
24338
+ description,
24339
+ duration: resolveValue(options.duration, value)
24340
+ });
24341
+ }, [
24342
+ options.description,
24343
+ options.duration,
24344
+ options.fallbackDescription,
24345
+ options.messages,
24346
+ options.signature,
24347
+ options.title,
24348
+ options.variant,
24349
+ translate,
24350
+ value
24351
+ ]);
24352
+ }
24353
+ function useToastFeed(items, options = {}) {
24354
+ const previousVisibleSignaturesRef = React.useRef(/* @__PURE__ */ new Set());
24355
+ const translate = options.translate;
24356
+ const emitItem = React.useCallback(
24357
+ (item, index, visibleSignatures) => {
24358
+ const variant = item.variant ?? "info";
24359
+ const title = translateMessage(
24360
+ translate,
24361
+ item.title || getDefaultMessage(options.messages, variant === "warning" ? "warningTitle" : "errorTitle")
24362
+ );
24363
+ const description = translateMessage(
24364
+ translate,
24365
+ item.description || getDefaultMessage(
24366
+ options.messages,
24367
+ variant === "warning" ? "defaultWarningDescription" : "defaultErrorDescription"
24368
+ )
24369
+ );
24370
+ const signature = item.signature || [variant, title, description, index].join("|");
24371
+ visibleSignatures.add(signature);
24372
+ if (previousVisibleSignaturesRef.current.has(signature) || !shouldEmitToast(signature)) {
24373
+ return;
24374
+ }
24375
+ toast.show({
24376
+ variant,
24377
+ title,
24378
+ description,
24379
+ duration: item.duration
24380
+ });
24381
+ },
24382
+ [options.messages, translate]
24383
+ );
24384
+ React.useEffect(() => {
24385
+ const visibleSignatures = /* @__PURE__ */ new Set();
24386
+ items.forEach((item, index) => {
24387
+ if (item) {
24388
+ emitItem(item, index, visibleSignatures);
24389
+ }
24390
+ });
24391
+ previousVisibleSignaturesRef.current = visibleSignatures;
24392
+ }, [emitItem, items]);
24393
+ }
24394
+ var toast = Object.assign(
24395
+ (message, options) => sonner.toast(message, options),
24396
+ {
24397
+ show: emitToast,
24398
+ error: (input, options) => emitToast(normalizeToastInput(input, "error", options)),
24399
+ warning: (input, options) => emitToast(normalizeToastInput(input, "warning", options)),
24400
+ success: (input, options) => emitToast(normalizeToastInput(input, "success", options)),
24401
+ info: (input, options) => emitToast(normalizeToastInput(input, "info", options)),
24402
+ message: sonner.toast.message,
24403
+ promise: sonner.toast.promise,
24404
+ dismiss: sonner.toast.dismiss,
24405
+ loading: sonner.toast.loading,
24406
+ custom: sonner.toast.custom,
24407
+ getHistory: sonner.toast.getHistory,
24408
+ getToasts: sonner.toast.getToasts
24409
+ }
24410
+ );
24411
+ function cn5(...inputs) {
24147
24412
  return inputs.filter(Boolean).join(" ");
24148
24413
  }
24149
24414
  function SunIcon({ className }) {
@@ -24195,7 +24460,7 @@ function DarkModeSelector({
24195
24460
  const trigger = /* @__PURE__ */ jsxRuntime.jsx(DropdownMenu3__namespace.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
24196
24461
  "button",
24197
24462
  {
24198
- className: cn4(
24463
+ className: cn5(
24199
24464
  "inline-flex h-8 w-8 items-center justify-center rounded-md text-[hsl(var(--foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] transition-colors focus-visible:outline-none",
24200
24465
  className
24201
24466
  ),
@@ -24229,7 +24494,7 @@ function DarkModeSelector({
24229
24494
  children: options.map(({ value, label, Icon }) => /* @__PURE__ */ jsxRuntime.jsxs(
24230
24495
  DropdownMenu3__namespace.Item,
24231
24496
  {
24232
- className: cn4(
24497
+ className: cn5(
24233
24498
  "relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))]",
24234
24499
  mode === value && "bg-[hsl(var(--accent))]"
24235
24500
  ),
@@ -24291,7 +24556,7 @@ function DarkModeSubMenu({
24291
24556
  {
24292
24557
  checked: mode === value,
24293
24558
  disabled: mode === value,
24294
- className: cn4(
24559
+ className: cn5(
24295
24560
  "relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 pl-7 text-sm outline-none transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
24296
24561
  ),
24297
24562
  onCheckedChange: () => onModeChange(value),
@@ -24307,7 +24572,7 @@ function DarkModeSubMenu({
24307
24572
  ) })
24308
24573
  ] });
24309
24574
  }
24310
- function cn5(...inputs) {
24575
+ function cn6(...inputs) {
24311
24576
  return inputs.filter(Boolean).join(" ");
24312
24577
  }
24313
24578
  function GlobeIcon({ className }) {
@@ -24327,7 +24592,7 @@ function I18nSelector({
24327
24592
  const trigger = /* @__PURE__ */ jsxRuntime.jsx(DropdownMenu3__namespace.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
24328
24593
  "button",
24329
24594
  {
24330
- className: cn5(
24595
+ className: cn6(
24331
24596
  "inline-flex h-8 w-8 items-center justify-center rounded-md text-[hsl(var(--foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] transition-colors focus-visible:outline-none",
24332
24597
  className
24333
24598
  ),
@@ -24361,7 +24626,7 @@ function I18nSelector({
24361
24626
  children: languages.map(({ code, label }) => /* @__PURE__ */ jsxRuntime.jsx(
24362
24627
  DropdownMenu3__namespace.Item,
24363
24628
  {
24364
- className: cn5(
24629
+ className: cn6(
24365
24630
  "relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))]",
24366
24631
  currentLanguage === code && "bg-[hsl(var(--accent))]"
24367
24632
  ),
@@ -24543,10 +24808,14 @@ exports.InteractiveTableEditableTextCell = InteractiveTableEditableTextCell;
24543
24808
  exports.InteractiveTableReadonlyCell = InteractiveTableReadonlyCell;
24544
24809
  exports.InteractiveTableSelectCell = InteractiveTableSelectCell;
24545
24810
  exports.LoginLayout = LoginLayout;
24811
+ exports.MonkeysToastProvider = MonkeysToastProvider;
24812
+ exports.MonkeysToaster = MonkeysToaster;
24546
24813
  exports.NavButton = NavButton;
24547
24814
  exports.OAuthButton = OAuthButton;
24548
24815
  exports.OIDCButton = OIDCButton;
24549
24816
  exports.PendingApproval = PendingApproval;
24817
+ exports.ToastProvider = MonkeysToastProvider;
24818
+ exports.Toaster = MonkeysToaster;
24550
24819
  exports.WorkbenchContentPane = WorkbenchContentPane;
24551
24820
  exports.WorkbenchContentToolbar = WorkbenchContentToolbar;
24552
24821
  exports.WorkbenchDetailSidebar = WorkbenchDetailSidebar;
@@ -24565,6 +24834,7 @@ exports.calculateSaturation = calculateSaturation;
24565
24834
  exports.clearRegistry = clearRegistry;
24566
24835
  exports.cn = cn3;
24567
24836
  exports.createSolidColorScale = createSolidColorScale;
24837
+ exports.extractToastMessage = extractToastMessage;
24568
24838
  exports.genTailwindTheme = genTailwindTheme;
24569
24839
  exports.getBaseBadgeToneClassName = getBaseBadgeToneClassName;
24570
24840
  exports.getBaseButtonToneClassName = getBaseButtonToneClassName;
@@ -24583,8 +24853,12 @@ exports.resolveBaseAppearance = resolveBaseAppearance;
24583
24853
  exports.resolveComponent = resolveComponent;
24584
24854
  exports.resolveDataExplorerAppearance = resolveDataExplorerAppearance;
24585
24855
  exports.resolveMonkeysTheme = resolveMonkeysTheme;
24856
+ exports.resolveToastVariantForMessage = resolveToastVariantForMessage;
24586
24857
  exports.setNeocardTheme = setNeocardTheme;
24587
24858
  exports.setTailwindTheme = setTailwindTheme;
24859
+ exports.toast = toast;
24588
24860
  exports.useDarkMode = useDarkMode;
24861
+ exports.useToastFeed = useToastFeed;
24862
+ exports.useToastOnValue = useToastOnValue;
24589
24863
  //# sourceMappingURL=index.js.map
24590
24864
  //# sourceMappingURL=index.js.map