@tmagic/editor 1.8.0-beta.20 → 1.8.0-beta.22

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 (31) hide show
  1. package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +5 -2
  2. package/dist/es/fields/StyleSetter/components/Box.vue_vue_type_script_setup_true_lang.js +2 -2
  3. package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +6 -1
  4. package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +35 -3
  5. package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +26 -5
  6. package/dist/es/index.js +2 -2
  7. package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +23 -12
  8. package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +1 -1
  9. package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +1 -1
  10. package/dist/es/services/editor.js +12 -8
  11. package/dist/es/services/events.js +2 -2
  12. package/dist/es/utils/dep/idle-task.js +28 -5
  13. package/dist/es/utils/event.js +19 -7
  14. package/dist/es/utils/type-match-rules.js +17 -9
  15. package/dist/tmagic-editor.umd.cjs +173 -57
  16. package/package.json +7 -7
  17. package/src/fields/EventSelect.vue +7 -5
  18. package/src/fields/StyleSetter/components/Box.vue +1 -1
  19. package/src/fields/StyleSetter/components/Position.vue +1 -1
  20. package/src/fields/StyleSetter/pro/Background.vue +7 -0
  21. package/src/fields/StyleSetter/pro/Font.vue +57 -0
  22. package/src/fields/StyleSetter/pro/Position.vue +31 -0
  23. package/src/layouts/props-panel/PropsPanel.vue +30 -16
  24. package/src/layouts/sidebar/ComponentListPanel.vue +5 -1
  25. package/src/layouts/sidebar/layer/LayerPanel.vue +1 -1
  26. package/src/services/editor.ts +27 -8
  27. package/src/services/events.ts +3 -3
  28. package/src/utils/dep/idle-task.ts +43 -11
  29. package/src/utils/event.ts +25 -12
  30. package/src/utils/type-match-rules.ts +37 -4
  31. package/types/index.d.ts +33 -4
@@ -173,7 +173,7 @@ var EventSelect_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
173
173
  name: "name",
174
174
  label: "事件名",
175
175
  type: eventNameConfig.value.type,
