@xh/hoist 79.0.0-SNAPSHOT.1765828263630 → 79.0.0-SNAPSHOT.1765828486265

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.
@@ -4,27 +4,15 @@
4
4
  *
5
5
  * Copyright © 2025 Extremely Heavy Industries Inc.
6
6
  */
7
- import {hoistCmp, PlainObject} from '@xh/hoist/core';
7
+ import {hoistCmp} from '@xh/hoist/core';
8
8
  import '@xh/hoist/desktop/register';
9
9
  import {fmtJson} from '@xh/hoist/format';
10
- import Ajv, {Options, SchemaObject, ValidateFunction} from 'ajv';
10
+ import * as codemirror from 'codemirror';
11
+ import 'codemirror/mode/javascript/javascript';
11
12
  import {codeInput, CodeInputProps} from './CodeInput';
12
- import {jsonlint} from './impl/jsonlint.js';
13
+ import {jsonlint} from './impl/jsonlint';
13
14
 
14
- export interface JsonInputProps extends CodeInputProps {
15
- /**
16
- * JSON Schema object used to validate the input JSON. Accepts any valid JSON Schema keywords
17
- * supported by AJV, such as `type`, `properties`, `required`, and `additionalProperties`.
18
- * @see https://ajv.js.org/json-schema.html
19
- */
20
- jsonSchema?: SchemaObject;
21
-
22
- /**
23
- * Configuration object with any properties supported by the AJV API.
24
- * @see {@link https://ajv.js.org/options.html}
25
- */
26
- ajvProps?: Options;
27
- }
15
+ export type JsonInputProps = CodeInputProps;
28
16
 
