@lightningtv/core
Advanced tools
Comparing version 1.3.10 to 1.4.0-rc1
@@ -126,2 +126,3 @@ import { renderer, createShader } from './lightningInit.js'; | ||
insertChild(node, beforeNode) { | ||
node.parent = this; | ||
if (beforeNode) { | ||
@@ -132,8 +133,8 @@ // SolidJS can move nodes around in the children array. | ||
const index = this.children.indexOf(beforeNode); | ||
this.children.splice(index, 0, node); | ||
if (index >= 0) { | ||
this.children.splice(index, 0, node); | ||
return; | ||
} | ||
} | ||
else { | ||
this.children.push(node); | ||
} | ||
node.parent = this; | ||
this.children.push(node); | ||
} | ||
@@ -234,4 +235,5 @@ removeChild(node) { | ||
const focusedIndex = typeof this.forwardFocus === 'number' ? this.forwardFocus : null; | ||
if (focusedIndex !== null && focusedIndex < this.children.length) { | ||
const child = this.children[focusedIndex]; | ||
const nodes = this.children; | ||
if (focusedIndex !== null && focusedIndex < nodes.length) { | ||
const child = nodes[focusedIndex]; | ||
isElementNode(child) && child.setFocus(); | ||
@@ -320,3 +322,5 @@ return; | ||
set states(states) { | ||
this._states = new States(this._stateChanged.bind(this), states); | ||
this._states = this._states | ||
? this._states.merge(states) | ||
: new States(this._stateChanged.bind(this), states); | ||
if (this.rendered) { | ||
@@ -323,0 +327,0 @@ this._stateChanged(); |
@@ -9,3 +9,4 @@ export type NodeStates = string[] | string | Record<string, boolean | undefined>; | ||
toggle(state: string, force?: boolean): void; | ||
merge(newStates: NodeStates): this; | ||
remove(state: string): void; | ||
} |
@@ -34,10 +34,6 @@ import { isArray, isString } from './utils.js'; | ||
if (force === true) { | ||
if (!this.has(state)) { | ||
this.add(state); | ||
} | ||
this.add(state); | ||
} | ||
else if (force === false) { | ||
if (this.has(state)) { | ||
this.remove(state); | ||
} | ||
this.remove(state); | ||
} | ||
@@ -53,2 +49,18 @@ else { | ||
} | ||
merge(newStates) { | ||
if (isArray(newStates)) { | ||
this.length = 0; // Clear the current states | ||
this.push(...newStates); | ||
} | ||
else if (isString(newStates)) { | ||
this.length = 0; // Clear the current states | ||
this.push(newStates); | ||
} | ||
else { | ||
for (const state in newStates) { | ||
this.toggle(state, newStates[state]); | ||
} | ||
} | ||
return this; | ||
} | ||
remove(state) { | ||
@@ -55,0 +67,0 @@ const stateIndexToRemove = this.indexOf(state); |
{ | ||
"name": "@lightningtv/core", | ||
"version": "1.3.10", | ||
"version": "1.4.0-rc1", | ||
"description": "Lightning TV Core for Universal Renderers", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -236,2 +236,3 @@ import { renderer, createShader } from './lightningInit.js'; | ||
) { | ||
node.parent = this; | ||
if (beforeNode) { | ||
@@ -242,8 +243,8 @@ // SolidJS can move nodes around in the children array. | ||
const index = this.children.indexOf(beforeNode); | ||
this.children.splice(index, 0, node); | ||
} else { | ||
this.children.push(node); | ||
if (index >= 0) { | ||
this.children.splice(index, 0, node); | ||
return; | ||
} | ||
} | ||
node.parent = this; | ||
this.children.push(node); | ||
} | ||
@@ -379,4 +380,5 @@ | ||
typeof this.forwardFocus === 'number' ? this.forwardFocus : null; | ||
if (focusedIndex !== null && focusedIndex < this.children.length) { | ||
const child = this.children[focusedIndex]; | ||
const nodes = this.children; | ||
if (focusedIndex !== null && focusedIndex < nodes.length) { | ||
const child = nodes[focusedIndex]; | ||
isElementNode(child) && child.setFocus(); | ||
@@ -482,3 +484,5 @@ return; | ||
set states(states: NodeStates) { | ||
this._states = new States(this._stateChanged.bind(this), states); | ||
this._states = this._states | ||
? this._states.merge(states) | ||
: new States(this._stateChanged.bind(this), states); | ||
if (this.rendered) { | ||
@@ -485,0 +489,0 @@ this._stateChanged(); |
@@ -46,9 +46,5 @@ import { isArray, isString } from './utils.js'; | ||
if (force === true) { | ||
if (!this.has(state)) { | ||
this.add(state); | ||
} | ||
this.add(state); | ||
} else if (force === false) { | ||
if (this.has(state)) { | ||
this.remove(state); | ||
} | ||
this.remove(state); | ||
} else { | ||
@@ -63,2 +59,17 @@ if (this.has(state)) { | ||
merge(newStates: NodeStates) { | ||
if (isArray(newStates)) { | ||
this.length = 0; // Clear the current states | ||
this.push(...newStates); | ||
} else if (isString(newStates)) { | ||
this.length = 0; // Clear the current states | ||
this.push(newStates); | ||
} else { | ||
for (const state in newStates) { | ||
this.toggle(state, newStates[state]); | ||
} | ||
} | ||
return this; | ||
} | ||
remove(state: string) { | ||
@@ -65,0 +76,0 @@ const stateIndexToRemove = this.indexOf(state); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
203106
3207
3