@sybz-components/utils 1.0.18 → 1.0.19

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.s3A3s_9I.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.C6JV38T7.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.s3A3s_9I.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.C6JV38T7.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.s3A3s_9I.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.C6JV38T7.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.s3A3s_9I.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.C6JV38T7.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,28 @@ 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 appComponents = _resolveAppContext(null)?.components;
422
+ if (typeof messageOptions.icon === "string") {
423
+ const icon = appComponents?.SIcon ?? appComponents?.["s-icon"];
424
+ if (icon) {
425
+ const iconName = messageOptions.icon;
426
+ messageOptions.icon = () => h(icon, { cursor: "default", ...iconAttrs, icon: iconName });
427
+ }
428
+ } else if (messageOptions.icon && iconAttrs) {
429
+ const icon = messageOptions.icon;
430
+ messageOptions.icon = () => h(icon, iconAttrs);
431
+ }
432
+ if (typeof messageOptions.message === "string" && messageOptions.dangerouslyUseHTMLString) {
433
+ const registeredComponents = appComponents ?? {};
434
+ if (Object.keys(registeredComponents).length > 0) {
435
+ messageOptions.message = renderToastComponents(messageOptions.message, registeredComponents, handlers);
436
+ messageOptions.dangerouslyUseHTMLString = false;
437
+ }
438
+ }
390
439
  if (options.closeAll) {
391
440
  ElMessage.closeAll();
392
441
  }
@@ -1204,7 +1253,7 @@ function getVariable(propertyName, fallback = "") {
1204
1253
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1205
1254
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1206
1255
  {
1207
- return "2026-11-12 14:28:53";
1256
+ return "2026-11-16 18:13:32";
1208
1257
  }
1209
1258
  }
1210
1259
  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,28 @@ 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 appComponents = _resolveAppContext(null)?.components;
428
+ if (typeof messageOptions.icon === "string") {
429
+ const icon = appComponents?.SIcon ?? appComponents?.["s-icon"];
430
+ if (icon) {
431
+ const iconName = messageOptions.icon;
432
+ messageOptions.icon = () => vue.h(icon, { cursor: "default", ...iconAttrs, icon: iconName });
433
+ }
434
+ } else if (messageOptions.icon && iconAttrs) {
435
+ const icon = messageOptions.icon;
436
+ messageOptions.icon = () => vue.h(icon, iconAttrs);
437
+ }
438
+ if (typeof messageOptions.message === "string" && messageOptions.dangerouslyUseHTMLString) {
439
+ const registeredComponents = appComponents ?? {};
440
+ if (Object.keys(registeredComponents).length > 0) {
441
+ messageOptions.message = renderToastComponents(messageOptions.message, registeredComponents, handlers);
442
+ messageOptions.dangerouslyUseHTMLString = false;
443
+ }
444
+ }
396
445
  if (options.closeAll) {
397
446
  elementPlus.ElMessage.closeAll();
398
447
  }
@@ -1210,7 +1259,7 @@ function getVariable(propertyName, fallback = "") {
1210
1259
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1211
1260
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1212
1261
  {
1213
- return "2026-11-12 14:28:53";
1262
+ return "2026-11-16 18:13:32";
1214
1263
  }
1215
1264
  }
1216
1265
  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.19",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",