@iquji-web/web-component 0.1.10 → 0.1.11

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.js CHANGED
@@ -4749,26 +4749,716 @@ function IqujiEmojiPicker({ value, options, onChange, label, searchLabel, emptyL
4749
4749
  })
4750
4750
  });
4751
4751
  }
4752
+ // src/log-viewer.tsx
4753
+ import {
4754
+ useMemo as useMemo9,
4755
+ useRef as useRef15,
4756
+ useState as useState17
4757
+ } from "react";
4758
+ import { IqujiIcon as IqujiIcon16 } from "@iquji-web/web-icons";
4759
+ import { jsx as jsx36, jsxs as jsxs32 } from "react/jsx-runtime";
4760
+ var ISO_DATE_PATTERN = /^(\d{4}-\d{2}-\d{2}[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)\s*/i;
4761
+ var LEVEL_PATTERN = /^(info|information|warn|warning|error|err|failed|debug|trace|fatal)\b\s*/i;
4762
+ function parseLogLine(raw, index) {
4763
+ let text = raw.trim();
4764
+ let timestamp;
4765
+ let level = "info";
4766
+ let source;
4767
+ let phase;
4768
+ const dateMatch = text.match(ISO_DATE_PATTERN);
4769
+ if (dateMatch && dateMatch[1]) {
4770
+ timestamp = dateMatch[1];
4771
+ text = text.slice(dateMatch[0].length).trim();
4772
+ }
4773
+ const levelMatch = text.match(LEVEL_PATTERN);
4774
+ if (levelMatch && levelMatch[1]) {
4775
+ const matched = levelMatch[1].toLowerCase();
4776
+ if (matched === "error" || matched === "err" || matched === "failed" || matched === "fatal") {
4777
+ level = "error";
4778
+ } else if (matched === "warn" || matched === "warning") {
4779
+ level = "warn";
4780
+ } else if (matched === "debug" || matched === "trace") {
4781
+ level = "debug";
4782
+ } else {
4783
+ level = "info";
4784
+ }
4785
+ text = text.slice(levelMatch[0].length).trim();
4786
+ }
4787
+ if (/error|failed|failure|fatal|panic|失败|异常|错误/i.test(text)) {
4788
+ level = "error";
4789
+ } else if (/warn|warning|告警/i.test(text) && level === "info") {
4790
+ level = "warn";
4791
+ }
4792
+ const words = text.split(/\s+/);
4793
+ const firstWord = words[0];
4794
+ const secondWord = words[1];
4795
+ if (words.length >= 3 && firstWord && secondWord && /^[a-z0-9_-]+$/i.test(firstWord) && /^[a-z0-9_-]+$/i.test(secondWord)) {
4796
+ source = firstWord;
4797
+ phase = secondWord;
4798
+ text = words.slice(2).join(" ");
4799
+ }
4800
+ return {
4801
+ id: `parsed-${index}`,
4802
+ timestamp,
4803
+ level,
4804
+ source,
4805
+ phase,
4806
+ message: text || raw
4807
+ };
4808
+ }
4809
+ function normalizeLevel(level) {
4810
+ if (!level)
4811
+ return "info";
4812
+ const lower = level.toLowerCase();
4813
+ if (lower === "error" || lower === "err" || lower === "failed" || lower === "fatal")
4814
+ return "error";
4815
+ if (lower === "warn" || lower === "warning")
4816
+ return "warn";
4817
+ if (lower === "debug" || lower === "trace")
4818
+ return "debug";
4819
+ return "info";
4820
+ }
4821
+ function renderHighlighted(text, query) {
4822
+ if (!query.trim())
4823
+ return text;
4824
+ const parts = text.split(new RegExp(`(${query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`, "gi"));
4825
+ return parts.map((part, i) => part.toLowerCase() === query.toLowerCase() ? /* @__PURE__ */ jsx36("mark", {
4826
+ className: "iquji-log-viewer__highlight",
4827
+ children: part
4828
+ }, `h-${i}`) : part);
4829
+ }
4830
+ function IqujiLogViewer({
4831
+ actions,
4832
+ className,
4833
+ emptyLabel = "暂无日志记录",
4834
+ label = "日志查看器",
4835
+ loading = false,
4836
+ logs,
4837
+ maxHeight = 380,
4838
+ onCopy,
4839
+ showLineNumbers = true,
4840
+ showTimestamps = true,
4841
+ toolbar = true,
4842
+ wrapLines = false
4843
+ }) {
4844
+ const [search, setSearch] = useState17("");
4845
+ const [levelFilter, setLevelFilter] = useState17("all");
4846
+ const [wrapped, setWrapped] = useState17(wrapLines);
4847
+ const [copied, setCopied] = useState17(false);
4848
+ const scrollRef = useRef15(null);
4849
+ const normalized = useMemo9(() => {
4850
+ return logs.map((item, index) => {
4851
+ if (typeof item === "string") {
4852
+ return parseLogLine(item, index);
4853
+ }
4854
+ return {
4855
+ ...item,
4856
+ level: normalizeLevel(item.level)
4857
+ };
4858
+ });
4859
+ }, [logs]);
4860
+ const stats = useMemo9(() => {
4861
+ let errorCount = 0;
4862
+ let warnCount = 0;
4863
+ let infoCount = 0;
4864
+ for (const item of normalized) {
4865
+ if (item.level === "error")
4866
+ errorCount++;
4867
+ else if (item.level === "warn")
4868
+ warnCount++;
4869
+ else
4870
+ infoCount++;
4871
+ }
4872
+ return { errorCount, warnCount, infoCount, total: normalized.length };
4873
+ }, [normalized]);
4874
+ const filtered = useMemo9(() => {
4875
+ return normalized.filter((item) => {
4876
+ if (levelFilter !== "all" && item.level !== levelFilter) {
4877
+ return false;
4878
+ }
4879
+ if (search.trim()) {
4880
+ const query = search.trim().toLowerCase();
4881
+ const inMsg = item.message.toLowerCase().includes(query);
4882
+ const inSource = item.source?.toLowerCase().includes(query) ?? false;
4883
+ const inPhase = item.phase?.toLowerCase().includes(query) ?? false;
4884
+ const inSummary = item.errorSummary?.toLowerCase().includes(query) ?? false;
4885
+ return inMsg || inSource || inPhase || inSummary;
4886
+ }
4887
+ return true;
4888
+ });
4889
+ }, [normalized, levelFilter, search]);
4890
+ const handleCopy = async () => {
4891
+ const textToCopy = filtered.map((item) => [item.timestamp, item.level?.toUpperCase(), item.source, item.phase, item.message].filter(Boolean).join(" ")).join(`
4892
+ `);
4893
+ try {
4894
+ await navigator.clipboard.writeText(textToCopy);
4895
+ setCopied(true);
4896
+ onCopy?.(textToCopy);
4897
+ setTimeout(() => setCopied(false), 2000);
4898
+ } catch {}
4899
+ };
4900
+ const handleScrollBottom = () => {
4901
+ if (scrollRef.current) {
4902
+ scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
4903
+ }
4904
+ };
4905
+ const heightStyle = {
4906
+ maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight
4907
+ };
4908
+ return /* @__PURE__ */ jsxs32("div", {
4909
+ "aria-label": label,
4910
+ className: classNames("iquji-log-viewer", className),
4911
+ "data-wrap": wrapped ? "true" : undefined,
4912
+ role: "region",
4913
+ children: [
4914
+ toolbar ? /* @__PURE__ */ jsxs32("div", {
4915
+ className: "iquji-log-viewer__toolbar",
4916
+ children: [
4917
+ /* @__PURE__ */ jsxs32("div", {
4918
+ className: "iquji-log-viewer__toolbar-left",
4919
+ children: [
4920
+ /* @__PURE__ */ jsxs32("div", {
4921
+ className: "iquji-log-viewer__search",
4922
+ children: [
4923
+ /* @__PURE__ */ jsx36(IqujiIcon16, {
4924
+ decorative: true,
4925
+ name: "search",
4926
+ size: 12
4927
+ }),
4928
+ /* @__PURE__ */ jsx36("input", {
4929
+ "aria-label": "搜索日志",
4930
+ className: "iquji-log-viewer__search-input",
4931
+ onChange: (e) => setSearch(e.target.value),
4932
+ placeholder: "搜索日志内容…",
4933
+ type: "text",
4934
+ value: search
4935
+ }),
4936
+ search ? /* @__PURE__ */ jsx36("button", {
4937
+ "aria-label": "清空搜索",
4938
+ className: "iquji-log-viewer__filter-btn",
4939
+ onClick: () => setSearch(""),
4940
+ type: "button",
4941
+ children: /* @__PURE__ */ jsx36(IqujiIcon16, {
4942
+ decorative: true,
4943
+ name: "x-circle",
4944
+ size: 11
4945
+ })
4946
+ }) : null
4947
+ ]
4948
+ }),
4949
+ /* @__PURE__ */ jsxs32("div", {
4950
+ className: "iquji-log-viewer__filters",
4951
+ children: [
4952
+ /* @__PURE__ */ jsxs32("button", {
4953
+ className: "iquji-log-viewer__filter-btn",
4954
+ "data-active": levelFilter === "all" ? "true" : undefined,
4955
+ onClick: () => setLevelFilter("all"),
4956
+ type: "button",
4957
+ children: [
4958
+ "全部 (",
4959
+ stats.total,
4960
+ ")"
4961
+ ]
4962
+ }),
4963
+ /* @__PURE__ */ jsxs32("button", {
4964
+ className: "iquji-log-viewer__filter-btn",
4965
+ "data-active": levelFilter === "error" ? "true" : undefined,
4966
+ "data-tone": "error",
4967
+ onClick: () => setLevelFilter("error"),
4968
+ type: "button",
4969
+ children: [
4970
+ "错误 ",
4971
+ stats.errorCount > 0 ? `(${stats.errorCount})` : ""
4972
+ ]
4973
+ }),
4974
+ /* @__PURE__ */ jsxs32("button", {
4975
+ className: "iquji-log-viewer__filter-btn",
4976
+ "data-active": levelFilter === "warn" ? "true" : undefined,
4977
+ onClick: () => setLevelFilter("warn"),
4978
+ type: "button",
4979
+ children: [
4980
+ "警告 ",
4981
+ stats.warnCount > 0 ? `(${stats.warnCount})` : ""
4982
+ ]
4983
+ }),
4984
+ /* @__PURE__ */ jsx36("button", {
4985
+ className: "iquji-log-viewer__filter-btn",
4986
+ "data-active": levelFilter === "info" ? "true" : undefined,
4987
+ onClick: () => setLevelFilter("info"),
4988
+ type: "button",
4989
+ children: "信息"
4990
+ })
4991
+ ]
4992
+ })
4993
+ ]
4994
+ }),
4995
+ /* @__PURE__ */ jsxs32("div", {
4996
+ className: "iquji-log-viewer__toolbar-right",
4997
+ children: [
4998
+ /* @__PURE__ */ jsxs32("button", {
4999
+ "aria-label": wrapped ? "切换为单行横向滚动" : "切换为自动折行",
5000
+ className: "iquji-log-viewer__tool-btn",
5001
+ "data-active": wrapped ? "true" : undefined,
5002
+ onClick: () => setWrapped(!wrapped),
5003
+ title: wrapped ? "单行滚动" : "自动换行",
5004
+ type: "button",
5005
+ children: [
5006
+ /* @__PURE__ */ jsx36(IqujiIcon16, {
5007
+ decorative: true,
5008
+ name: "list-bulleted",
5009
+ size: 12
5010
+ }),
5011
+ /* @__PURE__ */ jsx36("span", {
5012
+ children: wrapped ? "折行" : "展开"
5013
+ })
5014
+ ]
5015
+ }),
5016
+ /* @__PURE__ */ jsxs32("button", {
5017
+ "aria-label": "复制当前日志",
5018
+ className: "iquji-log-viewer__tool-btn",
5019
+ disabled: filtered.length === 0,
5020
+ onClick: () => void handleCopy(),
5021
+ type: "button",
5022
+ children: [
5023
+ /* @__PURE__ */ jsx36(IqujiIcon16, {
5024
+ decorative: true,
5025
+ name: copied ? "check" : "copy",
5026
+ size: 12
5027
+ }),
5028
+ /* @__PURE__ */ jsx36("span", {
5029
+ children: copied ? "已复制" : "复制"
5030
+ })
5031
+ ]
5032
+ }),
5033
+ actions
5034
+ ]
5035
+ })
5036
+ ]
5037
+ }) : null,
5038
+ /* @__PURE__ */ jsx36("div", {
5039
+ className: "iquji-log-viewer__scroll",
5040
+ ref: scrollRef,
5041
+ style: heightStyle,
5042
+ children: loading ? /* @__PURE__ */ jsxs32("div", {
5043
+ className: "iquji-log-viewer__loading",
5044
+ children: [
5045
+ /* @__PURE__ */ jsx36(IqujiIcon16, {
5046
+ decorative: true,
5047
+ name: "rotate-ccw",
5048
+ size: 18
5049
+ }),
5050
+ /* @__PURE__ */ jsx36("span", {
5051
+ children: "正在读取日志流…"
5052
+ })
5053
+ ]
5054
+ }) : filtered.length === 0 ? /* @__PURE__ */ jsxs32("div", {
5055
+ className: "iquji-log-viewer__empty",
5056
+ children: [
5057
+ /* @__PURE__ */ jsx36(IqujiIcon16, {
5058
+ decorative: true,
5059
+ name: "terminal",
5060
+ size: 20
5061
+ }),
5062
+ /* @__PURE__ */ jsx36("span", {
5063
+ children: search || levelFilter !== "all" ? "未匹配到符合条件的日志" : emptyLabel
5064
+ })
5065
+ ]
5066
+ }) : /* @__PURE__ */ jsx36("div", {
5067
+ className: "iquji-log-viewer__lines",
5068
+ children: filtered.map((item, index) => {
5069
+ const level = item.level ?? "info";
5070
+ return /* @__PURE__ */ jsxs32("div", {
5071
+ className: "iquji-log-viewer__line",
5072
+ "data-level": level,
5073
+ children: [
5074
+ showLineNumbers ? /* @__PURE__ */ jsx36("span", {
5075
+ className: "iquji-log-viewer__num",
5076
+ children: index + 1
5077
+ }) : null,
5078
+ showTimestamps && item.timestamp ? /* @__PURE__ */ jsx36("span", {
5079
+ className: "iquji-log-viewer__time",
5080
+ children: item.timestamp
5081
+ }) : null,
5082
+ /* @__PURE__ */ jsx36("span", {
5083
+ className: "iquji-log-viewer__level",
5084
+ "data-level": level,
5085
+ children: level.toUpperCase()
5086
+ }),
5087
+ item.source || item.phase ? /* @__PURE__ */ jsx36("span", {
5088
+ className: "iquji-log-viewer__tag",
5089
+ children: [item.source, item.phase].filter(Boolean).join(" ")
5090
+ }) : null,
5091
+ /* @__PURE__ */ jsxs32("span", {
5092
+ className: "iquji-log-viewer__msg",
5093
+ children: [
5094
+ renderHighlighted(item.message, search),
5095
+ item.errorSummary ? /* @__PURE__ */ jsxs32("span", {
5096
+ className: "iquji-log-viewer__summary",
5097
+ children: [
5098
+ " — ",
5099
+ item.errorSummary
5100
+ ]
5101
+ }) : null
5102
+ ]
5103
+ })
5104
+ ]
5105
+ }, item.id ?? `log-${index}`);
5106
+ })
5107
+ })
5108
+ }),
5109
+ /* @__PURE__ */ jsxs32("div", {
5110
+ className: "iquji-log-viewer__status",
5111
+ children: [
5112
+ /* @__PURE__ */ jsxs32("div", {
5113
+ children: [
5114
+ search ? /* @__PURE__ */ jsxs32("span", {
5115
+ children: [
5116
+ "已过滤: ",
5117
+ filtered.length,
5118
+ " / 共 ",
5119
+ normalized.length,
5120
+ " 条"
5121
+ ]
5122
+ }) : /* @__PURE__ */ jsxs32("span", {
5123
+ children: [
5124
+ "共 ",
5125
+ normalized.length,
5126
+ " 条日志"
5127
+ ]
5128
+ }),
5129
+ stats.errorCount > 0 && levelFilter !== "error" ? /* @__PURE__ */ jsxs32("span", {
5130
+ style: { marginLeft: 8, color: "#f87171" },
5131
+ children: [
5132
+ "· ",
5133
+ stats.errorCount,
5134
+ " 处错误"
5135
+ ]
5136
+ }) : null
5137
+ ]
5138
+ }),
5139
+ /* @__PURE__ */ jsxs32("button", {
5140
+ "aria-label": "滚动到底部",
5141
+ className: "iquji-log-viewer__filter-btn",
5142
+ onClick: handleScrollBottom,
5143
+ type: "button",
5144
+ children: [
5145
+ /* @__PURE__ */ jsx36(IqujiIcon16, {
5146
+ decorative: true,
5147
+ name: "arrow-down",
5148
+ size: 11
5149
+ }),
5150
+ /* @__PURE__ */ jsx36("span", {
5151
+ children: "底部"
5152
+ })
5153
+ ]
5154
+ })
5155
+ ]
5156
+ })
5157
+ ]
5158
+ });
5159
+ }
5160
+ // src/diagnostic.tsx
5161
+ import { useMemo as useMemo10, useState as useState18 } from "react";
5162
+ import { IqujiIcon as IqujiIcon17 } from "@iquji-web/web-icons";
5163
+ import { jsx as jsx37, jsxs as jsxs33, Fragment as Fragment9 } from "react/jsx-runtime";
5164
+ function IqujiDiagnosticBanner({
5165
+ action,
5166
+ className,
5167
+ description,
5168
+ errorCode,
5169
+ title,
5170
+ tone = "danger"
5171
+ }) {
5172
+ const [copiedCode, setCopiedCode] = useState18(false);
5173
+ const iconName = tone === "success" ? "check-circle" : tone === "warning" || tone === "danger" ? "circle-alert" : "circle-info";
5174
+ const handleCopyCode = async (code) => {
5175
+ try {
5176
+ await navigator.clipboard.writeText(code);
5177
+ setCopiedCode(true);
5178
+ setTimeout(() => setCopiedCode(false), 2000);
5179
+ } catch {}
5180
+ };
5181
+ return /* @__PURE__ */ jsxs33("div", {
5182
+ className: classNames("iquji-diagnostic-banner", className),
5183
+ "data-tone": tone,
5184
+ role: "alert",
5185
+ children: [
5186
+ /* @__PURE__ */ jsxs33("div", {
5187
+ className: "iquji-diagnostic-banner__header",
5188
+ children: [
5189
+ /* @__PURE__ */ jsxs33("div", {
5190
+ className: "iquji-diagnostic-banner__lead",
5191
+ children: [
5192
+ /* @__PURE__ */ jsx37("span", {
5193
+ className: "iquji-diagnostic-banner__icon",
5194
+ children: /* @__PURE__ */ jsx37(IqujiIcon17, {
5195
+ decorative: true,
5196
+ name: iconName,
5197
+ size: 16
5198
+ })
5199
+ }),
5200
+ /* @__PURE__ */ jsx37("h4", {
5201
+ className: "iquji-diagnostic-banner__title",
5202
+ children: title
5203
+ })
5204
+ ]
5205
+ }),
5206
+ errorCode ? /* @__PURE__ */ jsxs33("button", {
5207
+ "aria-label": `复制错误码: ${errorCode}`,
5208
+ className: "iquji-diagnostic-banner__code",
5209
+ onClick: () => void handleCopyCode(errorCode),
5210
+ title: "点击复制错误代码",
5211
+ type: "button",
5212
+ children: [
5213
+ /* @__PURE__ */ jsx37("code", {
5214
+ children: errorCode
5215
+ }),
5216
+ /* @__PURE__ */ jsx37(IqujiIcon17, {
5217
+ decorative: true,
5218
+ name: copiedCode ? "check" : "copy",
5219
+ size: 11
5220
+ })
5221
+ ]
5222
+ }) : null
5223
+ ]
5224
+ }),
5225
+ description ? /* @__PURE__ */ jsx37("p", {
5226
+ className: "iquji-diagnostic-banner__desc",
5227
+ children: description
5228
+ }) : null,
5229
+ action ? /* @__PURE__ */ jsx37("div", {
5230
+ className: "iquji-diagnostic-banner__action",
5231
+ children: action
5232
+ }) : null
5233
+ ]
5234
+ });
5235
+ }
5236
+ function IqujiDiagnosticPanel({
5237
+ action,
5238
+ className,
5239
+ errorCode,
5240
+ errorMessage,
5241
+ errorTitle = "操作未完成",
5242
+ logs = [],
5243
+ logsError,
5244
+ logsLoading = false,
5245
+ maxHeight = 360,
5246
+ onRefreshLogs,
5247
+ status,
5248
+ taskId
5249
+ }) {
5250
+ const [copiedTaskId, setCopiedTaskId] = useState18(false);
5251
+ const statusTone = status === "failed" || status === "error" ? "danger" : status === "running" || status === "queued" ? "info" : status === "succeeded" || status === "success" ? "success" : "neutral";
5252
+ const handleCopyTaskId = async (id) => {
5253
+ try {
5254
+ await navigator.clipboard.writeText(id);
5255
+ setCopiedTaskId(true);
5256
+ setTimeout(() => setCopiedTaskId(false), 2000);
5257
+ } catch {}
5258
+ };
5259
+ return /* @__PURE__ */ jsxs33("div", {
5260
+ className: classNames("iquji-diagnostic-dialog-body", className),
5261
+ children: [
5262
+ action || taskId || status ? /* @__PURE__ */ jsxs33("div", {
5263
+ className: "iquji-diagnostic-meta",
5264
+ children: [
5265
+ action ? /* @__PURE__ */ jsx37("span", {
5266
+ className: "iquji-diagnostic-meta__item",
5267
+ children: /* @__PURE__ */ jsx37("span", {
5268
+ children: action
5269
+ })
5270
+ }) : null,
5271
+ taskId ? /* @__PURE__ */ jsxs33("span", {
5272
+ className: "iquji-diagnostic-meta__item",
5273
+ children: [
5274
+ /* @__PURE__ */ jsx37("code", {
5275
+ children: taskId
5276
+ }),
5277
+ /* @__PURE__ */ jsx37("button", {
5278
+ "aria-label": `复制任务ID: ${taskId}`,
5279
+ className: "iquji-diagnostic-meta__btn",
5280
+ onClick: () => void handleCopyTaskId(taskId),
5281
+ title: "复制任务 ID",
5282
+ type: "button",
5283
+ children: /* @__PURE__ */ jsx37(IqujiIcon17, {
5284
+ decorative: true,
5285
+ name: copiedTaskId ? "check" : "copy",
5286
+ size: 11
5287
+ })
5288
+ })
5289
+ ]
5290
+ }) : null,
5291
+ status ? /* @__PURE__ */ jsx37(IqujiBadge, {
5292
+ tone: statusTone,
5293
+ children: status === "failed" ? "失败" : status === "running" ? "执行中" : status === "queued" ? "队列中" : status === "succeeded" ? "成功" : status
5294
+ }) : null
5295
+ ]
5296
+ }) : null,
5297
+ errorMessage || errorCode ? /* @__PURE__ */ jsx37(IqujiDiagnosticBanner, {
5298
+ description: errorMessage,
5299
+ errorCode,
5300
+ title: errorTitle,
5301
+ tone: "danger"
5302
+ }) : null,
5303
+ logsError ? /* @__PURE__ */ jsx37(IqujiDiagnosticBanner, {
5304
+ action: onRefreshLogs ? /* @__PURE__ */ jsx37(IqujiButton, {
5305
+ compact: true,
5306
+ onClick: onRefreshLogs,
5307
+ variant: "secondary",
5308
+ children: "重新读取"
5309
+ }) : null,
5310
+ description: logsError,
5311
+ title: "诊断日志读取失败",
5312
+ tone: "danger"
5313
+ }) : null,
5314
+ /* @__PURE__ */ jsx37(IqujiLogViewer, {
5315
+ actions: onRefreshLogs ? /* @__PURE__ */ jsxs33("button", {
5316
+ "aria-label": "刷新日志",
5317
+ className: "iquji-log-viewer__tool-btn",
5318
+ disabled: logsLoading,
5319
+ onClick: onRefreshLogs,
5320
+ title: "刷新日志",
5321
+ type: "button",
5322
+ children: [
5323
+ /* @__PURE__ */ jsx37(IqujiIcon17, {
5324
+ decorative: true,
5325
+ name: "rotate-ccw",
5326
+ size: 11
5327
+ }),
5328
+ /* @__PURE__ */ jsx37("span", {
5329
+ children: logsLoading ? "刷新中…" : "刷新"
5330
+ })
5331
+ ]
5332
+ }) : null,
5333
+ emptyLabel: "此操作没有详细日志。旧版本未记录的失败原因需要重新探测或重试后查看。",
5334
+ label: "操作诊断日志",
5335
+ loading: logsLoading,
5336
+ logs,
5337
+ maxHeight
5338
+ })
5339
+ ]
5340
+ });
5341
+ }
5342
+ function IqujiDiagnosticDialog({
5343
+ action,
5344
+ closeLabel = "关闭操作诊断日志",
5345
+ diagnosticText,
5346
+ errorCode,
5347
+ errorMessage,
5348
+ errorTitle = "操作未完成",
5349
+ logs = [],
5350
+ logsError,
5351
+ logsLoading = false,
5352
+ onOpenChange,
5353
+ onRefreshLogs,
5354
+ open,
5355
+ size: size2 = "lg",
5356
+ status,
5357
+ taskId,
5358
+ title = "操作诊断日志",
5359
+ ...dialogProps
5360
+ }) {
5361
+ const [copiedDiagnostic, setCopiedDiagnostic] = useState18(false);
5362
+ const fullDiagnosticReport = useMemo10(() => {
5363
+ if (diagnosticText)
5364
+ return diagnosticText;
5365
+ const lines = ["### 操作诊断报告"];
5366
+ if (taskId)
5367
+ lines.push(`- **任务 ID**: \`${taskId}\``);
5368
+ if (action)
5369
+ lines.push(`- **动作**: \`${action}\``);
5370
+ if (status)
5371
+ lines.push(`- **状态**: ${status}`);
5372
+ if (errorCode)
5373
+ lines.push(`- **错误代码**: \`${errorCode}\``);
5374
+ if (errorMessage)
5375
+ lines.push(`- **错误说明**: ${errorMessage}`);
5376
+ lines.push("", "### 详细日志");
5377
+ if (logs.length === 0) {
5378
+ lines.push("*(无详细日志)*");
5379
+ } else {
5380
+ lines.push("```");
5381
+ for (const log of logs) {
5382
+ if (typeof log === "string") {
5383
+ lines.push(log);
5384
+ } else {
5385
+ lines.push([log.timestamp, log.level?.toUpperCase(), log.source, log.phase, log.message].filter(Boolean).join(" "));
5386
+ }
5387
+ }
5388
+ lines.push("```");
5389
+ }
5390
+ return lines.join(`
5391
+ `);
5392
+ }, [action, diagnosticText, errorCode, errorMessage, logs, status, taskId]);
5393
+ const handleCopyDiagnostic = async () => {
5394
+ try {
5395
+ await navigator.clipboard.writeText(fullDiagnosticReport);
5396
+ setCopiedDiagnostic(true);
5397
+ setTimeout(() => setCopiedDiagnostic(false), 2500);
5398
+ } catch {}
5399
+ };
5400
+ return /* @__PURE__ */ jsx37(IqujiDialog, {
5401
+ ...dialogProps,
5402
+ actions: /* @__PURE__ */ jsxs33(Fragment9, {
5403
+ children: [
5404
+ onRefreshLogs ? /* @__PURE__ */ jsx37(IqujiButton, {
5405
+ loading: logsLoading,
5406
+ onClick: onRefreshLogs,
5407
+ variant: "secondary",
5408
+ children: "刷新日志"
5409
+ }) : null,
5410
+ /* @__PURE__ */ jsx37(IqujiButton, {
5411
+ onClick: () => void handleCopyDiagnostic(),
5412
+ variant: "primary",
5413
+ children: copiedDiagnostic ? "✓ 诊断信息已复制" : "复制诊断信息"
5414
+ }),
5415
+ /* @__PURE__ */ jsx37(IqujiButton, {
5416
+ onClick: () => onOpenChange?.(false),
5417
+ variant: "ghost",
5418
+ children: "关闭"
5419
+ })
5420
+ ]
5421
+ }),
5422
+ closeLabel,
5423
+ description: action && taskId ? `${action} · ${taskId}` : dialogProps.description,
5424
+ onOpenChange,
5425
+ open,
5426
+ size: size2,
5427
+ title,
5428
+ children: /* @__PURE__ */ jsx37(IqujiDiagnosticPanel, {
5429
+ action,
5430
+ errorCode,
5431
+ errorMessage,
5432
+ errorTitle,
5433
+ logs,
5434
+ logsError,
5435
+ logsLoading,
5436
+ onRefreshLogs,
5437
+ status,
5438
+ taskId
5439
+ })
5440
+ });
5441
+ }
4752
5442
 
4753
5443
  // src/index.tsx
4754
- import { jsx as jsx36, jsxs as jsxs32, Fragment as Fragment9 } from "react/jsx-runtime";
5444
+ import { jsx as jsx38, jsxs as jsxs34, Fragment as Fragment10 } from "react/jsx-runtime";
4755
5445
  var renderNavigationItem = (item) => {
4756
- const content = /* @__PURE__ */ jsxs32(Fragment9, {
5446
+ const content = /* @__PURE__ */ jsxs34(Fragment10, {
4757
5447
  children: [
4758
5448
  item.icon,
4759
- /* @__PURE__ */ jsx36("span", {
5449
+ /* @__PURE__ */ jsx38("span", {
4760
5450
  children: item.label
4761
5451
  })
4762
5452
  ]
4763
5453
  });
4764
- return item.disabled || !item.href ? /* @__PURE__ */ jsx36("button", {
5454
+ return item.disabled || !item.href ? /* @__PURE__ */ jsx38("button", {
4765
5455
  "aria-label": item.label,
4766
5456
  className: "iquji-app-shell__navigation-item",
4767
5457
  "data-disabled": "true",
4768
5458
  disabled: true,
4769
5459
  type: "button",
4770
5460
  children: content
4771
- }, item.id) : /* @__PURE__ */ jsx36("a", {
5461
+ }, item.id) : /* @__PURE__ */ jsx38("a", {
4772
5462
  "aria-label": item.label,
4773
5463
  "aria-current": item.active ? "page" : undefined,
4774
5464
  className: "iquji-app-shell__navigation-item",
@@ -4790,29 +5480,29 @@ function AppShell({
4790
5480
  mainId = "iquji-main-content",
4791
5481
  skipLinkLabel
4792
5482
  }) {
4793
- return /* @__PURE__ */ jsxs32("div", {
5483
+ return /* @__PURE__ */ jsxs34("div", {
4794
5484
  className: "iquji-app-shell",
4795
5485
  children: [
4796
- skipLinkLabel ? /* @__PURE__ */ jsx36("a", {
5486
+ skipLinkLabel ? /* @__PURE__ */ jsx38("a", {
4797
5487
  className: "iquji-skip-link",
4798
5488
  href: `#${mainId}`,
4799
5489
  children: skipLinkLabel
4800
5490
  }) : null,
4801
- /* @__PURE__ */ jsxs32("aside", {
5491
+ /* @__PURE__ */ jsxs34("aside", {
4802
5492
  className: "iquji-app-shell__sidebar",
4803
5493
  children: [
4804
- /* @__PURE__ */ jsx36("div", {
5494
+ /* @__PURE__ */ jsx38("div", {
4805
5495
  className: "iquji-app-shell__brand",
4806
5496
  children: brand
4807
5497
  }),
4808
- /* @__PURE__ */ jsx36("nav", {
5498
+ /* @__PURE__ */ jsx38("nav", {
4809
5499
  "aria-label": navigationLabel,
4810
5500
  className: "iquji-app-shell__navigation",
4811
- children: navigationGroups?.length ? navigationGroups.map((group) => /* @__PURE__ */ jsxs32("section", {
5501
+ children: navigationGroups?.length ? navigationGroups.map((group) => /* @__PURE__ */ jsxs34("section", {
4812
5502
  "aria-labelledby": `${group.id}-navigation-heading`,
4813
5503
  className: "iquji-app-shell__navigation-group",
4814
5504
  children: [
4815
- /* @__PURE__ */ jsx36("h2", {
5505
+ /* @__PURE__ */ jsx38("h2", {
4816
5506
  className: "iquji-app-shell__navigation-heading",
4817
5507
  id: `${group.id}-navigation-heading`,
4818
5508
  children: group.label
@@ -4823,14 +5513,14 @@ function AppShell({
4823
5513
  })
4824
5514
  ]
4825
5515
  }),
4826
- /* @__PURE__ */ jsxs32("div", {
5516
+ /* @__PURE__ */ jsxs34("div", {
4827
5517
  className: "iquji-app-shell__workspace",
4828
5518
  children: [
4829
- /* @__PURE__ */ jsx36("header", {
5519
+ /* @__PURE__ */ jsx38("header", {
4830
5520
  className: "iquji-app-shell__header",
4831
5521
  children: header
4832
5522
  }),
4833
- /* @__PURE__ */ jsx36("main", {
5523
+ /* @__PURE__ */ jsx38("main", {
4834
5524
  className: "iquji-app-shell__main",
4835
5525
  id: mainId,
4836
5526
  tabIndex: -1,
@@ -4858,7 +5548,7 @@ var IconButton = forwardRef3(function IconButton2({
4858
5548
  compact ? "iquji-icon-button--compact" : null,
4859
5549
  className
4860
5550
  ].filter(Boolean).join(" ");
4861
- return /* @__PURE__ */ jsx36("button", {
5551
+ return /* @__PURE__ */ jsx38("button", {
4862
5552
  ...buttonProps,
4863
5553
  "aria-busy": loading || undefined,
4864
5554
  "aria-label": label,
@@ -4867,10 +5557,10 @@ var IconButton = forwardRef3(function IconButton2({
4867
5557
  ref,
4868
5558
  title: label,
4869
5559
  type,
4870
- children: loading ? /* @__PURE__ */ jsx36("span", {
5560
+ children: loading ? /* @__PURE__ */ jsx38("span", {
4871
5561
  "aria-hidden": "true",
4872
5562
  className: "iquji-button__spinner"
4873
- }) : /* @__PURE__ */ jsx36("span", {
5563
+ }) : /* @__PURE__ */ jsx38("span", {
4874
5564
  "aria-hidden": "true",
4875
5565
  className: "iquji-icon-button__icon",
4876
5566
  children: icon
@@ -4883,7 +5573,7 @@ function StatusBadge({
4883
5573
  ...props
4884
5574
  }) {
4885
5575
  const names = ["iquji-status-badge", className].filter(Boolean).join(" ");
4886
- return /* @__PURE__ */ jsx36("span", {
5576
+ return /* @__PURE__ */ jsx38("span", {
4887
5577
  className: names,
4888
5578
  "data-tone": tone,
4889
5579
  ...props
@@ -4911,11 +5601,11 @@ var IqujiButton = forwardRef3(function IqujiButton2({
4911
5601
  allowLabelWrap ? "iquji-button--allow-label-wrap" : null,
4912
5602
  className
4913
5603
  ].filter(Boolean).join(" ");
4914
- const content = typeof children === "string" || typeof children === "number" ? /* @__PURE__ */ jsx36("span", {
5604
+ const content = typeof children === "string" || typeof children === "number" ? /* @__PURE__ */ jsx38("span", {
4915
5605
  className: "iquji-button__label",
4916
5606
  children
4917
5607
  }) : children;
4918
- return /* @__PURE__ */ jsxs32("button", {
5608
+ return /* @__PURE__ */ jsxs34("button", {
4919
5609
  ...buttonProps,
4920
5610
  "aria-busy": loading || undefined,
4921
5611
  className: names,
@@ -4923,16 +5613,16 @@ var IqujiButton = forwardRef3(function IqujiButton2({
4923
5613
  ref,
4924
5614
  type,
4925
5615
  children: [
4926
- loading ? /* @__PURE__ */ jsx36("span", {
5616
+ loading ? /* @__PURE__ */ jsx38("span", {
4927
5617
  className: "iquji-button__spinner",
4928
5618
  "aria-hidden": "true"
4929
- }) : iconStart ? /* @__PURE__ */ jsx36("span", {
5619
+ }) : iconStart ? /* @__PURE__ */ jsx38("span", {
4930
5620
  className: "iquji-button__icon",
4931
5621
  "aria-hidden": "true",
4932
5622
  children: iconStart
4933
5623
  }) : null,
4934
5624
  content,
4935
- !loading && iconEnd ? /* @__PURE__ */ jsx36("span", {
5625
+ !loading && iconEnd ? /* @__PURE__ */ jsx38("span", {
4936
5626
  className: "iquji-button__icon",
4937
5627
  "aria-hidden": "true",
4938
5628
  children: iconEnd
@@ -4966,11 +5656,11 @@ function IqujiButtonLink({
4966
5656
  allowLabelWrap ? "iquji-button-link--allow-label-wrap" : null,
4967
5657
  className
4968
5658
  ].filter(Boolean).join(" ");
4969
- const content = typeof children === "string" || typeof children === "number" ? /* @__PURE__ */ jsx36("span", {
5659
+ const content = typeof children === "string" || typeof children === "number" ? /* @__PURE__ */ jsx38("span", {
4970
5660
  className: "iquji-button__label",
4971
5661
  children
4972
5662
  }) : children;
4973
- return /* @__PURE__ */ jsxs32("a", {
5663
+ return /* @__PURE__ */ jsxs34("a", {
4974
5664
  ...anchorProps,
4975
5665
  "aria-busy": loading || undefined,
4976
5666
  "aria-disabled": blocked || undefined,
@@ -4988,16 +5678,16 @@ function IqujiButtonLink({
4988
5678
  },
4989
5679
  tabIndex: blocked ? -1 : tabIndex,
4990
5680
  children: [
4991
- loading ? /* @__PURE__ */ jsx36("span", {
5681
+ loading ? /* @__PURE__ */ jsx38("span", {
4992
5682
  className: "iquji-button__spinner",
4993
5683
  "aria-hidden": "true"
4994
- }) : iconStart ? /* @__PURE__ */ jsx36("span", {
5684
+ }) : iconStart ? /* @__PURE__ */ jsx38("span", {
4995
5685
  className: "iquji-button__icon",
4996
5686
  "aria-hidden": "true",
4997
5687
  children: iconStart
4998
5688
  }) : null,
4999
5689
  content,
5000
- !loading && iconEnd ? /* @__PURE__ */ jsx36("span", {
5690
+ !loading && iconEnd ? /* @__PURE__ */ jsx38("span", {
5001
5691
  className: "iquji-button__icon",
5002
5692
  "aria-hidden": "true",
5003
5693
  children: iconEnd
@@ -5012,11 +5702,11 @@ function IqujiPanel({
5012
5702
  ...sectionProps
5013
5703
  }) {
5014
5704
  const names = ["iquji-panel", className].filter(Boolean).join(" ");
5015
- return /* @__PURE__ */ jsxs32("section", {
5705
+ return /* @__PURE__ */ jsxs34("section", {
5016
5706
  className: names,
5017
5707
  ...sectionProps,
5018
5708
  children: [
5019
- header ? /* @__PURE__ */ jsx36("header", {
5709
+ header ? /* @__PURE__ */ jsx38("header", {
5020
5710
  className: "iquji-panel__header",
5021
5711
  children: header
5022
5712
  }) : null,
@@ -5033,20 +5723,20 @@ function IqujiPageHeading({
5033
5723
  titleId
5034
5724
  }) {
5035
5725
  const names = ["iquji-page-heading", className].filter(Boolean).join(" ");
5036
- return /* @__PURE__ */ jsxs32("div", {
5726
+ return /* @__PURE__ */ jsxs34("div", {
5037
5727
  className: names,
5038
5728
  children: [
5039
- /* @__PURE__ */ jsxs32("div", {
5729
+ /* @__PURE__ */ jsxs34("div", {
5040
5730
  children: [
5041
- kicker ? /* @__PURE__ */ jsx36("p", {
5731
+ kicker ? /* @__PURE__ */ jsx38("p", {
5042
5732
  className: "iquji-page-heading__kicker",
5043
5733
  children: kicker
5044
5734
  }) : null,
5045
- /* @__PURE__ */ jsx36("h1", {
5735
+ /* @__PURE__ */ jsx38("h1", {
5046
5736
  id: titleId,
5047
5737
  children: title
5048
5738
  }),
5049
- summary ? /* @__PURE__ */ jsx36("p", {
5739
+ summary ? /* @__PURE__ */ jsx38("p", {
5050
5740
  className: "iquji-page-heading__summary",
5051
5741
  children: summary
5052
5742
  }) : null
@@ -5067,24 +5757,24 @@ function IqujiEmptyState({
5067
5757
  ...sectionProps
5068
5758
  }) {
5069
5759
  const names = ["iquji-empty-state", className].filter(Boolean).join(" ");
5070
- return /* @__PURE__ */ jsxs32("section", {
5760
+ return /* @__PURE__ */ jsxs34("section", {
5071
5761
  className: names,
5072
5762
  ...sectionProps,
5073
5763
  children: [
5074
- icon ? /* @__PURE__ */ jsx36("span", {
5764
+ icon ? /* @__PURE__ */ jsx38("span", {
5075
5765
  className: "iquji-empty-state__icon",
5076
5766
  "aria-hidden": "true",
5077
5767
  children: icon
5078
5768
  }) : null,
5079
- title ? /* @__PURE__ */ jsx36("h2", {
5769
+ title ? /* @__PURE__ */ jsx38("h2", {
5080
5770
  id: titleId,
5081
5771
  children: title
5082
5772
  }) : null,
5083
- body ? /* @__PURE__ */ jsx36("p", {
5773
+ body ? /* @__PURE__ */ jsx38("p", {
5084
5774
  children: body
5085
5775
  }) : null,
5086
5776
  children,
5087
- action ? /* @__PURE__ */ jsx36("div", {
5777
+ action ? /* @__PURE__ */ jsx38("div", {
5088
5778
  className: "iquji-empty-state__action",
5089
5779
  children: action
5090
5780
  }) : null
@@ -5097,18 +5787,18 @@ function IqujiLoadingState({
5097
5787
  ...divProps
5098
5788
  }) {
5099
5789
  const names = ["iquji-loading-state", className].filter(Boolean).join(" ");
5100
- return /* @__PURE__ */ jsxs32("div", {
5790
+ return /* @__PURE__ */ jsxs34("div", {
5101
5791
  "aria-busy": "true",
5102
5792
  "aria-live": "polite",
5103
5793
  className: names,
5104
5794
  role: "status",
5105
5795
  ...divProps,
5106
5796
  children: [
5107
- /* @__PURE__ */ jsx36("span", {
5797
+ /* @__PURE__ */ jsx38("span", {
5108
5798
  className: "iquji-loading-state__spinner",
5109
5799
  "aria-hidden": "true"
5110
5800
  }),
5111
- /* @__PURE__ */ jsx36("span", {
5801
+ /* @__PURE__ */ jsx38("span", {
5112
5802
  children: label
5113
5803
  })
5114
5804
  ]
@@ -5117,6 +5807,7 @@ function IqujiLoadingState({
5117
5807
  export {
5118
5808
  useIqujiOverlayContainer,
5119
5809
  useIqujiNotification,
5810
+ parseLogLine,
5120
5811
  parseCalendarDate,
5121
5812
  normalizeIqujiColor,
5122
5813
  formatCalendarDate,
@@ -5153,6 +5844,7 @@ export {
5153
5844
  IqujiOverlayProvider,
5154
5845
  IqujiNotificationProvider,
5155
5846
  IqujiMultiSelect,
5847
+ IqujiLogViewer,
5156
5848
  IqujiLoadingState,
5157
5849
  IqujiInput,
5158
5850
  IqujiFormSteps,
@@ -5163,6 +5855,9 @@ export {
5163
5855
  IqujiDropdownMenu,
5164
5856
  IqujiDrawer,
5165
5857
  IqujiDialog,
5858
+ IqujiDiagnosticPanel,
5859
+ IqujiDiagnosticDialog,
5860
+ IqujiDiagnosticBanner,
5166
5861
  IqujiDesktopTitleBar,
5167
5862
  IqujiDesktopTabStrip,
5168
5863
  IqujiDesktopShell,