ember-promise-modals 1.1.1 → 3.0.1
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/.prettierignore +27 -0
- package/.release-it.js +20 -0
- package/CHANGELOG.md +75 -0
- package/MIGRATION.md +2 -0
- package/README.md +114 -49
- package/addon/components/modal.js +29 -15
- package/addon/modal.js +20 -1
- package/addon/services/modals.js +15 -4
- package/addon/templates/components/modal-container.hbs +5 -7
- package/addon/templates/components/modal.hbs +4 -1
- package/index.js +14 -12
- package/package.json +75 -44
- package/pnpm-lock.yaml +14011 -0
- package/renovate.json +29 -0
- package/.github/epm.svg +0 -1
- package/.github/workflows/ci.yml +0 -67
- package/.github/workflows/release.yml +0 -22
package/.prettierignore
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# unconventional js
|
|
2
|
+
/blueprints/*/files/
|
|
3
|
+
/vendor/
|
|
4
|
+
|
|
5
|
+
# compiled output
|
|
6
|
+
/dist/
|
|
7
|
+
/tmp/
|
|
8
|
+
|
|
9
|
+
# dependencies
|
|
10
|
+
/bower_components/
|
|
11
|
+
/node_modules/
|
|
12
|
+
|
|
13
|
+
# misc
|
|
14
|
+
/coverage/
|
|
15
|
+
!.*
|
|
16
|
+
.eslintcache
|
|
17
|
+
.lint-todo/
|
|
18
|
+
|
|
19
|
+
# ember-try
|
|
20
|
+
/.node_modules.ember-try/
|
|
21
|
+
/bower.json.ember-try
|
|
22
|
+
/npm-shrinkwrap.json.ember-try
|
|
23
|
+
/package.json.ember-try
|
|
24
|
+
/package-lock.json.ember-try
|
|
25
|
+
/yarn.lock.ember-try
|
|
26
|
+
|
|
27
|
+
CHANGELOG.md
|
package/.release-it.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable no-template-curly-in-string */
|
|
2
|
+
module.exports = {
|
|
3
|
+
plugins: {
|
|
4
|
+
'release-it-lerna-changelog': {
|
|
5
|
+
infile: 'CHANGELOG.md',
|
|
6
|
+
},
|
|
7
|
+
},
|
|
8
|
+
git: {
|
|
9
|
+
commitMessage: 'v${version}',
|
|
10
|
+
tagName: 'v${version}',
|
|
11
|
+
},
|
|
12
|
+
github: {
|
|
13
|
+
release: true,
|
|
14
|
+
releaseName: 'v${version}',
|
|
15
|
+
tokenRef: 'GITHUB_AUTH',
|
|
16
|
+
},
|
|
17
|
+
npm: {
|
|
18
|
+
publish: false,
|
|
19
|
+
},
|
|
20
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## v3.0.1 (2022-04-12)
|
|
6
|
+
|
|
7
|
+
#### :bug: Bug Fix
|
|
8
|
+
* [#596](https://github.com/simplabs/ember-promise-modals/pull/596) Ensure calls to @close run before the focus-out deactivation ([@pichfl](https://github.com/pichfl))
|
|
9
|
+
|
|
10
|
+
#### :house: Internal
|
|
11
|
+
* [#597](https://github.com/simplabs/ember-promise-modals/pull/597) Remove deprecated `clickOutsideDeactivates` option ([@pichfl](https://github.com/pichfl))
|
|
12
|
+
|
|
13
|
+
#### Committers: 1
|
|
14
|
+
- Florian Pichler ([@pichfl](https://github.com/pichfl))
|
|
15
|
+
|
|
16
|
+
## v3.0.0 (2022-04-11)
|
|
17
|
+
|
|
18
|
+
#### :boom: Breaking Change
|
|
19
|
+
* [#588](https://github.com/simplabs/ember-promise-modals/pull/588) Use ember-auto-import@2 ([@pichfl](https://github.com/pichfl))
|
|
20
|
+
* [#438](https://github.com/simplabs/ember-promise-modals/pull/438) bump @ember/test-waiters to 3.0.0 ([@nickschot](https://github.com/nickschot))
|
|
21
|
+
* [#437](https://github.com/simplabs/ember-promise-modals/pull/437) Drop Node 10 support ([@nickschot](https://github.com/nickschot))
|
|
22
|
+
|
|
23
|
+
#### :rocket: Enhancement
|
|
24
|
+
* [#549](https://github.com/simplabs/ember-promise-modals/pull/549) Enhance focus trap configuration ([@zeppelin](https://github.com/zeppelin))
|
|
25
|
+
* [#533](https://github.com/simplabs/ember-promise-modals/pull/533) Legacy: Downgrade native class to Ember.Object ([@pichfl](https://github.com/pichfl))
|
|
26
|
+
* [#436](https://github.com/simplabs/ember-promise-modals/pull/436) Embroider optimized compatibility ([@nickschot](https://github.com/nickschot))
|
|
27
|
+
* [#517](https://github.com/simplabs/ember-promise-modals/pull/517) Add option to disable focus trap ([@zeppelin](https://github.com/zeppelin))
|
|
28
|
+
|
|
29
|
+
#### :memo: Documentation
|
|
30
|
+
* [#502](https://github.com/simplabs/ember-promise-modals/pull/502) Provide additional documentation for the Modal class and ModalOptions ([@pichfl](https://github.com/pichfl))
|
|
31
|
+
|
|
32
|
+
#### :house: Internal
|
|
33
|
+
* [#594](https://github.com/simplabs/ember-promise-modals/pull/594) Configure release-it ([@pichfl](https://github.com/pichfl))
|
|
34
|
+
* [#570](https://github.com/simplabs/ember-promise-modals/pull/570) Setup Renovatebot ([@nickschot](https://github.com/nickschot))
|
|
35
|
+
* [#477](https://github.com/simplabs/ember-promise-modals/pull/477) Replace Yarn with pnpm ([@pichfl](https://github.com/pichfl))
|
|
36
|
+
* [#530](https://github.com/simplabs/ember-promise-modals/pull/530) Internal: Extend and apply prettier configuration ([@pichfl](https://github.com/pichfl))
|
|
37
|
+
* [#500](https://github.com/simplabs/ember-promise-modals/pull/500) Specify octane edition in package.json & add missing optional features ([@nickschot](https://github.com/nickschot))
|
|
38
|
+
* [#499](https://github.com/simplabs/ember-promise-modals/pull/499) Update ember-release scenario to use auto-import v2 ([@nickschot](https://github.com/nickschot))
|
|
39
|
+
|
|
40
|
+
#### Committers: 3
|
|
41
|
+
- Florian Pichler ([@pichfl](https://github.com/pichfl))
|
|
42
|
+
- Gabor Babicz ([@zeppelin](https://github.com/zeppelin))
|
|
43
|
+
- Nick Schot ([@nickschot](https://github.com/nickschot))
|
|
44
|
+
|
|
45
|
+
## v2.0.0 (2021-09-01)
|
|
46
|
+
|
|
47
|
+
#### :boom: Breaking Change
|
|
48
|
+
* [#427](https://github.com/simplabs/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
|
|
49
|
+
|
|
50
|
+
#### :rocket: Enhancement
|
|
51
|
+
* [#427](https://github.com/simplabs/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
|
|
52
|
+
|
|
53
|
+
#### :memo: Documentation
|
|
54
|
+
* [#432](https://github.com/simplabs/ember-promise-modals/pull/432) Fix responsiveness of dummy app ([@nickschot](https://github.com/nickschot))
|
|
55
|
+
* [#414](https://github.com/simplabs/ember-promise-modals/pull/414) Improve README and dummy application ([@pichfl](https://github.com/pichfl))
|
|
56
|
+
|
|
57
|
+
#### :house: Internal
|
|
58
|
+
* [#431](https://github.com/simplabs/ember-promise-modals/pull/431) Use env=production when building the dummy application ([@pichfl](https://github.com/pichfl))
|
|
59
|
+
* [#430](https://github.com/simplabs/ember-promise-modals/pull/430) Update production build path for GitHub pages ([@pichfl](https://github.com/pichfl))
|
|
60
|
+
* [#415](https://github.com/simplabs/ember-promise-modals/pull/415) Deploy dummy application to Github pages ([@pichfl](https://github.com/pichfl))
|
|
61
|
+
|
|
62
|
+
#### Committers: 4
|
|
63
|
+
- Anass OUMIRI ([@aoumiri](https://github.com/aoumiri))
|
|
64
|
+
- Florian Pichler ([@pichfl](https://github.com/pichfl))
|
|
65
|
+
- Nick Schot ([@nickschot](https://github.com/nickschot))
|
|
66
|
+
- [@dependabot-preview[bot]](https://github.com/apps/dependabot-preview)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## v1.1.1 (2021-07-27)
|
|
70
|
+
|
|
71
|
+
#### :bug: Bug Fix
|
|
72
|
+
* [#422](https://github.com/simplabs/ember-promise-modals/pull/422) fix promsie-modals from breaking when used in another addon instead of an app ([@nickschot](https://github.com/nickschot))
|
|
73
|
+
|
|
74
|
+
#### Committers: 1
|
|
75
|
+
- Nick Schot ([@nickschot](https://github.com/nickschot))
|
|
76
|
+
|
|
77
|
+
|
|
3
78
|
## v1.1.0 (2021-07-27)
|
|
4
79
|
|
|
5
80
|
#### :rocket: Enhancement
|
package/MIGRATION.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Migration
|
|
2
2
|
|
|
3
3
|
## From 0.x.x to 1.x.x
|
|
4
|
+
|
|
4
5
|
Version 1.0.0 replaced the ember-animated powered animations with CSS based animations. In addition to that the default animation was also changed. This guide will show you how to get the animations of the old version.
|
|
5
6
|
|
|
6
7
|
### From top/bottom animations
|
|
@@ -72,6 +73,7 @@ Furthermore, some CSS variables will need to be overridden so that the new anima
|
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
### Using both animations
|
|
76
|
+
|
|
75
77
|
If you need to switch between both animations it's easiest to replicate the setup shown in the dummy app. See [the application.js controller](./tests/dummy/app/controllers/application.js)
|
|
76
78
|
for how the modals are openend in your JavaScript actions and look at
|
|
77
79
|
[app.css](./tests/dummy/app/styles/app.css) for the style definition of these
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<p align="center"><img src="
|
|
1
|
+
<p align="center"><img src="./tests/dummy/public/ember-promise-modals-logo.svg" role="presentation" alt="" width="600" height="400" /></p>
|
|
2
2
|
|
|
3
3
|
# ember-promise-modals
|
|
4
4
|
|
|
@@ -7,8 +7,8 @@ The better way to handle modals in your Ember.js apps.
|
|
|
7
7
|
## Compatibility
|
|
8
8
|
|
|
9
9
|
- Ember.js v3.4 or above
|
|
10
|
-
- Ember CLI
|
|
11
|
-
- Node.js
|
|
10
|
+
- Ember CLI v3.4 or above
|
|
11
|
+
- Node.js v12, v14 or above
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
@@ -24,48 +24,59 @@ To use EPM in your project, add the target for the modals to your `application.h
|
|
|
24
24
|
<EpmModalContainer />
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Then you
|
|
27
|
+
Then you can to inject the `modals` service wherever you need and call its `open` method with a component name to render it as a modal.
|
|
28
28
|
|
|
29
|
-
```
|
|
30
|
-
@service modals;
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Now you can call the `open` method with a component name to render it as a modal:
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
this.modals.open('component-to-render');
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Basic usage
|
|
40
|
-
|
|
41
|
-
Here is a basic code example:
|
|
42
|
-
|
|
43
|
-
```javascript
|
|
29
|
+
```js
|
|
44
30
|
import { inject as service } from '@ember/service';
|
|
45
31
|
|
|
46
32
|
export default class extends Component {
|
|
47
33
|
@service modals;
|
|
48
34
|
|
|
49
35
|
@action
|
|
50
|
-
handleOpenModal() {
|
|
51
|
-
this.modals.open('confirmation-modal');
|
|
36
|
+
async handleOpenModal() {
|
|
37
|
+
let modal = this.modals.open('confirmation-modal');
|
|
38
|
+
|
|
39
|
+
// the instance acts as a promise that resolves with anything passed to the @close function
|
|
40
|
+
modal.then(results => {
|
|
41
|
+
// do something with the data
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// so does `await`ing it!
|
|
45
|
+
let results = await modal;
|
|
46
|
+
|
|
47
|
+
// you can also close the modal from outside
|
|
48
|
+
modal.close();
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
51
|
```
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
```handlebars
|
|
59
|
-
<button {{on "click" this.handleOpenModal}}>
|
|
53
|
+
```hbs
|
|
54
|
+
<button type='button' {{on 'click' this.handleOpenModal}}>
|
|
60
55
|
Click Me!
|
|
61
56
|
</button>
|
|
62
57
|
```
|
|
63
58
|
|
|
64
|
-
###
|
|
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
|
+
### Passing data to the rendered component
|
|
65
76
|
|
|
66
77
|
You can pass custom data into your rendered template like so:
|
|
67
78
|
|
|
68
|
-
```
|
|
79
|
+
```js
|
|
69
80
|
this.modals.open('file-preview', {
|
|
70
81
|
fileUrl: this.fileUrl,
|
|
71
82
|
});
|
|
@@ -73,31 +84,27 @@ this.modals.open('file-preview', {
|
|
|
73
84
|
|
|
74
85
|
All passed attributes can be accessed from the passed-in `data` object:
|
|
75
86
|
|
|
76
|
-
```
|
|
77
|
-
<!--
|
|
78
|
-
|
|
87
|
+
```hbs
|
|
88
|
+
<!-- components/file-preview.hbs -->
|
|
79
89
|
<img src={{@data.fileUrl}} />
|
|
80
90
|
```
|
|
81
91
|
|
|
82
|
-
```
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
this.data.fileUrl; // or this.args.data.fileUrl in Glimmer components
|
|
92
|
+
```js
|
|
93
|
+
// components/file-preview.js
|
|
94
|
+
this.args.data.fileUrl; // or this.data.fileUrl in classic components
|
|
86
95
|
```
|
|
87
96
|
|
|
88
97
|
**NOTE:** By default, a `close` method is passed in your rendered component, in
|
|
89
98
|
order to trigger the "close modal" action. It can be called like so:
|
|
90
99
|
|
|
91
|
-
```
|
|
92
|
-
<!--
|
|
93
|
-
|
|
94
|
-
<button {{on "click" @close}}>Close</button>
|
|
100
|
+
```hbs
|
|
101
|
+
<!-- components/file-preview.hbs -->
|
|
102
|
+
<button type='button' {{on 'click' (fn @close results)}}>Close</button>
|
|
95
103
|
```
|
|
96
104
|
|
|
97
|
-
```
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
this.close(); // or this.args.close() in Glimmer components
|
|
105
|
+
```js
|
|
106
|
+
// components/file-preview.js
|
|
107
|
+
this.args.close(results); // or this.close() in classic components
|
|
101
108
|
```
|
|
102
109
|
|
|
103
110
|
## Animation
|
|
@@ -117,7 +124,7 @@ detected.
|
|
|
117
124
|
To override the animation for a specific modal, an `options` object containing
|
|
118
125
|
a custom `className` can be handed to the `.open()` method.
|
|
119
126
|
|
|
120
|
-
```
|
|
127
|
+
```js
|
|
121
128
|
this.modals.open(
|
|
122
129
|
'file-preview',
|
|
123
130
|
{
|
|
@@ -128,12 +135,12 @@ this.modals.open(
|
|
|
128
135
|
className: 'custom-modal',
|
|
129
136
|
// optional: name the animation triggered by the custom css class
|
|
130
137
|
// animations ending in "-out" are detected by default!
|
|
131
|
-
// You most likely do not have to do this unless you absolutely
|
|
138
|
+
// You most likely do not have to do this unless you absolutely
|
|
132
139
|
// can't have an animation ending in '-out'
|
|
133
140
|
animationKeyframesOutName: 'custom-animation-name-out',
|
|
134
141
|
// optional: a hook that is called when the closing animation of
|
|
135
142
|
// the modal (so not the backdrop) has finished.
|
|
136
|
-
onAnimationModalOutEnd: () => {}
|
|
143
|
+
onAnimationModalOutEnd: () => {},
|
|
137
144
|
},
|
|
138
145
|
);
|
|
139
146
|
```
|
|
@@ -176,12 +183,12 @@ The CSS animations which are applied by the custom CSS class _must_ end in
|
|
|
176
183
|
|
|
177
184
|
#### Examples
|
|
178
185
|
|
|
179
|
-
Examples for custom animations and how to apply them can be found in the addons
|
|
180
|
-
dummy application.
|
|
186
|
+
Examples for custom animations and how to apply them can be found in the addons
|
|
187
|
+
dummy application.
|
|
181
188
|
|
|
182
|
-
See [the application.js controller](./tests/dummy/app/controllers/application.js)
|
|
189
|
+
See [the application.js controller](./tests/dummy/app/controllers/application.js)
|
|
183
190
|
for how the modals are openend in your JavaScript actions and look at
|
|
184
|
-
[app.css](./tests/dummy/app/styles/app.css) for the style definition of these
|
|
191
|
+
[app.css](./tests/dummy/app/styles/app.css) for the style definition of these
|
|
185
192
|
custom animations.
|
|
186
193
|
|
|
187
194
|
### CSS Variables
|
|
@@ -219,6 +226,64 @@ EPM will ensure to [focus the first "tabbable element" by default](https://www.w
|
|
|
219
226
|
If no focusable element is present, focus will be applied on the currently
|
|
220
227
|
visible auto-generated container for the current modal.
|
|
221
228
|
|
|
229
|
+
Focus Trap can be configured both on the `modals` service, and the individual
|
|
230
|
+
modal level when calling `this.modals.open()`. Global and local options are used
|
|
231
|
+
in that order, which means that local config take precedence.
|
|
232
|
+
|
|
233
|
+
To set global Focus Trap config that all modals inherit, override the default
|
|
234
|
+
`Modals` service by extending it, place it to `app/services/modals.js`, then
|
|
235
|
+
use the `focusTrapOptions` property:
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
import BaseModalsService from 'ember-promise-modals/services/modals';
|
|
239
|
+
|
|
240
|
+
export default class ModalsService extends BaseModalsService {
|
|
241
|
+
focusTrapOptions = {
|
|
242
|
+
clickOutsideDeactivates: false,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Example for local Focus Trap option, when opening a specific modal:
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
this.modals.open(
|
|
251
|
+
'file-preview',
|
|
252
|
+
{ fileUrl: this.fileUrl },
|
|
253
|
+
{
|
|
254
|
+
focusTrapOptions: {
|
|
255
|
+
clickOutsideDeactivates: false,
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
To disable Focus Trap completely, set `focusTrapOptions` to `null` on the
|
|
262
|
+
`modals` service:
|
|
263
|
+
|
|
264
|
+
```js
|
|
265
|
+
import BaseModalsService from 'ember-promise-modals/services/modals';
|
|
266
|
+
|
|
267
|
+
export default class ModalsService extends BaseModalsService {
|
|
268
|
+
focusTrapOptions = null;
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Or when opening a modal:
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
this.modals.open(
|
|
276
|
+
'file-preview',
|
|
277
|
+
{ fileUrl: this.fileUrl },
|
|
278
|
+
{
|
|
279
|
+
focusTrapOptions: null,
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
⚠️ _We strongly advise against doing this. This will in most cases worsen the
|
|
285
|
+
accessibility of modals for your users. Be very careful._
|
|
286
|
+
|
|
222
287
|
## Testing
|
|
223
288
|
|
|
224
289
|
This addon provides a test helper function that reduces the timing for the CSS transitions to near zero to speed up your tests.
|
|
@@ -19,33 +19,45 @@ export default Component.extend({
|
|
|
19
19
|
optionsClassName: readOnly('modal._options.className'),
|
|
20
20
|
|
|
21
21
|
modalElementId: null,
|
|
22
|
+
focusTrapOptions: null,
|
|
22
23
|
|
|
23
24
|
init() {
|
|
24
25
|
this._super(...arguments);
|
|
25
26
|
|
|
26
27
|
set(this, 'modalElementId', guidFor(this));
|
|
27
28
|
this.modal._componentInstance = this;
|
|
29
|
+
|
|
30
|
+
let { focusTrapOptions: globalFocusTrapOptions } = this.modals;
|
|
31
|
+
let { focusTrapOptions: localFocusTrapOptions } = this.modal._options;
|
|
32
|
+
|
|
33
|
+
if (localFocusTrapOptions !== null) {
|
|
34
|
+
this.focusTrapOptions = localFocusTrapOptions || globalFocusTrapOptions;
|
|
35
|
+
}
|
|
28
36
|
},
|
|
29
37
|
|
|
30
38
|
didInsertElement() {
|
|
31
39
|
this._super(...arguments);
|
|
32
40
|
|
|
33
|
-
let { clickOutsideDeactivates } = this.modals;
|
|
34
41
|
let element = document.getElementById(this.modalElementId);
|
|
35
|
-
let options = {
|
|
36
|
-
clickOutsideDeactivates,
|
|
37
|
-
fallbackFocus: `#${this.modalElementId}`,
|
|
38
|
-
onDeactivate: () => {
|
|
39
|
-
if (this.isDestroyed || this.isDestroying) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.closeModal();
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
42
|
|
|
47
|
-
this.
|
|
48
|
-
|
|
43
|
+
if (this.focusTrapOptions) {
|
|
44
|
+
let options = {
|
|
45
|
+
...this.focusTrapOptions,
|
|
46
|
+
fallbackFocus: `#${this.modalElementId}`,
|
|
47
|
+
onPostDeactivate: (...args) => {
|
|
48
|
+
this.focusTrapOptions.onPostDeactivate?.(...args);
|
|
49
|
+
|
|
50
|
+
if (this.isDestroyed || this.isDestroying) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.closeModal();
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
this.focusTrap = createFocusTrap(element, options);
|
|
59
|
+
this.focusTrap.activate();
|
|
60
|
+
}
|
|
49
61
|
|
|
50
62
|
this.fadeOutEnd = ({ target, animationName }) => {
|
|
51
63
|
this.modals._onModalAnimationEnd();
|
|
@@ -88,7 +100,9 @@ export default Component.extend({
|
|
|
88
100
|
set(this, 'animatingOutClass', this.outAnimationClass);
|
|
89
101
|
|
|
90
102
|
if (this.focusTrap) {
|
|
91
|
-
this.focusTrap.deactivate({
|
|
103
|
+
this.focusTrap.deactivate({
|
|
104
|
+
onDeactivate: this.focusTrapOptions.onDeactivate,
|
|
105
|
+
});
|
|
92
106
|
}
|
|
93
107
|
|
|
94
108
|
this.modal._resolve(result);
|
package/addon/modal.js
CHANGED
|
@@ -4,12 +4,31 @@ import { waitForPromise } from '@ember/test-waiters';
|
|
|
4
4
|
|
|
5
5
|
import { defer } from 'rsvp';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} ModalOptions
|
|
9
|
+
* @property {Function} [onAnimationModalOutEnd]
|
|
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
|
+
*/
|
|
7
22
|
export default class Modal {
|
|
8
23
|
constructor(service, name, data, options = {}) {
|
|
9
24
|
this._service = service;
|
|
10
25
|
this._name = name;
|
|
11
26
|
this._data = data;
|
|
12
|
-
this._options =
|
|
27
|
+
this._options = {
|
|
28
|
+
className: '',
|
|
29
|
+
onAnimationModalOutEnd: undefined,
|
|
30
|
+
...options,
|
|
31
|
+
};
|
|
13
32
|
this._result = undefined;
|
|
14
33
|
this._deferred = defer();
|
|
15
34
|
this._deferredOutAnimation = undefined;
|
package/addon/services/modals.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A } from '@ember/array';
|
|
2
|
-
import { computed
|
|
2
|
+
import { computed } from '@ember/object';
|
|
3
3
|
import { alias } from '@ember/object/computed';
|
|
4
4
|
import Service from '@ember/service';
|
|
5
5
|
|
|
@@ -11,18 +11,30 @@ export default Service.extend({
|
|
|
11
11
|
}),
|
|
12
12
|
top: alias('_stack.lastObject'),
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
_renderBackdrop: false,
|
|
14
|
+
focusTrapOptions: undefined,
|
|
16
15
|
|
|
17
16
|
init() {
|
|
18
17
|
this._super(...arguments);
|
|
19
18
|
this._stack = A([]);
|
|
19
|
+
|
|
20
|
+
if (this.focusTrapOptions !== null) {
|
|
21
|
+
this.focusTrapOptions = {
|
|
22
|
+
...(this.focusTrapOptions ?? {}),
|
|
23
|
+
clickOutsideDeactivates: this.focusTrapOptions?.clickOutsideDeactivate ?? true,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
20
26
|
},
|
|
21
27
|
|
|
22
28
|
willDestroy() {
|
|
23
29
|
this._onLastModalRemoved();
|
|
24
30
|
},
|
|
25
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @param {string} name component path
|
|
34
|
+
* @param {*} data passed to the component template
|
|
35
|
+
* @param {ModalOptions} options applied to the modal
|
|
36
|
+
* @returns {Modal}
|
|
37
|
+
*/
|
|
26
38
|
open(name, data, options) {
|
|
27
39
|
let modal = new Modal(this, name, data, options);
|
|
28
40
|
|
|
@@ -36,7 +48,6 @@ export default Service.extend({
|
|
|
36
48
|
},
|
|
37
49
|
|
|
38
50
|
_onFirstModalAdded() {
|
|
39
|
-
set(this, '_renderBackdrop', true);
|
|
40
51
|
document.body.classList.add('epm-scrolling-disabled');
|
|
41
52
|
},
|
|
42
53
|
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
{{#
|
|
1
|
+
{{#each this.modals._stack as |modal index|}}
|
|
2
2
|
<div
|
|
3
|
-
class="epm-backdrop {{
|
|
3
|
+
class="epm-backdrop {{if modal.isClosing "epm-out"}}"
|
|
4
4
|
tabindex="-1"
|
|
5
5
|
role="presentation"
|
|
6
6
|
aria-hidden="true"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
{{#each this.modals._stack as |modal|}}
|
|
7
|
+
data-test-epm-backdrop="{{index}}"
|
|
8
|
+
/>
|
|
11
9
|
<div class="epm-modal-container">
|
|
12
|
-
<EpmModal @modal={{modal}} />
|
|
10
|
+
<EpmModal @modal={{modal}} data-test-epm-modal="{{index}}" />
|
|
13
11
|
</div>
|
|
14
12
|
{{/each}}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
{{!-- template-lint-disable no-action --}}
|
|
1
2
|
<div id={{this.modalElementId}} class="epm-modal {{this.optionsClassName}} {{this.animatingOutClass}}">
|
|
2
|
-
{{component @modal._name data=@modal._data close=(action "close")}}
|
|
3
|
+
{{#let (component (ensure-safe-component @modal._name) data=@modal._data close=(action "close")) as |ModalComponent|}}
|
|
4
|
+
<ModalComponent />
|
|
5
|
+
{{/let}}
|
|
3
6
|
</div>
|
package/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const funnel = require('broccoli-funnel');
|
|
4
4
|
const mergeTrees = require('broccoli-merge-trees');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const BroccoliPostCSS = require('broccoli-postcss');
|
|
6
|
+
const postcssPresetEnv = require('postcss-preset-env');
|
|
7
7
|
|
|
8
8
|
const pkg = require('./package.json');
|
|
9
9
|
|
|
@@ -11,11 +11,10 @@ module.exports = {
|
|
|
11
11
|
name: require('./package').name,
|
|
12
12
|
|
|
13
13
|
treeForAddon() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let addonConfig = options[pkg.name] || {};
|
|
14
|
+
const tree = this._super(...arguments);
|
|
15
|
+
const app = this._findHost();
|
|
16
|
+
const options = typeof app.options === 'object' ? app.options : {};
|
|
17
|
+
const addonConfig = options[pkg.name] || {};
|
|
19
18
|
|
|
20
19
|
const addonWithoutStyles = funnel(tree, {
|
|
21
20
|
exclude: ['**/*.css'],
|
|
@@ -29,12 +28,15 @@ module.exports = {
|
|
|
29
28
|
include: ['**/*.css'],
|
|
30
29
|
});
|
|
31
30
|
|
|
32
|
-
const processedStyles =
|
|
31
|
+
const processedStyles = new BroccoliPostCSS(addonStyles, {
|
|
33
32
|
plugins: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
{
|
|
34
|
+
module: postcssPresetEnv,
|
|
35
|
+
options: {
|
|
36
|
+
stage: 3,
|
|
37
|
+
overrideBrowserslist: app.project._targets.browsers,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
38
40
|
],
|
|
39
41
|
});
|
|
40
42
|
|