@visual-json/core 0.1.1 → 0.3.0

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.
package/README.md CHANGED
@@ -80,6 +80,14 @@ All operations return a new `TreeState` with structural sharing.
80
80
  <td><code>addProperty(state, parentId, key, value)</code></td>
81
81
  <td>Add a child to an object or array</td>
82
82
  </tr>
83
+ <tr>
84
+ <td><code>insertProperty(state, parentId, key, value, index)</code></td>
85
+ <td>Insert a child at a specific index</td>
86
+ </tr>
87
+ <tr>
88
+ <td><code>insertNode(state, parentId, node, index)</code></td>
89
+ <td>Insert an existing node subtree at a specific index, preserving IDs</td>
90
+ </tr>
83
91
  <tr>
84
92
  <td><code>removeNode(state, nodeId)</code></td>
85
93
  <td>Remove a node</td>
@@ -92,6 +100,10 @@ All operations return a new `TreeState` with structural sharing.
92
100
  <td><code>reorderChildren(state, parentId, from, to)</code></td>
93
101
  <td>Reorder children within a parent</td>
94
102
  </tr>
103
+ <tr>
104
+ <td><code>reorderChildrenMulti(state, parentId, movedIds, targetSiblingId, position)</code></td>
105
+ <td>Reorder multiple children relative to a sibling</td>
106
+ </tr>
95
107
  <tr>
96
108
  <td><code>changeType(state, nodeId, newType)</code></td>
97
109
  <td>Convert a node to a different type</td>
package/dist/index.d.mts CHANGED
@@ -70,15 +70,30 @@ declare function getNodeType(value: JsonValue): NodeType;
70
70
  declare function buildSubtree(key: string, value: JsonValue, parentPath: string, parentId: string | null, nodesById: Map<string, TreeNode>): TreeNode;
71
71
  declare function fromJson(value: JsonValue): TreeState;
72
72
  declare function toJson(node: TreeNode): JsonValue;
73
+ /**
74
+ * Clone a subtree with updated key, path, and parentId while preserving
75
+ * all original node IDs. Used for cross-parent moves where identity must
76
+ * be retained so that UI state (expanded, selected, etc.) stays valid.
77
+ */
78
+ declare function reparentSubtree(node: TreeNode, newKey: string, parentPath: string, newParentId: string): TreeNode;
73
79
  declare function findNode(state: TreeState, nodeId: string): TreeNode | undefined;
74
80
  declare function findNodeByPath(state: TreeState, path: string): TreeNode | undefined;
81
+ /**
82
+ * Check whether `nodeId` is a descendant of `potentialAncestorId` by walking
83
+ * up `parentId` links. Returns `true` when the two IDs are equal (a node is
84
+ * considered a descendant of itself).
85
+ */
86
+ declare function isDescendant(tree: TreeState, nodeId: string, potentialAncestorId: string): boolean;
75
87
 
76
88
  declare function setValue(state: TreeState, nodeId: string, value: JsonValue): TreeState;
77
89
  declare function setKey(state: TreeState, nodeId: string, newKey: string): TreeState;
78
90
  declare function addProperty(state: TreeState, parentId: string, key: string, value: JsonValue): TreeState;
91
+ declare function insertProperty(state: TreeState, parentId: string, key: string, value: JsonValue, index: number): TreeState;
92
+ declare function insertNode(state: TreeState, parentId: string, node: TreeNode, index: number): TreeState;
79
93
  declare function removeNode(state: TreeState, nodeId: string): TreeState;
80
94
  declare function moveNode(state: TreeState, nodeId: string, newParentId: string, index?: number): TreeState;
81
95
  declare function reorderChildren(state: TreeState, parentId: string, fromIndex: number, toIndex: number): TreeState;
96
+ declare function reorderChildrenMulti(state: TreeState, parentId: string, movedIds: string[], targetSiblingId: string, position: "before" | "after"): TreeState;
82
97
  declare function changeType(state: TreeState, nodeId: string, newType: NodeType): TreeState;
83
98
  declare function duplicateNode(state: TreeState, nodeId: string): TreeState;
84
99
 
