Skip to content

Commit 9eb9592

Browse files
moutonjeremyJeremy Mouton
andauthored
Implement automatic CSS style injection for OpenBlock editor (#8)
* refactor: remove direct CSS import in favor of auto-injection by OpenBlockEditor * feat: add style injection functions to index export * feat: add CSS style injection functionality for OpenBlock editor * feat: add injectStyles option for automatic CSS style injection * feat: auto-inject styles on editor initialization --------- Co-authored-by: Jeremy Mouton <jeremy.mouton@spendesk.com>
1 parent 39b8015 commit 9eb9592

5 files changed

Lines changed: 1469 additions & 214 deletions

File tree

examples/basic/src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useOpenBlock, OpenBlockView, useEditorContent, SlashMenu, BubbleMenu, TableHandles } from '@labbs/openblock-react';
22
import { sampleDocument } from './data';
3-
// CSS is now auto-injected by the editor - no need to import!
4-
// import '@labbs/openblock-core/styles/editor.css';
3+
// CSS is now auto-injected by OpenBlockEditor (injectStyles: true by default)
54
import './styles.css';
65

76
export default function App() {

packages/core/src/editor/Editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class OpenBlockEditor {
7777
this._config = { ...defaultConfig, ...config };
7878
this.pm = new ProseMirrorAPI(this);
7979

80-
// Auto-inject styles if enabled (default: true)
80+
// Auto-inject styles unless explicitly disabled
8181
if (this._config.injectStyles !== false) {
8282
injectStyles();
8383
}

packages/core/src/editor/EditorConfig.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ export interface EditorConfig {
106106
*/
107107
inputRules?: InputRulesConfig | false;
108108

109+
/**
110+
* Whether to auto-inject CSS styles into the document head.
111+
*
112+
* When true (default), OpenBlock will automatically inject all required
113+
* CSS styles, so you don't need to import any CSS files manually.
114+
*
115+
* Set to false if you want to provide your own styles or import the
116+
* CSS file manually.
117+
*
118+
* @default true
119+
*/
120+
injectStyles?: boolean;
121+
109122
/**
110123
* Direct ProseMirror configuration.
111124
* Use this for advanced customization.

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,3 @@ export type {
215215
// ===========================================================================
216216

217217
export { injectStyles, removeStyles, areStylesInjected } from './styles/injectStyles';
218-

0 commit comments

Comments
 (0)