-
Notifications
You must be signed in to change notification settings - Fork 98
TINY-11907: add support for 'disabled' property #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bc23fb2
TINY-11907: add support for 'disabled' property
michalnieruchalski-tiugo b563d89
TINY-11907: add dependency
michalnieruchalski-tiugo 9e2f049
TINY-11907: add 'readonly' property
michalnieruchalski-tiugo d5a6357
TINY-11907: add changelog
michalnieruchalski-tiugo 3a76143
TINY-11907: cleanup tiny versions
michalnieruchalski-tiugo e134a6d
TINY-11907: apply codereview comment
michalnieruchalski-tiugo f181d5e
TINY-11907: remove dependency
michalnieruchalski-tiugo d9a0f5b
TINY-11907: apply codereview comment
michalnieruchalski-tiugo 0c77869
retrigger checks
michalnieruchalski-tiugo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
| <button (click)="toggleReadonly()">{{ isReadonly ? 'Escape readonly' : 'Enter readonly' }}</button> | ||
| <editor | ||
| [apiKey]="apiKey" | ||
| [readonly]="isReadonly" | ||
| [initialValue]="initialValue" | ||
| [init]="{ height: 300 }" | ||
| /> |
This file contains hidden or 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,13 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { apiKey, sampleContent } from '../Settings'; | ||
|
|
||
| @Component({ | ||
| selector: 'readonly', | ||
| templateUrl: './Readonly.component.html', | ||
| }) | ||
| export class ReadonlyComponent { | ||
| public isReadonly = false; | ||
| public apiKey = apiKey; | ||
| public initialValue = sampleContent; | ||
| public toggleReadonly = () => (this.isReadonly = !this.isReadonly); | ||
| } |
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
tinymce-angular-component/src/main/ts/utils/DisabledUtils.ts
This file contains hidden or 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,12 @@ | ||
| import { getTinymce } from '../TinyMCE'; | ||
| import { TinyMCE } from 'tinymce'; | ||
|
|
||
| const isDisabledOptionSupported = () => { | ||
| const tiny: TinyMCE = getTinymce(); | ||
| // Disabled option is supported since Tiny 7.6.0 | ||
| return Number(tiny.majorVersion) > 7 || (Number(tiny.majorVersion) === 7 && Number(tiny.minorVersion) >= 6); | ||
| }; | ||
|
|
||
| export { | ||
| isDisabledOptionSupported | ||
| }; |
This file contains hidden or 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
107 changes: 107 additions & 0 deletions
107
tinymce-angular-component/src/test/ts/browser/DisabledPropertyTest.ts
This file contains hidden or 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,107 @@ | ||
| import { Assertions } from '@ephox/agar'; | ||
| import '../alien/InitTestEnvironment'; | ||
|
|
||
| import { EditorComponent } from '../../../main/ts/public_api'; | ||
| import { describe, it } from '@ephox/bedrock-client'; | ||
| import { eachVersionContext, editorHook } from '../alien/TestHooks'; | ||
| import { Editor } from 'tinymce'; | ||
|
|
||
| describe('DisabledPropertyTest', () => { | ||
| const getMode = (editor: Editor) => { | ||
| if (typeof editor.mode?.get === 'function') { | ||
| return editor.mode.get(); | ||
| } | ||
| return editor.readonly ? 'readonly' : 'design'; | ||
| }; | ||
| const assertDesignMode = (editor: Editor) => Assertions.assertEq('TinyMCE should be in design mode', 'design', getMode(editor)); | ||
| const assertReadonlyMode = (editor: Editor) => Assertions.assertEq('TinyMCE should be in readonly mode', 'readonly', getMode(editor)); | ||
| const assertDisabledOption = (editor: Editor, expected: boolean) => | ||
| Assertions.assertEq(`TinyMCE should have disabled option set to ${expected}`, expected, editor.options.get('disabled')); | ||
|
|
||
| eachVersionContext([ '7.5.0' ], () => { | ||
| const createFixture = editorHook(EditorComponent); | ||
|
|
||
| it(`Component 'disabled' property is mapped to editor 'readonly' property`, async () => { | ||
| const { editor } = await createFixture({ disabled: true }); | ||
| assertReadonlyMode(editor); | ||
| }); | ||
|
|
||
| it(`Toggling component's 'disabled' property is mapped to editor 'readonly' property`, async () => { | ||
| const fixture = await createFixture(); | ||
| const { editor } = fixture; | ||
|
|
||
| assertDesignMode(editor); | ||
|
|
||
| fixture.componentRef.setInput('disabled', true); | ||
| fixture.detectChanges(); | ||
| assertReadonlyMode(editor); | ||
|
|
||
| fixture.componentRef.setInput('disabled', false); | ||
| fixture.detectChanges(); | ||
| assertDesignMode(editor); | ||
| }); | ||
|
|
||
| it(`[disabled]=true [readonly]=false triggers readonly mode`, async () => { | ||
| const { editor } = await createFixture({ disabled: true, readonly: false }); | ||
| assertReadonlyMode(editor); | ||
| }); | ||
|
|
||
| it(`[disabled]=false [readonly]=true triggers readonly mode`, async () => { | ||
| const { editor } = await createFixture({ disabled: false, readonly: true }); | ||
| assertReadonlyMode(editor); | ||
| }); | ||
| }); | ||
|
|
||
| eachVersionContext([ '7' ], () => { | ||
| const createFixture = editorHook(EditorComponent); | ||
|
|
||
| it(`Component 'disabled' property is mapped to editor 'disabled' property`, async () => { | ||
| const { editor } = await createFixture({ disabled: true }); | ||
|
|
||
| Assertions.assertEq('TinyMCE should have disabled option set to true', true, editor.options.get('disabled')); | ||
| assertDesignMode(editor); | ||
| }); | ||
|
|
||
| it(`Toggling component's 'disabled' property is mapped to editor 'disabled' property`, async () => { | ||
| const fixture = await createFixture(); | ||
| const { editor } = fixture; | ||
|
|
||
| assertDesignMode(editor); | ||
| assertDisabledOption(editor, false); | ||
|
|
||
| fixture.componentRef.setInput('disabled', true); | ||
| fixture.detectChanges(); | ||
| assertDesignMode(editor); | ||
| assertDisabledOption(editor, true); | ||
|
|
||
| fixture.componentRef.setInput('disabled', false); | ||
| fixture.detectChanges(); | ||
| assertDesignMode(editor); | ||
| assertDisabledOption(editor, false); | ||
| }); | ||
| }); | ||
|
|
||
| eachVersionContext([ '4', '5', '6', '7' ], () => { | ||
| const createFixture = editorHook(EditorComponent); | ||
|
|
||
| it(`Setting the 'readonly' property causing readonly mode`, async () => { | ||
| const { editor } = await createFixture({ readonly: true }); | ||
| assertReadonlyMode(editor); | ||
| }); | ||
|
|
||
| it(`Toggling component's 'readonly' property is mapped to editor 'readonly' mode`, async () => { | ||
| const fixture = await createFixture(); | ||
| const { editor } = fixture; | ||
|
|
||
| assertDesignMode(editor); | ||
|
|
||
| fixture.componentRef.setInput('readonly', true); | ||
| fixture.detectChanges(); | ||
| assertReadonlyMode(editor); | ||
|
|
||
| fixture.componentRef.setInput('readonly', false); | ||
| fixture.detectChanges(); | ||
| assertDesignMode(editor); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.