@examplary/ui 1.47.0 → 1.49.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.
Files changed (32) hide show
  1. package/README.md +1 -1
  2. package/dist/components/rich-text/index.d.ts +2 -1
  3. package/dist/components/rich-text/index.js +2 -1
  4. package/dist/components/rich-text/minimal-rich-text-field.d.ts +7 -2
  5. package/dist/components/rich-text/minimal-rich-text-field.js +53 -34
  6. package/dist/components/rich-text/tiptap/collaboration-caret.d.ts +25 -0
  7. package/dist/components/rich-text/tiptap/collaboration-caret.js +81 -0
  8. package/dist/components/rich-text/tiptap/content-reference.d.ts +3 -0
  9. package/dist/components/rich-text/tiptap/content-reference.js +25 -0
  10. package/dist/components/rich-text/tiptap/extensions.d.ts +2 -0
  11. package/dist/components/rich-text/tiptap/extensions.js +43 -0
  12. package/dist/components/rich-text/tiptap/file-attachment.js +38 -14
  13. package/dist/components/rich-text/tiptap/image.d.ts +0 -19
  14. package/dist/components/rich-text/tiptap/mathematics-component.js +2 -2
  15. package/dist/components/rich-text/tiptap/mathematics.js +1 -1
  16. package/dist/components/rich-text/tiptap/page-clipping.js +0 -26
  17. package/dist/components/rich-text/tiptap/rich-text-formatting-menu.js +35 -27
  18. package/dist/components/ui/badge.d.ts +1 -1
  19. package/dist/components/ui/badge.js +1 -0
  20. package/dist/components/ui/button.js +1 -1
  21. package/dist/components/ui/popover.js +1 -1
  22. package/dist/components/web-components/content-reference.d.ts +11 -0
  23. package/dist/components/web-components/content-reference.js +111 -0
  24. package/dist/components/web-components/file-attachment.d.ts +0 -9
  25. package/dist/components/web-components/file-attachment.js +20 -11
  26. package/dist/components/web-components/index.d.ts +1 -0
  27. package/dist/components/web-components/index.js +6 -0
  28. package/dist/components/web-components/page-clipping.d.ts +0 -1
  29. package/dist/components/web-components/page-clipping.js +5 -9
  30. package/dist/src/global.css +1 -1
  31. package/package.json +9 -4
  32. package/src/global.css +59 -0
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # UI components for Examplary
2
2
 