176
- options: (mForm, { formValue }) => eventsService.getEvent(formValue.type).map((option) => ({
176
+ options: (mForm, { formValue }) => eventsService.getEvent(formValue.type, { node: editorService.getNodeById(formValue.id) }).map((option) => ({
177
177
  text: option.label,
178
178
  value: option.value
179
179
  }))
@@ -190,7 +190,10 @@ var EventSelect_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
190
190
  options: (mForm, { model }) => {
191
191
  const node = editorService.getNodeById(model.to);
192
192
  if (!node?.type) return [];
193
- return eventsService.getMethod(node.type, model.to).map((option) => ({
193
+ return eventsService.getMethod(node.type, {
194
+ targetId: model.to,
195
+ node
196
+ }).map((option) => ({
194
197
  text: option.label,
195
198
  value: option.value
196
199
  }));
@@ -7,7 +7,7 @@ var _hoisted_2 = {
7
7
  };
8
8
  var _hoisted_3 = { class: "next-input" };
9
9
  var _hoisted_4 = [
10
- "model-value",
10
+ "value",
11
11
  "title",
12
12
  "disabled",
13
13
  "onChange"
@@ -69,7 +69,7 @@ var Box_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompon
69
69
  key: index,
70
70
  class: normalizeClass(item.class)
71
71
  }, [item.text ? (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(item.text), 1)) : createCommentVNode("v-if", true), createElementVNode("span", _hoisted_3, [createElementVNode("input", {
72
- "model-value": __props.model[item.name],
72
+ value: __props.model[item.name],
73
73
  placeholder: "0",
74
74
  title: __props.model[item.name],
75
75
  disabled: __props.disabled,
@@ -4,6 +4,7 @@ import RepeatX_default from "../icons/background-repeat/RepeatX.js";
4
4
  import RepeatY_default from "../icons/background-repeat/RepeatY.js";
5
5
  import NoRepeat_default from "../icons/background-repeat/NoRepeat.js";
6
6
  import { MContainer, defineFormConfig } from "@tmagic/form";
7
+ import { appendValidateSuggestion } from "@tmagic/design";
7
8
  import { Fragment, createBlock, createElementBlock, defineComponent, markRaw, openBlock, renderList, unref } from "vue";
8
9
  //#region packages/editor/src/fields/StyleSetter/pro/Background.vue?vue&type=script&setup=true&lang.ts
9
10
  var Background_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
@@ -26,7 +27,11 @@ var Background_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
26
27
  text: "背景色",
27
28
  labelWidth: "68px",
28
29
  type: "data-source-field-select",
29
- fieldConfig: { type: "colorPicker" }
30
+ fieldConfig: { type: "colorPicker" },
31
+ rules: [{
32
+ typeMatch: true,
33
+ message: appendValidateSuggestion("背景色应为字符串", "请参考以下示例值:\"#000000\"")
34
+ }]
30
35
  },
31
36
  {
32
37
  name: "backgroundImage",
@@ -1,7 +1,9 @@
1
+ import { validateDataSourceFieldSelectValue } from "../../../utils/type-match-rules.js";
1
2
  import Left_default from "../icons/text-align/Left.js";
2
3
  import Center_default from "../icons/text-align/Center.js";
3
4
  import Right_default from "../icons/text-align/Right.js";
4
5
  import { MContainer, defineFormConfig } from "@tmagic/form";
6
+ import { appendValidateSuggestion } from "@tmagic/design";
5
7
  import { Fragment, createBlock, createElementBlock, defineComponent, markRaw, openBlock, renderList, unref } from "vue";
6
8
  //#region packages/editor/src/fields/StyleSetter/pro/Font.vue?vue&type=script&setup=true&lang.ts
7
9
  var Font_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
@@ -25,7 +27,11 @@ var Font_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
25
27
  name: "fontSize",
26
28
  text: "字号",
27
29
  type: "data-source-field-select",
28
- fieldConfig: { type: "text" }
30
+ fieldConfig: { type: "text" },
31
+ rules: [{
32
+ typeMatch: true,
33
+ message: appendValidateSuggestion("字号应为字符串或数字", "请参考以下示例值:24 或 \"24\"")
34
+ }]
29
35
  }, {
30
36
  labelWidth: "68px",
31
37
  name: "lineHeight",
@@ -39,20 +45,46 @@ var Font_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
39
45
  text: "字重",
40
46
  labelWidth: "68px",
41
47
  type: "data-source-field-select",
48
+ dataSourceFieldType: ["string", "number"],
42
49
  fieldConfig: {
43
50
  type: "select",
51
+ allowCreate: true,
44
52
  options: ["normal", "bold"].concat(Array(7).fill(1).map((x, i) => `${i + 1}00`)).map((item) => ({
45
53
  value: item,
46
54
  text: item
47
55
  }))
48
- }
56
+ },
57
+ rules: [{ typeMatch: false }, { validator: ({ value, callback }, { config, model, prop }, mForm) => {
58
+ if (value === "" || value === null || value === void 0) return callback();
59
+ const result = validateDataSourceFieldSelectValue(value, {
60
+ fieldType: "data-source-field-select",
61
+ mForm,
62
+ props: {
63
+ config,
64
+ model,
65
+ prop
66
+ }
67
+ }, { validatePlainValue: (plainValue) => {
68
+ if (typeof plainValue === "string" || typeof plainValue === "number" && !Number.isNaN(plainValue)) return;
69
+ return "字重应为字符串或数字";
70
+ } });
71
+ if (result && typeof result.then === "function") {
72
+ result.then((error) => callback(error), (error) => callback(error));
73
+ return;
74
+ }
75
+ return callback(result);
76
+ } }]
49
77
  },
50
78
  {
51
79
  labelWidth: "68px",
52
80
  name: "color",
53
81
  text: "颜色",
54
82
  type: "data-source-field-select",
55
- fieldConfig: { type: "colorPicker" }
83
+ fieldConfig: { type: "colorPicker" },
84
+ rules: [{
85
+ typeMatch: true,
86
+ message: appendValidateSuggestion("颜色应为字符串", "请参考以下示例值:\"#000000\"")
87
+ }]
56
88
  },
57
89
  {
58
90
  name: "textAlign",
@@ -1,4 +1,5 @@
1
1
  import { MContainer, defineFormConfig } from "@tmagic/form";
2
+ import { appendValidateSuggestion } from "@tmagic/design";
2
3
  import { Fragment, createBlock, createElementBlock, defineComponent, openBlock, renderList, unref } from "vue";
3
4
  //#region packages/editor/src/fields/StyleSetter/pro/Position.vue?vue&type=script&setup=true&lang.ts
4
5
  var Position_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
@@ -44,12 +45,20 @@ var Position_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
44
45
  name: "left",
45
46
  type: "data-source-field-select",
46
47
  text: "left",
47
- fieldConfig: { type: "text" }
48
+ fieldConfig: { type: "text" },
49
+ rules: [{
50
+ typeMatch: true,
51
+ message: appendValidateSuggestion("left 应为字符串", "请参考以下示例值:\"10\"")
52
+ }]
48
53
  }, {
49
54
  name: "top",
50
55
  type: "data-source-field-select",
51
56
  text: "top",
52
- fieldConfig: { type: "text" }
57
+ fieldConfig: { type: "text" },
58
+ rules: [{
59
+ typeMatch: true,
60
+ message: appendValidateSuggestion("top 应为字符串", "请参考以下示例值:\"10\"")
61
+ }]
53
62
  }]
54
63
  },
55
64
  {
@@ -60,12 +69,20 @@ var Position_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
60
69
  name: "right",
61
70
  type: "data-source-field-select",
62
71
  text: "right",
63
- fieldConfig: { type: "text" }
72
+ fieldConfig: { type: "text" },
73
+ rules: [{
74
+ typeMatch: true,
75
+ message: appendValidateSuggestion("right 应为字符串", "请参考以下示例值:\"10\"")
76
+ }]
64
77
  }, {
65
78
  name: "bottom",
66
79
  type: "data-source-field-select",
67
80
  text: "bottom",
68
- fieldConfig: { type: "text" }
81
+ fieldConfig: { type: "text" },
82
+ rules: [{
83
+ typeMatch: true,
84
+ message: appendValidateSuggestion("bottom 应为字符串", "请参考以下示例值:\"10\"")
85
+ }]
69
86
  }]
70
87
  },
71
88
  {
@@ -73,7 +90,11 @@ var Position_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
73
90
  name: "zIndex",
74
91
  text: "zIndex",
75
92
  type: "data-source-field-select",
76
- fieldConfig: { type: "text" }
93
+ fieldConfig: { type: "text" },
94
+ rules: [{
95
+ typeMatch: true,
96
+ message: appendValidateSuggestion("zIndex 应为数字", "请参考以下示例值:10")
97
+ }]
77
98
  }
78
99
  ]);
79
100
  const change = (value, eventData) => {
package/dist/es/index.js CHANGED
@@ -31,7 +31,7 @@ import { IdleTask } from "./utils/dep/idle-task.js";
31
31
  import { ScrollViewer } from "./utils/scroll-viewer.js";
32
32
  import codeBlock_default from "./services/codeBlock.js";
33
33
  import dataSource_default from "./services/dataSource.js";
34
- import { ALL_COND_OPS, editorTypeMatchRules } from "./utils/type-match-rules.js";
34
+ import { ALL_COND_OPS, editorTypeMatchRules, validateDataSourceFieldSelectValue } from "./utils/type-match-rules.js";
35
35
  import events_default from "./services/events.js";
36
36
  import { EVENT_NAME_VALUE_SEPARATOR, collectEventNameOptionValues, getCompActionAllowedValues, getCompActionOptions, getEventNameAllowedValues, getEventNameOptions, isEventNameCheckStrictly, normalizeCompActionValue } from "./utils/event.js";
37
37
  import monaco_editor_default from "./utils/monaco-editor.js";
@@ -92,4 +92,4 @@ export * from "@tmagic/table";
92
92
  export * from "@tmagic/stage";
93
93
  export * from "@tmagic/design";
94
94
  export * from "@tmagic/utils";
95
- export { ALL_COND_OPS, CODE_DRAFT_STORAGE_KEY, COPY_CODE_STORAGE_KEY, COPY_DS_STORAGE_KEY, COPY_STORAGE_KEY, CodeBlockEditor_default as CodeBlockEditor, CodeBlockList_default as CodeBlockList, CodeBlockListPanel_default as CodeBlockListPanel, CodeDeleteErrorType, CodeSelect_default as CodeSelect, CodeSelectCol_default as CodeSelectCol, ColumnLayout, CompareForm_default as CompareForm, ComponentListPanel_default as ComponentListPanel, CondOpSelect_default as CondOpSelect, ContentMenu_default as ContentMenu, DEFAULT_LEFT_COLUMN_WIDTH, DEFAULT_RIGHT_COLUMN_WIDTH, DataSourceAddButton_default as DataSourceAddButton, DataSourceConfigPanel_default as DataSourceConfigPanel, Index_default as DataSourceFieldSelect, DataSourceFields_default as DataSourceFields, DataSourceInput_default as DataSourceInput, DataSourceMethodSelect_default as DataSourceMethodSelect, DataSourceMethods_default as DataSourceMethods, DataSourceMocks_default as DataSourceMocks, DataSourceSelect_default as DataSourceSelect, DepTargetType, DisplayConds_default as DisplayConds, DragType, EVENT_NAME_VALUE_SEPARATOR, EventSelect_default as EventSelect, Fixed2Other, FloatingBox_default as FloatingBox, H_GUIDE_LINE_STORAGE_KEY, HistoryDiffDialog_default as HistoryDiffDialog, Bucket_default as HistoryListBucket, BucketTab_default as HistoryListBucketTab, Icon_default as Icon, IdleTask, KeyBindingCommand, KeyValue_default as KeyValue, Keys, LEFT_COLUMN_WIDTH_STORAGE_KEY, LayerNodeContent_default as LayerNodeContent, LayerOffset, LayerPanel_default as LayerPanel, Layout, SplitView_default as LayoutContainer, MIN_CENTER_COLUMN_WIDTH, MIN_LEFT_COLUMN_WIDTH, MIN_RIGHT_COLUMN_WIDTH, PROPS_PANEL_WIDTH_STORAGE_KEY, PageFragmentSelect_default as PageFragmentSelect, FormPanel_default as PropsFormPanel, PropsPanel_default as PropsPanel, RIGHT_COLUMN_WIDTH_STORAGE_KEY, Resizer_default as Resizer, ScrollViewer, SideItemKey, SplitView_default as SplitView, StageCore, Index_default$1 as StyleSetter, CodeEditor_default as TMagicCodeEditor, Editor_default as TMagicEditor, ToolButton_default as ToolButton, Tree_default as Tree, TreeNode_default as TreeNode, UI_SELECT_MODE_EVENT_NAME, UndoRedo, V_GUIDE_LINE_STORAGE_KEY, ViewForm_default as ViewForm, advancedTabConfig, arrayOptions, beforePaste, booleanOptions, buildChangeRecords, calcAlignCenterStyle, calcLayerTargetIndex, calcMoveStyle, canUsePluginMethods, change2Fixed, classifyDragSources, codeBlock_default as codeBlockService, collectEventNameOptionValues, collectRelatedNodes, componentList_default as componentListService, confirmHistoryAction, createStackStep, dataSource_default as dataSourceService, debug, plugin_default as default, defaultIsExpandable, dep_default as depService, describeRevertStep, describeStepForRevert, deserializeStacks, designPlugin, detectStackOpType, detectTargetId, detectTargetName, displayTabConfig, editorNodeMergeCustomizer, editor_default as editorService, editorTypeMatchRules, eqOptions, error, eventTabConfig, events_default as eventsService, fillConfig, fixNodeLeft, fixNodePosition, formPlugin, generatePageName, generatePageNameByApp, getAddParent, getCascaderOptionsFromFields, getCodeBlockFormConfig, getCompActionAllowedValues, getCompActionOptions, getCondOpOptionsByFieldType, getDefaultConfig, getDisplayField, getEditorConfig, getEventNameAllowedValues, getEventNameOptions, getFieldType, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getLastPushedHistoryIds, getNodeIndex, getOrCreateStack, getPageFragmentList, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, history_default as historyService, idbDelete, idbGet, idbSet, info, isEventNameCheckStrictly, isGlobalFlat, isIncludeDataSource, isIndexedDBSupported, keybinding_default as keybindingService, monaco_editor_default as loadMonaco, log, markStackSaved, mergeSteps, moveItemsInContainer, normalizeCompActionValue, numberOptions, openIndexedDB, props_default as propsService, removeStyleDisplayConfig, resolveFieldByPath, resolveSelectedNode, serializeConfig, serializeStacks, setChildrenLayout, setEditorConfig, setLayout, stageOverlay_default as stageOverlayService, storage_default as storageService, styleTabConfig, tablePlugin, toggleFixedPosition, ui_default as uiService, undoFloor, updateStatus, useCodeBlockEdit, useCompareForm, useEditorContentHeight, useFilter, useFloatBox, useGetSo, useHistoryRevert, useNextFloatBoxPosition, useNodeStatus, useServices, useStage, useWindowRect, warn };
95
+ export { ALL_COND_OPS, CODE_DRAFT_STORAGE_KEY, COPY_CODE_STORAGE_KEY, COPY_DS_STORAGE_KEY, COPY_STORAGE_KEY, CodeBlockEditor_default as CodeBlockEditor, CodeBlockList_default as CodeBlockList, CodeBlockListPanel_default as CodeBlockListPanel, CodeDeleteErrorType, CodeSelect_default as CodeSelect, CodeSelectCol_default as CodeSelectCol, ColumnLayout, CompareForm_default as CompareForm, ComponentListPanel_default as ComponentListPanel, CondOpSelect_default as CondOpSelect, ContentMenu_default as ContentMenu, DEFAULT_LEFT_COLUMN_WIDTH, DEFAULT_RIGHT_COLUMN_WIDTH, DataSourceAddButton_default as DataSourceAddButton, DataSourceConfigPanel_default as DataSourceConfigPanel, Index_default as DataSourceFieldSelect, DataSourceFields_default as DataSourceFields, DataSourceInput_default as DataSourceInput, DataSourceMethodSelect_default as DataSourceMethodSelect, DataSourceMethods_default as DataSourceMethods, DataSourceMocks_default as DataSourceMocks, DataSourceSelect_default as DataSourceSelect, DepTargetType, DisplayConds_default as DisplayConds, DragType, EVENT_NAME_VALUE_SEPARATOR, EventSelect_default as EventSelect, Fixed2Other, FloatingBox_default as FloatingBox, H_GUIDE_LINE_STORAGE_KEY, HistoryDiffDialog_default as HistoryDiffDialog, Bucket_default as HistoryListBucket, BucketTab_default as HistoryListBucketTab, Icon_default as Icon, IdleTask, KeyBindingCommand, KeyValue_default as KeyValue, Keys, LEFT_COLUMN_WIDTH_STORAGE_KEY, LayerNodeContent_default as LayerNodeContent, LayerOffset, LayerPanel_default as LayerPanel, Layout, SplitView_default as LayoutContainer, MIN_CENTER_COLUMN_WIDTH, MIN_LEFT_COLUMN_WIDTH, MIN_RIGHT_COLUMN_WIDTH, PROPS_PANEL_WIDTH_STORAGE_KEY, PageFragmentSelect_default as PageFragmentSelect, FormPanel_default as PropsFormPanel, PropsPanel_default as PropsPanel, RIGHT_COLUMN_WIDTH_STORAGE_KEY, Resizer_default as Resizer, ScrollViewer, SideItemKey, SplitView_default as SplitView, StageCore, Index_default$1 as StyleSetter, CodeEditor_default as TMagicCodeEditor, Editor_default as TMagicEditor, ToolButton_default as ToolButton, Tree_default as Tree, TreeNode_default as TreeNode, UI_SELECT_MODE_EVENT_NAME, UndoRedo, V_GUIDE_LINE_STORAGE_KEY, ViewForm_default as ViewForm, advancedTabConfig, arrayOptions, beforePaste, booleanOptions, buildChangeRecords, calcAlignCenterStyle, calcLayerTargetIndex, calcMoveStyle, canUsePluginMethods, change2Fixed, classifyDragSources, codeBlock_default as codeBlockService, collectEventNameOptionValues, collectRelatedNodes, componentList_default as componentListService, confirmHistoryAction, createStackStep, dataSource_default as dataSourceService, debug, plugin_default as default, defaultIsExpandable, dep_default as depService, describeRevertStep, describeStepForRevert, deserializeStacks, designPlugin, detectStackOpType, detectTargetId, detectTargetName, displayTabConfig, editorNodeMergeCustomizer, editor_default as editorService, editorTypeMatchRules, eqOptions, error, eventTabConfig, events_default as eventsService, fillConfig, fixNodeLeft, fixNodePosition, formPlugin, generatePageName, generatePageNameByApp, getAddParent, getCascaderOptionsFromFields, getCodeBlockFormConfig, getCompActionAllowedValues, getCompActionOptions, getCondOpOptionsByFieldType, getDefaultConfig, getDisplayField, getEditorConfig, getEventNameAllowedValues, getEventNameOptions, getFieldType, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getLastPushedHistoryIds, getNodeIndex, getOrCreateStack, getPageFragmentList, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, history_default as historyService, idbDelete, idbGet, idbSet, info, isEventNameCheckStrictly, isGlobalFlat, isIncludeDataSource, isIndexedDBSupported, keybinding_default as keybindingService, monaco_editor_default as loadMonaco, log, markStackSaved, mergeSteps, moveItemsInContainer, normalizeCompActionValue, numberOptions, openIndexedDB, props_default as propsService, removeStyleDisplayConfig, resolveFieldByPath, resolveSelectedNode, serializeConfig, serializeStacks, setChildrenLayout, setEditorConfig, setLayout, stageOverlay_default as stageOverlayService, storage_default as storageService, styleTabConfig, tablePlugin, toggleFixedPosition, ui_default as uiService, undoFloor, updateStatus, useCodeBlockEdit, useCompareForm, useEditorContentHeight, useFilter, useFloatBox, useGetSo, useHistoryRevert, useNextFloatBoxPosition, useNodeStatus, useServices, useStage, useWindowRect, validateDataSourceFieldSelectValue, warn };
@@ -68,22 +68,33 @@ var PropsPanel_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
68
68
  const submit = async (v, eventData, error, source = "props") => {
69
69
  try {
70
70
  if (!v.id) v.id = values.value.id;
71
- const newValue = {
72
- ...v,
73
- style: {}
74
- };
75
- if (v.style) if (eventData) {
76
- Object.entries(v.style).forEach(([key, value]) => {
77
- if (value !== "" && newValue.style) newValue.style[key] = value;
78
- });
79
- eventData.changeRecords?.forEach((record) => {
80
- if (record.propPath?.startsWith("style") && record.value === "") setValueByKeyPath(record.propPath, record.value, newValue);
81
- });
82
- } else newValue.style = { ...v.style };
83
71
  const historySource = eventData ? "props" : "code";
72
+ const replace = historySource === "code";
73
+ let newValue;
74
+ if (replace) if (source === "style") newValue = {
75
+ ...values.value,
76
+ id: v.id || values.value.id,
77
+ style: { ...v.style || {} }
78
+ };
79
+ else newValue = { ...v };
80
+ else {
81
+ newValue = {
82
+ ...v,
83
+ style: {}
84
+ };
85
+ if (v.style) {
86
+ Object.entries(v.style).forEach(([key, value]) => {
87
+ if (value !== "" && newValue.style) newValue.style[key] = value;
88
+ });
89
+ eventData?.changeRecords?.forEach((record) => {
90
+ if (record.propPath?.startsWith("style") && record.value === "") setValueByKeyPath(record.propPath, record.value, newValue);
91
+ });
92
+ }
93
+ }
84
94
  editorService.update(newValue, {
85
95
  changeRecords: eventData?.changeRecords,
86
96
  historySource,
97
+ replace,
87
98
  ...enablePropsFormValidate && error ? { invalidInfo: {
88
99
  id: newValue.id,
89
100
  source,
@@ -23,7 +23,7 @@ var ComponentListPanel_vue_vue_type_script_setup_true_lang_default = /*@__PURE__
23
23
  const stage = computed(() => editorService.get("stage"));
24
24
  const list = computed(() => componentListService.getList().map((group) => ({
25
25
  ...group,
26
- items: group.items.filter((item) => item.text.includes(searchText.value))
26
+ items: group.items.filter((item) => `${item.text || ""}${item.desc || ""}${item.type}`.toLocaleLowerCase().includes(searchText.value.toLocaleLowerCase()))
27
27
  })));
28
28
  const collapseValue = ref();
29
29
  watch(list, () => {
@@ -39,7 +39,7 @@ var LayerPanel_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
39
39
  let name = "";
40
40
  if (data.name) name = data.name;
41
41
  else if (data.items) name = "container";
42
- return `${data.id}${name}${data.type}`.includes(v);
42
+ return `${data.id}${name}${data.type || ""}`.toLocaleLowerCase().includes(v.toLocaleLowerCase());
43
43
  };
44
44
  const { filterTextChangeHandler } = useFilter(nodeData, nodeStatusMap, filterNodeMethod);
45
45
  const collapseAllHandler = () => {
@@ -467,14 +467,14 @@ var Editor = class extends BaseService {
467
467
  remove: removedPages
468
468
  });
469
469
  }
470
- async doUpdate(config, { changeRecords = [], historySource } = {}) {
470
+ async doUpdate(config, { changeRecords = [], historySource, replace = false } = {}) {
471
471
  if (!this.get("root")) throw new Error("root为空");
472
472
  if (!config?.id) throw new Error("没有配置或者配置缺少id值");
473
473
  const info = this.getNodeInfo(config.id, false);
474
474
  if (!info.node) throw new Error(`获取不到id为${config.id}的节点`);
475
475
  const node = toRaw(info.node);
476
- let newConfig = await toggleFixedPosition(toRaw(config), node, info.path, this.getLayout);
477
- newConfig = mergeWith(cloneDeep$1(node), newConfig, editorNodeMergeCustomizer);
476
+ let newConfig = replace ? cloneDeep$1(toRaw(config)) : await toggleFixedPosition(toRaw(config), node, info.path, this.getLayout);
477
+ if (!replace) newConfig = mergeWith(cloneDeep$1(node), newConfig, editorNodeMergeCustomizer);
478
478
  if (!newConfig.type) throw new Error("配置缺少type值");
479
479
  if (newConfig.type === NodeType.ROOT) {
480
480
  this.set("root", newConfig, { historySource });
@@ -489,9 +489,11 @@ var Editor = class extends BaseService {
489
489
  const parentNodeItems = parent.items;
490
490
  const index = getNodeIndex(newConfig.id, parent);
491
491
  if (!parentNodeItems || typeof index === "undefined" || index === -1) throw new Error("更新的节点未找到");
492
- const newLayout = await this.getLayout(newConfig);
493
- const layout = await this.getLayout(node);
494
- if (Array.isArray(newConfig.items) && newLayout !== layout) newConfig = setChildrenLayout(newConfig, newLayout);
492
+ if (!replace) {
493
+ const newLayout = await this.getLayout(newConfig);
494
+ const layout = await this.getLayout(node);
495
+ if (Array.isArray(newConfig.items) && newLayout !== layout) newConfig = setChildrenLayout(newConfig, newLayout);
496
+ }
495
497
  parentNodeItems[index] = newConfig;
496
498
  const selectedNodes = this.get("nodes");
497
499
  const targetIndex = selectedNodes.findIndex((nodeItem) => `${nodeItem.id}` === `${newConfig.id}`);
@@ -519,17 +521,19 @@ var Editor = class extends BaseService {
519
521
  * @param data.changeRecordList 多节点 form 端变更记录列表,按 config 数组同序对应每个节点;优先级高于 changeRecords
520
522
  * @param data.doNotPushHistory 是否不写入历史记录(默认 false)
521
523
  * @param data.historyDescription 入栈时附带的人类可读描述,用于历史面板展示(不影响 undo/redo 行为)
524
+ * @param data.replace 是否整节点替换:为 true 时跳过 mergeWith / toggleFixedPosition / setChildrenLayout,直接用传入配置覆盖(默认 false)
522
525
  * @returns 更新后的节点配置
523
526
  */
524
527
  async update(config, data = {}) {
525
528
  this.captureSelectionBeforeOp();
526
- const { doNotPushHistory = false, changeRecordList, changeRecords, historyDescription, historySource, invalidInfo } = data;
529
+ const { doNotPushHistory = false, changeRecordList, changeRecords, historyDescription, historySource, replace = false, invalidInfo } = data;
527
530
  const nodes = Array.isArray(config) ? config : [config];
528
531
  const updateData = await Promise.all(nodes.map((node, index) => {
529
532
  const recordsForNode = changeRecordList ? changeRecordList[index] ?? [] : changeRecords ?? [];
530
533
  return this.doUpdate(node, {
531
534
  changeRecords: recordsForNode,
532
- historySource
535
+ historySource,
536
+ replace
533
537
  });
534
538
  }));
535
539
  this.applyInvalidInfo(config, invalidInfo);
@@ -32,7 +32,7 @@ var Events = class extends BaseService {
32
32
  setEvent(type, events) {
33
33
  eventMap[toLine(type)] = [...events];
34
34
  }
35
- getEvent(type) {
35
+ getEvent(type, _data = {}) {
36
36
  return cloneDeep(eventMap[toLine(type)]) || [];
37
37
  }
38
38
  setMethods(methods) {
@@ -43,7 +43,7 @@ var Events = class extends BaseService {
43
43
  setMethod(type, method) {
44
44
  methodMap[toLine(type)] = [...method];
45
45
  }
46
- getMethod(type, _targetId) {
46
+ getMethod(type, _data = {}) {
47
47
  return cloneDeep(methodMap[toLine(type)]) || [];
48
48
  }
49
49
  resetState() {
@@ -1,6 +1,16 @@
1
1
  import { error } from "../logger.js";
2
2
  import { EventEmitter } from "events";
3
3
  //#region packages/editor/src/utils/dep/idle-task.ts
4
+ /**
5
+ * 回调因 timeout 触发(主线程一直没有空闲)时,单次回调执行任务的时间预算,单位 ms
6
+ * 参考一帧内可让出的余量:既保证队列有进展,又不长时间阻塞主线程
7
+ */
8
+ var TIMEOUT_RUN_BUDGET = 5;
9
+ /**
10
+ * 回调因 timeout 触发时,每两次读取时钟之间执行的任务数
11
+ * 与空闲时间 <=5ms 时的批量保持一致,避免每个任务都读一次时钟
12
+ */
13
+ var TIMEOUT_BATCH_SIZE = 10;
4
14
  globalThis.requestIdleCallback = globalThis.requestIdleCallback || function(cb) {
5
15
  const start = Date.now();
6
16
  return setTimeout(() => {
@@ -52,6 +62,13 @@ var IdleTask = class extends EventEmitter {
52
62
  runTaskQueue(deadline) {
53
63
  this.taskHandle = null;
54
64
  try {
65
+ if (deadline.didTimeout) {
66
+ const start = Date.now();
67
+ do
68
+ this.runTaskBatch(TIMEOUT_BATCH_SIZE);
69
+ while (this.getTaskLength() && Date.now() - start < TIMEOUT_RUN_BUDGET);
70
+ return;
71
+ }
55
72
  while (deadline.timeRemaining() > 0 && this.getTaskLength()) {
56
73
  const timeRemaining = deadline.timeRemaining();
57
74
  let times = 0;
@@ -59,17 +76,23 @@ var IdleTask = class extends EventEmitter {
59
76
  else if (timeRemaining <= 10) times = 100;
60
77
  else if (timeRemaining <= 15) times = 300;
61
78
  else times = 600;
62
- for (let i = 0; i < times; i++) {
63
- const task = this.hightLevelTaskList.length > 0 ? this.hightLevelTaskList.shift() : this.taskList.shift();
64
- if (task) this.runTask(task);
65
- if (!this.getTaskLength()) break;
66
- }
79
+ this.runTaskBatch(times);
67
80
  }
68
81
  } finally {
69
82
  this.finishRun();
70
83
  }
71
84
  }
72
85
  /**
86
+ * 执行一批任务,队列被清空时提前结束
87
+ */
88
+ runTaskBatch(times) {
89
+ for (let i = 0; i < times; i++) {
90
+ const task = this.hightLevelTaskList.length > 0 ? this.hightLevelTaskList.shift() : this.taskList.shift();
91
+ if (task) this.runTask(task);
92
+ if (!this.getTaskLength()) break;
93
+ }
94
+ }
95
+ /**
73
96
  * 单个任务失败不能中断整个队列,否则后续任务永远不会被执行,
74
97
  * 依赖收集会停在半路(收集中状态与剩余任务数都不再变化)
75
98
  */
@@ -19,7 +19,8 @@ var normalizeCompActionValue = (value) => {
19
19
  var getEventNameOptions = (src, formValue = {}) => {
20
20
  if (!formValue.type) return [];
21
21
  if (src === "component") {
22
- let events = events_default.getEvent(formValue.type) || [];
22
+ const sourceNode = editor_default.getNodeById(formValue.id);
23
+ let events = events_default.getEvent(formValue.type, { node: sourceNode }) || [];
23
24
  if (formValue.type === "page-fragment-container" && formValue.pageFragmentId) {
24
25
  const pageFragment = editor_default.get("root")?.items?.find((page) => page.id === formValue.pageFragmentId);
25
26
  if (!pageFragment) return [];
@@ -28,9 +29,11 @@ var getEventNameOptions = (src, formValue = {}) => {
28
29
  value: pageFragment.id,
29
30
  children: events
30
31
  }];
31
- (pageFragment.items || []).forEach((node) => {
32
- traverseNode(node, (current) => {
33
- const nodeEvents = current.type && events_default.getEvent(current.type) || [];
32
+ (pageFragment.items || []).forEach((item) => {
33
+ traverseNode(item, (current) => {
34
+ if (!current.type) return;
35
+ const node = editor_default.getNodeById(current.id) || current;
36
+ const nodeEvents = events_default.getEvent(current.type, { node }) || [];
34
37
  events.push({
35
38
  label: `${current.name}_${current.id}`,
36
39
  value: `${current.id}`,
@@ -89,15 +92,24 @@ var getCompActionOptions = (toId) => {
89
92
  if (typeof toId === "undefined" || toId === null || toId === "") return [];
90
93
  const node = editor_default.getNodeById(toId);
91
94
  if (!node?.type) return [];
92
- let methods = events_default.getMethod(node.type, toId) || [];
95
+ let methods = events_default.getMethod(node.type, {
96
+ targetId: toId,
97
+ node
98
+ }) || [];
93
99
  if (node.type === "page-fragment-container" && node.pageFragmentId) {
94
100
  const pageFragment = editor_default.get("root")?.items?.find((page) => page.id === node.pageFragmentId);
95
101
  if (!pageFragment) return [];
96
102
  methods = [];
97
103
  (pageFragment.items || []).forEach((item) => {
98
104
  traverseNode(item, (current) => {
99
- const nodeMethods = current.type && events_default.getMethod(current.type, current.id) || [];
100
- if (nodeMethods.length) methods.push({
105
+ const node = editor_default.getNodeById(current.id) || current;
106
+ if (!current.type) return;
107
+ const nodeMethods = events_default.getMethod(current.type, {
108
+ targetId: current.id,
109
+ node
110
+ }) || [];
111
+ if (!nodeMethods.length) return;
112
+ methods.push({
101
113
  label: `${current.name}_${current.id}`,
102
114
  value: `${current.id}`,
103
115
  children: nodeMethods
@@ -268,15 +268,22 @@ var isDataSourceFieldPathValue = (value, config) => {
268
268
  if (config.value === "key") return true;
269
269
  return `${value[0]}`.startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX);
270
270
  };
271
- var validateDataSourceFieldSelect = (value, { mForm, message, props }) => {
271
+ /**
272
+ * data-source-field-select 的 typeMatch 校验逻辑,可供自定义 rules.validator 复用。
273
+ */
274
+ var validateDataSourceFieldSelectValue = (value, context, options) => {
275
+ const { mForm, message, props } = context;
272
276
  const config = props.config || {};
273
- if (config.fieldConfig && !isDataSourceFieldPathValue(value, config)) return validateTypeMatch(value, mForm, {
274
- ...props,
275
- config: {
276
- name: config.name,
277
- ...config.fieldConfig
278
- }
279
- }, message);
277
+ if (!isDataSourceFieldPathValue(value, config)) {
278
+ if (options?.validatePlainValue) return options.validatePlainValue(value, context);
279
+ if (config.fieldConfig) return validateTypeMatch(value, mForm, {
280
+ ...props,
281
+ config: {
282
+ name: config.name,
283
+ ...config.fieldConfig
284
+ }
285
+ }, message);
286
+ }
280
287
  if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) return defaultMessage(message, `${value}类型应为字符串数组`, dataSourceFieldPathSuggestion());
281
288
  return validateDataSourceFieldPath(value, {
282
289
  dataSourceId: config.dataSourceId,
@@ -285,6 +292,7 @@ var validateDataSourceFieldSelect = (value, { mForm, message, props }) => {
285
292
  message
286
293
  });
287
294
  };
295
+ var validateDataSourceFieldSelect = (value, context) => validateDataSourceFieldSelectValue(value, context);
288
296
  var validateDataSourceSelect = (value, { message, props }) => {
289
297
  const config = props.config || {};
290
298
  const dataSources = getDataSources();
@@ -364,4 +372,4 @@ var editorTypeMatchRules = {
364
372
  "display-conds": validateDisplayConds
365
373
  };
366
374
  //#endregion
367
- export { ALL_COND_OPS, editorTypeMatchRules };
375
+ export { ALL_COND_OPS, editorTypeMatchRules, validateDataSourceFieldSelectValue };