@abraca/nuxt 2.50.0 → 2.51.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/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "2.50.0",
7
+ "version": "2.51.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -12,8 +12,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
12
12
  awareness: boolean;
13
13
  tag: "video" | "audio";
14
14
  live: boolean;
15
- controls: boolean;
16
15
  total: boolean;
16
+ controls: boolean;
17
17
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
18
  declare const _default: typeof __VLS_export;
19
19
  export default _default;
@@ -12,8 +12,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
12
12
  awareness: boolean;
13
13
  tag: "video" | "audio";
14
14
  live: boolean;
15
- controls: boolean;
16
15
  total: boolean;
16
+ controls: boolean;
17
17
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
18
  declare const _default: typeof __VLS_export;
19
19
  export default _default;
@@ -20,9 +20,8 @@ async function getServerDoc() {
20
20
  }
21
21
  export async function renderDocToHTML(ydoc) {
22
22
  try {
23
- const [{ getSchema }, { yDocToProsemirrorJSON }, { default: StarterKit }, { Node, DOMSerializer }, { coreServerSchemaStubs, pruneUnknownNodes }] = await Promise.all([
23
+ const [{ getSchema }, { default: StarterKit }, { Node, DOMSerializer }, { coreServerSchemaStubs, pruneUnknownNodes, yFragmentToPmJSON }] = await Promise.all([
24
24
  import("@tiptap/core"),
25
- import("@tiptap/y-tiptap"),
26
25
  import("@tiptap/starter-kit"),
27
26
  import("prosemirror-model"),
28
27
  import("./serverSchemaStubs.js")
@@ -32,7 +31,11 @@ export async function renderDocToHTML(ydoc) {
32
31
  ...coreServerSchemaStubs(_extensions),
33
32
  ..._extensions
34
33
  ]);
35
- const json = pruneUnknownNodes(yDocToProsemirrorJSON(ydoc, "default"), schema);
34
+ const { json: rawJson, dropped } = yFragmentToPmJSON(ydoc.getXmlFragment("default"));
35
+ if (dropped.length) {
36
+ console.warn(`[abracadabra:doc-cache] skipped ${dropped.length} unclassifiable node(s) while rendering:`, [...new Set(dropped)].join(", "));
37
+ }
38
+ const json = pruneUnknownNodes(rawJson, schema);
36
39
  const node = Node.fromJSON(schema, json);
37
40
  const serverDoc = await getServerDoc();
38
41
  const container = serverDoc.createElement("div");
@@ -14,6 +14,15 @@ interface PmJsonNode {
14
14
  }>;
15
15
  [key: string]: unknown;
16
16
  }
17
+ /**
18
+ * Convert a Y.XmlFragment to ProseMirror `{ type: 'doc', content }` JSON without
19
+ * relying on cross-module `instanceof`. Unclassifiable children are dropped and
20
+ * their type name collected in `dropped` for a single non-fatal warning.
21
+ */
22
+ export declare function yFragmentToPmJSON(fragment: any): {
23
+ json: PmJsonNode;
24
+ dropped: string[];
25
+ };
17
26
  /**
18
27
  * Drop nodes whose type the schema doesn't know (and unknown marks), keeping
19
28
  * everything else intact. Returns a structurally-cloned JSON tree that is
@@ -33,6 +33,47 @@ export function coreServerSchemaStubs(appExtensions = []) {
33
33
  const taken = new Set(appExtensions.map((e) => e.name));
34
34
  return [DocumentHeaderStub, DocumentMetaStub, CalloutStub, DividerStub, QuoteStub].filter((s) => !taken.has(s.name));
35
35
  }
36
+ const HASHED_MARK_NAME = /(.*)--[a-z0-9+/=]{8}$/i;
37
+ function yAttrToMarkName(attrName) {
38
+ return HASHED_MARK_NAME.exec(attrName)?.[1] ?? attrName;
39
+ }
40
+ function isYText(item) {
41
+ return item != null && typeof item.toDelta === "function" && typeof item.nodeName !== "string";
42
+ }
43
+ function isYElement(item) {
44
+ return item != null && typeof item.nodeName === "string" && typeof item.getAttributes === "function" && typeof item.toArray === "function";
45
+ }
46
+ export function yFragmentToPmJSON(fragment) {
47
+ const dropped = [];
48
+ const serialize = (item) => {
49
+ if (isYText(item)) {
50
+ return item.toDelta().map((d) => {
51
+ const text = { type: "text", text: d.insert };
52
+ if (d.attributes) {
53
+ text.marks = Object.keys(d.attributes).map((key) => {
54
+ const mark = { type: yAttrToMarkName(key) };
55
+ const attrs = d.attributes[key];
56
+ if (attrs && Object.keys(attrs).length) mark.attrs = attrs;
57
+ return mark;
58
+ });
59
+ }
60
+ return text;
61
+ });
62
+ }
63
+ if (isYElement(item)) {
64
+ const node = { type: item.nodeName };
65
+ const attrs = item.getAttributes();
66
+ if (attrs && Object.keys(attrs).length) node.attrs = attrs;
67
+ const children = item.toArray().flatMap(serialize);
68
+ if (children.length) node.content = children;
69
+ return [node];
70
+ }
71
+ dropped.push(item?.constructor?.name ?? typeof item);
72
+ return [];
73
+ };
74
+ const content = fragment.toArray().flatMap(serialize);
75
+ return { json: { type: "doc", content }, dropped };
76
+ }
36
77
  export function pruneUnknownNodes(json, schema) {
37
78
  const knownNode = (t) => !!t && !!schema.nodes[t];
38
79
  const knownMark = (t) => !!t && !!schema.marks[t];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/nuxt",
3
- "version": "2.50.0",
3
+ "version": "2.51.0",
4
4
  "description": "First-class Nuxt module for the Abracadabra CRDT collaboration platform",
5
5
  "repository": "abracadabra/abracadabra-nuxt",
6
6
  "license": "MIT",