@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
@@ -5,7 +5,7 @@ import { Icon } from '@ngstarter-ui/components/icon';
5
5
  import { Menu, MenuItem, MenuTrigger, MenuHeading, MenuContent } from '@ngstarter-ui/components/menu';
6
6
  import { DialogRef, DialogContent, DialogTitle, DialogActions, DIALOG_DATA, Dialog } from '@ngstarter-ui/components/dialog';
7
7
  import * as i1 from '@ngstarter-ui/components/headless-editor';
8
- import { isNgsHeadlessEditorTextContent, getNgsHeadlessEditorTableData, NgsHeadlessEditor, NgsHeadlessEditorInlineRegion, NgsHeadlessEditorSurface, createNgsHeadlessEditorId, provideNgsHeadlessEditorInlineRegion, NGS_HEADLESS_EDITOR_TOGGLE_BOLD, NGS_HEADLESS_EDITOR_TOGGLE_ITALIC, NGS_HEADLESS_EDITOR_TOGGLE_CODE, NGS_HEADLESS_EDITOR_TOGGLE_STRIKE, NGS_HEADLESS_EDITOR_TOGGLE_UNDERLINE, NGS_HEADLESS_EDITOR_TOGGLE_SUPERSCRIPT, NGS_HEADLESS_EDITOR_TOGGLE_SUBSCRIPT, NGS_HEADLESS_EDITOR_SET_LINK, NGS_HEADLESS_EDITOR_UNSET_LINK, NGS_HEADLESS_EDITOR_SET_TEXT_COLOR, NGS_HEADLESS_EDITOR_UNSET_TEXT_COLOR, NGS_HEADLESS_EDITOR_SET_BACKGROUND_COLOR, NGS_HEADLESS_EDITOR_UNSET_BACKGROUND_COLOR, provideNgsHeadlessEditor, withHeadlessEditorPlugin, basicTextEditorPlugin, colorEditorPlugin, linkEditorPlugin, createNgsHeadlessEditorText, normalizeNgsHeadlessEditorLink, normalizeNgsHeadlessEditorColor, createNgsHeadlessEditorDocument, readNgsHeadlessEditorInlineContent, NgsHeadlessEditorRuns } from '@ngstarter-ui/components/headless-editor';
8
+ import { isNgsHeadlessEditorTextContent, getNgsHeadlessEditorTableData, NgsHeadlessEditor, NgsHeadlessEditorInlineRegion, NgsHeadlessEditorSurface, createNgsHeadlessEditorId, provideNgsHeadlessEditorInlineRegion, NGS_HEADLESS_EDITOR_TOGGLE_BOLD, NGS_HEADLESS_EDITOR_TOGGLE_ITALIC, NGS_HEADLESS_EDITOR_TOGGLE_CODE, NGS_HEADLESS_EDITOR_TOGGLE_STRIKE, NGS_HEADLESS_EDITOR_TOGGLE_UNDERLINE, NGS_HEADLESS_EDITOR_TOGGLE_SUPERSCRIPT, NGS_HEADLESS_EDITOR_TOGGLE_SUBSCRIPT, NGS_HEADLESS_EDITOR_SET_LINK, NGS_HEADLESS_EDITOR_UNSET_LINK, NGS_HEADLESS_EDITOR_SET_TEXT_COLOR, NGS_HEADLESS_EDITOR_UNSET_TEXT_COLOR, NGS_HEADLESS_EDITOR_SET_BACKGROUND_COLOR, NGS_HEADLESS_EDITOR_UNSET_BACKGROUND_COLOR, provideNgsHeadlessEditor, withHeadlessEditorPlugin, basicTextEditorPlugin, colorEditorPlugin, linkEditorPlugin, createNgsHeadlessEditorText, normalizeNgsHeadlessEditorLink, normalizeNgsHeadlessEditorColor, normalizeNgsHeadlessEditorTextContent, createNgsHeadlessEditorDocument, readNgsHeadlessEditorInlineContent, NgsHeadlessEditorRuns } from '@ngstarter-ui/components/headless-editor';
9
9
  import { DOCUMENT, isPlatformBrowser, isPlatformServer, NgComponentOutlet, AsyncPipe, NgTemplateOutlet } from '@angular/common';
10
10
  import { Input } from '@ngstarter-ui/components/input';
11
11
  import { FormField, Label, Hint } from '@ngstarter-ui/components/form-field';
@@ -856,25 +856,25 @@ const CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS = {
856
856
 
857
857
  const CONTENT_EDITOR_EXTRA_BLOCK_DEFS = [
858
858
  {
859
- type: 'callout', component: () => import('./ngstarter-ui-components-content-editor-callout-block-Cnga7Z-6.mjs').then(m => m.ContentEditorCalloutBlock),
859
+ type: 'callout', component: () => import('./ngstarter-ui-components-content-editor-callout-block-Jbf8h2yz.mjs').then(m => m.ContentEditorCalloutBlock),
860
860
  empty: () => ({ content: [createNgsHeadlessEditorText()], settings: { variant: 'note' } }), options: {}
861
861
  },
862
862
  {
863
- type: 'toggle', component: () => import('./ngstarter-ui-components-content-editor-toggle-block-B01lhY_V.mjs').then(m => m.ContentEditorToggleBlock),
863
+ type: 'toggle', component: () => import('./ngstarter-ui-components-content-editor-toggle-block-B46YeMGQ.mjs').then(m => m.ContentEditorToggleBlock),
864
864
  empty: () => ({ content: { title: [], blocks: [emptyParagraph()] }, settings: { expanded: true } }), options: {}
865
865
  },
866
866
  {
867
- type: 'attachment', component: () => import('./ngstarter-ui-components-content-editor-attachment-block-B2GUlWO2.mjs').then(m => m.ContentEditorAttachmentBlock),
867
+ type: 'attachment', component: () => import('./ngstarter-ui-components-content-editor-attachment-block-DlUkhwCu.mjs').then(m => m.ContentEditorAttachmentBlock),
868
868
  empty: () => ({ content: { url: '', name: '', size: 0, mimeType: '' }, settings: {} }),
869
869
  options: { uploadFn: (_file, dataUrl) => Promise.resolve(dataUrl) }
870
870
  },
871
871
  {
872
- type: 'gallery', component: () => import('./ngstarter-ui-components-content-editor-gallery-block-cEy-dCMa.mjs').then(m => m.ContentEditorGalleryBlock),
872
+ type: 'gallery', component: () => import('./ngstarter-ui-components-content-editor-gallery-block-C4p-S0Do.mjs').then(m => m.ContentEditorGalleryBlock),
873
873
  empty: () => ({ content: { images: [] }, settings: {} }),
874
874
  options: { uploadFn: (_file, dataUrl) => Promise.resolve(dataUrl) }
875
875
  },
876
876
  {
877
- type: 'grid', component: () => import('./ngstarter-ui-components-content-editor-grid-block-DFLGRFiO.mjs').then(m => m.ContentEditorGridBlock),
877
+ type: 'grid', component: () => import('./ngstarter-ui-components-content-editor-grid-block-Cdq_Dcv2.mjs').then(m => m.ContentEditorGridBlock),
878
878
  empty: () => ({ content: { cells: Array.from({ length: 4 }, emptyGridCell) }, settings: { columns: 2, gap: 'medium', stackOnMobile: true } }), options: {}
879
879
  }
880
880
  ].map(def => ({ ...def, toHtml: CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS[def.type] }));
@@ -999,6 +999,541 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
999
999
  args: [{ providedIn: 'root' }]
1000
1000
  }] });
