@riil-frontend/component-topology 2.4.6 → 2.4.8

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.
@@ -8,6 +8,7 @@ import TextPropertyView from "./text/TextPropertyView";
8
8
  import NodePropertyView from "./node/NodePropertyView";
9
9
  import ViewPropertyView from "./view/ViewPropertyView";
10
10
  import LinkPropertyView from "./link/LinkPropertyView";
11
+ import useSettingRuntimeState from "./useSettingRuntimeState";
11
12
 
12
13
  function getElementType(selection) {
13
14
  var selectionElement = selection[0];
@@ -37,6 +38,7 @@ export default function Settings(props) {
37
38
  topoEditApi = props.topoEditApi,
38
39
  selection = props.selection,
39
40
  editorProps = props.editorProps;
41
+ var settingRuntimeState = useSettingRuntimeState();
40
42
  var selectionSize = selection.length;
41
43
  var selectionIds = selection.map(function (item) {
42
44
  return item.id;
@@ -112,7 +114,8 @@ export default function Settings(props) {
112
114
  selection: selection,
113
115
  values: values,
114
116
  onChange: updateElementProperty,
115
- editorProps: editorProps
117
+ editorProps: editorProps,
118
+ settingRuntimeState: settingRuntimeState
116
119
  })));
117
120
  }
118
121
  ;
@@ -5,9 +5,11 @@ import React, { useState } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import NodeSizeNumberPicker from "./NodeSizeNumberPicker";
7
7
  import styles from "./NodeSizeInput.module.scss";
8
+ import rlog from "@riil-frontend/component-topology-utils/es/utils/rlog";
8
9
  var FormItem = _Form.Item;
9
10
  var Row = _Grid.Row,
10
11
  Col = _Grid.Col;
12
+ var NODE_SIZE_LOCK = 'NODE_SIZE_LOCK';
11
13
  /**
12
14
  * 节点大小组件
13
15
  *
@@ -15,12 +17,12 @@ var Row = _Grid.Row,
15
17
  */
16
18
 
