Skip to content

Commit

Permalink
feat: limit entry to synced doc block using awareness store flag (toe…
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushAgrawal-A2 authored Feb 20, 2024
1 parent f4e551a commit 134cc0b
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ export class EmbedCardToolbar extends WithDisposable(LitElement) {
}

private get _canConvertToEmbedView() {
// synced doc entry controlled by awareness flag
if (isEmbedLinkedDocBlock(this._model)) {
const isSyncedDocEnabled = this._model.page.awarenessStore.getFlag(
'enable_synced_doc_block'
);
if (!isSyncedDocEnabled) {
return false;
}
}

return (
'convertToEmbed' in this.block || this._embedOptions?.viewType === 'embed'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { InlineRange } from '@blocksuite/inline';
import type { BlockElement } from '@blocksuite/lit';
import { WithDisposable } from '@blocksuite/lit';
import { computePosition, flip, inline, offset, shift } from '@floating-ui/dom';
import { html, LitElement } from 'lit';
import { html, LitElement, nothing } from 'lit';
import { customElement, property, query } from 'lit/decorators.js';

import type { PageBlockComponent } from '../../../../../page-block/types.js';
Expand Down Expand Up @@ -108,6 +108,12 @@ export class ReferencePopup extends WithDisposable(LitElement) {
return std;
}

get page() {
const page = this.blockElement.page;
assertExists(page);
return page;
}

private _openPage() {
const refPageId = this.referencePageId;
const blockElement = this.blockElement;
Expand Down Expand Up @@ -189,6 +195,11 @@ export class ReferencePopup extends WithDisposable(LitElement) {
}

override render() {
// synced doc entry controlled by awareness flag
const isSyncedDocEnabled = this.page.awarenessStore.getFlag(
'enable_synced_doc_block'
);

return html`
<div class="overlay-root blocksuite-overlay">
<div class="affine-reference-popover-container">
Expand Down Expand Up @@ -222,15 +233,21 @@ export class ReferencePopup extends WithDisposable(LitElement) {
<affine-tooltip .offset=${12}>${'Card view'}</affine-tooltip>
</icon-button>
<icon-button
size="24px"
class="affine-reference-popover-view-selector-button embed"
hover="false"
@click=${() => this._convertToEmbedView()}
>
${EmbedWebIcon}
<affine-tooltip .offset=${12}>${'Embed view'}</affine-tooltip>
</icon-button>
${isSyncedDocEnabled
? html`
<icon-button
size="24px"
class="affine-reference-popover-view-selector-button embed"
hover="false"
@click=${() => this._convertToEmbedView()}
>
${EmbedWebIcon}
<affine-tooltip .offset=${12}
>${'Embed view'}</affine-tooltip
>
</icon-button>
`
: nothing}
</div>
<span class="affine-reference-popover-dividing-line"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockElement<
convertToEmbed = () => {
const { page, pageId, caption, xywh } = this.model;

// synced doc entry controlled by awareness flag
const isSyncedDocEnabled = page.awarenessStore.getFlag(
'enable_synced_doc_block'
);
if (!isSyncedDocEnabled) {
return;
}

if (this.isInSurface) {
const style = 'syncedDoc';
const bound = Bound.deserialize(xywh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) {

private get _canConvertToEmbedView() {
const block = this._blockElement;

// synced doc entry controlled by awareness flag
if (!!block && isEmbedLinkedDocBlock(block.model)) {
const isSyncedDocEnabled = block.page.awarenessStore.getFlag(
'enable_synced_doc_block'
);
if (!isSyncedDocEnabled) {
return false;
}
}

return (
(block && 'convertToEmbed' in block) ||
this._embedOptions?.viewType === 'embed'
Expand Down
1 change: 1 addition & 0 deletions packages/framework/global/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare type BlockSuiteFlags = {
enable_synced_doc_block: boolean;
enable_legacy_validation: boolean;
enable_expand_database_block: boolean;
enable_bultin_ledits: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/framework/store/src/workspace/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface StoreOptions<
}

const FLAGS_PRESET = {
enable_synced_doc_block: false,
enable_legacy_validation: true,
enable_expand_database_block: false,
enable_bultin_ledits: false,
Expand Down
1 change: 1 addition & 0 deletions packages/playground/apps/default/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export async function createDefaultPageWorkspace() {
docSources,
awarenessSources,
defaultFlags: {
enable_synced_doc_block: true,
enable_bultin_ledits: true,
},
};
Expand Down
156 changes: 79 additions & 77 deletions packages/playground/apps/starter/data/synced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,83 +71,85 @@ export const synced: InitFn = (workspace: Workspace, id: string) => {
page: pageMain,
noteId,
markdown: syncedPageMarkdown,
}).catch(console.error);

// Add synced block - self
pageMain.addBlock(
'affine:paragraph',
{
text: new Text('Cyclic / Matryoshka synced block 👇'),
type: 'h4',
},
noteId
);

// Add synced block - self
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: id,
},
noteId
);

// Add synced block - page view
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'synced-page',
},
noteId
);

// Add synced block - edgeless view
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'synced-edgeless',
},
noteId
);

// Add synced block - page view
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'synced-page',
xywh: '[-1000, 0, 752, 455]',
},
surfaceId
);

// Add synced block - edgeless view
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'synced-edgeless',
xywh: '[-1000, 500, 752, 455]',
},
surfaceId
);

// Add synced block - self
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: id,
xywh: '[-1000, 1000, 752, 455]',
},
surfaceId
);

// Add synced block - self
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'deleted-page',
},
noteId
);
})
.then(() => {
// Add synced block - self
pageMain.addBlock(
'affine:paragraph',
{
text: new Text('Cyclic / Matryoshka synced block 👇'),
type: 'h4',
},
noteId
);

// Add synced block - self
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: id,
},
noteId
);

// Add synced block - page view
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'synced-page',
},
noteId
);

// Add synced block - edgeless view
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'synced-edgeless',
},
noteId
);

// Add synced block - page view
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'synced-page',
xywh: '[-1000, 0, 752, 455]',
},
surfaceId
);

// Add synced block - edgeless view
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'synced-edgeless',
xywh: '[-1000, 500, 752, 455]',
},
surfaceId
);

// Add synced block - self
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: id,
xywh: '[-1000, 1000, 752, 455]',
},
surfaceId
);

// Add synced block - self
pageMain.addBlock(
'affine:embed-synced-doc',
{
pageId: 'deleted-page',
},
noteId
);
})
.catch(console.error);
});

pageSyncedEdgeless.resetHistory();
Expand Down
1 change: 1 addition & 0 deletions packages/playground/apps/starter/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function createStarterPageWorkspace() {
idGenerator,
blobStorages,
defaultFlags: {
enable_synced_doc_block: true,
enable_bultin_ledits: featureArgs.includes('ledits'),
},
awarenessSources: [new BroadcastChannelAwarenessSource()],
Expand Down
1 change: 1 addition & 0 deletions packages/presets/src/__tests__/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function createWorkspaceOptions() {
idGenerator,
blobStorages,
defaultFlags: {
enable_synced_doc_block: true,
enable_transformer_clipboard: true,
enable_bultin_ledits: true,
readonly: {
Expand Down

0 comments on commit 134cc0b

Please sign in to comment.