@kep-platform/basic-component 0.0.40 → 0.0.41

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.
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ type RippleType = {
3
+ id: number;
4
+ left: number;
5
+ top: number;
6
+ };
7
+ export declare const Ripple: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
8
+ export declare class RippleManagerStore {
9
+ list: RippleType[];
10
+ constructor();
11
+ clearList(): void;
12
+ addRipple(left: number, top: number): void;
13
+ get rippleInfo(): React.JSX.Element[];
14
+ }
15
+ export {};
@@ -0,0 +1,56 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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; }
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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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
+ import { makeAutoObservable } from 'mobx';
9
+ import React from 'react';
10
+ import styled, { keyframes } from 'styled-components';
11
+ var rippleAnimation = keyframes(["from{transform:scale(1);}to{transform:scale(4);opacity:0;}"]);
12
+ export var Ripple = styled.div.withConfig({
13
+ displayName: "Ripple",
14
+ componentId: "basic-component-347b__sc-zqrqyo-0"
15
+ })(["position:absolute;border-radius:50%;width:10px;height:10px;background-color:#fff0;& > div{position:absolute;left:0;top:0;width:10px;height:10px;background-color:#fff;border-radius:50%;margin-left:-5px;margin-top:-5px;transform:scale(0);animation:", " 500ms linear;}& .first{}& .second{animation-delay:150ms;}"], rippleAnimation);
16
+ export var RippleManagerStore = /*#__PURE__*/function () {
17
+ function RippleManagerStore() {
18
+ _classCallCheck(this, RippleManagerStore);
19
+ _defineProperty(this, "list", []);
20
+ makeAutoObservable(this);
21
+ }
22
+ _createClass(RippleManagerStore, [{
23
+ key: "clearList",
24
+ value: function clearList() {
25
+ this.list = [];
26
+ }
27
+ }, {
28
+ key: "addRipple",
29
+ value: function addRipple(left, top) {
30
+ this.list.push({
31
+ id: new Date().getTime(),
32
+ left: left,
33
+ top: top
34
+ });
35
+ }
36
+ }, {
37
+ key: "rippleInfo",
38
+ get: function get() {
39
+ return this.list.map(function (ripple) {
40
+ return /*#__PURE__*/React.createElement(Ripple, {
41
+ key: ripple.id,
42
+ style: {
43
+ left: ripple.left,
44
+ top: ripple.top,
45
+ zIndex: 10
46
+ }
47
+ }, /*#__PURE__*/React.createElement("div", {
48
+ className: "first"
49
+ }), /*#__PURE__*/React.createElement("div", {
50
+ className: "second"
51
+ }));
52
+ });
53
+ }
54
+ }]);
55
+ return RippleManagerStore;
56
+ }();
@@ -1,8 +1,4 @@
1
- import { Transform } from '@dnd-kit/utilities';
2
1
  import React, { HtmlHTMLAttributes, ReactNode } from 'react';
3
- import { WindowStore } from '../Window';
4
- import { WindowProps } from '../Window/Window';
5
- import { WindowControllerType } from '../Window/WindowController';
6
2
  import { ViewPortStore } from './ViewPortStore';
7
3
  type ViewPortProps = {
8
4
  children?: ReactNode;
@@ -12,46 +8,9 @@ type ViewPortProps = {
12
8
  } & HtmlHTMLAttributes<HTMLDivElement>;
13
9
  declare function ViewPort(props: ViewPortProps): React.JSX.Element;
14
10
  declare namespace ViewPort {
15
- var Window: React.FunctionComponent<WindowProps & {
11
+ var Window: React.FunctionComponent<import("../Window/Window").WindowProps & {
16
12
  viewPortStore: ViewPortStore;
17
- window: ViewPortWindowStore;
13
+ window: import("./ViewPortWindow").ViewPortWindowStore;
18
14
  }>;
19
15
  }
20
16
  export default ViewPort;
21
- export declare class ViewPortWindowStore extends WindowStore {
22
- scale: number;
23
- get style(): {
24
- left: string;
25
- top: string;
26
- width: string;
27
- height: string;
28
- zIndex: number;
29
- transform: string;
30
- transition: string;
31
- transformOrigin?: undefined;
32
- } | {
33
- left: string;
34
- top: string;
35
- width: number;
36
- height: number;
37
- zIndex: number;
38
- transform: string;
39
- transition: string;
40
- transformOrigin?: undefined;
41
- } | {
42
- left: string;
43
- top: string;
44
- width: string;
45
- height: string;
46
- zIndex: number;
47
- transform: string;
48
- transformOrigin: string;
49
- transition: string;
50
- };
51
- calculateTransform(transform: Transform): {
52
- x: number;
53
- y: number;
54
- };
55
- controll(transform: Transform, type: WindowControllerType): void;
56
- constructor(id: string, onClosedHandler?: (id: string) => void);
57
- }
@@ -1,29 +1,14 @@
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
- var _excluded = ["children", "viewPortStore"],
3
- _excluded2 = ["viewPortStore", "window"];
4
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
- 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); } }
6
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
- 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); }
8
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
- 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); }; }
10
- 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); }
11
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
- 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; } }
13
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
- 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; }
15
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
16
- 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); }
1
+ var _excluded = ["children", "viewPortStore", "onScroll", "onScale"],
2
+ _excluded2 = ["children", "viewPortStore"];
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); }
17
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; }
18
5
  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; }
19
- 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); }
20
6
  import { DndContext, useDraggable } from '@dnd-kit/core';
21
- import { makeObservable, observable, override, runInAction } from 'mobx';
22
7
  import { observer } from 'mobx-react-lite';
23
8
  import React, { useEffect, useRef } from 'react';
24
9
  import styled from 'styled-components';