3
- Read more in the [📘 Developer Documentation](https://developers.examplary.ai/question-types).
3
+ Read more in the [📘 Developer Documentation](https://examplary.ai/developers/question-types).
@@ -1,5 +1,6 @@
1
1
  export { RichTextDisplay } from "./rich-text-display";
2
2
  export { RichTextField } from "./rich-text-field";
3
3
  export { RichTextToolbar } from "./rich-text-toolbar";
4
- export { MinimalRichTextField } from "./minimal-rich-text-field";
4
+ export { MinimalRichTextField, getEditorById } from "./minimal-rich-text-field";
5
5
  export { processFilesAsString } from "./tiptap/file-handler";
6
+ export * from "./tiptap/extensions";
@@ -1,5 +1,6 @@
1
1
  export { RichTextDisplay } from "./rich-text-display";
2
2
  export { RichTextField } from "./rich-text-field";
3
3
  export { RichTextToolbar } from "./rich-text-toolbar";
4
- export { MinimalRichTextField } from "./minimal-rich-text-field";
4
+ export { MinimalRichTextField, getEditorById } from "./minimal-rich-text-field";
5
5
  export { processFilesAsString } from "./tiptap/file-handler";
6
+ export * from "./tiptap/extensions";
@@ -1,4 +1,6 @@
1
- import { EditorContentProps } from "@tiptap/react";
1
+ import { Editor, EditorContentProps } from "@tiptap/react";
2
+ import { XmlFragment } from "yjs";
3
+ export declare const getEditorById: (id: string) => Editor;
2
4
  export type MinimalRichTextFieldProps = {
3
5
  className?: string;
4
6
  value?: string;
@@ -9,11 +11,14 @@ export type MinimalRichTextFieldProps = {
9
11
  onBlur?: (value: string) => void;
10
12
  slotBefore?: (editor: any) => React.ReactNode;
11
13
  singleLine?: boolean;
14
+ id?: string;
12
15
  autoFocus?: boolean;
13
16
  showFormattingMenu?: boolean;
14
17
  uploadFile?: (file: File) => Promise<{
15
18
  url: string;
16
19
  name: string;
17
20
  }>;
21
+ fragment?: XmlFragment;
22
+ awareness?: any;
18
23
  } & Omit<EditorContentProps, "editor">;
19
- export declare const MinimalRichTextField: ({ className, value, defaultValue, placeholder, onChange, onBlur, slotBefore, style, singleLine, autoFocus, showFormattingMenu, uploadFile, ...props }: MinimalRichTextFieldProps) => import("react/jsx-runtime").JSX.Element;
24
+ export declare const MinimalRichTextField: ({ className, value, defaultValue, placeholder, onChange, onBlur, slotBefore, style, singleLine, autoFocus, showFormattingMenu, uploadFile, fragment, awareness, id, ...props }: MinimalRichTextFieldProps) => import("react/jsx-runtime").JSX.Element;
@@ -32,23 +32,38 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
32
32
  };
33
33
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
34
34
  import { useEffect, useMemo, useState } from "react";
35
+ import Collaboration from "@tiptap/extension-collaboration";
35
36
  import Document from "@tiptap/extension-document";
36
- import Highlight from "@tiptap/extension-highlight";
37
- import Link from "@tiptap/extension-link";
38
37
  import Placeholder from "@tiptap/extension-placeholder";
39
- import { TableKit } from "@tiptap/extension-table";
40
- import Typography from "@tiptap/extension-typography";
38
+ import { UndoRedo } from "@tiptap/extensions";
41
39
  import { EditorContent, useEditor, } from "@tiptap/react";
42
- import StarterKit from "@tiptap/starter-kit";
40
+ import { CollaborationCaret } from "./tiptap/collaboration-caret";
43
41
  import { cn } from "../../utils";
44
42
  import { registerWebComponents } from "../web-components";
45
- import FileAttachment from "./tiptap/file-attachment";
43
+ import { defaultRichTextExtensions } from "./tiptap/extensions";
46
44
  import { fileHandler } from "./tiptap/file-handler";
47
45
  import Image from "./tiptap/image";
48
- import { Mathematics } from "./tiptap/mathematics";
49
- import PageClipping from "./tiptap/page-clipping";
50
46
  import { RichTextFormattingMenu } from "./tiptap/rich-text-formatting-menu";
51
47
  registerWebComponents();
48
+ var textEditors = new Map();
49
+ export var getEditorById = function (id) {
50
+ return textEditors.get(id);
51
+ };
52
+ var CustomCollaboration = Collaboration.extend({
53
+ addCommands: function () {
54
+ return {
55
+ undo: function () { return function () {
56
+ return false;
57
+ }; },
58
+ redo: function () { return function () {
59
+ return false;
60
+ }; },
61
+ };
62
+ },
63
+ addKeyboardShortcuts: function () {
64
+ return {};
65
+ },
66
+ });
52
67
  var isEmpty = function (value) {
53
68
  var _a;
54
69
  if (!value) {
@@ -66,36 +81,26 @@ var isEmpty = function (value) {
66
81
  return false;
67
82
  };
68
83
  export var MinimalRichTextField = function (_a) {
69
- var _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.value, value = _c === void 0 ? "" : _c, defaultValue = _a.defaultValue, _d = _a.placeholder, placeholder = _d === void 0 ? "" : _d, onChange = _a.onChange, onBlur = _a.onBlur, slotBefore = _a.slotBefore, style = _a.style, _e = _a.singleLine, singleLine = _e === void 0 ? false : _e, _f = _a.autoFocus, autoFocus = _f === void 0 ? false : _f, _g = _a.showFormattingMenu, showFormattingMenu = _g === void 0 ? false : _g, _h = _a.uploadFile, uploadFile = _h === void 0 ? undefined : _h, props = __rest(_a, ["className", "value", "defaultValue", "placeholder", "onChange", "onBlur", "slotBefore", "style", "singleLine", "autoFocus", "showFormattingMenu", "uploadFile"]);
84
+ var _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.value, value = _c === void 0 ? "" : _c, defaultValue = _a.defaultValue, _d = _a.placeholder, placeholder = _d === void 0 ? "" : _d, onChange = _a.onChange, onBlur = _a.onBlur, slotBefore = _a.slotBefore, style = _a.style, _e = _a.singleLine, singleLine = _e === void 0 ? false : _e, _f = _a.autoFocus, autoFocus = _f === void 0 ? false : _f, _g = _a.showFormattingMenu, showFormattingMenu = _g === void 0 ? false : _g, _h = _a.uploadFile, uploadFile = _h === void 0 ? undefined : _h, fragment = _a.fragment, awareness = _a.awareness, id = _a.id, props = __rest(_a, ["className", "value", "defaultValue", "placeholder", "onChange", "onBlur", "slotBefore", "style", "singleLine", "autoFocus", "showFormattingMenu", "uploadFile", "fragment", "awareness", "id"]);
70
85
  var _j = useState(value), content = _j[0], setContent = _j[1];
71
86
  var extensions = useMemo(function () {
72
- return __spreadArray(__spreadArray([], (singleLine
73
- ? [
74
- StarterKit.configure({
75
- document: false,
76
- link: false,
77
- }),
78
- Document.extend({
87
+ return __spreadArray(__spreadArray([], defaultRichTextExtensions, true), [
88
+ singleLine
89
+ ? Document.extend({
79
90
  content: "block",
80
- }),
81
- ]
82
- : [StarterKit.configure({ link: false })]), true), [
83
- Link.configure({
84
- openOnClick: false,
85
- }),
86
- Typography,
91
+ })
92
+ : Document,
87
93
  Image,
94
+ !fragment && UndoRedo,
95
+ fragment &&
96
+ CustomCollaboration.configure({
97
+ fragment: fragment,
98
+ }),
99
+ awareness && CollaborationCaret.configure({ awareness: awareness }),
88
100
  placeholder && Placeholder.configure({ placeholder: placeholder }),
89
- FileAttachment,
90
- PageClipping,
91
- Mathematics,
92
- Highlight,
93
- TableKit.configure({
94
- table: { resizable: true },
95
- }),
96
101
  uploadFile && fileHandler(uploadFile),
97
102
  ], false).filter(Boolean);
98
- }, [singleLine, placeholder, uploadFile]);
103
+ }, [singleLine, placeholder, uploadFile, fragment, awareness]);
99
104
  var editor = useEditor({
100
105
  onUpdate: function (_a) {
101
106
  var editor = _a.editor;
@@ -111,7 +116,7 @@ export var MinimalRichTextField = function (_a) {
111
116
  onBlur === null || onBlur === void 0 ? void 0 : onBlur(html);
112
117
  },
113
118
  autofocus: autoFocus,
114
- content: content,
119
+ content: fragment ? undefined : content,
115
120
  extensions: extensions,
116
121
  editorProps: {
117
122
  attributes: {
@@ -121,6 +126,8 @@ export var MinimalRichTextField = function (_a) {
121
126
  },
122
127
  });
123
128
  useEffect(function () {
129
+ if (fragment)
130
+ return;
124
131
  if (value !== content && defaultValue === undefined) {
125
132
  setContent(value);
126
133
  editor === null || editor === void 0 ? void 0 : editor.commands.setContent(value, {
@@ -130,8 +137,10 @@ export var MinimalRichTextField = function (_a) {
130
137
  },
131
138
  });
132
139
  }
133
- }, [value, content, editor]);
140
+ }, [value, content, editor, fragment]);
134
141
  useEffect(function () {
142
+ if (fragment)
143
+ return;
135
144
  if (defaultValue !== undefined) {
136
145
  setContent(defaultValue);
137
146
  editor === null || editor === void 0 ? void 0 : editor.commands.setContent(defaultValue, {
@@ -141,6 +150,16 @@ export var MinimalRichTextField = function (_a) {
141
150
  },
142
151
  });
143
152
  }
144
- }, [defaultValue]);
153
+ }, [defaultValue, fragment]);
154
+ useEffect(function () {
155
+ if (!editor || !id)
156
+ return;
157
+ textEditors.set(id, editor);
158
+ return function () {
159
+ if (textEditors.get(id) === editor) {
160
+ textEditors.delete(id);
161
+ }
162
+ };
163
+ }, [editor, id]);
145
164
  return (_jsxs(_Fragment, { children: [slotBefore ? slotBefore(editor) : null, showFormattingMenu && _jsx(RichTextFormattingMenu, { editor: editor }), _jsx(EditorContent, __assign({ editor: editor }, props))] }));
146
165
  };
@@ -0,0 +1,25 @@
1
+ import { Extension } from "@tiptap/core";
2
+ type CollaborationCaretStorage = {
3
+ users: {
4
+ clientId: number;
5
+ [key: string]: any;
6
+ }[];
7
+ updateHandler: (() => void) | null;
8
+ };
9
+ export interface CollaborationCaretOptions {
10
+ /**
11
+ * The awareness provider
12
+ */
13
+ awareness: any;
14
+ }
15
+ declare module "@tiptap/core" {
16
+ interface Storage {
17
+ collaborationCaret: CollaborationCaretStorage;
18
+ }
19
+ }
20
+ /**
21
+ * This extension allows you to add collaboration carets to your editor.
22
+ * @see https://tiptap.dev/api/extensions/collaboration-caret
23
+ */
24
+ export declare const CollaborationCaret: Extension<CollaborationCaretOptions, CollaborationCaretStorage>;
25
+ export {};
@@ -0,0 +1,81 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { Extension } from "@tiptap/core";
13
+ import { defaultSelectionBuilder, yCursorPlugin } from "@tiptap/y-tiptap";
14
+ var awarenessStatesToArray = function (states) {
15
+ return Array.from(states.entries()).map(function (_a) {
16
+ var key = _a[0], value = _a[1];
17
+ return __assign({ clientId: key }, value.user);
18
+ });
19
+ };
20
+ var getSafeColor = function (color) {
21
+ return typeof color === "string" ? color : "";
22
+ };
23
+ var renderCursor = function (user) {
24
+ var cursor = document.createElement("span");
25
+ var color = getSafeColor(user.color);
26
+ cursor.classList.add("collaboration-carets__caret");
27
+ cursor.style.borderColor = color;
28
+ var label = document.createElement("div");
29
+ label.classList.add("collaboration-carets__label");
30
+ label.style.backgroundColor = color;
31
+ label.insertBefore(document.createTextNode(user.name), null);
32
+ cursor.insertBefore(label, null);
33
+ return cursor;
34
+ };
35
+ /**
36
+ * This extension allows you to add collaboration carets to your editor.
37
+ * @see https://tiptap.dev/api/extensions/collaboration-caret
38
+ */
39
+ export var CollaborationCaret = Extension.create({
40
+ name: "collaborationCaret",
41
+ priority: 999,
42
+ addOptions: function () {
43
+ return {
44
+ awareness: null,
45
+ };
46
+ },
47
+ onCreate: function () {
48
+ if (!this.options.awareness) {
49
+ throw new Error('The "awareness" option is required for the CollaborationCaret extension');
50
+ }
51
+ },
52
+ addStorage: function () {
53
+ return {
54
+ users: [],
55
+ updateHandler: null,
56
+ };
57
+ },
58
+ onDestroy: function () {
59
+ if (this.options.awareness && this.storage.updateHandler) {
60
+ this.options.awareness.off("update", this.storage.updateHandler);
61
+ this.storage.updateHandler = null;
62
+ }
63
+ },
64
+ addProseMirrorPlugins: function () {
65
+ var _this = this;
66
+ return [
67
+ yCursorPlugin((function () {
68
+ _this.storage.users = awarenessStatesToArray(_this.options.awareness.states);
69
+ var updateHandler = function () {
70
+ _this.storage.users = awarenessStatesToArray(_this.options.awareness.states);
71
+ };
72
+ _this.storage.updateHandler = updateHandler;
73
+ _this.options.awareness.on("update", updateHandler);
74
+ return _this.options.awareness;
75
+ })(), {
76
+ cursorBuilder: renderCursor,
77
+ selectionBuilder: defaultSelectionBuilder,
78
+ }),
79
+ ];
80
+ },
81
+ });
@@ -0,0 +1,3 @@
1
+ import { Mark } from "@tiptap/core";
2
+ declare const ContentReference: Mark<any, any>;
3
+ export default ContentReference;
@@ -0,0 +1,25 @@
1
+ import { Mark, mergeAttributes } from "@tiptap/core";
2
+ var ContentReference = Mark.create({
3
+ name: "content-reference",
4
+ addAttributes: function () {
5
+ return {
6
+ quote: {
7
+ default: null,
8
+ parseHTML: function (element) { return element.getAttribute("quote"); },
9
+ renderHTML: function (attributes) {
10
+ if (!attributes.quote)
11
+ return {};
12
+ return { quote: attributes.quote };
13
+ },
14
+ },
15
+ };
16
+ },
17
+ parseHTML: function () {
18
+ return [{ tag: "content-reference" }];
19
+ },
20
+ renderHTML: function (_a) {
21
+ var HTMLAttributes = _a.HTMLAttributes;
22
+ return ["content-reference", mergeAttributes(HTMLAttributes), 0];
23
+ },
24
+ });
25
+ export default ContentReference;
@@ -0,0 +1,2 @@
1
+ export declare const defaultRichTextExtensions: (import("@tiptap/core").Mark<any, any> | import("@tiptap/core").Node<any, any> | import("@tiptap/core").Extension<import("@tiptap/starter-kit").StarterKitOptions, any> | import("@tiptap/core").Extension<import("@tiptap/extension-typography").TypographyOptions, any> | import("@tiptap/core").Extension<import("@tiptap/extension-table").TableKitOptions, any>)[];
2
+ export declare const htmlRenderingRichTextExtensions: (import("@tiptap/core").Mark<any, any> | import("@tiptap/core").Node<any, any> | import("@tiptap/core").Extension<import("@tiptap/starter-kit").StarterKitOptions, any> | import("@tiptap/core").Extension<import("@tiptap/extension-typography").TypographyOptions, any> | import("@tiptap/core").Extension<import("@tiptap/extension-table").TableKitOptions, any>)[];
@@ -0,0 +1,43 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import Document from "@tiptap/extension-document";
11
+ import Highlight from "@tiptap/extension-highlight";
12
+ import Image from "@tiptap/extension-image";
13
+ import Link from "@tiptap/extension-link";
14
+ import { TableKit } from "@tiptap/extension-table";
15
+ import Typography from "@tiptap/extension-typography";
16
+ import StarterKit from "@tiptap/starter-kit";
17
+ import ContentReference from "./content-reference.js";
18
+ import FileAttachment from "./file-attachment.js";
19
+ import { Mathematics } from "./mathematics.js";
20
+ import PageClipping from "./page-clipping.js";
21
+ export var defaultRichTextExtensions = [
22
+ StarterKit.configure({
23
+ document: false,
24
+ link: false,
25
+ undoRedo: false,
26
+ }),
27
+ Link.configure({
28
+ openOnClick: false,
29
+ }),
30
+ Typography,
31
+ FileAttachment,
32
+ PageClipping,
33
+ ContentReference,
34
+ Mathematics,
35
+ Highlight,
36
+ TableKit.configure({
37
+ table: { resizable: true },
38
+ }),
39
+ ];
40
+ export var htmlRenderingRichTextExtensions = __spreadArray([
41
+ Document,
42
+ Image
43
+ ], defaultRichTextExtensions, true);
@@ -1,7 +1,5 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
1
  import { mergeAttributes, Node } from "@tiptap/core";
3
- import { createRoot } from "react-dom/client";
4
- import { FileAttachmentView } from "../../web-components/file-attachment";
2
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
5
3
  export default Node.create({
6
4
  name: "file-attachment",
7
5
  group: "block",
@@ -25,16 +23,42 @@ export default Node.create({
25
23
  var HTMLAttributes = _a.HTMLAttributes;
26
24
  return ["file-attachment", mergeAttributes(HTMLAttributes)];
27
25
  },
28
- addNodeView: function () {
29
- return function (_a) {
30
- var node = _a.node;
31
- var dom = document.createElement("div");
32
- dom.classList.add("file-attachment");
33
- var root = createRoot(dom);
34
- root.render(_jsx(FileAttachmentView, { title: node.attrs.title, type: node.attrs.type, href: node.attrs.href, className: "pointer-events-none" }));
35
- return {
36
- dom: dom,
37
- };
38
- };
26
+ addProseMirrorPlugins: function () {
27
+ var _this = this;
28
+ // Similar to the TipTap Link extension, we disable clicking on these
29
+ // links in the editor, since that is annoying. We don't want to change
30
+ // the HTML tag though!
31
+ return [
32
+ new Plugin({
33
+ key: new PluginKey("handleClickFileAttachment"),
34
+ props: {
35
+ handleClick: function (view, pos, event) {
36
+ if (event.button !== 0) {
37
+ return false;
38
+ }
39
+ if (!view.editable) {
40
+ return false;
41
+ }
42
+ var link = null;
43
+ var target = event.target;
44
+ if (!target) {
45
+ return false;
46
+ }
47
+ var root = _this.editor.view.dom;
48
+ link = target.closest("file-attachment");
49
+ if (link && !root.contains(link)) {
50
+ link = null;
51
+ }
52
+ if (!link) {
53
+ return false;
54
+ }
55
+ if (target !== link) {
56
+ _this.editor.commands.selectParentNode();
57
+ }
58
+ return true;
59
+ },
60
+ },
61
+ }),
62
+ ];
39
63
  },
40
64
  });
@@ -20,25 +20,6 @@ export interface ImageOptions {
20
20
  */
21
21
  HTMLAttributes: Record<string, any>;
22
22
  }
23
- declare module "@tiptap/core" {
24
- interface Commands<ReturnType> {
25
- image: {
26
- /**
27
- * Add an image
28
- * @param options The image attributes
29
- * @example
30
- * editor
31
- * .commands
32
- * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })
33
- */
34
- setImage: (options: {
35
- src: string;
36
- alt?: string;
37
- title?: string;
38
- }) => ReturnType;
39
- };
40
- }
41
- }
42
23
  /**
43
24
  * Matches an image to a ![image](src "title") on input.
44
25
  */
@@ -3,8 +3,8 @@ import { useMemo, useState } from "react";
3
3
  import { NodeViewWrapper } from "@tiptap/react";
4
4
  import { EditIcon } from "lucide-react";
5
5
  import { convertLatexToMathMl } from "mathlive";
6
- import { cn } from "../../../utils";
7
- import { Popover, PopoverTrigger, PopoverContent } from "../../ui/popover";
6
+ import { cn } from "../../../utils.js";
7
+ import { Popover, PopoverTrigger, PopoverContent } from "../../ui/popover.js";
8
8
  import "mathlive";
9
9
  export var MathematicsEditComponent = function (_a) {
10
10
  var node = _a.node, editor = _a.editor;
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { InputRule, Node } from "@tiptap/core";
13
13
  import { ReactNodeViewRenderer } from "@tiptap/react";
14
- import { MathematicsEditComponent } from "./mathematics-component";
14
+ import { MathematicsEditComponent } from "./mathematics-component.js";
15
15
  /**
16
16
  * InlineMath is a Tiptap extension for rendering inline mathematical expressions using LaTeX and MathML.
17
17
  * It allows users to insert LaTeX formatted math expressions inline within text.
@@ -1,18 +1,4 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
1
  import { mergeAttributes, Node } from "@tiptap/core";
14
- import { createRoot } from "react-dom/client";
15
- import { PageClippingView } from "../../web-components/page-clipping";
16
2
  export default Node.create({
17
3
  name: "page-clipping",
18
4
  group: "block",
@@ -39,16 +25,4 @@ export default Node.create({
39
25
  var HTMLAttributes = _a.HTMLAttributes;
40
26
  return ["page-clipping", mergeAttributes(HTMLAttributes)];
41
27
  },
42
- addNodeView: function () {
43
- return function (_a) {
44
- var node = _a.node;
45
- var dom = document.createElement("div");
46
- dom.classList.add("page-clipping");
47
- var root = createRoot(dom);
48
- root.render(_jsx(PageClippingView, __assign({}, node.attrs)));
49
- return {
50
- dom: dom,
51
- };
52
- };
53
- },
54
28
  });
@@ -3,7 +3,7 @@ import { useCallback, useState } from "react";
3
3
  import { Trans } from "react-i18next";
4
4
  import { useEditorState } from "@tiptap/react";
5
5
  import { BubbleMenu } from "@tiptap/react/menus";
6
- import { BoldIcon, CropIcon, HighlighterIcon, ItalicIcon, LinkIcon, ListIcon, SquareFunctionIcon, TextQuoteIcon, } from "lucide-react";
6
+ import { BoldIcon, CropIcon, HighlighterIcon, ItalicIcon, LinkIcon, ListIcon, SquareFunctionIcon, TextQuoteIcon, TrashIcon, } from "lucide-react";
7
7
  import { CropPageClippingModal } from "./crop-page-clipping-modal";
8
8
  import { cn } from "../../../utils";
9
9
  export var RichTextFormattingMenu = function (_a) {
@@ -47,35 +47,43 @@ export var RichTextFormattingMenu = function (_a) {
47
47
  isBlockquote: ctx.editor.isActive("blockquote"),
48
48
  isInlineMath: ctx.editor.isActive("inlineMath"),
49
49
  isPageClipping: ctx.editor.isActive("page-clipping"),
50
+ isFileAttachment: ctx.editor.isActive("file-attachment"),
51
+ isImage: ctx.editor.isActive("image"),
50
52
  }); },
51
53
  });
52
54
  if (!editor) {
53
55
  return null;
54
56
  }
55
- return (_jsxs(_Fragment, { children: [_jsx(CropPageClippingModal, { pageClipping: pageClipping, onClose: function () { return setPageClipping(null); }, onUpdate: function (newParameters) {
56
- setPageClipping(null);
57
- editor
58
- .chain()
59
- .focus()
60
- .updateAttributes("page-clipping", newParameters)
61
- .run();
62
- } }), _jsx(BubbleMenu, { editor: editor, children: _jsx("div", { className: "border p-0.5 gap-0.5 bg-white rounded-md flex items-center shadow-md text-xs font-medium select-none", children: state.isPageClipping ? (_jsxs("span", { onClick: function () {
63
- return setPageClipping(editor.getAttributes("page-clipping"));
64
- }, className: "p-1 cursor-pointer flex items-center gap-1 pr-2 hover:bg-zinc-100 rounded-base", children: [_jsx(CropIcon, { className: "size-3.5 m-0.5" }), _jsx(Trans, { children: "formatting.crop.crop" })] })) : (_jsxs(_Fragment, { children: [_jsx("span", { onClick: function () {
65
- return editor.chain().focus().toggleBold().run();
66
- }, className: cn("p-1 cursor-pointer", state.isBold ? "bg-zinc-200 rounded-base" : ""), children: _jsx(BoldIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isBold ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
67
- return editor.chain().focus().toggleItalic().run();
68
- }, className: cn("p-1 cursor-pointer", state.isItalic ? "bg-zinc-200 rounded-base" : ""), children: _jsx(ItalicIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isItalic ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
69
- return editor.chain().focus().toggleHighlight().run();
70
- }, className: cn("p-1 cursor-pointer", state.isHighlight ? "bg-zinc-200 rounded-base" : ""), children: _jsx(HighlighterIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isHighlight ? 2.75 : 2 }) }), _jsx("span", { onClick: setLink, className: cn("p-1 cursor-pointer", state.isLink ? "bg-zinc-200 rounded-base" : ""), children: _jsx(LinkIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isLink ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
71
- return editor.chain().focus().toggleBulletList().run();
72
- }, className: cn("p-1 cursor-pointer", state.isBulletList ? "bg-zinc-200 rounded-base" : ""), children: _jsx(ListIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isBulletList ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
73
- return editor.chain().focus().toggleOrderedList().run();
74
- }, className: cn("p-1 cursor-pointer", state.isOrderedList ? "bg-zinc-200 rounded-base" : ""), children: _jsx(ListIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isOrderedList ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
75
- return editor.chain().focus().toggleBlockquote().run();
76
- }, className: cn("p-1 cursor-pointer", state.isBlockquote ? "bg-zinc-200 rounded-base" : ""), children: _jsx(TextQuoteIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isBlockquote ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
77
- return editor.chain().focus()
78
- .insertInlineMath({ latex: "" })
79
- .run();
80
- }, className: cn("p-1 cursor-pointer", state.isInlineMath ? "bg-zinc-200 rounded-base" : ""), children: _jsx(SquareFunctionIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isInlineMath ? 2.75 : 2 }) })] })) }) })] }));
57
+ if (state.isPageClipping) {
58
+ return (_jsxs(_Fragment, { children: [_jsx(CropPageClippingModal, { pageClipping: pageClipping, onClose: function () { return setPageClipping(null); }, onUpdate: function (newParameters) {
59
+ setPageClipping(null);
60
+ editor
61
+ .chain()
62
+ .focus()
63
+ .updateAttributes("page-clipping", newParameters)
64
+ .run();
65
+ } }), _jsx(BubbleMenu, { editor: editor, children: _jsx("div", { className: "border p-0.5 gap-0.5 bg-white rounded-md flex items-center shadow-md text-xs font-medium select-none", children: _jsxs("span", { onClick: function () {
66
+ return setPageClipping(editor.getAttributes("page-clipping"));
67
+ }, className: "p-1 cursor-pointer flex items-center gap-1 pr-2 hover:bg-zinc-100 rounded-base", children: [_jsx(CropIcon, { className: "size-3.5 m-0.5" }), _jsx(Trans, { children: "formatting.crop.crop" })] }) }) })] }));
68
+ }
69
+ if (state.isImage || state.isFileAttachment) {
70
+ return (_jsx(BubbleMenu, { editor: editor, children: _jsx("div", { className: "border p-0.5 gap-0.5 bg-white rounded-md flex items-center shadow-md text-xs font-medium select-none", children: _jsxs("span", { onClick: function () { return editor.commands.deleteSelection(); }, className: "p-1 cursor-pointer flex items-center gap-1 pr-2 hover:bg-zinc-100 rounded-base", children: [_jsx(TrashIcon, { className: "size-3.5 m-0.5" }), _jsx(Trans, { children: "formatting.delete" })] }) }) }));
71
+ }
72
+ return (_jsx(BubbleMenu, { editor: editor, children: _jsxs("div", { className: "border p-0.5 gap-0.5 bg-white rounded-md flex items-center shadow-md text-xs font-medium select-none", children: [_jsx("span", { onClick: function () {
73
+ return editor.chain().focus().toggleBold().run();
74
+ }, className: cn("p-1 cursor-pointer", state.isBold ? "bg-zinc-200 rounded-base" : ""), children: _jsx(BoldIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isBold ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
75
+ return editor.chain().focus().toggleItalic().run();
76
+ }, className: cn("p-1 cursor-pointer", state.isItalic ? "bg-zinc-200 rounded-base" : ""), children: _jsx(ItalicIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isItalic ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
77
+ return editor.chain().focus().toggleHighlight().run();
78
+ }, className: cn("p-1 cursor-pointer", state.isHighlight ? "bg-zinc-200 rounded-base" : ""), children: _jsx(HighlighterIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isHighlight ? 2.75 : 2 }) }), _jsx("span", { onClick: setLink, className: cn("p-1 cursor-pointer", state.isLink ? "bg-zinc-200 rounded-base" : ""), children: _jsx(LinkIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isLink ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
79
+ return editor.chain().focus().toggleBulletList().run();
80
+ }, className: cn("p-1 cursor-pointer", state.isBulletList ? "bg-zinc-200 rounded-base" : ""), children: _jsx(ListIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isBulletList ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
81
+ return editor.chain().focus().toggleOrderedList().run();
82
+ }, className: cn("p-1 cursor-pointer", state.isOrderedList ? "bg-zinc-200 rounded-base" : ""), children: _jsx(ListIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isOrderedList ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
83
+ return editor.chain().focus().toggleBlockquote().run();
84
+ }, className: cn("p-1 cursor-pointer", state.isBlockquote ? "bg-zinc-200 rounded-base" : ""), children: _jsx(TextQuoteIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isBlockquote ? 2.75 : 2 }) }), _jsx("span", { onClick: function () {
85
+ return editor.chain().focus()
86
+ .insertInlineMath({ latex: "" })
87
+ .run();
88
+ }, className: cn("p-1 cursor-pointer", state.isInlineMath ? "bg-zinc-200 rounded-base" : ""), children: _jsx(SquareFunctionIcon, { className: "size-3.5 m-0.5", strokeWidth: state.isInlineMath ? 2.75 : 2 }) })] }) }));
81
89
  };
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const badgeVariants: (props?: {
4
- variant?: "default" | "secondary" | "blue" | "bright" | "positive" | "orange";
4
+ variant?: "default" | "secondary" | "destructive" | "blue" | "bright" | "positive" | "orange";
5
5
  } & import("class-variance-authority/types").ClassProp) => string;
6
6
  export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement>, VariantProps<typeof badgeVariants> {
7
7
  asChild?: boolean;
@@ -34,6 +34,7 @@ var badgeVariants = cva("font-semibold text-xs rounded-4xl py-0.5 px-2 whitespac
34
34
  positive: "bg-emerald-100 text-emerald-600",
35
35
  orange: "bg-orange-100 text-orange-800/75",
36
36
  secondary: "bg-zinc-200 text-zinc-600",
37
+ destructive: "bg-red-100 text-red-700",
37
38
  },
38
39
  },
39
40
  defaultVariants: {