total5 0.0.1-40 → 0.0.1-41

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 (4) hide show
  1. package/builders.js +8 -6
  2. package/cms.js +127 -41
  3. package/index.js +13 -3
  4. package/package.json +1 -1
package/builders.js CHANGED
@@ -1153,10 +1153,7 @@ exports.newaction = function(name, obj) {
1153
1153
  if (obj.route) {
1154
1154
  if (obj.route.indexOf('-->') === -1)
1155
1155
  obj.route = obj.route + ' ' + (obj.input ? '+' : '-') + obj.$url + ' --> ' + name;
1156
- var flags = null;
1157
- if (obj.encrypt)
1158
- flags = '@encrypt';
1159
- obj.route = F.route(obj.route, flags || []);
1156
+ obj.route = F.route(obj.route + (obj.encrypt ? ' @encrypt' : ''));
1160
1157
  }
1161
1158
 
1162
1159
  if (obj.permissions && typeof(obj.permissions) === 'string')
@@ -1267,6 +1264,9 @@ ActionCaller.prototype.exec = function() {
1267
1264
  } else {
1268
1265
  $.response[$.id] = response;
1269
1266
  meta.response && self.finish && self.finish(response);
1267
+ var key = '@' + $.id;
1268
+ if (F.$events[key])
1269
+ F.emit(key, $, response);
1270
1270
  self.exec();
1271
1271
  }
1272
1272
  };
