@blocksuite/virgo
Advanced tools
Comparing version 0.4.0-20230201063624-4e0463b to 0.4.0-20230201220903-262005c
@@ -88,2 +88,26 @@ import { expect, test } from '@playwright/test'; | ||
}); | ||
test('readonly mode', async ({ page }) => { | ||
await enterPlayground(page); | ||
await focusRichText(page); | ||
const editorA = page.locator('[data-virgo-root="true"]').nth(0); | ||
const editorB = page.locator('[data-virgo-root="true"]').nth(1); | ||
expect(await editorA.innerText()).toBe(ZERO_WIDTH_SPACE); | ||
expect(await editorB.innerText()).toBe(ZERO_WIDTH_SPACE); | ||
await pageType(page, 'abcdefg'); | ||
expect(await editorA.innerText()).toBe('abcdefg'); | ||
expect(await editorB.innerText()).toBe('abcdefg'); | ||
await page.evaluate(() => { | ||
const richTextA = document | ||
.querySelector('test-page') | ||
?.shadowRoot?.querySelector('rich-text'); | ||
if (!richTextA) { | ||
throw new Error('Cannot find editor'); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
richTextA.vEditor.setReadOnly(true); | ||
}); | ||
await pageType(page, 'aaaa'); | ||
expect(await editorA.innerText()).toBe('abcdefg'); | ||
expect(await editorB.innerText()).toBe('abcdefg'); | ||
}); | ||
//# sourceMappingURL=input.spec.js.map |
@@ -14,2 +14,3 @@ import type * as Y from 'yjs'; | ||
private _isComposing; | ||
private _isReadOnly; | ||
private _renderElement; | ||
@@ -28,2 +29,4 @@ signals: { | ||
getVRange(): VRange | null; | ||
getReadOnly(): boolean; | ||
setReadOnly(isReadOnly: boolean): void; | ||
setVRange(vRange: VRange): void; | ||
@@ -30,0 +33,0 @@ deleteText(vRange: VRange): void; |
@@ -12,2 +12,3 @@ import { ZERO_WIDTH_SPACE } from './constant.js'; | ||
this._isComposing = false; | ||
this._isReadOnly = false; | ||
this._renderElement = baseRenderElement; | ||
@@ -146,2 +147,8 @@ this._onYTextChange = () => { | ||
} | ||
getReadOnly() { | ||
return this._isReadOnly; | ||
} | ||
setReadOnly(isReadOnly) { | ||
this._isReadOnly = isReadOnly; | ||
} | ||
setVRange(vRange) { | ||
@@ -380,2 +387,5 @@ this.signals.updateVRange.emit([vRange, 'other']); | ||
event.preventDefault(); | ||
if (this._isReadOnly) { | ||
return; | ||
} | ||
if (!this._vRange) { | ||
@@ -382,0 +392,0 @@ return; |
{ | ||
"name": "@blocksuite/virgo", | ||
"version": "0.4.0-20230201063624-4e0463b", | ||
"version": "0.4.0-20230201220903-262005c", | ||
"description": "A micro editor.", | ||
@@ -26,3 +26,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@blocksuite/global": "0.4.0-20230201063624-4e0463b" | ||
"@blocksuite/global": "0.4.0-20230201220903-262005c" | ||
}, | ||
@@ -29,0 +29,0 @@ "scripts": { |
@@ -133,1 +133,35 @@ import { expect, test } from '@playwright/test'; | ||
}); | ||
test('readonly mode', async ({ page }) => { | ||
await enterPlayground(page); | ||
await focusRichText(page); | ||
const editorA = page.locator('[data-virgo-root="true"]').nth(0); | ||
const editorB = page.locator('[data-virgo-root="true"]').nth(1); | ||
expect(await editorA.innerText()).toBe(ZERO_WIDTH_SPACE); | ||
expect(await editorB.innerText()).toBe(ZERO_WIDTH_SPACE); | ||
await pageType(page, 'abcdefg'); | ||
expect(await editorA.innerText()).toBe('abcdefg'); | ||
expect(await editorB.innerText()).toBe('abcdefg'); | ||
await page.evaluate(() => { | ||
const richTextA = document | ||
.querySelector('test-page') | ||
?.shadowRoot?.querySelector('rich-text'); | ||
if (!richTextA) { | ||
throw new Error('Cannot find editor'); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(richTextA as any).vEditor.setReadOnly(true); | ||
}); | ||
await pageType(page, 'aaaa'); | ||
expect(await editorA.innerText()).toBe('abcdefg'); | ||
expect(await editorB.innerText()).toBe('abcdefg'); | ||
}); |
@@ -30,2 +30,3 @@ import type * as Y from 'yjs'; | ||
private _isComposing = false; | ||
private _isReadOnly = false; | ||
private _renderElement: (delta: DeltaInsert) => TextElement = | ||
@@ -157,2 +158,10 @@ baseRenderElement; | ||
getReadOnly(): boolean { | ||
return this._isReadOnly; | ||
} | ||
setReadOnly(isReadOnly: boolean): void { | ||
this._isReadOnly = isReadOnly; | ||
} | ||
setVRange(vRange: VRange): void { | ||
@@ -472,2 +481,6 @@ this.signals.updateVRange.emit([vRange, 'other']); | ||
if (this._isReadOnly) { | ||
return; | ||
} | ||
if (!this._vRange) { | ||
@@ -474,0 +487,0 @@ return; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172785
2046
+ Added@blocksuite/global@0.4.0-20230201220903-262005c(transitive)
- Removed@blocksuite/global@0.4.0-20230201063624-4e0463b(transitive)