@semcore/ellipsis 2.39.0-prerelease.4 → 2.39.0

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/CHANGELOG.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
- ## [2.39.0] - 2025-02-27
5
+ ## [2.39.0] - 2025-03-14
6
6
 
7
- ### Changed
7
+ ### Added
8
8
 
9
- - Version minor update due to children dependencies update (`@semcore/utils` [4.45.1 ~> 4.47.1], `@semcore/flex-box` [5.40.1 ~> 5.41.0], `@semcore/tooltip` [6.47.3 ~> 6.48.0], `@semcore/core` [2.38.1 ~> 2.39.0]).
9
+ - Build for ESM.
10
10
 
11
11
  ## [2.38.1] - 2025-02-05
12
12
 
@@ -0,0 +1,204 @@
1
+ import J from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import I from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ import d from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import K from "@babel/runtime/helpers/esm/classCallCheck";
5
+ import Q from "@babel/runtime/helpers/esm/createClass";
6
+ import z from "@babel/runtime/helpers/esm/assertThisInitialized";
7
+ import X from "@babel/runtime/helpers/esm/inherits";
8
+ import Y from "@babel/runtime/helpers/esm/createSuper";
9
+ import E from "@babel/runtime/helpers/esm/defineProperty";
10
+ import { sstyled as Z } from "@semcore/utils/lib/core/index";
11
+ import ee, { sstyled as h, Component as te, assignProps as F } from "@semcore/core";
12
+ import i from "react";
13
+ import R from "@semcore/tooltip";
14
+ import { Box as L } from "@semcore/flex-box";
15
+ import { useResizeObserver as ie } from "./useResizeObserver.mjs";
16
+ import ne from "@semcore/utils/lib/use/useEnhancedEffect";
17
+ import re, { isAdvanceMode as oe } from "@semcore/utils/lib/findComponent";
18
+ import N from "@semcore/utils/lib/reactToText";
19
+ import W from "@semcore/utils/lib/getOriginChildren";
20
+ import D from "@semcore/utils/lib/pick";
21
+ import { forkRef as ae } from "@semcore/utils/lib/ref";
22
+ import { callAllEventHandlers as le } from "@semcore/utils/lib/assignProps";
23
+ var se = ["styles", "Children", "maxLine", "tooltip", "trim", "containerRect", "containerRef", "includeTooltipProps", "children"], de = ["styles", "text", "tooltip", "containerRect", "containerRef", "textRef", "tooltipProps", "children", "advanceMode"], ce = (
24
+ /*__reshadow_css_start__*/
25
+ (Z.insert(
26
+ /*__inner_css_start__*/
27
+ ".___SContainerMiddle_jtu7a_gg_,.___SContainer_jtu7a_gg_,.___SEllipsis_jtu7a_gg_.__middle-mod_jtu7a_gg_,.___SNoTooltipContainer_jtu7a_gg_{display:flex;overflow:hidden}.___SBeginning_jtu7a_gg_,.___SEllipsis_jtu7a_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:pre}.___SEllipsis_jtu7a_gg_.__maxLine_jtu7a_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_jtu7a);-webkit-box-orient:vertical;overflow:hidden;white-space:normal;word-wrap:break-word}.___SContainerMiddle_jtu7a_gg_>:has(.___SBeginning_jtu7a_gg_),.___SContainerMiddle_jtu7a_gg_>:has(.___STail_jtu7a_gg_){display:flex;width:100%}.___STail_jtu7a_gg_{white-space:pre}",
28
+ "jtu7a_gg_"
29
+ ), {
30
+ __SContainer: "___SContainer_jtu7a_gg_",
31
+ __SNoTooltipContainer: "___SNoTooltipContainer_jtu7a_gg_",
32
+ __SContainerMiddle: "___SContainerMiddle_jtu7a_gg_",
33
+ __SBeginning: "___SBeginning_jtu7a_gg_",
34
+ __SEllipsis: "___SEllipsis_jtu7a_gg_",
35
+ "_middle-mod": "__middle-mod_jtu7a_gg_",
36
+ _maxLine: "__maxLine_jtu7a_gg_",
37
+ "--maxLine": "--maxLine_jtu7a",
38
+ __STail: "___STail_jtu7a_gg_"
39
+ })
40
+ ), pe = ["title", "theme", "strategy", "modifiers", "placement", "interaction", "timeout", "visible", "defaultVisible", "onVisibleChange", "offset", "preventOverflow", "arrow", "flip", "computeStyles", "eventListeners", "onFirstUpdate", "cursorAnchoring"], _e = function(o, a) {
41
+ var t = window.getComputedStyle(o, null), e = document.createElement("temporary-block");
42
+ return e.style.display = t.getPropertyValue("display"), e.style.padding = t.getPropertyValue("padding"), e.style.position = "absolute", e.style.right = "0%", e.style.bottom = "0%", e.style.visibility = "hidden", e.style.fontFamily = t.getPropertyValue("font-family"), e.style.fontSize = t.getPropertyValue("font-size"), e.style.fontWeight = t.getPropertyValue("font-weight"), e.style.lineHeight = t.getPropertyValue("line-height"), e.style.whiteSpace = t.getPropertyValue("white-space"), e.style.wordWrap = t.getPropertyValue("word-wrap"), e.style.fontFeatureSettings = t.getPropertyValue("font-feature-settings"), e.style.fontVariantNumeric = t.getPropertyValue("font-variant-numeric"), e.innerHTML = a ?? o.innerHTML, e;
43
+ };
44
+ function ue(g, o, a) {
45
+ if (!g) return !1;
46
+ var t = g.getBoundingClientRect(), e = t.height, l = t.width, r = _e(g, a), n = !1;
47
+ if (document.body.appendChild(r), o) {
48
+ r.style.width = "".concat(l, "px");
49
+ var _ = r.scrollWidth, s = r.getBoundingClientRect().height;
50
+ (Math.ceil(e) < s || Math.ceil(l) < _) && (n = !0);
51
+ } else
52
+ r.style.whiteSpace = "nowrap", n = Math.ceil(l) < r.getBoundingClientRect().width;
53
+ return document.body.removeChild(r), n;
54
+ }
55
+ var U = {
56
+ forcedAdvancedMode: !0
57
+ }, me = {}, B = /* @__PURE__ */ function(g) {
58
+ X(a, g);
59
+ var o = Y(a);
60
+ function a() {
61
+ var t;
62
+ K(this, a);
63
+ for (var e = arguments.length, l = new Array(e), r = 0; r < e; r++)
64
+ l[r] = arguments[r];
65
+ return t = o.call.apply(o, [this].concat(l)), E(z(t), "state", {
66
+ visible: !1
67
+ }), E(z(t), "textRef", /* @__PURE__ */ i.createRef()), E(z(t), "handlerVisibleChange", function(n) {
68
+ t.setState({
69
+ visible: n && t.showTooltip()
70
+ });
71
+ }), t;
72
+ }
73
+ return Q(a, [{
74
+ key: "showTooltip",
75
+ value: function() {
76
+ var e = this.asProps, l = e.maxLine, r = l === void 0 ? 1 : l, n = e.Children, _ = N(W(n));
77
+ return ue(this.textRef.current, r > 1, _);
78
+ }
79
+ }, {
80
+ key: "getContentProps",
81
+ value: function() {
82
+ return {
83
+ ref: this.textRef,
84
+ maxLine: this.asProps.maxLine
85
+ };
86
+ }
87
+ }, {
88
+ key: "getPopperProps",
89
+ value: function() {
90
+ var e = this.asProps, l = e.Children, r = e.includeTooltipProps, n = N(W(l)), _ = D(this.asProps, r);
91
+ return d({
92
+ children: n
93
+ }, _);
94
+ }
95
+ }, {
96
+ key: "render",
97
+ value: function() {
98
+ var e, l, r = this.Root, n = R, _ = L, s = this.asProps, u = s.styles, c = s.Children, y = s.maxLine, m = s.tooltip, k = s.trim, M = s.containerRect, P = s.containerRef, A = s.includeTooltipProps;
99
+ s.children;
100
+ var C = I(s, se), T = this.state.visible, j = re(c, [$.Content.displayName]), x = N(j || W(c)), f = oe(c, [$.Content.displayName, $.Popper.displayName]), p = D(this.asProps, A);
101
+ if (p.visible = (l = p.visible) !== null && l !== void 0 ? l : T, p.onVisibleChange = p.onVisibleChange ? le(p.onVisibleChange, this.handlerVisibleChange) : this.handlerVisibleChange, k === "middle") {
102
+ var S;
103
+ return S = h(u), /* @__PURE__ */ i.createElement(ge, S.cn("EllipsisMiddle", d({
104
+ text: x,
105
+ styles: u,
106
+ tooltip: m,
107
+ containerRect: M,
108
+ containerRef: P,
109
+ textRef: this.textRef,
110
+ tooltipProps: p,
111
+ advanceMode: f
112
+ }, C)), /* @__PURE__ */ i.createElement(c, S.cn("Children", {})));
113
+ }
114
+ if (m) {
115
+ var v;
116
+ return v = h(u), /* @__PURE__ */ i.createElement(n, v.cn("SContainer", d(d({
117
+ interaction: "hover",
118
+ title: f ? void 0 : x
119
+ }, p), f ? U : me)), f ? /* @__PURE__ */ i.createElement(c, v.cn("Children", {})) : /* @__PURE__ */ i.createElement(r, v.cn("SEllipsis", d({
120
+ render: L,
121
+ ref: this.textRef,
122
+ maxLine: y
123
+ }, C)), /* @__PURE__ */ i.createElement(c, v.cn("Children", {}))));
124
+ }
125
+ return e = h(u), /* @__PURE__ */ i.createElement(_, e.cn("SNoTooltipContainer", {}), f ? /* @__PURE__ */ i.createElement(c, e.cn("Children", {})) : /* @__PURE__ */ i.createElement(r, e.cn("SEllipsis", d({
126
+ render: L,
127
+ ref: this.textRef,
128
+ maxLine: y
129
+ }, C)), /* @__PURE__ */ i.createElement(c, e.cn("Children", {}))));
130
+ }
131
+ }]), a;
132
+ }(te);
133
+ E(B, "displayName", "Ellipsis");
134
+ E(B, "style", ce);
135
+ E(B, "defaultProps", {
136
+ trim: "end",
137
+ tooltip: !0,
138
+ includeTooltipProps: pe,
139
+ __excludeProps: ["title"]
140
+ });
141
+ var q = /* @__PURE__ */ i.createContext(null), ge = function(o) {
142
+ var a, t = o.styles, e = o.text, l = o.tooltip, r = o.containerRect, n = o.containerRef, _ = o.textRef, s = o.tooltipProps, u = o.children, c = o.advanceMode, y = I(o, de), m = i.useRef(null), k = i.useState({
143
+ fontSize: "14",
144
+ symbolWidth: 0
145
+ }), M = J(k, 2), P = M[0], A = M[1], C = ie(m, r).width;
146
+ ne(function() {
147
+ var O = (n == null ? void 0 : n.current) || (m == null ? void 0 : m.current);
148
+ if (O) {
149
+ var w = document.createElement("temporary-block");
150
+ w.setAttribute("style", "fontSize: ".concat(P.fontSize, "px")), w.innerHTML = "a", document.body.appendChild(w);
151
+ var G = w.getBoundingClientRect();
152
+ A({
153
+ fontSize: window.getComputedStyle(O, null).getPropertyValue("font-size"),
154
+ symbolWidth: G.width
155
+ }), document.body.removeChild(w);
156
+ }
157
+ }, []);
158
+ var T = "span", j = "span", x = o.tag || L, f = R, p = i.useMemo(function() {
159
+ return Math.round(C / P.symbolWidth);
160
+ }, [C, P.symbolWidth]), S = e.length > p ? "hover" : "none", v = n ?? m, b = i.useMemo(function() {
161
+ return {
162
+ begining: e.substring(0, e.length - p / 2 - 1),
163
+ tail: e.substring(e.length - p / 2 - 1),
164
+ ref: v
165
+ };
166
+ }, [e, p]);
167
+ if (c) {
168
+ var H;
169
+ return H = h(t), /* @__PURE__ */ i.createElement(f, H.cn("SAdvancedModeContainerMiddle", d(d({
170
+ interaction: S
171
+ }, s), U)), /* @__PURE__ */ i.createElement(q.Provider, {
172
+ value: b
173
+ }, u));
174
+ }
175
+ if (l) {
176
+ var V;
177
+ return V = h(t), /* @__PURE__ */ i.createElement(x, V.cn("SContainerMiddle", d({
178
+ interaction: S,
179
+ title: e,
180
+ ref: ae(v, _),
181
+ tag: R,
182
+ __excludeProps: ["title"]
183
+ }, s)), /* @__PURE__ */ i.createElement(j, V.cn("SBeginning", {}), b.begining), /* @__PURE__ */ i.createElement(T, V.cn("STail", {}), b.tail));
184
+ }
185
+ return a = h(t), /* @__PURE__ */ i.createElement(x, a.cn("SContainerMiddle", d(d({}, y), {}, {
186
+ ref: n ?? m
187
+ })), /* @__PURE__ */ i.createElement(j, a.cn("SBeginning", {}), b.begining), /* @__PURE__ */ i.createElement(T, a.cn("STail", {}), b.tail));
188
+ }, ve = function(o) {
189
+ var a = arguments[0], t, e = o.styles, l = o.Children, r = R.Trigger, n = i.useContext(q), _ = "span", s = "span";
190
+ if (n) {
191
+ var u, c = n.begining, y = n.tail, m = n.ref;
192
+ return u = h(e), /* @__PURE__ */ i.createElement(r, u.cn("SEllipsis", d({}, F({
193
+ "middle-mod": !0,
194
+ ref: m
195
+ }, a))), /* @__PURE__ */ i.createElement(s, u.cn("SBeginning", {}), c), /* @__PURE__ */ i.createElement(_, u.cn("STail", {}), y));
196
+ }
197
+ return t = h(e), /* @__PURE__ */ i.createElement(r, t.cn("SEllipsis", d({}, F({}, a))), /* @__PURE__ */ i.createElement(l, t.cn("Children", {})));
198
+ }, $ = ee(B, {
199
+ Content: ve,
200
+ Popper: R.Popper
201
+ });
202
+ export {
203
+ $ as default
204
+ };
@@ -0,0 +1,6 @@
1
+ import { default as o } from "./Ellipsis.mjs";
2
+ import { useResizeObserver as s } from "./useResizeObserver.mjs";
3
+ export {
4
+ o as default,
5
+ s as useResizeObserver
6
+ };
@@ -0,0 +1,24 @@
1
+ import o from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import c from "react";
3
+ import m from "@semcore/utils/lib/use/useEnhancedEffect";
4
+ import R from "@semcore/utils/lib/canUseDOM";
5
+ var z = function(r, e) {
6
+ var i = c.useState(0), n = o(i, 2), s = n[0], u = n[1], a = c.useCallback(function(t) {
7
+ u(t[0].contentRect.width);
8
+ }, []);
9
+ return m(function() {
10
+ if (r.current && !e && R()) {
11
+ var t = new ResizeObserver(function(f) {
12
+ a(f);
13
+ });
14
+ return t.observe(r.current), function() {
15
+ t.disconnect();
16
+ };
17
+ }
18
+ }, [e]), e || {
19
+ width: s
20
+ };
21
+ };
22
+ export {
23
+ z as useResizeObserver
24
+ };
package/package.json CHANGED
@@ -1,20 +1,25 @@
1
1
  {
2
2
  "name": "@semcore/ellipsis",
3
3
  "description": "Semrush Ellipsis Component",
4
- "version": "2.39.0-prerelease.4",
4
+ "version": "2.39.0",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",
8
8
  "sideEffects": false,
9
9
  "author": "UI-KIT team <ui-kit-team@semrush.com>",
10
10
  "license": "MIT",
11
+ "exports": {
12
+ "require": "./lib/cjs/index.js",
13
+ "import": "./lib/esm/index.mjs",
14
+ "types": "./lib/types/index.d.ts"
15
+ },
11
16
  "dependencies": {
12
- "@semcore/utils": "4.47.1-prerelease.4",
13
- "@semcore/flex-box": "5.41.0-prerelease.4",
14
- "@semcore/tooltip": "6.48.0-prerelease.4"
17
+ "@semcore/utils": "4.48.0",
18
+ "@semcore/flex-box": "5.41.0",
19
+ "@semcore/tooltip": "6.49.0"
15
20
  },
16
21
  "peerDependencies": {
17
- "@semcore/core": "^2.39.0-prerelease.4",
22
+ "@semcore/core": "^2.17.5",
18
23
  "react": "16.8 - 18",
19
24
  "react-dom": "16.8 - 18"
20
25
  },
@@ -28,6 +33,6 @@
28
33
  "directory": "semcore/ellipsis"
29
34
  },
30
35
  "scripts": {
31
- "build": "pnpm semcore-builder --source=js"
36
+ "build": "pnpm semcore-builder --source=js && pnpm vite build"
32
37
  }
33
38
  }
package/vite.config.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { defineConfig, mergeConfig } from 'vite';
2
+
3
+ import viteConfig from '../../commonVite.config';
4
+
5
+ export default mergeConfig(
6
+ viteConfig,
7
+ defineConfig({
8
+ build: {
9
+ lib: {
10
+ entry: './src/index.js',
11
+ },
12
+ rollupOptions: {
13
+ external: ['react', 'react-dom', 'react/jsx-runtime', /@babel\/runtime\/*/, /@semcore\/*/],
14
+ },
15
+ },
16
+ }),
17
+ );