-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from universal-ember/make-setup-async
[Breaking] Make tabster not required. new import for setting up tabster, and it's async.
- Loading branch information
Showing
10 changed files
with
94 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* @internal | ||
*/ | ||
export const PRIMITIVES = Symbol.for('ember-primitives-globals'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { registerDestructor } from '@ember/destroyable'; | ||
|
||
export async function setupTabster( | ||
/** | ||
* A destroyable object. | ||
* This is needed so that when the app (or tests) or unmounted or ending, | ||
* the tabster instance can be disposed of. | ||
*/ | ||
context: object, | ||
{ | ||
tabster, | ||
setTabsterRoot, | ||
}: { | ||
/** | ||
* Let this setup function initalize tabster. | ||
* https://tabster.io/docs/core | ||
* | ||
* This should be done only once per application as we don't want | ||
* focus managers fighting with each other. | ||
* | ||
* Defaults to `true`, | ||
* | ||
* Will fallback to an existing tabster instance automatically if `getTabster` returns a value. | ||
* | ||
* If `false` is explicitly passed here, you'll also be in charge of teardown. | ||
*/ | ||
tabster?: boolean; | ||
setTabsterRoot?: boolean; | ||
} = {} | ||
) { | ||
const { createTabster, getDeloser, getMover, getTabster, disposeTabster } = await import( | ||
'tabster' | ||
); | ||
|
||
tabster ??= true; | ||
setTabsterRoot ??= true; | ||
|
||
if (!tabster) { | ||
return; | ||
} | ||
|
||
let existing = getTabster(window); | ||
let primitivesTabster = existing ?? createTabster(window); | ||
|
||
getMover(primitivesTabster); | ||
getDeloser(primitivesTabster); | ||
|
||
if (setTabsterRoot) { | ||
document.body.setAttribute('data-tabster', '{ "root": {} }'); | ||
} | ||
|
||
registerDestructor(context, () => { | ||
disposeTabster(primitivesTabster); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
import { assert } from '@ember/debug'; | ||
|
||
import type SetupService from '../services/ember-primitives/setup.ts'; | ||
import { setupTabster as _setupTabster } from '../tabster.ts'; | ||
|
||
import type Owner from '@ember/owner'; | ||
|
||
/** | ||
* Sets up all support utilities for primitive components. | ||
* Including the tabster root. | ||
*/ | ||
export function setup(owner: Owner) { | ||
let service = owner.lookup('service:ember-primitives/setup'); | ||
async function setup(owner: Owner) { | ||
_setupTabster(owner, { setTabsterRoot: false }); | ||
|
||
assert('Could not find the ember-primitives service', service); | ||
document.querySelector('#ember-testing')?.setAttribute('data-tabster', '{ "root": {} }'); | ||
} | ||
|
||
(service as SetupService).setup({ setTabsterRoot: false }); | ||
export function setupTabster(hooks: { | ||
beforeEach: (callback: () => void | Promise<void>) => unknown; | ||
}) { | ||
hooks.beforeEach(function (this: { owner: object }) { | ||
let owner = this.owner; | ||
|
||
document.querySelector('#ember-testing')?.setAttribute('data-tabster', '{ "root": {} }'); | ||
assert( | ||
`Test does not have an owner, be sure to use setupRenderingTest, setupTest, or setupApplicationTest (from ember-qunit (or similar))`, | ||
owner | ||
); | ||
|
||
setup(this.owner as Owner); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { setupTabster } from './a11y.ts'; | ||
export { fillOTP } from './otp.ts'; | ||
export { getRouter, setupRouting } from './routing.ts'; | ||
export { ZoetropeHelper } from './zoetrope.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters