@web-atoms/web-controls 2.6.5 → 2.6.6
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/tsconfig.tsbuildinfo +1 -1
- package/dist-esm/ArrayLike.js +14 -12
- package/dist-esm/DataAttributes.js +18 -19
- package/dist-esm/Focusable.js +10 -11
- package/dist-esm/ModuleFiles.js +43 -42
- package/dist-esm/NumberFormats.js +60 -56
- package/dist-esm/PageNavigator.js +28 -30
- package/dist-esm/animations/Animations.js +36 -33
- package/dist-esm/basic/AtomChips.js +312 -305
- package/dist-esm/basic/AtomRepeater.js +1070 -1035
- package/dist-esm/basic/AtomSuggestions.js +97 -107
- package/dist-esm/basic/AttachedPopup.js +0 -1
- package/dist-esm/basic/Button.js +45 -19
- package/dist-esm/basic/ButtonBar.js +84 -64
- package/dist-esm/basic/Calendar.js +211 -203
- package/dist-esm/basic/CheckBoxList.js +90 -70
- package/dist-esm/basic/Checkbox.js +16 -8
- package/dist-esm/basic/Chip.js +36 -12
- package/dist-esm/basic/ComboBox.js +47 -51
- package/dist-esm/basic/DataGrid.js +258 -252
- package/dist-esm/basic/DateField.js +149 -127
- package/dist-esm/basic/DropDown.js +91 -103
- package/dist-esm/basic/DropDownInput.js +78 -106
- package/dist-esm/basic/Editable.js +82 -77
- package/dist-esm/basic/Expander.js +104 -86
- package/dist-esm/basic/FilesDragDrop.js +84 -80
- package/dist-esm/basic/Form.js +80 -52
- package/dist-esm/basic/FormField.js +164 -106
- package/dist-esm/basic/IElement.js +1 -2
- package/dist-esm/basic/InlinePopup.js +263 -234
- package/dist-esm/basic/InlinePopupButton.js +99 -88
- package/dist-esm/basic/InlinePopupControl.js +24 -23
- package/dist-esm/basic/ItemPath.js +59 -60
- package/dist-esm/basic/LimitedText.js +49 -38
- package/dist-esm/basic/ListRepeater.js +13 -14
- package/dist-esm/basic/MaskedInput.js +37 -29
- package/dist-esm/basic/MaskedInputDiv.js +55 -48
- package/dist-esm/basic/MergeNode.js +64 -35
- package/dist-esm/basic/PasswordBox.js +32 -17
- package/dist-esm/basic/PinchZoomView.js +221 -199
- package/dist-esm/basic/PopupButton.js +39 -16
- package/dist-esm/basic/PopupMenu.js +3 -4
- package/dist-esm/basic/RadioButtonList.js +35 -25
- package/dist-esm/basic/RefreshLock.js +41 -42
- package/dist-esm/basic/Resizable.js +43 -33
- package/dist-esm/basic/Select.js +72 -65
- package/dist-esm/basic/SortByButton.js +41 -31
- package/dist-esm/basic/Swipe.js +91 -84
- package/dist-esm/basic/Switch.js +22 -8
- package/dist-esm/basic/TableRepeater.js +29 -33
- package/dist-esm/basic/TimeEditor.js +97 -52
- package/dist-esm/basic/TitleEditor.js +115 -95
- package/dist-esm/basic/ToggleButtonBar.js +21 -22
- package/dist-esm/basic/Tooltip.js +49 -47
- package/dist-esm/basic/TypeWriter.js +45 -42
- package/dist-esm/basic/UploadEvent.js +211 -178
- package/dist-esm/basic/ZoomView.js +229 -198
- package/dist-esm/basic/combineClasses.js +2 -3
- package/dist-esm/basic/elements/AtomPopover.js +270 -253
- package/dist-esm/basic/elements/getContainingBlock.js +34 -35
- package/dist-esm/basic/elements/relativeRect.js +40 -21
- package/dist-esm/desktop-app/DesktopApp.js +65 -80
- package/dist-esm/desktop-app/MobileDesktopApp.js +20 -23
- package/dist-esm/html-editor/AtomHtmlEditor.js +243 -268
- package/dist-esm/html-editor/HtmlEditorCommands.js +6 -4
- package/dist-esm/html-editor/InlineHtmlEditor.js +174 -166
- package/dist-esm/html-editor/RangeEditor.js +49 -51
- package/dist-esm/html-editor/commands/AddImage.js +40 -35
- package/dist-esm/html-editor/commands/AddLink.js +56 -54
- package/dist-esm/html-editor/commands/Align.js +24 -7
- package/dist-esm/html-editor/commands/AttachFile.js +23 -13
- package/dist-esm/html-editor/commands/AttachImage.js +35 -25
- package/dist-esm/html-editor/commands/Bold.js +10 -11
- package/dist-esm/html-editor/commands/ChangeColor.js +31 -107
- package/dist-esm/html-editor/commands/ChangeFont.js +42 -42
- package/dist-esm/html-editor/commands/ChangeFontSize.js +15 -5
- package/dist-esm/html-editor/commands/Command.js +34 -16
- package/dist-esm/html-editor/commands/CommandButton.js +51 -32
- package/dist-esm/html-editor/commands/Headings.js +25 -9
- package/dist-esm/html-editor/commands/HorizontalRule.js +9 -10
- package/dist-esm/html-editor/commands/HtmlCommands.js +160 -65
- package/dist-esm/html-editor/commands/IndentLess.js +10 -11
- package/dist-esm/html-editor/commands/IndentMore.js +10 -11
- package/dist-esm/html-editor/commands/Italic.js +10 -11
- package/dist-esm/html-editor/commands/NumberedList.js +10 -11
- package/dist-esm/html-editor/commands/Quote.js +10 -11
- package/dist-esm/html-editor/commands/RemoveFormat.js +10 -11
- package/dist-esm/html-editor/commands/Separator.js +5 -4
- package/dist-esm/html-editor/commands/Source.js +29 -25
- package/dist-esm/html-editor/commands/StrikeThrough.js +10 -11
- package/dist-esm/html-editor/commands/Toolbar.js +6 -4
- package/dist-esm/html-editor/commands/Underline.js +10 -11
- package/dist-esm/html-editor/commands/Unlink.js +10 -9
- package/dist-esm/html-editor/commands/UnorderedList.js +10 -11
- package/dist-esm/mobile-app/BottomPopup.js +137 -148
- package/dist-esm/mobile-app/MasterDetailPage.js +153 -152
- package/dist-esm/mobile-app/MobileApp.js +577 -569
- package/dist-esm/player/AtomVideoPlayer.js +316 -270
- package/dist-esm/player/TrackProgress.js +11 -7
- package/dist-esm/player/input-range-style.js +97 -98
- package/dist-esm/tests/app-test/AppTestApp.js +12 -15
- package/dist-esm/tests/app-test/AppTestApp.pack.js +54 -0
- package/dist-esm/tests/app-test/commands/AppCommands.js +14 -11
- package/dist-esm/tests/app-test/drawer/AppDrawer.js +4 -6
- package/dist-esm/tests/app-test/model/model.js +1 -2
- package/dist-esm/tests/app-test/pages/detail/DetailPage.js +21 -15
- package/dist-esm/tests/app-test/pages/home/HomePage.js +7 -8
- package/dist-esm/tests/app-test/pages/list/ListPage.js +79 -62
- package/dist-esm/tests/basic/PopupTest.js +9 -7
- package/dist-esm/tests/basic/TimeEditorTest.js +5 -9
- package/dist-esm/tests/basic/TimeEditorTest.pack.js +39 -0
- package/dist-esm/tests/basic/TimerTest.js +27 -37
- package/dist-esm/tests/basic/TimerTest.pack.js +40 -0
- package/dist-esm/tests/basic/basic-form/BasicForm.js +47 -27
- package/dist-esm/tests/basic/basic-form/BasicForm.pack.js +44 -0
- package/dist-esm/tests/basic/calendar/BasicCalendarTest.js +5 -9
- package/dist-esm/tests/basic/calendar/BasicCalendarTest.pack.js +53 -0
- package/dist-esm/tests/basic/chips/ChipsTest.js +25 -15
- package/dist-esm/tests/basic/chips/ChipsTest.pack.js +56 -0
- package/dist-esm/tests/basic/data-grid/DataGridTest.js +55 -60
- package/dist-esm/tests/basic/data-grid/DataGridTest.pack.js +58 -0
- package/dist-esm/tests/basic/date/DateFieldTest.js +21 -96
- package/dist-esm/tests/basic/date/DateFieldTest.pack.js +57 -0
- package/dist-esm/tests/basic/drop-down/DropDownTest.js +25 -19
- package/dist-esm/tests/basic/drop-down/DropDownTest.pack.js +52 -0
- package/dist-esm/tests/basic/drop-down-input/DropDownTest.js +32 -32
- package/dist-esm/tests/basic/drop-down-input/DropDownTest.pack.js +54 -0
- package/dist-esm/tests/basic/expander/ExpanderMenuTest.js +20 -14
- package/dist-esm/tests/basic/expander/ExpanderMenuTest.pack.js +38 -0
- package/dist-esm/tests/basic/expander/ExpanderTest.js +11 -12
- package/dist-esm/tests/basic/expander/ExpanderTest.pack.js +38 -0
- package/dist-esm/tests/basic/form2/Form2Test.js +26 -24
- package/dist-esm/tests/basic/form2/Form2Test.pack.js +46 -0
- package/dist-esm/tests/basic/limited-text/LimitedTextTest.js +14 -11
- package/dist-esm/tests/basic/limited-text/LimitedTextTest.pack.js +38 -0
- package/dist-esm/tests/basic/pinch-zoom/PinchZoomViewTest.js +14 -14
- package/dist-esm/tests/basic/pinch-zoom/PinchZoomViewTest.pack.js +38 -0
- package/dist-esm/tests/basic/repeater/DragDropRepater.js +30 -12
- package/dist-esm/tests/basic/repeater/DragDropRepater.pack.js +51 -0
- package/dist-esm/tests/basic/repeater/RepeaterTest.js +45 -35
- package/dist-esm/tests/basic/repeater/RepeaterTest.pack.js +52 -0
- package/dist-esm/tests/basic/swipe/SwipeTest.js +13 -13
- package/dist-esm/tests/basic/swipe/SwipeTest.pack.js +52 -0
- package/dist-esm/tests/basic/switch-test/SwitchTest.js +8 -10
- package/dist-esm/tests/basic/switch-test/SwitchTest.pack.js +38 -0
- package/dist-esm/tests/basic/title-editor/TitleEditorTest.js +8 -9
- package/dist-esm/tests/basic/title-editor/TitleEditorTest.pack.js +38 -0
- package/dist-esm/tests/basic/tooltip/TooltipTest.js +30 -24
- package/dist-esm/tests/basic/tooltip/TooltipTest.pack.js +52 -0
- package/dist-esm/tests/basic/typewriter/TypeWriter.js +10 -9
- package/dist-esm/tests/basic/typewriter/TypeWriter.pack.js +39 -0
- package/dist-esm/tests/basic/video/AtomVideoTest.js +13 -10
- package/dist-esm/tests/basic/video/AtomVideoTest.pack.js +38 -0
- package/dist-esm/tests/basic/zoom/ZoomViewTest.js +13 -13
- package/dist-esm/tests/basic/zoom/ZoomViewTest.pack.js +38 -0
- package/dist-esm/tests/check-box-list/CheckBoxListSample.js +13 -12
- package/dist-esm/tests/check-box-list/CheckBoxListSample.pack.js +52 -0
- package/dist-esm/tests/data-grid/GridTestViewModel.js +203 -227
- package/dist-esm/tests/form/CustomHelp.js +6 -9
- package/dist-esm/tests/form/FormViewModel.js +21 -28
- package/dist-esm/tests/html-editor/HtmlEditorTest.js +7 -37
- package/dist-esm/tests/html-editor/HtmlEditorTest.pack.js +83 -0
- package/dist-esm/tests/html-editor/InlineHtmlEdiorTest.js +9 -38
- package/dist-esm/tests/html-editor/InlineHtmlEdiorTest.pack.js +85 -0
- package/dist-esm/tests/mask/MaskedInputTest.js +11 -12
- package/dist-esm/tests/mask/MaskedInputTest.pack.js +38 -0
- package/dist-esm/tests/mobile-app/DesktopAppTest.js +8 -9
- package/dist-esm/tests/mobile-app/DesktopAppTest.pack.js +60 -0
- package/dist-esm/tests/mobile-app/MobileAppTest.js +64 -53
- package/dist-esm/tests/mobile-app/MobileAppTest.pack.js +55 -0
- package/dist-esm/tests/pop-over/PopOverTest.js +37 -77
- package/dist-esm/tests/switch/SwitchTest.js +9 -8
- package/dist-esm/tests/toggle-view/ToggleViewTest.js +15 -22
- package/dist-esm/tests/toggle-view/ToggleViewTest.pack.js +45 -0
- package/dist-esm/toggle-view/AtomToggleView.js +77 -73
- package/dist-esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -2,89 +2,93 @@ const supportsFileSystemAccessAPI = "getAsFileSystemHandle" in DataTransferItem.
|
|
|
2
2
|
const supportsWebkitGetAsEntry = "webkitGetAsEntry" in DataTransferItem.prototype;
|
|
3
3
|
import { StringHelper } from "@web-atoms/core/dist/core/StringHelper.js";
|
|
4
4
|
import { AtomControl } from "@web-atoms/core/dist/web/controls/AtomControl.js";
|
|
5
|
-
import
|
|
6
|
-
const dragEnter =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
ESMPack.installStyleSheet(import.meta.resolve("./FilesDragDrop.global.css"));
|
|
6
|
+
const dragEnter = e => {
|
|
7
|
+
if (!e.dataTransfer) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
e.currentTarget.setAttribute("data-drop-enabled", "1");
|
|
11
11
|
};
|
|
12
|
-
const dragOver =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const dragOver = e => {
|
|
13
|
+
if (!e.dataTransfer) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
e.preventDefault();
|
|
17
17
|
};
|
|
18
|
-
const dragLeave =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const dragLeave = e => {
|
|
19
|
+
if (!e.dataTransfer) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
e.currentTarget.removeAttribute("data-drop-enabled");
|
|
23
23
|
};
|
|
24
|
-
const eventDrop =
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const eventDrop = e => {
|
|
25
|
+
if (!e.dataTransfer) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
const currentTarget = e.currentTarget;
|
|
30
|
+
currentTarget.removeAttribute("data-drop-enabled");
|
|
31
|
+
const uploadEvent = StringHelper.fromHyphenToCamel(currentTarget.getAttribute("data-upload-event"));
|
|
32
|
+
const uploadRequested = StringHelper.fromHyphenToCamel(currentTarget.getAttribute("data-upload-requested"));
|
|
33
|
+
const extra = currentTarget.getAttribute("data-extra");
|
|
34
|
+
const convert = currentTarget.getAttribute("data-convert") === "true";
|
|
35
|
+
const maxSize = parseInt(currentTarget.getAttribute("data-max-size") || "0", 10);
|
|
36
|
+
const fileHandlesPromises = [...e.dataTransfer.items].filter(item => item.kind === "file").map(item => supportsFileSystemAccessAPI ? item.getAsFileSystemHandle() : supportsWebkitGetAsEntry ? item.webkitGetAsEntry() : item.getAsFile());
|
|
37
|
+
const files = [];
|
|
38
|
+
const getFiles = async (dir, parent = dir.name) => {
|
|
39
|
+
const all = [];
|
|
40
|
+
for await (const [name, handle] of dir.entries()) {
|
|
41
|
+
const path = `${parent}/${handle.name}`;
|
|
42
|
+
if (handle.kind === "directory" || handle.isDirectory) {
|
|
43
|
+
all.push(...(await getFiles(handle, path)));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const file = await handle.getFile();
|
|
47
|
+
Object.defineProperty(file, "webkitRelativePath", {
|
|
48
|
+
value: path
|
|
49
|
+
});
|
|
50
|
+
all.push(file);
|
|
51
|
+
}
|
|
52
|
+
return all;
|
|
53
|
+
};
|
|
54
|
+
const control = AtomControl.from(e.currentTarget);
|
|
55
|
+
control.app.runAsync(async () => {
|
|
56
|
+
for await (const handle of fileHandlesPromises) {
|
|
57
|
+
if (handle.kind === "directory" || handle.isDirectory) {
|
|
58
|
+
files.push(...(await getFiles(handle)));
|
|
59
|
+
} else {
|
|
60
|
+
files.push(await handle.getFile());
|
|
61
|
+
}
|
|
27
62
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const convert = currentTarget.getAttribute("data-convert") === "true";
|
|
35
|
-
const maxSize = parseInt(currentTarget.getAttribute("data-max-size") || "0", 10);
|
|
36
|
-
const fileHandlesPromises = [...e.dataTransfer.items]
|
|
37
|
-
.filter((item) => item.kind === "file")
|
|
38
|
-
.map((item) => supportsFileSystemAccessAPI
|
|
39
|
-
? item.getAsFileSystemHandle()
|
|
40
|
-
: supportsWebkitGetAsEntry
|
|
41
|
-
? item.webkitGetAsEntry()
|
|
42
|
-
: item.getAsFile());
|
|
43
|
-
const files = [];
|
|
44
|
-
const getFiles = async (dir, parent = dir.name) => {
|
|
45
|
-
const all = [];
|
|
46
|
-
for await (const [name, handle] of dir.entries()) {
|
|
47
|
-
const path = `${parent}/${handle.name}`;
|
|
48
|
-
if (handle.kind === "directory" || handle.isDirectory) {
|
|
49
|
-
all.push(...(await getFiles(handle, path)));
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const file = await handle.getFile();
|
|
53
|
-
Object.defineProperty(file, "webkitRelativePath", { value: path });
|
|
54
|
-
all.push(file);
|
|
55
|
-
}
|
|
56
|
-
return all;
|
|
63
|
+
const detail = {
|
|
64
|
+
files,
|
|
65
|
+
extra,
|
|
66
|
+
convert,
|
|
67
|
+
maxSize,
|
|
68
|
+
uploadEvent
|
|
57
69
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
else {
|
|
65
|
-
files.push(await handle.getFile());
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const detail = {
|
|
69
|
-
files,
|
|
70
|
-
extra,
|
|
71
|
-
convert,
|
|
72
|
-
maxSize,
|
|
73
|
-
uploadEvent
|
|
74
|
-
};
|
|
75
|
-
currentTarget.dispatchEvent(new CustomEvent(uploadRequested, { detail, bubbles: true, cancelable: true }));
|
|
76
|
-
});
|
|
70
|
+
currentTarget.dispatchEvent(new CustomEvent(uploadRequested, {
|
|
71
|
+
detail,
|
|
72
|
+
bubbles: true,
|
|
73
|
+
cancelable: true
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
77
76
|
};
|
|
78
|
-
export const FilesDragDrop = ({
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
77
|
+
export const FilesDragDrop = ({
|
|
78
|
+
uploadEvent = "files-available",
|
|
79
|
+
uploadRequested = "upload-requested",
|
|
80
|
+
convert = false,
|
|
81
|
+
maxSize = 50 * 1024 * 1024,
|
|
82
|
+
extra = ""
|
|
83
|
+
}) => ({
|
|
84
|
+
"data-extra": extra,
|
|
85
|
+
"data-drag-drop": "1",
|
|
86
|
+
"data-convert": convert,
|
|
87
|
+
"data-upload-event": uploadEvent,
|
|
88
|
+
"data-upload-requested": uploadRequested,
|
|
89
|
+
"data-max-size": maxSize,
|
|
90
|
+
"event-dragenter": dragEnter,
|
|
91
|
+
"event-dragleave": dragLeave,
|
|
92
|
+
"event-dragover": dragOver,
|
|
93
|
+
"event-drop": eventDrop
|
|
94
|
+
});
|
package/dist-esm/basic/Form.js
CHANGED
|
@@ -1,61 +1,89 @@
|
|
|
1
1
|
import Bind from "@web-atoms/core/dist/core/Bind.js";
|
|
2
2
|
import { StringHelper } from "@web-atoms/core/dist/core/StringHelper.js";
|
|
3
3
|
import XNode from "@web-atoms/core/dist/core/XNode.js";
|
|
4
|
-
import
|
|
5
|
-
const checkClick =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
4
|
+
ESMPack.installStyleSheet(import.meta.resolve("../styles/form.global.css"));
|
|
5
|
+
const checkClick = e => {
|
|
6
|
+
const form = e.currentTarget;
|
|
7
|
+
const element = e.target;
|
|
8
|
+
let target = element;
|
|
9
|
+
while (target.tagName !== "BUTTON") {
|
|
10
|
+
target = target.parentElement;
|
|
11
|
+
if (!target || target === form) {
|
|
12
|
+
return;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
}
|
|
15
|
+
const submitEvent = target.getAttribute("data-submit-event");
|
|
16
|
+
if (!submitEvent) {
|
|
17
|
+
if (!/submit/i.test(target.getAttribute("type") ?? target.getAttribute("data-type"))) {
|
|
18
|
+
return;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
}
|
|
21
|
+
form.setAttribute("data-show-validation", "true");
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
const all = Array.from(form.getElementsByClassName("field-error"));
|
|
24
|
+
for (const iterator of all) {
|
|
25
|
+
if (iterator.textContent) {
|
|
26
|
+
form.setAttribute("data-valid", "false");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
form.setAttribute("data-valid", "true");
|
|
31
|
+
const eventName = StringHelper.fromHyphenToCamel(submitEvent ?? form.getAttribute("data-submit-event"));
|
|
32
|
+
target.dispatchEvent(new CustomEvent(eventName, {
|
|
33
|
+
bubbles: true,
|
|
34
|
+
cancelable: true
|
|
35
|
+
}));
|
|
36
|
+
}, 100);
|
|
34
37
|
};
|
|
35
|
-
export default function Form({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
export default function Form({
|
|
39
|
+
"data-submit-event": submitEvent = "submitForm",
|
|
40
|
+
"data-show-validation": showValidation = "false",
|
|
41
|
+
"data-error-message": errorMessage = "Please fix all validations",
|
|
42
|
+
...a
|
|
43
|
+
}, ...nodes) {
|
|
44
|
+
return XNode.create("div", {
|
|
45
|
+
...a,
|
|
46
|
+
"data-submit-event": submitEvent,
|
|
47
|
+
"data-form": "form",
|
|
48
|
+
"data-valid": "true",
|
|
49
|
+
"data-show-validation": showValidation,
|
|
50
|
+
"data-error-message": errorMessage,
|
|
51
|
+
"event-click": checkClick
|
|
52
|
+
}, XNode.create("div", {
|
|
53
|
+
class: "error-message",
|
|
54
|
+
text: errorMessage
|
|
55
|
+
}), ...nodes);
|
|
39
56
|
}
|
|
40
|
-
export const BindError = ({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return message(msg, element.parentElement.querySelector(`[data-element=label]`)?.textContent || "This field ");
|
|
57
|
+
export const BindError = ({
|
|
58
|
+
value,
|
|
59
|
+
message = (v, l) => `${l} is invalid`,
|
|
60
|
+
isValid = (v, e) => !!v
|
|
61
|
+
}) => {
|
|
62
|
+
function f2(sender, element) {
|
|
63
|
+
const isRequired = element.parentElement.querySelector(`[data-required]`);
|
|
64
|
+
const msg = value.call(this, sender);
|
|
65
|
+
if (!msg) {
|
|
66
|
+
if (!isRequired) {
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
53
69
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
if (isValid(msg, element)) {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
return message(msg, element.parentElement.querySelector(`[data-element=label]`)?.textContent || "This field ");
|
|
74
|
+
}
|
|
75
|
+
;
|
|
76
|
+
f2.toString = () => value.toString();
|
|
77
|
+
return Bind.oneWay(f2);
|
|
60
78
|
};
|
|
61
|
-
|
|
79
|
+
export const BindEmailError = ({
|
|
80
|
+
value,
|
|
81
|
+
message = (v, l) => `${l} is not a valid email address`,
|
|
82
|
+
isValid = (v, e) => /[^\@]+\@[^\@]+\.[^\@]+/i.test(v)
|
|
83
|
+
}) => {
|
|
84
|
+
return BindError({
|
|
85
|
+
value,
|
|
86
|
+
message,
|
|
87
|
+
isValid
|
|
88
|
+
});
|
|
89
|
+
};
|
|
@@ -1,122 +1,180 @@
|
|
|
1
1
|
import Bind from "@web-atoms/core/dist/core/Bind.js";
|
|
2
2
|
import XNode from "@web-atoms/core/dist/core/XNode.js";
|
|
3
3
|
import PopupService, { PopupWindow } from "@web-atoms/core/dist/web/services/PopupService.js";
|
|
4
|
-
import
|
|
5
|
-
document.body.addEventListener("click",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
label = label.parentElement;
|
|
12
|
-
if (label === document.body) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (!label) {
|
|
17
|
-
return;
|
|
4
|
+
ESMPack.installStyleSheet(import.meta.resolve("./styles/form-field.global.css"));
|
|
5
|
+
document.body.addEventListener("click", e => {
|
|
6
|
+
let label = e.target;
|
|
7
|
+
while (label && label.tagName !== "LABEL") {
|
|
8
|
+
if (label.getAttribute("data-element") === "label") {
|
|
9
|
+
break;
|
|
18
10
|
}
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
11
|
+
label = label.parentElement;
|
|
12
|
+
if (label === document.body) {
|
|
13
|
+
return;
|
|
22
14
|
}
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
}
|
|
16
|
+
if (!label) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const formField = label.parentElement;
|
|
20
|
+
if (!formField.hasAttribute("data-wa-form-field")) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const selectable = formField.querySelector("select,input,textarea");
|
|
24
|
+
selectable?.focus?.();
|
|
25
25
|
});
|
|
26
|
-
document.addEventListener("focusin",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
target = target.parentElement;
|
|
26
|
+
document.addEventListener("focusin", e => {
|
|
27
|
+
let target = e.target;
|
|
28
|
+
while (target) {
|
|
29
|
+
if (target.getAttribute("data-wa-form-field") === "wa-form-field") {
|
|
30
|
+
target.setAttribute("data-focused", "true");
|
|
31
|
+
break;
|
|
34
32
|
}
|
|
33
|
+
target = target.parentElement;
|
|
34
|
+
}
|
|
35
35
|
});
|
|
36
|
-
document.addEventListener("focusout",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
target = target.parentElement;
|
|
36
|
+
document.addEventListener("focusout", e => {
|
|
37
|
+
let target = e.target;
|
|
38
|
+
while (target) {
|
|
39
|
+
if (target.getAttribute("data-wa-form-field") === "wa-form-field") {
|
|
40
|
+
target.removeAttribute("data-focused");
|
|
41
|
+
break;
|
|
44
42
|
}
|
|
43
|
+
target = target.parentElement;
|
|
44
|
+
}
|
|
45
45
|
});
|
|
46
|
-
export default function FormField({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
46
|
+
export default function FormField({
|
|
47
|
+
label,
|
|
48
|
+
required,
|
|
49
|
+
error,
|
|
50
|
+
helpIcon = "fas fa-question-circle",
|
|
51
|
+
help,
|
|
52
|
+
helpEventClick,
|
|
53
|
+
helpTitle,
|
|
54
|
+
border = false,
|
|
55
|
+
...others
|
|
56
|
+
}, node) {
|
|
57
|
+
if (node) {
|
|
58
|
+
const na = node.attributes ??= {};
|
|
59
|
+
na["data-element"] = "content";
|
|
60
|
+
}
|
|
61
|
+
if (!helpEventClick && help) {
|
|
62
|
+
helpEventClick = Bind.event((s, e) => {
|
|
63
|
+
const app = s.app;
|
|
64
|
+
if (typeof help === "string" || help instanceof XNode) {
|
|
65
|
+
PopupService.notify(help).catch(console.error);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
class HelpPopup extends PopupWindow {
|
|
69
|
+
create() {
|
|
70
|
+
this.render(XNode.create("div", {
|
|
71
|
+
"data-form-field-help": "help-window"
|
|
72
|
+
}, help));
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
}
|
|
75
|
+
HelpPopup.showWindow({
|
|
76
|
+
title: helpTitle ?? "Help",
|
|
77
|
+
modal: true
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
let labelIsNode = false;
|
|
82
|
+
if (label) {
|
|
83
|
+
if (label instanceof XNode) {
|
|
84
|
+
const la = label.attributes ??= {};
|
|
85
|
+
la["data-element"] = "label";
|
|
86
|
+
labelIsNode = true;
|
|
87
|
+
} else {
|
|
88
|
+
if (node) {
|
|
89
|
+
if (!(node.attributes?.ariaLabel || node.attributes?.["aria-label"])) {
|
|
90
|
+
(node.attributes ??= {})["aria-label"] = label;
|
|
79
91
|
}
|
|
92
|
+
}
|
|
80
93
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
}
|
|
95
|
+
return XNode.create("div", {
|
|
96
|
+
"data-wa-form-field": "wa-form-field",
|
|
97
|
+
"data-border": border,
|
|
98
|
+
...others
|
|
99
|
+
}, label && (labelIsNode ? label : XNode.create("label", {
|
|
100
|
+
"data-element": "label",
|
|
101
|
+
text: label
|
|
102
|
+
})), required && XNode.create("span", {
|
|
103
|
+
"data-required": "required",
|
|
104
|
+
class: required,
|
|
105
|
+
text: "*"
|
|
106
|
+
}), border && XNode.create("i", {
|
|
107
|
+
"data-border": "border"
|
|
108
|
+
}), node, help && XNode.create("i", {
|
|
109
|
+
"data-help": "help",
|
|
110
|
+
class: helpIcon,
|
|
111
|
+
title: helpTitle,
|
|
112
|
+
eventClick: helpEventClick
|
|
113
|
+
}), XNode.create("div", {
|
|
114
|
+
class: "field-error",
|
|
115
|
+
text: error
|
|
116
|
+
}));
|
|
88
117
|
}
|
|
89
|
-
export function HorizontalFormField({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
118
|
+
export function HorizontalFormField({
|
|
119
|
+
label,
|
|
120
|
+
required,
|
|
121
|
+
error,
|
|
122
|
+
helpIcon = "fas fa-question-circle",
|
|
123
|
+
help,
|
|
124
|
+
helpEventClick,
|
|
125
|
+
helpTitle,
|
|
126
|
+
border = false,
|
|
127
|
+
...others
|
|
128
|
+
}, node) {
|
|
129
|
+
if (node) {
|
|
130
|
+
const na = node.attributes ??= {};
|
|
131
|
+
na["data-content"] = "content";
|
|
132
|
+
}
|
|
133
|
+
if (!helpEventClick && help) {
|
|
134
|
+
helpEventClick = Bind.event((s, e) => {
|
|
135
|
+
const app = s.app;
|
|
136
|
+
if (typeof help === "string" || help instanceof XNode) {
|
|
137
|
+
PopupService.notify(help).catch(console.error);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
class HelpPopup extends PopupWindow {
|
|
141
|
+
create() {
|
|
142
|
+
this.render(XNode.create("div", {
|
|
143
|
+
"data-form-field-help": "help-window"
|
|
144
|
+
}, help));
|
|
112
145
|
}
|
|
146
|
+
}
|
|
147
|
+
HelpPopup.showWindow({
|
|
148
|
+
title: helpTitle ?? "Help"
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (node) {
|
|
153
|
+
if (!(node.attributes?.ariaLabel || node.attributes?.["aria-label"])) {
|
|
154
|
+
(node.attributes ??= {})["aria-label"] = label;
|
|
113
155
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
156
|
+
}
|
|
157
|
+
return XNode.create("div", {
|
|
158
|
+
"data-wa-form-field": "wa-form-field",
|
|
159
|
+
"data-layout": "horizontal",
|
|
160
|
+
"data-border": border,
|
|
161
|
+
...others
|
|
162
|
+
}, label && XNode.create("label", {
|
|
163
|
+
class: "label",
|
|
164
|
+
text: label
|
|
165
|
+
}), required && XNode.create("span", {
|
|
166
|
+
"data-required": "required",
|
|
167
|
+
class: required,
|
|
168
|
+
text: "*"
|
|
169
|
+
}), border && XNode.create("i", {
|
|
170
|
+
"data-border": "border"
|
|
171
|
+
}), node, help && XNode.create("i", {
|
|
172
|
+
"data-help": "help",
|
|
173
|
+
class: helpIcon,
|
|
174
|
+
title: helpTitle,
|
|
175
|
+
eventClick: helpEventClick
|
|
176
|
+
}), XNode.create("div", {
|
|
177
|
+
class: "field-error",
|
|
178
|
+
text: error
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=IElement.js.map
|
|
1
|
+
export {};
|