@kep-platform/basic-component 0.0.42 → 0.0.44

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,6 @@ type ViewPortProps = {
9
9
  declare function ViewPort(props: ViewPortProps): React.JSX.Element;
10
10
  declare namespace ViewPort {
11
11
  var Window: React.FunctionComponent<import("../Window/Window").WindowProps & {
12
- viewPortStore: ViewPortStore;
13
12
  window: import("./ViewPortWindow").ViewPortWindowStore;
14
13
  }>;
15
14
  }
@@ -30,6 +30,20 @@ export declare class ViewPortStore {
30
30
  move(transform: Transform): void;
31
31
  endMove(): void;
32
32
  get contentStyle(): CSSProperties;
33
+ get viewPortRect(): {
34
+ left: number;
35
+ top: number;
36
+ width: number;
37
+ height: number;
38
+ scale: number;
39
+ };
40
+ posInViewPort(left: number, top: number, width: number, height: number): {
41
+ left: number;
42
+ top: number;
43
+ width: number;
44
+ height: number;
45
+ scale: number;
46
+ };
33
47
  get containerStyle(): CSSProperties;
34
48
  get info(): string;
35
49
  }
@@ -131,11 +131,28 @@ export var ViewPortStore = /*#__PURE__*/function () {
131
131
  width: this.width * this.ratio + 'px',
132
132
  height: this.height * this.ratio + 'px',
133
133
  transformOrigin: 'left top',
134
- transition: this.isMoving ? 'none' : 'all 0.5s',
134
+ transition: this.isMoving ? 'none' : 'all 1s ease-in-out',
135
135
  background: '#188fff67',
136
136
  cursor: this.isMoving ? 'grab' : 'default'
137
137
  };
138
138
  }
139
+ }, {
140
+ key: "viewPortRect",
141
+ get: function get() {
142
+ return this.posInViewPort(0, 0, this.width, this.height);
143
+ }
144
+ /* 这个函数比较重要,因为你想要让content中的元素在视窗相对位置显示,这个函数会帮你计算偏移量和缩放量,直接得出你的元素应该在content中的偏移量 */
145
+ }, {
146
+ key: "posInViewPort",
147
+ value: function posInViewPort(left, top, width, height) {
148
+ return {
149
+ left: (-this.transform.left + this.offsetLeft + left) / this.scale,
150
+ top: (-this.transform.top + this.offsetTop + top) / this.scale,
151
+ width: width / this.scale,
152
+ height: height / this.scale,
153
+ scale: this.scale
154
+ };
155
+ }
139
156
  }, {
140
157
  key: "containerStyle",
141
158
  get: function get() {
@@ -5,7 +5,7 @@ import { WindowProps } from '../Window/Window';
5
5
  import { WindowControllerType } from '../Window/WindowController';
6
6
  import { ViewPortStore } from './ViewPortStore';
7
7
  export declare class ViewPortWindowStore extends WindowStore {
8
- scale: number;
8
+ viewPortStore: ViewPortStore;
9
9
  get style(): {
10
10
  left: string;
11
11
  top: string;
@@ -13,17 +13,8 @@ export declare class ViewPortWindowStore extends WindowStore {
13
13
  height: string;
14
14
  zIndex: number;
15
15
  transform: string;
16
+ transformOrigin: string;
16
17
  transition: string;
17
- transformOrigin?: undefined;
18
- } | {
19
- left: string;
20
- top: string;
21
- width: number;
22
- height: number;
23
- zIndex: number;
24
- transform: string;
25
- transition: string;
26
- transformOrigin?: undefined;
27
18
  } | {
28
19
  left: string;
29
20
  top: string;
@@ -31,17 +22,19 @@ export declare class ViewPortWindowStore extends WindowStore {
31
22
  height: string;
32
23
  zIndex: number;
33
24
  transform: string;
34
- transformOrigin: string;
35
25
  transition: string;
26
+ transformOrigin?: undefined;
36
27
  };
28
+ focus(): void;
37
29
  calculateTransform(transform: Transform): {
38
30
  x: number;
39
31
  y: number;
40
32
  };
41
33
  controll(transform: Transform, type: WindowControllerType): void;
42
- constructor(id: string, onClosedHandler?: (id: string) => void);
34
+ centerDisplay(): void;
35
+ fullscreenWindow(func?: () => void): void;
36
+ constructor(id: string, viewPort: ViewPortStore, onClosedHandler?: (id: string) => void);
43
37
  }
44
38
  export declare const ViewPortWindow: React.FunctionComponent<WindowProps & {
45
- viewPortStore: ViewPortStore;
46
39
  window: ViewPortWindowStore;
47
40
  }>;
@@ -1,4 +1,4 @@
1
- var _excluded = ["viewPortStore", "window"];
1
+ var _excluded = ["window"];
2
2
  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); }
3
3
  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); }
