@ctzhian/tiptap 1.8.0 → 1.8.2-beta.1

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.
@@ -7,16 +7,17 @@ import { Box, Button } from '@mui/material';
7
7
  import React from 'react';
8
8
  import "../index.css";
9
9
  var Reader = function Reader() {
10
+ var isMarkdown = false;
10
11
  var _useTiptap = useTiptap({
11
12
  editable: true,
12
- // mode: 'markdown',
13
+ contentType: isMarkdown ? 'markdown' : 'html',
13
14
  exclude: ['invisibleCharacters'],
14
15
  onSave: function onSave(editor) {
15
- console.log('============= markdown =============');
16
- console.log(editor.getMarkdown());
17
- console.log('============= html =============');
18
- console.log(editor.getHTML());
19
- editor.commands.setContent(editor.getHTML());
16
+ var value = isMarkdown ? editor.getMarkdown() : editor.getHTML();
17
+ console.log(value);
18
+ editor.chain().focus().setContent(value, {
19
+ contentType: isMarkdown ? 'markdown' : 'html'
20
+ }).run();
20
21
  },
21
22
  onAiWritingGetSuggestion: function () {
22
23
  var _onAiWritingGetSuggestion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
@@ -100,11 +100,17 @@ var useTiptap = function useTiptap(_ref) {
100
100
  }));
101
101
  return {
102
102
  editor: editor,
103
+ setContent: function setContent(value) {
104
+ var _editor$chain;
105
+ editor === null || editor === void 0 || (_editor$chain = editor.chain()) === null || _editor$chain === void 0 || (_editor$chain = _editor$chain.focus()) === null || _editor$chain === void 0 || (_editor$chain = _editor$chain.setContent(value, {
106
+ contentType: contentType === 'markdown' ? 'markdown' : 'html'
107
+ })) === null || _editor$chain === void 0 || _editor$chain.run();
108
+ },
103
109
  getMarkdown: function getMarkdown() {
110
+ if (!editor) return '';
104
111
  if (contentType === 'markdown') {
105
112
  return editor.getMarkdown();
106
113
  }
107
- if (!editor) return '';
108
114
  return renderToMarkdown({
109
115
  extensions: editor.extensionManager.extensions,
110
116
  content: editor.getJSON()
@@ -2,6 +2,7 @@
2
2
  import { PopoverOrigin, SxProps, Theme } from '@mui/material';
3
3
  import { Editor, Extension } from '@tiptap/core';
4
4
  import { YoutubeOptions } from '@tiptap/extension-youtube';
5
+ import { UseEditorOptions } from '@tiptap/react';
5
6
  export type { Editor } from '@tiptap/react';
6
7
  export interface MenuItem {
7
8
  label?: React.ReactNode;
@@ -84,14 +85,13 @@ export type MentionExtensionProps = {
84
85
  query: string;
85
86
  }) => Promise<MentionItems>;
86
87
  };
87
- export type ModeType = 'rich-text' | 'markdown' | 'diff';
88
88
  export type ExtensionRelativeProps = MentionExtensionProps & EditorFnProps & {
89
- contentType?: ModeType;
90
89
  limit?: number | null;
91
90
  exclude?: string[];
92
91
  extensions?: Extension[];
93
92
  editable: boolean;
94
93
  youtube?: Partial<YoutubeOptions>;
94
+ contentType?: UseEditorOptions['contentType'];
95
95
  };
96
96
  export type UseTiptapProps = {
97
97
  onSave?: (editor: Editor) => void;
@@ -99,6 +99,7 @@ export type UseTiptapProps = {
99
99
  export type GetExtensionsProps = ExtensionRelativeProps;
100
100
  export type UseTiptapReturn = {
101
101
  editor: Editor;
102
+ setContent: (value: string) => void;
102
103
  getMarkdown: () => string;
103
104
  getText: () => string;
104
105
  getHTML: () => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "1.8.0",
3
+ "version": "1.8.2-beta.1",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",