@gct-paas/schema 0.1.4-dev.11 → 0.1.4-dev.12

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.
@@ -1,155 +1,231 @@
1
- import { isEmpty, pick, isNil } from 'lodash-es';
2
-
1
+ import { isEmpty, isNil, pick } from "lodash-es";
2
+ //#region src/utils/schema-style/index.ts
3
+ /**
4
+ * 样式计算工具类
5
+ * 提供样式单位转换、属性映射、样式属性处理等公共方法
6
+ */
7
+ /**
8
+ * 将像素值转换为对应单位
9
+ * 在移动环境下转换为 vw,其他环境保持 px
10
+ *
11
+ * @param pxValue - 像素值
12
+ * @returns 转换后的单位值字符串
13
+ */
3
14
  function pxToVw(pxValue) {
4
- return pxValue + "px";
15
+ return pxValue + "px";
5
16
  }
17
+ /**
18
+ * 添加 px 单位到样式值
19
+ *
20
+ * @param value - 样式值
21
+ * @returns 带 px 单位和 !important 的样式字符串
22
+ */
6
23
  function addPxUnit(value) {
7
- return isEmpty(value) ? "" : `${value}px !important`;
24
+ return isEmpty(value) ? "" : `${value}px !important`;
8
25
  }
26
+ /**
27
+ * 添加 !important 标志到样式值(不添加单位)
28
+ *
29
+ * @param value - 样式值
30
+ * @returns 带 !important 的样式字符串
31
+ */
9
32
  function addImportant(value) {
10
- return isEmpty(value) ? "" : `${value} !important`;
33
+ return isEmpty(value) ? "" : `${value} !important`;
11
34
  }
35
+ /**
36
+ * 格式化边框样式对象
37
+ *
38
+ * @param border - 边框配置对象,包含 borderWidth、borderStyle、borderColor
39
+ * @returns 格式化后的边框样式字符串
40
+ */
12
41
  function formatBorder(border) {
13
- if (!border || isEmpty(border.borderWidth)) return "";
14
- return `${border.borderWidth}px ${border.borderStyle || "solid"} ${border.borderColor || "transparent"} !important`;
42
+ if (!border || isEmpty(border.borderWidth)) return "";
43
+ return `${border.borderWidth}px ${border.borderStyle || "solid"} ${border.borderColor || "transparent"} !important`;
15
44
  }
