@alxgrn/telefrag-ui 0.1.4 → 0.1.5

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 +1 @@
1
- .MainMenu{margin-top:var(--alxgrn-unit);margin-right:var(--alxgrn-unit-half)}.Sidebar .MainMenu{margin-top:0}.MainMenu .MainMenuAlternative{padding:var(--alxgrn-unit-half);border-radius:var(--alxgrn-unit-half);-webkit-user-select:none;user-select:none}.MainMenu .MainMenuAlternative:hover{background-color:var(--alxgrn-bg-panel)}.MainMenu .MainMenuAlternative:hover *{color:var(--alxgrn-color-accent)}.MainMenu .MainMenuAlternative a{display:flex;align-items:center;gap:var(--alxgrn-unit-half);cursor:pointer;color:var(--alxgrn-color-text)!important;text-decoration:none}.MainMenu .MainMenuAlternative svg{color:var(--alxgrn-color-accent);font-size:var(--alxgrn-font-size-big)}.MainMenu .MainMenuAlternative img{width:var(--alxgrn-font-size-big);height:var(--alxgrn-font-size-big);border-radius:50%;flex:0 0 auto}.MainMenu .MainMenuAlternative .MainMenuAlternativeText{font-size:var(--alxgrn-font-size);overflow-wrap:break-word;display:-webkit-box;line-clamp:1;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden;flex:1 1 auto}.MainMenu .MainMenuAlternative .MainMenuAlternativeCheck{display:block;width:var(--alxgrn-unit-half);height:var(--alxgrn-unit-half);border-radius:50%;background-color:var(--alxgrn-color-accent);flex:0 0 auto}.MainMenu .MainMenuNode,.MainMenu .MainMenuTitle{padding:var(--alxgrn-unit-half)}.MainMenu .MainMenuTitle{text-transform:uppercase;font-size:var(--alxgrn-font-size-small);font-weight:600;color:var(--alxgrn-color-light);overflow-wrap:break-word;display:-webkit-box;line-clamp:1;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden}
1
+ .MainMenu{margin-top:var(--alxgrn-unit);margin-right:var(--alxgrn-unit-half)}.Sidebar .MainMenu{margin-top:0}.MainMenu .MainMenuAlternative{padding:var(--alxgrn-unit-half);border-radius:var(--alxgrn-unit-half);-webkit-user-select:none;user-select:none}.MainMenu .MainMenuAlternative:hover{background-color:var(--alxgrn-bg-panel)}.MainMenu .MainMenuAlternative:hover *{color:var(--alxgrn-color-accent)}.MainMenu .MainMenuAlternative a{display:flex;align-items:center;gap:var(--alxgrn-unit-half);cursor:pointer;color:var(--alxgrn-color-text);text-decoration:none;border:none}.MainMenu .MainMenuAlternative svg{color:var(--alxgrn-color-accent);font-size:var(--alxgrn-font-size-big)}.MainMenu .MainMenuAlternative img{width:var(--alxgrn-font-size-big);height:var(--alxgrn-font-size-big);border-radius:50%;flex:0 0 auto}.MainMenu .MainMenuAlternative .MainMenuAlternativeText{font-size:var(--alxgrn-font-size);overflow-wrap:break-word;display:-webkit-box;line-clamp:1;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden;flex:1 1 auto}.MainMenu .MainMenuAlternative .MainMenuAlternativeCheck{display:block;width:var(--alxgrn-unit-half);height:var(--alxgrn-unit-half);border-radius:50%;background-color:var(--alxgrn-color-accent);flex:0 0 auto}.MainMenu .MainMenuNode,.MainMenu .MainMenuTitle{padding:var(--alxgrn-unit-half)}.MainMenu .MainMenuTitle{text-transform:uppercase;font-size:var(--alxgrn-font-size-small);font-weight:600;color:var(--alxgrn-color-light);overflow-wrap:break-word;display:-webkit-box;line-clamp:1;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden}
@@ -1,13 +1,7 @@
1
1
  import { default as React, PropsWithChildren } from 'react';
