@kep-platform/basic-component 0.0.35 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,12 @@
1
1
  import { Transform } from '@dnd-kit/utilities';
2
2
  import React, { HtmlHTMLAttributes, ReactNode } from 'react';
3
+ import { WindowStore } from '../Window';
4
+ import { WindowProps } from '../Window/Window';
3
5
  type ViewPortProps = {
4
6
  children?: ReactNode;
5
- ratio?: number;
6
- width?: number;
7
- height?: number;
7
+ viewPortStore: ViewPortStore;
8
+ onScale?: (left: number, top: number, scale: number, ratio: number) => void;
9
+ onScroll?: (left: number, top: number, scale: number, ratio: number) => void;
8
10
  } & HtmlHTMLAttributes<HTMLDivElement>;
9
11
  export declare class ViewPortStore {
10
12
  transform: {
@@ -19,7 +21,7 @@ export declare class ViewPortStore {
19
21
  width: number;
20
22
  height: number;
21
23
  ratio: number;
22
- constructor(ratio?: number);
24
+ constructor(width?: number, height?: number, ratio?: number);
23
25
  increaseScale(): void;
24
26
  decreaseScale(): void;
25
27
  move(transform: Transform): void;
@@ -34,12 +36,10 @@ export declare class ViewPortStore {
34
36
  min: number;
35
37
  };
36
38
  };
37
- get formatedTransform(): {
39
+ formatedTransform(left: number, top: number): {
38
40
  left: number;
39
41
  top: number;
40
42
  };
41
- get minScale(): number;
42
- get maxScale(): number;
43
43
  get formatedScale(): number;
44
44
  get contentStyle(): {
45
45
  left: string;
@@ -55,5 +55,43 @@ export declare class ViewPortStore {
55
55
  overflow: string;
56
56
  };
57
57
  }
58
- export default function ViewPort(props: ViewPortProps): React.JSX.Element;
59
- export {};
58
+ declare function ViewPort(props: ViewPortProps): React.JSX.Element;
59
+ declare namespace ViewPort {
60
+ var Window: React.FunctionComponent<WindowProps & {
61
+ viewPortStore: ViewPortStore;
62
+ window: ViewPortWindowStore;
63
+ }>;
64
+ }
65
+ export default ViewPort;
66
+ export declare class ViewPortWindowStore extends WindowStore {
67
+ scale: number;
68
+ get style(): {
69
+ left: string;
70
+ top: string;
71
+ width: string;
72
+ height: string;
73
+ zIndex: number;
74
+ transform: string;
75
+ transition: string;
76
+ transformOrigin?: undefined;
77
+ } | {
78
+ left: string;
79
+ top: string;
80
+ width: number;
81
+ height: number;
82
+ zIndex: number;
83
+ transform: string;
84
+ transition: string;
85
+ transformOrigin?: undefined;
86
+ } | {
87
+ left: string;
88
+ top: string;
89
+ width: string;
90
+ height: string;
91
+ zIndex: number;
92
+ transform: string;
93
+ transformOrigin: string;
94
+ transition: string;
95
+ };
96
+ constructor(id: string, onClosedHandler?: (id: string) => void);
97
+ }
@@ -1,10 +1,15 @@
1
+ var _excluded = ["children", "viewPortStore"],
2
+ _excluded2 = ["viewPortStore", "window"];
1
3
  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); }
2
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- 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); }
5
- 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; }
6
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
4
+ 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); }
5
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
6
+ 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); }; }
7
+ 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); }
8
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
9
+ 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; } }
10
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
11
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
12
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
8
13
  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); }
9
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
15
  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); } }
@@ -13,10 +18,12 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
13
18
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
19
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
20
  import { DndContext, useDraggable } from '@dnd-kit/core';
16
- import { makeAutoObservable, runInAction } from 'mobx';
21
+ import { makeAutoObservable, makeObservable, observable, override, runInAction } from 'mobx';
17
22
  import { observer } from 'mobx-react-lite';
18
- import React, { useEffect, useRef, useState } from 'react';
23
+ import React, { useEffect, useRef } from 'react';
19
24
  import styled from 'styled-components';
25
+ import { WindowStore } from "../Window";
26
+ import { default as Window } from "../Window/Window";
20
27
  import { GlobalStyles } from "../__styles";
