@ngstarter-ui/components 22.2.3 → 22.2.5
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 +97 -8
- package/content-editor/BLOCK_FORMAT.md +182 -0
- package/data-view/API.md +262 -0
- package/fesm2022/ngstarter-ui-components-button.mjs +2 -2
- package/fesm2022/ngstarter-ui-components-button.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-content-editor-attachment-block-DZqyCrEK.mjs +35 -0
- package/fesm2022/ngstarter-ui-components-content-editor-attachment-block-DZqyCrEK.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-callout-block-Jbf8h2yz.mjs → ngstarter-ui-components-content-editor-callout-block-CyVPVMXi.mjs} +3 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-callout-block-Jbf8h2yz.mjs.map → ngstarter-ui-components-content-editor-callout-block-CyVPVMXi.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-code-block.component-BizHRPdC.mjs → ngstarter-ui-components-content-editor-code-block.component-Qzsc08aS.mjs} +4 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-code-block.component-BizHRPdC.mjs.map → ngstarter-ui-components-content-editor-code-block.component-Qzsc08aS.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-embed-block-BzoaJvai.mjs → ngstarter-ui-components-content-editor-embed-block-9EHRGpW_.mjs} +2 -2
- package/fesm2022/{ngstarter-ui-components-content-editor-embed-block-BzoaJvai.mjs.map → ngstarter-ui-components-content-editor-embed-block-9EHRGpW_.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-gallery-block-C4p-S0Do.mjs → ngstarter-ui-components-content-editor-gallery-block-CBuzrmSH.mjs} +16 -39
- package/fesm2022/ngstarter-ui-components-content-editor-gallery-block-CBuzrmSH.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-grid-block-Cdq_Dcv2.mjs → ngstarter-ui-components-content-editor-grid-block-Sy67i4mg.mjs} +5 -6
- package/fesm2022/{ngstarter-ui-components-content-editor-grid-block-Cdq_Dcv2.mjs.map → ngstarter-ui-components-content-editor-grid-block-Sy67i4mg.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-heading-block.component-CDSt4rXe.mjs → ngstarter-ui-components-content-editor-heading-block.component-CnDuIpxQ.mjs} +8 -5
- package/fesm2022/ngstarter-ui-components-content-editor-heading-block.component-CnDuIpxQ.mjs.map +1 -0
- package/fesm2022/ngstarter-ui-components-content-editor-image-block.component-CqbgVnDh.mjs +113 -0
- package/fesm2022/ngstarter-ui-components-content-editor-image-block.component-CqbgVnDh.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-list-block.component-CdQ30RjA.mjs → ngstarter-ui-components-content-editor-list-block.component-CHJr_pFf.mjs} +4 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-list-block.component-CdQ30RjA.mjs.map → ngstarter-ui-components-content-editor-list-block.component-CHJr_pFf.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-nested-blocks-CbZY0keH.mjs → ngstarter-ui-components-content-editor-nested-blocks-fPnU42nP.mjs} +4 -4
- package/fesm2022/ngstarter-ui-components-content-editor-nested-blocks-fPnU42nP.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-CK4ssnlk.mjs → ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-dGibIV4n.mjs} +2089 -1521
- package/fesm2022/ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-dGibIV4n.mjs.map +1 -0
- package/fesm2022/{ngstarter-ui-components-content-editor-paragraph-block.component-Dd0pQquG.mjs → ngstarter-ui-components-content-editor-paragraph-block.component-CqU1XJTo.mjs} +4 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-paragraph-block.component-Dd0pQquG.mjs.map → ngstarter-ui-components-content-editor-paragraph-block.component-CqU1XJTo.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-quote-block.component-CUxKoeb_.mjs → ngstarter-ui-components-content-editor-quote-block.component-fAUfABVY.mjs} +4 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-quote-block.component-CUxKoeb_.mjs.map → ngstarter-ui-components-content-editor-quote-block.component-fAUfABVY.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-table-block.component-BTExrXy8.mjs → ngstarter-ui-components-content-editor-table-block.component-CqbnMNug.mjs} +4 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-table-block.component-BTExrXy8.mjs.map → ngstarter-ui-components-content-editor-table-block.component-CqbnMNug.mjs.map} +1 -1
- package/fesm2022/{ngstarter-ui-components-content-editor-toggle-block-B46YeMGQ.mjs → ngstarter-ui-components-content-editor-toggle-block-CHtnu1GQ.mjs} +3 -4
- package/fesm2022/{ngstarter-ui-components-content-editor-toggle-block-B46YeMGQ.mjs.map → ngstarter-ui-components-content-editor-toggle-block-CHtnu1GQ.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-DKcWb54Z.mjs +134 -0
- package/fesm2022/ngstarter-ui-components-content-editor-video-block.component-DKcWb54Z.mjs.map +1 -0
- package/fesm2022/ngstarter-ui-components-content-editor.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-core.mjs +46 -1
- package/fesm2022/ngstarter-ui-components-core.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-data-view.mjs +1011 -90
- package/fesm2022/ngstarter-ui-components-data-view.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-datepicker.mjs +45 -19
- package/fesm2022/ngstarter-ui-components-datepicker.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-filter-builder.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-filter-builder.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-form-builder.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-form-builder.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-headless-editor.mjs +58 -1
- package/fesm2022/ngstarter-ui-components-headless-editor.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-image-designer.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-image-designer.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-kanban-board.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-kanban-board.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-menu.mjs +17 -4
- package/fesm2022/ngstarter-ui-components-menu.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-pdf-builder.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-pdf-builder.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-pdf-viewer.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-pdf-viewer.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-phone-input.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-phone-input.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-signature-pad.mjs +1 -1
- package/fesm2022/ngstarter-ui-components-signature-pad.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-sort.mjs +9 -2
- package/fesm2022/ngstarter-ui-components-sort.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-table.mjs +10 -0
- package/fesm2022/ngstarter-ui-components-table.mjs.map +1 -1
- package/package.json +1 -1
- package/styles/_common.scss +2 -1
- package/styles/_tokens.scss +32 -1
- package/styles/themes/default.scss +1 -1
- package/types/ngstarter-ui-components-content-editor.d.ts +211 -11
- package/types/ngstarter-ui-components-core.d.ts +4 -1
- package/types/ngstarter-ui-components-data-view.d.ts +204 -11
- package/types/ngstarter-ui-components-datepicker.d.ts +3 -1
- package/types/ngstarter-ui-components-headless-editor.d.ts +6 -1
- package/types/ngstarter-ui-components-menu.d.ts +5 -1
- package/types/ngstarter-ui-components-sort.d.ts +1 -0
- package/types/ngstarter-ui-components-table.d.ts +2 -0
- package/fesm2022/ngstarter-ui-components-content-editor-attachment-block-DlUkhwCu.mjs +0 -54
- package/fesm2022/ngstarter-ui-components-content-editor-attachment-block-DlUkhwCu.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-block-base-C46lyMrp.mjs +0 -47
- package/fesm2022/ngstarter-ui-components-content-editor-block-base-C46lyMrp.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-gallery-block-C4p-S0Do.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-heading-block.component-CDSt4rXe.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-image-block.component-LfKZapgv.mjs +0 -169
- package/fesm2022/ngstarter-ui-components-content-editor-image-block.component-LfKZapgv.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-nested-blocks-CbZY0keH.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-CK4ssnlk.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-upload-block-base-DKqojf--.mjs +0 -29
- package/fesm2022/ngstarter-ui-components-content-editor-upload-block-base-DKqojf--.mjs.map +0 -1
- package/fesm2022/ngstarter-ui-components-content-editor-video-block.component-hBR5AauH.mjs +0 -201
- package/fesm2022/ngstarter-ui-components-content-editor-video-block.component-hBR5AauH.mjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, DestroyRef, signal, computed,
|
|
2
|
+
import { inject, Injectable, InjectionToken, makeEnvironmentProviders, DestroyRef, signal, computed, ElementRef, input, output, effect, untracked, afterNextRender, afterRenderEffect, Directive, ChangeDetectionStrategy, Component, DOCUMENT as DOCUMENT$1, model, EventEmitter, HostListener, Output, Input as Input$1, PLATFORM_ID, viewChild, numberAttribute, EnvironmentInjector, ChangeDetectorRef, booleanAttribute, runInInjectionContext, forwardRef, linkedSignal, viewChildren } from '@angular/core';
|
|
3
3
|
import { Button } from '@ngstarter-ui/components/button';
|
|
4
4
|
import { Icon } from '@ngstarter-ui/components/icon';
|
|
5
|
-
import { Menu, MenuItem, MenuTrigger, MenuHeading, MenuContent } from '@ngstarter-ui/components/menu';
|
|
5
|
+
import { Menu, MenuItem, MenuTrigger, MenuHeading, MenuContent, MenuHeader } 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,
|
|
8
|
+
import { isNgsHeadlessEditorTextContent, getNgsHeadlessEditorTableData, createNgsHeadlessEditorId, normalizeNgsHeadlessEditorLink, normalizeNgsHeadlessEditorColor, basicTextEditorPlugin, colorEditorPlugin, linkEditorPlugin, createNgsHeadlessEditorText, normalizeNgsHeadlessEditorTextContent, NgsHeadlessEditor, NgsHeadlessEditorInlineRegion, NgsHeadlessEditorSurface, 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, createNgsHeadlessEditorDocument, 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';
|
|
@@ -13,10 +13,12 @@ import * as i1$1 from '@angular/forms';
|
|
|
13
13
|
import { FormBuilder, Validators, ReactiveFormsModule, FormsModule } from '@angular/forms';
|
|
14
14
|
import { SlideToggle } from '@ngstarter-ui/components/slide-toggle';
|
|
15
15
|
import { Tooltip } from '@ngstarter-ui/components/tooltip';
|
|
16
|
+
import { EmptyState } from '@ngstarter-ui/components/empty-state';
|
|
16
17
|
import { v7 } from 'uuid';
|
|
17
18
|
import { CdkDropList, CdkDrag, CdkDragHandle, CdkDragPlaceholder } from '@angular/cdk/drag-drop';
|
|
18
19
|
import { ConfirmManager } from '@ngstarter-ui/components/confirm';
|
|
19
20
|
import { CdkMonitorFocus } from '@angular/cdk/a11y';
|
|
21
|
+
import { bindNgsOverlayTheme, SafeResourceUrlPipe } from '@ngstarter-ui/components/core';
|
|
20
22
|
import { ComponentPortal } from '@angular/cdk/portal';
|
|
21
23
|
import { Subject, fromEvent } from 'rxjs';
|
|
22
24
|
import { throttleTime, shareReplay, auditTime, map, startWith, distinctUntilChanged } from 'rxjs/operators';
|
|
@@ -31,7 +33,6 @@ import { ExpansionPanel, ExpansionPanelHeader, ExpansionPanelTitle } from '@ngst
|
|
|
31
33
|
import { Alert, AlertIconDirective } from '@ngstarter-ui/components/alert';
|
|
32
34
|
import { CodeHighlighter } from '@ngstarter-ui/components/code-highlighter';
|
|
33
35
|
import { Divider } from '@ngstarter-ui/components/divider';
|
|
34
|
-
import { SafeResourceUrlPipe } from '@ngstarter-ui/components/core';
|
|
35
36
|
import { NativeTable } from '@ngstarter-ui/components/table';
|
|
36
37
|
|
|
37
38
|
/** Plain text used by empty states and literal code editing. */
|
|
@@ -153,1423 +154,1693 @@ function cloneContentEditorValue(value) {
|
|
|
153
154
|
}
|
|
154
155
|
return value;
|
|
155
156
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const mouse = (event) => { if (this.dragging)
|
|
166
|
-
this.dragPointer.set({ x: event.clientX, y: event.clientY }); };
|
|
167
|
-
const touch = (event) => {
|
|
168
|
-
const point = event.touches[0];
|
|
169
|
-
if (this.dragging && point)
|
|
170
|
-
this.dragPointer.set({ x: point.clientX, y: point.clientY });
|
|
171
|
-
};
|
|
172
|
-
document.addEventListener('mousemove', mouse, true);
|
|
173
|
-
document.addEventListener('touchmove', touch, { capture: true, passive: true });
|
|
174
|
-
inject(DestroyRef).onDestroy(() => {
|
|
175
|
-
document.removeEventListener('mousemove', mouse, true);
|
|
176
|
-
document.removeEventListener('touchmove', touch, true);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
textEdit = null;
|
|
180
|
-
/** Scopes typing groups to one text region, so adjacent cells never share undo. */
|
|
181
|
-
withTextEdit(origin, group, edit) {
|
|
182
|
-
const previous = this.textEdit;
|
|
183
|
-
this.textEdit = { origin, group };
|
|
184
|
-
try {
|
|
185
|
-
edit();
|
|
186
|
-
}
|
|
187
|
-
finally {
|
|
188
|
-
this.textEdit = previous;
|
|
157
|
+
/** Locates the collection owning a block, including deeply nested Grid/Toggle blocks. */
|
|
158
|
+
function contentEditorBlockScope(blocks, id, scope = {}) {
|
|
159
|
+
for (const block of blocks) {
|
|
160
|
+
if (block.id === id)
|
|
161
|
+
return scope;
|
|
162
|
+
if (block.type === 'toggle') {
|
|
163
|
+
const found = contentEditorBlockScope(block.content.blocks, id, { parentId: block.id });
|
|
164
|
+
if (found)
|
|
165
|
+
return found;
|
|
189
166
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
dragPointer = signal(null, /* @ts-ignore */
|
|
196
|
-
...(ngDevMode ? [{ debugName: "dragPointer" }] : /* istanbul ignore next */ []));
|
|
197
|
-
setDragging(dragging) {
|
|
198
|
-
this.dragging = dragging;
|
|
199
|
-
if (!dragging)
|
|
200
|
-
this.dragPointer.set(null);
|
|
201
|
-
}
|
|
202
|
-
dropLists = signal([], /* @ts-ignore */
|
|
203
|
-
...(ngDevMode ? [{ debugName: "dropLists" }] : /* istanbul ignore next */ []));
|
|
204
|
-
registerDropList(list) {
|
|
205
|
-
if (!this.dropLists().includes(list))
|
|
206
|
-
this.dropLists.update(lists => [...lists, list]);
|
|
207
|
-
}
|
|
208
|
-
unregisterDropList(list) {
|
|
209
|
-
this.dropLists.update(lists => lists.filter(item => item !== list));
|
|
210
|
-
}
|
|
211
|
-
blocks = computed(() => this.editor.document().blocks.map(contentEditorBlockView), /* @ts-ignore */
|
|
212
|
-
...(ngDevMode ? [{ debugName: "blocks" }] : /* istanbul ignore next */ []));
|
|
213
|
-
setFocusedBlockId(id) { this.focusedBlockId.set(id); }
|
|
214
|
-
setActiveBlockId(id) { this.activeBlockId.set(id); }
|
|
215
|
-
setBlocks(value) {
|
|
216
|
-
this.editor.setDocument(value);
|
|
217
|
-
}
|
|
218
|
-
addBlock(block, index, scope = {}) {
|
|
219
|
-
const native = contentEditorNativeBlock(block);
|
|
220
|
-
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
221
|
-
const collection = [...contentEditorCollection(blocks, scope)];
|
|
222
|
-
collection.splice(index, 0, native);
|
|
223
|
-
replaceContentEditorCollection(blocks, scope, collection);
|
|
224
|
-
this.editor.updateDocument({ version: 1, blocks });
|
|
225
|
-
}
|
|
226
|
-
deleteBlock(id, _index) {
|
|
227
|
-
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
228
|
-
const remove = (items) => {
|
|
229
|
-
const index = items.findIndex(block => block.id === id);
|
|
230
|
-
if (index !== -1) {
|
|
231
|
-
items.splice(index, 1);
|
|
232
|
-
return true;
|
|
167
|
+
if (block.type === 'grid')
|
|
168
|
+
for (const cell of block.content.cells) {
|
|
169
|
+
const found = contentEditorBlockScope(cell.blocks, id, { parentId: block.id, cellId: cell.id });
|
|
170
|
+
if (found)
|
|
171
|
+
return found;
|
|
233
172
|
}
|
|
234
|
-
return items.some(block => contentEditorChildCollections(block).some(children => remove(children)));
|
|
235
|
-
};
|
|
236
|
-
if (remove(blocks))
|
|
237
|
-
this.editor.updateDocument({ version: 1, blocks });
|
|
238
|
-
}
|
|
239
|
-
updateBlock(id, data) {
|
|
240
|
-
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
241
|
-
const previous = findContentEditorBlock(blocks, id);
|
|
242
|
-
if (!previous)
|
|
243
|
-
return;
|
|
244
|
-
const next = contentEditorNativeBlock({ ...contentEditorBlockView(previous), ...data });
|
|
245
|
-
const origin = this.textEdit?.origin ?? 'command';
|
|
246
|
-
const typing = origin === 'keyboard' || origin === 'composition';
|
|
247
|
-
const root = blocks.find(block => !!findContentEditorBlock([block], id));
|
|
248
|
-
Object.assign(previous, next);
|
|
249
|
-
this.editor.updateBlock(root.id, { content: root.content, attrs: root.attrs }, typing ? origin : 'command', typing ? this.textEdit?.group ?? null : null);
|
|
250
|
-
}
|
|
251
|
-
moveBlock(from, to) {
|
|
252
|
-
const blocks = [...this.editor.document().blocks];
|
|
253
|
-
const [block] = blocks.splice(from, 1);
|
|
254
|
-
blocks.splice(to, 0, block);
|
|
255
|
-
this.editor.updateDocument({ version: 1, blocks });
|
|
256
|
-
}
|
|
257
|
-
moveBetweenCollections(from, to, source, target) {
|
|
258
|
-
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
259
|
-
const sourceItems = [...contentEditorCollection(blocks, source)];
|
|
260
|
-
const block = sourceItems[from];
|
|
261
|
-
if (!block || (target.parentId && findContentEditorBlock([block], target.parentId)))
|
|
262
|
-
return;
|
|
263
|
-
sourceItems.splice(from, 1);
|
|
264
|
-
replaceContentEditorCollection(blocks, source, sourceItems);
|
|
265
|
-
const targetItems = [...contentEditorCollection(blocks, target)];
|
|
266
|
-
targetItems.splice(to, 0, block);
|
|
267
|
-
replaceContentEditorCollection(blocks, target, targetItems);
|
|
268
|
-
this.editor.updateDocument({ version: 1, blocks });
|
|
269
173
|
}
|
|
270
|
-
|
|
271
|
-
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
/** Copies for insertion/duplication receive fresh ids throughout the tree. */
|
|
177
|
+
function contentEditorCopyBlocks(blocks) {
|
|
178
|
+
const copy = cloneContentEditorValue([...blocks]);
|
|
179
|
+
const visit = (block) => {
|
|
180
|
+
block.id = createNgsHeadlessEditorId(block.type);
|
|
181
|
+
for (const children of contentEditorChildCollections(block))
|
|
182
|
+
children.forEach(visit);
|
|
183
|
+
if (block.type === 'grid')
|
|
184
|
+
block.content.cells.forEach((cell) => cell.id = createNgsHeadlessEditorId('cell'));
|
|
185
|
+
if (block.type === 'gallery')
|
|
186
|
+
block.content.images.forEach((image) => image.id = createNgsHeadlessEditorId('image'));
|
|
187
|
+
};
|
|
188
|
+
copy.forEach(visit);
|
|
189
|
+
return copy;
|
|
190
|
+
}
|
|
191
|
+
/** UTF-16 offsets match the editor selection model; marks remain on sliced runs. */
|
|
192
|
+
function contentEditorSliceText(content, start, end = Infinity) {
|
|
193
|
+
let offset = 0;
|
|
194
|
+
return content.flatMap(run => {
|
|
195
|
+
const from = Math.max(0, start - offset);
|
|
196
|
+
const to = Math.min(run.text.length, end - offset);
|
|
197
|
+
offset += run.text.length;
|
|
198
|
+
return to > from ? [{ ...run, text: run.text.slice(from, to) }] : [];
|
|
199
|
+
});
|
|
272
200
|
}
|
|
273
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentBuilderStore, decorators: [{
|
|
274
|
-
type: Injectable
|
|
275
|
-
}], ctorParameters: () => [] });
|
|
276
201
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
surface = inject(NgsHeadlessEditorSurface);
|
|
282
|
-
store = inject(ContentBuilderStore, { optional: true });
|
|
283
|
-
historyGroup = createNgsHeadlessEditorId('content-region');
|
|
284
|
-
element = inject(ElementRef).nativeElement;
|
|
285
|
-
content = input([], { ...(ngDevMode ? { debugName: "content" } : /* istanbul ignore next */ {}), alias: 'ngsContentEditorContentEditable' });
|
|
286
|
-
settings = input({}, /* @ts-ignore */
|
|
287
|
-
...(ngDevMode ? [{ debugName: "settings" }] : /* istanbul ignore next */ []));
|
|
288
|
-
props = input([], /* @ts-ignore */
|
|
289
|
-
...(ngDevMode ? [{ debugName: "props" }] : /* istanbul ignore next */ []));
|
|
290
|
-
singleLine = input(false, /* @ts-ignore */
|
|
291
|
-
...(ngDevMode ? [{ debugName: "singleLine" }] : /* istanbul ignore next */ []));
|
|
292
|
-
contentChanged = output();
|
|
293
|
-
propsChanged = output();
|
|
294
|
-
pressedEnter = output();
|
|
295
|
-
initialized = output();
|
|
296
|
-
static forElement(element) {
|
|
297
|
-
return element ? regions.get(element) : undefined;
|
|
298
|
-
}
|
|
299
|
-
constructor() {
|
|
300
|
-
regions.set(this.element, this);
|
|
301
|
-
effect(() => {
|
|
302
|
-
const content = this.content();
|
|
303
|
-
untracked(() => this.region.load(content));
|
|
304
|
-
});
|
|
305
|
-
effect(() => {
|
|
306
|
-
const content = this.region.content();
|
|
307
|
-
const origin = this.region.editor.origin();
|
|
308
|
-
if (origin !== 'external' && origin !== 'history') {
|
|
309
|
-
untracked(() => {
|
|
310
|
-
if (this.store)
|
|
311
|
-
this.store.withTextEdit(origin, this.historyGroup, () => this.contentChanged.emit(content));
|
|
312
|
-
else
|
|
313
|
-
this.contentChanged.emit(content);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
// Capture before the surface and the block's own listeners. Structural Enter
|
|
318
|
-
// stays with the content builder; multiline fields use the headless surface.
|
|
319
|
-
this.element.addEventListener('keydown', this.onKeydown, true);
|
|
320
|
-
this.element.addEventListener('beforeinput', this.onBeforeInput, true);
|
|
321
|
-
afterNextRender(() => this.initialized.emit());
|
|
202
|
+
function getTextAlignment(props) {
|
|
203
|
+
const value = props?.find(prop => prop.name === 'text-alignment')?.value;
|
|
204
|
+
if (value === 'center' || value === 'right' || value === 'justify') {
|
|
205
|
+
return value;
|
|
322
206
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
this.propsChanged.emit([
|
|
329
|
-
...this.props().filter(prop => prop.name !== 'text-alignment'),
|
|
330
|
-
{ name: 'text-alignment', value }
|
|
331
|
-
]);
|
|
207
|
+
return 'left';
|
|
208
|
+
}
|
|
209
|
+
function getDimensionAttribute(value) {
|
|
210
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
211
|
+
return value;
|
|
332
212
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.pressedEnter.emit(event);
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
onBeforeInput = (event) => {
|
|
341
|
-
if (event.inputType === 'insertParagraph' && this.singleLine() && !event.isComposing) {
|
|
342
|
-
event.preventDefault();
|
|
343
|
-
event.stopImmediatePropagation();
|
|
344
|
-
this.pressedEnter.emit(new KeyboardEvent('keydown', { key: 'Enter' }));
|
|
213
|
+
if (typeof value === 'string') {
|
|
214
|
+
const trimmed = value.trim();
|
|
215
|
+
if (!trimmed || trimmed === 'auto') {
|
|
216
|
+
return null;
|
|
345
217
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
regions.delete(this.element);
|
|
349
|
-
this.element.removeEventListener('keydown', this.onKeydown, true);
|
|
350
|
-
this.element.removeEventListener('beforeinput', this.onBeforeInput, true);
|
|
218
|
+
const parsed = Number.parseFloat(trimmed);
|
|
219
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
351
220
|
}
|
|
352
|
-
|
|
353
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.7", type: ContentEditorContentEditableDirective, isStandalone: true, selector: "[ngsContentEditorContentEditable]", inputs: { content: { classPropertyName: "content", publicName: "ngsContentEditorContentEditable", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, singleLine: { classPropertyName: "singleLine", publicName: "singleLine", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { contentChanged: "contentChanged", propsChanged: "propsChanged", pressedEnter: "pressedEnter", initialized: "initialized" }, host: { listeners: { "focus": "activate()" }, properties: { "class.align-left": "alignment() === \"left\"", "class.align-center": "alignment() === \"center\"", "class.align-right": "alignment() === \"right\"", "class.align-justify": "alignment() === \"justify\"" }, classAttribute: "ngs-content-editor-content-editable" }, providers: [provideNgsHeadlessEditorInlineRegion()], exportAs: ["ngsContentEditorContentEditable"], hostDirectives: [{ directive: i1.NgsHeadlessEditorSurface }], ngImport: i0 });
|
|
221
|
+
return null;
|
|
354
222
|
}
|
|
355
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorContentEditableDirective, decorators: [{
|
|
356
|
-
type: Directive,
|
|
357
|
-
args: [{
|
|
358
|
-
selector: '[ngsContentEditorContentEditable]',
|
|
359
|
-
exportAs: 'ngsContentEditorContentEditable',
|
|
360
|
-
providers: [provideNgsHeadlessEditorInlineRegion()],
|
|
361
|
-
hostDirectives: [NgsHeadlessEditorSurface],
|
|
362
|
-
host: {
|
|
363
|
-
'class': 'ngs-content-editor-content-editable',
|
|
364
|
-
'[class.align-left]': 'alignment() === "left"',
|
|
365
|
-
'[class.align-center]': 'alignment() === "center"',
|
|
366
|
-
'[class.align-right]': 'alignment() === "right"',
|
|
367
|
-
'[class.align-justify]': 'alignment() === "justify"',
|
|
368
|
-
'(focus)': 'activate()'
|
|
369
|
-
}
|
|
370
|
-
}]
|
|
371
|
-
}], ctorParameters: () => [], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsContentEditorContentEditable", required: false }] }], settings: [{ type: i0.Input, args: [{ isSignal: true, alias: "settings", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], singleLine: [{ type: i0.Input, args: [{ isSignal: true, alias: "singleLine", required: false }] }], contentChanged: [{ type: i0.Output, args: ["contentChanged"] }], propsChanged: [{ type: i0.Output, args: ["propsChanged"] }], pressedEnter: [{ type: i0.Output, args: ["pressedEnter"] }], initialized: [{ type: i0.Output, args: ["initialized"] }] } });
|
|
372
223
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
cancel() {
|
|
381
|
-
this._dialogRef.close(false);
|
|
382
|
-
}
|
|
383
|
-
add() {
|
|
384
|
-
this._dialogRef.close(this.form.value);
|
|
385
|
-
}
|
|
386
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: AddLinkDialog, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
387
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.1.7", type: AddLinkDialog, isStandalone: true, selector: "ngs-add-link", ngImport: i0, template: "<h1 ngs-dialog-title>Add link</h1>\n<ngs-dialog-content [formGroup]=\"form\" class=\"!overflow-hidden\">\n <ngs-form-field class=\"w-full\">\n <ngs-label>Href (Url, Tel or other)</ngs-label>\n <input ngsInput type=\"text\" formControlName=\"href\">\n </ngs-form-field>\n <ngs-slide-toggle formControlName=\"openInNewTab\">Open link in a new tab</ngs-slide-toggle>\n</ngs-dialog-content>\n<ngs-dialog-actions>\n <button ngsButton (click)=\"cancel()\">Cancel</button>\n <button ngsButton=\"filled\"\n [disabled]=\"form.invalid\" (click)=\"add()\">Add</button>\n</ngs-dialog-actions>\n", styles: [""], dependencies: [{ kind: "component", type: DialogContent, selector: "ngs-dialog-content,[ngs-dialog-content],[ngsDialogContent]" }, { kind: "component", type: FormField, selector: "ngs-form-field", inputs: ["labelMode", "subscriptHiddenIfEmpty", "sameHeightAsButton"], exportAs: ["ngsFormField"] }, { kind: "directive", type: Input, selector: "input[ngsInput], textarea[ngsInput]", inputs: ["id", "placeholder", "required", "disabled", "readonly", "errorStateMatcher"], exportAs: ["ngsInput"] }, { kind: "component", type: DialogTitle, selector: "ngs-dialog-title, [ngs-dialog-title], [ngsDialogTitle]", inputs: ["id"], exportAs: ["ngsDialogTitle"] }, { kind: "component", type: DialogActions, selector: "ngs-dialog-actions, [ngs-dialog-actions], [ngsDialogActions]", inputs: ["align"] }, { kind: "component", type: Button, selector: " button[ngsButton], button[ngsIconButton], a[ngsButton], a[ngsIconButton] ", inputs: ["ngsButton", "ngsIconButton", "loading", "disabled", "disabledInteractive", "disableRipple", "reverse", "fullWidth", "hideTextOnMobile"], exportAs: ["ngsButton"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1$1.DefaultValueAccessor, selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1$1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: Label, selector: "ngs-label" }, { kind: "component", type: SlideToggle, selector: "ngs-slide-toggle", inputs: ["id", "name", "labelPosition", "aria-label", "aria-labelledby", "aria-describedby", "required", "disabled", "disableRipple", "tabIndex", "hideIcon", "color", "checked"], outputs: ["disabledChange", "checkedChange", "change", "toggleChange"], exportAs: ["ngsSlideToggle"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
224
|
+
/** Defaults shared by editing and read-only layout. */
|
|
225
|
+
function contentEditorGridSettings(settings) {
|
|
226
|
+
return {
|
|
227
|
+
columns: settings.columns === 3 || settings.columns === 4 ? settings.columns : 2,
|
|
228
|
+
gap: settings.gap === 'small' || settings.gap === 'large' ? settings.gap : 'medium',
|
|
229
|
+
stackOnMobile: settings.stackOnMobile !== false
|
|
230
|
+
};
|
|
388
231
|
}
|
|
389
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: AddLinkDialog, decorators: [{
|
|
390
|
-
type: Component,
|
|
391
|
-
args: [{ selector: 'ngs-add-link', imports: [
|
|
392
|
-
DialogContent,
|
|
393
|
-
FormField,
|
|
394
|
-
Input,
|
|
395
|
-
DialogTitle,
|
|
396
|
-
DialogActions,
|
|
397
|
-
Button,
|
|
398
|
-
ReactiveFormsModule,
|
|
399
|
-
Label,
|
|
400
|
-
SlideToggle
|
|
401
|
-
], changeDetection: ChangeDetectionStrategy.Eager, template: "<h1 ngs-dialog-title>Add link</h1>\n<ngs-dialog-content [formGroup]=\"form\" class=\"!overflow-hidden\">\n <ngs-form-field class=\"w-full\">\n <ngs-label>Href (Url, Tel or other)</ngs-label>\n <input ngsInput type=\"text\" formControlName=\"href\">\n </ngs-form-field>\n <ngs-slide-toggle formControlName=\"openInNewTab\">Open link in a new tab</ngs-slide-toggle>\n</ngs-dialog-content>\n<ngs-dialog-actions>\n <button ngsButton (click)=\"cancel()\">Cancel</button>\n <button ngsButton=\"filled\"\n [disabled]=\"form.invalid\" (click)=\"add()\">Add</button>\n</ngs-dialog-actions>\n" }]
|
|
402
|
-
}] });
|
|
403
232
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
|
|
233
|
+
/** Plain HTML layout styles, independent of Angular and the component library's theme. */
|
|
234
|
+
const CONTENT_EDITOR_GRID_HTML_STYLES = `.ngs-content-editor-html-grid{container-type:inline-size}.ngs-content-editor-html-grid-cells{display:grid;grid-template-columns:repeat(var(--ngs-html-grid-columns),minmax(0,1fr));gap:var(--ngs-html-grid-gap)}.ngs-content-editor-html-grid-cell{min-width:0}@container(max-width:480px){.ngs-content-editor-html-grid-stack{grid-template-columns:minmax(0,1fr)}}`;
|
|
235
|
+
const CONTENT_EDITOR_CALLOUT_HTML_STYLES = `.ngs-content-editor-html-callout{padding:16px;border-radius:8px;background:var(--ngs-color-primary-container,#eef3ff);color:var(--ngs-color-on-surface,#172033)}.ngs-content-editor-html-callout[data-callout=tip]{background:var(--ngs-color-success-container,#e8f5ee)}.ngs-content-editor-html-callout[data-callout=warning]{background:var(--ngs-color-warning-container,#fff3dc)}.ngs-content-editor-html-callout[data-callout=danger]{background:var(--ngs-color-danger-container,#fdeaea)}`;
|
|
236
|
+
const CONTENT_EDITOR_GALLERY_HTML_STYLES = `.ngs-content-editor-html-gallery{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;gap:16px}.ngs-content-editor-html-gallery>figure{flex:0 0 100%;min-width:0;margin:0;scroll-snap-align:start}.ngs-content-editor-html-gallery img{display:block;width:100%}`;
|
|
237
|
+
function settings(block) { return block.attrs?.['settings'] ?? {}; }
|
|
238
|
+
function alignment(props) {
|
|
239
|
+
const align = getTextAlignment(props);
|
|
240
|
+
return align === 'left' ? '' : ` style="text-align:${align}"`;
|
|
241
|
+
}
|
|
242
|
+
function dimension(name, value) {
|
|
243
|
+
const number = getDimensionAttribute(value);
|
|
244
|
+
return number !== null && number > 0 ? ` ${name}="${Math.round(number)}"` : '';
|
|
245
|
+
}
|
|
246
|
+
const contentEditorParagraphToHtml = (block, ctx) => `<p${alignment(block.attrs?.['props'])}>${ctx.renderText(block.content)}</p>`;
|
|
247
|
+
const contentEditorHeadingToHtml = (block, ctx) => {
|
|
248
|
+
const value = settings(block)['level'];
|
|
249
|
+
const level = Number.isInteger(value) && value >= 1 && value <= 6 ? value : 2;
|
|
250
|
+
return `<h${level}${alignment(block.attrs?.['props'])}>${ctx.renderText(block.content)}</h${level}>`;
|
|
251
|
+
};
|
|
252
|
+
const contentEditorCodeToHtml = (block, ctx) => `<pre><code data-language="${ctx.escape(settings(block)['language'] ?? 'none')}">${ctx.escape(contentEditorText(block.content))}</code></pre>`;
|
|
253
|
+
const contentEditorDividerToHtml = () => '<hr>';
|
|
254
|
+
const contentEditorListToHtml = (block, ctx) => {
|
|
255
|
+
const tag = block.type === 'orderedList' ? 'ol' : 'ul';
|
|
256
|
+
const list = (items) => `<${tag}>${items.map(item => `<li${alignment(item.props)}>${ctx.renderText(item.content)}${item.children?.length ? list(item.children) : ''}</li>`).join('')}</${tag}>`;
|
|
257
|
+
return list(block.content ?? []);
|
|
258
|
+
};
|
|
259
|
+
const contentEditorQuoteToHtml = (block, ctx) => {
|
|
260
|
+
const quote = block.content?.cite;
|
|
261
|
+
const caption = block.content?.caption;
|
|
262
|
+
return `<figure><blockquote${alignment(quote?.props)}>${ctx.renderText(quote?.content ?? [])}</blockquote>${contentEditorText(caption?.content).trim() ? `<figcaption${alignment(caption.props)}>${ctx.renderText(caption.content)}</figcaption>` : ''}</figure>`;
|
|
263
|
+
};
|
|
264
|
+
const contentEditorTableToHtml = (block, ctx) => {
|
|
265
|
+
const table = getNgsHeadlessEditorTableData(block);
|
|
266
|
+
const metadata = block.attrs?.['cellMetadata'];
|
|
267
|
+
const rows = table.rows.map((row, r) => `<tr>${row.map((runs, c) => {
|
|
268
|
+
const tag = r === 0 && table.header ? 'th' : 'td';
|
|
269
|
+
const cell = metadata?.[r]?.[c];
|
|
270
|
+
return `<${tag}${dimension('colspan', cell?.options?.['colspan'])}${dimension('rowspan', cell?.options?.['rowspan'])}${dimension('width', cell?.options?.['width'])}${alignment(cell?.props)}>${ctx.renderText(runs)}</${tag}>`;
|
|
271
|
+
}).join('')}</tr>`).join('');
|
|
272
|
+
return `<table><tbody>${rows}</tbody></table>`;
|
|
273
|
+
};
|
|
274
|
+
const contentEditorImageToHtml = (block, ctx) => {
|
|
275
|
+
const src = ctx.safeUrl(block.content?.src, 'image');
|
|
276
|
+
if (!src)
|
|
277
|
+
return '';
|
|
278
|
+
const alt = block.content?.alt ?? '';
|
|
279
|
+
const config = settings(block);
|
|
280
|
+
return `<figure><img src="${ctx.escape(src)}" alt="${ctx.escape(alt)}"${dimension('width', config['width'])}${dimension('height', config['height'])} style="max-width:100%;height:auto">${alt ? `<figcaption>${ctx.escape(alt)}</figcaption>` : ''}</figure>`;
|
|
281
|
+
};
|
|
282
|
+
const contentEditorVideoToHtml = (block, ctx) => {
|
|
283
|
+
const src = ctx.safeUrl(block.content?.src, 'media');
|
|
284
|
+
if (!src)
|
|
285
|
+
return '';
|
|
286
|
+
const config = settings(block);
|
|
287
|
+
return `<figure><video src="${ctx.escape(src)}" controls${dimension('width', config['width'])}${dimension('height', config['height'])} style="max-width:100%"></video>${block.content?.caption ? `<figcaption>${ctx.escape(block.content.caption)}</figcaption>` : ''}</figure>`;
|
|
288
|
+
};
|
|
289
|
+
const contentEditorEmbedToHtml = (block, ctx) => {
|
|
290
|
+
const src = ctx.safeUrl(block.content?.url, 'embed');
|
|
291
|
+
if (!src)
|
|
292
|
+
return '';
|
|
293
|
+
const config = settings(block);
|
|
294
|
+
return `<figure><iframe src="${ctx.escape(src)}" title="${ctx.escape(block.content?.type || 'Embedded content')}"${dimension('width', config['width'] ?? 700)}${dimension('height', config['height'] ?? 400)} style="max-width:100%" allowfullscreen></iframe></figure>`;
|
|
295
|
+
};
|
|
296
|
+
const contentEditorCalloutToHtml = (block, ctx) => {
|
|
297
|
+
ctx.addStyles(CONTENT_EDITOR_CALLOUT_HTML_STYLES);
|
|
298
|
+
const value = settings(block)['variant'];
|
|
299
|
+
const variant = ['note', 'tip', 'warning', 'danger'].includes(value) ? value : 'note';
|
|
300
|
+
return `<aside class="ngs-content-editor-html-callout" data-callout="${variant}"${alignment(block.attrs?.['props'])}>${ctx.renderText(block.content)}</aside>`;
|
|
301
|
+
};
|
|
302
|
+
const contentEditorToggleToHtml = (block, ctx) => `<details${settings(block)['expanded'] ? ' open' : ''}><summary>${ctx.renderText(block.content?.title ?? [])}</summary>${ctx.renderBlocks(block.content?.blocks ?? [])}</details>`;
|
|
303
|
+
const contentEditorAttachmentToHtml = (block, ctx) => {
|
|
304
|
+
const url = ctx.safeUrl(block.content?.url, 'attachment');
|
|
305
|
+
return url ? `<a href="${ctx.escape(url)}" download="${ctx.escape(block.content?.name)}">${ctx.escape(block.content?.name || 'Download')}</a>` : '';
|
|
306
|
+
};
|
|
307
|
+
const contentEditorGalleryToHtml = (block, ctx) => {
|
|
308
|
+
ctx.addStyles(CONTENT_EDITOR_GALLERY_HTML_STYLES);
|
|
309
|
+
return `<div class="ngs-content-editor-html-gallery" data-content-editor="gallery">${(block.content?.images ?? []).map(image => {
|
|
310
|
+
const src = ctx.safeUrl(image.src, 'image');
|
|
311
|
+
return src ? `<figure><img src="${ctx.escape(src)}" alt="${ctx.escape(image.alt)}" style="max-width:100%;height:auto">${contentEditorText(image.caption).trim() ? `<figcaption>${ctx.renderText(image.caption)}</figcaption>` : ''}</figure>` : '';
|
|
312
|
+
}).join('')}</div>`;
|
|
313
|
+
};
|
|
314
|
+
const contentEditorGridToHtml = (block, ctx) => {
|
|
315
|
+
const layout = contentEditorGridSettings(settings(block));
|
|
316
|
+
ctx.addStyles(CONTENT_EDITOR_GRID_HTML_STYLES);
|
|
317
|
+
const gap = { small: 12, medium: 24, large: 36 }[layout.gap];
|
|
318
|
+
return `<div class="ngs-content-editor-html-grid" style="--ngs-html-grid-columns:${layout.columns};--ngs-html-grid-gap:${gap}px"><div class="ngs-content-editor-html-grid-cells${layout.stackOnMobile ? ' ngs-content-editor-html-grid-stack' : ''}">${(block.content?.cells ?? []).map(cell => `<div class="ngs-content-editor-html-grid-cell">${ctx.renderBlocks(cell.blocks)}</div>`).join('')}</div></div>`;
|
|
319
|
+
};
|
|
320
|
+
const CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS = {
|
|
321
|
+
paragraph: contentEditorParagraphToHtml, heading: contentEditorHeadingToHtml,
|
|
322
|
+
code: contentEditorCodeToHtml, divider: contentEditorDividerToHtml,
|
|
323
|
+
bulletList: contentEditorListToHtml, orderedList: contentEditorListToHtml,
|
|
324
|
+
quote: contentEditorQuoteToHtml, table: contentEditorTableToHtml,
|
|
325
|
+
image: contentEditorImageToHtml, video: contentEditorVideoToHtml,
|
|
326
|
+
embed: contentEditorEmbedToHtml, callout: contentEditorCalloutToHtml,
|
|
327
|
+
toggle: contentEditorToggleToHtml, attachment: contentEditorAttachmentToHtml,
|
|
328
|
+
gallery: contentEditorGalleryToHtml, grid: contentEditorGridToHtml
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
function escapeContentEditorHtml(value) {
|
|
332
|
+
return String(value ?? '').replace(/[&<>"']/g, character => ({
|
|
333
|
+
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
|
334
|
+
})[character]);
|
|
335
|
+
}
|
|
336
|
+
function safeContentEditorHtmlUrl(value, kind = 'link') {
|
|
337
|
+
if (typeof value !== 'string')
|
|
338
|
+
return null;
|
|
339
|
+
const url = value.trim();
|
|
340
|
+
if (!url || /[\u0000-\u0020\u007f]/.test(url))
|
|
341
|
+
return null;
|
|
342
|
+
if (kind === 'link')
|
|
343
|
+
return normalizeNgsHeadlessEditorLink(url);
|
|
344
|
+
if (/^https?:/i.test(url) || !/^[a-z][a-z\d+.-]*:/i.test(url))
|
|
345
|
+
return url;
|
|
346
|
+
if (kind !== 'embed' && /^blob:https?:\/\//i.test(url))
|
|
347
|
+
return url;
|
|
348
|
+
if (kind === 'attachment' && /^(mailto:|tel:)/i.test(url))
|
|
349
|
+
return url;
|
|
350
|
+
const mime = kind === 'image' ? 'image/[a-z0-9.+-]+' : kind === 'media'
|
|
351
|
+
? '(?:audio|video)/[a-z0-9.+-]+' : kind === 'attachment'
|
|
352
|
+
? '(?:application/(?!xhtml\\+xml|xml|javascript)[a-z0-9.+-]+|text/(?:plain|csv)|(?:image|audio|video)/[a-z0-9.+-]+)' : null;
|
|
353
|
+
return mime && new RegExp(`^data:${mime};base64,[a-z0-9+/=]${kind === 'attachment' ? '*' : '+'}$`, 'i').test(url) ? url : null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const MARK_TAGS = {
|
|
357
|
+
bold: 'strong', italic: 'em', strike: 's', underline: 'u', code: 'code', superscript: 'sup', subscript: 'sub'
|
|
358
|
+
};
|
|
359
|
+
/** Pure document export: works without DOM, Angular DI, or a mounted editor. */
|
|
360
|
+
function contentEditorToHtml(document, config = {}) {
|
|
361
|
+
return serialize(document.blocks, config);
|
|
362
|
+
}
|
|
363
|
+
function contentEditorBlockToHtml(block, config = {}) {
|
|
364
|
+
return serialize([block], config);
|
|
365
|
+
}
|
|
366
|
+
function serialize(blocks, config) {
|
|
367
|
+
const styles = new Set();
|
|
368
|
+
const context = {
|
|
369
|
+
escape: escapeContentEditorHtml,
|
|
370
|
+
safeUrl: safeContentEditorHtmlUrl,
|
|
371
|
+
addStyles: css => { if (config.includeStyles !== false)
|
|
372
|
+
styles.add(css); },
|
|
373
|
+
renderBlock: block => {
|
|
374
|
+
const converter = config.blocks?.[block.type]?.toHtml ?? defaultConverter(block.type) ?? config.unknownBlockToHtml;
|
|
375
|
+
if (!converter)
|
|
376
|
+
throw new Error(`No HTML converter for Content Editor block "${block.type}".`);
|
|
377
|
+
return converter(block, context);
|
|
378
|
+
},
|
|
379
|
+
renderBlocks: children => children.map(context.renderBlock).join(''),
|
|
380
|
+
defaultToHtml: block => {
|
|
381
|
+
const converter = defaultConverter(block.type);
|
|
382
|
+
if (!converter)
|
|
383
|
+
throw new Error(`No default HTML converter for Content Editor block "${block.type}".`);
|
|
384
|
+
return converter(block, context);
|
|
385
|
+
},
|
|
386
|
+
renderText: text => renderText(text, context, config)
|
|
387
|
+
};
|
|
388
|
+
const html = context.renderBlocks(blocks);
|
|
389
|
+
return [...styles].map(css => `<style>${css}</style>`).join('') + html;
|
|
390
|
+
}
|
|
391
|
+
function renderText(text, ctx, config) {
|
|
392
|
+
if (!isNgsHeadlessEditorTextContent(text))
|
|
393
|
+
return '';
|
|
394
|
+
return text.map(run => run.marks.reduce((html, mark) => {
|
|
395
|
+
const override = config.marks && Object.hasOwn(config.marks, mark.type) ? config.marks[mark.type] : undefined;
|
|
396
|
+
return override ? override(html, mark, ctx) : renderMark(html, mark, ctx);
|
|
397
|
+
}, ctx.escape(run.text).replace(/\r\n|\r|\n/g, '<br>'))).join('');
|
|
398
|
+
}
|
|
399
|
+
function renderMark(html, mark, ctx) {
|
|
400
|
+
const tag = Object.hasOwn(MARK_TAGS, mark.type) ? MARK_TAGS[mark.type] : undefined;
|
|
401
|
+
if (tag)
|
|
402
|
+
return `<${tag}>${html}</${tag}>`;
|
|
403
|
+
if (mark.type === 'link') {
|
|
404
|
+
const href = ctx.safeUrl(mark.attrs?.['href']);
|
|
405
|
+
if (!href)
|
|
406
|
+
return html;
|
|
407
|
+
const target = mark.attrs?.['target'] === '_blank' ? '_blank' : '_self';
|
|
408
|
+
return `<a href="${ctx.escape(href)}" target="${target}" rel="noopener noreferrer">${html}</a>`;
|
|
414
409
|
}
|
|
415
|
-
|
|
416
|
-
|
|
410
|
+
if (mark.type === 'textColor' || mark.type === 'backgroundColor') {
|
|
411
|
+
const color = normalizeNgsHeadlessEditorColor(String(mark.attrs?.['color'] ?? ''));
|
|
412
|
+
return color ? `<span style="${mark.type === 'textColor' ? 'color' : 'background-color'}:${ctx.escape(color)}">${html}</span>` : html;
|
|
417
413
|
}
|
|
418
|
-
|
|
419
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.1.7", type: EditLinkDialog, isStandalone: true, selector: "ngs-edit-link", ngImport: i0, template: "<h1 ngs-dialog-title>Edit link</h1>\n<ngs-dialog-content [formGroup]=\"form\" class=\"!overflow-hidden\">\n <ngs-form-field class=\"w-full\">\n <ngs-label>Href (Url, Tel or other)</ngs-label>\n <input ngsInput type=\"text\" formControlName=\"href\">\n <ngs-hint>To delete the link, clear this field and apply</ngs-hint>\n </ngs-form-field>\n <ngs-slide-toggle formControlName=\"openInNewTab\" class=\"mt-5\">Open link in a new tab</ngs-slide-toggle>\n</ngs-dialog-content>\n<ngs-dialog-actions>\n <button ngsButton (click)=\"cancel()\">Cancel</button>\n <button ngsButton=\"filled\"\n [disabled]=\"form.invalid\" (click)=\"add()\">Apply</button>\n</ngs-dialog-actions>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1$1.DefaultValueAccessor, selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "component", type: Button, selector: " button[ngsButton], button[ngsIconButton], a[ngsButton], a[ngsIconButton] ", inputs: ["ngsButton", "ngsIconButton", "loading", "disabled", "disabledInteractive", "disableRipple", "reverse", "fullWidth", "hideTextOnMobile"], exportAs: ["ngsButton"] }, { kind: "component", type: DialogActions, selector: "ngs-dialog-actions, [ngs-dialog-actions], [ngsDialogActions]", inputs: ["align"] }, { kind: "component", type: DialogContent, selector: "ngs-dialog-content,[ngs-dialog-content],[ngsDialogContent]" }, { kind: "component", type: DialogTitle, selector: "ngs-dialog-title, [ngs-dialog-title], [ngsDialogTitle]", inputs: ["id"], exportAs: ["ngsDialogTitle"] }, { kind: "component", type: FormField, selector: "ngs-form-field", inputs: ["labelMode", "subscriptHiddenIfEmpty", "sameHeightAsButton"], exportAs: ["ngsFormField"] }, { kind: "directive", type: Input, selector: "input[ngsInput], textarea[ngsInput]", inputs: ["id", "placeholder", "required", "disabled", "readonly", "errorStateMatcher"], exportAs: ["ngsInput"] }, { kind: "component", type: Label, selector: "ngs-label" }, { kind: "component", type: SlideToggle, selector: "ngs-slide-toggle", inputs: ["id", "name", "labelPosition", "aria-label", "aria-labelledby", "aria-describedby", "required", "disabled", "disableRipple", "tabIndex", "hideIcon", "color", "checked"], outputs: ["disabledChange", "checkedChange", "change", "toggleChange"], exportAs: ["ngsSlideToggle"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1$1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: Hint, selector: "ngs-hint", inputs: ["align"], exportAs: ["ngsHint"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
414
|
+
return html;
|
|
420
415
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
416
|
+
function defaultConverter(type) {
|
|
417
|
+
return Object.hasOwn(CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS, type) ? CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS[type] : undefined;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Export saved documents with the current environment's shared configuration. */
|
|
421
|
+
class ContentEditorHtmlSerializer {
|
|
422
|
+
config = inject(CONTENT_EDITOR_CONFIG);
|
|
423
|
+
toHtml(document, config = {}) {
|
|
424
|
+
return contentEditorToHtml(document, mergeContentEditorConfig(this.config, config));
|
|
425
|
+
}
|
|
426
|
+
blockToHtml(block, config = {}) {
|
|
427
|
+
return contentEditorBlockToHtml(block, mergeContentEditorConfig(this.config, config));
|
|
428
|
+
}
|
|
429
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorHtmlSerializer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
430
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorHtmlSerializer, providedIn: 'root' });
|
|
431
|
+
}
|
|
432
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorHtmlSerializer, decorators: [{
|
|
433
|
+
type: Injectable,
|
|
434
|
+
args: [{ providedIn: 'root' }]
|
|
436
435
|
}] });
|
|
437
436
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
{
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
{
|
|
453
|
-
name: 'Gray',
|
|
454
|
-
color: '#7f7f7f',
|
|
455
|
-
type: 'text'
|
|
456
|
-
},
|
|
457
|
-
{
|
|
458
|
-
name: 'Brown',
|
|
459
|
-
color: '#ae2012',
|
|
460
|
-
type: 'text'
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
name: 'Orange',
|
|
464
|
-
color: '#fb5607',
|
|
465
|
-
type: 'text'
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
name: 'Yellow',
|
|
469
|
-
color: '#ffa200',
|
|
470
|
-
type: 'text'
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
name: 'Green',
|
|
474
|
-
color: '#40916c',
|
|
475
|
-
type: 'text'
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
name: 'Blue',
|
|
479
|
-
color: '#00bbf9',
|
|
480
|
-
type: 'text'
|
|
481
|
-
},
|
|
482
|
-
{
|
|
483
|
-
name: 'Purple',
|
|
484
|
-
color: '#907ad6',
|
|
485
|
-
type: 'text'
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
name: 'Pink',
|
|
489
|
-
color: '#fa3faf',
|
|
490
|
-
type: 'text'
|
|
491
|
-
},
|
|
492
|
-
{
|
|
493
|
-
name: 'Red',
|
|
494
|
-
color: '#ef233c',
|
|
495
|
-
type: 'text'
|
|
437
|
+
/** Nested renderers inherit per-instance configuration through their parent. */
|
|
438
|
+
const CONTENT_EDITOR_RENDER_CONFIG = new InjectionToken('CONTENT_EDITOR_RENDER_CONFIG');
|
|
439
|
+
const CONTENT_EDITOR_CONFIG = new InjectionToken('CONTENT_EDITOR_CONFIG', {
|
|
440
|
+
providedIn: 'root', factory: () => ({})
|
|
441
|
+
});
|
|
442
|
+
/** Later configurations override individual block fields, preserving unrelated options. */
|
|
443
|
+
function mergeContentEditorConfig(...configs) {
|
|
444
|
+
const result = { blocks: Object.create(null), marks: {} };
|
|
445
|
+
for (const config of configs) {
|
|
446
|
+
for (const [type, block] of Object.entries(config.blocks ?? {})) {
|
|
447
|
+
const previous = result.blocks[type];
|
|
448
|
+
result.blocks[type] = {
|
|
449
|
+
...previous, ...block, options: { ...previous?.options, ...block.options }
|
|
450
|
+
};
|
|
496
451
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
color: '#ffe0c0',
|
|
513
|
-
type: 'background'
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
name: 'Orange',
|
|
517
|
-
color: '#ffd8c6',
|
|
518
|
-
type: 'background'
|
|
519
|
-
},
|
|
520
|
-
{
|
|
521
|
-
name: 'Yellow',
|
|
522
|
-
color: '#fff3b0',
|
|
523
|
-
type: 'background'
|
|
524
|
-
},
|
|
525
|
-
{
|
|
526
|
-
name: 'Green',
|
|
527
|
-
color: '#eff6e0',
|
|
528
|
-
type: 'background'
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
name: 'Blue',
|
|
532
|
-
color: '#edf6f9',
|
|
533
|
-
type: 'background'
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
name: 'Purple',
|
|
537
|
-
color: '#e0aaff',
|
|
538
|
-
type: 'background'
|
|
539
|
-
},
|
|
452
|
+
result.marks = { ...result.marks, ...config.marks };
|
|
453
|
+
if (config.draft !== undefined)
|
|
454
|
+
result.draft = { ...result.draft, ...config.draft };
|
|
455
|
+
if (config.includeStyles !== undefined)
|
|
456
|
+
result.includeStyles = config.includeStyles;
|
|
457
|
+
if (config.importMarks !== undefined)
|
|
458
|
+
result.importMarks = config.importMarks;
|
|
459
|
+
if (config.unknownBlockToHtml !== undefined)
|
|
460
|
+
result.unknownBlockToHtml = config.unknownBlockToHtml;
|
|
461
|
+
}
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
464
|
+
/** Application or route environment configuration. Child environments inherit parent settings. */
|
|
465
|
+
function provideContentEditorConfig(config = {}) {
|
|
466
|
+
return makeEnvironmentProviders([
|
|
540
467
|
{
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
type: 'background'
|
|
468
|
+
provide: CONTENT_EDITOR_CONFIG,
|
|
469
|
+
useFactory: () => mergeContentEditorConfig(inject(CONTENT_EDITOR_CONFIG, { skipSelf: true, optional: true }) ?? {}, config)
|
|
544
470
|
},
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
else if (color.type === 'background') {
|
|
559
|
-
this.selectBackgroundColor(color);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
selectTextColor(color) {
|
|
563
|
-
this.selectedTextColor.set(color);
|
|
564
|
-
this.textColorChanged.emit(color.color);
|
|
565
|
-
this._addToRecently(color);
|
|
566
|
-
}
|
|
567
|
-
selectBackgroundColor(color) {
|
|
568
|
-
this.selectedBackgroundColor.set(color);
|
|
569
|
-
this.backgroundColorChanged.emit(color.color);
|
|
570
|
-
this._addToRecently(color);
|
|
471
|
+
ContentEditorHtmlSerializer,
|
|
472
|
+
ContentEditorImporter
|
|
473
|
+
]);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** Structured failure. The editor is never modified when parsing fails. */
|
|
477
|
+
class ContentEditorImportError extends Error {
|
|
478
|
+
path;
|
|
479
|
+
constructor(path, message) {
|
|
480
|
+
super(`${path}: ${message}`);
|
|
481
|
+
this.path = path;
|
|
482
|
+
this.name = 'ContentEditorImportError';
|
|
571
483
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
colors = colors.length >= 5 ? colors.slice(1, 5) : colors;
|
|
581
|
-
this.recentlyUsed.set([...colors, color]);
|
|
582
|
-
try {
|
|
583
|
-
this._document.defaultView?.localStorage.setItem('ngsContentEditorRecentlyUsedTextColor', JSON.stringify(this.recentlyUsed()));
|
|
584
|
-
}
|
|
585
|
-
catch {
|
|
586
|
-
// Keep the recent colors in memory when browser storage is unavailable.
|
|
587
|
-
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Parses and validates the native version-1 format without changing the caller's objects. */
|
|
487
|
+
function contentEditorFromJson(source, config = {}, options = {}) {
|
|
488
|
+
const maxDepth = options.maxDepth ?? 64;
|
|
489
|
+
const maxBlocks = options.maxBlocks ?? 10000;
|
|
490
|
+
if (!Number.isInteger(maxDepth) || maxDepth < 1 || !Number.isInteger(maxBlocks) || maxBlocks < 1) {
|
|
491
|
+
throw new ContentEditorImportError('$options', 'maxDepth and maxBlocks must be positive integers');
|
|
588
492
|
}
|
|
589
|
-
|
|
493
|
+
let value = source;
|
|
494
|
+
if (typeof source === 'string') {
|
|
590
495
|
try {
|
|
591
|
-
|
|
592
|
-
const colors = value ? JSON.parse(value) : [];
|
|
593
|
-
return Array.isArray(colors) ? colors : [];
|
|
496
|
+
value = JSON.parse(source);
|
|
594
497
|
}
|
|
595
498
|
catch {
|
|
596
|
-
|
|
499
|
+
throw new ContentEditorImportError('$', 'Invalid JSON');
|
|
597
500
|
}
|
|
598
501
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
openLinkDialog(edit) {
|
|
635
|
-
this.retainSelection();
|
|
636
|
-
const saved = this.savedSelection;
|
|
637
|
-
if (!saved)
|
|
502
|
+
const fail = (path, message) => { throw new ContentEditorImportError(path, message); };
|
|
503
|
+
const ancestors = new Set();
|
|
504
|
+
const copy = (input, path, depth) => {
|
|
505
|
+
if (depth > maxDepth)
|
|
506
|
+
fail(path, `Maximum nesting depth (${maxDepth}) exceeded`);
|
|
507
|
+
if (input === null || typeof input === 'string' || typeof input === 'boolean')
|
|
508
|
+
return input;
|
|
509
|
+
if (typeof input === 'number' && Number.isFinite(input))
|
|
510
|
+
return input;
|
|
511
|
+
if (!input || typeof input !== 'object')
|
|
512
|
+
return fail(path, 'Expected a JSON-compatible value');
|
|
513
|
+
if (ancestors.has(input))
|
|
514
|
+
fail(path, 'Cyclic data is not supported');
|
|
515
|
+
if (!Array.isArray(input) && ![Object.prototype, null].includes(Object.getPrototypeOf(input)))
|
|
516
|
+
fail(path, 'Expected a plain JSON object');
|
|
517
|
+
ancestors.add(input);
|
|
518
|
+
const output = Array.isArray(input)
|
|
519
|
+
? Array.from(input, (item, i) => copy(item, `${path}[${i}]`, depth + 1))
|
|
520
|
+
: Object.fromEntries(Object.entries(input).filter(([, item]) => item !== undefined).map(([key, item]) => [key, copy(item, `${path}.${key}`, depth + 1)]));
|
|
521
|
+
ancestors.delete(input);
|
|
522
|
+
return output;
|
|
523
|
+
};
|
|
524
|
+
const object = (input, path) => {
|
|
525
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input))
|
|
526
|
+
fail(path, 'Expected an object');
|
|
527
|
+
return input;
|
|
528
|
+
};
|
|
529
|
+
const array = (input, path) => { if (!Array.isArray(input))
|
|
530
|
+
fail(path, 'Expected an array'); return input; };
|
|
531
|
+
const string = (input, path, nonempty = false) => {
|
|
532
|
+
if (typeof input !== 'string' || (nonempty && !input.trim()))
|
|
533
|
+
fail(path, nonempty ? 'Expected a non-empty string' : 'Expected a string');
|
|
534
|
+
};
|
|
535
|
+
const props = (input, path) => {
|
|
536
|
+
if (input === undefined)
|
|
638
537
|
return;
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
: this.dialog.open(AddLinkDialog, { width: '500px', restoreFocus: false });
|
|
644
|
-
ref.afterClosed().subscribe((value) => {
|
|
645
|
-
if (!this.restoreSelection())
|
|
646
|
-
return;
|
|
647
|
-
if (value) {
|
|
648
|
-
if (value.href)
|
|
649
|
-
this.editor.execute(NGS_HEADLESS_EDITOR_SET_LINK, { href: value.href, target: value.openInNewTab ? '_blank' : '_self' });
|
|
650
|
-
else
|
|
651
|
-
this.editor.execute(NGS_HEADLESS_EDITOR_UNSET_LINK);
|
|
652
|
-
}
|
|
653
|
-
this.restoreSelectionAfterOverlay();
|
|
538
|
+
array(input, path).forEach((prop, i) => {
|
|
539
|
+
object(prop, `${path}[${i}]`);
|
|
540
|
+
string(prop.name, `${path}[${i}].name`, true);
|
|
541
|
+
string(prop.value, `${path}[${i}].value`);
|
|
654
542
|
});
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
// Restore the editor afterwards, using model points rather than old DOM nodes.
|
|
681
|
-
Promise.resolve().then(() => {
|
|
682
|
-
const region = this.restoreSelection();
|
|
683
|
-
this.savedSelection = null;
|
|
684
|
-
if (region && this.observedElement()?.isConnected)
|
|
685
|
-
region.focus();
|
|
543
|
+
};
|
|
544
|
+
const runs = (input, path) => {
|
|
545
|
+
array(input, path).forEach((run, i) => {
|
|
546
|
+
const p = `${path}[${i}]`;
|
|
547
|
+
object(run, p);
|
|
548
|
+
if (run.type !== 'text')
|
|
549
|
+
fail(`${p}.type`, 'Expected "text"');
|
|
550
|
+
string(run.text, `${p}.text`);
|
|
551
|
+
array(run.marks, `${p}.marks`).forEach((mark, j) => {
|
|
552
|
+
const m = `${p}.marks[${j}]`;
|
|
553
|
+
object(mark, m);
|
|
554
|
+
string(mark.type, `${m}.type`, true);
|
|
555
|
+
if (mark.attrs !== undefined) {
|
|
556
|
+
for (const [key, attr] of Object.entries(object(mark.attrs, `${m}.attrs`))) {
|
|
557
|
+
if (attr !== null && !['string', 'number', 'boolean'].includes(typeof attr))
|
|
558
|
+
fail(`${m}.attrs.${key}`, 'Expected a scalar mark attribute');
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (mark.type === 'link' && !safeContentEditorHtmlUrl(mark.attrs?.href))
|
|
562
|
+
fail(`${m}.attrs.href`, 'Expected a supported non-empty link URL');
|
|
563
|
+
if (mark.type === 'link')
|
|
564
|
+
enumValue(mark.attrs?.target, ['_blank', '_self'], `${m}.attrs.target`);
|
|
565
|
+
if (['textColor', 'backgroundColor'].includes(mark.type) && (typeof mark.attrs?.color !== 'string' || !normalizeNgsHeadlessEditorColor(mark.attrs.color)))
|
|
566
|
+
fail(`${m}.attrs.color`, 'Expected a supported CSS color');
|
|
567
|
+
});
|
|
686
568
|
});
|
|
687
|
-
}
|
|
688
|
-
preventMenuClose(event) { event.stopPropagation(); event.preventDefault(); }
|
|
689
|
-
onTextColorChanged(color) {
|
|
690
|
-
const region = this.restoreSelection();
|
|
691
|
-
if (!region)
|
|
692
|
-
return;
|
|
693
|
-
if (color)
|
|
694
|
-
this.editor.execute(NGS_HEADLESS_EDITOR_SET_TEXT_COLOR, color);
|
|
695
|
-
else
|
|
696
|
-
this.editor.execute(NGS_HEADLESS_EDITOR_UNSET_TEXT_COLOR);
|
|
697
|
-
region.focus();
|
|
698
|
-
}
|
|
699
|
-
onBackgroundColorChanged(color) {
|
|
700
|
-
const region = this.restoreSelection();
|
|
701
|
-
if (!region)
|
|
702
|
-
return;
|
|
703
|
-
if (color)
|
|
704
|
-
this.editor.execute(NGS_HEADLESS_EDITOR_SET_BACKGROUND_COLOR, color);
|
|
705
|
-
else
|
|
706
|
-
this.editor.execute(NGS_HEADLESS_EDITOR_UNSET_BACKGROUND_COLOR);
|
|
707
|
-
region.focus();
|
|
708
|
-
}
|
|
709
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: CommandBarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
710
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: CommandBarComponent, isStandalone: true, selector: "ngs-command-bar", inputs: { observedElement: { classPropertyName: "observedElement", publicName: "observedElement", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "mousedown": "preserveSelection($event)" }, classAttribute: "ngs-command-bar" }, ngImport: i0, template: "<div class=\"flex items-center gap-1\">\n <button ngsIconButton (click)=\"toggleBold()\"\n [class.is-active]=\"isActive('strong')\">\n <ngs-icon name=\"fluent:text-bold-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleItalic()\"\n [class.is-active]=\"isActive('em')\">\n <ngs-icon name=\"fluent:text-italic-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleStrike()\"\n [class.is-active]=\"isActive('s')\">\n <ngs-icon name=\"fluent:text-strikethrough-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleUnderline()\"\n [class.is-active]=\"isActive('u')\">\n <ngs-icon name=\"fluent:text-underline-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleSuperscript()\"\n [class.is-active]=\"isActive('sup')\">\n <ngs-icon name=\"fluent:text-superscript-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleSubscript()\"\n [class.is-active]=\"isActive('sub')\">\n <ngs-icon name=\"fluent:text-subscript-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleCode()\"\n [class.is-active]=\"isActive('code')\">\n <ngs-icon name=\"fluent:code-24-regular\"/>\n </button>\n\n @if (isLinkActive()) {\n <button ngsIconButton (click)=\"editLink()\">\n <ngs-icon name=\"fluent:link-24-regular\"/>\n </button>\n } @else {\n <button ngsIconButton (click)=\"addLink()\">\n <ngs-icon name=\"fluent:link-add-24-regular\"/>\n </button>\n }\n <button ngsIconButton [ngsMenuTriggerFor]=\"alignMenu\"\n (menuOpened)=\"retainSelection()\" (menuClosed)=\"restoreSelectionAfterOverlay()\">\n @switch (alignment()) {\n @case ('left') {\n <ngs-icon name=\"fluent:text-align-left-24-regular\"/>\n }\n @case ('center') {\n <ngs-icon name=\"fluent:text-align-center-24-regular\"/>\n }\n @case ('right') {\n <ngs-icon name=\"fluent:text-align-right-24-regular\"/>\n }\n }\n </button>\n <button ngsIconButton [ngsMenuTriggerFor]=\"formatColorText\"\n (menuOpened)=\"retainSelection()\" (menuClosed)=\"restoreSelectionAfterOverlay()\">\n <ngs-icon name=\"fluent:text-color-24-regular\"/>\n </button>\n</div>\n\n<ngs-menu #alignMenu=\"ngsMenu\">\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('left')\"\n ngs-menu-item\n (click)=\"setTextAlignment('left')\">\n <ngs-icon name=\"fluent:text-align-left-24-regular\"/>\n Align Left\n </button>\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('center')\"\n ngs-menu-item\n (click)=\"setTextAlignment('center')\">\n <ngs-icon name=\"fluent:text-align-center-24-regular\"/>\n Align Center\n </button>\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('right')\"\n ngs-menu-item (click)=\"setTextAlignment('right')\">\n <ngs-icon name=\"fluent:text-align-right-24-regular\"/>\n Align Right\n </button>\n</ngs-menu>\n\n<ngs-menu #formatColorText=\"ngsMenu\">\n <div class=\"px-4 py-3\" (mousedown)=\"preventMenuClose($event)\">\n <ngs-text-color (textColorChanged)=\"onTextColorChanged($event)\"\n (backgroundColorChanged)=\"onBackgroundColorChanged($event)\"/>\n </div>\n</ngs-menu>\n", styles: [":host{background:var(--ngs-color-on-surface);color:var(--ngs-color-surface);border-radius:calc(var(--spacing, .25rem) * 3);padding:var(--spacing, .25rem);box-shadow:var(--ngs-shadow-lg)}:host button[ngsIconButton]{--ngs-button-color: var(--ngs-color-surface);--ngs-button-hover-bg: var(--ngs-color-surface);--ngs-state-focus-ring: var(--ngs-color-surface)}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton]{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-color-surface) 12%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton]{--ngs-state-focus-ring: color-mix(in srgb, var(--ngs-color-surface) 40%, transparent)}}:host button[ngsIconButton].is-active{--ngs-button-bg: var(--ngs-color-surface);--ngs-button-hover-bg: var(--ngs-color-surface)}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].is-active{--ngs-button-bg: color-mix(in srgb, var(--ngs-color-surface) 20%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].is-active{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-color-surface) 28%, transparent)}}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "component", type: Button, selector: " button[ngsButton], button[ngsIconButton], a[ngsButton], a[ngsIconButton] ", inputs: ["ngsButton", "ngsIconButton", "loading", "disabled", "disabledInteractive", "disableRipple", "reverse", "fullWidth", "hideTextOnMobile"], exportAs: ["ngsButton"] }, { kind: "component", type: Icon, selector: "ngs-icon", inputs: ["name"], exportAs: ["ngsIcon"] }, { kind: "component", type: Menu, selector: "ngs-menu", inputs: ["role", "classList", "xPosition", "yPosition", "pushIntoViewport"], outputs: ["closed"], exportAs: ["ngsMenu"] }, { kind: "component", type: MenuItem, selector: "ngs-menu-item, [ngs-menu-item]", inputs: ["disabled", "role", "selected"], outputs: ["_triggered"], exportAs: ["ngsMenuItem"] }, { kind: "directive", type: MenuTrigger, selector: "[ngsMenuTriggerFor]", inputs: ["ngsMenuTriggerFor", "ngsMenuTriggerData", "ngsMenuDisabled", "xPosition", "yPosition", "ngsMenuTriggerRestoreFocus"], outputs: ["menuOpened", "menuClosed"], exportAs: ["ngsMenuTrigger"] }, { kind: "component", type: TextColorComponent, selector: "ngs-text-color", inputs: ["recentlyUsed", "selectedTextColor", "selectedBackgroundColor", "textColors", "backgroundColors"], outputs: ["recentlyUsedChange", "selectedTextColorChange", "selectedBackgroundColorChange", "textColorChanged", "backgroundColorChanged"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
711
|
-
}
|
|
712
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: CommandBarComponent, decorators: [{
|
|
713
|
-
type: Component,
|
|
714
|
-
args: [{ selector: 'ngs-command-bar', imports: [Button, Icon, Menu, MenuItem, MenuTrigger, TextColorComponent], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
715
|
-
'class': 'ngs-command-bar',
|
|
716
|
-
'(mousedown)': 'preserveSelection($event)'
|
|
717
|
-
}, template: "<div class=\"flex items-center gap-1\">\n <button ngsIconButton (click)=\"toggleBold()\"\n [class.is-active]=\"isActive('strong')\">\n <ngs-icon name=\"fluent:text-bold-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleItalic()\"\n [class.is-active]=\"isActive('em')\">\n <ngs-icon name=\"fluent:text-italic-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleStrike()\"\n [class.is-active]=\"isActive('s')\">\n <ngs-icon name=\"fluent:text-strikethrough-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleUnderline()\"\n [class.is-active]=\"isActive('u')\">\n <ngs-icon name=\"fluent:text-underline-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleSuperscript()\"\n [class.is-active]=\"isActive('sup')\">\n <ngs-icon name=\"fluent:text-superscript-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleSubscript()\"\n [class.is-active]=\"isActive('sub')\">\n <ngs-icon name=\"fluent:text-subscript-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleCode()\"\n [class.is-active]=\"isActive('code')\">\n <ngs-icon name=\"fluent:code-24-regular\"/>\n </button>\n\n @if (isLinkActive()) {\n <button ngsIconButton (click)=\"editLink()\">\n <ngs-icon name=\"fluent:link-24-regular\"/>\n </button>\n } @else {\n <button ngsIconButton (click)=\"addLink()\">\n <ngs-icon name=\"fluent:link-add-24-regular\"/>\n </button>\n }\n <button ngsIconButton [ngsMenuTriggerFor]=\"alignMenu\"\n (menuOpened)=\"retainSelection()\" (menuClosed)=\"restoreSelectionAfterOverlay()\">\n @switch (alignment()) {\n @case ('left') {\n <ngs-icon name=\"fluent:text-align-left-24-regular\"/>\n }\n @case ('center') {\n <ngs-icon name=\"fluent:text-align-center-24-regular\"/>\n }\n @case ('right') {\n <ngs-icon name=\"fluent:text-align-right-24-regular\"/>\n }\n }\n </button>\n <button ngsIconButton [ngsMenuTriggerFor]=\"formatColorText\"\n (menuOpened)=\"retainSelection()\" (menuClosed)=\"restoreSelectionAfterOverlay()\">\n <ngs-icon name=\"fluent:text-color-24-regular\"/>\n </button>\n</div>\n\n<ngs-menu #alignMenu=\"ngsMenu\">\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('left')\"\n ngs-menu-item\n (click)=\"setTextAlignment('left')\">\n <ngs-icon name=\"fluent:text-align-left-24-regular\"/>\n Align Left\n </button>\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('center')\"\n ngs-menu-item\n (click)=\"setTextAlignment('center')\">\n <ngs-icon name=\"fluent:text-align-center-24-regular\"/>\n Align Center\n </button>\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('right')\"\n ngs-menu-item (click)=\"setTextAlignment('right')\">\n <ngs-icon name=\"fluent:text-align-right-24-regular\"/>\n Align Right\n </button>\n</ngs-menu>\n\n<ngs-menu #formatColorText=\"ngsMenu\">\n <div class=\"px-4 py-3\" (mousedown)=\"preventMenuClose($event)\">\n <ngs-text-color (textColorChanged)=\"onTextColorChanged($event)\"\n (backgroundColorChanged)=\"onBackgroundColorChanged($event)\"/>\n </div>\n</ngs-menu>\n", styles: [":host{background:var(--ngs-color-on-surface);color:var(--ngs-color-surface);border-radius:calc(var(--spacing, .25rem) * 3);padding:var(--spacing, .25rem);box-shadow:var(--ngs-shadow-lg)}:host button[ngsIconButton]{--ngs-button-color: var(--ngs-color-surface);--ngs-button-hover-bg: var(--ngs-color-surface);--ngs-state-focus-ring: var(--ngs-color-surface)}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton]{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-color-surface) 12%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton]{--ngs-state-focus-ring: color-mix(in srgb, var(--ngs-color-surface) 40%, transparent)}}:host button[ngsIconButton].is-active{--ngs-button-bg: var(--ngs-color-surface);--ngs-button-hover-bg: var(--ngs-color-surface)}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].is-active{--ngs-button-bg: color-mix(in srgb, var(--ngs-color-surface) 20%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].is-active{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-color-surface) 28%, transparent)}}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
718
|
-
}], propDecorators: { observedElement: [{ type: i0.Input, args: [{ isSignal: true, alias: "observedElement", required: false }] }] } });
|
|
719
|
-
|
|
720
|
-
const CONTENT_BUILDER = new InjectionToken('CONTENT_BUILDER');
|
|
721
|
-
const CONTENT_EDITOR_BLOCK = new InjectionToken('CONTENT_EDITOR_BLOCK');
|
|
722
|
-
|
|
723
|
-
/** Shared marks and commands for content editing and read-only rendering. */
|
|
724
|
-
function provideContentEditor() {
|
|
725
|
-
return provideNgsHeadlessEditor(withHeadlessEditorPlugin(basicTextEditorPlugin()), withHeadlessEditorPlugin(colorEditorPlugin()), withHeadlessEditorPlugin(linkEditorPlugin()));
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
function getTextAlignment(props) {
|
|
729
|
-
const value = props?.find(prop => prop.name === 'text-alignment')?.value;
|
|
730
|
-
if (value === 'center' || value === 'right' || value === 'justify') {
|
|
731
|
-
return value;
|
|
732
|
-
}
|
|
733
|
-
return 'left';
|
|
734
|
-
}
|
|
735
|
-
function getDimensionAttribute(value) {
|
|
736
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
737
|
-
return value;
|
|
738
|
-
}
|
|
739
|
-
if (typeof value === 'string') {
|
|
740
|
-
const trimmed = value.trim();
|
|
741
|
-
if (!trimmed || trimmed === 'auto') {
|
|
742
|
-
return null;
|
|
743
|
-
}
|
|
744
|
-
const parsed = Number.parseFloat(trimmed);
|
|
745
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
746
|
-
}
|
|
747
|
-
return null;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/** Defaults shared by editing and read-only layout. */
|
|
751
|
-
function contentEditorGridSettings(settings) {
|
|
752
|
-
return {
|
|
753
|
-
columns: settings.columns === 3 || settings.columns === 4 ? settings.columns : 2,
|
|
754
|
-
gap: settings.gap === 'small' || settings.gap === 'large' ? settings.gap : 'medium',
|
|
755
|
-
stackOnMobile: settings.stackOnMobile !== false
|
|
756
569
|
};
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
const CONTENT_EDITOR_GRID_HTML_STYLES = `.ngs-content-editor-html-grid{container-type:inline-size}.ngs-content-editor-html-grid-cells{display:grid;grid-template-columns:repeat(var(--ngs-html-grid-columns),minmax(0,1fr));gap:var(--ngs-html-grid-gap)}.ngs-content-editor-html-grid-cell{min-width:0}@container(max-width:480px){.ngs-content-editor-html-grid-stack{grid-template-columns:minmax(0,1fr)}}`;
|
|
761
|
-
const CONTENT_EDITOR_CALLOUT_HTML_STYLES = `.ngs-content-editor-html-callout{padding:16px;border-radius:8px;background:var(--ngs-color-primary-container,#eef3ff);color:var(--ngs-color-on-surface,#172033)}.ngs-content-editor-html-callout[data-callout=tip]{background:var(--ngs-color-success-container,#e8f5ee)}.ngs-content-editor-html-callout[data-callout=warning]{background:var(--ngs-color-warning-container,#fff3dc)}.ngs-content-editor-html-callout[data-callout=danger]{background:var(--ngs-color-danger-container,#fdeaea)}`;
|
|
762
|
-
const CONTENT_EDITOR_GALLERY_HTML_STYLES = `.ngs-content-editor-html-gallery{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;gap:16px}.ngs-content-editor-html-gallery>figure{flex:0 0 100%;min-width:0;margin:0;scroll-snap-align:start}.ngs-content-editor-html-gallery img{display:block;width:100%}`;
|
|
763
|
-
function settings(block) { return block.attrs?.['settings'] ?? {}; }
|
|
764
|
-
function alignment(props) {
|
|
765
|
-
const align = getTextAlignment(props);
|
|
766
|
-
return align === 'left' ? '' : ` style="text-align:${align}"`;
|
|
767
|
-
}
|
|
768
|
-
function dimension(name, value) {
|
|
769
|
-
const number = getDimensionAttribute(value);
|
|
770
|
-
return number !== null && number > 0 ? ` ${name}="${Math.round(number)}"` : '';
|
|
771
|
-
}
|
|
772
|
-
const contentEditorParagraphToHtml = (block, ctx) => `<p${alignment(block.attrs?.['props'])}>${ctx.renderText(block.content)}</p>`;
|
|
773
|
-
const contentEditorHeadingToHtml = (block, ctx) => {
|
|
774
|
-
const value = settings(block)['level'];
|
|
775
|
-
const level = Number.isInteger(value) && value >= 1 && value <= 6 ? value : 2;
|
|
776
|
-
return `<h${level}${alignment(block.attrs?.['props'])}>${ctx.renderText(block.content)}</h${level}>`;
|
|
777
|
-
};
|
|
778
|
-
const contentEditorCodeToHtml = (block, ctx) => `<pre><code data-language="${ctx.escape(settings(block)['language'] ?? 'none')}">${ctx.escape(contentEditorText(block.content))}</code></pre>`;
|
|
779
|
-
const contentEditorDividerToHtml = () => '<hr>';
|
|
780
|
-
const contentEditorListToHtml = (block, ctx) => {
|
|
781
|
-
const tag = block.type === 'orderedList' ? 'ol' : 'ul';
|
|
782
|
-
const list = (items) => `<${tag}>${items.map(item => `<li${alignment(item.props)}>${ctx.renderText(item.content)}${item.children?.length ? list(item.children) : ''}</li>`).join('')}</${tag}>`;
|
|
783
|
-
return list(block.content ?? []);
|
|
784
|
-
};
|
|
785
|
-
const contentEditorQuoteToHtml = (block, ctx) => {
|
|
786
|
-
const quote = block.content?.cite;
|
|
787
|
-
const caption = block.content?.caption;
|
|
788
|
-
return `<figure><blockquote${alignment(quote?.props)}>${ctx.renderText(quote?.content ?? [])}</blockquote>${contentEditorText(caption?.content).trim() ? `<figcaption${alignment(caption.props)}>${ctx.renderText(caption.content)}</figcaption>` : ''}</figure>`;
|
|
789
|
-
};
|
|
790
|
-
const contentEditorTableToHtml = (block, ctx) => {
|
|
791
|
-
const table = getNgsHeadlessEditorTableData(block);
|
|
792
|
-
const metadata = block.attrs?.['cellMetadata'];
|
|
793
|
-
const rows = table.rows.map((row, r) => `<tr>${row.map((runs, c) => {
|
|
794
|
-
const tag = r === 0 && table.header ? 'th' : 'td';
|
|
795
|
-
const cell = metadata?.[r]?.[c];
|
|
796
|
-
return `<${tag}${dimension('colspan', cell?.options?.['colspan'])}${dimension('rowspan', cell?.options?.['rowspan'])}${dimension('width', cell?.options?.['width'])}${alignment(cell?.props)}>${ctx.renderText(runs)}</${tag}>`;
|
|
797
|
-
}).join('')}</tr>`).join('');
|
|
798
|
-
return `<table><tbody>${rows}</tbody></table>`;
|
|
799
|
-
};
|
|
800
|
-
const contentEditorImageToHtml = (block, ctx) => {
|
|
801
|
-
const src = ctx.safeUrl(block.content?.src, 'image');
|
|
802
|
-
if (!src)
|
|
803
|
-
return '';
|
|
804
|
-
const alt = block.content?.alt ?? '';
|
|
805
|
-
const config = settings(block);
|
|
806
|
-
return `<figure><img src="${ctx.escape(src)}" alt="${ctx.escape(alt)}"${dimension('width', config['width'])}${dimension('height', config['height'])} style="max-width:100%;height:auto">${alt ? `<figcaption>${ctx.escape(alt)}</figcaption>` : ''}</figure>`;
|
|
807
|
-
};
|
|
808
|
-
const contentEditorVideoToHtml = (block, ctx) => {
|
|
809
|
-
const src = ctx.safeUrl(block.content?.src, 'media');
|
|
810
|
-
if (!src)
|
|
811
|
-
return '';
|
|
812
|
-
const config = settings(block);
|
|
813
|
-
return `<figure><video src="${ctx.escape(src)}" controls${dimension('width', config['width'])}${dimension('height', config['height'])} style="max-width:100%"></video>${block.content?.caption ? `<figcaption>${ctx.escape(block.content.caption)}</figcaption>` : ''}</figure>`;
|
|
814
|
-
};
|
|
815
|
-
const contentEditorEmbedToHtml = (block, ctx) => {
|
|
816
|
-
const src = ctx.safeUrl(block.content?.url, 'embed');
|
|
817
|
-
if (!src)
|
|
818
|
-
return '';
|
|
819
|
-
const config = settings(block);
|
|
820
|
-
return `<figure><iframe src="${ctx.escape(src)}" title="${ctx.escape(block.content?.type || 'Embedded content')}"${dimension('width', config['width'] ?? 700)}${dimension('height', config['height'] ?? 400)} style="max-width:100%" allowfullscreen></iframe></figure>`;
|
|
821
|
-
};
|
|
822
|
-
const contentEditorCalloutToHtml = (block, ctx) => {
|
|
823
|
-
ctx.addStyles(CONTENT_EDITOR_CALLOUT_HTML_STYLES);
|
|
824
|
-
const value = settings(block)['variant'];
|
|
825
|
-
const variant = ['note', 'tip', 'warning', 'danger'].includes(value) ? value : 'note';
|
|
826
|
-
return `<aside class="ngs-content-editor-html-callout" data-callout="${variant}"${alignment(block.attrs?.['props'])}>${ctx.renderText(block.content)}</aside>`;
|
|
827
|
-
};
|
|
828
|
-
const contentEditorToggleToHtml = (block, ctx) => `<details${settings(block)['expanded'] ? ' open' : ''}><summary>${ctx.renderText(block.content?.title ?? [])}</summary>${ctx.renderBlocks(block.content?.blocks ?? [])}</details>`;
|
|
829
|
-
const contentEditorAttachmentToHtml = (block, ctx) => {
|
|
830
|
-
const url = ctx.safeUrl(block.content?.url, 'attachment');
|
|
831
|
-
return url ? `<a href="${ctx.escape(url)}" download="${ctx.escape(block.content?.name)}">${ctx.escape(block.content?.name || 'Download')}</a>` : '';
|
|
832
|
-
};
|
|
833
|
-
const contentEditorGalleryToHtml = (block, ctx) => {
|
|
834
|
-
ctx.addStyles(CONTENT_EDITOR_GALLERY_HTML_STYLES);
|
|
835
|
-
return `<div class="ngs-content-editor-html-gallery" data-content-editor="gallery">${(block.content?.images ?? []).map(image => {
|
|
836
|
-
const src = ctx.safeUrl(image.src, 'image');
|
|
837
|
-
return src ? `<figure><img src="${ctx.escape(src)}" alt="${ctx.escape(image.alt)}" style="max-width:100%;height:auto">${contentEditorText(image.caption).trim() ? `<figcaption>${ctx.renderText(image.caption)}</figcaption>` : ''}</figure>` : '';
|
|
838
|
-
}).join('')}</div>`;
|
|
839
|
-
};
|
|
840
|
-
const contentEditorGridToHtml = (block, ctx) => {
|
|
841
|
-
const layout = contentEditorGridSettings(settings(block));
|
|
842
|
-
ctx.addStyles(CONTENT_EDITOR_GRID_HTML_STYLES);
|
|
843
|
-
const gap = { small: 12, medium: 24, large: 36 }[layout.gap];
|
|
844
|
-
return `<div class="ngs-content-editor-html-grid" style="--ngs-html-grid-columns:${layout.columns};--ngs-html-grid-gap:${gap}px"><div class="ngs-content-editor-html-grid-cells${layout.stackOnMobile ? ' ngs-content-editor-html-grid-stack' : ''}">${(block.content?.cells ?? []).map(cell => `<div class="ngs-content-editor-html-grid-cell">${ctx.renderBlocks(cell.blocks)}</div>`).join('')}</div></div>`;
|
|
845
|
-
};
|
|
846
|
-
const CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS = {
|
|
847
|
-
paragraph: contentEditorParagraphToHtml, heading: contentEditorHeadingToHtml,
|
|
848
|
-
code: contentEditorCodeToHtml, divider: contentEditorDividerToHtml,
|
|
849
|
-
bulletList: contentEditorListToHtml, orderedList: contentEditorListToHtml,
|
|
850
|
-
quote: contentEditorQuoteToHtml, table: contentEditorTableToHtml,
|
|
851
|
-
image: contentEditorImageToHtml, video: contentEditorVideoToHtml,
|
|
852
|
-
embed: contentEditorEmbedToHtml, callout: contentEditorCalloutToHtml,
|
|
853
|
-
toggle: contentEditorToggleToHtml, attachment: contentEditorAttachmentToHtml,
|
|
854
|
-
gallery: contentEditorGalleryToHtml, grid: contentEditorGridToHtml
|
|
855
|
-
};
|
|
856
|
-
|
|
857
|
-
const CONTENT_EDITOR_EXTRA_BLOCK_DEFS = [
|
|
858
|
-
{
|
|
859
|
-
type: 'callout', component: () => import('./ngstarter-ui-components-content-editor-callout-block-Jbf8h2yz.mjs').then(m => m.ContentEditorCalloutBlock),
|
|
860
|
-
empty: () => ({ content: [createNgsHeadlessEditorText()], settings: { variant: 'note' } }), options: {}
|
|
861
|
-
},
|
|
862
|
-
{
|
|
863
|
-
type: 'toggle', component: () => import('./ngstarter-ui-components-content-editor-toggle-block-B46YeMGQ.mjs').then(m => m.ContentEditorToggleBlock),
|
|
864
|
-
empty: () => ({ content: { title: [], blocks: [emptyParagraph()] }, settings: { expanded: true } }), options: {}
|
|
865
|
-
},
|
|
866
|
-
{
|
|
867
|
-
type: 'attachment', component: () => import('./ngstarter-ui-components-content-editor-attachment-block-DlUkhwCu.mjs').then(m => m.ContentEditorAttachmentBlock),
|
|
868
|
-
empty: () => ({ content: { url: '', name: '', size: 0, mimeType: '' }, settings: {} }),
|
|
869
|
-
options: { uploadFn: (_file, dataUrl) => Promise.resolve(dataUrl) }
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
type: 'gallery', component: () => import('./ngstarter-ui-components-content-editor-gallery-block-C4p-S0Do.mjs').then(m => m.ContentEditorGalleryBlock),
|
|
873
|
-
empty: () => ({ content: { images: [] }, settings: {} }),
|
|
874
|
-
options: { uploadFn: (_file, dataUrl) => Promise.resolve(dataUrl) }
|
|
875
|
-
},
|
|
876
|
-
{
|
|
877
|
-
type: 'grid', component: () => import('./ngstarter-ui-components-content-editor-grid-block-Cdq_Dcv2.mjs').then(m => m.ContentEditorGridBlock),
|
|
878
|
-
empty: () => ({ content: { cells: Array.from({ length: 4 }, emptyGridCell) }, settings: { columns: 2, gap: 'medium', stackOnMobile: true } }), options: {}
|
|
879
|
-
}
|
|
880
|
-
].map(def => ({ ...def, toHtml: CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS[def.type] }));
|
|
881
|
-
function emptyParagraph() {
|
|
882
|
-
return { id: createNgsHeadlessEditorId('paragraph'), type: 'paragraph', content: [createNgsHeadlessEditorText()] };
|
|
883
|
-
}
|
|
884
|
-
function emptyGridCell() { return { id: createNgsHeadlessEditorId('cell'), blocks: [emptyParagraph()] }; }
|
|
885
|
-
const CONTENT_EDITOR_EXTRA_SUGGESTIONS = [
|
|
886
|
-
{ type: 'heading', title: 'Content & layout' },
|
|
887
|
-
...[
|
|
888
|
-
['callout', 'Callout', 'Notes, tips and warnings', 'fluent:info-24-regular'],
|
|
889
|
-
['toggle', 'Toggle', 'Collapsible content with nested blocks', 'fluent:chevron-down-24-regular'],
|
|
890
|
-
['attachment', 'Attachment', 'Upload a file for download', 'fluent:attach-24-regular'],
|
|
891
|
-
['gallery', 'Gallery', 'Image carousel with captions', 'fluent:image-multiple-24-regular'],
|
|
892
|
-
['grid', 'Grid', 'Responsive grid with nested blocks', 'fluent:grid-24-regular']
|
|
893
|
-
].map(([blockType, title, description, iconName]) => ({ type: 'item', blockType, title, description, iconName, blockSettings: {} }))
|
|
894
|
-
];
|
|
895
|
-
|
|
896
|
-
function escapeContentEditorHtml(value) {
|
|
897
|
-
return String(value ?? '').replace(/[&<>"']/g, character => ({
|
|
898
|
-
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
|
899
|
-
})[character]);
|
|
900
|
-
}
|
|
901
|
-
function safeContentEditorHtmlUrl(value, kind = 'link') {
|
|
902
|
-
if (typeof value !== 'string')
|
|
903
|
-
return null;
|
|
904
|
-
const url = value.trim();
|
|
905
|
-
if (!url || /[\u0000-\u0020\u007f]/.test(url))
|
|
906
|
-
return null;
|
|
907
|
-
if (kind === 'link')
|
|
908
|
-
return normalizeNgsHeadlessEditorLink(url);
|
|
909
|
-
if (/^https?:/i.test(url) || !/^[a-z][a-z\d+.-]*:/i.test(url))
|
|
910
|
-
return url;
|
|
911
|
-
if (kind !== 'embed' && /^blob:https?:\/\//i.test(url))
|
|
912
|
-
return url;
|
|
913
|
-
if (kind === 'attachment' && /^(mailto:|tel:)/i.test(url))
|
|
914
|
-
return url;
|
|
915
|
-
const mime = kind === 'image' ? 'image/[a-z0-9.+-]+' : kind === 'media'
|
|
916
|
-
? '(?:audio|video)/[a-z0-9.+-]+' : kind === 'attachment'
|
|
917
|
-
? '(?:application/(?!xhtml\\+xml|xml|javascript)[a-z0-9.+-]+|text/(?:plain|csv)|(?:image|audio|video)/[a-z0-9.+-]+)' : null;
|
|
918
|
-
return mime && new RegExp(`^data:${mime};base64,[a-z0-9+/=]${kind === 'attachment' ? '*' : '+'}$`, 'i').test(url) ? url : null;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
const MARK_TAGS = {
|
|
922
|
-
bold: 'strong', italic: 'em', strike: 's', underline: 'u', code: 'code', superscript: 'sup', subscript: 'sub'
|
|
923
|
-
};
|
|
924
|
-
/** Pure document export: works without DOM, Angular DI, or a mounted editor. */
|
|
925
|
-
function contentEditorToHtml(document, config = {}) {
|
|
926
|
-
return serialize(document.blocks, config);
|
|
927
|
-
}
|
|
928
|
-
function contentEditorBlockToHtml(block, config = {}) {
|
|
929
|
-
return serialize([block], config);
|
|
930
|
-
}
|
|
931
|
-
function serialize(blocks, config) {
|
|
932
|
-
const styles = new Set();
|
|
933
|
-
const context = {
|
|
934
|
-
escape: escapeContentEditorHtml,
|
|
935
|
-
safeUrl: safeContentEditorHtmlUrl,
|
|
936
|
-
addStyles: css => { if (config.includeStyles !== false)
|
|
937
|
-
styles.add(css); },
|
|
938
|
-
renderBlock: block => {
|
|
939
|
-
const converter = config.blocks?.[block.type]?.toHtml ?? defaultConverter(block.type) ?? config.unknownBlockToHtml;
|
|
940
|
-
if (!converter)
|
|
941
|
-
throw new Error(`No HTML converter for Content Editor block "${block.type}".`);
|
|
942
|
-
return converter(block, context);
|
|
943
|
-
},
|
|
944
|
-
renderBlocks: children => children.map(context.renderBlock).join(''),
|
|
945
|
-
defaultToHtml: block => {
|
|
946
|
-
const converter = defaultConverter(block.type);
|
|
947
|
-
if (!converter)
|
|
948
|
-
throw new Error(`No default HTML converter for Content Editor block "${block.type}".`);
|
|
949
|
-
return converter(block, context);
|
|
950
|
-
},
|
|
951
|
-
renderText: text => renderText(text, context, config)
|
|
570
|
+
const enumValue = (input, allowed, path) => {
|
|
571
|
+
if (input !== undefined && !allowed.includes(input))
|
|
572
|
+
fail(path, `Expected one of: ${allowed.join(', ')}`);
|
|
952
573
|
};
|
|
953
|
-
const
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
574
|
+
const dimension = (input, path) => {
|
|
575
|
+
if (input !== undefined && input !== null && input !== 'auto' && !(typeof input === 'number' && Number.isFinite(input) && input > 0))
|
|
576
|
+
fail(path, 'Expected a positive pixel dimension, "auto", or null');
|
|
577
|
+
};
|
|
578
|
+
const usedIds = new Set();
|
|
579
|
+
let count = 0;
|
|
580
|
+
const list = (input, path) => {
|
|
581
|
+
array(input, path).forEach((item, i) => {
|
|
582
|
+
const p = `${path}[${i}]`;
|
|
583
|
+
object(item, p);
|
|
584
|
+
runs(item.content, `${p}.content`);
|
|
585
|
+
props(item.props, `${p}.props`);
|
|
586
|
+
list(item.children, `${p}.children`);
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
const blocks = (input, path) => {
|
|
590
|
+
array(input, path).forEach((block, i) => {
|
|
591
|
+
const p = `${path}[${i}]`;
|
|
592
|
+
object(block, p);
|
|
593
|
+
if (++count > maxBlocks)
|
|
594
|
+
fail(p, `Maximum block count (${maxBlocks}) exceeded`);
|
|
595
|
+
string(block.id, `${p}.id`, true);
|
|
596
|
+
string(block.type, `${p}.type`, true);
|
|
597
|
+
if (usedIds.has(block.id))
|
|
598
|
+
fail(`${p}.id`, `Duplicate block ID "${block.id}"`);
|
|
599
|
+
usedIds.add(block.id);
|
|
600
|
+
if (!Object.hasOwn(block, 'content'))
|
|
601
|
+
fail(`${p}.content`, 'Required field');
|
|
602
|
+
const attrs = block.attrs === undefined ? {} : object(block.attrs, `${p}.attrs`);
|
|
603
|
+
const settings = attrs['settings'] === undefined ? {} : object(attrs['settings'], `${p}.attrs.settings`);
|
|
604
|
+
props(attrs['props'], `${p}.attrs.props`);
|
|
605
|
+
const c = block.content;
|
|
606
|
+
const cp = `${p}.content`;
|
|
607
|
+
const sp = `${p}.attrs.settings`;
|
|
608
|
+
switch (block.type) {
|
|
609
|
+
case 'paragraph':
|
|
610
|
+
case 'heading':
|
|
611
|
+
case 'code':
|
|
612
|
+
case 'callout':
|
|
613
|
+
runs(c, cp);
|
|
614
|
+
if (block.type === 'heading')
|
|
615
|
+
enumValue(settings['level'], [1, 2, 3, 4, 5, 6], `${sp}.level`);
|
|
616
|
+
if (block.type === 'code' && settings['language'] !== undefined)
|
|
617
|
+
string(settings['language'], `${sp}.language`);
|
|
618
|
+
if (block.type === 'callout')
|
|
619
|
+
enumValue(settings['variant'], ['note', 'tip', 'warning', 'danger'], `${sp}.variant`);
|
|
620
|
+
break;
|
|
621
|
+
case 'divider':
|
|
622
|
+
if (c !== null)
|
|
623
|
+
fail(cp, 'Divider content must be null');
|
|
624
|
+
break;
|
|
625
|
+
case 'bulletList':
|
|
626
|
+
case 'orderedList':
|
|
627
|
+
list(c, cp);
|
|
628
|
+
enumValue(settings['listStyle'], ['bullet', 'ordered'], `${sp}.listStyle`);
|
|
629
|
+
break;
|
|
630
|
+
case 'quote':
|
|
631
|
+
object(c, cp);
|
|
632
|
+
for (const name of ['cite', 'caption']) {
|
|
633
|
+
object(c[name], `${cp}.${name}`);
|
|
634
|
+
runs(c[name].content, `${cp}.${name}.content`);
|
|
635
|
+
props(c[name].props, `${cp}.${name}.props`);
|
|
636
|
+
}
|
|
637
|
+
break;
|
|
638
|
+
case 'table':
|
|
639
|
+
if (c !== null)
|
|
640
|
+
fail(cp, 'Native table content must be null; use attrs.rows');
|
|
641
|
+
if (array(attrs['rows'], `${p}.attrs.rows`).length > 500)
|
|
642
|
+
fail(`${p}.attrs.rows`, 'Tables support at most 500 rows');
|
|
643
|
+
attrs['rows'].forEach((row, r) => {
|
|
644
|
+
if (array(row, `${p}.attrs.rows[${r}]`).length > 50)
|
|
645
|
+
fail(`${p}.attrs.rows[${r}]`, 'Tables support at most 50 columns');
|
|
646
|
+
row.forEach((cell, col) => runs(cell, `${p}.attrs.rows[${r}][${col}]`));
|
|
647
|
+
});
|
|
648
|
+
enumValue(attrs['header'], [true, false], `${p}.attrs.header`);
|
|
649
|
+
if (attrs['cellMetadata'] !== undefined)
|
|
650
|
+
array(attrs['cellMetadata'], `${p}.attrs.cellMetadata`).forEach((row, r) => array(row, `${p}.attrs.cellMetadata[${r}]`).forEach((cell, col) => {
|
|
651
|
+
const mp = `${p}.attrs.cellMetadata[${r}][${col}]`;
|
|
652
|
+
object(cell, mp);
|
|
653
|
+
props(cell.props, `${mp}.props`);
|
|
654
|
+
if (cell.options !== undefined) {
|
|
655
|
+
const opts = object(cell.options, `${mp}.options`);
|
|
656
|
+
for (const key of ['colspan', 'rowspan'])
|
|
657
|
+
if (opts[key] !== undefined && !(Number.isInteger(opts[key]) && opts[key] > 0))
|
|
658
|
+
fail(`${mp}.options.${key}`, 'Expected a positive integer');
|
|
659
|
+
dimension(opts['width'], `${mp}.options.width`);
|
|
660
|
+
}
|
|
661
|
+
}));
|
|
662
|
+
break;
|
|
663
|
+
case 'image':
|
|
664
|
+
case 'video':
|
|
665
|
+
case 'embed':
|
|
666
|
+
case 'attachment':
|
|
667
|
+
object(c, cp);
|
|
668
|
+
for (const key of block.type === 'image' ? ['src', 'alt'] : block.type === 'video' ? ['src', 'caption'] : block.type === 'embed' ? ['url', 'type'] : ['url', 'name', 'mimeType'])
|
|
669
|
+
string(c[key], `${cp}.${key}`);
|
|
670
|
+
{
|
|
671
|
+
const key = ['image', 'video'].includes(block.type) ? 'src' : 'url';
|
|
672
|
+
const kind = block.type === 'video' ? 'media' : block.type === 'image' ? 'image' : block.type === 'embed' ? 'embed' : 'attachment';
|
|
673
|
+
if (c[key] && !safeContentEditorHtmlUrl(c[key], kind))
|
|
674
|
+
fail(`${cp}.${key}`, 'Unsupported resource URL');
|
|
675
|
+
}
|
|
676
|
+
if (block.type === 'attachment' && !(Number.isInteger(c.size) && c.size >= 0))
|
|
677
|
+
fail(`${cp}.size`, 'Expected a non-negative integer byte count');
|
|
678
|
+
if (block.type === 'video')
|
|
679
|
+
enumValue(c.orientation, ['portrait', 'landscape'], `${cp}.orientation`);
|
|
680
|
+
for (const key of ['width', 'height', 'actualWidth', 'actualHeight'])
|
|
681
|
+
dimension(settings[key], `${sp}.${key}`);
|
|
682
|
+
break;
|
|
683
|
+
case 'gallery': {
|
|
684
|
+
object(c, cp);
|
|
685
|
+
const ids = new Set();
|
|
686
|
+
array(c.images, `${cp}.images`).forEach((image, j) => {
|
|
687
|
+
const ip = `${cp}.images[${j}]`;
|
|
688
|
+
object(image, ip);
|
|
689
|
+
string(image.id, `${ip}.id`, true);
|
|
690
|
+
if (ids.has(image.id))
|
|
691
|
+
fail(`${ip}.id`, 'Duplicate image ID');
|
|
692
|
+
ids.add(image.id);
|
|
693
|
+
string(image.src, `${ip}.src`);
|
|
694
|
+
string(image.alt, `${ip}.alt`);
|
|
695
|
+
runs(image.caption, `${ip}.caption`);
|
|
696
|
+
if (image.src && !safeContentEditorHtmlUrl(image.src, 'image'))
|
|
697
|
+
fail(`${ip}.src`, 'Unsupported image URL');
|
|
698
|
+
});
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
case 'toggle':
|
|
702
|
+
object(c, cp);
|
|
703
|
+
runs(c.title, `${cp}.title`);
|
|
704
|
+
blocks(c.blocks, `${cp}.blocks`);
|
|
705
|
+
enumValue(settings['expanded'], [true, false], `${sp}.expanded`);
|
|
706
|
+
break;
|
|
707
|
+
case 'grid': {
|
|
708
|
+
object(c, cp);
|
|
709
|
+
const ids = new Set();
|
|
710
|
+
array(c.cells, `${cp}.cells`).forEach((cell, j) => {
|
|
711
|
+
const gp = `${cp}.cells[${j}]`;
|
|
712
|
+
object(cell, gp);
|
|
713
|
+
string(cell.id, `${gp}.id`, true);
|
|
714
|
+
if (ids.has(cell.id))
|
|
715
|
+
fail(`${gp}.id`, 'Duplicate grid cell ID');
|
|
716
|
+
ids.add(cell.id);
|
|
717
|
+
blocks(cell.blocks, `${gp}.blocks`);
|
|
718
|
+
});
|
|
719
|
+
enumValue(settings['columns'], [2, 3, 4], `${sp}.columns`);
|
|
720
|
+
enumValue(settings['gap'], ['small', 'medium', 'large'], `${sp}.gap`);
|
|
721
|
+
enumValue(settings['stackOnMobile'], [true, false], `${sp}.stackOnMobile`);
|
|
722
|
+
break;
|
|
723
|
+
}
|
|
724
|
+
default:
|
|
725
|
+
if (!options.allowUnknownBlocks && !Object.hasOwn(config.blocks ?? {}, block.type))
|
|
726
|
+
fail(`${p}.type`, `Unknown block type "${block.type}"`);
|
|
727
|
+
}
|
|
728
|
+
const validation = config.blocks?.[block.type]?.validateImport?.(block);
|
|
729
|
+
if (validation !== undefined)
|
|
730
|
+
fail(p, validation);
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
const document = object(copy(value, '$', 0), '$');
|
|
734
|
+
if (document['version'] !== 1)
|
|
735
|
+
fail('$.version', 'Only document version 1 is supported');
|
|
736
|
+
blocks(document['blocks'], '$.blocks');
|
|
737
|
+
return { version: 1, blocks: document['blocks'] };
|
|
996
738
|
}
|
|
997
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorHtmlSerializer, decorators: [{
|
|
998
|
-
type: Injectable,
|
|
999
|
-
args: [{ providedIn: 'root' }]
|
|
1000
|
-
}] });
|
|
1001
739
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
740
|
+
const ignoredTags = new Set(['script', 'style', 'noscript', 'template', 'object', 'embed', 'head', 'meta', 'link']);
|
|
741
|
+
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']);
|
|
742
|
+
/** Imports semantic HTML into native blocks. Scripts, event handlers and arbitrary CSS are never stored. */
|
|
743
|
+
function contentEditorFromHtml(html, config = {}, options = {}) {
|
|
744
|
+
if (typeof html !== 'string')
|
|
745
|
+
throw new ContentEditorImportError('$html', 'Expected an HTML string');
|
|
746
|
+
const owner = options.document ?? globalThis.document;
|
|
747
|
+
if (!owner?.implementation?.createHTMLDocument) {
|
|
748
|
+
throw new ContentEditorImportError('$html', 'HTML import requires a DOM document; supply options.document when running on the server');
|
|
1009
749
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
/** Parses and validates the native version-1 format without changing the caller's objects. */
|
|
1013
|
-
function contentEditorFromJson(source, config = {}, options = {}) {
|
|
750
|
+
const inert = owner.implementation.createHTMLDocument('');
|
|
751
|
+
inert.body.innerHTML = html;
|
|
1014
752
|
const maxDepth = options.maxDepth ?? 64;
|
|
1015
753
|
const maxBlocks = options.maxBlocks ?? 10000;
|
|
1016
|
-
if (!Number.isInteger(maxDepth) || maxDepth < 1 || !Number.isInteger(maxBlocks) || maxBlocks < 1)
|
|
754
|
+
if (!Number.isInteger(maxDepth) || maxDepth < 1 || !Number.isInteger(maxBlocks) || maxBlocks < 1)
|
|
1017
755
|
throw new ContentEditorImportError('$options', 'maxDepth and maxBlocks must be positive integers');
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
756
|
+
const definitions = [...new Map([...basicTextEditorPlugin().marks, ...colorEditorPlugin().marks, ...linkEditorPlugin().marks, ...(config.importMarks ?? [])].map(mark => [mark.type, mark])).values()];
|
|
757
|
+
const overrides = Object.values(config.blocks ?? {}).flatMap(block => block.fromHtml ? [block.fromHtml] : []);
|
|
758
|
+
let depth = 0;
|
|
759
|
+
let count = 0;
|
|
760
|
+
const guarded = (read) => {
|
|
761
|
+
if (++depth > maxDepth)
|
|
762
|
+
throw new ContentEditorImportError('$html', `Maximum nesting depth (${maxDepth}) exceeded`);
|
|
1021
763
|
try {
|
|
1022
|
-
|
|
764
|
+
return read();
|
|
1023
765
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
766
|
+
finally {
|
|
767
|
+
depth--;
|
|
1026
768
|
}
|
|
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
769
|
};
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
770
|
+
const tag = (element) => element.tagName.toLowerCase();
|
|
771
|
+
const children = (element) => Array.from(element.children);
|
|
772
|
+
const direct = (element, selector) => children(element).find(child => child.matches(selector));
|
|
773
|
+
const alignment = (element) => {
|
|
774
|
+
const value = element.style?.textAlign || element.getAttribute('align');
|
|
775
|
+
return value && ['left', 'center', 'right', 'justify'].includes(value) ? [{ name: 'text-alignment', value }] : [];
|
|
1054
776
|
};
|
|
1055
|
-
const
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
777
|
+
const dimension = (element, name) => {
|
|
778
|
+
const raw = element.getAttribute(name);
|
|
779
|
+
if (!raw || !/^\d+(?:\.\d+)?$/.test(raw))
|
|
780
|
+
return null;
|
|
781
|
+
const value = Number(raw);
|
|
782
|
+
return value > 0 && Number.isFinite(value) ? value : null;
|
|
1060
783
|
};
|
|
1061
|
-
const
|
|
1062
|
-
if (
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
object(prop, `${path}[${i}]`);
|
|
1066
|
-
string(prop.name, `${path}[${i}].name`, true);
|
|
1067
|
-
string(prop.value, `${path}[${i}].value`);
|
|
1068
|
-
});
|
|
784
|
+
const createBlock = (type, content, attrs) => {
|
|
785
|
+
if (++count > maxBlocks)
|
|
786
|
+
throw new ContentEditorImportError('$html', `Maximum block count (${maxBlocks}) exceeded`);
|
|
787
|
+
return { id: createNgsHeadlessEditorId(type), type, content, ...(attrs ? { attrs } : {}) };
|
|
1069
788
|
};
|
|
1070
|
-
const
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
789
|
+
const parseText = (element) => {
|
|
790
|
+
const runs = [];
|
|
791
|
+
const newline = () => { if (runs.length && !runs.at(-1).text.endsWith('\n'))
|
|
792
|
+
runs.push(createNgsHeadlessEditorText('\n')); };
|
|
793
|
+
const visit = (node, marks) => guarded(() => {
|
|
794
|
+
if (node.nodeType === 3) {
|
|
795
|
+
const text = (node.textContent ?? '').replace(/[\t\r\n ]+/g, ' ');
|
|
796
|
+
if (text)
|
|
797
|
+
runs.push(createNgsHeadlessEditorText(text, marks));
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
if (node.nodeType !== 1)
|
|
801
|
+
return;
|
|
802
|
+
const el = node;
|
|
803
|
+
const name = tag(el);
|
|
804
|
+
if (ignoredTags.has(name) || ['iframe', 'img', 'video', 'audio', 'ul', 'ol'].includes(name))
|
|
805
|
+
return;
|
|
806
|
+
if (name === 'br') {
|
|
807
|
+
runs.push(createNgsHeadlessEditorText('\n', marks));
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
const next = [...marks];
|
|
811
|
+
for (const definition of definitions) {
|
|
812
|
+
const explicit = el.getAttribute('data-ngs-headless-editor-mark');
|
|
813
|
+
const styleMark = ['textColor', 'backgroundColor'].includes(definition.type) && !!el.style;
|
|
814
|
+
if (explicit ? explicit !== definition.type : name !== definition.tagName && !definition.parseTags?.includes(name) && !styleMark)
|
|
815
|
+
continue;
|
|
816
|
+
const attrs = definition.readAttributes?.(el);
|
|
817
|
+
if (!definition.readAttributes || attrs)
|
|
818
|
+
next.push({ type: definition.type, ...(attrs ? { attrs } : {}) });
|
|
819
|
+
}
|
|
820
|
+
// Common HTML produced by external WYSIWYG editors also expresses marks as inline styles.
|
|
821
|
+
const css = el.style;
|
|
822
|
+
if (css?.fontWeight === 'bold' || Number(css?.fontWeight) >= 600)
|
|
823
|
+
next.push({ type: 'bold' });
|
|
824
|
+
if (css?.fontStyle === 'italic')
|
|
825
|
+
next.push({ type: 'italic' });
|
|
826
|
+
if (css?.textDecoration.includes('underline'))
|
|
827
|
+
next.push({ type: 'underline' });
|
|
828
|
+
if (css?.textDecoration.includes('line-through'))
|
|
829
|
+
next.push({ type: 'strike' });
|
|
830
|
+
if (blockTags.has(name))
|
|
831
|
+
newline();
|
|
832
|
+
Array.from(node.childNodes).forEach(child => visit(child, next));
|
|
833
|
+
if (blockTags.has(name))
|
|
834
|
+
newline();
|
|
1094
835
|
});
|
|
836
|
+
visit(element, []);
|
|
837
|
+
while (runs.length && !runs[0].text.trim())
|
|
838
|
+
runs.shift();
|
|
839
|
+
while (runs.length && !runs.at(-1).text.trim())
|
|
840
|
+
runs.pop();
|
|
841
|
+
if (runs.length) {
|
|
842
|
+
runs[0] = { ...runs[0], text: runs[0].text.replace(/^\s+/, '') };
|
|
843
|
+
const last = runs.length - 1;
|
|
844
|
+
runs[last] = { ...runs[last], text: runs[last].text.replace(/\s+$/, '') };
|
|
845
|
+
}
|
|
846
|
+
return [...normalizeNgsHeadlessEditorTextContent(runs)];
|
|
1095
847
|
};
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1098
|
-
|
|
848
|
+
const listItems = (element) => guarded(() => children(element).filter(el => tag(el) === 'li').map(li => {
|
|
849
|
+
const text = li.cloneNode(true);
|
|
850
|
+
children(text).filter(el => ['ul', 'ol'].includes(tag(el))).forEach(el => el.remove());
|
|
851
|
+
return { content: parseText(text), props: alignment(li), children: children(li).filter(el => ['ul', 'ol'].includes(tag(el))).flatMap(listItems) };
|
|
852
|
+
}));
|
|
853
|
+
const media = (element, figure) => {
|
|
854
|
+
const name = tag(element);
|
|
855
|
+
const kind = name === 'img' ? 'image' : name === 'video' ? 'media' : 'embed';
|
|
856
|
+
const src = safeContentEditorHtmlUrl(element.getAttribute('src') || element.querySelector('source')?.getAttribute('src'), kind);
|
|
857
|
+
if (!src)
|
|
858
|
+
return [];
|
|
859
|
+
const caption = figure ? direct(figure, 'figcaption') : undefined;
|
|
860
|
+
const settings = Object.fromEntries(['width', 'height'].flatMap(key => { const n = dimension(element, key); return n ? [[key, n]] : []; }));
|
|
861
|
+
const content = name === 'img' ? { src, alt: element.getAttribute('alt') ?? '' }
|
|
862
|
+
: name === 'video' ? { src, caption: caption?.textContent ?? '', orientation: 'landscape' }
|
|
863
|
+
: { url: src, type: element.getAttribute('title') ?? '' };
|
|
864
|
+
return [createBlock(name === 'img' ? 'image' : name === 'video' ? 'video' : 'embed', content, { settings })];
|
|
1099
865
|
};
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
866
|
+
const builtin = (element) => {
|
|
867
|
+
const name = tag(element);
|
|
868
|
+
const attrs = { props: alignment(element) };
|
|
869
|
+
if (ignoredTags.has(name))
|
|
870
|
+
return [];
|
|
871
|
+
if (element.matches('[data-content-editor="gallery"], .ngs-content-editor-html-gallery')) {
|
|
872
|
+
const images = children(element).flatMap(figure => {
|
|
873
|
+
const image = tag(figure) === 'img' ? figure : direct(figure, 'img');
|
|
874
|
+
const src = safeContentEditorHtmlUrl(image?.getAttribute('src'), 'image');
|
|
875
|
+
if (!image || !src)
|
|
876
|
+
return [];
|
|
877
|
+
const caption = direct(figure, 'figcaption');
|
|
878
|
+
return [{ id: createNgsHeadlessEditorId('image'), src, alt: image.getAttribute('alt') ?? '', caption: caption ? parseText(caption) : [] }];
|
|
879
|
+
});
|
|
880
|
+
return [createBlock('gallery', { images })];
|
|
881
|
+
}
|
|
882
|
+
if (element.matches('.ngs-content-editor-html-grid')) {
|
|
883
|
+
const container = direct(element, '.ngs-content-editor-html-grid-cells') ?? element;
|
|
884
|
+
const css = element.style;
|
|
885
|
+
const columnValue = Number(element.getAttribute('data-columns') || css?.getPropertyValue('--ngs-html-grid-columns'));
|
|
886
|
+
const gapValue = css?.getPropertyValue('--ngs-html-grid-gap').trim();
|
|
887
|
+
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') };
|
|
888
|
+
const cells = children(container).filter(cell => cell.matches('.ngs-content-editor-html-grid-cell')).map(cell => ({ id: createNgsHeadlessEditorId('cell'), blocks: parseBlocks(cell) }));
|
|
889
|
+
return [createBlock('grid', { cells }, { settings })];
|
|
890
|
+
}
|
|
891
|
+
if (name === 'p' || /^h[1-6]$/.test(name)) {
|
|
892
|
+
if (element.querySelector('img, video, iframe, a[download]'))
|
|
893
|
+
return parseBlocks(element);
|
|
894
|
+
return [createBlock(name === 'p' ? 'paragraph' : 'heading', parseText(element), { ...attrs, ...(name !== 'p' ? { settings: { level: Number(name[1]) } } : {}) })];
|
|
895
|
+
}
|
|
896
|
+
if (name === 'hr')
|
|
897
|
+
return [createBlock('divider', null)];
|
|
898
|
+
if (name === 'pre') {
|
|
899
|
+
const code = direct(element, 'code') ?? element;
|
|
900
|
+
const language = code.getAttribute('data-language') ?? Array.from(code.classList).find(cls => cls.startsWith('language-'))?.slice(9) ?? 'none';
|
|
901
|
+
return [createBlock('code', [createNgsHeadlessEditorText(code.textContent ?? '')], { settings: { language } })];
|
|
902
|
+
}
|
|
903
|
+
if (name === 'ul' || name === 'ol')
|
|
904
|
+
return [createBlock(name === 'ol' ? 'orderedList' : 'bulletList', listItems(element), { settings: { listStyle: name === 'ol' ? 'ordered' : 'bullet' } })];
|
|
905
|
+
if (name === 'details') {
|
|
906
|
+
const summary = direct(element, 'summary');
|
|
907
|
+
const body = element.cloneNode(true);
|
|
908
|
+
direct(body, 'summary')?.remove();
|
|
909
|
+
return [createBlock('toggle', { title: summary ? parseText(summary) : [], blocks: parseBlocks(body) }, { settings: { expanded: element.hasAttribute('open') } })];
|
|
910
|
+
}
|
|
911
|
+
if (name === 'aside' && (element.hasAttribute('data-callout') || element.classList.contains('ngs-content-editor-html-callout'))) {
|
|
912
|
+
const value = element.getAttribute('data-callout');
|
|
913
|
+
return [createBlock('callout', parseText(element), { ...attrs, settings: { variant: ['note', 'tip', 'warning', 'danger'].includes(value ?? '') ? value : 'note' } })];
|
|
914
|
+
}
|
|
915
|
+
if (name === 'blockquote' || (name === 'figure' && direct(element, 'blockquote'))) {
|
|
916
|
+
const quote = name === 'blockquote' ? element : direct(element, 'blockquote');
|
|
917
|
+
const caption = name === 'figure' ? direct(element, 'figcaption') : undefined;
|
|
918
|
+
return [createBlock('quote', { cite: { content: parseText(quote), props: alignment(quote) }, caption: { content: caption ? parseText(caption) : [], props: caption ? alignment(caption) : [] } })];
|
|
919
|
+
}
|
|
920
|
+
if (name === 'table') {
|
|
921
|
+
const rows = Array.from(element.querySelectorAll('tr')).filter(row => row.closest('table') === element);
|
|
922
|
+
const cells = rows.map(row => children(row).filter(cell => ['td', 'th'].includes(tag(cell))));
|
|
923
|
+
return [createBlock('table', null, {
|
|
924
|
+
rows: cells.map(row => row.map(parseText)), header: !!cells[0]?.some(cell => tag(cell) === 'th'),
|
|
925
|
+
cellMetadata: cells.map(row => row.map(cell => ({ props: alignment(cell), options: {
|
|
926
|
+
colspan: Math.max(1, Math.floor(dimension(cell, 'colspan') ?? 1)), rowspan: Math.max(1, Math.floor(dimension(cell, 'rowspan') ?? 1)),
|
|
927
|
+
...(dimension(cell, 'width') ? { width: dimension(cell, 'width') } : {})
|
|
928
|
+
} })))
|
|
929
|
+
})];
|
|
930
|
+
}
|
|
931
|
+
if (name === 'figure') {
|
|
932
|
+
const child = direct(element, 'img, video, iframe');
|
|
933
|
+
if (child)
|
|
934
|
+
return media(child, element);
|
|
935
|
+
}
|
|
936
|
+
if (['img', 'video', 'iframe'].includes(name))
|
|
937
|
+
return media(element);
|
|
938
|
+
if (name === 'a' && element.hasAttribute('download')) {
|
|
939
|
+
const url = safeContentEditorHtmlUrl(element.getAttribute('href'), 'attachment');
|
|
940
|
+
return url ? [createBlock('attachment', { url, name: element.getAttribute('download') || element.textContent?.trim() || 'Download', size: 0, mimeType: '' })] : [];
|
|
941
|
+
}
|
|
942
|
+
return parseBlocks(element);
|
|
1103
943
|
};
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1106
|
-
|
|
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
|
-
});
|
|
944
|
+
const context = {
|
|
945
|
+
createBlock, createId: createNgsHeadlessEditorId, parseText, parseBlocks: element => parseBlocks(element),
|
|
946
|
+
defaultFromHtml: builtin, safeUrl: safeContentEditorHtmlUrl
|
|
1114
947
|
};
|
|
1115
|
-
const
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
if (
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
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;
|
|
948
|
+
const parseElement = (element) => guarded(() => {
|
|
949
|
+
if (ignoredTags.has(tag(element)))
|
|
950
|
+
return [];
|
|
951
|
+
for (const override of overrides) {
|
|
952
|
+
if (element.matches(override.selector)) {
|
|
953
|
+
const result = override.parse(element, context);
|
|
954
|
+
return result === null ? [] : Array.isArray(result) ? [...result] : [result];
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return builtin(element);
|
|
958
|
+
});
|
|
959
|
+
const parseBlocks = (element) => guarded(() => {
|
|
960
|
+
const output = [];
|
|
961
|
+
let inline = inert.createElement('div');
|
|
962
|
+
const flush = () => {
|
|
963
|
+
const runs = parseText(inline);
|
|
964
|
+
if (runs.some(run => run.text.trim()))
|
|
965
|
+
output.push(createBlock('paragraph', runs, { props: alignment(element) }));
|
|
966
|
+
inline = inert.createElement('div');
|
|
967
|
+
};
|
|
968
|
+
for (const node of Array.from(element.childNodes)) {
|
|
969
|
+
if (node.nodeType === 1) {
|
|
970
|
+
const child = node;
|
|
971
|
+
if (ignoredTags.has(tag(child)))
|
|
972
|
+
continue;
|
|
973
|
+
if (blockTags.has(tag(child)) || ['img', 'video', 'iframe'].includes(tag(child)) || child.matches('a[download]') || overrides.some(override => child.matches(override.selector))) {
|
|
974
|
+
flush();
|
|
975
|
+
output.push(...parseElement(child));
|
|
976
|
+
continue;
|
|
1226
977
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
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;
|
|
978
|
+
// Unknown inline wrappers may contain block elements; keep those structures.
|
|
979
|
+
if (child.querySelector([...blockTags, 'img', 'video', 'iframe', 'a[download]'].join(',')) || overrides.some(override => child.querySelector(override.selector))) {
|
|
980
|
+
flush();
|
|
981
|
+
output.push(...parseElement(child));
|
|
982
|
+
continue;
|
|
1249
983
|
}
|
|
1250
|
-
default:
|
|
1251
|
-
if (!options.allowUnknownBlocks && !Object.hasOwn(config.blocks ?? {}, block.type))
|
|
1252
|
-
fail(`${p}.type`, `Unknown block type "${block.type}"`);
|
|
1253
984
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
985
|
+
inline.appendChild(node.cloneNode(true));
|
|
986
|
+
}
|
|
987
|
+
flush();
|
|
988
|
+
return output;
|
|
989
|
+
});
|
|
990
|
+
return contentEditorFromJson({ version: 1, blocks: parseBlocks(inert.body) }, config, options);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/** Parsing only: applications decide when to replace their current document. */
|
|
994
|
+
class ContentEditorImporter {
|
|
995
|
+
config = inject(CONTENT_EDITOR_CONFIG);
|
|
996
|
+
document = inject(DOCUMENT);
|
|
997
|
+
fromJson(source, config = {}, options = {}) {
|
|
998
|
+
return contentEditorFromJson(source, mergeContentEditorConfig(this.config, config), options);
|
|
999
|
+
}
|
|
1000
|
+
fromHtml(html, config = {}, options = {}) {
|
|
1001
|
+
return contentEditorFromHtml(html, mergeContentEditorConfig(this.config, config), { document: this.document, ...options });
|
|
1002
|
+
}
|
|
1003
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorImporter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1004
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorImporter, providedIn: 'root' });
|
|
1005
|
+
}
|
|
1006
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorImporter, decorators: [{
|
|
1007
|
+
type: Injectable,
|
|
1008
|
+
args: [{ providedIn: 'root' }]
|
|
1009
|
+
}] });
|
|
1010
|
+
|
|
1011
|
+
/** Text fields use the same HTML parser as documents, flattening structure to lines. */
|
|
1012
|
+
function contentEditorImportedText(blocks) {
|
|
1013
|
+
const parts = [];
|
|
1014
|
+
const read = (block) => {
|
|
1015
|
+
const content = block.content;
|
|
1016
|
+
if (isNgsHeadlessEditorTextContent(content))
|
|
1017
|
+
parts.push(content);
|
|
1018
|
+
else if (block.type === 'quote') {
|
|
1019
|
+
parts.push(content.cite.content, content.caption.content);
|
|
1020
|
+
}
|
|
1021
|
+
else if (block.type === 'bulletList' || block.type === 'orderedList') {
|
|
1022
|
+
const item = (value) => { parts.push(value.content); value.children?.forEach(item); };
|
|
1023
|
+
content.forEach(item);
|
|
1024
|
+
}
|
|
1025
|
+
else if (block.type === 'table') {
|
|
1026
|
+
for (const row of (block.attrs?.['rows'] ?? []))
|
|
1027
|
+
parts.push(row.flatMap((cell, i) => i ? [createNgsHeadlessEditorText('\t'), ...cell] : cell));
|
|
1028
|
+
}
|
|
1029
|
+
else if (block.type === 'toggle') {
|
|
1030
|
+
parts.push(content.title);
|
|
1031
|
+
content.blocks.forEach(read);
|
|
1032
|
+
}
|
|
1033
|
+
else if (block.type === 'grid')
|
|
1034
|
+
content.cells.forEach((cell) => cell.blocks.forEach(read));
|
|
1035
|
+
else if (block.type === 'image' || block.type === 'gallery')
|
|
1036
|
+
parts.push([createNgsHeadlessEditorText(content.alt ?? '')]);
|
|
1037
|
+
};
|
|
1038
|
+
blocks.forEach(read);
|
|
1039
|
+
return normalizeNgsHeadlessEditorTextContent(parts.filter(part => part.some(run => run.text)).flatMap((part, i) => i ? [createNgsHeadlessEditorText('\n'), ...part] : part));
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
const CONTENT_BUILDER = new InjectionToken('CONTENT_BUILDER');
|
|
1043
|
+
const CONTENT_EDITOR_BLOCK = new InjectionToken('CONTENT_EDITOR_BLOCK');
|
|
1044
|
+
|
|
1045
|
+
/** UI state and block operations. The headless document is the only content store. */
|
|
1046
|
+
class ContentBuilderStore {
|
|
1047
|
+
editor = inject(NgsHeadlessEditor);
|
|
1048
|
+
dragging = false;
|
|
1049
|
+
constructor() {
|
|
1050
|
+
const document = inject(DOCUMENT);
|
|
1051
|
+
// Capture the current point before CDK chooses a connected list. Its moved
|
|
1052
|
+
// output is emitted after hit testing and would provide the previous point.
|
|
1053
|
+
const mouse = (event) => { if (this.dragging)
|
|
1054
|
+
this.dragPointer.set({ x: event.clientX, y: event.clientY }); };
|
|
1055
|
+
const touch = (event) => {
|
|
1056
|
+
const point = event.touches[0];
|
|
1057
|
+
if (this.dragging && point)
|
|
1058
|
+
this.dragPointer.set({ x: point.clientX, y: point.clientY });
|
|
1059
|
+
};
|
|
1060
|
+
document.addEventListener('mousemove', mouse, true);
|
|
1061
|
+
document.addEventListener('touchmove', touch, { capture: true, passive: true });
|
|
1062
|
+
inject(DestroyRef).onDestroy(() => {
|
|
1063
|
+
document.removeEventListener('mousemove', mouse, true);
|
|
1064
|
+
document.removeEventListener('touchmove', touch, true);
|
|
1257
1065
|
});
|
|
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
1066
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
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`);
|
|
1067
|
+
textEdit = null;
|
|
1068
|
+
/** Scopes typing groups to one text region, so adjacent cells never share undo. */
|
|
1069
|
+
withTextEdit(origin, group, edit) {
|
|
1070
|
+
const previous = this.textEdit;
|
|
1071
|
+
this.textEdit = { origin, group };
|
|
1289
1072
|
try {
|
|
1290
|
-
|
|
1073
|
+
edit();
|
|
1291
1074
|
}
|
|
1292
1075
|
finally {
|
|
1293
|
-
|
|
1076
|
+
this.textEdit = previous;
|
|
1294
1077
|
}
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1078
|
+
}
|
|
1079
|
+
insertionTarget = signal({ scope: {} }, /* @ts-ignore */
|
|
1080
|
+
...(ngDevMode ? [{ debugName: "insertionTarget" }] : /* istanbul ignore next */ []));
|
|
1081
|
+
restoreTextSelection = signal(null, /* @ts-ignore */
|
|
1082
|
+
...(ngDevMode ? [{ debugName: "restoreTextSelection" }] : /* istanbul ignore next */ []));
|
|
1083
|
+
focusedBlockId = signal(null, /* @ts-ignore */
|
|
1084
|
+
...(ngDevMode ? [{ debugName: "focusedBlockId" }] : /* istanbul ignore next */ []));
|
|
1085
|
+
activeBlockId = signal(null, /* @ts-ignore */
|
|
1086
|
+
...(ngDevMode ? [{ debugName: "activeBlockId" }] : /* istanbul ignore next */ []));
|
|
1087
|
+
dragPointer = signal(null, /* @ts-ignore */
|
|
1088
|
+
...(ngDevMode ? [{ debugName: "dragPointer" }] : /* istanbul ignore next */ []));
|
|
1089
|
+
setDragging(dragging) {
|
|
1090
|
+
this.dragging = dragging;
|
|
1091
|
+
if (!dragging)
|
|
1092
|
+
this.dragPointer.set(null);
|
|
1093
|
+
}
|
|
1094
|
+
dropLists = signal([], /* @ts-ignore */
|
|
1095
|
+
...(ngDevMode ? [{ debugName: "dropLists" }] : /* istanbul ignore next */ []));
|
|
1096
|
+
registerDropList(list) {
|
|
1097
|
+
if (!this.dropLists().includes(list))
|
|
1098
|
+
this.dropLists.update(lists => [...lists, list]);
|
|
1099
|
+
}
|
|
1100
|
+
unregisterDropList(list) {
|
|
1101
|
+
this.dropLists.update(lists => lists.filter(item => item !== list));
|
|
1102
|
+
}
|
|
1103
|
+
blocks = computed(() => this.editor.document().blocks.map(contentEditorBlockView), /* @ts-ignore */
|
|
1104
|
+
...(ngDevMode ? [{ debugName: "blocks" }] : /* istanbul ignore next */ []));
|
|
1105
|
+
setFocusedBlockId(id) { this.focusedBlockId.set(id); }
|
|
1106
|
+
setActiveBlockId(id) { this.activeBlockId.set(id); }
|
|
1107
|
+
setBlocks(value) {
|
|
1108
|
+
this.editor.setDocument(value);
|
|
1109
|
+
}
|
|
1110
|
+
addBlock(block, index, scope = {}) {
|
|
1111
|
+
const native = contentEditorNativeBlock(block);
|
|
1112
|
+
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
1113
|
+
const collection = [...contentEditorCollection(blocks, scope)];
|
|
1114
|
+
collection.splice(index, 0, native);
|
|
1115
|
+
replaceContentEditorCollection(blocks, scope, collection);
|
|
1116
|
+
this.editor.updateDocument({ version: 1, blocks });
|
|
1117
|
+
}
|
|
1118
|
+
deleteBlock(id, _index) { this.deleteBlocks([id]); }
|
|
1119
|
+
deleteBlocks(ids) {
|
|
1120
|
+
const selected = new Set(ids);
|
|
1121
|
+
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
1122
|
+
let changed = false;
|
|
1123
|
+
const remove = (items) => {
|
|
1124
|
+
for (let index = items.length - 1; index >= 0; index--) {
|
|
1125
|
+
if (selected.has(items[index].id)) {
|
|
1126
|
+
items.splice(index, 1);
|
|
1127
|
+
changed = true;
|
|
1128
|
+
}
|
|
1129
|
+
else
|
|
1130
|
+
for (const children of contentEditorChildCollections(items[index]))
|
|
1131
|
+
remove(children);
|
|
1325
1132
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1133
|
+
};
|
|
1134
|
+
remove(blocks);
|
|
1135
|
+
if (changed)
|
|
1136
|
+
this.editor.updateDocument({ version: 1, blocks });
|
|
1137
|
+
}
|
|
1138
|
+
updateBlock(id, data) {
|
|
1139
|
+
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
1140
|
+
const previous = findContentEditorBlock(blocks, id);
|
|
1141
|
+
if (!previous)
|
|
1142
|
+
return;
|
|
1143
|
+
const next = contentEditorNativeBlock({ ...contentEditorBlockView(previous), ...data });
|
|
1144
|
+
const origin = this.textEdit?.origin ?? 'command';
|
|
1145
|
+
const typing = origin === 'keyboard' || origin === 'composition';
|
|
1146
|
+
const root = blocks.find(block => !!findContentEditorBlock([block], id));
|
|
1147
|
+
Object.assign(previous, next);
|
|
1148
|
+
this.editor.updateBlock(root.id, { content: root.content, attrs: root.attrs }, typing ? origin : 'command', typing ? this.textEdit?.group ?? null : null);
|
|
1149
|
+
}
|
|
1150
|
+
moveBlock(from, to) {
|
|
1151
|
+
const blocks = [...this.editor.document().blocks];
|
|
1152
|
+
const [block] = blocks.splice(from, 1);
|
|
1153
|
+
blocks.splice(to, 0, block);
|
|
1154
|
+
this.editor.updateDocument({ version: 1, blocks });
|
|
1155
|
+
}
|
|
1156
|
+
moveBetweenCollections(from, to, source, target) {
|
|
1157
|
+
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
1158
|
+
const sourceItems = [...contentEditorCollection(blocks, source)];
|
|
1159
|
+
const block = sourceItems[from];
|
|
1160
|
+
if (!block || (target.parentId && findContentEditorBlock([block], target.parentId)))
|
|
1161
|
+
return;
|
|
1162
|
+
sourceItems.splice(from, 1);
|
|
1163
|
+
replaceContentEditorCollection(blocks, source, sourceItems);
|
|
1164
|
+
const targetItems = [...contentEditorCollection(blocks, target)];
|
|
1165
|
+
targetItems.splice(to, 0, block);
|
|
1166
|
+
replaceContentEditorCollection(blocks, target, targetItems);
|
|
1167
|
+
this.editor.updateDocument({ version: 1, blocks });
|
|
1168
|
+
}
|
|
1169
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentBuilderStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1170
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentBuilderStore });
|
|
1171
|
+
}
|
|
1172
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentBuilderStore, decorators: [{
|
|
1173
|
+
type: Injectable
|
|
1174
|
+
}], ctorParameters: () => [] });
|
|
1175
|
+
|
|
1176
|
+
const regions = new WeakMap();
|
|
1177
|
+
/** A headless inline editor bound to a text field in a content block. */
|
|
1178
|
+
class ContentEditorContentEditableDirective {
|
|
1179
|
+
region = inject(NgsHeadlessEditorInlineRegion);
|
|
1180
|
+
surface = inject(NgsHeadlessEditorSurface);
|
|
1181
|
+
importer = inject(ContentEditorImporter);
|
|
1182
|
+
builder = inject(CONTENT_BUILDER, { optional: true });
|
|
1183
|
+
store = inject(ContentBuilderStore, { optional: true });
|
|
1184
|
+
historyGroup = createNgsHeadlessEditorId('content-region');
|
|
1185
|
+
element = inject(ElementRef).nativeElement;
|
|
1186
|
+
content = input([], { ...(ngDevMode ? { debugName: "content" } : /* istanbul ignore next */ {}), alias: 'ngsContentEditorContentEditable' });
|
|
1187
|
+
settings = input({}, /* @ts-ignore */
|
|
1188
|
+
...(ngDevMode ? [{ debugName: "settings" }] : /* istanbul ignore next */ []));
|
|
1189
|
+
props = input([], /* @ts-ignore */
|
|
1190
|
+
...(ngDevMode ? [{ debugName: "props" }] : /* istanbul ignore next */ []));
|
|
1191
|
+
singleLine = input(false, /* @ts-ignore */
|
|
1192
|
+
...(ngDevMode ? [{ debugName: "singleLine" }] : /* istanbul ignore next */ []));
|
|
1193
|
+
contentChanged = output();
|
|
1194
|
+
propsChanged = output();
|
|
1195
|
+
pressedEnter = output();
|
|
1196
|
+
initialized = output();
|
|
1197
|
+
static forElement(element) {
|
|
1198
|
+
return element ? regions.get(element) : undefined;
|
|
1199
|
+
}
|
|
1200
|
+
constructor() {
|
|
1201
|
+
regions.set(this.element, this);
|
|
1202
|
+
effect(() => {
|
|
1203
|
+
const content = this.content();
|
|
1204
|
+
untracked(() => this.region.load(content));
|
|
1205
|
+
});
|
|
1206
|
+
effect(() => {
|
|
1207
|
+
const content = this.region.content();
|
|
1208
|
+
const origin = this.region.editor.origin();
|
|
1209
|
+
if (origin !== 'external' && origin !== 'history') {
|
|
1210
|
+
untracked(() => {
|
|
1211
|
+
if (this.store)
|
|
1212
|
+
this.store.withTextEdit(origin, this.historyGroup, () => this.contentChanged.emit(content));
|
|
1213
|
+
else
|
|
1214
|
+
this.contentChanged.emit(content);
|
|
1215
|
+
});
|
|
1335
1216
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1217
|
+
});
|
|
1218
|
+
// Capture before the surface and the block's own listeners. Structural Enter
|
|
1219
|
+
// stays with the content builder; multiline fields use the headless surface.
|
|
1220
|
+
this.element.addEventListener('paste', this.onPaste, true);
|
|
1221
|
+
this.element.addEventListener('keydown', this.onKeydown, true);
|
|
1222
|
+
this.element.addEventListener('beforeinput', this.onBeforeInput, true);
|
|
1223
|
+
afterNextRender(() => this.initialized.emit());
|
|
1224
|
+
afterRenderEffect(() => {
|
|
1225
|
+
const pending = this.store?.restoreTextSelection();
|
|
1226
|
+
const wrapper = this.element.closest('[data-block-id]');
|
|
1227
|
+
if (pending && wrapper?.getAttribute('data-block-id') === pending.blockId &&
|
|
1228
|
+
wrapper.querySelector('.ngs-content-editor-content-editable') === this.element) {
|
|
1229
|
+
this.activate();
|
|
1230
|
+
this.region.editor.setSelection(pending.selection);
|
|
1231
|
+
this.surface.focus();
|
|
1232
|
+
this.store.restoreTextSelection.set(null);
|
|
1345
1233
|
}
|
|
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
1234
|
});
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1235
|
+
}
|
|
1236
|
+
activate() {
|
|
1237
|
+
this.region.activate();
|
|
1238
|
+
const id = this.element.closest('[data-block-id]')?.getAttribute('data-block-id');
|
|
1239
|
+
if (id && this.store) {
|
|
1240
|
+
const scope = this.builder && 'scope' in this.builder ? this.builder.scope() : {};
|
|
1241
|
+
this.store.insertionTarget.set({ scope, afterId: id });
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
focus() { this.activate(); this.surface.focus(); }
|
|
1245
|
+
getContent() { return this.region.content(); }
|
|
1246
|
+
alignment() { return this.props().find(prop => prop.name === 'text-alignment')?.value ?? 'left'; }
|
|
1247
|
+
setAlignment(value) {
|
|
1248
|
+
this.propsChanged.emit([
|
|
1249
|
+
...this.props().filter(prop => prop.name !== 'text-alignment'),
|
|
1250
|
+
{ name: 'text-alignment', value }
|
|
1251
|
+
]);
|
|
1252
|
+
}
|
|
1253
|
+
onPaste = (event) => {
|
|
1254
|
+
if (event.defaultPrevented || this.region.editor.readOnly())
|
|
1255
|
+
return;
|
|
1256
|
+
const html = event.clipboardData?.getData('text/html');
|
|
1257
|
+
if (!html)
|
|
1258
|
+
return;
|
|
1259
|
+
try {
|
|
1260
|
+
const config = this.builder?.rootBuilder.config() ?? {};
|
|
1261
|
+
const parsed = this.importer.fromHtml(html, config);
|
|
1262
|
+
this.activate();
|
|
1263
|
+
this.surface.syncSelectionFromDom();
|
|
1264
|
+
const id = this.element.closest('[data-block-id]')?.getAttribute('data-block-id');
|
|
1265
|
+
const structural = parsed.blocks.length > 1 || parsed.blocks.some(block => block.type !== 'paragraph');
|
|
1266
|
+
const selection = this.region.editor.selection();
|
|
1267
|
+
if (structural && id && this.builder && selection) {
|
|
1268
|
+
const lines = this.region.editor.document().blocks;
|
|
1269
|
+
const offset = (point) => lines.slice(0, lines.findIndex(line => line.id === point.blockId))
|
|
1270
|
+
.reduce((sum, line) => sum + line.content.reduce((total, run) => total + run.text.length, 0) + 1, 0) + point.offset;
|
|
1271
|
+
if (this.builder.rootBuilder.pasteBlocksAtSelection(id, parsed, offset(selection.anchor), offset(selection.focus))) {
|
|
1272
|
+
event.preventDefault();
|
|
1273
|
+
event.stopImmediatePropagation();
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
const content = contentEditorImportedText(parsed.blocks);
|
|
1278
|
+
if (!content.some(run => run.text))
|
|
1279
|
+
return;
|
|
1280
|
+
this.activate();
|
|
1281
|
+
this.surface.syncSelectionFromDom();
|
|
1282
|
+
event.preventDefault();
|
|
1283
|
+
event.stopImmediatePropagation();
|
|
1284
|
+
this.region.editor.insertTextContent(content);
|
|
1285
|
+
}
|
|
1286
|
+
catch {
|
|
1287
|
+
// The surface can still paste the plain-text representation on parse failure.
|
|
1371
1288
|
}
|
|
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
1289
|
};
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
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 })];
|
|
1290
|
+
onKeydown = (event) => {
|
|
1291
|
+
if (event.key === 'Enter' && this.singleLine() && !event.shiftKey && !event.isComposing) {
|
|
1292
|
+
event.preventDefault();
|
|
1293
|
+
event.stopImmediatePropagation();
|
|
1294
|
+
this.pressedEnter.emit(event);
|
|
1407
1295
|
}
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
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 })];
|
|
1296
|
+
};
|
|
1297
|
+
onBeforeInput = (event) => {
|
|
1298
|
+
if (event.inputType === 'insertParagraph' && this.singleLine() && !event.isComposing) {
|
|
1299
|
+
event.preventDefault();
|
|
1300
|
+
event.stopImmediatePropagation();
|
|
1301
|
+
this.pressedEnter.emit(new KeyboardEvent('keydown', { key: 'Enter' }));
|
|
1416
1302
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1303
|
+
};
|
|
1304
|
+
ngOnDestroy() {
|
|
1305
|
+
regions.delete(this.element);
|
|
1306
|
+
this.element.removeEventListener('paste', this.onPaste, true);
|
|
1307
|
+
this.element.removeEventListener('keydown', this.onKeydown, true);
|
|
1308
|
+
this.element.removeEventListener('beforeinput', this.onBeforeInput, true);
|
|
1309
|
+
}
|
|
1310
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorContentEditableDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1311
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.7", type: ContentEditorContentEditableDirective, isStandalone: true, selector: "[ngsContentEditorContentEditable]", inputs: { content: { classPropertyName: "content", publicName: "ngsContentEditorContentEditable", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, singleLine: { classPropertyName: "singleLine", publicName: "singleLine", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { contentChanged: "contentChanged", propsChanged: "propsChanged", pressedEnter: "pressedEnter", initialized: "initialized" }, host: { listeners: { "focus": "activate()" }, properties: { "class.align-left": "alignment() === \"left\"", "class.align-center": "alignment() === \"center\"", "class.align-right": "alignment() === \"right\"", "class.align-justify": "alignment() === \"justify\"" }, classAttribute: "ngs-content-editor-content-editable" }, providers: [provideNgsHeadlessEditorInlineRegion()], exportAs: ["ngsContentEditorContentEditable"], hostDirectives: [{ directive: i1.NgsHeadlessEditorSurface }], ngImport: i0 });
|
|
1312
|
+
}
|
|
1313
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorContentEditableDirective, decorators: [{
|
|
1314
|
+
type: Directive,
|
|
1315
|
+
args: [{
|
|
1316
|
+
selector: '[ngsContentEditorContentEditable]',
|
|
1317
|
+
exportAs: 'ngsContentEditorContentEditable',
|
|
1318
|
+
providers: [provideNgsHeadlessEditorInlineRegion()],
|
|
1319
|
+
hostDirectives: [NgsHeadlessEditorSurface],
|
|
1320
|
+
host: {
|
|
1321
|
+
'class': 'ngs-content-editor-content-editable',
|
|
1322
|
+
'[class.align-left]': 'alignment() === "left"',
|
|
1323
|
+
'[class.align-center]': 'alignment() === "center"',
|
|
1324
|
+
'[class.align-right]': 'alignment() === "right"',
|
|
1325
|
+
'[class.align-justify]': 'alignment() === "justify"',
|
|
1326
|
+
'(focus)': 'activate()'
|
|
1327
|
+
}
|
|
1328
|
+
}]
|
|
1329
|
+
}], ctorParameters: () => [], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsContentEditorContentEditable", required: false }] }], settings: [{ type: i0.Input, args: [{ isSignal: true, alias: "settings", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], singleLine: [{ type: i0.Input, args: [{ isSignal: true, alias: "singleLine", required: false }] }], contentChanged: [{ type: i0.Output, args: ["contentChanged"] }], propsChanged: [{ type: i0.Output, args: ["propsChanged"] }], pressedEnter: [{ type: i0.Output, args: ["pressedEnter"] }], initialized: [{ type: i0.Output, args: ["initialized"] }] } });
|
|
1330
|
+
|
|
1331
|
+
class AddLinkDialog {
|
|
1332
|
+
_dialogRef = inject(DialogRef);
|
|
1333
|
+
_formBuilder = inject(FormBuilder);
|
|
1334
|
+
form = this._formBuilder.group({
|
|
1335
|
+
href: [''],
|
|
1336
|
+
openInNewTab: [true, [Validators.required]]
|
|
1337
|
+
});
|
|
1338
|
+
cancel() {
|
|
1339
|
+
this._dialogRef.close(false);
|
|
1340
|
+
}
|
|
1341
|
+
add() {
|
|
1342
|
+
this._dialogRef.close(this.form.value);
|
|
1343
|
+
}
|
|
1344
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: AddLinkDialog, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1345
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.1.7", type: AddLinkDialog, isStandalone: true, selector: "ngs-add-link", ngImport: i0, template: "<h1 ngs-dialog-title>Add link</h1>\n<ngs-dialog-content [formGroup]=\"form\" class=\"!overflow-hidden\">\n <ngs-form-field class=\"w-full\">\n <ngs-label>Href (Url, Tel or other)</ngs-label>\n <input ngsInput type=\"text\" formControlName=\"href\">\n </ngs-form-field>\n <ngs-slide-toggle formControlName=\"openInNewTab\">Open link in a new tab</ngs-slide-toggle>\n</ngs-dialog-content>\n<ngs-dialog-actions>\n <button ngsButton (click)=\"cancel()\">Cancel</button>\n <button ngsButton=\"filled\"\n [disabled]=\"form.invalid\" (click)=\"add()\">Add</button>\n</ngs-dialog-actions>\n", styles: [""], dependencies: [{ kind: "component", type: DialogContent, selector: "ngs-dialog-content,[ngs-dialog-content],[ngsDialogContent]" }, { kind: "component", type: FormField, selector: "ngs-form-field", inputs: ["labelMode", "subscriptHiddenIfEmpty", "sameHeightAsButton"], exportAs: ["ngsFormField"] }, { kind: "directive", type: Input, selector: "input[ngsInput], textarea[ngsInput]", inputs: ["id", "placeholder", "required", "disabled", "readonly", "errorStateMatcher"], exportAs: ["ngsInput"] }, { kind: "component", type: DialogTitle, selector: "ngs-dialog-title, [ngs-dialog-title], [ngsDialogTitle]", inputs: ["id"], exportAs: ["ngsDialogTitle"] }, { kind: "component", type: DialogActions, selector: "ngs-dialog-actions, [ngs-dialog-actions], [ngsDialogActions]", inputs: ["align"] }, { kind: "component", type: Button, selector: " button[ngsButton], button[ngsIconButton], a[ngsButton], a[ngsIconButton] ", inputs: ["ngsButton", "ngsIconButton", "loading", "disabled", "disabledInteractive", "disableRipple", "reverse", "fullWidth", "hideTextOnMobile"], exportAs: ["ngsButton"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1$1.DefaultValueAccessor, selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1$1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: Label, selector: "ngs-label" }, { kind: "component", type: SlideToggle, selector: "ngs-slide-toggle", inputs: ["id", "name", "labelPosition", "aria-label", "aria-labelledby", "aria-describedby", "required", "disabled", "disableRipple", "tabIndex", "hideIcon", "color", "checked"], outputs: ["disabledChange", "checkedChange", "change", "toggleChange"], exportAs: ["ngsSlideToggle"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
1346
|
+
}
|
|
1347
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: AddLinkDialog, decorators: [{
|
|
1348
|
+
type: Component,
|
|
1349
|
+
args: [{ selector: 'ngs-add-link', imports: [
|
|
1350
|
+
DialogContent,
|
|
1351
|
+
FormField,
|
|
1352
|
+
Input,
|
|
1353
|
+
DialogTitle,
|
|
1354
|
+
DialogActions,
|
|
1355
|
+
Button,
|
|
1356
|
+
ReactiveFormsModule,
|
|
1357
|
+
Label,
|
|
1358
|
+
SlideToggle
|
|
1359
|
+
], changeDetection: ChangeDetectionStrategy.Eager, template: "<h1 ngs-dialog-title>Add link</h1>\n<ngs-dialog-content [formGroup]=\"form\" class=\"!overflow-hidden\">\n <ngs-form-field class=\"w-full\">\n <ngs-label>Href (Url, Tel or other)</ngs-label>\n <input ngsInput type=\"text\" formControlName=\"href\">\n </ngs-form-field>\n <ngs-slide-toggle formControlName=\"openInNewTab\">Open link in a new tab</ngs-slide-toggle>\n</ngs-dialog-content>\n<ngs-dialog-actions>\n <button ngsButton (click)=\"cancel()\">Cancel</button>\n <button ngsButton=\"filled\"\n [disabled]=\"form.invalid\" (click)=\"add()\">Add</button>\n</ngs-dialog-actions>\n" }]
|
|
1360
|
+
}] });
|
|
1361
|
+
|
|
1362
|
+
class EditLinkDialog {
|
|
1363
|
+
_dialogRef = inject(DialogRef);
|
|
1364
|
+
_dialogData = inject(DIALOG_DATA);
|
|
1365
|
+
_formBuilder = inject(FormBuilder);
|
|
1366
|
+
form = this._formBuilder.group({
|
|
1367
|
+
href: [this._dialogData.href],
|
|
1368
|
+
openInNewTab: [this._dialogData.openInNewTab, [Validators.required]]
|
|
1369
|
+
});
|
|
1370
|
+
cancel() {
|
|
1371
|
+
this._dialogRef.close(false);
|
|
1372
|
+
}
|
|
1373
|
+
add() {
|
|
1374
|
+
this._dialogRef.close(this.form.value);
|
|
1375
|
+
}
|
|
1376
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: EditLinkDialog, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1377
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.1.7", type: EditLinkDialog, isStandalone: true, selector: "ngs-edit-link", ngImport: i0, template: "<h1 ngs-dialog-title>Edit link</h1>\n<ngs-dialog-content [formGroup]=\"form\" class=\"!overflow-hidden\">\n <ngs-form-field class=\"w-full\">\n <ngs-label>Href (Url, Tel or other)</ngs-label>\n <input ngsInput type=\"text\" formControlName=\"href\">\n <ngs-hint>To delete the link, clear this field and apply</ngs-hint>\n </ngs-form-field>\n <ngs-slide-toggle formControlName=\"openInNewTab\" class=\"mt-5\">Open link in a new tab</ngs-slide-toggle>\n</ngs-dialog-content>\n<ngs-dialog-actions>\n <button ngsButton (click)=\"cancel()\">Cancel</button>\n <button ngsButton=\"filled\"\n [disabled]=\"form.invalid\" (click)=\"add()\">Apply</button>\n</ngs-dialog-actions>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1$1.DefaultValueAccessor, selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "component", type: Button, selector: " button[ngsButton], button[ngsIconButton], a[ngsButton], a[ngsIconButton] ", inputs: ["ngsButton", "ngsIconButton", "loading", "disabled", "disabledInteractive", "disableRipple", "reverse", "fullWidth", "hideTextOnMobile"], exportAs: ["ngsButton"] }, { kind: "component", type: DialogActions, selector: "ngs-dialog-actions, [ngs-dialog-actions], [ngsDialogActions]", inputs: ["align"] }, { kind: "component", type: DialogContent, selector: "ngs-dialog-content,[ngs-dialog-content],[ngsDialogContent]" }, { kind: "component", type: DialogTitle, selector: "ngs-dialog-title, [ngs-dialog-title], [ngsDialogTitle]", inputs: ["id"], exportAs: ["ngsDialogTitle"] }, { kind: "component", type: FormField, selector: "ngs-form-field", inputs: ["labelMode", "subscriptHiddenIfEmpty", "sameHeightAsButton"], exportAs: ["ngsFormField"] }, { kind: "directive", type: Input, selector: "input[ngsInput], textarea[ngsInput]", inputs: ["id", "placeholder", "required", "disabled", "readonly", "errorStateMatcher"], exportAs: ["ngsInput"] }, { kind: "component", type: Label, selector: "ngs-label" }, { kind: "component", type: SlideToggle, selector: "ngs-slide-toggle", inputs: ["id", "name", "labelPosition", "aria-label", "aria-labelledby", "aria-describedby", "required", "disabled", "disableRipple", "tabIndex", "hideIcon", "color", "checked"], outputs: ["disabledChange", "checkedChange", "change", "toggleChange"], exportAs: ["ngsSlideToggle"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1$1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: Hint, selector: "ngs-hint", inputs: ["align"], exportAs: ["ngsHint"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
1378
|
+
}
|
|
1379
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: EditLinkDialog, decorators: [{
|
|
1380
|
+
type: Component,
|
|
1381
|
+
args: [{ selector: 'ngs-edit-link', imports: [
|
|
1382
|
+
FormsModule,
|
|
1383
|
+
Button,
|
|
1384
|
+
DialogActions,
|
|
1385
|
+
DialogContent,
|
|
1386
|
+
DialogTitle,
|
|
1387
|
+
FormField,
|
|
1388
|
+
Input,
|
|
1389
|
+
Label,
|
|
1390
|
+
SlideToggle,
|
|
1391
|
+
ReactiveFormsModule,
|
|
1392
|
+
Hint
|
|
1393
|
+
], changeDetection: ChangeDetectionStrategy.Eager, template: "<h1 ngs-dialog-title>Edit link</h1>\n<ngs-dialog-content [formGroup]=\"form\" class=\"!overflow-hidden\">\n <ngs-form-field class=\"w-full\">\n <ngs-label>Href (Url, Tel or other)</ngs-label>\n <input ngsInput type=\"text\" formControlName=\"href\">\n <ngs-hint>To delete the link, clear this field and apply</ngs-hint>\n </ngs-form-field>\n <ngs-slide-toggle formControlName=\"openInNewTab\" class=\"mt-5\">Open link in a new tab</ngs-slide-toggle>\n</ngs-dialog-content>\n<ngs-dialog-actions>\n <button ngsButton (click)=\"cancel()\">Cancel</button>\n <button ngsButton=\"filled\"\n [disabled]=\"form.invalid\" (click)=\"add()\">Apply</button>\n</ngs-dialog-actions>\n" }]
|
|
1394
|
+
}] });
|
|
1395
|
+
|
|
1396
|
+
class TextColorComponent {
|
|
1397
|
+
_document = inject(DOCUMENT$1);
|
|
1398
|
+
recentlyUsed = model(this._getRecentlyUsed(), /* @ts-ignore */
|
|
1399
|
+
...(ngDevMode ? [{ debugName: "recentlyUsed" }] : /* istanbul ignore next */ []));
|
|
1400
|
+
selectedTextColor = model(null, /* @ts-ignore */
|
|
1401
|
+
...(ngDevMode ? [{ debugName: "selectedTextColor" }] : /* istanbul ignore next */ []));
|
|
1402
|
+
selectedBackgroundColor = model(null, /* @ts-ignore */
|
|
1403
|
+
...(ngDevMode ? [{ debugName: "selectedBackgroundColor" }] : /* istanbul ignore next */ []));
|
|
1404
|
+
textColors = input([
|
|
1405
|
+
{
|
|
1406
|
+
name: 'Default',
|
|
1407
|
+
color: '',
|
|
1408
|
+
type: 'text'
|
|
1409
|
+
},
|
|
1410
|
+
{
|
|
1411
|
+
name: 'Gray',
|
|
1412
|
+
color: '#7f7f7f',
|
|
1413
|
+
type: 'text'
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
name: 'Brown',
|
|
1417
|
+
color: '#ae2012',
|
|
1418
|
+
type: 'text'
|
|
1419
|
+
},
|
|
1420
|
+
{
|
|
1421
|
+
name: 'Orange',
|
|
1422
|
+
color: '#fb5607',
|
|
1423
|
+
type: 'text'
|
|
1424
|
+
},
|
|
1425
|
+
{
|
|
1426
|
+
name: 'Yellow',
|
|
1427
|
+
color: '#ffa200',
|
|
1428
|
+
type: 'text'
|
|
1429
|
+
},
|
|
1430
|
+
{
|
|
1431
|
+
name: 'Green',
|
|
1432
|
+
color: '#40916c',
|
|
1433
|
+
type: 'text'
|
|
1434
|
+
},
|
|
1435
|
+
{
|
|
1436
|
+
name: 'Blue',
|
|
1437
|
+
color: '#00bbf9',
|
|
1438
|
+
type: 'text'
|
|
1439
|
+
},
|
|
1440
|
+
{
|
|
1441
|
+
name: 'Purple',
|
|
1442
|
+
color: '#907ad6',
|
|
1443
|
+
type: 'text'
|
|
1444
|
+
},
|
|
1445
|
+
{
|
|
1446
|
+
name: 'Pink',
|
|
1447
|
+
color: '#fa3faf',
|
|
1448
|
+
type: 'text'
|
|
1449
|
+
},
|
|
1450
|
+
{
|
|
1451
|
+
name: 'Red',
|
|
1452
|
+
color: '#ef233c',
|
|
1453
|
+
type: 'text'
|
|
1421
1454
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1455
|
+
], /* @ts-ignore */
|
|
1456
|
+
...(ngDevMode ? [{ debugName: "textColors" }] : /* istanbul ignore next */ []));
|
|
1457
|
+
backgroundColors = input([
|
|
1458
|
+
{
|
|
1459
|
+
name: 'Default',
|
|
1460
|
+
color: '',
|
|
1461
|
+
type: 'background'
|
|
1462
|
+
},
|
|
1463
|
+
{
|
|
1464
|
+
name: 'Gray',
|
|
1465
|
+
color: '#e9ecef',
|
|
1466
|
+
type: 'background'
|
|
1467
|
+
},
|
|
1468
|
+
{
|
|
1469
|
+
name: 'Brown',
|
|
1470
|
+
color: '#ffe0c0',
|
|
1471
|
+
type: 'background'
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
name: 'Orange',
|
|
1475
|
+
color: '#ffd8c6',
|
|
1476
|
+
type: 'background'
|
|
1477
|
+
},
|
|
1478
|
+
{
|
|
1479
|
+
name: 'Yellow',
|
|
1480
|
+
color: '#fff3b0',
|
|
1481
|
+
type: 'background'
|
|
1482
|
+
},
|
|
1483
|
+
{
|
|
1484
|
+
name: 'Green',
|
|
1485
|
+
color: '#eff6e0',
|
|
1486
|
+
type: 'background'
|
|
1487
|
+
},
|
|
1488
|
+
{
|
|
1489
|
+
name: 'Blue',
|
|
1490
|
+
color: '#edf6f9',
|
|
1491
|
+
type: 'background'
|
|
1492
|
+
},
|
|
1493
|
+
{
|
|
1494
|
+
name: 'Purple',
|
|
1495
|
+
color: '#e0aaff',
|
|
1496
|
+
type: 'background'
|
|
1497
|
+
},
|
|
1498
|
+
{
|
|
1499
|
+
name: 'Pink',
|
|
1500
|
+
color: '#fae0ec',
|
|
1501
|
+
type: 'background'
|
|
1502
|
+
},
|
|
1503
|
+
{
|
|
1504
|
+
name: 'Red',
|
|
1505
|
+
color: '#ffdccc',
|
|
1506
|
+
type: 'background'
|
|
1428
1507
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1508
|
+
], /* @ts-ignore */
|
|
1509
|
+
...(ngDevMode ? [{ debugName: "backgroundColors" }] : /* istanbul ignore next */ []));
|
|
1510
|
+
textColorChanged = output();
|
|
1511
|
+
backgroundColorChanged = output();
|
|
1512
|
+
selectRecentlyColor(color) {
|
|
1513
|
+
if (color.type === 'text') {
|
|
1514
|
+
this.selectTextColor(color);
|
|
1436
1515
|
}
|
|
1437
|
-
if (
|
|
1438
|
-
|
|
1439
|
-
return [createBlock('callout', parseText(element), { ...attrs, settings: { variant: ['note', 'tip', 'warning', 'danger'].includes(value ?? '') ? value : 'note' } })];
|
|
1516
|
+
else if (color.type === 'background') {
|
|
1517
|
+
this.selectBackgroundColor(color);
|
|
1440
1518
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1519
|
+
}
|
|
1520
|
+
selectTextColor(color) {
|
|
1521
|
+
this.selectedTextColor.set(color);
|
|
1522
|
+
this.textColorChanged.emit(color.color);
|
|
1523
|
+
this._addToRecently(color);
|
|
1524
|
+
}
|
|
1525
|
+
selectBackgroundColor(color) {
|
|
1526
|
+
this.selectedBackgroundColor.set(color);
|
|
1527
|
+
this.backgroundColorChanged.emit(color.color);
|
|
1528
|
+
this._addToRecently(color);
|
|
1529
|
+
}
|
|
1530
|
+
_addToRecently(color) {
|
|
1531
|
+
const hasRecentlyUsed = this.recentlyUsed()
|
|
1532
|
+
.filter(recentlyColor => recentlyColor.name === color.name && recentlyColor.type === color.type)
|
|
1533
|
+
.length > 0;
|
|
1534
|
+
if (hasRecentlyUsed) {
|
|
1535
|
+
return;
|
|
1445
1536
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
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
|
-
})];
|
|
1537
|
+
let colors = [...this.recentlyUsed()];
|
|
1538
|
+
colors = colors.length >= 5 ? colors.slice(1, 5) : colors;
|
|
1539
|
+
this.recentlyUsed.set([...colors, color]);
|
|
1540
|
+
try {
|
|
1541
|
+
this._document.defaultView?.localStorage.setItem('ngsContentEditorRecentlyUsedTextColor', JSON.stringify(this.recentlyUsed()));
|
|
1456
1542
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
if (child)
|
|
1460
|
-
return media(child, element);
|
|
1543
|
+
catch {
|
|
1544
|
+
// Keep the recent colors in memory when browser storage is unavailable.
|
|
1461
1545
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
const
|
|
1466
|
-
|
|
1546
|
+
}
|
|
1547
|
+
_getRecentlyUsed() {
|
|
1548
|
+
try {
|
|
1549
|
+
const value = this._document.defaultView?.localStorage.getItem('ngsContentEditorRecentlyUsedTextColor');
|
|
1550
|
+
const colors = value ? JSON.parse(value) : [];
|
|
1551
|
+
return Array.isArray(colors) ? colors : [];
|
|
1467
1552
|
}
|
|
1468
|
-
|
|
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)))
|
|
1553
|
+
catch {
|
|
1476
1554
|
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
1555
|
}
|
|
1483
|
-
|
|
1484
|
-
});
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
};
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1556
|
+
}
|
|
1557
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: TextColorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1558
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: TextColorComponent, isStandalone: true, selector: "ngs-text-color", inputs: { recentlyUsed: { classPropertyName: "recentlyUsed", publicName: "recentlyUsed", isSignal: true, isRequired: false, transformFunction: null }, selectedTextColor: { classPropertyName: "selectedTextColor", publicName: "selectedTextColor", isSignal: true, isRequired: false, transformFunction: null }, selectedBackgroundColor: { classPropertyName: "selectedBackgroundColor", publicName: "selectedBackgroundColor", isSignal: true, isRequired: false, transformFunction: null }, textColors: { classPropertyName: "textColors", publicName: "textColors", isSignal: true, isRequired: false, transformFunction: null }, backgroundColors: { classPropertyName: "backgroundColors", publicName: "backgroundColors", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { recentlyUsed: "recentlyUsedChange", selectedTextColor: "selectedTextColorChange", selectedBackgroundColor: "selectedBackgroundColorChange", textColorChanged: "textColorChanged", backgroundColorChanged: "backgroundColorChanged" }, ngImport: i0, template: "@if (recentlyUsed().length > 0) {\n <div class=\"mb-5\">\n <div class=\"text-xs text-on-surface-variant text-semibold\">Recently colors</div>\n <div class=\"flex gap-2 flex-wrap mt-3\">\n @for (recentlyColor of recentlyUsed(); track recentlyColor) {\n @if (recentlyColor.type === 'text') {\n <button class=\"rounded-sm border border-border size-7 flex-none flex items-center justify-center cursor-pointer\"\n [style.color]=\"recentlyColor.color\" [ngsTooltip]=\"recentlyColor.name\" [attr.aria-label]=\"recentlyColor.type + ' color: ' + recentlyColor.name\"\n (click)=\"selectRecentlyColor(recentlyColor)\">\n <ngs-icon name=\"fluent:text-field-24-regular\"/>\n </button>\n } @else if (recentlyColor.type === 'background') {\n <button class=\"rounded-sm border border-border size-7 flex-none flex items-center justify-center cursor-pointer\"\n [style.background-color]=\"recentlyColor.color\" [ngsTooltip]=\"recentlyColor.name\" [attr.aria-label]=\"recentlyColor.type + ' color: ' + recentlyColor.name\"\n (click)=\"selectRecentlyColor(recentlyColor)\">\n </button>\n }\n }\n </div>\n </div>\n}\n\n<div class=\"mb-5\">\n <div class=\"text-xs text-on-surface-variant text-semibold\">Text color</div>\n <div class=\"flex gap-2 flex-wrap mt-3\">\n @for (textColor of textColors(); track $index) {\n <button class=\"rounded-sm border border-border size-7 flex-none flex items-center justify-center cursor-pointer\n [&.is-selected]:outline [&.is-selected]:outline-primary\"\n [style.color]=\"textColor.color\" [ngsTooltip]=\"textColor.name\" [attr.aria-label]=\"'Text color: ' + textColor.name\"\n [class.is-selected]=\"selectedTextColor()?.color === textColor.color\"\n (click)=\"selectTextColor(textColor)\">\n <ngs-icon name=\"fluent:text-field-24-regular\"/>\n </button>\n }\n </div>\n</div>\n\n<div>\n <div class=\"text-xs text-on-surface-variant text-semibold\">Background color</div>\n <div class=\"flex gap-2 flex-wrap mt-3\">\n @for (backgroundColor of backgroundColors(); track $index) {\n <button class=\"rounded-sm border border-border size-7 flex-none flex items-center justify-center cursor-pointer\n [&.is-selected]:outline [&.is-selected]:outline-primary\"\n [style.background-color]=\"backgroundColor.color\" [ngsTooltip]=\"backgroundColor.name\" [attr.aria-label]=\"'Background color: ' + backgroundColor.name\"\n [class.is-selected]=\"selectedBackgroundColor()?.color === backgroundColor.color\"\n (click)=\"selectBackgroundColor(backgroundColor)\">\n </button>\n }\n </div>\n</div>\n", styles: [":host{display:block;width:172px}\n"], dependencies: [{ kind: "component", type: Icon, selector: "ngs-icon", inputs: ["name"], exportAs: ["ngsIcon"] }, { kind: "directive", type: Tooltip, selector: "[ngsTooltip]", inputs: ["ngsTooltip", "ngsTooltipPosition", "ngsTooltipClass", "ngsTooltipShowDelay", "ngsTooltipHideDelay", "ngsTooltipOffset", "ngsTooltipPositionAtOrigin", "ngsTooltipDisabled"], exportAs: ["ngsTooltip"] }], changeDetection: i0.ChangeDetectionStrategy.Eager });
|
|
1559
|
+
}
|
|
1560
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: TextColorComponent, decorators: [{
|
|
1561
|
+
type: Component,
|
|
1562
|
+
args: [{ selector: 'ngs-text-color', imports: [
|
|
1563
|
+
Icon,
|
|
1564
|
+
Tooltip
|
|
1565
|
+
], changeDetection: ChangeDetectionStrategy.Eager, template: "@if (recentlyUsed().length > 0) {\n <div class=\"mb-5\">\n <div class=\"text-xs text-on-surface-variant text-semibold\">Recently colors</div>\n <div class=\"flex gap-2 flex-wrap mt-3\">\n @for (recentlyColor of recentlyUsed(); track recentlyColor) {\n @if (recentlyColor.type === 'text') {\n <button class=\"rounded-sm border border-border size-7 flex-none flex items-center justify-center cursor-pointer\"\n [style.color]=\"recentlyColor.color\" [ngsTooltip]=\"recentlyColor.name\" [attr.aria-label]=\"recentlyColor.type + ' color: ' + recentlyColor.name\"\n (click)=\"selectRecentlyColor(recentlyColor)\">\n <ngs-icon name=\"fluent:text-field-24-regular\"/>\n </button>\n } @else if (recentlyColor.type === 'background') {\n <button class=\"rounded-sm border border-border size-7 flex-none flex items-center justify-center cursor-pointer\"\n [style.background-color]=\"recentlyColor.color\" [ngsTooltip]=\"recentlyColor.name\" [attr.aria-label]=\"recentlyColor.type + ' color: ' + recentlyColor.name\"\n (click)=\"selectRecentlyColor(recentlyColor)\">\n </button>\n }\n }\n </div>\n </div>\n}\n\n<div class=\"mb-5\">\n <div class=\"text-xs text-on-surface-variant text-semibold\">Text color</div>\n <div class=\"flex gap-2 flex-wrap mt-3\">\n @for (textColor of textColors(); track $index) {\n <button class=\"rounded-sm border border-border size-7 flex-none flex items-center justify-center cursor-pointer\n [&.is-selected]:outline [&.is-selected]:outline-primary\"\n [style.color]=\"textColor.color\" [ngsTooltip]=\"textColor.name\" [attr.aria-label]=\"'Text color: ' + textColor.name\"\n [class.is-selected]=\"selectedTextColor()?.color === textColor.color\"\n (click)=\"selectTextColor(textColor)\">\n <ngs-icon name=\"fluent:text-field-24-regular\"/>\n </button>\n }\n </div>\n</div>\n\n<div>\n <div class=\"text-xs text-on-surface-variant text-semibold\">Background color</div>\n <div class=\"flex gap-2 flex-wrap mt-3\">\n @for (backgroundColor of backgroundColors(); track $index) {\n <button class=\"rounded-sm border border-border size-7 flex-none flex items-center justify-center cursor-pointer\n [&.is-selected]:outline [&.is-selected]:outline-primary\"\n [style.background-color]=\"backgroundColor.color\" [ngsTooltip]=\"backgroundColor.name\" [attr.aria-label]=\"'Background color: ' + backgroundColor.name\"\n [class.is-selected]=\"selectedBackgroundColor()?.color === backgroundColor.color\"\n (click)=\"selectBackgroundColor(backgroundColor)\">\n </button>\n }\n </div>\n</div>\n", styles: [":host{display:block;width:172px}\n"] }]
|
|
1566
|
+
}], propDecorators: { recentlyUsed: [{ type: i0.Input, args: [{ isSignal: true, alias: "recentlyUsed", required: false }] }, { type: i0.Output, args: ["recentlyUsedChange"] }], selectedTextColor: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedTextColor", required: false }] }, { type: i0.Output, args: ["selectedTextColorChange"] }], selectedBackgroundColor: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedBackgroundColor", required: false }] }, { type: i0.Output, args: ["selectedBackgroundColorChange"] }], textColors: [{ type: i0.Input, args: [{ isSignal: true, alias: "textColors", required: false }] }], backgroundColors: [{ type: i0.Input, args: [{ isSignal: true, alias: "backgroundColors", required: false }] }], textColorChanged: [{ type: i0.Output, args: ["textColorChanged"] }], backgroundColorChanged: [{ type: i0.Output, args: ["backgroundColorChanged"] }] } });
|
|
1567
|
+
|
|
1568
|
+
class CommandBarComponent {
|
|
1569
|
+
editor = inject(NgsHeadlessEditor);
|
|
1570
|
+
dialog = inject(Dialog);
|
|
1571
|
+
observedElement = input(null, /* @ts-ignore */
|
|
1572
|
+
...(ngDevMode ? [{ debugName: "observedElement" }] : /* istanbul ignore next */ []));
|
|
1573
|
+
alignment = computed(() => this.region()?.alignment() ?? 'left', /* @ts-ignore */
|
|
1574
|
+
...(ngDevMode ? [{ debugName: "alignment" }] : /* istanbul ignore next */ []));
|
|
1575
|
+
savedSelection = null;
|
|
1576
|
+
region() { return ContentEditorContentEditableDirective.forElement(this.observedElement()); }
|
|
1577
|
+
toggleBold() { this.editor.execute(NGS_HEADLESS_EDITOR_TOGGLE_BOLD); }
|
|
1578
|
+
toggleItalic() { this.editor.execute(NGS_HEADLESS_EDITOR_TOGGLE_ITALIC); }
|
|
1579
|
+
toggleCode() { this.editor.execute(NGS_HEADLESS_EDITOR_TOGGLE_CODE); }
|
|
1580
|
+
toggleStrike() { this.editor.execute(NGS_HEADLESS_EDITOR_TOGGLE_STRIKE); }
|
|
1581
|
+
toggleUnderline() { this.editor.execute(NGS_HEADLESS_EDITOR_TOGGLE_UNDERLINE); }
|
|
1582
|
+
toggleSuperscript() { this.editor.execute(NGS_HEADLESS_EDITOR_TOGGLE_SUPERSCRIPT); }
|
|
1583
|
+
toggleSubscript() { this.editor.execute(NGS_HEADLESS_EDITOR_TOGGLE_SUBSCRIPT); }
|
|
1584
|
+
isLinkActive() { return this.editor.isMarkActive('link'); }
|
|
1585
|
+
isActive(tag) {
|
|
1586
|
+
return this.editor.isMarkActive({ strong: 'bold', em: 'italic', s: 'strike', u: 'underline', sup: 'superscript', sub: 'subscript' }[tag] ?? tag);
|
|
1587
|
+
}
|
|
1588
|
+
setTextAlignment(value) { this.restoreSelection()?.setAlignment(value); }
|
|
1589
|
+
isTextAlignment(value) { return this.alignment() === value; }
|
|
1590
|
+
addLink() { this.openLinkDialog(false); }
|
|
1591
|
+
editLink() { this.openLinkDialog(true); }
|
|
1592
|
+
openLinkDialog(edit) {
|
|
1593
|
+
this.retainSelection();
|
|
1594
|
+
const saved = this.savedSelection;
|
|
1595
|
+
if (!saved)
|
|
1596
|
+
return;
|
|
1597
|
+
const target = saved.region.region.editor;
|
|
1598
|
+
const mark = target.getActiveMark('link');
|
|
1599
|
+
const ref = edit
|
|
1600
|
+
? this.dialog.open(EditLinkDialog, { data: { href: mark?.attrs?.['href'], openInNewTab: mark?.attrs?.['target'] === '_blank' }, width: '500px', restoreFocus: false })
|
|
1601
|
+
: this.dialog.open(AddLinkDialog, { width: '500px', restoreFocus: false });
|
|
1602
|
+
ref.afterClosed().subscribe((value) => {
|
|
1603
|
+
if (!this.restoreSelection())
|
|
1604
|
+
return;
|
|
1605
|
+
if (value) {
|
|
1606
|
+
if (value.href)
|
|
1607
|
+
this.editor.execute(NGS_HEADLESS_EDITOR_SET_LINK, { href: value.href, target: value.openInNewTab ? '_blank' : '_self' });
|
|
1608
|
+
else
|
|
1609
|
+
this.editor.execute(NGS_HEADLESS_EDITOR_UNSET_LINK);
|
|
1510
1610
|
}
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1611
|
+
this.restoreSelectionAfterOverlay();
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
preserveSelection(event) {
|
|
1615
|
+
event.preventDefault();
|
|
1616
|
+
this.region()?.activate();
|
|
1617
|
+
this.retainSelection();
|
|
1618
|
+
}
|
|
1619
|
+
retainSelection() {
|
|
1620
|
+
if (this.savedSelection)
|
|
1621
|
+
return;
|
|
1622
|
+
const region = this.region();
|
|
1623
|
+
const selection = region?.region.editor.selection();
|
|
1624
|
+
if (region && selection)
|
|
1625
|
+
this.savedSelection = { region, selection };
|
|
1626
|
+
}
|
|
1627
|
+
restoreSelection() {
|
|
1628
|
+
const saved = this.savedSelection;
|
|
1629
|
+
if (!saved)
|
|
1630
|
+
return this.region();
|
|
1631
|
+
if (!this.observedElement()?.isConnected || saved.region.region.editor !== this.editor.inlineTarget())
|
|
1632
|
+
return;
|
|
1633
|
+
saved.region.region.editor.setSelection(saved.selection);
|
|
1634
|
+
return saved.region;
|
|
1635
|
+
}
|
|
1636
|
+
restoreSelectionAfterOverlay() {
|
|
1637
|
+
// MenuTrigger restores its own focus after emitting menuClosed.
|
|
1638
|
+
// Restore the editor afterwards, using model points rather than old DOM nodes.
|
|
1639
|
+
Promise.resolve().then(() => {
|
|
1640
|
+
const region = this.restoreSelection();
|
|
1641
|
+
this.savedSelection = null;
|
|
1642
|
+
if (region && this.observedElement()?.isConnected)
|
|
1643
|
+
region.focus();
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1646
|
+
preventMenuClose(event) { event.stopPropagation(); event.preventDefault(); }
|
|
1647
|
+
onTextColorChanged(color) {
|
|
1648
|
+
const region = this.restoreSelection();
|
|
1649
|
+
if (!region)
|
|
1650
|
+
return;
|
|
1651
|
+
if (color)
|
|
1652
|
+
this.editor.execute(NGS_HEADLESS_EDITOR_SET_TEXT_COLOR, color);
|
|
1653
|
+
else
|
|
1654
|
+
this.editor.execute(NGS_HEADLESS_EDITOR_UNSET_TEXT_COLOR);
|
|
1655
|
+
region.focus();
|
|
1656
|
+
}
|
|
1657
|
+
onBackgroundColorChanged(color) {
|
|
1658
|
+
const region = this.restoreSelection();
|
|
1659
|
+
if (!region)
|
|
1660
|
+
return;
|
|
1661
|
+
if (color)
|
|
1662
|
+
this.editor.execute(NGS_HEADLESS_EDITOR_SET_BACKGROUND_COLOR, color);
|
|
1663
|
+
else
|
|
1664
|
+
this.editor.execute(NGS_HEADLESS_EDITOR_UNSET_BACKGROUND_COLOR);
|
|
1665
|
+
region.focus();
|
|
1666
|
+
}
|
|
1667
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: CommandBarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1668
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: CommandBarComponent, isStandalone: true, selector: "ngs-command-bar", inputs: { observedElement: { classPropertyName: "observedElement", publicName: "observedElement", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "mousedown": "preserveSelection($event)" }, classAttribute: "ngs-command-bar" }, ngImport: i0, template: "<div class=\"flex items-center gap-1\">\n <button ngsIconButton (click)=\"toggleBold()\"\n [class.is-active]=\"isActive('strong')\">\n <ngs-icon name=\"fluent:text-bold-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleItalic()\"\n [class.is-active]=\"isActive('em')\">\n <ngs-icon name=\"fluent:text-italic-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleStrike()\"\n [class.is-active]=\"isActive('s')\">\n <ngs-icon name=\"fluent:text-strikethrough-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleUnderline()\"\n [class.is-active]=\"isActive('u')\">\n <ngs-icon name=\"fluent:text-underline-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleSuperscript()\"\n [class.is-active]=\"isActive('sup')\">\n <ngs-icon name=\"fluent:text-superscript-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleSubscript()\"\n [class.is-active]=\"isActive('sub')\">\n <ngs-icon name=\"fluent:text-subscript-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleCode()\"\n [class.is-active]=\"isActive('code')\">\n <ngs-icon name=\"fluent:code-24-regular\"/>\n </button>\n\n @if (isLinkActive()) {\n <button ngsIconButton (click)=\"editLink()\">\n <ngs-icon name=\"fluent:link-24-regular\"/>\n </button>\n } @else {\n <button ngsIconButton (click)=\"addLink()\">\n <ngs-icon name=\"fluent:link-add-24-regular\"/>\n </button>\n }\n <button ngsIconButton [ngsMenuTriggerFor]=\"alignMenu\"\n (menuOpened)=\"retainSelection()\" (menuClosed)=\"restoreSelectionAfterOverlay()\">\n @switch (alignment()) {\n @case ('left') {\n <ngs-icon name=\"fluent:text-align-left-24-regular\"/>\n }\n @case ('center') {\n <ngs-icon name=\"fluent:text-align-center-24-regular\"/>\n }\n @case ('right') {\n <ngs-icon name=\"fluent:text-align-right-24-regular\"/>\n }\n }\n </button>\n <button ngsIconButton [ngsMenuTriggerFor]=\"formatColorText\"\n (menuOpened)=\"retainSelection()\" (menuClosed)=\"restoreSelectionAfterOverlay()\">\n <ngs-icon name=\"fluent:text-color-24-regular\"/>\n </button>\n</div>\n\n<ngs-menu #alignMenu=\"ngsMenu\" [themeSource]=\"observedElement()\">\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('left')\"\n ngs-menu-item\n (click)=\"setTextAlignment('left')\">\n <ngs-icon name=\"fluent:text-align-left-24-regular\"/>\n Align Left\n </button>\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('center')\"\n ngs-menu-item\n (click)=\"setTextAlignment('center')\">\n <ngs-icon name=\"fluent:text-align-center-24-regular\"/>\n Align Center\n </button>\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('right')\"\n ngs-menu-item (click)=\"setTextAlignment('right')\">\n <ngs-icon name=\"fluent:text-align-right-24-regular\"/>\n Align Right\n </button>\n</ngs-menu>\n\n<ngs-menu #formatColorText=\"ngsMenu\" [themeSource]=\"observedElement()\">\n <div class=\"px-4 py-3\" (mousedown)=\"preventMenuClose($event)\">\n <ngs-text-color (textColorChanged)=\"onTextColorChanged($event)\"\n (backgroundColorChanged)=\"onBackgroundColorChanged($event)\"/>\n </div>\n</ngs-menu>\n", styles: [":host{background:var(--ngs-content-editor-toolbar-bg, var(--ngs-color-on-surface));color:var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface));border-radius:var(--ngs-content-editor-toolbar-radius, var(--ngs-control-radius));padding:var(--spacing, .25rem);box-shadow:var(--ngs-shadow-lg)}:host button[ngsIconButton]{--ngs-button-color: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface));--ngs-button-hover-bg: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface));--ngs-state-focus-ring: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface))}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton]{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface)) 12%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton]{--ngs-state-focus-ring: color-mix(in srgb, var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface)) 40%, transparent)}}:host button[ngsIconButton].is-active{--ngs-button-bg: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface));--ngs-button-hover-bg: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface))}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].is-active{--ngs-button-bg: color-mix(in srgb, var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface)) 20%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].is-active{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface)) 28%, transparent)}}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "component", type: Button, selector: " button[ngsButton], button[ngsIconButton], a[ngsButton], a[ngsIconButton] ", inputs: ["ngsButton", "ngsIconButton", "loading", "disabled", "disabledInteractive", "disableRipple", "reverse", "fullWidth", "hideTextOnMobile"], exportAs: ["ngsButton"] }, { kind: "component", type: Icon, selector: "ngs-icon", inputs: ["name"], exportAs: ["ngsIcon"] }, { kind: "component", type: Menu, selector: "ngs-menu", inputs: ["themeSource", "role", "classList", "xPosition", "yPosition", "pushIntoViewport"], outputs: ["closed"], exportAs: ["ngsMenu"] }, { kind: "component", type: MenuItem, selector: "ngs-menu-item, [ngs-menu-item]", inputs: ["disabled", "role", "selected"], outputs: ["_triggered"], exportAs: ["ngsMenuItem"] }, { kind: "directive", type: MenuTrigger, selector: "[ngsMenuTriggerFor]", inputs: ["ngsMenuTriggerFor", "ngsMenuTriggerData", "ngsMenuDisabled", "xPosition", "yPosition", "ngsMenuTriggerRestoreFocus"], outputs: ["menuOpened", "menuClosed"], exportAs: ["ngsMenuTrigger"] }, { kind: "component", type: TextColorComponent, selector: "ngs-text-color", inputs: ["recentlyUsed", "selectedTextColor", "selectedBackgroundColor", "textColors", "backgroundColors"], outputs: ["recentlyUsedChange", "selectedTextColorChange", "selectedBackgroundColorChange", "textColorChanged", "backgroundColorChanged"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1669
|
+
}
|
|
1670
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: CommandBarComponent, decorators: [{
|
|
1671
|
+
type: Component,
|
|
1672
|
+
args: [{ selector: 'ngs-command-bar', imports: [Button, Icon, Menu, MenuItem, MenuTrigger, TextColorComponent], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
1673
|
+
'class': 'ngs-command-bar',
|
|
1674
|
+
'(mousedown)': 'preserveSelection($event)'
|
|
1675
|
+
}, template: "<div class=\"flex items-center gap-1\">\n <button ngsIconButton (click)=\"toggleBold()\"\n [class.is-active]=\"isActive('strong')\">\n <ngs-icon name=\"fluent:text-bold-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleItalic()\"\n [class.is-active]=\"isActive('em')\">\n <ngs-icon name=\"fluent:text-italic-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleStrike()\"\n [class.is-active]=\"isActive('s')\">\n <ngs-icon name=\"fluent:text-strikethrough-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleUnderline()\"\n [class.is-active]=\"isActive('u')\">\n <ngs-icon name=\"fluent:text-underline-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleSuperscript()\"\n [class.is-active]=\"isActive('sup')\">\n <ngs-icon name=\"fluent:text-superscript-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleSubscript()\"\n [class.is-active]=\"isActive('sub')\">\n <ngs-icon name=\"fluent:text-subscript-24-regular\"/>\n </button>\n <button ngsIconButton (click)=\"toggleCode()\"\n [class.is-active]=\"isActive('code')\">\n <ngs-icon name=\"fluent:code-24-regular\"/>\n </button>\n\n @if (isLinkActive()) {\n <button ngsIconButton (click)=\"editLink()\">\n <ngs-icon name=\"fluent:link-24-regular\"/>\n </button>\n } @else {\n <button ngsIconButton (click)=\"addLink()\">\n <ngs-icon name=\"fluent:link-add-24-regular\"/>\n </button>\n }\n <button ngsIconButton [ngsMenuTriggerFor]=\"alignMenu\"\n (menuOpened)=\"retainSelection()\" (menuClosed)=\"restoreSelectionAfterOverlay()\">\n @switch (alignment()) {\n @case ('left') {\n <ngs-icon name=\"fluent:text-align-left-24-regular\"/>\n }\n @case ('center') {\n <ngs-icon name=\"fluent:text-align-center-24-regular\"/>\n }\n @case ('right') {\n <ngs-icon name=\"fluent:text-align-right-24-regular\"/>\n }\n }\n </button>\n <button ngsIconButton [ngsMenuTriggerFor]=\"formatColorText\"\n (menuOpened)=\"retainSelection()\" (menuClosed)=\"restoreSelectionAfterOverlay()\">\n <ngs-icon name=\"fluent:text-color-24-regular\"/>\n </button>\n</div>\n\n<ngs-menu #alignMenu=\"ngsMenu\" [themeSource]=\"observedElement()\">\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('left')\"\n ngs-menu-item\n (click)=\"setTextAlignment('left')\">\n <ngs-icon name=\"fluent:text-align-left-24-regular\"/>\n Align Left\n </button>\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('center')\"\n ngs-menu-item\n (click)=\"setTextAlignment('center')\">\n <ngs-icon name=\"fluent:text-align-center-24-regular\"/>\n Align Center\n </button>\n <button class=\"[&.is-active]:!bg-secondary-container\"\n [class.is-active]=\"isTextAlignment('right')\"\n ngs-menu-item (click)=\"setTextAlignment('right')\">\n <ngs-icon name=\"fluent:text-align-right-24-regular\"/>\n Align Right\n </button>\n</ngs-menu>\n\n<ngs-menu #formatColorText=\"ngsMenu\" [themeSource]=\"observedElement()\">\n <div class=\"px-4 py-3\" (mousedown)=\"preventMenuClose($event)\">\n <ngs-text-color (textColorChanged)=\"onTextColorChanged($event)\"\n (backgroundColorChanged)=\"onBackgroundColorChanged($event)\"/>\n </div>\n</ngs-menu>\n", styles: [":host{background:var(--ngs-content-editor-toolbar-bg, var(--ngs-color-on-surface));color:var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface));border-radius:var(--ngs-content-editor-toolbar-radius, var(--ngs-control-radius));padding:var(--spacing, .25rem);box-shadow:var(--ngs-shadow-lg)}:host button[ngsIconButton]{--ngs-button-color: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface));--ngs-button-hover-bg: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface));--ngs-state-focus-ring: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface))}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton]{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface)) 12%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton]{--ngs-state-focus-ring: color-mix(in srgb, var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface)) 40%, transparent)}}:host button[ngsIconButton].is-active{--ngs-button-bg: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface));--ngs-button-hover-bg: var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface))}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].is-active{--ngs-button-bg: color-mix(in srgb, var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface)) 20%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].is-active{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-content-editor-toolbar-color, var(--ngs-color-surface)) 28%, transparent)}}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
1676
|
+
}], propDecorators: { observedElement: [{ type: i0.Input, args: [{ isSignal: true, alias: "observedElement", required: false }] }] } });
|
|
1677
|
+
|
|
1678
|
+
/** Shared marks and commands for content editing and read-only rendering. */
|
|
1679
|
+
function provideContentEditor() {
|
|
1680
|
+
return provideNgsHeadlessEditor(withHeadlessEditorPlugin(basicTextEditorPlugin()), withHeadlessEditorPlugin(colorEditorPlugin()), withHeadlessEditorPlugin(linkEditorPlugin()));
|
|
1517
1681
|
}
|
|
1518
1682
|
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1683
|
+
const CONTENT_EDITOR_EXTRA_BLOCK_DEFS = [
|
|
1684
|
+
{
|
|
1685
|
+
type: 'callout', component: () => import('./ngstarter-ui-components-content-editor-callout-block-CyVPVMXi.mjs').then(m => m.ContentEditorCalloutBlock),
|
|
1686
|
+
empty: () => ({ content: [createNgsHeadlessEditorText()], settings: { variant: 'note' } }), options: {}
|
|
1687
|
+
},
|
|
1688
|
+
{
|
|
1689
|
+
type: 'toggle', component: () => import('./ngstarter-ui-components-content-editor-toggle-block-CHtnu1GQ.mjs').then(m => m.ContentEditorToggleBlock),
|
|
1690
|
+
empty: () => ({ content: { title: [], blocks: [emptyParagraph()] }, settings: { expanded: true } }), options: {}
|
|
1691
|
+
},
|
|
1692
|
+
{
|
|
1693
|
+
type: 'attachment', component: () => import('./ngstarter-ui-components-content-editor-attachment-block-DZqyCrEK.mjs').then(m => m.ContentEditorAttachmentBlock),
|
|
1694
|
+
empty: () => ({ content: { url: '', name: '', size: 0, mimeType: '' }, settings: {} }),
|
|
1695
|
+
options: { uploadFn: (_file, dataUrl) => Promise.resolve(dataUrl) }
|
|
1696
|
+
},
|
|
1697
|
+
{
|
|
1698
|
+
type: 'gallery', component: () => import('./ngstarter-ui-components-content-editor-gallery-block-CBuzrmSH.mjs').then(m => m.ContentEditorGalleryBlock),
|
|
1699
|
+
empty: () => ({ content: { images: [] }, settings: {} }),
|
|
1700
|
+
options: { uploadFn: (_file, dataUrl) => Promise.resolve(dataUrl) }
|
|
1701
|
+
},
|
|
1702
|
+
{
|
|
1703
|
+
type: 'grid', component: () => import('./ngstarter-ui-components-content-editor-grid-block-Sy67i4mg.mjs').then(m => m.ContentEditorGridBlock),
|
|
1704
|
+
empty: () => ({ content: { cells: Array.from({ length: 4 }, emptyGridCell) }, settings: { columns: 2, gap: 'medium', stackOnMobile: true } }), options: {}
|
|
1528
1705
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1706
|
+
].map(def => ({ ...def, toHtml: CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS[def.type] }));
|
|
1707
|
+
function emptyParagraph() {
|
|
1708
|
+
return { id: createNgsHeadlessEditorId('paragraph'), type: 'paragraph', content: [createNgsHeadlessEditorText()] };
|
|
1531
1709
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1710
|
+
function emptyGridCell() { return { id: createNgsHeadlessEditorId('cell'), blocks: [emptyParagraph()] }; }
|
|
1711
|
+
const CONTENT_EDITOR_EXTRA_SUGGESTIONS = [
|
|
1712
|
+
{ type: 'heading', title: 'Content & layout' },
|
|
1713
|
+
...[
|
|
1714
|
+
['callout', 'Callout', 'Notes, tips and warnings', 'fluent:info-24-regular'],
|
|
1715
|
+
['toggle', 'Toggle', 'Collapsible content with nested blocks', 'fluent:chevron-down-24-regular'],
|
|
1716
|
+
['attachment', 'Attachment', 'Upload a file for download', 'fluent:attach-24-regular'],
|
|
1717
|
+
['gallery', 'Gallery', 'Image carousel with captions', 'fluent:image-multiple-24-regular'],
|
|
1718
|
+
['grid', 'Grid', 'Responsive grid with nested blocks', 'fluent:grid-24-regular']
|
|
1719
|
+
].map(([blockType, title, description, iconName]) => ({ type: 'item', blockType, title, description, iconName, blockSettings: {} }))
|
|
1720
|
+
];
|
|
1536
1721
|
|
|
1537
|
-
const
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1722
|
+
const browserStorage = {
|
|
1723
|
+
getItem: key => globalThis.localStorage.getItem(key),
|
|
1724
|
+
setItem: (key, value) => globalThis.localStorage.setItem(key, value),
|
|
1725
|
+
removeItem: key => globalThis.localStorage.removeItem(key)
|
|
1726
|
+
};
|
|
1727
|
+
/** Delayed persistence keeps storage errors visible and flushes before switching documents. */
|
|
1728
|
+
class ContentEditorDraftController {
|
|
1729
|
+
status = signal('disabled', /* @ts-ignore */
|
|
1730
|
+
...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
|
|
1731
|
+
error = signal('', /* @ts-ignore */
|
|
1732
|
+
...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
1733
|
+
savedAt = signal(null, /* @ts-ignore */
|
|
1734
|
+
...(ngDevMode ? [{ debugName: "savedAt" }] : /* istanbul ignore next */ []));
|
|
1735
|
+
key = '';
|
|
1736
|
+
storage = browserStorage;
|
|
1737
|
+
debounceMs = 500;
|
|
1738
|
+
enabled = false;
|
|
1739
|
+
pending = null;
|
|
1740
|
+
timer = null;
|
|
1741
|
+
configure(key, enabled, config = {}) {
|
|
1742
|
+
const storage = config.storage ?? browserStorage;
|
|
1743
|
+
if (this.key !== key || this.enabled !== enabled || this.storage !== storage) {
|
|
1744
|
+
this.flush();
|
|
1745
|
+
this.key = key;
|
|
1746
|
+
this.enabled = enabled;
|
|
1747
|
+
this.storage = storage;
|
|
1748
|
+
this.status.set(enabled ? 'idle' : 'disabled');
|
|
1749
|
+
this.error.set('');
|
|
1750
|
+
this.savedAt.set(null);
|
|
1549
1751
|
}
|
|
1550
|
-
|
|
1551
|
-
if (config.includeStyles !== undefined)
|
|
1552
|
-
result.includeStyles = config.includeStyles;
|
|
1553
|
-
if (config.importMarks !== undefined)
|
|
1554
|
-
result.importMarks = config.importMarks;
|
|
1555
|
-
if (config.unknownBlockToHtml !== undefined)
|
|
1556
|
-
result.unknownBlockToHtml = config.unknownBlockToHtml;
|
|
1752
|
+
this.debounceMs = Number.isFinite(config.debounceMs) ? Math.max(0, config.debounceMs) : 500;
|
|
1557
1753
|
}
|
|
1558
|
-
|
|
1754
|
+
read(validate) {
|
|
1755
|
+
if (!this.enabled)
|
|
1756
|
+
return null;
|
|
1757
|
+
try {
|
|
1758
|
+
const source = this.storage.getItem(this.key);
|
|
1759
|
+
if (!source)
|
|
1760
|
+
return null;
|
|
1761
|
+
const document = validate(source);
|
|
1762
|
+
this.status.set('saved');
|
|
1763
|
+
return document;
|
|
1764
|
+
}
|
|
1765
|
+
catch (error) {
|
|
1766
|
+
this.fail(error);
|
|
1767
|
+
return null;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
schedule(document) {
|
|
1771
|
+
if (!this.enabled)
|
|
1772
|
+
return;
|
|
1773
|
+
this.pending = document;
|
|
1774
|
+
this.status.set('saving');
|
|
1775
|
+
this.error.set('');
|
|
1776
|
+
if (this.timer)
|
|
1777
|
+
clearTimeout(this.timer);
|
|
1778
|
+
this.timer = setTimeout(() => this.flush(), this.debounceMs);
|
|
1779
|
+
}
|
|
1780
|
+
flush() {
|
|
1781
|
+
if (this.timer)
|
|
1782
|
+
clearTimeout(this.timer);
|
|
1783
|
+
this.timer = null;
|
|
1784
|
+
if (!this.enabled || !this.pending)
|
|
1785
|
+
return;
|
|
1786
|
+
const document = this.pending;
|
|
1787
|
+
this.pending = null;
|
|
1788
|
+
try {
|
|
1789
|
+
this.storage.setItem(this.key, JSON.stringify(document));
|
|
1790
|
+
this.status.set('saved');
|
|
1791
|
+
this.error.set('');
|
|
1792
|
+
this.savedAt.set(Date.now());
|
|
1793
|
+
}
|
|
1794
|
+
catch (error) {
|
|
1795
|
+
this.fail(error);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
clear() {
|
|
1799
|
+
if (this.timer)
|
|
1800
|
+
clearTimeout(this.timer);
|
|
1801
|
+
this.timer = null;
|
|
1802
|
+
this.pending = null;
|
|
1803
|
+
if (!this.enabled)
|
|
1804
|
+
return;
|
|
1805
|
+
try {
|
|
1806
|
+
this.storage.removeItem(this.key);
|
|
1807
|
+
this.status.set('idle');
|
|
1808
|
+
this.error.set('');
|
|
1809
|
+
this.savedAt.set(null);
|
|
1810
|
+
}
|
|
1811
|
+
catch (error) {
|
|
1812
|
+
this.fail(error);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
fail(error) { this.error.set(error instanceof Error ? error.message : 'Could not save draft'); this.status.set('error'); }
|
|
1559
1816
|
}
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
])
|
|
1817
|
+
|
|
1818
|
+
const CONTENT_EDITOR_CONVERTIBLE_BLOCKS = ['paragraph', 'heading', 'quote', 'callout'];
|
|
1819
|
+
/** Retains identity, rich text and alignment. Quote attribution becomes a final line. */
|
|
1820
|
+
function contentEditorConvertBlock(block, type, settings = {}) {
|
|
1821
|
+
if (!CONTENT_EDITOR_CONVERTIBLE_BLOCKS.includes(block.type) || !CONTENT_EDITOR_CONVERTIBLE_BLOCKS.includes(type)) {
|
|
1822
|
+
throw new Error(`Cannot convert ${block.type} to ${type}`);
|
|
1823
|
+
}
|
|
1824
|
+
if (type === 'heading' && settings['level'] !== undefined && ![1, 2, 3, 4, 5, 6].includes(settings['level']))
|
|
1825
|
+
throw new Error('Heading level must be between 1 and 6');
|
|
1826
|
+
if (type === 'callout' && settings['variant'] !== undefined && !['note', 'tip', 'warning', 'danger'].includes(settings['variant']))
|
|
1827
|
+
throw new Error('Unsupported callout variant');
|
|
1828
|
+
const next = cloneContentEditorValue(block);
|
|
1829
|
+
if (type === block.type)
|
|
1830
|
+
return { ...next, attrs: { ...next.attrs, settings: { ...next.attrs?.['settings'], ...settings } } };
|
|
1831
|
+
const quote = block.type === 'quote' ? block.content : null;
|
|
1832
|
+
const cite = quote ? quote.cite.content : block.content;
|
|
1833
|
+
const caption = quote?.caption?.content ?? [];
|
|
1834
|
+
const text = normalizeNgsHeadlessEditorTextContent(caption.some(run => run.text)
|
|
1835
|
+
? [...cite, createNgsHeadlessEditorText('\n'), ...caption] : cite);
|
|
1836
|
+
const props = (quote?.cite.props ?? block.attrs?.['props'] ?? []);
|
|
1837
|
+
const defaults = type === 'heading' ? { level: 2 } : type === 'callout' ? { variant: 'note' } : {};
|
|
1838
|
+
return { ...next, type,
|
|
1839
|
+
content: type === 'quote' ? { cite: { content: text, props }, caption: { content: [], props: [] } } : text,
|
|
1840
|
+
attrs: { ...next.attrs, props, settings: { ...defaults, ...(type === block.type ? next.attrs?.['settings'] : {}), ...settings } }
|
|
1841
|
+
};
|
|
1570
1842
|
}
|
|
1571
1843
|
|
|
1572
|
-
// src/app/text-selection-popup.directive.ts
|
|
1573
1844
|
const POPUP_VERTICAL_OFFSET = 8;
|
|
1574
1845
|
const POPUP_VIEWPORT_MARGIN = 8;
|
|
1575
1846
|
class TextSelectionPopupDirective {
|
|
@@ -1582,6 +1853,7 @@ class TextSelectionPopupDirective {
|
|
|
1582
1853
|
targetComponent;
|
|
1583
1854
|
closestContentObserverClass = null;
|
|
1584
1855
|
tagSelected = new EventEmitter();
|
|
1856
|
+
themeCleanup = null;
|
|
1585
1857
|
overlayRef = null;
|
|
1586
1858
|
hostElement;
|
|
1587
1859
|
currentSelectionRange = null;
|
|
@@ -1693,6 +1965,7 @@ class TextSelectionPopupDirective {
|
|
|
1693
1965
|
hasBackdrop: false,
|
|
1694
1966
|
scrollStrategy: this.overlay.scrollStrategies.noop(),
|
|
1695
1967
|
});
|
|
1968
|
+
this.themeCleanup = bindNgsOverlayTheme(this.hostElement, this.overlayRef.overlayElement);
|
|
1696
1969
|
const portal = new ComponentPortal(this.targetComponent, this.viewContainerRef);
|
|
1697
1970
|
const componentRef = this.overlayRef.attach(portal);
|
|
1698
1971
|
if (componentRef.instance && 'observedElement' in componentRef.instance) {
|
|
@@ -1720,6 +1993,8 @@ class TextSelectionPopupDirective {
|
|
|
1720
1993
|
return;
|
|
1721
1994
|
this.popupResizeObserver?.disconnect();
|
|
1722
1995
|
this.popupResizeObserver = null;
|
|
1996
|
+
this.themeCleanup?.();
|
|
1997
|
+
this.themeCleanup = null;
|
|
1723
1998
|
this.overlayRef.dispose();
|
|
1724
1999
|
this.overlayRef = null;
|
|
1725
2000
|
this.positionStrategy = null;
|
|
@@ -2006,9 +2281,20 @@ class ContentBuilderComponent {
|
|
|
2006
2281
|
config = input({}, /* @ts-ignore */
|
|
2007
2282
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
2008
2283
|
/** One insertion menu shared by root controls, nested collections and custom blocks. */
|
|
2284
|
+
conversionMenu = viewChild.required('conversionMenu', /* @ts-ignore */
|
|
2285
|
+
...(ngDevMode ? [{ debugName: "conversionMenu" }] : /* istanbul ignore next */ []));
|
|
2286
|
+
conversionTypes = CONTENT_EDITOR_CONVERTIBLE_BLOCKS;
|
|
2009
2287
|
blockMenu = viewChild.required('suggestionsMenu', /* @ts-ignore */
|
|
2010
2288
|
...(ngDevMode ? [{ debugName: "blockMenu" }] : /* istanbul ignore next */ []));
|
|
2011
2289
|
document = inject(DOCUMENT);
|
|
2290
|
+
drafts = new ContentEditorDraftController();
|
|
2291
|
+
draftStatus = this.drafts.status;
|
|
2292
|
+
draftError = this.drafts.error;
|
|
2293
|
+
draftSavedAt = this.drafts.savedAt;
|
|
2294
|
+
documentId = input(/* @ts-ignore */
|
|
2295
|
+
...(ngDevMode ? [undefined, { debugName: "documentId" }] : /* istanbul ignore next */ []));
|
|
2296
|
+
draftDebounceMs = input(undefined, { ...(ngDevMode ? { debugName: "draftDebounceMs" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
2297
|
+
draftKey = '';
|
|
2012
2298
|
loaded = false;
|
|
2013
2299
|
lastInput = null;
|
|
2014
2300
|
_platformId = inject(PLATFORM_ID);
|
|
@@ -2016,7 +2302,8 @@ class ContentBuilderComponent {
|
|
|
2016
2302
|
dropList = viewChild.required(CdkDropList, /* @ts-ignore */
|
|
2017
2303
|
...(ngDevMode ? [{ debugName: "dropList" }] : /* istanbul ignore next */ []));
|
|
2018
2304
|
connectedDropLists = this._store.dropLists;
|
|
2019
|
-
elRef = inject(
|
|
2305
|
+
elRef = inject(ElementRef);
|
|
2306
|
+
themeSource = this.elRef.nativeElement;
|
|
2020
2307
|
envInjector = inject(EnvironmentInjector);
|
|
2021
2308
|
cdr = inject(ChangeDetectorRef);
|
|
2022
2309
|
confirmManager = inject(ConfirmManager);
|
|
@@ -2045,7 +2332,7 @@ class ContentBuilderComponent {
|
|
|
2045
2332
|
}
|
|
2046
2333
|
},
|
|
2047
2334
|
{
|
|
2048
|
-
component: () => import('./ngstarter-ui-components-content-editor-paragraph-block.component-
|
|
2335
|
+
component: () => import('./ngstarter-ui-components-content-editor-paragraph-block.component-CqU1XJTo.mjs').then(c => c.ParagraphBlockComponent),
|
|
2049
2336
|
type: 'paragraph',
|
|
2050
2337
|
options: {},
|
|
2051
2338
|
empty: () => {
|
|
@@ -2057,7 +2344,7 @@ class ContentBuilderComponent {
|
|
|
2057
2344
|
}
|
|
2058
2345
|
},
|
|
2059
2346
|
{
|
|
2060
|
-
component: () => import('./ngstarter-ui-components-content-editor-code-block.component-
|
|
2347
|
+
component: () => import('./ngstarter-ui-components-content-editor-code-block.component-Qzsc08aS.mjs').then(c => c.CodeBlockComponent),
|
|
2061
2348
|
type: 'code',
|
|
2062
2349
|
options: {},
|
|
2063
2350
|
empty: () => {
|
|
@@ -2070,7 +2357,7 @@ class ContentBuilderComponent {
|
|
|
2070
2357
|
}
|
|
2071
2358
|
},
|
|
2072
2359
|
{
|
|
2073
|
-
component: () => import('./ngstarter-ui-components-content-editor-heading-block.component-
|
|
2360
|
+
component: () => import('./ngstarter-ui-components-content-editor-heading-block.component-CnDuIpxQ.mjs').then(c => c.HeadingBlockComponent),
|
|
2074
2361
|
type: 'heading',
|
|
2075
2362
|
options: {},
|
|
2076
2363
|
empty: () => {
|
|
@@ -2084,7 +2371,7 @@ class ContentBuilderComponent {
|
|
|
2084
2371
|
}
|
|
2085
2372
|
},
|
|
2086
2373
|
{
|
|
2087
|
-
component: () => import('./ngstarter-ui-components-content-editor-image-block.component-
|
|
2374
|
+
component: () => import('./ngstarter-ui-components-content-editor-image-block.component-CqbgVnDh.mjs').then(c => c.ImageBlockComponent),
|
|
2088
2375
|
type: 'image',
|
|
2089
2376
|
options: {
|
|
2090
2377
|
uploadFn: (file, base64) => {
|
|
@@ -2111,7 +2398,7 @@ class ContentBuilderComponent {
|
|
|
2111
2398
|
}
|
|
2112
2399
|
},
|
|
2113
2400
|
{
|
|
2114
|
-
component: () => import('./ngstarter-ui-components-content-editor-video-block.component-
|
|
2401
|
+
component: () => import('./ngstarter-ui-components-content-editor-video-block.component-DKcWb54Z.mjs').then(c => c.VideoBlockComponent),
|
|
2115
2402
|
type: 'video',
|
|
2116
2403
|
options: {
|
|
2117
2404
|
uploadFn: (file, base64) => {
|
|
@@ -2139,7 +2426,7 @@ class ContentBuilderComponent {
|
|
|
2139
2426
|
}
|
|
2140
2427
|
},
|
|
2141
2428
|
{
|
|
2142
|
-
component: () => import('./ngstarter-ui-components-content-editor-list-block.component-
|
|
2429
|
+
component: () => import('./ngstarter-ui-components-content-editor-list-block.component-CHJr_pFf.mjs').then(c => c.ListBlockComponent),
|
|
2143
2430
|
type: 'bulletList',
|
|
2144
2431
|
options: {},
|
|
2145
2432
|
empty: () => {
|
|
@@ -2152,7 +2439,7 @@ class ContentBuilderComponent {
|
|
|
2152
2439
|
}
|
|
2153
2440
|
},
|
|
2154
2441
|
{
|
|
2155
|
-
component: () => import('./ngstarter-ui-components-content-editor-list-block.component-
|
|
2442
|
+
component: () => import('./ngstarter-ui-components-content-editor-list-block.component-CHJr_pFf.mjs').then(c => c.ListBlockComponent),
|
|
2156
2443
|
type: 'orderedList',
|
|
2157
2444
|
options: {},
|
|
2158
2445
|
empty: () => {
|
|
@@ -2165,7 +2452,7 @@ class ContentBuilderComponent {
|
|
|
2165
2452
|
}
|
|
2166
2453
|
},
|
|
2167
2454
|
{
|
|
2168
|
-
component: () => import('./ngstarter-ui-components-content-editor-table-block.component-
|
|
2455
|
+
component: () => import('./ngstarter-ui-components-content-editor-table-block.component-CqbnMNug.mjs').then(c => c.TableBlockComponent),
|
|
2169
2456
|
type: 'table',
|
|
2170
2457
|
options: {},
|
|
2171
2458
|
empty: () => {
|
|
@@ -2234,7 +2521,7 @@ class ContentBuilderComponent {
|
|
|
2234
2521
|
}
|
|
2235
2522
|
},
|
|
2236
2523
|
{
|
|
2237
|
-
component: () => import('./ngstarter-ui-components-content-editor-quote-block.component-
|
|
2524
|
+
component: () => import('./ngstarter-ui-components-content-editor-quote-block.component-fAUfABVY.mjs').then(c => c.QuoteBlockComponent),
|
|
2238
2525
|
type: 'quote',
|
|
2239
2526
|
options: {},
|
|
2240
2527
|
empty: () => {
|
|
@@ -2254,7 +2541,7 @@ class ContentBuilderComponent {
|
|
|
2254
2541
|
}
|
|
2255
2542
|
},
|
|
2256
2543
|
{
|
|
2257
|
-
component: () => import('./ngstarter-ui-components-content-editor-embed-block-
|
|
2544
|
+
component: () => import('./ngstarter-ui-components-content-editor-embed-block-9EHRGpW_.mjs').then(c => c.EmbedBlock),
|
|
2258
2545
|
type: 'embed',
|
|
2259
2546
|
options: {},
|
|
2260
2547
|
empty: () => {
|
|
@@ -2440,33 +2727,110 @@ class ContentBuilderComponent {
|
|
|
2440
2727
|
};
|
|
2441
2728
|
}
|
|
2442
2729
|
// Build helper maps: component map and merged options map
|
|
2730
|
+
insertionSuggestions = computed(() => {
|
|
2731
|
+
const config = mergeContentEditorConfig(this.globalConfig, this.config());
|
|
2732
|
+
const custom = Object.entries(config.blocks ?? {}).flatMap(([type, definition]) => definition.menu ? [{
|
|
2733
|
+
type: 'item', title: definition.menu.title, description: definition.menu.description ?? '',
|
|
2734
|
+
iconName: definition.menu.iconName ?? 'fluent:document-24-regular', blockType: type,
|
|
2735
|
+
blockSettings: definition.menu.settings ?? {}, hotKeys: ''
|
|
2736
|
+
}] : []);
|
|
2737
|
+
const defaults = this.suggestions();
|
|
2738
|
+
const existingTypes = new Set(defaults.filter((item) => item.type === 'item').map((item) => item.blockType));
|
|
2739
|
+
const extra = custom.filter(item => !existingTypes.has(item.blockType));
|
|
2740
|
+
return [...defaults.map((item) => custom.find(entry => entry.blockType === item.blockType) ?? item),
|
|
2741
|
+
...(extra.length ? [{ type: 'heading', title: 'Custom blocks' }, ...extra] : [])];
|
|
2742
|
+
}, /* @ts-ignore */
|
|
2743
|
+
...(ngDevMode ? [{ debugName: "insertionSuggestions" }] : /* istanbul ignore next */ []));
|
|
2744
|
+
menuQuery = signal('', /* @ts-ignore */
|
|
2745
|
+
...(ngDevMode ? [{ debugName: "menuQuery" }] : /* istanbul ignore next */ []));
|
|
2746
|
+
filteredInsertionSuggestions = computed(() => {
|
|
2747
|
+
const query = this.menuQuery().trim().toLocaleLowerCase();
|
|
2748
|
+
if (!query)
|
|
2749
|
+
return this.insertionSuggestions();
|
|
2750
|
+
const items = [];
|
|
2751
|
+
let heading = null;
|
|
2752
|
+
for (const item of this.insertionSuggestions()) {
|
|
2753
|
+
if (item.type === 'heading') {
|
|
2754
|
+
heading = item;
|
|
2755
|
+
continue;
|
|
2756
|
+
}
|
|
2757
|
+
if (!`${item.title} ${item.description ?? ''} ${item.blockType}`.toLocaleLowerCase().includes(query))
|
|
2758
|
+
continue;
|
|
2759
|
+
if (heading) {
|
|
2760
|
+
items.push(heading);
|
|
2761
|
+
heading = null;
|
|
2762
|
+
}
|
|
2763
|
+
items.push(item);
|
|
2764
|
+
}
|
|
2765
|
+
return items;
|
|
2766
|
+
}, /* @ts-ignore */
|
|
2767
|
+
...(ngDevMode ? [{ debugName: "filteredInsertionSuggestions" }] : /* istanbul ignore next */ []));
|
|
2768
|
+
onMenuSearchKeydown(event, target) {
|
|
2769
|
+
event.stopPropagation();
|
|
2770
|
+
if (event.key === 'ArrowDown') {
|
|
2771
|
+
event.preventDefault();
|
|
2772
|
+
this.blockMenu().items()[0]?.focus();
|
|
2773
|
+
}
|
|
2774
|
+
if (event.key === 'Escape')
|
|
2775
|
+
this.blockMenu().closed.emit('keydown');
|
|
2776
|
+
if (event.key === 'Enter') {
|
|
2777
|
+
const first = this.filteredInsertionSuggestions().find(item => item.type === 'item');
|
|
2778
|
+
if (first) {
|
|
2779
|
+
event.preventDefault();
|
|
2780
|
+
this.addBlockFromSuggestionMenu(this.blockMenu(), target, first.blockType, first.blockSettings);
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
componentSources = new Map();
|
|
2443
2785
|
buildBlockDefMaps() {
|
|
2444
2786
|
const overrides = this.options() || {};
|
|
2445
2787
|
const config = mergeContentEditorConfig(this.globalConfig, this.config());
|
|
2446
2788
|
this.blockDefsOptionsMap = new Map();
|
|
2447
|
-
this.blockDefs().
|
|
2448
|
-
|
|
2789
|
+
const definitions = new Map(this.blockDefs().map(def => [def.type, def]));
|
|
2790
|
+
for (const [type, block] of Object.entries(config.blocks ?? {})) {
|
|
2791
|
+
const previous = definitions.get(type);
|
|
2792
|
+
if (!previous && !(block.editor || block.loadEditor))
|
|
2793
|
+
continue;
|
|
2794
|
+
const component = block.loadEditor ?? (block.editor ? () => Promise.resolve(block.editor) : previous.component);
|
|
2795
|
+
definitions.set(type, { ...previous, type, component,
|
|
2796
|
+
empty: block.create ? () => {
|
|
2797
|
+
const initial = block.create();
|
|
2798
|
+
return { content: initial.content, settings: initial.attrs?.['settings'] ?? {}, props: initial.attrs?.['props'] ?? [], attrs: initial.attrs };
|
|
2799
|
+
} : previous?.empty ?? (() => ({ content: null, settings: {} })),
|
|
2800
|
+
toHtml: block.toHtml ?? previous?.toHtml, options: previous?.options ?? {} });
|
|
2801
|
+
const source = block.loadEditor ?? block.editor ?? previous?.component;
|
|
2802
|
+
if (this.componentSources.get(type) !== source)
|
|
2803
|
+
this.blockDefsMap.delete(type);
|
|
2804
|
+
this.componentSources.set(type, source);
|
|
2805
|
+
}
|
|
2806
|
+
for (const type of this.blockDefsMap.keys())
|
|
2807
|
+
if (!definitions.has(type))
|
|
2808
|
+
this.blockDefsMap.delete(type);
|
|
2809
|
+
definitions.forEach(def => {
|
|
2810
|
+
const configured = config.blocks?.[def.type];
|
|
2811
|
+
const source = configured?.loadEditor ?? configured?.editor ?? def.component;
|
|
2812
|
+
if (this.componentSources.get(def.type) !== source)
|
|
2813
|
+
this.blockDefsMap.delete(def.type);
|
|
2814
|
+
this.componentSources.set(def.type, source);
|
|
2815
|
+
if (!this.blockDefsMap.has(def.type))
|
|
2449
2816
|
this.blockDefsMap.set(def.type, def.component());
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
...(def.options || {}),
|
|
2453
|
-
toHtml: def.toHtml,
|
|
2454
|
-
...config.blocks?.[def.type]?.options,
|
|
2455
|
-
...(config.blocks?.[def.type]?.toHtml ? { toHtml: config.blocks[def.type].toHtml } : {}),
|
|
2456
|
-
...(overrides[def.type] || {})
|
|
2457
|
-
};
|
|
2458
|
-
this.blockDefsOptionsMap.set(def.type, merged);
|
|
2817
|
+
this.blockDefsOptionsMap.set(def.type, { ...def.options, toHtml: def.toHtml,
|
|
2818
|
+
...config.blocks?.[def.type]?.options, ...(overrides[def.type] || {}) });
|
|
2459
2819
|
});
|
|
2820
|
+
this.resolvedBlockDefs = definitions;
|
|
2460
2821
|
}
|
|
2822
|
+
resolvedBlockDefs = new Map();
|
|
2461
2823
|
/** Shared by nested block collections; all edits use this root editor. */
|
|
2462
2824
|
get rootBuilder() { return this; }
|
|
2463
2825
|
getBlockComponent(type) { return this.blockDefsMap.get(type); }
|
|
2464
2826
|
createBlockView(type, settings = {}, content) { return this._createBlock(type, settings, content); }
|
|
2465
2827
|
getBlockDefOption(type, key) {
|
|
2466
|
-
return this.blockDefsOptionsMap.get(type)[key];
|
|
2828
|
+
return this.blockDefsOptionsMap.get(type)?.[key];
|
|
2467
2829
|
}
|
|
2468
2830
|
ngOnInit() {
|
|
2469
2831
|
this.lastInput = this.content();
|
|
2832
|
+
this.buildBlockDefMaps();
|
|
2833
|
+
this.configureDraft();
|
|
2470
2834
|
const document = this._getDraftContent() ?? this.lastInput;
|
|
2471
2835
|
const last = document.blocks.at(-1);
|
|
2472
2836
|
const blocks = last && (last.type !== 'paragraph' || contentEditorText(last.content).length > 0)
|
|
@@ -2480,6 +2844,7 @@ class ContentBuilderComponent {
|
|
|
2480
2844
|
}
|
|
2481
2845
|
}
|
|
2482
2846
|
constructor() {
|
|
2847
|
+
inject(DestroyRef).onDestroy(() => this.drafts.flush());
|
|
2483
2848
|
effect(() => {
|
|
2484
2849
|
this.config();
|
|
2485
2850
|
this.options();
|
|
@@ -2488,10 +2853,18 @@ class ContentBuilderComponent {
|
|
|
2488
2853
|
});
|
|
2489
2854
|
effect(() => {
|
|
2490
2855
|
const value = this.content();
|
|
2856
|
+
this.documentId();
|
|
2857
|
+
this.persistDraft();
|
|
2858
|
+
this.draftDebounceMs();
|
|
2859
|
+
this.config();
|
|
2491
2860
|
untracked(() => {
|
|
2492
|
-
if (this.loaded
|
|
2861
|
+
if (!this.loaded)
|
|
2862
|
+
return;
|
|
2863
|
+
const previousKey = this.draftKey;
|
|
2864
|
+
this.configureDraft();
|
|
2865
|
+
if (value !== this.lastInput || previousKey !== this.draftKey) {
|
|
2493
2866
|
this.lastInput = value;
|
|
2494
|
-
this._store.setBlocks(value);
|
|
2867
|
+
this._store.setBlocks(previousKey !== this.draftKey ? this._getDraftContent() ?? value : value);
|
|
2495
2868
|
}
|
|
2496
2869
|
});
|
|
2497
2870
|
});
|
|
@@ -2631,7 +3004,9 @@ class ContentBuilderComponent {
|
|
|
2631
3004
|
return this.editor.document().blocks.find(block => block.id === newBlock.id);
|
|
2632
3005
|
}
|
|
2633
3006
|
_createBlock(type, settings = {}, content) {
|
|
2634
|
-
const blockDef = this.blockDefs().find(
|
|
3007
|
+
const blockDef = this.resolvedBlockDefs.get(type) ?? this.blockDefs().find(item => item.type === type);
|
|
3008
|
+
if (!blockDef)
|
|
3009
|
+
throw new Error(`No Content Editor definition for "${type}"`);
|
|
2635
3010
|
const empty = blockDef.empty();
|
|
2636
3011
|
if (settings) {
|
|
2637
3012
|
empty.settings = {
|
|
@@ -2660,6 +3035,45 @@ class ContentBuilderComponent {
|
|
|
2660
3035
|
}
|
|
2661
3036
|
this.insertBlock(type, index, options);
|
|
2662
3037
|
}
|
|
3038
|
+
canConvertBlock(id) {
|
|
3039
|
+
const block = findContentEditorBlock(this.editor.document().blocks, id);
|
|
3040
|
+
return !!block && this.conversionTypes.includes(block.type) && !this.editor.readOnly();
|
|
3041
|
+
}
|
|
3042
|
+
convertBlock(id, type, settings = {}) {
|
|
3043
|
+
if (!this.canConvertBlock(id))
|
|
3044
|
+
return false;
|
|
3045
|
+
const regions = Array.from(this.elRef.nativeElement.querySelectorAll('.ngs-content-editor-content-editable'));
|
|
3046
|
+
const activeElement = regions.find(element => element.closest('[data-block-id]')?.getAttribute('data-block-id') === id && ContentEditorContentEditableDirective.forElement(element)?.region.active());
|
|
3047
|
+
const region = ContentEditorContentEditableDirective.forElement(activeElement ?? null);
|
|
3048
|
+
let selection = region?.region.editor.selection();
|
|
3049
|
+
const source = findContentEditorBlock(this.editor.document().blocks, id);
|
|
3050
|
+
if (selection && source.type === 'quote' && type !== 'quote' && activeElement?.classList.contains('caption')) {
|
|
3051
|
+
const quote = source.content;
|
|
3052
|
+
const caption = contentEditorText(quote.caption?.content);
|
|
3053
|
+
const text = contentEditorText(quote.cite.content) + (caption ? '\n' + caption : '');
|
|
3054
|
+
const shift = contentEditorText(quote.cite.content).length + (caption ? 1 : 0);
|
|
3055
|
+
const lines = text.split('\n');
|
|
3056
|
+
const point = (value) => {
|
|
3057
|
+
const regionLines = region.region.editor.document().blocks;
|
|
3058
|
+
const index = regionLines.findIndex(line => line.id === value.blockId);
|
|
3059
|
+
let offset = shift + regionLines.slice(0, index).reduce((sum, line) => sum + contentEditorText(line.content).length + 1, 0) + value.offset;
|
|
3060
|
+
let line = 0;
|
|
3061
|
+
while (line < lines.length - 1 && offset > lines[line].length) {
|
|
3062
|
+
offset -= lines[line].length + 1;
|
|
3063
|
+
line++;
|
|
3064
|
+
}
|
|
3065
|
+
return { blockId: `line-${line}`, offset };
|
|
3066
|
+
};
|
|
3067
|
+
selection = { anchor: point(selection.anchor), focus: point(selection.focus) };
|
|
3068
|
+
}
|
|
3069
|
+
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
3070
|
+
const block = findContentEditorBlock(blocks, id);
|
|
3071
|
+
Object.assign(block, contentEditorConvertBlock(block, type, settings));
|
|
3072
|
+
this.editor.updateDocument({ version: 1, blocks });
|
|
3073
|
+
if (selection)
|
|
3074
|
+
this._store.restoreTextSelection.set({ blockId: id, selection });
|
|
3075
|
+
return true;
|
|
3076
|
+
}
|
|
2663
3077
|
duplicateBlock(blockId) {
|
|
2664
3078
|
const index = this._content().findIndex(dataBlock => dataBlock.id === blockId);
|
|
2665
3079
|
if (index === -1) {
|
|
@@ -2790,19 +3204,91 @@ class ContentBuilderComponent {
|
|
|
2790
3204
|
getData() {
|
|
2791
3205
|
return this.editor.document();
|
|
2792
3206
|
}
|
|
3207
|
+
/** Structural HTML paste splits the active text block without flattening lists/tables. */
|
|
3208
|
+
pasteBlocksAtSelection(id, imported, start, end) {
|
|
3209
|
+
if (this.editor.readOnly() || !imported.blocks.length)
|
|
3210
|
+
return false;
|
|
3211
|
+
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
3212
|
+
const source = findContentEditorBlock(blocks, id);
|
|
3213
|
+
const scope = contentEditorBlockScope(blocks, id) ?? this._store.insertionTarget().scope;
|
|
3214
|
+
if (!source) {
|
|
3215
|
+
// The empty nested paragraph is a UI placeholder until its first edit.
|
|
3216
|
+
const collection = contentEditorCollection(blocks, scope);
|
|
3217
|
+
if (collection.length)
|
|
3218
|
+
return false;
|
|
3219
|
+
this.applyImport(imported, { mode: 'insert', target: { scope } });
|
|
3220
|
+
return true;
|
|
3221
|
+
}
|
|
3222
|
+
if (!['paragraph', 'heading'].includes(source.type))
|
|
3223
|
+
return false;
|
|
3224
|
+
const text = source.content;
|
|
3225
|
+
const before = contentEditorSliceText(text, 0, Math.min(start, end));
|
|
3226
|
+
const after = contentEditorSliceText(text, Math.max(start, end));
|
|
3227
|
+
const insertion = contentEditorCopyBlocks(imported.blocks);
|
|
3228
|
+
if (contentEditorText(before)) {
|
|
3229
|
+
if (source.type === 'paragraph' && insertion[0].type === 'paragraph')
|
|
3230
|
+
insertion[0] = {
|
|
3231
|
+
...source, content: [...before, ...insertion[0].content]
|
|
3232
|
+
};
|
|
3233
|
+
else
|
|
3234
|
+
insertion.unshift({ ...source, content: before });
|
|
3235
|
+
}
|
|
3236
|
+
const last = insertion.at(-1);
|
|
3237
|
+
const textLast = ['paragraph', 'heading'].includes(last.type);
|
|
3238
|
+
const caretLines = textLast ? contentEditorText(last.content).split('\n') : [''];
|
|
3239
|
+
const caretPoint = { blockId: `line-${caretLines.length - 1}`, offset: caretLines.at(-1).length };
|
|
3240
|
+
if (textLast)
|
|
3241
|
+
insertion[insertion.length - 1] = { ...last, content: [...last.content, ...after] };
|
|
3242
|
+
else if (contentEditorText(after))
|
|
3243
|
+
insertion.push({ id: v7(), type: 'paragraph', content: after, attrs: { props: source.attrs?.['props'] ?? [] } });
|
|
3244
|
+
const items = [...contentEditorCollection(blocks, scope)];
|
|
3245
|
+
items.splice(items.findIndex(block => block.id === id), 1, ...insertion);
|
|
3246
|
+
replaceContentEditorCollection(blocks, scope, items);
|
|
3247
|
+
this.editor.updateDocument({ version: 1, blocks });
|
|
3248
|
+
if (textLast)
|
|
3249
|
+
this._store.restoreTextSelection.set({ blockId: last.id, selection: { anchor: caretPoint, focus: caretPoint } });
|
|
3250
|
+
return true;
|
|
3251
|
+
}
|
|
2793
3252
|
/** Validates before replacing the document. Import is one undoable edit. */
|
|
2794
3253
|
importJson(source, config = {}, options = {}) {
|
|
2795
|
-
return this.applyImport(this.importer.fromJson(source, mergeContentEditorConfig(this.config(), config), options));
|
|
3254
|
+
return this.applyImport(this.importer.fromJson(source, mergeContentEditorConfig(this.config(), config), options), options);
|
|
2796
3255
|
}
|
|
2797
3256
|
importHtml(html, config = {}, options = {}) {
|
|
2798
|
-
return this.applyImport(this.importer.fromHtml(html, mergeContentEditorConfig(this.config(), config), options));
|
|
3257
|
+
return this.applyImport(this.importer.fromHtml(html, mergeContentEditorConfig(this.config(), config), options), options);
|
|
2799
3258
|
}
|
|
2800
|
-
|
|
3259
|
+
getInsertionTarget() {
|
|
3260
|
+
const saved = this._store.insertionTarget();
|
|
3261
|
+
const id = saved.afterId ?? this._store.activeBlockId() ?? this._store.focusedBlockId();
|
|
3262
|
+
const scope = id ? contentEditorBlockScope(this.editor.document().blocks, id) : null;
|
|
3263
|
+
if (scope)
|
|
3264
|
+
return { scope, afterId: id };
|
|
3265
|
+
return { scope: saved.scope };
|
|
3266
|
+
}
|
|
3267
|
+
applyImport(document, placement = {}) {
|
|
2801
3268
|
if (!this.loaded)
|
|
2802
3269
|
throw new ContentEditorImportError('$editor', 'Initialize the builder before importing');
|
|
2803
3270
|
if (this.editor.readOnly())
|
|
2804
3271
|
throw new ContentEditorImportError('$editor', 'Cannot import into a read-only editor');
|
|
2805
|
-
|
|
3272
|
+
if (placement.mode === 'insert') {
|
|
3273
|
+
const target = placement.target ?? this.getInsertionTarget();
|
|
3274
|
+
const blocks = cloneContentEditorValue([...this.editor.document().blocks]);
|
|
3275
|
+
if (target.scope.parentId) {
|
|
3276
|
+
const parent = findContentEditorBlock(blocks, target.scope.parentId);
|
|
3277
|
+
if (!parent || !['toggle', 'grid'].includes(parent.type) ||
|
|
3278
|
+
(parent.type === 'grid' && !parent.content.cells.some((cell) => cell.id === target.scope.cellId))) {
|
|
3279
|
+
throw new ContentEditorImportError('$target.scope', 'Insertion collection does not exist');
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
const items = [...contentEditorCollection(blocks, target.scope)];
|
|
3283
|
+
const index = target.afterId ? items.findIndex(block => block.id === target.afterId) : items.length - 1;
|
|
3284
|
+
if (target.afterId && index < 0)
|
|
3285
|
+
throw new ContentEditorImportError('$target.afterId', 'Insertion block does not exist in this collection');
|
|
3286
|
+
items.splice(index + 1, 0, ...contentEditorCopyBlocks(document.blocks));
|
|
3287
|
+
replaceContentEditorCollection(blocks, target.scope, items);
|
|
3288
|
+
this.editor.updateDocument({ version: 1, blocks });
|
|
3289
|
+
}
|
|
3290
|
+
else
|
|
3291
|
+
this.editor.updateDocument(document);
|
|
2806
3292
|
this.selectedBlocksModel.clear();
|
|
2807
3293
|
this._store.setFocusedBlockId(null);
|
|
2808
3294
|
this._store.setActiveBlockId(null);
|
|
@@ -2854,9 +3340,7 @@ class ContentBuilderComponent {
|
|
|
2854
3340
|
.map(id => ({ id, index: this._content().findIndex(b => b.id === id) }))
|
|
2855
3341
|
.filter(x => x.index !== -1)
|
|
2856
3342
|
.sort((a, b) => b.index - a.index);
|
|
2857
|
-
|
|
2858
|
-
this.deleteBlock(item.id);
|
|
2859
|
-
}
|
|
3343
|
+
this._store.deleteBlocks(toDelete.map(item => item.id));
|
|
2860
3344
|
this.unselectSelectedBlocks();
|
|
2861
3345
|
});
|
|
2862
3346
|
}
|
|
@@ -2910,6 +3394,7 @@ class ContentBuilderComponent {
|
|
|
2910
3394
|
onFocusChange(origin, dataBlock) {
|
|
2911
3395
|
}
|
|
2912
3396
|
onSuggestionsMenuClose(reason) {
|
|
3397
|
+
this.menuQuery.set('');
|
|
2913
3398
|
if (!reason) {
|
|
2914
3399
|
this._store.setFocusedBlockId(this._store.activeBlockId());
|
|
2915
3400
|
this.focusChanged.emit();
|
|
@@ -2945,36 +3430,23 @@ class ContentBuilderComponent {
|
|
|
2945
3430
|
}
|
|
2946
3431
|
this._scroll$ = null;
|
|
2947
3432
|
}
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
if (!draft) {
|
|
2955
|
-
return null;
|
|
2956
|
-
}
|
|
2957
|
-
const content = JSON.parse(draft);
|
|
2958
|
-
return content?.version === 1 && Array.isArray(content.blocks) ? content : null;
|
|
2959
|
-
}
|
|
2960
|
-
catch {
|
|
2961
|
-
return null;
|
|
2962
|
-
}
|
|
2963
|
-
}
|
|
2964
|
-
_saveDraft(content) {
|
|
2965
|
-
if (!this._canUseDraftStorage()) {
|
|
2966
|
-
return;
|
|
2967
|
-
}
|
|
2968
|
-
try {
|
|
2969
|
-
localStorage.setItem(this._getDraftStorageKey(), JSON.stringify(content));
|
|
2970
|
-
}
|
|
2971
|
-
catch {
|
|
2972
|
-
}
|
|
3433
|
+
configureDraft() {
|
|
3434
|
+
this.draftKey = this._getDraftStorageKey();
|
|
3435
|
+
const config = mergeContentEditorConfig(this.globalConfig, this.config()).draft;
|
|
3436
|
+
this.drafts.configure(this.draftKey, this._canUseDraftStorage(), {
|
|
3437
|
+
...config, ...(this.draftDebounceMs() === undefined ? {} : { debounceMs: this.draftDebounceMs() })
|
|
3438
|
+
});
|
|
2973
3439
|
}
|
|
2974
|
-
|
|
2975
|
-
return
|
|
3440
|
+
_getDraftContent() {
|
|
3441
|
+
return this.drafts.read(source => this.importer.fromJson(source, this.config()));
|
|
2976
3442
|
}
|
|
3443
|
+
_saveDraft(content) { this.drafts.schedule(content); }
|
|
3444
|
+
saveDraftNow() { this.drafts.schedule(this.getData()); this.drafts.flush(); }
|
|
3445
|
+
clearDraft() { this.drafts.clear(); }
|
|
3446
|
+
_canUseDraftStorage() { return !isPlatformServer(this._platformId) && this.persistDraft(); }
|
|
2977
3447
|
_getDraftStorageKey(prefix = ContentBuilderComponent.DRAFT_STORAGE_PREFIX) {
|
|
3448
|
+
if (this.documentId()?.trim())
|
|
3449
|
+
return `${prefix}:document:${encodeURIComponent(this.documentId())}`;
|
|
2978
3450
|
const elementId = this.elRef.nativeElement.id;
|
|
2979
3451
|
const locationKey = typeof window === 'undefined'
|
|
2980
3452
|
? 'server'
|
|
@@ -3018,7 +3490,13 @@ class ContentBuilderComponent {
|
|
|
3018
3490
|
}
|
|
3019
3491
|
}
|
|
3020
3492
|
if (html) {
|
|
3021
|
-
|
|
3493
|
+
try {
|
|
3494
|
+
this._handleHtmlPaste(html, index);
|
|
3495
|
+
}
|
|
3496
|
+
catch {
|
|
3497
|
+
if (text)
|
|
3498
|
+
this._handleTextPaste(text, index);
|
|
3499
|
+
}
|
|
3022
3500
|
}
|
|
3023
3501
|
else if (text) {
|
|
3024
3502
|
this._handleTextPaste(text, index);
|
|
@@ -3044,110 +3522,11 @@ class ContentBuilderComponent {
|
|
|
3044
3522
|
}
|
|
3045
3523
|
}
|
|
3046
3524
|
_handleHtmlPaste(html, index) {
|
|
3047
|
-
const
|
|
3048
|
-
|
|
3049
|
-
let currentIndex = index;
|
|
3050
|
-
Array.from(body.children).forEach(node => {
|
|
3051
|
-
const block = this._mapNodeToBlock(node);
|
|
3052
|
-
if (block) {
|
|
3053
|
-
this.insertBlock(block.type, currentIndex, block.settings, false, block.content);
|
|
3054
|
-
currentIndex++;
|
|
3055
|
-
}
|
|
3056
|
-
});
|
|
3057
|
-
}
|
|
3058
|
-
_mapNodeToBlock(node) {
|
|
3059
|
-
const tag = node.tagName.toLowerCase();
|
|
3060
|
-
switch (tag) {
|
|
3061
|
-
case 'h1':
|
|
3062
|
-
case 'h2':
|
|
3063
|
-
case 'h3':
|
|
3064
|
-
case 'h4':
|
|
3065
|
-
case 'h5':
|
|
3066
|
-
case 'h6':
|
|
3067
|
-
return {
|
|
3068
|
-
type: 'heading',
|
|
3069
|
-
settings: { level: parseInt(tag.substring(1)) },
|
|
3070
|
-
content: readNgsHeadlessEditorInlineContent(node, this.editor, { lineBreaks: true })
|
|
3071
|
-
};
|
|
3072
|
-
case 'p':
|
|
3073
|
-
return {
|
|
3074
|
-
type: 'paragraph',
|
|
3075
|
-
settings: {},
|
|
3076
|
-
content: readNgsHeadlessEditorInlineContent(node, this.editor, { lineBreaks: true })
|
|
3077
|
-
};
|
|
3078
|
-
case 'ul':
|
|
3079
|
-
return {
|
|
3080
|
-
type: 'bulletList',
|
|
3081
|
-
settings: { listStyle: 'bullet' },
|
|
3082
|
-
content: this._mapListItems(node)
|
|
3083
|
-
};
|
|
3084
|
-
case 'ol':
|
|
3085
|
-
return {
|
|
3086
|
-
type: 'orderedList',
|
|
3087
|
-
settings: { listStyle: 'ordered' },
|
|
3088
|
-
content: this._mapListItems(node)
|
|
3089
|
-
};
|
|
3090
|
-
case 'img':
|
|
3091
|
-
return {
|
|
3092
|
-
type: 'image',
|
|
3093
|
-
settings: {},
|
|
3094
|
-
content: {
|
|
3095
|
-
src: node.getAttribute('src') || '',
|
|
3096
|
-
alt: node.getAttribute('alt') || ''
|
|
3097
|
-
}
|
|
3098
|
-
};
|
|
3099
|
-
case 'video':
|
|
3100
|
-
return {
|
|
3101
|
-
type: 'video',
|
|
3102
|
-
settings: {},
|
|
3103
|
-
content: {
|
|
3104
|
-
src: node.getAttribute('src') || '',
|
|
3105
|
-
caption: node.getAttribute('title') || ''
|
|
3106
|
-
}
|
|
3107
|
-
};
|
|
3108
|
-
case 'blockquote':
|
|
3109
|
-
return {
|
|
3110
|
-
type: 'quote',
|
|
3111
|
-
settings: {},
|
|
3112
|
-
content: { cite: { content: readNgsHeadlessEditorInlineContent(node, this.editor, { lineBreaks: true }), props: [] }, caption: { content: [], props: [] } }
|
|
3113
|
-
};
|
|
3114
|
-
case 'pre':
|
|
3115
|
-
const codeNode = node.querySelector('code');
|
|
3116
|
-
const content = (codeNode || node).textContent || '';
|
|
3117
|
-
return {
|
|
3118
|
-
type: 'code',
|
|
3119
|
-
settings: { language: 'none' },
|
|
3120
|
-
content: [createNgsHeadlessEditorText(content.replace(/\r\n?/g, '\n').trimEnd())]
|
|
3121
|
-
};
|
|
3122
|
-
case 'hr':
|
|
3123
|
-
return {
|
|
3124
|
-
type: 'divider',
|
|
3125
|
-
settings: {}
|
|
3126
|
-
};
|
|
3127
|
-
default:
|
|
3128
|
-
if (node.textContent?.trim()) {
|
|
3129
|
-
return {
|
|
3130
|
-
type: 'paragraph',
|
|
3131
|
-
settings: {},
|
|
3132
|
-
content: readNgsHeadlessEditorInlineContent(node, this.editor, { lineBreaks: true })
|
|
3133
|
-
};
|
|
3134
|
-
}
|
|
3135
|
-
return null;
|
|
3136
|
-
}
|
|
3137
|
-
}
|
|
3138
|
-
_mapListItems(node) {
|
|
3139
|
-
return Array.from(node.children)
|
|
3140
|
-
.filter(child => child.tagName.toLowerCase() === 'li')
|
|
3141
|
-
.map(li => {
|
|
3142
|
-
const inline = li.cloneNode(true);
|
|
3143
|
-
const nested = Array.from(inline.children).filter(child => ['ul', 'ol'].includes(child.tagName.toLowerCase()));
|
|
3144
|
-
const children = nested.flatMap(list => this._mapListItems(list));
|
|
3145
|
-
nested.forEach(list => list.remove());
|
|
3146
|
-
return { content: readNgsHeadlessEditorInlineContent(inline, this.editor, { lineBreaks: true }), props: [], children };
|
|
3147
|
-
});
|
|
3525
|
+
const afterId = this.editor.document().blocks[index - 1]?.id;
|
|
3526
|
+
this.importHtml(html, {}, { mode: 'insert', target: { scope: {}, afterId } });
|
|
3148
3527
|
}
|
|
3149
3528
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentBuilderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
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: [
|
|
3529
|
+
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 }, documentId: { classPropertyName: "documentId", publicName: "documentId", isSignal: true, isRequired: false, transformFunction: null }, draftDebounceMs: { classPropertyName: "draftDebounceMs", publicName: "draftDebounceMs", 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: [
|
|
3151
3530
|
provideContentEditor(),
|
|
3152
3531
|
ContentEditorHtmlSerializer,
|
|
3153
3532
|
ContentEditorImporter,
|
|
@@ -3156,7 +3535,7 @@ class ContentBuilderComponent {
|
|
|
3156
3535
|
provide: CONTENT_BUILDER,
|
|
3157
3536
|
useExisting: forwardRef(() => ContentBuilderComponent)
|
|
3158
3537
|
}
|
|
3159
|
-
], viewQueries: [{ propertyName: "blockMenu", first: true, predicate: ["suggestionsMenu"], descendants: true, isSignal: true }, { propertyName: "dropList", first: true, predicate: CdkDropList, descendants: true, isSignal: true }], exportAs: ["ngsContentEditorBuilder"], hostDirectives: [{ directive: BlockSelectionDirective, inputs: ["autoScrollContainerSelector", "autoScrollContainerSelector"] }], ngImport: i0, template: "<div class=\"container py-4\">\n <div class=\"content\"\n cdkDropList\n [cdkDropListData]=\"{}\"\n [cdkDropListConnectedTo]=\"connectedDropLists()\"\n [cdkDropListEnterPredicate]=\"canEnterRoot\"\n ngsTextSelectionPopup\n closestContentObserverClass=\"ngs-content-editor-content-editable\"\n [targetComponent]=\"commandBar\"\n (tagSelected)=\"onTagSelected($event)\"\n (cdkDropListDropped)=\"drop($event)\">\n @for (contentBlock of _content(); track contentBlock.id) {\n <div class=\"block\"\n [attr.data-block-id]=\"contentBlock.id\"\n [class.is-focused]=\"isBlockFocused(contentBlock.id)\"\n [class.is-active]=\"isActiveBlock(contentBlock.id)\"\n cdkDrag\n [cdkDragData]=\"contentBlock.id\"\n cdkMonitorSubtreeFocus\n (cdkDragStarted)=\"onDragStarted($event, contentBlock)\"\n (cdkDragEnded)=\"onDragEnded($event, contentBlock)\"\n (cdkFocusChange)=\"onFocusChange($event, contentBlock)\">\n <div class=\"block-controls\" [class.is-settings-popover-open]=\"settingsTrigger.api.isOpen()\">\n <button class=\"block-control\" aria-label=\"Add block\"\n (mousedown)=\"setActiveBlockId($event, contentBlock.id)\"\n [ngsMenuTriggerFor]=\"suggestionsMenu\"\n [ngsMenuTriggerData]=\"{target: {scope: {}, afterId: contentBlock.id}}\"\n [ngsMenuTriggerRestoreFocus]=\"false\">\n <ngs-icon name=\"fluent:add-24-regular\"/>\n </button>\n <div class=\"block-control block-control-drag\"\n (click)=\"selectBlock(contentBlock.id)\"\n [ngsPopoverTriggerFor]=\"settingsPopover\"\n (closed)=\"onSettingsPopoverClose()\"\n #settingsTrigger=\"ngsPopoverTriggerFor\"\n hasBackdrop\n position=\"before-center\">\n <button cdkDragHandle\n trigger=\"hover\"\n closeOnOriginClick\n closeOnOriginMouseLeave\n #dragTrigger=\"ngsPopoverTriggerFor\"\n [ngsPopoverTriggerFor]=\"dragControlTooltip\"\n position=\"below-center\"\n (mousedown)=\"dragTrigger.api.close()\"\n delay=\"1000\" class=\"w-full h-full flex items-center justify-center\">\n <ngs-icon name=\"fluent:re-order-dots-vertical-24-regular\"/>\n </button>\n </div>\n <ng-template #dragControlTooltip>\n <div class=\"bg-neutral-900 text-xs flex flex-col gap-0.5 rounded-lg items-center px-2 py-1.5 font-medium\">\n <div>\n <div class=\"text-neutral-100\">Drag <span class=\"text-neutral-400\">to move</span></div>\n </div>\n <div>\n <div class=\"text-neutral-100\">Click <span class=\"text-neutral-400\">to open menu</span></div>\n </div>\n </div>\n </ng-template>\n </div>\n <div class=\"block-content\" [class.is-selected]=\"isBlockSelected(contentBlock.id)\">\n <div class=\"drag-placeholder\" *cdkDragPlaceholder></div>\n <ng-container [ngComponentOutlet]=\"blockDefsMap.get(contentBlock.type) | async\"\n [ngComponentOutletInputs]=\"{\n id: contentBlock.id,\n content: contentBlock.content,\n settings: contentBlock.settings,\n props: contentBlock.props,\n index: $index\n }\"/>\n </div>\n </div>\n }\n </div>\n</div>\n\n<ngs-popover #settingsPopover=\"ngsPopover\">\n <div class=\"px-2 py-0 w-72 settings-popover\">\n <ngs-list>\n <ngs-list-item (click)=\"duplicateSelectedBlocks(settingsPopover)\">\n <ngs-icon name=\"fluent:copy-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Duplicate</div>\n </ngs-list-item>\n <ngs-list-item (click)=\"deleteSelectedBlocks(settingsPopover)\">\n <ngs-icon name=\"fluent:delete-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Delete</div>\n </ngs-list-item>\n </ngs-list>\n </div>\n</ngs-popover>\n\n<ngs-menu #suggestionsMenu=\"ngsMenu\" classList=\"min-h-[70vh] max-h-[70vh]!\" pushIntoViewport (closed)=\"onSuggestionsMenuClose($event)\">\n <ng-template ngsMenuContent let-target=\"target\">\n <div (click)=\"preventMenuClose($event)\">\n @for (suggestionItem of suggestions(); track $index; let first = $first) {\n @switch (suggestionItem.type) {\n @case ('heading') {\n <ngs-menu-heading>{{ suggestionItem.title }}</ngs-menu-heading>\n }\n @case ('item') {\n <button ngs-menu-item\n (click)=\"addBlockFromSuggestionMenu(suggestionsMenu, target, suggestionItem.blockType, suggestionItem.blockSettings)\">\n <div class=\"h-full flex items-center gap-3 py-2\">\n <div class=\"size-9 flex items-center rounded-lg justify-center bg-surface-container\">\n <ngs-icon [name]=\"suggestionItem.iconName\" class=\"!me-0\"/>\n </div>\n <div class=\"grow min-w-[200px]\">\n <div>{{ suggestionItem.title }}</div>\n <div class=\"text-2xs text-neutral-600\">{{ suggestionItem.description }}</div>\n </div>\n @if (suggestionItem.hotKeys) {\n <div class=\"ms-auto bg-surface-container-highest rounded-full h-5\n text-4xs px-2 flex items-center font-bold\">{{ suggestionItem.hotKeys }}</div>\n }\n </div>\n </button>\n }\n }\n }\n </div>\n </ng-template>\n</ngs-menu>\n", styles: [":host{--ngs-content-editor-builder-content-width: 704px;outline:none}:host.is-block-dragging{cursor:grabbing}:host .container{display:flex;width:100%;max-width:820px;min-height:200px;height:100%;padding:calc(var(--spacing, .25rem) * 5) calc(var(--spacing, .25rem) * 5) calc(var(--spacing, .25rem) * 5) 0;margin:0 auto;outline:none}:host .content{flex-grow:1;width:100%;min-width:0}:host .block{position:relative;flex:none;padding:var(--spacing, .25rem) 0;display:flex;align-items:center}:host .block:not(:has(.block-content.is-selected)):hover .block-content{background:var(--ngs-color-neutral-50)}:host:not(.is-block-dragging) .block:hover .block-controls,:host:not(.is-block-dragging) .block.is-active .block-controls{opacity:1}:host .block-content{position:relative;flex-grow:1;min-width:0;padding:calc(var(--spacing, .25rem) * 3)}:host .block-content.is-selected{background:var(--ngs-color-primary-100)}:host ::ng-deep .selection-area{background:var(--ngs-color-primary-100);opacity:.4;border:1px solid var(--ngs-color-primary);border-radius:var(--ngs-radius-sm)}:host ::ng-deep .ngs-content-editor-content-editable{-webkit-user-select:text;user-select:text}:host ::ng-deep .ngs-content-editor-content-editable a[data-ngs-headless-editor-mark=link]{color:var(--ngs-color-primary);text-decoration:underline;text-underline-offset:.15em}:host ::ng-deep .ngs-content-editor-content-editable.align-center{text-align:center}:host ::ng-deep .ngs-content-editor-content-editable.align-right{text-align:right}:host ::ng-deep .ngs-content-editor-content-editable.align-justify{text-align:justify}:host ::ng-deep .ngs-content-editor-content-editable>p{margin:0}:host ::ng-deep .ngs-content-editor-content-editable[data-empty]:before{content:attr(data-empty-placeholder);display:block;height:0;color:var(--ngs-color-neutral-500);pointer-events:none}:host.select-none ::ng-deep .ngs-content-editor-content-editable,:host.is-selection-of-blocks-active ::ng-deep .ngs-content-editor-content-editable{-webkit-user-select:none!important;user-select:none!important}:host .block-controls{left:0;display:flex;align-items:center;color:var(--ngs-color-neutral-500);width:calc(var(--spacing, .25rem) * 18);padding:0 calc(var(--spacing, .25rem) * 2);opacity:0;flex:none}:host .block-controls.is-settings-popover-open{opacity:1}:host .block-controls.is-settings-popover-open .block-control:not(.block-control-drag){opacity:0}:host .block-control{cursor:pointer;width:calc(var(--spacing, .25rem) * 7);height:calc(var(--spacing, .25rem) * 7);flex:none;border-radius:var(--ngs-radius-lg);display:inline-flex;align-items:center;justify-content:center}:host .block-control:hover{background:var(--ngs-color-surface-container-low);color:var(--ngs-color-on-surface)}:host .block-control-drag button{cursor:grab}:host .drag-placeholder{height:calc(var(--spacing, .25rem) * 8);flex:none;position:relative}:host .drag-placeholder:before{position:absolute;left:calc(var(--spacing, .25rem) * 18);display:block;right:0;content:\"\";height:calc(var(--spacing, .25rem) * 2);top:50%;transform:translateY(-50%);background:var(--ngs-color-primary-300);border-radius:calc(var(--spacing, .25rem) * .5)}:host ::ng-deep code{color:var(--ngs-color-primary)}.cdk-drag.cdk-drag-preview{overflow:hidden;display:flex;align-items:center;color:var(--ngs-color-neutral-500);width:calc(var(--spacing, .25rem) * 18);padding:0 calc(var(--spacing, .25rem) * 2)}.cdk-drag.cdk-drag-preview .block-control{width:calc(var(--spacing, .25rem) * 7);height:calc(var(--spacing, .25rem) * 7);flex:none;border-radius:var(--ngs-radius-lg);display:inline-flex;align-items:center;justify-content:center;cursor:grabbing}.cdk-drag.cdk-drag-preview .block-control:first-child{opacity:0}.cdk-drag.cdk-drag-preview .block-control:last-child{color:var(--ngs-color-on-surface)}.cdk-drag.cdk-drag-preview .block-content{opacity:0}.settings-popover{--ngs-list-list-item-one-line-container-height: calc(var(--spacing, .25rem) * 10)}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "component", type: Icon, selector: "ngs-icon", inputs: ["name"], exportAs: ["ngsIcon"] }, { kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }, { kind: "directive", type: CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer", "cdkDragScale"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: ["cdkDropListConnectedTo", "cdkDropListData", "cdkDropListOrientation", "id", "cdkDropListLockAxis", "cdkDropListDisabled", "cdkDropListSortingDisabled", "cdkDropListEnterPredicate", "cdkDropListSortPredicate", "cdkDropListAutoScrollDisabled", "cdkDropListAutoScrollStep", "cdkDropListElementContainer", "cdkDropListHasAnchor"], outputs: ["cdkDropListDropped", "cdkDropListEntered", "cdkDropListExited", "cdkDropListSorted"], exportAs: ["cdkDropList"] }, { kind: "directive", type: CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { kind: "directive", type: CdkDragPlaceholder, selector: "ng-template[cdkDragPlaceholder]", inputs: ["data"] }, { kind: "component", type: Menu, selector: "ngs-menu", inputs: ["role", "classList", "xPosition", "yPosition", "pushIntoViewport"], outputs: ["closed"], exportAs: ["ngsMenu"] }, { kind: "component", type: MenuItem, selector: "ngs-menu-item, [ngs-menu-item]", inputs: ["disabled", "role", "selected"], outputs: ["_triggered"], exportAs: ["ngsMenuItem"] }, { kind: "directive", type: MenuTrigger, selector: "[ngsMenuTriggerFor]", inputs: ["ngsMenuTriggerFor", "ngsMenuTriggerData", "ngsMenuDisabled", "xPosition", "yPosition", "ngsMenuTriggerRestoreFocus"], outputs: ["menuOpened", "menuClosed"], exportAs: ["ngsMenuTrigger"] }, { kind: "directive", type: CdkMonitorFocus, selector: "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]", outputs: ["cdkFocusChange"], exportAs: ["cdkMonitorFocus"] }, { kind: "directive", type: TextSelectionPopupDirective, selector: "[ngsTextSelectionPopup]", inputs: ["targetComponent", "closestContentObserverClass"], outputs: ["tagSelected"] }, { kind: "directive", type: PopoverTriggerForDirective, selector: "[ngsPopoverTriggerFor]", inputs: ["ngsPopoverTriggerFor", "ngsPopoverContext", "trigger", "position", "delay", "origin", "closeOnOriginClick", "closeOnOriginMouseLeave", "hasBackdrop"], outputs: ["opened", "closed"], exportAs: ["ngsPopoverTriggerFor"] }, { kind: "component", type: Popover, selector: "ngs-popover", exportAs: ["ngsPopover"] }, { kind: "directive", type: ListItemTitle, selector: "[ngsListItemTitle]" }, { kind: "directive", type: ListItemIcon, selector: "[ngsListItemIcon]" }, { kind: "component", type: ListItem, selector: "ngs-list-item, a[ngs-list-item], button[ngs-list-item]", inputs: ["disabled", "lines"], exportAs: ["ngsListItem"] }, { kind: "component", type: List, selector: "ngs-list", inputs: ["disabled", "disableRipple"], exportAs: ["ngsList"] }, { kind: "component", type: MenuHeading, selector: "ngs-menu-heading" }, { kind: "directive", type: MenuContent, selector: "[ngsMenuContent]" }, { kind: "pipe", type: AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
3538
|
+
], viewQueries: [{ propertyName: "conversionMenu", first: true, predicate: ["conversionMenu"], descendants: true, isSignal: true }, { propertyName: "blockMenu", first: true, predicate: ["suggestionsMenu"], descendants: true, isSignal: true }, { propertyName: "dropList", first: true, predicate: CdkDropList, descendants: true, isSignal: true }], exportAs: ["ngsContentEditorBuilder"], hostDirectives: [{ directive: BlockSelectionDirective, inputs: ["autoScrollContainerSelector", "autoScrollContainerSelector"] }], ngImport: i0, template: "<div class=\"container py-4\">\n <div class=\"content\"\n cdkDropList\n [cdkDropListData]=\"{}\"\n [cdkDropListConnectedTo]=\"connectedDropLists()\"\n [cdkDropListEnterPredicate]=\"canEnterRoot\"\n ngsTextSelectionPopup\n closestContentObserverClass=\"ngs-content-editor-content-editable\"\n [targetComponent]=\"commandBar\"\n (tagSelected)=\"onTagSelected($event)\"\n (cdkDropListDropped)=\"drop($event)\">\n @for (contentBlock of _content(); track contentBlock.id) {\n <div class=\"block\"\n [attr.data-block-id]=\"contentBlock.id\"\n [class.is-focused]=\"isBlockFocused(contentBlock.id)\"\n [class.is-active]=\"isActiveBlock(contentBlock.id)\"\n cdkDrag\n [cdkDragData]=\"contentBlock.id\"\n cdkMonitorSubtreeFocus\n (cdkDragStarted)=\"onDragStarted($event, contentBlock)\"\n (cdkDragEnded)=\"onDragEnded($event, contentBlock)\"\n (cdkFocusChange)=\"onFocusChange($event, contentBlock)\">\n <div class=\"block-controls\" [class.is-settings-popover-open]=\"settingsTrigger.api.isOpen()\">\n <button class=\"block-control\" aria-label=\"Add block\"\n (mousedown)=\"setActiveBlockId($event, contentBlock.id)\"\n [ngsMenuTriggerFor]=\"suggestionsMenu\"\n [ngsMenuTriggerData]=\"{target: {scope: {}, afterId: contentBlock.id}}\"\n [ngsMenuTriggerRestoreFocus]=\"false\">\n <ngs-icon name=\"fluent:add-24-regular\"/>\n </button>\n <div class=\"block-control block-control-drag\"\n (click)=\"selectBlock(contentBlock.id)\"\n [ngsPopoverTriggerFor]=\"settingsPopover\"\n (closed)=\"onSettingsPopoverClose()\"\n #settingsTrigger=\"ngsPopoverTriggerFor\"\n hasBackdrop\n position=\"before-center\">\n <button cdkDragHandle\n trigger=\"hover\"\n closeOnOriginClick\n closeOnOriginMouseLeave\n #dragTrigger=\"ngsPopoverTriggerFor\"\n [ngsPopoverTriggerFor]=\"dragControlTooltip\"\n position=\"below-center\"\n (mousedown)=\"dragTrigger.api.close()\"\n delay=\"1000\" class=\"w-full h-full flex items-center justify-center\">\n <ngs-icon name=\"fluent:re-order-dots-vertical-24-regular\"/>\n </button>\n </div>\n <ng-template #dragControlTooltip>\n <div class=\"bg-on-surface text-xs flex flex-col gap-0.5 rounded-lg items-center px-2 py-1.5 font-medium\">\n <div>\n <div class=\"text-surface\">Drag <span class=\"text-surface/70\">to move</span></div>\n </div>\n <div>\n <div class=\"text-surface\">Click <span class=\"text-surface/70\">to open menu</span></div>\n </div>\n </div>\n </ng-template>\n </div>\n <div class=\"block-content\" [class.is-selected]=\"isBlockSelected(contentBlock.id)\">\n <div class=\"drag-placeholder\" *cdkDragPlaceholder></div>\n <ng-container [ngComponentOutlet]=\"blockDefsMap.get(contentBlock.type) | async\"\n [ngComponentOutletInputs]=\"{\n id: contentBlock.id,\n content: contentBlock.content,\n settings: contentBlock.settings,\n props: contentBlock.props,\n index: $index\n }\"/>\n </div>\n </div>\n }\n </div>\n</div>\n\n<ngs-popover #settingsPopover=\"ngsPopover\">\n <div class=\"px-2 py-0 w-72 settings-popover\">\n <ngs-list>\n @if (selectedBlocksModel.selected.length === 1 && canConvertBlock(selectedBlocksModel.selected[0])) {\n <ngs-list-item [ngsMenuTriggerFor]=\"conversionMenu\" [ngsMenuTriggerData]=\"{blockId: selectedBlocksModel.selected[0]}\" [ngsMenuTriggerRestoreFocus]=\"false\">\n <ngs-icon name=\"fluent:arrow-swap-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Turn into</div>\n </ngs-list-item>\n }\n <ngs-list-item (click)=\"duplicateSelectedBlocks(settingsPopover)\">\n <ngs-icon name=\"fluent:copy-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Duplicate</div>\n </ngs-list-item>\n <ngs-list-item (click)=\"deleteSelectedBlocks(settingsPopover)\">\n <ngs-icon name=\"fluent:delete-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Delete</div>\n </ngs-list-item>\n </ngs-list>\n </div>\n</ngs-popover>\n\n<ngs-menu #suggestionsMenu=\"ngsMenu\" classList=\"min-h-[70vh] max-h-[70vh]! w-80 max-w-[calc(100vw-1rem)]!\" [themeSource]=\"themeSource\" pushIntoViewport (closed)=\"onSuggestionsMenuClose($event)\">\n <ngs-menu-header>\n <div class=\"p-3\">\n <div class=\"mb-2 text-sm font-semibold text-on-surface\">Insert block</div>\n <ngs-form-field subscriptHiddenIfEmpty>\n <input ngsInput aria-label=\"Search blocks\" placeholder=\"Search blocks\u2026\" [value]=\"menuQuery()\" (input)=\"menuQuery.set($any($event.target).value)\" (keydown)=\"onMenuSearchKeydown($event, blockMenu().context()?.target ?? getInsertionTarget())\">\n </ngs-form-field>\n </div>\n </ngs-menu-header>\n <ng-template ngsMenuContent let-target=\"target\">\n <div (click)=\"preventMenuClose($event)\">\n @for (suggestionItem of filteredInsertionSuggestions(); track $index; let first = $first) {\n @switch (suggestionItem.type) {\n @case ('heading') {\n <ngs-menu-heading>{{ suggestionItem.title }}</ngs-menu-heading>\n }\n @case ('item') {\n <button ngs-menu-item\n (click)=\"addBlockFromSuggestionMenu(suggestionsMenu, target, suggestionItem.blockType, suggestionItem.blockSettings)\">\n <div class=\"h-full flex items-center gap-3 py-2\">\n <div class=\"size-9 flex items-center rounded-lg justify-center bg-surface-container\">\n <ngs-icon [name]=\"suggestionItem.iconName\" class=\"!me-0\"/>\n </div>\n <div class=\"grow min-w-[200px]\">\n <div>{{ suggestionItem.title }}</div>\n <div class=\"text-xs text-on-surface-variant\">{{ suggestionItem.description }}</div>\n </div>\n @if (suggestionItem.hotKeys) {\n <div class=\"ms-auto bg-surface-container-highest rounded-full h-5\n text-4xs px-2 flex items-center font-bold\">{{ suggestionItem.hotKeys }}</div>\n }\n </div>\n </button>\n }\n }\n }\n @if (!filteredInsertionSuggestions().length) { <ngs-empty-state>No matching blocks</ngs-empty-state> }\n </div>\n </ng-template>\n</ngs-menu>\n\n<ngs-menu #conversionMenu [themeSource]=\"themeSource\">\n <ng-template ngsMenuContent let-blockId=\"blockId\">\n @for (type of conversionTypes; track type) {\n <button ngs-menu-item (click)=\"convertBlock(blockId, type); settingsPopover.close()\">{{type}}</button>\n }\n </ng-template>\n</ngs-menu>\n", styles: [":host{--ngs-content-editor-builder-content-width: var(--ngs-content-editor-content-width, 704px);font-size:var(--ngs-content-editor-font-size, var(--ngs-font-size-md));line-height:var(--ngs-content-editor-line-height, 1.6);outline:none}:host.is-block-dragging{cursor:grabbing}:host .container{display:flex;width:100%;max-width:820px;min-height:200px;height:100%;padding:calc(var(--spacing, .25rem) * 5) calc(var(--spacing, .25rem) * 5) calc(var(--spacing, .25rem) * 5) 0;margin:0 auto;outline:none}:host .content{flex-grow:1;width:100%;min-width:0}:host .block{position:relative;flex:none;padding:var(--spacing, .25rem) 0;display:flex;align-items:center}:host .block:not(:has(.block-content.is-selected)):hover .block-content{background:var(--ngs-content-editor-hover-bg, var(--ngs-state-hover-bg))}:host:not(.is-block-dragging) .block:hover .block-controls,:host:not(.is-block-dragging) .block.is-active .block-controls,:host:not(.is-block-dragging) .block:focus-within .block-controls{opacity:1}:host .block-content{position:relative;flex-grow:1;min-width:0;padding:var(--ngs-content-editor-block-padding, calc(var(--spacing, .25rem) * 3));border-radius:var(--ngs-content-editor-block-radius, var(--ngs-control-radius))}:host .block-content.is-selected{background:var(--ngs-content-editor-selected-bg, var(--ngs-color-primary-container));color:var(--ngs-content-editor-selected-color, var(--ngs-color-on-primary-container))}:host ::ng-deep .selection-area{background:var(--ngs-content-editor-selected-bg, var(--ngs-color-primary-container));opacity:.4;border:1px solid var(--ngs-color-primary);border-radius:var(--ngs-radius-sm)}:host ::ng-deep .ngs-content-editor-content-editable{-webkit-user-select:text;user-select:text}:host ::ng-deep .ngs-content-editor-content-editable a[data-ngs-headless-editor-mark=link]{color:var(--ngs-color-primary);text-decoration:underline;text-underline-offset:.15em}:host ::ng-deep .ngs-content-editor-content-editable.align-center{text-align:center}:host ::ng-deep .ngs-content-editor-content-editable.align-right{text-align:right}:host ::ng-deep .ngs-content-editor-content-editable.align-justify{text-align:justify}:host ::ng-deep .ngs-content-editor-content-editable>p{margin:0}:host ::ng-deep .ngs-content-editor-content-editable[data-empty]:before{content:attr(data-empty-placeholder);display:block;height:0;color:var(--ngs-content-editor-placeholder-color, var(--ngs-color-on-surface-variant));pointer-events:none}:host.select-none ::ng-deep .ngs-content-editor-content-editable,:host.is-selection-of-blocks-active ::ng-deep .ngs-content-editor-content-editable{-webkit-user-select:none!important;user-select:none!important}:host .block-controls{left:0;display:flex;align-items:center;color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));width:calc(2 * var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8)) + calc(var(--spacing, .25rem) * 4));padding:0 calc(var(--spacing, .25rem) * 2);opacity:0;flex:none}:host .block-controls.is-settings-popover-open{opacity:1}:host .block-controls.is-settings-popover-open .block-control:not(.block-control-drag){opacity:0}:host .block-control{cursor:pointer;width:var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8));height:var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8));flex:none;border-radius:var(--ngs-radius-lg);display:inline-flex;align-items:center;justify-content:center}:host .block-control:hover{background:var(--ngs-color-surface-container-low);color:var(--ngs-color-on-surface)}:host .block-control:focus-visible{outline:2px solid var(--ngs-state-focus-ring);outline-offset:2px}:host .block-control-drag button{cursor:grab}@media(hover:none){:host .block-controls{opacity:1}}:host .drag-placeholder{height:calc(var(--spacing, .25rem) * 8);flex:none;position:relative}:host .drag-placeholder:before{position:absolute;left:calc(var(--spacing, .25rem) * 18);display:block;right:0;content:\"\";height:calc(var(--spacing, .25rem) * 2);top:50%;transform:translateY(-50%);background:var(--ngs-color-primary-300);border-radius:calc(var(--spacing, .25rem) * .5)}:host ::ng-deep ngs-form-field{--ngs-form-field-border-radius: var(--ngs-control-radius);--ngs-form-field-border-color: var(--ngs-content-editor-field-border, var(--ngs-color-outline))}:host ::ng-deep ngs-upload-area{--ngs-upload-area-color: var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));--ngs-upload-area-border: 1px solid var(--ngs-content-editor-field-border, var(--ngs-color-outline));--ngs-upload-area-border-radius: var(--ngs-control-radius)}:host ::ng-deep code{color:var(--ngs-color-primary)}.cdk-drag.cdk-drag-preview{overflow:hidden;display:flex;align-items:center;color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));width:calc(2 * var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8)) + calc(var(--spacing, .25rem) * 4));padding:0 calc(var(--spacing, .25rem) * 2)}.cdk-drag.cdk-drag-preview .block-control{width:var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8));height:var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8));flex:none;border-radius:var(--ngs-radius-lg);display:inline-flex;align-items:center;justify-content:center;cursor:grabbing}.cdk-drag.cdk-drag-preview .block-control:first-child{opacity:0}.cdk-drag.cdk-drag-preview .block-control:last-child{color:var(--ngs-color-on-surface)}.cdk-drag.cdk-drag-preview .block-content{opacity:0}.settings-popover{--ngs-list-list-item-one-line-container-height: calc(var(--spacing, .25rem) * 10)}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "component", type: Icon, selector: "ngs-icon", inputs: ["name"], exportAs: ["ngsIcon"] }, { kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }, { kind: "directive", type: CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer", "cdkDragScale"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: ["cdkDropListConnectedTo", "cdkDropListData", "cdkDropListOrientation", "id", "cdkDropListLockAxis", "cdkDropListDisabled", "cdkDropListSortingDisabled", "cdkDropListEnterPredicate", "cdkDropListSortPredicate", "cdkDropListAutoScrollDisabled", "cdkDropListAutoScrollStep", "cdkDropListElementContainer", "cdkDropListHasAnchor"], outputs: ["cdkDropListDropped", "cdkDropListEntered", "cdkDropListExited", "cdkDropListSorted"], exportAs: ["cdkDropList"] }, { kind: "directive", type: CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { kind: "directive", type: CdkDragPlaceholder, selector: "ng-template[cdkDragPlaceholder]", inputs: ["data"] }, { kind: "component", type: Menu, selector: "ngs-menu", inputs: ["themeSource", "role", "classList", "xPosition", "yPosition", "pushIntoViewport"], outputs: ["closed"], exportAs: ["ngsMenu"] }, { kind: "component", type: MenuItem, selector: "ngs-menu-item, [ngs-menu-item]", inputs: ["disabled", "role", "selected"], outputs: ["_triggered"], exportAs: ["ngsMenuItem"] }, { kind: "directive", type: MenuTrigger, selector: "[ngsMenuTriggerFor]", inputs: ["ngsMenuTriggerFor", "ngsMenuTriggerData", "ngsMenuDisabled", "xPosition", "yPosition", "ngsMenuTriggerRestoreFocus"], outputs: ["menuOpened", "menuClosed"], exportAs: ["ngsMenuTrigger"] }, { kind: "directive", type: CdkMonitorFocus, selector: "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]", outputs: ["cdkFocusChange"], exportAs: ["cdkMonitorFocus"] }, { kind: "directive", type: TextSelectionPopupDirective, selector: "[ngsTextSelectionPopup]", inputs: ["targetComponent", "closestContentObserverClass"], outputs: ["tagSelected"] }, { kind: "directive", type: PopoverTriggerForDirective, selector: "[ngsPopoverTriggerFor]", inputs: ["ngsPopoverTriggerFor", "ngsPopoverContext", "trigger", "position", "delay", "origin", "closeOnOriginClick", "closeOnOriginMouseLeave", "hasBackdrop"], outputs: ["opened", "closed"], exportAs: ["ngsPopoverTriggerFor"] }, { kind: "component", type: Popover, selector: "ngs-popover", exportAs: ["ngsPopover"] }, { kind: "directive", type: ListItemTitle, selector: "[ngsListItemTitle]" }, { kind: "directive", type: ListItemIcon, selector: "[ngsListItemIcon]" }, { kind: "component", type: ListItem, selector: "ngs-list-item, a[ngs-list-item], button[ngs-list-item]", inputs: ["disabled", "lines"], exportAs: ["ngsListItem"] }, { kind: "component", type: List, selector: "ngs-list", inputs: ["disabled", "disableRipple"], exportAs: ["ngsList"] }, { kind: "component", type: MenuHeading, selector: "ngs-menu-heading" }, { kind: "directive", type: MenuContent, selector: "[ngsMenuContent]" }, { kind: "component", type: MenuHeader, selector: "ngs-menu-header", exportAs: ["ngsMenuHeader"] }, { kind: "component", type: FormField, selector: "ngs-form-field", inputs: ["labelMode", "subscriptHiddenIfEmpty", "sameHeightAsButton"], exportAs: ["ngsFormField"] }, { kind: "directive", type: Input, selector: "input[ngsInput], textarea[ngsInput]", inputs: ["id", "placeholder", "required", "disabled", "readonly", "errorStateMatcher"], exportAs: ["ngsInput"] }, { kind: "component", type: EmptyState, selector: "ngs-empty-state", exportAs: ["ngsEmptyState"] }, { kind: "pipe", type: AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
3160
3539
|
}
|
|
3161
3540
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentBuilderComponent, decorators: [{
|
|
3162
3541
|
type: Component,
|
|
@@ -3180,7 +3559,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
3180
3559
|
ListItem,
|
|
3181
3560
|
List,
|
|
3182
3561
|
MenuHeading,
|
|
3183
|
-
MenuContent
|
|
3562
|
+
MenuContent, MenuHeader, FormField, Input, EmptyState
|
|
3184
3563
|
], hostDirectives: [
|
|
3185
3564
|
{
|
|
3186
3565
|
directive: BlockSelectionDirective,
|
|
@@ -3206,8 +3585,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
3206
3585
|
'tabindex': '0',
|
|
3207
3586
|
'(paste)': '_onPaste($event)',
|
|
3208
3587
|
'(keydown)': '_onKeyDown($event)',
|
|
3209
|
-
}, template: "<div class=\"container py-4\">\n <div class=\"content\"\n cdkDropList\n [cdkDropListData]=\"{}\"\n [cdkDropListConnectedTo]=\"connectedDropLists()\"\n [cdkDropListEnterPredicate]=\"canEnterRoot\"\n ngsTextSelectionPopup\n closestContentObserverClass=\"ngs-content-editor-content-editable\"\n [targetComponent]=\"commandBar\"\n (tagSelected)=\"onTagSelected($event)\"\n (cdkDropListDropped)=\"drop($event)\">\n @for (contentBlock of _content(); track contentBlock.id) {\n <div class=\"block\"\n [attr.data-block-id]=\"contentBlock.id\"\n [class.is-focused]=\"isBlockFocused(contentBlock.id)\"\n [class.is-active]=\"isActiveBlock(contentBlock.id)\"\n cdkDrag\n [cdkDragData]=\"contentBlock.id\"\n cdkMonitorSubtreeFocus\n (cdkDragStarted)=\"onDragStarted($event, contentBlock)\"\n (cdkDragEnded)=\"onDragEnded($event, contentBlock)\"\n (cdkFocusChange)=\"onFocusChange($event, contentBlock)\">\n <div class=\"block-controls\" [class.is-settings-popover-open]=\"settingsTrigger.api.isOpen()\">\n <button class=\"block-control\" aria-label=\"Add block\"\n (mousedown)=\"setActiveBlockId($event, contentBlock.id)\"\n [ngsMenuTriggerFor]=\"suggestionsMenu\"\n [ngsMenuTriggerData]=\"{target: {scope: {}, afterId: contentBlock.id}}\"\n [ngsMenuTriggerRestoreFocus]=\"false\">\n <ngs-icon name=\"fluent:add-24-regular\"/>\n </button>\n <div class=\"block-control block-control-drag\"\n (click)=\"selectBlock(contentBlock.id)\"\n [ngsPopoverTriggerFor]=\"settingsPopover\"\n (closed)=\"onSettingsPopoverClose()\"\n #settingsTrigger=\"ngsPopoverTriggerFor\"\n hasBackdrop\n position=\"before-center\">\n <button cdkDragHandle\n trigger=\"hover\"\n closeOnOriginClick\n closeOnOriginMouseLeave\n #dragTrigger=\"ngsPopoverTriggerFor\"\n [ngsPopoverTriggerFor]=\"dragControlTooltip\"\n position=\"below-center\"\n (mousedown)=\"dragTrigger.api.close()\"\n delay=\"1000\" class=\"w-full h-full flex items-center justify-center\">\n <ngs-icon name=\"fluent:re-order-dots-vertical-24-regular\"/>\n </button>\n </div>\n <ng-template #dragControlTooltip>\n <div class=\"bg-neutral-900 text-xs flex flex-col gap-0.5 rounded-lg items-center px-2 py-1.5 font-medium\">\n <div>\n <div class=\"text-neutral-100\">Drag <span class=\"text-neutral-400\">to move</span></div>\n </div>\n <div>\n <div class=\"text-neutral-100\">Click <span class=\"text-neutral-400\">to open menu</span></div>\n </div>\n </div>\n </ng-template>\n </div>\n <div class=\"block-content\" [class.is-selected]=\"isBlockSelected(contentBlock.id)\">\n <div class=\"drag-placeholder\" *cdkDragPlaceholder></div>\n <ng-container [ngComponentOutlet]=\"blockDefsMap.get(contentBlock.type) | async\"\n [ngComponentOutletInputs]=\"{\n id: contentBlock.id,\n content: contentBlock.content,\n settings: contentBlock.settings,\n props: contentBlock.props,\n index: $index\n }\"/>\n </div>\n </div>\n }\n </div>\n</div>\n\n<ngs-popover #settingsPopover=\"ngsPopover\">\n <div class=\"px-2 py-0 w-72 settings-popover\">\n <ngs-list>\n <ngs-list-item (click)=\"duplicateSelectedBlocks(settingsPopover)\">\n <ngs-icon name=\"fluent:copy-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Duplicate</div>\n </ngs-list-item>\n <ngs-list-item (click)=\"deleteSelectedBlocks(settingsPopover)\">\n <ngs-icon name=\"fluent:delete-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Delete</div>\n </ngs-list-item>\n </ngs-list>\n </div>\n</ngs-popover>\n\n<ngs-menu #suggestionsMenu=\"ngsMenu\" classList=\"min-h-[70vh] max-h-[70vh]!\" pushIntoViewport (closed)=\"onSuggestionsMenuClose($event)\">\n <ng-template ngsMenuContent let-target=\"target\">\n <div (click)=\"preventMenuClose($event)\">\n @for (suggestionItem of suggestions(); track $index; let first = $first) {\n @switch (suggestionItem.type) {\n @case ('heading') {\n <ngs-menu-heading>{{ suggestionItem.title }}</ngs-menu-heading>\n }\n @case ('item') {\n <button ngs-menu-item\n (click)=\"addBlockFromSuggestionMenu(suggestionsMenu, target, suggestionItem.blockType, suggestionItem.blockSettings)\">\n <div class=\"h-full flex items-center gap-3 py-2\">\n <div class=\"size-9 flex items-center rounded-lg justify-center bg-surface-container\">\n <ngs-icon [name]=\"suggestionItem.iconName\" class=\"!me-0\"/>\n </div>\n <div class=\"grow min-w-[200px]\">\n <div>{{ suggestionItem.title }}</div>\n <div class=\"text-2xs text-neutral-600\">{{ suggestionItem.description }}</div>\n </div>\n @if (suggestionItem.hotKeys) {\n <div class=\"ms-auto bg-surface-container-highest rounded-full h-5\n text-4xs px-2 flex items-center font-bold\">{{ suggestionItem.hotKeys }}</div>\n }\n </div>\n </button>\n }\n }\n }\n </div>\n </ng-template>\n</ngs-menu>\n", styles: [":host{--ngs-content-editor-builder-content-width: 704px;outline:none}:host.is-block-dragging{cursor:grabbing}:host .container{display:flex;width:100%;max-width:820px;min-height:200px;height:100%;padding:calc(var(--spacing, .25rem) * 5) calc(var(--spacing, .25rem) * 5) calc(var(--spacing, .25rem) * 5) 0;margin:0 auto;outline:none}:host .content{flex-grow:1;width:100%;min-width:0}:host .block{position:relative;flex:none;padding:var(--spacing, .25rem) 0;display:flex;align-items:center}:host .block:not(:has(.block-content.is-selected)):hover .block-content{background:var(--ngs-color-neutral-50)}:host:not(.is-block-dragging) .block:hover .block-controls,:host:not(.is-block-dragging) .block.is-active .block-controls{opacity:1}:host .block-content{position:relative;flex-grow:1;min-width:0;padding:calc(var(--spacing, .25rem) * 3)}:host .block-content.is-selected{background:var(--ngs-color-primary-100)}:host ::ng-deep .selection-area{background:var(--ngs-color-primary-100);opacity:.4;border:1px solid var(--ngs-color-primary);border-radius:var(--ngs-radius-sm)}:host ::ng-deep .ngs-content-editor-content-editable{-webkit-user-select:text;user-select:text}:host ::ng-deep .ngs-content-editor-content-editable a[data-ngs-headless-editor-mark=link]{color:var(--ngs-color-primary);text-decoration:underline;text-underline-offset:.15em}:host ::ng-deep .ngs-content-editor-content-editable.align-center{text-align:center}:host ::ng-deep .ngs-content-editor-content-editable.align-right{text-align:right}:host ::ng-deep .ngs-content-editor-content-editable.align-justify{text-align:justify}:host ::ng-deep .ngs-content-editor-content-editable>p{margin:0}:host ::ng-deep .ngs-content-editor-content-editable[data-empty]:before{content:attr(data-empty-placeholder);display:block;height:0;color:var(--ngs-color-neutral-500);pointer-events:none}:host.select-none ::ng-deep .ngs-content-editor-content-editable,:host.is-selection-of-blocks-active ::ng-deep .ngs-content-editor-content-editable{-webkit-user-select:none!important;user-select:none!important}:host .block-controls{left:0;display:flex;align-items:center;color:var(--ngs-color-neutral-500);width:calc(var(--spacing, .25rem) * 18);padding:0 calc(var(--spacing, .25rem) * 2);opacity:0;flex:none}:host .block-controls.is-settings-popover-open{opacity:1}:host .block-controls.is-settings-popover-open .block-control:not(.block-control-drag){opacity:0}:host .block-control{cursor:pointer;width:calc(var(--spacing, .25rem) * 7);height:calc(var(--spacing, .25rem) * 7);flex:none;border-radius:var(--ngs-radius-lg);display:inline-flex;align-items:center;justify-content:center}:host .block-control:hover{background:var(--ngs-color-surface-container-low);color:var(--ngs-color-on-surface)}:host .block-control-drag button{cursor:grab}:host .drag-placeholder{height:calc(var(--spacing, .25rem) * 8);flex:none;position:relative}:host .drag-placeholder:before{position:absolute;left:calc(var(--spacing, .25rem) * 18);display:block;right:0;content:\"\";height:calc(var(--spacing, .25rem) * 2);top:50%;transform:translateY(-50%);background:var(--ngs-color-primary-300);border-radius:calc(var(--spacing, .25rem) * .5)}:host ::ng-deep code{color:var(--ngs-color-primary)}.cdk-drag.cdk-drag-preview{overflow:hidden;display:flex;align-items:center;color:var(--ngs-color-neutral-500);width:calc(var(--spacing, .25rem) * 18);padding:0 calc(var(--spacing, .25rem) * 2)}.cdk-drag.cdk-drag-preview .block-control{width:calc(var(--spacing, .25rem) * 7);height:calc(var(--spacing, .25rem) * 7);flex:none;border-radius:var(--ngs-radius-lg);display:inline-flex;align-items:center;justify-content:center;cursor:grabbing}.cdk-drag.cdk-drag-preview .block-control:first-child{opacity:0}.cdk-drag.cdk-drag-preview .block-control:last-child{color:var(--ngs-color-on-surface)}.cdk-drag.cdk-drag-preview .block-content{opacity:0}.settings-popover{--ngs-list-list-item-one-line-container-height: calc(var(--spacing, .25rem) * 10)}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3210
|
-
}], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: false }] }], blockMenu: [{ type: i0.ViewChild, args: ['suggestionsMenu', { isSignal: true }] }], dropList: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CdkDropList), { isSignal: true }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], contentChangedDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "contentChangedDelay", required: false }] }], persistDraft: [{ type: i0.Input, args: [{ isSignal: true, alias: "persistDraft", required: false }] }], suggestions: [{ type: i0.Input, args: [{ isSignal: true, alias: "suggestions", required: false }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: false }] }], scrollContainer: [{ type: i0.Input, args: [{ isSignal: true, alias: "scrollContainer", required: false }] }], contentChanged: [{ type: i0.Output, args: ["contentChanged"] }] } });
|
|
3588
|
+
}, template: "<div class=\"container py-4\">\n <div class=\"content\"\n cdkDropList\n [cdkDropListData]=\"{}\"\n [cdkDropListConnectedTo]=\"connectedDropLists()\"\n [cdkDropListEnterPredicate]=\"canEnterRoot\"\n ngsTextSelectionPopup\n closestContentObserverClass=\"ngs-content-editor-content-editable\"\n [targetComponent]=\"commandBar\"\n (tagSelected)=\"onTagSelected($event)\"\n (cdkDropListDropped)=\"drop($event)\">\n @for (contentBlock of _content(); track contentBlock.id) {\n <div class=\"block\"\n [attr.data-block-id]=\"contentBlock.id\"\n [class.is-focused]=\"isBlockFocused(contentBlock.id)\"\n [class.is-active]=\"isActiveBlock(contentBlock.id)\"\n cdkDrag\n [cdkDragData]=\"contentBlock.id\"\n cdkMonitorSubtreeFocus\n (cdkDragStarted)=\"onDragStarted($event, contentBlock)\"\n (cdkDragEnded)=\"onDragEnded($event, contentBlock)\"\n (cdkFocusChange)=\"onFocusChange($event, contentBlock)\">\n <div class=\"block-controls\" [class.is-settings-popover-open]=\"settingsTrigger.api.isOpen()\">\n <button class=\"block-control\" aria-label=\"Add block\"\n (mousedown)=\"setActiveBlockId($event, contentBlock.id)\"\n [ngsMenuTriggerFor]=\"suggestionsMenu\"\n [ngsMenuTriggerData]=\"{target: {scope: {}, afterId: contentBlock.id}}\"\n [ngsMenuTriggerRestoreFocus]=\"false\">\n <ngs-icon name=\"fluent:add-24-regular\"/>\n </button>\n <div class=\"block-control block-control-drag\"\n (click)=\"selectBlock(contentBlock.id)\"\n [ngsPopoverTriggerFor]=\"settingsPopover\"\n (closed)=\"onSettingsPopoverClose()\"\n #settingsTrigger=\"ngsPopoverTriggerFor\"\n hasBackdrop\n position=\"before-center\">\n <button cdkDragHandle\n trigger=\"hover\"\n closeOnOriginClick\n closeOnOriginMouseLeave\n #dragTrigger=\"ngsPopoverTriggerFor\"\n [ngsPopoverTriggerFor]=\"dragControlTooltip\"\n position=\"below-center\"\n (mousedown)=\"dragTrigger.api.close()\"\n delay=\"1000\" class=\"w-full h-full flex items-center justify-center\">\n <ngs-icon name=\"fluent:re-order-dots-vertical-24-regular\"/>\n </button>\n </div>\n <ng-template #dragControlTooltip>\n <div class=\"bg-on-surface text-xs flex flex-col gap-0.5 rounded-lg items-center px-2 py-1.5 font-medium\">\n <div>\n <div class=\"text-surface\">Drag <span class=\"text-surface/70\">to move</span></div>\n </div>\n <div>\n <div class=\"text-surface\">Click <span class=\"text-surface/70\">to open menu</span></div>\n </div>\n </div>\n </ng-template>\n </div>\n <div class=\"block-content\" [class.is-selected]=\"isBlockSelected(contentBlock.id)\">\n <div class=\"drag-placeholder\" *cdkDragPlaceholder></div>\n <ng-container [ngComponentOutlet]=\"blockDefsMap.get(contentBlock.type) | async\"\n [ngComponentOutletInputs]=\"{\n id: contentBlock.id,\n content: contentBlock.content,\n settings: contentBlock.settings,\n props: contentBlock.props,\n index: $index\n }\"/>\n </div>\n </div>\n }\n </div>\n</div>\n\n<ngs-popover #settingsPopover=\"ngsPopover\">\n <div class=\"px-2 py-0 w-72 settings-popover\">\n <ngs-list>\n @if (selectedBlocksModel.selected.length === 1 && canConvertBlock(selectedBlocksModel.selected[0])) {\n <ngs-list-item [ngsMenuTriggerFor]=\"conversionMenu\" [ngsMenuTriggerData]=\"{blockId: selectedBlocksModel.selected[0]}\" [ngsMenuTriggerRestoreFocus]=\"false\">\n <ngs-icon name=\"fluent:arrow-swap-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Turn into</div>\n </ngs-list-item>\n }\n <ngs-list-item (click)=\"duplicateSelectedBlocks(settingsPopover)\">\n <ngs-icon name=\"fluent:copy-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Duplicate</div>\n </ngs-list-item>\n <ngs-list-item (click)=\"deleteSelectedBlocks(settingsPopover)\">\n <ngs-icon name=\"fluent:delete-24-regular\" ngsListItemIcon/>\n <div ngsListItemTitle>Delete</div>\n </ngs-list-item>\n </ngs-list>\n </div>\n</ngs-popover>\n\n<ngs-menu #suggestionsMenu=\"ngsMenu\" classList=\"min-h-[70vh] max-h-[70vh]! w-80 max-w-[calc(100vw-1rem)]!\" [themeSource]=\"themeSource\" pushIntoViewport (closed)=\"onSuggestionsMenuClose($event)\">\n <ngs-menu-header>\n <div class=\"p-3\">\n <div class=\"mb-2 text-sm font-semibold text-on-surface\">Insert block</div>\n <ngs-form-field subscriptHiddenIfEmpty>\n <input ngsInput aria-label=\"Search blocks\" placeholder=\"Search blocks\u2026\" [value]=\"menuQuery()\" (input)=\"menuQuery.set($any($event.target).value)\" (keydown)=\"onMenuSearchKeydown($event, blockMenu().context()?.target ?? getInsertionTarget())\">\n </ngs-form-field>\n </div>\n </ngs-menu-header>\n <ng-template ngsMenuContent let-target=\"target\">\n <div (click)=\"preventMenuClose($event)\">\n @for (suggestionItem of filteredInsertionSuggestions(); track $index; let first = $first) {\n @switch (suggestionItem.type) {\n @case ('heading') {\n <ngs-menu-heading>{{ suggestionItem.title }}</ngs-menu-heading>\n }\n @case ('item') {\n <button ngs-menu-item\n (click)=\"addBlockFromSuggestionMenu(suggestionsMenu, target, suggestionItem.blockType, suggestionItem.blockSettings)\">\n <div class=\"h-full flex items-center gap-3 py-2\">\n <div class=\"size-9 flex items-center rounded-lg justify-center bg-surface-container\">\n <ngs-icon [name]=\"suggestionItem.iconName\" class=\"!me-0\"/>\n </div>\n <div class=\"grow min-w-[200px]\">\n <div>{{ suggestionItem.title }}</div>\n <div class=\"text-xs text-on-surface-variant\">{{ suggestionItem.description }}</div>\n </div>\n @if (suggestionItem.hotKeys) {\n <div class=\"ms-auto bg-surface-container-highest rounded-full h-5\n text-4xs px-2 flex items-center font-bold\">{{ suggestionItem.hotKeys }}</div>\n }\n </div>\n </button>\n }\n }\n }\n @if (!filteredInsertionSuggestions().length) { <ngs-empty-state>No matching blocks</ngs-empty-state> }\n </div>\n </ng-template>\n</ngs-menu>\n\n<ngs-menu #conversionMenu [themeSource]=\"themeSource\">\n <ng-template ngsMenuContent let-blockId=\"blockId\">\n @for (type of conversionTypes; track type) {\n <button ngs-menu-item (click)=\"convertBlock(blockId, type); settingsPopover.close()\">{{type}}</button>\n }\n </ng-template>\n</ngs-menu>\n", styles: [":host{--ngs-content-editor-builder-content-width: var(--ngs-content-editor-content-width, 704px);font-size:var(--ngs-content-editor-font-size, var(--ngs-font-size-md));line-height:var(--ngs-content-editor-line-height, 1.6);outline:none}:host.is-block-dragging{cursor:grabbing}:host .container{display:flex;width:100%;max-width:820px;min-height:200px;height:100%;padding:calc(var(--spacing, .25rem) * 5) calc(var(--spacing, .25rem) * 5) calc(var(--spacing, .25rem) * 5) 0;margin:0 auto;outline:none}:host .content{flex-grow:1;width:100%;min-width:0}:host .block{position:relative;flex:none;padding:var(--spacing, .25rem) 0;display:flex;align-items:center}:host .block:not(:has(.block-content.is-selected)):hover .block-content{background:var(--ngs-content-editor-hover-bg, var(--ngs-state-hover-bg))}:host:not(.is-block-dragging) .block:hover .block-controls,:host:not(.is-block-dragging) .block.is-active .block-controls,:host:not(.is-block-dragging) .block:focus-within .block-controls{opacity:1}:host .block-content{position:relative;flex-grow:1;min-width:0;padding:var(--ngs-content-editor-block-padding, calc(var(--spacing, .25rem) * 3));border-radius:var(--ngs-content-editor-block-radius, var(--ngs-control-radius))}:host .block-content.is-selected{background:var(--ngs-content-editor-selected-bg, var(--ngs-color-primary-container));color:var(--ngs-content-editor-selected-color, var(--ngs-color-on-primary-container))}:host ::ng-deep .selection-area{background:var(--ngs-content-editor-selected-bg, var(--ngs-color-primary-container));opacity:.4;border:1px solid var(--ngs-color-primary);border-radius:var(--ngs-radius-sm)}:host ::ng-deep .ngs-content-editor-content-editable{-webkit-user-select:text;user-select:text}:host ::ng-deep .ngs-content-editor-content-editable a[data-ngs-headless-editor-mark=link]{color:var(--ngs-color-primary);text-decoration:underline;text-underline-offset:.15em}:host ::ng-deep .ngs-content-editor-content-editable.align-center{text-align:center}:host ::ng-deep .ngs-content-editor-content-editable.align-right{text-align:right}:host ::ng-deep .ngs-content-editor-content-editable.align-justify{text-align:justify}:host ::ng-deep .ngs-content-editor-content-editable>p{margin:0}:host ::ng-deep .ngs-content-editor-content-editable[data-empty]:before{content:attr(data-empty-placeholder);display:block;height:0;color:var(--ngs-content-editor-placeholder-color, var(--ngs-color-on-surface-variant));pointer-events:none}:host.select-none ::ng-deep .ngs-content-editor-content-editable,:host.is-selection-of-blocks-active ::ng-deep .ngs-content-editor-content-editable{-webkit-user-select:none!important;user-select:none!important}:host .block-controls{left:0;display:flex;align-items:center;color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));width:calc(2 * var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8)) + calc(var(--spacing, .25rem) * 4));padding:0 calc(var(--spacing, .25rem) * 2);opacity:0;flex:none}:host .block-controls.is-settings-popover-open{opacity:1}:host .block-controls.is-settings-popover-open .block-control:not(.block-control-drag){opacity:0}:host .block-control{cursor:pointer;width:var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8));height:var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8));flex:none;border-radius:var(--ngs-radius-lg);display:inline-flex;align-items:center;justify-content:center}:host .block-control:hover{background:var(--ngs-color-surface-container-low);color:var(--ngs-color-on-surface)}:host .block-control:focus-visible{outline:2px solid var(--ngs-state-focus-ring);outline-offset:2px}:host .block-control-drag button{cursor:grab}@media(hover:none){:host .block-controls{opacity:1}}:host .drag-placeholder{height:calc(var(--spacing, .25rem) * 8);flex:none;position:relative}:host .drag-placeholder:before{position:absolute;left:calc(var(--spacing, .25rem) * 18);display:block;right:0;content:\"\";height:calc(var(--spacing, .25rem) * 2);top:50%;transform:translateY(-50%);background:var(--ngs-color-primary-300);border-radius:calc(var(--spacing, .25rem) * .5)}:host ::ng-deep ngs-form-field{--ngs-form-field-border-radius: var(--ngs-control-radius);--ngs-form-field-border-color: var(--ngs-content-editor-field-border, var(--ngs-color-outline))}:host ::ng-deep ngs-upload-area{--ngs-upload-area-color: var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));--ngs-upload-area-border: 1px solid var(--ngs-content-editor-field-border, var(--ngs-color-outline));--ngs-upload-area-border-radius: var(--ngs-control-radius)}:host ::ng-deep code{color:var(--ngs-color-primary)}.cdk-drag.cdk-drag-preview{overflow:hidden;display:flex;align-items:center;color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));width:calc(2 * var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8)) + calc(var(--spacing, .25rem) * 4));padding:0 calc(var(--spacing, .25rem) * 2)}.cdk-drag.cdk-drag-preview .block-control{width:var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8));height:var(--ngs-content-editor-control-size, calc(var(--spacing, .25rem) * 8));flex:none;border-radius:var(--ngs-radius-lg);display:inline-flex;align-items:center;justify-content:center;cursor:grabbing}.cdk-drag.cdk-drag-preview .block-control:first-child{opacity:0}.cdk-drag.cdk-drag-preview .block-control:last-child{color:var(--ngs-color-on-surface)}.cdk-drag.cdk-drag-preview .block-content{opacity:0}.settings-popover{--ngs-list-list-item-one-line-container-height: calc(var(--spacing, .25rem) * 10)}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3589
|
+
}], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: false }] }], conversionMenu: [{ type: i0.ViewChild, args: ['conversionMenu', { isSignal: true }] }], blockMenu: [{ type: i0.ViewChild, args: ['suggestionsMenu', { isSignal: true }] }], documentId: [{ type: i0.Input, args: [{ isSignal: true, alias: "documentId", required: false }] }], draftDebounceMs: [{ type: i0.Input, args: [{ isSignal: true, alias: "draftDebounceMs", required: false }] }], dropList: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CdkDropList), { isSignal: true }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], contentChangedDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "contentChangedDelay", required: false }] }], persistDraft: [{ type: i0.Input, args: [{ isSignal: true, alias: "persistDraft", required: false }] }], suggestions: [{ type: i0.Input, args: [{ isSignal: true, alias: "suggestions", required: false }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: false }] }], scrollContainer: [{ type: i0.Input, args: [{ isSignal: true, alias: "scrollContainer", required: false }] }], contentChanged: [{ type: i0.Output, args: ["contentChanged"] }] } });
|
|
3211
3590
|
|
|
3212
3591
|
const CONTENT_EDITOR_BLOCK_RENDERERS = new InjectionToken('CONTENT_EDITOR_BLOCK_RENDERERS', {
|
|
3213
3592
|
factory: () => [],
|
|
@@ -3346,13 +3725,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
3346
3725
|
args: [{ selector: 'ngs-content-editor-gallery-renderer', imports: [NgsHeadlessEditorRuns, ImageViewerDirective, ImageViewerPictureDirective, Carousel, CarouselCard, Button, Icon], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (selectedImage(); as image) {\n <figure class=\"gallery m-0 flex min-w-0 flex-col gap-4\" ngsImageViewer role=\"region\" aria-label=\"Image gallery\" aria-roledescription=\"carousel\" (keydown)=\"onKeydown($event)\">\n <div class=\"gallery-preview relative overflow-hidden rounded-lg\">\n <ngs-carousel tabindex=\"0\" aria-label=\"Gallery images. Use arrow keys to navigate.\" (indexChange)=\"onIndexChange($event)\">\n @for (slide of images(); track slide.id) {\n <ngs-carousel-card role=\"group\" aria-roledescription=\"slide\" [attr.aria-label]=\"($index + 1) + ' of ' + images().length\" [attr.aria-hidden]=\"$index !== selectedIndex()\">\n <button ngsButton type=\"button\" class=\"gallery-picture\" [fullWidth]=\"true\" [attr.tabindex]=\"$index === selectedIndex() ? 0 : -1\" ngsImageViewerPicture [sourceUrl]=\"slide.src\" [caption]=\"captionText(slide.caption)\" [attr.aria-label]=\"slide.alt || 'View image'\">\n <img [src]=\"slide.src\" [alt]=\"slide.alt\" draggable=\"false\">\n </button>\n </ngs-carousel-card>\n }\n </ngs-carousel>\n <button ngsIconButton type=\"button\" class=\"preview-action expand-action absolute right-3 top-3\" aria-label=\"View full-size image\" ngsImageViewerPicture [sourceUrl]=\"image.src\" [caption]=\"captionText(image.caption)\">\n <ngs-icon name=\"fluent:arrow-expand-24-regular\"/>\n </button>\n @if (images().length > 1) {\n <button ngsIconButton type=\"button\" class=\"preview-action absolute left-3 top-1/2 -translate-y-1/2\" aria-label=\"Previous image\" [disabled]=\"selectedIndex() === 0\" (click)=\"selectImage(selectedIndex() - 1)\"><ngs-icon name=\"fluent:chevron-left-24-regular\"/></button>\n <button ngsIconButton type=\"button\" class=\"preview-action absolute right-3 top-1/2 -translate-y-1/2\" aria-label=\"Next image\" [disabled]=\"selectedIndex() === images().length - 1\" (click)=\"selectImage(selectedIndex() + 1)\"><ngs-icon name=\"fluent:chevron-right-24-regular\"/></button>\n }\n </div>\n @if (captionText(image.caption) || images().length > 1) {\n <figcaption class=\"flex min-w-0 items-start justify-between gap-4\">\n <span class=\"gallery-caption min-w-0 flex-1 text-sm\" [ngsHeadlessEditorRuns]=\"image.caption\"></span>\n @if (images().length > 1) {\n <span class=\"gallery-counter shrink-0 text-sm\" aria-live=\"polite\" aria-atomic=\"true\">{{ selectedIndex() + 1 }} of {{ images().length }}</span>\n }\n </figcaption>\n }\n @if (images().length > 1) {\n <div class=\"thumbnail-strip relative flex min-w-0 gap-3 overflow-x-auto p-1\" role=\"group\" aria-label=\"Choose an image\">\n @for (thumbnail of images(); track thumbnail.id) {\n <button #thumbnailButton ngsButton type=\"button\" class=\"thumbnail-picture shrink-0\" [class.is-selected]=\"$index === selectedIndex()\" [attr.aria-label]=\"'Select image ' + ($index + 1)\" [attr.aria-pressed]=\"$index === selectedIndex()\" (click)=\"selectImage($index)\">\n <img [src]=\"thumbnail.src\" alt=\"\" draggable=\"false\" loading=\"lazy\">\n </button>\n }\n </div>\n }\n </figure>\n}\n", styles: [":host{display:block;min-width:0}:host .gallery{margin:0}:host figcaption{margin:0}:host ngs-carousel{--ngs-carousel-gap: 0px;outline-offset:-3px}:host ngs-carousel:focus-visible{outline:2px solid var(--ngs-color-primary)}:host ngs-carousel ::ng-deep .content{overflow-x:auto;scrollbar-width:none;scroll-snap-type:x mandatory}:host ngs-carousel ::ng-deep .content::-webkit-scrollbar{display:none}:host ngs-carousel-card{width:100%;min-width:0;scroll-snap-align:center}:host button[ngsButton]{--ngs-button-height: auto;--ngs-button-padding: 0;--ngs-button-content-gap: 0;display:block;min-width:0;overflow:hidden;line-height:0}:host button[ngsButton] img{display:block;width:100%;margin:0;object-fit:cover}:host button[ngsButton] ::ng-deep .content{display:block;width:100%}:host button[ngsButton].gallery-picture{width:100%;border-radius:0}:host button[ngsButton].gallery-picture img{aspect-ratio:16/9}:host button[ngsButton].thumbnail-picture{width:calc(var(--spacing, .25rem) * 32);border-radius:var(--ngs-radius-md)}:host button[ngsButton].thumbnail-picture img{aspect-ratio:16/9}:host button[ngsButton].thumbnail-picture.is-selected{outline:2px solid var(--ngs-color-primary);outline-offset:2px}:host .gallery-preview{background:var(--ngs-color-surface-container-low)}:host button[ngsIconButton].preview-action{--ngs-button-height: calc(var(--spacing, .25rem) * 9);--ngs-button-bg: var(--ngs-color-white);--ngs-button-color: var(--ngs-color-black);--ngs-button-hover-bg: var(--ngs-color-white);position:absolute;box-shadow:var(--ngs-shadow-sm)}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].preview-action{--ngs-button-hover-bg: color-mix(in srgb, var(--ngs-color-white), var(--ngs-color-black) 8%)}}:host button[ngsIconButton].preview-action.ngs-button-disabled{opacity:.55;background:var(--ngs-color-white)}:host .gallery-caption,:host .gallery-counter{color:var(--ngs-color-on-surface-variant)}:host .gallery-caption{overflow-wrap:anywhere}:host .thumbnail-strip{scrollbar-width:thin}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3347
3726
|
}], ctorParameters: () => [], propDecorators: { cards: [{ type: i0.ViewChildren, args: [i0.forwardRef(() => CarouselCard), { isSignal: true }] }], thumbnails: [{ type: i0.ViewChildren, args: ['thumbnailButton', { ...{ read: (ElementRef) }, isSignal: true }] }] } });
|
|
3348
3727
|
|
|
3349
|
-
/** Read files
|
|
3350
|
-
function readContentEditorFile(file) {
|
|
3728
|
+
/** Read files with actual cancellation and progress. */
|
|
3729
|
+
function readContentEditorFile(file, context) {
|
|
3351
3730
|
return new Promise((resolve, reject) => {
|
|
3352
3731
|
const reader = new FileReader();
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3732
|
+
const abort = () => { reader.abort(); reject(new DOMException('Upload cancelled', 'AbortError')); cleanup(); };
|
|
3733
|
+
const cleanup = () => context?.signal.removeEventListener('abort', abort);
|
|
3734
|
+
if (context?.signal.aborted) {
|
|
3735
|
+
abort();
|
|
3736
|
+
return;
|
|
3737
|
+
}
|
|
3738
|
+
context?.signal.addEventListener('abort', abort, { once: true });
|
|
3739
|
+
reader.onload = () => { cleanup(); typeof reader.result === 'string' ? resolve(reader.result) : reject(new Error('Could not read file')); };
|
|
3740
|
+
reader.onerror = () => { cleanup(); reject(new Error('Could not read file')); };
|
|
3741
|
+
reader.onabort = () => { cleanup(); reject(new DOMException('Upload cancelled', 'AbortError')); };
|
|
3742
|
+
reader.onprogress = event => { if (event.lengthComputable)
|
|
3743
|
+
context?.onProgress(event.loaded / event.total * 100); };
|
|
3356
3744
|
reader.readAsDataURL(file);
|
|
3357
3745
|
});
|
|
3358
3746
|
}
|
|
@@ -3520,13 +3908,13 @@ class ContentEditorHeadingRenderer {
|
|
|
3520
3908
|
...(ngDevMode ? [{ debugName: "runs" }] : /* istanbul ignore next */ []));
|
|
3521
3909
|
level = computed(() => {
|
|
3522
3910
|
const level = this.settings()?.level;
|
|
3523
|
-
return level ===
|
|
3911
|
+
return typeof level === 'number' && Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2;
|
|
3524
3912
|
}, /* @ts-ignore */
|
|
3525
3913
|
...(ngDevMode ? [{ debugName: "level" }] : /* istanbul ignore next */ []));
|
|
3526
3914
|
alignment = computed(() => getTextAlignment(this.props()), /* @ts-ignore */
|
|
3527
3915
|
...(ngDevMode ? [{ debugName: "alignment" }] : /* istanbul ignore next */ []));
|
|
3528
3916
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorHeadingRenderer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3529
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorHeadingRenderer, isStandalone: true, selector: "ngs-content-editor-heading-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.level-1": "level() === 1", "class.level-2": "level() === 2", "class.level-3": "level() === 3" }, classAttribute: "ngs-content-editor-heading-renderer" }, ngImport: i0, template: "@switch (level()) {\n @case (1) {\n <h1\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h1>\n }\n @case (3) {\n <h3\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h3>\n }\n @default {\n <h2\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h2>\n }\n}\n", styles: [":host{display:block}:host .content-html{margin:0;font-weight:
|
|
3917
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorHeadingRenderer, isStandalone: true, selector: "ngs-content-editor-heading-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.level-1": "level() === 1", "class.level-2": "level() === 2", "class.level-3": "level() === 3", "class.level-6": "level() === 6", "class.level-5": "level() === 5", "class.level-4": "level() === 4" }, classAttribute: "ngs-content-editor-heading-renderer" }, ngImport: i0, template: "@switch (level()) {\n @case (1) {\n <h1\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h1>\n }\n @case (3) {\n <h3\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h3>\n }\n @case (4) {\n <h4 class=\"content-html\" [class.align-left]=\"alignment() === 'left'\" [class.align-center]=\"alignment() === 'center'\" [class.align-right]=\"alignment() === 'right'\" [class.align-justify]=\"alignment() === 'justify'\" [ngsHeadlessEditorRuns]=\"runs()\"></h4>\n }\n @case (5) {\n <h5 class=\"content-html\" [class.align-left]=\"alignment() === 'left'\" [class.align-center]=\"alignment() === 'center'\" [class.align-right]=\"alignment() === 'right'\" [class.align-justify]=\"alignment() === 'justify'\" [ngsHeadlessEditorRuns]=\"runs()\"></h5>\n }\n @case (6) {\n <h6 class=\"content-html\" [class.align-left]=\"alignment() === 'left'\" [class.align-center]=\"alignment() === 'center'\" [class.align-right]=\"alignment() === 'right'\" [class.align-justify]=\"alignment() === 'justify'\" [ngsHeadlessEditorRuns]=\"runs()\"></h6>\n }\n @default {\n <h2\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h2>\n }\n}\n", styles: [":host{display:block}:host .align-left{text-align:left}:host .align-center{text-align:center}:host .align-right{text-align:right}:host .align-justify{text-align:justify}:host .content-html{margin:0;outline:none;font-weight:var(--ngs-content-editor-heading-weight, 650);line-height:var(--ngs-content-editor-heading-line-height, 1.2)}:host.level-1 .content-html{font-size:var(--ngs-content-editor-heading-1-size, 2.5rem)}:host.level-2 .content-html{font-size:var(--ngs-content-editor-heading-2-size, 2rem)}:host.level-3 .content-html{font-size:var(--ngs-content-editor-heading-3-size, 1.5rem)}:host.level-4 .content-html{font-size:var(--ngs-content-editor-heading-4-size, 1.25rem)}:host.level-5 .content-html{font-size:var(--ngs-content-editor-heading-5-size, 1.125rem)}:host.level-6 .content-html{font-size:var(--ngs-content-editor-heading-6-size, 1rem)}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "directive", type: NgsHeadlessEditorRuns, selector: "[ngsHeadlessEditorRuns]", inputs: ["ngsHeadlessEditorRuns"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
3530
3918
|
}
|
|
3531
3919
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorHeadingRenderer, decorators: [{
|
|
3532
3920
|
type: Component,
|
|
@@ -3537,7 +3925,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
3537
3925
|
'[class.level-1]': 'level() === 1',
|
|
3538
3926
|
'[class.level-2]': 'level() === 2',
|
|
3539
3927
|
'[class.level-3]': 'level() === 3',
|
|
3540
|
-
|
|
3928
|
+
'[class.level-6]': 'level() === 6',
|
|
3929
|
+
'[class.level-5]': 'level() === 5',
|
|
3930
|
+
'[class.level-4]': 'level() === 4',
|
|
3931
|
+
}, template: "@switch (level()) {\n @case (1) {\n <h1\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h1>\n }\n @case (3) {\n <h3\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h3>\n }\n @case (4) {\n <h4 class=\"content-html\" [class.align-left]=\"alignment() === 'left'\" [class.align-center]=\"alignment() === 'center'\" [class.align-right]=\"alignment() === 'right'\" [class.align-justify]=\"alignment() === 'justify'\" [ngsHeadlessEditorRuns]=\"runs()\"></h4>\n }\n @case (5) {\n <h5 class=\"content-html\" [class.align-left]=\"alignment() === 'left'\" [class.align-center]=\"alignment() === 'center'\" [class.align-right]=\"alignment() === 'right'\" [class.align-justify]=\"alignment() === 'justify'\" [ngsHeadlessEditorRuns]=\"runs()\"></h5>\n }\n @case (6) {\n <h6 class=\"content-html\" [class.align-left]=\"alignment() === 'left'\" [class.align-center]=\"alignment() === 'center'\" [class.align-right]=\"alignment() === 'right'\" [class.align-justify]=\"alignment() === 'justify'\" [ngsHeadlessEditorRuns]=\"runs()\"></h6>\n }\n @default {\n <h2\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n ></h2>\n }\n}\n", styles: [":host{display:block}:host .align-left{text-align:left}:host .align-center{text-align:center}:host .align-right{text-align:right}:host .align-justify{text-align:justify}:host .content-html{margin:0;outline:none;font-weight:var(--ngs-content-editor-heading-weight, 650);line-height:var(--ngs-content-editor-heading-line-height, 1.2)}:host.level-1 .content-html{font-size:var(--ngs-content-editor-heading-1-size, 2.5rem)}:host.level-2 .content-html{font-size:var(--ngs-content-editor-heading-2-size, 2rem)}:host.level-3 .content-html{font-size:var(--ngs-content-editor-heading-3-size, 1.5rem)}:host.level-4 .content-html{font-size:var(--ngs-content-editor-heading-4-size, 1.25rem)}:host.level-5 .content-html{font-size:var(--ngs-content-editor-heading-5-size, 1.125rem)}:host.level-6 .content-html{font-size:var(--ngs-content-editor-heading-6-size, 1rem)}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3541
3932
|
}], propDecorators: { block: [{ type: i0.Input, args: [{ isSignal: true, alias: "block", required: false }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], settings: [{ type: i0.Input, args: [{ isSignal: true, alias: "settings", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], index: [{ type: i0.Input, args: [{ isSignal: true, alias: "index", required: false }] }] } });
|
|
3542
3933
|
|
|
3543
3934
|
class ContentEditorImageRenderer {
|
|
@@ -3564,13 +3955,13 @@ class ContentEditorImageRenderer {
|
|
|
3564
3955
|
height = computed(() => getDimensionAttribute(this.settings()?.height), /* @ts-ignore */
|
|
3565
3956
|
...(ngDevMode ? [{ debugName: "height" }] : /* istanbul ignore next */ []));
|
|
3566
3957
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorImageRenderer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3567
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorImageRenderer, isStandalone: true, selector: "ngs-content-editor-image-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-image-renderer" }, ngImport: i0, template: "@if (src()) {\n <figure>\n <img [src]=\"src()\" [alt]=\"alt()\" [attr.width]=\"width()\" [attr.height]=\"height()\">\n @if (alt()) {\n <figcaption>{{ alt() }}</figcaption>\n }\n </figure>\n}\n", styles: [":host{display:block}:host figure{margin:0}:host img{display:block;max-width:100%;height:auto}:host figcaption{margin-top:calc(var(--spacing, .25rem) * 2);color:var(--ngs-color-
|
|
3958
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorImageRenderer, isStandalone: true, selector: "ngs-content-editor-image-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-image-renderer" }, ngImport: i0, template: "@if (src()) {\n <figure>\n <img [src]=\"src()\" [alt]=\"alt()\" [attr.width]=\"width()\" [attr.height]=\"height()\">\n @if (alt()) {\n <figcaption>{{ alt() }}</figcaption>\n }\n </figure>\n}\n", styles: [":host{display:block}:host figure{margin:0}:host img{display:block;max-width:100%;height:auto}:host figcaption{margin-top:calc(var(--spacing, .25rem) * 2);color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));font-size:var(--ngs-font-size-sm);text-align:center}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
3568
3959
|
}
|
|
3569
3960
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorImageRenderer, decorators: [{
|
|
3570
3961
|
type: Component,
|
|
3571
3962
|
args: [{ selector: 'ngs-content-editor-image-renderer', imports: [], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
3572
3963
|
'class': 'ngs-content-editor-image-renderer',
|
|
3573
|
-
}, template: "@if (src()) {\n <figure>\n <img [src]=\"src()\" [alt]=\"alt()\" [attr.width]=\"width()\" [attr.height]=\"height()\">\n @if (alt()) {\n <figcaption>{{ alt() }}</figcaption>\n }\n </figure>\n}\n", styles: [":host{display:block}:host figure{margin:0}:host img{display:block;max-width:100%;height:auto}:host figcaption{margin-top:calc(var(--spacing, .25rem) * 2);color:var(--ngs-color-
|
|
3964
|
+
}, template: "@if (src()) {\n <figure>\n <img [src]=\"src()\" [alt]=\"alt()\" [attr.width]=\"width()\" [attr.height]=\"height()\">\n @if (alt()) {\n <figcaption>{{ alt() }}</figcaption>\n }\n </figure>\n}\n", styles: [":host{display:block}:host figure{margin:0}:host img{display:block;max-width:100%;height:auto}:host figcaption{margin-top:calc(var(--spacing, .25rem) * 2);color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));font-size:var(--ngs-font-size-sm);text-align:center}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3574
3965
|
}], propDecorators: { block: [{ type: i0.Input, args: [{ isSignal: true, alias: "block", required: false }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], settings: [{ type: i0.Input, args: [{ isSignal: true, alias: "settings", required: false }] }], index: [{ type: i0.Input, args: [{ isSignal: true, alias: "index", required: false }] }] } });
|
|
3575
3966
|
|
|
3576
3967
|
class ContentEditorListRenderer {
|
|
@@ -3630,7 +4021,7 @@ class ContentEditorParagraphRenderer {
|
|
|
3630
4021
|
alignment = computed(() => getTextAlignment(this.props()), /* @ts-ignore */
|
|
3631
4022
|
...(ngDevMode ? [{ debugName: "alignment" }] : /* istanbul ignore next */ []));
|
|
3632
4023
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorParagraphRenderer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3633
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.1.7", type: ContentEditorParagraphRenderer, isStandalone: true, selector: "ngs-content-editor-paragraph-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-paragraph-renderer" }, ngImport: i0, template: "<p\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n></p>\n", styles: [":host{display:block}:host .content-html{margin:0;line-height:var(--
|
|
4024
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.1.7", type: ContentEditorParagraphRenderer, isStandalone: true, selector: "ngs-content-editor-paragraph-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-paragraph-renderer" }, ngImport: i0, template: "<p\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n></p>\n", styles: [":host{display:block}:host .content-html{margin:0;line-height:var(--ngs-content-editor-line-height, 1.6)}:host .align-left{text-align:left}:host .align-center{text-align:center}:host .align-right{text-align:right}:host .align-justify{text-align:justify}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "directive", type: NgsHeadlessEditorRuns, selector: "[ngsHeadlessEditorRuns]", inputs: ["ngsHeadlessEditorRuns"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
3634
4025
|
}
|
|
3635
4026
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorParagraphRenderer, decorators: [{
|
|
3636
4027
|
type: Component,
|
|
@@ -3638,7 +4029,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
3638
4029
|
NgsHeadlessEditorRuns,
|
|
3639
4030
|
], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
3640
4031
|
'class': 'ngs-content-editor-paragraph-renderer',
|
|
3641
|
-
}, template: "<p\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n></p>\n", styles: [":host{display:block}:host .content-html{margin:0;line-height:var(--
|
|
4032
|
+
}, template: "<p\n class=\"content-html\"\n [class.align-left]=\"alignment() === 'left'\"\n [class.align-center]=\"alignment() === 'center'\"\n [class.align-right]=\"alignment() === 'right'\"\n [class.align-justify]=\"alignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"runs()\"\n></p>\n", styles: [":host{display:block}:host .content-html{margin:0;line-height:var(--ngs-content-editor-line-height, 1.6)}:host .align-left{text-align:left}:host .align-center{text-align:center}:host .align-right{text-align:right}:host .align-justify{text-align:justify}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3642
4033
|
}], propDecorators: { block: [{ type: i0.Input, args: [{ isSignal: true, alias: "block", required: false }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], settings: [{ type: i0.Input, args: [{ isSignal: true, alias: "settings", required: false }] }], index: [{ type: i0.Input, args: [{ isSignal: true, alias: "index", required: false }] }] } });
|
|
3643
4034
|
|
|
3644
4035
|
class ContentEditorQuoteRenderer {
|
|
@@ -3667,7 +4058,7 @@ class ContentEditorQuoteRenderer {
|
|
|
3667
4058
|
captionAlignment = computed(() => getTextAlignment(this.content()?.caption?.props), /* @ts-ignore */
|
|
3668
4059
|
...(ngDevMode ? [{ debugName: "captionAlignment" }] : /* istanbul ignore next */ []));
|
|
3669
4060
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorQuoteRenderer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3670
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorQuoteRenderer, isStandalone: true, selector: "ngs-content-editor-quote-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-quote-renderer" }, ngImport: i0, template: "<blockquote\n class=\"content-html\"\n [class.align-left]=\"quoteAlignment() === 'left'\"\n [class.align-center]=\"quoteAlignment() === 'center'\"\n [class.align-right]=\"quoteAlignment() === 'right'\"\n [class.align-justify]=\"quoteAlignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"quoteRuns()\"\n></blockquote>\n@if (hasCaption()) {\n <figcaption\n class=\"caption-html\"\n [class.align-left]=\"captionAlignment() === 'left'\"\n [class.align-center]=\"captionAlignment() === 'center'\"\n [class.align-right]=\"captionAlignment() === 'right'\"\n [class.align-justify]=\"captionAlignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"captionRuns()\"\n ></figcaption>\n}\n", styles: [":host{display:block}:host .content-html{border-inline-start:var(--spacing, .25rem) solid var(--ngs-color-border);margin:0 0 calc(var(--spacing, .25rem) * 2);padding:calc(var(--spacing, .25rem) * 2) calc(var(--spacing, .25rem) * 3)}:host .caption-html{color:var(--ngs-color-
|
|
4061
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorQuoteRenderer, isStandalone: true, selector: "ngs-content-editor-quote-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-quote-renderer" }, ngImport: i0, template: "<blockquote\n class=\"content-html\"\n [class.align-left]=\"quoteAlignment() === 'left'\"\n [class.align-center]=\"quoteAlignment() === 'center'\"\n [class.align-right]=\"quoteAlignment() === 'right'\"\n [class.align-justify]=\"quoteAlignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"quoteRuns()\"\n></blockquote>\n@if (hasCaption()) {\n <figcaption\n class=\"caption-html\"\n [class.align-left]=\"captionAlignment() === 'left'\"\n [class.align-center]=\"captionAlignment() === 'center'\"\n [class.align-right]=\"captionAlignment() === 'right'\"\n [class.align-justify]=\"captionAlignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"captionRuns()\"\n ></figcaption>\n}\n", styles: [":host{display:block}:host .content-html{border-inline-start:var(--spacing, .25rem) solid var(--ngs-color-border);margin:0 0 calc(var(--spacing, .25rem) * 2);padding:calc(var(--spacing, .25rem) * 2) calc(var(--spacing, .25rem) * 3)}:host .caption-html{color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));display:block;font-size:var(--ngs-font-size-sm)}:host .align-left{text-align:left}:host .align-center{text-align:center}:host .align-right{text-align:right}:host .align-justify{text-align:justify}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "directive", type: NgsHeadlessEditorRuns, selector: "[ngsHeadlessEditorRuns]", inputs: ["ngsHeadlessEditorRuns"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
3671
4062
|
}
|
|
3672
4063
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorQuoteRenderer, decorators: [{
|
|
3673
4064
|
type: Component,
|
|
@@ -3675,7 +4066,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
3675
4066
|
NgsHeadlessEditorRuns,
|
|
3676
4067
|
], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
3677
4068
|
'class': 'ngs-content-editor-quote-renderer',
|
|
3678
|
-
}, template: "<blockquote\n class=\"content-html\"\n [class.align-left]=\"quoteAlignment() === 'left'\"\n [class.align-center]=\"quoteAlignment() === 'center'\"\n [class.align-right]=\"quoteAlignment() === 'right'\"\n [class.align-justify]=\"quoteAlignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"quoteRuns()\"\n></blockquote>\n@if (hasCaption()) {\n <figcaption\n class=\"caption-html\"\n [class.align-left]=\"captionAlignment() === 'left'\"\n [class.align-center]=\"captionAlignment() === 'center'\"\n [class.align-right]=\"captionAlignment() === 'right'\"\n [class.align-justify]=\"captionAlignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"captionRuns()\"\n ></figcaption>\n}\n", styles: [":host{display:block}:host .content-html{border-inline-start:var(--spacing, .25rem) solid var(--ngs-color-border);margin:0 0 calc(var(--spacing, .25rem) * 2);padding:calc(var(--spacing, .25rem) * 2) calc(var(--spacing, .25rem) * 3)}:host .caption-html{color:var(--ngs-color-
|
|
4069
|
+
}, template: "<blockquote\n class=\"content-html\"\n [class.align-left]=\"quoteAlignment() === 'left'\"\n [class.align-center]=\"quoteAlignment() === 'center'\"\n [class.align-right]=\"quoteAlignment() === 'right'\"\n [class.align-justify]=\"quoteAlignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"quoteRuns()\"\n></blockquote>\n@if (hasCaption()) {\n <figcaption\n class=\"caption-html\"\n [class.align-left]=\"captionAlignment() === 'left'\"\n [class.align-center]=\"captionAlignment() === 'center'\"\n [class.align-right]=\"captionAlignment() === 'right'\"\n [class.align-justify]=\"captionAlignment() === 'justify'\"\n [ngsHeadlessEditorRuns]=\"captionRuns()\"\n ></figcaption>\n}\n", styles: [":host{display:block}:host .content-html{border-inline-start:var(--spacing, .25rem) solid var(--ngs-color-border);margin:0 0 calc(var(--spacing, .25rem) * 2);padding:calc(var(--spacing, .25rem) * 2) calc(var(--spacing, .25rem) * 3)}:host .caption-html{color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));display:block;font-size:var(--ngs-font-size-sm)}:host .align-left{text-align:left}:host .align-center{text-align:center}:host .align-right{text-align:right}:host .align-justify{text-align:justify}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3679
4070
|
}], propDecorators: { block: [{ type: i0.Input, args: [{ isSignal: true, alias: "block", required: false }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], settings: [{ type: i0.Input, args: [{ isSignal: true, alias: "settings", required: false }] }], index: [{ type: i0.Input, args: [{ isSignal: true, alias: "index", required: false }] }] } });
|
|
3680
4071
|
|
|
3681
4072
|
class ContentEditorTableRenderer {
|
|
@@ -3745,13 +4136,13 @@ class ContentEditorVideoRenderer {
|
|
|
3745
4136
|
height = computed(() => getDimensionAttribute(this.settings()?.height), /* @ts-ignore */
|
|
3746
4137
|
...(ngDevMode ? [{ debugName: "height" }] : /* istanbul ignore next */ []));
|
|
3747
4138
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorVideoRenderer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3748
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorVideoRenderer, isStandalone: true, selector: "ngs-content-editor-video-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-video-renderer" }, ngImport: i0, template: "@if (src()) {\n <figure>\n <video\n [src]=\"src()\"\n [attr.width]=\"width()\"\n [attr.height]=\"height()\"\n controls\n ></video>\n @if (caption()) {\n <figcaption>{{ caption() }}</figcaption>\n }\n </figure>\n}\n", styles: [":host{display:block}:host figure{margin:0}:host video{display:block;max-width:100%;height:auto}:host figcaption{margin-top:calc(var(--spacing, .25rem) * 2);color:var(--ngs-color-
|
|
4139
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorVideoRenderer, isStandalone: true, selector: "ngs-content-editor-video-renderer", inputs: { block: { classPropertyName: "block", publicName: "block", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: false, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-video-renderer" }, ngImport: i0, template: "@if (src()) {\n <figure>\n <video\n [src]=\"src()\"\n [attr.width]=\"width()\"\n [attr.height]=\"height()\"\n controls\n ></video>\n @if (caption()) {\n <figcaption>{{ caption() }}</figcaption>\n }\n </figure>\n}\n", styles: [":host{display:block}:host figure{margin:0}:host video{display:block;max-width:100%;height:auto}:host figcaption{margin-top:calc(var(--spacing, .25rem) * 2);color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));font-size:var(--ngs-font-size-sm);text-align:center}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
3749
4140
|
}
|
|
3750
4141
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorVideoRenderer, decorators: [{
|
|
3751
4142
|
type: Component,
|
|
3752
4143
|
args: [{ selector: 'ngs-content-editor-video-renderer', imports: [], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
3753
4144
|
'class': 'ngs-content-editor-video-renderer',
|
|
3754
|
-
}, template: "@if (src()) {\n <figure>\n <video\n [src]=\"src()\"\n [attr.width]=\"width()\"\n [attr.height]=\"height()\"\n controls\n ></video>\n @if (caption()) {\n <figcaption>{{ caption() }}</figcaption>\n }\n </figure>\n}\n", styles: [":host{display:block}:host figure{margin:0}:host video{display:block;max-width:100%;height:auto}:host figcaption{margin-top:calc(var(--spacing, .25rem) * 2);color:var(--ngs-color-
|
|
4145
|
+
}, template: "@if (src()) {\n <figure>\n <video\n [src]=\"src()\"\n [attr.width]=\"width()\"\n [attr.height]=\"height()\"\n controls\n ></video>\n @if (caption()) {\n <figcaption>{{ caption() }}</figcaption>\n }\n </figure>\n}\n", styles: [":host{display:block}:host figure{margin:0}:host video{display:block;max-width:100%;height:auto}:host figcaption{margin-top:calc(var(--spacing, .25rem) * 2);color:var(--ngs-content-editor-muted-color, var(--ngs-color-on-surface-variant));font-size:var(--ngs-font-size-sm);text-align:center}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3755
4146
|
}], propDecorators: { block: [{ type: i0.Input, args: [{ isSignal: true, alias: "block", required: false }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], settings: [{ type: i0.Input, args: [{ isSignal: true, alias: "settings", required: false }] }], index: [{ type: i0.Input, args: [{ isSignal: true, alias: "index", required: false }] }] } });
|
|
3756
4147
|
|
|
3757
4148
|
const CONTENT_EDITOR_DEFAULT_RENDERERS = [
|
|
@@ -3807,6 +4198,10 @@ const CONTENT_EDITOR_DEFAULT_RENDERERS = [
|
|
|
3807
4198
|
];
|
|
3808
4199
|
|
|
3809
4200
|
class ContentEditorRenderer {
|
|
4201
|
+
globalConfig = inject(CONTENT_EDITOR_CONFIG);
|
|
4202
|
+
parentConfig = inject(CONTENT_EDITOR_RENDER_CONFIG, { skipSelf: true, optional: true });
|
|
4203
|
+
resolvedConfig = computed(() => mergeContentEditorConfig(this.globalConfig, this.parentConfig?.() ?? {}, this.config()), /* @ts-ignore */
|
|
4204
|
+
...(ngDevMode ? [{ debugName: "resolvedConfig" }] : /* istanbul ignore next */ []));
|
|
3810
4205
|
htmlSerializer = inject(ContentEditorHtmlSerializer);
|
|
3811
4206
|
config = input({}, /* @ts-ignore */
|
|
3812
4207
|
...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
|
|
@@ -3818,12 +4213,13 @@ class ContentEditorRenderer {
|
|
|
3818
4213
|
blocks = input(null, /* @ts-ignore */
|
|
3819
4214
|
...(ngDevMode ? [{ debugName: "blocks" }] : /* istanbul ignore next */ []));
|
|
3820
4215
|
toHtml(config = {}) {
|
|
3821
|
-
return this.htmlSerializer.toHtml({ version: 1, blocks: this.blocks() ?? this.content().blocks }, mergeContentEditorConfig(this.
|
|
4216
|
+
return this.htmlSerializer.toHtml({ version: 1, blocks: this.blocks() ?? this.content().blocks }, mergeContentEditorConfig(this.resolvedConfig(), config));
|
|
3822
4217
|
}
|
|
3823
4218
|
rendererMap = computed(() => {
|
|
3824
4219
|
const renderers = [
|
|
3825
4220
|
...CONTENT_EDITOR_DEFAULT_RENDERERS,
|
|
3826
4221
|
...this.providedRendererGroups.flat(),
|
|
4222
|
+
...Object.entries(this.resolvedConfig().blocks ?? {}).flatMap(([type, block]) => block.renderer ? [{ type, component: block.renderer }] : []),
|
|
3827
4223
|
];
|
|
3828
4224
|
return new Map(renderers.map(renderer => [renderer.type, renderer.component]));
|
|
3829
4225
|
}, /* @ts-ignore */
|
|
@@ -3850,20 +4246,192 @@ class ContentEditorRenderer {
|
|
|
3850
4246
|
}, /* @ts-ignore */
|
|
3851
4247
|
...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
3852
4248
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorRenderer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3853
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorRenderer, isStandalone: true, selector: "ngs-content-editor-renderer", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, blocks: { classPropertyName: "blocks", publicName: "blocks", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-renderer prose max-w-full" }, providers: [provideContentEditor(), ContentEditorHtmlSerializer
|
|
4249
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: ContentEditorRenderer, isStandalone: true, selector: "ngs-content-editor-renderer", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: false, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, blocks: { classPropertyName: "blocks", publicName: "blocks", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "ngs-content-editor-renderer prose max-w-full" }, providers: [provideContentEditor(), ContentEditorHtmlSerializer, {
|
|
4250
|
+
provide: CONTENT_EDITOR_RENDER_CONFIG, useFactory: () => inject(forwardRef(() => ContentEditorRenderer)).resolvedConfig
|
|
4251
|
+
}], exportAs: ["ngsContentEditorRenderer"], ngImport: i0, template: "@for (item of items(); track item.block.id || $index) {\n @if (item.component) {\n <div class=\"block\" [attr.data-block-id]=\"item.block.id\" [attr.data-block-type]=\"item.block.type\">\n <ng-container\n [ngComponentOutlet]=\"item.component\"\n [ngComponentOutletInputs]=\"item.inputs\"\n />\n </div>\n }\n}\n", styles: [":host{--ngs-content-editor-renderer-block-gap: calc(var(--spacing, .25rem) * 4);font-size:var(--ngs-content-editor-font-size, var(--ngs-font-size-md));line-height:var(--ngs-content-editor-line-height, 1.6);display:flex;flex-direction:column;gap:var(--ngs-content-editor-renderer-block-gap)}:host .block{min-width:0}:host ::ng-deep a[data-ngs-headless-editor-mark=link]{color:var(--ngs-color-primary);text-decoration:underline;text-underline-offset:.15em}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
3854
4252
|
}
|
|
3855
4253
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorRenderer, decorators: [{
|
|
3856
4254
|
type: Component,
|
|
3857
|
-
args: [{ selector: 'ngs-content-editor-renderer', exportAs: 'ngsContentEditorRenderer', providers: [provideContentEditor(), ContentEditorHtmlSerializer
|
|
4255
|
+
args: [{ selector: 'ngs-content-editor-renderer', exportAs: 'ngsContentEditorRenderer', providers: [provideContentEditor(), ContentEditorHtmlSerializer, {
|
|
4256
|
+
provide: CONTENT_EDITOR_RENDER_CONFIG, useFactory: () => inject(forwardRef(() => ContentEditorRenderer)).resolvedConfig
|
|
4257
|
+
}], imports: [
|
|
3858
4258
|
NgComponentOutlet,
|
|
3859
4259
|
], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
3860
4260
|
'class': 'ngs-content-editor-renderer prose max-w-full',
|
|
3861
|
-
}, template: "@for (item of items(); track item.block.id || $index) {\n @if (item.component) {\n <div class=\"block\" [attr.data-block-id]=\"item.block.id\" [attr.data-block-type]=\"item.block.type\">\n <ng-container\n [ngComponentOutlet]=\"item.component\"\n [ngComponentOutletInputs]=\"item.inputs\"\n />\n </div>\n }\n}\n", styles: [":host{--ngs-content-editor-renderer-block-gap: calc(var(--spacing, .25rem) * 4);display:flex;flex-direction:column;gap:var(--ngs-content-editor-renderer-block-gap)}:host .block{min-width:0}:host ::ng-deep a[data-ngs-headless-editor-mark=link]{color:var(--ngs-color-primary);text-decoration:underline;text-underline-offset:.15em}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
4261
|
+
}, template: "@for (item of items(); track item.block.id || $index) {\n @if (item.component) {\n <div class=\"block\" [attr.data-block-id]=\"item.block.id\" [attr.data-block-type]=\"item.block.type\">\n <ng-container\n [ngComponentOutlet]=\"item.component\"\n [ngComponentOutletInputs]=\"item.inputs\"\n />\n </div>\n }\n}\n", styles: [":host{--ngs-content-editor-renderer-block-gap: calc(var(--spacing, .25rem) * 4);font-size:var(--ngs-content-editor-font-size, var(--ngs-font-size-md));line-height:var(--ngs-content-editor-line-height, 1.6);display:flex;flex-direction:column;gap:var(--ngs-content-editor-renderer-block-gap)}:host .block{min-width:0}:host ::ng-deep a[data-ngs-headless-editor-mark=link]{color:var(--ngs-color-primary);text-decoration:underline;text-underline-offset:.15em}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
3862
4262
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: false }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], blocks: [{ type: i0.Input, args: [{ isSignal: true, alias: "blocks", required: false }] }] } });
|
|
3863
4263
|
|
|
4264
|
+
/** One cancellable request per block. Retry only sends failed files again. */
|
|
4265
|
+
class ContentEditorUploadTask {
|
|
4266
|
+
writable;
|
|
4267
|
+
uploading = signal(false, /* @ts-ignore */
|
|
4268
|
+
...(ngDevMode ? [{ debugName: "uploading" }] : /* istanbul ignore next */ []));
|
|
4269
|
+
progress = signal(null, /* @ts-ignore */
|
|
4270
|
+
...(ngDevMode ? [{ debugName: "progress" }] : /* istanbul ignore next */ []));
|
|
4271
|
+
error = signal('', /* @ts-ignore */
|
|
4272
|
+
...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
4273
|
+
canRetry = signal(false, /* @ts-ignore */
|
|
4274
|
+
...(ngDevMode ? [{ debugName: "canRetry" }] : /* istanbul ignore next */ []));
|
|
4275
|
+
controller = null;
|
|
4276
|
+
failed = null;
|
|
4277
|
+
constructor(writable) {
|
|
4278
|
+
this.writable = writable;
|
|
4279
|
+
}
|
|
4280
|
+
cancel() {
|
|
4281
|
+
this.controller?.abort();
|
|
4282
|
+
this.controller = null;
|
|
4283
|
+
this.uploading.set(false);
|
|
4284
|
+
this.progress.set(null);
|
|
4285
|
+
this.failed = null;
|
|
4286
|
+
this.canRetry.set(false);
|
|
4287
|
+
this.error.set('');
|
|
4288
|
+
}
|
|
4289
|
+
retry() { return this.failed ? this.run(this.failed) : Promise.resolve(); }
|
|
4290
|
+
async run(request) {
|
|
4291
|
+
this.cancel();
|
|
4292
|
+
if (!request.files.length || !this.writable())
|
|
4293
|
+
return;
|
|
4294
|
+
const controller = new AbortController();
|
|
4295
|
+
this.controller = controller;
|
|
4296
|
+
const active = () => this.controller === controller && !controller.signal.aborted && this.writable();
|
|
4297
|
+
this.uploading.set(true);
|
|
4298
|
+
const progress = request.files.map(() => null);
|
|
4299
|
+
const report = (index, percent) => {
|
|
4300
|
+
if (!active())
|
|
4301
|
+
return;
|
|
4302
|
+
progress[index] = percent;
|
|
4303
|
+
this.progress.set(progress.every(value => value !== null) ? progress.reduce((sum, value) => sum + (value ?? 0), 0) / progress.length : null);
|
|
4304
|
+
};
|
|
4305
|
+
const results = await Promise.allSettled(request.files.map(async (file, index) => {
|
|
4306
|
+
if (request.accept && !request.accept(file))
|
|
4307
|
+
throw new Error(`Unsupported file: ${file.name}`);
|
|
4308
|
+
if (request.maxFileSize !== undefined && file.size > request.maxFileSize)
|
|
4309
|
+
throw new Error(`File is too large: ${file.name}`);
|
|
4310
|
+
const dataUrl = await readContentEditorFile(file, { signal: controller.signal, onProgress: value => report(index, value * 0.2) });
|
|
4311
|
+
if (!active())
|
|
4312
|
+
throw new DOMException('Upload cancelled', 'AbortError');
|
|
4313
|
+
report(index, null);
|
|
4314
|
+
const url = await abortable(request.upload(file, dataUrl, { signal: controller.signal, onProgress: value => {
|
|
4315
|
+
if (Number.isFinite(value))
|
|
4316
|
+
report(index, 20 + Math.max(0, Math.min(100, value)) * 0.8);
|
|
4317
|
+
} }), controller.signal);
|
|
4318
|
+
if (!active())
|
|
4319
|
+
throw new DOMException('Upload cancelled', 'AbortError');
|
|
4320
|
+
if (typeof url !== 'string' || !safeContentEditorHtmlUrl(url, request.urlKind ?? 'attachment'))
|
|
4321
|
+
throw new Error(`Invalid upload URL: ${file.name}`);
|
|
4322
|
+
report(index, 100);
|
|
4323
|
+
return { file, url, dataUrl };
|
|
4324
|
+
}));
|
|
4325
|
+
if (this.controller !== controller || controller.signal.aborted)
|
|
4326
|
+
return;
|
|
4327
|
+
if (!this.writable()) {
|
|
4328
|
+
this.cancel();
|
|
4329
|
+
return;
|
|
4330
|
+
}
|
|
4331
|
+
const succeeded = results.flatMap(result => result.status === 'fulfilled' ? [result.value] : []);
|
|
4332
|
+
const failed = request.files.filter((_, index) => results[index].status === 'rejected');
|
|
4333
|
+
try {
|
|
4334
|
+
if (succeeded.length)
|
|
4335
|
+
request.apply(succeeded);
|
|
4336
|
+
}
|
|
4337
|
+
catch (error) {
|
|
4338
|
+
this.error.set(error instanceof Error ? error.message : 'Could not save uploaded files.');
|
|
4339
|
+
this.failed = null;
|
|
4340
|
+
this.canRetry.set(false);
|
|
4341
|
+
this.uploading.set(false);
|
|
4342
|
+
return;
|
|
4343
|
+
}
|
|
4344
|
+
if (failed.length) {
|
|
4345
|
+
const reason = results.find(result => result.status === 'rejected');
|
|
4346
|
+
this.error.set(`Could not upload ${failed.length} file(s): ${reason.reason instanceof Error ? reason.reason.message : 'Upload failed'}`);
|
|
4347
|
+
const retryable = failed.filter(file => (!request.accept || request.accept(file)) && (request.maxFileSize === undefined || file.size <= request.maxFileSize));
|
|
4348
|
+
this.failed = retryable.length ? { ...request, files: retryable } : null;
|
|
4349
|
+
this.canRetry.set(!!this.failed);
|
|
4350
|
+
}
|
|
4351
|
+
this.uploading.set(false);
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
function abortable(work, signal) {
|
|
4355
|
+
return new Promise((resolve, reject) => {
|
|
4356
|
+
const abort = () => reject(new DOMException('Upload cancelled', 'AbortError'));
|
|
4357
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
4358
|
+
work.then(value => { signal.removeEventListener('abort', abort); resolve(value); }, error => { signal.removeEventListener('abort', abort); reject(error); });
|
|
4359
|
+
if (signal.aborted)
|
|
4360
|
+
abort();
|
|
4361
|
+
});
|
|
4362
|
+
}
|
|
4363
|
+
|
|
4364
|
+
/** Shared native inputs and root history for the built-in block editors. */
|
|
4365
|
+
class ContentEditorBlockBase {
|
|
4366
|
+
store = inject(ContentBuilderStore);
|
|
4367
|
+
builder = inject(CONTENT_BUILDER);
|
|
4368
|
+
element = inject(ElementRef).nativeElement;
|
|
4369
|
+
id = input.required(/* @ts-ignore */
|
|
4370
|
+
...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
4371
|
+
content = input.required(/* @ts-ignore */
|
|
4372
|
+
...(ngDevMode ? [{ debugName: "content" }] : /* istanbul ignore next */ []));
|
|
4373
|
+
settings = input.required(/* @ts-ignore */
|
|
4374
|
+
...(ngDevMode ? [{ debugName: "settings" }] : /* istanbul ignore next */ []));
|
|
4375
|
+
index = input(0, /* @ts-ignore */
|
|
4376
|
+
...(ngDevMode ? [{ debugName: "index" }] : /* istanbul ignore next */ []));
|
|
4377
|
+
props = input([], /* @ts-ignore */
|
|
4378
|
+
...(ngDevMode ? [{ debugName: "props" }] : /* istanbul ignore next */ []));
|
|
4379
|
+
initialized = signal(true, /* @ts-ignore */
|
|
4380
|
+
...(ngDevMode ? [{ debugName: "initialized" }] : /* istanbul ignore next */ []));
|
|
4381
|
+
constructor() {
|
|
4382
|
+
effect(() => {
|
|
4383
|
+
if (this.store.focusedBlockId() === this.id())
|
|
4384
|
+
untracked(() => this.focus());
|
|
4385
|
+
});
|
|
4386
|
+
}
|
|
4387
|
+
focus() { this.element.querySelector('[contenteditable="true"], input, button')?.focus(); }
|
|
4388
|
+
getData() { return { content: this.content(), settings: this.settings(), props: this.props() }; }
|
|
4389
|
+
isEmpty() {
|
|
4390
|
+
const block = findContentEditorBlock(this.store.editor.document().blocks, this.id());
|
|
4391
|
+
return !block || isContentEditorBlockEmpty(block);
|
|
4392
|
+
}
|
|
4393
|
+
save(content, settings = this.settings()) { this.store.updateBlock(this.id(), { content, settings }); }
|
|
4394
|
+
latestContent() {
|
|
4395
|
+
const block = findContentEditorBlock(this.store.editor.document().blocks, this.id());
|
|
4396
|
+
return block ? contentEditorBlockView(block).content : this.content();
|
|
4397
|
+
}
|
|
4398
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorBlockBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
4399
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.7", type: ContentEditorBlockBase, isStandalone: true, inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: true, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: true, transformFunction: null }, settings: { classPropertyName: "settings", publicName: "settings", isSignal: true, isRequired: true, transformFunction: null }, index: { classPropertyName: "index", publicName: "index", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
|
|
4400
|
+
}
|
|
4401
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorBlockBase, decorators: [{
|
|
4402
|
+
type: Directive
|
|
4403
|
+
}], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: true }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: true }] }], settings: [{ type: i0.Input, args: [{ isSignal: true, alias: "settings", required: true }] }], index: [{ type: i0.Input, args: [{ isSignal: true, alias: "index", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }] } });
|
|
4404
|
+
|
|
4405
|
+
class ContentEditorUploadBlockBase extends ContentEditorBlockBase {
|
|
4406
|
+
uploadTask = new ContentEditorUploadTask(() => !this.store.editor.readOnly() && !!findContentEditorBlock(this.store.editor.document().blocks, this.id()));
|
|
4407
|
+
uploading = this.uploadTask.uploading;
|
|
4408
|
+
error = this.uploadTask.error;
|
|
4409
|
+
constructor() {
|
|
4410
|
+
super();
|
|
4411
|
+
effect(() => {
|
|
4412
|
+
if (this.store.editor.readOnly() || !findContentEditorBlock(this.store.editor.document().blocks, this.id()))
|
|
4413
|
+
this.uploadTask.cancel();
|
|
4414
|
+
});
|
|
4415
|
+
inject(DestroyRef).onDestroy(() => this.uploadTask.cancel());
|
|
4416
|
+
}
|
|
4417
|
+
uploadFiles(type, request) {
|
|
4418
|
+
return this.uploadTask.run({ ...request,
|
|
4419
|
+
urlKind: request.urlKind ?? (type === 'video' ? 'media' : type === 'image' || type === 'gallery' ? 'image' : 'attachment'),
|
|
4420
|
+
upload: this.builder.getBlockDefOption(type, 'uploadFn'),
|
|
4421
|
+
maxFileSize: this.builder.getBlockDefOption(type, 'maxFileSize')
|
|
4422
|
+
});
|
|
4423
|
+
}
|
|
4424
|
+
cancelUpload() { this.uploadTask.cancel(); }
|
|
4425
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorUploadBlockBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
4426
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.7", type: ContentEditorUploadBlockBase, isStandalone: true, usesInheritance: true, ngImport: i0 });
|
|
4427
|
+
}
|
|
4428
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ContentEditorUploadBlockBase, decorators: [{
|
|
4429
|
+
type: Directive
|
|
4430
|
+
}], ctorParameters: () => [] });
|
|
4431
|
+
|
|
3864
4432
|
/**
|
|
3865
4433
|
* Generated bundle index. Do not edit.
|
|
3866
4434
|
*/
|
|
3867
4435
|
|
|
3868
|
-
export {
|
|
3869
|
-
//# sourceMappingURL=ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-
|
|
4436
|
+
export { contentEditorBlockToHtml as $, ContentEditorAttachmentRenderer as A, BlockSelectionDirective as B, ContentBuilderStore as C, ContentEditorCalloutRenderer as D, ContentEditorCodeRenderer as E, ContentEditorDividerRenderer as F, ContentEditorDraftController as G, ContentEditorEmbedRenderer as H, ContentEditorGalleryRenderer as I, ContentEditorGridRenderer as J, ContentEditorHeadingRenderer as K, ContentEditorHtmlSerializer as L, ContentEditorImageRenderer as M, ContentEditorImportError as N, ContentEditorImporter as O, ContentEditorListRenderer as P, ContentEditorParagraphRenderer as Q, ContentEditorQuoteRenderer as R, ContentEditorRenderer as S, ContentEditorRendererBase as T, ContentEditorTableRenderer as U, ContentEditorToggleRenderer as V, ContentEditorUploadTask as W, ContentEditorVideoRenderer as X, TextSelectionPopupDirective as Y, contentEditorAttachmentToHtml as Z, contentEditorBlockScope as _, CONTENT_BUILDER as a, contentEditorCalloutToHtml as a0, contentEditorCodeToHtml as a1, contentEditorConvertBlock as a2, contentEditorCopyBlocks as a3, contentEditorDividerToHtml as a4, contentEditorEmbedToHtml as a5, contentEditorFromHtml as a6, contentEditorFromJson as a7, contentEditorGalleryToHtml as a8, contentEditorGridToHtml as a9, contentEditorHeadingToHtml as aa, contentEditorImageToHtml as ab, contentEditorListToHtml as ac, contentEditorNativeBlock as ad, contentEditorParagraphToHtml as ae, contentEditorQuoteToHtml as af, contentEditorSliceText as ag, contentEditorTableToHtml as ah, contentEditorToHtml as ai, contentEditorToggleToHtml as aj, contentEditorVideoToHtml as ak, isContentEditorBlockEmpty as al, mergeContentEditorConfig as am, provideContentEditor as an, provideContentEditorConfig as ao, provideContentEditorRenderer as ap, provideContentEditorRenderers as aq, readContentEditorFile as ar, replaceContentEditorCollection as as, contentEditorText as b, cloneContentEditorValue as c, ContentEditorContentEditableDirective as d, CONTENT_EDITOR_BLOCK as e, ContentEditorUploadBlockBase as f, ContentEditorBlockBase as g, contentEditorFileSize as h, contentEditorResourceUrl as i, contentEditorGridSettings as j, findContentEditorBlock as k, emptyGridCell as l, contentEditorCollection as m, contentEditorBlockView as n, contentEditorChildCollections as o, CONTENT_EDITOR_BLOCK_RENDERERS as p, CONTENT_EDITOR_CALLOUT_HTML_STYLES as q, CONTENT_EDITOR_CONFIG as r, CONTENT_EDITOR_CONVERTIBLE_BLOCKS as s, CONTENT_EDITOR_DEFAULT_HTML_CONVERTERS as t, CONTENT_EDITOR_DEFAULT_RENDERERS as u, CONTENT_EDITOR_GALLERY_HTML_STYLES as v, CONTENT_EDITOR_GRID_HTML_STYLES as w, CONTENT_EDITOR_RENDER_CONFIG as x, CommandBarComponent as y, ContentBuilderComponent as z };
|
|
4437
|
+
//# sourceMappingURL=ngstarter-ui-components-content-editor-ngstarter-ui-components-content-editor-dGibIV4n.mjs.map
|