-
Notifications
You must be signed in to change notification settings - Fork 0
Added ability to create extensions #6
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 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ac4273d
Added ability to create extensions
slaveeks 20e5514
Removed editorjs.config.sample.js
slaveeks 1f1df16
Removed config from extensions
slaveeks 655734f
Removed default editorConfig properties from editor.config.sample.ts
slaveeks 1017f00
Update extensions/ReadOnly.ts
slaveeks 58141d5
Removed stand.css template, added separate class for adding extension…
slaveeks 85530c3
Added getting editor.js holder from editorConfig, set 'editorjs' as d…
slaveeks 83ee5a3
Editor holder not hardcoded in stand
slaveeks 52d1f66
Some code style fixes in templates
slaveeks 1a4027d
Update dev-stand/src/templates/stand-template.js
slaveeks 11ffe5a
Fixed line breaks in tsconfig, changed StandAPI by passing element to it
slaveeks 5a0109f
Merge branch 'feature/added-extensions' of github.com:editor-js/dev-t…
slaveeks 3e74294
Renamed addExtensionToStand to add in StandExtension
slaveeks 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** | ||
| * Class for stand API, which is used to interact with Stand | ||
| */ | ||
| export default class StandAPI { | ||
| /** | ||
| * Editor.js wrapper | ||
| */ | ||
| public editorWrapper: HTMLDivElement; | ||
|
|
||
| /** | ||
| * Constructor for stand API | ||
| * | ||
| * @param {string} holder - editor.js holder name | ||
| */ | ||
| constructor(holder: string) { | ||
| this.editorWrapper = document.getElementById(holder) as HTMLDivElement; | ||
| } | ||
| } |
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,113 @@ | ||
| import Extension from '../types/extension'; | ||
|
|
||
| /** | ||
| * Class for adding extension to stand | ||
| */ | ||
| export default class StandExtension { | ||
| /** | ||
| * Extension instance | ||
| */ | ||
| public readonly extension: Extension; | ||
|
|
||
| /** | ||
| * Constructor for stand extension | ||
| * | ||
| * @param extension - extension instance | ||
| */ | ||
| constructor(extension: Extension) { | ||
| this.extension = extension; | ||
| } | ||
|
|
||
| /** | ||
| * Get CSS classes for stand extension | ||
| */ | ||
| private static getCSS(): {[key: string]: string} { | ||
| return { | ||
| devStandExtensionButton: `dev-stand__extensions-button`, | ||
| devStandExtensionButtonActive: `dev-stand__extensions-button--active`, | ||
| devStandExtensionItem: `dev-stand__extensions-item`, | ||
| devStandExtensions: `dev-stand__extensions`, | ||
|
|
||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Add extension to stand | ||
| */ | ||
| public addExtensionToStand(): void { | ||
| this.addExtensionStyles(); | ||
|
|
||
| /** | ||
| * Create elements for extension | ||
| */ | ||
| const btn = this.createExtensionButton(); | ||
| const title = this.createExtensionTitle(); | ||
| const container = this.createExtensionContainer(); | ||
|
|
||
| /** | ||
| * Append button and title to extension container | ||
| */ | ||
| container.appendChild(title); | ||
| container.appendChild(btn); | ||
|
|
||
| /** | ||
| * Append extension container to extensions | ||
| */ | ||
| const extensionsContainer = document.getElementsByClassName(StandExtension.getCSS().devStandExtensions)[0]; | ||
|
|
||
| if (extensionsContainer) { | ||
| extensionsContainer.appendChild(container); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Add extension styles to stand | ||
| */ | ||
| private addExtensionStyles(): void { | ||
| if (!this.extension.styles) { | ||
| return; | ||
| } | ||
| const styleElement = document.createElement('style'); | ||
|
|
||
| styleElement.textContent += this.extension.styles; | ||
| document.head.appendChild(styleElement); | ||
| } | ||
|
|
||
| /** | ||
| * Create extension toggle button | ||
| */ | ||
| private createExtensionButton(): HTMLButtonElement { | ||
| const button = document.createElement('button'); | ||
|
|
||
| button.innerHTML = this.extension.control.icon; | ||
| button.addEventListener('click', () => { | ||
| this.extension.control.onActivate(); | ||
| button.classList.toggle(StandExtension.getCSS().devStandExtensionButtonActive); | ||
| }); | ||
| button.classList.add(StandExtension.getCSS().devStandExtensionButton); | ||
|
|
||
| return button; | ||
| } | ||
|
|
||
| /** | ||
| * Create container for extension | ||
| */ | ||
| private createExtensionContainer(): HTMLDivElement { | ||
| const container = document.createElement('div'); | ||
|
|
||
| container.classList.add(StandExtension.getCSS().devStandExtensionItem); | ||
|
|
||
| return container; | ||
| } | ||
|
|
||
| /** | ||
| * Create extension title | ||
| */ | ||
| private createExtensionTitle(): HTMLDivElement { | ||
| const title = document.createElement('div'); | ||
|
|
||
| title.innerHTML = this.extension.control.title; | ||
|
|
||
| return title; | ||
| } | ||
| } |
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,14 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Editor.js Dev Stand</title> | ||
| <link rel="stylesheet" href="stand.css"> | ||
| </head> | ||
| <body> | ||
| <div class="dev-stand"> | ||
| <div class="dev-stand__content"></div> | ||
| <div class="dev-stand__extensions"></div> | ||
| </div> | ||
| </body> | ||
| </html> |
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,48 @@ | ||
| import config from '../editorjs.config'; | ||
| import StandAPI from './src/StandAPI/StandAPI'; | ||
| import StandExtension from './src/StandExtension/StandExtension'; | ||
|
|
||
| // {{{ Tools }}} | ||
|
|
||
| const editorConfig = config().editorConfig; | ||
| const extensions = config().extensions; | ||
|
|
||
| if (typeof editorConfig.tools === 'undefined') { | ||
| editorConfig.tools = {} | ||
| } | ||
|
|
||
| const devStandContentClass = 'dev-stand__content'; | ||
|
|
||
| /** | ||
| * Check if holder is set in config | ||
| */ | ||
| const editorHolderId = editorConfig.holder ? editorConfig.holder : 'editorjs'; | ||
|
|
||
| /** | ||
| * Create holder for editor | ||
| */ | ||
| const editorHolder = document.createElement('div'); | ||
| editorHolder.id = editorHolderId; | ||
|
|
||
| /** | ||
| * Append holder to dev-stand | ||
| */ | ||
| const devStandContent = document.querySelector(`.${devStandContentClass}`); | ||
| devStandContent.appendChild(editorHolder); | ||
|
|
||
| // {{{ Tools configuration }}} | ||
|
|
||
| // {{{ Core }}} | ||
|
|
||
| const standAPI = new StandAPI(editorHolderId); | ||
|
|
||
| /** | ||
| * Iterate over all extensions | ||
| */ | ||
| for (const extensionClass of extensions) { | ||
| const extension = new extensionClass(editor, standAPI); | ||
| const standExtension = new StandExtension(extension); | ||
| standExtension.addExtensionToStand(); | ||
slaveeks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
|
|
||
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,42 @@ | ||
| import StandAPI from '../StandAPI/StandAPI'; | ||
| import EditorJS from '@editorjs/editorjs'; | ||
|
|
||
| /** | ||
| * Extension control interface | ||
| */ | ||
| export interface Control { | ||
| /** | ||
| * Icon for extension | ||
| */ | ||
| icon: string; | ||
| /** | ||
| * Title for extension | ||
| */ | ||
| title: string; | ||
| /** | ||
| * Function to activate extension | ||
| */ | ||
| onActivate: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * Extension interface | ||
| */ | ||
| export default interface Extension { | ||
| /** | ||
| * Editor.js instance | ||
| */ | ||
| editor: EditorJS; | ||
| /** | ||
| * Stand API instance | ||
| */ | ||
| stand: StandAPI; | ||
| /** | ||
| * Getter for extension control | ||
| */ | ||
| readonly control: Control; | ||
| /** | ||
| * Getter for extension styles for editor.js wrapper | ||
| */ | ||
| readonly styles?: string; | ||
| } |
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,70 @@ | ||
| :root { | ||
| --color-bg-main: #fff; | ||
| --color-border-light: #E8E8EB; | ||
| --color-text-main: #000; | ||
| } | ||
|
|
||
| body { | ||
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; | ||
| font-size: 14px; | ||
| line-height: 1.5em; | ||
| margin: 0; | ||
| background: var(--color-bg-main); | ||
| color: var(--color-text-main); | ||
| } | ||
|
|
||
| .dev-stand { | ||
| font-size: 16.2px; | ||
| } | ||
|
|
||
| .dev-stand__extensions { | ||
| display: flex; | ||
| align-items: center; | ||
| position: fixed; | ||
| bottom: 0; | ||
| right: 0; | ||
| left: 0; | ||
| background: var(--color-bg-main); | ||
| border-radius: 8px 8px 0 0; | ||
| border-top: 1px solid var(--color-border-light); | ||
| box-shadow: 0 2px 6px var(--color-border-light); | ||
| font-size: 13px; | ||
| padding: 8px 15px; | ||
| z-index: 1; | ||
| user-select: none; | ||
| } | ||
|
|
||
| .dev-stand__extensions-item:not(:last-of-type)::after { | ||
| content: '|'; | ||
| color: #ddd; | ||
| margin: 0 15px 0 12px; | ||
| } | ||
|
|
||
| .dev-stand__extensions-item { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 10px; | ||
| } | ||
|
|
||
| .dev-stand__extensions-button { | ||
| display: inline-block; | ||
| padding: 3px 12px; | ||
| transition: all 150ms ease; | ||
| cursor: pointer; | ||
| border-radius: 31px; | ||
| background: #eff1f4; | ||
| text-align: center; | ||
| user-select: none; | ||
| border: 1px solid #e1e3e8; | ||
| } | ||
|
|
||
| .dev-stand__extensions-button--active { | ||
| background: gray; | ||
| } | ||
|
|
||
| .dev-stand__content { | ||
| max-width: 1100px; | ||
| margin: 0 auto; | ||
| -webkit-font-smoothing: antialiased; | ||
| -moz-osx-font-smoothing: grayscale; | ||
| } |
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,41 @@ | ||
| import EditorJS from '@editorjs/editorjs'; | ||
| import StandAPI from '../dev-stand/src/StandAPI/StandAPI'; | ||
| import Extension, { Control } from '../dev-stand/src/types/extension'; | ||
|
|
||
| /** | ||
| * Extension for toggle read only mode | ||
| */ | ||
| export default class ReadOnlyExtension implements Extension { | ||
| /** | ||
| * Editor.js instance | ||
| */ | ||
| public readonly editor: EditorJS; | ||
| /** | ||
| * Stand API with editor.js wrapper | ||
| */ | ||
| public readonly stand: StandAPI; | ||
|
|
||
| /** | ||
| * Constructor for read only extension | ||
| * | ||
| * @param editor - editor.js instance | ||
| * @param {StandAPI} stand - stand API instance | ||
| */ | ||
| constructor(editor: EditorJS, stand: StandAPI) { | ||
| this.editor = editor; | ||
| this.stand = stand; | ||
| } | ||
|
|
||
| /** | ||
| * Get extension control | ||
| */ | ||
| public get control(): Control { | ||
| return { | ||
| icon: '🔒', | ||
| title: 'Read Only', | ||
| onActivate: () => { | ||
| this.editor.readOnly.toggle(); | ||
| }, | ||
| }; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we pass
editorHolderelement instead of id? so we won't need to find it again in DOMThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done