@glyphjs/components 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +104 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +105 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -271,6 +271,22 @@ function ChartAccessibleTable({
|
|
|
271
271
|
}
|
|
272
272
|
);
|
|
273
273
|
}
|
|
274
|
+
function inferAxisKeys(series, explicitX, explicitY) {
|
|
275
|
+
if (explicitX && explicitY) return { xKey: explicitX, yKey: explicitY };
|
|
276
|
+
const sample = series[0]?.data[0];
|
|
277
|
+
if (!sample) return { xKey: explicitX ?? "x", yKey: explicitY ?? "y" };
|
|
278
|
+
let inferredX;
|
|
279
|
+
let inferredY;
|
|
280
|
+
for (const [key, value] of Object.entries(sample)) {
|
|
281
|
+
if (!inferredX && typeof value === "string") inferredX = key;
|
|
282
|
+
if (!inferredY && typeof value === "number") inferredY = key;
|
|
283
|
+
if (inferredX && inferredY) break;
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
xKey: explicitX ?? inferredX ?? "x",
|
|
287
|
+
yKey: explicitY ?? inferredY ?? "y"
|
|
288
|
+
};
|
|
289
|
+
}
|
|
274
290
|
function computeScales(width, height, type, series, xKey, yKey, margin) {
|
|
275
291
|
const innerWidth = width - margin.left - margin.right;
|
|
276
292
|
const innerHeight = height - margin.top - margin.bottom;
|
|
@@ -411,9 +427,9 @@ function Chart({
|
|
|
411
427
|
const svgRef = react.useRef(null);
|
|
412
428
|
const tooltipRef = react.useRef(null);
|
|
413
429
|
const [width, setWidth] = react.useState(DEFAULT_WIDTH);
|
|
430
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
414
431
|
const { type, series, xAxis, yAxis, legend } = data;
|
|
415
|
-
const xKey = xAxis?.key
|
|
416
|
-
const yKey = yAxis?.key ?? "y";
|
|
432
|
+
const { xKey, yKey } = inferAxisKeys(series, xAxis?.key, yAxis?.key);
|
|
417
433
|
const height = DEFAULT_HEIGHT;
|
|
418
434
|
const isCompact = containerCtx.tier === "compact";
|
|
419
435
|
const margin = isCompact ? {
|
|
@@ -474,6 +490,7 @@ function Chart({
|
|
|
474
490
|
if (legend) {
|
|
475
491
|
renderLegend(sel, series, margin.left, margin.top, isCompact ? "10px" : void 0);
|
|
476
492
|
}
|
|
493
|
+
setIsLoading(false);
|
|
477
494
|
}, [
|
|
478
495
|
scales,
|
|
479
496
|
type,
|
|
@@ -495,6 +512,7 @@ function Chart({
|
|
|
495
512
|
"div",
|
|
496
513
|
{
|
|
497
514
|
ref: containerRef,
|
|
515
|
+
"data-glyph-loading": isLoading || void 0,
|
|
498
516
|
style: {
|
|
499
517
|
position: "relative",
|
|
500
518
|
width: "100%",
|
|
@@ -1356,6 +1374,13 @@ var timelineDefinition = {
|
|
|
1356
1374
|
// src/utils/measureText.ts
|
|
1357
1375
|
var measurementCache = /* @__PURE__ */ new WeakMap();
|
|
1358
1376
|
function measurePlainText(text, style) {
|
|
1377
|
+
if (typeof document === "undefined") {
|
|
1378
|
+
const avgCharWidth = parseInt(style.fontSize) * 0.6;
|
|
1379
|
+
return {
|
|
1380
|
+
width: text.length * avgCharWidth,
|
|
1381
|
+
height: parseInt(style.fontSize) * 1.2
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1359
1384
|
const canvas = document.createElement("canvas");
|
|
1360
1385
|
const ctx = canvas.getContext("2d");
|
|
1361
1386
|
if (!ctx) {
|
|
@@ -1373,6 +1398,10 @@ function measurePlainText(text, style) {
|
|
|
1373
1398
|
return { width, height };
|
|
1374
1399
|
}
|
|
1375
1400
|
function measureHtmlText(content, style) {
|
|
1401
|
+
if (typeof document === "undefined") {
|
|
1402
|
+
const plainText = flattenInlineNodes(content);
|
|
1403
|
+
return measurePlainText(plainText, style);
|
|
1404
|
+
}
|
|
1376
1405
|
const cached = measurementCache.get(content);
|
|
1377
1406
|
if (cached) {
|
|
1378
1407
|
return cached;
|
|
@@ -1401,6 +1430,28 @@ function measureHtmlText(content, style) {
|
|
|
1401
1430
|
measurementCache.set(content, dimensions);
|
|
1402
1431
|
return dimensions;
|
|
1403
1432
|
}
|
|
1433
|
+
function flattenInlineNodes(nodes) {
|
|
1434
|
+
return nodes.map((node) => {
|
|
1435
|
+
switch (node.type) {
|
|
1436
|
+
case "text":
|
|
1437
|
+
return node.value;
|
|
1438
|
+
case "inlineCode":
|
|
1439
|
+
return node.value;
|
|
1440
|
+
case "strong":
|
|
1441
|
+
case "emphasis":
|
|
1442
|
+
case "delete":
|
|
1443
|
+
return flattenInlineNodes(node.children);
|
|
1444
|
+
case "link":
|
|
1445
|
+
return flattenInlineNodes(node.children);
|
|
1446
|
+
case "image":
|
|
1447
|
+
return node.alt ?? "";
|
|
1448
|
+
case "break":
|
|
1449
|
+
return "\n";
|
|
1450
|
+
default:
|
|
1451
|
+
return "";
|
|
1452
|
+
}
|
|
1453
|
+
}).join("");
|
|
1454
|
+
}
|
|
1404
1455
|
function inlineNodesToHtml(nodes) {
|
|
1405
1456
|
return nodes.map((node) => {
|
|
1406
1457
|
switch (node.type) {
|
|
@@ -1426,6 +1477,9 @@ function inlineNodesToHtml(nodes) {
|
|
|
1426
1477
|
}).join("");
|
|
1427
1478
|
}
|
|
1428
1479
|
function escapeHtml(str) {
|
|
1480
|
+
if (typeof document === "undefined") {
|
|
1481
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1482
|
+
}
|
|
1429
1483
|
const div = document.createElement("div");
|
|
1430
1484
|
div.textContent = str;
|
|
1431
1485
|
return div.innerHTML;
|
|
@@ -2014,6 +2068,7 @@ function Graph({
|
|
|
2014
2068
|
const svgRef = react.useRef(null);
|
|
2015
2069
|
const rootRef = react.useRef(null);
|
|
2016
2070
|
const groupIndex = react.useRef(/* @__PURE__ */ new Map());
|
|
2071
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
2017
2072
|
const layoutResult = react.useMemo(() => {
|
|
2018
2073
|
const direction = resolveLayout(data);
|
|
2019
2074
|
if (direction === "force") {
|
|
@@ -2054,9 +2109,10 @@ function Graph({
|
|
|
2054
2109
|
if (rootElement) {
|
|
2055
2110
|
rootRef.current = rootElement;
|
|
2056
2111
|
}
|
|
2112
|
+
setIsLoading(false);
|
|
2057
2113
|
}, [layoutResult, outgoingRefs, onNavigate, zoomBehavior, handleNodeClick]);
|
|
2058
2114
|
const ariaLabel = `${data.type} graph with ${data.nodes.length} nodes and ${data.edges.length} edges`;
|
|
2059
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-graph-container", children: [
|
|
2115
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-graph-container", "data-glyph-loading": isLoading || void 0, children: [
|
|
2060
2116
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
|
|
2061
2117
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2062
2118
|
"svg",
|
|
@@ -3799,7 +3855,7 @@ var DIRECTION_MAP = {
|
|
|
3799
3855
|
"bottom-up": "UP"
|
|
3800
3856
|
};
|
|
3801
3857
|
function buildElkNode(node) {
|
|
3802
|
-
if (node.
|
|
3858
|
+
if (node.children?.length) {
|
|
3803
3859
|
return {
|
|
3804
3860
|
id: node.id,
|
|
3805
3861
|
labels: [{ text: node.label }],
|
|
@@ -3843,7 +3899,7 @@ function collectNodes(elkNode, nodeMap, offsetX, offsetY, nodes, zones, depth, z
|
|
|
3843
3899
|
const absX = offsetX + (elkNode.x ?? 0);
|
|
3844
3900
|
const absY = offsetY + (elkNode.y ?? 0);
|
|
3845
3901
|
const original = nodeMap.get(elkNode.id);
|
|
3846
|
-
if (original?.
|
|
3902
|
+
if (original?.children?.length && elkNode.children?.length) {
|
|
3847
3903
|
zones.push({
|
|
3848
3904
|
id: elkNode.id,
|
|
3849
3905
|
label: original.label,
|
|
@@ -3880,7 +3936,7 @@ function flattenNodeMap(children, map) {
|
|
|
3880
3936
|
function buildAncestorMap(children, ancestors, map) {
|
|
3881
3937
|
for (const node of children) {
|
|
3882
3938
|
map.set(node.id, [...ancestors]);
|
|
3883
|
-
if (node.
|
|
3939
|
+
if (node.children?.length) {
|
|
3884
3940
|
buildAncestorMap(node.children, [...ancestors, node.id], map);
|
|
3885
3941
|
}
|
|
3886
3942
|
}
|
|
@@ -4159,6 +4215,7 @@ function Architecture({
|
|
|
4159
4215
|
{
|
|
4160
4216
|
ref: containerRef,
|
|
4161
4217
|
className: "glyph-architecture-container",
|
|
4218
|
+
"data-glyph-loading": !layout || void 0,
|
|
4162
4219
|
style: { position: "relative" },
|
|
4163
4220
|
children: [
|
|
4164
4221
|
!layout && /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4218,7 +4275,7 @@ function Architecture({
|
|
|
4218
4275
|
function flattenNodes(children, zone) {
|
|
4219
4276
|
const result = [];
|
|
4220
4277
|
for (const child of children) {
|
|
4221
|
-
if (child.
|
|
4278
|
+
if (child.children?.length) {
|
|
4222
4279
|
result.push(...flattenNodes(child.children, child.label));
|
|
4223
4280
|
} else {
|
|
4224
4281
|
result.push({ id: child.id, label: child.label, zone });
|
|
@@ -4229,7 +4286,7 @@ function flattenNodes(children, zone) {
|
|
|
4229
4286
|
function countLeafNodes(children) {
|
|
4230
4287
|
let count = 0;
|
|
4231
4288
|
for (const child of children) {
|
|
4232
|
-
if (child.
|
|
4289
|
+
if (child.children?.length) {
|
|
4233
4290
|
count += countLeafNodes(child.children);
|
|
4234
4291
|
} else {
|
|
4235
4292
|
count++;
|
|
@@ -5550,6 +5607,10 @@ function renderRatingGroup(items, keyPrefix) {
|
|
|
5550
5607
|
);
|
|
5551
5608
|
}) }, keyPrefix);
|
|
5552
5609
|
}
|
|
5610
|
+
function cssEscape(value) {
|
|
5611
|
+
if (typeof CSS !== "undefined" && CSS.escape) return CSS.escape(value);
|
|
5612
|
+
return value.replace(/([^\w-])/g, "\\$1");
|
|
5613
|
+
}
|
|
5553
5614
|
function Infographic({
|
|
5554
5615
|
data,
|
|
5555
5616
|
block,
|
|
@@ -5602,7 +5663,7 @@ function Infographic({
|
|
|
5602
5663
|
borderLeft: "3px solid var(--glyph-infographic-accent, #3b82f6)",
|
|
5603
5664
|
paddingLeft: "var(--glyph-spacing-sm, 0.5rem)"
|
|
5604
5665
|
};
|
|
5605
|
-
const printCss = useGrid ? `@media print { #${
|
|
5666
|
+
const printCss = useGrid ? `@media print { #${cssEscape(baseId)} [data-layout="grid"] { display: grid !important; grid-template-columns: repeat(2, 1fr) !important; gap: 0.5rem !important; } #${cssEscape(baseId)} [data-layout="grid"] > div { break-inside: avoid; } }` : "";
|
|
5606
5667
|
let progressColorOffset = 0;
|
|
5607
5668
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: baseId, role: "region", "aria-label": title ?? "Infographic", style: containerStyle11, children: [
|
|
5608
5669
|
printCss && /* @__PURE__ */ jsxRuntime.jsx("style", { children: printCss }),
|
|
@@ -7408,6 +7469,39 @@ var annotateDefinition = {
|
|
|
7408
7469
|
render: Annotate
|
|
7409
7470
|
};
|
|
7410
7471
|
|
|
7472
|
+
// src/index.ts
|
|
7473
|
+
var allComponentDefinitions = [
|
|
7474
|
+
calloutDefinition,
|
|
7475
|
+
chartDefinition,
|
|
7476
|
+
stepsDefinition,
|
|
7477
|
+
tableDefinition,
|
|
7478
|
+
tabsDefinition,
|
|
7479
|
+
timelineDefinition,
|
|
7480
|
+
graphDefinition,
|
|
7481
|
+
relationDefinition,
|
|
7482
|
+
kpiDefinition,
|
|
7483
|
+
accordionDefinition,
|
|
7484
|
+
comparisonDefinition,
|
|
7485
|
+
codeDiffDefinition,
|
|
7486
|
+
flowchartDefinition,
|
|
7487
|
+
fileTreeDefinition,
|
|
7488
|
+
sequenceDefinition,
|
|
7489
|
+
architectureDefinition,
|
|
7490
|
+
mindMapDefinition,
|
|
7491
|
+
equationDefinition,
|
|
7492
|
+
quizDefinition,
|
|
7493
|
+
cardDefinition,
|
|
7494
|
+
infographicDefinition,
|
|
7495
|
+
pollDefinition,
|
|
7496
|
+
ratingDefinition,
|
|
7497
|
+
rankerDefinition,
|
|
7498
|
+
sliderDefinition,
|
|
7499
|
+
matrixDefinition,
|
|
7500
|
+
formDefinition,
|
|
7501
|
+
kanbanDefinition,
|
|
7502
|
+
annotateDefinition
|
|
7503
|
+
];
|
|
7504
|
+
|
|
7411
7505
|
exports.Accordion = Accordion;
|
|
7412
7506
|
exports.Annotate = Annotate;
|
|
7413
7507
|
exports.Architecture = Architecture;
|
|
@@ -7438,6 +7532,7 @@ exports.Table = Table;
|
|
|
7438
7532
|
exports.Tabs = Tabs;
|
|
7439
7533
|
exports.Timeline = Timeline;
|
|
7440
7534
|
exports.accordionDefinition = accordionDefinition;
|
|
7535
|
+
exports.allComponentDefinitions = allComponentDefinitions;
|
|
7441
7536
|
exports.annotateDefinition = annotateDefinition;
|
|
7442
7537
|
exports.architectureDefinition = architectureDefinition;
|
|
7443
7538
|
exports.calloutDefinition = calloutDefinition;
|