jsf.js_next_gen 4.0.1-beta.5 → 4.0.1-beta.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 (188) hide show
  1. package/dist/docs/assets/style.css +4 -5
  2. package/dist/window/faces-development.js +111 -91
  3. package/dist/window/faces-development.js.br +0 -0
  4. package/dist/window/faces-development.js.gz +0 -0
  5. package/dist/window/faces-development.js.map +1 -1
  6. package/dist/window/faces.js +1 -1
  7. package/dist/window/faces.js.br +0 -0
  8. package/dist/window/faces.js.gz +0 -0
  9. package/dist/window/faces.js.map +1 -1
  10. package/dist/window/jsf-development.js +111 -91
  11. package/dist/window/jsf-development.js.br +0 -0
  12. package/dist/window/jsf-development.js.gz +0 -0
  13. package/dist/window/jsf-development.js.map +1 -1
  14. package/dist/window/jsf.js +1 -1
  15. package/dist/window/jsf.js.br +0 -0
  16. package/dist/window/jsf.js.gz +0 -0
  17. package/dist/window/jsf.js.map +1 -1
  18. package/package.json +10 -10
  19. package/src/main/typescript/impl/util/XhrQueueController.ts +3 -17
  20. package/src/main/typescript/impl/xhrCore/XhrRequest.ts +94 -51
  21. package/src/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.ts +1 -1
  22. package/src/main/typescript/test/frameworkBase/_ext/shared/StandardInits.ts +126 -0
  23. package/src/main/typescript/test/frameworkBase/_ext/shared/XmlResponses.ts +60 -0
  24. package/src/main/typescript/test/frameworkBase/_ext/shared/fixtures/css/bootstrap-icons.css +15 -0
  25. package/src/main/typescript/test/frameworkBase/_ext/shared/fixtures/css/tobago.css +15 -0
  26. package/src/main/typescript/test/frameworkBase/_ext/shared/fixtures/js/tobago.js +15 -0
  27. package/src/main/typescript/test/myfaces/{OnLoadSpec.ts → OnLoad.spec.ts} +2 -2
  28. package/src/main/typescript/test/xhrCore/ErrorChainTest.spec.ts +136 -0
  29. package/src/main/typescript/test/xhrCore/NamespacesRequestTest.spec.ts +9 -12
  30. package/src/main/typescript/test/xhrCore/RequestParamsTest.spec.ts +1 -1
  31. package/src/main/typescript/test/xhrCore/ResponseTest23.spec.ts +18 -0
  32. package/target/AssocArray.js +281 -0
  33. package/target/AssocArray.js.map +1 -0
  34. package/target/Config.js +235 -0
  35. package/target/Config.js.map +1 -0
  36. package/target/CryptoExtensions.js +112 -0
  37. package/target/CryptoExtensions.js.map +1 -0
  38. package/target/DomQuery.js +1963 -0
  39. package/target/DomQuery.js.map +1 -0
  40. package/target/Es2019Array.js +117 -0
  41. package/target/Es2019Array.js.map +1 -0
  42. package/target/Global.js +38 -0
  43. package/target/Global.js.map +1 -0
  44. package/target/IDomQuery.js +3 -0
  45. package/target/IDomQuery.js.map +1 -0
  46. package/target/Lang.js +183 -0
  47. package/target/Lang.js.map +1 -0
  48. package/target/Messaging.js +645 -0
  49. package/target/Messaging.js.map +1 -0
  50. package/target/Monad.js +330 -0
  51. package/target/Monad.js.map +1 -0
  52. package/target/Promise.js +296 -0
  53. package/target/Promise.js.map +1 -0
  54. package/target/PromiseShim.js +30 -0
  55. package/target/PromiseShim.js.map +1 -0
  56. package/target/SourcesCollectors.js +444 -0
  57. package/target/SourcesCollectors.js.map +1 -0
  58. package/target/Stream.js +562 -0
  59. package/target/Stream.js.map +1 -0
  60. package/target/TagBuilder.js +178 -0
  61. package/target/TagBuilder.js.map +1 -0
  62. package/target/XmlQuery.js +84 -0
  63. package/target/XmlQuery.js.map +1 -0
  64. package/target/impl/util/XhrQueueController.js +3 -18
  65. package/target/impl/util/XhrQueueController.js.map +1 -1
  66. package/target/impl/xhrCore/XhrRequest.js +89 -45
  67. package/target/impl/xhrCore/XhrRequest.js.map +1 -1
  68. package/target/index.js +80 -0
  69. package/target/index.js.map +1 -0
  70. package/target/index_core.js +76 -0
  71. package/target/index_core.js.map +1 -0
  72. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js +1 -1
  73. package/target/test/frameworkBase/_ext/shared/StandardInits.js +124 -0
  74. package/target/test/frameworkBase/_ext/shared/StandardInits.js.map +1 -1
  75. package/target/test/frameworkBase/_ext/shared/XmlResponses.js +57 -1
  76. package/target/test/frameworkBase/_ext/shared/XmlResponses.js.map +1 -1
  77. package/target/test/myfaces/OnLoad.spec.js +57 -0
  78. package/target/test/myfaces/OnLoad.spec.js.map +1 -0
  79. package/target/test/myfaces/OnLoadSpec.js +2 -2
  80. package/target/test/myfaces/OnLoadSpec.js.map +1 -1
  81. package/target/test/xhrCore/ErrorChainTest.spec.js +156 -0
  82. package/target/test/xhrCore/ErrorChainTest.spec.js.map +1 -0
  83. package/target/test/xhrCore/NamespacesRequestTest.spec.js +8 -5
  84. package/target/test/xhrCore/NamespacesRequestTest.spec.js.map +1 -1
  85. package/target/test/xhrCore/RequestParamsTest.spec.js.map +1 -1
  86. package/target/test/xhrCore/ResponseTest23.spec.js +13 -0
  87. package/target/test/xhrCore/ResponseTest23.spec.js.map +1 -1
  88. package/target/types/main/typescript/AssocArray.d.ts +86 -0
  89. package/target/types/main/typescript/Config.d.ts +94 -0
  90. package/target/types/main/typescript/CryptoExtensions.d.ts +87 -0
  91. package/target/types/main/typescript/DomQuery.d.ts +587 -0
  92. package/target/types/main/typescript/Es2019Array.d.ts +30 -0
  93. package/target/types/main/typescript/Global.d.ts +23 -0
  94. package/target/types/main/typescript/IDomQuery.d.ts +480 -0
  95. package/target/types/main/typescript/Lang.d.ts +97 -0
  96. package/target/types/main/typescript/Messaging.d.ts +285 -0
  97. package/target/types/main/typescript/Monad.d.ts +161 -0
  98. package/target/types/main/typescript/Promise.d.ts +58 -0
  99. package/target/types/main/typescript/PromiseShim.d.ts +22 -0
  100. package/target/types/main/typescript/SourcesCollectors.d.ts +280 -0
  101. package/target/types/main/typescript/Stream.d.ts +284 -0
  102. package/target/types/main/typescript/TagBuilder.d.ts +50 -0
  103. package/target/types/main/typescript/XmlQuery.d.ts +31 -0
  104. package/target/types/main/typescript/api/_api.d.ts +182 -0
  105. package/target/types/main/typescript/api/faces.d.ts +17 -0
  106. package/target/types/main/typescript/api/jsf.d.ts +17 -0
  107. package/target/types/main/typescript/impl/AjaxImpl.d.ts +164 -0
  108. package/target/types/main/typescript/impl/PushImpl.d.ts +38 -0
  109. package/target/types/main/typescript/impl/core/Const.d.ts +138 -0
  110. package/target/types/main/typescript/impl/core/ImplTypes.d.ts +16 -0
  111. package/target/types/main/typescript/impl/i18n/Messages.d.ts +102 -0
  112. package/target/types/main/typescript/impl/util/Assertions.d.ts +46 -0
  113. package/target/types/main/typescript/impl/util/AsyncRunnable.d.ts +112 -0
  114. package/target/types/main/typescript/impl/util/ExtDomQuery.d.ts +100 -0
  115. package/target/types/main/typescript/impl/util/FileUtils.d.ts +25 -0
  116. package/target/types/main/typescript/impl/util/HiddenInputBuilder.d.ts +37 -0
  117. package/target/types/main/typescript/impl/util/IListener.d.ts +18 -0
  118. package/target/types/main/typescript/impl/util/Lang.d.ts +138 -0
  119. package/target/types/main/typescript/impl/util/XhrQueueController.d.ts +51 -0
  120. package/target/types/main/typescript/impl/xhrCore/ErrorData.d.ts +37 -0
  121. package/target/types/main/typescript/impl/xhrCore/EventData.d.ts +25 -0
  122. package/target/types/main/typescript/impl/xhrCore/IResponseProcessor.d.ts +136 -0
  123. package/target/types/main/typescript/impl/xhrCore/RequestDataResolver.d.ts +84 -0
  124. package/target/types/main/typescript/impl/xhrCore/ResonseDataResolver.d.ts +60 -0
  125. package/target/types/main/typescript/impl/xhrCore/Response.d.ts +29 -0
  126. package/target/types/main/typescript/impl/xhrCore/ResponseProcessor.d.ts +208 -0
  127. package/target/types/main/typescript/impl/xhrCore/XhrFormData.d.ts +83 -0
  128. package/target/types/main/typescript/impl/xhrCore/XhrRequest.d.ts +102 -0
  129. package/target/types/main/typescript/index.d.ts +34 -0
  130. package/target/types/main/typescript/index_core.d.ts +29 -0
  131. package/target/types/main/typescript/myfaces/OamSubmit.d.ts +53 -0
  132. package/target/types/main/typescript/test/frameworkBase/LangTest.spec.d.ts +1 -0
  133. package/target/types/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.d.ts +1 -0
  134. package/target/types/main/typescript/test/frameworkBase/_ext/monadish/LangTest.spec.d.ts +16 -0
  135. package/target/types/main/typescript/test/frameworkBase/_ext/monadish/MappingProbes.d.ts +39 -0
  136. package/target/types/main/typescript/test/frameworkBase/_ext/monadish/MappingTest.spec.d.ts +16 -0
  137. package/target/types/main/typescript/test/frameworkBase/_ext/monadish/MonadTest.spec.d.ts +16 -0
  138. package/target/types/main/typescript/test/frameworkBase/_ext/monadish/XmlQueryTest.spec.d.ts +0 -0
  139. package/target/types/main/typescript/test/frameworkBase/_ext/monadish/markups/tobago-with-header.d.ts +1 -0
  140. package/target/types/main/typescript/test/frameworkBase/_ext/monadish/markups/tobago-without-header.d.ts +1 -0
  141. package/target/types/main/typescript/test/frameworkBase/_ext/shared/StandardInits.d.ts +63 -0
  142. package/target/types/main/typescript/test/frameworkBase/_ext/shared/XmlResponses.d.ts +23 -0
  143. package/target/types/main/typescript/test/impl/ImplTest.spec.d.ts +16 -0
  144. package/target/types/main/typescript/test/impl/ImplTest_23.spec.d.ts +16 -0
  145. package/target/types/main/typescript/test/impl/SeparatorCharsTest.spec.d.ts +16 -0
  146. package/target/types/main/typescript/test/myfaces/OamSubmit.spec.d.ts +16 -0
  147. package/target/types/main/typescript/test/myfaces/OnLoad.spec.d.ts +16 -0
  148. package/target/types/main/typescript/test/queue/AsynchronousProbe.d.ts +38 -0
  149. package/target/types/main/typescript/test/queue/AsynchronousQueueTest.spec.d.ts +16 -0
  150. package/target/types/main/typescript/test/xhrCore/ClientWindow.spec.d.ts +1 -0
  151. package/target/types/main/typescript/test/xhrCore/ErrorChainTest.spec.d.ts +16 -0
  152. package/target/types/main/typescript/test/xhrCore/EventTests.spec.d.ts +16 -0
  153. package/target/types/main/typescript/test/xhrCore/FakeWebsocket.d.ts +24 -0
  154. package/target/types/main/typescript/test/xhrCore/FileUploadTest.spec.d.ts +1 -0
  155. package/target/types/main/typescript/test/xhrCore/NamespacesRequestTest.spec.d.ts +16 -0
  156. package/target/types/main/typescript/test/xhrCore/OamSubmitTest.spec.d.ts +16 -0
  157. package/target/types/main/typescript/test/xhrCore/RequestParamsTest.spec.d.ts +1 -0
  158. package/target/types/main/typescript/test/xhrCore/RequestTest.spec.d.ts +16 -0
  159. package/target/types/main/typescript/test/xhrCore/RequestTest_23.spec.d.ts +16 -0
  160. package/target/types/main/typescript/test/xhrCore/ResponseTest.spec.d.ts +16 -0
  161. package/target/types/main/typescript/test/xhrCore/ResponseTest23.spec.d.ts +16 -0
  162. package/target/types/main/typescript/test/xhrCore/ShadowDomTest.spec.d.ts +16 -0
  163. package/target/types/main/typescript/test/xhrCore/TobagoFileUploadTest.spec.d.ts +1 -0
  164. package/target/types/main/typescript/test/xhrCore/WebsocketTest.d.ts +1 -0
  165. package/target/types/main/typescript/test/xhrCore/XhrFormDataTest.spec.d.ts +16 -0
  166. package/target/types/test/typescript/AssocArrayTest.spec.d.ts +1 -0
  167. package/target/types/test/typescript/DomQueryTest.spec.d.ts +1 -0
  168. package/target/types/test/typescript/ExtendedArrayTest.spec.d.ts +1 -0
  169. package/target/types/test/typescript/LangTest.spec.d.ts +1 -0
  170. package/target/types/test/typescript/MappingProbes.d.ts +24 -0
  171. package/target/types/test/typescript/MappingTest.spec.d.ts +1 -0
  172. package/target/types/test/typescript/MessagingTest.spec.d.ts +1 -0
  173. package/target/types/test/typescript/MonadTest.spec.d.ts +16 -0
  174. package/target/types/test/typescript/PromiseTest.spec.d.ts +1 -0
  175. package/target/types/test/typescript/StreamTest.spec.d.ts +1 -0
  176. package/target/types/test/typescript/XmlQueryTest.spec.d.ts +1 -0
  177. package/target/types/test/typescript/markups/tobago-with-header.d.ts +1 -0
  178. package/target/types/test/typescript/markups/tobago-without-header.d.ts +1 -0
  179. package/webpack.config.js +1 -1
  180. package/webpack.config.js.map +1 -1
  181. package/.nyc_output/09ca9ebc-2305-4357-8db9-48ddfc7dfde2.json +0 -1
  182. package/.nyc_output/7c496a14-166e-4aa5-85b9-47b22b055ad8.json +0 -1
  183. package/.nyc_output/processinfo/09ca9ebc-2305-4357-8db9-48ddfc7dfde2.json +0 -1
  184. package/.nyc_output/processinfo/7c496a14-166e-4aa5-85b9-47b22b055ad8.json +0 -1
  185. package/.nyc_output/processinfo/index.json +0 -1
  186. package/src/test.html +0 -75
  187. package/src/tmp/test.html +0 -16
  188. package/tmp.xml +0 -36
