halfcab 15.0.3 → 15.0.5
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 +37 -28
- package/package.json +1 -1
package/halfcab.mjs
CHANGED
|
@@ -3,6 +3,7 @@ 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
5
|
import { html as litHtml, render } from 'lit'
|
|
6
|
+
import { unsafeHTML } from 'lit/directives/unsafe-html.js'
|
|
6
7
|
import { render as renderSSR } from '@lit-labs/ssr'
|
|
7
8
|
import { hydrate } from '@lit-labs/ssr-client'
|
|
8
9
|
import axios from 'axios'
|
|
@@ -12,14 +13,12 @@ import marked from 'marked'
|
|
|
12
13
|
import { decode } from 'html-entities'
|
|
13
14
|
import eventEmitter from './eventEmitter/index.mjs'
|
|
14
15
|
import qs from 'qs'
|
|
15
|
-
import * as deepDiff from 'deep-object-diff'
|
|
16
|
-
import clone from 'fast-clone'
|
|
17
16
|
|
|
18
17
|
let cssTag = cssInject
|
|
19
18
|
let componentCSSString = ''
|
|
20
19
|
let routesArray = []
|
|
21
20
|
let externalRoutes = []
|
|
22
|
-
let state = {}
|
|
21
|
+
let state = {}
|
|
23
22
|
let router
|
|
24
23
|
let rootEl
|
|
25
24
|
let components
|
|
@@ -71,15 +70,15 @@ let html = (strings, ...values) => {
|
|
|
71
70
|
// fix for allowing csjs to coexist with lit-html
|
|
72
71
|
values = values.map(value => {
|
|
73
72
|
if (value && value.hasOwnProperty('toString') && !value.hasOwnProperty('_$litType$')) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
}
|
|
83
82
|
}
|
|
84
83
|
return value
|
|
85
84
|
})
|
|
@@ -90,17 +89,17 @@ let html = (strings, ...values) => {
|
|
|
90
89
|
const newRaw = strings.raw ? [...strings.raw] : [...strings]
|
|
91
90
|
const newVals = [...strings]
|
|
92
91
|
const onEventRegex = /on([a-zA-Z]+)=$/
|
|
93
|
-
|
|
92
|
+
|
|
94
93
|
for (let i = 0; i < newVals.length; i++) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
+
}
|
|
102
101
|
}
|
|
103
|
-
|
|
102
|
+
|
|
104
103
|
newStrings = newVals
|
|
105
104
|
newStrings.raw = newRaw
|
|
106
105
|
stringsCache.set(strings, newStrings)
|
|
@@ -353,7 +352,7 @@ function updateState (updateObject, options) {
|
|
|
353
352
|
}
|
|
354
353
|
|
|
355
354
|
function emptySSRVideos (c) {
|
|
356
|
-
// This was for nanomorph. Lit handles updates differently.
|
|
355
|
+
// This was for nanomorph. Lit handles updates differently.
|
|
357
356
|
// If we need to manipulate DOM before render, it's harder with Templates.
|
|
358
357
|
// Leaving empty or deprecated.
|
|
359
358
|
}
|
|
@@ -362,11 +361,11 @@ function injectHTML (htmlString, options) {
|
|
|
362
361
|
if (options && options.wrapper === false) {
|
|
363
362
|
return html([htmlString])
|
|
364
363
|
}
|
|
365
|
-
return html([`<div>${htmlString}</div>`])
|
|
364
|
+
return html([`<div>${htmlString}</div>`])
|
|
366
365
|
}
|
|
367
366
|
|
|
368
367
|
function injectMarkdown (mdString, options) {
|
|
369
|
-
return injectHTML(decode(marked(mdString)), options)
|
|
368
|
+
return injectHTML(decode(marked(mdString)), options)
|
|
370
369
|
}
|
|
371
370
|
|
|
372
371
|
function gotoRoute (route) {
|
|
@@ -432,6 +431,7 @@ export default (config, {shiftyRouter = shiftyRouterModule, href = hrefModule, h
|
|
|
432
431
|
//this default function is used for setting up client side and is not run on
|
|
433
432
|
// the server
|
|
434
433
|
({components, el} = config)
|
|
434
|
+
let { hydrationSkipRoutes } = config
|
|
435
435
|
|
|
436
436
|
return new Promise((resolve, reject) => {
|
|
437
437
|
let routesFormatted = routesArray.map(r => [
|
|
@@ -482,9 +482,17 @@ export default (config, {shiftyRouter = shiftyRouterModule, href = hrefModule, h
|
|
|
482
482
|
if (el) {
|
|
483
483
|
// rootEl is the container
|
|
484
484
|
rootEl = document.querySelector(el)
|
|
485
|
-
|
|
485
|
+
|
|
486
486
|
// Initial render. Only hydrate when container has Lit SSR markers.
|
|
487
|
-
|
|
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) {
|
|
488
496
|
try {
|
|
489
497
|
hydrate(c, rootEl)
|
|
490
498
|
} catch (e) {
|
|
@@ -495,7 +503,7 @@ export default (config, {shiftyRouter = shiftyRouterModule, href = hrefModule, h
|
|
|
495
503
|
} else {
|
|
496
504
|
render(c, rootEl)
|
|
497
505
|
}
|
|
498
|
-
|
|
506
|
+
|
|
499
507
|
return resolve({rootEl, state})
|
|
500
508
|
}
|
|
501
509
|
// If no root element provided?
|
|
@@ -530,5 +538,6 @@ export {
|
|
|
530
538
|
resetTouched,
|
|
531
539
|
nextTick,
|
|
532
540
|
addToHoldingPen,
|
|
533
|
-
removeFromHoldingPen
|
|
541
|
+
removeFromHoldingPen,
|
|
542
|
+
unsafeHTML
|
|
534
543
|
}
|
package/package.json
CHANGED