tiptop-editor 1.1.0 → 1.2.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.
Files changed (25) hide show
  1. package/README.md +34 -0
  2. package/dist/components/{TableSelectionMenu.d.ts → editor/TableSelectionMenu.d.ts} +1 -1
  3. package/dist/components/editor/TiptopEditor.d.ts +3 -0
  4. package/dist/components/editor/TiptopEditor.stories.d.ts +16 -0
  5. package/dist/components/{ColorButton.d.ts → menus/ColorButton.d.ts} +1 -1
  6. package/dist/components/{TextSelectionMenu.d.ts → menus/TextSelectionMenu.d.ts} +1 -1
  7. package/dist/components/{EditorButton.d.ts → ui/EditorButton.d.ts} +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/tiptop-editor.css +1 -1
  10. package/dist/tiptop-editor.es.js +4 -1
  11. package/dist/tiptop-editor.umd.js +2 -2
  12. package/dist/types.d.ts +6 -0
  13. package/package.json +7 -2
  14. package/dist/components/TiptopEditor.d.ts +0 -7
  15. /package/dist/components/{DragHandleColorList.d.ts → editor/DragHandleColorList.d.ts} +0 -0
  16. /package/dist/components/{TiptopDragHandle.d.ts → editor/TiptopDragHandle.d.ts} +0 -0
  17. /package/dist/components/{TransformIntoIcon.d.ts → editor/TransformIntoIcon.d.ts} +0 -0
  18. /package/dist/components/{ColorButtonMenu.d.ts → menus/ColorButtonMenu.d.ts} +0 -0
  19. /package/dist/components/{LinkButtonMenu.d.ts → menus/LinkButtonMenu.d.ts} +0 -0
  20. /package/dist/components/{MoreOptionsButtonMenu.d.ts → menus/MoreOptionsButtonMenu.d.ts} +0 -0
  21. /package/dist/components/{TableButtonMenu.d.ts → menus/TableButtonMenu.d.ts} +0 -0
  22. /package/dist/components/{TransformIntoButtonMenu.d.ts → menus/TransformIntoButtonMenu.d.ts} +0 -0
  23. /package/dist/components/{CloseIcon.d.ts → ui/CloseIcon.d.ts} +0 -0
  24. /package/dist/components/{ColorIcon.d.ts → ui/ColorIcon.d.ts} +0 -0
  25. /package/dist/components/{Icon.d.ts → ui/Icon.d.ts} +0 -0
package/README.md CHANGED
@@ -45,6 +45,40 @@ export function Editor() {
45
45
 
46
46
  `editorOptions` accepts the same options as `useEditor` from `@tiptap/react`, except `extensions`, which is managed internally by the package.
47
47
 
48
+ ## Editor Ref and Events
49
+
50
+ You can access the editor instance and bind Tiptap runtime event listeners through the component ref.
51
+
52
+ ```tsx
53
+ import { useEffect, useRef } from 'react'
54
+ import { TiptopEditor, type TiptopEditorHandle } from 'tiptop-editor'
55
+
56
+ export function EditorWithEvents() {
57
+ const editorRef = useRef<TiptopEditorHandle>(null)
58
+
59
+ useEffect(() => {
60
+ const handleUpdate = ({ editor }: { editor: NonNullable<ReturnType<TiptopEditorHandle['getEditor']>> }) => {
61
+ console.log(editor.getHTML())
62
+ }
63
+
64
+ editorRef.current?.on('update', handleUpdate)
65
+
66
+ return () => {
67
+ editorRef.current?.off('update', handleUpdate)
68
+ }
69
+ }, [])
70
+
71
+ return <TiptopEditor ref={editorRef} />
72
+ }
73
+ ```
74
+
75
+ Available ref methods:
76
+
77
+ - `getEditor()`
78
+ - `on(event, callback)`
79
+ - `off(event, callback?)`
80
+ - `once(event, callback)`
81
+
48
82
  ## Custom Editor UI Options
49
83
 
50
84
  `TiptopEditor` also supports a few package-specific options inside `editorOptions`:
@@ -1,4 +1,4 @@
1
1
  import { default as React } from 'react';
2
- import { TextSelectionMenuProps } from '../types';
2
+ import { TextSelectionMenuProps } from '../../types';
3
3
  declare const _default: React.MemoExoticComponent<({ editor }: TextSelectionMenuProps) => import("react/jsx-runtime").JSX.Element>;
4
4
  export default _default;
@@ -0,0 +1,3 @@
1
+ import { TiptopEditorHandle, TiptopEditorProps } from '../../types';
2
+ declare const TiptopEditor: import('react').ForwardRefExoticComponent<Omit<TiptopEditorProps, "ref"> & import('react').RefAttributes<TiptopEditorHandle>>;
3
+ export default TiptopEditor;
@@ -0,0 +1,16 @@
1
+ import { StoryObj } from '@storybook/react-vite';
2
+ declare const meta: {
3
+ title: string;
4
+ component: import('react').ForwardRefExoticComponent<Omit<import('../..').TiptopEditorProps, "ref"> & import('react').RefAttributes<import('../..').TiptopEditorHandle>>;
5
+ tags: string[];
6
+ args: {
7
+ editorOptions: {
8
+ content: string;
9
+ immediatelyRender: false;
10
+ };
11
+ };
12
+ };
13
+ export default meta;
14
+ type Story = StoryObj<typeof meta>;
15
+ export declare const Default: Story;
16
+ export declare const Frameless: Story;
@@ -1,4 +1,4 @@
1
1
  import { default as React } from 'react';
2
- import { ColorButtonProps } from '../types';
2
+ import { ColorButtonProps } from '../../types';
3
3
  declare const _default: React.MemoExoticComponent<({ editor, buttonType, hsl, color, bgColor, tooltipText, tooltipDisabled, }: ColorButtonProps) => import("react/jsx-runtime").JSX.Element>;
4
4
  export default _default;
@@ -1,4 +1,4 @@
1
1
  import { default as React } from 'react';
2
- import { TextSelectionMenuProps } from '../types';
2
+ import { TextSelectionMenuProps } from '../../types';
3
3
  declare const _default: React.MemoExoticComponent<({ editor, prepend, append }: TextSelectionMenuProps) => import("react/jsx-runtime").JSX.Element>;
4
4
  export default _default;
@@ -1,4 +1,4 @@
1
- import { EditorButtonProps } from '../types';
1
+ import { EditorButtonProps } from '../../types';
2
2
  import { default as React } from 'react';
3
3
  declare const _default: React.MemoExoticComponent<({ editor, buttonKey, tooltipText, isIconOnly, color, variant, isDisabled, icon, iconClass, text, withActive, onPressed, }: EditorButtonProps) => import("react/jsx-runtime").JSX.Element>;
4
4
  export default _default;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { default as TiptopEditor } from './components/TiptopEditor';
1
+ export { default as TiptopEditor } from './components/editor/TiptopEditor';
2
2
  export * from './types';