-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ember-auto-import to bring in ClipboardJS
- Replace window.ClipboardJS with an import - Make ember-auto-import a dependency - Bump ClipboardJS version to add SSR support - Bump ember-cli-babel - Check for FastBoot in is-clipboard-supported helper - Add FastBoot test
- Loading branch information
Showing
8 changed files
with
621 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import Helper from '@ember/component/helper'; | ||
import ClipboardJS from 'clipboard'; | ||
import { getOwner } from '@ember/application'; | ||
|
||
export const isClipboardSupported = | ||
window && window.ClipboardJS ? window.ClipboardJS.isSupported : () => false; | ||
export default helper(isClipboardSupported); | ||
export default class IsClipboardSupportedHelper extends Helper { | ||
constructor() { | ||
super(...arguments); | ||
const service = getOwner(this).lookup('service:fastboot'); | ||
this.isFastboot = service?.isFastBoot; | ||
} | ||
|
||
compute([action]) { | ||
const { isFastboot } = this; | ||
return isFastboot ? false : ClipboardJS.isSupported(action); | ||
} | ||
} |
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,23 +1,5 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var fastbootTransform = require('fastboot-transform'); | ||
|
||
module.exports = { | ||
name: require('./package').name, | ||
|
||
treeForVendor() { | ||
var Funnel = require('broccoli-funnel'); | ||
var clipboardPath = path.join(path.dirname(require.resolve('clipboard')), '..'); | ||
|
||
return new fastbootTransform(Funnel(this.treeGenerator(clipboardPath), { | ||
destDir: 'clipboard' | ||
})); | ||
}, | ||
|
||
included() { | ||
this._super.included.apply(this, arguments); | ||
|
||
this.import('vendor/clipboard/dist/clipboard.js'); | ||
} | ||
}; |
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,19 @@ | ||
import { module, test } from 'qunit'; | ||
import { setup, visit } from 'ember-cli-fastboot-testing/test-support'; | ||
|
||
module('FastBoot | fastboot', function (hooks) { | ||
setup(hooks); | ||
|
||
test('it renders with FastBoot', async function (assert) { | ||
await visit('/'); | ||
assert | ||
.dom('button.copy-btn') | ||
.exists({ count: 4 }, '`<CopyButton>` renders in FastBoot'); | ||
assert | ||
.dom('.application__supported-text') | ||
.hasText( | ||
'Clipboard is not supported', | ||
'`{{is-clipboard-supported}}` returns `false` in FastBoot' | ||
); | ||
}); | ||
}); |
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,33 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import ClipboardJS from 'clipboard'; | ||
|
||
module('Integration | Helper | is-clipboard-supported', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('isClipboardSupported works same as ClipboardJS.isSupported', async function (assert) { | ||
await render(hbs`{{is-clipboard-supported this.action}}`); | ||
[undefined, 'cut', 'copy', 'not-a-action'].forEach((action) => { | ||
this.set('action', action); | ||
assert | ||
.dom() | ||
.hasText( | ||
`${ClipboardJS.isSupported(this.action)}`, | ||
`\`is-clipboard-supported\` returns the correct value when given \`${action}\` action param` | ||
); | ||
}); | ||
}); | ||
|
||
test('isClipboardSupported when FastBoot is not present', async function (assert) { | ||
this.owner.register('service:fastboot', null, { instantiate: false }); | ||
await render(hbs`{{is-clipboard-supported}}`); | ||
assert | ||
.dom() | ||
.hasText( | ||
`${ClipboardJS.isSupported()}`, | ||
'`is-clipboard-supported` works when FastBoot is not present' | ||
); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.