Two build targets — core and full
dist/ribbit/ribbit-core.js — editor without extra features dist/ribbit/ribbit.js — editor with all features Added a theme feature flag for vim keybindings
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* ribbit-core.ts — lightweight entry point without optional features (vim).
|
||||
*
|
||||
* Same API as ribbit-editor.ts but excludes VimHandler.
|
||||
*/
|
||||
|
||||
import { HopDown } from './hopdown';
|
||||
import { defaultTags, defaultBlockTags, defaultInlineTags, inlineTag } from './tags';
|
||||
import { defaultTheme } from './default-theme';
|
||||
import { Ribbit, camelCase, decodeHtmlEntities, encodeHtmlEntities } from './ribbit';
|
||||
import { type MacroDef } from './macros';
|
||||
|
||||
export { RibbitEditor as Editor } from './ribbit-editor';
|
||||
export { Ribbit as Viewer };
|
||||
export { HopDown };
|
||||
export { inlineTag };
|
||||
export { defaultTags, defaultBlockTags, defaultInlineTags };
|
||||
export { defaultTheme };
|
||||
export { camelCase, decodeHtmlEntities, encodeHtmlEntities };
|
||||
export { ToolbarManager } from './toolbar';
|
||||
export type { MacroDef };
|
||||
+16
-14
@@ -23,7 +23,7 @@ import { type MacroDef } from './macros';
|
||||
* editor.view(); // switch to read-only view
|
||||
*/
|
||||
export class RibbitEditor extends Ribbit {
|
||||
private vim!: VimHandler;
|
||||
private vim?: VimHandler;
|
||||
|
||||
run(): void {
|
||||
this.states = {
|
||||
@@ -32,17 +32,19 @@ export class RibbitEditor extends Ribbit {
|
||||
WYSIWYG: 'wysiwyg'
|
||||
};
|
||||
|
||||
this.vim = new VimHandler((mode) => {
|
||||
if (mode === 'normal') {
|
||||
this.toolbar.disable();
|
||||
this.element.classList.add('vim-normal');
|
||||
this.element.classList.remove('vim-insert');
|
||||
} else {
|
||||
this.toolbar.enable();
|
||||
this.element.classList.add('vim-insert');
|
||||
this.element.classList.remove('vim-normal');
|
||||
}
|
||||
});
|
||||
if (this.theme.features?.vim) {
|
||||
this.vim = new VimHandler((mode) => {
|
||||
if (mode === 'normal') {
|
||||
this.toolbar.disable();
|
||||
this.element.classList.add('vim-normal');
|
||||
this.element.classList.remove('vim-insert');
|
||||
} else {
|
||||
this.toolbar.enable();
|
||||
this.element.classList.add('vim-insert');
|
||||
this.element.classList.remove('vim-normal');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.#bindEvents();
|
||||
this.element.classList.add('loaded');
|
||||
@@ -218,7 +220,7 @@ export class RibbitEditor extends Ribbit {
|
||||
|
||||
wysiwyg(): void {
|
||||
if (this.getState() === this.states.WYSIWYG) return;
|
||||
this.vim.detach();
|
||||
this.vim?.detach();
|
||||
this.element.contentEditable = 'true';
|
||||
this.element.innerHTML = this.getHTML();
|
||||
Array.from(this.element.querySelectorAll('.macro')).forEach(el => {
|
||||
@@ -238,7 +240,7 @@ export class RibbitEditor extends Ribbit {
|
||||
if (this.state === this.states.EDIT) return;
|
||||
this.element.contentEditable = 'true';
|
||||
this.element.innerHTML = encodeHtmlEntities(this.getMarkdown());
|
||||
this.vim.attach(this.element);
|
||||
this.vim?.attach(this.element);
|
||||
this.setState(this.states.EDIT);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ export interface InlineTagDef {
|
||||
|
||||
export interface RibbitThemeFeatures {
|
||||
sourceMode?: boolean;
|
||||
vim?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user