@blocksuite/virgo
Advanced tools
Comparing version 0.4.0-20230203030233-b22bea7 to 0.4.0-20230203145315-ce4acef
@@ -33,9 +33,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
unitText.delta = this.delta; | ||
return html ` | ||
<span | ||
data-virgo-element="true" | ||
style=${virgoTextStyles(this.delta.attributes)} | ||
>${unitText}</span | ||
> | ||
`; | ||
// we need to avoid \n appearing before and after the span element, which will | ||
// cause the unexpected space | ||
return html `<span | ||
data-virgo-element="true" | ||
style=${virgoTextStyles(this.delta.attributes)} | ||
>${unitText}</span | ||
>`; | ||
} | ||
@@ -42,0 +42,0 @@ createRenderRoot() { |
@@ -17,2 +17,3 @@ import type * as Y from 'yjs'; | ||
private _renderElement; | ||
private _onKeyDown; | ||
signals: { | ||
@@ -22,3 +23,6 @@ updateVRange: Signal<UpdateVRangeProp>; | ||
yText: Y.Text; | ||
constructor(yText: VEditor['yText'], renderElement?: (delta: DeltaInsert) => TextElement); | ||
constructor(yText: VEditor['yText'], opts?: { | ||
renderElement?: (delta: DeltaInsert) => TextElement; | ||
onKeyDown?: (event: KeyboardEvent) => void; | ||
}); | ||
mount(rootElement: HTMLElement): void; | ||
@@ -25,0 +29,0 @@ unmount(): void; |
@@ -8,3 +8,3 @@ import { ZERO_WIDTH_SPACE } from './constant.js'; | ||
export class VEditor { | ||
constructor(yText, renderElement) { | ||
constructor(yText, opts = {}) { | ||
this._rootElement = null; | ||
@@ -16,2 +16,5 @@ this._rootElementAbort = null; | ||
this._renderElement = baseRenderElement; | ||
this._onKeyDown = () => { | ||
return; | ||
}; | ||
this._onYTextChange = () => { | ||
@@ -70,5 +73,9 @@ assertExists(this._rootElement); | ||
this.yText = yText; | ||
const { renderElement, onKeyDown } = opts; | ||
if (renderElement) { | ||
this._renderElement = renderElement; | ||
} | ||
if (onKeyDown) { | ||
this._onKeyDown = onKeyDown; | ||
} | ||
this.signals = { | ||
@@ -105,2 +112,5 @@ updateVRange: new Signal(), | ||
}); | ||
this._rootElement.addEventListener('keydown', this._onKeyDown, { | ||
signal: this._rootElementAbort.signal, | ||
}); | ||
} | ||
@@ -107,0 +117,0 @@ unmount() { |
{ | ||
"name": "@blocksuite/virgo", | ||
"version": "0.4.0-20230203030233-b22bea7", | ||
"version": "0.4.0-20230203145315-ce4acef", | ||
"description": "A micro editor.", | ||
@@ -26,3 +26,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@blocksuite/global": "0.4.0-20230203030233-b22bea7" | ||
"@blocksuite/global": "0.4.0-20230203145315-ce4acef" | ||
}, | ||
@@ -29,0 +29,0 @@ "scripts": { |
@@ -31,9 +31,9 @@ import { LitElement, html } from 'lit'; | ||
return html` | ||
<span | ||
data-virgo-element="true" | ||
style=${virgoTextStyles(this.delta.attributes)} | ||
>${unitText}</span | ||
> | ||
`; | ||
// we need to avoid \n appearing before and after the span element, which will | ||
// cause the unexpected space | ||
return html`<span | ||
data-virgo-element="true" | ||
style=${virgoTextStyles(this.delta.attributes)} | ||
>${unitText}</span | ||
>`; | ||
} | ||
@@ -40,0 +40,0 @@ |
@@ -34,2 +34,5 @@ import type * as Y from 'yjs'; | ||
baseRenderElement; | ||
private _onKeyDown: (event: KeyboardEvent) => void = () => { | ||
return; | ||
}; | ||
@@ -43,5 +46,10 @@ signals: { | ||
yText: VEditor['yText'], | ||
renderElement?: (delta: DeltaInsert) => TextElement | ||
opts: { | ||
renderElement?: (delta: DeltaInsert) => TextElement; | ||
onKeyDown?: (event: KeyboardEvent) => void; | ||
} = {} | ||
) { | ||
this.yText = yText; | ||
const { renderElement, onKeyDown } = opts; | ||
if (renderElement) { | ||
@@ -51,2 +59,6 @@ this._renderElement = renderElement; | ||
if (onKeyDown) { | ||
this._onKeyDown = onKeyDown; | ||
} | ||
this.signals = { | ||
@@ -101,2 +113,6 @@ updateVRange: new Signal<UpdateVRangeProp>(), | ||
); | ||
this._rootElement.addEventListener('keydown', this._onKeyDown, { | ||
signal: this._rootElementAbort.signal, | ||
}); | ||
} | ||
@@ -103,0 +119,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
182392
2244
+ Added@blocksuite/global@0.4.0-20230203145315-ce4acef(transitive)
- Removed@blocksuite/global@0.4.0-20230203030233-b22bea7(transitive)