@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.
- package/{esm2015/ecodev-natural-editor.js → esm2020/ecodev-natural-editor.mjs} +0 -0
- package/esm2020/lib/class-dialog/class-dialog.component.mjs +37 -0
- package/esm2020/lib/color-dialog/color-dialog.component.mjs +184 -0
- package/esm2020/lib/custom-css/custom-css.directive.mjs +71 -0
- package/esm2020/lib/editor/editor.component.mjs +213 -0
- package/esm2020/lib/editor.module.mjs +90 -0
- package/{esm2015/lib/link-dialog/link-dialog.component.js → esm2020/lib/link-dialog/link-dialog.component.mjs} +5 -8
- package/esm2020/lib/utils/image.mjs +81 -0
- package/{esm2015/lib/utils/inputrules.js → esm2020/lib/utils/inputrules.mjs} +0 -0
- package/esm2020/lib/utils/items/cell-background-color-item.mjs +55 -0
- package/esm2020/lib/utils/items/class-item.mjs +86 -0
- package/esm2020/lib/utils/items/horizontal-rule-item.mjs +24 -0
- package/esm2020/lib/utils/items/item.mjs +39 -0
- package/esm2020/lib/utils/items/link-item.mjs +40 -0
- package/esm2020/lib/utils/items/table-item.mjs +43 -0
- package/esm2020/lib/utils/items/text-align-item.mjs +78 -0
- package/esm2020/lib/utils/items/utils.mjs +41 -0
- package/esm2020/lib/utils/items/wrap-list-item.mjs +6 -0
- package/esm2020/lib/utils/keymap.mjs +115 -0
- package/esm2020/lib/utils/menu.mjs +101 -0
- package/esm2020/lib/utils/schema/paragraph-with-alignment.mjs +50 -0
- package/esm2020/lib/utils/schema/schema.mjs +51 -0
- package/esm2020/lib/utils/schema/table.mjs +113 -0
- package/esm2020/public-api.mjs +9 -0
- package/fesm2015/ecodev-natural-editor.mjs +1548 -0
- package/fesm2015/ecodev-natural-editor.mjs.map +1 -0
- package/fesm2020/ecodev-natural-editor.mjs +1546 -0
- package/fesm2020/ecodev-natural-editor.mjs.map +1 -0
- package/lib/class-dialog/class-dialog.component.d.ts +24 -0
- package/lib/color-dialog/color-dialog.component.d.ts +26 -0
- package/lib/custom-css/custom-css.directive.d.ts +29 -0
- package/lib/editor.module.d.ts +19 -16
- package/lib/utils/items/cell-background-color-item.d.ts +5 -0
- package/lib/utils/items/class-item.d.ts +6 -0
- package/lib/utils/items/horizontal-rule-item.d.ts +5 -0
- package/lib/utils/{item.d.ts → items/item.d.ts} +0 -0
- package/lib/utils/items/link-item.d.ts +6 -0
- package/lib/utils/items/table-item.d.ts +4 -0
- package/lib/utils/{text-align-item.d.ts → items/text-align-item.d.ts} +0 -0
- package/lib/utils/items/utils.d.ts +18 -0
- package/lib/utils/items/wrap-list-item.d.ts +3 -0
- package/lib/utils/menu.d.ts +2 -2
- package/lib/utils/schema/paragraph-with-alignment.d.ts +8 -0
- package/lib/utils/{schema.d.ts → schema/schema.d.ts} +0 -0
- package/lib/utils/schema/table.d.ts +9 -0
- package/package.json +22 -8
- package/public-api.d.ts +1 -0
- package/src/lib/editor/_editor.theme.scss +1 -1
- package/theming/_natural-editor.theme.scss +1 -1
- package/bundles/ecodev-natural-editor.umd.js +0 -1351
- package/bundles/ecodev-natural-editor.umd.js.map +0 -1
- package/esm2015/lib/editor/editor.component.js +0 -219
- package/esm2015/lib/editor.module.js +0 -82
- package/esm2015/lib/utils/image.js +0 -81
- package/esm2015/lib/utils/item.js +0 -39
- package/esm2015/lib/utils/keymap.js +0 -115
- package/esm2015/lib/utils/menu.js +0 -178
- package/esm2015/lib/utils/paragraph-with-alignment.js +0 -43
- package/esm2015/lib/utils/schema.js +0 -47
- package/esm2015/lib/utils/table.js +0 -37
- package/esm2015/lib/utils/text-align-item.js +0 -78
- package/esm2015/public-api.js +0 -8
- package/fesm2015/ecodev-natural-editor.js +0 -997
- package/fesm2015/ecodev-natural-editor.js.map +0 -1
- package/lib/utils/paragraph-with-alignment.d.ts +0 -2
- package/lib/utils/table.d.ts +0 -8
|
@@ -0,0 +1,1548 @@
|
|
|
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
|
+
var _a;
|
|
87
|
+
(_a = this.style) === null || _a === void 0 ? void 0 : _a.remove();
|
|
88
|
+
// Reset uniqueId if we have no component alive anymore, so that we never reach max int
|
|
89
|
+
componentCount--;
|
|
90
|
+
if (componentCount <= 0) {
|
|
91
|
+
uniqueId = 0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
NaturalCustomCssDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalCustomCssDirective, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Directive });
|
|
96
|
+
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 });
|
|
97
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalCustomCssDirective, decorators: [{
|
|
98
|
+
type: Directive,
|
|
99
|
+
args: [{
|
|
100
|
+
selector: '[naturalCustomCss]',
|
|
101
|
+
}]
|
|
102
|
+
}], ctorParameters: function () {
|
|
103
|
+
return [{ type: Document, decorators: [{
|
|
104
|
+
type: Inject,
|
|
105
|
+
args: [DOCUMENT]
|
|
106
|
+
}] }];
|
|
107
|
+
}, propDecorators: { id: [{
|
|
108
|
+
type: HostBinding,
|
|
109
|
+
args: ['attr.data-natural-id']
|
|
110
|
+
}], naturalCustomCss: [{
|
|
111
|
+
type: Input
|
|
112
|
+
}] } });
|
|
113
|
+
|
|
114
|
+
class ImagePlugin {
|
|
115
|
+
constructor(document) {
|
|
116
|
+
this.document = document;
|
|
117
|
+
this.plugin = new Plugin({
|
|
118
|
+
state: {
|
|
119
|
+
init() {
|
|
120
|
+
return DecorationSet.empty;
|
|
121
|
+
},
|
|
122
|
+
apply(tr, set) {
|
|
123
|
+
// Adjust decoration positions to changes made by the transaction
|
|
124
|
+
set = set.map(tr.mapping, tr.doc);
|
|
125
|
+
// See if the transaction adds or removes any placeholders
|
|
126
|
+
const action = tr.getMeta(this);
|
|
127
|
+
if (action && action.add) {
|
|
128
|
+
const widget = document.createElement('placeholder');
|
|
129
|
+
const deco = Decoration.widget(action.add.pos, widget, { id: action.add.id });
|
|
130
|
+
set = set.add(tr.doc, [deco]);
|
|
131
|
+
}
|
|
132
|
+
else if (action && action.remove) {
|
|
133
|
+
set = set.remove(set.find(undefined, undefined, spec => spec.id === action.remove.id));
|
|
134
|
+
}
|
|
135
|
+
return set;
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
props: {
|
|
139
|
+
decorations(state) {
|
|
140
|
+
return this.getState(state);
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
findPlaceholder(state, id) {
|
|
146
|
+
const decorators = this.plugin.getState(state);
|
|
147
|
+
const found = decorators.find(undefined, undefined, spec => spec.id === id);
|
|
148
|
+
return found.length ? found[0].from : null;
|
|
149
|
+
}
|
|
150
|
+
startImageUpload(view, file, uploader, schema) {
|
|
151
|
+
// A fresh object to act as the ID for this upload
|
|
152
|
+
const id = {};
|
|
153
|
+
// Replace the selection with a placeholder
|
|
154
|
+
const tr = view.state.tr;
|
|
155
|
+
if (!tr.selection.empty) {
|
|
156
|
+
tr.deleteSelection();
|
|
157
|
+
}
|
|
158
|
+
tr.setMeta(this.plugin, { add: { id, pos: tr.selection.from } });
|
|
159
|
+
view.dispatch(tr);
|
|
160
|
+
uploader(file).subscribe({
|
|
161
|
+
next: url => {
|
|
162
|
+
const pos = this.findPlaceholder(view.state, id);
|
|
163
|
+
// If the content around the placeholder has been deleted, drop
|
|
164
|
+
// the image
|
|
165
|
+
if (pos === null) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// Otherwise, insert it at the placeholder's position, and remove
|
|
169
|
+
// the placeholder
|
|
170
|
+
view.dispatch(view.state.tr
|
|
171
|
+
.replaceWith(pos, pos, schema.nodes.image.create({ src: url }))
|
|
172
|
+
.setMeta(this.plugin, { remove: { id } }));
|
|
173
|
+
},
|
|
174
|
+
error: () => {
|
|
175
|
+
// On failure, just clean up the placeholder
|
|
176
|
+
view === null || view === void 0 ? void 0 : view.dispatch(tr.setMeta(this.plugin, { remove: { id } }));
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
ImagePlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ImagePlugin, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
182
|
+
ImagePlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ImagePlugin });
|
|
183
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ImagePlugin, decorators: [{
|
|
184
|
+
type: Injectable
|
|
185
|
+
}], ctorParameters: function () {
|
|
186
|
+
return [{ type: Document, decorators: [{
|
|
187
|
+
type: Inject,
|
|
188
|
+
args: [DOCUMENT]
|
|
189
|
+
}] }];
|
|
190
|
+
} });
|
|
191
|
+
|
|
192
|
+
const ALIGN_PATTERN = /(left|right|center|justify)/;
|
|
193
|
+
/**
|
|
194
|
+
* A plain paragraph textblock. Represented in the DOM
|
|
195
|
+
* as a `<p>` element.
|
|
196
|
+
*
|
|
197
|
+
* https://github.com/ProseMirror/prosemirror-schema-basic/blob/master/src/schema-basic.js
|
|
198
|
+
*/
|
|
199
|
+
const paragraphWithAlignment = {
|
|
200
|
+
attrs: {
|
|
201
|
+
align: { default: null },
|
|
202
|
+
class: { default: null },
|
|
203
|
+
id: { default: null },
|
|
204
|
+
},
|
|
205
|
+
content: 'inline*',
|
|
206
|
+
group: 'block',
|
|
207
|
+
parseDOM: [
|
|
208
|
+
{
|
|
209
|
+
tag: 'p',
|
|
210
|
+
getAttrs: (dom) => {
|
|
211
|
+
if (!(dom instanceof HTMLElement)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const { textAlign } = dom.style;
|
|
215
|
+
let align = dom.getAttribute('align') || textAlign || '';
|
|
216
|
+
align = ALIGN_PATTERN.test(align) ? align : null;
|
|
217
|
+
const id = dom.getAttribute('id') || '';
|
|
218
|
+
return { align, class: dom.className, id };
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
toDOM: node => {
|
|
223
|
+
const { align, id } = node.attrs;
|
|
224
|
+
const attrs = {};
|
|
225
|
+
let style = '';
|
|
226
|
+
if (align && align !== 'left') {
|
|
227
|
+
style += `text-align: ${align};`;
|
|
228
|
+
}
|
|
229
|
+
if (style) {
|
|
230
|
+
attrs.style = style;
|
|
231
|
+
}
|
|
232
|
+
if (id) {
|
|
233
|
+
attrs.id = id;
|
|
234
|
+
}
|
|
235
|
+
if (node.attrs.class) {
|
|
236
|
+
attrs.class = node.attrs.class;
|
|
237
|
+
}
|
|
238
|
+
return ['p', attrs, 0];
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
function getCellAttrs(dom, extraAttrs) {
|
|
243
|
+
if (!(dom instanceof HTMLElement)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const widthAttr = dom.getAttribute('data-colwidth');
|
|
247
|
+
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(',').map(s => Number(s)) : null;
|
|
248
|
+
const colspan = Number(dom.getAttribute('colspan') || 1);
|
|
249
|
+
const result = {
|
|
250
|
+
colspan,
|
|
251
|
+
rowspan: Number(dom.getAttribute('rowspan') || 1),
|
|
252
|
+
colwidth: widths && widths.length == colspan ? widths : null,
|
|
253
|
+
};
|
|
254
|
+
for (const prop in extraAttrs) {
|
|
255
|
+
const getter = extraAttrs[prop].getFromDOM;
|
|
256
|
+
const value = getter && getter(dom);
|
|
257
|
+
if (value != null)
|
|
258
|
+
result[prop] = value;
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
function setCellAttrs(node, extraAttrs) {
|
|
263
|
+
const attrs = {};
|
|
264
|
+
if (node.attrs.colspan != 1)
|
|
265
|
+
attrs.colspan = node.attrs.colspan;
|
|
266
|
+
if (node.attrs.rowspan != 1)
|
|
267
|
+
attrs.rowspan = node.attrs.rowspan;
|
|
268
|
+
if (node.attrs.colwidth)
|
|
269
|
+
attrs['data-colwidth'] = node.attrs.colwidth.join(',');
|
|
270
|
+
for (const prop in extraAttrs) {
|
|
271
|
+
const setter = extraAttrs[prop].setDOMAttr;
|
|
272
|
+
if (setter)
|
|
273
|
+
setter(node.attrs[prop], attrs);
|
|
274
|
+
}
|
|
275
|
+
return attrs;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* This function creates a set of [node
|
|
279
|
+
* specs](http://prosemirror.net/docs/ref/#model.SchemaSpec.nodes) for
|
|
280
|
+
* `table`, `table_row`, and `table_cell` nodes types.
|
|
281
|
+
*
|
|
282
|
+
* It is very directly inspired by prosemirror-table
|
|
283
|
+
*/
|
|
284
|
+
function tableNodes(options) {
|
|
285
|
+
const extraAttrs = options.cellAttributes || {};
|
|
286
|
+
const cellAttrs = {
|
|
287
|
+
colspan: { default: 1 },
|
|
288
|
+
rowspan: { default: 1 },
|
|
289
|
+
colwidth: { default: null },
|
|
290
|
+
};
|
|
291
|
+
for (const prop in extraAttrs) {
|
|
292
|
+
cellAttrs[prop] = {
|
|
293
|
+
default: extraAttrs[prop].default,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
table: {
|
|
298
|
+
attrs: {
|
|
299
|
+
class: { default: null },
|
|
300
|
+
},
|
|
301
|
+
content: 'table_row+',
|
|
302
|
+
tableRole: 'table',
|
|
303
|
+
isolating: true,
|
|
304
|
+
group: options.tableGroup,
|
|
305
|
+
parseDOM: [
|
|
306
|
+
{
|
|
307
|
+
tag: 'table',
|
|
308
|
+
getAttrs: (dom) => {
|
|
309
|
+
if (!(dom instanceof HTMLElement)) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
return { class: dom.className };
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
toDOM: node => {
|
|
317
|
+
const attrs = {};
|
|
318
|
+
if (node.attrs.class) {
|
|
319
|
+
attrs.class = node.attrs.class;
|
|
320
|
+
}
|
|
321
|
+
return ['table', attrs, ['tbody', 0]];
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
table_row: {
|
|
325
|
+
content: '(table_cell | table_header)*',
|
|
326
|
+
tableRole: 'row',
|
|
327
|
+
parseDOM: [{ tag: 'tr' }],
|
|
328
|
+
toDOM: () => {
|
|
329
|
+
return ['tr', 0];
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
table_cell: {
|
|
333
|
+
content: options.cellContent,
|
|
334
|
+
attrs: cellAttrs,
|
|
335
|
+
tableRole: 'cell',
|
|
336
|
+
isolating: true,
|
|
337
|
+
parseDOM: [{ tag: 'td', getAttrs: dom => getCellAttrs(dom, extraAttrs) }],
|
|
338
|
+
toDOM: node => {
|
|
339
|
+
return ['td', setCellAttrs(node, extraAttrs), 0];
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
table_header: {
|
|
343
|
+
content: options.cellContent,
|
|
344
|
+
attrs: cellAttrs,
|
|
345
|
+
tableRole: 'header_cell',
|
|
346
|
+
isolating: true,
|
|
347
|
+
parseDOM: [{ tag: 'th', getAttrs: dom => getCellAttrs(dom, extraAttrs) }],
|
|
348
|
+
toDOM: node => {
|
|
349
|
+
return ['th', setCellAttrs(node, extraAttrs), 0];
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const basicNodes = {
|
|
356
|
+
heading: nodes.heading,
|
|
357
|
+
doc: nodes.doc,
|
|
358
|
+
paragraph: nodes.paragraph,
|
|
359
|
+
text: nodes.text,
|
|
360
|
+
hard_break: nodes.hard_break,
|
|
361
|
+
};
|
|
362
|
+
const basicMarks = {
|
|
363
|
+
link: marks.link,
|
|
364
|
+
em: marks.em,
|
|
365
|
+
strong: marks.strong,
|
|
366
|
+
};
|
|
367
|
+
const tmpSchema = new Schema({ nodes: basicNodes, marks: basicMarks });
|
|
368
|
+
const basicSchema = new Schema({
|
|
369
|
+
nodes: addListNodes(tmpSchema.spec.nodes, 'paragraph block*', 'block'),
|
|
370
|
+
marks: tmpSchema.spec.marks,
|
|
371
|
+
});
|
|
372
|
+
const tmpSchema2 = new Schema({
|
|
373
|
+
nodes: Object.assign(Object.assign(Object.assign({}, nodes), tableNodes({
|
|
374
|
+
tableGroup: 'block',
|
|
375
|
+
cellContent: 'block+',
|
|
376
|
+
cellAttributes: {
|
|
377
|
+
background: {
|
|
378
|
+
default: null,
|
|
379
|
+
getFromDOM(dom) {
|
|
380
|
+
return dom.style.backgroundColor || null;
|
|
381
|
+
},
|
|
382
|
+
setDOMAttr(value, attrs) {
|
|
383
|
+
if (value) {
|
|
384
|
+
attrs.style = (attrs.style || '') + `background-color: ${value};`;
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
})), { paragraph: paragraphWithAlignment }),
|
|
390
|
+
marks: basicMarks,
|
|
391
|
+
});
|
|
392
|
+
const advancedSchema = new Schema({
|
|
393
|
+
nodes: addListNodes(tmpSchema2.spec.nodes, 'paragraph block*', 'block'),
|
|
394
|
+
marks: basicMarks,
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* One item of the menu.
|
|
399
|
+
*
|
|
400
|
+
* This is the equivalent of `MenuItem` but without all the rendering logic since we use Angular
|
|
401
|
+
* templates for rendering. Also it caches the state of the item everytime the editor state changes,
|
|
402
|
+
* so Angular can query the state as often as needed without performance hit.
|
|
403
|
+
*/
|
|
404
|
+
class Item {
|
|
405
|
+
constructor(spec) {
|
|
406
|
+
this.spec = spec;
|
|
407
|
+
/**
|
|
408
|
+
* Whether the item is 'active' (for example, the item for toggling the strong mark might be active when the cursor is in strong text).
|
|
409
|
+
*/
|
|
410
|
+
this.active = false;
|
|
411
|
+
/**
|
|
412
|
+
* Button is shown but disabled, because the item cannot be (un-)applied
|
|
413
|
+
*/
|
|
414
|
+
this.disabled = false;
|
|
415
|
+
/**
|
|
416
|
+
* Whether the item is shown at the moment
|
|
417
|
+
*/
|
|
418
|
+
this.show = true;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Update the item state according to the editor state
|
|
422
|
+
*/
|
|
423
|
+
update(view, state) {
|
|
424
|
+
if (this.spec.active) {
|
|
425
|
+
this.active = this.spec.active(state);
|
|
426
|
+
}
|
|
427
|
+
if (this.spec.enable) {
|
|
428
|
+
this.disabled = !this.spec.enable(state);
|
|
429
|
+
}
|
|
430
|
+
if (this.spec.select) {
|
|
431
|
+
this.show = this.spec.select(state);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function setTextAlign(tr, schema, alignment) {
|
|
437
|
+
const { selection, doc } = tr;
|
|
438
|
+
if (!selection || !doc) {
|
|
439
|
+
return tr;
|
|
440
|
+
}
|
|
441
|
+
const { from, to } = selection;
|
|
442
|
+
const { nodes } = schema;
|
|
443
|
+
const tasks = [];
|
|
444
|
+
alignment = alignment || null;
|
|
445
|
+
const allowedNodeTypes = new Set([
|
|
446
|
+
nodes.paragraph,
|
|
447
|
+
// nodes['blockquote'],
|
|
448
|
+
// nodes['listItem'],
|
|
449
|
+
// nodes['heading'],
|
|
450
|
+
]);
|
|
451
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
452
|
+
const nodeType = node.type;
|
|
453
|
+
const align = node.attrs.align || null;
|
|
454
|
+
if (align !== alignment && allowedNodeTypes.has(nodeType)) {
|
|
455
|
+
tasks.push({
|
|
456
|
+
node,
|
|
457
|
+
pos,
|
|
458
|
+
nodeType,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
return true;
|
|
462
|
+
});
|
|
463
|
+
if (!tasks.length) {
|
|
464
|
+
return tr;
|
|
465
|
+
}
|
|
466
|
+
tasks.forEach(job => {
|
|
467
|
+
const { node, pos, nodeType } = job;
|
|
468
|
+
const newAttrs = Object.assign(Object.assign({}, node.attrs), { align: alignment ? alignment : null });
|
|
469
|
+
tr = tr.setNodeMarkup(pos, nodeType, newAttrs, node.marks);
|
|
470
|
+
});
|
|
471
|
+
return tr;
|
|
472
|
+
}
|
|
473
|
+
class TextAlignItem extends Item {
|
|
474
|
+
constructor(alignment) {
|
|
475
|
+
super({
|
|
476
|
+
active: state => {
|
|
477
|
+
const { selection, doc } = state;
|
|
478
|
+
const { from, to } = selection;
|
|
479
|
+
let keepLooking = true;
|
|
480
|
+
let active = false;
|
|
481
|
+
doc.nodesBetween(from, to, node => {
|
|
482
|
+
if (keepLooking && node.attrs.align === alignment) {
|
|
483
|
+
keepLooking = false;
|
|
484
|
+
active = true;
|
|
485
|
+
}
|
|
486
|
+
return keepLooking;
|
|
487
|
+
});
|
|
488
|
+
return active;
|
|
489
|
+
},
|
|
490
|
+
enable: state => {
|
|
491
|
+
const { selection } = state;
|
|
492
|
+
return selection instanceof TextSelection || selection instanceof AllSelection;
|
|
493
|
+
},
|
|
494
|
+
run: (state, dispatch) => {
|
|
495
|
+
const { schema, selection } = state;
|
|
496
|
+
const tr = setTextAlign(state.tr.setSelection(selection), schema, this.active ? null : alignment);
|
|
497
|
+
if (tr.docChanged) {
|
|
498
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch(tr);
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
class ColorDialogComponent {
|
|
510
|
+
constructor(data, dialogRef) {
|
|
511
|
+
this.dialogRef = dialogRef;
|
|
512
|
+
this.colors = [
|
|
513
|
+
[
|
|
514
|
+
'#000000',
|
|
515
|
+
'#111111',
|
|
516
|
+
'#1c1c1c',
|
|
517
|
+
'#333333',
|
|
518
|
+
'#666666',
|
|
519
|
+
'#808080',
|
|
520
|
+
'#999999',
|
|
521
|
+
'#b2b2b2',
|
|
522
|
+
'#cccccc',
|
|
523
|
+
'#dddddd',
|
|
524
|
+
'#eeeeee',
|
|
525
|
+
'#ffffff',
|
|
526
|
+
],
|
|
527
|
+
[
|
|
528
|
+
'#ffff00',
|
|
529
|
+
'#ffbf00',
|
|
530
|
+
'#ff8000',
|
|
531
|
+
'#ff4000',
|
|
532
|
+
'#ff0000',
|
|
533
|
+
'#bf0041',
|
|
534
|
+
'#800080',
|
|
535
|
+
'#55308d',
|
|
536
|
+
'#2a6099',
|
|
537
|
+
'#158466',
|
|
538
|
+
'#00a933',
|
|
539
|
+
'#81d41a',
|
|
540
|
+
],
|
|
541
|
+
[
|
|
542
|
+
'#ffffd7',
|
|
543
|
+
'#fff5ce',
|
|
544
|
+
'#ffdbb6',
|
|
545
|
+
'#ffd8ce',
|
|
546
|
+
'#ffd7d7',
|
|
547
|
+
'#f7d1d5',
|
|
548
|
+
'#e0c2cd',
|
|
549
|
+
'#dedce6',
|
|
550
|
+
'#dee6ef',
|
|
551
|
+
'#dee7e5',
|
|
552
|
+
'#dde8cb',
|
|
553
|
+
'#f6f9d4',
|
|
554
|
+
],
|
|
555
|
+
[
|
|
556
|
+
'#ffffa6',
|
|
557
|
+
'#ffe994',
|
|
558
|
+
'#ffb66c',
|
|
559
|
+
'#ffaa95',
|
|
560
|
+
'#ffa6a6',
|
|
561
|
+
'#ec9ba4',
|
|
562
|
+
'#bf819e',
|
|
563
|
+
'#b7b3ca',
|
|
564
|
+
'#b4c7dc',
|
|
565
|
+
'#b3cac7',
|
|
566
|
+
'#afd095',
|
|
567
|
+
'#e8f2a1',
|
|
568
|
+
],
|
|
569
|
+
[
|
|
570
|
+
'#ffff6d',
|
|
571
|
+
'#ffde59',
|
|
572
|
+
'#ff972f',
|
|
573
|
+
'#ff7b59',
|
|
574
|
+
'#ff6d6d',
|
|
575
|
+
'#e16173',
|
|
576
|
+
'#a1467e',
|
|
577
|
+
'#8e86ae',
|
|
578
|
+
'#729fcf',
|
|
579
|
+
'#81aca6',
|
|
580
|
+
'#77bc65',
|
|
581
|
+
'#d4ea6b',
|
|
582
|
+
],
|
|
583
|
+
[
|
|
584
|
+
'#ffff38',
|
|
585
|
+
'#ffd428',
|
|
586
|
+
'#ff860d',
|
|
587
|
+
'#ff5429',
|
|
588
|
+
'#ff3838',
|
|
589
|
+
'#d62e4e',
|
|
590
|
+
'#8d1d75',
|
|
591
|
+
'#6b5e9b',
|
|
592
|
+
'#5983b0',
|
|
593
|
+
'#50938a',
|
|
594
|
+
'#3faf46',
|
|
595
|
+
'#bbe33d',
|
|
596
|
+
],
|
|
597
|
+
[
|
|
598
|
+
'#e6e905',
|
|
599
|
+
'#e8a202',
|
|
600
|
+
'#ea7500',
|
|
601
|
+
'#ed4c05',
|
|
602
|
+
'#f10d0c',
|
|
603
|
+
'#a7074b',
|
|
604
|
+
'#780373',
|
|
605
|
+
'#5b277d',
|
|
606
|
+
'#3465a4',
|
|
607
|
+
'#168253',
|
|
608
|
+
'#069a2e',
|
|
609
|
+
'#5eb91e',
|
|
610
|
+
],
|
|
611
|
+
[
|
|
612
|
+
'#acb20c',
|
|
613
|
+
'#b47804',
|
|
614
|
+
'#b85c00',
|
|
615
|
+
'#be480a',
|
|
616
|
+
'#c9211e',
|
|
617
|
+
'#861141',
|
|
618
|
+
'#650953',
|
|
619
|
+
'#55215b',
|
|
620
|
+
'#355269',
|
|
621
|
+
'#1e6a39',
|
|
622
|
+
'#127622',
|
|
623
|
+
'#468a1a',
|
|
624
|
+
],
|
|
625
|
+
[
|
|
626
|
+
'#706e0c',
|
|
627
|
+
'#784b04',
|
|
628
|
+
'#7b3d00',
|
|
629
|
+
'#813709',
|
|
630
|
+
'#8d281e',
|
|
631
|
+
'#611729',
|
|
632
|
+
'#4e102d',
|
|
633
|
+
'#481d32',
|
|
634
|
+
'#383d3c',
|
|
635
|
+
'#28471f',
|
|
636
|
+
'#224b12',
|
|
637
|
+
'#395511',
|
|
638
|
+
],
|
|
639
|
+
[
|
|
640
|
+
'#443205',
|
|
641
|
+
'#472702',
|
|
642
|
+
'#492300',
|
|
643
|
+
'#4b2204',
|
|
644
|
+
'#50200c',
|
|
645
|
+
'#41190d',
|
|
646
|
+
'#3b160e',
|
|
647
|
+
'#3a1a0f',
|
|
648
|
+
'#362413',
|
|
649
|
+
'#302709',
|
|
650
|
+
'#2e2706',
|
|
651
|
+
'#342a06',
|
|
652
|
+
],
|
|
653
|
+
];
|
|
654
|
+
this.colorControl = new FormControl('', Validators.pattern(/^#\p{Hex_Digit}{6}/u));
|
|
655
|
+
this.form = new FormGroup({
|
|
656
|
+
color: this.colorControl,
|
|
657
|
+
});
|
|
658
|
+
this.form.setValue(data);
|
|
659
|
+
}
|
|
660
|
+
maybeConfirm() {
|
|
661
|
+
ifValid(this.form).subscribe(() => this.confirm());
|
|
662
|
+
}
|
|
663
|
+
confirm() {
|
|
664
|
+
this.dialogRef.close(this.form.value);
|
|
665
|
+
}
|
|
666
|
+
selectColor(color) {
|
|
667
|
+
this.colorControl.setValue(color);
|
|
668
|
+
this.maybeConfirm();
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
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 });
|
|
672
|
+
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"] }] });
|
|
673
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: ColorDialogComponent, decorators: [{
|
|
674
|
+
type: Component,
|
|
675
|
+
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"] }]
|
|
676
|
+
}], ctorParameters: function () {
|
|
677
|
+
return [{ type: undefined, decorators: [{
|
|
678
|
+
type: Inject,
|
|
679
|
+
args: [MAT_DIALOG_DATA]
|
|
680
|
+
}] }, { type: i1.MatDialogRef }];
|
|
681
|
+
} });
|
|
682
|
+
|
|
683
|
+
const setCellBackgroundColor = setCellAttr.bind(null, 'background');
|
|
684
|
+
function findFirstClassInSelection$1(state) {
|
|
685
|
+
var _a, _b;
|
|
686
|
+
if (!isInTable(state)) {
|
|
687
|
+
return '';
|
|
688
|
+
}
|
|
689
|
+
// For single cell selection
|
|
690
|
+
const $cell = selectionCell(state);
|
|
691
|
+
let foundColor = (_b = (_a = $cell === null || $cell === void 0 ? void 0 : $cell.nodeAfter) === null || _a === void 0 ? void 0 : _a.attrs.background) !== null && _b !== void 0 ? _b : '';
|
|
692
|
+
if (foundColor) {
|
|
693
|
+
return foundColor;
|
|
694
|
+
}
|
|
695
|
+
// For multiple cells selection
|
|
696
|
+
let keepLooking = true;
|
|
697
|
+
if (state.selection instanceof CellSelection) {
|
|
698
|
+
state.selection.forEachCell(node => {
|
|
699
|
+
const color = node.attrs.background;
|
|
700
|
+
if (keepLooking && color) {
|
|
701
|
+
keepLooking = false;
|
|
702
|
+
foundColor = color;
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
return foundColor;
|
|
707
|
+
}
|
|
708
|
+
class CellBackgroundColorItem extends Item {
|
|
709
|
+
constructor(dialog) {
|
|
710
|
+
super({
|
|
711
|
+
enable(state) {
|
|
712
|
+
// Pretend to set a unique color that is not already set, to test if we can any color at all
|
|
713
|
+
const cmd = setCellBackgroundColor('#000001');
|
|
714
|
+
return cmd(state);
|
|
715
|
+
},
|
|
716
|
+
run(state, dispatch, view) {
|
|
717
|
+
dialog
|
|
718
|
+
.open(ColorDialogComponent, {
|
|
719
|
+
data: {
|
|
720
|
+
color: findFirstClassInSelection$1(state),
|
|
721
|
+
},
|
|
722
|
+
})
|
|
723
|
+
.afterClosed()
|
|
724
|
+
.subscribe(result => {
|
|
725
|
+
if (dispatch && result) {
|
|
726
|
+
const cmd = setCellBackgroundColor(result.color);
|
|
727
|
+
cmd(state, dispatch);
|
|
728
|
+
}
|
|
729
|
+
view.focus();
|
|
730
|
+
});
|
|
731
|
+
},
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
class LinkDialogComponent {
|
|
737
|
+
constructor(data, dialogRef) {
|
|
738
|
+
this.dialogRef = dialogRef;
|
|
739
|
+
this.hrefControl = new FormControl('', Validators.required);
|
|
740
|
+
this.titleControl = new FormControl('');
|
|
741
|
+
this.form = new FormGroup({
|
|
742
|
+
href: this.hrefControl,
|
|
743
|
+
title: this.titleControl,
|
|
744
|
+
});
|
|
745
|
+
this.form.setValue(data);
|
|
746
|
+
}
|
|
747
|
+
maybeConfirm() {
|
|
748
|
+
ifValid(this.form).subscribe(() => this.confirm());
|
|
749
|
+
}
|
|
750
|
+
confirm() {
|
|
751
|
+
this.dialogRef.close(this.form.value);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
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 });
|
|
755
|
+
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"] }] });
|
|
756
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: LinkDialogComponent, decorators: [{
|
|
757
|
+
type: Component,
|
|
758
|
+
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"] }]
|
|
759
|
+
}], ctorParameters: function () {
|
|
760
|
+
return [{ type: undefined, decorators: [{
|
|
761
|
+
type: Inject,
|
|
762
|
+
args: [MAT_DIALOG_DATA]
|
|
763
|
+
}] }, { type: i1.MatDialogRef }];
|
|
764
|
+
} });
|
|
765
|
+
|
|
766
|
+
function markActive(state, type) {
|
|
767
|
+
const { from, $from, to, empty } = state.selection;
|
|
768
|
+
if (empty) {
|
|
769
|
+
return !!type.isInSet(state.storedMarks || $from.marks());
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
return state.doc.rangeHasMark(from, to, type);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Convert built-in `MenuItem` into our Angular specific `Item`
|
|
777
|
+
*/
|
|
778
|
+
function menuItemToItem(item) {
|
|
779
|
+
return new Item(item.spec);
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* From a `Command`, creates a new `Item` that will have an automatic `enable` spec
|
|
783
|
+
*/
|
|
784
|
+
function cmdToItem(cmd, options = {}) {
|
|
785
|
+
const passedOptions = Object.assign({ run: cmd }, options);
|
|
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 () {
|
|
887
|
+
return [{ type: undefined, decorators: [{
|
|
888
|
+
type: Inject,
|
|
889
|
+
args: [MAT_DIALOG_DATA]
|
|
890
|
+
}] }, { type: i1.MatDialogRef }];
|
|
891
|
+
} });
|
|
892
|
+
|
|
893
|
+
function setClass(tr, classValue, allowedNodeType) {
|
|
894
|
+
const { selection, doc } = tr;
|
|
895
|
+
if (!selection || !doc) {
|
|
896
|
+
return tr;
|
|
897
|
+
}
|
|
898
|
+
const { from, to } = selection;
|
|
899
|
+
const tasks = [];
|
|
900
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
901
|
+
const nodeType = node.type;
|
|
902
|
+
const currentClass = node.attrs.class || null;
|
|
903
|
+
if (currentClass !== classValue && allowedNodeType === nodeType) {
|
|
904
|
+
tasks.push({
|
|
905
|
+
node,
|
|
906
|
+
pos,
|
|
907
|
+
nodeType,
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
return true;
|
|
911
|
+
});
|
|
912
|
+
if (!tasks.length) {
|
|
913
|
+
return tr;
|
|
914
|
+
}
|
|
915
|
+
tasks.forEach(job => {
|
|
916
|
+
const { node, pos, nodeType } = job;
|
|
917
|
+
const newAttrs = Object.assign(Object.assign({}, node.attrs), { class: classValue ? classValue : null });
|
|
918
|
+
tr = tr.setNodeMarkup(pos, nodeType, newAttrs, node.marks);
|
|
919
|
+
});
|
|
920
|
+
return tr;
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Returns the first `class` attribute that is non-empty in the selection.
|
|
924
|
+
* If not found, return empty string.
|
|
925
|
+
*/
|
|
926
|
+
function findFirstClassInSelection(state, allowedNodeType) {
|
|
927
|
+
const { selection, doc } = state;
|
|
928
|
+
const { from, to } = selection;
|
|
929
|
+
let keepLooking = true;
|
|
930
|
+
let foundClass = '';
|
|
931
|
+
doc.nodesBetween(from, to, node => {
|
|
932
|
+
if (keepLooking && node.type === allowedNodeType && node.attrs.class) {
|
|
933
|
+
keepLooking = false;
|
|
934
|
+
foundClass = node.attrs.class;
|
|
935
|
+
}
|
|
936
|
+
return keepLooking;
|
|
937
|
+
});
|
|
938
|
+
return foundClass;
|
|
939
|
+
}
|
|
940
|
+
class ClassItem extends Item {
|
|
941
|
+
constructor(dialog, nodeType) {
|
|
942
|
+
super({
|
|
943
|
+
active: state => {
|
|
944
|
+
return !!findFirstClassInSelection(state, nodeType);
|
|
945
|
+
},
|
|
946
|
+
enable: state => {
|
|
947
|
+
const { selection } = state;
|
|
948
|
+
return selection instanceof TextSelection || selection instanceof AllSelection;
|
|
949
|
+
},
|
|
950
|
+
run: (state, dispatch, view) => {
|
|
951
|
+
dialog
|
|
952
|
+
.open(ClassDialogComponent, {
|
|
953
|
+
data: {
|
|
954
|
+
class: findFirstClassInSelection(state, nodeType),
|
|
955
|
+
},
|
|
956
|
+
})
|
|
957
|
+
.afterClosed()
|
|
958
|
+
.subscribe(result => {
|
|
959
|
+
if (dispatch && result) {
|
|
960
|
+
const { selection } = state;
|
|
961
|
+
const tr = setClass(state.tr.setSelection(selection), result.class, nodeType);
|
|
962
|
+
if (tr.docChanged) {
|
|
963
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch(tr);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
view.focus();
|
|
967
|
+
});
|
|
968
|
+
},
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function createCell(cellType, cellContent) {
|
|
974
|
+
return cellContent ? cellType.createChecked(null, cellContent) : cellType.createAndFill();
|
|
975
|
+
}
|
|
976
|
+
function createTable(state, rowsCount, colsCount, withHeaderRow, cellContent) {
|
|
977
|
+
const types = tableNodeTypes(state.schema);
|
|
978
|
+
const headerCells = [];
|
|
979
|
+
const cells = [];
|
|
980
|
+
for (let index = 0; index < colsCount; index += 1) {
|
|
981
|
+
const cell = createCell(types.cell, cellContent);
|
|
982
|
+
if (cell) {
|
|
983
|
+
cells.push(cell);
|
|
984
|
+
}
|
|
985
|
+
if (withHeaderRow) {
|
|
986
|
+
const headerCell = createCell(types.header_cell, cellContent);
|
|
987
|
+
if (headerCell) {
|
|
988
|
+
headerCells.push(headerCell);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
const rows = [];
|
|
993
|
+
for (let index = 0; index < rowsCount; index += 1) {
|
|
994
|
+
rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
|
|
995
|
+
}
|
|
996
|
+
return types.table.createChecked(null, rows);
|
|
997
|
+
}
|
|
998
|
+
function addTable(state, dispatch, { rowsCount = 3, colsCount = 3, withHeaderRow = true, cellContent, } = {}) {
|
|
999
|
+
const offset = state.tr.selection.anchor + 1;
|
|
1000
|
+
const nodes = createTable(state, rowsCount, colsCount, withHeaderRow, cellContent);
|
|
1001
|
+
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView();
|
|
1002
|
+
const resolvedPos = tr.doc.resolve(offset);
|
|
1003
|
+
// move cursor into table
|
|
1004
|
+
tr.setSelection(TextSelection.near(resolvedPos));
|
|
1005
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch(tr);
|
|
1006
|
+
}
|
|
1007
|
+
class AddTableItem extends Item {
|
|
1008
|
+
constructor() {
|
|
1009
|
+
super({ run: (editor, tr) => addTable(editor, tr) });
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Given a schema, look for default mark and node types in it and
|
|
1015
|
+
* return an object with relevant menu items relating to those marks:
|
|
1016
|
+
*/
|
|
1017
|
+
function buildMenuItems(schema, dialog) {
|
|
1018
|
+
const r = {
|
|
1019
|
+
joinUp: menuItemToItem(joinUpItem),
|
|
1020
|
+
lift: menuItemToItem(liftItem),
|
|
1021
|
+
selectParentNode: menuItemToItem(selectParentNodeItem),
|
|
1022
|
+
undo: menuItemToItem(undoItem),
|
|
1023
|
+
redo: menuItemToItem(redoItem),
|
|
1024
|
+
};
|
|
1025
|
+
let type;
|
|
1026
|
+
type = schema.marks.strong;
|
|
1027
|
+
if (type) {
|
|
1028
|
+
r.toggleStrong = markTypeToItem(type);
|
|
1029
|
+
}
|
|
1030
|
+
type = schema.marks.em;
|
|
1031
|
+
if (type) {
|
|
1032
|
+
r.toggleEm = markTypeToItem(type);
|
|
1033
|
+
}
|
|
1034
|
+
type = schema.marks.code;
|
|
1035
|
+
if (type) {
|
|
1036
|
+
r.toggleCode = markTypeToItem(type);
|
|
1037
|
+
}
|
|
1038
|
+
type = schema.marks.link;
|
|
1039
|
+
if (type) {
|
|
1040
|
+
r.toggleLink = new LinkItem(type, dialog);
|
|
1041
|
+
}
|
|
1042
|
+
type = schema.nodes.bullet_list;
|
|
1043
|
+
if (type) {
|
|
1044
|
+
r.wrapBulletList = wrapListItem(type);
|
|
1045
|
+
}
|
|
1046
|
+
type = schema.nodes.ordered_list;
|
|
1047
|
+
if (type) {
|
|
1048
|
+
r.wrapOrderedList = wrapListItem(type);
|
|
1049
|
+
}
|
|
1050
|
+
type = schema.nodes.blockquote;
|
|
1051
|
+
if (type) {
|
|
1052
|
+
r.wrapBlockQuote = menuItemToItem(wrapItem(type, {}));
|
|
1053
|
+
}
|
|
1054
|
+
type = schema.nodes.paragraph;
|
|
1055
|
+
if (type) {
|
|
1056
|
+
r.makeParagraph = menuItemToItem(blockTypeItem(type, {}));
|
|
1057
|
+
if (type.spec === paragraphWithAlignment) {
|
|
1058
|
+
r.alignLeft = new TextAlignItem('left');
|
|
1059
|
+
r.alignRight = new TextAlignItem('right');
|
|
1060
|
+
r.alignCenter = new TextAlignItem('center');
|
|
1061
|
+
r.alignJustify = new TextAlignItem('justify');
|
|
1062
|
+
r.paragraphClass = new ClassItem(dialog, type);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
type = schema.nodes.code_block;
|
|
1066
|
+
if (type) {
|
|
1067
|
+
r.makeCodeBlock = menuItemToItem(blockTypeItem(type, {}));
|
|
1068
|
+
}
|
|
1069
|
+
type = schema.nodes.heading;
|
|
1070
|
+
if (type) {
|
|
1071
|
+
r.makeHead1 = menuItemToItem(blockTypeItem(type, { attrs: { level: 1 } }));
|
|
1072
|
+
r.makeHead2 = menuItemToItem(blockTypeItem(type, { attrs: { level: 2 } }));
|
|
1073
|
+
r.makeHead3 = menuItemToItem(blockTypeItem(type, { attrs: { level: 3 } }));
|
|
1074
|
+
r.makeHead4 = menuItemToItem(blockTypeItem(type, { attrs: { level: 4 } }));
|
|
1075
|
+
r.makeHead5 = menuItemToItem(blockTypeItem(type, { attrs: { level: 5 } }));
|
|
1076
|
+
r.makeHead6 = menuItemToItem(blockTypeItem(type, { attrs: { level: 6 } }));
|
|
1077
|
+
}
|
|
1078
|
+
type = schema.nodes.horizontal_rule;
|
|
1079
|
+
if (type) {
|
|
1080
|
+
r.insertHorizontalRule = new HorizontalRuleItem(type);
|
|
1081
|
+
}
|
|
1082
|
+
type = schema.nodes.table;
|
|
1083
|
+
if (type) {
|
|
1084
|
+
r.insertTable = new AddTableItem();
|
|
1085
|
+
r.addColumnBefore = cmdToItem(addColumnBefore);
|
|
1086
|
+
r.addColumnAfter = cmdToItem(addColumnAfter);
|
|
1087
|
+
r.deleteColumn = cmdToItem(deleteColumn);
|
|
1088
|
+
r.addRowBefore = cmdToItem(addRowBefore);
|
|
1089
|
+
r.addRowAfter = cmdToItem(addRowAfter);
|
|
1090
|
+
r.deleteRow = cmdToItem(deleteRow);
|
|
1091
|
+
r.deleteTable = cmdToItem(deleteTable);
|
|
1092
|
+
r.mergeCells = cmdToItem(mergeCells);
|
|
1093
|
+
r.splitCell = cmdToItem(splitCell);
|
|
1094
|
+
r.toggleHeaderColumn = cmdToItem(toggleHeaderColumn);
|
|
1095
|
+
r.toggleHeaderRow = cmdToItem(toggleHeaderRow);
|
|
1096
|
+
r.toggleHeaderCell = cmdToItem(toggleHeaderCell);
|
|
1097
|
+
r.cellBackgroundColor = new CellBackgroundColorItem(dialog);
|
|
1098
|
+
r.tableClass = new ClassItem(dialog, type);
|
|
1099
|
+
}
|
|
1100
|
+
return r;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* Given a blockquote node type, returns an input rule that turns `"> "`
|
|
1105
|
+
* at the start of a textblock into a blockquote.
|
|
1106
|
+
*/
|
|
1107
|
+
function blockQuoteRule(nodeType) {
|
|
1108
|
+
return wrappingInputRule(/^\s*>\s$/, nodeType);
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Given a list node type, returns an input rule that turns a number
|
|
1112
|
+
* followed by a dot at the start of a textblock into an ordered list.
|
|
1113
|
+
*/
|
|
1114
|
+
function orderedListRule(nodeType) {
|
|
1115
|
+
return wrappingInputRule(/^(\d+)\.\s$/, nodeType, match => ({ order: +match[1] }), (match, node) => node.childCount + node.attrs.order === +match[1]);
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Given a list node type, returns an input rule that turns a bullet
|
|
1119
|
+
* (dash, plush, or asterisk) at the start of a textblock into a
|
|
1120
|
+
* bullet list.
|
|
1121
|
+
*/
|
|
1122
|
+
function bulletListRule(nodeType) {
|
|
1123
|
+
return wrappingInputRule(/^\s*([-+*])\s$/, nodeType);
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Given a code block node type, returns an input rule that turns a
|
|
1127
|
+
* textblock starting with three backticks into a code block.
|
|
1128
|
+
*/
|
|
1129
|
+
function codeBlockRule(nodeType) {
|
|
1130
|
+
return textblockTypeInputRule(/^```$/, nodeType);
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Given a node type and a maximum level, creates an input rule that
|
|
1134
|
+
* turns up to that number of `#` characters followed by a space at
|
|
1135
|
+
* the start of a textblock into a heading whose level corresponds to
|
|
1136
|
+
* the number of `#` signs.
|
|
1137
|
+
*/
|
|
1138
|
+
function headingRule(nodeType, maxLevel) {
|
|
1139
|
+
return textblockTypeInputRule(new RegExp('^(#{1,' + maxLevel + '})\\s$'), nodeType, match => ({
|
|
1140
|
+
level: match[1].length,
|
|
1141
|
+
}));
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* A set of input rules for creating the basic block quotes, lists,
|
|
1145
|
+
* code blocks, and heading.
|
|
1146
|
+
*/
|
|
1147
|
+
function buildInputRules(schema) {
|
|
1148
|
+
const rules = [ellipsis, emDash];
|
|
1149
|
+
let type = schema.nodes.blockquote;
|
|
1150
|
+
if (type) {
|
|
1151
|
+
rules.push(blockQuoteRule(type));
|
|
1152
|
+
}
|
|
1153
|
+
type = schema.nodes.ordered_list;
|
|
1154
|
+
if (type) {
|
|
1155
|
+
rules.push(orderedListRule(type));
|
|
1156
|
+
}
|
|
1157
|
+
type = schema.nodes.bullet_list;
|
|
1158
|
+
if (type) {
|
|
1159
|
+
rules.push(bulletListRule(type));
|
|
1160
|
+
}
|
|
1161
|
+
type = schema.nodes.code_block;
|
|
1162
|
+
if (type) {
|
|
1163
|
+
rules.push(codeBlockRule(type));
|
|
1164
|
+
}
|
|
1165
|
+
type = schema.nodes.heading;
|
|
1166
|
+
if (type) {
|
|
1167
|
+
rules.push(headingRule(type, 6));
|
|
1168
|
+
}
|
|
1169
|
+
return inputRules({ rules });
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Inspect the given schema looking for marks and nodes from the
|
|
1174
|
+
* basic schema, and if found, add key bindings related to them.
|
|
1175
|
+
* This will add:
|
|
1176
|
+
*
|
|
1177
|
+
* * **Mod-b** for toggling [strong](#schema-basic.StrongMark)
|
|
1178
|
+
* * **Mod-i** for toggling [emphasis](#schema-basic.EmMark)
|
|
1179
|
+
* * **Mod-`** for toggling [code font](#schema-basic.CodeMark)
|
|
1180
|
+
* * **Ctrl-Shift-0** for making the current textblock a paragraph
|
|
1181
|
+
* * **Ctrl-Shift-1** to **Ctrl-Shift-Digit6** for making the current
|
|
1182
|
+
* textblock a heading of the corresponding level
|
|
1183
|
+
* * **Ctrl-Shift-Backslash** to make the current textblock a code block
|
|
1184
|
+
* * **Ctrl-Shift-8** to wrap the selection in an ordered list
|
|
1185
|
+
* * **Ctrl-Shift-9** to wrap the selection in a bullet list
|
|
1186
|
+
* * **Ctrl->** to wrap the selection in a block quote
|
|
1187
|
+
* * **Enter** to split a non-empty textblock in a list item while at
|
|
1188
|
+
* the same time splitting the list item
|
|
1189
|
+
* * **Mod-Enter** to insert a hard break
|
|
1190
|
+
* * **Mod-_** to insert a horizontal rule
|
|
1191
|
+
* * **Backspace** to undo an input rule
|
|
1192
|
+
* * **Alt-ArrowUp** to `joinUp`
|
|
1193
|
+
* * **Alt-ArrowDown** to `joinDown`
|
|
1194
|
+
* * **Mod-BracketLeft** to `lift`
|
|
1195
|
+
* * **Escape** to `selectParentNode`
|
|
1196
|
+
*
|
|
1197
|
+
* You can suppress or map these bindings by passing a `mapKeys`
|
|
1198
|
+
* argument, which maps key names (say `"Mod-B"` to either `false`, to
|
|
1199
|
+
* remove the binding, or a new key name string.
|
|
1200
|
+
*/
|
|
1201
|
+
function buildKeymap(schema, isMac) {
|
|
1202
|
+
const keys = {};
|
|
1203
|
+
keys['Mod-z'] = undo;
|
|
1204
|
+
keys['Shift-Mod-z'] = redo;
|
|
1205
|
+
keys['Backspace'] = undoInputRule;
|
|
1206
|
+
if (!isMac) {
|
|
1207
|
+
keys['Mod-y'] = redo;
|
|
1208
|
+
}
|
|
1209
|
+
keys['Alt-ArrowUp'] = joinUp;
|
|
1210
|
+
keys['Alt-ArrowDown'] = joinDown;
|
|
1211
|
+
keys['Mod-BracketLeft'] = lift;
|
|
1212
|
+
keys['Escape'] = selectParentNode;
|
|
1213
|
+
let type = schema.marks.strong;
|
|
1214
|
+
if (type) {
|
|
1215
|
+
keys['Mod-b'] = toggleMark(type);
|
|
1216
|
+
keys['Mod-B'] = toggleMark(type);
|
|
1217
|
+
}
|
|
1218
|
+
type = schema.marks.em;
|
|
1219
|
+
if (type) {
|
|
1220
|
+
keys['Mod-i'] = toggleMark(type);
|
|
1221
|
+
keys['Mod-I'] = toggleMark(type);
|
|
1222
|
+
}
|
|
1223
|
+
type = schema.marks.code;
|
|
1224
|
+
if (type) {
|
|
1225
|
+
keys['Mod-`'] = toggleMark(type);
|
|
1226
|
+
}
|
|
1227
|
+
type = schema.nodes.bullet_list;
|
|
1228
|
+
if (type) {
|
|
1229
|
+
keys['Shift-Ctrl-8'] = wrapInList(type);
|
|
1230
|
+
}
|
|
1231
|
+
type = schema.nodes.ordered_list;
|
|
1232
|
+
if (type) {
|
|
1233
|
+
keys['Shift-Ctrl-9'] = wrapInList(type);
|
|
1234
|
+
}
|
|
1235
|
+
type = schema.nodes.blockquote;
|
|
1236
|
+
if (type) {
|
|
1237
|
+
keys['Ctrl->'] = wrapIn(type);
|
|
1238
|
+
}
|
|
1239
|
+
type = schema.nodes.hard_break;
|
|
1240
|
+
if (type) {
|
|
1241
|
+
const br = type;
|
|
1242
|
+
const cmd = chainCommands(exitCode, (state, dispatch) => {
|
|
1243
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView());
|
|
1244
|
+
return true;
|
|
1245
|
+
});
|
|
1246
|
+
keys['Mod-Enter'] = cmd;
|
|
1247
|
+
keys['Shift-Enter'] = cmd;
|
|
1248
|
+
if (isMac) {
|
|
1249
|
+
keys['Ctrl-Enter'] = cmd;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
type = schema.nodes.list_item;
|
|
1253
|
+
if (type) {
|
|
1254
|
+
keys['Enter'] = splitListItem(type);
|
|
1255
|
+
keys['Mod-['] = liftListItem(type);
|
|
1256
|
+
keys['Mod-]'] = sinkListItem(type);
|
|
1257
|
+
}
|
|
1258
|
+
type = schema.nodes.paragraph;
|
|
1259
|
+
if (type) {
|
|
1260
|
+
keys['Shift-Ctrl-0'] = setBlockType(type);
|
|
1261
|
+
}
|
|
1262
|
+
type = schema.nodes.code_block;
|
|
1263
|
+
if (type) {
|
|
1264
|
+
keys['Shift-Ctrl-\\'] = setBlockType(type);
|
|
1265
|
+
}
|
|
1266
|
+
type = schema.nodes.heading;
|
|
1267
|
+
if (type) {
|
|
1268
|
+
for (let i = 1; i <= 6; i++) {
|
|
1269
|
+
keys['Shift-Ctrl-' + i] = setBlockType(type, { level: i });
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
type = schema.nodes.horizontal_rule;
|
|
1273
|
+
if (type) {
|
|
1274
|
+
const hr = type;
|
|
1275
|
+
keys['Mod-_'] = (state, dispatch) => {
|
|
1276
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch(state.tr.replaceSelectionWith(hr.create()).scrollIntoView());
|
|
1277
|
+
return true;
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
return keys;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* Prosemirror component
|
|
1285
|
+
*
|
|
1286
|
+
* Usage :
|
|
1287
|
+
*
|
|
1288
|
+
* ```html
|
|
1289
|
+
* <natural-editor [(ngModel)]="htmlString"></natural-editor>
|
|
1290
|
+
* ```
|
|
1291
|
+
*/
|
|
1292
|
+
// @dynamic
|
|
1293
|
+
class NaturalEditorComponent {
|
|
1294
|
+
constructor(ngControl, document, dialog, imagePlugin) {
|
|
1295
|
+
this.ngControl = ngControl;
|
|
1296
|
+
this.document = document;
|
|
1297
|
+
this.dialog = dialog;
|
|
1298
|
+
this.imagePlugin = imagePlugin;
|
|
1299
|
+
this.view = null;
|
|
1300
|
+
this.contentChange = new EventEmitter();
|
|
1301
|
+
/**
|
|
1302
|
+
* Callback to upload an image.
|
|
1303
|
+
*
|
|
1304
|
+
* If given it will enable advanced schema, including image and tables.
|
|
1305
|
+
* It must be given on initialization and cannot be changed later on.
|
|
1306
|
+
*/
|
|
1307
|
+
this.imageUploader = null;
|
|
1308
|
+
this.schema = basicSchema;
|
|
1309
|
+
/**
|
|
1310
|
+
* HTML string
|
|
1311
|
+
*/
|
|
1312
|
+
this.content = '';
|
|
1313
|
+
this.menu = null;
|
|
1314
|
+
/**
|
|
1315
|
+
* If subscribed to, then the save button will be shown and click events forwarded
|
|
1316
|
+
*/
|
|
1317
|
+
this.save = new EventEmitter();
|
|
1318
|
+
if (this.ngControl !== null) {
|
|
1319
|
+
this.ngControl.valueAccessor = this;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
ngOnInit() {
|
|
1323
|
+
this.schema = this.imageUploader ? advancedSchema : basicSchema;
|
|
1324
|
+
this.menu = buildMenuItems(this.schema, this.dialog);
|
|
1325
|
+
const serializer = DOMSerializer.fromSchema(this.schema);
|
|
1326
|
+
const state = this.createState();
|
|
1327
|
+
this.view = new EditorView(this.editor.nativeElement, {
|
|
1328
|
+
state: state,
|
|
1329
|
+
dispatchTransaction: (transaction) => {
|
|
1330
|
+
if (!this.view) {
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
const newState = this.view.state.apply(transaction);
|
|
1334
|
+
this.view.updateState(newState);
|
|
1335
|
+
// Transform doc into HTML string
|
|
1336
|
+
const dom = serializer.serializeFragment(this.view.state.doc);
|
|
1337
|
+
const el = this.document.createElement('_');
|
|
1338
|
+
el.appendChild(dom);
|
|
1339
|
+
const newContent = el.innerHTML;
|
|
1340
|
+
if (this.content === newContent) {
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
this.content = el.innerHTML;
|
|
1344
|
+
if (this.onChange) {
|
|
1345
|
+
this.onChange(this.content);
|
|
1346
|
+
}
|
|
1347
|
+
this.contentChange.emit(this.content);
|
|
1348
|
+
},
|
|
1349
|
+
});
|
|
1350
|
+
this.update();
|
|
1351
|
+
}
|
|
1352
|
+
writeValue(val) {
|
|
1353
|
+
if (typeof val === 'string' && val !== this.content) {
|
|
1354
|
+
this.content = val;
|
|
1355
|
+
}
|
|
1356
|
+
if (this.view !== null) {
|
|
1357
|
+
const state = this.createState();
|
|
1358
|
+
this.view.updateState(state);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
createState() {
|
|
1362
|
+
const template = this.document.createElement('_');
|
|
1363
|
+
template.innerHTML = '<div>' + this.content + '</div>';
|
|
1364
|
+
if (!template.firstChild) {
|
|
1365
|
+
throw new Error('child of template element could not be created');
|
|
1366
|
+
}
|
|
1367
|
+
const parser = DOMParser.fromSchema(this.schema);
|
|
1368
|
+
const doc = parser.parse(template.firstChild);
|
|
1369
|
+
return EditorState.create({
|
|
1370
|
+
doc: doc,
|
|
1371
|
+
plugins: this.createPlugins(),
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
createPlugins() {
|
|
1375
|
+
var _a;
|
|
1376
|
+
const isMac = !!((_a = this.document.defaultView) === null || _a === void 0 ? void 0 : _a.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 () {
|
|
1452
|
+
return [{ type: i4.NgControl, decorators: [{
|
|
1453
|
+
type: Optional
|
|
1454
|
+
}, {
|
|
1455
|
+
type: Self
|
|
1456
|
+
}] }, { type: Document, decorators: [{
|
|
1457
|
+
type: Inject,
|
|
1458
|
+
args: [DOCUMENT]
|
|
1459
|
+
}] }, { type: i1.MatDialog }, { type: ImagePlugin }];
|
|
1460
|
+
}, propDecorators: { editor: [{
|
|
1461
|
+
type: ViewChild,
|
|
1462
|
+
args: ['editor', { read: ElementRef, static: true }]
|
|
1463
|
+
}], contentChange: [{
|
|
1464
|
+
type: Output
|
|
1465
|
+
}], imageUploader: [{
|
|
1466
|
+
type: Input
|
|
1467
|
+
}], save: [{
|
|
1468
|
+
type: Output
|
|
1469
|
+
}] } });
|
|
1470
|
+
|
|
1471
|
+
const imports = [
|
|
1472
|
+
CommonModule,
|
|
1473
|
+
MatButtonModule,
|
|
1474
|
+
MatButtonToggleModule,
|
|
1475
|
+
MatDialogModule,
|
|
1476
|
+
MatDividerModule,
|
|
1477
|
+
MatFormFieldModule,
|
|
1478
|
+
MatIconModule,
|
|
1479
|
+
MatInputModule,
|
|
1480
|
+
MatMenuModule,
|
|
1481
|
+
MatToolbarModule,
|
|
1482
|
+
MatTooltipModule,
|
|
1483
|
+
NaturalFileModule,
|
|
1484
|
+
NaturalIconModule,
|
|
1485
|
+
ReactiveFormsModule,
|
|
1486
|
+
];
|
|
1487
|
+
const declarationsToExport = [NaturalEditorComponent, NaturalCustomCssDirective];
|
|
1488
|
+
class NaturalEditorModule {
|
|
1489
|
+
}
|
|
1490
|
+
NaturalEditorModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1491
|
+
NaturalEditorModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorModule, declarations: [ClassDialogComponent, ColorDialogComponent, LinkDialogComponent, NaturalEditorComponent, NaturalCustomCssDirective], imports: [CommonModule,
|
|
1492
|
+
MatButtonModule,
|
|
1493
|
+
MatButtonToggleModule,
|
|
1494
|
+
MatDialogModule,
|
|
1495
|
+
MatDividerModule,
|
|
1496
|
+
MatFormFieldModule,
|
|
1497
|
+
MatIconModule,
|
|
1498
|
+
MatInputModule,
|
|
1499
|
+
MatMenuModule,
|
|
1500
|
+
MatToolbarModule,
|
|
1501
|
+
MatTooltipModule,
|
|
1502
|
+
NaturalFileModule,
|
|
1503
|
+
NaturalIconModule,
|
|
1504
|
+
ReactiveFormsModule], exports: [CommonModule,
|
|
1505
|
+
MatButtonModule,
|
|
1506
|
+
MatButtonToggleModule,
|
|
1507
|
+
MatDialogModule,
|
|
1508
|
+
MatDividerModule,
|
|
1509
|
+
MatFormFieldModule,
|
|
1510
|
+
MatIconModule,
|
|
1511
|
+
MatInputModule,
|
|
1512
|
+
MatMenuModule,
|
|
1513
|
+
MatToolbarModule,
|
|
1514
|
+
MatTooltipModule,
|
|
1515
|
+
NaturalFileModule,
|
|
1516
|
+
NaturalIconModule,
|
|
1517
|
+
ReactiveFormsModule, NaturalEditorComponent, NaturalCustomCssDirective] });
|
|
1518
|
+
NaturalEditorModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorModule, imports: [[...imports], CommonModule,
|
|
1519
|
+
MatButtonModule,
|
|
1520
|
+
MatButtonToggleModule,
|
|
1521
|
+
MatDialogModule,
|
|
1522
|
+
MatDividerModule,
|
|
1523
|
+
MatFormFieldModule,
|
|
1524
|
+
MatIconModule,
|
|
1525
|
+
MatInputModule,
|
|
1526
|
+
MatMenuModule,
|
|
1527
|
+
MatToolbarModule,
|
|
1528
|
+
MatTooltipModule,
|
|
1529
|
+
NaturalFileModule,
|
|
1530
|
+
NaturalIconModule,
|
|
1531
|
+
ReactiveFormsModule] });
|
|
1532
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: NaturalEditorModule, decorators: [{
|
|
1533
|
+
type: NgModule,
|
|
1534
|
+
args: [{
|
|
1535
|
+
declarations: [ClassDialogComponent, ColorDialogComponent, LinkDialogComponent, ...declarationsToExport],
|
|
1536
|
+
imports: [...imports],
|
|
1537
|
+
exports: [...imports, ...declarationsToExport],
|
|
1538
|
+
}]
|
|
1539
|
+
}] });
|
|
1540
|
+
|
|
1541
|
+
// Load `$localize` onto the global scope - to be able to use that function to translate strings in components/services.
|
|
1542
|
+
|
|
1543
|
+
/**
|
|
1544
|
+
* Generated bundle index. Do not edit.
|
|
1545
|
+
*/
|
|
1546
|
+
|
|
1547
|
+
export { NaturalCustomCssDirective, NaturalEditorComponent, NaturalEditorModule };
|
|
1548
|
+
//# sourceMappingURL=ecodev-natural-editor.mjs.map
|