@solidtv/solid 1.0.2 → 1.1.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/src/core/config.d.ts +1 -0
- package/dist/src/core/config.js +1 -0
- package/dist/src/core/config.js.map +1 -1
- package/dist/src/core/dom-renderer/domRenderer.js +2 -0
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +1 -0
- package/dist/src/core/elementNode.d.ts +16 -3
- package/dist/src/core/elementNode.js +143 -50
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/focusManager.d.ts +14 -0
- package/dist/src/core/focusManager.js +75 -0
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/intrinsicTypes.d.ts +2 -7
- package/dist/src/core/nodeTypes.d.ts +7 -0
- package/dist/src/core/nodeTypes.js +8 -0
- package/dist/src/core/nodeTypes.js.map +1 -1
- package/dist/src/core/utils.d.ts +2 -1
- package/dist/src/core/utils.js.map +1 -1
- package/dist/src/devtools/hexColorTransform.d.ts +6 -0
- package/dist/src/devtools/hexColorTransform.js +42 -0
- package/dist/src/devtools/hexColorTransform.js.map +1 -0
- package/dist/src/devtools/index.d.ts +2 -0
- package/dist/src/devtools/index.js +1 -0
- package/dist/src/devtools/index.js.map +1 -1
- package/dist/src/primitives/index.d.ts +0 -2
- package/dist/src/primitives/index.js +0 -2
- package/dist/src/primitives/index.js.map +1 -1
- package/dist/src/primitives/routerIndex.d.ts +2 -0
- package/dist/src/primitives/routerIndex.js +3 -0
- package/dist/src/primitives/routerIndex.js.map +1 -0
- package/dist/src/primitives/useMouse.js.map +1 -1
- package/dist/src/solidOpts.d.ts +1 -1
- package/dist/src/solidOpts.js +3 -13
- package/dist/src/solidOpts.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -3
- package/src/core/config.ts +2 -0
- package/src/core/dom-renderer/domRenderer.ts +2 -0
- package/src/core/dom-renderer/domRendererTypes.ts +1 -0
- package/src/core/elementNode.ts +164 -55
- package/src/core/focusManager.ts +115 -0
- package/src/core/intrinsicTypes.ts +3 -7
- package/src/core/nodeTypes.ts +12 -0
- package/src/core/utils.ts +2 -2
- package/src/devtools/hexColorTransform.ts +56 -0
- package/src/devtools/index.ts +3 -0
- package/src/primitives/index.ts +0 -2
- package/src/primitives/routerIndex.ts +2 -0
- package/src/primitives/useMouse.ts +3 -3
- package/src/solidOpts.ts +5 -16
package/src/core/elementNode.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
type Styles,
|
|
9
9
|
AddColorString,
|
|
10
10
|
TextProps,
|
|
11
|
-
TextNode,
|
|
12
11
|
type OnEvent,
|
|
13
12
|
NewOmit,
|
|
14
13
|
SingleBorderStyle,
|
|
@@ -47,7 +46,7 @@ import type {
|
|
|
47
46
|
INodeProps,
|
|
48
47
|
} from '@solidtv/renderer';
|
|
49
48
|
import { assertTruthy } from '@solidtv/renderer/utils';
|
|
50
|
-
import { NodeType } from './nodeTypes.js';
|
|
49
|
+
import { NodeType, TextNode } from './nodeTypes.js';
|
|
51
50
|
import {
|
|
52
51
|
ForwardFocusHandler,
|
|
53
52
|
setActiveElement,
|
|
@@ -63,27 +62,45 @@ import {
|
|
|
63
62
|
IRendererTextNodeProps,
|
|
64
63
|
} from './dom-renderer/domRendererTypes.js';
|
|
65
64
|
|
|
65
|
+
// Unified post-mutation scheduler.
|
|
66
|
+
//
|
|
67
|
+
// Three phases run in one microtask (or one renderer-tick callback):
|
|
68
|
+
// 1. delete-flush — destroy nodes that were removed and not re-inserted
|
|
69
|
+
// 2. layout — recompute flex layout for any dirty subtree
|
|
70
|
+
// 3. focus — resolve forwardFocus on deferred elements, then apply
|
|
71
|
+
//
|
|
72
|
+
// Order matters: layout reads the rendered tree (so destroyed nodes must be
|
|
73
|
+
// gone), and focus reads the laid-out tree.
|
|
74
|
+
let postMutationQueued = false;
|
|
66
75
|
let nextActiveElement: ElementNode | null = null;
|
|
67
|
-
let
|
|
68
|
-
let layoutRunQueued = false;
|
|
76
|
+
let deferredFocusElement: ElementNode | null = null;
|
|
69
77
|
const layoutQueue = new Set<ElementNode>();
|
|
78
|
+
export const elementDeleteQueue: ElementNode[] = [];
|
|
70
79
|
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'reprocessUpdates' in renderer.stage &&
|
|
77
|
-
renderer.stage.reprocessUpdates
|
|
78
|
-
) {
|
|
79
|
-
renderer.stage.reprocessUpdates(runLayout);
|
|
80
|
-
} else {
|
|
81
|
-
queueMicrotask(runLayout);
|
|
82
|
-
}
|
|
80
|
+
export function schedulePostMutation() {
|
|
81
|
+
if (postMutationQueued) return;
|
|
82
|
+
postMutationQueued = true;
|
|
83
|
+
if ('reprocessUpdates' in renderer.stage && renderer.stage.reprocessUpdates) {
|
|
84
|
+
renderer.stage.reprocessUpdates(runPostMutation);
|
|
83
85
|
}
|
|
86
|
+
queueMicrotask(runPostMutation);
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
function
|
|
89
|
+
function runPostMutation() {
|
|
90
|
+
postMutationQueued = false;
|
|
91
|
+
|
|
92
|
+
// Phase 1: delete-flush
|
|
93
|
+
if (elementDeleteQueue.length > 0) {
|
|
94
|
+
for (let el of elementDeleteQueue) {
|
|
95
|
+
if (Number(el._queueDelete) < 0) {
|
|
96
|
+
el.destroy();
|
|
97
|
+
}
|
|
98
|
+
el._queueDelete = undefined;
|
|
99
|
+
}
|
|
100
|
+
elementDeleteQueue.length = 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Phase 2: layout
|
|
87
104
|
while (layoutQueue.size > 0) {
|
|
88
105
|
const queue = [...layoutQueue];
|
|
89
106
|
layoutQueue.clear();
|
|
@@ -92,7 +109,45 @@ function runLayout() {
|
|
|
92
109
|
node.updateLayout();
|
|
93
110
|
}
|
|
94
111
|
}
|
|
95
|
-
|
|
112
|
+
|
|
113
|
+
// Phase 3: focus. setFocus() may have evaluated forwardFocus pre-render
|
|
114
|
+
// (when no children existed yet); deferredFocusElement re-runs setFocus
|
|
115
|
+
// here once the subtree has rendered, then setActiveElement is applied.
|
|
116
|
+
if (deferredFocusElement !== null) {
|
|
117
|
+
const el = deferredFocusElement;
|
|
118
|
+
deferredFocusElement = null;
|
|
119
|
+
el.setFocus();
|
|
120
|
+
} else if (nextActiveElement !== null) {
|
|
121
|
+
const element = nextActiveElement;
|
|
122
|
+
nextActiveElement = null;
|
|
123
|
+
setActiveElement(element);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function addToLayoutQueue(node: ElementNode) {
|
|
128
|
+
layoutQueue.add(node);
|
|
129
|
+
schedulePostMutation();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Text-default template, built once on first use. Config.fontSettings is
|
|
133
|
+
// expected to be set at app startup and not change afterwards.
|
|
134
|
+
let _fontTemplate: Array<[string, any]> | undefined;
|
|
135
|
+
let _fontFamilyIdx = -1;
|
|
136
|
+
let _fontFamilyWithWeight: string | undefined;
|
|
137
|
+
|
|
138
|
+
function buildFontTemplate() {
|
|
139
|
+
const tpl: Array<[string, any]> = [];
|
|
140
|
+
const fs = Config.fontSettings;
|
|
141
|
+
if (fs) {
|
|
142
|
+
for (const key in fs) {
|
|
143
|
+
if (key === 'fontFamily') {
|
|
144
|
+
_fontFamilyIdx = tpl.length;
|
|
145
|
+
_fontFamilyWithWeight = `${fs.fontFamily}${fs.fontWeight || ''}`;
|
|
146
|
+
}
|
|
147
|
+
tpl.push([key, (fs as any)[key]]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
_fontTemplate = tpl;
|
|
96
151
|
}
|
|
97
152
|
|
|
98
153
|
const parseAndAssignShaderProps = (
|
|
@@ -263,6 +318,16 @@ export interface ElementNode extends RendererNode, FocusNode {
|
|
|
263
318
|
_type: 'element' | 'textNode';
|
|
264
319
|
_undoStyles?: string[];
|
|
265
320
|
autosize?: boolean;
|
|
321
|
+
/**
|
|
322
|
+
* Optional component name for inspector / dev tooling — emitted by the
|
|
323
|
+
* Babel devtools plugin (see `devtools/jsx-locator.js`).
|
|
324
|
+
*/
|
|
325
|
+
componentName?: string;
|
|
326
|
+
/**
|
|
327
|
+
* Optional source-location string for inspector / dev tooling — emitted by
|
|
328
|
+
* the Babel devtools plugin.
|
|
329
|
+
*/
|
|
330
|
+
componentLocation?: string;
|
|
266
331
|
/**
|
|
267
332
|
* The distance from the bottom edge of the parent element.
|
|
268
333
|
* When `bottom` is set, `mountY` is automatically set to 1.
|
|
@@ -683,13 +748,48 @@ export interface ElementNode extends RendererNode, FocusNode {
|
|
|
683
748
|
stateOrder?: DollarString[];
|
|
684
749
|
}
|
|
685
750
|
|
|
686
|
-
export class ElementNode
|
|
751
|
+
export class ElementNode {
|
|
687
752
|
constructor(name: string) {
|
|
688
|
-
super();
|
|
689
753
|
this._type = name === 'text' ? NodeType.TextNode : NodeType.Element;
|
|
690
754
|
this.rendered = false;
|
|
691
|
-
|
|
755
|
+
// initialize lng with standard properties for v8 optimization
|
|
756
|
+
this.lng = {
|
|
757
|
+
w: undefined,
|
|
758
|
+
h: undefined,
|
|
759
|
+
x: undefined,
|
|
760
|
+
y: undefined,
|
|
761
|
+
alpha: undefined,
|
|
762
|
+
color: undefined,
|
|
763
|
+
shader: undefined,
|
|
764
|
+
clipping: undefined,
|
|
765
|
+
text: undefined,
|
|
766
|
+
};
|
|
692
767
|
this.children = [];
|
|
768
|
+
|
|
769
|
+
// Initialize lazy underscore fields explicitly in a fixed order. This
|
|
770
|
+
// gives every ElementNode the same hidden class on construction; later
|
|
771
|
+
// assignments transition predictably instead of forking shapes by
|
|
772
|
+
// first-touch order.
|
|
773
|
+
this._queueDelete = undefined;
|
|
774
|
+
this._animationQueue = undefined;
|
|
775
|
+
this._animationQueueSettings = undefined;
|
|
776
|
+
this._animationRunning = undefined;
|
|
777
|
+
this._animationSettings = undefined;
|
|
778
|
+
this._autofocus = undefined;
|
|
779
|
+
this._calcWidth = undefined;
|
|
780
|
+
this._calcHeight = undefined;
|
|
781
|
+
this._containsFlexGrow = undefined;
|
|
782
|
+
this._hasRenderedChildren = undefined;
|
|
783
|
+
this._effects = undefined;
|
|
784
|
+
this._fontFamily = undefined;
|
|
785
|
+
this._fontWeight = undefined;
|
|
786
|
+
this._id = undefined;
|
|
787
|
+
this._parent = undefined;
|
|
788
|
+
this._states = undefined;
|
|
789
|
+
this._style = undefined;
|
|
790
|
+
this._theme = undefined;
|
|
791
|
+
this._lastAnyKeyPressTime = undefined;
|
|
792
|
+
this._undoStyles = undefined;
|
|
693
793
|
}
|
|
694
794
|
|
|
695
795
|
get effects(): StyleEffects | undefined {
|
|
@@ -826,7 +926,10 @@ export class ElementNode extends Object {
|
|
|
826
926
|
|
|
827
927
|
removeChild(node: ElementNode | ElementText | TextNode) {
|
|
828
928
|
if (spliceItem(this.children, node, 1) > -1) {
|
|
829
|
-
|
|
929
|
+
if (isElementNode(node) && node.onRemove) {
|
|
930
|
+
node.onRemove.call(node, node);
|
|
931
|
+
}
|
|
932
|
+
|
|
830
933
|
if (this.requiresLayout()) {
|
|
831
934
|
addToLayoutQueue(this);
|
|
832
935
|
}
|
|
@@ -872,6 +975,16 @@ export class ElementNode extends Object {
|
|
|
872
975
|
| undefined
|
|
873
976
|
| AnimationSettings);
|
|
874
977
|
|
|
978
|
+
// If the renderer doesn't support animateProp,
|
|
979
|
+
// keep backwards compatible with LightningRenderer
|
|
980
|
+
if (!('animateProp' in this.lng)) {
|
|
981
|
+
const animationController = this.animate(
|
|
982
|
+
{ [name]: value },
|
|
983
|
+
animationSettings,
|
|
984
|
+
);
|
|
985
|
+
return animationController.start();
|
|
986
|
+
}
|
|
987
|
+
|
|
875
988
|
return (this.lng as any).animateProp(
|
|
876
989
|
name,
|
|
877
990
|
value,
|
|
@@ -964,19 +1077,10 @@ export class ElementNode extends Object {
|
|
|
964
1077
|
}
|
|
965
1078
|
}
|
|
966
1079
|
}
|
|
967
|
-
// Delay setting focus so children can render (useful for Row + Column)
|
|
1080
|
+
// Delay setting focus so children can render (useful for Row + Column).
|
|
1081
|
+
// The post-mutation scheduler applies setActiveElement in its focus phase.
|
|
968
1082
|
nextActiveElement = this;
|
|
969
|
-
|
|
970
|
-
focusQueued = true;
|
|
971
|
-
queueMicrotask(() => {
|
|
972
|
-
focusQueued = false;
|
|
973
|
-
if (nextActiveElement) {
|
|
974
|
-
const element = nextActiveElement;
|
|
975
|
-
nextActiveElement = null;
|
|
976
|
-
setActiveElement(element);
|
|
977
|
-
}
|
|
978
|
-
});
|
|
979
|
-
}
|
|
1083
|
+
schedulePostMutation();
|
|
980
1084
|
} else {
|
|
981
1085
|
this._autofocus = true;
|
|
982
1086
|
}
|
|
@@ -984,12 +1088,7 @@ export class ElementNode extends Object {
|
|
|
984
1088
|
|
|
985
1089
|
_layoutOnLoad() {
|
|
986
1090
|
(this.lng as IRendererNode).on('loaded', () => {
|
|
987
|
-
|
|
988
|
-
'reprocessUpdates' in renderer.stage &&
|
|
989
|
-
renderer.stage.reprocessUpdates
|
|
990
|
-
) {
|
|
991
|
-
renderer.stage.reprocessUpdates(runLayout);
|
|
992
|
-
}
|
|
1091
|
+
schedulePostMutation();
|
|
993
1092
|
this.parent!.updateLayout();
|
|
994
1093
|
});
|
|
995
1094
|
}
|
|
@@ -1150,9 +1249,12 @@ export class ElementNode extends Object {
|
|
|
1150
1249
|
*/
|
|
1151
1250
|
set autofocus(val: any) {
|
|
1152
1251
|
this._autofocus = val;
|
|
1153
|
-
//
|
|
1154
|
-
//
|
|
1155
|
-
|
|
1252
|
+
// Defer setFocus so children render first (forwardFocus needs them).
|
|
1253
|
+
// The post-mutation focus phase calls setFocus on this element.
|
|
1254
|
+
if (val) {
|
|
1255
|
+
deferredFocusElement = this;
|
|
1256
|
+
schedulePostMutation();
|
|
1257
|
+
}
|
|
1156
1258
|
}
|
|
1157
1259
|
|
|
1158
1260
|
get autofocus() {
|
|
@@ -1351,14 +1453,22 @@ export class ElementNode extends Object {
|
|
|
1351
1453
|
|
|
1352
1454
|
if (isElementText(node)) {
|
|
1353
1455
|
const textProps = props as TextProps;
|
|
1354
|
-
if (
|
|
1355
|
-
|
|
1456
|
+
if (_fontTemplate === undefined) buildFontTemplate();
|
|
1457
|
+
const tpl = _fontTemplate!;
|
|
1458
|
+
if (tpl.length > 0) {
|
|
1459
|
+
const familyIdx = _fontFamilyIdx;
|
|
1460
|
+
const familyWithWeight =
|
|
1461
|
+
textProps['fontWeight'] === undefined
|
|
1462
|
+
? _fontFamilyWithWeight
|
|
1463
|
+
: undefined;
|
|
1464
|
+
for (let i = 0; i < tpl.length; i++) {
|
|
1465
|
+
const entry = tpl[i]!;
|
|
1466
|
+
const key = entry[0];
|
|
1356
1467
|
if (textProps[key] === undefined) {
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
textProps[key] = value;
|
|
1468
|
+
textProps[key] =
|
|
1469
|
+
i === familyIdx && familyWithWeight !== undefined
|
|
1470
|
+
? familyWithWeight
|
|
1471
|
+
: entry[1];
|
|
1362
1472
|
}
|
|
1363
1473
|
}
|
|
1364
1474
|
}
|
|
@@ -1496,11 +1606,10 @@ export class ElementNode extends Object {
|
|
|
1496
1606
|
}
|
|
1497
1607
|
}
|
|
1498
1608
|
}
|
|
1499
|
-
if (topNode
|
|
1500
|
-
//
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
queueMicrotask(runLayout);
|
|
1609
|
+
if (topNode) {
|
|
1610
|
+
// Schedule one post-mutation pass; <For> may add many children in one
|
|
1611
|
+
// tick, but the scheduler dedupes and runs everything once.
|
|
1612
|
+
schedulePostMutation();
|
|
1504
1613
|
}
|
|
1505
1614
|
|
|
1506
1615
|
node._autofocus && node.setFocus();
|
package/src/core/focusManager.ts
CHANGED
|
@@ -84,11 +84,120 @@ const addFocusDebug = (
|
|
|
84
84
|
});
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// Focus History
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
export interface FocusHistoryEntry {
|
|
92
|
+
timestamp: number;
|
|
93
|
+
keyPressed: string | number | undefined;
|
|
94
|
+
mappedKey: string | undefined;
|
|
95
|
+
prev: ElementNode | undefined;
|
|
96
|
+
next: ElementNode;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const MAX_FOCUS_HISTORY = 50;
|
|
100
|
+
const focusHistory: FocusHistoryEntry[] = [];
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* WeakMap keyed by ElementNode so entries are automatically eligible for GC
|
|
104
|
+
* when the element is no longer referenced elsewhere.
|
|
105
|
+
*/
|
|
106
|
+
const elementFocusData = new WeakMap<
|
|
107
|
+
ElementNode,
|
|
108
|
+
{ focusCount: number; lastFocusedAt: number }
|
|
109
|
+
>();
|
|
110
|
+
|
|
111
|
+
/** The key that triggered the most recent (non-throttled) propagation pass. */
|
|
112
|
+
let _pendingHistoryKey: {
|
|
113
|
+
keyPressed: string | number | undefined;
|
|
114
|
+
mappedKey: string | undefined;
|
|
115
|
+
} = { keyPressed: undefined, mappedKey: undefined };
|
|
116
|
+
|
|
117
|
+
const getElementLabel = (elm: ElementNode | undefined): string => {
|
|
118
|
+
if (!elm) return 'None';
|
|
119
|
+
// ElementNode exposes _id internally; componentName comes from the Babel devtools plugin
|
|
120
|
+
const id = (elm as any).id ?? elm._id;
|
|
121
|
+
return id ?? elm.componentName ?? 'Unknown';
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const recordFocusHistory = (
|
|
125
|
+
next: ElementNode,
|
|
126
|
+
prev: ElementNode | undefined,
|
|
127
|
+
): void => {
|
|
128
|
+
if (isDev && Config.focusHistoryDebug > 0) {
|
|
129
|
+
const now = performance.now();
|
|
130
|
+
|
|
131
|
+
// Update WeakMap metadata for the element gaining focus
|
|
132
|
+
const existing = elementFocusData.get(next);
|
|
133
|
+
elementFocusData.set(next, {
|
|
134
|
+
focusCount: (existing?.focusCount ?? 0) + 1,
|
|
135
|
+
lastFocusedAt: now,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const entry: FocusHistoryEntry = {
|
|
139
|
+
timestamp: now,
|
|
140
|
+
keyPressed: _pendingHistoryKey.keyPressed,
|
|
141
|
+
mappedKey: _pendingHistoryKey.mappedKey,
|
|
142
|
+
prev,
|
|
143
|
+
next,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
focusHistory.push(entry);
|
|
147
|
+
if (focusHistory.length > MAX_FOCUS_HISTORY) {
|
|
148
|
+
focusHistory.shift();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
printFocusHistory(Config.focusHistoryDebug);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/** Returns a snapshot of the focus history ring buffer (up to 50 entries). */
|
|
156
|
+
export const getFocusHistory = (): Readonly<FocusHistoryEntry[]> =>
|
|
157
|
+
focusHistory;
|
|
158
|
+
|
|
159
|
+
if (isDev) {
|
|
160
|
+
console.log(
|
|
161
|
+
'DEBUG: Last focus target stored in $f, use inspect($f) to jump to it in the Elements panel. Enable with Config.focusHistoryDebug = n',
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Prints the last `count` focus history entries as a console.table.
|
|
166
|
+
* Callable at any time from the browser console: `printFocusHistory(20)`
|
|
167
|
+
*/
|
|
168
|
+
export const printFocusHistory = (count: number): void => {
|
|
169
|
+
const entries = focusHistory.slice(-count);
|
|
170
|
+
console.table(
|
|
171
|
+
entries.map((e) => ({
|
|
172
|
+
prev: getElementLabel(e.prev),
|
|
173
|
+
key: e.mappedKey ?? e.keyPressed ?? '—',
|
|
174
|
+
next: getElementLabel(e.next),
|
|
175
|
+
nextElm: e.next,
|
|
176
|
+
nextDiv: (e.next.lng as any).div as HTMLDivElement,
|
|
177
|
+
})),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// 2. Expose the most recent element for easy inspection
|
|
181
|
+
const lastEntry = entries[entries.length - 1];
|
|
182
|
+
if (lastEntry) {
|
|
183
|
+
const lastElm = (lastEntry.next.lng as any)?.div;
|
|
184
|
+
if (lastElm) {
|
|
185
|
+
(window as any).$f = lastElm;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
|
|
87
192
|
let activeElement: ElementNode | undefined;
|
|
88
193
|
export const setActiveElement = (elm: ElementNode) => {
|
|
89
194
|
if (elm === activeElement) return;
|
|
195
|
+
const prev = activeElement;
|
|
90
196
|
updateFocusPath(elm, activeElement);
|
|
91
197
|
activeElement = elm;
|
|
198
|
+
recordFocusHistory(elm, prev);
|
|
199
|
+
// Reset key attribution so programmatic focus changes show '—' for key fields
|
|
200
|
+
_pendingHistoryKey = { keyPressed: undefined, mappedKey: undefined };
|
|
92
201
|
// Callback for libraries to use signals / refs
|
|
93
202
|
Config.setActiveElement(elm);
|
|
94
203
|
};
|
|
@@ -176,6 +285,12 @@ const propagateKeyPress = (
|
|
|
176
285
|
}
|
|
177
286
|
lastGlobalKeyPressTime = currentTime;
|
|
178
287
|
}
|
|
288
|
+
|
|
289
|
+
// Record the key for focus-history attribution (keyup presses don't trigger focus changes)
|
|
290
|
+
if (!isUp) {
|
|
291
|
+
_pendingHistoryKey = { keyPressed: key, mappedKey: mappedEvent };
|
|
292
|
+
}
|
|
293
|
+
|
|
179
294
|
const numItems = focusPath.length;
|
|
180
295
|
if (numItems === 0) return false;
|
|
181
296
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as lngr from '@solidtv/renderer';
|
|
2
2
|
import { ElementNode, type RendererNode } from './elementNode.js';
|
|
3
|
+
import type { TextNode } from './nodeTypes.js';
|
|
3
4
|
import { NodeStates } from './states.js';
|
|
4
5
|
import {
|
|
5
6
|
ShaderBorderProps,
|
|
@@ -115,13 +116,6 @@ export interface ElementText
|
|
|
115
116
|
style: TextStyles;
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
export interface TextNode {
|
|
119
|
-
_type: 'text';
|
|
120
|
-
parent?: ElementText;
|
|
121
|
-
text: string;
|
|
122
|
-
[key: string]: any;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
119
|
export interface NodeProps
|
|
126
120
|
extends RendererNode,
|
|
127
121
|
EventHandlers<DefaultKeyMap>,
|
|
@@ -140,6 +134,8 @@ export interface NodeProps
|
|
|
140
134
|
| 'preFlexheight'
|
|
141
135
|
| 'width'
|
|
142
136
|
| 'height'
|
|
137
|
+
| 'componentName'
|
|
138
|
+
| 'componentLocation'
|
|
143
139
|
>
|
|
144
140
|
> {
|
|
145
141
|
states?: NodeStates;
|
package/src/core/nodeTypes.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import type { ElementText } from './intrinsicTypes.js';
|
|
2
|
+
|
|
1
3
|
export const NodeType = {
|
|
2
4
|
Element: 'element',
|
|
3
5
|
TextNode: 'textNode',
|
|
4
6
|
Text: 'text',
|
|
5
7
|
} as const;
|
|
6
8
|
export type NodeTypes = (typeof NodeType)[keyof typeof NodeType];
|
|
9
|
+
|
|
10
|
+
export class TextNode {
|
|
11
|
+
readonly _type: 'text' = 'text';
|
|
12
|
+
parent: ElementText | undefined = undefined;
|
|
13
|
+
text: string;
|
|
14
|
+
|
|
15
|
+
constructor(text: string) {
|
|
16
|
+
this.text = text;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/core/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type INode, type Point } from '@solidtv/renderer';
|
|
2
2
|
import { Config, isDev } from './config.js';
|
|
3
|
-
import type { Styles, ElementText
|
|
3
|
+
import type { Styles, ElementText } from './intrinsicTypes.js';
|
|
4
4
|
import { ElementNode } from './elementNode.js';
|
|
5
|
-
import { NodeType } from './nodeTypes.js';
|
|
5
|
+
import { NodeType, TextNode } from './nodeTypes.js';
|
|
6
6
|
|
|
7
7
|
function hasDebug(node: any) {
|
|
8
8
|
return isObject(node) && node.debug;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createFilter, type Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
export interface HexColorTransformOptions {
|
|
4
|
+
include?: string | string[];
|
|
5
|
+
exclude?: string | string[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default function hexColorTransform(
|
|
9
|
+
options: HexColorTransformOptions = {},
|
|
10
|
+
): Plugin {
|
|
11
|
+
const filter = createFilter(options.include, options.exclude);
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
name: 'vite-plugin-hex-color-transform',
|
|
15
|
+
|
|
16
|
+
transform(code, id) {
|
|
17
|
+
if (!filter(id)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const hexColorRegex =
|
|
22
|
+
/["']#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})["']/g;
|
|
23
|
+
|
|
24
|
+
const convertHexTo0x = (_match: string, p1: string) => {
|
|
25
|
+
let hex = p1;
|
|
26
|
+
|
|
27
|
+
if (hex.length === 3) {
|
|
28
|
+
hex =
|
|
29
|
+
hex
|
|
30
|
+
.split('')
|
|
31
|
+
.map((char) => char + char)
|
|
32
|
+
.join('') + 'FF';
|
|
33
|
+
} else if (hex.length === 4) {
|
|
34
|
+
const alpha = hex[3]! + hex[3]!;
|
|
35
|
+
hex =
|
|
36
|
+
hex
|
|
37
|
+
.slice(0, 3)
|
|
38
|
+
.split('')
|
|
39
|
+
.map((char) => char + char)
|
|
40
|
+
.join('') + alpha;
|
|
41
|
+
} else if (hex.length === 6) {
|
|
42
|
+
hex += 'FF';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return `0x${hex.toUpperCase()}`;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const transformedCode = code.replace(hexColorRegex, convertHexTo0x);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
code: transformedCode,
|
|
52
|
+
map: null,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
package/src/devtools/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as debug from '@solid-devtools/debugger/types';
|
|
2
2
|
import * as lng from '../core/index.js';
|
|
3
3
|
|
|
4
|
+
export { default as hexColorTransform } from './hexColorTransform.js';
|
|
5
|
+
export type { HexColorTransformOptions } from './hexColorTransform.js';
|
|
6
|
+
|
|
4
7
|
const EMPTY_CHILDREN: (lng.ElementNode | lng.ElementText)[] = [];
|
|
5
8
|
|
|
6
9
|
/**
|
package/src/primitives/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ export * from './Lazy.jsx';
|
|
|
8
8
|
export * from './LazyImport.js';
|
|
9
9
|
export * from './Image.jsx';
|
|
10
10
|
export * from './Visible.jsx';
|
|
11
|
-
export * from './router.js';
|
|
12
11
|
export * from './Column.jsx';
|
|
13
12
|
export * from './Row.jsx';
|
|
14
13
|
export * from './Grid.jsx';
|
|
@@ -19,7 +18,6 @@ export * from './Suspense.jsx';
|
|
|
19
18
|
export * from './Marquee.jsx';
|
|
20
19
|
export * from './createFocusStack.jsx';
|
|
21
20
|
export * from './useHold.js';
|
|
22
|
-
export * from './KeepAlive.jsx';
|
|
23
21
|
export * from './VirtualGrid.jsx';
|
|
24
22
|
export * from './Virtual.jsx';
|
|
25
23
|
export * from './utils/withScrolling.js';
|
|
@@ -30,21 +30,21 @@ export function addCustomStateToElement(
|
|
|
30
30
|
element: RenderableNode,
|
|
31
31
|
state: CustomState,
|
|
32
32
|
): void {
|
|
33
|
-
element.states?.add(state);
|
|
33
|
+
(element as ElementNode).states?.add(state);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function removeCustomStateFromElement(
|
|
37
37
|
element: RenderableNode,
|
|
38
38
|
state: CustomState,
|
|
39
39
|
): void {
|
|
40
|
-
element?.states?.remove(state);
|
|
40
|
+
(element as ElementNode)?.states?.remove(state);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function hasCustomState(
|
|
44
44
|
element: RenderableNode,
|
|
45
45
|
state: CustomState,
|
|
46
46
|
): boolean {
|
|
47
|
-
return element.states?.has(state);
|
|
47
|
+
return (element as ElementNode).states?.has(state);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
function createKeyboardEvent(
|
package/src/solidOpts.ts
CHANGED
|
@@ -2,10 +2,11 @@ import {
|
|
|
2
2
|
assertTruthy,
|
|
3
3
|
isElementText,
|
|
4
4
|
ElementNode,
|
|
5
|
-
|
|
5
|
+
TextNode,
|
|
6
6
|
log,
|
|
7
7
|
type ElementText,
|
|
8
|
-
|
|
8
|
+
elementDeleteQueue,
|
|
9
|
+
schedulePostMutation,
|
|
9
10
|
} from './core/index.js';
|
|
10
11
|
import type { SolidNode, SolidRendererOptions } from './types.js';
|
|
11
12
|
|
|
@@ -18,23 +19,11 @@ Object.defineProperty(ElementNode.prototype, 'preserve', {
|
|
|
18
19
|
},
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
let elementDeleteQueue: ElementNode[] = [];
|
|
22
|
-
|
|
23
|
-
function flushDeleteQueue(): void {
|
|
24
|
-
for (let el of elementDeleteQueue) {
|
|
25
|
-
if (Number(el._queueDelete) < 0) {
|
|
26
|
-
el.destroy();
|
|
27
|
-
}
|
|
28
|
-
el._queueDelete = undefined;
|
|
29
|
-
}
|
|
30
|
-
elementDeleteQueue.length = 0;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
22
|
function pushDeleteQueue(node: ElementNode, n: number): void {
|
|
34
23
|
if (node._queueDelete === undefined) {
|
|
35
24
|
node._queueDelete = n;
|
|
36
25
|
if (elementDeleteQueue.push(node) === 1) {
|
|
37
|
-
|
|
26
|
+
schedulePostMutation();
|
|
38
27
|
}
|
|
39
28
|
} else {
|
|
40
29
|
node._queueDelete += n;
|
|
@@ -47,7 +36,7 @@ export default {
|
|
|
47
36
|
},
|
|
48
37
|
createTextNode(text: string): TextNode {
|
|
49
38
|
// A text node is just a string - not the <text> node
|
|
50
|
-
return
|
|
39
|
+
return new TextNode(text);
|
|
51
40
|
},
|
|
52
41
|
replaceText(node: TextNode, value: string): void {
|
|
53
42
|
log('Replace Text: ', node, value);
|