diff --git a/js-assembler/runtime-src/baselib-srclocs.js b/js-assembler/runtime-src/baselib-srclocs.js new file mode 100644 index 0000000..2a4eee1 --- /dev/null +++ b/js-assembler/runtime-src/baselib-srclocs.js @@ -0,0 +1,30 @@ +(function(baselib) { + 'use strict'; + + var exports = {}; + baselib.srclocs = exports; + + + // (define-struct srcloc (source line column position span)) + var srcloc = baselib.structs.makeStructureType( + 'srcloc', false, 5, 0, false, false); + + + var makeSrcloc = srcloc.constructor; + + var isSrcloc = srcloc.predicate; + var srclocSource = function(x) { return srcloc.accessor(x, 0); } + var srclocLine = function(x) { return srcloc.accessor(x, 1); } + var srclocColumn = function(x) { return srcloc.accessor(x, 2); } + var srclocPosition = function(x) { return srcloc.accessor(x, 3); } + var srclocSpan = function(x) { return srcloc.accessor(x, 4); } + + ////////////////////////////////////////////////////////////////////// + exports.makeSrcloc = makeSrcloc; + exports.isSrcloc = isSrcloc; + exports.srclocSource = srclocSource; + exports.srclocColumn = srclocColumn; + exports.srclocPosition = srclocPosition; + exports.srclocSpan = srclocSpan; + +}(this.plt.baselib)) \ No newline at end of file diff --git a/scribblings/cs19.scrbl b/scribblings/cs19.scrbl index b2971e2..240e78d 100644 --- a/scribblings/cs19.scrbl +++ b/scribblings/cs19.scrbl @@ -357,32 +357,55 @@ moment. } +Once we have a view, we can refocus the view to different elements by using +@racket[view-left], @racket[view-right], @racket[view-up], and @racket[view-down]. + + +@defproc[(view-left? [v view]) boolean]{ +See if the view can be moved to the previous sibling. +} @defproc[(view-left [v view]) view]{ Move the focus to the previous sibling. } +@defproc[(view-right? [v view]) boolean]{ +See if the view can be moved to the next sibling. +} @defproc[(view-right [v view]) view]{ Move the focus to the next sibling.} +@defproc[(view-up? [v view]) boolean]{ +See if the view can be moved to the parent. +} @defproc[(view-up [v view]) view]{ Move the focus to the parent.} +@defproc[(view-down? [v view]) boolean]{ +See if the view can be moved to the first child. +} @defproc[(view-down [v view]) view]{ Move the view to the first child.} + + +Once we focus the view on an element, we can bind a world handler to it that +responds to events. +@defproc[(view-bind [v view] [type string] [world-updater ([w world] [v view] [e event]? -> world)]) view]{ +Attach a world-updating event to the focus. When the world-updater is +called, the view will be focused on the element that triggered the +event. Common event types include @racket["click"], +@racket["mouseenter"], @racket["change"].} + + + +When the view is on an element that we'd like to query or update, we can use +several functions: + @defproc[(view-text [v view]) string]{ Get the textual content at the focus. } @defproc[(update-view-text [v view] [s string]) view]{ Update the textual content at the focus.} -@defproc[(view-bind [v view] [type string] [world-updater ([w world] [v view] [e event]? -> world)]) view]{ -Attach a world-updating event to the focus. - -Attach a world-updating event to the focus. When the world-updater is -called, the view will be focused on the element that triggered the -event. - -Common event types include @racket["click"], @racket["mouseenter"], @racket["change"].} @defproc[(view-show [v view]) view]{ Show the element at the focus. diff --git a/scribblings/manual.scrbl b/scribblings/manual.scrbl index 50ddbed..925c1a9 100644 --- a/scribblings/manual.scrbl +++ b/scribblings/manual.scrbl @@ -743,15 +743,26 @@ moment. } +@defproc[(view-left? [v view]) boolean]{ +See if the view can be moved to the previous sibling. +} @defproc[(view-left [v view]) view]{ Move the focus to the previous sibling. } +@defproc[(view-right? [v view]) boolean]{ +See if the view can be moved to the next sibling. +} @defproc[(view-right [v view]) view]{ Move the focus to the next sibling.} - +@defproc[(view-up? [v view]) boolean]{ +See if the view can be moved to the parent. +} @defproc[(view-up [v view]) view]{ Move the focus to the parent.} +@defproc[(view-down? [v view]) boolean]{ +See if the view can be moved to the first child. +} @defproc[(view-down [v view]) view]{ Move the view to the first child.}