@@ -25,20 +25,16 @@ const { errorLines, joiVersion, language, readOnly } = defineProps({
2525 readOnly: { default: false , type: Boolean },
2626});
2727
28-
2928const data = defineModel ({ default: ' ' , type: String });
3029
31-
3230const { isDark } = useData ();
3331const editorContainer = ref (null );
3432let view = null ;
3533
36-
3734const themeCompartment = new Compartment ();
3835const joiCompartment = new Compartment ();
3936const setErrorLines = StateEffect .define ();
4037
41-
4238const errorLineField = StateField .define ({
4339 create () {
4440 return Decoration .none ;
@@ -62,7 +58,6 @@ const errorLineField = StateField.define({
6258 },
6359});
6460
65-
6661const getThemeExtension = () => {
6762 const theme = isDark .value ? darcula : eclipse;
6863 const cursorTheme = EditorView .theme ({
@@ -76,7 +71,6 @@ const getThemeExtension = () => {
7671 return [theme, cursorTheme];
7772};
7873
79-
8074const getJoiExtension = () => {
8175 if (! joiVersion) {
8276 return [];
@@ -86,13 +80,11 @@ const getJoiExtension = () => {
8680 });
8781};
8882
89-
9083const format = async () => {
9184 if (! view) {
9285 return ;
9386 }
9487
95-
9688 const code = view .state .doc .toString ();
9789 try {
9890 const [prettier , prettierPluginBabel , prettierPluginEstree ] = await Promise .all ([
@@ -101,7 +93,6 @@ const format = async () => {
10193 import (' prettier/plugins/estree' ),
10294 ]);
10395
104-
10596 const formatted = await prettier .format (code, {
10697 parser: language === ' json' ? ' json' : ' babel' ,
10798 plugins: [
@@ -114,7 +105,6 @@ const format = async () => {
114105 trailingComma: ' all' ,
115106 });
116107
117-
118108 if (formatted !== code) {
119109 view .dispatch ({
120110 changes: { from: 0 , insert: formatted, to: view .state .doc .length },
@@ -125,10 +115,8 @@ const format = async () => {
125115 }
126116};
127117
128-
129118defineExpose ({ format });
130119
131-
132120onMounted (() => {
133121 const extensions = [
134122 basicSetup,
@@ -162,7 +150,6 @@ onMounted(() => {
162150 }
163151});
164152
165-
166153watch (data, (newValue ) => {
167154 if (view && newValue !== view .state .doc .toString ()) {
168155 view .dispatch ({
@@ -171,7 +158,6 @@ watch(data, (newValue) => {
171158 }
172159});
173160
174-
175161watch (
176162 () => errorLines,
177163 (newLines ) => {
@@ -184,7 +170,6 @@ watch(
184170 { deep: true },
185171);
186172
187-
188173watch (isDark, () => {
189174 if (view) {
190175 view .dispatch ({
@@ -193,7 +178,6 @@ watch(isDark, () => {
193178 }
194179});
195180
196-
197181watch (
198182 () => joiVersion,
199183 () => {
@@ -205,7 +189,6 @@ watch(
205189 },
206190);
207191
208-
209192onBeforeUnmount (() => {
210193 if (view) {
211194 view .destroy ();
0 commit comments