Skip to content

Commit

Permalink
feat: expose method findElement(path)
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Apr 21, 2022
1 parent 6a86ccb commit 655a790
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/modes/treemode/TreeMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 655a790

Please sign in to comment.