@zuilib/text-editor 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog — @zuilib/text-editor
2
2
 
3
+ ## 0.4.0
4
+
5
+ - **Table density**, Slab-style: the floating table toolbar (caret in a
6
+ table) gains *compact* / *comfortable* (default) / *spacious* row padding
7
+ and font size, next to the width toggle
8
+ - The settings comment above a GFM table now lists every non-default
9
+ setting, e.g. `<!-- width: content; density: compact -->`; the 0.3.1
10
+ `<!-- width: content -->` form is unchanged for width-only tables
11
+ - `useMarkdownEditor()` gains `tableDensity` / `setTableDensity`
12
+ - New exports: `TableDensity`, `TableSettings`, `DEFAULT_TABLE_SETTINGS`,
13
+ `$getTableSettings` / `$setTableSettings`, `$getTableDensity` /
14
+ `$setTableDensity`, `parseTableSettingsMarker` /
15
+ `formatTableSettingsMarker`. `TABLE_WIDTH_MARKER` is deprecated in favour
16
+ of `formatTableSettingsMarker`
17
+
18
+ ## 0.3.1
19
+
20
+ - **Block width** for tables and drawings: switch any table or drawing
21
+ between *full width* (spans the editor, the previous behaviour) and
22
+ *content width* (shrinks to fit its columns / shapes, left-aligned with
23
+ the text), Slab-style
24
+ - Tables: a floating toggle docks to the top-right of the table the caret
25
+ is in; content width sizes columns by their content. Persisted as a
26
+ `<!-- width: content -->` line directly above the GFM table (hidden by
27
+ other markdown renderers)
28
+ - Drawings: toggle at the right end of the canvas toolbar; content width
29
+ fits the rightmost shape and grows as shapes move. Persisted as a
30
+ top-level `"width":"content"` field in the ```drawing payload
31
+ (`DrawingData.width`, `DRAWING_DATA_JSON_SCHEMA` updated; omitted when
32
+ full, so existing payloads are unchanged)
33
+ - `useMarkdownEditor()` gains `tableWidth` / `setTableWidth` for custom
34
+ toolbars
35
+ - New exports: `BlockWidth`, `$getTableWidth`, `$setTableWidth`,
36
+ `$getSelectedTable`, `TABLE_WIDTH_MARKER`
37
+
3
38
  ## 0.3.0
4
39
 
5
40
  - **Custom toolbars**
package/DRAWING_FORMAT.md CHANGED
@@ -22,8 +22,12 @@ degrades to an empty canvas (invalid shapes are dropped individually).
22
22
 
23
23
  - Origin `(0,0)` is the canvas's top-left; x grows right, y grows down.
24
24
  - Units are CSS pixels.
25
- - The canvas is as wide as the editor (fluid). Keep shapes within roughly
26
- x ∈ [0, 700] to be safe on typical layouts.
25
+ - The canvas is as wide as the editor by default (`width` omitted or
26
+ `"full"`). Keep shapes within roughly x ∈ [0, 700] to be safe on typical
27
+ layouts.
28
+ - `"width":"content"` instead sizes the canvas to fit the rightmost shape
29
+ (plus a margin, never narrower than 240px), left-aligned with the text —
30
+ use it for small diagrams that shouldn't stretch across the page.
27
31
  - `height` is the canvas height in pixels (minimum 80; 300–400 is typical).
28
32
 
29
33
  ## Top-level object
@@ -32,6 +36,7 @@ degrades to an empty canvas (invalid shapes are dropped individually).
32
36
  |-----------|-----------|-----------------------------------------|
33
37
  | `version` | `1` | Literal `1` |
34
38
  | `height` | `number` | Canvas height in px |
39
+ | `width` | `"full"` \| `"content"` | Optional; default `"full"`. `"content"` fits the shapes' extent |
35
40
  | `shapes` | `Shape[]` | Render order: later shapes draw on top |
36
41
 
37
42
  ## Shape object
package/README.md CHANGED
@@ -13,6 +13,8 @@ document outline, and collapsible sections.
13
13
  blockquotes, links, fenced code (with syntax highlighting), tables
14
14
  - **Tables**: GFM pipe tables, edited in place (tab between cells, ranges,
15
15
  inline formatting), styled like Claude artifacts
16
+ - **Table settings**: full/content width and row density per table;
17
+ diagrams switch between full and content width too — Slab-style
16
18
  - **Diagrams**: a drawing canvas embedded in the document — cards with
17
19
  attached text slots, bound arrows that follow their cards, elbow and
18
20
  multi-waypoint routing, labels, color palettes, dark mode
@@ -96,6 +98,34 @@ Editing is in place: Tab/arrows between cells, cell range selection, inline
96
98
  formatting inside cells. Cell content is single-line in markdown; newlines
97
99
  are escaped as `\n`.
98
100
 
101
+ ### Table settings: width and density
102
+
103
+ Place the caret in a table and a small toolbar floats at its top-right
104
+ corner:
105
+
106
+ - **Width** — *full* (default: columns share the editor width) or
107
+ *content* (the table shrinks to fit its columns, left-aligned with the
108
+ text, never wider than the editor).
109
+ - **Density** — *compact*, *comfortable* (default), or *spacious* cell
110
+ padding and font size.
111
+
112
+ Non-default settings are persisted as one HTML comment on the line directly
113
+ above the table — other markdown renderers hide it:
114
+
115
+ ```md
116
+ <!-- width: content; density: compact -->
117
+ | Key | Value |
118
+ | --- | --- |
119
+ | Region | eu-west-1 |
120
+ ```
121
+
122
+ Programmatic access: `useMarkdownEditor().tableWidth` / `setTableWidth` and
123
+ `tableDensity` / `setTableDensity` (for custom toolbars), or
124
+ `$getTableSettings(node)` / `$setTableSettings(node, { width, density })`
125
+ inside `editor.update`. `parseTableSettingsMarker` /
126
+ `formatTableSettingsMarker` convert between the comment line and a
127
+ `TableSettings` object.
128
+
99
129
  ## Toolbar & custom toolbars
100
130
 
101
131
  In `edit-md` mode a toolbar offers inline formatting (bold, italic,
@@ -179,8 +209,10 @@ function BoldButton() {
179
209
  ```
