@websy/websy-designs 1.3.2 → 1.3.3
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/dist/server/routes/v1/shop.js +2 -1
- package/dist/websy-designs-es6.debug.js +52 -6
- package/dist/websy-designs-es6.js +62 -5
- package/dist/websy-designs-es6.min.js +1 -1
- package/dist/websy-designs.debug.js +53 -7
- package/dist/websy-designs.js +63 -6
- package/dist/websy-designs.min.js +1 -1
- package/package.json +1 -1
|
@@ -3062,6 +3062,7 @@ class WebsyResultList {
|
|
|
3062
3062
|
this.rows = []
|
|
3063
3063
|
this.apiService = new WebsyDesigns.APIService('/api')
|
|
3064
3064
|
this.templateService = new WebsyDesigns.APIService('')
|
|
3065
|
+
this.activeTemplate = ''
|
|
3065
3066
|
if (!elementId) {
|
|
3066
3067
|
console.log('No element Id provided for Websy Search List')
|
|
3067
3068
|
return
|
|
@@ -3083,16 +3084,17 @@ class WebsyResultList {
|
|
|
3083
3084
|
appendData (d) {
|
|
3084
3085
|
let startIndex = this.rows.length
|
|
3085
3086
|
this.rows = this.rows.concat(d)
|
|
3087
|
+
this.activeTemplate = this.options.template
|
|
3086
3088
|
const html = this.buildHTML(d, startIndex)
|
|
3087
3089
|
const el = document.getElementById(this.elementId)
|
|
3088
3090
|
el.innerHTML += html.replace(/\n/g, '')
|
|
3089
3091
|
}
|
|
3090
|
-
buildHTML (d, startIndex = 0) {
|
|
3092
|
+
buildHTML (d, startIndex = 0, inputTemplate) {
|
|
3091
3093
|
let html = ``
|
|
3092
3094
|
if (this.options.template) {
|
|
3093
3095
|
if (d.length > 0) {
|
|
3094
3096
|
d.forEach((row, ix) => {
|
|
3095
|
-
let template = `${ix > 0 ? '-->' : ''}${this.options.template}${ix < d.length - 1 ? '<!--' : ''}`
|
|
3097
|
+
let template = `${ix > 0 ? '-->' : ''}${inputTemplate || this.options.template}${ix < d.length - 1 ? '<!--' : ''}`
|
|
3096
3098
|
// find conditional elements
|
|
3097
3099
|
let ifMatches = [...template.matchAll(/<\s*if[^>]*>([\s\S]*?)<\s*\/\s*if>/g)]
|
|
3098
3100
|
ifMatches.forEach(m => {
|
|
@@ -3171,16 +3173,39 @@ class WebsyResultList {
|
|
|
3171
3173
|
}
|
|
3172
3174
|
}
|
|
3173
3175
|
})
|
|
3176
|
+
let forMatches = [...template.matchAll(/<\s*for[^>]*>([\s\S]*?)<\s*\/\s*for>/g)]
|
|
3177
|
+
forMatches.forEach(m => {
|
|
3178
|
+
let itemsMatch = m[0].match(/(items=["|']\w.+)["|']/g)
|
|
3179
|
+
let forMarkup = m[0].match(/<\s*for[^>]*>/)
|
|
3180
|
+
let withoutFor = m[0].replace(forMarkup, '').replace('</for>', '').replace(/<\s*for[^>]*>/g, '')
|
|
3181
|
+
if (itemsMatch && itemsMatch[0]) {
|
|
3182
|
+
let c = itemsMatch[0].trim().replace('items=', '')
|
|
3183
|
+
if (c.split('')[0] === '"') {
|
|
3184
|
+
c = c.replace(/"/g, '')
|
|
3185
|
+
}
|
|
3186
|
+
else if (c.split('')[0] === '\'') {
|
|
3187
|
+
c = c.replace(/'/g, '')
|
|
3188
|
+
}
|
|
3189
|
+
let items = row
|
|
3190
|
+
let parts = c.split('.')
|
|
3191
|
+
parts.forEach(p => {
|
|
3192
|
+
items = items[p]
|
|
3193
|
+
})
|
|
3194
|
+
template = template.replace(m[0], this.buildHTML(items, 0, withoutFor))
|
|
3195
|
+
}
|
|
3196
|
+
})
|
|
3174
3197
|
let tagMatches = [...template.matchAll(/(\sdata-event=["|']\w.+)["|']/g)]
|
|
3175
3198
|
tagMatches.forEach(m => {
|
|
3176
3199
|
if (m[0] && m.index > -1) {
|
|
3177
3200
|
template = template.replace(m[0], `${m[0]} data-id=${startIndex + ix}`)
|
|
3178
3201
|
}
|
|
3179
|
-
})
|
|
3180
|
-
|
|
3202
|
+
})
|
|
3203
|
+
let flatRow = this.flattenObject(row)
|
|
3204
|
+
for (let key in flatRow) {
|
|
3181
3205
|
let rg = new RegExp(`{${key}}`, 'gm')
|
|
3182
|
-
template = template.replace(rg,
|
|
3206
|
+
template = template.replace(rg, flatRow[key] || '')
|
|
3183
3207
|
}
|
|
3208
|
+
template = template.replace(/\{(.*?)\}/g, '')
|
|
3184
3209
|
html += template
|
|
3185
3210
|
})
|
|
3186
3211
|
}
|
|
@@ -3205,6 +3230,27 @@ class WebsyResultList {
|
|
|
3205
3230
|
}
|
|
3206
3231
|
return null
|
|
3207
3232
|
}
|
|
3233
|
+
flattenObject (obj) {
|
|
3234
|
+
const toReturn = {}
|
|
3235
|
+
for (const i in obj) {
|
|
3236
|
+
if (!obj.hasOwnProperty(i)) {
|
|
3237
|
+
continue
|
|
3238
|
+
}
|
|
3239
|
+
if (typeof obj[i] === 'object') {
|
|
3240
|
+
const flatObject = this.flattenObject(obj[i])
|
|
3241
|
+
for (const x in flatObject) {
|
|
3242
|
+
if (!flatObject.hasOwnProperty(x)) {
|
|
3243
|
+
continue
|
|
3244
|
+
}
|
|
3245
|
+
toReturn[i + '.' + x] = flatObject[x]
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
else {
|
|
3249
|
+
toReturn[i] = obj[i]
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
return JSON.parse(JSON.stringify(toReturn))
|
|
3253
|
+
}
|
|
3208
3254
|
handleClick (event) {
|
|
3209
3255
|
if (event.target.classList.contains('clickable')) {
|
|
3210
3256
|
let l = event.target.getAttribute('data-event')
|
|
@@ -3290,7 +3336,7 @@ class WebsyRouter {
|
|
|
3290
3336
|
if (this.options.onHide) {
|
|
3291
3337
|
this.on('hide', this.options.onHide)
|
|
3292
3338
|
}
|
|
3293
|
-
this.init()
|
|
3339
|
+
// this.init()
|
|
3294
3340
|
}
|
|
3295
3341
|
addGroup (group) {
|
|
3296
3342
|
if (!this.groups[group]) {
|
|
@@ -3346,6 +3346,7 @@ var WebsyResultList = /*#__PURE__*/function () {
|
|
|
3346
3346
|
this.rows = [];
|
|
3347
3347
|
this.apiService = new WebsyDesigns.APIService('/api');
|
|
3348
3348
|
this.templateService = new WebsyDesigns.APIService('');
|
|
3349
|
+
this.activeTemplate = '';
|
|
3349
3350
|
|
|
3350
3351
|
if (!elementId) {
|
|
3351
3352
|
console.log('No element Id provided for Websy Search List');
|
|
@@ -3374,6 +3375,7 @@ var WebsyResultList = /*#__PURE__*/function () {
|
|
|
3374
3375
|
value: function appendData(d) {
|
|
3375
3376
|
var startIndex = this.rows.length;
|
|
3376
3377
|
this.rows = this.rows.concat(d);
|
|
3378
|
+
this.activeTemplate = this.options.template;
|
|
3377
3379
|
var html = this.buildHTML(d, startIndex);
|
|
3378
3380
|
var el = document.getElementById(this.elementId);
|
|
3379
3381
|
el.innerHTML += html.replace(/\n/g, '');
|
|
@@ -3384,12 +3386,13 @@ var WebsyResultList = /*#__PURE__*/function () {
|
|
|
3384
3386
|
var _this21 = this;
|
|
3385
3387
|
|
|
3386
3388
|
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
3389
|
+
var inputTemplate = arguments.length > 2 ? arguments[2] : undefined;
|
|
3387
3390
|
var html = "";
|
|
3388
3391
|
|
|
3389
3392
|
if (this.options.template) {
|
|
3390
3393
|
if (d.length > 0) {
|
|
3391
3394
|
d.forEach(function (row, ix) {
|
|
3392
|
-
var template = "".concat(ix > 0 ? '-->' : '').concat(_this21.options.template).concat(ix < d.length - 1 ? '<!--' : ''); // find conditional elements
|
|
3395
|
+
var template = "".concat(ix > 0 ? '-->' : '').concat(inputTemplate || _this21.options.template).concat(ix < d.length - 1 ? '<!--' : ''); // find conditional elements
|
|
3393
3396
|
|
|
3394
3397
|
var ifMatches = _toConsumableArray(template.matchAll(/<\s*if[^>]*>([\s\S]*?)<\s*\/\s*if>/g));
|
|
3395
3398
|
|
|
@@ -3473,6 +3476,31 @@ var WebsyResultList = /*#__PURE__*/function () {
|
|
|
3473
3476
|
}
|
|
3474
3477
|
});
|
|
3475
3478
|
|
|
3479
|
+
var forMatches = _toConsumableArray(template.matchAll(/<\s*for[^>]*>([\s\S]*?)<\s*\/\s*for>/g));
|
|
3480
|
+
|
|
3481
|
+
forMatches.forEach(function (m) {
|
|
3482
|
+
var itemsMatch = m[0].match(/(items=["|']\w.+)["|']/g);
|
|
3483
|
+
var forMarkup = m[0].match(/<\s*for[^>]*>/);
|
|
3484
|
+
var withoutFor = m[0].replace(forMarkup, '').replace('</for>', '').replace(/<\s*for[^>]*>/g, '');
|
|
3485
|
+
|
|
3486
|
+
if (itemsMatch && itemsMatch[0]) {
|
|
3487
|
+
var c = itemsMatch[0].trim().replace('items=', '');
|
|
3488
|
+
|
|
3489
|
+
if (c.split('')[0] === '"') {
|
|
3490
|
+
c = c.replace(/"/g, '');
|
|
3491
|
+
} else if (c.split('')[0] === '\'') {
|
|
3492
|
+
c = c.replace(/'/g, '');
|
|
3493
|
+
}
|
|
3494
|
+
|
|
3495
|
+
var items = row;
|
|
3496
|
+
var parts = c.split('.');
|
|
3497
|
+
parts.forEach(function (p) {
|
|
3498
|
+
items = items[p];
|
|
3499
|
+
});
|
|
3500
|
+
template = template.replace(m[0], _this21.buildHTML(items, 0, withoutFor));
|
|
3501
|
+
}
|
|
3502
|
+
});
|
|
3503
|
+
|
|
3476
3504
|
var tagMatches = _toConsumableArray(template.matchAll(/(\sdata-event=["|']\w.+)["|']/g));
|
|
3477
3505
|
|
|
3478
3506
|
tagMatches.forEach(function (m) {
|
|
@@ -3481,11 +3509,14 @@ var WebsyResultList = /*#__PURE__*/function () {
|
|
|
3481
3509
|
}
|
|
3482
3510
|
});
|
|
3483
3511
|
|
|
3484
|
-
|
|
3512
|
+
var flatRow = _this21.flattenObject(row);
|
|
3513
|
+
|
|
3514
|
+
for (var key in flatRow) {
|
|
3485
3515
|
var rg = new RegExp("{".concat(key, "}"), 'gm');
|
|
3486
|
-
template = template.replace(rg,
|
|
3516
|
+
template = template.replace(rg, flatRow[key] || '');
|
|
3487
3517
|
}
|
|
3488
3518
|
|
|
3519
|
+
template = template.replace(/\{(.*?)\}/g, '');
|
|
3489
3520
|
html += template;
|
|
3490
3521
|
});
|
|
3491
3522
|
} else if (this.options.noRowsHTML) {
|
|
@@ -3506,6 +3537,33 @@ var WebsyResultList = /*#__PURE__*/function () {
|
|
|
3506
3537
|
|
|
3507
3538
|
return null;
|
|
3508
3539
|
}
|
|
3540
|
+
}, {
|
|
3541
|
+
key: "flattenObject",
|
|
3542
|
+
value: function flattenObject(obj) {
|
|
3543
|
+
var toReturn = {};
|
|
3544
|
+
|
|
3545
|
+
for (var i in obj) {
|
|
3546
|
+
if (!obj.hasOwnProperty(i)) {
|
|
3547
|
+
continue;
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
if (_typeof(obj[i]) === 'object') {
|
|
3551
|
+
var flatObject = this.flattenObject(obj[i]);
|
|
3552
|
+
|
|
3553
|
+
for (var x in flatObject) {
|
|
3554
|
+
if (!flatObject.hasOwnProperty(x)) {
|
|
3555
|
+
continue;
|
|
3556
|
+
}
|
|
3557
|
+
|
|
3558
|
+
toReturn[i + '.' + x] = flatObject[x];
|
|
3559
|
+
}
|
|
3560
|
+
} else {
|
|
3561
|
+
toReturn[i] = obj[i];
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
return JSON.parse(JSON.stringify(toReturn));
|
|
3566
|
+
}
|
|
3509
3567
|
}, {
|
|
3510
3568
|
key: "handleClick",
|
|
3511
3569
|
value: function handleClick(event) {
|
|
@@ -3627,9 +3685,8 @@ var WebsyRouter = /*#__PURE__*/function () {
|
|
|
3627
3685
|
|
|
3628
3686
|
if (this.options.onHide) {
|
|
3629
3687
|
this.on('hide', this.options.onHide);
|
|
3630
|
-
}
|
|
3688
|
+
} // this.init()
|
|
3631
3689
|
|
|
3632
|
-
this.init();
|
|
3633
3690
|
}
|
|
3634
3691
|
|
|
3635
3692
|
_createClass(WebsyRouter, [{
|