@jzg223/design-runtime 0.0.1 → 0.1.0-rc.2

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +52 -0
  3. package/dist/board/api.js +57 -0
  4. package/dist/board/board-chart.vue.js +7 -0
  5. package/dist/board/board-chart2.vue.js +93 -0
  6. package/dist/board/context.js +15 -0
  7. package/dist/board/datav-map.js +66 -0
  8. package/dist/board/design-board.vue.js +172 -0
  9. package/dist/board/design-board2.vue.js +331 -0
  10. package/dist/board/echarts.js +40 -0
  11. package/dist/board/part-node.vue.js +63 -0
  12. package/dist/board/part-node2.vue.js +125 -0
  13. package/dist/board/part-renderer.vue.js +561 -0
  14. package/dist/board/part-renderer2.vue.js +884 -0
  15. package/dist/board/theme-host.js +129 -0
  16. package/dist/board-engine/asset.js +32 -0
  17. package/dist/board-engine/chart-option.js +377 -0
  18. package/dist/board-engine/data-hub.js +67 -0
  19. package/dist/board-engine/datav-meta.js +51 -0
  20. package/dist/board-engine/i18n.js +130 -0
  21. package/dist/board-engine/param-catalog.js +137 -0
  22. package/dist/board-engine/params.js +61 -0
  23. package/dist/board-engine/render-model.js +65 -0
  24. package/dist/board-engine/schema.js +856 -0
  25. package/dist/board-engine/theme-manifest.js +19 -0
  26. package/dist/board-engine/version.js +4 -0
  27. package/dist/host.js +6 -1
  28. package/dist/index.js +172 -24
  29. package/dist/style.css +1067 -0
  30. package/dist/types/board/api.d.ts +45 -0
  31. package/dist/types/board/board-chart.vue.d.ts +15 -0
  32. package/dist/types/board/context.d.ts +29 -0
  33. package/dist/types/board/datav-map.d.ts +24 -0
  34. package/dist/types/board/design-board.vue.d.ts +1409 -0
  35. package/dist/types/board/echarts.d.ts +25 -0
  36. package/dist/types/board/part-node.vue.d.ts +1237 -0
  37. package/dist/types/board/part-renderer.vue.d.ts +1205 -0
  38. package/dist/types/board/theme-host.d.ts +41 -0
  39. package/dist/types/board-engine/asset.d.ts +37 -0
  40. package/dist/types/board-engine/chart-option.d.ts +737 -0
  41. package/dist/types/board-engine/data-hub.d.ts +48 -0
  42. package/dist/types/board-engine/datav-meta.d.ts +37 -0
  43. package/dist/types/board-engine/i18n.d.ts +43 -0
  44. package/dist/types/board-engine/index.d.ts +25 -0
  45. package/dist/types/board-engine/param-catalog.d.ts +82 -0
  46. package/dist/types/board-engine/params.d.ts +37 -0
  47. package/dist/types/board-engine/render-model.d.ts +87 -0
  48. package/dist/types/board-engine/schema.d.ts +513 -0
  49. package/dist/types/board-engine/theme-manifest.d.ts +23 -0
  50. package/dist/types/board-engine/types.d.ts +147 -0
  51. package/dist/types/board-engine/version.d.ts +10 -0
  52. package/dist/types/host.d.ts +21 -0
  53. package/dist/types/index.d.ts +21 -2
  54. package/package.json +21 -4
