@web-atoms/web-controls 2.6.5 → 2.6.7

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 (185) hide show
  1. package/dist/html-editor/InlineHtmlEditor.d.ts +1 -1
  2. package/dist/html-editor/InlineHtmlEditor.d.ts.map +1 -1
  3. package/dist/html-editor/InlineHtmlEditor.js +2 -2
  4. package/dist/html-editor/InlineHtmlEditor.js.map +1 -1
  5. package/dist/tsconfig.tsbuildinfo +1 -1
  6. package/dist-esm/ArrayLike.js +14 -12
  7. package/dist-esm/DataAttributes.js +18 -19
  8. package/dist-esm/Focusable.js +10 -11
  9. package/dist-esm/ModuleFiles.js +43 -42
  10. package/dist-esm/NumberFormats.js +60 -56
  11. package/dist-esm/PageNavigator.js +28 -30
  12. package/dist-esm/animations/Animations.js +36 -33
  13. package/dist-esm/basic/AtomChips.js +312 -305
  14. package/dist-esm/basic/AtomRepeater.js +1070 -1035
  15. package/dist-esm/basic/AtomSuggestions.js +97 -107
  16. package/dist-esm/basic/AttachedPopup.js +0 -1
  17. package/dist-esm/basic/Button.js +45 -19
  18. package/dist-esm/basic/ButtonBar.js +84 -64
  19. package/dist-esm/basic/Calendar.js +211 -203
  20. package/dist-esm/basic/CheckBoxList.js +90 -70
  21. package/dist-esm/basic/Checkbox.js +16 -8
  22. package/dist-esm/basic/Chip.js +36 -12
  23. package/dist-esm/basic/ComboBox.js +47 -51
  24. package/dist-esm/basic/DataGrid.js +258 -252
  25. package/dist-esm/basic/DateField.js +149 -127
  26. package/dist-esm/basic/DropDown.js +91 -103
  27. package/dist-esm/basic/DropDownInput.js +78 -106
  28. package/dist-esm/basic/Editable.js +82 -77
  29. package/dist-esm/basic/Expander.js +104 -86
  30. package/dist-esm/basic/FilesDragDrop.js +84 -80
  31. package/dist-esm/basic/Form.js +80 -52
  32. package/dist-esm/basic/FormField.js +164 -106
  33. package/dist-esm/basic/IElement.js +1 -2
  34. package/dist-esm/basic/InlinePopup.js +263 -234
  35. package/dist-esm/basic/InlinePopupButton.js +99 -88
  36. package/dist-esm/basic/InlinePopupControl.js +24 -23
  37. package/dist-esm/basic/ItemPath.js +59 -60
  38. package/dist-esm/basic/LimitedText.js +49 -38
  39. package/dist-esm/basic/ListRepeater.js +13 -14
  40. package/dist-esm/basic/MaskedInput.js +37 -29
  41. package/dist-esm/basic/MaskedInputDiv.js +55 -48
  42. package/dist-esm/basic/MergeNode.js +64 -35
  43. package/dist-esm/basic/PasswordBox.js +32 -17
  44. package/dist-esm/basic/PinchZoomView.js +221 -199
  45. package/dist-esm/basic/PopupButton.js +39 -16
  46. package/dist-esm/basic/PopupMenu.js +3 -4
  47. package/dist-esm/basic/RadioButtonList.js +35 -25
  48. package/dist-esm/basic/RefreshLock.js +41 -42
  49. package/dist-esm/basic/Resizable.js +43 -33
  50. package/dist-esm/basic/Select.js +72 -65
  51. package/dist-esm/basic/SortByButton.js +41 -31
  52. package/dist-esm/basic/Swipe.js +91 -84
  53. package/dist-esm/basic/Switch.js +22 -8
  54. package/dist-esm/basic/TableRepeater.js +29 -33
  55. package/dist-esm/basic/TimeEditor.js +97 -52
  56. package/dist-esm/basic/TitleEditor.js +115 -95
  57. package/dist-esm/basic/ToggleButtonBar.js +21 -22
  58. package/dist-esm/basic/Tooltip.js +49 -47
  59. package/dist-esm/basic/TypeWriter.js +45 -42
  60. package/dist-esm/basic/UploadEvent.js +211 -178
  61. package/dist-esm/basic/ZoomView.js +229 -198
  62. package/dist-esm/basic/combineClasses.js +2 -3
  63. package/dist-esm/basic/elements/AtomPopover.js +270 -253
  64. package/dist-esm/basic/elements/getContainingBlock.js +34 -35
  65. package/dist-esm/basic/elements/relativeRect.js +40 -21
  66. package/dist-esm/desktop-app/DesktopApp.js +65 -80
  67. package/dist-esm/desktop-app/MobileDesktopApp.js +20 -23
  68. package/dist-esm/html-editor/AtomHtmlEditor.js +243 -268
  69. package/dist-esm/html-editor/HtmlEditorCommands.js +6 -4
  70. package/dist-esm/html-editor/InlineHtmlEditor.d.ts +1 -1
  71. package/dist-esm/html-editor/InlineHtmlEditor.d.ts.map +1 -1
  72. package/dist-esm/html-editor/InlineHtmlEditor.js +175 -167
  73. package/dist-esm/html-editor/InlineHtmlEditor.js.map +1 -1
  74. package/dist-esm/html-editor/RangeEditor.js +49 -51
  75. package/dist-esm/html-editor/commands/AddImage.js +40 -35
  76. package/dist-esm/html-editor/commands/AddLink.js +56 -54
  77. package/dist-esm/html-editor/commands/Align.js +24 -7
  78. package/dist-esm/html-editor/commands/AttachFile.js +23 -13
  79. package/dist-esm/html-editor/commands/AttachImage.js +35 -25
  80. package/dist-esm/html-editor/commands/Bold.js +10 -11
  81. package/dist-esm/html-editor/commands/ChangeColor.js +31 -107
  82. package/dist-esm/html-editor/commands/ChangeFont.js +42 -42
  83. package/dist-esm/html-editor/commands/ChangeFontSize.js +15 -5
  84. package/dist-esm/html-editor/commands/Command.js +34 -16
  85. package/dist-esm/html-editor/commands/CommandButton.js +51 -32
  86. package/dist-esm/html-editor/commands/Headings.js +25 -9
  87. package/dist-esm/html-editor/commands/HorizontalRule.js +9 -10
  88. package/dist-esm/html-editor/commands/HtmlCommands.js +160 -65
  89. package/dist-esm/html-editor/commands/IndentLess.js +10 -11
  90. package/dist-esm/html-editor/commands/IndentMore.js +10 -11
  91. package/dist-esm/html-editor/commands/Italic.js +10 -11
  92. package/dist-esm/html-editor/commands/NumberedList.js +10 -11
  93. package/dist-esm/html-editor/commands/Quote.js +10 -11
  94. package/dist-esm/html-editor/commands/RemoveFormat.js +10 -11
  95. package/dist-esm/html-editor/commands/Separator.js +5 -4
  96. package/dist-esm/html-editor/commands/Source.js +29 -25
  97. package/dist-esm/html-editor/commands/StrikeThrough.js +10 -11
  98. package/dist-esm/html-editor/commands/Toolbar.js +6 -4
  99. package/dist-esm/html-editor/commands/Underline.js +10 -11
  100. package/dist-esm/html-editor/commands/Unlink.js +10 -9
  101. package/dist-esm/html-editor/commands/UnorderedList.js +10 -11
  102. package/dist-esm/mobile-app/BottomPopup.js +137 -148
  103. package/dist-esm/mobile-app/MasterDetailPage.js +153 -152
  104. package/dist-esm/mobile-app/MobileApp.js +577 -569
  105. package/dist-esm/player/AtomVideoPlayer.js +316 -270
  106. package/dist-esm/player/TrackProgress.js +11 -7
  107. package/dist-esm/player/input-range-style.js +97 -98
  108. package/dist-esm/tests/app-test/AppTestApp.js +12 -15
  109. package/dist-esm/tests/app-test/AppTestApp.pack.js +54 -0
  110. package/dist-esm/tests/app-test/commands/AppCommands.js +14 -11
  111. package/dist-esm/tests/app-test/drawer/AppDrawer.js +4 -6
  112. package/dist-esm/tests/app-test/model/model.js +1 -2
  113. package/dist-esm/tests/app-test/pages/detail/DetailPage.js +21 -15
  114. package/dist-esm/tests/app-test/pages/home/HomePage.js +7 -8
  115. package/dist-esm/tests/app-test/pages/list/ListPage.js +79 -62
  116. package/dist-esm/tests/basic/PopupTest.js +9 -7
  117. package/dist-esm/tests/basic/TimeEditorTest.js +5 -9
  118. package/dist-esm/tests/basic/TimeEditorTest.pack.js +39 -0
  119. package/dist-esm/tests/basic/TimerTest.js +27 -37
  120. package/dist-esm/tests/basic/TimerTest.pack.js +40 -0
  121. package/dist-esm/tests/basic/basic-form/BasicForm.js +47 -27
  122. package/dist-esm/tests/basic/basic-form/BasicForm.pack.js +44 -0
  123. package/dist-esm/tests/basic/calendar/BasicCalendarTest.js +5 -9
  124. package/dist-esm/tests/basic/calendar/BasicCalendarTest.pack.js +53 -0
  125. package/dist-esm/tests/basic/chips/ChipsTest.js +25 -15
  126. package/dist-esm/tests/basic/chips/ChipsTest.pack.js +56 -0
  127. package/dist-esm/tests/basic/data-grid/DataGridTest.js +55 -60
  128. package/dist-esm/tests/basic/data-grid/DataGridTest.pack.js +58 -0
  129. package/dist-esm/tests/basic/date/DateFieldTest.js +21 -96
  130. package/dist-esm/tests/basic/date/DateFieldTest.pack.js +57 -0
  131. package/dist-esm/tests/basic/drop-down/DropDownTest.js +25 -19
  132. package/dist-esm/tests/basic/drop-down/DropDownTest.pack.js +52 -0
  133. package/dist-esm/tests/basic/drop-down-input/DropDownTest.js +32 -32
  134. package/dist-esm/tests/basic/drop-down-input/DropDownTest.pack.js +54 -0
  135. package/dist-esm/tests/basic/expander/ExpanderMenuTest.js +20 -14
  136. package/dist-esm/tests/basic/expander/ExpanderMenuTest.pack.js +38 -0
  137. package/dist-esm/tests/basic/expander/ExpanderTest.js +11 -12
  138. package/dist-esm/tests/basic/expander/ExpanderTest.pack.js +38 -0
  139. package/dist-esm/tests/basic/form2/Form2Test.js +26 -24
  140. package/dist-esm/tests/basic/form2/Form2Test.pack.js +46 -0
  141. package/dist-esm/tests/basic/limited-text/LimitedTextTest.js +14 -11
  142. package/dist-esm/tests/basic/limited-text/LimitedTextTest.pack.js +38 -0
  143. package/dist-esm/tests/basic/pinch-zoom/PinchZoomViewTest.js +14 -14
  144. package/dist-esm/tests/basic/pinch-zoom/PinchZoomViewTest.pack.js +38 -0
  145. package/dist-esm/tests/basic/repeater/DragDropRepater.js +30 -12
  146. package/dist-esm/tests/basic/repeater/DragDropRepater.pack.js +51 -0
  147. package/dist-esm/tests/basic/repeater/RepeaterTest.js +45 -35
  148. package/dist-esm/tests/basic/repeater/RepeaterTest.pack.js +52 -0
  149. package/dist-esm/tests/basic/swipe/SwipeTest.js +13 -13
  150. package/dist-esm/tests/basic/swipe/SwipeTest.pack.js +52 -0
  151. package/dist-esm/tests/basic/switch-test/SwitchTest.js +8 -10
  152. package/dist-esm/tests/basic/switch-test/SwitchTest.pack.js +38 -0
  153. package/dist-esm/tests/basic/title-editor/TitleEditorTest.js +8 -9
  154. package/dist-esm/tests/basic/title-editor/TitleEditorTest.pack.js +38 -0
  155. package/dist-esm/tests/basic/tooltip/TooltipTest.js +30 -24
  156. package/dist-esm/tests/basic/tooltip/TooltipTest.pack.js +52 -0
  157. package/dist-esm/tests/basic/typewriter/TypeWriter.js +10 -9
  158. package/dist-esm/tests/basic/typewriter/TypeWriter.pack.js +39 -0
  159. package/dist-esm/tests/basic/video/AtomVideoTest.js +13 -10
  160. package/dist-esm/tests/basic/video/AtomVideoTest.pack.js +38 -0
  161. package/dist-esm/tests/basic/zoom/ZoomViewTest.js +13 -13
  162. package/dist-esm/tests/basic/zoom/ZoomViewTest.pack.js +38 -0
  163. package/dist-esm/tests/check-box-list/CheckBoxListSample.js +13 -12
  164. package/dist-esm/tests/check-box-list/CheckBoxListSample.pack.js +52 -0
  165. package/dist-esm/tests/data-grid/GridTestViewModel.js +203 -227
  166. package/dist-esm/tests/form/CustomHelp.js +6 -9
  167. package/dist-esm/tests/form/FormViewModel.js +21 -28
  168. package/dist-esm/tests/html-editor/HtmlEditorTest.js +7 -37
  169. package/dist-esm/tests/html-editor/HtmlEditorTest.pack.js +83 -0
  170. package/dist-esm/tests/html-editor/InlineHtmlEdiorTest.js +9 -38
  171. package/dist-esm/tests/html-editor/InlineHtmlEdiorTest.pack.js +85 -0
  172. package/dist-esm/tests/mask/MaskedInputTest.js +11 -12
  173. package/dist-esm/tests/mask/MaskedInputTest.pack.js +38 -0
  174. package/dist-esm/tests/mobile-app/DesktopAppTest.js +8 -9
  175. package/dist-esm/tests/mobile-app/DesktopAppTest.pack.js +60 -0
  176. package/dist-esm/tests/mobile-app/MobileAppTest.js +64 -53
  177. package/dist-esm/tests/mobile-app/MobileAppTest.pack.js +55 -0
  178. package/dist-esm/tests/pop-over/PopOverTest.js +37 -77
  179. package/dist-esm/tests/switch/SwitchTest.js +9 -8
  180. package/dist-esm/tests/toggle-view/ToggleViewTest.js +15 -22
  181. package/dist-esm/tests/toggle-view/ToggleViewTest.pack.js +45 -0
  182. package/dist-esm/toggle-view/AtomToggleView.js +77 -73
  183. package/dist-esm/tsconfig.esm.tsbuildinfo +1 -1
  184. package/package.json +3 -3
  185. package/src/html-editor/InlineHtmlEditor.tsx +1 -1
