|
1 | | -import { ToggleInputField } from './ToggleInputField'; |
2 | | -import { InputFieldMarkdownRenderChild, InputFieldMarkdownRenderChildType } from '../InputFieldMarkdownRenderChild'; |
3 | | -import { TextInputField } from './TextInputField'; |
4 | | -import { SliderInputField } from './SliderInputField'; |
5 | | -import { TextAreaInputField } from './TextAreaInputField'; |
6 | | -import { SelectInputField } from './SelectInputField'; |
7 | | -import { MultiSelectInputField } from './MultiSelectInputField'; |
8 | | -import { DateInputField } from './DateInputField'; |
9 | | -import { TimeInputField } from './TimeInputField'; |
10 | | -import { AbstractInputField } from './AbstractInputField'; |
11 | | -import { InputFieldType } from '../parsers/InputFieldDeclarationParser'; |
12 | | -import { DatePickerInputField } from './DatePicker/DatePickerInputField'; |
13 | | -import { NumberInputField } from './NumberInputField'; |
14 | | -import { SuggestInputField } from './Suggest/SuggestInputField'; |
15 | | -import { MetaBindParsingError } from '../utils/MetaBindErrors'; |
16 | | -import { EditorInputField } from './Editor/EditorInputField'; |
17 | | -import { ImageSuggestInputField } from './ImageSuggest/ImageSuggestInputField'; |
| 1 | +import {ToggleInputField} from './ToggleInputField'; |
| 2 | +import {InputFieldMarkdownRenderChild, InputFieldMarkdownRenderChildType} from '../InputFieldMarkdownRenderChild'; |
| 3 | +import {TextInputField} from './TextInputField'; |
| 4 | +import {SliderInputField} from './SliderInputField'; |
| 5 | +import {TextAreaInputField} from './TextAreaInputField'; |
| 6 | +import {SelectInputField} from './SelectInputField'; |
| 7 | +import {MultiSelectInputField} from './MultiSelectInputField'; |
| 8 | +import {DateInputField} from './DateInputField'; |
| 9 | +import {TimeInputField} from './TimeInputField'; |
| 10 | +import {AbstractInputField} from './AbstractInputField'; |
| 11 | +import {InputFieldType} from '../parsers/InputFieldDeclarationParser'; |
| 12 | +import {DatePickerInputField} from './DatePicker/DatePickerInputField'; |
| 13 | +import {NumberInputField} from './NumberInputField'; |
| 14 | +import {SuggestInputField} from './Suggest/SuggestInputField'; |
| 15 | +import {MetaBindParsingError} from '../utils/MetaBindErrors'; |
| 16 | +import {EditorInputField} from './Editor/EditorInputField'; |
| 17 | +import {ImageSuggestInputField} from './ImageSuggest/ImageSuggestInputField'; |
| 18 | +import MetaBindPlugin from '../main'; |
18 | 19 |
|
19 | 20 | export class InputFieldFactory { |
20 | 21 | static allowCodeBlockMap: Record<string, { codeBlock: boolean; inlineCodeBlock: boolean }> = { |
@@ -76,51 +77,46 @@ export class InputFieldFactory { |
76 | 77 | inputFieldType: InputFieldType, |
77 | 78 | args: { type: InputFieldMarkdownRenderChildType; inputFieldMarkdownRenderChild: InputFieldMarkdownRenderChild; onValueChanged: (value: any) => void | Promise<void> } |
78 | 79 | ): AbstractInputField | undefined { |
| 80 | + if (inputFieldType !== InputFieldType.INVALID) { |
| 81 | + InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type, args.inputFieldMarkdownRenderChild.plugin); |
| 82 | + } |
| 83 | + |
79 | 84 | if (inputFieldType === InputFieldType.TOGGLE) { |
80 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
81 | 85 | return new ToggleInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
82 | 86 | } else if (inputFieldType === InputFieldType.SLIDER) { |
83 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
84 | 87 | return new SliderInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
85 | 88 | } else if (inputFieldType === InputFieldType.TEXT) { |
86 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
87 | 89 | return new TextInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
88 | 90 | } else if (inputFieldType === InputFieldType.TEXT_AREA) { |
89 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
90 | 91 | return new TextAreaInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
91 | 92 | } else if (inputFieldType === InputFieldType.SELECT) { |
92 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
93 | 93 | return new SelectInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
94 | 94 | } else if (inputFieldType === InputFieldType.MULTI_SELECT) { |
95 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
96 | 95 | return new MultiSelectInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
97 | 96 | } else if (inputFieldType === InputFieldType.DATE) { |
98 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
99 | 97 | return new DateInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
100 | 98 | } else if (inputFieldType === InputFieldType.TIME) { |
101 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
102 | 99 | return new TimeInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
103 | 100 | } else if (inputFieldType === InputFieldType.DATE_PICKER) { |
104 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
105 | 101 | return new DatePickerInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
106 | 102 | } else if (inputFieldType === InputFieldType.NUMBER) { |
107 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
108 | 103 | return new NumberInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
109 | 104 | } else if (inputFieldType === InputFieldType.SUGGESTER) { |
110 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
111 | 105 | return new SuggestInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
112 | 106 | } else if (inputFieldType === InputFieldType.EDITOR) { |
113 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
114 | 107 | return new EditorInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
115 | 108 | } else if (inputFieldType === InputFieldType.IMAGE_SUGGESTER) { |
116 | | - InputFieldFactory.checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType, args.type); |
117 | 109 | return new ImageSuggestInputField(args.inputFieldMarkdownRenderChild, args.onValueChanged); |
118 | 110 | } |
119 | 111 |
|
120 | 112 | return undefined; |
121 | 113 | } |
122 | 114 |
|
123 | | - static checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType: InputFieldType, type: InputFieldMarkdownRenderChildType): void { |
| 115 | + static checkInputFieldMarkdownRenderChildTypeAllowed(inputFieldType: InputFieldType, type: InputFieldMarkdownRenderChildType, plugin: MetaBindPlugin): void { |
| 116 | + if (plugin.settings.ignoreCodeBlockRestrictions) { |
| 117 | + return; |
| 118 | + } |
| 119 | + |
124 | 120 | const allowCodeBlock: { codeBlock: boolean; inlineCodeBlock: boolean } = InputFieldFactory.allowCodeBlockMap[inputFieldType]; |
125 | 121 | if (type === InputFieldMarkdownRenderChildType.CODE_BLOCK && !allowCodeBlock.codeBlock) { |
126 | 122 | throw new MetaBindParsingError(`'${inputFieldType}' is not allowed as code block`); |
|
0 commit comments