import "./cljs_env.js";
goog.provide('clojure_eval.extensions.sci');
var module$node_modules$$codemirror$view$dist$index_cjs=shadow.js.require("module$node_modules$$codemirror$view$dist$index_cjs", {});
if((typeof clojure_eval !== 'undefined') && (typeof clojure_eval.extensions !== 'undefined') && (typeof clojure_eval.extensions.sci !== 'undefined') && (typeof clojure_eval.extensions.sci._BANG_viewer !== 'undefined')){
} else {
clojure_eval.extensions.sci._BANG_viewer = cljs.core.atom.cljs$core$IFn$_invoke$arity$1("");
}
if((typeof clojure_eval !== 'undefined') && (typeof clojure_eval.extensions !== 'undefined') && (typeof clojure_eval.extensions.sci !== 'undefined') && (typeof clojure_eval.extensions.sci.last_result !== 'undefined')){
} else {
clojure_eval.extensions.sci.last_result = cljs.core.atom.cljs$core$IFn$_invoke$arity$1("");
}
if((typeof clojure_eval !== 'undefined') && (typeof clojure_eval.extensions !== 'undefined') && (typeof clojure_eval.extensions.sci !== 'undefined') && (typeof clojure_eval.extensions.sci.context !== 'undefined')){
} else {
clojure_eval.extensions.sci.context = sci.core.init(new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"classes","classes",2037804510),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Symbol(null,"js","js",-886355190,null),goog.global,new cljs.core.Keyword(null,"allow","allow",-1857325745),new cljs.core.Keyword(null,"all","all",892129742)], null)], null));
}
clojure_eval.extensions.sci.eval_string = (function clojure_eval$extensions$sci$eval_string(var_args){
var G__69755 = arguments.length;
switch (G__69755) {
case 1:
return clojure_eval.extensions.sci.eval_string.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
case 2:
return clojure_eval.extensions.sci.eval_string.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

(clojure_eval.extensions.sci.eval_string.cljs$core$IFn$_invoke$arity$1 = (function (source){
return clojure_eval.extensions.sci.eval_string.cljs$core$IFn$_invoke$arity$2(clojure_eval.extensions.sci.context,source);
}));

(clojure_eval.extensions.sci.eval_string.cljs$core$IFn$_invoke$arity$2 = (function (ctx,source){
var temp__5757__auto__ = cljs.core.not_empty(clojure.string.trim(source));
if((temp__5757__auto__ == null)){
return null;
} else {
var code = temp__5757__auto__;
try{return new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"result","result",1415092211),sci.core.eval_string_STAR_(ctx,code)], null);
}catch (e69759){if((e69759 instanceof Error)){
var e = e69759;
return new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"error","error",-978969032),cljs.core.str.cljs$core$IFn$_invoke$arity$1(e.message)], null);
} else {
throw e69759;

}
}}
}));

(clojure_eval.extensions.sci.eval_string.cljs$lang$maxFixedArity = 2);

