@web-atoms/web-controls 2.1.13 → 2.1.19

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 (51) hide show
  1. package/dist/basic/FormField.d.ts +1 -1
  2. package/dist/basic/FormField.d.ts.map +1 -1
  3. package/dist/basic/FormField.js +9 -2
  4. package/dist/basic/FormField.js.map +1 -1
  5. package/dist/basic/PopupButton.d.ts.map +1 -1
  6. package/dist/basic/PopupButton.js +1 -2
  7. package/dist/basic/PopupButton.js.map +1 -1
  8. package/dist/form/AtomField.d.ts +4 -17
  9. package/dist/form/AtomField.d.ts.map +1 -1
  10. package/dist/form/AtomField.js +22 -63
  11. package/dist/form/AtomField.js.map +1 -1
  12. package/dist/html-editor/HtmlEditor.d.ts +2 -1
  13. package/dist/html-editor/HtmlEditor.d.ts.map +1 -1
  14. package/dist/html-editor/HtmlEditor.js +7 -0
  15. package/dist/html-editor/HtmlEditor.js.map +1 -1
  16. package/dist/html-editor/commands/AddImage.d.ts +5 -2
  17. package/dist/html-editor/commands/AddImage.d.ts.map +1 -1
  18. package/dist/html-editor/commands/AddImage.js +48 -2
  19. package/dist/html-editor/commands/AddImage.js.map +1 -1
  20. package/dist/html-editor/commands/AddLink.d.ts +1 -1
  21. package/dist/html-editor/commands/AddLink.d.ts.map +1 -1
  22. package/dist/html-editor/commands/AddLink.js +5 -4
  23. package/dist/html-editor/commands/AddLink.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/HtmlCommands.d.ts +59 -0
  29. package/dist/html-editor/commands/HtmlCommands.d.ts.map +1 -0
  30. package/dist/html-editor/commands/HtmlCommands.js +81 -0
  31. package/dist/html-editor/commands/HtmlCommands.js.map +1 -0
  32. package/dist/html-editor/commands/Source.d.ts +4 -1
  33. package/dist/html-editor/commands/Source.d.ts.map +1 -1
  34. package/dist/html-editor/commands/Source.js +7 -7
  35. package/dist/html-editor/commands/Source.js.map +1 -1
  36. package/dist/html-editor/commands/Unlink.d.ts +3 -1
  37. package/dist/html-editor/commands/Unlink.d.ts.map +1 -1
  38. package/dist/html-editor/commands/Unlink.js +10 -6
  39. package/dist/html-editor/commands/Unlink.js.map +1 -1
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/package.json +2 -2
  42. package/src/basic/FormField.tsx +11 -1
  43. package/src/basic/PopupButton.tsx +1 -2
  44. package/src/form/AtomField.tsx +18 -68
  45. package/src/html-editor/HtmlEditor.tsx +11 -1
  46. package/src/html-editor/commands/AddImage.tsx +48 -2
  47. package/src/html-editor/commands/AddLink.tsx +4 -3
  48. package/src/html-editor/commands/CommandButton.tsx +22 -4
  49. package/src/html-editor/commands/HtmlCommands.ts +78 -0
  50. package/src/html-editor/commands/Source.tsx +6 -6
  51. package/src/html-editor/commands/Unlink.tsx +9 -9
