jqx-es 1.2.6 → 1.2.8

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.
@@ -60,7 +60,7 @@ export default function($) {
60
60
  if (evt.target.closest(`#closeHandleIcon`) || !evt.target.closest(`#jqxPopupContent`)) {
61
61
  initHidePopup();
62
62
  }
63
-
63
+
64
64
  return true;
65
65
  }
66
66
 
@@ -1,42 +1,53 @@
1
+ import { default as IS, maybe } from "./TypeofAnything.js";
2
+ import {ATTRS} from "./EmbedResources.js";
1
3
  import {default as tagFNFactory} from "./tinyDOM.js";
2
- import {default as IS, maybe} from "./TypeofAnything.js";
3
4
  import styleFactory from "./LifeCSS.js";
4
- import {ATTRS} from "./EmbedResources.js";
5
+ import {createElementFromHtmlString, inject2DOMTree, cleanupHtml} from "./DOM.js";
6
+ import PopupFactory from "./Popup.js";
7
+ import { listeners, default as HandleFactory } from "./HandlerFactory.js";
8
+ import tagLib from "./HTMLTags.js";
5
9
 
10
+ const systemLog = systemLogFactory();
11
+ const insertPositions = Object.freeze(new Proxy({
12
+ start: "afterbegin", afterbegin: "afterbegin",
13
+ end: "beforeend", beforeend: "beforeend",
14
+ before: "beforebegin", beforebegin: "beforebegin",
15
+ after: "afterend", afterend: "afterend" }, {
16
+ get(obj, key) { return obj[String(key).toLowerCase()] ?? obj[key]; }
17
+ }));
6
18
  const characters4RandomString = [...Array(26)]
7
19
  .map((x, i) => String.fromCharCode(i + 65))
8
20
  .concat([...Array(26)].map((x, i) => String.fromCharCode(i + 97)))
9
21
  .concat([...Array(10)].map((x, i) => `${i}`));
10
- const systemLog = systemLogFactory();
11
22
  const datasetKeyProxy = Object.freeze({
12
23
  get(obj, key) { return obj[toCamelcase(key)] || obj[key]; },
13
24
  enumerable: false,
14
25
  configurable: false
15
26
  });
16
- const insertPositions = Object.freeze(new Proxy({
17
- start: "afterbegin", afterbegin: "afterbegin",
18
- end: "beforeend", beforeend: "beforeend",
19
- before: "beforebegin", beforebegin: "beforebegin",
20
- after: "afterend", afterend: "afterend" }, {
21
- get(obj, key) { return obj[String(key).toLowerCase()] ?? obj[key]; }
22
- }));
23
27
 
24
28
  export {
25
- addHandlerId, after, applyStyle, assignAttrValues, before, checkProp, cloneAndDestroy, css, datasetKeyProxy,
26
- ElemArray2HtmlString, emptyElement, escHtml, ExamineElementFeatureFactory, findParentScrollDistance,
27
- input2Collection, insertPositions, IS, isArrayOfHtmlElements, isArrayOfHtmlStrings, isCommentOrTextNode,
28
- isHtmlString, isNode, isNonEmptyString, logTime, loop, maybe, randomNr, randomString, resolveEventTypeParameter,
29
- selectedFactoryHelpers, setCollectionFromCssSelector, setData, styleFactory, systemLog, tagFNFactory,
30
- toCamelcase, toDashedNotation, truncate2SingleStr, truncateHtmlStr,
29
+ after, applyStyle, assignAttrValues, ATTRS, before, checkProp, cleanupHtml, cloneAndDestroy,
30
+ createElementFromHtmlString, datasetKeyProxy, inject2DOMTree, ElemArray2HtmlString, emptyElement,
31
+ escHtml, findParentScrollDistance, HandleFactory, input2Collection, insertPositions, IS, isArrayOfHtmlElements,
32
+ isArrayOfHtmlStrings, isComment, isCommentOrTextNode, isHtmlString, isModal, isNode, isNonEmptyString,
33
+ isText, isVisible, isWritable, listeners, logTime, maybe, pad0, PopupFactory, randomNr, randomString,
34
+ resolveEventTypeParameter, setData, styleFactory, systemLog, tagFNFactory, tagLib, toCamelcase,
35
+ toDashedNotation, truncate2SingleStr, truncateHtmlStr, ucFirst,
31
36
  };
