@examplary/ui 1.0.0 → 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.
@@ -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;
@@ -48,9 +48,25 @@ import Image from "./tiptap/image";
48
48
  import PageClipping from "./tiptap/page-clipping";
49
49
  import { RichTextFormattingMenu } from "./tiptap/rich-text-formatting-menu";
50
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
+ };
51
67
  export var MinimalRichTextField = function (_a) {
52
- 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"]);
53
- 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];
54
70
  var extensions = useMemo(function () {
55
71
  return __spreadArray(__spreadArray([], (singleLine
56
72
  ? [
@@ -80,6 +96,7 @@ export var MinimalRichTextField = function (_a) {
80
96
  onUpdate: function (_a) {
81
97
  var editor = _a.editor;
82
98
  var html = editor.getHTML();
99
+ html = isEmpty(html) ? "" : html;
83
100
  setContent(html);
84
101
  onChange === null || onChange === void 0 ? void 0 : onChange(html);
85
102
  },
@@ -91,7 +108,7 @@ export var MinimalRichTextField = function (_a) {
91
108
  extensions: extensions,
92
109
  editorProps: {
93
110
  attributes: {
94
- class: editorClassName || "",
111
+ class: cn("max-w-none", className),
95
112
  },
96
113
  },
97
114
  });
@@ -106,5 +123,5 @@ export var MinimalRichTextField = function (_a) {
106
123
  });
107
124
  }
108
125
  }, [value, content, editor]);
109
- 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))] }));
110
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;
@@ -20,12 +20,10 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  }
21
21
  return t;
22
22
  };
23
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
24
- import { useState } from "react";
23
+ import { jsx as _jsx } from "react/jsx-runtime";
25
24
  import { MinimalRichTextField, } from "./minimal-rich-text-field";
26
25
  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))] }));
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)));
31
29
  };
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": "1.0.0",
5
+ "version": "1.1.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "files": [
@@ -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;