jails-js 6.6.0 → 6.7.1
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/dist/index.js +63 -23
- package/dist/index.js.map +1 -1
- package/dist/jails.js +1 -1
- package/dist/jails.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +1 -1
- package/src/component.ts +12 -7
- package/src/template-system.ts +4 -0
package/dist/index.js
CHANGED
@@ -109,7 +109,7 @@ var Idiomorph = (function() {
|
|
109
109
|
}
|
110
110
|
const { id: activeElementId, selectionStart, selectionEnd } = activeElement;
|
111
111
|
const results = fn();
|
112
|
-
if (activeElementId && activeElementId !== ((_a = document.activeElement) == null ? void 0 : _a.id)) {
|
112
|
+
if (activeElementId && activeElementId !== ((_a = document.activeElement) == null ? void 0 : _a.getAttribute("id"))) {
|
113
113
|
activeElement = ctx.target.querySelector(`[id="${activeElementId}"]`);
|
114
114
|
activeElement == null ? void 0 : activeElement.focus();
|
115
115
|
}
|
@@ -142,16 +142,22 @@ var Idiomorph = (function() {
|
|
142
142
|
continue;
|
143
143
|
}
|
144
144
|
}
|
145
|
-
if (newChild instanceof Element
|
146
|
-
const
|
147
|
-
|
148
|
-
newChild.id
|
149
|
-
insertionPoint,
|
150
|
-
ctx
|
145
|
+
if (newChild instanceof Element) {
|
146
|
+
const newChildId = (
|
147
|
+
/** @type {String} */
|
148
|
+
newChild.getAttribute("id")
|
151
149
|
);
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
if (ctx.persistentIds.has(newChildId)) {
|
151
|
+
const movedChild = moveBeforeById(
|
152
|
+
oldParent,
|
153
|
+
newChildId,
|
154
|
+
insertionPoint,
|
155
|
+
ctx
|
156
|
+
);
|
157
|
+
morphNode(movedChild, newChild, ctx);
|
158
|
+
insertionPoint = movedChild.nextSibling;
|
159
|
+
continue;
|
160
|
+
}
|
155
161
|
}
|
156
162
|
const insertedNode = createNode(
|
157
163
|
oldParent,
|
@@ -211,7 +217,7 @@ var Idiomorph = (function() {
|
|
211
217
|
softMatch = void 0;
|
212
218
|
}
|
213
219
|
}
|
214
|
-
if (
|
220
|
+
if (ctx.activeElementAndParents.includes(cursor)) break;
|
215
221
|
cursor = cursor.nextSibling;
|
216
222
|
}
|
217
223
|
return softMatch || null;
|
@@ -228,6 +234,7 @@ var Idiomorph = (function() {
|
|
228
234
|
return false;
|
229
235
|
}
|
230
236
|
function isSoftMatch(oldNode, newNode) {
|
237
|
+
var _a, _b, _c;
|
231
238
|
const oldElt = (
|
232
239
|
/** @type {Element} */
|
233
240
|
oldNode
|
@@ -239,7 +246,8 @@ var Idiomorph = (function() {
|
|
239
246
|
return oldElt.nodeType === newElt.nodeType && oldElt.tagName === newElt.tagName && // If oldElt has an `id` with possible state and it doesn't match newElt.id then avoid morphing.
|
240
247
|
// We'll still match an anonymous node with an IDed newElt, though, because if it got this far,
|
241
248
|
// its not persistent, and new nodes can't have any hidden state.
|
242
|
-
|
249
|
+
// We can't use .id because of form input shadowing, and we can't count on .getAttribute's presence because it could be a document-fragment
|
250
|
+
(!((_a = oldElt.getAttribute) == null ? void 0 : _a.call(oldElt, "id")) || ((_b = oldElt.getAttribute) == null ? void 0 : _b.call(oldElt, "id")) === ((_c = newElt.getAttribute) == null ? void 0 : _c.call(newElt, "id")));
|
243
251
|
}
|
244
252
|
return findBestMatch2;
|
245
253
|
})();
|
@@ -266,16 +274,22 @@ var Idiomorph = (function() {
|
|
266
274
|
return cursor;
|
267
275
|
}
|
268
276
|
function moveBeforeById(parentNode, id, after, ctx) {
|
277
|
+
var _a, _b;
|
269
278
|
const target = (
|
270
279
|
/** @type {Element} - will always be found */
|
271
|
-
ctx.target.id
|
280
|
+
// ctx.target.id unsafe because of form input shadowing
|
281
|
+
// ctx.target could be a document fragment which doesn't have `getAttribute`
|
282
|
+
((_b = (_a = ctx.target).getAttribute) == null ? void 0 : _b.call(_a, "id")) === id && ctx.target || ctx.target.querySelector(`[id="${id}"]`) || ctx.pantry.querySelector(`[id="${id}"]`)
|
272
283
|
);
|
273
284
|
removeElementFromAncestorsIdMaps(target, ctx);
|
274
285
|
moveBefore(parentNode, target, after);
|
275
286
|
return target;
|
276
287
|
}
|
277
288
|
function removeElementFromAncestorsIdMaps(element, ctx) {
|
278
|
-
const id =
|
289
|
+
const id = (
|
290
|
+
/** @type {String} */
|
291
|
+
element.getAttribute("id")
|
292
|
+
);
|
279
293
|
while (element = element.parentNode) {
|
280
294
|
let idSet = ctx.idMap.get(element);
|
281
295
|
if (idSet) {
|
@@ -539,6 +553,7 @@ var Idiomorph = (function() {
|
|
539
553
|
idMap,
|
540
554
|
persistentIds,
|
541
555
|
pantry: createPantry(),
|
556
|
+
activeElementAndParents: createActiveElementAndParents(oldNode),
|
542
557
|
callbacks: mergedConfig.callbacks,
|
543
558
|
head: mergedConfig.head
|
544
559
|
};
|
@@ -560,16 +575,33 @@ var Idiomorph = (function() {
|
|
560
575
|
document.body.insertAdjacentElement("afterend", pantry);
|
561
576
|
return pantry;
|
562
577
|
}
|
578
|
+
function createActiveElementAndParents(oldNode) {
|
579
|
+
let activeElementAndParents = [];
|
580
|
+
let elt = document.activeElement;
|
581
|
+
if ((elt == null ? void 0 : elt.tagName) !== "BODY" && oldNode.contains(elt)) {
|
582
|
+
while (elt) {
|
583
|
+
activeElementAndParents.push(elt);
|
584
|
+
if (elt === oldNode) break;
|
585
|
+
elt = elt.parentElement;
|
586
|
+
}
|
587
|
+
}
|
588
|
+
return activeElementAndParents;
|
589
|
+
}
|
563
590
|
function findIdElements(root) {
|
591
|
+
var _a;
|
564
592
|
let elements = Array.from(root.querySelectorAll("[id]"));
|
565
|
-
if (root.id) {
|
593
|
+
if ((_a = root.getAttribute) == null ? void 0 : _a.call(root, "id")) {
|
566
594
|
elements.push(root);
|
567
595
|
}
|
568
596
|
return elements;
|
569
597
|
}
|
570
598
|
function populateIdMapWithTree(idMap, persistentIds, root, elements) {
|
571
599
|
for (const elt of elements) {
|
572
|
-
|
600
|
+
const id = (
|
601
|
+
/** @type {String} */
|
602
|
+
elt.getAttribute("id")
|
603
|
+
);
|
604
|
+
if (persistentIds.has(id)) {
|
573
605
|
let current = elt;
|
574
606
|
while (current) {
|
575
607
|
let idSet = idMap.get(current);
|
@@ -577,7 +609,7 @@ var Idiomorph = (function() {
|
|
577
609
|
idSet = /* @__PURE__ */ new Set();
|
578
610
|
idMap.set(current, idSet);
|
579
611
|
}
|
580
|
-
idSet.add(
|
612
|
+
idSet.add(id);
|
581
613
|
if (current === root) break;
|
582
614
|
current = current.parentElement;
|
583
615
|
}
|
@@ -795,7 +827,7 @@ const Component = ({ name, module, dependencies, node, templates: templates2, si
|
|
795
827
|
const scopeid = node.getAttribute("html-scopeid");
|
796
828
|
const tpl = templates2[tplid];
|
797
829
|
const scope = g.scope[scopeid];
|
798
|
-
const model = dup(((_a = module == null ? void 0 : module.model) == null ? void 0 : _a.apply) ? _model({ elm: node, initialState }) : _model);
|
830
|
+
const model = dup(((_a = module == null ? void 0 : module.model) == null ? void 0 : _a.apply) ? _model({ elm: node, initialState, dependencies }) : _model);
|
799
831
|
const state = Object.assign({}, scope, model, initialState);
|
800
832
|
const view = module.view ? module.view : (data) => data;
|
801
833
|
const base = {
|
@@ -974,18 +1006,19 @@ const Component = ({ name, module, dependencies, node, templates: templates2, si
|
|
974
1006
|
Promise.resolve().then(() => {
|
975
1007
|
node.querySelectorAll("[tplid]").forEach((element) => {
|
976
1008
|
const child = register2.get(element);
|
1009
|
+
const scope2 = __spreadValues({}, child.__scope__);
|
977
1010
|
if (!child) return;
|
978
1011
|
child.state.protected().forEach((key) => delete data[key]);
|
979
1012
|
const useEffect = child.effect();
|
980
1013
|
if (useEffect) {
|
981
1014
|
const promise = useEffect(data);
|
982
1015
|
if (promise && promise.then) {
|
983
|
-
promise.then(() => child.state.set(data));
|
1016
|
+
promise.then(() => child.state.set(__spreadValues(__spreadValues({}, data), scope2)));
|
984
1017
|
} else {
|
985
|
-
child.state.set(data);
|
1018
|
+
child.state.set(__spreadValues(__spreadValues({}, data), scope2));
|
986
1019
|
}
|
987
1020
|
} else {
|
988
|
-
child.state.set(data);
|
1021
|
+
child.state.set(__spreadValues(__spreadValues({}, data), scope2));
|
989
1022
|
}
|
990
1023
|
});
|
991
1024
|
Promise.resolve().then(() => {
|
@@ -999,14 +1032,18 @@ const Component = ({ name, module, dependencies, node, templates: templates2, si
|
|
999
1032
|
register2.set(node, base);
|
1000
1033
|
return module.default(base);
|
1001
1034
|
};
|
1002
|
-
const IdiomorphOptions = (parent, register2) => ({
|
1035
|
+
const IdiomorphOptions = (parent, register2, data) => ({
|
1003
1036
|
callbacks: {
|
1004
|
-
beforeNodeMorphed(node) {
|
1037
|
+
beforeNodeMorphed(node, newnode) {
|
1005
1038
|
if (node.nodeType === 1) {
|
1006
1039
|
if ("html-static" in node.attributes) {
|
1007
1040
|
return false;
|
1008
1041
|
}
|
1009
1042
|
if (register2.get(node) && node !== parent) {
|
1043
|
+
const scopeid = newnode.getAttribute("html-scopeid");
|
1044
|
+
const scope = g.scope[scopeid];
|
1045
|
+
const base = register2.get(node);
|
1046
|
+
base.__scope__ = scope;
|
1010
1047
|
return false;
|
1011
1048
|
}
|
1012
1049
|
}
|
@@ -1113,6 +1150,9 @@ const transformTemplate = (clone) => {
|
|
1113
1150
|
const htmlClass = element.getAttribute("html-class");
|
1114
1151
|
if (htmlFor) {
|
1115
1152
|
element.removeAttribute("html-for");
|
1153
|
+
if (!element.id) {
|
1154
|
+
element.setAttribute("id", "jails___scope-id");
|
1155
|
+
}
|
1116
1156
|
const split = htmlFor.match(/(.*)\sin\s(.*)/) || "";
|
1117
1157
|
const varname = split[1];
|
1118
1158
|
const object = split[2];
|