halfcab 14.0.0 → 14.0.2

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 (2) hide show
  1. package/halfcab.mjs +29 -2
  2. package/package.json +1 -1
package/halfcab.mjs CHANGED
@@ -13,6 +13,7 @@ import eventEmitter from './eventEmitter/index.mjs'
13
13
  import qs from 'qs'
14
14
  import * as deepDiff from 'deep-object-diff'
15
15
  import clone from 'fast-clone'
16
+ import LRU from 'nanolru'
16
17
 
17
18
  let cssTag = cssInject
18
19
  let componentCSSString = ''
@@ -80,11 +81,38 @@ let html = (strings, ...values) => {
80
81
  return litHtml(strings, ...values)
81
82
  }
82
83
 
84
+ function resolveTemplate (value) {
85
+ if (Array.isArray(value)) {
86
+ return value.map(resolveTemplate).join('')
87
+ }
88
+ if (value && typeof value === 'object') {
89
+ if (value.strings) {
90
+ let result = ''
91
+ const { strings, values } = value
92
+ for (let i = 0; i < strings.length; i++) {
93
+ result += strings[i]
94
+ if (i < values.length) {
95
+ result += resolveTemplate(values[i])
96
+ }
97
+ }
98
+ return result
99
+ }
100
+
101
+ if (value['_$litDirective$']) {
102
+ const directive = value['_$litDirective$']
103
+ if (directive.directiveName === 'unsafeHTML' && value.values && value.values.length > 0) {
104
+ return String(value.values[0])
105
+ }
106
+ }
107
+ }
108
+ return value === undefined || value === null ? '' : String(value)
109
+ }
110
+
83
111
  function ssr (rootComponent) {
84
112
  // Simple fallback for SSR since lit-html produces objects
85
113
  let componentsString = ''
86
114
  try {
87
- componentsString = String(rootComponent)
115
+ componentsString = resolveTemplate(rootComponent)
88
116
  } catch (e) {}
89
117
  return {componentsString, stylesString: componentCSSString}
90
118
  }
@@ -468,7 +496,6 @@ function cachedComponent (Class, args, id) {
468
496
  return new Class().render(args)
469
497
  }
470
498
 
471
- function LRU () {}
472
499
 
473
500
  export {
474
501
  getRouteComponent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "halfcab",
3
- "version": "14.0.0",
3
+ "version": "14.0.2",
4
4
  "type": "module",
5
5
  "description": "A simple universal JavaScript framework focused on making use of es2015 template strings to build components.",
6
6
  "main": "halfcab.mjs",