@solidtv/solid 1.3.8 → 1.3.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidtv/solid",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "SolidTV",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1232,7 +1232,11 @@ function updateNodeData(node: DOMNode | DOMText) {
1232
1232
  if (keyValue === undefined) {
1233
1233
  node.div.removeAttribute('data-' + key);
1234
1234
  } else {
1235
- node.div.dataset[key] = String(keyValue);
1235
+ // dataset[key] requires key to already be camelCase (DOMStringMap rejects hyphenated
1236
+ // property names outright, e.g. "section-id" -- SyntaxError: not a valid property
1237
+ // name). Our data props are passed as data-attribute-style keys (kebab-case), so use
1238
+ // setAttribute directly instead, consistent with the removeAttribute branch above.
1239
+ node.div.setAttribute('data-' + key, String(keyValue));
1236
1240
  }
1237
1241
  }
1238
1242
  }
@@ -470,7 +470,7 @@ function createVirtual<T>(
470
470
  },
471
471
  ).start();
472
472
  } else {
473
- this.lng[axis] = this.lng[axis]! + childSize * slice().shiftBy;
473
+ this.lng[axis] = (prevChildPos - active[axis]) + childSize * slice().shiftBy;
474
474
  }
475
475
  });
476
476
  };
@@ -10,7 +10,7 @@ import {
10
10
  import { makeEventListener } from '@solid-primitives/event-listener';
11
11
  import { useMousePosition } from '@solid-primitives/mouse';
12
12
  import { createScheduled, throttle } from '@solid-primitives/scheduled';
13
- import { createEffect, getOwner, runWithOwner } from 'solid-js';
13
+ import { createEffect, createSignal, getOwner, runWithOwner } from 'solid-js';
14
14
 
15
15
  type CustomState = `$${string}`;
16
16
 
@@ -51,7 +51,7 @@ function createKeyboardEvent(
51
51
  keyCode: number,
52
52
  eventName: string = 'keydown',
53
53
  ): KeyboardEvent {
54
- return new KeyboardEvent(eventName, {
54
+ const event = new KeyboardEvent(eventName, {
55
55
  key,
56
56
  keyCode,
57
57
  which: keyCode,
@@ -61,8 +61,55 @@ function createKeyboardEvent(
61
61
  metaKey: false,
62
62
  bubbles: true,
63
63
  });
64
+
65
+ // Chrome < 51 (LG webOS 3.x runs Chrome 38) ignores the key/keyCode/which
66
+ // members of KeyboardEventInit, so the event arrives with key '' / keyCode 0
67
+ // and the focusManager drops it. Force the values onto the instance so Magic
68
+ // Remote clicks and scrolls still map to keys on those devices.
69
+ if (event.key !== key || event.keyCode !== keyCode) {
70
+ Object.defineProperty(event, 'key', { get: () => key });
71
+ Object.defineProperty(event, 'keyCode', { get: () => keyCode });
72
+ Object.defineProperty(event, 'which', { get: () => keyCode });
73
+ }
74
+
75
+ return event;
64
76
  }
65
77
 
78
+ const [cursorVisible, setCursorVisible] = createSignal(false);
79
+
80
+ let listening = false;
81
+
82
+ // webOS dispatches `cursorStateChange` on `document` whenever the Magic Remote
83
+ // pointer appears or disappears; `detail.visibility` is the new state.
84
+ const handleCursorStateChange = (event: Event) => {
85
+ setCursorVisible(
86
+ Boolean(
87
+ (event as CustomEvent<{ visibility?: boolean }>).detail?.visibility,
88
+ ),
89
+ );
90
+ };
91
+
92
+ // A single, app-lifetime listener backs every caller so a page full of rails
93
+ // does not attach one listener per rail. Attached lazily on first read.
94
+ const ensureListening = () => {
95
+ if (listening || typeof document === 'undefined') return;
96
+ listening = true;
97
+ document.addEventListener(
98
+ 'cursorStateChange',
99
+ handleCursorStateChange,
100
+ false,
101
+ );
102
+ };
103
+
104
+ /**
105
+ * Reactive accessor for webOS Magic Remote cursor visibility. `true` while the
106
+ * pointer is on screen, `false` otherwise.
107
+ */
108
+ export const isCursorVisible = () => {
109
+ ensureListening();
110
+ return cursorVisible();
111
+ };
112
+
66
113
  let scrollTimeout: ReturnType<typeof setTimeout>;
67
114
  const handleScroll = throttle((e: WheelEvent): void => {
68
115
  const deltaY = e.deltaY;
@@ -167,14 +214,14 @@ function handleElementClick(
167
214
  pressedElementRef.current = null;
168
215
  }
169
216
 
217
+ // onMouseClick is mouse-specific, so call it directly.
170
218
  if (isFunction(clickedElement.onMouseClick)) {
171
219
  clickedElement.onMouseClick(e, clickedElement);
172
220
  return;
173
- } else if (isFunction(clickedElement.onEnter)) {
174
- clickedElement.onEnter(e, clickedElement, clickedElement);
175
- return;
176
221
  }
177
222
 
223
+ // Otherwise focus the element and dispatch a synthetic Enter so the
224
+ // focusManager handles it exactly like a remote/keyboard Enter press:
178
225
  clickedElement.setFocus();
179
226
  setTimeout(() => {
180
227
  document.dispatchEvent(createKeyboardEvent('Enter', 13));