@openmrs/esm-implementer-tools-app 8.0.1-pre.3370 → 8.0.1-pre.3376

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.
@@ -1,13 +1,22 @@
1
1
  import React, { useCallback, useEffect, useState } from 'react';
2
- import { Button } from '@carbon/react';
3
- import { useTranslation } from 'react-i18next';
4
2
  import classNames from 'classnames';
5
3
  import AceEditor from 'react-ace';
6
- import 'ace-builds/src-noconflict/mode-json';
7
- import 'ace-builds/src-noconflict/theme-dracula';
4
+ import { Button } from '@carbon/react';
5
+ import { useTranslation } from 'react-i18next';
8
6
  import { clearConfigErrors, temporaryConfigStore, useStore } from '@openmrs/esm-framework/src/internal';
9
7
  import styles from './json-editor.scss';
10
8
 
9
+ import 'ace-builds/src-noconflict/mode-json';
10
+ import 'ace-builds/src-noconflict/theme-dracula';
11
+ import ace from 'ace-builds/src-noconflict/ace';
12
+
13
+ // Configure ace to bundle workers locally (webpack 5 asset modules)
14
+ // Using new URL() syntax instead of deprecated file-loader or CDN for offline compatibility
15
+ ace.config.setModuleUrl(
16
+ 'ace/mode/json_worker',
17
+ new URL('ace-builds/src-noconflict/worker-json.js', import.meta.url).href,
18
+ );
19
+
11
20
  export interface JsonEditorProps {
12
21
  /** A CSS value */
13
22
  height: string;
@@ -25,17 +34,17 @@ export default function JsonEditor({ height }: JsonEditorProps) {
25
34
  try {
26
35
  config = JSON.parse(editorValue);
27
36
  } catch (e) {
28
- setError(e.message);
37
+ setError(e instanceof Error ? e.message : 'Invalid JSON');
29
38
  return;
30
39
  }
31
40
  setError('');
32
41
  clearConfigErrors();
33
42
  temporaryConfigStore.setState({ config });
34
- }, [editorValue, temporaryConfigStore]);
43
+ }, [editorValue, temporaryConfig.config]);
35
44
 
36
45
  useEffect(() => {
37
46
  if (editorValue != JSON.stringify(temporaryConfig.config, null, 2)) {
38
- setKey((k) => `${k}+`); // just keep appendingplus signs
47
+ setKey((k) => `${k}+`); // just keep appending plus signs
39
48
  }
40
49
  }, [temporaryConfig.config]);
41
50