@portabletext/editor 4.3.4 → 4.3.5

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/lib/index.js CHANGED
@@ -283,7 +283,7 @@ function isEqualToEmptyEditor(initialValue, blocks, schemaTypes) {
283
283
  if (!Element$1.isElement(firstBlock) || firstBlock._type !== schemaTypes.block.name || "listItem" in firstBlock || !("style" in firstBlock) || firstBlock.style !== schemaTypes.styles.at(0)?.name || !Array.isArray(firstBlock.children) || firstBlock.children.length !== 1)
284
284
  return !1;
285
285
  const firstChild = firstBlock.children.at(0);
286
- return !(!firstChild || !Text.isText(firstChild) || !("_type" in firstChild) || firstChild._type !== schemaTypes.span.name || firstChild.text !== "" || firstChild.marks?.join("") || Object.keys(firstBlock).some((key) => key !== "_type" && key !== "_key" && key !== "children" && key !== "markDefs" && key !== "style") || isEqualValues({
286
+ return !(!firstChild || !Text.isText(firstChild) || !("_type" in firstChild) || firstChild._type !== schemaTypes.span.name || firstChild.text !== "" || firstChild.marks?.join("") || "markDefs" in firstBlock && Array.isArray(firstBlock.markDefs) && firstBlock.markDefs.length > 0 || Object.keys(firstBlock).some((key) => key !== "_type" && key !== "_key" && key !== "children" && key !== "markDefs" && key !== "style") || isEqualValues({
287
287
  schema: schemaTypes
288
288
  }, initialValue, [firstBlock]));
289
289
  }
@@ -5218,11 +5218,21 @@ function mergeNodePatch(schema, children, operation, beforeValue) {
5218
5218
  }, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && isSpan({
5219
5219
  schema
5220
5220
  }, block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
5221
- updatedSpan && (block.children.filter((span) => span._key === updatedSpan._key).length === 1 ? patches.push(set(updatedSpan.text, [{
5222
- _key: block._key
5223
- }, "children", {
5224
- _key: updatedSpan._key
5225
- }, "text"])) : console.warn(`Multiple spans have \`_key\` ${updatedSpan._key}. It's ambiguous which one to update.`, JSON.stringify(block, null, 2))), removedSpan && (block.children.filter((span) => span._key === removedSpan._key).length === 1 ? patches.push(unset([{
5221
+ if (updatedSpan) {
5222
+ const spansMatchingKey = block.children.filter((span) => span._key === updatedSpan._key);
5223
+ if (spansMatchingKey.length === 1) {
5224
+ const prevSpan = spansMatchingKey[0];
5225
+ isSpan({
5226
+ schema
5227
+ }, prevSpan) && prevSpan.text !== updatedSpan.text && patches.push(set(updatedSpan.text, [{
5228
+ _key: block._key
5229
+ }, "children", {
5230
+ _key: updatedSpan._key
5231
+ }, "text"]));
5232
+ } else
5233
+ console.warn(`Multiple spans have \`_key\` ${updatedSpan._key}. It's ambiguous which one to update.`, JSON.stringify(block, null, 2));
5234
+ }
5235
+ removedSpan && (block.children.filter((span) => span._key === removedSpan._key).length === 1 ? patches.push(unset([{
5226
5236
  _key: block._key
5227
5237
  }, "children", {
5228
5238
  _key: removedSpan._key