@@ -1338,8 +1338,10 @@ ActionCaller.prototype.exec = function() {
1338
1338
  ActionCaller.prototype.finish = function(value) {
1339
1339
  var self = this;
1340
1340
  self.finish = null;
1341
- self.options.callback(self.error.length ? self.error : null, value === undefined ? self.$.response : value);
1342
- self.options.callback = null;
1341
+ if (self.options.callback) {
1342
+ self.options.callback(self.error.length ? self.error : null, value === undefined ? self.$.response : value);
1343
+ self.options.callback = null;
1344
+ }
1343
1345
  };
1344
1346
 
1345
1347
  ActionCaller.prototype.cancel = function() {
package/cms.js CHANGED
@@ -271,8 +271,7 @@ function tidy(body) {
271
271
  var arr = text.substring(is ? 8 : 7, text.length - 1).split(' ');
272
272
  var builder = '';
273
273
 
274
- for (var i = 0; i < arr.length; i++) {
275
- var cls = arr[i];
274
+ for (let cls of arr) {
276
275
  if (cls[0] === 'C' && cls[1] === 'M' && cls[2] === 'S' && !SKIP_CLASSES[cls])
277
276
  continue;
278
277
  builder += (builder ? ' ' : '') + cls;
@@ -283,14 +282,101 @@ function tidy(body) {
283
282
  }).replace(/<div\s>/g, '<div>');
284
283
  }
285
284
 
285
+ exports.widgets = function(html) {
286
+
287
+ let arr = html.match(/data-cms=".*?"/g) || EMPTYARRAY;
288
+ let response = [];
289
+ let indexer = 0;
290
+ let index;
291
+ let beg;
292
+ let end;
293
+
294
+ for (let attr of arr) {
295
+
296
+ if (html.indexOf(attr) === -1)
297
+ continue;
298
+
299
+ let w = attr.substring(10);
300
+ index = w.indexOf('__');
301
+ let id = w.substring(0, index);
302
+
303
+ index = html.lastIndexOf('<', html.indexOf(attr));
304
+ beg = '<div';
305
+ end = '</div>';
306
+
307
+ let pos = index + 1;
308
+ let count = 0;
309
+ let counter = 0;
310
+
311
+ while (true) {
312
+
313
+ if (counter++ > 100)
314
+ break;
315
+
316
+ let a = html.indexOf(beg, pos);
317
+ let b = html.indexOf(end, pos);
318
+
319
+ if (a !== -1 && a < b) {
320
+ count++;
321
+ pos = html.indexOf('>', a);
322
+ continue;
323
+ }
324
+
325
+ if (a === -1 || b < a) {
326
+
327
+ pos = b + 6;
328
+
329
+ if (count) {
330
+ count--;
331
+ continue;
332
+ }
333
+
334
+ break;
335
+ }
336
+ }
337
+
338
+ let body = html.substring(index, pos);
339
+ html = html.replace(body, clean(body));
340
+ index = body.indexOf('>');
341
+ body = body.substring(0, index + 1) + '~BEG~' + body.substring(index + 1);
342
+ index = body.lastIndexOf('<');
343
+ body = body.substring(0, index) + '~END~' + body.substring(index);
344
+
345
+ index = w.indexOf('__');
346
+
347
+ let config = decodeURIComponent(w.substring(index + 2, w.length - 1)).parseJSON(true);
348
+ let opt = {};
349
+
350
+ opt.id = id;
351
+ opt.indexer = indexer;
352
+ opt.body = tidy(clean(body));
353
+ opt.html = body.substring(body.lastIndexOf('~BEG~') + 5, body.lastIndexOf('~END~'));
354
+ opt.config = config || EMPTYOBJECT;
355
+ opt.beg = opt.body.substring(0, opt.body.indexOf('>') + 1);
356
+ opt.end = opt.body.substring(opt.body.lastIndexOf('<'));
357
+
358
+ index = opt.beg.indexOf('data-cms-id="');
359
+
360
+ if (index === -1)
361
+ opt.uid = opt.beg.makeid();
362
+ else
363
+ opt.uid = opt.beg.substring(index + 13, opt.beg.indexOf('"', index + 14));
364
+
365
+ response.push(opt);
366
+ indexer++;
367
+ }
368
+
369
+ return response;
370
+ };
371
+
286
372
  exports.compile = function(html, widgets, used) {
287
373
 
288
- var arr = html.match(/data-cms=".*?"/g) || EMPTYARRAY;
289
- var response = new CMSRender();
290
- var indexer = 0;
291
- var index;
292
- var beg;
293
- var end;
374
+ let arr = html.match(/data-cms=".*?"/g) || EMPTYARRAY;
375
+ let response = new CMSRender();
376
+ let indexer = 0;
377
+ let index;
378
+ let beg;
379
+ let end;
294
380
 
295
381
  response.css = [];
296
382
  response.js = [];
@@ -299,7 +385,7 @@ exports.compile = function(html, widgets, used) {
299
385
  response.tangular = [];
300
386
 
301
387
  if (!used) {
302
- for (var widget of widgets) {
388
+ for (let widget of widgets) {
303
389
  if (widget.css)
304
390
  response.css.push(F.TUtils.minify_css(widget.css));
305
391
  if (widget.js)
@@ -311,30 +397,30 @@ exports.compile = function(html, widgets, used) {
311
397
  }
312
398
  }
313
399
 
314
- for (var attr of arr) {
400
+ for (let attr of arr) {
315
401
 
316
402
  if (html.indexOf(attr) === -1)
317
403
  continue;
318
404
 
319
- var w = attr.substring(10);
320
- var index = w.indexOf('__');
321
- var id = w.substring(0, index);
405
+ let w = attr.substring(10);
406
+ index = w.indexOf('__');
407
+ let id = w.substring(0, index);
322
408
 
323
409
  index = html.lastIndexOf('<', html.indexOf(attr));
324
410
  beg = '<div';
325
411
  end = '</div>';
326
412
 
327
- var pos = index + 1;
328
- var count = 0;
329
- var counter = 0;
413
+ let pos = index + 1;
414
+ let count = 0;
415
+ let counter = 0;
330
416
 
331
417
  while (true) {
332
418
 
333
419
  if (counter++ > 100)
334
420
  break;
335
421
 
336
- var a = html.indexOf(beg, pos);
337
- var b = html.indexOf(end, pos);
422
+ let a = html.indexOf(beg, pos);
423
+ let b = html.indexOf(end, pos);
338
424
 
339
425
  if (a !== -1 && a < b) {
340
426
  count++;
@@ -355,8 +441,8 @@ exports.compile = function(html, widgets, used) {
355
441
  }
356
442
  }
357
443
 
358
- var widget = widgets instanceof Array ? widgets.findItem('id', id) : widgets[id];
359
- var body = html.substring(index, pos);
444
+ let widget = widgets instanceof Array ? widgets.findItem('id', id) : widgets[id];
445
+ let body = html.substring(index, pos);
360
446
 
361
447
  // Widget not found
362
448
  if (!widget) {
@@ -391,9 +477,9 @@ exports.compile = function(html, widgets, used) {
391
477
  body = body.substring(0, index) + '~END~' + body.substring(index);
392
478
 
393
479
  index = w.indexOf('__');
394
- var config = decodeURIComponent(w.substring(index + 2, w.length - 1)).parseJSON(true);
395
480
 
396
- var opt = {};
481
+ let config = decodeURIComponent(w.substring(index + 2, w.length - 1)).parseJSON(true);
482
+ let opt = {};
397
483
  opt.id = id;
398
484
  opt.indexer = indexer;
399
485
  opt.body = tidy(clean(body));
@@ -423,17 +509,17 @@ exports.compile = function(html, widgets, used) {
423
509
  if (index === -1)
424
510
  break;
425
511
 
426
- var beg = html.lastIndexOf('<script', index);
427
- var end = html.indexOf('</script>', index);
428
- var endhead = html.indexOf('>', index);
429
- var head = html.substring(beg, endhead);
430
- var name = head.match(/name=".*?"/i)[0];
431
- var template = html.substring(html.indexOf('>', endhead) + 1, end);
512
+ let begindex = html.lastIndexOf('<script', index);
513
+ let endindex = html.indexOf('</script>', index);
514
+ let endhead = html.indexOf('>', index);
515
+ let head = html.substring(begindex, endhead);
516
+ let name = head.match(/name=".*?"/i)[0];
517
+ let template = html.substring(html.indexOf('>', endhead) + 1, endindex);
432
518
 
433
519
  name = name.substring(6, name.length - 1);
434
- html = html.replace(html.substring(beg, end + 9), '~WIDGET#' + response.tangular.length + '~');
520
+ html = html.replace(html.substring(begindex, endindex + 9), '~WIDGET#' + response.tangular.length + '~');
435
521
  response.tangular.push({ id: HASH(name).toString(36), name: name, type: 'nav', template: Tangular.compile(template) });
436
- index = beg;
522
+ index = begindex;
437
523
 
438
524
  }
439
525
 
@@ -446,26 +532,26 @@ exports.compile = function(html, widgets, used) {
446
532
  if (index === -1)
447
533
  break;
448
534
 
449
- var beg = html.lastIndexOf('<script', index);
450
- var end = html.indexOf('</script>', index);
451
- var endhead = html.indexOf('>', index);
452
- var template = html.substring(html.indexOf('>', endhead) + 1, end);
453
- html = html.replace(html.substring(beg, end + 9), '~WIDGET#' + response.tangular.length + '~');
535
+ let begindex = html.lastIndexOf('<script', index);
536
+ let endindex = html.indexOf('</script>', index);
537
+ let endhead = html.indexOf('>', index);
538
+ let template = html.substring(html.indexOf('>', endhead) + 1, endindex);
539
+ html = html.replace(html.substring(begindex, endindex + 9), '~WIDGET#' + response.tangular.length + '~');
454
540
  response.tangular.push({ type: 'breadcrumb', template: Tangular.compile(template) });
455
- index = beg;
541
+ index = begindex;
456
542
  }
457
543
 
458
544
  response.html = tidy(trash(layout(html, '~WIDGETLAYOUT~')));
459
545
  response.multiple = expressions_multiple(response.html);
460
546
 
461
- for (var item of response.multiple)
547
+ for (let item of response.multiple)
462
548
  response.html = response.html.replace(item.html, item.replace);
463
549
 
464
550
  response.expressions = expressions(response.html);
465
551
  response.widgets.reverse();
466
552
 
467
- var builder = [];
468
- var text = [];
553
+ let builder = [];
554
+ let text = [];
469
555
 
470
556
  while (true) {
471
557
 
@@ -473,8 +559,8 @@ exports.compile = function(html, widgets, used) {
473
559
 
474
560
  if (beg !== -1) {
475
561
  end = response.html.indexOf('~', beg + 6) + 1;
476
- var h = response.html.substring(0, beg);
477
- var windex = response.html.substring(beg + 7, end - 1);
562
+ let h = response.html.substring(0, beg);
563
+ let windex = response.html.substring(beg + 7, end - 1);
478
564
  if (windex[0] === '#') {
479
565
  response.html = response.html.substring(end);
480
566
  builder.push('text[{0}]+tangular[{1}]'.format(text.push(h) - 1, windex.substring(1)));
package/index.js CHANGED
@@ -1339,7 +1339,6 @@ F.logger = function(enable) {
1339
1339
  };
1340
1340
  };
1341
1341
 
1342
-
1343
1342
  F.componentator = function(name, components, removeprev = true, attrs = '') {
1344
1343
 
1345
1344
  if (typeof(removeprev) === 'string') {
@@ -1893,19 +1892,30 @@ F.newtransform = function(name, action, id) {
1893
1892
  let obj = {};
1894
1893
  obj.id = id;
1895
1894
  obj.action = action;
1896
-
1895
+ obj.remove = function() {
1896
+ let arr = F.transformations[name];
1897
+ if (arr) {
1898
+ let index = arr.indexOf(obj);
1899
+ if (index !== -1) {
1900
+ arr.splice(index, 1);
1901
+ if (!arr.length)
1902
+ delete F.transformations[name];
1903
+ }
1904
+ }
1905
+ };
1897
1906
  if (F.transformations[name])
1898
1907
  F.transformations[name].push(obj);
1899
1908
  else
1900
1909
  F.transformations[name] = [obj];
1910
+ return obj;
1901
1911
  }
1902
1912
  };
1903
1913
 
1904
1914
  function transform(items, opt, index) {
1905
1915
  var t = items[index];
1906
1916
  if (t) {
1917
+ opt.next = () => transform(items, opt, index + 1);
1907
1918
  t.action(opt, opt.value);
1908
- t.next = () => transform(items, opt, index + 1);
1909
1919
  } else
1910
1920
  opt.$callback(opt.error.items.length ? opt.error : null, opt.value);
1911
1921
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.1-40",
3
+ "version": "0.0.1-41",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {