@kep-platform/basic-component 0.0.34 → 0.0.35

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+ import { Transform } from '@dnd-kit/utilities';
2
+ import React, { HtmlHTMLAttributes, ReactNode } from 'react';
3
+ type ViewPortProps = {
4
+ children?: ReactNode;
5
+ ratio?: number;
6
+ width?: number;
7
+ height?: number;
8
+ } & HtmlHTMLAttributes<HTMLDivElement>;
9
+ export declare class ViewPortStore {
10
+ transform: {
11
+ left: number;
12
+ top: number;
13
+ };
14
+ offset: {
15
+ x: number;
16
+ y: number;
17
+ };
18
+ scale: number;
19
+ width: number;
20
+ height: number;
21
+ ratio: number;
22
+ constructor(ratio?: number);
23
+ increaseScale(): void;
24
+ decreaseScale(): void;
25
+ move(transform: Transform): void;
26
+ endMove(): void;
27
+ get transformLimit(): {
28
+ left: {
29
+ max: number;
30
+ min: number;
31
+ };
32
+ top: {
33
+ max: number;
34
+ min: number;
35
+ };
36
+ };
37
+ get formatedTransform(): {
38
+ left: number;
39
+ top: number;
40
+ };
41
+ get minScale(): number;
42
+ get maxScale(): number;
43
+ get formatedScale(): number;
44
+ get contentStyle(): {
45
+ left: string;
46
+ top: string;
47
+ transform: string;
48
+ width: string;
49
+ height: string;
50
+ transformOrigin: string;
51
+ };
52
+ get containerStyle(): {
53
+ width: string;
54
+ height: string;
55
+ overflow: string;
56
+ };
57
+ }
58
+ export default function ViewPort(props: ViewPortProps): React.JSX.Element;
59
+ export {};
@@ -0,0 +1,205 @@
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
+ 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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ 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); } }
11
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
+ 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; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
+ 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
+ import { DndContext, useDraggable } from '@dnd-kit/core';
16
+ import { makeAutoObservable, runInAction } from 'mobx';
17
+ import { observer } from 'mobx-react-lite';
18
+ import React, { useEffect, useRef, useState } from 'react';
19
+ import styled from 'styled-components';
20
+ import { GlobalStyles } from "../__styles";
21
+ var Container = styled.div.withConfig({
22
+ displayName: "Container",
23
+ componentId: "basic-component-347b__sc-1qpmpop-0"
24
+ })(["position:relative;border:1px solid #eee;"]);
25
+ var Content = styled.div.withConfig({
26
+ displayName: "Content",
27
+ componentId: "basic-component-347b__sc-1qpmpop-1"
28
+ })(["position:absolute;"]);
29
+ export var ViewPortStore = /*#__PURE__*/function () {
30
+ //缩放比例
31
+ function ViewPortStore(ratio) {
32
+ _classCallCheck(this, ViewPortStore);
33
+ _defineProperty(this, "transform", {
34
+ left: 0,
35
+ top: 0
36
+ });
37
+ _defineProperty(this, "offset", {
38
+ x: 0,
39
+ y: 0
40
+ });
41
+ _defineProperty(this, "scale", 1);
42
+ _defineProperty(this, "width", 800);
43
+ _defineProperty(this, "height", 800);
44
+ _defineProperty(this, "ratio", 5);
45
+ if (ratio) this.ratio = ratio;
46
+ makeAutoObservable(this);
47
+ }
48
+ _createClass(ViewPortStore, [{
49
+ key: "increaseScale",
50
+ value: function increaseScale() {
51
+ if (this.scale < 1) this.scale += 0.03125;else this.scale = 1;
52
+ }
53
+ }, {
54
+ key: "decreaseScale",
55
+ value: function decreaseScale() {
56
+ if (this.scale > this.minScale) this.scale -= 0.03125;
57
+ }
58
+ }, {
59
+ key: "move",
60
+ 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;
63
+ this.offset.x = transform.x;
64
+ this.offset.y = transform.y;
65
+ }
66
+ }, {
67
+ key: "endMove",
68
+ value: function endMove() {
69
+ this.offset.x = 0;
70
+ this.offset.y = 0;
71
+ }
72
+ }, {
73
+ key: "transformLimit",
74
+ get: function get() {
75
+ return {
76
+ left: {
77
+ max: 0,
78
+ min: this.width - this.width * this.ratio * this.formatedScale
79
+ },
80
+ top: {
81
+ max: 0,
82
+ min: this.height - this.height * this.ratio * this.formatedScale
83
+ }
84
+ };
85
+ }
86
+ }, {
87
+ key: "formatedTransform",
88
+ get: function get() {
89
+ 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))
92
+ };
93
+ }
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
+ }, {
105
+ key: "formatedScale",
106
+ get: function get() {
107
+ return Math.min(this.maxScale, Math.max(this.minScale, this.scale));
108
+ }
109
+ }, {
110
+ key: "contentStyle",
111
+ get: function get() {
112
+ return {
113
+ left: this.formatedTransform.left + 'px',
114
+ top: this.formatedTransform.top + 'px',
115
+ transform: "scale(".concat(this.formatedScale, ")"),
116
+ width: this.width * this.ratio + 'px',
117
+ height: this.height * this.ratio + 'px',
118
+ transformOrigin: 'left top'
119
+ };
120
+ }
121
+ }, {
122
+ key: "containerStyle",
123
+ get: function get() {
124
+ return {
125
+ width: this.width + 'px',
126
+ height: this.height + 'px',
127
+ overflow: 'hidden'
128
+ };
129
+ }
130
+ }]);
131
+ return ViewPortStore;
132
+ }();
133
+ var ViewPortEntity = observer(function (props) {
134
+ var children = props.children,
135
+ viewPortStore = props.viewPortStore;
136
+ var _useDraggable = useDraggable({
137
+ id: 'ViewPortEntity'
138
+ }),
139
+ setNodeRef = _useDraggable.setNodeRef,
140
+ attributes = _useDraggable.attributes,
141
+ listeners = _useDraggable.listeners,
142
+ setActivatorNodeRef = _useDraggable.setActivatorNodeRef,
143
+ transform = _useDraggable.transform;
144
+ var _ref = useRef(null);
145
+ useEffect(function () {
146
+ if (transform) {
147
+ viewPortStore.move(transform);
148
+ } else {
149
+ viewPortStore.endMove();
150
+ }
151
+ }, [transform]);
152
+ useEffect(function () {
153
+ var _ref$current;
154
+ function scaleHandler(e) {
155
+ e.stopPropagation();
156
+ e.preventDefault();
157
+ if (e.deltaY > 0) {
158
+ viewPortStore.increaseScale();
159
+ } else {
160
+ viewPortStore.decreaseScale();
161
+ }
162
+ }
163
+ (_ref$current = _ref.current) === null || _ref$current === void 0 || _ref$current.addEventListener('wheel', scaleHandler, {
164
+ passive: false
165
+ });
166
+ return function () {
167
+ var _ref$current2;
168
+ (_ref$current2 = _ref.current) === null || _ref$current2 === void 0 || _ref$current2.removeEventListener('wheel', scaleHandler);
169
+ };
170
+ }, []);
171
+ return /*#__PURE__*/React.createElement(Container, {
172
+ style: viewPortStore.containerStyle
173
+ }, /*#__PURE__*/React.createElement(Content, _extends({
174
+ ref: function ref(dom) {
175
+ _ref.current = dom;
176
+ setNodeRef(_ref.current);
177
+ setActivatorNodeRef(_ref.current);
178
+ }
179
+ }, attributes, listeners, {
180
+ style: viewPortStore.contentStyle
181
+ }), viewPortStore.ratio, children));
182
+ });
183
+ export default function ViewPort(props) {
184
+ 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]);
200
+ return /*#__PURE__*/React.createElement(DndContext, null, /*#__PURE__*/React.createElement(GlobalStyles, {
201
+ $css: []
202
+ }), /*#__PURE__*/React.createElement(ViewPortEntity, {
203
+ viewPortStore: viewPortStore
204
+ }, children));
205
+ }
@@ -0,0 +1 @@
1
+ export { default as ViewPort, ViewPortStore } from './ViewPort';
@@ -0,0 +1 @@
1
+ export { default as ViewPort, ViewPortStore } from "./ViewPort";
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function Test(): React.JSX.Element;
@@ -0,0 +1,73 @@
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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ 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
+ 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
+ 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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ 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";
18
+ var WindowManager = /*#__PURE__*/function () {
19
+ function WindowManager() {
20
+ _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))]);
22
+ makeAutoObservable(this);
23
+ }
24
+ _createClass(WindowManager, [{
25
+ key: "closeWindowHanlder",
26
+ value: function closeWindowHanlder(id) {
27
+ this.windows = this.windows.filter(function (window) {
28
+ return window.id !== id;
29
+ });
30
+ }
31
+ }, {
32
+ key: "report",
33
+ get: function get() {
34
+ return this.windows.map(function (window) {
35
+ return window.id;
36
+ }).join(',');
37
+ }
38
+ }]);
39
+ return WindowManager;
40
+ }();
41
+ 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];
51
+ useEffect(function () {
52
+ function setWidthHeight() {
53
+ setWidth(document.body.offsetWidth);
54
+ setHeight(document.body.offsetHeight);
55
+ }
56
+ window.addEventListener('resize', setWidthHeight);
57
+ setWidthHeight();
58
+ return function () {
59
+ window.removeEventListener('resize', setWidthHeight);
60
+ };
61
+ }, []);
62
+ return /*#__PURE__*/React.createElement(ViewPort, {
63
+ ratio: 5,
64
+ width: width,
65
+ height: height
66
+ }, windowManager.windows.map(function (windowStore) {
67
+ return /*#__PURE__*/React.createElement(Window, {
68
+ window: windowStore,
69
+ key: windowStore.id,
70
+ title: 'xixi'
71
+ }, "123");
72
+ }));
73
+ }
@@ -14,7 +14,7 @@ var WindowStore = /*#__PURE__*/function () {
14
14
  _defineProperty(this, "left", '0px');
15
15
  _defineProperty(this, "top", '0px');
16
16
  _defineProperty(this, "zIndex", 1);
17
- _defineProperty(this, "fullscreen", true);
17
+ _defineProperty(this, "fullscreen", false);
18
18
  _defineProperty(this, "id", '');
19
19
  _defineProperty(this, "transform", null);
20
20
  _defineProperty(this, "isMoving", false);
@@ -12,7 +12,8 @@ import React from 'react';
12
12
  import { Button } from "../Button";
13
13
  import { Space } from "../Space";
14
14
  import { GlobalStyles } from "../__styles";
15
- import { Window, WindowStore } from "./index";
15
+ import Window from "./Window";
16
+ import { WindowStore } from "./index";
16
17
  var WindowManager = /*#__PURE__*/function () {
17
18
  function WindowManager() {
18
19
  _classCallCheck(this, WindowManager);
@@ -38,24 +39,19 @@ var WindowManager = /*#__PURE__*/function () {
38
39
  }();
39
40
  var windowManager = new WindowManager();
40
41
  export default observer(function Test() {
41
- return /*#__PURE__*/React.createElement(DndContext, null, /*#__PURE__*/React.createElement(Space, null, windowManager.report, /*#__PURE__*/React.createElement(Button, {
42
+ return /*#__PURE__*/React.createElement(DndContext, null, /*#__PURE__*/React.createElement(GlobalStyles, {
43
+ $css: []
44
+ }), /*#__PURE__*/React.createElement(Space, null, windowManager.report, /*#__PURE__*/React.createElement(Button, {
42
45
  onClick: function onClick() {
43
46
  windowManager.windows.forEach(function (window) {
44
47
  window.normalizeWindow();
45
48
  });
46
49
  }
47
- }, "\u5C55\u5F00")), /*#__PURE__*/React.createElement("div", {
48
- style: {
49
- position: 'relative',
50
- height: '1200px'
51
- }
52
- }, /*#__PURE__*/React.createElement(GlobalStyles, {
53
- $css: []
54
- }), windowManager.windows.map(function (windowStore) {
50
+ }, "\u5C55\u5F00")), windowManager.windows.map(function (windowStore) {
55
51
  return /*#__PURE__*/React.createElement(Window, {
56
52
  window: windowStore,
57
53
  key: windowStore.id,
58
54
  title: 'xixi'
59
55
  }, "123");
60
- })));
56
+ }));
61
57
  });
package/dist/index.d.ts CHANGED
@@ -12,5 +12,6 @@ export * from './Space';
12
12
  export * from './Spin';
13
13
  export * from './Table';
14
14
  export * from './Tree';
15
+ export * from './ViewPort';
15
16
  export * from './Window';
16
17
  export * from './__styles';
package/dist/index.js CHANGED
@@ -12,5 +12,6 @@ export * from "./Space";
12
12
  export * from "./Spin";
13
13
  export * from "./Table";
14
14
  export * from "./Tree";
15
+ export * from "./ViewPort";
15
16
  export * from "./Window";
16
17
  export * from "./__styles";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kep-platform/basic-component",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
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.34",
50
+ "@kep-platform/hooks": "^0.0.35",
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": "1593591a4d45fb124fcb1aa51e13ee96c08fecca"
90
+ "gitHead": "cc6b4bd3ca4d5463f8abf837c04fc4bae0ba17df"
91
91
  }