sync update from LAN repo (source dhk-1 @ fc974e93)
This commit is contained in:
1 parent
a1fa13a238
commit
e2fea6a801
432 files changed
+68707
-2270
No files matched your search
+181
-77
@@ -118,8 +118,20 @@ DATA_MARKER = "__PAGE_DATA__"
|
||||
MANIFEST_MARKER = "__PAGE_MANIFEST__"
|
||||
RUNTIME_MARKER = "__PAGE_RUNTIME__"
|
||||
STRUCTURED_MARKERS: tuple[str, ...] = (DATA_MARKER, MANIFEST_MARKER, RUNTIME_MARKER)
|
||||
# 结构化模板目录里的组成文件(manifest.json 可选,其余必备)。
|
||||
STRUCTURED_PARTS: tuple[str, ...] = ("template.html", "runtime.js", "data.json", "manifest.json")
|
||||
_MARKER_RE = re.compile(r"__PAGE_[A-Z0-9_]+__")
|
||||
# 结构化模板目录里的必备件。
|
||||
STRUCTURED_PARTS: tuple[str, ...] = ("template.html", "runtime.js", "data.json")
|
||||
# 可选件:seed/reset 按存在复制;骨架里可写 __PAGE_<NAME>__ 扩展标记引用同名件
|
||||
# (NAME 小写、下划线转连字符,如 KNOWLEDGE→knowledge.json、SOURCE_LOCAL→source-local.json)。
|
||||
STRUCTURED_OPTIONAL_PARTS: tuple[str, ...] = (
|
||||
"manifest.json", "fields.json", "knowledge.json", "source-local.json",
|
||||
)
|
||||
|
||||
|
||||
def _marker_part_name(marker: str) -> str:
|
||||
"""扩展标记 → 可选件文件名(``__PAGE_SOURCE_LOCAL__`` → ``source-local.json``)。"""
|
||||
inner = marker[len("__PAGE_") : -len("__")]
|
||||
return inner.lower().replace("_", "-") + ".json"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -180,199 +192,259 @@ TEMPLATES: tuple[TemplateSpec, ...] = (
|
||||
id="no2",
|
||||
name="no.2",
|
||||
description="",
|
||||
file="no2/taiwan_air_force_v3_2.html",
|
||||
# 暂只展示已有数据,不做 JSON 转换/填充(后续接入转换后再开)。
|
||||
convertible=False,
|
||||
file="no2/template.html",
|
||||
# 结构化模板:骨架+runtime+data/knowledge/source-local/manifest/fields,
|
||||
# KNOWLEDGE/SOURCE_LOCAL 经 __PAGE_KNOWLEDGE__/__PAGE_SOURCE_LOCAL__ 扩展标记注入。
|
||||
kind="structured",
|
||||
legacy_file="no2/taiwan_air_force_v3_2.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no3",
|
||||
name="no.3",
|
||||
description="",
|
||||
file="no3/no3.html",
|
||||
# 无 const DATA= 注入点,暂只展示已有数据(后续接入转换后再开)。
|
||||
convertible=False,
|
||||
file="no3/template.html",
|
||||
# 结构化模板:骨架+runtime+data/manifest/fields,页面隐藏/字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no3/no3.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no4",
|
||||
name="no.4",
|
||||
description="",
|
||||
file="no4/no4.html",
|
||||
# 数据存于 <script id="app-data" type="application/json"> 元素(非 const DATA= 行),
|
||||
# 当前引擎只支持 const VAR= 行注入,故暂注册为只展示;接转换需扩展元素注入。
|
||||
convertible=False,
|
||||
file="no4/template.html",
|
||||
# 结构化模板:骨架+runtime+data(8 顶层键,40 数据集)/manifest(6 页面)/fields
|
||||
# (267 字段),页面隐藏/字段值级隐藏/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no4/no4.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no5",
|
||||
name="no.5",
|
||||
description="",
|
||||
file="no5/no5.html",
|
||||
# 数据用 `let DATA = {…}`(let + 空格,非 const DATA= 行),当前引擎不匹配,
|
||||
# 故暂注册为只展示;接转换需扩展行注入正则。
|
||||
convertible=False,
|
||||
file="no5/template.html",
|
||||
# 结构化模板:骨架+runtime+data(8 顶层键,含 navigation.tabs/ui.field_labels)
|
||||
# /manifest(5 页面)/fields(68 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no5/no5.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no6",
|
||||
name="no.6",
|
||||
description="",
|
||||
file="no6/no6.html",
|
||||
# 数据用 `const DATA = {…}`(= 前有空格,当前引擎正则要求 const DATA=),不匹配,
|
||||
# 故暂注册为只展示;接转换需放宽行注入正则。
|
||||
convertible=False,
|
||||
file="no6/template.html",
|
||||
# 结构化模板:骨架+runtime+data(14 顶层分支,11 页面)/manifest/fields
|
||||
# (108 中文字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no6/no6.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no7",
|
||||
name="no.7",
|
||||
description="",
|
||||
file="no7/no7.html",
|
||||
# 数据存于 <script id="PAGE_DATA" type="application/json"> 元素(同 no.4 类元素注入),
|
||||
# 当前引擎只支持 const VAR= 行注入,故暂注册为只展示;接转换需扩展元素注入。
|
||||
convertible=False,
|
||||
file="no7/template.html",
|
||||
# 结构化模板:骨架+runtime+data(9 顶层键,6 页面)/manifest/fields
|
||||
# (149 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no7/no7.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
# 显示 no.8;id 用 no8b(no8 已被显示名 no.12 的模板占用)。
|
||||
id="no8b",
|
||||
name="no.8",
|
||||
description="",
|
||||
file="no8b/no8b.html",
|
||||
convertible=False,
|
||||
# 结构化模板:骨架 + runtime + 数据 + 页面/字段配置。保留旧单文件,
|
||||
# 以便运行时存储只在用户未修改旧稿时自动升级。
|
||||
file="no8b/template.html",
|
||||
kind="structured",
|
||||
legacy_file="no8b/no8b.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
# 显示 no.9;id 用 no9b(no9 已被显示名 no.13 的模板占用)。
|
||||
id="no9b",
|
||||
name="no.9",
|
||||
description="",
|
||||
file="no9b/no9b.html",
|
||||
convertible=False,
|
||||
# 结构化模板:骨架 + runtime + 数据 + 页面/字段配置。保留旧单文件,
|
||||
# 以便运行时存储只在用户未修改旧稿时自动升级。
|
||||
file="no9b/template.html",
|
||||
kind="structured",
|
||||
legacy_file="no9b/no9b.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no10",
|
||||
name="no.10",
|
||||
description="",
|
||||
file="no10/no10.html",
|
||||
convertible=False,
|
||||
file="no10/template.html",
|
||||
# 结构化模板:骨架+runtime+data(6 顶层键,10 分类页面)/manifest/fields
|
||||
# (110 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no10/no10.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no11",
|
||||
name="no.11",
|
||||
description="",
|
||||
file="no11/no11.html",
|
||||
convertible=False,
|
||||
file="no11/template.html",
|
||||
# 结构化模板:骨架+runtime+data(15 顶层键,10 分类页面)/manifest/fields
|
||||
# (71 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no11/no11.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no8",
|
||||
name="no.12",
|
||||
description="",
|
||||
file="no8/no8.html",
|
||||
# 数据存于 <script id="DATA" type="application/json"> 元素(同 no.4/no.7 元素注入),
|
||||
# 当前引擎只支持 const VAR= 行注入,故暂注册为只展示;接转换需扩展元素注入。
|
||||
convertible=False,
|
||||
file="no8/template.html",
|
||||
# 结构化模板:骨架+runtime+data(11 顶层键,8 分类 tab)/manifest/fields
|
||||
# (73 中文字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no8/no8.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no9",
|
||||
name="no.13",
|
||||
description="",
|
||||
file="no9/no9.html",
|
||||
# 数据用 `const DATA = {…}`(= 前有空格,同 no.6),当前引擎正则要求 const DATA=,不匹配,
|
||||
# 故暂注册为只展示;接转换需放宽行注入正则。
|
||||
convertible=False,
|
||||
file="no9/template.html",
|
||||
# 结构化模板:骨架+runtime+data(18 顶层键,12 页面)/manifest/fields
|
||||
# (110 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no9/no9.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no14",
|
||||
name="no.14",
|
||||
description="",
|
||||
file="no14/no14.html",
|
||||
convertible=False,
|
||||
file="no14/template.html",
|
||||
# 结构化模板:骨架+runtime+data(10 顶层键,11 静态 panel 页面)/manifest/fields
|
||||
# (53 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no14/no14.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no15",
|
||||
name="no.15",
|
||||
description="",
|
||||
file="no15/no15.html",
|
||||
convertible=False,
|
||||
file="no15/template.html",
|
||||
# 结构化模板:骨架+runtime+data(9 顶层键,12 动态 tab 页面)/manifest/fields
|
||||
# (130 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no15/no15.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no16",
|
||||
name="no.16",
|
||||
description="",
|
||||
file="no16/no16.html",
|
||||
convertible=False,
|
||||
file="no16/template.html",
|
||||
# 结构化模板:骨架+runtime+data(16 顶层键,11 动态 tab 页面)/manifest/fields
|
||||
# (123 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no16/no16.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no17",
|
||||
name="no.17",
|
||||
description="",
|
||||
file="no17/no17.html",
|
||||
convertible=False,
|
||||
# 结构化模板:保留原始数据集和全部页签交互,支持页面/字段配置与旧稿升级。
|
||||
file="no17/template.html",
|
||||
kind="structured",
|
||||
legacy_file="no17/no17.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no18",
|
||||
name="no.18",
|
||||
description="",
|
||||
file="no18/no18.html",
|
||||
convertible=False,
|
||||
# 原始静态页面模块被保存为结构化 pages 数据,保留旧单文件用于自动升级。
|
||||
file="no18/template.html",
|
||||
kind="structured",
|
||||
legacy_file="no18/no18.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no19",
|
||||
name="no.19",
|
||||
description="",
|
||||
file="no19/no.19.html",
|
||||
convertible=False,
|
||||
file="no19/template.html",
|
||||
# 结构化模板:骨架+runtime+data(6 个数据集,10 个静态分页)/manifest/fields
|
||||
# (29 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no19/no.19.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no20",
|
||||
name="no.20",
|
||||
description="",
|
||||
file="no20/no.20.html",
|
||||
convertible=False,
|
||||
file="no20/template.html",
|
||||
# 结构化模板:骨架+runtime+data(12 顶层键,11 个动态 tab)/manifest/fields
|
||||
# (65 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no20/no.20.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no21",
|
||||
name="no.21",
|
||||
description="",
|
||||
file="no21/no.21.html",
|
||||
convertible=False,
|
||||
file="no21/template.html",
|
||||
# 结构化模板:骨架+runtime+data(4 顶层键,12 个动态 tab)/manifest/fields
|
||||
# (108 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no21/no.21.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no22",
|
||||
name="no.22",
|
||||
description="",
|
||||
file="no22/no.22.html",
|
||||
convertible=False,
|
||||
file="no22/template.html",
|
||||
# 结构化模板:骨架+runtime+data(19 顶层键,10 个动态 tab)/manifest/fields
|
||||
# (76 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no22/no.22.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no23",
|
||||
name="no.23",
|
||||
description="",
|
||||
file="no23/no.23.html",
|
||||
convertible=False,
|
||||
file="no23/template.html",
|
||||
# 结构化模板:骨架+runtime+data(13 顶层键,10 个分页)/manifest/fields
|
||||
# (39 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no23/no.23.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no24",
|
||||
name="no.24",
|
||||
description="",
|
||||
file="no24/no.24.html",
|
||||
convertible=False,
|
||||
file="no24/template.html",
|
||||
# 结构化模板:骨架+runtime+data(7 顶层键,12 个动态 tab)/manifest/fields
|
||||
# (29 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no24/no.24.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no25",
|
||||
name="no.25",
|
||||
description="",
|
||||
file="no25/no.25.html",
|
||||
convertible=False,
|
||||
# 结构化模板:保留原始动态数据模型、搜索/筛选/详情交互和旧稿升级能力。
|
||||
file="no25/template.html",
|
||||
kind="structured",
|
||||
legacy_file="no25/no.25.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no26",
|
||||
name="no.26",
|
||||
description="",
|
||||
file="no26/no.26.html",
|
||||
convertible=False,
|
||||
file="no26/template.html",
|
||||
# 结构化模板:骨架+runtime+data(2 顶层键,11 个分页)/manifest/fields
|
||||
# (3 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no26/no.26.html",
|
||||
),
|
||||
TemplateSpec(
|
||||
id="no27",
|
||||
name="no.27",
|
||||
description="",
|
||||
file="no27/no.27.html",
|
||||
convertible=False,
|
||||
file="no27/template.html",
|
||||
# 结构化模板:骨架+runtime+data(2 顶层键,11 个分页)/manifest/fields
|
||||
# (8 字段),页面隐藏/值级字段管理/写回全量能力。
|
||||
kind="structured",
|
||||
legacy_file="no27/no.27.html",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -518,7 +590,7 @@ def structured_module_labels(template_id: str) -> list[dict[str, str]]:
|
||||
ref = reference_data(template_id)
|
||||
manifest = _read_default_manifest(template_id)
|
||||
labels: dict[str, str] = {}
|
||||
split_index: dict[str, str] = {}
|
||||
page_seg: dict[str, str] = {}
|
||||
pages = manifest.get("页面")
|
||||
if isinstance(pages, list):
|
||||
for page in pages:
|
||||
@@ -537,14 +609,21 @@ def structured_module_labels(template_id: str) -> list[dict[str, str]]:
|
||||
candidates.append(key)
|
||||
for key in candidates:
|
||||
labels[key] = name
|
||||
first = candidates[0] if candidates else ""
|
||||
if first and "_" in first:
|
||||
for part in first.split("_"):
|
||||
page_seg[key] = name
|
||||
for part in key.split("_"):
|
||||
if part:
|
||||
split_index[part] = name
|
||||
page_seg.setdefault(part, name)
|
||||
out: list[dict[str, str]] = []
|
||||
for key in ref:
|
||||
out.append({"key": key, "label": labels.get(key) or split_index.get(key) or key})
|
||||
label = labels.get(key)
|
||||
if not label:
|
||||
# 双向段匹配:分支键与页面候选键互为子段(如 capability_pressure_matrix
|
||||
# ↔ 页面编号 matrix)时按页面名显示。
|
||||
for part in key.split("_"):
|
||||
if part and part in page_seg:
|
||||
label = page_seg[part]
|
||||
break
|
||||
out.append({"key": key, "label": label or key})
|
||||
return out
|
||||
|
||||
|
||||
@@ -554,6 +633,7 @@ def compose_structured(
|
||||
runtime: str,
|
||||
data: Any,
|
||||
manifest: dict[str, Any] | None = None,
|
||||
extra_parts: dict[str, str] | None = None,
|
||||
) -> str:
|
||||
"""把数据/运行时按标记组合进骨架,产出自包含单文件 HTML。
|
||||
|
||||
@@ -571,22 +651,45 @@ def compose_structured(
|
||||
)
|
||||
out = out.replace(MANIFEST_MARKER, serialized_manifest)
|
||||
out = out.replace(RUNTIME_MARKER, runtime.replace("</script", "<\\/script"))
|
||||
residual = [m for m in STRUCTURED_MARKERS if m in out]
|
||||
for marker, payload in (extra_parts or {}).items():
|
||||
if marker in out:
|
||||
out = out.replace(marker, payload.replace("</", "<" + chr(92) + "/"))
|
||||
residual = _MARKER_RE.findall(out)
|
||||
if residual:
|
||||
raise TemplateError(f"结构化模板组合后仍残留标记:{'、'.join(residual)}")
|
||||
raise TemplateError(f"结构化模板组合后仍残留标记:{','.join(sorted(set(residual)))}")
|
||||
return out
|
||||
|
||||
|
||||
def structured_extra_parts(template_id: str, skeleton: str) -> dict[str, str]:
|
||||
"""解析骨架里的扩展标记,从模板目录读对应可选数据件并序列化。
|
||||
|
||||
标准 DATA/MANIFEST 标记不走这里(它们由 compose 参数注入)。文件缺失的扩展
|
||||
标记跳过——组合后的残留断言会兜底报错。
|
||||
"""
|
||||
parts: dict[str, str] = {}
|
||||
for marker in set(_MARKER_RE.findall(skeleton)):
|
||||
if marker in STRUCTURED_MARKERS:
|
||||
continue
|
||||
path = _structured_part(template_id, _marker_part_name(marker))
|
||||
if path is not None:
|
||||
parts[marker] = json.dumps(
|
||||
json.loads(path.read_text(encoding="utf-8")), ensure_ascii=False
|
||||
)
|
||||
return parts
|
||||
|
||||
|
||||
def read_template_text(template_id: str) -> str:
|
||||
spec = _require(template_id)
|
||||
if spec.structured:
|
||||
# 结构化模板对外始终呈现「组合后的完整文档」(预览/只展示/参考展示共用);
|
||||
# 骨架原文(编辑用)由 template_store.read_template_html 直接读文件。
|
||||
tpl_skeleton = _structured_text(template_id, "template.html")
|
||||
return compose_structured(
|
||||
skeleton=_structured_text(template_id, "template.html"),
|
||||
skeleton=tpl_skeleton,
|
||||
runtime=_structured_text(template_id, "runtime.js"),
|
||||
data=reference_data(template_id),
|
||||
manifest=_read_default_manifest(template_id),
|
||||
extra_parts=structured_extra_parts(template_id, tpl_skeleton),
|
||||
)
|
||||
path = _template_path(spec)
|
||||
if not path.is_file():
|
||||
@@ -998,6 +1101,7 @@ def _fill_structured(
|
||||
runtime=_structured_text(template_id, "runtime.js"),
|
||||
data=data_obj,
|
||||
manifest=manifest,
|
||||
extra_parts=structured_extra_parts(template_id, skeleton),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user