@dxos/plugin-markdown 0.6.12-main.ed7cda7 → 0.6.12-staging.0b4bb48
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/{DocumentCard-RKENHCNE.mjs → DocumentCard-2P4EICBA.mjs} +3 -3
- package/dist/lib/browser/DocumentEditor-GPWV3VN3.mjs +11 -0
- package/dist/lib/browser/{MarkdownEditor-5EUT7P66.mjs → MarkdownEditor-EKJJQEFL.mjs} +3 -3
- package/dist/lib/browser/{chunk-2SJN46PA.mjs → chunk-4GGD6YJO.mjs} +5 -2
- package/dist/lib/browser/chunk-4GGD6YJO.mjs.map +7 -0
- package/dist/lib/browser/{chunk-JDTH4A4I.mjs → chunk-7AF2JLK4.mjs} +4 -6
- package/dist/lib/browser/{chunk-JDTH4A4I.mjs.map → chunk-7AF2JLK4.mjs.map} +2 -2
- package/dist/lib/browser/{chunk-R6CSLNWW.mjs → chunk-CQJL4G4X.mjs} +2 -2
- package/dist/lib/browser/chunk-CQJL4G4X.mjs.map +7 -0
- package/dist/lib/browser/{chunk-AFWT6Z7B.mjs → chunk-RL7QY322.mjs} +2 -2
- package/dist/lib/browser/{chunk-AVGUYNPR.mjs → chunk-VUN4QKTT.mjs} +53 -65
- package/dist/lib/browser/chunk-VUN4QKTT.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +22 -29
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node/{DocumentCard-ECPKHJT7.cjs → DocumentCard-EHJDDSRY.cjs} +8 -8
- package/dist/lib/node/{DocumentCard-ECPKHJT7.cjs.map → DocumentCard-EHJDDSRY.cjs.map} +2 -2
- package/dist/lib/node/{DocumentEditor-YVZTTY5L.cjs → DocumentEditor-I5GCRBKU.cjs} +9 -9
- package/dist/lib/node/DocumentEditor-I5GCRBKU.cjs.map +7 -0
- package/dist/lib/node/{MarkdownEditor-ZD4W4UJ6.cjs → MarkdownEditor-UE23H75V.cjs} +8 -8
- package/dist/lib/node/MarkdownEditor-UE23H75V.cjs.map +7 -0
- package/dist/lib/node/{chunk-2T7LIVPT.cjs → chunk-7XIBNEI7.cjs} +51 -59
- package/dist/lib/node/chunk-7XIBNEI7.cjs.map +7 -0
- package/dist/lib/node/{chunk-5ZWOR7JF.cjs → chunk-Q4ZSCBQE.cjs} +6 -6
- package/dist/lib/node/{chunk-OEWBZFBF.cjs → chunk-RVGN72IX.cjs} +10 -12
- package/dist/lib/node/chunk-RVGN72IX.cjs.map +7 -0
- package/dist/lib/node/{chunk-LPD4NOTH.cjs → chunk-TGMR2CKU.cjs} +18 -5
- package/dist/lib/node/chunk-TGMR2CKU.cjs.map +7 -0
- package/dist/lib/node/{chunk-MCA5BBJR.cjs → chunk-VWQH4WC2.cjs} +6 -6
- package/dist/lib/node/chunk-VWQH4WC2.cjs.map +7 -0
- package/dist/lib/node/index.cjs +63 -70
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +5 -5
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/types/src/MarkdownPlugin.d.ts.map +1 -1
- package/dist/types/src/components/DocumentEditor.d.ts.map +1 -1
- package/dist/types/src/components/MarkdownEditor.d.ts +1 -1
- package/dist/types/src/components/MarkdownEditor.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +4 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/types/document.d.ts +0 -2
- package/dist/types/src/types/document.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +6 -5
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +34 -38
- package/src/MarkdownPlugin.tsx +10 -17
- package/src/components/DocumentEditor.tsx +1 -3
- package/src/components/MarkdownEditor.tsx +43 -15
- package/src/meta.tsx +5 -1
- package/src/types/types.ts +5 -6
- package/dist/lib/browser/DocumentEditor-FAXQRX37.mjs +0 -11
- package/dist/lib/browser/chunk-2SJN46PA.mjs.map +0 -7
- package/dist/lib/browser/chunk-AVGUYNPR.mjs.map +0 -7
- package/dist/lib/browser/chunk-R6CSLNWW.mjs.map +0 -7
- package/dist/lib/node/DocumentEditor-YVZTTY5L.cjs.map +0 -7
- package/dist/lib/node/MarkdownEditor-ZD4W4UJ6.cjs.map +0 -7
- package/dist/lib/node/chunk-2T7LIVPT.cjs.map +0 -7
- package/dist/lib/node/chunk-LPD4NOTH.cjs.map +0 -7
- package/dist/lib/node/chunk-MCA5BBJR.cjs.map +0 -7
- package/dist/lib/node/chunk-OEWBZFBF.cjs.map +0 -7
- package/dist/lib/node-esm/DocumentCard-RHVY4Z6L.mjs +0 -12
- package/dist/lib/node-esm/DocumentCard-RHVY4Z6L.mjs.map +0 -7
- package/dist/lib/node-esm/DocumentEditor-JBVVPEYE.mjs +0 -12
- package/dist/lib/node-esm/DocumentEditor-JBVVPEYE.mjs.map +0 -7
- package/dist/lib/node-esm/MarkdownEditor-OS7YG6MA.mjs +0 -11
- package/dist/lib/node-esm/MarkdownEditor-OS7YG6MA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2BGTVWHN.mjs +0 -18
- package/dist/lib/node-esm/chunk-2BGTVWHN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OE3CMI5X.mjs +0 -87
- package/dist/lib/node-esm/chunk-OE3CMI5X.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QARGBUBS.mjs +0 -221
- package/dist/lib/node-esm/chunk-QARGBUBS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RO5FEVW6.mjs +0 -119
- package/dist/lib/node-esm/chunk-RO5FEVW6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UG4MIBCA.mjs +0 -167
- package/dist/lib/node-esm/chunk-UG4MIBCA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-W525OVFX.mjs +0 -40
- package/dist/lib/node-esm/chunk-W525OVFX.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -540
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -13
- package/dist/lib/node-esm/types/index.mjs.map +0 -7
- package/dist/types/src/hooks/index.d.ts +0 -2
- package/dist/types/src/hooks/index.d.ts.map +0 -1
- package/dist/types/src/hooks/useSelectCurrentThread.d.ts +0 -6
- package/dist/types/src/hooks/useSelectCurrentThread.d.ts.map +0 -1
- package/src/hooks/index.ts +0 -5
- package/src/hooks/useSelectCurrentThread.tsx +0 -46
- /package/dist/lib/browser/{DocumentCard-RKENHCNE.mjs.map → DocumentCard-2P4EICBA.mjs.map} +0 -0
- /package/dist/lib/browser/{DocumentEditor-FAXQRX37.mjs.map → DocumentEditor-GPWV3VN3.mjs.map} +0 -0
- /package/dist/lib/browser/{MarkdownEditor-5EUT7P66.mjs.map → MarkdownEditor-EKJJQEFL.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-AFWT6Z7B.mjs.map → chunk-RL7QY322.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-5ZWOR7JF.cjs.map → chunk-Q4ZSCBQE.cjs.map} +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { openSearchPanel } from '@codemirror/search';
|
|
6
|
-
import {
|
|
6
|
+
import { EditorView } from '@codemirror/view';
|
|
7
7
|
import React, { useMemo, useEffect, useCallback } from 'react';
|
|
8
8
|
|
|
9
9
|
import {
|
|
@@ -11,11 +11,12 @@ import {
|
|
|
11
11
|
LayoutAction,
|
|
12
12
|
type LayoutCoordinate,
|
|
13
13
|
useResolvePlugin,
|
|
14
|
+
useIntentResolver,
|
|
14
15
|
parseLayoutPlugin,
|
|
15
16
|
useIntentDispatcher,
|
|
16
17
|
} from '@dxos/app-framework';
|
|
18
|
+
import { parseAttentionPlugin } from '@dxos/plugin-attention';
|
|
17
19
|
import { useThemeContext, useTranslation } from '@dxos/react-ui';
|
|
18
|
-
import { useIsDirectlyAttended } from '@dxos/react-ui-attention';
|
|
19
20
|
import {
|
|
20
21
|
type Action,
|
|
21
22
|
type DNDOptions,
|
|
@@ -35,16 +36,16 @@ import {
|
|
|
35
36
|
useTextEditor,
|
|
36
37
|
editorContent,
|
|
37
38
|
editorGutter,
|
|
39
|
+
Cursor,
|
|
40
|
+
setSelection,
|
|
38
41
|
} from '@dxos/react-ui-editor';
|
|
39
42
|
import { sectionToolbarLayout } from '@dxos/react-ui-stack';
|
|
40
43
|
import { textBlockWidth, focusRing, mx } from '@dxos/react-ui-theme';
|
|
41
|
-
import {
|
|
44
|
+
import { nonNullable } from '@dxos/util';
|
|
42
45
|
|
|
43
|
-
import { useSelectCurrentThread } from '../hooks';
|
|
44
46
|
import { MARKDOWN_PLUGIN } from '../meta';
|
|
45
|
-
import {
|
|
47
|
+
import type { MarkdownPluginState } from '../types';
|
|
46
48
|
|
|
47
|
-
// TODO(Zan): Factor into a shared location.
|
|
48
49
|
const attentionFragment = mx(
|
|
49
50
|
'group-focus-within/editor:attention-surface group-[[aria-current]]/editor:attention-surface',
|
|
50
51
|
'group-focus-within/editor:border-separator',
|
|
@@ -82,16 +83,14 @@ export const MarkdownEditor = ({
|
|
|
82
83
|
const { t } = useTranslation(MARKDOWN_PLUGIN);
|
|
83
84
|
const { themeMode } = useThemeContext();
|
|
84
85
|
const dispatch = useIntentDispatcher();
|
|
86
|
+
const attentionPlugin = useResolvePlugin(parseAttentionPlugin);
|
|
85
87
|
const layoutPlugin = useResolvePlugin(parseLayoutPlugin);
|
|
88
|
+
const attended = Array.from(attentionPlugin?.provides.attention?.attended ?? []);
|
|
89
|
+
const isDirectlyAttended = attended.length === 1 && attended[0] === id;
|
|
86
90
|
const [formattingState, formattingObserver] = useFormattingState();
|
|
87
|
-
const isDirectlyAttended = useIsDirectlyAttended(id);
|
|
88
91
|
|
|
89
92
|
// Extensions from other plugins.
|
|
90
|
-
const providerExtensions = useMemo(
|
|
91
|
-
// TODO(burdon): Must pass object to provider.
|
|
92
|
-
() => extensionProviders?.flatMap((provider) => provider({})).filter(nonNullable),
|
|
93
|
-
[extensionProviders],
|
|
94
|
-
);
|
|
93
|
+
const providerExtensions = useMemo(() => extensionProviders?.map((provider) => provider({})), [extensionProviders]);
|
|
95
94
|
|
|
96
95
|
// TODO(Zan): Move these into thread plugin as well?
|
|
97
96
|
const [commentsState, commentObserver] = useCommentState();
|
|
@@ -100,6 +99,36 @@ export const MarkdownEditor = ({
|
|
|
100
99
|
}, [dispatch]);
|
|
101
100
|
const commentClickObserver = useCommentClickListener(onCommentClick);
|
|
102
101
|
|
|
102
|
+
// Focus the space that references the comment.
|
|
103
|
+
useIntentResolver(MARKDOWN_PLUGIN, ({ action, data }) => {
|
|
104
|
+
switch (action) {
|
|
105
|
+
// TODO(burdon): Use fully qualified ids everywhere.
|
|
106
|
+
case LayoutAction.SCROLL_INTO_VIEW: {
|
|
107
|
+
if (editorView && data?.id === id && data?.cursor) {
|
|
108
|
+
// TODO(burdon): We need typed intents.
|
|
109
|
+
const range = Cursor.getRangeFromCursor(editorView.state, data.cursor);
|
|
110
|
+
if (range) {
|
|
111
|
+
const selection = editorView.state.selection.main.from !== range.from ? { anchor: range.from } : undefined;
|
|
112
|
+
const effects = [
|
|
113
|
+
// NOTE: This does not use the DOM scrollIntoView function.
|
|
114
|
+
EditorView.scrollIntoView(range.from, { y: 'start', yMargin: 96 }),
|
|
115
|
+
];
|
|
116
|
+
if (selection) {
|
|
117
|
+
// Update the editor selection to get bi-directional highlighting.
|
|
118
|
+
effects.push(setSelection.of({ current: id }));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
editorView.dispatch({
|
|
122
|
+
effects,
|
|
123
|
+
selection: selection ? { anchor: range.from } : undefined,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
103
132
|
// Drag files.
|
|
104
133
|
const handleDrop: DNDOptions['onDrop'] = async (view, { files }) => {
|
|
105
134
|
const file = files[0];
|
|
@@ -132,10 +161,10 @@ export const MarkdownEditor = ({
|
|
|
132
161
|
slots: { content: { className: editorContent } },
|
|
133
162
|
}),
|
|
134
163
|
editorGutter,
|
|
135
|
-
role !== 'section' && onFileUpload
|
|
164
|
+
role !== 'section' && onFileUpload ? dropFile({ onDrop: handleDrop }) : [],
|
|
136
165
|
providerExtensions,
|
|
137
166
|
extensions,
|
|
138
|
-
].filter(
|
|
167
|
+
].filter(nonNullable),
|
|
139
168
|
...(role !== 'section' && {
|
|
140
169
|
id,
|
|
141
170
|
scrollTo,
|
|
@@ -149,7 +178,6 @@ export const MarkdownEditor = ({
|
|
|
149
178
|
);
|
|
150
179
|
|
|
151
180
|
useTest(editorView);
|
|
152
|
-
useSelectCurrentThread(editorView, id);
|
|
153
181
|
|
|
154
182
|
// Toolbar handler.
|
|
155
183
|
const handleToolbarAction = useActionHandler(editorView);
|
package/src/meta.tsx
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type IconProps, TextAa } from '@phosphor-icons/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
5
8
|
import { pluginMeta } from '@dxos/app-framework';
|
|
6
9
|
|
|
7
10
|
export const MARKDOWN_PLUGIN = 'dxos.org/plugin/markdown';
|
|
@@ -11,5 +14,6 @@ export default pluginMeta({
|
|
|
11
14
|
name: 'Editor',
|
|
12
15
|
description: 'Markdown text editor.',
|
|
13
16
|
homePage: 'https://github.com/dxos/dxos/tree/main/packages/apps/plugins/plugin-markdown',
|
|
14
|
-
|
|
17
|
+
iconComponent: (props: IconProps) => <TextAa {...props} />,
|
|
18
|
+
iconSymbol: 'ph--text-aa--regular',
|
|
15
19
|
});
|
package/src/types/types.ts
CHANGED
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
TranslationsProvides,
|
|
13
13
|
} from '@dxos/app-framework';
|
|
14
14
|
import { type SchemaProvides } from '@dxos/plugin-client';
|
|
15
|
-
import { type SpaceInitProvides } from '@dxos/plugin-space';
|
|
16
15
|
import { type Extension, type EditorInputMode, type EditorViewMode } from '@dxos/react-ui-editor';
|
|
17
16
|
|
|
18
17
|
import { type DocumentType } from './document';
|
|
@@ -27,7 +26,7 @@ export enum MarkdownAction {
|
|
|
27
26
|
|
|
28
27
|
export type MarkdownProperties = Record<string, any>;
|
|
29
28
|
|
|
30
|
-
export type ExtensionsProvider = (props: { document?: DocumentType }) => Extension[]
|
|
29
|
+
export type ExtensionsProvider = (props: { document?: DocumentType }) => Extension[];
|
|
31
30
|
|
|
32
31
|
export type OnChange = (text: string) => void;
|
|
33
32
|
|
|
@@ -50,7 +49,7 @@ export type MarkdownPluginState = {
|
|
|
50
49
|
|
|
51
50
|
// TODO(burdon): Extend view mode per document to include scroll position, etc.
|
|
52
51
|
// View mode per document.
|
|
53
|
-
viewMode:
|
|
52
|
+
viewMode: { [key: string]: EditorViewMode };
|
|
54
53
|
};
|
|
55
54
|
|
|
56
55
|
export type MarkdownSettingsProps = {
|
|
@@ -65,11 +64,12 @@ export type MarkdownSettingsProps = {
|
|
|
65
64
|
folding?: boolean;
|
|
66
65
|
};
|
|
67
66
|
|
|
68
|
-
// TODO(Zan): Move this to the plugin-space plugin or another common location
|
|
67
|
+
// TODO(Zan): Move this to the plugin-space plugin or another common location
|
|
68
|
+
// when we implement comments in sheets.
|
|
69
69
|
type ThreadProvides<T> = {
|
|
70
70
|
thread: {
|
|
71
71
|
predicate: (obj: any) => obj is T;
|
|
72
|
-
createSort: (obj: T) => (anchorA: string
|
|
72
|
+
createSort: (obj: T) => (anchorA: string, anchorB: string) => number;
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
|
|
@@ -81,6 +81,5 @@ export type MarkdownPluginProvides = SurfaceProvides &
|
|
|
81
81
|
SettingsProvides<MarkdownSettingsProps> &
|
|
82
82
|
TranslationsProvides &
|
|
83
83
|
SchemaProvides &
|
|
84
|
-
SpaceInitProvides &
|
|
85
84
|
StackProvides &
|
|
86
85
|
ThreadProvides<DocumentType>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DocumentEditor_default
|
|
3
|
-
} from "./chunk-JDTH4A4I.mjs";
|
|
4
|
-
import "./chunk-R6CSLNWW.mjs";
|
|
5
|
-
import "./chunk-354DCID5.mjs";
|
|
6
|
-
import "./chunk-AVGUYNPR.mjs";
|
|
7
|
-
import "./chunk-2SJN46PA.mjs";
|
|
8
|
-
export {
|
|
9
|
-
DocumentEditor_default as default
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=DocumentEditor-FAXQRX37.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/meta.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { pluginMeta } from '@dxos/app-framework';\n\nexport const MARKDOWN_PLUGIN = 'dxos.org/plugin/markdown';\n\nexport default pluginMeta({\n id: MARKDOWN_PLUGIN,\n name: 'Editor',\n description: 'Markdown text editor.',\n homePage: 'https://github.com/dxos/dxos/tree/main/packages/apps/plugins/plugin-markdown',\n icon: 'ph--text-aa--regular',\n});\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,kBAAkB;AAEpB,IAAMC,kBAAkB;AAE/B,IAAA,eAAeC,WAAW;EACxBC,IAAIF;EACJG,MAAM;EACNC,aAAa;EACbC,UAAU;EACVC,MAAM;AACR,CAAA;",
|
|
6
|
-
"names": ["pluginMeta", "MARKDOWN_PLUGIN", "pluginMeta", "id", "name", "description", "homePage", "icon"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/MarkdownEditor.tsx", "../../../src/hooks/useSelectCurrentThread.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { openSearchPanel } from '@codemirror/search';\nimport { type EditorView } from '@codemirror/view';\nimport React, { useMemo, useEffect, useCallback } from 'react';\n\nimport {\n type FileInfo,\n LayoutAction,\n type LayoutCoordinate,\n useResolvePlugin,\n parseLayoutPlugin,\n useIntentDispatcher,\n} from '@dxos/app-framework';\nimport { useThemeContext, useTranslation } from '@dxos/react-ui';\nimport { useIsDirectlyAttended } from '@dxos/react-ui-attention';\nimport {\n type Action,\n type DNDOptions,\n type EditorViewMode,\n type EditorInputMode,\n type UseTextEditorProps,\n Toolbar,\n createBasicExtensions,\n createMarkdownExtensions,\n createThemeExtensions,\n dropFile,\n processAction,\n useActionHandler,\n useCommentState,\n useCommentClickListener,\n useFormattingState,\n useTextEditor,\n editorContent,\n editorGutter,\n} from '@dxos/react-ui-editor';\nimport { sectionToolbarLayout } from '@dxos/react-ui-stack';\nimport { textBlockWidth, focusRing, mx } from '@dxos/react-ui-theme';\nimport { isNotFalsy, nonNullable } from '@dxos/util';\n\nimport { useSelectCurrentThread } from '../hooks';\nimport { MARKDOWN_PLUGIN } from '../meta';\nimport { type MarkdownPluginState } from '../types';\n\n// TODO(Zan): Factor into a shared location.\nconst attentionFragment = mx(\n 'group-focus-within/editor:attention-surface group-[[aria-current]]/editor:attention-surface',\n 'group-focus-within/editor:border-separator',\n);\n\nconst DEFAULT_VIEW_MODE: EditorViewMode = 'preview';\n\nexport type MarkdownEditorProps = {\n id: string;\n coordinate?: LayoutCoordinate;\n inputMode?: EditorInputMode;\n role?: string;\n scrollPastEnd?: boolean;\n toolbar?: boolean;\n viewMode?: EditorViewMode;\n onViewModeChange?: (id: string, mode: EditorViewMode) => void;\n onFileUpload?: (file: File) => Promise<FileInfo | undefined>;\n} & Pick<UseTextEditorProps, 'initialValue' | 'scrollTo' | 'selection' | 'extensions'> &\n Partial<Pick<MarkdownPluginState, 'extensionProviders'>>;\n\nexport const MarkdownEditor = ({\n id,\n role = 'article',\n initialValue,\n extensions,\n extensionProviders,\n scrollPastEnd,\n scrollTo,\n selection,\n toolbar,\n viewMode,\n onFileUpload,\n onViewModeChange,\n}: MarkdownEditorProps) => {\n const { t } = useTranslation(MARKDOWN_PLUGIN);\n const { themeMode } = useThemeContext();\n const dispatch = useIntentDispatcher();\n const layoutPlugin = useResolvePlugin(parseLayoutPlugin);\n const [formattingState, formattingObserver] = useFormattingState();\n const isDirectlyAttended = useIsDirectlyAttended(id);\n\n // Extensions from other plugins.\n const providerExtensions = useMemo(\n // TODO(burdon): Must pass object to provider.\n () => extensionProviders?.flatMap((provider) => provider({})).filter(nonNullable),\n [extensionProviders],\n );\n\n // TODO(Zan): Move these into thread plugin as well?\n const [commentsState, commentObserver] = useCommentState();\n const onCommentClick = useCallback(() => {\n void dispatch({ action: LayoutAction.SET_LAYOUT, data: { element: 'complementary', state: true } });\n }, [dispatch]);\n const commentClickObserver = useCommentClickListener(onCommentClick);\n\n // Drag files.\n const handleDrop: DNDOptions['onDrop'] = async (view, { files }) => {\n const file = files[0];\n const info = file && onFileUpload ? await onFileUpload(file) : undefined;\n if (info) {\n processAction(view, { type: 'image', data: info.url });\n }\n };\n\n const {\n parentRef,\n view: editorView,\n focusAttributes,\n } = useTextEditor(\n () => ({\n initialValue,\n extensions: [\n formattingObserver,\n commentObserver,\n commentClickObserver,\n createBasicExtensions({\n readonly: viewMode === 'readonly',\n placeholder: t('editor placeholder'),\n scrollPastEnd: role === 'section' ? false : scrollPastEnd,\n }),\n createMarkdownExtensions({ themeMode }),\n createThemeExtensions({\n themeMode,\n syntaxHighlighting: true,\n slots: { content: { className: editorContent } },\n }),\n editorGutter,\n role !== 'section' && onFileUpload && dropFile({ onDrop: handleDrop }),\n providerExtensions,\n extensions,\n ].filter(isNotFalsy),\n ...(role !== 'section' && {\n id,\n scrollTo,\n selection,\n // TODO(wittjosiah): Autofocus based on layout is racy.\n autoFocus: layoutPlugin?.provides.layout ? layoutPlugin?.provides.layout.scrollIntoView === id : true,\n moveToEndOfLine: true,\n }),\n }),\n [id, initialValue, formattingObserver, viewMode, themeMode, extensions, providerExtensions],\n );\n\n useTest(editorView);\n useSelectCurrentThread(editorView, id);\n\n // Toolbar handler.\n const handleToolbarAction = useActionHandler(editorView);\n const handleAction = (action: Action) => {\n switch (action.type) {\n case 'search': {\n if (editorView) {\n openSearchPanel(editorView);\n }\n return;\n }\n case 'view-mode': {\n onViewModeChange?.(id, action.data);\n return;\n }\n }\n\n handleToolbarAction?.(action);\n };\n\n return (\n <div\n role='none'\n // TODO(burdon): Move role logic out of here (see sheet, table, sketch, etc.)\n {...(role === 'section'\n ? { className: 'flex flex-col' }\n : {\n className: 'contents group/editor',\n ...(isDirectlyAttended && { 'aria-current': 'location' }),\n })}\n >\n {toolbar && (\n <div role='none' className={mx('flex shrink-0 justify-center overflow-x-auto', attentionFragment)}>\n <Toolbar.Root\n classNames={\n role === 'section'\n ? [\n textBlockWidth,\n 'z-[2] group-focus-within/section:visible',\n !isDirectlyAttended && 'invisible',\n sectionToolbarLayout,\n ]\n : [\n textBlockWidth,\n 'group-focus-within/editor:border-separator group-[[aria-current]]/editor:border-separator',\n ]\n }\n state={formattingState && { ...formattingState, ...commentsState }}\n onAction={handleAction}\n >\n <Toolbar.Markdown />\n {onFileUpload && <Toolbar.Custom onUpload={onFileUpload} />}\n <Toolbar.Separator />\n <Toolbar.View mode={viewMode ?? DEFAULT_VIEW_MODE} />\n <Toolbar.Actions />\n </Toolbar.Root>\n </div>\n )}\n <div\n role='none'\n ref={parentRef}\n data-testid='composer.markdownRoot'\n data-toolbar={toolbar ? 'enabled' : 'disabled'}\n className={\n role === 'section'\n ? mx('flex flex-col flex-1 min-bs-[12rem]', focusRing)\n : mx(\n 'flex is-full bs-full overflow-hidden',\n focusRing,\n attentionFragment,\n 'focus-visible:ring-inset',\n 'data-[toolbar=disabled]:pbs-2 data-[toolbar=disabled]:row-span-2',\n )\n }\n {...focusAttributes}\n />\n </div>\n );\n};\n\n// Expose editor view for playwright tests.\n// TODO(wittjosiah): Find a better way to expose this or find a way to limit it to test runs.\nconst useTest = (view?: EditorView) => {\n useEffect(() => {\n const composer = (window as any).composer;\n if (composer) {\n composer.editorView = view;\n }\n }, [view]);\n};\n\nexport default MarkdownEditor;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { EditorView } from '@codemirror/view';\nimport { useCallback } from 'react';\n\nimport { LayoutAction, useIntentResolver } from '@dxos/app-framework';\nimport { Cursor, setSelection } from '@dxos/react-ui-editor';\n\nimport { MARKDOWN_PLUGIN } from '../meta';\n\n/**\n * Handle scrolling and selection of the current thread in a markdown editor.\n */\nexport const useSelectCurrentThread = (editorView: EditorView | undefined, documentId: string) => {\n const handleScrollIntoView = useCallback(\n ({ action, data }: { action: string; data?: any }) => {\n if (action === LayoutAction.SCROLL_INTO_VIEW) {\n if (editorView && data?.id === documentId && data?.cursor) {\n // TODO(burdon): We need typed intents.\n const range = Cursor.getRangeFromCursor(editorView.state, data.cursor);\n if (range) {\n const selection = editorView.state.selection.main.from !== range.from ? { anchor: range.from } : undefined;\n const effects = [\n // NOTE: This does not use the DOM scrollIntoView function.\n EditorView.scrollIntoView(range.from, { y: 'start', yMargin: 96 }),\n ];\n if (selection) {\n // Update the editor selection to get bi-directional highlighting.\n effects.push(setSelection.of({ current: documentId }));\n }\n\n editorView.dispatch({\n effects,\n selection: selection ? { anchor: range.from } : undefined,\n });\n }\n }\n }\n },\n [documentId, editorView],\n );\n\n useIntentResolver(MARKDOWN_PLUGIN, handleScrollIntoView);\n};\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,SAASA,uBAAuB;AAEhC,OAAOC,SAASC,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,GAAGA;MAAiB,GAAGW;IAAc;IACjEyD,UAAUR;KAEV,sBAAA,cAACG,QAAQM,UAAQ,IAAA,GAChBjF,gBAAgB,sBAAA,cAAC2E,QAAQO,QAAM;IAACC,UAAUnF;MAC3C,sBAAA,cAAC2E,QAAQS,WAAS,IAAA,GAClB,sBAAA,cAACT,QAAQU,MAAI;IAACC,MAAMvF,YAAYX;MAChC,sBAAA,cAACuF,QAAQY,SAAO,IAAA,CAAA,CAAA,GAItB,sBAAA,cAACb,OAAAA;IACCnF,MAAK;IACLiG,KAAK3C;IACL4C,eAAY;IACZC,gBAAc5F,UAAU,YAAY;IACpC2D,WACElE,SAAS,YACLJ,GAAG,uCAAuCwG,SAAAA,IAC1CxG,GACE,wCACAwG,WACAzG,mBACA,4BACA,kEAAA;IAGP,GAAG6D;;AAIZ;AAIA,IAAMqB,UAAU,CAAC/B,SAAAA;AACfuD,YAAU,MAAA;AACR,UAAMC,WAAYC,OAAeD;AACjC,QAAIA,UAAU;AACZA,eAAS/C,aAAaT;IACxB;EACF,GAAG;IAACA;GAAK;AACX;AAEA,IAAA,yBAAehD;",
|
|
6
|
-
"names": ["openSearchPanel", "React", "useMemo", "useEffect", "useCallback", "LayoutAction", "useResolvePlugin", "parseLayoutPlugin", "useIntentDispatcher", "useThemeContext", "useTranslation", "useIsDirectlyAttended", "Toolbar", "createBasicExtensions", "createMarkdownExtensions", "createThemeExtensions", "dropFile", "processAction", "useActionHandler", "useCommentState", "useCommentClickListener", "useFormattingState", "useTextEditor", "editorContent", "editorGutter", "sectionToolbarLayout", "textBlockWidth", "focusRing", "mx", "isNotFalsy", "nonNullable", "EditorView", "useCallback", "LayoutAction", "useIntentResolver", "Cursor", "setSelection", "useSelectCurrentThread", "editorView", "documentId", "handleScrollIntoView", "useCallback", "action", "data", "LayoutAction", "SCROLL_INTO_VIEW", "id", "cursor", "range", "Cursor", "getRangeFromCursor", "state", "selection", "main", "from", "anchor", "undefined", "effects", "EditorView", "scrollIntoView", "y", "yMargin", "push", "setSelection", "of", "current", "dispatch", "useIntentResolver", "MARKDOWN_PLUGIN", "attentionFragment", "mx", "DEFAULT_VIEW_MODE", "MarkdownEditor", "id", "role", "initialValue", "extensions", "extensionProviders", "scrollPastEnd", "scrollTo", "selection", "toolbar", "viewMode", "onFileUpload", "onViewModeChange", "t", "useTranslation", "MARKDOWN_PLUGIN", "themeMode", "useThemeContext", "dispatch", "useIntentDispatcher", "layoutPlugin", "useResolvePlugin", "parseLayoutPlugin", "formattingState", "formattingObserver", "useFormattingState", "isDirectlyAttended", "useIsDirectlyAttended", "providerExtensions", "useMemo", "flatMap", "provider", "filter", "nonNullable", "commentsState", "commentObserver", "useCommentState", "onCommentClick", "useCallback", "action", "LayoutAction", "SET_LAYOUT", "data", "element", "state", "commentClickObserver", "useCommentClickListener", "handleDrop", "view", "files", "file", "info", "undefined", "processAction", "type", "url", "parentRef", "editorView", "focusAttributes", "useTextEditor", "createBasicExtensions", "readonly", "placeholder", "createMarkdownExtensions", "createThemeExtensions", "syntaxHighlighting", "slots", "content", "className", "editorContent", "editorGutter", "dropFile", "onDrop", "isNotFalsy", "autoFocus", "provides", "layout", "scrollIntoView", "moveToEndOfLine", "useTest", "useSelectCurrentThread", "handleToolbarAction", "useActionHandler", "handleAction", "openSearchPanel", "div", "Toolbar", "Root", "classNames", "textBlockWidth", "sectionToolbarLayout", "onAction", "Markdown", "Custom", "onUpload", "Separator", "View", "mode", "Actions", "ref", "data-testid", "data-toolbar", "focusRing", "useEffect", "composer", "window"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types/document.ts", "../../../src/types/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { ref, S, TypedObject } from '@dxos/echo-schema';\nimport { ThreadType } from '@dxos/plugin-space/types';\n\nexport class TextType extends TypedObject({ typename: 'dxos.org/type/Text', version: '0.1.0' })({\n content: S.String,\n}) {}\n\nexport class DocumentType extends TypedObject({ typename: 'dxos.org/type/Document', version: '0.1.0' })({\n name: S.optional(S.String),\n fallbackName: S.optional(S.String),\n content: ref(TextType),\n threads: S.mutable(S.Array(ref(ThreadType))),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type {\n GraphBuilderProvides,\n GraphSerializerProvides,\n IntentResolverProvides,\n MetadataRecordsProvides,\n SettingsProvides,\n SurfaceProvides,\n TranslationsProvides,\n} from '@dxos/app-framework';\nimport { type SchemaProvides } from '@dxos/plugin-client';\nimport { type SpaceInitProvides } from '@dxos/plugin-space';\nimport { type Extension, type EditorInputMode, type EditorViewMode } from '@dxos/react-ui-editor';\n\nimport { type DocumentType } from './document';\nimport { MARKDOWN_PLUGIN } from '../meta';\n\nconst MARKDOWN_ACTION = `${MARKDOWN_PLUGIN}/action`;\n\nexport enum MarkdownAction {\n CREATE = `${MARKDOWN_ACTION}/create`,\n SET_VIEW_MODE = `${MARKDOWN_ACTION}/set-view-mode`,\n}\n\nexport type MarkdownProperties = Record<string, any>;\n\nexport type ExtensionsProvider = (props: { document?: DocumentType }) => Extension[] | undefined;\n\nexport type OnChange = (text: string) => void;\n\nexport type MarkdownExtensionProvides = {\n markdown: {\n extensions: ExtensionsProvider;\n };\n};\n\n// TODO(wittjosiah): Factor out to graph plugin?\ntype StackProvides = {\n stack: {\n creators?: Record<string, any>[];\n };\n};\n\nexport type MarkdownPluginState = {\n // Codemirror extensions provided by other plugins.\n extensionProviders: NonNullable<ExtensionsProvider>[];\n\n // TODO(burdon): Extend view mode per document to include scroll position, etc.\n // View mode per document.\n viewMode: Record<string, EditorViewMode>;\n};\n\nexport type MarkdownSettingsProps = {\n defaultViewMode: EditorViewMode;\n editorInputMode?: EditorInputMode;\n experimental?: boolean;\n debug?: boolean;\n toolbar?: boolean;\n typewriter?: string;\n // TODO(burdon): Per document settings.\n numberedHeadings?: boolean;\n folding?: boolean;\n};\n\n// TODO(Zan): Move this to the plugin-space plugin or another common location when we implement comments in sheets.\ntype ThreadProvides<T> = {\n thread: {\n predicate: (obj: any) => obj is T;\n createSort: (obj: T) => (anchorA: string | undefined, anchorB: string | undefined) => number;\n };\n};\n\nexport type MarkdownPluginProvides = SurfaceProvides &\n IntentResolverProvides &\n GraphBuilderProvides &\n GraphSerializerProvides &\n MetadataRecordsProvides &\n SettingsProvides<MarkdownSettingsProps> &\n TranslationsProvides &\n SchemaProvides &\n SpaceInitProvides &\n StackProvides &\n ThreadProvides<DocumentType>;\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,SAASA,KAAKC,GAAGC,mBAAmB;AACpC,SAASC,kBAAkB;AAEpB,IAAMC,WAAN,cAAuBC,YAAY;EAAEC,UAAU;EAAsBC,SAAS;AAAQ,CAAA,EAAG;EAC9FC,SAASC,EAAEC;AACb,CAAA,EAAA;AAAI;AAEG,IAAMC,eAAN,cAA2BN,YAAY;EAAEC,UAAU;EAA0BC,SAAS;AAAQ,CAAA,EAAG;EACtGK,MAAMH,EAAEI,SAASJ,EAAEC,MAAM;EACzBI,cAAcL,EAAEI,SAASJ,EAAEC,MAAM;EACjCF,SAASO,IAAIX,QAAAA;EACbY,SAASP,EAAEQ,QAAQR,EAAES,MAAMH,IAAII,UAAAA,CAAAA,CAAAA;AACjC,CAAA,EAAA;AAAI;;;ACIJ,IAAMC,kBAAkB,GAAGC,eAAAA;;UAEfC,iBAAAA;8CACD,GAAGF,eAAAA,SAAwB,IAAA;qDACpB,GAAGA,eAAAA,gBAA+B,IAAA;GAFxCE,mBAAAA,iBAAAA,CAAAA,EAAAA;",
|
|
6
|
-
"names": ["ref", "S", "TypedObject", "ThreadType", "TextType", "TypedObject", "typename", "version", "content", "S", "String", "DocumentType", "name", "optional", "fallbackName", "ref", "threads", "mutable", "Array", "ThreadType", "MARKDOWN_ACTION", "MARKDOWN_PLUGIN", "MarkdownAction"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["DocumentEditor-YVZTTY5L.cjs"],
|
|
4
|
-
"sourcesContent": ["import {\n DocumentEditor_default\n} from \"./chunk-OEWBZFBF.cjs\";\nimport \"./chunk-MCA5BBJR.cjs\";\nimport \"./chunk-KTYIOXL5.cjs\";\nimport \"./chunk-2T7LIVPT.cjs\";\nimport \"./chunk-LPD4NOTH.cjs\";\nexport {\n DocumentEditor_default as default\n};\n//# sourceMappingURL=DocumentEditor-YVZTTY5L.cjs.map\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAEO;AACP,4BAAO;AACP,4BAAO;AACP,4BAAO;AACP,4BAAO;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["MarkdownEditor-ZD4W4UJ6.cjs"],
|
|
4
|
-
"sourcesContent": ["import {\n MarkdownEditor,\n MarkdownEditor_default\n} from \"./chunk-2T7LIVPT.cjs\";\nimport \"./chunk-LPD4NOTH.cjs\";\nexport {\n MarkdownEditor,\n MarkdownEditor_default as default\n};\n//# sourceMappingURL=MarkdownEditor-ZD4W4UJ6.cjs.map\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAGO;AACP,4BAAO;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/MarkdownEditor.tsx", "../../../src/hooks/useSelectCurrentThread.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { openSearchPanel } from '@codemirror/search';\nimport { type EditorView } from '@codemirror/view';\nimport React, { useMemo, useEffect, useCallback } from 'react';\n\nimport {\n type FileInfo,\n LayoutAction,\n type LayoutCoordinate,\n useResolvePlugin,\n parseLayoutPlugin,\n useIntentDispatcher,\n} from '@dxos/app-framework';\nimport { useThemeContext, useTranslation } from '@dxos/react-ui';\nimport { useIsDirectlyAttended } from '@dxos/react-ui-attention';\nimport {\n type Action,\n type DNDOptions,\n type EditorViewMode,\n type EditorInputMode,\n type UseTextEditorProps,\n Toolbar,\n createBasicExtensions,\n createMarkdownExtensions,\n createThemeExtensions,\n dropFile,\n processAction,\n useActionHandler,\n useCommentState,\n useCommentClickListener,\n useFormattingState,\n useTextEditor,\n editorContent,\n editorGutter,\n} from '@dxos/react-ui-editor';\nimport { sectionToolbarLayout } from '@dxos/react-ui-stack';\nimport { textBlockWidth, focusRing, mx } from '@dxos/react-ui-theme';\nimport { isNotFalsy, nonNullable } from '@dxos/util';\n\nimport { useSelectCurrentThread } from '../hooks';\nimport { MARKDOWN_PLUGIN } from '../meta';\nimport { type MarkdownPluginState } from '../types';\n\n// TODO(Zan): Factor into a shared location.\nconst attentionFragment = mx(\n 'group-focus-within/editor:attention-surface group-[[aria-current]]/editor:attention-surface',\n 'group-focus-within/editor:border-separator',\n);\n\nconst DEFAULT_VIEW_MODE: EditorViewMode = 'preview';\n\nexport type MarkdownEditorProps = {\n id: string;\n coordinate?: LayoutCoordinate;\n inputMode?: EditorInputMode;\n role?: string;\n scrollPastEnd?: boolean;\n toolbar?: boolean;\n viewMode?: EditorViewMode;\n onViewModeChange?: (id: string, mode: EditorViewMode) => void;\n onFileUpload?: (file: File) => Promise<FileInfo | undefined>;\n} & Pick<UseTextEditorProps, 'initialValue' | 'scrollTo' | 'selection' | 'extensions'> &\n Partial<Pick<MarkdownPluginState, 'extensionProviders'>>;\n\nexport const MarkdownEditor = ({\n id,\n role = 'article',\n initialValue,\n extensions,\n extensionProviders,\n scrollPastEnd,\n scrollTo,\n selection,\n toolbar,\n viewMode,\n onFileUpload,\n onViewModeChange,\n}: MarkdownEditorProps) => {\n const { t } = useTranslation(MARKDOWN_PLUGIN);\n const { themeMode } = useThemeContext();\n const dispatch = useIntentDispatcher();\n const layoutPlugin = useResolvePlugin(parseLayoutPlugin);\n const [formattingState, formattingObserver] = useFormattingState();\n const isDirectlyAttended = useIsDirectlyAttended(id);\n\n // Extensions from other plugins.\n const providerExtensions = useMemo(\n // TODO(burdon): Must pass object to provider.\n () => extensionProviders?.flatMap((provider) => provider({})).filter(nonNullable),\n [extensionProviders],\n );\n\n // TODO(Zan): Move these into thread plugin as well?\n const [commentsState, commentObserver] = useCommentState();\n const onCommentClick = useCallback(() => {\n void dispatch({ action: LayoutAction.SET_LAYOUT, data: { element: 'complementary', state: true } });\n }, [dispatch]);\n const commentClickObserver = useCommentClickListener(onCommentClick);\n\n // Drag files.\n const handleDrop: DNDOptions['onDrop'] = async (view, { files }) => {\n const file = files[0];\n const info = file && onFileUpload ? await onFileUpload(file) : undefined;\n if (info) {\n processAction(view, { type: 'image', data: info.url });\n }\n };\n\n const {\n parentRef,\n view: editorView,\n focusAttributes,\n } = useTextEditor(\n () => ({\n initialValue,\n extensions: [\n formattingObserver,\n commentObserver,\n commentClickObserver,\n createBasicExtensions({\n readonly: viewMode === 'readonly',\n placeholder: t('editor placeholder'),\n scrollPastEnd: role === 'section' ? false : scrollPastEnd,\n }),\n createMarkdownExtensions({ themeMode }),\n createThemeExtensions({\n themeMode,\n syntaxHighlighting: true,\n slots: { content: { className: editorContent } },\n }),\n editorGutter,\n role !== 'section' && onFileUpload && dropFile({ onDrop: handleDrop }),\n providerExtensions,\n extensions,\n ].filter(isNotFalsy),\n ...(role !== 'section' && {\n id,\n scrollTo,\n selection,\n // TODO(wittjosiah): Autofocus based on layout is racy.\n autoFocus: layoutPlugin?.provides.layout ? layoutPlugin?.provides.layout.scrollIntoView === id : true,\n moveToEndOfLine: true,\n }),\n }),\n [id, initialValue, formattingObserver, viewMode, themeMode, extensions, providerExtensions],\n );\n\n useTest(editorView);\n useSelectCurrentThread(editorView, id);\n\n // Toolbar handler.\n const handleToolbarAction = useActionHandler(editorView);\n const handleAction = (action: Action) => {\n switch (action.type) {\n case 'search': {\n if (editorView) {\n openSearchPanel(editorView);\n }\n return;\n }\n case 'view-mode': {\n onViewModeChange?.(id, action.data);\n return;\n }\n }\n\n handleToolbarAction?.(action);\n };\n\n return (\n <div\n role='none'\n // TODO(burdon): Move role logic out of here (see sheet, table, sketch, etc.)\n {...(role === 'section'\n ? { className: 'flex flex-col' }\n : {\n className: 'contents group/editor',\n ...(isDirectlyAttended && { 'aria-current': 'location' }),\n })}\n >\n {toolbar && (\n <div role='none' className={mx('flex shrink-0 justify-center overflow-x-auto', attentionFragment)}>\n <Toolbar.Root\n classNames={\n role === 'section'\n ? [\n textBlockWidth,\n 'z-[2] group-focus-within/section:visible',\n !isDirectlyAttended && 'invisible',\n sectionToolbarLayout,\n ]\n : [\n textBlockWidth,\n 'group-focus-within/editor:border-separator group-[[aria-current]]/editor:border-separator',\n ]\n }\n state={formattingState && { ...formattingState, ...commentsState }}\n onAction={handleAction}\n >\n <Toolbar.Markdown />\n {onFileUpload && <Toolbar.Custom onUpload={onFileUpload} />}\n <Toolbar.Separator />\n <Toolbar.View mode={viewMode ?? DEFAULT_VIEW_MODE} />\n <Toolbar.Actions />\n </Toolbar.Root>\n </div>\n )}\n <div\n role='none'\n ref={parentRef}\n data-testid='composer.markdownRoot'\n data-toolbar={toolbar ? 'enabled' : 'disabled'}\n className={\n role === 'section'\n ? mx('flex flex-col flex-1 min-bs-[12rem]', focusRing)\n : mx(\n 'flex is-full bs-full overflow-hidden',\n focusRing,\n attentionFragment,\n 'focus-visible:ring-inset',\n 'data-[toolbar=disabled]:pbs-2 data-[toolbar=disabled]:row-span-2',\n )\n }\n {...focusAttributes}\n />\n </div>\n );\n};\n\n// Expose editor view for playwright tests.\n// TODO(wittjosiah): Find a better way to expose this or find a way to limit it to test runs.\nconst useTest = (view?: EditorView) => {\n useEffect(() => {\n const composer = (window as any).composer;\n if (composer) {\n composer.editorView = view;\n }\n }, [view]);\n};\n\nexport default MarkdownEditor;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { EditorView } from '@codemirror/view';\nimport { useCallback } from 'react';\n\nimport { LayoutAction, useIntentResolver } from '@dxos/app-framework';\nimport { Cursor, setSelection } from '@dxos/react-ui-editor';\n\nimport { MARKDOWN_PLUGIN } from '../meta';\n\n/**\n * Handle scrolling and selection of the current thread in a markdown editor.\n */\nexport const useSelectCurrentThread = (editorView: EditorView | undefined, documentId: string) => {\n const handleScrollIntoView = useCallback(\n ({ action, data }: { action: string; data?: any }) => {\n if (action === LayoutAction.SCROLL_INTO_VIEW) {\n if (editorView && data?.id === documentId && data?.cursor) {\n // TODO(burdon): We need typed intents.\n const range = Cursor.getRangeFromCursor(editorView.state, data.cursor);\n if (range) {\n const selection = editorView.state.selection.main.from !== range.from ? { anchor: range.from } : undefined;\n const effects = [\n // NOTE: This does not use the DOM scrollIntoView function.\n EditorView.scrollIntoView(range.from, { y: 'start', yMargin: 96 }),\n ];\n if (selection) {\n // Update the editor selection to get bi-directional highlighting.\n effects.push(setSelection.of({ current: documentId }));\n }\n\n editorView.dispatch({\n effects,\n selection: selection ? { anchor: range.from } : undefined,\n });\n }\n }\n }\n },\n [documentId, editorView],\n );\n\n useIntentResolver(MARKDOWN_PLUGIN, handleScrollIntoView);\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAAgC;AAEhC,mBAAuD;AAEvD,2BAOO;AACP,sBAAgD;AAChD,gCAAsC;AACtC,6BAmBO;AACP,4BAAqC;AACrC,4BAA8C;AAC9C,kBAAwC;ACpCxC,kBAA2B;AAC3B,IAAAA,gBAA4B;AAE5B,IAAAC,wBAAgD;AAChD,IAAAC,0BAAqC;AAO9B,IAAMC,yBAAyB,CAACC,YAAoCC,eAAAA;AACzE,QAAMC,2BAAuBC,2BAC3B,CAAC,EAAEC,QAAQC,KAAI,MAAkC;AAC/C,QAAID,WAAWE,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AuC4F,+BAAAA,QAC1C5F,0BACE,wCACA4F,iCACA7F,mBACA,4BACA,kEAAA;IAGP,GAAGkD;;AAIZ;AAIA,IAAMoB,UAAU,CAAC5B,SAAAA;AACfoD,8BAAU,MAAA;AACR,UAAMC,WAAYC,OAAeD;AACjC,QAAIA,UAAU;AACZA,eAAS9H,aAAayE;IACxB;EACF,GAAG;IAACA;GAAK;AACX;AAEA,IAAA,yBAAevC;",
|
|
6
|
-
"names": ["import_react", "import_app_framework", "import_react_ui_editor", "useSelectCurrentThread", "editorView", "documentId", "handleScrollIntoView", "useCallback", "action", "data", "LayoutAction", "SCROLL_INTO_VIEW", "id", "cursor", "range", "Cursor", "getRangeFromCursor", "state", "selection", "main", "from", "anchor", "undefined", "effects", "EditorView", "scrollIntoView", "y", "yMargin", "push", "setSelection", "of", "current", "dispatch", "useIntentResolver", "MARKDOWN_PLUGIN", "attentionFragment", "mx", "DEFAULT_VIEW_MODE", "MarkdownEditor", "role", "initialValue", "extensions", "extensionProviders", "scrollPastEnd", "scrollTo", "toolbar", "viewMode", "onFileUpload", "onViewModeChange", "t", "useTranslation", "themeMode", "useThemeContext", "useIntentDispatcher", "layoutPlugin", "useResolvePlugin", "parseLayoutPlugin", "formattingState", "formattingObserver", "useFormattingState", "isDirectlyAttended", "useIsDirectlyAttended", "providerExtensions", "useMemo", "flatMap", "provider", "filter", "nonNullable", "commentsState", "commentObserver", "useCommentState", "onCommentClick", "SET_LAYOUT", "element", "commentClickObserver", "useCommentClickListener", "handleDrop", "view", "files", "file", "info", "processAction", "type", "url", "parentRef", "focusAttributes", "useTextEditor", "createBasicExtensions", "readonly", "placeholder", "createMarkdownExtensions", "createThemeExtensions", "syntaxHighlighting", "slots", "content", "className", "editorContent", "editorGutter", "dropFile", "onDrop", "isNotFalsy", "autoFocus", "provides", "layout", "moveToEndOfLine", "useTest", "handleToolbarAction", "useActionHandler", "handleAction", "openSearchPanel", "React", "div", "Toolbar", "Root", "classNames", "textBlockWidth", "sectionToolbarLayout", "onAction", "Markdown", "Custom", "onUpload", "Separator", "View", "mode", "Actions", "ref", "data-testid", "data-toolbar", "focusRing", "useEffect", "composer", "window"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/meta.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { pluginMeta } from '@dxos/app-framework';\n\nexport const MARKDOWN_PLUGIN = 'dxos.org/plugin/markdown';\n\nexport default pluginMeta({\n id: MARKDOWN_PLUGIN,\n name: 'Editor',\n description: 'Markdown text editor.',\n homePage: 'https://github.com/dxos/dxos/tree/main/packages/apps/plugins/plugin-markdown',\n icon: 'ph--text-aa--regular',\n});\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,2BAA2B;AAEpB,IAAMA,kBAAkB;AAE/B,IAAA,mBAAeC,iCAAW;EACxBC,IAAIF;EACJG,MAAM;EACNC,aAAa;EACbC,UAAU;EACVC,MAAM;AACR,CAAA;",
|
|
6
|
-
"names": ["MARKDOWN_PLUGIN", "pluginMeta", "id", "name", "description", "homePage", "icon"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types/document.ts", "../../../src/types/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { ref, S, TypedObject } from '@dxos/echo-schema';\nimport { ThreadType } from '@dxos/plugin-space/types';\n\nexport class TextType extends TypedObject({ typename: 'dxos.org/type/Text', version: '0.1.0' })({\n content: S.String,\n}) {}\n\nexport class DocumentType extends TypedObject({ typename: 'dxos.org/type/Document', version: '0.1.0' })({\n name: S.optional(S.String),\n fallbackName: S.optional(S.String),\n content: ref(TextType),\n threads: S.mutable(S.Array(ref(ThreadType))),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type {\n GraphBuilderProvides,\n GraphSerializerProvides,\n IntentResolverProvides,\n MetadataRecordsProvides,\n SettingsProvides,\n SurfaceProvides,\n TranslationsProvides,\n} from '@dxos/app-framework';\nimport { type SchemaProvides } from '@dxos/plugin-client';\nimport { type SpaceInitProvides } from '@dxos/plugin-space';\nimport { type Extension, type EditorInputMode, type EditorViewMode } from '@dxos/react-ui-editor';\n\nimport { type DocumentType } from './document';\nimport { MARKDOWN_PLUGIN } from '../meta';\n\nconst MARKDOWN_ACTION = `${MARKDOWN_PLUGIN}/action`;\n\nexport enum MarkdownAction {\n CREATE = `${MARKDOWN_ACTION}/create`,\n SET_VIEW_MODE = `${MARKDOWN_ACTION}/set-view-mode`,\n}\n\nexport type MarkdownProperties = Record<string, any>;\n\nexport type ExtensionsProvider = (props: { document?: DocumentType }) => Extension[] | undefined;\n\nexport type OnChange = (text: string) => void;\n\nexport type MarkdownExtensionProvides = {\n markdown: {\n extensions: ExtensionsProvider;\n };\n};\n\n// TODO(wittjosiah): Factor out to graph plugin?\ntype StackProvides = {\n stack: {\n creators?: Record<string, any>[];\n };\n};\n\nexport type MarkdownPluginState = {\n // Codemirror extensions provided by other plugins.\n extensionProviders: NonNullable<ExtensionsProvider>[];\n\n // TODO(burdon): Extend view mode per document to include scroll position, etc.\n // View mode per document.\n viewMode: Record<string, EditorViewMode>;\n};\n\nexport type MarkdownSettingsProps = {\n defaultViewMode: EditorViewMode;\n editorInputMode?: EditorInputMode;\n experimental?: boolean;\n debug?: boolean;\n toolbar?: boolean;\n typewriter?: string;\n // TODO(burdon): Per document settings.\n numberedHeadings?: boolean;\n folding?: boolean;\n};\n\n// TODO(Zan): Move this to the plugin-space plugin or another common location when we implement comments in sheets.\ntype ThreadProvides<T> = {\n thread: {\n predicate: (obj: any) => obj is T;\n createSort: (obj: T) => (anchorA: string | undefined, anchorB: string | undefined) => number;\n };\n};\n\nexport type MarkdownPluginProvides = SurfaceProvides &\n IntentResolverProvides &\n GraphBuilderProvides &\n GraphSerializerProvides &\n MetadataRecordsProvides &\n SettingsProvides<MarkdownSettingsProps> &\n TranslationsProvides &\n SchemaProvides &\n SpaceInitProvides &\n StackProvides &\n ThreadProvides<DocumentType>;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,yBAAoC;AACpC,mBAA2B;AAEpB,IAAMA,WAAN,kBAAuBC,gCAAY;EAAEC,UAAU;EAAsBC,SAAS;AAAQ,CAAA,EAAG;EAC9FC,SAASC,qBAAEC;AACb,CAAA,EAAA;AAAI;AAEG,IAAMC,eAAN,kBAA2BN,gCAAY;EAAEC,UAAU;EAA0BC,SAAS;AAAQ,CAAA,EAAG;EACtGK,MAAMH,qBAAEI,SAASJ,qBAAEC,MAAM;EACzBI,cAAcL,qBAAEI,SAASJ,qBAAEC,MAAM;EACjCF,aAASO,wBAAIX,QAAAA;EACbY,SAASP,qBAAEQ,QAAQR,qBAAES,UAAMH,wBAAII,uBAAAA,CAAAA,CAAAA;AACjC,CAAA,EAAA;AAAI;ACIJ,IAAMC,kBAAkB,GAAGC,qCAAAA;;UAEfC,iBAAAA;8CACD,GAAGF,eAAAA,SAAwB,IAAA;qDACpB,GAAGA,eAAAA,gBAA+B,IAAA;GAFxCE,mBAAAA,iBAAAA,CAAAA,EAAAA;",
|
|
6
|
-
"names": ["TextType", "TypedObject", "typename", "version", "content", "S", "String", "DocumentType", "name", "optional", "fallbackName", "ref", "threads", "mutable", "Array", "ThreadType", "MARKDOWN_ACTION", "MARKDOWN_PLUGIN", "MarkdownAction"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/DocumentEditor.tsx", "../../../src/util.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useEffect, useMemo } from 'react';\n\nimport { useResolvePlugin, parseFileManagerPlugin, useIntentDispatcher } from '@dxos/app-framework';\nimport { createDocAccessor, fullyQualifiedId, getSpace } from '@dxos/react-client/echo';\nimport { useIdentity } from '@dxos/react-client/halo';\nimport {\n createDataExtensions,\n listener,\n localStorageStateStoreAdapter,\n state,\n type Extension,\n type EditorSelectionState,\n} from '@dxos/react-ui-editor';\n\nimport MarkdownEditor, { type MarkdownEditorProps } from './MarkdownEditor';\nimport { createBaseExtensions } from '../extensions';\nimport { type DocumentType, type MarkdownPluginState, type MarkdownSettingsProps } from '../types';\nimport { getFallbackName, setFallbackName } from '../util';\n\ntype DocumentEditorProps = {\n document: DocumentType;\n settings: MarkdownSettingsProps;\n} & Omit<MarkdownEditorProps, 'id' | 'inputMode' | 'toolbar' | 'extensions'> &\n Pick<MarkdownPluginState, 'extensionProviders'>;\n\n/**\n * Editor for a `DocumentType`.\n */\nconst DocumentEditor = ({\n document: doc,\n extensionProviders = [],\n viewMode,\n settings,\n ...props\n}: DocumentEditorProps) => {\n const space = getSpace(doc);\n const identity = useIdentity();\n const dispatch = useIntentDispatcher();\n\n const baseExtensions = useMemo(() => {\n // TODO(wittjosiah): Autocomplete is not working and this query is causing performance issues.\n // const query = space?.db.query(Filter.schema(DocumentType));\n // query?.subscribe();\n return createBaseExtensions({\n viewMode,\n settings,\n document: doc,\n dispatch,\n // query,\n });\n }, [doc, viewMode, dispatch, settings, settings.folding, settings.numberedHeadings]);\n\n const providerExtensions = useMemo(\n () =>\n extensionProviders.reduce((acc: Extension[], provider) => {\n const provided = typeof provider === 'function' ? provider({ document: doc }) : provider;\n if (provided) {\n acc.push(...provided);\n }\n return acc;\n }, []),\n [extensionProviders],\n );\n\n const extensions = useMemo(\n () => [\n // NOTE: Data extensions must be first so that automerge is updated before other extensions compute their state.\n createDataExtensions({\n id: doc.id,\n text: doc.content && createDocAccessor(doc.content, ['content']),\n space,\n identity,\n }),\n state(localStorageStateStoreAdapter),\n listener({\n onChange: (text) => {\n setFallbackName(doc, text);\n },\n }),\n providerExtensions,\n baseExtensions,\n ],\n [doc, doc.content, space, baseExtensions, providerExtensions, identity],\n );\n\n const initialValue = useMemo(() => doc.content?.content, [doc.content]);\n\n // Migrate gradually to `fallbackName`.\n useEffect(() => {\n if (!doc.fallbackName && doc.content?.content) {\n doc.fallbackName = getFallbackName(doc.content.content);\n }\n }, [doc, doc.content]);\n\n // Restore last selection and scroll point.\n const id = fullyQualifiedId(doc);\n const { scrollTo, selection } = useMemo<EditorSelectionState>(\n () => localStorageStateStoreAdapter.getState(id) ?? {},\n [doc],\n );\n\n const fileManagerPlugin = useResolvePlugin(parseFileManagerPlugin);\n const handleFileUpload = useMemo(() => {\n if (space === undefined) {\n return undefined;\n }\n\n if (fileManagerPlugin?.provides.file.upload === undefined) {\n return undefined;\n }\n\n return async (file: File) => {\n return fileManagerPlugin?.provides?.file?.upload?.(file, space);\n };\n }, [fileManagerPlugin, space]);\n\n return (\n <MarkdownEditor\n id={id}\n initialValue={initialValue}\n extensions={extensions}\n scrollTo={scrollTo}\n selection={selection}\n onFileUpload={handleFileUpload}\n inputMode={settings.editorInputMode}\n toolbar={settings.toolbar}\n viewMode={viewMode}\n {...props}\n />\n );\n};\n\nexport default DocumentEditor;\n\nexport type DocumentEditor = typeof DocumentEditor;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Plugin } from '@dxos/app-framework';\nimport { debounce } from '@dxos/async';\nimport { type TypedObjectSerializer } from '@dxos/plugin-space/types';\nimport { create, createEchoObject, isEchoObject, loadObjectReferences } from '@dxos/react-client/echo';\n\nimport { DocumentType, type MarkdownProperties, type MarkdownExtensionProvides, TextType } from './types';\n\nexport const isMarkdownProperties = (data: unknown): data is MarkdownProperties =>\n isEchoObject(data)\n ? true\n : data && typeof data === 'object'\n ? 'title' in data && typeof data.title === 'string'\n : false;\n\ntype MarkdownExtensionPlugin = Plugin<MarkdownExtensionProvides>;\n\nexport const markdownExtensionPlugins = (plugins: Plugin[]): MarkdownExtensionPlugin[] => {\n return (plugins as MarkdownExtensionPlugin[]).filter((plugin) => Boolean(plugin.provides?.markdown));\n};\n\nconst nonTitleChars = /[^\\w ]/g;\n\nexport const getFallbackName = (content: string) => {\n return content.substring(0, 31).split('\\n')[0].replaceAll(nonTitleChars, '').trim();\n};\n\nexport const setFallbackName = debounce((doc: DocumentType, content: string) => {\n const name = getFallbackName(content);\n if (doc.fallbackName !== name) {\n doc.fallbackName = name;\n }\n}, 200);\n\nexport const serializer: TypedObjectSerializer<DocumentType> = {\n serialize: async ({ object }): Promise<string> => {\n const content = await loadObjectReferences(object, (doc) => doc.content);\n return JSON.stringify({ name: object.name, content: content.content });\n },\n\n deserialize: async ({ content: serialized }) => {\n const { name, content } = JSON.parse(serialized);\n return createEchoObject(create(DocumentType, { name, content: create(TextType, { content }), threads: [] }));\n },\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAA0C;AAE1C,2BAA8E;AAC9E,kBAA8D;AAC9D,kBAA4B;AAC5B,6BAOO;ACXP,mBAAyB;AAEzB,IAAAA,eAA6E;AAItE,IAAMC,uBAAuB,CAACC,aACnCC,2BAAaD,IAAAA,IACT,OACAA,QAAQ,OAAOA,SAAS,WACtB,WAAWA,QAAQ,OAAOA,KAAKE,UAAU,WACzC;AAID,IAAMC,2BAA2B,CAACC,YAAAA;AACvC,SAAQA,QAAsCC,OAAO,CAACC,WAAWC,QAAQD,OAAOE,UAAUC,QAAAA,CAAAA;AAC5F;AAEA,IAAMC,gBAAgB;AAEf,IAAMC,kBAAkB,CAACC,YAAAA;AAC9B,SAAOA,QAAQC,UAAU,GAAG,EAAA,EAAIC,MAAM,IAAA,EAAM,CAAA,EAAGC,WAAWL,eAAe,EAAA,EAAIM,KAAI;AACnF;AAEO,IAAMC,sBAAkBC,uBAAS,CAACC,KAAmBP,YAAAA;AAC1D,QAAMQ,OAAOT,gBAAgBC,OAAAA;AAC7B,MAAIO,IAAIE,iBAAiBD,MAAM;AAC7BD,QAAIE,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names": ["import_echo", "isMarkdownProperties", "data", "isEchoObject", "title", "markdownExtensionPlugins", "plugins", "filter", "plugin", "Boolean", "provides", "markdown", "nonTitleChars", "getFallbackName", "content", "substring", "split", "replaceAll", "trim", "setFallbackName", "debounce", "doc", "name", "fallbackName", "serializer", "serialize", "object", "loadObjectReferences", "JSON", "stringify", "deserialize", "serialized", "parse", "createEchoObject", "create", "DocumentType", "TextType", "threads", "DocumentEditor", "document", "extensionProviders", "viewMode", "settings", "props", "space", "getSpace", "identity", "useIdentity", "dispatch", "useIntentDispatcher", "baseExtensions", "useMemo", "createBaseExtensions", "folding", "numberedHeadings", "providerExtensions", "reduce", "acc", "provider", "provided", "push", "extensions", "createDataExtensions", "id", "text", "createDocAccessor", "state", "localStorageStateStoreAdapter", "listener", "onChange", "initialValue", "useEffect", "fullyQualifiedId", "scrollTo", "selection", "getState", "fileManagerPlugin", "useResolvePlugin", "parseFileManagerPlugin", "handleFileUpload", "undefined", "file", "upload", "React", "MarkdownEditor", "onFileUpload", "inputMode", "editorInputMode", "toolbar"]
|
|
7
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
DocumentCard,
|
|
4
|
-
DocumentCard_default
|
|
5
|
-
} from "./chunk-OE3CMI5X.mjs";
|
|
6
|
-
import "./chunk-RO5FEVW6.mjs";
|
|
7
|
-
import "./chunk-2BGTVWHN.mjs";
|
|
8
|
-
export {
|
|
9
|
-
DocumentCard,
|
|
10
|
-
DocumentCard_default as default
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=DocumentCard-RHVY4Z6L.mjs.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
DocumentEditor_default
|
|
4
|
-
} from "./chunk-UG4MIBCA.mjs";
|
|
5
|
-
import "./chunk-W525OVFX.mjs";
|
|
6
|
-
import "./chunk-RO5FEVW6.mjs";
|
|
7
|
-
import "./chunk-QARGBUBS.mjs";
|
|
8
|
-
import "./chunk-2BGTVWHN.mjs";
|
|
9
|
-
export {
|
|
10
|
-
DocumentEditor_default as default
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=DocumentEditor-JBVVPEYE.mjs.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
MarkdownEditor,
|
|
4
|
-
MarkdownEditor_default
|
|
5
|
-
} from "./chunk-QARGBUBS.mjs";
|
|
6
|
-
import "./chunk-2BGTVWHN.mjs";
|
|
7
|
-
export {
|
|
8
|
-
MarkdownEditor,
|
|
9
|
-
MarkdownEditor_default as default
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=MarkdownEditor-OS7YG6MA.mjs.map
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// packages/plugins/plugin-markdown/src/meta.tsx
|
|
4
|
-
import { pluginMeta } from "@dxos/app-framework";
|
|
5
|
-
var MARKDOWN_PLUGIN = "dxos.org/plugin/markdown";
|
|
6
|
-
var meta_default = pluginMeta({
|
|
7
|
-
id: MARKDOWN_PLUGIN,
|
|
8
|
-
name: "Editor",
|
|
9
|
-
description: "Markdown text editor.",
|
|
10
|
-
homePage: "https://github.com/dxos/dxos/tree/main/packages/apps/plugins/plugin-markdown",
|
|
11
|
-
icon: "ph--text-aa--regular"
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
MARKDOWN_PLUGIN,
|
|
16
|
-
meta_default
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=chunk-2BGTVWHN.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/meta.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { pluginMeta } from '@dxos/app-framework';\n\nexport const MARKDOWN_PLUGIN = 'dxos.org/plugin/markdown';\n\nexport default pluginMeta({\n id: MARKDOWN_PLUGIN,\n name: 'Editor',\n description: 'Markdown text editor.',\n homePage: 'https://github.com/dxos/dxos/tree/main/packages/apps/plugins/plugin-markdown',\n icon: 'ph--text-aa--regular',\n});\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,kBAAkB;AAEpB,IAAMC,kBAAkB;AAE/B,IAAA,eAAeC,WAAW;EACxBC,IAAIF;EACJG,MAAM;EACNC,aAAa;EACbC,UAAU;EACVC,MAAM;AACR,CAAA;",
|
|
6
|
-
"names": ["pluginMeta", "MARKDOWN_PLUGIN", "pluginMeta", "id", "name", "description", "homePage", "icon"]
|
|
7
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
createBaseExtensions
|
|
4
|
-
} from "./chunk-RO5FEVW6.mjs";
|
|
5
|
-
import {
|
|
6
|
-
MARKDOWN_PLUGIN
|
|
7
|
-
} from "./chunk-2BGTVWHN.mjs";
|
|
8
|
-
|
|
9
|
-
// packages/plugins/plugin-markdown/src/components/DocumentCard.tsx
|
|
10
|
-
import React, { forwardRef } from "react";
|
|
11
|
-
import { createDocAccessor } from "@dxos/react-client/echo";
|
|
12
|
-
import { DropdownMenu, Input, useThemeContext, useTranslation } from "@dxos/react-ui";
|
|
13
|
-
import { Card } from "@dxos/react-ui-card";
|
|
14
|
-
import { createBasicExtensions, createDataExtensions, createThemeExtensions, useTextEditor } from "@dxos/react-ui-editor";
|
|
15
|
-
import { focusRing, mx } from "@dxos/react-ui-theme";
|
|
16
|
-
var DocumentCard = /* @__PURE__ */ forwardRef(({ classNames, isDragging, draggableStyle, draggableProps, item: { id, object, color }, grow, settings, onSelect, onAction }, forwardRef2) => {
|
|
17
|
-
const { t } = useTranslation(MARKDOWN_PLUGIN);
|
|
18
|
-
const { themeMode } = useThemeContext();
|
|
19
|
-
const { parentRef, focusAttributes } = useTextEditor(() => ({
|
|
20
|
-
initialValue: object.content?.content,
|
|
21
|
-
extensions: [
|
|
22
|
-
createBasicExtensions({
|
|
23
|
-
placeholder: t("editor placeholder")
|
|
24
|
-
}),
|
|
25
|
-
createThemeExtensions({
|
|
26
|
-
themeMode
|
|
27
|
-
}),
|
|
28
|
-
createDataExtensions({
|
|
29
|
-
id: object.id,
|
|
30
|
-
text: object.content && createDocAccessor(object.content, [
|
|
31
|
-
"content"
|
|
32
|
-
])
|
|
33
|
-
}),
|
|
34
|
-
createBaseExtensions({
|
|
35
|
-
document: object,
|
|
36
|
-
debug: settings.debug,
|
|
37
|
-
experimental: settings.experimental
|
|
38
|
-
})
|
|
39
|
-
]
|
|
40
|
-
}), [
|
|
41
|
-
object,
|
|
42
|
-
object.content,
|
|
43
|
-
themeMode
|
|
44
|
-
]);
|
|
45
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
46
|
-
role: "none",
|
|
47
|
-
ref: forwardRef2,
|
|
48
|
-
className: "flex w-full",
|
|
49
|
-
style: draggableStyle
|
|
50
|
-
}, /* @__PURE__ */ React.createElement(Card.Root, {
|
|
51
|
-
classNames: mx("w-full snap-center", color, isDragging && "opacity-20", classNames),
|
|
52
|
-
grow
|
|
53
|
-
}, /* @__PURE__ */ React.createElement(Card.Header, {
|
|
54
|
-
onDoubleClick: () => onSelect?.()
|
|
55
|
-
}, /* @__PURE__ */ React.createElement(Card.DragHandle, draggableProps), /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
|
|
56
|
-
variant: "subdued",
|
|
57
|
-
classNames: "p-0",
|
|
58
|
-
placeholder: t("document title placeholder"),
|
|
59
|
-
value: object.name,
|
|
60
|
-
onChange: (event) => object.name = event.target.value
|
|
61
|
-
})), /* @__PURE__ */ React.createElement(Card.Menu, null, /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
|
|
62
|
-
onClick: () => onAction?.({
|
|
63
|
-
id,
|
|
64
|
-
action: "delete"
|
|
65
|
-
})
|
|
66
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
67
|
-
className: "grow"
|
|
68
|
-
}, "Delete")), /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
|
|
69
|
-
onClick: () => onAction?.({
|
|
70
|
-
id,
|
|
71
|
-
action: "set-color"
|
|
72
|
-
})
|
|
73
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
74
|
-
className: "grow"
|
|
75
|
-
}, "Change color")))), /* @__PURE__ */ React.createElement(Card.Body, null, /* @__PURE__ */ React.createElement("div", {
|
|
76
|
-
...focusAttributes,
|
|
77
|
-
ref: parentRef,
|
|
78
|
-
className: mx(focusRing, "rounded-sm h-full p-1 text-sm")
|
|
79
|
-
}))));
|
|
80
|
-
});
|
|
81
|
-
var DocumentCard_default = DocumentCard;
|
|
82
|
-
|
|
83
|
-
export {
|
|
84
|
-
DocumentCard,
|
|
85
|
-
DocumentCard_default
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=chunk-OE3CMI5X.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/DocumentCard.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { forwardRef } from 'react';\n\nimport { createDocAccessor } from '@dxos/react-client/echo';\nimport { DropdownMenu, Input, useThemeContext, useTranslation } from '@dxos/react-ui';\nimport { Card } from '@dxos/react-ui-card';\nimport {\n createBasicExtensions,\n createDataExtensions,\n createThemeExtensions,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport type { MosaicTileComponent } from '@dxos/react-ui-mosaic';\nimport { focusRing, mx } from '@dxos/react-ui-theme';\n\nimport { createBaseExtensions } from '../extensions';\nimport { MARKDOWN_PLUGIN } from '../meta';\nimport { type DocumentType, type MarkdownSettingsProps } from '../types';\n\nexport type DocumentItemProps = {\n id: string;\n object: DocumentType;\n color?: string;\n};\n\nexport type DocumentCardProps = {\n settings: MarkdownSettingsProps;\n};\n\n/**\n * @deprecated\n */\n// TODO(wittjosiah): Unify with DocumentEditor.\nexport const DocumentCard: MosaicTileComponent<DocumentItemProps, HTMLDivElement, DocumentCardProps> = forwardRef(\n (\n {\n classNames,\n isDragging,\n draggableStyle,\n draggableProps,\n item: { id, object, color },\n grow,\n settings,\n onSelect,\n onAction,\n },\n forwardRef,\n ) => {\n const { t } = useTranslation(MARKDOWN_PLUGIN);\n const { themeMode } = useThemeContext();\n const { parentRef, focusAttributes } = useTextEditor(\n () => ({\n initialValue: object.content?.content,\n extensions: [\n createBasicExtensions({ placeholder: t('editor placeholder') }),\n createThemeExtensions({ themeMode }),\n createDataExtensions({\n id: object.id,\n text: object.content && createDocAccessor(object.content, ['content']),\n }),\n createBaseExtensions({\n document: object,\n debug: settings.debug,\n experimental: settings.experimental,\n }),\n ],\n }),\n [object, object.content, themeMode],\n );\n\n return (\n <div role='none' ref={forwardRef} className='flex w-full' style={draggableStyle}>\n <Card.Root classNames={mx('w-full snap-center', color, isDragging && 'opacity-20', classNames)} grow={grow}>\n <Card.Header onDoubleClick={() => onSelect?.()}>\n <Card.DragHandle {...draggableProps} />\n <Input.Root>\n <Input.TextInput\n variant='subdued'\n classNames='p-0'\n placeholder={t('document title placeholder')}\n value={object.name}\n onChange={(event) => (object.name = event.target.value)}\n />\n </Input.Root>\n <Card.Menu>\n {/* TODO(burdon): Handle events/intents? */}\n <DropdownMenu.Item onClick={() => onAction?.({ id, action: 'delete' })}>\n <span className='grow'>Delete</span>\n </DropdownMenu.Item>\n <DropdownMenu.Item onClick={() => onAction?.({ id, action: 'set-color' })}>\n <span className='grow'>Change color</span>\n </DropdownMenu.Item>\n </Card.Menu>\n </Card.Header>\n <Card.Body>\n <div {...focusAttributes} ref={parentRef} className={mx(focusRing, 'rounded-sm h-full p-1 text-sm')} />\n </Card.Body>\n </Card.Root>\n </div>\n );\n },\n);\n\nexport default DocumentCard;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAIA,OAAOA,SAASC,kBAAkB;AAElC,SAASC,yBAAyB;AAClC,SAASC,cAAcC,OAAOC,iBAAiBC,sBAAsB;AACrE,SAASC,YAAY;AACrB,SACEC,uBACAC,sBACAC,uBACAC,qBACK;AAEP,SAASC,WAAWC,UAAU;AAoBvB,IAAMC,eAA0FC,2BACrG,CACE,EACEC,YACAC,YACAC,gBACAC,gBACAC,MAAM,EAAEC,IAAIC,QAAQC,MAAK,GACzBC,MACAC,UACAC,UACAC,SAAQ,GAEVZ,gBAAAA;AAEA,QAAM,EAAEa,EAAC,IAAKC,eAAeC,eAAAA;AAC7B,QAAM,EAAEC,UAAS,IAAKC,gBAAAA;AACtB,QAAM,EAAEC,WAAWC,gBAAe,IAAKC,cACrC,OAAO;IACLC,cAAcd,OAAOe,SAASA;IAC9BC,YAAY;MACVC,sBAAsB;QAAEC,aAAaZ,EAAE,oBAAA;MAAsB,CAAA;MAC7Da,sBAAsB;QAAEV;MAAU,CAAA;MAClCW,qBAAqB;QACnBrB,IAAIC,OAAOD;QACXsB,MAAMrB,OAAOe,WAAWO,kBAAkBtB,OAAOe,SAAS;UAAC;SAAU;MACvE,CAAA;MACAQ,qBAAqB;QACnBC,UAAUxB;QACVyB,OAAOtB,SAASsB;QAChBC,cAAcvB,SAASuB;MACzB,CAAA;;EAEJ,IACA;IAAC1B;IAAQA,OAAOe;IAASN;GAAU;AAGrC,SACE,sBAAA,cAACkB,OAAAA;IAAIC,MAAK;IAAOC,KAAKpC;IAAYqC,WAAU;IAAcC,OAAOnC;KAC/D,sBAAA,cAACoC,KAAKC,MAAI;IAACvC,YAAYwC,GAAG,sBAAsBjC,OAAON,cAAc,cAAcD,UAAAA;IAAaQ;KAC9F,sBAAA,cAAC8B,KAAKG,QAAM;IAACC,eAAe,MAAMhC,WAAAA;KAChC,sBAAA,cAAC4B,KAAKK,YAAexC,cAAAA,GACrB,sBAAA,cAACyC,MAAML,MAAI,MACT,sBAAA,cAACK,MAAMC,WAAS;IACdC,SAAQ;IACR9C,YAAW;IACXwB,aAAaZ,EAAE,4BAAA;IACfmC,OAAOzC,OAAO0C;IACdC,UAAU,CAACC,UAAW5C,OAAO0C,OAAOE,MAAMC,OAAOJ;OAGrD,sBAAA,cAACT,KAAKc,MAAI,MAER,sBAAA,cAACC,aAAaC,MAAI;IAACC,SAAS,MAAM5C,WAAW;MAAEN;MAAImD,QAAQ;IAAS,CAAA;KAClE,sBAAA,cAACC,QAAAA;IAAKrB,WAAU;KAAO,QAAA,CAAA,GAEzB,sBAAA,cAACiB,aAAaC,MAAI;IAACC,SAAS,MAAM5C,WAAW;MAAEN;MAAImD,QAAQ;IAAY,CAAA;KACrE,sBAAA,cAACC,QAAAA;IAAKrB,WAAU;KAAO,cAAA,CAAA,CAAA,CAAA,GAI7B,sBAAA,cAACE,KAAKoB,MAAI,MACR,sBAAA,cAACzB,OAAAA;IAAK,GAAGf;IAAiBiB,KAAKlB;IAAWmB,WAAWI,GAAGmB,WAAW,+BAAA;;AAK7E,CAAA;AAGF,IAAA,uBAAe7D;",
|
|
6
|
-
"names": ["React", "forwardRef", "createDocAccessor", "DropdownMenu", "Input", "useThemeContext", "useTranslation", "Card", "createBasicExtensions", "createDataExtensions", "createThemeExtensions", "useTextEditor", "focusRing", "mx", "DocumentCard", "forwardRef", "classNames", "isDragging", "draggableStyle", "draggableProps", "item", "id", "object", "color", "grow", "settings", "onSelect", "onAction", "t", "useTranslation", "MARKDOWN_PLUGIN", "themeMode", "useThemeContext", "parentRef", "focusAttributes", "useTextEditor", "initialValue", "content", "extensions", "createBasicExtensions", "placeholder", "createThemeExtensions", "createDataExtensions", "text", "createDocAccessor", "createBaseExtensions", "document", "debug", "experimental", "div", "role", "ref", "className", "style", "Card", "Root", "mx", "Header", "onDoubleClick", "DragHandle", "Input", "TextInput", "variant", "value", "name", "onChange", "event", "target", "Menu", "DropdownMenu", "Item", "onClick", "action", "span", "Body", "focusRing"]
|
|
7
|
-
}
|