4
4
  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; }
@@ -16,7 +16,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
16
16
  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; }
17
17
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
18
  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); }
19
- import { makeObservable, observable, override, runInAction } from 'mobx';
19
+ import { action, makeObservable, override } from 'mobx';
20
20
  import { observer } from 'mobx-react-lite';
21
21
  import React, { useEffect } from 'react';
22
22
  import { WindowStore } from "../Window";
@@ -24,15 +24,17 @@ import { default as Window } from "../Window/Window";
24
24
  export var ViewPortWindowStore = /*#__PURE__*/function (_WindowStore) {
25
25
  _inherits(ViewPortWindowStore, _WindowStore);
26
26
  var _super = _createSuper(ViewPortWindowStore);
27
- function ViewPortWindowStore(id, onClosedHandler) {
27
+ function ViewPortWindowStore(id, viewPort, onClosedHandler) {
28
28
  var _this;
29
29
  _classCallCheck(this, ViewPortWindowStore);
30
30
  _this = _super.call(this, id, onClosedHandler);
31
- _defineProperty(_assertThisInitialized(_this), "scale", 1);
31
+ _defineProperty(_assertThisInitialized(_this), "viewPortStore", void 0);
32
+ _this.viewPortStore = viewPort;
32
33
  makeObservable(_assertThisInitialized(_this), {
33
34
  style: override,
34
- scale: observable,
35
- controll: override
35
+ controll: override,
36
+ focus: override,
37
+ centerDisplay: action
36
38
  });
37
39
  return _this;
38
40
  }
@@ -47,6 +49,7 @@ export var ViewPortWindowStore = /*#__PURE__*/function (_WindowStore) {
47
49
  height: this.height + 'px',
48
50
  zIndex: this.zIndex,
49
51
  transform: 'scale(0)',
52
+ transformOrigin: 'center center',
50
53
  transition: 'all 0.5s ease-out'
51
54
  };
52
55
  }
@@ -54,21 +57,22 @@ export var ViewPortWindowStore = /*#__PURE__*/function (_WindowStore) {
54
57
  return {
55
58
  left: this.minimizePos.left + 'px',
56
59
  top: this.minimizePos.top + 'px',
57
- width: 0,
58
- height: 0,
60
+ width: this.width + 'px',
61
+ height: this.height + 'px',
59
62
  zIndex: this.zIndex,
60
63
  transform: 'scale(0)',
61
- transition: 'all 0.5s ease-out'
64
+ transformOrigin: 'left top',
65
+ transition: "all ".concat(0.5 + this.viewPortStore.scale, "s ease-out")
62
66
  };
63
67
  }
64
68
  if (this.fullscreen) {
65
69
  return {
66
- left: this.fullscreenPos.left / this.scale + 'px',
67
- top: this.fullscreenPos.top / this.scale + 'px',
68
- width: this.fullscreenPos.width + 'px',
69
- height: this.fullscreenPos.height + 'px',
70
+ left: this.fullscreenPos.left + 'px',
71
+ top: this.fullscreenPos.top + 'px',
72
+ width: this.fullscreenPos.width * this.viewPortStore.scale + 'px',
73
+ height: this.fullscreenPos.height * this.viewPortStore.scale + 'px',
70
74
  zIndex: this.zIndex,
71
- transform: "scale(".concat(1 / this.scale, ") "),
75
+ transform: "scale(".concat(1 / this.viewPortStore.scale, ")"),
72
76
  transformOrigin: 'left top',
73
77
  transition: 'width height 0.5s ease-out'
74
78
  };
@@ -94,13 +98,18 @@ export var ViewPortWindowStore = /*#__PURE__*/function (_WindowStore) {
94
98
  transition: 'all 0.5s ease-out'
95
99
  };
96
100
  }
101
+ }, {
102
+ key: "focus",
103
+ value: function focus() {
104
+ this.zIndex = ++this.viewPortStore.maxZIndex;
105
+ }
97
106
  }, {
98
107
  key: "calculateTransform",
99
108
  value: function calculateTransform(transform) {
100
109
  var _this$transform, _this$transform2;
101
110
  return {
102
- x: (transform.x - (((_this$transform = this.transform) === null || _this$transform === void 0 ? void 0 : _this$transform.x) || 0)) / this.scale,
103
- y: (transform.y - (((_this$transform2 = this.transform) === null || _this$transform2 === void 0 ? void 0 : _this$transform2.y) || 0)) / this.scale
111
+ x: (transform.x - (((_this$transform = this.transform) === null || _this$transform === void 0 ? void 0 : _this$transform.x) || 0)) / this.viewPortStore.scale,
112
+ y: (transform.y - (((_this$transform2 = this.transform) === null || _this$transform2 === void 0 ? void 0 : _this$transform2.y) || 0)) / this.viewPortStore.scale
104
113
  };
105
114
  }
106
115
  }, {
@@ -134,32 +143,32 @@ export var ViewPortWindowStore = /*#__PURE__*/function (_WindowStore) {
134
143
  }
135
144
  this.transform = transform;
136
145
  }
