effect-start 0.25.0 → 0.26.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.
- package/package.json +18 -86
- package/dist/ChildProcess.js +0 -42
- package/dist/Commander.js +0 -410
- package/dist/ContentNegotiation.js +0 -465
- package/dist/Cookies.js +0 -371
- package/dist/Development.js +0 -94
- package/dist/Effectify.js +0 -27
- package/dist/Entity.js +0 -289
- package/dist/Fetch.js +0 -192
- package/dist/FilePathPattern.js +0 -97
- package/dist/FileRouter.js +0 -204
- package/dist/FileRouterCodegen.js +0 -298
- package/dist/FileSystem.js +0 -132
- package/dist/Http.js +0 -107
- package/dist/PathPattern.js +0 -451
- package/dist/PlatformError.js +0 -40
- package/dist/PlatformRuntime.js +0 -71
- package/dist/Route.js +0 -143
- package/dist/RouteBody.js +0 -92
- package/dist/RouteError.js +0 -76
- package/dist/RouteHook.js +0 -64
- package/dist/RouteHttp.js +0 -367
- package/dist/RouteHttpTracer.js +0 -90
- package/dist/RouteMount.js +0 -86
- package/dist/RouteSchema.js +0 -271
- package/dist/RouteSse.js +0 -94
- package/dist/RouteTree.js +0 -119
- package/dist/RouteTrie.js +0 -179
- package/dist/SchemaExtra.js +0 -99
- package/dist/Socket.js +0 -40
- package/dist/SqlIntrospect.js +0 -515
- package/dist/Start.js +0 -79
- package/dist/StartApp.js +0 -3
- package/dist/StreamExtra.js +0 -135
- package/dist/System.js +0 -38
- package/dist/TuplePathPattern.js +0 -74
- package/dist/Unique.js +0 -226
- package/dist/Values.js +0 -52
- package/dist/bun/BunBundle.js +0 -186
- package/dist/bun/BunChildProcessSpawner.js +0 -142
- package/dist/bun/BunImportTrackerPlugin.js +0 -91
- package/dist/bun/BunRoute.js +0 -157
- package/dist/bun/BunRuntime.js +0 -41
- package/dist/bun/BunServer.js +0 -285
- package/dist/bun/BunVirtualFilesPlugin.js +0 -54
- package/dist/bun/_BunEnhancedResolve.js +0 -127
- package/dist/bun/index.js +0 -5
- package/dist/bundler/Bundle.js +0 -92
- package/dist/bundler/BundleFiles.js +0 -154
- package/dist/bundler/BundleRoute.js +0 -62
- package/dist/client/Overlay.js +0 -33
- package/dist/client/ScrollState.js +0 -106
- package/dist/client/index.js +0 -97
- package/dist/console/Console.js +0 -42
- package/dist/console/ConsoleErrors.js +0 -211
- package/dist/console/ConsoleLogger.js +0 -56
- package/dist/console/ConsoleMetrics.js +0 -72
- package/dist/console/ConsoleProcess.js +0 -59
- package/dist/console/ConsoleStore.js +0 -72
- package/dist/console/ConsoleTracer.js +0 -107
- package/dist/console/Simulation.js +0 -784
- package/dist/console/index.js +0 -3
- package/dist/console/routes/tree.js +0 -30
- package/dist/datastar/actions/fetch.js +0 -536
- package/dist/datastar/actions/peek.js +0 -13
- package/dist/datastar/actions/setAll.js +0 -19
- package/dist/datastar/actions/toggleAll.js +0 -19
- package/dist/datastar/attributes/attr.js +0 -49
- package/dist/datastar/attributes/bind.js +0 -194
- package/dist/datastar/attributes/class.js +0 -54
- package/dist/datastar/attributes/computed.js +0 -25
- package/dist/datastar/attributes/effect.js +0 -10
- package/dist/datastar/attributes/indicator.js +0 -33
- package/dist/datastar/attributes/init.js +0 -27
- package/dist/datastar/attributes/jsonSignals.js +0 -33
- package/dist/datastar/attributes/on.js +0 -81
- package/dist/datastar/attributes/onIntersect.js +0 -53
- package/dist/datastar/attributes/onInterval.js +0 -31
- package/dist/datastar/attributes/onSignalPatch.js +0 -51
- package/dist/datastar/attributes/ref.js +0 -11
- package/dist/datastar/attributes/show.js +0 -32
- package/dist/datastar/attributes/signals.js +0 -18
- package/dist/datastar/attributes/style.js +0 -57
- package/dist/datastar/attributes/text.js +0 -29
- package/dist/datastar/engine.js +0 -1145
- package/dist/datastar/index.js +0 -25
- package/dist/datastar/utils.js +0 -250
- package/dist/datastar/watchers/patchElements.js +0 -486
- package/dist/datastar/watchers/patchSignals.js +0 -14
- package/dist/experimental/EncryptedCookies.js +0 -328
- package/dist/experimental/index.js +0 -1
- package/dist/hyper/Hyper.js +0 -28
- package/dist/hyper/HyperHtml.js +0 -165
- package/dist/hyper/HyperNode.js +0 -13
- package/dist/hyper/HyperRoute.js +0 -45
- package/dist/hyper/html.js +0 -30
- package/dist/hyper/index.js +0 -5
- package/dist/hyper/jsx-runtime.js +0 -14
- package/dist/index.js +0 -8
- package/dist/node/NodeFileSystem.js +0 -675
- package/dist/node/NodeUtils.js +0 -23
- package/dist/sql/Sql.js +0 -8
- package/dist/sql/bun/index.js +0 -142
- package/dist/sql/index.js +0 -1
- package/dist/sql/libsql/index.js +0 -156
- package/dist/sql/mssql/docker.js +0 -110
- package/dist/sql/mssql/index.js +0 -194
- package/dist/testing/TestLogger.js +0 -42
- package/dist/testing/index.js +0 -2
- package/dist/testing/utils.js +0 -61
- package/dist/x/cloudflare/CloudflareTunnel.js +0 -63
- package/dist/x/cloudflare/index.js +0 -1
- package/dist/x/tailscale/TailscaleTunnel.js +0 -94
- package/dist/x/tailscale/index.js +0 -1
- package/dist/x/tailwind/TailwindPlugin.js +0 -294
- package/dist/x/tailwind/compile.js +0 -210
- package/dist/x/tailwind/plugin.js +0 -17
|
@@ -1,486 +0,0 @@
|
|
|
1
|
-
import { watcher } from "../engine.js"
|
|
2
|
-
import { aliasify, isHTMLOrSVG, supportsViewTransitions } from "../utils.js"
|
|
3
|
-
|
|
4
|
-
const isValidType = (arr, value) =>
|
|
5
|
-
(arr).includes(value)
|
|
6
|
-
|
|
7
|
-
const PATCH_MODES = /** @type {const} */ [
|
|
8
|
-
"remove",
|
|
9
|
-
"outer",
|
|
10
|
-
"inner",
|
|
11
|
-
"replace",
|
|
12
|
-
"prepend",
|
|
13
|
-
"append",
|
|
14
|
-
"before",
|
|
15
|
-
"after",
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
const NAMESPACES = /** @type {const} */ ["html", "svg", "mathml"]
|
|
19
|
-
|
|
20
|
-
watcher({
|
|
21
|
-
name: "datastar-patch-elements",
|
|
22
|
-
apply(
|
|
23
|
-
ctx,
|
|
24
|
-
{ selector = "", mode = "outer", namespace = "html", useViewTransition = "", elements = "" },
|
|
25
|
-
) {
|
|
26
|
-
if (!isValidType(PATCH_MODES, mode)) {
|
|
27
|
-
throw ctx.error("PatchElementsInvalidMode", { mode })
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!selector && mode !== "outer" && mode !== "replace") {
|
|
31
|
-
throw ctx.error("PatchElementsExpectedSelector")
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!isValidType(NAMESPACES, namespace)) {
|
|
35
|
-
throw ctx.error("PatchElementsInvalidNamespace", { namespace })
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const args2 = {
|
|
39
|
-
selector,
|
|
40
|
-
mode,
|
|
41
|
-
namespace,
|
|
42
|
-
useViewTransition: useViewTransition.trim() === "true",
|
|
43
|
-
elements,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (supportsViewTransitions && useViewTransition) {
|
|
47
|
-
document.startViewTransition(() => onPatchElements(ctx, args2))
|
|
48
|
-
} else {
|
|
49
|
-
onPatchElements(ctx, args2)
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
const onPatchElements = (
|
|
55
|
-
{ error },
|
|
56
|
-
{ selector, mode, namespace, elements },
|
|
57
|
-
) => {
|
|
58
|
-
const elementsWithSvgsRemoved = elements.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim, "")
|
|
59
|
-
const hasHtml = /<\/html>/.test(elementsWithSvgsRemoved)
|
|
60
|
-
const hasHead = /<\/head>/.test(elementsWithSvgsRemoved)
|
|
61
|
-
const hasBody = /<\/body>/.test(elementsWithSvgsRemoved)
|
|
62
|
-
|
|
63
|
-
const wrapperTag = namespace === "svg" ? "svg" : namespace === "mathml" ? "math" : ""
|
|
64
|
-
const wrappedEls = wrapperTag ? `<${wrapperTag}>${elements}</${wrapperTag}>` : elements
|
|
65
|
-
|
|
66
|
-
const newDocument = new DOMParser().parseFromString(
|
|
67
|
-
hasHtml || hasHead || hasBody ? elements : `<body><template>${wrappedEls}</template></body>`,
|
|
68
|
-
"text/html",
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
let newContent = document.createDocumentFragment()
|
|
72
|
-
if (hasHtml) {
|
|
73
|
-
newContent.appendChild(newDocument.documentElement)
|
|
74
|
-
} else if (hasHead && hasBody) {
|
|
75
|
-
newContent.appendChild(newDocument.head)
|
|
76
|
-
newContent.appendChild(newDocument.body)
|
|
77
|
-
} else if (hasHead) {
|
|
78
|
-
newContent.appendChild(newDocument.head)
|
|
79
|
-
} else if (hasBody) {
|
|
80
|
-
newContent.appendChild(newDocument.body)
|
|
81
|
-
} else if (wrapperTag) {
|
|
82
|
-
const wrapperEl = newDocument.querySelector("template").content.querySelector(wrapperTag)
|
|
83
|
-
for (const child of wrapperEl.childNodes) {
|
|
84
|
-
newContent.appendChild(child)
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
newContent = newDocument.querySelector("template").content
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!selector && (mode === "outer" || mode === "replace")) {
|
|
91
|
-
for (const child of newContent.children) {
|
|
92
|
-
let target
|
|
93
|
-
if (child instanceof HTMLHtmlElement) {
|
|
94
|
-
target = document.documentElement
|
|
95
|
-
} else if (child instanceof HTMLBodyElement) {
|
|
96
|
-
target = document.body
|
|
97
|
-
} else if (child instanceof HTMLHeadElement) {
|
|
98
|
-
target = document.head
|
|
99
|
-
} else {
|
|
100
|
-
target = document.getElementById(child.id)
|
|
101
|
-
if (!target) {
|
|
102
|
-
console.warn(error("PatchElementsNoTargetsFound"), {
|
|
103
|
-
element: { id: child.id },
|
|
104
|
-
})
|
|
105
|
-
continue
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
applyToTargets(mode, child, [target])
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
const targets = document.querySelectorAll(selector)
|
|
113
|
-
if (!targets.length) {
|
|
114
|
-
console.warn(error("PatchElementsNoTargetsFound"), { selector })
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
applyToTargets(mode, newContent, targets)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const scripts = new WeakSet()
|
|
123
|
-
for (const script of document.querySelectorAll("script")) {
|
|
124
|
-
scripts.add(script)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const execute = (target) => {
|
|
128
|
-
const elScripts =
|
|
129
|
-
target instanceof HTMLScriptElement ? [target] : target.querySelectorAll("script")
|
|
130
|
-
for (const old of elScripts) {
|
|
131
|
-
if (!scripts.has(old)) {
|
|
132
|
-
const script = document.createElement("script")
|
|
133
|
-
for (const { name, value } of old.attributes) {
|
|
134
|
-
script.setAttribute(name, value)
|
|
135
|
-
}
|
|
136
|
-
script.text = old.text
|
|
137
|
-
old.replaceWith(script)
|
|
138
|
-
scripts.add(script)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const applyPatchMode = (
|
|
144
|
-
targets,
|
|
145
|
-
element,
|
|
146
|
-
action,
|
|
147
|
-
) => {
|
|
148
|
-
for (const target of targets) {
|
|
149
|
-
const cloned = element.cloneNode(true)
|
|
150
|
-
execute(cloned)
|
|
151
|
-
// @ts-ignore
|
|
152
|
-
target[action](cloned)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const applyToTargets = (
|
|
157
|
-
mode,
|
|
158
|
-
element,
|
|
159
|
-
targets,
|
|
160
|
-
) => {
|
|
161
|
-
switch (mode) {
|
|
162
|
-
case "remove":
|
|
163
|
-
for (const target of targets) {
|
|
164
|
-
target.remove()
|
|
165
|
-
}
|
|
166
|
-
break
|
|
167
|
-
case "outer":
|
|
168
|
-
case "inner":
|
|
169
|
-
for (const target of targets) {
|
|
170
|
-
morph(target, element.cloneNode(true), mode)
|
|
171
|
-
execute(target)
|
|
172
|
-
}
|
|
173
|
-
break
|
|
174
|
-
case "replace":
|
|
175
|
-
applyPatchMode(targets, element, "replaceWith")
|
|
176
|
-
break
|
|
177
|
-
case "prepend":
|
|
178
|
-
case "append":
|
|
179
|
-
case "before":
|
|
180
|
-
case "after":
|
|
181
|
-
applyPatchMode(targets, element, mode)
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const ctxIdMap = new Map()
|
|
186
|
-
const ctxPersistentIds = new Set()
|
|
187
|
-
const oldIdTagNameMap = new Map()
|
|
188
|
-
const duplicateIds = new Set()
|
|
189
|
-
const ctxPantry = document.createElement("div")
|
|
190
|
-
ctxPantry.hidden = true
|
|
191
|
-
|
|
192
|
-
const aliasedIgnoreMorph = aliasify("ignore-morph")
|
|
193
|
-
const aliasedIgnoreMorphAttr = `[${aliasedIgnoreMorph}]`
|
|
194
|
-
const morph = (
|
|
195
|
-
oldElt,
|
|
196
|
-
newContent,
|
|
197
|
-
mode = "outer",
|
|
198
|
-
) => {
|
|
199
|
-
if (
|
|
200
|
-
(isHTMLOrSVG(oldElt) &&
|
|
201
|
-
isHTMLOrSVG(newContent) &&
|
|
202
|
-
(oldElt).hasAttribute(aliasedIgnoreMorph) &&
|
|
203
|
-
(newContent).hasAttribute(aliasedIgnoreMorph)) ||
|
|
204
|
-
oldElt.parentElement?.closest(aliasedIgnoreMorphAttr)
|
|
205
|
-
) {
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const normalizedElt = document.createElement("div")
|
|
210
|
-
normalizedElt.append(newContent)
|
|
211
|
-
document.body.insertAdjacentElement("afterend", ctxPantry)
|
|
212
|
-
|
|
213
|
-
const oldIdElements = oldElt.querySelectorAll("[id]")
|
|
214
|
-
for (const { id, tagName } of oldIdElements) {
|
|
215
|
-
if (oldIdTagNameMap.has(id)) {
|
|
216
|
-
duplicateIds.add(id)
|
|
217
|
-
} else {
|
|
218
|
-
oldIdTagNameMap.set(id, tagName)
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (oldElt instanceof Element && oldElt.id) {
|
|
222
|
-
if (oldIdTagNameMap.has(oldElt.id)) {
|
|
223
|
-
duplicateIds.add(oldElt.id)
|
|
224
|
-
} else {
|
|
225
|
-
oldIdTagNameMap.set(oldElt.id, oldElt.tagName)
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
ctxPersistentIds.clear()
|
|
230
|
-
const newIdElements = normalizedElt.querySelectorAll("[id]")
|
|
231
|
-
for (const { id, tagName } of newIdElements) {
|
|
232
|
-
if (ctxPersistentIds.has(id)) {
|
|
233
|
-
duplicateIds.add(id)
|
|
234
|
-
} else if (oldIdTagNameMap.get(id) === tagName) {
|
|
235
|
-
ctxPersistentIds.add(id)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
for (const id of duplicateIds) {
|
|
240
|
-
ctxPersistentIds.delete(id)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
oldIdTagNameMap.clear()
|
|
244
|
-
duplicateIds.clear()
|
|
245
|
-
ctxIdMap.clear()
|
|
246
|
-
|
|
247
|
-
const parent = mode === "outer" ? oldElt.parentElement : oldElt
|
|
248
|
-
populateIdMapWithTree(parent, oldIdElements)
|
|
249
|
-
populateIdMapWithTree(normalizedElt, newIdElements)
|
|
250
|
-
|
|
251
|
-
morphChildren(parent, normalizedElt, mode === "outer" ? oldElt : null, oldElt.nextSibling)
|
|
252
|
-
|
|
253
|
-
ctxPantry.remove()
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const morphChildren = (
|
|
257
|
-
oldParent,
|
|
258
|
-
newParent,
|
|
259
|
-
insertionPoint = null,
|
|
260
|
-
endPoint = null,
|
|
261
|
-
) => {
|
|
262
|
-
if (oldParent instanceof HTMLTemplateElement && newParent instanceof HTMLTemplateElement) {
|
|
263
|
-
oldParent = oldParent.content
|
|
264
|
-
newParent = newParent.content
|
|
265
|
-
}
|
|
266
|
-
insertionPoint ??= oldParent.firstChild
|
|
267
|
-
|
|
268
|
-
for (const newChild of newParent.childNodes) {
|
|
269
|
-
if (insertionPoint && insertionPoint !== endPoint) {
|
|
270
|
-
const bestMatch = findBestMatch(newChild, insertionPoint, endPoint)
|
|
271
|
-
if (bestMatch) {
|
|
272
|
-
if (bestMatch !== insertionPoint) {
|
|
273
|
-
let cursor = insertionPoint
|
|
274
|
-
while (cursor && cursor !== bestMatch) {
|
|
275
|
-
const tempNode = cursor
|
|
276
|
-
cursor = cursor.nextSibling
|
|
277
|
-
removeNode(tempNode)
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
morphNode(bestMatch, newChild)
|
|
281
|
-
insertionPoint = bestMatch.nextSibling
|
|
282
|
-
continue
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (newChild instanceof Element && ctxPersistentIds.has(newChild.id)) {
|
|
287
|
-
const movedChild = document.getElementById(newChild.id)
|
|
288
|
-
|
|
289
|
-
let current = movedChild
|
|
290
|
-
while ((current = current.parentNode)) {
|
|
291
|
-
const idSet = ctxIdMap.get(current)
|
|
292
|
-
if (idSet) {
|
|
293
|
-
idSet.delete(newChild.id)
|
|
294
|
-
if (!idSet.size) {
|
|
295
|
-
ctxIdMap.delete(current)
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
moveBefore(oldParent, movedChild, insertionPoint)
|
|
301
|
-
morphNode(movedChild, newChild)
|
|
302
|
-
insertionPoint = movedChild.nextSibling
|
|
303
|
-
continue
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if (ctxIdMap.has(newChild)) {
|
|
307
|
-
const namespaceURI = (newChild).namespaceURI
|
|
308
|
-
const tagName = (newChild).tagName
|
|
309
|
-
const newEmptyChild =
|
|
310
|
-
namespaceURI && namespaceURI !== "http://www.w3.org/1999/xhtml"
|
|
311
|
-
? document.createElementNS(namespaceURI, tagName)
|
|
312
|
-
: document.createElement(tagName)
|
|
313
|
-
oldParent.insertBefore(newEmptyChild, insertionPoint)
|
|
314
|
-
morphNode(newEmptyChild, newChild)
|
|
315
|
-
insertionPoint = newEmptyChild.nextSibling
|
|
316
|
-
} else {
|
|
317
|
-
const newClonedChild = document.importNode(newChild, true)
|
|
318
|
-
oldParent.insertBefore(newClonedChild, insertionPoint)
|
|
319
|
-
insertionPoint = newClonedChild.nextSibling
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
while (insertionPoint && insertionPoint !== endPoint) {
|
|
324
|
-
const tempNode = insertionPoint
|
|
325
|
-
insertionPoint = insertionPoint.nextSibling
|
|
326
|
-
removeNode(tempNode)
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const findBestMatch = (node, startPoint, endPoint) => {
|
|
331
|
-
let bestMatch = null
|
|
332
|
-
let nextSibling = node.nextSibling
|
|
333
|
-
let siblingSoftMatchCount = 0
|
|
334
|
-
let displaceMatchCount = 0
|
|
335
|
-
|
|
336
|
-
const nodeMatchCount = ctxIdMap.get(node)?.size || 0
|
|
337
|
-
|
|
338
|
-
let cursor = startPoint
|
|
339
|
-
while (cursor && cursor !== endPoint) {
|
|
340
|
-
if (isSoftMatch(cursor, node)) {
|
|
341
|
-
let isIdSetMatch = false
|
|
342
|
-
const oldSet = ctxIdMap.get(cursor)
|
|
343
|
-
const newSet = ctxIdMap.get(node)
|
|
344
|
-
|
|
345
|
-
if (newSet && oldSet) {
|
|
346
|
-
for (const id of oldSet) {
|
|
347
|
-
if (newSet.has(id)) {
|
|
348
|
-
isIdSetMatch = true
|
|
349
|
-
break
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if (isIdSetMatch) {
|
|
355
|
-
return cursor
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (!bestMatch && !ctxIdMap.has(cursor)) {
|
|
359
|
-
if (!nodeMatchCount) {
|
|
360
|
-
return cursor
|
|
361
|
-
}
|
|
362
|
-
bestMatch = cursor
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
displaceMatchCount += ctxIdMap.get(cursor)?.size || 0
|
|
367
|
-
if (displaceMatchCount > nodeMatchCount) {
|
|
368
|
-
break
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (bestMatch === null && nextSibling && isSoftMatch(cursor, nextSibling)) {
|
|
372
|
-
siblingSoftMatchCount++
|
|
373
|
-
nextSibling = nextSibling.nextSibling
|
|
374
|
-
|
|
375
|
-
if (siblingSoftMatchCount >= 2) {
|
|
376
|
-
bestMatch = undefined
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
cursor = cursor.nextSibling
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return bestMatch || null
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const isSoftMatch = (oldNode, newNode) =>
|
|
387
|
-
oldNode.nodeType === newNode.nodeType &&
|
|
388
|
-
(oldNode).tagName === (newNode).tagName &&
|
|
389
|
-
(!(oldNode).id || (oldNode).id === (newNode).id)
|
|
390
|
-
|
|
391
|
-
const removeNode = (node) => {
|
|
392
|
-
ctxIdMap.has(node) ? moveBefore(ctxPantry, node, null) : node.parentNode?.removeChild(node)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const moveBefore =
|
|
396
|
-
// @ts-expect-error
|
|
397
|
-
removeNode.call.bind(ctxPantry.moveBefore ?? ctxPantry.insertBefore)
|
|
398
|
-
|
|
399
|
-
const aliasedPreserveAttr = aliasify("preserve-attr")
|
|
400
|
-
|
|
401
|
-
const morphNode = (oldNode, newNode) => {
|
|
402
|
-
const type = newNode.nodeType
|
|
403
|
-
|
|
404
|
-
if (type === 1) {
|
|
405
|
-
const oldElt = oldNode
|
|
406
|
-
const newElt = newNode
|
|
407
|
-
const shouldScopeChildren = oldElt.hasAttribute("data-scope-children")
|
|
408
|
-
if (oldElt.hasAttribute(aliasedIgnoreMorph) && newElt.hasAttribute(aliasedIgnoreMorph)) {
|
|
409
|
-
return oldNode
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
oldElt instanceof HTMLInputElement &&
|
|
414
|
-
newElt instanceof HTMLInputElement &&
|
|
415
|
-
newElt.type !== "file"
|
|
416
|
-
) {
|
|
417
|
-
if (newElt.getAttribute("value") !== oldElt.getAttribute("value")) {
|
|
418
|
-
oldElt.value = newElt.getAttribute("value") ?? ""
|
|
419
|
-
}
|
|
420
|
-
} else if (oldElt instanceof HTMLTextAreaElement && newElt instanceof HTMLTextAreaElement) {
|
|
421
|
-
if (newElt.value !== oldElt.value) {
|
|
422
|
-
oldElt.value = newElt.value
|
|
423
|
-
}
|
|
424
|
-
if (oldElt.firstChild && oldElt.firstChild.nodeValue !== newElt.value) {
|
|
425
|
-
oldElt.firstChild.nodeValue = newElt.value
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
const preserveAttrs = ((newNode).getAttribute(aliasedPreserveAttr) ?? "").split(
|
|
430
|
-
" ",
|
|
431
|
-
)
|
|
432
|
-
|
|
433
|
-
for (const { name, value } of newElt.attributes) {
|
|
434
|
-
if (oldElt.getAttribute(name) !== value && !preserveAttrs.includes(name)) {
|
|
435
|
-
oldElt.setAttribute(name, value)
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
for (let i = oldElt.attributes.length - 1; i >= 0; i--) {
|
|
440
|
-
const { name } = oldElt.attributes[i]
|
|
441
|
-
if (!newElt.hasAttribute(name) && !preserveAttrs.includes(name)) {
|
|
442
|
-
oldElt.removeAttribute(name)
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
if (shouldScopeChildren && !oldElt.hasAttribute("data-scope-children")) {
|
|
447
|
-
oldElt.setAttribute("data-scope-children", "")
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (!oldElt.isEqualNode(newElt)) {
|
|
451
|
-
morphChildren(oldElt, newElt)
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
if (shouldScopeChildren) {
|
|
455
|
-
oldElt.dispatchEvent(new CustomEvent("datastar:scope-children", { bubbles: false }))
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if (type === 8 || type === 3) {
|
|
460
|
-
if (oldNode.nodeValue !== newNode.nodeValue) {
|
|
461
|
-
oldNode.nodeValue = newNode.nodeValue
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return oldNode
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
const populateIdMapWithTree = (
|
|
469
|
-
root,
|
|
470
|
-
elements,
|
|
471
|
-
) => {
|
|
472
|
-
for (const elt of elements) {
|
|
473
|
-
if (ctxPersistentIds.has(elt.id)) {
|
|
474
|
-
let current = elt
|
|
475
|
-
while (current && current !== root) {
|
|
476
|
-
let idSet = ctxIdMap.get(current)
|
|
477
|
-
if (!idSet) {
|
|
478
|
-
idSet = new Set()
|
|
479
|
-
ctxIdMap.set(current, idSet)
|
|
480
|
-
}
|
|
481
|
-
idSet.add(elt.id)
|
|
482
|
-
current = current.parentElement
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { mergePatch, watcher } from "../engine.js"
|
|
2
|
-
import { jsStrToObject } from "../utils.js"
|
|
3
|
-
|
|
4
|
-
watcher({
|
|
5
|
-
name: "datastar-patch-signals",
|
|
6
|
-
apply({ error }, { signals, onlyIfMissing }) {
|
|
7
|
-
if (signals) {
|
|
8
|
-
const ifMissing = onlyIfMissing?.trim() === "true"
|
|
9
|
-
mergePatch(jsStrToObject(signals), { ifMissing })
|
|
10
|
-
} else {
|
|
11
|
-
throw error("PatchSignalsExpectedSignals")
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
})
|