@ngstarter-ui/components 22.2.1 → 22.2.3

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.
Files changed (46) hide show
  1. package/ai/component-registry.json +15 -0
  2. package/content-editor/BLOCK_FORMAT.md +717 -0
  3. package/content-editor/document.schema.json +1598 -0
  4. package/fesm2022/ngstarter-ui-components-color-picker.mjs +147 -272
  5. package/fesm2022/ngstarter-ui-components-color-picker.mjs.map +1 -1
  6. package/fesm2022/{ngstarter-ui-components-content-editor-attachment-block-B2GUlWO2.mjs → ngstarter-ui-components-content-editor-attachment-block-DlUkhwCu.mjs} +3 -3
  7. package/fesm2022/{ngstarter-ui-components-content-editor-attachment-block-B2GUlWO2.mjs.map → ngstarter-ui-components-content-editor-attachment-block-DlUkhwCu.mjs.map} +1 -1
  8. package/fesm2022/{ngstarter-ui-components-content-editor-block-base-BHAxKEOT.mjs → ngstarter-ui-components-content-editor-block-base-C46lyMrp.mjs} +2 -2
  9. package/fesm2022/{ngstarter-ui-components-content-editor-block-base-BHAxKEOT.mjs.map → ngstarter-ui-components-content-editor-block-base-C46lyMrp.mjs.map} +1 -1
  10. package/fesm2022/{ngstarter-ui-components-content-editor-callout-block-Cnga7Z-6.mjs → ngstarter-ui-components-content-editor-callout-block-Jbf8h2yz.mjs} +3 -3
  11. package/fesm2022/{ngstarter-ui-components-content-editor-callout-block-Cnga7Z-6.mjs.map → ngstarter-ui-components-content-editor-callout-block-Jbf8h2yz.mjs.map} +1 -1
  12. package/fesm2022/{ngstarter-ui-components-content-editor-code-block.component-DSdVOJtH.mjs → ngstarter-ui-components-content-editor-code-block.component-BizHRPdC.mjs} +2 -2
  13. package/fesm2022/{ngstarter-ui-components-content-editor-code-block.component-DSdVOJtH.mjs.map → ngstarter-ui-components-content-editor-code-block.component-BizHRPdC.mjs.map} +1 -1
  14. package/fesm2022/{ngstarter-ui-components-content-editor-embed-block-DhFxtMQS.mjs → ngstarter-ui-components-content-editor-embed-block-BzoaJvai.mjs} +2 -2
  15. package/fesm2022/{ngstarter-ui-components-content-editor-embed-block-DhFxtMQS.mjs.map → ngstarter-ui-components-content-editor-embed-block-BzoaJvai.mjs.map} +1 -1
  16. package/fesm2022/{ngstarter-ui-components-content-editor-gallery-block-cEy-dCMa.mjs → ngstarter-ui-components-content-editor-gallery-block-C4p-S0Do.mjs} +3 -3
  17. package/fesm2022/{ngstarter-ui-components-content-editor-gallery-block-cEy-dCMa.mjs.map → ngstarter-ui-components-content-editor-gallery-block-C4p-S0Do.mjs.map} +1 -1
  18. package/fesm2022/{ngstarter-ui-components-content-editor-grid-block-DFLGRFiO.mjs → ngstarter-ui-components-content-editor-grid-block-Cdq_Dcv2.mjs} +4 -4
  19. package/fesm2022/{ngstarter-ui-components-content-editor-grid-block-DFLGRFiO.mjs.map → ngstarter-ui-components-content-editor-grid-block-Cdq_Dcv2.mjs.map} +1 -1
  20. package/fesm2022/{ngstarter-ui-components-content-editor-heading-block.component-BYpctSPe.mjs → ngstarter-ui-components-content-editor-heading-block.component-CDSt4rXe.mjs} +2 -2
  21. package/fesm2022/{ngstarter-ui-components-content-editor-heading-block.component-BYpctSPe.mjs.map → ngstarter-ui-components-content-editor-heading-block.component-CDSt4rXe.mjs.map} +1 -1
  22. package/fesm2022/{ngstarter-ui-components-content-editor-image-block.component-B3MnANpi.mjs → ngstarter-ui-components-content-editor-image-block.component-LfKZapgv.mjs} +2 -2
  23. package/fesm2022/{ngstarter-ui-components-content-editor-image-block.component-B3MnANpi.mjs.map → ngstarter-ui-components-content-editor-image-block.component-LfKZapgv.mjs.map} +1 -1
  24. package/fesm2022/{ngstarter-ui-components-content-editor-list-block.component-6SMBxIl4.mjs → ngstarter-ui-components-content-editor-list-block.component-CdQ30RjA.mjs} +2 -2
  25. package/fesm2022/{ngstarter-ui-components-content-editor-list-block.component-6SMBxIl4.mjs.map → ngstarter-ui-components-content-editor-list-block.component-CdQ30RjA.mjs.map} +1 -1
  26. package/fesm2022/{ngstarter-ui-components-content-editor-nested-blocks-DSY7xfzf.mjs → ngstarter-ui-components-content-editor-nested-blocks-CbZY0keH.mjs} +2 -2
  27. package/fesm2022/{ngstarter-ui-components-content-editor-nested-blocks-DSY7xfzf.mjs.map → ngstarter-ui-components-content-editor-nested-blocks-CbZY0keH.mjs.map} +1 -1
  28. package/fesm2022/{ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor--rb3-UuO.mjs → ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-CK4ssnlk.mjs} +578 -19
  29. package/fesm2022/ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-CK4ssnlk.mjs.map +1 -0
  30. package/fesm2022/{ngstarter-ui-components-content-editor-paragraph-block.component-JVxf_Cdx.mjs → ngstarter-ui-components-content-editor-paragraph-block.component-Dd0pQquG.mjs} +2 -2
  31. package/fesm2022/{ngstarter-ui-components-content-editor-paragraph-block.component-JVxf_Cdx.mjs.map → ngstarter-ui-components-content-editor-paragraph-block.component-Dd0pQquG.mjs.map} +1 -1
  32. package/fesm2022/{ngstarter-ui-components-content-editor-quote-block.component-7EO7z7Sr.mjs → ngstarter-ui-components-content-editor-quote-block.component-CUxKoeb_.mjs} +2 -2
  33. package/fesm2022/{ngstarter-ui-components-content-editor-quote-block.component-7EO7z7Sr.mjs.map → ngstarter-ui-components-content-editor-quote-block.component-CUxKoeb_.mjs.map} +1 -1
  34. package/fesm2022/{ngstarter-ui-components-content-editor-table-block.component-CJS-IBHw.mjs → ngstarter-ui-components-content-editor-table-block.component-BTExrXy8.mjs} +2 -2
  35. package/fesm2022/{ngstarter-ui-components-content-editor-table-block.component-CJS-IBHw.mjs.map → ngstarter-ui-components-content-editor-table-block.component-BTExrXy8.mjs.map} +1 -1
  36. package/fesm2022/{ngstarter-ui-components-content-editor-toggle-block-B01lhY_V.mjs → ngstarter-ui-components-content-editor-toggle-block-B46YeMGQ.mjs} +4 -4
  37. package/fesm2022/{ngstarter-ui-components-content-editor-toggle-block-B01lhY_V.mjs.map → ngstarter-ui-components-content-editor-toggle-block-B46YeMGQ.mjs.map} +1 -1
  38. package/fesm2022/{ngstarter-ui-components-content-editor-upload-block-base-D9ELpJr-.mjs → ngstarter-ui-components-content-editor-upload-block-base-DKqojf--.mjs} +3 -3
  39. package/fesm2022/{ngstarter-ui-components-content-editor-upload-block-base-D9ELpJr-.mjs.map → ngstarter-ui-components-content-editor-upload-block-base-DKqojf--.mjs.map} +1 -1
  40. package/fesm2022/{ngstarter-ui-components-content-editor-video-block.component-DQUPVDwV.mjs → ngstarter-ui-components-content-editor-video-block.component-hBR5AauH.mjs} +2 -2
  41. package/fesm2022/{ngstarter-ui-components-content-editor-video-block.component-DQUPVDwV.mjs.map → ngstarter-ui-components-content-editor-video-block.component-hBR5AauH.mjs.map} +1 -1
  42. package/fesm2022/ngstarter-ui-components-content-editor.mjs +1 -1
  43. package/package.json +3 -1
  44. package/types/ngstarter-ui-components-color-picker.d.ts +2 -2
  45. package/types/ngstarter-ui-components-content-editor.d.ts +102 -13
  46. package/fesm2022/ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor--rb3-UuO.mjs.map +0 -1