@@ -6,337 +6,344 @@ import { CancelToken } from "@web-atoms/core/dist/core/types.js";
6
6
  import XNode from "@web-atoms/core/dist/core/XNode.js";
7
7
  import AtomRepeater, { MatchTrue } from "./AtomRepeater.js";
8
8
  export { default as Chip } from "./Chip.js";
9
- import "./styles/chips.global.css";
10
- import "./styles/item-suggestion.global.css";
9
+ ESMPack.installStyleSheet(import.meta.resolve("./styles/chips.global.css"));
10
+ ESMPack.installStyleSheet(import.meta.resolve("./styles/item-suggestion.global.css"));
11
11
  import AtomPopover from "./elements/AtomPopover.js";
12
12
  function getChips(target) {
13
- let start = target;
14
- while (start) {
15
- const chips = start.atomControl;
16
- if (chips && chips instanceof AtomChips) {
17
- return chips;
18
- }
19
- start = start.parentElement;
13
+ let start = target;
14
+ while (start) {
15
+ const chips = start.atomControl;
16
+ if (chips && chips instanceof AtomChips) {
17
+ return chips;
20
18
  }
19
+ start = start.parentElement;
20
+ }
21
21
  }
22
- document.body.addEventListener("focusin", (e) => {
23
- const chips = getChips(e.target);
24
- chips?.setFocus(true);
22
+ document.body.addEventListener("focusin", e => {
23
+ const chips = getChips(e.target);
24
+ chips?.setFocus(true);
25
25
  });
26
- document.body.addEventListener("focusout", (e) => {
27
- const chips = getChips(e.target);
28
- chips?.setFocus(false);
26
+ document.body.addEventListener("focusout", e => {
27
+ const chips = getChips(e.target);
28
+ chips?.setFocus(false);
29
29
  });
30
- document.body.addEventListener("keydown", (e) => {
31
- const chips = getChips(e.target);
32
- chips?.onKey(e);
30
+ document.body.addEventListener("keydown", e => {
31
+ const chips = getChips(e.target);
32
+ chips?.onKey(e);
33
33
  });
34
34
  function askSuggestionPopup(host, opener, itemRenderer, suggestionFilter, cancelToken) {
35
- class Suggestions extends AtomPopover {
36
- init() {
37
- this.opener = opener;
38
- this.renderer = XNode.create("div", { "data-suggestion-popup": "suggestion-popup" },
39
- XNode.create("div", { class: "items" },
40
- XNode.create(AtomRepeater, { class: "presenter", selectedItem: Bind.source(opener, (x) => x.source.anchorItem), itemRenderer: itemRenderer, eventDeleteSuggestion: (e) => opener.element.dispatchEvent(e), visibilityFilter: suggestionFilter ?? MatchTrue, "event-item-click": (e) => {
41
- e.preventDefault();
42
- e.stopImmediatePropagation();
43
- e.stopPropagation();
44
- this.close(e.detail);
45
- }, items: Bind.source(opener, (x) => x.source.suggestions) })));
46
- }
35
+ class Suggestions extends AtomPopover {
36
+ init() {
37
+ this.opener = opener;
38
+ this.renderer = XNode.create("div", {
39
+ "data-suggestion-popup": "suggestion-popup"
40
+ }, XNode.create("div", {
41
+ class: "items"
42
+ }, XNode.create(AtomRepeater, {
43
+ class: "presenter",
44
+ selectedItem: Bind.source(opener, x => x.source.anchorItem),
45
+ itemRenderer: itemRenderer,
46
+ eventDeleteSuggestion: e => opener.element.dispatchEvent(e),
47
+ visibilityFilter: suggestionFilter ?? MatchTrue,
48
+ "event-item-click": e => {
49
+ e.preventDefault();
50
+ e.stopImmediatePropagation();
51
+ e.stopPropagation();
52
+ this.close(e.detail);
53
+ },
54
+ items: Bind.source(opener, x => x.source.suggestions)
55
+ })));
47
56
  }
48
- return Suggestions.show(host, { "anchor-top": "parent-bottom", "anchor-left": "parent-left", cancelToken });
57
+ }
58
+ return Suggestions.show(host, {
59
+ "anchor-top": "parent-bottom",
60
+ "anchor-left": "parent-left",
61
+ cancelToken
62
+ });
49
63
  }
50
- export function Suggestion({ icon, label, header, deleteIcon, ...a }, ...nodes) {
51
- return XNode.create("div", { "data-item-suggestion": "suggestion", ...a },
52
- icon && XNode.create("i", { class: "icon " + icon }),
53
- header && XNode.create("label", { class: "header", text: header, title: header }),
54
- label && XNode.create("label", { class: "label", text: label, title: label }),
55
- ...nodes,
56
- deleteIcon && XNode.create("i", { class: "delete " + deleteIcon, "data-click-event": "remove-suggestion" }));
64
+ export function Suggestion({
65
+ icon,
66
+ label,
67
+ header,
68
+ deleteIcon,
69
+ ...a
70
+ }, ...nodes) {
71
+ return XNode.create("div", {
72
+ "data-item-suggestion": "suggestion",
73
+ ...a
74
+ }, icon && XNode.create("i", {
75
+ class: "icon " + icon
76
+ }), header && XNode.create("label", {
77
+ class: "header",
78
+ text: header,
79
+ title: header
80
+ }), label && XNode.create("label", {
81
+ class: "label",
82
+ text: label,
83
+ title: label
84
+ }), ...nodes, deleteIcon && XNode.create("i", {
85
+ class: "delete " + deleteIcon,
86
+ "data-click-event": "remove-suggestion"
87
+ }));
57
88
  }
58
89
  export default class AtomChips extends AtomRepeater {
59
- get searchType() {
60
- return this.searchInput.type;
90
+ get searchType() {
91
+ return this.searchInput.type;
92
+ }
93
+ set searchType(v) {
94
+ this.searchInput.type = v;
95
+ }
96
+ get enterKeyHint() {
97
+ return this.searchInput.enterKeyHint;
98
+ }
99
+ set enterKeyHint(v) {
100
+ this.searchInput.enterKeyHint = v;
101
+ }
102
+ onPropertyChanged(name) {
103
+ super.onPropertyChanged(name);
104
+ switch (name) {
105
+ case "labelPath":
106
+ this.itemRenderer = item => XNode.create("div", {
107
+ text: this.labelPath(item)
108
+ });
109
+ break;
110
+ case "prompt":
111
+ this.updateClasses();
112
+ break;
113
+ case "focused":
114
+ this.updatePopup();
115
+ break;
116
+ case "suggestions":
117
+ this.suggestionsWatcher?.dispose();
118
+ this.suggestionsWatcher = undefined;
119
+ const suggestions = this.suggestions;
120
+ if (suggestions) {
121
+ this.suggestionsWatcher = this.registerDisposable(suggestions.watch(() => {
122
+ this.updatePopup();
123
+ }));
124
+ }
125
+ this.updatePopup();
126
+ break;
61
127
  }
62
- set searchType(v) {
63
- this.searchInput.type = v;
128
+ }
129
+ preCreate() {
130
+ super.preCreate();
131
+ this.preventDuplicates = true;
132
+ this.softDeleteProperty = null;
133
+ this.prompt = "Search";
134
+ this.element.setAttribute("data-atom-chips", "atom-chips");
135
+ this.element.setAttribute("data-mode", "search");
136
+ this.suggestionFilter = MatchTrue;
137
+ this.valuePath = item => item?.value ?? item;
138
+ this.labelPath = item => item?.label ?? item;
139
+ this.itemRenderer = item => XNode.create("div", {
140
+ text: this.labelPath(item)
141
+ });
142
+ this.element.dataset.dropDown = "drop-down";
143
+ this.render(XNode.create("div", null, XNode.create("div", {
144
+ class: "presenter"
145
+ }), XNode.create("input", {
146
+ class: "search",
147
+ placeholder: Bind.oneWay(() => this.prompt),
148
+ value: Bind.twoWaysImmediate(() => this.search),
149
+ autofocus: Bind.oneWay(() => this.autofocus),
150
+ type: "search"
151
+ }), XNode.create("div", {
152
+ class: "footer"
153
+ })));
154
+ this.itemsPresenter = this.element.children[0];
155
+ this.searchInput = this.element.children[1];
156
+ this.footerPresenter = this.element.children[2];
157
+ this.bindEvent(this.element, "removeChip", e => e.defaultPrevented || this.removeItem(e.detail));
158
+ this.bindEvent(this.element, "undoRemoveChip", e => e.defaultPrevented || this.undoRemoveItem(e.detail));
159
+ this.bindEvent(this.searchInput, "blur", () => {
160
+ if (!this.onBlurItemToChip) {
161
+ return;
162
+ }
163
+ setTimeout(() => {
164
+ const search = this.search;
165
+ if (search) {
166
+ const item = this.onBlurItemToChip(search);
167
+ if (item) {
168
+ this.items.add(item);
169
+ this.searchInput.value = "";
170
+ this.search = "";
171
+ }
172
+ }
173
+ }, 200);
174
+ });
175
+ }
176
+ setFocus(hasFocus) {
177
+ if (hasFocus) {
178
+ if (this.focusTimeout) {
179
+ clearTimeout(this.focusTimeout);
180
+ this.focusTimeout = void 0;
181
+ }
182
+ this.focused = true;
183
+ return;
64
184
  }
65
- get enterKeyHint() {
66
- return this.searchInput.enterKeyHint;
185
+ this.focusTimeout = setTimeout(() => {
186
+ this.focusTimeout = void 0;
187
+ this.focused = false;
188
+ }, 1500);
189
+ }
190
+ async updatePopup() {
191
+ const suggestions = this.suggestions;
192
+ if (!this.focused) {
193
+ this.popupCancelToken?.cancel();
194
+ this.popupCancelToken = null;
195
+ return;
67
196
  }
68
- set enterKeyHint(v) {
69
- this.searchInput.enterKeyHint = v;
197
+ const detail = this.suggestions;
198
+ const ce = new CustomEvent("suggestions-requested", {
199
+ detail
200
+ });
201
+ this.element.dispatchEvent(ce);
202
+ if (ce.defaultPrevented) {
203
+ return;
70
204
  }
71
- onPropertyChanged(name) {
72
- super.onPropertyChanged(name);
73
- switch (name) {
74
- case "labelPath":
75
- this.itemRenderer = (item) => XNode.create("div", { text: this.labelPath(item) });
76
- break;
77
- case "prompt":
78
- this.updateClasses();
79
- break;
80
- case "focused":
81
- this.updatePopup();
82
- break;
83
- case "suggestions":
84
- this.suggestionsWatcher?.dispose();
85
- this.suggestionsWatcher = undefined;
86
- const suggestions = this.suggestions;
87
- if (suggestions) {
88
- this.suggestionsWatcher = this.registerDisposable(suggestions.watch(() => {
89
- this.updatePopup();
90
- }));
91
- }
92
- this.updatePopup();
93
- break;
94
- }
205
+ const {
206
+ promise
207
+ } = ce;
208
+ if (promise) {
209
+ await promise;
95
210
  }
96
- preCreate() {
97
- super.preCreate();
98
- this.preventDuplicates = true;
99
- this.softDeleteProperty = null;
100
- this.prompt = "Search";
101
- this.element.setAttribute("data-atom-chips", "atom-chips");
102
- this.element.setAttribute("data-mode", "search");
103
- this.suggestionFilter = MatchTrue;
104
- this.valuePath = (item) => item?.value ?? item;
105
- this.labelPath = (item) => item?.label ?? item;
106
- this.itemRenderer = (item) => XNode.create("div", { text: this.labelPath(item) });
107
- this.element.dataset.dropDown = "drop-down";
108
- this.render(XNode.create("div", null,
109
- XNode.create("div", { class: "presenter" }),
110
- XNode.create("input", { class: "search", placeholder: Bind.oneWay(() => this.prompt), value: Bind.twoWaysImmediate(() => this.search), autofocus: Bind.oneWay(() => this.autofocus), type: "search" }),
111
- XNode.create("div", { class: "footer" })));
112
- this.itemsPresenter = this.element.children[0];
113
- this.searchInput = this.element.children[1];
114
- this.footerPresenter = this.element.children[2];
115
- this.bindEvent(this.element, "removeChip", (e) => e.defaultPrevented || this.removeItem(e.detail));
116
- this.bindEvent(this.element, "undoRemoveChip", (e) => e.defaultPrevented || this.undoRemoveItem(e.detail));
117
- this.bindEvent(this.searchInput, "blur", () => {
118
- if (!this.onBlurItemToChip) {
119
- return;
120
- }
121
- setTimeout(() => {
122
- const search = this.search;
123
- if (search) {
124
- const item = this.onBlurItemToChip(search);
125
- if (item) {
126
- this.items.add(item);
127
- this.searchInput.value = "";
128
- this.search = "";
129
- }
130
- }
131
- }, 200);
132
- });
211
+ if (ce.detail !== this.suggestions) {
212
+ this.suggestions = ce.detail;
133
213
  }
134
- setFocus(hasFocus) {
135
- if (hasFocus) {
136
- if (this.focusTimeout) {
137
- clearTimeout(this.focusTimeout);
138
- this.focusTimeout = void 0;
139
- }
140
- this.focused = true;
141
- return;
142
- }
143
- this.focusTimeout = setTimeout(() => {
144
- this.focusTimeout = void 0;
145
- this.focused = false;
146
- }, 1500);
214
+ if (!suggestions?.length) {
215
+ this.popupCancelToken?.cancel();
216
+ this.popupCancelToken = null;
217
+ return;
147
218
  }
148
- async updatePopup() {
149
- const suggestions = this.suggestions;
150
- if (!this.focused) {
151
- this.popupCancelToken?.cancel();
152
- this.popupCancelToken = null;
153
- return;
154
- }
155
- const detail = this.suggestions;
156
- const ce = new CustomEvent("suggestions-requested", { detail });
157
- this.element.dispatchEvent(ce);
158
- if (ce.defaultPrevented) {
159
- return;
160
- }
161
- const { promise } = ce;
162
- if (promise) {
163
- await promise;
164
- }
165
- if (ce.detail !== this.suggestions) {
166
- this.suggestions = ce.detail;
167
- }
168
- if (!(suggestions?.length)) {
169
- this.popupCancelToken?.cancel();
170
- this.popupCancelToken = null;
171
- return;
172
- }
173
- if (this.popupCancelToken) {
174
- return;
175
- }
176
- const cancelToken = this.popupCancelToken = new CancelToken();
177
- try {
178
- let selectedItem = await askSuggestionPopup(this.element, this, this.suggestionRenderer ?? this.itemRenderer, this.suggestionFilter, cancelToken);
179
- const itemToChip = this.itemToChip;
180
- if (itemToChip) {
181
- selectedItem = itemToChip(selectedItem, this.search);
182
- }
183
- this.addItem(selectedItem);
184
- this.search = "";
185
- this.popupCancelToken = null;
186
- }
187
- catch (e) {
188
- this.popupCancelToken = null;
189
- if (CancelToken.isCancelled(e)) {
190
- return;
191
- }
192
- console.warn(e);
193
- }
219
+ if (this.popupCancelToken) {
220
+ return;
194
221
  }
195
- addItem(selectedItem) {
196
- const ce = new CustomEvent("suggestionChosen", {
197
- detail: selectedItem,
198
- cancelable: true,
199
- bubbles: true
200
- });
201
- this.element.dispatchEvent(ce);
202
- if (!ce.defaultPrevented) {
203
- const item = ce.detail;
204
- const vp = this.valuePath ?? ((x) => x);
205
- const v = vp(item);
206
- for (const iterator of this.items) {
207
- if (v === vp(iterator)) {
208
- return;
209
- }
210
- }
211
- this.items.add(ce.detail);
222
+ const cancelToken = this.popupCancelToken = new CancelToken();
223
+ try {
224
+ let selectedItem = await askSuggestionPopup(this.element, this, this.suggestionRenderer ?? this.itemRenderer, this.suggestionFilter, cancelToken);
225
+ const itemToChip = this.itemToChip;
226
+ if (itemToChip) {
227
+ selectedItem = itemToChip(selectedItem, this.search);
228
+ }
229
+ this.addItem(selectedItem);
230
+ this.search = "";
231
+ this.popupCancelToken = null;
232
+ } catch (e) {
233
+ this.popupCancelToken = null;
234
+ if (CancelToken.isCancelled(e)) {
235
+ return;
236
+ }
237
+ console.warn(e);
238
+ }
239
+ }
240
+ addItem(selectedItem) {
241
+ const ce = new CustomEvent("suggestionChosen", {
242
+ detail: selectedItem,
243
+ cancelable: true,
244
+ bubbles: true
245
+ });
246
+ this.element.dispatchEvent(ce);
247
+ if (!ce.defaultPrevented) {
248
+ const item = ce.detail;
249
+ const vp = this.valuePath ?? (x => x);
250
+ const v = vp(item);
251
+ for (const iterator of this.items) {
252
+ if (v === vp(iterator)) {
253
+ return;
212
254
  }
255
+ }
256
+ this.items.add(ce.detail);
213
257
  }
214
- undoRemoveItem(item) {
215
- let { softDeleteProperty } = this;
216
- softDeleteProperty = typeof softDeleteProperty !== "string" ? "$deleted" : softDeleteProperty;
217
- item[softDeleteProperty] = false;
218
- AtomBinder.refreshValue(this.items, "length");
219
- this.refreshItem(item);
258
+ }
259
+ undoRemoveItem(item) {
260
+ let {
261
+ softDeleteProperty
262
+ } = this;
263
+ softDeleteProperty = typeof softDeleteProperty !== "string" ? "$deleted" : softDeleteProperty;
264
+ item[softDeleteProperty] = false;
265
+ AtomBinder.refreshValue(this.items, "length");
266
+ this.refreshItem(item);
267
+ }
268
+ removeItem(item) {
269
+ let {
270
+ softDeleteProperty
271
+ } = this;
272
+ if (softDeleteProperty) {
273
+ softDeleteProperty = typeof softDeleteProperty !== "string" ? "$deleted" : softDeleteProperty;
274
+ item[softDeleteProperty] = true;
275
+ AtomBinder.refreshValue(this.items, "length");
276
+ this.refreshItem(item);
277
+ } else {
278
+ this.items.remove(item);
220
279
  }
221
- removeItem(item) {
222
- let { softDeleteProperty } = this;
223
- if (softDeleteProperty) {
224
- softDeleteProperty = typeof softDeleteProperty !== "string" ? "$deleted" : softDeleteProperty;
225
- item[softDeleteProperty] = true;
226
- AtomBinder.refreshValue(this.items, "length");
227
- this.refreshItem(item);
228
- }
229
- else {
230
- this.items.remove(item);
231
- }
280
+ }
281
+ onKey(e) {
282
+ const suggested = this.suggestions;
283
+ const onKeyPressedItemToChip = this.onKeyPressedItemToChip;
284
+ if (onKeyPressedItemToChip && this.search) {
285
+ const item = onKeyPressedItemToChip(e.key, this.search);
286
+ if (item) {
287
+ this.addItem(item);
288
+ this.searchInput.value = "";
289
+ return;
290
+ }
232
291
  }
233
- onKey(e) {
234
- const suggested = this.suggestions;
235
- const onKeyPressedItemToChip = this.onKeyPressedItemToChip;
236
- if (onKeyPressedItemToChip && this.search) {
237
- const item = onKeyPressedItemToChip(e.key, this.search);
238
- if (item) {
239
- this.addItem(item);
240
- this.searchInput.value = "";
241
- return;
292
+ switch (e.key) {
293
+ case "Enter":
294
+ e.preventDefault?.();
295
+ e.stopImmediatePropagation?.();
296
+ setTimeout(() => {
297
+ let anchorItem = this.anchorItem;
298
+ const itemToChip = this.itemToChip;
299
+ if (itemToChip) {
300
+ anchorItem = itemToChip(anchorItem, this.search);
301
+ }
302
+ if (!anchorItem) {
303
+ return;
304
+ }
305
+ this.addItem(anchorItem);
306
+ this.anchorIndex = 0;
307
+ this.anchorItem = null;
308
+ this.search = "";
309
+ }, 1);
310
+ break;
311
+ case "ArrowDown":
312
+ if (suggested) {
313
+ if (!this.anchorItem) {
314
+ this.anchorIndex = 0;
315
+ } else {
316
+ if (this.anchorIndex < suggested.length - 1) {
317
+ this.anchorIndex++;
242
318
  }
319
+ }
320
+ this.anchorItem = suggested[this.anchorIndex];
243
321
  }
244
- switch (e.key) {
245
- case "Enter":
246
- e.preventDefault?.();
247
- e.stopImmediatePropagation?.();
248
- setTimeout(() => {
249
- let anchorItem = this.anchorItem;
250
- const itemToChip = this.itemToChip;
251
- if (itemToChip) {
252
- anchorItem = itemToChip(anchorItem, this.search);
253
- }
254
- if (!anchorItem) {
255
- return;
256
- }
257
- this.addItem(anchorItem);
258
- this.anchorIndex = 0;
259
- this.anchorItem = null;
260
- this.search = "";
261
- }, 1);
262
- break;
263
- case "ArrowDown":
264
- if (suggested) {
265
- if (!this.anchorItem) {
266
- this.anchorIndex = 0;
267
- }
268
- else {
269
- if (this.anchorIndex < suggested.length - 1) {
270
- this.anchorIndex++;
271
- }
272
- }
273
- this.anchorItem = suggested[this.anchorIndex];
274
- }
275
- break;
276
- case "ArrowUp":
277
- if (suggested) {
278
- if (!this.anchorItem) {
279
- return;
280
- }
281
- if (this.anchorIndex) {
282
- this.anchorIndex--;
283
- }
284
- this.anchorItem = suggested[this.anchorIndex];
285
- }
286
- break;
322
+ break;
323
+ case "ArrowUp":
324
+ if (suggested) {
325
+ if (!this.anchorItem) {
326
+ return;
327
+ }
328
+ if (this.anchorIndex) {
329
+ this.anchorIndex--;
330
+ }
331
+ this.anchorItem = suggested[this.anchorIndex];
287
332
  }
333
+ break;
288
334
  }
335
+ }
289
336
  }
290
- __decorate([
291
- BindableProperty,
292
- __metadata("design:type", Array)
293
- ], AtomChips.prototype, "suggestions", void 0);
294
- __decorate([
295
- BindableProperty,
296
- __metadata("design:type", String)
297
- ], AtomChips.prototype, "search", void 0);
298
- __decorate([
299
- BindableProperty,
300
- __metadata("design:type", String)
301
- ], AtomChips.prototype, "prompt", void 0);
302
- __decorate([
303
- BindableProperty,
304
- __metadata("design:type", String)
305
- ], AtomChips.prototype, "suggestionPrompt", void 0);
306
- __decorate([
307
- BindableProperty,
308
- __metadata("design:type", Object)
309
- ], AtomChips.prototype, "autofocus", void 0);
310
- __decorate([
311
- BindableProperty,
312
- __metadata("design:type", String)
313
- ], AtomChips.prototype, "softDeleteProperty", void 0);
314
- __decorate([
315
- BindableProperty,
316
- __metadata("design:type", Function)
317
- ], AtomChips.prototype, "labelPath", void 0);
318
- __decorate([
319
- BindableProperty,
320
- __metadata("design:type", Function)
321
- ], AtomChips.prototype, "match", void 0);
322
- __decorate([
323
- BindableProperty,
324
- __metadata("design:type", Function)
325
- ], AtomChips.prototype, "suggestionRenderer", void 0);
326
- __decorate([
327
- BindableProperty,
328
- __metadata("design:type", Function)
329
- ], AtomChips.prototype, "suggestionFilter", void 0);
330
- __decorate([
331
- BindableProperty,
332
- __metadata("design:type", Boolean)
333
- ], AtomChips.prototype, "focused", void 0);
334
- __decorate([
335
- BindableProperty,
336
- __metadata("design:type", Function)
337
- ], AtomChips.prototype, "onKeyPressedItemToChip", void 0);
338
- __decorate([
339
- BindableProperty,
340
- __metadata("design:type", Function)
341
- ], AtomChips.prototype, "onBlurItemToChip", void 0);
342
- //# sourceMappingURL=AtomChips.js.map
337
+ __decorate([BindableProperty, __metadata("design:type", Array)], AtomChips.prototype, "suggestions", void 0);
338
+ __decorate([BindableProperty, __metadata("design:type", String)], AtomChips.prototype, "search", void 0);
339
+ __decorate([BindableProperty, __metadata("design:type", String)], AtomChips.prototype, "prompt", void 0);
340
+ __decorate([BindableProperty, __metadata("design:type", String)], AtomChips.prototype, "suggestionPrompt", void 0);
341
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomChips.prototype, "autofocus", void 0);
342
+ __decorate([BindableProperty, __metadata("design:type", String)], AtomChips.prototype, "softDeleteProperty", void 0);
343
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomChips.prototype, "labelPath", void 0);
344
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomChips.prototype, "match", void 0);
345
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomChips.prototype, "suggestionRenderer", void 0);
346
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomChips.prototype, "suggestionFilter", void 0);
347
+ __decorate([BindableProperty, __metadata("design:type", Boolean)], AtomChips.prototype, "focused", void 0);
348
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomChips.prototype, "onKeyPressedItemToChip", void 0);
349
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomChips.prototype, "onBlurItemToChip", void 0);