1001
1001
 
1002
+ /** Structured failure. The editor is never modified when parsing fails. */
1003
+ class ContentEditorImportError extends Error {
1004
+ path;
1005
+ constructor(path, message) {
1006
+ super(`${path}: ${message}`);
1007
+ this.path = path;
1008
+ this.name = 'ContentEditorImportError';
1009
+ }
1010
+ }
1011
+
1012
+ /** Parses and validates the native version-1 format without changing the caller's objects. */
1013
+ function contentEditorFromJson(source, config = {}, options = {}) {
1014
+ const maxDepth = options.maxDepth ?? 64;
1015
+ const maxBlocks = options.maxBlocks ?? 10000;
1016
+ if (!Number.isInteger(maxDepth) || maxDepth < 1 || !Number.isInteger(maxBlocks) || maxBlocks < 1) {
1017
+ throw new ContentEditorImportError('$options', 'maxDepth and maxBlocks must be positive integers');
1018
+ }
1019
+ let value = source;
1020
+ if (typeof source === 'string') {
1021
+ try {
1022
+ value = JSON.parse(source);
1023
+ }
1024
+ catch {
1025
+ throw new ContentEditorImportError('$', 'Invalid JSON');
1026
+ }
1027
+ }
1028
+ const fail = (path, message) => { throw new ContentEditorImportError(path, message); };
1029
+ const ancestors = new Set();
1030
+ const copy = (input, path, depth) => {
1031
+ if (depth > maxDepth)
1032
+ fail(path, `Maximum nesting depth (${maxDepth}) exceeded`);
1033
+ if (input === null || typeof input === 'string' || typeof input === 'boolean')
1034
+ return input;
1035
+ if (typeof input === 'number' && Number.isFinite(input))
1036
+ return input;
1037
+ if (!input || typeof input !== 'object')
1038
+ return fail(path, 'Expected a JSON-compatible value');
1039
+ if (ancestors.has(input))
1040
+ fail(path, 'Cyclic data is not supported');
1041
+ if (!Array.isArray(input) && ![Object.prototype, null].includes(Object.getPrototypeOf(input)))
1042
+ fail(path, 'Expected a plain JSON object');
1043
+ ancestors.add(input);
1044
+ const output = Array.isArray(input)
1045
+ ? Array.from(input, (item, i) => copy(item, `${path}[${i}]`, depth + 1))
1046
+ : Object.fromEntries(Object.entries(input).filter(([, item]) => item !== undefined).map(([key, item]) => [key, copy(item, `${path}.${key}`, depth + 1)]));
1047
+ ancestors.delete(input);
1048
+ return output;
1049
+ };
1050
+ const object = (input, path) => {
1051
+ if (input === null || typeof input !== 'object' || Array.isArray(input))
1052
+ fail(path, 'Expected an object');
1053
+ return input;
1054
+ };
1055
+ const array = (input, path) => { if (!Array.isArray(input))
1056
+ fail(path, 'Expected an array'); return input; };
1057
+ const string = (input, path, nonempty = false) => {
1058
+ if (typeof input !== 'string' || (nonempty && !input.trim()))
1059
+ fail(path, nonempty ? 'Expected a non-empty string' : 'Expected a string');
1060
+ };
1061
+ const props = (input, path) => {
1062
+ if (input === undefined)
1063
+ return;
1064
+ array(input, path).forEach((prop, i) => {
1065
+ object(prop, `${path}[${i}]`);
1066
+ string(prop.name, `${path}[${i}].name`, true);
1067
+ string(prop.value, `${path}[${i}].value`);
1068
+ });
1069
+ };
1070
+ const runs = (input, path) => {
1071
+ array(input, path).forEach((run, i) => {
1072
+ const p = `${path}[${i}]`;
1073
+ object(run, p);
1074
+ if (run.type !== 'text')
1075
+ fail(`${p}.type`, 'Expected "text"');
1076
+ string(run.text, `${p}.text`);
1077
+ array(run.marks, `${p}.marks`).forEach((mark, j) => {
1078
+ const m = `${p}.marks[${j}]`;
1079
+ object(mark, m);
1080
+ string(mark.type, `${m}.type`, true);
1081
+ if (mark.attrs !== undefined) {
1082
+ for (const [key, attr] of Object.entries(object(mark.attrs, `${m}.attrs`))) {
1083
+ if (attr !== null && !['string', 'number', 'boolean'].includes(typeof attr))
1084
+ fail(`${m}.attrs.${key}`, 'Expected a scalar mark attribute');
1085
+ }
1086
+ }
1087
+ if (mark.type === 'link' && !safeContentEditorHtmlUrl(mark.attrs?.href))
1088
+ fail(`${m}.attrs.href`, 'Expected a supported non-empty link URL');
1089
+ if (mark.type === 'link')
1090
+ enumValue(mark.attrs?.target, ['_blank', '_self'], `${m}.attrs.target`);
1091
+ if (['textColor', 'backgroundColor'].includes(mark.type) && (typeof mark.attrs?.color !== 'string' || !normalizeNgsHeadlessEditorColor(mark.attrs.color)))
1092
+ fail(`${m}.attrs.color`, 'Expected a supported CSS color');
1093
+ });
1094
+ });
1095
+ };
1096
+ const enumValue = (input, allowed, path) => {
1097
+ if (input !== undefined && !allowed.includes(input))
1098
+ fail(path, `Expected one of: ${allowed.join(', ')}`);
1099
+ };
1100
+ const dimension = (input, path) => {
1101
+ if (input !== undefined && input !== null && input !== 'auto' && !(typeof input === 'number' && Number.isFinite(input) && input > 0))
1102
+ fail(path, 'Expected a positive pixel dimension, "auto", or null');
1103
+ };
1104
+ const usedIds = new Set();
1105
+ let count = 0;
1106
+ const list = (input, path) => {
1107
+ array(input, path).forEach((item, i) => {
1108
+ const p = `${path}[${i}]`;
1109
+ object(item, p);
1110
+ runs(item.content, `${p}.content`);
1111
+ props(item.props, `${p}.props`);
1112
+ list(item.children, `${p}.children`);
1113
+ });
1114
+ };
1115
+ const blocks = (input, path) => {
1116
+ array(input, path).forEach((block, i) => {
1117
+ const p = `${path}[${i}]`;
1118
+ object(block, p);
1119
+ if (++count > maxBlocks)
1120
+ fail(p, `Maximum block count (${maxBlocks}) exceeded`);
1121
+ string(block.id, `${p}.id`, true);
1122
+ string(block.type, `${p}.type`, true);
1123
+ if (usedIds.has(block.id))
1124
+ fail(`${p}.id`, `Duplicate block ID "${block.id}"`);
1125
+ usedIds.add(block.id);
1126
+ if (!Object.hasOwn(block, 'content'))
1127
+ fail(`${p}.content`, 'Required field');
1128
+ const attrs = block.attrs === undefined ? {} : object(block.attrs, `${p}.attrs`);
1129
+ const settings = attrs['settings'] === undefined ? {} : object(attrs['settings'], `${p}.attrs.settings`);
1130
+ props(attrs['props'], `${p}.attrs.props`);
1131
+ const c = block.content;
1132
+ const cp = `${p}.content`;
1133
+ const sp = `${p}.attrs.settings`;
1134
+ switch (block.type) {
1135
+ case 'paragraph':
1136
+ case 'heading':
1137
+ case 'code':
1138
+ case 'callout':
1139
+ runs(c, cp);
1140
+ if (block.type === 'heading')
1141
+ enumValue(settings['level'], [1, 2, 3, 4, 5, 6], `${sp}.level`);
1142
+ if (block.type === 'code' && settings['language'] !== undefined)
1143
+ string(settings['language'], `${sp}.language`);
1144
+ if (block.type === 'callout')
1145
+ enumValue(settings['variant'], ['note', 'tip', 'warning', 'danger'], `${sp}.variant`);
1146
+ break;
1147
+ case 'divider':
1148
+ if (c !== null)
1149
+ fail(cp, 'Divider content must be null');
1150
+ break;
1151
+ case 'bulletList':
1152
+ case 'orderedList':
1153
+ list(c, cp);
1154
+ enumValue(settings['listStyle'], ['bullet', 'ordered'], `${sp}.listStyle`);
1155
+ break;
1156
+ case 'quote':
1157
+ object(c, cp);
1158
+ for (const name of ['cite', 'caption']) {
1159
+ object(c[name], `${cp}.${name}`);
1160
+ runs(c[name].content, `${cp}.${name}.content`);
1161
+ props(c[name].props, `${cp}.${name}.props`);
1162
+ }
1163
+ break;
1164
+ case 'table':
1165
+ if (c !== null)
1166
+ fail(cp, 'Native table content must be null; use attrs.rows');
1167
+ if (array(attrs['rows'], `${p}.attrs.rows`).length > 500)
1168
+ fail(`${p}.attrs.rows`, 'Tables support at most 500 rows');
1169
+ attrs['rows'].forEach((row, r) => {
1170
+ if (array(row, `${p}.attrs.rows[${r}]`).length > 50)
1171
+ fail(`${p}.attrs.rows[${r}]`, 'Tables support at most 50 columns');
1172
+ row.forEach((cell, col) => runs(cell, `${p}.attrs.rows[${r}][${col}]`));
1173
+ });
1174
+ enumValue(attrs['header'], [true, false], `${p}.attrs.header`);
1175
+ if (attrs['cellMetadata'] !== undefined)
1176
+ array(attrs['cellMetadata'], `${p}.attrs.cellMetadata`).forEach((row, r) => array(row, `${p}.attrs.cellMetadata[${r}]`).forEach((cell, col) => {
1177
+ const mp = `${p}.attrs.cellMetadata[${r}][${col}]`;
1178
+ object(cell, mp);
1179
+ props(cell.props, `${mp}.props`);
1180
+ if (cell.options !== undefined) {
1181
+ const opts = object(cell.options, `${mp}.options`);
1182
+ for (const key of ['colspan', 'rowspan'])
1183
+ if (opts[key] !== undefined && !(Number.isInteger(opts[key]) && opts[key] > 0))
1184
+ fail(`${mp}.options.${key}`, 'Expected a positive integer');
1185
+ dimension(opts['width'], `${mp}.options.width`);
1186
+ }
1187
+ }));
1188
+ break;
1189
+ case 'image':
1190
+ case 'video':
1191
+ case 'embed':
1192
+ case 'attachment':
1193
+ object(c, cp);
1194
+ for (const key of block.type === 'image' ? ['src', 'alt'] : block.type === 'video' ? ['src', 'caption'] : block.type === 'embed' ? ['url', 'type'] : ['url', 'name', 'mimeType'])
1195
+ string(c[key], `${cp}.${key}`);
1196
+ {
1197
+ const key = ['image', 'video'].includes(block.type) ? 'src' : 'url';
1198
+ const kind = block.type === 'video' ? 'media' : block.type === 'image' ? 'image' : block.type === 'embed' ? 'embed' : 'attachment';
1199
+ if (c[key] && !safeContentEditorHtmlUrl(c[key], kind))
1200
+ fail(`${cp}.${key}`, 'Unsupported resource URL');
1201
+ }
1202
+ if (block.type === 'attachment' && !(Number.isInteger(c.size) && c.size >= 0))
1203
+ fail(`${cp}.size`, 'Expected a non-negative integer byte count');
1204
+ if (block.type === 'video')
1205
+ enumValue(c.orientation, ['portrait', 'landscape'], `${cp}.orientation`);
1206
+ for (const key of ['width', 'height', 'actualWidth', 'actualHeight'])
1207
+ dimension(settings[key], `${sp}.${key}`);
1208
+ break;
1209
+ case 'gallery': {
1210
+ object(c, cp);
1211
+ const ids = new Set();
1212
+ array(c.images, `${cp}.images`).forEach((image, j) => {
1213
+ const ip = `${cp}.images[${j}]`;
1214
+ object(image, ip);
1215
+ string(image.id, `${ip}.id`, true);
1216
+ if (ids.has(image.id))
1217
+ fail(`${ip}.id`, 'Duplicate image ID');
1218
+ ids.add(image.id);
1219
+ string(image.src, `${ip}.src`);
1220
+ string(image.alt, `${ip}.alt`);
1221
+ runs(image.caption, `${ip}.caption`);
1222
+ if (image.src && !safeContentEditorHtmlUrl(image.src, 'image'))
1223
+ fail(`${ip}.src`, 'Unsupported image URL');
1224
+ });
1225
+ break;
1226
+ }
1227
+ case 'toggle':
1228
+ object(c, cp);
1229
+ runs(c.title, `${cp}.title`);
1230
+ blocks(c.blocks, `${cp}.blocks`);
1231
+ enumValue(settings['expanded'], [true, false], `${sp}.expanded`);
1232
+ break;
1233
+ case 'grid': {
1234
+ object(c, cp);
1235
+ const ids = new Set();
1236
+ array(c.cells, `${cp}.cells`).forEach((cell, j) => {
1237
+ const gp = `${cp}.cells[${j}]`;
1238
+ object(cell, gp);
1239
+ string(cell.id, `${gp}.id`, true);
1240
+ if (ids.has(cell.id))
1241
+ fail(`${gp}.id`, 'Duplicate grid cell ID');
1242
+ ids.add(cell.id);
1243
+ blocks(cell.blocks, `${gp}.blocks`);
1244
+ });
1245
+ enumValue(settings['columns'], [2, 3, 4], `${sp}.columns`);
1246
+ enumValue(settings['gap'], ['small', 'medium', 'large'], `${sp}.gap`);
1247
+ enumValue(settings['stackOnMobile'], [true, false], `${sp}.stackOnMobile`);
1248
+ break;
1249
+ }
1250
+ default:
1251
+ if (!options.allowUnknownBlocks && !Object.hasOwn(config.blocks ?? {}, block.type))
1252
+ fail(`${p}.type`, `Unknown block type "${block.type}"`);
1253
+ }
1254
+ const validation = config.blocks?.[block.type]?.validateImport?.(block);
1255
+ if (validation !== undefined)
1256
+ fail(p, validation);
1257
+ });
1258
+ };
1259
+ const document = object(copy(value, '$', 0), '$');
1260
+ if (document['version'] !== 1)
1261
+ fail('$.version', 'Only document version 1 is supported');
1262
+ blocks(document['blocks'], '$.blocks');
1263
+ return { version: 1, blocks: document['blocks'] };
1264
+ }
1265
+
1266
+ const ignoredTags = new Set(['script', 'style', 'noscript', 'template', 'object', 'embed', 'head', 'meta', 'link']);
1267
+ const blockTags = new Set(['p', 'div', 'section', 'article', 'header', 'footer', 'main', 'aside', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre', 'blockquote', 'figure', 'ul', 'ol', 'table', 'details', 'hr']);
1268
+ /** Imports semantic HTML into native blocks. Scripts, event handlers and arbitrary CSS are never stored. */
1269
+ function contentEditorFromHtml(html, config = {}, options = {}) {
1270
+ if (typeof html !== 'string')
1271
+ throw new ContentEditorImportError('$html', 'Expected an HTML string');
1272
+ const owner = options.document ?? globalThis.document;
1273
+ if (!owner?.implementation?.createHTMLDocument) {
1274
+ throw new ContentEditorImportError('$html', 'HTML import requires a DOM document; supply options.document when running on the server');
1275
+ }
1276
+ const inert = owner.implementation.createHTMLDocument('');
1277
+ inert.body.innerHTML = html;
1278
+ const maxDepth = options.maxDepth ?? 64;
1279
+ const maxBlocks = options.maxBlocks ?? 10000;
1280
+ if (!Number.isInteger(maxDepth) || maxDepth < 1 || !Number.isInteger(maxBlocks) || maxBlocks < 1)
1281
+ throw new ContentEditorImportError('$options', 'maxDepth and maxBlocks must be positive integers');
1282
+ const definitions = [...new Map([...basicTextEditorPlugin().marks, ...colorEditorPlugin().marks, ...linkEditorPlugin().marks, ...(config.importMarks ?? [])].map(mark => [mark.type, mark])).values()];
1283
+ const overrides = Object.values(config.blocks ?? {}).flatMap(block => block.fromHtml ? [block.fromHtml] : []);
1284
+ let depth = 0;
1285
+ let count = 0;
1286
+ const guarded = (read) => {
1287
+ if (++depth > maxDepth)
1288
+ throw new ContentEditorImportError('$html', `Maximum nesting depth (${maxDepth}) exceeded`);
1289
+ try {
1290
+ return read();
1291
+ }
1292
+ finally {
1293
+ depth--;
1294
+ }
1295
+ };
1296
+ const tag = (element) => element.tagName.toLowerCase();
1297
+ const children = (element) => Array.from(element.children);
1298
+ const direct = (element, selector) => children(element).find(child => child.matches(selector));
1299
+ const alignment = (element) => {
1300
+ const value = element.style?.textAlign || element.getAttribute('align');
1301
+ return value && ['left', 'center', 'right', 'justify'].includes(value) ? [{ name: 'text-alignment', value }] : [];
1302
+ };
1303
+ const dimension = (element, name) => {
1304
+ const raw = element.getAttribute(name);
1305
+ if (!raw || !/^\d+(?:\.\d+)?$/.test(raw))
1306
+ return null;
1307
+ const value = Number(raw);
1308
+ return value > 0 && Number.isFinite(value) ? value : null;
1309
+ };
1310
+ const createBlock = (type, content, attrs) => {
1311
+ if (++count > maxBlocks)
1312
+ throw new ContentEditorImportError('$html', `Maximum block count (${maxBlocks}) exceeded`);
1313
+ return { id: createNgsHeadlessEditorId(type), type, content, ...(attrs ? { attrs } : {}) };
1314
+ };
1315
+ const parseText = (element) => {
1316
+ const runs = [];
1317
+ const newline = () => { if (runs.length && !runs.at(-1).text.endsWith('\n'))
1318
+ runs.push(createNgsHeadlessEditorText('\n')); };
1319
+ const visit = (node, marks) => guarded(() => {
1320
+ if (node.nodeType === 3) {
1321
+ const text = (node.textContent ?? '').replace(/[\t\r\n ]+/g, ' ');
1322
+ if (text)
1323
+ runs.push(createNgsHeadlessEditorText(text, marks));
1324
+ return;
1325
+ }
1326
+ if (node.nodeType !== 1)
1327
+ return;
1328
+ const el = node;
1329
+ const name = tag(el);
1330
+ if (ignoredTags.has(name) || ['iframe', 'img', 'video', 'audio', 'ul', 'ol'].includes(name))
1331
+ return;
1332
+ if (name === 'br') {
1333
+ runs.push(createNgsHeadlessEditorText('\n', marks));
1334
+ return;
1335
+ }
1336
+ const next = [...marks];
1337
+ for (const definition of definitions) {
1338
+ const explicit = el.getAttribute('data-ngs-headless-editor-mark');
1339
+ const styleMark = ['textColor', 'backgroundColor'].includes(definition.type) && !!el.style;
1340
+ if (explicit ? explicit !== definition.type : name !== definition.tagName && !definition.parseTags?.includes(name) && !styleMark)
1341
+ continue;
1342
+ const attrs = definition.readAttributes?.(el);
1343
+ if (!definition.readAttributes || attrs)
1344
+ next.push({ type: definition.type, ...(attrs ? { attrs } : {}) });
1345
+ }
1346
+ // Common HTML produced by external WYSIWYG editors also expresses marks as inline styles.
1347
+ const css = el.style;
1348
+ if (css?.fontWeight === 'bold' || Number(css?.fontWeight) >= 600)
1349
+ next.push({ type: 'bold' });
1350
+ if (css?.fontStyle === 'italic')
1351
+ next.push({ type: 'italic' });
1352
+ if (css?.textDecoration.includes('underline'))
1353
+ next.push({ type: 'underline' });
1354
+ if (css?.textDecoration.includes('line-through'))
1355
+ next.push({ type: 'strike' });
1356
+ if (blockTags.has(name))
1357
+ newline();
1358
+ Array.from(node.childNodes).forEach(child => visit(child, next));
1359
+ if (blockTags.has(name))
1360
+ newline();
1361
+ });
1362
+ visit(element, []);
1363
+ while (runs.length && !runs[0].text.trim())
1364
+ runs.shift();
1365
+ while (runs.length && !runs.at(-1).text.trim())
1366
+ runs.pop();
1367
+ if (runs.length) {
1368
+ runs[0] = { ...runs[0], text: runs[0].text.replace(/^\s+/, '') };
1369
+ const last = runs.length - 1;
1370
+ runs[last] = { ...runs[last], text: runs[last].text.replace(/\s+$/, '') };
1371
+ }
1372
+ return [...normalizeNgsHeadlessEditorTextContent(runs)];
1373
+ };
1374
+ const listItems = (element) => guarded(() => children(element).filter(el => tag(el) === 'li').map(li => {
1375
+ const text = li.cloneNode(true);
1376
+ children(text).filter(el => ['ul', 'ol'].includes(tag(el))).forEach(el => el.remove());
1377
+ return { content: parseText(text), props: alignment(li), children: children(li).filter(el => ['ul', 'ol'].includes(tag(el))).flatMap(listItems) };
1378
+ }));
1379
+ const media = (element, figure) => {
1380
+ const name = tag(element);
1381
+ const kind = name === 'img' ? 'image' : name === 'video' ? 'media' : 'embed';
1382
+ const src = safeContentEditorHtmlUrl(element.getAttribute('src') || element.querySelector('source')?.getAttribute('src'), kind);
1383
+ if (!src)
1384
+ return [];
1385
+ const caption = figure ? direct(figure, 'figcaption') : undefined;
1386
+ const settings = Object.fromEntries(['width', 'height'].flatMap(key => { const n = dimension(element, key); return n ? [[key, n]] : []; }));
1387
+ const content = name === 'img' ? { src, alt: element.getAttribute('alt') ?? '' }
1388
+ : name === 'video' ? { src, caption: caption?.textContent ?? '', orientation: 'landscape' }
1389
+ : { url: src, type: element.getAttribute('title') ?? '' };
1390
+ return [createBlock(name === 'img' ? 'image' : name === 'video' ? 'video' : 'embed', content, { settings })];
1391
+ };
1392
+ const builtin = (element) => {
1393
+ const name = tag(element);
1394
+ const attrs = { props: alignment(element) };
1395
+ if (ignoredTags.has(name))
1396
+ return [];
1397
+ if (element.matches('[data-content-editor="gallery"], .ngs-content-editor-html-gallery')) {
1398
+ const images = children(element).flatMap(figure => {
1399
+ const image = tag(figure) === 'img' ? figure : direct(figure, 'img');
1400
+ const src = safeContentEditorHtmlUrl(image?.getAttribute('src'), 'image');
1401
+ if (!image || !src)
1402
+ return [];
1403
+ const caption = direct(figure, 'figcaption');
1404
+ return [{ id: createNgsHeadlessEditorId('image'), src, alt: image.getAttribute('alt') ?? '', caption: caption ? parseText(caption) : [] }];
1405
+ });
1406
+ return [createBlock('gallery', { images })];
1407
+ }
1408
+ if (element.matches('.ngs-content-editor-html-grid')) {
1409
+ const container = direct(element, '.ngs-content-editor-html-grid-cells') ?? element;
1410
+ const css = element.style;
1411
+ const columnValue = Number(element.getAttribute('data-columns') || css?.getPropertyValue('--ngs-html-grid-columns'));
1412
+ const gapValue = css?.getPropertyValue('--ngs-html-grid-gap').trim();
1413
+ const settings = { columns: [2, 3, 4].includes(columnValue) ? columnValue : 2, gap: gapValue === '12px' ? 'small' : gapValue === '36px' ? 'large' : 'medium', stackOnMobile: container.classList.contains('ngs-content-editor-html-grid-stack') };
1414
+ const cells = children(container).filter(cell => cell.matches('.ngs-content-editor-html-grid-cell')).map(cell => ({ id: createNgsHeadlessEditorId('cell'), blocks: parseBlocks(cell) }));
1415
+ return [createBlock('grid', { cells }, { settings })];
1416
+ }
1417
+ if (name === 'p' || /^h[1-6]$/.test(name)) {
1418
+ if (element.querySelector('img, video, iframe, a[download]'))
1419
+ return parseBlocks(element);
1420
+ return [createBlock(name === 'p' ? 'paragraph' : 'heading', parseText(element), { ...attrs, ...(name !== 'p' ? { settings: { level: Number(name[1]) } } : {}) })];
1421
+ }
1422
+ if (name === 'hr')
1423
+ return [createBlock('divider', null)];
1424
+ if (name === 'pre') {
1425
+ const code = direct(element, 'code') ?? element;
1426
+ const language = code.getAttribute('data-language') ?? Array.from(code.classList).find(cls => cls.startsWith('language-'))?.slice(9) ?? 'none';
1427
+ return [createBlock('code', [createNgsHeadlessEditorText(code.textContent ?? '')], { settings: { language } })];
1428
+ }
1429
+ if (name === 'ul' || name === 'ol')
1430
+ return [createBlock(name === 'ol' ? 'orderedList' : 'bulletList', listItems(element), { settings: { listStyle: name === 'ol' ? 'ordered' : 'bullet' } })];
1431
+ if (name === 'details') {
1432
+ const summary = direct(element, 'summary');
1433
+ const body = element.cloneNode(true);
1434
+ direct(body, 'summary')?.remove();
1435
+ return [createBlock('toggle', { title: summary ? parseText(summary) : [], blocks: parseBlocks(body) }, { settings: { expanded: element.hasAttribute('open') } })];
1436
+ }
1437
+ if (name === 'aside' && (element.hasAttribute('data-callout') || element.classList.contains('ngs-content-editor-html-callout'))) {
1438
+ const value = element.getAttribute('data-callout');
1439
+ return [createBlock('callout', parseText(element), { ...attrs, settings: { variant: ['note', 'tip', 'warning', 'danger'].includes(value ?? '') ? value : 'note' } })];
1440
+ }
1441
+ if (name === 'blockquote' || (name === 'figure' && direct(element, 'blockquote'))) {
1442
+ const quote = name === 'blockquote' ? element : direct(element, 'blockquote');
1443
+ const caption = name === 'figure' ? direct(element, 'figcaption') : undefined;
1444
+ return [createBlock('quote', { cite: { content: parseText(quote), props: alignment(quote) }, caption: { content: caption ? parseText(caption) : [], props: caption ? alignment(caption) : [] } })];
1445
+ }
1446
+ if (name === 'table') {
1447
+ const rows = Array.from(element.querySelectorAll('tr')).filter(row => row.closest('table') === element);
1448
+ const cells = rows.map(row => children(row).filter(cell => ['td', 'th'].includes(tag(cell))));
1449
+ return [createBlock('table', null, {
1450
+ rows: cells.map(row => row.map(parseText)), header: !!cells[0]?.some(cell => tag(cell) === 'th'),
1451
+ cellMetadata: cells.map(row => row.map(cell => ({ props: alignment(cell), options: {
1452
+ colspan: Math.max(1, Math.floor(dimension(cell, 'colspan') ?? 1)), rowspan: Math.max(1, Math.floor(dimension(cell, 'rowspan') ?? 1)),
1453
+ ...(dimension(cell, 'width') ? { width: dimension(cell, 'width') } : {})
1454
+ } })))
1455
+ })];
1456
+ }
1457
+ if (name === 'figure') {
1458
+ const child = direct(element, 'img, video, iframe');
1459
+ if (child)
1460
+ return media(child, element);
1461
+ }
1462
+ if (['img', 'video', 'iframe'].includes(name))
1463
+ return media(element);
1464
+ if (name === 'a' && element.hasAttribute('download')) {
1465
+ const url = safeContentEditorHtmlUrl(element.getAttribute('href'), 'attachment');
1466
+ return url ? [createBlock('attachment', { url, name: element.getAttribute('download') || element.textContent?.trim() || 'Download', size: 0, mimeType: '' })] : [];
1467
+ }
1468
+ return parseBlocks(element);
1469
+ };
1470
+ const context = {
1471
+ createBlock, createId: createNgsHeadlessEditorId, parseText, parseBlocks: element => parseBlocks(element),
1472
+ defaultFromHtml: builtin, safeUrl: safeContentEditorHtmlUrl
1473
+ };
1474
+ const parseElement = (element) => guarded(() => {
1475
+ if (ignoredTags.has(tag(element)))
1476
+ return [];
1477
+ for (const override of overrides) {
1478
+ if (element.matches(override.selector)) {
1479
+ const result = override.parse(element, context);
1480
+ return result === null ? [] : Array.isArray(result) ? [...result] : [result];
1481
+ }
1482
+ }
1483
+ return builtin(element);
1484
+ });
1485
+ const parseBlocks = (element) => guarded(() => {
1486
+ const output = [];
1487
+ let inline = inert.createElement('div');
1488
+ const flush = () => {
1489
+ const runs = parseText(inline);
1490
+ if (runs.some(run => run.text.trim()))
1491
+ output.push(createBlock('paragraph', runs, { props: alignment(element) }));
1492
+ inline = inert.createElement('div');
1493
+ };
1494
+ for (const node of Array.from(element.childNodes)) {
1495
+ if (node.nodeType === 1) {
1496
+ const child = node;
1497
+ if (ignoredTags.has(tag(child)))
1498
+ continue;
1499
+ if (blockTags.has(tag(child)) || ['img', 'video', 'iframe'].includes(tag(child)) || child.matches('a[download]') || overrides.some(override => child.matches(override.selector))) {
1500
+ flush();
1501
+ output.push(...parseElement(child));
1502
+ continue;
1503
+ }
1504
+ // Unknown inline wrappers may contain block elements; keep those structures.
1505
+ if (child.querySelector([...blockTags, 'img', 'video', 'iframe', 'a[download]'].join(',')) || overrides.some(override => child.querySelector(override.selector))) {
1506
+ flush();
1507
+ output.push(...parseElement(child));
1508
+ continue;
1509
+ }
1510
+ }
1511
+ inline.appendChild(node.cloneNode(true));
1512
+ }
1513
+ flush();
1514
+ return output;
1515
+ });
1516
+ return contentEditorFromJson({ version: 1, blocks: parseBlocks(inert.body) }, config, options);
1517
+ }
1518
+
1519
+ /** Parsing only: applications decide when to replace their current document. */
1520
+ class ContentEditorImporter {
1521
+ config = inject(CONTENT_EDITOR_CONFIG);
1522
+ document = inject(DOCUMENT);
1523
+ fromJson(source, config = {}, options = {}) {
1524
+ return contentEditorFromJson(source, mergeContentEditorConfig(this.config, config), options);
1525
+ }
1526
+ fromHtml(html, config = {}, options = {}) {
1527
+ return contentEditorFromHtml(html, mergeContentEditorConfig(this.config, config), { document: this.document, ...options });
1528
+ }
1529
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorImporter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1530
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorImporter, providedIn: 'root' });
1531
+ }
1532
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorImporter, decorators: [{
1533
+ type: Injectable,
1534
+ args: [{ providedIn: 'root' }]
1535
+ }] });
1536
+
1002
1537
  const CONTENT_EDITOR_CONFIG = new InjectionToken('CONTENT_EDITOR_CONFIG', {
1003
1538
  providedIn: 'root', factory: () => ({})
1004
1539
  });
