Skip to content

Commit

Permalink
Fix: updating y-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmullapudi committed Feb 20, 2025
1 parent 2acd15b commit 4d54dfc
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 182 deletions.
40 changes: 38 additions & 2 deletions apps/server/src/modules/content/content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { PrismaService } from 'nestjs-prisma';
import { LoggerService } from 'modules/logger/logger.service';
import { isValidAuthentication } from 'modules/sync/sync.utils';
import { TasksService } from 'modules/tasks/tasks.service';
import { yXmlFragmentToProsemirrorJSON } from 'y-prosemirror';
import { prosemirrorJSONToYXmlFragment } from 'y-prosemirror';
import { getSchema } from '@sigma/editor-extensions';
@Injectable()
export class ContentService implements OnModuleInit {
private readonly logger: LoggerService = new LoggerService('ContentGateway');
Expand Down Expand Up @@ -78,8 +79,43 @@ export class ContentService implements OnModuleInit {

await docConnection.transact((doc) => {
const editorState = doc.getXmlFragment('default');
// const tiptapJSON = yXmlFragmentToProsemirrorJSON(editorState);

console.log(editorState.toString());
const newJSON = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'asd',
},
],
},
{
type: 'paragraph',
},
{
type: 'heading',
attrs: {
level: 1,
},
content: [
{
type: 'text',
text: 'working',
},
],
},
{
type: 'paragraph',
content: [],
},
],
};

