Skip to content

Commit 693d220

Browse files
author
Petro Salema
committed
Introducing MutationsTrees
1 parent 55eed9b commit 693d220

6 files changed

Lines changed: 440 additions & 26 deletions

File tree

sandbox/index.html

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
</style>
6060
</head>
6161
<body>
62-
<div class="aloha-editable"><p>one <b>two</b> three</p></div>
62+
<div class="aloha-editable">starting<i>foobar</i><p
63+
><span>one</span> <u><b>two</b> <i>three</i></u></p> <h6
64+
>four</h6
65+
></div>
6366

6467
<br/>
6568

@@ -128,6 +131,44 @@ <h1>Aloha Editor</h1>
128131
}
129132
function main(aloha) {
130133
aloha.arrays.coerce(document.querySelectorAll('.aloha-editable')).forEach(aloha);
134+
aloha.metaview.toggle(document.querySelector('.aloha-editable'),{outline:true,padding: true});
135+
136+
/*
137+
var boundaries = [
138+
aloha.boundaries.create(document.querySelector('.aloha-editable'), 0),
139+
aloha.boundaries.create(document.querySelector('.aloha-editable'), 1),
140+
aloha.boundaries.create(document.querySelector('.aloha-editable'), 2),
141+
aloha.boundaries.create(document.querySelector('.aloha-editable'), 1),
142+
aloha.boundaries.create(document.querySelector('i').firstChild, 1),
143+
aloha.boundaries.create(document.querySelector('i').firstChild, 2),
144+
aloha.boundaries.create(document.querySelector('i').firstChild, 2),
145+
aloha.boundaries.fromEndOfNode(document.querySelector('i')),
146+
aloha.boundaries.fromNode(document.querySelector('i')),
147+
aloha.boundaries.create(document.querySelector('span').firstChild, 2),
148+
aloha.boundaries.create(document.querySelector('i').firstChild, 3),
149+
aloha.boundaries.create(document.querySelector('h6').firstChild, 3)
150+
];
151+
*/
152+
153+
var editable = document.querySelector('.aloha-editable');
154+
var boundaries = [
155+
aloha.boundaries.create(editable.querySelector('h6').firstChild, 2),
156+
aloha.boundaries.create(document.querySelector('b').firstChild, 0),
157+
aloha.boundaries.create(document.querySelector('b').firstChild, 1),
158+
aloha.boundaries.create(document.querySelector('b').firstChild, 2),
159+
aloha.boundaries.create(document.querySelector('b').firstChild, 3),
160+
aloha.boundaries.create(document.querySelector('b'), 1),
161+
aloha.boundaries.create(document.querySelector('b'), 1),
162+
aloha.boundaries.fromNode(document.querySelector('b')),
163+
aloha.boundaries.create(document.querySelector('b').firstChild, 2)
164+
];
165+
var limit = editable; //.querySelector('b').parentNode.parentNode;
166+
var splitBoundary = aloha.boundaries.create(limit.querySelector('b').firstChild, 1);
167+
var path = aloha.paths.fromBoundary(limit, splitBoundary);
168+
var tree = aloha.MutationTrees.create(limit, boundaries);
169+
var result = aloha.MutationTrees.split(tree, path)
170+
var updated = aloha.MutationTrees.update(result[0]);
171+
console.log(updated.domNode(), aloha.markers.hint(aloha.paths.toBoundary(updated.domNode(), result[1])));
131172
}
132173
if ('undefined' === typeof aloha) {
133174
setVersion('src');

src/api.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ define([
4747
'transform',
4848
'traversing',
4949
'typing',
50-
'undo'
50+
'undo',
51+
'mutation-trees'
5152
], function (
5253
Arrays,
5354
Blocks,
@@ -86,7 +87,8 @@ define([
8687
Transform,
8788
Traversing,
8889
Typing,
89-
Undo
90+
Undo,
91+
MutationTrees
9092
) {
9193
'use strict';
9294

@@ -550,5 +552,10 @@ define([
550552
exports['undo']['undo'] = Undo.undo;
551553
exports['undo']['redo'] = Undo.redo;
552554

555+
exports['MutationTrees'] = new Object();
556+
exports['MutationTrees'].split = MutationTrees.split;
557+
exports['MutationTrees'].create = MutationTrees.create;
558+
exports['MutationTrees'].update = MutationTrees.update;
559+
553560
return exports;
554561
});

src/boromir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ define([
621621
* boromir nodes, otherwise the behviour is undefined and may cause
622622
* errors to be thrown. The assumption that the tree wasn't modified
623623
* is necessary so that the DOM can be updated in the most efficient
624-
* manner possible, without perorming any redundant read operations
624+
* manner possible, without peforming any redundant read operations
625625
* on the DOM.
626626
*
627627
* For the reason above, after the DOM has been updated, the boromir

src/metaview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ define(['dom'], function (Dom) {
1414

1515
// outlines
1616
= '.✪{outline:5px solid #fce05e;}'
17-
+ '.✪ td,.✪ th,.✪ b,.✪ i,.✪ u,.✪ p,.✪ ul,.✪ ol,.✪ li,.✪ h1,.✪ h2,.✪ h3,.✪ h4,.✪ h5,.✪ h6,.✪ div{border:1px solid rgba(0,0,0,0.1)}'
17+
+ '.✪ td,.✪ th,.✪ b,.✪ i,.✪ u,.✪ p,.✪ ul,.✪ ol,.✪ li,.✪ h1,.✪ h2,.✪ h3,.✪ h4,.✪ h5,.✪ h6,.✪ div,.✪ span{border:1px solid rgba(0,0,0,0.1)}'
1818
+ '.✪ p,.✪ ul,.✪ ol,.✪ h1,.✪ h2,.✪ h3,.✪ h4,.✪ h5,.✪ h6,.✪ div{border-width:2px}'
1919
+ '.✪ b{border-color:#f47d43}'
2020
+ '.✪ i{border-color:#82b5e0}'

0 commit comments

Comments
 (0)