2
- type PropsWithMaxHeight = {
2
+ type Props = {
3
3
  maxHeight?: number;
4
- aspectRatio?: never;
5
- };
6
- type PropsWithAspectRatio = {
7
- maxHeight?: never;
8
4
  aspectRatio?: '1x1' | '16x9';
9
- };
10
- type Props = (PropsWithAspectRatio | PropsWithMaxHeight) & {
11
5
  expand?: string;
12
6
  collapse?: string;
13
7
  isCollapsable?: boolean;
@@ -1,72 +1,87 @@
1
- import { jsxs as i, jsx as a, Fragment as h } from "react/jsx-runtime";
2
- import { useState as f, useRef as E, useCallback as C, useEffect as I } from "react";
1
+ import { jsxs as x, jsx as u, Fragment as C } from "react/jsx-runtime";
2
+ import { useState as E, useRef as d, useCallback as g, useLayoutEffect as T, useEffect as L } from "react";
3
3
  import '../../../assets/Expandable.css';/* empty css */
4
- const M = 50, b = 300, j = ({
5
- children: m,
6
- maxHeight: l,
7
- aspectRatio: d = "1x1",
8
- expand: H = "Показать целиком...",
9
- collapse: g = "Свернуть...",
10
- isCollapsable: v = !0,
11
- noShadow: N
4
+ const M = 50, S = 300, _ = 1e3, D = ({
5
+ children: I,
6
+ maxHeight: f,
7
+ aspectRatio: b = "1x1",
8
+ expand: k = "Показать целиком...",
9
+ collapse: w = "Свернуть...",
10
+ isCollapsable: N = !0,
11
+ noShadow: O
12
12
  }) => {
13
- var x;
14
- const [t, u] = f(!1), [w, p] = f(!1), e = E(null), c = E(null), o = C(() => {
15
- if (l) return Math.max(l, M);
16
- const n = e.current;
17
- if (!n) return b;
18
- const r = n.clientWidth;
19
- switch (d) {
20
- case "1x1":
21
- return r;
22
- case "16x9":
23
- return Math.ceil(r / 16 * 9);
24
- default:
25
- return b;
13
+ const [c, v] = E(!1), [h, R] = E(!1), [A, H] = E("none"), r = d(null), y = d(!1), o = d(null), i = d(null), a = g(() => {
14
+ if (f !== void 0) return Math.max(f, M);
15
+ const e = r.current;
16
+ if (!e) return S;
17
+ const t = e.offsetWidth;
18
+ if (t === 0) return S;
19
+ const n = b === "16x9" ? Math.ceil(t / 16 * 9) : t;
20
+ return Math.max(n, M);
21
+ }, [f, b]), m = g(() => {
22
+ const e = r.current;
23
+ if (!e) return;
24
+ const t = e.getBoundingClientRect(), n = getComputedStyle(e);
25
+ if (t.width === 0 || t.height === 0 || n.display === "none" || n.visibility === "hidden")
26
+ return;
27
+ e.offsetHeight;
28
+ const s = e.scrollHeight, p = a();
29
+ R(s > p);
30
+ }, [a]), l = g(() => {
31
+ const e = r.current;
32
+ if (!e) return;
33
+ const t = e.querySelectorAll("img"), n = Array.from(t).filter((s) => !s.complete);
34
+ if (n.length === 0) {
35
+ m();
36
+ return;
26
37
  }
27
- }, [l, d, e]);
28
- return I(() => {
29
- const n = e.current;
30
- if (!n) return;
31
- const r = o();
32
- c.current && c.current.disconnect();
33
- const s = new ResizeObserver(() => {
34
- p(n.scrollHeight > r);
35
- });
36
- return s.observe(n), c.current = s, p(n.scrollHeight > r), () => {
37
- s && s.disconnect();
38
+ Promise.all(n.map((s) => new Promise((p) => {
39
+ s.onload = s.onerror = p;
40
+ }))).then(m);
41
+ }, [m]);
42
+ return T(() => {
43
+ if (y.current || !r.current) return;
44
+ y.current = !0;
45
+ const e = r.current, t = new MutationObserver(l);
46
+ t.observe(e, {
47
+ childList: !0,
48
+ subtree: !0
49
+ }), i.current && i.current.disconnect(), i.current = t;
50
+ const n = new ResizeObserver(l);
51
+ n.observe(e), o.current && o.current.disconnect(), o.current = n;
52
+ const s = setTimeout(l, _);
53
+ return l(), () => {
54
+ clearTimeout(s), o.current && o.current.disconnect(), i.current && i.current.disconnect();
38
55
  };
39
- }, [o]), /* @__PURE__ */ i("div", { className: "Expandable", children: [
40
- /* @__PURE__ */ a(
56
+ }, [l]), L(() => {
57
+ H(c ? r.current ? `${r.current.scrollHeight}px` : "none" : `${a()}px`);
58
+ }, [c, a]), /* @__PURE__ */ x("div", { className: "Expandable", children: [
59
+ /* @__PURE__ */ u(
41
60
  "div",
42
61
  {
43
- ref: e,
44
- className: t ? "ExpandableExpanded" : "ExpandableCollapsed",
45
- style: { maxHeight: t ? (x = e == null ? void 0 : e.current) != null && x.scrollHeight ? e.current.scrollHeight + "px" : "none" : `${o()}px` },
46
- children: m
62
+ ref: r,
63
+ className: h ? c ? "ExpandableExpanded" : "ExpandableCollapsed" : void 0,
64
+ style: h ? { maxHeight: A } : void 0,
65
+ children: I
47
66
  }
48
67
  ),
49
- w && /* @__PURE__ */ i(h, { children: [
50
- t && v && /* @__PURE__ */ a(
68
+ h && /* @__PURE__ */ x(C, { children: [
69
+ c && N && /* @__PURE__ */ u(
51
70
  "span",
52
71
  {
53
72
  className: "ExpandableButton",
54
- onClick: () => u(!1),
55
- "aria-expanded": t,
56
- "aria-controls": "collapsible-content",
57
- children: g
73
+ onClick: () => v(!1),
74
+ children: w
58
75
  }
59
76
  ),
60
- !t && /* @__PURE__ */ i(h, { children: [
61
- !N && /* @__PURE__ */ a("div", { className: "ExpandableShadow" }),
62
- /* @__PURE__ */ a(
77
+ !c && /* @__PURE__ */ x(C, { children: [
78
+ !O && /* @__PURE__ */ u("div", { className: "ExpandableShadow" }),
79
+ /* @__PURE__ */ u(
63
80
  "span",
64
81
  {
65
82
  className: "ExpandableButton",
66
- onClick: () => u(!0),
67
- "aria-expanded": t,
68
- "aria-controls": "collapsible-content",
69
- children: H
83
+ onClick: () => v(!0),
84
+ children: k
70
85
  }
71
86
  )
72
87
  ] })
@@ -74,5 +89,5 @@ const M = 50, b = 300, j = ({
74
89
  ] });
75
90
  };
76
91
  export {
77
- j as default
92
+ D as default
78
93
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alxgrn/telefrag-ui",
3
3
  "description": "UI library for The Daily Telefrag project",
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
5
5
  "private": false,
6
6
  "author": "Alexander Fedorov <alex@molner.ru>",
7
7
  "license": "Apache-2.0",