ember-promise-modals 2.0.0 → 3.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/.prettierignore +27 -0
- package/.release-it.js +20 -0
- package/CHANGELOG.md +76 -0
- package/MIGRATION.md +2 -0
- package/README.md +106 -21
- package/addon/components/modal.js +29 -15
- package/addon/modal.js +20 -1
- package/addon/services/modals.js +31 -1
- package/addon/templates/components/modal.hbs +4 -1
- package/index.js +14 -12
- package/package.json +74 -43
- package/pnpm-lock.yaml +14188 -0
- package/renovate.json +29 -0
- package/.github/workflows/ci.yml +0 -67
- package/.github/workflows/deploy.yml +0 -25
- 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,81 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
## v3.0.0 (2022-04-11)
|
|
5
|
+
|
|
6
|
+
#### :boom: Breaking Change
|
|
7
|
+
* [#588](https://github.com/simplabs/ember-promise-modals/pull/588) Use ember-auto-import@2 ([@pichfl](https://github.com/pichfl))
|
|
8
|
+
* [#478](https://github.com/simplabs/ember-promise-modals/pull/478) Update to latest addon blueprint ([@pichfl](https://github.com/pichfl))
|
|
9
|
+
* [#438](https://github.com/simplabs/ember-promise-modals/pull/438) bump @ember/test-waiters to 3.0.0 ([@nickschot](https://github.com/nickschot))
|
|
10
|
+
* [#437](https://github.com/simplabs/ember-promise-modals/pull/437) Drop Node 10 support ([@nickschot](https://github.com/nickschot))
|
|
11
|
+
* [#427](https://github.com/simplabs/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
|
|
12
|
+
* [#148](https://github.com/simplabs/ember-promise-modals/pull/148) Replace ember-animated with CSS animations ([@pichfl](https://github.com/pichfl))
|
|
13
|
+
|
|
14
|
+
#### :rocket: Enhancement
|
|
15
|
+
* [#549](https://github.com/simplabs/ember-promise-modals/pull/549) Enhance focus trap configuration ([@zeppelin](https://github.com/zeppelin))
|
|
16
|
+
* [#533](https://github.com/simplabs/ember-promise-modals/pull/533) Legacy: Downgrade native class to Ember.Object ([@pichfl](https://github.com/pichfl))
|
|
17
|
+
* [#436](https://github.com/simplabs/ember-promise-modals/pull/436) Embroider optimized compatibility ([@nickschot](https://github.com/nickschot))
|
|
18
|
+
* [#517](https://github.com/simplabs/ember-promise-modals/pull/517) Add option to disable focus trap ([@zeppelin](https://github.com/zeppelin))
|
|
19
|
+
* [#427](https://github.com/simplabs/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
|
|
20
|
+
* [#421](https://github.com/simplabs/ember-promise-modals/pull/421) add optional onAnimationModalOutEnd hook ([@nickschot](https://github.com/nickschot))
|
|
21
|
+
* [#148](https://github.com/simplabs/ember-promise-modals/pull/148) Replace ember-animated with CSS animations ([@pichfl](https://github.com/pichfl))
|
|
22
|
+
|
|
23
|
+
#### :bug: Bug Fix
|
|
24
|
+
* [#422](https://github.com/simplabs/ember-promise-modals/pull/422) fix promise-modals from breaking when used in another addon instead of an app ([@nickschot](https://github.com/nickschot))
|
|
25
|
+
* [#420](https://github.com/simplabs/ember-promise-modals/pull/420) explicitly specify animation delay and duration as separate to make sure they're properly used by the browser ([@nickschot](https://github.com/nickschot))
|
|
26
|
+
* [#419](https://github.com/simplabs/ember-promise-modals/pull/419) fix setting a delay on the backdrop or modal makes animation break ([@nickschot](https://github.com/nickschot))
|
|
27
|
+
* [#412](https://github.com/simplabs/ember-promise-modals/pull/412) fix backdrop not animating immediately after the last modal is closed ([@nickschot](https://github.com/nickschot))
|
|
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
|
+
* [#432](https://github.com/simplabs/ember-promise-modals/pull/432) Fix responsiveness of dummy app ([@nickschot](https://github.com/nickschot))
|
|
32
|
+
* [#414](https://github.com/simplabs/ember-promise-modals/pull/414) Improve README and dummy application ([@pichfl](https://github.com/pichfl))
|
|
33
|
+
|
|
34
|
+
#### :house: Internal
|
|
35
|
+
* [#594](https://github.com/simplabs/ember-promise-modals/pull/594) Configure release-it ([@pichfl](https://github.com/pichfl))
|
|
36
|
+
* [#570](https://github.com/simplabs/ember-promise-modals/pull/570) Setup Renovatebot ([@nickschot](https://github.com/nickschot))
|
|
37
|
+
* [#477](https://github.com/simplabs/ember-promise-modals/pull/477) Replace Yarn with pnpm ([@pichfl](https://github.com/pichfl))
|
|
38
|
+
* [#530](https://github.com/simplabs/ember-promise-modals/pull/530) Internal: Extend and apply prettier configuration ([@pichfl](https://github.com/pichfl))
|
|
39
|
+
* [#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))
|
|
40
|
+
* [#499](https://github.com/simplabs/ember-promise-modals/pull/499) Update ember-release scenario to use auto-import v2 ([@nickschot](https://github.com/nickschot))
|
|
41
|
+
* [#431](https://github.com/simplabs/ember-promise-modals/pull/431) Use env=production when building the dummy application ([@pichfl](https://github.com/pichfl))
|
|
42
|
+
* [#430](https://github.com/simplabs/ember-promise-modals/pull/430) Update production build path for GitHub pages ([@pichfl](https://github.com/pichfl))
|
|
43
|
+
* [#415](https://github.com/simplabs/ember-promise-modals/pull/415) Deploy dummy application to Github pages ([@pichfl](https://github.com/pichfl))
|
|
44
|
+
* [#417](https://github.com/simplabs/ember-promise-modals/pull/417) Delete unused modal service file from dummy app ([@nickschot](https://github.com/nickschot))
|
|
45
|
+
* [#413](https://github.com/simplabs/ember-promise-modals/pull/413) use babel-eslint as eslint parser ([@nickschot](https://github.com/nickschot))
|
|
46
|
+
* [#407](https://github.com/simplabs/ember-promise-modals/pull/407) upgrade to ember-qunit v5 ([@nickschot](https://github.com/nickschot))
|
|
47
|
+
* [#309](https://github.com/simplabs/ember-promise-modals/pull/309) Update addon layout according to latest ember addon blueprint ([@pichfl](https://github.com/pichfl))
|
|
48
|
+
|
|
49
|
+
#### Committers: 4
|
|
50
|
+
- Anass OUMIRI ([@aoumiri](https://github.com/aoumiri))
|
|
51
|
+
- Florian Pichler ([@pichfl](https://github.com/pichfl))
|
|
52
|
+
- Gabor Babicz ([@zeppelin](https://github.com/zeppelin))
|
|
53
|
+
- Nick Schot ([@nickschot](https://github.com/nickschot))
|
|
54
|
+
|
|
55
|
+
## v2.0.0 (2021-09-01)
|
|
56
|
+
|
|
57
|
+
#### :boom: Breaking Change
|
|
58
|
+
* [#427](https://github.com/simplabs/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
|
|
59
|
+
|
|
60
|
+
#### :rocket: Enhancement
|
|
61
|
+
* [#427](https://github.com/simplabs/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
|
|
62
|
+
|
|
63
|
+
#### :memo: Documentation
|
|
64
|
+
* [#432](https://github.com/simplabs/ember-promise-modals/pull/432) Fix responsiveness of dummy app ([@nickschot](https://github.com/nickschot))
|
|
65
|
+
* [#414](https://github.com/simplabs/ember-promise-modals/pull/414) Improve README and dummy application ([@pichfl](https://github.com/pichfl))
|
|
66
|
+
|
|
67
|
+
#### :house: Internal
|
|
68
|
+
* [#431](https://github.com/simplabs/ember-promise-modals/pull/431) Use env=production when building the dummy application ([@pichfl](https://github.com/pichfl))
|
|
69
|
+
* [#430](https://github.com/simplabs/ember-promise-modals/pull/430) Update production build path for GitHub pages ([@pichfl](https://github.com/pichfl))
|
|
70
|
+
* [#415](https://github.com/simplabs/ember-promise-modals/pull/415) Deploy dummy application to Github pages ([@pichfl](https://github.com/pichfl))
|
|
71
|
+
|
|
72
|
+
#### Committers: 4
|
|
73
|
+
- Anass OUMIRI ([@aoumiri](https://github.com/aoumiri))
|
|
74
|
+
- Florian Pichler ([@pichfl](https://github.com/pichfl))
|
|
75
|
+
- Nick Schot ([@nickschot](https://github.com/nickschot))
|
|
76
|
+
- [@dependabot-preview[bot]](https://github.com/apps/dependabot-preview)
|
|
77
|
+
|
|
78
|
+
|
|
3
79
|
## v1.1.1 (2021-07-27)
|
|
4
80
|
|
|
5
81
|
#### :bug: Bug Fix
|
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
|
@@ -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
|
|
|
@@ -26,30 +26,57 @@ To use EPM in your project, add the target for the modals to your `application.h
|
|
|
26
26
|
|
|
27
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
|
-
```
|
|
29
|
+
```js
|
|
30
30
|
import { inject as service } from '@ember/service';
|
|
31
31
|
|
|
32
32
|
export default class extends Component {
|
|
33
33
|
@service modals;
|
|
34
34
|
|
|
35
35
|
@action
|
|
36
|
-
handleOpenModal() {
|
|
37
|
-
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();
|
|
38
49
|
}
|
|
39
50
|
}
|
|
40
51
|
```
|
|
41
52
|
|
|
42
|
-
```
|
|
43
|
-
<button type=
|
|
53
|
+
```hbs
|
|
54
|
+
<button type='button' {{on 'click' this.handleOpenModal}}>
|
|
44
55
|
Click Me!
|
|
45
56
|
</button>
|
|
46
57
|
```
|
|
47
58
|
|
|
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
|
+
|
|
48
75
|
### Passing data to the rendered component
|
|
49
76
|
|
|
50
77
|
You can pass custom data into your rendered template like so:
|
|
51
78
|
|
|
52
|
-
```
|
|
79
|
+
```js
|
|
53
80
|
this.modals.open('file-preview', {
|
|
54
81
|
fileUrl: this.fileUrl,
|
|
55
82
|
});
|
|
@@ -57,12 +84,12 @@ this.modals.open('file-preview', {
|
|
|
57
84
|
|
|
58
85
|
All passed attributes can be accessed from the passed-in `data` object:
|
|
59
86
|
|
|
60
|
-
```
|
|
87
|
+
```hbs
|
|
61
88
|
<!-- components/file-preview.hbs -->
|
|
62
89
|
<img src={{@data.fileUrl}} />
|
|
63
90
|
```
|
|
64
91
|
|
|
65
|
-
```
|
|
92
|
+
```js
|
|
66
93
|
// components/file-preview.js
|
|
67
94
|
this.args.data.fileUrl; // or this.data.fileUrl in classic components
|
|
68
95
|
```
|
|
@@ -70,14 +97,14 @@ this.args.data.fileUrl; // or this.data.fileUrl in classic components
|
|
|
70
97
|
**NOTE:** By default, a `close` method is passed in your rendered component, in
|
|
71
98
|
order to trigger the "close modal" action. It can be called like so:
|
|
72
99
|
|
|
73
|
-
```
|
|
100
|
+
```hbs
|
|
74
101
|
<!-- components/file-preview.hbs -->
|
|
75
|
-
<button {{on
|
|
102
|
+
<button type='button' {{on 'click' (fn @close results)}}>Close</button>
|
|
76
103
|
```
|
|
77
104
|
|
|
78
|
-
```
|
|
105
|
+
```js
|
|
79
106
|
// components/file-preview.js
|
|
80
|
-
this.args.close(); // or this.close() in classic components
|
|
107
|
+
this.args.close(results); // or this.close() in classic components
|
|
81
108
|
```
|
|
82
109
|
|
|
83
110
|
## Animation
|
|
@@ -97,7 +124,7 @@ detected.
|
|
|
97
124
|
To override the animation for a specific modal, an `options` object containing
|
|
98
125
|
a custom `className` can be handed to the `.open()` method.
|
|
99
126
|
|
|
100
|
-
```
|
|
127
|
+
```js
|
|
101
128
|
this.modals.open(
|
|
102
129
|
'file-preview',
|
|
103
130
|
{
|
|
@@ -108,12 +135,12 @@ this.modals.open(
|
|
|
108
135
|
className: 'custom-modal',
|
|
109
136
|
// optional: name the animation triggered by the custom css class
|
|
110
137
|
// animations ending in "-out" are detected by default!
|
|
111
|
-
// 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
|
|
112
139
|
// can't have an animation ending in '-out'
|
|
113
140
|
animationKeyframesOutName: 'custom-animation-name-out',
|
|
114
141
|
// optional: a hook that is called when the closing animation of
|
|
115
142
|
// the modal (so not the backdrop) has finished.
|
|
116
|
-
onAnimationModalOutEnd: () => {}
|
|
143
|
+
onAnimationModalOutEnd: () => {},
|
|
117
144
|
},
|
|
118
145
|
);
|
|
119
146
|
```
|
|
@@ -156,12 +183,12 @@ The CSS animations which are applied by the custom CSS class _must_ end in
|
|
|
156
183
|
|
|
157
184
|
#### Examples
|
|
158
185
|
|
|
159
|
-
Examples for custom animations and how to apply them can be found in the addons
|
|
160
|
-
dummy application.
|
|
186
|
+
Examples for custom animations and how to apply them can be found in the addons
|
|
187
|
+
dummy application.
|
|
161
188
|
|
|
162
|
-
See [the application.js controller](./tests/dummy/app/controllers/application.js)
|
|
189
|
+
See [the application.js controller](./tests/dummy/app/controllers/application.js)
|
|
163
190
|
for how the modals are openend in your JavaScript actions and look at
|
|
164
|
-
[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
|
|
165
192
|
custom animations.
|
|
166
193
|
|
|
167
194
|
### CSS Variables
|
|
@@ -199,6 +226,64 @@ EPM will ensure to [focus the first "tabbable element" by default](https://www.w
|
|
|
199
226
|
If no focusable element is present, focus will be applied on the currently
|
|
200
227
|
visible auto-generated container for the current modal.
|
|
201
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
|
+
|
|
202
287
|
## Testing
|
|
203
288
|
|
|
204
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
|
+
onDeactivate: () => {
|
|
48
|
+
this.focusTrapOptions.onDeactivate?.();
|
|
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,4 +1,5 @@
|
|
|
1
1
|
import { A } from '@ember/array';
|
|
2
|
+
import { deprecate } from '@ember/debug';
|
|
2
3
|
import { computed } from '@ember/object';
|
|
3
4
|
import { alias } from '@ember/object/computed';
|
|
4
5
|
import Service from '@ember/service';
|
|
@@ -11,17 +12,46 @@ export default Service.extend({
|
|
|
11
12
|
}),
|
|
12
13
|
top: alias('_stack.lastObject'),
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
focusTrapOptions: undefined,
|
|
16
|
+
clickOutsideDeactivates: undefined,
|
|
15
17
|
|
|
16
18
|
init() {
|
|
17
19
|
this._super(...arguments);
|
|
18
20
|
this._stack = A([]);
|
|
21
|
+
|
|
22
|
+
deprecate(
|
|
23
|
+
'Defining `clickOutsideDeactivates` directly on the `modals` service is deprecated. ' +
|
|
24
|
+
`Please use \`focusTrapOptions: { clickOutsideDeactivates: ${this.clickOutsideDeactivates} }\` instead.`,
|
|
25
|
+
typeof this.clickOutsideDeactivates === 'undefined',
|
|
26
|
+
{
|
|
27
|
+
id: 'ember-promise-modals.clickOutsideDeactivates-on-modals-service',
|
|
28
|
+
since: '2.1.0',
|
|
29
|
+
until: '3.0.0',
|
|
30
|
+
for: 'ember-promise-modals',
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (this.focusTrapOptions !== null) {
|
|
35
|
+
let focusTrapOptions = this.focusTrapOptions ?? {};
|
|
36
|
+
let clickOutsideDeactivates = focusTrapOptions.clickOutsideDeactivates ?? this.clickOutsideDeactivates ?? true;
|
|
37
|
+
|
|
38
|
+
this.focusTrapOptions = {
|
|
39
|
+
...this.focusTrapOptions,
|
|
40
|
+
clickOutsideDeactivates,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
19
43
|
},
|
|
20
44
|
|
|
21
45
|
willDestroy() {
|
|
22
46
|
this._onLastModalRemoved();
|
|
23
47
|
},
|
|
24
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} name component path
|
|
51
|
+
* @param {*} data passed to the component template
|
|
52
|
+
* @param {ModalOptions} options applied to the modal
|
|
53
|
+
* @returns {Modal}
|
|
54
|
+
*/
|
|
25
55
|
open(name, data, options) {
|
|
26
56
|
let modal = new Modal(this, name, data, options);
|
|
27
57
|
|
|
@@ -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
|
|