@ecodev/natural-editor 41.3.0 → 42.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/{esm2015/ecodev-natural-editor.js → esm2020/ecodev-natural-editor.mjs} +0 -0
  2. package/esm2020/lib/class-dialog/class-dialog.component.mjs +37 -0
  3. package/esm2020/lib/color-dialog/color-dialog.component.mjs +184 -0
  4. package/esm2020/lib/custom-css/custom-css.directive.mjs +71 -0
  5. package/esm2020/lib/editor/editor.component.mjs +213 -0
  6. package/esm2020/lib/editor.module.mjs +90 -0
  7. package/{esm2015/lib/link-dialog/link-dialog.component.js → esm2020/lib/link-dialog/link-dialog.component.mjs} +5 -8
  8. package/esm2020/lib/utils/image.mjs +81 -0
  9. package/{esm2015/lib/utils/inputrules.js → esm2020/lib/utils/inputrules.mjs} +0 -0
  10. package/esm2020/lib/utils/items/cell-background-color-item.mjs +55 -0
  11. package/esm2020/lib/utils/items/class-item.mjs +86 -0
  12. package/esm2020/lib/utils/items/horizontal-rule-item.mjs +24 -0
  13. package/esm2020/lib/utils/items/item.mjs +39 -0
  14. package/esm2020/lib/utils/items/link-item.mjs +40 -0
  15. package/esm2020/lib/utils/items/table-item.mjs +43 -0
  16. package/esm2020/lib/utils/items/text-align-item.mjs +78 -0
  17. package/esm2020/lib/utils/items/utils.mjs +41 -0
  18. package/esm2020/lib/utils/items/wrap-list-item.mjs +6 -0
  19. package/esm2020/lib/utils/keymap.mjs +115 -0
  20. package/esm2020/lib/utils/menu.mjs +101 -0
  21. package/esm2020/lib/utils/schema/paragraph-with-alignment.mjs +50 -0
  22. package/esm2020/lib/utils/schema/schema.mjs +51 -0
  23. package/esm2020/lib/utils/schema/table.mjs +113 -0
  24. package/esm2020/public-api.mjs +9 -0
  25. package/fesm2015/ecodev-natural-editor.mjs +1548 -0
  26. package/fesm2015/ecodev-natural-editor.mjs.map +1 -0
  27. package/fesm2020/ecodev-natural-editor.mjs +1546 -0
  28. package/fesm2020/ecodev-natural-editor.mjs.map +1 -0
  29. package/lib/class-dialog/class-dialog.component.d.ts +24 -0
  30. package/lib/color-dialog/color-dialog.component.d.ts +26 -0
  31. package/lib/custom-css/custom-css.directive.d.ts +29 -0
  32. package/lib/editor.module.d.ts +19 -16
  33. package/lib/utils/items/cell-background-color-item.d.ts +5 -0
  34. package/lib/utils/items/class-item.d.ts +6 -0
  35. package/lib/utils/items/horizontal-rule-item.d.ts +5 -0
  36. package/lib/utils/{item.d.ts → items/item.d.ts} +0 -0
  37. package/lib/utils/items/link-item.d.ts +6 -0
  38. package/lib/utils/items/table-item.d.ts +4 -0
  39. package/lib/utils/{text-align-item.d.ts → items/text-align-item.d.ts} +0 -0
  40. package/lib/utils/items/utils.d.ts +18 -0
  41. package/lib/utils/items/wrap-list-item.d.ts +3 -0
  42. package/lib/utils/menu.d.ts +2 -2
  43. package/lib/utils/schema/paragraph-with-alignment.d.ts +8 -0
  44. package/lib/utils/{schema.d.ts → schema/schema.d.ts} +0 -0
  45. package/lib/utils/schema/table.d.ts +9 -0
  46. package/package.json +22 -8
  47. package/public-api.d.ts +1 -0
  48. package/src/lib/editor/_editor.theme.scss +1 -1
  49. package/theming/_natural-editor.theme.scss +1 -1
  50. package/bundles/ecodev-natural-editor.umd.js +0 -1351
  51. package/bundles/ecodev-natural-editor.umd.js.map +0 -1
  52. package/esm2015/lib/editor/editor.component.js +0 -219
  53. package/esm2015/lib/editor.module.js +0 -82
  54. package/esm2015/lib/utils/image.js +0 -81
  55. package/esm2015/lib/utils/item.js +0 -39
  56. package/esm2015/lib/utils/keymap.js +0 -115
  57. package/esm2015/lib/utils/menu.js +0 -178
  58. package/esm2015/lib/utils/paragraph-with-alignment.js +0 -43
  59. package/esm2015/lib/utils/schema.js +0 -47
  60. package/esm2015/lib/utils/table.js +0 -37
  61. package/esm2015/lib/utils/text-align-item.js +0 -78
  62. package/esm2015/public-api.js +0 -8
  63. package/fesm2015/ecodev-natural-editor.js +0 -997
  64. package/fesm2015/ecodev-natural-editor.js.map +0 -1
  65. package/lib/utils/paragraph-with-alignment.d.ts +0 -2
  66. package/lib/utils/table.d.ts +0 -8