@@ -129,4 +144,4 @@ interface DiffEntry {
129
144
  declare function computeDiff(original: JsonValue, current: JsonValue, path?: string): DiffEntry[];
130
145
  declare function getDiffPaths(entries: DiffEntry[]): Map<string, DiffType>;
131
146
 
132
- export { type DiffEntry, type DiffType, History, type JsonArray, type JsonObject, type JsonPrimitive, type JsonSchema, type JsonSchemaProperty, type JsonValue, type NodeType, type SearchMatch, type TreeNode, type TreeState, type ValidationResult, addProperty, buildSubtree, changeType, clearSchemaCache, computeDiff, duplicateNode, findNode, findNodeByPath, fromJson, generateId, getAncestorIds, getDiffPaths, getNodeType, getPropertySchema, moveNode, removeNode, reorderChildren, resetIdCounter, resolveRef, resolveSchema, searchNodes, setKey, setValue, toJson, validateNode };
147
+ export { type DiffEntry, type DiffType, History, type JsonArray, type JsonObject, type JsonPrimitive, type JsonSchema, type JsonSchemaProperty, type JsonValue, type NodeType, type SearchMatch, type TreeNode, type TreeState, type ValidationResult, addProperty, buildSubtree, changeType, clearSchemaCache, computeDiff, duplicateNode, findNode, findNodeByPath, fromJson, generateId, getAncestorIds, getDiffPaths, getNodeType, getPropertySchema, insertNode, insertProperty, isDescendant, moveNode, removeNode, reorderChildren, reorderChildrenMulti, reparentSubtree, resetIdCounter, resolveRef, resolveSchema, searchNodes, setKey, setValue, toJson, validateNode };
package/dist/index.d.ts CHANGED
@@ -70,15 +70,30 @@ declare function getNodeType(value: JsonValue): NodeType;
70
70
  declare function buildSubtree(key: string, value: JsonValue, parentPath: string, parentId: string | null, nodesById: Map<string, TreeNode>): TreeNode;
71
71
  declare function fromJson(value: JsonValue): TreeState;
72
72
  declare function toJson(node: TreeNode): JsonValue;
73
+ /**
74
+ * Clone a subtree with updated key, path, and parentId while preserving
75
+ * all original node IDs. Used for cross-parent moves where identity must
76
+ * be retained so that UI state (expanded, selected, etc.) stays valid.
77
+ */
78
+ declare function reparentSubtree(node: TreeNode, newKey: string, parentPath: string, newParentId: string): TreeNode;
73
79
  declare function findNode(state: TreeState, nodeId: string): TreeNode | undefined;
74
80
  declare function findNodeByPath(state: TreeState, path: string): TreeNode | undefined;
81
+ /**
82
+ * Check whether `nodeId` is a descendant of `potentialAncestorId` by walking
83
+ * up `parentId` links. Returns `true` when the two IDs are equal (a node is
84
+ * considered a descendant of itself).
85
+ */
86
+ declare function isDescendant(tree: TreeState, nodeId: string, potentialAncestorId: string): boolean;
75
87
 
76
88
  declare function setValue(state: TreeState, nodeId: string, value: JsonValue): TreeState;
77
89
  declare function setKey(state: TreeState, nodeId: string, newKey: string): TreeState;
78
90
  declare function addProperty(state: TreeState, parentId: string, key: string, value: JsonValue): TreeState;
91
+ declare function insertProperty(state: TreeState, parentId: string, key: string, value: JsonValue, index: number): TreeState;
92
+ declare function insertNode(state: TreeState, parentId: string, node: TreeNode, index: number): TreeState;
79
93
  declare function removeNode(state: TreeState, nodeId: string): TreeState;
80
94
  declare function moveNode(state: TreeState, nodeId: string, newParentId: string, index?: number): TreeState;
81
95
  declare function reorderChildren(state: TreeState, parentId: string, fromIndex: number, toIndex: number): TreeState;
96
+ declare function reorderChildrenMulti(state: TreeState, parentId: string, movedIds: string[], targetSiblingId: string, position: "before" | "after"): TreeState;
82
97
  declare function changeType(state: TreeState, nodeId: string, newType: NodeType): TreeState;
83
98
  declare function duplicateNode(state: TreeState, nodeId: string): TreeState;
84
99
 
@@ -129,4 +144,4 @@ interface DiffEntry {
129
144
  declare function computeDiff(original: JsonValue, current: JsonValue, path?: string): DiffEntry[];
130
145
  declare function getDiffPaths(entries: DiffEntry[]): Map<string, DiffType>;
131
146
 
132
- export { type DiffEntry, type DiffType, History, type JsonArray, type JsonObject, type JsonPrimitive, type JsonSchema, type JsonSchemaProperty, type JsonValue, type NodeType, type SearchMatch, type TreeNode, type TreeState, type ValidationResult, addProperty, buildSubtree, changeType, clearSchemaCache, computeDiff, duplicateNode, findNode, findNodeByPath, fromJson, generateId, getAncestorIds, getDiffPaths, getNodeType, getPropertySchema, moveNode, removeNode, reorderChildren, resetIdCounter, resolveRef, resolveSchema, searchNodes, setKey, setValue, toJson, validateNode };
147
+ export { type DiffEntry, type DiffType, History, type JsonArray, type JsonObject, type JsonPrimitive, type JsonSchema, type JsonSchemaProperty, type JsonValue, type NodeType, type SearchMatch, type TreeNode, type TreeState, type ValidationResult, addProperty, buildSubtree, changeType, clearSchemaCache, computeDiff, duplicateNode, findNode, findNodeByPath, fromJson, generateId, getAncestorIds, getDiffPaths, getNodeType, getPropertySchema, insertNode, insertProperty, isDescendant, moveNode, removeNode, reorderChildren, reorderChildrenMulti, reparentSubtree, resetIdCounter, resolveRef, resolveSchema, searchNodes, setKey, setValue, toJson, validateNode };
package/dist/index.js CHANGED
@@ -35,9 +35,14 @@ __export(index_exports, {
35
35
  getDiffPaths: () => getDiffPaths,
36
36
  getNodeType: () => getNodeType,
37
37
  getPropertySchema: () => getPropertySchema,
38
+ insertNode: () => insertNode,
39
+ insertProperty: () => insertProperty,
40
+ isDescendant: () => isDescendant,
38
41
  moveNode: () => moveNode,
39
42
  removeNode: () => removeNode,
40
43
  reorderChildren: () => reorderChildren,
44
+ reorderChildrenMulti: () => reorderChildrenMulti,
45
+ reparentSubtree: () => reparentSubtree,
41
46
  resetIdCounter: () => resetIdCounter,
42
47
  resolveRef: () => resolveRef,
43
48
  resolveSchema: () => resolveSchema,
@@ -130,6 +135,23 @@ function toJson(node) {
130
135
  return node.value;
131
136
  }
132
137
  }
138
+ function reparentSubtree(node, newKey, parentPath, newParentId) {
139
+ const newPath = parentPath ? `${parentPath}/${newKey}` : `/${newKey}`;
140
+ return {
141
+ ...node,
142
+ key: newKey,
143
+ path: newPath,
144
+ parentId: newParentId,
145
+ children: node.children.map(
146
+ (child, i) => reparentSubtree(
147
+ child,
148
+ node.type === "array" ? String(i) : child.key,
149
+ newPath,
150
+ node.id
151
+ )
152
+ )
153
+ };
154
+ }
133
155
  function findNode(state, nodeId) {
134
156
  return state.nodesById.get(nodeId);
135
157
  }
@@ -144,6 +166,14 @@ function findNodeByPath(state, path) {
144
166
  }
145
167
  return current;
146
168
  }
169
+ function isDescendant(tree, nodeId, potentialAncestorId) {
170
+ let current = tree.nodesById.get(nodeId);
171
+ while (current) {
172
+ if (current.id === potentialAncestorId) return true;
173
+ current = current.parentId ? tree.nodesById.get(current.parentId) : void 0;
174
+ }
175
+ return false;
176
+ }
147
177
 
148
178
  // src/operations.ts
149
179
  function rebuildMap(root) {
@@ -214,7 +244,13 @@ function setValue(state, nodeId, value) {
214
244
  return clonePathToNode(state, nodeId, (n) => {
215
245
  const parentPath = n.path.split("/").slice(0, -1).join("/") || "";
216
246
  const nodesById = /* @__PURE__ */ new Map();
217
- const subtree = buildSubtree(n.key, value, parentPath, n.parentId, nodesById);
247
+ const subtree = buildSubtree(
248
+ n.key,
249
+ value,
250
+ parentPath,
251
+ n.parentId,
252
+ nodesById
253
+ );
218
254
  return { ...subtree, id: n.id };
219
255
  });
220
256
  }
@@ -240,11 +276,33 @@ function addProperty(state, parentId, key, value) {
240
276
  if (!parent) return state;
241
277
  return clonePathToNode(state, parentId, (p) => {
242
278
  const parentPath = p.path === "/" ? "" : p.path;
243
- const nodesById = /* @__PURE__ */ new Map();
244
- const newChild = buildSubtree(key, value, parentPath, p.id, nodesById);
279
+ const newChild = buildSubtree(key, value, parentPath, p.id, /* @__PURE__ */ new Map());
245
280
  return { ...p, children: [...p.children, newChild] };
246
281
  });
247
282
  }
283
+ function insertProperty(state, parentId, key, value, index) {
284
+ const parent = state.nodesById.get(parentId);
285
+ if (!parent) return state;
286
+ return clonePathToNode(state, parentId, (p) => {
287
+ const parentPath = p.path === "/" ? "" : p.path;
288
+ const newChild = buildSubtree(key, value, parentPath, p.id, /* @__PURE__ */ new Map());
289
+ const newChildren = [...p.children];
290
+ newChildren.splice(index, 0, newChild);
291
+ return reindexArrayChildren({ ...p, children: newChildren });
292
+ });
293
+ }
294
+ function insertNode(state, parentId, node, index) {
295
+ const parent = state.nodesById.get(parentId);
296
+ if (!parent) return state;
297
+ return clonePathToNode(state, parentId, (p) => {
298
+ const parentPath = p.path === "/" ? "" : p.path;
299
+ const key = p.type === "array" ? String(index) : node.key;
300
+ const reparented = reparentSubtree(node, key, parentPath, p.id);
301
+ const newChildren = [...p.children];
302
+ newChildren.splice(index, 0, reparented);
303
+ return reindexArrayChildren({ ...p, children: newChildren });
304
+ });
305
+ }
248
306
  function removeNode(state, nodeId) {
249
307
  const node = state.nodesById.get(nodeId);
250
308
  if (!node || !node.parentId) return state;
@@ -266,13 +324,12 @@ function moveNode(state, nodeId, newParentId, index) {
266
324
  });
267
325
  return clonePathToNode(removed, newParentId, (p) => {
268
326
  const parentPath = p.path === "/" ? "" : p.path;
269
- const nodesById = /* @__PURE__ */ new Map();
270
327
  const newChild = buildSubtree(
271
328
  p.type === "array" ? String(index ?? p.children.length) : node.key,
272
329
  nodeValue,
273
330
  parentPath,
274
331
  p.id,
275
- nodesById
332
+ /* @__PURE__ */ new Map()
276
333
  );
277
334
  const newChildren = [...p.children];
278
335
  const insertAt = index ?? newChildren.length;
@@ -290,6 +347,40 @@ function reorderChildren(state, parentId, fromIndex, toIndex) {
290
347
  return reindexArrayChildren({ ...p, children: newChildren });
291
348
  });
292
349
  }
350
+ function reorderChildrenMulti(state, parentId, movedIds, targetSiblingId, position) {
351
+ const parent = state.nodesById.get(parentId);
352
+ if (!parent) return state;
353
+ const movedSet = new Set(movedIds);
354
+ return clonePathToNode(state, parentId, (p) => {
355
+ const remaining = p.children.filter((c) => !movedSet.has(c.id));
356
+ let insertIdx = remaining.findIndex((c) => c.id === targetSiblingId);
357
+ if (insertIdx === -1) {
358
+ if (movedSet.has(targetSiblingId)) {
359
+ const origIdx = p.children.findIndex((c) => c.id === targetSiblingId);
360
+ const origMap = new Map(p.children.map((c, i) => [c.id, i]));
361
+ if (position === "after") {
362
+ insertIdx = remaining.findIndex(
363
+ (c) => (origMap.get(c.id) ?? -1) > origIdx
364
+ );
365
+ if (insertIdx === -1) insertIdx = remaining.length;
366
+ } else {
367
+ insertIdx = remaining.findIndex(
368
+ (c) => (origMap.get(c.id) ?? -1) >= origIdx
369
+ );
370
+ if (insertIdx === -1) insertIdx = remaining.length;
371
+ }
372
+ } else {
373
+ insertIdx = position === "after" ? remaining.length : 0;
374
+ }
375
+ } else if (position === "after") {
376
+ insertIdx++;
377
+ }
378
+ const moved = movedIds.map((id) => p.children.find((c) => c.id === id)).filter((c) => c !== void 0);
379
+ const newChildren = [...remaining];
380
+ newChildren.splice(insertIdx, 0, ...moved);
381
+ return reindexArrayChildren({ ...p, children: newChildren });
382
+ });
383
+ }
293
384
  function convertValue(current, newType) {
294
385
  switch (newType) {
295
386
  case "string":
@@ -341,13 +432,12 @@ function duplicateNode(state, nodeId) {
341
432
  const idx = p.children.findIndex((c) => c.id === nodeId);
342
433
  const parentPath = p.path === "/" ? "" : p.path;
343
434
  const newKey = p.type === "array" ? String(idx + 1) : `${node.key}_copy`;
344
- const nodesById = /* @__PURE__ */ new Map();
345
435
  const newChild = buildSubtree(
346
436
  newKey,
347
437
  structuredClone(nodeValue),
348
438
  parentPath,
349
439
  p.id,
350
- nodesById
440
+ /* @__PURE__ */ new Map()
351
441
  );
352
442
  const newChildren = [...p.children];
353
443
  newChildren.splice(idx + 1, 0, newChild);
@@ -812,9 +902,14 @@ function getDiffPaths(entries) {
812
902
  getDiffPaths,
813
903
  getNodeType,
814
904
  getPropertySchema,
905
+ insertNode,
906
+ insertProperty,
907
+ isDescendant,
815
908
  moveNode,
816
909
  removeNode,
817
910
  reorderChildren,
911
+ reorderChildrenMulti,
912
+ reparentSubtree,
818
913
  resetIdCounter,
819
914
  resolveRef,
820
915
  resolveSchema,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/tree.ts","../src/operations.ts","../src/history.ts","../src/schema.ts","../src/validate.ts","../src/search.ts","../src/diff.ts"],"sourcesContent":["export type {\n JsonValue,\n JsonPrimitive,\n JsonArray,\n JsonObject,\n NodeType,\n TreeNode,\n TreeState,\n JsonSchema,\n JsonSchemaProperty,\n} from \"./types\";\n\nexport {\n fromJson,\n toJson,\n findNode,\n findNodeByPath,\n resetIdCounter,\n getNodeType,\n generateId,\n buildSubtree,\n} from \"./tree\";\n\nexport {\n setValue,\n setKey,\n addProperty,\n removeNode,\n moveNode,\n reorderChildren,\n changeType,\n duplicateNode,\n} from \"./operations\";\n\nexport { History } from \"./history\";\n\nexport {\n resolveSchema,\n resolveRef,\n getPropertySchema,\n clearSchemaCache,\n} from \"./schema\";\n\nexport { validateNode, type ValidationResult } from \"./validate\";\n\nexport { searchNodes, getAncestorIds, type SearchMatch } from \"./search\";\n\nexport {\n computeDiff,\n getDiffPaths,\n type DiffEntry,\n type DiffType,\n} from \"./diff\";\n","import type {\n JsonPrimitive,\n JsonValue,\n JsonObject,\n JsonArray,\n NodeType,\n TreeNode,\n TreeState,\n} from \"./types\";\n\nlet nextId = 0;\n\nexport function generateId(): string {\n return `node_${++nextId}`;\n}\n\nexport function resetIdCounter(): void {\n nextId = 0;\n}\n\nexport function getNodeType(value: JsonValue): NodeType {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"array\";\n return typeof value as NodeType;\n}\n\nexport function buildSubtree(\n key: string,\n value: JsonValue,\n parentPath: string,\n parentId: string | null,\n nodesById: Map<string, TreeNode>,\n): TreeNode {\n const id = generateId();\n const path = parentPath ? `${parentPath}/${key}` : `/${key}`;\n const type = getNodeType(value);\n\n const node: TreeNode = {\n id,\n key,\n path,\n type,\n value:\n type === \"object\" || type === \"array\"\n ? undefined\n : (value as JsonPrimitive),\n children: [],\n parentId,\n };\n\n nodesById.set(id, node);\n\n if (type === \"object\" && value !== null) {\n const obj = value as JsonObject;\n node.children = Object.keys(obj).map((childKey) =>\n buildSubtree(childKey, obj[childKey], path, id, nodesById),\n );\n } else if (type === \"array\") {\n const arr = value as JsonArray;\n node.children = arr.map((item, index) =>\n buildSubtree(String(index), item, path, id, nodesById),\n );\n }\n\n return node;\n}\n\nexport function fromJson(value: JsonValue): TreeState {\n const nodesById = new Map<string, TreeNode>();\n\n const rootType = getNodeType(value);\n const root: TreeNode = {\n id: generateId(),\n key: \"\",\n path: \"/\",\n type: rootType,\n value:\n rootType === \"object\" || rootType === \"array\"\n ? undefined\n : (value as JsonPrimitive),\n children: [],\n parentId: null,\n };\n\n nodesById.set(root.id, root);\n\n if (rootType === \"object\" && value !== null) {\n const obj = value as JsonObject;\n root.children = Object.keys(obj).map((key) =>\n buildSubtree(key, obj[key], \"\", root.id, nodesById),\n );\n } else if (rootType === \"array\") {\n const arr = value as JsonArray;\n root.children = arr.map((item, index) =>\n buildSubtree(String(index), item, \"\", root.id, nodesById),\n );\n }\n\n return { root, nodesById };\n}\n\nexport function toJson(node: TreeNode): JsonValue {\n switch (node.type) {\n case \"object\": {\n const obj: JsonObject = {};\n for (const child of node.children) {\n obj[child.key] = toJson(child);\n }\n return obj;\n }\n case \"array\":\n return node.children.map((child) => toJson(child));\n default:\n return node.value as JsonValue;\n }\n}\n\nexport function findNode(\n state: TreeState,\n nodeId: string,\n): TreeNode | undefined {\n return state.nodesById.get(nodeId);\n}\n\nexport function findNodeByPath(\n state: TreeState,\n path: string,\n): TreeNode | undefined {\n if (path === \"/\") return state.root;\n\n const segments = path.split(\"/\").filter(Boolean);\n let current = state.root;\n\n for (const segment of segments) {\n const child = current.children.find((c) => c.key === segment);\n if (!child) return undefined;\n current = child;\n }\n\n return current;\n}\n","import type {\n JsonPrimitive,\n JsonValue,\n NodeType,\n TreeNode,\n TreeState,\n} from \"./types\";\nimport {\n toJson,\n getNodeType,\n generateId,\n buildSubtree,\n} from \"./tree\";\n\nfunction rebuildMap(root: TreeNode): Map<string, TreeNode> {\n const map = new Map<string, TreeNode>();\n function walk(node: TreeNode) {\n map.set(node.id, node);\n for (const child of node.children) walk(child);\n }\n walk(root);\n return map;\n}\n\nfunction recomputePaths(node: TreeNode, newParentPath: string): TreeNode {\n const newPath = newParentPath\n ? `${newParentPath}/${node.key}`\n : `/${node.key}`;\n if (node.path === newPath && node.children.length === 0) return node;\n return {\n ...node,\n path: newPath,\n children: node.children.map((child) => recomputePaths(child, newPath)),\n };\n}\n\n/**\n * Clone only the ancestor chain from root to `targetId` (structural sharing),\n * apply `updater` to the target, and rebuild the `nodesById` map.\n */\nfunction clonePathToNode(\n state: TreeState,\n targetId: string,\n updater: (node: TreeNode) => TreeNode,\n): TreeState {\n const chain: string[] = [];\n let cur: TreeNode | undefined = state.nodesById.get(targetId);\n while (cur) {\n chain.unshift(cur.id);\n cur = cur.parentId ? state.nodesById.get(cur.parentId) : undefined;\n }\n if (chain.length === 0) return state;\n\n function cloneAlongPath(node: TreeNode, depth: number): TreeNode {\n if (depth === chain.length - 1) {\n return updater(node);\n }\n const nextInChain = chain[depth + 1];\n return {\n ...node,\n children: node.children.map((child) =>\n child.id === nextInChain ? cloneAlongPath(child, depth + 1) : child,\n ),\n };\n }\n\n const newRoot = cloneAlongPath(state.root, 0);\n return { root: newRoot, nodesById: rebuildMap(newRoot) };\n}\n\nfunction reindexArrayChildren(parent: TreeNode): TreeNode {\n if (parent.type !== \"array\") return parent;\n const parentPath = parent.path === \"/\" ? \"\" : parent.path;\n return {\n ...parent,\n children: parent.children.map((child, i) => {\n const newKey = String(i);\n if (child.key === newKey) return child;\n return recomputePaths({ ...child, key: newKey }, parentPath);\n }),\n };\n}\n\nexport function setValue(\n state: TreeState,\n nodeId: string,\n value: JsonValue,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node) return state;\n\n const newType = getNodeType(value);\n\n if (newType !== \"object\" && newType !== \"array\") {\n return clonePathToNode(state, nodeId, (n) => ({\n ...n,\n type: newType,\n value: value as JsonPrimitive,\n children: [],\n }));\n }\n\n return clonePathToNode(state, nodeId, (n) => {\n const parentPath = n.path.split(\"/\").slice(0, -1).join(\"/\") || \"\";\n const nodesById = new Map<string, TreeNode>();\n const subtree = buildSubtree(n.key, value, parentPath, n.parentId, nodesById);\n return { ...subtree, id: n.id };\n });\n}\n\nexport function setKey(\n state: TreeState,\n nodeId: string,\n newKey: string,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const parent = state.nodesById.get(node.parentId);\n if (!parent || parent.type !== \"object\") return state;\n\n return clonePathToNode(state, nodeId, (n) => {\n const parentPath = parent.path === \"/\" ? \"\" : parent.path;\n const newPath = `${parentPath}/${newKey}`;\n const updated: TreeNode = { ...n, key: newKey, path: newPath };\n if (updated.children.length > 0) {\n updated.children = updated.children.map((child) =>\n recomputePaths(child, newPath),\n );\n }\n return updated;\n });\n}\n\nexport function addProperty(\n state: TreeState,\n parentId: string,\n key: string,\n value: JsonValue,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const nodesById = new Map<string, TreeNode>();\n const newChild = buildSubtree(key, value, parentPath, p.id, nodesById);\n return { ...p, children: [...p.children, newChild] };\n });\n}\n\nexport function removeNode(state: TreeState, nodeId: string): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n return clonePathToNode(state, node.parentId, (p) => {\n const newChildren = p.children.filter((c) => c.id !== nodeId);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function moveNode(\n state: TreeState,\n nodeId: string,\n newParentId: string,\n index?: number,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const srcParent = state.nodesById.get(node.parentId);\n const dstParent = state.nodesById.get(newParentId);\n if (!srcParent || !dstParent) return state;\n\n const nodeValue = toJson(node);\n\n const removed = clonePathToNode(state, node.parentId, (p) => {\n const newChildren = p.children.filter((c) => c.id !== nodeId);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n\n return clonePathToNode(removed, newParentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const nodesById = new Map<string, TreeNode>();\n const newChild = buildSubtree(\n p.type === \"array\" ? String(index ?? p.children.length) : node.key,\n nodeValue,\n parentPath,\n p.id,\n nodesById,\n );\n const newChildren = [...p.children];\n const insertAt = index ?? newChildren.length;\n newChildren.splice(insertAt, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function reorderChildren(\n state: TreeState,\n parentId: string,\n fromIndex: number,\n toIndex: number,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const newChildren = [...p.children];\n const [item] = newChildren.splice(fromIndex, 1);\n newChildren.splice(toIndex, 0, item);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nfunction convertValue(current: JsonValue, newType: NodeType): JsonValue {\n switch (newType) {\n case \"string\":\n if (current === null || current === undefined) return \"\";\n if (typeof current === \"object\") return JSON.stringify(current);\n return String(current);\n case \"number\": {\n const n = Number(current);\n return isNaN(n) ? 0 : n;\n }\n case \"boolean\":\n return Boolean(current);\n case \"null\":\n return null;\n case \"object\":\n if (\n current !== null &&\n typeof current === \"object\" &&\n !Array.isArray(current)\n )\n return current;\n if (Array.isArray(current)) {\n const obj: Record<string, JsonValue> = {};\n current.forEach((item, i) => {\n obj[String(i)] = item;\n });\n return obj;\n }\n return {};\n case \"array\":\n if (Array.isArray(current)) return current;\n if (current !== null && typeof current === \"object\")\n return Object.values(current);\n return current === null || current === undefined ? [] : [current];\n default:\n return current;\n }\n}\n\nexport function changeType(\n state: TreeState,\n nodeId: string,\n newType: NodeType,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node) return state;\n\n const currentValue = toJson(node);\n const newValue = convertValue(currentValue, newType);\n return setValue(state, nodeId, newValue);\n}\n\nexport function duplicateNode(state: TreeState, nodeId: string): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const parent = state.nodesById.get(node.parentId);\n if (!parent) return state;\n\n const nodeValue = toJson(node);\n\n return clonePathToNode(state, node.parentId, (p) => {\n const idx = p.children.findIndex((c) => c.id === nodeId);\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newKey = p.type === \"array\" ? String(idx + 1) : `${node.key}_copy`;\n const nodesById = new Map<string, TreeNode>();\n const newChild = buildSubtree(\n newKey,\n structuredClone(nodeValue),\n parentPath,\n p.id,\n nodesById,\n );\n const newChildren = [...p.children];\n newChildren.splice(idx + 1, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n","import type { TreeState } from \"./types\";\n\nconst MAX_HISTORY = 100;\n\nexport class History {\n private stack: TreeState[] = [];\n private cursor = -1;\n\n push(state: TreeState): void {\n this.stack = this.stack.slice(0, this.cursor + 1);\n this.stack.push(state);\n if (this.stack.length > MAX_HISTORY) {\n this.stack.shift();\n } else {\n this.cursor++;\n }\n }\n\n undo(): TreeState | null {\n if (!this.canUndo) return null;\n this.cursor--;\n return this.stack[this.cursor];\n }\n\n redo(): TreeState | null {\n if (!this.canRedo) return null;\n this.cursor++;\n return this.stack[this.cursor];\n }\n\n get canUndo(): boolean {\n return this.cursor > 0;\n }\n\n get canRedo(): boolean {\n return this.cursor < this.stack.length - 1;\n }\n\n get current(): TreeState | null {\n return this.stack[this.cursor] ?? null;\n }\n}\n","import type {\n JsonSchema,\n JsonSchemaProperty,\n JsonValue,\n JsonObject,\n} from \"./types\";\n\nconst KNOWN_SCHEMAS: Record<string, string> = {\n \"package.json\": \"https://json.schemastore.org/package.json\",\n \"tsconfig.json\": \"https://json.schemastore.org/tsconfig\",\n \"tsconfig.base.json\": \"https://json.schemastore.org/tsconfig\",\n \".eslintrc.json\": \"https://json.schemastore.org/eslintrc\",\n \".prettierrc\": \"https://json.schemastore.org/prettierrc\",\n \".prettierrc.json\": \"https://json.schemastore.org/prettierrc\",\n \"turbo.json\": \"https://turborepo.dev/schema.json\",\n \".babelrc\": \"https://json.schemastore.org/babelrc\",\n \"nest-cli.json\": \"https://json.schemastore.org/nest-cli\",\n \"vercel.json\": \"https://openapi.vercel.sh/vercel.json\",\n \".swcrc\": \"https://json.schemastore.org/swcrc\",\n};\n\nconst MAX_SCHEMA_CACHE = 50;\nconst schemaCache = new Map<string, JsonSchema>();\n\nasync function fetchSchema(url: string): Promise<JsonSchema | null> {\n if (schemaCache.has(url)) {\n return schemaCache.get(url)!;\n }\n try {\n const res = await fetch(url);\n if (!res.ok) return null;\n const schema = (await res.json()) as JsonSchema;\n if (schemaCache.size >= MAX_SCHEMA_CACHE) {\n const oldest = schemaCache.keys().next().value;\n if (oldest !== undefined) schemaCache.delete(oldest);\n }\n schemaCache.set(url, schema);\n return schema;\n } catch {\n return null;\n }\n}\n\nexport async function resolveSchema(\n json: JsonValue,\n filename?: string,\n): Promise<JsonSchema | null> {\n if (\n json !== null &&\n typeof json === \"object\" &&\n !Array.isArray(json) &&\n typeof (json as JsonObject)[\"$schema\"] === \"string\"\n ) {\n const url = (json as JsonObject)[\"$schema\"] as string;\n const schema = await fetchSchema(url);\n if (schema) return schema;\n }\n\n if (filename) {\n const base = filename.split(\"/\").pop() ?? filename;\n const knownUrl = KNOWN_SCHEMAS[base];\n if (knownUrl) {\n return fetchSchema(knownUrl);\n }\n }\n\n return null;\n}\n\nfunction findDefinition(\n root: JsonSchemaProperty,\n refPath: string,\n): JsonSchemaProperty | undefined {\n if (!refPath.startsWith(\"#/\")) return undefined;\n const segments = refPath.slice(2).split(\"/\");\n let current: unknown = root;\n\n for (const seg of segments) {\n if (current === null || typeof current !== \"object\") return undefined;\n current = (current as Record<string, unknown>)[seg];\n }\n\n return current as JsonSchemaProperty | undefined;\n}\n\n/**\n * Resolve `$ref` pointers and merge `allOf` within a schema.\n * `visited` tracks refs to prevent infinite cycles.\n */\nexport function resolveRef(\n prop: JsonSchemaProperty,\n root: JsonSchemaProperty,\n visited?: Set<string>,\n): JsonSchemaProperty {\n const seen = visited ?? new Set<string>();\n\n if (prop.$ref) {\n if (seen.has(prop.$ref)) return prop;\n seen.add(prop.$ref);\n const resolved = findDefinition(root, prop.$ref);\n if (resolved) {\n return resolveRef(resolved, root, seen);\n }\n return prop;\n }\n\n if (prop.allOf && prop.allOf.length > 0) {\n return mergeAllOf(prop, root, seen);\n }\n\n return prop;\n}\n\nfunction mergeAllOf(\n prop: JsonSchemaProperty,\n root: JsonSchemaProperty,\n visited: Set<string>,\n): JsonSchemaProperty {\n const merged: JsonSchemaProperty = { ...prop };\n delete merged.allOf;\n\n for (const sub of prop.allOf!) {\n const resolved = resolveRef(sub, root, new Set(visited));\n if (resolved.type && !merged.type) merged.type = resolved.type;\n if (resolved.properties) {\n merged.properties = { ...merged.properties, ...resolved.properties };\n }\n if (resolved.required) {\n merged.required = [\n ...new Set([...(merged.required ?? []), ...resolved.required]),\n ];\n }\n if (\n resolved.additionalProperties !== undefined &&\n merged.additionalProperties === undefined\n ) {\n merged.additionalProperties = resolved.additionalProperties;\n }\n if (resolved.items && !merged.items) merged.items = resolved.items;\n if (resolved.description && !merged.description)\n merged.description = resolved.description;\n if (resolved.title && !merged.title) merged.title = resolved.title;\n if (resolved.enum && !merged.enum) merged.enum = resolved.enum;\n if (resolved.minimum !== undefined && merged.minimum === undefined)\n merged.minimum = resolved.minimum;\n if (resolved.maximum !== undefined && merged.maximum === undefined)\n merged.maximum = resolved.maximum;\n if (resolved.minLength !== undefined && merged.minLength === undefined)\n merged.minLength = resolved.minLength;\n if (resolved.maxLength !== undefined && merged.maxLength === undefined)\n merged.maxLength = resolved.maxLength;\n if (resolved.pattern && !merged.pattern) merged.pattern = resolved.pattern;\n if (resolved.format && !merged.format) merged.format = resolved.format;\n }\n\n return merged;\n}\n\nexport function getPropertySchema(\n schema: JsonSchema | JsonSchemaProperty,\n path: string,\n rootSchema?: JsonSchemaProperty,\n): JsonSchemaProperty | undefined {\n const root = rootSchema ?? schema;\n const segments = path.split(\"/\").filter(Boolean);\n let current: JsonSchemaProperty | undefined = resolveRef(schema, root);\n\n for (const seg of segments) {\n if (!current) return undefined;\n current = resolveRef(current, root);\n\n if (current.properties?.[seg]) {\n current = resolveRef(current.properties[seg], root);\n continue;\n }\n\n if (current.patternProperties) {\n const match = Object.entries(current.patternProperties).find(\n ([pattern]) => {\n try {\n return new RegExp(pattern).test(seg);\n } catch {\n return false;\n }\n },\n );\n if (match) {\n current = resolveRef(match[1], root);\n continue;\n }\n }\n\n if (\n current.additionalProperties &&\n typeof current.additionalProperties === \"object\"\n ) {\n current = resolveRef(current.additionalProperties, root);\n continue;\n }\n\n if (current.items) {\n if (Array.isArray(current.items)) {\n const idx = Number(seg);\n if (!isNaN(idx) && current.items[idx]) {\n current = resolveRef(current.items[idx], root);\n continue;\n }\n } else {\n current = resolveRef(current.items, root);\n continue;\n }\n }\n\n if (current.anyOf || current.oneOf) {\n const variants = current.anyOf ?? current.oneOf ?? [];\n let found: JsonSchemaProperty | undefined;\n for (const variant of variants) {\n const resolved = resolveRef(variant, root);\n found = getPropertySchema(resolved, seg, root);\n if (found) break;\n }\n if (found) {\n current = found;\n continue;\n }\n return undefined;\n }\n\n return undefined;\n }\n\n return current;\n}\n\nexport function clearSchemaCache(): void {\n schemaCache.clear();\n}\n","import type { TreeNode, JsonSchemaProperty } from \"./types\";\n\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n}\n\nfunction schemaTypeMatches(\n nodeType: string,\n schemaType: string | string[] | undefined,\n): boolean {\n if (!schemaType) return true;\n const types = Array.isArray(schemaType) ? schemaType : [schemaType];\n\n if (nodeType === \"number\" && types.includes(\"integer\")) return true;\n return types.includes(nodeType);\n}\n\nconst FORMAT_PATTERNS: Record<string, RegExp> = {\n email: /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/,\n uri: /^https?:\\/\\/.+/,\n \"uri-reference\": /^(https?:\\/\\/|\\/|\\.\\.?\\/|#).*/,\n \"date-time\": /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/,\n date: /^\\d{4}-\\d{2}-\\d{2}$/,\n time: /^\\d{2}:\\d{2}:\\d{2}/,\n ipv4: /^(\\d{1,3}\\.){3}\\d{1,3}$/,\n ipv6: /^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$/,\n uuid: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,\n hostname:\n /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$/,\n};\n\nexport function validateNode(\n node: TreeNode,\n schema: JsonSchemaProperty | undefined,\n): ValidationResult {\n const errors: string[] = [];\n\n if (!schema) {\n return { valid: true, errors };\n }\n\n if (schema.type && !schemaTypeMatches(node.type, schema.type)) {\n const expected = Array.isArray(schema.type)\n ? schema.type.join(\" | \")\n : schema.type;\n errors.push(`Expected type \"${expected}\", got \"${node.type}\"`);\n }\n\n if (schema.enum && schema.enum.length > 0 && node.value !== undefined) {\n const match = schema.enum.some(\n (v) => JSON.stringify(v) === JSON.stringify(node.value),\n );\n if (!match) {\n errors.push(\n `Value must be one of: ${schema.enum.map((v) => JSON.stringify(v)).join(\", \")}`,\n );\n }\n }\n\n if (schema.const !== undefined && node.value !== undefined) {\n if (JSON.stringify(node.value) !== JSON.stringify(schema.const)) {\n errors.push(`Value must be ${JSON.stringify(schema.const)}`);\n }\n }\n\n if (schema.required && (node.type === \"object\" || node.type === \"array\")) {\n const childKeys = new Set(node.children.map((c) => c.key));\n for (const req of schema.required) {\n if (!childKeys.has(req)) {\n errors.push(`Missing required property \"${req}\"`);\n }\n }\n }\n\n if (node.type === \"number\" && typeof node.value === \"number\") {\n const val = node.value;\n if (schema.minimum !== undefined && val < schema.minimum) {\n errors.push(`Value must be >= ${schema.minimum}`);\n }\n if (schema.maximum !== undefined && val > schema.maximum) {\n errors.push(`Value must be <= ${schema.maximum}`);\n }\n if (schema.exclusiveMinimum !== undefined) {\n const bound =\n typeof schema.exclusiveMinimum === \"number\"\n ? schema.exclusiveMinimum\n : schema.minimum;\n if (bound !== undefined && val <= bound) {\n errors.push(`Value must be > ${bound}`);\n }\n }\n if (schema.exclusiveMaximum !== undefined) {\n const bound =\n typeof schema.exclusiveMaximum === \"number\"\n ? schema.exclusiveMaximum\n : schema.maximum;\n if (bound !== undefined && val >= bound) {\n errors.push(`Value must be < ${bound}`);\n }\n }\n if (schema.multipleOf !== undefined) {\n const remainder = Math.abs(val % schema.multipleOf);\n if (remainder > 1e-10 && Math.abs(remainder - schema.multipleOf) > 1e-10) {\n errors.push(`Value must be a multiple of ${schema.multipleOf}`);\n }\n }\n }\n\n if (node.type === \"string\" && typeof node.value === \"string\") {\n const val = node.value;\n if (schema.minLength !== undefined && val.length < schema.minLength) {\n errors.push(`Must be at least ${schema.minLength} characters`);\n }\n if (schema.maxLength !== undefined && val.length > schema.maxLength) {\n errors.push(`Must be at most ${schema.maxLength} characters`);\n }\n if (schema.pattern) {\n try {\n if (!new RegExp(schema.pattern).test(val)) {\n errors.push(`Must match pattern: ${schema.pattern}`);\n }\n } catch {\n // invalid regex in schema, skip\n }\n }\n if (schema.format && FORMAT_PATTERNS[schema.format]) {\n if (!FORMAT_PATTERNS[schema.format].test(val)) {\n errors.push(`Invalid ${schema.format} format`);\n }\n }\n }\n\n if (node.type === \"array\") {\n if (\n schema.minItems !== undefined &&\n node.children.length < schema.minItems\n ) {\n errors.push(`Must have at least ${schema.minItems} items`);\n }\n if (\n schema.maxItems !== undefined &&\n node.children.length > schema.maxItems\n ) {\n errors.push(`Must have at most ${schema.maxItems} items`);\n }\n }\n\n if (node.type === \"object\") {\n if (\n schema.minProperties !== undefined &&\n node.children.length < schema.minProperties\n ) {\n errors.push(`Must have at least ${schema.minProperties} properties`);\n }\n if (\n schema.maxProperties !== undefined &&\n node.children.length > schema.maxProperties\n ) {\n errors.push(`Must have at most ${schema.maxProperties} properties`);\n }\n }\n\n return { valid: errors.length === 0, errors };\n}\n","import type { TreeNode, TreeState } from \"./types\";\n\nexport interface SearchMatch {\n nodeId: string;\n field: \"key\" | \"value\";\n}\n\nexport function searchNodes(tree: TreeState, query: string): SearchMatch[] {\n if (!query.trim()) return [];\n const matches: SearchMatch[] = [];\n const lower = query.toLowerCase();\n\n function walk(node: TreeNode) {\n if (node.key && node.key.toLowerCase().includes(lower)) {\n matches.push({ nodeId: node.id, field: \"key\" });\n }\n if (\n node.value !== undefined &&\n node.value !== null &&\n String(node.value).toLowerCase().includes(lower)\n ) {\n matches.push({ nodeId: node.id, field: \"value\" });\n }\n for (const child of node.children) {\n walk(child);\n }\n }\n\n walk(tree.root);\n return matches;\n}\n\n/**\n * Collect all ancestor node IDs for each matched node so the tree\n * can auto-expand paths to search results.\n */\nexport function getAncestorIds(\n tree: TreeState,\n nodeIds: string[],\n): Set<string> {\n const ancestors = new Set<string>();\n\n for (const nodeId of nodeIds) {\n let current = tree.nodesById.get(nodeId);\n while (current && current.parentId) {\n ancestors.add(current.parentId);\n current = tree.nodesById.get(current.parentId);\n }\n }\n\n return ancestors;\n}\n","import type { JsonValue } from \"./types\";\n\nexport type DiffType = \"added\" | \"removed\" | \"changed\";\n\nexport interface DiffEntry {\n path: string;\n type: DiffType;\n oldValue?: JsonValue;\n newValue?: JsonValue;\n}\n\nexport function computeDiff(\n original: JsonValue,\n current: JsonValue,\n path = \"\",\n): DiffEntry[] {\n const entries: DiffEntry[] = [];\n\n if (original === current) {\n return entries;\n }\n\n if (\n original === null ||\n current === null ||\n typeof original !== typeof current ||\n Array.isArray(original) !== Array.isArray(current)\n ) {\n if (path) {\n entries.push({\n path,\n type: \"changed\",\n oldValue: original,\n newValue: current,\n });\n } else {\n diffObject(original, current, path, entries);\n }\n return entries;\n }\n\n if (typeof original !== \"object\") {\n if (original !== current) {\n entries.push({\n path: path || \"/\",\n type: \"changed\",\n oldValue: original,\n newValue: current,\n });\n }\n return entries;\n }\n\n if (Array.isArray(original) && Array.isArray(current)) {\n const maxLen = Math.max(original.length, current.length);\n for (let i = 0; i < maxLen; i++) {\n const childPath = path ? `${path}/${i}` : `/${i}`;\n if (i >= original.length) {\n entries.push({ path: childPath, type: \"added\", newValue: current[i] });\n } else if (i >= current.length) {\n entries.push({\n path: childPath,\n type: \"removed\",\n oldValue: original[i],\n });\n } else {\n entries.push(...computeDiff(original[i], current[i], childPath));\n }\n }\n return entries;\n }\n\n diffObject(original, current, path, entries);\n return entries;\n}\n\nfunction diffObject(\n original: JsonValue,\n current: JsonValue,\n path: string,\n entries: DiffEntry[],\n) {\n const origObj =\n original !== null &&\n typeof original === \"object\" &&\n !Array.isArray(original)\n ? (original as Record<string, JsonValue>)\n : {};\n const currObj =\n current !== null && typeof current === \"object\" && !Array.isArray(current)\n ? (current as Record<string, JsonValue>)\n : {};\n\n const allKeys = new Set([...Object.keys(origObj), ...Object.keys(currObj)]);\n\n for (const key of allKeys) {\n const childPath = path ? `${path}/${key}` : `/${key}`;\n const inOriginal = key in origObj;\n const inCurrent = key in currObj;\n\n if (!inOriginal && inCurrent) {\n entries.push({ path: childPath, type: \"added\", newValue: currObj[key] });\n } else if (inOriginal && !inCurrent) {\n entries.push({\n path: childPath,\n type: \"removed\",\n oldValue: origObj[key],\n });\n } else {\n entries.push(...computeDiff(origObj[key], currObj[key], childPath));\n }\n }\n}\n\nexport function getDiffPaths(entries: DiffEntry[]): Map<string, DiffType> {\n const map = new Map<string, DiffType>();\n for (const entry of entries) {\n map.set(entry.path, entry.type);\n }\n return map;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,IAAI,SAAS;AAEN,SAAS,aAAqB;AACnC,SAAO,QAAQ,EAAE,MAAM;AACzB;AAEO,SAAS,iBAAuB;AACrC,WAAS;AACX;AAEO,SAAS,YAAY,OAA4B;AACtD,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO;AACjC,SAAO,OAAO;AAChB;AAEO,SAAS,aACd,KACA,OACA,YACA,UACA,WACU;AACV,QAAM,KAAK,WAAW;AACtB,QAAM,OAAO,aAAa,GAAG,UAAU,IAAI,GAAG,KAAK,IAAI,GAAG;AAC1D,QAAM,OAAO,YAAY,KAAK;AAE9B,QAAM,OAAiB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OACE,SAAS,YAAY,SAAS,UAC1B,SACC;AAAA,IACP,UAAU,CAAC;AAAA,IACX;AAAA,EACF;AAEA,YAAU,IAAI,IAAI,IAAI;AAEtB,MAAI,SAAS,YAAY,UAAU,MAAM;AACvC,UA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AAC,GAAG,QAAQ,CAAC,GAAG,SAAS,CAAC;AAAA,MACjE;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,aAAW,UAAU,SAAS,MAAM,OAAO;AAC3C,SAAO;AACT;AAEA,SAAS,WACP,UACA,SACA,MACA,SACA;AACA,QAAM,UACJ,aAAa,QACb,OAAO,aAAa,YACpB,CAAC,MAAM,QAAQ,QAAQ,IAClB,WACD,CAAC;AACP,QAAM,UACJ,YAAY,QAAQ,OAAO,YAAY,YAAY,CAAC,MAAM,QAAQ,OAAO,IACpE,UACD,CAAC;AAEP,QAAM,UAAU,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,OAAO,GAAG,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC;AAE1E,aAAW,OAAO,SAAS;AACzB,UAAM,YAAY,OAAO,GAAG,IAAI,IAAI,GAAG,KAAK,IAAI,GAAG;AACnD,UAAM,aAAa,OAAO;AAC1B,UAAM,YAAY,OAAO;AAEzB,QAAI,CAAC,cAAc,WAAW;AAC5B,cAAQ,KAAK,EAAE,MAAM,WAAW,MAAM,SAAS,UAAU,QAAQ,GAAG,EAAE,CAAC;AAAA,IACzE,WAAW,cAAc,CAAC,WAAW;AACnC,cAAQ,KAAK;AAAA,QACX,MAAM;AAAA,QACN,MAAM;AAAA,QACN,UAAU,QAAQ,GAAG;AAAA,MACvB,CAAC;AAAA,IACH,OAAO;AACL,cAAQ,KAAK,GAAG,YAAY,QAAQ,GAAG,GAAG,QAAQ,GAAG,GAAG,SAAS,CAAC;AAAA,IACpE;AAAA,EACF;AACF;AAEO,SAAS,aAAa,SAA6C;AACxE,QAAM,MAAM,oBAAI,IAAsB;AACtC,aAAW,SAAS,SAAS;AAC3B,QAAI,IAAI,MAAM,MAAM,MAAM,IAAI;AAAA,EAChC;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/tree.ts","../src/operations.ts","../src/history.ts","../src/schema.ts","../src/validate.ts","../src/search.ts","../src/diff.ts"],"sourcesContent":["export type {\n JsonValue,\n JsonPrimitive,\n JsonArray,\n JsonObject,\n NodeType,\n TreeNode,\n TreeState,\n JsonSchema,\n JsonSchemaProperty,\n} from \"./types\";\n\nexport {\n fromJson,\n toJson,\n findNode,\n findNodeByPath,\n isDescendant,\n resetIdCounter,\n getNodeType,\n generateId,\n buildSubtree,\n reparentSubtree,\n} from \"./tree\";\n\nexport {\n setValue,\n setKey,\n addProperty,\n insertProperty,\n insertNode,\n removeNode,\n moveNode,\n reorderChildren,\n reorderChildrenMulti,\n changeType,\n duplicateNode,\n} from \"./operations\";\n\nexport { History } from \"./history\";\n\nexport {\n resolveSchema,\n resolveRef,\n getPropertySchema,\n clearSchemaCache,\n} from \"./schema\";\n\nexport { validateNode, type ValidationResult } from \"./validate\";\n\nexport { searchNodes, getAncestorIds, type SearchMatch } from \"./search\";\n\nexport {\n computeDiff,\n getDiffPaths,\n type DiffEntry,\n type DiffType,\n} from \"./diff\";\n","import type {\n JsonPrimitive,\n JsonValue,\n JsonObject,\n JsonArray,\n NodeType,\n TreeNode,\n TreeState,\n} from \"./types\";\n\nlet nextId = 0;\n\nexport function generateId(): string {\n return `node_${++nextId}`;\n}\n\nexport function resetIdCounter(): void {\n nextId = 0;\n}\n\nexport function getNodeType(value: JsonValue): NodeType {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"array\";\n return typeof value as NodeType;\n}\n\nexport function buildSubtree(\n key: string,\n value: JsonValue,\n parentPath: string,\n parentId: string | null,\n nodesById: Map<string, TreeNode>,\n): TreeNode {\n const id = generateId();\n const path = parentPath ? `${parentPath}/${key}` : `/${key}`;\n const type = getNodeType(value);\n\n const node: TreeNode = {\n id,\n key,\n path,\n type,\n value:\n type === \"object\" || type === \"array\"\n ? undefined\n : (value as JsonPrimitive),\n children: [],\n parentId,\n };\n\n nodesById.set(id, node);\n\n if (type === \"object\" && value !== null) {\n const obj = value as JsonObject;\n node.children = Object.keys(obj).map((childKey) =>\n buildSubtree(childKey, obj[childKey], path, id, nodesById),\n );\n } else if (type === \"array\") {\n const arr = value as JsonArray;\n node.children = arr.map((item, index) =>\n buildSubtree(String(index), item, path, id, nodesById),\n );\n }\n\n return node;\n}\n\nexport function fromJson(value: JsonValue): TreeState {\n const nodesById = new Map<string, TreeNode>();\n\n const rootType = getNodeType(value);\n const root: TreeNode = {\n id: generateId(),\n key: \"\",\n path: \"/\",\n type: rootType,\n value:\n rootType === \"object\" || rootType === \"array\"\n ? undefined\n : (value as JsonPrimitive),\n children: [],\n parentId: null,\n };\n\n nodesById.set(root.id, root);\n\n if (rootType === \"object\" && value !== null) {\n const obj = value as JsonObject;\n root.children = Object.keys(obj).map((key) =>\n buildSubtree(key, obj[key], \"\", root.id, nodesById),\n );\n } else if (rootType === \"array\") {\n const arr = value as JsonArray;\n root.children = arr.map((item, index) =>\n buildSubtree(String(index), item, \"\", root.id, nodesById),\n );\n }\n\n return { root, nodesById };\n}\n\nexport function toJson(node: TreeNode): JsonValue {\n switch (node.type) {\n case \"object\": {\n const obj: JsonObject = {};\n for (const child of node.children) {\n obj[child.key] = toJson(child);\n }\n return obj;\n }\n case \"array\":\n return node.children.map((child) => toJson(child));\n default:\n return node.value as JsonValue;\n }\n}\n\n/**\n * Clone a subtree with updated key, path, and parentId while preserving\n * all original node IDs. Used for cross-parent moves where identity must\n * be retained so that UI state (expanded, selected, etc.) stays valid.\n */\nexport function reparentSubtree(\n node: TreeNode,\n newKey: string,\n parentPath: string,\n newParentId: string,\n): TreeNode {\n const newPath = parentPath ? `${parentPath}/${newKey}` : `/${newKey}`;\n return {\n ...node,\n key: newKey,\n path: newPath,\n parentId: newParentId,\n children: node.children.map((child, i) =>\n reparentSubtree(\n child,\n node.type === \"array\" ? String(i) : child.key,\n newPath,\n node.id,\n ),\n ),\n };\n}\n\nexport function findNode(\n state: TreeState,\n nodeId: string,\n): TreeNode | undefined {\n return state.nodesById.get(nodeId);\n}\n\nexport function findNodeByPath(\n state: TreeState,\n path: string,\n): TreeNode | undefined {\n if (path === \"/\") return state.root;\n\n const segments = path.split(\"/\").filter(Boolean);\n let current = state.root;\n\n for (const segment of segments) {\n const child = current.children.find((c) => c.key === segment);\n if (!child) return undefined;\n current = child;\n }\n\n return current;\n}\n\n/**\n * Check whether `nodeId` is a descendant of `potentialAncestorId` by walking\n * up `parentId` links. Returns `true` when the two IDs are equal (a node is\n * considered a descendant of itself).\n */\nexport function isDescendant(\n tree: TreeState,\n nodeId: string,\n potentialAncestorId: string,\n): boolean {\n let current = tree.nodesById.get(nodeId);\n while (current) {\n if (current.id === potentialAncestorId) return true;\n current = current.parentId\n ? tree.nodesById.get(current.parentId)\n : undefined;\n }\n return false;\n}\n","import type {\n JsonPrimitive,\n JsonValue,\n NodeType,\n TreeNode,\n TreeState,\n} from \"./types\";\nimport { toJson, getNodeType, buildSubtree, reparentSubtree } from \"./tree\";\n\nfunction rebuildMap(root: TreeNode): Map<string, TreeNode> {\n const map = new Map<string, TreeNode>();\n function walk(node: TreeNode) {\n map.set(node.id, node);\n for (const child of node.children) walk(child);\n }\n walk(root);\n return map;\n}\n\nfunction recomputePaths(node: TreeNode, newParentPath: string): TreeNode {\n const newPath = newParentPath\n ? `${newParentPath}/${node.key}`\n : `/${node.key}`;\n if (node.path === newPath && node.children.length === 0) return node;\n return {\n ...node,\n path: newPath,\n children: node.children.map((child) => recomputePaths(child, newPath)),\n };\n}\n\n/**\n * Clone only the ancestor chain from root to `targetId` (structural sharing),\n * apply `updater` to the target, and rebuild the `nodesById` map.\n */\nfunction clonePathToNode(\n state: TreeState,\n targetId: string,\n updater: (node: TreeNode) => TreeNode,\n): TreeState {\n const chain: string[] = [];\n let cur: TreeNode | undefined = state.nodesById.get(targetId);\n while (cur) {\n chain.unshift(cur.id);\n cur = cur.parentId ? state.nodesById.get(cur.parentId) : undefined;\n }\n if (chain.length === 0) return state;\n\n function cloneAlongPath(node: TreeNode, depth: number): TreeNode {\n if (depth === chain.length - 1) {\n return updater(node);\n }\n const nextInChain = chain[depth + 1];\n return {\n ...node,\n children: node.children.map((child) =>\n child.id === nextInChain ? cloneAlongPath(child, depth + 1) : child,\n ),\n };\n }\n\n const newRoot = cloneAlongPath(state.root, 0);\n return { root: newRoot, nodesById: rebuildMap(newRoot) };\n}\n\nfunction reindexArrayChildren(parent: TreeNode): TreeNode {\n if (parent.type !== \"array\") return parent;\n const parentPath = parent.path === \"/\" ? \"\" : parent.path;\n return {\n ...parent,\n children: parent.children.map((child, i) => {\n const newKey = String(i);\n if (child.key === newKey) return child;\n return recomputePaths({ ...child, key: newKey }, parentPath);\n }),\n };\n}\n\nexport function setValue(\n state: TreeState,\n nodeId: string,\n value: JsonValue,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node) return state;\n\n const newType = getNodeType(value);\n\n if (newType !== \"object\" && newType !== \"array\") {\n return clonePathToNode(state, nodeId, (n) => ({\n ...n,\n type: newType,\n value: value as JsonPrimitive,\n children: [],\n }));\n }\n\n return clonePathToNode(state, nodeId, (n) => {\n const parentPath = n.path.split(\"/\").slice(0, -1).join(\"/\") || \"\";\n const nodesById = new Map<string, TreeNode>();\n const subtree = buildSubtree(\n n.key,\n value,\n parentPath,\n n.parentId,\n nodesById,\n );\n return { ...subtree, id: n.id };\n });\n}\n\nexport function setKey(\n state: TreeState,\n nodeId: string,\n newKey: string,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const parent = state.nodesById.get(node.parentId);\n if (!parent || parent.type !== \"object\") return state;\n\n return clonePathToNode(state, nodeId, (n) => {\n const parentPath = parent.path === \"/\" ? \"\" : parent.path;\n const newPath = `${parentPath}/${newKey}`;\n const updated: TreeNode = { ...n, key: newKey, path: newPath };\n if (updated.children.length > 0) {\n updated.children = updated.children.map((child) =>\n recomputePaths(child, newPath),\n );\n }\n return updated;\n });\n}\n\nexport function addProperty(\n state: TreeState,\n parentId: string,\n key: string,\n value: JsonValue,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newChild = buildSubtree(key, value, parentPath, p.id, new Map());\n return { ...p, children: [...p.children, newChild] };\n });\n}\n\nexport function insertProperty(\n state: TreeState,\n parentId: string,\n key: string,\n value: JsonValue,\n index: number,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newChild = buildSubtree(key, value, parentPath, p.id, new Map());\n const newChildren = [...p.children];\n newChildren.splice(index, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function insertNode(\n state: TreeState,\n parentId: string,\n node: TreeNode,\n index: number,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const key = p.type === \"array\" ? String(index) : node.key;\n const reparented = reparentSubtree(node, key, parentPath, p.id);\n const newChildren = [...p.children];\n newChildren.splice(index, 0, reparented);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function removeNode(state: TreeState, nodeId: string): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n return clonePathToNode(state, node.parentId, (p) => {\n const newChildren = p.children.filter((c) => c.id !== nodeId);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function moveNode(\n state: TreeState,\n nodeId: string,\n newParentId: string,\n index?: number,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const srcParent = state.nodesById.get(node.parentId);\n const dstParent = state.nodesById.get(newParentId);\n if (!srcParent || !dstParent) return state;\n\n const nodeValue = toJson(node);\n\n const removed = clonePathToNode(state, node.parentId, (p) => {\n const newChildren = p.children.filter((c) => c.id !== nodeId);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n\n return clonePathToNode(removed, newParentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newChild = buildSubtree(\n p.type === \"array\" ? String(index ?? p.children.length) : node.key,\n nodeValue,\n parentPath,\n p.id,\n new Map(),\n );\n const newChildren = [...p.children];\n const insertAt = index ?? newChildren.length;\n newChildren.splice(insertAt, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function reorderChildren(\n state: TreeState,\n parentId: string,\n fromIndex: number,\n toIndex: number,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const newChildren = [...p.children];\n const [item] = newChildren.splice(fromIndex, 1);\n newChildren.splice(toIndex, 0, item);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function reorderChildrenMulti(\n state: TreeState,\n parentId: string,\n movedIds: string[],\n targetSiblingId: string,\n position: \"before\" | \"after\",\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n const movedSet = new Set(movedIds);\n\n return clonePathToNode(state, parentId, (p) => {\n const remaining = p.children.filter((c) => !movedSet.has(c.id));\n let insertIdx = remaining.findIndex((c) => c.id === targetSiblingId);\n if (insertIdx === -1) {\n if (movedSet.has(targetSiblingId)) {\n const origIdx = p.children.findIndex((c) => c.id === targetSiblingId);\n const origMap = new Map(p.children.map((c, i) => [c.id, i]));\n if (position === \"after\") {\n insertIdx = remaining.findIndex(\n (c) => (origMap.get(c.id) ?? -1) > origIdx,\n );\n if (insertIdx === -1) insertIdx = remaining.length;\n } else {\n insertIdx = remaining.findIndex(\n (c) => (origMap.get(c.id) ?? -1) >= origIdx,\n );\n if (insertIdx === -1) insertIdx = remaining.length;\n }\n } else {\n insertIdx = position === \"after\" ? remaining.length : 0;\n }\n } else if (position === \"after\") {\n insertIdx++;\n }\n const moved = movedIds\n .map((id) => p.children.find((c) => c.id === id))\n .filter((c): c is TreeNode => c !== undefined);\n const newChildren = [...remaining];\n newChildren.splice(insertIdx, 0, ...moved);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nfunction convertValue(current: JsonValue, newType: NodeType): JsonValue {\n switch (newType) {\n case \"string\":\n if (current === null || current === undefined) return \"\";\n if (typeof current === \"object\") return JSON.stringify(current);\n return String(current);\n case \"number\": {\n const n = Number(current);\n return isNaN(n) ? 0 : n;\n }\n case \"boolean\":\n return Boolean(current);\n case \"null\":\n return null;\n case \"object\":\n if (\n current !== null &&\n typeof current === \"object\" &&\n !Array.isArray(current)\n )\n return current;\n if (Array.isArray(current)) {\n const obj: Record<string, JsonValue> = {};\n current.forEach((item, i) => {\n obj[String(i)] = item;\n });\n return obj;\n }\n return {};\n case \"array\":\n if (Array.isArray(current)) return current;\n if (current !== null && typeof current === \"object\")\n return Object.values(current);\n return current === null || current === undefined ? [] : [current];\n default:\n return current;\n }\n}\n\nexport function changeType(\n state: TreeState,\n nodeId: string,\n newType: NodeType,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node) return state;\n\n const currentValue = toJson(node);\n const newValue = convertValue(currentValue, newType);\n return setValue(state, nodeId, newValue);\n}\n\nexport function duplicateNode(state: TreeState, nodeId: string): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const parent = state.nodesById.get(node.parentId);\n if (!parent) return state;\n\n const nodeValue = toJson(node);\n\n return clonePathToNode(state, node.parentId, (p) => {\n const idx = p.children.findIndex((c) => c.id === nodeId);\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newKey = p.type === \"array\" ? String(idx + 1) : `${node.key}_copy`;\n const newChild = buildSubtree(\n newKey,\n structuredClone(nodeValue),\n parentPath,\n p.id,\n new Map(),\n );\n const newChildren = [...p.children];\n newChildren.splice(idx + 1, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n","import type { TreeState } from \"./types\";\n\nconst MAX_HISTORY = 100;\n\nexport class History {\n private stack: TreeState[] = [];\n private cursor = -1;\n\n push(state: TreeState): void {\n this.stack = this.stack.slice(0, this.cursor + 1);\n this.stack.push(state);\n if (this.stack.length > MAX_HISTORY) {\n this.stack.shift();\n } else {\n this.cursor++;\n }\n }\n\n undo(): TreeState | null {\n if (!this.canUndo) return null;\n this.cursor--;\n return this.stack[this.cursor];\n }\n\n redo(): TreeState | null {\n if (!this.canRedo) return null;\n this.cursor++;\n return this.stack[this.cursor];\n }\n\n get canUndo(): boolean {\n return this.cursor > 0;\n }\n\n get canRedo(): boolean {\n return this.cursor < this.stack.length - 1;\n }\n\n get current(): TreeState | null {\n return this.stack[this.cursor] ?? null;\n }\n}\n","import type {\n JsonSchema,\n JsonSchemaProperty,\n JsonValue,\n JsonObject,\n} from \"./types\";\n\nconst KNOWN_SCHEMAS: Record<string, string> = {\n \"package.json\": \"https://json.schemastore.org/package.json\",\n \"tsconfig.json\": \"https://json.schemastore.org/tsconfig\",\n \"tsconfig.base.json\": \"https://json.schemastore.org/tsconfig\",\n \".eslintrc.json\": \"https://json.schemastore.org/eslintrc\",\n \".prettierrc\": \"https://json.schemastore.org/prettierrc\",\n \".prettierrc.json\": \"https://json.schemastore.org/prettierrc\",\n \"turbo.json\": \"https://turborepo.dev/schema.json\",\n \".babelrc\": \"https://json.schemastore.org/babelrc\",\n \"nest-cli.json\": \"https://json.schemastore.org/nest-cli\",\n \"vercel.json\": \"https://openapi.vercel.sh/vercel.json\",\n \".swcrc\": \"https://json.schemastore.org/swcrc\",\n};\n\nconst MAX_SCHEMA_CACHE = 50;\nconst schemaCache = new Map<string, JsonSchema>();\n\nasync function fetchSchema(url: string): Promise<JsonSchema | null> {\n if (schemaCache.has(url)) {\n return schemaCache.get(url)!;\n }\n try {\n const res = await fetch(url);\n if (!res.ok) return null;\n const schema = (await res.json()) as JsonSchema;\n if (schemaCache.size >= MAX_SCHEMA_CACHE) {\n const oldest = schemaCache.keys().next().value;\n if (oldest !== undefined) schemaCache.delete(oldest);\n }\n schemaCache.set(url, schema);\n return schema;\n } catch {\n return null;\n }\n}\n\nexport async function resolveSchema(\n json: JsonValue,\n filename?: string,\n): Promise<JsonSchema | null> {\n if (\n json !== null &&\n typeof json === \"object\" &&\n !Array.isArray(json) &&\n typeof (json as JsonObject)[\"$schema\"] === \"string\"\n ) {\n const url = (json as JsonObject)[\"$schema\"] as string;\n const schema = await fetchSchema(url);\n if (schema) return schema;\n }\n\n if (filename) {\n const base = filename.split(\"/\").pop() ?? filename;\n const knownUrl = KNOWN_SCHEMAS[base];\n if (knownUrl) {\n return fetchSchema(knownUrl);\n }\n }\n\n return null;\n}\n\nfunction findDefinition(\n root: JsonSchemaProperty,\n refPath: string,\n): JsonSchemaProperty | undefined {\n if (!refPath.startsWith(\"#/\")) return undefined;\n const segments = refPath.slice(2).split(\"/\");\n let current: unknown = root;\n\n for (const seg of segments) {\n if (current === null || typeof current !== \"object\") return undefined;\n current = (current as Record<string, unknown>)[seg];\n }\n\n return current as JsonSchemaProperty | undefined;\n}\n\n/**\n * Resolve `$ref` pointers and merge `allOf` within a schema.\n * `visited` tracks refs to prevent infinite cycles.\n */\nexport function resolveRef(\n prop: JsonSchemaProperty,\n root: JsonSchemaProperty,\n visited?: Set<string>,\n): JsonSchemaProperty {\n const seen = visited ?? new Set<string>();\n\n if (prop.$ref) {\n if (seen.has(prop.$ref)) return prop;\n seen.add(prop.$ref);\n const resolved = findDefinition(root, prop.$ref);\n if (resolved) {\n return resolveRef(resolved, root, seen);\n }\n return prop;\n }\n\n if (prop.allOf && prop.allOf.length > 0) {\n return mergeAllOf(prop, root, seen);\n }\n\n return prop;\n}\n\nfunction mergeAllOf(\n prop: JsonSchemaProperty,\n root: JsonSchemaProperty,\n visited: Set<string>,\n): JsonSchemaProperty {\n const merged: JsonSchemaProperty = { ...prop };\n delete merged.allOf;\n\n for (const sub of prop.allOf!) {\n const resolved = resolveRef(sub, root, new Set(visited));\n if (resolved.type && !merged.type) merged.type = resolved.type;\n if (resolved.properties) {\n merged.properties = { ...merged.properties, ...resolved.properties };\n }\n if (resolved.required) {\n merged.required = [\n ...new Set([...(merged.required ?? []), ...resolved.required]),\n ];\n }\n if (\n resolved.additionalProperties !== undefined &&\n merged.additionalProperties === undefined\n ) {\n merged.additionalProperties = resolved.additionalProperties;\n }\n if (resolved.items && !merged.items) merged.items = resolved.items;\n if (resolved.description && !merged.description)\n merged.description = resolved.description;\n if (resolved.title && !merged.title) merged.title = resolved.title;\n if (resolved.enum && !merged.enum) merged.enum = resolved.enum;\n if (resolved.minimum !== undefined && merged.minimum === undefined)\n merged.minimum = resolved.minimum;\n if (resolved.maximum !== undefined && merged.maximum === undefined)\n merged.maximum = resolved.maximum;\n if (resolved.minLength !== undefined && merged.minLength === undefined)\n merged.minLength = resolved.minLength;\n if (resolved.maxLength !== undefined && merged.maxLength === undefined)\n merged.maxLength = resolved.maxLength;\n if (resolved.pattern && !merged.pattern) merged.pattern = resolved.pattern;\n if (resolved.format && !merged.format) merged.format = resolved.format;\n }\n\n return merged;\n}\n\nexport function getPropertySchema(\n schema: JsonSchema | JsonSchemaProperty,\n path: string,\n rootSchema?: JsonSchemaProperty,\n): JsonSchemaProperty | undefined {\n const root = rootSchema ?? schema;\n const segments = path.split(\"/\").filter(Boolean);\n let current: JsonSchemaProperty | undefined = resolveRef(schema, root);\n\n for (const seg of segments) {\n if (!current) return undefined;\n current = resolveRef(current, root);\n\n if (current.properties?.[seg]) {\n current = resolveRef(current.properties[seg], root);\n continue;\n }\n\n if (current.patternProperties) {\n const match = Object.entries(current.patternProperties).find(\n ([pattern]) => {\n try {\n return new RegExp(pattern).test(seg);\n } catch {\n return false;\n }\n },\n );\n if (match) {\n current = resolveRef(match[1], root);\n continue;\n }\n }\n\n if (\n current.additionalProperties &&\n typeof current.additionalProperties === \"object\"\n ) {\n current = resolveRef(current.additionalProperties, root);\n continue;\n }\n\n if (current.items) {\n if (Array.isArray(current.items)) {\n const idx = Number(seg);\n if (!isNaN(idx) && current.items[idx]) {\n current = resolveRef(current.items[idx], root);\n continue;\n }\n } else {\n current = resolveRef(current.items, root);\n continue;\n }\n }\n\n if (current.anyOf || current.oneOf) {\n const variants = current.anyOf ?? current.oneOf ?? [];\n let found: JsonSchemaProperty | undefined;\n for (const variant of variants) {\n const resolved = resolveRef(variant, root);\n found = getPropertySchema(resolved, seg, root);\n if (found) break;\n }\n if (found) {\n current = found;\n continue;\n }\n return undefined;\n }\n\n return undefined;\n }\n\n return current;\n}\n\nexport function clearSchemaCache(): void {\n schemaCache.clear();\n}\n","import type { TreeNode, JsonSchemaProperty } from \"./types\";\n\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n}\n\nfunction schemaTypeMatches(\n nodeType: string,\n schemaType: string | string[] | undefined,\n): boolean {\n if (!schemaType) return true;\n const types = Array.isArray(schemaType) ? schemaType : [schemaType];\n\n if (nodeType === \"number\" && types.includes(\"integer\")) return true;\n return types.includes(nodeType);\n}\n\nconst FORMAT_PATTERNS: Record<string, RegExp> = {\n email: /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/,\n uri: /^https?:\\/\\/.+/,\n \"uri-reference\": /^(https?:\\/\\/|\\/|\\.\\.?\\/|#).*/,\n \"date-time\": /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/,\n date: /^\\d{4}-\\d{2}-\\d{2}$/,\n time: /^\\d{2}:\\d{2}:\\d{2}/,\n ipv4: /^(\\d{1,3}\\.){3}\\d{1,3}$/,\n ipv6: /^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$/,\n uuid: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,\n hostname:\n /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$/,\n};\n\nexport function validateNode(\n node: TreeNode,\n schema: JsonSchemaProperty | undefined,\n): ValidationResult {\n const errors: string[] = [];\n\n if (!schema) {\n return { valid: true, errors };\n }\n\n if (schema.type && !schemaTypeMatches(node.type, schema.type)) {\n const expected = Array.isArray(schema.type)\n ? schema.type.join(\" | \")\n : schema.type;\n errors.push(`Expected type \"${expected}\", got \"${node.type}\"`);\n }\n\n if (schema.enum && schema.enum.length > 0 && node.value !== undefined) {\n const match = schema.enum.some(\n (v) => JSON.stringify(v) === JSON.stringify(node.value),\n );\n if (!match) {\n errors.push(\n `Value must be one of: ${schema.enum.map((v) => JSON.stringify(v)).join(\", \")}`,\n );\n }\n }\n\n if (schema.const !== undefined && node.value !== undefined) {\n if (JSON.stringify(node.value) !== JSON.stringify(schema.const)) {\n errors.push(`Value must be ${JSON.stringify(schema.const)}`);\n }\n }\n\n if (schema.required && (node.type === \"object\" || node.type === \"array\")) {\n const childKeys = new Set(node.children.map((c) => c.key));\n for (const req of schema.required) {\n if (!childKeys.has(req)) {\n errors.push(`Missing required property \"${req}\"`);\n }\n }\n }\n\n if (node.type === \"number\" && typeof node.value === \"number\") {\n const val = node.value;\n if (schema.minimum !== undefined && val < schema.minimum) {\n errors.push(`Value must be >= ${schema.minimum}`);\n }\n if (schema.maximum !== undefined && val > schema.maximum) {\n errors.push(`Value must be <= ${schema.maximum}`);\n }\n if (schema.exclusiveMinimum !== undefined) {\n const bound =\n typeof schema.exclusiveMinimum === \"number\"\n ? schema.exclusiveMinimum\n : schema.minimum;\n if (bound !== undefined && val <= bound) {\n errors.push(`Value must be > ${bound}`);\n }\n }\n if (schema.exclusiveMaximum !== undefined) {\n const bound =\n typeof schema.exclusiveMaximum === \"number\"\n ? schema.exclusiveMaximum\n : schema.maximum;\n if (bound !== undefined && val >= bound) {\n errors.push(`Value must be < ${bound}`);\n }\n }\n if (schema.multipleOf !== undefined) {\n const remainder = Math.abs(val % schema.multipleOf);\n if (\n remainder > 1e-10 &&\n Math.abs(remainder - schema.multipleOf) > 1e-10\n ) {\n errors.push(`Value must be a multiple of ${schema.multipleOf}`);\n }\n }\n }\n\n if (node.type === \"string\" && typeof node.value === \"string\") {\n const val = node.value;\n if (schema.minLength !== undefined && val.length < schema.minLength) {\n errors.push(`Must be at least ${schema.minLength} characters`);\n }\n if (schema.maxLength !== undefined && val.length > schema.maxLength) {\n errors.push(`Must be at most ${schema.maxLength} characters`);\n }\n if (schema.pattern) {\n try {\n if (!new RegExp(schema.pattern).test(val)) {\n errors.push(`Must match pattern: ${schema.pattern}`);\n }\n } catch {\n // invalid regex in schema, skip\n }\n }\n if (schema.format && FORMAT_PATTERNS[schema.format]) {\n if (!FORMAT_PATTERNS[schema.format].test(val)) {\n errors.push(`Invalid ${schema.format} format`);\n }\n }\n }\n\n if (node.type === \"array\") {\n if (\n schema.minItems !== undefined &&\n node.children.length < schema.minItems\n ) {\n errors.push(`Must have at least ${schema.minItems} items`);\n }\n if (\n schema.maxItems !== undefined &&\n node.children.length > schema.maxItems\n ) {\n errors.push(`Must have at most ${schema.maxItems} items`);\n }\n }\n\n if (node.type === \"object\") {\n if (\n schema.minProperties !== undefined &&\n node.children.length < schema.minProperties\n ) {\n errors.push(`Must have at least ${schema.minProperties} properties`);\n }\n if (\n schema.maxProperties !== undefined &&\n node.children.length > schema.maxProperties\n ) {\n errors.push(`Must have at most ${schema.maxProperties} properties`);\n }\n }\n\n return { valid: errors.length === 0, errors };\n}\n","import type { TreeNode, TreeState } from \"./types\";\n\nexport interface SearchMatch {\n nodeId: string;\n field: \"key\" | \"value\";\n}\n\nexport function searchNodes(tree: TreeState, query: string): SearchMatch[] {\n if (!query.trim()) return [];\n const matches: SearchMatch[] = [];\n const lower = query.toLowerCase();\n\n function walk(node: TreeNode) {\n if (node.key && node.key.toLowerCase().includes(lower)) {\n matches.push({ nodeId: node.id, field: \"key\" });\n }\n if (\n node.value !== undefined &&\n node.value !== null &&\n String(node.value).toLowerCase().includes(lower)\n ) {\n matches.push({ nodeId: node.id, field: \"value\" });\n }\n for (const child of node.children) {\n walk(child);\n }\n }\n\n walk(tree.root);\n return matches;\n}\n\n/**\n * Collect all ancestor node IDs for each matched node so the tree\n * can auto-expand paths to search results.\n */\nexport function getAncestorIds(\n tree: TreeState,\n nodeIds: string[],\n): Set<string> {\n const ancestors = new Set<string>();\n\n for (const nodeId of nodeIds) {\n let current = tree.nodesById.get(nodeId);\n while (current && current.parentId) {\n ancestors.add(current.parentId);\n current = tree.nodesById.get(current.parentId);\n }\n }\n\n return ancestors;\n}\n","import type { JsonValue } from \"./types\";\n\nexport type DiffType = \"added\" | \"removed\" | \"changed\";\n\nexport interface DiffEntry {\n path: string;\n type: DiffType;\n oldValue?: JsonValue;\n newValue?: JsonValue;\n}\n\nexport function computeDiff(\n original: JsonValue,\n current: JsonValue,\n path = \"\",\n): DiffEntry[] {\n const entries: DiffEntry[] = [];\n\n if (original === current) {\n return entries;\n }\n\n if (\n original === null ||\n current === null ||\n typeof original !== typeof current ||\n Array.isArray(original) !== Array.isArray(current)\n ) {\n if (path) {\n entries.push({\n path,\n type: \"changed\",\n oldValue: original,\n newValue: current,\n });\n } else {\n diffObject(original, current, path, entries);\n }\n return entries;\n }\n\n if (typeof original !== \"object\") {\n if (original !== current) {\n entries.push({\n path: path || \"/\",\n type: \"changed\",\n oldValue: original,\n newValue: current,\n });\n }\n return entries;\n }\n\n if (Array.isArray(original) && Array.isArray(current)) {\n const maxLen = Math.max(original.length, current.length);\n for (let i = 0; i < maxLen; i++) {\n const childPath = path ? `${path}/${i}` : `/${i}`;\n if (i >= original.length) {\n entries.push({ path: childPath, type: \"added\", newValue: current[i] });\n } else if (i >= current.length) {\n entries.push({\n path: childPath,\n type: \"removed\",\n oldValue: original[i],\n });\n } else {\n entries.push(...computeDiff(original[i], current[i], childPath));\n }\n }\n return entries;\n }\n\n diffObject(original, current, path, entries);\n return entries;\n}\n\nfunction diffObject(\n original: JsonValue,\n current: JsonValue,\n path: string,\n entries: DiffEntry[],\n) {\n const origObj =\n original !== null &&\n typeof original === \"object\" &&\n !Array.isArray(original)\n ? (original as Record<string, JsonValue>)\n : {};\n const currObj =\n current !== null && typeof current === \"object\" && !Array.isArray(current)\n ? (current as Record<string, JsonValue>)\n : {};\n\n const allKeys = new Set([...Object.keys(origObj), ...Object.keys(currObj)]);\n\n for (const key of allKeys) {\n const childPath = path ? `${path}/${key}` : `/${key}`;\n const inOriginal = key in origObj;\n const inCurrent = key in currObj;\n\n if (!inOriginal && inCurrent) {\n entries.push({ path: childPath, type: \"added\", newValue: currObj[key] });\n } else if (inOriginal && !inCurrent) {\n entries.push({\n path: childPath,\n type: \"removed\",\n oldValue: origObj[key],\n });\n } else {\n entries.push(...computeDiff(origObj[key], currObj[key], childPath));\n }\n }\n}\n\nexport function getDiffPaths(entries: DiffEntry[]): Map<string, DiffType> {\n const map = new Map<string, DiffType>();\n for (const entry of entries) {\n map.set(entry.path, entry.type);\n }\n return map;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,IAAI,SAAS;AAEN,SAAS,aAAqB;AACnC,SAAO,QAAQ,EAAE,MAAM;AACzB;AAEO,SAAS,iBAAuB;AACrC,WAAS;AACX;AAEO,SAAS,YAAY,OAA4B;AACtD,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO;AACjC,SAAO,OAAO;AAChB;AAEO,SAAS,aACd,KACA,OACA,YACA,UACA,WACU;AACV,QAAM,KAAK,WAAW;AACtB,QAAM,OAAO,aAAa,GAAG,UAAU,IAAI,GAAG,KAAK,IAAI,GAAG;AAC1D,QAAM,OAAO,YAAY,KAAK;AAE9B,QAAM,OAAiB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OACE,SAAS,YAAY,SAAS,UAC1B,S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AAA,QACN,MAAM;AAAA,QACN,UAAU,QAAQ,GAAG;AAAA,MACvB,CAAC;AAAA,IACH,OAAO;AACL,cAAQ,KAAK,GAAG,YAAY,QAAQ,GAAG,GAAG,QAAQ,GAAG,GAAG,SAAS,CAAC;AAAA,IACpE;AAAA,EACF;AACF;AAEO,SAAS,aAAa,SAA6C;AACxE,QAAM,MAAM,oBAAI,IAAsB;AACtC,aAAW,SAAS,SAAS;AAC3B,QAAI,IAAI,MAAM,MAAM,MAAM,IAAI;AAAA,EAChC;AACA,SAAO;AACT;","names":[]}
package/dist/index.mjs CHANGED
@@ -79,6 +79,23 @@ function toJson(node) {
79
79
  return node.value;
80
80
  }
81
81
  }
82
+ function reparentSubtree(node, newKey, parentPath, newParentId) {
83
+ const newPath = parentPath ? `${parentPath}/${newKey}` : `/${newKey}`;
84
+ return {
85
+ ...node,
86
+ key: newKey,
87
+ path: newPath,
88
+ parentId: newParentId,
89
+ children: node.children.map(
90
+ (child, i) => reparentSubtree(
91
+ child,
92
+ node.type === "array" ? String(i) : child.key,
93
+ newPath,
94
+ node.id
95
+ )
96
+ )
97
+ };
98
+ }
82
99
  function findNode(state, nodeId) {
83
100
  return state.nodesById.get(nodeId);
84
101
  }
@@ -93,6 +110,14 @@ function findNodeByPath(state, path) {
93
110
  }
94
111
  return current;
95
112
  }
113
+ function isDescendant(tree, nodeId, potentialAncestorId) {
114
+ let current = tree.nodesById.get(nodeId);
115
+ while (current) {
116
+ if (current.id === potentialAncestorId) return true;
117
+ current = current.parentId ? tree.nodesById.get(current.parentId) : void 0;
118
+ }
119
+ return false;
120
+ }
96
121
 
97
122
  // src/operations.ts
98
123
  function rebuildMap(root) {
@@ -163,7 +188,13 @@ function setValue(state, nodeId, value) {
163
188
  return clonePathToNode(state, nodeId, (n) => {
164
189
  const parentPath = n.path.split("/").slice(0, -1).join("/") || "";
165
190
  const nodesById = /* @__PURE__ */ new Map();
166
- const subtree = buildSubtree(n.key, value, parentPath, n.parentId, nodesById);
191
+ const subtree = buildSubtree(
192
+ n.key,
193
+ value,
194
+ parentPath,
195
+ n.parentId,
196
+ nodesById
197
+ );
167
198
  return { ...subtree, id: n.id };
168
199
  });
169
200
  }
@@ -189,11 +220,33 @@ function addProperty(state, parentId, key, value) {
189
220
  if (!parent) return state;
190
221
  return clonePathToNode(state, parentId, (p) => {
191
222
  const parentPath = p.path === "/" ? "" : p.path;
192
- const nodesById = /* @__PURE__ */ new Map();
193
- const newChild = buildSubtree(key, value, parentPath, p.id, nodesById);
223
+ const newChild = buildSubtree(key, value, parentPath, p.id, /* @__PURE__ */ new Map());
194
224
  return { ...p, children: [...p.children, newChild] };
195
225
  });
196
226
  }
227
+ function insertProperty(state, parentId, key, value, index) {
228
+ const parent = state.nodesById.get(parentId);
229
+ if (!parent) return state;
230
+ return clonePathToNode(state, parentId, (p) => {
231
+ const parentPath = p.path === "/" ? "" : p.path;
232
+ const newChild = buildSubtree(key, value, parentPath, p.id, /* @__PURE__ */ new Map());
233
+ const newChildren = [...p.children];
234
+ newChildren.splice(index, 0, newChild);
235
+ return reindexArrayChildren({ ...p, children: newChildren });
236
+ });
237
+ }
238
+ function insertNode(state, parentId, node, index) {
239
+ const parent = state.nodesById.get(parentId);
240
+ if (!parent) return state;
241
+ return clonePathToNode(state, parentId, (p) => {
242
+ const parentPath = p.path === "/" ? "" : p.path;
243
+ const key = p.type === "array" ? String(index) : node.key;
244
+ const reparented = reparentSubtree(node, key, parentPath, p.id);
245
+ const newChildren = [...p.children];
246
+ newChildren.splice(index, 0, reparented);
247
+ return reindexArrayChildren({ ...p, children: newChildren });
248
+ });
249
+ }
197
250
  function removeNode(state, nodeId) {
198
251
  const node = state.nodesById.get(nodeId);
199
252
  if (!node || !node.parentId) return state;
@@ -215,13 +268,12 @@ function moveNode(state, nodeId, newParentId, index) {
215
268
  });
216
269
  return clonePathToNode(removed, newParentId, (p) => {
217
270
  const parentPath = p.path === "/" ? "" : p.path;
218
- const nodesById = /* @__PURE__ */ new Map();
219
271
  const newChild = buildSubtree(
220
272
  p.type === "array" ? String(index ?? p.children.length) : node.key,
221
273
  nodeValue,
222
274
  parentPath,
223
275
  p.id,
224
- nodesById
276
+ /* @__PURE__ */ new Map()
225
277
  );
226
278
  const newChildren = [...p.children];
227
279
  const insertAt = index ?? newChildren.length;
@@ -239,6 +291,40 @@ function reorderChildren(state, parentId, fromIndex, toIndex) {
239
291
  return reindexArrayChildren({ ...p, children: newChildren });
240
292
  });
241
293
  }
294
+ function reorderChildrenMulti(state, parentId, movedIds, targetSiblingId, position) {
295
+ const parent = state.nodesById.get(parentId);
296
+ if (!parent) return state;
297
+ const movedSet = new Set(movedIds);
298
+ return clonePathToNode(state, parentId, (p) => {
299
+ const remaining = p.children.filter((c) => !movedSet.has(c.id));
300
+ let insertIdx = remaining.findIndex((c) => c.id === targetSiblingId);
301
+ if (insertIdx === -1) {
302
+ if (movedSet.has(targetSiblingId)) {
303
+ const origIdx = p.children.findIndex((c) => c.id === targetSiblingId);
304
+ const origMap = new Map(p.children.map((c, i) => [c.id, i]));
305
+ if (position === "after") {
306
+ insertIdx = remaining.findIndex(
307
+ (c) => (origMap.get(c.id) ?? -1) > origIdx
308
+ );
309
+ if (insertIdx === -1) insertIdx = remaining.length;
310
+ } else {
311
+ insertIdx = remaining.findIndex(
312
+ (c) => (origMap.get(c.id) ?? -1) >= origIdx
313
+ );
314
+ if (insertIdx === -1) insertIdx = remaining.length;
315
+ }
316
+ } else {
317
+ insertIdx = position === "after" ? remaining.length : 0;
318
+ }
319
+ } else if (position === "after") {
320
+ insertIdx++;
321
+ }
322
+ const moved = movedIds.map((id) => p.children.find((c) => c.id === id)).filter((c) => c !== void 0);
323
+ const newChildren = [...remaining];
324
+ newChildren.splice(insertIdx, 0, ...moved);
325
+ return reindexArrayChildren({ ...p, children: newChildren });
326
+ });
327
+ }
242
328
  function convertValue(current, newType) {
243
329
  switch (newType) {
244
330
  case "string":
@@ -290,13 +376,12 @@ function duplicateNode(state, nodeId) {
290
376
  const idx = p.children.findIndex((c) => c.id === nodeId);
291
377
  const parentPath = p.path === "/" ? "" : p.path;
292
378
  const newKey = p.type === "array" ? String(idx + 1) : `${node.key}_copy`;
293
- const nodesById = /* @__PURE__ */ new Map();
294
379
  const newChild = buildSubtree(
295
380
  newKey,
296
381
  structuredClone(nodeValue),
297
382
  parentPath,
298
383
  p.id,
299
- nodesById
384
+ /* @__PURE__ */ new Map()
300
385
  );
301
386
  const newChildren = [...p.children];
302
387
  newChildren.splice(idx + 1, 0, newChild);
@@ -760,9 +845,14 @@ export {
760
845
  getDiffPaths,
761
846
  getNodeType,
762
847
  getPropertySchema,
848
+ insertNode,
849
+ insertProperty,
850
+ isDescendant,
763
851
  moveNode,
764
852
  removeNode,
765
853
  reorderChildren,
854
+ reorderChildrenMulti,
855
+ reparentSubtree,
766
856
  resetIdCounter,
767
857
  resolveRef,
768
858
  resolveSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tree.ts","../src/operations.ts","../src/history.ts","../src/schema.ts","../src/validate.ts","../src/search.ts","../src/diff.ts"],"sourcesContent":["import type {\n JsonPrimitive,\n JsonValue,\n JsonObject,\n JsonArray,\n NodeType,\n TreeNode,\n TreeState,\n} from \"./types\";\n\nlet nextId = 0;\n\nexport function generateId(): string {\n return `node_${++nextId}`;\n}\n\nexport function resetIdCounter(): void {\n nextId = 0;\n}\n\nexport function getNodeType(value: JsonValue): NodeType {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"array\";\n return typeof value as NodeType;\n}\n\nexport function buildSubtree(\n key: string,\n value: JsonValue,\n parentPath: string,\n parentId: string | null,\n nodesById: Map<string, TreeNode>,\n): TreeNode {\n const id = generateId();\n const path = parentPath ? `${parentPath}/${key}` : `/${key}`;\n const type = getNodeType(value);\n\n const node: TreeNode = {\n id,\n key,\n path,\n type,\n value:\n type === \"object\" || type === \"array\"\n ? undefined\n : (value as JsonPrimitive),\n children: [],\n parentId,\n };\n\n nodesById.set(id, node);\n\n if (type === \"object\" && value !== null) {\n const obj = value as JsonObject;\n node.children = Object.keys(obj).map((childKey) =>\n buildSubtree(childKey, obj[childKey], path, id, nodesById),\n );\n } else if (type === \"array\") {\n const arr = value as JsonArray;\n node.children = arr.map((item, index) =>\n buildSubtree(String(index), item, path, id, nodesById),\n );\n }\n\n return node;\n}\n\nexport function fromJson(value: JsonValue): TreeState {\n const nodesById = new Map<string, TreeNode>();\n\n const rootType = getNodeType(value);\n const root: TreeNode = {\n id: generateId(),\n key: \"\",\n path: \"/\",\n type: rootType,\n value:\n rootType === \"object\" || rootType === \"array\"\n ? undefined\n : (value as JsonPrimitive),\n children: [],\n parentId: null,\n };\n\n nodesById.set(root.id, root);\n\n if (rootType === \"object\" && value !== null) {\n const obj = value as JsonObject;\n root.children = Object.keys(obj).map((key) =>\n buildSubtree(key, obj[key], \"\", root.id, nodesById),\n );\n } else if (rootType === \"array\") {\n const arr = value as JsonArray;\n root.children = arr.map((item, index) =>\n buildSubtree(String(index), item, \"\", root.id, nodesById),\n );\n }\n\n return { root, nodesById };\n}\n\nexport function toJson(node: TreeNode): JsonValue {\n switch (node.type) {\n case \"object\": {\n const obj: JsonObject = {};\n for (const child of node.children) {\n obj[child.key] = toJson(child);\n }\n return obj;\n }\n case \"array\":\n return node.children.map((child) => toJson(child));\n default:\n return node.value as JsonValue;\n }\n}\n\nexport function findNode(\n state: TreeState,\n nodeId: string,\n): TreeNode | undefined {\n return state.nodesById.get(nodeId);\n}\n\nexport function findNodeByPath(\n state: TreeState,\n path: string,\n): TreeNode | undefined {\n if (path === \"/\") return state.root;\n\n const segments = path.split(\"/\").filter(Boolean);\n let current = state.root;\n\n for (const segment of segments) {\n const child = current.children.find((c) => c.key === segment);\n if (!child) return undefined;\n current = child;\n }\n\n return current;\n}\n","import type {\n JsonPrimitive,\n JsonValue,\n NodeType,\n TreeNode,\n TreeState,\n} from \"./types\";\nimport {\n toJson,\n getNodeType,\n generateId,\n buildSubtree,\n} from \"./tree\";\n\nfunction rebuildMap(root: TreeNode): Map<string, TreeNode> {\n const map = new Map<string, TreeNode>();\n function walk(node: TreeNode) {\n map.set(node.id, node);\n for (const child of node.children) walk(child);\n }\n walk(root);\n return map;\n}\n\nfunction recomputePaths(node: TreeNode, newParentPath: string): TreeNode {\n const newPath = newParentPath\n ? `${newParentPath}/${node.key}`\n : `/${node.key}`;\n if (node.path === newPath && node.children.length === 0) return node;\n return {\n ...node,\n path: newPath,\n children: node.children.map((child) => recomputePaths(child, newPath)),\n };\n}\n\n/**\n * Clone only the ancestor chain from root to `targetId` (structural sharing),\n * apply `updater` to the target, and rebuild the `nodesById` map.\n */\nfunction clonePathToNode(\n state: TreeState,\n targetId: string,\n updater: (node: TreeNode) => TreeNode,\n): TreeState {\n const chain: string[] = [];\n let cur: TreeNode | undefined = state.nodesById.get(targetId);\n while (cur) {\n chain.unshift(cur.id);\n cur = cur.parentId ? state.nodesById.get(cur.parentId) : undefined;\n }\n if (chain.length === 0) return state;\n\n function cloneAlongPath(node: TreeNode, depth: number): TreeNode {\n if (depth === chain.length - 1) {\n return updater(node);\n }\n const nextInChain = chain[depth + 1];\n return {\n ...node,\n children: node.children.map((child) =>\n child.id === nextInChain ? cloneAlongPath(child, depth + 1) : child,\n ),\n };\n }\n\n const newRoot = cloneAlongPath(state.root, 0);\n return { root: newRoot, nodesById: rebuildMap(newRoot) };\n}\n\nfunction reindexArrayChildren(parent: TreeNode): TreeNode {\n if (parent.type !== \"array\") return parent;\n const parentPath = parent.path === \"/\" ? \"\" : parent.path;\n return {\n ...parent,\n children: parent.children.map((child, i) => {\n const newKey = String(i);\n if (child.key === newKey) return child;\n return recomputePaths({ ...child, key: newKey }, parentPath);\n }),\n };\n}\n\nexport function setValue(\n state: TreeState,\n nodeId: string,\n value: JsonValue,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node) return state;\n\n const newType = getNodeType(value);\n\n if (newType !== \"object\" && newType !== \"array\") {\n return clonePathToNode(state, nodeId, (n) => ({\n ...n,\n type: newType,\n value: value as JsonPrimitive,\n children: [],\n }));\n }\n\n return clonePathToNode(state, nodeId, (n) => {\n const parentPath = n.path.split(\"/\").slice(0, -1).join(\"/\") || \"\";\n const nodesById = new Map<string, TreeNode>();\n const subtree = buildSubtree(n.key, value, parentPath, n.parentId, nodesById);\n return { ...subtree, id: n.id };\n });\n}\n\nexport function setKey(\n state: TreeState,\n nodeId: string,\n newKey: string,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const parent = state.nodesById.get(node.parentId);\n if (!parent || parent.type !== \"object\") return state;\n\n return clonePathToNode(state, nodeId, (n) => {\n const parentPath = parent.path === \"/\" ? \"\" : parent.path;\n const newPath = `${parentPath}/${newKey}`;\n const updated: TreeNode = { ...n, key: newKey, path: newPath };\n if (updated.children.length > 0) {\n updated.children = updated.children.map((child) =>\n recomputePaths(child, newPath),\n );\n }\n return updated;\n });\n}\n\nexport function addProperty(\n state: TreeState,\n parentId: string,\n key: string,\n value: JsonValue,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const nodesById = new Map<string, TreeNode>();\n const newChild = buildSubtree(key, value, parentPath, p.id, nodesById);\n return { ...p, children: [...p.children, newChild] };\n });\n}\n\nexport function removeNode(state: TreeState, nodeId: string): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n return clonePathToNode(state, node.parentId, (p) => {\n const newChildren = p.children.filter((c) => c.id !== nodeId);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function moveNode(\n state: TreeState,\n nodeId: string,\n newParentId: string,\n index?: number,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const srcParent = state.nodesById.get(node.parentId);\n const dstParent = state.nodesById.get(newParentId);\n if (!srcParent || !dstParent) return state;\n\n const nodeValue = toJson(node);\n\n const removed = clonePathToNode(state, node.parentId, (p) => {\n const newChildren = p.children.filter((c) => c.id !== nodeId);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n\n return clonePathToNode(removed, newParentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const nodesById = new Map<string, TreeNode>();\n const newChild = buildSubtree(\n p.type === \"array\" ? String(index ?? p.children.length) : node.key,\n nodeValue,\n parentPath,\n p.id,\n nodesById,\n );\n const newChildren = [...p.children];\n const insertAt = index ?? newChildren.length;\n newChildren.splice(insertAt, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function reorderChildren(\n state: TreeState,\n parentId: string,\n fromIndex: number,\n toIndex: number,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const newChildren = [...p.children];\n const [item] = newChildren.splice(fromIndex, 1);\n newChildren.splice(toIndex, 0, item);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nfunction convertValue(current: JsonValue, newType: NodeType): JsonValue {\n switch (newType) {\n case \"string\":\n if (current === null || current === undefined) return \"\";\n if (typeof current === \"object\") return JSON.stringify(current);\n return String(current);\n case \"number\": {\n const n = Number(current);\n return isNaN(n) ? 0 : n;\n }\n case \"boolean\":\n return Boolean(current);\n case \"null\":\n return null;\n case \"object\":\n if (\n current !== null &&\n typeof current === \"object\" &&\n !Array.isArray(current)\n )\n return current;\n if (Array.isArray(current)) {\n const obj: Record<string, JsonValue> = {};\n current.forEach((item, i) => {\n obj[String(i)] = item;\n });\n return obj;\n }\n return {};\n case \"array\":\n if (Array.isArray(current)) return current;\n if (current !== null && typeof current === \"object\")\n return Object.values(current);\n return current === null || current === undefined ? [] : [current];\n default:\n return current;\n }\n}\n\nexport function changeType(\n state: TreeState,\n nodeId: string,\n newType: NodeType,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node) return state;\n\n const currentValue = toJson(node);\n const newValue = convertValue(currentValue, newType);\n return setValue(state, nodeId, newValue);\n}\n\nexport function duplicateNode(state: TreeState, nodeId: string): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const parent = state.nodesById.get(node.parentId);\n if (!parent) return state;\n\n const nodeValue = toJson(node);\n\n return clonePathToNode(state, node.parentId, (p) => {\n const idx = p.children.findIndex((c) => c.id === nodeId);\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newKey = p.type === \"array\" ? String(idx + 1) : `${node.key}_copy`;\n const nodesById = new Map<string, TreeNode>();\n const newChild = buildSubtree(\n newKey,\n structuredClone(nodeValue),\n parentPath,\n p.id,\n nodesById,\n );\n const newChildren = [...p.children];\n newChildren.splice(idx + 1, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n","import type { TreeState } from \"./types\";\n\nconst MAX_HISTORY = 100;\n\nexport class History {\n private stack: TreeState[] = [];\n private cursor = -1;\n\n push(state: TreeState): void {\n this.stack = this.stack.slice(0, this.cursor + 1);\n this.stack.push(state);\n if (this.stack.length > MAX_HISTORY) {\n this.stack.shift();\n } else {\n this.cursor++;\n }\n }\n\n undo(): TreeState | null {\n if (!this.canUndo) return null;\n this.cursor--;\n return this.stack[this.cursor];\n }\n\n redo(): TreeState | null {\n if (!this.canRedo) return null;\n this.cursor++;\n return this.stack[this.cursor];\n }\n\n get canUndo(): boolean {\n return this.cursor > 0;\n }\n\n get canRedo(): boolean {\n return this.cursor < this.stack.length - 1;\n }\n\n get current(): TreeState | null {\n return this.stack[this.cursor] ?? null;\n }\n}\n","import type {\n JsonSchema,\n JsonSchemaProperty,\n JsonValue,\n JsonObject,\n} from \"./types\";\n\nconst KNOWN_SCHEMAS: Record<string, string> = {\n \"package.json\": \"https://json.schemastore.org/package.json\",\n \"tsconfig.json\": \"https://json.schemastore.org/tsconfig\",\n \"tsconfig.base.json\": \"https://json.schemastore.org/tsconfig\",\n \".eslintrc.json\": \"https://json.schemastore.org/eslintrc\",\n \".prettierrc\": \"https://json.schemastore.org/prettierrc\",\n \".prettierrc.json\": \"https://json.schemastore.org/prettierrc\",\n \"turbo.json\": \"https://turborepo.dev/schema.json\",\n \".babelrc\": \"https://json.schemastore.org/babelrc\",\n \"nest-cli.json\": \"https://json.schemastore.org/nest-cli\",\n \"vercel.json\": \"https://openapi.vercel.sh/vercel.json\",\n \".swcrc\": \"https://json.schemastore.org/swcrc\",\n};\n\nconst MAX_SCHEMA_CACHE = 50;\nconst schemaCache = new Map<string, JsonSchema>();\n\nasync function fetchSchema(url: string): Promise<JsonSchema | null> {\n if (schemaCache.has(url)) {\n return schemaCache.get(url)!;\n }\n try {\n const res = await fetch(url);\n if (!res.ok) return null;\n const schema = (await res.json()) as JsonSchema;\n if (schemaCache.size >= MAX_SCHEMA_CACHE) {\n const oldest = schemaCache.keys().next().value;\n if (oldest !== undefined) schemaCache.delete(oldest);\n }\n schemaCache.set(url, schema);\n return schema;\n } catch {\n return null;\n }\n}\n\nexport async function resolveSchema(\n json: JsonValue,\n filename?: string,\n): Promise<JsonSchema | null> {\n if (\n json !== null &&\n typeof json === \"object\" &&\n !Array.isArray(json) &&\n typeof (json as JsonObject)[\"$schema\"] === \"string\"\n ) {\n const url = (json as JsonObject)[\"$schema\"] as string;\n const schema = await fetchSchema(url);\n if (schema) return schema;\n }\n\n if (filename) {\n const base = filename.split(\"/\").pop() ?? filename;\n const knownUrl = KNOWN_SCHEMAS[base];\n if (knownUrl) {\n return fetchSchema(knownUrl);\n }\n }\n\n return null;\n}\n\nfunction findDefinition(\n root: JsonSchemaProperty,\n refPath: string,\n): JsonSchemaProperty | undefined {\n if (!refPath.startsWith(\"#/\")) return undefined;\n const segments = refPath.slice(2).split(\"/\");\n let current: unknown = root;\n\n for (const seg of segments) {\n if (current === null || typeof current !== \"object\") return undefined;\n current = (current as Record<string, unknown>)[seg];\n }\n\n return current as JsonSchemaProperty | undefined;\n}\n\n/**\n * Resolve `$ref` pointers and merge `allOf` within a schema.\n * `visited` tracks refs to prevent infinite cycles.\n */\nexport function resolveRef(\n prop: JsonSchemaProperty,\n root: JsonSchemaProperty,\n visited?: Set<string>,\n): JsonSchemaProperty {\n const seen = visited ?? new Set<string>();\n\n if (prop.$ref) {\n if (seen.has(prop.$ref)) return prop;\n seen.add(prop.$ref);\n const resolved = findDefinition(root, prop.$ref);\n if (resolved) {\n return resolveRef(resolved, root, seen);\n }\n return prop;\n }\n\n if (prop.allOf && prop.allOf.length > 0) {\n return mergeAllOf(prop, root, seen);\n }\n\n return prop;\n}\n\nfunction mergeAllOf(\n prop: JsonSchemaProperty,\n root: JsonSchemaProperty,\n visited: Set<string>,\n): JsonSchemaProperty {\n const merged: JsonSchemaProperty = { ...prop };\n delete merged.allOf;\n\n for (const sub of prop.allOf!) {\n const resolved = resolveRef(sub, root, new Set(visited));\n if (resolved.type && !merged.type) merged.type = resolved.type;\n if (resolved.properties) {\n merged.properties = { ...merged.properties, ...resolved.properties };\n }\n if (resolved.required) {\n merged.required = [\n ...new Set([...(merged.required ?? []), ...resolved.required]),\n ];\n }\n if (\n resolved.additionalProperties !== undefined &&\n merged.additionalProperties === undefined\n ) {\n merged.additionalProperties = resolved.additionalProperties;\n }\n if (resolved.items && !merged.items) merged.items = resolved.items;\n if (resolved.description && !merged.description)\n merged.description = resolved.description;\n if (resolved.title && !merged.title) merged.title = resolved.title;\n if (resolved.enum && !merged.enum) merged.enum = resolved.enum;\n if (resolved.minimum !== undefined && merged.minimum === undefined)\n merged.minimum = resolved.minimum;\n if (resolved.maximum !== undefined && merged.maximum === undefined)\n merged.maximum = resolved.maximum;\n if (resolved.minLength !== undefined && merged.minLength === undefined)\n merged.minLength = resolved.minLength;\n if (resolved.maxLength !== undefined && merged.maxLength === undefined)\n merged.maxLength = resolved.maxLength;\n if (resolved.pattern && !merged.pattern) merged.pattern = resolved.pattern;\n if (resolved.format && !merged.format) merged.format = resolved.format;\n }\n\n return merged;\n}\n\nexport function getPropertySchema(\n schema: JsonSchema | JsonSchemaProperty,\n path: string,\n rootSchema?: JsonSchemaProperty,\n): JsonSchemaProperty | undefined {\n const root = rootSchema ?? schema;\n const segments = path.split(\"/\").filter(Boolean);\n let current: JsonSchemaProperty | undefined = resolveRef(schema, root);\n\n for (const seg of segments) {\n if (!current) return undefined;\n current = resolveRef(current, root);\n\n if (current.properties?.[seg]) {\n current = resolveRef(current.properties[seg], root);\n continue;\n }\n\n if (current.patternProperties) {\n const match = Object.entries(current.patternProperties).find(\n ([pattern]) => {\n try {\n return new RegExp(pattern).test(seg);\n } catch {\n return false;\n }\n },\n );\n if (match) {\n current = resolveRef(match[1], root);\n continue;\n }\n }\n\n if (\n current.additionalProperties &&\n typeof current.additionalProperties === \"object\"\n ) {\n current = resolveRef(current.additionalProperties, root);\n continue;\n }\n\n if (current.items) {\n if (Array.isArray(current.items)) {\n const idx = Number(seg);\n if (!isNaN(idx) && current.items[idx]) {\n current = resolveRef(current.items[idx], root);\n continue;\n }\n } else {\n current = resolveRef(current.items, root);\n continue;\n }\n }\n\n if (current.anyOf || current.oneOf) {\n const variants = current.anyOf ?? current.oneOf ?? [];\n let found: JsonSchemaProperty | undefined;\n for (const variant of variants) {\n const resolved = resolveRef(variant, root);\n found = getPropertySchema(resolved, seg, root);\n if (found) break;\n }\n if (found) {\n current = found;\n continue;\n }\n return undefined;\n }\n\n return undefined;\n }\n\n return current;\n}\n\nexport function clearSchemaCache(): void {\n schemaCache.clear();\n}\n","import type { TreeNode, JsonSchemaProperty } from \"./types\";\n\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n}\n\nfunction schemaTypeMatches(\n nodeType: string,\n schemaType: string | string[] | undefined,\n): boolean {\n if (!schemaType) return true;\n const types = Array.isArray(schemaType) ? schemaType : [schemaType];\n\n if (nodeType === \"number\" && types.includes(\"integer\")) return true;\n return types.includes(nodeType);\n}\n\nconst FORMAT_PATTERNS: Record<string, RegExp> = {\n email: /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/,\n uri: /^https?:\\/\\/.+/,\n \"uri-reference\": /^(https?:\\/\\/|\\/|\\.\\.?\\/|#).*/,\n \"date-time\": /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/,\n date: /^\\d{4}-\\d{2}-\\d{2}$/,\n time: /^\\d{2}:\\d{2}:\\d{2}/,\n ipv4: /^(\\d{1,3}\\.){3}\\d{1,3}$/,\n ipv6: /^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$/,\n uuid: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,\n hostname:\n /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$/,\n};\n\nexport function validateNode(\n node: TreeNode,\n schema: JsonSchemaProperty | undefined,\n): ValidationResult {\n const errors: string[] = [];\n\n if (!schema) {\n return { valid: true, errors };\n }\n\n if (schema.type && !schemaTypeMatches(node.type, schema.type)) {\n const expected = Array.isArray(schema.type)\n ? schema.type.join(\" | \")\n : schema.type;\n errors.push(`Expected type \"${expected}\", got \"${node.type}\"`);\n }\n\n if (schema.enum && schema.enum.length > 0 && node.value !== undefined) {\n const match = schema.enum.some(\n (v) => JSON.stringify(v) === JSON.stringify(node.value),\n );\n if (!match) {\n errors.push(\n `Value must be one of: ${schema.enum.map((v) => JSON.stringify(v)).join(\", \")}`,\n );\n }\n }\n\n if (schema.const !== undefined && node.value !== undefined) {\n if (JSON.stringify(node.value) !== JSON.stringify(schema.const)) {\n errors.push(`Value must be ${JSON.stringify(schema.const)}`);\n }\n }\n\n if (schema.required && (node.type === \"object\" || node.type === \"array\")) {\n const childKeys = new Set(node.children.map((c) => c.key));\n for (const req of schema.required) {\n if (!childKeys.has(req)) {\n errors.push(`Missing required property \"${req}\"`);\n }\n }\n }\n\n if (node.type === \"number\" && typeof node.value === \"number\") {\n const val = node.value;\n if (schema.minimum !== undefined && val < schema.minimum) {\n errors.push(`Value must be >= ${schema.minimum}`);\n }\n if (schema.maximum !== undefined && val > schema.maximum) {\n errors.push(`Value must be <= ${schema.maximum}`);\n }\n if (schema.exclusiveMinimum !== undefined) {\n const bound =\n typeof schema.exclusiveMinimum === \"number\"\n ? schema.exclusiveMinimum\n : schema.minimum;\n if (bound !== undefined && val <= bound) {\n errors.push(`Value must be > ${bound}`);\n }\n }\n if (schema.exclusiveMaximum !== undefined) {\n const bound =\n typeof schema.exclusiveMaximum === \"number\"\n ? schema.exclusiveMaximum\n : schema.maximum;\n if (bound !== undefined && val >= bound) {\n errors.push(`Value must be < ${bound}`);\n }\n }\n if (schema.multipleOf !== undefined) {\n const remainder = Math.abs(val % schema.multipleOf);\n if (remainder > 1e-10 && Math.abs(remainder - schema.multipleOf) > 1e-10) {\n errors.push(`Value must be a multiple of ${schema.multipleOf}`);\n }\n }\n }\n\n if (node.type === \"string\" && typeof node.value === \"string\") {\n const val = node.value;\n if (schema.minLength !== undefined && val.length < schema.minLength) {\n errors.push(`Must be at least ${schema.minLength} characters`);\n }\n if (schema.maxLength !== undefined && val.length > schema.maxLength) {\n errors.push(`Must be at most ${schema.maxLength} characters`);\n }\n if (schema.pattern) {\n try {\n if (!new RegExp(schema.pattern).test(val)) {\n errors.push(`Must match pattern: ${schema.pattern}`);\n }\n } catch {\n // invalid regex in schema, skip\n }\n }\n if (schema.format && FORMAT_PATTERNS[schema.format]) {\n if (!FORMAT_PATTERNS[schema.format].test(val)) {\n errors.push(`Invalid ${schema.format} format`);\n }\n }\n }\n\n if (node.type === \"array\") {\n if (\n schema.minItems !== undefined &&\n node.children.length < schema.minItems\n ) {\n errors.push(`Must have at least ${schema.minItems} items`);\n }\n if (\n schema.maxItems !== undefined &&\n node.children.length > schema.maxItems\n ) {\n errors.push(`Must have at most ${schema.maxItems} items`);\n }\n }\n\n if (node.type === \"object\") {\n if (\n schema.minProperties !== undefined &&\n node.children.length < schema.minProperties\n ) {\n errors.push(`Must have at least ${schema.minProperties} properties`);\n }\n if (\n schema.maxProperties !== undefined &&\n node.children.length > schema.maxProperties\n ) {\n errors.push(`Must have at most ${schema.maxProperties} properties`);\n }\n }\n\n return { valid: errors.length === 0, errors };\n}\n","import type { TreeNode, TreeState } from \"./types\";\n\nexport interface SearchMatch {\n nodeId: string;\n field: \"key\" | \"value\";\n}\n\nexport function searchNodes(tree: TreeState, query: string): SearchMatch[] {\n if (!query.trim()) return [];\n const matches: SearchMatch[] = [];\n const lower = query.toLowerCase();\n\n function walk(node: TreeNode) {\n if (node.key && node.key.toLowerCase().includes(lower)) {\n matches.push({ nodeId: node.id, field: \"key\" });\n }\n if (\n node.value !== undefined &&\n node.value !== null &&\n String(node.value).toLowerCase().includes(lower)\n ) {\n matches.push({ nodeId: node.id, field: \"value\" });\n }\n for (const child of node.children) {\n walk(child);\n }\n }\n\n walk(tree.root);\n return matches;\n}\n\n/**\n * Collect all ancestor node IDs for each matched node so the tree\n * can auto-expand paths to search results.\n */\nexport function getAncestorIds(\n tree: TreeState,\n nodeIds: string[],\n): Set<string> {\n const ancestors = new Set<string>();\n\n for (const nodeId of nodeIds) {\n let current = tree.nodesById.get(nodeId);\n while (current && current.parentId) {\n ancestors.add(current.parentId);\n current = tree.nodesById.get(current.parentId);\n }\n }\n\n return ancestors;\n}\n","import type { JsonValue } from \"./types\";\n\nexport type DiffType = \"added\" | \"removed\" | \"changed\";\n\nexport interface DiffEntry {\n path: string;\n type: DiffType;\n oldValue?: JsonValue;\n newValue?: JsonValue;\n}\n\nexport function computeDiff(\n original: JsonValue,\n current: JsonValue,\n path = \"\",\n): DiffEntry[] {\n const entries: DiffEntry[] = [];\n\n if (original === current) {\n return entries;\n }\n\n if (\n original === null ||\n current === null ||\n typeof original !== typeof current ||\n Array.isArray(original) !== Array.isArray(current)\n ) {\n if (path) {\n entries.push({\n path,\n type: \"changed\",\n oldValue: original,\n newValue: current,\n });\n } else {\n diffObject(original, current, path, entries);\n }\n return entries;\n }\n\n if (typeof original !== \"object\") {\n if (original !== current) {\n entries.push({\n path: path || \"/\",\n type: \"changed\",\n oldValue: original,\n newValue: current,\n });\n }\n return entries;\n }\n\n if (Array.isArray(original) && Array.isArray(current)) {\n const maxLen = Math.max(original.length, current.length);\n for (let i = 0; i < maxLen; i++) {\n const childPath = path ? `${path}/${i}` : `/${i}`;\n if (i >= original.length) {\n entries.push({ path: childPath, type: \"added\", newValue: current[i] });\n } else if (i >= current.length) {\n entries.push({\n path: childPath,\n type: \"removed\",\n oldValue: original[i],\n });\n } else {\n entries.push(...computeDiff(original[i], current[i], childPath));\n }\n }\n return entries;\n }\n\n diffObject(original, current, path, entries);\n return entries;\n}\n\nfunction diffObject(\n original: JsonValue,\n current: JsonValue,\n path: string,\n entries: DiffEntry[],\n) {\n const origObj =\n original !== null &&\n typeof original === \"object\" &&\n !Array.isArray(original)\n ? (original as Record<string, JsonValue>)\n : {};\n const currObj =\n current !== null && typeof current === \"object\" && !Array.isArray(current)\n ? (current as Record<string, JsonValue>)\n : {};\n\n const allKeys = new Set([...Object.keys(origObj), ...Object.keys(currObj)]);\n\n for (const key of allKeys) {\n const childPath = path ? `${path}/${key}` : `/${key}`;\n const inOriginal = key in origObj;\n const inCurrent = key in currObj;\n\n if (!inOriginal && inCurrent) {\n entries.push({ path: childPath, type: \"added\", newValue: currObj[key] });\n } else if (inOriginal && !inCurrent) {\n entries.push({\n path: childPath,\n type: \"removed\",\n oldValue: origObj[key],\n });\n } else {\n entries.push(...computeDiff(origObj[key], currObj[key], childPath));\n }\n }\n}\n\nexport function getDiffPaths(entries: DiffEntry[]): Map<string, DiffType> {\n const map = new Map<string, DiffType>();\n for (const entry of entries) {\n map.set(entry.path, entry.type);\n }\n return map;\n}\n"],"mappings":";AAUA,IAAI,SAAS;AAEN,SAAS,aAAqB;AACnC,SAAO,QAAQ,EAAE,MAAM;AACzB;AAEO,SAAS,iBAAuB;AACrC,WAAS;AACX;AAEO,SAAS,YAAY,OAA4B;AACtD,MAAI,UAAU,KAAM,QAAO;AAC3B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X,MAAM;AAAA,QACN,MAAM;AAAA,QACN,UAAU,QAAQ,GAAG;AAAA,MACvB,CAAC;AAAA,IACH,OAAO;AACL,cAAQ,KAAK,GAAG,YAAY,QAAQ,GAAG,GAAG,QAAQ,GAAG,GAAG,SAAS,CAAC;AAAA,IACpE;AAAA,EACF;AACF;AAEO,SAAS,aAAa,SAA6C;AACxE,QAAM,MAAM,oBAAI,IAAsB;AACtC,aAAW,SAAS,SAAS;AAC3B,QAAI,IAAI,MAAM,MAAM,MAAM,IAAI;AAAA,EAChC;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/tree.ts","../src/operations.ts","../src/history.ts","../src/schema.ts","../src/validate.ts","../src/search.ts","../src/diff.ts"],"sourcesContent":["import type {\n JsonPrimitive,\n JsonValue,\n JsonObject,\n JsonArray,\n NodeType,\n TreeNode,\n TreeState,\n} from \"./types\";\n\nlet nextId = 0;\n\nexport function generateId(): string {\n return `node_${++nextId}`;\n}\n\nexport function resetIdCounter(): void {\n nextId = 0;\n}\n\nexport function getNodeType(value: JsonValue): NodeType {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"array\";\n return typeof value as NodeType;\n}\n\nexport function buildSubtree(\n key: string,\n value: JsonValue,\n parentPath: string,\n parentId: string | null,\n nodesById: Map<string, TreeNode>,\n): TreeNode {\n const id = generateId();\n const path = parentPath ? `${parentPath}/${key}` : `/${key}`;\n const type = getNodeType(value);\n\n const node: TreeNode = {\n id,\n key,\n path,\n type,\n value:\n type === \"object\" || type === \"array\"\n ? undefined\n : (value as JsonPrimitive),\n children: [],\n parentId,\n };\n\n nodesById.set(id, node);\n\n if (type === \"object\" && value !== null) {\n const obj = value as JsonObject;\n node.children = Object.keys(obj).map((childKey) =>\n buildSubtree(childKey, obj[childKey], path, id, nodesById),\n );\n } else if (type === \"array\") {\n const arr = value as JsonArray;\n node.children = arr.map((item, index) =>\n buildSubtree(String(index), item, path, id, nodesById),\n );\n }\n\n return node;\n}\n\nexport function fromJson(value: JsonValue): TreeState {\n const nodesById = new Map<string, TreeNode>();\n\n const rootType = getNodeType(value);\n const root: TreeNode = {\n id: generateId(),\n key: \"\",\n path: \"/\",\n type: rootType,\n value:\n rootType === \"object\" || rootType === \"array\"\n ? undefined\n : (value as JsonPrimitive),\n children: [],\n parentId: null,\n };\n\n nodesById.set(root.id, root);\n\n if (rootType === \"object\" && value !== null) {\n const obj = value as JsonObject;\n root.children = Object.keys(obj).map((key) =>\n buildSubtree(key, obj[key], \"\", root.id, nodesById),\n );\n } else if (rootType === \"array\") {\n const arr = value as JsonArray;\n root.children = arr.map((item, index) =>\n buildSubtree(String(index), item, \"\", root.id, nodesById),\n );\n }\n\n return { root, nodesById };\n}\n\nexport function toJson(node: TreeNode): JsonValue {\n switch (node.type) {\n case \"object\": {\n const obj: JsonObject = {};\n for (const child of node.children) {\n obj[child.key] = toJson(child);\n }\n return obj;\n }\n case \"array\":\n return node.children.map((child) => toJson(child));\n default:\n return node.value as JsonValue;\n }\n}\n\n/**\n * Clone a subtree with updated key, path, and parentId while preserving\n * all original node IDs. Used for cross-parent moves where identity must\n * be retained so that UI state (expanded, selected, etc.) stays valid.\n */\nexport function reparentSubtree(\n node: TreeNode,\n newKey: string,\n parentPath: string,\n newParentId: string,\n): TreeNode {\n const newPath = parentPath ? `${parentPath}/${newKey}` : `/${newKey}`;\n return {\n ...node,\n key: newKey,\n path: newPath,\n parentId: newParentId,\n children: node.children.map((child, i) =>\n reparentSubtree(\n child,\n node.type === \"array\" ? String(i) : child.key,\n newPath,\n node.id,\n ),\n ),\n };\n}\n\nexport function findNode(\n state: TreeState,\n nodeId: string,\n): TreeNode | undefined {\n return state.nodesById.get(nodeId);\n}\n\nexport function findNodeByPath(\n state: TreeState,\n path: string,\n): TreeNode | undefined {\n if (path === \"/\") return state.root;\n\n const segments = path.split(\"/\").filter(Boolean);\n let current = state.root;\n\n for (const segment of segments) {\n const child = current.children.find((c) => c.key === segment);\n if (!child) return undefined;\n current = child;\n }\n\n return current;\n}\n\n/**\n * Check whether `nodeId` is a descendant of `potentialAncestorId` by walking\n * up `parentId` links. Returns `true` when the two IDs are equal (a node is\n * considered a descendant of itself).\n */\nexport function isDescendant(\n tree: TreeState,\n nodeId: string,\n potentialAncestorId: string,\n): boolean {\n let current = tree.nodesById.get(nodeId);\n while (current) {\n if (current.id === potentialAncestorId) return true;\n current = current.parentId\n ? tree.nodesById.get(current.parentId)\n : undefined;\n }\n return false;\n}\n","import type {\n JsonPrimitive,\n JsonValue,\n NodeType,\n TreeNode,\n TreeState,\n} from \"./types\";\nimport { toJson, getNodeType, buildSubtree, reparentSubtree } from \"./tree\";\n\nfunction rebuildMap(root: TreeNode): Map<string, TreeNode> {\n const map = new Map<string, TreeNode>();\n function walk(node: TreeNode) {\n map.set(node.id, node);\n for (const child of node.children) walk(child);\n }\n walk(root);\n return map;\n}\n\nfunction recomputePaths(node: TreeNode, newParentPath: string): TreeNode {\n const newPath = newParentPath\n ? `${newParentPath}/${node.key}`\n : `/${node.key}`;\n if (node.path === newPath && node.children.length === 0) return node;\n return {\n ...node,\n path: newPath,\n children: node.children.map((child) => recomputePaths(child, newPath)),\n };\n}\n\n/**\n * Clone only the ancestor chain from root to `targetId` (structural sharing),\n * apply `updater` to the target, and rebuild the `nodesById` map.\n */\nfunction clonePathToNode(\n state: TreeState,\n targetId: string,\n updater: (node: TreeNode) => TreeNode,\n): TreeState {\n const chain: string[] = [];\n let cur: TreeNode | undefined = state.nodesById.get(targetId);\n while (cur) {\n chain.unshift(cur.id);\n cur = cur.parentId ? state.nodesById.get(cur.parentId) : undefined;\n }\n if (chain.length === 0) return state;\n\n function cloneAlongPath(node: TreeNode, depth: number): TreeNode {\n if (depth === chain.length - 1) {\n return updater(node);\n }\n const nextInChain = chain[depth + 1];\n return {\n ...node,\n children: node.children.map((child) =>\n child.id === nextInChain ? cloneAlongPath(child, depth + 1) : child,\n ),\n };\n }\n\n const newRoot = cloneAlongPath(state.root, 0);\n return { root: newRoot, nodesById: rebuildMap(newRoot) };\n}\n\nfunction reindexArrayChildren(parent: TreeNode): TreeNode {\n if (parent.type !== \"array\") return parent;\n const parentPath = parent.path === \"/\" ? \"\" : parent.path;\n return {\n ...parent,\n children: parent.children.map((child, i) => {\n const newKey = String(i);\n if (child.key === newKey) return child;\n return recomputePaths({ ...child, key: newKey }, parentPath);\n }),\n };\n}\n\nexport function setValue(\n state: TreeState,\n nodeId: string,\n value: JsonValue,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node) return state;\n\n const newType = getNodeType(value);\n\n if (newType !== \"object\" && newType !== \"array\") {\n return clonePathToNode(state, nodeId, (n) => ({\n ...n,\n type: newType,\n value: value as JsonPrimitive,\n children: [],\n }));\n }\n\n return clonePathToNode(state, nodeId, (n) => {\n const parentPath = n.path.split(\"/\").slice(0, -1).join(\"/\") || \"\";\n const nodesById = new Map<string, TreeNode>();\n const subtree = buildSubtree(\n n.key,\n value,\n parentPath,\n n.parentId,\n nodesById,\n );\n return { ...subtree, id: n.id };\n });\n}\n\nexport function setKey(\n state: TreeState,\n nodeId: string,\n newKey: string,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const parent = state.nodesById.get(node.parentId);\n if (!parent || parent.type !== \"object\") return state;\n\n return clonePathToNode(state, nodeId, (n) => {\n const parentPath = parent.path === \"/\" ? \"\" : parent.path;\n const newPath = `${parentPath}/${newKey}`;\n const updated: TreeNode = { ...n, key: newKey, path: newPath };\n if (updated.children.length > 0) {\n updated.children = updated.children.map((child) =>\n recomputePaths(child, newPath),\n );\n }\n return updated;\n });\n}\n\nexport function addProperty(\n state: TreeState,\n parentId: string,\n key: string,\n value: JsonValue,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newChild = buildSubtree(key, value, parentPath, p.id, new Map());\n return { ...p, children: [...p.children, newChild] };\n });\n}\n\nexport function insertProperty(\n state: TreeState,\n parentId: string,\n key: string,\n value: JsonValue,\n index: number,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newChild = buildSubtree(key, value, parentPath, p.id, new Map());\n const newChildren = [...p.children];\n newChildren.splice(index, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function insertNode(\n state: TreeState,\n parentId: string,\n node: TreeNode,\n index: number,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const key = p.type === \"array\" ? String(index) : node.key;\n const reparented = reparentSubtree(node, key, parentPath, p.id);\n const newChildren = [...p.children];\n newChildren.splice(index, 0, reparented);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function removeNode(state: TreeState, nodeId: string): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n return clonePathToNode(state, node.parentId, (p) => {\n const newChildren = p.children.filter((c) => c.id !== nodeId);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function moveNode(\n state: TreeState,\n nodeId: string,\n newParentId: string,\n index?: number,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const srcParent = state.nodesById.get(node.parentId);\n const dstParent = state.nodesById.get(newParentId);\n if (!srcParent || !dstParent) return state;\n\n const nodeValue = toJson(node);\n\n const removed = clonePathToNode(state, node.parentId, (p) => {\n const newChildren = p.children.filter((c) => c.id !== nodeId);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n\n return clonePathToNode(removed, newParentId, (p) => {\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newChild = buildSubtree(\n p.type === \"array\" ? String(index ?? p.children.length) : node.key,\n nodeValue,\n parentPath,\n p.id,\n new Map(),\n );\n const newChildren = [...p.children];\n const insertAt = index ?? newChildren.length;\n newChildren.splice(insertAt, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function reorderChildren(\n state: TreeState,\n parentId: string,\n fromIndex: number,\n toIndex: number,\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n return clonePathToNode(state, parentId, (p) => {\n const newChildren = [...p.children];\n const [item] = newChildren.splice(fromIndex, 1);\n newChildren.splice(toIndex, 0, item);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nexport function reorderChildrenMulti(\n state: TreeState,\n parentId: string,\n movedIds: string[],\n targetSiblingId: string,\n position: \"before\" | \"after\",\n): TreeState {\n const parent = state.nodesById.get(parentId);\n if (!parent) return state;\n\n const movedSet = new Set(movedIds);\n\n return clonePathToNode(state, parentId, (p) => {\n const remaining = p.children.filter((c) => !movedSet.has(c.id));\n let insertIdx = remaining.findIndex((c) => c.id === targetSiblingId);\n if (insertIdx === -1) {\n if (movedSet.has(targetSiblingId)) {\n const origIdx = p.children.findIndex((c) => c.id === targetSiblingId);\n const origMap = new Map(p.children.map((c, i) => [c.id, i]));\n if (position === \"after\") {\n insertIdx = remaining.findIndex(\n (c) => (origMap.get(c.id) ?? -1) > origIdx,\n );\n if (insertIdx === -1) insertIdx = remaining.length;\n } else {\n insertIdx = remaining.findIndex(\n (c) => (origMap.get(c.id) ?? -1) >= origIdx,\n );\n if (insertIdx === -1) insertIdx = remaining.length;\n }\n } else {\n insertIdx = position === \"after\" ? remaining.length : 0;\n }\n } else if (position === \"after\") {\n insertIdx++;\n }\n const moved = movedIds\n .map((id) => p.children.find((c) => c.id === id))\n .filter((c): c is TreeNode => c !== undefined);\n const newChildren = [...remaining];\n newChildren.splice(insertIdx, 0, ...moved);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n\nfunction convertValue(current: JsonValue, newType: NodeType): JsonValue {\n switch (newType) {\n case \"string\":\n if (current === null || current === undefined) return \"\";\n if (typeof current === \"object\") return JSON.stringify(current);\n return String(current);\n case \"number\": {\n const n = Number(current);\n return isNaN(n) ? 0 : n;\n }\n case \"boolean\":\n return Boolean(current);\n case \"null\":\n return null;\n case \"object\":\n if (\n current !== null &&\n typeof current === \"object\" &&\n !Array.isArray(current)\n )\n return current;\n if (Array.isArray(current)) {\n const obj: Record<string, JsonValue> = {};\n current.forEach((item, i) => {\n obj[String(i)] = item;\n });\n return obj;\n }\n return {};\n case \"array\":\n if (Array.isArray(current)) return current;\n if (current !== null && typeof current === \"object\")\n return Object.values(current);\n return current === null || current === undefined ? [] : [current];\n default:\n return current;\n }\n}\n\nexport function changeType(\n state: TreeState,\n nodeId: string,\n newType: NodeType,\n): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node) return state;\n\n const currentValue = toJson(node);\n const newValue = convertValue(currentValue, newType);\n return setValue(state, nodeId, newValue);\n}\n\nexport function duplicateNode(state: TreeState, nodeId: string): TreeState {\n const node = state.nodesById.get(nodeId);\n if (!node || !node.parentId) return state;\n\n const parent = state.nodesById.get(node.parentId);\n if (!parent) return state;\n\n const nodeValue = toJson(node);\n\n return clonePathToNode(state, node.parentId, (p) => {\n const idx = p.children.findIndex((c) => c.id === nodeId);\n const parentPath = p.path === \"/\" ? \"\" : p.path;\n const newKey = p.type === \"array\" ? String(idx + 1) : `${node.key}_copy`;\n const newChild = buildSubtree(\n newKey,\n structuredClone(nodeValue),\n parentPath,\n p.id,\n new Map(),\n );\n const newChildren = [...p.children];\n newChildren.splice(idx + 1, 0, newChild);\n return reindexArrayChildren({ ...p, children: newChildren });\n });\n}\n","import type { TreeState } from \"./types\";\n\nconst MAX_HISTORY = 100;\n\nexport class History {\n private stack: TreeState[] = [];\n private cursor = -1;\n\n push(state: TreeState): void {\n this.stack = this.stack.slice(0, this.cursor + 1);\n this.stack.push(state);\n if (this.stack.length > MAX_HISTORY) {\n this.stack.shift();\n } else {\n this.cursor++;\n }\n }\n\n undo(): TreeState | null {\n if (!this.canUndo) return null;\n this.cursor--;\n return this.stack[this.cursor];\n }\n\n redo(): TreeState | null {\n if (!this.canRedo) return null;\n this.cursor++;\n return this.stack[this.cursor];\n }\n\n get canUndo(): boolean {\n return this.cursor > 0;\n }\n\n get canRedo(): boolean {\n return this.cursor < this.stack.length - 1;\n }\n\n get current(): TreeState | null {\n return this.stack[this.cursor] ?? null;\n }\n}\n","import type {\n JsonSchema,\n JsonSchemaProperty,\n JsonValue,\n JsonObject,\n} from \"./types\";\n\nconst KNOWN_SCHEMAS: Record<string, string> = {\n \"package.json\": \"https://json.schemastore.org/package.json\",\n \"tsconfig.json\": \"https://json.schemastore.org/tsconfig\",\n \"tsconfig.base.json\": \"https://json.schemastore.org/tsconfig\",\n \".eslintrc.json\": \"https://json.schemastore.org/eslintrc\",\n \".prettierrc\": \"https://json.schemastore.org/prettierrc\",\n \".prettierrc.json\": \"https://json.schemastore.org/prettierrc\",\n \"turbo.json\": \"https://turborepo.dev/schema.json\",\n \".babelrc\": \"https://json.schemastore.org/babelrc\",\n \"nest-cli.json\": \"https://json.schemastore.org/nest-cli\",\n \"vercel.json\": \"https://openapi.vercel.sh/vercel.json\",\n \".swcrc\": \"https://json.schemastore.org/swcrc\",\n};\n\nconst MAX_SCHEMA_CACHE = 50;\nconst schemaCache = new Map<string, JsonSchema>();\n\nasync function fetchSchema(url: string): Promise<JsonSchema | null> {\n if (schemaCache.has(url)) {\n return schemaCache.get(url)!;\n }\n try {\n const res = await fetch(url);\n if (!res.ok) return null;\n const schema = (await res.json()) as JsonSchema;\n if (schemaCache.size >= MAX_SCHEMA_CACHE) {\n const oldest = schemaCache.keys().next().value;\n if (oldest !== undefined) schemaCache.delete(oldest);\n }\n schemaCache.set(url, schema);\n return schema;\n } catch {\n return null;\n }\n}\n\nexport async function resolveSchema(\n json: JsonValue,\n filename?: string,\n): Promise<JsonSchema | null> {\n if (\n json !== null &&\n typeof json === \"object\" &&\n !Array.isArray(json) &&\n typeof (json as JsonObject)[\"$schema\"] === \"string\"\n ) {\n const url = (json as JsonObject)[\"$schema\"] as string;\n const schema = await fetchSchema(url);\n if (schema) return schema;\n }\n\n if (filename) {\n const base = filename.split(\"/\").pop() ?? filename;\n const knownUrl = KNOWN_SCHEMAS[base];\n if (knownUrl) {\n return fetchSchema(knownUrl);\n }\n }\n\n return null;\n}\n\nfunction findDefinition(\n root: JsonSchemaProperty,\n refPath: string,\n): JsonSchemaProperty | undefined {\n if (!refPath.startsWith(\"#/\")) return undefined;\n const segments = refPath.slice(2).split(\"/\");\n let current: unknown = root;\n\n for (const seg of segments) {\n if (current === null || typeof current !== \"object\") return undefined;\n current = (current as Record<string, unknown>)[seg];\n }\n\n return current as JsonSchemaProperty | undefined;\n}\n\n/**\n * Resolve `$ref` pointers and merge `allOf` within a schema.\n * `visited` tracks refs to prevent infinite cycles.\n */\nexport function resolveRef(\n prop: JsonSchemaProperty,\n root: JsonSchemaProperty,\n visited?: Set<string>,\n): JsonSchemaProperty {\n const seen = visited ?? new Set<string>();\n\n if (prop.$ref) {\n if (seen.has(prop.$ref)) return prop;\n seen.add(prop.$ref);\n const resolved = findDefinition(root, prop.$ref);\n if (resolved) {\n return resolveRef(resolved, root, seen);\n }\n return prop;\n }\n\n if (prop.allOf && prop.allOf.length > 0) {\n return mergeAllOf(prop, root, seen);\n }\n\n return prop;\n}\n\nfunction mergeAllOf(\n prop: JsonSchemaProperty,\n root: JsonSchemaProperty,\n visited: Set<string>,\n): JsonSchemaProperty {\n const merged: JsonSchemaProperty = { ...prop };\n delete merged.allOf;\n\n for (const sub of prop.allOf!) {\n const resolved = resolveRef(sub, root, new Set(visited));\n if (resolved.type && !merged.type) merged.type = resolved.type;\n if (resolved.properties) {\n merged.properties = { ...merged.properties, ...resolved.properties };\n }\n if (resolved.required) {\n merged.required = [\n ...new Set([...(merged.required ?? []), ...resolved.required]),\n ];\n }\n if (\n resolved.additionalProperties !== undefined &&\n merged.additionalProperties === undefined\n ) {\n merged.additionalProperties = resolved.additionalProperties;\n }\n if (resolved.items && !merged.items) merged.items = resolved.items;\n if (resolved.description && !merged.description)\n merged.description = resolved.description;\n if (resolved.title && !merged.title) merged.title = resolved.title;\n if (resolved.enum && !merged.enum) merged.enum = resolved.enum;\n if (resolved.minimum !== undefined && merged.minimum === undefined)\n merged.minimum = resolved.minimum;\n if (resolved.maximum !== undefined && merged.maximum === undefined)\n merged.maximum = resolved.maximum;\n if (resolved.minLength !== undefined && merged.minLength === undefined)\n merged.minLength = resolved.minLength;\n if (resolved.maxLength !== undefined && merged.maxLength === undefined)\n merged.maxLength = resolved.maxLength;\n if (resolved.pattern && !merged.pattern) merged.pattern = resolved.pattern;\n if (resolved.format && !merged.format) merged.format = resolved.format;\n }\n\n return merged;\n}\n\nexport function getPropertySchema(\n schema: JsonSchema | JsonSchemaProperty,\n path: string,\n rootSchema?: JsonSchemaProperty,\n): JsonSchemaProperty | undefined {\n const root = rootSchema ?? schema;\n const segments = path.split(\"/\").filter(Boolean);\n let current: JsonSchemaProperty | undefined = resolveRef(schema, root);\n\n for (const seg of segments) {\n if (!current) return undefined;\n current = resolveRef(current, root);\n\n if (current.properties?.[seg]) {\n current = resolveRef(current.properties[seg], root);\n continue;\n }\n\n if (current.patternProperties) {\n const match = Object.entries(current.patternProperties).find(\n ([pattern]) => {\n try {\n return new RegExp(pattern).test(seg);\n } catch {\n return false;\n }\n },\n );\n if (match) {\n current = resolveRef(match[1], root);\n continue;\n }\n }\n\n if (\n current.additionalProperties &&\n typeof current.additionalProperties === \"object\"\n ) {\n current = resolveRef(current.additionalProperties, root);\n continue;\n }\n\n if (current.items) {\n if (Array.isArray(current.items)) {\n const idx = Number(seg);\n if (!isNaN(idx) && current.items[idx]) {\n current = resolveRef(current.items[idx], root);\n continue;\n }\n } else {\n current = resolveRef(current.items, root);\n continue;\n }\n }\n\n if (current.anyOf || current.oneOf) {\n const variants = current.anyOf ?? current.oneOf ?? [];\n let found: JsonSchemaProperty | undefined;\n for (const variant of variants) {\n const resolved = resolveRef(variant, root);\n found = getPropertySchema(resolved, seg, root);\n if (found) break;\n }\n if (found) {\n current = found;\n continue;\n }\n return undefined;\n }\n\n return undefined;\n }\n\n return current;\n}\n\nexport function clearSchemaCache(): void {\n schemaCache.clear();\n}\n","import type { TreeNode, JsonSchemaProperty } from \"./types\";\n\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n}\n\nfunction schemaTypeMatches(\n nodeType: string,\n schemaType: string | string[] | undefined,\n): boolean {\n if (!schemaType) return true;\n const types = Array.isArray(schemaType) ? schemaType : [schemaType];\n\n if (nodeType === \"number\" && types.includes(\"integer\")) return true;\n return types.includes(nodeType);\n}\n\nconst FORMAT_PATTERNS: Record<string, RegExp> = {\n email: /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/,\n uri: /^https?:\\/\\/.+/,\n \"uri-reference\": /^(https?:\\/\\/|\\/|\\.\\.?\\/|#).*/,\n \"date-time\": /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/,\n date: /^\\d{4}-\\d{2}-\\d{2}$/,\n time: /^\\d{2}:\\d{2}:\\d{2}/,\n ipv4: /^(\\d{1,3}\\.){3}\\d{1,3}$/,\n ipv6: /^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$/,\n uuid: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,\n hostname:\n /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$/,\n};\n\nexport function validateNode(\n node: TreeNode,\n schema: JsonSchemaProperty | undefined,\n): ValidationResult {\n const errors: string[] = [];\n\n if (!schema) {\n return { valid: true, errors };\n }\n\n if (schema.type && !schemaTypeMatches(node.type, schema.type)) {\n const expected = Array.isArray(schema.type)\n ? schema.type.join(\" | \")\n : schema.type;\n errors.push(`Expected type \"${expected}\", got \"${node.type}\"`);\n }\n\n if (schema.enum && schema.enum.length > 0 && node.value !== undefined) {\n const match = schema.enum.some(\n (v) => JSON.stringify(v) === JSON.stringify(node.value),\n );\n if (!match) {\n errors.push(\n `Value must be one of: ${schema.enum.map((v) => JSON.stringify(v)).join(\", \")}`,\n );\n }\n }\n\n if (schema.const !== undefined && node.value !== undefined) {\n if (JSON.stringify(node.value) !== JSON.stringify(schema.const)) {\n errors.push(`Value must be ${JSON.stringify(schema.const)}`);\n }\n }\n\n if (schema.required && (node.type === \"object\" || node.type === \"array\")) {\n const childKeys = new Set(node.children.map((c) => c.key));\n for (const req of schema.required) {\n if (!childKeys.has(req)) {\n errors.push(`Missing required property \"${req}\"`);\n }\n }\n }\n\n if (node.type === \"number\" && typeof node.value === \"number\") {\n const val = node.value;\n if (schema.minimum !== undefined && val < schema.minimum) {\n errors.push(`Value must be >= ${schema.minimum}`);\n }\n if (schema.maximum !== undefined && val > schema.maximum) {\n errors.push(`Value must be <= ${schema.maximum}`);\n }\n if (schema.exclusiveMinimum !== undefined) {\n const bound =\n typeof schema.exclusiveMinimum === \"number\"\n ? schema.exclusiveMinimum\n : schema.minimum;\n if (bound !== undefined && val <= bound) {\n errors.push(`Value must be > ${bound}`);\n }\n }\n if (schema.exclusiveMaximum !== undefined) {\n const bound =\n typeof schema.exclusiveMaximum === \"number\"\n ? schema.exclusiveMaximum\n : schema.maximum;\n if (bound !== undefined && val >= bound) {\n errors.push(`Value must be < ${bound}`);\n }\n }\n if (schema.multipleOf !== undefined) {\n const remainder = Math.abs(val % schema.multipleOf);\n if (\n remainder > 1e-10 &&\n Math.abs(remainder - schema.multipleOf) > 1e-10\n ) {\n errors.push(`Value must be a multiple of ${schema.multipleOf}`);\n }\n }\n }\n\n if (node.type === \"string\" && typeof node.value === \"string\") {\n const val = node.value;\n if (schema.minLength !== undefined && val.length < schema.minLength) {\n errors.push(`Must be at least ${schema.minLength} characters`);\n }\n if (schema.maxLength !== undefined && val.length > schema.maxLength) {\n errors.push(`Must be at most ${schema.maxLength} characters`);\n }\n if (schema.pattern) {\n try {\n if (!new RegExp(schema.pattern).test(val)) {\n errors.push(`Must match pattern: ${schema.pattern}`);\n }\n } catch {\n // invalid regex in schema, skip\n }\n }\n if (schema.format && FORMAT_PATTERNS[schema.format]) {\n if (!FORMAT_PATTERNS[schema.format].test(val)) {\n errors.push(`Invalid ${schema.format} format`);\n }\n }\n }\n\n if (node.type === \"array\") {\n if (\n schema.minItems !== undefined &&\n node.children.length < schema.minItems\n ) {\n errors.push(`Must have at least ${schema.minItems} items`);\n }\n if (\n schema.maxItems !== undefined &&\n node.children.length > schema.maxItems\n ) {\n errors.push(`Must have at most ${schema.maxItems} items`);\n }\n }\n\n if (node.type === \"object\") {\n if (\n schema.minProperties !== undefined &&\n node.children.length < schema.minProperties\n ) {\n errors.push(`Must have at least ${schema.minProperties} properties`);\n }\n if (\n schema.maxProperties !== undefined &&\n node.children.length > schema.maxProperties\n ) {\n errors.push(`Must have at most ${schema.maxProperties} properties`);\n }\n }\n\n return { valid: errors.length === 0, errors };\n}\n","import type { TreeNode, TreeState } from \"./types\";\n\nexport interface SearchMatch {\n nodeId: string;\n field: \"key\" | \"value\";\n}\n\nexport function searchNodes(tree: TreeState, query: string): SearchMatch[] {\n if (!query.trim()) return [];\n const matches: SearchMatch[] = [];\n const lower = query.toLowerCase();\n\n function walk(node: TreeNode) {\n if (node.key && node.key.toLowerCase().includes(lower)) {\n matches.push({ nodeId: node.id, field: \"key\" });\n }\n if (\n node.value !== undefined &&\n node.value !== null &&\n String(node.value).toLowerCase().includes(lower)\n ) {\n matches.push({ nodeId: node.id, field: \"value\" });\n }\n for (const child of node.children) {\n walk(child);\n }\n }\n\n walk(tree.root);\n return matches;\n}\n\n/**\n * Collect all ancestor node IDs for each matched node so the tree\n * can auto-expand paths to search results.\n */\nexport function getAncestorIds(\n tree: TreeState,\n nodeIds: string[],\n): Set<string> {\n const ancestors = new Set<string>();\n\n for (const nodeId of nodeIds) {\n let current = tree.nodesById.get(nodeId);\n while (current && current.parentId) {\n ancestors.add(current.parentId);\n current = tree.nodesById.get(current.parentId);\n }\n }\n\n return ancestors;\n}\n","import type { JsonValue } from \"./types\";\n\nexport type DiffType = \"added\" | \"removed\" | \"changed\";\n\nexport interface DiffEntry {\n path: string;\n type: DiffType;\n oldValue?: JsonValue;\n newValue?: JsonValue;\n}\n\nexport function computeDiff(\n original: JsonValue,\n current: JsonValue,\n path = \"\",\n): DiffEntry[] {\n const entries: DiffEntry[] = [];\n\n if (original === current) {\n return entries;\n }\n\n if (\n original === null ||\n current === null ||\n typeof original !== typeof current ||\n Array.isArray(original) !== Array.isArray(current)\n ) {\n if (path) {\n entries.push({\n path,\n type: \"changed\",\n oldValue: original,\n newValue: current,\n });\n } else {\n diffObject(original, current, path, entries);\n }\n return entries;\n }\n\n if (typeof original !== \"object\") {\n if (original !== current) {\n entries.push({\n path: path || \"/\",\n type: \"changed\",\n oldValue: original,\n newValue: current,\n });\n }\n return entries;\n }\n\n if (Array.isArray(original) && Array.isArray(current)) {\n const maxLen = Math.max(original.length, current.length);\n for (let i = 0; i < maxLen; i++) {\n const childPath = path ? `${path}/${i}` : `/${i}`;\n if (i >= original.length) {\n entries.push({ path: childPath, type: \"added\", newValue: current[i] });\n } else if (i >= current.length) {\n entries.push({\n path: childPath,\n type: \"removed\",\n oldValue: original[i],\n });\n } else {\n entries.push(...computeDiff(original[i], current[i], childPath));\n }\n }\n return entries;\n }\n\n diffObject(original, current, path, entries);\n return entries;\n}\n\nfunction diffObject(\n original: JsonValue,\n current: JsonValue,\n path: string,\n entries: DiffEntry[],\n) {\n const origObj =\n original !== null &&\n typeof original === \"object\" &&\n !Array.isArray(original)\n ? (original as Record<string, JsonValue>)\n : {};\n const currObj =\n current !== null && typeof current === \"object\" && !Array.isArray(current)\n ? (current as Record<string, JsonValue>)\n : {};\n\n const allKeys = new Set([...Object.keys(origObj), ...Object.keys(currObj)]);\n\n for (const key of allKeys) {\n const childPath = path ? `${path}/${key}` : `/${key}`;\n const inOriginal = key in origObj;\n const inCurrent = key in currObj;\n\n if (!inOriginal && inCurrent) {\n entries.push({ path: childPath, type: \"added\", newValue: currObj[key] });\n } else if (inOriginal && !inCurrent) {\n entries.push({\n path: childPath,\n type: \"removed\",\n oldValue: origObj[key],\n });\n } else {\n entries.push(...computeDiff(origObj[key], currObj[key], childPath));\n }\n }\n}\n\nexport function getDiffPaths(entries: DiffEntry[]): Map<string, DiffType> {\n const map = new Map<string, DiffType>();\n for (const entry of entries) {\n map.set(entry.path, entry.type);\n }\n return map;\n}\n"],"mappings":";AAUA,IAAI,SAAS;AAEN,SAAS,aAAqB;AACnC,SAAO,QAAQ,EAAE,MAAM;AACzB;AAEO,SAAS,iBAAuB;AACrC,WAAS;AACX;AAEO,SAAS,YAAY,OAA4B;AACtD,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO;AACjC,SAAO,OAAO;AAChB;AAEO,SAAS,aACd,KACA,OACA,YACA,UACA,WACU;AACV,QAAM,KAAK,WAAW;AACtB,QAAM,OAAO,aAAa,GAAG,UAAU,IAAI,GAAG,KAAK,IAAI,GAAG;AAC1D,QAAM,OAAO,YAAY,KAAK;AAE9B,QAAM,OAAiB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OACE,SAAS,YAAY,SAAS,UAC1B,SACC;AAAA,IACP,UAAU,CAAC;AAAA,IACX;AAAA,EACF;AAEA,YAAU,IAAI,IAAI,IAAI;AAEtB,MAAI,SAAS,YAAY,UAAU,MAAM;AACvC,UAAM,MAAM;AACZ,SAAK,WAAW,OAAO,KAAK,GAAG,EAAE;AAAA,MAAI,CAAC,aACpC,aAAa,UAAU,IAAI,QAAQ,GAAG,MAAM,IAAI,SAAS;AAAA,IAC3D;AAAA,EACF,WAAW,SAAS,SAAS;AAC3B,UAAM,MAAM;AACZ,SAAK,WAAW,IAAI;AAAA,MAAI,CAAC,MAAM,UAC7B,aAAa,OAA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,6 @@
1
1
  {
2
2
  "name": "@visual-json/core",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Headless core for visual-json — the visual JSON editor. Schema-aware, embeddable, extensible.",
6
6
  "keywords": [
@@ -26,15 +26,15 @@
26
26
  "files": [
27
27
  "dist"
28
28
  ],
29
- "devDependencies": {
30
- "tsup": "^8.5.1",
31
- "typescript": "5.9.3"
32
- },
33
29
  "scripts": {
34
30
  "build": "tsup",
35
31
  "dev": "tsup --watch",
36
32
  "check-types": "tsc --noEmit",
37
33
  "lint": "eslint .",
38
34
  "format": "prettier --write \"**/*.{ts,tsx}\""
35
+ },
36
+ "devDependencies": {
37
+ "tsup": "^8.5.1",
38
+ "typescript": "5.9.3"
39
39
  }
40
- }
40
+ }
package/LICENSE DELETED
@@ -1,201 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to the Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by the Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding any notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. Please also get an
186
- "applicable copyright law appl" file (see
187
- http://www.apache.org/legal/), if one is available.
188
-
189
- Copyright 2025 visual-json contributors
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.