@elia-ori/editor 0.1.18 → 0.1.19

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");
@@ -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 = {