@nordcraft/runtime 1.0.10 → 1.0.12
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/custom-element.main.esm.js +27 -27
- package/dist/custom-element.main.esm.js.map +4 -4
- package/dist/editor/drag-drop/dragEnded.js +3 -2
- package/dist/editor/drag-drop/dragEnded.js.map +1 -1
- package/dist/editor/drag-drop/dragReorder.js +6 -4
- package/dist/editor/drag-drop/dragReorder.js.map +1 -1
- package/dist/editor-preview.main.js +6 -7
- package/dist/editor-preview.main.js.map +1 -1
- package/dist/page.main.esm.js +2 -2
- package/dist/page.main.esm.js.map +4 -4
- package/dist/utils/isElementInViewport.d.ts +1 -0
- package/dist/utils/isElementInViewport.js +10 -0
- package/dist/utils/isElementInViewport.js.map +1 -0
- package/package.json +3 -3
- package/src/editor/drag-drop/dragEnded.ts +3 -2
- package/src/editor/drag-drop/dragReorder.ts +6 -4
- package/src/editor-preview.main.ts +11 -12
- package/src/utils/isElementInViewport.ts +17 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isElementInViewport(element: HTMLElement, thresholdPx?: number): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function isElementInViewport(element, thresholdPx = 0) {
|
|
2
|
+
const rect = element.getBoundingClientRect();
|
|
3
|
+
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
4
|
+
const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
5
|
+
return (rect.top >= 0 - thresholdPx &&
|
|
6
|
+
rect.left >= 0 - thresholdPx &&
|
|
7
|
+
rect.bottom <= viewportHeight + thresholdPx &&
|
|
8
|
+
rect.right <= viewportWidth + thresholdPx);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=isElementInViewport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isElementInViewport.js","sourceRoot":"","sources":["../../src/utils/isElementInViewport.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CACjC,OAAoB,EACpB,WAAW,GAAG,CAAC;IAEf,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAA;IAC5C,MAAM,cAAc,GAClB,MAAM,CAAC,WAAW,IAAI,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAA;IAC7D,MAAM,aAAa,GACjB,MAAM,CAAC,UAAU,IAAI,QAAQ,CAAC,eAAe,CAAC,WAAW,CAAA;IAE3D,OAAO,CACL,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,WAAW;QAC3B,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG,WAAW;QAC5B,IAAI,CAAC,MAAM,IAAI,cAAc,GAAG,WAAW;QAC3C,IAAI,CAAC,KAAK,IAAI,aAAa,GAAG,WAAW,CAC1C,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://github.com/nordcraftengine/nordcraft",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@nordcraft/core": "1.0.
|
|
8
|
-
"@nordcraft/std-lib": "1.0.
|
|
7
|
+
"@nordcraft/core": "1.0.12",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.12",
|
|
9
9
|
"fast-deep-equal": "3.1.3",
|
|
10
10
|
"path-to-regexp": "6.3.0"
|
|
11
11
|
},
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"files": ["dist", "src"],
|
|
22
22
|
"main": "dist/page.main.js",
|
|
23
23
|
"types": "dist/page.main.d.ts",
|
|
24
|
-
"version": "1.0.
|
|
24
|
+
"version": "1.0.12"
|
|
25
25
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isElementInViewport } from '../../utils/isElementInViewport'
|
|
1
2
|
import { tryStartViewTransition } from '../../utils/tryStartViewTransition'
|
|
2
3
|
import type { DragState } from '../types'
|
|
3
4
|
import { DRAG_MOVE_CLASSNAME } from './dragMove'
|
|
@@ -18,14 +19,14 @@ export async function dragEnded(dragState: DragState, canceled: boolean) {
|
|
|
18
19
|
'dropped-item-self',
|
|
19
20
|
)
|
|
20
21
|
siblings.forEach((node, i) => {
|
|
21
|
-
if (node instanceof HTMLElement) {
|
|
22
|
+
if (node instanceof HTMLElement && isElementInViewport(node)) {
|
|
22
23
|
node.style.setProperty(
|
|
23
24
|
'view-transition-name',
|
|
24
25
|
'dropped-item-sibling-' + i,
|
|
25
26
|
)
|
|
26
27
|
}
|
|
27
28
|
})
|
|
28
|
-
dragState.repeatedNodes.forEach((node, i) => {
|
|
29
|
+
dragState.repeatedNodes.filter(isElementInViewport).forEach((node, i) => {
|
|
29
30
|
node.style.setProperty('view-transition-name', 'dropped-item-repeated-' + i)
|
|
30
31
|
})
|
|
31
32
|
await tryStartViewTransition(() => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isElementInViewport } from '../../utils/isElementInViewport'
|
|
1
2
|
import { tryStartViewTransition } from '../../utils/tryStartViewTransition'
|
|
2
3
|
import type { DragState } from '../types'
|
|
3
4
|
import { DRAG_MOVE_CLASSNAME } from './dragMove'
|
|
@@ -50,11 +51,12 @@ export function dragReorder(dragState: DragState | null) {
|
|
|
50
51
|
) {
|
|
51
52
|
dragState.isTransitioning = true
|
|
52
53
|
const siblings = Array.from(dragState.initialContainer.childNodes)
|
|
53
|
-
siblings
|
|
54
|
-
|
|
54
|
+
siblings
|
|
55
|
+
.filter((sibling) => sibling instanceof HTMLElement)
|
|
56
|
+
.filter(isElementInViewport)
|
|
57
|
+
.forEach((sibling, i) => {
|
|
55
58
|
sibling.style.setProperty('view-transition-name', 'item-' + i)
|
|
56
|
-
}
|
|
57
|
-
})
|
|
59
|
+
})
|
|
58
60
|
dragState.element.style.setProperty('view-transition-name', '__drag-item')
|
|
59
61
|
|
|
60
62
|
const prevLeft = dragState.element.offsetLeft
|
|
@@ -882,18 +882,17 @@ export const createRoot = (
|
|
|
882
882
|
const styleElem = document.createElement('style')
|
|
883
883
|
styleElem.appendChild(
|
|
884
884
|
document.createTextNode(`
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
`),
|
|
885
|
+
@keyframes preview_timeline {
|
|
886
|
+
${Object.values(keyframes)
|
|
887
|
+
.map(
|
|
888
|
+
({ key, value, position, easing }) =>
|
|
889
|
+
`${position * 100}% {
|
|
890
|
+
${key}: ${value};
|
|
891
|
+
${easing ? `animation-timing-function: ${easing};` : ''}
|
|
892
|
+
}`,
|
|
893
|
+
)
|
|
894
|
+
.join('\n')}
|
|
895
|
+
}`),
|
|
897
896
|
)
|
|
898
897
|
styleElem.setAttribute('data-timeline-keyframes', '')
|
|
899
898
|
document.head.appendChild(styleElem)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function isElementInViewport(
|
|
2
|
+
element: HTMLElement,
|
|
3
|
+
thresholdPx = 0,
|
|
4
|
+
): boolean {
|
|
5
|
+
const rect = element.getBoundingClientRect()
|
|
6
|
+
const viewportHeight =
|
|
7
|
+
window.innerHeight || document.documentElement.clientHeight
|
|
8
|
+
const viewportWidth =
|
|
9
|
+
window.innerWidth || document.documentElement.clientWidth
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
rect.top >= 0 - thresholdPx &&
|
|
13
|
+
rect.left >= 0 - thresholdPx &&
|
|
14
|
+
rect.bottom <= viewportHeight + thresholdPx &&
|
|
15
|
+
rect.right <= viewportWidth + thresholdPx
|
|
16
|
+
)
|
|
17
|
+
}
|