@3kles/kles-richtext-editor 0.0.0-stage → 1.0.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.
|
@@ -0,0 +1,1666 @@
|
|
|
1
|
+
import { JsonPipe, NgTemplateOutlet, isPlatformBrowser } from "@angular/common";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { APP_ID, ChangeDetectionStrategy, Component, DestroyRef, ElementRef, Injectable, InjectionToken, PLATFORM_ID, ViewChild, booleanAttribute, computed, effect, forwardRef, inject, input, output, signal, untracked, viewChild } from "@angular/core";
|
|
4
|
+
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
5
|
+
import { compareTextPoints, createEmptyDocument, getNodeAtPath, getTextBlockText, resolveTextBlock, safeLinkPolicy, validateDocument } from "@3kles/richtext-core";
|
|
6
|
+
import { createEditor } from "@3kles/richtext-dom";
|
|
7
|
+
const RICHTEXT_I18N = new InjectionToken("RICHTEXT_I18N", {
|
|
8
|
+
providedIn: "root",
|
|
9
|
+
factory: () => Object.freeze({ locale: "fr" })
|
|
10
|
+
});
|
|
11
|
+
function provideRichTextI18n(options) {
|
|
12
|
+
return {
|
|
13
|
+
provide: RICHTEXT_I18N,
|
|
14
|
+
useValue: Object.freeze({
|
|
15
|
+
...options,
|
|
16
|
+
...options.messages ? { messages: Object.freeze({ ...options.messages }) } : {}
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const RICHTEXT_MESSAGES_FR = Object.freeze({
|
|
21
|
+
editorLabel: "Contenu du document",
|
|
22
|
+
invalidDocument: "La valeur doit être un document 3KLES valide.",
|
|
23
|
+
requiredDocument: "Le document doit contenir du texte.",
|
|
24
|
+
validationError: "Le document comporte une erreur de validation.",
|
|
25
|
+
previewLabel: "Représentation JSON du document",
|
|
26
|
+
toolbarLabel: "Mise en forme du document",
|
|
27
|
+
toolbarFields: "Options de titre et de lien",
|
|
28
|
+
headingLevel: "Niveau",
|
|
29
|
+
headingLevelLabel: "Niveau du titre",
|
|
30
|
+
linkAddress: "Adresse du lien",
|
|
31
|
+
applyLink: "Appliquer le lien",
|
|
32
|
+
removeLink: "Retirer le lien",
|
|
33
|
+
invalidLink: "Saisissez une adresse HTTP, HTTPS ou mailto valide.",
|
|
34
|
+
actionUnavailable: "Cette action ne peut pas être appliquée à la sélection.",
|
|
35
|
+
undoDone: "Annulation effectuée.",
|
|
36
|
+
redoDone: "Rétablissement effectué.",
|
|
37
|
+
formatDone: "Mise en forme mise à jour.",
|
|
38
|
+
linkApplied: "Lien appliqué.",
|
|
39
|
+
linkNotApplied: "Le lien ne peut pas être appliqué à la sélection.",
|
|
40
|
+
linkRemoved: "Lien retiré.",
|
|
41
|
+
linkNotRemoved: "Le lien ne peut pas être retiré de la sélection.",
|
|
42
|
+
bold: "Gras",
|
|
43
|
+
italic: "Italique",
|
|
44
|
+
underline: "Souligné",
|
|
45
|
+
paragraph: "Paragraphe",
|
|
46
|
+
heading: "Titre",
|
|
47
|
+
strike: "Barré",
|
|
48
|
+
code: "Code en ligne",
|
|
49
|
+
bulletList: "Liste à puces",
|
|
50
|
+
orderedList: "Liste numérotée",
|
|
51
|
+
indent: "Indenter",
|
|
52
|
+
outdent: "Réduire le retrait",
|
|
53
|
+
blockquote: "Citation",
|
|
54
|
+
codeBlock: "Bloc de code",
|
|
55
|
+
clear: "Effacer la mise en forme",
|
|
56
|
+
undo: "Annuler",
|
|
57
|
+
redo: "Rétablir"
|
|
58
|
+
});
|
|
59
|
+
const RICHTEXT_MESSAGES_EN = Object.freeze({
|
|
60
|
+
editorLabel: "Document content",
|
|
61
|
+
invalidDocument: "The value must be a valid 3KLES document.",
|
|
62
|
+
requiredDocument: "The document must contain text.",
|
|
63
|
+
validationError: "The document has a validation error.",
|
|
64
|
+
previewLabel: "Document JSON representation",
|
|
65
|
+
toolbarLabel: "Document formatting",
|
|
66
|
+
toolbarFields: "Heading and link options",
|
|
67
|
+
headingLevel: "Level",
|
|
68
|
+
headingLevelLabel: "Heading level",
|
|
69
|
+
linkAddress: "Link address",
|
|
70
|
+
applyLink: "Apply link",
|
|
71
|
+
removeLink: "Remove link",
|
|
72
|
+
invalidLink: "Enter a valid HTTP, HTTPS or mailto address.",
|
|
73
|
+
actionUnavailable: "This action cannot be applied to the selection.",
|
|
74
|
+
undoDone: "Undo completed.",
|
|
75
|
+
redoDone: "Redo completed.",
|
|
76
|
+
formatDone: "Formatting updated.",
|
|
77
|
+
linkApplied: "Link applied.",
|
|
78
|
+
linkNotApplied: "The link cannot be applied to the selection.",
|
|
79
|
+
linkRemoved: "Link removed.",
|
|
80
|
+
linkNotRemoved: "The link cannot be removed from the selection.",
|
|
81
|
+
bold: "Bold",
|
|
82
|
+
italic: "Italic",
|
|
83
|
+
underline: "Underline",
|
|
84
|
+
paragraph: "Paragraph",
|
|
85
|
+
heading: "Heading",
|
|
86
|
+
strike: "Strikethrough",
|
|
87
|
+
code: "Inline code",
|
|
88
|
+
bulletList: "Bullet list",
|
|
89
|
+
orderedList: "Numbered list",
|
|
90
|
+
indent: "Indent",
|
|
91
|
+
outdent: "Outdent",
|
|
92
|
+
blockquote: "Blockquote",
|
|
93
|
+
codeBlock: "Code block",
|
|
94
|
+
clear: "Clear formatting",
|
|
95
|
+
undo: "Undo",
|
|
96
|
+
redo: "Redo"
|
|
97
|
+
});
|
|
98
|
+
function richTextLocale(locale) {
|
|
99
|
+
return locale?.trim().toLowerCase().split(/[-_]/u)[0] === "en" ? "en" : "fr";
|
|
100
|
+
}
|
|
101
|
+
function resolveRichTextMessages(locale, ...overrides) {
|
|
102
|
+
const messages = { ...richTextLocale(locale) === "en" ? RICHTEXT_MESSAGES_EN : RICHTEXT_MESSAGES_FR };
|
|
103
|
+
for (const override of overrides) {
|
|
104
|
+
if (!override) continue;
|
|
105
|
+
for (const [key, value] of Object.entries(override)) if (typeof value === "string" && value.trim().length > 0) Object.defineProperty(messages, key, {
|
|
106
|
+
value,
|
|
107
|
+
enumerable: true,
|
|
108
|
+
configurable: true,
|
|
109
|
+
writable: true
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return Object.freeze(messages);
|
|
113
|
+
}
|
|
114
|
+
function richTextLabel(value, fallback) {
|
|
115
|
+
return value?.trim() ? value : fallback;
|
|
116
|
+
}
|
|
117
|
+
var RichTextDocumentPreviewComponent = class RichTextDocumentPreviewComponent {
|
|
118
|
+
document = input.required(...ngDevMode ? [{ debugName: "document" }] : /* istanbul ignore next */ []);
|
|
119
|
+
labelOverride = input(void 0, {
|
|
120
|
+
...ngDevMode ? { debugName: "labelOverride" } : /* istanbul ignore next */ {},
|
|
121
|
+
alias: "label"
|
|
122
|
+
});
|
|
123
|
+
locale = input(...ngDevMode ? [void 0, { debugName: "locale" }] : /* istanbul ignore next */ []);
|
|
124
|
+
messages = input(...ngDevMode ? [void 0, { debugName: "messages" }] : /* istanbul ignore next */ []);
|
|
125
|
+
i18n = inject(RICHTEXT_I18N);
|
|
126
|
+
text = computed(() => resolveRichTextMessages(this.locale() ?? this.i18n.locale, this.i18n.messages, this.messages()), ...ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []);
|
|
127
|
+
label = computed(() => richTextLabel(this.labelOverride(), this.text().previewLabel), ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
128
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
129
|
+
minVersion: "12.0.0",
|
|
130
|
+
version: "22.2.6",
|
|
131
|
+
ngImport: i0,
|
|
132
|
+
type: RichTextDocumentPreviewComponent,
|
|
133
|
+
deps: [],
|
|
134
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
135
|
+
});
|
|
136
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
137
|
+
minVersion: "17.1.0",
|
|
138
|
+
version: "22.2.6",
|
|
139
|
+
type: RichTextDocumentPreviewComponent,
|
|
140
|
+
isStandalone: true,
|
|
141
|
+
selector: "kles-richtext-document-preview",
|
|
142
|
+
inputs: {
|
|
143
|
+
document: {
|
|
144
|
+
classPropertyName: "document",
|
|
145
|
+
publicName: "document",
|
|
146
|
+
isSignal: true,
|
|
147
|
+
isRequired: true,
|
|
148
|
+
transformFunction: null
|
|
149
|
+
},
|
|
150
|
+
labelOverride: {
|
|
151
|
+
classPropertyName: "labelOverride",
|
|
152
|
+
publicName: "label",
|
|
153
|
+
isSignal: true,
|
|
154
|
+
isRequired: false,
|
|
155
|
+
transformFunction: null
|
|
156
|
+
},
|
|
157
|
+
locale: {
|
|
158
|
+
classPropertyName: "locale",
|
|
159
|
+
publicName: "locale",
|
|
160
|
+
isSignal: true,
|
|
161
|
+
isRequired: false,
|
|
162
|
+
transformFunction: null
|
|
163
|
+
},
|
|
164
|
+
messages: {
|
|
165
|
+
classPropertyName: "messages",
|
|
166
|
+
publicName: "messages",
|
|
167
|
+
isSignal: true,
|
|
168
|
+
isRequired: false,
|
|
169
|
+
transformFunction: null
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
ngImport: i0,
|
|
173
|
+
template: "<section [attr.aria-label]=\"label()\">\n <pre tabindex=\"0\">{{ document() | json }}</pre>\n</section>\n",
|
|
174
|
+
styles: [":host{display:block;min-width:0}pre{max-height:42rem;margin:0;overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;font:inherit;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;line-height:1.55}\n"],
|
|
175
|
+
dependencies: [{
|
|
176
|
+
kind: "pipe",
|
|
177
|
+
type: JsonPipe,
|
|
178
|
+
name: "json"
|
|
179
|
+
}],
|
|
180
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
184
|
+
minVersion: "12.0.0",
|
|
185
|
+
version: "22.2.6",
|
|
186
|
+
ngImport: i0,
|
|
187
|
+
type: RichTextDocumentPreviewComponent,
|
|
188
|
+
decorators: [{
|
|
189
|
+
type: Component,
|
|
190
|
+
args: [{
|
|
191
|
+
selector: "kles-richtext-document-preview",
|
|
192
|
+
imports: [JsonPipe],
|
|
193
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
194
|
+
template: "<section [attr.aria-label]=\"label()\">\n <pre tabindex=\"0\">{{ document() | json }}</pre>\n</section>\n",
|
|
195
|
+
styles: [":host{display:block;min-width:0}pre{max-height:42rem;margin:0;overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;font:inherit;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;line-height:1.55}\n"]
|
|
196
|
+
}]
|
|
197
|
+
}],
|
|
198
|
+
propDecorators: {
|
|
199
|
+
document: [{
|
|
200
|
+
type: i0.Input,
|
|
201
|
+
args: [{
|
|
202
|
+
isSignal: true,
|
|
203
|
+
alias: "document",
|
|
204
|
+
required: true
|
|
205
|
+
}]
|
|
206
|
+
}],
|
|
207
|
+
labelOverride: [{
|
|
208
|
+
type: i0.Input,
|
|
209
|
+
args: [{
|
|
210
|
+
isSignal: true,
|
|
211
|
+
alias: "label",
|
|
212
|
+
required: false
|
|
213
|
+
}]
|
|
214
|
+
}],
|
|
215
|
+
locale: [{
|
|
216
|
+
type: i0.Input,
|
|
217
|
+
args: [{
|
|
218
|
+
isSignal: true,
|
|
219
|
+
alias: "locale",
|
|
220
|
+
required: false
|
|
221
|
+
}]
|
|
222
|
+
}],
|
|
223
|
+
messages: [{
|
|
224
|
+
type: i0.Input,
|
|
225
|
+
args: [{
|
|
226
|
+
isSignal: true,
|
|
227
|
+
alias: "messages",
|
|
228
|
+
required: false
|
|
229
|
+
}]
|
|
230
|
+
}]
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
const RICHTEXT_EDITOR_EXTENSIONS = new InjectionToken("RICHTEXT_EDITOR_EXTENSIONS");
|
|
234
|
+
var RichTextAccessibilityIds = class RichTextAccessibilityIds {
|
|
235
|
+
appId = inject(APP_ID);
|
|
236
|
+
sequence = 0;
|
|
237
|
+
next(purpose) {
|
|
238
|
+
return `${this.appId}-kles-richtext-${purpose}-${++this.sequence}`;
|
|
239
|
+
}
|
|
240
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
241
|
+
minVersion: "12.0.0",
|
|
242
|
+
version: "22.2.6",
|
|
243
|
+
ngImport: i0,
|
|
244
|
+
type: RichTextAccessibilityIds,
|
|
245
|
+
deps: [],
|
|
246
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
247
|
+
});
|
|
248
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
249
|
+
minVersion: "12.0.0",
|
|
250
|
+
version: "22.2.6",
|
|
251
|
+
ngImport: i0,
|
|
252
|
+
type: RichTextAccessibilityIds,
|
|
253
|
+
providedIn: "root"
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
257
|
+
minVersion: "12.0.0",
|
|
258
|
+
version: "22.2.6",
|
|
259
|
+
ngImport: i0,
|
|
260
|
+
type: RichTextAccessibilityIds,
|
|
261
|
+
decorators: [{
|
|
262
|
+
type: Injectable,
|
|
263
|
+
args: [{ providedIn: "root" }]
|
|
264
|
+
}]
|
|
265
|
+
});
|
|
266
|
+
const RICHTEXT_REQUIRED_ERROR = Object.freeze({ required: true });
|
|
267
|
+
function validateRichTextValue(value) {
|
|
268
|
+
return value === null ? {
|
|
269
|
+
ok: true,
|
|
270
|
+
value: createEmptyDocument(),
|
|
271
|
+
diagnostics: Object.freeze([])
|
|
272
|
+
} : validateDocument(value);
|
|
273
|
+
}
|
|
274
|
+
function richTextSchemaError(diagnostics) {
|
|
275
|
+
return Object.freeze({ richtextDocument: Object.freeze({ diagnostics }) });
|
|
276
|
+
}
|
|
277
|
+
function hasRichTextContent(document) {
|
|
278
|
+
const nonempty = (block) => {
|
|
279
|
+
if (block.type === "paragraph" || block.type === "heading" || block.type === "codeBlock") return getTextBlockText(block).trim().length > 0;
|
|
280
|
+
if (block.type === "blockquote") return block.children.some(nonempty);
|
|
281
|
+
return block.children.some((item) => item.children.some(nonempty));
|
|
282
|
+
};
|
|
283
|
+
return document.children.some(nonempty);
|
|
284
|
+
}
|
|
285
|
+
function richTextDocumentValidator(control) {
|
|
286
|
+
const result = validateRichTextValue(control.value);
|
|
287
|
+
return result.ok ? null : richTextSchemaError(result.diagnostics);
|
|
288
|
+
}
|
|
289
|
+
function richTextRequiredValidator(control) {
|
|
290
|
+
const result = validateRichTextValue(control.value);
|
|
291
|
+
if (!result.ok) return richTextSchemaError(result.diagnostics);
|
|
292
|
+
return hasRichTextContent(result.value) ? null : RICHTEXT_REQUIRED_ERROR;
|
|
293
|
+
}
|
|
294
|
+
var RichTextEditorComponent = class RichTextEditorComponent {
|
|
295
|
+
surface;
|
|
296
|
+
document = input(createEmptyDocument(), ...ngDevMode ? [{ debugName: "document" }] : /* istanbul ignore next */ []);
|
|
297
|
+
readOnly = input(false, {
|
|
298
|
+
...ngDevMode ? { debugName: "readOnly" } : /* istanbul ignore next */ {},
|
|
299
|
+
transform: booleanAttribute
|
|
300
|
+
});
|
|
301
|
+
disabled = input(false, {
|
|
302
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
303
|
+
transform: booleanAttribute
|
|
304
|
+
});
|
|
305
|
+
required = input(false, {
|
|
306
|
+
...ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {},
|
|
307
|
+
transform: booleanAttribute
|
|
308
|
+
});
|
|
309
|
+
invalid = input(false, {
|
|
310
|
+
...ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {},
|
|
311
|
+
transform: booleanAttribute
|
|
312
|
+
});
|
|
313
|
+
labelOverride = input(void 0, {
|
|
314
|
+
...ngDevMode ? { debugName: "labelOverride" } : /* istanbul ignore next */ {},
|
|
315
|
+
alias: "label"
|
|
316
|
+
});
|
|
317
|
+
locale = input(...ngDevMode ? [void 0, { debugName: "locale" }] : /* istanbul ignore next */ []);
|
|
318
|
+
messages = input(...ngDevMode ? [void 0, { debugName: "messages" }] : /* istanbul ignore next */ []);
|
|
319
|
+
i18n = inject(RICHTEXT_I18N);
|
|
320
|
+
text = computed(() => resolveRichTextMessages(this.locale() ?? this.i18n.locale, this.i18n.messages, this.messages()), ...ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []);
|
|
321
|
+
label = computed(() => richTextLabel(this.labelOverride(), this.text().editorLabel), ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
322
|
+
describedBy = input("", ...ngDevMode ? [{ debugName: "describedBy" }] : /* istanbul ignore next */ []);
|
|
323
|
+
errorId = inject(RichTextAccessibilityIds).next("document-error");
|
|
324
|
+
documentChange = output();
|
|
325
|
+
stateChange = output();
|
|
326
|
+
editorEvent = output();
|
|
327
|
+
validationChange = output();
|
|
328
|
+
stateValue = signal(void 0, ...ngDevMode ? [{ debugName: "stateValue" }] : /* istanbul ignore next */ []);
|
|
329
|
+
state = this.stateValue.asReadonly();
|
|
330
|
+
composingValue = signal(false, ...ngDevMode ? [{ debugName: "composingValue" }] : /* istanbul ignore next */ []);
|
|
331
|
+
composing = this.composingValue.asReadonly();
|
|
332
|
+
focusedValue = signal(false, ...ngDevMode ? [{ debugName: "focusedValue" }] : /* istanbul ignore next */ []);
|
|
333
|
+
focused = this.focusedValue.asReadonly();
|
|
334
|
+
formsDisabled = signal(false, ...ngDevMode ? [{ debugName: "formsDisabled" }] : /* istanbul ignore next */ []);
|
|
335
|
+
effectiveDisabled = computed(() => this.disabled() || this.formsDisabled(), ...ngDevMode ? [{ debugName: "effectiveDisabled" }] : /* istanbul ignore next */ []);
|
|
336
|
+
editable = computed(() => !this.effectiveDisabled() && !this.readOnly() && !this.composing(), ...ngDevMode ? [{ debugName: "editable" }] : /* istanbul ignore next */ []);
|
|
337
|
+
viewDocument = signal(createEmptyDocument(), ...ngDevMode ? [{ debugName: "viewDocument" }] : /* istanbul ignore next */ []);
|
|
338
|
+
schemaError = signal(null, ...ngDevMode ? [{ debugName: "schemaError" }] : /* istanbul ignore next */ []);
|
|
339
|
+
validationPresented = signal(false, ...ngDevMode ? [{ debugName: "validationPresented" }] : /* istanbul ignore next */ []);
|
|
340
|
+
validationError = computed(() => this.schemaError() ?? (this.required() && !hasRichTextContent(this.viewDocument()) ? RICHTEXT_REQUIRED_ERROR : null), ...ngDevMode ? [{ debugName: "validationError" }] : /* istanbul ignore next */ []);
|
|
341
|
+
ariaInvalid = computed(() => !this.effectiveDisabled() && (this.invalid() || this.schemaError() !== null || this.validationPresented() && this.validationError() !== null), ...ngDevMode ? [{ debugName: "ariaInvalid" }] : /* istanbul ignore next */ []);
|
|
342
|
+
validationMessage = computed(() => {
|
|
343
|
+
if (!this.ariaInvalid()) return "";
|
|
344
|
+
const error = this.validationError();
|
|
345
|
+
if (error?.richtextDocument) return this.text().invalidDocument;
|
|
346
|
+
if (error?.required) return this.text().requiredDocument;
|
|
347
|
+
return this.text().validationError;
|
|
348
|
+
}, ...ngDevMode ? [{ debugName: "validationMessage" }] : /* istanbul ignore next */ []);
|
|
349
|
+
descriptionIds = computed(() => [this.describedBy().trim(), this.validationMessage() ? this.errorId : ""].filter(Boolean).join(" ") || null, ...ngDevMode ? [{ debugName: "descriptionIds" }] : /* istanbul ignore next */ []);
|
|
350
|
+
editor;
|
|
351
|
+
browser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
352
|
+
extensions = inject(RICHTEXT_EDITOR_EXTENSIONS, { optional: true });
|
|
353
|
+
unsubscribe;
|
|
354
|
+
detachSubmit;
|
|
355
|
+
formsBound = false;
|
|
356
|
+
destroyed = false;
|
|
357
|
+
nativeNotificationDepth = 0;
|
|
358
|
+
lastLoadedSource;
|
|
359
|
+
pendingDocument;
|
|
360
|
+
pendingReadOnly;
|
|
361
|
+
pendingCompositionCancellation = false;
|
|
362
|
+
rejectedWriteSequence = 0;
|
|
363
|
+
pendingRejectedWrite;
|
|
364
|
+
pendingFlush = false;
|
|
365
|
+
pendingBlur = false;
|
|
366
|
+
blurTimer;
|
|
367
|
+
interacted = false;
|
|
368
|
+
focusRegions = /* @__PURE__ */ new Map();
|
|
369
|
+
onChange = () => void 0;
|
|
370
|
+
onTouched = () => void 0;
|
|
371
|
+
onValidatorChange = () => void 0;
|
|
372
|
+
constructor() {
|
|
373
|
+
effect(() => {
|
|
374
|
+
const document = this.document();
|
|
375
|
+
untracked(() => {
|
|
376
|
+
if (!this.formsBound) this.receiveDocument(document, false);
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
effect(() => {
|
|
380
|
+
const disabled = this.effectiveDisabled();
|
|
381
|
+
const readOnly = this.readOnly();
|
|
382
|
+
untracked(() => this.applyAccess(disabled, readOnly));
|
|
383
|
+
});
|
|
384
|
+
effect(() => {
|
|
385
|
+
const validation = this.validationError();
|
|
386
|
+
untracked(() => this.validationChange.emit(validation));
|
|
387
|
+
});
|
|
388
|
+
effect(() => {
|
|
389
|
+
this.required();
|
|
390
|
+
untracked(() => this.onValidatorChange());
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
ngAfterViewInit() {
|
|
394
|
+
const surface = this.surface?.nativeElement;
|
|
395
|
+
if (!surface || this.destroyed || !this.browser) return;
|
|
396
|
+
if (!this.formsBound) this.receiveDocument(this.document(), false);
|
|
397
|
+
this.editor = createEditor(surface, {
|
|
398
|
+
document: this.viewDocument(),
|
|
399
|
+
label: this.label(),
|
|
400
|
+
readOnly: this.readOnly() || this.effectiveDisabled(),
|
|
401
|
+
...this.extensions ? { extensions: this.extensions } : {}
|
|
402
|
+
});
|
|
403
|
+
this.stateValue.set(this.editor.getState());
|
|
404
|
+
this.unsubscribe = this.editor.subscribe((event) => this.handleEvent(event));
|
|
405
|
+
this.registerFocusRegion(surface);
|
|
406
|
+
this.registerFormSubmit(surface);
|
|
407
|
+
this.applyAccess(this.effectiveDisabled(), this.readOnly());
|
|
408
|
+
this.queueFlush();
|
|
409
|
+
queueMicrotask(() => {
|
|
410
|
+
if (!this.destroyed && this.editor) this.stateChange.emit(this.editor.getState());
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
writeValue(value) {
|
|
414
|
+
if (this.destroyed) return;
|
|
415
|
+
this.formsBound = true;
|
|
416
|
+
this.interacted = false;
|
|
417
|
+
this.pendingBlur = false;
|
|
418
|
+
this.cancelBlurCheck();
|
|
419
|
+
this.validationPresented.set(false);
|
|
420
|
+
this.receiveDocument(value, true);
|
|
421
|
+
}
|
|
422
|
+
registerOnChange(callback) {
|
|
423
|
+
if (this.destroyed) return;
|
|
424
|
+
this.formsBound = true;
|
|
425
|
+
this.onChange = callback;
|
|
426
|
+
}
|
|
427
|
+
registerOnTouched(callback) {
|
|
428
|
+
if (this.destroyed) return;
|
|
429
|
+
this.onTouched = callback;
|
|
430
|
+
}
|
|
431
|
+
setDisabledState(disabled) {
|
|
432
|
+
if (this.destroyed) return;
|
|
433
|
+
this.formsDisabled.set(disabled);
|
|
434
|
+
this.applyAccess(this.effectiveDisabled(), this.readOnly());
|
|
435
|
+
}
|
|
436
|
+
validate(control) {
|
|
437
|
+
return this.required() ? richTextRequiredValidator(control) : richTextDocumentValidator(control);
|
|
438
|
+
}
|
|
439
|
+
registerOnValidatorChange(callback) {
|
|
440
|
+
if (this.destroyed) return;
|
|
441
|
+
this.onValidatorChange = callback;
|
|
442
|
+
}
|
|
443
|
+
execute(command) {
|
|
444
|
+
if (!this.editor || this.effectiveDisabled()) return void 0;
|
|
445
|
+
this.interacted = true;
|
|
446
|
+
return this.editor.run(command);
|
|
447
|
+
}
|
|
448
|
+
focus() {
|
|
449
|
+
if (!this.effectiveDisabled()) this.editor?.focus();
|
|
450
|
+
}
|
|
451
|
+
getDocument() {
|
|
452
|
+
return this.editor?.getState().document ?? this.viewDocument();
|
|
453
|
+
}
|
|
454
|
+
canUndo() {
|
|
455
|
+
this.state();
|
|
456
|
+
return this.editable() && (this.editor?.canUndo() ?? false);
|
|
457
|
+
}
|
|
458
|
+
canRedo() {
|
|
459
|
+
this.state();
|
|
460
|
+
return this.editable() && (this.editor?.canRedo() ?? false);
|
|
461
|
+
}
|
|
462
|
+
isActive(mark) {
|
|
463
|
+
this.state();
|
|
464
|
+
return this.editor?.isActive(mark) ?? false;
|
|
465
|
+
}
|
|
466
|
+
can(command) {
|
|
467
|
+
this.state();
|
|
468
|
+
return !this.effectiveDisabled() && !this.composing() && (!this.readOnly() || command === "selectAll") && (this.editor?.can(command) ?? false);
|
|
469
|
+
}
|
|
470
|
+
isActiveCommand(command) {
|
|
471
|
+
this.state();
|
|
472
|
+
return this.editor?.isActiveCommand(command) ?? false;
|
|
473
|
+
}
|
|
474
|
+
loadHtml(html, emitChange = false) {
|
|
475
|
+
const result = this.editor?.loadHtml(html, { emitChange });
|
|
476
|
+
if (result?.ok) {
|
|
477
|
+
this.lastLoadedSource = result.state.document;
|
|
478
|
+
this.viewDocument.set(result.state.document);
|
|
479
|
+
this.schemaError.set(null);
|
|
480
|
+
}
|
|
481
|
+
return result;
|
|
482
|
+
}
|
|
483
|
+
insertHtml(html) {
|
|
484
|
+
if (!this.editor || this.effectiveDisabled()) return void 0;
|
|
485
|
+
this.interacted = true;
|
|
486
|
+
this.editor.focus();
|
|
487
|
+
return this.editor.insertHtml(html);
|
|
488
|
+
}
|
|
489
|
+
getHtml() {
|
|
490
|
+
return this.editor?.getHtml();
|
|
491
|
+
}
|
|
492
|
+
registerFocusRegion(element) {
|
|
493
|
+
if (this.destroyed || !this.browser) return () => void 0;
|
|
494
|
+
if (this.focusRegions.has(element)) return () => void 0;
|
|
495
|
+
const interaction = () => {
|
|
496
|
+
if (!this.effectiveDisabled()) this.interacted = true;
|
|
497
|
+
};
|
|
498
|
+
const pointerInteraction = (event) => {
|
|
499
|
+
if (this.effectiveDisabled() && element === this.surface?.nativeElement) {
|
|
500
|
+
event.preventDefault();
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
interaction();
|
|
504
|
+
};
|
|
505
|
+
const focusIn = () => {
|
|
506
|
+
this.cancelBlurCheck();
|
|
507
|
+
if (this.effectiveDisabled() && element === this.surface?.nativeElement) {
|
|
508
|
+
this.interacted = false;
|
|
509
|
+
this.pendingBlur = false;
|
|
510
|
+
this.focusedValue.set(false);
|
|
511
|
+
element.blur();
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
this.focusedValue.set(true);
|
|
515
|
+
this.pendingBlur = false;
|
|
516
|
+
};
|
|
517
|
+
const focusOut = () => {
|
|
518
|
+
this.pendingBlur = true;
|
|
519
|
+
this.queueFlush();
|
|
520
|
+
};
|
|
521
|
+
element.addEventListener("pointerdown", pointerInteraction, true);
|
|
522
|
+
element.addEventListener("keydown", interaction, true);
|
|
523
|
+
element.addEventListener("focusin", focusIn);
|
|
524
|
+
element.addEventListener("focusout", focusOut);
|
|
525
|
+
let disposed = false;
|
|
526
|
+
const dispose = () => {
|
|
527
|
+
if (disposed) return;
|
|
528
|
+
disposed = true;
|
|
529
|
+
element.removeEventListener("pointerdown", pointerInteraction, true);
|
|
530
|
+
element.removeEventListener("keydown", interaction, true);
|
|
531
|
+
element.removeEventListener("focusin", focusIn);
|
|
532
|
+
element.removeEventListener("focusout", focusOut);
|
|
533
|
+
this.focusRegions.delete(element);
|
|
534
|
+
this.pendingBlur = true;
|
|
535
|
+
this.queueFlush();
|
|
536
|
+
};
|
|
537
|
+
this.focusRegions.set(element, dispose);
|
|
538
|
+
return dispose;
|
|
539
|
+
}
|
|
540
|
+
ngOnDestroy() {
|
|
541
|
+
this.destroyed = true;
|
|
542
|
+
this.cancelBlurCheck();
|
|
543
|
+
this.detachSubmit?.();
|
|
544
|
+
this.detachSubmit = void 0;
|
|
545
|
+
this.unsubscribe?.();
|
|
546
|
+
this.unsubscribe = void 0;
|
|
547
|
+
for (const dispose of [...this.focusRegions.values()]) dispose();
|
|
548
|
+
this.editor?.destroy();
|
|
549
|
+
this.editor = void 0;
|
|
550
|
+
this.surface = void 0;
|
|
551
|
+
this.pendingDocument = void 0;
|
|
552
|
+
this.pendingReadOnly = void 0;
|
|
553
|
+
this.pendingCompositionCancellation = false;
|
|
554
|
+
this.pendingRejectedWrite = void 0;
|
|
555
|
+
this.pendingBlur = false;
|
|
556
|
+
this.interacted = false;
|
|
557
|
+
this.stateValue.set(void 0);
|
|
558
|
+
this.composingValue.set(false);
|
|
559
|
+
this.focusedValue.set(false);
|
|
560
|
+
this.onChange = () => void 0;
|
|
561
|
+
this.onTouched = () => void 0;
|
|
562
|
+
this.onValidatorChange = () => void 0;
|
|
563
|
+
}
|
|
564
|
+
registerFormSubmit(surface) {
|
|
565
|
+
const form = surface.closest("form");
|
|
566
|
+
if (!form) return;
|
|
567
|
+
const submit = (event) => {
|
|
568
|
+
const editor = this.editor;
|
|
569
|
+
if (this.destroyed || !editor || this.effectiveDisabled()) return;
|
|
570
|
+
this.validationPresented.set(true);
|
|
571
|
+
this.flushPendingInputs(true);
|
|
572
|
+
if (!editor.flushComposition()) {
|
|
573
|
+
event.preventDefault();
|
|
574
|
+
event.stopImmediatePropagation();
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
this.flushPendingInputs(true);
|
|
578
|
+
};
|
|
579
|
+
form.addEventListener("submit", submit, true);
|
|
580
|
+
this.detachSubmit = () => form.removeEventListener("submit", submit, true);
|
|
581
|
+
}
|
|
582
|
+
handleEvent(event) {
|
|
583
|
+
if (this.destroyed) return;
|
|
584
|
+
this.nativeNotificationDepth++;
|
|
585
|
+
try {
|
|
586
|
+
this.stateValue.set(event.state);
|
|
587
|
+
if (event.type === "compositionChange") this.composingValue.set(event.composing);
|
|
588
|
+
if (event.type === "documentChange") {
|
|
589
|
+
this.viewDocument.set(event.state.document);
|
|
590
|
+
this.lastLoadedSource = event.state.document;
|
|
591
|
+
if (!this.pendingDocument && !this.pendingCompositionCancellation && this.pendingRejectedWrite === void 0) {
|
|
592
|
+
this.schemaError.set(null);
|
|
593
|
+
if (event.commit.origin !== "load") {
|
|
594
|
+
this.validationPresented.set(true);
|
|
595
|
+
this.interacted = true;
|
|
596
|
+
if (this.formsBound) this.onChange(event.state.document);
|
|
597
|
+
}
|
|
598
|
+
if (!this.pendingDocument && this.pendingRejectedWrite === void 0) this.documentChange.emit(event.state.document);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (event.type === "blur") {
|
|
602
|
+
this.pendingBlur = true;
|
|
603
|
+
this.queueFlush();
|
|
604
|
+
}
|
|
605
|
+
if (event.type === "compositionChange" && !event.composing) this.queueFlush();
|
|
606
|
+
this.stateChange.emit(event.state);
|
|
607
|
+
this.editorEvent.emit(event);
|
|
608
|
+
} finally {
|
|
609
|
+
this.nativeNotificationDepth--;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
receiveDocument(value, fromForms) {
|
|
613
|
+
if (this.destroyed || !fromForms && this.formsBound) return;
|
|
614
|
+
if (!fromForms && value === this.lastLoadedSource) {
|
|
615
|
+
this.pendingDocument = void 0;
|
|
616
|
+
this.pendingRejectedWrite = void 0;
|
|
617
|
+
this.schemaError.set(null);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const validated = validateRichTextValue(value);
|
|
621
|
+
if (!validated.ok) {
|
|
622
|
+
this.pendingDocument = void 0;
|
|
623
|
+
this.pendingRejectedWrite = ++this.rejectedWriteSequence;
|
|
624
|
+
this.schemaError.set(richTextSchemaError(validated.diagnostics));
|
|
625
|
+
this.queueFlush();
|
|
626
|
+
if (this.editor?.getSnapshot().composing) {
|
|
627
|
+
this.pendingCompositionCancellation = true;
|
|
628
|
+
this.cancelPendingComposition();
|
|
629
|
+
}
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
this.pendingRejectedWrite = void 0;
|
|
633
|
+
this.schemaError.set(null);
|
|
634
|
+
const request = {
|
|
635
|
+
document: validated.value,
|
|
636
|
+
source: value
|
|
637
|
+
};
|
|
638
|
+
if (!this.editor) {
|
|
639
|
+
this.viewDocument.set(validated.value);
|
|
640
|
+
this.lastLoadedSource = value;
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
this.pendingDocument = request;
|
|
644
|
+
if (this.editor.getSnapshot().composing || this.nativeNotificationDepth) {
|
|
645
|
+
this.queueFlush();
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
this.applyPendingDocument();
|
|
649
|
+
}
|
|
650
|
+
applyPendingDocument() {
|
|
651
|
+
const editor = this.editor;
|
|
652
|
+
const pending = this.pendingDocument;
|
|
653
|
+
if (!editor || !pending || editor.getSnapshot().composing || this.nativeNotificationDepth) return;
|
|
654
|
+
this.pendingDocument = void 0;
|
|
655
|
+
const result = editor.loadDocument(pending.document);
|
|
656
|
+
if (result.ok) {
|
|
657
|
+
this.lastLoadedSource = pending.source;
|
|
658
|
+
this.viewDocument.set(result.state.document);
|
|
659
|
+
} else if (!editor.getSnapshot().destroyed) {
|
|
660
|
+
this.pendingDocument = pending;
|
|
661
|
+
this.queueFlush();
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
applyAccess(disabled, readOnly) {
|
|
665
|
+
if (this.destroyed) return;
|
|
666
|
+
const surface = this.browser ? this.surface?.nativeElement : void 0;
|
|
667
|
+
if (surface) {
|
|
668
|
+
surface.setAttribute("tabindex", disabled ? "-1" : "0");
|
|
669
|
+
surface.setAttribute("aria-disabled", String(disabled));
|
|
670
|
+
if (disabled) surface.setAttribute("contenteditable", "false");
|
|
671
|
+
}
|
|
672
|
+
if (disabled) {
|
|
673
|
+
this.interacted = false;
|
|
674
|
+
this.pendingBlur = false;
|
|
675
|
+
this.cancelBlurCheck();
|
|
676
|
+
if (surface?.contains(surface.ownerDocument.activeElement)) surface.blur();
|
|
677
|
+
}
|
|
678
|
+
const editor = this.editor;
|
|
679
|
+
if (!editor) return;
|
|
680
|
+
this.pendingReadOnly = disabled || readOnly;
|
|
681
|
+
if (this.nativeNotificationDepth) {
|
|
682
|
+
this.queueFlush();
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (disabled) editor.cancelComposition();
|
|
686
|
+
if (editor.getSnapshot().composing) {
|
|
687
|
+
if (disabled) this.queueFlush();
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const effective = this.pendingReadOnly;
|
|
691
|
+
this.pendingReadOnly = void 0;
|
|
692
|
+
if (editor.getState().readOnly !== effective) {
|
|
693
|
+
if (!editor.setReadOnly(effective).ok && !editor.getSnapshot().destroyed) {
|
|
694
|
+
this.pendingReadOnly = effective;
|
|
695
|
+
this.queueFlush();
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
cancelPendingComposition() {
|
|
700
|
+
const editor = this.editor;
|
|
701
|
+
if (!editor || !this.pendingCompositionCancellation) return;
|
|
702
|
+
if (this.nativeNotificationDepth) {
|
|
703
|
+
this.queueFlush();
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
editor.cancelComposition();
|
|
707
|
+
if (editor.getSnapshot().composing) this.queueFlush();
|
|
708
|
+
else this.pendingCompositionCancellation = false;
|
|
709
|
+
}
|
|
710
|
+
queueFlush() {
|
|
711
|
+
if (this.pendingFlush || this.destroyed) return;
|
|
712
|
+
this.pendingFlush = true;
|
|
713
|
+
queueMicrotask(() => {
|
|
714
|
+
this.pendingFlush = false;
|
|
715
|
+
this.flushPendingInputs();
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
cancelBlurCheck() {
|
|
719
|
+
if (this.blurTimer !== void 0) clearTimeout(this.blurTimer);
|
|
720
|
+
this.blurTimer = void 0;
|
|
721
|
+
}
|
|
722
|
+
queueBlurCheck() {
|
|
723
|
+
if (this.blurTimer !== void 0 || this.destroyed) return;
|
|
724
|
+
this.blurTimer = setTimeout(() => {
|
|
725
|
+
this.blurTimer = void 0;
|
|
726
|
+
this.flushPendingInputs(true);
|
|
727
|
+
}, 0);
|
|
728
|
+
}
|
|
729
|
+
flushPendingInputs(acceptBlur = false) {
|
|
730
|
+
if (this.destroyed || !this.editor) return;
|
|
731
|
+
if (this.nativeNotificationDepth) {
|
|
732
|
+
this.queueFlush();
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const rejectedWrite = this.pendingRejectedWrite;
|
|
736
|
+
this.cancelPendingComposition();
|
|
737
|
+
this.applyAccess(this.effectiveDisabled(), this.readOnly());
|
|
738
|
+
if (this.editor.getSnapshot().composing) return;
|
|
739
|
+
this.applyPendingDocument();
|
|
740
|
+
if (this.pendingRejectedWrite === rejectedWrite) this.pendingRejectedWrite = void 0;
|
|
741
|
+
if ([...this.focusRegions.keys()].some((element) => element.contains(element.ownerDocument.activeElement))) {
|
|
742
|
+
this.focusedValue.set(true);
|
|
743
|
+
this.cancelBlurCheck();
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (!this.pendingBlur) return;
|
|
747
|
+
if (!acceptBlur) {
|
|
748
|
+
this.queueBlurCheck();
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
this.cancelBlurCheck();
|
|
752
|
+
this.focusedValue.set(false);
|
|
753
|
+
this.pendingBlur = false;
|
|
754
|
+
if (this.interacted && !this.effectiveDisabled()) {
|
|
755
|
+
this.validationPresented.set(true);
|
|
756
|
+
this.interacted = false;
|
|
757
|
+
this.onTouched();
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
761
|
+
minVersion: "12.0.0",
|
|
762
|
+
version: "22.2.6",
|
|
763
|
+
ngImport: i0,
|
|
764
|
+
type: RichTextEditorComponent,
|
|
765
|
+
deps: [],
|
|
766
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
767
|
+
});
|
|
768
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
769
|
+
minVersion: "17.0.0",
|
|
770
|
+
version: "22.2.6",
|
|
771
|
+
type: RichTextEditorComponent,
|
|
772
|
+
isStandalone: true,
|
|
773
|
+
selector: "kles-richtext-editor",
|
|
774
|
+
inputs: {
|
|
775
|
+
document: {
|
|
776
|
+
classPropertyName: "document",
|
|
777
|
+
publicName: "document",
|
|
778
|
+
isSignal: true,
|
|
779
|
+
isRequired: false,
|
|
780
|
+
transformFunction: null
|
|
781
|
+
},
|
|
782
|
+
readOnly: {
|
|
783
|
+
classPropertyName: "readOnly",
|
|
784
|
+
publicName: "readOnly",
|
|
785
|
+
isSignal: true,
|
|
786
|
+
isRequired: false,
|
|
787
|
+
transformFunction: null
|
|
788
|
+
},
|
|
789
|
+
disabled: {
|
|
790
|
+
classPropertyName: "disabled",
|
|
791
|
+
publicName: "disabled",
|
|
792
|
+
isSignal: true,
|
|
793
|
+
isRequired: false,
|
|
794
|
+
transformFunction: null
|
|
795
|
+
},
|
|
796
|
+
required: {
|
|
797
|
+
classPropertyName: "required",
|
|
798
|
+
publicName: "required",
|
|
799
|
+
isSignal: true,
|
|
800
|
+
isRequired: false,
|
|
801
|
+
transformFunction: null
|
|
802
|
+
},
|
|
803
|
+
invalid: {
|
|
804
|
+
classPropertyName: "invalid",
|
|
805
|
+
publicName: "invalid",
|
|
806
|
+
isSignal: true,
|
|
807
|
+
isRequired: false,
|
|
808
|
+
transformFunction: null
|
|
809
|
+
},
|
|
810
|
+
labelOverride: {
|
|
811
|
+
classPropertyName: "labelOverride",
|
|
812
|
+
publicName: "label",
|
|
813
|
+
isSignal: true,
|
|
814
|
+
isRequired: false,
|
|
815
|
+
transformFunction: null
|
|
816
|
+
},
|
|
817
|
+
locale: {
|
|
818
|
+
classPropertyName: "locale",
|
|
819
|
+
publicName: "locale",
|
|
820
|
+
isSignal: true,
|
|
821
|
+
isRequired: false,
|
|
822
|
+
transformFunction: null
|
|
823
|
+
},
|
|
824
|
+
messages: {
|
|
825
|
+
classPropertyName: "messages",
|
|
826
|
+
publicName: "messages",
|
|
827
|
+
isSignal: true,
|
|
828
|
+
isRequired: false,
|
|
829
|
+
transformFunction: null
|
|
830
|
+
},
|
|
831
|
+
describedBy: {
|
|
832
|
+
classPropertyName: "describedBy",
|
|
833
|
+
publicName: "describedBy",
|
|
834
|
+
isSignal: true,
|
|
835
|
+
isRequired: false,
|
|
836
|
+
transformFunction: null
|
|
837
|
+
}
|
|
838
|
+
},
|
|
839
|
+
outputs: {
|
|
840
|
+
documentChange: "documentChange",
|
|
841
|
+
stateChange: "stateChange",
|
|
842
|
+
editorEvent: "editorEvent",
|
|
843
|
+
validationChange: "validationChange"
|
|
844
|
+
},
|
|
845
|
+
providers: [{
|
|
846
|
+
provide: NG_VALUE_ACCESSOR,
|
|
847
|
+
useExisting: forwardRef(() => RichTextEditorComponent),
|
|
848
|
+
multi: true
|
|
849
|
+
}, {
|
|
850
|
+
provide: NG_VALIDATORS,
|
|
851
|
+
useExisting: forwardRef(() => RichTextEditorComponent),
|
|
852
|
+
multi: true
|
|
853
|
+
}],
|
|
854
|
+
viewQueries: [{
|
|
855
|
+
propertyName: "surface",
|
|
856
|
+
first: true,
|
|
857
|
+
predicate: ["surface"],
|
|
858
|
+
descendants: true,
|
|
859
|
+
static: true
|
|
860
|
+
}],
|
|
861
|
+
ngImport: i0,
|
|
862
|
+
template: "<div\n #surface\n class=\"richtext-surface\"\n role=\"textbox\"\n aria-multiline=\"true\"\n [attr.aria-label]=\"label()\"\n [attr.tabindex]=\"effectiveDisabled() ? -1 : 0\"\n [attr.aria-readonly]=\"readOnly() || effectiveDisabled()\"\n [class.richtext-surface-disabled]=\"effectiveDisabled()\"\n [class.richtext-surface-invalid]=\"ariaInvalid()\"\n [attr.aria-disabled]=\"effectiveDisabled()\"\n [attr.aria-required]=\"required() ? 'true' : null\"\n [attr.aria-invalid]=\"ariaInvalid() ? 'true' : null\"\n [attr.aria-describedby]=\"descriptionIds()\"\n></div>\n@if (validationMessage()) {\n <p [id]=\"errorId\" class=\"richtext-validation-message\" role=\"alert\">{{ validationMessage() }}</p>\n}\n",
|
|
863
|
+
styles: [":host{display:block;min-width:0}.richtext-surface{min-height:16rem;padding:1.25rem;border:1px solid var(--kles-richtext-border, var(--border, #b7c6d8));border-radius:.5rem;background:var(--kles-richtext-surface, var(--surface, transparent));color:var(--kles-richtext-color, var(--text, inherit));line-height:1.65;white-space:pre-wrap;overflow-wrap:anywhere;outline-offset:3px}.richtext-surface[aria-readonly=true]{background:var(--kles-richtext-readonly-surface, var(--background, transparent))}.richtext-surface-disabled{opacity:.65;cursor:not-allowed}.richtext-surface-invalid{border-color:var(--kles-richtext-error, var(--error, #b42318))}.richtext-validation-message{color:var(--kles-richtext-error, var(--error, #b42318));margin:.5rem 0 0;line-height:1.5}\n"],
|
|
864
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
865
|
+
});
|
|
866
|
+
};
|
|
867
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
868
|
+
minVersion: "12.0.0",
|
|
869
|
+
version: "22.2.6",
|
|
870
|
+
ngImport: i0,
|
|
871
|
+
type: RichTextEditorComponent,
|
|
872
|
+
decorators: [{
|
|
873
|
+
type: Component,
|
|
874
|
+
args: [{
|
|
875
|
+
selector: "kles-richtext-editor",
|
|
876
|
+
standalone: true,
|
|
877
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
878
|
+
providers: [{
|
|
879
|
+
provide: NG_VALUE_ACCESSOR,
|
|
880
|
+
useExisting: forwardRef(() => RichTextEditorComponent),
|
|
881
|
+
multi: true
|
|
882
|
+
}, {
|
|
883
|
+
provide: NG_VALIDATORS,
|
|
884
|
+
useExisting: forwardRef(() => RichTextEditorComponent),
|
|
885
|
+
multi: true
|
|
886
|
+
}],
|
|
887
|
+
template: "<div\n #surface\n class=\"richtext-surface\"\n role=\"textbox\"\n aria-multiline=\"true\"\n [attr.aria-label]=\"label()\"\n [attr.tabindex]=\"effectiveDisabled() ? -1 : 0\"\n [attr.aria-readonly]=\"readOnly() || effectiveDisabled()\"\n [class.richtext-surface-disabled]=\"effectiveDisabled()\"\n [class.richtext-surface-invalid]=\"ariaInvalid()\"\n [attr.aria-disabled]=\"effectiveDisabled()\"\n [attr.aria-required]=\"required() ? 'true' : null\"\n [attr.aria-invalid]=\"ariaInvalid() ? 'true' : null\"\n [attr.aria-describedby]=\"descriptionIds()\"\n></div>\n@if (validationMessage()) {\n <p [id]=\"errorId\" class=\"richtext-validation-message\" role=\"alert\">{{ validationMessage() }}</p>\n}\n",
|
|
888
|
+
styles: [":host{display:block;min-width:0}.richtext-surface{min-height:16rem;padding:1.25rem;border:1px solid var(--kles-richtext-border, var(--border, #b7c6d8));border-radius:.5rem;background:var(--kles-richtext-surface, var(--surface, transparent));color:var(--kles-richtext-color, var(--text, inherit));line-height:1.65;white-space:pre-wrap;overflow-wrap:anywhere;outline-offset:3px}.richtext-surface[aria-readonly=true]{background:var(--kles-richtext-readonly-surface, var(--background, transparent))}.richtext-surface-disabled{opacity:.65;cursor:not-allowed}.richtext-surface-invalid{border-color:var(--kles-richtext-error, var(--error, #b42318))}.richtext-validation-message{color:var(--kles-richtext-error, var(--error, #b42318));margin:.5rem 0 0;line-height:1.5}\n"]
|
|
889
|
+
}]
|
|
890
|
+
}],
|
|
891
|
+
ctorParameters: () => [],
|
|
892
|
+
propDecorators: {
|
|
893
|
+
surface: [{
|
|
894
|
+
type: ViewChild,
|
|
895
|
+
args: ["surface", { static: true }]
|
|
896
|
+
}],
|
|
897
|
+
document: [{
|
|
898
|
+
type: i0.Input,
|
|
899
|
+
args: [{
|
|
900
|
+
isSignal: true,
|
|
901
|
+
alias: "document",
|
|
902
|
+
required: false
|
|
903
|
+
}]
|
|
904
|
+
}],
|
|
905
|
+
readOnly: [{
|
|
906
|
+
type: i0.Input,
|
|
907
|
+
args: [{
|
|
908
|
+
isSignal: true,
|
|
909
|
+
alias: "readOnly",
|
|
910
|
+
required: false
|
|
911
|
+
}]
|
|
912
|
+
}],
|
|
913
|
+
disabled: [{
|
|
914
|
+
type: i0.Input,
|
|
915
|
+
args: [{
|
|
916
|
+
isSignal: true,
|
|
917
|
+
alias: "disabled",
|
|
918
|
+
required: false
|
|
919
|
+
}]
|
|
920
|
+
}],
|
|
921
|
+
required: [{
|
|
922
|
+
type: i0.Input,
|
|
923
|
+
args: [{
|
|
924
|
+
isSignal: true,
|
|
925
|
+
alias: "required",
|
|
926
|
+
required: false
|
|
927
|
+
}]
|
|
928
|
+
}],
|
|
929
|
+
invalid: [{
|
|
930
|
+
type: i0.Input,
|
|
931
|
+
args: [{
|
|
932
|
+
isSignal: true,
|
|
933
|
+
alias: "invalid",
|
|
934
|
+
required: false
|
|
935
|
+
}]
|
|
936
|
+
}],
|
|
937
|
+
labelOverride: [{
|
|
938
|
+
type: i0.Input,
|
|
939
|
+
args: [{
|
|
940
|
+
isSignal: true,
|
|
941
|
+
alias: "label",
|
|
942
|
+
required: false
|
|
943
|
+
}]
|
|
944
|
+
}],
|
|
945
|
+
locale: [{
|
|
946
|
+
type: i0.Input,
|
|
947
|
+
args: [{
|
|
948
|
+
isSignal: true,
|
|
949
|
+
alias: "locale",
|
|
950
|
+
required: false
|
|
951
|
+
}]
|
|
952
|
+
}],
|
|
953
|
+
messages: [{
|
|
954
|
+
type: i0.Input,
|
|
955
|
+
args: [{
|
|
956
|
+
isSignal: true,
|
|
957
|
+
alias: "messages",
|
|
958
|
+
required: false
|
|
959
|
+
}]
|
|
960
|
+
}],
|
|
961
|
+
describedBy: [{
|
|
962
|
+
type: i0.Input,
|
|
963
|
+
args: [{
|
|
964
|
+
isSignal: true,
|
|
965
|
+
alias: "describedBy",
|
|
966
|
+
required: false
|
|
967
|
+
}]
|
|
968
|
+
}],
|
|
969
|
+
documentChange: [{
|
|
970
|
+
type: i0.Output,
|
|
971
|
+
args: ["documentChange"]
|
|
972
|
+
}],
|
|
973
|
+
stateChange: [{
|
|
974
|
+
type: i0.Output,
|
|
975
|
+
args: ["stateChange"]
|
|
976
|
+
}],
|
|
977
|
+
editorEvent: [{
|
|
978
|
+
type: i0.Output,
|
|
979
|
+
args: ["editorEvent"]
|
|
980
|
+
}],
|
|
981
|
+
validationChange: [{
|
|
982
|
+
type: i0.Output,
|
|
983
|
+
args: ["validationChange"]
|
|
984
|
+
}]
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
const RICHTEXT_TOOLBAR_CONFIG = new InjectionToken("RICHTEXT_TOOLBAR_CONFIG", {
|
|
988
|
+
providedIn: "root",
|
|
989
|
+
factory: () => Object.freeze({})
|
|
990
|
+
});
|
|
991
|
+
function provideRichTextToolbar(config) {
|
|
992
|
+
return {
|
|
993
|
+
provide: RICHTEXT_TOOLBAR_CONFIG,
|
|
994
|
+
useValue: config
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
const TOOLBAR_ACTIONS = Object.freeze([
|
|
998
|
+
{
|
|
999
|
+
id: "bold",
|
|
1000
|
+
key: "bold",
|
|
1001
|
+
command: "bold",
|
|
1002
|
+
toggle: true
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
id: "italic",
|
|
1006
|
+
key: "italic",
|
|
1007
|
+
command: "italic",
|
|
1008
|
+
toggle: true
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
id: "underline",
|
|
1012
|
+
key: "underline",
|
|
1013
|
+
command: "underline",
|
|
1014
|
+
toggle: true
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
id: "paragraph",
|
|
1018
|
+
key: "paragraph",
|
|
1019
|
+
command: "paragraph",
|
|
1020
|
+
toggle: true
|
|
1021
|
+
},
|
|
1022
|
+
{
|
|
1023
|
+
id: "heading",
|
|
1024
|
+
key: "heading",
|
|
1025
|
+
command: "heading",
|
|
1026
|
+
toggle: true
|
|
1027
|
+
},
|
|
1028
|
+
{
|
|
1029
|
+
id: "strike",
|
|
1030
|
+
key: "strike",
|
|
1031
|
+
command: "strike",
|
|
1032
|
+
toggle: true
|
|
1033
|
+
},
|
|
1034
|
+
{
|
|
1035
|
+
id: "code",
|
|
1036
|
+
key: "code",
|
|
1037
|
+
command: "code",
|
|
1038
|
+
toggle: true
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
id: "bulletList",
|
|
1042
|
+
key: "bulletList",
|
|
1043
|
+
command: "bulletList",
|
|
1044
|
+
toggle: true
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
id: "orderedList",
|
|
1048
|
+
key: "orderedList",
|
|
1049
|
+
command: "orderedList",
|
|
1050
|
+
toggle: true
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
id: "indent",
|
|
1054
|
+
key: "indent",
|
|
1055
|
+
command: Object.freeze({ type: "indentListItem" })
|
|
1056
|
+
},
|
|
1057
|
+
{
|
|
1058
|
+
id: "outdent",
|
|
1059
|
+
key: "outdent",
|
|
1060
|
+
command: Object.freeze({ type: "outdentListItem" })
|
|
1061
|
+
},
|
|
1062
|
+
{
|
|
1063
|
+
id: "blockquote",
|
|
1064
|
+
key: "blockquote",
|
|
1065
|
+
command: "blockquote",
|
|
1066
|
+
toggle: true
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
id: "codeBlock",
|
|
1070
|
+
key: "codeBlock",
|
|
1071
|
+
command: "codeBlock",
|
|
1072
|
+
toggle: true
|
|
1073
|
+
},
|
|
1074
|
+
{
|
|
1075
|
+
id: "clear",
|
|
1076
|
+
key: "clear",
|
|
1077
|
+
command: Object.freeze({ type: "clearFormatting" })
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
id: "undo",
|
|
1081
|
+
key: "undo",
|
|
1082
|
+
command: "undo"
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
id: "redo",
|
|
1086
|
+
key: "redo",
|
|
1087
|
+
command: "redo"
|
|
1088
|
+
}
|
|
1089
|
+
]);
|
|
1090
|
+
const DEFAULT_RICHTEXT_TOOLBAR_ITEMS = Object.freeze([
|
|
1091
|
+
...TOOLBAR_ACTIONS.map(({ id }) => id),
|
|
1092
|
+
"headingLevel",
|
|
1093
|
+
"link"
|
|
1094
|
+
]);
|
|
1095
|
+
function resolveToolbarItems(items) {
|
|
1096
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1097
|
+
const resolved = [];
|
|
1098
|
+
for (const input of items) {
|
|
1099
|
+
const item = typeof input === "string" ? { id: input } : input;
|
|
1100
|
+
if (!item.id.trim()) throw new TypeError("Toolbar item IDs must be nonempty.");
|
|
1101
|
+
if (seen.has(item.id)) throw new TypeError(`Duplicate toolbar item ID: ${item.id}`);
|
|
1102
|
+
seen.add(item.id);
|
|
1103
|
+
if (item.visible === false) continue;
|
|
1104
|
+
if ("kind" in item && item.kind === "command") {
|
|
1105
|
+
if (TOOLBAR_ACTIONS.some((action) => action.id === item.id) || item.id === "headingLevel" || item.id === "link") throw new TypeError(`Custom toolbar item uses a reserved ID: ${item.id}`);
|
|
1106
|
+
if (!item.label.trim()) throw new TypeError("Custom toolbar commands need a nonempty label.");
|
|
1107
|
+
resolved.push(Object.freeze({
|
|
1108
|
+
...item,
|
|
1109
|
+
kind: "action",
|
|
1110
|
+
builtin: false,
|
|
1111
|
+
toggle: item.toggle ?? false
|
|
1112
|
+
}));
|
|
1113
|
+
} else if (item.id === "headingLevel" || item.id === "link") resolved.push(Object.freeze({
|
|
1114
|
+
...item,
|
|
1115
|
+
kind: "field",
|
|
1116
|
+
id: item.id
|
|
1117
|
+
}));
|
|
1118
|
+
else {
|
|
1119
|
+
const definition = TOOLBAR_ACTIONS.find((action) => action.id === item.id);
|
|
1120
|
+
if (!definition) throw new TypeError(`Unknown toolbar item ID: ${item.id}`);
|
|
1121
|
+
resolved.push(Object.freeze({
|
|
1122
|
+
...item,
|
|
1123
|
+
...definition,
|
|
1124
|
+
kind: "action",
|
|
1125
|
+
builtin: true,
|
|
1126
|
+
toggle: definition.toggle ?? false
|
|
1127
|
+
}));
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
return Object.freeze(resolved);
|
|
1131
|
+
}
|
|
1132
|
+
function toolbarActionQueries(items) {
|
|
1133
|
+
return items.filter((item) => item.kind === "action").map((item) => ({
|
|
1134
|
+
id: item.id,
|
|
1135
|
+
builtin: item.builtin,
|
|
1136
|
+
command: item.command,
|
|
1137
|
+
disabled: item.disabled ?? false,
|
|
1138
|
+
toggle: item.toggle
|
|
1139
|
+
}));
|
|
1140
|
+
}
|
|
1141
|
+
function sameToolbarActionQueries(left, right) {
|
|
1142
|
+
return left.length === right.length && left.every((item, index) => {
|
|
1143
|
+
const next = right[index];
|
|
1144
|
+
return next !== void 0 && item.id === next.id && item.builtin === next.builtin && item.command === next.command && item.disabled === next.disabled && item.toggle === next.toggle;
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
function toolbarItemLabel(item, messages) {
|
|
1148
|
+
const override = item.labelKey !== void 0 && Object.hasOwn(messages, item.labelKey) ? messages[item.labelKey] : void 0;
|
|
1149
|
+
return (typeof override === "string" && override.trim() ? override : void 0) ?? (item.label?.trim() ? item.label : void 0) ?? (item.kind === "action" && item.key ? messages[item.key] : item.kind === "field" && item.id === "headingLevel" ? messages.headingLevel : messages.linkAddress);
|
|
1150
|
+
}
|
|
1151
|
+
function toolbarButtonContent(action, messages, preferIconOnly = false) {
|
|
1152
|
+
const label = toolbarItemLabel(action, messages);
|
|
1153
|
+
const ariaLabel = richTextLabel(action.ariaLabel, label);
|
|
1154
|
+
const icon = action.icon?.trim();
|
|
1155
|
+
if (!icon) return {
|
|
1156
|
+
label,
|
|
1157
|
+
ariaLabel
|
|
1158
|
+
};
|
|
1159
|
+
const iconType = action.iconType ?? (icon === "undo" || icon === "redo" ? "material" : "text");
|
|
1160
|
+
return {
|
|
1161
|
+
icon,
|
|
1162
|
+
iconType,
|
|
1163
|
+
label: preferIconOnly || action.label?.trim() === "" || iconType === "material" && action.label === void 0 && action.labelKey === void 0 ? "" : label,
|
|
1164
|
+
ariaLabel
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
function nextToolbarItem(items, current, key) {
|
|
1168
|
+
const available = items.filter((item) => !item.disabled);
|
|
1169
|
+
if (key === "Home") return available[0]?.id;
|
|
1170
|
+
if (key === "End") return available.at(-1)?.id;
|
|
1171
|
+
const index = available.findIndex((item) => item.id === current);
|
|
1172
|
+
if (index < 0) return key === "ArrowLeft" ? available.at(-1)?.id : available[0]?.id;
|
|
1173
|
+
return available[(index + (key === "ArrowLeft" ? -1 : 1) + available.length) % available.length]?.id;
|
|
1174
|
+
}
|
|
1175
|
+
function toolbarHeadingLevel(snapshot) {
|
|
1176
|
+
if (!snapshot) return void 0;
|
|
1177
|
+
const selection = snapshot.selection;
|
|
1178
|
+
const node = selection.kind === "range" ? resolveTextBlock(snapshot.document, selection.focus.textblockPath) : selection.kind === "node" ? getNodeAtPath(snapshot.document, selection.nodePath) : void 0;
|
|
1179
|
+
return node?.type === "heading" ? node.level : void 0;
|
|
1180
|
+
}
|
|
1181
|
+
function toolbarLinkHref(snapshot) {
|
|
1182
|
+
if (!snapshot || snapshot.selection.kind !== "range") return void 0;
|
|
1183
|
+
const { anchor, focus } = snapshot.selection;
|
|
1184
|
+
const order = compareTextPoints(anchor, focus);
|
|
1185
|
+
if (order === 0) {
|
|
1186
|
+
const stored = snapshot.storedMarks.find((mark) => mark.type === "link");
|
|
1187
|
+
if (stored?.type === "link") return stored.href;
|
|
1188
|
+
}
|
|
1189
|
+
const point = order <= 0 ? anchor : focus;
|
|
1190
|
+
const block = resolveTextBlock(snapshot.document, point.textblockPath);
|
|
1191
|
+
if (!block) return void 0;
|
|
1192
|
+
const affinity = order === 0 ? point.affinity : "after";
|
|
1193
|
+
const length = getTextBlockText(block).length;
|
|
1194
|
+
let offset = 0;
|
|
1195
|
+
for (const child of block.children) {
|
|
1196
|
+
const end = offset + (child.type === "text" ? child.text.length : 1);
|
|
1197
|
+
if ((point.offset > offset && point.offset < end || point.offset === offset && affinity === "after" || point.offset === end && (affinity === "before" || end === length)) && child.type === "text") {
|
|
1198
|
+
const mark = child.marks?.find((value) => value.type === "link");
|
|
1199
|
+
return mark?.type === "link" ? mark.href : void 0;
|
|
1200
|
+
}
|
|
1201
|
+
offset = end;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
function isToolbarHeadingLevel(level) {
|
|
1205
|
+
return level === 1 || level === 2 || level === 3 || level === 4 || level === 5 || level === 6;
|
|
1206
|
+
}
|
|
1207
|
+
var RichTextToolbarComponent = class RichTextToolbarComponent {
|
|
1208
|
+
editor = input.required(...ngDevMode ? [{ debugName: "editor" }] : /* istanbul ignore next */ []);
|
|
1209
|
+
labelOverride = input(void 0, {
|
|
1210
|
+
...ngDevMode ? { debugName: "labelOverride" } : /* istanbul ignore next */ {},
|
|
1211
|
+
alias: "label"
|
|
1212
|
+
});
|
|
1213
|
+
locale = input(...ngDevMode ? [void 0, { debugName: "locale" }] : /* istanbul ignore next */ []);
|
|
1214
|
+
messages = input(...ngDevMode ? [void 0, { debugName: "messages" }] : /* istanbul ignore next */ []);
|
|
1215
|
+
config = input(...ngDevMode ? [void 0, { debugName: "config" }] : /* istanbul ignore next */ []);
|
|
1216
|
+
items = input(...ngDevMode ? [void 0, { debugName: "items" }] : /* istanbul ignore next */ []);
|
|
1217
|
+
buttonTemplate = input(...ngDevMode ? [void 0, { debugName: "buttonTemplate" }] : /* istanbul ignore next */ []);
|
|
1218
|
+
refreshKey = input(...ngDevMode ? [void 0, { debugName: "refreshKey" }] : /* istanbul ignore next */ []);
|
|
1219
|
+
headingLevels = [
|
|
1220
|
+
1,
|
|
1221
|
+
2,
|
|
1222
|
+
3,
|
|
1223
|
+
4,
|
|
1224
|
+
5,
|
|
1225
|
+
6
|
|
1226
|
+
];
|
|
1227
|
+
headingLevel = signal(2, ...ngDevMode ? [{ debugName: "headingLevel" }] : /* istanbul ignore next */ []);
|
|
1228
|
+
linkHref = signal("https://", ...ngDevMode ? [{ debugName: "linkHref" }] : /* istanbul ignore next */ []);
|
|
1229
|
+
linkDirty = signal(false, ...ngDevMode ? [{ debugName: "linkDirty" }] : /* istanbul ignore next */ []);
|
|
1230
|
+
status = signal("", ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
|
|
1231
|
+
linkErrorId = inject(RichTextAccessibilityIds).next("link-error");
|
|
1232
|
+
host = inject(ElementRef);
|
|
1233
|
+
defaults = inject(RICHTEXT_TOOLBAR_CONFIG);
|
|
1234
|
+
i18n = inject(RICHTEXT_I18N);
|
|
1235
|
+
commands = viewChild("commands", ...ngDevMode ? [{ debugName: "commands" }] : /* istanbul ignore next */ []);
|
|
1236
|
+
currentAction = signal("bold", ...ngDevMode ? [{ debugName: "currentAction" }] : /* istanbul ignore next */ []);
|
|
1237
|
+
refreshVersion = signal(0, ...ngDevMode ? [{ debugName: "refreshVersion" }] : /* istanbul ignore next */ []);
|
|
1238
|
+
statusKey = signal(void 0, ...ngDevMode ? [{ debugName: "statusKey" }] : /* istanbul ignore next */ []);
|
|
1239
|
+
destroyed = false;
|
|
1240
|
+
lastFocusedElement;
|
|
1241
|
+
text = computed(() => resolveRichTextMessages(this.locale() ?? this.i18n.locale, this.i18n.messages, this.messages()), ...ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []);
|
|
1242
|
+
label = computed(() => richTextLabel(this.labelOverride(), this.text().toolbarLabel), ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
1243
|
+
iconOnly = computed(() => this.config()?.iconOnly ?? this.defaults.iconOnly ?? false, ...ngDevMode ? [{ debugName: "iconOnly" }] : /* istanbul ignore next */ []);
|
|
1244
|
+
resolvedItems = computed(() => resolveToolbarItems(this.items() ?? this.config()?.items ?? this.defaults.items ?? DEFAULT_RICHTEXT_TOOLBAR_ITEMS), ...ngDevMode ? [{ debugName: "resolvedItems" }] : /* istanbul ignore next */ []);
|
|
1245
|
+
hasItems = computed(() => this.resolvedItems().length > 0, ...ngDevMode ? [{ debugName: "hasItems" }] : /* istanbul ignore next */ []);
|
|
1246
|
+
actions = computed(() => this.resolvedItems().filter((item) => item.kind === "action"), ...ngDevMode ? [{ debugName: "actions" }] : /* istanbul ignore next */ []);
|
|
1247
|
+
fields = computed(() => this.resolvedItems().filter((item) => item.kind === "field").map((item) => ({
|
|
1248
|
+
...item,
|
|
1249
|
+
label: toolbarItemLabel(item, this.text())
|
|
1250
|
+
})), ...ngDevMode ? [{ debugName: "fields" }] : /* istanbul ignore next */ []);
|
|
1251
|
+
queries = computed(() => toolbarActionQueries(this.resolvedItems()), {
|
|
1252
|
+
...ngDevMode ? { debugName: "queries" } : /* istanbul ignore next */ {},
|
|
1253
|
+
equal: sameToolbarActionQueries
|
|
1254
|
+
});
|
|
1255
|
+
staticQueries = computed(() => this.queries().filter((item) => !item.builtin || item.id !== "heading"), {
|
|
1256
|
+
...ngDevMode ? { debugName: "staticQueries" } : /* istanbul ignore next */ {},
|
|
1257
|
+
equal: sameToolbarActionQueries
|
|
1258
|
+
});
|
|
1259
|
+
headingQuery = computed(() => this.queries().filter((item) => item.builtin && item.id === "heading"), {
|
|
1260
|
+
...ngDevMode ? { debugName: "headingQuery" } : /* istanbul ignore next */ {},
|
|
1261
|
+
equal: sameToolbarActionQueries
|
|
1262
|
+
});
|
|
1263
|
+
blocked = computed(() => {
|
|
1264
|
+
const editor = this.editor();
|
|
1265
|
+
return !editor.state() || editor.effectiveDisabled() || editor.readOnly() || editor.composing();
|
|
1266
|
+
}, ...ngDevMode ? [{ debugName: "blocked" }] : /* istanbul ignore next */ []);
|
|
1267
|
+
staticCapabilities = computed(() => {
|
|
1268
|
+
this.refreshKey();
|
|
1269
|
+
this.refreshVersion();
|
|
1270
|
+
this.editor().state();
|
|
1271
|
+
const blocked = this.blocked();
|
|
1272
|
+
return this.staticQueries().map((action) => this.queryButton(action, action.command, blocked));
|
|
1273
|
+
}, ...ngDevMode ? [{ debugName: "staticCapabilities" }] : /* istanbul ignore next */ []);
|
|
1274
|
+
headingCapability = computed(() => {
|
|
1275
|
+
this.refreshKey();
|
|
1276
|
+
this.refreshVersion();
|
|
1277
|
+
const action = this.headingQuery()[0];
|
|
1278
|
+
if (!action) return void 0;
|
|
1279
|
+
this.editor().state();
|
|
1280
|
+
return this.queryButton(action, {
|
|
1281
|
+
type: "setHeading",
|
|
1282
|
+
level: this.headingLevel()
|
|
1283
|
+
}, this.blocked());
|
|
1284
|
+
}, ...ngDevMode ? [{ debugName: "headingCapability" }] : /* istanbul ignore next */ []);
|
|
1285
|
+
buttons = computed(() => {
|
|
1286
|
+
const capabilities = new Map(this.staticCapabilities().map((item) => [item.id, item]));
|
|
1287
|
+
const heading = this.headingCapability();
|
|
1288
|
+
if (heading) capabilities.set(heading.id, heading);
|
|
1289
|
+
const messages = this.text();
|
|
1290
|
+
const iconOnly = this.iconOnly();
|
|
1291
|
+
return this.actions().flatMap((action) => {
|
|
1292
|
+
const capability = capabilities.get(action.id);
|
|
1293
|
+
if (!capability) return [];
|
|
1294
|
+
return [{
|
|
1295
|
+
...capability,
|
|
1296
|
+
...toolbarButtonContent(action, messages, iconOnly)
|
|
1297
|
+
}];
|
|
1298
|
+
});
|
|
1299
|
+
}, ...ngDevMode ? [{ debugName: "buttons" }] : /* istanbul ignore next */ []);
|
|
1300
|
+
tabStop = computed(() => {
|
|
1301
|
+
const available = this.buttons().filter((button) => !button.disabled);
|
|
1302
|
+
return available.find((button) => button.id === this.currentAction())?.id ?? available[0]?.id;
|
|
1303
|
+
}, ...ngDevMode ? [{ debugName: "tabStop" }] : /* istanbul ignore next */ []);
|
|
1304
|
+
headingFieldQuery = computed(() => {
|
|
1305
|
+
const field = this.resolvedItems().find((item) => item.kind === "field" && item.id === "headingLevel");
|
|
1306
|
+
return field === void 0 ? void 0 : { disabled: field.disabled ?? false };
|
|
1307
|
+
}, {
|
|
1308
|
+
...ngDevMode ? { debugName: "headingFieldQuery" } : /* istanbul ignore next */ {},
|
|
1309
|
+
equal: (left, right) => left?.disabled === right?.disabled && left === void 0 === (right === void 0)
|
|
1310
|
+
});
|
|
1311
|
+
linkFieldQuery = computed(() => {
|
|
1312
|
+
const field = this.resolvedItems().find((item) => item.kind === "field" && item.id === "link");
|
|
1313
|
+
return field === void 0 ? void 0 : { disabled: field.disabled ?? false };
|
|
1314
|
+
}, {
|
|
1315
|
+
...ngDevMode ? { debugName: "linkFieldQuery" } : /* istanbul ignore next */ {},
|
|
1316
|
+
equal: (left, right) => left?.disabled === right?.disabled && left === void 0 === (right === void 0)
|
|
1317
|
+
});
|
|
1318
|
+
headingDisabled = computed(() => {
|
|
1319
|
+
this.refreshKey();
|
|
1320
|
+
this.refreshVersion();
|
|
1321
|
+
const field = this.headingFieldQuery();
|
|
1322
|
+
if (!field || field.disabled || this.blocked()) return true;
|
|
1323
|
+
const button = this.headingCapability();
|
|
1324
|
+
const configuredButton = this.headingQuery()[0];
|
|
1325
|
+
if (button && !configuredButton?.disabled) return button.disabled;
|
|
1326
|
+
return !this.editor().can({
|
|
1327
|
+
type: "setHeading",
|
|
1328
|
+
level: this.headingLevel()
|
|
1329
|
+
});
|
|
1330
|
+
}, ...ngDevMode ? [{ debugName: "headingDisabled" }] : /* istanbul ignore next */ []);
|
|
1331
|
+
linksDisabled = computed(() => {
|
|
1332
|
+
this.refreshKey();
|
|
1333
|
+
this.refreshVersion();
|
|
1334
|
+
const field = this.linkFieldQuery();
|
|
1335
|
+
return !field || field.disabled || this.blocked() || !this.editor().can({
|
|
1336
|
+
type: "setLink",
|
|
1337
|
+
href: "https://example.invalid"
|
|
1338
|
+
});
|
|
1339
|
+
}, ...ngDevMode ? [{ debugName: "linksDisabled" }] : /* istanbul ignore next */ []);
|
|
1340
|
+
linkInvalid = computed(() => this.linkFieldQuery() !== void 0 && this.linkDirty() && !safeLinkPolicy(this.linkHref()), ...ngDevMode ? [{ debugName: "linkInvalid" }] : /* istanbul ignore next */ []);
|
|
1341
|
+
applyLinkDisabled = computed(() => {
|
|
1342
|
+
this.refreshKey();
|
|
1343
|
+
this.refreshVersion();
|
|
1344
|
+
const field = this.linkFieldQuery();
|
|
1345
|
+
return !field || field.disabled || this.blocked() || !safeLinkPolicy(this.linkHref()) || !this.editor().can({
|
|
1346
|
+
type: "setLink",
|
|
1347
|
+
href: this.linkHref()
|
|
1348
|
+
});
|
|
1349
|
+
}, ...ngDevMode ? [{ debugName: "applyLinkDisabled" }] : /* istanbul ignore next */ []);
|
|
1350
|
+
removeLinkDisabled = computed(() => {
|
|
1351
|
+
this.refreshKey();
|
|
1352
|
+
this.refreshVersion();
|
|
1353
|
+
const field = this.linkFieldQuery();
|
|
1354
|
+
return !field || field.disabled || this.blocked() || !this.editor().can({ type: "unsetLink" });
|
|
1355
|
+
}, ...ngDevMode ? [{ debugName: "removeLinkDisabled" }] : /* istanbul ignore next */ []);
|
|
1356
|
+
constructor() {
|
|
1357
|
+
inject(DestroyRef).onDestroy(() => {
|
|
1358
|
+
this.destroyed = true;
|
|
1359
|
+
});
|
|
1360
|
+
effect((onCleanup) => {
|
|
1361
|
+
const editor = this.editor();
|
|
1362
|
+
onCleanup(untracked(() => editor.registerFocusRegion(this.host.nativeElement)));
|
|
1363
|
+
this.currentAction.set("bold");
|
|
1364
|
+
this.linkDirty.set(false);
|
|
1365
|
+
this.linkHref.set("https://");
|
|
1366
|
+
this.statusKey.set(void 0);
|
|
1367
|
+
this.status.set("");
|
|
1368
|
+
});
|
|
1369
|
+
effect(() => {
|
|
1370
|
+
const key = this.statusKey();
|
|
1371
|
+
const messages = this.text();
|
|
1372
|
+
if (key) this.status.set(messages[key]);
|
|
1373
|
+
});
|
|
1374
|
+
effect(() => {
|
|
1375
|
+
const level = toolbarHeadingLevel(this.editor().state());
|
|
1376
|
+
if (level !== void 0) this.headingLevel.set(level);
|
|
1377
|
+
});
|
|
1378
|
+
effect(() => {
|
|
1379
|
+
const state = this.editor().state();
|
|
1380
|
+
if (!this.linkDirty()) {
|
|
1381
|
+
const href = toolbarLinkHref(state);
|
|
1382
|
+
if (href !== void 0) this.linkHref.set(href);
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
effect(() => {
|
|
1386
|
+
const buttons = this.buttons();
|
|
1387
|
+
const fields = this.fields();
|
|
1388
|
+
const root = this.host.nativeElement;
|
|
1389
|
+
const current = root.ownerDocument.activeElement;
|
|
1390
|
+
const active = current === root.ownerDocument.body && this.lastFocusedElement && (!this.lastFocusedElement.isConnected || this.lastFocusedElement.matches(":disabled")) ? this.lastFocusedElement : current;
|
|
1391
|
+
if (!(active instanceof HTMLElement) || !root.contains(active) && active !== this.lastFocusedElement) return;
|
|
1392
|
+
const actionId = active.getAttribute("data-richtext-action");
|
|
1393
|
+
const fieldId = active.closest("[data-richtext-field]")?.getAttribute("data-richtext-field");
|
|
1394
|
+
if (actionId ? buttons.some((button) => button.id === actionId && !button.disabled) : fieldId ? fields.some((field) => field.id === fieldId && !field.disabled) : true) return;
|
|
1395
|
+
queueMicrotask(() => {
|
|
1396
|
+
if (this.destroyed) return;
|
|
1397
|
+
const now = root.ownerDocument.activeElement;
|
|
1398
|
+
if (now !== active && now !== root.ownerDocument.body) return;
|
|
1399
|
+
this.lastFocusedElement = void 0;
|
|
1400
|
+
const target = root.querySelector("button[data-richtext-action]:not(:disabled), select:not(:disabled), input:not(:disabled)");
|
|
1401
|
+
if (target) target.focus();
|
|
1402
|
+
else this.editor().focus();
|
|
1403
|
+
});
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
refresh() {
|
|
1407
|
+
this.refreshVersion.update((value) => value + 1);
|
|
1408
|
+
}
|
|
1409
|
+
queryButton(action, command, blocked) {
|
|
1410
|
+
const editor = this.editor();
|
|
1411
|
+
return {
|
|
1412
|
+
id: action.id,
|
|
1413
|
+
command,
|
|
1414
|
+
disabled: action.disabled || blocked || !editor.can(command),
|
|
1415
|
+
...action.toggle ? { pressed: !action.disabled && editor.isActiveCommand(command) } : {}
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
announce(key) {
|
|
1419
|
+
this.statusKey.set(key);
|
|
1420
|
+
this.status.set(this.text()[key]);
|
|
1421
|
+
}
|
|
1422
|
+
preserveSelection(event) {
|
|
1423
|
+
if (event.button === 0) event.preventDefault();
|
|
1424
|
+
}
|
|
1425
|
+
execute(button) {
|
|
1426
|
+
if (button.disabled) return;
|
|
1427
|
+
this.currentAction.set(button.id);
|
|
1428
|
+
const result = this.editor().execute(button.command);
|
|
1429
|
+
this.announce(result && !result.ok ? "actionUnavailable" : button.id === "undo" ? "undoDone" : button.id === "redo" ? "redoDone" : "formatDone");
|
|
1430
|
+
}
|
|
1431
|
+
changeHeadingLevel(event) {
|
|
1432
|
+
if (!(event.target instanceof HTMLSelectElement)) return;
|
|
1433
|
+
const level = Number(event.target.value);
|
|
1434
|
+
if (isToolbarHeadingLevel(level)) this.headingLevel.set(level);
|
|
1435
|
+
}
|
|
1436
|
+
changeLink(value) {
|
|
1437
|
+
this.linkDirty.set(true);
|
|
1438
|
+
this.linkHref.set(value);
|
|
1439
|
+
this.statusKey.set(void 0);
|
|
1440
|
+
this.status.set("");
|
|
1441
|
+
}
|
|
1442
|
+
applyLink(event) {
|
|
1443
|
+
event?.preventDefault();
|
|
1444
|
+
if (this.applyLinkDisabled()) {
|
|
1445
|
+
if (this.linkInvalid()) this.announce("invalidLink");
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
const result = this.editor().execute({
|
|
1449
|
+
type: "setLink",
|
|
1450
|
+
href: this.linkHref()
|
|
1451
|
+
});
|
|
1452
|
+
if (result?.ok) this.linkDirty.set(false);
|
|
1453
|
+
this.announce(result?.ok ? "linkApplied" : "linkNotApplied");
|
|
1454
|
+
}
|
|
1455
|
+
removeLink() {
|
|
1456
|
+
if (this.removeLinkDisabled()) return;
|
|
1457
|
+
const result = this.editor().execute({ type: "unsetLink" });
|
|
1458
|
+
this.announce(result?.ok ? "linkRemoved" : "linkNotRemoved");
|
|
1459
|
+
}
|
|
1460
|
+
rememberFocus(event) {
|
|
1461
|
+
const target = event.target;
|
|
1462
|
+
if (target instanceof HTMLElement) this.lastFocusedElement = target;
|
|
1463
|
+
if (!(target instanceof HTMLButtonElement)) return;
|
|
1464
|
+
const id = target.getAttribute("data-richtext-action");
|
|
1465
|
+
if (id) this.currentAction.set(id);
|
|
1466
|
+
}
|
|
1467
|
+
navigate(event) {
|
|
1468
|
+
if (event.isComposing || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || !(event.target instanceof HTMLButtonElement)) return;
|
|
1469
|
+
const key = event.key;
|
|
1470
|
+
if (key !== "ArrowLeft" && key !== "ArrowRight" && key !== "Home" && key !== "End") return;
|
|
1471
|
+
const id = nextToolbarItem(this.buttons(), event.target.getAttribute("data-richtext-action") ?? void 0, key);
|
|
1472
|
+
if (!id) return;
|
|
1473
|
+
event.preventDefault();
|
|
1474
|
+
this.currentAction.set(id);
|
|
1475
|
+
const buttons = this.commands()?.nativeElement.querySelectorAll("button[data-richtext-action]");
|
|
1476
|
+
for (const button of buttons ?? []) if (button.getAttribute("data-richtext-action") === id) {
|
|
1477
|
+
button.focus();
|
|
1478
|
+
break;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1482
|
+
minVersion: "12.0.0",
|
|
1483
|
+
version: "22.2.6",
|
|
1484
|
+
ngImport: i0,
|
|
1485
|
+
type: RichTextToolbarComponent,
|
|
1486
|
+
deps: [],
|
|
1487
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
1488
|
+
});
|
|
1489
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
1490
|
+
minVersion: "17.0.0",
|
|
1491
|
+
version: "22.2.6",
|
|
1492
|
+
type: RichTextToolbarComponent,
|
|
1493
|
+
isStandalone: true,
|
|
1494
|
+
selector: "kles-richtext-toolbar",
|
|
1495
|
+
inputs: {
|
|
1496
|
+
editor: {
|
|
1497
|
+
classPropertyName: "editor",
|
|
1498
|
+
publicName: "editor",
|
|
1499
|
+
isSignal: true,
|
|
1500
|
+
isRequired: true,
|
|
1501
|
+
transformFunction: null
|
|
1502
|
+
},
|
|
1503
|
+
labelOverride: {
|
|
1504
|
+
classPropertyName: "labelOverride",
|
|
1505
|
+
publicName: "label",
|
|
1506
|
+
isSignal: true,
|
|
1507
|
+
isRequired: false,
|
|
1508
|
+
transformFunction: null
|
|
1509
|
+
},
|
|
1510
|
+
locale: {
|
|
1511
|
+
classPropertyName: "locale",
|
|
1512
|
+
publicName: "locale",
|
|
1513
|
+
isSignal: true,
|
|
1514
|
+
isRequired: false,
|
|
1515
|
+
transformFunction: null
|
|
1516
|
+
},
|
|
1517
|
+
messages: {
|
|
1518
|
+
classPropertyName: "messages",
|
|
1519
|
+
publicName: "messages",
|
|
1520
|
+
isSignal: true,
|
|
1521
|
+
isRequired: false,
|
|
1522
|
+
transformFunction: null
|
|
1523
|
+
},
|
|
1524
|
+
config: {
|
|
1525
|
+
classPropertyName: "config",
|
|
1526
|
+
publicName: "config",
|
|
1527
|
+
isSignal: true,
|
|
1528
|
+
isRequired: false,
|
|
1529
|
+
transformFunction: null
|
|
1530
|
+
},
|
|
1531
|
+
items: {
|
|
1532
|
+
classPropertyName: "items",
|
|
1533
|
+
publicName: "items",
|
|
1534
|
+
isSignal: true,
|
|
1535
|
+
isRequired: false,
|
|
1536
|
+
transformFunction: null
|
|
1537
|
+
},
|
|
1538
|
+
buttonTemplate: {
|
|
1539
|
+
classPropertyName: "buttonTemplate",
|
|
1540
|
+
publicName: "buttonTemplate",
|
|
1541
|
+
isSignal: true,
|
|
1542
|
+
isRequired: false,
|
|
1543
|
+
transformFunction: null
|
|
1544
|
+
},
|
|
1545
|
+
refreshKey: {
|
|
1546
|
+
classPropertyName: "refreshKey",
|
|
1547
|
+
publicName: "refreshKey",
|
|
1548
|
+
isSignal: true,
|
|
1549
|
+
isRequired: false,
|
|
1550
|
+
transformFunction: null
|
|
1551
|
+
}
|
|
1552
|
+
},
|
|
1553
|
+
viewQueries: [{
|
|
1554
|
+
propertyName: "commands",
|
|
1555
|
+
first: true,
|
|
1556
|
+
predicate: ["commands"],
|
|
1557
|
+
descendants: true,
|
|
1558
|
+
isSignal: true
|
|
1559
|
+
}],
|
|
1560
|
+
ngImport: i0,
|
|
1561
|
+
template: "<div class=\"kles-richtext-toolbar\" (focusin)=\"rememberFocus($event)\">\n @if (hasItems()) {\n @if (buttons().length) {\n <div\n #commands\n class=\"kles-richtext-toolbar__commands\"\n role=\"toolbar\"\n [attr.aria-label]=\"label()\"\n [attr.aria-disabled]=\"blocked()\"\n [attr.aria-busy]=\"editor().composing()\"\n (keydown)=\"navigate($event)\"\n >\n @for (button of buttons(); track button.id) {\n <button\n type=\"button\"\n [attr.data-richtext-action]=\"button.id\"\n [class.kles-richtext-toolbar__button-with-icon]=\"!buttonTemplate() && !!button.icon\"\n [disabled]=\"button.disabled\"\n [attr.aria-label]=\"button.ariaLabel\"\n [attr.title]=\"button.label ? null : button.ariaLabel\"\n [attr.aria-pressed]=\"button.pressed ?? null\"\n [tabIndex]=\"tabStop() === button.id ? 0 : -1\"\n (mousedown)=\"preserveSelection($event)\"\n (click)=\"execute(button)\"\n >\n @if (buttonTemplate(); as template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"{ $implicit: button, item: button }\"\n />\n } @else {\n @if (button.iconType === 'material') {\n <span\n class=\"kles-richtext-toolbar__material-icon\"\n [attr.data-material-icon]=\"button.icon\"\n aria-hidden=\"true\"\n ></span>\n } @else if (button.icon) {\n <span aria-hidden=\"true\">{{ button.icon }}</span>\n }\n {{ button.label }}\n }\n </button>\n }\n </div>\n }\n @if (fields().length) {\n <div class=\"kles-richtext-toolbar__fields\" role=\"group\" [attr.aria-label]=\"text().toolbarFields\">\n @for (field of fields(); track field.id) {\n @if (field.id === 'headingLevel') {\n <label class=\"kles-richtext-toolbar__level\" data-richtext-field=\"headingLevel\">\n {{ field.label }}\n <select\n [attr.aria-label]=\"field.ariaLabel?.trim() || text().headingLevelLabel\"\n [disabled]=\"headingDisabled()\"\n (change)=\"changeHeadingLevel($event)\"\n >\n @for (level of headingLevels; track level) {\n <option [value]=\"level\" [selected]=\"level === headingLevel()\">{{ level }}</option>\n }\n </select>\n </label>\n } @else {\n <label class=\"kles-richtext-toolbar__link\" data-richtext-field=\"link\">\n {{ field.label }}\n <input\n #linkInput\n type=\"url\"\n [disabled]=\"linksDisabled()\"\n [value]=\"linkHref()\"\n [attr.aria-label]=\"field.ariaLabel?.trim() || field.label\"\n [attr.aria-invalid]=\"linkInvalid() ? 'true' : null\"\n [attr.aria-describedby]=\"linkInvalid() ? linkErrorId : null\"\n (input)=\"changeLink(linkInput.value)\"\n (keydown.enter)=\"applyLink($event)\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n />\n </label>\n <button\n type=\"button\"\n data-richtext-field=\"link\"\n [class.kles-richtext-toolbar__button-with-icon]=\"iconOnly()\"\n [disabled]=\"applyLinkDisabled()\"\n [attr.aria-label]=\"iconOnly() ? text().applyLink : null\"\n [attr.title]=\"iconOnly() ? text().applyLink : null\"\n (mousedown)=\"preserveSelection($event)\"\n (click)=\"applyLink()\"\n >\n @if (iconOnly()) {\n <span\n class=\"kles-richtext-toolbar__material-icon\"\n data-material-icon=\"link\"\n aria-hidden=\"true\"\n ></span>\n } @else {\n {{ text().applyLink }}\n }\n </button>\n <button\n type=\"button\"\n data-richtext-field=\"link\"\n [class.kles-richtext-toolbar__button-with-icon]=\"iconOnly()\"\n [disabled]=\"removeLinkDisabled()\"\n [attr.aria-label]=\"iconOnly() ? text().removeLink : null\"\n [attr.title]=\"iconOnly() ? text().removeLink : null\"\n (mousedown)=\"preserveSelection($event)\"\n (click)=\"removeLink()\"\n >\n @if (iconOnly()) {\n <span\n class=\"kles-richtext-toolbar__material-icon\"\n data-material-icon=\"link_off\"\n aria-hidden=\"true\"\n ></span>\n } @else {\n {{ text().removeLink }}\n }\n </button>\n }\n }\n </div>\n }\n @if (linkInvalid()) {\n <p [id]=\"linkErrorId\" class=\"kles-richtext-toolbar__error\">{{ text().invalidLink }}</p>\n }\n <p class=\"kles-richtext-toolbar__status\" role=\"status\" aria-live=\"polite\">{{ status() }}</p>\n }\n</div>\n",
|
|
1562
|
+
styles: [":host{display:block;min-width:0;max-width:100%}.kles-richtext-toolbar{margin-block-end:1rem;color:inherit}.kles-richtext-toolbar__commands,.kles-richtext-toolbar__fields{display:flex;align-items:center;flex-wrap:wrap;gap:.5rem}.kles-richtext-toolbar__fields{align-items:flex-end;margin-block-start:.75rem}.kles-richtext-toolbar__level,.kles-richtext-toolbar__link{display:flex;flex-direction:column;gap:.35rem;margin:0;font-weight:600;min-width:0}.kles-richtext-toolbar__link{flex:1 1 14rem;max-width:28rem}.kles-richtext-toolbar button,.kles-richtext-toolbar input,.kles-richtext-toolbar select{box-sizing:border-box;font:inherit;min-height:2.75rem;max-width:100%;padding:.5rem .7rem;border:1px solid var(--kles-richtext-toolbar-accent, var(--accent, #174f89));border-radius:var(--kles-richtext-toolbar-radius, .5rem);background:var(--kles-richtext-toolbar-background, var(--surface, #fff));color:var(--kles-richtext-toolbar-accent, var(--accent, #174f89))}.kles-richtext-toolbar input{min-width:0;width:100%;color:inherit}.kles-richtext-toolbar button{cursor:pointer;overflow-wrap:anywhere}.kles-richtext-toolbar button.kles-richtext-toolbar__button-with-icon{display:inline-flex;align-items:center;justify-content:center;gap:.35rem;min-inline-size:2.75rem}.kles-richtext-toolbar__material-icon{font-family:var(--kles-richtext-toolbar-material-icon-font, \"Material Icons\");font-feature-settings:\"liga\";font-style:normal;font-weight:400;font-size:1.5rem;line-height:1;letter-spacing:normal;text-transform:none;white-space:nowrap;direction:ltr}.kles-richtext-toolbar__material-icon:before{content:attr(data-material-icon)}.kles-richtext-toolbar button:hover:enabled{text-decoration:underline}.kles-richtext-toolbar button[aria-pressed=true]{background:var(--kles-richtext-toolbar-accent, var(--accent, #174f89));color:var(--kles-richtext-toolbar-background, var(--surface, #fff))}.kles-richtext-toolbar :is(button,input,select):disabled{opacity:.5;cursor:not-allowed}.kles-richtext-toolbar :is(button,input,select):focus-visible{outline:3px solid var(--kles-richtext-toolbar-focus, var(--accent, #174f89));outline-offset:3px}.kles-richtext-toolbar input[aria-invalid=true]{border-color:var(--kles-richtext-toolbar-error, var(--error, #9e2020))}.kles-richtext-toolbar__status{margin:.5rem 0 0;font-size:.9rem;line-height:1.5}.kles-richtext-toolbar__status:empty{margin:0}.kles-richtext-toolbar__error{color:var(--kles-richtext-toolbar-error, var(--error, #9e2020));margin:.5rem 0 0;line-height:1.5}\n"],
|
|
1563
|
+
dependencies: [{
|
|
1564
|
+
kind: "directive",
|
|
1565
|
+
type: NgTemplateOutlet,
|
|
1566
|
+
selector: "[ngTemplateOutlet]",
|
|
1567
|
+
inputs: [
|
|
1568
|
+
"ngTemplateOutletContext",
|
|
1569
|
+
"ngTemplateOutlet",
|
|
1570
|
+
"ngTemplateOutletInjector"
|
|
1571
|
+
]
|
|
1572
|
+
}],
|
|
1573
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
1574
|
+
});
|
|
1575
|
+
};
|
|
1576
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1577
|
+
minVersion: "12.0.0",
|
|
1578
|
+
version: "22.2.6",
|
|
1579
|
+
ngImport: i0,
|
|
1580
|
+
type: RichTextToolbarComponent,
|
|
1581
|
+
decorators: [{
|
|
1582
|
+
type: Component,
|
|
1583
|
+
args: [{
|
|
1584
|
+
selector: "kles-richtext-toolbar",
|
|
1585
|
+
standalone: true,
|
|
1586
|
+
imports: [NgTemplateOutlet],
|
|
1587
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
1588
|
+
template: "<div class=\"kles-richtext-toolbar\" (focusin)=\"rememberFocus($event)\">\n @if (hasItems()) {\n @if (buttons().length) {\n <div\n #commands\n class=\"kles-richtext-toolbar__commands\"\n role=\"toolbar\"\n [attr.aria-label]=\"label()\"\n [attr.aria-disabled]=\"blocked()\"\n [attr.aria-busy]=\"editor().composing()\"\n (keydown)=\"navigate($event)\"\n >\n @for (button of buttons(); track button.id) {\n <button\n type=\"button\"\n [attr.data-richtext-action]=\"button.id\"\n [class.kles-richtext-toolbar__button-with-icon]=\"!buttonTemplate() && !!button.icon\"\n [disabled]=\"button.disabled\"\n [attr.aria-label]=\"button.ariaLabel\"\n [attr.title]=\"button.label ? null : button.ariaLabel\"\n [attr.aria-pressed]=\"button.pressed ?? null\"\n [tabIndex]=\"tabStop() === button.id ? 0 : -1\"\n (mousedown)=\"preserveSelection($event)\"\n (click)=\"execute(button)\"\n >\n @if (buttonTemplate(); as template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"{ $implicit: button, item: button }\"\n />\n } @else {\n @if (button.iconType === 'material') {\n <span\n class=\"kles-richtext-toolbar__material-icon\"\n [attr.data-material-icon]=\"button.icon\"\n aria-hidden=\"true\"\n ></span>\n } @else if (button.icon) {\n <span aria-hidden=\"true\">{{ button.icon }}</span>\n }\n {{ button.label }}\n }\n </button>\n }\n </div>\n }\n @if (fields().length) {\n <div class=\"kles-richtext-toolbar__fields\" role=\"group\" [attr.aria-label]=\"text().toolbarFields\">\n @for (field of fields(); track field.id) {\n @if (field.id === 'headingLevel') {\n <label class=\"kles-richtext-toolbar__level\" data-richtext-field=\"headingLevel\">\n {{ field.label }}\n <select\n [attr.aria-label]=\"field.ariaLabel?.trim() || text().headingLevelLabel\"\n [disabled]=\"headingDisabled()\"\n (change)=\"changeHeadingLevel($event)\"\n >\n @for (level of headingLevels; track level) {\n <option [value]=\"level\" [selected]=\"level === headingLevel()\">{{ level }}</option>\n }\n </select>\n </label>\n } @else {\n <label class=\"kles-richtext-toolbar__link\" data-richtext-field=\"link\">\n {{ field.label }}\n <input\n #linkInput\n type=\"url\"\n [disabled]=\"linksDisabled()\"\n [value]=\"linkHref()\"\n [attr.aria-label]=\"field.ariaLabel?.trim() || field.label\"\n [attr.aria-invalid]=\"linkInvalid() ? 'true' : null\"\n [attr.aria-describedby]=\"linkInvalid() ? linkErrorId : null\"\n (input)=\"changeLink(linkInput.value)\"\n (keydown.enter)=\"applyLink($event)\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n />\n </label>\n <button\n type=\"button\"\n data-richtext-field=\"link\"\n [class.kles-richtext-toolbar__button-with-icon]=\"iconOnly()\"\n [disabled]=\"applyLinkDisabled()\"\n [attr.aria-label]=\"iconOnly() ? text().applyLink : null\"\n [attr.title]=\"iconOnly() ? text().applyLink : null\"\n (mousedown)=\"preserveSelection($event)\"\n (click)=\"applyLink()\"\n >\n @if (iconOnly()) {\n <span\n class=\"kles-richtext-toolbar__material-icon\"\n data-material-icon=\"link\"\n aria-hidden=\"true\"\n ></span>\n } @else {\n {{ text().applyLink }}\n }\n </button>\n <button\n type=\"button\"\n data-richtext-field=\"link\"\n [class.kles-richtext-toolbar__button-with-icon]=\"iconOnly()\"\n [disabled]=\"removeLinkDisabled()\"\n [attr.aria-label]=\"iconOnly() ? text().removeLink : null\"\n [attr.title]=\"iconOnly() ? text().removeLink : null\"\n (mousedown)=\"preserveSelection($event)\"\n (click)=\"removeLink()\"\n >\n @if (iconOnly()) {\n <span\n class=\"kles-richtext-toolbar__material-icon\"\n data-material-icon=\"link_off\"\n aria-hidden=\"true\"\n ></span>\n } @else {\n {{ text().removeLink }}\n }\n </button>\n }\n }\n </div>\n }\n @if (linkInvalid()) {\n <p [id]=\"linkErrorId\" class=\"kles-richtext-toolbar__error\">{{ text().invalidLink }}</p>\n }\n <p class=\"kles-richtext-toolbar__status\" role=\"status\" aria-live=\"polite\">{{ status() }}</p>\n }\n</div>\n",
|
|
1589
|
+
styles: [":host{display:block;min-width:0;max-width:100%}.kles-richtext-toolbar{margin-block-end:1rem;color:inherit}.kles-richtext-toolbar__commands,.kles-richtext-toolbar__fields{display:flex;align-items:center;flex-wrap:wrap;gap:.5rem}.kles-richtext-toolbar__fields{align-items:flex-end;margin-block-start:.75rem}.kles-richtext-toolbar__level,.kles-richtext-toolbar__link{display:flex;flex-direction:column;gap:.35rem;margin:0;font-weight:600;min-width:0}.kles-richtext-toolbar__link{flex:1 1 14rem;max-width:28rem}.kles-richtext-toolbar button,.kles-richtext-toolbar input,.kles-richtext-toolbar select{box-sizing:border-box;font:inherit;min-height:2.75rem;max-width:100%;padding:.5rem .7rem;border:1px solid var(--kles-richtext-toolbar-accent, var(--accent, #174f89));border-radius:var(--kles-richtext-toolbar-radius, .5rem);background:var(--kles-richtext-toolbar-background, var(--surface, #fff));color:var(--kles-richtext-toolbar-accent, var(--accent, #174f89))}.kles-richtext-toolbar input{min-width:0;width:100%;color:inherit}.kles-richtext-toolbar button{cursor:pointer;overflow-wrap:anywhere}.kles-richtext-toolbar button.kles-richtext-toolbar__button-with-icon{display:inline-flex;align-items:center;justify-content:center;gap:.35rem;min-inline-size:2.75rem}.kles-richtext-toolbar__material-icon{font-family:var(--kles-richtext-toolbar-material-icon-font, \"Material Icons\");font-feature-settings:\"liga\";font-style:normal;font-weight:400;font-size:1.5rem;line-height:1;letter-spacing:normal;text-transform:none;white-space:nowrap;direction:ltr}.kles-richtext-toolbar__material-icon:before{content:attr(data-material-icon)}.kles-richtext-toolbar button:hover:enabled{text-decoration:underline}.kles-richtext-toolbar button[aria-pressed=true]{background:var(--kles-richtext-toolbar-accent, var(--accent, #174f89));color:var(--kles-richtext-toolbar-background, var(--surface, #fff))}.kles-richtext-toolbar :is(button,input,select):disabled{opacity:.5;cursor:not-allowed}.kles-richtext-toolbar :is(button,input,select):focus-visible{outline:3px solid var(--kles-richtext-toolbar-focus, var(--accent, #174f89));outline-offset:3px}.kles-richtext-toolbar input[aria-invalid=true]{border-color:var(--kles-richtext-toolbar-error, var(--error, #9e2020))}.kles-richtext-toolbar__status{margin:.5rem 0 0;font-size:.9rem;line-height:1.5}.kles-richtext-toolbar__status:empty{margin:0}.kles-richtext-toolbar__error{color:var(--kles-richtext-toolbar-error, var(--error, #9e2020));margin:.5rem 0 0;line-height:1.5}\n"]
|
|
1590
|
+
}]
|
|
1591
|
+
}],
|
|
1592
|
+
ctorParameters: () => [],
|
|
1593
|
+
propDecorators: {
|
|
1594
|
+
editor: [{
|
|
1595
|
+
type: i0.Input,
|
|
1596
|
+
args: [{
|
|
1597
|
+
isSignal: true,
|
|
1598
|
+
alias: "editor",
|
|
1599
|
+
required: true
|
|
1600
|
+
}]
|
|
1601
|
+
}],
|
|
1602
|
+
labelOverride: [{
|
|
1603
|
+
type: i0.Input,
|
|
1604
|
+
args: [{
|
|
1605
|
+
isSignal: true,
|
|
1606
|
+
alias: "label",
|
|
1607
|
+
required: false
|
|
1608
|
+
}]
|
|
1609
|
+
}],
|
|
1610
|
+
locale: [{
|
|
1611
|
+
type: i0.Input,
|
|
1612
|
+
args: [{
|
|
1613
|
+
isSignal: true,
|
|
1614
|
+
alias: "locale",
|
|
1615
|
+
required: false
|
|
1616
|
+
}]
|
|
1617
|
+
}],
|
|
1618
|
+
messages: [{
|
|
1619
|
+
type: i0.Input,
|
|
1620
|
+
args: [{
|
|
1621
|
+
isSignal: true,
|
|
1622
|
+
alias: "messages",
|
|
1623
|
+
required: false
|
|
1624
|
+
}]
|
|
1625
|
+
}],
|
|
1626
|
+
config: [{
|
|
1627
|
+
type: i0.Input,
|
|
1628
|
+
args: [{
|
|
1629
|
+
isSignal: true,
|
|
1630
|
+
alias: "config",
|
|
1631
|
+
required: false
|
|
1632
|
+
}]
|
|
1633
|
+
}],
|
|
1634
|
+
items: [{
|
|
1635
|
+
type: i0.Input,
|
|
1636
|
+
args: [{
|
|
1637
|
+
isSignal: true,
|
|
1638
|
+
alias: "items",
|
|
1639
|
+
required: false
|
|
1640
|
+
}]
|
|
1641
|
+
}],
|
|
1642
|
+
buttonTemplate: [{
|
|
1643
|
+
type: i0.Input,
|
|
1644
|
+
args: [{
|
|
1645
|
+
isSignal: true,
|
|
1646
|
+
alias: "buttonTemplate",
|
|
1647
|
+
required: false
|
|
1648
|
+
}]
|
|
1649
|
+
}],
|
|
1650
|
+
refreshKey: [{
|
|
1651
|
+
type: i0.Input,
|
|
1652
|
+
args: [{
|
|
1653
|
+
isSignal: true,
|
|
1654
|
+
alias: "refreshKey",
|
|
1655
|
+
required: false
|
|
1656
|
+
}]
|
|
1657
|
+
}],
|
|
1658
|
+
commands: [{
|
|
1659
|
+
type: i0.ViewChild,
|
|
1660
|
+
args: ["commands", { isSignal: true }]
|
|
1661
|
+
}]
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
export { DEFAULT_RICHTEXT_TOOLBAR_ITEMS, RICHTEXT_EDITOR_EXTENSIONS, RICHTEXT_I18N, RICHTEXT_MESSAGES_EN, RICHTEXT_MESSAGES_FR, RICHTEXT_TOOLBAR_CONFIG, RichTextDocumentPreviewComponent, RichTextEditorComponent, RichTextToolbarComponent, provideRichTextI18n, provideRichTextToolbar, richTextDocumentValidator, richTextRequiredValidator, validateRichTextValue };
|
|
1665
|
+
|
|
1666
|
+
//# sourceMappingURL=3kles-kles-richtext-editor.mjs.map
|