16
- const DEFAULT_FONT_CONFIG = {
17
- fontAttrs: [
18
- "fontWeight",
19
- "fontSize",
20
- "color",
21
- "textDecorationLine",
22
- "textAlign"
23
- ],
24
- mapAttrs: {
25
- bold: {
26
- attr: "fontWeight",
27
- callback: (value) => {
28
- return value ? 700 : 400;
29
- }
30
- },
31
- italic: {
32
- attr: "fontStyle",
33
- callback: (value) => {
34
- return value ? "italic" : "normal";
35
- }
36
- },
37
- textDecoration: {
38
- attr: "textDecorationLine"
39
- },
40
- fontSize: {
41
- attr: "fontSize",
42
- callback: (value) => {
43
- return value ? pxToVw(value) : "";
44
- }
45
- },
46
- align: {
47
- attr: "textAlign"
48
- }
49
- }
45
+ /**
46
+ * 字体样式处理默认配置
47
+ */
48
+ var DEFAULT_FONT_CONFIG = {
49
+ fontAttrs: [
50
+ "fontWeight",
51
+ "fontSize",
52
+ "color",
53
+ "textDecorationLine",
54
+ "textAlign"
55
+ ],
56
+ mapAttrs: {
57
+ bold: {
58
+ attr: "fontWeight",
59
+ callback: (value) => {
60
+ return value ? 700 : 400;
61
+ }
62
+ },
63
+ italic: {
64
+ attr: "fontStyle",
65
+ callback: (value) => {
66
+ return value ? "italic" : "normal";
67
+ }
68
+ },
69
+ textDecoration: { attr: "textDecorationLine" },
70
+ fontSize: {
71
+ attr: "fontSize",
72
+ callback: (value) => {
73
+ return value ? pxToVw(value) : "";
74
+ }
75
+ },
76
+ align: { attr: "textAlign" }
77
+ }
50
78
  };
79
+ /**
80
+ * 从字体配置对象中提取并转换字体样式
81
+ *
82
+ * @param font - 字体配置对象
83
+ * @param config - 字体样式处理配置(可选,使用默认配置)
84
+ * @returns 转换后的样式对象
85
+ */
51
86
  function extractFontStyle(font, config = DEFAULT_FONT_CONFIG) {
52
- if (!font) return {};
53
- const result = {};
54
- Object.assign(result, pick(font, config.fontAttrs));
55
- if (typeof config.mapAttrs === "object") {
56
- Object.keys(config.mapAttrs).forEach((k) => {
57
- const { attr, callback } = config.mapAttrs[k];
58
- result[attr] = typeof callback === "function" ? callback(font[k]) : font[k];
59
- });
60
- }
61
- return result;
87
+ if (!font) return {};
88
+ const result = {};
89
+ Object.assign(result, pick(font, config.fontAttrs));
90
+ if (typeof config.mapAttrs === "object") Object.keys(config.mapAttrs).forEach((k) => {
91
+ const { attr, callback } = config.mapAttrs[k];
92
+ result[attr] = typeof callback === "function" ? callback(font[k]) : font[k];
93
+ });
94
+ return result;
62
95
  }
96
+ /**
97
+ * 将样式属性对象转换为 CSS 样式字符串格式
98
+ *
99
+ * @param styleProps - 样式属性对象
100
+ * @returns 转换后的样式对象(含单位和 !important)
101
+ */
63
102
  function propsToStyle(styleProps = {}) {
64
- const wStyle = {};
65
- for (const prop in styleProps) {
66
- wStyle[prop] = makeStyleProp(prop, styleProps[prop]);
67
- }
68
- return wStyle;
103
+ const wStyle = {};
104
+ for (const prop in styleProps) wStyle[prop] = makeStyleProp(prop, styleProps[prop]);
105
+ return wStyle;
69
106
  }
70
- const NOT_NEED_PX_STYLE = [
71
- "opacity",
72
- "zIndex",
73
- "fontWeight",
74
- "lineHeight",
75
- "letterSpacing",
76
- "wordSpacing",
77
- "textAlign",
78
- "textDecoration",
79
- "textTransform",
80
- "fontStyle",
81
- "textDecorationLine"
107
+ /**
108
+ * 不需要添加 px 单位的 CSS 属性列表
109
+ */
110
+ var NOT_NEED_PX_STYLE = [
111
+ "opacity",
112
+ "zIndex",
113
+ "fontWeight",
114
+ "lineHeight",
115
+ "letterSpacing",
116
+ "wordSpacing",
117
+ "textAlign",
118
+ "textDecoration",
119
+ "textTransform",
120
+ "fontStyle",
121
+ "textDecorationLine"
82
122
  ];
123
+ /**
124
+ * 将单个样式属性值转换为带单位的 CSS 字符串
125
+ *
126
+ * @param prop - 属性名
127
+ * @param value - 属性值
128
+ * @returns 转换后的样式值字符串
129
+ */
83
130
  function makeStyleProp(prop, value) {
84
- if (isNil(value) || isEmpty(value)) {
85
- return "";
86
- }
87
- if (NOT_NEED_PX_STYLE.includes(prop)) {
88
- return value + " !important";
89
- }
90
- return value + "px !important";
131
+ if (isNil(value) || isEmpty(value)) return "";
132
+ if (NOT_NEED_PX_STYLE.includes(prop)) return value + " !important";
133
+ return value + "px !important";
91
134
  }
92
- const ALIGN_TO_FLEX_MAP = {
93
- left: "flex-start",
94
- center: "center",
95
- right: "flex-end",
96
- justify: "space-between"
135
+ /**
136
+ * 对齐方式到 Flex 对齐值的映射
137
+ */
138
+ var ALIGN_TO_FLEX_MAP = {
139
+ left: "flex-start",
140
+ center: "center",
141
+ right: "flex-end",
142
+ justify: "space-between"
97
143
  };
144
+ /**
145
+ * 将对齐属性值转换为 Flex 对齐值
146
+ *
147
+ * @param align - 对齐方式(left、center、right、justify)
148
+ * @returns 对应的 Flex 对齐值
149
+ */
98
150
  function transAlign2flex(align) {
99
- return ALIGN_TO_FLEX_MAP[align] || align;
151
+ return ALIGN_TO_FLEX_MAP[align] || align;
100
152
  }
153
+ /**
154
+ * 生成位置和尺寸样式对象
155
+ *
156
+ * @param style - 样式配置对象
157
+ * @returns 位置和尺寸样式对象
158
+ */
101
159
  function generatePositionStyles(style) {
102
- return {
103
- position: addImportant(style.position),
104
- top: addPxUnit(style.top),
105
- left: addPxUnit(style.left),
106
- right: addPxUnit(style.right),
107
- bottom: addPxUnit(style.bottom),
108
- width: addPxUnit(style.width),
109
- height: addPxUnit(style.height)
110
- };
160
+ return {
161
+ position: addImportant(style.position),
162
+ top: addPxUnit(style.top),
163
+ left: addPxUnit(style.left),
164
+ right: addPxUnit(style.right),
165
+ bottom: addPxUnit(style.bottom),
166
+ width: addPxUnit(style.width),
167
+ height: addPxUnit(style.height)
168
+ };
111
169
  }
170
+ /**
171
+ * 生成背景和间距样式对象
172
+ *
173
+ * @param style - 样式配置对象
174
+ * @returns 背景和间距样式对象
175
+ */
112
176
  function generateSpacingStyles(style) {
113
- return {
114
- backgroundColor: addImportant(style.backgroundColor),
115
- marginTop: addPxUnit(style.marginTop),
116
- marginRight: addPxUnit(style.marginRight),
117
- marginBottom: addPxUnit(style.marginBottom),
118
- marginLeft: addPxUnit(style.marginLeft),
119
- paddingTop: addPxUnit(style.paddingTop),
120
- paddingRight: addPxUnit(style.paddingRight),
121
- paddingBottom: addPxUnit(style.paddingBottom),
122
- paddingLeft: addPxUnit(style.paddingLeft)
123
- };
177
+ return {
178
+ backgroundColor: addImportant(style.backgroundColor),
179
+ marginTop: addPxUnit(style.marginTop),
180
+ marginRight: addPxUnit(style.marginRight),
181
+ marginBottom: addPxUnit(style.marginBottom),
182
+ marginLeft: addPxUnit(style.marginLeft),
183
+ paddingTop: addPxUnit(style.paddingTop),
184
+ paddingRight: addPxUnit(style.paddingRight),
185
+ paddingBottom: addPxUnit(style.paddingBottom),
186
+ paddingLeft: addPxUnit(style.paddingLeft)
187
+ };
124
188
  }
189
+ /**
190
+ * 生成边框样式对象
191
+ *
192
+ * @param style - 样式配置对象
193
+ * @returns 边框样式对象
194
+ */
125
195
  function generateBorderStyles(style) {
126
- return {
127
- borderLeft: formatBorder(style.borderLeft),
128
- borderRight: formatBorder(style.borderRight),
129
- borderBottom: formatBorder(style.borderBottom),
130
- borderTop: formatBorder(style.borderTop),
131
- borderTopRightRadius: addPxUnit(style.borderTopRightRadius),
132
- borderTopLeftRadius: addPxUnit(style.borderTopLeftRadius),
133
- borderBottomRightRadius: addPxUnit(style.borderBottomRightRadius),
134
- borderBottomLeftRadius: addPxUnit(style.borderBottomLeftRadius)
135
- };
196
+ return {
197
+ borderLeft: formatBorder(style.borderLeft),
198
+ borderRight: formatBorder(style.borderRight),
199
+ borderBottom: formatBorder(style.borderBottom),
200
+ borderTop: formatBorder(style.borderTop),
201
+ borderTopRightRadius: addPxUnit(style.borderTopRightRadius),
202
+ borderTopLeftRadius: addPxUnit(style.borderTopLeftRadius),
203
+ borderBottomRightRadius: addPxUnit(style.borderBottomRightRadius),
204
+ borderBottomLeftRadius: addPxUnit(style.borderBottomLeftRadius)
205
+ };
136
206
  }
207
+ /**
208
+ * 生成完整的包装样式对象
209
+ * 合并位置、间距、边框等所有样式
210
+ *
211
+ * @param style - 样式配置对象
212
+ * @param ignoringStyle - 需要忽略的样式属性数组
213
+ * @returns 合并后的完整样式对象
214
+ */
137
215
  function generateWrapperStyle(style, ignoringStyle = []) {
138
- const styleData = {
139
- ...generatePositionStyles(style),
140
- ...generateSpacingStyles(style),
141
- ...generateBorderStyles(style)
142
- };
143
- ignoringStyle.forEach((key) => {
144
- delete styleData[key];
145
- });
146
- Object.keys(styleData).forEach((key) => {
147
- const val = styleData[key];
148
- if (isNil(val) || isEmpty(val)) {
149
- delete styleData[key];
150
- }
151
- });
152
- return styleData;
216
+ const styleData = {
217
+ ...generatePositionStyles(style),
218
+ ...generateSpacingStyles(style),
219
+ ...generateBorderStyles(style)
220
+ };
221
+ ignoringStyle.forEach((key) => {
222
+ delete styleData[key];
223
+ });
224
+ Object.keys(styleData).forEach((key) => {
225
+ const val = styleData[key];
226
+ if (isNil(val) || isEmpty(val)) delete styleData[key];
227
+ });
228
+ return styleData;
153
229
  }
154
-
230
+ //#endregion
155
231
  export { ALIGN_TO_FLEX_MAP, addImportant, addPxUnit, extractFontStyle, formatBorder, generateBorderStyles, generatePositionStyles, generateSpacingStyles, generateWrapperStyle, makeStyleProp, propsToStyle, pxToVw, transAlign2flex };
@@ -1,76 +1,149 @@
1
- import { Platform } from '@gct-paas/core';
2
-
3
- class WidgetInfo {
4
- events = {};
5
- propEditors = {};
6
- schema = {};
7
- callback = {};
8
- beforeCreate = {};
9
- styleEditors = {};
10
- designerConfig = {};
11
- hooks = {};
12
- whiteList = {};
13
- blackList = {};
14
- }
15
- const webWidgetInfo = new WidgetInfo();
16
- const mobileWidgetInfo = new WidgetInfo();
17
- const padWidgetInfo = new WidgetInfo();
1
+ import { Platform } from "@gct-paas/core";
2
+ //#region src/utils/widget-info/widget-info.ts
3
+ /**
4
+ * 设计界面所有组件配置信息
5
+ *
6
+ * @export
7
+ * @class WidgetInfo
8
+ * @implements {IWidgetInfo}
9
+ */
10
+ var WidgetInfo = class {
11
+ events = {};
12
+ propEditors = {};
13
+ schema = {};
14
+ callback = {};
15
+ beforeCreate = {};
16
+ styleEditors = {};
17
+ designerConfig = {};
18
+ hooks = {};
19
+ whiteList = {};
20
+ blackList = {};
21
+ };
22
+ /**
23
+ * 网页端组件配置信息
24
+ */
25
+ var webWidgetInfo = new WidgetInfo();
26
+ /**
27
+ * 移动端组件配置信息
28
+ */
29
+ var mobileWidgetInfo = new WidgetInfo();
30
+ /**
31
+ * 平板端组件配置信息
32
+ */
33
+ var padWidgetInfo = new WidgetInfo();
34
+ /**
35
+ * 获取指定平台的组件配置信息
36
+ *
37
+ * @export
38
+ * @param {Platform} [platform] 平台类型
39
+ * @return {*} {IWidgetInfo} 组件配置信息
40
+ */
18
41
  function getWidgetInfo(platform) {
19
- switch (platform) {
20
- case Platform.WEB:
21
- return webWidgetInfo;
22
- case Platform.MOBILE:
23
- return mobileWidgetInfo;
24
- case Platform.PAD:
25
- return padWidgetInfo;
26
- default:
27
- return webWidgetInfo;
28
- }
42
+ switch (platform) {
43
+ case Platform.WEB: return webWidgetInfo;
44
+ case Platform.MOBILE: return mobileWidgetInfo;
45
+ case Platform.PAD: return padWidgetInfo;
46
+ default: return webWidgetInfo;
47
+ }
29
48
  }
49
+ /**
50
+ * 注册单一组件信息
51
+ *
52
+ * @export
53
+ * @param {IWidgetInfo} widgetInfo
54
+ * @param {string} type
55
+ * @param {IObject} module
56
+ */
30
57
  function registerWidgetItem(widgetInfo, type, module) {
31
- widgetInfo.events[type] = module.eventList;
32
- widgetInfo.hooks[type] = module.hooks;
33
- widgetInfo.whiteList[type] = module.whiteList;
34
- widgetInfo.blackList[type] = module.blackList;
35
- widgetInfo.propEditors[type] = module.propEditorList;
36
- widgetInfo.schema[type] = module.widget;
37
- widgetInfo.callback[type] = module.runCallback;
38
- widgetInfo.beforeCreate[type] = module.beforeCreate;
39
- widgetInfo.styleEditors[type] = module.styleEditorList;
40
- widgetInfo.designerConfig[type] = module.designerConfig;
58
+ widgetInfo.events[type] = module.eventList;
59
+ widgetInfo.hooks[type] = module.hooks;
60
+ widgetInfo.whiteList[type] = module.whiteList;
61
+ widgetInfo.blackList[type] = module.blackList;
62
+ widgetInfo.propEditors[type] = module.propEditorList;
63
+ widgetInfo.schema[type] = module.widget;
64
+ widgetInfo.callback[type] = module.runCallback;
65
+ widgetInfo.beforeCreate[type] = module.beforeCreate;
66
+ widgetInfo.styleEditors[type] = module.styleEditorList;
67
+ widgetInfo.designerConfig[type] = module.designerConfig;
41
68
  }
69
+ /**
70
+ * 注册网页端单一组件信息
71
+ *
72
+ * @export
73
+ * @param {IObject} module
74
+ * @param {string} type
75
+ */
42
76
  function registerWebWidgetItem(module, type) {
43
- registerWidgetItem(webWidgetInfo, type, module);
77
+ registerWidgetItem(webWidgetInfo, type, module);
44
78
  }
79
+ /**
80
+ * 注册移动端单一组件信息
81
+ *
82
+ * @export
83
+ * @param {IObject} module
84
+ * @param {string} type
85
+ */
45
86
  function registerMobileWidgetItem(module, type) {
46
- registerWidgetItem(mobileWidgetInfo, type, module);
87
+ registerWidgetItem(mobileWidgetInfo, type, module);
47
88
  }
89
+ /**
90
+ * 注册平板端单一组件信息
91
+ *
92
+ * @export
93
+ * @param {IObject} module
94
+ * @param {string} type
95
+ */
48
96
  function registerPadWidgetItem(module, type) {
49
- registerWidgetItem(padWidgetInfo, type, module);
97
+ registerWidgetItem(padWidgetInfo, type, module);
50
98
  }
99
+ /**
100
+ * 注册单一组件信息(插件方式)
101
+ *
102
+ * @export
103
+ * @param {IWidgetInfo} widgetInfo
104
+ * @param {IWidgetInfoItem} designer
105
+ */
51
106
  function registerPluginWidgetItem(widgetInfo, designer) {
52
- if (designer) {
53
- const { type } = designer.schema;
54
- widgetInfo.events[type] = designer.events;
55
- widgetInfo.hooks[type] = designer.hooks;
56
- widgetInfo.whiteList[type] = designer.whiteList;
57
- widgetInfo.blackList[type] = designer.blackList;
58
- widgetInfo.propEditors[type] = designer.propEditors;
59
- widgetInfo.schema[type] = designer.schema;
60
- widgetInfo.callback[type] = designer.callback;
61
- widgetInfo.beforeCreate[type] = designer.beforeCreate;
62
- widgetInfo.styleEditors[type] = designer.styleEditors;
63
- widgetInfo.designerConfig[type] = designer.designerConfig;
64
- }
107
+ if (designer) {
108
+ const { type } = designer.schema;
109
+ widgetInfo.events[type] = designer.events;
110
+ widgetInfo.hooks[type] = designer.hooks;
111
+ widgetInfo.whiteList[type] = designer.whiteList;
112
+ widgetInfo.blackList[type] = designer.blackList;
113
+ widgetInfo.propEditors[type] = designer.propEditors;
114
+ widgetInfo.schema[type] = designer.schema;
115
+ widgetInfo.callback[type] = designer.callback;
116
+ widgetInfo.beforeCreate[type] = designer.beforeCreate;
117
+ widgetInfo.styleEditors[type] = designer.styleEditors;
118
+ widgetInfo.designerConfig[type] = designer.designerConfig;
119
+ }
65
120
  }
121
+ /**
122
+ * 注册网页端插件组件配置
123
+ *
124
+ * @export
125
+ * @param {IWidgetInfoItem} designer
126
+ */
66
127
  function registerWebPluginWidgetItem(designer) {
67
- registerPluginWidgetItem(webWidgetInfo, designer);
128
+ registerPluginWidgetItem(webWidgetInfo, designer);
68
129
  }
130
+ /**
131
+ * 注册移动端插件组件配置
132
+ *
133
+ * @export
134
+ * @param {IWidgetInfoItem} designer
135
+ */
69
136
  function registerMobilePluginWidgetItem(designer) {
70
- registerPluginWidgetItem(mobileWidgetInfo, designer);
137
+ registerPluginWidgetItem(mobileWidgetInfo, designer);
71
138
  }
139
+ /**
140
+ * 注册平板端插件组件配置
141
+ *
142
+ * @export
143
+ * @param {IWidgetInfoItem} designer
144
+ */
72
145
  function registerPadPluginWidgetItem(designer) {
73
- registerPluginWidgetItem(padWidgetInfo, designer);
146
+ registerPluginWidgetItem(padWidgetInfo, designer);
74
147
  }
75
-
148
+ //#endregion
76
149
  export { getWidgetInfo, mobileWidgetInfo, padWidgetInfo, registerMobilePluginWidgetItem, registerMobileWidgetItem, registerPadPluginWidgetItem, registerPadWidgetItem, registerPluginWidgetItem, registerWebPluginWidgetItem, registerWebWidgetItem, registerWidgetItem, webWidgetInfo };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gct-paas/schema",
3
- "version": "0.1.4-dev.11",
3
+ "version": "0.1.4-dev.12",
4
4
  "type": "module",
5
5
  "description": "paas 平台 schema 架构包",
6
6
  "main": "dist/index.min.cjs",
@@ -52,12 +52,13 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@gct-paas/api": "0.1.1",
55
- "@gct-paas/core": "0.1.4-dev.11",
55
+ "@gct-paas/core": "0.1.4-dev.12",
56
+ "lodash-es": "^4.17.23",
56
57
  "vue": "^3.5.29"
57
58
  },
58
59
  "devDependencies": {
59
- "@gct-paas/build": "^0.1.5-dev.9",
60
+ "@gct-paas/build": "^0.1.6-dev.1",
60
61
  "vitest": "^4.0.18"
61
62
  },
62
- "gitHead": "6b0fd87c1a7799aa228f40b160e53a7358c25186"
63
+ "gitHead": "0a7f1a0388cb21eb1c3a4868b14d664a5a3152ed"
63
64
  }