@object-ui/plugin-timeline 17.5.0 → 17.6.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 +103 -0
- package/dist/ObjectTimeline.d.ts.map +1 -1
- package/dist/index.js +77 -87
- package/dist/index.umd.cjs +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,108 @@
|
|
|
1
1
|
# @object-ui/plugin-timeline
|
|
2
2
|
|
|
3
|
+
## 17.6.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [88085e3]
|
|
8
|
+
- Updated dependencies [69251bf]
|
|
9
|
+
- Updated dependencies [57e668f]
|
|
10
|
+
- Updated dependencies [516663d]
|
|
11
|
+
- Updated dependencies [41ac1b7]
|
|
12
|
+
- Updated dependencies [1eaf0a1]
|
|
13
|
+
- Updated dependencies [460c4d0]
|
|
14
|
+
- Updated dependencies [0ae27f7]
|
|
15
|
+
- Updated dependencies [2533ec5]
|
|
16
|
+
- Updated dependencies [78c0f9a]
|
|
17
|
+
- Updated dependencies [bbe8b86]
|
|
18
|
+
- Updated dependencies [8477be5]
|
|
19
|
+
- Updated dependencies [279fb13]
|
|
20
|
+
- Updated dependencies [2e82ab2]
|
|
21
|
+
- Updated dependencies [ad07b65]
|
|
22
|
+
- Updated dependencies [41f498b]
|
|
23
|
+
- Updated dependencies [ef0d150]
|
|
24
|
+
- Updated dependencies [f34226e]
|
|
25
|
+
- Updated dependencies [564b605]
|
|
26
|
+
- Updated dependencies [e1d4251]
|
|
27
|
+
- Updated dependencies [40d3a33]
|
|
28
|
+
- Updated dependencies [8b9dc62]
|
|
29
|
+
- Updated dependencies [1184192]
|
|
30
|
+
- Updated dependencies [a2a9747]
|
|
31
|
+
- Updated dependencies [a1609a6]
|
|
32
|
+
- Updated dependencies [53f23bc]
|
|
33
|
+
- Updated dependencies [c4533dc]
|
|
34
|
+
- Updated dependencies [be60815]
|
|
35
|
+
- Updated dependencies [37f6844]
|
|
36
|
+
- Updated dependencies [93de4f6]
|
|
37
|
+
- Updated dependencies [2b50261]
|
|
38
|
+
- Updated dependencies [384f30d]
|
|
39
|
+
- Updated dependencies [ac600e5]
|
|
40
|
+
- Updated dependencies [97fba31]
|
|
41
|
+
- Updated dependencies [232f61a]
|
|
42
|
+
- Updated dependencies [d374caf]
|
|
43
|
+
- Updated dependencies [5673576]
|
|
44
|
+
- Updated dependencies [c1ef923]
|
|
45
|
+
- Updated dependencies [911ceaa]
|
|
46
|
+
- Updated dependencies [98eab36]
|
|
47
|
+
- Updated dependencies [af5e292]
|
|
48
|
+
- Updated dependencies [3fbbea1]
|
|
49
|
+
- Updated dependencies [5458414]
|
|
50
|
+
- Updated dependencies [7f96b10]
|
|
51
|
+
- Updated dependencies [167ec42]
|
|
52
|
+
- Updated dependencies [616a2a5]
|
|
53
|
+
- Updated dependencies [0046d8f]
|
|
54
|
+
- Updated dependencies [f1d4748]
|
|
55
|
+
- Updated dependencies [bea374e]
|
|
56
|
+
- Updated dependencies [b1119ec]
|
|
57
|
+
- Updated dependencies [9f23d2b]
|
|
58
|
+
- Updated dependencies [578e025]
|
|
59
|
+
- Updated dependencies [af025ee]
|
|
60
|
+
- Updated dependencies [d109a4d]
|
|
61
|
+
- Updated dependencies [598c89a]
|
|
62
|
+
- Updated dependencies [4a0bd17]
|
|
63
|
+
- Updated dependencies [b8b9af4]
|
|
64
|
+
- Updated dependencies [31676be]
|
|
65
|
+
- Updated dependencies [8c0d52e]
|
|
66
|
+
- Updated dependencies [aff10e2]
|
|
67
|
+
- Updated dependencies [70a774b]
|
|
68
|
+
- Updated dependencies [9ce096f]
|
|
69
|
+
- Updated dependencies [e05db88]
|
|
70
|
+
- Updated dependencies [7458a41]
|
|
71
|
+
- Updated dependencies [ad13d63]
|
|
72
|
+
- Updated dependencies [5ffcc14]
|
|
73
|
+
- Updated dependencies [d971e51]
|
|
74
|
+
- Updated dependencies [97abb24]
|
|
75
|
+
- Updated dependencies [deb157a]
|
|
76
|
+
- Updated dependencies [9c60144]
|
|
77
|
+
- Updated dependencies [d2ce342]
|
|
78
|
+
- Updated dependencies [9695da7]
|
|
79
|
+
- Updated dependencies [75444e3]
|
|
80
|
+
- Updated dependencies [58b8346]
|
|
81
|
+
- Updated dependencies [2d0bd16]
|
|
82
|
+
- Updated dependencies [a9e17b4]
|
|
83
|
+
- Updated dependencies [b8ce7dc]
|
|
84
|
+
- Updated dependencies [dad51e5]
|
|
85
|
+
- Updated dependencies [1c9c342]
|
|
86
|
+
- Updated dependencies [787c738]
|
|
87
|
+
- Updated dependencies [8396656]
|
|
88
|
+
- Updated dependencies [dbbd38a]
|
|
89
|
+
- Updated dependencies [8871c14]
|
|
90
|
+
- Updated dependencies [93fe362]
|
|
91
|
+
- Updated dependencies [dfc6975]
|
|
92
|
+
- Updated dependencies [3cf4de0]
|
|
93
|
+
- Updated dependencies [c9dc811]
|
|
94
|
+
- Updated dependencies [144ef9b]
|
|
95
|
+
- Updated dependencies [138ab04]
|
|
96
|
+
- Updated dependencies [a0b9e91]
|
|
97
|
+
- Updated dependencies [99bd015]
|
|
98
|
+
- Updated dependencies [21e4585]
|
|
99
|
+
- @object-ui/types@17.6.0
|
|
100
|
+
- @object-ui/i18n@17.6.0
|
|
101
|
+
- @object-ui/react@17.6.0
|
|
102
|
+
- @object-ui/components@17.6.0
|
|
103
|
+
- @object-ui/core@17.6.0
|
|
104
|
+
- @object-ui/mobile@17.6.0
|
|
105
|
+
|
|
3
106
|
## 17.5.0
|
|
4
107
|
|
|
5
108
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectTimeline.d.ts","sourceRoot":"","sources":["../src/ObjectTimeline.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ObjectTimeline.d.ts","sourceRoot":"","sources":["../src/ObjectTimeline.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAS3F;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAuB1C,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,cAAc,GAAG;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB;;;;WAIG;QACH,QAAQ,CAAC,EAAE,sBAAsB,CAAC;QAClC;;;;;;;;;WASG;QACH,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACrC;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;SAAE,CAAC,CAAC;QAClE;;;;WAIG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,kDAAkD;QAClD,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,sDAAsD;QACtD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,sDAAsD;QACtD,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,oDAAoD;QACpD,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,oDAAoD;QACpD,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,kDAAkD;QAClD,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,6CAA6C;QAC7C,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;QAE/D,OAAO,CAAC,EAAE;YACR,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAA;KACF,CAAC;IACF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;CACrC;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CA0WxD,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { NavigationOverlay as a, cn as o, cva as s, renderChildren as c } from "
|
|
|
4
4
|
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
5
5
|
import { ComponentRegistry as d, buildExpandFields as f, convertSortToQueryParams as p, extractRecords as m } from "@object-ui/core";
|
|
6
6
|
import { createSafeTranslation as h, useDisplayLocale as g } from "@object-ui/i18n";
|
|
7
|
-
import { ElementDataSourceGate as ee, useDataScope as te, useNavigationOverlay as ne,
|
|
7
|
+
import { ElementDataSourceGate as ee, useDataScope as te, useNavigationOverlay as ne, useSafeFieldLabel as re, useSchemaContext as _ } from "@object-ui/react";
|
|
8
8
|
import { usePullToRefresh as ie } from "@object-ui/mobile";
|
|
9
9
|
import { z as v } from "zod";
|
|
10
10
|
//#region src/useTimelineTranslation.ts
|
|
@@ -83,14 +83,14 @@ function E(e) {
|
|
|
83
83
|
maxDate: new Date(r).toISOString().split("T")[0]
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function D(e, t, n, r) {
|
|
87
87
|
let i = new Date(e).getTime(), a = new Date(t).getTime(), o = new Date(n).getTime(), s = new Date(r).getTime() - o, c = i - o, l = a - i;
|
|
88
88
|
return {
|
|
89
89
|
start: c / s * 100,
|
|
90
90
|
width: l / s * 100
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function O(e, t, n) {
|
|
94
94
|
let r = new Date(e);
|
|
95
95
|
return t === "short" ? r.toLocaleDateString(n) : t === "long" ? r.toLocaleDateString(n, {
|
|
96
96
|
year: "numeric",
|
|
@@ -98,7 +98,7 @@ function D(e, t, n) {
|
|
|
98
98
|
day: "numeric"
|
|
99
99
|
}) : r.toISOString().split("T")[0];
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function k({ label: e, color: t }) {
|
|
102
102
|
let n = t ? {
|
|
103
103
|
backgroundColor: `${t}22`,
|
|
104
104
|
color: t,
|
|
@@ -110,7 +110,7 @@ function O({ label: e, color: t }) {
|
|
|
110
110
|
children: e
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function A(e) {
|
|
114
114
|
let t = [];
|
|
115
115
|
for (let n of e) {
|
|
116
116
|
let e = n.group == null ? "" : String(n.group), r = t[t.length - 1];
|
|
@@ -121,14 +121,14 @@ function k(e) {
|
|
|
121
121
|
}
|
|
122
122
|
return t;
|
|
123
123
|
}
|
|
124
|
-
var
|
|
124
|
+
var j = ({ schema: e, className: t, ...n }) => {
|
|
125
125
|
let { variant: r = "vertical", items: i = [], dateFormat: a = "short", onItemClick: s } = e, d = g(), { t: f } = S();
|
|
126
126
|
if (r === "vertical") {
|
|
127
|
-
let e =
|
|
127
|
+
let e = A(i), r = e.some((e) => e.key !== ""), f = (e, t) => {
|
|
128
128
|
let n = e.color ? {
|
|
129
129
|
backgroundColor: `${e.color}33`,
|
|
130
130
|
borderColor: e.color
|
|
131
|
-
} : void 0, r = e.time ?
|
|
131
|
+
} : void 0, r = e.time ? O(e.time, a, d) : e.startDate ? O(e.startDate, a, d) : "", i = e.endDate && e.endDate !== e.startDate ? O(e.endDate, a, d) : "", f = Array.isArray(e.meta) ? e.meta : [];
|
|
132
132
|
return /* @__PURE__ */ u(I, {
|
|
133
133
|
density: "compact",
|
|
134
134
|
className: o(e.className, s && "cursor-pointer"),
|
|
@@ -155,7 +155,7 @@ var A = ({ schema: e, className: t, ...n }) => {
|
|
|
155
155
|
}),
|
|
156
156
|
f.length > 0 && /* @__PURE__ */ l("div", {
|
|
157
157
|
className: "flex flex-wrap gap-1.5 mt-1 mb-1",
|
|
158
|
-
children: f.map((e) => /* @__PURE__ */ l(
|
|
158
|
+
children: f.map((e) => /* @__PURE__ */ l(k, {
|
|
159
159
|
label: e.label,
|
|
160
160
|
color: e.color
|
|
161
161
|
}, e.key))
|
|
@@ -209,7 +209,7 @@ var A = ({ schema: e, className: t, ...n }) => {
|
|
|
209
209
|
children: [
|
|
210
210
|
e.time && /* @__PURE__ */ l(V, {
|
|
211
211
|
dateTime: e.time,
|
|
212
|
-
children:
|
|
212
|
+
children: O(e.time, a, d)
|
|
213
213
|
}),
|
|
214
214
|
e.title && /* @__PURE__ */ l(B, { children: e.title }),
|
|
215
215
|
e.description && /* @__PURE__ */ l(H, {
|
|
@@ -250,13 +250,13 @@ var A = ({ schema: e, className: t, ...n }) => {
|
|
|
250
250
|
children: i.map((e, t) => /* @__PURE__ */ l(Y, {
|
|
251
251
|
className: "relative",
|
|
252
252
|
children: (e.items || []).map((n, r) => {
|
|
253
|
-
let i =
|
|
253
|
+
let i = D(n.startDate, n.endDate, c, p);
|
|
254
254
|
return /* @__PURE__ */ l(Z, {
|
|
255
255
|
start: i.start,
|
|
256
256
|
width: i.width,
|
|
257
257
|
variant: n.variant || "default",
|
|
258
258
|
onClick: () => s?.(n, e, t, r),
|
|
259
|
-
title: `${n.title || ""}\n${
|
|
259
|
+
title: `${n.title || ""}\n${O(n.startDate, a, d)} - ${O(n.endDate, a, d)}`,
|
|
260
260
|
children: /* @__PURE__ */ l(Q, { children: n.title })
|
|
261
261
|
}, r);
|
|
262
262
|
})
|
|
@@ -267,7 +267,7 @@ var A = ({ schema: e, className: t, ...n }) => {
|
|
|
267
267
|
}
|
|
268
268
|
return null;
|
|
269
269
|
};
|
|
270
|
-
d.register("timeline",
|
|
270
|
+
d.register("timeline", j, {
|
|
271
271
|
namespace: "plugin-timeline",
|
|
272
272
|
label: "Timeline",
|
|
273
273
|
category: "data-display",
|
|
@@ -462,22 +462,12 @@ d.register("timeline", A, {
|
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
});
|
|
465
|
-
//#endregion
|
|
466
|
-
//#region src/ObjectTimeline.tsx
|
|
467
|
-
var j = {
|
|
468
|
-
fieldOptionLabel: (e, t, n, r) => r,
|
|
469
|
-
translateOptions: (e, t, n) => n,
|
|
470
|
-
fieldLabel: (e, t, n) => n
|
|
471
|
-
};
|
|
472
|
-
function oe() {
|
|
473
|
-
return re() ?? j;
|
|
474
|
-
}
|
|
475
465
|
var M = v.object({
|
|
476
466
|
title: v.string().optional(),
|
|
477
467
|
date: v.string().optional(),
|
|
478
468
|
description: v.string().optional(),
|
|
479
469
|
variant: v.string().optional()
|
|
480
|
-
}),
|
|
470
|
+
}), ae = v.object({
|
|
481
471
|
mapping: M.optional(),
|
|
482
472
|
objectName: v.string().optional(),
|
|
483
473
|
titleField: v.string().optional(),
|
|
@@ -496,21 +486,21 @@ var M = v.object({
|
|
|
496
486
|
"year"
|
|
497
487
|
]).optional()
|
|
498
488
|
}), N = ({ schema: e, dataSource: o, className: s, onRowClick: c, onItemClick: d, ...h }) => {
|
|
499
|
-
let [g, ee] = i([]), [
|
|
489
|
+
let [g, ee] = i([]), [_, v] = i(() => {
|
|
500
490
|
let t = Array.isArray(e.items) && e.items.length > 0, n = Array.isArray(h.data) && h.data.length > 0;
|
|
501
491
|
return !t && !n && !!e.objectName;
|
|
502
|
-
}), [
|
|
492
|
+
}), [y, b] = i(null), [x, C] = i(0), [w, T] = i(null), E = e.timeline;
|
|
503
493
|
n(() => {
|
|
504
|
-
let t =
|
|
494
|
+
let t = ae.safeParse(e);
|
|
505
495
|
t.success || console.warn("[ObjectTimeline] Invalid timeline configuration:", t.error.format());
|
|
506
496
|
}, [e]);
|
|
507
|
-
let
|
|
497
|
+
let D = te(e.bind);
|
|
508
498
|
n(() => {
|
|
509
499
|
let t = !0;
|
|
510
500
|
return (async () => {
|
|
511
501
|
if (!(!o || typeof o.getObjectSchema != "function" || !e.objectName)) try {
|
|
512
502
|
let n = await o.getObjectSchema(e.objectName);
|
|
513
|
-
t &&
|
|
503
|
+
t && T(n);
|
|
514
504
|
} catch (e) {
|
|
515
505
|
console.warn("Failed to fetch object def for ObjectTimeline", e);
|
|
516
506
|
}
|
|
@@ -518,16 +508,16 @@ var M = v.object({
|
|
|
518
508
|
t = !1;
|
|
519
509
|
};
|
|
520
510
|
}, [e.objectName, o]);
|
|
521
|
-
let
|
|
511
|
+
let O = JSON.stringify(e.filter ?? null), k = JSON.stringify(e.sort ?? null);
|
|
522
512
|
n(() => {
|
|
523
|
-
e.objectName && !
|
|
513
|
+
e.objectName && !D && !e.items && !h.data ? (async () => {
|
|
524
514
|
if (!o || typeof o.find != "function" || !e.objectName) {
|
|
525
|
-
|
|
515
|
+
v(!1);
|
|
526
516
|
return;
|
|
527
517
|
}
|
|
528
|
-
|
|
518
|
+
v(!0);
|
|
529
519
|
try {
|
|
530
|
-
let t = f(
|
|
520
|
+
let t = f(w?.fields), n = await o.find(e.objectName, {
|
|
531
521
|
$filter: e.filter,
|
|
532
522
|
$orderby: p(e.sort),
|
|
533
523
|
$top: e.limit ?? 100,
|
|
@@ -535,32 +525,32 @@ var M = v.object({
|
|
|
535
525
|
}), r = m(n);
|
|
536
526
|
ee(r);
|
|
537
527
|
} catch (e) {
|
|
538
|
-
console.error(e),
|
|
528
|
+
console.error(e), b(e);
|
|
539
529
|
} finally {
|
|
540
|
-
|
|
530
|
+
v(!1);
|
|
541
531
|
}
|
|
542
|
-
})() :
|
|
532
|
+
})() : v(!1);
|
|
543
533
|
}, [
|
|
544
534
|
e.objectName,
|
|
545
535
|
o,
|
|
546
|
-
|
|
536
|
+
D,
|
|
547
537
|
e.items,
|
|
548
538
|
h.data,
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
539
|
+
x,
|
|
540
|
+
w,
|
|
541
|
+
O,
|
|
542
|
+
k,
|
|
553
543
|
e.limit
|
|
554
544
|
]);
|
|
555
|
-
let
|
|
545
|
+
let A = h.data || D || g, { t: M } = S(), { fieldOptionLabel: N } = re(), P = E?.titleField ?? e.mapping?.title ?? e.titleField ?? "name", F = E?.startDateField ?? E?.dateField ?? e.mapping?.date ?? e.startDateField ?? e.dateField ?? "date", I = E?.endDateField ?? e.endDateField ?? F, L = e.mapping?.description ?? e.descriptionField ?? "description", R = e.mapping?.variant ?? "variant", z = E?.groupByField ?? e.groupByField, B = E?.colorField ?? e.colorField, V = r(() => {
|
|
556
546
|
if (e.items) return e.items;
|
|
557
|
-
if (!
|
|
558
|
-
let t =
|
|
547
|
+
if (!A || !Array.isArray(A)) return [];
|
|
548
|
+
let t = w?.fields ?? {}, n = e.objectName || "", r = (e) => {
|
|
559
549
|
if (!e || !t[e]?.options) return {};
|
|
560
550
|
let n = {};
|
|
561
551
|
for (let r of t[e].options) r && r.value != null && (n[String(r.value)] = r);
|
|
562
552
|
return n;
|
|
563
|
-
}, i = r(
|
|
553
|
+
}, i = r(B), a = Array.isArray(E?.metaFields) ? E.metaFields.filter((e) => typeof e == "string" && e) : ["status", "priority"].filter((e) => t[e]), o = {};
|
|
564
554
|
for (let e of a) o[e] = r(e);
|
|
565
555
|
let s = (e) => {
|
|
566
556
|
if (e == null || e === "") return;
|
|
@@ -572,11 +562,11 @@ var M = v.object({
|
|
|
572
562
|
if (t == null || t === "") return null;
|
|
573
563
|
let i = r[String(t)];
|
|
574
564
|
return {
|
|
575
|
-
label: i?.label ?
|
|
565
|
+
label: i?.label ? N(n, e, String(t), i.label) : String(t),
|
|
576
566
|
color: i?.color
|
|
577
567
|
};
|
|
578
|
-
}, l =
|
|
579
|
-
let t = e[
|
|
568
|
+
}, l = A.map((e) => {
|
|
569
|
+
let t = e[F], r = e[I], i = B ? e[B] : void 0, l = z ? e[z] : void 0, u = [];
|
|
580
570
|
if (n) for (let t of a) {
|
|
581
571
|
let n = c(t, e[t], o[t] || {});
|
|
582
572
|
n && u.push({
|
|
@@ -586,12 +576,12 @@ var M = v.object({
|
|
|
586
576
|
});
|
|
587
577
|
}
|
|
588
578
|
return {
|
|
589
|
-
title: e[
|
|
579
|
+
title: e[P],
|
|
590
580
|
time: t,
|
|
591
581
|
startDate: t,
|
|
592
582
|
endDate: r,
|
|
593
|
-
description: e[
|
|
594
|
-
variant: e[
|
|
583
|
+
description: e[L],
|
|
584
|
+
variant: e[R] || "default",
|
|
595
585
|
color: s(i),
|
|
596
586
|
group: l,
|
|
597
587
|
meta: u,
|
|
@@ -600,17 +590,17 @@ var M = v.object({
|
|
|
600
590
|
});
|
|
601
591
|
l.sort((e, t) => (e.startDate ? new Date(e.startDate).getTime() : Infinity) - (t.startDate ? new Date(t.startDate).getTime() : Infinity));
|
|
602
592
|
let u = /* @__PURE__ */ new Date(), d = (e) => new Date(e.getFullYear(), e.getMonth(), e.getDate()).getTime(), f = d(u), p = 864e5, m = f - (u.getDay() + 6) % 7 * p + 7 * p, h = m + 7 * p, g = (e) => {
|
|
603
|
-
if (!e) return
|
|
593
|
+
if (!e) return M("timeline.bucket.noDate");
|
|
604
594
|
let t = d(new Date(e));
|
|
605
|
-
return Number.isNaN(t) ?
|
|
595
|
+
return Number.isNaN(t) ? M("timeline.bucket.noDate") : t < f ? M("timeline.bucket.overdue") : t === f ? M("timeline.bucket.today") : t === f + p ? M("timeline.bucket.tomorrow") : M(t < m ? "timeline.bucket.thisWeek" : t < h ? "timeline.bucket.nextWeek" : "timeline.bucket.later");
|
|
606
596
|
};
|
|
607
|
-
if (
|
|
608
|
-
let e = r(
|
|
597
|
+
if (z && !l.every((e) => e.group == null || e.group === "")) {
|
|
598
|
+
let e = r(z);
|
|
609
599
|
return l.map((t) => {
|
|
610
|
-
let n = c(
|
|
600
|
+
let n = c(z, t.group, e);
|
|
611
601
|
return {
|
|
612
602
|
...t,
|
|
613
|
-
group: n ? n.label : t.group != null && t.group !== "" ? String(t.group) :
|
|
603
|
+
group: n ? n.label : t.group != null && t.group !== "" ? String(t.group) : M("timeline.bucket.unassigned")
|
|
614
604
|
};
|
|
615
605
|
});
|
|
616
606
|
}
|
|
@@ -620,43 +610,43 @@ var M = v.object({
|
|
|
620
610
|
}));
|
|
621
611
|
}, [
|
|
622
612
|
e.items,
|
|
623
|
-
|
|
624
|
-
|
|
613
|
+
A,
|
|
614
|
+
w,
|
|
625
615
|
e.objectName,
|
|
626
|
-
M,
|
|
627
|
-
N,
|
|
628
616
|
P,
|
|
629
617
|
F,
|
|
630
618
|
I,
|
|
631
|
-
R,
|
|
632
619
|
L,
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
620
|
+
R,
|
|
621
|
+
B,
|
|
622
|
+
z,
|
|
623
|
+
M,
|
|
624
|
+
N
|
|
625
|
+
]), H = t(async () => {
|
|
626
|
+
C((e) => e + 1);
|
|
627
|
+
}, []), { ref: U, isRefreshing: W, pullDistance: G } = ie({
|
|
628
|
+
onRefresh: H,
|
|
639
629
|
enabled: !!e.objectName && !!o
|
|
640
|
-
}),
|
|
630
|
+
}), K = ne({
|
|
641
631
|
navigation: e.navigation,
|
|
642
632
|
objectName: e.objectName,
|
|
643
633
|
onRowClick: c ?? d
|
|
644
|
-
}),
|
|
634
|
+
}), q = E?.scale ?? e.scale, J = {
|
|
645
635
|
...e,
|
|
646
|
-
items:
|
|
636
|
+
items: V || [],
|
|
647
637
|
className: s || e.className,
|
|
648
|
-
...
|
|
638
|
+
...q ? { timeScale: q } : {},
|
|
649
639
|
onItemClick: (e) => {
|
|
650
640
|
let t = e._data || e;
|
|
651
|
-
|
|
641
|
+
K.handleClick(t), d?.(t);
|
|
652
642
|
}
|
|
653
643
|
};
|
|
654
|
-
return
|
|
644
|
+
return y ? /* @__PURE__ */ u("div", {
|
|
655
645
|
className: "p-4 text-destructive",
|
|
656
646
|
"data-testid": "timeline-error",
|
|
657
647
|
role: "alert",
|
|
658
|
-
children: ["Error loading timeline: ",
|
|
659
|
-
}) :
|
|
648
|
+
children: ["Error loading timeline: ", y.message]
|
|
649
|
+
}) : _ && (!V || V.length === 0) ? /* @__PURE__ */ u("div", {
|
|
660
650
|
className: "flex flex-col h-full min-h-[200px] p-4 gap-3",
|
|
661
651
|
"data-testid": "timeline-loading",
|
|
662
652
|
role: "status",
|
|
@@ -679,17 +669,17 @@ var M = v.object({
|
|
|
679
669
|
})]
|
|
680
670
|
}, e))]
|
|
681
671
|
}) : /* @__PURE__ */ u("div", {
|
|
682
|
-
ref:
|
|
672
|
+
ref: U,
|
|
683
673
|
className: "relative overflow-auto h-full min-w-0",
|
|
684
674
|
children: [
|
|
685
|
-
|
|
675
|
+
G > 0 && /* @__PURE__ */ l("div", {
|
|
686
676
|
className: "flex items-center justify-center text-xs text-muted-foreground",
|
|
687
|
-
style: { height:
|
|
688
|
-
children:
|
|
677
|
+
style: { height: G },
|
|
678
|
+
children: W ? "Refreshing…" : "Pull to refresh"
|
|
689
679
|
}),
|
|
690
|
-
/* @__PURE__ */ l(
|
|
691
|
-
|
|
692
|
-
...
|
|
680
|
+
/* @__PURE__ */ l(j, { schema: J }),
|
|
681
|
+
K.isOverlay && /* @__PURE__ */ l(a, {
|
|
682
|
+
...K,
|
|
693
683
|
title: "Timeline Item",
|
|
694
684
|
children: (e) => /* @__PURE__ */ l("div", {
|
|
695
685
|
className: "space-y-3",
|
|
@@ -838,7 +828,7 @@ var Q = e.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ l("div", {
|
|
|
838
828
|
...t
|
|
839
829
|
}));
|
|
840
830
|
Q.displayName = "TimelineGanttBarContent";
|
|
841
|
-
var
|
|
831
|
+
var oe = {
|
|
842
832
|
filter: !0,
|
|
843
833
|
sort: !0,
|
|
844
834
|
limit: "limit"
|
|
@@ -846,7 +836,7 @@ var ce = {
|
|
|
846
836
|
let { dataSource: n } = _() || {};
|
|
847
837
|
return /* @__PURE__ */ l(ee, {
|
|
848
838
|
schema: e,
|
|
849
|
-
mapping:
|
|
839
|
+
mapping: oe,
|
|
850
840
|
dataSource: n,
|
|
851
841
|
testId: "object-timeline",
|
|
852
842
|
errorTitle: "This timeline’s data source could not be resolved",
|
|
@@ -897,4 +887,4 @@ d.register("object-timeline", $, {
|
|
|
897
887
|
}]
|
|
898
888
|
});
|
|
899
889
|
//#endregion
|
|
900
|
-
export { N as ObjectTimeline, $ as ObjectTimelineRenderer, C as TIMELINE_SCALES, P as Timeline, z as TimelineContent, H as TimelineDescription, G as TimelineGantt, Z as TimelineGanttBar, Q as TimelineGanttBarContent, J as TimelineGanttGrid, K as TimelineGanttHeader, X as TimelineGanttLabel, Y as TimelineGanttRow, q as TimelineGanttRowLabels, U as TimelineHorizontal, W as TimelineHorizontalItem, I as TimelineItem, R as TimelineMarker,
|
|
890
|
+
export { N as ObjectTimeline, $ as ObjectTimelineRenderer, C as TIMELINE_SCALES, P as Timeline, z as TimelineContent, H as TimelineDescription, G as TimelineGantt, Z as TimelineGanttBar, Q as TimelineGanttBarContent, J as TimelineGanttGrid, K as TimelineGanttHeader, X as TimelineGanttLabel, Y as TimelineGanttRow, q as TimelineGanttRowLabels, U as TimelineHorizontal, W as TimelineHorizontalItem, I as TimelineItem, R as TimelineMarker, j as TimelineRenderer, V as TimelineTime, B as TimelineTitle, T as generateTimeScaleHeaders, w as resolveTimelineScale, F as timelineItemVariants, L as timelineMarkerVariants };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/components"),require("react/jsx-runtime"),require("@object-ui/core"),require("@object-ui/i18n"),require("@object-ui/react"),require("@object-ui/mobile"),require("zod")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/components`,`react/jsx-runtime`,`@object-ui/core`,`@object-ui/i18n`,`@object-ui/react`,`@object-ui/mobile`,`zod`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginTimeline={},e.React,e.ObjectUIComponents,e.react_jsx_runtime,e.ObjectUICore,e._object_ui_i18n,e.ObjectUIReact,e.ObjectUIMobile,e.zod))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule||!m.call(e,`default`)?u(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var g={"timeline.bucket.overdue":`Overdue`,"timeline.bucket.today":`Today`,"timeline.bucket.tomorrow":`Tomorrow`,"timeline.bucket.thisWeek":`This week`,"timeline.bucket.nextWeek":`Next week`,"timeline.bucket.later":`Later`,"timeline.bucket.noDate":`No date`,"timeline.bucket.unassigned":`Unassigned`,"timeline.relative.today":`Today`,"timeline.relative.tomorrow":`Tomorrow`,"timeline.relative.yesterday":`Yesterday`,"timeline.relative.inDays":`In {{n}} days`,"timeline.relative.daysAgo":`{{n}} days ago`,"timeline.scale.week":`Week {{n}}`,"timeline.scale.quarter":`Q{{quarter}} {{year}}`,"timeline.gantt.rowLabel":`Items`},_=`timeline.bucket.today`,v=(e,t)=>Object.entries(t??{}).reduce((e,[t,n])=>e.split(`{{${t}}}`).join(String(n)),g[e]||e),y=(0,a.createSafeTranslation)(g,_),b=new Set([`hour`,`day`,`week`,`month`,`quarter`,`year`]);function x(e){let t=e.scale??e.timeScale;return typeof t==`string`&&b.has(t)?t:`month`}function S(e,t,n,r=`en`,i=v){let a=[],o=new Date(t),s=new Date(n);if(Number.isNaN(o.getTime())||Number.isNaN(s.getTime())||o>s)return a;let c=new Date(o);switch(e){case`hour`:for(;c<=s;)a.push(c.toLocaleString(r,{month:`short`,day:`numeric`,hour:`numeric`})),c.setHours(c.getHours()+1);break;case`day`:for(;c<=s;)a.push(c.toLocaleDateString(r,{month:`short`,day:`numeric`})),c.setDate(c.getDate()+1);break;case`week`:{let e=1;for(;c<=s;)a.push(i(`timeline.scale.week`,{n:e++})),c.setDate(c.getDate()+7);break}case`quarter`:for(c.setMonth(Math.floor(c.getMonth()/3)*3,1);c<=s;)a.push(i(`timeline.scale.quarter`,{quarter:Math.floor(c.getMonth()/3)+1,year:c.getFullYear()})),c.setMonth(c.getMonth()+3);break;case`year`:for(c.setMonth(0,1);c<=s;)a.push(String(c.getFullYear())),c.setFullYear(c.getFullYear()+1);break;default:for(;c<=s;)a.push(c.toLocaleDateString(r,{month:`short`,year:`numeric`})),c.setMonth(c.getMonth()+1)}return a}function C(e){let t=e.flatMap(e=>(e.items||[]).flatMap(e=>[e.startDate,e.endDate])),n=Math.min(...t.map(e=>new Date(e).getTime())),r=Math.max(...t.map(e=>new Date(e).getTime()));return{minDate:new Date(n).toISOString().split(`T`)[0],maxDate:new Date(r).toISOString().split(`T`)[0]}}function w(e,t,n,r){let i=new Date(e).getTime(),a=new Date(t).getTime(),o=new Date(n).getTime(),s=new Date(r).getTime()-o,c=i-o,l=a-i;return{start:c/s*100,width:l/s*100}}function T(e,t,n){let r=new Date(e);return t===`short`?r.toLocaleDateString(n):t===`long`?r.toLocaleDateString(n,{year:`numeric`,month:`long`,day:`numeric`}):r.toISOString().split(`T`)[0]}function E({label:e,color:t}){let i=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,r.jsx)(`span`,{className:(0,n.cn)(`inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-medium`,!t&&`bg-muted text-muted-foreground border-transparent`),style:i,children:e})}function D(e){let t=[];for(let n of e){let e=n.group==null?``:String(n.group),r=t[t.length-1];r&&r.key===e?r.items.push(n):t.push({key:e,items:[n]})}return t}var O=({schema:e,className:t,...i})=>{let{variant:o=`vertical`,items:s=[],dateFormat:c=`short`,onItemClick:l}=e,u=(0,a.useDisplayLocale)(),{t:d}=y();if(o===`vertical`){let e=D(s),a=e.some(e=>e.key!==``),o=(e,t)=>{let i=e.color?{backgroundColor:`${e.color}33`,borderColor:e.color}:void 0,a=e.time?T(e.time,c,u):e.startDate?T(e.startDate,c,u):``,o=e.endDate&&e.endDate!==e.startDate?T(e.endDate,c,u):``,s=Array.isArray(e.meta)?e.meta:[];return(0,r.jsxs)(I,{density:`compact`,className:(0,n.cn)(e.className,l&&`cursor-pointer`),onClick:()=>l?.(e),children:[(0,r.jsx)(R,{variant:e.color?`default`:e.variant||`default`,style:i,children:e.icon&&(0,r.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,r.jsxs)(z,{children:[(a||o)&&(0,r.jsxs)(V,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[a,o&&(0,r.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,o]})]}),e.title&&(0,r.jsx)(B,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,r.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,r.jsx)(E,{label:e.label,color:e.color},e.key))}),e.description&&(0,r.jsx)(H,{className:`text-sm text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&(0,n.renderChildren)(e.content)]})]},t)};return a?(0,r.jsx)(`div`,{className:(0,n.cn)(`px-4 sm:px-6 py-2`,t),...i,children:e.map((e,t)=>(0,r.jsxs)(`section`,{className:`mb-4`,children:[(0,r.jsxs)(`header`,{className:`sticky top-0 z-10 -mx-4 sm:-mx-6 px-4 sm:px-6 py-1.5 backdrop-blur bg-background/90 text-xs font-semibold uppercase tracking-wide text-muted-foreground border-b`,children:[(0,r.jsx)(`span`,{children:e.key}),(0,r.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,r.jsx)(P,{className:`mt-3`,children:e.items.map((e,n)=>o(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,r.jsx)(P,{className:t,...i,children:s.map((e,t)=>o(e,t))})}if(o===`horizontal`)return(0,r.jsx)(U,{className:(0,n.cn)(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...i,children:s.map((e,t)=>(0,r.jsxs)(W,{className:(0,n.cn)(e.className,l&&`cursor-pointer`),onClick:()=>l?.(e),children:[(0,r.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,r.jsx)(R,{variant:e.variant||`default`,children:e.icon&&(0,r.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,r.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,r.jsx)(V,{dateTime:e.time,children:T(e.time,c,u)}),e.title&&(0,r.jsx)(B,{children:e.title}),e.description&&(0,r.jsx)(H,{className:`text-center line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&(0,n.renderChildren)(e.content)]})]}),t<s.length-1&&(0,r.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(o===`gantt`){let a=C(s),o=e.minDate||a.minDate,f=e.maxDate||a.maxDate,p=S(x(e),o,f,u,d);return(0,r.jsxs)(G,{className:(0,n.cn)(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...i,children:[(0,r.jsxs)(K,{children:[(0,r.jsx)(q,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,r.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||d(`timeline.gantt.rowLabel`)})}),(0,r.jsx)(J,{children:(0,r.jsx)(`div`,{className:`flex h-full`,children:p.map((e,t)=>(0,r.jsx)(`div`,{className:`flex-1 px-1 sm:px-2 py-2 sm:py-3 border-r text-xs font-medium text-center`,children:e},t))})})]}),(0,r.jsx)(`div`,{children:(0,r.jsxs)(`div`,{className:`flex`,children:[(0,r.jsx)(q,{children:s.map((e,t)=>(0,r.jsx)(Y,{children:(0,r.jsx)(X,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,r.jsx)(J,{className:`relative`,children:s.map((e,t)=>(0,r.jsx)(Y,{className:`relative`,children:(e.items||[]).map((n,i)=>{let a=w(n.startDate,n.endDate,o,f);return(0,r.jsx)(Z,{start:a.start,width:a.width,variant:n.variant||`default`,onClick:()=>l?.(n,e,t,i),title:`${n.title||``}\n${T(n.startDate,c,u)} - ${T(n.endDate,c,u)}`,children:(0,r.jsx)(Q,{children:n.title})},i)})},t))})]})})]})}return null};i.ComponentRegistry.register(`timeline`,O,{namespace:`plugin-timeline`,label:`Timeline`,category:`data-display`,inputs:[{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],label:`Timeline Variant`,defaultValue:`vertical`},{name:`items`,type:`array`,label:`Timeline Items`,description:`For vertical/horizontal: Array of { time, title, description, variant, icon, content }. For gantt: Array of { label, items: [{ title, startDate, endDate, variant }] }`},{name:`dateFormat`,type:`enum`,enum:[`short`,`long`,`iso`],label:`Date Format`,defaultValue:`short`},{name:`timeScale`,type:`enum`,enum:[`day`,`week`,`month`],label:`Time Scale (Gantt only)`,defaultValue:`month`},{name:`rowLabel`,type:`string`,label:`Row Label (Gantt only)`,defaultValue:`Items`},{name:`minDate`,type:`string`,label:`Min Date (Gantt only)`,description:`Override auto-calculated min date (YYYY-MM-DD)`},{name:`maxDate`,type:`string`,label:`Max Date (Gantt only)`,description:`Override auto-calculated max date (YYYY-MM-DD)`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{variant:`vertical`,dateFormat:`short`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`,icon:`🚀`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`,icon:`🎨`},{time:`2024-03-15`,title:`Beta Release`,description:`Released beta version to testers`,variant:`warning`,icon:`⚡`},{time:`2024-04-01`,title:`Launch`,description:`Official product launch`,variant:`success`,icon:`🎉`}]},examples:{vertical:{variant:`vertical`,dateFormat:`long`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`}]},horizontal:{variant:`horizontal`,dateFormat:`short`,items:[{time:`2024-01-01`,title:`Q1`,description:`First quarter`,variant:`default`},{time:`2024-04-01`,title:`Q2`,description:`Second quarter`,variant:`info`},{time:`2024-07-01`,title:`Q3`,description:`Third quarter`,variant:`warning`},{time:`2024-10-01`,title:`Q4`,description:`Fourth quarter`,variant:`success`}]},gantt:{variant:`gantt`,dateFormat:`short`,timeScale:`month`,rowLabel:`Projects`,items:[{label:`Backend Development`,items:[{title:`API Design`,startDate:`2024-01-01`,endDate:`2024-01-31`,variant:`success`},{title:`Implementation`,startDate:`2024-02-01`,endDate:`2024-03-31`,variant:`info`}]},{label:`Frontend Development`,items:[{title:`UI Design`,startDate:`2024-01-15`,endDate:`2024-02-15`,variant:`warning`},{title:`Component Dev`,startDate:`2024-02-15`,endDate:`2024-04-15`,variant:`default`}]},{label:`Testing`,items:[{title:`QA Phase`,startDate:`2024-03-01`,endDate:`2024-04-30`,variant:`danger`}]}]}}});var k={fieldOptionLabel:(e,t,n,r)=>r,translateOptions:(e,t,n)=>n,fieldLabel:(e,t,n)=>n};function A(){return(0,o.useObjectLabel)()??k}var j=c.z.object({title:c.z.string().optional(),date:c.z.string().optional(),description:c.z.string().optional(),variant:c.z.string().optional()}),M=c.z.object({mapping:j.optional(),objectName:c.z.string().optional(),titleField:c.z.string().optional(),dateField:c.z.string().optional(),startDateField:c.z.string().optional(),endDateField:c.z.string().optional(),descriptionField:c.z.string().optional(),groupByField:c.z.string().optional(),colorField:c.z.string().optional(),scale:c.z.enum([`hour`,`day`,`week`,`month`,`quarter`,`year`]).optional()}),N=({schema:e,dataSource:a,className:c,onRowClick:l,onItemClick:u,...d})=>{let[f,p]=(0,t.useState)([]),[m,h]=(0,t.useState)(()=>{let t=Array.isArray(e.items)&&e.items.length>0,n=Array.isArray(d.data)&&d.data.length>0;return!t&&!n&&!!e.objectName}),[g,_]=(0,t.useState)(null),[v,b]=(0,t.useState)(0),[x,S]=(0,t.useState)(null),C=e.timeline;(0,t.useEffect)(()=>{let t=M.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let w=(0,o.useDataScope)(e.bind);(0,t.useEffect)(()=>{let t=!0;return(async()=>{if(!(!a||typeof a.getObjectSchema!=`function`||!e.objectName))try{let n=await a.getObjectSchema(e.objectName);t&&S(n)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{t=!1}},[e.objectName,a]);let T=JSON.stringify(e.filter??null),E=JSON.stringify(e.sort??null);(0,t.useEffect)(()=>{e.objectName&&!w&&!e.items&&!d.data?(async()=>{if(!a||typeof a.find!=`function`||!e.objectName){h(!1);return}h(!0);try{let t=(0,i.buildExpandFields)(x?.fields),n=await a.find(e.objectName,{$filter:e.filter,$orderby:(0,i.convertSortToQueryParams)(e.sort),$top:e.limit??100,...t.length>0?{$expand:t}:{}}),r=(0,i.extractRecords)(n);p(r)}catch(e){console.error(e),_(e)}finally{h(!1)}})():h(!1)},[e.objectName,a,w,e.items,d.data,v,x,T,E,e.limit]);let D=d.data||w||f,{t:k}=y(),{fieldOptionLabel:j}=A(),N=C?.titleField??e.mapping?.title??e.titleField??`name`,P=C?.startDateField??C?.dateField??e.mapping?.date??e.startDateField??e.dateField??`date`,F=C?.endDateField??e.endDateField??P,I=e.mapping?.description??e.descriptionField??`description`,L=e.mapping?.variant??`variant`,R=C?.groupByField??e.groupByField,z=C?.colorField??e.colorField,B=(0,t.useMemo)(()=>{if(e.items)return e.items;if(!D||!Array.isArray(D))return[];let t=x?.fields??{},n=e.objectName||``,r=e=>{if(!e||!t[e]?.options)return{};let n={};for(let r of t[e].options)r&&r.value!=null&&(n[String(r.value)]=r);return n},i=r(z),a=Array.isArray(C?.metaFields)?C.metaFields.filter(e=>typeof e==`string`&&e):[`status`,`priority`].filter(e=>t[e]),o={};for(let e of a)o[e]=r(e);let s=e=>{if(e==null||e===``)return;let t=i[String(e)];if(t?.color)return String(t.color);let n=String(e);if(/^#([0-9a-f]{3}){1,2}$/i.test(n)||n.startsWith(`rgb`)||n.startsWith(`hsl`))return n},c=(e,t,r)=>{if(t==null||t===``)return null;let i=r[String(t)];return{label:i?.label?j(n,e,String(t),i.label):String(t),color:i?.color}},l=D.map(e=>{let t=e[P],r=e[F],i=z?e[z]:void 0,l=R?e[R]:void 0,u=[];if(n)for(let t of a){let n=c(t,e[t],o[t]||{});n&&u.push({key:t,label:n.label,color:n.color})}return{title:e[N],time:t,startDate:t,endDate:r,description:e[I],variant:e[L]||`default`,color:s(i),group:l,meta:u,_data:e}});l.sort((e,t)=>(e.startDate?new Date(e.startDate).getTime():1/0)-(t.startDate?new Date(t.startDate).getTime():1/0));let u=new Date,d=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),f=d(u),p=864e5,m=f-(u.getDay()+6)%7*p+7*p,h=m+7*p,g=e=>{if(!e)return k(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?k(`timeline.bucket.noDate`):t<f?k(`timeline.bucket.overdue`):t===f?k(`timeline.bucket.today`):t===f+p?k(`timeline.bucket.tomorrow`):k(t<m?`timeline.bucket.thisWeek`:t<h?`timeline.bucket.nextWeek`:`timeline.bucket.later`)};if(R&&!l.every(e=>e.group==null||e.group===``)){let e=r(R);return l.map(t=>{let n=c(R,t.group,e);return{...t,group:n?n.label:t.group!=null&&t.group!==``?String(t.group):k(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,D,x,e.objectName,N,P,F,I,L,z,R,k,j]),V=(0,t.useCallback)(async()=>{b(e=>e+1)},[]),{ref:H,isRefreshing:U,pullDistance:W}=(0,s.usePullToRefresh)({onRefresh:V,enabled:!!e.objectName&&!!a}),G=(0,o.useNavigationOverlay)({navigation:e.navigation,objectName:e.objectName,onRowClick:l??u}),K=C?.scale??e.scale,q={...e,items:B||[],className:c||e.className,...K?{timeScale:K}:{},onItemClick:e=>{let t=e._data||e;G.handleClick(t),u?.(t)}};return g?(0,r.jsxs)(`div`,{className:`p-4 text-destructive`,"data-testid":`timeline-error`,role:`alert`,children:[`Error loading timeline: `,g.message]}):m&&(!B||B.length===0)?(0,r.jsxs)(`div`,{className:`flex flex-col h-full min-h-[200px] p-4 gap-3`,"data-testid":`timeline-loading`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,r.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,r.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,r.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,r.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,r.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,r.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,r.jsxs)(`div`,{ref:H,className:`relative overflow-auto h-full min-w-0`,children:[W>0&&(0,r.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:W},children:U?`Refreshing…`:`Pull to refresh`}),(0,r.jsx)(O,{schema:q}),G.isOverlay&&(0,r.jsx)(n.NavigationOverlay,{...G,title:`Timeline Item`,children:e=>(0,r.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,r.jsxs)(`div`,{className:`flex flex-col`,children:[(0,r.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,r.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},P=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`ol`,{ref:i,className:(0,n.cn)(`relative ml-3 border-l border-gray-200`,e),...t}));P.displayName=`Timeline`;var F=(0,n.cva)(`ml-6`,{variants:{density:{default:`mb-10`,compact:`mb-3`,comfortable:`mb-6`}},defaultVariants:{density:`default`}}),I=t.forwardRef(({className:e,density:t,...i},a)=>(0,r.jsx)(`li`,{ref:a,className:(0,n.cn)(F({density:t}),e),...i}));I.displayName=`TimelineItem`;var L=(0,n.cva)(`absolute -left-3 w-6 h-6 rounded-full border-2 flex items-center justify-center`,{variants:{variant:{default:`bg-blue-200 border-blue-400`,success:`bg-emerald-200 border-emerald-500`,warning:`bg-amber-200 border-amber-500`,danger:`bg-red-200 border-red-500`,info:`bg-purple-200 border-purple-500`,todo:`bg-slate-200 border-slate-400`,"in-progress":`bg-blue-200 border-blue-500`,done:`bg-emerald-200 border-emerald-500`}},defaultVariants:{variant:`default`}}),R=t.forwardRef(({className:e,variant:t=`default`,...i},a)=>(0,r.jsx)(`div`,{ref:a,className:(0,n.cn)(L({variant:t}),e),...i}));R.displayName=`TimelineMarker`;var z=t.forwardRef(({className:e,...t},n)=>(0,r.jsx)(`div`,{ref:n,className:e,...t}));z.displayName=`TimelineContent`;var B=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`h3`,{ref:i,className:(0,n.cn)(`font-semibold text-lg mb-1`,e),...t}));B.displayName=`TimelineTitle`;var V=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`time`,{ref:i,className:(0,n.cn)(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));V.displayName=`TimelineTime`;var H=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`p`,{ref:i,className:(0,n.cn)(`text-base text-gray-700`,e),...t}));H.displayName=`TimelineDescription`;var U=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`relative flex overflow-x-auto py-8`,e),...t}));U.displayName=`TimelineHorizontal`;var W=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`shrink-0 w-64 relative`,e),...t}));W.displayName=`TimelineHorizontalItem`;var G=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`relative w-full border rounded-lg overflow-hidden`,e),...t}));G.displayName=`TimelineGantt`;var K=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`flex border-b bg-gray-50`,e),...t}));K.displayName=`TimelineGanttHeader`;var q=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`w-48 border-r bg-white`,e),...t}));q.displayName=`TimelineGanttRowLabels`;var J=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`flex-1 overflow-x-auto`,e),...t}));J.displayName=`TimelineGanttGrid`;var Y=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`flex items-center border-b min-h-12`,e),...t}));Y.displayName=`TimelineGanttRow`;var X=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`px-4 py-2 font-medium text-sm truncate`,e),...t}));X.displayName=`TimelineGanttLabel`;var Z=t.forwardRef(({className:e,start:t=0,width:i=100,variant:a=`default`,...o},s)=>(0,r.jsx)(`div`,{ref:s,className:(0,n.cn)(`absolute h-8 rounded-md transition-colors cursor-pointer`,{default:`bg-blue-500 hover:bg-blue-600`,success:`bg-green-500 hover:bg-green-600`,warning:`bg-yellow-500 hover:bg-yellow-600`,danger:`bg-red-500 hover:bg-red-600`,info:`bg-purple-500 hover:bg-purple-600`}[a],e),style:{left:`${t}%`,width:`${i}%`},...o}));Z.displayName=`TimelineGanttBar`;var Q=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`px-2 py-1 text-white text-xs font-medium truncate`,e),...t}));Q.displayName=`TimelineGanttBarContent`;var ee={filter:!0,sort:!0,limit:`limit`},$=({schema:e,...t})=>{let{dataSource:n}=(0,o.useSchemaContext)()||{};return(0,r.jsx)(o.ElementDataSourceGate,{schema:e,mapping:ee,dataSource:n,testId:`object-timeline`,errorTitle:`This timeline’s data source could not be resolved`,children:e=>(0,r.jsx)(N,{schema:e,dataSource:n,...t})})};i.ComponentRegistry.register(`object-timeline`,$,{namespace:`plugin-timeline`,label:`Object Timeline`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]}),i.ComponentRegistry.register(`timeline`,$,{namespace:`view`,label:`Timeline View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]}),e.ObjectTimeline=N,e.ObjectTimelineRenderer=$,e.TIMELINE_SCALES=b,e.Timeline=P,e.TimelineContent=z,e.TimelineDescription=H,e.TimelineGantt=G,e.TimelineGanttBar=Z,e.TimelineGanttBarContent=Q,e.TimelineGanttGrid=J,e.TimelineGanttHeader=K,e.TimelineGanttLabel=X,e.TimelineGanttRow=Y,e.TimelineGanttRowLabels=q,e.TimelineHorizontal=U,e.TimelineHorizontalItem=W,e.TimelineItem=I,e.TimelineMarker=R,e.TimelineRenderer=O,e.TimelineTime=V,e.TimelineTitle=B,e.generateTimeScaleHeaders=S,e.resolveTimelineScale=x,e.timelineItemVariants=F,e.timelineMarkerVariants=L});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/components"),require("react/jsx-runtime"),require("@object-ui/core"),require("@object-ui/i18n"),require("@object-ui/react"),require("@object-ui/mobile"),require("zod")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/components`,`react/jsx-runtime`,`@object-ui/core`,`@object-ui/i18n`,`@object-ui/react`,`@object-ui/mobile`,`zod`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginTimeline={},e.React,e.ObjectUIComponents,e.react_jsx_runtime,e.ObjectUICore,e._object_ui_i18n,e.ObjectUIReact,e.ObjectUIMobile,e.zod))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule||!m.call(e,`default`)?u(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var g={"timeline.bucket.overdue":`Overdue`,"timeline.bucket.today":`Today`,"timeline.bucket.tomorrow":`Tomorrow`,"timeline.bucket.thisWeek":`This week`,"timeline.bucket.nextWeek":`Next week`,"timeline.bucket.later":`Later`,"timeline.bucket.noDate":`No date`,"timeline.bucket.unassigned":`Unassigned`,"timeline.relative.today":`Today`,"timeline.relative.tomorrow":`Tomorrow`,"timeline.relative.yesterday":`Yesterday`,"timeline.relative.inDays":`In {{n}} days`,"timeline.relative.daysAgo":`{{n}} days ago`,"timeline.scale.week":`Week {{n}}`,"timeline.scale.quarter":`Q{{quarter}} {{year}}`,"timeline.gantt.rowLabel":`Items`},_=`timeline.bucket.today`,v=(e,t)=>Object.entries(t??{}).reduce((e,[t,n])=>e.split(`{{${t}}}`).join(String(n)),g[e]||e),y=(0,a.createSafeTranslation)(g,_),b=new Set([`hour`,`day`,`week`,`month`,`quarter`,`year`]);function x(e){let t=e.scale??e.timeScale;return typeof t==`string`&&b.has(t)?t:`month`}function S(e,t,n,r=`en`,i=v){let a=[],o=new Date(t),s=new Date(n);if(Number.isNaN(o.getTime())||Number.isNaN(s.getTime())||o>s)return a;let c=new Date(o);switch(e){case`hour`:for(;c<=s;)a.push(c.toLocaleString(r,{month:`short`,day:`numeric`,hour:`numeric`})),c.setHours(c.getHours()+1);break;case`day`:for(;c<=s;)a.push(c.toLocaleDateString(r,{month:`short`,day:`numeric`})),c.setDate(c.getDate()+1);break;case`week`:{let e=1;for(;c<=s;)a.push(i(`timeline.scale.week`,{n:e++})),c.setDate(c.getDate()+7);break}case`quarter`:for(c.setMonth(Math.floor(c.getMonth()/3)*3,1);c<=s;)a.push(i(`timeline.scale.quarter`,{quarter:Math.floor(c.getMonth()/3)+1,year:c.getFullYear()})),c.setMonth(c.getMonth()+3);break;case`year`:for(c.setMonth(0,1);c<=s;)a.push(String(c.getFullYear())),c.setFullYear(c.getFullYear()+1);break;default:for(;c<=s;)a.push(c.toLocaleDateString(r,{month:`short`,year:`numeric`})),c.setMonth(c.getMonth()+1)}return a}function C(e){let t=e.flatMap(e=>(e.items||[]).flatMap(e=>[e.startDate,e.endDate])),n=Math.min(...t.map(e=>new Date(e).getTime())),r=Math.max(...t.map(e=>new Date(e).getTime()));return{minDate:new Date(n).toISOString().split(`T`)[0],maxDate:new Date(r).toISOString().split(`T`)[0]}}function w(e,t,n,r){let i=new Date(e).getTime(),a=new Date(t).getTime(),o=new Date(n).getTime(),s=new Date(r).getTime()-o,c=i-o,l=a-i;return{start:c/s*100,width:l/s*100}}function T(e,t,n){let r=new Date(e);return t===`short`?r.toLocaleDateString(n):t===`long`?r.toLocaleDateString(n,{year:`numeric`,month:`long`,day:`numeric`}):r.toISOString().split(`T`)[0]}function E({label:e,color:t}){let i=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,r.jsx)(`span`,{className:(0,n.cn)(`inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-medium`,!t&&`bg-muted text-muted-foreground border-transparent`),style:i,children:e})}function D(e){let t=[];for(let n of e){let e=n.group==null?``:String(n.group),r=t[t.length-1];r&&r.key===e?r.items.push(n):t.push({key:e,items:[n]})}return t}var O=({schema:e,className:t,...i})=>{let{variant:o=`vertical`,items:s=[],dateFormat:c=`short`,onItemClick:l}=e,u=(0,a.useDisplayLocale)(),{t:d}=y();if(o===`vertical`){let e=D(s),a=e.some(e=>e.key!==``),o=(e,t)=>{let i=e.color?{backgroundColor:`${e.color}33`,borderColor:e.color}:void 0,a=e.time?T(e.time,c,u):e.startDate?T(e.startDate,c,u):``,o=e.endDate&&e.endDate!==e.startDate?T(e.endDate,c,u):``,s=Array.isArray(e.meta)?e.meta:[];return(0,r.jsxs)(P,{density:`compact`,className:(0,n.cn)(e.className,l&&`cursor-pointer`),onClick:()=>l?.(e),children:[(0,r.jsx)(I,{variant:e.color?`default`:e.variant||`default`,style:i,children:e.icon&&(0,r.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,r.jsxs)(L,{children:[(a||o)&&(0,r.jsxs)(z,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[a,o&&(0,r.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,o]})]}),e.title&&(0,r.jsx)(R,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,r.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,r.jsx)(E,{label:e.label,color:e.color},e.key))}),e.description&&(0,r.jsx)(B,{className:`text-sm text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&(0,n.renderChildren)(e.content)]})]},t)};return a?(0,r.jsx)(`div`,{className:(0,n.cn)(`px-4 sm:px-6 py-2`,t),...i,children:e.map((e,t)=>(0,r.jsxs)(`section`,{className:`mb-4`,children:[(0,r.jsxs)(`header`,{className:`sticky top-0 z-10 -mx-4 sm:-mx-6 px-4 sm:px-6 py-1.5 backdrop-blur bg-background/90 text-xs font-semibold uppercase tracking-wide text-muted-foreground border-b`,children:[(0,r.jsx)(`span`,{children:e.key}),(0,r.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,r.jsx)(M,{className:`mt-3`,children:e.items.map((e,n)=>o(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,r.jsx)(M,{className:t,...i,children:s.map((e,t)=>o(e,t))})}if(o===`horizontal`)return(0,r.jsx)(V,{className:(0,n.cn)(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...i,children:s.map((e,t)=>(0,r.jsxs)(H,{className:(0,n.cn)(e.className,l&&`cursor-pointer`),onClick:()=>l?.(e),children:[(0,r.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,r.jsx)(I,{variant:e.variant||`default`,children:e.icon&&(0,r.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,r.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,r.jsx)(z,{dateTime:e.time,children:T(e.time,c,u)}),e.title&&(0,r.jsx)(R,{children:e.title}),e.description&&(0,r.jsx)(B,{className:`text-center line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&(0,n.renderChildren)(e.content)]})]}),t<s.length-1&&(0,r.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(o===`gantt`){let a=C(s),o=e.minDate||a.minDate,f=e.maxDate||a.maxDate,p=S(x(e),o,f,u,d);return(0,r.jsxs)(U,{className:(0,n.cn)(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...i,children:[(0,r.jsxs)(W,{children:[(0,r.jsx)(G,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,r.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||d(`timeline.gantt.rowLabel`)})}),(0,r.jsx)(K,{children:(0,r.jsx)(`div`,{className:`flex h-full`,children:p.map((e,t)=>(0,r.jsx)(`div`,{className:`flex-1 px-1 sm:px-2 py-2 sm:py-3 border-r text-xs font-medium text-center`,children:e},t))})})]}),(0,r.jsx)(`div`,{children:(0,r.jsxs)(`div`,{className:`flex`,children:[(0,r.jsx)(G,{children:s.map((e,t)=>(0,r.jsx)(q,{children:(0,r.jsx)(J,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,r.jsx)(K,{className:`relative`,children:s.map((e,t)=>(0,r.jsx)(q,{className:`relative`,children:(e.items||[]).map((n,i)=>{let a=w(n.startDate,n.endDate,o,f);return(0,r.jsx)(Y,{start:a.start,width:a.width,variant:n.variant||`default`,onClick:()=>l?.(n,e,t,i),title:`${n.title||``}\n${T(n.startDate,c,u)} - ${T(n.endDate,c,u)}`,children:(0,r.jsx)(X,{children:n.title})},i)})},t))})]})})]})}return null};i.ComponentRegistry.register(`timeline`,O,{namespace:`plugin-timeline`,label:`Timeline`,category:`data-display`,inputs:[{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],label:`Timeline Variant`,defaultValue:`vertical`},{name:`items`,type:`array`,label:`Timeline Items`,description:`For vertical/horizontal: Array of { time, title, description, variant, icon, content }. For gantt: Array of { label, items: [{ title, startDate, endDate, variant }] }`},{name:`dateFormat`,type:`enum`,enum:[`short`,`long`,`iso`],label:`Date Format`,defaultValue:`short`},{name:`timeScale`,type:`enum`,enum:[`day`,`week`,`month`],label:`Time Scale (Gantt only)`,defaultValue:`month`},{name:`rowLabel`,type:`string`,label:`Row Label (Gantt only)`,defaultValue:`Items`},{name:`minDate`,type:`string`,label:`Min Date (Gantt only)`,description:`Override auto-calculated min date (YYYY-MM-DD)`},{name:`maxDate`,type:`string`,label:`Max Date (Gantt only)`,description:`Override auto-calculated max date (YYYY-MM-DD)`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{variant:`vertical`,dateFormat:`short`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`,icon:`🚀`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`,icon:`🎨`},{time:`2024-03-15`,title:`Beta Release`,description:`Released beta version to testers`,variant:`warning`,icon:`⚡`},{time:`2024-04-01`,title:`Launch`,description:`Official product launch`,variant:`success`,icon:`🎉`}]},examples:{vertical:{variant:`vertical`,dateFormat:`long`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`}]},horizontal:{variant:`horizontal`,dateFormat:`short`,items:[{time:`2024-01-01`,title:`Q1`,description:`First quarter`,variant:`default`},{time:`2024-04-01`,title:`Q2`,description:`Second quarter`,variant:`info`},{time:`2024-07-01`,title:`Q3`,description:`Third quarter`,variant:`warning`},{time:`2024-10-01`,title:`Q4`,description:`Fourth quarter`,variant:`success`}]},gantt:{variant:`gantt`,dateFormat:`short`,timeScale:`month`,rowLabel:`Projects`,items:[{label:`Backend Development`,items:[{title:`API Design`,startDate:`2024-01-01`,endDate:`2024-01-31`,variant:`success`},{title:`Implementation`,startDate:`2024-02-01`,endDate:`2024-03-31`,variant:`info`}]},{label:`Frontend Development`,items:[{title:`UI Design`,startDate:`2024-01-15`,endDate:`2024-02-15`,variant:`warning`},{title:`Component Dev`,startDate:`2024-02-15`,endDate:`2024-04-15`,variant:`default`}]},{label:`Testing`,items:[{title:`QA Phase`,startDate:`2024-03-01`,endDate:`2024-04-30`,variant:`danger`}]}]}}});var k=c.z.object({title:c.z.string().optional(),date:c.z.string().optional(),description:c.z.string().optional(),variant:c.z.string().optional()}),A=c.z.object({mapping:k.optional(),objectName:c.z.string().optional(),titleField:c.z.string().optional(),dateField:c.z.string().optional(),startDateField:c.z.string().optional(),endDateField:c.z.string().optional(),descriptionField:c.z.string().optional(),groupByField:c.z.string().optional(),colorField:c.z.string().optional(),scale:c.z.enum([`hour`,`day`,`week`,`month`,`quarter`,`year`]).optional()}),j=({schema:e,dataSource:a,className:c,onRowClick:l,onItemClick:u,...d})=>{let[f,p]=(0,t.useState)([]),[m,h]=(0,t.useState)(()=>{let t=Array.isArray(e.items)&&e.items.length>0,n=Array.isArray(d.data)&&d.data.length>0;return!t&&!n&&!!e.objectName}),[g,_]=(0,t.useState)(null),[v,b]=(0,t.useState)(0),[x,S]=(0,t.useState)(null),C=e.timeline;(0,t.useEffect)(()=>{let t=A.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let w=(0,o.useDataScope)(e.bind);(0,t.useEffect)(()=>{let t=!0;return(async()=>{if(!(!a||typeof a.getObjectSchema!=`function`||!e.objectName))try{let n=await a.getObjectSchema(e.objectName);t&&S(n)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{t=!1}},[e.objectName,a]);let T=JSON.stringify(e.filter??null),E=JSON.stringify(e.sort??null);(0,t.useEffect)(()=>{e.objectName&&!w&&!e.items&&!d.data?(async()=>{if(!a||typeof a.find!=`function`||!e.objectName){h(!1);return}h(!0);try{let t=(0,i.buildExpandFields)(x?.fields),n=await a.find(e.objectName,{$filter:e.filter,$orderby:(0,i.convertSortToQueryParams)(e.sort),$top:e.limit??100,...t.length>0?{$expand:t}:{}}),r=(0,i.extractRecords)(n);p(r)}catch(e){console.error(e),_(e)}finally{h(!1)}})():h(!1)},[e.objectName,a,w,e.items,d.data,v,x,T,E,e.limit]);let D=d.data||w||f,{t:k}=y(),{fieldOptionLabel:j}=(0,o.useSafeFieldLabel)(),M=C?.titleField??e.mapping?.title??e.titleField??`name`,N=C?.startDateField??C?.dateField??e.mapping?.date??e.startDateField??e.dateField??`date`,P=C?.endDateField??e.endDateField??N,F=e.mapping?.description??e.descriptionField??`description`,I=e.mapping?.variant??`variant`,L=C?.groupByField??e.groupByField,R=C?.colorField??e.colorField,z=(0,t.useMemo)(()=>{if(e.items)return e.items;if(!D||!Array.isArray(D))return[];let t=x?.fields??{},n=e.objectName||``,r=e=>{if(!e||!t[e]?.options)return{};let n={};for(let r of t[e].options)r&&r.value!=null&&(n[String(r.value)]=r);return n},i=r(R),a=Array.isArray(C?.metaFields)?C.metaFields.filter(e=>typeof e==`string`&&e):[`status`,`priority`].filter(e=>t[e]),o={};for(let e of a)o[e]=r(e);let s=e=>{if(e==null||e===``)return;let t=i[String(e)];if(t?.color)return String(t.color);let n=String(e);if(/^#([0-9a-f]{3}){1,2}$/i.test(n)||n.startsWith(`rgb`)||n.startsWith(`hsl`))return n},c=(e,t,r)=>{if(t==null||t===``)return null;let i=r[String(t)];return{label:i?.label?j(n,e,String(t),i.label):String(t),color:i?.color}},l=D.map(e=>{let t=e[N],r=e[P],i=R?e[R]:void 0,l=L?e[L]:void 0,u=[];if(n)for(let t of a){let n=c(t,e[t],o[t]||{});n&&u.push({key:t,label:n.label,color:n.color})}return{title:e[M],time:t,startDate:t,endDate:r,description:e[F],variant:e[I]||`default`,color:s(i),group:l,meta:u,_data:e}});l.sort((e,t)=>(e.startDate?new Date(e.startDate).getTime():1/0)-(t.startDate?new Date(t.startDate).getTime():1/0));let u=new Date,d=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),f=d(u),p=864e5,m=f-(u.getDay()+6)%7*p+7*p,h=m+7*p,g=e=>{if(!e)return k(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?k(`timeline.bucket.noDate`):t<f?k(`timeline.bucket.overdue`):t===f?k(`timeline.bucket.today`):t===f+p?k(`timeline.bucket.tomorrow`):k(t<m?`timeline.bucket.thisWeek`:t<h?`timeline.bucket.nextWeek`:`timeline.bucket.later`)};if(L&&!l.every(e=>e.group==null||e.group===``)){let e=r(L);return l.map(t=>{let n=c(L,t.group,e);return{...t,group:n?n.label:t.group!=null&&t.group!==``?String(t.group):k(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,D,x,e.objectName,M,N,P,F,I,R,L,k,j]),B=(0,t.useCallback)(async()=>{b(e=>e+1)},[]),{ref:V,isRefreshing:H,pullDistance:U}=(0,s.usePullToRefresh)({onRefresh:B,enabled:!!e.objectName&&!!a}),W=(0,o.useNavigationOverlay)({navigation:e.navigation,objectName:e.objectName,onRowClick:l??u}),G=C?.scale??e.scale,K={...e,items:z||[],className:c||e.className,...G?{timeScale:G}:{},onItemClick:e=>{let t=e._data||e;W.handleClick(t),u?.(t)}};return g?(0,r.jsxs)(`div`,{className:`p-4 text-destructive`,"data-testid":`timeline-error`,role:`alert`,children:[`Error loading timeline: `,g.message]}):m&&(!z||z.length===0)?(0,r.jsxs)(`div`,{className:`flex flex-col h-full min-h-[200px] p-4 gap-3`,"data-testid":`timeline-loading`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,r.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,r.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,r.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,r.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,r.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,r.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,r.jsxs)(`div`,{ref:V,className:`relative overflow-auto h-full min-w-0`,children:[U>0&&(0,r.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:U},children:H?`Refreshing…`:`Pull to refresh`}),(0,r.jsx)(O,{schema:K}),W.isOverlay&&(0,r.jsx)(n.NavigationOverlay,{...W,title:`Timeline Item`,children:e=>(0,r.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,r.jsxs)(`div`,{className:`flex flex-col`,children:[(0,r.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,r.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},M=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`ol`,{ref:i,className:(0,n.cn)(`relative ml-3 border-l border-gray-200`,e),...t}));M.displayName=`Timeline`;var N=(0,n.cva)(`ml-6`,{variants:{density:{default:`mb-10`,compact:`mb-3`,comfortable:`mb-6`}},defaultVariants:{density:`default`}}),P=t.forwardRef(({className:e,density:t,...i},a)=>(0,r.jsx)(`li`,{ref:a,className:(0,n.cn)(N({density:t}),e),...i}));P.displayName=`TimelineItem`;var F=(0,n.cva)(`absolute -left-3 w-6 h-6 rounded-full border-2 flex items-center justify-center`,{variants:{variant:{default:`bg-blue-200 border-blue-400`,success:`bg-emerald-200 border-emerald-500`,warning:`bg-amber-200 border-amber-500`,danger:`bg-red-200 border-red-500`,info:`bg-purple-200 border-purple-500`,todo:`bg-slate-200 border-slate-400`,"in-progress":`bg-blue-200 border-blue-500`,done:`bg-emerald-200 border-emerald-500`}},defaultVariants:{variant:`default`}}),I=t.forwardRef(({className:e,variant:t=`default`,...i},a)=>(0,r.jsx)(`div`,{ref:a,className:(0,n.cn)(F({variant:t}),e),...i}));I.displayName=`TimelineMarker`;var L=t.forwardRef(({className:e,...t},n)=>(0,r.jsx)(`div`,{ref:n,className:e,...t}));L.displayName=`TimelineContent`;var R=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`h3`,{ref:i,className:(0,n.cn)(`font-semibold text-lg mb-1`,e),...t}));R.displayName=`TimelineTitle`;var z=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`time`,{ref:i,className:(0,n.cn)(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));z.displayName=`TimelineTime`;var B=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`p`,{ref:i,className:(0,n.cn)(`text-base text-gray-700`,e),...t}));B.displayName=`TimelineDescription`;var V=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`relative flex overflow-x-auto py-8`,e),...t}));V.displayName=`TimelineHorizontal`;var H=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`shrink-0 w-64 relative`,e),...t}));H.displayName=`TimelineHorizontalItem`;var U=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`relative w-full border rounded-lg overflow-hidden`,e),...t}));U.displayName=`TimelineGantt`;var W=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`flex border-b bg-gray-50`,e),...t}));W.displayName=`TimelineGanttHeader`;var G=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`w-48 border-r bg-white`,e),...t}));G.displayName=`TimelineGanttRowLabels`;var K=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`flex-1 overflow-x-auto`,e),...t}));K.displayName=`TimelineGanttGrid`;var q=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`flex items-center border-b min-h-12`,e),...t}));q.displayName=`TimelineGanttRow`;var J=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`px-4 py-2 font-medium text-sm truncate`,e),...t}));J.displayName=`TimelineGanttLabel`;var Y=t.forwardRef(({className:e,start:t=0,width:i=100,variant:a=`default`,...o},s)=>(0,r.jsx)(`div`,{ref:s,className:(0,n.cn)(`absolute h-8 rounded-md transition-colors cursor-pointer`,{default:`bg-blue-500 hover:bg-blue-600`,success:`bg-green-500 hover:bg-green-600`,warning:`bg-yellow-500 hover:bg-yellow-600`,danger:`bg-red-500 hover:bg-red-600`,info:`bg-purple-500 hover:bg-purple-600`}[a],e),style:{left:`${t}%`,width:`${i}%`},...o}));Y.displayName=`TimelineGanttBar`;var X=t.forwardRef(({className:e,...t},i)=>(0,r.jsx)(`div`,{ref:i,className:(0,n.cn)(`px-2 py-1 text-white text-xs font-medium truncate`,e),...t}));X.displayName=`TimelineGanttBarContent`;var Z={filter:!0,sort:!0,limit:`limit`},Q=({schema:e,...t})=>{let{dataSource:n}=(0,o.useSchemaContext)()||{};return(0,r.jsx)(o.ElementDataSourceGate,{schema:e,mapping:Z,dataSource:n,testId:`object-timeline`,errorTitle:`This timeline’s data source could not be resolved`,children:e=>(0,r.jsx)(j,{schema:e,dataSource:n,...t})})};i.ComponentRegistry.register(`object-timeline`,Q,{namespace:`plugin-timeline`,label:`Object Timeline`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]}),i.ComponentRegistry.register(`timeline`,Q,{namespace:`view`,label:`Timeline View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]}),e.ObjectTimeline=j,e.ObjectTimelineRenderer=Q,e.TIMELINE_SCALES=b,e.Timeline=M,e.TimelineContent=L,e.TimelineDescription=B,e.TimelineGantt=U,e.TimelineGanttBar=Y,e.TimelineGanttBarContent=X,e.TimelineGanttGrid=K,e.TimelineGanttHeader=W,e.TimelineGanttLabel=J,e.TimelineGanttRow=q,e.TimelineGanttRowLabels=G,e.TimelineHorizontal=V,e.TimelineHorizontalItem=H,e.TimelineItem=P,e.TimelineMarker=I,e.TimelineRenderer=O,e.TimelineTime=z,e.TimelineTitle=R,e.generateTimeScaleHeaders=S,e.resolveTimelineScale=x,e.timelineItemVariants=N,e.timelineMarkerVariants=F});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-timeline",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Timeline component plugin for Object UI",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@objectstack/spec": "^17.0.0
|
|
27
|
+
"@objectstack/spec": "^17.0.0",
|
|
28
28
|
"class-variance-authority": "^0.7.1",
|
|
29
29
|
"zod": "^4.4.3",
|
|
30
|
-
"@object-ui/components": "17.
|
|
31
|
-
"@object-ui/core": "17.
|
|
32
|
-
"@object-ui/i18n": "17.
|
|
33
|
-
"@object-ui/mobile": "17.
|
|
34
|
-
"@object-ui/react": "17.
|
|
35
|
-
"@object-ui/types": "17.
|
|
30
|
+
"@object-ui/components": "17.6.0",
|
|
31
|
+
"@object-ui/core": "17.6.0",
|
|
32
|
+
"@object-ui/i18n": "17.6.0",
|
|
33
|
+
"@object-ui/mobile": "17.6.0",
|
|
34
|
+
"@object-ui/react": "17.6.0",
|
|
35
|
+
"@object-ui/types": "17.6.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typescript": "^6.0.3",
|
|
46
46
|
"vite": "^8.2.1",
|
|
47
47
|
"vite-plugin-dts": "^5.0.3",
|
|
48
|
-
"@object-ui/data-objectstack": "17.
|
|
48
|
+
"@object-ui/data-objectstack": "17.6.0"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"objectui",
|