@examplary/ui 0.0.1 → 1.1.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/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://developers.examplary.ai/question-types).
@@ -1,5 +1,5 @@
1
1
  export { RichTextDisplay } from "./rich-text-display";
2
- export { RichTextInput } from "./rich-text-input";
2
+ export { RichTextField } from "./rich-text-field";
3
3
  export { RichTextToolbar } from "./rich-text-toolbar";
4
4
  export { MinimalRichTextField } from "./minimal-rich-text-field";
5
5
  export { processFilesAsString } from "./tiptap/file-handler";
@@ -1,5 +1,5 @@
1
1
  export { RichTextDisplay } from "./rich-text-display";
2
- export { RichTextInput } from "./rich-text-input";
2
+ export { RichTextField } from "./rich-text-field";
3
3
  export { RichTextToolbar } from "./rich-text-toolbar";
4
4
  export { MinimalRichTextField } from "./minimal-rich-text-field";
5
5
  export { processFilesAsString } from "./tiptap/file-handler";
@@ -1,7 +1,6 @@
1
1
  import { EditorContentProps } from "@tiptap/react";
2
2
  export type MinimalRichTextFieldProps = {
3
3
  className?: string;
4
- editorClassName?: string;
5
4
  value?: string;
6
5
  placeholder?: string;
7
6
  onChange?: (value: string) => void;
@@ -14,4 +13,4 @@ export type MinimalRichTextFieldProps = {
14
13
  name: string;
15
14
  }>;
16
15
  } & Omit<EditorContentProps, "editor">;
17
- export declare const MinimalRichTextField: ({ className, editorClassName, value, placeholder, onChange, slotBefore, singleLine, autoFocus, showFormattingMenu, uploadFile, ...props }: MinimalRichTextFieldProps) => import("react/jsx-runtime").JSX.Element;
16
+ export declare const MinimalRichTextField: ({ className, value, placeholder, onChange, slotBefore, singleLine, autoFocus, showFormattingMenu, uploadFile, ...props }: MinimalRichTextFieldProps) => import("react/jsx-runtime").JSX.Element;
@@ -20,6 +20,15 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  }
21
21
  return t;
22
22
  };
23
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
24
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
25
+ if (ar || !(i in from)) {
26
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
27
+ ar[i] = from[i];
28
+ }
29
+ }
30
+ return to.concat(ar || Array.prototype.slice.call(from));
31
+ };
23
32
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
24
33
  import { useEffect, useMemo, useState } from "react";
25
34
  import Document from "@tiptap/extension-document";
@@ -39,19 +48,37 @@ import Image from "./tiptap/image";
39
48
  import PageClipping from "./tiptap/page-clipping";
40
49
  import { RichTextFormattingMenu } from "./tiptap/rich-text-formatting-menu";
41
50
  registerWebComponents();
