@rh-support/components 2.1.39 → 2.1.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.
- package/lib/cjs/PromisifyModal/PromisifyModal.d.ts +6 -9
- package/lib/cjs/PromisifyModal/PromisifyModal.d.ts.map +1 -1
- package/lib/cjs/PromisifyModal/PromisifyModal.js +20 -19
- package/lib/esm/PromisifyModal/PromisifyModal.d.ts +6 -9
- package/lib/esm/PromisifyModal/PromisifyModal.d.ts.map +1 -1
- package/lib/esm/PromisifyModal/PromisifyModal.js +20 -19
- package/package.json +4 -4
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
+
type RenderFunction<T> = (props: RenderFunctionProps<T>) => ReactElement<any>;
|
|
2
3
|
interface Options {
|
|
3
4
|
destructionDelay?: number;
|
|
4
5
|
}
|
|
5
|
-
type
|
|
6
|
-
type OnSubmitCallback<R> = {
|
|
7
|
-
(): void;
|
|
8
|
-
(value: R): void;
|
|
9
|
-
};
|
|
6
|
+
type Callback<R> = void extends R ? () => void : (value: R) => void;
|
|
10
7
|
interface RenderFunctionProps<R> {
|
|
11
8
|
show: boolean;
|
|
12
|
-
onSubmit:
|
|
13
|
-
onDismiss:
|
|
9
|
+
onSubmit: Callback<R>;
|
|
10
|
+
onDismiss: Callback<void>;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
export declare function PromisifyModal<R
|
|
12
|
+
export declare function PromisifyModal(renderModal: RenderFunction<void>, options?: Options): Promise<true | undefined>;
|
|
13
|
+
export declare function PromisifyModal<R>(renderModal: RenderFunction<R>, options?: Options): Promise<R | undefined>;
|
|
17
14
|
export {};
|
|
18
15
|
//# sourceMappingURL=PromisifyModal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromisifyModal.d.ts","sourceRoot":"","sources":["../../../src/PromisifyModal/PromisifyModal.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PromisifyModal.d.ts","sourceRoot":"","sources":["../../../src/PromisifyModal/PromisifyModal.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AASrC,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,GAAG,CAAC,CAAC;AAE9E,UAAU,OAAO;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,KAAK,QAAQ,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEpE,UAAU,mBAAmB,CAAC,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;AAEhH,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC"}
|
|
@@ -5,38 +5,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.PromisifyModal = void 0;
|
|
6
6
|
const client_1 = require("react-dom/client");
|
|
7
7
|
const DEFAULT_DESTRUCTION_DELAY = 300;
|
|
8
|
-
const DEFAULT_OPTIONS = {
|
|
9
|
-
destructionDelay: DEFAULT_DESTRUCTION_DELAY,
|
|
10
|
-
};
|
|
11
8
|
const noop = () => { };
|
|
12
9
|
function PromisifyModal(renderModal, options = {}) {
|
|
13
|
-
const { destructionDelay
|
|
10
|
+
const { destructionDelay = DEFAULT_DESTRUCTION_DELAY } = options;
|
|
14
11
|
const container = document.createElement('div');
|
|
15
12
|
document.body.appendChild(container);
|
|
16
|
-
const
|
|
13
|
+
const root = (0, client_1.createRoot)(container);
|
|
17
14
|
function displayModal({ onSubmit, onDismiss }) {
|
|
18
|
-
render(renderModal({ onSubmit, onDismiss, show: true }));
|
|
15
|
+
root.render(renderModal({ onSubmit, onDismiss, show: true }));
|
|
19
16
|
}
|
|
20
|
-
function hideModal({ onSubmit, onDismiss }
|
|
21
|
-
render(renderModal({ onSubmit, onDismiss, show: false }));
|
|
22
|
-
requestIdleCallback(callback); // referred https://github.com/reactwg/react-18/discussions/5
|
|
17
|
+
function hideModal({ onSubmit, onDismiss }) {
|
|
18
|
+
root.render(renderModal({ onSubmit, onDismiss, show: false }));
|
|
23
19
|
}
|
|
24
20
|
function destroyModal() {
|
|
25
|
-
unmount();
|
|
21
|
+
root.unmount();
|
|
26
22
|
document.body.removeChild(container);
|
|
27
23
|
}
|
|
28
24
|
const confirmation = new Promise((resolve) => {
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
function onSubmit(value) {
|
|
26
|
+
if (arguments.length === 0) {
|
|
27
|
+
resolve(true);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
resolve(value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function onDismiss() {
|
|
34
|
+
resolve(undefined);
|
|
35
|
+
}
|
|
31
36
|
displayModal({ onSubmit, onDismiss });
|
|
32
37
|
});
|
|
33
|
-
return confirmation.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
hideModal({ onSubmit, onDismiss }, () => {
|
|
37
|
-
setTimeout(destroyModal, destructionDelay);
|
|
38
|
-
});
|
|
39
|
-
return result;
|
|
38
|
+
return confirmation.finally(() => {
|
|
39
|
+
hideModal({ onSubmit: noop, onDismiss: noop });
|
|
40
|
+
setTimeout(destroyModal, destructionDelay);
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
exports.PromisifyModal = PromisifyModal;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
+
type RenderFunction<T> = (props: RenderFunctionProps<T>) => ReactElement<any>;
|
|
2
3
|
interface Options {
|
|
3
4
|
destructionDelay?: number;
|
|
4
5
|
}
|
|
5
|
-
type
|
|
6
|
-
type OnSubmitCallback<R> = {
|
|
7
|
-
(): void;
|
|
8
|
-
(value: R): void;
|
|
9
|
-
};
|
|
6
|
+
type Callback<R> = void extends R ? () => void : (value: R) => void;
|
|
10
7
|
interface RenderFunctionProps<R> {
|
|
11
8
|
show: boolean;
|
|
12
|
-
onSubmit:
|
|
13
|
-
onDismiss:
|
|
9
|
+
onSubmit: Callback<R>;
|
|
10
|
+
onDismiss: Callback<void>;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
export declare function PromisifyModal<R
|
|
12
|
+
export declare function PromisifyModal(renderModal: RenderFunction<void>, options?: Options): Promise<true | undefined>;
|
|
13
|
+
export declare function PromisifyModal<R>(renderModal: RenderFunction<R>, options?: Options): Promise<R | undefined>;
|
|
17
14
|
export {};
|
|
18
15
|
//# sourceMappingURL=PromisifyModal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromisifyModal.d.ts","sourceRoot":"","sources":["../../../src/PromisifyModal/PromisifyModal.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PromisifyModal.d.ts","sourceRoot":"","sources":["../../../src/PromisifyModal/PromisifyModal.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AASrC,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,GAAG,CAAC,CAAC;AAE9E,UAAU,OAAO;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,KAAK,QAAQ,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEpE,UAAU,mBAAmB,CAAC,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;AAEhH,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC"}
|
|
@@ -2,37 +2,38 @@
|
|
|
2
2
|
// https://github.com/prezly/react-promise-modal/
|
|
3
3
|
import { createRoot } from 'react-dom/client';
|
|
4
4
|
const DEFAULT_DESTRUCTION_DELAY = 300;
|
|
5
|
-
const DEFAULT_OPTIONS = {
|
|
6
|
-
destructionDelay: DEFAULT_DESTRUCTION_DELAY,
|
|
7
|
-
};
|
|
8
5
|
const noop = () => { };
|
|
9
6
|
export function PromisifyModal(renderModal, options = {}) {
|
|
10
|
-
const { destructionDelay
|
|
7
|
+
const { destructionDelay = DEFAULT_DESTRUCTION_DELAY } = options;
|
|
11
8
|
const container = document.createElement('div');
|
|
12
9
|
document.body.appendChild(container);
|
|
13
|
-
const
|
|
10
|
+
const root = createRoot(container);
|
|
14
11
|
function displayModal({ onSubmit, onDismiss }) {
|
|
15
|
-
render(renderModal({ onSubmit, onDismiss, show: true }));
|
|
12
|
+
root.render(renderModal({ onSubmit, onDismiss, show: true }));
|
|
16
13
|
}
|
|
17
|
-
function hideModal({ onSubmit, onDismiss }
|
|
18
|
-
render(renderModal({ onSubmit, onDismiss, show: false }));
|
|
19
|
-
requestIdleCallback(callback); // referred https://github.com/reactwg/react-18/discussions/5
|
|
14
|
+
function hideModal({ onSubmit, onDismiss }) {
|
|
15
|
+
root.render(renderModal({ onSubmit, onDismiss, show: false }));
|
|
20
16
|
}
|
|
21
17
|
function destroyModal() {
|
|
22
|
-
unmount();
|
|
18
|
+
root.unmount();
|
|
23
19
|
document.body.removeChild(container);
|
|
24
20
|
}
|
|
25
21
|
const confirmation = new Promise((resolve) => {
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
function onSubmit(value) {
|
|
23
|
+
if (arguments.length === 0) {
|
|
24
|
+
resolve(true);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
resolve(value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function onDismiss() {
|
|
31
|
+
resolve(undefined);
|
|
32
|
+
}
|
|
28
33
|
displayModal({ onSubmit, onDismiss });
|
|
29
34
|
});
|
|
30
|
-
return confirmation.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
hideModal({ onSubmit, onDismiss }, () => {
|
|
34
|
-
setTimeout(destroyModal, destructionDelay);
|
|
35
|
-
});
|
|
36
|
-
return result;
|
|
35
|
+
return confirmation.finally(() => {
|
|
36
|
+
hideModal({ onSubmit: noop, onDismiss: noop });
|
|
37
|
+
setTimeout(destroyModal, destructionDelay);
|
|
37
38
|
});
|
|
38
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.41",
|
|
4
4
|
"description": "Contains all reusabel components for support app",
|
|
5
5
|
"author": "Vikas Rathee <vrathee@redhat.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"@patternfly/react-core": "5.1.1",
|
|
80
80
|
"@patternfly/react-table": "5.1.1",
|
|
81
81
|
"@rh-support/types": "2.0.3",
|
|
82
|
-
"@rh-support/user-permissions": "2.1.
|
|
83
|
-
"@rh-support/utils": "2.1.
|
|
82
|
+
"@rh-support/user-permissions": "2.1.30",
|
|
83
|
+
"@rh-support/utils": "2.1.22",
|
|
84
84
|
"dompurify": "^2.2.6",
|
|
85
85
|
"downshift": "^6.0.5",
|
|
86
86
|
"js-worker-search": "^1.4.1",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"defaults and supports es6-module",
|
|
121
121
|
"maintained node versions"
|
|
122
122
|
],
|
|
123
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "1507b066b04853fb74cbd1fcac022dbcc94c0ec3"
|
|
124
124
|
}
|