@solidtv/solid 1.1.0 → 1.1.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/jsx-runtime.d.ts +0 -1
- package/dist/src/core/config.js.map +1 -1
- package/dist/src/core/dom-renderer/domRenderer.js +36 -36
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererUtils.js +2 -2
- package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
- package/dist/src/core/elementNode.d.ts +19 -14
- package/dist/src/core/elementNode.js +42 -7
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/flex.js +1 -1
- package/dist/src/core/flex.js.map +1 -1
- package/dist/src/core/flexLayout.js +5 -9
- package/dist/src/core/flexLayout.js.map +1 -1
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/nodeTypes.d.ts +1 -1
- package/dist/src/core/nodeTypes.js.map +1 -1
- package/dist/src/core/shaders.js +1 -1
- package/dist/src/core/shaders.js.map +1 -1
- package/dist/src/core/states.js.map +1 -1
- package/dist/src/core/utils.js +2 -1
- package/dist/src/core/utils.js.map +1 -1
- package/dist/src/devtools/index.js +2 -2
- package/dist/src/devtools/index.js.map +1 -1
- package/dist/src/primitives/Grid.jsx.map +1 -1
- package/dist/src/primitives/Image.jsx.map +1 -1
- package/dist/src/primitives/KeepAlive.jsx.map +1 -1
- package/dist/src/primitives/Lazy.d.ts +16 -0
- package/dist/src/primitives/Lazy.jsx +82 -38
- package/dist/src/primitives/Lazy.jsx.map +1 -1
- package/dist/src/primitives/LazyImport.js +14 -11
- package/dist/src/primitives/LazyImport.js.map +1 -1
- package/dist/src/primitives/Marquee.jsx +3 -3
- package/dist/src/primitives/Marquee.jsx.map +1 -1
- package/dist/src/primitives/Preserve.jsx +1 -1
- package/dist/src/primitives/Preserve.jsx.map +1 -1
- package/dist/src/primitives/Suspense.jsx +1 -1
- package/dist/src/primitives/Suspense.jsx.map +1 -1
- package/dist/src/primitives/Virtual.jsx +6 -5
- package/dist/src/primitives/Virtual.jsx.map +1 -1
- package/dist/src/primitives/borderBox.jsx.map +1 -1
- package/dist/src/primitives/useMouse.js +72 -82
- package/dist/src/primitives/useMouse.js.map +1 -1
- package/dist/src/primitives/utils/createSpriteMap.js.map +1 -1
- package/dist/src/solidOpts.js +1 -1
- package/dist/src/solidOpts.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jsx-runtime.d.ts +0 -1
- package/package.json +2 -1
- package/src/core/config.ts +2 -0
- package/src/core/dom-renderer/domRenderer.ts +46 -46
- package/src/core/dom-renderer/domRendererUtils.ts +2 -2
- package/src/core/elementNode.ts +50 -20
- package/src/core/flex.ts +3 -3
- package/src/core/flexLayout.ts +7 -11
- package/src/core/focusManager.ts +1 -1
- package/src/core/nodeTypes.ts +1 -1
- package/src/core/shaders.ts +1 -1
- package/src/core/states.ts +2 -2
- package/src/core/utils.ts +2 -1
- package/src/devtools/index.ts +2 -2
- package/src/primitives/Grid.tsx +1 -1
- package/src/primitives/Image.tsx +1 -1
- package/src/primitives/KeepAlive.tsx +2 -2
- package/src/primitives/Lazy.tsx +106 -37
- package/src/primitives/LazyImport.ts +5 -4
- package/src/primitives/Marquee.tsx +3 -3
- package/src/primitives/Preserve.tsx +1 -1
- package/src/primitives/Suspense.tsx +1 -1
- package/src/primitives/Virtual.tsx +8 -7
- package/src/primitives/borderBox.tsx +1 -1
- package/src/primitives/useMouse.ts +94 -125
- package/src/primitives/utils/createSpriteMap.ts +1 -1
- package/src/solidOpts.ts +1 -1
package/src/primitives/Lazy.tsx
CHANGED
|
@@ -4,15 +4,51 @@ import * as s from 'solid-js';
|
|
|
4
4
|
|
|
5
5
|
type LazyProps<T extends readonly any[]> = lng.NewOmit<lng.NodeProps, 'children'> & {
|
|
6
6
|
each: T | undefined | null | false;
|
|
7
|
+
|
|
8
|
+
/** Initial visible item count before user navigation. */
|
|
7
9
|
upCount: number;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Items to keep rendered ahead of the current selection. When selection
|
|
13
|
+
* moves within this distance of the rendered edge, the next item is
|
|
14
|
+
* scheduled to mount. Default depends on the scroll mode.
|
|
15
|
+
*/
|
|
8
16
|
buffer?: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Milliseconds to wait after a navigation key press before mounting the
|
|
20
|
+
* next item. Should match the scroll animation duration — mounting items
|
|
21
|
+
* mid-animation causes jank. If the user presses again before this timer
|
|
22
|
+
* fires (faster than the animation), an item is added synchronously to
|
|
23
|
+
* keep the rendered window ahead of selection.
|
|
24
|
+
*/
|
|
9
25
|
delay?: number;
|
|
26
|
+
|
|
27
|
+
/** Render `upCount` items synchronously on mount instead of ramping up. */
|
|
10
28
|
sync?: boolean;
|
|
29
|
+
|
|
30
|
+
/** Continue mounting items in the background past `upCount`. */
|
|
11
31
|
eagerLoad?: boolean;
|
|
32
|
+
|
|
33
|
+
/** Skip refocusing the container when `each.length` changes. */
|
|
12
34
|
noRefocus?: boolean;
|
|
35
|
+
|
|
13
36
|
children: (item: s.Accessor<T[number]>, index: number) => s.JSX.Element;
|
|
14
37
|
};
|
|
15
38
|
|
|
39
|
+
// Lifecycle when props.each changes:
|
|
40
|
+
// 1. items memo invalidates → <Index> reconciles → new ElementNodes mounted (sync)
|
|
41
|
+
// 2. refocus effect runs (microtask) → calls viewRef.setFocus()
|
|
42
|
+
// 3. setFocus queues runPostMutation
|
|
43
|
+
// 4. post-mutation: delete-flush → layout → setActiveElement
|
|
44
|
+
// Children are always mounted before focus is applied; do not wrap setFocus
|
|
45
|
+
// in queueMicrotask — it only adds a redundant defer.
|
|
46
|
+
//
|
|
47
|
+
// Navigation key handler (updateOffset):
|
|
48
|
+
// - On each onRight/onDown, if selection is within `buffer` of the rendered
|
|
49
|
+
// edge, mount one more item. With `delay` set, the mount is deferred until
|
|
50
|
+
// the scroll animation completes so it doesn't drop a frame mid-animation.
|
|
51
|
+
// If the user out-paces `delay`, the mount fires synchronously instead.
|
|
16
52
|
function createLazy<T>(
|
|
17
53
|
component: s.ValidComponent,
|
|
18
54
|
props: LazyProps<readonly T[]>,
|
|
@@ -20,9 +56,17 @@ function createLazy<T>(
|
|
|
20
56
|
) {
|
|
21
57
|
// Need at least one item so it can be focused
|
|
22
58
|
const [offset, setOffset] = s.createSignal<number>(props.sync ? props.upCount : 0);
|
|
23
|
-
let
|
|
59
|
+
let preloadTimer: ReturnType<typeof setTimeout> | null = null;
|
|
60
|
+
let navDelayTimer: ReturnType<typeof setTimeout> | null = null;
|
|
61
|
+
let disposed = false;
|
|
24
62
|
let viewRef!: lngp.NavigableElement;
|
|
25
|
-
let itemLength
|
|
63
|
+
let itemLength = 0;
|
|
64
|
+
|
|
65
|
+
s.onCleanup(() => {
|
|
66
|
+
disposed = true;
|
|
67
|
+
if (preloadTimer) clearTimeout(preloadTimer);
|
|
68
|
+
if (navDelayTimer) clearTimeout(navDelayTimer);
|
|
69
|
+
});
|
|
26
70
|
|
|
27
71
|
const buffer = s.createMemo(() => {
|
|
28
72
|
if (typeof props.buffer === 'number') {
|
|
@@ -44,39 +88,54 @@ function createLazy<T>(
|
|
|
44
88
|
|
|
45
89
|
if (!props.sync || props.eagerLoad) {
|
|
46
90
|
s.createEffect(() => {
|
|
47
|
-
if (props.each)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
count++;
|
|
54
|
-
} else if (props.eagerLoad) {
|
|
55
|
-
const maxOffset = props.each ? props.each.length : 0;
|
|
56
|
-
if (count >= maxOffset) return;
|
|
57
|
-
setOffset((prev) => Math.min(prev + 1, maxOffset));
|
|
58
|
-
lng.scheduleTask(loadItems);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
loadItems();
|
|
91
|
+
if (!props.each) return;
|
|
92
|
+
// Cancel any in-flight preload chain from a prior effect run before
|
|
93
|
+
// starting a new one — otherwise two chains share state and race.
|
|
94
|
+
if (preloadTimer) {
|
|
95
|
+
clearTimeout(preloadTimer);
|
|
96
|
+
preloadTimer = null;
|
|
62
97
|
}
|
|
98
|
+
const loadItems = () => {
|
|
99
|
+
if (disposed) return;
|
|
100
|
+
const count = s.untrack(offset);
|
|
101
|
+
if (count < props.upCount) {
|
|
102
|
+
setOffset(count + 1);
|
|
103
|
+
preloadTimer = setTimeout(loadItems, 16); // ~60fps
|
|
104
|
+
} else if (props.eagerLoad) {
|
|
105
|
+
const maxOffset = props.each ? props.each.length : 0;
|
|
106
|
+
if (count >= maxOffset) return;
|
|
107
|
+
setOffset((prev) => Math.min(prev + 1, maxOffset));
|
|
108
|
+
lng.scheduleTask(loadItems);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
loadItems();
|
|
63
112
|
});
|
|
64
113
|
}
|
|
65
114
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
115
|
+
// Refocus when each.length changes. Side effect kept out of the items memo
|
|
116
|
+
// (memos must be pure — Solid may skip evaluation when there are no readers).
|
|
117
|
+
s.createEffect(() => {
|
|
118
|
+
if (!Array.isArray(props.each)) {
|
|
119
|
+
itemLength = 0;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const len = props.each.length;
|
|
123
|
+
if (itemLength !== len) {
|
|
124
|
+
itemLength = len;
|
|
125
|
+
if (viewRef && !viewRef.noRefocus && lng.hasFocus(viewRef)) {
|
|
126
|
+
// Clamp selected so a shrunk list doesn't refocus a disposed index.
|
|
127
|
+
if (typeof viewRef.selected === 'number' && viewRef.selected >= len) {
|
|
128
|
+
viewRef.selected = Math.max(0, len - 1);
|
|
72
129
|
}
|
|
130
|
+
viewRef.setFocus();
|
|
73
131
|
}
|
|
74
|
-
return props.each.slice(0, offset());
|
|
75
132
|
}
|
|
76
|
-
itemLength = 0;
|
|
77
|
-
return [];
|
|
78
133
|
});
|
|
79
134
|
|
|
135
|
+
const items: s.Accessor<T[]> = s.createMemo(() =>
|
|
136
|
+
Array.isArray(props.each) ? props.each.slice(0, offset()) : [],
|
|
137
|
+
);
|
|
138
|
+
|
|
80
139
|
function lazyScrollToIndex(this: lngp.NavigableElement, index: number) {
|
|
81
140
|
setOffset(Math.max(index, 0) + buffer())
|
|
82
141
|
queueMicrotask(() => viewRef.scrollToIndex(index));
|
|
@@ -85,24 +144,34 @@ function createLazy<T>(
|
|
|
85
144
|
const updateOffset = (_event: KeyboardEvent, container: lng.ElementNode) => {
|
|
86
145
|
const maxOffset = props.each ? props.each.length : 0;
|
|
87
146
|
const selected = container.selected || 0;
|
|
88
|
-
const
|
|
89
|
-
|
|
147
|
+
const rendered = offset(); // == container.children.length
|
|
148
|
+
|
|
149
|
+
// Already mounted everything, or still far enough from the rendered edge
|
|
150
|
+
// that the buffer covers the next selection — no work to do.
|
|
151
|
+
if (rendered >= maxOffset || selected < rendered - buffer()) return;
|
|
152
|
+
|
|
153
|
+
const bump = () => setOffset((prev) => Math.min(prev + 1, maxOffset));
|
|
90
154
|
|
|
155
|
+
// No animation to hide behind — mount immediately.
|
|
91
156
|
if (!props.delay) {
|
|
92
|
-
|
|
157
|
+
bump();
|
|
93
158
|
return;
|
|
94
159
|
}
|
|
95
160
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
161
|
+
// A delayed mount from the previous press hasn't fired yet, which means
|
|
162
|
+
// the user is navigating faster than the scroll animation. Drop the wait
|
|
163
|
+
// (we can't smooth a frame the user is already past) and mount now.
|
|
164
|
+
if (navDelayTimer) {
|
|
165
|
+
clearTimeout(navDelayTimer);
|
|
166
|
+
bump();
|
|
100
167
|
}
|
|
101
168
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
169
|
+
// Schedule the trailing mount to land after the scroll animation completes,
|
|
170
|
+
// so a single item mount doesn't jank the in-flight animation.
|
|
171
|
+
navDelayTimer = setTimeout(() => {
|
|
172
|
+
bump();
|
|
173
|
+
navDelayTimer = null;
|
|
174
|
+
}, props.delay);
|
|
106
175
|
};
|
|
107
176
|
|
|
108
177
|
const handler = keyHandler(updateOffset);
|
|
@@ -34,8 +34,9 @@ export function lazy<T extends Component<any>>(
|
|
|
34
34
|
comp = s;
|
|
35
35
|
}
|
|
36
36
|
let Comp: T | undefined;
|
|
37
|
-
return createMemo(() =>
|
|
38
|
-
|
|
37
|
+
return createMemo(() => {
|
|
38
|
+
Comp = comp();
|
|
39
|
+
return Comp
|
|
39
40
|
? untrack(() => {
|
|
40
41
|
if (!ctx || sharedConfig.done) return Comp!(props);
|
|
41
42
|
const c = sharedConfig.context;
|
|
@@ -44,8 +45,8 @@ export function lazy<T extends Component<any>>(
|
|
|
44
45
|
sharedConfig.context = c;
|
|
45
46
|
return r;
|
|
46
47
|
})
|
|
47
|
-
: null
|
|
48
|
-
) as unknown as JSX.Element;
|
|
48
|
+
: null;
|
|
49
|
+
}) as unknown as JSX.Element;
|
|
49
50
|
}) as T;
|
|
50
51
|
wrap.preload = () =>
|
|
51
52
|
p || ((p = fn()).then((mod) => (comp = () => mod.default)), p);
|
|
@@ -69,7 +69,7 @@ export function MarqueeText(props: MarqueeTextProps) {
|
|
|
69
69
|
s.createEffect(() => {
|
|
70
70
|
if (shouldScroll()) {
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
const options: lng.AnimationSettings = {
|
|
73
73
|
duration: (textWidth() + scrollGap()) / speed() * 1000,
|
|
74
74
|
delay: delay(),
|
|
75
75
|
loop: true,
|
|
@@ -79,8 +79,8 @@ export function MarqueeText(props: MarqueeTextProps) {
|
|
|
79
79
|
text1.lng.x = 0
|
|
80
80
|
text2.lng.x = textWidth() + scrollGap()
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const a1 = text1.lng.animate!({x: -textWidth() -scrollGap()}, options).start()
|
|
83
|
+
const a2 = text2.lng.animate!({x: 0}, options).start()
|
|
84
84
|
|
|
85
85
|
s.onCleanup(() => {
|
|
86
86
|
a1.stop()
|
|
@@ -247,7 +247,7 @@ function createVirtual<T>(
|
|
|
247
247
|
}
|
|
248
248
|
break;
|
|
249
249
|
|
|
250
|
-
case 'edge':
|
|
250
|
+
case 'edge': {
|
|
251
251
|
const startScrolling = Math.max(
|
|
252
252
|
1,
|
|
253
253
|
props.displaySize + (atStart ? -1 : 0),
|
|
@@ -316,6 +316,7 @@ function createVirtual<T>(
|
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
break;
|
|
319
|
+
}
|
|
319
320
|
|
|
320
321
|
case 'none':
|
|
321
322
|
default:
|
|
@@ -396,18 +397,18 @@ function createVirtual<T>(
|
|
|
396
397
|
_active,
|
|
397
398
|
_lastIdx,
|
|
398
399
|
) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
const idx = _idx;
|
|
401
|
+
const lastIdx = _lastIdx || 0;
|
|
402
|
+
const active = _active;
|
|
402
403
|
const noChange = idx === lastIdx;
|
|
403
404
|
const total = itemCount();
|
|
404
405
|
originalPosition = originalPosition ?? elm[axis];
|
|
405
406
|
|
|
406
407
|
if (props.onSelectedChanged) {
|
|
407
408
|
props.onSelectedChanged.call(
|
|
408
|
-
this
|
|
409
|
+
this,
|
|
409
410
|
idx,
|
|
410
|
-
this
|
|
411
|
+
this,
|
|
411
412
|
active,
|
|
412
413
|
lastIdx,
|
|
413
414
|
);
|
|
@@ -480,7 +481,7 @@ function createVirtual<T>(
|
|
|
480
481
|
|
|
481
482
|
queueMicrotask(() => {
|
|
482
483
|
viewRef.updateLayout();
|
|
483
|
-
|
|
484
|
+
const activeIndex = viewRef.children.findIndex((x) => x.item === item);
|
|
484
485
|
if (activeIndex === -1) return;
|
|
485
486
|
viewRef.selected = activeIndex;
|
|
486
487
|
if (lng.hasFocus(viewRef)) {
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
activeElement,
|
|
6
6
|
isElementNode,
|
|
7
7
|
isFunc,
|
|
8
|
-
isTextNode,
|
|
9
8
|
rootNode,
|
|
10
9
|
} from '../index.js';
|
|
11
10
|
import { makeEventListener } from '@solid-primitives/event-listener';
|
|
@@ -88,41 +87,39 @@ function findElementWithCustomState<TApp extends ElementNode>(
|
|
|
88
87
|
y: number,
|
|
89
88
|
customState: CustomState,
|
|
90
89
|
): ElementNode | undefined {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let element: ElementNode | undefined = result[result.length - 1];
|
|
100
|
-
|
|
101
|
-
while (element) {
|
|
102
|
-
const elmParent = element.parent;
|
|
103
|
-
if (elmParent?.forwardStates && hasCustomState(elmParent, customState)) {
|
|
104
|
-
element = elmParent;
|
|
105
|
-
} else {
|
|
90
|
+
const path = getChildrenByPosition(myApp, x, y);
|
|
91
|
+
let element: ElementNode | undefined;
|
|
92
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
93
|
+
if (hasCustomState(path[i]!, customState)) {
|
|
94
|
+
element = path[i];
|
|
106
95
|
break;
|
|
107
96
|
}
|
|
108
97
|
}
|
|
98
|
+
if (!element) return undefined;
|
|
109
99
|
|
|
100
|
+
let p = element.parent;
|
|
101
|
+
while (p?.forwardStates && hasCustomState(p, customState)) {
|
|
102
|
+
element = p;
|
|
103
|
+
p = p.parent;
|
|
104
|
+
}
|
|
110
105
|
return element;
|
|
111
106
|
}
|
|
112
107
|
|
|
113
108
|
function findElementByActiveElement(e: MouseEvent): ElementNode | null {
|
|
114
109
|
const active = activeElement();
|
|
115
110
|
const precision = Config.rendererOptions?.deviceLogicalPixelRatio || 1;
|
|
111
|
+
const px = e.clientX / precision;
|
|
112
|
+
const py = e.clientY / precision;
|
|
116
113
|
|
|
117
114
|
if (
|
|
118
115
|
active instanceof ElementNode &&
|
|
119
116
|
testCollision(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
(
|
|
123
|
-
(
|
|
124
|
-
|
|
125
|
-
|
|
117
|
+
px,
|
|
118
|
+
py,
|
|
119
|
+
(active.lng.absX as number) || 0,
|
|
120
|
+
(active.lng.absY as number) || 0,
|
|
121
|
+
active.width || 0,
|
|
122
|
+
active.height || 0,
|
|
126
123
|
)
|
|
127
124
|
) {
|
|
128
125
|
return active;
|
|
@@ -132,14 +129,13 @@ function findElementByActiveElement(e: MouseEvent): ElementNode | null {
|
|
|
132
129
|
while (parent) {
|
|
133
130
|
if (
|
|
134
131
|
isFunc(parent.onMouseClick) &&
|
|
135
|
-
active &&
|
|
136
132
|
testCollision(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
(
|
|
140
|
-
(
|
|
141
|
-
|
|
142
|
-
|
|
133
|
+
px,
|
|
134
|
+
py,
|
|
135
|
+
(parent.lng.absX as number) || 0,
|
|
136
|
+
(parent.lng.absY as number) || 0,
|
|
137
|
+
parent.width || 0,
|
|
138
|
+
parent.height || 0,
|
|
143
139
|
)
|
|
144
140
|
) {
|
|
145
141
|
return parent;
|
|
@@ -256,7 +252,6 @@ function isNodeAtPosition(
|
|
|
256
252
|
node: ElementNode | ElementText | TextNode,
|
|
257
253
|
x: number,
|
|
258
254
|
y: number,
|
|
259
|
-
precision: number,
|
|
260
255
|
): node is ElementNode {
|
|
261
256
|
if (!isElementNode(node)) {
|
|
262
257
|
return false;
|
|
@@ -268,37 +263,14 @@ function isNodeAtPosition(
|
|
|
268
263
|
testCollision(
|
|
269
264
|
x,
|
|
270
265
|
y,
|
|
271
|
-
(
|
|
272
|
-
(
|
|
273
|
-
|
|
274
|
-
|
|
266
|
+
(node.lng.absX as number) || 0,
|
|
267
|
+
(node.lng.absY as number) || 0,
|
|
268
|
+
node.width || 0,
|
|
269
|
+
node.height || 0,
|
|
275
270
|
)
|
|
276
271
|
);
|
|
277
272
|
}
|
|
278
273
|
|
|
279
|
-
function findHighestZIndexNode(nodes: ElementNode[]): ElementNode | undefined {
|
|
280
|
-
if (nodes.length === 0) {
|
|
281
|
-
return undefined;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (nodes.length === 1) {
|
|
285
|
-
return nodes[0];
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
let maxZIndex = -1;
|
|
289
|
-
let highestNode: ElementNode | undefined = undefined;
|
|
290
|
-
|
|
291
|
-
for (const node of nodes) {
|
|
292
|
-
const zIndex = node.zIndex ?? -1;
|
|
293
|
-
if (zIndex >= maxZIndex) {
|
|
294
|
-
maxZIndex = zIndex;
|
|
295
|
-
highestNode = node;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return highestNode;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
274
|
function getChildrenByPosition<TElement extends ElementNode = ElementNode>(
|
|
303
275
|
node: TElement,
|
|
304
276
|
x: number,
|
|
@@ -306,28 +278,25 @@ function getChildrenByPosition<TElement extends ElementNode = ElementNode>(
|
|
|
306
278
|
): TElement[] {
|
|
307
279
|
const result: TElement[] = [];
|
|
308
280
|
const precision = Config.rendererOptions?.deviceLogicalPixelRatio || 1;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
while (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (!highestZIndexNode || isTextNode(highestZIndexNode)) {
|
|
326
|
-
break;
|
|
281
|
+
const px = x / precision;
|
|
282
|
+
const py = y / precision;
|
|
283
|
+
|
|
284
|
+
let current: ElementNode | ElementText | TextNode | undefined = node;
|
|
285
|
+
while (current && isNodeAtPosition(current, px, py)) {
|
|
286
|
+
result.push(current as TElement);
|
|
287
|
+
|
|
288
|
+
let best: ElementNode | undefined;
|
|
289
|
+
let bestZ = -Infinity;
|
|
290
|
+
for (const child of current.children) {
|
|
291
|
+
if (!isNodeAtPosition(child, px, py)) continue;
|
|
292
|
+
const z = child.zIndex ?? -1;
|
|
293
|
+
if (z >= bestZ) {
|
|
294
|
+
bestZ = z;
|
|
295
|
+
best = child;
|
|
296
|
+
}
|
|
327
297
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
queue = highestZIndexNode.children;
|
|
298
|
+
if (!best) break;
|
|
299
|
+
current = best;
|
|
331
300
|
}
|
|
332
301
|
|
|
333
302
|
return result;
|
|
@@ -358,60 +327,60 @@ export function useMouse<TApp extends ElementNode = ElementNode>(
|
|
|
358
327
|
runWithOwner(owner, () => handleMouseDown(e));
|
|
359
328
|
};
|
|
360
329
|
|
|
330
|
+
const focusKey = Config.focusStateKey;
|
|
331
|
+
|
|
361
332
|
makeEventListener(window, 'wheel', handleScroll);
|
|
362
333
|
makeEventListener(window, 'click', handleClickContext);
|
|
363
334
|
makeEventListener(window, 'mousedown', handleMouseDownContext);
|
|
364
335
|
createEffect(() => {
|
|
365
|
-
if (scheduled())
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (!activeElm) {
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// Update Row & Column Selected property
|
|
394
|
-
const activeElmParent = activeElm.parent;
|
|
395
|
-
if (activeElmParent?.selected !== undefined) {
|
|
396
|
-
activeElmParent.selected =
|
|
397
|
-
activeElmParent.children.indexOf(activeElm);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (previousElement && previousElement !== activeElm && hoverState) {
|
|
401
|
-
removeCustomStateFromElement(previousElement, hoverState);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (hoverState) {
|
|
405
|
-
addCustomStateToElement(activeElm, hoverState);
|
|
406
|
-
} else {
|
|
407
|
-
activeElm.setFocus();
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
previousElement = activeElm;
|
|
411
|
-
} else if (previousElement && hoverState) {
|
|
336
|
+
if (!scheduled()) return;
|
|
337
|
+
|
|
338
|
+
const path = getChildrenByPosition(myApp, pos.x, pos.y);
|
|
339
|
+
let activeElm: ElementNode | undefined;
|
|
340
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
341
|
+
const el = path[i]!;
|
|
342
|
+
if (
|
|
343
|
+
el.onEnter ||
|
|
344
|
+
el.onMouseClick ||
|
|
345
|
+
el.onFocus ||
|
|
346
|
+
el[focusKey] ||
|
|
347
|
+
(hoverState && el[hoverState])
|
|
348
|
+
) {
|
|
349
|
+
activeElm = el;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (!activeElm) {
|
|
355
|
+
if (previousElement && hoverState) {
|
|
412
356
|
removeCustomStateFromElement(previousElement, hoverState);
|
|
413
357
|
previousElement = null;
|
|
414
358
|
}
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
let p = activeElm.parent;
|
|
363
|
+
while (p?.forwardStates) {
|
|
364
|
+
activeElm = p;
|
|
365
|
+
p = p.parent;
|
|
415
366
|
}
|
|
367
|
+
|
|
368
|
+
// Update Row & Column Selected property
|
|
369
|
+
const activeElmParent = activeElm.parent;
|
|
370
|
+
if (activeElmParent?.selected !== undefined) {
|
|
371
|
+
activeElmParent.selected = activeElmParent.children.indexOf(activeElm);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (previousElement && previousElement !== activeElm && hoverState) {
|
|
375
|
+
removeCustomStateFromElement(previousElement, hoverState);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (hoverState) {
|
|
379
|
+
addCustomStateToElement(activeElm, hoverState);
|
|
380
|
+
} else {
|
|
381
|
+
activeElm.setFocus();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
previousElement = activeElm;
|
|
416
385
|
});
|
|
417
386
|
}
|
package/src/solidOpts.ts
CHANGED
|
@@ -51,7 +51,7 @@ export default {
|
|
|
51
51
|
insertNode(parent: ElementNode, node: SolidNode, anchor: SolidNode): void {
|
|
52
52
|
log('INSERT: ', parent, node, anchor);
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const prevParent = node.parent;
|
|
55
55
|
parent.insertChild(node, anchor);
|
|
56
56
|
|
|
57
57
|
if (node instanceof ElementNode) {
|