From b615a7cf0fc9d81b4b905a9d4e1db0beebdebd3d Mon Sep 17 00:00:00 2001 From: s-ol Date: Sun, 8 May 2022 21:14:58 +0200 Subject: initial commit --- $mmm/plugins/code/converts: text$lua -> table.lua | 121 +++++++++++++++++++++ .../code/converts: text$moonscript -> table.moon | 90 +++++++++++++++ .../scripts: text$lua -> fn -> text$html+frag.lua | 12 ++ ...s: text$moonscript -> fn -> text$html+frag.moon | 14 +++ $mmm/plugins/code/style: text$css.css | 110 +++++++++++++++++++ 5 files changed, 347 insertions(+) create mode 100644 $mmm/plugins/code/converts: text$lua -> table.lua create mode 100644 $mmm/plugins/code/converts: text$moonscript -> table.moon create mode 100644 $mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua create mode 100644 $mmm/plugins/code/scripts: text$moonscript -> fn -> text$html+frag.moon create mode 100644 $mmm/plugins/code/style: text$css.css (limited to '$mmm/plugins/code') diff --git a/$mmm/plugins/code/converts: text$lua -> table.lua b/$mmm/plugins/code/converts: text$lua -> table.lua new file mode 100644 index 0000000..c578a69 --- /dev/null +++ b/$mmm/plugins/code/converts: text$lua -> table.lua @@ -0,0 +1,121 @@ +local pre, div, button +do + local _obj_0 = require('mmm.dom') + pre, div, button = _obj_0.pre, _obj_0.div, _obj_0.button +end +local languages +languages = require('mmm.highlighting').languages +local Editor +do + local _class_0 + local o + local _base_0 = { + EDITOR = true, + change = function(self) + self.timeout = nil + local doc = self.cm:getDoc() + if self.lastPreview and doc:isClean(self.lastPreview) then + return + end + self.lastPreview = doc:changeGeneration() + local value = doc:getValue() + self.fileder.facets[self.key] = value + return BROWSER:refresh() + end, + save = function(self, e) + e:preventDefault() + local doc = self.cm:getDoc() + self.fileder:set(self.key, doc:getValue()) + self.lastSave = doc:changeGeneration(true) + end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self, value, mode, fileder, key) + self.fileder, self.key = fileder, key + self.node = div({ + class = 'editor' + }) + do + local _with_0 = button('save') + _with_0.disabled = true + _with_0.onclick = function(_, e) + return self:save(e) + end + self.saveBtn = _with_0 + end + self.cm = window:CodeMirror(self.node, o({ + value = value, + mode = mode, + lineNumber = true, + lineWrapping = true, + autoRefresh = true, + theme = 'hybrid' + })) + self.lastSave = self.cm:getDoc():changeGeneration(true) + return self.cm:on('changes', function(_, mirr) + local doc = self.cm:getDoc() + self.saveBtn.disabled = doc:isClean(self.lastSave) + if self.timeout then + window:clearTimeout(self.timeout) + end + self.timeout = window:setTimeout((function() + return self:change() + end), 300) + end) + end, + __base = _base_0, + __name = "Editor" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({}, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + local self = _class_0 + if MODE == 'CLIENT' then + local mkobj = window:eval("(function () { return {}; })") + o = function(tbl) + do + local obj = mkobj() + for k, v in pairs(tbl) do + obj[k] = v + end + return obj + end + end + end + Editor = _class_0 +end +local _ = [[ editors: if MODE == 'CLIENT' then { + { + inp: 'text/([^ ]*).*' + out: 'mmm/dom' + cost: 0 + transform: (value, fileder, key) => + mode = @from\match @convert.inp + Editor value, mode, fileder, key + } + { + inp: 'URL.*' + out: 'mmm/dom' + cost: 0 + transform: (value, fileder, key) => + Editor value, nil, fileder, key + } + } +]] +return { + { + inp = 'text/([^ ]*).*', + out = 'mmm/dom', + cost = 5, + transform = function(self, val) + local lang = self.from:match(self.convert.inp) + return pre(languages[lang](val)) + end + } +} diff --git a/$mmm/plugins/code/converts: text$moonscript -> table.moon b/$mmm/plugins/code/converts: text$moonscript -> table.moon new file mode 100644 index 0000000..851efba --- /dev/null +++ b/$mmm/plugins/code/converts: text$moonscript -> table.moon @@ -0,0 +1,90 @@ +import pre, div, button from require 'mmm.dom' +import languages from require 'mmm.highlighting' + +class Editor + o = if MODE == 'CLIENT' + mkobj = window\eval "(function () { return {}; })" + (tbl) -> + with obj = mkobj! + for k,v in pairs(tbl) + obj[k] = v + + EDITOR: true + + new: (value, mode, @fileder, @key) => + @node = div class: 'editor' + + @saveBtn = with button 'save' + .disabled = true + .onclick = (_, e) -> @save e + + @cm = window\CodeMirror @node, o { + :value + :mode + lineNumber: true + lineWrapping: true + autoRefresh: true + theme: 'hybrid' + } + + @lastSave = @cm\getDoc!\changeGeneration true + + @cm\on 'changes', (_, mirr) -> + doc = @cm\getDoc! + @saveBtn.disabled = doc\isClean @lastSave + + window\clearTimeout @timeout if @timeout + @timeout = window\setTimeout (-> @change!), 300 + + change: => + @timeout = nil + doc = @cm\getDoc! + + if @lastPreview and doc\isClean @lastPreview + -- no changes since last event + return + + @lastPreview = doc\changeGeneration! + value = doc\getValue! + + @fileder.facets[@key] = value + BROWSER\refresh! + + save: (e) => + e\preventDefault! + + doc = @cm\getDoc! + @fileder\set @key, doc\getValue! + @lastSave = doc\changeGeneration true + +[[ + editors: if MODE == 'CLIENT' then { + { + inp: 'text/([^ ]*).*' + out: 'mmm/dom' + cost: 0 + transform: (value, fileder, key) => + mode = @from\match @convert.inp + Editor value, mode, fileder, key + } + { + inp: 'URL.*' + out: 'mmm/dom' + cost: 0 + transform: (value, fileder, key) => + Editor value, nil, fileder, key + } + } +]] + +-- syntax-highlighted code +{ + { + inp: 'text/([^ ]*).*' + out: 'mmm/dom' + cost: 5 + transform: (val) => + lang = @from\match @convert.inp + pre languages[lang] val + } +} diff --git a/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua b/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua new file mode 100644 index 0000000..87a182f --- /dev/null +++ b/$mmm/plugins/code/scripts: text$lua -> fn -> text$html+frag.lua @@ -0,0 +1,12 @@ +local tourl +tourl = (require('mmm.mmmfs.util'))({ }).tourl +return function(self) + return "\n text/css')) .. "\" />" .. [[ + ]] +end diff --git a/$mmm/plugins/code/scripts: text$moonscript -> fn -> text$html+frag.moon b/$mmm/plugins/code/scripts: text$moonscript -> fn -> text$html+frag.moon new file mode 100644 index 0000000..9799ac6 --- /dev/null +++ b/$mmm/plugins/code/scripts: text$moonscript -> fn -> text$html+frag.moon @@ -0,0 +1,14 @@ +import tourl from (require 'mmm.mmmfs.util') {} + +=> + " + text/css'}\" />" .. + [[ + + ]] diff --git a/$mmm/plugins/code/style: text$css.css b/$mmm/plugins/code/style: text$css.css new file mode 100644 index 0000000..0acf4a2 --- /dev/null +++ b/$mmm/plugins/code/style: text$css.css @@ -0,0 +1,110 @@ +/* + +vim-hybrid theme by w0ng (https://github.com/w0ng/vim-hybrid) + +*/ + +/*background color*/ +.hljs { + background: #1d1f21; + border-radius: 6px; + padding: 0.2em 0.5em; + white-space: nowrap; +} + +pre > .hljs { + display: block; + overflow-x: auto; + padding: 1em; + white-space: pre-wrap; + margin: 0 2em; +} + +/*selection color*/ +.hljs::selection, +.hljs span::selection { + background: #373b41; +} + +.hljs::-moz-selection, +.hljs span::-moz-selection { + background: #373b41; +} + +/*foreground color*/ +.hljs { + color: #c5c8c6; +} + +/*color: fg_yellow*/ +.hljs-title, +.hljs-name { + color: #f0c674; +} + +/*color: fg_comment*/ +.hljs-comment, +.hljs-meta, +.hljs-meta .hljs-keyword { + color: #707880; +} + +/*color: fg_red*/ +.hljs-number, +.hljs-symbol, +.hljs-literal, +.hljs-deletion, +.hljs-link { + color: #cc6666 +} + +/*color: fg_green*/ +.hljs-string, +.hljs-doctag, +.hljs-addition, +.hljs-regexp, +.hljs-selector-attr, +.hljs-selector-pseudo { + color: #b5bd68; +} + +/*color: fg_purple*/ +.hljs-attribute, +.hljs-code, +.hljs-selector-id { + color: #b294bb; +} + +/*color: fg_blue*/ +.hljs-keyword, +.hljs-selector-tag, +.hljs-bullet, +.hljs-tag { + color: #81a2be; +} + +/*color: fg_aqua*/ +.hljs-subst, +.hljs-variable, +.hljs-template-tag, +.hljs-template-variable { + color: #8abeb7; +} + +/*color: fg_orange*/ +.hljs-type, +.hljs-built_in, +.hljs-builtin-name, +.hljs-quote, +.hljs-section, +.hljs-selector-class { + color: #de935f; +} + +.hljs-emphasis { + font-style: italic; +} + +.hljs-strong { + font-weight: bold; +} -- cgit v1.2.3