@@ -172,6 +172,9 @@ export class HtmlEditorControl extends AtomControl {
172
172
  const updateVersion = () => setTimeout(() => {
173
173
  this.version++;
174
174
  AtomBinder.refreshValue(this, "htmlContent");
175
+ this.element.dispatchEvent(new CustomEvent("documentUpdated", {
176
+ detail: doc
177
+ }));
175
178
  }, 1);
176
179
  this.editor.addEventListener("click", updateVersion);
177
180
  this.editor.addEventListener("keydown", updateVersion);
@@ -180,6 +183,12 @@ export class HtmlEditorControl extends AtomControl {
180
183
  this.editorWindow = frame.contentWindow;
181
184
  this.editorDocument = doc;
182
185
 
186
+ updateVersion();
187
+
188
+ this.element.dispatchEvent(new CustomEvent("documentCreated", {
189
+ detail: doc
190
+ }));
191
+
183
192
  this.registerDisposable({
184
193
  dispose: () => {
185
194
  this.editor.removeEventListener("click", updateVersion);
@@ -193,13 +202,14 @@ export class HtmlEditorControl extends AtomControl {
193
202
 
194
203
  export interface IHtmlEditor {
195
204
  insertImage?: (s: HtmlEditorControl, e: Event) => Promise<string> | string;
205
+ htmlContent?: string;
196
206
  }
197
207
 
198
208
  export default function HtmlEditor(
199
209
  {
200
210
  insertImage,
201
211
  ... attributes
202
- }: any,
212
+ }: IHtmlEditor,
203
213
  ... nodes: XNode[]) {
204
214
 
205
215
  if (nodes.length === 0) {
@@ -1,12 +1,58 @@
1
+ import Bind from "@web-atoms/core/dist/core/Bind";
2
+ import { BindableProperty } from "@web-atoms/core/dist/core/BindableProperty";
3
+ import XNode from "@web-atoms/core/dist/core/XNode";
4
+ import PopupService, { PopupWindow } from "@web-atoms/core/dist/web/services/PopupService";
5
+ import FormField from "../../basic/FormField";
6
+ import type { HtmlEditorControl } from "../HtmlEditor";
1
7
  import CommandButton, { notSet } from "./CommandButton";
8
+ import HtmlCommands from "./HtmlCommands";
9
+
10
+ class ImageDialog extends PopupWindow {
11
+
12
+ @BindableProperty
13
+ public link: string;
14
+
15
+ @BindableProperty
16
+ public alt: string;
17
+
18
+ protected create(): void {
19
+ this.link = "";
20
+ this.alt = "";
21
+ this.render(<div>
22
+ <FormField label="Url">
23
+ <input value={Bind.twoWaysImmediate(() => this.link)}/>
24
+ </FormField>
25
+ <FormField label="Alt">
26
+ <input value={Bind.twoWaysImmediate(() => this.alt)}/>
27
+ </FormField>
28
+ <div class="command-bar">
29
+ <button
30
+ eventClick={() => this.viewModel.close(this.createImage())}
31
+ text="Add"/>
32
+ </div>
33
+ </div>);
34
+ }
35
+
36
+ private createImage() {
37
+ if (this.alt) {
38
+ return `<img src="${this.link}" alt="${this.alt}" />`;
39
+ }
40
+ return `<img src="${this.link}"/>`;
41
+ }
42
+ }
43
+
44
+ function showImageDialog(s: HtmlEditorControl, e: Event): Promise<string> | string {
45
+ return PopupService.showWindow<string>(e.currentTarget as HTMLElement, ImageDialog, { title: "Add Image" });
46
+ }
2
47
 
3
48
  export default function AddImage({
4
- eventInsertHtml = notSet("AddImage"),
5
- insertCommand = "insertHTML"
49
+ eventInsertHtml = showImageDialog,
50
+ insertCommand = HtmlCommands.insertImage
6
51
  }) {
7
52
  return CommandButton({
8
53
  icon: "ri-image-add-fill",
9
54
  insertCommand,
55
+ disabled: false,
10
56
  title: "Insert Image",
11
57
  eventInsertHtml
12
58
  });
@@ -9,6 +9,7 @@ import CSS from "@web-atoms/core/dist/web/styles/CSS";
9
9
  import FormField from "../../basic/FormField";
10
10
  import type { HtmlEditorControl } from "../HtmlEditor";
11
11
  import CommandButton, { notSet } from "./CommandButton";
12
+ import HtmlCommands from "./HtmlCommands";
12
13
 
13
14
  const linkTypes = [
14
15
  {
@@ -74,16 +75,16 @@ class LinkDialog extends PopupWindow {
74
75
  }
75
76
 
76
77
  function showDialog(s: HtmlEditorControl, e: Event): Promise<string> {
77
- const popupService = s.app.resolve(PopupService);
78
- return popupService.showWindow(s.element, LinkDialog);
78
+ return PopupService.showWindow(s.element, LinkDialog);
79
79
  }
80
80
 
81
81
  export default function AddLink({
82
- insertCommand = "createLink"
82
+ insertCommand = HtmlCommands.createLink
83
83
  }) {
84
84
  return CommandButton({
85
85
  icon: "ri-link-m",
86
86
  insertCommand,
87
+ disabled: false,
87
88
  eventInsertHtml: showDialog,
88
89
  title: "Create Hyper Link"
89
90
  });
@@ -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
3
  import type { HtmlEditorControl } 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,7 +33,7 @@ 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 {
36
+ function insert(callback: (s: HtmlEditorControl, e: Event) => Promise<string> | string, command: IHtmlCommand): any {
31
37
  return async (s: HtmlEditorControl, e: Event) => {
32
38
  let r = callback(s, e);
33
39
  if (typeof r !== "string") {
@@ -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: HtmlEditorControl) => 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>;
@@ -0,0 +1,78 @@
1
+ import type { HtmlEditorControl } from "../HtmlEditor";
2
+
3
+ function query(name: keyof typeof HtmlCommands): IHtmlCommand {
4
+ return {
5
+ canExecute(e: HtmlEditorControl): boolean {
6
+ return e.queryCommandState(name);
7
+ },
8
+ execute(e: HtmlEditorControl, showUI?: boolean, value?: string): boolean {
9
+ return e.executeCommand(name, showUI, value);
10
+ }
11
+ };
12
+ }
13
+
14
+ export interface IHtmlCommand {
15
+ canExecute(e: HtmlEditorControl): boolean;
16
+ execute(e: HtmlEditorControl, 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
+ }
@@ -6,16 +6,16 @@ import PopupService, { PopupWindow } from "@web-atoms/core/dist/web/services/Pop
6
6
  import CSS from "@web-atoms/core/dist/web/styles/CSS";
7
7
  import { HtmlEditorControl } 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")
12
- .minHeight(800)
13
- .minWidth(800)
13
+ .minHeight(500)
14
+ .minWidth(700)
14
15
  )
15
16
  );
16
17
 
17
18
  async function showDialog(s: HtmlEditorControl, e: Event): Promise<string> {
18
- const popupService = s.app.resolve(PopupService);
19
19
 
20
20
  class SourceDialog extends PopupWindow {
21
21
 
@@ -36,18 +36,18 @@ async function showDialog(s: HtmlEditorControl, e: Event): Promise<string> {
36
36
 
37
37
  }
38
38
 
39
- const result = await popupService.showWindow(s.element, SourceDialog);
39
+ const result = await PopupService.showWindow(s.element, SourceDialog);
40
40
  s.htmlContent = result as string;
41
41
  return null;
42
42
  }
43
43
 
44
44
  export default function Source({
45
- insertCommand = "createLink"
45
+ insertCommand = HtmlCommands.enabled
46
46
  }) {
47
47
  return CommandButton({
48
48
  icon: "ri-edit-box-fill",
49
49
  insertCommand,
50
50
  eventInsertHtml: showDialog,
51
- title: "Create Hyper Link"
51
+ title: "Edit Source Code"
52
52
  });
53
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
  }