@@ -1015,6 +1550,8 @@ function mergeContentEditorConfig(...configs) {
1015
1550
  result.marks = { ...result.marks, ...config.marks };
1016
1551
  if (config.includeStyles !== undefined)
1017
1552
  result.includeStyles = config.includeStyles;
1553
+ if (config.importMarks !== undefined)
1554
+ result.importMarks = config.importMarks;
1018
1555
  if (config.unknownBlockToHtml !== undefined)
1019
1556
  result.unknownBlockToHtml = config.unknownBlockToHtml;
1020
1557
  }
@@ -1027,7 +1564,8 @@ function provideContentEditorConfig(config = {}) {
1027
1564
  provide: CONTENT_EDITOR_CONFIG,
1028
1565
  useFactory: () => mergeContentEditorConfig(inject(CONTENT_EDITOR_CONFIG, { skipSelf: true, optional: true }) ?? {}, config)
1029
1566
  },
1030
- ContentEditorHtmlSerializer
1567
+ ContentEditorHtmlSerializer,
1568
+ ContentEditorImporter
1031
1569
  ]);
1032
1570
  }
1033
1571
 
@@ -1464,6 +2002,7 @@ class ContentBuilderComponent {
1464
2002
  editor = inject(NgsHeadlessEditor);
1465
2003
  globalConfig = inject(CONTENT_EDITOR_CONFIG);
1466
2004
  htmlSerializer = inject(ContentEditorHtmlSerializer);
2005
+ importer = inject(ContentEditorImporter);
1467
2006
  config = input({}, /* @ts-ignore */
1468
2007
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
1469
2008
  /** One insertion menu shared by root controls, nested collections and custom blocks. */
@@ -1506,7 +2045,7 @@ class ContentBuilderComponent {
1506
2045
  }
1507
2046
  },
1508
2047
  {
1509
- component: () => import('./ngstarter-ui-components-content-editor-paragraph-block.component-JVxf_Cdx.mjs').then(c => c.ParagraphBlockComponent),
2048
+ component: () => import('./ngstarter-ui-components-content-editor-paragraph-block.component-Dd0pQquG.mjs').then(c => c.ParagraphBlockComponent),
1510
2049
  type: 'paragraph',
1511
2050
  options: {},
1512
2051
  empty: () => {
@@ -1518,7 +2057,7 @@ class ContentBuilderComponent {
1518
2057
  }
1519
2058
  },
1520
2059
  {
1521
- component: () => import('./ngstarter-ui-components-content-editor-code-block.component-DSdVOJtH.mjs').then(c => c.CodeBlockComponent),
2060
+ component: () => import('./ngstarter-ui-components-content-editor-code-block.component-BizHRPdC.mjs').then(c => c.CodeBlockComponent),
1522
2061
  type: 'code',
1523
2062
  options: {},
1524
2063
  empty: () => {
@@ -1531,7 +2070,7 @@ class ContentBuilderComponent {
1531
2070
  }
1532
2071
  },
1533
2072
  {
1534
- component: () => import('./ngstarter-ui-components-content-editor-heading-block.component-BYpctSPe.mjs').then(c => c.HeadingBlockComponent),
2073
+ component: () => import('./ngstarter-ui-components-content-editor-heading-block.component-CDSt4rXe.mjs').then(c => c.HeadingBlockComponent),
1535
2074
  type: 'heading',
1536
2075
  options: {},
1537
2076
  empty: () => {
@@ -1545,7 +2084,7 @@ class ContentBuilderComponent {
1545
2084
  }
1546
2085
  },
1547
2086
  {
1548
- component: () => import('./ngstarter-ui-components-content-editor-image-block.component-B3MnANpi.mjs').then(c => c.ImageBlockComponent),
2087
+ component: () => import('./ngstarter-ui-components-content-editor-image-block.component-LfKZapgv.mjs').then(c => c.ImageBlockComponent),
1549
2088
  type: 'image',
1550
2089
  options: {
1551
2090
  uploadFn: (file, base64) => {
@@ -1572,7 +2111,7 @@ class ContentBuilderComponent {
1572
2111
  }
1573
2112
  },
1574
2113
  {
1575
- component: () => import('./ngstarter-ui-components-content-editor-video-block.component-DQUPVDwV.mjs').then(c => c.VideoBlockComponent),
2114
+ component: () => import('./ngstarter-ui-components-content-editor-video-block.component-hBR5AauH.mjs').then(c => c.VideoBlockComponent),
1576
2115
  type: 'video',
1577
2116
  options: {
1578
2117
  uploadFn: (file, base64) => {
@@ -1600,7 +2139,7 @@ class ContentBuilderComponent {
1600
2139
  }
1601
2140
  },
1602
2141
  {
1603
- component: () => import('./ngstarter-ui-components-content-editor-list-block.component-6SMBxIl4.mjs').then(c => c.ListBlockComponent),
2142
+ component: () => import('./ngstarter-ui-components-content-editor-list-block.component-CdQ30RjA.mjs').then(c => c.ListBlockComponent),
1604
2143
  type: 'bulletList',
1605
2144
  options: {},
1606
2145
  empty: () => {
@@ -1613,7 +2152,7 @@ class ContentBuilderComponent {
1613
2152
  }
1614
2153
  },
1615
2154
  {
1616
- component: () => import('./ngstarter-ui-components-content-editor-list-block.component-6SMBxIl4.mjs').then(c => c.ListBlockComponent),
2155
+ component: () => import('./ngstarter-ui-components-content-editor-list-block.component-CdQ30RjA.mjs').then(c => c.ListBlockComponent),
1617
2156
  type: 'orderedList',
1618
2157
  options: {},
1619
2158
  empty: () => {
@@ -1626,7 +2165,7 @@ class ContentBuilderComponent {
1626
2165
  }
1627
2166
  },
1628
2167
  {
1629
- component: () => import('./ngstarter-ui-components-content-editor-table-block.component-CJS-IBHw.mjs').then(c => c.TableBlockComponent),
2168
+ component: () => import('./ngstarter-ui-components-content-editor-table-block.component-BTExrXy8.mjs').then(c => c.TableBlockComponent),
1630
2169
  type: 'table',
1631
2170
  options: {},
1632
2171
  empty: () => {
@@ -1695,7 +2234,7 @@ class ContentBuilderComponent {
1695
2234
  }
1696
2235
  },
1697
2236
  {
1698
- component: () => import('./ngstarter-ui-components-content-editor-quote-block.component-7EO7z7Sr.mjs').then(c => c.QuoteBlockComponent),
2237
+ component: () => import('./ngstarter-ui-components-content-editor-quote-block.component-CUxKoeb_.mjs').then(c => c.QuoteBlockComponent),
1699
2238
  type: 'quote',
1700
2239
  options: {},
1701
2240
  empty: () => {
@@ -1715,7 +2254,7 @@ class ContentBuilderComponent {
1715
2254
  }
1716
2255
  },
1717
2256
  {
1718
- component: () => import('./ngstarter-ui-components-content-editor-embed-block-DhFxtMQS.mjs').then(c => c.EmbedBlock),
2257
+ component: () => import('./ngstarter-ui-components-content-editor-embed-block-BzoaJvai.mjs').then(c => c.EmbedBlock),
1719
2258
  type: 'embed',
1720
2259
  options: {},
1721
2260
  empty: () => {
@@ -2251,6 +2790,24 @@ class ContentBuilderComponent {
2251
2790
  getData() {
2252
2791
  return this.editor.document();
2253
2792
  }
2793
+ /** Validates before replacing the document. Import is one undoable edit. */
2794
+ importJson(source, config = {}, options = {}) {
2795
+ return this.applyImport(this.importer.fromJson(source, mergeContentEditorConfig(this.config(), config), options));
2796
+ }
2797
+ importHtml(html, config = {}, options = {}) {
2798
+ return this.applyImport(this.importer.fromHtml(html, mergeContentEditorConfig(this.config(), config), options));
2799
+ }
2800
+ applyImport(document) {
2801
+ if (!this.loaded)
2802
+ throw new ContentEditorImportError('$editor', 'Initialize the builder before importing');
2803
+ if (this.editor.readOnly())
2804
+ throw new ContentEditorImportError('$editor', 'Cannot import into a read-only editor');
2805
+ this.editor.updateDocument(document);
2806
+ this.selectedBlocksModel.clear();
2807
+ this._store.setFocusedBlockId(null);
2808
+ this._store.setActiveBlockId(null);
2809
+ return this.getData();
2810
+ }
2254
2811
  /** Exports the live document, including nested blocks, through the configured converters. */
2255
2812
  toHtml(config = {}) {
2256
2813
  const defaults = { blocks: Object.fromEntries(this.blockDefs().map(def => [def.type, { toHtml: def.toHtml }])) };
@@ -2593,6 +3150,7 @@ class ContentBuilderComponent {
2593
3150
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentBuilderComponent, isStandalone: true, selector: "ngs-content-editor-builder", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, contentChangedDelay: { classPropertyName: "contentChangedDelay", publicName: "contentChangedDelay", isSignal: true, isRequired: false, transformFunction: null }, persistDraft: { classPropertyName: "persistDraft", publicName: "persistDraft", isSignal: true, isRequired: false, transformFunction: null }, suggestions: { classPropertyName: "suggestions", publicName: "suggestions", isSignal: true, isRequired: false, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: false, transformFunction: null }, scrollContainer: { classPropertyName: "scrollContainer", publicName: "scrollContainer", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { contentChanged: "contentChanged" }, host: { attributes: { "tabindex": "0" }, listeners: { "paste": "_onPaste($event)", "keydown": "_onKeyDown($event)" }, properties: { "class.is-block-dragging": "_blockDragging()", "class.is-selection-of-blocks-active": "isSelectionOfBlocksActive()", "class.select-none": "isSelectionOfBlocksActive()", "style.user-select": "isSelectionOfBlocksActive() ? \"none\" : null" }, classAttribute: "ngs-content-editor-builder" }, providers: [
2594
3151
  provideContentEditor(),
2595
3152
  ContentEditorHtmlSerializer,
3153
+ ContentEditorImporter,
2596
3154
  ContentBuilderStore,
2597
3155
  {
2598
3156
  provide: CONTENT_BUILDER,
@@ -2633,6 +3191,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
2633
3191
  ], changeDetection: ChangeDetectionStrategy.OnPush, providers: [
2634
3192
  provideContentEditor(),
2635
3193
  ContentEditorHtmlSerializer,
3194
+ ContentEditorImporter,
2636
3195
  ContentBuilderStore,
2637
3196
  {
2638
3197
  provide: CONTENT_BUILDER,
@@ -3306,5 +3865,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
3306
3865
  * Generated bundle index. Do not edit.
3307
3866
  */
3308
3867
 
3309
- export { contentEditorImageToHtml as $, ContentEditorCodeRenderer as A, BlockSelectionDirective as B, ContentBuilderStore as C, ContentEditorDividerRenderer as D, ContentEditorEmbedRenderer as E, ContentEditorGalleryRenderer as F, ContentEditorGridRenderer as G, ContentEditorHeadingRenderer as H, ContentEditorHtmlSerializer as I, ContentEditorImageRenderer as J, ContentEditorListRenderer as K, ContentEditorParagraphRenderer as L, ContentEditorQuoteRenderer as M, ContentEditorRenderer as N, ContentEditorTableRenderer as O, ContentEditorToggleRenderer as P, ContentEditorVideoRenderer as Q, contentEditorAttachmentToHtml as R, contentEditorBlockToHtml as S, TextSelectionPopupDirective as T, contentEditorCalloutToHtml as U, contentEditorCodeToHtml as V, contentEditorDividerToHtml as W, contentEditorEmbedToHtml as X, contentEditorGalleryToHtml as Y, contentEditorGridToHtml as Z, contentEditorHeadingToHtml as _, CONTENT_BUILDER as a, contentEditorListToHtml as a0, contentEditorNativeBlock as a1, contentEditorParagraphToHtml as a2, contentEditorQuoteToHtml as a3, contentEditorTableToHtml as a4, contentEditorToHtml as a5, contentEditorToggleToHtml as a6, contentEditorVideoToHtml as a7, mergeContentEditorConfig as a8, provideContentEditor as a9, provideContentEditorConfig as aa, provideContentEditorRenderer as ab, provideContentEditorRenderers as ac, replaceContentEditorCollection as ad, contentEditorText as b, cloneContentEditorValue as c, ContentEditorContentEditableDirective as d, CONTENT_EDITOR_BLOCK as e, contentEditorFileSize as f, contentEditorResourceUrl as g, findContentEditorBlock as h, contentEditorGridSettings as i, emptyGridCell as j, contentEditorCollection as k, contentEditorBlockView as l, contentEditorChildCollections as m, isContentEditorBlockEmpty as n, CONTENT_EDITOR_BLOCK_RENDERERS as o, CONTENT_EDITOR_CALLOUT_HTML_STYLES as p, CONTENT_EDITOR_CONFIG as q, readContentEditorFile as r, CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS as s, CONTENT_EDITOR_DEFAULT_RENDERERS as t, CONTENT_EDITOR_GALLERY_HTML_STYLES as u, CONTENT_EDITOR_GRID_HTML_STYLES as v, CommandBarComponent as w, ContentBuilderComponent as x, ContentEditorAttachmentRenderer as y, ContentEditorCalloutRenderer as z };
3310
- //# sourceMappingURL=ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor--rb3-UuO.mjs.map
3868
+ export { contentEditorFromJson as $, ContentEditorCodeRenderer as A, BlockSelectionDirective as B, ContentBuilderStore as C, ContentEditorDividerRenderer as D, ContentEditorEmbedRenderer as E, ContentEditorGalleryRenderer as F, ContentEditorGridRenderer as G, ContentEditorHeadingRenderer as H, ContentEditorHtmlSerializer as I, ContentEditorImageRenderer as J, ContentEditorImportError as K, ContentEditorImporter as L, ContentEditorListRenderer as M, ContentEditorParagraphRenderer as N, ContentEditorQuoteRenderer as O, ContentEditorRenderer as P, ContentEditorTableRenderer as Q, ContentEditorToggleRenderer as R, ContentEditorVideoRenderer as S, TextSelectionPopupDirective as T, contentEditorAttachmentToHtml as U, contentEditorBlockToHtml as V, contentEditorCalloutToHtml as W, contentEditorCodeToHtml as X, contentEditorDividerToHtml as Y, contentEditorEmbedToHtml as Z, contentEditorFromHtml as _, CONTENT_BUILDER as a, contentEditorGalleryToHtml as a0, contentEditorGridToHtml as a1, contentEditorHeadingToHtml as a2, contentEditorImageToHtml as a3, contentEditorListToHtml as a4, contentEditorNativeBlock as a5, contentEditorParagraphToHtml as a6, contentEditorQuoteToHtml as a7, contentEditorTableToHtml as a8, contentEditorToHtml as a9, contentEditorToggleToHtml as aa, contentEditorVideoToHtml as ab, mergeContentEditorConfig as ac, provideContentEditor as ad, provideContentEditorConfig as ae, provideContentEditorRenderer as af, provideContentEditorRenderers as ag, replaceContentEditorCollection as ah, contentEditorText as b, cloneContentEditorValue as c, ContentEditorContentEditableDirective as d, CONTENT_EDITOR_BLOCK as e, contentEditorFileSize as f, contentEditorResourceUrl as g, findContentEditorBlock as h, contentEditorGridSettings as i, emptyGridCell as j, contentEditorCollection as k, contentEditorBlockView as l, contentEditorChildCollections as m, isContentEditorBlockEmpty as n, CONTENT_EDITOR_BLOCK_RENDERERS as o, CONTENT_EDITOR_CALLOUT_HTML_STYLES as p, CONTENT_EDITOR_CONFIG as q, readContentEditorFile as r, CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS as s, CONTENT_EDITOR_DEFAULT_RENDERERS as t, CONTENT_EDITOR_GALLERY_HTML_STYLES as u, CONTENT_EDITOR_GRID_HTML_STYLES as v, CommandBarComponent as w, ContentBuilderComponent as x, ContentEditorAttachmentRenderer as y, ContentEditorCalloutRenderer as z };
3869
+ //# sourceMappingURL=ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-CK4ssnlk.mjs.map