@@ -0,0 +1,130 @@
1
+ const LOCALES = [
2
+ { code: "zh-CHS", label: "简体中文" },
3
+ { code: "en-US", label: "English" },
4
+ { code: "ug-CN", label: "ئۇيغۇرچە(维吾尔语)" }
5
+ ];
6
+ const DEFAULT_LOCALE = "zh-CHS";
7
+ const TRANSLATABLE = {
8
+ _common: [{ path: "name", label: "部件名称" }],
9
+ chart: [],
10
+ kpi: [
11
+ { path: "view.title", label: "标题" },
12
+ { path: "view.unit", label: "单位" }
13
+ ],
14
+ table: [],
15
+ crossTable: [],
16
+ text: [{ path: "view.content", label: "文本内容" }],
17
+ image: [],
18
+ border: [{ path: "view.title", label: "边框标题" }],
19
+ container: [{ path: "view.title", label: "容器标题" }],
20
+ tabContainer: [
21
+ { path: "view.tabs", label: "页签(每行一个)", multi: true },
22
+ { path: "view.contents", label: "每页内容(每行一段)", multi: true }
23
+ ],
24
+ iframe: [],
25
+ video: [],
26
+ carousel: [{ path: "view.images", label: "图片标题(每行一个)", multi: true, sub: "title" }],
27
+ marquee: [{ path: "view.content", label: "播报内容" }],
28
+ progress: [
29
+ { path: "view.title", label: "标题" },
30
+ { path: "view.unit", label: "单位" }
31
+ ],
32
+ button: [{ path: "view.text", label: "按钮文字" }],
33
+ filter: [
34
+ { path: "view.label", label: "标签" },
35
+ { path: "view.paramCode", label: "参数编码" }
36
+ ]
37
+ };
38
+ function translatableFields(part) {
39
+ const list = [...TRANSLATABLE._common ?? []];
40
+ const extra = TRANSLATABLE[part == null ? void 0 : part.type] ?? [];
41
+ return list.concat(extra);
42
+ }
43
+ function getByPath(obj, path) {
44
+ return path.split(".").reduce((o, k) => o === null || o === void 0 ? void 0 : o[k], obj);
45
+ }
46
+ function setByPath(obj, path, value) {
47
+ const keys = path.split(".");
48
+ let cur = obj;
49
+ for (let i = 0; i < keys.length - 1; i++) {
50
+ const k = keys[i];
51
+ if (cur[k] === void 0 || cur[k] === null) cur[k] = {};
52
+ cur = cur[k];
53
+ }
54
+ cur[keys[keys.length - 1]] = value;
55
+ }
56
+ function asText(v) {
57
+ return v === void 0 || v === null ? "" : String(v);
58
+ }
59
+ function fieldText(part, locale, path, sub) {
60
+ var _a;
61
+ const ov = (_a = part == null ? void 0 : part.i18n) == null ? void 0 : _a[locale];
62
+ const base = getByPath(part, path);
63
+ if (locale === DEFAULT_LOCALE || !ov || ov[path] === void 0) {
64
+ if (sub && Array.isArray(base)) return base.map((x) => (x == null ? void 0 : x[sub]) ?? "").join("\n");
65
+ if (Array.isArray(base)) return base.join("\n");
66
+ return asText(base);
67
+ }
68
+ const v = ov[path];
69
+ if (Array.isArray(v)) return v.join("\n");
70
+ return asText(v);
71
+ }
72
+ function setFieldText(part, locale, path, text, sub) {
73
+ if (locale === DEFAULT_LOCALE) {
74
+ const base2 = getByPath(part, path);
75
+ if (sub && Array.isArray(base2)) {
76
+ const lines = String(text).split("\n");
77
+ base2.forEach((x, i) => {
78
+ x[sub] = lines[i] === void 0 ? x[sub] : lines[i];
79
+ });
80
+ } else if (Array.isArray(base2) || path === "view.tabs" || path === "view.contents") {
81
+ setByPath(part, path, String(text).split("\n"));
82
+ } else {
83
+ setByPath(part, path, text);
84
+ }
85
+ return;
86
+ }
87
+ if (!part.i18n) part.i18n = {};
88
+ if (!part.i18n[locale]) part.i18n[locale] = {};
89
+ const base = getByPath(part, path);
90
+ const bucket = part.i18n[locale];
91
+ if (sub && Array.isArray(base)) {
92
+ const lines = String(text).split("\n");
93
+ bucket[path] = base.map((x, i) => ({
94
+ [sub]: lines[i] === void 0 ? (x == null ? void 0 : x[sub]) ?? "" : lines[i]
95
+ }));
96
+ } else if (Array.isArray(base)) {
97
+ bucket[path] = String(text).split("\n");
98
+ } else {
99
+ bucket[path] = text;
100
+ }
101
+ }
102
+ function localizePart(part, locale) {
103
+ var _a;
104
+ if (!part || locale === DEFAULT_LOCALE || !((_a = part.i18n) == null ? void 0 : _a[locale])) return part;
105
+ const copy = JSON.parse(JSON.stringify(part));
106
+ const ov = part.i18n[locale];
107
+ Object.keys(ov).forEach((path) => {
108
+ setByPath(copy, path, JSON.parse(JSON.stringify(ov[path])));
109
+ });
110
+ return copy;
111
+ }
112
+ function translatedCount(part, locale) {
113
+ var _a;
114
+ if (locale === DEFAULT_LOCALE || !((_a = part.i18n) == null ? void 0 : _a[locale])) return 0;
115
+ const bucket = part.i18n[locale];
116
+ return Object.keys(bucket).filter((k) => {
117
+ const v = bucket[k];
118
+ return Array.isArray(v) ? v.length > 0 : !!v;
119
+ }).length;
120
+ }
121
+ export {
122
+ DEFAULT_LOCALE,
123
+ LOCALES,
124
+ TRANSLATABLE,
125
+ fieldText,
126
+ localizePart,
127
+ setFieldText,
128
+ translatableFields,
129
+ translatedCount
130
+ };
@@ -0,0 +1,137 @@
1
+ function parseOptions(src) {
2
+ if (!src || typeof src !== "string") return [];
3
+ const out = [];
4
+ src.split(/[,,;\n\r]+/).forEach((t) => {
5
+ const v = t.trim();
6
+ if (v && out.indexOf(v) < 0) out.push(v);
7
+ });
8
+ return out;
9
+ }
10
+ function valueSourceReference(src) {
11
+ const opts = parseOptions(src);
12
+ return opts.length === 1 ? opts[0] : "";
13
+ }
14
+ function effectiveFilterFor(view, declared) {
15
+ const v = view ?? {};
16
+ const code = String(v.paramCode ?? "");
17
+ const ownOpts = parseOptions(v.options);
18
+ const declaredOpts = declared ? parseOptions(declared.valueSource) : [];
19
+ const type = v.paramType || (declared == null ? void 0 : declared.paramType) || (ownOpts.length ? "select" : "input");
20
+ const options = ownOpts.length ? ownOpts : declaredOpts;
21
+ return {
22
+ code,
23
+ declared,
24
+ type,
25
+ options,
26
+ typeOverridden: !!(v.paramType && declared),
27
+ optionsOverridden: ownOpts.length > 0,
28
+ optionsMismatch: !!(declared && ownOpts.length && declaredOpts.length && ownOpts.join("") !== declaredOpts.join("")),
29
+ typeMismatch: !!(declared && v.paramType && v.paramType !== declared.paramType),
30
+ reference: declared ? declaredOpts.length ? "" : valueSourceReference(declared.valueSource) : "",
31
+ undeclared: !!code && !declared
32
+ };
33
+ }
34
+ function createParamCatalog(options = {}) {
35
+ const state = { byCode: {}, loadedKey: "", loading: false, version: 0 };
36
+ const listeners = /* @__PURE__ */ new Set();
37
+ const emit = () => {
38
+ listeners.forEach((fn) => {
39
+ try {
40
+ fn(state);
41
+ } catch (e) {
42
+ console.error("[design-board] 参数目录订阅回调异常", e);
43
+ }
44
+ });
45
+ };
46
+ const catalog = {
47
+ state,
48
+ async load(setIds) {
49
+ const ids = Array.from(
50
+ new Set((setIds ?? []).filter(Boolean))
51
+ ).map((x) => String(x)).sort();
52
+ const key = ids.join(",");
53
+ if (state.loadedKey === key) return state;
54
+ state.loading = true;
55
+ state.version += 1;
56
+ emit();
57
+ try {
58
+ let list = [];
59
+ if (ids.length && options.fetchParams) {
60
+ const res = await options.fetchParams(key);
61
+ list = res ?? [];
62
+ }
63
+ const byCode = {};
64
+ list.forEach((p) => {
65
+ const code = p == null ? void 0 : p.paramCode;
66
+ if (!code) return;
67
+ if (!byCode[code]) {
68
+ byCode[code] = {
69
+ paramCode: code,
70
+ paramName: p.paramName || code,
71
+ paramType: p.paramType || "input",
72
+ defaultValue: p.defaultValue || "",
73
+ valueSource: p.valueSource || "",
74
+ sets: []
75
+ };
76
+ }
77
+ const d = byCode[code];
78
+ if (p.setId !== void 0 && p.setId !== null && d.sets.indexOf(p.setId) < 0) {
79
+ d.sets.push(p.setId);
80
+ }
81
+ if (!d.paramType) d.paramType = p.paramType;
82
+ if (!d.defaultValue && p.defaultValue) d.defaultValue = p.defaultValue;
83
+ if (!d.valueSource && p.valueSource) d.valueSource = p.valueSource;
84
+ });
85
+ state.byCode = byCode;
86
+ state.loadedKey = key;
87
+ } catch (e) {
88
+ state.byCode = {};
89
+ state.loadedKey = key;
90
+ } finally {
91
+ state.loading = false;
92
+ state.version += 1;
93
+ emit();
94
+ }
95
+ return state;
96
+ },
97
+ reset() {
98
+ state.byCode = {};
99
+ state.loadedKey = "";
100
+ state.version += 1;
101
+ emit();
102
+ },
103
+ declared(code) {
104
+ return code ? state.byCode[code] ?? null : null;
105
+ },
106
+ list() {
107
+ return Object.keys(state.byCode).sort().map((k) => state.byCode[k]);
108
+ },
109
+ effectiveFilter(view) {
110
+ const code = String((view == null ? void 0 : view.paramCode) ?? "");
111
+ return effectiveFilterFor(view, code ? state.byCode[code] ?? null : null);
112
+ },
113
+ subscribe(listener) {
114
+ listeners.add(listener);
115
+ return () => listeners.delete(listener);
116
+ }
117
+ };
118
+ return catalog;
119
+ }
120
+ const defaultParamCatalog = createParamCatalog();
121
+ const loadParamCatalog = (setIds) => defaultParamCatalog.load(setIds);
122
+ const resetParamCatalog = () => defaultParamCatalog.reset();
123
+ const declaredParam = (code) => defaultParamCatalog.declared(code);
124
+ const catalogList = () => defaultParamCatalog.list();
125
+ const effectiveFilter = (view) => defaultParamCatalog.effectiveFilter(view);
126
+ export {
127
+ catalogList,
128
+ createParamCatalog,
129
+ declaredParam,
130
+ defaultParamCatalog,
131
+ effectiveFilter,
132
+ effectiveFilterFor,
133
+ loadParamCatalog,
134
+ parseOptions,
135
+ resetParamCatalog,
136
+ valueSourceReference
137
+ };
@@ -0,0 +1,61 @@
1
+ function toParamValue(value) {
2
+ if (value === null || value === void 0) return "";
3
+ return String(value);
4
+ }
5
+ function createBoardParams(initial) {
6
+ const state = { values: {}, version: 0 };
7
+ if (initial) {
8
+ Object.keys(initial).forEach((k) => {
9
+ state.values[k] = toParamValue(initial[k]);
10
+ });
11
+ }
12
+ const listeners = /* @__PURE__ */ new Set();
13
+ const emit = () => {
14
+ listeners.forEach((fn) => {
15
+ try {
16
+ fn(state);
17
+ } catch (e) {
18
+ console.error("[design-board] 参数订阅回调异常", e);
19
+ }
20
+ });
21
+ };
22
+ return {
23
+ state,
24
+ set(code, value) {
25
+ if (!code) return;
26
+ const next = toParamValue(value);
27
+ if (state.values[code] === next) return;
28
+ state.values[code] = next;
29
+ state.version += 1;
30
+ emit();
31
+ },
32
+ get(code) {
33
+ return state.values[code];
34
+ },
35
+ all() {
36
+ return { ...state.values };
37
+ },
38
+ reset() {
39
+ state.values = {};
40
+ state.version += 1;
41
+ emit();
42
+ },
43
+ subscribe(listener) {
44
+ listeners.add(listener);
45
+ return () => listeners.delete(listener);
46
+ }
47
+ };
48
+ }
49
+ const defaultBoardParams = createBoardParams();
50
+ const setParam = (code, value) => defaultBoardParams.set(code, value);
51
+ const getParam = (code) => defaultBoardParams.get(code);
52
+ const allParams = () => defaultBoardParams.all();
53
+ const resetParams = () => defaultBoardParams.reset();
54
+ export {
55
+ allParams,
56
+ createBoardParams,
57
+ defaultBoardParams,
58
+ getParam,
59
+ resetParams,
60
+ setParam
61
+ };
@@ -0,0 +1,65 @@
1
+ import { childLayoutOf, paddingOf, isContainer, CARD_TYPES, gridPartStyle, stackPartStyle, partStyle, titleReserveOf, titleInsetOf, titleOffsetOf, titleStyleOf, decorOf, canHostChildren, borderPresetOf, partVisualStyle } from "./schema.js";
2
+ function resolveLayout(page, override) {
3
+ if (override) return override;
4
+ return (page == null ? void 0 : page.layoutMode) === "grid" ? "grid" : "free";
5
+ }
6
+ function partRenderModel(part, page, options = {}) {
7
+ const layout = resolveLayout(page, options.layout);
8
+ const container = isContainer(part.type);
9
+ const card = CARD_TYPES.indexOf(part.type) >= 0;
10
+ let outerStyle;
11
+ if (layout === "grid") outerStyle = gridPartStyle(part, page);
12
+ else if (layout === "stack") outerStyle = stackPartStyle(part, options.childCount ?? 0);
13
+ else outerStyle = partStyle(part);
14
+ const view = part.view ?? {};
15
+ const hasTitle = !!view.showTitle && view.title !== void 0;
16
+ const title = hasTitle ? {
17
+ style: titleStyleOf(part),
18
+ text: String(view.title ?? ""),
19
+ offset: titleOffsetOf(part),
20
+ inset: titleInsetOf(part),
21
+ reserve: titleReserveOf(part)
22
+ } : null;
23
+ const decor = decorOf(part) ?? {};
24
+ const classes = ["drb-part", `drb-part--${part.type}`];
25
+ if (container) classes.push("drb-part--container");
26
+ if (card) classes.push("drb-part--card");
27
+ classes.push(`drb-layout--${layout}`);
28
+ return {
29
+ id: String(part.id ?? ""),
30
+ type: String(part.type ?? ""),
31
+ layout,
32
+ isContainer: container,
33
+ isCard: card,
34
+ outerStyle,
35
+ panelStyle: partVisualStyle(part),
36
+ pad: paddingOf(part),
37
+ title,
38
+ decor: {
39
+ border: view.datavBorder,
40
+ decoration: view.datavDecoration,
41
+ borderPreset: String(borderPresetOf(part) ?? "none"),
42
+ corner: !!decor.corner,
43
+ glass: !!decor.glass
44
+ },
45
+ childLayout: String(childLayoutOf(part) ?? "free"),
46
+ canHostChildren: !!canHostChildren(part),
47
+ classes
48
+ };
49
+ }
50
+ function containerChildrenStyle(part, page, innerWidth) {
51
+ const layout = String(childLayoutOf(part) ?? "free");
52
+ if (layout !== "grid") return {};
53
+ return {
54
+ display: "grid",
55
+ padding: `${paddingOf(part)}px`,
56
+ boxSizing: "border-box",
57
+ gap: `${(page == null ? void 0 : page.gridGap) ?? 12}px`,
58
+ ...innerWidth ? { width: `${innerWidth}px` } : {}
59
+ };
60
+ }
61
+ export {
62
+ containerChildrenStyle,
63
+ partRenderModel,
64
+ resolveLayout
65
+ };