piral-modals 0.15.0-alpha.4345 → 0.15.0-alpha.4399
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/default.js +1 -1
- package/esm/default.js.map +1 -1
- package/lib/default.js +1 -1
- package/lib/default.js.map +1 -1
- package/package.json +3 -3
- package/piral-modals.min.js +1 -1
- package/src/Modals.test.tsx +151 -85
- package/src/default.tsx +1 -1
package/esm/default.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { defaultRender } from 'piral-core';
|
|
3
|
-
export const DefaultHost = (props) => (React.createElement("div", { className: "piral-modals-host"
|
|
3
|
+
export const DefaultHost = (props) => (React.createElement("div", { className: "piral-modals-host" }, props.open && React.createElement("div", { className: "piral-modals-overlay" }, props.children)));
|
|
4
4
|
export const DefaultDialog = (props) => defaultRender(props.children);
|
|
5
5
|
//# sourceMappingURL=default.js.map
|
package/esm/default.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,CAAC,MAAM,WAAW,GAA8B,CAAC,KAAK,EAAE,EAAE,CAAC,CAC/D,6BAAK,SAAS,EAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,CAAC,MAAM,WAAW,GAA8B,CAAC,KAAK,EAAE,EAAE,CAAC,CAC/D,6BAAK,SAAS,EAAC,mBAAmB,IAC/B,KAAK,CAAC,IAAI,IAAI,6BAAK,SAAS,EAAC,sBAAsB,IAAE,KAAK,CAAC,QAAQ,CAAO,CACvE,CACP,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAgC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC"}
|
package/lib/default.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DefaultDialog = exports.DefaultHost = void 0;
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const piral_core_1 = require("piral-core");
|
|
6
|
-
const DefaultHost = (props) => (React.createElement("div", { className: "piral-modals-host"
|
|
6
|
+
const DefaultHost = (props) => (React.createElement("div", { className: "piral-modals-host" }, props.open && React.createElement("div", { className: "piral-modals-overlay" }, props.children)));
|
|
7
7
|
exports.DefaultHost = DefaultHost;
|
|
8
8
|
const DefaultDialog = (props) => (0, piral_core_1.defaultRender)(props.children);
|
|
9
9
|
exports.DefaultDialog = DefaultDialog;
|
package/lib/default.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAA2C;AAGpC,MAAM,WAAW,GAA8B,CAAC,KAAK,EAAE,EAAE,CAAC,CAC/D,6BAAK,SAAS,EAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAA2C;AAGpC,MAAM,WAAW,GAA8B,CAAC,KAAK,EAAE,EAAE,CAAC,CAC/D,6BAAK,SAAS,EAAC,mBAAmB,IAC/B,KAAK,CAAC,IAAI,IAAI,6BAAK,SAAS,EAAC,sBAAsB,IAAE,KAAK,CAAC,QAAQ,CAAO,CACvE,CACP,CAAC;AAJW,QAAA,WAAW,eAItB;AAEK,MAAM,aAAa,GAAgC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAAtF,QAAA,aAAa,iBAAyE"}
|
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.4399",
|
|
4
4
|
"description": "Plugin for the display of modal dialogs in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@types/react": "^18.0.0",
|
|
65
|
-
"piral-core": "0.15.0-alpha.
|
|
65
|
+
"piral-core": "0.15.0-alpha.4399",
|
|
66
66
|
"react": "^18.0.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"piral-core": "0.14.x || 0.15.x",
|
|
70
70
|
"react": ">=16.8.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "34be0cac6948a92981ab4994b01b34e44462e7a0"
|
|
73
73
|
}
|
package/piral-modals.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var piralModals=(()=>{var
|
|
1
|
+
var piralModals=(()=>{var N=Object.create;var y=Object.defineProperty,T=Object.defineProperties,$=Object.getOwnPropertyDescriptor,k=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)=>T(o,k(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,l))||a.enumerable});return o},M=o=>j(S(y(o!=null?N(K(o)):{},"default",o&&o.__esModule&&"default"in o?{get:()=>o.default,enumerable:!0}:{value:o,enumerable:!0})),o);var Z={};v(Z,{Modals:()=>h,PiralModalsDialog:()=>b,PiralModalsHost:()=>R,createModalsApi:()=>Y});var P={};v(P,{closeModal:()=>z,openModal:()=>q,registerModal:()=>J,unregisterModal:()=>Q});var p=M(g("piral-core"));function q(o,t){o.dispatch(a=>i(e({},a),{modals:(0,p.prependItem)(a.modals,t)}))}function z(o,t){o.dispatch(a=>i(e({},a),{modals:(0,p.excludeOn)(a.modals,l=>l.id===t.id)}))}function J(o,t,a){o.dispatch(l=>i(e({},l),{registry:i(e({},l.registry),{modals:(0,p.withKey)(l.registry.modals,t,a)})}))}function Q(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"},o.open&&x.createElement("div",{className:"piral-modals-overlay"},o.children)),B=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 U(o){o.forEach(t=>t.close())}function V(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=()=>U(t),l=t.map(r=>{let s=o[r.name]||V(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 W(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 X(o){return t=>i(e({},t),{components:e({ModalsHost:I,ModalsDialog:B},t.components),registry:i(e({},t.registry),{modals:o}),modals:[]})}function Y(o={}){let{dialogs:t=[],selectId:a=l=>`${l}-${~~(Math.random()*1e4)}`}=o;return l=>(l.defineActions(P),l.dispatch((0,d.withAll)(X(W(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 F=(0,d.buildName)(s,n);return l.registerModal(F,{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 Z;})();
|
package/src/Modals.test.tsx
CHANGED
|
@@ -1,127 +1,193 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import create from 'zustand';
|
|
3
|
+
import { StateContext } from 'piral-core';
|
|
4
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
5
|
import { Modals } from './Modals';
|
|
4
|
-
import { PiralModalsHost } from './components';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
function createMockContainer(registeredModals: Record<string, any>, openModals: Array<any>) {
|
|
8
|
+
const state = create(() => ({
|
|
9
|
+
components: {
|
|
10
|
+
ModalsHost: ({ open, children, close }) => (
|
|
11
|
+
<div role="host">
|
|
12
|
+
{open && (
|
|
13
|
+
<div role="overlay">
|
|
14
|
+
<button role="close" onClick={close}>
|
|
15
|
+
Close
|
|
16
|
+
</button>
|
|
17
|
+
{children}
|
|
18
|
+
</div>
|
|
19
|
+
)}
|
|
20
|
+
</div>
|
|
21
|
+
),
|
|
22
|
+
},
|
|
23
|
+
registry: {
|
|
24
|
+
modals: registeredModals,
|
|
25
|
+
},
|
|
26
|
+
modals: openModals,
|
|
27
|
+
}));
|
|
28
|
+
return {
|
|
29
|
+
context: {
|
|
30
|
+
on: jest.fn(),
|
|
31
|
+
off: jest.fn(),
|
|
32
|
+
emit: jest.fn(),
|
|
33
|
+
defineActions() {},
|
|
34
|
+
converters: {},
|
|
35
|
+
readState(select) {
|
|
36
|
+
return select(state.getState());
|
|
37
|
+
},
|
|
38
|
+
state,
|
|
39
|
+
dispatch(update) {
|
|
40
|
+
state.setState(update(state.getState()));
|
|
41
|
+
},
|
|
42
|
+
} as any,
|
|
43
|
+
api: {} as any,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
21
46
|
|
|
22
47
|
describe('Modals Component Shell Module', () => {
|
|
23
48
|
it('Should display nothing is nothing is there', () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
49
|
+
const { context } = createMockContainer({}, []);
|
|
50
|
+
const node = render(
|
|
51
|
+
<StateContext.Provider value={context}>
|
|
52
|
+
<Modals />
|
|
53
|
+
</StateContext.Provider>,
|
|
54
|
+
);
|
|
55
|
+
expect(node.queryByRole('overlay')).toBe(null);
|
|
28
56
|
});
|
|
29
57
|
|
|
30
58
|
it('Should display something if something is there and wanted', () => {
|
|
31
|
-
|
|
32
|
-
foo: {
|
|
33
|
-
component: () => <div />,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
state.modals = [
|
|
59
|
+
const { context } = createMockContainer(
|
|
37
60
|
{
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
foo: {
|
|
62
|
+
component: () => <div />,
|
|
63
|
+
},
|
|
40
64
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
[
|
|
66
|
+
{
|
|
67
|
+
name: 'foo',
|
|
68
|
+
options: {},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
);
|
|
72
|
+
const node = render(
|
|
73
|
+
<StateContext.Provider value={context}>
|
|
74
|
+
<Modals />
|
|
75
|
+
</StateContext.Provider>,
|
|
76
|
+
);
|
|
77
|
+
expect(node.queryByRole('overlay')).not.toBe(null);
|
|
44
78
|
});
|
|
45
79
|
|
|
46
80
|
it('Should display nothing if something is there and not wanted', () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
81
|
+
const { context } = createMockContainer(
|
|
82
|
+
{
|
|
83
|
+
foo: {
|
|
84
|
+
component: () => <div />,
|
|
85
|
+
},
|
|
50
86
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const node =
|
|
54
|
-
|
|
87
|
+
[],
|
|
88
|
+
);
|
|
89
|
+
const node = render(
|
|
90
|
+
<StateContext.Provider value={context}>
|
|
91
|
+
<Modals />
|
|
92
|
+
</StateContext.Provider>,
|
|
93
|
+
);
|
|
94
|
+
expect(node.queryByRole('overlay')).toBe(null);
|
|
55
95
|
});
|
|
56
96
|
|
|
57
97
|
it('Should display something if something is there and wanted even indirectly', () => {
|
|
58
|
-
|
|
59
|
-
'abc:foo': {
|
|
60
|
-
component: () => <div />,
|
|
61
|
-
name: 'bar',
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
state.modals = [
|
|
98
|
+
const { context } = createMockContainer(
|
|
65
99
|
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
100
|
+
'abc:foo': {
|
|
101
|
+
component: () => <div />,
|
|
102
|
+
name: 'bar',
|
|
103
|
+
},
|
|
69
104
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
105
|
+
[
|
|
106
|
+
{
|
|
107
|
+
name: 'xyz:foo',
|
|
108
|
+
alternative: 'bar',
|
|
109
|
+
options: {},
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
);
|
|
113
|
+
const node = render(
|
|
114
|
+
<StateContext.Provider value={context}>
|
|
115
|
+
<Modals />
|
|
116
|
+
</StateContext.Provider>,
|
|
117
|
+
);
|
|
118
|
+
expect(node.queryByRole('overlay')).not.toBe(null);
|
|
73
119
|
});
|
|
74
120
|
|
|
75
121
|
it('Should display nothing is something is there and not wanted with indirection', () => {
|
|
76
|
-
|
|
77
|
-
'abc:foo': {
|
|
78
|
-
component: () => <div />,
|
|
79
|
-
name: 'qxz',
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
state.modals = [
|
|
122
|
+
const { context } = createMockContainer(
|
|
83
123
|
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
124
|
+
'abc:foo': {
|
|
125
|
+
component: () => <div />,
|
|
126
|
+
name: 'qxz',
|
|
127
|
+
},
|
|
87
128
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
129
|
+
[
|
|
130
|
+
{
|
|
131
|
+
name: 'xyz:foo',
|
|
132
|
+
alternative: 'bar',
|
|
133
|
+
options: {},
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
);
|
|
137
|
+
const node = render(
|
|
138
|
+
<StateContext.Provider value={context}>
|
|
139
|
+
<Modals />
|
|
140
|
+
</StateContext.Provider>,
|
|
141
|
+
);
|
|
142
|
+
expect(node.queryByRole('overlay')).toBe(null);
|
|
91
143
|
});
|
|
92
144
|
|
|
93
145
|
it('Should display nothing if nothing is available even if wanted', () => {
|
|
94
|
-
|
|
95
|
-
state.modals = [
|
|
146
|
+
const { context } = createMockContainer({}, [
|
|
96
147
|
{
|
|
97
148
|
name: 'foo',
|
|
98
149
|
options: {},
|
|
99
150
|
},
|
|
100
|
-
];
|
|
101
|
-
const node =
|
|
102
|
-
|
|
151
|
+
]);
|
|
152
|
+
const node = render(
|
|
153
|
+
<StateContext.Provider value={context}>
|
|
154
|
+
<Modals />
|
|
155
|
+
</StateContext.Provider>,
|
|
156
|
+
);
|
|
157
|
+
expect(node.queryByRole('overlay')).toBe(null);
|
|
103
158
|
});
|
|
104
159
|
|
|
105
160
|
it('Should close all available dialogs', () => {
|
|
106
161
|
const close = jest.fn();
|
|
107
|
-
|
|
108
|
-
state.modals = [
|
|
109
|
-
{
|
|
110
|
-
name: 'foo',
|
|
111
|
-
options: {},
|
|
112
|
-
close,
|
|
113
|
-
},
|
|
162
|
+
const { context } = createMockContainer(
|
|
114
163
|
{
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
164
|
+
foo: {
|
|
165
|
+
component: () => <div />,
|
|
166
|
+
},
|
|
167
|
+
bar: {
|
|
168
|
+
component: () => <div />,
|
|
169
|
+
},
|
|
118
170
|
},
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
171
|
+
[
|
|
172
|
+
{
|
|
173
|
+
name: 'foo',
|
|
174
|
+
options: {},
|
|
175
|
+
close,
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'bar',
|
|
179
|
+
options: {},
|
|
180
|
+
close,
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
);
|
|
184
|
+
const node = render(
|
|
185
|
+
<StateContext.Provider value={context}>
|
|
186
|
+
<Modals />
|
|
187
|
+
</StateContext.Provider>,
|
|
188
|
+
);
|
|
123
189
|
expect(close).toHaveBeenCalledTimes(0);
|
|
124
|
-
|
|
190
|
+
fireEvent.click(node.getByRole('close'));
|
|
125
191
|
expect(close).toHaveBeenCalledTimes(2);
|
|
126
192
|
});
|
|
127
193
|
});
|
package/src/default.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { defaultRender } from 'piral-core';
|
|
|
3
3
|
import { ModalsHostProps, ModalsDialogProps } from './types';
|
|
4
4
|
|
|
5
5
|
export const DefaultHost: React.FC<ModalsHostProps> = (props) => (
|
|
6
|
-
<div className="piral-modals-host"
|
|
6
|
+
<div className="piral-modals-host">
|
|
7
7
|
{props.open && <div className="piral-modals-overlay">{props.children}</div>}
|
|
8
8
|
</div>
|
|
9
9
|
);
|