slate 0.113.0 → 0.114.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +40 -11
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +58 -20
- package/dist/index.js.map +1 -1
- package/dist/interfaces/text.d.ts +10 -1
- package/dist/interfaces/text.d.ts.map +1 -1
- package/dist/slate.js +58 -20
- package/dist/slate.min.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2094,7 +2094,9 @@ var Text = {
|
|
|
2094
2094
|
return true;
|
|
2095
2095
|
},
|
|
2096
2096
|
decorations: function decorations(node, _decorations) {
|
|
2097
|
-
var leaves = [
|
|
2097
|
+
var leaves = [{
|
|
2098
|
+
leaf: _objectSpread$a({}, node)
|
|
2099
|
+
}];
|
|
2098
2100
|
var _iterator = _createForOfIteratorHelper$k(_decorations),
|
|
2099
2101
|
_step;
|
|
2100
2102
|
try {
|
|
@@ -2106,30 +2108,34 @@ var Text = {
|
|
|
2106
2108
|
rest = _objectWithoutProperties(dec, _excluded2$2);
|
|
2107
2109
|
var _Range$edges = Range.edges(dec),
|
|
2108
2110
|
_Range$edges2 = _slicedToArray(_Range$edges, 2),
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
+
_start = _Range$edges2[0],
|
|
2112
|
+
_end = _Range$edges2[1];
|
|
2111
2113
|
var next = [];
|
|
2112
2114
|
var leafEnd = 0;
|
|
2113
|
-
var decorationStart =
|
|
2114
|
-
var decorationEnd =
|
|
2115
|
+
var decorationStart = _start.offset;
|
|
2116
|
+
var decorationEnd = _end.offset;
|
|
2115
2117
|
var merge = mergeDecoration !== null && mergeDecoration !== void 0 ? mergeDecoration : Object.assign;
|
|
2116
|
-
var
|
|
2117
|
-
|
|
2118
|
+
var _iterator3 = _createForOfIteratorHelper$k(leaves),
|
|
2119
|
+
_step3;
|
|
2118
2120
|
try {
|
|
2119
|
-
for (
|
|
2120
|
-
var leaf =
|
|
2121
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
2122
|
+
var leaf = _step3.value.leaf;
|
|
2121
2123
|
var length = leaf.text.length;
|
|
2122
2124
|
var leafStart = leafEnd;
|
|
2123
2125
|
leafEnd += length;
|
|
2124
2126
|
// If the range encompasses the entire leaf, add the range.
|
|
2125
2127
|
if (decorationStart <= leafStart && leafEnd <= decorationEnd) {
|
|
2126
2128
|
merge(leaf, rest);
|
|
2127
|
-
next.push(
|
|
2129
|
+
next.push({
|
|
2130
|
+
leaf: leaf
|
|
2131
|
+
});
|
|
2128
2132
|
continue;
|
|
2129
2133
|
}
|
|
2130
2134
|
// If the range expanded and match the leaf, or starts after, or ends before it, continue.
|
|
2131
2135
|
if (decorationStart !== decorationEnd && (decorationStart === leafEnd || decorationEnd === leafStart) || decorationStart > leafEnd || decorationEnd < leafStart || decorationEnd === leafStart && leafStart !== 0) {
|
|
2132
|
-
next.push(
|
|
2136
|
+
next.push({
|
|
2137
|
+
leaf: leaf
|
|
2138
|
+
});
|
|
2133
2139
|
continue;
|
|
2134
2140
|
}
|
|
2135
2141
|
// Otherwise we need to split the leaf, at the start, end, or both,
|
|
@@ -2140,18 +2146,22 @@ var Text = {
|
|
|
2140
2146
|
var after = void 0;
|
|
2141
2147
|
if (decorationEnd < leafEnd) {
|
|
2142
2148
|
var off = decorationEnd - leafStart;
|
|
2143
|
-
after =
|
|
2144
|
-
|
|
2145
|
-
|
|
2149
|
+
after = {
|
|
2150
|
+
leaf: _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
|
2151
|
+
text: middle.text.slice(off)
|
|
2152
|
+
})
|
|
2153
|
+
};
|
|
2146
2154
|
middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
|
2147
2155
|
text: middle.text.slice(0, off)
|
|
2148
2156
|
});
|
|
2149
2157
|
}
|
|
2150
2158
|
if (decorationStart > leafStart) {
|
|
2151
2159
|
var _off = decorationStart - leafStart;
|
|
2152
|
-
before =
|
|
2153
|
-
|
|
2154
|
-
|
|
2160
|
+
before = {
|
|
2161
|
+
leaf: _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
|
2162
|
+
text: middle.text.slice(0, _off)
|
|
2163
|
+
})
|
|
2164
|
+
};
|
|
2155
2165
|
middle = _objectSpread$a(_objectSpread$a({}, middle), {}, {
|
|
2156
2166
|
text: middle.text.slice(_off)
|
|
2157
2167
|
});
|
|
@@ -2160,15 +2170,17 @@ var Text = {
|
|
|
2160
2170
|
if (before) {
|
|
2161
2171
|
next.push(before);
|
|
2162
2172
|
}
|
|
2163
|
-
next.push(
|
|
2173
|
+
next.push({
|
|
2174
|
+
leaf: middle
|
|
2175
|
+
});
|
|
2164
2176
|
if (after) {
|
|
2165
2177
|
next.push(after);
|
|
2166
2178
|
}
|
|
2167
2179
|
}
|
|
2168
2180
|
} catch (err) {
|
|
2169
|
-
|
|
2181
|
+
_iterator3.e(err);
|
|
2170
2182
|
} finally {
|
|
2171
|
-
|
|
2183
|
+
_iterator3.f();
|
|
2172
2184
|
}
|
|
2173
2185
|
leaves = next;
|
|
2174
2186
|
}
|
|
@@ -2177,6 +2189,32 @@ var Text = {
|
|
|
2177
2189
|
} finally {
|
|
2178
2190
|
_iterator.f();
|
|
2179
2191
|
}
|
|
2192
|
+
if (leaves.length > 1) {
|
|
2193
|
+
var currentOffset = 0;
|
|
2194
|
+
var _iterator2 = _createForOfIteratorHelper$k(leaves.entries()),
|
|
2195
|
+
_step2;
|
|
2196
|
+
try {
|
|
2197
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
2198
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
2199
|
+
index = _step2$value[0],
|
|
2200
|
+
item = _step2$value[1];
|
|
2201
|
+
var start = currentOffset;
|
|
2202
|
+
var end = start + item.leaf.text.length;
|
|
2203
|
+
var position = {
|
|
2204
|
+
start: start,
|
|
2205
|
+
end: end
|
|
2206
|
+
};
|
|
2207
|
+
if (index === 0) position.isFirst = true;
|
|
2208
|
+
if (index === leaves.length - 1) position.isLast = true;
|
|
2209
|
+
item.position = position;
|
|
2210
|
+
currentOffset = end;
|
|
2211
|
+
}
|
|
2212
|
+
} catch (err) {
|
|
2213
|
+
_iterator2.e(err);
|
|
2214
|
+
} finally {
|
|
2215
|
+
_iterator2.f();
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2180
2218
|
return leaves;
|
|
2181
2219
|
}
|
|
2182
2220
|
};
|