@allhailai/tempusmachina-core 1.0.0 → 1.1.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/dist/index.cjs +52 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +52 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1263,17 +1263,62 @@ var timeGridPlugin = {
|
|
|
1263
1263
|
};
|
|
1264
1264
|
|
|
1265
1265
|
// src/plugins/timeline.ts
|
|
1266
|
+
function buildResourceGroups(resources) {
|
|
1267
|
+
const parentMap = /* @__PURE__ */ new Map();
|
|
1268
|
+
const parentResources = /* @__PURE__ */ new Map();
|
|
1269
|
+
const ungrouped = [];
|
|
1270
|
+
const childParentIds = new Set(
|
|
1271
|
+
resources.filter((r) => r.parentId && r.parentId !== r.id).map((r) => r.parentId)
|
|
1272
|
+
);
|
|
1273
|
+
for (const resource of resources) {
|
|
1274
|
+
if (childParentIds.has(resource.id)) {
|
|
1275
|
+
parentResources.set(resource.id, resource);
|
|
1276
|
+
if (!parentMap.has(resource.id)) parentMap.set(resource.id, []);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
for (const resource of resources) {
|
|
1280
|
+
if (resource.parentId && resource.parentId !== resource.id && parentMap.has(resource.parentId)) {
|
|
1281
|
+
parentMap.get(resource.parentId).push(resource);
|
|
1282
|
+
} else if (!childParentIds.has(resource.id)) {
|
|
1283
|
+
ungrouped.push(resource);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
const groups = [];
|
|
1287
|
+
for (const [parentId, children] of parentMap) {
|
|
1288
|
+
const parent = parentResources.get(parentId);
|
|
1289
|
+
if (parent && children.length > 0) {
|
|
1290
|
+
groups.push({
|
|
1291
|
+
id: parentId,
|
|
1292
|
+
title: parent.title,
|
|
1293
|
+
subtitle: typeof parent.extendedProps?.subtitle === "string" ? parent.extendedProps.subtitle : void 0,
|
|
1294
|
+
resources: children,
|
|
1295
|
+
extendedProps: parent.extendedProps
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return { groups, ungrouped };
|
|
1300
|
+
}
|
|
1266
1301
|
var timelineLayoutSolver = (events, config, context) => {
|
|
1267
1302
|
const spine = generateDateSpine(config);
|
|
1268
1303
|
const resources = context.getResources();
|
|
1269
|
-
const
|
|
1304
|
+
const buildLanes = (resourceList) => resourceList.map((resource) => {
|
|
1270
1305
|
const resourceEvents = events.filter((e) => e.resourceIds.includes(resource.id));
|
|
1271
|
-
|
|
1272
|
-
return {
|
|
1273
|
-
resource,
|
|
1274
|
-
events: positioned
|
|
1275
|
-
};
|
|
1306
|
+
return { resource, events: solveLayout(resourceEvents, config) };
|
|
1276
1307
|
});
|
|
1308
|
+
const hasGrouping = resources.some((r) => r.parentId);
|
|
1309
|
+
let lanes;
|
|
1310
|
+
let resourceGroups;
|
|
1311
|
+
if (hasGrouping) {
|
|
1312
|
+
const { groups, ungrouped } = buildResourceGroups(resources);
|
|
1313
|
+
resourceGroups = groups;
|
|
1314
|
+
lanes = [];
|
|
1315
|
+
for (const group of groups) {
|
|
1316
|
+
lanes.push(...buildLanes(group.resources));
|
|
1317
|
+
}
|
|
1318
|
+
lanes.push(...buildLanes(ungrouped));
|
|
1319
|
+
} else {
|
|
1320
|
+
lanes = buildLanes(resources);
|
|
1321
|
+
}
|
|
1277
1322
|
const unassignedEvents = events.filter((e) => e.resourceIds.length === 0);
|
|
1278
1323
|
if (unassignedEvents.length > 0) {
|
|
1279
1324
|
lanes.push({
|
|
@@ -1285,6 +1330,7 @@ var timelineLayoutSolver = (events, config, context) => {
|
|
|
1285
1330
|
viewType: "timeline",
|
|
1286
1331
|
dateRange: config.visibleRange,
|
|
1287
1332
|
lanes,
|
|
1333
|
+
resourceGroups,
|
|
1288
1334
|
timeSlots: spine.slots?.[0] ?? [],
|
|
1289
1335
|
nowPosition: getNowPosition(config)
|
|
1290
1336
|
};
|