@web-atoms/web-controls 2.1.14 → 2.1.20
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/dist/basic/FormField.d.ts +1 -1
- package/dist/basic/FormField.d.ts.map +1 -1
- package/dist/basic/FormField.js +9 -2
- package/dist/basic/FormField.js.map +1 -1
- package/dist/form/AtomField.d.ts +4 -17
- package/dist/form/AtomField.d.ts.map +1 -1
- package/dist/form/AtomField.js +22 -63
- package/dist/form/AtomField.js.map +1 -1
- package/dist/html-editor/HtmlEditor.d.ts +6 -5
- package/dist/html-editor/HtmlEditor.d.ts.map +1 -1
- package/dist/html-editor/HtmlEditor.js +38 -38
- package/dist/html-editor/HtmlEditor.js.map +1 -1
- package/dist/html-editor/commands/AddImage.d.ts +4 -5
- package/dist/html-editor/commands/AddImage.d.ts.map +1 -1
- package/dist/html-editor/commands/AddImage.js +6 -2
- package/dist/html-editor/commands/AddImage.js.map +1 -1
- package/dist/html-editor/commands/AddLink.d.ts +1 -1
- package/dist/html-editor/commands/AddLink.d.ts.map +1 -1
- package/dist/html-editor/commands/AddLink.js +4 -2
- package/dist/html-editor/commands/AddLink.js.map +1 -1
- package/dist/html-editor/commands/Align.js.map +1 -1
- package/dist/html-editor/commands/ChangeColor.js.map +1 -1
- package/dist/html-editor/commands/ChangeFont.js.map +1 -1
- package/dist/html-editor/commands/ChangeFontSize.js.map +1 -1
- package/dist/html-editor/commands/Command.d.ts +3 -3
- package/dist/html-editor/commands/Command.d.ts.map +1 -1
- package/dist/html-editor/commands/Command.js.map +1 -1
- package/dist/html-editor/commands/CommandButton.d.ts +7 -2
- package/dist/html-editor/commands/CommandButton.d.ts.map +1 -1
- package/dist/html-editor/commands/CommandButton.js +12 -4
- package/dist/html-editor/commands/CommandButton.js.map +1 -1
- package/dist/html-editor/commands/Headings.js.map +1 -1
- package/dist/html-editor/commands/HtmlCommands.d.ts +59 -0
- package/dist/html-editor/commands/HtmlCommands.d.ts.map +1 -0
- package/dist/html-editor/commands/HtmlCommands.js +81 -0
- package/dist/html-editor/commands/HtmlCommands.js.map +1 -0
- package/dist/html-editor/commands/Source.d.ts +4 -1
- package/dist/html-editor/commands/Source.d.ts.map +1 -1
- package/dist/html-editor/commands/Source.js +4 -3
- package/dist/html-editor/commands/Source.js.map +1 -1
- package/dist/html-editor/commands/Unlink.d.ts +3 -1
- package/dist/html-editor/commands/Unlink.d.ts.map +1 -1
- package/dist/html-editor/commands/Unlink.js +10 -6
- package/dist/html-editor/commands/Unlink.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/basic/FormField.tsx +11 -1
- package/src/form/AtomField.tsx +18 -68
- package/src/html-editor/HtmlEditor.tsx +36 -26
- package/src/html-editor/commands/AddImage.tsx +7 -5
- package/src/html-editor/commands/AddLink.tsx +5 -3
- package/src/html-editor/commands/Align.tsx +5 -5
- package/src/html-editor/commands/ChangeColor.tsx +3 -3
- package/src/html-editor/commands/ChangeFont.tsx +4 -4
- package/src/html-editor/commands/ChangeFontSize.tsx +3 -3
- package/src/html-editor/commands/Command.tsx +7 -7
- package/src/html-editor/commands/CommandButton.tsx +24 -6
- package/src/html-editor/commands/Headings.tsx +2 -2
- package/src/html-editor/commands/HtmlCommands.ts +78 -0
- package/src/html-editor/commands/Source.tsx +5 -4
- package/src/html-editor/commands/Unlink.tsx +9 -9
package/src/basic/FormField.tsx
CHANGED
|
@@ -10,6 +10,14 @@ export interface IFormField {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const css = CSS(StyleRule()
|
|
13
|
+
.child(StyleRule(".error")
|
|
14
|
+
.padding(5)
|
|
15
|
+
.backgroundColor(Colors.red)
|
|
16
|
+
.color(Colors.white)
|
|
17
|
+
.and(StyleRule(":empty")
|
|
18
|
+
.display("none")
|
|
19
|
+
)
|
|
20
|
+
)
|
|
13
21
|
.child(StyleRule(".label")
|
|
14
22
|
.child(StyleRule(".true")
|
|
15
23
|
.visibility("visible")
|
|
@@ -24,7 +32,8 @@ const css = CSS(StyleRule()
|
|
|
24
32
|
export default function FormField(
|
|
25
33
|
{
|
|
26
34
|
label,
|
|
27
|
-
required
|
|
35
|
+
required,
|
|
36
|
+
error
|
|
28
37
|
}: IFormField,
|
|
29
38
|
node: XNode) {
|
|
30
39
|
return <div class={css}>
|
|
@@ -33,5 +42,6 @@ export default function FormField(
|
|
|
33
42
|
<span class="required" styleClass={required} text="*" />
|
|
34
43
|
</div>
|
|
35
44
|
{ node }
|
|
45
|
+
<div class="error" text={error}/>
|
|
36
46
|
</div>;
|
|
37
47
|
}
|
package/src/form/AtomField.tsx
CHANGED
|
@@ -10,7 +10,7 @@ export { default as HP } from "./HelpPopup";
|
|
|
10
10
|
|
|
11
11
|
let inputID = 0;
|
|
12
12
|
|
|
13
|
-
class
|
|
13
|
+
export default class AtomField extends AtomControl {
|
|
14
14
|
|
|
15
15
|
@BindableProperty
|
|
16
16
|
public icon: string;
|
|
@@ -39,9 +39,6 @@ class AtomFieldControl extends AtomControl {
|
|
|
39
39
|
@BindableProperty
|
|
40
40
|
public fieldClass: string;
|
|
41
41
|
|
|
42
|
-
@BindableProperty
|
|
43
|
-
public content: any;
|
|
44
|
-
|
|
45
42
|
public get hasError(): boolean {
|
|
46
43
|
return this.error ? true : false;
|
|
47
44
|
}
|
|
@@ -56,44 +53,14 @@ class AtomFieldControl extends AtomControl {
|
|
|
56
53
|
@BindableProperty
|
|
57
54
|
protected htmlFor: any;
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
private fieldCreated;
|
|
57
|
+
|
|
58
|
+
public onPropertyChanged(name: keyof AtomField): void {
|
|
60
59
|
switch (name) {
|
|
61
|
-
case "error":
|
|
62
|
-
AtomBinder.refreshValue(this, "hasError");
|
|
63
|
-
break;
|
|
64
60
|
case "helpLink":
|
|
65
61
|
case "helpText":
|
|
66
62
|
AtomBinder.refreshValue(this, "hasHelp");
|
|
67
63
|
break;
|
|
68
|
-
case "content":
|
|
69
|
-
if (!this.contentPresenter) {
|
|
70
|
-
setTimeout(() => this.onPropertyChanged(name), 100);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
this.removeAllChildren(this.contentPresenter);
|
|
74
|
-
const content = this.content;
|
|
75
|
-
if (!content) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
for (const iterator of content) {
|
|
79
|
-
const e = iterator?.element ?? iterator as HTMLElement;
|
|
80
|
-
if (!e) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
if (typeof e === "string") {
|
|
84
|
-
this.contentPresenter.appendChild(document.createTextNode(e));
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this.contentPresenter.appendChild(e);
|
|
88
|
-
const input = e.tagName === "INPUT" ? e : e.getElementsByTagName("input")[0];
|
|
89
|
-
if (input) {
|
|
90
|
-
if (!input.id) {
|
|
91
|
-
input.id = `__ID__formElementInput${inputID++}`;
|
|
92
|
-
}
|
|
93
|
-
this.htmlFor = input.id;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
64
|
}
|
|
98
65
|
}
|
|
99
66
|
|
|
@@ -123,8 +90,16 @@ class AtomFieldControl extends AtomControl {
|
|
|
123
90
|
this.required = false;
|
|
124
91
|
this.visible = true;
|
|
125
92
|
this.fieldClass = "";
|
|
126
|
-
this.
|
|
127
|
-
|
|
93
|
+
this.fieldCreated = false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
protected render(node: XNode, e?: any, creator?: any): void {
|
|
97
|
+
if (this.fieldCreated) {
|
|
98
|
+
return super.render(node, e, creator);
|
|
99
|
+
}
|
|
100
|
+
this.fieldCreated = true;
|
|
101
|
+
super.render(<div
|
|
102
|
+
{ ... node.attributes}
|
|
128
103
|
class={Bind.oneWay(() => ({
|
|
129
104
|
"form-field": 1,
|
|
130
105
|
[this.fieldClass]: this.fieldClass,
|
|
@@ -138,40 +113,15 @@ class AtomFieldControl extends AtomControl {
|
|
|
138
113
|
<span
|
|
139
114
|
class="required"
|
|
140
115
|
styleVisibility={Bind.oneTime(() => this.required ? "visible" : "hidden")}>*</span>
|
|
141
|
-
<div
|
|
142
|
-
class="presenter"
|
|
116
|
+
<div
|
|
117
|
+
class="presenter">
|
|
118
|
+
{... node.children as any[]}
|
|
119
|
+
</div>
|
|
143
120
|
<span
|
|
144
121
|
class="error"
|
|
145
122
|
styleDisplay={Bind.oneWay(() => this.error ? "" : "none")}
|
|
146
123
|
text={Bind.oneWay(() => this.error)}></span>
|
|
147
124
|
</div>);
|
|
148
|
-
|
|
149
|
-
if (this.content) {
|
|
150
|
-
this.onPropertyChanged("content");
|
|
151
|
-
}
|
|
152
125
|
}
|
|
153
126
|
|
|
154
127
|
}
|
|
155
|
-
|
|
156
|
-
export interface IFieldAttributes {
|
|
157
|
-
label?;
|
|
158
|
-
error?;
|
|
159
|
-
helpText?;
|
|
160
|
-
helpLink?;
|
|
161
|
-
helpIcon?;
|
|
162
|
-
required?;
|
|
163
|
-
visible?;
|
|
164
|
-
fieldClass?;
|
|
165
|
-
baseClass?: IClassOf<AtomFieldControl>;
|
|
166
|
-
[key: string]: any;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export default function AtomField( attributes: IFieldAttributes, ... children: XNode[]) {
|
|
170
|
-
const ControlClass = attributes.baseClass ?? AtomFieldControl;
|
|
171
|
-
attributes.visible ??= true;
|
|
172
|
-
attributes.fieldClass ??= null;
|
|
173
|
-
return <ControlClass
|
|
174
|
-
{ ... attributes}
|
|
175
|
-
content={children}
|
|
176
|
-
/>;
|
|
177
|
-
}
|
|
@@ -6,7 +6,7 @@ import XNode from "@web-atoms/core/dist/core/XNode";
|
|
|
6
6
|
import StyleRule from "@web-atoms/core/dist/style/StyleRule";
|
|
7
7
|
import { AtomControl } from "@web-atoms/core/dist/web/controls/AtomControl";
|
|
8
8
|
import CSS from "@web-atoms/core/dist/web/styles/CSS";
|
|
9
|
-
import AddImage from "./commands/AddImage";
|
|
9
|
+
import AddImage, { showImageDialog } from "./commands/AddImage";
|
|
10
10
|
import AddLink from "./commands/AddLink";
|
|
11
11
|
import Align from "./commands/Align";
|
|
12
12
|
import Bold from "./commands/Bold";
|
|
@@ -67,7 +67,7 @@ export function Toolbar(a: any, ... nodes: XNode[]) {
|
|
|
67
67
|
</div>;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export class
|
|
70
|
+
export default class HtmlEditor extends AtomControl {
|
|
71
71
|
|
|
72
72
|
@BindableProperty
|
|
73
73
|
public content: string;
|
|
@@ -80,10 +80,15 @@ export class HtmlEditorControl extends AtomControl {
|
|
|
80
80
|
|
|
81
81
|
public editor: HTMLDivElement;
|
|
82
82
|
|
|
83
|
+
public eventDocumentCreated: (e: CustomEvent<Document>) => void;
|
|
84
|
+
|
|
85
|
+
public eventDocumentUpdated: (e: CustomEvent<Document>) => void;
|
|
86
|
+
|
|
83
87
|
public get htmlContent(): string {
|
|
84
88
|
try {
|
|
85
89
|
return this.editor.innerHTML;
|
|
86
90
|
} catch (ex) {
|
|
91
|
+
// tslint:disable-next-line: no-console
|
|
87
92
|
console.warn(ex);
|
|
88
93
|
}
|
|
89
94
|
}
|
|
@@ -97,6 +102,12 @@ export class HtmlEditorControl extends AtomControl {
|
|
|
97
102
|
|
|
98
103
|
private editorDocument: Document;
|
|
99
104
|
|
|
105
|
+
private editorCreated: boolean;
|
|
106
|
+
|
|
107
|
+
public insertImage(s: HtmlEditor, e: Event) {
|
|
108
|
+
return showImageDialog(s, e);
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
public executeCommand(cmd, showUI?: boolean, value?: string): boolean {
|
|
101
112
|
const r = this.editorDocument.execCommand(cmd, showUI, value);
|
|
102
113
|
setTimeout(() => this.version++, 1);
|
|
@@ -172,6 +183,9 @@ export class HtmlEditorControl extends AtomControl {
|
|
|
172
183
|
const updateVersion = () => setTimeout(() => {
|
|
173
184
|
this.version++;
|
|
174
185
|
AtomBinder.refreshValue(this, "htmlContent");
|
|
186
|
+
this.element.dispatchEvent(new CustomEvent("documentUpdated", {
|
|
187
|
+
detail: doc
|
|
188
|
+
}));
|
|
175
189
|
}, 1);
|
|
176
190
|
this.editor.addEventListener("click", updateVersion);
|
|
177
191
|
this.editor.addEventListener("keydown", updateVersion);
|
|
@@ -180,6 +194,12 @@ export class HtmlEditorControl extends AtomControl {
|
|
|
180
194
|
this.editorWindow = frame.contentWindow;
|
|
181
195
|
this.editorDocument = doc;
|
|
182
196
|
|
|
197
|
+
updateVersion();
|
|
198
|
+
|
|
199
|
+
this.element.dispatchEvent(new CustomEvent("documentCreated", {
|
|
200
|
+
detail: doc
|
|
201
|
+
}));
|
|
202
|
+
|
|
183
203
|
this.registerDisposable({
|
|
184
204
|
dispose: () => {
|
|
185
205
|
this.editor.removeEventListener("click", updateVersion);
|
|
@@ -189,23 +209,15 @@ export class HtmlEditorControl extends AtomControl {
|
|
|
189
209
|
}
|
|
190
210
|
});
|
|
191
211
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export interface IHtmlEditor {
|
|
195
|
-
insertImage?: (s: HtmlEditorControl, e: Event) => Promise<string> | string;
|
|
196
|
-
}
|
|
197
212
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return <HtmlEditorControl { ... attributes}>
|
|
207
|
-
<Toolbar>
|
|
208
|
-
<Bold/>
|
|
213
|
+
protected render(node: XNode, e?: any, creator?: any): void {
|
|
214
|
+
if (this.editorCreated) {
|
|
215
|
+
return super.render(node, e, creator);
|
|
216
|
+
}
|
|
217
|
+
this.editorCreated = true;
|
|
218
|
+
if (!node.children || node.children.length === 0 ) {
|
|
219
|
+
node.children[0] = <Toolbar>
|
|
220
|
+
<Bold/>
|
|
209
221
|
<Italic/>
|
|
210
222
|
<Underline/>
|
|
211
223
|
<StrikeThrough/>
|
|
@@ -223,20 +235,18 @@ export default function HtmlEditor(
|
|
|
223
235
|
<IndentLess/>
|
|
224
236
|
<IndentMore/>
|
|
225
237
|
<Separator/>
|
|
226
|
-
<AddImage
|
|
238
|
+
<AddImage/>
|
|
227
239
|
<Separator/>
|
|
228
240
|
<AddLink/>
|
|
229
241
|
<Unlink/>
|
|
230
242
|
<RemoveFormat/>
|
|
231
243
|
<Separator/>
|
|
232
244
|
<Source/>
|
|
233
|
-
</Toolbar
|
|
245
|
+
</Toolbar>;
|
|
246
|
+
}
|
|
247
|
+
super.render(<div {... node.attributes}>
|
|
248
|
+
{ ... node.children as any[]}
|
|
234
249
|
<iframe class="editor-frame"/>
|
|
235
|
-
</
|
|
250
|
+
</div>);
|
|
236
251
|
}
|
|
237
|
-
|
|
238
|
-
return <HtmlEditorControl { ... attributes}>
|
|
239
|
-
{ ... nodes}
|
|
240
|
-
<iframe class="editor-frame"/>
|
|
241
|
-
</HtmlEditorControl>;
|
|
242
252
|
}
|
|
@@ -3,8 +3,9 @@ import { BindableProperty } from "@web-atoms/core/dist/core/BindableProperty";
|
|
|
3
3
|
import XNode from "@web-atoms/core/dist/core/XNode";
|
|
4
4
|
import PopupService, { PopupWindow } from "@web-atoms/core/dist/web/services/PopupService";
|
|
5
5
|
import FormField from "../../basic/FormField";
|
|
6
|
-
import type
|
|
6
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
7
7
|
import CommandButton, { notSet } from "./CommandButton";
|
|
8
|
+
import HtmlCommands from "./HtmlCommands";
|
|
8
9
|
|
|
9
10
|
class ImageDialog extends PopupWindow {
|
|
10
11
|
|
|
@@ -40,17 +41,18 @@ class ImageDialog extends PopupWindow {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
function showImageDialog(s:
|
|
44
|
-
return PopupService.showWindow(e.currentTarget as HTMLElement, ImageDialog, { title: "Add Image" });
|
|
44
|
+
export function showImageDialog(s: HtmlEditor, e: Event): Promise<string> | string {
|
|
45
|
+
return PopupService.showWindow<string>(e.currentTarget as HTMLElement, ImageDialog, { title: "Add Image" });
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export default function AddImage({
|
|
48
|
-
eventInsertHtml =
|
|
49
|
-
insertCommand =
|
|
49
|
+
eventInsertHtml = (s: HtmlEditor, e: Event) => s.insertImage(s, e),
|
|
50
|
+
insertCommand = HtmlCommands.insertImage
|
|
50
51
|
}) {
|
|
51
52
|
return CommandButton({
|
|
52
53
|
icon: "ri-image-add-fill",
|
|
53
54
|
insertCommand,
|
|
55
|
+
disabled: false,
|
|
54
56
|
title: "Insert Image",
|
|
55
57
|
eventInsertHtml
|
|
56
58
|
});
|
|
@@ -7,8 +7,9 @@ import { AtomToggleButtonBar } from "@web-atoms/core/dist/web/controls/AtomToggl
|
|
|
7
7
|
import PopupService, { PopupWindow } from "@web-atoms/core/dist/web/services/PopupService";
|
|
8
8
|
import CSS from "@web-atoms/core/dist/web/styles/CSS";
|
|
9
9
|
import FormField from "../../basic/FormField";
|
|
10
|
-
import type
|
|
10
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
11
11
|
import CommandButton, { notSet } from "./CommandButton";
|
|
12
|
+
import HtmlCommands from "./HtmlCommands";
|
|
12
13
|
|
|
13
14
|
const linkTypes = [
|
|
14
15
|
{
|
|
@@ -73,16 +74,17 @@ class LinkDialog extends PopupWindow {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
function showDialog(s:
|
|
77
|
+
function showDialog(s: HtmlEditor, e: Event): Promise<string> {
|
|
77
78
|
return PopupService.showWindow(s.element, LinkDialog);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
export default function AddLink({
|
|
81
|
-
insertCommand =
|
|
82
|
+
insertCommand = HtmlCommands.createLink
|
|
82
83
|
}) {
|
|
83
84
|
return CommandButton({
|
|
84
85
|
icon: "ri-link-m",
|
|
85
86
|
insertCommand,
|
|
87
|
+
disabled: false,
|
|
86
88
|
eventInsertHtml: showDialog,
|
|
87
89
|
title: "Create Hyper Link"
|
|
88
90
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Bind from "@web-atoms/core/dist/core/Bind";
|
|
2
2
|
import XNode from "@web-atoms/core/dist/core/XNode";
|
|
3
3
|
import PopupButton, { MenuItem } from "../../basic/PopupButton";
|
|
4
|
-
import type
|
|
4
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
5
5
|
|
|
6
6
|
export default function Align() {
|
|
7
7
|
return <PopupButton
|
|
@@ -11,22 +11,22 @@ export default function Align() {
|
|
|
11
11
|
<MenuItem
|
|
12
12
|
icon="ri-align-left"
|
|
13
13
|
title="Align Left"
|
|
14
|
-
eventClick={Bind.event((e:
|
|
14
|
+
eventClick={Bind.event((e: HtmlEditor) =>
|
|
15
15
|
e.executeCommand("justifyLeft"))}/>
|
|
16
16
|
<MenuItem
|
|
17
17
|
icon="ri-align-center"
|
|
18
18
|
title="Align Center"
|
|
19
|
-
eventClick={Bind.event((e:
|
|
19
|
+
eventClick={Bind.event((e: HtmlEditor) =>
|
|
20
20
|
e.executeCommand("justifyCenter"))}/>
|
|
21
21
|
<MenuItem
|
|
22
22
|
icon="ri-align-right"
|
|
23
23
|
title="Align Right"
|
|
24
|
-
eventClick={Bind.event((e:
|
|
24
|
+
eventClick={Bind.event((e: HtmlEditor) =>
|
|
25
25
|
e.executeCommand("justifyRight"))}/>
|
|
26
26
|
<MenuItem
|
|
27
27
|
icon="ri-align-justify"
|
|
28
28
|
title="Justify"
|
|
29
|
-
eventClick={Bind.event((e:
|
|
29
|
+
eventClick={Bind.event((e: HtmlEditor) =>
|
|
30
30
|
e.executeCommand("justifyFull"))}/>
|
|
31
31
|
</PopupButton>;
|
|
32
32
|
}
|
|
@@ -3,7 +3,7 @@ import XNode from "@web-atoms/core/dist/core/XNode";
|
|
|
3
3
|
import StyleRule from "@web-atoms/core/dist/style/StyleRule";
|
|
4
4
|
import CSS from "@web-atoms/core/dist/web/styles/CSS";
|
|
5
5
|
import PopupButton from "../../basic/PopupButton";
|
|
6
|
-
import type
|
|
6
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
7
7
|
|
|
8
8
|
const gray = [
|
|
9
9
|
"rgb(0,0,0)",
|
|
@@ -115,14 +115,14 @@ const colorSelectorCss = CSS(StyleRule("color-selector")
|
|
|
115
115
|
function TextColor(color: string) {
|
|
116
116
|
return <div
|
|
117
117
|
class="color-button"
|
|
118
|
-
eventClick={Bind.event((e:
|
|
118
|
+
eventClick={Bind.event((e: HtmlEditor) => e.executeCommand("foreColor", false, color))}
|
|
119
119
|
styleBackgroundColor={color.toLowerCase()} title={color}></div>;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
function BackgroundColor(color: string) {
|
|
123
123
|
return <div
|
|
124
124
|
class="color-button"
|
|
125
|
-
eventClick={Bind.event((e:
|
|
125
|
+
eventClick={Bind.event((e: HtmlEditor) => e.executeCommand("hiliteColor", false, color))}
|
|
126
126
|
styleBackgroundColor={color.toLowerCase()} title={color}></div>;
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -4,7 +4,7 @@ import XNode from "@web-atoms/core/dist/core/XNode";
|
|
|
4
4
|
import StyleRule from "@web-atoms/core/dist/style/StyleRule";
|
|
5
5
|
import CSS from "@web-atoms/core/dist/web/styles/CSS";
|
|
6
6
|
import PopupButton from "../../basic/PopupButton";
|
|
7
|
-
import type
|
|
7
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
8
8
|
|
|
9
9
|
const fontMenuCSS = CSS(StyleRule()
|
|
10
10
|
.padding(5)
|
|
@@ -38,8 +38,8 @@ export function FontMenu({ name, value }) {
|
|
|
38
38
|
const cssName = value.join(" ");
|
|
39
39
|
return <div
|
|
40
40
|
class="menu"
|
|
41
|
-
eventClick={Bind.event((e:
|
|
42
|
-
<i class={Bind.oneWay((e:
|
|
41
|
+
eventClick={Bind.event((e: HtmlEditor) => e.executeCommand("fontName", false, cssName) )}>
|
|
42
|
+
<i class={Bind.oneWay((e: HtmlEditor) => ({
|
|
43
43
|
"ri-check-line": 1,
|
|
44
44
|
"selected": e.getStyle("fontFamily", e.version)
|
|
45
45
|
.toLowerCase()
|
|
@@ -66,7 +66,7 @@ function selectFont(name: string) {
|
|
|
66
66
|
export default function ChangeFont() {
|
|
67
67
|
return <PopupButton
|
|
68
68
|
class="command"
|
|
69
|
-
text={Bind.oneWay((e:
|
|
69
|
+
text={Bind.oneWay((e: HtmlEditor) => selectFont(e.getStyle("fontFamily", e.version)))}
|
|
70
70
|
title="Change Font">
|
|
71
71
|
<div class={fontMenuCSS}>
|
|
72
72
|
{ ... fonts.map((x) => <FontMenu name={x[0]} value={x[1]}/>)}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Bind from "@web-atoms/core/dist/core/Bind";
|
|
2
2
|
import XNode from "@web-atoms/core/dist/core/XNode";
|
|
3
3
|
import PopupButton, { MenuItem } from "../../basic/PopupButton";
|
|
4
|
-
import type
|
|
4
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
5
5
|
import Command, { ICommand } from "./Command";
|
|
6
6
|
|
|
7
7
|
export default function ChangeFontSize(cmd: ICommand) {
|
|
@@ -9,9 +9,9 @@ export default function ChangeFontSize(cmd: ICommand) {
|
|
|
9
9
|
class="command"
|
|
10
10
|
icon="ri-font-size-2"
|
|
11
11
|
title="Change Font Size">
|
|
12
|
-
<MenuItem icon="ri-add-line" label="Increase" eventClick={Bind.event((e:
|
|
12
|
+
<MenuItem icon="ri-add-line" label="Increase" eventClick={Bind.event((e: HtmlEditor) =>
|
|
13
13
|
e.executeCommand("increaseFontSize"))}/>
|
|
14
|
-
<MenuItem icon="ri-subtract-line" label="Decrease" eventClick={Bind.event((e:
|
|
14
|
+
<MenuItem icon="ri-subtract-line" label="Decrease" eventClick={Bind.event((e: HtmlEditor) =>
|
|
15
15
|
e.executeCommand("decreaseFontSize"))}/>
|
|
16
16
|
</PopupButton>;
|
|
17
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Bind from "@web-atoms/core/dist/core/Bind";
|
|
2
2
|
import XNode from "@web-atoms/core/dist/core/XNode";
|
|
3
|
-
import type
|
|
3
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
4
4
|
|
|
5
5
|
export interface ICommand {
|
|
6
6
|
label?: string;
|
|
@@ -8,8 +8,8 @@ export interface ICommand {
|
|
|
8
8
|
queryState?: string;
|
|
9
9
|
enabled?: boolean;
|
|
10
10
|
title?: string;
|
|
11
|
-
command?: (editor:
|
|
12
|
-
query?: (editor:
|
|
11
|
+
command?: (editor: HtmlEditor) => void;
|
|
12
|
+
query?: (editor: HtmlEditor) => boolean;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export default function Command({
|
|
@@ -22,8 +22,8 @@ export default function Command({
|
|
|
22
22
|
}: ICommand) {
|
|
23
23
|
if (label) {
|
|
24
24
|
return <div
|
|
25
|
-
eventClick={Bind.event((e) => command(e as
|
|
26
|
-
styleClass={Bind.oneWay((e:
|
|
25
|
+
eventClick={Bind.event((e) => command(e as HtmlEditor))}
|
|
26
|
+
styleClass={Bind.oneWay((e: HtmlEditor) => ({
|
|
27
27
|
command: e.version,
|
|
28
28
|
pressed: !e.queryCommandState(queryState)
|
|
29
29
|
}))}
|
|
@@ -33,8 +33,8 @@ export default function Command({
|
|
|
33
33
|
</div>;
|
|
34
34
|
}
|
|
35
35
|
return <div
|
|
36
|
-
eventClick={Bind.event((e) => command(e as
|
|
37
|
-
styleClass={Bind.oneWay((e:
|
|
36
|
+
eventClick={Bind.event((e) => command(e as HtmlEditor))}
|
|
37
|
+
styleClass={Bind.oneWay((e: HtmlEditor) => ({
|
|
38
38
|
command: e.version,
|
|
39
39
|
pressed: e.queryCommandState(queryState)
|
|
40
40
|
}))}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Bind from "@web-atoms/core/dist/core/Bind";
|
|
2
2
|
import XNode from "@web-atoms/core/dist/core/XNode";
|
|
3
|
-
import type
|
|
3
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
4
|
+
import { IHtmlCommand } from "./HtmlCommands";
|
|
4
5
|
|
|
5
6
|
export interface ICommandButton {
|
|
6
7
|
icon?: string;
|
|
@@ -13,12 +14,17 @@ export interface ICommandButton {
|
|
|
13
14
|
/**
|
|
14
15
|
* Default is insertHTML but you can change it.
|
|
15
16
|
*/
|
|
16
|
-
insertCommand:
|
|
17
|
+
insertCommand: IHtmlCommand;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Tooltip
|
|
20
21
|
*/
|
|
21
22
|
title?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* setup if command is disabled or not
|
|
26
|
+
*/
|
|
27
|
+
disabled?: boolean;
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
export function notSet(text: string) {
|
|
@@ -27,8 +33,8 @@ export function notSet(text: string) {
|
|
|
27
33
|
};
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
function insert(callback: (s:
|
|
31
|
-
return async (s:
|
|
36
|
+
function insert(callback: (s: HtmlEditor, e: Event) => Promise<string> | string, command: IHtmlCommand): any {
|
|
37
|
+
return async (s: HtmlEditor, e: Event) => {
|
|
32
38
|
let r = callback(s, e);
|
|
33
39
|
if (typeof r !== "string") {
|
|
34
40
|
if (r.then) {
|
|
@@ -36,7 +42,11 @@ function insert(callback: (s: HtmlEditorControl, e: Event) => Promise<string> |
|
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
if (r) {
|
|
39
|
-
|
|
45
|
+
if (command) {
|
|
46
|
+
command.execute(s, false, r as string);
|
|
47
|
+
} else {
|
|
48
|
+
s.executeCommand("insertHTML", false, r as string);
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
51
|
};
|
|
42
52
|
}
|
|
@@ -46,11 +56,18 @@ export default function CommandButton({
|
|
|
46
56
|
label,
|
|
47
57
|
eventInsertHtml,
|
|
48
58
|
insertCommand,
|
|
49
|
-
title
|
|
59
|
+
title,
|
|
60
|
+
disabled
|
|
50
61
|
}: ICommandButton) {
|
|
62
|
+
|
|
63
|
+
disabled ??= Bind.oneWay((x: HtmlEditor) => x.version
|
|
64
|
+
? !insertCommand.canExecute(x)
|
|
65
|
+
: false);
|
|
66
|
+
|
|
51
67
|
if (label) {
|
|
52
68
|
return <button
|
|
53
69
|
class="command"
|
|
70
|
+
disabled={disabled}
|
|
54
71
|
eventClick={Bind.event(insert(eventInsertHtml, insertCommand))}
|
|
55
72
|
title={title}>
|
|
56
73
|
<label class="label">
|
|
@@ -62,6 +79,7 @@ export default function CommandButton({
|
|
|
62
79
|
return <button
|
|
63
80
|
title={title}
|
|
64
81
|
class="command"
|
|
82
|
+
disabled={disabled}
|
|
65
83
|
eventClick={Bind.event(insert(eventInsertHtml, insertCommand))}>
|
|
66
84
|
<i class={icon} />
|
|
67
85
|
</button>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import Bind from "@web-atoms/core/dist/core/Bind";
|
|
2
2
|
import XNode from "@web-atoms/core/dist/core/XNode";
|
|
3
3
|
import PopupButton, { MenuItem } from "../../basic/PopupButton";
|
|
4
|
-
import type
|
|
4
|
+
import type HtmlEditor from "../HtmlEditor";
|
|
5
5
|
|
|
6
6
|
export default function Headings() {
|
|
7
7
|
return <PopupButton
|
|
8
8
|
class="command"
|
|
9
9
|
icon="ri-heading"
|
|
10
10
|
title="Apply Heading">
|
|
11
|
-
<MenuItem icon="ri-h-1" eventClick={Bind.event((e:
|
|
11
|
+
<MenuItem icon="ri-h-1" eventClick={Bind.event((e: HtmlEditor) =>
|
|
12
12
|
e.executeCommand("formatBlock", false, "H1"))}/>
|
|
13
13
|
<MenuItem icon="ri-h-2" eventClick={Bind.event((e: any) =>
|
|
14
14
|
e.executeCommand("formatBlock", false, "H2"))}/>
|