@arbidocs/coedit 0.4.120 → 0.4.122

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.js CHANGED
@@ -723,6 +723,10 @@ var NodeRegistry = class {
723
723
  get(id) {
724
724
  return this.entries.get(id);
725
725
  }
726
+ /** Whether the id names a node, one inside a paragraph that is not open yet included. */
727
+ has(id) {
728
+ return (this.entries.get(id) ?? this.resolveInsideParagraph(id)) !== void 0;
729
+ }
726
730
  require(id) {
727
731
  let entry = this.entries.get(id) ?? this.resolveInsideParagraph(id);
728
732
  if (!entry) throw new RegistryError(`journal names unknown node ${id}`);
@@ -1123,8 +1127,31 @@ function moveNode(registry, id, destinationId, destinationIndex) {
1123
1127
  const destination = childrenOf(asLiveElement(destinationEntry.live, destinationId));
1124
1128
  destination.insert(destinationIndex, [registry.toLive(copy)]);
1125
1129
  }
1130
+ function renameNode(registry, id, qname) {
1131
+ const entry = registry.require(id);
1132
+ if ("plain" in entry) {
1133
+ const el = entry.plain;
1134
+ if (el.type !== "element") return false;
1135
+ el.ns = qname.namespaceUri;
1136
+ el.local = qname.localName;
1137
+ if (qname.prefix === void 0) delete el.prefix;
1138
+ else el.prefix = qname.prefix;
1139
+ registry.touch(el);
1140
+ return true;
1141
+ }
1142
+ const live = entry.live;
1143
+ if (live instanceof Y3.Text || isRichParagraph(live)) return false;
1144
+ if (live.get("ns") !== qname.namespaceUri) live.set("ns", qname.namespaceUri);
1145
+ if (live.get("local") !== qname.localName) live.set("local", qname.localName);
1146
+ if (qname.prefix === void 0) {
1147
+ if (live.has("prefix")) live.delete("prefix");
1148
+ } else if (live.get("prefix") !== qname.prefix) live.set("prefix", qname.prefix);
1149
+ return true;
1150
+ }
1126
1151
  function putNode(registry, effect) {
1127
1152
  const d = effect.descriptor;
1153
+ if (d.kind !== "textValue" && registry.has(d.logicalId) && renameNode(registry, d.logicalId, d.qname))
1154
+ return;
1128
1155
  if (d.kind === "textValue") {
1129
1156
  registry.registerPlain({ type: "text", id: d.logicalId, value: "" });
1130
1157
  return;