@@ -0,0 +1,717 @@
1
+ # Content Editor block format and import
2
+
3
+ Import public APIs from `@ngstarter-ui/components/content-editor`. This is the native Headless Editor version-1 document, not editor view objects or HTML stored in JSON strings. Third-party systems can export this format directly.
4
+
5
+ The package includes `@ngstarter-ui/components/content-editor/document.schema.json` (JSON Schema draft 2020-12) and this reference. The schema describes built-in blocks; custom schemas may extend its block alternatives. Semantic validation also checks global block ID uniqueness, gallery/cell ID uniqueness, resource/link URLs, color values and configurable size/depth limits.
6
+
7
+ ## Envelope and common fields
8
+
9
+ ```typescript
10
+ type Document = { version: 1; blocks: Block[] };
11
+ type Block<T = unknown> = { id: string; type: string; content: T;
12
+ attrs?: { settings?: Record<string, unknown>; props?: Property[];
13
+ [key: string]: unknown } };
14
+ type Property = { name: string; value: string };
15
+ type TextRun = { type: 'text'; text: string; marks: Mark[] };
16
+ type Mark = { type: string;
17
+ attrs?: Record<string, string | number | boolean | null> };
18
+ ```
19
+
20
+ - `version` is exactly `1`; `blocks` is an ordered array, including an empty array. Only these envelope fields are part of the contract.
21
+ - `id` is a non-empty string, globally unique across root blocks, toggle descendants and grid cells' descendants. External IDs are accepted and preserved; JSON import never silently changes duplicate IDs.
22
+ - `type` is one of the 16 built-in types below. `content` is required and varies by type. `attrs` is optional except for tables, which need `attrs.rows`.
23
+ - `attrs.settings` is a JSON object of block-specific settings. `attrs.props` is an optional array of `{name,value}` strings. The supported alignment property is `{name:'text-alignment',value:'left'|'center'|'right'|'justify'}`.
24
+ - Unknown JSON fields inside block content/attrs are retained. Functions, Dates, non-finite numbers and cycles are rejected; undefined optional object properties are omitted, as in JSON serialization. Do not save component instances, input signals, runtime callbacks, isEmpty or builder cell/view objects.
25
+ - Text is `TextRun[]`, never an HTML string. Each run requires `type:'text'`, `text` and `marks:[]` (or populated marks). Empty text is `[]` or `[{type:'text',text:'',marks:[]}]`; newline characters remain literal text.
26
+ - The editor normalizes empty root documents to an editable paragraph and may normalize adjacent text runs, mark ordering and table rows. Import parsing itself returns a detached document without changing the caller's object.
27
+
28
+ ## Marks
29
+
30
+ ### bold / italic / strike / underline / code / superscript / subscript
31
+
32
+ No attrs required.
33
+
34
+ HTML mapping: strong/b, em/i, s/strike, u, code, sup, sub.
35
+
36
+ ### link
37
+
38
+ attrs.href: non-empty URL; attrs.target?: _blank | _self.
39
+
40
+ HTML mapping: a[href]; unsafe links keep their visible text without a link mark..
41
+
42
+ ### textColor / backgroundColor
43
+
44
+ attrs.color: supported CSS color string.
45
+
46
+ HTML mapping: span style color/background-color; both can be applied together..
47
+
48
+ ### Custom mark
49
+
50
+ Any non-empty type and scalar attrs; register matching Headless Editor mark definitions for UI rendering.
51
+
52
+ HTML mapping: Use config.importMarks with type/tagName/parseTags/readAttributes; export customization uses config.marks..
53
+
54
+ Colors accept supported hexadecimal, named, rgb/rgba, hsl/hsla and modern CSS color expressions or safe var(--token) references. URLs allow web, mail, telephone and relative links; executable schemes are rejected. Media resources allow web/relative URLs and applicable data/blob URLs, while iframe embeds allow web/relative URLs only. Use the importer as well as the schema for semantic checks.
55
+
56
+ ## Block reference
57
+
58
+ ### `paragraph` — Paragraph
59
+
60
+ content: TextRun[]. attrs.props?: Property[].
61
+
62
+ Text runs; use an empty array or an empty text run for an empty paragraph. Alignment is a text-alignment property, not a setting.
63
+
64
+ HTML mapping: p and unwrapped inline text.
65
+
66
+ ```json
67
+ {
68
+ "id": "paragraph",
69
+ "type": "paragraph",
70
+ "content": [
71
+ {
72
+ "type": "text",
73
+ "text": "Hello ",
74
+ "marks": [
75
+ {
76
+ "type": "bold"
77
+ }
78
+ ]
79
+ },
80
+ {
81
+ "type": "text",
82
+ "text": "world",
83
+ "marks": [
84
+ {
85
+ "type": "link",
86
+ "attrs": {
87
+ "href": "https://example.com",
88
+ "target": "_blank"
89
+ }
90
+ }
91
+ ]
92
+ }
93
+ ],
94
+ "attrs": {
95
+ "props": [
96
+ {
97
+ "name": "text-alignment",
98
+ "value": "left"
99
+ }
100
+ ]
101
+ }
102
+ }
103
+ ```
104
+
105
+ ### `heading` — Heading
106
+
107
+ content: TextRun[]. attrs.settings.level?: 1 | 2 | 3 | 4 | 5 | 6.
108
+
109
+ Level defaults to 2 when omitted. The native type is heading; the level belongs to attrs.settings.
110
+
111
+ HTML mapping: h1–h6 preserve the heading level.
112
+
113
+ ```json
114
+ {
115
+ "id": "heading",
116
+ "type": "heading",
117
+ "content": [
118
+ {
119
+ "type": "text",
120
+ "text": "Section",
121
+ "marks": []
122
+ }
123
+ ],
124
+ "attrs": {
125
+ "settings": {
126
+ "level": 2
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ ### `code` — Code
133
+
134
+ content: TextRun[]. attrs.settings.language?: string.
135
+
136
+ language defaults to none. Text is literal source code, including newline characters. HTML export escapes it and ignores text marks.
137
+
138
+ HTML mapping: pre > code; data-language or language-* class supplies the language.
139
+
140
+ ```json
141
+ {
142
+ "id": "code",
143
+ "type": "code",
144
+ "content": [
145
+ {
146
+ "type": "text",
147
+ "text": "const answer = 42;\nconsole.log(answer);",
148
+ "marks": []
149
+ }
150
+ ],
151
+ "attrs": {
152
+ "settings": {
153
+ "language": "javascript"
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ ### `divider` — Divider
160
+
161
+ content: null.
162
+
163
+ No content fields or block-specific settings.
164
+
165
+ HTML mapping: hr.
166
+
167
+ ```json
168
+ {
169
+ "id": "divider",
170
+ "type": "divider",
171
+ "content": null
172
+ }
173
+ ```
174
+
175
+ ### `bulletList` — Bullet list
176
+
177
+ content: ListItem[]. ListItem = { content: TextRun[], children: ListItem[], props?: Property[] }. attrs.settings.listStyle?: "bullet" | "ordered".
178
+
179
+ children is required, including [] for leaf items. Each nested item can have its own alignment. Item IDs are not used. The block type determines the exported list tag.
180
+
181
+ HTML mapping: ul > li; nested lists become children. Mixed nested list styles use the parent block style.
182
+
183
+ ```json
184
+ {
185
+ "id": "bullet-list",
186
+ "type": "bulletList",
187
+ "content": [
188
+ {
189
+ "content": [
190
+ {
191
+ "type": "text",
192
+ "text": "Parent",
193
+ "marks": []
194
+ }
195
+ ],
196
+ "children": [
197
+ {
198
+ "content": [
199
+ {
200
+ "type": "text",
201
+ "text": "Child",
202
+ "marks": []
203
+ }
204
+ ],
205
+ "children": []
206
+ }
207
+ ]
208
+ }
209
+ ],
210
+ "attrs": {
211
+ "settings": {
212
+ "listStyle": "bullet"
213
+ }
214
+ }
215
+ }
216
+ ```
217
+
218
+ ### `orderedList` — Ordered list
219
+
220
+ content: ListItem[]. attrs.settings.listStyle?: "bullet" | "ordered".
221
+
222
+ Uses the same recursive item shape as bulletList. The editor creates listStyle: ordered. Numbering/start counters are not part of this format.
223
+
224
+ HTML mapping: ol > li, including nested items.
225
+
226
+ ```json
227
+ {
228
+ "id": "ordered-list",
229
+ "type": "orderedList",
230
+ "content": [
231
+ {
232
+ "content": [
233
+ {
234
+ "type": "text",
235
+ "text": "First item",
236
+ "marks": []
237
+ }
238
+ ],
239
+ "children": []
240
+ }
241
+ ],
242
+ "attrs": {
243
+ "settings": {
244
+ "listStyle": "ordered"
245
+ }
246
+ }
247
+ }
248
+ ```
249
+
250
+ ### `quote` — Quote
251
+
252
+ content: { cite: { content: TextRun[], props?: Property[] }, caption: { content: TextRun[], props?: Property[] } }.
253
+
254
+ Both cite and caption are required. Use caption.content: [] when no attribution is present. Alignment can differ between quote and caption.
255
+
256
+ HTML mapping: blockquote, or figure > blockquote plus figcaption.
257
+
258
+ ```json
259
+ {
260
+ "id": "quote",
261
+ "type": "quote",
262
+ "content": {
263
+ "cite": {
264
+ "content": [
265
+ {
266
+ "type": "text",
267
+ "text": "A quotation",
268
+ "marks": []
269
+ }
270
+ ],
271
+ "props": []
272
+ },
273
+ "caption": {
274
+ "content": [
275
+ {
276
+ "type": "text",
277
+ "text": "Author",
278
+ "marks": []
279
+ }
280
+ ],
281
+ "props": []
282
+ }
283
+ }
284
+ }
285
+ ```
286
+
287
+ ### `table` — Table
288
+
289
+ content: null. attrs.rows: TextRun[][][]. attrs.header?: boolean. attrs.cellMetadata?: CellMetadata[][]. CellMetadata = { props?: Property[], options?: { colspan?: positive integer, rowspan?: positive integer, width?: positive number | "auto" | null }, styles?: object }.
290
+
291
+ Index rows[row][column] to get the text runs of one cell; metadata uses the same row/column indexes. header defaults to false. Spans default to 1. At most 500 rows and 50 columns; keep a consistent logical row width. Headless Editor pads ragged/empty rows on rendering. styles and other JSON metadata are retained, but only alignment/spans/width are used by built-in export. Never put builder UI cell objects in content.
292
+
293
+ HTML mapping: table rows, th/td, colspan/rowspan/width and text-align. A th in the first row enables the header.
294
+
295
+ ```json
296
+ {
297
+ "id": "table",
298
+ "type": "table",
299
+ "content": null,
300
+ "attrs": {
301
+ "rows": [
302
+ [
303
+ [
304
+ {
305
+ "type": "text",
306
+ "text": "Name",
307
+ "marks": []
308
+ }
309
+ ],
310
+ [
311
+ {
312
+ "type": "text",
313
+ "text": "Value",
314
+ "marks": []
315
+ }
316
+ ]
317
+ ],
318
+ [
319
+ [
320
+ {
321
+ "type": "text",
322
+ "text": "Answer",
323
+ "marks": []
324
+ }
325
+ ],
326
+ [
327
+ {
328
+ "type": "text",
329
+ "text": "42",
330
+ "marks": []
331
+ }
332
+ ]
333
+ ]
334
+ ],
335
+ "header": true,
336
+ "cellMetadata": [
337
+ [
338
+ {
339
+ "props": [],
340
+ "options": {
341
+ "colspan": 1,
342
+ "rowspan": 1,
343
+ "width": 180
344
+ }
345
+ },
346
+ {
347
+ "props": [],
348
+ "options": {
349
+ "colspan": 1,
350
+ "rowspan": 1
351
+ }
352
+ }
353
+ ],
354
+ [
355
+ {
356
+ "props": [],
357
+ "options": {
358
+ "colspan": 1,
359
+ "rowspan": 1
360
+ }
361
+ },
362
+ {
363
+ "props": [],
364
+ "options": {
365
+ "colspan": 1,
366
+ "rowspan": 1
367
+ }
368
+ }
369
+ ]
370
+ ]
371
+ }
372
+ }
373
+ ```
374
+
375
+ ### `image` — Image
376
+
377
+ content: { src: string, alt: string }. attrs.settings?: { width?, height?, actualWidth?, actualHeight? }.
378
+
379
+ Dimensions are positive pixel numbers, auto or null; actualWidth/actualHeight are optional source metadata. src and alt may be empty for an unfilled block. The built-in renderer also displays alt as its caption; there is no separate image caption field.
380
+
381
+ HTML mapping: img, optionally inside figure. src, alt, width and height are imported; arbitrary figure caption text is not a separate image field.
382
+
383
+ ```json
384
+ {
385
+ "id": "image",
386
+ "type": "image",
387
+ "content": {
388
+ "src": "/assets/chairs.jpg",
389
+ "alt": "A meeting room"
390
+ },
391
+ "attrs": {
392
+ "settings": {
393
+ "width": 640,
394
+ "height": "auto"
395
+ }
396
+ }
397
+ }
398
+ ```
399
+
400
+ ### `video` — Video
401
+
402
+ content: { src: string, caption: string, orientation?: "portrait" | "landscape" }. attrs.settings?: { width?, height?, actualWidth?, actualHeight? }.
403
+
404
+ caption is a plain string, not text runs. src/caption may be empty. Dimensions use the same types as image.
405
+
406
+ HTML mapping: video (or its source child), optionally inside figure with figcaption. Orientation defaults to landscape because ordinary HTML has no orientation metadata.
407
+
408
+ ```json
409
+ {
410
+ "id": "video",
411
+ "type": "video",
412
+ "content": {
413
+ "src": "https://example.com/movie.mp4",
414
+ "caption": "Product demo",
415
+ "orientation": "landscape"
416
+ },
417
+ "attrs": {
418
+ "settings": {
419
+ "width": 640
420
+ }
421
+ }
422
+ }
423
+ ```
424
+
425
+ ### `embed` — Embed
426
+
427
+ content: { url: string, type: string }. attrs.settings?: { width?, height? }.
428
+
429
+ Save the embed URL, not the share-page URL. Built-in providers include pdf, youtube, vimeo, spotify, google-maps, google-docs, google-drive, codepen, figma, loom, twitter, instagram, tiktok, soundcloud, stackblitz, gist and website. The editor resolves provider URLs when entered. width/height accept positive numbers, auto or null; HTML export uses 700 × 400 if omitted.
430
+
431
+ HTML mapping: iframe src/width/height. HTML title becomes type; provider metadata cannot be reliably recovered from arbitrary markup. A custom fromHtml handler can resolve provider-specific types.
432
+
433
+ ```json
434
+ {
435
+ "id": "embed",
436
+ "type": "embed",
437
+ "content": {
438
+ "url": "https://www.youtube.com/embed/example",
439
+ "type": "youtube"
440
+ },
441
+ "attrs": {
442
+ "settings": {
443
+ "width": 700,
444
+ "height": 400
445
+ }
446
+ }
447
+ }
448
+ ```
449
+
450
+ ### `callout` — Callout
451
+
452
+ content: TextRun[]. attrs.settings.variant?: "note" | "tip" | "warning" | "danger".
453
+
454
+ Variant defaults to note. Block alignment uses attrs.props.
455
+
456
+ HTML mapping: aside[data-callout] or .ngs-content-editor-html-callout.
457
+
458
+ ```json
459
+ {
460
+ "id": "callout",
461
+ "type": "callout",
462
+ "content": [
463
+ {
464
+ "type": "text",
465
+ "text": "Remember this",
466
+ "marks": []
467
+ }
468
+ ],
469
+ "attrs": {
470
+ "settings": {
471
+ "variant": "tip"
472
+ }
473
+ }
474
+ }
475
+ ```
476
+
477
+ ### `toggle` — Toggle
478
+
479
+ content: { title: TextRun[], blocks: Block[] }. attrs.settings.expanded?: boolean.
480
+
481
+ title and blocks are required; nested blocks follow the exact same block contract. Missing expanded means closed in the reader. New editor blocks are created expanded.
482
+
483
+ HTML mapping: details > summary and nested content; open sets expanded.
484
+
485
+ ```json
486
+ {
487
+ "id": "toggle",
488
+ "type": "toggle",
489
+ "content": {
490
+ "title": [
491
+ {
492
+ "type": "text",
493
+ "text": "Details",
494
+ "marks": []
495
+ }
496
+ ],
497
+ "blocks": [
498
+ {
499
+ "id": "toggle-paragraph",
500
+ "type": "paragraph",
501
+ "content": [
502
+ {
503
+ "type": "text",
504
+ "text": "Nested content",
505
+ "marks": []
506
+ }
507
+ ]
508
+ }
509
+ ]
510
+ },
511
+ "attrs": {
512
+ "settings": {
513
+ "expanded": true
514
+ }
515
+ }
516
+ }
517
+ ```
518
+
519
+ ### `attachment` — Attachment
520
+
521
+ content: { url: string, name: string, size: non-negative integer, mimeType: string }.
522
+
523
+ size is the file size in bytes, not a formatted label. URL/name/MIME may be empty for an unfilled block. Upload callbacks are runtime configuration and never part of saved JSON.
524
+
525
+ HTML mapping: a[download]. Name comes from download or link text. HTML does not contain reliable file size/MIME metadata, so size is 0 and mimeType is an empty string.
526
+
527
+ ```json
528
+ {
529
+ "id": "attachment",
530
+ "type": "attachment",
531
+ "content": {
532
+ "url": "https://example.com/guide.pdf",
533
+ "name": "guide.pdf",
534
+ "size": 2048,
535
+ "mimeType": "application/pdf"
536
+ }
537
+ }
538
+ ```
539
+
540
+ ### `gallery` — Gallery / carousel
541
+
542
+ content: { images: { id: string, src: string, alt: string, caption: TextRun[] }[] }.
543
+
544
+ All four fields are required for each image. Image IDs must be unique inside this gallery. Order is the array order. caption supports marks in the reader/export; the editor edits it as ordinary text. No Grid/Carousel mode field is supported. Empty images: [] is valid.
545
+
546
+ HTML mapping: [data-content-editor="gallery"] or .ngs-content-editor-html-gallery, with figure/img/figcaption. HTML generates fresh image IDs.
547
+
548
+ ```json
549
+ {
550
+ "id": "gallery",
551
+ "type": "gallery",
552
+ "content": {
553
+ "images": [
554
+ {
555
+ "id": "photo-one",
556
+ "src": "/assets/chairs.jpg",
557
+ "alt": "Meeting room",
558
+ "caption": [
559
+ {
560
+ "type": "text",
561
+ "text": "A bright workspace",
562
+ "marks": []
563
+ }
564
+ ]
565
+ },
566
+ {
567
+ "id": "photo-two",
568
+ "src": "/assets/chairs2.jpg",
569
+ "alt": "Another room",
570
+ "caption": []
571
+ }
572
+ ]
573
+ }
574
+ }
575
+ ```
576
+
577
+ ### `grid` — Grid
578
+
579
+ content: { cells: { id: string, blocks: Block[] }[] }. attrs.settings?: { columns?: 2 | 3 | 4, gap?: "small" | "medium" | "large", stackOnMobile?: boolean }.
580
+
581
+ Defaults: columns 2, gap medium (24 px), stackOnMobile true. Small/large gaps are 12/36 px. Cells have IDs unique inside their grid; all nested block IDs remain globally unique. Order is the cells array, row-major. Empty cells/collections are valid. The editor may show a normal empty paragraph for editing. There is no columns block or migration format.
582
+
583
+ HTML mapping: .ngs-content-editor-html-grid > .ngs-content-editor-html-grid-cells > .ngs-content-editor-html-grid-cell. CSS variables --ngs-html-grid-columns/--ngs-html-grid-gap and the -stack class recover exported layout settings.
584
+
585
+ ```json
586
+ {
587
+ "id": "grid",
588
+ "type": "grid",
589
+ "content": {
590
+ "cells": [
591
+ {
592
+ "id": "cell-one",
593
+ "blocks": [
594
+ {
595
+ "id": "grid-heading",
596
+ "type": "heading",
597
+ "content": [
598
+ {
599
+ "type": "text",
600
+ "text": "Overview",
601
+ "marks": []
602
+ }
603
+ ],
604
+ "attrs": {
605
+ "settings": {
606
+ "level": 3
607
+ }
608
+ }
609
+ }
610
+ ]
611
+ },
612
+ {
613
+ "id": "cell-two",
614
+ "blocks": [
615
+ {
616
+ "id": "grid-paragraph",
617
+ "type": "paragraph",
618
+ "content": [
619
+ {
620
+ "type": "text",
621
+ "text": "Grid content",
622
+ "marks": []
623
+ }
624
+ ]
625
+ }
626
+ ]
627
+ }
628
+ ]
629
+ },
630
+ "attrs": {
631
+ "settings": {
632
+ "columns": 2,
633
+ "gap": "medium",
634
+ "stackOnMobile": true
635
+ }
636
+ }
637
+ }
638
+ ```
639
+
640
+ ## Import API
641
+
642
+ ```typescript
643
+ import { ContentEditorImporter, contentEditorFromJson, contentEditorFromHtml,
644
+ ContentEditorImportError } from '@ngstarter-ui/components/content-editor';
645
+
646
+ // Pure functions: only the explicitly supplied configuration is used.
647
+ const fromJson = contentEditorFromJson(jsonStringOrObject);
648
+ const fromHtml = contentEditorFromHtml('<h2>Hello</h2><p><strong>World</strong></p>');
649
+
650
+ // Injected service: environment defaults are inherited.
651
+ readonly importer = inject(ContentEditorImporter);
652
+ const parsed = this.importer.fromJson(source);
653
+
654
+ // Builder methods replace the live document as one undoable edit.
655
+ builder.importJson(jsonStringOrObject);
656
+ builder.importHtml(html);
657
+ const nativeDocument = builder.getData();
658
+ const htmlExport = builder.toHtml();
659
+
660
+ try { builder.importJson(source); }
661
+ catch (error) {
662
+ if (error instanceof ContentEditorImportError) {
663
+ console.log(error.path, error.message);
664
+ }
665
+ }
666
+ ```
667
+
668
+ - `contentEditorFromJson(source, config?, options?)`: accepts JSON text or an unknown native object; validates all nested structures before returning `ContentEditorDocument`.
669
+ - `contentEditorFromHtml(html, config?, options?)`: imports HTML text into a detached document. Requires a DOM implementation. For server-side use, pass `{document: domDocument}` as the third argument; the parser uses `document.implementation.createHTMLDocument()` as an inert parsing document.
670
+ - `ContentEditorImporter.fromJson/fromHtml`: same signatures, with injected environment configuration and DOCUMENT for HTML parsing. Standalone pure functions do not read Angular providers.
671
+ - `builder.importJson/importHtml`: same source/config/options arguments; replaces the live document as one undoable edit, clears stale block selection and emits contentChanged through the existing change mechanism. Failed import never changes content, selection, history or draft. The return value is the live document after editor normalization. Methods require an initialized builder.
672
+ - Import options: `maxDepth: 64`, `maxBlocks: 10000`, `allowUnknownBlocks: false` by default. Blocks include descendants; depth checks protect both the source tree and returned JSON. Positive integer limits are required. To transport an application-specific JSON block without a declared config, opt in with allowUnknownBlocks. This does not create an editor UI or Angular renderer for it.
673
+ - Configuration priority: built-in parsing, environment provider, builder instance config, per-call config. `provideContentEditorConfig` works in application/route providers and inherits parent environments. It configures both imports and exports; a route gets its own importer so overrides apply to injected calls.
674
+ - Errors: ContentEditorImportError exposes `path` and `message`, for example `$.blocks[2].content.cells[0].blocks[1].id: Duplicate block ID`. Parsing stops at the first invalid field. Callback errors also propagate; no document is applied.
675
+
676
+ ## HTML fidelity and extension points
677
+
678
+ HTML import is structural conversion, not arbitrary DOM serialization. It groups inline content into paragraphs, preserves supported semantic blocks/marks/alignment, ignores scripts/styles/noscript/template/object/embed content, filters unsafe resource/link URLs, and never saves event handlers or arbitrary HTML/CSS. A hyperlink with an unsafe URL keeps its text. Unsupported layout wrappers keep their supported text and descendants; unsafe/unsupported media is omitted. Empty paragraphs, br line breaks and literal code are supported.
679
+
680
+ The default HTML exported by Content Editor is recognized for callouts, galleries and responsive grids as well as standard paragraphs, headings, lists, quotes, tables, images, videos, iframes, details and downloads. HTML cannot recover original block/cell/image IDs, upload metadata, unknown attrs, video orientation or attachment size/MIME; it generates fresh IDs/default metadata. Mixed nested list styles map to the parent list type. For a lossless transfer, use native JSON. There is no implicit old-format migration.
681
+
682
+ Per-block `fromHtml` contains `selector` and `parse(element, ctx)`. It runs before the built-in parser; return a block, an array of blocks, or null to discard that element. Use `ctx.createBlock`, `createId`, `parseText`, `parseBlocks`, `safeUrl` and `defaultFromHtml`. The latter bypasses the same override and lets you extend standard parsing without recursion. `parseBlocks` retains configured overrides for descendants. Parsed custom blocks are still JSON-validated. `validateImport(block)` returns undefined on success or an error message to reject the block. Built-in validation always runs before an additional custom validator.
683
+
684
+ ```typescript
685
+ provideContentEditorConfig({
686
+ blocks: {
687
+ heading: {
688
+ fromHtml: {
689
+ selector: 'h1, h2, h3, h4, h5, h6',
690
+ parse: (element, ctx) => ctx.defaultFromHtml(element)
691
+ }
692
+ },
693
+ product: {
694
+ fromHtml: {
695
+ selector: '[data-product-id]',
696
+ parse: (element, ctx) => ctx.createBlock('product', {
697
+ productId: element.getAttribute('data-product-id')
698
+ })
699
+ },
700
+ validateImport: block => typeof (block.content as { productId?: unknown })?.productId === 'string'
701
+ ? undefined : 'productId must be a string',
702
+ toHtml: (block, ctx) => `<div data-product-id="${ctx.escape((block.content as { productId: string }).productId)}"></div>`
703
+ }
704
+ }
705
+ });
706
+ ```
707
+
708
+ Use `config.importMarks` for additional HTML mark definitions (type, tagName, parseTags and optional readAttributes), and `config.marks` for HTML export converters. Register matching Headless Editor plugins and Content Editor renderer components to display application-defined content; import configuration alone does not add an editable block component. Custom parser/renderer/converter code is application-owned.
709
+
710
+ ## Third-party exporter checklist
711
+
712
+ 1. Emit `{version:1,blocks:[...]}`, UTF-8 JSON, with non-empty globally unique block IDs.
713
+ 2. Serialize text as text runs with an explicit marks array. Use actual newline characters; do not escape HTML into text fields.
714
+ 3. Put block settings/properties inside attrs, nested blocks inside toggle.content.blocks or grid.content.cells[].blocks, list descendants inside item.children, and table text inside attrs.rows.
715
+ 4. Include all required media fields, including empty strings/arrays if unfilled, and attachment byte count/MIME type. Use persistent URLs for production assets. Runtime uploadFn callbacks do not belong in JSON.
716
+ 5. Validate against document.schema.json, then use contentEditorFromJson for semantic ID, URL and limit checks before storing/importing.
717
+ 6. Use native JSON for exact re-import. Treat HTML as an interoperable display/import representation with the documented metadata limitations.