Skip to content

Commit

Permalink
Handle newline semantically, use special chars to denote text nodes a…
Browse files Browse the repository at this point in the history
…nd unprintable chars in editor HTML

 * move cursor to new section after hitting enter
 * Select the first marker el in a new section rather than the section el
 * Append blank marker to empty section, only create markup from valid tag
 * Do not modify/wrap element in section element in Section parser
  • Loading branch information
bantic committed Jul 31, 2015
1 parent 33d296a commit 99824ba
Show file tree
Hide file tree
Showing 26 changed files with 1,107 additions and 235 deletions.
11 changes: 8 additions & 3 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,21 @@ var ContentKitDemo = exports.ContentKitDemo = {
}
}

function addPipeBetweenAdjacentTextNodes(textNode) {
function markAdjacentTextNodes(textNode) {
var boxChar = '\u2591',
emptySquareChar = '\u25A2',
invisibleChar = '\u200C';
var nextSibling = textNode.nextSibling;
if (nextSibling && nextSibling.nodeType === Node.TEXT_NODE) {
textNode.textContent = textNode.textContent + '|';
textNode.textContent = textNode.textContent + boxChar;
}
textNode.textContent = textNode.textContent.replace(new RegExp(invisibleChar, 'g'),
emptySquareChar);
}

var deep = true;
var cloned = node.cloneNode(deep);
convertTextNodes(cloned, addPipeBetweenAdjacentTextNodes);
convertTextNodes(cloned, markAdjacentTextNodes);
return displayHTML(cloned.innerHTML);
};

Expand Down
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ <h2>rendered mobiledoc (dom)</h2>
<hr>

<h2>innerHTML of editor surface</h2>
<p class='desc'>With special chars to mark text node boundaries and invisible characters.</p>
<div id='editor-html'></div>
</div>

Expand Down
59 changes: 59 additions & 0 deletions notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
abc|def|ghi

i=0, length=0, offset=3
i=1, length=3, offset=3

length === offset


abc <b>bold <i>italic+bold</li> bold2</b> def

const PickColorCard = {
name: 'pick-color',
edit: {
setup(element, options, {save, cancel}, payload) {
// ^ env - an object of runtime options and hooks
let component = EditPickColorComponent.create(payload);
component.save = function(newPayload) {
save(newPayload);
};
component.cancel = cancel;
component.appendTo(element);
return {component};
},
teardown({component}) {
Ember.run(component,component.destroy);
}
},
render: {
setup(element, options, {edit}, payload) {
let component = PickColorComponent.create(payload);
component.appendTo(element);
if (options.mode === 'edit') {
$(element).click(function(){
window.popup(payload.editUrl);
});
}
return {component};
},
teardown({component}) {
Ember.run(component, component.destroy);
};
}
};

new ContentKit.Edtior(editorElement, cards: [
PickColorCard
]});

var domRenderer = new MobiledocDOMRenderer();
var rendered = renderer.render(mobiledoc, {
cardOptions: { mode: 'highQuality' },
unknownCard(element, options, {name}, payload) {
// manage unknown name
// can only be rendered, has no teardown
},
cards: [
PickColorCard
]
});
11 changes: 0 additions & 11 deletions src/js/commands/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import { inherit } from 'content-kit-utils';

function injectCardBlock(/* cardName, cardPayload, editor, index */) {
throw new Error('Unimplemented: BlockModel and Type.CARD are no longer things');
// FIXME: Do we change the block model internal representation here?
/*
var cardBlock = BlockModel.createWithType(Type.CARD, {
attributes: {
name: cardName,
payload: cardPayload
}
});
editor.replaceBlock(cardBlock, index);
*/
}

function CardCommand() {
Expand All @@ -32,7 +22,6 @@ CardCommand.prototype = {
var cardName = 'pick-color';
var cardPayload = { options: ['red', 'blue'] };
injectCardBlock(cardName, cardPayload, editor, currentEditingIndex);
editor.renderBlockAt(currentEditingIndex, true);
}
};

Expand Down
8 changes: 0 additions & 8 deletions src/js/commands/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ OEmbedCommand.prototype.exec = function(url) {
embedIntent.show();
} else {
throw new Error('Unimplemented EmbedModel is not a thing');
/*
var embedModel = new EmbedModel(response);
editorContext.insertBlock(embedModel, index);
editorContext.renderBlockAt(index);
if (embedModel.attributes.provider_name.toLowerCase() === 'twitter') {
loadTwitterWidgets(editorContext.element);
}
*/
}
}
});
Expand Down
Loading

0 comments on commit 99824ba

Please sign in to comment.