halfcab 15.0.4 → 15.0.6
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 +34 -25
- package/package.json +1 -1
package/halfcab.mjs
CHANGED
|
@@ -70,15 +70,15 @@ let html = (strings, ...values) => {
|
|
|
70
70
|
// fix for allowing csjs to coexist with lit-html
|
|
71
71
|
values = values.map(value => {
|
|
72
72
|
if (value && value.hasOwnProperty('toString') && !value.hasOwnProperty('_$litType$')) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
// Check if it's a template result (lit-html object). If not, and has toString (like CSJS object), stringify it.
|
|
74
|
+
if (Array.isArray(value)) return value;
|
|
75
|
+
if (typeof value === 'object' && value !== null) {
|
|
76
|
+
if (value['_$litType$'] !== undefined) return value; // It's a TemplateResult
|
|
77
|
+
// CSJS object:
|
|
78
|
+
if (value.toString && value.toString !== Object.prototype.toString) {
|
|
79
|
+
return value.toString()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
82
|
}
|
|
83
83
|
return value
|
|
84
84
|
})
|
|
@@ -89,17 +89,17 @@ let html = (strings, ...values) => {
|
|
|
89
89
|
const newRaw = strings.raw ? [...strings.raw] : [...strings]
|
|
90
90
|
const newVals = [...strings]
|
|
91
91
|
const onEventRegex = /on([a-zA-Z]+)=$/
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
for (let i = 0; i < newVals.length; i++) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
let match = newVals[i].match(onEventRegex)
|
|
95
|
+
if (match) {
|
|
96
|
+
const eventName = match[1]
|
|
97
|
+
const replacement = `@${eventName}=`
|
|
98
|
+
newVals[i] = newVals[i].replace(onEventRegex, replacement)
|
|
99
|
+
newRaw[i] = newRaw[i].replace(onEventRegex, replacement)
|
|
100
|
+
}
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
newStrings = newVals
|
|
104
104
|
newStrings.raw = newRaw
|
|
105
105
|
stringsCache.set(strings, newStrings)
|
|
@@ -352,20 +352,20 @@ function updateState (updateObject, options) {
|
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
function emptySSRVideos (c) {
|
|
355
|
-
// This was for nanomorph. Lit handles updates differently.
|
|
355
|
+
// This was for nanomorph. Lit handles updates differently.
|
|
356
356
|
// If we need to manipulate DOM before render, it's harder with Templates.
|
|
357
357
|
// Leaving empty or deprecated.
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
function injectHTML (htmlString, options) {
|
|
361
361
|
if (options && options.wrapper === false) {
|
|
362
|
-
return
|
|
362
|
+
return unsafeHTML(htmlString)
|
|
363
363
|
}
|
|
364
|
-
return html
|
|
364
|
+
return html`<div>${unsafeHTML(htmlString)}</div>`
|
|
365
365
|
}
|
|
366
366
|
|
|
367
367
|
function injectMarkdown (mdString, options) {
|
|
368
|
-
return injectHTML(decode(marked(mdString)), options)
|
|
368
|
+
return injectHTML(decode(marked(mdString)), options)
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
function gotoRoute (route) {
|
|
@@ -431,6 +431,7 @@ export default (config, {shiftyRouter = shiftyRouterModule, href = hrefModule, h
|
|
|
431
431
|
//this default function is used for setting up client side and is not run on
|
|
432
432
|
// the server
|
|
433
433
|
({components, el} = config)
|
|
434
|
+
let { hydrationSkipRoutes } = config
|
|
434
435
|
|
|
435
436
|
return new Promise((resolve, reject) => {
|
|
436
437
|
let routesFormatted = routesArray.map(r => [
|
|
@@ -481,9 +482,17 @@ export default (config, {shiftyRouter = shiftyRouterModule, href = hrefModule, h
|
|
|
481
482
|
if (el) {
|
|
482
483
|
// rootEl is the container
|
|
483
484
|
rootEl = document.querySelector(el)
|
|
484
|
-
|
|
485
|
+
|
|
485
486
|
// Initial render. Only hydrate when container has Lit SSR markers.
|
|
486
|
-
|
|
487
|
+
console.log(`Hydration check. Router Key: ${state.router.key}`)
|
|
488
|
+
const shouldSkipHydration = hydrationSkipRoutes && hydrationSkipRoutes.includes(state.router.key)
|
|
489
|
+
|
|
490
|
+
if (shouldSkipHydration) {
|
|
491
|
+
console.log(`Skipping hydration for route: ${state.router.key}`)
|
|
492
|
+
rootEl.innerHTML = ''
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
if (canHydrateContainer(rootEl) && !shouldSkipHydration) {
|
|
487
496
|
try {
|
|
488
497
|
hydrate(c, rootEl)
|
|
489
498
|
} catch (e) {
|
|
@@ -494,7 +503,7 @@ export default (config, {shiftyRouter = shiftyRouterModule, href = hrefModule, h
|
|
|
494
503
|
} else {
|
|
495
504
|
render(c, rootEl)
|
|
496
505
|
}
|
|
497
|
-
|
|
506
|
+
|
|
498
507
|
return resolve({rootEl, state})
|
|
499
508
|
}
|
|
500
509
|
// If no root element provided?
|
package/package.json
CHANGED