New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@blocksuite/lit

Package Overview
Dependencies
Maintainers
2
Versions
470
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocksuite/lit - npm Package Compare versions

Comparing version 0.12.0 to 0.13.0-canary-202403050653-934469c

6

dist/element/block-element.d.ts

@@ -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;

@@ -9,2 +9,3 @@ /* eslint-disable lit/binding-positions, lit/no-invalid-html */

import { BlockStdScope } from '@blocksuite/block-std';
import { handleError } from '@blocksuite/global/exceptions';
import { assertExists } from '@blocksuite/global/utils';

@@ -26,3 +27,3 @@ import { LitElement, nothing, } from 'lit';

const { flavour } = model;
const schema = this.page.schema.flavourSchemaMap.get(flavour);
const schema = this.doc.schema.flavourSchemaMap.get(flavour);
if (!schema) {

@@ -40,3 +41,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 {

@@ -51,3 +52,3 @@ ...mapping,

.host=${this}
.page=${this.page}
.doc=${this.doc}
.model=${model}

@@ -57,6 +58,6 @@ .widgets=${widgets}

};
this.renderSpecPortal = (page, specs) => {
this.renderSpecPortal = (doc, specs) => {
return html `
<editor-host
.page=${page}
.doc=${doc}
.specs=${specs}

@@ -109,27 +110,38 @@ contenteditable="false"

async getUpdateComplete() {
const result = await super.getUpdateComplete();
const root = this.page.root;
assertExists(root);
const view = this.std.spec.getView(root.flavour);
assertExists(view);
const widgetTags = Object.values(view.widgets ?? {});
const elementsTags = [view.component, ...widgetTags];
await Promise.all(elementsTags.map(tag => {
const element = this.renderRoot.querySelector(tag._$litStatic$);
if (element instanceof LitElement) {
return element.updateComplete;
try {
const result = await super.getUpdateComplete();
const rootModel = this.doc.root;
assertExists(rootModel);
const view = this.std.spec.getView(rootModel.flavour);
assertExists(view);
const widgetTags = Object.values(view.widgets ?? {});
const elementsTags = [view.component, ...widgetTags];
await Promise.all(elementsTags.map(tag => {
const element = this.renderRoot.querySelector(tag._$litStatic$);
if (element instanceof LitElement) {
return element.updateComplete;
}
return;
}));
return result;
}
catch (e) {
if (e instanceof Error) {
handleError(e);
}
return;
}));
return result;
else {
console.error(e);
}
return true;
}
}
connectedCallback() {
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 +159,3 @@ this._registerView();

render() {
const { root } = this.page;
const { root } = this.doc;
if (!root)

@@ -159,3 +171,3 @@ return nothing;

property({ attribute: false })
], EditorHost.prototype, "page", void 0);
], EditorHost.prototype, "doc", void 0);
__decorate([

@@ -162,0 +174,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,

@@ -211,5 +211,5 @@ });

this.host.disposables.add(this.selectionManager.slots.changed.on(this._onStdSelectionChanged));
this.host.disposables.add(this.host.event.add('selectionChange', throttle(() => {
this.host.disposables.addFromEvent(document, 'selectionchange', throttle(() => {
this._onNativeSelectionChanged().catch(console.error);
}, 10)));
}, 10));
this.host.disposables.add(this.host.event.add('beforeInput', ctx => {

@@ -216,0 +216,0 @@ const event = ctx.get('defaultState').event;

{
"name": "@blocksuite/lit",
"version": "0.12.0",
"version": "0.13.0-canary-202403050653-934469c",
"description": "Lit renderer for blocksuite store",

@@ -11,13 +11,13 @@ "type": "module",

"peerDependencies": {
"@blocksuite/block-std": "0.12.0",
"@blocksuite/store": "0.12.0"
"@blocksuite/block-std": "0.13.0-canary-202403050653-934469c",
"@blocksuite/store": "0.13.0-canary-202403050653-934469c"
},
"dependencies": {
"lit": "^3.1.1",
"@blocksuite/global": "0.12.0",
"@blocksuite/inline": "0.12.0"
"@blocksuite/global": "0.13.0-canary-202403050653-934469c",
"@blocksuite/inline": "0.13.0-canary-202403050653-934469c"
},
"devDependencies": {
"@blocksuite/store": "0.12.0",
"@blocksuite/block-std": "0.12.0"
"@blocksuite/block-std": "0.13.0-canary-202403050653-934469c",
"@blocksuite/store": "0.13.0-canary-202403050653-934469c"
},

@@ -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(

@@ -220,3 +220,3 @@ schema,

this.service = this.host.std.spec.getService(this.model.flavour) as Service;
this.service = this.host.std.spec.getService(this.model.flavour);
this.path = this.host.view.calculatePath(this);

@@ -294,5 +294,3 @@

() => {
const schema = this.page.schema.flavourSchemaMap.get(
this.model.flavour
);
const schema = this.doc.schema.flavourSchemaMap.get(this.model.flavour);
assertExists(

@@ -299,0 +297,0 @@ schema,

@@ -12,4 +12,5 @@ /* eslint-disable lit/binding-positions, lit/no-invalid-html */

import { BlockStdScope } from '@blocksuite/block-std';
import { handleError } from '@blocksuite/global/exceptions';
import { assertExists } from '@blocksuite/global/utils';
import type { BlockModel, Page } from '@blocksuite/store';
import type { BlockModel, Doc } from '@blocksuite/store';
import {

@@ -38,3 +39,3 @@ LitElement,

@property({ attribute: false })
page!: Page;
doc!: Doc;

@@ -79,19 +80,28 @@ @property({ attribute: false })

override async getUpdateComplete(): Promise<boolean> {
const result = await super.getUpdateComplete();
const root = this.page.root;
assertExists(root);
const view = this.std.spec.getView(root.flavour);
assertExists(view);
const widgetTags = Object.values(view.widgets ?? {});
const elementsTags = [view.component, ...widgetTags];
await Promise.all(
elementsTags.map(tag => {
const element = this.renderRoot.querySelector(tag._$litStatic$);
if (element instanceof LitElement) {
return element.updateComplete;
}
return;
})
);
return result;
try {
const result = await super.getUpdateComplete();
const rootModel = this.doc.root;
assertExists(rootModel);
const view = this.std.spec.getView(rootModel.flavour);
assertExists(view);
const widgetTags = Object.values(view.widgets ?? {});
const elementsTags = [view.component, ...widgetTags];
await Promise.all(
elementsTags.map(tag => {
const element = this.renderRoot.querySelector(tag._$litStatic$);
if (element instanceof LitElement) {
return element.updateComplete;
}
return;
})
);
return result;
} catch (e) {
if (e instanceof Error) {
handleError(e);
} else {
console.error(e);
}
return true;
}
}

@@ -102,5 +112,5 @@

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 +121,4 @@ }

host: this,
workspace: this.page.workspace,
page: this.page,
workspace: this.doc.workspace,
doc: this.doc,
});

@@ -129,3 +139,3 @@ this._registerView();

override render() {
const { root } = this.page;
const { root } = this.doc;
if (!root) return nothing;

@@ -138,3 +148,3 @@

const { flavour } = model;
const schema = this.page.schema.flavourSchemaMap.get(flavour);
const schema = this.doc.schema.flavourSchemaMap.get(flavour);
if (!schema) {

@@ -156,3 +166,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 +179,3 @@ return {

.host=${this}
.page=${this.page}
.doc=${this.doc}
.model=${model}

@@ -176,6 +186,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 +192,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 {

@@ -30,9 +30,8 @@ import type { BaseSelection, TextSelection } from '@blocksuite/block-std';

this.host.disposables.add(
this.host.event.add(
'selectionChange',
throttle(() => {
this._onNativeSelectionChanged().catch(console.error);
}, 10)
)
this.host.disposables.addFromEvent(
document,
'selectionchange',
throttle(() => {
this._onNativeSelectionChanged().catch(console.error);
}, 10)
);

@@ -158,3 +157,3 @@

this.host.page.transact(() => {
this.host.doc.transact(() => {
startText.delete(from.index, from.length);

@@ -170,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,

@@ -240,3 +239,3 @@ });

this.host.page.transact(() => {
this.host.doc.transact(() => {
endText.delete(0, to.length);

@@ -250,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,

@@ -255,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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc