spyne 0.19.1 → 0.20.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.
Files changed (129) hide show
  1. package/.eslintrc.js +4 -3
  2. package/.travis.yml +24 -11
  3. package/karma.conf.js +76 -86
  4. package/lib/spyne.esm.js +15 -0
  5. package/lib/spyne.esm.js.map +1 -0
  6. package/lib/spyne.umd.js +9565 -0
  7. package/package.json +47 -27
  8. package/rollup.config.js +26 -0
  9. package/src/spyne/channels/channel-fetch-class.js +39 -43
  10. package/src/spyne/channels/channel-payload-class.js +61 -74
  11. package/src/spyne/channels/channel-proxy.js +25 -26
  12. package/src/spyne/channels/channel.js +141 -149
  13. package/src/spyne/channels/channels-config.js +46 -47
  14. package/src/spyne/channels/channels-map.js +61 -65
  15. package/src/spyne/channels/spyne-channel-lifecycle.js +12 -12
  16. package/src/spyne/channels/spyne-channel-route.js +241 -250
  17. package/src/spyne/channels/spyne-channel-ui.js +213 -75
  18. package/src/spyne/channels/spyne-channel-window.js +157 -157
  19. package/src/spyne/spyne-app.js +32 -19
  20. package/src/spyne/spyne-plugins.js +55 -70
  21. package/src/spyne/spyne.js +23 -23
  22. package/src/spyne/utils/channel-config-validator.js +10 -10
  23. package/src/spyne/utils/channel-fetch-util.js +72 -55
  24. package/src/spyne/utils/channel-payload-filter.js +89 -100
  25. package/src/spyne/utils/deep-merge.js +31 -29
  26. package/src/spyne/utils/frp-tools.js +108 -92
  27. package/src/spyne/utils/gc.js +6 -6
  28. package/src/spyne/utils/mixins/base-core-mixins.js +17 -15
  29. package/src/spyne/utils/mixins/base-streams-mixins.js +9 -9
  30. package/src/spyne/utils/route-channel-updater.js +23 -29
  31. package/src/spyne/utils/safe-clone.js +40 -58
  32. package/src/spyne/utils/sanitize-html.js +35 -0
  33. package/src/spyne/utils/security-policy.js +11 -0
  34. package/src/spyne/utils/spyne-app-properties.js +110 -114
  35. package/src/spyne/utils/spyne-logger.js +4 -11
  36. package/src/spyne/utils/spyne-plugins-methods.js +38 -63
  37. package/src/spyne/utils/spyne-trait.js +33 -33
  38. package/src/spyne/utils/spyne-utils-channel-route-url.js +229 -153
  39. package/src/spyne/utils/spyne-utils-channel-route.js +128 -138
  40. package/src/spyne/utils/spyne-utils-channel-window.js +39 -39
  41. package/src/spyne/utils/viewstream-animations.js +12 -12
  42. package/src/spyne/utils/viewstream-observables.js +45 -45
  43. package/src/spyne/views/dom-element-template.js +111 -114
  44. package/src/spyne/views/dom-element.js +82 -84
  45. package/src/spyne/views/view-stream-broadcaster.js +66 -62
  46. package/src/spyne/views/view-stream-element.js +105 -106
  47. package/src/spyne/views/view-stream-payload.js +25 -27
  48. package/src/spyne/views/view-stream-selector.js +157 -163
  49. package/src/spyne/views/view-stream.js +416 -640
  50. package/src/tests/channels/channel-dom.test.js +15 -15
  51. package/src/tests/channels/channel-fetch.test.js +51 -62
  52. package/src/tests/channels/channel-payload-class.test.js +50 -63
  53. package/src/tests/channels/channel-payload-filter.test.js +133 -193
  54. package/src/tests/channels/channel-route.test.js +102 -112
  55. package/src/tests/channels/channel-stream-item.test.js +19 -19
  56. package/src/tests/channels/channel-ui.test.js +15 -27
  57. package/src/tests/channels/channel-util-dom.test.js +31 -31
  58. package/src/tests/channels/channel.test.js +20 -25
  59. package/src/tests/channels/route-utils.test.js +61 -66
  60. package/src/tests/channels/url-utils.test.js +151 -151
  61. package/src/tests/channels/view-stream-broadcaster.test.js +7 -7
  62. package/src/tests/import.test.js +5 -5
  63. package/src/tests/index.js +6 -7
  64. package/src/tests/index.test.js +6 -8
  65. package/src/tests/mocks/channel-payload-data.js +218 -220
  66. package/src/tests/mocks/enhancer.test.js +5 -5
  67. package/src/tests/mocks/payload-ui.js +87 -90
  68. package/src/tests/mocks/routes-data.js +264 -266
  69. package/src/tests/mocks/spyne-docs.mocks.js +3 -3
  70. package/src/tests/mocks/template-renderer.mocks.js +47 -47
  71. package/src/tests/mocks/utils-data.js +78 -79
  72. package/src/tests/mocks/viewstream-internal-payload.mocks.js +50 -50
  73. package/src/tests/mocks/window-events-arr.js +1 -1
  74. package/src/tests/package-json.spec.test.js +9 -0
  75. package/src/tests/spyne-app.test.js +15 -18
  76. package/src/tests/spyne-plugin.test.js +16 -20
  77. package/src/tests/utils/channel-action-filter.test.js +84 -86
  78. package/src/tests/utils/channel-data-packet-generator.unused.js +62 -86
  79. package/src/tests/utils/channel-fetch-util.test.js +64 -66
  80. package/src/tests/utils/frp-tools.test.js +19 -19
  81. package/src/tests/utils/plugins-methods.test.js +31 -55
  82. package/src/tests/utils/security.test.js +10 -0
  83. package/src/tests/utils/spyne-app-properties.test.js +4 -8
  84. package/src/tests/views/dom-el-selectors.test.js +112 -119
  85. package/src/tests/views/dom-el-template-proxy.test.js +7 -0
  86. package/src/tests/views/dom-el-template.test.js +186 -156
  87. package/src/tests/views/dom-el.test.js +58 -56
  88. package/src/tests/views/view-stream-enhancer-loader.test.js +2 -2
  89. package/src/tests/views/view-stream-enhancer.test.js +11 -11
  90. package/src/tests/views/view-stream.test.js +22 -33
  91. package/webpack.config.js +76 -67
  92. package/docs/-_%20Solves%20equations%20of%20the%20form%20a%20_%20x%20=%20b.html +0 -487
  93. package/docs/DomItem.html +0 -298
  94. package/docs/DomItem_DomItem.html +0 -314
  95. package/docs/ViewStream.html +0 -2249
  96. package/docs/ViewStream_ViewStream.html +0 -503
  97. package/docs/custom/css/jsdoc-viewstream.css +0 -377
  98. package/docs/custom/layout.tmpl +0 -47
  99. package/docs/dom-item.js.html +0 -213
  100. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  101. package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
  102. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  103. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  104. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  105. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  106. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  107. package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
  108. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  109. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  110. package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
  111. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  112. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  113. package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  114. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  115. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  116. package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
  117. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  118. package/docs/global.html +0 -548
  119. package/docs/index-custom.html +0 -79
  120. package/docs/index.html +0 -82
  121. package/docs/jsdoc.config.json +0 -22
  122. package/docs/scripts/linenumber.js +0 -25
  123. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  124. package/docs/scripts/prettify/lang-css.js +0 -2
  125. package/docs/scripts/prettify/prettify.js +0 -28
  126. package/docs/styles/jsdoc-default.css +0 -358
  127. package/docs/styles/prettify-jsdoc.css +0 -111
  128. package/docs/styles/prettify-tomorrow.css +0 -132
  129. package/docs/view-stream.js.html +0 -767