25
- import { WindowStore } from "../Window";
26
- import { default as Window } from "../Window/Window";
10
+ import { RippleManagerStore } from "./Ripple";
11
+ import { ViewPortWindow } from "./ViewPortWindow";
27
12
  var Container = styled.div.withConfig({
28
13
  displayName: "Container",
29
14
  componentId: "basic-component-347b__sc-1qpmpop-0"
@@ -32,11 +17,13 @@ var Content = styled.div.withConfig({
32
17
  displayName: "Content",
33
18
  componentId: "basic-component-347b__sc-1qpmpop-1"
34
19
  })(["position:absolute;"]);
20
+ var rippleManagerStore = new RippleManagerStore();
35
21
  var ViewPortEntity = observer(function (props) {
36
22
  var children = props.children,
37
23
  viewPortStore = props.viewPortStore,
38
24
  onScroll = props.onScroll,
39
- onScale = props.onScale;
25
+ onScale = props.onScale,
26
+ rest = _objectWithoutProperties(props, _excluded);
40
27
  var _useDraggable = useDraggable({
41
28
  id: 'ViewPortEntity'
42
29
  }),
@@ -46,6 +33,17 @@ var ViewPortEntity = observer(function (props) {
46
33
  setActivatorNodeRef = _useDraggable.setActivatorNodeRef,
47
34
  transform = _useDraggable.transform;
48
35
  var _ref = useRef(null);
36
+ var createRipple = function createRipple(event) {
37
+ event.preventDefault();
38
+ event.stopPropagation();
39
+ var rect = event.currentTarget.getBoundingClientRect();
40
+ var left = event.clientX - rect.left;
41
+ var top = event.clientY - rect.top;
42
+ rippleManagerStore.addRipple(left, top);
43
+ setTimeout(function () {
44
+ rippleManagerStore.clearList();
45
+ }, 30000);
46
+ };
49
47
  useEffect(function () {
50
48
  if (transform) {
51
49
  viewPortStore.move(transform);
@@ -74,8 +72,9 @@ var ViewPortEntity = observer(function (props) {
74
72
  (_ref$current2 = _ref.current) === null || _ref$current2 === void 0 || _ref$current2.removeEventListener('wheel', scaleHandler);
75
73
  };
76
74
  }, []);
77
- return /*#__PURE__*/React.createElement(Container, {
75
+ return /*#__PURE__*/React.createElement(Container, _extends({
78
76
  style: viewPortStore.containerStyle,
77
+ onPointerDown: createRipple,
79
78
  onDoubleClick: function onDoubleClick(e) {
80
79
  var container = e.currentTarget;
81
80
  var _container$getBoundin = container.getBoundingClientRect(),
@@ -83,11 +82,11 @@ var ViewPortEntity = observer(function (props) {
83
82
  top = _container$getBoundin.top;
84
83
  var offsetLeft = e.clientX - left;
85
84
  var offsetTop = e.clientY - top;
86
- if (viewPortStore.formatedScale > 0.5) {
87
- viewPortStore.setScale(1 / viewPortStore.ratio);
85
+ if (viewPortStore.scale === 1) {
86
+ viewPortStore.unfocus();
88
87
  } else viewPortStore.focus(offsetLeft, offsetTop);
89
88
  }
90
- }, /*#__PURE__*/React.createElement(Content, _extends({
89
+ }, rest), rippleManagerStore.rippleInfo, /*#__PURE__*/React.createElement(Content, _extends({
91
90
  ref: function ref(dom) {
92
91
  _ref.current = dom;
93
92
  setNodeRef(_ref.current);
@@ -100,147 +99,9 @@ var ViewPortEntity = observer(function (props) {
100
99
  export default function ViewPort(props) {
101
100
  var children = props.children,
102
101
  viewPortStore = props.viewPortStore,
103
- rest = _objectWithoutProperties(props, _excluded);
102
+ rest = _objectWithoutProperties(props, _excluded2);
104
103
  return /*#__PURE__*/React.createElement(DndContext, null, /*#__PURE__*/React.createElement(ViewPortEntity, _extends({
105
104
  viewPortStore: viewPortStore
106
105
  }, rest), children));
107
106
  }
108
- export var ViewPortWindowStore = /*#__PURE__*/function (_WindowStore) {
109
- _inherits(ViewPortWindowStore, _WindowStore);
110
- var _super = _createSuper(ViewPortWindowStore);
111
- function ViewPortWindowStore(id, onClosedHandler) {
112
- var _this;
113
- _classCallCheck(this, ViewPortWindowStore);
114
- _this = _super.call(this, id, onClosedHandler);
115
- _defineProperty(_assertThisInitialized(_this), "scale", 1);
116
- makeObservable(_assertThisInitialized(_this), {
117
- style: override,
118
- scale: observable,
119
- controll: override
120
- });
121
- return _this;
122
- }
123
- _createClass(ViewPortWindowStore, [{
124
- key: "style",
125
- get: function get() {
126
- if (this.isClosed) {
127
- return {
128
- left: this.left + 'px',
129
- top: this.top + 'px',
130
- width: this.width + 'px',
131
- height: this.height + 'px',
132
- zIndex: this.zIndex,
133
- transform: 'scale(0)',
134
- transition: 'all 0.5s ease-out'
135
- };
136
- }
137
- if (this.isMinimize && this.minimizePos) {
138
- return {
139
- left: this.minimizePos.left + 'px',
140
- top: this.minimizePos.top + 'px',
141
- width: 0,
142
- height: 0,
143
- zIndex: this.zIndex,
144
- transform: 'scale(0)',
145
- transition: 'all 0.5s ease-out'
146
- };
147
- }
148
- if (this.fullscreen) {
149
- return {
150
- left: this.fullscreenPos.left / this.scale + 'px',
151
- top: this.fullscreenPos.top / this.scale + 'px',
152
- width: this.fullscreenPos.width + 'px',
153
- height: this.fullscreenPos.height + 'px',
154
- zIndex: this.zIndex,
155
- transform: "scale(".concat(1 / this.scale, ") "),
156
- transformOrigin: 'left top',
157
- transition: 'width height 0.5s ease-out'
158
- };
159
- }
160
- if (this.isMoving || this.isResizing) {
161
- return {
162
- left: this.left + 'px',
163
- top: this.top + 'px',
164
- width: this.width + 'px',
165
- height: this.height + 'px',
166
- zIndex: this.zIndex,
167
- transform: 'none',
168
- transition: 'none'
169
- };
170
- }
171
- return {
172
- left: this.left + 'px',
173
- top: this.top + 'px',
174
- width: this.width + 'px',
175
- height: this.height + 'px',
176
- zIndex: this.zIndex,
177
- transform: 'none',
178
- transition: 'all 0.5s ease-out'
179
- };
180
- }
181
- }, {
182
- key: "calculateTransform",
183
- value: function calculateTransform(transform) {
184
- var _this$transform, _this$transform2;
185
- return {
186
- x: (transform.x - (((_this$transform = this.transform) === null || _this$transform === void 0 ? void 0 : _this$transform.x) || 0)) / this.scale,
187
- y: (transform.y - (((_this$transform2 = this.transform) === null || _this$transform2 === void 0 ? void 0 : _this$transform2.y) || 0)) / this.scale
188
- };
189
- }
190
- }, {
191
- key: "controll",
192
- value: function controll(transform, type) {
193
- var offsetTransform = this.calculateTransform(transform);
194
- if (type === 'move') {
195
- this.isMoving = true;
196
- this.isResizing = false;
197
- } else {
198
- this.isMoving = false;
199
- this.isResizing = true;
200
- }
201
- if (type.includes('left')) {
202
- this.left = Math.round(this.left + offsetTransform.x);
203
- this.width = Math.round(this.width - offsetTransform.x);
204
- }
205
- if (type.includes('right')) {
206
- this.width = Math.round(this.width + offsetTransform.x);
207
- }
208
- if (type.includes('top')) {
209
- this.top = Math.round(this.top + offsetTransform.y);
210
- this.height = Math.round(this.height - offsetTransform.y);
211
- }
212
- if (type.includes('bottom')) {
213
- this.height = Math.round(this.height + offsetTransform.y);
214
- }
215
- if (type.includes('move')) {
216
- this.left = Math.round(this.left + offsetTransform.x);
217
- this.top = Math.round(this.top + offsetTransform.y);
218
- }
219
- this.transform = transform;
220
- }
221
- }]);
222
- return ViewPortWindowStore;
223
- }(WindowStore);
224
- ViewPort.Window = observer(function ViewPortWindow(props) {
225
- var viewPortStore = props.viewPortStore,
226
- window = props.window,
227
- rest = _objectWithoutProperties(props, _excluded2);
228
- useEffect(function () {
229
- runInAction(function () {
230
- var transform = viewPortStore.formatedTransform(viewPortStore.transform.left, viewPortStore.transform.top);
231
- window.fullscreenPos.left = -transform.left;
232
- window.fullscreenPos.top = -transform.top;
233
- window.fullscreenPos.width = viewPortStore.width;
234
- window.fullscreenPos.height = viewPortStore.height;
235
- window.scale = viewPortStore.formatedScale;
236
- });
237
- }, [viewPortStore.transform.left, viewPortStore.transform.top, viewPortStore.scale, viewPortStore.ratio, viewPortStore.width, viewPortStore.height]);
238
- return /*#__PURE__*/React.createElement(Window, _extends({
239
- window: window
240
- }, rest, {
241
- onFocusHandler: function onFocusHandler() {
242
- viewPortStore.maxZIndex++;
243
- window.zIndex = viewPortStore.maxZIndex;
244
- }
245
- }));
246
- });
107
+ ViewPort.Window = ViewPortWindow;
@@ -1,4 +1,5 @@
1
1
  import { Transform } from '@dnd-kit/utilities';
2
+ import { CSSProperties } from 'react';
2
3
  export declare class ViewPortStore {
3
4
  transform: {
4
5
  left: number;
@@ -15,38 +16,20 @@ export declare class ViewPortStore {
15
16
  isMoving: boolean;
16
17
  maxZIndex: number;
17
18
  constructor(width?: number, height?: number, ratio?: number);
19
+ get scaleStep(): number;
18
20
  increaseScale(): void;
19
- setScale(scale: number): void;
20
- focus(left: number, top: number): void;
21
21
  decreaseScale(): void;
22
+ private validScale;
23
+ private setScale;
24
+ private setTransform;
25
+ get offsetLeft(): number;
26
+ get offsetTop(): number;
27
+ private formatedTransform;
28
+ focus(left: number, top: number): void;
29
+ unfocus(): void;
22
30
  move(transform: Transform): void;
23
31
  endMove(): void;
24
- get transformLimit(): {
25
- left: {
26
- max: number;
27
- min: number;
28
- };
29
- top: {
30
- max: number;
31
- min: number;
32
- };
33
- };
34
- formatedTransform(left: number, top: number): {
35
- left: number;
36
- top: number;
37
- };
38
- get formatedScale(): number;
39
- get contentStyle(): {
40
- transform: string;
41
- width: string;
42
- height: string;
43
- transformOrigin: string;
44
- transition: string;
45
- };
46
- get containerStyle(): {
47
- width: string;
48
- height: string;
49
- overflow: string;
50
- };
32
+ get contentStyle(): CSSProperties;
33
+ get containerStyle(): CSSProperties;
51
34
  get info(): string;
52
35
  }
@@ -30,34 +30,87 @@ export var ViewPortStore = /*#__PURE__*/function () {
30
30
  makeAutoObservable(this);
31
31
  }
32
32
  _createClass(ViewPortStore, [{
33
+ key: "scaleStep",
34
+ get: function get() {
35
+ return 1 / this.ratio * 0.125;
36
+ }
37
+ }, {
33
38
  key: "increaseScale",
34
39
  value: function increaseScale() {
35
- if (this.scale < 1) this.scale += 0.03125;else this.scale = 1;
40
+ this.setScale(this.scale + this.scaleStep);
41
+ this.setTransform(this.transform.left, this.transform.top);
42
+ }
43
+ }, {
44
+ key: "decreaseScale",
45
+ value: function decreaseScale() {
46
+ this.setScale(this.scale - this.scaleStep);
47
+ this.setTransform(this.transform.left, this.transform.top);
48
+ }
49
+ }, {
50
+ key: "validScale",
51
+ value: function validScale(scale) {
52
+ return Math.min(1, Math.max(1 / this.ratio, scale));
36
53
  }
37
54
  }, {
38
55
  key: "setScale",
39
56
  value: function setScale(scale) {
40
- this.scale = scale;
57
+ this.scale = this.validScale(scale);
58
+ }
59
+ }, {
60
+ key: "setTransform",
61
+ value: function setTransform(left, top) {
62
+ this.transform = this.formatedTransform(left, top);
63
+ }
64
+
65
+ /* 这个函数是获取left偏移量 */
66
+ }, {
67
+ key: "offsetLeft",
68
+ get: function get() {
69
+ return (this.width * this.ratio * this.scale - this.width) / 2;
70
+ }
71
+ /* 获取top偏移量 */
72
+ }, {
73
+ key: "offsetTop",
74
+ get: function get() {
75
+ return (this.height * this.ratio * this.scale - this.height) / 2;
76
+ }
77
+ }, {
78
+ key: "formatedTransform",
79
+ value: function formatedTransform(left, top) {
80
+ var areaLimit = {
81
+ left: {
82
+ min: -this.offsetLeft,
83
+ max: this.offsetLeft
84
+ },
85
+ top: {
86
+ min: -this.offsetTop,
87
+ max: this.offsetTop
88
+ }
89
+ };
90
+ return {
91
+ left: Math.max(areaLimit.left.min, Math.min(left, areaLimit.left.max)),
92
+ top: Math.max(areaLimit.top.min, Math.min(top, areaLimit.top.max))
93
+ };
41
94
  }
42
95
  }, {
43
96
  key: "focus",
44
97
  value: function focus(left, top) {
45
- this.scale = 0.8;
46
- this.transform = {
47
- left: (1 - this.ratio) * left,
48
- top: (1 - this.ratio) * top
49
- };
98
+ this.setScale(1);
99
+ this.setTransform((1 - this.ratio) * left + this.offsetLeft, (1 - this.ratio) * top + this.offsetTop);
50
100
  }
51
101
  }, {
52
- key: "decreaseScale",
53
- value: function decreaseScale() {
54
- if (this.scale > parseFloat((1 / this.ratio).toFixed(1))) this.scale -= 0.03125;
102
+ key: "unfocus",
103
+ value: function unfocus() {
104
+ this.setScale(1 / this.ratio);
105
+ this.setTransform(0, 0);
55
106
  }
56
107
  }, {
57
108
  key: "move",
58
109
  value: function move(transform) {
59
110
  this.isMoving = true;
60
- this.transform = this.formatedTransform(transform.x - this.offset.x + this.transform.left, transform.y - this.offset.y + this.transform.top);
111
+ var calculateLeft = transform.x - this.offset.x + this.transform.left;
112
+ var calculateTop = transform.y - this.offset.y + this.transform.top;
113
+ this.setTransform(calculateLeft, calculateTop);
61
114
  this.offset.x = transform.x;
62
115
  this.offset.y = transform.y;
63
116
  }
@@ -68,43 +121,19 @@ export var ViewPortStore = /*#__PURE__*/function () {
68
121
  this.offset.y = 0;
69
122
  this.isMoving = false;
70
123
  }
71
- }, {
72
- key: "transformLimit",
73
- get: function get() {
74
- return {
75
- left: {
76
- max: 0,
77
- min: this.width - this.width * this.ratio * this.formatedScale
78
- },
79
- top: {
80
- max: 0,
81
- min: this.height - this.height * this.ratio * this.formatedScale
82
- }
83
- };
84
- }
85
- }, {
86
- key: "formatedTransform",
87
- value: function formatedTransform(left, top) {
88
- return {
89
- left: Math.max(this.transformLimit.left.min, Math.min(left, this.transformLimit.left.max)),
90
- top: Math.max(this.transformLimit.top.min, Math.min(top, this.transformLimit.top.max))
91
- };
92
- }
93
- }, {
94
- key: "formatedScale",
95
- get: function get() {
96
- return Math.min(1, Math.max(1 / this.ratio, this.scale));
97
- }
98
124
  }, {
99
125
  key: "contentStyle",
100
126
  get: function get() {
101
- var transform = this.formatedTransform(this.transform.left, this.transform.top);
102
127
  return {
103
- transform: "translate(".concat(transform.left, "px,").concat(transform.top, "px) scale(").concat(this.formatedScale, ")"),
128
+ left: -this.offsetLeft,
129
+ top: -this.offsetTop,
130
+ transform: " translate(".concat(this.transform.left, "px,").concat(this.transform.top, "px) scale(").concat(this.scale, ")"),
104
131
  width: this.width * this.ratio + 'px',
105
132
  height: this.height * this.ratio + 'px',
106
133
  transformOrigin: 'left top',
107
- transition: this.isMoving ? 'none' : 'all 0.5s'
134
+ transition: this.isMoving ? 'none' : 'all 0.5s',
135
+ background: '#188fff67',
136
+ cursor: this.isMoving ? 'grab' : 'default'
108
137
  };
109
138
  }
110
139
  }, {
@@ -0,0 +1,47 @@
1
+ import { Transform } from '@dnd-kit/utilities';
2
+ import React from 'react';
3
+ import { WindowStore } from '../Window';
4
+ import { WindowProps } from '../Window/Window';
5
+ import { WindowControllerType } from '../Window/WindowController';
6
+ import { ViewPortStore } from './ViewPortStore';
7
+ export declare class ViewPortWindowStore extends WindowStore {
8
+ scale: number;
9
+ get style(): {
10
+ left: string;
11
+ top: string;
12
+ width: string;
13
+ height: string;
14
+ zIndex: number;
15
+ transform: string;
16
+ 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
+ } | {
28
+ left: string;
29
+ top: string;
30
+ width: string;
31
+ height: string;
32
+ zIndex: number;
33
+ transform: string;
34
+ transformOrigin: string;
35
+ transition: string;
36
+ };
37
+ calculateTransform(transform: Transform): {
38
+ x: number;
39
+ y: number;
40
+ };
41
+ controll(transform: Transform, type: WindowControllerType): void;
42
+ constructor(id: string, onClosedHandler?: (id: string) => void);
43
+ }
44
+ export declare const ViewPortWindow: React.FunctionComponent<WindowProps & {
45
+ viewPortStore: ViewPortStore;
46
+ window: ViewPortWindowStore;
47
+ }>;
@@ -0,0 +1,165 @@
1
+ var _excluded = ["viewPortStore", "window"];
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
+ 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
+ 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; }
5
+ 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; }
6
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7
+ 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); } }
8
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
+ 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); }
10
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
+ 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); }; }
12
+ 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); }
13
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
+ 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; } }
15
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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';
20
+ import { observer } from 'mobx-react-lite';
21
+ import React, { useEffect } from 'react';
22
+ import { WindowStore } from "../Window";
23
+ import { default as Window } from "../Window/Window";
24
+ export var ViewPortWindowStore = /*#__PURE__*/function (_WindowStore) {
25
+ _inherits(ViewPortWindowStore, _WindowStore);
26
+ var _super = _createSuper(ViewPortWindowStore);
27
+ function ViewPortWindowStore(id, onClosedHandler) {
28
+ var _this;
29
+ _classCallCheck(this, ViewPortWindowStore);
30
+ _this = _super.call(this, id, onClosedHandler);
31
+ _defineProperty(_assertThisInitialized(_this), "scale", 1);
32
+ makeObservable(_assertThisInitialized(_this), {
33
+ style: override,
34
+ scale: observable,
35
+ controll: override
36
+ });
37
+ return _this;
38
+ }
39
+ _createClass(ViewPortWindowStore, [{
40
+ key: "style",
41
+ get: function get() {
42
+ if (this.isClosed) {
43
+ return {
44
+ left: this.left + 'px',
45
+ top: this.top + 'px',
46
+ width: this.width + 'px',
47
+ height: this.height + 'px',
48
+ zIndex: this.zIndex,
49
+ transform: 'scale(0)',
50
+ transition: 'all 0.5s ease-out'
51
+ };
52
+ }
53
+ if (this.isMinimize && this.minimizePos) {
54
+ return {
55
+ left: this.minimizePos.left + 'px',
56
+ top: this.minimizePos.top + 'px',
57
+ width: 0,
58
+ height: 0,
59
+ zIndex: this.zIndex,
60
+ transform: 'scale(0)',
61
+ transition: 'all 0.5s ease-out'
62
+ };
63
+ }
64
+ if (this.fullscreen) {
65
+ 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
+ zIndex: this.zIndex,
71
+ transform: "scale(".concat(1 / this.scale, ") "),
72
+ transformOrigin: 'left top',
73
+ transition: 'width height 0.5s ease-out'
74
+ };
75
+ }
76
+ if (this.isMoving || this.isResizing) {
77
+ return {
78
+ left: this.left + 'px',
79
+ top: this.top + 'px',
80
+ width: this.width + 'px',
81
+ height: this.height + 'px',
82
+ zIndex: this.zIndex,
83
+ transform: 'none',
84
+ transition: 'none'
85
+ };
86
+ }
87
+ return {
88
+ left: this.left + 'px',
89
+ top: this.top + 'px',
90
+ width: this.width + 'px',
91
+ height: this.height + 'px',
92
+ zIndex: this.zIndex,
93
+ transform: 'none',
94
+ transition: 'all 0.5s ease-out'
95
+ };
96
+ }
97
+ }, {
98
+ key: "calculateTransform",
99
+ value: function calculateTransform(transform) {
100
+ var _this$transform, _this$transform2;
101
+ 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
104
+ };
105
+ }
106
+ }, {
107
+ key: "controll",
108
+ value: function controll(transform, type) {
109
+ var offsetTransform = this.calculateTransform(transform);
110
+ if (type === 'move') {
111
+ this.isMoving = true;
112
+ this.isResizing = false;
113
+ } else {
114
+ this.isMoving = false;
115
+ this.isResizing = true;
116
+ }
117
+ if (type.includes('left')) {
118
+ this.left = Math.round(this.left + offsetTransform.x);
119
+ this.width = Math.round(this.width - offsetTransform.x);
120
+ }
121
+ if (type.includes('right')) {
122
+ this.width = Math.round(this.width + offsetTransform.x);
123
+ }
124
+ if (type.includes('top')) {
125
+ this.top = Math.round(this.top + offsetTransform.y);
126
+ this.height = Math.round(this.height - offsetTransform.y);
127
+ }
128
+ if (type.includes('bottom')) {
129
+ this.height = Math.round(this.height + offsetTransform.y);
130
+ }
131
+ if (type.includes('move')) {
132
+ this.left = Math.round(this.left + offsetTransform.x);
133
+ this.top = Math.round(this.top + offsetTransform.y);
134
+ }
135
+ this.transform = transform;
136
+ }
137
+ }]);
138
+ return ViewPortWindowStore;
139
+ }(WindowStore);
140
+ export var ViewPortWindow = observer(function ViewPortWindow(props) {
141
+ var viewPortStore = props.viewPortStore,
142
+ window = props.window,
143
+ rest = _objectWithoutProperties(props, _excluded);
144
+ 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;
156
+ }, []);
157
+ return /*#__PURE__*/React.createElement(Window, _extends({
158
+ window: window
159
+ }, rest, {
160
+ onFocusHandler: function onFocusHandler() {
161
+ viewPortStore.maxZIndex++;
162
+ window.zIndex = viewPortStore.maxZIndex;
163
+ }
164
+ }));
165
+ });
@@ -8,8 +8,11 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  import { makeAutoObservable, runInAction } from 'mobx';
9
9
  import { observer, useLocalObservable } from 'mobx-react-lite';
10
10
  import React, { useEffect } from 'react';
11
- import ViewPort, { ViewPortWindowStore } from "./ViewPort";
11
+ import styled from 'styled-components';
12
+ import { GlobalStyles } from '..';
13
+ import ViewPort from "./ViewPort";
12
14
  import { ViewPortStore } from "./ViewPortStore";
15
+ import { ViewPortWindowStore } from "./ViewPortWindow";
13
16
  var WindowManager = /*#__PURE__*/function () {
14
17
  function WindowManager() {
15
18
  _classCallCheck(this, WindowManager);
@@ -34,15 +37,19 @@ var WindowManager = /*#__PURE__*/function () {
34
37
  return WindowManager;
35
38
  }();
36
39
  var windowManager = new WindowManager();
40
+ var StyledViewPort = styled(ViewPort).withConfig({
41
+ displayName: "StyledViewPort",
42
+ componentId: "basic-component-347b__sc-1b1xrkc-0"
43
+ })(["border:1px solid #eee;"]);
37
44
  export default observer(function Test() {
38
45
  var viewPortStore = useLocalObservable(function () {
39
- return new ViewPortStore(600, 600, 5);
46
+ return new ViewPortStore(600, 600, 2);
40
47
  });
41
48
  useEffect(function () {
42
49
  function setWidthHeight() {
43
50
  runInAction(function () {
44
- viewPortStore.width = 800;
45
- viewPortStore.height = 800;
51
+ viewPortStore.width = 600;
52
+ viewPortStore.height = 600;
46
53
  });
47
54
  }
48
55
  window.addEventListener('resize', setWidthHeight);
@@ -51,7 +58,9 @@ export default observer(function Test() {
51
58
  window.removeEventListener('resize', setWidthHeight);
52
59
  };
53
60
  }, []);
54
- return /*#__PURE__*/React.createElement(ViewPort, {
61
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(GlobalStyles, {
62
+ $css: []
63
+ }), /*#__PURE__*/React.createElement(StyledViewPort, {
55
64
  viewPortStore: viewPortStore
56
65
  }, windowManager.windows.map(function (windowStore) {
57
66
  return /*#__PURE__*/React.createElement(ViewPort.Window, {
@@ -60,5 +69,5 @@ export default observer(function Test() {
60
69
  title: 'xixi',
61
70
  viewPortStore: viewPortStore
62
71
  }, /*#__PURE__*/React.createElement("br", null));
63
- }));
72
+ })));
64
73
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kep-platform/basic-component",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
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.40",
50
+ "@kep-platform/hooks": "^0.0.41",
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": "6bffe69d00a564159af57dba5e0922073da85a3c"
90
+ "gitHead": "05f330f339c2445ce3234da33d78d1e6f64891c6"
91
91
  }