@ctzhian/tiptap 1.8.1 → 1.8.2-beta.2

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,24 @@ var useTiptap = function useTiptap(_ref) {
100
100
  }));
101
101
  return {
102
102
  editor: editor,
103
- getMarkdown: function getMarkdown() {
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
+ },
109
+ getContent: function getContent() {
110
+ if (!editor) return '';
104
111
  if (contentType === 'markdown') {
105
112
  return editor.getMarkdown();
106
113
  }
114
+ return editor.getHTML() || '';
115
+ },
116
+ getMarkdown: function getMarkdown() {
107
117
  if (!editor) return '';
118
+ if (contentType === 'markdown') {
119
+ return editor.getMarkdown();
120
+ }
108
121
  return renderToMarkdown({
109
122
  extensions: editor.extensionManager.extensions,
110
123
  content: editor.getJSON()
@@ -91,15 +91,16 @@ export type ExtensionRelativeProps = MentionExtensionProps & EditorFnProps & {
91
91
  extensions?: Extension[];
92
92
  editable: boolean;
93
93
  youtube?: Partial<YoutubeOptions>;
94
+ contentType?: UseEditorOptions['contentType'];
94
95
  };
95
96
  export type UseTiptapProps = {
96
97
  onSave?: (editor: Editor) => void;
97
98
  } & ExtensionRelativeProps;
98
- export type GetExtensionsProps = ExtensionRelativeProps & {
99
- contentType?: UseEditorOptions['contentType'];
100
- };
99
+ export type GetExtensionsProps = ExtensionRelativeProps;
101
100
  export type UseTiptapReturn = {
102
101
  editor: Editor;
102
+ setContent: (value: string) => void;
103
+ getContent: () => string;
103
104
  getMarkdown: () => string;
104
105
  getText: () => string;
105
106
  getHTML: () => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "1.8.1",
3
+ "version": "1.8.2-beta.2",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",