Skip to content

feat: add experimental GridBlockTemplates extension#1152

Draft
makhnatkin wants to merge 8 commits into
feat/yfm-html-block-templates-and-previewfrom
feat/grid-block-templates-experiment
Draft

feat: add experimental GridBlockTemplates extension#1152
makhnatkin wants to merge 8 commits into
feat/yfm-html-block-templates-and-previewfrom
feat/grid-block-templates-experiment

Conversation

@makhnatkin

@makhnatkin makhnatkin commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds an experimental GridBlockTemplates additional extension for building reusable grid layouts from typed block and container templates.

This PR is stacked on top of feat/yfm-html-block-templates-and-preview, so the diff stays scoped to the new experiment.

What Changed

  • Adds a ProseMirror atom node and React NodeView for editing grid blocks, per-block HTML/CSS, container CSS, drag reordering, and serialization into YFM ::: html output.
  • Supports typed <template type="block|container"> parsing and localStorage-backed user templates with merge-by-id and clear support.
  • Adds default demo templates and a Storybook example for the experimental extension.
  • Covers template parsing, storage validation, and HTML serialization with focused unit tests.
  • Splits the NodeView implementation into block item, settings popup, drag, text-editing, and template helper modules.

Validation

  • pnpm --filter @gravity-ui/markdown-editor lint
  • pnpm --filter @gravity-ui/markdown-editor typecheck

Notes

Jest tests were not run locally after the refactor because AGENTS.md requires tests to run in Docker, and this repository only exposes a Docker wrapper for Playwright, not for the affected Jest slice.

@sourcery-ai

sourcery-ai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a new experimental GridBlockTemplates extension that defines a ProseMirror atom node, React-based NodeView UI, HTML serialization, and localStorage-backed template parsing/storage, plus Storybook demo and tests.

File-Level Changes

Change Details Files
Add React NodeView UI and UX for managing grid block templates inside the editor.
  • Implement GridBlockTemplatesView with toolbar to edit container CSS, pick/apply templates, and remove the grid node
  • Support inline CSS parsing and scoped styles for the grid container and items
  • Enable in-place text editing within blocks with contentEditable wrappers and custom selection/clipboard handling
  • Provide BlockSettingsPopup and CssPopup components for editing block HTML/CSS and container CSS
  • Wire NodeView to ProseMirror via WGridBlockTemplatesNodeView with React Portal rendering and attribute updates
packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesNodeView/GridBlockTemplatesView.tsx
packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesNodeView/NodeView.tsx
packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesNodeView/BlockInsertPopup.tsx
packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesNodeView/TemplatesPopup.tsx
packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesNodeView/const.ts
Define grid block templates node specs, actions, types and extension wiring, including YFM HTML serialization.
  • Introduce GridBlockTemplatesSpecs with atom node spec, attributes, DOM representation, and ::: html serialization via buildGridHtml
  • Add GridBlockTemplates action and extension entry that registers node spec, NodeView, and createGridBlockTemplates toolbar action
  • Define GridBlock, template types, and extension options in a shared types module
  • Expose constants and nodeType helpers for the new node
  • Add unit test verifying YFM HTML serialization output
packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesSpecs/index.ts
packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesSpecs/const.ts
packages/editor/src/extensions/additional/GridBlockTemplates/actions.ts
packages/editor/src/extensions/additional/GridBlockTemplates/types.ts
packages/editor/src/extensions/additional/GridBlockTemplates/index.ts
packages/editor/src/extensions/additional/GridBlockTemplates/const.ts
packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplates.test.ts
Implement HTML template parsing and localStorage-backed persistence for grid block templates.
  • Implement parseTemplateBlock and parseTemplates to extract container/block CSS and inner HTML from markup
  • Implement storage utilities to read, merge, save, and clear templates in localStorage with runtime validation
  • Expose template parsing and storage APIs via templates/index.ts
  • Add unit tests for template parsing and storage behavior, including validation and merge semantics
  • packages/editor/src/extensions/additional/GridBlockTemplates/templates/parse.ts
    packages/editor/src/extensions/additional/GridBlockTemplates/templates/storage.ts
    packages/editor/src/extensions/additional/GridBlockTemplates/templates/index.ts
    packages/editor/src/extensions/additional/GridBlockTemplates/templates/storage.test.ts
    packages/editor/src/extensions/additional/GridBlockTemplates/templates/parse.test.ts Add styling and i18n resources for the GridBlockTemplates UI.
    • Add SCSS for main grid block templates container, items, editable text, CSS editor, and block settings editor
    • Add SCSS for templates/block-insert popup layout and controls
    • Register new i18n keyset for grid-block-templates with English and Russian translations
    packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesNodeView/GridBlockTemplates.scss
    packages/editor/src/extensions/additional/GridBlockTemplates/GridBlockTemplatesNodeView/TemplatesPopup.scss
    packages/editor/src/i18n/grid-block-templates/index.ts
    packages/editor/src/i18n/grid-block-templates/en.json
    packages/editor/src/i18n/grid-block-templates/ru.json Add demo usage in the markdown-editor demo app with default templates and toolbar integration.
    • Define default container templates for the demo as GridBlockTemplate objects
    • Wire GridBlockTemplates extension into demo markdown editor with custom toolbar button and templates options
    • Add Storybook story showcasing the Grid block templates example
    demo/src/defaults/grid-block-templates.ts
    demo/src/stories/examples/grid-block-templates/GridBlockTemplates.tsx
    demo/src/stories/examples/grid-block-templates/GridBlockTemplates.stories.tsx
    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

@gravity-ui

gravity-ui Bot commented Jun 17, 2026

Copy link
Copy Markdown

Storybook Deployed

@gravity-ui

gravity-ui Bot commented Jun 17, 2026

Copy link
Copy Markdown

🎭 Playwright Report

makhnatkin and others added 6 commits June 17, 2026 13:22
…locks

Replace native HTML5 drag with a pointer-based drag handle so reordering
works reliably over preview HTML; make the handle visible above block
content (z-index, float background, touch-action: none).

Keep user-entered raw HTML verbatim inside the block instead of unwrapping
its root element, so a pasted <div>text</div> stays as
<div class="block-N"><div>text</div></div> on serialization.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a second textarea in the container gear popup for free-form CSS rules
with selectors (.grid {}, .block-1 {}). Rules are scoped to the grid
instance so they never leak to other grids, applied live in the preview
and serialized into a <style> tag inside the html block.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Wrap the menu in both the container-templates and block-insert popups in
a scrollable container (max-height) so a long list of templates no longer
overflows the viewport; the search field stays pinned above it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tyles

Replace inline CSS everywhere with a single selector-based model. The
container gear has one CSS field (.grid {}, .block-1 {}); the block gear
keeps HTML + a CSS field where & targets the block root and other
selectors are scoped under it. All rules are scoped to the instance and
emitted into a <style> tag instead of style="" attributes; templates
convert their inline style to rules on insert.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@makhnatkin makhnatkin changed the title feat: add grid block templates experiment feat: add experimental GridBlockTemplates extension Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant