UNPKG

bucklescript-tea

Version:
1,006 lines (995 loc) 45.7 kB
// 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 ]), /* :: */[ Tea_html2.span(undefined, undefined, /* :: */[ Tea_html2.Attributes.class$prime("message"), /* [] */0 ], /* :: */[ /* Text */Block.__(1, [param[0]]), /* [] */0 ]), /* :: */[ Tea_html2.span(undefined, undefined, /* :: */[ Tea_html2.Attributes.class$prime("index"), /* [] */0 ], /* :: */[ /* Text */Block.__(1, [String(count - i | 0)]), /* [] */0 ]), /* [] */0 ] ] ]); }), model.history)); }; var view$prime = function (model) { var match = model.state; var match$1; if (match) { var index = match[0]; match$1 = /* tuple */[ index, List.nth(model.history, index)[1], true ]; } else { match$1 = /* tuple */[ 0, List.hd(model.history)[1], false ]; } var paused = match$1[2]; var history_count = List.length(model.history); var vnode = Curry._1(view, match$1[1]); return Tea_html2.div(undefined, undefined, /* [] */0, /* :: */[ Vdom.map(client_msg, vnode), /* :: */[ Tea_html2.div(undefined, undefined, /* :: */[ Tea_html2.Attributes.id("debug"), /* :: */[ Tea_html2.Attributes.classList(/* :: */[ /* tuple */[ "paused", paused ], /* [] */0 ]), /* [] */0 ] ], /* :: */[ view_styles(/* () */0), /* :: */[ Tea_html2.nav(undefined, undefined, /* [] */0, /* :: */[ Tea_html2.div(undefined, undefined, /* :: */[ Tea_html2.Attributes.class$prime("toggle"), /* :: */[ Tea_html2.Events.onClick(/* TogglePaused */0), /* :: */[ paused ? Tea_html2.Attributes.title("click to resume") : Tea_html2.Attributes.title("click to pause"), /* [] */0 ] ] ], /* :: */[ /* Text */Block.__(1, [Curry._1(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "Explore History (", /* Int */Block.__(4, [ /* Int_d */0, /* No_padding */0, /* No_precision */0, /* Char_literal */Block.__(12, [ /* ")" */41, /* End_of_format */0 ]) ]) ]), "Explore History (%d)" ]), history_count)]), /* [] */0 ]), /* :: */[ paused ? view_history(model, match$1[0]) : Tea_html2.noNode, /* [] */0 ] ]), /* [] */0 ] ]), /* [] */0 ] ]); }; var subscriptions$prime = function (model) { return Tea_sub.map(client_msg, Curry._1(subscriptions, List.hd(model.history)[1])); }; var shutdown$prime = function (model) { return Tea_cmd.map(client_msg, Curry._1(shutdown, List.hd(model.history)[1])); }; return /* tuple */[ init_debug, update$prime, view$prime, subscriptions$prime, shutdown$prime ]; } function debug_program(string_of_msg, param) { var init = param.init; var match = debug(string_of_msg, param.update, param.view, param.subscriptions, param.shutdown); var init_debug = match[0]; return { init: (function (flags) { return Curry._1(init_debug, Curry._1(init, flags)); }), update: match[1], view: match[2], subscriptions: match[3], shutdown: match[4] }; } function debug_navigation_progam(string_of_msg, param) { var init = param.init; var match = debug(string_of_msg, param.update, param.view, param.subscriptions, param.shutdown); var init_debug = match[0]; return { init: (function (flags, $$location) { return Curry._1(init_debug, Curry._2(init, flags, $$location)); }), update: match[1], view: match[2], subscriptions: match[3], shutdown: match[4] }; } function beginnerProgram(param, string_of_msg, pnode, flags) { var update = param.update; var model = param.model; var debugged = debug_program(string_of_msg, { 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; }), shutdown: (function (_model) { return /* NoCmd */0; }) }); return Tea_app.program(debugged, pnode, flags); } function standardProgram(param, string_of_msg, pnode, flags) { var debugged = debug_program(string_of_msg, { init: param.init, update: param.update, view: param.view, subscriptions: param.subscriptions, shutdown: (function (_model) { return /* NoCmd */0; }) }); return Tea_app.program(debugged, pnode, flags); } function program(param, string_of_msg, pnode, flags) { var debugged = debug_program(string_of_msg, { init: param.init, update: param.update, view: param.view, subscriptions: param.subscriptions, shutdown: param.shutdown }); return Tea_app.program(debugged, pnode, flags); } function navigationProgram(location_to_msg, param, string_of_msg, pnode, flags) { var $$location = function ($$location$1) { return /* ClientMsg */Block.__(0, [Curry._1(location_to_msg, $$location$1)]); }; var debugged = debug_navigation_progam(string_of_msg, { init: param.init, update: param.update, view: param.view, subscriptions: param.subscriptions, shutdown: param.shutdown }); return Tea_navigation.navigationProgram($$location, debugged)(pnode, flags); } exports.client_msg = client_msg; exports.debug = debug; exports.debug_program = debug_program; exports.debug_navigation_progam = debug_navigation_progam; exports.beginnerProgram = beginnerProgram; exports.standardProgram = standardProgram; exports.program = program; exports.navigationProgram = navigationProgram; /* Tea_html2 Not a pure module */