added support for all HTML5 tags and drag&drop events

This commit is contained in:
Andreas Rumpf 2017-04-14 19:39:00 +02:00
commit 74c5fb48ff

View file

@ -23,10 +23,6 @@ proc getName(n: NimNode): string =
proc newDotAsgn(tmp: NimNode, key: string, x: NimNode): NimNode = proc newDotAsgn(tmp: NimNode, key: string, x: NimNode): NimNode =
result = newTree(nnkAsgn, newDotExpr(tmp, newIdentNode key), x) result = newTree(nnkAsgn, newDotExpr(tmp, newIdentNode key), x)
proc isTag(s: string): bool =
for i in VNodeKind.low.succ..VNodeKind.high:
if $i == s: return true
proc tcall2(n, tmpContext: NimNode): NimNode = proc tcall2(n, tmpContext: NimNode): NimNode =
# we need to distinguish statement and expression contexts: # we need to distinguish statement and expression contexts:
# every call statement 's' needs to be transformed to 'dest.add s'. # every call statement 's' needs to be transformed to 'dest.add s'.
@ -62,10 +58,9 @@ proc tcall2(n, tmpContext: NimNode): NimNode =
of nnkCallKinds: of nnkCallKinds:
let op = getName(n[0]) let op = getName(n[0])
let ck = isComponent(op) let ck = isComponent(op)
let isTag = isTag(op) if ck != ComponentKind.None:
if isTag or ck != ComponentKind.None:
let tmp = genSym(nskLet, "tmp") let tmp = genSym(nskLet, "tmp")
let call = if isTag: let call = if ck == ComponentKind.Tag:
newCall(bindSym"tree", newDotExpr(bindSym"VNodeKind", n[0])) newCall(bindSym"tree", newDotExpr(bindSym"VNodeKind", n[0]))
elif ck == ComponentKind.VNode: elif ck == ComponentKind.VNode:
newCall(bindSym"vthunk", newLit(op)) newCall(bindSym"vthunk", newLit(op))
@ -85,7 +80,7 @@ proc tcall2(n, tmpContext: NimNode): NimNode =
result.add newDotAsgn(tmp, key, x[1]) result.add newDotAsgn(tmp, key, x[1])
else: else:
result.add newCall(bindSym"setAttr", tmp, newLit(key), x[1]) result.add newCall(bindSym"setAttr", tmp, newLit(key), x[1])
elif not isTag: elif ck != ComponentKind.Tag:
call.add x call.add x
elif eqIdent(x, "setFocus"): elif eqIdent(x, "setFocus"):
result.add newCall(x, tmp) result.add newCall(x, tmp)