UNPKG

bucklescript-tea

Version:
1,162 lines (1,137 loc) 825 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Test_client = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; var Web = require("./web.js"); var List = require("bs-platform/lib/js/list.js"); var Vdom = require("./vdom.js"); var Curry = require("bs-platform/lib/js/curry.js"); var Tea_cmd = require("./tea_cmd.js"); var Tea_sub = require("./tea_sub.js"); var Caml_option = require("bs-platform/lib/js/caml_option.js"); var Caml_builtin_exceptions = require("bs-platform/lib/js/caml_builtin_exceptions.js"); function programStateWrapper(initModel, pump, shutdown) { var model = { contents: initModel }; var callbacks = { contents: { enqueue: (function (_msg) { console.log("INVALID enqueue CALL!"); return /* () */0; }), on: (function (param) { return /* () */0; }) } }; var pumperInterface = Curry._1(pump, callbacks); var pending = { contents: undefined }; var handler = function (msg) { var match = pending.contents; if (match !== undefined) { pending.contents = /* :: */[ msg, match ]; return /* () */0; } else { pending.contents = /* [] */0; var newModel = Curry._2(pumperInterface.handleMsg, model.contents, msg); model.contents = newModel; var match$1 = pending.contents; if (match$1 !== undefined) { var msgs = match$1; if (msgs) { pending.contents = undefined; return List.iter(handler, List.rev(msgs)); } else { pending.contents = undefined; return /* () */0; } } else { throw [ Caml_builtin_exceptions.failure, "INVALID message queue state, should never be None during message processing!" ]; } } }; var render_events = { contents: /* [] */0 }; var finalizedCBs_enqueue = handler; var finalizedCBs_on = function (param) { if (typeof param === "number") { return List.iter(handler, render_events.contents); } else if (param.tag) { var msg = param[0]; render_events.contents = List.filter((function (mg) { return msg !== mg; }))(render_events.contents); return /* () */0; } else { render_events.contents = List.append(render_events.contents, /* :: */[ param[0], /* [] */0 ]); return /* () */0; } }; var finalizedCBs = { enqueue: finalizedCBs_enqueue, on: finalizedCBs_on }; callbacks.contents = finalizedCBs; var pi_requestShutdown = function (param) { callbacks.contents = { enqueue: (function (_msg) { console.log("INVALID message enqueued when shut down"); return /* () */0; }), on: (function (param) { return /* () */0; }) }; var cmd = Curry._1(shutdown, model.contents); Curry._1(pumperInterface.shutdown, cmd); return /* () */0; }; var render_string = function (param) { return Curry._1(pumperInterface.render_string, model.contents); }; Curry._1(pumperInterface.startup, /* () */0); return { pushMsg: handler, shutdown: pi_requestShutdown, getHtmlString: render_string }; } function programLoop(update, view, subscriptions, initModel, initCmd, param) { if (param !== undefined) { var parentNode = Caml_option.valFromOption(param); return (function (callbacks) { var priorRenderedVdom = { contents: /* [] */0 }; var latestModel = { contents: initModel }; var nextFrameID = { contents: undefined }; var doRender = function (_delta) { var match = nextFrameID.contents; if (match !== undefined) { var newVdom_000 = Curry._1(view, latestModel.contents); var newVdom = /* :: */[ newVdom_000, /* [] */0 ]; var justRenderedVdom = Vdom.patchVNodesIntoElement(callbacks, parentNode, priorRenderedVdom.contents, newVdom); priorRenderedVdom.contents = justRenderedVdom; Curry._1(callbacks.contents.on, /* Render */0); nextFrameID.contents = undefined; return /* () */0; } else { return /* () */0; } }; var scheduleRender = function (param) { var match = nextFrameID.contents; if (match !== undefined) { return /* () */0; } else { var id = window.requestAnimationFrame(doRender); nextFrameID.contents = id; return /* () */0; } }; var clearPnode = function (param) { while(parentNode.childNodes.length > 0) { var match = parentNode.firstChild; if (match !== null) { parentNode.removeChild(match); } }; return /* () */0; }; var oldSub = { contents: /* NoSub */0 }; var handleSubscriptionChange = function (model) { var newSub = Curry._1(subscriptions, model); oldSub.contents = Tea_sub.run(callbacks, callbacks, oldSub.contents, newSub); return /* () */0; }; var handlerStartup = function (param) { clearPnode(/* () */0); Tea_cmd.run(callbacks, initCmd); handleSubscriptionChange(latestModel.contents); nextFrameID.contents = -1; doRender(16); return /* () */0; }; var render_string = function (model) { return Vdom.renderToHtmlString(Curry._1(view, model)); }; var handler = function (model, msg) { var match = Curry._2(update, model, msg); var newModel = match[0]; latestModel.contents = newModel; Tea_cmd.run(callbacks, match[1]); scheduleRender(/* () */0); handleSubscriptionChange(newModel); return newModel; }; var handlerShutdown = function (cmd) { nextFrameID.contents = undefined; Tea_cmd.run(callbacks, cmd); oldSub.contents = Tea_sub.run(callbacks, callbacks, oldSub.contents, /* NoSub */0); priorRenderedVdom.contents = /* [] */0; clearPnode(/* () */0); return /* () */0; }; return { startup: handlerStartup, render_string: render_string, handleMsg: handler, shutdown: handlerShutdown }; }); } else { return (function (callbacks) { var oldSub = { contents: /* NoSub */0 }; var handleSubscriptionChange = function (model) { var newSub = Curry._1(subscriptions, model); oldSub.contents = Tea_sub.run(callbacks, callbacks, oldSub.contents, newSub); return /* () */0; }; return { startup: (function (param) { Tea_cmd.run(callbacks, initCmd); handleSubscriptionChange(initModel); return /* () */0; }), render_string: (function (model) { return Vdom.renderToHtmlString(Curry._1(view, model)); }), handleMsg: (function (model, msg) { var match = Curry._2(update, model, msg); var newModel = match[0]; Tea_cmd.run(callbacks, match[1]); handleSubscriptionChange(newModel); return newModel; }), shutdown: (function (cmd) { Tea_cmd.run(callbacks, cmd); oldSub.contents = Tea_sub.run(callbacks, callbacks, oldSub.contents, /* NoSub */0); return /* () */0; }) }; }); } } function program(param, pnode, flags) { Web.polyfills(/* () */0); var match = Curry._1(param.init, flags); var initModel = match[0]; var opnode = (pnode == null) ? undefined : Caml_option.some(pnode); var pumpInterface = programLoop(param.update, param.view, param.subscriptions, initModel, match[1], opnode); return programStateWrapper(initModel, pumpInterface, param.shutdown); } function standardProgram(param, pnode, args) { return program({ init: param.init, update: param.update, view: param.view, subscriptions: param.subscriptions, shutdown: (function (_model) { return /* NoCmd */0; }) }, pnode, args); } function beginnerProgram(param, pnode, param$1) { var update = param.update; var model = param.model; return standardProgram({ init: (function (param) { return /* tuple */[ model, /* NoCmd */0 ]; }), update: (function (model, msg) { return /* tuple */[ Curry._2(update, model, msg), /* NoCmd */0 ]; }), view: param.view, subscriptions: (function (_model) { return /* NoSub */0; }) }, pnode, /* () */0); } var map = Vdom.map; exports.programStateWrapper = programStateWrapper; exports.programLoop = programLoop; exports.program = program; exports.standardProgram = standardProgram; exports.beginnerProgram = beginnerProgram; exports.map = map; /* No side effect */ },{"./tea_cmd.js":2,"./tea_sub.js":12,"./vdom.js":14,"./web.js":15,"bs-platform/lib/js/caml_builtin_exceptions.js":40,"bs-platform/lib/js/caml_option.js":50,"bs-platform/lib/js/curry.js":58,"bs-platform/lib/js/list.js":61}],2:[function(require,module,exports){ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; var List = require("bs-platform/lib/js/list.js"); var Vdom = require("./vdom.js"); var Block = require("bs-platform/lib/js/block.js"); var Curry = require("bs-platform/lib/js/curry.js"); function batch(cmds) { return /* Batch */Block.__(1, [cmds]); } function call(call$1) { return /* EnqueueCall */Block.__(2, [call$1]); } function fnMsg(fnMsg$1) { return /* EnqueueCall */Block.__(2, [(function (callbacks) { return Curry._1(callbacks.contents.enqueue, Curry._1(fnMsg$1, /* () */0)); })]); } function msg(msg$1) { return /* EnqueueCall */Block.__(2, [(function (callbacks) { return Curry._1(callbacks.contents.enqueue, msg$1); })]); } function run(_callbacks, _param) { while(true) { var param = _param; var callbacks = _callbacks; if (typeof param === "number") { return /* () */0; } else { switch (param.tag | 0) { case /* Mapper */0 : var subCallbacks = Curry._1(param[0], callbacks); _param = param[1]; _callbacks = subCallbacks; continue ; case /* Batch */1 : return List.fold_left((function(callbacks){ return function (param, cmd) { return run(callbacks, cmd); } }(callbacks)), /* () */0, param[0]); case /* EnqueueCall */2 : return Curry._1(param[0], callbacks); } } }; } function map(func, cmd) { var mapper = function (param) { return Vdom.wrapCallbacks(func, param); }; return /* Mapper */Block.__(0, [ mapper, cmd ]); } var none = /* NoCmd */0; exports.none = none; exports.batch = batch; exports.call = call; exports.fnMsg = fnMsg; exports.msg = msg; exports.run = run; exports.map = map; /* No side effect */ },{"./vdom.js":14,"bs-platform/lib/js/block.js":36,"bs-platform/lib/js/curry.js":58,"bs-platform/lib/js/list.js":61}],3:[function(require,module,exports){ // Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; var List = require("bs-platform/lib/js/list.js"); var Vdom = require("./vdom.js"); var Block = require("bs-platform/lib/js/block.js"); var Curry = require("bs-platform/lib/js/curry.js"); var Printf = require("bs-platform/lib/js/printf.js"); var $$String = require("bs-platform/lib/js/string.js"); var Tea_app = require("./tea_app.js"); var Tea_cmd = require("./tea_cmd.js"); var Tea_sub = require("./tea_sub.js"); var Tea_html2 = require("./tea_html2.js"); var Tea_navigation = require("./tea_navigation.js"); function client_msg(msg) { return /* ClientMsg */Block.__(0, [msg]); } function debug(string_of_msg, update, view, subscriptions, shutdown) { var init_debug = function (param) { return /* tuple */[ { history: /* :: */[ /* tuple */[ "_init_", param[0] ], /* [] */0 ], state: /* Running */0, show_details: false }, Tea_cmd.map(client_msg, param[1]) ]; }; var update$prime = function (model, param) { if (typeof param === "number") { if (param === /* TogglePaused */0) { var match = model.state; if (match) { return /* tuple */[ { history: model.history, state: /* Running */0, show_details: model.show_details }, /* NoCmd */0 ]; } else { return /* tuple */[ { history: model.history, state: /* Paused */[0], show_details: model.show_details }, /* NoCmd */0 ]; } } else { return /* tuple */[ { history: model.history, state: model.state, show_details: !model.show_details }, /* NoCmd */0 ]; } } else if (param.tag) { return /* tuple */[ { history: model.history, state: /* Paused */[param[0]], show_details: model.show_details }, /* NoCmd */0 ]; } else if (model.state === /* Running */0) { var msg = param[0]; var match$1 = List.hd(model.history); var match$2 = Curry._2(update, match$1[1], msg); var dmodel$prime_history = /* :: */[ /* tuple */[ Curry._1(string_of_msg, msg), match$2[0] ], model.history ]; var dmodel$prime_state = model.state; var dmodel$prime_show_details = model.show_details; var dmodel$prime = { history: dmodel$prime_history, state: dmodel$prime_state, show_details: dmodel$prime_show_details }; return /* tuple */[ dmodel$prime, Tea_cmd.map(client_msg, match$2[1]) ]; } else { return /* tuple */[ model, /* NoCmd */0 ]; } }; var view_styles = function (param) { var rule = function (selector, properties) { return /* Text */Block.__(1, [Curry._2(Printf.sprintf(/* Format */[ /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " {", /* String */Block.__(2, [ /* No_padding */0, /* Char_literal */Block.__(12, [ /* "}" */125, /* End_of_format */0 ]) ]) ]) ]), "%s {%s}" ]), selector, $$String.concat(";", List.map((function (param) { return param[0] + (":" + param[1]); }), properties)))]); }; return Tea_html2.node(undefined, "style", undefined, undefined, /* [] */0, /* :: */[ rule("#debug.paused", /* :: */[ /* tuple */[ "position", "fixed" ], /* :: */[ /* tuple */[ "top", "0" ], /* :: */[ /* tuple */[ "left", "0" ], /* :: */[ /* tuple */[ "width", "100%" ], /* :: */[ /* tuple */[ "height", "100%" ], /* :: */[ /* tuple */[ "pointer-events", "all" ], /* :: */[ /* tuple */[ "background-color", "rgba(0,0,0,.1)" ], /* :: */[ /* tuple */[ "box-shadow", "inset 0 0 10px #333" ], /* [] */0 ] ] ] ] ] ] ] ]), /* :: */[ rule("#debug nav", /* :: */[ /* tuple */[ "position", "fixed" ], /* :: */[ /* tuple */[ "max-width", "50%" ], /* :: */[ /* tuple */[ "bottom", "0" ], /* :: */[ /* tuple */[ "right", "6px" ], /* :: */[ /* tuple */[ "border-radius", "4px 4px 0 0" ], /* :: */[ /* tuple */[ "background-color", "#444" ], /* :: */[ /* tuple */[ "color", "#fff" ], /* :: */[ /* tuple */[ "font-family", "monospace" ], /* :: */[ /* tuple */[ "box-shadow", "0 0 10px #333" ], /* [] */0 ] ] ] ] ] ] ] ] ]), /* :: */[ rule("#debug.paused nav", /* :: */[ /* tuple */[ "height", "50%" ], /* :: */[ /* tuple */[ "padding-bottom", "2em" ], /* [] */0 ] ]), /* :: */[ rule("#debug nav .toggle", /* :: */[ /* tuple */[ "padding", "6px" ], /* :: */[ /* tuple */[ "padding-left", "9px" ], /* :: */[ /* tuple */[ "cursor", "pointer" ], /* :: */[ /* tuple */[ "min-width", "24ch" ], /* :: */[ /* tuple */[ "text-align", "center" ], /* :: */[ /* tuple */[ "border-left", "3px solid #333" ], /* :: */[ /* tuple */[ "border-radius", "4px 4px 0 0" ], /* [] */0 ] ] ] ] ] ] ]), /* :: */[ rule("#debug nav .toggle:before", /* :: */[ /* tuple */[ "content", "' '" ], /* :: */[ /* tuple */[ "position", "absolute" ], /* :: */[ /* tuple */[ "left", "0" ], /* :: */[ /* tuple */[ "top", "0" ], /* :: */[ /* tuple */[ "width", ".5ch" ], /* :: */[ /* tuple */[ "height", "1.8ch" ], /* :: */[ /* tuple */[ "margin", "1.2ch" ], /* :: */[ /* tuple */[ "border", "solid #fff" ], /* :: */[ /* tuple */[ "border-width", "0 .5ch" ], /* [] */0 ] ] ] ] ] ] ] ] ]), /* :: */[ rule("#debug.paused nav .toggle:before", /* :: */[ /* tuple */[ "border-color", "transparent" ], /* :: */[ /* tuple */[ "border-left-color", "#fff" ], /* :: */[ /* tuple */[ "border-width", "1ch" ], /* :: */[ /* tuple */[ "width", "0" ], /* :: */[ /* tuple */[ "height", "0" ], /* [] */0 ] ] ] ] ]), /* :: */[ rule("#debug nav .history", /* :: */[ /* tuple */[ "margin", "0" ], /* :: */[ /* tuple */[ "padding", "0" ], /* :: */[ /* tuple */[ "height", "100%" ], /* :: */[ /* tuple */[ "overflow-y", "auto" ], /* :: */[ /* tuple */[ "list-style", "none" ], /* [] */0 ] ] ] ] ]), /* :: */[ rule("#debug nav .history li", /* :: */[ /* tuple */[ "margin", "0" ], /* :: */[ /* tuple */[ "padding", "0.2ch" ], /* :: */[ /* tuple */[ "border-left", "3px solid #333" ], /* [] */0 ] ] ]), /* :: */[ rule("#debug nav .history li.selected", /* :: */[ /* tuple */[ "background-color", "#333" ], /* [] */0 ]), /* :: */[ rule("#debug nav .history span.details", /* :: */[ /* tuple */[ "display", "inline-block" ], /* :: */[ /* tuple */[ "cursor", "pointer" ], /* :: */[ /* tuple */[ "width", "1ch" ], /* :: */[ /* tuple */[ "margin", "0 1ch" ], /* :: */[ /* tuple */[ "vertical-align", "super" ], /* [] */0 ] ] ] ] ]), /* :: */[ rule("#debug nav .history li.selected span.details:after", /* :: */[ /* tuple */[ "content", "'\\2026'" ], /* [] */0 ]), /* :: */[ rule("#debug nav .history li.selected.show", /* :: */[ /* tuple */[ "border-left", "3px solid white" ], /* [] */0 ]), /* :: */[ rule("#debug nav .history span.message", /* :: */[ /* tuple */[ "display", "inline-block" ], /* :: */[ /* tuple */[ "cursor", "pointer" ], /* :: */[ /* tuple */[ "white-space", "nowrap" ], /* :: */[ /* tuple */[ "overflow", "hidden" ], /* :: */[ /* tuple */[ "text-overflow", "ellipsis" ], /* :: */[ /* tuple */[ "width", "calc(100% - 75px)" ], /* [] */0 ] ] ] ] ] ]), /* :: */[ rule("#debug nav .history span.index", /* :: */[ /* tuple */[ "display", "inline-block" ], /* :: */[ /* tuple */[ "min-width", "3ch" ], /* :: */[ /* tuple */[ "margin", "0 1ch" ], /* :: */[ /* tuple */[ "color", "#aaa" ], /* :: */[ /* tuple */[ "text-align", "right" ], /* :: */[ /* tuple */[ "float", "right" ], /* [] */0 ] ] ] ] ] ]), /* :: */[ rule("#debug aside.details", /* :: */[ /* tuple */[ "position", "absolute" ], /* :: */[ /* tuple */[ "width", "40ch" ], /* :: */[ /* tuple */[ "top", "0" ], /* :: */[ /* tuple */[ "bottom", "0" ], /* :: */[ /* tuple */[ "right", "100%" ], /* :: */[ /* tuple */[ "margin-right", "1.5ch" ], /* :: */[ /* tuple */[ "overflow", "scroll" ], /* :: */[ /* tuple */[ "background-color", "#fff" ], /* :: */[ /* tuple */[ "color", "#000" ], /* :: */[ /* tuple */[ "box-shadow", "0 0 10px #333" ], /* :: */[ /* tuple */[ "border-radius", "4px 4px 0 0" ], /* :: */[ /* tuple */[ "border", "2px solid #333" ], /* :: */[ /* tuple */[ "padding", "1ch" ], /* :: */[ /* tuple */[ "white-space", "pre" ], /* [] */0 ] ] ] ] ] ] ] ] ] ] ] ] ] ]), /* [] */0 ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]); }; var view_details = function (model) { var format = (function (v) { var formatRecord = function (data, labels) { return data.reduce( function (acc, cur, index) { acc[labels[index]] = formatValue(cur) return acc }, {}) } var listToArray = function (data) { var result = [] var cur = data while (typeof cur !== "number") { result.push(formatValue(cur[0])) cur = cur[1] } return result } var formatVariant = function (data, recordVariant) { if (recordVariant === "::") { return listToArray(data) } else { return formatRecord(data, [recordVariant]) } } var formatValue = function (x) { var recordLabels, recordVariant, recordModule, recordPolyVar if (x == null) { return null } else if ((recordLabels = x[Symbol.for('BsRecord')]) !== undefined) { return formatRecord(x, recordLabels) } else if ((recordModule = x[Symbol.for('BsLocalModule')]) !== undefined) { return formatRecord(x, recordModule) } else if ((recordVariant = x[Symbol.for('BsVariant')]) !== undefined) { return formatVariant(x, recordVariant) } else if ((recordPolyVar = x[Symbol.for('BsPolyVar')]) !== undefined) { return x[1] } else if (Array.isArray(x)) { // tuple return x.map(formatValue) } else { // scalar return x } } return JSON.stringify(formatValue(v), null, 2); }); return Tea_html2.aside(undefined, undefined, /* :: */[ Tea_html2.Attributes.class$prime("details"), /* [] */0 ], /* :: */[ /* Text */Block.__(1, [format(model)]), /* [] */0 ]); }; var view_history = function (model, selected_index) { var count = List.length(model.history); return Tea_html2.ul(undefined, undefined, /* :: */[ Tea_html2.Attributes.class$prime("history"), /* [] */0 ], List.mapi((function (i, param) { var selected = i === selected_index; return Tea_html2.li(undefined, undefined, /* :: */[ Tea_html2.Events.onClick(/* SelectHistoryItem */Block.__(1, [i])), /* :: */[ Tea_html2.Attributes.classList(/* :: */[ /* tuple */[ "selected", selected ], /* :: */[ /* tuple */[ "show", selected && model.show_details ], /* [] */0 ] ]), /* [] */0 ] ], /* :: */[ Tea_html2.span(undefined, undefined, /* :: */[ Tea_html2.Attributes.classList(/* :: */[ /* tuple */[ "details", true ], /* :: */[ /* tuple */[ "show", true ], /* [] */0 ] ]), selected ? /* :: */[ Tea_html2.Events.onClick(/* ToggleDetails */1), /* :: */[ Tea_html2.Attributes.title("toggle details"), /* [] */0 ] ] : /* :: */[ Tea_html2.Attributes.noProp, /* :: */[ Tea_html2.Attributes.noProp, /* [] */0 ] ] ], /* :: */[ selected && model.show_details ? view_details(param[1]) : Tea_html2.noNode, /* [] */0 ]), /* :: */[