Lively Kernel canvas
//null""pt(400, 550)true["EditContent"]function() {
var model = Record.newPlainInstance({EditContent: ''});
this.relayToModel(model, {EditContent: "EditContent"});
}function() {
this.enableEditMode();
}function(extent) {
var panel = new WikiWidgetPanel(extent);
panel = PanelMorph.makePanedPanel(extent, [
['readModeButton', function(bnds){return new ButtonMorph(bnds)}, new Rectangle(0.8, 0, 0.1, 0.03)],
['editModeButton', function(bnds){return new ButtonMorph(bnds)}, new Rectangle(0.9, 0, 0.1, 0.03)],
['body', function(bnds){return new ContainerMorph(bnds)}, new Rectangle(0, 0.05, 1, 0.95)]
], panel);
var m;
var model = this.getModel();
m = panel.readModeButton;
m.setLabel('Read');
m.buttonAction(this.enableReadMode, this);
m.applyStyle({fill: Color.white, borderRadius: 0})
m = panel.editModeButton;
m.setLabel('Edit');
m.buttonAction(this.enableEditMode, this);
m.applyStyle({fill: Color.white, borderRadius: 0})
m = panel.body;
m.applyStyle({fill: null /*Color.red/*null*/, borderWidth: 0});
panel.applyStyle({fill: Color.white, borderWidth: 0.1, borderColor: Color.black});
//panel.suppressHandles = false;
this.panel = panel;
this.panel.widget = this;
this.start();
return panel;
}function() {
this.deleteBodyMorphs();
var bounds = this.getBody().getExtent().subPt(pt(2,2)).extentAsRectangle();
var editMorph = new TextMorph(bounds, this.getEditContent(), true /*Change clue*/);
editMorph.closeDnD(); editMorph.suppressHandles = true;
editMorph.connectModel(this.getModel().newRelay({Text: "EditContent"}));
var scroll = this.createScrollMorphFor(editMorph, bounds);
this.getBody().addMorph(scroll);
}function() {
this.deleteBodyMorphs();
var bounds = this.getBody().getExtent().subPt(pt(2,2)).extentAsRectangle();
var box = new ContainerMorph(bounds);
box.applyStyle({fill: Color.white});
box.ignoreEvents();//box.closeDnD(); //box.suppressHandles = true;
this.getBody().addMorph(this.createScrollMorphFor(box, bounds));
var morphs = this.editContentsToMorphs();
if (!morphs) return;
var yPos = 0;
morphs.forEach(function(ea) {
box.addMorph(ea);
ea.setExtent(pt(bounds.width, ea.getExtent.y));
ea.setPosition(pt(0,yPos));
ea.ignoreEvents();
yPos += ea.getExtent().y;
}, this)
box.owner.owner.getScrollBar().applyStyle({fill: Color.white, borderWidth: 0});
}function() { return this.panel.body }function(newContent) {
this.panel.storedEditContent = newContent;
}function() {
this.getBody().submorphs.invoke('remove');
}function() {
var markup = this.getEditContent().replace(/\r/g, '\n')
var result = OMetaSupport.matchAllWithGrammar(WikiParser, 'wikiTextDescription', markup);
if (!result) return null;
console.log('#morphs: ' + result.length);
return result;
}function($super, world, optLoc) {
// return $super(world, optLoc);
var view = this.buildView(this.getInitialViewExtent(world), this.getModel());
view.ownerWidget = this; // for remembering the widget during serialization...
var window = world.addFramedMorph(view, this.getViewTitle(), optLoc, this.useLightFrame);
window.titleBar.contentMorph.applyStyle({fill: Color.white, borderWidth: 0.1, borderColor: Color.black});
return window;
// if (optLoc) view.setPosition(optLoc);
// return world.addMorph(view);
}function(innerMorph, bounds) {
var m = new ScrollPane(innerMorph, bounds);
m.closeDnD();
innerMorph.closeDnD();
m.getScrollBar().slider.applyStyle({fill: Color.gray.lighter(), borderWidth: 0.2});
m.getScrollBar().applyStyle({fill: Color.white, borderWidth: 0});
return m;
}function() {
//dbgOn(true)
var widget = new WikiWidget();
this.owner.targetMorph = this.owner.addMorph(widget.buildView(this.getExtent()));
this.owner.targetMorph.setPosition(this.getPosition());
this.owner.titleBar.contentMorph.applyStyle({fill: Color.white, borderWidth: 0.1, borderColor: Color.black});
var wikiMarkup = this.storedEditContent;
var inner = this.body.submorphs[0].innerMorph();
if (inner.constructor == ContainerMorph) {
console.log('Deserializing WikiWidget: ReadMode');
widget.enableReadMode();
this.body.submorphs.forEach(function(ea) {
ea.remove();
widget.getBody().addMorph(ea);
}, this)
} else if (inner.constructor == TextMorph && !wikiMarkup) {
console.log('Deserializing WikiWidget: EditMode');
wikiMarkup = inner.textString;
}
if (!wikiMarkup) console.warn('Deserializing WikiWidget: No wiki markup found!' )
widget.setEditContent(wikiMarkup || '');
this.remove();
}
Config.modulesOnWorldLoad.push('lively.Ometa')require('ometa/parser.js').toRun(function() {
WikiParser=Object.delegated(Parser,{"nl":function(){var $elf=this;return $elf._applyWithArgs("exactly","\n")},"createTextSpec":function(){var $elf=this;return (function (){var spec=({"string": "","attributes": []});spec["assemble"]=(function (){var morph=new TextMorph(new Rectangle((0),(0),(10),(10)));morph.applyStyle(({"fill": Color["white"],"borderWidth": (0),"opacity": (0),"fontSize": (16)}));var text=new lively.Text.Text(spec["string"]);spec["attributes"].forEach((function (ea){text.emphasize(ea,ea["start"],ea["stop"])}));morph.setRichText(text);return morph});spec["add"]=(function (str){spec["string"]+=str});spec["addAttribute"]=(function (attr){spec["attributes"].push(attr)});spec["addAttributed"]=(function (str,attribute){attribute["start"]=spec["string"]["length"];spec.add(str);attribute["stop"]=spec["string"]["length"];spec.addAttribute(attribute)});return spec})()},"heading":function(){var $elf=this,start,c,cs,end;return (function(){start=$elf._many1(function(){return $elf._applyWithArgs("exactly","=")});cs=$elf._many1(function(){return (function(){$elf._not(function(){return $elf._applyWithArgs("exactly","\n")});$elf._not(function(){return $elf._applyWithArgs("exactly","=")});c=$elf._apply("char");return c})()});end=$elf._many1(function(){return $elf._applyWithArgs("exactly","=")});$elf._pred((end["length"] == start["length"]));return (function (){var morph=new TextMorph(new Rectangle((0),(0),(10),(10)),cs.join(""));morph.applyStyle(({"fill": Color["white"],"borderWidth": (0),"opacity": (0),"fontSize": ((40) - (start["length"] * (6)))}));return morph})()})()},"paragraph":function(){var $elf=this,spec;return (function(){spec=$elf._apply("createTextSpec");$elf._many1(function(){return $elf._applyWithArgs("atomicText",spec)});return spec.assemble()})()},"nestableText":function(){var $elf=this,spec;return (function(){spec=$elf._apply("anything");return $elf._or((function(){return $elf._applyWithArgs("atomicText",spec)}),(function(){return $elf._applyWithArgs("list",spec)}))})()},"list":function(){var $elf=this,spec,level;return (function(){spec=$elf._apply("anything");level=$elf._many1(function(){return $elf._applyWithArgs("exactly","*")});$elf._apply("spaces");(function (){spec.add(level.collect((function (ea){return "\t"})).join(""));return spec.add("• ")})();$elf._many1(function(){return (function(){$elf._not(function(){return $elf._applyWithArgs("exactly","\n")});return $elf._or((function(){return $elf._applyWithArgs("bold",spec)}),(function(){return $elf._applyWithArgs("italic",spec)}),(function(){return $elf._applyWithArgs("link",spec)}),(function(){return $elf._applyWithArgs("wordsNoNewline",spec)}))})()});$elf._or((function(){return $elf._applyWithArgs("exactly","\n")}),(function(){return $elf._apply("end")}));spec.add("\n");return $elf._many(function(){return $elf._applyWithArgs("list",spec)})})()},"atomicText":function(){var $elf=this,spec;return (function(){spec=$elf._apply("anything");return $elf._or((function(){return $elf._applyWithArgs("wordsNoParagraphEnd",spec)}),(function(){return $elf._applyWithArgs("bold",spec)}),(function(){return $elf._applyWithArgs("italic",spec)}),(function(){return $elf._applyWithArgs("link",spec)}),(function(){return $elf._applyWithArgs("list",spec)}))})()},"character":function(){var $elf=this,spec,c;return (function(){spec=$elf._apply("anything");c=$elf._apply("char");return spec.add(c)})()},"wordsNoParagraphEnd":function(){var $elf=this,spec,c;return (function(){spec=$elf._apply("anything");return $elf._many1(function(){return (function(){$elf._not(function(){return $elf._apply("paragraphEnd")});c=$elf._apply("char");$elf._pred(((((c != "*") && (c != "[")) && (c != "<")) && (c != "\'")));return spec.add(c)})()})})()},"wordsNoNewline":function(){var $elf=this,spec,c;return (function(){spec=$elf._apply("anything");return $elf._many1(function(){return (function(){c=$elf._apply("char");$elf._pred((((((c != "\n") && (c != "*")) && (c != "[")) && (c != "<")) && (c != "\'")));return spec.add(c)})()})})()},"bold":function(){var $elf=this,spec,c,cs;return (function(){spec=$elf._apply("anything");$elf._not(function(){return $elf._apply("space")});$elf._applyWithArgs("token","\'\'\'");cs=$elf._many1(function(){return (function(){$elf._not(function(){return $elf._applyWithArgs("token","\'\'\'")});c=$elf._apply("char");return c})()});$elf._applyWithArgs("token","\'\'\'");return spec.addAttributed(cs.join(""),({"style": "bold"}))})()},"italic":function(){var $elf=this,spec,c,cs;return (function(){spec=$elf._apply("anything");$elf._not(function(){return $elf._apply("space")});$elf._applyWithArgs("token","\'\'");cs=$elf._many1(function(){return (function(){$elf._not(function(){return $elf._applyWithArgs("token","\'\'")});c=$elf._apply("char");return c})()});$elf._applyWithArgs("token","\'\'");return spec.addAttributed(cs.join(""),({"style": "italic"}))})()},"link":function(){var $elf=this,spec,c,target,c,name;return (function(){spec=$elf._apply("anything");$elf._applyWithArgs("exactly","[");target=$elf._many1(function(){return (function(){$elf._not(function(){return $elf._applyWithArgs("exactly","]")});$elf._not(function(){return $elf._apply("space")});c=$elf._apply("char");return c})()});name=$elf._or((function(){return (function(){$elf._many1(function(){return $elf._apply("space")});return $elf._many1(function(){return (function(){$elf._not(function(){return $elf._applyWithArgs("exactly","]")});c=$elf._apply("char");return c})()})})()}),(function(){return (function(){$elf._apply("empty");return []})()}));$elf._applyWithArgs("exactly","]");return spec.addAttributed((name.join("") || target.join("")),({"link": target.join(""),"color": "blue"}))})()},"paragraphEnd":function(){var $elf=this;return (function(){$elf._applyWithArgs("exactly","\n");return $elf._or((function(){return $elf._many1(function(){return $elf._applyWithArgs("exactly","\n")})}),(function(){return $elf._applyWithArgs("exactly","=")}))})()},"partEnd":function(){var $elf=this;return $elf._or((function(){return $elf._many1(function(){return $elf._applyWithArgs("exactly","\n")})}),(function(){return $elf._apply("end")}))},"textParts":function(){var $elf=this,p;return $elf._many1(function(){return (function(){p=$elf._or((function(){return $elf._apply("heading")}),(function(){return $elf._apply("paragraph")}));$elf._apply("partEnd");return p})()})},"log":function(){var $elf=this,msg;return (function(){msg=$elf._apply("anything");return console.log(msg)})()},"wikiTextDescription":function(){var $elf=this,parts;return (function(){parts=$elf._apply("textParts");$elf._apply("end");return parts})()}})
});
10000.1082694727353012Wikicontroltrue
10001.6351527124993779Wikicontroltrue
Readfalsenullfalsefalse
Editfalsenullfalsefalse
truefalsetruetruetruefalse
false1truefalsetruetruefalsefalse
truefalse
nullfalsetruenullfalse
falsenullfalsetrue15nullfalsefalsenullnullnullnullfalsenull45