if((typeof clojure_eval !== 'undefined') && (typeof clojure_eval.extensions !== 'undefined') && (typeof clojure_eval.extensions.sci !== 'undefined') && (typeof clojure_eval.extensions.sci.eval_tail !== 'undefined')){
} else {
clojure_eval.extensions.sci.eval_tail = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(null);
}
clojure_eval.extensions.sci.update_editor_BANG_ = (function clojure_eval$extensions$sci$update_editor_BANG_(text,cursor_pos){
var end = cljs.core.count((function (){var G__69762 = cljs.core.deref(clojure_eval.extensions.sci._BANG_viewer);
var G__69762__$1 = (((G__69762 == null))?null:G__69762.state);
var G__69762__$2 = (((G__69762__$1 == null))?null:G__69762__$1.doc);
if((G__69762__$2 == null)){
return null;
} else {
return cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__69762__$2);
}
})());
return cljs.core.deref(clojure_eval.extensions.sci._BANG_viewer).dispatch(({"changes": ({"from": (0), "to": end, "insert": text}), "selection": ({"anchor": cursor_pos, "head": cursor_pos})}));
});
clojure_eval.extensions.sci.eval_at_cursor = (function clojure_eval$extensions$sci$eval_at_cursor(on_result,p__69765){
var map__69766 = p__69765;
var map__69766__$1 = (((((!((map__69766 == null))))?(((((map__69766.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__69766.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__69766):map__69766);
var state = (function (){var obj69768 = map__69766__$1;
var k69769 = "state";
if((function (){var obj69770 = obj69768;
return (((!((obj69770 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k69769,obj69770)));
})()){
return (obj69768[k69769]);
} else {
return undefined;
}
})();
var cursor_pos_69795 = (function (){var G__69771 = cljs.core.deref(clojure_eval.extensions.sci._BANG_viewer);
var G__69771__$1 = (((G__69771 == null))?null:G__69771.state);
var G__69771__$2 = (((G__69771__$1 == null))?null:G__69771__$1.selection);
var G__69771__$3 = (((G__69771__$2 == null))?null:G__69771__$2.main);
if((G__69771__$3 == null)){
return null;
} else {
return G__69771__$3.head;
}
})();
var code_69796 = cljs.core.first(clojure.string.split.cljs$core$IFn$_invoke$arity$2(cljs.core.str.cljs$core$IFn$_invoke$arity$1((function (){var G__69773 = cljs.core.deref(clojure_eval.extensions.sci._BANG_viewer);
var G__69773__$1 = (((G__69773 == null))?null:G__69773.state);
var G__69773__$2 = (((G__69773__$1 == null))?null:G__69773__$1.doc);
if((G__69773__$2 == null)){
return null;
} else {
return cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__69773__$2);
}
})()),/ => /));
var G__69774_69797 = clojure_eval.extensions.eval_region.cursor_node_string(state);
var G__69774_69798__$1 = (((G__69774_69797 == null))?null:clojure_eval.extensions.sci.eval_string.cljs$core$IFn$_invoke$arity$1(G__69774_69797));
if((G__69774_69798__$1 == null)){
} else {
(on_result.cljs$core$IFn$_invoke$arity$1 ? on_result.cljs$core$IFn$_invoke$arity$1(G__69774_69798__$1) : on_result.call(null,G__69774_69798__$1));
}

clojure_eval.extensions.sci.update_editor_BANG_([cljs.core.subs.cljs$core$IFn$_invoke$arity$3(code_69796,(0),cursor_pos_69795),((cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2("",new cljs.core.Keyword(null,"result","result",1415092211).cljs$core$IFn$_invoke$arity$1(cljs.core.deref(clojure_eval.extensions.sci.last_result))))?null:" => "),cljs.core.str.cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"result","result",1415092211).cljs$core$IFn$_invoke$arity$1(cljs.core.deref(clojure_eval.extensions.sci.last_result))),cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.reset_BANG_(clojure_eval.extensions.sci.eval_tail,cljs.core.subs.cljs$core$IFn$_invoke$arity$3(code_69796,cursor_pos_69795,cljs.core.count(code_69796))))].join(''),cursor_pos_69795);

cljs.core.deref(clojure_eval.extensions.sci._BANG_viewer).dispatch(({"selection": ({"anchor": cursor_pos_69795, "head": cursor_pos_69795})}));

return true;
});
clojure_eval.extensions.sci.eval_top_level = (function clojure_eval$extensions$sci$eval_top_level(on_result,p__69775){
var map__69776 = p__69775;
var map__69776__$1 = (((((!((map__69776 == null))))?(((((map__69776.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__69776.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__69776):map__69776);
var state = (function (){var obj69778 = map__69776__$1;
var k69779 = "state";
if((function (){var obj69780 = obj69778;
return (((!((obj69780 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k69779,obj69780)));
})()){
return (obj69778[k69779]);
} else {
return undefined;
}
})();
var G__69781_69802 = clojure_eval.extensions.eval_region.top_level_string(state);
var G__69781_69803__$1 = (((G__69781_69802 == null))?null:clojure_eval.extensions.sci.eval_string.cljs$core$IFn$_invoke$arity$1(G__69781_69802));
if((G__69781_69803__$1 == null)){
} else {
(on_result.cljs$core$IFn$_invoke$arity$1 ? on_result.cljs$core$IFn$_invoke$arity$1(G__69781_69803__$1) : on_result.call(null,G__69781_69803__$1));
}

return true;
});
clojure_eval.extensions.sci.eval_cell = (function clojure_eval$extensions$sci$eval_cell(on_result,p__69782){
var map__69783 = p__69782;
var map__69783__$1 = (((((!((map__69783 == null))))?(((((map__69783.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__69783.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__69783):map__69783);
var state = (function (){var obj69785 = map__69783__$1;
var k69786 = "state";
if((function (){var obj69787 = obj69785;
return (((!((obj69787 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k69786,obj69787)));
})()){
return (obj69785[k69786]);
} else {
return undefined;
}
})();
var G__69788_69804 = clojure_eval.extensions.sci.eval_string.cljs$core$IFn$_invoke$arity$1(["(do ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(state.doc)," )"].join(''));
(on_result.cljs$core$IFn$_invoke$arity$1 ? on_result.cljs$core$IFn$_invoke$arity$1(G__69788_69804) : on_result.call(null,G__69788_69804));

return true;
});
clojure_eval.extensions.sci.clear_eval = (function clojure_eval$extensions$sci$clear_eval(){
if(cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2("",cljs.core.deref(clojure_eval.extensions.sci.last_result))){
cljs.core.reset_BANG_(clojure_eval.extensions.sci.last_result,"");

var code = [cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.first(clojure.string.split.cljs$core$IFn$_invoke$arity$2(cljs.core.str.cljs$core$IFn$_invoke$arity$1((function (){var G__69792 = cljs.core.deref(clojure_eval.extensions.sci._BANG_viewer);
var G__69792__$1 = (((G__69792 == null))?null:G__69792.state);
var G__69792__$2 = (((G__69792__$1 == null))?null:G__69792__$1.doc);
if((G__69792__$2 == null)){
return null;
} else {
return cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__69792__$2);
}
})()),/ => /))),cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.deref(clojure_eval.extensions.sci.eval_tail))].join('');
var cursor_pos = (function (){var G__69793 = cljs.core.deref(clojure_eval.extensions.sci._BANG_viewer);
var G__69793__$1 = (((G__69793 == null))?null:G__69793.state);
var G__69793__$2 = (((G__69793__$1 == null))?null:G__69793__$1.selection);
var G__69793__$3 = (((G__69793__$2 == null))?null:G__69793__$2.main);
if((G__69793__$3 == null)){
return null;
} else {
return G__69793__$3.head;
}
})();
return clojure_eval.extensions.sci.update_editor_BANG_(code,(function (){var x__4309__auto__ = cursor_pos;
var y__4310__auto__ = ((code).length);
return ((x__4309__auto__ < y__4310__auto__) ? x__4309__auto__ : y__4310__auto__);
})());
} else {
return null;
}
});
clojure_eval.extensions.sci.extension = (function clojure_eval$extensions$sci$extension(){
return module$node_modules$$codemirror$view$dist$index_cjs.keymap.of([({"key":"Alt-Enter","run":cljs.core.partial.cljs$core$IFn$_invoke$arity$2(clojure_eval.extensions.sci.eval_cell,(function (result){
return cljs.core.reset_BANG_(clojure_eval.extensions.sci.last_result,result);
}))}),({"key":"Mod-Enter","run":cljs.core.partial.cljs$core$IFn$_invoke$arity$2(clojure_eval.extensions.sci.eval_top_level,(function (result){
return cljs.core.reset_BANG_(clojure_eval.extensions.sci.last_result,result);
}))}),({"key":"Shift-Enter","run":cljs.core.partial.cljs$core$IFn$_invoke$arity$2(clojure_eval.extensions.sci.eval_at_cursor,(function (result){
return cljs.core.reset_BANG_(clojure_eval.extensions.sci.last_result,result);
}))}),({"key":"Escape","run":clojure_eval.extensions.sci.clear_eval}),({"key":"ArrowLeft","run":clojure_eval.extensions.sci.clear_eval}),({"key":"ArrowRight","run":clojure_eval.extensions.sci.clear_eval}),({"key":"ArrowUp","run":clojure_eval.extensions.sci.clear_eval}),({"key":"ArrowDown","run":clojure_eval.extensions.sci.clear_eval})]);
});

//# sourceMappingURL=clojure_eval.extensions.sci.js.map
