@web-atoms/web-controls 2.1.17 → 2.1.21

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.
Files changed (56) hide show
  1. package/dist/form/AtomField.d.ts +0 -2
  2. package/dist/form/AtomField.d.ts.map +1 -1
  3. package/dist/form/AtomField.js +12 -48
  4. package/dist/form/AtomField.js.map +1 -1
  5. package/dist/html-editor/HtmlEditor.d.ts +5 -5
  6. package/dist/html-editor/HtmlEditor.d.ts.map +1 -1
  7. package/dist/html-editor/HtmlEditor.js +36 -38
  8. package/dist/html-editor/HtmlEditor.js.map +1 -1
  9. package/dist/html-editor/commands/AddImage.d.ts +4 -5
  10. package/dist/html-editor/commands/AddImage.d.ts.map +1 -1
  11. package/dist/html-editor/commands/AddImage.js +6 -2
  12. package/dist/html-editor/commands/AddImage.js.map +1 -1
  13. package/dist/html-editor/commands/AddLink.d.ts +1 -1
  14. package/dist/html-editor/commands/AddLink.d.ts.map +1 -1
  15. package/dist/html-editor/commands/AddLink.js +4 -2
  16. package/dist/html-editor/commands/AddLink.js.map +1 -1
  17. package/dist/html-editor/commands/Align.js.map +1 -1
  18. package/dist/html-editor/commands/ChangeColor.js.map +1 -1
  19. package/dist/html-editor/commands/ChangeFont.js.map +1 -1
  20. package/dist/html-editor/commands/ChangeFontSize.js.map +1 -1
  21. package/dist/html-editor/commands/Command.d.ts +3 -3
  22. package/dist/html-editor/commands/Command.d.ts.map +1 -1
  23. package/dist/html-editor/commands/Command.js.map +1 -1
  24. package/dist/html-editor/commands/CommandButton.d.ts +7 -2
  25. package/dist/html-editor/commands/CommandButton.d.ts.map +1 -1
  26. package/dist/html-editor/commands/CommandButton.js +12 -4
  27. package/dist/html-editor/commands/CommandButton.js.map +1 -1
  28. package/dist/html-editor/commands/Headings.js.map +1 -1
  29. package/dist/html-editor/commands/HtmlCommands.d.ts +59 -0
  30. package/dist/html-editor/commands/HtmlCommands.d.ts.map +1 -0
  31. package/dist/html-editor/commands/HtmlCommands.js +81 -0
  32. package/dist/html-editor/commands/HtmlCommands.js.map +1 -0
  33. package/dist/html-editor/commands/Source.d.ts +4 -1
  34. package/dist/html-editor/commands/Source.d.ts.map +1 -1
  35. package/dist/html-editor/commands/Source.js +4 -3
  36. package/dist/html-editor/commands/Source.js.map +1 -1
  37. package/dist/html-editor/commands/Unlink.d.ts +3 -1
  38. package/dist/html-editor/commands/Unlink.d.ts.map +1 -1
  39. package/dist/html-editor/commands/Unlink.js +10 -6
  40. package/dist/html-editor/commands/Unlink.js.map +1 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +2 -2
  43. package/src/form/AtomField.tsx +12 -42
  44. package/src/html-editor/HtmlEditor.tsx +32 -26
  45. package/src/html-editor/commands/AddImage.tsx +7 -5
  46. package/src/html-editor/commands/AddLink.tsx +5 -3
  47. package/src/html-editor/commands/Align.tsx +5 -5
  48. package/src/html-editor/commands/ChangeColor.tsx +3 -3
  49. package/src/html-editor/commands/ChangeFont.tsx +4 -4
  50. package/src/html-editor/commands/ChangeFontSize.tsx +3 -3
  51. package/src/html-editor/commands/Command.tsx +7 -7
  52. package/src/html-editor/commands/CommandButton.tsx +24 -6
  53. package/src/html-editor/commands/Headings.tsx +2 -2
  54. package/src/html-editor/commands/HtmlCommands.ts +78 -0
  55. package/src/html-editor/commands/Source.tsx +5 -4
  56. package/src/html-editor/commands/Unlink.tsx +9 -9
