@3kles/kles-richtext-editor 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/fesm2022/3kles-kles-richtext-editor-dynamicforms.mjs +179 -0
- package/fesm2022/3kles-kles-richtext-editor-dynamicforms.mjs.map +1 -0
- package/fesm2022/3kles-kles-richtext-editor.mjs +91 -10
- package/fesm2022/3kles-kles-richtext-editor.mjs.map +1 -1
- package/package.json +15 -4
- package/types/3kles-kles-richtext-editor-dynamicforms.d.ts +24 -0
- package/types/3kles-kles-richtext-editor-dynamicforms.d.ts.map +1 -0
- package/types/3kles-kles-richtext-editor.d.ts +14 -1
- package/types/3kles-kles-richtext-editor.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ export class DocumentFormComponent {
|
|
|
44
44
|
}
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
The form value is the native `DocumentNode` AST. Passing `null`, including through `reset()`, displays a canonical empty document. The core validates and copies external values. If a value is invalid, the editor keeps displaying the previous document and reports `richtextDocument` with schema diagnostics.
|
|
47
|
+
The default form value is the native `DocumentNode` AST. Passing `null`, including through `reset()`, displays a canonical empty document. The core validates and copies external values. If a value is invalid, the editor keeps displaying the previous document and reports `richtextDocument` with schema diagnostics. Select `formValueFormat="html"` when binding a control containing HTML strings.
|
|
48
48
|
|
|
49
49
|
An external write received during a native notification takes precedence over the remaining events from that edit. If the write is invalid, the editor preserves its error and the control value until notification completes. The earlier `documentChange` cannot overwrite it through `onChange`. A newer valid write supersedes the rejected write, and a subsequent edit can correct the invalid value.
|
|
50
50
|
|
|
@@ -105,6 +105,8 @@ The component defers `readOnly` until composition ends. `disabled` immediately b
|
|
|
105
105
|
|
|
106
106
|
`loadHtml(html, emitChange = false)`, `insertHtml(html)`, and `getHtml()` expose sanitized conversion and diagnostics. Loading replaces the document, resets history, and works in read-only mode. The legacy `emitChange` option requests a `documentChange` output without calling the Forms `onChange` callback. Insertion is an undoable edit. `editorEvent` also reports paste diagnostics as `contentDiagnostics`. To load HTML into a form, convert it to an AST and write that value to the control.
|
|
107
107
|
|
|
108
|
+
The toolbar and `setLink` accept complete template destinations such as `${context.url}`. The editor and preview keep these destinations inert. `loadHtml()` and `getHtml()` preserve the literal variable in `href`, ready for the consuming application's template rendering.
|
|
109
|
+
|
|
108
110
|
## Configuration and lifecycle
|
|
109
111
|
|
|
110
112
|
`RICHTEXT_EDITOR_EXTENSIONS` configures instances within its injection scope. Without a provider, the editor installs the native preset. An empty array preserves basic editing and existing documents. The editor captures the configuration at mount time and rejects collisions before modifying the surface.
|
|
@@ -115,4 +117,26 @@ The peer dependencies are `@angular/common`, `@angular/core`, and `@angular/form
|
|
|
115
117
|
|
|
116
118
|
The workspace Angular and browser suites verify Forms, the toolbar, and consumption from an external package. The phase reports document limits for cross-platform composition, Firefox and WebKit, screen readers, and performance.
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
## Dynamic Forms
|
|
121
|
+
|
|
122
|
+
Import `RichTextDynamicFieldComponent` and `RichTextDynamicFieldConfig` from `@3kles/kles-richtext-editor/dynamicforms`. This entry point requires the optional peer `@3kles/kles-material-dynamicforms` at `^22.11.0`. The primary entry point works independently of that peer.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { provideRichTextToolbar, richTextHtmlRequiredValidator } from '@3kles/kles-richtext-editor';
|
|
126
|
+
import { RichTextDynamicFieldComponent } from '@3kles/kles-richtext-editor/dynamicforms';
|
|
127
|
+
import type { RichTextDynamicFieldConfig } from '@3kles/kles-richtext-editor/dynamicforms';
|
|
128
|
+
|
|
129
|
+
const body: RichTextDynamicFieldConfig = {
|
|
130
|
+
name: 'body',
|
|
131
|
+
component: RichTextDynamicFieldComponent,
|
|
132
|
+
label: 'Message',
|
|
133
|
+
richTextValueFormat: 'html',
|
|
134
|
+
value: '<p><a href="${process.url}">Open the process</a></p>',
|
|
135
|
+
providers: [provideRichTextToolbar({ items: ['bold', 'italic', 'link', 'undo', 'redo'] })],
|
|
136
|
+
validations: [{ name: 'required', message: 'Enter a message.', validator: richTextHtmlRequiredValidator }],
|
|
137
|
+
};
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Omit `richTextValueFormat` for the default `DocumentNode | null` control. HTML mode uses `string | null`. An external HTML value is imported into the editor without rewriting the control. Edits write sanitized HTML with the original template destinations in `href`. The empty paragraph exports as `''` after an edit, and `reset(null)` retains `null`. Template destinations remain inert in the editing DOM. The host resolves them when generating the final document.
|
|
141
|
+
|
|
142
|
+
For Angular Forms outside Dynamic Forms, use `formValueFormat="html"` on `kles-richtext-editor` with a `FormControl<string | null>`. The `document` input, `documentChange` output and native editor APIs still use the AST. Configure the value format when creating the control. [Dynamic Forms demo](../../src/app/dynamicforms-demo/README.md)
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { ChangeDetectionStrategy, Component, computed, inject } from "@angular/core";
|
|
4
|
+
import { toSignal } from "@angular/core/rxjs-interop";
|
|
5
|
+
import * as i1 from "@angular/forms";
|
|
6
|
+
import { FormControl, ReactiveFormsModule } from "@angular/forms";
|
|
7
|
+
import { FIELD, FIELD_CONTEXT, FieldMapper, GROUP } from "@3kles/kles-material-dynamicforms";
|
|
8
|
+
import { RICHTEXT_I18N, RichTextEditorComponent, RichTextToolbarComponent, validateRichTextValue } from "@3kles/kles-richtext-editor";
|
|
9
|
+
function createRichTextControl(field) {
|
|
10
|
+
const source = field.value;
|
|
11
|
+
const value = initialValue(source ?? null, field.richTextValueFormat ?? "document");
|
|
12
|
+
return new FormControl({
|
|
13
|
+
value,
|
|
14
|
+
disabled: field.disabled === true
|
|
15
|
+
}, {
|
|
16
|
+
validators: (field.validations ?? []).map((validation) => validation.validator),
|
|
17
|
+
asyncValidators: (field.asyncValidations ?? []).map((validation) => validation.validator),
|
|
18
|
+
updateOn: field.updateOn ?? "change"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function initialValue(source, format) {
|
|
22
|
+
if (source === null) return null;
|
|
23
|
+
if (format === "html") {
|
|
24
|
+
if (typeof source === "string") return source;
|
|
25
|
+
throw new TypeError("An HTML rich-text field requires a string or null.");
|
|
26
|
+
}
|
|
27
|
+
const result = validateRichTextValue(source);
|
|
28
|
+
if (!result.ok) throw new TypeError("A document rich-text field requires a valid native document or null.");
|
|
29
|
+
return result.value;
|
|
30
|
+
}
|
|
31
|
+
let RichTextDynamicFieldComponent = class RichTextDynamicFieldComponent {
|
|
32
|
+
field = inject(FIELD);
|
|
33
|
+
group = inject(GROUP);
|
|
34
|
+
toolbarLanguage = inject(RICHTEXT_I18N).locale;
|
|
35
|
+
valueFormat = this.field.richTextValueFormat ?? "document";
|
|
36
|
+
context = inject(FIELD_CONTEXT, { optional: true });
|
|
37
|
+
control = this.fieldControl();
|
|
38
|
+
controlEvents = toSignal(this.control.events);
|
|
39
|
+
required = (this.field.validations ?? []).some((validation) => "name" in validation && validation.name === "required");
|
|
40
|
+
invalid = computed(() => {
|
|
41
|
+
this.controlEvents();
|
|
42
|
+
return this.control.invalid && this.control.touched;
|
|
43
|
+
}, ...ngDevMode ? [{ debugName: "invalid" }] : /* istanbul ignore next */ []);
|
|
44
|
+
readOnly = computed(() => {
|
|
45
|
+
const context = this.context?.();
|
|
46
|
+
return typeof context === "object" && context !== null && "readOnly" in context && context.readOnly === true;
|
|
47
|
+
}, ...ngDevMode ? [{ debugName: "readOnly" }] : /* istanbul ignore next */ []);
|
|
48
|
+
fieldControl() {
|
|
49
|
+
const control = this.group.get([this.field.name]);
|
|
50
|
+
if (!control) throw new Error("Dynamic Forms did not create the registered rich-text control.");
|
|
51
|
+
return control;
|
|
52
|
+
}
|
|
53
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
54
|
+
minVersion: "12.0.0",
|
|
55
|
+
version: "22.2.6",
|
|
56
|
+
ngImport: i0,
|
|
57
|
+
type: RichTextDynamicFieldComponent,
|
|
58
|
+
deps: [],
|
|
59
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
60
|
+
});
|
|
61
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
62
|
+
minVersion: "17.0.0",
|
|
63
|
+
version: "22.2.6",
|
|
64
|
+
type: RichTextDynamicFieldComponent,
|
|
65
|
+
isStandalone: true,
|
|
66
|
+
selector: "app-kles-richtext-dynamic-field",
|
|
67
|
+
ngImport: i0,
|
|
68
|
+
template: "<section class=\"dynamic-richtext-field\" [formGroup]=\"group\" [attr.aria-label]=\"field.label ?? 'Document 3KLES'\">\n <h3>\n {{ field.label ?? 'Document 3KLES' }}\n @if (required) {\n <span aria-hidden=\"true\">*</span>\n }\n </h3>\n <kles-richtext-toolbar [editor]=\"editor\" [attr.lang]=\"toolbarLanguage\" />\n <kles-richtext-editor\n #editor\n [formControlName]=\"field.name\"\n [formValueFormat]=\"valueFormat\"\n [required]=\"required\"\n [readOnly]=\"readOnly()\"\n [invalid]=\"invalid()\"\n [label]=\"field.label ?? 'Document 3KLES'\"\n />\n @if (field.hint) {\n <p class=\"field-hint\">{{ field.hint }}</p>\n }\n</section>\n",
|
|
69
|
+
styles: [":host{display:block;min-width:0}.dynamic-richtext-field{min-width:0;margin-block:1.25rem}h3{font-size:1.1rem;margin:0 0 .75rem}.field-hint{color:var(--muted, inherit);font-size:.9rem;line-height:1.5}\n"],
|
|
70
|
+
dependencies: [
|
|
71
|
+
{
|
|
72
|
+
kind: "ngmodule",
|
|
73
|
+
type: ReactiveFormsModule
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
kind: "directive",
|
|
77
|
+
type: i1.NgControlStatus,
|
|
78
|
+
selector: "[formControlName],[ngModel],[formControl]"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
kind: "directive",
|
|
82
|
+
type: i1.NgControlStatusGroup,
|
|
83
|
+
selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
kind: "directive",
|
|
87
|
+
type: i1.RequiredValidator,
|
|
88
|
+
selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]",
|
|
89
|
+
inputs: ["required"]
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
kind: "directive",
|
|
93
|
+
type: i1.FormGroupDirective,
|
|
94
|
+
selector: "[formGroup]",
|
|
95
|
+
inputs: ["formGroup"],
|
|
96
|
+
outputs: ["ngSubmit"],
|
|
97
|
+
exportAs: ["ngForm"]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
kind: "directive",
|
|
101
|
+
type: i1.FormControlName,
|
|
102
|
+
selector: "[formControlName]",
|
|
103
|
+
inputs: [
|
|
104
|
+
"formControlName",
|
|
105
|
+
"disabled",
|
|
106
|
+
"ngModel"
|
|
107
|
+
],
|
|
108
|
+
outputs: ["ngModelChange"]
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
kind: "component",
|
|
112
|
+
type: RichTextEditorComponent,
|
|
113
|
+
selector: "kles-richtext-editor",
|
|
114
|
+
inputs: [
|
|
115
|
+
"document",
|
|
116
|
+
"formValueFormat",
|
|
117
|
+
"readOnly",
|
|
118
|
+
"disabled",
|
|
119
|
+
"required",
|
|
120
|
+
"invalid",
|
|
121
|
+
"label",
|
|
122
|
+
"locale",
|
|
123
|
+
"messages",
|
|
124
|
+
"describedBy"
|
|
125
|
+
],
|
|
126
|
+
outputs: [
|
|
127
|
+
"documentChange",
|
|
128
|
+
"stateChange",
|
|
129
|
+
"editorEvent",
|
|
130
|
+
"validationChange"
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
kind: "component",
|
|
135
|
+
type: RichTextToolbarComponent,
|
|
136
|
+
selector: "kles-richtext-toolbar",
|
|
137
|
+
inputs: [
|
|
138
|
+
"editor",
|
|
139
|
+
"label",
|
|
140
|
+
"locale",
|
|
141
|
+
"messages",
|
|
142
|
+
"config",
|
|
143
|
+
"items",
|
|
144
|
+
"buttonTemplate",
|
|
145
|
+
"refreshKey"
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
RichTextDynamicFieldComponent = __decorate([FieldMapper({
|
|
153
|
+
type: "3kles-richtext",
|
|
154
|
+
factory: createRichTextControl
|
|
155
|
+
})], RichTextDynamicFieldComponent);
|
|
156
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
157
|
+
minVersion: "12.0.0",
|
|
158
|
+
version: "22.2.6",
|
|
159
|
+
ngImport: i0,
|
|
160
|
+
type: RichTextDynamicFieldComponent,
|
|
161
|
+
decorators: [{
|
|
162
|
+
type: Component,
|
|
163
|
+
args: [{
|
|
164
|
+
selector: "app-kles-richtext-dynamic-field",
|
|
165
|
+
standalone: true,
|
|
166
|
+
imports: [
|
|
167
|
+
ReactiveFormsModule,
|
|
168
|
+
RichTextEditorComponent,
|
|
169
|
+
RichTextToolbarComponent
|
|
170
|
+
],
|
|
171
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
172
|
+
template: "<section class=\"dynamic-richtext-field\" [formGroup]=\"group\" [attr.aria-label]=\"field.label ?? 'Document 3KLES'\">\n <h3>\n {{ field.label ?? 'Document 3KLES' }}\n @if (required) {\n <span aria-hidden=\"true\">*</span>\n }\n </h3>\n <kles-richtext-toolbar [editor]=\"editor\" [attr.lang]=\"toolbarLanguage\" />\n <kles-richtext-editor\n #editor\n [formControlName]=\"field.name\"\n [formValueFormat]=\"valueFormat\"\n [required]=\"required\"\n [readOnly]=\"readOnly()\"\n [invalid]=\"invalid()\"\n [label]=\"field.label ?? 'Document 3KLES'\"\n />\n @if (field.hint) {\n <p class=\"field-hint\">{{ field.hint }}</p>\n }\n</section>\n",
|
|
173
|
+
styles: [":host{display:block;min-width:0}.dynamic-richtext-field{min-width:0;margin-block:1.25rem}h3{font-size:1.1rem;margin:0 0 .75rem}.field-hint{color:var(--muted, inherit);font-size:.9rem;line-height:1.5}\n"]
|
|
174
|
+
}]
|
|
175
|
+
}]
|
|
176
|
+
});
|
|
177
|
+
export { RichTextDynamicFieldComponent };
|
|
178
|
+
|
|
179
|
+
//# sourceMappingURL=3kles-kles-richtext-editor-dynamicforms.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"3kles-kles-richtext-editor-dynamicforms.mjs","names":[],"sources":["../../../projects/kles-richtext-editor/dynamicforms/src/richtext-dynamic-field.component.ts","../../../projects/kles-richtext-editor/dynamicforms/src/richtext-dynamic-field.component.html"],"sourcesContent":["import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { FormControl, ReactiveFormsModule } from '@angular/forms';\nimport type { AbstractControl } from '@angular/forms';\nimport { FIELD, FIELD_CONTEXT, FieldMapper, GROUP } from '@3kles/kles-material-dynamicforms';\nimport type { IKlesFieldConfig } from '@3kles/kles-material-dynamicforms';\nimport {\n RICHTEXT_I18N,\n RichTextEditorComponent,\n RichTextToolbarComponent,\n validateRichTextValue,\n} from '@3kles/kles-richtext-editor';\nimport type { RichTextFormValueFormat } from '@3kles/kles-richtext-editor';\nimport type { DocumentNode } from '@3kles/richtext-core';\n\nexport interface RichTextDynamicFieldConfig extends IKlesFieldConfig {\n readonly richTextValueFormat?: RichTextFormValueFormat;\n}\n\n/** Dynamic Forms invokes this factory for the registered component itself. */\nfunction createRichTextControl(field: RichTextDynamicFieldConfig): FormControl<DocumentNode | string | null> {\n const source: unknown = field.value;\n const value = initialValue(source ?? null, field.richTextValueFormat ?? 'document');\n return new FormControl<DocumentNode | string | null>(\n { value, disabled: field.disabled === true },\n {\n validators: (field.validations ?? []).map((validation) => validation.validator),\n asyncValidators: (field.asyncValidations ?? []).map((validation) => validation.validator),\n updateOn: field.updateOn ?? 'change',\n },\n );\n}\n\nfunction initialValue(source: unknown, format: RichTextFormValueFormat): DocumentNode | string | null {\n if (source === null) return null;\n if (format === 'html') {\n if (typeof source === 'string') return source;\n throw new TypeError('An HTML rich-text field requires a string or null.');\n }\n const result = validateRichTextValue(source);\n if (!result.ok) throw new TypeError('A document rich-text field requires a valid native document or null.');\n return result.value;\n}\n\n@FieldMapper({ type: '3kles-richtext', factory: createRichTextControl })\n@Component({\n selector: 'app-kles-richtext-dynamic-field',\n standalone: true,\n imports: [ReactiveFormsModule, RichTextEditorComponent, RichTextToolbarComponent],\n templateUrl: './richtext-dynamic-field.component.html',\n styleUrl: './richtext-dynamic-field.component.scss',\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class RichTextDynamicFieldComponent {\n readonly field: RichTextDynamicFieldConfig = inject(FIELD);\n readonly group = inject(GROUP);\n readonly toolbarLanguage = inject(RICHTEXT_I18N).locale;\n readonly valueFormat = this.field.richTextValueFormat ?? 'document';\n private readonly context = inject(FIELD_CONTEXT, { optional: true });\n readonly control = this.fieldControl();\n private readonly controlEvents = toSignal(this.control.events);\n readonly required = (this.field.validations ?? []).some(\n (validation) => 'name' in validation && validation.name === 'required',\n );\n readonly invalid = computed(() => {\n this.controlEvents();\n return this.control.invalid && this.control.touched;\n });\n readonly readOnly = computed(() => {\n const context: unknown = this.context?.();\n return typeof context === 'object' && context !== null && 'readOnly' in context && context.readOnly === true;\n });\n\n private fieldControl(): AbstractControl<unknown> {\n const control: AbstractControl<unknown> | null = this.group.get([this.field.name]);\n if (!control) throw new Error('Dynamic Forms did not create the registered rich-text control.');\n return control;\n }\n}\n","<section class=\"dynamic-richtext-field\" [formGroup]=\"group\" [attr.aria-label]=\"field.label ?? 'Document 3KLES'\">\n <h3>\n {{ field.label ?? 'Document 3KLES' }}\n @if (required) {\n <span aria-hidden=\"true\">*</span>\n }\n </h3>\n <kles-richtext-toolbar [editor]=\"editor\" [attr.lang]=\"toolbarLanguage\" />\n <kles-richtext-editor\n #editor\n [formControlName]=\"field.name\"\n [formValueFormat]=\"valueFormat\"\n [required]=\"required\"\n [readOnly]=\"readOnly()\"\n [invalid]=\"invalid()\"\n [label]=\"field.label ?? 'Document 3KLES'\"\n />\n @if (field.hint) {\n <p class=\"field-hint\">{{ field.hint }}</p>\n }\n</section>\n"],"mappings":"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"}
|
|
@@ -2,8 +2,9 @@ import { JsonPipe, NgTemplateOutlet, isPlatformBrowser } from "@angular/common";
|
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
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
4
|
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
5
|
-
import { compareTextPoints, createEmptyDocument, getNodeAtPath, getTextBlockText,
|
|
5
|
+
import { compareTextPoints, createEmptyDocument, getNodeAtPath, getTextBlockText, isSupportedLinkDestination, resolveTextBlock, validateDocument } from "@3kles/richtext-core";
|
|
6
6
|
import { createEditor } from "@3kles/richtext-dom";
|
|
7
|
+
import { importHtml } from "@3kles/richtext-formats";
|
|
7
8
|
const RICHTEXT_I18N = new InjectionToken("RICHTEXT_I18N", {
|
|
8
9
|
providedIn: "root",
|
|
9
10
|
factory: () => Object.freeze({ locale: "fr" })
|
|
@@ -30,7 +31,7 @@ const RICHTEXT_MESSAGES_FR = Object.freeze({
|
|
|
30
31
|
linkAddress: "Adresse du lien",
|
|
31
32
|
applyLink: "Appliquer le lien",
|
|
32
33
|
removeLink: "Retirer le lien",
|
|
33
|
-
invalidLink: "Saisissez une adresse HTTP, HTTPS ou
|
|
34
|
+
invalidLink: "Saisissez une adresse HTTP, HTTPS, mailto ou une destination dynamique valide.",
|
|
34
35
|
actionUnavailable: "Cette action ne peut pas être appliquée à la sélection.",
|
|
35
36
|
undoDone: "Annulation effectuée.",
|
|
36
37
|
redoDone: "Rétablissement effectué.",
|
|
@@ -69,7 +70,7 @@ const RICHTEXT_MESSAGES_EN = Object.freeze({
|
|
|
69
70
|
linkAddress: "Link address",
|
|
70
71
|
applyLink: "Apply link",
|
|
71
72
|
removeLink: "Remove link",
|
|
72
|
-
invalidLink: "Enter a valid HTTP, HTTPS or
|
|
73
|
+
invalidLink: "Enter a valid HTTP, HTTPS, mailto, or dynamic link destination.",
|
|
73
74
|
actionUnavailable: "This action cannot be applied to the selection.",
|
|
74
75
|
undoDone: "Undo completed.",
|
|
75
76
|
redoDone: "Redo completed.",
|
|
@@ -271,6 +272,27 @@ function validateRichTextValue(value) {
|
|
|
271
272
|
diagnostics: Object.freeze([])
|
|
272
273
|
} : validateDocument(value);
|
|
273
274
|
}
|
|
275
|
+
function validateRichTextHtmlValue(value) {
|
|
276
|
+
if (value === null) return validateRichTextValue(null);
|
|
277
|
+
const result = importHtml(value);
|
|
278
|
+
if (result.ok) return {
|
|
279
|
+
ok: true,
|
|
280
|
+
value: result.value,
|
|
281
|
+
diagnostics: []
|
|
282
|
+
};
|
|
283
|
+
return {
|
|
284
|
+
ok: false,
|
|
285
|
+
diagnostics: richTextHtmlDiagnostics(result.diagnostics)
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function richTextHtmlDiagnostics(diagnostics) {
|
|
289
|
+
return diagnostics.map(({ code, path, message }) => ({
|
|
290
|
+
code: code === "resourceLimit" || code === "invalidUnicode" ? code : "invalidType",
|
|
291
|
+
severity: "error",
|
|
292
|
+
path,
|
|
293
|
+
message
|
|
294
|
+
}));
|
|
295
|
+
}
|
|
274
296
|
function richTextSchemaError(diagnostics) {
|
|
275
297
|
return Object.freeze({ richtextDocument: Object.freeze({ diagnostics }) });
|
|
276
298
|
}
|
|
@@ -291,9 +313,15 @@ function richTextRequiredValidator(control) {
|
|
|
291
313
|
if (!result.ok) return richTextSchemaError(result.diagnostics);
|
|
292
314
|
return hasRichTextContent(result.value) ? null : RICHTEXT_REQUIRED_ERROR;
|
|
293
315
|
}
|
|
316
|
+
function richTextHtmlRequiredValidator(control) {
|
|
317
|
+
const result = validateRichTextHtmlValue(control.value);
|
|
318
|
+
if (!result.ok) return richTextSchemaError(result.diagnostics);
|
|
319
|
+
return hasRichTextContent(result.value) ? null : RICHTEXT_REQUIRED_ERROR;
|
|
320
|
+
}
|
|
294
321
|
var RichTextEditorComponent = class RichTextEditorComponent {
|
|
295
322
|
surface;
|
|
296
323
|
document = input(createEmptyDocument(), ...ngDevMode ? [{ debugName: "document" }] : /* istanbul ignore next */ []);
|
|
324
|
+
formValueFormat = input("document", ...ngDevMode ? [{ debugName: "formValueFormat" }] : /* istanbul ignore next */ []);
|
|
297
325
|
readOnly = input(false, {
|
|
298
326
|
...ngDevMode ? { debugName: "readOnly" } : /* istanbul ignore next */ {},
|
|
299
327
|
transform: booleanAttribute
|
|
@@ -367,6 +395,7 @@ var RichTextEditorComponent = class RichTextEditorComponent {
|
|
|
367
395
|
interacted = false;
|
|
368
396
|
focusRegions = /* @__PURE__ */ new Map();
|
|
369
397
|
onChange = () => void 0;
|
|
398
|
+
htmlFormValue;
|
|
370
399
|
onTouched = () => void 0;
|
|
371
400
|
onValidatorChange = () => void 0;
|
|
372
401
|
constructor() {
|
|
@@ -434,6 +463,11 @@ var RichTextEditorComponent = class RichTextEditorComponent {
|
|
|
434
463
|
this.applyAccess(this.effectiveDisabled(), this.readOnly());
|
|
435
464
|
}
|
|
436
465
|
validate(control) {
|
|
466
|
+
if (this.formValueFormat() === "html") {
|
|
467
|
+
const result = this.decodeHtmlFormValue(control.value);
|
|
468
|
+
if (!result.ok) return richTextSchemaError(result.diagnostics);
|
|
469
|
+
return this.required() && !hasRichTextContent(result.value) ? RICHTEXT_REQUIRED_ERROR : null;
|
|
470
|
+
}
|
|
437
471
|
return this.required() ? richTextRequiredValidator(control) : richTextDocumentValidator(control);
|
|
438
472
|
}
|
|
439
473
|
registerOnValidatorChange(callback) {
|
|
@@ -554,6 +588,7 @@ var RichTextEditorComponent = class RichTextEditorComponent {
|
|
|
554
588
|
this.pendingRejectedWrite = void 0;
|
|
555
589
|
this.pendingBlur = false;
|
|
556
590
|
this.interacted = false;
|
|
591
|
+
this.htmlFormValue = void 0;
|
|
557
592
|
this.stateValue.set(void 0);
|
|
558
593
|
this.composingValue.set(false);
|
|
559
594
|
this.focusedValue.set(false);
|
|
@@ -593,7 +628,7 @@ var RichTextEditorComponent = class RichTextEditorComponent {
|
|
|
593
628
|
if (event.commit.origin !== "load") {
|
|
594
629
|
this.validationPresented.set(true);
|
|
595
630
|
this.interacted = true;
|
|
596
|
-
if (this.formsBound) this.
|
|
631
|
+
if (this.formsBound) this.publishFormValue(event.state.document);
|
|
597
632
|
}
|
|
598
633
|
if (!this.pendingDocument && this.pendingRejectedWrite === void 0) this.documentChange.emit(event.state.document);
|
|
599
634
|
}
|
|
@@ -609,6 +644,37 @@ var RichTextEditorComponent = class RichTextEditorComponent {
|
|
|
609
644
|
this.nativeNotificationDepth--;
|
|
610
645
|
}
|
|
611
646
|
}
|
|
647
|
+
decodeHtmlFormValue(source) {
|
|
648
|
+
if (this.htmlFormValue && this.htmlFormValue.source === source) return this.htmlFormValue.result;
|
|
649
|
+
const result = validateRichTextHtmlValue(source);
|
|
650
|
+
this.htmlFormValue = {
|
|
651
|
+
source,
|
|
652
|
+
result
|
|
653
|
+
};
|
|
654
|
+
return result;
|
|
655
|
+
}
|
|
656
|
+
publishFormValue(document) {
|
|
657
|
+
if (this.formValueFormat() !== "html") {
|
|
658
|
+
this.onChange(document);
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const result = this.getHtml();
|
|
662
|
+
if (!result) return;
|
|
663
|
+
if (!result.ok) {
|
|
664
|
+
this.schemaError.set(richTextSchemaError(richTextHtmlDiagnostics(result.diagnostics)));
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const html = result.value === "<p></p>" ? "" : result.value;
|
|
668
|
+
this.htmlFormValue = {
|
|
669
|
+
source: html,
|
|
670
|
+
result: {
|
|
671
|
+
ok: true,
|
|
672
|
+
value: document,
|
|
673
|
+
diagnostics: []
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
this.onChange(html);
|
|
677
|
+
}
|
|
612
678
|
receiveDocument(value, fromForms) {
|
|
613
679
|
if (this.destroyed || !fromForms && this.formsBound) return;
|
|
614
680
|
if (!fromForms && value === this.lastLoadedSource) {
|
|
@@ -617,7 +683,7 @@ var RichTextEditorComponent = class RichTextEditorComponent {
|
|
|
617
683
|
this.schemaError.set(null);
|
|
618
684
|
return;
|
|
619
685
|
}
|
|
620
|
-
const validated = validateRichTextValue(value);
|
|
686
|
+
const validated = fromForms && this.formValueFormat() === "html" ? this.decodeHtmlFormValue(value) : validateRichTextValue(value);
|
|
621
687
|
if (!validated.ok) {
|
|
622
688
|
this.pendingDocument = void 0;
|
|
623
689
|
this.pendingRejectedWrite = ++this.rejectedWriteSequence;
|
|
@@ -779,6 +845,13 @@ var RichTextEditorComponent = class RichTextEditorComponent {
|
|
|
779
845
|
isRequired: false,
|
|
780
846
|
transformFunction: null
|
|
781
847
|
},
|
|
848
|
+
formValueFormat: {
|
|
849
|
+
classPropertyName: "formValueFormat",
|
|
850
|
+
publicName: "formValueFormat",
|
|
851
|
+
isSignal: true,
|
|
852
|
+
isRequired: false,
|
|
853
|
+
transformFunction: null
|
|
854
|
+
},
|
|
782
855
|
readOnly: {
|
|
783
856
|
classPropertyName: "readOnly",
|
|
784
857
|
publicName: "readOnly",
|
|
@@ -902,6 +975,14 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
902
975
|
required: false
|
|
903
976
|
}]
|
|
904
977
|
}],
|
|
978
|
+
formValueFormat: [{
|
|
979
|
+
type: i0.Input,
|
|
980
|
+
args: [{
|
|
981
|
+
isSignal: true,
|
|
982
|
+
alias: "formValueFormat",
|
|
983
|
+
required: false
|
|
984
|
+
}]
|
|
985
|
+
}],
|
|
905
986
|
readOnly: [{
|
|
906
987
|
type: i0.Input,
|
|
907
988
|
args: [{
|
|
@@ -1337,12 +1418,12 @@ var RichTextToolbarComponent = class RichTextToolbarComponent {
|
|
|
1337
1418
|
href: "https://example.invalid"
|
|
1338
1419
|
});
|
|
1339
1420
|
}, ...ngDevMode ? [{ debugName: "linksDisabled" }] : /* istanbul ignore next */ []);
|
|
1340
|
-
linkInvalid = computed(() => this.linkFieldQuery() !== void 0 && this.linkDirty() && !
|
|
1421
|
+
linkInvalid = computed(() => this.linkFieldQuery() !== void 0 && this.linkDirty() && !isSupportedLinkDestination(this.linkHref()), ...ngDevMode ? [{ debugName: "linkInvalid" }] : /* istanbul ignore next */ []);
|
|
1341
1422
|
applyLinkDisabled = computed(() => {
|
|
1342
1423
|
this.refreshKey();
|
|
1343
1424
|
this.refreshVersion();
|
|
1344
1425
|
const field = this.linkFieldQuery();
|
|
1345
|
-
return !field || field.disabled || this.blocked() || !
|
|
1426
|
+
return !field || field.disabled || this.blocked() || !isSupportedLinkDestination(this.linkHref()) || !this.editor().can({
|
|
1346
1427
|
type: "setLink",
|
|
1347
1428
|
href: this.linkHref()
|
|
1348
1429
|
});
|
|
@@ -1558,7 +1639,7 @@ var RichTextToolbarComponent = class RichTextToolbarComponent {
|
|
|
1558
1639
|
isSignal: true
|
|
1559
1640
|
}],
|
|
1560
1641
|
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",
|
|
1642
|
+
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=\"text\"\n inputmode=\"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
1643
|
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
1644
|
dependencies: [{
|
|
1564
1645
|
kind: "directive",
|
|
@@ -1585,7 +1666,7 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1585
1666
|
standalone: true,
|
|
1586
1667
|
imports: [NgTemplateOutlet],
|
|
1587
1668
|
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",
|
|
1669
|
+
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=\"text\"\n inputmode=\"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
1670
|
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
1671
|
}]
|
|
1591
1672
|
}],
|
|
@@ -1661,6 +1742,6 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1661
1742
|
}]
|
|
1662
1743
|
}
|
|
1663
1744
|
});
|
|
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 };
|
|
1745
|
+
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, richTextHtmlRequiredValidator, richTextRequiredValidator, validateRichTextValue };
|
|
1665
1746
|
|
|
1666
1747
|
//# sourceMappingURL=3kles-kles-richtext-editor.mjs.map
|