17
19
  function NodeSizeInput(props) {
18
- var value = props.value,
19
- onChange = props.onChange;
20
-
21
- var _useState = useState(false),
22
- lock = _useState[0],
23
- setLock = _useState[1];
20
+ var node = props.node,
21
+ value = props.value,
22
+ onChange = props.onChange,
23
+ settingRuntimeState = props.settingRuntimeState;
24
+ var lock = settingRuntimeState.getAttr(NODE_SIZE_LOCK) !== false;
25
+ var RUNTIME_STATE_NAME_NODE_SIZE_INFO = "NODE_SIZE_INFO." + node.id;
24
26
 
25
27
  var handleValue = function handleValue(val) {
26
28
  if (!val || val < 1) {
@@ -34,22 +36,70 @@ function NodeSizeInput(props) {
34
36
  return parseInt(val);
35
37
  };
36
38
 
39
+ function initSizeRatio() {
40
+ var ratioInfo = {
41
+ ratio: value.width / value.height,
42
+ size: value
43
+ };
44
+ updateSizeRatioCurrentSize(ratioInfo);
45
+ rlog.debug('initSizeRatio', ratioInfo);
46
+ return ratioInfo;
47
+ }
48
+
49
+ function updateSizeRatioCurrentSize(ratioInfo) {
50
+ settingRuntimeState.setAttr(RUNTIME_STATE_NAME_NODE_SIZE_INFO, ratioInfo);
51
+ return ratioInfo;
52
+ }
53
+
54
+ function getSizeRatio() {
55
+ return settingRuntimeState.getAttr(RUNTIME_STATE_NAME_NODE_SIZE_INFO);
56
+ }
57
+
37
58
  var handleChange = function handleChange(name, attrValue) {
38
59
  var _extends2;
39
60
 
40
61
  var newSize = _extends({}, value, (_extends2 = {}, _extends2[name] = attrValue, _extends2));
41
62
 
42
63
  if (lock) {
64
+ var ratioInfo = getSizeRatio();
65
+
66
+ if (!ratioInfo) {
67
+ // 首次没有比例时,初始化当前节点比例
68
+ ratioInfo = initSizeRatio();
69
+ rlog.debug('首次没有比例时,初始化当前节点比例', ratioInfo);
70
+ } else {
71
+ // 修改后,非锁定方式调整比例(画图调整节点大小,未开启锁定修改),重新初始化比例
72
+ var prevSize = ratioInfo.size;
73
+
74
+ if (value.width !== prevSize.width || value.height !== prevSize.height) {
75
+ ratioInfo = initSizeRatio();
76
+ rlog.debug('修改后,重新初始化比例', ratioInfo);
77
+ }
78
+ }
79
+
80
+ var ratio = ratioInfo.ratio;
81
+
43
82
  if (name === 'width') {
44
- newSize.height = handleValue(value.height / value.width * attrValue);
83
+ newSize.height = handleValue(attrValue / ratio);
45
84
  } else {
46
- newSize.width = handleValue(value.width / value.height * attrValue);
85
+ newSize.width = handleValue(attrValue * ratio);
47
86
  }
87
+
88
+ updateSizeRatioCurrentSize({
89
+ ratio: ratio,
90
+ size: newSize
91
+ });
92
+ rlog.debug('按比例更新', name, attrValue, ratio, value, newSize, ratioInfo);
48
93
  }
49
94
 
50
95
  onChange(newSize);
51
96
  };
52
97
 
98
+ var switchLock = function switchLock() {
99
+ var isLock = !lock;
100
+ settingRuntimeState.setAttr(NODE_SIZE_LOCK, isLock);
101
+ };
102
+
53
103
  function parseValue(val) {
54
104
  return val ? parseInt(val) : val;
55
105
  }
@@ -76,16 +126,9 @@ function NodeSizeInput(props) {
76
126
  }
77
127
  }))), /*#__PURE__*/React.createElement("div", {
78
128
  className: styles.lockBtn,
79
- onClick: function onClick() {
80
- setLock(!lock);
81
- }
82
- }, lock ? /*#__PURE__*/React.createElement("img", {
83
- src: require("./img/icon_\u89E3\u9501.svg"),
84
- title: "\u89E3\u9501",
85
- alt: ""
86
- }) : /*#__PURE__*/React.createElement("img", {
87
- src: require("./img/icon_\u9501.svg"),
88
- title: "\u9501\u5B9A",
129
+ onClick: switchLock
130
+ }, /*#__PURE__*/React.createElement("img", {
131
+ src: require(lock ? './img/icon_锁.svg' : './img/icon_解锁.svg'),
89
132
  alt: ""
90
133
  })), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(FormItem, {
91
134
  required: true,
@@ -37,7 +37,7 @@ export default function NodePropertyView(props) {
37
37
  topoEditApi = props.topoEditApi,
38
38
  values = props.values,
39
39
  _onChange = props.onChange,
40
- editorProps = props.editorProps;
40
+ settingRuntimeState = props.settingRuntimeState;
41
41
  var bindType = getBindType(values);
42
42
 
43
43
  var field = _Field.useField({
@@ -135,6 +135,7 @@ export default function NodePropertyView(props) {
135
135
  })), /*#__PURE__*/React.createElement(_Form.Item, {
136
136
  label: "\u56FE\u7247\u5C3A\u5BF8"
137
137
  }, /*#__PURE__*/React.createElement(NodeSizeInput, {
138
+ node: values,
138
139
  value: {
139
140
  width: values.width,
140
141
  height: values.height
@@ -143,7 +144,8 @@ export default function NodePropertyView(props) {
143
144
  _onChange('width', size.width);
144
145
 
145
146
  _onChange('height', size.height);
146
- }
147
+ },
148
+ settingRuntimeState: settingRuntimeState
147
149
  }))))));
148
150
  }; // 未绑定资源的节点,根据参数控制是否可关联资源
149
151
 
@@ -0,0 +1,5 @@
1
+ export default function _default(): {
2
+ state: {};
3
+ getAttr: (name: any) => any;
4
+ setAttr: (name: any, value: any) => void;
5
+ };
@@ -0,0 +1,23 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import { useState } from "react";
3
+ export default function () {
4
+ var _useState = useState({}),
5
+ state = _useState[0],
6
+ setState = _useState[1];
7
+
8
+ function setAttr(name, value) {
9
+ var _extends2;
10
+
11
+ setState(_extends({}, state, (_extends2 = {}, _extends2[name] = value, _extends2)));
12
+ }
13
+
14
+ function getAttr(name) {
15
+ return state[name];
16
+ }
17
+
18
+ return {
19
+ state: state,
20
+ getAttr: getAttr,
21
+ setAttr: setAttr
22
+ };
23
+ }
@@ -27,6 +27,8 @@ var _ViewPropertyView = _interopRequireDefault(require("./view/ViewPropertyView"
27
27
 
28
28
  var _LinkPropertyView = _interopRequireDefault(require("./link/LinkPropertyView"));
29
29
 
30
+ var _useSettingRuntimeState = _interopRequireDefault(require("./useSettingRuntimeState"));
31
+
30
32
  function getElementType(selection) {
31
33
  var selectionElement = selection[0];
32
34
  var selectionSize = selection.length;
@@ -55,6 +57,7 @@ function Settings(props) {
55
57
  topoEditApi = props.topoEditApi,
56
58
  selection = props.selection,
57
59
  editorProps = props.editorProps;
60
+ var settingRuntimeState = (0, _useSettingRuntimeState["default"])();
58
61
  var selectionSize = selection.length;
59
62
  var selectionIds = selection.map(function (item) {
60
63
  return item.id;
@@ -128,7 +131,8 @@ function Settings(props) {
128
131
  selection: selection,
129
132
  values: values,
130
133
  onChange: updateElementProperty,
131
- editorProps: editorProps
134
+ editorProps: editorProps,
135
+ settingRuntimeState: settingRuntimeState
132
136
  })));
133
137
  }
134
138
 
@@ -21,9 +21,12 @@ var _NodeSizeNumberPicker = _interopRequireDefault(require("./NodeSizeNumberPick
21
21
 
22
22
  var _NodeSizeInputModule = _interopRequireDefault(require("./NodeSizeInput.module.scss"));
23
23
 
24
+ var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-utils/es/utils/rlog"));
25
+
24
26
  var FormItem = _form["default"].Item;
25
27
  var Row = _grid["default"].Row,
26
28
  Col = _grid["default"].Col;
29
+ var NODE_SIZE_LOCK = 'NODE_SIZE_LOCK';
27
30
  /**
28
31
  * 节点大小组件
29
32
  *
@@ -31,12 +34,12 @@ var Row = _grid["default"].Row,
31
34
  */
32
35
 
33
36
  function NodeSizeInput(props) {
34
- var value = props.value,
35
- onChange = props.onChange;
36
-
37
- var _useState = (0, _react.useState)(false),
38
- lock = _useState[0],
39
- setLock = _useState[1];
37
+ var node = props.node,
38
+ value = props.value,
39
+ onChange = props.onChange,
40
+ settingRuntimeState = props.settingRuntimeState;
41
+ var lock = settingRuntimeState.getAttr(NODE_SIZE_LOCK) !== false;
42
+ var RUNTIME_STATE_NAME_NODE_SIZE_INFO = "NODE_SIZE_INFO." + node.id;
40
43
 
41
44
  var handleValue = function handleValue(val) {
42
45
  if (!val || val < 1) {
@@ -50,22 +53,75 @@ function NodeSizeInput(props) {
50
53
  return parseInt(val);
51
54
  };
52
55
 
56
+ function initSizeRatio() {
57
+ var ratioInfo = {
58
+ ratio: value.width / value.height,
59
+ size: value
60
+ };
61
+ updateSizeRatioCurrentSize(ratioInfo);
62
+
63
+ _rlog["default"].debug('initSizeRatio', ratioInfo);
64
+
65
+ return ratioInfo;
66
+ }
67
+
68
+ function updateSizeRatioCurrentSize(ratioInfo) {
69
+ settingRuntimeState.setAttr(RUNTIME_STATE_NAME_NODE_SIZE_INFO, ratioInfo);
70
+ return ratioInfo;
71
+ }
72
+
73
+ function getSizeRatio() {
74
+ return settingRuntimeState.getAttr(RUNTIME_STATE_NAME_NODE_SIZE_INFO);
75
+ }
76
+
53
77
  var handleChange = function handleChange(name, attrValue) {
54
78
  var _extends2;
55
79
 
56
80
  var newSize = (0, _extends3["default"])({}, value, (_extends2 = {}, _extends2[name] = attrValue, _extends2));
57
81
 
58
82
  if (lock) {
83
+ var ratioInfo = getSizeRatio();
84
+
85
+ if (!ratioInfo) {
86
+ // 首次没有比例时,初始化当前节点比例
87
+ ratioInfo = initSizeRatio();
88
+
89
+ _rlog["default"].debug('首次没有比例时,初始化当前节点比例', ratioInfo);
90
+ } else {
91
+ // 修改后,非锁定方式调整比例(画图调整节点大小,未开启锁定修改),重新初始化比例
92
+ var prevSize = ratioInfo.size;
93
+
94
+ if (value.width !== prevSize.width || value.height !== prevSize.height) {
95
+ ratioInfo = initSizeRatio();
96
+
97
+ _rlog["default"].debug('修改后,重新初始化比例', ratioInfo);
98
+ }
99
+ }
100
+
101
+ var ratio = ratioInfo.ratio;
102
+
59
103
  if (name === 'width') {
60
- newSize.height = handleValue(value.height / value.width * attrValue);
104
+ newSize.height = handleValue(attrValue / ratio);
61
105
  } else {
62
- newSize.width = handleValue(value.width / value.height * attrValue);
106
+ newSize.width = handleValue(attrValue * ratio);
63
107
  }
108
+
109
+ updateSizeRatioCurrentSize({
110
+ ratio: ratio,
111
+ size: newSize
112
+ });
113
+
114
+ _rlog["default"].debug('按比例更新', name, attrValue, ratio, value, newSize, ratioInfo);
64
115
  }
65
116
 
66
117
  onChange(newSize);
67
118
  };
68
119
 
120
+ var switchLock = function switchLock() {
121
+ var isLock = !lock;
122
+ settingRuntimeState.setAttr(NODE_SIZE_LOCK, isLock);
123
+ };
124
+
69
125
  function parseValue(val) {
70
126
  return val ? parseInt(val) : val;
71
127
  }
@@ -92,16 +148,9 @@ function NodeSizeInput(props) {
92
148
  }
93
149
  }))), /*#__PURE__*/_react["default"].createElement("div", {
94
150
  className: _NodeSizeInputModule["default"].lockBtn,
95
- onClick: function onClick() {
96
- setLock(!lock);
97
- }
98
- }, lock ? /*#__PURE__*/_react["default"].createElement("img", {
99
- src: require("./img/icon_\u89E3\u9501.svg"),
100
- title: "\u89E3\u9501",
101
- alt: ""
102
- }) : /*#__PURE__*/_react["default"].createElement("img", {
103
- src: require("./img/icon_\u9501.svg"),
104
- title: "\u9501\u5B9A",
151
+ onClick: switchLock
152
+ }, /*#__PURE__*/_react["default"].createElement("img", {
153
+ src: require(lock ? './img/icon_锁.svg' : './img/icon_解锁.svg'),
105
154
  alt: ""
106
155
  })), /*#__PURE__*/_react["default"].createElement(Col, null, /*#__PURE__*/_react["default"].createElement(FormItem, {
107
156
  required: true,
@@ -59,7 +59,7 @@ function NodePropertyView(props) {
59
59
  topoEditApi = props.topoEditApi,
60
60
  values = props.values,
61
61
  _onChange = props.onChange,
62
- editorProps = props.editorProps;
62
+ settingRuntimeState = props.settingRuntimeState;
63
63
  var bindType = getBindType(values);
64
64
 
65
65
  var field = _field["default"].useField({
@@ -157,6 +157,7 @@ function NodePropertyView(props) {
157
157
  })), /*#__PURE__*/_react["default"].createElement(_form["default"].Item, {
158
158
  label: "\u56FE\u7247\u5C3A\u5BF8"
159
159
  }, /*#__PURE__*/_react["default"].createElement(_NodeSizeInput["default"], {
160
+ node: values,
160
161
  value: {
161
162
  width: values.width,
162
163
  height: values.height
@@ -165,7 +166,8 @@ function NodePropertyView(props) {
165
166
  _onChange('width', size.width);
166
167
 
167
168
  _onChange('height', size.height);
168
- }
169
+ },
170
+ settingRuntimeState: settingRuntimeState
169
171
  }))))));
170
172
  }; // 未绑定资源的节点,根据参数控制是否可关联资源
171
173
 
@@ -0,0 +1,5 @@
1
+ export default function _default(): {
2
+ state: {};
3
+ getAttr: (name: any) => any;
4
+ setAttr: (name: any, value: any) => void;
5
+ };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports["default"] = _default;
7
+
8
+ var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _react = require("react");
11
+
12
+ function _default() {
13
+ var _useState = (0, _react.useState)({}),
14
+ state = _useState[0],
15
+ setState = _useState[1];
16
+
17
+ function setAttr(name, value) {
18
+ var _extends2;
19
+
20
+ setState((0, _extends3["default"])({}, state, (_extends2 = {}, _extends2[name] = value, _extends2)));
21
+ }
22
+
23
+ function getAttr(name) {
24
+ return state[name];
25
+ }
26
+
27
+ return {
28
+ state: state,
29
+ getAttr: getAttr,
30
+ setAttr: setAttr
31
+ };
32
+ }
package/package.json CHANGED
@@ -1,18 +1,7 @@
1
1
  {
2
2
  "name": "@riil-frontend/component-topology",
3
- "version": "2.4.6",
3
+ "version": "2.4.8",
4
4
  "description": "拓扑",
5
- "files": [
6
- "demo/",
7
- "demo-mock/",
8
- "lib/",
9
- "es/",
10
- "build/",
11
- "public/"
12
- ],
13
- "main": "lib/index.js",
14
- "module": "es/index.js",
15
- "stylePath": "style.js",
16
5
  "scripts": {
17
6
  "start": "build-scripts start",
18
7
  "start:warch": "build-scripts start --watch",
@@ -26,6 +15,17 @@
26
15
  "stylelint": "stylelint \"**/*.{css,scss,less}\"",
27
16
  "lint": "npm run eslint && npm run stylelint"
28
17
  },
18
+ "main": "lib/index.js",
19
+ "module": "es/index.js",
20
+ "stylePath": "style.js",
21
+ "files": [
22
+ "demo/",
23
+ "demo-mock/",
24
+ "lib/",
25
+ "es/",
26
+ "build/",
27
+ "public/"
28
+ ],
29
29
  "keywords": [
30
30
  "ice",
31
31
  "react",
@@ -100,6 +100,6 @@
100
100
  "access": "public"
101
101
  },
102
102
  "license": "MIT",
103
- "homepage": "https://unpkg.com/@riil-frontend/component-topology@2.4.6/build/index.html",
103
+ "homepage": "https://unpkg.com/@riil-frontend/component-topology@2.4.8/build/index.html",
104
104
  "gitHead": "8d9f286eb5da11dfadbef62890d74d2c2dd4d3a9"
105
105
  }