redhotmagma-graphics-editor 1.41.1 → 1.42.0
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/App.js +90 -165
- package/CanvasAdapters/Mock/Canvas.js +71 -125
- package/CanvasAdapters/Mock/Objects/CanvasObject.js +23 -40
- package/CanvasAdapters/Mock/Objects/Group.js +15 -46
- package/CanvasAdapters/Mock/Objects/Image.js +15 -46
- package/CanvasAdapters/Mock/Objects/Text.js +15 -51
- package/CanvasAdapters/Mock/index.js +0 -1
- package/CanvasAdapters/PaperJs/Canvas.js +268 -398
- package/CanvasAdapters/PaperJs/CanvasRepository.js +6 -23
- package/CanvasAdapters/PaperJs/Modifiers/FontSizeMin.js +2 -5
- package/CanvasAdapters/PaperJs/Objects/CanvasObject.js +33 -65
- package/CanvasAdapters/PaperJs/Objects/Group.js +14 -48
- package/CanvasAdapters/PaperJs/Objects/Image.js +58 -114
- package/CanvasAdapters/PaperJs/Objects/Text.js +43 -99
- package/CanvasAdapters/PaperJs/Utils/HTML2Paper.js +57 -108
- package/CanvasAdapters/PaperJs/Utils/SVGfix.js +9 -30
- package/CanvasAdapters/PaperJs/Utils/StyleParams.js +10 -21
- package/CanvasAdapters/PaperJs/Utils/TextToSVGRepository.js +53 -86
- package/CanvasAdapters/PaperJs/Utils/TextToSVGUtils.js +4 -14
- package/CanvasAdapters/PaperJs/Utils/UTF8Base64.js +3 -24
- package/CanvasAdapters/PaperJs/Utils/UseColorLayer.js +58 -0
- package/CanvasAdapters/PaperJs/Utils/UseMask.js +183 -279
- package/CanvasAdapters/PaperJs/Utils/__tests__/SVGfix.test.js +0 -1
- package/CanvasAdapters/PaperJs/Utils/__tests__/TextToSVGUtils.test.js +0 -1
- package/CanvasAdapters/PaperJs/Utils/__tests__/updateFontStyle.test.js +0 -1
- package/CanvasAdapters/PaperJs/Utils/updateFontStyle.js +5 -11
- package/CanvasAdapters/PaperJs/index.js +0 -1
- package/CanvasInterface/Canvas.js +145 -235
- package/CanvasInterface/CanvasProvider.js +25 -75
- package/CanvasInterface/Objects/CanvasObject.js +68 -148
- package/CanvasInterface/Objects/index.js +0 -1
- package/CanvasInterface/Observable.js +10 -29
- package/CanvasInterface/canvasConnect.js +12 -44
- package/CanvasInterface/index.js +1 -7
- package/Components/Canvas/Canvas.js +14 -41
- package/Components/Canvas/CanvasContainer.js +5 -18
- package/Components/Canvas/styles.js +2 -3
- package/Components/DelayedContainer.js +14 -39
- package/Components/Editor/Editor.js +47 -102
- package/Components/Editor/EditorContainer.js +47 -131
- package/Components/Editor/styles.js +2 -3
- package/Components/InlineToolbox/InlineToolbox.js +49 -142
- package/Components/InlineToolbox/InlineToolboxButton.js +9 -19
- package/Components/InlineToolbox/styles.js +2 -3
- package/Components/ManipulableContainer.js +15 -41
- package/Components/ResizeDetect/ResizeDetect.js +14 -47
- package/Components/Rulers/Ruler.js +20 -68
- package/Components/Rulers/Rulers.js +14 -46
- package/Components/Rulers/styles.js +2 -3
- package/Components/SelectionToolbox/ColorPalette.js +25 -73
- package/Components/SelectionToolbox/SelectionToolbox.js +39 -101
- package/Components/SelectionToolbox/TextTools.js +81 -157
- package/Components/SelectionToolbox/styles.js +2 -3
- package/Components/StandardToolbox/StandardToolbox.js +81 -144
- package/Components/TextEditor/TextEditor.js +67 -182
- package/Components/TextEditor/TextEditorStateProvider.js +20 -56
- package/Components/Toolbox/ToolboxContainer.js +5 -18
- package/Components/Toolbox/ToolboxRow.js +4 -16
- package/Components/Toolbox/styles.js +2 -3
- package/Utils/Calc2D.js +3 -9
- package/Utils/DOM.js +22 -80
- package/Utils/Device.js +2 -6
- package/Utils/Image.js +17 -11
- package/Utils/Logger.js +8 -32
- package/Utils/Range.js +6 -33
- package/Utils/String.js +2 -8
- package/Utils/UnitConversion.js +3 -9
- package/Utils/__tests__/Calc2D.test.js +1 -3
- package/Utils/__tests__/DOM.test.js +17 -25
- package/Utils/__tests__/Range.test.js +0 -1
- package/_demos/UsingExternalControls/App.js +13 -48
- package/_demos/UsingRenderProps/App.js +15 -54
- package/index.js +2 -6
- package/package.json +5 -7
- package/src/App.js +35 -38
- package/src/CanvasAdapters/PaperJs/Canvas.ts +11 -0
- package/src/CanvasAdapters/PaperJs/Utils/UseColorLayer.js +56 -0
- package/src/Components/InlineToolbox/InlineToolbox.js +2 -2
- package/src/Components/SelectionToolbox/TextTools.js +1 -1
- package/src/_demos/UsingExternalControls/App.js +25 -28
- package/src/_demos/UsingRenderProps/App.js +16 -19
- package/src/index.js +2 -2
|
@@ -1,68 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.withCanvasPosition = exports["default"] = exports.EditorContainer = exports.CanvasPositionContext = void 0;
|
|
9
|
-
|
|
10
7
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
9
|
var _cssElementQueries = require("css-element-queries");
|
|
15
|
-
|
|
16
10
|
var _Canvas = require("../../CanvasInterface/Canvas");
|
|
17
|
-
|
|
18
11
|
var _CanvasProvider = require("../../CanvasInterface/CanvasProvider");
|
|
19
|
-
|
|
20
12
|
var _Logger = _interopRequireDefault(require("../../Utils/Logger"));
|
|
21
|
-
|
|
22
13
|
var _String = require("../../Utils/String");
|
|
23
|
-
|
|
24
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
|
-
|
|
26
|
-
function _extends() { _extends = Object.assign
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
31
|
-
|
|
15
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
32
19
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
33
|
-
|
|
34
20
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
35
|
-
|
|
36
21
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
37
|
-
|
|
38
22
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
39
|
-
|
|
40
23
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
41
|
-
|
|
42
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
43
|
-
|
|
24
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
44
25
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
45
|
-
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
51
|
-
|
|
52
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
53
|
-
|
|
26
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
27
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
28
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
54
30
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
55
|
-
|
|
56
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
57
|
-
|
|
31
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
58
32
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
59
|
-
|
|
60
33
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
61
|
-
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
function
|
|
65
|
-
|
|
34
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
35
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
36
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
37
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
66
38
|
var logger = new _Logger["default"]('EditorContainer');
|
|
67
39
|
var initialState = {
|
|
68
40
|
canvasPosition: {
|
|
@@ -76,82 +48,57 @@ var initialState = {
|
|
|
76
48
|
ratio: 1,
|
|
77
49
|
containerStyle: {}
|
|
78
50
|
};
|
|
79
|
-
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
exports.CanvasPositionContext = CanvasPositionContext;
|
|
83
|
-
|
|
84
|
-
var EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
51
|
+
var CanvasPositionContext = exports.CanvasPositionContext = /*#__PURE__*/_react["default"].createContext(initialState);
|
|
52
|
+
var EditorContainer = exports.EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
85
53
|
_inherits(EditorContainer, _React$Component);
|
|
86
|
-
|
|
87
54
|
var _super = _createSuper(EditorContainer);
|
|
88
|
-
|
|
89
55
|
function EditorContainer() {
|
|
90
56
|
var _this;
|
|
91
|
-
|
|
92
57
|
_classCallCheck(this, EditorContainer);
|
|
93
|
-
|
|
94
58
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
95
59
|
args[_key] = arguments[_key];
|
|
96
60
|
}
|
|
97
|
-
|
|
98
61
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
99
|
-
|
|
100
62
|
_defineProperty(_assertThisInitialized(_this), "state", initialState);
|
|
101
|
-
|
|
102
63
|
_defineProperty(_assertThisInitialized(_this), "resizeSensor", null);
|
|
103
|
-
|
|
104
64
|
_defineProperty(_assertThisInitialized(_this), "onSizeChange", function (size) {
|
|
105
65
|
_this.setState({
|
|
106
66
|
editorSize: size
|
|
107
67
|
});
|
|
108
68
|
});
|
|
109
|
-
|
|
110
69
|
_defineProperty(_assertThisInitialized(_this), "onCanvasSizeChange", function () {
|
|
111
70
|
logger.log('canvas size changed, updating canvas position');
|
|
112
|
-
|
|
113
71
|
_this.updateCanvasPosition();
|
|
114
72
|
});
|
|
115
|
-
|
|
116
73
|
_defineProperty(_assertThisInitialized(_this), "containerRef", /*#__PURE__*/_react["default"].createRef());
|
|
117
|
-
|
|
118
74
|
_defineProperty(_assertThisInitialized(_this), "calculateSiblingsHeight", function () {
|
|
119
75
|
var element = _this.containerRef.current;
|
|
120
|
-
|
|
121
76
|
if (!element) {
|
|
122
77
|
return 0;
|
|
123
78
|
}
|
|
124
|
-
|
|
125
79
|
var sum = 0;
|
|
126
|
-
|
|
127
80
|
var children = _toConsumableArray(element.parentElement.children);
|
|
128
|
-
|
|
129
81
|
children.forEach(function (child) {
|
|
130
82
|
sum += child === element || child.className === 'resize-sensor' ? 0 : child.getBoundingClientRect().height;
|
|
131
83
|
});
|
|
132
84
|
return sum;
|
|
133
85
|
});
|
|
134
|
-
|
|
135
86
|
_defineProperty(_assertThisInitialized(_this), "calculateContainerStyle", function () {
|
|
136
87
|
var wrapper = _this.containerRef.current && _this.containerRef.current.parentElement;
|
|
137
88
|
var _this$props = _this.props,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
89
|
+
fillContainer = _this$props.fillContainer,
|
|
90
|
+
canvas = _this$props.canvas,
|
|
91
|
+
style = _this$props.style;
|
|
142
92
|
if (!fillContainer && canvas && wrapper) {
|
|
143
93
|
// set the max size to the minimum of current canvas size and the available area
|
|
144
94
|
var _canvas$getElementSiz = canvas.getElementSize(),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
95
|
+
cw = _canvas$getElementSiz.width,
|
|
96
|
+
ch = _canvas$getElementSiz.height;
|
|
148
97
|
var _wrapper$getBoundingC = wrapper.getBoundingClientRect(),
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
98
|
+
aw = _wrapper$getBoundingC.width,
|
|
99
|
+
ah = _wrapper$getBoundingC.height;
|
|
152
100
|
var aspectRatio = cw / ch;
|
|
153
101
|
var width, height;
|
|
154
|
-
|
|
155
102
|
if (aspectRatio < 1) {
|
|
156
103
|
height = Math.min(ch, ah);
|
|
157
104
|
width = height * aspectRatio;
|
|
@@ -159,7 +106,6 @@ var EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
159
106
|
width = Math.min(cw, aw);
|
|
160
107
|
height = width / aspectRatio;
|
|
161
108
|
}
|
|
162
|
-
|
|
163
109
|
return _objectSpread({
|
|
164
110
|
width: '100%',
|
|
165
111
|
height: '100%',
|
|
@@ -167,39 +113,34 @@ var EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
167
113
|
maxHeight: height
|
|
168
114
|
}, style);
|
|
169
115
|
}
|
|
170
|
-
|
|
171
116
|
return style;
|
|
172
117
|
});
|
|
173
|
-
|
|
174
118
|
return _this;
|
|
175
119
|
}
|
|
176
|
-
|
|
177
120
|
_createClass(EditorContainer, [{
|
|
178
121
|
key: "componentDidMount",
|
|
179
122
|
value: function componentDidMount() {
|
|
180
123
|
var container = this.containerRef.current;
|
|
181
|
-
var parent = container.parentElement;
|
|
182
|
-
|
|
183
|
-
this.resizeSensor = new _cssElementQueries.ResizeSensor(parent, this.onSizeChange); // initial size change should be called
|
|
124
|
+
var parent = container.parentElement;
|
|
184
125
|
|
|
126
|
+
// register ResizeSensor in the parent to detect container size changes
|
|
127
|
+
this.resizeSensor = new _cssElementQueries.ResizeSensor(parent, this.onSizeChange);
|
|
128
|
+
// initial size change should be called
|
|
185
129
|
var _parent$getBoundingCl = parent.getBoundingClientRect(),
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
130
|
+
width = _parent$getBoundingCl.width,
|
|
131
|
+
height = _parent$getBoundingCl.height;
|
|
189
132
|
this.onSizeChange({
|
|
190
133
|
width: width,
|
|
191
134
|
height: height
|
|
192
135
|
});
|
|
193
136
|
var _this$props2 = this.props,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
137
|
+
onContainerReady = _this$props2.onContainerReady,
|
|
138
|
+
canvas = _this$props2.canvas;
|
|
197
139
|
if (onContainerReady) {
|
|
198
140
|
this._unmountCallback = onContainerReady({
|
|
199
141
|
container: container
|
|
200
142
|
});
|
|
201
143
|
}
|
|
202
|
-
|
|
203
144
|
if (canvas) {
|
|
204
145
|
canvas.on(_Canvas.CanvasEvents.OnSizeChange, this.onCanvasSizeChange);
|
|
205
146
|
}
|
|
@@ -208,11 +149,9 @@ var EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
208
149
|
key: "componentWillUnmount",
|
|
209
150
|
value: function componentWillUnmount() {
|
|
210
151
|
this.resizeSensor && this.resizeSensor.detach();
|
|
211
|
-
|
|
212
152
|
if (this._unmountCallback) {
|
|
213
153
|
this._unmountCallback();
|
|
214
154
|
}
|
|
215
|
-
|
|
216
155
|
this.props.canvas && this.props.canvas.off(_Canvas.CanvasEvents.OnSizeChange, this.onCanvasSizeChange);
|
|
217
156
|
}
|
|
218
157
|
}, {
|
|
@@ -220,26 +159,21 @@ var EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
220
159
|
value: function componentDidUpdate(prevProps, prevState) {
|
|
221
160
|
var editorSize = this.state.editorSize;
|
|
222
161
|
var _this$props3 = this.props,
|
|
223
|
-
|
|
224
|
-
|
|
162
|
+
canvas = _this$props3.canvas,
|
|
163
|
+
selectedColor = _this$props3.selectedColor;
|
|
225
164
|
var prevCanvas = prevProps.canvas,
|
|
226
|
-
|
|
227
|
-
|
|
165
|
+
prevSelectedColor = prevProps.selectedColor;
|
|
228
166
|
if (canvas && canvas !== prevCanvas) {
|
|
229
167
|
prevCanvas && prevCanvas.off(_Canvas.CanvasEvents.OnSizeChange, this.onCanvasSizeChange);
|
|
230
168
|
canvas.on(_Canvas.CanvasEvents.OnSizeChange, this.onCanvasSizeChange);
|
|
231
169
|
}
|
|
232
|
-
|
|
233
170
|
if (selectedColor && selectedColor !== prevSelectedColor) {
|
|
234
171
|
canvas.setSelectedColor(selectedColor);
|
|
235
172
|
}
|
|
236
|
-
|
|
237
173
|
if (canvas !== prevCanvas || editorSize !== prevState.editorSize) {
|
|
238
174
|
this.updateCanvasPosition(prevState);
|
|
239
175
|
}
|
|
240
|
-
|
|
241
176
|
var onContainerUpdate = this.props.onContainerUpdate;
|
|
242
|
-
|
|
243
177
|
if (this.state !== prevState && onContainerUpdate) {
|
|
244
178
|
onContainerUpdate({
|
|
245
179
|
container: this.containerRef.current
|
|
@@ -251,42 +185,35 @@ var EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
251
185
|
value: function updateCanvasPosition() {
|
|
252
186
|
var prevState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state;
|
|
253
187
|
var _this$props4 = this.props,
|
|
254
|
-
|
|
255
|
-
|
|
188
|
+
subtractSiblingsHeight = _this$props4.subtractSiblingsHeight,
|
|
189
|
+
canvas = _this$props4.canvas;
|
|
256
190
|
var editorSize = this.state.editorSize;
|
|
257
191
|
var ew = editorSize.width,
|
|
258
|
-
|
|
259
|
-
|
|
192
|
+
eh = editorSize.height;
|
|
260
193
|
if (subtractSiblingsHeight) {
|
|
261
194
|
eh -= this.calculateSiblingsHeight();
|
|
262
195
|
}
|
|
263
|
-
|
|
264
196
|
if (eh <= 0 || ew <= 0) {
|
|
265
197
|
logger.log('zero editor size, skipping canvas update');
|
|
266
198
|
return;
|
|
267
199
|
}
|
|
268
|
-
|
|
269
200
|
var _canvas$size = canvas.size,
|
|
270
|
-
|
|
271
|
-
|
|
201
|
+
cw = _canvas$size.width,
|
|
202
|
+
ch = _canvas$size.height;
|
|
272
203
|
var ratio = Math.max(cw / ew, ch / eh);
|
|
273
204
|
var allowUpScaling = this.props.allowUpScaling;
|
|
274
|
-
|
|
275
205
|
if (allowUpScaling) {
|
|
276
206
|
var iRatio = 1 / ratio;
|
|
277
207
|
canvas.setZoom(iRatio);
|
|
278
208
|
} else if (ratio > 1) {
|
|
279
209
|
var _iRatio = 1 / ratio;
|
|
280
|
-
|
|
281
210
|
canvas.setZoom(_iRatio);
|
|
282
211
|
} else if (prevState.ratio > 1) {
|
|
283
212
|
canvas.setZoom(1);
|
|
284
213
|
}
|
|
285
|
-
|
|
286
214
|
var _canvas$getElementSiz2 = canvas.getElementSize(),
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
215
|
+
rw = _canvas$getElementSiz2.width,
|
|
216
|
+
rh = _canvas$getElementSiz2.height;
|
|
290
217
|
var fixPosition = !this.props.fillContainer && (cw / ch > 1 ? rw <= ew + 0.1 : rh <= eh + 0.1);
|
|
291
218
|
var canvasPosition = fixPosition ? {
|
|
292
219
|
left: 0,
|
|
@@ -305,9 +232,9 @@ var EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
305
232
|
value: function render() {
|
|
306
233
|
logger.log('render EditorContainer');
|
|
307
234
|
var _this$props5 = this.props,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
235
|
+
className = _this$props5.className,
|
|
236
|
+
children = _this$props5.children,
|
|
237
|
+
fillContainer = _this$props5.fillContainer;
|
|
311
238
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
312
239
|
className: (0, _String.xc)(className, fillContainer && 'fillContainer'),
|
|
313
240
|
style: this.calculateContainerStyle(),
|
|
@@ -317,12 +244,8 @@ var EditorContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
317
244
|
}, children));
|
|
318
245
|
}
|
|
319
246
|
}]);
|
|
320
|
-
|
|
321
247
|
return EditorContainer;
|
|
322
248
|
}(_react["default"].Component);
|
|
323
|
-
|
|
324
|
-
exports.EditorContainer = EditorContainer;
|
|
325
|
-
|
|
326
249
|
_defineProperty(EditorContainer, "propTypes", {
|
|
327
250
|
allowUpScaling: _propTypes["default"].bool,
|
|
328
251
|
subtractSiblingsHeight: _propTypes["default"].bool,
|
|
@@ -334,7 +257,6 @@ _defineProperty(EditorContainer, "propTypes", {
|
|
|
334
257
|
selectedColor: _propTypes["default"].string,
|
|
335
258
|
style: _propTypes["default"].object
|
|
336
259
|
});
|
|
337
|
-
|
|
338
260
|
_defineProperty(EditorContainer, "defaultProps", {
|
|
339
261
|
allowUpScaling: false,
|
|
340
262
|
subtractSiblingsHeight: false,
|
|
@@ -345,17 +267,11 @@ _defineProperty(EditorContainer, "defaultProps", {
|
|
|
345
267
|
onContainerUpdate: null,
|
|
346
268
|
style: null
|
|
347
269
|
});
|
|
348
|
-
|
|
349
|
-
var
|
|
350
|
-
|
|
351
|
-
exports["default"] = _default;
|
|
352
|
-
|
|
353
|
-
var withCanvasPosition = function withCanvasPosition(Component) {
|
|
270
|
+
var _default = exports["default"] = (0, _CanvasProvider.withCanvas)(EditorContainer);
|
|
271
|
+
var withCanvasPosition = exports.withCanvasPosition = function withCanvasPosition(Component) {
|
|
354
272
|
return function (props) {
|
|
355
273
|
return /*#__PURE__*/_react["default"].createElement(CanvasPositionContext.Consumer, null, function (state) {
|
|
356
274
|
return /*#__PURE__*/_react["default"].createElement(Component, _extends({}, state, props));
|
|
357
275
|
});
|
|
358
276
|
};
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
exports.withCanvasPosition = withCanvasPosition;
|
|
277
|
+
};
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
var _default = {
|
|
7
|
+
var _default = exports["default"] = {
|
|
8
8
|
graphicsEditorContainer: {
|
|
9
9
|
backgroundColor: '#fff',
|
|
10
10
|
backgroundImage: 'linear-gradient(45deg,#efefef 25%,transparent 25%,transparent 75%,#efefef 75%,#efefef), linear-gradient(45deg,#efefef 25%,transparent 25%,transparent 75%,#efefef 75%,#efefef)',
|
|
@@ -20,5 +20,4 @@ var _default = {
|
|
|
20
20
|
height: '100%'
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
};
|
|
24
|
-
exports["default"] = _default;
|
|
23
|
+
};
|