51
+ var isEmpty = function (value) {
52
+ var _a;
53
+ if (!value) {
54
+ return true;
55
+ }
56
+ if (!((_a = value.trim) === null || _a === void 0 ? void 0 : _a.call(value))) {
57
+ return true;
58
+ }
59
+ if (value.trim() === "<p></p>" || value.trim() === "<p><br></p>") {
60
+ return true;
61
+ }
62
+ if (value.trim() === "<p> </p>" || value.trim() === "<p></p><p></p>") {
63
+ return true;
64
+ }
65
+ return false;
66
+ };
42
67
  export var MinimalRichTextField = function (_a) {
43
- var _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.editorClassName, editorClassName = _c === void 0 ? "" : _c, _d = _a.value, value = _d === void 0 ? "" : _d, _e = _a.placeholder, placeholder = _e === void 0 ? "" : _e, onChange = _a.onChange, slotBefore = _a.slotBefore, _f = _a.singleLine, singleLine = _f === void 0 ? false : _f, _g = _a.autoFocus, autoFocus = _g === void 0 ? false : _g, _h = _a.showFormattingMenu, showFormattingMenu = _h === void 0 ? false : _h, _j = _a.uploadFile, uploadFile = _j === void 0 ? undefined : _j, props = __rest(_a, ["className", "editorClassName", "value", "placeholder", "onChange", "slotBefore", "singleLine", "autoFocus", "showFormattingMenu", "uploadFile"]);
44
- var _k = useState(value), content = _k[0], setContent = _k[1];
68
+ var _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.value, value = _c === void 0 ? "" : _c, _d = _a.placeholder, placeholder = _d === void 0 ? "" : _d, onChange = _a.onChange, slotBefore = _a.slotBefore, _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", "placeholder", "onChange", "slotBefore", "singleLine", "autoFocus", "showFormattingMenu", "uploadFile"]);
69
+ var _j = useState(value), content = _j[0], setContent = _j[1];
45
70
  var extensions = useMemo(function () {
46
- return [
47
- StarterKit.configure({
48
- document: singleLine ? false : undefined,
49
- link: false,
50
- }),
51
- singleLine &&
71
+ return __spreadArray(__spreadArray([], (singleLine
72
+ ? [
73
+ StarterKit.configure({
74
+ document: false,
75
+ link: false,
76
+ }),
52
77
  Document.extend({
53
78
  content: "block",
54
79
  }),
80
+ ]
81
+ : [StarterKit.configure({ link: false })]), true), [
55
82
  Link.configure({
56
83
  openOnClick: false,
57
84
  }),
@@ -63,12 +90,13 @@ export var MinimalRichTextField = function (_a) {
63
90
  // Mathematics,
64
91
  Highlight,
65
92
  uploadFile && fileHandler(uploadFile),
66
- ].filter(Boolean);
93
+ ], false).filter(Boolean);
67
94
  }, [singleLine, placeholder, uploadFile]);
68
95
  var editor = useEditor({
69
96
  onUpdate: function (_a) {
70
97
  var editor = _a.editor;
71
98
  var html = editor.getHTML();
99
+ html = isEmpty(html) ? "" : html;
72
100
  setContent(html);
73
101
  onChange === null || onChange === void 0 ? void 0 : onChange(html);
74
102
  },
@@ -80,7 +108,7 @@ export var MinimalRichTextField = function (_a) {
80
108
  extensions: extensions,
81
109
  editorProps: {
82
110
  attributes: {
83
- class: editorClassName || "",
111
+ class: cn("max-w-none", className),
84
112
  },
85
113
  },
86
114
  });
@@ -95,5 +123,5 @@ export var MinimalRichTextField = function (_a) {
95
123
  });
96
124
  }
97
125
  }, [value, content, editor]);
98
- return (_jsxs(_Fragment, { children: [slotBefore ? slotBefore(editor) : null, showFormattingMenu && _jsx(RichTextFormattingMenu, { editor: editor }), _jsx("div", { className: cn("max-w-none", className), children: _jsx(EditorContent, __assign({ editor: editor }, props)) })] }));
126
+ return (_jsxs(_Fragment, { children: [slotBefore ? slotBefore(editor) : null, showFormattingMenu && _jsx(RichTextFormattingMenu, { editor: editor }), _jsx(EditorContent, __assign({ editor: editor }, props))] }));
99
127
  };
@@ -0,0 +1,2 @@
1
+ import { MinimalRichTextFieldProps } from "./minimal-rich-text-field";
2
+ export declare const RichTextField: ({ singleLine, className, ...props }: MinimalRichTextFieldProps) => import("react/jsx-runtime").JSX.Element;
@@ -21,11 +21,9 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
- import * as React from "react";
25
- import { cn } from "../utils";
26
- var Input = React.forwardRef(function (_a, ref) {
27
- var className = _a.className, type = _a.type, props = __rest(_a, ["className", "type"]);
28
- return (_jsx("input", __assign({ type: type, className: cn("flex h-10 w-full rounded-base border-2 text-text dark:text-darkText font-base selection:bg-main selection:text-text border-border dark:border-darkBorder bg-white dark:bg-secondaryBlack px-3 py-2 text-sm ring-offset-white file:border-0 file:bg-transparent file:text-sm file:font-base focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", className), ref: ref }, props)));
29
- });
30
- Input.displayName = "Input";
31
- export { Input };
24
+ import { MinimalRichTextField, } from "./minimal-rich-text-field";
25
+ import { cn } from "../../utils";
26
+ export var RichTextField = function (_a) {
27
+ var singleLine = _a.singleLine, className = _a.className, props = __rest(_a, ["singleLine", "className"]);
28
+ return (_jsx(MinimalRichTextField, __assign({ singleLine: singleLine, className: cn("box p-3 text-sm", !singleLine && "min-h-16", className) }, props)));
29
+ };
@@ -1,4 +1,4 @@
1
1
  import { Editor } from "@tiptap/react";
