Layouts for prose (headings+paragraphs+???)

オープン
#41 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript
領域
frontend, web-dev

調査の方向性

ファイルやテストは指定されていません。まず Svedit のノードカーソル、散文/テキストノード構造、コピーアンドペーストの動作を追跡し、最初に散文コンテナモデルとそのエッジケースについて合意してください。向き、挿入、削除、貼り付けられたノードについて、決定済みでテスト可能な設計ができれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Trying to work out the right approach for allowing different orientations/layouts for prose. E.g. for my website I might want a group of headings and paragraphs be left-aligned, centered, or right-oriented, to make things a bit more interesting visually.

My first attempt was to just encode all that layout information in a text node's layout property. E.g. I'd have 9 layouts for headings: left-aligned h1,h2,3 centered h1,h2,h3 and right-oriented h1,h2,h3.

While this works in principle, and keeps the content structure flat, it has downsides:

  • if i want to change the orientation of multiple text nodes i'd need to change them one by one, or have some badge command (but then it's hard and error-prone to match the right layouts together, e.g. paragraph I have layout: 1,2,3 (you can only choose the orientation) while for headings you haver 1,2,...9.
  • Also when splitting nodes or copy and paste you'd need to look for predecessors/successor text nodes and inspect them in order to determine which layout the pasted elements should get.

After some consideration I think a better approach is to group sections of prose together to single units, which then get a layout property (the orientation). For that I'd introduce a new node type prose at top level, that can take headings and paragraphs.

Pros:

  • I'd have a dedicated entity to set stuff for a body of text. e.g. orientation, but also background
  • You can optimize spacing because you know which body of text belongs together.
  • Copy and paste: Easy to move text nodes from one prose node to another, while it automatically inherits the right layout

Cons:

  • Copy and paste special cases: Say you select a bunch of paragraphs from a prose node, and then paste them at a top-level position. In this case Svedit would need to somehow determine the right parent component (in this case a prose node) so we have a valid structure again. Definitely possible, but needs significant changes to Svedit.
  • Say the node cursor is after a Hero element, and you press ENTER. Currently you would expect a new paragraph to be created and a blinking cursor. But now to be consistent with the rest of the system, it would create a prose element with a heading and two paragraphs. The good thing is that you then understand implicitly how prose nodes work, and how a finished prose section roughly looks like. However the bad side is that it may be surprising, because it doesn't behave like your traditional text editor.
  • Another edge case: What should happen when you want to delete the last text block inside a prose node. Should the prose node be removed alltogether, or should just EW just reject that (current behavior)
  • You might accidentally create new prose elements, instead of adding new text blocks to an existing one. This could be a source of confusion/complexity. You'd only want to create a new prose node, when you want to change the layout e.g. start with left aligned and then continue with centered text. However, typically you'd never have two prose nodes after another. Or would you? Needs testing I guess.
  • Added complexity to "just add a heading": A common use case might be that you just want to add a heading, e.g. before a gallery node. To do that you press ENTER at a node cursor position, then by default a prose with placeholders for one heading + 2 paragraphs is inserted. Now you need to delete the paragraph, and the heading (level 1) remains.

Generally I think adding a prose wrapper adds a lot of flexibility, and is definitely a pattern that can be utilized in custom nodes. On the downside it's definitely getting more complex, and breaks a bit with the expectations of a rich text-editor. Maybe that's not a bad thing, but it definitely hurts a bit simplicity, and might overwhelm some people that "just want to write a blog post".

Some ideas to mitigate the problems of the prose-container-approach:

  • Maybe separate nodes for Section Headlines (much spacing etc., separator lines) and Headings (inside a Prose element, that are part of a body of text).
主要言語
TypeScript
スター
1.8k
フォーク
148
平均マージ
2時間 47分
マージ済み PR(30日)
13

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

michael/editable のほかの issue

michael/editable の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。