@fibery/prosemirror-schema 4.19.0-next.3 → 4.20.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/lib/index.d.ts +1 -0
- package/lib/index.js +8 -1
- package/lib/src/block-id-utils.d.ts +7 -0
- package/lib/src/block-id-utils.js +49 -0
- package/lib/src/create-schema.js +3 -0
- package/lib/src/nodes/fibery-view.js +10 -3
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { defaultHeight, defaultWidth } from "./src/resizable-node-attrs";
|
|
2
2
|
export { Node, Schema } from "prosemirror-model";
|
|
3
3
|
export { createSchema, Basic } from "./src/create-schema";
|
|
4
|
+
export { getBlockId, getBlockIdAttr, hasLegacyGuidAttr, buildBlockIdAttrs, getFiberyViewRef, FIBERY_VIEW_TYPE, } from "./src/block-id-utils";
|
|
4
5
|
export { DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT } from "./src/nodes/video";
|
|
5
6
|
export type { EmojiOptions } from "./src/nodes/emoji";
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_VIDEO_HEIGHT = exports.DEFAULT_VIDEO_WIDTH = exports.Basic = exports.createSchema = exports.Schema = exports.Node = exports.defaultWidth = exports.defaultHeight = void 0;
|
|
3
|
+
exports.DEFAULT_VIDEO_HEIGHT = exports.DEFAULT_VIDEO_WIDTH = exports.FIBERY_VIEW_TYPE = exports.getFiberyViewRef = exports.buildBlockIdAttrs = exports.hasLegacyGuidAttr = exports.getBlockIdAttr = exports.getBlockId = exports.Basic = exports.createSchema = exports.Schema = exports.Node = exports.defaultWidth = exports.defaultHeight = void 0;
|
|
4
4
|
var resizable_node_attrs_1 = require("./src/resizable-node-attrs");
|
|
5
5
|
Object.defineProperty(exports, "defaultHeight", { enumerable: true, get: function () { return resizable_node_attrs_1.defaultHeight; } });
|
|
6
6
|
Object.defineProperty(exports, "defaultWidth", { enumerable: true, get: function () { return resizable_node_attrs_1.defaultWidth; } });
|
|
@@ -10,6 +10,13 @@ Object.defineProperty(exports, "Schema", { enumerable: true, get: function () {
|
|
|
10
10
|
var create_schema_1 = require("./src/create-schema");
|
|
11
11
|
Object.defineProperty(exports, "createSchema", { enumerable: true, get: function () { return create_schema_1.createSchema; } });
|
|
12
12
|
Object.defineProperty(exports, "Basic", { enumerable: true, get: function () { return create_schema_1.Basic; } });
|
|
13
|
+
var block_id_utils_1 = require("./src/block-id-utils");
|
|
14
|
+
Object.defineProperty(exports, "getBlockId", { enumerable: true, get: function () { return block_id_utils_1.getBlockId; } });
|
|
15
|
+
Object.defineProperty(exports, "getBlockIdAttr", { enumerable: true, get: function () { return block_id_utils_1.getBlockIdAttr; } });
|
|
16
|
+
Object.defineProperty(exports, "hasLegacyGuidAttr", { enumerable: true, get: function () { return block_id_utils_1.hasLegacyGuidAttr; } });
|
|
17
|
+
Object.defineProperty(exports, "buildBlockIdAttrs", { enumerable: true, get: function () { return block_id_utils_1.buildBlockIdAttrs; } });
|
|
18
|
+
Object.defineProperty(exports, "getFiberyViewRef", { enumerable: true, get: function () { return block_id_utils_1.getFiberyViewRef; } });
|
|
19
|
+
Object.defineProperty(exports, "FIBERY_VIEW_TYPE", { enumerable: true, get: function () { return block_id_utils_1.FIBERY_VIEW_TYPE; } });
|
|
13
20
|
var video_1 = require("./src/nodes/video");
|
|
14
21
|
Object.defineProperty(exports, "DEFAULT_VIDEO_WIDTH", { enumerable: true, get: function () { return video_1.DEFAULT_VIDEO_WIDTH; } });
|
|
15
22
|
Object.defineProperty(exports, "DEFAULT_VIDEO_HEIGHT", { enumerable: true, get: function () { return video_1.DEFAULT_VIDEO_HEIGHT; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Node, NodeType } from "prosemirror-model";
|
|
2
|
+
export declare const getBlockIdAttr: (type: NodeType) => "id" | null;
|
|
3
|
+
export declare const hasLegacyGuidAttr: (type: NodeType) => boolean;
|
|
4
|
+
export declare const getBlockId: (node: Node) => string | null;
|
|
5
|
+
export declare const buildBlockIdAttrs: (node: Node, nextId: string) => Record<string, unknown>;
|
|
6
|
+
export declare const FIBERY_VIEW_TYPE = "fiberyView";
|
|
7
|
+
export declare const getFiberyViewRef: (node: Node) => string | null;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFiberyViewRef = exports.FIBERY_VIEW_TYPE = exports.buildBlockIdAttrs = exports.getBlockId = exports.hasLegacyGuidAttr = exports.getBlockIdAttr = void 0;
|
|
4
|
+
// Node types whose "id" attr references another entity rather than
|
|
5
|
+
// identifying the block itself — never generate or rewrite these ids.
|
|
6
|
+
const REFERENCE_ID_TYPES = new Set(["fiberyView"]);
|
|
7
|
+
// Returns the block-identifier attr of a node type, or null when the type
|
|
8
|
+
// carries no block id (inline nodes, the doc itself, reference ids).
|
|
9
|
+
const getBlockIdAttr = (type) => {
|
|
10
|
+
if (type.isInline || type.name === "doc" || REFERENCE_ID_TYPES.has(type.name)) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const attrs = type.spec.attrs ?? {};
|
|
14
|
+
return "id" in attrs ? "id" : null;
|
|
15
|
+
};
|
|
16
|
+
exports.getBlockIdAttr = getBlockIdAttr;
|
|
17
|
+
// paragraph/heading/code_block keep the deprecated "guid" attr mirrored to
|
|
18
|
+
// "id" until all consumers (references, highlights) read "id".
|
|
19
|
+
const hasLegacyGuidAttr = (type) => {
|
|
20
|
+
const attrs = type.spec.attrs ?? {};
|
|
21
|
+
return "guid" in attrs;
|
|
22
|
+
};
|
|
23
|
+
exports.hasLegacyGuidAttr = hasLegacyGuidAttr;
|
|
24
|
+
const normalizeId = (value) => (typeof value === "string" && value !== "" ? value : null);
|
|
25
|
+
// The effective block id: "id" with a fallback to the legacy "guid".
|
|
26
|
+
const getBlockId = (node) => {
|
|
27
|
+
if ((0, exports.getBlockIdAttr)(node.type) === null) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return normalizeId(node.attrs.id) ?? normalizeId(node.attrs.guid);
|
|
31
|
+
};
|
|
32
|
+
exports.getBlockId = getBlockId;
|
|
33
|
+
// Attrs object with the block id set (and mirrored into "guid" on legacy types).
|
|
34
|
+
const buildBlockIdAttrs = (node, nextId) => ({
|
|
35
|
+
...node.attrs,
|
|
36
|
+
id: nextId,
|
|
37
|
+
...((0, exports.hasLegacyGuidAttr)(node.type) ? { guid: nextId } : {}),
|
|
38
|
+
});
|
|
39
|
+
exports.buildBlockIdAttrs = buildBlockIdAttrs;
|
|
40
|
+
exports.FIBERY_VIEW_TYPE = "fiberyView";
|
|
41
|
+
// The embedded view entity reference of a fiberyView node: "viewId" with a
|
|
42
|
+
// fallback to the deprecated "id" (documents saved before "viewId" existed).
|
|
43
|
+
const getFiberyViewRef = (node) => {
|
|
44
|
+
if (node.type.name !== exports.FIBERY_VIEW_TYPE) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return normalizeId(node.attrs.viewId) ?? normalizeId(node.attrs.id);
|
|
48
|
+
};
|
|
49
|
+
exports.getFiberyViewRef = getFiberyViewRef;
|
package/lib/src/create-schema.js
CHANGED
|
@@ -9,6 +9,11 @@ exports.fiberyView = {
|
|
|
9
9
|
atom: true,
|
|
10
10
|
draggable: false,
|
|
11
11
|
attrs: {
|
|
12
|
+
// "viewId" references the embedded view entity. "id" is deprecated and
|
|
13
|
+
// kept mirrored to "viewId" until every consumer (older clients, the
|
|
14
|
+
// collaboration service, fibery backend) reads "viewId"; after that "id"
|
|
15
|
+
// will become the standard block identifier like on every other block.
|
|
16
|
+
viewId: { default: null },
|
|
12
17
|
id: { default: "" },
|
|
13
18
|
...(0, resizable_node_attrs_1.createDefaultAttrs)(),
|
|
14
19
|
},
|
|
@@ -17,17 +22,19 @@ exports.fiberyView = {
|
|
|
17
22
|
tag: "div[data-view-id]",
|
|
18
23
|
getAttrs: (domNode) => {
|
|
19
24
|
const dom = domNode;
|
|
25
|
+
const viewId = dom.getAttribute("data-view-id");
|
|
20
26
|
return {
|
|
21
|
-
|
|
27
|
+
viewId,
|
|
28
|
+
id: viewId,
|
|
22
29
|
...(0, resizable_node_attrs_1.createParseDomAttrs)(dom),
|
|
23
30
|
};
|
|
24
31
|
},
|
|
25
32
|
},
|
|
26
33
|
],
|
|
27
34
|
toDOM(node) {
|
|
28
|
-
const
|
|
35
|
+
const viewId = node.attrs.viewId || node.attrs.id;
|
|
29
36
|
const attrs = {
|
|
30
|
-
"data-view-id":
|
|
37
|
+
"data-view-id": viewId,
|
|
31
38
|
contenteditable: "false",
|
|
32
39
|
...(0, resizable_node_attrs_1.createToDomAttrs)(node.attrs),
|
|
33
40
|
};
|