Artifact
d8a62131828bf5e48f7db6628e68c46813303b910b33f8900db9ca82da953d8d:
0000: 69 6d 70 6f 72 74 20 7b 20 70 61 72 73 65 45 78 import { parseEx
0010: 70 72 65 73 73 69 6f 6e 73 2c 20 70 61 72 73 65 pressions, parse
0020: 41 74 74 72 69 62 75 74 65 73 20 7d 20 66 72 6f Attributes } fro
0030: 6d 20 27 2e 2e 2f 70 61 72 73 65 27 0a 69 6d 70 m '../parse'.imp
0040: 6f 72 74 20 52 65 66 45 78 70 72 20 66 72 6f 6d ort RefExpr from
0050: 20 27 2e 2e 2f 72 65 66 27 0a 69 6d 70 6f 72 74 '../ref'.import
0060: 20 7b 20 6d 69 78 69 6e 20 7d 20 66 72 6f 6d 20 { mixin } from
0070: 27 2e 2e 2f 63 6f 72 65 27 0a 0a 69 6d 70 6f 72 '../core'..impor
0080: 74 20 7b 20 47 4c 4f 42 41 4c 5f 4d 49 58 49 4e t { GLOBAL_MIXIN
0090: 20 7d 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f 2e 2e } from './../..
00a0: 2f 63 6f 6d 6d 6f 6e 2f 67 6c 6f 62 61 6c 2d 76 /common/global-v
00b0: 61 72 69 61 62 6c 65 73 27 0a 0a 69 6d 70 6f 72 ariables'..impor
00c0: 74 20 73 65 74 41 74 74 72 69 62 75 74 65 20 66 t setAttribute f
00d0: 72 6f 6d 20 27 2e 2f 2e 2e 2f 2e 2e 2f 63 6f 6d rom './../../com
00e0: 6d 6f 6e 2f 75 74 69 6c 2f 64 6f 6d 2f 73 65 74 mon/util/dom/set
00f0: 2d 61 74 74 72 69 62 75 74 65 27 0a 69 6d 70 6f -attribute'.impo
0100: 72 74 20 77 61 6c 6b 41 74 74 72 69 62 75 74 65 rt walkAttribute
0110: 73 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f 2e 2e 2f s from './../../
0120: 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 64 6f 6d 2f common/util/dom/
0130: 77 61 6c 6b 2d 61 74 74 72 69 62 75 74 65 73 27 walk-attributes'
0140: 0a 0a 69 6d 70 6f 72 74 20 65 61 63 68 20 66 72 ..import each fr
0150: 6f 6d 20 27 2e 2f 2e 2e 2f 2e 2e 2f 63 6f 6d 6d om './../../comm
0160: 6f 6e 2f 75 74 69 6c 2f 6d 69 73 63 2f 65 61 63 on/util/misc/eac
0170: 68 27 0a 69 6d 70 6f 72 74 20 64 65 66 69 6e 65 h'.import define
0180: 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f 2e 2e 2f 63 from './../../c
0190: 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 6d 69 73 63 2f ommon/util/misc/
01a0: 64 65 66 69 6e 65 27 0a 0a 69 6d 70 6f 72 74 20 define'..import
01b0: 67 65 74 49 6d 6d 65 64 69 61 74 65 43 75 73 74 getImmediateCust
01c0: 6f 6d 50 61 72 65 6e 74 20 66 72 6f 6d 20 27 2e omParent from '.
01d0: 2f 2e 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 /../../common/ut
01e0: 69 6c 2f 74 61 67 73 2f 67 65 74 2d 69 6d 6d 65 il/tags/get-imme
01f0: 64 69 61 74 65 2d 63 75 73 74 6f 6d 2d 70 61 72 diate-custom-par
0200: 65 6e 74 27 0a 69 6d 70 6f 72 74 20 75 70 64 61 ent'.import upda
0210: 74 65 4f 70 74 73 20 66 72 6f 6d 20 27 2e 2f 2e teOpts from './.
0220: 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c ./../common/util
0230: 2f 74 61 67 73 2f 75 70 64 61 74 65 2d 6f 70 74 /tags/update-opt
0240: 69 6f 6e 73 27 0a 69 6d 70 6f 72 74 20 73 65 74 ions'.import set
0250: 4d 6f 75 6e 74 53 74 61 74 65 20 66 72 6f 6d 20 MountState from
0260: 27 2e 2f 2e 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f './../../common/
0270: 75 74 69 6c 2f 74 61 67 73 2f 73 65 74 2d 6d 6f util/tags/set-mo
0280: 75 6e 74 2d 73 74 61 74 65 27 0a 0a 2f 2a 2a 0a unt-state'../**.
0290: 20 2a 20 4d 6f 75 6e 74 20 74 68 65 20 63 75 72 * Mount the cur
02a0: 72 65 6e 74 20 74 61 67 20 69 6e 73 74 61 6e 63 rent tag instanc
02b0: 65 0a 20 2a 20 40 72 65 74 75 72 6e 73 20 7b 20 e. * @returns {
02c0: 54 61 67 20 7d 20 74 68 65 20 63 75 72 72 65 6e Tag } the curren
02d0: 74 20 74 61 67 20 69 6e 73 74 61 6e 63 65 0a 20 t tag instance.
02e0: 2a 2f 0a 65 78 70 6f 72 74 20 64 65 66 61 75 6c */.export defaul
02f0: 74 20 66 75 6e 63 74 69 6f 6e 20 63 6f 6d 70 6f t function compo
0300: 6e 65 6e 74 4d 6f 75 6e 74 28 74 61 67 2c 20 64 nentMount(tag, d
0310: 6f 6d 2c 20 65 78 70 72 65 73 73 69 6f 6e 73 2c om, expressions,
0320: 20 6f 70 74 73 29 20 7b 0a 20 20 63 6f 6e 73 74 opts) {. const
0330: 20 5f 5f 20 3d 20 74 61 67 2e 5f 5f 0a 20 20 63 __ = tag.__. c
0340: 6f 6e 73 74 20 72 6f 6f 74 20 3d 20 5f 5f 2e 72 onst root = __.r
0350: 6f 6f 74 0a 20 20 72 6f 6f 74 2e 5f 74 61 67 20 oot. root._tag
0360: 3d 20 74 61 67 20 2f 2f 20 6b 65 65 70 20 61 20 = tag // keep a
0370: 72 65 66 65 72 65 6e 63 65 20 74 6f 20 74 68 65 reference to the
0380: 20 74 61 67 20 6a 75 73 74 20 63 72 65 61 74 65 tag just create
0390: 64 0a 0a 20 20 2f 2f 20 52 65 61 64 20 61 6c 6c d.. // Read all
03a0: 20 74 68 65 20 61 74 74 72 73 20 6f 6e 20 74 68 the attrs on th
03b0: 69 73 20 69 6e 73 74 61 6e 63 65 2e 20 54 68 69 is instance. Thi
03c0: 73 20 67 69 76 65 20 75 73 20 74 68 65 20 69 6e s give us the in
03d0: 66 6f 20 77 65 20 6e 65 65 64 20 66 6f 72 20 75 fo we need for u
03e0: 70 64 61 74 65 4f 70 74 73 0a 20 20 70 61 72 73 pdateOpts. pars
03f0: 65 41 74 74 72 69 62 75 74 65 73 2e 61 70 70 6c eAttributes.appl
0400: 79 28 5f 5f 2e 70 61 72 65 6e 74 2c 20 5b 72 6f y(__.parent, [ro
0410: 6f 74 2c 20 72 6f 6f 74 2e 61 74 74 72 69 62 75 ot, root.attribu
0420: 74 65 73 2c 20 28 61 74 74 72 2c 20 65 78 70 72 tes, (attr, expr
0430: 29 20 3d 3e 20 7b 0a 20 20 20 20 69 66 20 28 21 ) => {. if (!
0440: 5f 5f 2e 69 73 41 6e 6f 6e 79 6d 6f 75 73 20 26 __.isAnonymous &
0450: 26 20 52 65 66 45 78 70 72 2e 69 73 50 72 6f 74 & RefExpr.isProt
0460: 6f 74 79 70 65 4f 66 28 65 78 70 72 29 29 20 65 otypeOf(expr)) e
0470: 78 70 72 2e 74 61 67 20 3d 20 74 61 67 0a 20 20 xpr.tag = tag.
0480: 20 20 61 74 74 72 2e 65 78 70 72 20 3d 20 65 78 attr.expr = ex
0490: 70 72 0a 20 20 20 20 5f 5f 2e 69 6e 73 74 41 74 pr. __.instAt
04a0: 74 72 73 2e 70 75 73 68 28 61 74 74 72 29 0a 20 trs.push(attr).
04b0: 20 7d 5d 29 0a 0a 20 20 2f 2f 20 75 70 64 61 74 }]).. // updat
04c0: 65 20 74 68 65 20 72 6f 6f 74 20 61 64 64 69 6e e the root addin
04d0: 67 20 63 75 73 74 6f 6d 20 61 74 74 72 69 62 75 g custom attribu
04e0: 74 65 73 20 63 6f 6d 69 6e 67 20 66 72 6f 6d 20 tes coming from
04f0: 74 68 65 20 63 6f 6d 70 69 6c 65 72 0a 20 20 77 the compiler. w
0500: 61 6c 6b 41 74 74 72 69 62 75 74 65 73 28 5f 5f alkAttributes(__
0510: 2e 69 6d 70 6c 2e 61 74 74 72 73 2c 20 28 6b 2c .impl.attrs, (k,
0520: 20 76 29 20 3d 3e 20 7b 20 5f 5f 2e 69 6d 70 6c v) => { __.impl
0530: 41 74 74 72 73 2e 70 75 73 68 28 7b 6e 61 6d 65 Attrs.push({name
0540: 3a 20 6b 2c 20 76 61 6c 75 65 3a 20 76 7d 29 20 : k, value: v})
0550: 7d 29 0a 20 20 70 61 72 73 65 41 74 74 72 69 62 }). parseAttrib
0560: 75 74 65 73 2e 61 70 70 6c 79 28 74 61 67 2c 20 utes.apply(tag,
0570: 5b 72 6f 6f 74 2c 20 5f 5f 2e 69 6d 70 6c 41 74 [root, __.implAt
0580: 74 72 73 2c 20 28 61 74 74 72 2c 20 65 78 70 72 trs, (attr, expr
0590: 29 20 3d 3e 20 7b 0a 20 20 20 20 69 66 20 28 65 ) => {. if (e
05a0: 78 70 72 29 20 65 78 70 72 65 73 73 69 6f 6e 73 xpr) expressions
05b0: 2e 70 75 73 68 28 65 78 70 72 29 0a 20 20 20 20 .push(expr).
05c0: 65 6c 73 65 20 73 65 74 41 74 74 72 69 62 75 74 else setAttribut
05d0: 65 28 72 6f 6f 74 2c 20 61 74 74 72 2e 6e 61 6d e(root, attr.nam
05e0: 65 2c 20 61 74 74 72 2e 76 61 6c 75 65 29 0a 20 e, attr.value).
05f0: 20 7d 5d 29 0a 0a 20 20 2f 2f 20 69 6e 69 74 69 }]).. // initi
0600: 61 6c 69 61 74 69 6f 6e 0a 20 20 75 70 64 61 74 aliation. updat
0610: 65 4f 70 74 73 2e 61 70 70 6c 79 28 74 61 67 2c eOpts.apply(tag,
0620: 20 5b 5f 5f 2e 69 73 4c 6f 6f 70 2c 20 5f 5f 2e [__.isLoop, __.
0630: 70 61 72 65 6e 74 2c 20 5f 5f 2e 69 73 41 6e 6f parent, __.isAno
0640: 6e 79 6d 6f 75 73 2c 20 6f 70 74 73 2c 20 5f 5f nymous, opts, __
0650: 2e 69 6e 73 74 41 74 74 72 73 5d 29 0a 0a 20 20 .instAttrs])..
0660: 2f 2f 20 61 64 64 20 67 6c 6f 62 61 6c 20 6d 69 // add global mi
0670: 78 69 6e 73 0a 20 20 63 6f 6e 73 74 20 67 6c 6f xins. const glo
0680: 62 61 6c 4d 69 78 69 6e 20 3d 20 6d 69 78 69 6e balMixin = mixin
0690: 28 47 4c 4f 42 41 4c 5f 4d 49 58 49 4e 29 0a 0a (GLOBAL_MIXIN)..
06a0: 20 20 69 66 20 28 67 6c 6f 62 61 6c 4d 69 78 69 if (globalMixi
06b0: 6e 20 26 26 20 21 5f 5f 2e 73 6b 69 70 41 6e 6f n && !__.skipAno
06c0: 6e 79 6d 6f 75 73 29 20 7b 0a 20 20 20 20 66 6f nymous) {. fo
06d0: 72 20 28 63 6f 6e 73 74 20 69 20 69 6e 20 67 6c r (const i in gl
06e0: 6f 62 61 6c 4d 69 78 69 6e 29 20 7b 0a 20 20 20 obalMixin) {.
06f0: 20 20 20 69 66 20 28 67 6c 6f 62 61 6c 4d 69 78 if (globalMix
0700: 69 6e 2e 68 61 73 4f 77 6e 50 72 6f 70 65 72 74 in.hasOwnPropert
0710: 79 28 69 29 29 20 7b 0a 20 20 20 20 20 20 20 20 y(i)) {.
0720: 74 61 67 2e 6d 69 78 69 6e 28 67 6c 6f 62 61 6c tag.mixin(global
0730: 4d 69 78 69 6e 5b 69 5d 29 0a 20 20 20 20 20 20 Mixin[i]).
0740: 7d 0a 20 20 20 20 7d 0a 20 20 7d 0a 0a 20 20 69 }. }. }.. i
0750: 66 20 28 5f 5f 2e 69 6d 70 6c 2e 66 6e 29 20 5f f (__.impl.fn) _
0760: 5f 2e 69 6d 70 6c 2e 66 6e 2e 63 61 6c 6c 28 74 _.impl.fn.call(t
0770: 61 67 2c 20 6f 70 74 73 29 0a 0a 20 20 69 66 20 ag, opts).. if
0780: 28 21 5f 5f 2e 73 6b 69 70 41 6e 6f 6e 79 6d 6f (!__.skipAnonymo
0790: 75 73 29 20 74 61 67 2e 74 72 69 67 67 65 72 28 us) tag.trigger(
07a0: 27 62 65 66 6f 72 65 2d 6d 6f 75 6e 74 27 29 0a 'before-mount').
07b0: 0a 20 20 2f 2f 20 70 61 72 73 65 20 6c 61 79 6f . // parse layo
07c0: 75 74 20 61 66 74 65 72 20 69 6e 69 74 2e 20 66 ut after init. f
07d0: 6e 20 6d 61 79 20 63 61 6c 63 75 6c 61 74 65 20 n may calculate
07e0: 61 72 67 73 20 66 6f 72 20 6e 65 73 74 65 64 20 args for nested
07f0: 63 75 73 74 6f 6d 20 74 61 67 73 0a 20 20 65 61 custom tags. ea
0800: 63 68 28 70 61 72 73 65 45 78 70 72 65 73 73 69 ch(parseExpressi
0810: 6f 6e 73 2e 61 70 70 6c 79 28 74 61 67 2c 20 5b ons.apply(tag, [
0820: 64 6f 6d 2c 20 5f 5f 2e 69 73 41 6e 6f 6e 79 6d dom, __.isAnonym
0830: 6f 75 73 5d 29 2c 20 65 20 3d 3e 20 65 78 70 72 ous]), e => expr
0840: 65 73 73 69 6f 6e 73 2e 70 75 73 68 28 65 29 29 essions.push(e))
0850: 0a 0a 20 20 74 61 67 2e 75 70 64 61 74 65 28 5f .. tag.update(_
0860: 5f 2e 69 74 65 6d 29 0a 0a 20 20 69 66 20 28 21 _.item).. if (!
0870: 5f 5f 2e 69 73 41 6e 6f 6e 79 6d 6f 75 73 20 26 __.isAnonymous &
0880: 26 20 21 5f 5f 2e 69 73 49 6e 6c 69 6e 65 29 20 & !__.isInline)
0890: 7b 0a 20 20 20 20 77 68 69 6c 65 20 28 64 6f 6d {. while (dom
08a0: 2e 66 69 72 73 74 43 68 69 6c 64 29 20 72 6f 6f .firstChild) roo
08b0: 74 2e 61 70 70 65 6e 64 43 68 69 6c 64 28 64 6f t.appendChild(do
08c0: 6d 2e 66 69 72 73 74 43 68 69 6c 64 29 0a 20 20 m.firstChild).
08d0: 7d 0a 0a 20 20 64 65 66 69 6e 65 28 74 61 67 2c }.. define(tag,
08e0: 20 27 72 6f 6f 74 27 2c 20 72 6f 6f 74 29 0a 0a 'root', root)..
08f0: 20 20 2f 2f 20 69 66 20 77 65 20 6e 65 65 64 20 // if we need
0900: 74 6f 20 77 61 69 74 20 74 68 61 74 20 74 68 65 to wait that the
0910: 20 70 61 72 65 6e 74 20 22 6d 6f 75 6e 74 22 20 parent "mount"
0920: 6f 72 20 22 75 70 64 61 74 65 64 22 20 65 76 65 or "updated" eve
0930: 6e 74 20 67 65 74 73 20 74 72 69 67 67 65 72 65 nt gets triggere
0940: 64 0a 20 20 69 66 20 28 21 5f 5f 2e 73 6b 69 70 d. if (!__.skip
0950: 41 6e 6f 6e 79 6d 6f 75 73 20 26 26 20 74 61 67 Anonymous && tag
0960: 2e 70 61 72 65 6e 74 29 20 7b 0a 20 20 20 20 63 .parent) {. c
0970: 6f 6e 73 74 20 70 20 3d 20 67 65 74 49 6d 6d 65 onst p = getImme
0980: 64 69 61 74 65 43 75 73 74 6f 6d 50 61 72 65 6e diateCustomParen
0990: 74 28 74 61 67 2e 70 61 72 65 6e 74 29 0a 20 20 t(tag.parent).
09a0: 20 20 70 2e 6f 6e 65 28 21 70 2e 69 73 4d 6f 75 p.one(!p.isMou
09b0: 6e 74 65 64 20 3f 20 27 6d 6f 75 6e 74 27 20 3a nted ? 'mount' :
09c0: 20 27 75 70 64 61 74 65 64 27 2c 20 28 29 20 3d 'updated', () =
09d0: 3e 20 7b 0a 20 20 20 20 20 20 73 65 74 4d 6f 75 > {. setMou
09e0: 6e 74 53 74 61 74 65 2e 63 61 6c 6c 28 74 61 67 ntState.call(tag
09f0: 2c 20 74 72 75 65 29 0a 20 20 20 20 7d 29 0a 20 , true). }).
0a00: 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20 2f 2f } else {. //
0a10: 20 6f 74 68 65 72 77 69 73 65 20 69 74 27 73 20 otherwise it's
0a20: 6e 6f 74 20 61 20 63 68 69 6c 64 20 74 61 67 20 not a child tag
0a30: 77 65 20 63 61 6e 20 74 72 69 67 67 65 72 20 69 we can trigger i
0a40: 74 73 20 6d 6f 75 6e 74 20 65 76 65 6e 74 0a 20 ts mount event.
0a50: 20 20 20 73 65 74 4d 6f 75 6e 74 53 74 61 74 65 setMountState
0a60: 2e 63 61 6c 6c 28 74 61 67 2c 20 74 72 75 65 29 .call(tag, true)
0a70: 0a 20 20 7d 0a 0a 20 20 74 61 67 2e 5f 5f 2e 77 . }.. tag.__.w
0a80: 61 73 43 72 65 61 74 65 64 20 3d 20 74 72 75 65 asCreated = true
0a90: 0a 0a 20 20 72 65 74 75 72 6e 20 74 61 67 0a 7d .. return tag.}