|
1 | 1 | import { type EditorSelection, type EditorState } from '@codemirror/state'; |
2 | | -import type MetaBindPlugin from '../main'; |
3 | | -import { type Component, editorInfoField, type TFile } from 'obsidian'; |
4 | | -import { ErrorLevel, MetaBindInternalError } from '../utils/errors/MetaBindErrors'; |
5 | | -import { InputFieldWidget, type MarkdownRenderChildWidget, MBWidgetType, ViewFieldWidget } from './Cm6_Widgets'; |
| 2 | +import { editorInfoField, type TFile } from 'obsidian'; |
6 | 3 | import { type DecorationSet, type EditorView } from '@codemirror/view'; |
7 | | -import { type AbstractMDRC } from '../renderChildren/AbstractMDRC'; |
8 | 4 |
|
9 | 5 | export class Cm6_Util { |
10 | 6 | /** |
@@ -39,84 +35,6 @@ export class Cm6_Util { |
39 | 35 | return state.sliceDoc(from, to); |
40 | 36 | } |
41 | 37 |
|
42 | | - /** |
43 | | - * Creates a MDRC widget from a given widget type. |
44 | | - * |
45 | | - * @param widgetType |
46 | | - * @param content |
47 | | - * @param filePath |
48 | | - * @param component |
49 | | - * @param plugin |
50 | | - */ |
51 | | - static constructMarkdownRenderChildWidget( |
52 | | - widgetType: MBWidgetType, |
53 | | - content: string, |
54 | | - filePath: string, |
55 | | - component: Component, |
56 | | - plugin: MetaBindPlugin, |
57 | | - ): MarkdownRenderChildWidget<AbstractMDRC> | undefined { |
58 | | - if (widgetType === MBWidgetType.INPUT_FIELD_WIDGET) { |
59 | | - return new InputFieldWidget(content, filePath, component, plugin); |
60 | | - } else if (widgetType === MBWidgetType.VIEW_FIELD_WIDGET) { |
61 | | - return new ViewFieldWidget(content, filePath, component, plugin); |
62 | | - } |
63 | | - |
64 | | - return undefined; |
65 | | - } |
66 | | - |
67 | | - /** |
68 | | - * Gets the prefix of a given widget type. (e.g. INPUT or VIEW) |
69 | | - * |
70 | | - * @param widgetType |
71 | | - */ |
72 | | - static getDeclarationPrefix(widgetType: MBWidgetType): string { |
73 | | - if (widgetType === MBWidgetType.INPUT_FIELD_WIDGET) { |
74 | | - return 'INPUT'; |
75 | | - } else if (widgetType === MBWidgetType.VIEW_FIELD_WIDGET) { |
76 | | - return 'VIEW'; |
77 | | - } |
78 | | - |
79 | | - throw new MetaBindInternalError({ |
80 | | - errorLevel: ErrorLevel.CRITICAL, |
81 | | - effect: 'failed to get declaration prefix', |
82 | | - cause: `Invalid widget type "${widgetType}"`, |
83 | | - }); |
84 | | - } |
85 | | - |
86 | | - /** |
87 | | - * Checks if a string is a declaration of a given widget type. |
88 | | - * |
89 | | - * @param widgetType |
90 | | - * @param str |
91 | | - */ |
92 | | - static isDeclaration(widgetType: MBWidgetType, str: string): boolean { |
93 | | - const startStr: string = Cm6_Util.getDeclarationPrefix(widgetType) + '['; |
94 | | - const endStr: string = ']'; |
95 | | - |
96 | | - return str.startsWith(startStr) && str.endsWith(endStr); |
97 | | - } |
98 | | - |
99 | | - /** |
100 | | - * Checks if a string is any declaration and if yes returns the widget type. |
101 | | - * This does not use {@link isDeclaration} because of performance reasons. |
102 | | - * |
103 | | - * @param str |
104 | | - */ |
105 | | - static isDeclarationAndGetWidgetType(str: string): MBWidgetType | undefined { |
106 | | - if (!str.endsWith(']')) { |
107 | | - return undefined; |
108 | | - } |
109 | | - |
110 | | - for (const widgetType of Object.values(MBWidgetType)) { |
111 | | - const startStr: string = Cm6_Util.getDeclarationPrefix(widgetType) + '['; |
112 | | - if (str.startsWith(startStr)) { |
113 | | - return widgetType; |
114 | | - } |
115 | | - } |
116 | | - |
117 | | - return undefined; |
118 | | - } |
119 | | - |
120 | 38 | /** |
121 | 39 | * Gets the current file of an editor. |
122 | 40 | * |
|
0 commit comments