@mdocui/react 0.1.2 → 0.1.4
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 +186 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +185 -62
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -116,10 +116,10 @@ import { ComponentRegistry } from "@mdocui/core";
|
|
|
116
116
|
// src/components/content.tsx
|
|
117
117
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
118
118
|
var calloutColors = {
|
|
119
|
-
info: { bg: "
|
|
120
|
-
warning: { bg: "
|
|
121
|
-
error: { bg: "
|
|
122
|
-
success: { bg: "
|
|
119
|
+
info: { bg: "rgba(59,130,246,0.1)", border: "#3b82f6" },
|
|
120
|
+
warning: { bg: "rgba(245,158,11,0.1)", border: "#f59e0b" },
|
|
121
|
+
error: { bg: "rgba(239,68,68,0.1)", border: "#ef4444" },
|
|
122
|
+
success: { bg: "rgba(34,197,94,0.1)", border: "#22c55e" }
|
|
123
123
|
};
|
|
124
124
|
function Callout({ props, children }) {
|
|
125
125
|
const type = props.type ?? "info";
|
|
@@ -145,11 +145,11 @@ function Callout({ props, children }) {
|
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
147
|
var badgeColors = {
|
|
148
|
-
default: { bg: "
|
|
149
|
-
success: { bg: "
|
|
150
|
-
warning: { bg: "
|
|
151
|
-
error: { bg: "
|
|
152
|
-
info: { bg: "
|
|
148
|
+
default: { bg: "rgba(148,163,184,0.15)", color: "#94a3b8" },
|
|
149
|
+
success: { bg: "rgba(34,197,94,0.15)", color: "#4ade80" },
|
|
150
|
+
warning: { bg: "rgba(245,158,11,0.15)", color: "#fbbf24" },
|
|
151
|
+
error: { bg: "rgba(239,68,68,0.15)", color: "#f87171" },
|
|
152
|
+
info: { bg: "rgba(59,130,246,0.15)", color: "#60a5fa" }
|
|
153
153
|
};
|
|
154
154
|
function Badge({ props }) {
|
|
155
155
|
const label = props.label;
|
|
@@ -248,7 +248,7 @@ function Link({ props, onAction, isStreaming }) {
|
|
|
248
248
|
"data-mdocui-link": true,
|
|
249
249
|
href: url ?? "#",
|
|
250
250
|
onClick: handleClick,
|
|
251
|
-
style: { color: "#
|
|
251
|
+
style: { color: "#60a5fa", textDecoration: "underline", cursor: "pointer" },
|
|
252
252
|
children: label
|
|
253
253
|
}
|
|
254
254
|
);
|
|
@@ -258,36 +258,88 @@ function Link({ props, onAction, isStreaming }) {
|
|
|
258
258
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
259
259
|
function Chart({ props }) {
|
|
260
260
|
const type = props.type;
|
|
261
|
-
const labels = props.labels
|
|
262
|
-
const values = props.values
|
|
261
|
+
const labels = Array.isArray(props.labels) ? props.labels : [];
|
|
262
|
+
const values = Array.isArray(props.values) ? props.values.map(Number) : [];
|
|
263
263
|
const title = props.title;
|
|
264
264
|
const max = values.reduce((a, b) => Math.max(a, b), 1);
|
|
265
|
-
return /* @__PURE__ */ jsxs2("div", { "data-mdocui-chart": true, "data-type": type, children: [
|
|
266
|
-
title && /* @__PURE__ */ jsx3("div", { style: { fontWeight: 600, marginBottom: "
|
|
267
|
-
(type === "bar" || type === "line") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", alignItems: "flex-end", gap: "
|
|
268
|
-
|
|
265
|
+
return /* @__PURE__ */ jsxs2("div", { "data-mdocui-chart": true, "data-type": type, style: { padding: "12px 0" }, children: [
|
|
266
|
+
title && /* @__PURE__ */ jsx3("div", { style: { fontWeight: 600, marginBottom: "12px" }, children: title }),
|
|
267
|
+
(type === "bar" || type === "line") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", alignItems: "flex-end", gap: "6px", height: "140px" }, children: values.map((val, i) => /* @__PURE__ */ jsxs2(
|
|
268
|
+
"div",
|
|
269
|
+
{
|
|
270
|
+
style: {
|
|
271
|
+
flex: 1,
|
|
272
|
+
textAlign: "center",
|
|
273
|
+
display: "flex",
|
|
274
|
+
flexDirection: "column",
|
|
275
|
+
justifyContent: "flex-end",
|
|
276
|
+
height: "100%"
|
|
277
|
+
},
|
|
278
|
+
children: [
|
|
279
|
+
/* @__PURE__ */ jsx3("div", { style: { fontSize: "11px", color: "#94a3b8", marginBottom: "4px" }, children: val }),
|
|
280
|
+
/* @__PURE__ */ jsx3(
|
|
281
|
+
"div",
|
|
282
|
+
{
|
|
283
|
+
style: {
|
|
284
|
+
height: `${Math.max(val / max * 100, 4)}%`,
|
|
285
|
+
background: "linear-gradient(180deg, #3b82f6, #2563eb)",
|
|
286
|
+
borderRadius: "4px 4px 0 0",
|
|
287
|
+
minHeight: "4px"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
),
|
|
291
|
+
/* @__PURE__ */ jsx3("div", { style: { fontSize: "11px", marginTop: "6px", color: "#64748b" }, children: labels[i] })
|
|
292
|
+
]
|
|
293
|
+
},
|
|
294
|
+
labels[i] ?? i
|
|
295
|
+
)) }),
|
|
296
|
+
(type === "pie" || type === "donut") && /* @__PURE__ */ jsx3("div", { style: { display: "flex", gap: "12px", flexWrap: "wrap" }, children: labels.map((label, i) => {
|
|
297
|
+
const total = values.reduce((a, b) => a + b, 0);
|
|
298
|
+
const pct = total > 0 ? Math.round(values[i] / total * 100) : 0;
|
|
299
|
+
return /* @__PURE__ */ jsxs2(
|
|
269
300
|
"div",
|
|
270
301
|
{
|
|
271
|
-
style: {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
302
|
+
style: { display: "flex", alignItems: "center", gap: "6px", fontSize: "13px" },
|
|
303
|
+
children: [
|
|
304
|
+
/* @__PURE__ */ jsx3(
|
|
305
|
+
"div",
|
|
306
|
+
{
|
|
307
|
+
style: {
|
|
308
|
+
width: 10,
|
|
309
|
+
height: 10,
|
|
310
|
+
borderRadius: "50%",
|
|
311
|
+
background: chartColors[i % chartColors.length]
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
),
|
|
315
|
+
/* @__PURE__ */ jsxs2("span", { children: [
|
|
316
|
+
label,
|
|
317
|
+
": ",
|
|
318
|
+
values[i],
|
|
319
|
+
" (",
|
|
320
|
+
pct,
|
|
321
|
+
"%)"
|
|
322
|
+
] })
|
|
323
|
+
]
|
|
324
|
+
},
|
|
325
|
+
label
|
|
326
|
+
);
|
|
327
|
+
}) })
|
|
286
328
|
] });
|
|
287
329
|
}
|
|
330
|
+
var chartColors = [
|
|
331
|
+
"#3b82f6",
|
|
332
|
+
"#22c55e",
|
|
333
|
+
"#f59e0b",
|
|
334
|
+
"#ef4444",
|
|
335
|
+
"#8b5cf6",
|
|
336
|
+
"#ec4899",
|
|
337
|
+
"#06b6d4",
|
|
338
|
+
"#f97316"
|
|
339
|
+
];
|
|
288
340
|
function Table({ props }) {
|
|
289
|
-
const headers = props.headers
|
|
290
|
-
const rows = props.rows
|
|
341
|
+
const headers = Array.isArray(props.headers) ? props.headers : [];
|
|
342
|
+
const rows = Array.isArray(props.rows) ? props.rows : [];
|
|
291
343
|
const caption = props.caption;
|
|
292
344
|
return /* @__PURE__ */ jsxs2("table", { "data-mdocui-table": true, style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
293
345
|
caption && /* @__PURE__ */ jsx3("caption", { style: { textAlign: "left", fontWeight: 600, marginBottom: "8px" }, children: caption }),
|
|
@@ -297,17 +349,22 @@ function Table({ props }) {
|
|
|
297
349
|
style: {
|
|
298
350
|
textAlign: "left",
|
|
299
351
|
padding: "8px",
|
|
300
|
-
borderBottom: "2px solid #
|
|
301
|
-
fontWeight: 600
|
|
352
|
+
borderBottom: "2px solid #333",
|
|
353
|
+
fontWeight: 600,
|
|
354
|
+
color: "#94a3b8",
|
|
355
|
+
fontSize: "13px"
|
|
302
356
|
},
|
|
303
357
|
children: h
|
|
304
358
|
},
|
|
305
359
|
h
|
|
306
360
|
)) }) }),
|
|
307
|
-
/* @__PURE__ */ jsx3("tbody", { children: rows.map((row) =>
|
|
308
|
-
const
|
|
309
|
-
return /* @__PURE__ */ jsx3("
|
|
310
|
-
|
|
361
|
+
/* @__PURE__ */ jsx3("tbody", { children: rows.map((row) => {
|
|
362
|
+
const cells = Array.isArray(row) ? row : [String(row)];
|
|
363
|
+
return /* @__PURE__ */ jsx3("tr", { children: cells.map((cell) => {
|
|
364
|
+
const cellKey = `${cells[0]}-${cell}`;
|
|
365
|
+
return /* @__PURE__ */ jsx3("td", { style: { padding: "8px", borderBottom: "1px solid #222" }, children: cell }, cellKey);
|
|
366
|
+
}) }, cells.join(" "));
|
|
367
|
+
}) })
|
|
311
368
|
] });
|
|
312
369
|
}
|
|
313
370
|
function Stat({ props }) {
|
|
@@ -315,24 +372,41 @@ function Stat({ props }) {
|
|
|
315
372
|
const value = props.value;
|
|
316
373
|
const change = props.change;
|
|
317
374
|
const trend = props.trend ?? "neutral";
|
|
318
|
-
const trendColor = trend === "up" ? "#
|
|
319
|
-
return /* @__PURE__ */ jsxs2("div", { "data-mdocui-stat": true, children: [
|
|
375
|
+
const trendColor = trend === "up" ? "#4ade80" : trend === "down" ? "#f87171" : "#64748b";
|
|
376
|
+
return /* @__PURE__ */ jsxs2("div", { "data-mdocui-stat": true, style: { padding: "8px 0" }, children: [
|
|
320
377
|
/* @__PURE__ */ jsx3("div", { style: { fontSize: "13px", color: "#64748b" }, children: label }),
|
|
321
378
|
/* @__PURE__ */ jsx3("div", { style: { fontSize: "24px", fontWeight: 700 }, children: value }),
|
|
322
379
|
change && /* @__PURE__ */ jsx3("div", { style: { fontSize: "13px", color: trendColor }, children: change })
|
|
323
380
|
] });
|
|
324
381
|
}
|
|
325
382
|
function Progress({ props }) {
|
|
326
|
-
const value = props.value;
|
|
383
|
+
const value = Number(props.value) || 0;
|
|
327
384
|
const label = props.label;
|
|
328
|
-
const max = props.max
|
|
385
|
+
const max = Number(props.max) || 100;
|
|
329
386
|
const pct = Math.min(100, Math.max(0, value / max * 100));
|
|
330
387
|
return /* @__PURE__ */ jsxs2("div", { "data-mdocui-progress": true, children: [
|
|
331
|
-
label && /* @__PURE__ */
|
|
388
|
+
label && /* @__PURE__ */ jsxs2(
|
|
389
|
+
"div",
|
|
390
|
+
{
|
|
391
|
+
style: {
|
|
392
|
+
fontSize: "13px",
|
|
393
|
+
marginBottom: "4px",
|
|
394
|
+
display: "flex",
|
|
395
|
+
justifyContent: "space-between"
|
|
396
|
+
},
|
|
397
|
+
children: [
|
|
398
|
+
/* @__PURE__ */ jsx3("span", { children: label }),
|
|
399
|
+
/* @__PURE__ */ jsxs2("span", { style: { color: "#64748b" }, children: [
|
|
400
|
+
Math.round(pct),
|
|
401
|
+
"%"
|
|
402
|
+
] })
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
),
|
|
332
406
|
/* @__PURE__ */ jsx3(
|
|
333
407
|
"div",
|
|
334
408
|
{
|
|
335
|
-
style: { height: "8px", background: "#
|
|
409
|
+
style: { height: "8px", background: "#27272a", borderRadius: "4px", overflow: "hidden" },
|
|
336
410
|
children: /* @__PURE__ */ jsx3(
|
|
337
411
|
"div",
|
|
338
412
|
{
|
|
@@ -351,14 +425,17 @@ function Progress({ props }) {
|
|
|
351
425
|
}
|
|
352
426
|
|
|
353
427
|
// src/components/interactive.tsx
|
|
428
|
+
import { useState as useState2 } from "react";
|
|
354
429
|
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
355
430
|
function Button({ props, onAction, isStreaming }) {
|
|
356
431
|
const action = props.action;
|
|
357
432
|
const label = props.label;
|
|
358
433
|
const variant = props.variant ?? "primary";
|
|
359
434
|
const disabled = props.disabled ?? false;
|
|
435
|
+
const [clicked, setClicked] = useState2(false);
|
|
436
|
+
const isDisabled = isStreaming || disabled || clicked;
|
|
360
437
|
const handleClick = () => {
|
|
361
|
-
if (
|
|
438
|
+
if (isDisabled) return;
|
|
362
439
|
const event = {
|
|
363
440
|
type: "button_click",
|
|
364
441
|
action,
|
|
@@ -366,6 +443,7 @@ function Button({ props, onAction, isStreaming }) {
|
|
|
366
443
|
tagName: "button"
|
|
367
444
|
};
|
|
368
445
|
onAction(event);
|
|
446
|
+
setClicked(true);
|
|
369
447
|
};
|
|
370
448
|
return /* @__PURE__ */ jsx4(
|
|
371
449
|
"button",
|
|
@@ -373,16 +451,16 @@ function Button({ props, onAction, isStreaming }) {
|
|
|
373
451
|
type: "button",
|
|
374
452
|
"data-mdocui-button": true,
|
|
375
453
|
"data-variant": variant,
|
|
376
|
-
disabled:
|
|
454
|
+
disabled: isDisabled,
|
|
377
455
|
onClick: handleClick,
|
|
378
456
|
style: {
|
|
379
457
|
padding: "8px 16px",
|
|
380
458
|
borderRadius: "6px",
|
|
381
|
-
cursor:
|
|
382
|
-
opacity:
|
|
383
|
-
border: variant === "outline" ? "1px solid
|
|
384
|
-
background: variant === "primary" ? "#
|
|
385
|
-
color:
|
|
459
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
460
|
+
opacity: isDisabled ? 0.5 : 1,
|
|
461
|
+
border: variant === "outline" ? "1px solid #555" : "none",
|
|
462
|
+
background: variant === "primary" ? "#3b82f6" : variant === "ghost" ? "transparent" : "#27272a",
|
|
463
|
+
color: "#fff"
|
|
386
464
|
},
|
|
387
465
|
children: label
|
|
388
466
|
}
|
|
@@ -423,7 +501,9 @@ function Input({ props }) {
|
|
|
423
501
|
style: {
|
|
424
502
|
width: "100%",
|
|
425
503
|
padding: "8px 12px",
|
|
426
|
-
border: "1px solid #
|
|
504
|
+
border: "1px solid #333",
|
|
505
|
+
background: "#18181b",
|
|
506
|
+
color: "inherit",
|
|
427
507
|
borderRadius: "6px",
|
|
428
508
|
boxSizing: "border-box"
|
|
429
509
|
}
|
|
@@ -434,7 +514,7 @@ function Input({ props }) {
|
|
|
434
514
|
function Select({ props, onAction, isStreaming }) {
|
|
435
515
|
const name = props.name;
|
|
436
516
|
const label = props.label;
|
|
437
|
-
const options = props.options
|
|
517
|
+
const options = Array.isArray(props.options) ? props.options : [];
|
|
438
518
|
const placeholder = props.placeholder;
|
|
439
519
|
const required = props.required ?? false;
|
|
440
520
|
const id = `mdocui-${name}`;
|
|
@@ -459,7 +539,9 @@ function Select({ props, onAction, isStreaming }) {
|
|
|
459
539
|
style: {
|
|
460
540
|
width: "100%",
|
|
461
541
|
padding: "8px 12px",
|
|
462
|
-
border: "1px solid #
|
|
542
|
+
border: "1px solid #333",
|
|
543
|
+
background: "#18181b",
|
|
544
|
+
color: "inherit",
|
|
463
545
|
borderRadius: "6px"
|
|
464
546
|
},
|
|
465
547
|
children: [
|
|
@@ -498,9 +580,10 @@ function Checkbox({ props, onAction, isStreaming }) {
|
|
|
498
580
|
function Form({ props, children, onAction, isStreaming }) {
|
|
499
581
|
const formName = props.name;
|
|
500
582
|
const action = props.action ?? `submit:${formName}`;
|
|
583
|
+
const [submitted, setSubmitted] = useState2(false);
|
|
501
584
|
const handleSubmit = (e) => {
|
|
502
585
|
e.preventDefault();
|
|
503
|
-
if (isStreaming) return;
|
|
586
|
+
if (isStreaming || submitted) return;
|
|
504
587
|
const formData = new FormData(e.currentTarget);
|
|
505
588
|
const state = {};
|
|
506
589
|
formData.forEach((value, key) => {
|
|
@@ -514,7 +597,47 @@ function Form({ props, children, onAction, isStreaming }) {
|
|
|
514
597
|
tagName: "form"
|
|
515
598
|
};
|
|
516
599
|
onAction(event);
|
|
600
|
+
setSubmitted(true);
|
|
517
601
|
};
|
|
602
|
+
if (submitted) {
|
|
603
|
+
return /* @__PURE__ */ jsxs3(
|
|
604
|
+
"div",
|
|
605
|
+
{
|
|
606
|
+
"data-mdocui-form": true,
|
|
607
|
+
"data-name": formName,
|
|
608
|
+
"data-submitted": true,
|
|
609
|
+
style: {
|
|
610
|
+
display: "flex",
|
|
611
|
+
flexDirection: "column",
|
|
612
|
+
gap: "12px",
|
|
613
|
+
opacity: 0.5,
|
|
614
|
+
pointerEvents: "none",
|
|
615
|
+
position: "relative"
|
|
616
|
+
},
|
|
617
|
+
children: [
|
|
618
|
+
children,
|
|
619
|
+
/* @__PURE__ */ jsx4(
|
|
620
|
+
"div",
|
|
621
|
+
{
|
|
622
|
+
style: {
|
|
623
|
+
position: "absolute",
|
|
624
|
+
inset: 0,
|
|
625
|
+
display: "flex",
|
|
626
|
+
alignItems: "center",
|
|
627
|
+
justifyContent: "center",
|
|
628
|
+
background: "rgba(0,0,0,0.3)",
|
|
629
|
+
borderRadius: "8px",
|
|
630
|
+
fontSize: "13px",
|
|
631
|
+
color: "#4ade80",
|
|
632
|
+
fontWeight: 500
|
|
633
|
+
},
|
|
634
|
+
children: "Submitted"
|
|
635
|
+
}
|
|
636
|
+
)
|
|
637
|
+
]
|
|
638
|
+
}
|
|
639
|
+
);
|
|
640
|
+
}
|
|
518
641
|
return /* @__PURE__ */ jsx4(
|
|
519
642
|
"form",
|
|
520
643
|
{
|
|
@@ -528,7 +651,7 @@ function Form({ props, children, onAction, isStreaming }) {
|
|
|
528
651
|
}
|
|
529
652
|
|
|
530
653
|
// src/components/layout.tsx
|
|
531
|
-
import React, { useState as
|
|
654
|
+
import React, { useState as useState3 } from "react";
|
|
532
655
|
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
533
656
|
function Stack({ props, children }) {
|
|
534
657
|
const direction = props.direction ?? "vertical";
|
|
@@ -574,7 +697,7 @@ function Card({ props, children }) {
|
|
|
574
697
|
{
|
|
575
698
|
"data-mdocui-card": true,
|
|
576
699
|
"data-variant": props.variant ?? "default",
|
|
577
|
-
style: { border: "1px solid #
|
|
700
|
+
style: { border: "1px solid #27272a", borderRadius: "8px", padding: "16px" },
|
|
578
701
|
children: [
|
|
579
702
|
title && /* @__PURE__ */ jsx5("div", { "data-mdocui-card-title": true, style: { fontWeight: 600, marginBottom: "8px" }, children: title }),
|
|
580
703
|
/* @__PURE__ */ jsx5("div", { "data-mdocui-card-body": true, children })
|
|
@@ -587,7 +710,7 @@ function Divider(_) {
|
|
|
587
710
|
"hr",
|
|
588
711
|
{
|
|
589
712
|
"data-mdocui-divider": true,
|
|
590
|
-
style: { border: "none", borderTop: "1px solid #
|
|
713
|
+
style: { border: "none", borderTop: "1px solid #27272a", margin: "8px 0" }
|
|
591
714
|
}
|
|
592
715
|
);
|
|
593
716
|
}
|
|
@@ -600,16 +723,16 @@ function Accordion({ props, children }) {
|
|
|
600
723
|
] });
|
|
601
724
|
}
|
|
602
725
|
function Tabs({ props, children }) {
|
|
603
|
-
const labels = props.labels
|
|
726
|
+
const labels = Array.isArray(props.labels) ? props.labels : [];
|
|
604
727
|
const initialActive = props.active ?? 0;
|
|
605
|
-
const [active, setActive] =
|
|
728
|
+
const [active, setActive] = useState3(initialActive);
|
|
606
729
|
const childArray = React.Children.toArray(children);
|
|
607
730
|
return /* @__PURE__ */ jsxs4("div", { "data-mdocui-tabs": true, children: [
|
|
608
731
|
/* @__PURE__ */ jsx5(
|
|
609
732
|
"div",
|
|
610
733
|
{
|
|
611
734
|
role: "tablist",
|
|
612
|
-
style: { display: "flex", gap: "4px", borderBottom: "1px solid #
|
|
735
|
+
style: { display: "flex", gap: "4px", borderBottom: "1px solid #27272a" },
|
|
613
736
|
children: labels.map((label, i) => /* @__PURE__ */ jsx5(
|
|
614
737
|
"button",
|
|
615
738
|
{
|