-
-
Notifications
You must be signed in to change notification settings - Fork 425
-
Hi there :) I already managed to get the "default" editor to work, and im now trying to add a custom block. So far so good, the custom block is loading and can be added via a button. My Problem is now, that it wont get rendered. Im always getting a "Cannot find view for my-block." error. The view/element works, if i try to use it it normal html. Thanks for your help =) |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Replies: 2 comments · 27 replies
-
Hi, thanks for your trying! We haven't exposed the custom block helper API (prototype recently implemented in #5518) in our docs yet, which should allow you to define |
Beta Was this translation helpful? Give feedback.
All reactions
-
Why not wrap them as a function and pass blocksuite/packages/blocks/src/_common/widgets/slash-menu/config.ts Lines 62 to 614 in dd29665
|
Beta Was this translation helpful? Give feedback.
All reactions
-
Didnt even think about that :0 Im still getting this two errors though, no idea why. Everything works as aspected: +page.svelte:21 Error: Invalid schema for affine:paragraph: Hub/Content must have parent.
at Schema.validate (schema.ts:81:13)
at Page.addBlock (page.ts:333:17)
at +page.svelte:34:18
at slot.ts:106:9
at Array.forEach (<anonymous>)
at _Slot.emit (slot.ts:104:21)
at Page._handleYBlockAdd (page.ts:737:29)
at page.ts:762:16
at Map.forEach (<anonymous>)
at Page._handleYEvent (page.ts:760:18)
+page.svelte:22 Error: Length exceeded!
at create3 (error.js:12:28)
at lengthExceeded (AbstractType.js:686:36)
at typeListInsertGenerics (AbstractType.js:699:11)
at YArray.js:145:9
at transact (Transaction.js:425:14)
at _YArray.insert (YArray.js:144:7)
at page.ts:362:19
at transact (Transaction.js:425:14)
at _Doc.transact (Doc.js:167:12)
at Page.transact (space.ts:115:21) "+page.svelte:21-22" would be: 20: const pageBlockId = page.addBlock('affine:page', {text: new Text("my page")});
21: noteId = page.addBlock('affine:note', {}, pageBlockId);
22: page.addBlock('affine:surface', {}, pageBlockId);
23: page.addBlock('affine:paragraph', {text: new Text("my Paragraph")}, noteId);
24: page.addBlock('my-block',{}, noteId) "+page.svelte:34" would be: 29: if(e.type == "add" && e.flavour !== "affine:paragraph"){
30: const addedBlock = page.getBlockById(e.id);
31: const parent = page.getParent(addedBlock);
32: const index = parent.children.indexOf(addedBlock);
33:
34: page.addBlock('affine:paragraph',{}, noteId, index + 1);
} according to the Documentation, this should be correct. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Theres also a Problem with "renderModelChildren", that is implemented in the BlockElement. Even though my BlockView extens Blockelement, i cant access this.renderModelChildren. Any idea, what im doing wrong? export class MyBlockView extends BlockElement<MyBlockModel> {
private _yen = '0¥';
private _onClick = () => {
this.page.updateBlock(this.model, {
count: this.model.count + 1
});
};
override connectedCallback() {
super.connectedCallback();
this.model.propsUpdated.on(() => {
this._yen = `${this.model.count * 100}¥`;
});
}
override render() {
return html`
<div class="">
<div>
<h3>My Block</h3>
<p>Price: ${this._yen}</p>
<button @click=${this._onClick}>Add</button>
</div>
<div>${this.renderModelChildren(this.model)}</div>
</div>
`;
}
} |
Beta Was this translation helpful? Give feedback.
All reactions
-
Manged to find the error: this.renderModelChildren seems to be the new way, and is not yet pushed to release? My NPM pacakge still uses ${this.content} |
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm also interested in getting this to work with svelte. Could you maybe give an outline of your setup, or is there now an official guide for this? |
Beta Was this translation helpful? Give feedback.
All reactions
-
Im planning on rewriting the view/Ui in svelte and using blocksuite headless, as soon as the documentation is a bit more streamlined. What I'm doing currently is using the slot/event system to communicate between my svelte setup and the "default" Lit interface. So for the entire Editor part, I'm using lit, and lit components (as laid out in the docs). Whenever something happens, that needs to work with my svelte app (like assigning a user, to a todo), I fire an event that then triggers a svelte function (ex. show user select popUp). |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thx for the info! Yeah slot/events/attr was also my idea for connecting with svelte. If you get to implementing a headless version with svelte, let me know if you're going to make it a package. :) On a somewhat related note, (as I'm also new to Yjs), do you know of good resources on how to handle auth in Yjs? |
Beta Was this translation helpful? Give feedback.
All reactions
-
We did not really encounter any Problem. We just want to switch to Svelte, so everything is unified, and we can use our component libraries for the Editor. At the same time, writing it from 0, gives us more control overall. Y.js authentication could be done via websocket. We personally dont handle it ourselfs and use liveblocks "https://liveblocks.io/" for the Collaboration. They have there own auth handlers, in which you can dock you custom authentication logic. If we write something on our own, i will send you a msg =) |
Beta Was this translation helpful? Give feedback.
All reactions
-
Sure, you can also write it here for others to get the info :) |
Beta Was this translation helpful? Give feedback.
Manged to find the error: this.renderModelChildren seems to be the new way, and is not yet pushed to release? My NPM pacakge still uses ${this.content}