zuii 1.4.7 → 1.4.8
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/Context-menu/js/context-menu.d.ts +3 -1
- package/dist/components/Context-menu/js/context-menu.js +21 -18
- package/dist/components/Context-menu/react/index.js +46 -41
- package/dist/components/Dropdown/react/index.d.ts +6 -1
- package/dist/components/Dropdown/react/index.js +22 -20
- package/dist/templates/Dropdowns/Dropdowns.tsx +3 -0
- package/package.json +1 -1
|
@@ -31,9 +31,11 @@ export declare const isItemDisabled: (item: ContextMenuItem) => boolean;
|
|
|
31
31
|
* @param {number} y - Position Y souhaitée.
|
|
32
32
|
* @param {number} menuWidth - Largeur du menu.
|
|
33
33
|
* @param {number} menuHeight - Hauteur du menu.
|
|
34
|
+
* @param {number} [offsetX=2] - Décalage horizontal par rapport au clic.
|
|
35
|
+
* @param {number} [offsetY=2] - Décalage vertical par rapport au clic.
|
|
34
36
|
* @returns {{x: number, y: number}} La position corrigée.
|
|
35
37
|
*/
|
|
36
|
-
export declare const calculatePosition: (x: number, y: number, menuWidth: number, menuHeight: number) => {
|
|
38
|
+
export declare const calculatePosition: (x: number, y: number, menuWidth: number, menuHeight: number, offsetX?: number, offsetY?: number) => {
|
|
37
39
|
x: number;
|
|
38
40
|
y: number;
|
|
39
41
|
};
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
const
|
|
1
|
+
const c = (t) => {
|
|
2
2
|
const e = t.items && t.items.length > 0;
|
|
3
3
|
return !!(t.disabled || !e && !t.onAction && !t.action && t.type !== "separator");
|
|
4
|
-
},
|
|
5
|
-
let l = t, i = e;
|
|
6
|
-
return
|
|
7
|
-
|
|
4
|
+
}, s = (t, e, o, a, n = 2, r = 2) => {
|
|
5
|
+
let l = t + n, i = e + r;
|
|
6
|
+
return l + o > window.innerWidth && (l = t - o - n), i + a > window.innerHeight && (i = e - a - r), {
|
|
7
|
+
x: Math.max(0, Math.min(l, window.innerWidth - o)),
|
|
8
|
+
y: Math.max(0, Math.min(i, window.innerHeight - a))
|
|
9
|
+
};
|
|
10
|
+
}, d = () => {
|
|
8
11
|
document.body.style.overflow = "hidden";
|
|
9
|
-
},
|
|
12
|
+
}, b = () => {
|
|
10
13
|
document.body.style.overflow = "";
|
|
11
|
-
},
|
|
14
|
+
}, h = (t) => {
|
|
12
15
|
const e = t.getBoundingClientRect();
|
|
13
16
|
e.right > window.innerWidth && (t.style.left = "auto", t.style.right = "100%", t.style.marginLeft = "0", t.style.marginRight = "2px"), e.bottom > window.innerHeight && (t.style.top = "auto", t.style.bottom = "0");
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
+
}, p = (t, e) => {
|
|
18
|
+
c(t) || t.type === "separator" || (t.onAction && t.onAction(), t.action && e && e(t.action));
|
|
19
|
+
}, u = (t) => !t || t.length === 0 ? "" : t.join(" + "), w = {
|
|
17
20
|
items: [
|
|
18
21
|
{
|
|
19
22
|
label: "Nouveau",
|
|
@@ -74,12 +77,12 @@ const n = (t) => {
|
|
|
74
77
|
]
|
|
75
78
|
};
|
|
76
79
|
export {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
h as adjustSubMenuPosition,
|
|
81
|
+
s as calculatePosition,
|
|
82
|
+
w as contextMenuData,
|
|
83
|
+
p as executeAction,
|
|
84
|
+
u as getDisplayShortcut,
|
|
85
|
+
c as isItemDisabled,
|
|
86
|
+
d as lockScroll,
|
|
87
|
+
b as unlockScroll
|
|
85
88
|
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { jsxs as M, jsx as
|
|
2
|
-
import { useState as b, useRef as
|
|
3
|
-
import { calculatePosition as C, lockScroll as
|
|
1
|
+
import { jsxs as M, jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { useState as b, useRef as v, useCallback as h, useEffect as x } from "react";
|
|
3
|
+
import { calculatePosition as C, lockScroll as g, unlockScroll as y, contextMenuData as N, getDisplayShortcut as k, isItemDisabled as D, adjustSubMenuPosition as E, executeAction as I } from "../js/context-menu.js";
|
|
4
4
|
import '../style/index.css';/* empty css */
|
|
5
|
-
const $ = ({ item:
|
|
6
|
-
const [
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
}, [
|
|
5
|
+
const $ = ({ item: s, onAction: f, closeMenu: p }) => {
|
|
6
|
+
const [u, o] = b(!1), r = v(null), e = "context-menu", i = !!(s.items && s.items.length > 0), t = k(s.shortcuts), c = D(s);
|
|
7
|
+
return x(() => {
|
|
8
|
+
u && r.current && E(r.current);
|
|
9
|
+
}, [u]), s.type === "separator" ? /* @__PURE__ */ l("div", { className: `${e}__separator` }) : /* @__PURE__ */ M(
|
|
10
10
|
"div",
|
|
11
11
|
{
|
|
12
|
-
className: `${
|
|
13
|
-
onMouseEnter: () =>
|
|
14
|
-
onMouseLeave: () =>
|
|
12
|
+
className: `${e}__item ${i ? `${e}__sub-trigger` : ""} ${c ? "disabled" : ""}`.trim(),
|
|
13
|
+
onMouseEnter: () => i && !c && o(!0),
|
|
14
|
+
onMouseLeave: () => i && !c && o(!1),
|
|
15
15
|
onClick: (a) => {
|
|
16
|
-
!
|
|
16
|
+
!i && !c && (a.stopPropagation(), I(s, f), p());
|
|
17
17
|
},
|
|
18
18
|
children: [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
s.label,
|
|
20
|
+
t && /* @__PURE__ */ l("span", { className: `${e}__shortcut`, children: t }),
|
|
21
|
+
i && u && /* @__PURE__ */ l(
|
|
22
22
|
"div",
|
|
23
23
|
{
|
|
24
|
-
ref:
|
|
25
|
-
className: `${
|
|
26
|
-
children:
|
|
24
|
+
ref: r,
|
|
25
|
+
className: `${e} ${e}__sub-menu`,
|
|
26
|
+
children: s.items.map((a, m) => /* @__PURE__ */ l(
|
|
27
27
|
$,
|
|
28
28
|
{
|
|
29
29
|
item: a,
|
|
@@ -37,46 +37,51 @@ const $ = ({ item: e, onAction: f, closeMenu: p }) => {
|
|
|
37
37
|
]
|
|
38
38
|
}
|
|
39
39
|
);
|
|
40
|
-
},
|
|
41
|
-
items:
|
|
40
|
+
}, L = ({
|
|
41
|
+
items: s = N.items,
|
|
42
42
|
onAction: f,
|
|
43
43
|
children: p,
|
|
44
|
-
className:
|
|
44
|
+
className: u = ""
|
|
45
45
|
}) => {
|
|
46
|
-
const [o,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}, []), m = x(() => {
|
|
51
|
-
c(!1);
|
|
46
|
+
const [o, r] = b(!1), [e, i] = b({ x: 0, y: 0 }), t = v(null), c = "context-menu", a = h((n) => {
|
|
47
|
+
n.preventDefault(), i({ x: n.clientX, y: n.clientY }), r(!0);
|
|
48
|
+
}, []), m = h(() => {
|
|
49
|
+
r(!1);
|
|
52
50
|
}, []);
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
return x(() => {
|
|
52
|
+
if (o && t.current) {
|
|
53
|
+
const { offsetWidth: n, offsetHeight: d } = t.current, { x: _, y: S } = C(e.x, e.y, n, d);
|
|
54
|
+
t.current.style.top = `${S}px`, t.current.style.left = `${_}px`, t.current.style.visibility = "visible";
|
|
55
|
+
}
|
|
56
|
+
}, [o, e.x, e.y]), x(() => {
|
|
57
|
+
const n = (d) => {
|
|
58
|
+
t.current && !t.current.contains(d.target) && m();
|
|
56
59
|
};
|
|
57
|
-
return o ? (document.addEventListener("mousedown",
|
|
58
|
-
document.removeEventListener("mousedown",
|
|
60
|
+
return o ? (document.addEventListener("mousedown", n), g()) : y(), () => {
|
|
61
|
+
document.removeEventListener("mousedown", n), y();
|
|
59
62
|
};
|
|
60
63
|
}, [o, m]), /* @__PURE__ */ M(
|
|
61
64
|
"div",
|
|
62
65
|
{
|
|
63
66
|
onContextMenu: a,
|
|
64
|
-
className: `context-menu-wrapper ${
|
|
67
|
+
className: `context-menu-wrapper ${u}`,
|
|
65
68
|
children: [
|
|
66
69
|
p,
|
|
67
|
-
o && /* @__PURE__ */
|
|
70
|
+
o && /* @__PURE__ */ l(
|
|
68
71
|
"div",
|
|
69
72
|
{
|
|
70
|
-
ref:
|
|
71
|
-
className:
|
|
73
|
+
ref: t,
|
|
74
|
+
className: c,
|
|
72
75
|
style: {
|
|
73
|
-
top:
|
|
74
|
-
left:
|
|
76
|
+
top: e.y,
|
|
77
|
+
left: e.x,
|
|
78
|
+
visibility: "hidden"
|
|
79
|
+
// Caché le temps de la mesure au premier affichage
|
|
75
80
|
},
|
|
76
|
-
children:
|
|
81
|
+
children: s.map((n, d) => /* @__PURE__ */ l(
|
|
77
82
|
$,
|
|
78
83
|
{
|
|
79
|
-
item:
|
|
84
|
+
item: n,
|
|
80
85
|
onAction: f,
|
|
81
86
|
closeMenu: m
|
|
82
87
|
},
|
|
@@ -89,5 +94,5 @@ const $ = ({ item: e, onAction: f, closeMenu: p }) => {
|
|
|
89
94
|
);
|
|
90
95
|
};
|
|
91
96
|
export {
|
|
92
|
-
|
|
97
|
+
L as ContextMenu
|
|
93
98
|
};
|
|
@@ -3,6 +3,7 @@ interface DropdownItem {
|
|
|
3
3
|
label?: string;
|
|
4
4
|
href?: string;
|
|
5
5
|
type?: "divider" | "item";
|
|
6
|
+
onClick?: () => void;
|
|
6
7
|
}
|
|
7
8
|
interface Props extends Omit<DropdownProps, "children"> {
|
|
8
9
|
/**
|
|
@@ -25,6 +26,10 @@ interface Props extends Omit<DropdownProps, "children"> {
|
|
|
25
26
|
* Contenu optionnel.
|
|
26
27
|
*/
|
|
27
28
|
children?: React.ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Fonction appelée lorsque le dropdown est ouvert.
|
|
31
|
+
*/
|
|
32
|
+
onClick?: () => void;
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
35
|
* Composant Dropdown personnalisé.
|
|
@@ -34,7 +39,7 @@ interface Props extends Omit<DropdownProps, "children"> {
|
|
|
34
39
|
* @returns {JSX.Element} Le composant Dropdown rendu.
|
|
35
40
|
*/
|
|
36
41
|
export declare const Dropdown: {
|
|
37
|
-
({ label, variant, items, align, className, children, ...props }: Props): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
({ label, variant, items, align, className, children, onClick, ...props }: Props): import("react/jsx-runtime").JSX.Element;
|
|
38
43
|
Toggle({ className, ...props }: any): import("react/jsx-runtime").JSX.Element;
|
|
39
44
|
Menu({ className, ...props }: any): import("react/jsx-runtime").JSX.Element;
|
|
40
45
|
Item({ className, ...props }: any): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import { jsx as o, jsxs as
|
|
1
|
+
import { jsx as o, jsxs as _, Fragment as $ } from "react/jsx-runtime";
|
|
2
2
|
import { Dropdown as d } from "react-bootstrap";
|
|
3
3
|
import '../style/index.css';/* empty css */
|
|
4
|
-
const
|
|
4
|
+
const n = ({
|
|
5
5
|
label: r = "Dropdown",
|
|
6
6
|
variant: e = "primary",
|
|
7
|
-
items:
|
|
8
|
-
align:
|
|
9
|
-
className:
|
|
10
|
-
children:
|
|
11
|
-
|
|
7
|
+
items: l = [],
|
|
8
|
+
align: t = "start",
|
|
9
|
+
className: c = "",
|
|
10
|
+
children: s,
|
|
11
|
+
onClick: g,
|
|
12
|
+
...p
|
|
12
13
|
}) => {
|
|
13
|
-
const
|
|
14
|
-
return /* @__PURE__ */ o(d, { className: `${
|
|
15
|
-
/* @__PURE__ */ o(d.Toggle, { variant: e, id: `dropdown-${r}`, className: `${
|
|
16
|
-
/* @__PURE__ */ o(d.Menu, { className: `${
|
|
14
|
+
const i = "dropdown";
|
|
15
|
+
return /* @__PURE__ */ o(d, { className: `${i} ${c}`.trim(), align: t, ...p, children: s || /* @__PURE__ */ _($, { children: [
|
|
16
|
+
/* @__PURE__ */ o(d.Toggle, { variant: e, id: `dropdown-${r}`, className: `${i}__toggle`, children: r }),
|
|
17
|
+
/* @__PURE__ */ o(d.Menu, { className: `${i}__menu`, children: l.map((m, a) => m.type === "divider" ? /* @__PURE__ */ o(d.Divider, { className: `${i}__divider` }, a) : /* @__PURE__ */ o(
|
|
17
18
|
d.Item,
|
|
18
19
|
{
|
|
19
|
-
href:
|
|
20
|
-
className: `${
|
|
21
|
-
|
|
20
|
+
href: m.href,
|
|
21
|
+
className: `${i}__item`,
|
|
22
|
+
onClick: m.onClick,
|
|
23
|
+
children: m.label
|
|
22
24
|
},
|
|
23
|
-
|
|
25
|
+
a
|
|
24
26
|
)) })
|
|
25
27
|
] }) });
|
|
26
28
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
n.Toggle = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Toggle, { className: `dropdown__toggle ${r}`.trim(), ...e });
|
|
30
|
+
n.Menu = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Menu, { className: `dropdown__menu ${r}`.trim(), ...e });
|
|
31
|
+
n.Item = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Item, { className: `dropdown__item ${r}`.trim(), ...e });
|
|
32
|
+
n.Divider = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Divider, { className: `dropdown__divider ${r}`.trim(), ...e });
|
|
31
33
|
export {
|
|
32
|
-
|
|
34
|
+
n as Dropdown
|
|
33
35
|
};
|