Skip to content

Commit e68ac81

Browse files
committed
Add feature to upgrade old documents #1111
1 parent 3afa5e5 commit e68ac81

24 files changed

+997
-1615
lines changed

browser/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ data-browser/coverage
3434
**/tomic-svelte-**.tgz
3535
**/tomic-cli-**.tgz
3636
**/tomic-create-template-**.tgz
37+
38+
data-browser/src/locales/.wuchale
39+
data-browser/src/locales/data.js
40+

browser/data-browser/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@tiptap/extension-list": "^3.7.2",
3636
"@tiptap/extension-mention": "^3.7.2",
3737
"@tiptap/extension-placeholder": "^3.7.2",
38+
"@tiptap/extension-table": "^3.10.5",
3839
"@tiptap/extension-text-align": "^3.7.2",
3940
"@tiptap/extension-text-style": "^3.7.2",
4041
"@tiptap/extension-typography": "^3.7.2",
@@ -47,8 +48,8 @@
4748
"@tomic/react": "workspace:*",
4849
"@uiw/codemirror-theme-github": "^4.24.1",
4950
"@uiw/react-codemirror": "^4.24.1",
50-
"@wuchale/jsx": "^0.7.4",
51-
"@wuchale/vite-plugin": "^0.14.6",
51+
"@wuchale/jsx": "^0.9.4",
52+
"@wuchale/vite-plugin": "^0.15.3",
5253
"ai": "^5.0.29",
5354
"clsx": "^2.1.1",
5455
"downshift": "^9.0.9",
@@ -75,7 +76,7 @@
7576
"styled-components": "^6.1.19",
7677
"stylis": "4.3.0",
7778
"tiptap-markdown": "^0.8.10",
78-
"wuchale": "^0.16.5",
79+
"wuchale": "^0.18.3",
7980
"y-protocols": "^1.0.6",
8081
"yjs": "^13.6.27",
8182
"zod": "^4.1.5"

