@blocksuite/lit
Advanced tools
Comparing version 0.12.0-canary-202402261119-f8f6883 to 0.12.0-canary-202402270321-fb79e2f
@@ -6,3 +6,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
import type { BlockModel } from '@blocksuite/store'; | ||
import type { Page } from '@blocksuite/store'; | ||
import type { Doc } from '@blocksuite/store'; | ||
import { type PropertyValues, type TemplateResult } from 'lit'; | ||
@@ -18,3 +18,3 @@ import type { EditorHost } from './lit-host.js'; | ||
widgets: Record<WidgetName, TemplateResult>; | ||
page: Page; | ||
doc: Doc; | ||
dirty: boolean; | ||
@@ -27,3 +27,3 @@ selected: BaseSelection | null; | ||
get childBlockElements(): BlockElement<BlockModel<object>, BlockService<BlockModel<object>>, string>[]; | ||
get rootBlockElement(): BlockElement<BlockModel<object>, BlockService<BlockModel<object>>, string>; | ||
get rootElement(): BlockElement<BlockModel<object>, BlockService<BlockModel<object>>, string>; | ||
get topContenteditableElement(): BlockElement | null; | ||
@@ -30,0 +30,0 @@ get flavour(): string; |
@@ -56,5 +56,5 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
} | ||
get rootBlockElement() { | ||
get rootElement() { | ||
const rootElement = this.host.view.viewFromPath('block', [ | ||
this.page.root.id, | ||
this.doc.root.id, | ||
]); | ||
@@ -65,3 +65,3 @@ assertExists(rootElement); | ||
get topContenteditableElement() { | ||
return this.rootBlockElement; | ||
return this.rootElement; | ||
} | ||
@@ -86,3 +86,3 @@ get flavour() { | ||
get isVersionMismatch() { | ||
const schema = this.page.schema.flavourSchemaMap.get(this.model.flavour); | ||
const schema = this.doc.schema.flavourSchemaMap.get(this.model.flavour); | ||
assertExists(schema, `Cannot find schema for flavour ${this.model.flavour}`); | ||
@@ -195,3 +195,3 @@ const expectedVersion = schema.version; | ||
return when(this.isVersionMismatch, () => { | ||
const schema = this.page.schema.flavourSchemaMap.get(this.model.flavour); | ||
const schema = this.doc.schema.flavourSchemaMap.get(this.model.flavour); | ||
assertExists(schema, `Cannot find schema for flavour ${this.model.flavour}`); | ||
@@ -230,3 +230,3 @@ const expectedVersion = schema.version; | ||
property({ attribute: false }) | ||
], BlockElement.prototype, "page", void 0); | ||
], BlockElement.prototype, "doc", void 0); | ||
__decorate([ | ||
@@ -233,0 +233,0 @@ property({ attribute: false }) |
import type { BlockSpec, CommandManager, SelectionManager, SpecStore, UIEventDispatcher, ViewStore } from '@blocksuite/block-std'; | ||
import type { BlockModel, Page } from '@blocksuite/store'; | ||
import type { BlockModel, Doc } from '@blocksuite/store'; | ||
import { nothing, type PropertyValues, type TemplateResult } from 'lit'; | ||
@@ -12,3 +12,3 @@ import type { StaticValue } from 'lit/static-html.js'; | ||
specs: BlockSpec[]; | ||
page: Page; | ||
doc: Doc; | ||
blockIdAttr: string; | ||
@@ -29,3 +29,3 @@ widgetIdAttr: string; | ||
renderModel: (model: BlockModel) => TemplateResult; | ||
renderSpecPortal: (page: Page, specs: BlockSpec[]) => TemplateResult; | ||
renderSpecPortal: (doc: Doc, specs: BlockSpec[]) => TemplateResult; | ||
renderModelChildren: (model: BlockModel) => TemplateResult; | ||
@@ -32,0 +32,0 @@ private _registerView; |
@@ -25,3 +25,3 @@ /* eslint-disable lit/binding-positions, lit/no-invalid-html */ | ||
const { flavour } = model; | ||
const schema = this.page.schema.flavourSchemaMap.get(flavour); | ||
const schema = this.doc.schema.flavourSchemaMap.get(flavour); | ||
if (!schema) { | ||
@@ -39,3 +39,3 @@ console.warn(`Cannot find schema for ${flavour}.`); | ||
? Object.entries(view.widgets).reduce((mapping, [key, tag]) => { | ||
const template = html `<${tag} ${unsafeStatic(this.widgetIdAttr)}=${key} .host=${this} .page=${this.page}></${tag}>`; | ||
const template = html `<${tag} ${unsafeStatic(this.widgetIdAttr)}=${key} .host=${this} .doc=${this.doc}></${tag}>`; | ||
return { | ||
@@ -50,3 +50,3 @@ ...mapping, | ||
.host=${this} | ||
.page=${this.page} | ||
.doc=${this.doc} | ||
.model=${model} | ||
@@ -56,6 +56,6 @@ .widgets=${widgets} | ||
}; | ||
this.renderSpecPortal = (page, specs) => { | ||
this.renderSpecPortal = (doc, specs) => { | ||
return html ` | ||
<editor-host | ||
.page=${page} | ||
.doc=${doc} | ||
.specs=${specs} | ||
@@ -109,5 +109,5 @@ contenteditable="false" | ||
const result = await super.getUpdateComplete(); | ||
const root = this.page.root; | ||
assertExists(root); | ||
const view = this.std.spec.getView(root.flavour); | ||
const rootModel = this.doc.root; | ||
assertExists(rootModel); | ||
const view = this.std.spec.getView(rootModel.flavour); | ||
assertExists(view); | ||
@@ -127,9 +127,9 @@ const widgetTags = Object.values(view.widgets ?? {}); | ||
super.connectedCallback(); | ||
if (!this.page.root) { | ||
throw new Error('This page is missing root block. Please initialize the default block structure before connecting the editor to DOM.'); | ||
if (!this.doc.root) { | ||
throw new Error('This doc is missing root block. Please initialize the default block structure before connecting the editor to DOM.'); | ||
} | ||
this.std = new BlockStdScope({ | ||
host: this, | ||
workspace: this.page.workspace, | ||
page: this.page, | ||
workspace: this.doc.workspace, | ||
doc: this.doc, | ||
}); | ||
@@ -147,3 +147,3 @@ this._registerView(); | ||
render() { | ||
const { root } = this.page; | ||
const { root } = this.doc; | ||
if (!root) | ||
@@ -159,3 +159,3 @@ return nothing; | ||
property({ attribute: false }) | ||
], EditorHost.prototype, "page", void 0); | ||
], EditorHost.prototype, "doc", void 0); | ||
__decorate([ | ||
@@ -162,0 +162,0 @@ property({ attribute: false }) |
/// <reference types="node" resolution-mode="require"/> | ||
import type { BlockService } from '@blocksuite/block-std'; | ||
import { type EventName, type UIEventHandler } from '@blocksuite/block-std'; | ||
import type { Page } from '@blocksuite/store'; | ||
import type { Doc } from '@blocksuite/store'; | ||
import { LitElement } from 'lit'; | ||
@@ -11,3 +11,3 @@ import type { BlockElement } from './block-element.js'; | ||
host: EditorHost; | ||
page: Page; | ||
doc: Doc; | ||
path: string[]; | ||
@@ -14,0 +14,0 @@ service: BlockService; |
@@ -69,3 +69,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
property({ attribute: false }) | ||
], WidgetElement.prototype, "page", void 0); | ||
], WidgetElement.prototype, "doc", void 0); | ||
//# sourceMappingURL=widget-element.js.map |
@@ -5,5 +5,5 @@ import { PathFinder } from '@blocksuite/block-std'; | ||
export const getInlineRangeProvider = element => { | ||
const root = element.host; | ||
const selectionManager = root.selection; | ||
const rangeManager = root.rangeManager; | ||
const editorHost = element.host; | ||
const selectionManager = editorHost.selection; | ||
const rangeManager = editorHost.rangeManager; | ||
const inlineRangeUpdatedSlot = new Slot(); | ||
@@ -22,3 +22,3 @@ assertExists(selectionManager); | ||
return false; | ||
const blockElement = startElement?.closest(`[${root.blockIdAttr}]`); | ||
const blockElement = startElement?.closest(`[${editorHost.blockIdAttr}]`); | ||
if (!blockElement || blockElement !== element) | ||
@@ -25,0 +25,0 @@ return false; |
@@ -104,3 +104,3 @@ import { PathFinder } from '@blocksuite/block-std'; | ||
event.preventDefault(); | ||
this.host.page.transact(() => { | ||
this.host.doc.transact(() => { | ||
startText.delete(from.index, from.length); | ||
@@ -115,5 +115,5 @@ startText.insert(event.data ?? '', from.index); | ||
.forEach(block => { | ||
const parent = this.host.page.getParent(block.model); | ||
const parent = this.host.doc.getParent(block.model); | ||
assertExists(parent); | ||
this.host.page.deleteBlock(block.model, { | ||
this.host.doc.deleteBlock(block.model, { | ||
bringChildrenTo: parent, | ||
@@ -173,3 +173,3 @@ }); | ||
} | ||
this.host.page.transact(() => { | ||
this.host.doc.transact(() => { | ||
endText.delete(0, to.length); | ||
@@ -182,5 +182,5 @@ startText.join(endText); | ||
.forEach(block => { | ||
const parent = this.host.page.getParent(block.model); | ||
const parent = this.host.doc.getParent(block.model); | ||
assertExists(parent); | ||
this.host.page.deleteBlock(block.model, { | ||
this.host.doc.deleteBlock(block.model, { | ||
bringChildrenTo: parent, | ||
@@ -187,0 +187,0 @@ }); |
{ | ||
"name": "@blocksuite/lit", | ||
"version": "0.12.0-canary-202402261119-f8f6883", | ||
"version": "0.12.0-canary-202402270321-fb79e2f", | ||
"description": "Lit renderer for blocksuite store", | ||
@@ -11,13 +11,13 @@ "type": "module", | ||
"peerDependencies": { | ||
"@blocksuite/block-std": "0.12.0-canary-202402261119-f8f6883", | ||
"@blocksuite/store": "0.12.0-canary-202402261119-f8f6883" | ||
"@blocksuite/block-std": "0.12.0-canary-202402270321-fb79e2f", | ||
"@blocksuite/store": "0.12.0-canary-202402270321-fb79e2f" | ||
}, | ||
"dependencies": { | ||
"lit": "^3.1.1", | ||
"@blocksuite/global": "0.12.0-canary-202402261119-f8f6883", | ||
"@blocksuite/inline": "0.12.0-canary-202402261119-f8f6883" | ||
"@blocksuite/global": "0.12.0-canary-202402270321-fb79e2f", | ||
"@blocksuite/inline": "0.12.0-canary-202402270321-fb79e2f" | ||
}, | ||
"devDependencies": { | ||
"@blocksuite/store": "0.12.0-canary-202402261119-f8f6883", | ||
"@blocksuite/block-std": "0.12.0-canary-202402261119-f8f6883" | ||
"@blocksuite/block-std": "0.12.0-canary-202402270321-fb79e2f", | ||
"@blocksuite/store": "0.12.0-canary-202402270321-fb79e2f" | ||
}, | ||
@@ -24,0 +24,0 @@ "exports": { |
@@ -7,3 +7,3 @@ import type { BlockService } from '@blocksuite/block-std'; | ||
import type { BlockModel } from '@blocksuite/store'; | ||
import type { Page } from '@blocksuite/store'; | ||
import type { Doc } from '@blocksuite/store'; | ||
import { nothing, type PropertyValues, render, type TemplateResult } from 'lit'; | ||
@@ -49,3 +49,3 @@ import { property, state } from 'lit/decorators.js'; | ||
@property({ attribute: false }) | ||
page!: Page; | ||
doc!: Doc; | ||
@@ -88,5 +88,5 @@ @property({ attribute: false }) | ||
get rootBlockElement() { | ||
get rootElement() { | ||
const rootElement = this.host.view.viewFromPath('block', [ | ||
this.page.root!.id, | ||
this.doc.root!.id, | ||
]); | ||
@@ -98,3 +98,3 @@ assertExists(rootElement); | ||
get topContenteditableElement(): BlockElement | null { | ||
return this.rootBlockElement; | ||
return this.rootElement; | ||
} | ||
@@ -124,3 +124,3 @@ | ||
get isVersionMismatch() { | ||
const schema = this.page.schema.flavourSchemaMap.get(this.model.flavour); | ||
const schema = this.doc.schema.flavourSchemaMap.get(this.model.flavour); | ||
assertExists( | ||
@@ -293,5 +293,3 @@ schema, | ||
() => { | ||
const schema = this.page.schema.flavourSchemaMap.get( | ||
this.model.flavour | ||
); | ||
const schema = this.doc.schema.flavourSchemaMap.get(this.model.flavour); | ||
assertExists( | ||
@@ -298,0 +296,0 @@ schema, |
@@ -13,3 +13,3 @@ /* eslint-disable lit/binding-positions, lit/no-invalid-html */ | ||
import { assertExists } from '@blocksuite/global/utils'; | ||
import type { BlockModel, Page } from '@blocksuite/store'; | ||
import type { BlockModel, Doc } from '@blocksuite/store'; | ||
import { | ||
@@ -38,3 +38,3 @@ LitElement, | ||
@property({ attribute: false }) | ||
page!: Page; | ||
doc!: Doc; | ||
@@ -80,5 +80,5 @@ @property({ attribute: false }) | ||
const result = await super.getUpdateComplete(); | ||
const root = this.page.root; | ||
assertExists(root); | ||
const view = this.std.spec.getView(root.flavour); | ||
const rootModel = this.doc.root; | ||
assertExists(rootModel); | ||
const view = this.std.spec.getView(rootModel.flavour); | ||
assertExists(view); | ||
@@ -102,5 +102,5 @@ const widgetTags = Object.values(view.widgets ?? {}); | ||
if (!this.page.root) { | ||
if (!this.doc.root) { | ||
throw new Error( | ||
'This page is missing root block. Please initialize the default block structure before connecting the editor to DOM.' | ||
'This doc is missing root block. Please initialize the default block structure before connecting the editor to DOM.' | ||
); | ||
@@ -111,4 +111,4 @@ } | ||
host: this, | ||
workspace: this.page.workspace, | ||
page: this.page, | ||
workspace: this.doc.workspace, | ||
doc: this.doc, | ||
}); | ||
@@ -129,3 +129,3 @@ this._registerView(); | ||
override render() { | ||
const { root } = this.page; | ||
const { root } = this.doc; | ||
if (!root) return nothing; | ||
@@ -138,3 +138,3 @@ | ||
const { flavour } = model; | ||
const schema = this.page.schema.flavourSchemaMap.get(flavour); | ||
const schema = this.doc.schema.flavourSchemaMap.get(flavour); | ||
if (!schema) { | ||
@@ -156,3 +156,3 @@ console.warn(`Cannot find schema for ${flavour}.`); | ||
this.widgetIdAttr | ||
)}=${key} .host=${this} .page=${this.page}></${tag}>`; | ||
)}=${key} .host=${this} .doc=${this.doc}></${tag}>`; | ||
@@ -169,3 +169,3 @@ return { | ||
.host=${this} | ||
.page=${this.page} | ||
.doc=${this.doc} | ||
.model=${model} | ||
@@ -176,6 +176,6 @@ .widgets=${widgets} | ||
renderSpecPortal = (page: Page, specs: BlockSpec[]) => { | ||
renderSpecPortal = (doc: Doc, specs: BlockSpec[]) => { | ||
return html` | ||
<editor-host | ||
.page=${page} | ||
.doc=${doc} | ||
.specs=${specs} | ||
@@ -182,0 +182,0 @@ contenteditable="false" |
import type { BlockService } from '@blocksuite/block-std'; | ||
import { type EventName, type UIEventHandler } from '@blocksuite/block-std'; | ||
import { assertExists } from '@blocksuite/global/utils'; | ||
import type { Page } from '@blocksuite/store'; | ||
import type { Doc } from '@blocksuite/store'; | ||
import { LitElement } from 'lit'; | ||
@@ -19,3 +19,3 @@ import { property } from 'lit/decorators.js'; | ||
@property({ attribute: false }) | ||
page!: Page; | ||
doc!: Doc; | ||
@@ -22,0 +22,0 @@ path!: string[]; |
@@ -15,5 +15,5 @@ import { PathFinder, type TextSelection } from '@blocksuite/block-std'; | ||
) => InlineRangeProvider = element => { | ||
const root = element.host; | ||
const selectionManager = root.selection; | ||
const rangeManager = root.rangeManager; | ||
const editorHost = element.host; | ||
const selectionManager = editorHost.selection; | ||
const rangeManager = editorHost.rangeManager; | ||
const inlineRangeUpdatedSlot = new Slot<InlineRangeUpdatedProp>(); | ||
@@ -35,3 +35,3 @@ | ||
const blockElement = startElement?.closest(`[${root.blockIdAttr}]`); | ||
const blockElement = startElement?.closest(`[${editorHost.blockIdAttr}]`); | ||
if (!blockElement || blockElement !== element) return false; | ||
@@ -38,0 +38,0 @@ } else { |
@@ -157,3 +157,3 @@ import type { BaseSelection, TextSelection } from '@blocksuite/block-std'; | ||
this.host.page.transact(() => { | ||
this.host.doc.transact(() => { | ||
startText.delete(from.index, from.length); | ||
@@ -169,5 +169,5 @@ startText.insert(event.data ?? '', from.index); | ||
.forEach(block => { | ||
const parent = this.host.page.getParent(block.model); | ||
const parent = this.host.doc.getParent(block.model); | ||
assertExists(parent); | ||
this.host.page.deleteBlock(block.model, { | ||
this.host.doc.deleteBlock(block.model, { | ||
bringChildrenTo: parent, | ||
@@ -239,3 +239,3 @@ }); | ||
this.host.page.transact(() => { | ||
this.host.doc.transact(() => { | ||
endText.delete(0, to.length); | ||
@@ -249,5 +249,5 @@ startText.join(endText); | ||
.forEach(block => { | ||
const parent = this.host.page.getParent(block.model); | ||
const parent = this.host.doc.getParent(block.model); | ||
assertExists(parent); | ||
this.host.page.deleteBlock(block.model, { | ||
this.host.doc.deleteBlock(block.model, { | ||
bringChildrenTo: parent, | ||
@@ -254,0 +254,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
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
153845
2584
+ Added@blocksuite/block-std@0.12.0-canary-202402270321-fb79e2f(transitive)
+ Added@blocksuite/global@0.12.0-canary-202402270321-fb79e2f(transitive)
+ Added@blocksuite/inline@0.12.0-canary-202402270321-fb79e2f(transitive)
+ Added@blocksuite/store@0.12.0-canary-202402270321-fb79e2f(transitive)
+ Added@blocksuite/sync@0.12.0-canary-202402270321-fb79e2f(transitive)
- Removed@blocksuite/block-std@0.12.0-canary-202402261119-f8f6883(transitive)
- Removed@blocksuite/global@0.12.0-canary-202402261119-f8f6883(transitive)
- Removed@blocksuite/inline@0.12.0-canary-202402261119-f8f6883(transitive)
- Removed@blocksuite/store@0.12.0-canary-202402261119-f8f6883(transitive)
- Removed@blocksuite/sync@0.12.0-canary-202402261119-f8f6883(transitive)
Updated@blocksuite/global@0.12.0-canary-202402270321-fb79e2f
Updated@blocksuite/inline@0.12.0-canary-202402270321-fb79e2f