Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refine image toolbar widget #7075

Merged
merged 1 commit into from
May 21, 2024
Merged

feat: refine image toolbar widget #7075

merged 1 commit into from
May 21, 2024

Conversation

donteatfriedrice
Copy link
Member

@donteatfriedrice donteatfriedrice commented May 16, 2024

  • Split ask-ai-button and action panel into independent components to support reuse
  • Transform the image toolbar to support adding custom buttons
  config: ImageConfigItem[] = [];

  moreMenuConfig: MoreMenuConfigItem[] = [];

  clearConfig = () => {
    this.config = [];
    this.moreMenuConfig = [];
    return this;
  };

  addConfigItems = (item: ImageConfigItem[], index?: number) => {
    if (index === undefined) {
      this.config.push(...item);
      return this;
    }

    this.config.splice(index, 0, ...item);
    return this;
  };

  addMoreMenuItems = (item: MoreMenuConfigItem[], index?: number) => {
    if (index === undefined) {
      this.moreMenuConfig.push(...item);
      return this;
    }

    this.moreMenuConfig.splice(index, 0, ...item);
    return this;
  };

  buildDefaultConfig = () => {
    this.clearConfig()
      .addConfigItems(commonConfig)
      .addMoreMenuItems(moreMenuConfig);
    return this;
  };
export function setupImageToolbarEntry(imageToolbar: AffineImageToolbarWidget) {
  imageToolbar.buildDefaultConfig();
  imageToolbar.addConfigItems(
    [
      {
        type: 'custom',
        render(imageBlock: ImageBlockComponent) {
          return html`<ask-ai-button
            class="image-toolbar-button ask-ai"
            .host=${imageBlock.host}
            .actionGroups=${AIImageItemGroups}
            .size=${'small'}
            .backgroundColor=${'var(--affine-white)'}
            .boxShadow=${'var(--affine-shadow-1)'}
          ></ask-ai-button>`;
        },
        showWhen: () => true,
      },
    ],
    0
  );
}

export const AIImageBlockSpec: BlockSpec = {
  ...ImageBlockSpec,
  setup(slots, disposableGroup) {
    ImageBlockSpec.setup?.(slots, disposableGroup);
    slots.widgetConnected.on(view => {
      if (view.component instanceof AffineImageToolbarWidget) {
        setupImageToolbarEntry(view.component);
      }
    });
  },
};

Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ❌ Failed (Inspect) May 21, 2024 10:38am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview May 21, 2024 10:38am

Copy link

graphite-app bot commented May 16, 2024

Your org has enabled the Graphite merge queue for merging into master

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@donteatfriedrice donteatfriedrice marked this pull request as draft May 16, 2024 17:00
@donteatfriedrice donteatfriedrice changed the title feat: image ai entry feat: refine image toolbar widget May 21, 2024
@donteatfriedrice donteatfriedrice marked this pull request as ready for review May 21, 2024 09:02
Copy link

graphite-app bot commented May 21, 2024

Merge activity

  • May 21, 5:06 AM EDT: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • May 21, 6:21 AM EDT: donteatfriedrice added this pull request to the Graphite merge queue.
  • May 21, 6:36 AM EDT: donteatfriedrice merged this pull request with the Graphite merge queue.

@graphite-app graphite-app bot merged commit 4a6c0b4 into master May 21, 2024
17 of 19 checks passed
@graphite-app graphite-app bot deleted the feat/image-ai-entry branch May 21, 2024 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants