@nice2dev/ui 1.1.9 → 1.1.10
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 +74 -0
- package/README.md +17 -16
- package/dist/NiceCodeEditor-BfkH1bsZ.cjs +260 -0
- package/dist/NiceCodeEditor-CduGYggj.js +1179 -0
- package/dist/NiceColorPicker-CdUnhM-A.cjs +1 -0
- package/dist/NiceColorPicker-DpXwnDwL.js +598 -0
- package/dist/NiceConfirmDialog-B7aNRL2K.cjs +1 -0
- package/dist/NiceConfirmDialog-BdhWenrO.js +81 -0
- package/dist/NiceDataGrid-CVYEo_nv.cjs +10 -0
- package/dist/NiceDataGrid-D-rm4lu8.js +2217 -0
- package/dist/NiceDocumentViewer-BgcgLWJ3.cjs +180 -0
- package/dist/NiceDocumentViewer-sukmGhRx.js +672 -0
- package/dist/NiceForm-DVc0Xoly.js +4819 -0
- package/dist/NiceForm-qD_RKPYz.cjs +1 -0
- package/dist/NiceGantt-4UBd4uJ8.cjs +1 -0
- package/dist/NiceGantt-B_1lwEsp.js +328 -0
- package/dist/NiceHtmlEditor-Bce9Vwe1.cjs +10 -0
- package/dist/NiceHtmlEditor-CGRgcu2h.js +848 -0
- package/dist/NiceLoginForm-BTuQ0eKk.cjs +1 -0
- package/dist/NiceLoginForm-o1A-TBcp.js +736 -0
- package/dist/NiceMention-Dds9GQzk.cjs +430 -0
- package/dist/NiceMention-DlLXWddO.js +11268 -0
- package/dist/NiceModal-Dr1e3nQZ.cjs +1 -0
- package/dist/NiceModal-sihGCfDy.js +95 -0
- package/dist/NiceModuleLifecyclePanel-Du7G3-RG.js +7053 -0
- package/dist/NiceModuleLifecyclePanel-js1p7LIY.cjs +1 -0
- package/dist/NicePagination-D44waj9o.cjs +1 -0
- package/dist/NicePagination-DdxH8KMG.js +179 -0
- package/dist/NicePivotGrid-B2YHP3Z6.js +1183 -0
- package/dist/NicePivotGrid-BtVUWiud.cjs +152 -0
- package/dist/NiceSavedQueryPanel-C0A-eoYN.js +5142 -0
- package/dist/NiceSavedQueryPanel-ZrilZRtf.cjs +586 -0
- package/dist/NiceScheduler-KSzaUQxC.js +1693 -0
- package/dist/NiceScheduler-O3AwmdGG.cjs +5 -0
- package/dist/NiceSelect-BCbWtu1v.js +433 -0
- package/dist/NiceSelect-BqtiQbfD.cjs +1 -0
- package/dist/NiceWindow-BU1Ce7gS.js +1623 -0
- package/dist/NiceWindow-jjdE6vGy.cjs +1 -0
- package/dist/charts-C44vJber.cjs +768 -0
- package/dist/charts-XVlDwU0y.js +4732 -0
- package/dist/charts.cjs +1 -1
- package/dist/charts.mjs +8 -8
- package/dist/core-BxiH7vkV.cjs +1 -0
- package/dist/core-DMV6_SEE.js +795 -0
- package/dist/data-branching-oEH04O3i.js +6273 -0
- package/dist/data-branching-wmsbLNfa.cjs +1 -0
- package/dist/data-branching.cjs +1 -1
- package/dist/data-branching.mjs +1 -1
- package/dist/data.cjs +1 -1
- package/dist/data.d.ts +2 -2
- package/dist/data.mjs +3 -3
- package/dist/devops-Bt6EsfPa.cjs +17 -0
- package/dist/devops-CnZQ1rU5.js +8312 -0
- package/dist/devops.cjs +1 -1
- package/dist/devops.mjs +1 -1
- package/dist/editors.cjs +1 -1
- package/dist/editors.d.ts +2 -1
- package/dist/editors.mjs +7 -7
- package/dist/feedback.cjs +1 -1
- package/dist/feedback.mjs +3 -3
- package/dist/index.cjs +142 -142
- package/dist/index.d.ts +45 -26
- package/dist/index.mjs +7480 -7459
- package/dist/lazy.cjs +1 -1
- package/dist/lazy.mjs +24 -24
- package/dist/navigation.cjs +1 -1
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.mjs +69 -69
- package/dist/no-code-4GtIBr6f.js +7503 -0
- package/dist/no-code-Bdwh1vyS.cjs +332 -0
- package/dist/no-code.cjs +1 -1
- package/dist/no-code.mjs +1 -1
- package/dist/overlays.cjs +1 -1
- package/dist/overlays.mjs +102 -102
- package/dist/pickerCommons-31hyz1gs.js +1122 -0
- package/dist/pickerCommons-BifIkPdk.cjs +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { jsxs as l, jsx as s } from "react/jsx-runtime";
|
|
2
|
+
import { useNiceAccessMode as le, useNiceTranslation as he } from "@nice2dev/ui-core";
|
|
3
|
+
import { useState as J, useRef as S, useEffect as Y, useMemo as q, useCallback as z } from "react";
|
|
4
|
+
const b = (m, N) => {
|
|
5
|
+
const y = new Date(m);
|
|
6
|
+
return y.setDate(y.getDate() + N), y;
|
|
7
|
+
}, E = (m, N) => Math.ceil((N.getTime() - m.getTime()) / 864e5), me = ({
|
|
8
|
+
tasks: m,
|
|
9
|
+
columns: N,
|
|
10
|
+
scale: y = "day",
|
|
11
|
+
rowHeight: _ = 36,
|
|
12
|
+
dayWidth: G = 30,
|
|
13
|
+
onTaskClick: O,
|
|
14
|
+
onTaskUpdate: w,
|
|
15
|
+
showDependencies: P = !0,
|
|
16
|
+
dependencyStyle: K = "square",
|
|
17
|
+
draggable: M,
|
|
18
|
+
zoomControls: V,
|
|
19
|
+
className: Z,
|
|
20
|
+
style: k,
|
|
21
|
+
accessMode: H,
|
|
22
|
+
id: U
|
|
23
|
+
}) => {
|
|
24
|
+
const ee = le(H, U) === "hidden", { t: _e } = he(), [o, C] = J(G), [f, A] = J(null), x = N || [{ field: "title", title: "Task", width: 200 }], B = x.reduce((e, t) => e + (t.width || 120), 0), j = S(null), X = S(null), W = S(!1);
|
|
25
|
+
Y(() => {
|
|
26
|
+
const e = j.current, t = X.current;
|
|
27
|
+
if (!e || !t)
|
|
28
|
+
return;
|
|
29
|
+
const a = (c, i) => () => {
|
|
30
|
+
W.current || (W.current = !0, i.scrollTop = c.scrollTop, requestAnimationFrame(() => {
|
|
31
|
+
W.current = !1;
|
|
32
|
+
}));
|
|
33
|
+
}, n = a(e, t), r = a(t, e);
|
|
34
|
+
return e.addEventListener("scroll", n, { passive: !0 }), t.addEventListener("scroll", r, { passive: !0 }), () => {
|
|
35
|
+
e.removeEventListener("scroll", n), t.removeEventListener("scroll", r);
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
const d = q(() => {
|
|
39
|
+
const e = (t) => m.filter((n) => (n.parentId ?? null) === t).flatMap((n) => [n, ...e(n.id)]);
|
|
40
|
+
return e(null);
|
|
41
|
+
}, [m]), u = q(() => {
|
|
42
|
+
if (d.length === 0)
|
|
43
|
+
return { start: /* @__PURE__ */ new Date(), end: /* @__PURE__ */ new Date(), days: 30 };
|
|
44
|
+
let e = new Date(d[0].start), t = new Date(d[0].end);
|
|
45
|
+
return d.forEach((a) => {
|
|
46
|
+
new Date(a.start) < e && (e = new Date(a.start)), new Date(a.end) > t && (t = new Date(a.end));
|
|
47
|
+
}), e = b(e, -2), t = b(t, 2), { start: e, end: t, days: E(e, t) };
|
|
48
|
+
}, [d]), I = u.days * o;
|
|
49
|
+
Y(() => {
|
|
50
|
+
if (!f || !w)
|
|
51
|
+
return;
|
|
52
|
+
const e = (a) => {
|
|
53
|
+
const n = a.clientX - f.startX, r = Math.round(n / o);
|
|
54
|
+
if (r === 0)
|
|
55
|
+
return;
|
|
56
|
+
const c = m.find((i) => i.id === f.taskId);
|
|
57
|
+
if (c)
|
|
58
|
+
if (f.mode === "move")
|
|
59
|
+
w({
|
|
60
|
+
...c,
|
|
61
|
+
start: b(f.origStart, r),
|
|
62
|
+
end: b(f.origEnd, r)
|
|
63
|
+
});
|
|
64
|
+
else {
|
|
65
|
+
const i = b(f.origEnd, r);
|
|
66
|
+
i > f.origStart && w({ ...c, end: i });
|
|
67
|
+
}
|
|
68
|
+
}, t = () => A(null);
|
|
69
|
+
return document.addEventListener("mousemove", e), document.addEventListener("mouseup", t), () => {
|
|
70
|
+
document.removeEventListener("mousemove", e), document.removeEventListener("mouseup", t);
|
|
71
|
+
};
|
|
72
|
+
}, [f, o, m, w]);
|
|
73
|
+
const Q = z(
|
|
74
|
+
(e, t, a) => {
|
|
75
|
+
if (!M || !w)
|
|
76
|
+
return;
|
|
77
|
+
a.stopPropagation();
|
|
78
|
+
const n = m.find((r) => r.id === e);
|
|
79
|
+
n && A({
|
|
80
|
+
taskId: e,
|
|
81
|
+
mode: t,
|
|
82
|
+
startX: a.clientX,
|
|
83
|
+
origStart: new Date(n.start),
|
|
84
|
+
origEnd: new Date(n.end)
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
[M, m, w]
|
|
88
|
+
), te = z(() => C((e) => Math.min(100, e + 5)), []), ne = z(() => C((e) => Math.max(8, e - 5)), []), ae = () => {
|
|
89
|
+
const e = [], t = [];
|
|
90
|
+
new Date(u.start);
|
|
91
|
+
const a = [
|
|
92
|
+
"Jan",
|
|
93
|
+
"Feb",
|
|
94
|
+
"Mar",
|
|
95
|
+
"Apr",
|
|
96
|
+
"May",
|
|
97
|
+
"Jun",
|
|
98
|
+
"Jul",
|
|
99
|
+
"Aug",
|
|
100
|
+
"Sep",
|
|
101
|
+
"Oct",
|
|
102
|
+
"Nov",
|
|
103
|
+
"Dec"
|
|
104
|
+
];
|
|
105
|
+
if (y === "day") {
|
|
106
|
+
let n = -1, r = 0;
|
|
107
|
+
for (let c = 0; c < u.days; c++) {
|
|
108
|
+
const i = b(u.start, c);
|
|
109
|
+
i.getMonth() !== n && (n >= 0 && e.push(
|
|
110
|
+
/* @__PURE__ */ l(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
className: "nice-gantt__header-cell",
|
|
114
|
+
style: { width: (c - r) * o },
|
|
115
|
+
children: [
|
|
116
|
+
a[n],
|
|
117
|
+
" ",
|
|
118
|
+
i.getFullYear()
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
`m${n}-${r}`
|
|
122
|
+
)
|
|
123
|
+
), n = i.getMonth(), r = c);
|
|
124
|
+
const h = i.getDay() === 0 || i.getDay() === 6;
|
|
125
|
+
t.push(
|
|
126
|
+
/* @__PURE__ */ s(
|
|
127
|
+
"div",
|
|
128
|
+
{
|
|
129
|
+
className: `nice-gantt__header-cell nice-gantt__header-cell--sub ${h ? "nice-gantt__header-cell--weekend" : ""}`,
|
|
130
|
+
style: { width: o },
|
|
131
|
+
children: i.getDate()
|
|
132
|
+
},
|
|
133
|
+
c
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
n >= 0 && e.push(
|
|
138
|
+
/* @__PURE__ */ s(
|
|
139
|
+
"div",
|
|
140
|
+
{
|
|
141
|
+
className: "nice-gantt__header-cell",
|
|
142
|
+
style: { width: (u.days - r) * o },
|
|
143
|
+
children: a[n]
|
|
144
|
+
},
|
|
145
|
+
`m${n}-last`
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return /* @__PURE__ */ l("div", { className: "nice-gantt__chart-header", children: [
|
|
150
|
+
/* @__PURE__ */ s("div", { className: "nice-gantt__header-row", children: e }),
|
|
151
|
+
/* @__PURE__ */ s("div", { className: "nice-gantt__header-row", children: t })
|
|
152
|
+
] });
|
|
153
|
+
}, re = (e, t) => {
|
|
154
|
+
const a = E(u.start, new Date(e.start)) * o, n = Math.max(E(new Date(e.start), new Date(e.end)) * o, o), r = t * _ + 4, c = _ - 8, i = e.progress ?? 0;
|
|
155
|
+
return /* @__PURE__ */ l(
|
|
156
|
+
"div",
|
|
157
|
+
{
|
|
158
|
+
className: `nice-gantt__bar ${M ? "nice-gantt__bar--draggable" : ""}`,
|
|
159
|
+
title: `${e.title} (${Math.round(i)}%)`,
|
|
160
|
+
style: {
|
|
161
|
+
left: a,
|
|
162
|
+
top: r,
|
|
163
|
+
width: n,
|
|
164
|
+
height: c,
|
|
165
|
+
backgroundColor: e.color || "var(--nice-color-primary, #3b82f6)"
|
|
166
|
+
},
|
|
167
|
+
onClick: () => O?.(e),
|
|
168
|
+
onMouseDown: M ? (h) => Q(e.id, "move", h) : void 0,
|
|
169
|
+
children: [
|
|
170
|
+
i > 0 && /* @__PURE__ */ s("div", { className: "nice-gantt__bar-progress", style: { width: `${i}%` } }),
|
|
171
|
+
/* @__PURE__ */ s("span", { className: "nice-gantt__bar-label", children: e.title }),
|
|
172
|
+
M && /* @__PURE__ */ s(
|
|
173
|
+
"div",
|
|
174
|
+
{
|
|
175
|
+
className: "nice-gantt__bar-resize",
|
|
176
|
+
onMouseDown: (h) => Q(e.id, "resize", h)
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
e.id
|
|
182
|
+
);
|
|
183
|
+
}, se = (e, t, a, n, r) => {
|
|
184
|
+
const h = e + 10, L = a - 14, R = (t + n) / 2, D = n >= t ? 1 : -1, T = Math.abs(n - t) < 1, F = L <= h + 4, $ = T ? t : R, g = F ? Math.max(h, e + 10) : h, v = F ? Math.min(L, a - 10) : L;
|
|
185
|
+
if (T || !r)
|
|
186
|
+
return [
|
|
187
|
+
`M ${e} ${t}`,
|
|
188
|
+
`L ${g} ${t}`,
|
|
189
|
+
`L ${g} ${$}`,
|
|
190
|
+
`L ${v} ${$}`,
|
|
191
|
+
`L ${v} ${n}`,
|
|
192
|
+
`L ${a} ${n}`
|
|
193
|
+
].join(" ");
|
|
194
|
+
const ce = Math.max(0, v - g), oe = Math.abs(n - t), de = Math.min(oe / 2 || 10, ce / 2 || 10), p = Math.max(2, Math.min(10, de));
|
|
195
|
+
return [
|
|
196
|
+
`M ${e} ${t}`,
|
|
197
|
+
`L ${g - p} ${t}`,
|
|
198
|
+
`Q ${g} ${t} ${g} ${t + D * p}`,
|
|
199
|
+
`L ${g} ${$ - D * p}`,
|
|
200
|
+
`Q ${g} ${$} ${g + p} ${$}`,
|
|
201
|
+
`L ${v - p} ${$}`,
|
|
202
|
+
`Q ${v} ${$} ${v} ${$ + D * p}`,
|
|
203
|
+
`L ${v} ${n - D * p}`,
|
|
204
|
+
`Q ${v} ${n} ${v + p} ${n}`,
|
|
205
|
+
`L ${a} ${n}`
|
|
206
|
+
].join(" ");
|
|
207
|
+
}, ie = () => {
|
|
208
|
+
if (!P)
|
|
209
|
+
return null;
|
|
210
|
+
const e = [], t = new Map(d.map((a, n) => [a.id, n]));
|
|
211
|
+
return d.forEach((a) => {
|
|
212
|
+
(a.dependencies || []).forEach((n) => {
|
|
213
|
+
const r = t.get(n), c = t.get(a.id);
|
|
214
|
+
if (r == null || c == null)
|
|
215
|
+
return;
|
|
216
|
+
const i = d[r], h = E(u.start, new Date(i.end)) * o, L = r * _ + _ / 2, R = E(u.start, new Date(a.start)) * o, D = c * _ + _ / 2;
|
|
217
|
+
e.push(
|
|
218
|
+
/* @__PURE__ */ s(
|
|
219
|
+
"path",
|
|
220
|
+
{
|
|
221
|
+
d: se(h, L, R, D, K === "rounded"),
|
|
222
|
+
fill: "none",
|
|
223
|
+
stroke: "var(--nice-text-secondary, #6b7280)",
|
|
224
|
+
strokeWidth: 1.5,
|
|
225
|
+
strokeLinejoin: "round",
|
|
226
|
+
strokeLinecap: "round",
|
|
227
|
+
markerEnd: "url(#arrowhead)"
|
|
228
|
+
},
|
|
229
|
+
`${n}-${a.id}`
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
});
|
|
233
|
+
}), /* @__PURE__ */ l(
|
|
234
|
+
"svg",
|
|
235
|
+
{
|
|
236
|
+
className: "nice-gantt__deps",
|
|
237
|
+
width: I,
|
|
238
|
+
height: d.length * _,
|
|
239
|
+
style: { position: "absolute", top: 0, left: 0, pointerEvents: "none" },
|
|
240
|
+
children: [
|
|
241
|
+
/* @__PURE__ */ s("defs", { children: /* @__PURE__ */ s("marker", { id: "arrowhead", markerWidth: "6", markerHeight: "4", refX: "5", refY: "2", orient: "auto", children: /* @__PURE__ */ s("polygon", { points: "0 0, 6 2, 0 4", fill: "var(--nice-text-secondary, #6b7280)" }) }) }),
|
|
242
|
+
e
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
};
|
|
247
|
+
return ee ? null : /* @__PURE__ */ l("div", { className: `nice-gantt ${Z || ""}`, style: k, children: [
|
|
248
|
+
V && /* @__PURE__ */ l("div", { className: "nice-gantt__zoom-controls", children: [
|
|
249
|
+
/* @__PURE__ */ s("button", { type: "button", className: "nice-btn nice-btn--sm", onClick: ne, children: "−" }),
|
|
250
|
+
/* @__PURE__ */ l("span", { className: "nice-gantt__zoom-label", children: [
|
|
251
|
+
o,
|
|
252
|
+
"px"
|
|
253
|
+
] }),
|
|
254
|
+
/* @__PURE__ */ s("button", { type: "button", className: "nice-btn nice-btn--sm", onClick: te, children: "+" })
|
|
255
|
+
] }),
|
|
256
|
+
/* @__PURE__ */ l("div", { className: "nice-gantt__container", children: [
|
|
257
|
+
/* @__PURE__ */ l("div", { className: "nice-gantt__table", style: { width: B, minWidth: B }, children: [
|
|
258
|
+
/* @__PURE__ */ l("div", { className: "nice-gantt__table-header", children: [
|
|
259
|
+
/* @__PURE__ */ s(
|
|
260
|
+
"div",
|
|
261
|
+
{
|
|
262
|
+
className: "nice-gantt__table-header-row nice-gantt__table-header-row--main",
|
|
263
|
+
"aria-hidden": "true",
|
|
264
|
+
children: " "
|
|
265
|
+
}
|
|
266
|
+
),
|
|
267
|
+
/* @__PURE__ */ s("div", { className: "nice-gantt__table-header-row nice-gantt__table-header-row--sub", children: x.map((e, t) => /* @__PURE__ */ s(
|
|
268
|
+
"div",
|
|
269
|
+
{
|
|
270
|
+
className: "nice-gantt__table-header-cell",
|
|
271
|
+
style: { width: e.width || 120 },
|
|
272
|
+
children: e.title
|
|
273
|
+
},
|
|
274
|
+
t
|
|
275
|
+
)) })
|
|
276
|
+
] }),
|
|
277
|
+
/* @__PURE__ */ s("div", { className: "nice-gantt__table-body", ref: j, children: d.map((e, t) => /* @__PURE__ */ s("div", { className: "nice-gantt__table-row", style: { height: _ }, children: x.map((a, n) => /* @__PURE__ */ s(
|
|
278
|
+
"div",
|
|
279
|
+
{
|
|
280
|
+
className: "nice-gantt__table-cell",
|
|
281
|
+
style: { width: a.width || 120 },
|
|
282
|
+
children: e[a.field]
|
|
283
|
+
},
|
|
284
|
+
n
|
|
285
|
+
)) }, e.id)) })
|
|
286
|
+
] }),
|
|
287
|
+
/* @__PURE__ */ s("div", { className: "nice-gantt__chart", children: /* @__PURE__ */ l("div", { className: "nice-gantt__chart-body-wrap", ref: X, children: [
|
|
288
|
+
ae(),
|
|
289
|
+
/* @__PURE__ */ l(
|
|
290
|
+
"div",
|
|
291
|
+
{
|
|
292
|
+
className: "nice-gantt__chart-body",
|
|
293
|
+
style: {
|
|
294
|
+
width: I,
|
|
295
|
+
height: d.length * _,
|
|
296
|
+
position: "relative"
|
|
297
|
+
},
|
|
298
|
+
children: [
|
|
299
|
+
Array.from({ length: u.days }, (e, t) => {
|
|
300
|
+
const a = b(u.start, t), n = a.getDay() === 0 || a.getDay() === 6;
|
|
301
|
+
return /* @__PURE__ */ s(
|
|
302
|
+
"div",
|
|
303
|
+
{
|
|
304
|
+
className: `nice-gantt__gridline ${n ? "nice-gantt__gridline--weekend" : ""}`,
|
|
305
|
+
style: {
|
|
306
|
+
left: t * o,
|
|
307
|
+
width: o,
|
|
308
|
+
height: "100%",
|
|
309
|
+
position: "absolute",
|
|
310
|
+
top: 0
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
t
|
|
314
|
+
);
|
|
315
|
+
}),
|
|
316
|
+
d.map((e, t) => re(e, t)),
|
|
317
|
+
ie()
|
|
318
|
+
]
|
|
319
|
+
}
|
|
320
|
+
)
|
|
321
|
+
] }) })
|
|
322
|
+
] })
|
|
323
|
+
] });
|
|
324
|
+
};
|
|
325
|
+
me.displayName = "NiceGantt";
|
|
326
|
+
export {
|
|
327
|
+
me as NiceGantt
|
|
328
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),u=require("@nice2dev/ui-core"),i=require("react"),g=require("./NiceColorPicker-CdUnhM-A.cjs"),Ze=require("./NiceSelect-BqtiQbfD.cjs");function he(b){const t=b.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")||t.startsWith("/")||t.startsWith("./")||t.startsWith("../")?!0:!(t.startsWith("javascript:")||t.startsWith("vbscript:")||t.startsWith("data:text"))}const et=[{target:".nice-htmleditor",titleKey:"tutorial.htmlEditor.intro.title",title:"Rich text editor",contentKey:"tutorial.htmlEditor.intro.content",content:"Format text with the toolbar, insert links, images and tables, and switch to HTML or Markdown source when you need it.",placement:"auto"}],tt=["bold","italic","underline","strikethrough","h1","h2","h3","ul","ol","blockquote","hr","link","unlink","image","table","code","alignLeft","alignCenter","alignRight","fontSize","fontColor","undo","redo","clear","findReplace","emoji","source","fullscreen","markdown"],l=b=>r.jsx(u.NiceIcon,{name:b,size:16}),nt={bold:r.jsx("strong",{style:{fontFamily:"serif"},children:"B"}),italic:r.jsx("em",{style:{fontFamily:"serif"},children:"I"}),underline:r.jsx("span",{style:{textDecoration:"underline"},children:"U"}),strikethrough:r.jsx("span",{style:{textDecoration:"line-through"},children:"S"}),h1:"H1",h2:"H2",h3:"H3",ul:l("list"),ol:l("list-ordered"),link:l("link"),unlink:l("unlink"),undo:l("reply"),redo:l("forward"),clear:l("trash"),table:l("table"),image:l("image"),code:l("code"),markdown:"MD",blockquote:l("quote"),hr:l("minus"),subscript:"X₂",superscript:"X²",indent:l("indent"),outdent:l("outdent"),alignLeft:l("align-left"),alignCenter:l("align-center"),alignRight:l("align-right"),alignJustify:l("align-justify"),fullscreen:l("expand"),removeFormat:l("eraser"),print:l("printer"),source:l("terminal"),emoji:l("smile"),findReplace:l("search"),fontSize:l("type"),fontColor:l("palette")},rt=[{value:"1",label:"8pt"},{value:"2",label:"10pt"},{value:"3",label:"12pt"},{value:"4",label:"14pt"},{value:"5",label:"18pt"},{value:"6",label:"24pt"},{value:"7",label:"36pt"}],ot=[{label:"Faces",emojis:["😀","😂","😊","😍","🤔","😢","😎","🥳","😤","🤯","🥰","😴"]},{label:"Hands",emojis:["👍","👎","👏","🤝","✌️","🤞","💪","🙌","👋","🤙"]},{label:"Symbols",emojis:["❤️","⭐","🔥","✅","❌","⚡","💡","📌","🎯","🏆","🎉","💬"]},{label:"Arrows",emojis:["➡️","⬅️","⬆️","⬇️","↩️","🔄","▶️","⏸️","⏹️","⏩"]}];function it(b){let t=b;return t=t.replace(/<h1[^>]*>(.*?)<\/h1>/gi,`# $1
|
|
2
|
+
`),t=t.replace(/<h2[^>]*>(.*?)<\/h2>/gi,`## $1
|
|
3
|
+
`),t=t.replace(/<h3[^>]*>(.*?)<\/h3>/gi,`### $1
|
|
4
|
+
`),t=t.replace(/<strong[^>]*>(.*?)<\/strong>/gi,"**$1**"),t=t.replace(/<b[^>]*>(.*?)<\/b>/gi,"**$1**"),t=t.replace(/<em[^>]*>(.*?)<\/em>/gi,"*$1*"),t=t.replace(/<i[^>]*>(.*?)<\/i>/gi,"*$1*"),t=t.replace(/<code[^>]*>(.*?)<\/code>/gi,"`$1`"),t=t.replace(/<pre[^>]*>(.*?)<\/pre>/gis,"```\n$1\n```\n"),t=t.replace(/<br\s*\/?>/gi,`
|
|
5
|
+
`),t=t.replace(/<li[^>]*>(.*?)<\/li>/gi,`- $1
|
|
6
|
+
`),t=t.replace(/<\/?(?:ul|ol|p|div)[^>]*>/gi,`
|
|
7
|
+
`),t=t.replace(/<[^>]+>/g,""),t=t.replace(/\n{3,}/g,`
|
|
8
|
+
|
|
9
|
+
`),t.trim()}function st(b){let t=b;return t=t.replace(/^### (.+)$/gm,"<h3>$1</h3>"),t=t.replace(/^## (.+)$/gm,"<h2>$1</h2>"),t=t.replace(/^# (.+)$/gm,"<h1>$1</h1>"),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/`([^`]+)`/g,"<code>$1</code>"),t=t.replace(/```\n?([\s\S]*?)\n?```/g,"<pre>$1</pre>"),t=t.replace(/^- (.+)$/gm,"<li>$1</li>"),t=t.replace(/(<li>.*<\/li>)/gs,"<ul>$1</ul>"),t=t.replace(/\n/g,"<br>"),t}const at=({value:b,defaultValue:t,onChange:xe,placeholder:be,height:$=200,toolbar:ge=tt,readOnly:h,onImageUpload:w,mentionTrigger:C,mentionSuggestions:Ce,onMentionSearch:Y,onFileDrop:H,pasteCleanup:Z=!0,maxLength:M=0,showWordCount:ee=!1,templates:D,label:te,error:L,helperText:ne,required:ke,disabled:x,size:ye="md",id:re,className:ve,style:je,accessMode:Se,tutorial:Te})=>{const I=u.useNiceAccessMode(Se,re),we=I==="hidden";I==="disabled"&&(x=!0),I==="readOnly"&&(h=!0);const oe=u.useControlId(re),[m,c]=u.useControllableState({value:b,defaultValue:t,fallbackValue:"",onChange:xe,componentName:"NiceHtmlEditor"}),d=i.useRef(null),[He]=i.useState(()=>({__html:m})),E=i.useRef(m);E.current=m;const Me=i.useCallback(e=>{d.current=e,e&&e.innerHTML!==E.current&&(e.innerHTML=E.current)},[]);i.useLayoutEffect(()=>{const e=d.current;e&&e.innerHTML!==m&&(e.innerHTML=m)},[m]);const ie=i.useRef(null),Ne=i.useRef(null),[v,O]=i.useState(!1),[F,se]=i.useState(""),[j,B]=i.useState(!1),[W,ae]=i.useState(""),[K,R]=i.useState(!1),[_e,Le]=i.useState(""),[A,q]=i.useState(0),[P,Re]=i.useState(!1),[le,ze]=i.useState("#000000"),[ce,$e]=i.useState("#ffff00"),[de,U]=i.useState(0),[De,Ie]=i.useState(0),[Q,X]=i.useState(!1),[f,Ee]=i.useState(""),[N,Oe]=i.useState(""),[J,ue]=i.useState(!1),[me,fe]=i.useState(!1),p=i.useCallback((e,n)=>{if(h||x)return;if(e==="markdown"){v?(c(st(F)),O(!1)):(se(it(m)),O(!0),B(!1));return}if(e==="source"){j?(c(W),B(!1)):(ae(m),B(!0),O(!1));return}const s=d.current;if(s){if(e==="fullscreen"){Re(o=>!o);return}if(e==="emoji"){ue(o=>!o);return}if(e==="findReplace"){X(o=>!o);return}if(e==="image"){if(w)ie.current?.click();else{const o=prompt("Image URL:");o&&he(o)&&(s.focus(),document.execCommand("insertImage",!1,o),c(u.sanitizeHtml(s.innerHTML)))}return}switch(s.focus(),e){case"bold":document.execCommand("bold");break;case"italic":document.execCommand("italic");break;case"underline":document.execCommand("underline");break;case"strikethrough":document.execCommand("strikeThrough");break;case"h1":document.execCommand("formatBlock",!1,"h1");break;case"h2":document.execCommand("formatBlock",!1,"h2");break;case"h3":document.execCommand("formatBlock",!1,"h3");break;case"ul":document.execCommand("insertUnorderedList");break;case"ol":document.execCommand("insertOrderedList");break;case"blockquote":document.execCommand("formatBlock",!1,"blockquote");break;case"hr":document.execCommand("insertHorizontalRule");break;case"subscript":document.execCommand("subscript");break;case"superscript":document.execCommand("superscript");break;case"indent":document.execCommand("indent");break;case"outdent":document.execCommand("outdent");break;case"alignLeft":document.execCommand("justifyLeft");break;case"alignCenter":document.execCommand("justifyCenter");break;case"alignRight":document.execCommand("justifyRight");break;case"alignJustify":document.execCommand("justifyFull");break;case"removeFormat":document.execCommand("removeFormat");break;case"print":window.print();return;case"link":{const o=prompt("URL:");o&&he(o)&&document.execCommand("createLink",!1,o);break}case"unlink":document.execCommand("unlink");break;case"undo":document.execCommand("undo");break;case"redo":document.execCommand("redo");break;case"clear":document.execCommand("removeFormat");break;case"fontSize":{n&&document.execCommand("fontSize",!1,n);break}case"fontColor":{n&&document.execCommand("foreColor",!1,n);break}case"bgColor":{n&&document.execCommand("hiliteColor",!1,n);break}case"table":{document.execCommand("insertHTML",!1,'<table class="nice-htmleditor__table"><thead><tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr></thead><tbody><tr><td> </td><td> </td><td> </td></tr><tr><td> </td><td> </td><td> </td></tr></tbody></table><p> </p>');break}case"code":{const a=window.getSelection()?.toString()||"";a.includes(`
|
|
10
|
+
`)||a.length>60?document.execCommand("insertHTML",!1,`<pre class="nice-htmleditor__code-block">${a||"// code"}</pre>`):document.execCommand("insertHTML",!1,`<code>${a||"code"}</code>`);break}}c(u.sanitizeHtml(s.innerHTML)),U(s.textContent?.length??0)}},[c,h,x,v,F,m,w,j,W]),Fe=i.useCallback(async e=>{const n=e.target.files?.[0];if(!n||!w)return;const s=await w(n),o=d.current;o&&s&&(o.focus(),document.execCommand("insertImage",!1,s),c(o.innerHTML)),e.target.value=""},[w,c]),Be=i.useCallback(()=>{const e=d.current;if(!e)return;const n=e.textContent?.length??0;if(M>0&&n>M&&(e.textContent=(e.textContent??"").slice(0,M)),U(n),Ie((e.textContent??"").trim().split(/\s+/).filter(Boolean).length),c(e.innerHTML),C){const s=window.getSelection();if(s&&s.rangeCount>0){const o=s.getRangeAt(0),a=o.startContainer;if(a.nodeType===Node.TEXT_NODE){const k=a.textContent||"",T=o.startOffset,z=k.slice(0,T),y=z.lastIndexOf(C);if(y>=0&&(y===0||/\s/.test(z[y-1]))){const _=z.slice(y+C.length);if(!/\s/.test(_)){R(!0),Le(_),q(0),Y?.(_);return}}}}R(!1)}},[c,C,Y]),S=Ce?.filter(e=>e.label.toLowerCase().includes(_e.toLowerCase())).slice(0,8)??[],V=i.useCallback(e=>{const n=d.current;if(!n)return;const s=window.getSelection();if(!s||s.rangeCount===0)return;const o=s.getRangeAt(0),a=o.startContainer;if(a.nodeType===Node.TEXT_NODE&&C){const k=a.textContent||"",T=o.startOffset,y=k.slice(0,T).lastIndexOf(C);if(y>=0){const _=k.slice(0,y),Ve=k.slice(T),Ge=`<span class="nice-htmleditor__mention" data-mention="${e.key}" contenteditable="false">${C}${e.label}</span> `;a.textContent=_;const G=document.createRange();G.setStartAfter(a),G.collapse(!0);const Ye=G.createContextualFragment(Ge+Ve);a.parentNode?.insertBefore(Ye,a.nextSibling),s.collapseToEnd(),c(n.innerHTML)}}R(!1)},[C,c]),We=i.useCallback(e=>{if(K&&S.length>0){e.key==="ArrowDown"?(e.preventDefault(),q(n=>Math.min(n+1,S.length-1))):e.key==="ArrowUp"?(e.preventDefault(),q(n=>Math.max(n-1,0))):e.key==="Enter"?(e.preventDefault(),V(S[A])):e.key==="Escape"&&R(!1);return}(e.ctrlKey||e.metaKey)&&e.key==="b"?(e.preventDefault(),p("bold")):(e.ctrlKey||e.metaKey)&&e.key==="i"?(e.preventDefault(),p("italic")):(e.ctrlKey||e.metaKey)&&e.key==="u"?(e.preventDefault(),p("underline")):(e.ctrlKey||e.metaKey)&&e.key==="f"?(e.preventDefault(),X(n=>!n)):(e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey?(e.preventDefault(),p("undo")):(e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey)&&(e.preventDefault(),p("redo"))},[K,S,A,V,p]),Ke=i.useCallback(e=>{if(!Z)return;e.preventDefault();const n=e.clipboardData.getData("text/html"),s=e.clipboardData.getData("text/plain");if(n){const a=n.replace(/<style[\s\S]*?<\/style>/gi,"").replace(/<script[\s\S]*?<\/script>/gi,"").replace(/class="[^"]*"/gi,"").replace(/style="[^"]*"/gi,"").replace(/<o:[^>]*>[\s\S]*?<\/o:[^>]*>/gi,"").replace(/<!--[\s\S]*?-->/g,"").replace(/<\/?(?:xml|meta|link|font|span)[^>]*>/gi,"");document.execCommand("insertHTML",!1,a)}else s&&document.execCommand("insertText",!1,s);const o=d.current;o&&(c(o.innerHTML),U(o.textContent?.length??0))},[Z,c]),Ae=i.useCallback(async e=>{if(!H)return;e.preventDefault();const n=Array.from(e.dataTransfer.files);if(n.length===0)return;const s=await H(n),o=d.current;if(o){o.focus();for(const a of s)if(/\.(png|jpe?g|gif|webp|svg|bmp|ico)$/i.test(a)||a.startsWith("data:image/"))document.execCommand("insertImage",!1,a);else{const T=`<a href="${a}">${a.split("/").pop()??a}</a>`;document.execCommand("insertHTML",!1,T)}c(o.innerHTML)}},[H,c]),qe=i.useCallback(e=>{H&&e.preventDefault()},[H]),pe=i.useCallback(e=>{const n=d.current;if(!n||!f)return;const s=n.textContent??"",o=f.toLowerCase(),a=s.toLowerCase();(e===1?a.indexOf(o):a.lastIndexOf(o))!==-1&&(n.focus(),window.find?.(f))},[f]),Pe=i.useCallback(()=>{const e=d.current;!e||!f||(e.innerHTML=e.innerHTML.split(f).join(N),c(e.innerHTML))},[f,N,c]),Ue=i.useCallback(()=>{if(!f)return;const e=m.split(f).join(N);c(e);const n=d.current;n&&(n.innerHTML=e)},[f,N,m,c]),Qe=i.useCallback(e=>{const n=d.current;n&&(n.focus(),document.execCommand("insertText",!1,e),c(n.innerHTML),ue(!1))},[c]),Xe=i.useCallback(e=>{const n=d.current;n&&(n.focus(),document.execCommand("insertHTML",!1,e),c(n.innerHTML),fe(!1))},[c]),Je=i.useCallback(e=>{const n=x||h;if(e==="fontSize")return r.jsx(Ze.NiceSelect,{size:"sm",value:"",onChange:o=>p("fontSize",String(o)),disabled:n,placeholder:"Size",options:rt.map(o=>({value:o.value,label:o.label})),style:{minWidth:70,maxWidth:80}},e);if(e==="fontColor")return r.jsx(g.NiceColorPicker,{value:le,onChange:o=>{ze(o),p("fontColor",o)},disabled:n,size:"sm",label:"",title:"Text color"},e);if(e==="bgColor")return r.jsx(g.NiceColorPicker,{value:ce,onChange:o=>{$e(o),p("bgColor",o)},disabled:n,size:"sm",label:"",title:"Highlight color"},e);const s=e==="markdown"&&v||e==="fullscreen"&&P||e==="source"&&j||e==="findReplace"&&Q||e==="emoji"&&J;return r.jsx(g.NiceButton,{size:"sm",variant:s?"primary":"ghost",onClick:()=>p(e),title:e,disabled:n,children:nt[e]||e},e)},[x,h,p,v,P,le,ce,j,Q,J]);return we?null:r.jsxs("div",{className:`nice-field nice-field--${ye} ${L?"nice-field--error":""} ${ve||""}`,style:je,children:[te&&r.jsxs("label",{className:"nice-field__label",htmlFor:oe,children:[te,ke&&r.jsx("span",{className:"nice-field__required",children:"*"})]}),r.jsxs("div",{ref:Ne,className:`nice-htmleditor${P?" nice-htmleditor--fullscreen":""}`,style:{position:"relative"},children:[r.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:r.jsx(u.NiceTutorialButton,{steps:u.resolveTutorial(Te,et)})}),r.jsxs("div",{className:"nice-htmleditor__toolbar",style:{display:"flex",flexWrap:"wrap",gap:2,alignItems:"center"},children:[ge.map(Je),D&&D.length>0&&r.jsxs("div",{style:{position:"relative"},children:[r.jsx(g.NiceButton,{size:"sm",variant:me?"primary":"ghost",onClick:()=>fe(e=>!e),title:"Insert template",children:r.jsx(u.NiceIcon,{name:"clipboard",size:16})}),me&&r.jsx("ul",{style:{position:"absolute",top:"100%",right:0,zIndex:200,background:"var(--nice-bg-primary, #fff)",border:"1px solid var(--nice-border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px var(--nice-overlay-12, rgba(0, 0, 0, 0.12))",listStyle:"none",margin:0,padding:4,minWidth:160,maxHeight:200,overflow:"auto"},children:D.map((e,n)=>r.jsx("li",{style:{padding:"6px 10px",cursor:"pointer",borderRadius:4},onMouseDown:s=>{s.preventDefault(),Xe(e.html)},children:e.label},n))})]})]}),Q&&r.jsxs("div",{className:"nice-htmleditor__find-bar",style:{display:"flex",gap:4,alignItems:"center",padding:"4px 8px",background:"var(--nice-bg-secondary, #f8f9fa)",borderBottom:"1px solid var(--nice-border-color, #ddd)",fontSize:"0.875em"},children:[r.jsx("input",{type:"text",placeholder:"Find...",value:f,onChange:e=>Ee(e.target.value),style:{flex:1,maxWidth:180,padding:"2px 6px",border:"1px solid var(--nice-border-color, #ccc)",borderRadius:4,background:"var(--nice-bg-primary, #fff)",color:"var(--nice-text-primary, #1f2937)"}}),r.jsx("input",{type:"text",placeholder:"Replace...",value:N,onChange:e=>Oe(e.target.value),style:{flex:1,maxWidth:180,padding:"2px 6px",border:"1px solid var(--nice-border-color, #ccc)",borderRadius:4,background:"var(--nice-bg-primary, #fff)",color:"var(--nice-text-primary, #1f2937)"}}),r.jsx(g.NiceButton,{size:"sm",variant:"ghost",onClick:()=>pe(1),title:"Find next",children:r.jsx(u.NiceIcon,{name:"chevron-right",size:14})}),r.jsx(g.NiceButton,{size:"sm",variant:"ghost",onClick:()=>pe(-1),title:"Find previous",children:r.jsx(u.NiceIcon,{name:"chevron-left",size:14})}),r.jsx(g.NiceButton,{size:"sm",variant:"ghost",onClick:Pe,disabled:x||h,children:"Replace"}),r.jsx(g.NiceButton,{size:"sm",variant:"ghost",onClick:Ue,disabled:x||h,children:"All"}),r.jsx(g.NiceButton,{size:"sm",variant:"ghost",onClick:()=>X(!1),children:r.jsx(u.NiceIcon,{name:"close",size:14,title:"Close"})})]}),J&&r.jsx("div",{className:"nice-htmleditor__emoji-picker",style:{padding:8,background:"var(--nice-bg-primary, #fff)",borderBottom:"1px solid var(--nice-border-color, #ddd)",maxHeight:180,overflowY:"auto"},children:ot.map(e=>r.jsxs("div",{children:[r.jsx("div",{style:{fontSize:"0.7em",fontWeight:600,color:"var(--nice-text-muted, #999)",padding:"4px 0"},children:e.label}),r.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:2},children:e.emojis.map(n=>r.jsx("span",{style:{cursor:"pointer",fontSize:"1.2em",padding:2,borderRadius:4},onClick:()=>Qe(n),title:n,children:n},n))})]},e.label))}),r.jsx("input",{ref:ie,type:"file",accept:"image/*",style:{display:"none"},onChange:Fe}),j?r.jsx("textarea",{className:"nice-htmleditor__source",value:W,onChange:e=>ae(e.target.value),style:{minHeight:$,width:"100%",fontFamily:"monospace",resize:"vertical",whiteSpace:"pre",fontSize:"0.85em",background:"var(--nice-bg-primary, #fff)",color:"var(--nice-text-primary, #1f2937)",border:"none",padding:12,boxSizing:"border-box",outline:"none"},disabled:x||h}):v?r.jsx("textarea",{className:"nice-htmleditor__markdown",value:F,onChange:e=>se(e.target.value),style:{minHeight:$,width:"100%",fontFamily:"monospace",resize:"vertical",background:"var(--nice-bg-primary, #fff)",color:"var(--nice-text-primary, #1f2937)",border:"none",padding:12,boxSizing:"border-box",outline:"none"},disabled:x||h}):r.jsxs("div",{style:{position:"relative"},children:[r.jsx("div",{ref:Me,id:oe,className:"nice-htmleditor__content",contentEditable:!x&&!h,dangerouslySetInnerHTML:He,onInput:Be,onKeyDown:We,onPaste:Ke,onDrop:Ae,onDragOver:qe,style:{minHeight:$},"data-placeholder":be,role:"textbox","aria-multiline":"true",suppressContentEditableWarning:!0}),K&&S.length>0&&r.jsx("ul",{className:"nice-htmleditor__mention-list",children:S.map((e,n)=>r.jsx("li",{className:`nice-htmleditor__mention-item ${n===A?"nice-htmleditor__mention-item--active":""}`,onMouseDown:s=>{s.preventDefault(),V(e)},children:e.label},e.key))})]}),r.jsxs("div",{className:"nice-htmleditor__statusbar",style:{display:"flex",gap:12,padding:"2px 8px",fontSize:"0.75em",color:"var(--nice-text-muted, #666)",borderTop:"1px solid var(--nice-border-color, #eee)"},children:[M>0&&r.jsxs("span",{children:[de," / ",M]}),ee&&r.jsxs("span",{children:[De," words"]}),ee&&r.jsxs("span",{children:[de," chars"]}),j&&r.jsx("span",{style:{fontWeight:600},children:"HTML Source"}),v&&r.jsx("span",{style:{fontWeight:600},children:"Markdown"})]})]}),L&&r.jsx("div",{className:"nice-field__error",children:L}),ne&&!L&&r.jsx("div",{className:"nice-field__hint",children:ne})]})};exports.NiceHtmlEditor=at;
|