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:
gsb
2026-04-29 07:57:40 +00:00
parent 3368e719fd
commit 2e28598243
5 changed files with 48 additions and 22 deletions
+21
View File
@@ -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
View File
@@ -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);
}
+1
View File
@@ -68,6 +68,7 @@ export interface InlineTagDef {
export interface RibbitThemeFeatures {
sourceMode?: boolean;
vim?: boolean;
}
/**