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 28, 2024
1 parent 293269d commit 5479d1c
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 27 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,25 @@ 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'}
?disabled=${this.doc.readonly}
>
${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
18 changes: 18 additions & 0 deletions packages/affine/model/src/consts/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,29 @@ 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'}
@click=${() => this._copyUrl()}
>
${CopyIcon}
</editor-icon-button>
<editor-icon-button
aria-label="Edit"
data-testid="edit"
.tooltip=${'Edit'}
?disabled=${this.doc.readonly}
@click=${() => model && toggleEmbedCardEditModal(this.host, model)}

Check failure on line 645 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' is not assignable to parameter of type 'EmbedCardModel'.
>
${EditIcon}
</editor-icon-button>
`,

this._viewToggleMenu(),

Expand Down

0 comments on commit 5479d1c

Please sign in to comment.