21
28
  var Container = styled.div.withConfig({
22
29
  displayName: "Container",
@@ -28,7 +35,7 @@ var Content = styled.div.withConfig({
28
35
  })(["position:absolute;"]);
29
36
  export var ViewPortStore = /*#__PURE__*/function () {
30
37
  //缩放比例
31
- function ViewPortStore(ratio) {
38
+ function ViewPortStore(width, height, ratio) {
32
39
  _classCallCheck(this, ViewPortStore);
33
40
  _defineProperty(this, "transform", {
34
41
  left: 0,
@@ -43,6 +50,8 @@ export var ViewPortStore = /*#__PURE__*/function () {
43
50
  _defineProperty(this, "height", 800);
44
51
  _defineProperty(this, "ratio", 5);
45
52
  if (ratio) this.ratio = ratio;
53
+ if (width) this.width = width;
54
+ if (height) this.height = height;
46
55
  makeAutoObservable(this);
47
56
  }
48
57
  _createClass(ViewPortStore, [{
@@ -53,13 +62,12 @@ export var ViewPortStore = /*#__PURE__*/function () {
53
62
  }, {
54
63
  key: "decreaseScale",
55
64
  value: function decreaseScale() {
56
- if (this.scale > this.minScale) this.scale -= 0.03125;
65
+ if (this.scale > parseFloat((1 / this.ratio).toFixed(1))) this.scale -= 0.03125;
57
66
  }
58
67
  }, {
59
68
  key: "move",
60
69
  value: function move(transform) {
61
- this.transform.left = transform.x - this.offset.x + this.transform.left;
62
- this.transform.top = transform.y - this.offset.y + this.transform.top;
70
+ this.transform = this.formatedTransform(transform.x - this.offset.x + this.transform.left, transform.y - this.offset.y + this.transform.top);
63
71
  this.offset.x = transform.x;
64
72
  this.offset.y = transform.y;
65
73
  }
@@ -85,33 +93,23 @@ export var ViewPortStore = /*#__PURE__*/function () {
85
93
  }
86
94
  }, {
87
95
  key: "formatedTransform",
88
- get: function get() {
96
+ value: function formatedTransform(left, top) {
89
97
  return {
90
- left: Math.max(this.transformLimit.left.min, Math.min(this.transform.left, this.transformLimit.left.max)),
91
- top: Math.max(this.transformLimit.top.min, Math.min(this.transform.top, this.transformLimit.top.max))
98
+ left: Math.max(this.transformLimit.left.min, Math.min(left, this.transformLimit.left.max)),
99
+ top: Math.max(this.transformLimit.top.min, Math.min(top, this.transformLimit.top.max))
92
100
  };
93
101
  }
94
- }, {
95
- key: "minScale",
96
- get: function get() {
97
- return parseFloat((1 / this.ratio).toFixed(1));
98
- }
99
- }, {
100
- key: "maxScale",
101
- get: function get() {
102
- return 1;
103
- }
104
102
  }, {
105
103
  key: "formatedScale",
106
104
  get: function get() {
107
- return Math.min(this.maxScale, Math.max(this.minScale, this.scale));
105
+ return Math.min(1, Math.max(parseFloat((1 / this.ratio).toFixed(1)), this.scale));
108
106
  }
109
107
  }, {
110
108
  key: "contentStyle",
111
109
  get: function get() {
112
110
  return {
113
- left: this.formatedTransform.left + 'px',
114
- top: this.formatedTransform.top + 'px',
111
+ left: this.transform.left + 'px',
112
+ top: this.transform.top + 'px',
115
113
  transform: "scale(".concat(this.formatedScale, ")"),
116
114
  width: this.width * this.ratio + 'px',
117
115
  height: this.height * this.ratio + 'px',
@@ -132,7 +130,9 @@ export var ViewPortStore = /*#__PURE__*/function () {
132
130
  }();
133
131
  var ViewPortEntity = observer(function (props) {
134
132
  var children = props.children,
135
- viewPortStore = props.viewPortStore;
133
+ viewPortStore = props.viewPortStore,
134
+ onScroll = props.onScroll,
135
+ onScale = props.onScale;
136
136
  var _useDraggable = useDraggable({
137
137
  id: 'ViewPortEntity'
138
138
  }),
@@ -145,6 +145,7 @@ var ViewPortEntity = observer(function (props) {
145
145
  useEffect(function () {
146
146
  if (transform) {
147
147
  viewPortStore.move(transform);
148
+ onScroll === null || onScroll === void 0 || onScroll(viewPortStore.transform.left, viewPortStore.transform.top, viewPortStore.scale, viewPortStore.ratio);
148
149
  } else {
149
150
  viewPortStore.endMove();
150
151
  }
@@ -159,6 +160,7 @@ var ViewPortEntity = observer(function (props) {
159
160
  } else {
160
161
  viewPortStore.decreaseScale();
161
162
  }
163
+ onScale === null || onScale === void 0 || onScale(viewPortStore.transform.left, viewPortStore.transform.top, viewPortStore.scale, viewPortStore.ratio);
162
164
  }
163
165
  (_ref$current = _ref.current) === null || _ref$current === void 0 || _ref$current.addEventListener('wheel', scaleHandler, {
164
166
  passive: false
@@ -178,28 +180,107 @@ var ViewPortEntity = observer(function (props) {
178
180
  }
179
181
  }, attributes, listeners, {
180
182
  style: viewPortStore.contentStyle
181
- }), viewPortStore.ratio, children));
183
+ }), children));
182
184
  });
183
185
  export default function ViewPort(props) {
184
186
  var children = props.children,
185
- ratio = props.ratio,
186
- width = props.width,
187
- height = props.height;
188
- var _useState = useState(function () {
189
- return new ViewPortStore(ratio);
190
- }),
191
- _useState2 = _slicedToArray(_useState, 1),
192
- viewPortStore = _useState2[0];
193
- useEffect(function () {
194
- runInAction(function () {
195
- if (ratio) viewPortStore.ratio = ratio;
196
- if (width) viewPortStore.width = width;
197
- if (height) viewPortStore.height = height;
198
- });
199
- }, [ratio, width, height]);
187
+ viewPortStore = props.viewPortStore,
188
+ rest = _objectWithoutProperties(props, _excluded);
200
189
  return /*#__PURE__*/React.createElement(DndContext, null, /*#__PURE__*/React.createElement(GlobalStyles, {
201
190
  $css: []
202
- }), /*#__PURE__*/React.createElement(ViewPortEntity, {
191
+ }), /*#__PURE__*/React.createElement(ViewPortEntity, _extends({
203
192
  viewPortStore: viewPortStore
204
- }, children));
205
- }
193
+ }, rest), children));
194
+ }
195
+ export var ViewPortWindowStore = /*#__PURE__*/function (_WindowStore) {
196
+ _inherits(ViewPortWindowStore, _WindowStore);
197
+ var _super = _createSuper(ViewPortWindowStore);
198
+ function ViewPortWindowStore(id, onClosedHandler) {
199
+ var _this;
200
+ _classCallCheck(this, ViewPortWindowStore);
201
+ _this = _super.call(this, id, onClosedHandler);
202
+ _defineProperty(_assertThisInitialized(_this), "scale", 1);
203
+ makeObservable(_assertThisInitialized(_this), {
204
+ style: override,
205
+ scale: observable
206
+ });
207
+ return _this;
208
+ }
209
+ _createClass(ViewPortWindowStore, [{
210
+ key: "style",
211
+ get: function get() {
212
+ if (this.isClosed) {
213
+ return {
214
+ left: this.left + 'px',
215
+ top: this.top + 'px',
216
+ width: this.width + 'px',
217
+ height: this.height + 'px',
218
+ zIndex: this.zIndex,
219
+ transform: 'scale(0)',
220
+ transition: 'all 0.5s ease-out'
221
+ };
222
+ }
223
+ if (this.isMinimize && this.minimizePos) {
224
+ return {
225
+ left: this.minimizePos.left + 'px',
226
+ top: this.minimizePos.top + 'px',
227
+ width: 0,
228
+ height: 0,
229
+ zIndex: this.zIndex,
230
+ transform: 'scale(0)',
231
+ transition: 'all 0.5s ease-out'
232
+ };
233
+ }
234
+ if (this.fullscreen) {
235
+ return {
236
+ left: this.fullscreenPos.left / this.scale + 'px',
237
+ top: this.fullscreenPos.top / this.scale + 'px',
238
+ width: this.fullscreenPos.width + 'px',
239
+ height: this.fullscreenPos.height + 'px',
240
+ zIndex: this.zIndex,
241
+ transform: "scale(".concat(1 / this.scale, ") "),
242
+ transformOrigin: 'left top',
243
+ transition: 'width height 0.5s ease-out'
244
+ };
245
+ }
246
+ if (this.isMoving || this.isResizing) {
247
+ return {
248
+ left: this.left + 'px',
249
+ top: this.top + 'px',
250
+ width: this.width + 'px',
251
+ height: this.height + 'px',
252
+ zIndex: this.zIndex,
253
+ transform: 'none',
254
+ transition: 'none'
255
+ };
256
+ }
257
+ return {
258
+ left: this.left + 'px',
259
+ top: this.top + 'px',
260
+ width: this.width + 'px',
261
+ height: this.height + 'px',
262
+ zIndex: this.zIndex,
263
+ transform: 'none',
264
+ transition: 'all 0.5s ease-out'
265
+ };
266
+ }
267
+ }]);
268
+ return ViewPortWindowStore;
269
+ }(WindowStore);
270
+ ViewPort.Window = observer(function ViewPortWindow(props) {
271
+ var viewPortStore = props.viewPortStore,
272
+ window = props.window,
273
+ rest = _objectWithoutProperties(props, _excluded2);
274
+ useEffect(function () {
275
+ runInAction(function () {
276
+ window.fullscreenPos.left = -viewPortStore.transform.left;
277
+ window.fullscreenPos.top = -viewPortStore.transform.top;
278
+ window.fullscreenPos.width = viewPortStore.width;
279
+ window.fullscreenPos.height = viewPortStore.height;
280
+ window.scale = viewPortStore.scale;
281
+ });
282
+ }, [viewPortStore.transform.left, viewPortStore.transform.top, viewPortStore.scale, viewPortStore.ratio, viewPortStore.width, viewPortStore.height]);
283
+ return /*#__PURE__*/React.createElement(Window, _extends({
284
+ window: window
285
+ }, rest));
286
+ });
@@ -1,2 +1,3 @@
1
1
  import React from 'react';
2
- export default function Test(): React.JSX.Element;
2
+ declare const _default: React.FunctionComponent<object>;
3
+ export default _default;
@@ -1,24 +1,18 @@
1
1
  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); }
2
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- 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); }
5
- 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; }
6
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
2
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
3
  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); } }
10
4
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
5
  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; }
