@d-matrix/utils 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/enhancedComponent.d.ts +12 -0
- package/dist/react/enhancedComponent.js +44 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/package.json +4 -2
- package/readme.md +27 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* react component 的增强类
|
|
4
|
+
*/
|
|
5
|
+
export declare class EnhancedComponent<P, S> extends React.Component<P, S> {
|
|
6
|
+
/**
|
|
7
|
+
* setState 方法的同步版本
|
|
8
|
+
* @param state
|
|
9
|
+
* @returns Promise
|
|
10
|
+
*/
|
|
11
|
+
protected setStateAsync<K extends keyof S>(state: ((prevState: Readonly<S>, props: Readonly<P>) => Pick<S, K> | S | null) | (Pick<S, K> | S | null)): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.EnhancedComponent = void 0;
|
|
22
|
+
var react_1 = __importDefault(require("react"));
|
|
23
|
+
/**
|
|
24
|
+
* react component 的增强类
|
|
25
|
+
*/
|
|
26
|
+
var EnhancedComponent = /** @class */ (function (_super) {
|
|
27
|
+
__extends(EnhancedComponent, _super);
|
|
28
|
+
function EnhancedComponent() {
|
|
29
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* setState 方法的同步版本
|
|
33
|
+
* @param state
|
|
34
|
+
* @returns Promise
|
|
35
|
+
*/
|
|
36
|
+
EnhancedComponent.prototype.setStateAsync = function (state) {
|
|
37
|
+
var _this = this;
|
|
38
|
+
return new Promise(function (resolve) {
|
|
39
|
+
_this.setState(state, resolve);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return EnhancedComponent;
|
|
43
|
+
}(react_1.default.Component));
|
|
44
|
+
exports.EnhancedComponent = EnhancedComponent;
|
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -15,3 +15,4 @@ __exportStar(require("./useStateCallback"), exports);
|
|
|
15
15
|
__exportStar(require("./renderToString"), exports);
|
|
16
16
|
__exportStar(require("./useIsMounted"), exports);
|
|
17
17
|
__exportStar(require("./useCopyToClipboard"), exports);
|
|
18
|
+
__exportStar(require("./enhancedComponent"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-matrix/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "A dozen of utils for Front-End Development",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"cy:component": "cypress run --component --spec",
|
|
12
12
|
"cy:component:all": "cypress run --component",
|
|
13
13
|
"test:tsd": "tsd",
|
|
14
|
-
"postversion": "git push && git push --tags"
|
|
14
|
+
"postversion": "git push && git push --tags",
|
|
15
|
+
"cnpm:sync": "cnpm sync %npm_package_name%"
|
|
15
16
|
},
|
|
16
17
|
"engines": {
|
|
17
18
|
"node": ">=16.20.0"
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@vitejs/plugin-react": "^4.2.1",
|
|
46
|
+
"cnpm": "^9.4.0",
|
|
45
47
|
"cypress": "^13.6.6",
|
|
46
48
|
"expect-type": "^0.19.0",
|
|
47
49
|
"rimraf": "^5.0.5",
|
package/readme.md
CHANGED
|
@@ -88,6 +88,33 @@ const Test = () => {
|
|
|
88
88
|
|
|
89
89
|
复制文本到剪切板, 用法见[测试](./tests/react.cy.tsx)
|
|
90
90
|
|
|
91
|
+
- `EnhancedComponent.prototype.setStateAsync(state)`
|
|
92
|
+
|
|
93
|
+
setState 方法的同步版本
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { react } from '@d-matrix/utils';
|
|
97
|
+
|
|
98
|
+
class TestComponent extends EnhancedComponent<unknown, { pageIndex: number }> {
|
|
99
|
+
state = {
|
|
100
|
+
pageIndex: 1,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
async onClick() {
|
|
104
|
+
await this.setStateAsync({ pageIndex: 2 });
|
|
105
|
+
console.log(this.state.pageIndex); // 2
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
render() {
|
|
109
|
+
return (
|
|
110
|
+
<button data-cy="test-button" onClick={() => this.onClick()}>
|
|
111
|
+
click
|
|
112
|
+
</button>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
91
118
|
### dom
|
|
92
119
|
|
|
93
120
|
- `scrollToTop(element: Element | null | undefined): void`
|