146
+ }, {
147
+ key: "centerDisplay",
148
+ value: function centerDisplay() {
149
+ this.focus();
150
+ var rect = this.viewPortStore.viewPortRect;
151
+ this.left = rect.left + Math.max(0, rect.width - this.width) / 2;
152
+ this.top = rect.top + Math.max(0, rect.height - this.height) / 2;
153
+ }
154
+ }, {
155
+ key: "fullscreenWindow",
156
+ value: function fullscreenWindow(func) {
157
+ this.resetState();
158
+ this.fullscreen = true;
159
+ func === null || func === void 0 || func();
160
+ this.fullscreenPos = this.viewPortStore.viewPortRect;
161
+ }
137
162
  }]);
138
163
  return ViewPortWindowStore;
139
164
  }(WindowStore);
140
165
  export var ViewPortWindow = observer(function ViewPortWindow(props) {
141
- var viewPortStore = props.viewPortStore,
142
- window = props.window,
166
+ var window = props.window,
143
167
  rest = _objectWithoutProperties(props, _excluded);
144
168
  useEffect(function () {
145
- runInAction(function () {
146
- window.fullscreenPos.left = -viewPortStore.transform.left + viewPortStore.offsetLeft;
147
- window.fullscreenPos.top = -viewPortStore.transform.top + viewPortStore.offsetTop;
148
- window.fullscreenPos.width = viewPortStore.width;
149
- window.fullscreenPos.height = viewPortStore.height;
150
- window.scale = viewPortStore.scale;
151
- });
152
- }, [viewPortStore.transform.left, viewPortStore.transform.top, viewPortStore.scale, viewPortStore.ratio, viewPortStore.width, viewPortStore.height]);
153
- useEffect(function () {
154
- window.left = (viewPortStore.width * viewPortStore.ratio - viewPortStore.width) / 2;
155
- window.top = (viewPortStore.width * viewPortStore.ratio - viewPortStore.width) / 2;
169
+ window.centerDisplay();
156
170
  }, []);
157
171
  return /*#__PURE__*/React.createElement(Window, _extends({
158
172
  window: window
159
- }, rest, {
160
- onFocusHandler: function onFocusHandler() {
161
- viewPortStore.maxZIndex++;
162
- window.zIndex = viewPortStore.maxZIndex;
163
- }
164
- }));
173
+ }, rest));
165
174
  });
