Skip to content

Commit dc4671a

Browse files
authoredDec 15, 2023
feat: change the type of json from JSONValue to unknown (#371)
BREAKING CHANGE: The type `Content` is changed from `{ json: JSONValue} | { text: string }` into `{ json: unknown } | { text: string }`, and all other types having `JSONValue` changed to `unknown`. The return type of `JSONParser.stringify` changed from `string` to `string | undefined`.
1 parent 0d59366 commit dc4671a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+414
-486
lines changed
 

‎README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Or one-way binding:
9090
}
9191
9292
function handleChange(updatedContent, previousContent, { contentErrors, patchResult }) {
93-
// content is an object { json: JSONValue } | { text: string }
93+
// content is an object { json: unknown } | { text: string }
9494
console.log('onChange: ', { updatedContent, previousContent, contentErrors, patchResult })
9595
content = updatedContent
9696
}
@@ -151,7 +151,7 @@ Browser example loading the standalone ES module:
151151
props: {
152152
content,
153153
onChange: (updatedContent, previousContent, { contentErrors, patchResult }) => {
154-
// content is an object { json: JSONValue } | { text: string }
154+
// content is an object { json: unknown } | { text: string }
155155
console.log('onChange', { updatedContent, previousContent, contentErrors, patchResult })
156156
content = updatedContent
157157
}
@@ -203,7 +203,7 @@ const editor = new JSONEditor({
203203
props: {
204204
content,
205205
onChange: (updatedContent, previousContent, { contentErrors, patchResult }) => {
206-
// content is an object { json: JSONValue } | { text: string }
206+
// content is an object { json: unknown } | { text: string }
207207
console.log('onChange', { updatedContent, previousContent, contentErrors, patchResult })
208208
}
209209
}
@@ -225,7 +225,7 @@ const editor = new JSONEditor({
225225
- `escapeControlCharacters: boolean`. False by default. When `true`, control characters like newline and tab are rendered as escaped characters `\n` and `\t`. Only applicable for `'tree'` mode, in `'text'` mode control characters are always escaped.
226226
- `escapeUnicodeCharacters: boolean`. False by default. When `true`, unicode characters like ☎ and 😀 are rendered escaped like `\u260e` and `\ud83d\ude00`.
227227
- `flattenColumns: boolean`. True by default. Only applicable to `'table'` mode. When `true`, nested object properties will be displayed each in their own column, with the nested path as column name. When `false`, nested objects will be rendered inline, and double-clicking them will open them in a popup.
228-
- `validator: function (json: JSONValue): ValidationError[]`. Validate the JSON document.
228+
- `validator: function (json: unknown): ValidationError[]`. Validate the JSON document.
229229
For example use the built-in JSON Schema validator powered by Ajv:
230230

231231
```js
@@ -438,7 +438,7 @@ Note that most methods are asynchronous and will resolve after the editor is re-
438438
- `editor.expand(path => true)` expand all
439439
- `editor.expand(path => false)` collapse all
440440
- `editor.expand(path => path.length < 2)` expand all paths up to 2 levels deep
441-
- `transform({ id?: string, rootPath?: [], onTransform: ({ operations: JSONPatchDocument, json: JSONValue, transformedJson: JSONValue }) => void, onClose: () => void })` programmatically trigger clicking of the transform button in the main menu, opening the transform model. If a callback `onTransform` is provided, it will replace the build-in logic to apply a transform, allowing you to process the transform operations in an alternative way. If provided, `onClose` callback will trigger when the transform modal closes, both after the user clicked apply or cancel. If an `id` is provided, the transform modal will load the previous status of this `id` instead of the status of the editors transform modal.
441+
- `transform({ id?: string, rootPath?: [], onTransform: ({ operations: JSONPatchDocument, json: unknown, transformedJson: unknown }) => void, onClose: () => void })` programmatically trigger clicking of the transform button in the main menu, opening the transform model. If a callback `onTransform` is provided, it will replace the build-in logic to apply a transform, allowing you to process the transform operations in an alternative way. If provided, `onClose` callback will trigger when the transform modal closes, both after the user clicked apply or cancel. If an `id` is provided, the transform modal will load the previous status of this `id` instead of the status of the editors transform modal.
442442
- `scrollTo(path: Path): Promise<void>` Scroll the editor vertically such that the specified path comes into view. Only applicable to modes `tree` and `table`. The path will be expanded when needed. The returned Promise is resolved after scrolling is finished.
443443
- `findElement(path: Path)` Find the DOM element of a given path. Returns `null` when not found.
444444
- `acceptAutoRepair(): Promise<Content>` In tree mode, invalid JSON is automatically repaired when loaded. When the repair was successful, the repaired contents are rendered but not yet applied to the document itself until the user clicks "Ok" or starts editing the data. Instead of accepting the repair, the user can also click "Repair manually instead". Invoking `.acceptAutoRepair()` will programmatically accept the repair. This will trigger an update, and the method itself also returns the updated contents. In case of `text` mode or when the editor is not in an "accept auto repair" status, nothing will happen, and the contents will be returned as is.

‎package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.