@@ -0,0 +1,1546 @@
1
+ import '@angular/localize/init';
2
+ import * as i0 from '@angular/core';
3
+ import { Directive, Inject, HostBinding, Input, Injectable, Component, EventEmitter, ElementRef, Optional, Self, ViewChild, Output, NgModule } from '@angular/core';
4
+ import * as i6 from '@angular/common';
5
+ import { DOCUMENT, CommonModule } from '@angular/common';
6
+ import { DecorationSet, Decoration, EditorView } from 'prosemirror-view';
7
+ import { Plugin, TextSelection, AllSelection, EditorState } from 'prosemirror-state';
8
+ import { Schema, DOMSerializer, DOMParser } from 'prosemirror-model';
9
+ import { setCellAttr, isInTable, selectionCell, CellSelection, tableNodeTypes, addColumnBefore, addColumnAfter, deleteColumn, addRowBefore, addRowAfter, deleteRow, deleteTable, mergeCells, splitCell, toggleHeaderColumn, toggleHeaderRow, toggleHeaderCell, tableEditing, goToNextCell } from 'prosemirror-tables';
10
+ import { keymap } from 'prosemirror-keymap';
11
+ import { nodes, marks } from 'prosemirror-schema-basic';
12
+ import { addListNodes, wrapInList, splitListItem, liftListItem, sinkListItem } from 'prosemirror-schema-list';
13
+ import { joinUpItem, liftItem, selectParentNodeItem, undoItem, redoItem, wrapItem, blockTypeItem } from 'prosemirror-menu';
14
+ import * as i1 from '@angular/material/dialog';
15
+ import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
16
+ import * as i4 from '@angular/forms';
17
+ import { FormControl, Validators, FormGroup, ReactiveFormsModule } from '@angular/forms';
18
+ import * as i3$1 from '@ecodev/natural';
19
+ import { ifValid, NaturalFileModule, NaturalIconModule } from '@ecodev/natural';
20
+ import * as i3 from '@angular/material/button';
21
+ import { MatButtonModule } from '@angular/material/button';
22
+ import * as i2 from '@angular/material/form-field';
23
+ import { MatFormFieldModule } from '@angular/material/form-field';
24
+ import * as i5 from '@angular/material/input';
25
+ import { MatInputModule } from '@angular/material/input';
26
+ import { toggleMark, joinUp, joinDown, lift, selectParentNode, wrapIn, chainCommands, exitCode, setBlockType, baseKeymap } from 'prosemirror-commands';
27
+ import { undo, redo, history } from 'prosemirror-history';
28
+ import { dropCursor } from 'prosemirror-dropcursor';
29
+ import { gapCursor } from 'prosemirror-gapcursor';
30
+ import { wrappingInputRule, textblockTypeInputRule, ellipsis, emDash, inputRules, undoInputRule } from 'prosemirror-inputrules';
31
+ import * as i5$1 from '@angular/material/icon';
32
+ import { MatIconModule } from '@angular/material/icon';
33
+ import * as i6$1 from '@angular/material/button-toggle';
34
+ import { MatButtonToggleModule } from '@angular/material/button-toggle';
35
+ import * as i7 from '@angular/material/menu';
36
+ import { MatMenuModule } from '@angular/material/menu';
37
+ import * as i8 from '@angular/material/divider';
38
+ import { MatDividerModule } from '@angular/material/divider';
39
+ import * as i10 from '@angular/material/tooltip';
40
+ import { MatTooltipModule } from '@angular/material/tooltip';
41
+ import { MatToolbarModule } from '@angular/material/toolbar';
42
+
43
+ /**
44
+ * Prefix all CSS selectors with the given selector
45
+ *
46
+ * This is meant to be relatively simple and might not cover advanced CSS syntax
47
+ */
48
+ function prefixCss(prefix, css) {
49
+ prefix = '\n' + prefix + ' ';
50
+ return css
51
+ .replace(/([^{}]*){/gs, selectors => selectors
52
+ .split(',')
53
+ .map(selector => prefix + selector.trim())
54
+ .join(','))
55
+ .trim();
56
+ }
57
+ let uniqueId = 0;
58
+ let componentCount = 0;
59
+ /**
60
+ * Inject custom CSS into component and scope the CSS only to this component
61
+ *
62
+ * Usage :
63
+ *
64
+ * ```html
65
+ * <div [naturalCustomCss]=".my-class {background: red}">
66
+ * <p class="my-class">foo bar</p>
67
+ * </div>
68
+ * ```
69
+ */
70
+ class NaturalCustomCssDirective {
71
+ constructor(document) {
72
+ this.document = document;
73
+ this.style = null;
74
+ this.id = 'n' + ++uniqueId;
75
+ }
76
+ set naturalCustomCss(value) {
77
+ if (value && !this.style) {
78
+ this.style = this.document.createElement('style');
79
+ this.document.head.appendChild(this.style);
80
+ }
81
+ if (this.style) {
82
+ this.style.innerHTML = value ? prefixCss(`[data-natural-id=${this.id}]`, value) : '';
83
+ }
84
+ }
85
+ ngOnDestroy() {
86
+ this.style?.remove();
87
+ // Reset uniqueId if we have no component alive anymore, so that we never reach max int
88
+ componentCount--;
89
+ if (componentCount <= 0) {
90
+ uniqueId = 0;
91
+ }
92
+ }
93
+ }
94
+ NaturalCustomCssDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalCustomCssDirective, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Directive });
95
+ NaturalCustomCssDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.0", type: NaturalCustomCssDirective, selector: "[naturalCustomCss]", inputs: { naturalCustomCss: "naturalCustomCss" }, host: { properties: { "attr.data-natural-id": "this.id" } }, ngImport: i0 });
96
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalCustomCssDirective, decorators: [{
97
+ type: Directive,
98
+ args: [{
99
+ selector: '[naturalCustomCss]',
100
+ }]
101
+ }], ctorParameters: function () { return [{ type: Document, decorators: [{
102
+ type: Inject,
103
+ args: [DOCUMENT]
104
+ }] }]; }, propDecorators: { id: [{
105
+ type: HostBinding,
106
+ args: ['attr.data-natural-id']
107
+ }], naturalCustomCss: [{
108
+ type: Input
109
+ }] } });
110
+
111
+ class ImagePlugin {
112
+ constructor(document) {
113
+ this.document = document;
114
+ this.plugin = new Plugin({
115
+ state: {
116
+ init() {
117
+ return DecorationSet.empty;
118
+ },
119
+ apply(tr, set) {
120
+ // Adjust decoration positions to changes made by the transaction
121
+ set = set.map(tr.mapping, tr.doc);
122
+ // See if the transaction adds or removes any placeholders
123
+ const action = tr.getMeta(this);
124
+ if (action && action.add) {
125
+ const widget = document.createElement('placeholder');
126
+ const deco = Decoration.widget(action.add.pos, widget, { id: action.add.id });
127
+ set = set.add(tr.doc, [deco]);
128
+ }
129
+ else if (action && action.remove) {
130
+ set = set.remove(set.find(undefined, undefined, spec => spec.id === action.remove.id));
131
+ }
132
+ return set;
133
+ },
134
+ },
135
+ props: {
136
+ decorations(state) {
137
+ return this.getState(state);
138
+ },
139
+ },
140
+ });
141
+ }
142
+ findPlaceholder(state, id) {
143
+ const decorators = this.plugin.getState(state);
144
+ const found = decorators.find(undefined, undefined, spec => spec.id === id);
145
+ return found.length ? found[0].from : null;
146
+ }
147
+ startImageUpload(view, file, uploader, schema) {
148
+ // A fresh object to act as the ID for this upload
149
+ const id = {};
150
+ // Replace the selection with a placeholder
151
+ const tr = view.state.tr;
152
+ if (!tr.selection.empty) {
153
+ tr.deleteSelection();
154
+ }
155
+ tr.setMeta(this.plugin, { add: { id, pos: tr.selection.from } });
156
+ view.dispatch(tr);
157
+ uploader(file).subscribe({
158
+ next: url => {
159
+ const pos = this.findPlaceholder(view.state, id);
160
+ // If the content around the placeholder has been deleted, drop
161
+ // the image
162
+ if (pos === null) {
163
+ return;
164
+ }
165
+ // Otherwise, insert it at the placeholder's position, and remove
166
+ // the placeholder
167
+ view.dispatch(view.state.tr
168
+ .replaceWith(pos, pos, schema.nodes.image.create({ src: url }))
169
+ .setMeta(this.plugin, { remove: { id } }));
170
+ },
171
+ error: () => {
172
+ // On failure, just clean up the placeholder
173
+ view?.dispatch(tr.setMeta(this.plugin, { remove: { id } }));
174
+ },
175
+ });
176
+ }
177
+ }
178
+ ImagePlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ImagePlugin, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
179
+ ImagePlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ImagePlugin });
180
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ImagePlugin, decorators: [{
181
+ type: Injectable
182
+ }], ctorParameters: function () { return [{ type: Document, decorators: [{
183
+ type: Inject,
184
+ args: [DOCUMENT]
185
+ }] }]; } });
186
+
187
+ const ALIGN_PATTERN = /(left|right|center|justify)/;
188
+ /**
189
+ * A plain paragraph textblock. Represented in the DOM
190
+ * as a `<p>` element.
191
+ *
192
+ * https://github.com/ProseMirror/prosemirror-schema-basic/blob/master/src/schema-basic.js
193
+ */
194
+ const paragraphWithAlignment = {
195
+ attrs: {
196
+ align: { default: null },
197
+ class: { default: null },
198
+ id: { default: null },
199
+ },
200
+ content: 'inline*',
201
+ group: 'block',
202
+ parseDOM: [
203
+ {
204
+ tag: 'p',
205
+ getAttrs: (dom) => {
206
+ if (!(dom instanceof HTMLElement)) {
207
+ return;
208
+ }
209
+ const { textAlign } = dom.style;
210
+ let align = dom.getAttribute('align') || textAlign || '';
211
+ align = ALIGN_PATTERN.test(align) ? align : null;
212
+ const id = dom.getAttribute('id') || '';
213
+ return { align, class: dom.className, id };
214
+ },
215
+ },
216
+ ],
217
+ toDOM: node => {
218
+ const { align, id } = node.attrs;
219
+ const attrs = {};
220
+ let style = '';
221
+ if (align && align !== 'left') {
222
+ style += `text-align: ${align};`;
223
+ }
224
+ if (style) {
225
+ attrs.style = style;
226
+ }
227
+ if (id) {
228
+ attrs.id = id;
229
+ }
230
+ if (node.attrs.class) {
231
+ attrs.class = node.attrs.class;
232
+ }
233
+ return ['p', attrs, 0];
234
+ },
235
+ };
236
+
237
+ function getCellAttrs(dom, extraAttrs) {
238
+ if (!(dom instanceof HTMLElement)) {
239
+ return;
240
+ }
241
+ const widthAttr = dom.getAttribute('data-colwidth');
242
+ const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(',').map(s => Number(s)) : null;
243
+ const colspan = Number(dom.getAttribute('colspan') || 1);
244
+ const result = {
245
+ colspan,
246
+ rowspan: Number(dom.getAttribute('rowspan') || 1),
247
+ colwidth: widths && widths.length == colspan ? widths : null,
248
+ };
249
+ for (const prop in extraAttrs) {
250
+ const getter = extraAttrs[prop].getFromDOM;
251
+ const value = getter && getter(dom);
252
+ if (value != null)
253
+ result[prop] = value;
254
+ }
255
+ return result;
256
+ }
257
+ function setCellAttrs(node, extraAttrs) {
258
+ const attrs = {};
259
+ if (node.attrs.colspan != 1)
260
+ attrs.colspan = node.attrs.colspan;
261
+ if (node.attrs.rowspan != 1)
262
+ attrs.rowspan = node.attrs.rowspan;
263
+ if (node.attrs.colwidth)
264
+ attrs['data-colwidth'] = node.attrs.colwidth.join(',');
265
+ for (const prop in extraAttrs) {
266
+ const setter = extraAttrs[prop].setDOMAttr;
267
+ if (setter)
268
+ setter(node.attrs[prop], attrs);
269
+ }
270
+ return attrs;
271
+ }
272
+ /**
273
+ * This function creates a set of [node
274
+ * specs](http://prosemirror.net/docs/ref/#model.SchemaSpec.nodes) for
275
+ * `table`, `table_row`, and `table_cell` nodes types.
276
+ *
277
+ * It is very directly inspired by prosemirror-table
278
+ */
279
+ function tableNodes(options) {
280
+ const extraAttrs = options.cellAttributes || {};
281
+ const cellAttrs = {
282
+ colspan: { default: 1 },
283
+ rowspan: { default: 1 },
284
+ colwidth: { default: null },
285
+ };
286
+ for (const prop in extraAttrs) {
287
+ cellAttrs[prop] = {
288
+ default: extraAttrs[prop].default,
289
+ };
290
+ }
291
+ return {
292
+ table: {
293
+ attrs: {
294
+ class: { default: null },
295
+ },
296
+ content: 'table_row+',
297
+ tableRole: 'table',
298
+ isolating: true,
299
+ group: options.tableGroup,
300
+ parseDOM: [
301
+ {
302
+ tag: 'table',
303
+ getAttrs: (dom) => {
304
+ if (!(dom instanceof HTMLElement)) {
305
+ return;
306
+ }
307
+ return { class: dom.className };
308
+ },
309
+ },
310
+ ],
311
+ toDOM: node => {
312
+ const attrs = {};
313
+ if (node.attrs.class) {
314
+ attrs.class = node.attrs.class;
315
+ }
316
+ return ['table', attrs, ['tbody', 0]];
317
+ },
318
+ },
319
+ table_row: {
320
+ content: '(table_cell | table_header)*',
321
+ tableRole: 'row',
322
+ parseDOM: [{ tag: 'tr' }],
323
+ toDOM: () => {
324
+ return ['tr', 0];
325
+ },
326
+ },
327
+ table_cell: {
328
+ content: options.cellContent,
329
+ attrs: cellAttrs,
330
+ tableRole: 'cell',
331
+ isolating: true,
332
+ parseDOM: [{ tag: 'td', getAttrs: dom => getCellAttrs(dom, extraAttrs) }],
333
+ toDOM: node => {
334
+ return ['td', setCellAttrs(node, extraAttrs), 0];
335
+ },
336
+ },
337
+ table_header: {
338
+ content: options.cellContent,
339
+ attrs: cellAttrs,
340
+ tableRole: 'header_cell',
341
+ isolating: true,
342
+ parseDOM: [{ tag: 'th', getAttrs: dom => getCellAttrs(dom, extraAttrs) }],
343
+ toDOM: node => {
344
+ return ['th', setCellAttrs(node, extraAttrs), 0];
345
+ },
346
+ },
347
+ };
348
+ }
349
+
350
+ const basicNodes = {
351
+ heading: nodes.heading,
352
+ doc: nodes.doc,
353
+ paragraph: nodes.paragraph,
354
+ text: nodes.text,
355
+ hard_break: nodes.hard_break,
356
+ };
357
+ const basicMarks = {
358
+ link: marks.link,
359
+ em: marks.em,
360
+ strong: marks.strong,
361
+ };
362
+ const tmpSchema = new Schema({ nodes: basicNodes, marks: basicMarks });
363
+ const basicSchema = new Schema({
364
+ nodes: addListNodes(tmpSchema.spec.nodes, 'paragraph block*', 'block'),
365
+ marks: tmpSchema.spec.marks,
366
+ });
367
+ const tmpSchema2 = new Schema({
368
+ nodes: {
369
+ ...nodes,
370
+ ...tableNodes({
371
+ tableGroup: 'block',
372
+ cellContent: 'block+',
373
+ cellAttributes: {
374
+ background: {
375
+ default: null,
376
+ getFromDOM(dom) {
377
+ return dom.style.backgroundColor || null;
378
+ },
379
+ setDOMAttr(value, attrs) {
380
+ if (value) {
381
+ attrs.style = (attrs.style || '') + `background-color: ${value};`;
382
+ }
383
+ },
384
+ },
385
+ },
386
+ }),
387
+ paragraph: paragraphWithAlignment,
388
+ },
389
+ marks: basicMarks,
390
+ });
391
+ const advancedSchema = new Schema({
392
+ nodes: addListNodes(tmpSchema2.spec.nodes, 'paragraph block*', 'block'),
393
+ marks: basicMarks,
394
+ });
395
+
396
+ /**
397
+ * One item of the menu.
398
+ *
399
+ * This is the equivalent of `MenuItem` but without all the rendering logic since we use Angular
400
+ * templates for rendering. Also it caches the state of the item everytime the editor state changes,
401
+ * so Angular can query the state as often as needed without performance hit.
402
+ */
403
+ class Item {
404
+ constructor(spec) {
405
+ this.spec = spec;
406
+ /**
407
+ * Whether the item is 'active' (for example, the item for toggling the strong mark might be active when the cursor is in strong text).
408
+ */
409
+ this.active = false;
410
+ /**
411
+ * Button is shown but disabled, because the item cannot be (un-)applied
412
+ */
413
+ this.disabled = false;
414
+ /**
415
+ * Whether the item is shown at the moment
416
+ */
417
+ this.show = true;
418
+ }
419
+ /**
420
+ * Update the item state according to the editor state
421
+ */
422
+ update(view, state) {
423
+ if (this.spec.active) {
424
+ this.active = this.spec.active(state);
425
+ }
426
+ if (this.spec.enable) {
427
+ this.disabled = !this.spec.enable(state);
428
+ }
429
+ if (this.spec.select) {
430
+ this.show = this.spec.select(state);
431
+ }
432
+ }
433
+ }
434
+
435
+ function setTextAlign(tr, schema, alignment) {
436
+ const { selection, doc } = tr;
437
+ if (!selection || !doc) {
438
+ return tr;
439
+ }
440
+ const { from, to } = selection;
441
+ const { nodes } = schema;
442
+ const tasks = [];
443
+ alignment = alignment || null;
444
+ const allowedNodeTypes = new Set([
445
+ nodes.paragraph,
446
+ // nodes['blockquote'],
447
+ // nodes['listItem'],
448
+ // nodes['heading'],
449
+ ]);
450
+ doc.nodesBetween(from, to, (node, pos) => {
451
+ const nodeType = node.type;
452
+ const align = node.attrs.align || null;
453
+ if (align !== alignment && allowedNodeTypes.has(nodeType)) {
454
+ tasks.push({
455
+ node,
456
+ pos,
457
+ nodeType,
458
+ });
459
+ }
460
+ return true;
461
+ });
462
+ if (!tasks.length) {
463
+ return tr;
464
+ }
465
+ tasks.forEach(job => {
466
+ const { node, pos, nodeType } = job;
467
+ const newAttrs = {
468
+ ...node.attrs,
469
+ align: alignment ? alignment : null,
470
+ };
471
+ tr = tr.setNodeMarkup(pos, nodeType, newAttrs, node.marks);
472
+ });
473
+ return tr;
474
+ }
475
+ class TextAlignItem extends Item {
476
+ constructor(alignment) {
477
+ super({
478
+ active: state => {
479
+ const { selection, doc } = state;
480
+ const { from, to } = selection;
481
+ let keepLooking = true;
482
+ let active = false;
483
+ doc.nodesBetween(from, to, node => {
484
+ if (keepLooking && node.attrs.align === alignment) {
485
+ keepLooking = false;
486
+ active = true;
487
+ }
488
+ return keepLooking;
489
+ });
490
+ return active;
491
+ },
492
+ enable: state => {
493
+ const { selection } = state;
494
+ return selection instanceof TextSelection || selection instanceof AllSelection;
495
+ },
496
+ run: (state, dispatch) => {
497
+ const { schema, selection } = state;
498
+ const tr = setTextAlign(state.tr.setSelection(selection), schema, this.active ? null : alignment);
499
+ if (tr.docChanged) {
500
+ dispatch?.(tr);
501
+ return true;
502
+ }
503
+ else {
504
+ return false;
505
+ }
506
+ },
507
+ });
508
+ }
509
+ }
510
+
511
+ class ColorDialogComponent {
512
+ constructor(data, dialogRef) {
513
+ this.dialogRef = dialogRef;
514
+ this.colors = [
515
+ [
516
+ '#000000',
517
+ '#111111',
518
+ '#1c1c1c',
519
+ '#333333',
520
+ '#666666',
521
+ '#808080',
522
+ '#999999',
523
+ '#b2b2b2',
524
+ '#cccccc',
525
+ '#dddddd',
526
+ '#eeeeee',
527
+ '#ffffff',
528
+ ],
529
+ [
530
+ '#ffff00',
531
+ '#ffbf00',
532
+ '#ff8000',
533
+ '#ff4000',
534
+ '#ff0000',
535
+ '#bf0041',
536
+ '#800080',
537
+ '#55308d',
538
+ '#2a6099',
539
+ '#158466',
540
+ '#00a933',
541
+ '#81d41a',
542
+ ],
543
+ [
544
+ '#ffffd7',
545
+ '#fff5ce',
546
+ '#ffdbb6',
547
+ '#ffd8ce',
548
+ '#ffd7d7',
549
+ '#f7d1d5',
550
+ '#e0c2cd',
551
+ '#dedce6',
552
+ '#dee6ef',
553
+ '#dee7e5',
554
+ '#dde8cb',
555
+ '#f6f9d4',
556
+ ],
557
+ [
558
+ '#ffffa6',
559
+ '#ffe994',
560
+ '#ffb66c',
561
+ '#ffaa95',
562
+ '#ffa6a6',
563
+ '#ec9ba4',
564
+ '#bf819e',
565
+ '#b7b3ca',
566
+ '#b4c7dc',
567
+ '#b3cac7',
568
+ '#afd095',
569
+ '#e8f2a1',
570
+ ],
571
+ [
572
+ '#ffff6d',
573
+ '#ffde59',
574
+ '#ff972f',
575
+ '#ff7b59',
576
+ '#ff6d6d',
577
+ '#e16173',
578
+ '#a1467e',
579
+ '#8e86ae',
580
+ '#729fcf',
581
+ '#81aca6',
582
+ '#77bc65',
583
+ '#d4ea6b',
584
+ ],
585
+ [
586
+ '#ffff38',
587
+ '#ffd428',
588
+ '#ff860d',
589
+ '#ff5429',
590
+ '#ff3838',
591
+ '#d62e4e',
592
+ '#8d1d75',
593
+ '#6b5e9b',
594
+ '#5983b0',
595
+ '#50938a',
596
+ '#3faf46',
597
+ '#bbe33d',
598
+ ],
599
+ [
600
+ '#e6e905',
601
+ '#e8a202',
602
+ '#ea7500',
603
+ '#ed4c05',
604
+ '#f10d0c',
605
+ '#a7074b',
606
+ '#780373',
607
+ '#5b277d',
608
+ '#3465a4',
609
+ '#168253',
610
+ '#069a2e',
611
+ '#5eb91e',
612
+ ],
613
+ [
614
+ '#acb20c',
615
+ '#b47804',
616
+ '#b85c00',
617
+ '#be480a',
618
+ '#c9211e',
619
+ '#861141',
620
+ '#650953',
621
+ '#55215b',
622
+ '#355269',
623
+ '#1e6a39',
624
+ '#127622',
625
+ '#468a1a',
626
+ ],
627
+ [
628
+ '#706e0c',
629
+ '#784b04',
630
+ '#7b3d00',
631
+ '#813709',
632
+ '#8d281e',
633
+ '#611729',
634
+ '#4e102d',
635
+ '#481d32',
636
+ '#383d3c',
637
+ '#28471f',
638
+ '#224b12',
639
+ '#395511',
640
+ ],
641
+ [
642
+ '#443205',
643
+ '#472702',
644
+ '#492300',
645
+ '#4b2204',
646
+ '#50200c',
647
+ '#41190d',
648
+ '#3b160e',
649
+ '#3a1a0f',
650
+ '#362413',
651
+ '#302709',
652
+ '#2e2706',
653
+ '#342a06',
654
+ ],
655
+ ];
656
+ this.colorControl = new FormControl('', Validators.pattern(/^#\p{Hex_Digit}{6}/u));
657
+ this.form = new FormGroup({
658
+ color: this.colorControl,
659
+ });
660
+ this.form.setValue(data);
661
+ }
662
+ maybeConfirm() {
663
+ ifValid(this.form).subscribe(() => this.confirm());
664
+ }
665
+ confirm() {
666
+ this.dialogRef.close(this.form.value);
667
+ }
668
+ selectColor(color) {
669
+ this.colorControl.setValue(color);
670
+ this.maybeConfirm();
671
+ }
672
+ }
673
+ ColorDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ColorDialogComponent, deps: [{ token: MAT_DIALOG_DATA }, { token: i1.MatDialogRef }], target: i0.ɵɵFactoryTarget.Component });
674
+ ColorDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.0", type: ColorDialogComponent, selector: "ng-component", ngImport: i0, template: "<h2 i18n mat-dialog-title>S\u00E9lectionner une couleur</h2>\n\n<mat-dialog-content [formGroup]=\"form\">\n <div>\n <div *ngFor=\"let row of colors\">\n <div\n *ngFor=\"let color of row\"\n class=\"color\"\n [style]=\"{backgroundColor: color}\"\n (click)=\"selectColor(color)\"\n >\n </div>\n </div>\n </div>\n\n <div>\n <button mat-button (click)=\"selectColor('')\">\n <natural-icon name=\"format_color_reset\"></natural-icon>\n <span i18n>Transparent</span></button\n >\n </div>\n\n <mat-form-field>\n <mat-label i18n>Couleur</mat-label>\n <input matInput [formControl]=\"colorControl\" (keydown.enter)=\"maybeConfirm()\" cdkFocusInitial />\n <div class=\"sample\" matSuffix [style]=\"{backgroundColor: colorControl.valid ? colorControl.value : ''}\"></div>\n <mat-error *ngIf=\"colorControl.hasError('pattern')\" i18n\n >Doit \u00EAtre le format hexadecimal. Par exemple: #ff4000\n </mat-error>\n </mat-form-field>\n</mat-dialog-content>\n\n<mat-dialog-actions>\n <button mat-button [mat-dialog-close] i18n>Annuler</button>\n <button mat-stroked-button (click)=\"maybeConfirm()\" [disabled]=\"!form.valid\"><span i18n>Valider</span></button>\n</mat-dialog-actions>\n", styles: ["mat-dialog-actions{display:flex;flex-direction:row;justify-content:flex-end}mat-dialog-content{width:70vw;max-width:30em;display:grid;justify-content:center;row-gap:25px}.color{display:inline-block;width:25px;height:25px;margin:3px;cursor:pointer}.color:hover{padding:3px;margin:0}.sample{width:27px;height:27px}\n"], components: [{ type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { type: i3$1.NaturalIconComponent, selector: "natural-icon", inputs: ["label", "labelColor", "labelPosition", "name", "size"] }, { type: i2.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }], directives: [{ type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i4.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i4.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i6.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.MatLabel, selector: "mat-label" }, { type: i5.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { type: i4.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { type: i2.MatSuffix, selector: "[matSuffix]" }, { type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.MatError, selector: "mat-error", inputs: ["id"] }, { type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }, { type: i1.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["aria-label", "type", "mat-dialog-close", "matDialogClose"], exportAs: ["matDialogClose"] }] });
675
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ColorDialogComponent, decorators: [{
676
+ type: Component,
677
+ args: [{ template: "<h2 i18n mat-dialog-title>S\u00E9lectionner une couleur</h2>\n\n<mat-dialog-content [formGroup]=\"form\">\n <div>\n <div *ngFor=\"let row of colors\">\n <div\n *ngFor=\"let color of row\"\n class=\"color\"\n [style]=\"{backgroundColor: color}\"\n (click)=\"selectColor(color)\"\n >\n </div>\n </div>\n </div>\n\n <div>\n <button mat-button (click)=\"selectColor('')\">\n <natural-icon name=\"format_color_reset\"></natural-icon>\n <span i18n>Transparent</span></button\n >\n </div>\n\n <mat-form-field>\n <mat-label i18n>Couleur</mat-label>\n <input matInput [formControl]=\"colorControl\" (keydown.enter)=\"maybeConfirm()\" cdkFocusInitial />\n <div class=\"sample\" matSuffix [style]=\"{backgroundColor: colorControl.valid ? colorControl.value : ''}\"></div>\n <mat-error *ngIf=\"colorControl.hasError('pattern')\" i18n\n >Doit \u00EAtre le format hexadecimal. Par exemple: #ff4000\n </mat-error>\n </mat-form-field>\n</mat-dialog-content>\n\n<mat-dialog-actions>\n <button mat-button [mat-dialog-close] i18n>Annuler</button>\n <button mat-stroked-button (click)=\"maybeConfirm()\" [disabled]=\"!form.valid\"><span i18n>Valider</span></button>\n</mat-dialog-actions>\n", styles: ["mat-dialog-actions{display:flex;flex-direction:row;justify-content:flex-end}mat-dialog-content{width:70vw;max-width:30em;display:grid;justify-content:center;row-gap:25px}.color{display:inline-block;width:25px;height:25px;margin:3px;cursor:pointer}.color:hover{padding:3px;margin:0}.sample{width:27px;height:27px}\n"] }]
678
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
679
+ type: Inject,
680
+ args: [MAT_DIALOG_DATA]
681
+ }] }, { type: i1.MatDialogRef }]; } });
682
+
683
+ const setCellBackgroundColor = setCellAttr.bind(null, 'background');
684
+ function findFirstClassInSelection$1(state) {
685
+ if (!isInTable(state)) {
686
+ return '';
687
+ }
688
+ // For single cell selection
689
+ const $cell = selectionCell(state);
690
+ let foundColor = $cell?.nodeAfter?.attrs.background ?? '';
691
+ if (foundColor) {
692
+ return foundColor;
693
+ }
694
+ // For multiple cells selection
695
+ let keepLooking = true;
696
+ if (state.selection instanceof CellSelection) {
697
+ state.selection.forEachCell(node => {
698
+ const color = node.attrs.background;
699
+ if (keepLooking && color) {
700
+ keepLooking = false;
701
+ foundColor = color;
702
+ }
703
+ });
704
+ }
705
+ return foundColor;
706
+ }
707
+ class CellBackgroundColorItem extends Item {
708
+ constructor(dialog) {
709
+ super({
710
+ enable(state) {
711
+ // Pretend to set a unique color that is not already set, to test if we can any color at all
712
+ const cmd = setCellBackgroundColor('#000001');
713
+ return cmd(state);
714
+ },
715
+ run(state, dispatch, view) {
716
+ dialog
717
+ .open(ColorDialogComponent, {
718
+ data: {
719
+ color: findFirstClassInSelection$1(state),
720
+ },
721
+ })
722
+ .afterClosed()
723
+ .subscribe(result => {
724
+ if (dispatch && result) {
725
+ const cmd = setCellBackgroundColor(result.color);
726
+ cmd(state, dispatch);
727
+ }
728
+ view.focus();
729
+ });
730
+ },
731
+ });
732
+ }
733
+ }
734
+
735
+ class LinkDialogComponent {
736
+ constructor(data, dialogRef) {
737
+ this.dialogRef = dialogRef;
738
+ this.hrefControl = new FormControl('', Validators.required);
739
+ this.titleControl = new FormControl('');
740
+ this.form = new FormGroup({
741
+ href: this.hrefControl,
742
+ title: this.titleControl,
743
+ });
744
+ this.form.setValue(data);
745
+ }
746
+ maybeConfirm() {
747
+ ifValid(this.form).subscribe(() => this.confirm());
748
+ }
749
+ confirm() {
750
+ this.dialogRef.close(this.form.value);
751
+ }
752
+ }
753
+ LinkDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: LinkDialogComponent, deps: [{ token: MAT_DIALOG_DATA }, { token: i1.MatDialogRef }], target: i0.ɵɵFactoryTarget.Component });
754
+ LinkDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.0", type: LinkDialogComponent, selector: "ng-component", ngImport: i0, template: "<h2 i18n mat-dialog-title>Ins\u00E9rer un lien</h2>\n\n<mat-dialog-content [formGroup]=\"form\">\n <mat-form-field>\n <mat-label i18n>URL</mat-label>\n <input matInput [formControl]=\"hrefControl\" (keydown.enter)=\"maybeConfirm()\" />\n <mat-error *ngIf=\"hrefControl.hasError('required')\" i18n>Ce champ est requis</mat-error>\n </mat-form-field>\n <mat-form-field>\n <mat-label i18n>Titre</mat-label>\n <input matInput [formControl]=\"titleControl\" (keydown.enter)=\"maybeConfirm()\" />\n </mat-form-field>\n</mat-dialog-content>\n\n<mat-dialog-actions>\n <button mat-button [mat-dialog-close] i18n>Annuler</button>\n <button mat-stroked-button (click)=\"maybeConfirm()\" [disabled]=\"!form.valid\"><span i18n>Valider</span></button>\n</mat-dialog-actions>\n", styles: ["mat-dialog-actions{display:flex;flex-direction:row;justify-content:flex-end}mat-dialog-content{width:70vw;max-width:60em;display:grid}\n"], components: [{ type: i2.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i4.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i4.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i2.MatLabel, selector: "mat-label" }, { type: i5.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { type: i4.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.MatError, selector: "mat-error", inputs: ["id"] }, { type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }, { type: i1.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["aria-label", "type", "mat-dialog-close", "matDialogClose"], exportAs: ["matDialogClose"] }] });
755
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: LinkDialogComponent, decorators: [{
756
+ type: Component,
757
+ args: [{ template: "<h2 i18n mat-dialog-title>Ins\u00E9rer un lien</h2>\n\n<mat-dialog-content [formGroup]=\"form\">\n <mat-form-field>\n <mat-label i18n>URL</mat-label>\n <input matInput [formControl]=\"hrefControl\" (keydown.enter)=\"maybeConfirm()\" />\n <mat-error *ngIf=\"hrefControl.hasError('required')\" i18n>Ce champ est requis</mat-error>\n </mat-form-field>\n <mat-form-field>\n <mat-label i18n>Titre</mat-label>\n <input matInput [formControl]=\"titleControl\" (keydown.enter)=\"maybeConfirm()\" />\n </mat-form-field>\n</mat-dialog-content>\n\n<mat-dialog-actions>\n <button mat-button [mat-dialog-close] i18n>Annuler</button>\n <button mat-stroked-button (click)=\"maybeConfirm()\" [disabled]=\"!form.valid\"><span i18n>Valider</span></button>\n</mat-dialog-actions>\n", styles: ["mat-dialog-actions{display:flex;flex-direction:row;justify-content:flex-end}mat-dialog-content{width:70vw;max-width:60em;display:grid}\n"] }]
758
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
759
+ type: Inject,
760
+ args: [MAT_DIALOG_DATA]
761
+ }] }, { type: i1.MatDialogRef }]; } });
762
+
763
+ function markActive(state, type) {
764
+ const { from, $from, to, empty } = state.selection;
765
+ if (empty) {
766
+ return !!type.isInSet(state.storedMarks || $from.marks());
767
+ }
768
+ else {
769
+ return state.doc.rangeHasMark(from, to, type);
770
+ }
771
+ }
772
+ /**
773
+ * Convert built-in `MenuItem` into our Angular specific `Item`
774
+ */
775
+ function menuItemToItem(item) {
776
+ return new Item(item.spec);
777
+ }
778
+ /**
779
+ * From a `Command`, creates a new `Item` that will have an automatic `enable` spec
780
+ */
781
+ function cmdToItem(cmd, options = {}) {
782
+ const passedOptions = {
783
+ run: cmd,
784
+ ...options,
785
+ };
786
+ if (!options.enable && !options.select) {
787
+ passedOptions.enable = state => cmd(state);
788
+ }
789
+ return new Item(passedOptions);
790
+ }
791
+ /**
792
+ * From a `MarkType`, creates a new `Item` that will have an automatic `active` and `enable` spec
793
+ */
794
+ function markTypeToItem(markType) {
795
+ return cmdToItem(toggleMark(markType), {
796
+ active(state) {
797
+ return markActive(state, markType);
798
+ },
799
+ });
800
+ }
801
+
802
+ class LinkItem extends Item {
803
+ constructor(markType, dialog) {
804
+ super({
805
+ active(state) {
806
+ return markActive(state, markType);
807
+ },
808
+ enable(state) {
809
+ return !state.selection.empty;
810
+ },
811
+ run(state, dispatch, view) {
812
+ if (markActive(state, markType)) {
813
+ toggleMark(markType)(state, dispatch);
814
+ return;
815
+ }
816
+ dialog
817
+ .open(LinkDialogComponent, {
818
+ data: {
819
+ href: '',
820
+ title: '',
821
+ },
822
+ })
823
+ .afterClosed()
824
+ .subscribe(result => {
825
+ if (result) {
826
+ if (!result.title) {
827
+ delete result.title;
828
+ }
829
+ toggleMark(markType, result)(view.state, view.dispatch);
830
+ }
831
+ view.focus();
832
+ });
833
+ },
834
+ });
835
+ }
836
+ }
837
+
838
+ function canInsert(state, nodeType) {
839
+ const $from = state.selection.$from;
840
+ for (let d = $from.depth; d >= 0; d--) {
841
+ const index = $from.index(d);
842
+ if ($from.node(d).canReplaceWith(index, index, nodeType)) {
843
+ return true;
844
+ }
845
+ }
846
+ return false;
847
+ }
848
+ class HorizontalRuleItem extends Item {
849
+ constructor(hr) {
850
+ super({
851
+ enable(state) {
852
+ return canInsert(state, hr);
853
+ },
854
+ run(state, dispatch) {
855
+ dispatch(state.tr.replaceSelectionWith(hr.create()));
856
+ },
857
+ });
858
+ }
859
+ }
860
+
861
+ function wrapListItem(nodeType) {
862
+ return cmdToItem(wrapInList(nodeType));
863
+ }
864
+
865
+ class ClassDialogComponent {
866
+ constructor(data, dialogRef) {
867
+ this.dialogRef = dialogRef;
868
+ this.classControl = new FormControl('', Validators.pattern(/(^\s*(-?[_a-zA-Z]+[_a-zA-Z0-9-]*\s*)+)/));
869
+ this.form = new FormGroup({
870
+ class: this.classControl,
871
+ });
872
+ this.form.setValue(data);
873
+ }
874
+ maybeConfirm() {
875
+ ifValid(this.form).subscribe(() => this.confirm());
876
+ }
877
+ confirm() {
878
+ this.dialogRef.close(this.form.value);
879
+ }
880
+ }
881
+ ClassDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ClassDialogComponent, deps: [{ token: MAT_DIALOG_DATA }, { token: i1.MatDialogRef }], target: i0.ɵɵFactoryTarget.Component });
882
+ ClassDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.0", type: ClassDialogComponent, selector: "ng-component", ngImport: i0, template: "<h2 i18n mat-dialog-title>Saisir les classes CSS</h2>\n\n<mat-dialog-content [formGroup]=\"form\">\n <mat-form-field>\n <mat-label i18n>Classes CSS</mat-label>\n <input matInput [formControl]=\"classControl\" (keydown.enter)=\"maybeConfirm()\" cdkFocusInitial />\n <div class=\"sample\" matSuffix [style]=\"{backgroundClass: classControl.valid ? classControl.value : ''}\"></div>\n <mat-error *ngIf=\"classControl.hasError('pattern')\" i18n>Doit \u00EAtre un ou plusieurs nom de classe CSS</mat-error>\n </mat-form-field>\n</mat-dialog-content>\n\n<mat-dialog-actions>\n <button mat-button [mat-dialog-close] i18n>Annuler</button>\n <button mat-stroked-button (click)=\"maybeConfirm()\" [disabled]=\"!form.valid\"><span i18n>Valider</span></button>\n</mat-dialog-actions>\n", styles: ["mat-dialog-actions{display:flex;flex-direction:row;justify-content:flex-end}mat-dialog-content{width:70vw;max-width:30em;display:grid}\n"], components: [{ type: i2.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i4.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i4.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i2.MatLabel, selector: "mat-label" }, { type: i5.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { type: i4.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { type: i2.MatSuffix, selector: "[matSuffix]" }, { type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.MatError, selector: "mat-error", inputs: ["id"] }, { type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }, { type: i1.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["aria-label", "type", "mat-dialog-close", "matDialogClose"], exportAs: ["matDialogClose"] }] });
883
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ClassDialogComponent, decorators: [{
884
+ type: Component,
885
+ args: [{ template: "<h2 i18n mat-dialog-title>Saisir les classes CSS</h2>\n\n<mat-dialog-content [formGroup]=\"form\">\n <mat-form-field>\n <mat-label i18n>Classes CSS</mat-label>\n <input matInput [formControl]=\"classControl\" (keydown.enter)=\"maybeConfirm()\" cdkFocusInitial />\n <div class=\"sample\" matSuffix [style]=\"{backgroundClass: classControl.valid ? classControl.value : ''}\"></div>\n <mat-error *ngIf=\"classControl.hasError('pattern')\" i18n>Doit \u00EAtre un ou plusieurs nom de classe CSS</mat-error>\n </mat-form-field>\n</mat-dialog-content>\n\n<mat-dialog-actions>\n <button mat-button [mat-dialog-close] i18n>Annuler</button>\n <button mat-stroked-button (click)=\"maybeConfirm()\" [disabled]=\"!form.valid\"><span i18n>Valider</span></button>\n</mat-dialog-actions>\n", styles: ["mat-dialog-actions{display:flex;flex-direction:row;justify-content:flex-end}mat-dialog-content{width:70vw;max-width:30em;display:grid}\n"] }]
886
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
887
+ type: Inject,
888
+ args: [MAT_DIALOG_DATA]
889
+ }] }, { type: i1.MatDialogRef }]; } });
890
+
891
+ function setClass(tr, classValue, allowedNodeType) {
892
+ const { selection, doc } = tr;
893
+ if (!selection || !doc) {
894
+ return tr;
895
+ }
896
+ const { from, to } = selection;
897
+ const tasks = [];
898
+ doc.nodesBetween(from, to, (node, pos) => {
899
+ const nodeType = node.type;
900
+ const currentClass = node.attrs.class || null;
901
+ if (currentClass !== classValue && allowedNodeType === nodeType) {
902
+ tasks.push({
903
+ node,
904
+ pos,
905
+ nodeType,
906
+ });
907
+ }
908
+ return true;
909
+ });
910
+ if (!tasks.length) {
911
+ return tr;
912
+ }
913
+ tasks.forEach(job => {
914
+ const { node, pos, nodeType } = job;
915
+ const newAttrs = {
916
+ ...node.attrs,
917
+ class: classValue ? classValue : null,
918
+ };
919
+ tr = tr.setNodeMarkup(pos, nodeType, newAttrs, node.marks);
920
+ });
921
+ return tr;
922
+ }
923
+ /**
924
+ * Returns the first `class` attribute that is non-empty in the selection.
925
+ * If not found, return empty string.
926
+ */
927
+ function findFirstClassInSelection(state, allowedNodeType) {
928
+ const { selection, doc } = state;
929
+ const { from, to } = selection;
930
+ let keepLooking = true;
931
+ let foundClass = '';
932
+ doc.nodesBetween(from, to, node => {
933
+ if (keepLooking && node.type === allowedNodeType && node.attrs.class) {
934
+ keepLooking = false;
935
+ foundClass = node.attrs.class;
936
+ }
937
+ return keepLooking;
938
+ });
939
+ return foundClass;
940
+ }
941
+ class ClassItem extends Item {
942
+ constructor(dialog, nodeType) {
943
+ super({
944
+ active: state => {
945
+ return !!findFirstClassInSelection(state, nodeType);
946
+ },
947
+ enable: state => {
948
+ const { selection } = state;
949
+ return selection instanceof TextSelection || selection instanceof AllSelection;
950
+ },
951
+ run: (state, dispatch, view) => {
952
+ dialog
953
+ .open(ClassDialogComponent, {
954
+ data: {
955
+ class: findFirstClassInSelection(state, nodeType),
956
+ },
957
+ })
958
+ .afterClosed()
959
+ .subscribe(result => {
960
+ if (dispatch && result) {
961
+ const { selection } = state;
962
+ const tr = setClass(state.tr.setSelection(selection), result.class, nodeType);
963
+ if (tr.docChanged) {
964
+ dispatch?.(tr);
965
+ }
966
+ }
967
+ view.focus();
968
+ });
969
+ },
970
+ });
971
+ }
972
+ }
973
+
974
+ function createCell(cellType, cellContent) {
975
+ return cellContent ? cellType.createChecked(null, cellContent) : cellType.createAndFill();
976
+ }
977
+ function createTable(state, rowsCount, colsCount, withHeaderRow, cellContent) {
978
+ const types = tableNodeTypes(state.schema);
979
+ const headerCells = [];
980
+ const cells = [];
981
+ for (let index = 0; index < colsCount; index += 1) {
982
+ const cell = createCell(types.cell, cellContent);
983
+ if (cell) {
984
+ cells.push(cell);
985
+ }
986
+ if (withHeaderRow) {
987
+ const headerCell = createCell(types.header_cell, cellContent);
988
+ if (headerCell) {
989
+ headerCells.push(headerCell);
990
+ }
991
+ }
992
+ }
993
+ const rows = [];
994
+ for (let index = 0; index < rowsCount; index += 1) {
995
+ rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
996
+ }
997
+ return types.table.createChecked(null, rows);
998
+ }
999
+ function addTable(state, dispatch, { rowsCount = 3, colsCount = 3, withHeaderRow = true, cellContent, } = {}) {
1000
+ const offset = state.tr.selection.anchor + 1;
1001
+ const nodes = createTable(state, rowsCount, colsCount, withHeaderRow, cellContent);
1002
+ const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView();
1003
+ const resolvedPos = tr.doc.resolve(offset);
1004
+ // move cursor into table
1005
+ tr.setSelection(TextSelection.near(resolvedPos));
1006
+ dispatch?.(tr);
1007
+ }
1008
+ class AddTableItem extends Item {
1009
+ constructor() {
1010
+ super({ run: (editor, tr) => addTable(editor, tr) });
1011
+ }
1012
+ }
1013
+
1014
+ /**
1015
+ * Given a schema, look for default mark and node types in it and
1016
+ * return an object with relevant menu items relating to those marks:
1017
+ */
1018
+ function buildMenuItems(schema, dialog) {
1019
+ const r = {
1020
+ joinUp: menuItemToItem(joinUpItem),
1021
+ lift: menuItemToItem(liftItem),
1022
+ selectParentNode: menuItemToItem(selectParentNodeItem),
1023
+ undo: menuItemToItem(undoItem),
1024
+ redo: menuItemToItem(redoItem),
1025
+ };
1026
+ let type;
1027
+ type = schema.marks.strong;
1028
+ if (type) {
1029
+ r.toggleStrong = markTypeToItem(type);
1030
+ }
1031
+ type = schema.marks.em;
1032
+ if (type) {
1033
+ r.toggleEm = markTypeToItem(type);
1034
+ }
1035
+ type = schema.marks.code;
1036
+ if (type) {
1037
+ r.toggleCode = markTypeToItem(type);
1038
+ }
1039
+ type = schema.marks.link;
1040
+ if (type) {
1041
+ r.toggleLink = new LinkItem(type, dialog);
1042
+ }
1043
+ type = schema.nodes.bullet_list;
1044
+ if (type) {
1045
+ r.wrapBulletList = wrapListItem(type);
1046
+ }
1047
+ type = schema.nodes.ordered_list;
1048
+ if (type) {
1049
+ r.wrapOrderedList = wrapListItem(type);
1050
+ }
1051
+ type = schema.nodes.blockquote;
1052
+ if (type) {
1053
+ r.wrapBlockQuote = menuItemToItem(wrapItem(type, {}));
1054
+ }
1055
+ type = schema.nodes.paragraph;
1056
+ if (type) {
1057
+ r.makeParagraph = menuItemToItem(blockTypeItem(type, {}));
1058
+ if (type.spec === paragraphWithAlignment) {
1059
+ r.alignLeft = new TextAlignItem('left');
1060
+ r.alignRight = new TextAlignItem('right');
1061
+ r.alignCenter = new TextAlignItem('center');
1062
+ r.alignJustify = new TextAlignItem('justify');
1063
+ r.paragraphClass = new ClassItem(dialog, type);
1064
+ }
1065
+ }
1066
+ type = schema.nodes.code_block;
1067
+ if (type) {
1068
+ r.makeCodeBlock = menuItemToItem(blockTypeItem(type, {}));
1069
+ }
1070
+ type = schema.nodes.heading;
1071
+ if (type) {
1072
+ r.makeHead1 = menuItemToItem(blockTypeItem(type, { attrs: { level: 1 } }));
1073
+ r.makeHead2 = menuItemToItem(blockTypeItem(type, { attrs: { level: 2 } }));
1074
+ r.makeHead3 = menuItemToItem(blockTypeItem(type, { attrs: { level: 3 } }));
1075
+ r.makeHead4 = menuItemToItem(blockTypeItem(type, { attrs: { level: 4 } }));
1076
+ r.makeHead5 = menuItemToItem(blockTypeItem(type, { attrs: { level: 5 } }));
1077
+ r.makeHead6 = menuItemToItem(blockTypeItem(type, { attrs: { level: 6 } }));
1078
+ }
1079
+ type = schema.nodes.horizontal_rule;
1080
+ if (type) {
1081
+ r.insertHorizontalRule = new HorizontalRuleItem(type);
1082
+ }
1083
+ type = schema.nodes.table;
1084
+ if (type) {
1085
+ r.insertTable = new AddTableItem();
1086
+ r.addColumnBefore = cmdToItem(addColumnBefore);
1087
+ r.addColumnAfter = cmdToItem(addColumnAfter);
1088
+ r.deleteColumn = cmdToItem(deleteColumn);
1089
+ r.addRowBefore = cmdToItem(addRowBefore);
1090
+ r.addRowAfter = cmdToItem(addRowAfter);
1091
+ r.deleteRow = cmdToItem(deleteRow);
1092
+ r.deleteTable = cmdToItem(deleteTable);
1093
+ r.mergeCells = cmdToItem(mergeCells);
1094
+ r.splitCell = cmdToItem(splitCell);
1095
+ r.toggleHeaderColumn = cmdToItem(toggleHeaderColumn);
1096
+ r.toggleHeaderRow = cmdToItem(toggleHeaderRow);
1097
+ r.toggleHeaderCell = cmdToItem(toggleHeaderCell);
1098
+ r.cellBackgroundColor = new CellBackgroundColorItem(dialog);
1099
+ r.tableClass = new ClassItem(dialog, type);
1100
+ }
1101
+ return r;
1102
+ }
1103
+
1104
+ /**
1105
+ * Given a blockquote node type, returns an input rule that turns `"> "`
1106
+ * at the start of a textblock into a blockquote.
1107
+ */
1108
+ function blockQuoteRule(nodeType) {
1109
+ return wrappingInputRule(/^\s*>\s$/, nodeType);
1110
+ }
1111
+ /**
1112
+ * Given a list node type, returns an input rule that turns a number
1113
+ * followed by a dot at the start of a textblock into an ordered list.
1114
+ */
1115
+ function orderedListRule(nodeType) {
1116
+ return wrappingInputRule(/^(\d+)\.\s$/, nodeType, match => ({ order: +match[1] }), (match, node) => node.childCount + node.attrs.order === +match[1]);
1117
+ }
1118
+ /**
1119
+ * Given a list node type, returns an input rule that turns a bullet
1120
+ * (dash, plush, or asterisk) at the start of a textblock into a
1121
+ * bullet list.
1122
+ */
1123
+ function bulletListRule(nodeType) {
1124
+ return wrappingInputRule(/^\s*([-+*])\s$/, nodeType);
1125
+ }
1126
+ /**
1127
+ * Given a code block node type, returns an input rule that turns a
1128
+ * textblock starting with three backticks into a code block.
1129
+ */
1130
+ function codeBlockRule(nodeType) {
1131
+ return textblockTypeInputRule(/^```$/, nodeType);
1132
+ }
1133
+ /**
1134
+ * Given a node type and a maximum level, creates an input rule that
1135
+ * turns up to that number of `#` characters followed by a space at
1136
+ * the start of a textblock into a heading whose level corresponds to
1137
+ * the number of `#` signs.
1138
+ */
1139
+ function headingRule(nodeType, maxLevel) {
1140
+ return textblockTypeInputRule(new RegExp('^(#{1,' + maxLevel + '})\\s$'), nodeType, match => ({
1141
+ level: match[1].length,
1142
+ }));
1143
+ }
1144
+ /**
1145
+ * A set of input rules for creating the basic block quotes, lists,
1146
+ * code blocks, and heading.
1147
+ */
1148
+ function buildInputRules(schema) {
1149
+ const rules = [ellipsis, emDash];
1150
+ let type = schema.nodes.blockquote;
1151
+ if (type) {
1152
+ rules.push(blockQuoteRule(type));
1153
+ }
1154
+ type = schema.nodes.ordered_list;
1155
+ if (type) {
1156
+ rules.push(orderedListRule(type));
1157
+ }
1158
+ type = schema.nodes.bullet_list;
1159
+ if (type) {
1160
+ rules.push(bulletListRule(type));
1161
+ }
1162
+ type = schema.nodes.code_block;
1163
+ if (type) {
1164
+ rules.push(codeBlockRule(type));
1165
+ }
1166
+ type = schema.nodes.heading;
1167
+ if (type) {
1168
+ rules.push(headingRule(type, 6));
1169
+ }
1170
+ return inputRules({ rules });
1171
+ }
1172
+
1173
+ /**
1174
+ * Inspect the given schema looking for marks and nodes from the
1175
+ * basic schema, and if found, add key bindings related to them.
1176
+ * This will add:
1177
+ *
1178
+ * * **Mod-b** for toggling [strong](#schema-basic.StrongMark)
1179
+ * * **Mod-i** for toggling [emphasis](#schema-basic.EmMark)
1180
+ * * **Mod-`** for toggling [code font](#schema-basic.CodeMark)
1181
+ * * **Ctrl-Shift-0** for making the current textblock a paragraph
1182
+ * * **Ctrl-Shift-1** to **Ctrl-Shift-Digit6** for making the current
1183
+ * textblock a heading of the corresponding level
1184
+ * * **Ctrl-Shift-Backslash** to make the current textblock a code block
1185
+ * * **Ctrl-Shift-8** to wrap the selection in an ordered list
1186
+ * * **Ctrl-Shift-9** to wrap the selection in a bullet list
1187
+ * * **Ctrl->** to wrap the selection in a block quote
1188
+ * * **Enter** to split a non-empty textblock in a list item while at
1189
+ * the same time splitting the list item
1190
+ * * **Mod-Enter** to insert a hard break
1191
+ * * **Mod-_** to insert a horizontal rule
1192
+ * * **Backspace** to undo an input rule
1193
+ * * **Alt-ArrowUp** to `joinUp`
1194
+ * * **Alt-ArrowDown** to `joinDown`
1195
+ * * **Mod-BracketLeft** to `lift`
1196
+ * * **Escape** to `selectParentNode`
1197
+ *
1198
+ * You can suppress or map these bindings by passing a `mapKeys`
1199
+ * argument, which maps key names (say `"Mod-B"` to either `false`, to
1200
+ * remove the binding, or a new key name string.
1201
+ */
1202
+ function buildKeymap(schema, isMac) {
1203
+ const keys = {};
1204
+ keys['Mod-z'] = undo;
1205
+ keys['Shift-Mod-z'] = redo;
1206
+ keys['Backspace'] = undoInputRule;
1207
+ if (!isMac) {
1208
+ keys['Mod-y'] = redo;
1209
+ }
1210
+ keys['Alt-ArrowUp'] = joinUp;
1211
+ keys['Alt-ArrowDown'] = joinDown;
1212
+ keys['Mod-BracketLeft'] = lift;
1213
+ keys['Escape'] = selectParentNode;
1214
+ let type = schema.marks.strong;
1215
+ if (type) {
1216
+ keys['Mod-b'] = toggleMark(type);
1217
+ keys['Mod-B'] = toggleMark(type);
1218
+ }
1219
+ type = schema.marks.em;
1220
+ if (type) {
1221
+ keys['Mod-i'] = toggleMark(type);
1222
+ keys['Mod-I'] = toggleMark(type);
1223
+ }
1224
+ type = schema.marks.code;
1225
+ if (type) {
1226
+ keys['Mod-`'] = toggleMark(type);
1227
+ }
1228
+ type = schema.nodes.bullet_list;
1229
+ if (type) {
1230
+ keys['Shift-Ctrl-8'] = wrapInList(type);
1231
+ }
1232
+ type = schema.nodes.ordered_list;
1233
+ if (type) {
1234
+ keys['Shift-Ctrl-9'] = wrapInList(type);
1235
+ }
1236
+ type = schema.nodes.blockquote;
1237
+ if (type) {
1238
+ keys['Ctrl->'] = wrapIn(type);
1239
+ }
1240
+ type = schema.nodes.hard_break;
1241
+ if (type) {
1242
+ const br = type;
1243
+ const cmd = chainCommands(exitCode, (state, dispatch) => {
1244
+ dispatch?.(state.tr.replaceSelectionWith(br.create()).scrollIntoView());
1245
+ return true;
1246
+ });
1247
+ keys['Mod-Enter'] = cmd;
1248
+ keys['Shift-Enter'] = cmd;
1249
+ if (isMac) {
1250
+ keys['Ctrl-Enter'] = cmd;
1251
+ }
1252
+ }
1253
+ type = schema.nodes.list_item;
1254
+ if (type) {
1255
+ keys['Enter'] = splitListItem(type);
1256
+ keys['Mod-['] = liftListItem(type);
1257
+ keys['Mod-]'] = sinkListItem(type);
1258
+ }
1259
+ type = schema.nodes.paragraph;
1260
+ if (type) {
1261
+ keys['Shift-Ctrl-0'] = setBlockType(type);
1262
+ }
1263
+ type = schema.nodes.code_block;
1264
+ if (type) {
1265
+ keys['Shift-Ctrl-\\'] = setBlockType(type);
1266
+ }
1267
+ type = schema.nodes.heading;
1268
+ if (type) {
1269
+ for (let i = 1; i <= 6; i++) {
1270
+ keys['Shift-Ctrl-' + i] = setBlockType(type, { level: i });
1271
+ }
1272
+ }
1273
+ type = schema.nodes.horizontal_rule;
1274
+ if (type) {
1275
+ const hr = type;
1276
+ keys['Mod-_'] = (state, dispatch) => {
1277
+ dispatch?.(state.tr.replaceSelectionWith(hr.create()).scrollIntoView());
1278
+ return true;
1279
+ };
1280
+ }
1281
+ return keys;
1282
+ }
1283
+
1284
+ /**
1285
+ * Prosemirror component
1286
+ *
1287
+ * Usage :
1288
+ *
1289
+ * ```html
1290
+ * <natural-editor [(ngModel)]="htmlString"></natural-editor>
1291
+ * ```
1292
+ */
1293
+ // @dynamic
1294
+ class NaturalEditorComponent {
1295
+ constructor(ngControl, document, dialog, imagePlugin) {
1296
+ this.ngControl = ngControl;
1297
+ this.document = document;
1298
+ this.dialog = dialog;
1299
+ this.imagePlugin = imagePlugin;
1300
+ this.view = null;
1301
+ this.contentChange = new EventEmitter();
1302
+ /**
1303
+ * Callback to upload an image.
1304
+ *
1305
+ * If given it will enable advanced schema, including image and tables.
1306
+ * It must be given on initialization and cannot be changed later on.
1307
+ */
1308
+ this.imageUploader = null;
1309
+ this.schema = basicSchema;
1310
+ /**
1311
+ * HTML string
1312
+ */
1313
+ this.content = '';
1314
+ this.menu = null;
1315
+ /**
1316
+ * If subscribed to, then the save button will be shown and click events forwarded
1317
+ */
1318
+ this.save = new EventEmitter();
1319
+ if (this.ngControl !== null) {
1320
+ this.ngControl.valueAccessor = this;
1321
+ }
1322
+ }
1323
+ ngOnInit() {
1324
+ this.schema = this.imageUploader ? advancedSchema : basicSchema;
1325
+ this.menu = buildMenuItems(this.schema, this.dialog);
1326
+ const serializer = DOMSerializer.fromSchema(this.schema);
1327
+ const state = this.createState();
1328
+ this.view = new EditorView(this.editor.nativeElement, {
1329
+ state: state,
1330
+ dispatchTransaction: (transaction) => {
1331
+ if (!this.view) {
1332
+ return;
1333
+ }
1334
+ const newState = this.view.state.apply(transaction);
1335
+ this.view.updateState(newState);
1336
+ // Transform doc into HTML string
1337
+ const dom = serializer.serializeFragment(this.view.state.doc);
1338
+ const el = this.document.createElement('_');
1339
+ el.appendChild(dom);
1340
+ const newContent = el.innerHTML;
1341
+ if (this.content === newContent) {
1342
+ return;
1343
+ }
1344
+ this.content = el.innerHTML;
1345
+ if (this.onChange) {
1346
+ this.onChange(this.content);
1347
+ }
1348
+ this.contentChange.emit(this.content);
1349
+ },
1350
+ });
1351
+ this.update();
1352
+ }
1353
+ writeValue(val) {
1354
+ if (typeof val === 'string' && val !== this.content) {
1355
+ this.content = val;
1356
+ }
1357
+ if (this.view !== null) {
1358
+ const state = this.createState();
1359
+ this.view.updateState(state);
1360
+ }
1361
+ }
1362
+ createState() {
1363
+ const template = this.document.createElement('_');
1364
+ template.innerHTML = '<div>' + this.content + '</div>';
1365
+ if (!template.firstChild) {
1366
+ throw new Error('child of template element could not be created');
1367
+ }
1368
+ const parser = DOMParser.fromSchema(this.schema);
1369
+ const doc = parser.parse(template.firstChild);
1370
+ return EditorState.create({
1371
+ doc: doc,
1372
+ plugins: this.createPlugins(),
1373
+ });
1374
+ }
1375
+ createPlugins() {
1376
+ const isMac = !!this.document.defaultView?.navigator.platform.match(/Mac/);
1377
+ const plugins = [
1378
+ buildInputRules(this.schema),
1379
+ keymap(buildKeymap(this.schema, isMac)),
1380
+ keymap(baseKeymap),
1381
+ dropCursor(),
1382
+ gapCursor(),
1383
+ history(),
1384
+ new Plugin({
1385
+ props: {
1386
+ attributes: { class: 'ProseMirror-example-setup-style' },
1387
+ },
1388
+ }),
1389
+ new Plugin({
1390
+ view: () => this,
1391
+ }),
1392
+ ];
1393
+ if (this.schema === advancedSchema) {
1394
+ plugins.push(this.imagePlugin.plugin, tableEditing(), keymap({
1395
+ Tab: goToNextCell(1),
1396
+ 'Shift-Tab': goToNextCell(-1),
1397
+ }));
1398
+ }
1399
+ return plugins;
1400
+ }
1401
+ /**
1402
+ * Called by Prosemirror whenever the editor state changes. So we update our menu states.
1403
+ */
1404
+ update() {
1405
+ if (!this.view || !this.menu) {
1406
+ return;
1407
+ }
1408
+ for (const item of Object.values(this.menu)) {
1409
+ item.update(this.view, this.view.state);
1410
+ }
1411
+ }
1412
+ registerOnChange(fn) {
1413
+ this.onChange = fn;
1414
+ }
1415
+ registerOnTouched(fn) { }
1416
+ setDisabledState(isDisabled) {
1417
+ // TODO disable editor ?
1418
+ }
1419
+ ngOnDestroy() {
1420
+ if (this.view) {
1421
+ this.view.destroy();
1422
+ this.view = null;
1423
+ }
1424
+ }
1425
+ run(event, key) {
1426
+ if (!this.view || !this.menu) {
1427
+ return;
1428
+ }
1429
+ const item = this.menu[key];
1430
+ if (!item || item.disabled || !item.show) {
1431
+ return;
1432
+ }
1433
+ item.spec.run(this.view.state, this.view.dispatch, this.view, event);
1434
+ this.view.focus();
1435
+ }
1436
+ upload(file) {
1437
+ if (!this.view || !this.imageUploader) {
1438
+ return;
1439
+ }
1440
+ if (this.view.state.selection.$from.parent.inlineContent) {
1441
+ this.imagePlugin.startImageUpload(this.view, file, this.imageUploader, this.schema);
1442
+ }
1443
+ this.view.focus();
1444
+ }
1445
+ }
1446
+ NaturalEditorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorComponent, deps: [{ token: i4.NgControl, optional: true, self: true }, { token: DOCUMENT }, { token: i1.MatDialog }, { token: ImagePlugin }], target: i0.ɵɵFactoryTarget.Component });
1447
+ NaturalEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.0", type: NaturalEditorComponent, selector: "natural-editor", inputs: { imageUploader: "imageUploader" }, outputs: { contentChange: "contentChange", save: "save" }, providers: [ImagePlugin], viewQueries: [{ propertyName: "editor", first: true, predicate: ["editor"], descendants: true, read: ElementRef, static: true }], ngImport: i0, template: "<div class=\"menu-container\" *ngIf=\"menu\">\n <div class=\"menu\">\n <button mat-button *ngIf=\"save.observed\" (click)=\"save.emit()\" i18n-matTooltip matTooltip=\"Enregistrer\">\n <mat-icon>save</mat-icon>\n </button>\n\n <mat-button-toggle-group multiple>\n <mat-button-toggle\n *ngIf=\"menu.toggleStrong\"\n [disabled]=\"menu.toggleStrong.disabled\"\n [checked]=\"menu.toggleStrong.active\"\n (click)=\"run($event, 'toggleStrong')\"\n i18n-matTooltip\n matTooltip=\"Gras\"\n >\n <mat-icon>format_bold</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.toggleEm\"\n [disabled]=\"menu.toggleEm.disabled\"\n [checked]=\"menu.toggleEm.active\"\n (click)=\"run($event, 'toggleEm')\"\n i18n-matTooltip\n matTooltip=\"Italique\"\n >\n <mat-icon>format_italic</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.toggleCode\"\n [disabled]=\"menu.toggleCode.disabled\"\n [checked]=\"menu.toggleCode.active\"\n (click)=\"run($event, 'toggleCode')\"\n i18n-matTooltip\n matTooltip=\"Code\"\n >\n <mat-icon>code</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.toggleLink\"\n [disabled]=\"menu.toggleLink.disabled\"\n [checked]=\"menu.toggleLink.active\"\n (click)=\"run($event, 'toggleLink')\"\n i18n-matTooltip\n matTooltip=\"Ins\u00E9rer un lien...\"\n >\n <mat-icon>insert_link</mat-icon>\n </mat-button-toggle>\n </mat-button-toggle-group>\n\n <button mat-button [matMenuTriggerFor]=\"blockMenu\">\n <span i18n>Type</span>\n <mat-icon>arrow_drop_down</mat-icon>\n </button>\n\n <mat-menu #blockMenu=\"matMenu\">\n <button\n mat-menu-item\n *ngIf=\"menu.makeParagraph\"\n [disabled]=\"menu.makeParagraph.disabled\"\n (click)=\"run($event, 'makeParagraph')\"\n i18n\n >Paragraphe\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeCodeBlock\"\n [disabled]=\"menu.makeCodeBlock.disabled\"\n (click)=\"run($event, 'makeCodeBlock')\"\n i18n\n >Code\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead1\"\n [disabled]=\"menu.makeHead1.disabled\"\n (click)=\"run($event, 'makeHead1')\"\n i18n\n >Titre 1\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead2\"\n [disabled]=\"menu.makeHead2.disabled\"\n (click)=\"run($event, 'makeHead2')\"\n i18n\n >Titre 2\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead3\"\n [disabled]=\"menu.makeHead3.disabled\"\n (click)=\"run($event, 'makeHead3')\"\n i18n\n >Titre 3\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead4\"\n [disabled]=\"menu.makeHead4.disabled\"\n (click)=\"run($event, 'makeHead4')\"\n i18n\n >Titre 4\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead5\"\n [disabled]=\"menu.makeHead5.disabled\"\n (click)=\"run($event, 'makeHead5')\"\n i18n\n >Titre 5\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead6\"\n [disabled]=\"menu.makeHead6.disabled\"\n (click)=\"run($event, 'makeHead6')\"\n i18n\n >Titre 6\n </button>\n\n <mat-divider></mat-divider>\n\n <button\n mat-menu-item\n *ngIf=\"menu.paragraphClass\"\n [disabled]=\"menu.paragraphClass.disabled\"\n (click)=\"run($event, 'paragraphClass')\"\n i18n\n >Classe...\n </button>\n </mat-menu>\n\n <button mat-button [matMenuTriggerFor]=\"tableMenu\" *ngIf=\"menu.addColumnBefore\">\n <span i18n>Tableau</span>\n <mat-icon>arrow_drop_down</mat-icon>\n </button>\n\n <mat-menu #tableMenu=\"matMenu\">\n <button\n mat-menu-item\n *ngIf=\"menu.insertTable\"\n [disabled]=\"menu.insertTable.disabled\"\n (click)=\"run($event, 'insertTable')\"\n i18n\n >Ins\u00E9rer un tableau\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.deleteTable\"\n [disabled]=\"menu.deleteTable.disabled\"\n (click)=\"run($event, 'deleteTable')\"\n i18n\n >Supprimer le tableau\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.mergeCells\"\n [disabled]=\"menu.mergeCells.disabled\"\n (click)=\"run($event, 'mergeCells')\"\n i18n\n >Fusionner les cellules\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.splitCell\"\n [disabled]=\"menu.splitCell.disabled\"\n (click)=\"run($event, 'splitCell')\"\n i18n\n >Scinder les cellules\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.cellBackgroundColor\"\n [disabled]=\"menu.cellBackgroundColor.disabled\"\n (click)=\"run($event, 'cellBackgroundColor')\"\n i18n\n >Couleur de fond...\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.tableClass\"\n [disabled]=\"menu.tableClass.disabled\"\n (click)=\"run($event, 'tableClass')\"\n i18n\n >Classe...\n </button>\n\n <mat-divider></mat-divider>\n\n <button\n mat-menu-item\n *ngIf=\"menu.addColumnBefore\"\n [disabled]=\"menu.addColumnBefore.disabled\"\n (click)=\"run($event, 'addColumnBefore')\"\n i18n\n >Ins\u00E9rer une colonne avant\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.addColumnAfter\"\n [disabled]=\"menu.addColumnAfter.disabled\"\n (click)=\"run($event, 'addColumnAfter')\"\n i18n\n >Ins\u00E9rer une colonne apr\u00E8s\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.deleteColumn\"\n [disabled]=\"menu.deleteColumn.disabled\"\n (click)=\"run($event, 'deleteColumn')\"\n i18n\n >Supprimer la colonne\n </button>\n\n <mat-divider></mat-divider>\n\n <button\n mat-menu-item\n *ngIf=\"menu.addRowBefore\"\n [disabled]=\"menu.addRowBefore.disabled\"\n (click)=\"run($event, 'addRowBefore')\"\n i18n\n >Ins\u00E9rer une ligne avant\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.addRowAfter\"\n [disabled]=\"menu.addRowAfter.disabled\"\n (click)=\"run($event, 'addRowAfter')\"\n i18n\n >Ins\u00E9rer une ligne apr\u00E8s\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.deleteRow\"\n [disabled]=\"menu.deleteRow.disabled\"\n (click)=\"run($event, 'deleteRow')\"\n i18n\n >Supprimer la ligne\n </button>\n\n <mat-divider></mat-divider>\n\n <button\n mat-menu-item\n *ngIf=\"menu.toggleHeaderColumn\"\n [disabled]=\"menu.toggleHeaderColumn.disabled\"\n (click)=\"run($event, 'toggleHeaderColumn')\"\n i18n\n >Ent\u00EAte de colonne\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.toggleHeaderRow\"\n [disabled]=\"menu.toggleHeaderRow.disabled\"\n (click)=\"run($event, 'toggleHeaderRow')\"\n i18n\n >Ent\u00EAte de ligne\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.toggleHeaderCell\"\n [disabled]=\"menu.toggleHeaderCell.disabled\"\n (click)=\"run($event, 'toggleHeaderCell')\"\n i18n\n >Ent\u00EAte de cellule\n </button>\n </mat-menu>\n\n <button\n mat-button\n *ngIf=\"imageUploader\"\n naturalFileDrop\n [selectable]=\"true\"\n [broadcast]=\"false\"\n i18n-matTooltip\n matTooltip=\"Ins\u00E9rer une image\"\n (fileChange)=\"upload($event)\"\n >\n <mat-icon>insert_photo</mat-icon>\n </button>\n\n <mat-button-toggle-group *ngIf=\"menu.alignLeft\">\n <mat-button-toggle\n *ngIf=\"menu.alignLeft\"\n [disabled]=\"menu.alignLeft.disabled\"\n [checked]=\"menu.alignLeft.active\"\n (click)=\"run($event, 'alignLeft')\"\n i18n-matTooltip\n matTooltip=\"Aligner gauche\"\n >\n <mat-icon>format_align_left</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.alignCenter\"\n [disabled]=\"menu.alignCenter.disabled\"\n [checked]=\"menu.alignCenter.active\"\n (click)=\"run($event, 'alignCenter')\"\n i18n-matTooltip\n matTooltip=\"Centrer\"\n >\n <mat-icon>format_align_center</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.alignRight\"\n [disabled]=\"menu.alignRight.disabled\"\n [checked]=\"menu.alignRight.active\"\n (click)=\"run($event, 'alignRight')\"\n i18n-matTooltip\n matTooltip=\"Aligner droite\"\n >\n <mat-icon>format_align_right</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.alignJustify\"\n [disabled]=\"menu.alignJustify.disabled\"\n [checked]=\"menu.alignJustify.active\"\n (click)=\"run($event, 'alignJustify')\"\n i18n-matTooltip\n matTooltip=\"Justifier\"\n >\n <mat-icon>format_align_justify</mat-icon>\n </mat-button-toggle>\n </mat-button-toggle-group>\n\n <button\n mat-button\n *ngIf=\"menu.undo\"\n [disabled]=\"menu.undo.disabled\"\n (click)=\"run($event, 'undo')\"\n i18n-matTooltip\n matTooltip=\"Annuler\"\n >\n <mat-icon>undo</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.redo\"\n [disabled]=\"menu.redo.disabled\"\n (click)=\"run($event, 'redo')\"\n i18n-matTooltip\n matTooltip=\"Refaire\"\n >\n <mat-icon>redo</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.wrapBulletList && menu.wrapBulletList.show\"\n [disabled]=\"menu.wrapBulletList.disabled\"\n (click)=\"run($event, 'wrapBulletList')\"\n i18n-matTooltip\n matTooltip=\"Liste \u00E0 puce\"\n >\n <mat-icon>format_list_bulleted</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.wrapOrderedList && menu.wrapOrderedList.show\"\n [disabled]=\"menu.wrapOrderedList.disabled\"\n (click)=\"run($event, 'wrapOrderedList')\"\n i18n-matTooltip\n matTooltip=\"Liste \u00E0 num\u00E9ro\"\n >\n <mat-icon>format_list_numbered</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.wrapBlockQuote && menu.wrapBlockQuote.show\"\n [disabled]=\"menu.wrapBlockQuote.disabled\"\n (click)=\"run($event, 'wrapBlockQuote')\"\n i18n-matTooltip\n matTooltip=\"Citation\"\n >\n <mat-icon>format_quote</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.joinUp && menu.joinUp.show\"\n [disabled]=\"menu.joinUp.disabled\"\n (click)=\"run($event, 'joinUp')\"\n i18n-matTooltip\n matTooltip=\"Fusionner avec l'\u00E9l\u00E9ment du haut\"\n >\n <mat-icon>move_up</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.lift && menu.lift.show\"\n [disabled]=\"menu.lift.disabled\"\n (click)=\"run($event, 'lift')\"\n i18n-matTooltip\n matTooltip=\"D\u00E9sindenter\"\n >\n <mat-icon>format_indent_decrease</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.selectParentNode && menu.selectParentNode.show\"\n [disabled]=\"menu.selectParentNode.disabled\"\n (click)=\"run($event, 'selectParentNode')\"\n i18n-matTooltip\n matTooltip=\"S\u00E9lectionner l'\u00E9l\u00E9ment parent\"\n >\n <mat-icon>select_all</mat-icon>\n </button>\n </div>\n</div>\n<div #editor></div>\n", styles: [".menu{border-bottom:1px solid;display:flex;flex-wrap:wrap;padding:10px 18px}.menu-container{position:sticky;top:-20px;z-index:999}::ng-deep .ProseMirror{position:relative}::ng-deep .ProseMirror{word-wrap:break-word;white-space:pre-wrap;-webkit-font-variant-ligatures:none;font-feature-settings:none;font-variant-ligatures:none}::ng-deep .ProseMirror pre{white-space:pre-wrap}::ng-deep .ProseMirror li{position:relative}::ng-deep .ProseMirror-hideselection *::selection{background:transparent}::ng-deep .ProseMirror-hideselection *::-moz-selection{background:transparent}::ng-deep .ProseMirror-hideselection{caret-color:transparent}::ng-deep .ProseMirror-selectednode{outline:2px solid #8cf}::ng-deep li.ProseMirror-selectednode{outline:none}::ng-deep li.ProseMirror-selectednode:after{content:\"\";position:absolute;left:-32px;right:-2px;top:-2px;bottom:-2px;border:2px solid #8cf;pointer-events:none}::ng-deep .ProseMirror-gapcursor{display:none;pointer-events:none;position:absolute}::ng-deep .ProseMirror-gapcursor:after{content:\"\";display:block;position:absolute;top:-2px;width:20px;border-top:1px solid black;animation:ProseMirror-cursor-blink 1.1s steps(2,start) infinite}@keyframes ProseMirror-cursor-blink{to{visibility:hidden}}::ng-deep .ProseMirror-focused .ProseMirror-gapcursor{display:block}::ng-deep .ProseMirror-example-setup-style hr{padding:2px 10px;border:none;margin:1em 0}::ng-deep .ProseMirror-example-setup-style hr:after{content:\"\";display:block;height:1px;background-color:silver;line-height:2px}::ng-deep .ProseMirror ul,::ng-deep .ProseMirror ol{padding-left:30px}::ng-deep .ProseMirror blockquote{padding-left:1em;border-left:3px solid #eee;margin-left:0;margin-right:0}::ng-deep .ProseMirror-example-setup-style img{cursor:default}::ng-deep .ProseMirror p:first-child,::ng-deep .ProseMirror h1:first-child,::ng-deep .ProseMirror h2:first-child,::ng-deep .ProseMirror h3:first-child,::ng-deep .ProseMirror h4:first-child,::ng-deep .ProseMirror h5:first-child,::ng-deep .ProseMirror h6:first-child{margin-top:10px}::ng-deep .ProseMirror{padding:4px 8px 4px 14px;line-height:1.2;outline:none}::ng-deep .ProseMirror p{margin-bottom:1em}::ng-deep .ProseMirror .tableWrapper{overflow-x:auto}::ng-deep .ProseMirror table{border-collapse:collapse;table-layout:fixed;width:100%;overflow:hidden}::ng-deep .ProseMirror td,::ng-deep .ProseMirror th{vertical-align:top;box-sizing:border-box;position:relative}::ng-deep .ProseMirror .column-resize-handle{position:absolute;right:-2px;top:0;bottom:0;width:4px;z-index:20;background-color:#adf;pointer-events:none}::ng-deep .ProseMirror.resize-cursor{cursor:col-resize}::ng-deep .ProseMirror .selectedCell:after{z-index:2;position:absolute;content:\"\";left:0;right:0;top:0;bottom:0;background:rgba(200,200,255,.4);pointer-events:none}::ng-deep .ProseMirror table{margin:0}::ng-deep .ProseMirror th,::ng-deep .ProseMirror td{min-width:1em;border:1px solid #ddd;padding:3px 5px}::ng-deep .ProseMirror .tableWrapper{margin:1em 0}::ng-deep .ProseMirror th{font-weight:700;text-align:left}::ng-deep placeholder{display:block;width:50px;height:50px;background-size:500% 100%!important;animation:gradient 3s none infinite}@keyframes gradient{0%{background-position:100% 100%}to{background-position:0 0}}\n"], components: [{ type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { type: i5$1.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { type: i6$1.MatButtonToggle, selector: "mat-button-toggle", inputs: ["disableRipple", "aria-label", "aria-labelledby", "id", "name", "value", "tabIndex", "appearance", "checked", "disabled"], outputs: ["change"], exportAs: ["matButtonToggle"] }, { type: i7.MatMenu, selector: "mat-menu", exportAs: ["matMenu"] }, { type: i7.MatMenuItem, selector: "[mat-menu-item]", inputs: ["disabled", "disableRipple", "role"], exportAs: ["matMenuItem"] }, { type: i8.MatDivider, selector: "mat-divider", inputs: ["vertical", "inset"] }], directives: [{ type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i10.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { type: i6$1.MatButtonToggleGroup, selector: "mat-button-toggle-group", inputs: ["appearance", "name", "vertical", "value", "multiple", "disabled"], outputs: ["valueChange", "change"], exportAs: ["matButtonToggleGroup"] }, { type: i7.MatMenuTrigger, selector: "[mat-menu-trigger-for], [matMenuTriggerFor]", exportAs: ["matMenuTrigger"] }, { type: i3$1.NaturalFileDropDirective, selector: ":not([naturalFileSelect])[naturalFileDrop]", outputs: ["fileOver"] }] });
1448
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorComponent, decorators: [{
1449
+ type: Component,
1450
+ args: [{ selector: 'natural-editor', providers: [ImagePlugin], template: "<div class=\"menu-container\" *ngIf=\"menu\">\n <div class=\"menu\">\n <button mat-button *ngIf=\"save.observed\" (click)=\"save.emit()\" i18n-matTooltip matTooltip=\"Enregistrer\">\n <mat-icon>save</mat-icon>\n </button>\n\n <mat-button-toggle-group multiple>\n <mat-button-toggle\n *ngIf=\"menu.toggleStrong\"\n [disabled]=\"menu.toggleStrong.disabled\"\n [checked]=\"menu.toggleStrong.active\"\n (click)=\"run($event, 'toggleStrong')\"\n i18n-matTooltip\n matTooltip=\"Gras\"\n >\n <mat-icon>format_bold</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.toggleEm\"\n [disabled]=\"menu.toggleEm.disabled\"\n [checked]=\"menu.toggleEm.active\"\n (click)=\"run($event, 'toggleEm')\"\n i18n-matTooltip\n matTooltip=\"Italique\"\n >\n <mat-icon>format_italic</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.toggleCode\"\n [disabled]=\"menu.toggleCode.disabled\"\n [checked]=\"menu.toggleCode.active\"\n (click)=\"run($event, 'toggleCode')\"\n i18n-matTooltip\n matTooltip=\"Code\"\n >\n <mat-icon>code</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.toggleLink\"\n [disabled]=\"menu.toggleLink.disabled\"\n [checked]=\"menu.toggleLink.active\"\n (click)=\"run($event, 'toggleLink')\"\n i18n-matTooltip\n matTooltip=\"Ins\u00E9rer un lien...\"\n >\n <mat-icon>insert_link</mat-icon>\n </mat-button-toggle>\n </mat-button-toggle-group>\n\n <button mat-button [matMenuTriggerFor]=\"blockMenu\">\n <span i18n>Type</span>\n <mat-icon>arrow_drop_down</mat-icon>\n </button>\n\n <mat-menu #blockMenu=\"matMenu\">\n <button\n mat-menu-item\n *ngIf=\"menu.makeParagraph\"\n [disabled]=\"menu.makeParagraph.disabled\"\n (click)=\"run($event, 'makeParagraph')\"\n i18n\n >Paragraphe\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeCodeBlock\"\n [disabled]=\"menu.makeCodeBlock.disabled\"\n (click)=\"run($event, 'makeCodeBlock')\"\n i18n\n >Code\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead1\"\n [disabled]=\"menu.makeHead1.disabled\"\n (click)=\"run($event, 'makeHead1')\"\n i18n\n >Titre 1\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead2\"\n [disabled]=\"menu.makeHead2.disabled\"\n (click)=\"run($event, 'makeHead2')\"\n i18n\n >Titre 2\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead3\"\n [disabled]=\"menu.makeHead3.disabled\"\n (click)=\"run($event, 'makeHead3')\"\n i18n\n >Titre 3\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead4\"\n [disabled]=\"menu.makeHead4.disabled\"\n (click)=\"run($event, 'makeHead4')\"\n i18n\n >Titre 4\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead5\"\n [disabled]=\"menu.makeHead5.disabled\"\n (click)=\"run($event, 'makeHead5')\"\n i18n\n >Titre 5\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.makeHead6\"\n [disabled]=\"menu.makeHead6.disabled\"\n (click)=\"run($event, 'makeHead6')\"\n i18n\n >Titre 6\n </button>\n\n <mat-divider></mat-divider>\n\n <button\n mat-menu-item\n *ngIf=\"menu.paragraphClass\"\n [disabled]=\"menu.paragraphClass.disabled\"\n (click)=\"run($event, 'paragraphClass')\"\n i18n\n >Classe...\n </button>\n </mat-menu>\n\n <button mat-button [matMenuTriggerFor]=\"tableMenu\" *ngIf=\"menu.addColumnBefore\">\n <span i18n>Tableau</span>\n <mat-icon>arrow_drop_down</mat-icon>\n </button>\n\n <mat-menu #tableMenu=\"matMenu\">\n <button\n mat-menu-item\n *ngIf=\"menu.insertTable\"\n [disabled]=\"menu.insertTable.disabled\"\n (click)=\"run($event, 'insertTable')\"\n i18n\n >Ins\u00E9rer un tableau\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.deleteTable\"\n [disabled]=\"menu.deleteTable.disabled\"\n (click)=\"run($event, 'deleteTable')\"\n i18n\n >Supprimer le tableau\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.mergeCells\"\n [disabled]=\"menu.mergeCells.disabled\"\n (click)=\"run($event, 'mergeCells')\"\n i18n\n >Fusionner les cellules\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.splitCell\"\n [disabled]=\"menu.splitCell.disabled\"\n (click)=\"run($event, 'splitCell')\"\n i18n\n >Scinder les cellules\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.cellBackgroundColor\"\n [disabled]=\"menu.cellBackgroundColor.disabled\"\n (click)=\"run($event, 'cellBackgroundColor')\"\n i18n\n >Couleur de fond...\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.tableClass\"\n [disabled]=\"menu.tableClass.disabled\"\n (click)=\"run($event, 'tableClass')\"\n i18n\n >Classe...\n </button>\n\n <mat-divider></mat-divider>\n\n <button\n mat-menu-item\n *ngIf=\"menu.addColumnBefore\"\n [disabled]=\"menu.addColumnBefore.disabled\"\n (click)=\"run($event, 'addColumnBefore')\"\n i18n\n >Ins\u00E9rer une colonne avant\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.addColumnAfter\"\n [disabled]=\"menu.addColumnAfter.disabled\"\n (click)=\"run($event, 'addColumnAfter')\"\n i18n\n >Ins\u00E9rer une colonne apr\u00E8s\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.deleteColumn\"\n [disabled]=\"menu.deleteColumn.disabled\"\n (click)=\"run($event, 'deleteColumn')\"\n i18n\n >Supprimer la colonne\n </button>\n\n <mat-divider></mat-divider>\n\n <button\n mat-menu-item\n *ngIf=\"menu.addRowBefore\"\n [disabled]=\"menu.addRowBefore.disabled\"\n (click)=\"run($event, 'addRowBefore')\"\n i18n\n >Ins\u00E9rer une ligne avant\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.addRowAfter\"\n [disabled]=\"menu.addRowAfter.disabled\"\n (click)=\"run($event, 'addRowAfter')\"\n i18n\n >Ins\u00E9rer une ligne apr\u00E8s\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.deleteRow\"\n [disabled]=\"menu.deleteRow.disabled\"\n (click)=\"run($event, 'deleteRow')\"\n i18n\n >Supprimer la ligne\n </button>\n\n <mat-divider></mat-divider>\n\n <button\n mat-menu-item\n *ngIf=\"menu.toggleHeaderColumn\"\n [disabled]=\"menu.toggleHeaderColumn.disabled\"\n (click)=\"run($event, 'toggleHeaderColumn')\"\n i18n\n >Ent\u00EAte de colonne\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.toggleHeaderRow\"\n [disabled]=\"menu.toggleHeaderRow.disabled\"\n (click)=\"run($event, 'toggleHeaderRow')\"\n i18n\n >Ent\u00EAte de ligne\n </button>\n <button\n mat-menu-item\n *ngIf=\"menu.toggleHeaderCell\"\n [disabled]=\"menu.toggleHeaderCell.disabled\"\n (click)=\"run($event, 'toggleHeaderCell')\"\n i18n\n >Ent\u00EAte de cellule\n </button>\n </mat-menu>\n\n <button\n mat-button\n *ngIf=\"imageUploader\"\n naturalFileDrop\n [selectable]=\"true\"\n [broadcast]=\"false\"\n i18n-matTooltip\n matTooltip=\"Ins\u00E9rer une image\"\n (fileChange)=\"upload($event)\"\n >\n <mat-icon>insert_photo</mat-icon>\n </button>\n\n <mat-button-toggle-group *ngIf=\"menu.alignLeft\">\n <mat-button-toggle\n *ngIf=\"menu.alignLeft\"\n [disabled]=\"menu.alignLeft.disabled\"\n [checked]=\"menu.alignLeft.active\"\n (click)=\"run($event, 'alignLeft')\"\n i18n-matTooltip\n matTooltip=\"Aligner gauche\"\n >\n <mat-icon>format_align_left</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.alignCenter\"\n [disabled]=\"menu.alignCenter.disabled\"\n [checked]=\"menu.alignCenter.active\"\n (click)=\"run($event, 'alignCenter')\"\n i18n-matTooltip\n matTooltip=\"Centrer\"\n >\n <mat-icon>format_align_center</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.alignRight\"\n [disabled]=\"menu.alignRight.disabled\"\n [checked]=\"menu.alignRight.active\"\n (click)=\"run($event, 'alignRight')\"\n i18n-matTooltip\n matTooltip=\"Aligner droite\"\n >\n <mat-icon>format_align_right</mat-icon>\n </mat-button-toggle>\n\n <mat-button-toggle\n *ngIf=\"menu.alignJustify\"\n [disabled]=\"menu.alignJustify.disabled\"\n [checked]=\"menu.alignJustify.active\"\n (click)=\"run($event, 'alignJustify')\"\n i18n-matTooltip\n matTooltip=\"Justifier\"\n >\n <mat-icon>format_align_justify</mat-icon>\n </mat-button-toggle>\n </mat-button-toggle-group>\n\n <button\n mat-button\n *ngIf=\"menu.undo\"\n [disabled]=\"menu.undo.disabled\"\n (click)=\"run($event, 'undo')\"\n i18n-matTooltip\n matTooltip=\"Annuler\"\n >\n <mat-icon>undo</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.redo\"\n [disabled]=\"menu.redo.disabled\"\n (click)=\"run($event, 'redo')\"\n i18n-matTooltip\n matTooltip=\"Refaire\"\n >\n <mat-icon>redo</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.wrapBulletList && menu.wrapBulletList.show\"\n [disabled]=\"menu.wrapBulletList.disabled\"\n (click)=\"run($event, 'wrapBulletList')\"\n i18n-matTooltip\n matTooltip=\"Liste \u00E0 puce\"\n >\n <mat-icon>format_list_bulleted</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.wrapOrderedList && menu.wrapOrderedList.show\"\n [disabled]=\"menu.wrapOrderedList.disabled\"\n (click)=\"run($event, 'wrapOrderedList')\"\n i18n-matTooltip\n matTooltip=\"Liste \u00E0 num\u00E9ro\"\n >\n <mat-icon>format_list_numbered</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.wrapBlockQuote && menu.wrapBlockQuote.show\"\n [disabled]=\"menu.wrapBlockQuote.disabled\"\n (click)=\"run($event, 'wrapBlockQuote')\"\n i18n-matTooltip\n matTooltip=\"Citation\"\n >\n <mat-icon>format_quote</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.joinUp && menu.joinUp.show\"\n [disabled]=\"menu.joinUp.disabled\"\n (click)=\"run($event, 'joinUp')\"\n i18n-matTooltip\n matTooltip=\"Fusionner avec l'\u00E9l\u00E9ment du haut\"\n >\n <mat-icon>move_up</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.lift && menu.lift.show\"\n [disabled]=\"menu.lift.disabled\"\n (click)=\"run($event, 'lift')\"\n i18n-matTooltip\n matTooltip=\"D\u00E9sindenter\"\n >\n <mat-icon>format_indent_decrease</mat-icon>\n </button>\n\n <button\n mat-button\n *ngIf=\"menu.selectParentNode && menu.selectParentNode.show\"\n [disabled]=\"menu.selectParentNode.disabled\"\n (click)=\"run($event, 'selectParentNode')\"\n i18n-matTooltip\n matTooltip=\"S\u00E9lectionner l'\u00E9l\u00E9ment parent\"\n >\n <mat-icon>select_all</mat-icon>\n </button>\n </div>\n</div>\n<div #editor></div>\n", styles: [".menu{border-bottom:1px solid;display:flex;flex-wrap:wrap;padding:10px 18px}.menu-container{position:sticky;top:-20px;z-index:999}::ng-deep .ProseMirror{position:relative}::ng-deep .ProseMirror{word-wrap:break-word;white-space:pre-wrap;-webkit-font-variant-ligatures:none;font-feature-settings:none;font-variant-ligatures:none}::ng-deep .ProseMirror pre{white-space:pre-wrap}::ng-deep .ProseMirror li{position:relative}::ng-deep .ProseMirror-hideselection *::selection{background:transparent}::ng-deep .ProseMirror-hideselection *::-moz-selection{background:transparent}::ng-deep .ProseMirror-hideselection{caret-color:transparent}::ng-deep .ProseMirror-selectednode{outline:2px solid #8cf}::ng-deep li.ProseMirror-selectednode{outline:none}::ng-deep li.ProseMirror-selectednode:after{content:\"\";position:absolute;left:-32px;right:-2px;top:-2px;bottom:-2px;border:2px solid #8cf;pointer-events:none}::ng-deep .ProseMirror-gapcursor{display:none;pointer-events:none;position:absolute}::ng-deep .ProseMirror-gapcursor:after{content:\"\";display:block;position:absolute;top:-2px;width:20px;border-top:1px solid black;animation:ProseMirror-cursor-blink 1.1s steps(2,start) infinite}@keyframes ProseMirror-cursor-blink{to{visibility:hidden}}::ng-deep .ProseMirror-focused .ProseMirror-gapcursor{display:block}::ng-deep .ProseMirror-example-setup-style hr{padding:2px 10px;border:none;margin:1em 0}::ng-deep .ProseMirror-example-setup-style hr:after{content:\"\";display:block;height:1px;background-color:silver;line-height:2px}::ng-deep .ProseMirror ul,::ng-deep .ProseMirror ol{padding-left:30px}::ng-deep .ProseMirror blockquote{padding-left:1em;border-left:3px solid #eee;margin-left:0;margin-right:0}::ng-deep .ProseMirror-example-setup-style img{cursor:default}::ng-deep .ProseMirror p:first-child,::ng-deep .ProseMirror h1:first-child,::ng-deep .ProseMirror h2:first-child,::ng-deep .ProseMirror h3:first-child,::ng-deep .ProseMirror h4:first-child,::ng-deep .ProseMirror h5:first-child,::ng-deep .ProseMirror h6:first-child{margin-top:10px}::ng-deep .ProseMirror{padding:4px 8px 4px 14px;line-height:1.2;outline:none}::ng-deep .ProseMirror p{margin-bottom:1em}::ng-deep .ProseMirror .tableWrapper{overflow-x:auto}::ng-deep .ProseMirror table{border-collapse:collapse;table-layout:fixed;width:100%;overflow:hidden}::ng-deep .ProseMirror td,::ng-deep .ProseMirror th{vertical-align:top;box-sizing:border-box;position:relative}::ng-deep .ProseMirror .column-resize-handle{position:absolute;right:-2px;top:0;bottom:0;width:4px;z-index:20;background-color:#adf;pointer-events:none}::ng-deep .ProseMirror.resize-cursor{cursor:col-resize}::ng-deep .ProseMirror .selectedCell:after{z-index:2;position:absolute;content:\"\";left:0;right:0;top:0;bottom:0;background:rgba(200,200,255,.4);pointer-events:none}::ng-deep .ProseMirror table{margin:0}::ng-deep .ProseMirror th,::ng-deep .ProseMirror td{min-width:1em;border:1px solid #ddd;padding:3px 5px}::ng-deep .ProseMirror .tableWrapper{margin:1em 0}::ng-deep .ProseMirror th{font-weight:700;text-align:left}::ng-deep placeholder{display:block;width:50px;height:50px;background-size:500% 100%!important;animation:gradient 3s none infinite}@keyframes gradient{0%{background-position:100% 100%}to{background-position:0 0}}\n"] }]
1451
+ }], ctorParameters: function () { return [{ type: i4.NgControl, decorators: [{
1452
+ type: Optional
1453
+ }, {
1454
+ type: Self
1455
+ }] }, { type: Document, decorators: [{
1456
+ type: Inject,
1457
+ args: [DOCUMENT]
1458
+ }] }, { type: i1.MatDialog }, { type: ImagePlugin }]; }, propDecorators: { editor: [{
1459
+ type: ViewChild,
1460
+ args: ['editor', { read: ElementRef, static: true }]
1461
+ }], contentChange: [{
1462
+ type: Output
1463
+ }], imageUploader: [{
1464
+ type: Input
1465
+ }], save: [{
1466
+ type: Output
1467
+ }] } });
1468
+
1469
+ const imports = [
1470
+ CommonModule,
1471
+ MatButtonModule,
1472
+ MatButtonToggleModule,
1473
+ MatDialogModule,
1474
+ MatDividerModule,
1475
+ MatFormFieldModule,
1476
+ MatIconModule,
1477
+ MatInputModule,
1478
+ MatMenuModule,
1479
+ MatToolbarModule,
1480
+ MatTooltipModule,
1481
+ NaturalFileModule,
1482
+ NaturalIconModule,
1483
+ ReactiveFormsModule,
1484
+ ];
1485
+ const declarationsToExport = [NaturalEditorComponent, NaturalCustomCssDirective];
1486
+ class NaturalEditorModule {
1487
+ }
1488
+ NaturalEditorModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1489
+ NaturalEditorModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorModule, declarations: [ClassDialogComponent, ColorDialogComponent, LinkDialogComponent, NaturalEditorComponent, NaturalCustomCssDirective], imports: [CommonModule,
1490
+ MatButtonModule,
1491
+ MatButtonToggleModule,
1492
+ MatDialogModule,
1493
+ MatDividerModule,
1494
+ MatFormFieldModule,
1495
+ MatIconModule,
1496
+ MatInputModule,
1497
+ MatMenuModule,
1498
+ MatToolbarModule,
1499
+ MatTooltipModule,
1500
+ NaturalFileModule,
1501
+ NaturalIconModule,
1502
+ ReactiveFormsModule], exports: [CommonModule,
1503
+ MatButtonModule,
1504
+ MatButtonToggleModule,
1505
+ MatDialogModule,
1506
+ MatDividerModule,
1507
+ MatFormFieldModule,
1508
+ MatIconModule,
1509
+ MatInputModule,
1510
+ MatMenuModule,
1511
+ MatToolbarModule,
1512
+ MatTooltipModule,
1513
+ NaturalFileModule,
1514
+ NaturalIconModule,
1515
+ ReactiveFormsModule, NaturalEditorComponent, NaturalCustomCssDirective] });
1516
+ NaturalEditorModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorModule, imports: [[...imports], CommonModule,
1517
+ MatButtonModule,
1518
+ MatButtonToggleModule,
1519
+ MatDialogModule,
1520
+ MatDividerModule,
1521
+ MatFormFieldModule,
1522
+ MatIconModule,
1523
+ MatInputModule,
1524
+ MatMenuModule,
1525
+ MatToolbarModule,
1526
+ MatTooltipModule,
1527
+ NaturalFileModule,
1528
+ NaturalIconModule,
1529
+ ReactiveFormsModule] });
1530
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorModule, decorators: [{
1531
+ type: NgModule,
1532
+ args: [{
1533
+ declarations: [ClassDialogComponent, ColorDialogComponent, LinkDialogComponent, ...declarationsToExport],
1534
+ imports: [...imports],
1535
+ exports: [...imports, ...declarationsToExport],
1536
+ }]
1537
+ }] });
1538
+
1539
+ // Load `$localize` onto the global scope - to be able to use that function to translate strings in components/services.
1540
+
1541
+ /**
1542
+ * Generated bundle index. Do not edit.
1543
+ */
1544
+
1545
+ export { NaturalCustomCssDirective, NaturalEditorComponent, NaturalEditorModule };
1546
+ //# sourceMappingURL=ecodev-natural-editor.mjs.map