@dxos/react-ui-editor 0.4.8-main.aa7abac → 0.4.8-main.beadd4b
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.
- package/dist/lib/browser/index.mjs +21 -46
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts +3 -3
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/TextEditor/TextEditor.tsx +2 -2
- package/src/components/Toolbar/Toolbar.stories.tsx +25 -23
- package/src/components/Toolbar/Toolbar.tsx +6 -13
- package/src/extensions/comments.ts +2 -2
- package/src/extensions/markdown/formatting.ts +7 -11
- package/src/hooks/useTextEditor.ts +0 -3
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
ListChecks,
|
|
14
14
|
ListNumbers,
|
|
15
15
|
Paragraph,
|
|
16
|
-
Quotes,
|
|
17
16
|
TextStrikethrough,
|
|
18
17
|
Table,
|
|
19
18
|
TextB,
|
|
@@ -24,6 +23,7 @@ import {
|
|
|
24
23
|
TextHFive,
|
|
25
24
|
TextHSix,
|
|
26
25
|
TextItalic,
|
|
26
|
+
Quotes,
|
|
27
27
|
} from '@phosphor-icons/react';
|
|
28
28
|
import { createContext } from '@radix-ui/react-context';
|
|
29
29
|
import React, { type PropsWithChildren, useEffect, useRef, useState } from 'react';
|
|
@@ -33,9 +33,9 @@ import {
|
|
|
33
33
|
DensityProvider,
|
|
34
34
|
ElevationProvider,
|
|
35
35
|
Select,
|
|
36
|
+
type ThemedClassName,
|
|
36
37
|
Toolbar as NaturalToolbar,
|
|
37
38
|
Tooltip,
|
|
38
|
-
type ThemedClassName,
|
|
39
39
|
type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
|
|
40
40
|
type ToolbarButtonProps as NaturalToolbarButtonProps,
|
|
41
41
|
useTranslation,
|
|
@@ -83,7 +83,7 @@ export type Action = {
|
|
|
83
83
|
|
|
84
84
|
export type ToolbarProps = ThemedClassName<
|
|
85
85
|
PropsWithChildren<{
|
|
86
|
-
state: Formatting |
|
|
86
|
+
state: Formatting | null;
|
|
87
87
|
onAction?: (action: Action) => void;
|
|
88
88
|
}>
|
|
89
89
|
>;
|
|
@@ -355,7 +355,6 @@ const MarkdownCustom = ({ onUpload }: MarkdownCustomOptions = {}) => {
|
|
|
355
355
|
'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
|
|
356
356
|
},
|
|
357
357
|
});
|
|
358
|
-
|
|
359
358
|
useEffect(() => {
|
|
360
359
|
if (onUpload && acceptedFiles.length) {
|
|
361
360
|
setTimeout(async () => {
|
|
@@ -389,15 +388,9 @@ const MarkdownActions = () => {
|
|
|
389
388
|
const { onAction } = useToolbarContext('MarkdownStyles');
|
|
390
389
|
const { t } = useTranslation(translationKey);
|
|
391
390
|
return (
|
|
392
|
-
|
|
393
|
-
{
|
|
394
|
-
|
|
395
|
-
{/* {t('comment label')} */}
|
|
396
|
-
{/* </ToolbarButton> */}
|
|
397
|
-
<ToolbarButton value='comment' Icon={ChatText} onClick={() => onAction?.({ type: 'comment' })}>
|
|
398
|
-
{t('comment label')}
|
|
399
|
-
</ToolbarButton>
|
|
400
|
-
</>
|
|
391
|
+
<ToolbarButton value='comment' Icon={ChatText} onClick={() => onAction?.({ type: 'comment' })}>
|
|
392
|
+
{t('comment label')}
|
|
393
|
+
</ToolbarButton>
|
|
401
394
|
);
|
|
402
395
|
};
|
|
403
396
|
|
|
@@ -508,14 +508,14 @@ export const focusComment = (view: EditorView, id: string, center = true) => {
|
|
|
508
508
|
/**
|
|
509
509
|
* Update comments state field.
|
|
510
510
|
*/
|
|
511
|
-
export const useComments = (view: EditorView | null | undefined, id: string, comments
|
|
511
|
+
export const useComments = (view: EditorView | null | undefined, id: string, comments: Comment[] = []) => {
|
|
512
512
|
useEffect(() => {
|
|
513
513
|
if (view) {
|
|
514
514
|
// Check same document.
|
|
515
515
|
// NOTE: Hook might be called before editor state is updated.
|
|
516
516
|
if (id === view.state.facet(documentId)) {
|
|
517
517
|
view.dispatch({
|
|
518
|
-
effects: setComments.of({ id, comments
|
|
518
|
+
effects: setComments.of({ id, comments }),
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
521
|
}
|
|
@@ -15,9 +15,7 @@ import {
|
|
|
15
15
|
} from '@codemirror/state';
|
|
16
16
|
import { EditorView, keymap } from '@codemirror/view';
|
|
17
17
|
import { type SyntaxNodeRef, type SyntaxNode } from '@lezer/common';
|
|
18
|
-
import { useMemo } from 'react';
|
|
19
|
-
|
|
20
|
-
import { useStateRef } from '@dxos/react-async';
|
|
18
|
+
import { useState, useMemo } from 'react';
|
|
21
19
|
|
|
22
20
|
// Markdown refs:
|
|
23
21
|
// https://github.github.com/gfm
|
|
@@ -58,7 +56,7 @@ export type Formatting = {
|
|
|
58
56
|
listStyle: null | 'ordered' | 'bullet' | 'task';
|
|
59
57
|
};
|
|
60
58
|
|
|
61
|
-
export const
|
|
59
|
+
export const compareFormatting = (a: Formatting, b: Formatting) =>
|
|
62
60
|
a.blockType === b.blockType &&
|
|
63
61
|
a.strong === b.strong &&
|
|
64
62
|
a.emphasis === b.emphasis &&
|
|
@@ -1063,7 +1061,7 @@ export const getFormatting = (state: EditorState): Formatting => {
|
|
|
1063
1061
|
const inline: (boolean | null)[] = [null, null, null, null];
|
|
1064
1062
|
let link: boolean = false;
|
|
1065
1063
|
let blockQuote: boolean | null = null;
|
|
1066
|
-
// False indicates mixed list styles
|
|
1064
|
+
// False indicates mixed list styles
|
|
1067
1065
|
let listStyle: Formatting['listStyle'] | null | false = null;
|
|
1068
1066
|
|
|
1069
1067
|
// Track block context for list/blockquote handling.
|
|
@@ -1222,18 +1220,16 @@ export const getFormatting = (state: EditorState): Formatting => {
|
|
|
1222
1220
|
};
|
|
1223
1221
|
|
|
1224
1222
|
/**
|
|
1225
|
-
* Hook
|
|
1223
|
+
* Hook computes the current formatting state.
|
|
1226
1224
|
*/
|
|
1227
|
-
export const useFormattingState = (): [Formatting |
|
|
1228
|
-
const [state, setState
|
|
1225
|
+
export const useFormattingState = (): [Formatting | null, Extension] => {
|
|
1226
|
+
const [state, setState] = useState<Formatting | null>(null);
|
|
1229
1227
|
const observer = useMemo(
|
|
1230
1228
|
() =>
|
|
1231
1229
|
EditorView.updateListener.of((update) => {
|
|
1232
1230
|
if (update.docChanged || update.selectionSet) {
|
|
1233
1231
|
const newState = getFormatting(update.state);
|
|
1234
|
-
if (!
|
|
1235
|
-
// TODO(burdon): Error on first click on toolbar.
|
|
1236
|
-
// Warning: React has detected a change in the order of Hooks called by ForwardRef. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks
|
|
1232
|
+
if (!state || !compareFormatting(state, newState)) {
|
|
1237
1233
|
setState(newState);
|
|
1238
1234
|
}
|
|
1239
1235
|
}
|
|
@@ -33,8 +33,6 @@ export const useTextEditor = (cb: () => UseTextEditorProps = () => ({}), deps: D
|
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
let view: EditorView;
|
|
35
35
|
if (parentRef.current) {
|
|
36
|
-
log('create', { id });
|
|
37
|
-
|
|
38
36
|
// https://codemirror.net/docs/ref/#state.EditorStateConfig
|
|
39
37
|
const state = EditorState.create({
|
|
40
38
|
doc,
|
|
@@ -71,7 +69,6 @@ export const useTextEditor = (cb: () => UseTextEditorProps = () => ({}), deps: D
|
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
return () => {
|
|
74
|
-
log('destroy', { id });
|
|
75
72
|
view?.destroy();
|
|
76
73
|
};
|
|
77
74
|
}, deps);
|