UNPKG

bucklescript-tea

Version:
225 lines (207 loc) 6.75 kB
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; var Vdom = require("../src-ocaml/vdom.js"); var Block = require("bs-platform/lib/js/block.js"); var Tea_app = require("../src-ocaml/tea_app.js"); var Tea_html = require("../src-ocaml/tea_html.js"); var Tea_json = require("../src-ocaml/tea_json.js"); var Tea_mouse = require("../src-ocaml/tea_mouse.js"); var Tea_result = require("../src-ocaml/tea_result.js"); function dragStart(param_0) { return /* DragStart */Block.__(0, [param_0]); } function dragAt(param_0) { return /* DragAt */Block.__(1, [param_0]); } function dragEnd(param_0) { return /* DragEnd */Block.__(2, [param_0]); } function init(param) { return /* tuple */[ { position: { x: 200, y: 200 }, drag: undefined }, /* NoCmd */0 ]; } function getPosition(param) { var drag = param.drag; var position = param.position; if (drag !== undefined) { var match = drag; var current = match.current; var start = match.start; return { x: (position.x + current.x | 0) - start.x | 0, y: (position.y + current.y | 0) - start.y | 0 }; } else { return position; } } function updateHelp(model, param) { var position = model.position; switch (param.tag | 0) { case /* DragStart */0 : var xy = param[0]; return { position: position, drag: { start: xy, current: xy } }; case /* DragAt */1 : var match = model.drag; return { position: position, drag: match !== undefined ? ({ start: match.start, current: param[0] }) : undefined }; case /* DragEnd */2 : return { position: getPosition(model), drag: undefined }; } } function update(model, msg) { return /* tuple */[ updateHelp(model, msg), /* NoCmd */0 ]; } function subscriptions(model) { var match = model.drag; if (match !== undefined) { return /* Batch */Block.__(0, [/* :: */[ Tea_mouse.moves(undefined, dragAt), /* :: */[ Tea_mouse.ups(undefined, dragEnd), /* [] */0 ] ]]); } else { return /* NoSub */0; } } function px(number) { return String(number) + "px"; } function cb(ev) { return Tea_result.result_to_option(Tea_json.Decoder.decodeEvent(Tea_json.Decoder.map(dragStart, Tea_mouse.position), ev)); } var onMouseDown = Vdom.onCB("mousedown", "", cb); function view(model) { var realPosition = getPosition(model); return Tea_html.div(undefined, undefined, /* :: */[ onMouseDown, /* :: */[ /* Style */Block.__(4, [/* :: */[ /* tuple */[ "background-color", "#3C8D2F" ], /* :: */[ /* tuple */[ "cursor", "move" ], /* :: */[ /* tuple */[ "width", "100px" ], /* :: */[ /* tuple */[ "height", "100px" ], /* :: */[ /* tuple */[ "border-radius", "4px" ], /* :: */[ /* tuple */[ "position", "absolute" ], /* :: */[ /* tuple */[ "left", String(realPosition.x) + "px" ], /* :: */[ /* tuple */[ "top", String(realPosition.y) + "px" ], /* :: */[ /* tuple */[ "color", "white" ], /* :: */[ /* tuple */[ "display", "flex" ], /* :: */[ /* tuple */[ "align-items", "center" ], /* :: */[ /* tuple */[ "justify-content", "center" ], /* [] */0 ] ] ] ] ] ] ] ] ] ] ] ]]), /* [] */0 ] ], /* :: */[ /* Text */Block.__(1, ["Drag Me!"]), /* [] */0 ]); } var partial_arg = { init: init, update: update, view: view, subscriptions: subscriptions }; function main(param, param$1) { return Tea_app.standardProgram(partial_arg, param, param$1); } exports.dragStart = dragStart; exports.dragAt = dragAt; exports.dragEnd = dragEnd; exports.init = init; exports.getPosition = getPosition; exports.updateHelp = updateHelp; exports.update = update; exports.subscriptions = subscriptions; exports.px = px; exports.onMouseDown = onMouseDown; exports.view = view; exports.main = main; /* onMouseDown Not a pure module */