@varlet/ui 3.20.6 → 3.20.7

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
3
  "framework": "vue",
4
- "version": "3.20.6",
4
+ "version": "3.20.7",
5
5
  "name": "VARLET",
6
6
  "contributions": {
7
7
  "html": {
@@ -4125,6 +4125,15 @@
4125
4125
  "kind": "expression"
4126
4126
  }
4127
4127
  },
4128
+ {
4129
+ "name": "expandable-on-overflow",
4130
+ "description": "Allow expansion only if the text is overflowed",
4131
+ "default": "false",
4132
+ "value": {
4133
+ "type": "boolean",
4134
+ "kind": "expression"
4135
+ }
4136
+ },
4128
4137
  {
4129
4138
  "name": "line-clamp",
4130
4139
  "description": "Maximum number of display lines, see [line-clamp](https://caniuse.com/?search=line-clamp) for compatibility",
@@ -4134,6 +4143,15 @@
4134
4143
  "kind": "expression"
4135
4144
  }
4136
4145
  },
4146
+ {
4147
+ "name": "tooltip-on-overflow",
4148
+ "description": "Show the tooltip only when the text is truncated",
4149
+ "default": "false",
4150
+ "value": {
4151
+ "type": "boolean",
4152
+ "kind": "expression"
4153
+ }
4154
+ },
4137
4155
  {
4138
4156
  "name": "tooltip",
4139
4157
  "description": "Tooltip component props, for deep customization. For more convenience, `sameWidth` defaults to `true` here",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
3
  "framework": "vue",
4
- "version": "3.20.6",
4
+ "version": "3.20.7",
5
5
  "name": "VARLET",
6
6
  "contributions": {
7
7
  "html": {
@@ -3876,6 +3876,15 @@
3876
3876
  "kind": "expression"
3877
3877
  }
3878
3878
  },
3879
+ {
3880
+ "name": "expandable-on-overflow",
3881
+ "description": "仅在文本被省略时允许展开",
3882
+ "default": "false",
3883
+ "value": {
3884
+ "type": "boolean",
3885
+ "kind": "expression"
3886
+ }
3887
+ },
3879
3888
  {
3880
3889
  "name": "line-clamp",
3881
3890
  "description": "最大显示行数,兼容性见 [line-clamp](https://caniuse.com/?search=line-clamp)",
@@ -3885,6 +3894,15 @@
3885
3894
  "kind": "expression"
3886
3895
  }
3887
3896
  },