180
210
 
181
211
  It returns `editor` (the Lexical instance), `activeFormats`,
182
- `toggleFormat`, `insertTable`, `insertDrawing`, `canUndo`, `canRedo`,
183
- `undo`, `redo`.
212
+ `toggleFormat`, `insertTable`, `insertDrawing`, `tableWidth` /
213
+ `setTableWidth` and `tableDensity` / `setTableDensity` (settings of the
214
+ table containing the selection, `null` outside tables), `canUndo`,
215
+ `canRedo`, `undo`, `redo`.
184
216
 
185
217
  ## Diagrams (drawing canvas)
186
218
 
@@ -203,6 +235,10 @@ in the markdown as a ` ```drawing ` fenced JSON block, fully specified in
203
235
  bends). One-way / two-way arrowhead toggle; midpoint **labels**.
204
236
  - **Canvas**: resizable height, dot grid, white surface that inverts
205
237
  Excalidraw-style in dark mode (`.dark` ancestor class).
238
+ - **Width**: the toggle at the right end of the canvas toolbar switches
239
+ between **full width** (spans the editor) and **content width** (the
240
+ canvas fits the rightmost shape and grows as shapes move). Stored as
241
+ `"width":"content"` in the payload; omitted when full.
206
242
 
207
243
  ## Outline & section folding
208
244
 
@@ -241,6 +277,9 @@ diagrams:
241
277
  | `Toolbar`, `ToolbarButton`, `ToolbarDivider`, `FormatButtons`, `InsertButtons`, `HistoryButtons` | Toolbar primitives |
242
278
  | `@zuilib/text-editor/styles.css` | Editor chrome + theme styles (required) |
243
279
  | `TABLE` | GFM table markdown transformer |
280
+ | `BlockWidth`, `TableDensity`, `TableSettings`, `DEFAULT_TABLE_SETTINGS` | Table setting types |
281
+ | `$getTableSettings`, `$setTableSettings`, `$getTableWidth`, `$setTableWidth`, `$getTableDensity`, `$setTableDensity`, `$getSelectedTable` | Table setting helpers (inside `editor.update`/`read`) |
282
+ | `parseTableSettingsMarker`, `formatTableSettingsMarker` | Marker comment ⇄ `TableSettings` |
244
283
  | `DRAWING`, `DrawingNode`, `$createDrawingNode`, `$isDrawingNode` | Drawing node + markdown transformer |
245
284
  | `FRONTMATTER`, `FrontmatterNode`, `$createFrontmatterNode`, `$isFrontmatterNode` | Frontmatter node + transformer |
246
285
  | `DrawingData`, `DrawingShape`, `DrawingShapeType` | Drawing payload types |
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode, ReactElement } from 'react';
3
3
  import { LexicalEditor, TextFormatType, ElementNode, NodeKey, EditorConfig, SerializedElementNode, LexicalNode, DecoratorNode, Spread, SerializedLexicalNode, DOMExportOutput, DOMConversionMap } from 'lexical';
4
+ import { TableNode } from '@lexical/table';
4
5
  import { MultilineElementTransformer, ElementTransformer } from '@lexical/markdown';
5
6
 
6
7
  type EditorMode = 'edit-raw' | 'edit-md' | 'view';
@@ -40,6 +41,35 @@ declare function EditorContent({ placeholder, foldable, children, }: EditorConte
40
41
  */
41
42
  declare function OutlinePlugin(): ReactElement;
42
43
 
44
+ /**
45
+ * Horizontal sizing of a block that would otherwise span the editor:
46
+ * `full` stretches to the content column, `content` shrinks to fit what is
47
+ * inside (table columns, drawing shapes) and left-aligns with the text.
48
+ */
49
+ type BlockWidth = 'full' | 'content';
50
+
51
+ /** Cell padding / font size preset */
52
+ type TableDensity = 'compact' | 'comfortable' | 'spacious';
53
+ type TableSettings = Readonly<{
54
+ width: BlockWidth;
55
+ density: TableDensity;
56
+ }>;
57
+ declare const DEFAULT_TABLE_SETTINGS: TableSettings;
58
+ declare function $getTableSettings(table: TableNode): TableSettings;
59
+ declare function $setTableSettings(table: TableNode, settings: Partial<TableSettings>): void;
60
+ declare function $getTableWidth(table: TableNode): BlockWidth;
61
+ declare function $setTableWidth(table: TableNode, width: BlockWidth): void;
62
+ declare function $getTableDensity(table: TableNode): TableDensity;
63
+ declare function $setTableDensity(table: TableNode, density: TableDensity): void;
64
+ /** The table containing the current selection (caret or cell range), if any */
65
+ declare function $getSelectedTable(): TableNode | null;
66
+ /** @deprecated Use `formatTableSettingsMarker({ ...DEFAULT_TABLE_SETTINGS, width: 'content' })` */
67
+ declare const TABLE_WIDTH_MARKER = "<!-- width: content -->";
68
+ /** Settings encoded in a marker line, or null if the text is not a marker */
69
+ declare function parseTableSettingsMarker(text: string): Partial<TableSettings> | null;
70
+ /** Marker line for the given settings, or null when everything is default */
71
+ declare function formatTableSettingsMarker(settings: TableSettings): string | null;
72
+
43
73
  type MarkdownEditorApi = Readonly<{
44
74
  /** The underlying Lexical editor, for dispatching your own commands */
45
75
  editor: LexicalEditor;
@@ -51,6 +81,14 @@ type MarkdownEditorApi = Readonly<{
51
81
  columns?: number;
52
82
  }) => void;
53
83
  insertDrawing: () => void;
84
+ /** Width of the table containing the selection; `null` outside tables */
85
+ tableWidth: BlockWidth | null;
86
+ /** Resize the table containing the selection; no-op outside tables */
87
+ setTableWidth: (width: BlockWidth) => void;
88
+ /** Density of the table containing the selection; `null` outside tables */
89
+ tableDensity: TableDensity | null;
90
+ /** Change the density of the table containing the selection; no-op outside tables */
91
+ setTableDensity: (density: TableDensity) => void;
54
92
  canUndo: boolean;
55
93
  canRedo: boolean;
56
94
  undo: () => void;
@@ -213,6 +251,11 @@ type DrawingShape = Readonly<{
213
251
  type DrawingData = Readonly<{
214
252
  version: 1;
215
253
  height: number;
254
+ /**
255
+ * Canvas width: `full` (default, omitted when serialized) spans the editor;
256
+ * `content` fits the shapes' horizontal extent.
257
+ */
258
+ width?: BlockWidth;
216
259
  shapes: readonly DrawingShape[];
217
260
  }>;
218
261
  declare function serializeDrawingData(data: DrawingData): string;
@@ -257,6 +300,9 @@ declare const DRAWING: MultilineElementTransformer;
257
300
  * Markdown transformer for GFM tables. Adapted from the Lexical playground.
258
301
  * Rows are matched line-by-line on import and stitched into a single
259
302
  * TableNode; the divider row promotes the row above it to a header row.
303
+ * A `<!-- width: content; density: compact -->` settings line directly
304
+ * above the table (see tableSettings.ts) is consumed on import and
305
+ * re-emitted on export.
260
306
  */
261
307
  declare const TABLE: ElementTransformer;
262
308
 
@@ -282,7 +328,11 @@ declare const DRAWING_DATA_JSON_SCHEMA: {
282
328
  readonly height: {
283
329
  readonly type: "number";
284
330
  readonly minimum: 80;
285
- readonly description: "Canvas height in pixels (width is fluid)";
331
+ readonly description: "Canvas height in pixels";
332
+ };
333
+ readonly width: {
334
+ readonly enum: readonly ["full", "content"];
335
+ readonly description: "Canvas width: \"full\" (default) spans the editor; \"content\" fits the shapes' horizontal extent and left-aligns with the text";
286
336
  };
287
337
  readonly shapes: {
288
338
  readonly type: "array";
@@ -392,4 +442,4 @@ declare const DRAWING_DATA_JSON_SCHEMA: {
392
442
  };
393
443
  };
394
444
 
395
- export { $createDrawingNode, $createFrontmatterNode, $isDrawingNode, $isFrontmatterNode, DRAWING, DRAWING_DATA_JSON_SCHEMA, type DrawingData, DrawingNode, type DrawingShape, type DrawingShapeType, type EditorContentProps, type EditorMode, type EditorRootProps, FRONTMATTER, FormatButtons, FrontmatterNode, HistoryButtons, InsertButtons, MarkdownEditor, type MarkdownEditorApi, type Props as MarkdownEditorProps, type SerializedDrawingNode, type SerializedFrontmatterNode, TABLE, Toolbar, ToolbarButton, ToolbarDivider, type ToolbarItems, parseDrawingData, serializeDrawingData, useMarkdownEditor };
445
+ export { $createDrawingNode, $createFrontmatterNode, $getSelectedTable, $getTableDensity, $getTableSettings, $getTableWidth, $isDrawingNode, $isFrontmatterNode, $setTableDensity, $setTableSettings, $setTableWidth, type BlockWidth, DEFAULT_TABLE_SETTINGS, DRAWING, DRAWING_DATA_JSON_SCHEMA, type DrawingData, DrawingNode, type DrawingShape, type DrawingShapeType, type EditorContentProps, type EditorMode, type EditorRootProps, FRONTMATTER, FormatButtons, FrontmatterNode, HistoryButtons, InsertButtons, MarkdownEditor, type MarkdownEditorApi, type Props as MarkdownEditorProps, type SerializedDrawingNode, type SerializedFrontmatterNode, TABLE, TABLE_WIDTH_MARKER, type TableDensity, type TableSettings, Toolbar, ToolbarButton, ToolbarDivider, type ToolbarItems, formatTableSettingsMarker, parseDrawingData, parseTableSettingsMarker, serializeDrawingData, useMarkdownEditor };