refactor: remove as= override and render data-spark at runtime
- Drop resolveBlockAs and the as= attribute; scanDoc now switches directly on role and warns on unknown roles instead of silently stripping - md-table derives data-spark from its loaded CSV via parseSparkTableCsv; delete injectSparkDirectives and the second registry pass so pathIndex is exactly scanDoc output - Align spark-table dice header regex with isSparkTableHeader
This commit is contained in:
@@ -10,10 +10,11 @@ import {
|
||||
import { parseMarkdown } from "../markdown";
|
||||
import { parseCSVString, CSV, processVariables } from "./utils/csv-loader";
|
||||
import { resolveContentRef } from "./utils/resolve-content";
|
||||
import { parseSparkTableCsv } from "./utils/spark-table";
|
||||
import {
|
||||
areAllLabelsNumeric,
|
||||
weightedRandomIndex,
|
||||
} from "./utils/weighted-random";
|
||||
} from "./utils/weighted-random";;
|
||||
|
||||
export interface TableProps {
|
||||
roll?: boolean;
|
||||
@@ -59,16 +60,23 @@ customElement(
|
||||
if (content === null) {
|
||||
throw new Error(`Failed to resolve table content: "${ref}"`);
|
||||
}
|
||||
return parseCSVString(content);
|
||||
return content;
|
||||
},
|
||||
);
|
||||
|
||||
// 当数据加载完成后更新 rows
|
||||
// 当数据加载完成后更新 rows,并为火花表设置 data-spark(供 RevealManager
|
||||
// 悬停触发 /roll)。data-spark 在渲染时派生,不在扫描时注入。
|
||||
createEffect(() => {
|
||||
const data = csvData();
|
||||
if (data) {
|
||||
// 将加载的数据赋值给 rows,CSV 类型已经包含 sourcePath 等属性
|
||||
setRows(data as unknown as CSV<TableRow>);
|
||||
const content = csvData();
|
||||
if (!content) return;
|
||||
setRows(parseCSVString(content) as unknown as CSV<TableRow>);
|
||||
if (element) {
|
||||
const meta = parseSparkTableCsv(content);
|
||||
if (meta) {
|
||||
element.setAttribute("data-spark", meta.slug);
|
||||
} else {
|
||||
element.removeAttribute("data-spark");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user