Skip to content

Commit 66cc51d

Browse files
author
Zaydek Michels-Gualtieri
committed
More scratch work
1 parent dca66e4 commit 66cc51d

2 files changed

Lines changed: 112 additions & 15 deletions

File tree

src/Editor/components/toReactTree2/convTypesToArray.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ function sorter(t1, t2) {
1212
return SORT_ORDER[t1] - SORT_ORDER[t2]
1313
}
1414

15-
// Convert a type-map to a type-array.
15+
// Convert a type map to a sorted type array.
1616
function convTypesToArray(types) {
1717
const keys = Object.keys(types).sort(sorter)
1818
return keys.reduce((acc, each) => {
19-
acc.push({ type: each, props: types[each] })
19+
acc.push({
20+
type: each,
21+
props: types[each],
22+
})
2023
return acc
2124
}, [])
2225
}

src/Editor/components/toReactTree2/notes.js

Lines changed: 107 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,130 @@ function doSomething(children) {
2727
break
2828
}
2929
}
30-
recurse(children.slice(x, x2))
30+
31+
// recurse(children.slice(x, x2))
3132
}
3233
}
3334

34-
// Returns a map of the types in common. Returns null if
35-
// there are no types in common.
35+
// // Returns a map of the types in common. Returns null if
36+
// // there are no types in common.
37+
// function typesInCommon(types1, types2) {
38+
// const common = {}
39+
// for (const each of Object.keys(types2)) {
40+
// if (types1[each] && types2[each] && JSONEqual(types1[each], types2[each])) {
41+
// common[each] = types1[each]
42+
// }
43+
// }
44+
// if (!Object.keys(common).length) {
45+
// return null
46+
// }
47+
// return common
48+
// }
49+
50+
// Returns a map of the types in common.
3651
function typesInCommon(types1, types2) {
3752
const common = {}
3853
for (const each of Object.keys(types2)) {
3954
if (types1[each] && types2[each] && JSONEqual(types1[each], types2[each])) {
4055
common[each] = types1[each]
4156
}
4257
}
43-
if (!Object.keys(common).length) {
44-
return null
45-
}
4658
return common
4759
}
4860

4961

50-
// // Converts children to tree-shaped children.
51-
// function toTree(children) {
52-
// const tree = []
53-
// for (const each of children) {
54-
// const [parentElement, types] = queryNext(tree, each)
55-
// parentElement.push(createElement(each, types))
62+
// // Returns an array of keys of the uncommon types.
63+
// function uncommonTypeKeys(types1, types2) {
64+
// const common = {}
65+
// for (const each of Object.keys(types2)) {
66+
// if (types1[each] && types2[each] && JSONEqual(types1[each], types2[each])) {
67+
// common[each] = types1[each]
68+
// }
5669
// }
57-
// return tree
70+
// return common
5871
// }
5972

73+
// Returns an array of uncommon type keys.
74+
function uncommonKeys(types1, types2) {
75+
const uncommon = []
76+
for (const each of Object.keys(types1)) {
77+
if (!types2[each] || !JSONEqual(types1[each], types2[each])) {
78+
uncommon.push(each)
79+
}
80+
}
81+
return uncommon
82+
}
83+
84+
function fn(children) {
85+
if (!children.length) {
86+
// ....
87+
}
88+
89+
const common = JSONClone(children[0].types)
90+
for (const each of children.slice(1)) {
91+
const keys = uncommonKeys(common, each)
92+
for (const key of keys) {
93+
common[key] = undefined
94+
}
95+
}
96+
97+
sortedCommonArray = convTypesToArray(common)
98+
for (const each of sortedCommonArray) {
99+
// render
100+
}
101+
102+
// ...
103+
}
104+
105+
// Stress test
106+
107+
// - code
108+
// --- code + strong
109+
// ----- code + strong + em
110+
// --- code + strong
111+
// - code
112+
113+
<code>
114+
aaa
115+
<strong>
116+
bbb
117+
<em>
118+
ccc
119+
</em>
120+
ddd
121+
</strong>
122+
eee
123+
</code>
124+
125+
// render in common
126+
// render remaining (could be a string)
127+
128+
// ----- code + strong + em
129+
// --- code + strong
130+
// - code
131+
// --- code + strong
132+
// ----- code + strong + em
133+
134+
function render() {
135+
136+
}
137+
138+
<code>
139+
<strong>
140+
<em>
141+
aaa
142+
</em>
143+
bbb
144+
</strong>
145+
ccc
146+
<strong>
147+
ddd
148+
<em>
149+
eee
150+
</em>
151+
</strong>
152+
</code>
153+
60154
[
61155
{
62156
types: {

0 commit comments

Comments
 (0)