halfcab 14.0.2 → 14.0.4
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/halfcab.mjs +49 -3
- package/package.json +1 -1
package/halfcab.mjs
CHANGED
|
@@ -2,8 +2,11 @@ import shiftyRouterModule from 'shifty-router'
|
|
|
2
2
|
import hrefModule from 'shifty-router/href.js'
|
|
3
3
|
import historyModule from 'shifty-router/history.js'
|
|
4
4
|
import createLocation from 'shifty-router/create-location.js'
|
|
5
|
-
import { html as litHtml, render } from 'lit-html'
|
|
5
|
+
import { html as litHtml, render, nothing, noChange } from 'lit-html'
|
|
6
6
|
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js'
|
|
7
|
+
import { repeat } from 'lit-html/directives/repeat.js'
|
|
8
|
+
import { classMap } from 'lit-html/directives/class-map.js'
|
|
9
|
+
import { styleMap } from 'lit-html/directives/style-map.js'
|
|
7
10
|
import axios from 'axios'
|
|
8
11
|
import cssInject from 'csjs-inject'
|
|
9
12
|
import merge from 'deepmerge'
|
|
@@ -81,7 +84,16 @@ let html = (strings, ...values) => {
|
|
|
81
84
|
return litHtml(strings, ...values)
|
|
82
85
|
}
|
|
83
86
|
|
|
87
|
+
// Capture directive classes for SSR identification
|
|
88
|
+
const RepeatDirective = repeat([], () => {})['_$litDirective$']
|
|
89
|
+
const ClassMapDirective = classMap({})['_$litDirective$']
|
|
90
|
+
const StyleMapDirective = styleMap({})['_$litDirective$']
|
|
91
|
+
|
|
84
92
|
function resolveTemplate (value) {
|
|
93
|
+
if (value === nothing || value === noChange) {
|
|
94
|
+
return ''
|
|
95
|
+
}
|
|
96
|
+
|
|
85
97
|
if (Array.isArray(value)) {
|
|
86
98
|
return value.map(resolveTemplate).join('')
|
|
87
99
|
}
|
|
@@ -99,12 +111,46 @@ function resolveTemplate (value) {
|
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
if (value['_$litDirective$']) {
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
114
|
+
const directiveClass = value['_$litDirective$']
|
|
115
|
+
if (directiveClass.directiveName === 'unsafeHTML' && value.values && value.values.length > 0) {
|
|
104
116
|
return String(value.values[0])
|
|
105
117
|
}
|
|
118
|
+
|
|
119
|
+
if (directiveClass === RepeatDirective) {
|
|
120
|
+
const items = value.values[0]
|
|
121
|
+
const templateFn = value.values[value.values.length - 1]
|
|
122
|
+
if (items && typeof templateFn === 'function') {
|
|
123
|
+
return Array.from(items).map((item, index) => resolveTemplate(templateFn(item, index))).join('')
|
|
124
|
+
}
|
|
125
|
+
return ''
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (directiveClass === ClassMapDirective) {
|
|
129
|
+
const classObj = value.values[0]
|
|
130
|
+
if (typeof classObj === 'object') {
|
|
131
|
+
return Object.keys(classObj)
|
|
132
|
+
.filter(key => classObj[key])
|
|
133
|
+
.join(' ')
|
|
134
|
+
}
|
|
135
|
+
return ''
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (directiveClass === StyleMapDirective) {
|
|
139
|
+
const styleObj = value.values[0]
|
|
140
|
+
if (typeof styleObj === 'object') {
|
|
141
|
+
return Object.keys(styleObj)
|
|
142
|
+
.map(key => `${key}:${styleObj[key]}`)
|
|
143
|
+
.join(';')
|
|
144
|
+
}
|
|
145
|
+
return ''
|
|
146
|
+
}
|
|
106
147
|
}
|
|
107
148
|
}
|
|
149
|
+
|
|
150
|
+
if (typeof value === 'function') {
|
|
151
|
+
return ''
|
|
152
|
+
}
|
|
153
|
+
|
|
108
154
|
return value === undefined || value === null ? '' : String(value)
|
|
109
155
|
}
|
|
110
156
|
|
package/package.json
CHANGED