@@ -1,5 +1,6 @@
1
- import {includes, __, ifElse, path, prop, reject, is, isNil, isEmpty} from 'ramda';
2
-
1
+ import { includes, __, ifElse, path, prop, reject, is, isNil, isEmpty } from 'ramda'
2
+ import sanitizeHTML from '../utils/sanitize-html'
3
+ import { SpyneAppProperties } from '../utils/spyne-app-properties'
3
4
 
4
5
  /**
5
6
  * @module DomElTemplate
@@ -134,221 +135,217 @@ import {includes, __, ifElse, path, prop, reject, is, isNil, isEmpty} from 'ramd
134
135
  */
135
136
 
136
137
  export class DomElementTemplate {
137
- constructor(template, data={}) {
138
- this.template = this.formatTemplate(template);
139
- this.isProxyData = data.__cms__isProxy === true;
140
-
138
+ constructor(template, data = {}) {
139
+ this.template = this.formatTemplate(template)
140
+ this.isProxyData = data.__cms__isProxy === true
141
141
 
142
-
143
- const checkForArrayData = ()=>{
142
+ const checkForArrayData = () => {
144
143
  if (is(Array, data) === true) {
145
- data = {spyneData:data};
146
- this.template = this.template.replace("{{/}}", "{{/spyneData}}");
147
- this.template = this.template.replace("{{#}}", "{{#spyneData}}");
144
+ data = { spyneData:data }
145
+ this.template = this.template.replace('{{/}}', '{{/spyneData}}')
146
+ this.template = this.template.replace('{{#}}', '{{#spyneData}}')
148
147
  }
149
- };
150
-
148
+ }
151
149
 
152
- checkForArrayData();
150
+ checkForArrayData()
153
151
 
154
- this.templateData = data;
152
+ this.templateData = data
155
153
 
156
- let strArr = DomElementTemplate.getStringArray(this.template);
154
+ const strArr = DomElementTemplate.getStringArray(this.template)
157
155
 
158
- let strMatches = this.template.match(DomElementTemplate.findTmplLoopsRE());
159
- strMatches = strMatches === null ? [] : strMatches;
156
+ let strMatches = this.template.match(DomElementTemplate.findTmplLoopsRE())
157
+ strMatches = strMatches === null ? [] : strMatches
160
158
 
161
- const parseTmplLoopsRE = DomElementTemplate.parseTmplLoopsRE();
159
+ const parseTmplLoopsRE = DomElementTemplate.parseTmplLoopsRE()
162
160
 
163
- const parseTmplLoopFn = this.parseTheTmplLoop.bind(this);
161
+ const parseTmplLoopFn = this.parseTheTmplLoop.bind(this)
164
162
 
165
163
  const mapTmplLoop = (str, data) => {
166
- return str.replace(parseTmplLoopsRE, parseTmplLoopFn);
164
+ return str.replace(parseTmplLoopsRE, parseTmplLoopFn)
167
165
  }
168
166
 
169
- const findTmplLoopsPred = includes(__, strMatches);
167
+ const findTmplLoopsPred = includes(__, strMatches)
170
168
  const checkForMatches = ifElse(
171
- findTmplLoopsPred,
172
- mapTmplLoop,
173
- this.addParams.bind(this));
174
-
175
- this.finalArr = strArr.map(checkForMatches);
169
+ findTmplLoopsPred,
170
+ mapTmplLoop,
171
+ this.addParams.bind(this))
176
172
 
173
+ this.finalArr = strArr.map(checkForMatches)
177
174
  }
178
175
 
179
- static isPrimitiveTag(str){
180
- return /({{\.\*?}})/.test(str);;
176
+ static isPrimitiveTag(str) {
177
+ return /({{\.\*?}})/.test(str)
181
178
  }
182
179
 
183
180
  // FIND CORRECT NESTED DATA
184
- static getNestedDataReducer(data={}, param=""){
185
- const dataReducer = (nestedData, str) =>{
186
- if (nestedData[str]){
187
- return nestedData[str];
181
+ static getNestedDataReducer(data = {}, param = '') {
182
+ const dataReducer = (nestedData, str) => {
183
+ if (nestedData[str]) {
184
+ return nestedData[str]
188
185
  }
189
- return nestedData;
186
+ return typeof nestedData === 'string' ? nestedData : ''
190
187
  }
191
- return /(\.)/gm.test(String(param)) ? String(param).split('.').reduce(dataReducer,data) : data[param];
188
+
189
+ return /(\.)/gm.test(String(param)) ? String(param).split('.').reduce(dataReducer, data) : data[param] ?? ''
192
190
  }
193
191
 
194
192
  static getStringArray(template) {
195
- let strArr = template.split(DomElementTemplate.findTmplLoopsRE());
196
- const emptyRE = /^([\\n\s\W]+)$/;
197
- const filterOutEmptyStrings = s => s.match(emptyRE);
198
- const finalStr = reject(filterOutEmptyStrings, strArr);
199
-
200
- return finalStr;
193
+ const strArr = template.split(DomElementTemplate.findTmplLoopsRE())
194
+ const emptyRE = /^([\\n\s\W]+)$/
195
+ const filterOutEmptyStrings = s => s.match(emptyRE)
196
+ const finalStr = reject(filterOutEmptyStrings, strArr)
201
197
 
198
+ return finalStr
202
199
  }
203
200
 
204
201
  static findTmplLoopsRE() {
205
- return /({{#[\w.]+}}[\w\n\s\W]+?{{\/[\w.]+}})/gm;
202
+ return /({{#[\w.]+}}[\w\n\s\W]+?{{\/[\w.]+}})/gm
206
203
  }
207
204
 
208
205
  static parseTmplLoopsRE() {
209
- return /({{#([\w.]+)}})([\w\n\s\W]+?)({{\/\2}})/gm;
206
+ return /({{#([\w.]+)}})([\w\n\s\W]+?)({{\/\2}})/gm
210
207
  }
211
208
 
212
209
  static swapParamsForTagsRE() {
213
- return /({{)(.*?)(}})/gm;
210
+ return /({{)(.*?)(}})/gm
214
211
  }
215
212
 
216
213
  removeThis() {
217
- this.finalArr = undefined;
218
- this.templateData = undefined;
219
- this.template = undefined;
214
+ if (this !== undefined) {
215
+ this.finalArr = undefined
216
+ this.templateData = undefined
217
+ this.template = undefined
218
+ }
220
219
  }
221
220
 
222
-
223
221
  /**
224
222
  *
225
223
  * @desc Returns a document fragment generated from the template and any added data.
226
224
  */
227
225
 
228
-
229
226
  renderDocFrag() {
230
- const html = this.finalArr.join('');
231
- const isTableSubTag = /^([^>]*?)(<){1}(\b)(thead|col|colgroup|tbody|td|tfoot|tr|th)(\b)([^\0]*)$/.test(html);
232
- const el = isTableSubTag ? html : document.createRange().createContextualFragment(html);
233
-
234
- window.setTimeout(this.removeThis(), 2);
235
- return el;
236
-
227
+ let html = DomElementTemplate.replaceImgPath(this.finalArr.join(''))
228
+ // html = sanitizeHTML(this.finalArr.join(''))
229
+ html = sanitizeHTML(html)
230
+ const isTableSubTag = /^([^>]*?)(<){1}(\b)(thead|col|colgroup|tbody|td|tfoot|tr|th)(\b)([^\0]*)$/.test(html)
231
+ const el = isTableSubTag ? html : document.createRange().createContextualFragment(html)
232
+
233
+ window.setTimeout(this.removeThis, 2)
234
+ return el
237
235
  }
238
236
 
239
- renderToString(){
240
- const html = this.finalArr.join('');
241
- window.setTimeout(this.removeThis(), 2);
242
- return html;
237
+ renderToString() {
238
+ let html = this.finalArr.join('')
239
+ html = DomElementTemplate.replaceImgPath(html)
240
+ window.setTimeout(this.removeThis, 2)
241
+ return html
243
242
  }
244
243
 
245
244
  getTemplateString() {
246
- return this.finalArr.join('');
245
+ return this.finalArr.join('')
247
246
  }
248
247
 
249
248
  formatTemplate(template) {
250
- return prop('nodeName', template)==='SCRIPT' ? template.innerHTML : template;
249
+ return ['SCRIPT', 'TEMPLATE'].includes(prop('nodeName', template)) === true ? template.innerHTML : template
251
250
  }
252
251
 
253
- getDataValFromPathStr(pathStr, dataFile){
254
- const pathArr = String(pathStr).split('.');
255
- const pathData = path(pathArr, dataFile);
256
- return pathData || '';
252
+ getDataValFromPathStr(pathStr, dataFile) {
253
+ const pathArr = String(pathStr).split('.')
254
+ const pathData = path(pathArr, dataFile)
255
+ return pathData || ''
257
256
  }
258
257
 
259
258
  addParams(str) {
260
- const re = /(\.)/gm;
261
259
  const replaceTags = (str, p1, p2, p3) => {
262
- return DomElementTemplate.getNestedDataReducer(this.templateData, p2);
263
- };
264
- return str.replace(DomElementTemplate.swapParamsForTagsRE(), replaceTags);
265
-
260
+ return DomElementTemplate.getNestedDataReducer(this.templateData, p2)
261
+ }
262
+ return str.replace(DomElementTemplate.swapParamsForTagsRE(), replaceTags)
266
263
  }
267
264
 
268
-
269
-
270
-
271
- parseTheTmplLoop(str, p1, p2, p3) {
272
- const dotConverter = str=>`${str.replace(/(\.)/g, "][")}`
273
- const reDot = /(\.)/gm;
274
- const subStr = p3;
275
-
276
- const dataReducer = (acc, str) =>{
277
- acc = acc[str];
278
- return acc;
265
+ static replaceImgPath(templateStr) {
266
+ const { IMG_PATH } = SpyneAppProperties
267
+ if (IMG_PATH !== undefined) {
268
+ templateStr = templateStr.replaceAll(/src\s*=\s*(['"])imgs\//g, `src=$1${IMG_PATH}`)
269
+ return templateStr.replaceAll(/url\(\s*(['"]?)imgs\//g, `url($1${IMG_PATH}`)
279
270
  }
271
+ return templateStr
272
+ }
280
273
 
274
+ parseTheTmplLoop(str, p1, p2, p3) {
275
+ // const dotConverter = str => `${str.replace(/(\.)/g, '][')}`
276
+ const reDot = /(\.)/gm
277
+ const subStr = p3
281
278
 
282
- let elData = DomElementTemplate.getNestedDataReducer(this.templateData, p2);
279
+ /* const dataReducer = (acc, str) => {
280
+ acc = acc[str]
281
+ return acc
282
+ } */
283
283
 
284
- const arrayStringToObjAdapter = (d,str, i)=>{
284
+ let elData = DomElementTemplate.getNestedDataReducer(this.templateData, p2)
285
285
 
286
+ const arrayStringToObjAdapter = (d, str, i) => {
286
287
  // IF {{.}} RUN parseString
287
- if (DomElementTemplate.isPrimitiveTag(str)){
288
- return parseString(d, str, i);
288
+ if (DomElementTemplate.isPrimitiveTag(str)) {
289
+ return parseString(d, str, i)
289
290
  }
290
291
 
291
292
  // CREATE DATA OBJ -- CHECK TO ADD PROXY VALUES
292
- const createDataObj = ()=>{
293
- const spyneLoopKey = d;
294
- const loopIndex = i;
295
- const loopNum = i+1;
293
+ const createDataObj = () => {
294
+ const spyneLoopKey = d
295
+ const loopIndex = i
296
+ const loopNum = i + 1
296
297
 
297
298
  if (this.isProxyData) {
298
- const __cms__dataId = elData.__cms__dataId;
299
+ const __cms__dataId = elData.__cms__dataId
299
300
  const keyIdStr = `__cms__keyFor_${d}`
300
- const origKey = elData[keyIdStr];
301
- return {spyneLoopKey, __cms__dataId, origKey, loopIndex, loopNum, d}
302
-
301
+ const origKey = elData[keyIdStr]
302
+ return { spyneLoopKey, __cms__dataId, origKey, loopIndex, loopNum, d }
303
303
  }
304
- return {spyneLoopKey, loopIndex, loopNum};
304
+ return { spyneLoopKey, loopIndex, loopNum }
305
305
  }
306
306
 
307
- return parseObject(createDataObj(), str, i);
307
+ return parseObject(createDataObj(), str, i)
308
308
  }
309
309
 
310
310
  const parseString = (item, str, index, origIndex) => {
311
- return str.replace(DomElementTemplate.swapParamsForTagsRE(), item);
312
- };
313
-
311
+ return str.replace(DomElementTemplate.swapParamsForTagsRE(), item)
312
+ }
314
313
 
315
314
  // PARSING ARRAYS AND OBJECTS
316
315
  const parseObject = (obj, str, i) => {
317
316
  /// LOOP NUMBER VALUES AUTO ADDED
318
317
 
319
- //const loopIndex = i;
320
- //const loopNum = i+1;
318
+ // const loopIndex = i;
319
+ // const loopNum = i+1;
321
320
 
322
321
  const loopObj = (str, p1, p2) => {
323
322
  // DOT SYNTAX CHECK
324
323
  const hash = {
325
324
  loopIndex: i,
326
- loopNum: i+1
325
+ loopNum: i + 1
327
326
  }
328
327
 
329
328
  // IF {{.}}
330
- if (reDot.test(p2) === false && obj[p2] !==undefined) {
329
+ if (reDot.test(p2) === false && obj[p2] !== undefined) {
331
330
  return hash[p2] !== undefined ? hash[p2] : obj[p2]
332
331
  }
333
332
 
334
- const dataReducedVal = this.getDataValFromPathStr(p2, obj);
333
+ const dataReducedVal = this.getDataValFromPathStr(p2, obj)
335
334
  return hash[p2] !== undefined ? hash[p2] : dataReducedVal
336
- };
337
- return str.replace(DomElementTemplate.swapParamsForTagsRE(), loopObj);
338
- };
335
+ }
336
+ return str.replace(DomElementTemplate.swapParamsForTagsRE(), loopObj)
337
+ }
339
338
 
340
- const mapStringData = (d, i) => typeof(d) === 'string' ? arrayStringToObjAdapter(d, subStr, i) : parseObject(d, subStr, i);
339
+ const mapStringData = (d, i) => typeof (d) === 'string' ? arrayStringToObjAdapter(d, subStr, i) : parseObject(d, subStr, i)
341
340
 
342
341
  if (isNil(elData) === true || isEmpty(elData)) {
343
- return '';
342
+ return ''
344
343
  }
345
344
 
346
- if (elData.length===undefined) {
347
- elData = [elData];
345
+ if (elData.length === undefined) {
346
+ elData = [elData]
348
347
  }
349
348
 
350
- return elData.map(mapStringData).join('');
351
-
352
-
349
+ return elData.map(mapStringData).join('')
353
350
  }
354
351
  }
@@ -1,7 +1,7 @@
1
- import { baseCoreMixins } from '../utils/mixins/base-core-mixins';
2
- import { DomElementTemplate } from './dom-element-template';
3
- import { deepMerge } from '../utils/deep-merge';
4
- import {is, defaultTo, pick, mapObjIndexed, forEachObjIndexed, pipe} from 'ramda';
1
+ import { baseCoreMixins } from '../utils/mixins/base-core-mixins'
2
+ import { DomElementTemplate } from './dom-element-template'
3
+ import { deepMerge } from '../utils/deep-merge'
4
+ import { is, defaultTo, pick, mapObjIndexed, forEachObjIndexed, pipe } from 'ramda'
5
5
 
6
6
  class DomElement {
7
7
  /**
@@ -25,91 +25,90 @@ class DomElement {
25
25
  *
26
26
  */
27
27
 
28
- constructor(props={}) {
28
+ constructor(props = {}) {
29
+ const checkDefault = (dflt, val) => defaultTo(dflt)(val)
29
30
 
30
- const checkDefault = (dflt, val)=>defaultTo(dflt)(val);
31
+ props.tagName = checkDefault('div', props.tagName)
31
32
 
32
- props.tagName = checkDefault('div', props.tagName);
33
+ props.attributes = props.attributes !== undefined ? props.attributes : this.getDomAttributes(props)
34
+ props.attrs = this.updateAttrs(props.attributes)
33
35
 
34
- props.attributes = props.attributes!==undefined ? props.attributes : this.getDomAttributes(props);
35
- props.attrs = this.updateAttrs(props.attributes);
36
+ props.fragment = document.createDocumentFragment()
37
+ this.props = props
36
38
 
37
- props.fragment = document.createDocumentFragment()
38
- this.props = props;
39
-
40
- this.addMixins();
39
+ this.addMixins()
41
40
  }
42
41
 
43
42
  setProp(key, val) {
44
- this.props[key] = val;
43
+ this.props[key] = val
45
44
  }
46
45
 
47
46
  getProp(val) {
48
- return this.props[val];
47
+ return this.props[val]
49
48
  }
50
49
 
51
50
  get el() {
52
- return this.props.el;
51
+ return this.props.el
53
52
  }
54
53
 
55
54
  setElAttrs(el, params) {
56
- let addAttributes = (val, key) => {
57
- let addToDataset = (val, key) => { el.dataset[key] = val; };
55
+ const addAttributes = (val, key) => {
56
+ const addToDataset = (val, key) => { el.dataset[key] = val }
58
57
  if (key === 'dataset') {
59
- forEachObjIndexed(addToDataset, val);
58
+ forEachObjIndexed(addToDataset, val)
60
59
  } else {
61
- el.setAttribute(key, val);
60
+ el.setAttribute(key, val)
62
61
  }
63
- };
64
- this.getProp('attrs').forEach(addAttributes);
65
- return el;
62
+ }
63
+ this.getProp('attrs').forEach(addAttributes)
64
+ return el
66
65
  }
67
66
 
68
67
  updateAttrs(params, m) {
69
- let theMap = m !== undefined ? m : new Map();
70
- let addAttributes = (val, key) => theMap.set(key, val);
71
- mapObjIndexed(addAttributes, params);
72
- return theMap;
68
+ const theMap = m !== undefined ? m : new Map()
69
+ const addAttributes = (val, key) => theMap.set(key, val)
70
+ mapObjIndexed(addAttributes, params)
71
+ return theMap
73
72
  }
74
73
 
75
74
  addTemplate(el) {
76
- let template = this.getProp('template');
75
+ const template = this.getProp('template')
77
76
 
78
- let addTmpl = (template) => {
79
- let data = this.getProp('data');
80
- data = is(Object, data) ? data : {};
81
- let frag = new DomElementTemplate(template, data).renderDocFrag();
82
- const fragIsString = is(String, frag);
83
- fragIsString ? el.innerHTML = frag : el.appendChild(frag);
84
- return el;
85
- };
86
- let doNothing = (el) => el;
87
- return template !== undefined ? addTmpl(template) : doNothing(el);
77
+ const addTmpl = (template) => {
78
+ let data = this.getProp('data')
79
+ data = is(Object, data) ? data : {}
80
+ const frag = new DomElementTemplate(template, data).renderDocFrag()
81
+ const fragIsString = is(String, frag)
82
+ fragIsString ? el.innerHTML = frag : el.appendChild(frag)
83
+ return el
84
+ }
85
+ const doNothing = (el) => el
86
+ return template !== undefined ? addTmpl(template) : doNothing(el)
88
87
  }
89
88
 
90
89
  createElement(tagName = 'div') {
91
- return document.createElement(tagName);
90
+ return document.createElement(tagName)
92
91
  }
93
92
 
94
93
  addContent(el) {
95
- let text = (this.getProp('data'));
96
- let isText = is(String, text);
94
+ const text = (this.getProp('data'))
95
+ const isText = is(String, text)
97
96
  if (isText === true) {
98
- let txt = document.createTextNode(text);
99
- el.appendChild(txt);
97
+ const txt = document.createTextNode(text)
98
+ el.appendChild(txt)
100
99
  }
101
- return el;
100
+ return el
102
101
  }
103
102
 
104
103
  execute() {
105
- let el = pipe(
104
+ const el = pipe(
106
105
  this.createElement.bind(this),
107
106
  this.setElAttrs.bind(this),
108
107
  this.addTemplate.bind(this),
109
108
  this.addContent.bind(this)
110
- )(this.getProp('tagName'));
109
+ )(this.getProp('tagName'))
111
110
  // this.getProp('fragment').appendChild(el);
112
- this.props.el = el;
111
+ this.props.el = el
113
112
  }
114
113
 
115
114
  /**
@@ -117,67 +116,67 @@ class DomElement {
117
116
  * @returns {HTMLElement} HTMLElement
118
117
  */
119
118
  render() {
120
- this.execute();
121
- this.props.template = undefined;
122
- this.props.data = undefined;
123
- this.props.attributes = undefined;
124
- return this.getProp('el');
119
+ this.execute()
120
+ this.props.template = undefined
121
+ this.props.data = undefined
122
+ this.props.attributes = undefined
123
+ return this.getProp('el')
125
124
  }
126
125
 
127
126
  renderToHTMLString() {
128
- this.execute();
129
- this.props.template = undefined;
130
- this.props.data = undefined;
131
- this.props.attributes = undefined;
132
- return this.getProp('el').outerHTML;
127
+ this.execute()
128
+ this.props.template = undefined
129
+ this.props.data = undefined
130
+ this.props.attributes = undefined
131
+ return this.getProp('el').outerHTML
133
132
  }
134
133
 
135
-
136
134
  returnIfDefined(obj, val) {
137
135
  if (val !== undefined) {
138
- let isObj = typeof (val) === 'undefined';
139
- isObj === false ? obj[val] = val : obj[val] = deepMerge(obj[val], val);
136
+ const isObj = typeof (val) === 'undefined'
137
+ isObj === false ? obj[val] = val : obj[val] = deepMerge(obj[val], val)
140
138
  }
141
139
  }
142
140
 
143
141
  updateprops(val) {
144
- this.returnIfDefined(this.props, val);
145
- return this;
142
+ this.returnIfDefined(this.props, val)
143
+ return this
146
144
  }
147
145
 
148
146
  updatepropsAndRun(val) {
149
- this.updateprops(val);
150
- this.execute();
151
- return this.getProp('fragment');
147
+ this.updateprops(val)
148
+ this.execute()
149
+ return this.getProp('fragment')
152
150
  }
153
151
 
154
152
  unmount() {
155
153
  if (this.props !== undefined) {
156
- this.getProp('el').remove();
157
- this.props = undefined;
158
- this.gc();
154
+ this.getProp('el').remove()
155
+ this.props = undefined
156
+ this.gc()
159
157
  }
160
158
  }
161
159
 
162
- updateTag(tagName = 'div') { this.updateprops(tagName); }
163
- updateAttributes(attrs = {}) { this.updateprops(attrs); }
164
- updateTemplate(template) { this.updateprops(template); }
165
- updateData(data = {}) { this.updateprops(data); }
166
- addTagAndRender(tagName = 'div') { this.updatepropsAndRun(tagName); }
167
- addAttrsibutesAndRender(attrs = {}) { this.updatepropsAndRun(attrs); }
168
- addTemplateAndRender(template) { this.updatepropsAndRun(template); }
169
- addDataAndRender(data = {}) { this.updatepropsAndRun(data); }
160
+ updateTag(tagName = 'div') { this.updateprops(tagName) }
161
+ updateAttributes(attrs = {}) { this.updateprops(attrs) }
162
+ updateTemplate(template) { this.updateprops(template) }
163
+ updateData(data = {}) { this.updateprops(data) }
164
+ addTagAndRender(tagName = 'div') { this.updatepropsAndRun(tagName) }
165
+ addAttrsibutesAndRender(attrs = {}) { this.updatepropsAndRun(attrs) }
166
+ addTemplateAndRender(template) { this.updatepropsAndRun(template) }
167
+ addDataAndRender(data = {}) { this.updatepropsAndRun(data) }
170
168
  // ==================================
171
169
  // BASE CORE MIXINS
172
170
  // ==================================
173
171
  addMixins() {
174
- let coreMixins = baseCoreMixins();
175
- this.gc = coreMixins.gc.bind(this);
172
+ const coreMixins = baseCoreMixins()
173
+ this.gc = coreMixins.gc.bind(this)
176
174
  }
177
175
 
178
- getDomAttributes(props){
179
- return pick(this.attributesArray, props);
176
+ getDomAttributes(props) {
177
+ return pick(this.attributesArray, props)
180
178
  }
179
+
181
180
  get attributesArray() {
182
181
  return [
183
182
  'accept',
@@ -302,9 +301,8 @@ class DomElement {
302
301
  'value',
303
302
  'width',
304
303
  'wrap'
305
- ];
304
+ ]
306
305
  }
307
-
308
306
  }
309
- const DomEl = DomElement;
310
- export {DomElement, DomEl}
307
+ const DomEl = DomElement
308
+ export { DomElement, DomEl }