From 6cb52e685ddb7aebfce72ea0a1f1a0393c0d2c91 Mon Sep 17 00:00:00 2001 From: Raymond Pasco Date: Thu, 6 Aug 2015 15:39:35 -0400 Subject: [PATCH 1/4] Pill and formatting --- arvo/hoon.hoon | 84 +++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/arvo/hoon.hoon b/arvo/hoon.hoon index f91e6e2bc..0ee402f83 100644 --- a/arvo/hoon.hoon +++ b/arvo/hoon.hoon @@ -1278,7 +1278,7 @@ [%n ~] == :: -++ fl :: arbitrary precision floating point +++ fl :: arb. precision fp =+ ^- [[p=@u v=@s w=@u] r=?(%n %u %d %z %a) d=?(%d %f %i)] [[113 -16.494 32.765] %n %d] :: p=precision: number of bits in arithmetic form; must be at least 2 @@ -1306,14 +1306,14 @@ ++ add :: add; exact if e |= [a=[e=@s a=@u] b=[e=@s a=@u] e=?] ^- fn =+ q=(dif:si e.a e.b) - |- ?. (syn:si q) $(b a, a b, q +(q)) :: a has larger exponent + |- ?. (syn:si q) $(b a, a b, q +(q)) :: a has larger exp ?: e [%f & e.b (^add (lsh 0 (abs:si q) a.a) a.b)] =+ [ma=(met 0 a.a) mb=(met 0 a.b)] - =+ ^= w %+ dif:si e.a %- sun:si :: expanded exponent of a + =+ ^= w %+ dif:si e.a %- sun:si :: expanded exp of a ?: (gth prc ma) (^sub prc ma) 0 - =+ ^= x %+ sum:si e.b (sun:si mb) :: highest exponent that b reaches - ?: =((cmp:si w x) --1) :: don't actually need to add + =+ ^= x %+ sum:si e.b (sun:si mb) :: highest exp for b + ?: =((cmp:si w x) --1) :: don't need to add ?- r %z (lug %fl a &) %d (lug %fl a &) %a (lug %lg a &) %u (lug %lg a &) @@ -1425,7 +1425,7 @@ |= [t=?(%fl %ce %sm %lg %ne %na %nt) a=[e=@s a=@u] s=?] ^- fn ?< =(a.a 0) =- - ?. =(den %f) - :: if %f, flush denormals + ?. =(den %f) - :: flush denormals ?. ?=([%f *] -) - ?: =((met 0 ->+>) prc) - [%f & zer] :: @@ -1466,7 +1466,7 @@ %ce ?: &(=(b 0) s) a a(a +(a.a)) %ne ?~ b a =+ y=(bex (dec q)) - ?: &(=(b y) s) :: halfway rounds to even + ?: &(=(b y) s) :: round halfs to even ?~ (dis a.a 1) a a(a +(a.a)) ?: (^lth b y) a a(a +(a.a)) %na ?~ b a @@ -1485,8 +1485,8 @@ ?: =(den %i) [%f & a] ?: =((cmp:si emx e.a) -1) [%i &] [%f & a] :: enforce max. exp :: - ++ drg :: dragon4; convert to decimal - ~/ %drg + ++ drg :: dragon4; + ~/ %drg :: convert to decimal |= [a=[e=@s a=@u]] ^- [@s @u] ?< =(a.a 0) =. a ?: (^lth (met 0 a.a) prc) (xpd a) a @@ -1548,15 +1548,15 @@ |= [a=fn] ^- fn ?-(-.a %f a(s !s.a), %i a(s !s.a), %n a) :: - ++ swr ?+(r r %d %u, %u %d) :: flipped rounding mode - ++ prc ?>((gth p 1) p) :: enforce precision at least 2 - ++ den d :: denorms/flush/inf exponent range + ++ swr ?+(r r %d %u, %u %d) :: flipped rounding + ++ prc ?>((gth p 1) p) :: force >= 2 precision + ++ den d :: denorm/flush/inf exp ++ emn v :: minimum exponent ++ emx (sum:si emn (sun:si w)) :: maximum exponent ++ spd [e=emn a=1] :: smallest denormal ++ spn [e=emn a=(bex (dec prc))] :: smallest normal ++ lfn [e=emx a=(fil 0 prc 1)] :: largest - ++ lfe (sum:si emx (sun:si prc)) :: 2^lfe is larger than all floats + ++ lfe (sum:si emx (sun:si prc)) :: 2^lfe is > than all ++ zer [e=--0 a=0] -- |% @@ -1668,11 +1668,11 @@ |= [a=fn] ^- fn (div [%f & --0 1] a) :: - ++ sun :: unsigned integer to float + ++ sun :: uns integer to float |= [a=@u] ^- fn (rou [%f & --0 a]) :: - ++ san :: signed integer to float + ++ san :: sgn integer to float |= [a=@s] ^- fn =+ b=(old:si a) (rou [%f -.b --0 +.b]) @@ -1748,7 +1748,7 @@ =.(r swr (fli (^toj +>.a))) -- :: -++ ff :: ieee 754 format floating point +++ ff :: ieee 754 format fp |_ [[w=@u p=@u b=@s] r=?(%n %u %d %z %a)] :: this core has no use outside of the functionality :: provided to ++rd, ++rs, ++rq, and ++rh @@ -1776,9 +1776,9 @@ =+ r=(^add f (bex p)) [%f s q r] :: - ++ bit |= [a=fn] (bif (rou:pa a)) :: fn to @r with rounding + ++ bit |= [a=fn] (bif (rou:pa a)) :: fn to @r w/ rounding :: - ++ bif :: fn to @r without rounding + ++ bif :: fn to @r no rounding |= [a=fn] ^- @r ?: ?=([%i *] a) =+ q=(lsh 0 p (fil 0 w 1)) @@ -1836,7 +1836,7 @@ |= [a=@r b=@r] (fall (gte:pa (sea a) (sea b)) |) ++ gth :: greater-than |= [a=@r b=@r] (fall (gth:pa (sea a) (sea b)) |) - ++ sun :: unsigned integer to @r + ++ sun :: uns integer to @r |= [a=@u] (bit [%f & --0 a]) ++ san :: signed integer to @r |= [a=@s] (bit [%f (syn:si a) --0 (abs:si a)]) @@ -1848,16 +1848,16 @@ |= [a=dn] (bif (grd:pa a)) -- :: -++ rlyd |= a=@rd ^- dn (drg:rd a) :: prepare @rd for printing -++ rlys |= a=@rs ^- dn (drg:rs a) :: prepare @rs for printing -++ rlyh |= a=@rh ^- dn (drg:rh a) :: prepare @rh for printing -++ rlyq |= a=@rq ^- dn (drg:rq a) :: prepare @rq for printing -++ ryld |= a=dn ^- @rd (grd:rd a) :: finish parsing of @rd -++ ryls |= a=dn ^- @rs (grd:rs a) :: finish parsing of @rs -++ rylh |= a=dn ^- @rh (grd:rh a) :: finish parsing of @rh -++ rylq |= a=dn ^- @rq (grd:rq a) :: finish parsing of @rq +++ rlyd |= a=@rd ^- dn (drg:rd a) :: prep @rd for print +++ rlys |= a=@rs ^- dn (drg:rs a) :: prep @rs for print +++ rlyh |= a=@rh ^- dn (drg:rh a) :: prep @rh for print +++ rlyq |= a=@rq ^- dn (drg:rq a) :: prep @rq for print +++ ryld |= a=dn ^- @rd (grd:rd a) :: finish parsing @rd +++ ryls |= a=dn ^- @rs (grd:rs a) :: finish parsing @rs +++ rylh |= a=dn ^- @rh (grd:rh a) :: finish parsing @rh +++ rylq |= a=dn ^- @rq (grd:rq a) :: finish parsing @rq :: -++ rd :: double precision floating point +++ rd :: double precision fp ~% %rd +> ~ |_ r=?(%n %u %d %z) :: round to nearest, round up, round down, round to zero @@ -1906,8 +1906,8 @@ ++ gth ~/ %gth :: greater-than |= [a=@rd b=@rd] ~| %rd-fail (gth:ma a b) :: - ++ sun |= [a=@u] ^- @rd (sun:ma a) :: unsigned integer to @rd - ++ san |= [a=@s] ^- @rd (san:ma a) :: signed integer to @rd + ++ sun |= [a=@u] ^- @rd (sun:ma a) :: uns integer to @rd + ++ san |= [a=@s] ^- @rd (san:ma a) :: sgn integer to @rd ++ sig |= [a=@rd] ^- ? (sig:ma a) :: get sign ++ exp |= [a=@rd] ^- @s (exp:ma a) :: get exponent ++ toi |= [a=@rd] ^- (unit ,@s) (toi:ma a) :: round to integer @@ -1915,7 +1915,7 @@ ++ grd |= [a=dn] ^- @rd (grd:ma a) :: decimal float to @rd -- :: -++ rs :: single precision floating point +++ rs :: single precision fp ~% %rs +> ~ |_ r=?(%n %u %d %z) :: round to nearest, round up, round down, round to zero @@ -1964,8 +1964,8 @@ ++ gth ~/ %gth :: greater-than |= [a=@rs b=@rs] ~| %rs-fail (gth:ma a b) :: - ++ sun |= [a=@u] ^- @rs (sun:ma a) :: unsigned integer to @rs - ++ san |= [a=@s] ^- @rs (san:ma a) :: signed integer to @rs + ++ sun |= [a=@u] ^- @rs (sun:ma a) :: uns integer to @rs + ++ san |= [a=@s] ^- @rs (san:ma a) :: sgn integer to @rs ++ sig |= [a=@rs] ^- ? (sig:ma a) :: get sign ++ exp |= [a=@rs] ^- @s (exp:ma a) :: get exponent ++ toi |= [a=@rs] ^- (unit ,@s) (toi:ma a) :: round to integer @@ -1973,7 +1973,7 @@ ++ grd |= [a=dn] ^- @rs (grd:ma a) :: decimal float to @rs -- :: -++ rq :: quadruple precision floating point +++ rq :: quad precision fp ~% %rq +> ~ |_ r=?(%n %u %d %z) :: round to nearest, round up, round down, round to zero @@ -2022,8 +2022,8 @@ ++ gth ~/ %gth :: greater-than |= [a=@rq b=@rq] ~| %rq-fail (gth:ma a b) :: - ++ sun |= [a=@u] ^- @rq (sun:ma a) :: unsigned integer to @rq - ++ san |= [a=@s] ^- @rq (san:ma a) :: signed integer to @rq + ++ sun |= [a=@u] ^- @rq (sun:ma a) :: uns integer to @rq + ++ san |= [a=@s] ^- @rq (san:ma a) :: sgn integer to @rq ++ sig |= [a=@rq] ^- ? (sig:ma a) :: get sign ++ exp |= [a=@rq] ^- @s (exp:ma a) :: get exponent ++ toi |= [a=@rq] ^- (unit ,@s) (toi:ma a) :: round to integer @@ -2031,7 +2031,7 @@ ++ grd |= [a=dn] ^- @rq (grd:ma a) :: decimal float to @rq -- :: -++ rh :: half precision floating point +++ rh :: half precision fp |_ r=?(%n %u %d %z) :: round to nearest, round up, round down, round to zero :: @@ -2061,8 +2061,8 @@ ++ gth ~/ %gth :: greater-than |= [a=@rh b=@rh] ~| %rh-fail (gth:ma a b) :: - ++ sun |= [a=@u] ^- @rh (sun:ma a) :: unsigned integer to @rh - ++ san |= [a=@s] ^- @rh (san:ma a) :: signed integer to @rh + ++ sun |= [a=@u] ^- @rh (sun:ma a) :: uns integer to @rh + ++ san |= [a=@s] ^- @rh (san:ma a) :: sgn integer to @rh ++ sig |= [a=@rh] ^- ? (sig:ma a) :: get sign ++ exp |= [a=@rh] ^- @s (exp:ma a) :: get exponent ++ toi |= [a=@rh] ^- (unit ,@s) (toi:ma a) :: round to integer @@ -2248,7 +2248,7 @@ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: section 2cJ, extra math :: :: -++ sqt :: square root w/remainder +++ sqt :: sqrt w/remainder ~/ %sqt |= a=@ ^- [p=@ q=@] ?~ a [0 0] @@ -5864,8 +5864,8 @@ ?: (lth b 256) [[b (end 0 b d)] ~] [[256 d] $(c d, b (sub b 256))] - ++ raws :: random bits continuation - |= b=@ + ++ raws :: random bits + |= b=@ :: continuation =+ r=(raw b) [r +>.$(a (shas %og-s r))] -- From f9631a60c0407616a8e686892cf3cdfe30bbdfa7 Mon Sep 17 00:00:00 2001 From: Galen Wolfe-Pauly Date: Thu, 6 Aug 2015 16:27:13 -0700 Subject: [PATCH 2/4] re tree --- lib/tree.hoon | 2 +- pub/tree/src/js/main.js | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/tree.hoon b/lib/tree.hoon index d422db0fb..24518dde7 100644 --- a/lib/tree.hoon +++ b/lib/tree.hoon @@ -17,7 +17,7 @@ ++ json-front |= a=json ^- json =- (fall `(unit json)`- ~) - %+ biff ((ar some):jo a) + %+ biff ((ot c/(ar some) ~):jo a) %+ find-in-tree (ot c/(ar some) gn/so ga/(om so) ~):jo |= [nom=span atr=(map span cord)] ^- (unit json) ?. (~(has by atr) 'urb:front') ~ diff --git a/pub/tree/src/js/main.js b/pub/tree/src/js/main.js index 9e65a9d32..81955fcd0 100644 --- a/pub/tree/src/js/main.js +++ b/pub/tree/src/js/main.js @@ -35,7 +35,6 @@ module.exports = { }; - },{"../dispatcher/Dispatcher.coffee":11,"../persistence/TreePersistence.coffee":17}],2:[function(require,module,exports){ var BodyComponent, Links, TreeActions, TreeStore, a, clas, div, query, recl, ref; @@ -284,7 +283,6 @@ module.exports = query({ })); - },{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":18,"./Async.coffee":3,"./BodyComponent.coffee":4,"classnames":13}],3:[function(require,module,exports){ var TreeActions, TreeStore, _load, code, div, recl, ref, span; @@ -375,7 +373,6 @@ module.exports = function(queries, Child, load) { }; - },{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":18,"./LoadComponent.coffee":8}],4:[function(require,module,exports){ var div, query, reactify, recl; @@ -403,7 +400,6 @@ module.exports = query({ })); - },{"./Async.coffee":3,"./Reactify.coffee":9}],5:[function(require,module,exports){ var div, recl, ref, textarea; @@ -427,7 +423,6 @@ module.exports = recl({ }); - },{}],6:[function(require,module,exports){ var a, div, hr, li, query, reactify, recl, ref, ul; @@ -471,7 +466,6 @@ module.exports = query({ })); - },{"./Async.coffee":3}],7:[function(require,module,exports){ var a, clas, div, h1, li, query, reactify, recl, ref, ul; @@ -571,7 +565,6 @@ module.exports = query({ })); - },{"./Async.coffee":3,"classnames":13}],8:[function(require,module,exports){ var div, input, recl, ref, textarea; @@ -612,7 +605,6 @@ module.exports = recl({ }); - },{}],9:[function(require,module,exports){ var codemirror, components, div, kids, list, load, lost, recl, ref, span, toc; @@ -667,7 +659,6 @@ module.exports = recl({ }); - },{"./CodeMirror.coffee":5,"./KidsComponent.coffee":6,"./ListComponent.coffee":7,"./LoadComponent.coffee":8,"./TocComponent.coffee":10}],10:[function(require,module,exports){ var div, query, reactify, recl; @@ -802,7 +793,6 @@ module.exports = query({ })); - },{"./Async.coffee":3}],11:[function(require,module,exports){ var Dispatcher; @@ -824,7 +814,6 @@ module.exports = _.extend(new Dispatcher(), { }); - },{"flux":14}],12:[function(require,module,exports){ var rend; @@ -971,7 +960,6 @@ $(function() { }); - },{"./actions/TreeActions.coffee":1,"./components/AnchorComponent.coffee":2,"./components/BodyComponent.coffee":4,"./components/Reactify.coffee":9,"./persistence/TreePersistence.coffee":17}],13:[function(require,module,exports){ /*! Copyright (c) 2015 Jed Watson. @@ -1392,7 +1380,6 @@ module.exports = { }; - },{}],18:[function(require,module,exports){ var EventEmitter, MessageDispatcher, TreeStore, _curr, _data, _tree, clog; @@ -1619,7 +1606,6 @@ TreeStore.dispatchToken = MessageDispatcher.register(function(payload) { module.exports = TreeStore; - },{"../dispatcher/Dispatcher.coffee":11,"events":19}],19:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // From 5c02fb0473c04735c7c95f4b8089b2e59d238fe6 Mon Sep 17 00:00:00 2001 From: Anton Dyudin Date: Thu, 6 Aug 2015 17:09:29 -0700 Subject: [PATCH 3/4] refactored component circular include, type-check queries, added sect:'r' section headers --- lib/tree.hoon | 5 +- mar/headers.hoon | 31 +++ mar/react-headers.hoon | 20 ++ pub/doc/tree.md | 30 +-- .../src/js/components/AnchorComponent.coffee | 13 +- pub/tree/src/js/components/Async.coffee | 2 +- .../src/js/components/BodyComponent.coffee | 9 +- pub/tree/src/js/components/Components.coffee | 8 + .../src/js/components/KidsComponent.coffee | 2 +- .../src/js/components/ListComponent.coffee | 4 +- pub/tree/src/js/components/Reactify.coffee | 48 ++-- .../src/js/components/TocComponent.coffee | 4 +- pub/tree/src/js/main.coffee | 2 +- pub/tree/src/js/main.js | 242 ++++++++++-------- pub/tree/src/js/stores/TreeStore.coffee | 11 +- sur/tree-include.hoon | 1 + tree-gen/tree-include.hook | 3 +- tree/json.hook | 4 +- 18 files changed, 256 insertions(+), 183 deletions(-) create mode 100644 mar/headers.hoon create mode 100644 mar/react-headers.hoon create mode 100644 pub/tree/src/js/components/Components.coffee diff --git a/lib/tree.hoon b/lib/tree.hoon index d422db0fb..96f40dd67 100644 --- a/lib/tree.hoon +++ b/lib/tree.hoon @@ -4,7 +4,8 @@ ++ baff |*([a=(unit) b=(trap)] ?^(a a *b)) ++ find-in-tree |* [paz=fist:jo fun=$+(* (unit))] - |= a=(list json) + |= jon=json + =+ a=`(list json)`~[jon] |^ (try) ++ try |. ^+ *fun @@ -17,7 +18,7 @@ ++ json-front |= a=json ^- json =- (fall `(unit json)`- ~) - %+ biff ((ar some):jo a) + %. a %+ find-in-tree (ot c/(ar some) gn/so ga/(om so) ~):jo |= [nom=span atr=(map span cord)] ^- (unit json) ?. (~(has by atr) 'urb:front') ~ diff --git a/mar/headers.hoon b/mar/headers.hoon new file mode 100644 index 000000000..8cf3bd693 --- /dev/null +++ b/mar/headers.hoon @@ -0,0 +1,31 @@ +:: +:::: /hoon/core/elem/mar + :: +/? 314 +!: +|% +++ getall + |= tag=mane + |= ele=manx ^- marl + ?: =(tag n.g.ele) ~[ele] + (zing (turn c.ele ..$)) +-- +:: +!: +|_ hed=marl +:: +++ grow :: convert to + |% + ++ mime + =< mime + |% + ++ elem ;div:"*{hed}" + ++ hymn ;html:(head:title:"headers" body:"+{elem}") :: convert to %hymn + ++ html (crip (poxo hymn)) :: convert to %html + ++ mime [/text/html (taco html)] :: convert to %mime + -- + -- +++ grab |% :: convert from + ++ noun marl :: clam from %noun + ++ elem (getall %h1) +-- -- diff --git a/mar/react-headers.hoon b/mar/react-headers.hoon new file mode 100644 index 000000000..5ea607627 --- /dev/null +++ b/mar/react-headers.hoon @@ -0,0 +1,20 @@ +:: +:::: /hoon/core/react-headers/mar + :: +/? 314 +/+ react +!: +:::: + :: +|_ hed=marl +:: +++ grow :: convert to + |% + ++ mime [/application/json (tact tape)] + ++ tape (pojo react-headers-json) + ++ react-headers-json (react-to-json ;div:"*{hed}") + -- +++ grab |% :: convert from + ++ noun marl + ++ headers |=(a=marl a) +-- -- diff --git a/pub/doc/tree.md b/pub/doc/tree.md index da8119bfa..fa6f071f0 100644 --- a/pub/doc/tree.md +++ b/pub/doc/tree.md @@ -14,12 +14,12 @@ a `getPath` method, if present (defaulting to current url), is used to determine something something coffeescript ## `/[desk]/tree/{path}.json` -tree/json.hook accepts a query string schema `q` in light noun encoding¹ +tree/json.hook accepts a query string schema `q` in light noun encoding ++ schema (dict ,[term $|(mark schema)]) ++ dict |*(a=_,* $&([a (dict a)] a)) -which is normalized and type-checked(request types are `%t` text, `%r` html-derived tree, and `%j` arbitrary json) to a `query` list of +which is normalized and type-checked to a `query` list of - `[%kids query]`, the only recursive value, which executes for all subpaths XX descent is only currently supported to a single level as a performance optimization - `[%name %t]`, the node name @@ -29,26 +29,6 @@ which is normalized and type-checked(request types are `%t` text, `%r` html-deri - `[%body %r]`, the `react-json` body - `[%meta %j]`, json frontmatter per the `mdy` mark definition -Per this specification, the current access points will be migrated: -- (json.hook)`""` to `body:'r' kids:{name:'t'}` `"?body.r__kids_name.t"` -- `"?kids"` to `kids:{name:'t' body:'r'}` `"?kids_name.t_body.r"` -- `"?snip"` to `kids:{name:'t' snip:'r' head:'r' meta:'j'}` `"?kids_name.t_snip.r_head.r_meta.j"` - -¹In the examples, - - =< (cook to-noun (cook to-tree apex)) - |% - ++ data $|(term [n=@ l=data r=data]) - ++ apex ;~(plug sym (star ;~(plug delim sym))) - ++ delim ;~(pose (cold 0 dot) (cook lent (plus cab))) - ++ to-noun |=(a=data ?@(a a [$(a l.a) $(a r.a)])) - ++ to-tree - |= [acc=data a=(list ,[p=@u q=term])] - %+ roll a =< .(acc ^acc) - |= [[n=@u v=term] acc=data] - ?@ acc [n acc v] - ?: (gth n n.acc) [n acc v] - acc(r $(acc r.acc)) - -- - -XX Curtis, this can be full coin `%many` if you wish. +The request types above are `%t` text, `%r` html-derived tree, and `%j` +arbitrary json; an example query, used by the main content renderer, is +`"q=body.r__kids_name.t"` (`body:'r' kids:{name:'t'}` ) diff --git a/pub/tree/src/js/components/AnchorComponent.coffee b/pub/tree/src/js/components/AnchorComponent.coffee index 28d8009a2..b3202d320 100644 --- a/pub/tree/src/js/components/AnchorComponent.coffee +++ b/pub/tree/src/js/components/AnchorComponent.coffee @@ -2,6 +2,7 @@ clas = require 'classnames' BodyComponent = React.createFactory require './BodyComponent.coffee' query = require './Async.coffee' +reactify = require './Reactify.coffee' TreeStore = require '../stores/TreeStore.coffee' TreeActions = require '../actions/TreeActions.coffee' @@ -37,12 +38,10 @@ Links = React.createFactory query { className = clas active: key is @props.curr (div {className,key}, (a {href,onClick:@props.onClick}, head)) - toText: (elem)-> switch - # manx: {fork: ["string", {gn:"string" ga:{dict:"string"} c:{list:"manx"}}]} - when !elem? then "" - when typeof elem == "string" then elem - when elem.gn? then (elem.c ? []).map(@toText).join "" - else throw "Bad react-json #{JSON.stringify elem}" + toText: (elem)-> reactify.walk elem, + ()->'' + (s)->s + ({c})->(c ? []).join '' ), recl displayName: "Links_loading" render: -> div {className:'links'}, @props.children, @_render() @@ -60,8 +59,8 @@ module.exports = query {sein:'t',path:'t',name:'t',next:'t',prev:'t'},recl toggleFocus: (state) -> $(@getDOMNode()).toggleClass 'focus',state - componentDidUpdate: -> @setTitle() componentWillUnmount: -> clearInterval @interval; $('body').off 'click', 'a' + componentDidUpdate: -> @setTitle() componentDidMount: -> @setTitle() @interval = setInterval @checkURL,100 diff --git a/pub/tree/src/js/components/Async.coffee b/pub/tree/src/js/components/Async.coffee index 6f1f6cc6b..1437b2fb5 100644 --- a/pub/tree/src/js/components/Async.coffee +++ b/pub/tree/src/js/components/Async.coffee @@ -51,5 +51,5 @@ module.exports = (queries, Child, load=_load)-> recl if @filterQueries()? React.createElement load, @props else React.createElement Child, - (_.merge {}, @props, @state.got), + (_.extend {}, @props, @state.got), @props.children diff --git a/pub/tree/src/js/components/BodyComponent.coffee b/pub/tree/src/js/components/BodyComponent.coffee index 62c91785a..2757ff4b1 100644 --- a/pub/tree/src/js/components/BodyComponent.coffee +++ b/pub/tree/src/js/components/BodyComponent.coffee @@ -1,10 +1,9 @@ -reactify = React.createFactory require './Reactify.coffee' -query = require './Async.coffee' +query = require './Async.coffee' +reactify = require './Reactify.coffee' -recl = React.createClass +recl = React.createClass {div} = React.DOM module.exports = query {body:'r',path:'t'}, recl displayName: "Body" - render: -> (div {}, (div {id:'body',key:"body"+@props.path}, - (reactify manx: @props.body))) + render: -> (div {}, (div {id:'body',key:"body"+@props.path}, reactify @props.body)) diff --git a/pub/tree/src/js/components/Components.coffee b/pub/tree/src/js/components/Components.coffee new file mode 100644 index 000000000..dad510449 --- /dev/null +++ b/pub/tree/src/js/components/Components.coffee @@ -0,0 +1,8 @@ +recl = React.createClass + +module.exports = + codemirror: require './CodeMirror.coffee' + list: require './ListComponent.coffee' + kids: require './KidsComponent.coffee' + toc: require './TocComponent.coffee' + lost: recl render: -> (div {}, "lost") diff --git a/pub/tree/src/js/components/KidsComponent.coffee b/pub/tree/src/js/components/KidsComponent.coffee index 54d127622..e9e206f1f 100644 --- a/pub/tree/src/js/components/KidsComponent.coffee +++ b/pub/tree/src/js/components/KidsComponent.coffee @@ -1,4 +1,4 @@ -reactify = (manx)-> React.createElement window.tree.reactify, {manx} +reactify = require './Reactify.coffee' query = require './Async.coffee' recl = React.createClass diff --git a/pub/tree/src/js/components/ListComponent.coffee b/pub/tree/src/js/components/ListComponent.coffee index bf45ae7b2..f00859272 100644 --- a/pub/tree/src/js/components/ListComponent.coffee +++ b/pub/tree/src/js/components/ListComponent.coffee @@ -1,6 +1,6 @@ clas = require 'classnames' -reactify = (manx)-> React.createElement window.tree.reactify, {manx} +reactify = require './Reactify.coffee' query = require './Async.coffee' recl = React.createClass @@ -49,7 +49,7 @@ module.exports = query { else parts.push elem.snip if @props.titlesOnly - parts = elem.head + parts = [elem.head] li {key:item,className:@props.dataType ? ""}, a {href,className:(clas preview: @props.dataPreview?)}, reactify diff --git a/pub/tree/src/js/components/Reactify.coffee b/pub/tree/src/js/components/Reactify.coffee index bbd83cd84..4e4d727f6 100644 --- a/pub/tree/src/js/components/Reactify.coffee +++ b/pub/tree/src/js/components/Reactify.coffee @@ -1,28 +1,30 @@ recl = React.createClass +rele = React.createElement {div,span} = React.DOM -load = React.createFactory require './LoadComponent.coffee' +load = React.createFactory require './LoadComponent.coffee' -codemirror = require './CodeMirror.coffee' -list = require './ListComponent.coffee' -kids = require './KidsComponent.coffee' -toc = require './TocComponent.coffee' -lost = recl render: -> (div {}, "lost") -components = - kids:kids - list:list - lost:lost - toc:toc - codemirror:codemirror - -module.exports = recl - displayName: "Virtual" - render: -> @walk @props.manx - walk: (elem,key) -> switch - # manx: {fork: ["string", {gn:"string" ga:{dict:"string"} c:{list:"manx"}}]} - when !elem? then (load {}, "") - when typeof elem == "string" then elem +walk = (root,_nil,_str,_comp)-> + # manx: {fork: ["string", {gn:"string" ga:{dict:"string"} c:{list:"manx"}}]} + _walk = (elem,key)-> switch + when !elem? then _nil() + when typeof elem == "string" then _str elem when elem.gn? - React.createElement components[elem.gn] ? elem.gn, - $.extend {key}, elem.ga - elem.c?.map @walk + {gn,ga,c} = elem + c = c?.map _walk ? [] + _comp {gn,ga,c}, key else throw "Bad react-json #{JSON.stringify elem}" + _walk root + +Virtual = recl + displayName: "Virtual" + render: -> + {components} = window.tree + walk @props.manx, + ()-> (load {},"") + (str)-> str + ({gn,ga,c},key)-> rele (components[gn] ? gn), + (_.extend {key}, ga), + c + +reactify = (manx)-> rele Virtual, {manx} +module.exports = _.extend reactify, {walk,Virtual} diff --git a/pub/tree/src/js/components/TocComponent.coffee b/pub/tree/src/js/components/TocComponent.coffee index 7f68b5b91..7f41bf37d 100644 --- a/pub/tree/src/js/components/TocComponent.coffee +++ b/pub/tree/src/js/components/TocComponent.coffee @@ -1,11 +1,11 @@ query = require './Async.coffee' +reactify = require './Reactify.coffee' recl = React.createClass {div} = React.DOM -reactify = (manx)-> React.createElement window.tree.reactify, {manx} -module.exports = query {body:'t'}, recl +module.exports = query {body:'r'}, recl hash:null displayName: "TableOfContents" diff --git a/pub/tree/src/js/main.coffee b/pub/tree/src/js/main.coffee index 617667963..b3a27a245 100644 --- a/pub/tree/src/js/main.coffee +++ b/pub/tree/src/js/main.coffee @@ -7,7 +7,7 @@ $ -> head = React.createFactory require './components/AnchorComponent.coffee' body = React.createFactory require './components/BodyComponent.coffee' - window.tree.reactify = require './components/Reactify.coffee' # sigh + window.tree.components = require './components/Components.coffee' # sigh window.tree._basepath = window.urb.util.basepath("/") window.tree._basepath += diff --git a/pub/tree/src/js/main.js b/pub/tree/src/js/main.js index 9e65a9d32..901aaa7d6 100644 --- a/pub/tree/src/js/main.js +++ b/pub/tree/src/js/main.js @@ -36,8 +36,8 @@ module.exports = { -},{"../dispatcher/Dispatcher.coffee":11,"../persistence/TreePersistence.coffee":17}],2:[function(require,module,exports){ -var BodyComponent, Links, TreeActions, TreeStore, a, clas, div, query, recl, ref; +},{"../dispatcher/Dispatcher.coffee":12,"../persistence/TreePersistence.coffee":18}],2:[function(require,module,exports){ +var BodyComponent, Links, TreeActions, TreeStore, a, clas, div, query, reactify, recl, ref; clas = require('classnames'); @@ -45,6 +45,8 @@ BodyComponent = React.createFactory(require('./BodyComponent.coffee')); query = require('./Async.coffee'); +reactify = require('./Reactify.coffee'); + TreeStore = require('../stores/TreeStore.coffee'); TreeActions = require('../actions/TreeActions.coffee'); @@ -114,17 +116,15 @@ Links = React.createFactory(query({ })(this))); }, toText: function(elem) { - var ref1; - switch (false) { - case !(elem == null): - return ""; - case typeof elem !== "string": - return elem; - case elem.gn == null: - return ((ref1 = elem.c) != null ? ref1 : []).map(this.toText).join(""); - default: - throw "Bad react-json " + (JSON.stringify(elem)); - } + return reactify.walk(elem, function() { + return ''; + }, function(s) { + return s; + }, function(arg) { + var c; + c = arg.c; + return (c != null ? c : []).join(''); + }); } }), recl({ displayName: "Links_loading", @@ -174,13 +174,13 @@ module.exports = query({ toggleFocus: function(state) { return $(this.getDOMNode()).toggleClass('focus', state); }, - componentDidUpdate: function() { - return this.setTitle(); - }, componentWillUnmount: function() { clearInterval(this.interval); return $('body').off('click', 'a'); }, + componentDidUpdate: function() { + return this.setTitle(); + }, componentDidMount: function() { this.setTitle(); this.interval = setInterval(this.checkURL, 100); @@ -285,7 +285,7 @@ module.exports = query({ -},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":18,"./Async.coffee":3,"./BodyComponent.coffee":4,"classnames":13}],3:[function(require,module,exports){ +},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":19,"./Async.coffee":3,"./BodyComponent.coffee":4,"./Reactify.coffee":10,"classnames":14}],3:[function(require,module,exports){ var TreeActions, TreeStore, _load, code, div, recl, ref, span; _load = require('./LoadComponent.coffee'); @@ -369,20 +369,20 @@ module.exports = function(queries, Child, load) { } }, render: function() { - return div({}, this.filterQueries() != null ? React.createElement(load, this.props) : React.createElement(Child, _.merge({}, this.props, this.state.got), this.props.children)); + return div({}, this.filterQueries() != null ? React.createElement(load, this.props) : React.createElement(Child, _.extend({}, this.props, this.state.got), this.props.children)); } }); }; -},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":18,"./LoadComponent.coffee":8}],4:[function(require,module,exports){ +},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":19,"./LoadComponent.coffee":9}],4:[function(require,module,exports){ var div, query, reactify, recl; -reactify = React.createFactory(require('./Reactify.coffee')); - query = require('./Async.coffee'); +reactify = require('./Reactify.coffee'); + recl = React.createClass; div = React.DOM.div; @@ -396,15 +396,13 @@ module.exports = query({ return div({}, div({ id: 'body', key: "body" + this.props.path - }, reactify({ - manx: this.props.body - }))); + }, reactify(this.props.body))); } })); -},{"./Async.coffee":3,"./Reactify.coffee":9}],5:[function(require,module,exports){ +},{"./Async.coffee":3,"./Reactify.coffee":10}],5:[function(require,module,exports){ var div, recl, ref, textarea; recl = React.createClass; @@ -429,13 +427,28 @@ module.exports = recl({ },{}],6:[function(require,module,exports){ +var recl; + +recl = React.createClass; + +module.exports = { + codemirror: require('./CodeMirror.coffee'), + list: require('./ListComponent.coffee'), + kids: require('./KidsComponent.coffee'), + toc: require('./TocComponent.coffee'), + lost: recl({ + render: function() { + return div({}, "lost"); + } + }) +}; + + + +},{"./CodeMirror.coffee":5,"./KidsComponent.coffee":7,"./ListComponent.coffee":8,"./TocComponent.coffee":11}],7:[function(require,module,exports){ var a, div, hr, li, query, reactify, recl, ref, ul; -reactify = function(manx) { - return React.createElement(window.tree.reactify, { - manx: manx - }); -}; +reactify = require('./Reactify.coffee'); query = require('./Async.coffee'); @@ -472,16 +485,12 @@ module.exports = query({ -},{"./Async.coffee":3}],7:[function(require,module,exports){ +},{"./Async.coffee":3,"./Reactify.coffee":10}],8:[function(require,module,exports){ var a, clas, div, h1, li, query, reactify, recl, ref, ul; clas = require('classnames'); -reactify = function(manx) { - return React.createElement(window.tree.reactify, { - manx: manx - }); -}; +reactify = require('./Reactify.coffee'); query = require('./Async.coffee'); @@ -551,7 +560,7 @@ module.exports = query({ } } if (this.props.titlesOnly) { - parts = elem.head; + parts = [elem.head]; } results.push(li({ key: item, @@ -572,7 +581,7 @@ module.exports = query({ -},{"./Async.coffee":3,"classnames":13}],8:[function(require,module,exports){ +},{"./Async.coffee":3,"./Reactify.coffee":10,"classnames":14}],9:[function(require,module,exports){ var div, input, recl, ref, textarea; recl = React.createClass; @@ -613,78 +622,86 @@ module.exports = recl({ -},{}],9:[function(require,module,exports){ -var codemirror, components, div, kids, list, load, lost, recl, ref, span, toc; +},{}],10:[function(require,module,exports){ +var Virtual, div, load, reactify, recl, ref, rele, span, walk; recl = React.createClass; +rele = React.createElement; + ref = React.DOM, div = ref.div, span = ref.span; load = React.createFactory(require('./LoadComponent.coffee')); -codemirror = require('./CodeMirror.coffee'); - -list = require('./ListComponent.coffee'); - -kids = require('./KidsComponent.coffee'); - -toc = require('./TocComponent.coffee'); - -lost = recl({ - render: function() { - return div({}, "lost"); - } -}); - -components = { - kids: kids, - list: list, - lost: lost, - toc: toc, - codemirror: codemirror -}; - -module.exports = recl({ - displayName: "Virtual", - render: function() { - return this.walk(this.props.manx); - }, - walk: function(elem, key) { - var ref1, ref2; +walk = function(root, _nil, _str, _comp) { + var _walk; + _walk = function(elem, key) { + var c, ga, gn; switch (false) { case !(elem == null): - return load({}, ""); + return _nil(); case typeof elem !== "string": - return elem; + return _str(elem); case elem.gn == null: - return React.createElement((ref1 = components[elem.gn]) != null ? ref1 : elem.gn, $.extend({ - key: key - }, elem.ga), (ref2 = elem.c) != null ? ref2.map(this.walk) : void 0); + gn = elem.gn, ga = elem.ga, c = elem.c; + c = c != null ? c.map(_walk != null ? _walk : []) : void 0; + return _comp({ + gn: gn, + ga: ga, + c: c + }, key); default: throw "Bad react-json " + (JSON.stringify(elem)); } + }; + return _walk(root); +}; + +Virtual = recl({ + displayName: "Virtual", + render: function() { + var components; + components = window.tree.components; + return walk(this.props.manx, function() { + return load({}, ""); + }, function(str) { + return str; + }, function(arg, key) { + var c, ga, gn, ref1; + gn = arg.gn, ga = arg.ga, c = arg.c; + return rele((ref1 = components[gn]) != null ? ref1 : gn, _.extend({ + key: key + }, ga), c); + }); } }); +reactify = function(manx) { + return rele(Virtual, { + manx: manx + }); +}; + +module.exports = _.extend(reactify, { + walk: walk, + Virtual: Virtual +}); + -},{"./CodeMirror.coffee":5,"./KidsComponent.coffee":6,"./ListComponent.coffee":7,"./LoadComponent.coffee":8,"./TocComponent.coffee":10}],10:[function(require,module,exports){ +},{"./LoadComponent.coffee":9}],11:[function(require,module,exports){ var div, query, reactify, recl; query = require('./Async.coffee'); +reactify = require('./Reactify.coffee'); + recl = React.createClass; div = React.DOM.div; -reactify = function(manx) { - return React.createElement(window.tree.reactify, { - manx: manx - }); -}; - module.exports = query({ - body: 't' + body: 'r' }, recl({ hash: null, displayName: "TableOfContents", @@ -803,7 +820,7 @@ module.exports = query({ -},{"./Async.coffee":3}],11:[function(require,module,exports){ +},{"./Async.coffee":3,"./Reactify.coffee":10}],12:[function(require,module,exports){ var Dispatcher; Dispatcher = require('flux').Dispatcher; @@ -825,7 +842,7 @@ module.exports = _.extend(new Dispatcher(), { -},{"flux":14}],12:[function(require,module,exports){ +},{"flux":15}],13:[function(require,module,exports){ var rend; rend = React.render; @@ -836,7 +853,7 @@ $(function() { React.initializeTouchEvents(true); head = React.createFactory(require('./components/AnchorComponent.coffee')); body = React.createFactory(require('./components/BodyComponent.coffee')); - window.tree.reactify = require('./components/Reactify.coffee'); + window.tree.components = require('./components/Components.coffee'); window.tree._basepath = window.urb.util.basepath("/"); window.tree._basepath += (window.location.pathname.replace(window.tree._basepath, "")).split("/")[0]; window.tree.basepath = function(path) { @@ -972,7 +989,7 @@ $(function() { -},{"./actions/TreeActions.coffee":1,"./components/AnchorComponent.coffee":2,"./components/BodyComponent.coffee":4,"./components/Reactify.coffee":9,"./persistence/TreePersistence.coffee":17}],13:[function(require,module,exports){ +},{"./actions/TreeActions.coffee":1,"./components/AnchorComponent.coffee":2,"./components/BodyComponent.coffee":4,"./components/Components.coffee":6,"./persistence/TreePersistence.coffee":18}],14:[function(require,module,exports){ /*! Copyright (c) 2015 Jed Watson. Licensed under the MIT License (MIT), see @@ -1023,7 +1040,7 @@ $(function() { }()); -},{}],14:[function(require,module,exports){ +},{}],15:[function(require,module,exports){ /** * Copyright (c) 2014-2015, Facebook, Inc. * All rights reserved. @@ -1035,7 +1052,7 @@ $(function() { module.exports.Dispatcher = require('./lib/Dispatcher') -},{"./lib/Dispatcher":15}],15:[function(require,module,exports){ +},{"./lib/Dispatcher":16}],16:[function(require,module,exports){ /* * Copyright (c) 2014, Facebook, Inc. * All rights reserved. @@ -1287,7 +1304,7 @@ var _prefix = 'ID_'; module.exports = Dispatcher; -},{"./invariant":16}],16:[function(require,module,exports){ +},{"./invariant":17}],17:[function(require,module,exports){ /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. @@ -1342,7 +1359,7 @@ var invariant = function(condition, format, a, b, c, d, e, f) { module.exports = invariant; -},{}],17:[function(require,module,exports){ +},{}],18:[function(require,module,exports){ module.exports = { get: function(path, query, cb) { var url; @@ -1393,8 +1410,8 @@ module.exports = { -},{}],18:[function(require,module,exports){ -var EventEmitter, MessageDispatcher, TreeStore, _curr, _data, _tree, clog; +},{}],19:[function(require,module,exports){ +var EventEmitter, MessageDispatcher, QUERIES, TreeStore, _curr, _data, _tree, clog; EventEmitter = require('events').EventEmitter; @@ -1408,6 +1425,14 @@ _data = {}; _curr = ""; +QUERIES = { + body: 'r', + head: 'r', + snip: 'r', + sect: 'r', + meta: 'j' +}; + TreeStore = _.extend(EventEmitter.prototype, { addChangeListener: function(cb) { return this.on('change', cb); @@ -1425,14 +1450,17 @@ TreeStore = _.extend(EventEmitter.prototype, { return this.fulfillAt(this.getTree(path.split('/')), path, query); }, fulfillAt: function(tree, path, query) { - var data, i, k, len, ref, ref1, sub; + var data, k, ref, sub, t; data = this.fulfillLocal(path, query); - ref = ["body", "head", "snip", "meta"]; - for (i = 0, len = ref.length; i < len; i++) { - k = ref[i]; - if (query[k]) { - data[k] = (ref1 = _data[path]) != null ? ref1[k] : void 0; + for (k in query) { + t = query[k]; + if (!QUERIES[k]) { + continue; } + if (t !== QUERIES[k]) { + throw TypeError("Wrong query type: " + k + ", '" + t + "'"); + } + data[k] = (ref = _data[path]) != null ? ref[k] : void 0; } if (query.kids) { data.kids = {}; @@ -1475,18 +1503,16 @@ TreeStore = _.extend(EventEmitter.prototype, { return this.loadValues(this.getTree(path.split('/'), true), path, data); }, loadValues: function(tree, path, data) { - var i, k, len, old, ref, ref1, ref2, v; + var k, old, ref, ref1, v; old = (ref = _data[path]) != null ? ref : {}; - ref1 = ["body", "head", "snip", "meta"]; - for (i = 0, len = ref1.length; i < len; i++) { - k = ref1[i]; - if (data[k] !== void 0) { + for (k in data) { + if (QUERIES[k]) { old[k] = data[k]; } } - ref2 = data.kids; - for (k in ref2) { - v = ref2[k]; + ref1 = data.kids; + for (k in ref1) { + v = ref1[k]; if (tree[k] == null) { tree[k] = {}; } @@ -1620,7 +1646,7 @@ module.exports = TreeStore; -},{"../dispatcher/Dispatcher.coffee":11,"events":19}],19:[function(require,module,exports){ +},{"../dispatcher/Dispatcher.coffee":12,"events":20}],20:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -1923,4 +1949,4 @@ function isUndefined(arg) { return arg === void 0; } -},{}]},{},[12]); +},{}]},{},[13]); diff --git a/pub/tree/src/js/stores/TreeStore.coffee b/pub/tree/src/js/stores/TreeStore.coffee index 85f480c30..4976a8bc2 100644 --- a/pub/tree/src/js/stores/TreeStore.coffee +++ b/pub/tree/src/js/stores/TreeStore.coffee @@ -7,6 +7,8 @@ _tree = {} _data = {} _curr = "" +QUERIES = {body:'r', head:'r', snip:'r', sect:'r', meta:'j'} + TreeStore = _.extend EventEmitter.prototype, { addChangeListener: (cb) -> @on 'change', cb @@ -19,8 +21,9 @@ TreeStore = _.extend EventEmitter.prototype, { fulfill: (path,query) -> @fulfillAt (@getTree path.split '/'),path,query fulfillAt: (tree,path,query)-> data = @fulfillLocal path, query - for k in ["body", "head" ,"snip" ,"meta"] - data[k] = _data[path]?[k] if query[k] + for k,t of query when QUERIES[k] + if t isnt QUERIES[k] then throw TypeError "Wrong query type: #{k}, '#{t}'" + data[k] = _data[path]?[k] if query.kids data.kids = {} for k,sub of tree @@ -43,8 +46,8 @@ TreeStore = _.extend EventEmitter.prototype, { @loadValues (@getTree (path.split '/'),true), path, data loadValues: (tree,path,data) -> old = _data[path] ? {} - for k in ["body", "head" ,"snip" ,"meta"] - old[k] = data[k] if data[k] isnt undefined + for k of data when QUERIES[k] + old[k] = data[k] for k,v of data.kids tree[k] ?= {} diff --git a/sur/tree-include.hoon b/sur/tree-include.hoon index 9b3c9bccc..3e6337595 100644 --- a/sur/tree-include.hoon +++ b/sur/tree-include.hoon @@ -3,4 +3,5 @@ $: body=json head=json snip=json meta=json + sect=json == diff --git a/tree-gen/tree-include.hook b/tree-gen/tree-include.hook index def41f95d..ee15ea769 100644 --- a/tree-gen/tree-include.hook +++ b/tree-gen/tree-include.hook @@ -2,6 +2,7 @@ /= body /: /=== /% /react-json/ /= head /: /=== /% /react-head-json/ /= snip /: /=== /% /react-snip-json/ +/= sect /: /=== /% /react-headers-json/ /= meta /: /=== /% /; json-front /react-snip-json/ ^- tree-include -[body head snip meta] +[body head snip meta sect] diff --git a/tree/json.hook b/tree/json.hook index f49a22078..892ff179d 100644 --- a/tree/json.hook +++ b/tree/json.hook @@ -21,6 +21,7 @@ $% [%kids p=(list query)] [%name %t] [%path %t] + [%sect %r] [%snip %r] [%head %r] [%body %r] @@ -53,13 +54,14 @@ %path (from-type +.a (crip (spud (flop s.bem)))) %head (from-type +.a head.dat) %snip (from-type +.a snip.dat) + %sect (from-type +.a sect.dat) %meta (from-type +.a meta.dat) %body (from-type +.a body.dat) %kids ?< (~(has by (mo p.a)) %kids) :: XX recursion? =< o/(~(urn by kid) .) |= [dir=span dak=tree-include] ^^$(quy p.a, s.bem [dir s.bem], dat dak, kid ~) - == + == -- !: :::: From 544bcfba626f8cacd4181c3d167873f0ca758ad3 Mon Sep 17 00:00:00 2001 From: Anton Dyudin Date: Thu, 6 Aug 2015 18:21:51 -0700 Subject: [PATCH 4/4] search v1 --- pub/tree/src/js/components/Components.coffee | 1 + pub/tree/src/js/components/Reactify.coffee | 4 +- .../src/js/components/SearchComponent.coffee | 34 +++++ pub/tree/src/js/main.js | 137 +++++++++++++++--- 4 files changed, 156 insertions(+), 20 deletions(-) create mode 100644 pub/tree/src/js/components/SearchComponent.coffee diff --git a/pub/tree/src/js/components/Components.coffee b/pub/tree/src/js/components/Components.coffee index dad510449..e169fd194 100644 --- a/pub/tree/src/js/components/Components.coffee +++ b/pub/tree/src/js/components/Components.coffee @@ -2,6 +2,7 @@ recl = React.createClass module.exports = codemirror: require './CodeMirror.coffee' + search: require './SearchComponent.coffee' list: require './ListComponent.coffee' kids: require './KidsComponent.coffee' toc: require './TocComponent.coffee' diff --git a/pub/tree/src/js/components/Reactify.coffee b/pub/tree/src/js/components/Reactify.coffee index 4e4d727f6..f4157b55f 100644 --- a/pub/tree/src/js/components/Reactify.coffee +++ b/pub/tree/src/js/components/Reactify.coffee @@ -11,7 +11,7 @@ walk = (root,_nil,_str,_comp)-> when elem.gn? {gn,ga,c} = elem c = c?.map _walk ? [] - _comp {gn,ga,c}, key + _comp.call elem, {gn,ga,c}, key else throw "Bad react-json #{JSON.stringify elem}" _walk root @@ -26,5 +26,5 @@ Virtual = recl (_.extend {key}, ga), c -reactify = (manx)-> rele Virtual, {manx} +reactify = (manx,key)-> rele Virtual, {manx,key} module.exports = _.extend reactify, {walk,Virtual} diff --git a/pub/tree/src/js/components/SearchComponent.coffee b/pub/tree/src/js/components/SearchComponent.coffee new file mode 100644 index 000000000..153efa564 --- /dev/null +++ b/pub/tree/src/js/components/SearchComponent.coffee @@ -0,0 +1,34 @@ +query = require './Async.coffee' +reactify = require './Reactify.coffee' + +recl = React.createClass +{div,input} = React.DOM + + +module.exports = query {kids: sect:'r'}, recl + hash:null + displayName: "Search" + getInitialState: -> search: 'dva' + onKeyUp: (e)-> @setState search: e.target.value + render: -> div {}, + input {@onKeyUp,ref:'inp',defaultValue:'dva'} + _(c for x,{sect:{c}} of @props.kids) + .flatten() + .map(@highlight) + .filter() + .map(reactify) + .value() + + highlight: (e)-> + return e unless @state.search + got = false + res = reactify.walk e, + ()-> null + (s)=> + m = s.split @state.search + return [s] unless m[1]? + lit = gn:'span',c:[@state.search],ga:style:background: '#ff6' + got = true + [m[0], _.flatten([lit,s] for s in m[1..])...] + ({gn,ga,c})->{gn,ga,c:_.flatten c} + res if got diff --git a/pub/tree/src/js/main.js b/pub/tree/src/js/main.js index 901aaa7d6..6e12b7697 100644 --- a/pub/tree/src/js/main.js +++ b/pub/tree/src/js/main.js @@ -36,7 +36,7 @@ module.exports = { -},{"../dispatcher/Dispatcher.coffee":12,"../persistence/TreePersistence.coffee":18}],2:[function(require,module,exports){ +},{"../dispatcher/Dispatcher.coffee":13,"../persistence/TreePersistence.coffee":19}],2:[function(require,module,exports){ var BodyComponent, Links, TreeActions, TreeStore, a, clas, div, query, reactify, recl, ref; clas = require('classnames'); @@ -285,7 +285,7 @@ module.exports = query({ -},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":19,"./Async.coffee":3,"./BodyComponent.coffee":4,"./Reactify.coffee":10,"classnames":14}],3:[function(require,module,exports){ +},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":20,"./Async.coffee":3,"./BodyComponent.coffee":4,"./Reactify.coffee":10,"classnames":15}],3:[function(require,module,exports){ var TreeActions, TreeStore, _load, code, div, recl, ref, span; _load = require('./LoadComponent.coffee'); @@ -376,7 +376,7 @@ module.exports = function(queries, Child, load) { -},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":19,"./LoadComponent.coffee":9}],4:[function(require,module,exports){ +},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":20,"./LoadComponent.coffee":9}],4:[function(require,module,exports){ var div, query, reactify, recl; query = require('./Async.coffee'); @@ -433,6 +433,7 @@ recl = React.createClass; module.exports = { codemirror: require('./CodeMirror.coffee'), + search: require('./SearchComponent.coffee'), list: require('./ListComponent.coffee'), kids: require('./KidsComponent.coffee'), toc: require('./TocComponent.coffee'), @@ -445,7 +446,7 @@ module.exports = { -},{"./CodeMirror.coffee":5,"./KidsComponent.coffee":7,"./ListComponent.coffee":8,"./TocComponent.coffee":11}],7:[function(require,module,exports){ +},{"./CodeMirror.coffee":5,"./KidsComponent.coffee":7,"./ListComponent.coffee":8,"./SearchComponent.coffee":11,"./TocComponent.coffee":12}],7:[function(require,module,exports){ var a, div, hr, li, query, reactify, recl, ref, ul; reactify = require('./Reactify.coffee'); @@ -581,7 +582,7 @@ module.exports = query({ -},{"./Async.coffee":3,"./Reactify.coffee":10,"classnames":14}],9:[function(require,module,exports){ +},{"./Async.coffee":3,"./Reactify.coffee":10,"classnames":15}],9:[function(require,module,exports){ var div, input, recl, ref, textarea; recl = React.createClass; @@ -645,7 +646,7 @@ walk = function(root, _nil, _str, _comp) { case elem.gn == null: gn = elem.gn, ga = elem.ga, c = elem.c; c = c != null ? c.map(_walk != null ? _walk : []) : void 0; - return _comp({ + return _comp.call(elem, { gn: gn, ga: ga, c: c @@ -676,9 +677,10 @@ Virtual = recl({ } }); -reactify = function(manx) { +reactify = function(manx, key) { return rele(Virtual, { - manx: manx + manx: manx, + key: key }); }; @@ -690,6 +692,105 @@ module.exports = _.extend(reactify, { },{"./LoadComponent.coffee":9}],11:[function(require,module,exports){ +var div, input, query, reactify, recl, ref, + slice = [].slice; + +query = require('./Async.coffee'); + +reactify = require('./Reactify.coffee'); + +recl = React.createClass; + +ref = React.DOM, div = ref.div, input = ref.input; + +module.exports = query({ + kids: { + sect: 'r' + } +}, recl({ + hash: null, + displayName: "Search", + getInitialState: function() { + return { + search: 'dva' + }; + }, + onKeyUp: function(e) { + return this.setState({ + search: e.target.value + }); + }, + render: function() { + var c, x; + return div({}, input({ + onKeyUp: this.onKeyUp, + ref: 'inp', + defaultValue: 'dva' + }), _((function() { + var ref1, results; + ref1 = this.props.kids; + results = []; + for (x in ref1) { + c = ref1[x].sect.c; + results.push(c); + } + return results; + }).call(this)).flatten().map(this.highlight).filter().map(reactify).value()); + }, + highlight: function(e) { + var got, res; + if (!this.state.search) { + return e; + } + got = false; + res = reactify.walk(e, function() { + return null; + }, (function(_this) { + return function(s) { + var lit, m; + m = s.split(_this.state.search); + if (m[1] == null) { + return [s]; + } + lit = { + gn: 'span', + c: [_this.state.search], + ga: { + style: { + background: '#ff6' + } + } + }; + got = true; + return [m[0]].concat(slice.call(_.flatten((function() { + var i, len, ref1, results; + ref1 = m.slice(1); + results = []; + for (i = 0, len = ref1.length; i < len; i++) { + s = ref1[i]; + results.push([lit, s]); + } + return results; + })()))); + }; + })(this), function(arg) { + var c, ga, gn; + gn = arg.gn, ga = arg.ga, c = arg.c; + return { + gn: gn, + ga: ga, + c: _.flatten(c) + }; + }); + if (got) { + return res; + } + } +})); + + + +},{"./Async.coffee":3,"./Reactify.coffee":10}],12:[function(require,module,exports){ var div, query, reactify, recl; query = require('./Async.coffee'); @@ -820,7 +921,7 @@ module.exports = query({ -},{"./Async.coffee":3,"./Reactify.coffee":10}],12:[function(require,module,exports){ +},{"./Async.coffee":3,"./Reactify.coffee":10}],13:[function(require,module,exports){ var Dispatcher; Dispatcher = require('flux').Dispatcher; @@ -842,7 +943,7 @@ module.exports = _.extend(new Dispatcher(), { -},{"flux":15}],13:[function(require,module,exports){ +},{"flux":16}],14:[function(require,module,exports){ var rend; rend = React.render; @@ -989,7 +1090,7 @@ $(function() { -},{"./actions/TreeActions.coffee":1,"./components/AnchorComponent.coffee":2,"./components/BodyComponent.coffee":4,"./components/Components.coffee":6,"./persistence/TreePersistence.coffee":18}],14:[function(require,module,exports){ +},{"./actions/TreeActions.coffee":1,"./components/AnchorComponent.coffee":2,"./components/BodyComponent.coffee":4,"./components/Components.coffee":6,"./persistence/TreePersistence.coffee":19}],15:[function(require,module,exports){ /*! Copyright (c) 2015 Jed Watson. Licensed under the MIT License (MIT), see @@ -1040,7 +1141,7 @@ $(function() { }()); -},{}],15:[function(require,module,exports){ +},{}],16:[function(require,module,exports){ /** * Copyright (c) 2014-2015, Facebook, Inc. * All rights reserved. @@ -1052,7 +1153,7 @@ $(function() { module.exports.Dispatcher = require('./lib/Dispatcher') -},{"./lib/Dispatcher":16}],16:[function(require,module,exports){ +},{"./lib/Dispatcher":17}],17:[function(require,module,exports){ /* * Copyright (c) 2014, Facebook, Inc. * All rights reserved. @@ -1304,7 +1405,7 @@ var _prefix = 'ID_'; module.exports = Dispatcher; -},{"./invariant":17}],17:[function(require,module,exports){ +},{"./invariant":18}],18:[function(require,module,exports){ /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. @@ -1359,7 +1460,7 @@ var invariant = function(condition, format, a, b, c, d, e, f) { module.exports = invariant; -},{}],18:[function(require,module,exports){ +},{}],19:[function(require,module,exports){ module.exports = { get: function(path, query, cb) { var url; @@ -1410,7 +1511,7 @@ module.exports = { -},{}],19:[function(require,module,exports){ +},{}],20:[function(require,module,exports){ var EventEmitter, MessageDispatcher, QUERIES, TreeStore, _curr, _data, _tree, clog; EventEmitter = require('events').EventEmitter; @@ -1646,7 +1747,7 @@ module.exports = TreeStore; -},{"../dispatcher/Dispatcher.coffee":12,"events":20}],20:[function(require,module,exports){ +},{"../dispatcher/Dispatcher.coffee":13,"events":21}],21:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -1949,4 +2050,4 @@ function isUndefined(arg) { return arg === void 0; } -},{}]},{},[13]); +},{}]},{},[14]);