piral-modals 0.15.0-alpha.4041 → 0.15.0-alpha.4231
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/esm/Modals.js +4 -3
- package/esm/Modals.js.map +1 -1
- package/esm/create.d.ts +6 -2
- package/esm/create.js +4 -2
- package/esm/create.js.map +1 -1
- package/esm/types.d.ts +25 -2
- package/lib/Modals.js +4 -3
- package/lib/Modals.js.map +1 -1
- package/lib/create.d.ts +6 -2
- package/lib/create.js +4 -2
- package/lib/create.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +25 -2
- package/package.json +19 -6
- package/piral-modals.min.js +1 -1
- package/src/Modals.tsx +7 -9
- package/src/create.ts +10 -4
- package/src/types.ts +27 -2
package/esm/Modals.js
CHANGED
|
@@ -22,10 +22,11 @@ export const Modals = () => {
|
|
|
22
22
|
const reg = modals[n.name] || findModal(modals, n.alternative);
|
|
23
23
|
const Component = reg && reg.component;
|
|
24
24
|
const defaults = reg && reg.defaults;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const options = Object.assign(Object.assign({}, defaults), n.options);
|
|
26
|
+
return (Component && (React.createElement(PiralModalsDialog, Object.assign({}, n, { options: options, defaults: reg.defaults, layout: reg.layout, key: n.name }),
|
|
27
|
+
React.createElement(Component, { onClose: n.close, options: options }))));
|
|
27
28
|
})
|
|
28
|
-
.filter(
|
|
29
|
+
.filter(Boolean);
|
|
29
30
|
const open = children.length > 0;
|
|
30
31
|
return (React.createElement(PiralModalsHost, { open: open, close: close }, children));
|
|
31
32
|
};
|
package/esm/Modals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modals.js","sourceRoot":"","sources":["../src/Modals.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO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AAC,CAAC,EAAE,EAAE;QACT,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;QAC/D,MAAM,SAAS,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC;QACvC,MAAM,QAAQ,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC;QACrC,MAAM,OAAO,mCACR,QAAQ,GACR,CAAC,CAAC,OAAO,CACb,CAAC;QACF,OAAO,CACL,SAAS,IAAI,CACX,oBAAC,iBAAiB,oBAAK,CAAC,IAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI;YACjG,oBAAC,SAAS,IAAC,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAI,CAC/B,CACrB,CACF,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAEjC,OAAO,CACL,oBAAC,eAAe,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IACtC,QAAQ,CACO,CACnB,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC"}
|
package/esm/create.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
import { PiralPlugin } from 'piral-core';
|
|
3
|
-
import { PiletModalsApi, BareModalComponentProps } from './types';
|
|
3
|
+
import { PiletModalsApi, BareModalComponentProps, ModalLayoutOptions } from './types';
|
|
4
4
|
export interface InitialModalDialog {
|
|
5
5
|
/**
|
|
6
6
|
* The name of the modal dialog.
|
|
@@ -13,7 +13,11 @@ export interface InitialModalDialog {
|
|
|
13
13
|
/**
|
|
14
14
|
* The default options for the modal dialog.
|
|
15
15
|
*/
|
|
16
|
-
defaults
|
|
16
|
+
defaults?: any;
|
|
17
|
+
/**
|
|
18
|
+
* The layout options for the modal dialog.
|
|
19
|
+
*/
|
|
20
|
+
layout?: ModalLayoutOptions;
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
23
|
* Available configuration options for the modals plugin.
|
package/esm/create.js
CHANGED
|
@@ -4,12 +4,13 @@ import { DefaultHost, DefaultDialog } from './default';
|
|
|
4
4
|
import { Modals } from './Modals';
|
|
5
5
|
function getModalDialogs(dialogs) {
|
|
6
6
|
const modals = {};
|
|
7
|
-
for (const { name, component, defaults } of dialogs) {
|
|
7
|
+
for (const { name, component, defaults, layout = {} } of dialogs) {
|
|
8
8
|
modals[`global-${name}`] = {
|
|
9
9
|
pilet: undefined,
|
|
10
10
|
name,
|
|
11
11
|
component,
|
|
12
12
|
defaults,
|
|
13
|
+
layout,
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
16
|
return modals;
|
|
@@ -42,13 +43,14 @@ export function createModalsApi(config = {}) {
|
|
|
42
43
|
context.openModal(dialog);
|
|
43
44
|
return dialog.close;
|
|
44
45
|
},
|
|
45
|
-
registerModal(name, arg, defaults) {
|
|
46
|
+
registerModal(name, arg, defaults, layout = {}) {
|
|
46
47
|
const id = buildName(pilet, name);
|
|
47
48
|
context.registerModal(id, {
|
|
48
49
|
pilet,
|
|
49
50
|
name,
|
|
50
51
|
component: withApi(context, arg, api, 'modal'),
|
|
51
52
|
defaults,
|
|
53
|
+
layout,
|
|
52
54
|
});
|
|
53
55
|
return () => api.unregisterModal(name);
|
|
54
56
|
},
|
package/esm/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,OAAO,E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P,CAAC,CAAC;oBACH,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;gBACzC,CAAC;gBACD,eAAe,CAAC,IAAI;oBAClB,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;oBAClC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;gBAC9B,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentType } from 'react';
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import type { Dict, WrappedComponent, BaseComponentProps, BaseRegistration, Disposable, AnyComponent, RegistrationDisposer } from 'piral-core';
|
|
3
3
|
declare module 'piral-core/lib/types/custom' {
|
|
4
4
|
interface PiletCustomApi extends PiletModalsApi {
|
|
@@ -61,8 +61,29 @@ export interface ModalsHostProps {
|
|
|
61
61
|
* Callback to invoke closing the modal dialog.
|
|
62
62
|
*/
|
|
63
63
|
close(): void;
|
|
64
|
+
/**
|
|
65
|
+
* The dialogs to display.
|
|
66
|
+
*/
|
|
67
|
+
children?: ReactNode;
|
|
64
68
|
}
|
|
65
69
|
export interface ModalsDialogProps extends OpenModalDialog {
|
|
70
|
+
/**
|
|
71
|
+
* The layout options given for the current dialog.
|
|
72
|
+
*/
|
|
73
|
+
layout: ModalLayoutOptions;
|
|
74
|
+
/**
|
|
75
|
+
* The provided default options.
|
|
76
|
+
*/
|
|
77
|
+
defaults: any;
|
|
78
|
+
/**
|
|
79
|
+
* The content of the dialog to display.
|
|
80
|
+
*/
|
|
81
|
+
children?: ReactNode;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The options provided for the dialog layout.
|
|
85
|
+
*/
|
|
86
|
+
export interface ModalLayoutOptions {
|
|
66
87
|
}
|
|
67
88
|
/**
|
|
68
89
|
* The error used when a registered modal dialog crashed.
|
|
@@ -121,6 +142,7 @@ export interface ModalRegistration extends BaseRegistration {
|
|
|
121
142
|
name: string;
|
|
122
143
|
component: WrappedComponent<ModalComponentProps<any>>;
|
|
123
144
|
defaults: any;
|
|
145
|
+
layout: ModalLayoutOptions;
|
|
124
146
|
}
|
|
125
147
|
export interface BaseModalOptions {
|
|
126
148
|
}
|
|
@@ -145,8 +167,9 @@ export interface PiletModalsApi {
|
|
|
145
167
|
* @param name The name of the modal to register.
|
|
146
168
|
* @param Component The component to render the page.
|
|
147
169
|
* @param defaults Optionally, sets the default values for the inserted options.
|
|
170
|
+
* @param layout Optionally, sets the layout options for the dialog wrapper.
|
|
148
171
|
*/
|
|
149
|
-
registerModal<T>(name: T extends string ? T : string, Component: AnyComponent<ModalComponentProps<T>>, defaults?: ModalOptions<T
|
|
172
|
+
registerModal<T>(name: T extends string ? T : string, Component: AnyComponent<ModalComponentProps<T>>, defaults?: ModalOptions<T>, layout?: ModalLayoutOptions): RegistrationDisposer;
|
|
150
173
|
/**
|
|
151
174
|
* Unregisters a modal by its name.
|
|
152
175
|
* @param name The name that was previously registered.
|
package/lib/Modals.js
CHANGED
|
@@ -25,10 +25,11 @@ const Modals = () => {
|
|
|
25
25
|
const reg = modals[n.name] || findModal(modals, n.alternative);
|
|
26
26
|
const Component = reg && reg.component;
|
|
27
27
|
const defaults = reg && reg.defaults;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const options = Object.assign(Object.assign({}, defaults), n.options);
|
|
29
|
+
return (Component && (React.createElement(components_1.PiralModalsDialog, Object.assign({}, n, { options: options, defaults: reg.defaults, layout: reg.layout, key: n.name }),
|
|
30
|
+
React.createElement(Component, { onClose: n.close, options: options }))));
|
|
30
31
|
})
|
|
31
|
-
.filter(
|
|
32
|
+
.filter(Boolean);
|
|
32
33
|
const open = children.length > 0;
|
|
33
34
|
return (React.createElement(components_1.PiralModalsHost, { open: open, close: close }, children));
|
|
34
35
|
};
|
package/lib/Modals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C,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;QAC/D,MAAM,SAAS,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC;QACvC,MAAM,QAAQ,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC;QACrC,MAAM,OAAO,mCACR,QAAQ,GACR,CAAC,CAAC,OAAO,CACb,CAAC;QACF,OAAO,CACL,SAAS,IAAI,CACX,oBAAC,8BAAiB,oBAAK,CAAC,IAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI;YACjG,oBAAC,SAAS,IAAC,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAI,CAC/B,CACrB,CACF,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAEjC,OAAO,CACL,oBAAC,4BAAe,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IACtC,QAAQ,CACO,CACnB,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,MAAM,UA6BjB;AACF,cAAM,CAAC,WAAW,GAAG,QAAQ,CAAC"}
|
package/lib/create.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
import { PiralPlugin } from 'piral-core';
|
|
3
|
-
import { PiletModalsApi, BareModalComponentProps } from './types';
|
|
3
|
+
import { PiletModalsApi, BareModalComponentProps, ModalLayoutOptions } from './types';
|
|
4
4
|
export interface InitialModalDialog {
|
|
5
5
|
/**
|
|
6
6
|
* The name of the modal dialog.
|
|
@@ -13,7 +13,11 @@ export interface InitialModalDialog {
|
|
|
13
13
|
/**
|
|
14
14
|
* The default options for the modal dialog.
|
|
15
15
|
*/
|
|
16
|
-
defaults
|
|
16
|
+
defaults?: any;
|
|
17
|
+
/**
|
|
18
|
+
* The layout options for the modal dialog.
|
|
19
|
+
*/
|
|
20
|
+
layout?: ModalLayoutOptions;
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
23
|
* Available configuration options for the modals plugin.
|
package/lib/create.js
CHANGED
|
@@ -7,12 +7,13 @@ const default_1 = require("./default");
|
|
|
7
7
|
const Modals_1 = require("./Modals");
|
|
8
8
|
function getModalDialogs(dialogs) {
|
|
9
9
|
const modals = {};
|
|
10
|
-
for (const { name, component, defaults } of dialogs) {
|
|
10
|
+
for (const { name, component, defaults, layout = {} } of dialogs) {
|
|
11
11
|
modals[`global-${name}`] = {
|
|
12
12
|
pilet: undefined,
|
|
13
13
|
name,
|
|
14
14
|
component,
|
|
15
15
|
defaults,
|
|
16
|
+
layout,
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
return modals;
|
|
@@ -45,13 +46,14 @@ function createModalsApi(config = {}) {
|
|
|
45
46
|
context.openModal(dialog);
|
|
46
47
|
return dialog.close;
|
|
47
48
|
},
|
|
48
|
-
registerModal(name, arg, defaults) {
|
|
49
|
+
registerModal(name, arg, defaults, layout = {}) {
|
|
49
50
|
const id = (0, piral_core_1.buildName)(pilet, name);
|
|
50
51
|
context.registerModal(id, {
|
|
51
52
|
pilet,
|
|
52
53
|
name,
|
|
53
54
|
component: (0, piral_core_1.withApi)(context, arg, api, 'modal'),
|
|
54
55
|
defaults,
|
|
56
|
+
layout,
|
|
55
57
|
});
|
|
56
58
|
return () => api.unregisterModal(name);
|
|
57
59
|
},
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;A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ACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA5CD,0CA4CC"}
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./create"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./components"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./Modals"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,uDAA6B;AAC7B,mDAAyB;AACzB,kDAAwB"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentType } from 'react';
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import type { Dict, WrappedComponent, BaseComponentProps, BaseRegistration, Disposable, AnyComponent, RegistrationDisposer } from 'piral-core';
|
|
3
3
|
declare module 'piral-core/lib/types/custom' {
|
|
4
4
|
interface PiletCustomApi extends PiletModalsApi {
|
|
@@ -61,8 +61,29 @@ export interface ModalsHostProps {
|
|
|
61
61
|
* Callback to invoke closing the modal dialog.
|
|
62
62
|
*/
|
|
63
63
|
close(): void;
|
|
64
|
+
/**
|
|
65
|
+
* The dialogs to display.
|
|
66
|
+
*/
|
|
67
|
+
children?: ReactNode;
|
|
64
68
|
}
|
|
65
69
|
export interface ModalsDialogProps extends OpenModalDialog {
|
|
70
|
+
/**
|
|
71
|
+
* The layout options given for the current dialog.
|
|
72
|
+
*/
|
|
73
|
+
layout: ModalLayoutOptions;
|
|
74
|
+
/**
|
|
75
|
+
* The provided default options.
|
|
76
|
+
*/
|
|
77
|
+
defaults: any;
|
|
78
|
+
/**
|
|
79
|
+
* The content of the dialog to display.
|
|
80
|
+
*/
|
|
81
|
+
children?: ReactNode;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The options provided for the dialog layout.
|
|
85
|
+
*/
|
|
86
|
+
export interface ModalLayoutOptions {
|
|
66
87
|
}
|
|
67
88
|
/**
|
|
68
89
|
* The error used when a registered modal dialog crashed.
|
|
@@ -121,6 +142,7 @@ export interface ModalRegistration extends BaseRegistration {
|
|
|
121
142
|
name: string;
|
|
122
143
|
component: WrappedComponent<ModalComponentProps<any>>;
|
|
123
144
|
defaults: any;
|
|
145
|
+
layout: ModalLayoutOptions;
|
|
124
146
|
}
|
|
125
147
|
export interface BaseModalOptions {
|
|
126
148
|
}
|
|
@@ -145,8 +167,9 @@ export interface PiletModalsApi {
|
|
|
145
167
|
* @param name The name of the modal to register.
|
|
146
168
|
* @param Component The component to render the page.
|
|
147
169
|
* @param defaults Optionally, sets the default values for the inserted options.
|
|
170
|
+
* @param layout Optionally, sets the layout options for the dialog wrapper.
|
|
148
171
|
*/
|
|
149
|
-
registerModal<T>(name: T extends string ? T : string, Component: AnyComponent<ModalComponentProps<T>>, defaults?: ModalOptions<T
|
|
172
|
+
registerModal<T>(name: T extends string ? T : string, Component: AnyComponent<ModalComponentProps<T>>, defaults?: ModalOptions<T>, layout?: ModalLayoutOptions): RegistrationDisposer;
|
|
150
173
|
/**
|
|
151
174
|
* Unregisters a modal by its name.
|
|
152
175
|
* @param name The name that was previously registered.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-modals",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.4231",
|
|
4
4
|
"description": "Plugin for the display of modal dialogs in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -20,6 +20,19 @@
|
|
|
20
20
|
"module": "esm/index.js",
|
|
21
21
|
"main": "lib/index.js",
|
|
22
22
|
"typings": "lib/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./esm/index.js",
|
|
26
|
+
"require": "./lib/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./esm/*": {
|
|
29
|
+
"import": "./esm/*"
|
|
30
|
+
},
|
|
31
|
+
"./lib/*": {
|
|
32
|
+
"require": "./lib/*"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
23
36
|
"sideEffects": false,
|
|
24
37
|
"files": [
|
|
25
38
|
"esm",
|
|
@@ -44,13 +57,13 @@
|
|
|
44
57
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
45
58
|
},
|
|
46
59
|
"devDependencies": {
|
|
47
|
-
"@types/react": "^
|
|
48
|
-
"piral-core": "0.15.0-alpha.
|
|
49
|
-
"react": "^
|
|
60
|
+
"@types/react": "^18.0.0",
|
|
61
|
+
"piral-core": "0.15.0-alpha.4231",
|
|
62
|
+
"react": "^18.0.0"
|
|
50
63
|
},
|
|
51
64
|
"peerDependencies": {
|
|
52
|
-
"piral-core": "0.14.x",
|
|
65
|
+
"piral-core": "0.14.x || 0.15.x",
|
|
53
66
|
"react": ">=16.8.0"
|
|
54
67
|
},
|
|
55
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "4e7f158bd276d82c5bf2c19d47ccfb3604f38e38"
|
|
56
69
|
}
|
package/piral-modals.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var piralModals=(()=>{var F=Object.create;var
|
|
1
|
+
var piralModals=(()=>{var F=Object.create;var y=Object.defineProperty,N=Object.defineProperties,T=Object.getOwnPropertyDescriptor,$=Object.getOwnPropertyDescriptors,E=Object.getOwnPropertyNames,G=Object.getOwnPropertySymbols,K=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var O=(o,t,a)=>t in o?y(o,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[t]=a,e=(o,t)=>{for(var a in t||(t={}))H.call(t,a)&&O(o,a,t[a]);if(G)for(var a of G(t))L.call(t,a)&&O(o,a,t[a]);return o},i=(o,t)=>N(o,$(t)),S=o=>y(o,"__esModule",{value:!0});var g=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(t,a)=>(typeof require!="undefined"?require:t)[a]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+o+'" is not supported')});var v=(o,t)=>{S(o);for(var a in t)y(o,a,{get:t[a],enumerable:!0})},j=(o,t,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of E(t))!H.call(o,l)&&l!=="default"&&y(o,l,{get:()=>t[l],enumerable:!(a=T(t,l))||a.enumerable});return o},M=o=>j(S(y(o!=null?F(K(o)):{},"default",o&&o.__esModule&&"default"in o?{get:()=>o.default,enumerable:!0}:{value:o,enumerable:!0})),o);var Y={};v(Y,{Modals:()=>h,PiralModalsDialog:()=>b,PiralModalsHost:()=>R,createModalsApi:()=>X});var P={};v(P,{closeModal:()=>q,openModal:()=>_,registerModal:()=>z,unregisterModal:()=>J});var p=M(g("piral-core"));function _(o,t){o.dispatch(a=>i(e({},a),{modals:(0,p.prependItem)(a.modals,t)}))}function q(o,t){o.dispatch(a=>i(e({},a),{modals:(0,p.excludeOn)(a.modals,l=>l.id===t.id)}))}function z(o,t,a){o.dispatch(l=>i(e({},l),{registry:i(e({},l.registry),{modals:(0,p.withKey)(l.registry.modals,t,a)})}))}function J(o,t){o.dispatch(a=>i(e({},a),{registry:i(e({},a.registry),{modals:(0,p.withoutKey)(a.registry.modals,t)})}))}var d=M(g("piral-core"));var x=M(g("react")),w=M(g("piral-core")),I=o=>x.createElement("div",{className:"piral-modals-host",key:"default_modals"},o.open&&x.createElement("div",{className:"piral-modals-overlay"},o.children)),k=o=>(0,w.defaultRender)(o.children);var D=M(g("react")),A=M(g("piral-core"));var C=M(g("piral-core")),R=(0,C.getPiralComponent)("ModalsHost"),b=(0,C.getPiralComponent)("ModalsDialog");function Q(o){o.forEach(t=>t.close())}function U(o,t){if(t){let[a]=Object.keys(o).filter(l=>o[l].name===t).map(l=>o[l]);return a}}var h=()=>{let o=(0,A.useGlobalState)(r=>r.registry.modals),t=(0,A.useGlobalState)(r=>r.modals),a=()=>Q(t),l=t.map(r=>{let s=o[r.name]||U(o,r.alternative),n=s&&s.component,c=s&&s.defaults,m=e(e({},c),r.options);return n&&D.createElement(b,i(e({},r),{options:m,defaults:s.defaults,layout:s.layout,key:r.name}),D.createElement(n,{onClose:r.close,options:m}))}).filter(Boolean),f=l.length>0;return D.createElement(R,{open:f,close:a},l)};h.displayName="Modals";function V(o){let t={};for(let{name:a,component:l,defaults:f,layout:r={}}of o)t[`global-${a}`]={pilet:void 0,name:a,component:l,defaults:f,layout:r};return t}function W(o){return t=>i(e({},t),{components:e({ModalsHost:I,ModalsDialog:k},t.components),registry:i(e({},t.registry),{modals:o}),modals:[]})}function X(o={}){let{dialogs:t=[],selectId:a=l=>`${l}-${~~(Math.random()*1e4)}`}=o;return l=>(l.defineActions(P),l.dispatch((0,d.withAll)(W(V(t)),(0,d.withRootExtension)("piral-modals",h))),(f,r)=>{let s=r.name;return{showModal(n,c){let m=(0,d.buildName)(s,n),u={id:a(m),name:m,alternative:n,options:c,close(){setTimeout(()=>l.closeModal(u),0)}};return l.openModal(u),u.close},registerModal(n,c,m,u={}){let B=(0,d.buildName)(s,n);return l.registerModal(B,{pilet:s,name:n,component:(0,d.withApi)(l,c,f,"modal"),defaults:m,layout:u}),()=>f.unregisterModal(n)},unregisterModal(n){let c=(0,d.buildName)(s,n);l.unregisterModal(c)}}})}return Y;})();
|
package/src/Modals.tsx
CHANGED
|
@@ -28,21 +28,19 @@ export const Modals: React.FC = () => {
|
|
|
28
28
|
const reg = modals[n.name] || findModal(modals, n.alternative);
|
|
29
29
|
const Component = reg && reg.component;
|
|
30
30
|
const defaults = reg && reg.defaults;
|
|
31
|
+
const options = {
|
|
32
|
+
...defaults,
|
|
33
|
+
...n.options,
|
|
34
|
+
};
|
|
31
35
|
return (
|
|
32
36
|
Component && (
|
|
33
|
-
<PiralModalsDialog {...n} key={n.name}>
|
|
34
|
-
<Component
|
|
35
|
-
onClose={n.close}
|
|
36
|
-
options={{
|
|
37
|
-
...defaults,
|
|
38
|
-
...n.options,
|
|
39
|
-
}}
|
|
40
|
-
/>
|
|
37
|
+
<PiralModalsDialog {...n} options={options} defaults={reg.defaults} layout={reg.layout} key={n.name}>
|
|
38
|
+
<Component onClose={n.close} options={options} />
|
|
41
39
|
</PiralModalsDialog>
|
|
42
40
|
)
|
|
43
41
|
);
|
|
44
42
|
})
|
|
45
|
-
.filter(
|
|
43
|
+
.filter(Boolean);
|
|
46
44
|
const open = children.length > 0;
|
|
47
45
|
|
|
48
46
|
return (
|
package/src/create.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ComponentType } from 'react';
|
|
|
3
3
|
import { withApi, buildName, PiralPlugin, Dict, withRootExtension, withAll, GlobalState } from 'piral-core';
|
|
4
4
|
import { DefaultHost, DefaultDialog } from './default';
|
|
5
5
|
import { Modals } from './Modals';
|
|
6
|
-
import { PiletModalsApi, ModalRegistration, BareModalComponentProps } from './types';
|
|
6
|
+
import { PiletModalsApi, ModalRegistration, BareModalComponentProps, ModalLayoutOptions } from './types';
|
|
7
7
|
|
|
8
8
|
export interface InitialModalDialog {
|
|
9
9
|
/**
|
|
@@ -17,7 +17,11 @@ export interface InitialModalDialog {
|
|
|
17
17
|
/**
|
|
18
18
|
* The default options for the modal dialog.
|
|
19
19
|
*/
|
|
20
|
-
defaults
|
|
20
|
+
defaults?: any;
|
|
21
|
+
/**
|
|
22
|
+
* The layout options for the modal dialog.
|
|
23
|
+
*/
|
|
24
|
+
layout?: ModalLayoutOptions;
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
/**
|
|
@@ -40,12 +44,13 @@ export interface ModalsConfig {
|
|
|
40
44
|
function getModalDialogs(dialogs: Array<InitialModalDialog>) {
|
|
41
45
|
const modals: Dict<ModalRegistration> = {};
|
|
42
46
|
|
|
43
|
-
for (const { name, component, defaults } of dialogs) {
|
|
47
|
+
for (const { name, component, defaults, layout = {} } of dialogs) {
|
|
44
48
|
modals[`global-${name}`] = {
|
|
45
49
|
pilet: undefined,
|
|
46
50
|
name,
|
|
47
51
|
component,
|
|
48
52
|
defaults,
|
|
53
|
+
layout,
|
|
49
54
|
};
|
|
50
55
|
}
|
|
51
56
|
|
|
@@ -97,13 +102,14 @@ export function createModalsApi(config: ModalsConfig = {}): PiralPlugin<PiletMod
|
|
|
97
102
|
context.openModal(dialog);
|
|
98
103
|
return dialog.close;
|
|
99
104
|
},
|
|
100
|
-
registerModal(name, arg, defaults) {
|
|
105
|
+
registerModal(name, arg, defaults, layout = {}) {
|
|
101
106
|
const id = buildName(pilet, name);
|
|
102
107
|
context.registerModal(id, {
|
|
103
108
|
pilet,
|
|
104
109
|
name,
|
|
105
110
|
component: withApi(context, arg, api, 'modal'),
|
|
106
111
|
defaults,
|
|
112
|
+
layout,
|
|
107
113
|
});
|
|
108
114
|
return () => api.unregisterModal(name);
|
|
109
115
|
},
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentType } from 'react';
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import type {
|
|
3
3
|
Dict,
|
|
4
4
|
WrappedComponent,
|
|
@@ -75,9 +75,31 @@ export interface ModalsHostProps {
|
|
|
75
75
|
* Callback to invoke closing the modal dialog.
|
|
76
76
|
*/
|
|
77
77
|
close(): void;
|
|
78
|
+
/**
|
|
79
|
+
* The dialogs to display.
|
|
80
|
+
*/
|
|
81
|
+
children?: ReactNode;
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
export interface ModalsDialogProps extends OpenModalDialog {
|
|
84
|
+
export interface ModalsDialogProps extends OpenModalDialog {
|
|
85
|
+
/**
|
|
86
|
+
* The layout options given for the current dialog.
|
|
87
|
+
*/
|
|
88
|
+
layout: ModalLayoutOptions;
|
|
89
|
+
/**
|
|
90
|
+
* The provided default options.
|
|
91
|
+
*/
|
|
92
|
+
defaults: any;
|
|
93
|
+
/**
|
|
94
|
+
* The content of the dialog to display.
|
|
95
|
+
*/
|
|
96
|
+
children?: ReactNode;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The options provided for the dialog layout.
|
|
101
|
+
*/
|
|
102
|
+
export interface ModalLayoutOptions {}
|
|
81
103
|
|
|
82
104
|
/**
|
|
83
105
|
* The error used when a registered modal dialog crashed.
|
|
@@ -139,6 +161,7 @@ export interface ModalRegistration extends BaseRegistration {
|
|
|
139
161
|
name: string;
|
|
140
162
|
component: WrappedComponent<ModalComponentProps<any>>;
|
|
141
163
|
defaults: any;
|
|
164
|
+
layout: ModalLayoutOptions;
|
|
142
165
|
}
|
|
143
166
|
|
|
144
167
|
export interface BaseModalOptions {}
|
|
@@ -170,11 +193,13 @@ export interface PiletModalsApi {
|
|
|
170
193
|
* @param name The name of the modal to register.
|
|
171
194
|
* @param Component The component to render the page.
|
|
172
195
|
* @param defaults Optionally, sets the default values for the inserted options.
|
|
196
|
+
* @param layout Optionally, sets the layout options for the dialog wrapper.
|
|
173
197
|
*/
|
|
174
198
|
registerModal<T>(
|
|
175
199
|
name: T extends string ? T : string,
|
|
176
200
|
Component: AnyComponent<ModalComponentProps<T>>,
|
|
177
201
|
defaults?: ModalOptions<T>,
|
|
202
|
+
layout?: ModalLayoutOptions,
|
|
178
203
|
): RegistrationDisposer;
|
|
179
204
|
/**
|
|
180
205
|
* Unregisters a modal by its name.
|