prosemirrorJSONToYXmlFragment(getSchema(), newJSON, editorState);
});
}
}
12 changes: 6 additions & 6 deletions apps/webapp/common/editor/editor-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import {
import { datePageExtension } from './date-page-extension';
import { fileExtension } from './file-extension';
import { imageExtension } from './image-extension';
import { default as ListItem } from './list-item';
import { LinkTaskExtension } from './link-task';
import { taskExtension } from './task-extension';
import { tasksExtension } from './tasks';
import trailingNode from './trailing-node';
import { LinkTaskExtension } from './link-task';

// create a lowlight instance with all languages loaded
const lowlight = createLowlight(all);
Expand Down Expand Up @@ -68,7 +66,11 @@ const starterKit = StarterKit.configure({
class: cx('list-decimal list-outside pl-6 leading-1 my-1'),
},
},
listItem: false,
listItem: {
HTMLAttributes: {
class: cx('leading-normal'),
},
},
blockquote: {
HTMLAttributes: {
class: cx('border-l-4 border-gray-400 dark:border-gray-500'),
Expand Down Expand Up @@ -135,7 +137,6 @@ export const defaultExtensions = [
tiptapLink,
horizontalRule,
heading,
ListItem,
AIHighlight,
fileExtension,
imageExtension,
Expand All @@ -145,7 +146,6 @@ export const defaultExtensions = [
tasksExtension,
CustomKeymap,
LinkTaskExtension,
trailingNode,
CodeBlockLowlight.configure({
lowlight,
}),
Expand Down
109 changes: 0 additions & 109 deletions apps/webapp/common/editor/list-item/index.ts

This file was deleted.

10 changes: 1 addition & 9 deletions apps/webapp/modules/my-day/day-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import type { PageType } from 'common/types';
import { useCreatePageMutation } from 'services/pages';

import { useContextStore } from 'store/global-context-provider';
import { Editor as EditorT } from '@tiptap/core';
import { addTasksSectionIfNotFound } from './utils';

interface DayEditorProps {
date: Date;
Expand All @@ -35,10 +33,8 @@ interface EditorWithPageProps {
export const EditorWithPage = observer(
({ page, date }: EditorWithPageProps) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [provider, setProvider] =
React.useState<HocuspocusProvider>(undefined);
const [_, setProvider] = React.useState<HocuspocusProvider>(undefined);
const [doc, setDoc] = React.useState(undefined);
const [editor, setEditor] = React.useState(undefined);

React.useEffect(() => {
initPageSocket();
Expand Down Expand Up @@ -67,9 +63,6 @@ export const EditorWithPage = observer(
};

const onDescriptionChange = () => {};
const onCreate = (editor: EditorT) => {
setEditor(editor);
};

if (page && doc) {
return (
Expand All @@ -83,7 +76,6 @@ export const EditorWithPage = observer(
document: doc,
}),
]}
onCreate={onCreate}
className="min-h-[calc(100vh_-_65vh)] my-1"
placeholder="Write notes..."
>
Expand Down
4 changes: 4 additions & 0 deletions packages/editor-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"@tiptap/extension-horizontal-rule": "^2.11.5",
"@tiptap/extension-image": "^2.11.5",
"@tiptap/extension-link": "^2.11.5",
"@tiptap/extension-placeholder": "^2.11.5",
"@tiptap/extension-highlight": "^2.11.5",
"@tiptap/extension-list-item": "^2.11.5",
"@tiptap/extension-mention": "^2.10.3",
"@tiptap/extension-ordered-list": "^2.11.5",
Expand All @@ -56,10 +58,12 @@
"@tiptap/extension-task-list": "^2.11.5",
"@tiptap/extension-text": "^2.11.5",
"@tiptap/extension-underline": "^2.11.5",
"@tiptap/extension-list-keymap": "2.11.5",
"@tiptap/html": "^2.10.3",
"@tiptap/react": "^2.5.4",
"add": "^2.0.6",
"lowlight": "^3.3.0",
"novel": "^0.5.0",
"pnpm": "^10.3.0"
},
"exports": {
Expand Down
17 changes: 14 additions & 3 deletions packages/editor-extensions/src/editor-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight';
import StarterKit from '@tiptap/starter-kit';
import { datePageExtension } from './date-page-extension';
import { fileExtension } from './file-extension';
import { imageExtension } from './image-extension';
import { taskExtension } from './task-extension';
import StarterKit from '@tiptap/starter-kit';
import Link from '@tiptap/extension-link';
import Placeholder from '@tiptap/extension-placeholder';
import Highlight from '@tiptap/extension-highlight';
import ListKeymap from '@tiptap/extension-list-keymap';
import { tasksExtension } from './tasks-extension';
import { getSchema as fetchSchema } from '@tiptap/core';

export const defaultExtensions = [
fileExtension,
imageExtension,
taskExtension,
tasksExtension,
datePageExtension,
CodeBlockLowlight,
StarterKit,
Link,
Placeholder,
Highlight,
ListKeymap,
];

export const getSchema = () => fetchSchema(defaultExtensions);
10 changes: 7 additions & 3 deletions packages/editor-extensions/src/task-extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { mergeAttributes, Node } from '@tiptap/core';

/// Copy of webapp/common/editor/task-extension
export const taskExtension = Node.create({
priority: 51,
name: 'taskExtension',
name: 'task',
group: 'inline',
inline: true,

Expand All @@ -11,18 +12,21 @@ export const taskExtension = Node.create({
id: {
default: undefined,
},
number: {
default: undefined,
},
};
},

parseHTML() {
return [
{
tag: 'task-extension',
tag: 'task',
},
];
},

renderHTML({ HTMLAttributes }) {
return ['task-extension', mergeAttributes(HTMLAttributes)];
return ['task', mergeAttributes(HTMLAttributes)];
},
});
19 changes: 19 additions & 0 deletions packages/editor-extensions/src/tasks-extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { mergeAttributes, Node } from '@tiptap/core';

export const tasksExtension = Node.create({
name: 'tasksExtension',
group: 'block',
content: 'block+',

parseHTML() {
return [
{
tag: 'tasks-extension',
},
];
},

renderHTML({ HTMLAttributes }) {
return ['tasks-extension', mergeAttributes(HTMLAttributes)];
},
});
16 changes: 0 additions & 16 deletions packages/services/src/activity/create-acitivity.ts

This file was deleted.

22 changes: 0 additions & 22 deletions packages/services/src/activity/get-activity.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/services/src/activity/index.ts

This file was deleted.

Loading

0 comments on commit 4d54dfc

Please sign in to comment.