ag-common 0.0.691 → 0.0.692
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Buffer } from 'buffer';
|
|
3
3
|
export declare const toBuffer: (ab: ArrayBuffer) => Buffer;
|
|
4
|
+
export declare function bufferToArrayBuffer(buffer: Buffer): ArrayBuffer;
|
|
5
|
+
export declare function b64ToArrayBuffer(base64: string): ArrayBufferLike;
|
|
4
6
|
/**
|
|
5
7
|
* convert an ArrayBuffer (usually from file.arrayBuffer) to base64. Usually on client side before server send
|
|
6
8
|
* @param buffer
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.base64ToBinary = exports.arrayBufferToBase64 = exports.toBuffer = void 0;
|
|
3
|
+
exports.base64ToBinary = exports.arrayBufferToBase64 = exports.b64ToArrayBuffer = exports.bufferToArrayBuffer = exports.toBuffer = void 0;
|
|
4
4
|
const buffer_1 = require("buffer");
|
|
5
5
|
const base64_1 = require("./string/base64");
|
|
6
6
|
const toBuffer = (ab) => buffer_1.Buffer.from(ab);
|
|
7
7
|
exports.toBuffer = toBuffer;
|
|
8
|
-
function
|
|
8
|
+
function bufferToArrayBuffer(buffer) {
|
|
9
|
+
const arrayBuffer = new ArrayBuffer(buffer.length);
|
|
10
|
+
const view = new Uint8Array(arrayBuffer);
|
|
11
|
+
for (let i = 0; i < buffer.length; ++i) {
|
|
12
|
+
view[i] = buffer[i];
|
|
13
|
+
}
|
|
14
|
+
return arrayBuffer;
|
|
15
|
+
}
|
|
16
|
+
exports.bufferToArrayBuffer = bufferToArrayBuffer;
|
|
17
|
+
function b64ToArrayBuffer(base64) {
|
|
9
18
|
const binary_string = (0, base64_1.fromBase64)(base64);
|
|
10
19
|
const len = binary_string.length;
|
|
11
20
|
const bytes = new Uint8Array(len);
|
|
@@ -14,6 +23,7 @@ function toArrayBuffer(base64) {
|
|
|
14
23
|
}
|
|
15
24
|
return bytes.buffer;
|
|
16
25
|
}
|
|
26
|
+
exports.b64ToArrayBuffer = b64ToArrayBuffer;
|
|
17
27
|
/**
|
|
18
28
|
* convert an ArrayBuffer (usually from file.arrayBuffer) to base64. Usually on client side before server send
|
|
19
29
|
* @param buffer
|
|
@@ -34,5 +44,5 @@ exports.arrayBufferToBase64 = arrayBufferToBase64;
|
|
|
34
44
|
* @param raw
|
|
35
45
|
* @returns
|
|
36
46
|
*/
|
|
37
|
-
const base64ToBinary = (raw) => (0, exports.toBuffer)(
|
|
47
|
+
const base64ToBinary = (raw) => (0, exports.toBuffer)(b64ToArrayBuffer(raw));
|
|
38
48
|
exports.base64ToBinary = base64ToBinary;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { CSSProperties } from 'react';
|
|
2
|
-
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare const ModalDialog: (content: React.ReactNode | ((p: {
|
|
4
|
+
close: () => void;
|
|
5
|
+
}) => React.ReactNode), opt?: {
|
|
3
6
|
style?: CSSProperties;
|
|
4
7
|
portalId?: string;
|
|
5
8
|
}) => Promise<string | undefined>;
|
|
@@ -20,18 +20,27 @@ const ModalDialog = (content, opt) => __awaiter(void 0, void 0, void 0, function
|
|
|
20
20
|
return new Promise((res) => {
|
|
21
21
|
const wrapper = document.body.appendChild(document.createElement('div'));
|
|
22
22
|
const root = (0, client_1.createRoot)(wrapper);
|
|
23
|
+
const onClose = () => {
|
|
24
|
+
try {
|
|
25
|
+
root.unmount();
|
|
26
|
+
wrapper.remove();
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
//
|
|
30
|
+
}
|
|
31
|
+
};
|
|
23
32
|
root.render(react_1.default.createElement(Modal_1.Modal, { open: true, setOpen: (o) => {
|
|
24
33
|
if (!o) {
|
|
25
|
-
|
|
26
|
-
root.unmount();
|
|
27
|
-
wrapper.remove();
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
//
|
|
31
|
-
}
|
|
34
|
+
onClose();
|
|
32
35
|
}
|
|
33
36
|
res('ok');
|
|
34
|
-
}, topPosition: "center", position: "center", style: opt === null || opt === void 0 ? void 0 : opt.style }, content
|
|
37
|
+
}, topPosition: "center", position: "center", style: opt === null || opt === void 0 ? void 0 : opt.style }, typeof content !== 'function'
|
|
38
|
+
? content
|
|
39
|
+
: content({
|
|
40
|
+
close: () => {
|
|
41
|
+
onClose();
|
|
42
|
+
},
|
|
43
|
+
})));
|
|
35
44
|
});
|
|
36
45
|
});
|
|
37
46
|
exports.ModalDialog = ModalDialog;
|
package/package.json
CHANGED