Skip to content

Commit

Permalink
feat: linked doc supports aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Nov 27, 2024
1 parent ed802f3 commit 1b72e4b
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { InlineEditor, InlineRootElement } from '@blocksuite/inline';

import { ReferenceInfoSchema } from '@blocksuite/affine-model';
import { AliasInfoSchema, ReferenceInfoSchema } from '@blocksuite/affine-model';
import { StdIdentifier } from '@blocksuite/block-std';
import { html } from 'lit';
import { z } from 'zod';
Expand Down Expand Up @@ -149,6 +149,7 @@ export const ReferenceInlineSpecExtension = InlineSpecExtension(
]),
})
.merge(ReferenceInfoSchema)
.merge(AliasInfoSchema)
.optional()
.nullable()
.catch(undefined),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class LinkPopup extends WithDisposable(LitElement) {
<editor-icon-button
aria-label="Copy"
data-testid="copy-link"
.tooltip=${'Click to copy link'}
.tooltip=${'Copy link'}
@click=${this._copyUrl}
>
${CopyIcon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import type { AffineInlineEditor } from '../../affine-inline-specs.js';

import {
CenterPeekIcon,
CopyIcon,
DeleteIcon,
EditIcon,
ExpandFullSmallIcon,
MoreVerticalIcon,
OpenIcon,
Expand Down Expand Up @@ -311,6 +313,24 @@ export class ReferencePopup extends WithDisposable(LitElement) {
const buttons = [
this._openMenuButton(),

html`
<editor-icon-button
aria-label="Copy"
data-testid="copy-link"
.tooltip=${'Copy link'}
>
${CopyIcon}
</editor-icon-button>
<editor-icon-button
aria-label="Edit"
data-testid="edit"
.tooltip=${'Edit'}
>
${EditIcon}
</editor-icon-button>
`,

this._viewToggleMenu(),

html`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BlockModel } from '@blocksuite/store';

import type { ReferenceInfo } from '../../../consts/doc.js';
import type { AliasInfo, ReferenceInfo } from '../../../consts/doc.js';
import type { EmbedCardStyle } from '../../../utils/index.js';

import { defineEmbedModel } from '../../../utils/index.js';
Expand All @@ -16,7 +16,8 @@ export const EmbedLinkedDocStyles: EmbedCardStyle[] = [
export type EmbedLinkedDocBlockProps = {
style: EmbedCardStyle;
caption: string | null;
} & ReferenceInfo;
} & ReferenceInfo &
AliasInfo;

export class EmbedLinkedDocModel extends defineEmbedModel<EmbedLinkedDocBlockProps>(
BlockModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BlockModel } from '@blocksuite/store';

import type { ReferenceInfo } from '../../../consts/doc.js';
import type { AliasInfo, ReferenceInfo } from '../../../consts/doc.js';
import type { EmbedCardStyle } from '../../../utils/index.js';

import { defineEmbedModel } from '../../../utils/index.js';
Expand All @@ -11,7 +11,8 @@ export type EmbedSyncedDocBlockProps = {
style: EmbedCardStyle;
caption?: string | null;
scale?: number;
} & ReferenceInfo;
} & ReferenceInfo &
AliasInfo;

export class EmbedSyncedDocModel extends defineEmbedModel<EmbedSyncedDocBlockProps>(
BlockModel
Expand Down
22 changes: 20 additions & 2 deletions packages/affine/model/src/consts/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const ReferenceParamsSchema = z
mode: z.enum(DocModes),
blockIds: z.string().array(),
elementIds: z.string().array(),
databaseId: z.string().optional(),
databaseRowId: z.string().optional(),
databaseId: z.string(),
databaseRowId: z.string(),
})
.partial();

Expand All @@ -22,3 +22,21 @@ export const ReferenceInfoSchema = z.object({
});

export type ReferenceInfo = z.infer<typeof ReferenceInfoSchema>;

/**
* Custom title and description information.
*
* Supports the following blocks:
*
* 1. AffineReference: title
* 2. EmbedLinkedDocBlock: title & description
* 3. EmbedSyncedDocBlock: title
*/
export const AliasInfoSchema = z
.object({
aliasTitle: z.string(),
aliasDescription: z.string(),
})
.partial();

export type AliasInfo = z.infer<typeof AliasInfoSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ export class EmbedCardToolbar extends WidgetComponent<
: null;

const buttons = [
this._openMenuButton(),

this._canShowUrlOptions && model && 'url' in model
? html`
<a
Expand All @@ -622,30 +624,30 @@ export class EmbedCardToolbar extends WidgetComponent<
>
<span>${getHostName(model.url)}</span>
</a>
<editor-icon-button
aria-label="Copy"
data-testid="copy-link"
.tooltip=${'Click to copy link'}
?disabled=${model.doc.readonly}
@click=${() => this._copyUrl()}
>
${CopyIcon}
</editor-icon-button>
<editor-icon-button
aria-label="Edit"
data-testid="edit"
.tooltip=${'Edit'}
?disabled=${this.doc.readonly}
@click=${() => toggleEmbedCardEditModal(this.host, model)}
>
${EditIcon}
</editor-icon-button>
`
: nothing,

this._openMenuButton(),
html`
<editor-icon-button
aria-label="Copy"
data-testid="copy-link"
.tooltip=${'Copy link'}
?disabled=${model.doc.readonly}

Check failure on line 635 in packages/blocks/src/root-block/widgets/embed-card-toolbar/embed-card-toolbar.ts

View workflow job for this annotation

GitHub Actions / Build

'model' is possibly 'undefined'.
@click=${() => this._copyUrl()}
>
${CopyIcon}
</editor-icon-button>
<editor-icon-button
aria-label="Edit"
data-testid="edit"
.tooltip=${'Edit'}
?disabled=${this.doc.readonly}
@click=${() => toggleEmbedCardEditModal(this.host, model)}

Check failure on line 646 in packages/blocks/src/root-block/widgets/embed-card-toolbar/embed-card-toolbar.ts

View workflow job for this annotation

GitHub Actions / Build

Argument of type 'EmbedToolbarModel | undefined' is not assignable to parameter of type 'EmbedCardModel'.
>
${EditIcon}
</editor-icon-button>
`,

this._viewToggleMenu(),

Expand Down

0 comments on commit 1b72e4b

Please sign in to comment.