jqx-es 1.1.9 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/DOMCleanup.js CHANGED
@@ -1,7 +1,6 @@
1
- import { truncate2SingleStr, IS } from "./JQxExtensionHelpers.js";
1
+ import { truncate2SingleStr, IS, debugLog } from "./JQxExtensionHelpers.js";
2
2
  import cleanupTagInfo from "./HTMLTags.js";
3
3
  import {ATTRS} from "./EmbedResources.js";
4
- import {debugLog} from "./JQxLog.js";
5
4
  import {escHtml} from "./Utilities.js";
6
5
 
7
6
  let logElementCreationErrors2Console = true;
@@ -31,7 +30,7 @@ const cleanupHtml = el2Clean => {
31
30
  rawHTML: el2Clean?.parentElement?.getHTML() ?? `no html`,
32
31
  removed: { },
33
32
  }
34
-
33
+
35
34
  if (IS(el2Clean, HTMLElement)) {
36
35
  [...el2Clean.childNodes].forEach(child => {
37
36
  if (child?.children?.length) {
@@ -58,11 +57,11 @@ const cleanupHtml = el2Clean => {
58
57
  }
59
58
  });
60
59
  }
61
-
60
+
62
61
  const allowed = elementCheck(child) ||
63
62
  child.constructor === CharacterData ||
64
63
  child.constructor === Comment;
65
-
64
+
66
65
  if (!allowed) {
67
66
  const tag = (child?.outerHTML || child?.textContent).trim();
68
67
  let tagValue = truncate2SingleStr(tag, 60) ?? `EMPTY`;
@@ -1,5 +1,5 @@
1
1
  import { createElementFromHtmlString, insertPositions, inject2DOMTree, cleanupHtml } from "./DOM.js";
2
- import { debugLog, Log, systemLog } from "./JQxLog.js";
2
+ import logFactory from "./JQxLog.js";
3
3
  import allMethodsFactory from "./JQxMethods.js";
4
4
  import PopupFactory from "./Popup.js";
5
5
  import { listeners, default as HandleFactory } from "./HandlerFactory.js";
@@ -10,7 +10,7 @@ import {
10
10
  isNonEmptyString, resolveEventTypeParameter,
11
11
  } from "./Utilities.js";
12
12
  let static4Docs = {};
13
- let instanceGetters, instanceMethods, $;
13
+ let instanceGetters, instanceMethods, $, systemLogger, debugLogger;
14
14
 
15
15
  const {
16
16
  isCommentOrTextNode, isNode,
@@ -147,14 +147,12 @@ function virtualFactory(jqx) {
147
147
 
148
148
  function combineObjectSources(...sources) {
149
149
  const result = {};
150
-
151
150
  for (const source of sources) {
152
151
  const descriptors = Object.getOwnPropertyDescriptors(source);
153
152
  for (const [key, descriptor] of Object.entries(descriptors)) {
154
153
  !(key in result) && Object.defineProperty(result, key, descriptor);
155
154
  }
156
155
  }
157
-
158
156
  return result;
159
157
  }
160
158
 
@@ -165,7 +163,6 @@ function tagNotAllowed(tagName) {
165
163
 
166
164
  function tagGetterFactory(tagName, cando, jqx, webComponentTagName) {
167
165
  tagName = toDashedNotation(webComponentTagName || tagName.toLowerCase());
168
-
169
166
  return {
170
167
  get() {
171
168
  return (...args) => {
@@ -181,7 +178,6 @@ function tagGetterFactory(tagName, cando, jqx, webComponentTagName) {
181
178
  function addGetters(tag, cando, jqx, webComponentTagName) {
182
179
  tag = tag.toLowerCase();
183
180
  const jqxGetterForThisTag = tagGetterFactory(tag, cando, jqx, webComponentTagName);
184
-
185
181
  return webComponentTagName
186
182
  ? { [webComponentTagName]: jqxGetterForThisTag, [toCamelcase(webComponentTagName)]: jqxGetterForThisTag, }
187
183
  : { [tag]: jqxGetterForThisTag, [tag.toUpperCase()]: jqxGetterForThisTag, };
@@ -222,10 +218,6 @@ function delegateCaptureFactory(listen) {
222
218
  canRemove = IS(canRemove, Boolean) ? canRemove : false;
223
219
  const params = { eventType: typesResolved, selector: selector || origin, capture,
224
220
  name: specifiedName, once, canRemove};
225
- const doHandle = handler => {
226
- params.name = specifiedName;
227
- IS(handler, Function) && listen({...params, callback: handler});
228
- }
229
221
  switch(true) {
230
222
  case IS(typesResolved, Array) && typesResolved.length > 0:
231
223
  for (const type of typesResolved) {
@@ -233,8 +225,12 @@ function delegateCaptureFactory(listen) {
233
225
  for (const handler of handlers) { doHandle(handler); }
234
226
  }
235
227
  return;
236
- default:
237
- for (const handler of handlers) { doHandle(handler); }
228
+ default: for (const handler of handlers) { doHandle(handler); }
229
+ }
230
+
231
+ function doHandle(handler) {
232
+ params.name = specifiedName;
233
+ IS(handler, Function) && listen({...params, callback: handler});
238
234
  }
239
235
  }
240
236
  }
@@ -247,55 +243,58 @@ function getNamedListener(type, name) {
247
243
  }
248
244
  }
249
245
 
246
+ function popupGetter(jqx) {
247
+ if (!jqx.activePopup) {
248
+ Object.defineProperty(
249
+ jqx, `activePopup`, {
250
+ value: PopupFactory(jqx),
251
+ enumerable: false
252
+ } );
253
+ }
254
+ return jqx.activePopup;
255
+ }
256
+
250
257
  function staticMethodsFactory(jqx) {
251
- $ = jqx;
258
+ const { debugLog, Log, systemLog } = logFactory(jqx);
252
259
  const { factoryExtensions, instanceExtensions } = allMethodsFactory(jqx);
260
+ systemLogger = systemLog;
261
+ debugLogger = debugLog;
253
262
  instanceGetters = factoryExtensions;
254
263
  instanceMethods = instanceExtensions;
264
+ $ = jqx;
255
265
  const editCssRule = (ruleOrSelector, ruleObject) => cssRuleEdit(ruleOrSelector, ruleObject);
256
266
  const allowProhibit = allowances(jqx);
257
267
  const handle = HandleFactory(jqx);
258
268
  const capturedHandling = delegateCaptureFactory(handle);
269
+
259
270
  return {
260
- debugLog,
261
- log: (...args) => Log(`fromStatic`, ...args),
262
- insertPositions,
271
+ log(...args) { Log(`fromStatic`, ...args); },
272
+ editCssRules(...rules) { for (const rule of rules) { cssRuleEdit(rule); } },
273
+ createStyle(id) { return styleFactory({createWithId: id || `jqx${randomString()}`}); },
274
+ editStylesheet(id) { return styleFactory({createWithId: id || `jqx${randomString()}`}); },
275
+ text(str, isComment = false) { return isComment ? jqx.comment(str) : document.createTextNode(str); },
276
+ node(selector, root = document) { return root.querySelector(selector, root); },
277
+ nodes(selector, root = document) {return [...root.querySelectorAll(selector, root)]; },
278
+ get editCssRule() { return editCssRule; },
279
+ get getNamedListener() { return getNamedListener; },
280
+ get debugLog() { return debugLog },
281
+ get virtual() { return virtualFactory(jqx); },
282
+ get allowTag() { return allowProhibit.allow; },
283
+ get prohibitTag() { return allowProhibit.prohibit; },
284
+ get removeCssRule() { return cssRemove; },
285
+ get removeCssRules() { return cssRemove; },
286
+ get delegate() { return delegateFactory(capturedHandling); },
287
+ get delegateCaptured() { return capturedHandling; } ,
288
+ get handle() { return capturedHandling; },
263
289
  get at() { return insertPositions; },
264
- editCssRules: (...rules) => { for (const rule of rules) { cssRuleEdit(rule); } },
265
- editCssRule,
266
290
  get setStyle() { /*deprecated*/return editCssRule; },
267
- getNamedListener,
268
- delegate: delegateFactory(capturedHandling),
269
- delegateCaptured: capturedHandling,
270
- handle: capturedHandling,
271
- virtual: virtualFactory(jqx),
272
291
  get fn() { return addFn; },
273
- allowTag: allowProhibit.allow,
274
- prohibitTag: allowProhibit.prohibit,
275
292
  get lenient() { return tagLib.allowUnknownHtmlTags; },
276
293
  get IS() { return IS; },
277
- get Popup() {
278
- if (!jqx.activePopup) {
279
- Object.defineProperty(
280
- jqx, `activePopup`, {
281
- value: PopupFactory(jqx),
282
- enumerable: false
283
- } );
284
- }
285
- return jqx.activePopup;
286
- },
287
- popup: () => jqx.Popup,
288
- createStyle: id => styleFactory({createWithId: id || `jqx${randomString()}`}),
289
- editStylesheet: id => styleFactory({createWithId: id || `jqx${randomString()}`}),
290
- removeCssRule: cssRemove,
291
- removeCssRules: cssRemove,
292
- text: (str, isComment = false) => isComment ? jqx.comment(str) : document.createTextNode(str),
293
- node: (selector, root = document) => root.querySelector(selector, root),
294
- nodes: (selector, root = document) => [...root.querySelectorAll(selector, root)],
294
+ get Popup() { return popupGetter(jqx); },
295
295
  };
296
296
  }
297
297
  /* endregion functions */
298
-
299
298
  export {
300
299
  hex2RGBA,
301
300
  addHandlerId,
@@ -317,7 +316,8 @@ export {
317
316
  addJQxStaticMethods,
318
317
  createElementFromHtmlString,
319
318
  insertPositions,
320
- systemLog,
319
+ systemLogger as systemLog,
320
+ debugLogger as debugLog,
321
321
  IS,
322
322
  static4Docs,
323
323
  elems4Docs,
package/src/JQxLog.js CHANGED
@@ -1,143 +1,172 @@
1
1
  import { logTime } from "./Utilities.js";
2
2
  import { createElementFromHtmlString, element2DOM, insertPositions } from "./DOM.js";
3
- import {IS, jqx} from "./JQxExtensionHelpers.js";
4
- import {logStyling} from "./EmbedResources.js";
5
- let logSystem = false;
6
- let useLogging = false;
7
- let log2Console = true;
8
- let reverseLogging = false;
9
- let useHtml = true;
10
- let editLogRule;
11
- const getLogBox = () => jqx(`#logBox`);
12
- const logBoxTextBoxId = `#jqx_logger`;
13
- const setStyling4Log = setStyle => { logStyling?.forEach(selector => setStyle(selector)); };
14
-
15
- const createLogElement = () => {
16
- if (logStyling) {
17
- setStyling4Log(editLogRule);
18
- }
19
- const jqx_logger_element_name = useHtml ? `div` : `pre`;
20
- const loggingFieldSet = `<div id="logBox"><div class="legend"><div></div></div><${
21
- jqx_logger_element_name} id="jqx_logger"></${jqx_logger_element_name}></div>`;
22
- element2DOM(createElementFromHtmlString(loggingFieldSet), undefined, insertPositions.AfterBegin);
23
- return jqx.node(logBoxTextBoxId);
24
- };
3
+ import { logStyling } from "./EmbedResources.js";
4
+
5
+ function logFactory(jqx) {
6
+ let logSystem = false;
7
+ let useLogging = false;
8
+ let log2Console = true;
9
+ let reverseLogging = false;
10
+ let useHtml = true;
11
+ let editLogRules;
12
+ const getLogBox = () => jqx(`#logBox`);
13
+ const logBoxTextBoxId = `#jqx_logger`;
14
+ const setStyling4Log = setStyle => {
15
+ logStyling?.forEach(selector => setStyle(selector));
16
+ };
25
17
 
26
- const decodeForConsole = something => IS(something, String) &&
27
- Object.assign(document.createElement(`textarea`), {innerHTML: something}).textContent || something;
18
+ const decodeForConsole = something => jqx.IS(something, String) &&
19
+ Object.assign(document.createElement(`textarea`), {innerHTML: something}).textContent || something;
20
+
21
+ function createLogElement(jqx) {
22
+ // note: jqx is not fully proxified here ...
23
+ const jqx_logger_element_name = useHtml ? `div` : `pre`;
24
+ const loggingFieldSet = `
25
+ <div id="logBox">
26
+ <div class="legend">
27
+ <div><!--legend text--></div>
28
+ </div>
29
+ <${jqx_logger_element_name} id="jqx_logger"></${jqx_logger_element_name}>`;
30
+ const logBoxElement = createElementFromHtmlString(loggingFieldSet);
31
+ element2DOM(logBoxElement, undefined, insertPositions.AfterBegin);
32
+ return jqx.node(logBoxTextBoxId);
33
+ }
28
34
 
29
- const Log = (...args) => {
35
+ const Log = (...args) => {
30
36
  const isInstanceLog = args[0] === `fromStatic`;
37
+
38
+ if (!jqx.node(`#JQxLogCSS`)) {
39
+ editLogRules = jqx.editStylesheet(`JQxLogCSS`);
40
+ for (const rule of logStyling) { editLogRules(rule); }
41
+ }
42
+
31
43
  args = isInstanceLog ? args.slice(1) : args;
32
- if ( isInstanceLog && !useLogging) {
44
+
45
+ if (isInstanceLog && !useLogging) {
33
46
  return args.forEach(arg => console.info(`${logTime()} ✔ ${decodeForConsole(arg)}`));
34
47
  }
35
48
 
36
49
  if (!useLogging) { return; }
37
50
 
38
- if (!log2Console && !jqx.node(`#logBox`)) {
39
- editLogRule = jqx.createStyle(`JQxLogCSS`);
40
- createLogElement();
41
- }
51
+ if (!log2Console && !jqx.node(`#logBox`)) { createLogElement(jqx); }
42
52
 
43
- const logLine = arg => `${IS(arg, Object) ? JSON.stringify(arg, null, 2) : arg}\n`;
53
+ const logLine = arg => `${jqx.IS(arg, Object) ? JSON.stringify(arg, null, 2) : arg}\n`;
44
54
 
45
- args.forEach( arg => log2Console
55
+ args.forEach(arg => log2Console
46
56
  ? console.info(`${logTime()} ✔ ${decodeForConsole(arg)}`)
47
57
  : jqx.node(`#jqx_logger`).insertAdjacentHTML(
48
- reverseLogging ? `afterbegin` : `beforeend`,
49
- `<div class="entry">${logTime()} ${logLine(arg.replace(/\n/g, `<br>`))}</div>`)
58
+ reverseLogging ? `afterbegin` : `beforeend`,
59
+ `<div class="entry">${logTime()} ${logLine(arg.replace(/\n/g, `<br>`))}</div>`)
50
60
  );
51
- };
61
+ };
52
62
 
53
- const logActive = {
54
- on() { useLogging = true; Log(`Logging activated`); },
55
- off() { useLogging = false; console.log(`Logging deactivated`) },
56
- }
63
+ const logActive = {
64
+ on() {
65
+ useLogging = true;
66
+ Log(`Logging activated (CSS in style#JQxLogCSS)`);
67
+ },
68
+ off() {
69
+ useLogging = false;
70
+ console.log(`${logTime()} ✔ Logging deactivated`)
71
+ },
72
+ }
57
73
 
58
- const setSystemLog = {
59
- on() { logSystem = true; },
60
- off() { logSystem = false; },
61
- };
62
-
63
- const systemLog = (...logTxt) => logSystem && Log(...logTxt);
64
-
65
- const debugLog = {
66
- get isConsole() { return log2Console === true; },
67
- get isOn() { return useLogging; },
68
- isVisible: function() { return jqx(`#jqx_logger`).is(`visible`); },
69
- on() {
70
- logActive.on();
71
- setSystemLog.on();
72
- if (!log2Console) {
73
- getLogBox()?.addClass(`visible`);
74
- }
75
- Log(`Debug logging started. Every call to [jqx instance] is logged`);
76
- return debugLog;
77
- },
78
- off() {
79
- if (!getLogBox().isEmpty) {
80
- setSystemLog.off();
81
- Log(`Debug logging stopped`);
82
- getLogBox()?.removeClass(`visible`);
83
- }
84
- logActive.off();
85
- return debugLog;
86
- },
87
- toConsole: {
74
+ const setSystemLog = {
75
+ on() {
76
+ logSystem = true;
77
+ },
78
+ off() {
79
+ logSystem = false;
80
+ },
81
+ };
82
+
83
+ const systemLog = (...logTxt) => logSystem && Log(...logTxt);
84
+
85
+ const debugLog = {
86
+ get isConsole() {
87
+ return log2Console === true;
88
+ },
89
+ get isOn() {
90
+ return useLogging;
91
+ },
92
+ isVisible: function () {
93
+ return jqx(`#jqx_logger`).is(`visible`);
94
+ },
88
95
  on() {
89
- log2Console = true;
90
- Log(`Started logging to console`);
96
+ logActive.on();
97
+ setSystemLog.on();
98
+ if (!log2Console) {
99
+ getLogBox()?.addClass(`visible`);
100
+ }
101
+ Log(`Debug logging started. Every call to [jqx instance] is logged`);
91
102
  return debugLog;
92
103
  },
93
104
  off() {
94
- Log(`Stopped logging to console (except error messages)`);
95
- log2Console = false;
105
+ if (!getLogBox().isEmpty) {
106
+ setSystemLog.off();
107
+ Log(`Debug logging stopped`);
108
+ getLogBox()?.removeClass(`visible`);
109
+ }
110
+ logActive.off();
96
111
  return debugLog;
97
- }
98
- },
99
- remove() {
100
- logActive.off();
101
- setSystemLog.off();
102
- getLogBox()?.remove();
103
- console.clear();
104
- console.log(`${logTime()} logging completely disabled and all entries removed`);
105
- return debugLog;
106
- },
107
- log: function(...args) {
108
- Log(...args);
109
- return debugLog;
110
- },
111
- hide() {
112
- getLogBox()?.removeClass(`visible`);
113
- return debugLog;
114
- },
115
- show: () => {
116
- getLogBox()?.addClass(`visible`);
117
- return debugLog;
118
- },
119
- get reversed() {
120
- return {
121
- on: () => {
122
- reverseLogging = true;
123
- Log(`Reverse logging set: now logging bottom to top (latest first)`);
124
- jqx(`#logBox .legend`).addClass(`reversed`);
112
+ },
113
+ toConsole: {
114
+ on() {
115
+ log2Console = true;
116
+ Log(`Started logging to console`);
125
117
  return debugLog;
126
118
  },
127
- off: () => {
128
- reverseLogging = false;
129
- jqx(`#logBox .legend`).removeClass(`reversed`);
130
- Log(`Reverse logging reset: now logging chronological (latest last)`);
119
+ off() {
120
+ Log(`Stopped logging to console (except error messages)`);
121
+ log2Console = false;
131
122
  return debugLog;
132
- },
133
- };
134
- },
135
- clear() {
136
- jqx(logBoxTextBoxId).text(``);
137
- console.clear();
138
- Log(`Logging cleared`);
139
- return debugLog;
140
- }
141
- };
123
+ }
124
+ },
125
+ remove() {
126
+ logActive.off();
127
+ setSystemLog.off();
128
+ getLogBox()?.remove();
129
+ console.clear();
130
+ console.log(`${logTime()} logging completely disabled and all entries removed`);
131
+ return debugLog;
132
+ },
133
+ log: function (...args) {
134
+ Log(...args);
135
+ return debugLog;
136
+ },
137
+ hide() {
138
+ getLogBox()?.removeClass(`visible`);
139
+ return debugLog;
140
+ },
141
+ show: () => {
142
+ getLogBox()?.addClass(`visible`);
143
+ return debugLog;
144
+ },
145
+ get reversed() {
146
+ return {
147
+ on: () => {
148
+ reverseLogging = true;
149
+ Log(`Reverse logging set: now logging bottom to top (latest first)`);
150
+ jqx(`#logBox .legend`).addClass(`reversed`);
151
+ return debugLog;
152
+ },
153
+ off: () => {
154
+ reverseLogging = false;
155
+ jqx(`#logBox .legend`).removeClass(`reversed`);
156
+ Log(`Reverse logging reset: now logging chronological (latest last)`);
157
+ return debugLog;
158
+ },
159
+ };
160
+ },
161
+ clear() {
162
+ jqx(logBoxTextBoxId).text(``);
163
+ console.clear();
164
+ Log(`Logging cleared`);
165
+ return debugLog;
166
+ }
167
+ };
168
+
169
+ return { Log, debugLog, systemLog };
170
+ }
142
171
 
143
- export { Log, debugLog, systemLog };
172
+ export default logFactory;