@fibery/prosemirror-schema 4.21.0 → 4.22.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 CHANGED
@@ -5,4 +5,6 @@ export { NODE_ATTR_CONSTRAINTS, validateAttrValue, validateAttrs } from "./src/a
5
5
  export type { AttrConstraint, AttrConstraintType, AttrValidationIssue } from "./src/attr-constraints";
6
6
  export { getBlockId, getBlockIdAttr, hasLegacyGuidAttr, buildBlockIdAttrs, getFiberyViewRef, FIBERY_VIEW_TYPE, } from "./src/block-id-utils";
7
7
  export { DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT } from "./src/nodes/video";
8
+ export { DEFAULT_CALLOUT_ICON, DEFAULT_CALLOUT_ICON_TYPE } from "./src/nodes/callout";
9
+ export { ColorToken } from "./src/marks/text-background-color";
8
10
  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.FIBERY_VIEW_TYPE = exports.getFiberyViewRef = exports.buildBlockIdAttrs = exports.hasLegacyGuidAttr = exports.getBlockIdAttr = exports.getBlockId = exports.validateAttrs = exports.validateAttrValue = exports.NODE_ATTR_CONSTRAINTS = exports.Basic = exports.createSchema = exports.Schema = exports.Node = exports.defaultWidth = exports.defaultHeight = void 0;
