@dckj-npm/dc-material 0.1.370 → 0.1.372

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.
@@ -68,41 +68,49 @@ const getImageStyleNumber = (target: any, styleKey: 'width' | 'height'): number
68
68
  return parsePxNumber(imageChildSchema?.props?.style?.[styleKey])
69
69
  }
70
70
 
71
- const syncImageStyleValue = (target: any, styleKey: 'width' | 'height', value: number) => {
72
- // 优先通过引擎节点 API 更新子节点 style,确保引擎感知变化(布局面板读取时可见)
73
- const imageChildNode = findImageChildNode(target)
74
- if (imageChildNode) {
75
- const currentStyle = imageChildNode.getPropValue?.('style') || {}
76
- // 同时确保 width/height 都存在于子节点 style 中,防止布局面板 replace 时丢失其中一个
77
- const updatedStyle: Record<string, any> = { ...currentStyle, [styleKey]: `${value}px` }
78
- // 如果另一轴尺寸在子节点 style 中不存在,则从父级 prop 补充,保证两轴都写入
79
- const otherKey = styleKey === 'width' ? 'height' : 'width'
80
- if (!updatedStyle[otherKey]) {
81
- const otherPropKey = otherKey === 'width' ? 'imgWidth' : 'imgHeight'
82
- const otherPropValue = parsePxNumber(target?.getProps?.()?.getPropValue?.(otherPropKey))
83
- if (otherPropValue !== undefined) {
84
- updatedStyle[otherKey] = `${otherPropValue}px`
85
- } else {
86
- // 子节点 style 也没有,使用默认值 100
87
- updatedStyle[otherKey] = '100px'
71
+ /**
72
+ * 异步写入 Image 子节点的 style,避免在 imgWidth/imgHeight.setValue 的同步执行栈内
73
+ * 触发引擎重评估 dataList.initialValue(会先清空 dataList prop,导致默认图覆盖绑定数据)。
74
+ * 通过 Promise.resolve().then() 将写入推迟到当前 settings 重评估完成后执行,
75
+ * 此时 dataList 已稳定为正确的 JSExpression,重评估无副作用。
76
+ */
77
+ const syncImageStyleValue = (target: any, styleKey: 'width' | 'height', value: number): void => {
78
+ Promise.resolve().then(() => {
79
+ // 优先通过引擎节点 API 更新子节点 style,确保引擎感知变化(布局面板读取时可见)
80
+ const imageChildNode = findImageChildNode(target)
81
+ if (imageChildNode) {
82
+ const currentStyle = imageChildNode.getPropValue?.('style') || {}
83
+ // 同时确保 width/height 都存在于子节点 style 中,防止布局面板 replace 时丢失其中一个
84
+ const updatedStyle: Record<string, any> = { ...currentStyle, [styleKey]: `${value}px` }
85
+ // 如果另一轴尺寸在子节点 style 中不存在,则从父级 prop 补充,保证两轴都写入
86
+ const otherKey = styleKey === 'width' ? 'height' : 'width'
87
+ if (!updatedStyle[otherKey]) {
88
+ const otherPropKey = otherKey === 'width' ? 'imgWidth' : 'imgHeight'
89
+ const otherPropValue = parsePxNumber(target?.getProps?.()?.getPropValue?.(otherPropKey))
90
+ if (otherPropValue !== undefined) {
91
+ updatedStyle[otherKey] = `${otherPropValue}px`
92
+ } else {
93
+ // 子节点 style 也没有,使用默认值 100
94
+ updatedStyle[otherKey] = '100px'
95
+ }
88
96
  }
97
+ imageChildNode.setPropValue?.('style', updatedStyle)
98
+ return
89
99
  }
90
- imageChildNode.setPropValue?.('style', updatedStyle)
91
- return
92
- }
93
- // 降级:直接写 schema(引擎无法感知,但保留作为兜底)
94
- const imageChildSchema = findImageChildSchema(target)
95
- if (!imageChildSchema) {
96
- return
97
- }
98
- if (!imageChildSchema.props) {
99
- imageChildSchema.props = {}
100
- }
101
- const currentStyle = imageChildSchema.props.style || {}
102
- imageChildSchema.props.style = {
103
- ...currentStyle,
104
- [styleKey]: `${value}px`,
105
- }
100
+ // 降级:直接写 schema(引擎无法感知,但保留作为兜底)
101
+ const imageChildSchema = findImageChildSchema(target)
102
+ if (!imageChildSchema) {
103
+ return
104
+ }
105
+ if (!imageChildSchema.props) {
106
+ imageChildSchema.props = {}
107
+ }
108
+ const currentStyle = imageChildSchema.props.style || {}
109
+ imageChildSchema.props.style = {
110
+ ...currentStyle,
111
+ [styleKey]: `${value}px`,
112
+ }
113
+ })
106
114
  }
107
115
 
108
116
  const syncImageDimensionPropsFromChild = (target: any) => {
@@ -365,17 +373,11 @@ const TeletextListMeta: IPublicTypeComponentMetadata = {
365
373
  return
366
374
  }
367
375
  const props = target.getProps()
368
- // 在任何 setPropValue 之前先写入模块级缓存(与 imagePlacement.setValue 同策略)
376
+ // 在写入前先更新模块级缓存,确保async syncImageStyleValue触发的重评估时缓存有效
369
377
  _cacheDataList(target)
370
- // 快照需要保护的数据,防止 syncImageStyleValue → imageChildNode.setPropValue
371
- // 触发引擎重评估 dataList.initialValue,导致 dataList 被重置为默认图
372
- const prevDataList = props.getPropValue('dataList')
373
- const prevDataListBind = props.getPropValue('dataListBind')
374
378
  props.setPropValue('imgWidth', parsedValue)
379
+ // syncImageStyleValue 异步执行,不在当前同步栈内触发 dataList.initialValue 重评估
375
380
  syncImageStyleValue(target, 'width', parsedValue)
376
- // 还原被保护的数据(幂等操作,若引擎未重置则无副作用)
377
- if (prevDataList !== undefined) props.setPropValue('dataList', prevDataList)
378
- if (prevDataListBind !== undefined) props.setPropValue('dataListBind', prevDataListBind)
379
381
  },
380
382
  },
381
383
  },
@@ -434,17 +436,11 @@ const TeletextListMeta: IPublicTypeComponentMetadata = {
434
436
  return
435
437
  }
436
438
  const props = target.getProps()
437
- // 在任何 setPropValue 之前先写入模块级缓存(与 imagePlacement.setValue 同策略)
439
+ // 在写入前先更新模块级缓存,确保async syncImageStyleValue触发的重评估时缓存有效
438
440
  _cacheDataList(target)
439
- // 快照需要保护的数据,防止 syncImageStyleValue → imageChildNode.setPropValue
440
- // 触发引擎重评估 dataList.initialValue,导致 dataList 被重置为默认图
441
- const prevDataList = props.getPropValue('dataList')
442
- const prevDataListBind = props.getPropValue('dataListBind')
443
441
  props.setPropValue('imgHeight', parsedValue)
442
+ // syncImageStyleValue 异步执行,不在当前同步栈内触发 dataList.initialValue 重评估
444
443
  syncImageStyleValue(target, 'height', parsedValue)
445
- // 还原被保护的数据(幂等操作,若引擎未重置则无副作用)
446
- if (prevDataList !== undefined) props.setPropValue('dataList', prevDataList)
447
- if (prevDataListBind !== undefined) props.setPropValue('dataListBind', prevDataListBind)
448
444
  },
