Skip to content

Commit e0a96fa

Browse files
authored
fix(types): fix circular deps (#1099)
1 parent 1d28791 commit e0a96fa

56 files changed

Lines changed: 412 additions & 411 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/editor/scripts/check-circular-deps.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable no-console, import/no-extraneous-dependencies, no-undef */
1+
/* eslint-disable no-console, no-undef */
22
const process = require('process');
33

44
const {parseDependencyTree, parseCircular, prettyCircular} = require('dpdm');
@@ -9,9 +9,7 @@ if (isNaN(threshold)) {
99
process.exit(1);
1010
}
1111

12-
parseDependencyTree('./src/index.ts', {
13-
transform: true,
14-
}).then((tree) => {
12+
parseDependencyTree('./src/index.ts', {}).then((tree) => {
1513
const circulars = parseCircular(tree);
1614
if (circulars.length > threshold) {
1715
console.error(prettyCircular(circulars));

packages/editor/src/bundle/Editor.ts

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import type {DirectiveSyntaxContext} from '../utils/directive';
2626

2727
import {MarkupManager} from './MarkupManager';
2828
import {createDynamicModifiers} from './config/dynamicModifiers';
29+
import type {ChangeEditorModeOptions, MarkdownEditorInstance} from './editor-public-types';
30+
import type {EventMap, ToolbarActionData} from './events';
2931
import type {
3032
MarkdownEditorMode as EditorMode,
3133
MarkdownEditorPreset as EditorPreset,
@@ -37,23 +39,7 @@ import type {
3739
MarkdownEditorSplitMode as SplitMode,
3840
} from './types';
3941

40-
export type ToolbarActionData = {
41-
editorMode: EditorMode;
42-
id: string;
43-
attrs?: {[key: string]: any};
44-
};
45-
46-
export interface EventMap {
47-
change: null;
48-
cancel: null;
49-
submit: null;
50-
51-
'toolbar-action': ToolbarActionData;
52-
53-
'change-editor-mode': {mode: EditorMode};
54-
'change-toolbar-visibility': {visible: boolean};
55-
'change-split-mode-enabled': {splitModeEnabled: boolean};
56-
}
42+
export type {ToolbarActionData, EventMap, ChangeEditorModeOptions};
5743

5844
// internal events
5945
interface EventMapInt extends EventMap {
@@ -62,18 +48,7 @@ interface EventMapInt extends EventMap {
6248
'cm-scroll': {event: Event};
6349
}
6450

65-
export interface Editor extends Receiver<EventMap>, CommonEditor {
66-
readonly logger: Logger2.LogReceiver;
67-
readonly currentMode: EditorMode;
68-
readonly toolbarVisible: boolean;
69-
70-
setEditorMode(mode: EditorMode, opts?: SetEditorModeOptions): void;
71-
72-
moveCursor(position: 'start' | 'end' | {line: number}): void;
73-
74-
/** @internal used in demo for dev-tools */
75-
readonly _wysiwygView?: PMEditorView;
76-
}
51+
export type Editor = MarkdownEditorInstance;
7752

7853
/** @internal */
7954
export interface EditorInt
@@ -117,12 +92,6 @@ export interface EditorInt
11792

11893
type SetEditorModeOptions = Pick<ChangeEditorModeOptions, 'emit'>;
11994

120-
export type ChangeEditorModeOptions = {
121-
mode: EditorMode;
122-
reason: 'error-boundary' | 'settings' | 'manually';
123-
emit?: boolean;
124-
};
125-
12695
export type EditorOptions = Pick<
12796
MarkdownEditorOptions,
12897
'md' | 'initial' | 'handlers' | 'experimental' | 'markupConfig' | 'wysiwygConfig' | 'mobile'

packages/editor/src/bundle/MarkdownEditorView.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {useMarkdownEditorContext} from './context';
2828
import {cnEditorComponent} from './editor-classname';
2929
import {EditorSettings, type EditorSettingsProps, type SettingItems} from './settings';
3030
import {stickyCn} from './sticky';
31-
import type {MToolbarData, MToolbarItemData, WToolbarData, WToolbarItemData} from './toolbar/types';
31+
import type {ToolbarConfigs} from './toolbar/types';
3232
import {getToolbarsConfigs} from './toolbar/utils/toolbarsConfigs';
3333
import type {MarkdownEditorMode} from './types';
3434

@@ -244,25 +244,6 @@ const EditorWrapper = forwardRef<HTMLDivElement, EditorWrapperProps>(
244244

245245
EditorWrapper.displayName = 'EditorWrapper';
246246

247-
type ToolbarConfigs = {
248-
/**
249-
* @deprecated use `toolbarsPreset` instead
250-
*/
251-
markupToolbarConfig?: MToolbarData;
252-
/**
253-
* @deprecated use `toolbarsPreset` instead
254-
*/
255-
wysiwygToolbarConfig?: WToolbarData;
256-
/**
257-
* @deprecated use `toolbarsPreset` instead
258-
*/
259-
markupHiddenActionsConfig?: MToolbarItemData[];
260-
/**
261-
* @deprecated use `toolbarsPreset` instead
262-
*/
263-
wysiwygHiddenActionsConfig?: WToolbarItemData[];
264-
};
265-
266247
type ViewProps = {
267248
editor?: Editor;
268249
autofocus?: boolean;

packages/editor/src/bundle/config/dynamicModifiers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {ExtensionsManager} from '../../core';
22
import {SchemaDynamicModifier} from '../../core/SchemaDynamicModifier';
33
import {MarkdownParserDynamicModifier} from '../../core/markdown/MarkdownParser';
4-
import {MarkdownSerializerDynamicModifier} from '../../core/markdown/MarkdownSerializerDynamicModifier';
4+
import {MarkdownSerializerDynamicModifier} from '../../core/markdown/MarkdownSerializer';
55
import {convertDynamicModifiersConfigs} from '../../core/utils/dynamicModifiers';
66
import {Logger2} from '../../logger';
77
import {FullSpecsPreset} from '../../presets/full-specs';

packages/editor/src/bundle/config/wysiwyg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
import {i18n as i18nHint} from '../../i18n/hints';
1212
import {i18n} from '../../i18n/menubar';
1313
import {Action as A, formatter as f} from '../../shortcuts';
14+
import type {MarkdownEditorPreset} from '../preset-base-types';
1415
import {ToolbarDataType} from '../toolbar/types';
1516
import type {
1617
WToolbarData,
@@ -26,7 +27,6 @@ import {
2627
WToolbarTextSelect,
2728
type WToolbarTextSelectProps,
2829
} from '../toolbar/wysiwyg/WToolbarTextSelect';
29-
import type {MarkdownEditorPreset} from '../types';
3030

3131
import {ActionName} from './action-names';
3232
import {icons} from './icons';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type {EditorView as PMEditorView} from 'prosemirror-view';
2+
3+
import type {CommonEditor} from '../common';
4+
import type {Logger2} from '../logger';
5+
import type {Receiver} from '../utils';
6+
7+
import type {EventMap} from './events';
8+
import type {MarkdownEditorMode} from './preset-base-types';
9+
10+
export type ChangeEditorModeOptions = {
11+
mode: MarkdownEditorMode;
12+
reason: 'error-boundary' | 'settings' | 'manually';
13+
emit?: boolean;
14+
};
15+
16+
export interface MarkdownEditorInstance extends Receiver<EventMap>, CommonEditor {
17+
readonly logger: Logger2.LogReceiver;
18+
readonly currentMode: MarkdownEditorMode;
19+
readonly toolbarVisible: boolean;
20+
setEditorMode(mode: MarkdownEditorMode, opts?: Pick<ChangeEditorModeOptions, 'emit'>): void;
21+
moveCursor(position: 'start' | 'end' | {line: number}): void;
22+
/** @internal used in demo for dev-tools */
23+
readonly _wysiwygView?: PMEditorView;
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type {MarkdownEditorMode} from './preset-base-types';
2+
3+
export type ToolbarActionData = {
4+
editorMode: MarkdownEditorMode;
5+
id: string;
6+
attrs?: {[key: string]: any};
7+
};
8+
9+
export interface EventMap {
10+
change: null;
11+
cancel: null;
12+
submit: null;
13+
14+
'toolbar-action': ToolbarActionData;
15+
16+
'change-editor-mode': {mode: MarkdownEditorMode};
17+
'change-toolbar-visibility': {visible: boolean};
18+
'change-split-mode-enabled': {splitModeEnabled: boolean};
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export type MarkdownEditorMode = 'wysiwyg' | 'markup';
2+
export type MarkdownEditorPreset = 'zero' | 'commonmark' | 'default' | 'yfm' | 'full';
3+
export type MarkdownEditorSplitMode = false | 'horizontal' | 'vertical';
4+
5+
export type WysiwygPlaceholderOptions = {
6+
value?: string | (() => string);
7+
/**
8+
* Default – empty-doc.
9+
*
10+
* Values:
11+
* - 'empty-doc' – The placeholder will only be shown when the document is completely empty;
12+
* - 'empty-row-top-level' – The placeholder will be displayed in an empty line that is at the top level of the document structure;
13+
* - 'empty-row' – The placeholder will be shown in any empty line within the document, regardless of its nesting level.
14+
*/
15+
behavior?: 'empty-doc' | 'empty-row-top-level' | 'empty-row';
16+
};

packages/editor/src/bundle/toolbar/types.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ActionStorage} from '../../core';
2-
import type {CodeEditor} from '../../markup';
2+
import type {CodeEditor} from '../../markup/editor';
33
import type {ToolbarListButtonData} from '../../toolbar';
44
import type {
55
ToolbarBaseProps,
@@ -35,3 +35,14 @@ export type MToolbarReactComponentData = ToolbarReactComponentData<CodeEditor>;
3535
export type MToolbarListButtonData = ToolbarListButtonData<CodeEditor>;
3636
export type MToolbarListItemData = ToolbarListItemData<CodeEditor>;
3737
export type MToolbarButtonPopupData = ToolbarButtonPopupData<CodeEditor>;
38+
39+
export type ToolbarConfigs = {
40+
/** @deprecated use `toolbarsPreset` instead */
41+
markupToolbarConfig?: MToolbarData;
42+
/** @deprecated use `toolbarsPreset` instead */
43+
wysiwygToolbarConfig?: WToolbarData;
44+
/** @deprecated use `toolbarsPreset` instead */
45+
markupHiddenActionsConfig?: MToolbarItemData[];
46+
/** @deprecated use `toolbarsPreset` instead */
47+
wysiwygHiddenActionsConfig?: WToolbarItemData[];
48+
};

packages/editor/src/bundle/toolbar/utils/toolbarsConfigs.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import type {
66
ToolbarItemWysiwyg,
77
ToolbarsPreset,
88
} from '../../../modules/toolbars/types';
9-
import type {MarkdownEditorViewProps} from '../../MarkdownEditorView';
109
import type {MarkdownEditorPreset} from '../../types';
1110
import {ToolbarDataType} from '../types';
12-
import type {MToolbarData, ToolbarIconData, WToolbarData} from '../types';
11+
import type {MToolbarData, ToolbarConfigs, ToolbarIconData, WToolbarData} from '../types';
1312

1413
import {flattenPreset} from './flattenPreset';
1514

@@ -97,13 +96,7 @@ export const createToolbarConfig = <T extends WToolbarData | MToolbarData>(
9796

9897
interface GetToolbarsConfigsArgs {
9998
toolbarsPreset?: ToolbarsPreset;
100-
props: Pick<
101-
MarkdownEditorViewProps,
102-
| 'markupToolbarConfig'
103-
| 'wysiwygToolbarConfig'
104-
| 'wysiwygHiddenActionsConfig'
105-
| 'markupHiddenActionsConfig'
106-
>;
99+
props: ToolbarConfigs;
107100
preset: MarkdownEditorPreset;
108101
}
109102
export const getToolbarsConfigs = ({toolbarsPreset, props, preset}: GetToolbarsConfigsArgs) => {

0 commit comments

Comments
 (0)