jqx-es 1.2.8 → 1.3.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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  randomString, toDashedNotation, IS, tagFNFactory as $T, styleFactory, toCamelcase, systemLog,
3
3
  escHtml, isNonEmptyString, resolveEventTypeParameter, selectedFactoryHelpers, insertPositions,
4
- cleanupHtml, PopupFactory, tagLib, listeners, HandleFactory,
4
+ cleanupHtml, PopupFactory, tagLib, HandlerFactory, getHandlerName,
5
5
  } from "./JQxUtilities.js";
6
6
  import allMethodsFactory from "./JQxInstanceMethods.js";
7
7
 
@@ -156,39 +156,48 @@ function delegateFactory(listen) {
156
156
  }
157
157
  }
158
158
 
159
- function delegateCaptureFactory(listen) {
159
+ /* region __WIP */
160
+ function delegateCaptureFactory(handlerWrapper) {
160
161
  return function(spec) {
161
- let {type, origin, selector, handlers, name, capture, once, canRemove} = spec;
162
+ let {type, types, origin, selector, handler, handlers, node, name, capture, once, about} = spec;
163
+ // <legacy>
164
+ handler = handlers || handler;
165
+ type = types || type;
166
+ selector = origin || selector;
167
+ // </legacy>
162
168
  const typesResolved = resolveEventTypeParameter(type);
163
169
  const specifiedName = name;
164
- handlers = IS(handlers, Function) ? [handlers] : handlers;
165
- canRemove = IS(canRemove, Boolean) ? canRemove : false;
170
+ handler = IS(handler, Function) ? [handler] : handler;
166
171
  const params = {
167
- eventType: typesResolved, selector: selector || origin, capture,
168
- name: specifiedName, once, canRemove };
169
-
172
+ type: typesResolved, selector: selector || origin, capture,
173
+ name: specifiedName, once, node, about };
174
+
170
175
  switch(true) {
171
176
  case IS(typesResolved, Array) && typesResolved.length > 0:
172
177
  for (const type of typesResolved) {
173
- params.eventType = type;
174
- assignListeners(handlers, params, listen);
178
+ params.type = type;
179
+ assignListeners(handler, params, handlerWrapper);
175
180
  }
176
181
  break;
177
- default: return assignListeners(handlers, params, listen);
182
+ default: return assignListeners(handler, params, handlerWrapper);
178
183
  }
179
184
  }
180
185
  }
181
186
 
