ember-promise-modals 4.0.0 → 5.0.0
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/README.md +27 -58
- package/addon-main.cjs +4 -0
- package/dist/_app_/components/epm-modal-container.js +1 -0
- package/dist/_app_/components/epm-modal.js +1 -0
- package/dist/_app_/helpers/open-modal.js +1 -0
- package/dist/_app_/services/modals.js +1 -0
- package/{addon/styles/ember-promise-modals.css → dist/components/epm-modal-container.css} +17 -15
- package/dist/components/epm-modal-container.js +14 -0
- package/dist/components/epm-modal-container.js.map +1 -0
- package/{addon/components/modal.js → dist/components/epm-modal.js} +26 -48
- package/dist/components/epm-modal.js.map +1 -0
- package/{addon → dist}/helpers/open-modal.js +13 -12
- package/dist/helpers/open-modal.js.map +1 -0
- package/{addon → dist}/modal.js +12 -36
- package/dist/modal.js.map +1 -0
- package/{addon → dist}/services/modals.js +10 -22
- package/dist/services/modals.js.map +1 -0
- package/{addon-test-support → dist/test-support}/index.js +4 -7
- package/dist/test-support/index.js.map +1 -0
- package/package.json +54 -82
- package/.prettierignore +0 -27
- package/.release-it.js +0 -20
- package/CHANGELOG.md +0 -205
- package/MIGRATION.md +0 -80
- package/addon/components/modal-container.js +0 -11
- package/addon/templates/components/modal-container.hbs +0 -12
- package/addon/templates/components/modal.hbs +0 -6
- package/app/components/epm-modal-container.js +0 -1
- package/app/components/epm-modal.js +0 -1
- package/app/helpers/open-modal.js +0 -1
- package/app/services/modals.js +0 -1
- package/config/environment.js +0 -5
- package/index.js +0 -45
- package/pnpm-lock.yaml +0 -14235
- package/renovate.json +0 -29
package/README.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
<p align="center"><img src="./
|
|
1
|
+
<p align="center"><img src="./packages/test-app/public/ember-promise-modals-logo.svg" role="presentation" alt="" width="600" height="400" /></p>
|
|
2
2
|
|
|
3
3
|
# ember-promise-modals
|
|
4
4
|
|
|
5
5
|
The better way to handle modals in your Ember.js apps.
|
|
6
6
|
|
|
7
|
+
> [!NOTE]
|
|
8
|
+
> ember-promise-modals was written and is maintained by [Mainmatter](https://mainmatter.com) and contributors.
|
|
9
|
+
> We offer consulting, training, and team augmentation for Ember.js – check out our [website](https://mainmatter.com/ember-consulting/) to learn more!
|
|
10
|
+
|
|
7
11
|
## Compatibility
|
|
8
12
|
|
|
9
|
-
- Ember.js v3.
|
|
10
|
-
- Ember CLI v3.
|
|
11
|
-
- Node.js
|
|
13
|
+
- Ember.js v3.28 or above
|
|
14
|
+
- Ember CLI v3.28 or above
|
|
15
|
+
- Node.js v16 or above
|
|
12
16
|
|
|
13
17
|
## Installation
|
|
14
18
|
|
|
@@ -24,17 +28,18 @@ To use EPM in your project, add the target for the modals to your `application.h
|
|
|
24
28
|
<EpmModalContainer />
|
|
25
29
|
```
|
|
26
30
|
|
|
27
|
-
Then you can
|
|
31
|
+
Then you can inject the `modals` [service](https://guides.emberjs.com/release/services/#toc_accessing-services) wherever you need and call its `open` method with a component class to render it as a modal.
|
|
28
32
|
|
|
29
33
|
```js
|
|
30
34
|
import { inject as service } from '@ember/service';
|
|
35
|
+
import ConfirmationModal from 'my-app/components/confirmation-modal';
|
|
31
36
|
|
|
32
37
|
export default class extends Component {
|
|
33
38
|
@service modals;
|
|
34
39
|
|
|
35
40
|
@action
|
|
36
41
|
async handleOpenModal() {
|
|
37
|
-
let modal = this.modals.open(
|
|
42
|
+
let modal = this.modals.open(ConfirmationModal);
|
|
38
43
|
|
|
39
44
|
// the instance acts as a promise that resolves with anything passed to the @close function
|
|
40
45
|
modal.then(results => {
|
|
@@ -56,28 +61,12 @@ export default class extends Component {
|
|
|
56
61
|
</button>
|
|
57
62
|
```
|
|
58
63
|
|
|
59
|
-
### Embroider Optimized Apps
|
|
60
|
-
|
|
61
|
-
If your application uses [Embroider](https://github.com/embroider-build/embroider), you need to pass the component class to the `open` method instead of just the modals name. This will become the default behavior in the future.
|
|
62
|
-
|
|
63
|
-
```js
|
|
64
|
-
import ConfirmationModal from '../components/confirmation-modal';
|
|
65
|
-
|
|
66
|
-
export default class extends Component {
|
|
67
|
-
//...
|
|
68
|
-
@action
|
|
69
|
-
handleOpenModal() {
|
|
70
|
-
this.modals.open(ConfirmationModal);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
```
|
|
74
|
-
|
|
75
64
|
### Passing data to the rendered component
|
|
76
65
|
|
|
77
66
|
You can pass custom data into your rendered template like so:
|
|
78
67
|
|
|
79
68
|
```js
|
|
80
|
-
this.modals.open(
|
|
69
|
+
this.modals.open(FilePreviewModal, {
|
|
81
70
|
fileUrl: this.fileUrl,
|
|
82
71
|
});
|
|
83
72
|
```
|
|
@@ -112,12 +101,12 @@ this.args.close(results); // or this.close() in classic components
|
|
|
112
101
|
This addon comes with a `{{open-modal}}` template helper which can be used to trigger modals from any templates. It accepts the similar arguments as the `open` method. It can be used to open a modal in a route, closing it automatically when navigating elsewhere.
|
|
113
102
|
|
|
114
103
|
```hbs
|
|
115
|
-
{{open-modal
|
|
104
|
+
{{open-modal this.ConfirmationModalComponent (hash fileUrl=this.fileUrl) close=(fn this.save results)}}
|
|
116
105
|
```
|
|
117
106
|
|
|
118
107
|
Positional arguments mimick the `open()` method on the service:
|
|
119
108
|
|
|
120
|
-
- `
|
|
109
|
+
- `componentClass`: An imported component class of the modal to render
|
|
121
110
|
- `data`: Pass additional context to the modal,
|
|
122
111
|
- `options`: Pass additional options to the modal
|
|
123
112
|
|
|
@@ -144,7 +133,7 @@ a custom `className` can be handed to the `.open()` method.
|
|
|
144
133
|
|
|
145
134
|
```js
|
|
146
135
|
this.modals.open(
|
|
147
|
-
|
|
136
|
+
FilePreviwModal,
|
|
148
137
|
{
|
|
149
138
|
fileUrl: this.fileUrl,
|
|
150
139
|
},
|
|
@@ -201,38 +190,14 @@ The CSS animations which are applied by the custom CSS class _must_ end in
|
|
|
201
190
|
|
|
202
191
|
#### Examples
|
|
203
192
|
|
|
204
|
-
Examples for custom animations and how to apply them can be found in the
|
|
193
|
+
Examples for custom animations and how to apply them can be found in the addon's
|
|
205
194
|
dummy application.
|
|
206
195
|
|
|
207
|
-
See [the application.js controller](./
|
|
208
|
-
for how the modals are
|
|
209
|
-
[app.css](./
|
|
196
|
+
See [the application.js controller](./packages/test-app/app/controllers/application.js)
|
|
197
|
+
for how the modals are opened in your JavaScript actions and look at
|
|
198
|
+
[app.css](./packages/test-app/app/styles/app.css) for the style definition of these
|
|
210
199
|
custom animations.
|
|
211
200
|
|
|
212
|
-
### CSS Variables
|
|
213
|
-
|
|
214
|
-
The addons CSS is run through PostCSS by default, which will create static
|
|
215
|
-
fallbacks for all custom properties using their defaults.
|
|
216
|
-
|
|
217
|
-
If your application uses PostCSS by itself, you can set `excludeCSS` to `true`
|
|
218
|
-
inside your `ember-cli-build.js`:
|
|
219
|
-
|
|
220
|
-
```js
|
|
221
|
-
let app = new EmberAddon(defaults, {
|
|
222
|
-
// Add options here
|
|
223
|
-
'ember-promise-modals': {
|
|
224
|
-
excludeCSS: true,
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
Done that, you can use [postcss-import](https://github.com/postcss/postcss-import)
|
|
230
|
-
to import the uncompiled addon styles in your projects `app/styles/app.css`:
|
|
231
|
-
|
|
232
|
-
```css
|
|
233
|
-
@import 'ember-promise-modals';
|
|
234
|
-
```
|
|
235
|
-
|
|
236
201
|
## Accessibility
|
|
237
202
|
|
|
238
203
|
User can press the <kbd>Esc</kbd> key to close the modal.
|
|
@@ -266,7 +231,7 @@ Example for local Focus Trap option, when opening a specific modal:
|
|
|
266
231
|
|
|
267
232
|
```js
|
|
268
233
|
this.modals.open(
|
|
269
|
-
|
|
234
|
+
FilePreviewModal,
|
|
270
235
|
{ fileUrl: this.fileUrl },
|
|
271
236
|
{
|
|
272
237
|
focusTrapOptions: {
|
|
@@ -291,7 +256,7 @@ Or when opening a modal:
|
|
|
291
256
|
|
|
292
257
|
```js
|
|
293
258
|
this.modals.open(
|
|
294
|
-
|
|
259
|
+
FilePreviewModal,
|
|
295
260
|
{ fileUrl: this.fileUrl },
|
|
296
261
|
{
|
|
297
262
|
focusTrapOptions: null,
|
|
@@ -318,7 +283,10 @@ module('Application | ...', function (hooks) {
|
|
|
318
283
|
|
|
319
284
|
## Migration guide
|
|
320
285
|
|
|
321
|
-
See the [Migration](MIGRATION.md) guide for details
|
|
286
|
+
See the [Migration](MIGRATION.md) guide for details:
|
|
287
|
+
|
|
288
|
+
- From 0.x.x to 1.x.x about the replacement of ember-animated powered animations with CSS-based animations.
|
|
289
|
+
- From v4.x.x to v5.x.x about the removal of the PostCSS process.
|
|
322
290
|
|
|
323
291
|
## Contributing
|
|
324
292
|
|
|
@@ -326,4 +294,5 @@ See the [Contributing](CONTRIBUTING.md) guide for details.
|
|
|
326
294
|
|
|
327
295
|
## License
|
|
328
296
|
|
|
329
|
-
|
|
297
|
+
ember-promise-modals is developed by and © Mainmatter GmbH and contributors. It
|
|
298
|
+
is released under the [MIT License](LICENSE.md).
|
package/addon-main.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "ember-promise-modals/components/epm-modal-container";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "ember-promise-modals/components/epm-modal";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "ember-promise-modals/helpers/open-modal";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "ember-promise-modals/services/modals";
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
@layer ember-promise-modals {
|
|
2
|
+
:root {
|
|
3
|
+
/* The named -duration and -delay variables will be lowered to near zero when using the setupPromiseModals test helper */
|
|
4
|
+
--epm-animation-backdrop-in-duration: 0.3s;
|
|
5
|
+
--epm-animation-backdrop-out-duration: 0.18s;
|
|
6
|
+
--epm-animation-modal-in-duration: 0.3s;
|
|
7
|
+
--epm-animation-modal-out-duration: 0.18s;
|
|
8
|
+
--epm-animation-backdrop-in-delay: 0s;
|
|
9
|
+
--epm-animation-backdrop-out-delay: 0s;
|
|
10
|
+
--epm-animation-modal-in-delay: 0s;
|
|
11
|
+
--epm-animation-modal-out-delay: 0s;
|
|
12
|
+
--epm-animation-backdrop-in: var(--epm-animation-backdrop-in-duration) ease var(--epm-animation-backdrop-in-delay) forwards epm-backdrop-in;
|
|
13
|
+
--epm-animation-backdrop-out: var(--epm-animation-backdrop-out-duration) ease var(--epm-animation-backdrop-out-delay) forwards epm-backdrop-out;
|
|
14
|
+
--epm-animation-modal-in: var(--epm-animation-modal-in-duration) ease-out var(--epm-animation-modal-in-delay) forwards epm-modal-in;
|
|
15
|
+
--epm-animation-modal-out: var(--epm-animation-modal-out-duration) ease-out var(--epm-animation-modal-out-delay) forwards epm-modal-out;
|
|
16
|
+
--epm-backdrop-background: #2d3748CD;
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
@media (prefers-reduced-motion: reduce) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Component, { setComponentTemplate } from '@ember/component';
|
|
2
|
+
import { inject } from '@ember/service';
|
|
3
|
+
import './epm-modal-container.css';
|
|
4
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
5
|
+
|
|
6
|
+
var TEMPLATE = precompileTemplate("{{#each this.modals._stack as |modal index|}}\n <div\n class=\"epm-backdrop {{if modal.isClosing \"epm-out\"}}\"\n tabindex=\"-1\"\n role=\"presentation\"\n aria-hidden=\"true\"\n data-test-epm-backdrop=\"{{index}}\"\n />\n <div class=\"epm-modal-container\">\n <EpmModal @modal={{modal}} data-test-epm-modal=\"{{index}}\" />\n </div>\n{{/each}}");
|
|
7
|
+
|
|
8
|
+
var epmModalContainer = setComponentTemplate(TEMPLATE, Component.extend({
|
|
9
|
+
tagName: '',
|
|
10
|
+
modals: inject()
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
export { epmModalContainer as default };
|
|
14
|
+
//# sourceMappingURL=epm-modal-container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epm-modal-container.js","sources":["../../src/components/epm-modal-container.hbs","../../src/components/epm-modal-container.js"],"sourcesContent":["import { precompileTemplate } from \"@ember/template-compilation\";\nexport default precompileTemplate(\"{{#each this.modals._stack as |modal index|}}\\n <div\\n class=\\\"epm-backdrop {{if modal.isClosing \\\"epm-out\\\"}}\\\"\\n tabindex=\\\"-1\\\"\\n role=\\\"presentation\\\"\\n aria-hidden=\\\"true\\\"\\n data-test-epm-backdrop=\\\"{{index}}\\\"\\n />\\n <div class=\\\"epm-modal-container\\\">\\n <EpmModal @modal={{modal}} data-test-epm-modal=\\\"{{index}}\\\" />\\n </div>\\n{{/each}}\")","import Component from '@ember/component';\nimport { inject as service } from '@ember/service';\n\nimport './epm-modal-container.css';\n\nexport default Component.extend({\n tagName: '',\n\n modals: service(),\n});\n"],"names":["setComponentTemplate","TEMPLATE","Component","extend","tagName","modals","service"],"mappings":";;;;;AACA,eAAe,kBAAkB,CAAC,iXAAiX;;ACInZ,wBAAAA,oBAAA,CAAAC,QAAA,EAAeC,SAAS,CAACC,MAAM,CAAC;AAC9BC,EAAAA,OAAO,EAAE,EAAE;EAEXC,MAAM,EAAEC,MAAO,EAAC;AAClB,CAAC,CAAC,CAAA;;;;"}
|
|
@@ -1,98 +1,83 @@
|
|
|
1
|
-
import Component from '@ember/component';
|
|
1
|
+
import Component, { setComponentTemplate } from '@ember/component';
|
|
2
2
|
import { set } from '@ember/object';
|
|
3
3
|
import { readOnly } from '@ember/object/computed';
|
|
4
4
|
import { guidFor } from '@ember/object/internals';
|
|
5
|
-
import { inject
|
|
6
|
-
|
|
5
|
+
import { inject } from '@ember/service';
|
|
7
6
|
import { createFocusTrap } from 'focus-trap';
|
|
7
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export default Component.extend({
|
|
12
|
-
layout,
|
|
9
|
+
var TEMPLATE = precompileTemplate("{{!-- template-lint-disable no-action --}}\n<div id={{this.modalElementId}} class=\"epm-modal {{this.optionsClassName}} {{this.animatingClass}}\">\n {{#let (component (ensure-safe-component @modal._componentClass) data=@modal._data close=(action \"close\")) as |ModalComponent|}}\n <ModalComponent />\n {{/let}}\n</div>");
|
|
13
10
|
|
|
11
|
+
var epmModal = setComponentTemplate(TEMPLATE, Component.extend({
|
|
14
12
|
tagName: '',
|
|
15
13
|
outAnimationClass: 'epm-out',
|
|
16
14
|
animatingClass: '',
|
|
17
|
-
|
|
18
|
-
modals: service(),
|
|
19
|
-
|
|
15
|
+
modals: inject(),
|
|
20
16
|
optionsClassName: readOnly('modal._options.className'),
|
|
21
|
-
|
|
22
17
|
modalElementId: null,
|
|
23
18
|
focusTrapOptions: null,
|
|
24
19
|
_animationEnd: null,
|
|
25
|
-
|
|
26
20
|
init() {
|
|
27
21
|
this._super(...arguments);
|
|
28
|
-
|
|
29
22
|
set(this, 'modalElementId', guidFor(this));
|
|
30
|
-
|
|
31
23
|
this.modal._componentInstance = this;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
let {
|
|
25
|
+
focusTrapOptions: globalFocusTrapOptions
|
|
26
|
+
} = this.modals;
|
|
27
|
+
let {
|
|
28
|
+
focusTrapOptions: localFocusTrapOptions
|
|
29
|
+
} = this.modal._options;
|
|
36
30
|
if (localFocusTrapOptions !== null) {
|
|
37
31
|
this.focusTrapOptions = localFocusTrapOptions || globalFocusTrapOptions;
|
|
38
32
|
}
|
|
39
33
|
},
|
|
40
|
-
|
|
41
34
|
didInsertElement() {
|
|
42
35
|
this._super(...arguments);
|
|
43
|
-
|
|
44
36
|
this._addFocusTrap();
|
|
45
37
|
this._addAnimationListeners();
|
|
46
38
|
|
|
47
39
|
// animating in starts when the element is added to the DOM. Inform the service about it.
|
|
48
40
|
this.modals._onModalAnimationStart();
|
|
49
41
|
},
|
|
50
|
-
|
|
51
42
|
willDestroyElement() {
|
|
52
43
|
this.destroyModal();
|
|
53
|
-
|
|
54
44
|
this._super(...arguments);
|
|
55
45
|
},
|
|
56
|
-
|
|
57
46
|
_getElement() {
|
|
58
47
|
return document.getElementById(this.modalElementId);
|
|
59
48
|
},
|
|
60
|
-
|
|
61
49
|
_addFocusTrap() {
|
|
62
50
|
let element = this._getElement();
|
|
63
|
-
|
|
64
51
|
if (!this.focusTrapOptions) {
|
|
65
52
|
return;
|
|
66
53
|
}
|
|
67
|
-
|
|
68
54
|
let options = {
|
|
69
55
|
...this.focusTrapOptions,
|
|
70
56
|
fallbackFocus: element,
|
|
71
57
|
onDeactivate: (...args) => {
|
|
72
58
|
this.focusTrapOptions.onDeactivate?.(...args);
|
|
73
|
-
|
|
74
59
|
if (this.isDestroyed || this.isDestroying) {
|
|
75
60
|
return;
|
|
76
61
|
}
|
|
77
|
-
|
|
78
62
|
this.closeModal();
|
|
79
|
-
}
|
|
63
|
+
}
|
|
80
64
|
};
|
|
81
|
-
|
|
82
65
|
this.focusTrap = createFocusTrap(element, options);
|
|
83
66
|
this.focusTrap.activate();
|
|
84
67
|
},
|
|
85
|
-
|
|
86
68
|
_removeFocusTrap(onDeactivate = this.focusTrapOptions?.onDeactivate) {
|
|
87
69
|
if (!this.focusTrap) {
|
|
88
70
|
return;
|
|
89
71
|
}
|
|
90
|
-
|
|
91
|
-
|
|
72
|
+
this.focusTrap.deactivate({
|
|
73
|
+
onDeactivate
|
|
74
|
+
});
|
|
92
75
|
},
|
|
93
|
-
|
|
94
76
|
_addAnimationListeners() {
|
|
95
|
-
this._animationEnd = ({
|
|
77
|
+
this._animationEnd = ({
|
|
78
|
+
target,
|
|
79
|
+
animationName
|
|
80
|
+
}) => {
|
|
96
81
|
// ignore animations bubbling up
|
|
97
82
|
if (target !== this._getElement()) {
|
|
98
83
|
return;
|
|
@@ -100,32 +85,26 @@ export default Component.extend({
|
|
|
100
85
|
|
|
101
86
|
// An animation has ended, inform the modals service
|
|
102
87
|
this.modals._onModalAnimationEnd();
|
|
103
|
-
|
|
104
88
|
let isOutAnimation = animationName.substring(animationName.length - 4) === '-out';
|
|
105
89
|
if (isOutAnimation) {
|
|
106
90
|
this.modal._remove();
|
|
107
91
|
}
|
|
108
92
|
};
|
|
109
|
-
|
|
110
93
|
let element = this._getElement();
|
|
111
94
|
if (element) {
|
|
112
95
|
element.addEventListener('animationend', this._animationEnd);
|
|
113
96
|
}
|
|
114
97
|
},
|
|
115
|
-
|
|
116
98
|
_removeAnimationListeners() {
|
|
117
99
|
if (!this._animationEnd) {
|
|
118
100
|
return;
|
|
119
101
|
}
|
|
120
|
-
|
|
121
102
|
let element = this._getElement();
|
|
122
103
|
if (element) {
|
|
123
104
|
element.removeEventListener('animationend', this._animationEnd);
|
|
124
105
|
}
|
|
125
|
-
|
|
126
106
|
this._animationEnd = null;
|
|
127
107
|
},
|
|
128
|
-
|
|
129
108
|
destroyModal() {
|
|
130
109
|
// Remove the focus trap without triggering the optional onDeactivate() hook
|
|
131
110
|
this._removeFocusTrap(null);
|
|
@@ -136,26 +115,25 @@ export default Component.extend({
|
|
|
136
115
|
// make sure that we remove the modal, also resolving the test waiter
|
|
137
116
|
this.modal._remove();
|
|
138
117
|
},
|
|
139
|
-
|
|
140
118
|
closeModal(result) {
|
|
141
119
|
if (this.animatingClass !== '') {
|
|
142
120
|
return;
|
|
143
121
|
}
|
|
144
|
-
|
|
145
122
|
this.modals._onModalAnimationStart();
|
|
146
123
|
|
|
147
124
|
// This triggers the out animation, which in turn will remove the modal after it completes
|
|
148
125
|
set(this, 'animatingClass', this.outAnimationClass);
|
|
149
|
-
|
|
150
126
|
this.modal._resolve(result);
|
|
151
127
|
},
|
|
152
|
-
|
|
153
128
|
actions: {
|
|
154
129
|
close(result) {
|
|
155
130
|
this.closeModal(result);
|
|
156
131
|
|
|
157
132
|
// Remove the focus trap, triggering the onDeactivate() hook
|
|
158
133
|
this._removeFocusTrap();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
export { epmModal as default };
|
|
139
|
+
//# sourceMappingURL=epm-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epm-modal.js","sources":["../../src/components/epm-modal.hbs","../../src/components/epm-modal.js"],"sourcesContent":["import { precompileTemplate } from \"@ember/template-compilation\";\nexport default precompileTemplate(\"{{!-- template-lint-disable no-action --}}\\n<div id={{this.modalElementId}} class=\\\"epm-modal {{this.optionsClassName}} {{this.animatingClass}}\\\">\\n {{#let (component (ensure-safe-component @modal._componentClass) data=@modal._data close=(action \\\"close\\\")) as |ModalComponent|}}\\n <ModalComponent />\\n {{/let}}\\n</div>\")","import Component from '@ember/component';\nimport { set } from '@ember/object';\nimport { readOnly } from '@ember/object/computed';\nimport { guidFor } from '@ember/object/internals';\nimport { inject as service } from '@ember/service';\n\nimport { createFocusTrap } from 'focus-trap';\n\nexport default Component.extend({\n tagName: '',\n outAnimationClass: 'epm-out',\n animatingClass: '',\n\n modals: service(),\n\n optionsClassName: readOnly('modal._options.className'),\n\n modalElementId: null,\n focusTrapOptions: null,\n _animationEnd: null,\n\n init() {\n this._super(...arguments);\n\n set(this, 'modalElementId', guidFor(this));\n\n this.modal._componentInstance = this;\n\n let { focusTrapOptions: globalFocusTrapOptions } = this.modals;\n let { focusTrapOptions: localFocusTrapOptions } = this.modal._options;\n\n if (localFocusTrapOptions !== null) {\n this.focusTrapOptions = localFocusTrapOptions || globalFocusTrapOptions;\n }\n },\n\n didInsertElement() {\n this._super(...arguments);\n\n this._addFocusTrap();\n this._addAnimationListeners();\n\n // animating in starts when the element is added to the DOM. Inform the service about it.\n this.modals._onModalAnimationStart();\n },\n\n willDestroyElement() {\n this.destroyModal();\n\n this._super(...arguments);\n },\n\n _getElement() {\n return document.getElementById(this.modalElementId);\n },\n\n _addFocusTrap() {\n let element = this._getElement();\n\n if (!this.focusTrapOptions) {\n return;\n }\n\n let options = {\n ...this.focusTrapOptions,\n fallbackFocus: element,\n onDeactivate: (...args) => {\n this.focusTrapOptions.onDeactivate?.(...args);\n\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n\n this.closeModal();\n },\n };\n\n this.focusTrap = createFocusTrap(element, options);\n this.focusTrap.activate();\n },\n\n _removeFocusTrap(onDeactivate = this.focusTrapOptions?.onDeactivate) {\n if (!this.focusTrap) {\n return;\n }\n\n this.focusTrap.deactivate({ onDeactivate });\n },\n\n _addAnimationListeners() {\n this._animationEnd = ({ target, animationName }) => {\n // ignore animations bubbling up\n if (target !== this._getElement()) {\n return;\n }\n\n // An animation has ended, inform the modals service\n this.modals._onModalAnimationEnd();\n\n let isOutAnimation = animationName.substring(animationName.length - 4) === '-out';\n if (isOutAnimation) {\n this.modal._remove();\n }\n };\n\n let element = this._getElement();\n if (element) {\n element.addEventListener('animationend', this._animationEnd);\n }\n },\n\n _removeAnimationListeners() {\n if (!this._animationEnd) {\n return;\n }\n\n let element = this._getElement();\n if (element) {\n element.removeEventListener('animationend', this._animationEnd);\n }\n\n this._animationEnd = null;\n },\n\n destroyModal() {\n // Remove the focus trap without triggering the optional onDeactivate() hook\n this._removeFocusTrap(null);\n\n // Remove the animation listeners\n this._removeAnimationListeners();\n\n // make sure that we remove the modal, also resolving the test waiter\n this.modal._remove();\n },\n\n closeModal(result) {\n if (this.animatingClass !== '') {\n return;\n }\n\n this.modals._onModalAnimationStart();\n\n // This triggers the out animation, which in turn will remove the modal after it completes\n set(this, 'animatingClass', this.outAnimationClass);\n\n this.modal._resolve(result);\n },\n\n actions: {\n close(result) {\n this.closeModal(result);\n\n // Remove the focus trap, triggering the onDeactivate() hook\n this._removeFocusTrap();\n },\n },\n});\n"],"names":["setComponentTemplate","TEMPLATE","Component","extend","tagName","outAnimationClass","animatingClass","modals","service","optionsClassName","readOnly","modalElementId","focusTrapOptions","_animationEnd","init","_super","arguments","set","guidFor","modal","_componentInstance","globalFocusTrapOptions","localFocusTrapOptions","_options","didInsertElement","_addFocusTrap","_addAnimationListeners","_onModalAnimationStart","willDestroyElement","destroyModal","_getElement","document","getElementById","element","options","fallbackFocus","onDeactivate","args","isDestroyed","isDestroying","closeModal","focusTrap","createFocusTrap","activate","_removeFocusTrap","deactivate","target","animationName","_onModalAnimationEnd","isOutAnimation","substring","length","_remove","addEventListener","_removeAnimationListeners","removeEventListener","result","_resolve","actions","close"],"mappings":";;;;;;;;AACA,eAAe,kBAAkB,CAAC,sUAAsU;;ACOxW,eAAAA,oBAAA,CAAAC,QAAA,EAAeC,SAAS,CAACC,MAAM,CAAC;AAC9BC,EAAAA,OAAO,EAAE,EAAE;AACXC,EAAAA,iBAAiB,EAAE,SAAS;AAC5BC,EAAAA,cAAc,EAAE,EAAE;EAElBC,MAAM,EAAEC,MAAO,EAAE;AAEjBC,EAAAA,gBAAgB,EAAEC,QAAQ,CAAC,0BAA0B,CAAC;AAEtDC,EAAAA,cAAc,EAAE,IAAI;AACpBC,EAAAA,gBAAgB,EAAE,IAAI;AACtBC,EAAAA,aAAa,EAAE,IAAI;AAEnBC,EAAAA,IAAIA,GAAG;AACL,IAAA,IAAI,CAACC,MAAM,CAAC,GAAGC,SAAS,CAAC,CAAA;IAEzBC,GAAG,CAAC,IAAI,EAAE,gBAAgB,EAAEC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;AAE1C,IAAA,IAAI,CAACC,KAAK,CAACC,kBAAkB,GAAG,IAAI,CAAA;IAEpC,IAAI;AAAER,MAAAA,gBAAgB,EAAES,sBAAAA;KAAwB,GAAG,IAAI,CAACd,MAAM,CAAA;IAC9D,IAAI;AAAEK,MAAAA,gBAAgB,EAAEU,qBAAAA;AAAsB,KAAC,GAAG,IAAI,CAACH,K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OAAO,EAAE;MACXA,OAAO,CAACsB,mBAAmB,CAAC,cAAc,EAAE,IAAI,CAAC1C,aAAa,CAAC,CAAA;AACjE,KAAA;IAEA,IAAI,CAACA,aAAa,GAAG,IAAI,CAAA;GAC1B;AAEDgB,EAAAA,YAAYA,GAAG;AACb;AACA,IAAA,IAAI,CAACe,gBAAgB,CAAC,IAAI,CAAC,CAAA;;AAE3B;IACA,IAAI,CAACU,yBAAyB,EAAE,CAAA;;AAEhC;AACA,IAAA,IAAI,CAACnC,KAAK,CAACiC,OAAO,EAAE,CAAA;GACrB;EAEDZ,UAAUA,CAACgB,MAAM,EAAE;AACjB,IAAA,IAAI,IAAI,CAAClD,cAAc,KAAK,EAAE,EAAE;AAC9B,MAAA,OAAA;AACF,KAAA;AAEA,IAAA,IAAI,CAACC,MAAM,CAACoB,sBAAsB,EAAE,CAAA;;AAEpC;IACAV,GAAG,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,CAACZ,iBAAiB,CAAC,CAAA;AAEnD,IAAA,IAAI,CAACc,KAAK,CAACsC,QAAQ,CAACD,MAAM,CAAC,CAAA;GAC5B;AAEDE,EAAAA,OAAO,EAAE;IACPC,KAAKA,CAACH,MAAM,EAAE;AACZ,MAAA,IAAI,CAAChB,UAAU,CAACgB,MAAM,CAAC,CAAA;;AAEvB;MACA,IAAI,CAACZ,gBAAgB,EAAE,CAAA;AACzB,KAAA;AACF,GAAA;AACF,CAAC,CAAC,CAAA;;;;"}
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import Helper from '@ember/component/helper';
|
|
2
|
-
import { inject
|
|
3
|
-
|
|
4
|
-
export default class OpenModalHelper extends Helper {
|
|
5
|
-
@service modals;
|
|
2
|
+
import { inject } from '@ember/service';
|
|
3
|
+
import { g, i } from 'decorator-transforms/runtime';
|
|
6
4
|
|
|
5
|
+
class OpenModalHelper extends Helper {
|
|
6
|
+
static {
|
|
7
|
+
g(this.prototype, "modals", [inject]);
|
|
8
|
+
}
|
|
9
|
+
#modals = (i(this, "modals"), void 0);
|
|
7
10
|
modal = null;
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
compute([modalComponent, data, options], {
|
|
12
|
+
close
|
|
13
|
+
}) {
|
|
10
14
|
this.showModal(modalComponent, data, options, close);
|
|
11
15
|
}
|
|
12
|
-
|
|
13
16
|
async showModal(modalComponent, data, options, close) {
|
|
14
17
|
this.modal = this.modals.open(modalComponent, data, options);
|
|
15
|
-
|
|
16
18
|
let success = await this.modal;
|
|
17
|
-
|
|
18
19
|
this.modal = null;
|
|
19
|
-
|
|
20
20
|
if (close) {
|
|
21
21
|
close(success);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
25
24
|
hideModal() {
|
|
26
25
|
this.modal?.close();
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
willDestroy() {
|
|
30
28
|
this.hideModal();
|
|
31
29
|
super.willDestroy(...arguments);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
32
|
+
|
|
33
|
+
export { OpenModalHelper as default };
|
|
34
|
+
//# sourceMappingURL=open-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-modal.js","sources":["../../src/helpers/open-modal.js"],"sourcesContent":["import Helper from '@ember/component/helper';\nimport { inject as service } from '@ember/service';\n\nexport default class OpenModalHelper extends Helper {\n @service modals;\n\n modal = null;\n\n compute([modalComponent, data, options], { close }) {\n this.showModal(modalComponent, data, options, close);\n }\n\n async showModal(modalComponent, data, options, close) {\n this.modal = this.modals.open(modalComponent, data, options);\n\n let success = await this.modal;\n\n this.modal = null;\n\n if (close) {\n close(success);\n }\n }\n\n hideModal() {\n this.modal?.close();\n }\n\n willDestroy() {\n this.hideModal();\n super.willDestroy(...arguments);\n }\n}\n"],"names":["OpenModalHelper","Helper","g","this","prototype","service","i","void 0","modal","compute","modalComponent","data","options","close","showModal","modals","open","success","hideModal","willDestroy","arguments"],"mappings":";;;;AAGe,MAAMA,eAAe,SAASC,MAAM,CAAC;AAAA,EAAA;AAAAC,IAAAA,CAAA,CAAAC,IAAA,CAAAC,SAAA,aACjDC,MAAO,CAAA,CAAA,CAAA;AAAA,GAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAAH,IAAA,aAAAI,KAAA,CAAA,EAAA;AAERC,EAAAA,KAAK,GAAG,IAAI,CAAA;EAEZC,OAAOA,CAAC,CAACC,cAAc,EAAEC,IAAI,EAAEC,OAAO,CAAC,EAAE;AAAEC,IAAAA,KAAAA;AAAM,GAAC,EAAE;IAClD,IAAI,CAACC,SAAS,CAACJ,cAAc,EAAEC,IAAI,EAAEC,OAAO,EAAEC,KAAK,CAAC,CAAA;AACtD,GAAA;EAEA,MAAMC,SAASA,CAACJ,cAAc,EAAEC,IAAI,EAAEC,OAAO,EAAEC,KAAK,EAAE;AACpD,IAAA,IAAI,CAACL,KAAK,GAAG,IAAI,CAACO,MAAM,CAACC,IAAI,CAACN,cAAc,EAAEC,IAAI,EAAEC,OAAO,CAAC,CAAA;AAE5D,IAAA,IAAIK,OAAO,GAAG,MAAM,IAAI,CAACT,KAAK,CAAA;IAE9B,IAAI,CAACA,KAAK,GAAG,IAAI,CAAA;AAEjB,IAAA,IAAIK,KAAK,EAAE;MACTA,KAAK,CAACI,OAAO,CAAC,CAAA;AAChB,KAAA;AACF,GAAA;AAEAC,EAAAA,SAASA,GAAG;AACV,IAAA,IAAI,CAACV,KAAK,EAAEK,KAAK,EAAE,CAAA;AACrB,GAAA;AAEAM,EAAAA,WAAWA,GAAG;IACZ,IAAI,CAACD,SAAS,EAAE,CAAA;AAChB,IAAA,KAAK,CAACC,WAAW,CAAC,GAAGC,SAAS,CAAC,CAAA;AACjC,GAAA;AACF;;;;"}
|
package/{addon → dist}/modal.js
RENAMED
|
@@ -1,94 +1,70 @@
|
|
|
1
|
-
// eslint-disable-next-line ember/no-computed-properties-in-native-classes
|
|
2
1
|
import { computed, set } from '@ember/object';
|
|
3
2
|
import { waitForPromise } from '@ember/test-waiters';
|
|
4
|
-
|
|
5
3
|
import { defer } from 'rsvp';
|
|
4
|
+
import { n } from 'decorator-transforms/runtime';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @property {String} [className] - CSS class name passed to the modal element
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @class Modal
|
|
15
|
-
* @param {Service} service
|
|
16
|
-
* @param {String} name
|
|
17
|
-
* @param {any} data
|
|
18
|
-
* @param {ModalOptions} options
|
|
19
|
-
* @method close - closes the modal
|
|
20
|
-
* @method then - resolves when the modal is closed
|
|
21
|
-
*/
|
|
22
|
-
export default class Modal {
|
|
23
|
-
constructor(service, name, data, options = {}) {
|
|
6
|
+
// eslint-disable-next-line ember/no-computed-properties-in-native-classes
|
|
7
|
+
class Modal {
|
|
8
|
+
constructor(service, componentClass, data, options = {}) {
|
|
24
9
|
this._service = service;
|
|
25
|
-
this.
|
|
10
|
+
this._componentClass = componentClass;
|
|
26
11
|
this._data = data;
|
|
27
12
|
this._options = {
|
|
28
13
|
className: '',
|
|
29
14
|
onAnimationModalOutEnd: undefined,
|
|
30
|
-
...options
|
|
15
|
+
...options
|
|
31
16
|
};
|
|
32
17
|
this._result = undefined;
|
|
33
18
|
this._deferred = defer();
|
|
34
19
|
this._deferredOutAnimation = undefined;
|
|
35
20
|
this._componentInstance = undefined;
|
|
36
21
|
}
|
|
37
|
-
|
|
38
22
|
get result() {
|
|
39
23
|
return this._result;
|
|
40
24
|
}
|
|
41
|
-
|
|
42
|
-
@computed('_deferredOutAnimation')
|
|
43
25
|
get isClosing() {
|
|
44
26
|
return Boolean(this._deferredOutAnimation);
|
|
45
27
|
}
|
|
46
|
-
|
|
28
|
+
static {
|
|
29
|
+
n(this.prototype, "isClosing", [computed('_deferredOutAnimation')]);
|
|
30
|
+
}
|
|
47
31
|
close(result) {
|
|
48
32
|
if (this._componentInstance) {
|
|
49
33
|
this._componentInstance.closeModal(result);
|
|
50
34
|
}
|
|
51
35
|
}
|
|
52
|
-
|
|
53
36
|
then(onFulfilled, onRejected) {
|
|
54
37
|
return this._deferred.promise.then(onFulfilled, onRejected);
|
|
55
38
|
}
|
|
56
|
-
|
|
57
39
|
_destroy() {
|
|
58
40
|
if (!this._componentInstance) {
|
|
59
41
|
return;
|
|
60
42
|
}
|
|
61
|
-
|
|
62
43
|
this._componentInstance.destroyModal();
|
|
63
44
|
}
|
|
64
|
-
|
|
65
45
|
_resolve(result) {
|
|
66
46
|
if (this._deferredOutAnimation) {
|
|
67
47
|
return;
|
|
68
48
|
}
|
|
69
|
-
|
|
70
49
|
set(this, '_deferredOutAnimation', defer());
|
|
71
50
|
if (this._options.onAnimationModalOutEnd) {
|
|
72
51
|
this._deferredOutAnimation.promise.then(() => this._options.onAnimationModalOutEnd()).catch(() => {});
|
|
73
52
|
}
|
|
74
|
-
|
|
75
53
|
this._result = result;
|
|
76
54
|
this._deferred.resolve(result);
|
|
77
|
-
|
|
78
55
|
waitForPromise(this._deferredOutAnimation.promise);
|
|
79
56
|
}
|
|
80
|
-
|
|
81
57
|
_remove() {
|
|
82
58
|
this._service._stack.removeObject(this);
|
|
83
|
-
|
|
84
59
|
if (this._service._stack.length === 0) {
|
|
85
60
|
this._service._onLastModalRemoved();
|
|
86
61
|
}
|
|
87
|
-
|
|
88
62
|
this._componentInstance = undefined;
|
|
89
|
-
|
|
90
63
|
if (this._deferredOutAnimation) {
|
|
91
64
|
this._deferredOutAnimation.resolve();
|
|
92
65
|
}
|
|
93
66
|
}
|
|
94
67
|
}
|
|
68
|
+
|
|
69
|
+
export { Modal as default };
|
|
70
|
+
//# sourceMappingURL=modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.js","sources":["../src/modal.js"],"sourcesContent":["// eslint-disable-next-line ember/no-computed-properties-in-native-classes\nimport { computed, set } from '@ember/object';\nimport { waitForPromise } from '@ember/test-waiters';\n\nimport { defer } from 'rsvp';\n\n/**\n * @typedef {Object} ModalOptions\n * @property {Function} [onAnimationModalOutEnd]\n * @property {String} [className] - CSS class name passed to the modal element\n */\n\n/**\n * @class Modal\n * @param {Service} service\n * @param {String} componentClass\n * @param {any} data\n * @param {ModalOptions} options\n * @method close - closes the modal\n * @method then - resolves when the modal is closed\n */\nexport default class Modal {\n constructor(service, componentClass, data, options = {}) {\n this._service = service;\n this._componentClass = componentClass;\n this._data = data;\n this._options = {\n className: '',\n onAnimationModalOutEnd: undefined,\n ...options,\n };\n this._result = undefined;\n this._deferred = defer();\n this._deferredOutAnimation = undefined;\n this._componentInstance = undefined;\n }\n\n get result() {\n return this._result;\n }\n\n @computed('_deferredOutAnimation')\n get isClosing() {\n return Boolean(this._deferredOutAnimation);\n }\n\n close(result) {\n if (this._componentInstance) {\n this._componentInstance.closeModal(result);\n }\n }\n\n then(onFulfilled, onRejected) {\n return this._deferred.promise.then(onFulfilled, onRejected);\n }\n\n _destroy() {\n if (!this._componentInstance) {\n return;\n }\n\n this._componentInstance.destroyModal();\n }\n\n _resolve(result) {\n if (this._deferredOutAnimation) {\n return;\n }\n\n set(this, '_deferredOutAnimation', defer());\n if (this._options.onAnimationModalOutEnd) {\n this._deferredOutAnimation.promise.then(() => this._options.onAnimationModalOutEnd()).catch(() => {});\n }\n\n this._result = result;\n this._deferred.resolve(result);\n\n waitForPromise(this._deferredOutAnimation.promise);\n }\n\n _remove() {\n this._service._stack.removeObject(this);\n\n if (this._service._stack.length === 0) {\n this._service._onLastModalRemoved();\n }\n\n this._componentInstance = undefined;\n\n if (this._deferredOutAnimation) {\n this._deferredOutAnimation.resolve();\n }\n }\n}\n"],"names":["Modal","constructor","service","componentClass","data","options","_service","_componentClass","_data","_options","className","onAnimationModalOutEnd","undefined","_result","_deferred","defer","_deferredOutAnimation","_componentInstance","result","isClosing","Boolean","n","this","prototype","computed","close","closeModal","then","onFulfilled","onRejected","promise","_destroy","destroyModal","_resolve","set","catch","resolve","waitForPromise","_remove","_stack","removeObject","length","_onLastModalR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