xt-plugin-editor 1.0.0 → 1.3.1
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/README.md +1 -1
- package/fesm2022/xt-plugin-editor.mjs +770 -0
- package/fesm2022/xt-plugin-editor.mjs.map +1 -0
- package/package.json +37 -64
- package/types/xt-plugin-editor.d.ts +88 -0
- package/types/xt-plugin-editor.d.ts.map +1 -0
- package/.editorconfig +0 -17
- package/.postcssrc.json +0 -1
- package/.prettierrc +0 -12
- package/.rush/temp/chunked-rush-logs/xt-plugin-editor.build.chunks.jsonl +0 -23
- package/.rush/temp/chunked-rush-logs/xt-plugin-editor.test.chunks.jsonl +0 -50
- package/.rush/temp/shrinkwrap-deps.json +0 -1200
- package/CHANGELOG.md +0 -2
- package/angular.json +0 -148
- package/projects/editor/README.md +0 -13
- package/projects/editor/ng-package.json +0 -7
- package/projects/editor/package.json +0 -43
- package/projects/editor/src/lib/editor/editor.component.css +0 -15
- package/projects/editor/src/lib/editor/editor.component.html +0 -29
- package/projects/editor/src/lib/editor/editor.component.spec.ts +0 -53
- package/projects/editor/src/lib/editor/editor.component.ts +0 -202
- package/projects/editor/src/lib/markdown/inline-markdown-pipe.spec.ts +0 -25
- package/projects/editor/src/lib/markdown/inline-markdown-pipe.ts +0 -30
- package/projects/editor/src/lib/markdown/markdown-pipe.spec.ts +0 -29
- package/projects/editor/src/lib/markdown/markdown-pipe.ts +0 -21
- package/projects/editor/src/lib/prose-mirror/basic-setup.ts +0 -655
- package/projects/editor/src/lib/register.ts +0 -33
- package/projects/editor/src/public-api.ts +0 -7
- package/projects/editor/tsconfig.lib.json +0 -13
- package/projects/editor/tsconfig.lib.prod.json +0 -11
- package/projects/editor/tsconfig.spec.json +0 -10
- package/projects/editor-plugin/federation.config.js +0 -33
- package/projects/editor-plugin/public/favicon.ico +0 -0
- package/projects/editor-plugin/src/app/app.component.css +0 -0
- package/projects/editor-plugin/src/app/app.component.html +0 -3
- package/projects/editor-plugin/src/app/app.component.spec.ts +0 -34
- package/projects/editor-plugin/src/app/app.component.ts +0 -23
- package/projects/editor-plugin/src/app/app.config.ts +0 -22
- package/projects/editor-plugin/src/app/app.routes.ts +0 -6
- package/projects/editor-plugin/src/app/editor-test-component/editor-test.component.css +0 -4
- package/projects/editor-plugin/src/app/editor-test-component/editor-test.component.html +0 -19
- package/projects/editor-plugin/src/app/editor-test-component/editor-test.component.spec.ts +0 -33
- package/projects/editor-plugin/src/app/editor-test-component/editor-test.component.ts +0 -67
- package/projects/editor-plugin/src/bootstrap.ts +0 -6
- package/projects/editor-plugin/src/index.html +0 -13
- package/projects/editor-plugin/src/main.ts +0 -6
- package/projects/editor-plugin/src/styles.css +0 -14
- package/projects/editor-plugin/tsconfig.app.json +0 -11
- package/projects/editor-plugin/tsconfig.federation.json +0 -13
- package/projects/editor-plugin/tsconfig.spec.json +0 -10
- package/rush-logs/xt-plugin-editor.build.error.log +0 -8
- package/rush-logs/xt-plugin-editor.build.log +0 -23
- package/rush-logs/xt-plugin-editor.test.error.log +0 -1
- package/rush-logs/xt-plugin-editor.test.log +0 -50
- package/tsconfig.json +0 -33
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { SecurityContext, Pipe, input, inject, viewChild, signal, effect, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
|
+
import { XtSimpleComponent, XtResolverService, updateFormGroupWithValue, XtRenderComponent } from 'xt-components';
|
|
4
|
+
import * as i1$1 from '@angular/forms';
|
|
5
|
+
import { FormGroup, ReactiveFormsModule, FormsModule } from '@angular/forms';
|
|
6
|
+
import { NodeSelection, EditorState } from 'prosemirror-state';
|
|
7
|
+
import { EditorView } from 'prosemirror-view';
|
|
8
|
+
import { schema, defaultMarkdownSerializer, defaultMarkdownParser } from 'prosemirror-markdown';
|
|
9
|
+
import { MenuItem, icons, wrapItem, blockTypeItem, Dropdown, DropdownSubmenu, joinUpItem, liftItem, selectParentNodeItem, undoItem, redoItem, menuBar } from 'prosemirror-menu';
|
|
10
|
+
import { joinUp, joinDown, lift, selectParentNode, toggleMark, wrapIn, chainCommands, exitCode, setBlockType, baseKeymap } from 'prosemirror-commands';
|
|
11
|
+
import { wrapInList, splitListItem, liftListItem, sinkListItem } from 'prosemirror-schema-list';
|
|
12
|
+
import { undo, redo, history } from 'prosemirror-history';
|
|
13
|
+
import { undoInputRule, wrappingInputRule, textblockTypeInputRule, smartQuotes, ellipsis, emDash, inputRules } from 'prosemirror-inputrules';
|
|
14
|
+
import { keymap } from 'prosemirror-keymap';
|
|
15
|
+
import { dropCursor } from 'prosemirror-dropcursor';
|
|
16
|
+
import { gapCursor } from 'prosemirror-gapcursor';
|
|
17
|
+
import { marked } from 'marked';
|
|
18
|
+
import * as i1 from '@angular/platform-browser';
|
|
19
|
+
import { Tooltip } from 'primeng/tooltip';
|
|
20
|
+
import { Dialog } from 'primeng/dialog';
|
|
21
|
+
import { ButtonDirective } from 'primeng/button';
|
|
22
|
+
|
|
23
|
+
/// Given a blockquote node type, returns an input rule that turns `"> "`
|
|
24
|
+
/// at the start of a textblock into a blockquote.
|
|
25
|
+
const prefix = "ProseMirror-prompt";
|
|
26
|
+
const mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : false;
|
|
27
|
+
/// Inspect the given schema looking for marks and nodes from the
|
|
28
|
+
/// basic schema, and if found, add key bindings related to them.
|
|
29
|
+
/// This will add:
|
|
30
|
+
///
|
|
31
|
+
/// * **Mod-b** for toggling [strong](#schema-basic.StrongMark)
|
|
32
|
+
/// * **Mod-i** for toggling [emphasis](#schema-basic.EmMark)
|
|
33
|
+
/// * **Mod-`** for toggling [code font](#schema-basic.CodeMark)
|
|
34
|
+
/// * **Ctrl-Shift-0** for making the current textblock a paragraph
|
|
35
|
+
/// * **Ctrl-Shift-1** to **Ctrl-Shift-Digit6** for making the current
|
|
36
|
+
/// textblock a heading of the corresponding level
|
|
37
|
+
/// * **Ctrl-Shift-Backslash** to make the current textblock a code block
|
|
38
|
+
/// * **Ctrl-Shift-8** to wrap the selection in an ordered list
|
|
39
|
+
/// * **Ctrl-Shift-9** to wrap the selection in a bullet list
|
|
40
|
+
/// * **Ctrl->** to wrap the selection in a block quote
|
|
41
|
+
/// * **Enter** to split a non-empty textblock in a list item while at
|
|
42
|
+
/// the same time splitting the list item
|
|
43
|
+
/// * **Mod-Enter** to insert a hard break
|
|
44
|
+
/// * **Mod-_** to insert a horizontal rule
|
|
45
|
+
/// * **Backspace** to undo an input rule
|
|
46
|
+
/// * **Alt-ArrowUp** to `joinUp`
|
|
47
|
+
/// * **Alt-ArrowDown** to `joinDown`
|
|
48
|
+
/// * **Mod-BracketLeft** to `lift`
|
|
49
|
+
/// * **Escape** to `selectParentNode`
|
|
50
|
+
///
|
|
51
|
+
/// You can suppress or map these bindings by passing a `mapKeys`
|
|
52
|
+
/// argument, which maps key names (say `"Mod-B"` to either `false`, to
|
|
53
|
+
/// remove the binding, or a new key name string.
|
|
54
|
+
function buildKeymap(schema, mapKeys) {
|
|
55
|
+
let keys = {}, type;
|
|
56
|
+
function bind(key, cmd) {
|
|
57
|
+
if (mapKeys) {
|
|
58
|
+
let mapped = mapKeys[key];
|
|
59
|
+
if (mapped === false)
|
|
60
|
+
return;
|
|
61
|
+
if (mapped)
|
|
62
|
+
key = mapped;
|
|
63
|
+
}
|
|
64
|
+
keys[key] = cmd;
|
|
65
|
+
}
|
|
66
|
+
bind("Mod-z", undo);
|
|
67
|
+
bind("Shift-Mod-z", redo);
|
|
68
|
+
bind("Backspace", undoInputRule);
|
|
69
|
+
if (!mac)
|
|
70
|
+
bind("Mod-y", redo);
|
|
71
|
+
bind("Alt-ArrowUp", joinUp);
|
|
72
|
+
bind("Alt-ArrowDown", joinDown);
|
|
73
|
+
bind("Mod-BracketLeft", lift);
|
|
74
|
+
bind("Escape", selectParentNode);
|
|
75
|
+
if (type = schema.marks["strong"]) {
|
|
76
|
+
bind("Mod-b", toggleMark(type));
|
|
77
|
+
bind("Mod-B", toggleMark(type));
|
|
78
|
+
}
|
|
79
|
+
if (type = schema.marks["em"]) {
|
|
80
|
+
bind("Mod-i", toggleMark(type));
|
|
81
|
+
bind("Mod-I", toggleMark(type));
|
|
82
|
+
}
|
|
83
|
+
if (type = schema.marks["code"])
|
|
84
|
+
bind("Mod-`", toggleMark(type));
|
|
85
|
+
if (type = schema.nodes["bullet_list"])
|
|
86
|
+
bind("Shift-Ctrl-8", wrapInList(type));
|
|
87
|
+
if (type = schema.nodes["ordered_list"])
|
|
88
|
+
bind("Shift-Ctrl-9", wrapInList(type));
|
|
89
|
+
if (type = schema.nodes["blockquote"])
|
|
90
|
+
bind("Ctrl->", wrapIn(type));
|
|
91
|
+
if (type = schema.nodes["hard_break"]) {
|
|
92
|
+
let br = type, cmd = chainCommands(exitCode, (state, dispatch) => {
|
|
93
|
+
if (dispatch)
|
|
94
|
+
dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView());
|
|
95
|
+
return true;
|
|
96
|
+
});
|
|
97
|
+
bind("Mod-Enter", cmd);
|
|
98
|
+
bind("Shift-Enter", cmd);
|
|
99
|
+
if (mac)
|
|
100
|
+
bind("Ctrl-Enter", cmd);
|
|
101
|
+
}
|
|
102
|
+
if (type = schema.nodes["list_item"]) {
|
|
103
|
+
bind("Enter", splitListItem(type));
|
|
104
|
+
bind("Mod-[", liftListItem(type));
|
|
105
|
+
bind("Mod-]", sinkListItem(type));
|
|
106
|
+
}
|
|
107
|
+
if (type = schema.nodes["paragraph"])
|
|
108
|
+
bind("Shift-Ctrl-0", setBlockType(type));
|
|
109
|
+
if (type = schema.nodes["code_block"])
|
|
110
|
+
bind("Shift-Ctrl-\\", setBlockType(type));
|
|
111
|
+
if (type = schema.nodes["heading"])
|
|
112
|
+
for (let i = 1; i <= 6; i++)
|
|
113
|
+
bind("Shift-Ctrl-" + i, setBlockType(type, { level: i }));
|
|
114
|
+
if (type = schema.nodes["horizontal_rule"]) {
|
|
115
|
+
let hr = type;
|
|
116
|
+
bind("Mod-_", (state, dispatch) => {
|
|
117
|
+
if (dispatch)
|
|
118
|
+
dispatch(state.tr.replaceSelectionWith(hr.create()).scrollIntoView());
|
|
119
|
+
return true;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return keys;
|
|
123
|
+
}
|
|
124
|
+
function openPrompt(options) {
|
|
125
|
+
let wrapper = document.body.appendChild(document.createElement("div"));
|
|
126
|
+
wrapper.className = prefix;
|
|
127
|
+
let mouseOutside = (e) => { if (!wrapper.contains(e.target))
|
|
128
|
+
close(); };
|
|
129
|
+
setTimeout(() => window.addEventListener("mousedown", mouseOutside), 50);
|
|
130
|
+
let close = () => {
|
|
131
|
+
window.removeEventListener("mousedown", mouseOutside);
|
|
132
|
+
if (wrapper.parentNode)
|
|
133
|
+
wrapper.parentNode.removeChild(wrapper);
|
|
134
|
+
};
|
|
135
|
+
let domFields = [];
|
|
136
|
+
for (let name in options.fields)
|
|
137
|
+
domFields.push(options.fields[name].render());
|
|
138
|
+
let submitButton = document.createElement("button");
|
|
139
|
+
submitButton.type = "submit";
|
|
140
|
+
submitButton.className = prefix + "-submit";
|
|
141
|
+
submitButton.textContent = "OK";
|
|
142
|
+
let cancelButton = document.createElement("button");
|
|
143
|
+
cancelButton.type = "button";
|
|
144
|
+
cancelButton.className = prefix + "-cancel";
|
|
145
|
+
cancelButton.textContent = "Cancel";
|
|
146
|
+
cancelButton.addEventListener("click", close);
|
|
147
|
+
let form = wrapper.appendChild(document.createElement("form"));
|
|
148
|
+
if (options.title)
|
|
149
|
+
form.appendChild(document.createElement("h5")).textContent = options.title;
|
|
150
|
+
domFields.forEach(field => {
|
|
151
|
+
form.appendChild(document.createElement("div")).appendChild(field);
|
|
152
|
+
});
|
|
153
|
+
let buttons = form.appendChild(document.createElement("div"));
|
|
154
|
+
buttons.className = prefix + "-buttons";
|
|
155
|
+
buttons.appendChild(submitButton);
|
|
156
|
+
buttons.appendChild(document.createTextNode(" "));
|
|
157
|
+
buttons.appendChild(cancelButton);
|
|
158
|
+
let box = wrapper.getBoundingClientRect();
|
|
159
|
+
wrapper.style.top = ((window.innerHeight - box.height) / 2) + "px";
|
|
160
|
+
wrapper.style.left = ((window.innerWidth - box.width) / 2) + "px";
|
|
161
|
+
let submit = () => {
|
|
162
|
+
let params = getValues(options.fields, domFields);
|
|
163
|
+
if (params) {
|
|
164
|
+
close();
|
|
165
|
+
options.callback(params);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
form.addEventListener("submit", e => {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
submit();
|
|
171
|
+
});
|
|
172
|
+
form.addEventListener("keydown", e => {
|
|
173
|
+
if (e.keyCode == 27) {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
close();
|
|
176
|
+
}
|
|
177
|
+
else if (e.keyCode == 13 && !(e.ctrlKey || e.metaKey || e.shiftKey)) {
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
submit();
|
|
180
|
+
}
|
|
181
|
+
else if (e.keyCode == 9) {
|
|
182
|
+
window.setTimeout(() => {
|
|
183
|
+
if (!wrapper.contains(document.activeElement))
|
|
184
|
+
close();
|
|
185
|
+
}, 500);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
let input = form.elements[0];
|
|
189
|
+
if (input)
|
|
190
|
+
input.focus();
|
|
191
|
+
}
|
|
192
|
+
function getValues(fields, domFields) {
|
|
193
|
+
let result = Object.create(null), i = 0;
|
|
194
|
+
for (let name in fields) {
|
|
195
|
+
let field = fields[name], dom = domFields[i++];
|
|
196
|
+
let value = field.read(dom), bad = field.validate(value);
|
|
197
|
+
if (bad) {
|
|
198
|
+
reportInvalid(dom, bad);
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
result[name] = field.clean(value);
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
function reportInvalid(dom, message) {
|
|
206
|
+
// FIXME this is awful and needs a lot more work
|
|
207
|
+
let parent = dom.parentNode;
|
|
208
|
+
let msg = parent.appendChild(document.createElement("div"));
|
|
209
|
+
msg.style.left = (dom.offsetLeft + dom.offsetWidth + 2) + "px";
|
|
210
|
+
msg.style.top = (dom.offsetTop - 5) + "px";
|
|
211
|
+
msg.className = "ProseMirror-invalid";
|
|
212
|
+
msg.textContent = message;
|
|
213
|
+
setTimeout(() => parent.removeChild(msg), 1500);
|
|
214
|
+
}
|
|
215
|
+
/// The type of field that `openPrompt` expects to be passed to it.
|
|
216
|
+
class Field {
|
|
217
|
+
/// Create a field with the given options. Options support by all
|
|
218
|
+
/// field types are:
|
|
219
|
+
constructor(
|
|
220
|
+
/// @internal
|
|
221
|
+
options) {
|
|
222
|
+
this.options = options;
|
|
223
|
+
}
|
|
224
|
+
/// Read the field's value from its DOM node.
|
|
225
|
+
read(dom) { return dom.value; }
|
|
226
|
+
/// A field-type-specific validation function.
|
|
227
|
+
validateType(value) { return null; }
|
|
228
|
+
/// @internal
|
|
229
|
+
validate(value) {
|
|
230
|
+
if (!value && this.options.required)
|
|
231
|
+
return "Required field";
|
|
232
|
+
return this.validateType(value) || (this.options.validate ? this.options.validate(value) : null);
|
|
233
|
+
}
|
|
234
|
+
clean(value) {
|
|
235
|
+
return this.options.clean ? this.options.clean(value) : value;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/// A field class for single-line text fields.
|
|
239
|
+
class TextField extends Field {
|
|
240
|
+
render() {
|
|
241
|
+
let input = document.createElement("input");
|
|
242
|
+
input.type = "text";
|
|
243
|
+
input.placeholder = this.options.label;
|
|
244
|
+
input.value = this.options.value || "";
|
|
245
|
+
input.autocomplete = "off";
|
|
246
|
+
return input;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/// A field class for dropdown fields based on a plain `<select>`
|
|
250
|
+
/// tag. Expects an option `options`, which should be an array of
|
|
251
|
+
/// `{value: string, label: string}` objects, or a function taking a
|
|
252
|
+
/// `ProseMirror` instance and returning such an array.
|
|
253
|
+
class SelectField extends Field {
|
|
254
|
+
render() {
|
|
255
|
+
let select = document.createElement("select");
|
|
256
|
+
this.options.options.forEach(o => {
|
|
257
|
+
let opt = select.appendChild(document.createElement("option"));
|
|
258
|
+
opt.value = o.value;
|
|
259
|
+
opt.selected = o.value == this.options.value;
|
|
260
|
+
opt.label = o.label;
|
|
261
|
+
});
|
|
262
|
+
return select;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Helpers to create specific types of items
|
|
266
|
+
function canInsert(state, nodeType) {
|
|
267
|
+
let $from = state.selection.$from;
|
|
268
|
+
for (let d = $from.depth; d >= 0; d--) {
|
|
269
|
+
let index = $from.index(d);
|
|
270
|
+
if ($from.node(d).canReplaceWith(index, index, nodeType))
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
function insertImageItem(nodeType) {
|
|
276
|
+
return new MenuItem({
|
|
277
|
+
title: "Insert image",
|
|
278
|
+
label: "Image",
|
|
279
|
+
enable(state) { return canInsert(state, nodeType); },
|
|
280
|
+
run(state, _, view) {
|
|
281
|
+
let { from, to } = state.selection, attrs = null;
|
|
282
|
+
if (state.selection instanceof NodeSelection && state.selection.node.type == nodeType)
|
|
283
|
+
attrs = state.selection.node.attrs;
|
|
284
|
+
openPrompt({
|
|
285
|
+
title: "Insert image",
|
|
286
|
+
fields: {
|
|
287
|
+
src: new TextField({ label: "Location", required: true, value: attrs && attrs["src"] }),
|
|
288
|
+
title: new TextField({ label: "Title", value: attrs && attrs["title"] }),
|
|
289
|
+
alt: new TextField({ label: "Description",
|
|
290
|
+
value: attrs ? attrs["alt"] : state.doc.textBetween(from, to, " ") })
|
|
291
|
+
},
|
|
292
|
+
callback(attrs) {
|
|
293
|
+
view.dispatch(view.state.tr.replaceSelectionWith(nodeType.createAndFill(attrs)));
|
|
294
|
+
view.focus();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function cmdItem(cmd, options) {
|
|
301
|
+
let passedOptions = {
|
|
302
|
+
label: options.title,
|
|
303
|
+
run: cmd
|
|
304
|
+
};
|
|
305
|
+
for (let prop in options)
|
|
306
|
+
passedOptions[prop] = options[prop];
|
|
307
|
+
if (!options.enable && !options.select)
|
|
308
|
+
passedOptions[options.enable ? "enable" : "select"] = state => cmd(state);
|
|
309
|
+
return new MenuItem(passedOptions);
|
|
310
|
+
}
|
|
311
|
+
function markActive(state, type) {
|
|
312
|
+
let { from, $from, to, empty } = state.selection;
|
|
313
|
+
if (empty)
|
|
314
|
+
return !!type.isInSet(state.storedMarks || $from.marks());
|
|
315
|
+
else
|
|
316
|
+
return state.doc.rangeHasMark(from, to, type);
|
|
317
|
+
}
|
|
318
|
+
function markItem(markType, options) {
|
|
319
|
+
let passedOptions = {
|
|
320
|
+
active(state) { return markActive(state, markType); }
|
|
321
|
+
};
|
|
322
|
+
for (let prop in options)
|
|
323
|
+
passedOptions[prop] = options[prop];
|
|
324
|
+
return cmdItem(toggleMark(markType), passedOptions);
|
|
325
|
+
}
|
|
326
|
+
function linkItem(markType) {
|
|
327
|
+
return new MenuItem({
|
|
328
|
+
title: "Add or remove link",
|
|
329
|
+
icon: icons["link"],
|
|
330
|
+
active(state) { return markActive(state, markType); },
|
|
331
|
+
enable(state) { return !state.selection.empty; },
|
|
332
|
+
run(state, dispatch, view) {
|
|
333
|
+
if (markActive(state, markType)) {
|
|
334
|
+
toggleMark(markType)(state, dispatch);
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
openPrompt({
|
|
338
|
+
title: "Create a link",
|
|
339
|
+
fields: {
|
|
340
|
+
href: new TextField({
|
|
341
|
+
label: "Link target",
|
|
342
|
+
required: true
|
|
343
|
+
}),
|
|
344
|
+
title: new TextField({ label: "Title" })
|
|
345
|
+
},
|
|
346
|
+
callback(attrs) {
|
|
347
|
+
toggleMark(markType, attrs)(view.state, view.dispatch);
|
|
348
|
+
view.focus();
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
function wrapListItem(nodeType, options) {
|
|
356
|
+
return cmdItem(wrapInList(nodeType, options.attrs), options);
|
|
357
|
+
}
|
|
358
|
+
/// Given a schema, look for default mark and node types in it and
|
|
359
|
+
/// return an object with relevant menu items relating to those marks.
|
|
360
|
+
function buildMenuItems(schema, override) {
|
|
361
|
+
let r = {};
|
|
362
|
+
let mark;
|
|
363
|
+
override = override || {};
|
|
364
|
+
if (mark = schema.marks["strong"])
|
|
365
|
+
r.toggleStrong = override["strong"] || markItem(mark, { title: "Toggle strong style", icon: icons["strong"] });
|
|
366
|
+
if (mark = schema.marks["em"])
|
|
367
|
+
r.toggleEm = override["em"] || markItem(mark, { title: "Toggle emphasis", icon: icons["em"] });
|
|
368
|
+
if (mark = schema.marks["code"])
|
|
369
|
+
r.toggleCode = override["code"] || markItem(mark, { title: "Toggle code font", icon: icons["code"] });
|
|
370
|
+
if (mark = schema.marks["link"])
|
|
371
|
+
r.toggleLink = override["link"] || linkItem(mark);
|
|
372
|
+
let node;
|
|
373
|
+
if (node = schema.nodes["image"])
|
|
374
|
+
r.insertImage = override["image"] || insertImageItem(node);
|
|
375
|
+
if (node = schema.nodes["bullet_list"])
|
|
376
|
+
r.wrapBulletList = override["bullet_list"] || wrapListItem(node, {
|
|
377
|
+
title: "Wrap in bullet list",
|
|
378
|
+
icon: icons["bulletList"]
|
|
379
|
+
});
|
|
380
|
+
if (node = schema.nodes["ordered_list"])
|
|
381
|
+
r.wrapOrderedList = override["ordered_list"] || wrapListItem(node, {
|
|
382
|
+
title: "Wrap in ordered list",
|
|
383
|
+
icon: icons["orderedList"]
|
|
384
|
+
});
|
|
385
|
+
if (node = schema.nodes["blockquote"])
|
|
386
|
+
r.wrapBlockQuote = override["blockquote"] || wrapItem(node, {
|
|
387
|
+
title: "Wrap in block quote",
|
|
388
|
+
icon: icons["blockquote"]
|
|
389
|
+
});
|
|
390
|
+
if (node = schema.nodes["paragraph"])
|
|
391
|
+
r.makeParagraph = override["paragraph"] || blockTypeItem(node, {
|
|
392
|
+
title: "Change to paragraph",
|
|
393
|
+
label: "Plain"
|
|
394
|
+
});
|
|
395
|
+
if (node = schema.nodes["code_block"])
|
|
396
|
+
r.makeCodeBlock = override["code_block"] || blockTypeItem(node, {
|
|
397
|
+
title: "Change to code block",
|
|
398
|
+
label: "Code"
|
|
399
|
+
});
|
|
400
|
+
if (node = schema.nodes["heading"])
|
|
401
|
+
for (let i = 1; i <= 10; i++)
|
|
402
|
+
r["makeHead" + i] = override["makeHead" + i] || blockTypeItem(node, {
|
|
403
|
+
title: "Change to heading " + i,
|
|
404
|
+
label: "Level " + i,
|
|
405
|
+
attrs: { level: i }
|
|
406
|
+
});
|
|
407
|
+
if (node = schema.nodes["horizontal_rule"]) {
|
|
408
|
+
let hr = node;
|
|
409
|
+
r.insertHorizontalRule = override["horizontal_rule"] || new MenuItem({
|
|
410
|
+
title: "Insert horizontal rule",
|
|
411
|
+
label: "Horizontal rule",
|
|
412
|
+
enable(state) { return canInsert(state, hr); },
|
|
413
|
+
run(state, dispatch) { dispatch(state.tr.replaceSelectionWith(hr.create())); }
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
let cut = (arr) => arr.filter(x => x);
|
|
417
|
+
r.insertMenu = new Dropdown(cut([r.insertImage, r.insertHorizontalRule]), { label: "Insert" });
|
|
418
|
+
r.typeMenu = new Dropdown(cut([r.makeParagraph, r.makeCodeBlock, r.makeHead1 && new DropdownSubmenu(cut([
|
|
419
|
+
r.makeHead1, r.makeHead2, r.makeHead3, r.makeHead4, r.makeHead5, r.makeHead6
|
|
420
|
+
]), { label: "Heading" })]), { label: "Type..." });
|
|
421
|
+
r.inlineMenu = [cut([r.toggleStrong, r.toggleEm, r.toggleCode, r.toggleLink])];
|
|
422
|
+
r.blockMenu = [cut([r.wrapBulletList, r.wrapOrderedList, r.wrapBlockQuote, joinUpItem,
|
|
423
|
+
liftItem, selectParentNodeItem])];
|
|
424
|
+
r.fullMenu = r.inlineMenu.concat([[r.insertMenu, r.typeMenu]], [[undoItem, redoItem]], r.blockMenu);
|
|
425
|
+
return r;
|
|
426
|
+
}
|
|
427
|
+
function blockQuoteRule(nodeType) {
|
|
428
|
+
return wrappingInputRule(/^\s*>\s$/, nodeType);
|
|
429
|
+
}
|
|
430
|
+
/// Given a list node type, returns an input rule that turns a number
|
|
431
|
+
/// followed by a dot at the start of a textblock into an ordered list.
|
|
432
|
+
function orderedListRule(nodeType) {
|
|
433
|
+
return wrappingInputRule(/^(\d+)\.\s$/, nodeType, match => ({ order: +match[1] }), (match, node) => node.childCount + node.attrs["order"] == +match[1]);
|
|
434
|
+
}
|
|
435
|
+
/// Given a list node type, returns an input rule that turns a bullet
|
|
436
|
+
/// (dash, plush, or asterisk) at the start of a textblock into a
|
|
437
|
+
/// bullet list.
|
|
438
|
+
function bulletListRule(nodeType) {
|
|
439
|
+
return wrappingInputRule(/^\s*([-+*])\s$/, nodeType);
|
|
440
|
+
}
|
|
441
|
+
/// Given a code block node type, returns an input rule that turns a
|
|
442
|
+
/// textblock starting with three backticks into a code block.
|
|
443
|
+
function codeBlockRule(nodeType) {
|
|
444
|
+
return textblockTypeInputRule(/^```$/, nodeType);
|
|
445
|
+
}
|
|
446
|
+
/// Given a node type and a maximum level, creates an input rule that
|
|
447
|
+
/// turns up to that number of `#` characters followed by a space at
|
|
448
|
+
/// the start of a textblock into a heading whose level corresponds to
|
|
449
|
+
/// the number of `#` signs.
|
|
450
|
+
function headingRule(nodeType, maxLevel) {
|
|
451
|
+
return textblockTypeInputRule(new RegExp("^(#{1," + maxLevel + "})\\s$"), nodeType, match => ({ level: match[1].length }));
|
|
452
|
+
}
|
|
453
|
+
/// A set of input rules for creating the basic block quotes, lists,
|
|
454
|
+
/// code blocks, and heading.
|
|
455
|
+
function buildInputRules(schema) {
|
|
456
|
+
let rules = smartQuotes.concat(ellipsis, emDash), type;
|
|
457
|
+
if (type = schema.nodes["blockquote"])
|
|
458
|
+
rules.push(blockQuoteRule(type));
|
|
459
|
+
if (type = schema.nodes["ordered_list"])
|
|
460
|
+
rules.push(orderedListRule(type));
|
|
461
|
+
if (type = schema.nodes["bullet_list"])
|
|
462
|
+
rules.push(bulletListRule(type));
|
|
463
|
+
if (type = schema.nodes["code_block"])
|
|
464
|
+
rules.push(codeBlockRule(type));
|
|
465
|
+
if (type = schema.nodes["heading"])
|
|
466
|
+
rules.push(headingRule(type, 6));
|
|
467
|
+
return inputRules({ rules });
|
|
468
|
+
}
|
|
469
|
+
/// Create an array of plugins pre-configured for the given schema.
|
|
470
|
+
/// The resulting array will include the following plugins:
|
|
471
|
+
///
|
|
472
|
+
/// * Input rules for smart quotes and creating the block types in the
|
|
473
|
+
/// schema using markdown conventions (say `"> "` to create a
|
|
474
|
+
/// blockquote)
|
|
475
|
+
///
|
|
476
|
+
/// * A keymap that defines keys to create and manipulate the nodes in the
|
|
477
|
+
/// schema
|
|
478
|
+
///
|
|
479
|
+
/// * A keymap binding the default keys provided by the
|
|
480
|
+
/// prosemirror-commands module
|
|
481
|
+
///
|
|
482
|
+
/// * The undo history plugin
|
|
483
|
+
///
|
|
484
|
+
/// * The drop cursor plugin
|
|
485
|
+
///
|
|
486
|
+
/// * The gap cursor plugin
|
|
487
|
+
///
|
|
488
|
+
/// * A custom plugin that adds a `menuContent` prop for the
|
|
489
|
+
/// prosemirror-menu wrapper, and a CSS class that enables the
|
|
490
|
+
/// additional styling defined in `style/style.css` in this package
|
|
491
|
+
///
|
|
492
|
+
/// Probably only useful for quickly setting up a passable
|
|
493
|
+
/// editor—you'll need more control over your settings in most
|
|
494
|
+
/// real-world situations.
|
|
495
|
+
function basicSetup(options) {
|
|
496
|
+
let plugins = [
|
|
497
|
+
buildInputRules(options.schema),
|
|
498
|
+
keymap(buildKeymap(options.schema, options.mapKeys)),
|
|
499
|
+
keymap(baseKeymap),
|
|
500
|
+
dropCursor(),
|
|
501
|
+
gapCursor()
|
|
502
|
+
];
|
|
503
|
+
if (options.menuBar !== false)
|
|
504
|
+
plugins.push(menuBar({ floating: options.floatingMenu !== false,
|
|
505
|
+
content: buildMenuItems(options.schema, options.menuContent).fullMenu }));
|
|
506
|
+
if (options.history !== false)
|
|
507
|
+
plugins.push(history());
|
|
508
|
+
return plugins; /*.concat(new Plugin({
|
|
509
|
+
props: {
|
|
510
|
+
attributes: {class: "ProseMirror-example-setup-style"}
|
|
511
|
+
}
|
|
512
|
+
}))*/
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
class MarkdownPipe {
|
|
516
|
+
constructor(sanitizer) {
|
|
517
|
+
this.sanitizer = sanitizer;
|
|
518
|
+
}
|
|
519
|
+
transform(value, ...args) {
|
|
520
|
+
if (typeof value === 'string') {
|
|
521
|
+
const html = marked.parse(value.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/, ""), {
|
|
522
|
+
async: false
|
|
523
|
+
});
|
|
524
|
+
return this.sanitizer.sanitize(SecurityContext.HTML, html);
|
|
525
|
+
}
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: MarkdownPipe, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
529
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.25", ngImport: i0, type: MarkdownPipe, isStandalone: true, name: "markdown" }); }
|
|
530
|
+
}
|
|
531
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: MarkdownPipe, decorators: [{
|
|
532
|
+
type: Pipe,
|
|
533
|
+
args: [{
|
|
534
|
+
name: 'markdown',
|
|
535
|
+
}]
|
|
536
|
+
}], ctorParameters: () => [{ type: i1.DomSanitizer }] });
|
|
537
|
+
|
|
538
|
+
class InlineMarkdownPipe {
|
|
539
|
+
transform(value, ...args) {
|
|
540
|
+
if (typeof value === 'string') {
|
|
541
|
+
let text = value;
|
|
542
|
+
if (text.length > 100)
|
|
543
|
+
text = text.substring(0, 100); // For inline text, we don't want all the text, just the start
|
|
544
|
+
text = text.replace(/!\[[^\]]*\]\([^)]*\)/g, ''); // images
|
|
545
|
+
text = text.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1'); // links -> visible text
|
|
546
|
+
text = text.replace(/^#{1,6}\s*/gm, ''); // headers
|
|
547
|
+
text = text.replace(/^\s*[-*+]\s+/gm, ''); // bullet lists
|
|
548
|
+
text = text.replace(/^\s*\d+[.)]\s+/gm, ''); // numbered lists
|
|
549
|
+
text = text.replace(/^\s*[-*]\s+/gm, ''); // bullets that were bold markers
|
|
550
|
+
text = text.replace(/\*\*([^*]*)\*\*/g, '$1'); // bold
|
|
551
|
+
text = text.replace(/\*([^*]*)\*/g, '$1'); // italic *
|
|
552
|
+
text = text.replace(/(?<!\w)_([^_\n]+)_(?!\w)/g, '$1'); // italic _text_
|
|
553
|
+
text = text.replace(/\s*\n\s*/g, ' '); // newlines -> spaces
|
|
554
|
+
text = text.replace(/\s{2,}/g, ' ').trim(); // collapse
|
|
555
|
+
if (text.length > 57) {
|
|
556
|
+
return text.substring(0, 57) + '...';
|
|
557
|
+
}
|
|
558
|
+
return text;
|
|
559
|
+
}
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: InlineMarkdownPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
563
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.25", ngImport: i0, type: InlineMarkdownPipe, isStandalone: true, name: "inlineMarkdown" }); }
|
|
564
|
+
}
|
|
565
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: InlineMarkdownPipe, decorators: [{
|
|
566
|
+
type: Pipe,
|
|
567
|
+
args: [{
|
|
568
|
+
name: 'inlineMarkdown',
|
|
569
|
+
}]
|
|
570
|
+
}] });
|
|
571
|
+
|
|
572
|
+
class EditorComponent extends XtSimpleComponent {
|
|
573
|
+
constructor() {
|
|
574
|
+
super();
|
|
575
|
+
this.context = input.required(...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
|
|
576
|
+
this.resolver = inject(XtResolverService);
|
|
577
|
+
this.editor = viewChild('editor', ...(ngDevMode ? [{ debugName: "editor" }] : /* istanbul ignore next */ []));
|
|
578
|
+
this.sampleJson = { "type": "doc", "content": [{ "type": "heading", "attrs": { "level": 1 }, "content": [{ "type": "text", "text": "Example Text" }] }, { "type": "paragraph", "content": [{ "type": "text", "text": "s it working ?" }] }] };
|
|
579
|
+
this.emptyJson = { "type": "doc", "content": [{ "type": "paragraph" }] };
|
|
580
|
+
// Mix the nodes from prosemirror-schema-list into the basic schema to create a schema with list support.
|
|
581
|
+
/** mySchema: Schema = new Schema({
|
|
582
|
+
nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block"),
|
|
583
|
+
marks: schema.spec.marks
|
|
584
|
+
});*/
|
|
585
|
+
// Creates the markdown schema
|
|
586
|
+
this.mySchema = schema;
|
|
587
|
+
this.view = null;
|
|
588
|
+
/**
|
|
589
|
+
* Enable dialog box for image or link editing
|
|
590
|
+
* @protected
|
|
591
|
+
*/
|
|
592
|
+
this.displayAttrDialog = signal(false, ...(ngDevMode ? [{ debugName: "displayAttrDialog" }] : /* istanbul ignore next */ []));
|
|
593
|
+
this.editAttrForm = new FormGroup({});
|
|
594
|
+
this.editAttrNodeType = this.mySchema['image'];
|
|
595
|
+
this.editAttrValueType = "editorImageType";
|
|
596
|
+
const imageType = this.resolver.typeResolver.findType('image');
|
|
597
|
+
const linkType = this.resolver.typeResolver.findType('link');
|
|
598
|
+
// Register the type with the image type if supported
|
|
599
|
+
this.resolver.registerTypes({
|
|
600
|
+
editorImageType: {
|
|
601
|
+
children: {
|
|
602
|
+
src: (imageType == null) ? "string" : "image",
|
|
603
|
+
title: "string",
|
|
604
|
+
alt: "string"
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
editorLinkType: {
|
|
608
|
+
children: {
|
|
609
|
+
href: (linkType == null) ? "string" : "link",
|
|
610
|
+
title: "string"
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
updateFormGroupWithValue(this.editAttrForm, {}, 'editorImageType', this.resolver.typeResolver);
|
|
615
|
+
// Setup the editor once the divs are available
|
|
616
|
+
effect(() => {
|
|
617
|
+
const editor = this.editor();
|
|
618
|
+
if ((editor != null) && (this.view == null)) {
|
|
619
|
+
const value = this.context().formControlValue();
|
|
620
|
+
const doc = this.toProseMirrorDoc(value);
|
|
621
|
+
this.view = new EditorView(editor.nativeElement, {
|
|
622
|
+
state: EditorState.create({
|
|
623
|
+
doc: doc,
|
|
624
|
+
plugins: basicSetup({ schema: this.mySchema, menuContent: {
|
|
625
|
+
image: this.imageMenu(this.mySchema.nodes['image'], this),
|
|
626
|
+
link: this.linkMenu(this.mySchema.marks['link'], this)
|
|
627
|
+
} })
|
|
628
|
+
}),
|
|
629
|
+
dispatchTransaction: this.handleTransactions.bind(this)
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
ngAfterViewInit() {
|
|
635
|
+
/* this.editor.valueChanges.pipe(takeUntil(this.unsubscribe)).subscribe((jsonDoc) => {
|
|
636
|
+
this.handleChange(jsonDoc);
|
|
637
|
+
});*/
|
|
638
|
+
}
|
|
639
|
+
imageMenu(imageNodeType, that) {
|
|
640
|
+
return new MenuItem({
|
|
641
|
+
title: "Insert image",
|
|
642
|
+
label: "Image",
|
|
643
|
+
enable(state) {
|
|
644
|
+
return canInsert(state, imageNodeType);
|
|
645
|
+
},
|
|
646
|
+
run(state, _, view) {
|
|
647
|
+
let { from, to } = state.selection, attrs = {};
|
|
648
|
+
if (state.selection instanceof NodeSelection && state.selection.node.type == imageNodeType)
|
|
649
|
+
attrs = state.selection.node.attrs || {};
|
|
650
|
+
if (attrs.alt == null)
|
|
651
|
+
attrs.alt = state.doc.textBetween(from, to, " ");
|
|
652
|
+
that.editAttrValueType = "editorImageType";
|
|
653
|
+
updateFormGroupWithValue(that.editAttrForm, attrs, that.editAttrValueType, that.resolver.typeResolver);
|
|
654
|
+
that.editAttrNodeType = imageNodeType;
|
|
655
|
+
that.displayAttrDialog.set(true);
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
updateAttrsFromForm() {
|
|
660
|
+
if (this.view != null) {
|
|
661
|
+
if (this.editAttrValueType == "editorImageType") {
|
|
662
|
+
this.view.dispatch(this.view.state.tr.replaceSelectionWith((this.mySchema.nodes['image']).createAndFill(this.editAttrForm.value)));
|
|
663
|
+
}
|
|
664
|
+
else if (this.editAttrValueType == "editorLinkType") {
|
|
665
|
+
toggleMark(this.editAttrNodeType, this.editAttrForm.value)(this.view.state, this.view.dispatch);
|
|
666
|
+
}
|
|
667
|
+
this.view.focus();
|
|
668
|
+
}
|
|
669
|
+
this.displayAttrDialog.set(false);
|
|
670
|
+
}
|
|
671
|
+
linkMenu(linkMarkType, that) {
|
|
672
|
+
return new MenuItem({
|
|
673
|
+
title: "Add or Remove link",
|
|
674
|
+
icon: icons["link"],
|
|
675
|
+
active(state) { return markActive(state, linkMarkType); },
|
|
676
|
+
enable(state) { return !state.selection.empty; },
|
|
677
|
+
run(state, _, view) {
|
|
678
|
+
let { from, to } = state.selection, attrs = {};
|
|
679
|
+
if (markActive(state, linkMarkType)) {
|
|
680
|
+
toggleMark(linkMarkType)(state, view.dispatch);
|
|
681
|
+
return true;
|
|
682
|
+
}
|
|
683
|
+
that.editAttrValueType = "editorLinkType";
|
|
684
|
+
updateFormGroupWithValue(that.editAttrForm, attrs, that.editAttrValueType, that.resolver.typeResolver);
|
|
685
|
+
that.editAttrNodeType = linkMarkType;
|
|
686
|
+
that.displayAttrDialog.set(true);
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
handleTransactions(tr) {
|
|
692
|
+
if (this.view != null) {
|
|
693
|
+
const state = this.view.state.apply(tr);
|
|
694
|
+
this.view.updateState(state);
|
|
695
|
+
if (tr.docChanged) {
|
|
696
|
+
const markdown = defaultMarkdownSerializer.serialize(state.doc);
|
|
697
|
+
this.context().setFormValue(markdown, true);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
console.error("Editor: View transaction received while no view defined.", tr.doc.toJSON());
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
toProseMirrorDoc(value) {
|
|
705
|
+
if (value == null) {
|
|
706
|
+
return this.mySchema.nodeFromJSON(this.emptyJson);
|
|
707
|
+
}
|
|
708
|
+
if (typeof value === 'string') {
|
|
709
|
+
// This is a markdown text,
|
|
710
|
+
return defaultMarkdownParser.parse(value);
|
|
711
|
+
}
|
|
712
|
+
return this.mySchema.nodeFromJSON(value);
|
|
713
|
+
}
|
|
714
|
+
textJson(text) {
|
|
715
|
+
return { "type": "doc", "content": [{ "type": "paragraph", "content": [{ "type": "text", "text": text }] }] };
|
|
716
|
+
}
|
|
717
|
+
;
|
|
718
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: EditorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
719
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.25", type: EditorComponent, isStandalone: true, selector: "xt-editor-editor", inputs: { context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: true, transformFunction: null } }, viewQueries: [{ propertyName: "editor", first: true, predicate: ["editor"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: "@if (isInForm() ) {\n <div class=\"editorContainer\">\n <div #editor [formGroup]=\"formGroup()\">\n </div>\n </div>\n <p-dialog [visible]=\"displayAttrDialog()\" [modal]=\"true\" header=\"Edit\">\n <form [formGroup]=\"editAttrForm\">\n <xt-render [valueType]=\"editAttrValueType\" [formGroup]=\"editAttrForm\" displayMode=\"FULL_EDITABLE\" ></xt-render>\n </form>\n <ng-template #footer>\n <button type=\"button\" pButton severity=\"secondary\" variant=\"outlined\" (click)=\"displayAttrDialog.set(false)\">Cancel</button>\n <button type=\"button\" pButton (click)=\"updateAttrsFromForm()\">Save</button>\n </ng-template>\n </p-dialog>\n} @else {\n @let toDisplay=displayValue();\n @if (toDisplay!=null) {\n @if (context().displayMode=='FULL_VIEW') {\n <div class=\"displayForm\" [innerHTML]=\"displayValue() | markdown\">\n </div>\n } @else {\n <span [pTooltip]=\"fullText\">{{ toDisplay | inlineMarkdown}}</span>\n <ng-template #fullText>\n <div class=\"toolTip\" [innerHTML]=\"displayValue() | markdown\">\n </div>\n </ng-template>\n }\n }\n}\n", styles: [".editorContainer{width:60em;border:white solid thin;padding:5px}.toolTip{white-space:normal}\n"], dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1$1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: Tooltip, selector: "[pTooltip]", inputs: ["tooltipPosition", "tooltipEvent", "positionStyle", "tooltipStyleClass", "tooltipZIndex", "escape", "showDelay", "hideDelay", "life", "positionTop", "positionLeft", "autoHide", "fitContent", "hideOnEscape", "showOnEllipsis", "pTooltip", "tooltipDisabled", "tooltipOptions", "appendTo", "ptTooltip", "pTooltipPT", "pTooltipUnstyled"] }, { kind: "component", type: Dialog, selector: "p-dialog", inputs: ["hostName", "header", "draggable", "resizable", "contentStyle", "contentStyleClass", "modal", "closeOnEscape", "dismissableMask", "rtl", "closable", "breakpoints", "styleClass", "maskStyleClass", "maskStyle", "showHeader", "blockScroll", "autoZIndex", "baseZIndex", "minX", "minY", "focusOnShow", "maximizable", "keepInViewport", "focusTrap", "transitionOptions", "maskMotionOptions", "motionOptions", "closeIcon", "closeAriaLabel", "closeTabindex", "minimizeIcon", "maximizeIcon", "closeButtonProps", "maximizeButtonProps", "visible", "style", "position", "role", "appendTo", "content", "contentTemplate", "footerTemplate", "closeIconTemplate", "maximizeIconTemplate", "minimizeIconTemplate", "headlessTemplate"], outputs: ["onShow", "onHide", "visibleChange", "onResizeInit", "onResizeEnd", "onDragEnd", "onMaximize"] }, { kind: "component", type: XtRenderComponent, selector: "xt-render", inputs: ["componentType", "displayMode", "valueType", "value", "formGroup", "subName", "inputs", "models"], outputs: ["valueChange", "outputs"] }, { kind: "directive", type: ButtonDirective, selector: "[pButton]", inputs: ["ptButtonDirective", "pButtonPT", "pButtonUnstyled", "hostName", "text", "plain", "raised", "size", "outlined", "rounded", "iconPos", "loadingIcon", "fluid", "label", "icon", "loading", "buttonProps", "severity"] }, { kind: "pipe", type: MarkdownPipe, name: "markdown" }, { kind: "pipe", type: InlineMarkdownPipe, name: "inlineMarkdown" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
720
|
+
}
|
|
721
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: EditorComponent, decorators: [{
|
|
722
|
+
type: Component,
|
|
723
|
+
args: [{ selector: 'xt-editor-editor', imports: [
|
|
724
|
+
ReactiveFormsModule,
|
|
725
|
+
FormsModule,
|
|
726
|
+
MarkdownPipe, InlineMarkdownPipe, Tooltip, Dialog,
|
|
727
|
+
XtRenderComponent, ButtonDirective
|
|
728
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (isInForm() ) {\n <div class=\"editorContainer\">\n <div #editor [formGroup]=\"formGroup()\">\n </div>\n </div>\n <p-dialog [visible]=\"displayAttrDialog()\" [modal]=\"true\" header=\"Edit\">\n <form [formGroup]=\"editAttrForm\">\n <xt-render [valueType]=\"editAttrValueType\" [formGroup]=\"editAttrForm\" displayMode=\"FULL_EDITABLE\" ></xt-render>\n </form>\n <ng-template #footer>\n <button type=\"button\" pButton severity=\"secondary\" variant=\"outlined\" (click)=\"displayAttrDialog.set(false)\">Cancel</button>\n <button type=\"button\" pButton (click)=\"updateAttrsFromForm()\">Save</button>\n </ng-template>\n </p-dialog>\n} @else {\n @let toDisplay=displayValue();\n @if (toDisplay!=null) {\n @if (context().displayMode=='FULL_VIEW') {\n <div class=\"displayForm\" [innerHTML]=\"displayValue() | markdown\">\n </div>\n } @else {\n <span [pTooltip]=\"fullText\">{{ toDisplay | inlineMarkdown}}</span>\n <ng-template #fullText>\n <div class=\"toolTip\" [innerHTML]=\"displayValue() | markdown\">\n </div>\n </ng-template>\n }\n }\n}\n", styles: [".editorContainer{width:60em;border:white solid thin;padding:5px}.toolTip{white-space:normal}\n"] }]
|
|
729
|
+
}], ctorParameters: () => [], propDecorators: { context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: true }] }], editor: [{ type: i0.ViewChild, args: ['editor', { isSignal: true }] }] } });
|
|
730
|
+
|
|
731
|
+
function registerEditorPlugin(resolverService) {
|
|
732
|
+
const pluginName = "Plugin Editor";
|
|
733
|
+
console.info('Registering ' + pluginName);
|
|
734
|
+
resolverService.registerPlugin({
|
|
735
|
+
name: pluginName,
|
|
736
|
+
uriLogo: 'pluginicon.png',
|
|
737
|
+
cssUrls: [
|
|
738
|
+
'prosemirror-view/style/prosemirror.css',
|
|
739
|
+
'prosemirror-menu/style/menu.css',
|
|
740
|
+
'prosemirror-gapcursor/style/gapcursor.css'
|
|
741
|
+
],
|
|
742
|
+
components: [
|
|
743
|
+
{
|
|
744
|
+
componentName: 'Editor',
|
|
745
|
+
componentClass: EditorComponent,
|
|
746
|
+
typesHandled: ['markdown', 'rich-text', 'description'],
|
|
747
|
+
}
|
|
748
|
+
],
|
|
749
|
+
types: {
|
|
750
|
+
'markdown': 'string',
|
|
751
|
+
'rich-text': 'string',
|
|
752
|
+
'description': 'string'
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
return pluginName;
|
|
756
|
+
}
|
|
757
|
+
function registerPlugin(resolverService) {
|
|
758
|
+
return registerEditorPlugin(resolverService);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/*
|
|
762
|
+
* Public API Surface of web plugin
|
|
763
|
+
*/
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Generated bundle index. Do not edit.
|
|
767
|
+
*/
|
|
768
|
+
|
|
769
|
+
export { EditorComponent, MarkdownPipe, registerEditorPlugin, registerPlugin };
|
|
770
|
+
//# sourceMappingURL=xt-plugin-editor.mjs.map
|