mirror of
https://github.com/maputnik/editor.git
synced 2026-09-02 02:17:26 +00:00
1730e9cb1c
## Launch Checklist - Resolves #891 This PR upgrades code mirror from version 5 to version 6. It should not change any functionality dramatically. The filter and other expressions have line numbers now as I was not able to remove those without introducing a lot of code, which I preferred not to. Before: <img width="571" height="933" alt="image" src="https://github.com/user-attachments/assets/02f047ee-0857-4eb1-9431-2620099ea025" /> After: <img width="571" height="933" alt="image" src="https://github.com/user-attachments/assets/7cf60155-7cd9-4c06-915e-dec2ae8247fc" /> - [x] Briefly describe the changes in this PR. - [x] Link to related issues. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality. - [x] Add an entry to `CHANGELOG.md` under the `## main` section. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
26 lines
714 B
TypeScript
26 lines
714 B
TypeScript
import { type PropertyNode, type ValueNode } from "json-to-ast";
|
|
|
|
export function jsonPathToPosition(path: string[], node: ValueNode | PropertyNode | undefined,) {
|
|
if (!node) {
|
|
return undefined;
|
|
}
|
|
if (path.length < 1) {
|
|
return node;
|
|
}
|
|
if (!("children" in node)) {
|
|
return undefined;
|
|
}
|
|
const key = path[0];
|
|
if (key.match(/^[0-9]+$/)) {
|
|
return jsonPathToPosition(path.slice(1), node.children[+path[0]]);
|
|
}
|
|
const newNode = node.children.find((childNode) => {
|
|
return (
|
|
"key" in childNode &&
|
|
childNode.key.type === "Identifier" &&
|
|
childNode.key.value === key
|
|
);
|
|
}) as PropertyNode | undefined;
|
|
return jsonPathToPosition(path.slice(1), newNode?.value);
|
|
}
|