-
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(presets): chat with workspace (#5748)
- Loading branch information
Showing
10 changed files
with
567 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/playground/apps/starter/components/left-side-panel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ShadowlessElement } from '@blocksuite/lit'; | ||
import { css, html } from 'lit'; | ||
import { customElement } from 'lit/decorators.js'; | ||
|
||
@customElement('left-side-panel') | ||
export class LeftSidePanel extends ShadowlessElement { | ||
static override styles = css` | ||
left-side-panel { | ||
padding-top: 50px; | ||
width: 300px; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100%; | ||
display: none; | ||
} | ||
`; | ||
currentContent: HTMLElement | null = null; | ||
|
||
showContent(ele: HTMLElement) { | ||
if (this.currentContent) { | ||
this.currentContent.remove(); | ||
} | ||
this.style.display = 'block'; | ||
this.currentContent = ele; | ||
this.append(ele); | ||
} | ||
|
||
hideContent() { | ||
if (this.currentContent) { | ||
this.style.display = 'none'; | ||
this.currentContent.remove(); | ||
this.currentContent = null; | ||
} | ||
} | ||
|
||
toggle(ele: HTMLElement) { | ||
if (this.currentContent !== ele) { | ||
this.showContent(ele); | ||
} else { | ||
this.hideContent(); | ||
} | ||
} | ||
|
||
protected override render(): unknown { | ||
return html``; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'left-side-panel': LeftSidePanel; | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
packages/playground/apps/starter/components/pages-panel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { createDefaultPage } from '@blocksuite/blocks'; | ||
import { CloseIcon } from '@blocksuite/blocks/_common/icons'; | ||
import { ShadowlessElement, WithDisposable } from '@blocksuite/lit'; | ||
import type { AffineEditorContainer } from '@blocksuite/presets'; | ||
import type { Workspace } from '@blocksuite/store'; | ||
import { css, html } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
import { repeat } from 'lit/directives/repeat.js'; | ||
import { styleMap } from 'lit/directives/style-map.js'; | ||
|
||
@customElement('pages-panel') | ||
export class PagesPanel extends WithDisposable(ShadowlessElement) { | ||
static override styles = css` | ||
pages-panel { | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
background-color: var(--affine-background-secondary-color); | ||
font-family: var(--affine-font-family); | ||
height: 100%; | ||
padding: 12px; | ||
gap: 4px; | ||
} | ||
.page-item:hover .delete-page-icon { | ||
display: flex; | ||
} | ||
.delete-page-icon { | ||
display: none; | ||
padding: 2px; | ||
border-radius: 4px; | ||
} | ||
.delete-page-icon:hover { | ||
background-color: var(--affine-hover-color); | ||
} | ||
.delete-page-icon svg { | ||
width: 14px; | ||
height: 14px; | ||
color: var(--affine-secondary-color); | ||
fill: var(--affine-secondary-color); | ||
} | ||
.new-page-button { | ||
margin-bottom: 16px; | ||
border: 1px solid var(--affine-border-color); | ||
border-radius: 4px; | ||
height: 32px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
cursor: pointer; | ||
} | ||
.new-page-button:hover { | ||
background-color: var(--affine-hover-color); | ||
} | ||
`; | ||
@property({ attribute: false }) | ||
editor!: AffineEditorContainer; | ||
|
||
public override connectedCallback() { | ||
super.connectedCallback(); | ||
this.disposables.add( | ||
this.editor.page.workspace.slots.pagesUpdated.on(() => { | ||
this.requestUpdate(); | ||
}) | ||
); | ||
} | ||
|
||
createPage = () => { | ||
createPageBlock(this.editor.page.workspace); | ||
}; | ||
|
||
protected override render(): unknown { | ||
const workspace = this.editor.page.workspace; | ||
const pages = [...workspace.pages.values()]; | ||
return html` | ||
<div @click="${this.createPage}" class="new-page-button">New Page</div> | ||
${repeat( | ||
pages, | ||
v => v.id, | ||
page => { | ||
const style = styleMap({ | ||
backgroundColor: | ||
this.editor.page.id === page.id | ||
? 'var(--affine-hover-color)' | ||
: undefined, | ||
padding: '4px 4px 4px 8px', | ||
borderRadius: '4px', | ||
cursor: 'pointer', | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
}); | ||
const click = () => { | ||
this.editor.page = page; | ||
this.requestUpdate(); | ||
}; | ||
const deletePage = () => { | ||
workspace.removePage(page.id); | ||
// When delete a page, we need to set the editor page to the first remaining page | ||
const pages = Array.from(workspace.pages.values()); | ||
this.editor.page = pages[0]; | ||
this.requestUpdate(); | ||
}; | ||
return html`<div class="page-item" @click="${click}" style="${style}"> | ||
${page.meta.title || 'Untitled'} | ||
<div @click="${deletePage}" class="delete-page-icon"> | ||
${CloseIcon} | ||
</div> | ||
</div>`; | ||
} | ||
)} | ||
`; | ||
} | ||
} | ||
|
||
function createPageBlock(workspace: Workspace) { | ||
const id = workspace.idGenerator('page'); | ||
createDefaultPage(workspace, { id }).catch(console.error); | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'pages-panel': PagesPanel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5ea5de7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
blocksuite – ./packages/playground
blocksuite-toeverything.vercel.app
try-blocksuite.vercel.app
blocksuite-git-master-toeverything.vercel.app