-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demo site improvement for Content Model (#1966)
* Demo site improvement for Content Model * fix plugin * Remove CutPasteListChain plugin from content model * remove Paste plugin
- Loading branch information
1 parent
87b6480
commit 997fd1f
Showing
7 changed files
with
91 additions
and
46 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
25 changes: 25 additions & 0 deletions
25
demo/scripts/controls/sidePane/editorOptions/codes/ContentModelButtonsCode.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import CodeElement from './CodeElement'; | ||
import { getObjectKeys } from 'roosterjs-editor-dom'; | ||
|
||
const codeMap: { [id: string]: string } = { | ||
buttonB: 'roosterjsContentModel.toggleBold(editor)', | ||
buttonI: 'roosterjsContentModel.toggleItalic(editor)', | ||
buttonU: 'roosterjsContentModel.toggleUnderline(editor)', | ||
buttonBullet: 'roosterjsContentModel.toggleBullet(editor)', | ||
buttonNumbering: 'roosterjsContentModel.toggleNumbering(editor)', | ||
buttonUndo: 'editor.undo()', | ||
buttonRedo: 'editor.redo()', | ||
}; | ||
const buttonDark = 'editor.setDarkModeState(!editor.isDarkMode())'; | ||
|
||
export default class ContentModelButtonsCode extends CodeElement { | ||
getCode() { | ||
const map = { ...codeMap, buttonDark: buttonDark }; | ||
return getObjectKeys(map) | ||
.map( | ||
id => | ||
`document.getElementById('${id}').addEventListener('click', () => ${map[id]});\n` | ||
) | ||
.join(''); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
demo/scripts/controls/sidePane/editorOptions/codes/ContentModelEditorCode.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import BuildInPluginState from '../../../BuildInPluginState'; | ||
import CodeElement from './CodeElement'; | ||
import ContentModelButtonsCode from './ContentModelButtonsCode'; | ||
import DarkModeCode from './DarkModeCode'; | ||
import DefaultFormatCode from './DefaultFormatCode'; | ||
import ExperimentalFeaturesCode from './ExperimentalFeaturesCode'; | ||
import PluginsCode from './PluginsCode'; | ||
|
||
export default class ContentModelEditorCode extends CodeElement { | ||
private plugins: PluginsCode; | ||
private defaultFormat: DefaultFormatCode; | ||
private buttons: ContentModelButtonsCode; | ||
private experimentalFeatures: ExperimentalFeaturesCode; | ||
private darkMode: DarkModeCode; | ||
|
||
constructor(state: BuildInPluginState) { | ||
super(); | ||
|
||
this.plugins = new PluginsCode(state); | ||
this.defaultFormat = new DefaultFormatCode(state.defaultFormat); | ||
this.buttons = new ContentModelButtonsCode(); | ||
this.experimentalFeatures = new ExperimentalFeaturesCode(state.experimentalFeatures); | ||
this.darkMode = new DarkModeCode(); | ||
} | ||
|
||
getCode() { | ||
let defaultFormat = this.defaultFormat.getCode(); | ||
let expermientalFeatures = this.experimentalFeatures.getCode(); | ||
let darkMode = this.darkMode.getCode(); | ||
let code = "let contentDiv = document.getElementById('contentDiv') as HTMLDivElement;\n"; | ||
code += `let plugins = ${this.plugins.getCode()};\n`; | ||
code += defaultFormat ? `let defaultFormat: DefaultFormat = ${defaultFormat};\n` : ''; | ||
code += 'let options: roosterjs.EditorOptions = {\n'; | ||
code += this.indent('plugins: plugins,\n'); | ||
code += defaultFormat ? this.indent('defaultFormat: defaultFormat,\n') : ''; | ||
code += expermientalFeatures | ||
? this.indent(`experimentalFeatures: [\n${expermientalFeatures}],\n`) | ||
: ''; | ||
code += darkMode ? this.indent(`getDarkColor: ${darkMode},\n`) : ''; | ||
code += '};\n'; | ||
code += 'let editor = new roosterjsContentModel.ContentModelEditor(contentDiv, options);\n'; | ||
code += this.buttons ? this.buttons.getCode() : ''; | ||
|
||
return code; | ||
} | ||
} |
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