32
37
 
33
- function pad0(nr, n=2) {
34
- return `${nr}`.padStart(n, `0`);
38
+ function checkProp(prop) {
39
+ return prop.startsWith(`data`) || ATTRS.html.find(attr => prop.toLowerCase() === attr);
35
40
  }
36
41
 
37
- function randomNr(max, min = 0) {
38
- [max, min] = [Math.floor(max), Math.ceil(min)];
39
- return Math.floor( ([...crypto.getRandomValues(new Uint32Array(1))].shift() / 2 ** 32 ) * (max - min + 1) + min );
42
+ function emptyElement(el) {
43
+ return el && (el.textContent = "");
44
+ }
45
+
46
+ function findParentScrollDistance(node, distance = 0, top = true) {
47
+ node = node?.parentElement;
48
+ const what = top ? `scrollTop` : `scrollLeft`;
49
+ distance += node ? node[what] : 0;
50
+ return !node ? distance : findParentScrollDistance(node, distance, top);
40
51
  }
41
52
 
42
53
  function isNonEmptyString(str, minlen = 1) {
@@ -44,70 +55,18 @@ function isNonEmptyString(str, minlen = 1) {
44
55
  return IS(str, String) && str.length >= minlen;
45
56
  }
46
57
 
47
- function resolveEventTypeParameter (maybeTypes) {
48
- maybeTypes = IS(maybeTypes, String) && /,/.test(maybeTypes) ? maybeTypes.split(`,`) : maybeTypes;
49
- return IS(maybeTypes, Array)
50
- ? maybeTypes.filter(t => isNonEmptyString(t)).map(t => t.trim().toLowerCase())
51
- : IS(maybeTypes, String) && maybeTypes?.trim().toLowerCase() || ``;
52
- }
53
-
54
- function loop(instance, callback) {
55
- const cleanCollection = instance.collection.filter(el => !isCommentOrTextNode(el));
56
- for (let i = 0; i < cleanCollection.length; i += 1) {
57
- callback(cleanCollection[i], i);
58
- }
59
-
60
- return instance;
61
- }
62
-
63
- function shuffle(array) {
64
- let i = array.length;
65
- while (i--) {
66
- const ri = randomNr(i);
67
- [array[i], array[ri]] = [array[ri], array[i]];
68
- }
69
- return array;
70
- }
71
-
72
- function truncateHtmlStr(str, maxLength = 120) {
73
- return `${str}`
74
- .trim()
75
- .slice(0, maxLength)
76
- .replace(/>\s+</g, `><`)
77
- .replace(/</g, `&lt;`)
78
- .replace(/\s{2,}/g, ` `)
79
- .replace(/\n/g, `\\n`) + (str.length > maxLength ? ` &hellip;` : ``).trim();
80
- }
81
-
82
- function toDashedNotation(str2Convert) {
83
- return str2Convert.replace(/[A-Z]/g, a => `-${a.toLowerCase()}`).replace(/^-|-$/, ``);
84
- }
85
-
86
- function ucFirst([first, ...theRest]) {
87
- return `${first.toUpperCase()}${theRest.join(``)}`;
88
- }
89
-
90
- function toCamelcase(str2Convert) {
91
- return IS(str2Convert, String)
92
- ? str2Convert.toLowerCase()
93
- .split(`-`)
94
- .map( (str, i) => i && `${ucFirst(str)}` || str)
95
- .join(``)
96
- : str2Convert;
97
- }
98
-
99
- function randomString() {
100
- return `_${shuffle(characters4RandomString).slice(0, 8).join(``)}`;
101
- }
102
-
103
58
  function truncate2SingleStr(str, maxLength = 120) {
104
59
  return truncateHtmlStr(str, maxLength).replace(/&lt;/g, `<`);
105
60
  }
106
61
 
107
- function logTime() {
108
- return ((d) =>
109
- `[${pad0(d.getHours())}:${pad0(d.getMinutes())}:${
110
- pad0(d.getSeconds())}.${pad0(d.getMilliseconds(), 3)}]`)(new Date());
62
+ function truncateHtmlStr(str, maxLength = 120) {
63
+ return `${str}`
64
+ .trim()
65
+ .slice(0, maxLength)
66
+ .replace(/>\s+</g, `><`)
67
+ .replace(/</g, `&lt;`)
68
+ .replace(/\s{2,}/g, ` `)
69
+ .replace(/\n/g, `\\n`) + (str.length > maxLength ? ` &hellip;` : ``).trim();
111
70
  }
112
71
 
113
72
  function escHtml(html) {
@@ -120,39 +79,72 @@ function escHtml(html) {
120
79
  }
121
80
  }
122
81
 
123
- function isCommentOrTextNode(node) {
124
- return IS(node, Comment, Text);
125
- }
126
-
127
- function isNode(input) {
128
- return IS(input, Text, HTMLElement, Comment)
129
- }
130
-
131
- function isComment(input) {
132
- IS(input, Comment);
133
- }
134
-
135
- function isText(input) {
136
- return IS(input, Text);
82
+ /* private */
83
+ function decodeForConsole(something) {
84
+ return IS(something, String) &&
85
+ Object.assign(
86
+ document.createElement(`textarea`),
87
+ {innerHTML: something}).textContent || something;
137
88
  }
138
89
 
139
- function isHtmlString(input) {
140
- return IS(input, String) && /^<|>$/.test(`${input}`.trim());
90
+ function systemLogFactory() {
91
+ let on = false;
92
+ const backLog = [];
93
+ const systemLogger = {
94
+ get on() { on = true; return systemLogger; },
95
+ get off() { on = false; return systemLogger; },
96
+ get backLog() { return backLog; },
97
+ };
98
+
99
+ function error(...args) {
100
+ backLog.unshift(...args.map(arg => `${logTime()} ⨻ ${decodeForConsole(arg)}`));
101
+ console.error(backLog.slice(0, args.length).join(`\n`));
102
+ return systemLogger;
103
+ }
104
+
105
+ function log(...args) {
106
+ backLog.unshift(...args.map(arg => `${logTime()} ✔ ${decodeForConsole(arg)}`));
107
+ switch(on) {
108
+ case true: console.log(backLog.slice(0, args.length).join(`\n`));
109
+ default: return systemLogger;
110
+ }
111
+ }
112
+
113
+ Object.defineProperties(systemLogger, {
114
+ log: {value: log, enumerable: false},
115
+ error: {value: error, enumerable: false},
116
+ });
117
+
118
+ return Object.freeze(systemLogger);
141
119
  }
142
120
 
143
- function isArrayOfHtmlElements(input) {
144
- return IS(input, Array) && !input?.find(el => !isNode(el));
121
+ function logTime() {
122
+ return ((d) =>
123
+ `[${pad0(d.getHours())}:${pad0(d.getMinutes())}:${
124
+ pad0(d.getSeconds())}.${pad0(d.getMilliseconds(), 3)}]`)(new Date());
145
125
  }
146
126
 
147
- function isArrayOfHtmlStrings(input) {
148
- return IS(input, Array) && !input?.find(s => !isHtmlString(s));
127
+ function assignAttrValues(el, keyValuePairs) {
128
+ if (el) {
129
+ for (let [key, value] of Object.entries(keyValuePairs)) {
130
+ key = toDashedNotation(key);
131
+ if (key.startsWith(`data`)) {
132
+ return setData(el, value);
133
+ }
134
+
135
+ if (IS(value, String) && checkProp(key)) {
136
+ el.setAttribute(key, value.split(/[, ]/)?.join(` `));
137
+ }
138
+ }
139
+ }
149
140
  }
150
141
 
151
- function ElemArray2HtmlString(elems) {
152
- return elems?.filter(el => el).reduce((acc, el) =>
153
- acc.concat(isComment(el) ? `<!--${el.data}-->`
154
- : isCommentOrTextNode(el) ? el.textContent
155
- : el.outerHTML), ``);
142
+ function setData(el, keyValuePairs) {
143
+ if (el && IS(keyValuePairs, Object)) {
144
+ for (const [key, value] of Object.entries(keyValuePairs)) {
145
+ el.setAttribute(`data-${toDashedNotation(key)}`, value);
146
+ }
147
+ }
156
148
  }
157
149
 
158
150
  function input2Collection(input) {
@@ -164,31 +156,40 @@ function input2Collection(input) {
164
156
  : input.isJQx ? input.collection : undefined;
165
157
  }
166
158
 
167
- function setCollectionFromCssSelector(input, root, self) {
168
- const selectorRoot = root !== document.body && (IS(input, String) && input.toLowerCase() !== "body") ? root : document;
169
- let errorStr = undefined;
159
+ function after(instance, elem2AddAfter) {
160
+ return instance.andThen(elem2AddAfter);
161
+ }
162
+
163
+ function before (instance, elem2AddBefore) {
164
+ return instance.andThen(elem2AddBefore, true);
165
+ }
170
166
 
171
- try { self.collection = [...selectorRoot.querySelectorAll(input)]; }
172
- catch (err) { errorStr = `Invalid CSS querySelector. [${!IS(input, String) ? `Nothing valid given!` : input}]`; }
173
- const collectionLen = self.collection.length;
174
- return collectionLen < 1
175
- ? `CSS querySelector "${input}", output: nothing`
176
- : errorStr ?? `CSS querySelector "${input}", output ${collectionLen} element${collectionLen > 1 ? `s` : ``}`;
167
+ function isNode(input) {
168
+ return IS(input, Text, HTMLElement, Comment)
177
169
  }
178
170
 
179
- function addHandlerId(instance) {
180
- const handleId = instance.data.get(`hid`) || `HID${randomString()}`;
181
- instance.data.add({hid: handleId});
182
- return `[data-hid="${handleId}"]`;
171
+ function applyStyle(el, rules) {
172
+ if (IS(rules, Object)) {
173
+ for (let [key, value] of Object.entries(rules)) {
174
+ let priority;
175
+ if (/!important/i.test(value)) {
176
+ value = value.slice(0, value.indexOf(`!`)).trim();
177
+ priority = 'important';
178
+ }
179
+
180
+ el.style.setProperty(toDashedNotation(key), value, priority)
181
+ }
182
+ }
183
183
  }
184
184
 
185
- function selectedFactoryHelpers() {
186
- return {
187
- isCommentOrTextNode, isNode, isComment, isText, isHtmlString, isArrayOfHtmlElements,
188
- isArrayOfHtmlStrings, ElemArray2HtmlString, input2Collection, setCollectionFromCssSelector,
189
- addHandlerId, cssRuleEdit: styleFactory({createWithId: `JQxStylesheet`}) };
185
+ function cloneAndDestroy(elem) {
186
+ const cloned = elem.cloneNode(true)
187
+ cloned.removeAttribute && cloned.removeAttribute(`id`);
188
+ elem.isConnected ? elem.remove() : elem = null;
189
+ return cloned;
190
190
  }
191
191
 
192
+
192
193
  function isVisible(el) {
193
194
  if (!el) { return undefined; }
194
195
  const elStyle = el.style;
@@ -205,169 +206,85 @@ function isWritable(elem) {
205
206
  return [...elem.parentNode.querySelectorAll(`:is(:read-write)`)]?.find(el => el === elem) ?? false;
206
207
  }
207
208
 
208
- function isModal(elem) {
209
- return [...elem.parentNode.querySelectorAll(`:is(:modal)`)]?.find(el => el === elem) ?? false;
209
+ function ElemArray2HtmlString(elems) {
210
+ return elems?.filter(el => el).reduce((acc, el) =>
211
+ acc.concat(isComment(el) ? `<!--${el.data}-->`
212
+ : isCommentOrTextNode(el) ? el.textContent
213
+ : el.outerHTML), ``);
210
214
  }
211
215
 
212
- function ExamineElementFeatureFactory() {
213
- const notApplicable = `n/a`;
214
- const noElements = Object.freeze({
215
- notInDOM: true, writable: notApplicable, modal: notApplicable, empty: true,
216
- open: notApplicable, visible: notApplicable, });
217
-
218
- return self => {
219
- const firstElem = self.node;
220
-
221
- return IS(firstElem, Node)
222
- ? Object.freeze({
223
- get writable() {
224
- return isWritable(firstElem);
225
- },
226
- get modal() {
227
- return isModal(firstElem);
228
- },
229
- get inDOM() {
230
- return firstElem.isConnected;
231
- },
232
- get open() {
233
- return firstElem.open ?? false;
234
- },
235
- get visible() {
236
- return isVisible(firstElem);
237
- },
238
- get disabled() {
239
- return firstElem.hasAttribute("readonly") || firstElem.hasAttribute("disabled");
240
- },
241
- get empty() {
242
- return self.collection.length < 1;
243
- },
244
- get virtual() {
245
- return self.isVirtual;
246
- }
247
- })
248
- : noElements;
249
- };
216
+ /* private */
217
+ function pad0(nr, n=2) {
218
+ return `${nr}`.padStart(n, `0`);
250
219
  }
251
220
 
252
- function decodeForConsole(something) {
253
- return IS(something, String) &&
254
- Object.assign(
255
- document.createElement(`textarea`),
256
- {innerHTML: something}).textContent || something;
221
+ function randomNr(max, min = 0) {
222
+ [max, min] = [Math.floor(max), Math.ceil(min)];
223
+ return Math.floor( ([...crypto.getRandomValues(new Uint32Array(1))].shift() / 2 ** 32 ) * (max - min + 1) + min );
257
224
  }
258
225
 
259
- function systemLogFactory() {
260
- let on = false;
261
- const backLog = [];
262
- const systemLogger = {
263
- get on() { on = true; return systemLogger; },
264
- get off() { on = false; return systemLogger; },
265
- get backLog() { return backLog; },
266
- };
267
-
268
- function error(...args) {
269
- backLog.unshift(...args.map(arg => `${logTime()} ⨻ ${decodeForConsole(arg)}`));
270
- console.error(backLog.slice(0, args.length).join(`\n`));
271
- return systemLogger;
272
- }
273
-
274
- function log(...args) {
275
- backLog.unshift(...args.map(arg => `${logTime()} ✔ ${decodeForConsole(arg)}`));
276
- switch(on) {
277
- case true: console.log(backLog.slice(0, args.length).join(`\n`));
278
- default: return systemLogger;
279
- }
280
- }
281
-
282
- Object.defineProperties(systemLogger, {
283
- log: {value: log, enumerable: false},
284
- error: {value: error, enumerable: false},
285
- });
226
+ function randomString() {
227
+ return `_${shuffle(characters4RandomString).slice(0, 8).join(``)}`;
228
+ }
286
229
 
287
- return Object.freeze(systemLogger);
230
+ function resolveEventTypeParameter (maybeTypes) {
231
+ maybeTypes = IS(maybeTypes, String) && /,/.test(maybeTypes) ? maybeTypes.split(`,`) : maybeTypes;
232
+ return IS(maybeTypes, Array)
233
+ ? maybeTypes.filter(t => isNonEmptyString(t)).map(t => t.trim().toLowerCase())
234
+ : IS(maybeTypes, String) && maybeTypes?.trim().toLowerCase() || ``;
288
235
  }
289
236
 
290
- function cloneAndDestroy(elem) {
291
- const cloned = elem.cloneNode(true)
292
- cloned.removeAttribute && cloned.removeAttribute(`id`);
293
- elem.isConnected ? elem.remove() : elem = null;
294
- return cloned;
237
+ function isModal(elem) {
238
+ return [...elem.parentNode.querySelectorAll(`:is(:modal)`)]?.find(el => el === elem) ?? false;
295
239
  }
296
240
 
297
- function setData(el, keyValuePairs) {
298
- if (el && IS(keyValuePairs, Object)) {
299
- for (const [key, value] of Object.entries(keyValuePairs)) {
300
- el.setAttribute(`data-${toDashedNotation(key)}`, value);
301
- }
241
+ /* private */
242
+ function shuffle(array) {
243
+ let i = array.length;
244
+ while (i--) {
245
+ const ri = randomNr(i);
246
+ [array[i], array[ri]] = [array[ri], array[i]];
302
247
  }
248
+ return array;
303
249
  }
304
250
 
305
- function before (instance, elem2AddBefore) {
306
- return instance.andThen(elem2AddBefore, true);
251
+ function toCamelcase(str2Convert) {
252
+ return IS(str2Convert, String)
253
+ ? str2Convert.toLowerCase()
254
+ .split(`-`)
255
+ .map( (str, i) => i && `${ucFirst(str)}` || str)
256
+ .join(``)
257
+ : str2Convert;
307
258
  }
308
259
 
309
- function after(instance, elem2AddAfter) {
310
- return instance.andThen(elem2AddAfter);
260
+ function toDashedNotation(str2Convert) {
261
+ return str2Convert.replace(/[A-Z]/g, a => `-${a.toLowerCase()}`).replace(/^-|-$/, ``);
311
262
  }
312
263
 
313
- function findParentScrollDistance(node, distance = 0, top = true) {
314
- node = node?.parentElement;
315
- const what = top ? `scrollTop` : `scrollLeft`;
316
- distance += node ? node[what] : 0;
317
- return !node ? distance : findParentScrollDistance(node, distance, top);
264
+ function ucFirst([first, ...theRest]) {
265
+ return `${first.toUpperCase()}${theRest.join(``)}`;
318
266
  }
319
267
 
320
- function emptyElement(el) {
321
- return el && (el.textContent = "");
268
+ function isCommentOrTextNode(node) {
269
+ return IS(node, Comment, Text);
322
270
  }
323
271
 
324
- function checkProp(prop) {
325
- return prop.startsWith(`data`) || ATTRS.html.find(attr => prop.toLowerCase() === attr);
272
+ function isComment(input) {
273
+ IS(input, Comment);
326
274
  }
327
275
 
328
- function css(el, keyOrKvPairs, value, jqx) {
329
- if (value && IS(keyOrKvPairs, String)) {
330
- keyOrKvPairs = {[keyOrKvPairs]: value === "-" ? "" : value};
331
- }
332
-
333
- let nwClass = undefined;
334
-
335
- if (keyOrKvPairs.className) {
336
- nwClass = keyOrKvPairs.className;
337
- delete keyOrKvPairs.className;
338
- }
339
-
340
- const classExists = ([...el.classList].find(c => c.startsWith(`JQxClass-`) || nwClass && c === nwClass));
341
- nwClass = classExists || nwClass || `JQxClass-${randomString().slice(1)}`;
342
- jqx.editCssRule(`.${nwClass}`, keyOrKvPairs);
343
- el.classList.add(nwClass);
276
+ function isText(input) {
277
+ return IS(input, Text);
344
278
  }
345
279
 
346
- function assignAttrValues(/*NODOC*/el, keyValuePairs) {
347
- if (el) {
348
- for (let [key, value] of Object.entries(keyValuePairs)) {
349
- key = toDashedNotation(key);
350
- if (key.startsWith(`data`)) {
351
- return setData(el, value);
352
- }
353
-
354
- if (IS(value, String) && checkProp(key)) {
355
- el.setAttribute(key, value.split(/[, ]/)?.join(` `));
356
- }
357
- }
358
- }
280
+ function isHtmlString(input) {
281
+ return IS(input, String) && /^<|>$/.test(`${input}`.trim());
359
282
  }
360
283
 
361
- function applyStyle(el, rules) {
362
- if (IS(rules, Object)) {
363
- for (let [key, value] of Object.entries(rules)) {
364
- let priority;
365
- if (/!important/i.test(value)) {
366
- value = value.slice(0, value.indexOf(`!`)).trim();
367
- priority = 'important';
368
- }
284
+ function isArrayOfHtmlElements(input) {
285
+ return IS(input, Array) && !input?.find(el => !isNode(el));
286
+ }
369
287
 
370
- el.style.setProperty(toDashedNotation(key), value, priority)
371
- }
372
- }
288
+ function isArrayOfHtmlStrings(input) {
289
+ return IS(input, Array) && !input?.find(s => !isHtmlString(s));
373
290
  }
@@ -1,9 +1,8 @@
1
1
  // JQx adapted from https://github.com/KooiInc/tinyDOM
2
2
  import { IS, maybe } from "./Utilities.js";
3
- const defaultTinyDOM = tinyDOM();
4
3
  const converts = { html: `innerHTML`, text: `textContent`, class: `className` };
5
4
 
6
- export default defaultTinyDOM;
5
+ export default tinyDOM();
7
6
 
8
7
  function tinyDOM() {
9
8
  const tinyDOMProxyGetter = { get(obj, key) {
package/index.js CHANGED
@@ -2,82 +2,5 @@
2
2
  This code is classfree object oriented. No this. No prototype. No class.
3
3
  Inspired by Douglas Crockford (see https://youtu.be/XFTOG895C7c?t=2562)
4
4
  */
5
-
6
- import { proxify, addJQxStaticMethods } from "./src/JQxFactory.js";
7
- import { inject2DOMTree, createElementFromHtmlString } from "./src/DOM.js";
8
- import {
9
- isHtmlString, truncateHtmlStr, isArrayOfHtmlStrings, isArrayOfHtmlElements,
10
- ElemArray2HtmlString, input2Collection, setCollectionFromCssSelector,
11
- IS, systemLog, insertPositions } from "./src/Utilities.js";
12
-
13
- export default addJQxStaticMethods(JQxFactory());
14
-
15
- function JQxFactory() {
16
- const logLineLength = 70;
17
-
18
- return function JQx(input, root, position = insertPositions.BeforeEnd) {
19
- if (input?.isJQx) { return input; }
20
- const isVirtual = IS(root, HTMLBRElement);
21
- root = (!isVirtual && root && root.isJQx ? root[0] : root) || document.body;
22
- position = position && Object.values(insertPositions).find(pos => position === pos) ? position : undefined;
23
- const isRawHtml = isHtmlString(input);
24
- const isRawHtmlArray = !isRawHtml && isArrayOfHtmlStrings(input);
25
- const shouldCreateElements = isRawHtmlArray || isRawHtml;
26
-
27
- let instance = {
28
- collection: input2Collection(input) ?? [],
29
- isVirtual,
30
- isJQx: true,
31
- };
32
-
33
- const isRawElemCollection = isArrayOfHtmlElements(instance.collection);
34
-
35
- const logStr = `JQx: input =&gt; ${
36
- isRawHtmlArray
37
- ? `"${truncateHtmlStr(input.join(`, `), logLineLength)}"`
38
- : !shouldCreateElements && isRawElemCollection ? `element collection [${
39
- truncateHtmlStr( instance.collection.map(el => `${
40
- IS(el, Comment, Text) ? `Comment|Text @` : ``} ${
41
- el?.outerHTML || el?.textContent}`).join(`, `), logLineLength)}]`
42
- : `"${truncateHtmlStr(input, logLineLength)}"`}`;
43
-
44
- if (instance.collection.length && isRawElemCollection) {
45
- systemLog.log(logStr);
46
-
47
- if (!isVirtual) {
48
- instance.collection.forEach(el => {
49
- if (!root.contains(el)) {
50
- inject2DOMTree([el], root, position);
51
- }
52
- });
53
- }
54
-
55
- return proxify(instance);
56
- }
57
-
58
- if (shouldCreateElements) {
59
- [input].flat().forEach(htmlStringOrComment =>
60
- instance.collection.push(createElementFromHtmlString(htmlStringOrComment)));
61
-
62
- if (instance.collection.length > 0) {
63
- const errors = instance.collection.filter( el => el?.dataset?.jqxcreationerror );
64
- instance.collection = instance.collection.filter(el => !el?.dataset?.jqxcreationerror);
65
-
66
- systemLog.log(`${logStr}`);
67
- systemLog.log(`JQx: created ${instance.isVirtual ? `VIRTUAL ` : ``}[${
68
- truncateHtmlStr(ElemArray2HtmlString(instance.collection).trim() ||
69
- "sanitized: no elements remaining", logLineLength)}]`);
70
-
71
- if (!instance.isVirtual) {
72
- inject2DOMTree(instance.collection, root, position);
73
- }
74
- }
75
-
76
- return proxify(instance);
77
- }
78
-
79
- const forLog = setCollectionFromCssSelector(input, root, instance);
80
- systemLog.log(`JQx: input => ${forLog}`);
81
- return proxify(instance);
82
- }
83
- }
5
+ import JQx from "./src/JQxConstructorFactory.js";
6
+ export default JQx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jqx-es",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "JQuery alike with a few twists",