2
2
  export declare const processFilesAsString: (uploadFile: any, files: any) => Promise<unknown>;
3
3
  export declare const processFiles: (uploadFile: any, currentEditor: Editor, files: any, pos: any) => void;
4
- export declare const fileHandler: (uploadFile: any) => import("@tiptap/core").Extension<Omit<import("@tiptap-pro/extension-file-handler").FileHandlePluginOptions, "key" | "editor">, any>;
4
+ export declare const fileHandler: (uploadFile: any) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "key" | "editor">, any>;
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import toast from "react-hot-toast";
38
- import FileHandler from "@tiptap-pro/extension-file-handler";
38
+ import FileHandler from "@tiptap/extension-file-handler";
39
39
  import { getImageSize } from "../tiptap/png-scanner";
40
40
  export var processFilesAsString = function (uploadFile, files) {
41
41
  return new Promise(function (resolve) {
@@ -178,6 +178,8 @@ export var fileHandler = function (uploadFile) {
178
178
  "application/pdf",
179
179
  "text/html",
180
180
  "text/plain",
181
+ "application/msword",
182
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
181
183
  ],
182
184
  onDrop: function (currentEditor, files, pos) {
183
185
  processFiles(uploadFile, currentEditor, files, pos);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  export * from "./utils";
2
- export { Button } from "./components/button";
3
- export { Input } from "./components/input";
4
2
  export * from "./components/rich-text";
5
3
  export * as WebComponents from "./components/web-components";
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
1
  export * from "./utils";
2
- export { Button } from "./components/button";
3
- export { Input } from "./components/input";
4
2
  export * from "./components/rich-text";
5
3
  export * as WebComponents from "./components/web-components";
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@examplary/ui",
3
3
  "description": "UI components for the Examplary testing platform.",
4
4
  "packageManager": "yarn@4.5.3",
5
- "version": "0.0.1",
5
+ "version": "1.1.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "files": [
@@ -17,9 +17,8 @@
17
17
  "@floating-ui/dom": "^1.7.2",
18
18
  "@tailwindcss/forms": "^0.5.10",
19
19
  "@tailwindcss/typography": "^0.5.16",
20
- "@tiptap-pro/extension-file-handler": "^2.21.5",
21
- "@tiptap-pro/extension-mathematics": "^2.18.0",
22
20
  "@tiptap/core": "^3.0.7",
21
+ "@tiptap/extension-file-handler": "^3.0.7",
23
22
  "@tiptap/extension-highlight": "^3.0.7",
24
23
  "@tiptap/extension-link": "^3.0.7",
25
24
  "@tiptap/extension-mathematics": "^3.0.7",
@@ -36,5 +35,10 @@
36
35
  },
37
36
  "devDependencies": {
38
37
  "typescript": "^5.8.3"
38
+ },
39
+ "homepage": "https://developers.examplary.ai",
40
+ "author": {
41
+ "name": "Examplary AI",
42
+ "email": "hi@examplary.ai"
39
43
  }
40
44
  }
@@ -1,11 +0,0 @@
1
- import * as React from "react";
2
- import { type VariantProps } from "class-variance-authority";
3
- declare const buttonVariants: (props?: {
4
- variant?: "default" | "transparent" | "primary" | "noShadow" | "neutral" | "simple" | "pressed" | "reverse";
5
- size?: "default" | "sm" | "lg" | "icon";
6
- } & import("class-variance-authority/types").ClassProp) => string;
7
- export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
8
- asChild?: boolean;
9
- }
10
- declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
11
- export { Button, buttonVariants };
@@ -1,58 +0,0 @@
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
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
- import { jsx as _jsx } from "react/jsx-runtime";
24
- import * as React from "react";
25
- import { Slot } from "@radix-ui/react-slot";
26
- import { cva } from "class-variance-authority";
27
- import { cn } from "../utils";
28
- var buttonVariants = cva("inline-flex font-medium cursor-pointer items-center text-text justify-center whitespace-nowrap rounded-base text-sm font-base ring-offset-white transition-all gap-2 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", {
29
- variants: {
30
- variant: {
31
- default: "bg-white border-2 border-border dark:border-darkBorder shadow-light dark:shadow-dark hover:translate-x-boxShadowX hover:translate-y-boxShadowY hover:shadow-none dark:hover:shadow-none",
32
- transparent: "border-2 border-border dark:border-darkBorder shadow-light dark:shadow-dark hover:translate-x-boxShadowX hover:translate-y-boxShadowY hover:shadow-none dark:hover:shadow-none",
33
- primary: "bg-bright border-2 border-border dark:border-darkBorder shadow-light dark:shadow-dark hover:translate-x-boxShadowX hover:translate-y-boxShadowY hover:shadow-none dark:hover:shadow-none",
34
- noShadow: "bg-white border-2 border-border dark:border-darkBorder",
35
- neutral: "bg-white dark:bg-secondaryBlack dark:text-darkText border-2 border-border dark:border-darkBorder shadow-light dark:shadow-dark hover:translate-x-boxShadowX hover:translate-y-boxShadowY hover:shadow-none dark:hover:shadow-none",
36
- simple: "bg-white border-2 border-border dark:border-darkBorder",
37
- pressed: "bg-white border-2 border-border mt-1 ml-1",
38
- reverse: "bg-white border-2 border-border dark:border-darkBorder hover:translate-x-reverseBoxShadowX hover:translate-y-reverseBoxShadowY hover:shadow-light dark:hover:shadow-dark",
39
- },
40
- size: {
41
- default: "h-10 px-4 py-2",
42
- sm: "h-9 px-3",
43
- lg: "h-11 px-8",
44
- icon: "h-10 w-10",
45
- },
46
- },
47
- defaultVariants: {
48
- variant: "default",
49
- size: "default",
50
- },
51
- });
52
- var Button = React.forwardRef(function (_a, ref) {
53
- var className = _a.className, variant = _a.variant, size = _a.size, _b = _a.asChild, asChild = _b === void 0 ? false : _b, props = __rest(_a, ["className", "variant", "size", "asChild"]);
54
- var Comp = asChild ? Slot : "button";
55
- return (_jsx(Comp, __assign({ className: cn(buttonVariants({ variant: variant, size: size, className: className })), ref: ref }, props)));
56
- });
57
- Button.displayName = "Button";
58
- export { Button, buttonVariants };
@@ -1,4 +0,0 @@
1
- import * as React from "react";
2
- export type InputProps = React.InputHTMLAttributes<HTMLInputElement>;
3
- declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
4
- export { Input };
@@ -1,14 +0,0 @@
1
- import { MinimalRichTextFieldProps } from "./minimal-rich-text-field";
2
- export type RichTextInputProps = {
3
- name: string;
4
- defaultValue?: string;
5
- className?: string;
6
- disabled?: boolean;
7
- } & MinimalRichTextFieldProps;
8
- export declare const RichTextInput: ({ name, defaultValue, className, disabled, ...props }: {
9
- [x: string]: any;
10
- name: any;
11
- defaultValue: any;
12
- className?: string;
13
- disabled?: boolean;
14
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,31 +0,0 @@
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
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
24
- import { useState } from "react";
25
- import { MinimalRichTextField, } from "./minimal-rich-text-field";
26
- import { cn } from "../../utils";
27
- export var RichTextInput = function (_a) {
28
- var name = _a.name, defaultValue = _a.defaultValue, _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, props = __rest(_a, ["name", "defaultValue", "className", "disabled"]);
29
- var _d = useState(defaultValue), value = _d[0], setValue = _d[1];
30
- return (_jsxs(_Fragment, { children: [_jsx("input", { type: "hidden", name: name, value: value }), _jsx(MinimalRichTextField, __assign({ className: cn("rounded-base border-2 text-sm font-base bg-white", "ring-offset-white focus-within:outline-none focus-within:ring-2 focus-within:ring-black focus-within:ring-offset-2", disabled && "opacity-50 pointer-events-none", className), editorClassName: "px-3 py-2", value: value, onChange: setValue }, props))] }));
31
- };