browser/data-browser/src/chunks/RTE/AsyncMarkdownEditor.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { StarterKit } from '@tiptap/starter-kit';
44
import { Link } from '@tiptap/extension-link';
55
import { Placeholder } from '@tiptap/extension-placeholder';
66
import { Typography } from '@tiptap/extension-typography';
7-
import { Markdown } from 'tiptap-markdown';
7+
import { Markdown } from '@tiptap/markdown';
88
import { EditorEvents } from './EditorEvents';
99
import { FaCode } from 'react-icons/fa6';
1010
import { useCallback, useState } from 'react';
1111
import { BubbleMenu } from './BubbleMenu';
1212
import { TiptapContextProvider } from './TiptapContext';
1313
import { SlashCommands, buildSuggestion } from './SlashMenu/CommandsExtension';
14+
import { TableKit } from '@tiptap/extension-table';
1415
import { ExtendedImage } from './ImagePicker';
1516
import { usePopoverContainer } from '../../components/Popover';
1617
import {
@@ -19,6 +20,7 @@ import {
1920
FloatingMenuText,
2021
FloatingCodeButton,
2122
} from './sharedEditorStyles';
23+
import { TaskItem, TaskList } from '@tiptap/extension-list';
2224

2325
export type AsyncMarkdownEditorProps = {
2426
placeholder?: string;
@@ -49,8 +51,13 @@ export default function AsyncMarkdownEditor({
4951
StarterKit.configure({
5052
link: false,
5153
}),
52-
Markdown,
54+
Markdown.configure({
55+
markedOptions: {
56+
gfm: true,
57+
},
58+
}),
5359
Typography,
60+
TableKit,
5461
Link.configure({
5562
protocols: [
5663
'http',
@@ -67,6 +74,10 @@ export default function AsyncMarkdownEditor({
6774
target: '_blank',
6875
},
6976
}),
77+
TaskList,
78+
TaskItem.configure({
79+
nested: true,
80+
}),
7081
ExtendedImage.configure({
7182
HTMLAttributes: {
7283
class: 'tiptap-image',
@@ -86,6 +97,7 @@ export default function AsyncMarkdownEditor({
8697
const editor = useEditor({
8798
extensions,
8899
content: markdown,
100+
contentType: 'markdown',
89101
onBlur,
90102
autofocus: !!autoFocus,
91103
editorProps: {
@@ -98,12 +110,11 @@ export default function AsyncMarkdownEditor({
98110
});
99111

100112
const handleChange = useCallback(() => {
101-
// @ts-expect-error - markdown is a valid storage
102-
const value = editor.storage.markdown.getMarkdown();
113+
const value = editor.getMarkdown();
103114

104115
setMarkdown(value);
105116
onChange?.(value);
106-
}, [onChange]);
117+
}, [onChange, editor]);
107118

108119
const handleRawChange = useCallback(
109120
(val: string) => {
@@ -117,7 +128,7 @@ export default function AsyncMarkdownEditor({
117128
setCodeMode(enable);
118129

119130
if (!enable) {
120-
editor?.commands.setContent(markdown);
131+
editor?.commands.setContent(markdown, { contentType: 'markdown' });
121132
}
122133
};
123134

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { getSchema, type Extensions } from '@tiptap/core';
2+
import { Link } from '@tiptap/extension-link';
3+
import { TaskList, TaskItem } from '@tiptap/extension-list';
4+
import TextAlign from '@tiptap/extension-text-align';
5+
import {
6+
TextStyle,
7+
Color,
8+
BackgroundColor,
9+
} from '@tiptap/extension-text-style';
10+
import Typography from '@tiptap/extension-typography';
11+
import StarterKit from '@tiptap/starter-kit';
12+
import { type Store } from '@tomic/react';
13+
import {
14+
ResourceNode,
15+
ResourceNodeInline,
16+
} from './ResourceExtension/ResourceNode';
17+
import Image from '@tiptap/extension-image';
18+
import type { Schema } from '@tiptap/pm/model';
19+
20+
export function getCollaborativeEditorSchema(store: Store): {
21+
schema: Schema;
22+
extensions: Extensions;
23+
} {
24+
const extensions = [
25+
StarterKit.configure({
26+
undoRedo: false,
27+
link: false,
28+
}),
29+
Typography,
30+
Link.extend({
31+
parseHTML: () => [
32+
{
33+
tag: 'a[href]',
34+
getAttrs: node => {
35+
// Links with a data-type are custom nodes that should be ignored by the link extension
36+
if (node.getAttribute('data-type')) {
37+
return false;
38+
}
39+
40+
// Default link parsing
41+
return {
42+
href: node.getAttribute('href'),
43+
target: node.getAttribute('target'),
44+
};
45+
},
46+
},
47+
],
48+
}).configure({
49+
autolink: true,
50+
openOnClick: true,
51+
protocols: [
52+
'http',
53+
'https',
54+
'mailto',
55+
{
56+
scheme: 'tel',
57+
optionalSlashes: true,
58+
},
59+
],
60+
HTMLAttributes: {
61+
class: 'tiptap-link',
62+
rel: 'noopener noreferrer',
63+
target: '_blank',
64+
},
65+
}),
66+
Image.configure({
67+
HTMLAttributes: {
68+
class: 'tiptap-image',
69+
},
70+
}),
71+
ResourceNode.configure({
72+
store,
73+
}),
74+
ResourceNodeInline.configure({
75+
store,
76+
}),
77+
TextAlign.configure({
78+
types: ['heading', 'paragraph'],
79+
}),
80+
TaskList,
81+
TaskItem.configure({
82+
nested: true,
83+
}),
84+
TextStyle,
85+
Color,
86+
BackgroundColor,
87+
];
88+
89+
return { schema: getSchema(extensions), extensions };
90+
}

browser/data-browser/src/chunks/RTE/sharedEditorStyles.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ export const StyledEditorWrapper = styled(EditorWrapperBase)`
3131
& .tiptap {
3232
width: min(100%, 75ch);
3333
min-height: ${MIN_EDITOR_HEIGHT};
34+
35+
table {
36+
border-collapse: collapse;
37+
td,
38+
th {
39+
border: 1px solid ${p => p.theme.colors.bg2};
40+
padding: ${p => p.theme.size(2)};
41+
}
42+
}
3443
}
3544
`;
3645

browser/data-browser/src/components/LocaleContext.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useLocalStorage } from '@hooks/useLocalStorage';
22
import React, { createContext, useContext, useEffect, useState } from 'react';
33
import { loadLocale } from 'wuchale/load-utils';
4+
import { useOnValueChange } from '@helpers/useOnValueChange';
45

5-
interface LocaleContext {
6+
interface LocaleContextType {
67
locale: string;
78
setLocale: (locale: string) => void;
89
}
910

10-
const LocaleContext = createContext<LocaleContext>({
11+
const LocaleContext = createContext<LocaleContextType>({
1112
locale: 'en',
1213
setLocale: () => {},
1314
});
@@ -21,8 +22,11 @@ export const LocaleProvider = ({ children }: React.PropsWithChildren) => {
2122
);
2223
const [localeLoaded, setLocaleLoaded] = useState(false);
2324

24-
useEffect(() => {
25+
useOnValueChange(() => {
2526
setLocaleLoaded(false);
27+
}, [locale]);
28+
29+
useEffect(() => {
2630
loadLocale(locale).then(() => setLocaleLoaded(true));
2731
}, [locale]);
2832

0 commit comments

Comments
 (0)