@@ -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 HtmlEditorControl extends AtomControl {
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,10 @@ export class HtmlEditorControl extends AtomControl {
97
102
 
98
103
  private editorDocument: Document;
99
104
 
105
+ public insertImage(s: HtmlEditor, e: Event) {
106
+ return showImageDialog(s, e);
107
+ }
108
+
100
109
  public executeCommand(cmd, showUI?: boolean, value?: string): boolean {
101
110
  const r = this.editorDocument.execCommand(cmd, showUI, value);
102
111
  setTimeout(() => this.version++, 1);
@@ -172,6 +181,9 @@ export class HtmlEditorControl extends AtomControl {
172
181
  const updateVersion = () => setTimeout(() => {
173
182
  this.version++;
174
183
  AtomBinder.refreshValue(this, "htmlContent");
184
+ this.element.dispatchEvent(new CustomEvent("documentUpdated", {
185
+ detail: doc
186
+ }));
175
187
  }, 1);
176
188
  this.editor.addEventListener("click", updateVersion);
177
189
  this.editor.addEventListener("keydown", updateVersion);
@@ -180,6 +192,12 @@ export class HtmlEditorControl extends AtomControl {
180
192
  this.editorWindow = frame.contentWindow;
181
193
  this.editorDocument = doc;
182
194
 
195
+ updateVersion();
196
+
197
+ this.element.dispatchEvent(new CustomEvent("documentCreated", {
198
+ detail: doc
199
+ }));
200
+
183
201
  this.registerDisposable({
184
202
  dispose: () => {
185
203
  this.editor.removeEventListener("click", updateVersion);
@@ -189,23 +207,13 @@ export class HtmlEditorControl extends AtomControl {
189
207
  }
190
208
  });
191
209
  }
192
- }
193
-
194
- export interface IHtmlEditor {
195
- insertImage?: (s: HtmlEditorControl, e: Event) => Promise<string> | string;
196
- }
197
210
 
198
- export default function HtmlEditor(
199
- {
200
- insertImage,
201
- ... attributes
202
- }: any,
203
- ... nodes: XNode[]) {
204
-
205
- if (nodes.length === 0) {
206
- return <HtmlEditorControl { ... attributes}>
207
- <Toolbar>
208
- <Bold/>
211
+ protected render(node: XNode, e?: any, creator?: any): void {
212
+ // following line will prevent stack overflow
213
+ this.render = super.render;
214
+ if (!node.children || node.children.length === 0 ) {
215
+ node.children[0] = <Toolbar>
216
+ <Bold/>
209
217
  <Italic/>
210
218
  <Underline/>
211
219
  <StrikeThrough/>
@@ -223,20 +231,18 @@ export default function HtmlEditor(
223
231
  <IndentLess/>
224
232
  <IndentMore/>
225
233
  <Separator/>
226
- <AddImage eventInsertHtml={insertImage}/>
234
+ <AddImage/>
227
235
  <Separator/>
228
236
  <AddLink/>
229
237
  <Unlink/>
230
238
  <RemoveFormat/>
231
239
  <Separator/>
232
240
  <Source/>
233
- </Toolbar>
241
+ </Toolbar>;
242
+ }
243
+ super.render(<div {... node.attributes}>
244
+ { ... node.children as any[]}
234
245
  <iframe class="editor-frame"/>
235
- </HtmlEditorControl>;
246
+ </div>);
236
247
  }
237
-
238
- return <HtmlEditorControl { ... attributes}>
239
- { ... nodes}
240
- <iframe class="editor-frame"/>
241
- </HtmlEditorControl>;
242
248
  }
@@ -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 { HtmlEditorControl } from "../HtmlEditor";
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: HtmlEditorControl, e: Event) {
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 = showImageDialog,
49
- insertCommand = "insertHTML"
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 { HtmlEditorControl } from "../HtmlEditor";
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: HtmlEditorControl, e: Event): Promise<string> {
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 = "createLink"
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 { HtmlEditorControl } from "../HtmlEditor";
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: HtmlEditorControl) =>
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: HtmlEditorControl) =>
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: HtmlEditorControl) =>
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: HtmlEditorControl) =>
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 { HtmlEditorControl } from "../HtmlEditor";
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: HtmlEditorControl) => e.executeCommand("foreColor", false, color))}
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: HtmlEditorControl) => e.executeCommand("hiliteColor", false, color))}
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 { HtmlEditorControl } from "../HtmlEditor";
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: HtmlEditorControl) => e.executeCommand("fontName", false, cssName) )}>
42
- <i class={Bind.oneWay((e: HtmlEditorControl) => ({
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: HtmlEditorControl) => selectFont(e.getStyle("fontFamily", e.version)))}
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 { HtmlEditorControl } from "../HtmlEditor";
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: HtmlEditorControl) =>
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: HtmlEditorControl) =>
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 { HtmlEditorControl } from "../HtmlEditor";
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: HtmlEditorControl) => void;
12
- query?: (editor: HtmlEditorControl) => boolean;
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 HtmlEditorControl))}
26
- styleClass={Bind.oneWay((e: HtmlEditorControl) => ({
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 HtmlEditorControl))}
37
- styleClass={Bind.oneWay((e: HtmlEditorControl) => ({
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 { HtmlEditorControl } from "../HtmlEditor";
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: any;
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: HtmlEditorControl, e: Event) => Promise<string> | string, command: string): any {
31
- return async (s: HtmlEditorControl, e: Event) => {
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
- s.executeCommand(command ?? "insertHTML", false, r as string);
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 { HtmlEditorControl } from "../HtmlEditor";
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: HtmlEditorControl) =>
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"))}/>
@@ -0,0 +1,78 @@
1
+ import type HtmlEditor from "../HtmlEditor";
2
+
3
+ function query(name: keyof typeof HtmlCommands): IHtmlCommand {
4
+ return {
5
+ canExecute(e: HtmlEditor): boolean {
6
+ return e.queryCommandState(name);
7
+ },
8
+ execute(e: HtmlEditor, showUI?: boolean, value?: string): boolean {
9
+ return e.executeCommand(name, showUI, value);
10
+ }
11
+ };
12
+ }
13
+
14
+ export interface IHtmlCommand {
15
+ canExecute(e: HtmlEditor): boolean;
16
+ execute(e: HtmlEditor, showUI?: boolean, value?: string): boolean;
17
+ }
18
+
19
+ export default class HtmlCommands {
20
+
21
+ public static backColor = query("backColor");
22
+ public static bold = query("bold");
23
+ public static contentReadOnly = query("contentReadOnly");
24
+ public static copy = query("copy");
25
+ public static createLink = query("createLink");
26
+ public static cut = query("cut");
27
+ public static decreaseFontSize = query("decreaseFontSize");
28
+ public static defaultParagraphSeparator = query("defaultParagraphSeparator");
29
+ public static enableAbsolutePositionEditor = query("enableAbsolutePositionEditor");
30
+ public static enableInlineTableEditing = query("enableInlineTableEditing");
31
+ public static enableObjectResizing = query("enableObjectResizing");
32
+ public static fontName = query("fontName");
33
+ public static fontSize = query("fontSize");
34
+ public static foreColor = query("foreColor");
35
+ public static formatBlock = query("formatBlock");
36
+ public static forwardDelete = query("forwardDelete");
37
+ public static heading = query("heading");
38
+ public static hiliteColor = query("hiliteColor");
39
+ public static increaseFontSize = query("increaseFontSize");
40
+ public static indent = query("indent");
41
+ public static insertBrOnReturn = query("insertBrOnReturn");
42
+ public static insertHorizontalRule = query("insertHorizontalRule");
43
+ public static insertHTML = query("insertHTML");
44
+ public static insertImage = query("insertImage");
45
+ public static insertOrderedList = query("insertOrderedList");
46
+ public static insertUnorderedList = query("insertUnorderedList");
47
+ public static insertParagraph = query("insertParagraph");
48
+ public static insertText = query("insertText");
49
+ public static italic = query("italic");
50
+ public static justifyCenter = query("justifyCenter");
51
+ public static justifyFull = query("justifyFull");
52
+ public static justifyLeft = query("justifyLeft");
53
+ public static justifyRight = query("justifyRight");
54
+ public static outdent = query("outdent");
55
+ public static paste = query("paste");
56
+ public static redo = query("redo");
57
+ public static removeFormat = query("removeFormat");
58
+ public static selectAll = query("selectAll");
59
+ public static strikeThrough = query("strikeThrough");
60
+ public static subscript = query("subscript");
61
+ public static superscript = query("superscript");
62
+ public static underline = query("underline");
63
+ public static undo = query("undo");
64
+ public static unlink = query("unlink");
65
+ public static useCSS = query("useCSS");
66
+ public static styleWithCSS = query("styleWithCSS");
67
+ public static AutoUrlDetect = query("AutoUrlDetect");
68
+
69
+ public static enabled = {
70
+ canExecute(e) {
71
+ return true;
72
+ },
73
+ execute() {
74
+ throw new Error("not supported");
75
+ }
76
+ };
77
+
78
+ }
@@ -4,8 +4,9 @@ import XNode from "@web-atoms/core/dist/core/XNode";
4
4
  import StyleRule from "@web-atoms/core/dist/style/StyleRule";
5
5
  import PopupService, { PopupWindow } from "@web-atoms/core/dist/web/services/PopupService";
6
6
  import CSS from "@web-atoms/core/dist/web/styles/CSS";
7
- import { HtmlEditorControl } from "../HtmlEditor";
7
+ import type HtmlEditor from "../HtmlEditor";
8
8
  import CommandButton from "./CommandButton";
9
+ import HtmlCommands from "./HtmlCommands";
9
10
 
10
11
  const css = CSS(StyleRule()
11
12
  .child(StyleRule("textarea")
@@ -14,7 +15,7 @@ const css = CSS(StyleRule()
14
15
  )
15
16
  );
16
17
 
17
- async function showDialog(s: HtmlEditorControl, e: Event): Promise<string> {
18
+ async function showDialog(s: HtmlEditor, e: Event): Promise<string> {
18
19
 
19
20
  class SourceDialog extends PopupWindow {
20
21
 
@@ -41,12 +42,12 @@ async function showDialog(s: HtmlEditorControl, e: Event): Promise<string> {
41
42
  }
42
43
 
43
44
  export default function Source({
44
- insertCommand = "createLink"
45
+ insertCommand = HtmlCommands.enabled
45
46
  }) {
46
47
  return CommandButton({
47
48
  icon: "ri-edit-box-fill",
48
49
  insertCommand,
49
50
  eventInsertHtml: showDialog,
50
- title: "Create Hyper Link"
51
+ title: "Edit Source Code"
51
52
  });
52
53
  }
@@ -1,13 +1,13 @@
1
- import Command from "./Command";
1
+ import CommandButton from "./CommandButton";
2
+ import HtmlCommands from "./HtmlCommands";
2
3
 
3
- export default function Unlink(cmd: any) {
4
- return Command({
4
+ export default function Unlink({
5
+ insertCommand = HtmlCommands.unlink
6
+ }) {
7
+ return CommandButton({
5
8
  icon: "ri-link-unlink-m",
6
- queryState: "unlink",
7
- title: "Remove Link",
8
- ... cmd,
9
- command(editor) {
10
- editor.executeCommand("unlink");
11
- }
9
+ insertCommand,
10
+ eventInsertHtml: () => "",
11
+ title: "Remove Hyperlink"
12
12
  });
13
13
  }