@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.
Files changed (177) hide show
  1. package/dist/tsconfig.tsbuildinfo +1 -1
  2. package/dist-esm/ArrayLike.js +14 -12
  3. package/dist-esm/DataAttributes.js +18 -19
  4. package/dist-esm/Focusable.js +10 -11
  5. package/dist-esm/ModuleFiles.js +43 -42
  6. package/dist-esm/NumberFormats.js +60 -56
  7. package/dist-esm/PageNavigator.js +28 -30
  8. package/dist-esm/animations/Animations.js +36 -33
  9. package/dist-esm/basic/AtomChips.js +312 -305
  10. package/dist-esm/basic/AtomRepeater.js +1070 -1035
  11. package/dist-esm/basic/AtomSuggestions.js +97 -107
  12. package/dist-esm/basic/AttachedPopup.js +0 -1
  13. package/dist-esm/basic/Button.js +45 -19
  14. package/dist-esm/basic/ButtonBar.js +84 -64
  15. package/dist-esm/basic/Calendar.js +211 -203
  16. package/dist-esm/basic/CheckBoxList.js +90 -70
  17. package/dist-esm/basic/Checkbox.js +16 -8
  18. package/dist-esm/basic/Chip.js +36 -12
  19. package/dist-esm/basic/ComboBox.js +47 -51
  20. package/dist-esm/basic/DataGrid.js +258 -252
  21. package/dist-esm/basic/DateField.js +149 -127
  22. package/dist-esm/basic/DropDown.js +91 -103
  23. package/dist-esm/basic/DropDownInput.js +78 -106
  24. package/dist-esm/basic/Editable.js +82 -77
  25. package/dist-esm/basic/Expander.js +104 -86
  26. package/dist-esm/basic/FilesDragDrop.js +84 -80
  27. package/dist-esm/basic/Form.js +80 -52
  28. package/dist-esm/basic/FormField.js +164 -106
  29. package/dist-esm/basic/IElement.js +1 -2
  30. package/dist-esm/basic/InlinePopup.js +263 -234
  31. package/dist-esm/basic/InlinePopupButton.js +99 -88
  32. package/dist-esm/basic/InlinePopupControl.js +24 -23
  33. package/dist-esm/basic/ItemPath.js +59 -60
  34. package/dist-esm/basic/LimitedText.js +49 -38
  35. package/dist-esm/basic/ListRepeater.js +13 -14
  36. package/dist-esm/basic/MaskedInput.js +37 -29
  37. package/dist-esm/basic/MaskedInputDiv.js +55 -48
  38. package/dist-esm/basic/MergeNode.js +64 -35
  39. package/dist-esm/basic/PasswordBox.js +32 -17
  40. package/dist-esm/basic/PinchZoomView.js +221 -199
  41. package/dist-esm/basic/PopupButton.js +39 -16
  42. package/dist-esm/basic/PopupMenu.js +3 -4
  43. package/dist-esm/basic/RadioButtonList.js +35 -25
  44. package/dist-esm/basic/RefreshLock.js +41 -42
  45. package/dist-esm/basic/Resizable.js +43 -33
  46. package/dist-esm/basic/Select.js +72 -65
  47. package/dist-esm/basic/SortByButton.js +41 -31
  48. package/dist-esm/basic/Swipe.js +91 -84
  49. package/dist-esm/basic/Switch.js +22 -8
  50. package/dist-esm/basic/TableRepeater.js +29 -33
  51. package/dist-esm/basic/TimeEditor.js +97 -52
  52. package/dist-esm/basic/TitleEditor.js +115 -95
  53. package/dist-esm/basic/ToggleButtonBar.js +21 -22
  54. package/dist-esm/basic/Tooltip.js +49 -47
  55. package/dist-esm/basic/TypeWriter.js +45 -42
  56. package/dist-esm/basic/UploadEvent.js +211 -178
  57. package/dist-esm/basic/ZoomView.js +229 -198
  58. package/dist-esm/basic/combineClasses.js +2 -3
  59. package/dist-esm/basic/elements/AtomPopover.js +270 -253
  60. package/dist-esm/basic/elements/getContainingBlock.js +34 -35
  61. package/dist-esm/basic/elements/relativeRect.js +40 -21
  62. package/dist-esm/desktop-app/DesktopApp.js +65 -80
  63. package/dist-esm/desktop-app/MobileDesktopApp.js +20 -23
  64. package/dist-esm/html-editor/AtomHtmlEditor.js +243 -268
  65. package/dist-esm/html-editor/HtmlEditorCommands.js +6 -4
  66. package/dist-esm/html-editor/InlineHtmlEditor.js +174 -166
  67. package/dist-esm/html-editor/RangeEditor.js +49 -51
  68. package/dist-esm/html-editor/commands/AddImage.js +40 -35
  69. package/dist-esm/html-editor/commands/AddLink.js +56 -54
  70. package/dist-esm/html-editor/commands/Align.js +24 -7
  71. package/dist-esm/html-editor/commands/AttachFile.js +23 -13
  72. package/dist-esm/html-editor/commands/AttachImage.js +35 -25
  73. package/dist-esm/html-editor/commands/Bold.js +10 -11
  74. package/dist-esm/html-editor/commands/ChangeColor.js +31 -107
  75. package/dist-esm/html-editor/commands/ChangeFont.js +42 -42
  76. package/dist-esm/html-editor/commands/ChangeFontSize.js +15 -5
  77. package/dist-esm/html-editor/commands/Command.js +34 -16
  78. package/dist-esm/html-editor/commands/CommandButton.js +51 -32
  79. package/dist-esm/html-editor/commands/Headings.js +25 -9
  80. package/dist-esm/html-editor/commands/HorizontalRule.js +9 -10
  81. package/dist-esm/html-editor/commands/HtmlCommands.js +160 -65
  82. package/dist-esm/html-editor/commands/IndentLess.js +10 -11
  83. package/dist-esm/html-editor/commands/IndentMore.js +10 -11
  84. package/dist-esm/html-editor/commands/Italic.js +10 -11
  85. package/dist-esm/html-editor/commands/NumberedList.js +10 -11
  86. package/dist-esm/html-editor/commands/Quote.js +10 -11
  87. package/dist-esm/html-editor/commands/RemoveFormat.js +10 -11
  88. package/dist-esm/html-editor/commands/Separator.js +5 -4
  89. package/dist-esm/html-editor/commands/Source.js +29 -25
  90. package/dist-esm/html-editor/commands/StrikeThrough.js +10 -11
  91. package/dist-esm/html-editor/commands/Toolbar.js +6 -4
  92. package/dist-esm/html-editor/commands/Underline.js +10 -11
  93. package/dist-esm/html-editor/commands/Unlink.js +10 -9
  94. package/dist-esm/html-editor/commands/UnorderedList.js +10 -11
  95. package/dist-esm/mobile-app/BottomPopup.js +137 -148
  96. package/dist-esm/mobile-app/MasterDetailPage.js +153 -152
  97. package/dist-esm/mobile-app/MobileApp.js +577 -569
  98. package/dist-esm/player/AtomVideoPlayer.js +316 -270
  99. package/dist-esm/player/TrackProgress.js +11 -7
  100. package/dist-esm/player/input-range-style.js +97 -98
  101. package/dist-esm/tests/app-test/AppTestApp.js +12 -15
  102. package/dist-esm/tests/app-test/AppTestApp.pack.js +54 -0
  103. package/dist-esm/tests/app-test/commands/AppCommands.js +14 -11
  104. package/dist-esm/tests/app-test/drawer/AppDrawer.js +4 -6
  105. package/dist-esm/tests/app-test/model/model.js +1 -2
  106. package/dist-esm/tests/app-test/pages/detail/DetailPage.js +21 -15
  107. package/dist-esm/tests/app-test/pages/home/HomePage.js +7 -8
  108. package/dist-esm/tests/app-test/pages/list/ListPage.js +79 -62
  109. package/dist-esm/tests/basic/PopupTest.js +9 -7
  110. package/dist-esm/tests/basic/TimeEditorTest.js +5 -9
  111. package/dist-esm/tests/basic/TimeEditorTest.pack.js +39 -0
  112. package/dist-esm/tests/basic/TimerTest.js +27 -37
  113. package/dist-esm/tests/basic/TimerTest.pack.js +40 -0
  114. package/dist-esm/tests/basic/basic-form/BasicForm.js +47 -27
  115. package/dist-esm/tests/basic/basic-form/BasicForm.pack.js +44 -0
  116. package/dist-esm/tests/basic/calendar/BasicCalendarTest.js +5 -9
  117. package/dist-esm/tests/basic/calendar/BasicCalendarTest.pack.js +53 -0
  118. package/dist-esm/tests/basic/chips/ChipsTest.js +25 -15
  119. package/dist-esm/tests/basic/chips/ChipsTest.pack.js +56 -0
  120. package/dist-esm/tests/basic/data-grid/DataGridTest.js +55 -60
  121. package/dist-esm/tests/basic/data-grid/DataGridTest.pack.js +58 -0
  122. package/dist-esm/tests/basic/date/DateFieldTest.js +21 -96
  123. package/dist-esm/tests/basic/date/DateFieldTest.pack.js +57 -0
  124. package/dist-esm/tests/basic/drop-down/DropDownTest.js +25 -19
  125. package/dist-esm/tests/basic/drop-down/DropDownTest.pack.js +52 -0
  126. package/dist-esm/tests/basic/drop-down-input/DropDownTest.js +32 -32
  127. package/dist-esm/tests/basic/drop-down-input/DropDownTest.pack.js +54 -0
  128. package/dist-esm/tests/basic/expander/ExpanderMenuTest.js +20 -14
  129. package/dist-esm/tests/basic/expander/ExpanderMenuTest.pack.js +38 -0
  130. package/dist-esm/tests/basic/expander/ExpanderTest.js +11 -12
  131. package/dist-esm/tests/basic/expander/ExpanderTest.pack.js +38 -0
  132. package/dist-esm/tests/basic/form2/Form2Test.js +26 -24
  133. package/dist-esm/tests/basic/form2/Form2Test.pack.js +46 -0
  134. package/dist-esm/tests/basic/limited-text/LimitedTextTest.js +14 -11
  135. package/dist-esm/tests/basic/limited-text/LimitedTextTest.pack.js +38 -0
  136. package/dist-esm/tests/basic/pinch-zoom/PinchZoomViewTest.js +14 -14
  137. package/dist-esm/tests/basic/pinch-zoom/PinchZoomViewTest.pack.js +38 -0
  138. package/dist-esm/tests/basic/repeater/DragDropRepater.js +30 -12
  139. package/dist-esm/tests/basic/repeater/DragDropRepater.pack.js +51 -0
  140. package/dist-esm/tests/basic/repeater/RepeaterTest.js +45 -35
  141. package/dist-esm/tests/basic/repeater/RepeaterTest.pack.js +52 -0
  142. package/dist-esm/tests/basic/swipe/SwipeTest.js +13 -13
  143. package/dist-esm/tests/basic/swipe/SwipeTest.pack.js +52 -0
  144. package/dist-esm/tests/basic/switch-test/SwitchTest.js +8 -10
  145. package/dist-esm/tests/basic/switch-test/SwitchTest.pack.js +38 -0
  146. package/dist-esm/tests/basic/title-editor/TitleEditorTest.js +8 -9
  147. package/dist-esm/tests/basic/title-editor/TitleEditorTest.pack.js +38 -0
  148. package/dist-esm/tests/basic/tooltip/TooltipTest.js +30 -24
  149. package/dist-esm/tests/basic/tooltip/TooltipTest.pack.js +52 -0
  150. package/dist-esm/tests/basic/typewriter/TypeWriter.js +10 -9
  151. package/dist-esm/tests/basic/typewriter/TypeWriter.pack.js +39 -0
  152. package/dist-esm/tests/basic/video/AtomVideoTest.js +13 -10
  153. package/dist-esm/tests/basic/video/AtomVideoTest.pack.js +38 -0
  154. package/dist-esm/tests/basic/zoom/ZoomViewTest.js +13 -13
  155. package/dist-esm/tests/basic/zoom/ZoomViewTest.pack.js +38 -0
  156. package/dist-esm/tests/check-box-list/CheckBoxListSample.js +13 -12
  157. package/dist-esm/tests/check-box-list/CheckBoxListSample.pack.js +52 -0
  158. package/dist-esm/tests/data-grid/GridTestViewModel.js +203 -227
  159. package/dist-esm/tests/form/CustomHelp.js +6 -9
  160. package/dist-esm/tests/form/FormViewModel.js +21 -28
  161. package/dist-esm/tests/html-editor/HtmlEditorTest.js +7 -37
  162. package/dist-esm/tests/html-editor/HtmlEditorTest.pack.js +83 -0
  163. package/dist-esm/tests/html-editor/InlineHtmlEdiorTest.js +9 -38
  164. package/dist-esm/tests/html-editor/InlineHtmlEdiorTest.pack.js +85 -0
  165. package/dist-esm/tests/mask/MaskedInputTest.js +11 -12
  166. package/dist-esm/tests/mask/MaskedInputTest.pack.js +38 -0
  167. package/dist-esm/tests/mobile-app/DesktopAppTest.js +8 -9
  168. package/dist-esm/tests/mobile-app/DesktopAppTest.pack.js +60 -0
  169. package/dist-esm/tests/mobile-app/MobileAppTest.js +64 -53
  170. package/dist-esm/tests/mobile-app/MobileAppTest.pack.js +55 -0
  171. package/dist-esm/tests/pop-over/PopOverTest.js +37 -77
  172. package/dist-esm/tests/switch/SwitchTest.js +9 -8
  173. package/dist-esm/tests/toggle-view/ToggleViewTest.js +15 -22
  174. package/dist-esm/tests/toggle-view/ToggleViewTest.pack.js +45 -0
  175. package/dist-esm/toggle-view/AtomToggleView.js +77 -73
  176. package/dist-esm/tsconfig.esm.tsbuildinfo +1 -1
  177. package/package.json +3 -3
