@sybz-components/utils 1.0.18 → 1.0.20

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/base.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  require('vue');
4
4
  require('consola');
5
5
  require('es-toolkit');
6
- const format = require('./shared/utils.DqukLavi.cjs');
6
+ const format = require('./shared/utils.CpSVN1vj.cjs');
7
7
  require('./confirmSemantic.cjs');
8
8
  require('element-plus');
9
9
  require('axios');
package/dist/base.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { VNode, AppContext, Ref } from 'vue';
2
+ import { Component, StyleValue, VNode, AppContext, Ref } from 'vue';
3
3
  import { SybzComponentTheme } from './theme.cjs';
4
4
  import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.cjs';
5
5
  import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
@@ -38,7 +38,24 @@ interface SybzUtilsConfig {
38
38
  /** HTTP 客户端的全局配置,应用入口配置一次即可。 */
39
39
  http?: CreateHttpOptions;
40
40
  }
41
- interface ToastOptions extends Partial<MessageOptions> {
41
+ interface ToastOptions extends Omit<Partial<MessageOptions>, 'icon'> {
42
+ /** 是否解析 HTML 字符串,并将已全局注册的组件标签渲染为 Vue 组件;默认 false。仅传可信内容。 */
43
+ dangerouslyUseHTMLString?: boolean;
44
+ /** 图标组件,或由全局 SIcon 自动解析的图标名称。 */
45
+ icon?: string | Component;
46
+ /** 传给 s-icon 或自定义图标组件的属性。 */
47
+ iconAttrs?: {
48
+ size?: string | number;
49
+ color?: string;
50
+ source?: 'auto' | 'element-plus' | 'iconify' | 'css' | 'svg' | 'url';
51
+ type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
52
+ variant?: 'plain' | 'light' | 'solid';
53
+ class?: string;
54
+ style?: StyleValue;
55
+ [key: string]: unknown;
56
+ };
57
+ /** 字符串组件标签中 @click="方法名" 等事件对应的处理函数。 */
58
+ handlers?: Record<string, (...args: any[]) => void>;
42
59
  /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
60
  showClose?: boolean;
44
61
  /**
package/dist/base.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { VNode, AppContext, Ref } from 'vue';
2
+ import { Component, StyleValue, VNode, AppContext, Ref } from 'vue';
3
3
  import { SybzComponentTheme } from './theme.mjs';
4
4
  import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.mjs';
5
5
  import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
@@ -38,7 +38,24 @@ interface SybzUtilsConfig {
38
38
  /** HTTP 客户端的全局配置,应用入口配置一次即可。 */
39
39
  http?: CreateHttpOptions;
40
40
  }
41
- interface ToastOptions extends Partial<MessageOptions> {
41
+ interface ToastOptions extends Omit<Partial<MessageOptions>, 'icon'> {
42
+ /** 是否解析 HTML 字符串,并将已全局注册的组件标签渲染为 Vue 组件;默认 false。仅传可信内容。 */
43
+ dangerouslyUseHTMLString?: boolean;
44
+ /** 图标组件,或由全局 SIcon 自动解析的图标名称。 */
45
+ icon?: string | Component;
46
+ /** 传给 s-icon 或自定义图标组件的属性。 */
47
+ iconAttrs?: {
48
+ size?: string | number;
49
+ color?: string;
50
+ source?: 'auto' | 'element-plus' | 'iconify' | 'css' | 'svg' | 'url';
51
+ type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
52
+ variant?: 'plain' | 'light' | 'solid';
53
+ class?: string;
54
+ style?: StyleValue;
55
+ [key: string]: unknown;
56
+ };
57
+ /** 字符串组件标签中 @click="方法名" 等事件对应的处理函数。 */
58
+ handlers?: Record<string, (...args: any[]) => void>;
42
59
  /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
60
  showClose?: boolean;
44
61
  /**
package/dist/base.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { VNode, AppContext, Ref } from 'vue';
2
+ import { Component, StyleValue, VNode, AppContext, Ref } from 'vue';
3
3
  import { SybzComponentTheme } from './theme.js';
4
4
  import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.js';
5
5
  import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
@@ -38,7 +38,24 @@ interface SybzUtilsConfig {
38
38
  /** HTTP 客户端的全局配置,应用入口配置一次即可。 */
39
39
  http?: CreateHttpOptions;
40
40
  }
41
- interface ToastOptions extends Partial<MessageOptions> {
41
+ interface ToastOptions extends Omit<Partial<MessageOptions>, 'icon'> {
42
+ /** 是否解析 HTML 字符串,并将已全局注册的组件标签渲染为 Vue 组件;默认 false。仅传可信内容。 */
43
+ dangerouslyUseHTMLString?: boolean;
44
+ /** 图标组件,或由全局 SIcon 自动解析的图标名称。 */
45
+ icon?: string | Component;
46
+ /** 传给 s-icon 或自定义图标组件的属性。 */
47
+ iconAttrs?: {
48
+ size?: string | number;
49
+ color?: string;
50
+ source?: 'auto' | 'element-plus' | 'iconify' | 'css' | 'svg' | 'url';
51
+ type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
52
+ variant?: 'plain' | 'light' | 'solid';
53
+ class?: string;
54
+ style?: StyleValue;
55
+ [key: string]: unknown;
56
+ };
57
+ /** 字符串组件标签中 @click="方法名" 等事件对应的处理函数。 */
58
+ handlers?: Record<string, (...args: any[]) => void>;
42
59
  /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
60
  showClose?: boolean;
44
61
  /**
package/dist/base.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import 'vue';
2
2
  import 'consola';
3
3
  import 'es-toolkit';
4
- export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.D3fsXXCj.mjs';
4
+ export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.C6u5wfj0.mjs';
5
5
  import './confirmSemantic.mjs';
6
6
  import 'element-plus';
7
7
  import 'axios';
package/dist/format.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.DqukLavi.cjs');
3
+ const format = require('./shared/utils.CpSVN1vj.cjs');
4
4
  require('./is.cjs');
5
5
  require('consola');
6
6
  require('vue');
package/dist/format.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.D3fsXXCj.mjs';
1
+ export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.C6u5wfj0.mjs';
2
2
  import './is.mjs';
3
3
  import 'consola';
4
4
  import 'vue';
package/dist/http.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  require('axios');
4
- const format = require('./shared/utils.DqukLavi.cjs');
4
+ const format = require('./shared/utils.CpSVN1vj.cjs');
5
5
  require('vue');
6
6
  require('consola');
7
7
  require('es-toolkit');
package/dist/http.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'axios';
2
- export { H as HttpError, G as configureHttp, I as createHttp, J as http } from './shared/utils.D3fsXXCj.mjs';
2
+ export { H as HttpError, G as configureHttp, I as createHttp, J as http } from './shared/utils.C6u5wfj0.mjs';
3
3
  import 'vue';
4
4
  import 'consola';
5
5
  import 'es-toolkit';
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.DqukLavi.cjs');
3
+ const format = require('./shared/utils.CpSVN1vj.cjs');
4
4
  const confirmSemantic = require('./confirmSemantic.cjs');
5
5
  const is = require('./is.cjs');
6
6
  const theme = require('./theme.cjs');
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { $ as $toast, H as HttpError, c as clearStorage, a as clone, G as configureHttp, b as configureUtils, d as confirm, e as copy, I as createHttp, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, J as http, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.D3fsXXCj.mjs';
1
+ export { $ as $toast, H as HttpError, c as clearStorage, a as clone, G as configureHttp, b as configureUtils, d as confirm, e as copy, I as createHttp, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, J as http, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.C6u5wfj0.mjs';
2
2
  export { resolveConfirmSemantic } from './confirmSemantic.mjs';
3
3
  export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.mjs';
4
4
  export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme } from './theme.mjs';
@@ -1,4 +1,4 @@
1
- import { isRef, unref, isVNode, toRaw } from 'vue';
1
+ import { isVNode, h, Fragment, isRef, unref, toRaw } from 'vue';
2
2
  import { consola } from 'consola';
3
3
  import { cloneDeep } from 'es-toolkit';
4
4
  import { resolveConfirmSemantic } from '../confirmSemantic.mjs';
@@ -372,6 +372,37 @@ function _parseStorageValue(value) {
372
372
  }
373
373
  return value;
374
374
  }
375
+ function renderToastComponents(message, components, handlers) {
376
+ const template = document.createElement("template");
377
+ template.innerHTML = message;
378
+ const renderNode = (node) => {
379
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
380
+ if (node.nodeType !== Node.ELEMENT_NODE) return null;
381
+ const element = node;
382
+ const tag = element.tagName.toLowerCase();
383
+ const pascalTag = tag.replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
384
+ const component = components[tag] ?? components[pascalTag];
385
+ const attrs = {};
386
+ for (const { name, value } of Array.from(element.attributes)) {
387
+ if (name.startsWith("@")) {
388
+ const handler = handlers?.[value];
389
+ if (handler) {
390
+ const eventName = name.slice(1).replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
391
+ attrs[`on${eventName}`] = handler;
392
+ }
393
+ } else {
394
+ attrs[name] = value === "" ? true : value;
395
+ }
396
+ }
397
+ const children = Array.from(element.childNodes, renderNode).filter((child) => child !== null);
398
+ return component ? h(component, attrs, { default: () => children }) : h(tag, attrs, children);
399
+ };
400
+ return h(
401
+ Fragment,
402
+ null,
403
+ Array.from(template.content.childNodes, renderNode).filter((child) => child !== null)
404
+ );
405
+ }
375
406
  function $toast(message, type = "success", otherParams = {}) {
376
407
  const typeMap = {
377
408
  s: "success",
@@ -383,10 +414,29 @@ function $toast(message, type = "success", otherParams = {}) {
383
414
  return ["s", "i", "e", "w"].includes(t);
384
415
  }
385
416
  function isToastOptions(obj) {
386
- return typeof obj === "object" && obj !== null;
417
+ return typeof obj === "object" && obj !== null && !isVNode(obj);
387
418
  }
388
419
  function showToast(options) {
389
- const { theme = utilsConfig.theme, customClass, ...messageOptions } = options;
420
+ const { theme = utilsConfig.theme, customClass, iconAttrs, handlers, ...messageOptions } = options;
421
+ const appContext = _resolveAppContext(null);
422
+ const appComponents = appContext?.components;
423
+ if (typeof messageOptions.icon === "string") {
424
+ const icon = appComponents?.SIcon ?? appComponents?.["s-icon"];
425
+ if (icon) {
426
+ const iconName = messageOptions.icon;
427
+ messageOptions.icon = () => h(icon, { cursor: "default", ...iconAttrs, icon: iconName });
428
+ }
429
+ } else if (messageOptions.icon && iconAttrs) {
430
+ const icon = messageOptions.icon;
431
+ messageOptions.icon = () => h(icon, iconAttrs);
432
+ }
433
+ if (typeof messageOptions.message === "string" && messageOptions.dangerouslyUseHTMLString) {
434
+ const registeredComponents = appComponents ?? {};
435
+ if (Object.keys(registeredComponents).length > 0) {
436
+ messageOptions.message = renderToastComponents(messageOptions.message, registeredComponents, handlers);
437
+ messageOptions.dangerouslyUseHTMLString = false;
438
+ }
439
+ }
390
440
  if (options.closeAll) {
391
441
  ElMessage.closeAll();
392
442
  }
@@ -396,11 +446,13 @@ function $toast(message, type = "success", otherParams = {}) {
396
446
  customClass !== "el" && theme !== "default" && `s-antd-message--${theme}`,
397
447
  customClass !== "el" && customClass
398
448
  );
399
- ElMessage({
449
+ const resolvedMessageOptions = {
400
450
  ...messageOptions,
401
451
  showClose: options.showClose ?? true,
402
452
  customClass: resolvedCustomClass
403
- });
453
+ };
454
+ if (appContext) ElMessage(resolvedMessageOptions, appContext);
455
+ else ElMessage(resolvedMessageOptions);
404
456
  }
405
457
  if (isToastOptions(message)) {
406
458
  showToast(message);
@@ -1204,7 +1256,7 @@ function getVariable(propertyName, fallback = "") {
1204
1256
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1205
1257
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1206
1258
  {
1207
- return "2026-11-12 14:28:53";
1259
+ return "2026-11-20 11:05:15";
1208
1260
  }
1209
1261
  }
1210
1262
  function test() {
@@ -378,6 +378,37 @@ function _parseStorageValue(value) {
378
378
  }
379
379
  return value;
380
380
  }
381
+ function renderToastComponents(message, components, handlers) {
382
+ const template = document.createElement("template");
383
+ template.innerHTML = message;
384
+ const renderNode = (node) => {
385
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
386
+ if (node.nodeType !== Node.ELEMENT_NODE) return null;
387
+ const element = node;
388
+ const tag = element.tagName.toLowerCase();
389
+ const pascalTag = tag.replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
390
+ const component = components[tag] ?? components[pascalTag];
391
+ const attrs = {};
392
+ for (const { name, value } of Array.from(element.attributes)) {
393
+ if (name.startsWith("@")) {
394
+ const handler = handlers?.[value];
395
+ if (handler) {
396
+ const eventName = name.slice(1).replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
397
+ attrs[`on${eventName}`] = handler;
398
+ }
399
+ } else {
400
+ attrs[name] = value === "" ? true : value;
401
+ }
402
+ }
403
+ const children = Array.from(element.childNodes, renderNode).filter((child) => child !== null);
404
+ return component ? vue.h(component, attrs, { default: () => children }) : vue.h(tag, attrs, children);
405
+ };
406
+ return vue.h(
407
+ vue.Fragment,
408
+ null,
409
+ Array.from(template.content.childNodes, renderNode).filter((child) => child !== null)
410
+ );
411
+ }
381
412
  function $toast(message, type = "success", otherParams = {}) {
382
413
  const typeMap = {
383
414
  s: "success",
@@ -389,10 +420,29 @@ function $toast(message, type = "success", otherParams = {}) {
389
420
  return ["s", "i", "e", "w"].includes(t);
390
421
  }
391
422
  function isToastOptions(obj) {
392
- return typeof obj === "object" && obj !== null;
423
+ return typeof obj === "object" && obj !== null && !vue.isVNode(obj);
393
424
  }
394
425
  function showToast(options) {
395
- const { theme = utilsConfig.theme, customClass, ...messageOptions } = options;
426
+ const { theme = utilsConfig.theme, customClass, iconAttrs, handlers, ...messageOptions } = options;
427
+ const appContext = _resolveAppContext(null);
428
+ const appComponents = appContext?.components;
429
+ if (typeof messageOptions.icon === "string") {
430
+ const icon = appComponents?.SIcon ?? appComponents?.["s-icon"];
431
+ if (icon) {
432
+ const iconName = messageOptions.icon;
433
+ messageOptions.icon = () => vue.h(icon, { cursor: "default", ...iconAttrs, icon: iconName });
434
+ }
435
+ } else if (messageOptions.icon && iconAttrs) {
436
+ const icon = messageOptions.icon;
437
+ messageOptions.icon = () => vue.h(icon, iconAttrs);
438
+ }
439
+ if (typeof messageOptions.message === "string" && messageOptions.dangerouslyUseHTMLString) {
440
+ const registeredComponents = appComponents ?? {};
441
+ if (Object.keys(registeredComponents).length > 0) {
442
+ messageOptions.message = renderToastComponents(messageOptions.message, registeredComponents, handlers);
443
+ messageOptions.dangerouslyUseHTMLString = false;
444
+ }
445
+ }
396
446
  if (options.closeAll) {
397
447
  elementPlus.ElMessage.closeAll();
398
448
  }
@@ -402,11 +452,13 @@ function $toast(message, type = "success", otherParams = {}) {
402
452
  customClass !== "el" && theme !== "default" && `s-antd-message--${theme}`,
403
453
  customClass !== "el" && customClass
404
454
  );
405
- elementPlus.ElMessage({
455
+ const resolvedMessageOptions = {
406
456
  ...messageOptions,
407
457
  showClose: options.showClose ?? true,
408
458
  customClass: resolvedCustomClass
409
- });
459
+ };
460
+ if (appContext) elementPlus.ElMessage(resolvedMessageOptions, appContext);
461
+ else elementPlus.ElMessage(resolvedMessageOptions);
410
462
  }
411
463
  if (isToastOptions(message)) {
412
464
  showToast(message);
@@ -1210,7 +1262,7 @@ function getVariable(propertyName, fallback = "") {
1210
1262
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1211
1263
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1212
1264
  {
1213
- return "2026-11-12 14:28:53";
1265
+ return "2026-11-20 11:05:15";
1214
1266
  }
1215
1267
  }
1216
1268
  function test() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybz-components/utils",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",