Fix up types
This commit is contained in:
parent
ef88fa5aec
commit
9cb312ddd3
|
@ -127,7 +127,7 @@ function spawnUIFragmentFactory(ds: Ref) {
|
|||
let selector: string;
|
||||
let html: Array<ChildNode>;
|
||||
let orderBy: NodeOrderKey;
|
||||
let anchorNodes: Array<Element> = [];
|
||||
let anchorNodes: Array<ParentNode> = [];
|
||||
let eventRegistrations =
|
||||
new FlexMap<RegistrationKey, HandlerClosure>(JSON.stringify);
|
||||
|
||||
|
@ -310,7 +310,7 @@ function configureNode(n: ChildNode) {
|
|||
// Runs post-insertion configuration of nodes.
|
||||
// TODO: review this design.
|
||||
selectorMatch(n, '.-syndicate-focus').forEach(
|
||||
(n: Element | HTMLTextAreaElement | HTMLInputElement) => {
|
||||
(n: ParentNode | HTMLTextAreaElement | HTMLInputElement) => {
|
||||
if ('focus' in n && 'setSelectionRange' in n) {
|
||||
n.focus();
|
||||
n.setSelectionRange(n.value.length, n.value.length);
|
||||
|
@ -350,6 +350,7 @@ function _attributeLike(selector: string,
|
|||
let savedValues: Array<{node: Element, value: any}> = [];
|
||||
|
||||
selectorMatch(document.body, selector).forEach(node => {
|
||||
if (!isElement(node)) return;
|
||||
switch (kind) {
|
||||
case 'attribute':
|
||||
if (key === 'class') {
|
||||
|
@ -545,15 +546,15 @@ function spawnAttributeUpdater(ds: Ref) {
|
|||
spawn named 'AttributeUpdater' {
|
||||
at ds {
|
||||
on message P.SetAttribute($s: string, $k: string, $v: string) =>
|
||||
update(s, n => n.setAttribute(k, v));
|
||||
update(s, n => isElement(n) && n.setAttribute(k, v));
|
||||
on message P.RemoveAttribute($s: string, $k: string) =>
|
||||
update(s, n => n.removeAttribute(k));
|
||||
update(s, n => isElement(n) && n.removeAttribute(k));
|
||||
on message P.SetProperty($s: string, $k: string, $v) =>
|
||||
update(s, n => { (n as any)[k] = v });
|
||||
on message P.RemoveProperty($s: string, $k: string) =>
|
||||
update(s, n => { delete (n as any)[k]; });
|
||||
|
||||
function update(selector: string, nodeUpdater: (n: Element) => void) {
|
||||
function update(selector: string, nodeUpdater: (n: ParentNode) => void) {
|
||||
selectorMatch(document.body, selector).forEach(nodeUpdater);
|
||||
}
|
||||
}
|
||||
|
@ -576,7 +577,11 @@ function isQueryableNode(x: any): x is ParentNode {
|
|||
return x !== null && typeof x === 'object' && 'querySelectorAll' in x;
|
||||
}
|
||||
|
||||
function selectorMatch(n: Element | Node, selector: string): Array<Element> {
|
||||
function isElement(x: any): x is Element {
|
||||
return x !== null && typeof x === 'object' && 'getAttribute' in x && 'setAttribute' in x;
|
||||
}
|
||||
|
||||
function selectorMatch(n: Node, selector: string): Array<ParentNode> {
|
||||
if (isQueryableNode(n)) {
|
||||
if (selector === '.') {
|
||||
return [n];
|
||||
|
|
Loading…
Reference in New Issue