-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 #263 from codex-team/delete-block
Events triggering
- Loading branch information
Showing
19 changed files
with
834 additions
and
37 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
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,50 @@ | ||
# CodeX Editor Events Module | ||
|
||
Module allows Developers to subscribe on events or trigger own events | ||
|
||
## Methods | ||
|
||
### On | ||
|
||
```javascript | ||
Events.on(eventName, callback) | ||
``` | ||
|
||
> Method subscribes callback on event. It will be called when CodeX Editor emits this event | ||
#### params | ||
|
||
| Param | Type | Description| | ||
| -------------|------ |:-------------:| | ||
| eventName | String | event name| | ||
| callback | Function | event callback| | ||
|
||
### Off | ||
|
||
```javascript | ||
Events.off(eventName, callback) | ||
``` | ||
|
||
> Method unsubscribes callback on event | ||
#### params | ||
|
||
| Param | Type | Description| | ||
| -------------|------ |:-------------:| | ||
| eventName | String | event name| | ||
| callback | Function | event callback| | ||
|
||
### Emit | ||
|
||
```javascript | ||
Events.emit(eventName, data) | ||
``` | ||
|
||
> Method emits data to all subscribed callbacks | ||
#### params | ||
|
||
| Param | Type | Description| | ||
| -------------|------ |:-------------:| | ||
| eventName | String | event name| | ||
| data | Object | any data| |
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,98 @@ | ||
/** | ||
* @class DeleteTune | ||
* @classdesc Editor's default tune that moves up selected block | ||
* | ||
* @copyright <CodeX Team> 2018 | ||
*/ | ||
import IBlockTune from './block-tune'; | ||
|
||
declare var $: any; | ||
declare var _: any; | ||
|
||
export default class DeleteTune implements IBlockTune { | ||
|
||
/** | ||
* Property that contains CodeX Editor API methods | ||
* @see {docs/api.md} | ||
*/ | ||
private readonly api: any; | ||
|
||
/** | ||
* Styles | ||
* @type {{wrapper: string}} | ||
*/ | ||
private CSS = { | ||
wrapper: 'ass', | ||
}; | ||
|
||
/** | ||
* Delete confirmation | ||
*/ | ||
private needConfirmation: boolean; | ||
|
||
/** | ||
* DeleteTune constructor | ||
* | ||
* @param {Object} api | ||
*/ | ||
public constructor({api}) { | ||
this.api = api; | ||
|
||
this.resetConfirmation = () => { | ||
this.setConfirmation(false); | ||
}; | ||
} | ||
|
||
/** | ||
* change tune state | ||
*/ | ||
private setConfirmation(state): void { | ||
this.needConfirmation = state; | ||
} | ||
|
||
/** | ||
* set false confirmation state | ||
*/ | ||
private resetConfirmation: () => void; | ||
|
||
/** | ||
* Create "Delete" button and add click event listener | ||
* @returns [Element} | ||
*/ | ||
public render() { | ||
const deleteButton = $.make('div', ['ce-settings-delete'], {}); | ||
deleteButton.addEventListener('click', (event) => this.handleClick(event), false); | ||
return deleteButton; | ||
} | ||
|
||
/** | ||
* Delete block conditions passed | ||
* @param {MouseEvent} event | ||
*/ | ||
public handleClick(event: MouseEvent): void { | ||
|
||
/** | ||
* if block is not waiting the confirmation, subscribe on block-settings-closing event to reset | ||
* otherwise delete block | ||
*/ | ||
if (!this.needConfirmation) { | ||
this.setConfirmation(true); | ||
|
||
/** | ||
* Subscribe on event. | ||
* When toolbar block settings is closed but block deletion is not confirmed, | ||
* then reset confirmation state | ||
*/ | ||
this.api.events.on('block-settings-closed', this.resetConfirmation); | ||
|
||
} else { | ||
|
||
/** | ||
* Unsubscribe from block-settings closing event | ||
*/ | ||
this.api.events.off('block-settings-closed', this.resetConfirmation); | ||
|
||
this.api.blocks.delete(); | ||
} | ||
} | ||
} |
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,58 @@ | ||
declare var Module: any; | ||
|
||
import { IEventsAPI } from '../interfaces/api'; | ||
|
||
/** | ||
* @class EventsAPI | ||
* provides with methods working with Toolbar | ||
*/ | ||
export default class EventsAPI extends Module implements IEventsAPI { | ||
|
||
/** | ||
* Save Editor config. API provides passed configuration to the Blocks | ||
* @param {EditorsConfig} config | ||
*/ | ||
constructor({config}) { | ||
super({config}); | ||
} | ||
|
||
/** | ||
* Available methods | ||
* @return {IEventsAPI} | ||
*/ | ||
get methods(): IEventsAPI { | ||
return { | ||
emit: (eventName: string, data: object) => this.emit(eventName, data), | ||
off: (eventName: string, callback: () => void) => this.off(eventName, callback), | ||
on: (eventName: string, callback: () => void) => this.on(eventName, callback), | ||
}; | ||
} | ||
|
||
/** | ||
* Subscribe on Events | ||
* @param {String} eventName | ||
* @param {Function} callback | ||
*/ | ||
public on(eventName, callback): void { | ||
this.Editor.Events.on(eventName, callback); | ||
} | ||
|
||
/** | ||
* Emit event with data | ||
* @param {String} eventName | ||
* @param {Object} data | ||
*/ | ||
public emit(eventName, data): void { | ||
this.Editor.Events.emit(eventName, data); | ||
} | ||
|
||
/** | ||
* Unsubscribe from Event | ||
* @param {String} eventName | ||
* @param {Function} callback | ||
*/ | ||
public off(eventName, callback): void { | ||
this.Editor.Events.off(eventName, callback); | ||
} | ||
|
||
} |
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
Oops, something went wrong.