@@ -0,0 +1,1963 @@
1
+ "use strict";
2
+ /*!
3
+ * Licensed to the Apache Software Foundation (ASF) under one or more
4
+ * contributor license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright ownership.
6
+ * The ASF licenses this file to you under the Apache License, Version 2.0
7
+ * (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ *
10
+ * http:// www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.DQ$ = exports.DQ = exports.DomQueryCollector = exports.DomQuery = exports.Style = exports.ElementAttribute = void 0;
29
+ const Monad_1 = require("./Monad");
30
+ const SourcesCollectors_1 = require("./SourcesCollectors");
31
+ const Lang_1 = require("./Lang");
32
+ const Global_1 = require("./Global");
33
+ const Es2019Array_1 = require("./Es2019Array");
34
+ var trim = Lang_1.Lang.trim;
35
+ var isString = Lang_1.Lang.isString;
36
+ var eqi = Lang_1.Lang.equalsIgnoreCase;
37
+ var objToArray = Lang_1.Lang.objToArray;
38
+ const AssocArray_1 = require("./AssocArray");
39
+ /**
40
+ *
41
+ * // - submit checkboxes and radio inputs only if checked
42
+ if ((tagName != "select" && elemType != "button"
43
+ && elemType != "reset" && elemType != "submit" && elemType != "image")
44
+ && ((elemType != "checkbox" && elemType != "radio"
45
+ */
46
+ var ALLOWED_SUBMITTABLE_ELEMENTS;
47
+ (function (ALLOWED_SUBMITTABLE_ELEMENTS) {
48
+ ALLOWED_SUBMITTABLE_ELEMENTS["SELECT"] = "select";
49
+ ALLOWED_SUBMITTABLE_ELEMENTS["BUTTON"] = "button";
50
+ ALLOWED_SUBMITTABLE_ELEMENTS["SUBMIT"] = "submit";
51
+ ALLOWED_SUBMITTABLE_ELEMENTS["RESET"] = "reset";
52
+ ALLOWED_SUBMITTABLE_ELEMENTS["IMAGE"] = "image";
53
+ ALLOWED_SUBMITTABLE_ELEMENTS["RADIO"] = "radio";
54
+ ALLOWED_SUBMITTABLE_ELEMENTS["CHECKBOX"] = "checkbox";
55
+ })(ALLOWED_SUBMITTABLE_ELEMENTS || (ALLOWED_SUBMITTABLE_ELEMENTS = {}));
56
+ /**
57
+ * helper to fix a common problem that a system has to wait, until a certain condition is reached.
58
+ * Depending on the browser this uses either the Mutation Observer or a semi compatible interval as fallback.
59
+ * @param root the root DomQuery element to start from
60
+ * @param condition the condition lambda to be fulfilled
61
+ * @param options options for the search
62
+ */
63
+ function waitUntilDom(root, condition, options = {
64
+ attributes: true,
65
+ childList: true,
66
+ subtree: true,
67
+ timeout: 500,
68
+ interval: 100
69
+ }) {
70
+ return new Promise((success, error) => {
71
+ let observer = null;
72
+ const MUT_ERROR = new Error("Mutation observer timeout");
73
+ // we do the same but for now ignore the options on the dom query
74
+ // we cannot use absent here, because the condition might search for an absent element
75
+ function findElement(root, condition) {
76
+ let found = null;
77
+ if (!!condition(root)) {
78
+ return root;
79
+ }
80
+ if (options.childList) {
81
+ found = (condition(root)) ? root : root.childNodes.filter(item => condition(item)).first().value.value;
82
+ }
83
+ else if (options.subtree) {
84
+ found = (condition(root)) ? root : root.querySelectorAll(" * ").filter(item => condition(item)).first().value.value;
85
+ }
86
+ else {
87
+ found = (condition(root)) ? root : null;
88
+ }
89
+ return found;
90
+ }
91
+ let foundElement = root;
92
+ if (!!(foundElement = findElement(foundElement, condition))) {
93
+ success(new DomQuery(foundElement));
94
+ return;
95
+ }
96
+ if ('undefined' != typeof MutationObserver) {
97
+ const mutTimeout = setTimeout(() => {
98
+ observer.disconnect();
99
+ return error(MUT_ERROR);
100
+ }, options.timeout);
101
+ const callback = (mutationList) => {
102
+ const found = new DomQuery(mutationList.map((mut) => mut.target)).filter(item => condition(item)).first();
103
+ if (found.isPresent()) {
104
+ clearTimeout(mutTimeout);
105
+ observer.disconnect();
106
+ success(new DomQuery(found || root));
107
+ }
108
+ };
109
+ observer = new MutationObserver(callback);
110
+ // browsers might ignore it, but we cannot break the api in the case
111
+ // hence no timeout is passed
112
+ let observableOpts = Object.assign({}, options);
113
+ delete observableOpts.timeout;
114
+ root.eachElem(item => {
115
+ observer.observe(item, observableOpts);
116
+ });
117
+ }
118
+ else { // fallback for legacy browsers without mutation observer
119
+ let interval = setInterval(() => {
120
+ let found = findElement(root, condition);
121
+ if (!!found) {
122
+ if (timeout) {
123
+ clearTimeout(timeout);
124
+ clearInterval(interval);
125
+ interval = null;
126
+ }
127
+ success(new DomQuery(found || root));
128
+ }
129
+ }, options.interval);
130
+ let timeout = setTimeout(() => {
131
+ if (interval) {
132
+ clearInterval(interval);
133
+ error(MUT_ERROR);
134
+ }
135
+ }, options.timeout);
136
+ }
137
+ });
138
+ }
139
+ class ElementAttribute extends Monad_1.ValueEmbedder {
140
+ constructor(element, name, defaultVal = null) {
141
+ super(element, name);
142
+ this.element = element;
143
+ this.name = name;
144
+ this.defaultVal = defaultVal;
145
+ }
146
+ get value() {
147
+ let val = this.element.get(0).orElse(...[]).values;
148
+ if (!val.length) {
149
+ return this.defaultVal;
150
+ }
151
+ return val[0].getAttribute(this.name);
152
+ }
153
+ set value(value) {
154
+ let val = this.element.get(0).orElse(...[]).values;
155
+ for (let cnt = 0; cnt < val.length; cnt++) {
156
+ val[cnt].setAttribute(this.name, value);
157
+ }
158
+ val[0].setAttribute(this.name, value);
159
+ }
160
+ getClass() {
161
+ return ElementAttribute;
162
+ }
163
+ static fromNullable(value, valueKey = "value") {
164
+ return new ElementAttribute(value, valueKey);
165
+ }
166
+ }
167
+ exports.ElementAttribute = ElementAttribute;
168
+ class Style extends Monad_1.ValueEmbedder {
169
+ constructor(element, name, defaultVal = null) {
170
+ super(element, name);
171
+ this.element = element;
172
+ this.name = name;
173
+ this.defaultVal = defaultVal;
174
+ }
175
+ get value() {
176
+ let val = this.element.values;
177
+ if (!val.length) {
178
+ return this.defaultVal;
179
+ }
180
+ return val[0].style[this.name];
181
+ }
182
+ set value(value) {
183
+ let val = this.element.values;
184
+ for (let cnt = 0; cnt < val.length; cnt++) {
185
+ val[cnt].style[this.name] = value;
186
+ }
187
+ }
188
+ getClass() {
189
+ return ElementAttribute;
190
+ }
191
+ static fromNullable(value, valueKey = "value") {
192
+ return new ElementAttribute(value, valueKey);
193
+ }
194
+ }
195
+ exports.Style = Style;
196
+ /**
197
+ * small helper for the specialized jsf case
198
+ * @constructor
199
+ */
200
+ const DEFAULT_WHITELIST = () => {
201
+ return true;
202
+ };
203
+ /**
204
+ * Monadic DomNode representation, ala jquery
205
+ * This is a thin wrapper over querySelectorAll
206
+ * to get slim monadic support
207
+ * to reduce implementation code on the users side.
208
+ * This is vital for frameworks which want to rely on
209
+ * plain dom but still do not want to lose
210
+ * the reduced code footprint of querying dom trees and traversing
211
+ * by using functional patterns.
212
+ *
213
+ * Also, a few convenience methods are added to reduce
214
+ * the code footprint of standard dom processing
215
+ * operations like eval
216
+ *
217
+ * in most older systems
218
+ * Note parts of this code still stem from the Dom.js I have written 10 years
219
+ * ago, those parts look a bit ancient and will be replaced over time.
220
+ *
221
+ */
222
+ class DomQuery {
223
+ constructor(...rootNode) {
224
+ this.rootNode = [];
225
+ this.pos = -1;
226
+ // because we can stream from an array stream directly into the dom query
227
+ this._limits = -1;
228
+ if (Monad_1.Optional.fromNullable(rootNode).isAbsent() || !rootNode.length) {
229
+ return;
230
+ }
231
+ else {
232
+ // we need to flatten out the arrays
233
+ for (let cnt = 0; cnt < rootNode.length; cnt++) {
234
+ if (!rootNode[cnt]) {
235
+ // we skip possible null entries which can happen in
236
+ // certain corner conditions due to the constructor re-wrapping single elements into arrays.
237
+ }
238
+ else if (isString(rootNode[cnt])) {
239
+ let foundElement = DomQuery.querySelectorAll(rootNode[cnt]);
240
+ if (!foundElement.isAbsent()) {
241
+ rootNode.push(...foundElement.values);
242
+ }
243
+ }
244
+ else if (rootNode[cnt] instanceof DomQuery) {
245
+ this.rootNode.push(...rootNode[cnt].values);
246
+ }
247
+ else {
248
+ this.rootNode.push(rootNode[cnt]);
249
+ }
250
+ }
251
+ }
252
+ }
253
+ /**
254
+ * returns the first element
255
+ */
256
+ get value() {
257
+ return this.getAsElem(0);
258
+ }
259
+ get values() {
260
+ return this.allElems();
261
+ }
262
+ get global() {
263
+ return Global_1._global$;
264
+ }
265
+ get stream() {
266
+ throw Error("Not implemented, include Stream.ts for this to work");
267
+ }
268
+ get lazyStream() {
269
+ throw Error("Not implemented, include Stream.ts for this to work");
270
+ }
271
+ /**
272
+ * returns the id of the first element
273
+ */
274
+ get id() {
275
+ return new ElementAttribute(this.get(0), "id");
276
+ }
277
+ /**
278
+ * length of the entire query set
279
+ */
280
+ get length() {
281
+ return this.rootNode.length;
282
+ }
283
+ /**
284
+ * convenience method for tagName
285
+ */
286
+ get tagName() {
287
+ return this.getAsElem(0).getIf("tagName");
288
+ }
289
+ /**
290
+ * convenience method for nodeName
291
+ */
292
+ get nodeName() {
293
+ return this.getAsElem(0).getIf("nodeName");
294
+ }
295
+ isTag(tagName) {
296
+ return !this.isAbsent()
297
+ && (this.nodeName.orElse("__none___")
298
+ .value.toLowerCase() == tagName.toLowerCase()
299
+ || this.tagName.orElse("__none___")
300
+ .value.toLowerCase() == tagName.toLowerCase());
301
+ }
302
+ /**
303
+ * convenience property for type
304
+ *
305
+ * returns null in case of no type existing otherwise
306
+ * the type of the first element
307
+ */
308
+ get type() {
309
+ return this.getAsElem(0).getIf("type");
310
+ }
311
+ /**
312
+ * convenience property for name
313
+ *
314
+ * returns null in case of no type existing otherwise
315
+ * the name of the first element
316
+ */
317
+ get name() {
318
+ return new Monad_1.ValueEmbedder(this.getAsElem(0).value, "name");
319
+ }
320
+ /**
321
+ * convenience property for value
322
+ *
323
+ * returns null in case of no type existing otherwise
324
+ * the value of the first element
325
+ */
326
+ get inputValue() {
327
+ if (this.getAsElem(0).getIf("value").isPresent()) {
328
+ return new Monad_1.ValueEmbedder(this.getAsElem(0).value);
329
+ }
330
+ else {
331
+ return Monad_1.ValueEmbedder.absent;
332
+ }
333
+ }
334
+ get val() {
335
+ return this.inputValue.value;
336
+ }
337
+ set val(value) {
338
+ this.inputValue.value = value;
339
+ }
340
+ get nodeId() {
341
+ return this.id.value;
342
+ }
343
+ set nodeId(value) {
344
+ this.id.value = value;
345
+ }
346
+ get checked() {
347
+ return new Es2019Array_1.Es2019Array(...this.values).every(el => !!el.checked);
348
+ }
349
+ set checked(newChecked) {
350
+ this.eachElem(el => el.checked = newChecked);
351
+ }
352
+ get elements() {
353
+ // a simple querySelectorAll should suffice
354
+ return this.querySelectorAll("input, checkbox, select, textarea, fieldset");
355
+ }
356
+ get deepElements() {
357
+ let elemStr = "input, select, textarea, checkbox, fieldset";
358
+ return this.querySelectorAllDeep(elemStr);
359
+ }
360
+ /**
361
+ * a deep search which treats the single isolated shadow dom areas
362
+ * separately and runs the query on each shadow dom
363
+ * @param queryStr
364
+ */
365
+ querySelectorAllDeep(queryStr) {
366
+ let found = [];
367
+ let queryRes = this.querySelectorAll(queryStr);
368
+ if (queryRes.length) {
369
+ found.push(queryRes);
370
+ }
371
+ let shadowRoots = this.querySelectorAll("*").shadowRoot;
372
+ if (shadowRoots.length) {
373
+ let shadowRes = shadowRoots.querySelectorAllDeep(queryStr);
374
+ if (shadowRes.length) {
375
+ found.push(shadowRes);
376
+ }
377
+ }
378
+ return new DomQuery(...found);
379
+ }
380
+ /**
381
+ * disabled flag
382
+ */
383
+ get disabled() {
384
+ return this.attr("disabled").isPresent();
385
+ }
386
+ set disabled(disabled) {
387
+ // this.attr("disabled").value = disabled + "";
388
+ if (!disabled) {
389
+ this.removeAttribute("disabled");
390
+ }
391
+ else {
392
+ this.attr("disabled").value = "disabled";
393
+ }
394
+ }
395
+ removeAttribute(name) {
396
+ this.eachElem(item => item.removeAttribute(name));
397
+ }
398
+ get childNodes() {
399
+ let childNodeArr = [];
400
+ this.eachElem((item) => {
401
+ childNodeArr = childNodeArr.concat(objToArray(item.childNodes));
402
+ });
403
+ return new DomQuery(...childNodeArr);
404
+ }
405
+ get asArray() {
406
+ // filter not supported by IE11
407
+ let items = new Es2019Array_1.Es2019Array(...this.rootNode).filter(item => {
408
+ return item != null;
409
+ }).map(item => {
410
+ return DomQuery.byId(item);
411
+ });
412
+ return items;
413
+ }
414
+ get offsetWidth() {
415
+ return new Es2019Array_1.Es2019Array(...this.rootNode)
416
+ .filter(item => item != null)
417
+ .map(elem => elem.offsetWidth)
418
+ .reduce((accumulate, incoming) => accumulate + incoming, 0);
419
+ }
420
+ get offsetHeight() {
421
+ return new Es2019Array_1.Es2019Array(...this.rootNode)
422
+ .filter(item => item != null)
423
+ .map(elem => elem.offsetHeight)
424
+ .reduce((accumulate, incoming) => accumulate + incoming, 0);
425
+ }
426
+ get offsetLeft() {
427
+ return new Es2019Array_1.Es2019Array(...this.rootNode)
428
+ .filter(item => item != null)
429
+ .map(elem => elem.offsetLeft)
430
+ .reduce((accumulate, incoming) => accumulate + incoming, 0);
431
+ }
432
+ get offsetTop() {
433
+ return new Es2019Array_1.Es2019Array(this.rootNode)
434
+ .filter(item => item != null)
435
+ .map(elem => elem.offsetTop)
436
+ .reduce((accumulate, incoming) => accumulate + incoming, 0);
437
+ }
438
+ get asNodeArray() {
439
+ return new Es2019Array_1.Es2019Array(...this.rootNode.filter(item => item != null));
440
+ }
441
+ static querySelectorAllDeep(selector) {
442
+ return new DomQuery(document).querySelectorAllDeep(selector);
443
+ }
444
+ /**
445
+ * easy query selector all producer
446
+ *
447
+ * @param selector the selector
448
+ * @returns a results dom query object
449
+ */
450
+ static querySelectorAll(selector) {
451
+ if (selector.indexOf("/shadow/") != -1) {
452
+ return new DomQuery(document)._querySelectorAllDeep(selector);
453
+ }
454
+ else {
455
+ return new DomQuery(document)._querySelectorAll(selector);
456
+ }
457
+ }
458
+ /**
459
+ * byId producer
460
+ *
461
+ * @param selector id
462
+ * @param deep true if you want to go into shadow areas
463
+ * @return a DomQuery containing the found elements
464
+ */
465
+ static byId(selector, deep = false) {
466
+ if (isString(selector)) {
467
+ return (!deep) ? new DomQuery(document).byId(selector) : new DomQuery(document).byIdDeep(selector);
468
+ }
469
+ else {
470
+ return new DomQuery(selector);
471
+ }
472
+ }
473
+ /**
474
+ * byTagName producer
475
+ *
476
+ * @param selector name
477
+ * @return a DomQuery containing the found elements
478
+ */
479
+ static byTagName(selector) {
480
+ if (isString(selector)) {
481
+ return new DomQuery(document).byTagName(selector);
482
+ }
483
+ else {
484
+ return new DomQuery(selector);
485
+ }
486
+ }
487
+ static globalEval(code, nonce) {
488
+ return new DomQuery(document).globalEval(code, nonce);
489
+ }
490
+ static globalEvalSticky(code, nonce) {
491
+ return new DomQuery(document).globalEvalSticky(code, nonce);
492
+ }
493
+ /**
494
+ * builds the ie nodes properly in a placeholder
495
+ * and bypasses a non script insert bug that way
496
+ * @param markup the markup code to be executed from
497
+ */
498
+ static fromMarkup(markup) {
499
+ // https:// developer.mozilla.org/de/docs/Web/API/DOMParser license creative commons
500
+ const doc = document.implementation.createHTMLDocument("");
501
+ markup = trim(markup);
502
+ let lowerMarkup = markup.toLowerCase();
503
+ if (lowerMarkup.search(/<!doctype[^\w\-]+/gi) != -1 ||
504
+ lowerMarkup.search(/<html[^\w\-]+/gi) != -1 ||
505
+ lowerMarkup.search(/<head[^\w\-]+/gi) != -1 ||
506
+ lowerMarkup.search(/<body[^\w\-]+/gi) != -1) {
507
+ doc.documentElement.innerHTML = markup;
508
+ return new DomQuery(doc.documentElement);
509
+ }
510
+ else {
511
+ let startsWithTag = function (str, tagName) {
512
+ let tag1 = ["<", tagName, ">"].join("");
513
+ let tag2 = ["<", tagName, " "].join("");
514
+ return (str.indexOf(tag1) == 0) || (str.indexOf(tag2) == 0);
515
+ };
516
+ let dummyPlaceHolder = new DomQuery(document.createElement("div"));
517
+ // table needs special treatment due to the browsers auto creation
518
+ if (startsWithTag(lowerMarkup, "thead") || startsWithTag(lowerMarkup, "tbody")) {
519
+ dummyPlaceHolder.html(`<table>${markup}</table>`);
520
+ return dummyPlaceHolder.querySelectorAll("table").get(0).childNodes.detach();
521
+ }
522
+ else if (startsWithTag(lowerMarkup, "tfoot")) {
523
+ dummyPlaceHolder.html(`<table><thead></thead><tbody><tbody${markup}</table>`);
524
+ return dummyPlaceHolder.querySelectorAll("table").get(2).childNodes.detach();
525
+ }
526
+ else if (startsWithTag(lowerMarkup, "tr")) {
527
+ dummyPlaceHolder.html(`<table><tbody>${markup}</tbody></table>`);
528
+ return dummyPlaceHolder.querySelectorAll("tbody").get(0).childNodes.detach();
529
+ }
530
+ else if (startsWithTag(lowerMarkup, "td")) {
531
+ dummyPlaceHolder.html(`<table><tbody><tr>${markup}</tr></tbody></table>`);
532
+ return dummyPlaceHolder.querySelectorAll("tr").get(0).childNodes.detach();
533
+ }
534
+ dummyPlaceHolder.html(markup);
535
+ return dummyPlaceHolder.childNodes.detach();
536
+ }
537
+ }
538
+ /**
539
+ * returns the nth element as DomQuery
540
+ * from the internal elements
541
+ * note if you try to reach a non-existing element position
542
+ * you will get back an absent entry
543
+ *
544
+ * @param index the nth index
545
+ */
546
+ get(index) {
547
+ return (index < this.rootNode.length) ? new DomQuery(this.rootNode[index]) : DomQuery.absent;
548
+ }
549
+ /**
550
+ * returns the nth element as optional of an Element object
551
+ * @param index the number from the index
552
+ * @param defaults the default value if the index is overrun default Optional\.absent
553
+ */
554
+ getAsElem(index, defaults = Monad_1.Optional.absent) {
555
+ return (index < this.rootNode.length) ? Monad_1.Optional.fromNullable(this.rootNode[index]) : defaults;
556
+ }
557
+ /**
558
+ * returns the files from a given element
559
+ * @param index
560
+ */
561
+ filesFromElem(index) {
562
+ var _a;
563
+ return (index < this.rootNode.length) ? ((_a = this.rootNode[index]) === null || _a === void 0 ? void 0 : _a.files) ? this.rootNode[index].files : [] : [];
564
+ }
565
+ /**
566
+ * returns the value array< of all elements
567
+ */
568
+ allElems() {
569
+ return this.rootNode;
570
+ }
571
+ /**
572
+ * absent no values reached?
573
+ */
574
+ isAbsent() {
575
+ return this.length == 0;
576
+ }
577
+ /**
578
+ * should make the code clearer
579
+ * note if you pass a function
580
+ * this refers to the active DomQuery object
581
+ */
582
+ isPresent(presentRunnable) {
583
+ let absent = this.isAbsent();
584
+ if (!absent && presentRunnable) {
585
+ presentRunnable.call(this, this);
586
+ }
587
+ return !absent;
588
+ }
589
+ /**
590
+ * should make the code clearer
591
+ * note if you pass a function
592
+ * this refers to the active DomQuery object
593
+ *
594
+ *
595
+ * @param presentRunnable
596
+ */
597
+ ifPresentLazy(presentRunnable = function () {
598
+ }) {
599
+ this.isPresent.call(this, presentRunnable);
600
+ return this;
601
+ }
602
+ /**
603
+ * remove all affected nodes from this query object from the dom tree
604
+ */
605
+ delete() {
606
+ this.eachElem((node) => {
607
+ if (node.parentNode) {
608
+ node.parentNode.removeChild(node);
609
+ }
610
+ });
611
+ }
612
+ querySelectorAll(selector) {
613
+ // We could merge both methods, but for now this is more readable
614
+ if (selector.indexOf("/shadow/") != -1) {
615
+ return this._querySelectorAllDeep(selector);
616
+ }
617
+ else {
618
+ return this._querySelectorAll(selector);
619
+ }
620
+ }
621
+ closest(selector) {
622
+ // We could merge both methods, but for now this is more readable
623
+ if (selector.indexOf("/shadow/") != -1) {
624
+ return this._closestDeep(selector);
625
+ }
626
+ else {
627
+ return this._closest(selector);
628
+ }
629
+ }
630
+ /**
631
+ * core byId method
632
+ * @param id the id to search for
633
+ * @param includeRoot also match the root element?
634
+ */
635
+ byId(id, includeRoot) {
636
+ let res = [];
637
+ if (includeRoot) {
638
+ res = res.concat(...new Es2019Array_1.Es2019Array(...((this === null || this === void 0 ? void 0 : this.rootNode) || []))
639
+ .filter(((item) => id == item.id))
640
+ .map(item => new DomQuery(item)));
641
+ }
642
+ // for some strange kind of reason the # selector fails
643
+ // on hidden elements we use the attributes match selector
644
+ // that works
645
+ res = res.concat(this.querySelectorAll(`[id="${id}"]`));
646
+ return new DomQuery(...res);
647
+ }
648
+ byIdDeep(id, includeRoot) {
649
+ let res = [];
650
+ if (includeRoot) {
651
+ res = res.concat(new Es2019Array_1.Es2019Array(...((this === null || this === void 0 ? void 0 : this.rootNode) || []))
652
+ .filter(item => id == item.id)
653
+ .map(item => new DomQuery(item)));
654
+ }
655
+ let subItems = this.querySelectorAllDeep(`[id="${id}"]`);
656
+ if (subItems.length) {
657
+ res.push(subItems);
658
+ }
659
+ return new DomQuery(...res);
660
+ }
661
+ /**
662
+ * same as byId just for the tag name
663
+ * @param tagName the tag-name to search for
664
+ * @param includeRoot shall the root element be part of this search
665
+ * @param deep do we also want to go into shadow dom areas
666
+ */
667
+ byTagName(tagName, includeRoot, deep) {
668
+ var _a;
669
+ let res = [];
670
+ if (includeRoot) {
671
+ res = new Es2019Array_1.Es2019Array(...((_a = this === null || this === void 0 ? void 0 : this.rootNode) !== null && _a !== void 0 ? _a : []))
672
+ .filter(element => (element === null || element === void 0 ? void 0 : element.tagName) == tagName)
673
+ .reduce((reduction, item) => reduction.concat([item]), res);
674
+ }
675
+ (deep) ? res.push(this.querySelectorAllDeep(tagName)) : res.push(this.querySelectorAll(tagName));
676
+ return new DomQuery(...res);
677
+ }
678
+ /**
679
+ * attr accessor, usage myQuery.attr("class").value = "bla"
680
+ * or let value myQuery.attr("class").value
681
+ * @param attr the attribute to set
682
+ * @param defaultValue the default value in case nothing is presented (defaults to null)
683
+ */
684
+ attr(attr, defaultValue = null) {
685
+ return new ElementAttribute(this, attr, defaultValue);
686
+ }
687
+ style(cssProperty, defaultValue = null) {
688
+ return new Style(this, cssProperty, defaultValue);
689
+ }
690
+ /**
691
+ * Checks for an existing class in the class attributes
692
+ *
693
+ * @param clazz the class to search for
694
+ */
695
+ hasClass(clazz) {
696
+ let hasIt = false;
697
+ this.eachElem(node => {
698
+ hasIt = node.classList.contains(clazz);
699
+ if (hasIt) {
700
+ return false;
701
+ }
702
+ });
703
+ return hasIt;
704
+ }
705
+ /**
706
+ * appends a class string if not already in the element(s)
707
+ *
708
+ * @param clazz the style class to append
709
+ */
710
+ addClass(clazz) {
711
+ this.eachElem(item => item.classList.add(clazz));
712
+ return this;
713
+ }
714
+ /**
715
+ * remove the style class if in the class definitions
716
+ *
717
+ * @param clazz
718
+ */
719
+ removeClass(clazz) {
720
+ this.eachElem(item => item.classList.remove(clazz));
721
+ return this;
722
+ }
723
+ /**
724
+ * checks whether we have a multipart element in our children
725
+ * or are one
726
+ */
727
+ isMultipartCandidate(deep = false) {
728
+ const FILE_INPUT = "input[type='file']";
729
+ return this.matchesSelector(FILE_INPUT) ||
730
+ ((!deep) ? this.querySelectorAll(FILE_INPUT) :
731
+ this.querySelectorAllDeep(FILE_INPUT)).first().isPresent();
732
+ }
733
+ /**
734
+ * innerHtml
735
+ * equivalent to jQueries html
736
+ * as setter the html is set and the
737
+ * DomQuery is given back
738
+ * as getter the html string is returned
739
+ *
740
+ * @param newInnerHTML the inner html to be inserted
741
+ */
742
+ html(newInnerHTML) {
743
+ if (Monad_1.Optional.fromNullable(newInnerHTML).isAbsent()) {
744
+ return this.isPresent() ? Monad_1.Optional.fromNullable(this.innerHTML) : Monad_1.Optional.absent;
745
+ }
746
+ this.innerHTML = newInnerHTML;
747
+ return this;
748
+ }
749
+ /**
750
+ * Standard dispatch event method, delegated from node
751
+ */
752
+ dispatchEvent(evt) {
753
+ this.eachElem(elem => elem.dispatchEvent(evt));
754
+ return this;
755
+ }
756
+ /**
757
+ * abbreviation property to use innerHTML directly like on the dom tree
758
+ * @param newInnerHTML the new inner html which should be attached to "this" domQuery
759
+ */
760
+ set innerHTML(newInnerHTML) {
761
+ this.eachElem(elem => elem.innerHTML = newInnerHTML);
762
+ }
763
+ /**
764
+ * getter abbreviation to use innerHTML directly
765
+ */
766
+ get innerHTML() {
767
+ let retArr = [];
768
+ this.eachElem(elem => retArr.push(elem.innerHTML));
769
+ return retArr.join("");
770
+ }
771
+ /**
772
+ * since the dom allows both innerHTML and innerHtml we also have to implement both
773
+ * @param newInnerHtml see above
774
+ */
775
+ set innerHtml(newInnerHtml) {
776
+ this.innerHTML = newInnerHtml;
777
+ }
778
+ /**
779
+ * same here, getter for allowing innerHtml directly
780
+ */
781
+ get innerHtml() {
782
+ return this.innerHTML;
783
+ }
784
+ /**
785
+ * filters the current dom query elements
786
+ * upon a given selector
787
+ *
788
+ * @param selector
789
+ */
790
+ filterSelector(selector) {
791
+ let matched = [];
792
+ this.eachElem(item => {
793
+ if (this._mozMatchesSelector(item, selector)) {
794
+ matched.push(item);
795
+ }
796
+ });
797
+ return new DomQuery(...matched);
798
+ }
799
+ /**
800
+ * checks whether any item in this domQuery level matches the selector
801
+ * if there is one element only attached, as root the match is only
802
+ * performed on this element.
803
+ * @param selector
804
+ */
805
+ matchesSelector(selector) {
806
+ return this.asArray
807
+ .some(item => this._mozMatchesSelector(item.getAsElem(0).value, selector));
808
+ }
809
+ /**
810
+ * easy node traversal, you can pass
811
+ * a set of node selectors which are joined as direct children
812
+ *
813
+ * Note!!! The root nodes are not in the getIf, those are always the child nodes
814
+ *
815
+ * @param nodeSelector
816
+ */
817
+ getIf(...nodeSelector) {
818
+ let selectorStage = this.childNodes;
819
+ for (let cnt = 0; cnt < nodeSelector.length; cnt++) {
820
+ selectorStage = selectorStage.filterSelector(nodeSelector[cnt]);
821
+ if (selectorStage.isAbsent()) {
822
+ return selectorStage;
823
+ }
824
+ }
825
+ return selectorStage;
826
+ }
827
+ eachElem(func) {
828
+ for (let cnt = 0, len = this.rootNode.length; cnt < len; cnt++) {
829
+ if (func(this.rootNode[cnt], cnt) === false) {
830
+ break;
831
+ }
832
+ }
833
+ return this;
834
+ }
835
+ firstElem(func = item => item) {
836
+ if (this.rootNode.length > 1) {
837
+ func(this.rootNode[0], 0);
838
+ }
839
+ return this;
840
+ }
841
+ lastElem(func = item => item) {
842
+ if (this.rootNode.length > 1) {
843
+ func(this.rootNode[this.rootNode.length - 1], 0);
844
+ }
845
+ return this;
846
+ }
847
+ each(func) {
848
+ new Es2019Array_1.Es2019Array(...this.rootNode)
849
+ .forEach((item, cnt) => {
850
+ // we could use a filter, but for the best performance we don´t
851
+ if (item == null) {
852
+ return;
853
+ }
854
+ return func(DomQuery.byId(item), cnt);
855
+ });
856
+ return this;
857
+ }
858
+ /**
859
+ * replace convenience function, replaces one or more elements with
860
+ * a set of elements passed as DomQuery
861
+ * @param toReplace the replaced nodes as reference (original node has been replaced)
862
+ */
863
+ replace(toReplace) {
864
+ this.each(item => {
865
+ let asElem = item.getAsElem(0).value;
866
+ let parent = asElem.parentElement;
867
+ let nextElement = asElem.nextElementSibling;
868
+ let previousElement = asElem.previousElementSibling;
869
+ if (nextElement != null) {
870
+ new DomQuery(nextElement).insertBefore(toReplace);
871
+ }
872
+ else if (previousElement) {
873
+ new DomQuery(previousElement).insertAfter(toReplace);
874
+ }
875
+ else {
876
+ new DomQuery(parent).append(toReplace);
877
+ }
878
+ item.delete();
879
+ });
880
+ return toReplace;
881
+ }
882
+ /**
883
+ * returns a new dom query containing only the first element max
884
+ *
885
+ * @param func a an optional callback function to perform an operation on the first element
886
+ */
887
+ first(func = (item) => item) {
888
+ if (this.rootNode.length >= 1) {
889
+ func(this.get(0), 0);
890
+ return this.get(0);
891
+ }
892
+ return this;
893
+ }
894
+ /**
895
+ * returns a new dom query containing only the first element max
896
+ *
897
+ * @param func a an optional callback function to perform an operation on the first element
898
+ */
899
+ last(func = (item) => item) {
900
+ if (this.rootNode.length >= 1) {
901
+ let lastNode = this.get(this.rootNode.length - 1);
902
+ func(lastNode, 0);
903
+ return lastNode;
904
+ }
905
+ return this;
906
+ }
907
+ /**
908
+ * filter function which filters a subset
909
+ *
910
+ * @param func
911
+ */
912
+ filter(func) {
913
+ let reArr = [];
914
+ this.each((item) => {
915
+ func(item) ? reArr.push(item) : null;
916
+ });
917
+ return new DomQuery(...reArr);
918
+ }
919
+ /**
920
+ * global eval head appendix method
921
+ * no other methods are supported anymore
922
+ * @param code the code to be evaluated
923
+ * @param nonce optional nonce key for higher security
924
+ */
925
+ globalEval(code, nonce) {
926
+ var _a, _b, _c;
927
+ const head = (_b = (_a = document.getElementsByTagName("head")) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : (_c = document.documentElement.getElementsByTagName("head")) === null || _c === void 0 ? void 0 : _c[0];
928
+ const script = document.createElement("script");
929
+ if (nonce) {
930
+ if ('undefined' != typeof (script === null || script === void 0 ? void 0 : script.nonce)) {
931
+ script.nonce = nonce;
932
+ }
933
+ else {
934
+ script.setAttribute("nonce", nonce);
935
+ }
936
+ }
937
+ script.type = "text/javascript";
938
+ script.innerHTML = code;
939
+ let newScriptElement = head.appendChild(script);
940
+ head.removeChild(newScriptElement);
941
+ return this;
942
+ }
943
+ /**
944
+ * global eval head appendix method
945
+ * no other methods are supported anymore
946
+ * @param code the code to be evaluated
947
+ * @param nonce optional nonce key for higher security
948
+ */
949
+ globalEvalSticky(code, nonce) {
950
+ let head = document.getElementsByTagName("head")[0] || document.documentElement;
951
+ let script = document.createElement("script");
952
+ this.applyNonce(nonce, script);
953
+ script.type = "text/javascript";
954
+ script.innerHTML = code;
955
+ head.appendChild(script);
956
+ return this;
957
+ }
958
+ /**
959
+ * detaches a set of nodes from their parent elements
960
+ * in a browser independent manner
961
+ * @return {Array} an array of nodes with the detached dom nodes
962
+ */
963
+ detach() {
964
+ this.eachElem((item) => {
965
+ item.parentNode.removeChild(item);
966
+ });
967
+ return this;
968
+ }
969
+ /**
970
+ * appends the current set of elements
971
+ * to the element or first element passed via elem
972
+ * @param elem
973
+ */
974
+ appendTo(elem) {
975
+ if (Lang_1.Lang.isString(elem)) {
976
+ this.appendTo(DomQuery.querySelectorAll(elem));
977
+ return this;
978
+ }
979
+ this.eachElem((item) => {
980
+ let value1 = elem.getAsElem(0).orElseLazy(() => {
981
+ return {
982
+ appendChild: () => {
983
+ }
984
+ };
985
+ }).value;
986
+ value1.appendChild(item);
987
+ });
988
+ return this;
989
+ }
990
+ /**
991
+ * loads and evaluates a script from a source uri
992
+ *
993
+ * @param src the source to be loaded and evaluated
994
+ * @param delay in milliseconds execution default (0 == no delay)
995
+ * @param nonce optional nonce value to allow increased security via nonce crypto token
996
+ */
997
+ loadScriptEval(src, delay = 0, nonce) {
998
+ this._loadScriptEval(false, src, delay, nonce);
999
+ return this;
1000
+ }
1001
+ /**
1002
+ * loads and evaluates a script from a source uri
1003
+ *
1004
+ * @param src the source to be loaded and evaluated
1005
+ * @param delay in milliseconds execution default (0 == no delay)
1006
+ * @param nonce optional nonce parameter for increased security via nonce crypto token
1007
+ */
1008
+ loadScriptEvalSticky(src, delay = 0, nonce) {
1009
+ this._loadScriptEval(true, src, delay, nonce);
1010
+ return this;
1011
+ }
1012
+ insertAfter(...toInsertParams) {
1013
+ this.each(existingItem => {
1014
+ let existingElement = existingItem.getAsElem(0).value;
1015
+ let rootNode = existingElement.parentNode;
1016
+ for (let cnt = 0; cnt < toInsertParams.length; cnt++) {
1017
+ let nextSibling = existingElement.nextSibling;
1018
+ toInsertParams[cnt].eachElem(insertElem => {
1019
+ if (nextSibling) {
1020
+ rootNode.insertBefore(insertElem, nextSibling);
1021
+ existingElement = nextSibling;
1022
+ }
1023
+ else {
1024
+ rootNode.appendChild(insertElem);
1025
+ }
1026
+ });
1027
+ }
1028
+ });
1029
+ let res = [];
1030
+ res.push(this);
1031
+ res = res.concat(toInsertParams);
1032
+ return new DomQuery(...res);
1033
+ }
1034
+ insertBefore(...toInsertParams) {
1035
+ this.each(existingItem => {
1036
+ let existingElement = existingItem.getAsElem(0).value;
1037
+ let rootNode = existingElement.parentNode;
1038
+ for (let cnt = 0; cnt < toInsertParams.length; cnt++) {
1039
+ toInsertParams[cnt].eachElem(insertElem => {
1040
+ rootNode.insertBefore(insertElem, existingElement);
1041
+ });
1042
+ }
1043
+ });
1044
+ let res = [];
1045
+ res.push(this);
1046
+ res = res.concat(toInsertParams);
1047
+ return new DomQuery(...res);
1048
+ }
1049
+ orElse(...elseValue) {
1050
+ if (this.isPresent()) {
1051
+ return this;
1052
+ }
1053
+ else {
1054
+ return new DomQuery(...elseValue);
1055
+ }
1056
+ }
1057
+ orElseLazy(func) {
1058
+ if (this.isPresent()) {
1059
+ return this;
1060
+ }
1061
+ else {
1062
+ return new DomQuery(func());
1063
+ }
1064
+ }
1065
+ /**
1066
+ * find all parents in the hierarchy for which the selector matches
1067
+ * @param selector
1068
+ */
1069
+ allParents(selector) {
1070
+ let parent = this.parent();
1071
+ let ret = [];
1072
+ while (parent.isPresent()) {
1073
+ if (parent.matchesSelector(selector)) {
1074
+ ret.push(parent);
1075
+ }
1076
+ parent = parent.parent();
1077
+ }
1078
+ return new DomQuery(...ret);
1079
+ }
1080
+ /**
1081
+ * finds the first parent in the hierarchy for which the selector matches
1082
+ * @param selector
1083
+ */
1084
+ firstParent(selector) {
1085
+ let parent = this.parent();
1086
+ while (parent.isPresent()) {
1087
+ if (parent.matchesSelector(selector)) {
1088
+ return parent;
1089
+ }
1090
+ parent = parent.parent();
1091
+ }
1092
+ return DomQuery.absent;
1093
+ }
1094
+ /**
1095
+ * fetches all parents as long as the filter criterium matches
1096
+ * @param selector
1097
+ */
1098
+ parentsWhileMatch(selector) {
1099
+ const retArr = [];
1100
+ let parent = this.parent().filter(item => item.matchesSelector(selector));
1101
+ while (parent.isPresent()) {
1102
+ retArr.push(parent);
1103
+ parent = parent.parent().filter(item => item.matchesSelector(selector));
1104
+ }
1105
+ return new DomQuery(...retArr);
1106
+ }
1107
+ parent() {
1108
+ let ret = [];
1109
+ this.eachElem((item) => {
1110
+ let parent = item.parentNode || item.host || item.shadowRoot;
1111
+ if (parent && ret.indexOf(parent) == -1) {
1112
+ ret.push(parent);
1113
+ }
1114
+ });
1115
+ return new DomQuery(...ret);
1116
+ }
1117
+ copyAttrs(sourceItem) {
1118
+ sourceItem.eachElem((sourceNode) => {
1119
+ let attrs = objToArray(sourceNode.attributes);
1120
+ for (let item of attrs) {
1121
+ let value = item.value;
1122
+ let name = item.name;
1123
+ switch (name) {
1124
+ case "id":
1125
+ this.id.value = value;
1126
+ break;
1127
+ case "disabled":
1128
+ this.resolveAttributeHolder("disabled").disabled = value;
1129
+ break;
1130
+ case "checked":
1131
+ this.resolveAttributeHolder("checked").checked = value;
1132
+ break;
1133
+ default:
1134
+ this.attr(name).value = value;
1135
+ }
1136
+ }
1137
+ });
1138
+ return this;
1139
+ }
1140
+ /**
1141
+ * outerHTML convenience method
1142
+ * browsers only support innerHTML but
1143
+ * for instance for your jsf.js we have a full
1144
+ * replace pattern which needs outerHTML processing
1145
+ *
1146
+ * @param markup the markup which should replace the root element
1147
+ * @param runEmbeddedScripts if true the embedded scripts are executed
1148
+ * @param runEmbeddedCss if true the embedded css are executed
1149
+ * @param deep should this also work for shadow dom (run scripts etc...)
1150
+ */
1151
+ outerHTML(markup, runEmbeddedScripts, runEmbeddedCss, deep = false) {
1152
+ var _a;
1153
+ if (this.isAbsent()) {
1154
+ return;
1155
+ }
1156
+ let focusElementId = (_a = document === null || document === void 0 ? void 0 : document.activeElement) === null || _a === void 0 ? void 0 : _a.id;
1157
+ let caretPosition = (focusElementId) ? DomQuery.getCaretPosition(document.activeElement) : null;
1158
+ let nodes = DomQuery.fromMarkup(markup);
1159
+ let res = [];
1160
+ let toReplace = this.getAsElem(0).value;
1161
+ let firstInsert = nodes.get(0);
1162
+ let parentNode = toReplace.parentNode;
1163
+ let replaced = firstInsert.getAsElem(0).value;
1164
+ parentNode.replaceChild(replaced, toReplace);
1165
+ res.push(new DomQuery(replaced));
1166
+ // no replacement possible
1167
+ if (this.isAbsent()) {
1168
+ return this;
1169
+ }
1170
+ let insertAdditionalItems = [];
1171
+ if (nodes.length > 1) {
1172
+ insertAdditionalItems = insertAdditionalItems.concat(...nodes.values.slice(1));
1173
+ res.push(DomQuery.byId(replaced).insertAfter(new DomQuery(...insertAdditionalItems)));
1174
+ }
1175
+ if (runEmbeddedScripts) {
1176
+ this.runScripts();
1177
+ }
1178
+ if (runEmbeddedCss) {
1179
+ this.runCss();
1180
+ }
1181
+ let focusElement = DomQuery.byId(focusElementId);
1182
+ if (focusElementId && focusElement.isPresent() &&
1183
+ caretPosition != null && "undefined" != typeof caretPosition) {
1184
+ focusElement.eachElem(item => DomQuery.setCaretPosition(item, caretPosition));
1185
+ }
1186
+ return nodes;
1187
+ }
1188
+ /**
1189
+ * Run through the given nodes in the DomQuery execute the inline scripts
1190
+ * @param sticky if set to true the evaluated elements will stick to the head, default false
1191
+ * @param whitelisted: optional whitelist function which can filter out script tags which are not processed
1192
+ * defaults to the standard jsf.js exclusion (we use this code for myfaces)
1193
+ */
1194
+ runScripts(sticky = false, whitelisted = DEFAULT_WHITELIST) {
1195
+ const evalCollectedScripts = (scriptsToProcess) => {
1196
+ if (scriptsToProcess.length) {
1197
+ // script source means we have to eval the existing
1198
+ // scripts before we run the 'include' command
1199
+ // this.globalEval(finalScripts.join("\n"));
1200
+ let joinedScripts = [];
1201
+ new Es2019Array_1.Es2019Array(...scriptsToProcess).forEach(item => {
1202
+ if (!item.nonce) {
1203
+ joinedScripts.push(item.evalText);
1204
+ }
1205
+ else {
1206
+ if (joinedScripts.length) {
1207
+ this.globalEval(joinedScripts.join("\n"));
1208
+ joinedScripts.length = 0;
1209
+ }
1210
+ (!sticky) ?
1211
+ this.globalEval(item.evalText, item.nonce) :
1212
+ this.globalEvalSticky(item.evalText, item.nonce);
1213
+ }
1214
+ });
1215
+ if (joinedScripts.length) {
1216
+ (!sticky) ? this.globalEval(joinedScripts.join("\n")) :
1217
+ this.globalEvalSticky(joinedScripts.join("\n"));
1218
+ joinedScripts.length = 0;
1219
+ }
1220
+ scriptsToProcess = [];
1221
+ }
1222
+ return scriptsToProcess;
1223
+ };
1224
+ let finalScripts = [], allowedItemTypes = ["", "script", "text/javascript", "text/ecmascript", "ecmascript"], execScript = (item) => {
1225
+ var _a, _b, _c, _d;
1226
+ let tagName = item.tagName;
1227
+ let itemType = ((_a = item === null || item === void 0 ? void 0 : item.type) !== null && _a !== void 0 ? _a : '').toLowerCase();
1228
+ if (tagName &&
1229
+ eqi(tagName, "script") &&
1230
+ allowedItemTypes.indexOf(itemType) != -1) {
1231
+ let src = item.getAttribute('src');
1232
+ if ('undefined' != typeof src
1233
+ && null != src
1234
+ && src.length > 0) {
1235
+ let nonce = (_b = item === null || item === void 0 ? void 0 : item.nonce) !== null && _b !== void 0 ? _b : item.getAttribute('nonce').value;
1236
+ // we have to move this into an inner if because chrome otherwise chokes
1237
+ // due to changing the and order instead of relying on left to right
1238
+ // if jsf.js is already registered we do not replace it anymore
1239
+ if (whitelisted(src)) {
1240
+ // we run the collected scripts, before we run the 'include' command
1241
+ finalScripts = evalCollectedScripts(finalScripts);
1242
+ if (!sticky) {
1243
+ (!!nonce) ? this.loadScriptEval(src, 0, nonce) :
1244
+ // if no nonce is set we do not pass any once
1245
+ this.loadScriptEval(src, 0);
1246
+ }
1247
+ else {
1248
+ (!!nonce) ? this.loadScriptEvalSticky(src, 0, nonce) :
1249
+ // if no nonce is set we do not pass any once
1250
+ this.loadScriptEvalSticky(src, 0);
1251
+ }
1252
+ }
1253
+ }
1254
+ else {
1255
+ // embedded script auto eval
1256
+ // probably not needed anymore
1257
+ let evalText = trim(item.text || item.innerText || item.innerHTML);
1258
+ let go = true;
1259
+ while (go) {
1260
+ go = false;
1261
+ if (evalText.substring(0, 4) == "<!--") {
1262
+ evalText = evalText.substring(4);
1263
+ go = true;
1264
+ }
1265
+ if (evalText.substring(0, 4) == "//<!--") {
1266
+ evalText = evalText.substring(6);
1267
+ go = true;
1268
+ }
1269
+ if (evalText.substring(0, 11) == "//<![CDATA[") {
1270
+ evalText = evalText.substring(11);
1271
+ go = true;
1272
+ }
1273
+ }
1274
+ let nonce = (_d = (_c = item === null || item === void 0 ? void 0 : item.nonce) !== null && _c !== void 0 ? _c : item.getAttribute('nonce').value) !== null && _d !== void 0 ? _d : '';
1275
+ // we have to run the script under a global context
1276
+ // we store the script for fewer calls to eval
1277
+ finalScripts.push({
1278
+ nonce,
1279
+ evalText
1280
+ });
1281
+ }
1282
+ }
1283
+ };
1284
+ try {
1285
+ let scriptElements = new DomQuery(this.filterSelector("script"), this.querySelectorAll("script"));
1286
+ // script execution order by relative pos in their dom tree
1287
+ scriptElements.asArray
1288
+ .flatMap(item => [...item.values])
1289
+ .sort((node1, node2) => node1.compareDocumentPosition(node2) - 3) // preceding 2, following == 4)
1290
+ .forEach(item => execScript(item));
1291
+ evalCollectedScripts(finalScripts);
1292
+ }
1293
+ catch (e) {
1294
+ if (console && console.error) {
1295
+ // not sure if we
1296
+ // should use our standard
1297
+ // error mechanisms here
1298
+ // because in the head appendix
1299
+ // method only a console
1300
+ // error would be raised as well
1301
+ console.error(e.message || e.description);
1302
+ }
1303
+ }
1304
+ finally {
1305
+ // the usual ie6 fix code
1306
+ // the IE6 garbage collector is broken
1307
+ // nulling closures helps somewhat to reduce
1308
+ // mem leaks, which are impossible to avoid
1309
+ // at this browser
1310
+ execScript = null;
1311
+ }
1312
+ return this;
1313
+ }
1314
+ runCss() {
1315
+ const execCss = (toReplace) => {
1316
+ const _toReplace = DomQuery.byId(toReplace);
1317
+ const tagName = _toReplace.tagName.orElse("").value;
1318
+ let newElement = DomQuery.fromMarkup(`<${tagName.toLowerCase()} />`);
1319
+ newElement = newElement.copyAttrs(_toReplace);
1320
+ newElement.innerHTML = toReplace.innerHTML;
1321
+ // css suffices a simple replace to get it eval-ed, no need
1322
+ // for a full head replace
1323
+ _toReplace.replace(newElement);
1324
+ };
1325
+ const scriptElements = new DomQuery(this.filterSelector("link, style"), this.querySelectorAll("link, style"));
1326
+ scriptElements.asArray
1327
+ .flatMap(item => [...item.values])
1328
+ // sort to make sure the execution order is correct
1329
+ // this is needed because we mix 2 queries together
1330
+ // -3 is needed due to the compareDocumentPosition return value
1331
+ .sort((node1, node2) => node1.compareDocumentPosition(node2) - 3)
1332
+ .forEach(item => execCss(item));
1333
+ return this;
1334
+ }
1335
+ /**
1336
+ * fires a click event on the underlying dom elements
1337
+ */
1338
+ click() {
1339
+ this.fireEvent("click");
1340
+ return this;
1341
+ }
1342
+ addEventListener(type, listener, options) {
1343
+ this.eachElem((node) => node.addEventListener(type, listener, options));
1344
+ return this;
1345
+ }
1346
+ removeEventListener(type, listener, options) {
1347
+ this.eachElem((node) => node.removeEventListener(type, listener, options));
1348
+ return this;
1349
+ }
1350
+ /**
1351
+ * fires an event
1352
+ */
1353
+ fireEvent(eventName, options = {}) {
1354
+ // merge with last one having the highest priority
1355
+ let finalOptions = {
1356
+ bubbles: true, cancelable: true
1357
+ };
1358
+ finalOptions = (0, AssocArray_1.simpleShallowMerge)(finalOptions, options);
1359
+ this.eachElem((node) => {
1360
+ let doc;
1361
+ if (node.ownerDocument) {
1362
+ doc = node.ownerDocument;
1363
+ }
1364
+ else if (node.nodeType == 9) {
1365
+ // the node may be the document itself, nodeType 9 = DOCUMENT_NODE
1366
+ doc = node;
1367
+ }
1368
+ else {
1369
+ throw new Error("Invalid node passed to fireEvent: " + node.id);
1370
+ }
1371
+ if (node.dispatchEvent) {
1372
+ // Gecko-style approach (now the standard) takes more work
1373
+ let EventClass = Event;
1374
+ // Different events have different event classes.
1375
+ // If this switch statement can't map an eventName to an EventClass,
1376
+ // the event firing is going to fail.
1377
+ // extend this list on demand
1378
+ switch (eventName) {
1379
+ case "click": // Dispatching of 'click' appears to not work correctly in Safari. Use 'mousedown' or 'mouseup' instead.
1380
+ case "mousedown":
1381
+ case "mouseup":
1382
+ case "mousemove":
1383
+ EventClass = this.global().MouseEvent;
1384
+ break;
1385
+ case "keyup":
1386
+ case "keydown":
1387
+ case "keypress":
1388
+ EventClass = this.global().KeyboardEvent;
1389
+ break;
1390
+ case "focus":
1391
+ case "change":
1392
+ case "blur":
1393
+ case "select":
1394
+ break;
1395
+ default:
1396
+ throw "fireEvent: Couldn't find an event class for event '" + eventName + "'.";
1397
+ }
1398
+ let event = new EventClass(eventName, finalOptions);
1399
+ // this is added as an extra to allow internally the detection of synthetic events
1400
+ // not used atm, but it does not hurt to have the extra info
1401
+ event.synthetic = true; // allow detection of synthetic events
1402
+ // The second parameter says go ahead with the default action
1403
+ node.dispatchEvent(event);
1404
+ }
1405
+ else if (node.fireEvent) {
1406
+ // IE-old school style, you can drop this if you don't need to support IE8 and lower
1407
+ let event = doc.createEventObject();
1408
+ event.synthetic = true; // allow detection of synthetic events
1409
+ Object.keys(finalOptions).forEach(key => event[key] = finalOptions[key]);
1410
+ node.fireEvent("on" + eventName, event);
1411
+ }
1412
+ });
1413
+ }
1414
+ textContent(joinString = "") {
1415
+ return this.asArray
1416
+ .map((value) => {
1417
+ let item = value.getAsElem(0).orElseLazy(() => {
1418
+ return {
1419
+ textContent: ""
1420
+ };
1421
+ }).value;
1422
+ return item.textContent || "";
1423
+ })
1424
+ .reduce((text1, text2) => [text1, joinString, text2].join(""), "");
1425
+ }
1426
+ innerText(joinString = "") {
1427
+ return this.asArray
1428
+ .map((value) => {
1429
+ let item = value.getAsElem(0).orElseLazy(() => {
1430
+ return {
1431
+ innerText: ""
1432
+ };
1433
+ }).value;
1434
+ return item.innerText || "";
1435
+ })
1436
+ .reduce((text1, text2) => {
1437
+ return [text1, text2].join(joinString);
1438
+ }, "");
1439
+ }
1440
+ /**
1441
+ * encodes all input elements properly into respective
1442
+ * config entries, this can be used
1443
+ * for legacy systems, for newer use-cases, use the
1444
+ * HTML5 Form class which all newer browsers provide
1445
+ *
1446
+ * @param toMerge optional config which can be merged in
1447
+ * @return a copy pf
1448
+ */
1449
+ encodeFormElement(toMerge = {}) {
1450
+ // browser behavior no element name no encoding (normal submit fails in that case)
1451
+ // https:// issues.apache.org/jira/browse/MYFACES-2847
1452
+ if (this.name.isAbsent()) {
1453
+ return;
1454
+ }
1455
+ // let´s keep it side-effects free
1456
+ let target = (0, AssocArray_1.simpleShallowMerge)(toMerge);
1457
+ this.each((element) => {
1458
+ var _a, _b;
1459
+ if (element.name.isAbsent()) { // no name, no encoding
1460
+ return;
1461
+ }
1462
+ let name = element.name.value;
1463
+ let tagName = element.tagName.orElse("__none__").value.toLowerCase();
1464
+ let elemType = element.type.orElse("__none__").value.toLowerCase();
1465
+ elemType = elemType.toLowerCase();
1466
+ // routine for all elements
1467
+ // rules:
1468
+ // - process only input, textarea and select elements
1469
+ // - elements must have attribute "name"
1470
+ // - elements must not be disabled
1471
+ if (((tagName == "input" || tagName == "textarea" || tagName == "select") &&
1472
+ (name != null && name != "")) && !element.disabled) {
1473
+ // routine for select elements
1474
+ // rules:
1475
+ // - if select-one and value-Attribute exist => "name=value"
1476
+ // (also if value empty => "name=")
1477
+ // - if select-one and value-Attribute don't exist =>
1478
+ // "name=DisplayValue"
1479
+ // - if select multi and multiple selected => "name=value1&name=value2"
1480
+ // - if select and selectedIndex=-1 don't submit
1481
+ if (tagName == "select") {
1482
+ // selectedIndex must be >= 0 to be submitted
1483
+ let selectElem = element.getAsElem(0).value;
1484
+ if (selectElem.selectedIndex >= 0) {
1485
+ let uLen = selectElem.options.length;
1486
+ for (let u = 0; u < uLen; u++) {
1487
+ // find all selected options
1488
+ // let subBuf = [];
1489
+ if (selectElem.options[u].selected) {
1490
+ let elementOption = selectElem.options[u];
1491
+ (0, AssocArray_1.append)(target, name).value = (elementOption.getAttribute("value") != null) ?
1492
+ elementOption.value : elementOption.text;
1493
+ }
1494
+ }
1495
+ }
1496
+ }
1497
+ // routine for remaining elements
1498
+ // rules:
1499
+ // - don't submit no selects (processed above), buttons, reset buttons, submit buttons,
1500
+ // - submit checkboxes and radio inputs only if checked
1501
+ if ((tagName != ALLOWED_SUBMITTABLE_ELEMENTS.SELECT &&
1502
+ elemType != ALLOWED_SUBMITTABLE_ELEMENTS.BUTTON &&
1503
+ elemType != ALLOWED_SUBMITTABLE_ELEMENTS.RESET &&
1504
+ elemType != ALLOWED_SUBMITTABLE_ELEMENTS.SUBMIT &&
1505
+ elemType != ALLOWED_SUBMITTABLE_ELEMENTS.IMAGE) && ((elemType != ALLOWED_SUBMITTABLE_ELEMENTS.CHECKBOX && elemType != ALLOWED_SUBMITTABLE_ELEMENTS.RADIO) ||
1506
+ element.checked)) {
1507
+ let uploadedFiles = (_b = (_a = element.value) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.files;
1508
+ let filesArr = uploadedFiles !== null && uploadedFiles !== void 0 ? uploadedFiles : [];
1509
+ if (filesArr === null || filesArr === void 0 ? void 0 : filesArr.length) { //files can be empty but set
1510
+ // xhr level2, single multiple must be passes as they are
1511
+ (0, AssocArray_1.assign)(target, name).value = Array.from(filesArr);
1512
+ }
1513
+ else {
1514
+ if (!!uploadedFiles) { //we skip empty file elements i
1515
+ return;
1516
+ }
1517
+ //checkboxes etc.. need to be appended
1518
+ (0, AssocArray_1.append)(target, name).value = element.inputValue.value;
1519
+ }
1520
+ }
1521
+ }
1522
+ });
1523
+ return target;
1524
+ }
1525
+ get cDATAAsString() {
1526
+ let TYPE_CDATA_BLOCK = 4;
1527
+ let res = this.asArray
1528
+ .flatMap(item => {
1529
+ return item.childNodes.asArray;
1530
+ })
1531
+ .filter(item => {
1532
+ var _a, _b;
1533
+ return ((_b = (_a = item === null || item === void 0 ? void 0 : item.value) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.nodeType) == TYPE_CDATA_BLOCK;
1534
+ })
1535
+ .reduce((reduced, item) => {
1536
+ var _a, _b, _c;
1537
+ reduced.push((_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.value) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : "");
1538
+ return reduced;
1539
+ }, []);
1540
+ /*let res: any = this.lazyStream.flatMap(item => {
1541
+ return item.childNodes.stream
1542
+ }).filter(item => {
1543
+ return item?.value?.value?.nodeType == TYPE_CDATA_BLOCK;
1544
+ }).reduce((reduced: Array<any>, item: DomQuery) => {
1545
+ reduced.push((<any>item?.value?.value)?.data ?? "");
1546
+ return reduced;
1547
+ }, []).value;*/
1548
+ // response may contain several blocks
1549
+ return res.join("");
1550
+ }
1551
+ subNodes(from, to) {
1552
+ if (Monad_1.Optional.fromNullable(to).isAbsent()) {
1553
+ to = this.length;
1554
+ }
1555
+ return new DomQuery(...this.rootNode.slice(from, Math.min(to, this.length)));
1556
+ }
1557
+ limits(end) {
1558
+ this._limits = end;
1559
+ return this;
1560
+ }
1561
+ //-- internally exposed methods needed for the interconnectivity
1562
+ hasNext() {
1563
+ let isLimitsReached = this._limits != -1 && this.pos >= this._limits - 1;
1564
+ let isEndOfArray = this.pos >= this.values.length - 1;
1565
+ return !(isLimitsReached ||
1566
+ isEndOfArray);
1567
+ }
1568
+ next() {
1569
+ if (!this.hasNext()) {
1570
+ return null;
1571
+ }
1572
+ this.pos++;
1573
+ return new DomQuery(this.values[this.pos]);
1574
+ }
1575
+ lookAhead(cnt = 1) {
1576
+ if ((this.values.length - 1) < (this.pos + cnt)) {
1577
+ return SourcesCollectors_1.ITERATION_STATUS.EO_STRM;
1578
+ }
1579
+ return new DomQuery(this.values[this.pos + cnt]);
1580
+ }
1581
+ current() {
1582
+ if (this.pos == -1) {
1583
+ return SourcesCollectors_1.ITERATION_STATUS.BEF_STRM;
1584
+ }
1585
+ return new DomQuery(this.values[this.pos]);
1586
+ }
1587
+ reset() {
1588
+ this.pos = -1;
1589
+ }
1590
+ attachShadow(params = { mode: "open" }) {
1591
+ let shadowRoots = [];
1592
+ this.eachElem((item) => {
1593
+ let shadowElement;
1594
+ if (item === null || item === void 0 ? void 0 : item.attachShadow) {
1595
+ shadowElement = DomQuery.byId(item.attachShadow(params));
1596
+ shadowRoots.push(shadowElement);
1597
+ }
1598
+ else {
1599
+ throw new Error("Shadow dom creation not supported by the browser, please use a shim, to gain this functionality");
1600
+ }
1601
+ });
1602
+ return new DomQuery(...shadowRoots);
1603
+ }
1604
+ /**
1605
+ * helper to fix a common dom problem
1606
+ * we have to wait until a certain condition is met, in most of the cases we just want to know whether an element is present in the sub dom-tree before being able to proceed
1607
+ * @param condition
1608
+ * @param options
1609
+ */
1610
+ waitUntilDom(condition, options = {
1611
+ attributes: true,
1612
+ childList: true,
1613
+ subtree: true,
1614
+ timeout: 500,
1615
+ interval: 100
1616
+ }) {
1617
+ return __awaiter(this, void 0, void 0, function* () {
1618
+ return waitUntilDom(this, condition, options);
1619
+ });
1620
+ }
1621
+ /**
1622
+ * returns the embedded shadow elements
1623
+ */
1624
+ get shadowElements() {
1625
+ let shadowElements = this.querySelectorAll("*")
1626
+ .filter(item => item.hasShadow);
1627
+ let mapped = (shadowElements.allElems() || []).map(element => element.shadowRoot);
1628
+ return new DomQuery(...mapped);
1629
+ }
1630
+ get shadowRoot() {
1631
+ let shadowRoots = [];
1632
+ for (let cnt = 0; cnt < this.rootNode.length; cnt++) {
1633
+ if (this.rootNode[cnt].shadowRoot) {
1634
+ shadowRoots.push(this.rootNode[cnt].shadowRoot);
1635
+ }
1636
+ }
1637
+ return new DomQuery(...shadowRoots);
1638
+ }
1639
+ get hasShadow() {
1640
+ for (let cnt = 0; cnt < this.rootNode.length; cnt++) {
1641
+ if (this.rootNode[cnt].shadowRoot) {
1642
+ return true;
1643
+ }
1644
+ }
1645
+ return false;
1646
+ }
1647
+ // from
1648
+ // http:// blog.vishalon.net/index.php/javascript-getting-and-setting-caret-position-in-textarea/
1649
+ static getCaretPosition(ctrl) {
1650
+ let caretPos = 0;
1651
+ try {
1652
+ if (document === null || document === void 0 ? void 0 : document.selection) {
1653
+ ctrl.focus();
1654
+ let selection = document.selection.createRange();
1655
+ // the selection now is start zero
1656
+ selection.moveStart('character', -ctrl.value.length);
1657
+ // the caret-position is the selection start
1658
+ caretPos = selection.text.length;
1659
+ }
1660
+ }
1661
+ catch (e) {
1662
+ // now this is ugly, but not supported input types throw errors for selectionStart
1663
+ // just in case someone dumps this code onto unsupported browsers
1664
+ }
1665
+ return caretPos;
1666
+ }
1667
+ /**
1668
+ * sets the caret position
1669
+ *
1670
+ * @param ctrl the control to set the caret position to
1671
+ * @param pos the position to set
1672
+ *
1673
+ * note if the control does not have any selectable and focusable behavior
1674
+ * calling this method does nothing (silent fail)
1675
+ *
1676
+ */
1677
+ static setCaretPosition(ctrl, pos) {
1678
+ (ctrl === null || ctrl === void 0 ? void 0 : ctrl.focus) ? ctrl === null || ctrl === void 0 ? void 0 : ctrl.focus() : null;
1679
+ // the selection range is our caret position
1680
+ (ctrl === null || ctrl === void 0 ? void 0 : ctrl.setSelectiongRange) ? ctrl === null || ctrl === void 0 ? void 0 : ctrl.setSelectiongRange(pos, pos) : null;
1681
+ }
1682
+ /**
1683
+ * Implementation of an iterator
1684
+ * to allow loops over dom query collections
1685
+ */
1686
+ [Symbol.iterator]() {
1687
+ return {
1688
+ next: () => {
1689
+ let done = !this.hasNext();
1690
+ let val = this.next();
1691
+ return {
1692
+ done: done,
1693
+ value: val
1694
+ };
1695
+ }
1696
+ };
1697
+ }
1698
+ /**
1699
+ * Concatenates the elements of two Dom Queries into a single one
1700
+ * @param toAttach the elements to attach
1701
+ * @param filterDoubles filter out possible double elements (aka same markup)
1702
+ */
1703
+ concat(toAttach, filterDoubles = true) {
1704
+ let domQueries = this.asArray;
1705
+ const ret = new DomQuery(...domQueries.concat(toAttach.asArray));
1706
+ // we now filter the doubles out
1707
+ if (!filterDoubles) {
1708
+ return ret;
1709
+ }
1710
+ let idx = {}; // ie11 does not support sets, we have to fake it
1711
+ return new DomQuery(...ret.asArray.filter(node => {
1712
+ const notFound = !(idx === null || idx === void 0 ? void 0 : idx[node.value.value.outerHTML]);
1713
+ idx[node.value.value.outerHTML] = true;
1714
+ return notFound;
1715
+ }));
1716
+ }
1717
+ append(elem) {
1718
+ this.each(item => elem.appendTo(item));
1719
+ return this;
1720
+ }
1721
+ prependTo(elem) {
1722
+ elem.eachElem(item => {
1723
+ item.prepend(...this.allElems());
1724
+ });
1725
+ return this;
1726
+ }
1727
+ prepend(elem) {
1728
+ this.eachElem(item => {
1729
+ item.prepend(...elem.allElems());
1730
+ });
1731
+ return this;
1732
+ }
1733
+ /**
1734
+ * query selector all on the existing dom queryX object
1735
+ *
1736
+ * @param selector the standard selector
1737
+ * @return a DomQuery with the results
1738
+ */
1739
+ _querySelectorAll(selector) {
1740
+ var _a, _b;
1741
+ if (!((_a = this === null || this === void 0 ? void 0 : this.rootNode) === null || _a === void 0 ? void 0 : _a.length)) {
1742
+ return this;
1743
+ }
1744
+ let nodes = [];
1745
+ for (let cnt = 0; cnt < this.rootNode.length; cnt++) {
1746
+ if (!((_b = this.rootNode[cnt]) === null || _b === void 0 ? void 0 : _b.querySelectorAll)) {
1747
+ continue;
1748
+ }
1749
+ let res = this.rootNode[cnt].querySelectorAll(selector);
1750
+ nodes = nodes.concat(...objToArray(res));
1751
+ }
1752
+ return new DomQuery(...nodes);
1753
+ }
1754
+ /*deep with a selector and a pseudo /shadow/ marker to break into the next level*/
1755
+ _querySelectorAllDeep(selector) {
1756
+ var _a;
1757
+ if (!((_a = this === null || this === void 0 ? void 0 : this.rootNode) === null || _a === void 0 ? void 0 : _a.length)) {
1758
+ return this;
1759
+ }
1760
+ let foundNodes = new DomQuery(...this.rootNode);
1761
+ let selectors = selector.split(/\/shadow\//);
1762
+ for (let cnt2 = 0; cnt2 < selectors.length; cnt2++) {
1763
+ if (selectors[cnt2] == "") {
1764
+ continue;
1765
+ }
1766
+ let levelSelector = selectors[cnt2];
1767
+ foundNodes = foundNodes.querySelectorAll(levelSelector);
1768
+ if (cnt2 < selectors.length - 1) {
1769
+ foundNodes = foundNodes.shadowRoot;
1770
+ }
1771
+ }
1772
+ return foundNodes;
1773
+ }
1774
+ /**
1775
+ * query selector all on the existing dom queryX object
1776
+ *
1777
+ * @param selector the standard selector
1778
+ * @return a DomQuery with the results
1779
+ */
1780
+ _closest(selector) {
1781
+ var _a, _b;
1782
+ if (!((_a = this === null || this === void 0 ? void 0 : this.rootNode) === null || _a === void 0 ? void 0 : _a.length)) {
1783
+ return this;
1784
+ }
1785
+ let nodes = [];
1786
+ for (let cnt = 0; cnt < this.rootNode.length; cnt++) {
1787
+ if (!((_b = this.rootNode[cnt]) === null || _b === void 0 ? void 0 : _b.closest)) {
1788
+ continue;
1789
+ }
1790
+ let res = [this.rootNode[cnt].closest(selector)];
1791
+ nodes = nodes.concat(...res);
1792
+ }
1793
+ return new DomQuery(...nodes);
1794
+ }
1795
+ /*deep with a selector and a pseudo /shadow/ marker to break into the next level*/
1796
+ _closestDeep(selector) {
1797
+ var _a;
1798
+ if (!((_a = this === null || this === void 0 ? void 0 : this.rootNode) === null || _a === void 0 ? void 0 : _a.length)) {
1799
+ return this;
1800
+ }
1801
+ let foundNodes = new DomQuery(...this.rootNode);
1802
+ let selectors = selector.split(/\/shadow\//);
1803
+ for (let cnt2 = 0; cnt2 < selectors.length; cnt2++) {
1804
+ if (selectors[cnt2] == "") {
1805
+ continue;
1806
+ }
1807
+ let levelSelector = selectors[cnt2];
1808
+ foundNodes = foundNodes.closest(levelSelector);
1809
+ if (cnt2 < selectors.length - 1) {
1810
+ foundNodes = foundNodes.shadowRoot;
1811
+ }
1812
+ }
1813
+ return foundNodes;
1814
+ }
1815
+ // source: https:// developer.mozilla.org/en-US/docs/Web/API/Element/matches
1816
+ // code snippet license: https:// creativecommons.org/licenses/by-sa/2.5/
1817
+ /**
1818
+ * matches selector call in a browser independent manner
1819
+ *
1820
+ * @param toMatch
1821
+ * @param selector
1822
+ * @private
1823
+ */
1824
+ _mozMatchesSelector(toMatch, selector) {
1825
+ let prototypeOwner = toMatch;
1826
+ let matchesSelector = prototypeOwner.matches ||
1827
+ prototypeOwner.matchesSelector ||
1828
+ prototypeOwner.mozMatchesSelector ||
1829
+ prototypeOwner.msMatchesSelector ||
1830
+ prototypeOwner.oMatchesSelector ||
1831
+ prototypeOwner.webkitMatchesSelector ||
1832
+ function (s) {
1833
+ let matches = (document || ownerDocument).querySelectorAll(s), i = matches.length;
1834
+ while (--i >= 0 && matches.item(i) !== toMatch) {
1835
+ }
1836
+ return i > -1;
1837
+ };
1838
+ return matchesSelector.call(toMatch, selector);
1839
+ }
1840
+ /**
1841
+ * sticky non-sticky unified code of the load script eval
1842
+ * implementation if programmatic &gt;script src="... loading
1843
+ *
1844
+ * @param sticky if set to true a head element is left in the dom tree after the script has loaded
1845
+ *
1846
+ * @param src the sec to load
1847
+ * @param delay delay the script loading x ms (default immediately === 0)
1848
+ * @param nonce optional nonce token to be passed into the script tag
1849
+ * @private
1850
+ */
1851
+ _loadScriptEval(sticky, src, delay = 0, nonce) {
1852
+ let srcNode = this.createSourceNode(src, nonce);
1853
+ let nonceCheck = this.createSourceNode(null, nonce);
1854
+ let marker = `nonce_${Date.now()}_${Math.random()}`;
1855
+ nonceCheck.innerHTML = `document.head["${marker}"] = true`; // noop
1856
+ let head = document.head;
1857
+ // upfront nonce check, needed mostly for testing
1858
+ // but cannot hurt to block src calls which have invalid nonce on localhost
1859
+ // the reason for doing this up until now we have a similar construct automatically
1860
+ // by loading the scripts via xhr and then embedding them.
1861
+ // this is not needed anymore but the nonce is more relaxed with script src
1862
+ // we now enforce it the old way
1863
+ head.appendChild(nonceCheck);
1864
+ head.removeChild(nonceCheck);
1865
+ if (!head[marker]) {
1866
+ return;
1867
+ }
1868
+ try {
1869
+ if (!delay) {
1870
+ head.appendChild(srcNode);
1871
+ if (!sticky) {
1872
+ head.removeChild(srcNode);
1873
+ }
1874
+ }
1875
+ else {
1876
+ setTimeout(() => {
1877
+ head.appendChild(srcNode);
1878
+ if (!sticky) {
1879
+ head.removeChild(srcNode);
1880
+ }
1881
+ }, delay);
1882
+ }
1883
+ }
1884
+ finally {
1885
+ delete head[marker];
1886
+ }
1887
+ return this;
1888
+ }
1889
+ /**
1890
+ * resolves an attribute holder compared
1891
+ * @param attrName the attribute name
1892
+ */
1893
+ resolveAttributeHolder(attrName = "value") {
1894
+ let ret = [];
1895
+ ret[attrName] = null;
1896
+ return (attrName in this.getAsElem(0).value) ?
1897
+ this.getAsElem(0).value :
1898
+ ret;
1899
+ }
1900
+ createSourceNode(src, nonce) {
1901
+ let srcNode = document.createElement("script");
1902
+ srcNode.type = "text/javascript";
1903
+ if (!!nonce) {
1904
+ if ('undefined' != typeof (srcNode === null || srcNode === void 0 ? void 0 : srcNode.nonce)) {
1905
+ srcNode.nonce = nonce;
1906
+ }
1907
+ else {
1908
+ srcNode.setAttribute("nonce", nonce);
1909
+ }
1910
+ }
1911
+ if (!!src) {
1912
+ srcNode.src = src;
1913
+ }
1914
+ return srcNode;
1915
+ }
1916
+ applyNonce(nonce, script) {
1917
+ if (nonce) {
1918
+ if ('undefined' != typeof (script === null || script === void 0 ? void 0 : script.nonce)) {
1919
+ script.nonce = nonce;
1920
+ }
1921
+ else {
1922
+ script.setAttribute("nonce", nonce);
1923
+ }
1924
+ }
1925
+ }
1926
+ }
1927
+ exports.DomQuery = DomQuery;
1928
+ DomQuery.absent = new DomQuery();
1929
+ /**
1930
+ * reference to the environmental global object
1931
+ */
1932
+ DomQuery.global = Global_1._global$;
1933
+ /**
1934
+ * Various collectors
1935
+ * which can be used in conjunction with Streams
1936
+ */
1937
+ /**
1938
+ * A collector which bundles a full dom query stream into a single dom query element
1939
+ *
1940
+ * This connects basically our stream back into DomQuery
1941
+ */
1942
+ class DomQueryCollector {
1943
+ constructor() {
1944
+ this.data = [];
1945
+ }
1946
+ collect(element) {
1947
+ this.data.push(element);
1948
+ }
1949
+ get finalValue() {
1950
+ return new DomQuery(...this.data);
1951
+ }
1952
+ }
1953
+ exports.DomQueryCollector = DomQueryCollector;
1954
+ /**
1955
+ * abbreviation for DomQuery
1956
+ */
1957
+ exports.DQ = DomQuery;
1958
+ // noinspection JSUnusedGlobalSymbols
1959
+ /**
1960
+ * replacement for the jquery $
1961
+ */
1962
+ exports.DQ$ = DomQuery.querySelectorAll;
1963
+ //# sourceMappingURL=DomQuery.js.map