@@ -6,20 +6,26 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
6
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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 { makeAutoObservable, runInAction } from 'mobx';
9
- import { observer, useLocalObservable } from 'mobx-react-lite';
9
+ import { observer } from 'mobx-react-lite';
10
10
  import React, { useEffect } from 'react';
11
11
  import styled from 'styled-components';
12
- import { GlobalStyles } from '..';
12
+ import { Button, GlobalStyles } from '..';
13
13
  import ViewPort from "./ViewPort";
14
14
  import { ViewPortStore } from "./ViewPortStore";
15
15
  import { ViewPortWindowStore } from "./ViewPortWindow";
16
+ var viewPortStore = new ViewPortStore(600, 600, 5);
16
17
  var WindowManager = /*#__PURE__*/function () {
17
18
  function WindowManager() {
18
19
  _classCallCheck(this, WindowManager);
19
- _defineProperty(this, "windows", [new ViewPortWindowStore('jss', this.closeWindowHanlder.bind(this)), new ViewPortWindowStore('jss12', this.closeWindowHanlder.bind(this))]);
20
+ _defineProperty(this, "windows", [new ViewPortWindowStore('jss', viewPortStore, this.closeWindowHanlder.bind(this)), new ViewPortWindowStore('jss12', viewPortStore, this.closeWindowHanlder.bind(this))]);
20
21
  makeAutoObservable(this);
21
22
  }
22
23
  _createClass(WindowManager, [{
24
+ key: "createWindow",
25
+ value: function createWindow() {
26
+ this.windows.push(new ViewPortWindowStore('jss' + Math.random(), viewPortStore, this.closeWindowHanlder.bind(this)));
27
+ }
28
+ }, {
23
29
  key: "closeWindowHanlder",
24
30
  value: function closeWindowHanlder(id) {
25
31
  this.windows = this.windows.filter(function (window) {
@@ -42,14 +48,11 @@ var StyledViewPort = styled(ViewPort).withConfig({
42
48
  componentId: "basic-component-347b__sc-1b1xrkc-0"
43
49
  })(["border:1px solid #eee;"]);
44
50
  export default observer(function Test() {
45
- var viewPortStore = useLocalObservable(function () {
46
- return new ViewPortStore(600, 600, 2);
47
- });
48
51
  useEffect(function () {
49
52
  function setWidthHeight() {
50
53
  runInAction(function () {
51
- viewPortStore.width = 600;
52
- viewPortStore.height = 600;
54
+ viewPortStore.width = 800;
55
+ viewPortStore.height = 800;
53
56
  });
54
57
  }
55
58
  window.addEventListener('resize', setWidthHeight);
@@ -60,14 +63,17 @@ export default observer(function Test() {
60
63
  }, []);
61
64
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(GlobalStyles, {
62
65
  $css: []
63
- }), /*#__PURE__*/React.createElement(StyledViewPort, {
66
+ }), /*#__PURE__*/React.createElement(Button, {
67
+ onClick: function onClick() {
68
+ windowManager.createWindow();
69
+ }
70
+ }, "\u65B0\u589E"), /*#__PURE__*/React.createElement(StyledViewPort, {
64
71
  viewPortStore: viewPortStore
65
72
  }, windowManager.windows.map(function (windowStore) {
66
73
  return /*#__PURE__*/React.createElement(ViewPort.Window, {
67
74
  window: windowStore,
68
75
  key: windowStore.id,
69
- title: 'xixi',
70
- viewPortStore: viewPortStore
76
+ title: 'xixi'
71
77
  }, /*#__PURE__*/React.createElement("br", null));
72
78
  })));
73
79
  });
@@ -102,6 +102,7 @@ var Window = observer(function (props) {
102
102
  },
103
103
  onPointerDown: function onPointerDown(e) {
104
104
  e.stopPropagation();
105
+ window.focus();
105
106
  onFocusHandler === null || onFocusHandler === void 0 || onFocusHandler();
106
107
  },
107
108
  ref: windowContainerRef
@@ -40,6 +40,7 @@ export default class WindowStore {
40
40
  minimizeWindow(): void;
41
41
  normalizeWindow(): void;
42
42
  closeWindow(): void;
43
+ focus(): void;
43
44
  get style(): {
44
45
  left: string;
45
46
  top: string;
@@ -47,15 +48,17 @@ export default class WindowStore {
47
48
  height: string;
48
49
  zIndex: number;
49
50
  transform: string;
51
+ transformOrigin: string;
50
52
  transition: string;
51
53
  } | {
52
54
  left: string;
53
55
  top: string;
54
- width: number;
55
- height: number;
56
+ width: string;
57
+ height: string;
56
58
  zIndex: number;
57
59
  transform: string;
58
60
  transition: string;
61
+ transformOrigin?: undefined;
59
62
  };
60
63
  get info(): string;
61
64
  }
@@ -55,6 +55,7 @@ var WindowStore = /*#__PURE__*/function () {
55
55
  normalizeWindow: action,
56
56
  closeWindow: action,
57
57
  resetState: action,
58
+ focus: action,
58
59
  info: computed
59
60
  });
60
61
  this.id = id;
@@ -145,6 +146,11 @@ var WindowStore = /*#__PURE__*/function () {
145
146
  this.isClosed = true;
146
147
  this.resetState();
147
148
  }
149
+ }, {
150
+ key: "focus",
151
+ value: function focus() {
152
+ this.zIndex++;
153
+ }
148
154
  }, {
149
155
  key: "style",
150
156
  get: function get() {
@@ -156,18 +162,20 @@ var WindowStore = /*#__PURE__*/function () {
156
162
  height: this.height + 'px',
157
163
  zIndex: this.zIndex,
158
164
  transform: 'scale(0)',
159
- transition: 'all 0.5s ease-out'
165
+ transformOrigin: 'center center',
166
+ transition: 'all 1s ease-in-out'
160
167
  };
161
168
  }
162
169
  if (this.isMinimize && this.minimizePos) {
163
170
  return {
164
171
  left: this.minimizePos.left + 'px',
165
172
  top: this.minimizePos.top + 'px',
166
- width: 0,
167
- height: 0,
173
+ width: this.width + 'px',
174
+ height: this.width + 'px',
168
175
  zIndex: this.zIndex,
169
176
  transform: 'scale(0)',
170
- transition: 'all 0.5s ease-out'
177
+ transformOrigin: 'left top',
178
+ transition: 'all 1s ease-in-out'
171
179
  };
172
180
  }
173
181
  if (this.fullscreen) {
@@ -178,7 +186,7 @@ var WindowStore = /*#__PURE__*/function () {
178
186
  height: this.fullscreenPos.height + 'px',
179
187
  zIndex: this.zIndex,
180
188
  transform: 'none',
181
- transition: 'all 0.5s ease-out'
189
+ transition: 'all 1s ease-in-out'
182
190
  };
183
191
  }
184
192
  if (this.isMoving || this.isResizing) {
@@ -199,7 +207,7 @@ var WindowStore = /*#__PURE__*/function () {
199
207
  height: this.height + 'px',
200
208
  zIndex: this.zIndex,
201
209
  transform: 'none',
202
- transition: 'all 0.5s ease-out'
210
+ transition: 'all 1s ease-in-out'
203
211
  };
204
212
  }
205
213
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kep-platform/basic-component",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
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.42",
50
+ "@kep-platform/hooks": "^0.0.44",
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": "345a676c9d5748fb2a93d5423e7517cbda956876"
90
+ "gitHead": "d7ee92047ae7296763e391b3f01553d4105500bb"
91
91
  }