449
445
  },
450
446
  },
@@ -961,16 +957,22 @@ const TeletextListMeta: IPublicTypeComponentMetadata = {
961
957
  // 2. 模块级 WeakMap 缓存(在任何 setPropValue 之前写入,完全不受引擎清空影响)
962
958
  // 3. settings API(重评估中间态下可能已清空,作为最后手段)
963
959
  // 4. 默认占位数据(仅首次创建组件时触达)
960
+ //
961
+ // 关键防御:一旦组件已绑定数据源(缓存或 node 中有值),
962
+ // 无论是哪种场景的 initialValue 调用,都必须返回已有值而不是默认数组。
963
+ // syncImageStyleValue 改为异步后,通常 node.getPropValue 已能拿到正确值;
964
+ // 缓存作为最后一道防线,彻底切断默认数组覆盖绑定表达式的可能。
964
965
  const node = target?.node
966
+ // 优先读缓存:即使 node.getPropValue 暂时处于中间态,缓存也能提供可靠值
967
+ const cached = node ? _nodeDataListCache.get(node) : undefined
965
968
  const fromNode = node?.getPropValue?.('dataList')
966
969
  if (fromNode !== undefined) {
967
970
  // 同步更新缓存,为后续可能的重评估提供后备
968
971
  if (node) _nodeDataListCache.set(node, fromNode)
969
972
  return fromNode
970
973
  }
971
- // node.getPropValue 返回 undefined:引擎已在调用 initialValue 前清空 node prop
974
+ // node.getPropValue 返回 undefined:引擎可能已在调用 initialValue 前清空 node prop
972
975
  // → 读取模块级缓存(在 setValue 中任何 setPropValue 之前写入,最可靠的后备)
973
- const cached = node ? _nodeDataListCache.get(node) : undefined
974
976
  if (cached !== undefined) {
975
977
  return cached
976
978
  }
@@ -1029,20 +1031,32 @@ const TeletextListMeta: IPublicTypeComponentMetadata = {
1029
1031
  return cached // undefined 仅在缓存为空(全新组件首次初始化)时出现,属正常情况
1030
1032
  },
1031
1033
  /**
1032
- * 自定义 setValue:用户每次编辑 dataList 条目时即时更新 WeakMap 缓存。
1033
- * 这是保证缓存与用户实际数据保持同步的关键——之前缓存只在
1034
- * imgWidth/imgHeight/imagePlacement.setValue 中写入,用户直接编辑 dataList
1035
- * 时缓存一直停留在初始默认值,导致 margin 修改时从缓存取出默认图数组。
1034
+ * 自定义 setValue:用户每次编辑 dataList 条目时,先更新 WeakMap 缓存,
1035
+ * 再通过 node.setPropValue 将值持久化到 schema。
1036
+ *
1037
+ * ⚠️ 此引擎中 extraProps.setValue 完全接管写入逻辑,引擎不会自动持久化:
1038
+ * 若不在此处显式调用 setPropValue,用户编辑的数据将只存于内存缓存,
1039
+ * 页面刷新后丢失,同时 imgWidth/imgHeight.setValue 的快照–还原机制也因
1040
+ * props.getPropValue('dataList') 返回 undefined 而失效,导致还原跳过,
1041
+ * 进而触发引擎 initDefaultValue,画布回退默认图。
1042
+ *
1043
+ * 写入顺序:先缓存(供 initialValue/getValue 兜底),再写 schema(持久化)。
1044
+ * 写入 schema 会触发引擎对 settings 的重评估,但此时 schema 已有值,
1045
+ * initialValue 不会被调用,不会产生循环。
1036
1046
  */
1037
1047
  setValue: (target: any, value: any) => {
1038
1048
  const node = target?.node
1039
1049
  if (!node) return
1040
1050
  if (value !== undefined) {
1051
+ // 先写缓存,确保重评估期间 getValue 可从缓存返回有效值
1041
1052
  _nodeDataListCache.set(node, value)
1053
+ // 再持久化到 schema(引擎不会自动写入,必须显式调用)
1054
+ target.getProps?.()?.setPropValue?.('dataList', value)
1042
1055
  } else {
1043
1056
  // clearValue 场景(value = undefined):清空缓存,使下次 initDefaultValue
1044
1057
  // 可正常返回默认数组(仅用于组件被显式清除数据的情况)
1045
1058
  _nodeDataListCache.delete(node)
1059
+ target.getProps?.()?.setPropValue?.('dataList', undefined)
1046
1060
  }
1047
1061
  },
1048
1062
  },
