Skip to content

Commit 39b8015

Browse files
authored
feat: implement automatic CSS injection for the editor and update configuration options (#7)
1 parent 0687e26 commit 39b8015

5 files changed

Lines changed: 305 additions & 1 deletion

File tree

examples/basic/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useOpenBlock, OpenBlockView, useEditorContent, SlashMenu, BubbleMenu, TableHandles } from '@labbs/openblock-react';
22
import { sampleDocument } from './data';
3-
import '@labbs/openblock-core/styles/editor.css';
3+
// CSS is now auto-injected by the editor - no need to import!
4+
// import '@labbs/openblock-core/styles/editor.css';
45
import './styles.css';
56

67
export default function App() {

packages/core/src/editor/Editor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { ProseMirrorAPI } from '../pm/ProseMirrorAPI';
3131
import { EditorConfig, defaultConfig, EditorEvents, EventHandler } from './EditorConfig';
3232
import { createSchema } from '../schema';
3333
import { createPlugins } from '../plugins';
34+
import { injectStyles } from '../styles/injectStyles';
3435
import {
3536
Block,
3637
PartialBlock,
@@ -76,6 +77,11 @@ export class OpenBlockEditor {
7677
this._config = { ...defaultConfig, ...config };
7778
this.pm = new ProseMirrorAPI(this);
7879

80+
// Auto-inject styles if enabled (default: true)
81+
if (this._config.injectStyles !== false) {
82+
injectStyles();
83+
}
84+
7985
this._schema = createSchema();
8086
this._createEditor();
8187

packages/core/src/editor/EditorConfig.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ export interface EditorConfig {
118118
nodeViews?: Record<string, NodeViewConstructor>;
119119
};
120120

121+
/**
122+
* Whether to automatically inject editor styles into the document.
123+
* Set to false if you want to provide your own CSS or import the stylesheet manually.
124+
* @default true
125+
*/
126+
injectStyles?: boolean;
127+
121128
/**
122129
* Event callbacks.
123130
*/
@@ -133,4 +140,5 @@ export interface EditorConfig {
133140
export const defaultConfig: Partial<EditorConfig> = {
134141
editable: true,
135142
autoFocus: false,
143+
injectStyles: true,
136144
};

packages/core/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,9 @@ export type {
210210
CommandFn,
211211
} from './types';
212212

213+
// ===========================================================================
214+
// STYLES
215+
// ===========================================================================
216+
217+
export { injectStyles, removeStyles, areStylesInjected } from './styles/injectStyles';
218+

0 commit comments

Comments
 (0)