3897
+ {
3898
+ "name": "tooltip-on-overflow",
3899
+ "description": "仅在文本被省略时显示 Tooltip",
3900
+ "default": "false",
3901
+ "value": {
3902
+ "type": "boolean",
3903
+ "kind": "expression"
3904
+ }
3905
+ },
3888
3906
  {
3889
3907
  "name": "tooltip",
3890
3908
  "description": "Tooltip 组件配置,用于深度定制。为了更方便使用,`sameWidth` 在这里默认为 `true`",
package/lib/varlet.cjs.js CHANGED
@@ -18413,7 +18413,9 @@ var stdin_default$99 = stdin_default$397;
18413
18413
  var props$32 = {
18414
18414
  expand: Boolean,
18415
18415
  expandTrigger: String,
18416
+ expandableOnOverflow: Boolean,
18416
18417
  lineClamp: [Number, String],
18418
+ tooltipOnOverflow: Boolean,
18417
18419
  tooltip: {
18418
18420
  type: [Object, Boolean],
18419
18421
  default: true
@@ -18444,11 +18446,12 @@ var _hoisted_1$26 = { key: 0 };
18444
18446
  function __render__$53(_ctx, _cache) {
18445
18447
  const _component_var_tooltip = (0, vue.resolveComponent)("var-tooltip");
18446
18448
  return (0, vue.openBlock)(), (0, vue.createBlock)(_component_var_tooltip, (0, vue.mergeProps)({
18449
+ ref: "rootRef",
18447
18450
  class: _ctx.classes(_ctx.n(), [
18448
18451
  _ctx.lineClamp,
18449
18452
  _ctx.n("--clamp"),
18450
18453
  _ctx.n("--line")
18451
- ], [_ctx.expandTrigger, _ctx.n("--cursor")], [_ctx.expanding, _ctx.n("--expand")]),
18454
+ ], [_ctx.clickable, _ctx.n("--cursor")], [_ctx.expanding, _ctx.n("--expand")]),
18452
18455
  "var-ellipsis-cover": "",
18453
18456
  style: _ctx.rootStyles
18454
18457
  }, _ctx.tooltipProps, { onClick: _ctx.handleClick }), {
@@ -18469,24 +18472,54 @@ var __sfc__$53 = (0, vue.defineComponent)({
18469
18472
  components: { VarTooltip: stdin_default$99 },
18470
18473
  props: props$32,
18471
18474
  setup(props2) {
18475
+ const rootRef = (0, vue.ref)(null);
18476
+ const truncated = (0, vue.ref)(false);
18472
18477
  const expanding = useVModel(props2, "expand");
18478
+ let previousWidth;
18479
+ const clickable = (0, vue.computed)(() => !!props2.expandTrigger && (!props2.expandableOnOverflow || truncated.value || expanding.value));
18473
18480
  const rootStyles = (0, vue.computed)(() => props2.lineClamp ? { "-webkit-line-clamp": props2.lineClamp } : {});
18474
18481
  const tooltipProps = (0, vue.computed)(() => {
18475
- if (props2.tooltip === false) return { disabled: true };
18482
+ if (props2.tooltip === false || props2.tooltipOnOverflow && !truncated.value) return { disabled: true };
18476
18483
  if (props2.tooltip === true) return { sameWidth: true };
18477
18484
  return __spreadValues$13({ sameWidth: true }, props2.tooltip);
18478
18485
  });
18486
+ function getRootElement() {
18487
+ var _a;
18488
+ if (!rootRef.value) return null;
18489
+ return (_a = rootRef.value.$el) != null ? _a : rootRef.value;
18490
+ }
18491
+ function checkTruncated() {
18492
+ const element = getRootElement();
18493
+ if (!element) return;
18494
+ const next = props2.lineClamp ? element.scrollHeight > element.clientHeight : element.scrollWidth > element.clientWidth;
18495
+ if (next !== truncated.value) truncated.value = next;
18496
+ }
18479
18497
  function handleClick() {
18480
- if (!props2.expandTrigger) return;
18498
+ if (!clickable.value) return;
18481
18499
  expanding.value = !expanding.value;
18482
18500
  }
18501
+ function handleResize(entries) {
18502
+ var _a;
18503
+ const width = (_a = entries[0]) == null ? void 0 : _a.contentRect.width;
18504
+ if (width !== void 0 && width !== previousWidth && previousWidth !== void 0 && props2.expandableOnOverflow && expanding.value) expanding.value = false;
18505
+ previousWidth = width;
18506
+ checkTruncated();
18507
+ }
18508
+ useResizeObserver(getRootElement, handleResize);
18509
+ (0, vue.watch)(() => props2.lineClamp, checkTruncated);
18510
+ onSmartMounted(checkTruncated);
18511
+ (0, vue.onUpdated)(checkTruncated);
18483
18512
  return {
18513
+ rootRef,
18514
+ truncated,
18515
+ clickable,
18484
18516
  tooltipProps,
18485
18517
  expanding,
18486
18518
  rootStyles,
18487
18519
  n: n$55,
18488
18520
  classes: classes$44,
18489
- handleClick
18521
+ handleClick,
18522
+ handleResize
18490
18523
  };
18491
18524
  }
18492
18525
  });
@@ -32877,7 +32910,7 @@ var _WatermarkComponent = stdin_default$108;
32877
32910
  var stdin_default$102 = stdin_default$108;
32878
32911
  //#endregion
32879
32912
  //#region es/index.bundle.mjs
32880
- var version = "3.20.6";
32913
+ var version = "3.20.7";
32881
32914
  function install(app) {
32882
32915
  stdin_default.install && app.use(stdin_default);
32883
32916
  stdin_default$1.install && app.use(stdin_default$1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/ui",
3
- "version": "3.20.6",
3
+ "version": "3.20.7",
4
4
  "description": "A Vue3 component library based on Material Design 2 and 3, supporting mobile and desktop.",
5
5
  "keywords": [
6
6
  "Vue3",
@@ -44,9 +44,9 @@
44
44
  "@popperjs/core": "^2.11.6",
45
45
  "dayjs": "^1.10.4",
46
46
  "decimal.js": "^10.2.1",
47
- "@varlet/use": "3.20.6",
48
- "@varlet/icons": "3.20.6",
49
- "@varlet/shared": "3.20.6"
47
+ "@varlet/shared": "3.20.7",
48
+ "@varlet/icons": "3.20.7",
49
+ "@varlet/use": "3.20.7"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/node": "^20.19.0",
@@ -62,9 +62,9 @@
62
62
  "vue": "3.5.21",
63
63
  "vue-router": "4.5.1",
64
64
  "zod": "^3.23.8",
65
- "@varlet/cli": "3.20.6",
66
- "@varlet/ui": "3.20.6",
67
- "@varlet/touch-emulator": "3.20.6"
65
+ "@varlet/ui": "3.20.7",
66
+ "@varlet/cli": "3.20.7",
67
+ "@varlet/touch-emulator": "3.20.7"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "vue": "^3.2.0"
@@ -8,7 +8,9 @@ export type EllipsisExpandTrigger = 'click'
8
8
  export interface EllipsisProps extends BasicAttributes {
9
9
  expand?: boolean
10
10
  expandTrigger?: EllipsisExpandTrigger
11
+ expandableOnOverflow?: boolean
11
12
  lineClamp?: string | number
13
+ tooltipOnOverflow?: boolean
12
14
  tooltip?: boolean | TooltipProps
13
15
  'onUpdate:expand'?: ListenerProp<(expand: boolean) => void>
14
16
  }