@dxos/react-ui-editor 0.8.2-main.f11618f → 0.8.2-staging.7ac8446
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 +371 -499
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +379 -515
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +371 -499
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/{stories/InputMode.stories.d.ts → InputMode.stories.d.ts} +1 -1
- package/dist/types/src/InputMode.stories.d.ts.map +1 -0
- package/dist/types/src/{stories/TextEditorBasic.stories.d.ts → TextEditor.stories.d.ts} +35 -2
- package/dist/types/src/TextEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/util.d.ts +3 -3
- package/dist/types/src/components/EditorToolbar/util.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/{view-mode.d.ts → viewMode.d.ts} +1 -1
- package/dist/types/src/components/EditorToolbar/viewMode.d.ts.map +1 -0
- package/dist/types/src/defaults.d.ts +0 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command.d.ts +10 -5
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/hint.d.ts +2 -4
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/index.d.ts +0 -1
- package/dist/types/src/extensions/command/index.d.ts.map +1 -1
- package/dist/types/src/extensions/command/menu.d.ts +2 -7
- package/dist/types/src/extensions/command/menu.d.ts.map +1 -1
- package/dist/types/src/extensions/command/preview.d.ts +12 -0
- package/dist/types/src/extensions/command/preview.d.ts.map +1 -0
- package/dist/types/src/extensions/command/state.d.ts +11 -9
- package/dist/types/src/extensions/command/state.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +7 -9
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +0 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts +1 -4
- package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts +2 -2
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts +1 -4
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
- package/dist/types/src/fragments.d.ts +3 -0
- package/dist/types/src/fragments.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts +1 -2
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +0 -5
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +1 -6
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/package.json +27 -33
- package/src/{stories/InputMode.stories.tsx → InputMode.stories.tsx} +4 -4
- package/src/TextEditor.stories.tsx +856 -0
- package/src/components/EditorToolbar/EditorToolbar.tsx +2 -2
- package/src/components/EditorToolbar/util.ts +3 -3
- package/src/defaults.ts +3 -5
- package/src/extensions/automerge/automerge.stories.tsx +11 -3
- package/src/extensions/command/command.ts +27 -9
- package/src/extensions/command/hint.ts +30 -33
- package/src/extensions/command/index.ts +0 -1
- package/src/extensions/command/menu.ts +8 -11
- package/src/extensions/command/preview.ts +79 -0
- package/src/extensions/command/state.ts +61 -41
- package/src/extensions/comments.ts +9 -9
- package/src/extensions/folding.tsx +1 -1
- package/src/extensions/index.ts +0 -1
- package/src/extensions/markdown/decorate.ts +3 -4
- package/src/extensions/markdown/formatting.ts +2 -2
- package/src/extensions/markdown/image.ts +11 -12
- package/src/extensions/markdown/link.ts +24 -33
- package/src/fragments.ts +19 -0
- package/src/hooks/useTextEditor.ts +3 -4
- package/src/types.ts +0 -7
- package/src/util/react.tsx +2 -20
- package/dist/lib/browser/testing/index.mjs +0 -67
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node/testing/index.cjs +0 -101
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -69
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +0 -1
- package/dist/types/src/extensions/command/action.d.ts +0 -17
- package/dist/types/src/extensions/command/action.d.ts.map +0 -1
- package/dist/types/src/extensions/preview/index.d.ts +0 -2
- package/dist/types/src/extensions/preview/index.d.ts.map +0 -1
- package/dist/types/src/extensions/preview/preview.d.ts +0 -39
- package/dist/types/src/extensions/preview/preview.d.ts.map +0 -1
- package/dist/types/src/stories/InputMode.stories.d.ts.map +0 -1
- package/dist/types/src/stories/TextEditorBasic.stories.d.ts.map +0 -1
- package/dist/types/src/stories/TextEditorComments.stories.d.ts +0 -13
- package/dist/types/src/stories/TextEditorComments.stories.d.ts.map +0 -1
- package/dist/types/src/stories/TextEditorPreview.stories.d.ts +0 -13
- package/dist/types/src/stories/TextEditorPreview.stories.d.ts.map +0 -1
- package/dist/types/src/stories/TextEditorSpecial.stories.d.ts +0 -19
- package/dist/types/src/stories/TextEditorSpecial.stories.d.ts.map +0 -1
- package/dist/types/src/stories/story-utils.d.ts +0 -53
- package/dist/types/src/stories/story-utils.d.ts.map +0 -1
- package/dist/types/src/testing/RefPopover.d.ts +0 -21
- package/dist/types/src/testing/RefPopover.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/src/extensions/command/action.ts +0 -49
- package/src/extensions/preview/index.ts +0 -5
- package/src/extensions/preview/preview.ts +0 -271
- package/src/stories/TextEditorBasic.stories.tsx +0 -289
- package/src/stories/TextEditorComments.stories.tsx +0 -99
- package/src/stories/TextEditorPreview.stories.tsx +0 -239
- package/src/stories/TextEditorSpecial.stories.tsx +0 -107
- package/src/stories/story-utils.tsx +0 -329
- package/src/testing/RefPopover.tsx +0 -74
- package/src/testing/index.ts +0 -5
- /package/src/components/EditorToolbar/{view-mode.ts → viewMode.ts} +0 -0
@@ -1,19 +0,0 @@
|
|
1
|
-
import '@dxos-theme';
|
2
|
-
import React from 'react';
|
3
|
-
import { type Meta } from '@dxos/storybook-utils';
|
4
|
-
import { DefaultStory } from './story-utils';
|
5
|
-
declare const meta: Meta<typeof DefaultStory>;
|
6
|
-
export default meta;
|
7
|
-
export declare const Listener: {
|
8
|
-
render: () => React.JSX.Element;
|
9
|
-
};
|
10
|
-
export declare const Typewriter: {
|
11
|
-
render: () => React.JSX.Element;
|
12
|
-
};
|
13
|
-
export declare const Blast: {
|
14
|
-
render: () => React.JSX.Element;
|
15
|
-
};
|
16
|
-
export declare const DND: {
|
17
|
-
render: () => React.JSX.Element;
|
18
|
-
};
|
19
|
-
//# sourceMappingURL=TextEditorSpecial.stories.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"TextEditorSpecial.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/TextEditorSpecial.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAGrB,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAgB,MAAM,eAAe,CAAC;AAG3D,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,YAAY,CAKnC,CAAC;AAEF,eAAe,IAAI,CAAC;AAMpB,eAAO,MAAM,QAAQ;;CAgBpB,CAAC;AAQF,eAAO,MAAM,UAAU;;CAOtB,CAAC;AAMF,eAAO,MAAM,KAAK;;CAqBjB,CAAC;AAMF,eAAO,MAAM,GAAG;;CAaf,CAAC"}
|
@@ -1,53 +0,0 @@
|
|
1
|
-
import { type Completion } from '@codemirror/autocomplete';
|
2
|
-
import { type Extension } from '@codemirror/state';
|
3
|
-
import { type EditorView } from '@codemirror/view';
|
4
|
-
import React from 'react';
|
5
|
-
import { type EditorSelectionState } from '../extensions';
|
6
|
-
import { type UseTextEditorProps } from '../hooks';
|
7
|
-
export declare const str: (...lines: string[]) => string;
|
8
|
-
export declare const num: () => string;
|
9
|
-
export declare const img = "";
|
10
|
-
export declare const code: string;
|
11
|
-
export declare const content: {
|
12
|
-
tasks: string;
|
13
|
-
bullets: string;
|
14
|
-
numbered: string;
|
15
|
-
typescript: string;
|
16
|
-
codeblocks: string;
|
17
|
-
comment: string;
|
18
|
-
links: string;
|
19
|
-
table: string;
|
20
|
-
image: string;
|
21
|
-
headings: string;
|
22
|
-
formatting: string;
|
23
|
-
blockquotes: string;
|
24
|
-
paragraphs: string;
|
25
|
-
footer: string;
|
26
|
-
};
|
27
|
-
export declare const text: string;
|
28
|
-
export declare const links: Completion[];
|
29
|
-
export declare const names: string[];
|
30
|
-
export declare const renderLinkTooltip: import("..").RenderCallback<{
|
31
|
-
url: string;
|
32
|
-
}>;
|
33
|
-
export declare const renderLinkButton: import("..").RenderCallback<{
|
34
|
-
url: string;
|
35
|
-
}>;
|
36
|
-
export declare const defaultExtensions: Extension[];
|
37
|
-
export declare const allExtensions: Extension[];
|
38
|
-
export declare const longText: string;
|
39
|
-
export declare const largeWithImages: string;
|
40
|
-
export declare const headings: string;
|
41
|
-
export declare const global: Map<string, EditorSelectionState>;
|
42
|
-
export type DebugMode = 'raw' | 'tree' | 'raw+tree';
|
43
|
-
export type StoryProps = {
|
44
|
-
id?: string;
|
45
|
-
debug?: DebugMode;
|
46
|
-
text?: string;
|
47
|
-
readOnly?: boolean;
|
48
|
-
placeholder?: string;
|
49
|
-
lineNumbers?: boolean;
|
50
|
-
onReady?: (view: EditorView) => void;
|
51
|
-
} & Pick<UseTextEditorProps, 'scrollTo' | 'selection' | 'extensions'>;
|
52
|
-
export declare const DefaultStory: ({ id, debug, text, extensions, readOnly, placeholder, scrollTo, selection, lineNumbers, onReady, }: StoryProps) => React.JSX.Element;
|
53
|
-
//# sourceMappingURL=story-utils.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"story-utils.d.ts","sourceRoot":"","sources":["../../../../src/stories/story-utils.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAuC,MAAM,OAAO,CAAC;AAW5D,OAAO,EACL,KAAK,oBAAoB,EAQ1B,MAAM,eAAe,CAAC;AAQvB,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,eAAO,MAAM,GAAG,aAAc,MAAM,EAAE,WAAqB,CAAC;AAE5D,eAAO,MAAM,GAAG,cAAiE,CAAC;AAElF,eAAO,MAAM,GAAG,yDAAyD,CAAC;AAE1E,eAAO,MAAM,IAAI,QAOhB,CAAC;AAGF,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;CA+FnB,CAAC;AAGF,eAAO,MAAM,IAAI,QAwBhB,CAAC;AAGF,eAAO,MAAM,KAAK,EAAE,UAAU,EAM7B,CAAC;AAEF,eAAO,MAAM,KAAK,UAA4E,CAAC;AAe/F,eAAO,MAAM,iBAAiB;SAVD,MAAM;EAUyB,CAAC;AAU7D,eAAO,MAAM,gBAAgB;SARD,MAAM;EAQwB,CAAC;AAG3D,eAAO,MAAM,iBAAiB,EAAE,SAAS,EAIxC,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAAS,EAOpC,CAAC;AAGF,eAAO,MAAM,QAAQ,QAEN,CAAC;AAEhB,eAAO,MAAM,eAAe,QAGb,CAAC;AAEhB,eAAO,MAAM,QAAQ,QAIpB,CAAC;AAEF,eAAO,MAAM,MAAM,mCAA0C,CAAC;AAG9D,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;AAEpD,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CACtC,GAAG,IAAI,CAAC,kBAAkB,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC;AAGtE,eAAO,MAAM,YAAY,uGAWtB,UAAU,sBAsDZ,CAAC"}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import React, { type PropsWithChildren } from 'react';
|
2
|
-
import { type PreviewLinkRef, type PreviewLinkTarget, type PreviewLookup } from '../extensions';
|
3
|
-
type RefPopoverValue = Partial<{
|
4
|
-
link: PreviewLinkRef;
|
5
|
-
target: PreviewLinkTarget;
|
6
|
-
pending: boolean;
|
7
|
-
}>;
|
8
|
-
declare const useRefPopover: (consumerName: string) => Partial<{
|
9
|
-
link: PreviewLinkRef;
|
10
|
-
target: PreviewLinkTarget;
|
11
|
-
pending: boolean;
|
12
|
-
}>;
|
13
|
-
type RefPopoverProviderProps = PropsWithChildren<{
|
14
|
-
onLookup?: PreviewLookup;
|
15
|
-
}>;
|
16
|
-
export declare const RefPopover: {
|
17
|
-
Provider: ({ children, onLookup }: RefPopoverProviderProps) => React.JSX.Element;
|
18
|
-
};
|
19
|
-
export { useRefPopover };
|
20
|
-
export type { RefPopoverProviderProps, RefPopoverValue };
|
21
|
-
//# sourceMappingURL=RefPopover.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"RefPopover.d.ts","sourceRoot":"","sources":["../../../../src/testing/RefPopover.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAA4D,MAAM,OAAO,CAAC;AAMhH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAKhG,KAAK,eAAe,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEtG,QAAA,MAAkC,aAAa;UAFR,cAAc;YAAU,iBAAiB;aAAW,OAAO;EAEA,CAAC;AAEnG,KAAK,uBAAuB,GAAG,iBAAiB,CAAC;IAAE,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AA+C/E,eAAO,MAAM,UAAU;uCA7C6B,uBAAuB;CA+C1E,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,YAAY,EAAE,uBAAuB,EAAE,eAAe,EAAE,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC"}
|
@@ -1,49 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Copyright 2025 DXOS.org
|
3
|
-
//
|
4
|
-
|
5
|
-
import { StateEffect } from '@codemirror/state';
|
6
|
-
import { type KeyBinding, type Command, type EditorView } from '@codemirror/view';
|
7
|
-
|
8
|
-
import { commandState } from './state';
|
9
|
-
|
10
|
-
export type Action =
|
11
|
-
| {
|
12
|
-
type: 'insert';
|
13
|
-
text: string;
|
14
|
-
}
|
15
|
-
| {
|
16
|
-
type: 'cancel';
|
17
|
-
};
|
18
|
-
|
19
|
-
export type ActionHandler = (action: Action) => void;
|
20
|
-
|
21
|
-
export const openEffect = StateEffect.define<{ pos: number; fullWidth?: boolean }>();
|
22
|
-
export const closeEffect = StateEffect.define<null>();
|
23
|
-
|
24
|
-
export const openCommand: Command = (view: EditorView) => {
|
25
|
-
if (view.state.field(commandState, false)) {
|
26
|
-
const selection = view.state.selection.main;
|
27
|
-
const line = view.state.doc.lineAt(selection.from);
|
28
|
-
if (line.from === selection.from && line.from === line.to) {
|
29
|
-
view.dispatch({ effects: openEffect.of({ pos: selection.anchor, fullWidth: true }) });
|
30
|
-
return true;
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
return false;
|
35
|
-
};
|
36
|
-
|
37
|
-
export const closeCommand: Command = (view: EditorView) => {
|
38
|
-
if (view.state.field(commandState, false)) {
|
39
|
-
view.dispatch({ effects: closeEffect.of(null) });
|
40
|
-
return true;
|
41
|
-
}
|
42
|
-
|
43
|
-
return false;
|
44
|
-
};
|
45
|
-
|
46
|
-
export const commandKeyBindings: readonly KeyBinding[] = [
|
47
|
-
{ key: '/', run: openCommand },
|
48
|
-
{ key: 'Escape', run: closeCommand },
|
49
|
-
];
|
@@ -1,271 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Copyright 2023 DXOS.org
|
3
|
-
//
|
4
|
-
|
5
|
-
import '@dxos/lit-ui/dx-ref-tag.pcss';
|
6
|
-
|
7
|
-
import { syntaxTree } from '@codemirror/language';
|
8
|
-
import {
|
9
|
-
type EditorState,
|
10
|
-
type Extension,
|
11
|
-
type RangeSet,
|
12
|
-
RangeSetBuilder,
|
13
|
-
StateField,
|
14
|
-
type Transaction,
|
15
|
-
} from '@codemirror/state';
|
16
|
-
import { Decoration, type DecorationSet, EditorView, WidgetType } from '@codemirror/view';
|
17
|
-
import { type SyntaxNode } from '@lezer/common';
|
18
|
-
|
19
|
-
import { type RenderCallback } from '../../types';
|
20
|
-
|
21
|
-
export type PreviewLinkRef = {
|
22
|
-
suggest?: boolean;
|
23
|
-
block?: boolean;
|
24
|
-
label: string;
|
25
|
-
ref: string;
|
26
|
-
};
|
27
|
-
|
28
|
-
export type PreviewLinkTarget = {
|
29
|
-
label: string;
|
30
|
-
text?: string;
|
31
|
-
object?: any;
|
32
|
-
};
|
33
|
-
|
34
|
-
export type PreviewAction =
|
35
|
-
| {
|
36
|
-
type: 'insert';
|
37
|
-
link: PreviewLinkRef;
|
38
|
-
target: PreviewLinkTarget;
|
39
|
-
}
|
40
|
-
| {
|
41
|
-
type: 'delete';
|
42
|
-
link: PreviewLinkRef;
|
43
|
-
};
|
44
|
-
|
45
|
-
// TODO(burdon): Handle error.
|
46
|
-
export type PreviewLookup = (link: PreviewLinkRef) => Promise<PreviewLinkTarget | null | undefined>;
|
47
|
-
|
48
|
-
export type PreviewActionHandler = (action: PreviewAction) => void;
|
49
|
-
|
50
|
-
export type PreviewRenderProps = {
|
51
|
-
readonly: boolean;
|
52
|
-
link: PreviewLinkRef;
|
53
|
-
onAction: PreviewActionHandler;
|
54
|
-
onLookup?: PreviewLookup;
|
55
|
-
};
|
56
|
-
|
57
|
-
export type PreviewOptions = {
|
58
|
-
renderBlock?: RenderCallback<PreviewRenderProps>;
|
59
|
-
onLookup?: PreviewLookup;
|
60
|
-
};
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Create preview decorations.
|
64
|
-
*/
|
65
|
-
export const preview = (options: PreviewOptions = {}): Extension => {
|
66
|
-
return [
|
67
|
-
// NOTE: Atomic block decorations must be created from a state field, now a widget, otherwise it results in the following error:
|
68
|
-
// "Block decorations may not be specified via plugins"
|
69
|
-
StateField.define<DecorationSet>({
|
70
|
-
create: (state) => buildDecorations(state, options),
|
71
|
-
update: (_: RangeSet<Decoration>, tr: Transaction) => buildDecorations(tr.state, options),
|
72
|
-
provide: (field) => [
|
73
|
-
EditorView.decorations.from(field),
|
74
|
-
EditorView.atomicRanges.of((view) => view.state.field(field)),
|
75
|
-
],
|
76
|
-
}),
|
77
|
-
|
78
|
-
EditorView.theme({
|
79
|
-
'.cm-preview-block': {
|
80
|
-
marginLeft: '-1rem',
|
81
|
-
marginRight: '-1rem',
|
82
|
-
padding: '1rem',
|
83
|
-
borderRadius: '0.5rem',
|
84
|
-
background: 'var(--dx-modalSurface)',
|
85
|
-
border: '1px solid var(--dx-separator)',
|
86
|
-
},
|
87
|
-
}),
|
88
|
-
];
|
89
|
-
};
|
90
|
-
|
91
|
-
/**
|
92
|
-
* Link references.
|
93
|
-
*
|
94
|
-
* [Label][dxn:echo:123] Inline reference
|
95
|
-
* ![Label][dxn:echo:123] Block reference
|
96
|
-
* ![Label][?dxn:echo:123] Suggestion
|
97
|
-
*/
|
98
|
-
const getLinkRef = (state: EditorState, node: SyntaxNode): PreviewLinkRef | undefined => {
|
99
|
-
const mark = node.getChild('LinkMark');
|
100
|
-
const label = node.getChild('LinkLabel');
|
101
|
-
if (mark && label) {
|
102
|
-
const ref = state.sliceDoc(label.from + 1, label.to - 1);
|
103
|
-
return {
|
104
|
-
suggest: ref.startsWith('?'),
|
105
|
-
block: state.sliceDoc(mark.from, mark.from + 1) === '!',
|
106
|
-
label: state.sliceDoc(mark.to, label.from - 1),
|
107
|
-
ref: ref.startsWith('?') ? ref.slice(1) : ref,
|
108
|
-
};
|
109
|
-
}
|
110
|
-
};
|
111
|
-
|
112
|
-
/**
|
113
|
-
* Echo references are represented as markdown reference links.
|
114
|
-
* https://www.markdownguide.org/basic-syntax/#reference-style-links
|
115
|
-
* [Label|block][dxn:echo:123]
|
116
|
-
* [Label|inline][dxn:echo:123]
|
117
|
-
*/
|
118
|
-
const buildDecorations = (state: EditorState, options: PreviewOptions) => {
|
119
|
-
const builder = new RangeSetBuilder<Decoration>();
|
120
|
-
|
121
|
-
syntaxTree(state).iterate({
|
122
|
-
enter: (node) => {
|
123
|
-
switch (node.name) {
|
124
|
-
//
|
125
|
-
// Decoration.
|
126
|
-
// [Label][dxn:echo:123]
|
127
|
-
//
|
128
|
-
case 'Link': {
|
129
|
-
const link = getLinkRef(state, node.node);
|
130
|
-
if (link) {
|
131
|
-
builder.add(
|
132
|
-
node.from,
|
133
|
-
node.to,
|
134
|
-
Decoration.replace({
|
135
|
-
widget: new PreviewInlineWidget(options, link),
|
136
|
-
}),
|
137
|
-
);
|
138
|
-
}
|
139
|
-
break;
|
140
|
-
}
|
141
|
-
//
|
142
|
-
// Block widget.
|
143
|
-
// ![Label][dxn:echo:123]
|
144
|
-
//
|
145
|
-
case 'Image': {
|
146
|
-
const link = getLinkRef(state, node.node);
|
147
|
-
if (options.renderBlock && link) {
|
148
|
-
builder.add(
|
149
|
-
node.from,
|
150
|
-
node.to,
|
151
|
-
Decoration.replace({
|
152
|
-
block: true,
|
153
|
-
// atomic: true,
|
154
|
-
widget: new PreviewBlockWidget(options, link),
|
155
|
-
}),
|
156
|
-
);
|
157
|
-
}
|
158
|
-
break;
|
159
|
-
}
|
160
|
-
}
|
161
|
-
},
|
162
|
-
});
|
163
|
-
|
164
|
-
return builder.finish();
|
165
|
-
};
|
166
|
-
|
167
|
-
/**
|
168
|
-
* Inline widget.
|
169
|
-
* [Label][dxn:echo:123]
|
170
|
-
*/
|
171
|
-
class PreviewInlineWidget extends WidgetType {
|
172
|
-
constructor(
|
173
|
-
readonly _options: PreviewOptions,
|
174
|
-
readonly _link: PreviewLinkRef,
|
175
|
-
) {
|
176
|
-
super();
|
177
|
-
}
|
178
|
-
|
179
|
-
// override ignoreEvent() {
|
180
|
-
// return false;
|
181
|
-
// }
|
182
|
-
|
183
|
-
override eq(other: this) {
|
184
|
-
return this._link.ref === other._link.ref && this._link.label === other._link.label;
|
185
|
-
}
|
186
|
-
|
187
|
-
override toDOM(view: EditorView) {
|
188
|
-
const root = document.createElement('dx-ref-tag');
|
189
|
-
root.textContent = this._link.label;
|
190
|
-
root.setAttribute('ref', this._link.ref);
|
191
|
-
return root;
|
192
|
-
}
|
193
|
-
}
|
194
|
-
|
195
|
-
/**
|
196
|
-
* Block widget.
|
197
|
-
* ![Label][dxn:echo:123]
|
198
|
-
*/
|
199
|
-
class PreviewBlockWidget extends WidgetType {
|
200
|
-
constructor(
|
201
|
-
readonly _options: PreviewOptions,
|
202
|
-
readonly _link: PreviewLinkRef,
|
203
|
-
) {
|
204
|
-
super();
|
205
|
-
}
|
206
|
-
|
207
|
-
// override ignoreEvent() {
|
208
|
-
// return true;
|
209
|
-
// }
|
210
|
-
|
211
|
-
override eq(other: this) {
|
212
|
-
return this._link.ref === other._link.ref;
|
213
|
-
}
|
214
|
-
|
215
|
-
override toDOM(view: EditorView) {
|
216
|
-
const root = document.createElement('div');
|
217
|
-
root.classList.add('cm-preview-block');
|
218
|
-
|
219
|
-
// TODO(burdon): Inject handler.
|
220
|
-
const handleAction: PreviewActionHandler = (action) => {
|
221
|
-
const pos = view.posAtDOM(root);
|
222
|
-
const node = syntaxTree(view.state).resolve(pos + 1).node.parent;
|
223
|
-
if (!node) {
|
224
|
-
return;
|
225
|
-
}
|
226
|
-
|
227
|
-
const link = getLinkRef(view.state, node);
|
228
|
-
if (link?.ref !== action.link.ref) {
|
229
|
-
return;
|
230
|
-
}
|
231
|
-
|
232
|
-
switch (action.type) {
|
233
|
-
// TODO(burdon): Should we dispatch to the view or mutate the document? (i.e., handle externally?)
|
234
|
-
// Insert ref text.
|
235
|
-
case 'insert': {
|
236
|
-
view.dispatch({
|
237
|
-
changes: {
|
238
|
-
from: node.from,
|
239
|
-
to: node.to,
|
240
|
-
insert: action.target.text,
|
241
|
-
},
|
242
|
-
});
|
243
|
-
break;
|
244
|
-
}
|
245
|
-
// Remove ref.
|
246
|
-
case 'delete': {
|
247
|
-
view.dispatch({
|
248
|
-
changes: {
|
249
|
-
from: node.from,
|
250
|
-
to: node.to,
|
251
|
-
},
|
252
|
-
});
|
253
|
-
break;
|
254
|
-
}
|
255
|
-
}
|
256
|
-
};
|
257
|
-
|
258
|
-
this._options.renderBlock!(
|
259
|
-
root,
|
260
|
-
{
|
261
|
-
readonly: view.state.readOnly,
|
262
|
-
link: this._link,
|
263
|
-
onAction: handleAction,
|
264
|
-
onLookup: this._options.onLookup,
|
265
|
-
},
|
266
|
-
view,
|
267
|
-
);
|
268
|
-
|
269
|
-
return root;
|
270
|
-
}
|
271
|
-
}
|