@jsenv/dom 0.8.8 → 0.9.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/dist/jsenv_dom.js +69 -40
- package/package.json +2 -2
package/dist/jsenv_dom.js
CHANGED
|
@@ -104,29 +104,31 @@ const getElementSignature = (element) => {
|
|
|
104
104
|
if (element.nodeType === Node.TEXT_NODE) {
|
|
105
105
|
return `#text(${getElementSignature(element.nodeValue)})`;
|
|
106
106
|
}
|
|
107
|
+
if (element instanceof HTMLElement) {
|
|
108
|
+
const tagName = element.tagName.toLowerCase();
|
|
109
|
+
const dataUIName = element.getAttribute("data-ui-name");
|
|
110
|
+
if (dataUIName) {
|
|
111
|
+
return `${tagName}[data-ui-name="${dataUIName}"]`;
|
|
112
|
+
}
|
|
113
|
+
if (element === document.body) {
|
|
114
|
+
return "<body>";
|
|
115
|
+
}
|
|
116
|
+
if (element === document.documentElement) {
|
|
117
|
+
return "<html>";
|
|
118
|
+
}
|
|
119
|
+
const elementId = element.id;
|
|
120
|
+
if (elementId) {
|
|
121
|
+
return `${tagName}#${elementId}`;
|
|
122
|
+
}
|
|
123
|
+
const className = element.className;
|
|
124
|
+
if (className) {
|
|
125
|
+
return `${tagName}.${className.split(" ").join(".")}`;
|
|
126
|
+
}
|
|
107
127
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (dataUIName) {
|
|
111
|
-
return `${tagName}[data-ui-name="${dataUIName}"]`;
|
|
128
|
+
const parentSignature = getElementSignature(element.parentElement);
|
|
129
|
+
return `${parentSignature} > ${tagName}`;
|
|
112
130
|
}
|
|
113
|
-
|
|
114
|
-
return "<body>";
|
|
115
|
-
}
|
|
116
|
-
if (element === document.documentElement) {
|
|
117
|
-
return "<html>";
|
|
118
|
-
}
|
|
119
|
-
const elementId = element.id;
|
|
120
|
-
if (elementId) {
|
|
121
|
-
return `${tagName}#${elementId}`;
|
|
122
|
-
}
|
|
123
|
-
const className = element.className;
|
|
124
|
-
if (className) {
|
|
125
|
-
return `${tagName}.${className.split(" ").join(".")}`;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const parentSignature = getElementSignature(element.parentElement);
|
|
129
|
-
return `${parentSignature} > ${tagName}`;
|
|
131
|
+
return String(element);
|
|
130
132
|
};
|
|
131
133
|
|
|
132
134
|
const createIterableWeakSet = () => {
|
|
@@ -9991,7 +9993,6 @@ const createTransition = ({
|
|
|
9991
9993
|
`Debug breakpoint hit at ${(breakpoint * 100).toFixed(1)}% progress`,
|
|
9992
9994
|
);
|
|
9993
9995
|
const notifyDebuggerEnd = notifyDebuggerStart();
|
|
9994
|
-
debugger;
|
|
9995
9996
|
notifyDebuggerEnd();
|
|
9996
9997
|
}
|
|
9997
9998
|
if (effect === "pause") {
|
|
@@ -11615,7 +11616,7 @@ const initFlexDetailsSet = (
|
|
|
11615
11616
|
}
|
|
11616
11617
|
};
|
|
11617
11618
|
|
|
11618
|
-
const applyAllocatedSpaces = (
|
|
11619
|
+
const applyAllocatedSpaces = ({ reason, animated }) => {
|
|
11619
11620
|
const changeSet = new Set();
|
|
11620
11621
|
let maxChange = 0;
|
|
11621
11622
|
|
|
@@ -11623,9 +11624,8 @@ const initFlexDetailsSet = (
|
|
|
11623
11624
|
const allocatedSpace = allocatedSpaceMap.get(child);
|
|
11624
11625
|
const allocatedSize = spaceToSize(allocatedSpace, child);
|
|
11625
11626
|
const space = spaceMap.get(child);
|
|
11626
|
-
const size = spaceToSize(space, child);
|
|
11627
|
+
const size = spaceToSize(space === undefined ? 0 : space, child);
|
|
11627
11628
|
const sizeChange = Math.abs(size - allocatedSize);
|
|
11628
|
-
|
|
11629
11629
|
if (size === allocatedSize) {
|
|
11630
11630
|
continue;
|
|
11631
11631
|
}
|
|
@@ -11658,16 +11658,18 @@ const initFlexDetailsSet = (
|
|
|
11658
11658
|
}
|
|
11659
11659
|
|
|
11660
11660
|
// Don't animate if changes are too small (avoids imperceptible animations that hide scrollbars)
|
|
11661
|
-
const shouldAnimate =
|
|
11662
|
-
resizeDetails.animated && maxChange >= ANIMATION_THRESHOLD_PX;
|
|
11661
|
+
const shouldAnimate = animated && maxChange >= ANIMATION_THRESHOLD_PX;
|
|
11663
11662
|
|
|
11664
|
-
if (debug &&
|
|
11663
|
+
if (debug && animated && !shouldAnimate) {
|
|
11665
11664
|
console.debug(
|
|
11666
11665
|
`🚫 Skipping animation: max change ${maxChange.toFixed(2)}px < ${ANIMATION_THRESHOLD_PX}px threshold`,
|
|
11667
11666
|
);
|
|
11668
11667
|
}
|
|
11669
11668
|
|
|
11670
11669
|
if (!shouldAnimate) {
|
|
11670
|
+
if (debug) {
|
|
11671
|
+
console.debug(`Applying size changes without animation`);
|
|
11672
|
+
}
|
|
11671
11673
|
const sizeChangeEntries = [];
|
|
11672
11674
|
for (const { element, target, sideEffect } of changeSet) {
|
|
11673
11675
|
element.style.height = `${target}px`;
|
|
@@ -11677,19 +11679,26 @@ const initFlexDetailsSet = (
|
|
|
11677
11679
|
}
|
|
11678
11680
|
sizeChangeEntries.push({ element, value: target });
|
|
11679
11681
|
}
|
|
11680
|
-
onSizeChange?.(sizeChangeEntries,
|
|
11682
|
+
onSizeChange?.(sizeChangeEntries, { reason, animated });
|
|
11681
11683
|
return;
|
|
11682
11684
|
}
|
|
11683
11685
|
|
|
11686
|
+
if (debug) {
|
|
11687
|
+
console.debug(`Start animating size changes`);
|
|
11688
|
+
}
|
|
11684
11689
|
// Create height animations for each element in changeSet
|
|
11685
11690
|
const transitions = Array.from(changeSet).map(({ element, target }) => {
|
|
11686
11691
|
const transition = createHeightTransition(element, target, {
|
|
11687
11692
|
duration: HEIGHT_TRANSITION_DURATION,
|
|
11693
|
+
// because we also set inline height when we don't want animation and it should win
|
|
11694
|
+
// we could also commit styles for animation or cancel any animation so that when we explicitely set height
|
|
11695
|
+
// sync the transition gets overriden
|
|
11696
|
+
styleSynchronizer: "inline_style",
|
|
11688
11697
|
});
|
|
11689
11698
|
return transition;
|
|
11690
11699
|
});
|
|
11691
11700
|
|
|
11692
|
-
const transition = transitionController.
|
|
11701
|
+
const transition = transitionController.update(transitions, {
|
|
11693
11702
|
onChange: (changeEntries, isLast) => {
|
|
11694
11703
|
// Apply side effects for each animated element
|
|
11695
11704
|
for (const { transition, value } of changeEntries) {
|
|
@@ -11713,7 +11722,7 @@ const initFlexDetailsSet = (
|
|
|
11713
11722
|
);
|
|
11714
11723
|
onSizeChange(
|
|
11715
11724
|
sizeChangeEntries,
|
|
11716
|
-
isLast ? {
|
|
11725
|
+
isLast ? { reason, animated: false } : { reason, animated },
|
|
11717
11726
|
);
|
|
11718
11727
|
}
|
|
11719
11728
|
},
|
|
@@ -11958,23 +11967,23 @@ const initFlexDetailsSet = (
|
|
|
11958
11967
|
}
|
|
11959
11968
|
};
|
|
11960
11969
|
|
|
11961
|
-
const updateSpaceDistribution = (
|
|
11970
|
+
const updateSpaceDistribution = ({ reason, animated }) => {
|
|
11962
11971
|
if (debug) {
|
|
11963
|
-
console.group(`updateSpaceDistribution: ${
|
|
11972
|
+
console.group(`updateSpaceDistribution: ${reason}`);
|
|
11964
11973
|
}
|
|
11965
11974
|
prepareSpaceDistribution();
|
|
11966
|
-
distributeAvailableSpace(
|
|
11975
|
+
distributeAvailableSpace(reason);
|
|
11967
11976
|
distributeRemainingSpace({
|
|
11968
11977
|
childToGrow: openedDetailsArray[openedDetailsArray.length - 1],
|
|
11969
11978
|
childToShrinkFrom: lastChild,
|
|
11970
11979
|
});
|
|
11971
11980
|
if (
|
|
11972
|
-
|
|
11973
|
-
|
|
11981
|
+
reason === "initial_space_distribution" ||
|
|
11982
|
+
reason === "content_change"
|
|
11974
11983
|
) {
|
|
11975
11984
|
spaceMap.clear(); // force to set size at start
|
|
11976
11985
|
}
|
|
11977
|
-
applyAllocatedSpaces(
|
|
11986
|
+
applyAllocatedSpaces({ reason, animated });
|
|
11978
11987
|
saveCurrentSizeAsRequestedSizes();
|
|
11979
11988
|
if (debug) {
|
|
11980
11989
|
console.groupEnd();
|
|
@@ -12015,6 +12024,19 @@ const initFlexDetailsSet = (
|
|
|
12015
12024
|
}
|
|
12016
12025
|
}
|
|
12017
12026
|
if (someNew || someOld) {
|
|
12027
|
+
for (const child of container.children) {
|
|
12028
|
+
if (!child.dispatchEvent) {
|
|
12029
|
+
// ignore text nodes
|
|
12030
|
+
continue;
|
|
12031
|
+
}
|
|
12032
|
+
child.dispatchEvent(
|
|
12033
|
+
new CustomEvent("resizablechange", {
|
|
12034
|
+
detail: {
|
|
12035
|
+
resizable: resizableDetailsIdSet.has(child.id),
|
|
12036
|
+
},
|
|
12037
|
+
}),
|
|
12038
|
+
);
|
|
12039
|
+
}
|
|
12018
12040
|
onResizableDetailsChange?.(resizableDetailsIdSet);
|
|
12019
12041
|
}
|
|
12020
12042
|
};
|
|
@@ -12231,11 +12253,18 @@ const initFlexDetailsSet = (
|
|
|
12231
12253
|
if (currentAllocatedSpaceMap) {
|
|
12232
12254
|
allocatedSpaceMap = currentAllocatedSpaceMap;
|
|
12233
12255
|
saveCurrentSizeAsRequestedSizes({ replaceExistingAttributes: true });
|
|
12234
|
-
|
|
12235
|
-
|
|
12236
|
-
|
|
12256
|
+
for (const [child, allocatedSpace] of allocatedSpaceMap) {
|
|
12257
|
+
const size = spaceToSize(allocatedSpace, child);
|
|
12258
|
+
if (onRequestedSizeChange) {
|
|
12237
12259
|
onRequestedSizeChange(child, size);
|
|
12238
12260
|
}
|
|
12261
|
+
child.dispatchEvent(
|
|
12262
|
+
new CustomEvent("resizeend", {
|
|
12263
|
+
detail: {
|
|
12264
|
+
size,
|
|
12265
|
+
},
|
|
12266
|
+
}),
|
|
12267
|
+
);
|
|
12239
12268
|
}
|
|
12240
12269
|
onMouseResizeEnd?.();
|
|
12241
12270
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/dom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "DOM utilities for writing frontend code",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@jsenv/core": "../../../",
|
|
43
43
|
"@jsenv/navi": "../navi",
|
|
44
44
|
"@jsenv/snapshot": "../../tooling/snapshot",
|
|
45
|
-
"@preact/signals": "2.
|
|
45
|
+
"@preact/signals": "2.8.1",
|
|
46
46
|
"preact": "11.0.0-beta.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|