@memobit/libs 3.27.0 → 3.28.1
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/components/ColorPicker/ColorPicker.css +1 -1
- package/dist/components/ColorPicker/ColorPicker2.js +114 -114
- package/dist/components/ContextMenu/ContextMenu2.js +46 -33
- package/dist/components/Dropdown/Dropdown2.js +42 -42
- package/dist/components/MenuBar/MenuBar.css +1 -0
- package/dist/components/MenuBar/MenuBar2.js +46 -0
- package/dist/components/ToolButton/ToolButton.css +1 -0
- package/dist/components/ToolButton/ToolButton2.js +36 -0
- package/dist/components/ToolPalette/ToolPalette.css +1 -0
- package/dist/components/ToolPalette/ToolPalette2.js +83 -0
- package/dist/components/Tooltip/Tooltip2.js +72 -66
- package/dist/helpers/VersionInfo.js +1 -1
- package/dist/index.d.ts +89 -2
- package/dist/index.js +191 -185
- package/dist/memobit-icons.json +3 -0
- package/dist/version.js +2 -2
- package/dist/version.json +4 -4
- package/package.json +2 -2
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import './Dropdown.css';
|
|
2
2
|
import { Icon as R } from "../Icon/Icon2.js";
|
|
3
|
-
import { libMessages as
|
|
4
|
-
import { useMessages as
|
|
3
|
+
import { libMessages as Ge } from "../../contexts/LanguageContext/libMessages.js";
|
|
4
|
+
import { useMessages as Je } from "../../hooks/useLanguage.js";
|
|
5
5
|
import { Button as be } from "../Button/Button2.js";
|
|
6
|
-
import { Tooltip as
|
|
7
|
-
import { InputText as
|
|
6
|
+
import { Tooltip as Qe } from "../Tooltip/Tooltip2.js";
|
|
7
|
+
import { InputText as Xe } from "../InputText/InputText2.js";
|
|
8
8
|
import { foldDiacritics as Ne } from "../../helpers/Search.js";
|
|
9
9
|
/* empty css */
|
|
10
|
-
import { useEffect as L, useId as
|
|
10
|
+
import { useEffect as L, useId as Ye, useRef as O, useState as y } from "react";
|
|
11
11
|
import { jsx as s, jsxs as b } from "react/jsx-runtime";
|
|
12
|
-
import { createPortal as
|
|
13
|
-
import { caretDown as
|
|
14
|
-
var
|
|
15
|
-
const S = Ge
|
|
12
|
+
import { createPortal as Ze } from "react-dom";
|
|
13
|
+
import { caretDown as Ve, clear as $e } from "@memobit/icons";
|
|
14
|
+
var hn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", clearable: Le = !0, disabled: N = !1, error: F, highlighted: ye = !1, id: Se, label: ee, maxVisibleSelectedLabels: Ie = 1, multilineChips: Ee = !1, multiple: i = !1, name: $, onChange: p, onSearchChange: Me, options: m, placeholder: De, searchable: f = !0, searchValue: W, selectedCountDisplay: _ = "inline", showChips: H = !1, sortSelectedFirst: ne = !1, success: z, usePortal: k = !0, value: d, valueAsChip: Re = !0 }) => {
|
|
15
|
+
const S = Je(Ge), U = De ?? S.selectOption, [u, v] = y(!1), [c, l] = y(W || ""), [a, te] = y(m), [I, E] = y(-1), [o, h] = y([]), [B, Be] = y({
|
|
16
16
|
top: 0,
|
|
17
17
|
bottom: 0,
|
|
18
18
|
left: 0,
|
|
19
19
|
width: 0,
|
|
20
20
|
maxHeight: 300
|
|
21
|
-
}), [K,
|
|
21
|
+
}), [K, Te] = y(!1), M = O(null), D = O([]), P = O(null), re = O(null), oe = Ye(), ie = Se ?? `dropdown-${oe}`, q = O(null), se = O(o);
|
|
22
22
|
L(() => {
|
|
23
23
|
se.current = o;
|
|
24
24
|
}), L(() => {
|
|
@@ -100,19 +100,19 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
100
100
|
const n = () => {
|
|
101
101
|
if (!M.current) return;
|
|
102
102
|
const t = M.current.getBoundingClientRect(), r = window.visualViewport, g = r?.offsetTop ?? 0, Y = g + (r?.height ?? window.innerHeight), we = 300, Z = 8, V = Y - t.bottom, me = t.top - g, ge = V < we && me > V;
|
|
103
|
-
if (
|
|
104
|
-
const
|
|
103
|
+
if (Te(ge), k) {
|
|
104
|
+
const Ke = Math.max(0, (ge ? me : V) - Z), A = re.current;
|
|
105
105
|
if (A && C.current === null) {
|
|
106
|
-
const
|
|
107
|
-
A.style.width = "max-content", C.current = A.offsetWidth, A.style.width =
|
|
106
|
+
const qe = A.style.width;
|
|
107
|
+
A.style.width = "max-content", C.current = A.offsetWidth, A.style.width = qe;
|
|
108
108
|
}
|
|
109
|
-
const
|
|
110
|
-
|
|
109
|
+
const Pe = 360, ve = document.documentElement.clientWidth, xe = Math.max(t.width, Math.min(C.current ?? t.width, Pe, ve - 16));
|
|
110
|
+
Be({
|
|
111
111
|
top: t.bottom,
|
|
112
112
|
bottom: window.innerHeight - t.top,
|
|
113
113
|
left: Math.max(Z, Math.min(t.left, ve - Z - xe)),
|
|
114
114
|
width: xe,
|
|
115
|
-
maxHeight: Math.min(we,
|
|
115
|
+
maxHeight: Math.min(we, Ke)
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
};
|
|
@@ -183,15 +183,15 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
183
183
|
}, de = (n) => {
|
|
184
184
|
const e = o.filter((t) => t.value !== n.value);
|
|
185
185
|
h(e), p && (i ? (j.current = !0, p(e, $)) : (p(null, $), f || l("")));
|
|
186
|
-
},
|
|
186
|
+
}, Ae = () => {
|
|
187
187
|
h([]), (!f || !i) && l(""), v(!1), p && p(i ? [] : null, $);
|
|
188
|
-
},
|
|
189
|
-
l(n), u || v(!0),
|
|
188
|
+
}, We = (n) => {
|
|
189
|
+
l(n), u || v(!0), Me?.(n);
|
|
190
190
|
}, le = () => {
|
|
191
191
|
N || (v(!0), !i && f && o.length > 0 && l(""), (i || f) && P.current?.focus());
|
|
192
|
-
},
|
|
192
|
+
}, He = () => {
|
|
193
193
|
N || (v(!u), u || (E(-1), !i && f && o.length > 0 && l(""), (i || f) && P.current?.focus()));
|
|
194
|
-
},
|
|
194
|
+
}, je = (n) => {
|
|
195
195
|
if (!N) {
|
|
196
196
|
if (!u) {
|
|
197
197
|
(n.key === "ArrowDown" || n.key === "Enter") && (v(!0), n.preventDefault());
|
|
@@ -222,16 +222,16 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
222
222
|
i && c === "" && o.length > 0 && (n.preventDefault(), de(o[o.length - 1]));
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
}, Q = (n) => o.some((e) => e.value === n.value),
|
|
225
|
+
}, Q = (n) => o.some((e) => e.value === n.value), Ce = () => {
|
|
226
226
|
if (o.length === 0) return "";
|
|
227
|
-
const n = Math.max(1,
|
|
227
|
+
const n = Math.max(1, Ie);
|
|
228
228
|
if (o.length <= n) return o.map((r) => r.label).join(", ");
|
|
229
229
|
const e = o.slice(0, n).map((r) => r.label).join(", "), t = o.length - n;
|
|
230
230
|
return S.selectedWithOthers(e, t);
|
|
231
|
-
},
|
|
231
|
+
}, Fe = () => i && H || f && u ? c : o.length > 0 ? i ? Ce() : o[0].label : "", _e = () => i && H ? o.length > 0 ? "" : U : u && f ? U : o.length > 0 ? "" : U, ze = () => !i || o.length === 0 || _ === "none" ? null : _ === "floating" ? /* @__PURE__ */ s("div", {
|
|
232
232
|
className: "dropdown-selected-count",
|
|
233
233
|
children: S.selectedCount(o.length)
|
|
234
|
-
}) : null, ae = () => !!(w && c && c.trim() && !a.some((n) => n.label.toLowerCase() === c.toLowerCase() || n.value.toString() === c)),
|
|
234
|
+
}) : null, ae = () => !!(w && c && c.trim() && !a.some((n) => n.label.toLowerCase() === c.toLowerCase() || n.value.toString() === c)), Ue = () => {
|
|
235
235
|
if (!u || N) return null;
|
|
236
236
|
const n = /* @__PURE__ */ s("div", {
|
|
237
237
|
ref: re,
|
|
@@ -318,10 +318,10 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
318
318
|
children: S.noOptions
|
|
319
319
|
})
|
|
320
320
|
});
|
|
321
|
-
return k ?
|
|
322
|
-
}, x = !i && o.length === 1 ? o[0] : null, T =
|
|
321
|
+
return k ? Ze(n, document.body) : n;
|
|
322
|
+
}, x = !i && o.length === 1 ? o[0] : null, T = Re && !u && !i && o.length > 0, fe = !!(x?.icon && !c && !T), ue = !!(x?.suffixIcon && !T), X = i && H, pe = Le && o.length > 0, he = f || w;
|
|
323
323
|
return /* @__PURE__ */ b("div", {
|
|
324
|
-
className: `dropdown-container ${F ? "dropdown-error" : ""} ${z ? "dropdown-success" : ""} ${
|
|
324
|
+
className: `dropdown-container ${F ? "dropdown-error" : ""} ${z ? "dropdown-success" : ""} ${ye ? "dropdown-highlighted" : ""} ${i ? "multiple" : ""} ${N ? "disabled" : ""} ${i ? `count-display-${_}` : ""} ${ke}`,
|
|
325
325
|
ref: M,
|
|
326
326
|
children: [
|
|
327
327
|
ee && /* @__PURE__ */ s("label", {
|
|
@@ -330,7 +330,7 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
330
330
|
children: ee
|
|
331
331
|
}),
|
|
332
332
|
/* @__PURE__ */ b("div", {
|
|
333
|
-
className: `dropdown-input-container ${fe ? "dropdown-input-container--has-prefix-icon" : ""} ${ue ? "dropdown-input-container--has-suffix-icon" : ""} ${X ? "dropdown-input-container--chips" : ""} ${X &&
|
|
333
|
+
className: `dropdown-input-container ${fe ? "dropdown-input-container--has-prefix-icon" : ""} ${ue ? "dropdown-input-container--has-suffix-icon" : ""} ${X ? "dropdown-input-container--chips" : ""} ${X && Ee ? "dropdown-input-container--chips-multiline" : ""} ${pe ? "dropdown-input-container--clearable" : ""}`,
|
|
334
334
|
children: [
|
|
335
335
|
fe && x?.icon && /* @__PURE__ */ s("span", {
|
|
336
336
|
className: "dropdown-selected-icon dropdown-selected-icon--prefix",
|
|
@@ -349,7 +349,7 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
349
349
|
children: [/* @__PURE__ */ s("span", {
|
|
350
350
|
className: "dropdown-chip__label",
|
|
351
351
|
children: n.label
|
|
352
|
-
}), /* @__PURE__ */ s(
|
|
352
|
+
}), /* @__PURE__ */ s(Qe, {
|
|
353
353
|
title: S.remove,
|
|
354
354
|
children: /* @__PURE__ */ s("button", {
|
|
355
355
|
type: "button",
|
|
@@ -362,14 +362,14 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
362
362
|
})
|
|
363
363
|
})]
|
|
364
364
|
}, `dd-chip-${n.value}`)),
|
|
365
|
-
/* @__PURE__ */ s(
|
|
365
|
+
/* @__PURE__ */ s(Xe, {
|
|
366
366
|
ref: P,
|
|
367
367
|
id: ie,
|
|
368
|
-
placeholder: T ? "" :
|
|
369
|
-
value: T ? "" :
|
|
370
|
-
onChange: he ?
|
|
368
|
+
placeholder: T ? "" : _e(),
|
|
369
|
+
value: T ? "" : Fe(),
|
|
370
|
+
onChange: he ? We : void 0,
|
|
371
371
|
onClick: le,
|
|
372
|
-
onKeyDown:
|
|
372
|
+
onKeyDown: je,
|
|
373
373
|
autoComplete: "off",
|
|
374
374
|
autoFocus: Oe,
|
|
375
375
|
disabled: N,
|
|
@@ -386,7 +386,7 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
386
386
|
className: "dropdown-action-button dropdown-clear-button",
|
|
387
387
|
children: /* @__PURE__ */ s(be, {
|
|
388
388
|
variant: "plain",
|
|
389
|
-
onClick:
|
|
389
|
+
onClick: Ae,
|
|
390
390
|
disabled: N,
|
|
391
391
|
children: $e
|
|
392
392
|
})
|
|
@@ -395,17 +395,17 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
395
395
|
className: `dropdown-action-button dropdown-toggle-button ${u ? "open" : ""}`,
|
|
396
396
|
children: /* @__PURE__ */ s(be, {
|
|
397
397
|
variant: "plain",
|
|
398
|
-
onClick:
|
|
398
|
+
onClick: He,
|
|
399
399
|
disabled: N,
|
|
400
|
-
children:
|
|
400
|
+
children: Ve
|
|
401
401
|
})
|
|
402
402
|
})
|
|
403
403
|
]
|
|
404
404
|
}),
|
|
405
|
-
|
|
405
|
+
ze()
|
|
406
406
|
]
|
|
407
407
|
}),
|
|
408
|
-
|
|
408
|
+
Ue(),
|
|
409
409
|
F && /* @__PURE__ */ s("span", {
|
|
410
410
|
className: "dropdown-error-message",
|
|
411
411
|
children: F
|
|
@@ -418,5 +418,5 @@ var pn = ({ allowCustomValue: w = !1, autofocus: Oe = !1, className: ke = "", di
|
|
|
418
418
|
});
|
|
419
419
|
};
|
|
420
420
|
export {
|
|
421
|
-
|
|
421
|
+
hn as Dropdown
|
|
422
422
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.menu-bar{align-items:center;gap:var(--spacing-2);display:flex}.menu-bar__menu{position:relative}.menu-bar__title{padding:var(--spacing-4) var(--spacing-8);border-radius:var(--radius-sm);color:var(--body-color);font:inherit;font-size:var(--font-size-sm);cursor:default;background:0 0;border:none}.menu-bar__title:hover,.menu-bar__title--open{background:var(--list-hover-background-color)}.menu-bar__list{z-index:1200;min-width:200px;padding:var(--spacing-4);background:var(--popover-background-color);border:1px solid var(--popover-border-color);border-radius:var(--radius);box-shadow:0 var(--spacing-8) var(--spacing-24) var(--box-shadow);flex-direction:column;display:flex;position:absolute;top:100%;left:0}.menu-bar__item{justify-content:space-between;align-items:center;gap:var(--spacing-24);padding:var(--spacing-6) var(--spacing-8);border-radius:var(--radius-sm);color:var(--popover-color);font:inherit;font-size:var(--font-size-sm);text-align:left;white-space:nowrap;cursor:default;background:0 0;border:none;display:flex}.menu-bar__item:hover:not(:disabled){background:color-mix(in srgb, var(--body-accent-color) 16%, transparent)}.menu-bar__item:disabled{color:var(--body-color-muted);opacity:.6}.menu-bar__shortcut{color:var(--body-color-muted);font-size:var(--font-size-xs)}.menu-bar__separator{height:1px;margin:var(--spacing-4) var(--spacing-2);background:var(--delimiter-color)}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import './MenuBar.css';
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { useEffect as d, useRef as m, useState as b } from "react";
|
|
4
|
+
import { jsx as a, jsxs as u } from "react/jsx-runtime";
|
|
5
|
+
var w = ({ menus: i, className: o }) => {
|
|
6
|
+
const [r, s] = b(null), l = m(null);
|
|
7
|
+
return d(() => {
|
|
8
|
+
if (r === null) return;
|
|
9
|
+
const n = (e) => {
|
|
10
|
+
e instanceof KeyboardEvent && e.key !== "Escape" || e instanceof MouseEvent && e.target instanceof Node && l.current?.contains(e.target) || s(null);
|
|
11
|
+
};
|
|
12
|
+
return window.addEventListener("mousedown", n), window.addEventListener("keydown", n), () => {
|
|
13
|
+
window.removeEventListener("mousedown", n), window.removeEventListener("keydown", n);
|
|
14
|
+
};
|
|
15
|
+
}, [r]), /* @__PURE__ */ a("div", {
|
|
16
|
+
className: `menu-bar${o ? ` ${o}` : ""}`,
|
|
17
|
+
ref: l,
|
|
18
|
+
children: i.map((n, e) => /* @__PURE__ */ u("div", {
|
|
19
|
+
className: "menu-bar__menu",
|
|
20
|
+
children: [/* @__PURE__ */ a("button", {
|
|
21
|
+
type: "button",
|
|
22
|
+
className: `menu-bar__title${r === e ? " menu-bar__title--open" : ""}`,
|
|
23
|
+
onClick: () => s(r === e ? null : e),
|
|
24
|
+
onMouseEnter: () => r !== null && s(e),
|
|
25
|
+
children: n.label
|
|
26
|
+
}), r === e && /* @__PURE__ */ a("div", {
|
|
27
|
+
className: "menu-bar__list",
|
|
28
|
+
children: n.entries.map((t, c) => t === "separator" ? /* @__PURE__ */ a("div", { className: "menu-bar__separator" }, `separator-${c}`) : /* @__PURE__ */ u("button", {
|
|
29
|
+
type: "button",
|
|
30
|
+
className: "menu-bar__item",
|
|
31
|
+
disabled: t.disabled,
|
|
32
|
+
onClick: () => {
|
|
33
|
+
s(null), t.onSelect();
|
|
34
|
+
},
|
|
35
|
+
children: [/* @__PURE__ */ a("span", { children: t.label }), t.shortcut && /* @__PURE__ */ a("span", {
|
|
36
|
+
className: "menu-bar__shortcut",
|
|
37
|
+
children: t.shortcut
|
|
38
|
+
})]
|
|
39
|
+
}, t.label))
|
|
40
|
+
})]
|
|
41
|
+
}, n.label))
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
w as MenuBar
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.tool-button--active.button,.tool-button--active.button:hover{background:var(--list-hover-background-color);color:var(--body-accent-color)}.tool-button--danger.button:not(:disabled),.tool-button--danger.button:not(:disabled):hover{color:var(--body-danger-color)}.tool-button--mirrored svg{transform:scaleX(-1)}.tool-button__badged{display:flex;position:relative}.tool-button__badged--disabled{opacity:.5}.tool-button__badge{padding:0 var(--spacing-2);border-radius:var(--radius-sm);background:var(--body-accent-color);color:var(--button-info-color);font-size:var(--font-size-xxs);font-weight:var(--font-weight-bold);line-height:var(--line-height-tight);pointer-events:none;position:absolute;bottom:0;right:0}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import './ToolButton.css';
|
|
2
|
+
import { Button as p } from "../Button/Button2.js";
|
|
3
|
+
import { Tooltip as d } from "../Tooltip/Tooltip2.js";
|
|
4
|
+
/* empty css */
|
|
5
|
+
import { jsx as t, jsxs as _ } from "react/jsx-runtime";
|
|
6
|
+
var v = ({ icon: r, hint: a, onClick: s, disabled: o, active: e, danger: i, mirrored: m, badge: n, hintPosition: u = "bottom", className: b }) => {
|
|
7
|
+
const c = [
|
|
8
|
+
"tool-button",
|
|
9
|
+
m && "tool-button--mirrored",
|
|
10
|
+
i && "tool-button--danger",
|
|
11
|
+
e && "tool-button--active",
|
|
12
|
+
b
|
|
13
|
+
].filter(Boolean).join(" "), l = /* @__PURE__ */ t(p, {
|
|
14
|
+
variant: "plain",
|
|
15
|
+
size: "small",
|
|
16
|
+
icon: r,
|
|
17
|
+
onClick: s,
|
|
18
|
+
disabled: o,
|
|
19
|
+
className: c
|
|
20
|
+
});
|
|
21
|
+
return /* @__PURE__ */ t(d, {
|
|
22
|
+
title: a,
|
|
23
|
+
position: u,
|
|
24
|
+
disabled: o,
|
|
25
|
+
children: n ? /* @__PURE__ */ _("span", {
|
|
26
|
+
className: `tool-button__badged${o ? " tool-button__badged--disabled" : ""}`,
|
|
27
|
+
children: [l, /* @__PURE__ */ t("span", {
|
|
28
|
+
className: "tool-button__badge",
|
|
29
|
+
children: n
|
|
30
|
+
})]
|
|
31
|
+
}) : l
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
v as ToolButton
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.tool-palette{--tool-palette-slot:38px;align-items:center;gap:var(--spacing-12);padding:var(--spacing-8) var(--spacing-4);background:var(--card-background-color);border-right:1px solid var(--border-color);flex-direction:column;flex:none;display:flex}.tool-palette__tools{width:calc(var(--tool-palette-slot) * var(--tool-palette-columns));flex-wrap:wrap;display:flex}.tool-palette__slot{width:var(--tool-palette-slot);justify-content:center;display:flex;position:relative}.tool-palette__slot--grouped:after{right:var(--spacing-2);bottom:var(--spacing-2);border-bottom:var(--spacing-4) solid var(--body-color-muted);border-left:var(--spacing-4) solid transparent;content:"";pointer-events:none;width:0;height:0;position:absolute}.tool-palette__menu{min-width:200px;padding:var(--spacing-4);flex-direction:column;display:flex}.tool-palette__menu-item.button{justify-content:flex-start;width:100%}.tool-palette__menu-item--active.button{color:var(--body-accent-color)}.tool-palette__menu-label{text-align:left;flex:1}.tool-palette__menu-shortcut{margin-left:var(--spacing-24);color:var(--body-color-muted);font-size:var(--font-size-xs)}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import './ToolPalette.css';
|
|
2
|
+
import { Button as v } from "../Button/Button2.js";
|
|
3
|
+
import { ContextMenu as w } from "../ContextMenu/ContextMenu2.js";
|
|
4
|
+
import { ToolButton as j } from "../ToolButton/ToolButton2.js";
|
|
5
|
+
/* empty css */
|
|
6
|
+
import { useState as m } from "react";
|
|
7
|
+
import { jsx as e, jsxs as _ } from "react/jsx-runtime";
|
|
8
|
+
var D = ({ items: f, activeId: n, onSelect: x, columns: $ = 2, children: b, className: h }) => {
|
|
9
|
+
const c = /* @__PURE__ */ new Map();
|
|
10
|
+
for (const t of f) {
|
|
11
|
+
const o = t.group ?? t.id;
|
|
12
|
+
c.set(o, [...c.get(o) ?? [], t]);
|
|
13
|
+
}
|
|
14
|
+
const [y, C] = m({}), [s, a] = m(null), i = (t) => t.group ?? t.id, p = (t) => t.find((o) => o.id === n) ?? t.find((o) => o.id === y[i(t[0])]) ?? t[0], r = (t) => {
|
|
15
|
+
C((o) => ({
|
|
16
|
+
...o,
|
|
17
|
+
[i(t)]: t.id
|
|
18
|
+
})), x(t.id);
|
|
19
|
+
}, N = (t) => {
|
|
20
|
+
const o = p(t);
|
|
21
|
+
o.id !== n || t.length === 1 ? r(o) : r(t[(t.indexOf(o) + 1) % t.length]);
|
|
22
|
+
}, k = (t, o) => {
|
|
23
|
+
t.preventDefault(), o.length > 1 && a({
|
|
24
|
+
group: o,
|
|
25
|
+
x: t.clientX,
|
|
26
|
+
y: t.clientY
|
|
27
|
+
});
|
|
28
|
+
}, u = (t) => t.shortcut ? `${t.label} (${t.shortcut})` : t.label, M = { "--tool-palette-columns": $ };
|
|
29
|
+
return /* @__PURE__ */ _("nav", {
|
|
30
|
+
className: `tool-palette${h ? ` ${h}` : ""}`,
|
|
31
|
+
style: M,
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ e("div", {
|
|
34
|
+
className: "tool-palette__tools",
|
|
35
|
+
children: [...c.values()].map((t) => {
|
|
36
|
+
const o = p(t), d = t.filter((l) => l !== o).map((l) => l.label);
|
|
37
|
+
return /* @__PURE__ */ e("span", {
|
|
38
|
+
className: `tool-palette__slot${t.length > 1 ? " tool-palette__slot--grouped" : ""}`,
|
|
39
|
+
onContextMenu: (l) => k(l, t),
|
|
40
|
+
children: /* @__PURE__ */ e(j, {
|
|
41
|
+
icon: o.icon,
|
|
42
|
+
hint: d.length > 0 ? `${u(o)} · also ${d.join(", ")}` : u(o),
|
|
43
|
+
hintPosition: "right",
|
|
44
|
+
onClick: () => N(t),
|
|
45
|
+
active: o.id === n
|
|
46
|
+
})
|
|
47
|
+
}, i(o));
|
|
48
|
+
})
|
|
49
|
+
}),
|
|
50
|
+
b,
|
|
51
|
+
s && /* @__PURE__ */ e(w, {
|
|
52
|
+
position: {
|
|
53
|
+
x: s.x,
|
|
54
|
+
y: s.y
|
|
55
|
+
},
|
|
56
|
+
onClose: () => a(null),
|
|
57
|
+
autoClose: !0,
|
|
58
|
+
children: /* @__PURE__ */ e("div", {
|
|
59
|
+
className: "tool-palette__menu",
|
|
60
|
+
children: s.group.map((t) => /* @__PURE__ */ _(v, {
|
|
61
|
+
variant: "plain",
|
|
62
|
+
size: "small",
|
|
63
|
+
icon: t.icon,
|
|
64
|
+
className: `tool-palette__menu-item${t.id === n ? " tool-palette__menu-item--active" : ""}`,
|
|
65
|
+
onClick: () => {
|
|
66
|
+
a(null), r(t);
|
|
67
|
+
},
|
|
68
|
+
children: [/* @__PURE__ */ e("span", {
|
|
69
|
+
className: "tool-palette__menu-label",
|
|
70
|
+
children: t.label
|
|
71
|
+
}), t.shortcut && /* @__PURE__ */ e("span", {
|
|
72
|
+
className: "tool-palette__menu-shortcut",
|
|
73
|
+
children: t.shortcut
|
|
74
|
+
})]
|
|
75
|
+
}, t.id))
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
D as ToolPalette
|
|
83
|
+
};
|
|
@@ -1,108 +1,114 @@
|
|
|
1
1
|
import './Tooltip.css';
|
|
2
2
|
/* empty css */
|
|
3
|
-
import { createContext as
|
|
4
|
-
import { Fragment as
|
|
5
|
-
import { createPortal as
|
|
6
|
-
var j =
|
|
7
|
-
const [g, u] =
|
|
3
|
+
import { createContext as H, useCallback as F, useContext as tt, useEffect as C, useRef as w, useState as P } from "react";
|
|
4
|
+
import { Fragment as et, jsx as x, jsxs as V } from "react/jsx-runtime";
|
|
5
|
+
import { createPortal as rt } from "react-dom";
|
|
6
|
+
var j = H(null), lt = ({ title: y, position: c = "top", delay: z = 200, children: q, disabled: E = !1, className: A = "", maxWidth: p, maxHeight: f }) => {
|
|
7
|
+
const [g, u] = P(!1), [D, G] = P(0), m = tt(j), [d, J] = P({
|
|
8
8
|
top: 0,
|
|
9
9
|
left: 0
|
|
10
|
-
}),
|
|
11
|
-
|
|
10
|
+
}), s = w(null), n = w(null), a = w(null), h = w(null), v = w(!1), T = f !== void 0, M = T ? 150 : 0, B = !!y && !E, $ = g && B && D === 0, N = g && B || D > 0, K = F((e) => {
|
|
11
|
+
G((t) => Math.max(0, t + (e ? 1 : -1)));
|
|
12
12
|
}, []);
|
|
13
13
|
C(() => {
|
|
14
|
-
if (!(!
|
|
15
|
-
return
|
|
16
|
-
}, [N,
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
19
|
-
const
|
|
20
|
-
let
|
|
21
|
-
if (
|
|
14
|
+
if (!(!m || !N))
|
|
15
|
+
return m(!0), () => m(!1);
|
|
16
|
+
}, [N, m]);
|
|
17
|
+
const R = F(() => {
|
|
18
|
+
if (!a.current || !h.current) return;
|
|
19
|
+
const e = a.current.firstElementChild?.getBoundingClientRect();
|
|
20
|
+
let t = e && e.width > 0 ? e : a.current.getBoundingClientRect();
|
|
21
|
+
if (t.width === 0 && t.height === 0) {
|
|
22
22
|
const _ = document.createRange();
|
|
23
|
-
_.selectNodeContents(
|
|
24
|
-
const
|
|
25
|
-
(
|
|
23
|
+
_.selectNodeContents(a.current);
|
|
24
|
+
const L = _.getBoundingClientRect();
|
|
25
|
+
(L.width > 0 || L.height > 0) && (t = L);
|
|
26
26
|
}
|
|
27
|
-
const r =
|
|
27
|
+
const r = h.current.getBoundingClientRect(), b = 8;
|
|
28
28
|
let o = 0, i = 0;
|
|
29
|
-
switch (
|
|
29
|
+
switch (c) {
|
|
30
30
|
case "top":
|
|
31
|
-
o =
|
|
31
|
+
o = t.top - r.height - b, i = t.left + t.width / 2 - r.width / 2;
|
|
32
32
|
break;
|
|
33
33
|
case "bottom":
|
|
34
|
-
o =
|
|
34
|
+
o = t.bottom + b, i = t.left + t.width / 2 - r.width / 2;
|
|
35
35
|
break;
|
|
36
36
|
case "left":
|
|
37
|
-
o =
|
|
37
|
+
o = t.top + t.height / 2 - r.height / 2, i = t.left - r.width - b;
|
|
38
38
|
break;
|
|
39
39
|
case "right":
|
|
40
|
-
o =
|
|
40
|
+
o = t.top + t.height / 2 - r.height / 2, i = t.right + b;
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
i <
|
|
42
|
+
const l = 8;
|
|
43
|
+
i < l && (i = l), i + r.width > window.innerWidth - l && (i = window.innerWidth - r.width - l), o < l && (o = l), o + r.height > window.innerHeight - l && (o = window.innerHeight - r.height - l);
|
|
44
|
+
const k = 12, I = c === "top" || c === "bottom", X = I ? t.left + t.width / 2 - i : t.top + t.height / 2 - o, Y = I ? r.width : r.height, Z = Math.min(Math.max(X, k), Y - k);
|
|
45
|
+
J({
|
|
44
46
|
top: o,
|
|
45
|
-
left: i
|
|
47
|
+
left: i,
|
|
48
|
+
arrowOffset: Z
|
|
46
49
|
});
|
|
47
|
-
}, [
|
|
48
|
-
E ||
|
|
50
|
+
}, [c]), S = () => {
|
|
51
|
+
E || v.current || (n.current && (clearTimeout(n.current), n.current = null), s.current = setTimeout(() => {
|
|
49
52
|
u(!0);
|
|
50
53
|
}, z));
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
|
|
54
|
+
}, O = () => {
|
|
55
|
+
v.current || (s.current && clearTimeout(s.current), M > 0 ? n.current = setTimeout(() => u(!1), M) : u(!1));
|
|
56
|
+
}, Q = (e) => {
|
|
57
|
+
e.pointerType !== "touch" && e.pointerType !== "pen" || E || (v.current = !0, s.current && (clearTimeout(s.current), s.current = null), e.stopPropagation(), u((t) => !t));
|
|
55
58
|
};
|
|
56
59
|
C(() => {
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
+
if (!$) return;
|
|
61
|
+
const e = (t) => {
|
|
62
|
+
t.target instanceof Node && h.current?.contains(t.target) || u(!1);
|
|
60
63
|
};
|
|
61
|
-
return
|
|
62
|
-
window.removeEventListener("scroll",
|
|
64
|
+
return R(), window.addEventListener("scroll", e, !0), window.addEventListener("resize", R), () => {
|
|
65
|
+
window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", R);
|
|
63
66
|
};
|
|
64
|
-
}, [
|
|
67
|
+
}, [$, R]), C(() => {
|
|
65
68
|
if (!g) return;
|
|
66
|
-
const
|
|
67
|
-
|
|
69
|
+
const e = (t) => {
|
|
70
|
+
a.current?.contains(t.target) || h.current?.contains(t.target) || u(!1);
|
|
68
71
|
};
|
|
69
|
-
return document.addEventListener("pointerdown",
|
|
70
|
-
document.removeEventListener("pointerdown",
|
|
72
|
+
return document.addEventListener("pointerdown", e), () => {
|
|
73
|
+
document.removeEventListener("pointerdown", e), v.current = !1;
|
|
71
74
|
};
|
|
72
75
|
}, [g]), C(() => () => {
|
|
73
|
-
|
|
76
|
+
s.current && clearTimeout(s.current), n.current && clearTimeout(n.current);
|
|
74
77
|
}, []);
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
|
|
78
|
+
const U = () => {
|
|
79
|
+
T && n.current && (clearTimeout(n.current), n.current = null);
|
|
80
|
+
}, W = () => {
|
|
81
|
+
T && (n.current = setTimeout(() => u(!1), M));
|
|
79
82
|
};
|
|
80
|
-
return /* @__PURE__ */
|
|
81
|
-
ref:
|
|
83
|
+
return /* @__PURE__ */ V(et, { children: [/* @__PURE__ */ x("span", {
|
|
84
|
+
ref: a,
|
|
82
85
|
className: "tooltip-trigger",
|
|
83
86
|
onMouseEnter: S,
|
|
84
|
-
onMouseLeave:
|
|
87
|
+
onMouseLeave: O,
|
|
85
88
|
onFocus: S,
|
|
86
|
-
onBlur:
|
|
87
|
-
onPointerDown:
|
|
88
|
-
children: /* @__PURE__ */
|
|
89
|
-
value:
|
|
90
|
-
children:
|
|
89
|
+
onBlur: O,
|
|
90
|
+
onPointerDown: Q,
|
|
91
|
+
children: /* @__PURE__ */ x(j.Provider, {
|
|
92
|
+
value: K,
|
|
93
|
+
children: q
|
|
91
94
|
})
|
|
92
|
-
}),
|
|
93
|
-
ref:
|
|
94
|
-
className: `tooltip tooltip--${
|
|
95
|
+
}), $ && rt(/* @__PURE__ */ V("div", {
|
|
96
|
+
ref: h,
|
|
97
|
+
className: `tooltip tooltip--${c} ${T ? "tooltip--scrollable" : ""} ${A}`,
|
|
95
98
|
style: {
|
|
96
|
-
top: `${
|
|
97
|
-
left: `${
|
|
99
|
+
top: `${d.top}px`,
|
|
100
|
+
left: `${d.left}px`,
|
|
98
101
|
...p !== void 0 && { maxWidth: typeof p == "number" ? `${p}px` : p },
|
|
99
|
-
...
|
|
102
|
+
...f !== void 0 && { maxHeight: typeof f == "number" ? `${f}px` : f }
|
|
100
103
|
},
|
|
101
|
-
onMouseEnter:
|
|
102
|
-
onMouseLeave:
|
|
103
|
-
children: [y, /* @__PURE__ */
|
|
104
|
+
onMouseEnter: U,
|
|
105
|
+
onMouseLeave: W,
|
|
106
|
+
children: [y, /* @__PURE__ */ x("div", {
|
|
107
|
+
className: `tooltip__arrow tooltip__arrow--${c}`,
|
|
108
|
+
style: d.arrowOffset === void 0 ? void 0 : c === "top" || c === "bottom" ? { left: `${d.arrowOffset}px` } : { top: `${d.arrowOffset}px` }
|
|
109
|
+
})]
|
|
104
110
|
}), document.body)] });
|
|
105
111
|
};
|
|
106
112
|
export {
|
|
107
|
-
|
|
113
|
+
lt as Tooltip
|
|
108
114
|
};
|