ag-common 0.0.690 → 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 toArrayBuffer(base64) {
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)(toArrayBuffer(raw));
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
- export declare const ModalDialog: (content: JSX.Element, opt?: {
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
- try {
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;
@@ -59,7 +59,7 @@ function getIdTokenAuthHeader(_a) {
59
59
  });
60
60
  }
61
61
  const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
62
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
62
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
63
63
  const { func, apiUrl, logout, newDefaultApi, headers } = p;
64
64
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
65
  let error;
@@ -116,7 +116,7 @@ const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
116
116
  (_j = (_h = ae.response) === null || _h === void 0 ? void 0 : _h.statusText.toString()) !== null && _j !== void 0 ? _j : '',
117
117
  (_l = (_k = ae.response) === null || _k === void 0 ? void 0 : _k.status.toString()) !== null && _l !== void 0 ? _l : '',
118
118
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
119
- (_m = ae.message.toString()) !== null && _m !== void 0 ? _m : '',
119
+ (_o = (_m = ae.message) === null || _m === void 0 ? void 0 : _m.toString()) !== null && _o !== void 0 ? _o : '',
120
120
  ]
121
121
  .filter(array_1.notEmpty)
122
122
  .sort((a, b) => (a.length < b.length ? -1 : 1))
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.690",
2
+ "version": "0.0.692",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",