12
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
7
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
- import { makeAutoObservable } from 'mobx';
15
- import React, { useEffect, useState } from 'react';
16
- import { Window, WindowStore } from "../Window";
17
- import ViewPort from "./ViewPort";
8
+ import { makeAutoObservable, runInAction } from 'mobx';
9
+ import { observer, useLocalObservable } from 'mobx-react-lite';
10
+ import React, { useEffect } from 'react';
11
+ import ViewPort, { ViewPortStore, ViewPortWindowStore } from "./ViewPort";
18
12
  var WindowManager = /*#__PURE__*/function () {
19
13
  function WindowManager() {
20
14
  _classCallCheck(this, WindowManager);
21
- _defineProperty(this, "windows", [new WindowStore('jss', this.closeWindowHanlder.bind(this)), new WindowStore('jx', this.closeWindowHanlder.bind(this)), new WindowStore('jiangxin', this.closeWindowHanlder.bind(this)), new WindowStore('xixi', this.closeWindowHanlder.bind(this))]);
15
+ _defineProperty(this, "windows", [new ViewPortWindowStore('jss', this.closeWindowHanlder.bind(this))]);
22
16
  makeAutoObservable(this);
23
17
  }
24
18
  _createClass(WindowManager, [{
@@ -39,19 +33,16 @@ var WindowManager = /*#__PURE__*/function () {
39
33
  return WindowManager;
40
34
  }();
41
35
  var windowManager = new WindowManager();
42
- export default function Test() {
43
- var _useState = useState(0),
44
- _useState2 = _slicedToArray(_useState, 2),
45
- width = _useState2[0],
46
- setWidth = _useState2[1];
47
- var _useState3 = useState(0),
48
- _useState4 = _slicedToArray(_useState3, 2),
49
- height = _useState4[0],
50
- setHeight = _useState4[1];
36
+ export default observer(function Test() {
37
+ var viewPortStore = useLocalObservable(function () {
38
+ return new ViewPortStore(0, 0, 5);
39
+ });
51
40
  useEffect(function () {
52
41
  function setWidthHeight() {
53
- setWidth(document.body.offsetWidth);
54
- setHeight(document.body.offsetHeight);
42
+ runInAction(function () {
43
+ viewPortStore.width = 800;
44
+ viewPortStore.height = 800;
45
+ });
55
46
  }
56
47
  window.addEventListener('resize', setWidthHeight);
57
48
  setWidthHeight();
@@ -60,14 +51,13 @@ export default function Test() {
60
51
  };
61
52
  }, []);
62
53
  return /*#__PURE__*/React.createElement(ViewPort, {
63
- ratio: 5,
64
- width: width,
65
- height: height
54
+ viewPortStore: viewPortStore
66
55
  }, windowManager.windows.map(function (windowStore) {
67
- return /*#__PURE__*/React.createElement(Window, {
56
+ return /*#__PURE__*/React.createElement(ViewPort.Window, {
68
57
  window: windowStore,
69
58
  key: windowStore.id,
70
- title: 'xixi'
71
- }, "123");
59
+ title: 'xixi',
60
+ viewPortStore: viewPortStore
61
+ }, /*#__PURE__*/React.createElement("br", null));
72
62
  }));
73
- }
63
+ });
@@ -4,10 +4,6 @@ export type WindowProps = {
4
4
  window: WindowStore;
5
5
  children: ReactNode;
6
6
  title: ReactNode;
7
- minimizePos?: {
8
- left: number;
9
- top: number;
10
- };
11
7
  };
12
8
  declare const Window: ((props: WindowProps) => React.JSX.Element) & {
13
9
  displayName: string;
@@ -1,6 +1,6 @@
1
1
  import { CloseCircleOutlined, FullscreenExitOutlined, FullscreenOutlined, MinusCircleOutlined } from '@ant-design/icons';
2
2
  import { observer } from 'mobx-react-lite';
3
- import React from 'react';
3
+ import React, { useEffect, useRef } from 'react';
4
4
  import styled, { css } from 'styled-components';
5
5
  import { Space } from "../Space";
6
6
  import WindowController from "./WindowController";
@@ -74,12 +74,20 @@ var WindowControllerRightBottom = styled(WindowController).withConfig({
74
74
  var Window = observer(function (props) {
75
75
  var window = props.window,
76
76
  title = props.title,
77
- children = props.children,
78
- _props$minimizePos = props.minimizePos,
79
- minimizePos = _props$minimizePos === void 0 ? {
80
- left: 0,
81
- top: 0
82
- } : _props$minimizePos;
77
+ children = props.children;
78
+ var windowContainerRef = useRef(null);
79
+ useEffect(function () {
80
+ var _windowContainerRef$c;
81
+ function stopWheel(e) {
82
+ e.stopPropagation();
83
+ e.preventDefault();
84
+ }
85
+ (_windowContainerRef$c = windowContainerRef.current) === null || _windowContainerRef$c === void 0 || _windowContainerRef$c.addEventListener('wheel', stopWheel);
86
+ return function () {
87
+ var _windowContainerRef$c2;
88
+ (_windowContainerRef$c2 = windowContainerRef.current) === null || _windowContainerRef$c2 === void 0 || _windowContainerRef$c2.removeEventListener('wheel', stopWheel);
89
+ };
90
+ }, []);
83
91
  /* style 的原因是因为性能问题 */
84
92
  return /*#__PURE__*/React.createElement(WindowContainer, {
85
93
  style: window.style,
@@ -89,7 +97,11 @@ var Window = observer(function (props) {
89
97
  var _window$onClosedHandl;
90
98
  (_window$onClosedHandl = window.onClosedHandler) === null || _window$onClosedHandl === void 0 || _window$onClosedHandl.call(window, window.id);
91
99
  }
92
- }
100
+ },
101
+ onPointerDown: function onPointerDown(e) {
102
+ e.stopPropagation();
103
+ },
104
+ ref: windowContainerRef
93
105
  }, /*#__PURE__*/React.createElement(WindowControllerLeft, {
94
106
  window: window,
95
107
  type: "left"
@@ -118,7 +130,14 @@ var Window = observer(function (props) {
118
130
  window: window,
119
131
  type: "move"
120
132
  }, /*#__PURE__*/React.createElement(WindowHeader, {
121
- isDragging: window.isMoving
133
+ isDragging: window.isMoving,
134
+ onDoubleClick: function onDoubleClick() {
135
+ if (window.fullscreen) {
136
+ window.fullscreenExitWindow();
137
+ } else {
138
+ window.fullscreenWindow();
139
+ }
140
+ }
122
141
  }, /*#__PURE__*/React.createElement("h5", null, title), /*#__PURE__*/React.createElement(WindowHeaderOptions, {
123
142
  onPointerDown: function onPointerDown(e) {
124
143
  e.stopPropagation();
@@ -139,7 +158,7 @@ var Window = observer(function (props) {
139
158
  color: "var(--kep-platform-green-3)",
140
159
  icon: /*#__PURE__*/React.createElement(MinusCircleOutlined, null),
141
160
  onClick: function onClick() {
142
- window.minimizeWindow(minimizePos);
161
+ window.minimizeWindow();
143
162
  }
144
163
  }), /*#__PURE__*/React.createElement(WindowOption, {
145
164
  onClick: function onClick() {
@@ -147,6 +166,6 @@ var Window = observer(function (props) {
147
166
  },
148
167
  icon: /*#__PURE__*/React.createElement(CloseCircleOutlined, null),
149
168
  color: "var(--kep-platform-red)"
150
- }))))), /*#__PURE__*/React.createElement(WindowBody, null, children)));
169
+ }))))), /*#__PURE__*/React.createElement(WindowBody, null, window.info, children)));
151
170
  });
152
171
  export default Window;
@@ -1,10 +1,10 @@
1
1
  import { Transform } from '@dnd-kit/utilities';
2
2
  import { WindowControllerType } from './WindowController';
3
3
  export default class WindowStore {
4
- width: string;
5
- height: string;
6
- left: string;
7
- top: string;
4
+ width: number;
5
+ height: number;
6
+ left: number;
7
+ top: number;
8
8
  zIndex: number;
9
9
  fullscreen: boolean;
10
10
  id: string;
@@ -18,6 +18,12 @@ export default class WindowStore {
18
18
  left: number;
19
19
  top: number;
20
20
  } | null;
21
+ fullscreenPos: {
22
+ left: number;
23
+ top: number;
24
+ width: number;
25
+ height: number;
26
+ };
21
27
  isMinimize: boolean;
22
28
  isClosed: boolean;
23
29
  onClosedHandler: ((id: string) => void) | undefined;
@@ -31,19 +37,25 @@ export default class WindowStore {
31
37
  };
32
38
  controll(transform: Transform, type: WindowControllerType): void;
33
39
  endControll(): void;
34
- minimizeWindow(minimize: {
35
- left: number;
36
- top: number;
37
- }): void;
40
+ minimizeWindow(): void;
38
41
  normalizeWindow(): void;
39
42
  closeWindow(): void;
40
43
  get style(): {
41
- left: string | number;
42
- top: string | number;
43
- width: string | number;
44
- height: string | number;
44
+ left: string;
45
+ top: string;
46
+ width: string;
47
+ height: string;
48
+ zIndex: number;
49
+ transform: string;
50
+ transition: string;
51
+ } | {
52
+ left: string;
53
+ top: string;
54
+ width: number;
55
+ height: number;
45
56
  zIndex: number;
46
57
  transform: string;
47
58
  transition: string;
48
59
  };
60
+ get info(): string;
49
61
  }
@@ -9,10 +9,10 @@ import { action, computed, makeObservable, observable } from 'mobx';
9
9
  var WindowStore = /*#__PURE__*/function () {
10
10
  function WindowStore(id, onClosedHandler) {
11
11
  _classCallCheck(this, WindowStore);
12
- _defineProperty(this, "width", '400px');
13
- _defineProperty(this, "height", '400px');
14
- _defineProperty(this, "left", '0px');
15
- _defineProperty(this, "top", '0px');
12
+ _defineProperty(this, "width", 400);
13
+ _defineProperty(this, "height", 400);
14
+ _defineProperty(this, "left", 0);
15
+ _defineProperty(this, "top", 0);
16
16
  _defineProperty(this, "zIndex", 1);
17
17
  _defineProperty(this, "fullscreen", false);
18
18
  _defineProperty(this, "id", '');
@@ -20,6 +20,12 @@ var WindowStore = /*#__PURE__*/function () {
20
20
  _defineProperty(this, "isMoving", false);
21
21
  _defineProperty(this, "isResizing", false);
22
22
  _defineProperty(this, "minimizePos", null);
23
+ _defineProperty(this, "fullscreenPos", {
24
+ left: 0,
25
+ top: 0,
26
+ width: 0,
27
+ height: 0
28
+ });
23
29
  _defineProperty(this, "isMinimize", false);
24
30
  _defineProperty(this, "isClosed", false);
25
31
  _defineProperty(this, "onClosedHandler", void 0);
@@ -41,10 +47,12 @@ var WindowStore = /*#__PURE__*/function () {
41
47
  style: computed.struct,
42
48
  isMinimize: observable,
43
49
  minimizePos: observable.struct,
50
+ fullscreenPos: observable.struct,
44
51
  minimizeWindow: action,
45
52
  normalizeWindow: action,
46
53
  closeWindow: action,
47
- resetState: action
54
+ resetState: action,
55
+ info: computed
48
56
  });
49
57
  this.id = id;
50
58
  this.onClosedHandler = onClosedHandler;
@@ -87,22 +95,22 @@ var WindowStore = /*#__PURE__*/function () {
87
95
  this.isResizing = true;
88
96
  }
89
97
  if (type.includes('left')) {
90
- this.left = Math.round(parseFloat(this.left) + offsetTransform.x) + 'px';
91
- this.width = Math.round(parseFloat(this.width) - offsetTransform.x) + 'px';
98
+ this.left = Math.round(this.left + offsetTransform.x);
99
+ this.width = Math.round(this.width - offsetTransform.x);
92
100
  }
93
101
  if (type.includes('right')) {
94
- this.width = Math.round(parseFloat(this.width) + offsetTransform.x) + 'px';
102
+ this.width = Math.round(this.width + offsetTransform.x);
95
103
  }
96
104
  if (type.includes('top')) {
97
- this.top = Math.round(parseFloat(this.top) + offsetTransform.y) + 'px';
98
- this.height = Math.round(parseFloat(this.height) - offsetTransform.y) + 'px';
105
+ this.top = Math.round(this.top + offsetTransform.y);
106
+ this.height = Math.round(this.height - offsetTransform.y);
99
107
  }
100
108
  if (type.includes('bottom')) {
101
- this.height = Math.round(parseFloat(this.height) + offsetTransform.y) + 'px';
109
+ this.height = Math.round(this.height + offsetTransform.y);
102
110
  }
103
111
  if (type.includes('move')) {
104
- this.left = Math.round(parseFloat(this.left) + offsetTransform.x) + 'px';
105
- this.top = Math.round(parseFloat(this.top) + offsetTransform.y) + 'px';
112
+ this.left = Math.round(this.left + offsetTransform.x);
113
+ this.top = Math.round(this.top + offsetTransform.y);
106
114
  }
107
115
  this.transform = transform;
108
116
  }
@@ -115,8 +123,7 @@ var WindowStore = /*#__PURE__*/function () {
115
123
  }
116
124
  }, {
117
125
  key: "minimizeWindow",
118
- value: function minimizeWindow(minimize) {
119
- this.minimizePos = minimize;
126
+ value: function minimizeWindow() {
120
127
  this.isMinimize = true;
121
128
  this.fullscreen = false;
122
129
  this.resetState();
@@ -138,16 +145,64 @@ var WindowStore = /*#__PURE__*/function () {
138
145
  }, {
139
146
  key: "style",
140
147
  get: function get() {
141
- var renderStyle = {
142
- left: this.isClosed ? this.left : this.isMinimize && this.minimizePos ? this.minimizePos.left : this.fullscreen ? 0 : this.left,
143
- top: this.isClosed ? this.top : this.isMinimize && this.minimizePos ? this.minimizePos.top : this.fullscreen ? 0 : this.top,
144
- width: this.isClosed ? this.width : this.isMinimize ? 0 : this.fullscreen ? '100%' : this.width,
145
- height: this.isClosed ? this.height : this.isMinimize ? 0 : this.fullscreen ? '100%' : this.height,
148
+ if (this.isClosed) {
149
+ return {
150
+ left: this.left + 'px',
151
+ top: this.top + 'px',
152
+ width: this.width + 'px',
153
+ height: this.height + 'px',
154
+ zIndex: this.zIndex,
155
+ transform: 'scale(0)',
156
+ transition: 'all 0.5s ease-out'
157
+ };
158
+ }
159
+ if (this.isMinimize && this.minimizePos) {
160
+ return {
161
+ left: this.minimizePos.left + 'px',
162
+ top: this.minimizePos.top + 'px',
163
+ width: 0,
164
+ height: 0,
165
+ zIndex: this.zIndex,
166
+ transform: 'scale(0)',
167
+ transition: 'all 0.5s ease-out'
168
+ };
169
+ }
170
+ if (this.fullscreen) {
171
+ return {
172
+ left: this.fullscreenPos.left + 'px',
173
+ top: this.fullscreenPos.top + 'px',
174
+ width: this.fullscreenPos.width + 'px',
175
+ height: this.fullscreenPos.height + 'px',
176
+ zIndex: this.zIndex,
177
+ transform: 'none',
178
+ transition: 'all 0.5s ease-out'
179
+ };
180
+ }
181
+ if (this.isMoving || this.isResizing) {
182
+ return {
183
+ left: this.left + 'px',
184
+ top: this.top + 'px',
185
+ width: this.width + 'px',
186
+ height: this.height + 'px',
187
+ zIndex: this.zIndex,
188
+ transform: 'none',
189
+ transition: 'none'
190
+ };
191
+ }
192
+ return {
193
+ left: this.left + 'px',
194
+ top: this.top + 'px',
195
+ width: this.width + 'px',
196
+ height: this.height + 'px',
146
197
  zIndex: this.zIndex,
147
- transform: this.isMinimize || this.isClosed ? 'scale(0)' : 'none',
148
- transition: this.isMoving || this.isResizing ? 'none' : 'all 0.5s ease-out'
198
+ transform: 'none',
199
+ transition: 'all 0.5s ease-out'
149
200
  };
150
- return renderStyle;
201
+ }
202
+ }, {
203
+ key: "info",
204
+ get: function get() {
205
+ return JSON.stringify(this.fullscreenPos, null, 4);
151
206
  }
152
207
  }]);
153
208
  return WindowStore;
@@ -7,10 +7,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
7
7
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
8
  import { DndContext } from '@dnd-kit/core';
9
9
  import { makeAutoObservable } from 'mobx';
10
- import { observer } from 'mobx-react-lite';
10
+ import { observer, useLocalObservable } from 'mobx-react-lite';
11
11
  import React from 'react';
12
- import { Button } from "../Button";
13
- import { Space } from "../Space";
12
+ import { ViewPort, ViewPortStore } from "../ViewPort";
14
13
  import { GlobalStyles } from "../__styles";
15
14
  import Window from "./Window";
16
15
  import { WindowStore } from "./index";
@@ -39,19 +38,18 @@ var WindowManager = /*#__PURE__*/function () {
39
38
  }();
40
39
  var windowManager = new WindowManager();
41
40
  export default observer(function Test() {
41
+ var viewPortStore = useLocalObservable(function () {
42
+ return new ViewPortStore();
43
+ });
42
44
  return /*#__PURE__*/React.createElement(DndContext, null, /*#__PURE__*/React.createElement(GlobalStyles, {
43
45
  $css: []
44
- }), /*#__PURE__*/React.createElement(Space, null, windowManager.report, /*#__PURE__*/React.createElement(Button, {
45
- onClick: function onClick() {
46
- windowManager.windows.forEach(function (window) {
47
- window.normalizeWindow();
48
- });
49
- }
50
- }, "\u5C55\u5F00")), windowManager.windows.map(function (windowStore) {
46
+ }), /*#__PURE__*/React.createElement(ViewPort, {
47
+ viewPortStore: viewPortStore
48
+ }, windowManager.windows.map(function (windowStore) {
51
49
  return /*#__PURE__*/React.createElement(Window, {
52
50
  window: windowStore,
53
51
  key: windowStore.id,
54
52
  title: 'xixi'
55
53
  }, "123");
56
- }));
54
+ })));
57
55
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kep-platform/basic-component",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@ant-design/icons": "^5.3.7",
50
- "@kep-platform/hooks": "^0.0.35",
50
+ "@kep-platform/hooks": "^0.0.37",
51
51
  "color": "^4.2.3",
52
52
  "rc-pagination": "^4.1.0",
53
53
  "styled-components": "^6.1.11"
@@ -87,5 +87,5 @@
87
87
  "authors": [
88
88
  "lee-step-jss 1599925910@qq.com"
89
89
  ],
90
- "gitHead": "cc6b4bd3ca4d5463f8abf837c04fc4bae0ba17df"
90
+ "gitHead": "80925e92fb2de497863b5dd479f24a343e62ca38"
91
91
  }