3
+ exports.ColorToken = exports.DEFAULT_CALLOUT_ICON_TYPE = exports.DEFAULT_CALLOUT_ICON = exports.DEFAULT_VIDEO_HEIGHT = exports.DEFAULT_VIDEO_WIDTH = exports.FIBERY_VIEW_TYPE = exports.getFiberyViewRef = exports.buildBlockIdAttrs = exports.hasLegacyGuidAttr = exports.getBlockIdAttr = exports.getBlockId = exports.validateAttrs = exports.validateAttrValue = exports.NODE_ATTR_CONSTRAINTS = 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; } });
@@ -24,3 +24,8 @@ Object.defineProperty(exports, "FIBERY_VIEW_TYPE", { enumerable: true, get: func
24
24
  var video_1 = require("./src/nodes/video");
25
25
  Object.defineProperty(exports, "DEFAULT_VIDEO_WIDTH", { enumerable: true, get: function () { return video_1.DEFAULT_VIDEO_WIDTH; } });
26
26
  Object.defineProperty(exports, "DEFAULT_VIDEO_HEIGHT", { enumerable: true, get: function () { return video_1.DEFAULT_VIDEO_HEIGHT; } });
27
+ var callout_1 = require("./src/nodes/callout");
28
+ Object.defineProperty(exports, "DEFAULT_CALLOUT_ICON", { enumerable: true, get: function () { return callout_1.DEFAULT_CALLOUT_ICON; } });
29
+ Object.defineProperty(exports, "DEFAULT_CALLOUT_ICON_TYPE", { enumerable: true, get: function () { return callout_1.DEFAULT_CALLOUT_ICON_TYPE; } });
30
+ var text_background_color_1 = require("./src/marks/text-background-color");
31
+ Object.defineProperty(exports, "ColorToken", { enumerable: true, get: function () { return text_background_color_1.ColorToken; } });
@@ -60,7 +60,7 @@ const createSchema = ({ sharedColorGenerator = null, headingToDOM = null, mediaT
60
60
  video: video_1.video,
61
61
  file: file_1.file,
62
62
  emoji: (0, emoji_1.makeEmoji)(emojiOptions),
63
- callout: callout_1.callout,
63
+ callout: (0, callout_1.makeCallout)(emojiOptions),
64
64
  columns: columns_1.columns,
65
65
  column: column_1.column,
66
66
  math_display: math_display_1.math_display,
@@ -1,2 +1,13 @@
1
1
  import type { MarkSpec } from "prosemirror-model";
2
+ export declare enum ColorToken {
3
+ Yellow = "YELLOW",
4
+ Green = "GREEN",
5
+ Aquamarine = "AQUAMARINE",
6
+ Aqua = "AQUA",
7
+ Blue = "BLUE",
8
+ Purple = "PURPLE",
9
+ Pink = "PINK",
10
+ Red = "RED",
11
+ Grey = "GREY"
12
+ }
2
13
  export declare const textBackgroundColor: MarkSpec;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.textBackgroundColor = void 0;
3
+ exports.textBackgroundColor = exports.ColorToken = void 0;
4
4
  var ColorToken;
5
5
  (function (ColorToken) {
6
6
  ColorToken["Yellow"] = "YELLOW";
@@ -12,7 +12,7 @@ var ColorToken;
12
12
  ColorToken["Pink"] = "PINK";
13
13
  ColorToken["Red"] = "RED";
14
14
  ColorToken["Grey"] = "GREY";
15
- })(ColorToken || (ColorToken = {}));
15
+ })(ColorToken || (exports.ColorToken = ColorToken = {}));
16
16
  const isColorToken = (text) => {
17
17
  return Object.values(ColorToken).includes(text);
18
18
  };
@@ -1,4 +1,7 @@
1
- export declare const callout: {
1
+ import type { EmojiOptions } from "./emoji";
2
+ export declare const DEFAULT_CALLOUT_ICON_TYPE = "icon";
3
+ export declare const DEFAULT_CALLOUT_ICON = "exclamation-circle";
4
+ export declare const makeCallout: ({ getEmoji }?: EmojiOptions) => {
2
5
  attrs: {
3
6
  color: {
4
7
  default: string;
@@ -21,10 +24,5 @@ export declare const callout: {
21
24
  icon: string | null;
22
25
  };
23
26
  }[];
24
- toDOM(node: import("prosemirror-model").Node): [string, {
25
- "data-callout-node": string;
26
- "data-color": any;
27
- "data-icon-type": any;
28
- "data-icon": any;
29
- }, number];
27
+ toDOM(node: import("prosemirror-model").Node): [string, Record<string, string>, number];
30
28
  };
@@ -1,12 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.callout = void 0;
3
+ exports.makeCallout = exports.DEFAULT_CALLOUT_ICON = exports.DEFAULT_CALLOUT_ICON_TYPE = void 0;
4
4
  const nodeType = "data-callout-node";
5
- exports.callout = {
5
+ exports.DEFAULT_CALLOUT_ICON_TYPE = "icon";
6
+ exports.DEFAULT_CALLOUT_ICON = "exclamation-circle";
7
+ const aliasAttr = "data-icon-emoji-alias";
8
+ const defaultOptions = {
9
+ getEmoji() {
10
+ return;
11
+ },
12
+ };
13
+ const makeCallout = ({ getEmoji } = defaultOptions) => ({
6
14
  attrs: {
7
15
  color: { default: "#199EE3" },
8
- iconType: { default: "icon" },
9
- icon: { default: "exclamation-circle" },
16
+ iconType: { default: exports.DEFAULT_CALLOUT_ICON_TYPE },
17
+ icon: { default: exports.DEFAULT_CALLOUT_ICON },
10
18
  },
11
19
  group: "block",
12
20
  content: "block+",
@@ -16,11 +24,19 @@ exports.callout = {
16
24
  tag: `div[${nodeType}]`,
17
25
  getAttrs(domNode) {
18
26
  const dom = domNode;
19
- return {
20
- color: dom.getAttribute("data-color"),
21
- iconType: dom.getAttribute("data-icon-type"),
22
- icon: dom.getAttribute("data-icon"),
23
- };
27
+ const color = dom.getAttribute("data-color");
28
+ const iconType = dom.getAttribute("data-icon-type");
29
+ const icon = dom.getAttribute("data-icon");
30
+ if (iconType === "emoji") {
31
+ // A custom emoji is stored in `icon` as a workspace-specific id (`:<uuid>:`).
32
+ // When pasted into another workspace that id doesn't resolve, so fall back to
33
+ // the human alias preserved in `data-icon-emoji-alias` (e.g. `:css:`). This
34
+ // mirrors the inline emoji node and handles copy-paste between workspaces.
35
+ const alias = dom.getAttribute(aliasAttr);
36
+ const emoji = (icon && getEmoji(icon)) || (alias && getEmoji(alias)) || null;
37
+ return { color, iconType, icon: emoji ? emoji.colons : icon };
38
+ }
39
+ return { color, iconType, icon };
24
40
  },
25
41
  },
26
42
  ],
@@ -32,6 +48,15 @@ exports.callout = {
32
48
  "data-icon-type": iconType,
33
49
  "data-icon": icon,
34
50
  };
51
+ if (iconType === "emoji") {
52
+ // Preserve the human-readable alias so a custom emoji icon can be re-resolved
53
+ // when pasted into another workspace, where its id won't match.
54
+ const emoji = getEmoji(icon);
55
+ if (emoji) {
56
+ attrs[aliasAttr] = emoji.native || `:${emoji.shortNames[0]}:`;
57
+ }
58
+ }
35
59
  return ["div", attrs, 0];
36
60
  },
37
- };
61
+ });
62
+ exports.makeCallout = makeCallout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/prosemirror-schema",
3
- "version": "4.21.0",
3
+ "version": "4.22.0",
4
4
  "private": false,
5
5
  "description": "Fibery prosemirror schema",
6
6
  "files": [