@@ -117,7 +117,7 @@ function fillRealVersion(meta, packageName, version, basicLibraryVersion) {
117
117
  packageName = '@dckj-npm/dc-material';
118
118
  }
119
119
  if (version === void 0) {
120
- version = '0.1.370';
120
+ version = '0.1.372';
121
121
  }
122
122
  if (basicLibraryVersion === void 0) {
123
123
  basicLibraryVersion = {
@@ -64,41 +64,50 @@ var getImageStyleNumber = function getImageStyleNumber(target, styleKey) {
64
64
  var imageChildSchema = findImageChildSchema(target);
65
65
  return parsePxNumber(imageChildSchema === null || imageChildSchema === void 0 ? void 0 : (_imageChildSchema$pro = imageChildSchema.props) === null || _imageChildSchema$pro === void 0 ? void 0 : (_imageChildSchema$pro2 = _imageChildSchema$pro.style) === null || _imageChildSchema$pro2 === void 0 ? void 0 : _imageChildSchema$pro2[styleKey]);
66
66
  };
67
+
68
+ /**
69
+ * 异步写入 Image 子节点的 style,避免在 imgWidth/imgHeight.setValue 的同步执行栈内
70
+ * 触发引擎重评估 dataList.initialValue(会先清空 dataList prop,导致默认图覆盖绑定数据)。
71
+ * 通过 Promise.resolve().then() 将写入推迟到当前 settings 重评估完成后执行,
72
+ * 此时 dataList 已稳定为正确的 JSExpression,重评估无副作用。
73
+ */
67
74
  var syncImageStyleValue = function syncImageStyleValue(target, styleKey, value) {
68
- var _extends3;
69
- // 优先通过引擎节点 API 更新子节点 style,确保引擎感知变化(布局面板读取时可见)
70
- var imageChildNode = findImageChildNode(target);
71
- if (imageChildNode) {
72
- var _imageChildNode$getPr3, _extends2, _imageChildNode$setPr;
73
- var _currentStyle = ((_imageChildNode$getPr3 = imageChildNode.getPropValue) === null || _imageChildNode$getPr3 === void 0 ? void 0 : _imageChildNode$getPr3.call(imageChildNode, 'style')) || {};
74
- // 同时确保 width/height 都存在于子节点 style 中,防止布局面板 replace 时丢失其中一个
75
- var updatedStyle = _extends({}, _currentStyle, (_extends2 = {}, _extends2[styleKey] = value + "px", _extends2));
76
- // 如果另一轴尺寸在子节点 style 中不存在,则从父级 prop 补充,保证两轴都写入
77
- var otherKey = styleKey === 'width' ? 'height' : 'width';
78
- if (!updatedStyle[otherKey]) {
79
- var _target$getProps, _target$getProps$call, _target$getProps$call2;
80
- var otherPropKey = otherKey === 'width' ? 'imgWidth' : 'imgHeight';
81
- var otherPropValue = parsePxNumber(target === null || target === void 0 ? void 0 : (_target$getProps = target.getProps) === null || _target$getProps === void 0 ? void 0 : (_target$getProps$call = _target$getProps.call(target)) === null || _target$getProps$call === void 0 ? void 0 : (_target$getProps$call2 = _target$getProps$call.getPropValue) === null || _target$getProps$call2 === void 0 ? void 0 : _target$getProps$call2.call(_target$getProps$call, otherPropKey));
82
- if (otherPropValue !== undefined) {
83
- updatedStyle[otherKey] = otherPropValue + "px";
84
- } else {
85
- // 子节点 style 也没有,使用默认值 100
86
- updatedStyle[otherKey] = '100px';
75
+ Promise.resolve().then(function () {
76
+ var _extends3;
77
+ // 优先通过引擎节点 API 更新子节点 style,确保引擎感知变化(布局面板读取时可见)
78
+ var imageChildNode = findImageChildNode(target);
79
+ if (imageChildNode) {
80
+ var _imageChildNode$getPr3, _extends2, _imageChildNode$setPr;
81
+ var _currentStyle = ((_imageChildNode$getPr3 = imageChildNode.getPropValue) === null || _imageChildNode$getPr3 === void 0 ? void 0 : _imageChildNode$getPr3.call(imageChildNode, 'style')) || {};
82
+ // 同时确保 width/height 都存在于子节点 style 中,防止布局面板 replace 时丢失其中一个
83
+ var updatedStyle = _extends({}, _currentStyle, (_extends2 = {}, _extends2[styleKey] = value + "px", _extends2));
84
+ // 如果另一轴尺寸在子节点 style 中不存在,则从父级 prop 补充,保证两轴都写入
85
+ var otherKey = styleKey === 'width' ? 'height' : 'width';
86
+ if (!updatedStyle[otherKey]) {
87
+ var _target$getProps, _target$getProps$call, _target$getProps$call2;
88
+ var otherPropKey = otherKey === 'width' ? 'imgWidth' : 'imgHeight';
89
+ var otherPropValue = parsePxNumber(target === null || target === void 0 ? void 0 : (_target$getProps = target.getProps) === null || _target$getProps === void 0 ? void 0 : (_target$getProps$call = _target$getProps.call(target)) === null || _target$getProps$call === void 0 ? void 0 : (_target$getProps$call2 = _target$getProps$call.getPropValue) === null || _target$getProps$call2 === void 0 ? void 0 : _target$getProps$call2.call(_target$getProps$call, otherPropKey));
90
+ if (otherPropValue !== undefined) {
91
+ updatedStyle[otherKey] = otherPropValue + "px";
92
+ } else {
93
+ // 子节点 style 也没有,使用默认值 100
94
+ updatedStyle[otherKey] = '100px';
95
+ }
87
96
  }
97
+ (_imageChildNode$setPr = imageChildNode.setPropValue) === null || _imageChildNode$setPr === void 0 ? void 0 : _imageChildNode$setPr.call(imageChildNode, 'style', updatedStyle);
98
+ return;
88
99
  }
89
- (_imageChildNode$setPr = imageChildNode.setPropValue) === null || _imageChildNode$setPr === void 0 ? void 0 : _imageChildNode$setPr.call(imageChildNode, 'style', updatedStyle);
90
- return;
91
- }
92
- // 降级:直接写 schema(引擎无法感知,但保留作为兜底)
93
- var imageChildSchema = findImageChildSchema(target);
94
- if (!imageChildSchema) {
95
- return;
96
- }
97
- if (!imageChildSchema.props) {
98
- imageChildSchema.props = {};
99
- }
100
- var currentStyle = imageChildSchema.props.style || {};
101
- imageChildSchema.props.style = _extends({}, currentStyle, (_extends3 = {}, _extends3[styleKey] = value + "px", _extends3));
100
+ // 降级:直接写 schema(引擎无法感知,但保留作为兜底)
101
+ var imageChildSchema = findImageChildSchema(target);
102
+ if (!imageChildSchema) {
103
+ return;
104
+ }
105
+ if (!imageChildSchema.props) {
106
+ imageChildSchema.props = {};
107
+ }
108
+ var currentStyle = imageChildSchema.props.style || {};
109
+ imageChildSchema.props.style = _extends({}, currentStyle, (_extends3 = {}, _extends3[styleKey] = value + "px", _extends3));
110
+ });
102
111
  };
103
112
  var syncImageDimensionPropsFromChild = function syncImageDimensionPropsFromChild(target) {
104
113
  var _target$getProps2;
@@ -336,17 +345,11 @@ var TeletextListMeta = {
336
345
  return;
337
346
  }
338
347
  var props = target.getProps();
339
- // 在任何 setPropValue 之前先写入模块级缓存(与 imagePlacement.setValue 同策略)
348
+ // 在写入前先更新模块级缓存,确保async syncImageStyleValue触发的重评估时缓存有效
340
349
  _cacheDataList(target);
341
- // 快照需要保护的数据,防止 syncImageStyleValue → imageChildNode.setPropValue
342
- // 触发引擎重评估 dataList.initialValue,导致 dataList 被重置为默认图
343
- var prevDataList = props.getPropValue('dataList');
344
- var prevDataListBind = props.getPropValue('dataListBind');
345
350
  props.setPropValue('imgWidth', parsedValue);
351
+ // syncImageStyleValue 异步执行,不在当前同步栈内触发 dataList.initialValue 重评估
346
352
  syncImageStyleValue(target, 'width', parsedValue);
347
- // 还原被保护的数据(幂等操作,若引擎未重置则无副作用)
348
- if (prevDataList !== undefined) props.setPropValue('dataList', prevDataList);
349
- if (prevDataListBind !== undefined) props.setPropValue('dataListBind', prevDataListBind);
350
353
  }
351
354
  }
352
355
  }, {
@@ -407,17 +410,11 @@ var TeletextListMeta = {
407
410
  return;
408
411
  }
409
412
  var props = target.getProps();
410
- // 在任何 setPropValue 之前先写入模块级缓存(与 imagePlacement.setValue 同策略)
413
+ // 在写入前先更新模块级缓存,确保async syncImageStyleValue触发的重评估时缓存有效
411
414
  _cacheDataList(target);
412
- // 快照需要保护的数据,防止 syncImageStyleValue → imageChildNode.setPropValue
413
- // 触发引擎重评估 dataList.initialValue,导致 dataList 被重置为默认图
414
- var prevDataList = props.getPropValue('dataList');
415
- var prevDataListBind = props.getPropValue('dataListBind');
416
415
  props.setPropValue('imgHeight', parsedValue);
416
+ // syncImageStyleValue 异步执行,不在当前同步栈内触发 dataList.initialValue 重评估
417
417
  syncImageStyleValue(target, 'height', parsedValue);
418
- // 还原被保护的数据(幂等操作,若引擎未重置则无副作用)
419
- if (prevDataList !== undefined) props.setPropValue('dataList', prevDataList);
420
- if (prevDataListBind !== undefined) props.setPropValue('dataListBind', prevDataListBind);
421
418
  }
422
419
  }
423
420
  }, {
@@ -893,16 +890,22 @@ var TeletextListMeta = {
893
890
  // 2. 模块级 WeakMap 缓存(在任何 setPropValue 之前写入,完全不受引擎清空影响)
894
891
  // 3. settings API(重评估中间态下可能已清空,作为最后手段)
895
892
  // 4. 默认占位数据(仅首次创建组件时触达)
893
+ //
894
+ // 关键防御:一旦组件已绑定数据源(缓存或 node 中有值),
895
+ // 无论是哪种场景的 initialValue 调用,都必须返回已有值而不是默认数组。
896
+ // syncImageStyleValue 改为异步后,通常 node.getPropValue 已能拿到正确值;
897
+ // 缓存作为最后一道防线,彻底切断默认数组覆盖绑定表达式的可能。
896
898
  var node = target === null || target === void 0 ? void 0 : target.node;
899
+ // 优先读缓存:即使 node.getPropValue 暂时处于中间态,缓存也能提供可靠值
900
+ var cached = node ? _nodeDataListCache.get(node) : undefined;
897
901
  var fromNode = node === null || node === void 0 ? void 0 : (_node$getPropValue2 = node.getPropValue) === null || _node$getPropValue2 === void 0 ? void 0 : _node$getPropValue2.call(node, 'dataList');
898
902
  if (fromNode !== undefined) {
899
903
  // 同步更新缓存,为后续可能的重评估提供后备
900
904
  if (node) _nodeDataListCache.set(node, fromNode);
901
905
  return fromNode;
902
906
  }
903
- // node.getPropValue 返回 undefined:引擎已在调用 initialValue 前清空 node prop
907
+ // node.getPropValue 返回 undefined:引擎可能已在调用 initialValue 前清空 node prop
904
908
  // → 读取模块级缓存(在 setValue 中任何 setPropValue 之前写入,最可靠的后备)
905
- var cached = node ? _nodeDataListCache.get(node) : undefined;
906
909
  if (cached !== undefined) {
907
910
  return cached;
908
911
  }
@@ -953,20 +956,34 @@ var TeletextListMeta = {
953
956
  return cached; // undefined 仅在缓存为空(全新组件首次初始化)时出现,属正常情况
954
957
  },
955
958
  /**
956
- * 自定义 setValue:用户每次编辑 dataList 条目时即时更新 WeakMap 缓存。
957
- * 这是保证缓存与用户实际数据保持同步的关键——之前缓存只在
958
- * imgWidth/imgHeight/imagePlacement.setValue 中写入,用户直接编辑 dataList
959
- * 时缓存一直停留在初始默认值,导致 margin 修改时从缓存取出默认图数组。
959
+ * 自定义 setValue:用户每次编辑 dataList 条目时,先更新 WeakMap 缓存,
960
+ * 再通过 node.setPropValue 将值持久化到 schema。
961
+ *
962
+ * ⚠️ 此引擎中 extraProps.setValue 完全接管写入逻辑,引擎不会自动持久化:
963
+ * 若不在此处显式调用 setPropValue,用户编辑的数据将只存于内存缓存,
964
+ * 页面刷新后丢失,同时 imgWidth/imgHeight.setValue 的快照–还原机制也因
965
+ * props.getPropValue('dataList') 返回 undefined 而失效,导致还原跳过,
966
+ * 进而触发引擎 initDefaultValue,画布回退默认图。
967
+ *
968
+ * 写入顺序:先缓存(供 initialValue/getValue 兜底),再写 schema(持久化)。
969
+ * 写入 schema 会触发引擎对 settings 的重评估,但此时 schema 已有值,
970
+ * initialValue 不会被调用,不会产生循环。
960
971
  */
961
972
  setValue: function setValue(target, value) {
962
973
  var node = target === null || target === void 0 ? void 0 : target.node;
963
974
  if (!node) return;
964
975
  if (value !== undefined) {
976
+ var _target$getProps10, _target$getProps10$ca, _target$getProps10$ca2;
977
+ // 先写缓存,确保重评估期间 getValue 可从缓存返回有效值
965
978
  _nodeDataListCache.set(node, value);
979
+ // 再持久化到 schema(引擎不会自动写入,必须显式调用)
980
+ (_target$getProps10 = target.getProps) === null || _target$getProps10 === void 0 ? void 0 : (_target$getProps10$ca = _target$getProps10.call(target)) === null || _target$getProps10$ca === void 0 ? void 0 : (_target$getProps10$ca2 = _target$getProps10$ca.setPropValue) === null || _target$getProps10$ca2 === void 0 ? void 0 : _target$getProps10$ca2.call(_target$getProps10$ca, 'dataList', value);
966
981
  } else {
982
+ var _target$getProps11, _target$getProps11$ca, _target$getProps11$ca2;
967
983
  // clearValue 场景(value = undefined):清空缓存,使下次 initDefaultValue
968
984
  // 可正常返回默认数组(仅用于组件被显式清除数据的情况)
969
985
  _nodeDataListCache["delete"](node);
986
+ (_target$getProps11 = target.getProps) === null || _target$getProps11 === void 0 ? void 0 : (_target$getProps11$ca = _target$getProps11.call(target)) === null || _target$getProps11$ca === void 0 ? void 0 : (_target$getProps11$ca2 = _target$getProps11$ca.setPropValue) === null || _target$getProps11$ca2 === void 0 ? void 0 : _target$getProps11$ca2.call(_target$getProps11$ca, 'dataList', undefined);
970
987
  }
971
988
  }
972
989
  }
@@ -122,7 +122,7 @@ function fillRealVersion(meta, packageName, version, basicLibraryVersion) {
122
122
  packageName = '@dckj-npm/dc-material';
123
123
  }
124
124
  if (version === void 0) {
125
- version = '0.1.370';
125
+ version = '0.1.372';
126
126
  }
127
127
  if (basicLibraryVersion === void 0) {
128
128
  basicLibraryVersion = {
@@ -69,41 +69,50 @@ var getImageStyleNumber = function getImageStyleNumber(target, styleKey) {
69
69
  var imageChildSchema = findImageChildSchema(target);
70
70
  return parsePxNumber(imageChildSchema === null || imageChildSchema === void 0 ? void 0 : (_imageChildSchema$pro = imageChildSchema.props) === null || _imageChildSchema$pro === void 0 ? void 0 : (_imageChildSchema$pro2 = _imageChildSchema$pro.style) === null || _imageChildSchema$pro2 === void 0 ? void 0 : _imageChildSchema$pro2[styleKey]);
71
71
  };
72
+
73
+ /**
74
+ * 异步写入 Image 子节点的 style,避免在 imgWidth/imgHeight.setValue 的同步执行栈内
75
+ * 触发引擎重评估 dataList.initialValue(会先清空 dataList prop,导致默认图覆盖绑定数据)。
76
+ * 通过 Promise.resolve().then() 将写入推迟到当前 settings 重评估完成后执行,
77
+ * 此时 dataList 已稳定为正确的 JSExpression,重评估无副作用。
78
+ */
72
79
  var syncImageStyleValue = function syncImageStyleValue(target, styleKey, value) {
73
- var _extends3;
74
- // 优先通过引擎节点 API 更新子节点 style,确保引擎感知变化(布局面板读取时可见)
75
- var imageChildNode = findImageChildNode(target);
76
- if (imageChildNode) {
77
- var _imageChildNode$getPr3, _extends2, _imageChildNode$setPr;
78
- var _currentStyle = ((_imageChildNode$getPr3 = imageChildNode.getPropValue) === null || _imageChildNode$getPr3 === void 0 ? void 0 : _imageChildNode$getPr3.call(imageChildNode, 'style')) || {};
79
- // 同时确保 width/height 都存在于子节点 style 中,防止布局面板 replace 时丢失其中一个
80
- var updatedStyle = (0, _extends4["default"])({}, _currentStyle, (_extends2 = {}, _extends2[styleKey] = value + "px", _extends2));
81
- // 如果另一轴尺寸在子节点 style 中不存在,则从父级 prop 补充,保证两轴都写入
82
- var otherKey = styleKey === 'width' ? 'height' : 'width';
83
- if (!updatedStyle[otherKey]) {
84
- var _target$getProps, _target$getProps$call, _target$getProps$call2;
85
- var otherPropKey = otherKey === 'width' ? 'imgWidth' : 'imgHeight';
86
- var otherPropValue = parsePxNumber(target === null || target === void 0 ? void 0 : (_target$getProps = target.getProps) === null || _target$getProps === void 0 ? void 0 : (_target$getProps$call = _target$getProps.call(target)) === null || _target$getProps$call === void 0 ? void 0 : (_target$getProps$call2 = _target$getProps$call.getPropValue) === null || _target$getProps$call2 === void 0 ? void 0 : _target$getProps$call2.call(_target$getProps$call, otherPropKey));
87
- if (otherPropValue !== undefined) {
88
- updatedStyle[otherKey] = otherPropValue + "px";
89
- } else {
90
- // 子节点 style 也没有,使用默认值 100
91
- updatedStyle[otherKey] = '100px';
80
+ Promise.resolve().then(function () {
81
+ var _extends3;
82
+ // 优先通过引擎节点 API 更新子节点 style,确保引擎感知变化(布局面板读取时可见)
83
+ var imageChildNode = findImageChildNode(target);
84
+ if (imageChildNode) {
85
+ var _imageChildNode$getPr3, _extends2, _imageChildNode$setPr;
86
+ var _currentStyle = ((_imageChildNode$getPr3 = imageChildNode.getPropValue) === null || _imageChildNode$getPr3 === void 0 ? void 0 : _imageChildNode$getPr3.call(imageChildNode, 'style')) || {};
87
+ // 同时确保 width/height 都存在于子节点 style 中,防止布局面板 replace 时丢失其中一个
88
+ var updatedStyle = (0, _extends4["default"])({}, _currentStyle, (_extends2 = {}, _extends2[styleKey] = value + "px", _extends2));
89
+ // 如果另一轴尺寸在子节点 style 中不存在,则从父级 prop 补充,保证两轴都写入
90
+ var otherKey = styleKey === 'width' ? 'height' : 'width';
91
+ if (!updatedStyle[otherKey]) {
92
+ var _target$getProps, _target$getProps$call, _target$getProps$call2;
93
+ var otherPropKey = otherKey === 'width' ? 'imgWidth' : 'imgHeight';
94
+ var otherPropValue = parsePxNumber(target === null || target === void 0 ? void 0 : (_target$getProps = target.getProps) === null || _target$getProps === void 0 ? void 0 : (_target$getProps$call = _target$getProps.call(target)) === null || _target$getProps$call === void 0 ? void 0 : (_target$getProps$call2 = _target$getProps$call.getPropValue) === null || _target$getProps$call2 === void 0 ? void 0 : _target$getProps$call2.call(_target$getProps$call, otherPropKey));
95
+ if (otherPropValue !== undefined) {
96
+ updatedStyle[otherKey] = otherPropValue + "px";
97
+ } else {
98
+ // 子节点 style 也没有,使用默认值 100
99
+ updatedStyle[otherKey] = '100px';
100
+ }
92
101
  }
102
+ (_imageChildNode$setPr = imageChildNode.setPropValue) === null || _imageChildNode$setPr === void 0 ? void 0 : _imageChildNode$setPr.call(imageChildNode, 'style', updatedStyle);
103
+ return;
93
104
  }
94
- (_imageChildNode$setPr = imageChildNode.setPropValue) === null || _imageChildNode$setPr === void 0 ? void 0 : _imageChildNode$setPr.call(imageChildNode, 'style', updatedStyle);
95
- return;
96
- }
97
- // 降级:直接写 schema(引擎无法感知,但保留作为兜底)
98
- var imageChildSchema = findImageChildSchema(target);
99
- if (!imageChildSchema) {
100
- return;
101
- }
102
- if (!imageChildSchema.props) {
103
- imageChildSchema.props = {};
104
- }
105
- var currentStyle = imageChildSchema.props.style || {};
106
- imageChildSchema.props.style = (0, _extends4["default"])({}, currentStyle, (_extends3 = {}, _extends3[styleKey] = value + "px", _extends3));
105
+ // 降级:直接写 schema(引擎无法感知,但保留作为兜底)
106
+ var imageChildSchema = findImageChildSchema(target);
107
+ if (!imageChildSchema) {
108
+ return;
109
+ }
110
+ if (!imageChildSchema.props) {
111
+ imageChildSchema.props = {};
112
+ }
113
+ var currentStyle = imageChildSchema.props.style || {};
114
+ imageChildSchema.props.style = (0, _extends4["default"])({}, currentStyle, (_extends3 = {}, _extends3[styleKey] = value + "px", _extends3));
115
+ });
107
116
  };
108
117
  var syncImageDimensionPropsFromChild = function syncImageDimensionPropsFromChild(target) {
109
118
  var _target$getProps2;
@@ -341,17 +350,11 @@ var TeletextListMeta = {
341
350
  return;
342
351
  }
343
352
  var props = target.getProps();
344
- // 在任何 setPropValue 之前先写入模块级缓存(与 imagePlacement.setValue 同策略)
353
+ // 在写入前先更新模块级缓存,确保async syncImageStyleValue触发的重评估时缓存有效
345
354
  _cacheDataList(target);
346
- // 快照需要保护的数据,防止 syncImageStyleValue → imageChildNode.setPropValue
347
- // 触发引擎重评估 dataList.initialValue,导致 dataList 被重置为默认图
348
- var prevDataList = props.getPropValue('dataList');
349
- var prevDataListBind = props.getPropValue('dataListBind');
350
355
  props.setPropValue('imgWidth', parsedValue);
356
+ // syncImageStyleValue 异步执行,不在当前同步栈内触发 dataList.initialValue 重评估
351
357
  syncImageStyleValue(target, 'width', parsedValue);
352
- // 还原被保护的数据(幂等操作,若引擎未重置则无副作用)
353
- if (prevDataList !== undefined) props.setPropValue('dataList', prevDataList);
354
- if (prevDataListBind !== undefined) props.setPropValue('dataListBind', prevDataListBind);
355
358
  }
356
359
  }
357
360
  }, {
@@ -412,17 +415,11 @@ var TeletextListMeta = {
412
415
  return;
413
416
  }
414
417
  var props = target.getProps();
415
- // 在任何 setPropValue 之前先写入模块级缓存(与 imagePlacement.setValue 同策略)
418
+ // 在写入前先更新模块级缓存,确保async syncImageStyleValue触发的重评估时缓存有效
416
419
  _cacheDataList(target);
417
- // 快照需要保护的数据,防止 syncImageStyleValue → imageChildNode.setPropValue
418
- // 触发引擎重评估 dataList.initialValue,导致 dataList 被重置为默认图
419
- var prevDataList = props.getPropValue('dataList');
420
- var prevDataListBind = props.getPropValue('dataListBind');
421
420
  props.setPropValue('imgHeight', parsedValue);
421
+ // syncImageStyleValue 异步执行,不在当前同步栈内触发 dataList.initialValue 重评估
422
422
  syncImageStyleValue(target, 'height', parsedValue);
423
- // 还原被保护的数据(幂等操作,若引擎未重置则无副作用)
424
- if (prevDataList !== undefined) props.setPropValue('dataList', prevDataList);
425
- if (prevDataListBind !== undefined) props.setPropValue('dataListBind', prevDataListBind);
426
423
  }
427
424
  }
428
425
  }, {
@@ -898,16 +895,22 @@ var TeletextListMeta = {
898
895
  // 2. 模块级 WeakMap 缓存(在任何 setPropValue 之前写入,完全不受引擎清空影响)
899
896
  // 3. settings API(重评估中间态下可能已清空,作为最后手段)
900
897
  // 4. 默认占位数据(仅首次创建组件时触达)
898
+ //
899
+ // 关键防御:一旦组件已绑定数据源(缓存或 node 中有值),
900
+ // 无论是哪种场景的 initialValue 调用,都必须返回已有值而不是默认数组。
901
+ // syncImageStyleValue 改为异步后,通常 node.getPropValue 已能拿到正确值;
902
+ // 缓存作为最后一道防线,彻底切断默认数组覆盖绑定表达式的可能。
901
903
  var node = target === null || target === void 0 ? void 0 : target.node;
904
+ // 优先读缓存:即使 node.getPropValue 暂时处于中间态,缓存也能提供可靠值
905
+ var cached = node ? _nodeDataListCache.get(node) : undefined;
902
906
  var fromNode = node === null || node === void 0 ? void 0 : (_node$getPropValue2 = node.getPropValue) === null || _node$getPropValue2 === void 0 ? void 0 : _node$getPropValue2.call(node, 'dataList');
903
907
  if (fromNode !== undefined) {
904
908
  // 同步更新缓存,为后续可能的重评估提供后备
905
909
  if (node) _nodeDataListCache.set(node, fromNode);
906
910
  return fromNode;
907
911
  }
908
- // node.getPropValue 返回 undefined:引擎已在调用 initialValue 前清空 node prop
912
+ // node.getPropValue 返回 undefined:引擎可能已在调用 initialValue 前清空 node prop
909
913
  // → 读取模块级缓存(在 setValue 中任何 setPropValue 之前写入,最可靠的后备)
910
- var cached = node ? _nodeDataListCache.get(node) : undefined;
911
914
  if (cached !== undefined) {
912
915
  return cached;
913
916
  }
@@ -958,20 +961,34 @@ var TeletextListMeta = {
958
961
  return cached; // undefined 仅在缓存为空(全新组件首次初始化)时出现,属正常情况
959
962
  },
960
963
  /**
961
- * 自定义 setValue:用户每次编辑 dataList 条目时即时更新 WeakMap 缓存。
962
- * 这是保证缓存与用户实际数据保持同步的关键——之前缓存只在
963
- * imgWidth/imgHeight/imagePlacement.setValue 中写入,用户直接编辑 dataList
964
- * 时缓存一直停留在初始默认值,导致 margin 修改时从缓存取出默认图数组。
964
+ * 自定义 setValue:用户每次编辑 dataList 条目时,先更新 WeakMap 缓存,
965
+ * 再通过 node.setPropValue 将值持久化到 schema。
966
+ *
967
+ * ⚠️ 此引擎中 extraProps.setValue 完全接管写入逻辑,引擎不会自动持久化:
968
+ * 若不在此处显式调用 setPropValue,用户编辑的数据将只存于内存缓存,
969
+ * 页面刷新后丢失,同时 imgWidth/imgHeight.setValue 的快照–还原机制也因
970
+ * props.getPropValue('dataList') 返回 undefined 而失效,导致还原跳过,
971
+ * 进而触发引擎 initDefaultValue,画布回退默认图。
972
+ *
973
+ * 写入顺序:先缓存(供 initialValue/getValue 兜底),再写 schema(持久化)。
974
+ * 写入 schema 会触发引擎对 settings 的重评估,但此时 schema 已有值,
975
+ * initialValue 不会被调用,不会产生循环。
965
976
  */
966
977
  setValue: function setValue(target, value) {
967
978
  var node = target === null || target === void 0 ? void 0 : target.node;
968
979
  if (!node) return;
969
980
  if (value !== undefined) {
981
+ var _target$getProps10, _target$getProps10$ca, _target$getProps10$ca2;
982
+ // 先写缓存,确保重评估期间 getValue 可从缓存返回有效值
970
983
  _nodeDataListCache.set(node, value);
984
+ // 再持久化到 schema(引擎不会自动写入,必须显式调用)
985
+ (_target$getProps10 = target.getProps) === null || _target$getProps10 === void 0 ? void 0 : (_target$getProps10$ca = _target$getProps10.call(target)) === null || _target$getProps10$ca === void 0 ? void 0 : (_target$getProps10$ca2 = _target$getProps10$ca.setPropValue) === null || _target$getProps10$ca2 === void 0 ? void 0 : _target$getProps10$ca2.call(_target$getProps10$ca, 'dataList', value);
971
986
  } else {
987
+ var _target$getProps11, _target$getProps11$ca, _target$getProps11$ca2;
972
988
  // clearValue 场景(value = undefined):清空缓存,使下次 initDefaultValue
973
989
  // 可正常返回默认数组(仅用于组件被显式清除数据的情况)
974
990
  _nodeDataListCache["delete"](node);
991
+ (_target$getProps11 = target.getProps) === null || _target$getProps11 === void 0 ? void 0 : (_target$getProps11$ca = _target$getProps11.call(target)) === null || _target$getProps11$ca === void 0 ? void 0 : (_target$getProps11$ca2 = _target$getProps11$ca.setPropValue) === null || _target$getProps11$ca2 === void 0 ? void 0 : _target$getProps11$ca2.call(_target$getProps11$ca, 'dataList', undefined);
975
992
  }
976
993
  }
977
994
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dckj-npm/dc-material",
3
- "version": "0.1.370",
3
+ "version": "0.1.372",
4
4
  "description": "dc低代码物料",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -114,10 +114,10 @@
114
114
  },
115
115
  "componentConfig": {
116
116
  "isComponentLibrary": true,
117
- "materialSchema": "https://unpkg.com/@dckj-npm/dc-material@0.1.370/build/lowcode/assets-prod.json"
117
+ "materialSchema": "https://unpkg.com/@dckj-npm/dc-material@0.1.372/build/lowcode/assets-prod.json"
118
118
  },
119
119
  "lcMeta": {
120
120
  "type": "component"
121
121
  },
122
- "homepage": "https://unpkg.com/@dckj-npm/dc-material@0.1.370/build/index.html"
122
+ "homepage": "https://unpkg.com/@dckj-npm/dc-material@0.1.372/build/index.html"
123
123
  }