@antscorp/antsomi-ui 1.3.7-beta.30 → 1.3.7-beta.32

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.
@@ -38,7 +38,7 @@ import { analyzeFont, defaultShouldShowBubbleMenu, getAllFullLinkGroups, handleL
38
38
  import { BubbleMenu } from './ui/BubbleMenu';
39
39
  import { LinkPopover } from './ui/LinkPopover';
40
40
  const TextEditorInternal = memo(forwardRef((props, ref) => {
41
- const { id, className, config, editable = true, initialContent = '', dataAttributes, onUpdateDebounced = 300, defaultTextStyle: defaultTextStyleProp, linkHandler: outerLinkHandler, smartTagHandler: outerSmartTagHandler, bubbleMenuProps, style, render, onUpdate, onFocus, onChangeFont, } = props;
41
+ const { id, className, config, editable = true, initialContent = '', dataAttributes, onUpdateDebounced = 300, defaultTextStyle: defaultTextStyleProp, linkHandler: outerLinkHandler, smartTagHandler: outerSmartTagHandler, bubbleMenuProps, style, render, onUpdate, onFocus, onCreate, onChangeFont, } = props;
42
42
  // Initialize bubbleMenuContainer with default value (document.body)
43
43
  // This ensures BubbleMenu receives a valid appendTo prop on first render
44
44
  const bubbleMenuContainer = useRef((() => {
@@ -189,6 +189,14 @@ const TextEditorInternal = memo(forwardRef((props, ref) => {
189
189
  if (safeParseContent !== initialContent) {
190
190
  editor.commands.setContent(safeParseContent);
191
191
  }
192
+ const text = editor.getText();
193
+ const json = editor.getJSON();
194
+ const html = editor.getHTML();
195
+ onCreate?.({
196
+ html: htmlSerializerForOutput(html),
197
+ text,
198
+ json,
199
+ });
192
200
  },
193
201
  onUpdate: ({ editor }) => {
194
202
  handleOnUpdateDebounce(editor);
@@ -293,6 +301,7 @@ const TextEditorInternal = memo(forwardRef((props, ref) => {
293
301
  })
294
302
  .run();
295
303
  },
304
+ getHTML: () => htmlSerializerForOutput(editor.getHTML()),
296
305
  eachLinkGroup: handleEachLinkGroup,
297
306
  eachSmartag: handleEachSmartag,
298
307
  setSmartTag: handleSetSmartTag,
@@ -300,7 +309,6 @@ const TextEditorInternal = memo(forwardRef((props, ref) => {
300
309
  updateSmartTagAttrs: handleUpdateSmartTagAttrs,
301
310
  blur: handleBlur,
302
311
  style: contentRef.current?.style,
303
- editor,
304
312
  }));
305
313
  if (!editor) {
306
314
  return null;
@@ -346,8 +354,8 @@ const TextEditorWithProvider = forwardRef((props, ref) => {
346
354
  get style() {
347
355
  return editorRef.current?.style;
348
356
  },
349
- get editor() {
350
- return editorRef.current?.editor ?? null;
357
+ get getHTML() {
358
+ return editorRef.current.getHTML;
351
359
  },
352
360
  get setLink() {
353
361
  return editorRef.current.setLink;
@@ -1,5 +1,5 @@
1
1
  import type React from 'react';
2
- import type { JSONContent, Editor, MarkRange } from '@tiptap/core';
2
+ import type { JSONContent, MarkRange } from '@tiptap/core';
3
3
  import { BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu';
4
4
  import type { Mark, Node } from '@tiptap/pm/model';
5
5
  import { ORDERED_LIST_STYLE_TYPE, UNORDERED_LIST_STYLE_TYPE } from './constants';
@@ -30,7 +30,7 @@ export type HandleLinkRef = {
30
30
  export type TextEditorRef = HandleSmartTagRef & HandleLinkRef & {
31
31
  blur: (perserveSelection?: boolean) => void;
32
32
  style?: CSSStyleDeclaration;
33
- readonly editor: Editor | null;
33
+ getHTML?: () => string;
34
34
  };
35
35
  export type SmartTagHandler = Partial<{
36
36
  edit: (id: string, event: React.MouseEvent) => void;
@@ -185,6 +185,11 @@ export type TextEditorProps = {
185
185
  text: string;
186
186
  json: JSONContent;
187
187
  }) => void;
188
+ onCreate?: (args: {
189
+ html: string;
190
+ text: string;
191
+ json: JSONContent;
192
+ }) => void;
188
193
  onChangeFont?: (changeInfo: {
189
194
  font: FontConfig;
190
195
  weight: number;
@@ -25,7 +25,7 @@ export const FormattingToolbar = (props) => {
25
25
  }, [config?.Toolbar]);
26
26
  // Map action names to React components
27
27
  const actionComponentMap = useMemo(() => ({
28
- fontFamily: (_jsx(FontFamilyAction, { editor: editor, fonts: config?.FontFamily?.fonts, onChange: (font, weight) => onChangeFont?.({ font, weight }), fontGroupingFn: config?.FontFamily?.fontGroupingFn, groupOrder: config?.FontFamily?.groupOrder }, "fontFamily")),
28
+ fontFamily: (_jsx(FontFamilyAction, { editor: editor, fonts: config?.FontFamily?.fonts, onChange: (font, weight) => onChangeFont?.({ font, weight }), fontGroupingFn: config?.FontFamily?.fontGroupingFn, groupOrder: config?.FontFamily?.groupOrder, defaultFontFamily: defaultTextStyle.fontFamily }, "fontFamily")),
29
29
  fontSize: (_jsx(FontSizeAction, { editor: editor, defaultFontSize: defaultTextStyle.fontSize }, "fontSize")),
30
30
  bold: _jsx(BoldAction, { editor: editor }, "bold"),
31
31
  italic: _jsx(ItalicAction, { editor: editor }, "italic"),
@@ -14,5 +14,6 @@ export interface FontFamilyActionProps {
14
14
  groupOrder?: string[] | GroupOrderFunction;
15
15
  /** Callback when font selection changes */
16
16
  onChange?: (font: FontConfig, weight: number) => void;
17
+ defaultFontFamily?: string;
17
18
  }
18
19
  export declare const FontFamilyAction: (props: FontFamilyActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -5,7 +5,7 @@ import { getPrimaryFontFamily } from '@antscorp/antsomi-ui/es/utils';
5
5
  import { useEditorState } from '@tiptap/react';
6
6
  import { useCallback, useEffect, useRef } from 'react';
7
7
  export const FontFamilyAction = (props) => {
8
- const { editor, fonts = DEFAULT_FONT_CONFIGS, onChange, fontGroupingFn, groupOrder } = props;
8
+ const { editor, fonts = DEFAULT_FONT_CONFIGS, onChange, fontGroupingFn, groupOrder, defaultFontFamily, } = props;
9
9
  const onChangeRef = useRef();
10
10
  useEffect(() => {
11
11
  onChangeRef.current = onChange;
@@ -15,7 +15,7 @@ export const FontFamilyAction = (props) => {
15
15
  selector: ({ editor: editorInstance }) => {
16
16
  const { fontWeight, fontFamily } = editorInstance.getAttributes('textStyle') || {};
17
17
  return {
18
- fontValue: getPrimaryFontFamily(fontFamily),
18
+ fontValue: getPrimaryFontFamily(fontFamily || defaultFontFamily),
19
19
  fontWeight: Number(fontWeight),
20
20
  };
21
21
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.7-beta.30",
3
+ "version": "1.3.7-beta.32",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",