diff --git a/README.md b/README.md index 27ccc75c..d7b603de 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,7 @@ const editor = new JSONEditor({ - `editor.expand(path => path.length < 2)` expand all paths up to 2 levels deep - `transform({ id?: string, selectedPath?: [], onTransform?: ({ operations: JSONPatchDocument, json: JSON, transformedJson: JSON }) => 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. - `scrollTo(path: Path)` Scroll the editor vertically such that the specified path comes into view. The path will be expanded when needed. +- `findElement(path: Path)` Find the DOM element of a given path. Returns `undefined` when not found - `acceptAutoRepair(): 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 code mode or when the editor is not in an "accept auto repair" status, nothing will happen, and the contents will be returned as is. - `focus()`. Give the editor focus. - `destroy()`. Destroy the editor, remove it from the DOM. diff --git a/src/lib/components/modes/treemode/TreeMode.svelte b/src/lib/components/modes/treemode/TreeMode.svelte index 97b9a0ff..cd87c828 100644 --- a/src/lib/components/modes/treemode/TreeMode.svelte +++ b/src/lib/components/modes/treemode/TreeMode.svelte @@ -1344,8 +1344,9 @@ /** * Find the DOM element of a given path. * Note that the path can only be found when the node is expanded. + * @param {Path} path */ - function findElement(path) { + export function findElement(path) { return refContents ? refContents.querySelector(`div[data-path="${encodeDataPath(path)}"]`) : undefined