@elia-ori/editor 0.1.18 → 0.1.20

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/dist/index.cjs CHANGED
@@ -37,8 +37,8 @@ __export(index_exports, {
37
37
  module.exports = __toCommonJS(index_exports);
38
38
 
39
39
  // src/components/tiptap-templates/simple/simple-editor.tsx
40
- var import_react85 = require("react");
41
- var import_react86 = require("@tiptap/react");
40
+ var import_react86 = require("react");
41
+ var import_react87 = require("@tiptap/react");
42
42
  var import_starter_kit = require("@tiptap/starter-kit");
43
43
  var import_extension_list = require("@tiptap/extension-list");
44
44
  var import_extension_text_align = require("@tiptap/extension-text-align");
@@ -2029,7 +2029,7 @@ var DropdownMenuSubContent = (0, import_react27.forwardRef)(({ className, portal
2029
2029
  return portal ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DropdownMenuPortal, { ...typeof portal === "object" ? portal : {}, children: content }) : content;
2030
2030
  });
2031
2031
  DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;
2032
- var DropdownMenuContent = (0, import_react27.forwardRef)(({ className, sideOffset = 4, portal = false, ...props }, ref) => {
2032
+ var DropdownMenuContent = (0, import_react27.forwardRef)(({ className, sideOffset = 4, portal = true, ...props }, ref) => {
2033
2033
  const content = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2034
2034
  DropdownMenuPrimitive.Content,
2035
2035
  {
@@ -2118,7 +2118,7 @@ var HeadingDropdownMenu = (0, import_react29.forwardRef)(
2118
2118
  editor: providedEditor,
2119
2119
  levels = [1, 2, 3, 4, 5, 6],
2120
2120
  hideWhenUnavailable = false,
2121
- portal = false,
2121
+ portal = true,
2122
2122
  onOpenChange,
2123
2123
  ...buttonProps
2124
2124
  }, ref) => {
@@ -3016,7 +3016,7 @@ function ListDropdownMenu({
3016
3016
  types = ["bulletList", "orderedList", "taskList"],
3017
3017
  hideWhenUnavailable = false,
3018
3018
  onOpenChange,
3019
- portal = false,
3019
+ portal = true,
3020
3020
  ...props
3021
3021
  }) {
3022
3022
  const { editor } = useTiptapEditor(providedEditor);
@@ -5545,7 +5545,7 @@ var CALLOUT_OPTIONS = [
5545
5545
  { type: "error", label: "\u932F\u8AA4\u63D0\u793A", className: "callout-option--error" },
5546
5546
  { type: "info", label: "\u8CC7\u8A0A\u63D0\u793A", className: "callout-option--info" }
5547
5547
  ];
5548
- function CalloutButton({ portal = false }) {
5548
+ function CalloutButton({ portal = true }) {
5549
5549
  const { editor } = useTiptapEditor();
5550
5550
  const [isOpen, setIsOpen] = React.useState(false);
5551
5551
  const [isVisible, setIsVisible] = React.useState(true);
@@ -5614,7 +5614,7 @@ var React2 = __toESM(require("react"), 1);
5614
5614
  var import_jsx_runtime60 = require("react/jsx-runtime");
5615
5615
  var GRID_SIZE = 6;
5616
5616
  var TOTAL_CELLS = GRID_SIZE * GRID_SIZE;
5617
- function TableButton({ portal = false }) {
5617
+ function TableButton({ portal = true }) {
5618
5618
  const { editor } = useTiptapEditor();
5619
5619
  const [isOpen, setIsOpen] = React2.useState(false);
5620
5620
  const [isVisible, setIsVisible] = React2.useState(true);
@@ -5754,7 +5754,7 @@ var TEXT_COLORS = [
5754
5754
  { color: "var(--tt-color-text-pink)", label: "\u7C89\u7D05", className: "text-color--pink" },
5755
5755
  { color: "var(--tt-color-text-red)", label: "\u7D05\u8272", className: "text-color--red" }
5756
5756
  ];
5757
- function TextColorButton({ portal = false }) {
5757
+ function TextColorButton({ portal = true }) {
5758
5758
  const { editor } = useTiptapEditor();
5759
5759
  const [isOpen, setIsOpen] = React3.useState(false);
5760
5760
  const [isVisible, setIsVisible] = React3.useState(true);
@@ -6061,6 +6061,35 @@ function useCursorVisibility({
6061
6061
  return rect;
6062
6062
  }
6063
6063
 
6064
+ // src/hooks/use-auto-height.ts
6065
+ var import_react85 = require("react");
6066
+ function useAutoHeight(containerRef, options) {
6067
+ const { enabled, bottomOffset = 24, minHeight = 200 } = options;
6068
+ const [height, setHeight] = (0, import_react85.useState)(void 0);
6069
+ const calculateHeight = (0, import_react85.useCallback)(() => {
6070
+ if (!enabled || !containerRef.current) {
6071
+ setHeight(void 0);
6072
+ return;
6073
+ }
6074
+ const rect = containerRef.current.getBoundingClientRect();
6075
+ const availableHeight = window.innerHeight - rect.top - bottomOffset;
6076
+ const finalHeight = Math.max(availableHeight, minHeight);
6077
+ setHeight(finalHeight);
6078
+ }, [enabled, bottomOffset, minHeight, containerRef]);
6079
+ (0, import_react85.useEffect)(() => {
6080
+ if (!enabled) {
6081
+ setHeight(void 0);
6082
+ return;
6083
+ }
6084
+ calculateHeight();
6085
+ window.addEventListener("resize", calculateHeight);
6086
+ return () => {
6087
+ window.removeEventListener("resize", calculateHeight);
6088
+ };
6089
+ }, [enabled, calculateHeight]);
6090
+ return height;
6091
+ }
6092
+
6064
6093
  // src/components/tiptap-templates/simple/simple-editor.tsx
6065
6094
  var import_jsx_runtime63 = require("react/jsx-runtime");
6066
6095
  var DEFAULT_TOOLBAR = [
@@ -6159,24 +6188,33 @@ function EliaEditor({
6159
6188
  editorClassName,
6160
6189
  autofocus = false,
6161
6190
  readOnly = false,
6162
- embedded = false
6191
+ embedded = false,
6192
+ autoHeight = false,
6193
+ bottomOffset = 24,
6194
+ minHeight = 200
6163
6195
  }) {
6164
6196
  const isMobile = useIsBreakpoint();
6165
6197
  const { height } = useWindowSize();
6166
- const [mobileView, setMobileView] = (0, import_react85.useState)(
6198
+ const [mobileView, setMobileView] = (0, import_react86.useState)(
6167
6199
  "main"
6168
6200
  );
6169
- const toolbarRef = (0, import_react85.useRef)(null);
6170
- const isInternalUpdate = (0, import_react85.useRef)(false);
6201
+ const toolbarRef = (0, import_react86.useRef)(null);
6202
+ const containerRef = (0, import_react86.useRef)(null);
6203
+ const isInternalUpdate = (0, import_react86.useRef)(false);
6204
+ const computedHeight = useAutoHeight(containerRef, {
6205
+ enabled: embedded && autoHeight,
6206
+ bottomOffset,
6207
+ minHeight
6208
+ });
6171
6209
  const uploadFn = onImageUpload || handleImageUpload;
6172
- const handleUpdate = (0, import_react85.useCallback)(
6210
+ const handleUpdate = (0, import_react86.useCallback)(
6173
6211
  ({ editor: editor2 }) => {
6174
6212
  isInternalUpdate.current = true;
6175
6213
  onChange?.(editor2.getHTML());
6176
6214
  },
6177
6215
  [onChange]
6178
6216
  );
6179
- const editor = (0, import_react86.useEditor)({
6217
+ const editor = (0, import_react87.useEditor)({
6180
6218
  immediatelyRender: false,
6181
6219
  editorProps: {
6182
6220
  attributes: {
@@ -6237,58 +6275,66 @@ function EliaEditor({
6237
6275
  editor,
6238
6276
  overlayHeight: toolbarRef.current?.getBoundingClientRect().height ?? 0
6239
6277
  });
6240
- (0, import_react85.useEffect)(() => {
6278
+ (0, import_react86.useEffect)(() => {
6241
6279
  if (!isMobile && mobileView !== "main") {
6242
6280
  setMobileView("main");
6243
6281
  }
6244
6282
  }, [isMobile, mobileView]);
6245
- (0, import_react85.useEffect)(() => {
6283
+ (0, import_react86.useEffect)(() => {
6246
6284
  if (editor && !isInternalUpdate.current && content !== editor.getHTML()) {
6247
6285
  editor.commands.setContent(content);
6248
6286
  }
6249
6287
  isInternalUpdate.current = false;
6250
6288
  }, [content, editor]);
6251
- (0, import_react85.useEffect)(() => {
6289
+ (0, import_react86.useEffect)(() => {
6252
6290
  if (editor) {
6253
6291
  editor.setEditable(!readOnly);
6254
6292
  }
6255
6293
  }, [readOnly, editor]);
6256
- return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)("div", { className: cn("simple-editor-wrapper", embedded && "simple-editor-embedded", className), children: /* @__PURE__ */ (0, import_jsx_runtime63.jsxs)(import_react86.EditorContext.Provider, { value: { editor }, children: [
6257
- /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6258
- Toolbar,
6259
- {
6260
- ref: toolbarRef,
6261
- style: {
6262
- ...isMobile && !embedded ? {
6263
- bottom: `calc(100% - ${height - rect.y}px)`
6264
- } : {}
6265
- },
6266
- children: mobileView === "main" ? /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6267
- MainToolbarContent,
6294
+ return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6295
+ "div",
6296
+ {
6297
+ ref: containerRef,
6298
+ className: cn("simple-editor-wrapper", embedded && "simple-editor-embedded", className),
6299
+ style: computedHeight ? { height: computedHeight } : void 0,
6300
+ children: /* @__PURE__ */ (0, import_jsx_runtime63.jsxs)(import_react87.EditorContext.Provider, { value: { editor }, children: [
6301
+ /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6302
+ Toolbar,
6268
6303
  {
6269
- onHighlighterClick: () => setMobileView("highlighter"),
6270
- onLinkClick: () => setMobileView("link"),
6271
- isMobile,
6272
- toolbar
6304
+ ref: toolbarRef,
6305
+ style: {
6306
+ ...isMobile && !embedded ? {
6307
+ bottom: `calc(100% - ${height - rect.y}px)`
6308
+ } : {}
6309
+ },
6310
+ children: mobileView === "main" ? /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6311
+ MainToolbarContent,
6312
+ {
6313
+ onHighlighterClick: () => setMobileView("highlighter"),
6314
+ onLinkClick: () => setMobileView("link"),
6315
+ isMobile,
6316
+ toolbar
6317
+ }
6318
+ ) : /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6319
+ MobileToolbarContent,
6320
+ {
6321
+ type: mobileView === "highlighter" ? "highlighter" : "link",
6322
+ onBack: () => setMobileView("main")
6323
+ }
6324
+ )
6273
6325
  }
6274
- ) : /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6275
- MobileToolbarContent,
6326
+ ),
6327
+ /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6328
+ import_react87.EditorContent,
6276
6329
  {
6277
- type: mobileView === "highlighter" ? "highlighter" : "link",
6278
- onBack: () => setMobileView("main")
6330
+ editor,
6331
+ role: "presentation",
6332
+ className: "simple-editor-content"
6279
6333
  }
6280
6334
  )
6281
- }
6282
- ),
6283
- /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
6284
- import_react86.EditorContent,
6285
- {
6286
- editor,
6287
- role: "presentation",
6288
- className: "simple-editor-content"
6289
- }
6290
- )
6291
- ] }) });
6335
+ ] })
6336
+ }
6337
+ );
6292
6338
  }
6293
6339
  // Annotate the CommonJS export names for ESM import in node:
6294
6340
  0 && (module.exports = {