@@ -10,1121 +10,1156 @@ import { AtomControl } from "@web-atoms/core/dist/web/controls/AtomControl.js";
10
10
  import { PopupWindow } from "@web-atoms/core/dist/web/services/PopupService.js";
11
11
  import MergeNode from "./MergeNode.js";
12
12
  import ItemPath from "./ItemPath.js";
13
- import "./styles/popup.global.css";
14
- import "./styles/suggestion-popup.global.css";
15
- import "./styles/repeater.global.css";
13
+ ESMPack.installStyleSheet(import.meta.resolve("./styles/popup.global.css"));
14
+ ESMPack.installStyleSheet(import.meta.resolve("./styles/suggestion-popup.global.css"));
15
+ ESMPack.installStyleSheet(import.meta.resolve("./styles/repeater.global.css"));
16
16
  import { ChildEnumerator } from "@web-atoms/core/dist/web/core/AtomUI.js";
17
17
  import DataAttributes from "../DataAttributes.js";
18
18
  import AtomPopover from "./elements/AtomPopover.js";
19
19
  import sleep from "@web-atoms/core/dist/core/sleep.js";
20
- export const getParentRepeaterItem = (target) => {
21
- let eventName;
22
- let repeater;
23
- let index;
24
- let root;
25
- while (target) {
26
- const a = target.atomControl;
27
- if (a !== undefined && a instanceof AtomRepeater) {
28
- repeater = a;
29
- break;
30
- }
31
- if (index === undefined) {
32
- const itemIndex = target.getAttribute("data-item-index");
33
- if (typeof itemIndex !== "undefined") {
34
- root = target;
35
- index = ~~itemIndex;
36
- }
37
- }
38
- if (eventName === undefined) {
39
- const itemClickEvent = target.getAttribute("data-click-event");
40
- if (itemClickEvent) {
41
- eventName = itemClickEvent.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
42
- }
43
- }
44
- target = target.parentElement;
20
+ export const getParentRepeaterItem = target => {
21
+ let eventName;
22
+ let repeater;
23
+ let index;
24
+ let root;
25
+ while (target) {
26
+ const a = target.atomControl;
27
+ if (a !== undefined && a instanceof AtomRepeater) {
28
+ repeater = a;
29
+ break;
30
+ }
31
+ if (index === undefined) {
32
+ const itemIndex = target.getAttribute("data-item-index");
33
+ if (typeof itemIndex !== "undefined") {
34
+ root = target;
35
+ index = ~~itemIndex;
36
+ }
45
37
  }
46
- if (index === void 0 || repeater === void 0) {
47
- return undefined;
38
+ if (eventName === undefined) {
39
+ const itemClickEvent = target.getAttribute("data-click-event");
40
+ if (itemClickEvent) {
41
+ eventName = itemClickEvent.replace(/-([a-z])/g, g => g[1].toUpperCase());
42
+ }
48
43
  }
49
- const item = repeater.items[~~index];
50
- return [eventName, repeater, item, index, root];
44
+ target = target.parentElement;
45
+ }
46
+ if (index === void 0 || repeater === void 0) {
47
+ return undefined;
48
+ }
49
+ const item = repeater.items[~~index];
50
+ return [eventName, repeater, item, index, root];
51
51
  };
52
52
  export const MatchTrue = (...a) => true;
53
53
  export const MatchFalse = (...a) => false;
54
- export const ArrowToString = (item) => item.label?.toString() ?? item.toString();
54
+ export const ArrowToString = item => item.label?.toString() ?? item.toString();
55
55
  export const MatchCaseInsensitive = (textField = ArrowToString) => {
56
- return (s) => {
57
- if (!s) {
58
- return MatchTrue;
59
- }
60
- const r = StringHelper.createContainsRegExp(s);
61
- return (item) => r.test(textField(item));
62
- };
56
+ return s => {
57
+ if (!s) {
58
+ return MatchTrue;
59
+ }
60
+ const r = StringHelper.createContainsRegExp(s);
61
+ return item => r.test(textField(item));
62
+ };
63
63
  };
64
64
  export const MatchAnyCaseInsensitive = (textField = ArrowToString) => {
65
- return (s) => {
66
- if (!s) {
67
- return MatchTrue;
68
- }
69
- const r = StringHelper.createContainsAnyWordRegExp(s);
70
- return (item) => r.test(textField(item));
71
- };
65
+ return s => {
66
+ if (!s) {
67
+ return MatchTrue;
68
+ }
69
+ const r = StringHelper.createContainsAnyWordRegExp(s);
70
+ return item => r.test(textField(item));
71
+ };
72
72
  };
73
- export const SameObjectValue = (item) => item;
73
+ export const SameObjectValue = item => item;
74
74
  export function askSuggestion(items, itemRenderer, match, options) {
75
- class Suggestions extends PopupWindow {
76
- create() {
77
- this.title = options?.title ?? "Select";
78
- this.render(XNode.create("div", { "data-repeater-popup": "popup" },
79
- XNode.create("input", { type: "search", value: Bind.twoWaysImmediate(() => this.search), autofocus: true }),
80
- XNode.create("div", { class: "items" },
81
- XNode.create(AtomRepeater, { class: "presenter", itemRenderer: itemRenderer, visibilityFilter: Bind.oneWay(() => match(this.search)), eventItemClick: (e) => {
82
- this.close(e.detail);
83
- }, items: items }))));
84
- }
75
+ class Suggestions extends PopupWindow {
76
+ create() {
77
+ this.title = options?.title ?? "Select";
78
+ this.render(XNode.create("div", {
79
+ "data-repeater-popup": "popup"
80
+ }, XNode.create("input", {
81
+ type: "search",
82
+ value: Bind.twoWaysImmediate(() => this.search),
83
+ autofocus: true
84
+ }), XNode.create("div", {
85
+ class: "items"
86
+ }, XNode.create(AtomRepeater, {
87
+ class: "presenter",
88
+ itemRenderer: itemRenderer,
89
+ visibilityFilter: Bind.oneWay(() => match(this.search)),
90
+ eventItemClick: e => {
91
+ this.close(e.detail);
92
+ },
93
+ items: items
94
+ }))));
85
95
  }
86
- __decorate([
87
- BindableProperty,
88
- __metadata("design:type", String)
89
- ], Suggestions.prototype, "search", void 0);
90
- options ??= {};
91
- if (typeof options.maximize === "undefined") {
92
- if (typeof options.width === "undefined") {
93
- options.maxWidth = "90%";
94
- options.minWidth = "300px";
95
- }
96
- if (typeof options.height === "undefined") {
97
- options.height = "80%";
98
- }
96
+ }
97
+ __decorate([BindableProperty, __metadata("design:type", String)], Suggestions.prototype, "search", void 0);
98
+ options ??= {};
99
+ if (typeof options.maximize === "undefined") {
100
+ if (typeof options.width === "undefined") {
101
+ options.maxWidth = "90%";
102
+ options.minWidth = "300px";
99
103
  }
100
- return Suggestions.showModal(options);
104
+ if (typeof options.height === "undefined") {
105
+ options.height = "80%";
106
+ }
107
+ }
108
+ return Suggestions.showModal(options);
101
109
  }
102
110
  export function askSuggestionPopup(opener, items, itemRenderer, match, selectedItem) {
103
- const itemsInOpener = "items" in opener;
104
- class Suggestions extends AtomPopover {
105
- constructor() {
106
- super(...arguments);
107
- this.anchorItem = null;
108
- this.anchorIndex = null;
109
- }
110
- init() {
111
- const disableSearch = opener.disableSearch;
112
- this.renderer = XNode.create("div", { "data-suggestion-popup": "suggestion-popup" },
113
- !disableSearch && XNode.create("input", { type: "search", value: Bind.sourceTwoWays(opener, (x) => x.source.search), eventKeydown: (e) => this.onKey(e), autofocus: true }),
114
- XNode.create("div", { class: "items" },
115
- XNode.create(AtomRepeater, { class: "presenter", selectedItem: Bind.source(this, (x) => x.source.anchorItem), itemRenderer: itemRenderer, visibilityFilter: Bind.source(opener, (x) => match(x.source.search)), presenter: Bind.presenter((c) => this.repeater = c), eventItemClick: (e) => {
116
- this.anchorItem = e.detail;
117
- setTimeout(() => this.close(e.detail), 50);
118
- }, items: Bind.source(opener, (x) => x.source.items) })));
119
- if (disableSearch) {
120
- const { input } = opener;
121
- if (input) {
122
- this.disposables.add(opener.bindEvent(input, "keydown", (e) => this.onKey(e)));
123
- }
124
- }
125
- }
126
- async cancelSelection() {
127
- await sleep(100);
128
- if (!this.removed) {
129
- this.close(opener.selectedItem);
130
- }
131
- }
132
- onKey(e) {
133
- const suggested = match ? opener.items?.filter(match(opener.search)) : opener.items;
134
- switch (e.key) {
135
- case "Escape":
136
- this.cancelSelection().catch(console.error);
137
- return;
138
- case "Tab":
139
- case "Enter":
140
- const anchorItem = this.anchorItem;
141
- if (!anchorItem) {
142
- if (e.key === "Tab") {
143
- e.preventDefault();
144
- this.cancelSelection().catch(console.error);
145
- }
146
- return;
147
- }
148
- this.anchorIndex = 0;
149
- setTimeout(() => this.close(anchorItem), 10);
150
- this.anchorItem = null;
151
- opener.search = "";
152
- e.preventDefault();
153
- break;
154
- case "ArrowDown":
155
- if (suggested) {
156
- if (!this.anchorItem) {
157
- this.anchorIndex = 0;
158
- }
159
- else {
160
- if (this.anchorIndex < suggested.length - 1) {
161
- this.anchorIndex++;
162
- }
163
- }
164
- this.anchorItem = suggested[this.anchorIndex];
165
- if (this.anchorItem) {
166
- const current = this.repeater.elementForItem(this.anchorItem);
167
- current?.scrollIntoView({ behavior: "auto", block: "center", inline: "nearest" });
168
- }
169
- e.preventDefault();
170
- }
171
- break;
172
- case "ArrowUp":
173
- if (suggested) {
174
- if (!this.anchorItem) {
175
- return;
176
- }
177
- if (this.anchorIndex) {
178
- this.anchorIndex--;
179
- }
180
- this.anchorItem = suggested[this.anchorIndex];
181
- if (this.anchorItem) {
182
- const current = this.repeater.elementForItem(this.anchorItem);
183
- current?.scrollIntoView({ behavior: "auto", block: "center", inline: "nearest" });
184
- }
185
- e.preventDefault();
186
- }
187
- break;
188
- }
189
- }
111
+ const itemsInOpener = "items" in opener;
112
+ class Suggestions extends AtomPopover {
113
+ constructor() {
114
+ super(...arguments);
115
+ this.anchorItem = null;
116
+ this.anchorIndex = null;
190
117
  }
191
- return Suggestions.show(opener.element, { "anchor-left": "parent-left" });
192
- }
193
- export function SelectorCheckBox({ text, icon = "far fa-square", iconSelected = "fas fa-check-square", ...a }, ...nodes) {
194
- if (text) {
195
- return XNode.create("label", { "data-selector": "check-box", ...a },
196
- XNode.create("i", { class: icon, "data-click-event": "item-select" }),
197
- XNode.create("i", { class: iconSelected, "data-click-event": "item-deselect" }),
198
- XNode.create("span", { "data-no-wrap": "true", text: text }),
199
- ...nodes);
200
- }
201
- return XNode.create("label", { "data-selector": "check-box", ...a },
202
- XNode.create("i", { class: icon, "data-click-event": "item-select" }),
203
- XNode.create("i", { class: iconSelected, "data-click-event": "item-deselect" }),
204
- ...nodes);
205
- }
206
- class SelectAllControl extends AtomControl {
207
- preCreate() {
208
- this.element.setAttribute("data-select-all", "select-all");
209
- this.items = [];
210
- this.selectedItems = [];
211
- this.render(XNode.create(SelectAllControl, { "data-is-selected": Bind.oneWay(() => this.items.length > 0
212
- && this.items.length === this.selectedItems.length, false) }));
213
- this.bindEvent(this.element, "click", () => {
214
- const si = this.selectedItems;
215
- const items = this.items;
216
- if (!si) {
217
- return;
118
+ init() {
119
+ const disableSearch = opener.disableSearch;
120
+ this.renderer = XNode.create("div", {
121
+ "data-suggestion-popup": "suggestion-popup"
122
+ }, !disableSearch && XNode.create("input", {
123
+ type: "search",
124
+ value: Bind.sourceTwoWays(opener, x => x.source.search),
125
+ eventKeydown: e => this.onKey(e),
126
+ autofocus: true
127
+ }), XNode.create("div", {
128
+ class: "items"
129
+ }, XNode.create(AtomRepeater, {
130
+ class: "presenter",
131
+ selectedItem: Bind.source(this, x => x.source.anchorItem),
132
+ itemRenderer: itemRenderer,
133
+ visibilityFilter: Bind.source(opener, x => match(x.source.search)),
134
+ presenter: Bind.presenter(c => this.repeater = c),
135
+ eventItemClick: e => {
136
+ this.anchorItem = e.detail;
137
+ setTimeout(() => this.close(e.detail), 50);
138
+ },
139
+ items: Bind.source(opener, x => x.source.items)
140
+ })));
141
+ if (disableSearch) {
142
+ const {
143
+ input
144
+ } = opener;
145
+ if (input) {
146
+ this.disposables.add(opener.bindEvent(input, "keydown", e => this.onKey(e)));
147
+ }
148
+ }
149
+ }
150
+ async cancelSelection() {
151
+ await sleep(100);
152
+ if (!this.removed) {
153
+ this.close(opener.selectedItem);
154
+ }
155
+ }
156
+ onKey(e) {
157
+ const suggested = match ? opener.items?.filter(match(opener.search)) : opener.items;
158
+ switch (e.key) {
159
+ case "Escape":
160
+ this.cancelSelection().catch(console.error);
161
+ return;
162
+ case "Tab":
163
+ case "Enter":
164
+ const anchorItem = this.anchorItem;
165
+ if (!anchorItem) {
166
+ if (e.key === "Tab") {
167
+ e.preventDefault();
168
+ this.cancelSelection().catch(console.error);
218
169
  }
219
- if (!items) {
220
- return;
170
+ return;
171
+ }
172
+ this.anchorIndex = 0;
173
+ setTimeout(() => this.close(anchorItem), 10);
174
+ this.anchorItem = null;
175
+ opener.search = "";
176
+ e.preventDefault();
177
+ break;
178
+ case "ArrowDown":
179
+ if (suggested) {
180
+ if (!this.anchorItem) {
181
+ this.anchorIndex = 0;
182
+ } else {
183
+ if (this.anchorIndex < suggested.length - 1) {
184
+ this.anchorIndex++;
185
+ }
221
186
  }
222
- if (items.length === 0) {
223
- return;
187
+ this.anchorItem = suggested[this.anchorIndex];
188
+ if (this.anchorItem) {
189
+ const current = this.repeater.elementForItem(this.anchorItem);
190
+ current?.scrollIntoView({
191
+ behavior: "auto",
192
+ block: "center",
193
+ inline: "nearest"
194
+ });
224
195
  }
225
- if (items.length === si.length) {
226
- si.clear();
196
+ e.preventDefault();
197
+ }
198
+ break;
199
+ case "ArrowUp":
200
+ if (suggested) {
201
+ if (!this.anchorItem) {
202
+ return;
227
203
  }
228
- else {
229
- si.length = 0;
230
- si.push(...items);
231
- si.refresh();
204
+ if (this.anchorIndex) {
205
+ this.anchorIndex--;
232
206
  }
233
- });
207
+ this.anchorItem = suggested[this.anchorIndex];
208
+ if (this.anchorItem) {
209
+ const current = this.repeater.elementForItem(this.anchorItem);
210
+ current?.scrollIntoView({
211
+ behavior: "auto",
212
+ block: "center",
213
+ inline: "nearest"
214
+ });
215
+ }
216
+ e.preventDefault();
217
+ }
218
+ break;
219
+ }
234
220
  }
221
+ }
222
+ return Suggestions.show(opener.element, {
223
+ "anchor-left": "parent-left"
224
+ });
235
225
  }
236
- __decorate([
237
- BindableProperty,
238
- __metadata("design:type", Array)
239
- ], SelectAllControl.prototype, "items", void 0);
240
- __decorate([
241
- BindableProperty,
242
- __metadata("design:type", Array)
243
- ], SelectAllControl.prototype, "selectedItems", void 0);
244
- export function SelectAll({ text = "Select All", icon = "far fa-square", iconSelected = "fas fa-check-square", ...a }, ...nodes) {
245
- if (text) {
246
- return XNode.create(SelectAllControl, { for: "label", ...a },
247
- XNode.create("i", { class: icon, "data-ui-type": "item-select" }),
248
- XNode.create("i", { class: iconSelected, "data-ui-type": "item-deselect" }),
249
- XNode.create("span", { "data-no-wrap": "true", text: text }));
250
- }
251
- return XNode.create(SelectAllControl, { for: "label", ...a },
252
- XNode.create("i", { class: icon, "data-ui-type": "item-select" }),
253
- XNode.create("i", { class: iconSelected, "data-ui-type": "item-deselect" }),
254
- ...nodes);
226
+ export function SelectorCheckBox({
227
+ text,
228
+ icon = "far fa-square",
229
+ iconSelected = "fas fa-check-square",
230
+ ...a
231
+ }, ...nodes) {
232
+ if (text) {
233
+ return XNode.create("label", {
234
+ "data-selector": "check-box",
235
+ ...a
236
+ }, XNode.create("i", {
237
+ class: icon,
238
+ "data-click-event": "item-select"
239
+ }), XNode.create("i", {
240
+ class: iconSelected,
241
+ "data-click-event": "item-deselect"
242
+ }), XNode.create("span", {
243
+ "data-no-wrap": "true",
244
+ text: text
245
+ }), ...nodes);
246
+ }
247
+ return XNode.create("label", {
248
+ "data-selector": "check-box",
249
+ ...a
250
+ }, XNode.create("i", {
251
+ class: icon,
252
+ "data-click-event": "item-select"
253
+ }), XNode.create("i", {
254
+ class: iconSelected,
255
+ "data-click-event": "item-deselect"
256
+ }), ...nodes);
255
257
  }
256
- export function disposeChildren(owner, e) {
257
- if (!e) {
258
+ class SelectAllControl extends AtomControl {
259
+ preCreate() {
260
+ this.element.setAttribute("data-select-all", "select-all");
261
+ this.items = [];
262
+ this.selectedItems = [];
263
+ this.render(XNode.create(SelectAllControl, {
264
+ "data-is-selected": Bind.oneWay(() => this.items.length > 0 && this.items.length === this.selectedItems.length, false)
265
+ }));
266
+ this.bindEvent(this.element, "click", () => {
267
+ const si = this.selectedItems;
268
+ const items = this.items;
269
+ if (!si) {
258
270
  return;
259
- }
260
- let s = e.firstElementChild;
261
- while (s) {
262
- const c = s;
263
- s = s.nextElementSibling;
264
- const ac = c.atomControl;
265
- if (ac) {
266
- ac.dispose();
267
- continue;
268
- }
269
- disposeChildren(owner, c);
270
- owner.unbind(c);
271
- owner.unbindEvent(c);
272
- }
273
- e.innerHTML = "";
271
+ }
272
+ if (!items) {
273
+ return;
274
+ }
275
+ if (items.length === 0) {
276
+ return;
277
+ }
278
+ if (items.length === si.length) {
279
+ si.clear();
280
+ } else {
281
+ si.length = 0;
282
+ si.push(...items);
283
+ si.refresh();
284
+ }
285
+ });
286
+ }
274
287
  }
275
- export function disposeChild(owner, e) {
276
- const ac = e.atomControl;
288
+ __decorate([BindableProperty, __metadata("design:type", Array)], SelectAllControl.prototype, "items", void 0);
289
+ __decorate([BindableProperty, __metadata("design:type", Array)], SelectAllControl.prototype, "selectedItems", void 0);
290
+ export function SelectAll({
291
+ text = "Select All",
292
+ icon = "far fa-square",
293
+ iconSelected = "fas fa-check-square",
294
+ ...a
295
+ }, ...nodes) {
296
+ if (text) {
297
+ return XNode.create(SelectAllControl, {
298
+ for: "label",
299
+ ...a
300
+ }, XNode.create("i", {
301
+ class: icon,
302
+ "data-ui-type": "item-select"
303
+ }), XNode.create("i", {
304
+ class: iconSelected,
305
+ "data-ui-type": "item-deselect"
306
+ }), XNode.create("span", {
307
+ "data-no-wrap": "true",
308
+ text: text
309
+ }));
310
+ }
311
+ return XNode.create(SelectAllControl, {
312
+ for: "label",
313
+ ...a
314
+ }, XNode.create("i", {
315
+ class: icon,
316
+ "data-ui-type": "item-select"
317
+ }), XNode.create("i", {
318
+ class: iconSelected,
319
+ "data-ui-type": "item-deselect"
320
+ }), ...nodes);
321
+ }
322
+ export function disposeChildren(owner, e) {
323
+ if (!e) {
324
+ return;
325
+ }
326
+ let s = e.firstElementChild;
327
+ while (s) {
328
+ const c = s;
329
+ s = s.nextElementSibling;
330
+ const ac = c.atomControl;
277
331
  if (ac) {
278
- ac.dispose();
279
- return;
332
+ ac.dispose();
333
+ continue;
280
334
  }
281
- disposeChildren(owner, e);
282
- owner.unbind(e);
283
- owner.unbindEvent(e);
284
- e.remove();
335
+ disposeChildren(owner, c);
336
+ owner.unbind(c);
337
+ owner.unbindEvent(c);
338
+ }
339
+ e.innerHTML = "";
340
+ }
341
+ export function disposeChild(owner, e) {
342
+ const ac = e.atomControl;
343
+ if (ac) {
344
+ ac.dispose();
345
+ return;
346
+ }
347
+ disposeChildren(owner, e);
348
+ owner.unbind(e);
349
+ owner.unbindEvent(e);
350
+ e.remove();
285
351
  }
286
352
  export function defaultComparer(left, right) {
287
- if (left && right) {
288
- if (left instanceof Date) {
289
- if (right instanceof Date) {
290
- return left.getTime() === right.getTime();
291
- }
292
- return false;
293
- }
353
+ if (left && right) {
354
+ if (left instanceof Date) {
355
+ if (right instanceof Date) {
356
+ return left.getTime() === right.getTime();
357
+ }
358
+ return false;
294
359
  }
295
- return left === right;
360
+ }
361
+ return left === right;
296
362
  }
297
- const getFirstChild = (container) => {
298
- let child = container.firstElementChild;
299
- while (child && !child.hasAttribute("data-item-index")) {
300
- child = child.nextElementSibling;
301
- }
302
- return child;
363
+ const getFirstChild = container => {
364
+ let child = container.firstElementChild;
365
+ while (child && !child.hasAttribute("data-item-index")) {
366
+ child = child.nextElementSibling;
367
+ }
368
+ return child;
303
369
  };
304
370
  function updateDragDrop(e, force = false) {
305
- if (!e) {
306
- return;
371
+ if (!e) {
372
+ return;
373
+ }
374
+ if (force) {
375
+ e.draggable = false;
376
+ } else {
377
+ force = e.draggable;
378
+ }
379
+ e = e.firstElementChild;
380
+ while (e) {
381
+ updateDragDrop(e, force);
382
+ e = e.nextElementSibling;
383
+ }
384
+ }
385
+ export default class AtomRepeater extends AtomControl {
386
+ constructor() {
387
+ super(...arguments);
388
+ this.bubbleEvents = true;
389
+ }
390
+ static from(element) {
391
+ while (element) {
392
+ const {
393
+ atomControl
394
+ } = element;
395
+ if (atomControl instanceof AtomRepeater) {
396
+ return atomControl;
397
+ }
398
+ element = element.parentElement;
307
399
  }
308
- if (force) {
309
- e.draggable = false;
400
+ }
401
+ static itemFromElement(e, ar = this.from(e)) {
402
+ const da = new DataAttributes(e, ar);
403
+ const recreate = da.get("data-recreate");
404
+ const header = da.get("data-header");
405
+ const footer = da.get("data-footer");
406
+ const itemIndex = da.get("data-item-index");
407
+ const itemPath = da.get("data-item-path");
408
+ let clickEvent = da.get("data-click-event") || (header ? "headerClick" : footer ? "footerClick" : "itemClick");
409
+ clickEvent = clickEvent.replace(/-([a-z])/g, g => g[1].toUpperCase());
410
+ const index = ~~itemIndex;
411
+ const item = ar.items[index];
412
+ let nestedItem = null;
413
+ if (item) {
414
+ if (itemPath || false) {
415
+ nestedItem = ItemPath.get(item, itemPath.trim());
416
+ }
310
417
  }
311
- else {
312
- force = e.draggable;
418
+ return {
419
+ recreate,
420
+ header,
421
+ footer,
422
+ itemPath,
423
+ itemIndex,
424
+ item,
425
+ nestedItem,
426
+ clickEvent,
427
+ target: e
428
+ };
429
+ }
430
+ set refreshEventScope(v) {
431
+ this.registerDisposable(v.listen(ce => {
432
+ this.refreshItem(ce.detail);
433
+ }));
434
+ }
435
+ get allSelected() {
436
+ const selectedItems = this.selectedItems;
437
+ const items = this.items;
438
+ if (!(items && selectedItems)) {
439
+ return false;
313
440
  }
314
- e = e.firstElementChild;
315
- while (e) {
316
- updateDragDrop(e, force);
317
- e = e.nextElementSibling;
441
+ return items.length && items.length === selectedItems.length;
442
+ }
443
+ get value() {
444
+ if (this.initialValue !== undefined) {
445
+ return this.initialValue;
318
446
  }
319
- }
320
- export default class AtomRepeater extends AtomControl {
321
- constructor() {
322
- super(...arguments);
323
- this.bubbleEvents = true;
324
- }
325
- static from(element) {
326
- while (element) {
327
- const { atomControl } = element;
328
- if (atomControl instanceof AtomRepeater) {
329
- return atomControl;
330
- }
331
- element = element.parentElement;
332
- }
447
+ const sp = this.selectedItem;
448
+ if (sp === undefined) {
449
+ return sp;
333
450
  }
334
- static itemFromElement(e, ar = this.from(e)) {
335
- const da = new DataAttributes(e, ar);
336
- const recreate = da.get("data-recreate");
337
- const header = da.get("data-header");
338
- const footer = da.get("data-footer");
339
- const itemIndex = da.get("data-item-index");
340
- const itemPath = da.get("data-item-path");
341
- let clickEvent = da.get("data-click-event") || (header
342
- ? "headerClick"
343
- : (footer ? "footerClick" : "itemClick"));
344
- clickEvent = clickEvent.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
345
- const index = ~~itemIndex;
346
- const item = ar.items[index];
347
- let nestedItem = null;
348
- if (item) {
349
- if (itemPath || false) {
350
- nestedItem = ItemPath.get(item, itemPath.trim());
351
- }
352
- }
353
- return {
354
- recreate,
355
- header,
356
- footer,
357
- itemPath,
358
- itemIndex,
359
- item,
360
- nestedItem,
361
- clickEvent,
362
- target: e
363
- };
364
- }
365
- set refreshEventScope(v) {
366
- this.registerDisposable(v.listen((ce) => {
367
- this.refreshItem(ce.detail);
368
- }));
369
- }
370
- get allSelected() {
371
- const selectedItems = this.selectedItems;
451
+ const vp = this.valuePath ?? SameObjectValue;
452
+ return vp(sp);
453
+ }
454
+ set value(v) {
455
+ this.initialValue = v;
456
+ if (!this.items || !this.items.length) {
457
+ AtomBinder.refreshValue(this, "value");
458
+ return;
459
+ }
460
+ const vp = this.valuePath ?? SameObjectValue;
461
+ const c = this.comparer ?? defaultComparer;
462
+ const selectedItem = this.items.find(item => c(vp(item), v));
463
+ this.selectedItem = selectedItem;
464
+ delete this.initialValue;
465
+ }
466
+ get selectedItem() {
467
+ return this.selectedItems?.[0];
468
+ }
469
+ set selectedItem(value) {
470
+ const si = this.selectedItems ??= [];
471
+ const first = si[0];
472
+ if (value === first) {
473
+ return;
474
+ }
475
+ si.set(0, value);
476
+ }
477
+ onPropertyChanged(name) {
478
+ switch (name) {
479
+ case "items":
480
+ this.itemsDisposable?.dispose();
372
481
  const items = this.items;
373
- if (!(items && selectedItems)) {
374
- return false;
482
+ const d = items?.watch((target, type, index, item) => {
483
+ switch (type) {
484
+ case "add":
485
+ case "remove":
486
+ case "set":
487
+ this.updatePartial(type, index, item);
488
+ break;
489
+ default:
490
+ this.updateItems();
491
+ break;
492
+ }
493
+ this.dispatchCustomEvent("items-updated", {
494
+ type,
495
+ items,
496
+ index
497
+ });
498
+ AtomBinder.refreshValue(this, "selectedItem");
499
+ AtomBinder.refreshValue(this, "value");
500
+ });
501
+ if (d) {
502
+ this.itemsDisposable = this.registerDisposable(d);
503
+ }
504
+ const iv = this.initialValue;
505
+ if (iv) {
506
+ this.value = iv;
507
+ }
508
+ this.updateItems();
509
+ this.dispatchCustomEvent("items-updated", {
510
+ type: "reset",
511
+ items,
512
+ index: 0
513
+ });
514
+ if (this.scrollToSelection) {
515
+ this.bringSelectionIntoView();
375
516
  }
376
- return items.length && items.length === selectedItems.length;
517
+ break;
518
+ case "selectedItems":
519
+ this.selectedItemsDisposable?.dispose();
520
+ const selectedItems = this.selectedItems;
521
+ const sd = selectedItems?.watch(() => {
522
+ this.updateClasses();
523
+ if (this.scrollToSelection) {
524
+ this.bringSelectionIntoView();
525
+ }
526
+ if (this.selectedItem) {
527
+ delete this.initialValue;
528
+ }
529
+ AtomBinder.refreshValue(this, "selectedItem");
530
+ AtomBinder.refreshValue(this, "value");
531
+ AtomBinder.refreshValue(this, "allSelected");
532
+ this.dispatchCustomEvent("selection-updated", selectedItems);
533
+ });
534
+ if (sd) {
535
+ this.selectedItemsDisposable = this.registerDisposable(sd);
536
+ }
537
+ this.updateClasses();
538
+ this.dispatchCustomEvent("selection-updated", selectedItems);
539
+ AtomBinder.refreshValue(this, "allSelected");
540
+ break;
541
+ case "itemRenderer":
542
+ case "watch":
543
+ this.updateItems();
544
+ break;
545
+ case "visibilityFilter":
546
+ this.updateVisibility();
547
+ break;
548
+ case "header":
549
+ case "headerRenderer":
550
+ this.updateHeaderFooter("header", this.headerPresenter, this.header, this.headerRenderer, true);
551
+ break;
552
+ case "footer":
553
+ case "footerRenderer":
554
+ this.updateHeaderFooter("footer", this.footerPresenter, this.footer, this.footerRenderer);
555
+ break;
377
556
  }
378
- get value() {
379
- if (this.initialValue !== undefined) {
380
- return this.initialValue;
381
- }
382
- const sp = this.selectedItem;
383
- if (sp === undefined) {
384
- return sp;
385
- }
386
- const vp = this.valuePath ?? SameObjectValue;
387
- return vp(sp);
557
+ }
558
+ bringSelectionIntoView(force) {
559
+ if (force) {
560
+ const selection = this.selectedItem;
561
+ if (selection) {
562
+ const element = this.elementForItem(selection);
563
+ element?.scrollIntoView();
564
+ }
565
+ return;
388
566
  }
389
- set value(v) {
390
- this.initialValue = v;
391
- if (!this.items || !this.items.length) {
392
- AtomBinder.refreshValue(this, "value");
393
- return;
394
- }
395
- const vp = this.valuePath ?? SameObjectValue;
396
- const c = this.comparer ?? defaultComparer;
397
- const selectedItem = this.items.find((item) => c(vp(item), v));
398
- this.selectedItem = selectedItem;
399
- delete this.initialValue;
567
+ if (this.bringIntoViewId) {
568
+ clearTimeout(this.bringIntoViewId);
400
569
  }
401
- get selectedItem() {
402
- return this.selectedItems?.[0];
570
+ this.bringIntoViewId = setTimeout(() => {
571
+ clearTimeout(this.bringIntoViewId);
572
+ this.bringIntoViewId = undefined;
573
+ this.bringSelectionIntoView(true);
574
+ }, 100);
575
+ }
576
+ forEach(action, container) {
577
+ container ??= this.itemsPresenter ?? this.element;
578
+ const items = this.items;
579
+ let start = getFirstChild(container);
580
+ while (start) {
581
+ const index = start.getAttribute("data-item-index");
582
+ const item = items[~~index];
583
+ action(item, start);
584
+ start = start.nextElementSibling;
403
585
  }
404
- set selectedItem(value) {
405
- const si = this.selectedItems ??= [];
406
- const first = si[0];
407
- if (value === first) {
408
- return;
409
- }
410
- si.set(0, value);
411
- }
412
- onPropertyChanged(name) {
413
- switch (name) {
414
- case "items":
415
- this.itemsDisposable?.dispose();
416
- const items = this.items;
417
- const d = items?.watch((target, type, index, item) => {
418
- switch (type) {
419
- case "add":
420
- case "remove":
421
- case "set":
422
- this.updatePartial(type, index, item);
423
- break;
424
- default:
425
- this.updateItems();
426
- break;
427
- }
428
- this.dispatchCustomEvent("items-updated", { type, items, index });
429
- AtomBinder.refreshValue(this, "selectedItem");
430
- AtomBinder.refreshValue(this, "value");
431
- });
432
- if (d) {
433
- this.itemsDisposable = this.registerDisposable(d);
434
- }
435
- const iv = this.initialValue;
436
- if (iv) {
437
- this.value = iv;
438
- }
439
- this.updateItems();
440
- this.dispatchCustomEvent("items-updated", { type: "reset", items, index: 0 });
441
- if (this.scrollToSelection) {
442
- this.bringSelectionIntoView();
443
- }
444
- break;
445
- case "selectedItems":
446
- this.selectedItemsDisposable?.dispose();
447
- const selectedItems = this.selectedItems;
448
- const sd = selectedItems?.watch(() => {
449
- this.updateClasses();
450
- if (this.scrollToSelection) {
451
- this.bringSelectionIntoView();
452
- }
453
- if (this.selectedItem) {
454
- delete this.initialValue;
455
- }
456
- AtomBinder.refreshValue(this, "selectedItem");
457
- AtomBinder.refreshValue(this, "value");
458
- AtomBinder.refreshValue(this, "allSelected");
459
- this.dispatchCustomEvent("selection-updated", selectedItems);
460
- });
461
- if (sd) {
462
- this.selectedItemsDisposable = this.registerDisposable(sd);
463
- }
464
- this.updateClasses();
465
- this.dispatchCustomEvent("selection-updated", selectedItems);
466
- AtomBinder.refreshValue(this, "allSelected");
467
- break;
468
- case "itemRenderer":
469
- case "watch":
470
- this.updateItems();
471
- break;
472
- case "visibilityFilter":
473
- this.updateVisibility();
474
- break;
475
- case "header":
476
- case "headerRenderer":
477
- this.updateHeaderFooter("header", this.headerPresenter, this.header, this.headerRenderer, true);
478
- break;
479
- case "footer":
480
- case "footerRenderer":
481
- this.updateHeaderFooter("footer", this.footerPresenter, this.footer, this.footerRenderer);
482
- break;
483
- }
586
+ }
587
+ *any(fx, itemSelector, container) {
588
+ container ??= this.itemsPresenter ?? this.element;
589
+ const items = this.items;
590
+ let node = getFirstChild(container);
591
+ while (node) {
592
+ const index = node.getAttribute("data-item-index");
593
+ const item = items[~~index];
594
+ let element = node;
595
+ if (itemSelector) {
596
+ element = element.querySelector(itemSelector);
597
+ }
598
+ const ie = {
599
+ item,
600
+ element
601
+ };
602
+ if (fx) {
603
+ if (fx(item)) {
604
+ yield ie;
605
+ }
606
+ continue;
607
+ }
608
+ yield ie;
609
+ node = node.nextElementSibling;
484
610
  }
485
- bringSelectionIntoView(force) {
486
- if (force) {
487
- const selection = this.selectedItem;
488
- if (selection) {
489
- const element = this.elementForItem(selection);
490
- element?.scrollIntoView();
491
- }
492
- return;
493
- }
494
- if (this.bringIntoViewId) {
495
- clearTimeout(this.bringIntoViewId);
496
- }
497
- this.bringIntoViewId = setTimeout(() => {
498
- clearTimeout(this.bringIntoViewId);
499
- this.bringIntoViewId = undefined;
500
- this.bringSelectionIntoView(true);
501
- }, 100);
502
- }
503
- forEach(action, container) {
504
- container ??= this.itemsPresenter ?? this.element;
505
- const items = this.items;
506
- let start = getFirstChild(container);
507
- while (start) {
508
- const index = start.getAttribute("data-item-index");
509
- const item = items[~~index];
510
- action(item, start);
511
- start = start.nextElementSibling;
512
- }
611
+ }
612
+ *all(container) {
613
+ container ??= this.itemsPresenter ?? this.element;
614
+ const items = this.items;
615
+ let element = getFirstChild(container);
616
+ while (element) {
617
+ const index = element.getAttribute("data-item-index");
618
+ const item = items[~~index];
619
+ yield {
620
+ item,
621
+ element
622
+ };
623
+ element = element.nextElementSibling;
513
624
  }
514
- *any(fx, itemSelector, container) {
515
- container ??= this.itemsPresenter ?? this.element;
516
- const items = this.items;
517
- let node = getFirstChild(container);
518
- while (node) {
519
- const index = node.getAttribute("data-item-index");
520
- const item = items[~~index];
521
- let element = node;
522
- if (itemSelector) {
523
- element = element.querySelector(itemSelector);
524
- }
525
- const ie = { item, element };
526
- if (fx) {
527
- if (fx(item)) {
528
- yield ie;
529
- }
530
- continue;
531
- }
532
- yield ie;
533
- node = node.nextElementSibling;
534
- }
625
+ }
626
+ elementAt(index, container) {
627
+ container ??= this.itemsPresenter ?? this.element;
628
+ const indexText = index.toString();
629
+ const element = ChildEnumerator.find(container, e => e.getAttribute("data-item-index") === indexText);
630
+ return element;
631
+ }
632
+ elementForItem(itemToFind, container) {
633
+ const index = this.items.indexOf(itemToFind);
634
+ return this.elementAt(index, container);
635
+ }
636
+ refreshItem(item, fx, index = -1) {
637
+ if (index === -1) {
638
+ index = this.items.indexOf(item);
535
639
  }
536
- *all(container) {
537
- container ??= this.itemsPresenter ?? this.element;
538
- const items = this.items;
539
- let element = getFirstChild(container);
540
- while (element) {
541
- const index = element.getAttribute("data-item-index");
542
- const item = items[~~index];
543
- yield { item, element };
544
- element = element.nextElementSibling;
545
- }
640
+ if (fx?.then) {
641
+ const finalize = v => {
642
+ this.refreshItem(item, v, index);
643
+ };
644
+ fx.then(finalize, finalize);
645
+ return;
546
646
  }
547
- elementAt(index, container) {
548
- container ??= this.itemsPresenter ?? this.element;
549
- const indexText = index.toString();
550
- const element = ChildEnumerator.find(container, (e) => e.getAttribute("data-item-index") === indexText);
551
- return element;
647
+ if (fx instanceof MergeNode) {
648
+ this.mergeItem(index, fx);
649
+ return;
552
650
  }
553
- elementForItem(itemToFind, container) {
554
- const index = this.items.indexOf(itemToFind);
555
- return this.elementAt(index, container);
651
+ this.updatePartial("set", index, item);
652
+ }
653
+ mergeItem(index, m) {
654
+ const item = this.items[index];
655
+ if (!item) {
656
+ return;
556
657
  }
557
- refreshItem(item, fx, index = -1) {
558
- if (index === -1) {
559
- index = this.items.indexOf(item);
560
- }
561
- if (fx?.then) {
562
- const finalize = (v) => {
563
- this.refreshItem(item, v, index);
564
- };
565
- fx.then(finalize, finalize);
566
- return;
567
- }
568
- if (fx instanceof MergeNode) {
569
- this.mergeItem(index, fx);
570
- return;
571
- }
572
- this.updatePartial("set", index, item);
658
+ if (m.classes?.[0]?.remove) {
659
+ this.items.removeAt(index);
660
+ return;
573
661
  }
574
- mergeItem(index, m) {
575
- const item = this.items[index];
576
- if (!item) {
577
- return;
578
- }
579
- if (m.classes?.[0]?.remove) {
580
- this.items.removeAt(index);
581
- return;
582
- }
583
- const container = this.itemsPresenter ?? this.element;
584
- const node = this.itemRenderer(item, index, this);
585
- const sourceElement = document.createElement("div");
586
- sourceElement.style.display = "none";
587
- container.appendChild(sourceElement);
588
- this.render(node, sourceElement);
589
- const targetElement = this.elementAt(index);
590
- for (const iterator of m.classes) {
591
- if (typeof iterator === "string") {
592
- const source = sourceElement.querySelectorAll(iterator);
593
- const target = targetElement.querySelectorAll(iterator);
594
- for (let i = 0; i < source.length && i < target.length; i++) {
595
- const element = source[i];
596
- const te = target[i];
597
- for (const name of te.getAttributeNames()) {
598
- te.removeAttribute(name);
599
- }
600
- te.innerHTML = element.innerHTML;
601
- for (const name of element.getAttributeNames()) {
602
- te.setAttribute(name, element.getAttribute(name));
603
- }
604
- }
605
- continue;
606
- }
607
- if (iterator.parent) {
608
- const targetParent = /self|\*/.test(iterator.parent)
609
- ? targetElement
610
- : targetElement.querySelector(iterator.parent);
611
- if (!targetParent) {
612
- continue;
613
- }
614
- for (const i of Array.from(targetElement.querySelectorAll(iterator.replace))) {
615
- i.remove();
616
- }
617
- for (const i of Array.from(sourceElement.querySelectorAll(iterator.replace))) {
618
- targetParent.appendChild(i);
619
- }
620
- continue;
621
- }
622
- let targetPrevious = targetElement.querySelector(iterator.after);
623
- for (const i of Array.from(targetElement.querySelectorAll(iterator.replace))) {
624
- i.remove();
625
- }
626
- for (const i of Array.from(sourceElement.querySelectorAll(iterator.replace))) {
627
- targetPrevious.insertAdjacentElement("afterend", i);
628
- targetPrevious = i;
629
- }
630
- }
631
- this.dispose(sourceElement);
632
- sourceElement.remove();
662
+ const container = this.itemsPresenter ?? this.element;
663
+ const node = this.itemRenderer(item, index, this);
664
+ const sourceElement = document.createElement("div");
665
+ sourceElement.style.display = "none";
666
+ container.appendChild(sourceElement);
667
+ this.render(node, sourceElement);
668
+ const targetElement = this.elementAt(index);
669
+ for (const iterator of m.classes) {
670
+ if (typeof iterator === "string") {
671
+ const source = sourceElement.querySelectorAll(iterator);
672
+ const target = targetElement.querySelectorAll(iterator);
673
+ for (let i = 0; i < source.length && i < target.length; i++) {
674
+ const element = source[i];
675
+ const te = target[i];
676
+ for (const name of te.getAttributeNames()) {
677
+ te.removeAttribute(name);
678
+ }
679
+ te.innerHTML = element.innerHTML;
680
+ for (const name of element.getAttributeNames()) {
681
+ te.setAttribute(name, element.getAttribute(name));
682
+ }
683
+ }
684
+ continue;
685
+ }
686
+ if (iterator.parent) {
687
+ const targetParent = /self|\*/.test(iterator.parent) ? targetElement : targetElement.querySelector(iterator.parent);
688
+ if (!targetParent) {
689
+ continue;
690
+ }
691
+ for (const i of Array.from(targetElement.querySelectorAll(iterator.replace))) {
692
+ i.remove();
693
+ }
694
+ for (const i of Array.from(sourceElement.querySelectorAll(iterator.replace))) {
695
+ targetParent.appendChild(i);
696
+ }
697
+ continue;
698
+ }
699
+ let targetPrevious = targetElement.querySelector(iterator.after);
700
+ for (const i of Array.from(targetElement.querySelectorAll(iterator.replace))) {
701
+ i.remove();
702
+ }
703
+ for (const i of Array.from(sourceElement.querySelectorAll(iterator.replace))) {
704
+ targetPrevious.insertAdjacentElement("afterend", i);
705
+ targetPrevious = i;
706
+ }
633
707
  }
634
- updatePartial(key, index, item, container) {
635
- const items = this.items;
636
- if (!items) {
637
- return;
638
- }
639
- const ir = this.itemRenderer;
640
- if (!ir) {
641
- return;
642
- }
643
- container ??= this.itemsPresenter ?? this.element;
644
- let start = getFirstChild(container);
645
- let ei;
646
- while (start) {
647
- ei = ~~start.getAttribute("data-item-index");
648
- if (ei === index) {
649
- break;
650
- }
651
- start = start.nextElementSibling;
652
- }
653
- if (key !== "add" && !start) {
654
- return;
655
- }
656
- const vp = this.valuePath ?? ((it) => it);
657
- const si = (this.selectedItems ?? []).map(vp);
658
- const isRemove = key === "remove";
659
- if (isRemove || key === "set") {
660
- const current = start;
661
- start = start.nextElementSibling;
662
- const ac = current.atomControl;
663
- if (ac) {
664
- ac.dispose();
665
- }
666
- else {
667
- this.unbind(current);
668
- this.unbindEvent(current);
669
- }
670
- current.remove();
671
- }
672
- const end = this.footerElement?.parentElement === container ? this.footerElement : null;
673
- if (!isRemove) {
674
- const en = ir(item, index, this);
675
- const ea = en.attributes ??= {};
676
- const v = vp(item);
677
- const e = document.createElement(ea.for ?? en.name ?? "div");
678
- e.setAttribute("data-item-index", `${index++}`);
679
- if (si.indexOf(v) !== -1) {
680
- e.setAttribute("data-selected-item", "true");
681
- }
682
- else {
683
- e.removeAttribute("data-selected-item");
684
- }
685
- if (this.enableDragDrop) {
686
- updateDragDrop(e);
687
- }
688
- if (start) {
689
- container.insertBefore(e, start);
690
- }
691
- else if (end) {
692
- container.insertBefore(e, end);
693
- }
694
- else {
695
- container.appendChild(e);
696
- }
697
- this.render(en, e, this.creator || this);
698
- }
699
- while (start) {
700
- const ci = items[index];
701
- const cv = vp(ci);
702
- start.setAttribute("data-item-index", `${index++}`);
703
- if (si.indexOf(cv) !== -1) {
704
- start.setAttribute("data-selected-item", "true");
705
- }
706
- else {
707
- start.removeAttribute("data-selected-item");
708
- }
709
- start = start.nextElementSibling;
710
- if (start?.hasAttribute("data-footer")) {
711
- break;
712
- }
713
- }
708
+ this.dispose(sourceElement);
709
+ sourceElement.remove();
710
+ }
711
+ updatePartial(key, index, item, container) {
712
+ const items = this.items;
713
+ if (!items) {
714
+ return;
714
715
  }
715
- updateItems(container, force) {
716
- if (this.deferUpdates && !force) {
717
- if (this.deferredUpdateId) {
718
- return;
719
- }
720
- this.deferredUpdateId = setTimeout(() => {
721
- this.deferredUpdateId = 0;
722
- this.updateItems(container, true);
723
- }, 1);
724
- return;
725
- }
726
- container ??= this.itemsPresenter ?? this.element;
727
- if (!container) {
728
- return;
729
- }
730
- disposeChildren(this, container);
731
- this.onPropertyChanged("header");
732
- const ir = this.itemRenderer;
733
- if (!ir) {
734
- this.onPropertyChanged("footer");
735
- return;
736
- }
737
- const items = this.items;
738
- if (!items) {
739
- this.onPropertyChanged("footer");
740
- return;
741
- }
742
- const vp = this.valuePath ?? ((it) => it);
743
- const si = (this.selectedItems ?? []).map(vp);
744
- let i = 0;
745
- for (const iterator of items) {
746
- const index = i++;
747
- const e = ir(iterator, index, this);
748
- const ea = e.attributes ??= {};
749
- const v = vp(iterator);
750
- const element = document.createElement(ea.for ?? e.name ?? "div");
751
- element.setAttribute("data-item-index", `${index}`);
752
- if (si.indexOf(v) !== -1) {
753
- element.setAttribute("data-selected-item", "true");
754
- }
755
- else {
756
- element.removeAttribute("data-selected-item");
757
- }
758
- this.render(e, element, this.creator || this);
759
- if (this.enableDragDrop) {
760
- updateDragDrop(element);
761
- }
762
- container.appendChild(element);
763
- }
764
- this.onPropertyChanged("footer");
716
+ const ir = this.itemRenderer;
717
+ if (!ir) {
718
+ return;
765
719
  }
766
- render(node, e, creator) {
767
- if (!this.creator && this !== creator) {
768
- this.creator = creator;
769
- }
770
- this.render = super.render;
771
- return super.render(node, e, creator);
720
+ container ??= this.itemsPresenter ?? this.element;
721
+ let start = getFirstChild(container);
722
+ let ei;
723
+ while (start) {
724
+ ei = ~~start.getAttribute("data-item-index");
725
+ if (ei === index) {
726
+ break;
727
+ }
728
+ start = start.nextElementSibling;
772
729
  }
773
- preCreate() {
774
- this.orderBy = null;
775
- this.mergeOnRefresh = false;
776
- this.selectOnClick = false;
777
- this.element.setAttribute("data-click-event", "item-click");
730
+ if (key !== "add" && !start) {
731
+ return;
778
732
  }
779
- dispatchCustomEvent(type, detail) {
780
- if (!this.element) {
781
- return;
782
- }
783
- const eventName = this.element.getAttribute("data-" + type + "-event");
784
- type = StringHelper.fromHyphenToCamel(eventName ?? type);
785
- this.element.dispatchEvent(new CustomEvent(type, {
786
- detail,
787
- bubbles: eventName !== null,
788
- cancelable: true
789
- }));
790
- }
791
- updateClasses() {
792
- const container = this.itemsPresenter ?? this.element;
793
- const items = this.items;
794
- let element = getFirstChild(container);
795
- const vp = this.valuePath ?? ((i) => i);
796
- const si = (this.selectedItems ?? []).map(vp);
797
- while (element) {
798
- const index = ~~element.getAttribute("data-item-index");
799
- const item = items[index];
800
- const v = vp(item);
801
- if (si.indexOf(v) !== -1) {
802
- element.setAttribute("data-selected-item", "true");
803
- }
804
- else {
805
- element.removeAttribute("data-selected-item");
806
- }
807
- element = element.nextElementSibling;
808
- }
733
+ const vp = this.valuePath ?? (it => it);
734
+ const si = (this.selectedItems ?? []).map(vp);
735
+ const isRemove = key === "remove";
736
+ if (isRemove || key === "set") {
737
+ const current = start;
738
+ start = start.nextElementSibling;
739
+ const ac = current.atomControl;
740
+ if (ac) {
741
+ ac.dispose();
742
+ } else {
743
+ this.unbind(current);
744
+ this.unbindEvent(current);
745
+ }
746
+ current.remove();
809
747
  }
810
- updateVisibility() {
811
- const container = this.itemsPresenter ?? this.element;
812
- const items = this.items;
813
- let element = container.firstElementChild;
814
- const vf = this.visibilityFilter ?? MatchTrue;
815
- while (element) {
816
- const index = ~~element.getAttribute("data-item-index");
817
- const item = items[index];
818
- if (vf(item)) {
819
- element.removeAttribute("data-ui-display");
820
- }
821
- else {
822
- element.setAttribute("data-ui-display", "none");
823
- }
824
- element = element.nextElementSibling;
825
- }
748
+ const end = this.footerElement?.parentElement === container ? this.footerElement : null;
749
+ if (!isRemove) {
750
+ const en = ir(item, index, this);
751
+ const ea = en.attributes ??= {};
752
+ const v = vp(item);
753
+ const e = document.createElement(ea.for ?? en.name ?? "div");
754
+ e.setAttribute("data-item-index", `${index++}`);
755
+ if (si.indexOf(v) !== -1) {
756
+ e.setAttribute("data-selected-item", "true");
757
+ } else {
758
+ e.removeAttribute("data-selected-item");
759
+ }
760
+ if (this.enableDragDrop) {
761
+ updateDragDrop(e);
762
+ }
763
+ if (start) {
764
+ container.insertBefore(e, start);
765
+ } else if (end) {
766
+ container.insertBefore(e, end);
767
+ } else {
768
+ container.appendChild(e);
769
+ }
770
+ this.render(en, e, this.creator || this);
826
771
  }
827
- updateHeaderFooter(name, presenter, item, itemRenderer, insert) {
828
- presenter ??= this.itemsPresenter ??= this.element;
829
- if (!presenter) {
830
- this[name + "Element"] = null;
831
- return;
832
- }
833
- let current;
834
- if (insert) {
835
- current = presenter.firstElementChild;
836
- while (current && current.dataset[name] !== name) {
837
- current = current.nextElementSibling;
838
- }
839
- }
840
- else {
841
- current = presenter.lastElementChild;
842
- while (current && current.dataset[name] !== name) {
843
- current = current.previousElementSibling;
844
- }
845
- }
846
- if (current) {
847
- disposeChild(this, current);
848
- this[name + "Element"] = null;
849
- }
850
- if (!(item && itemRenderer)) {
851
- return;
852
- }
853
- const node = itemRenderer(item);
854
- const element = document.createElement(node.attributes?.for ?? node.name ?? "div");
855
- element.dataset[name] = name;
856
- this.render(node, element, this.creator || this);
857
- if (insert) {
858
- presenter.insertBefore(element, presenter.firstElementChild);
859
- }
860
- else {
861
- presenter.appendChild(element);
862
- }
863
- this[name + "Element"] = element;
864
- }
865
- dispatchHeaderFooterEvent(eventName, type, recreate, originalTarget) {
866
- const detail = this[type];
867
- const ce = new CustomEvent(eventName ?? `${type}Click`, {
868
- detail,
869
- bubbles: this.bubbleEvents,
870
- cancelable: true
871
- });
872
- originalTarget.dispatchEvent(ce);
873
- if (ce.defaultPrevented || !ce.executed) {
874
- return;
875
- }
876
- if (recreate) {
877
- this.onPropertyChanged(type);
878
- }
772
+ while (start) {
773
+ const ci = items[index];
774
+ const cv = vp(ci);
775
+ start.setAttribute("data-item-index", `${index++}`);
776
+ if (si.indexOf(cv) !== -1) {
777
+ start.setAttribute("data-selected-item", "true");
778
+ } else {
779
+ start.removeAttribute("data-selected-item");
780
+ }
781
+ start = start.nextElementSibling;
782
+ if (start?.hasAttribute("data-footer")) {
783
+ break;
784
+ }
879
785
  }
880
- dispatchItemEvent(eventName, item, recreate, originalTarget, nestedItem) {
881
- const ce = new CustomEvent(eventName ?? "itemClick", {
882
- detail: nestedItem ?? item,
883
- bubbles: this.bubbleEvents,
884
- cancelable: true
885
- });
886
- originalTarget.dispatchEvent(ce);
887
- if (!ce.defaultPrevented) {
888
- if (this.selectOnClick || eventName === "itemSelect" || eventName === "itemDeselect") {
889
- const si = this.selectedItems ??= [];
890
- if (si) {
891
- const index = si.indexOf(item);
892
- if (index === -1) {
893
- if (this.allowMultipleSelection) {
894
- si.add(item);
895
- }
896
- else {
897
- si.set(0, item);
898
- }
899
- }
900
- else {
901
- si.removeAt(index);
902
- }
903
- }
904
- }
905
- }
906
- if (ce.defaultPrevented || !ce.executed) {
907
- return;
908
- }
909
- const promise = ce.promise;
910
- if (recreate) {
911
- this.refreshItem(item, promise);
912
- return;
913
- }
914
- if (promise) {
915
- promise.then((r) => r instanceof MergeNode && this.refreshItem(item, r));
916
- }
786
+ }
787
+ updateItems(container, force) {
788
+ if (this.deferUpdates && !force) {
789
+ if (this.deferredUpdateId) {
790
+ return;
791
+ }
792
+ this.deferredUpdateId = setTimeout(() => {
793
+ this.deferredUpdateId = 0;
794
+ this.updateItems(container, true);
795
+ }, 1);
796
+ return;
797
+ }
798
+ container ??= this.itemsPresenter ?? this.element;
799
+ if (!container) {
800
+ return;
801
+ }
802
+ disposeChildren(this, container);
803
+ this.onPropertyChanged("header");
804
+ const ir = this.itemRenderer;
805
+ if (!ir) {
806
+ this.onPropertyChanged("footer");
807
+ return;
808
+ }
809
+ const items = this.items;
810
+ if (!items) {
811
+ this.onPropertyChanged("footer");
812
+ return;
813
+ }
814
+ const vp = this.valuePath ?? (it => it);
815
+ const si = (this.selectedItems ?? []).map(vp);
816
+ let i = 0;
817
+ for (const iterator of items) {
818
+ const index = i++;
819
+ const e = ir(iterator, index, this);
820
+ const ea = e.attributes ??= {};
821
+ const v = vp(iterator);
822
+ const element = document.createElement(ea.for ?? e.name ?? "div");
823
+ element.setAttribute("data-item-index", `${index}`);
824
+ if (si.indexOf(v) !== -1) {
825
+ element.setAttribute("data-selected-item", "true");
826
+ } else {
827
+ element.removeAttribute("data-selected-item");
828
+ }
829
+ this.render(e, element, this.creator || this);
830
+ if (this.enableDragDrop) {
831
+ updateDragDrop(element);
832
+ }
833
+ container.appendChild(element);
834
+ }
835
+ this.onPropertyChanged("footer");
836
+ }
837
+ render(node, e, creator) {
838
+ if (!this.creator && this !== creator) {
839
+ this.creator = creator;
840
+ }
841
+ this.render = super.render;
842
+ return super.render(node, e, creator);
843
+ }
844
+ preCreate() {
845
+ this.orderBy = null;
846
+ this.mergeOnRefresh = false;
847
+ this.selectOnClick = false;
848
+ this.element.setAttribute("data-click-event", "item-click");
849
+ }
850
+ dispatchCustomEvent(type, detail) {
851
+ if (!this.element) {
852
+ return;
853
+ }
854
+ const eventName = this.element.getAttribute("data-" + type + "-event");
855
+ type = StringHelper.fromHyphenToCamel(eventName ?? type);
856
+ this.element.dispatchEvent(new CustomEvent(type, {
857
+ detail,
858
+ bubbles: eventName !== null,
859
+ cancelable: true
860
+ }));
861
+ }
862
+ updateClasses() {
863
+ const container = this.itemsPresenter ?? this.element;
864
+ const items = this.items;
865
+ let element = getFirstChild(container);
866
+ const vp = this.valuePath ?? (i => i);
867
+ const si = (this.selectedItems ?? []).map(vp);
868
+ while (element) {
869
+ const index = ~~element.getAttribute("data-item-index");
870
+ const item = items[index];
871
+ const v = vp(item);
872
+ if (si.indexOf(v) !== -1) {
873
+ element.setAttribute("data-selected-item", "true");
874
+ } else {
875
+ element.removeAttribute("data-selected-item");
876
+ }
877
+ element = element.nextElementSibling;
878
+ }
879
+ }
880
+ updateVisibility() {
881
+ const container = this.itemsPresenter ?? this.element;
882
+ const items = this.items;
883
+ let element = container.firstElementChild;
884
+ const vf = this.visibilityFilter ?? MatchTrue;
885
+ while (element) {
886
+ const index = ~~element.getAttribute("data-item-index");
887
+ const item = items[index];
888
+ if (vf(item)) {
889
+ element.removeAttribute("data-ui-display");
890
+ } else {
891
+ element.setAttribute("data-ui-display", "none");
892
+ }
893
+ element = element.nextElementSibling;
894
+ }
895
+ }
896
+ updateHeaderFooter(name, presenter, item, itemRenderer, insert) {
897
+ presenter ??= this.itemsPresenter ??= this.element;
898
+ if (!presenter) {
899
+ this[name + "Element"] = null;
900
+ return;
901
+ }
902
+ let current;
903
+ if (insert) {
904
+ current = presenter.firstElementChild;
905
+ while (current && current.dataset[name] !== name) {
906
+ current = current.nextElementSibling;
907
+ }
908
+ } else {
909
+ current = presenter.lastElementChild;
910
+ while (current && current.dataset[name] !== name) {
911
+ current = current.previousElementSibling;
912
+ }
917
913
  }
918
- dispatchClickEvent(e, data) {
919
- const { recreate, header, footer, itemIndex, itemPath, clickEvent, item, nestedItem } = AtomRepeater.itemFromElement(e.target, this);
920
- if (itemIndex !== void 0) {
921
- if (item) {
922
- if (nestedItem) {
923
- this.dispatchItemEvent(clickEvent, item, recreate, e.target, nestedItem);
924
- return;
925
- }
926
- this.dispatchItemEvent(clickEvent, item, recreate, e.target);
914
+ if (current) {
915
+ disposeChild(this, current);
916
+ this[name + "Element"] = null;
917
+ }
918
+ if (!(item && itemRenderer)) {
919
+ return;
920
+ }
921
+ const node = itemRenderer(item);
922
+ const element = document.createElement(node.attributes?.for ?? node.name ?? "div");
923
+ element.dataset[name] = name;
924
+ this.render(node, element, this.creator || this);
925
+ if (insert) {
926
+ presenter.insertBefore(element, presenter.firstElementChild);
927
+ } else {
928
+ presenter.appendChild(element);
929
+ }
930
+ this[name + "Element"] = element;
931
+ }
932
+ dispatchHeaderFooterEvent(eventName, type, recreate, originalTarget) {
933
+ const detail = this[type];
934
+ const ce = new CustomEvent(eventName ?? `${type}Click`, {
935
+ detail,
936
+ bubbles: this.bubbleEvents,
937
+ cancelable: true
938
+ });
939
+ originalTarget.dispatchEvent(ce);
940
+ if (ce.defaultPrevented || !ce.executed) {
941
+ return;
942
+ }
943
+ if (recreate) {
944
+ this.onPropertyChanged(type);
945
+ }
946
+ }
947
+ dispatchItemEvent(eventName, item, recreate, originalTarget, nestedItem) {
948
+ const ce = new CustomEvent(eventName ?? "itemClick", {
949
+ detail: nestedItem ?? item,
950
+ bubbles: this.bubbleEvents,
951
+ cancelable: true
952
+ });
953
+ originalTarget.dispatchEvent(ce);
954
+ if (!ce.defaultPrevented) {
955
+ if (this.selectOnClick || eventName === "itemSelect" || eventName === "itemDeselect") {
956
+ const si = this.selectedItems ??= [];
957
+ if (si) {
958
+ const index = si.indexOf(item);
959
+ if (index === -1) {
960
+ if (this.allowMultipleSelection) {
961
+ si.add(item);
962
+ } else {
963
+ si.set(0, item);
927
964
  }
928
- return;
929
- }
930
- if (header) {
931
- this.dispatchHeaderFooterEvent(clickEvent, header, recreate, e.target);
932
- }
933
- if (footer) {
934
- this.dispatchHeaderFooterEvent(clickEvent, footer, recreate, e.target);
965
+ } else {
966
+ si.removeAt(index);
967
+ }
935
968
  }
969
+ }
970
+ }
971
+ if (ce.defaultPrevented || !ce.executed) {
972
+ return;
973
+ }
974
+ const promise = ce.promise;
975
+ if (recreate) {
976
+ this.refreshItem(item, promise);
977
+ return;
978
+ }
979
+ if (promise) {
980
+ promise.then(r => r instanceof MergeNode && this.refreshItem(item, r));
981
+ }
982
+ }
983
+ dispatchClickEvent(e, data) {
984
+ const {
985
+ recreate,
986
+ header,
987
+ footer,
988
+ itemIndex,
989
+ itemPath,
990
+ clickEvent,
991
+ item,
992
+ nestedItem
993
+ } = AtomRepeater.itemFromElement(e.target, this);
994
+ if (itemIndex !== void 0) {
995
+ if (item) {
996
+ if (nestedItem) {
997
+ this.dispatchItemEvent(clickEvent, item, recreate, e.target, nestedItem);
998
+ return;
999
+ }
1000
+ this.dispatchItemEvent(clickEvent, item, recreate, e.target);
1001
+ }
1002
+ return;
1003
+ }
1004
+ if (header) {
1005
+ this.dispatchHeaderFooterEvent(clickEvent, header, recreate, e.target);
936
1006
  }
1007
+ if (footer) {
1008
+ this.dispatchHeaderFooterEvent(clickEvent, footer, recreate, e.target);
1009
+ }
1010
+ }
937
1011
  }
938
- __decorate([
939
- BindableProperty,
940
- __metadata("design:type", Boolean)
941
- ], AtomRepeater.prototype, "allowMultipleSelection", void 0);
942
- __decorate([
943
- BindableProperty,
944
- __metadata("design:type", Object)
945
- ], AtomRepeater.prototype, "selectOnClick", void 0);
946
- __decorate([
947
- BindableProperty,
948
- __metadata("design:type", Array)
949
- ], AtomRepeater.prototype, "selectedItems", void 0);
950
- __decorate([
951
- BindableProperty,
952
- __metadata("design:type", Object)
953
- ], AtomRepeater.prototype, "itemsPresenter", void 0);
954
- __decorate([
955
- BindableProperty,
956
- __metadata("design:type", Array)
957
- ], AtomRepeater.prototype, "items", void 0);
958
- __decorate([
959
- BindableProperty,
960
- __metadata("design:type", Object)
961
- ], AtomRepeater.prototype, "watch", void 0);
962
- __decorate([
963
- BindableProperty,
964
- __metadata("design:type", Function)
965
- ], AtomRepeater.prototype, "visibilityFilter", void 0);
966
- __decorate([
967
- BindableProperty,
968
- __metadata("design:type", Function)
969
- ], AtomRepeater.prototype, "enableFunc", void 0);
970
- __decorate([
971
- BindableProperty,
972
- __metadata("design:type", Function)
973
- ], AtomRepeater.prototype, "itemRenderer", void 0);
974
- __decorate([
975
- BindableProperty,
976
- __metadata("design:type", Function)
977
- ], AtomRepeater.prototype, "valuePath", void 0);
978
- __decorate([
979
- BindableProperty,
980
- __metadata("design:type", Function)
981
- ], AtomRepeater.prototype, "comparer", void 0);
982
- __decorate([
983
- BindableProperty,
984
- __metadata("design:type", Boolean)
985
- ], AtomRepeater.prototype, "deferUpdates", void 0);
986
- __decorate([
987
- BindableProperty,
988
- __metadata("design:type", Object)
989
- ], AtomRepeater.prototype, "header", void 0);
990
- __decorate([
991
- BindableProperty,
992
- __metadata("design:type", Object)
993
- ], AtomRepeater.prototype, "headerRenderer", void 0);
994
- __decorate([
995
- BindableProperty,
996
- __metadata("design:type", Object)
997
- ], AtomRepeater.prototype, "footer", void 0);
998
- __decorate([
999
- BindableProperty,
1000
- __metadata("design:type", Object)
1001
- ], AtomRepeater.prototype, "footerRenderer", void 0);
1002
- __decorate([
1003
- BindableProperty,
1004
- __metadata("design:type", Object)
1005
- ], AtomRepeater.prototype, "enableDragDrop", void 0);
1006
- __decorate([
1007
- BindableProperty,
1008
- __metadata("design:type", Object)
1009
- ], AtomRepeater.prototype, "orderBy", void 0);
1010
- __decorate([
1011
- WatchProperty,
1012
- __metadata("design:type", Object),
1013
- __metadata("design:paramtypes", [])
1014
- ], AtomRepeater.prototype, "allSelected", null);
1012
+ __decorate([BindableProperty, __metadata("design:type", Boolean)], AtomRepeater.prototype, "allowMultipleSelection", void 0);
1013
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "selectOnClick", void 0);
1014
+ __decorate([BindableProperty, __metadata("design:type", Array)], AtomRepeater.prototype, "selectedItems", void 0);
1015
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "itemsPresenter", void 0);
1016
+ __decorate([BindableProperty, __metadata("design:type", Array)], AtomRepeater.prototype, "items", void 0);
1017
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "watch", void 0);
1018
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomRepeater.prototype, "visibilityFilter", void 0);
1019
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomRepeater.prototype, "enableFunc", void 0);
1020
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomRepeater.prototype, "itemRenderer", void 0);
1021
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomRepeater.prototype, "valuePath", void 0);
1022
+ __decorate([BindableProperty, __metadata("design:type", Function)], AtomRepeater.prototype, "comparer", void 0);
1023
+ __decorate([BindableProperty, __metadata("design:type", Boolean)], AtomRepeater.prototype, "deferUpdates", void 0);
1024
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "header", void 0);
1025
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "headerRenderer", void 0);
1026
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "footer", void 0);
1027
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "footerRenderer", void 0);
1028
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "enableDragDrop", void 0);
1029
+ __decorate([BindableProperty, __metadata("design:type", Object)], AtomRepeater.prototype, "orderBy", void 0);
1030
+ __decorate([WatchProperty, __metadata("design:type", Object), __metadata("design:paramtypes", [])], AtomRepeater.prototype, "allSelected", null);
1015
1031
  let hoverItem = {
1016
- repeater: null,
1017
- target: null,
1018
- item: null,
1019
- placeholder: null
1032
+ repeater: null,
1033
+ target: null,
1034
+ item: null,
1035
+ placeholder: null
1020
1036
  };
1021
- document.body.addEventListener("dragstart", (e) => {
1022
- const { target } = e;
1023
- if (target.draggable) {
1024
- const ri = getParentRepeaterItem(target);
1025
- if (!ri) {
1026
- return;
1027
- }
1028
- const [type, repeater, item, index] = ri;
1029
- if (!repeater || !repeater.enableDragDrop) {
1030
- return;
1031
- }
1032
- const placeholder = document.createElement("div");
1033
- placeholder.style.width = target.offsetWidth + "px";
1034
- placeholder.style.height = target.offsetHeight + "px";
1035
- placeholder.style.backgroundColor = Colors.lightGray.toString();
1036
- placeholder.style.border = "solid 1px gray";
1037
- placeholder.style.borderRadius = "10px";
1038
- hoverItem = {
1039
- repeater,
1040
- target,
1041
- item,
1042
- placeholder,
1043
- };
1044
- e.dataTransfer.dropEffect = "move";
1045
- setTimeout(() => {
1046
- target.style.display = "none";
1047
- target.parentElement.insertBefore(placeholder, target);
1048
- }, 0);
1037
+ document.body.addEventListener("dragstart", e => {
1038
+ const {
1039
+ target
1040
+ } = e;
1041
+ if (target.draggable) {
1042
+ const ri = getParentRepeaterItem(target);
1043
+ if (!ri) {
1044
+ return;
1045
+ }
1046
+ const [type, repeater, item, index] = ri;
1047
+ if (!repeater || !repeater.enableDragDrop) {
1048
+ return;
1049
1049
  }
1050
+ const placeholder = document.createElement("div");
1051
+ placeholder.style.width = target.offsetWidth + "px";
1052
+ placeholder.style.height = target.offsetHeight + "px";
1053
+ placeholder.style.backgroundColor = Colors.lightGray.toString();
1054
+ placeholder.style.border = "solid 1px gray";
1055
+ placeholder.style.borderRadius = "10px";
1056
+ hoverItem = {
1057
+ repeater,
1058
+ target,
1059
+ item,
1060
+ placeholder
1061
+ };
1062
+ e.dataTransfer.dropEffect = "move";
1063
+ setTimeout(() => {
1064
+ target.style.display = "none";
1065
+ target.parentElement.insertBefore(placeholder, target);
1066
+ }, 0);
1067
+ }
1050
1068
  });
1051
- document.body.addEventListener("dragend", (e) => {
1052
- if (!(hoverItem?.placeholder)) {
1053
- return;
1069
+ document.body.addEventListener("dragend", e => {
1070
+ if (!hoverItem?.placeholder) {
1071
+ return;
1072
+ }
1073
+ const {
1074
+ item,
1075
+ placeholder,
1076
+ repeater
1077
+ } = hoverItem;
1078
+ let start = placeholder;
1079
+ let index = -1;
1080
+ while (start) {
1081
+ const itemIndex = start.previousElementSibling?.dataset?.itemIndex;
1082
+ if (itemIndex !== void 0) {
1083
+ index = ~~itemIndex;
1054
1084
  }
1055
- const { item, placeholder, repeater } = hoverItem;
1056
- let start = placeholder;
1057
- let index = -1;
1058
- while (start) {
1059
- const itemIndex = start.previousElementSibling?.dataset?.itemIndex;
1060
- if (itemIndex !== void 0) {
1061
- index = ~~itemIndex;
1062
- }
1063
- if (start.parentElement.atomControl) {
1064
- break;
1065
- }
1066
- start = start.parentElement;
1067
- }
1068
- const targetRepeater = start.parentElement.atomControl;
1069
- placeholder.remove();
1070
- hoverItem.placeholder = null;
1071
- repeater.items.remove(item);
1072
- index++;
1073
- const ce = new CustomEvent("itemDropped", { detail: { item, index } });
1074
- if (ce.defaultPrevented) {
1075
- return;
1085
+ if (start.parentElement.atomControl) {
1086
+ break;
1076
1087
  }
1077
- const { detail } = ce;
1078
- targetRepeater.items.insert(detail.index, detail.item);
1079
- });
1080
- const dragOver = (e) => {
1081
- if (!e.dataTransfer) {
1082
- return;
1088
+ start = start.parentElement;
1089
+ }
1090
+ const targetRepeater = start.parentElement.atomControl;
1091
+ placeholder.remove();
1092
+ hoverItem.placeholder = null;
1093
+ repeater.items.remove(item);
1094
+ index++;
1095
+ const ce = new CustomEvent("itemDropped", {
1096
+ detail: {
1097
+ item,
1098
+ index
1083
1099
  }
1084
- if (hoverItem) {
1085
- const { placeholder } = hoverItem;
1086
- if (!placeholder) {
1087
- return;
1088
- }
1089
- if (e.target === placeholder) {
1090
- return;
1091
- }
1100
+ });
1101
+ if (ce.defaultPrevented) {
1102
+ return;
1103
+ }
1104
+ const {
1105
+ detail
1106
+ } = ce;
1107
+ targetRepeater.items.insert(detail.index, detail.item);
1108
+ });
1109
+ const dragOver = e => {
1110
+ if (!e.dataTransfer) {
1111
+ return;
1112
+ }
1113
+ if (hoverItem) {
1114
+ const {
1115
+ placeholder
1116
+ } = hoverItem;
1117
+ if (!placeholder) {
1118
+ return;
1092
1119
  }
1093
- const ri = getParentRepeaterItem(e.target);
1094
- if (!ri) {
1095
- return;
1120
+ if (e.target === placeholder) {
1121
+ return;
1096
1122
  }
1097
- const [type, repeater, item, index, target] = ri;
1098
- if (!repeater) {
1123
+ }
1124
+ const ri = getParentRepeaterItem(e.target);
1125
+ if (!ri) {
1126
+ return;
1127
+ }
1128
+ const [type, repeater, item, index, target] = ri;
1129
+ if (!repeater) {
1130
+ return;
1131
+ }
1132
+ if (hoverItem) {
1133
+ const {
1134
+ placeholder
1135
+ } = hoverItem;
1136
+ e.preventDefault();
1137
+ const mp = {
1138
+ x: e.clientX,
1139
+ y: e.clientY
1140
+ };
1141
+ const isBefore = (co, n) => n.x <= co.x + co.width * 0.3 || n.y <= co.y + co.height * 0.3;
1142
+ const isAfter = (co, n) => n.x >= co.x + co.width * 0.7 || n.y >= co.y + co.height * 0.7;
1143
+ const targetBounds = target.getBoundingClientRect();
1144
+ if (isAfter(targetBounds, mp)) {
1145
+ const next = target.nextElementSibling;
1146
+ if (next === placeholder) {
1099
1147
  return;
1148
+ }
1149
+ placeholder.remove();
1150
+ target.insertAdjacentElement("afterend", placeholder);
1151
+ return;
1100
1152
  }
1101
- if (hoverItem) {
1102
- const { placeholder } = hoverItem;
1103
- e.preventDefault();
1104
- const mp = { x: e.clientX, y: e.clientY };
1105
- const isBefore = (co, n) => n.x <= (co.x + (co.width * 0.3)) || n.y <= (co.y + (co.height * 0.3));
1106
- const isAfter = (co, n) => n.x >= (co.x + (co.width * 0.7)) || n.y >= (co.y + (co.height * 0.7));
1107
- const targetBounds = target.getBoundingClientRect();
1108
- if (isAfter(targetBounds, mp)) {
1109
- const next = target.nextElementSibling;
1110
- if (next === placeholder) {
1111
- return;
1112
- }
1113
- placeholder.remove();
1114
- target.insertAdjacentElement("afterend", placeholder);
1115
- return;
1116
- }
1117
- if (isBefore(targetBounds, mp)) {
1118
- const previous = target.previousElementSibling;
1119
- if (previous === placeholder) {
1120
- return;
1121
- }
1122
- placeholder.remove();
1123
- target.insertAdjacentElement("beforebegin", placeholder);
1124
- }
1153
+ if (isBefore(targetBounds, mp)) {
1154
+ const previous = target.previousElementSibling;
1155
+ if (previous === placeholder) {
1125
1156
  return;
1157
+ }
1158
+ placeholder.remove();
1159
+ target.insertAdjacentElement("beforebegin", placeholder);
1126
1160
  }
1161
+ return;
1162
+ }
1127
1163
  };
1128
1164
  document.body.addEventListener("dragover", dragOver);
1129
- document.body.addEventListener("dragenter", dragOver);
1130
- //# sourceMappingURL=AtomRepeater.js.map
1165
+ document.body.addEventListener("dragenter", dragOver);