29
17
  /**
30
18
  * Code-editor style input for editing and validating JSON, powered by CodeMirror.
@@ -33,13 +21,11 @@ export const [JsonInput, jsonInput] = hoistCmp.withFactory<JsonInputProps>({
33
21
  displayName: 'JsonInput',
34
22
  className: 'xh-json-input',
35
23
  render(props, ref) {
36
- const {jsonSchema, ajvProps, ...rest} = props;
37
-
38
24
  return codeInput({
39
- linter: jsonLinterWrapper(jsonSchema, ajvProps),
25
+ linter: linter,
40
26
  formatter: fmtJson,
41
- language: 'json',
42
- ...rest,
27
+ mode: 'application/json',
28
+ ...props,
43
29
  ref
44
30
  });
45
31
  }
@@ -47,114 +33,24 @@ export const [JsonInput, jsonInput] = hoistCmp.withFactory<JsonInputProps>({
47
33
  (JsonInput as any).hasLayoutSupport = true;
48
34
 
49
35
  //----------------------
50
- // JSON Linter helper
51
- //----------------------
52
- function jsonLinterWrapper(jsonSchema?: PlainObject, ajvProps?: Options) {
53
- // No schema → only use JSONLint
54
- if (!jsonSchema) return jsonLintOnly;
55
-
56
- const ajv = new Ajv({...ajvProps}),
57
- validate = ajv.compile(jsonSchema);
58
-
59
- return (text: string) => {
60
- const annotations: any[] = [];
61
-
62
- if (!text.trim()) return annotations;
63
-
64
- runJsonLint(text, annotations);
65
- if (annotations.length) return annotations;
66
-
67
- runAjvValidation(text, validate, annotations);
68
-
69
- return annotations;
70
- };
71
- }
72
-
73
- /** Run JSONLint and append errors to annotations */
74
- function runJsonLint(text: string, annotations: any[]) {
75
- jsonlint.parseError = (message, hash) => {
76
- const {first_line, first_column, last_line, last_column} = hash.loc;
77
- annotations.push({
78
- from: indexFromLineCol(text, first_line, first_column),
79
- to: indexFromLineCol(text, last_line, last_column),
80
- message,
81
- severity: 'error'
36
+ // Implementation
37
+ //-----------------------
38
+ function linter(text: string) {
39
+ const errors = [];
40
+ if (!text) return errors;
41
+
42
+ jsonlint.parseError = function (str, hash) {
43
+ const loc = hash.loc;
44
+ errors.push({
45
+ from: codemirror.Pos(loc.first_line - 1, loc.first_column),
46
+ to: codemirror.Pos(loc.last_line - 1, loc.last_column),
47
+ message: str
82
48
  });
83
49
  };
84
50
 
85
51
  try {
86
52
  jsonlint.parse(text);
87
- } catch {
88
- // intentionally ignored: parseError handles reporting
89
- }
90
- }
91
-
92
- /** Run AJV schema validation and append errors to annotations */
93
- function runAjvValidation(text: string, validate: ValidateFunction, annotations: any[]) {
94
- let data: any;
95
- try {
96
- data = JSON.parse(text);
97
- } catch {
98
- return;
99
- }
100
-
101
- const valid = validate(data);
102
- if (valid || !validate.errors) return;
103
-
104
- validate.errors.forEach(err => {
105
- const {from, to} = getErrorPosition(err, text),
106
- message = formatAjvMessage(err);
107
-
108
- annotations.push({from, to, message, severity: 'error'});
109
- });
110
- }
111
-
112
- /** Determine text positions for AJV error highlighting */
113
- function getErrorPosition(err: any, text: string): {from: number; to: number} {
114
- let from = 0,
115
- to = 0,
116
- key: string;
117
-
118
- if (err.keyword === 'additionalProperties' && err.params?.additionalProperty) {
119
- key = err.params.additionalProperty;
120
- } else {
121
- const parts = (err.instancePath || '').split('/').filter(Boolean);
122
- key = parts[parts.length - 1];
123
- }
124
-
125
- if (key) {
126
- const idx = text.indexOf(`"${key}"`);
127
- if (idx >= 0) {
128
- from = idx;
129
- to = idx + key.length + 2;
130
- }
131
- }
132
-
133
- return {from, to};
134
- }
135
-
136
- /** Format AJV error messages nicely */
137
- function formatAjvMessage(err: any): string {
138
- const path = err.instancePath || '(root)';
139
- if (err.keyword === 'additionalProperties' && err.params?.additionalProperty) {
140
- return `Unexpected property "${err.params.additionalProperty}"`;
141
- }
142
- return `${path} ${err.message}`;
143
- }
144
-
145
- /** JSONLint-only linter (used when no jsonSchema prop) */
146
- function jsonLintOnly(text: string) {
147
- const annotations: any[] = [];
148
- if (!text) return annotations;
149
-
150
- runJsonLint(text, annotations);
151
- return annotations;
152
- }
53
+ } catch (ignored) {}
153
54
 
154
- /** Convert line/col to string index */
155
- function indexFromLineCol(text: string, line: number, col: number): number {
156
- const lines = text.split('\n');
157
- let idx = 0;
158
- for (let i = 0; i < line - 1; i++) idx += lines[i].length + 1;
159
- return idx + col;
55
+ return errors;
160
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "79.0.0-SNAPSHOT.1765828263630",
3
+ "version": "79.0.0-SNAPSHOT.1765828486265",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",
@@ -33,17 +33,6 @@
33
33
  "@blueprintjs/core": "^5.10.5",
34
34
  "@blueprintjs/datetime": "^5.3.7",
35
35
  "@blueprintjs/datetime2": "^2.3.7",
36
- "@codemirror/commands": "6.9.0",
37
- "@codemirror/lang-css": "^6.2.0",
38
- "@codemirror/lang-html": "^6.2.0",
39
- "@codemirror/lang-javascript": "^6.2.4",
40
- "@codemirror/lang-json": "^6.0.1",
41
- "@codemirror/lang-python": "^6.2.0",
42
- "@codemirror/lang-sql": "^6.2.0",
43
- "@codemirror/language": "6.11.3",
44
- "@codemirror/lint": "6.9.0",
45
- "@codemirror/search": "6.5.11",
46
- "@codemirror/view": "6.38.6",
47
36
  "@fortawesome/fontawesome-pro": "^6.6.0",
48
37
  "@fortawesome/fontawesome-svg-core": "^6.6.0",
49
38
  "@fortawesome/pro-light-svg-icons": "^6.6.0",
@@ -54,10 +43,9 @@
54
43
  "@onsenui/fastclick": "~1.1.1",
55
44
  "@popperjs/core": "~2.11.0",
56
45
  "@seznam/compose-react-refs": "~1.0.5",
57
- "ajv": "~8.17.1",
58
46
  "classnames": "~2.5.1",
59
47
  "clipboard-copy": "~4.0.1",
60
- "codemirror": "~6.0.2",
48
+ "codemirror": "~5.65.0",
61
49
  "core-js": "3.x",
62
50
  "debounce-promise": "~3.1.0",
63
51
  "dompurify": "~3.3.0",