182
- function assignListeners(handlers, params, listen) {
183
- for (const handler of handlers) {
184
- listen({...params, callback: handler});
187
+ function assignListeners(handlerFns, params, handlerWrapper) {
188
+ for (const handler of handlerFns) {
189
+ params.name = getHandlerName(params.name || handler.name);
190
+ handlerWrapper.listen({...params, handler});
185
191
  }
186
192
  }
193
+ /* endregion __WIP */
187
194
 
188
- function getNamedListener(type, name) {
189
- name = isNonEmptyString(name) && name;
190
- type = isNonEmptyString(type) && type;
191
- return name && type && [...listeners[type].values()].find(h => (h.name || ``) === name);
195
+ function getNamedListenerFactory(jqx) {
196
+ return function(type, name) {
197
+ name = isNonEmptyString(name) && name;
198
+ type = isNonEmptyString(type) && type;
199
+ return name && type && jqx.listenerStore[type][name];
200
+ };
192
201
  }
193
202
 
194
203
  function popupGetter(jqx) {
@@ -207,19 +216,21 @@ function getSelectedStaticMethods(jqx) {
207
216
  const createStyle = id => styleFactory({createWithId: id || `jqx${randomString()}`});
208
217
  const editCssRules = (...rules) => { for (const rule of rules) { cssRuleEdit(rule); } };
209
218
  const allowProhibit = allowances(jqx);
210
- const handle = HandleFactory(jqx);
211
- const capturedHandling = delegateCaptureFactory(handle);
219
+ const handlerWrapper = HandlerFactory(jqx);
220
+ const capturedHandling = delegateCaptureFactory(handlerWrapper);
212
221
  const log = (...line) => systemLog.on.log(...line).off;
213
- return {editCssRule, createStyle, editCssRules, allowProhibit, handle, capturedHandling,log};
222
+ return {
223
+ editCssRule, createStyle, editCssRules, allowProhibit, handle: capturedHandling, capturedHandling,
224
+ log, handlerWrapper};
214
225
  }
215
226
 
216
227
  function staticMethodsFactory(jqx) {
217
228
  const { factoryExtensions, instanceExtensions } = allMethodsFactory(jqx);
218
229
  instanceGetters = factoryExtensions;
219
230
  instanceMethods = instanceExtensions;
220
- const { editCssRule, createStyle, editCssRules, allowProhibit, handle, capturedHandling, log } =
231
+ const { editCssRule, createStyle, editCssRules, allowProhibit, handle, capturedHandling, log, handlerWrapper } =
221
232
  getSelectedStaticMethods(jqx);
222
-
233
+ const getNamedListener = getNamedListenerFactory(jqx);
223
234
  return {
224
235
  log,
225
236
  editCssRules,
@@ -240,11 +251,13 @@ function staticMethodsFactory(jqx) {
240
251
  get delegate() { return delegateFactory(capturedHandling); },
241
252
  get delegateCaptured() { return capturedHandling; } ,
242
253
  get handle() { return capturedHandling; },
254
+ get listen() { return handlerWrapper.listen; },
243
255
  get at() { return insertPositions; },
244
256
  get setStyle() { /*deprecated*/return editCssRule; },
245
257
  get fn() { return addFn; },
246
258
  get lenient() { return tagLib.allowUnknownHtmlTags; },
247
259
  get IS() { return IS; },
248
260
  get Popup() { return popupGetter(jqx); },
261
+ get listenerStore() { return handlerWrapper.ListenerStore; },
249
262
  };
250
263
  }
@@ -305,13 +305,20 @@ function instanceExtensionsFactory(jqx) {
305
305
  nth$: (instance, indexOrSelector) => instance.single(indexOrSelector),
306
306
  on: (instance, type, ...callback) => {
307
307
  if (instance.collection.length && IS(type, String, Array)) {
308
- if (type?.length < 1 || callback.length < 1) { return instance; }
309
- const cssSelector4Handler = addHandlerId(instance);
310
- jqx.handle({type, selector: cssSelector4Handler, handlers: callback});
308
+ if (!isNonEmptyString(type) || callback.length < 1) { return instance; }
309
+ jqx.handle({type, node: instance.node, handlers: callback});
311
310
  }
312
311
 
313
312
  return instance;
314
313
  },
314
+ once: (instance, type, ...callback) => {
315
+ if (instance.collection.length && IS(type, String, Array)) {
316
+ if (!isNonEmptyString(type) || callback.length < 1) { return instance; }
317
+ jqx.handle({type, once: true, node: instance.node, handlers: callback});
318
+ }
319
+
320
+ return instance;
321
+ },
315
322
  prepend: (instance, ...elems2Prepend) => {
316
323
  if (!instance.is.empty && elems2Prepend) {
317
324
  const shouldMove = instance.length === 1;
@@ -5,7 +5,7 @@ import {
5
5
  isNode, isNonEmptyString, isText, isVisible, isWritable, logTime, maybe, randomNr, randomString,
6
6
  resolveEventTypeParameter, setData, styleFactory, systemLog, tagFNFactory, toCamelcase, toDashedNotation,
7
7
  truncate2SingleStr, truncateHtmlStr, createElementFromHtmlString, inject2DOMTree, cleanupHtml,
8
- PopupFactory, tagLib, listeners, HandleFactory,
8
+ PopupFactory, tagLib, HandlerFactory, getHandlerName,
9
9
  } from "../Resource/Common/Utilities.js"
10
10
 
11
11
  export {
@@ -15,7 +15,7 @@ export {
15
15
  isHtmlString, isNode, isNonEmptyString, logTime, loop, maybe, randomNr, randomString, resolveEventTypeParameter,
16
16
  selectedFactoryHelpers, setCollectionFromCssSelector, setData, styleFactory, systemLog, tagFNFactory,
17
17
  toCamelcase, toDashedNotation, truncate2SingleStr, truncateHtmlStr, createElementFromHtmlString, inject2DOMTree,
18
- cleanupHtml, PopupFactory, tagLib, HandleFactory, listeners
18
+ cleanupHtml, PopupFactory, tagLib, HandlerFactory, getHandlerName,
19
19
  };
20
20
 
21
21
  function loop(instance, callback) {
@@ -40,7 +40,7 @@ function setCollectionFromCssSelector(input, root, self) {
40
40
  }
41
41
 
42
42
  function addHandlerId(instance) {
43
- const handleId = instance.data.get(`hid`) || `HID${randomString()}`;
43
+ const handleId = `anonymous_${Math.random().toString(36).slice(2)}`;
44
44
  instance.data.add({hid: handleId});
45
45
  return `[data-hid="${handleId}"]`;
46
46
  }