@tmagic/editor 1.8.0-beta.12 → 1.8.0-beta.13
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/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +13 -121
- package/dist/es/components/ViewForm.js +5 -0
- package/dist/es/components/ViewForm.vue_vue_type_script_setup_true_lang.js +58 -0
- package/dist/es/hooks/use-compare-form.js +119 -0
- package/dist/es/index.js +6 -4
- package/dist/es/services/codeBlock.js +1 -1
- package/dist/es/services/history.js +1 -1
- package/dist/es/services/props.js +1 -1
- package/dist/es/services/storage.js +1 -1
- package/dist/es/utils/props.js +26 -1
- package/dist/tmagic-editor.umd.cjs +618 -566
- package/package.json +7 -7
- package/src/components/CompareForm.vue +15 -202
- package/src/components/ViewForm.vue +55 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-compare-form.ts +187 -0
- package/src/index.ts +1 -0
- package/src/type.ts +52 -0
- package/src/utils/props.ts +29 -0
- package/types/index.d.ts +227 -169
|
@@ -5052,6 +5052,545 @@
|
|
|
5052
5052
|
};
|
|
5053
5053
|
};
|
|
5054
5054
|
//#endregion
|
|
5055
|
+
//#region packages/editor/src/utils/config.ts
|
|
5056
|
+
var $TMAGIC_EDITOR, setEditorConfig, getEditorConfig;
|
|
5057
|
+
var init_config = __esmMin((() => {
|
|
5058
|
+
$TMAGIC_EDITOR = {};
|
|
5059
|
+
setEditorConfig = (option) => {
|
|
5060
|
+
$TMAGIC_EDITOR = option;
|
|
5061
|
+
};
|
|
5062
|
+
getEditorConfig = (key) => $TMAGIC_EDITOR[key];
|
|
5063
|
+
}));
|
|
5064
|
+
//#endregion
|
|
5065
|
+
//#region packages/editor/src/utils/code-block.ts
|
|
5066
|
+
var defaultParamColConfig, getCodeBlockFormConfig;
|
|
5067
|
+
var init_code_block = __esmMin((() => {
|
|
5068
|
+
init_config();
|
|
5069
|
+
defaultParamColConfig = () => (0, _tmagic_form.defineFormItem)({
|
|
5070
|
+
type: "row",
|
|
5071
|
+
label: "参数类型",
|
|
5072
|
+
items: [{
|
|
5073
|
+
text: "参数类型",
|
|
5074
|
+
labelWidth: "70px",
|
|
5075
|
+
type: "select",
|
|
5076
|
+
name: "type",
|
|
5077
|
+
options: [
|
|
5078
|
+
{
|
|
5079
|
+
text: "数字",
|
|
5080
|
+
label: "数字",
|
|
5081
|
+
value: "number"
|
|
5082
|
+
},
|
|
5083
|
+
{
|
|
5084
|
+
text: "字符串",
|
|
5085
|
+
label: "字符串",
|
|
5086
|
+
value: "text"
|
|
5087
|
+
},
|
|
5088
|
+
{
|
|
5089
|
+
text: "组件",
|
|
5090
|
+
label: "组件",
|
|
5091
|
+
value: "ui-select"
|
|
5092
|
+
}
|
|
5093
|
+
]
|
|
5094
|
+
}]
|
|
5095
|
+
});
|
|
5096
|
+
getCodeBlockFormConfig = (options = {}) => {
|
|
5097
|
+
const { paramColConfig, isDataSource, dataSourceType, codeOptions = {}, editable = true } = options;
|
|
5098
|
+
return (0, _tmagic_form.defineFormConfig)([
|
|
5099
|
+
{
|
|
5100
|
+
text: "名称",
|
|
5101
|
+
name: "name",
|
|
5102
|
+
...editable ? { rules: [{
|
|
5103
|
+
required: true,
|
|
5104
|
+
message: "请输入名称",
|
|
5105
|
+
trigger: "blur"
|
|
5106
|
+
}] } : {}
|
|
5107
|
+
},
|
|
5108
|
+
{
|
|
5109
|
+
text: "描述",
|
|
5110
|
+
name: "desc"
|
|
5111
|
+
},
|
|
5112
|
+
{
|
|
5113
|
+
text: "执行时机",
|
|
5114
|
+
name: "timing",
|
|
5115
|
+
type: "select",
|
|
5116
|
+
options: () => {
|
|
5117
|
+
const list = [{
|
|
5118
|
+
text: "初始化前",
|
|
5119
|
+
value: "beforeInit"
|
|
5120
|
+
}, {
|
|
5121
|
+
text: "初始化后",
|
|
5122
|
+
value: "afterInit"
|
|
5123
|
+
}];
|
|
5124
|
+
if (dataSourceType?.() !== "base") {
|
|
5125
|
+
list.push({
|
|
5126
|
+
text: "请求前",
|
|
5127
|
+
value: "beforeRequest"
|
|
5128
|
+
});
|
|
5129
|
+
list.push({
|
|
5130
|
+
text: "请求后",
|
|
5131
|
+
value: "afterRequest"
|
|
5132
|
+
});
|
|
5133
|
+
}
|
|
5134
|
+
return list;
|
|
5135
|
+
},
|
|
5136
|
+
display: () => Boolean(isDataSource?.())
|
|
5137
|
+
},
|
|
5138
|
+
{
|
|
5139
|
+
type: "table",
|
|
5140
|
+
border: true,
|
|
5141
|
+
text: "参数",
|
|
5142
|
+
enableFullscreen: false,
|
|
5143
|
+
enableToggleMode: false,
|
|
5144
|
+
name: "params",
|
|
5145
|
+
dropSort: false,
|
|
5146
|
+
items: [
|
|
5147
|
+
{
|
|
5148
|
+
type: "text",
|
|
5149
|
+
label: "参数名",
|
|
5150
|
+
name: "name"
|
|
5151
|
+
},
|
|
5152
|
+
{
|
|
5153
|
+
type: "text",
|
|
5154
|
+
label: "描述",
|
|
5155
|
+
name: "extra"
|
|
5156
|
+
},
|
|
5157
|
+
paramColConfig || defaultParamColConfig()
|
|
5158
|
+
]
|
|
5159
|
+
},
|
|
5160
|
+
{
|
|
5161
|
+
name: "content",
|
|
5162
|
+
type: "vs-code",
|
|
5163
|
+
options: codeOptions,
|
|
5164
|
+
autosize: {
|
|
5165
|
+
minRows: 10,
|
|
5166
|
+
maxRows: 30
|
|
5167
|
+
},
|
|
5168
|
+
...editable ? { onChange: (_formState, code) => {
|
|
5169
|
+
try {
|
|
5170
|
+
getEditorConfig("parseDSL")(code);
|
|
5171
|
+
return code;
|
|
5172
|
+
} catch (error) {
|
|
5173
|
+
_tmagic_design.tMagicMessage.error(error.message);
|
|
5174
|
+
throw error;
|
|
5175
|
+
}
|
|
5176
|
+
} } : {}
|
|
5177
|
+
}
|
|
5178
|
+
]);
|
|
5179
|
+
};
|
|
5180
|
+
}));
|
|
5181
|
+
//#endregion
|
|
5182
|
+
//#region packages/editor/src/utils/props.ts
|
|
5183
|
+
var arrayOptions, eqOptions, numberOptions, booleanOptions, getCondOpOptionsByFieldType, styleTabConfig, eventTabConfig, advancedTabConfig, displayTabConfig, fillConfig, removeStyleDisplayConfig, validatePropsForm;
|
|
5184
|
+
var init_props = __esmMin((() => {
|
|
5185
|
+
arrayOptions = [{
|
|
5186
|
+
text: "包含",
|
|
5187
|
+
value: "include"
|
|
5188
|
+
}, {
|
|
5189
|
+
text: "不包含",
|
|
5190
|
+
value: "not_include"
|
|
5191
|
+
}];
|
|
5192
|
+
eqOptions = [{
|
|
5193
|
+
text: "等于",
|
|
5194
|
+
value: "="
|
|
5195
|
+
}, {
|
|
5196
|
+
text: "不等于",
|
|
5197
|
+
value: "!="
|
|
5198
|
+
}];
|
|
5199
|
+
numberOptions = [
|
|
5200
|
+
{
|
|
5201
|
+
text: "大于",
|
|
5202
|
+
value: ">"
|
|
5203
|
+
},
|
|
5204
|
+
{
|
|
5205
|
+
text: "大于等于",
|
|
5206
|
+
value: ">="
|
|
5207
|
+
},
|
|
5208
|
+
{
|
|
5209
|
+
text: "小于",
|
|
5210
|
+
value: "<"
|
|
5211
|
+
},
|
|
5212
|
+
{
|
|
5213
|
+
text: "小于等于",
|
|
5214
|
+
value: "<="
|
|
5215
|
+
},
|
|
5216
|
+
{
|
|
5217
|
+
text: "在范围内",
|
|
5218
|
+
value: "between"
|
|
5219
|
+
},
|
|
5220
|
+
{
|
|
5221
|
+
text: "不在范围内",
|
|
5222
|
+
value: "not_between"
|
|
5223
|
+
}
|
|
5224
|
+
];
|
|
5225
|
+
booleanOptions = [{
|
|
5226
|
+
text: "是",
|
|
5227
|
+
value: "is"
|
|
5228
|
+
}, {
|
|
5229
|
+
text: "不是",
|
|
5230
|
+
value: "not"
|
|
5231
|
+
}];
|
|
5232
|
+
getCondOpOptionsByFieldType = (type) => {
|
|
5233
|
+
if (type === "array") return arrayOptions;
|
|
5234
|
+
if (type === "boolean" || type === "null") return booleanOptions;
|
|
5235
|
+
if (type === "number") return [...eqOptions, ...numberOptions];
|
|
5236
|
+
if (type === "string") return [...arrayOptions, ...eqOptions];
|
|
5237
|
+
return [
|
|
5238
|
+
...arrayOptions,
|
|
5239
|
+
...eqOptions,
|
|
5240
|
+
...numberOptions
|
|
5241
|
+
];
|
|
5242
|
+
};
|
|
5243
|
+
styleTabConfig = {
|
|
5244
|
+
title: "样式",
|
|
5245
|
+
lazy: true,
|
|
5246
|
+
display: ({ services }) => !(services?.uiService?.get("showStylePanel") ?? true),
|
|
5247
|
+
items: [{
|
|
5248
|
+
name: "style",
|
|
5249
|
+
labelWidth: "100px",
|
|
5250
|
+
type: "style-setter",
|
|
5251
|
+
items: [{ names: [
|
|
5252
|
+
"display",
|
|
5253
|
+
"flexDirection",
|
|
5254
|
+
"justifyContent",
|
|
5255
|
+
"alignItems",
|
|
5256
|
+
"flexWrap",
|
|
5257
|
+
"marginTop",
|
|
5258
|
+
"marginRight",
|
|
5259
|
+
"marginBottom",
|
|
5260
|
+
"marginLeft",
|
|
5261
|
+
"paddingTop",
|
|
5262
|
+
"paddingRight",
|
|
5263
|
+
"paddingBottom",
|
|
5264
|
+
"paddingLeft",
|
|
5265
|
+
"width",
|
|
5266
|
+
"height",
|
|
5267
|
+
"overflow",
|
|
5268
|
+
"fontSize",
|
|
5269
|
+
"lineHeight",
|
|
5270
|
+
"fontWeight",
|
|
5271
|
+
"color",
|
|
5272
|
+
"textAlign",
|
|
5273
|
+
"backgroundColor",
|
|
5274
|
+
"backgroundImage",
|
|
5275
|
+
"backgroundSize",
|
|
5276
|
+
"backgroundPosition",
|
|
5277
|
+
"backgroundRepeat",
|
|
5278
|
+
"position",
|
|
5279
|
+
"zIndex",
|
|
5280
|
+
"top",
|
|
5281
|
+
"right",
|
|
5282
|
+
"bottom",
|
|
5283
|
+
"left",
|
|
5284
|
+
"borderRadius",
|
|
5285
|
+
"borderTopWidth",
|
|
5286
|
+
"borderTopStyle",
|
|
5287
|
+
"borderTopColor",
|
|
5288
|
+
"borderRightColor",
|
|
5289
|
+
"borderRightWidth",
|
|
5290
|
+
"borderRightStyle",
|
|
5291
|
+
"borderRightColor",
|
|
5292
|
+
"borderBottomWidth",
|
|
5293
|
+
"borderBottomStyle",
|
|
5294
|
+
"borderBottomColor",
|
|
5295
|
+
"borderLeftStyle",
|
|
5296
|
+
"borderLeftWidth",
|
|
5297
|
+
"borderLeftColor",
|
|
5298
|
+
"borderWidth",
|
|
5299
|
+
"borderStyle",
|
|
5300
|
+
"borderColor",
|
|
5301
|
+
"opacity"
|
|
5302
|
+
] }, {
|
|
5303
|
+
name: "transform",
|
|
5304
|
+
defaultValue: () => ({})
|
|
5305
|
+
}]
|
|
5306
|
+
}]
|
|
5307
|
+
};
|
|
5308
|
+
eventTabConfig = {
|
|
5309
|
+
title: "事件",
|
|
5310
|
+
lazy: true,
|
|
5311
|
+
items: [{
|
|
5312
|
+
name: "events",
|
|
5313
|
+
src: "component",
|
|
5314
|
+
labelWidth: "100px",
|
|
5315
|
+
type: "event-select",
|
|
5316
|
+
rules: [{ typeMatch: true }]
|
|
5317
|
+
}]
|
|
5318
|
+
};
|
|
5319
|
+
advancedTabConfig = {
|
|
5320
|
+
title: "高级",
|
|
5321
|
+
lazy: true,
|
|
5322
|
+
items: [
|
|
5323
|
+
{
|
|
5324
|
+
name: _tmagic_core.NODE_DISABLE_CODE_BLOCK_KEY,
|
|
5325
|
+
text: "禁用代码块",
|
|
5326
|
+
type: "switch",
|
|
5327
|
+
defaultValue: false,
|
|
5328
|
+
extra: "开启后,配置的代码块将不会被执行"
|
|
5329
|
+
},
|
|
5330
|
+
{
|
|
5331
|
+
name: _tmagic_core.NODE_DISABLE_DATA_SOURCE_KEY,
|
|
5332
|
+
text: "禁用数据源",
|
|
5333
|
+
type: "switch",
|
|
5334
|
+
defaultValue: false,
|
|
5335
|
+
extra: "开启后,组件内配置的数据源相关配置将不会被编译,显隐条件将失效"
|
|
5336
|
+
},
|
|
5337
|
+
{
|
|
5338
|
+
name: "created",
|
|
5339
|
+
text: "created",
|
|
5340
|
+
labelPosition: "top",
|
|
5341
|
+
type: "code-select",
|
|
5342
|
+
extra: "组件初始化时执行",
|
|
5343
|
+
rules: [{
|
|
5344
|
+
typeMatch: true,
|
|
5345
|
+
trigger: "change"
|
|
5346
|
+
}, { validator: ({ value, callback }) => {
|
|
5347
|
+
if (value && value.hookType !== _tmagic_core.HookType.CODE) return callback("hookType 必须是 code");
|
|
5348
|
+
callback();
|
|
5349
|
+
} }]
|
|
5350
|
+
},
|
|
5351
|
+
{
|
|
5352
|
+
name: "mounted",
|
|
5353
|
+
text: "mounted",
|
|
5354
|
+
labelPosition: "top",
|
|
5355
|
+
type: "code-select",
|
|
5356
|
+
extra: "组件挂载到dom时执行",
|
|
5357
|
+
rules: [{
|
|
5358
|
+
typeMatch: true,
|
|
5359
|
+
trigger: "change"
|
|
5360
|
+
}, { validator: ({ value, callback }) => {
|
|
5361
|
+
if (value && value.hookType !== _tmagic_core.HookType.CODE) return callback("hookType 必须是 code");
|
|
5362
|
+
callback();
|
|
5363
|
+
} }]
|
|
5364
|
+
},
|
|
5365
|
+
{
|
|
5366
|
+
name: "display",
|
|
5367
|
+
text: "display",
|
|
5368
|
+
extra: "控制组件是否渲染,关系的代码块返回值为false时不渲染",
|
|
5369
|
+
labelPosition: "top",
|
|
5370
|
+
type: "code-select",
|
|
5371
|
+
rules: [{
|
|
5372
|
+
typeMatch: true,
|
|
5373
|
+
trigger: "change"
|
|
5374
|
+
}, { validator: ({ value, callback }) => {
|
|
5375
|
+
if (value && value.hookType !== _tmagic_core.HookType.CODE) return callback("hookType 必须是 code");
|
|
5376
|
+
callback();
|
|
5377
|
+
} }]
|
|
5378
|
+
}
|
|
5379
|
+
]
|
|
5380
|
+
};
|
|
5381
|
+
displayTabConfig = {
|
|
5382
|
+
title: "显示条件",
|
|
5383
|
+
display: (_state, { model }) => model.type !== "page",
|
|
5384
|
+
items: [{
|
|
5385
|
+
name: _tmagic_core.NODE_CONDS_RESULT_KEY,
|
|
5386
|
+
type: "select",
|
|
5387
|
+
text: "条件成立时",
|
|
5388
|
+
defaultValue: false,
|
|
5389
|
+
options: [{
|
|
5390
|
+
text: "显示",
|
|
5391
|
+
value: false
|
|
5392
|
+
}, {
|
|
5393
|
+
text: "隐藏",
|
|
5394
|
+
value: true
|
|
5395
|
+
}],
|
|
5396
|
+
extra: (_state, { model }) => `条件成立时${model[_tmagic_core.NODE_CONDS_RESULT_KEY] ? "隐藏" : "显示"},不成立时${model[_tmagic_core.NODE_CONDS_RESULT_KEY] ? "显示" : "隐藏"};<br />同一条件组内的所有条件配置同时成立时表示该条件组成立,任意一个条件组成立时表示条件成立(条件组内为且的关系,条件组间为或的关系);<br />条件为空时表示成立;`
|
|
5397
|
+
}, {
|
|
5398
|
+
type: "display-conds",
|
|
5399
|
+
name: _tmagic_core.NODE_CONDS_KEY,
|
|
5400
|
+
titlePrefix: "条件组",
|
|
5401
|
+
defaultValue: [],
|
|
5402
|
+
rules: [{ typeMatch: true }]
|
|
5403
|
+
}]
|
|
5404
|
+
};
|
|
5405
|
+
fillConfig = (config = [], { labelWidth = "80px", disabledDataSource = false, disabledCodeBlock = false } = {}) => {
|
|
5406
|
+
const propsConfig = [];
|
|
5407
|
+
if (!config.find((item) => "name" in item && item.name === "type")) propsConfig.push({
|
|
5408
|
+
text: "type",
|
|
5409
|
+
name: "type",
|
|
5410
|
+
type: "hidden"
|
|
5411
|
+
});
|
|
5412
|
+
if (!config.find((item) => "name" in item && item.name === "id")) propsConfig.push({
|
|
5413
|
+
name: "id",
|
|
5414
|
+
text: "ID",
|
|
5415
|
+
type: "text",
|
|
5416
|
+
disabled: true,
|
|
5417
|
+
append: {
|
|
5418
|
+
type: "button",
|
|
5419
|
+
text: "复制",
|
|
5420
|
+
handler: (vm, { model }) => {
|
|
5421
|
+
navigator.clipboard.writeText(`${model.id}`).then(() => {
|
|
5422
|
+
_tmagic_design.tMagicMessage.success("已复制");
|
|
5423
|
+
}).catch(() => {
|
|
5424
|
+
_tmagic_design.tMagicMessage.error("复制失败");
|
|
5425
|
+
});
|
|
5426
|
+
}
|
|
5427
|
+
}
|
|
5428
|
+
});
|
|
5429
|
+
if (!config.find((item) => "name" in item && item.name === "name")) propsConfig.push({
|
|
5430
|
+
name: "name",
|
|
5431
|
+
text: "组件名称"
|
|
5432
|
+
});
|
|
5433
|
+
const noCodeAdvancedTabItems = advancedTabConfig.items.filter((item) => "type" in item && item.type !== "code-select");
|
|
5434
|
+
if (noCodeAdvancedTabItems.length > 0 && disabledCodeBlock) advancedTabConfig.items = noCodeAdvancedTabItems;
|
|
5435
|
+
const tabConfig = {
|
|
5436
|
+
type: "tab",
|
|
5437
|
+
labelWidth,
|
|
5438
|
+
items: [
|
|
5439
|
+
{
|
|
5440
|
+
title: "属性",
|
|
5441
|
+
items: [...propsConfig, ...config]
|
|
5442
|
+
},
|
|
5443
|
+
{ ...styleTabConfig },
|
|
5444
|
+
{ ...eventTabConfig }
|
|
5445
|
+
]
|
|
5446
|
+
};
|
|
5447
|
+
if (!disabledCodeBlock) tabConfig.items.push({ ...advancedTabConfig });
|
|
5448
|
+
else if (noCodeAdvancedTabItems.length > 0) tabConfig.items.push({ ...advancedTabConfig });
|
|
5449
|
+
if (!disabledDataSource) tabConfig.items.push({ ...displayTabConfig });
|
|
5450
|
+
return [tabConfig];
|
|
5451
|
+
};
|
|
5452
|
+
removeStyleDisplayConfig = (formConfig) => formConfig.map((item) => {
|
|
5453
|
+
if (!("type" in item)) return item;
|
|
5454
|
+
if (item?.type !== "tab" || !Array.isArray(item.items)) return item;
|
|
5455
|
+
return {
|
|
5456
|
+
...item,
|
|
5457
|
+
items: item.items.map((tabPane) => {
|
|
5458
|
+
if (tabPane?.title !== "样式" || !Array.isArray(tabPane.items)) return tabPane;
|
|
5459
|
+
return {
|
|
5460
|
+
...tabPane,
|
|
5461
|
+
display: true
|
|
5462
|
+
};
|
|
5463
|
+
})
|
|
5464
|
+
};
|
|
5465
|
+
});
|
|
5466
|
+
validatePropsForm = ({ config, values, appContext = null, services, stage, extendState, debug, typeMatchValid }) => (0, _tmagic_form.validateForm)({
|
|
5467
|
+
config,
|
|
5468
|
+
debug,
|
|
5469
|
+
typeMatchValid,
|
|
5470
|
+
initValues: values,
|
|
5471
|
+
appContext: appContext ? {
|
|
5472
|
+
...appContext,
|
|
5473
|
+
provides: { services }
|
|
5474
|
+
} : null,
|
|
5475
|
+
extendState: async (state) => ({
|
|
5476
|
+
...await extendState?.(state) || {},
|
|
5477
|
+
stage,
|
|
5478
|
+
services
|
|
5479
|
+
})
|
|
5480
|
+
});
|
|
5481
|
+
}));
|
|
5482
|
+
//#endregion
|
|
5483
|
+
//#region packages/editor/src/hooks/use-compare-form.ts
|
|
5484
|
+
var useCompareForm;
|
|
5485
|
+
var init_use_compare_form = __esmMin((() => {
|
|
5486
|
+
init_code_block();
|
|
5487
|
+
init_props();
|
|
5488
|
+
useCompareForm = (props) => {
|
|
5489
|
+
(0, vue.provide)("services", props.services);
|
|
5490
|
+
const config = (0, vue.ref)([]);
|
|
5491
|
+
/** vs-code 编辑器的 monaco 配置项,沿用 Editor 顶层 provide('codeOptions', ...) 的注入。 */
|
|
5492
|
+
const codeOptions = (0, vue.inject)("codeOptions", {});
|
|
5493
|
+
/** 将代码块的 content 字段统一成字符串,便于在表单 / 对比中展示 */
|
|
5494
|
+
const normalizeCodeBlockValue = (v) => {
|
|
5495
|
+
if (!v) return {};
|
|
5496
|
+
const next = { ...v };
|
|
5497
|
+
if (next.content && typeof next.content !== "string") try {
|
|
5498
|
+
next.content = next.content.toString();
|
|
5499
|
+
} catch {
|
|
5500
|
+
next.content = "";
|
|
5501
|
+
}
|
|
5502
|
+
return next;
|
|
5503
|
+
};
|
|
5504
|
+
const currentValues = (0, vue.computed)(() => {
|
|
5505
|
+
if (props.category === "code-block") return normalizeCodeBlockValue(props.value);
|
|
5506
|
+
return props.value || {};
|
|
5507
|
+
});
|
|
5508
|
+
/**
|
|
5509
|
+
* 外层包裹层的样式:当传入 `height` 时启用固定高度 + 内部滚动,
|
|
5510
|
+
* 这样滚动条会出现在组件内部,避免父容器(如 Dialog)自身也产生滚动。
|
|
5511
|
+
*/
|
|
5512
|
+
const wrapperStyle = (0, vue.computed)(() => {
|
|
5513
|
+
if (!props.height) return void 0;
|
|
5514
|
+
return {
|
|
5515
|
+
height: props.height,
|
|
5516
|
+
overflow: "auto"
|
|
5517
|
+
};
|
|
5518
|
+
});
|
|
5519
|
+
const mergedExtendState = (state) => {
|
|
5520
|
+
return (props.extendState ?? ((s) => s))(props.baseFormState || state);
|
|
5521
|
+
};
|
|
5522
|
+
/**
|
|
5523
|
+
* 内置的默认 FormConfig 加载逻辑:按 `category` 从对应 service / 工具取配置。
|
|
5524
|
+
* 作为 ctx.defaultLoadConfig 透传给自定义 `loadConfig`,方便复用与二次加工。
|
|
5525
|
+
*/
|
|
5526
|
+
const defaultLoadConfig = async () => {
|
|
5527
|
+
if (!props.services) return [];
|
|
5528
|
+
switch (props.category) {
|
|
5529
|
+
case "node":
|
|
5530
|
+
if (!props.type) return [];
|
|
5531
|
+
return removeStyleDisplayConfig(await props.services.propsService.getPropsConfig(props.type, { node: props.value }));
|
|
5532
|
+
case "data-source": return props.services.dataSourceService.getFormConfig(props.type || "base").map((item) => "type" in item && item.type === "tab" ? {
|
|
5533
|
+
...item,
|
|
5534
|
+
active: "fields"
|
|
5535
|
+
} : item);
|
|
5536
|
+
case "code-block": return getCodeBlockFormConfig({
|
|
5537
|
+
paramColConfig: props.services.codeBlockService.getParamsColConfig(),
|
|
5538
|
+
isDataSource: () => Boolean(props.dataSourceType),
|
|
5539
|
+
dataSourceType: () => props.dataSourceType,
|
|
5540
|
+
codeOptions,
|
|
5541
|
+
editable: false
|
|
5542
|
+
});
|
|
5543
|
+
default: return [];
|
|
5544
|
+
}
|
|
5545
|
+
};
|
|
5546
|
+
const loadConfig = async () => {
|
|
5547
|
+
if (props.loadConfig) {
|
|
5548
|
+
config.value = await props.loadConfig({
|
|
5549
|
+
category: props.category,
|
|
5550
|
+
type: props.type,
|
|
5551
|
+
dataSourceType: props.dataSourceType,
|
|
5552
|
+
defaultLoadConfig
|
|
5553
|
+
});
|
|
5554
|
+
return;
|
|
5555
|
+
}
|
|
5556
|
+
config.value = await defaultLoadConfig();
|
|
5557
|
+
};
|
|
5558
|
+
(0, vue.watch)([
|
|
5559
|
+
() => props.category,
|
|
5560
|
+
() => props.type,
|
|
5561
|
+
() => props.dataSourceType,
|
|
5562
|
+
() => props.loadConfig
|
|
5563
|
+
], () => {
|
|
5564
|
+
loadConfig();
|
|
5565
|
+
}, { immediate: true });
|
|
5566
|
+
const formRef = (0, vue.useTemplateRef)("form");
|
|
5567
|
+
/**
|
|
5568
|
+
* 把 services / stage 注入 MForm 的 formState,避免 propsService 注入的表单配置中
|
|
5569
|
+
* 形如 `display: ({ services }) => services.uiService.get(...)` 的 filterFunction
|
|
5570
|
+
* 在执行时拿不到 `formState.services` 而报错。
|
|
5571
|
+
*
|
|
5572
|
+
* 与 props-panel/FormPanel.vue 中的注入方式保持一致:
|
|
5573
|
+
* - services:整个 useServices() 返回的服务集合;
|
|
5574
|
+
* - stage:当前 editorService.get('stage') 的最新值。
|
|
5575
|
+
*/
|
|
5576
|
+
(0, vue.watchEffect)(() => {
|
|
5577
|
+
if (formRef.value && props.services) {
|
|
5578
|
+
formRef.value.formState.stage = props.services.editorService.get("stage");
|
|
5579
|
+
formRef.value.formState.services = props.services;
|
|
5580
|
+
}
|
|
5581
|
+
});
|
|
5582
|
+
return {
|
|
5583
|
+
config,
|
|
5584
|
+
currentValues,
|
|
5585
|
+
wrapperStyle,
|
|
5586
|
+
mergedExtendState,
|
|
5587
|
+
loadConfig,
|
|
5588
|
+
formRef,
|
|
5589
|
+
normalizeCodeBlockValue
|
|
5590
|
+
};
|
|
5591
|
+
};
|
|
5592
|
+
}));
|
|
5593
|
+
//#endregion
|
|
5055
5594
|
//#region packages/editor/src/services/BaseService.ts
|
|
5056
5595
|
var methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
|
|
5057
5596
|
var isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
|
|
@@ -5161,326 +5700,9 @@
|
|
|
5161
5700
|
}
|
|
5162
5701
|
};
|
|
5163
5702
|
//#endregion
|
|
5164
|
-
//#region packages/editor/src/utils/props.ts
|
|
5165
|
-
var arrayOptions = [{
|
|
5166
|
-
text: "包含",
|
|
5167
|
-
value: "include"
|
|
5168
|
-
}, {
|
|
5169
|
-
text: "不包含",
|
|
5170
|
-
value: "not_include"
|
|
5171
|
-
}];
|
|
5172
|
-
var eqOptions = [{
|
|
5173
|
-
text: "等于",
|
|
5174
|
-
value: "="
|
|
5175
|
-
}, {
|
|
5176
|
-
text: "不等于",
|
|
5177
|
-
value: "!="
|
|
5178
|
-
}];
|
|
5179
|
-
var numberOptions = [
|
|
5180
|
-
{
|
|
5181
|
-
text: "大于",
|
|
5182
|
-
value: ">"
|
|
5183
|
-
},
|
|
5184
|
-
{
|
|
5185
|
-
text: "大于等于",
|
|
5186
|
-
value: ">="
|
|
5187
|
-
},
|
|
5188
|
-
{
|
|
5189
|
-
text: "小于",
|
|
5190
|
-
value: "<"
|
|
5191
|
-
},
|
|
5192
|
-
{
|
|
5193
|
-
text: "小于等于",
|
|
5194
|
-
value: "<="
|
|
5195
|
-
},
|
|
5196
|
-
{
|
|
5197
|
-
text: "在范围内",
|
|
5198
|
-
value: "between"
|
|
5199
|
-
},
|
|
5200
|
-
{
|
|
5201
|
-
text: "不在范围内",
|
|
5202
|
-
value: "not_between"
|
|
5203
|
-
}
|
|
5204
|
-
];
|
|
5205
|
-
var booleanOptions = [{
|
|
5206
|
-
text: "是",
|
|
5207
|
-
value: "is"
|
|
5208
|
-
}, {
|
|
5209
|
-
text: "不是",
|
|
5210
|
-
value: "not"
|
|
5211
|
-
}];
|
|
5212
|
-
/** 按字段类型返回条件运算符选项(UI 与 typeMatch 校验共用) */
|
|
5213
|
-
var getCondOpOptionsByFieldType = (type) => {
|
|
5214
|
-
if (type === "array") return arrayOptions;
|
|
5215
|
-
if (type === "boolean" || type === "null") return booleanOptions;
|
|
5216
|
-
if (type === "number") return [...eqOptions, ...numberOptions];
|
|
5217
|
-
if (type === "string") return [...arrayOptions, ...eqOptions];
|
|
5218
|
-
return [
|
|
5219
|
-
...arrayOptions,
|
|
5220
|
-
...eqOptions,
|
|
5221
|
-
...numberOptions
|
|
5222
|
-
];
|
|
5223
|
-
};
|
|
5224
|
-
var styleTabConfig = {
|
|
5225
|
-
title: "样式",
|
|
5226
|
-
lazy: true,
|
|
5227
|
-
display: ({ services }) => !(services?.uiService?.get("showStylePanel") ?? true),
|
|
5228
|
-
items: [{
|
|
5229
|
-
name: "style",
|
|
5230
|
-
labelWidth: "100px",
|
|
5231
|
-
type: "style-setter",
|
|
5232
|
-
items: [{ names: [
|
|
5233
|
-
"display",
|
|
5234
|
-
"flexDirection",
|
|
5235
|
-
"justifyContent",
|
|
5236
|
-
"alignItems",
|
|
5237
|
-
"flexWrap",
|
|
5238
|
-
"marginTop",
|
|
5239
|
-
"marginRight",
|
|
5240
|
-
"marginBottom",
|
|
5241
|
-
"marginLeft",
|
|
5242
|
-
"paddingTop",
|
|
5243
|
-
"paddingRight",
|
|
5244
|
-
"paddingBottom",
|
|
5245
|
-
"paddingLeft",
|
|
5246
|
-
"width",
|
|
5247
|
-
"height",
|
|
5248
|
-
"overflow",
|
|
5249
|
-
"fontSize",
|
|
5250
|
-
"lineHeight",
|
|
5251
|
-
"fontWeight",
|
|
5252
|
-
"color",
|
|
5253
|
-
"textAlign",
|
|
5254
|
-
"backgroundColor",
|
|
5255
|
-
"backgroundImage",
|
|
5256
|
-
"backgroundSize",
|
|
5257
|
-
"backgroundPosition",
|
|
5258
|
-
"backgroundRepeat",
|
|
5259
|
-
"position",
|
|
5260
|
-
"zIndex",
|
|
5261
|
-
"top",
|
|
5262
|
-
"right",
|
|
5263
|
-
"bottom",
|
|
5264
|
-
"left",
|
|
5265
|
-
"borderRadius",
|
|
5266
|
-
"borderTopWidth",
|
|
5267
|
-
"borderTopStyle",
|
|
5268
|
-
"borderTopColor",
|
|
5269
|
-
"borderRightColor",
|
|
5270
|
-
"borderRightWidth",
|
|
5271
|
-
"borderRightStyle",
|
|
5272
|
-
"borderRightColor",
|
|
5273
|
-
"borderBottomWidth",
|
|
5274
|
-
"borderBottomStyle",
|
|
5275
|
-
"borderBottomColor",
|
|
5276
|
-
"borderLeftStyle",
|
|
5277
|
-
"borderLeftWidth",
|
|
5278
|
-
"borderLeftColor",
|
|
5279
|
-
"borderWidth",
|
|
5280
|
-
"borderStyle",
|
|
5281
|
-
"borderColor",
|
|
5282
|
-
"opacity"
|
|
5283
|
-
] }, {
|
|
5284
|
-
name: "transform",
|
|
5285
|
-
defaultValue: () => ({})
|
|
5286
|
-
}]
|
|
5287
|
-
}]
|
|
5288
|
-
};
|
|
5289
|
-
var eventTabConfig = {
|
|
5290
|
-
title: "事件",
|
|
5291
|
-
lazy: true,
|
|
5292
|
-
items: [{
|
|
5293
|
-
name: "events",
|
|
5294
|
-
src: "component",
|
|
5295
|
-
labelWidth: "100px",
|
|
5296
|
-
type: "event-select",
|
|
5297
|
-
rules: [{ typeMatch: true }]
|
|
5298
|
-
}]
|
|
5299
|
-
};
|
|
5300
|
-
var advancedTabConfig = {
|
|
5301
|
-
title: "高级",
|
|
5302
|
-
lazy: true,
|
|
5303
|
-
items: [
|
|
5304
|
-
{
|
|
5305
|
-
name: _tmagic_core.NODE_DISABLE_CODE_BLOCK_KEY,
|
|
5306
|
-
text: "禁用代码块",
|
|
5307
|
-
type: "switch",
|
|
5308
|
-
defaultValue: false,
|
|
5309
|
-
extra: "开启后,配置的代码块将不会被执行"
|
|
5310
|
-
},
|
|
5311
|
-
{
|
|
5312
|
-
name: _tmagic_core.NODE_DISABLE_DATA_SOURCE_KEY,
|
|
5313
|
-
text: "禁用数据源",
|
|
5314
|
-
type: "switch",
|
|
5315
|
-
defaultValue: false,
|
|
5316
|
-
extra: "开启后,组件内配置的数据源相关配置将不会被编译,显隐条件将失效"
|
|
5317
|
-
},
|
|
5318
|
-
{
|
|
5319
|
-
name: "created",
|
|
5320
|
-
text: "created",
|
|
5321
|
-
labelPosition: "top",
|
|
5322
|
-
type: "code-select",
|
|
5323
|
-
extra: "组件初始化时执行",
|
|
5324
|
-
rules: [{
|
|
5325
|
-
typeMatch: true,
|
|
5326
|
-
trigger: "change"
|
|
5327
|
-
}, { validator: ({ value, callback }) => {
|
|
5328
|
-
if (value && value.hookType !== _tmagic_core.HookType.CODE) return callback("hookType 必须是 code");
|
|
5329
|
-
callback();
|
|
5330
|
-
} }]
|
|
5331
|
-
},
|
|
5332
|
-
{
|
|
5333
|
-
name: "mounted",
|
|
5334
|
-
text: "mounted",
|
|
5335
|
-
labelPosition: "top",
|
|
5336
|
-
type: "code-select",
|
|
5337
|
-
extra: "组件挂载到dom时执行",
|
|
5338
|
-
rules: [{
|
|
5339
|
-
typeMatch: true,
|
|
5340
|
-
trigger: "change"
|
|
5341
|
-
}, { validator: ({ value, callback }) => {
|
|
5342
|
-
if (value && value.hookType !== _tmagic_core.HookType.CODE) return callback("hookType 必须是 code");
|
|
5343
|
-
callback();
|
|
5344
|
-
} }]
|
|
5345
|
-
},
|
|
5346
|
-
{
|
|
5347
|
-
name: "display",
|
|
5348
|
-
text: "display",
|
|
5349
|
-
extra: "控制组件是否渲染,关系的代码块返回值为false时不渲染",
|
|
5350
|
-
labelPosition: "top",
|
|
5351
|
-
type: "code-select",
|
|
5352
|
-
rules: [{
|
|
5353
|
-
typeMatch: true,
|
|
5354
|
-
trigger: "change"
|
|
5355
|
-
}, { validator: ({ value, callback }) => {
|
|
5356
|
-
if (value && value.hookType !== _tmagic_core.HookType.CODE) return callback("hookType 必须是 code");
|
|
5357
|
-
callback();
|
|
5358
|
-
} }]
|
|
5359
|
-
}
|
|
5360
|
-
]
|
|
5361
|
-
};
|
|
5362
|
-
var displayTabConfig = {
|
|
5363
|
-
title: "显示条件",
|
|
5364
|
-
display: (_state, { model }) => model.type !== "page",
|
|
5365
|
-
items: [{
|
|
5366
|
-
name: _tmagic_core.NODE_CONDS_RESULT_KEY,
|
|
5367
|
-
type: "select",
|
|
5368
|
-
text: "条件成立时",
|
|
5369
|
-
defaultValue: false,
|
|
5370
|
-
options: [{
|
|
5371
|
-
text: "显示",
|
|
5372
|
-
value: false
|
|
5373
|
-
}, {
|
|
5374
|
-
text: "隐藏",
|
|
5375
|
-
value: true
|
|
5376
|
-
}],
|
|
5377
|
-
extra: (_state, { model }) => `条件成立时${model[_tmagic_core.NODE_CONDS_RESULT_KEY] ? "隐藏" : "显示"},不成立时${model[_tmagic_core.NODE_CONDS_RESULT_KEY] ? "显示" : "隐藏"};<br />同一条件组内的所有条件配置同时成立时表示该条件组成立,任意一个条件组成立时表示条件成立(条件组内为且的关系,条件组间为或的关系);<br />条件为空时表示成立;`
|
|
5378
|
-
}, {
|
|
5379
|
-
type: "display-conds",
|
|
5380
|
-
name: _tmagic_core.NODE_CONDS_KEY,
|
|
5381
|
-
titlePrefix: "条件组",
|
|
5382
|
-
defaultValue: [],
|
|
5383
|
-
rules: [{ typeMatch: true }]
|
|
5384
|
-
}]
|
|
5385
|
-
};
|
|
5386
|
-
/**
|
|
5387
|
-
* 统一为组件属性表单加上事件、高级、样式配置
|
|
5388
|
-
* @param config 组件属性配置
|
|
5389
|
-
* @returns Object
|
|
5390
|
-
*/
|
|
5391
|
-
var fillConfig = (config = [], { labelWidth = "80px", disabledDataSource = false, disabledCodeBlock = false } = {}) => {
|
|
5392
|
-
const propsConfig = [];
|
|
5393
|
-
if (!config.find((item) => "name" in item && item.name === "type")) propsConfig.push({
|
|
5394
|
-
text: "type",
|
|
5395
|
-
name: "type",
|
|
5396
|
-
type: "hidden"
|
|
5397
|
-
});
|
|
5398
|
-
if (!config.find((item) => "name" in item && item.name === "id")) propsConfig.push({
|
|
5399
|
-
name: "id",
|
|
5400
|
-
text: "ID",
|
|
5401
|
-
type: "text",
|
|
5402
|
-
disabled: true,
|
|
5403
|
-
append: {
|
|
5404
|
-
type: "button",
|
|
5405
|
-
text: "复制",
|
|
5406
|
-
handler: (vm, { model }) => {
|
|
5407
|
-
navigator.clipboard.writeText(`${model.id}`).then(() => {
|
|
5408
|
-
_tmagic_design.tMagicMessage.success("已复制");
|
|
5409
|
-
}).catch(() => {
|
|
5410
|
-
_tmagic_design.tMagicMessage.error("复制失败");
|
|
5411
|
-
});
|
|
5412
|
-
}
|
|
5413
|
-
}
|
|
5414
|
-
});
|
|
5415
|
-
if (!config.find((item) => "name" in item && item.name === "name")) propsConfig.push({
|
|
5416
|
-
name: "name",
|
|
5417
|
-
text: "组件名称"
|
|
5418
|
-
});
|
|
5419
|
-
const noCodeAdvancedTabItems = advancedTabConfig.items.filter((item) => "type" in item && item.type !== "code-select");
|
|
5420
|
-
if (noCodeAdvancedTabItems.length > 0 && disabledCodeBlock) advancedTabConfig.items = noCodeAdvancedTabItems;
|
|
5421
|
-
const tabConfig = {
|
|
5422
|
-
type: "tab",
|
|
5423
|
-
labelWidth,
|
|
5424
|
-
items: [
|
|
5425
|
-
{
|
|
5426
|
-
title: "属性",
|
|
5427
|
-
items: [...propsConfig, ...config]
|
|
5428
|
-
},
|
|
5429
|
-
{ ...styleTabConfig },
|
|
5430
|
-
{ ...eventTabConfig }
|
|
5431
|
-
]
|
|
5432
|
-
};
|
|
5433
|
-
if (!disabledCodeBlock) tabConfig.items.push({ ...advancedTabConfig });
|
|
5434
|
-
else if (noCodeAdvancedTabItems.length > 0) tabConfig.items.push({ ...advancedTabConfig });
|
|
5435
|
-
if (!disabledDataSource) tabConfig.items.push({ ...displayTabConfig });
|
|
5436
|
-
return [tabConfig];
|
|
5437
|
-
};
|
|
5438
|
-
/**
|
|
5439
|
-
* 对一份「组件属性表单配置 + 值」做一次独立的校验,**不复用也不污染页面上正在展示的表单**。
|
|
5440
|
-
*
|
|
5441
|
-
* 内部基于 `@tmagic/form` 的 `validateForm` 另建一个独立的 MForm 实例完成校验,并统一处理
|
|
5442
|
-
* 编辑器场景所需的上下文注入:将当前组件实例的 provides 合入 appContext,并向 formState 注入
|
|
5443
|
-
* stage / services 及外部扩展状态,保证校验规则依赖的上下文可用。
|
|
5444
|
-
*
|
|
5445
|
-
* 常用于源码编辑器保存后,对最新配置做一次校验,并将校验结果(错误信息)随提交一并抛给上层记录,
|
|
5446
|
-
* 使源码保存的错误状态与表单编辑保持一致。
|
|
5447
|
-
*
|
|
5448
|
-
* @returns 校验通过返回空字符串 `''`,否则返回以 `<br>` 拼接的错误文案。
|
|
5449
|
-
* 仅在初始化超时或挂载失败等异常情况下才会 reject。
|
|
5450
|
-
*
|
|
5451
|
-
* @example
|
|
5452
|
-
* ```ts
|
|
5453
|
-
* const error = await validatePropsForm({
|
|
5454
|
-
* config,
|
|
5455
|
-
* values,
|
|
5456
|
-
* appContext: getCurrentInstance()?.appContext,
|
|
5457
|
-
* services,
|
|
5458
|
-
* stage: editorService.get('stage'),
|
|
5459
|
-
* extendState,
|
|
5460
|
-
* });
|
|
5461
|
-
* if (error) {
|
|
5462
|
-
* // 配置不合法,error 为错误文案
|
|
5463
|
-
* }
|
|
5464
|
-
* ```
|
|
5465
|
-
*/
|
|
5466
|
-
var validatePropsForm = ({ config, values, appContext = null, services, stage, extendState, debug, typeMatchValid }) => (0, _tmagic_form.validateForm)({
|
|
5467
|
-
config,
|
|
5468
|
-
debug,
|
|
5469
|
-
typeMatchValid,
|
|
5470
|
-
initValues: values,
|
|
5471
|
-
appContext: appContext ? {
|
|
5472
|
-
...appContext,
|
|
5473
|
-
provides: { services }
|
|
5474
|
-
} : null,
|
|
5475
|
-
extendState: async (state) => ({
|
|
5476
|
-
...await extendState?.(state) || {},
|
|
5477
|
-
stage,
|
|
5478
|
-
services
|
|
5479
|
-
})
|
|
5480
|
-
});
|
|
5481
|
-
//#endregion
|
|
5482
5703
|
//#region packages/editor/src/services/props.ts
|
|
5483
5704
|
init_lodash();
|
|
5705
|
+
init_props();
|
|
5484
5706
|
var canUsePluginMethods$8 = {
|
|
5485
5707
|
async: [
|
|
5486
5708
|
"setPropsConfig",
|
|
@@ -5703,18 +5925,7 @@
|
|
|
5703
5925
|
};
|
|
5704
5926
|
var props_default = new Props();
|
|
5705
5927
|
//#endregion
|
|
5706
|
-
//#region packages/editor/src/utils/config.ts
|
|
5707
|
-
var $TMAGIC_EDITOR, setEditorConfig, getEditorConfig;
|
|
5708
|
-
var init_config = __esmMin((() => {
|
|
5709
|
-
$TMAGIC_EDITOR = {};
|
|
5710
|
-
setEditorConfig = (option) => {
|
|
5711
|
-
$TMAGIC_EDITOR = option;
|
|
5712
|
-
};
|
|
5713
|
-
getEditorConfig = (key) => $TMAGIC_EDITOR[key];
|
|
5714
|
-
}));
|
|
5715
|
-
//#endregion
|
|
5716
5928
|
//#region packages/editor/src/utils/undo-redo.ts
|
|
5717
|
-
init_config();
|
|
5718
5929
|
init_lodash();
|
|
5719
5930
|
var UndoRedo = class UndoRedo {
|
|
5720
5931
|
/**
|
|
@@ -6140,6 +6351,7 @@
|
|
|
6140
6351
|
};
|
|
6141
6352
|
//#endregion
|
|
6142
6353
|
//#region packages/editor/src/services/history.ts
|
|
6354
|
+
init_config();
|
|
6143
6355
|
var canUsePluginMethods$7 = { sync: [
|
|
6144
6356
|
"push",
|
|
6145
6357
|
"undo",
|
|
@@ -9014,125 +9226,7 @@
|
|
|
9014
9226
|
return { nodeStatusMap };
|
|
9015
9227
|
};
|
|
9016
9228
|
//#endregion
|
|
9017
|
-
//#region packages/editor/src/utils/code-block.ts
|
|
9018
|
-
var defaultParamColConfig, getCodeBlockFormConfig;
|
|
9019
|
-
var init_code_block = __esmMin((() => {
|
|
9020
|
-
init_config();
|
|
9021
|
-
defaultParamColConfig = () => (0, _tmagic_form.defineFormItem)({
|
|
9022
|
-
type: "row",
|
|
9023
|
-
label: "参数类型",
|
|
9024
|
-
items: [{
|
|
9025
|
-
text: "参数类型",
|
|
9026
|
-
labelWidth: "70px",
|
|
9027
|
-
type: "select",
|
|
9028
|
-
name: "type",
|
|
9029
|
-
options: [
|
|
9030
|
-
{
|
|
9031
|
-
text: "数字",
|
|
9032
|
-
label: "数字",
|
|
9033
|
-
value: "number"
|
|
9034
|
-
},
|
|
9035
|
-
{
|
|
9036
|
-
text: "字符串",
|
|
9037
|
-
label: "字符串",
|
|
9038
|
-
value: "text"
|
|
9039
|
-
},
|
|
9040
|
-
{
|
|
9041
|
-
text: "组件",
|
|
9042
|
-
label: "组件",
|
|
9043
|
-
value: "ui-select"
|
|
9044
|
-
}
|
|
9045
|
-
]
|
|
9046
|
-
}]
|
|
9047
|
-
});
|
|
9048
|
-
getCodeBlockFormConfig = (options = {}) => {
|
|
9049
|
-
const { paramColConfig, isDataSource, dataSourceType, codeOptions = {}, editable = true } = options;
|
|
9050
|
-
return (0, _tmagic_form.defineFormConfig)([
|
|
9051
|
-
{
|
|
9052
|
-
text: "名称",
|
|
9053
|
-
name: "name",
|
|
9054
|
-
...editable ? { rules: [{
|
|
9055
|
-
required: true,
|
|
9056
|
-
message: "请输入名称",
|
|
9057
|
-
trigger: "blur"
|
|
9058
|
-
}] } : {}
|
|
9059
|
-
},
|
|
9060
|
-
{
|
|
9061
|
-
text: "描述",
|
|
9062
|
-
name: "desc"
|
|
9063
|
-
},
|
|
9064
|
-
{
|
|
9065
|
-
text: "执行时机",
|
|
9066
|
-
name: "timing",
|
|
9067
|
-
type: "select",
|
|
9068
|
-
options: () => {
|
|
9069
|
-
const list = [{
|
|
9070
|
-
text: "初始化前",
|
|
9071
|
-
value: "beforeInit"
|
|
9072
|
-
}, {
|
|
9073
|
-
text: "初始化后",
|
|
9074
|
-
value: "afterInit"
|
|
9075
|
-
}];
|
|
9076
|
-
if (dataSourceType?.() !== "base") {
|
|
9077
|
-
list.push({
|
|
9078
|
-
text: "请求前",
|
|
9079
|
-
value: "beforeRequest"
|
|
9080
|
-
});
|
|
9081
|
-
list.push({
|
|
9082
|
-
text: "请求后",
|
|
9083
|
-
value: "afterRequest"
|
|
9084
|
-
});
|
|
9085
|
-
}
|
|
9086
|
-
return list;
|
|
9087
|
-
},
|
|
9088
|
-
display: () => Boolean(isDataSource?.())
|
|
9089
|
-
},
|
|
9090
|
-
{
|
|
9091
|
-
type: "table",
|
|
9092
|
-
border: true,
|
|
9093
|
-
text: "参数",
|
|
9094
|
-
enableFullscreen: false,
|
|
9095
|
-
enableToggleMode: false,
|
|
9096
|
-
name: "params",
|
|
9097
|
-
dropSort: false,
|
|
9098
|
-
items: [
|
|
9099
|
-
{
|
|
9100
|
-
type: "text",
|
|
9101
|
-
label: "参数名",
|
|
9102
|
-
name: "name"
|
|
9103
|
-
},
|
|
9104
|
-
{
|
|
9105
|
-
type: "text",
|
|
9106
|
-
label: "描述",
|
|
9107
|
-
name: "extra"
|
|
9108
|
-
},
|
|
9109
|
-
paramColConfig || defaultParamColConfig()
|
|
9110
|
-
]
|
|
9111
|
-
},
|
|
9112
|
-
{
|
|
9113
|
-
name: "content",
|
|
9114
|
-
type: "vs-code",
|
|
9115
|
-
options: codeOptions,
|
|
9116
|
-
autosize: {
|
|
9117
|
-
minRows: 10,
|
|
9118
|
-
maxRows: 30
|
|
9119
|
-
},
|
|
9120
|
-
...editable ? { onChange: (_formState, code) => {
|
|
9121
|
-
try {
|
|
9122
|
-
getEditorConfig("parseDSL")(code);
|
|
9123
|
-
return code;
|
|
9124
|
-
} catch (error) {
|
|
9125
|
-
_tmagic_design.tMagicMessage.error(error.message);
|
|
9126
|
-
throw error;
|
|
9127
|
-
}
|
|
9128
|
-
} } : {}
|
|
9129
|
-
}
|
|
9130
|
-
]);
|
|
9131
|
-
};
|
|
9132
|
-
}));
|
|
9133
|
-
//#endregion
|
|
9134
9229
|
//#region packages/editor/src/utils/logger.ts
|
|
9135
|
-
init_code_block();
|
|
9136
9230
|
var log = (...args) => {
|
|
9137
9231
|
if (process.env.NODE_ENV === "development") console.log("magic editor: ", ...args);
|
|
9138
9232
|
};
|
|
@@ -10600,6 +10694,8 @@
|
|
|
10600
10694
|
var dataSource_default = new DataSource();
|
|
10601
10695
|
//#endregion
|
|
10602
10696
|
//#region packages/editor/src/utils/type-match-rules.ts
|
|
10697
|
+
init_use_compare_form();
|
|
10698
|
+
init_props();
|
|
10603
10699
|
/**
|
|
10604
10700
|
* 将值格式化为可读的参考示例字符串。
|
|
10605
10701
|
*/
|
|
@@ -13182,59 +13278,27 @@
|
|
|
13182
13278
|
__name: "CompareForm",
|
|
13183
13279
|
props: {
|
|
13184
13280
|
value: {},
|
|
13185
|
-
lastValue: {},
|
|
13186
13281
|
type: {},
|
|
13187
13282
|
category: { default: "node" },
|
|
13188
13283
|
dataSourceType: {},
|
|
13189
13284
|
labelWidth: { default: "120px" },
|
|
13190
13285
|
height: {},
|
|
13191
|
-
extendState: {
|
|
13192
|
-
type: Function,
|
|
13193
|
-
default: (state) => state
|
|
13194
|
-
},
|
|
13286
|
+
extendState: {},
|
|
13195
13287
|
baseFormState: {},
|
|
13196
|
-
selfDiffFieldTypes: {},
|
|
13197
13288
|
size: {},
|
|
13198
13289
|
loadConfig: {},
|
|
13199
|
-
services: {}
|
|
13290
|
+
services: {},
|
|
13291
|
+
lastValue: {},
|
|
13292
|
+
selfDiffFieldTypes: {}
|
|
13200
13293
|
},
|
|
13201
13294
|
setup(__props, { expose: __expose }) {
|
|
13202
13295
|
const props = __props;
|
|
13203
|
-
|
|
13204
|
-
const config = (0, vue.ref)([]);
|
|
13205
|
-
/** vs-code 编辑器的 monaco 配置项,沿用 Editor 顶层 provide('codeOptions', ...) 的注入。 */
|
|
13206
|
-
const codeOptions = (0, vue.inject)("codeOptions", {});
|
|
13207
|
-
/** 将代码块的 content 字段统一成字符串,便于在表单/对比中展示 */
|
|
13208
|
-
const normalizeCodeBlockValue = (v) => {
|
|
13209
|
-
if (!v) return {};
|
|
13210
|
-
const next = { ...v };
|
|
13211
|
-
if (next.content && typeof next.content !== "string") try {
|
|
13212
|
-
next.content = next.content.toString();
|
|
13213
|
-
} catch {
|
|
13214
|
-
next.content = "";
|
|
13215
|
-
}
|
|
13216
|
-
return next;
|
|
13217
|
-
};
|
|
13218
|
-
const currentValues = (0, vue.computed)(() => {
|
|
13219
|
-
if (props.category === "code-block") return normalizeCodeBlockValue(props.value);
|
|
13220
|
-
return props.value || {};
|
|
13221
|
-
});
|
|
13296
|
+
const { config, currentValues, wrapperStyle, mergedExtendState, loadConfig, formRef, normalizeCodeBlockValue } = useCompareForm(props);
|
|
13222
13297
|
const lastValuesProcessed = (0, vue.computed)(() => {
|
|
13223
13298
|
if (props.category === "code-block") return normalizeCodeBlockValue(props.lastValue);
|
|
13224
13299
|
return props.lastValue || {};
|
|
13225
13300
|
});
|
|
13226
13301
|
/**
|
|
13227
|
-
* 外层包裹层的样式:当传入 `height` 时启用固定高度 + 内部滚动,
|
|
13228
|
-
* 这样滚动条会出现在 CompareForm 内部,避免父容器(如 Dialog)自身也产生滚动。
|
|
13229
|
-
*/
|
|
13230
|
-
const wrapperStyle = (0, vue.computed)(() => {
|
|
13231
|
-
if (!props.height) return void 0;
|
|
13232
|
-
return {
|
|
13233
|
-
height: props.height,
|
|
13234
|
-
overflow: "auto"
|
|
13235
|
-
};
|
|
13236
|
-
});
|
|
13237
|
-
/**
|
|
13238
13302
|
* `code-select` 字段在历史数据中存在两种"语义为空"的形态:
|
|
13239
13303
|
* - 字符串 `''`(旧数据 / 用户从未配置过钩子);
|
|
13240
13304
|
* - `{ hookType: HookType.CODE, hookData: [] }`(CodeSelect.vue 在挂载时
|
|
@@ -13257,83 +13321,6 @@
|
|
|
13257
13321
|
}
|
|
13258
13322
|
return !isEqual(curValue, lastValue);
|
|
13259
13323
|
};
|
|
13260
|
-
const removeStyleDisplayConfig = (formConfig) => formConfig.map((item) => {
|
|
13261
|
-
if (!("type" in item)) return item;
|
|
13262
|
-
if (item?.type !== "tab" || !Array.isArray(item.items)) return item;
|
|
13263
|
-
return {
|
|
13264
|
-
...item,
|
|
13265
|
-
items: item.items.map((tabPane) => {
|
|
13266
|
-
if (tabPane?.title !== "样式" || !Array.isArray(tabPane.items)) return tabPane;
|
|
13267
|
-
return {
|
|
13268
|
-
...tabPane,
|
|
13269
|
-
display: true
|
|
13270
|
-
};
|
|
13271
|
-
})
|
|
13272
|
-
};
|
|
13273
|
-
});
|
|
13274
|
-
const mergedExtendState = (state) => {
|
|
13275
|
-
return props.extendState(props.baseFormState || state);
|
|
13276
|
-
};
|
|
13277
|
-
/**
|
|
13278
|
-
* 内置的默认 FormConfig 加载逻辑:按 `category` 从对应 service / 工具取配置。
|
|
13279
|
-
* 作为 ctx.defaultLoadConfig 透传给自定义 `loadConfig`,方便复用与二次加工。
|
|
13280
|
-
*/
|
|
13281
|
-
const defaultLoadConfig = async () => {
|
|
13282
|
-
if (!props.services) return [];
|
|
13283
|
-
switch (props.category) {
|
|
13284
|
-
case "node":
|
|
13285
|
-
if (!props.type) return [];
|
|
13286
|
-
return removeStyleDisplayConfig(await props.services.propsService.getPropsConfig(props.type, { node: props.value }));
|
|
13287
|
-
case "data-source": return props.services.dataSourceService.getFormConfig(props.type || "base").map((item) => "type" in item && item.type === "tab" ? {
|
|
13288
|
-
...item,
|
|
13289
|
-
active: "fields"
|
|
13290
|
-
} : item);
|
|
13291
|
-
case "code-block": return getCodeBlockFormConfig({
|
|
13292
|
-
paramColConfig: props.services.codeBlockService.getParamsColConfig(),
|
|
13293
|
-
isDataSource: () => Boolean(props.dataSourceType),
|
|
13294
|
-
dataSourceType: () => props.dataSourceType,
|
|
13295
|
-
codeOptions,
|
|
13296
|
-
editable: false
|
|
13297
|
-
});
|
|
13298
|
-
default: return [];
|
|
13299
|
-
}
|
|
13300
|
-
};
|
|
13301
|
-
const loadConfig = async () => {
|
|
13302
|
-
if (props.loadConfig) {
|
|
13303
|
-
config.value = await props.loadConfig({
|
|
13304
|
-
category: props.category,
|
|
13305
|
-
type: props.type,
|
|
13306
|
-
dataSourceType: props.dataSourceType,
|
|
13307
|
-
defaultLoadConfig
|
|
13308
|
-
});
|
|
13309
|
-
return;
|
|
13310
|
-
}
|
|
13311
|
-
config.value = await defaultLoadConfig();
|
|
13312
|
-
};
|
|
13313
|
-
(0, vue.watch)([
|
|
13314
|
-
() => props.category,
|
|
13315
|
-
() => props.type,
|
|
13316
|
-
() => props.dataSourceType,
|
|
13317
|
-
() => props.loadConfig
|
|
13318
|
-
], () => {
|
|
13319
|
-
loadConfig();
|
|
13320
|
-
}, { immediate: true });
|
|
13321
|
-
const formRef = (0, vue.useTemplateRef)("form");
|
|
13322
|
-
/**
|
|
13323
|
-
* 把 services / stage 注入 MForm 的 formState,避免 propsService 注入的表单配置中
|
|
13324
|
-
* 形如 `display: ({ services }) => services.uiService.get(...)` 的 filterFunction
|
|
13325
|
-
* 在执行时拿不到 `formState.services` 而报错。
|
|
13326
|
-
*
|
|
13327
|
-
* 与 props-panel/FormPanel.vue 中的注入方式保持一致:
|
|
13328
|
-
* - services:整个 useServices() 返回的服务集合;
|
|
13329
|
-
* - stage:当前 editorService.get('stage') 的最新值。
|
|
13330
|
-
*/
|
|
13331
|
-
(0, vue.watchEffect)(() => {
|
|
13332
|
-
if (formRef.value && props.services) {
|
|
13333
|
-
formRef.value.formState.stage = props.services.editorService.get("stage");
|
|
13334
|
-
formRef.value.formState.services = props.services;
|
|
13335
|
-
}
|
|
13336
|
-
});
|
|
13337
13324
|
__expose({
|
|
13338
13325
|
form: formRef,
|
|
13339
13326
|
config,
|
|
@@ -13342,18 +13329,18 @@
|
|
|
13342
13329
|
return (_ctx, _cache) => {
|
|
13343
13330
|
return (0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
|
|
13344
13331
|
class: "m-editor-compare-form-wrapper",
|
|
13345
|
-
style: (0, vue.normalizeStyle)(
|
|
13346
|
-
}, [config.
|
|
13332
|
+
style: (0, vue.normalizeStyle)((0, vue.unref)(wrapperStyle))
|
|
13333
|
+
}, [(0, vue.unref)(config).length ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_form.MForm), {
|
|
13347
13334
|
key: 0,
|
|
13348
13335
|
ref: "form",
|
|
13349
13336
|
class: "m-editor-compare-form",
|
|
13350
|
-
config: config
|
|
13351
|
-
"init-values": currentValues
|
|
13337
|
+
config: (0, vue.unref)(config),
|
|
13338
|
+
"init-values": (0, vue.unref)(currentValues),
|
|
13352
13339
|
"last-values": lastValuesProcessed.value,
|
|
13353
13340
|
"is-compare": true,
|
|
13354
13341
|
disabled: true,
|
|
13355
13342
|
"label-width": __props.labelWidth,
|
|
13356
|
-
"extend-state": mergedExtendState,
|
|
13343
|
+
"extend-state": (0, vue.unref)(mergedExtendState),
|
|
13357
13344
|
"show-diff": showDiff,
|
|
13358
13345
|
"self-diff-field-types": __props.selfDiffFieldTypes,
|
|
13359
13346
|
size: __props.size
|
|
@@ -13362,6 +13349,7 @@
|
|
|
13362
13349
|
"init-values",
|
|
13363
13350
|
"last-values",
|
|
13364
13351
|
"label-width",
|
|
13352
|
+
"extend-state",
|
|
13365
13353
|
"self-diff-field-types",
|
|
13366
13354
|
"size"
|
|
13367
13355
|
])) : (0, vue.createCommentVNode)("v-if", true)], 4);
|
|
@@ -14744,6 +14732,7 @@
|
|
|
14744
14732
|
//#endregion
|
|
14745
14733
|
//#region packages/editor/src/layouts/props-panel/FormPanel.vue?vue&type=script&setup=true&lang.ts
|
|
14746
14734
|
init_Icon();
|
|
14735
|
+
init_props();
|
|
14747
14736
|
init_CodeEditor();
|
|
14748
14737
|
var _hoisted_1$54 = { class: "m-editor-props-form-panel" };
|
|
14749
14738
|
var FormPanel_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ (0, vue.defineComponent)({
|
|
@@ -14942,6 +14931,7 @@
|
|
|
14942
14931
|
//#endregion
|
|
14943
14932
|
//#region packages/editor/src/layouts/props-panel/PropsPanel.vue?vue&type=script&setup=true&lang.ts
|
|
14944
14933
|
init_Icon();
|
|
14934
|
+
init_props();
|
|
14945
14935
|
var _hoisted_1$53 = {
|
|
14946
14936
|
ref: "propsPanel",
|
|
14947
14937
|
class: "m-editor-props-panel"
|
|
@@ -22885,6 +22875,64 @@
|
|
|
22885
22875
|
//#region packages/editor/src/fields/KeyValue.vue
|
|
22886
22876
|
var KeyValue_default = KeyValue_vue_vue_type_script_setup_true_lang_default;
|
|
22887
22877
|
//#endregion
|
|
22878
|
+
//#region packages/editor/src/components/ViewForm.vue?vue&type=script&setup=true&lang.ts
|
|
22879
|
+
init_use_compare_form();
|
|
22880
|
+
var ViewForm_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ (0, vue.defineComponent)({
|
|
22881
|
+
name: "MEditorViewForm",
|
|
22882
|
+
__name: "ViewForm",
|
|
22883
|
+
props: {
|
|
22884
|
+
value: {},
|
|
22885
|
+
type: {},
|
|
22886
|
+
category: { default: "node" },
|
|
22887
|
+
dataSourceType: {},
|
|
22888
|
+
labelWidth: { default: "120px" },
|
|
22889
|
+
height: {},
|
|
22890
|
+
extendState: {},
|
|
22891
|
+
baseFormState: {},
|
|
22892
|
+
size: {},
|
|
22893
|
+
loadConfig: {},
|
|
22894
|
+
services: {},
|
|
22895
|
+
disabled: {
|
|
22896
|
+
type: Boolean,
|
|
22897
|
+
default: true
|
|
22898
|
+
}
|
|
22899
|
+
},
|
|
22900
|
+
setup(__props, { expose: __expose }) {
|
|
22901
|
+
const { config, currentValues, wrapperStyle, mergedExtendState, loadConfig, formRef } = useCompareForm(__props);
|
|
22902
|
+
__expose({
|
|
22903
|
+
form: formRef,
|
|
22904
|
+
config,
|
|
22905
|
+
reload: loadConfig
|
|
22906
|
+
});
|
|
22907
|
+
return (_ctx, _cache) => {
|
|
22908
|
+
return (0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
|
|
22909
|
+
class: "m-editor-view-form-wrapper",
|
|
22910
|
+
style: (0, vue.normalizeStyle)((0, vue.unref)(wrapperStyle))
|
|
22911
|
+
}, [(0, vue.unref)(config).length ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_form.MForm), {
|
|
22912
|
+
key: 0,
|
|
22913
|
+
ref: "form",
|
|
22914
|
+
class: "m-editor-view-form",
|
|
22915
|
+
config: (0, vue.unref)(config),
|
|
22916
|
+
"init-values": (0, vue.unref)(currentValues),
|
|
22917
|
+
disabled: __props.disabled,
|
|
22918
|
+
"label-width": __props.labelWidth,
|
|
22919
|
+
"extend-state": (0, vue.unref)(mergedExtendState),
|
|
22920
|
+
size: __props.size
|
|
22921
|
+
}, null, 8, [
|
|
22922
|
+
"config",
|
|
22923
|
+
"init-values",
|
|
22924
|
+
"disabled",
|
|
22925
|
+
"label-width",
|
|
22926
|
+
"extend-state",
|
|
22927
|
+
"size"
|
|
22928
|
+
])) : (0, vue.createCommentVNode)("v-if", true)], 4);
|
|
22929
|
+
};
|
|
22930
|
+
}
|
|
22931
|
+
});
|
|
22932
|
+
//#endregion
|
|
22933
|
+
//#region packages/editor/src/components/ViewForm.vue
|
|
22934
|
+
var ViewForm_default = ViewForm_vue_vue_type_script_setup_true_lang_default;
|
|
22935
|
+
//#endregion
|
|
22888
22936
|
//#region packages/editor/src/fields/PageFragmentSelect.vue?vue&type=script&setup=true&lang.ts
|
|
22889
22937
|
init_HistoryDiffDialog();
|
|
22890
22938
|
init_Icon();
|
|
@@ -23146,6 +23194,7 @@
|
|
|
23146
23194
|
var DisplayConds_default = DisplayConds_vue_vue_type_script_setup_true_lang_default;
|
|
23147
23195
|
//#endregion
|
|
23148
23196
|
//#region packages/editor/src/fields/CondOpSelect.vue?vue&type=script&setup=true&lang.ts
|
|
23197
|
+
init_props();
|
|
23149
23198
|
var CondOpSelect_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ (0, vue.defineComponent)({
|
|
23150
23199
|
name: "MFieldsCondOpSelect",
|
|
23151
23200
|
__name: "CondOpSelect",
|
|
@@ -25067,6 +25116,7 @@
|
|
|
25067
25116
|
exports.UI_SELECT_MODE_EVENT_NAME = UI_SELECT_MODE_EVENT_NAME;
|
|
25068
25117
|
exports.UndoRedo = UndoRedo;
|
|
25069
25118
|
exports.V_GUIDE_LINE_STORAGE_KEY = V_GUIDE_LINE_STORAGE_KEY;
|
|
25119
|
+
exports.ViewForm = ViewForm_default;
|
|
25070
25120
|
exports.advancedTabConfig = advancedTabConfig;
|
|
25071
25121
|
exports.arrayOptions = arrayOptions;
|
|
25072
25122
|
exports.beforePaste = beforePaste;
|
|
@@ -25162,6 +25212,7 @@
|
|
|
25162
25212
|
exports.numberOptions = numberOptions;
|
|
25163
25213
|
exports.openIndexedDB = openIndexedDB;
|
|
25164
25214
|
exports.propsService = props_default;
|
|
25215
|
+
exports.removeStyleDisplayConfig = removeStyleDisplayConfig;
|
|
25165
25216
|
exports.resolveFieldByPath = resolveFieldByPath;
|
|
25166
25217
|
exports.resolveSelectedNode = resolveSelectedNode;
|
|
25167
25218
|
exports.serializeConfig = serializeConfig;
|
|
@@ -25183,6 +25234,7 @@
|
|
|
25183
25234
|
exports.undoFloor = undoFloor;
|
|
25184
25235
|
exports.updateStatus = updateStatus;
|
|
25185
25236
|
exports.useCodeBlockEdit = useCodeBlockEdit;
|
|
25237
|
+
exports.useCompareForm = useCompareForm;
|
|
25186
25238
|
exports.useEditorContentHeight = useEditorContentHeight;
|
|
25187
25239
|
exports.useFilter = useFilter;
|
|
25188
25240
|
exports.useFloatBox = useFloatBox;
|