@ngstarter-ui/components 22.2.2 → 22.2.4
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/ai/component-registry.json +37 -0
- package/content-editor/BLOCK_FORMAT.md +861 -0
- package/content-editor/document.schema.json +1598 -0
- package/fesm2022/ngstarter-ui-components-content-editor-attachment-block-rzZKJ2JH.mjs +35 -0
- package/fesm2022/ngstarter-ui-components-content-editor-attachment-block-rzZKJ2JH.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-callout-block-Cnga7Z-6.mjs → ngstarter-ui-components-content-editor-callout-block-DTdApN0r.mjs} +2 -3
- package/fesm2022/{ngstarter-ui-components-content-editor-callout-block-Cnga7Z-6.mjs.map → ngstarter-ui-components-content-editor-callout-block-DTdApN0r.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-code-block.component-DSdVOJtH.mjs → ngstarter-ui-components-content-editor-code-block.component-DpONkTMU.mjs} +2 -2
- package/fesm2022/{ngstarter-ui-components-content-editor-code-block.component-DSdVOJtH.mjs.map → ngstarter-ui-components-content-editor-code-block.component-DpONkTMU.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-embed-block-DhFxtMQS.mjs → ngstarter-ui-components-content-editor-embed-block-CmhzpaRk.mjs} +2 -2
- package/fesm2022/{ngstarter-ui-components-content-editor-embed-block-DhFxtMQS.mjs.map → ngstarter-ui-components-content-editor-embed-block-CmhzpaRk.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-gallery-block-cEy-dCMa.mjs → ngstarter-ui-components-content-editor-gallery-block-gtH7yWd5.mjs} +16 -39
- package/fesm2022/ngstarter-ui-components-content-editor-gallery-block-gtH7yWd5.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-grid-block-DFLGRFiO.mjs → ngstarter-ui-components-content-editor-grid-block-Pb-xV7Pw.mjs} +3 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-grid-block-DFLGRFiO.mjs.map → ngstarter-ui-components-content-editor-grid-block-Pb-xV7Pw.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-heading-block.component-BYpctSPe.mjs → ngstarter-ui-components-content-editor-heading-block.component-BKe9Zy_x.mjs} +2 -2
- package/fesm2022/{ngstarter-ui-components-content-editor-heading-block.component-BYpctSPe.mjs.map → ngstarter-ui-components-content-editor-heading-block.component-BKe9Zy_x.mjs.map} +1 -1
- package/fesm2022/ngstarter-ui-components-content-editor-image-block.component-DSpBVTu-.mjs +113 -0
- package/fesm2022/ngstarter-ui-components-content-editor-image-block.component-DSpBVTu-.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-list-block.component-6SMBxIl4.mjs → ngstarter-ui-components-content-editor-list-block.component-BPKPE1uY.mjs} +2 -2
- package/fesm2022/{ngstarter-ui-components-content-editor-list-block.component-6SMBxIl4.mjs.map → ngstarter-ui-components-content-editor-list-block.component-BPKPE1uY.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-nested-blocks-DSY7xfzf.mjs → ngstarter-ui-components-content-editor-nested-blocks-Dh-p3WMp.mjs} +4 -4
- package/fesm2022/ngstarter-ui-components-content-editor-nested-blocks-Dh-p3WMp.mjs.map +1 -0
- 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-CR-NrarE.mjs} +2058 -983
- package/fesm2022/ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-CR-NrarE.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-paragraph-block.component-JVxf_Cdx.mjs → ngstarter-ui-components-content-editor-paragraph-block.component-D5wS3m6O.mjs} +2 -2
- package/fesm2022/{ngstarter-ui-components-content-editor-paragraph-block.component-JVxf_Cdx.mjs.map → ngstarter-ui-components-content-editor-paragraph-block.component-D5wS3m6O.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-quote-block.component-7EO7z7Sr.mjs → ngstarter-ui-components-content-editor-quote-block.component-C3GFAGKF.mjs} +2 -2
- package/fesm2022/{ngstarter-ui-components-content-editor-quote-block.component-7EO7z7Sr.mjs.map → ngstarter-ui-components-content-editor-quote-block.component-C3GFAGKF.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-table-block.component-CJS-IBHw.mjs → ngstarter-ui-components-content-editor-table-block.component-DQgs_kyN.mjs} +2 -2
- package/fesm2022/{ngstarter-ui-components-content-editor-table-block.component-CJS-IBHw.mjs.map → ngstarter-ui-components-content-editor-table-block.component-DQgs_kyN.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-toggle-block-B01lhY_V.mjs → ngstarter-ui-components-content-editor-toggle-block-Cb67ChE8.mjs} +3 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-toggle-block-B01lhY_V.mjs.map → ngstarter-ui-components-content-editor-toggle-block-Cb67ChE8.mjs.map} +1 -1
- package/fesm2022/ngstarter-ui-components-content-editor-upload-status-QnKI_Rfz.mjs +19 -0
- package/fesm2022/ngstarter-ui-components-content-editor-upload-status-QnKI_Rfz.mjs.map +1 -0
- package/fesm2022/ngstarter-ui-components-content-editor-video-block.component-CRa0g9Ez.mjs +134 -0
- package/fesm2022/ngstarter-ui-components-content-editor-video-block.component-CRa0g9Ez.mjs.map +1 -0
- package/fesm2022/ngstarter-ui-components-content-editor.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-headless-editor.mjs +57 -0
- package/fesm2022/ngstarter-ui-components-headless-editor.mjs.map +1 -1
- package/package.json +3 -1
- package/types/ngstarter-ui-components-content-editor.d.ts +302 -18
- package/types/ngstarter-ui-components-headless-editor.d.ts +6 -1
- package/fesm2022/ngstarter-ui-components-content-editor-attachment-block-B2GUlWO2.mjs +0 -54
- package/fesm2022/ngstarter-ui-components-content-editor-attachment-block-B2GUlWO2.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-block-base-BHAxKEOT.mjs +0 -47
- package/fesm2022/ngstarter-ui-components-content-editor-block-base-BHAxKEOT.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-gallery-block-cEy-dCMa.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-image-block.component-B3MnANpi.mjs +0 -169
- package/fesm2022/ngstarter-ui-components-content-editor-image-block.component-B3MnANpi.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-nested-blocks-DSY7xfzf.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor--rb3-UuO.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-upload-block-base-D9ELpJr-.mjs +0 -29
- package/fesm2022/ngstarter-ui-components-content-editor-upload-block-base-D9ELpJr-.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-video-block.component-DQUPVDwV.mjs +0 -201
- package/fesm2022/ngstarter-ui-components-content-editor-video-block.component-DQUPVDwV.mjs.map +0 -1
|
@@ -0,0 +1,861 @@
|
|
|
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.
|
|
718
|
+
|
|
719
|
+
## Editing, insertion and application-defined blocks
|
|
720
|
+
|
|
721
|
+
Builder import defaults to replacement. Insert mode copies the entire imported tree with fresh
|
|
722
|
+
block, grid-cell and gallery-image IDs, leaving the source object untouched. A destination is a
|
|
723
|
+
root collection, Toggle body, or Grid cell. Capture the destination before opening an overlay:
|
|
724
|
+
|
|
725
|
+
```ts
|
|
726
|
+
const target = builder.getInsertionTarget();
|
|
727
|
+
// Root: { scope: {}, afterId: 'paragraph-id' }
|
|
728
|
+
// Toggle: { scope: { parentId: 'toggle-id' }, afterId: 'child-id' }
|
|
729
|
+
// Grid: { scope: { parentId: 'grid-id', cellId: 'cell-id' }, afterId: 'child-id' }
|
|
730
|
+
builder.importHtml(html, {}, { mode: 'insert', target });
|
|
731
|
+
builder.importJson(json, {}, { mode: 'insert', target });
|
|
732
|
+
// Omit afterId to append to the collection; omit target to use the active destination.
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
The destination must still exist when importing. An invalid parent, cell, or `afterId` raises
|
|
736
|
+
`ContentEditorImportError` without changing the document. Import remains one Undo/Redo operation.
|
|
737
|
+
Paste uses the same HTML importer and configuration. Paragraph/Heading fields split around the current selection when pasting structured blocks, retaining lists/tables and surrounding marked text. Other inline text fields flatten supported HTML structure to text lines while retaining supported marks; code fields retain literal text.
|
|
738
|
+
|
|
739
|
+
`builder.convertBlock(id, type, settings?)` converts `paragraph`, `heading`, `quote` and `callout`,
|
|
740
|
+
including nested blocks. It retains ID, rich text, custom attrs and alignment. Quote attribution
|
|
741
|
+
becomes a final text line when converting to another type. Unsupported source types return `false`.
|
|
742
|
+
Use the block action menu's **Turn into** action. The heading default is level 2; callout defaults
|
|
743
|
+
to `note`. Conversion is a single history operation and restores the active text range.
|
|
744
|
+
|
|
745
|
+
### A single block registration
|
|
746
|
+
|
|
747
|
+
Each `ContentEditorConfig.blocks[type]` entry may define all block behaviour:
|
|
748
|
+
|
|
749
|
+
| Field | Contract |
|
|
750
|
+
| --- | --- |
|
|
751
|
+
| `editor` | Standalone Angular component with the standard editor inputs. |
|
|
752
|
+
| `loadEditor` | `() => Promise<Type<unknown>>`; takes precedence over `editor`. |
|
|
753
|
+
| `renderer` | Standalone preview component with the standard renderer inputs. |
|
|
754
|
+
| `create` | `() => { content, attrs? }`; the builder supplies the new ID and type. |
|
|
755
|
+
| `menu` | `{ title, description?, iconName?, settings? }`; registers a global menu item. |
|
|
756
|
+
| `options` | Runtime editor options, including upload callbacks and maximum file size. |
|
|
757
|
+
| `toHtml` | HTML converter; use `ctx.escape()` and `ctx.safeUrl()` for dynamic values. |
|
|
758
|
+
| `fromHtml` | `{ selector, parse(element, context) }` importer. |
|
|
759
|
+
| `validateImport` | Return an error string to reject imported block data; otherwise return `undefined`. |
|
|
760
|
+
|
|
761
|
+
Provide the configuration globally with `provideContentEditorConfig(config)` or pass `[config]`
|
|
762
|
+
to a builder/renderer. Nested editing uses the root builder's definitions. Nested preview renderers
|
|
763
|
+
inherit instance configuration, so a custom block inside Grid/Toggle needs no additional provider.
|
|
764
|
+
Environment defaults are merged first, then instance overrides; block fields and options merge
|
|
765
|
+
individually. Legacy renderer providers remain supported; `blocks[type].renderer` takes precedence.
|
|
766
|
+
|
|
767
|
+
```ts
|
|
768
|
+
import { ContentEditorConfig, provideContentEditorConfig }
|
|
769
|
+
from '@ngstarter-ui/components/content-editor';
|
|
770
|
+
|
|
771
|
+
const config: ContentEditorConfig = {
|
|
772
|
+
blocks: {
|
|
773
|
+
product: {
|
|
774
|
+
editor: ProductEditor,
|
|
775
|
+
renderer: ProductPreview,
|
|
776
|
+
create: () => ({ content: { productId: '' } }),
|
|
777
|
+
menu: { title: 'Product', description: 'A product card' },
|
|
778
|
+
validateImport: block =>
|
|
779
|
+
typeof (block.content as { productId?: unknown })?.productId === 'string'
|
|
780
|
+
? undefined : 'productId must be a string',
|
|
781
|
+
fromHtml: {
|
|
782
|
+
selector: '[data-product-id]',
|
|
783
|
+
parse: (element, ctx) => ctx.createBlock('product', {
|
|
784
|
+
productId: element.getAttribute('data-product-id') ?? ''
|
|
785
|
+
})
|
|
786
|
+
},
|
|
787
|
+
toHtml: (block, ctx) =>
|
|
788
|
+
`<div data-product-id="${ctx.escape((block.content as { productId: string }).productId)}"></div>`
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
// Application/route providers: [provideContentEditorConfig(config)]
|
|
793
|
+
// Or: <ngs-content-editor-builder [config]="config" ... />
|
|
794
|
+
// And: <ngs-content-editor-renderer [config]="config" ... />
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
`ContentEditorBlockBase<TContent, TSettings>` supplies `id`, `content`, `settings`, `props`, `index`,
|
|
798
|
+
`initialized`, focus and history integration. Extend it in an editor and call protected
|
|
799
|
+
`save(nextContent, nextSettings?)`. `latestContent()` reads the current native value for edits that
|
|
800
|
+
may race with another field. `ContentEditorRendererBase<TContent, TSettings>` supplies preview
|
|
801
|
+
inputs, including the native `block`. Import both through the public `content-editor` entry point.
|
|
802
|
+
The docs builder includes a working Bookmark registration using these APIs.
|
|
803
|
+
|
|
804
|
+
A custom block entry explicitly permits its type during JSON import, and its `validateImport`
|
|
805
|
+
checks its content. Extend the supplied built-in JSON Schema with your own block shape when external
|
|
806
|
+
systems also validate custom documents. Unknown types without an explicit entry are rejected by
|
|
807
|
+
default. Runtime components/callbacks never belong in the saved JSON.
|
|
808
|
+
|
|
809
|
+
## Media upload contract
|
|
810
|
+
|
|
811
|
+
Image, Video, Gallery and Attachment share progress, cancellation, visible errors and retry.
|
|
812
|
+
Configure `options.uploadFn` and optionally `options.maxFileSize` (bytes) in their block entry:
|
|
813
|
+
|
|
814
|
+
```ts
|
|
815
|
+
import { ContentEditorUploadFn } from '@ngstarter-ui/components/content-editor';
|
|
816
|
+
|
|
817
|
+
const uploadFn: ContentEditorUploadFn = async (file, dataUrl, context) => {
|
|
818
|
+
const form = new FormData();
|
|
819
|
+
form.append('file', file);
|
|
820
|
+
const response = await fetch('/api/uploads', { method: 'POST', body: form, signal: context.signal });
|
|
821
|
+
if (!response.ok) throw new Error('Upload failed');
|
|
822
|
+
const result = await response.json() as { url: string };
|
|
823
|
+
return result.url;
|
|
824
|
+
};
|
|
825
|
+
// For a transport supporting progress, call context.onProgress(percent), from 0 to 100.
|
|
826
|
+
// Existing callbacks taking (file, dataUrl) continue to work.
|
|
827
|
+
provideContentEditorConfig({ blocks: { image: { options: { uploadFn, maxFileSize: 10 * 1024 * 1024 } } } });
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
Cancellation aborts file reading and signals the transport. Late results never update a cancelled,
|
|
831
|
+
removed, replaced or read-only block. Consumers must pass `context.signal` to their transport to
|
|
832
|
+
stop its network request. Gallery keeps successful files and retry resends only failed files.
|
|
833
|
+
MIME/size rejection requires choosing another file and is not automatically retried.
|
|
834
|
+
Without transport progress the indicator is indeterminate. A successful upload returns a supported
|
|
835
|
+
resource URL; callbacks must reject on failure. Default callbacks use data URLs.
|
|
836
|
+
|
|
837
|
+
## Draft persistence
|
|
838
|
+
|
|
839
|
+
Use a stable document ID for multiple editors or multiple documents on the same route:
|
|
840
|
+
|
|
841
|
+
```html
|
|
842
|
+
<ngs-content-editor-builder documentId="article-42" [content]="document"
|
|
843
|
+
[persistDraft]="true" [draftDebounceMs]="500" />
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
`persistDraft` defaults to true. Saves are delayed by 500ms by default and flushed on component
|
|
847
|
+
destruction or document switch. `documentId` identifies the storage entry; when omitted, the
|
|
848
|
+
existing route + element-ID storage key remains in use. Provide distinct IDs for independent editors.
|
|
849
|
+
Drafts are validated with the same JSON importer and custom configuration before restoration.
|
|
850
|
+
Malformed data falls back to the supplied document and exposes the error; it is not silently removed.
|
|
851
|
+
|
|
852
|
+
The builder exposes `draftStatus` (`disabled`, `idle`, `saving`, `saved`, `error`), `draftError`,
|
|
853
|
+
`draftSavedAt`, `saveDraftNow()` and `clearDraft()`. Status signals can drive an `aria-live` indicator
|
|
854
|
+
and a retry action. `clearDraft()` removes persisted state without altering the current document.
|
|
855
|
+
Storage/quota failures remain visible. No draft storage runs during SSR.
|
|
856
|
+
|
|
857
|
+
Environment or instance config can set `draft.debounceMs` and `draft.storage`. A storage adapter
|
|
858
|
+
implements synchronous `getItem(key): string | null`, `setItem(key, value): void`, and
|
|
859
|
+
`removeItem(key): void`; it stores serialized native JSON. The default is browser `localStorage`.
|
|
860
|
+
`[draftDebounceMs]` overrides the configured delay. Use `contentChanged` for asynchronous server
|
|
861
|
+
persistence.
|