@graphiql/plugin-query-builder 1.0.0 → 1.0.1

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.
Files changed (43) hide show
  1. package/dist/components/arg-input/arg-input-by-type.js +1 -2
  2. package/dist/components/arg-input/arg-input-by-type.js.map +1 -1
  3. package/dist/components/arg-input/enum-arg-control.js +1 -2
  4. package/dist/components/arg-input/enum-arg-control.js.map +1 -1
  5. package/dist/components/arg-input/index.js +1 -2
  6. package/dist/components/arg-input/index.js.map +1 -1
  7. package/dist/components/arg-input/scalar-arg-control.js +1 -2
  8. package/dist/components/arg-input/scalar-arg-control.js.map +1 -1
  9. package/dist/components/field-row.js +1 -2
  10. package/dist/components/field-row.js.map +1 -1
  11. package/dist/components/field-tree-context.d.ts +1 -1
  12. package/dist/components/field-tree-context.js +1 -2
  13. package/dist/components/field-tree-context.js.map +1 -1
  14. package/dist/components/field-tree-node.js +228 -92
  15. package/dist/components/field-tree-node.js.map +1 -1
  16. package/dist/components/field-tree.js +2 -3
  17. package/dist/components/field-tree.js.map +1 -1
  18. package/dist/components/fragment-editor.js +1 -2
  19. package/dist/components/fragment-editor.js.map +1 -1
  20. package/dist/components/fragment-section.js +1 -2
  21. package/dist/components/fragment-section.js.map +1 -1
  22. package/dist/components/query-builder.js +81 -91
  23. package/dist/components/query-builder.js.map +1 -1
  24. package/dist/components/type-condition-selector.js +193 -203
  25. package/dist/components/type-condition-selector.js.map +1 -1
  26. package/dist/components/use-cursor-path.js +1 -2
  27. package/dist/components/use-cursor-path.js.map +1 -1
  28. package/dist/components/use-cursor-reveal.d.ts +3 -1
  29. package/dist/components/use-cursor-reveal.js +49 -46
  30. package/dist/components/use-cursor-reveal.js.map +1 -1
  31. package/dist/components/use-working-document.js +295 -281
  32. package/dist/components/use-working-document.js.map +1 -1
  33. package/dist/index.js +2 -3
  34. package/dist/lib/arg-value.js +1 -2
  35. package/dist/lib/arguments.js +1 -2
  36. package/dist/lib/ast-path.js +1 -2
  37. package/dist/lib/field-list-view.js +1 -2
  38. package/dist/lib/field-selection.js +1 -2
  39. package/dist/lib/fragments.js +1 -2
  40. package/dist/lib/inline-fragments.js +1 -2
  41. package/dist/lib/schema-walk.js +1 -2
  42. package/dist/lib/variables.js +1 -2
  43. package/package.json +10 -8
@@ -3,7 +3,7 @@ import { useGraphiQL, useMonaco } from "@graphiql/react";
3
3
  import { c } from "react-compiler-runtime";
4
4
  import { parse } from "graphql";
5
5
  import { useEffect, useState } from "react";
6
- //#region src/components/use-cursor-path.ts
6
+ // src/components/use-cursor-path.ts
7
7
  var EMPTY_CONTEXT = {
8
8
  target: void 0,
9
9
  path: []
@@ -76,7 +76,6 @@ function _temp2(state_0) {
76
76
  function _temp(state) {
77
77
  return state.queryEditor;
78
78
  }
79
- //#endregion
80
79
  export { useCursorContext };
81
80
 
82
81
  //# sourceMappingURL=use-cursor-path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-cursor-path.js","names":["useGraphiQL","useMonaco","parse","useEffect","useState","DefinitionTarget","PathSegment","cursorContextAtOffset","CursorContext","target","path","EMPTY_CONTEXT","undefined","useCursorContext","$","_c","queryEditor","_temp","monaco","_temp2","context","setContext","t0","editor","timer","recompute","model","getModel","pos","getPosition","offset","getOffsetAt","resolved","getValue","schedule","clearTimeout","setTimeout","cursorDisposable","onDidChangeCursorPosition","e","reason","CursorChangeReason","Explicit","contentDisposable","onDidChangeModelContent","e_0","isFlush","dispose","t1","state_0","state"],"sources":["../../src/components/use-cursor-path.ts"],"sourcesContent":["import { useGraphiQL, useMonaco } from '@graphiql/react';\nimport { parse } from 'graphql';\nimport { useEffect, useState } from 'react';\nimport { type DefinitionTarget, type PathSegment } from '../lib/ast-path';\nimport { cursorContextAtOffset } from '../lib/schema-walk';\n\nexport interface CursorContext {\n /** The definition the cursor sits in, or undefined when it's outside one. */\n target: DefinitionTarget | undefined;\n /** Field path under the cursor within `target`; empty when not on a field. */\n path: PathSegment[];\n}\n\nconst EMPTY_CONTEXT: CursorContext = { target: undefined, path: [] };\n\n/**\n * Tracks the definition (operation or fragment) and field path under the editor\n * cursor. The builder follows this: the cursor's definition is the one being\n * edited, and the path expands the tree down to the cursor. Subscribes to the\n * query editor directly (debounced to avoid thrashing while typing), reacting\n * to explicit cursor moves and edits, but not content flushes from the\n * builder's own writes.\n */\nexport function useCursorContext(): CursorContext {\n const queryEditor = useGraphiQL(state => state.queryEditor);\n const monaco = useMonaco(state => state.monaco);\n\n const [context, setContext] = useState<CursorContext>(EMPTY_CONTEXT);\n useEffect(() => {\n if (!queryEditor) {\n return;\n }\n let timer: ReturnType<typeof setTimeout> | undefined;\n const recompute = () => {\n const model = queryEditor.getModel();\n const pos = queryEditor.getPosition();\n if (!model || !pos) {\n return;\n }\n const offset = model.getOffsetAt(pos);\n let resolved:\n | { target: DefinitionTarget | undefined; path: PathSegment[] }\n | undefined;\n try {\n resolved = cursorContextAtOffset(parse(model.getValue()), offset);\n } catch {\n // Unparseable in-progress edit — leave the context as-is.\n return;\n }\n setContext(resolved ?? EMPTY_CONTEXT);\n };\n const schedule = () => {\n clearTimeout(timer);\n timer = setTimeout(recompute, 80);\n };\n const cursorDisposable = queryEditor.onDidChangeCursorPosition(e => {\n // Only react to explicit (user) cursor moves, not content-flush/programmatic ones.\n if (e.reason === monaco?.editor.CursorChangeReason.Explicit) {\n schedule();\n }\n });\n const contentDisposable = queryEditor.onDidChangeModelContent(e => {\n // Typing moves the cursor with reason NotSet. setValue from the builder\n // also moves it, but its content event is a flush.\n if (!e.isFlush) {\n schedule();\n }\n });\n recompute();\n return () => {\n clearTimeout(timer);\n cursorDisposable.dispose();\n contentDisposable.dispose();\n };\n }, [queryEditor, monaco]);\n\n return context;\n}\n"],"mappings":";;;;;;AAaA,IAAMW,gBAA+B;CAAEF,QAAQG,KAAAA;CAAWF,MAAM,CAAA;AAAG;;;;;;;;;AAUnE,SAAOG,mBAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACL,MAAAC,cA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;CAAA,OAAAA,KAAAlC,EAAA;CA9CxBX,UAAUmB,IA8CP0B,EAAqB;CAAC,OAElB5B;AAAO;AArDT,SAAAD,OAAA8B,SAAA;CAAA,OAE6BC,QAAKhC;AAAO;AAFzC,SAAAD,MAAAiC,OAAA;CAAA,OACoCA,MAAKlC;AAAY"}
1
+ {"version":3,"file":"use-cursor-path.js","names":["useGraphiQL","useMonaco","parse","useEffect","useState","DefinitionTarget","PathSegment","cursorContextAtOffset","CursorContext","target","path","EMPTY_CONTEXT","undefined","useCursorContext","$","_c","queryEditor","_temp","monaco","_temp2","context","setContext","t0","editor","timer","recompute","model","getModel","pos","getPosition","offset","getOffsetAt","resolved","getValue","schedule","clearTimeout","setTimeout","cursorDisposable","onDidChangeCursorPosition","e","reason","CursorChangeReason","Explicit","contentDisposable","onDidChangeModelContent","e_0","isFlush","dispose","t1","state_0","state","_c"],"sources":["../../src/components/use-cursor-path.ts"],"sourcesContent":["import { useGraphiQL, useMonaco } from '@graphiql/react';\nimport { parse } from 'graphql';\nimport { useEffect, useState } from 'react';\nimport { type DefinitionTarget, type PathSegment } from '../lib/ast-path';\nimport { cursorContextAtOffset } from '../lib/schema-walk';\n\nexport interface CursorContext {\n /** The definition the cursor sits in, or undefined when it's outside one. */\n target: DefinitionTarget | undefined;\n /** Field path under the cursor within `target`; empty when not on a field. */\n path: PathSegment[];\n}\n\nconst EMPTY_CONTEXT: CursorContext = { target: undefined, path: [] };\n\n/**\n * Tracks the definition (operation or fragment) and field path under the editor\n * cursor. The builder follows this: the cursor's definition is the one being\n * edited, and the path expands the tree down to the cursor. Subscribes to the\n * query editor directly (debounced to avoid thrashing while typing), reacting\n * to explicit cursor moves and edits, but not content flushes from the\n * builder's own writes.\n */\nexport function useCursorContext(): CursorContext {\n const queryEditor = useGraphiQL(state => state.queryEditor);\n const monaco = useMonaco(state => state.monaco);\n\n const [context, setContext] = useState<CursorContext>(EMPTY_CONTEXT);\n useEffect(() => {\n if (!queryEditor) {\n return;\n }\n let timer: ReturnType<typeof setTimeout> | undefined;\n const recompute = () => {\n const model = queryEditor.getModel();\n const pos = queryEditor.getPosition();\n if (!model || !pos) {\n return;\n }\n const offset = model.getOffsetAt(pos);\n let resolved:\n | { target: DefinitionTarget | undefined; path: PathSegment[] }\n | undefined;\n try {\n resolved = cursorContextAtOffset(parse(model.getValue()), offset);\n } catch {\n // Unparseable in-progress edit — leave the context as-is.\n return;\n }\n setContext(resolved ?? EMPTY_CONTEXT);\n };\n const schedule = () => {\n clearTimeout(timer);\n timer = setTimeout(recompute, 80);\n };\n const cursorDisposable = queryEditor.onDidChangeCursorPosition(e => {\n // Only react to explicit (user) cursor moves, not content-flush/programmatic ones.\n if (e.reason === monaco?.editor.CursorChangeReason.Explicit) {\n schedule();\n }\n });\n const contentDisposable = queryEditor.onDidChangeModelContent(e => {\n // Typing moves the cursor with reason NotSet. setValue from the builder\n // also moves it, but its content event is a flush.\n if (!e.isFlush) {\n schedule();\n }\n });\n recompute();\n return () => {\n clearTimeout(timer);\n cursorDisposable.dispose();\n contentDisposable.dispose();\n };\n }, [queryEditor, monaco]);\n\n return context;\n}\n"],"mappings":";;;;;;AAaA,IAAMW,gBAA+B;CAAEF,QAAQG,KAAAA;CAAWF,MAAM,CAAA;AAAG;;;;;;;;;AAUnE,SAAOG,mBAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CACL,MAAAC,cAAoBhB,YAAYiB,KAA0B;CAC1D,MAAAC,SAAejB,UAAUkB,MAAqB;CAE9C,MAAA,CAAAC,SAAAC,cAA8BjB,SAAwBO,aAAa;CAAE,IAAAW;CAAA,IAAAR,EAAA,OAAAI,QAAAK,UAAAT,EAAA,OAAAE,aAAA;EAC3DM,WAAA;GACR,IAAI,CAACN,aAAW;GAGZQ,IAAAA;GACJ,MAAAC,kBAAkB;IAChB,MAAAC,QAAcV,YAAWW,SAAU;IACnC,MAAAC,MAAYZ,YAAWa,YAAa;IACpC,IAAI,CAACH,SAAD,CAAWE,KAAG;IAGlB,MAAAE,SAAeJ,MAAKK,YAAaH,GAAG;IAChCI,IAAAA;IAGJ,IAAA;KACEA,WAAWzB,sBAAsBL,MAAMwB,MAAKO,SAAU,CAAC,GAAGH,MAAM;IAAxD,QAAA;KAAA;IAAA;IAKVT,WAAWW,YAAArB,aAAyB;GAAC;GAEvC,MAAAuB,iBAAiB;IACfC,aAAaX,KAAK;IAClBA,QAAQY,WAAWX,WAAW,EAAE;GAA3B;GAEP,MAAAY,mBAAyBrB,YAAWsB,2BAA2BC,MAAA;IAE7D,IAAIA,EAACC,WAAYtB,QAAMK,OAA2BkB,mBAASC,UACzDR,SAAS;GACV,CACF;GACD,MAAAS,oBAA0B3B,YAAW4B,yBAAyBC,QAAA;IAG5D,IAAI,CAACN,IAACO,SACJZ,SAAS;GACV,CACF;GACDT,UAAU;GAAC,aACJ;IACLU,aAAaX,KAAK;IAClBa,iBAAgBU,QAAS;IACzBJ,kBAAiBI,QAAS;GAAC;EAC5B;EACFjC,EAAA,KAAAI,QAAAK;EAAAT,EAAA,KAAAE;EAAAF,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CAAA,IAAAkC;CAAA,IAAAlC,EAAA,OAAAI,UAAAJ,EAAA,OAAAE,aAAA;EAAEgC,KAAA,CAAChC,aAAaE,MAAM;EAACJ,EAAA,KAAAI;EAAAJ,EAAA,KAAAE;EAAAF,EAAA,KAAAkC;CAAA,OAAAA,KAAAlC,EAAA;CA9CxBX,UAAUmB,IA8CP0B,EAAqB;CAAC,OAElB5B;AAAO;AArDT,SAAAD,OAAA8B,SAAA;CAAA,OAE6BC,QAAKhC;AAAO;AAFzC,SAAAD,MAAAiC,OAAA;CAAA,OACoCA,MAAKlC;AAAY"}
@@ -8,7 +8,9 @@ import { PathSegment } from '../lib/ast-path';
8
8
  * the one field the cursor sits in. Shared by field rows and inline-fragment
9
9
  * rows so both react to the cursor.
10
10
  */
11
- export declare function useCursorReveal(fullPath: PathSegment[], cursorPath: PathSegment[] | undefined, setExpanded: (value: boolean) => void): {
11
+ export declare function useCursorReveal(fullPath: PathSegment[], cursorPath: PathSegment[] | undefined): {
12
+ expanded: boolean;
13
+ setExpanded: import('react').Dispatch<import('react').SetStateAction<boolean>>;
12
14
  flash: boolean;
13
15
  current: boolean;
14
16
  nodeRef: import('react').RefObject<HTMLDivElement | null>;
@@ -1,7 +1,7 @@
1
1
  import { segmentsEqual } from "../lib/ast-path.js";
2
2
  import { c } from "react-compiler-runtime";
3
3
  import { useEffect, useRef, useState } from "react";
4
- //#region src/components/use-cursor-reveal.ts
4
+ // src/components/use-cursor-reveal.ts
5
5
  /**
6
6
  * Reveals a tree node as the editor cursor moves onto it or a descendant:
7
7
  * auto-expands it when it's an ancestor of the cursor's field, and (only when
@@ -11,8 +11,8 @@ import { useEffect, useRef, useState } from "react";
11
11
  * the one field the cursor sits in. Shared by field rows and inline-fragment
12
12
  * rows so both react to the cursor.
13
13
  */
14
- function useCursorReveal(fullPath, cursorPath, setExpanded) {
15
- const $ = c(18);
14
+ function useCursorReveal(fullPath, cursorPath) {
15
+ const $ = c(15);
16
16
  let t0;
17
17
  if ($[0] !== cursorPath || $[1] !== fullPath) {
18
18
  t0 = cursorPath !== void 0 && cursorPath.length >= fullPath.length && fullPath.every((seg, i) => segmentsEqual(cursorPath[i], seg));
@@ -24,63 +24,66 @@ function useCursorReveal(fullPath, cursorPath, setExpanded) {
24
24
  const isAncestor = onCursorPath && cursorPath.length > fullPath.length;
25
25
  const isTarget = onCursorPath && cursorPath.length === fullPath.length;
26
26
  const nodeRef = useRef(null);
27
- const [flash, setFlash] = useState(false);
27
+ const [expanded, setExpanded] = useState(isAncestor);
28
28
  let t1;
29
- if ($[3] !== isAncestor || $[4] !== setExpanded) {
30
- t1 = () => {
31
- if (isAncestor) setExpanded(true);
29
+ if ($[3] !== cursorPath || $[4] !== isAncestor || $[5] !== isTarget) {
30
+ t1 = {
31
+ path: cursorPath,
32
+ isAncestor,
33
+ isTarget
32
34
  };
33
- $[3] = isAncestor;
34
- $[4] = setExpanded;
35
- $[5] = t1;
36
- } else t1 = $[5];
37
- let t2;
38
- if ($[6] !== cursorPath || $[7] !== isAncestor || $[8] !== setExpanded) {
39
- t2 = [
40
- cursorPath,
35
+ $[3] = cursorPath;
36
+ $[4] = isAncestor;
37
+ $[5] = isTarget;
38
+ $[6] = t1;
39
+ } else t1 = $[6];
40
+ const [previousCursor, setPreviousCursor] = useState(t1);
41
+ const [expiredCursorPath, setExpiredCursorPath] = useState();
42
+ const flash = isTarget && expiredCursorPath !== cursorPath;
43
+ if (cursorPath !== previousCursor.path || isAncestor !== previousCursor.isAncestor || isTarget !== previousCursor.isTarget) {
44
+ setPreviousCursor({
45
+ path: cursorPath,
41
46
  isAncestor,
42
- setExpanded
43
- ];
44
- $[6] = cursorPath;
45
- $[7] = isAncestor;
46
- $[8] = setExpanded;
47
- $[9] = t2;
48
- } else t2 = $[9];
49
- useEffect(t1, t2);
47
+ isTarget
48
+ });
49
+ if (isAncestor) setExpanded(true);
50
+ if (isTarget && !previousCursor.isTarget) setExpiredCursorPath(void 0);
51
+ }
52
+ let t2;
50
53
  let t3;
51
- if ($[10] !== isTarget) {
52
- t3 = () => {
54
+ if ($[7] !== cursorPath || $[8] !== isTarget) {
55
+ t2 = () => {
53
56
  if (!isTarget) return;
54
- setFlash(true);
55
57
  (nodeRef.current?.firstElementChild ?? nodeRef.current)?.scrollIntoView({ block: "center" });
56
- const timer = setTimeout(() => setFlash(false), 700);
58
+ const timer = setTimeout(() => setExpiredCursorPath(cursorPath), 700);
57
59
  return () => clearTimeout(timer);
58
60
  };
59
- $[10] = isTarget;
60
- $[11] = t3;
61
- } else t3 = $[11];
61
+ t3 = [cursorPath, isTarget];
62
+ $[7] = cursorPath;
63
+ $[8] = isTarget;
64
+ $[9] = t2;
65
+ $[10] = t3;
66
+ } else {
67
+ t2 = $[9];
68
+ t3 = $[10];
69
+ }
70
+ useEffect(t2, t3);
62
71
  let t4;
63
- if ($[12] !== cursorPath || $[13] !== isTarget) {
64
- t4 = [cursorPath, isTarget];
65
- $[12] = cursorPath;
66
- $[13] = isTarget;
67
- $[14] = t4;
68
- } else t4 = $[14];
69
- useEffect(t3, t4);
70
- let t5;
71
- if ($[15] !== flash || $[16] !== isTarget) {
72
- t5 = {
72
+ if ($[11] !== expanded || $[12] !== flash || $[13] !== isTarget) {
73
+ t4 = {
74
+ expanded,
75
+ setExpanded,
73
76
  flash,
74
77
  current: isTarget,
75
78
  nodeRef
76
79
  };
77
- $[15] = flash;
78
- $[16] = isTarget;
79
- $[17] = t5;
80
- } else t5 = $[17];
81
- return t5;
80
+ $[11] = expanded;
81
+ $[12] = flash;
82
+ $[13] = isTarget;
83
+ $[14] = t4;
84
+ } else t4 = $[14];
85
+ return t4;
82
86
  }
83
- //#endregion
84
87
  export { useCursorReveal };
85
88
 
86
89
  //# sourceMappingURL=use-cursor-reveal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-cursor-reveal.js","names":["useEffect","useRef","useState","segmentsEqual","PathSegment","useCursorReveal","fullPath","cursorPath","setExpanded","$","_c","t0","undefined","length","every","seg","i","onCursorPath","isAncestor","isTarget","nodeRef","flash","setFlash","t1","t2","t3","row","current","firstElementChild","scrollIntoView","block","timer","setTimeout","clearTimeout","t4","t5"],"sources":["../../src/components/use-cursor-reveal.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { segmentsEqual, type PathSegment } from '../lib/ast-path';\n\n/**\n * Reveals a tree node as the editor cursor moves onto it or a descendant:\n * auto-expands it when it's an ancestor of the cursor's field, and (only when\n * the cursor lands exactly on it) flashes it, scrolls it into view, and marks it\n * as the current node so the row can show a persistent highlight. Ancestors\n * expand but neither flash nor highlight, to keep the \"you are here\" signal on\n * the one field the cursor sits in. Shared by field rows and inline-fragment\n * rows so both react to the cursor.\n */\nexport function useCursorReveal(\n fullPath: PathSegment[],\n cursorPath: PathSegment[] | undefined,\n setExpanded: (value: boolean) => void,\n) {\n const onCursorPath =\n cursorPath !== undefined &&\n cursorPath.length >= fullPath.length &&\n fullPath.every((seg, i) => segmentsEqual(cursorPath[i]!, seg));\n const isAncestor = onCursorPath && cursorPath.length > fullPath.length;\n const isTarget = onCursorPath && cursorPath.length === fullPath.length;\n\n const nodeRef = useRef<HTMLDivElement>(null);\n const [flash, setFlash] = useState(false);\n\n // Re-assert on every cursor move (depend on the `cursorPath` array identity,\n // not just `isAncestor`): otherwise a node that's already an ancestor when it\n // gets collapsed never re-expands as the cursor moves deeper, since\n // `isAncestor` stays true and the effect wouldn't re-run.\n useEffect(() => {\n if (isAncestor) {\n setExpanded(true);\n }\n }, [cursorPath, isAncestor, setExpanded]);\n\n // Depend on the `cursorPath` array identity, not its contents: the editor\n // hands us a fresh array on every cursor event, so re-placing the cursor on\n // the same field re-flashes it (handy for getting your bearings).\n useEffect(() => {\n if (!isTarget) {\n return;\n }\n setFlash(true);\n // Scroll the header row into view, not the whole node. For a composite field\n // the node also wraps its expanded children, so centering the node would\n // center that tall subtree and leave the field's own row off-center. The\n // first child is the row (the children, if any, follow it). Centered\n // vertically so it doesn't land under the sticky operation header.\n const row = nodeRef.current?.firstElementChild ?? nodeRef.current;\n row?.scrollIntoView({ block: 'center' });\n const timer = setTimeout(() => setFlash(false), 700);\n return () => clearTimeout(timer);\n }, [cursorPath, isTarget]);\n\n return { flash, current: isTarget, nodeRef };\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAOK,gBAAAC,UAAAC,YAAAC,aAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAF,cAAAE,EAAA,OAAAH,UAAA;EAMHK,KAAAJ,eAAeK,KAAAA,KACfL,WAAUM,UAAWP,SAAQO,UAC7BP,SAAQQ,OAAOC,KAAAC,MAAYb,cAAcI,WAAWS,IAAKD,GAAG,CAAC;EAACN,EAAA,KAAAF;EAAAE,EAAA,KAAAH;EAAAG,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAHhE,MAAAQ,e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B,IAcPS,EAAsB;CAAC,IAAAC;CAAA,IAAA1B,EAAA,QAAAY,SAAAZ,EAAA,QAAAU,UAAA;EAEnBgB,KAAA;GAAAd;GAAAM,SAAkBR;GAAQC;EAAU;EAACX,EAAA,MAAAY;EAAAZ,EAAA,MAAAU;EAAAV,EAAA,MAAA0B;CAAA,OAAAA,KAAA1B,EAAA;CAAA,OAArC0B;AAAqC"}
1
+ {"version":3,"file":"use-cursor-reveal.js","names":["useEffect","useRef","useState","segmentsEqual","PathSegment","useCursorReveal","fullPath","cursorPath","$","_c","t0","undefined","length","every","seg","i","onCursorPath","isAncestor","isTarget","nodeRef","expanded","setExpanded","t1","path","previousCursor","setPreviousCursor","expiredCursorPath","setExpiredCursorPath","flash","t2","t3","row","current","firstElementChild","scrollIntoView","block","timer","setTimeout","clearTimeout","t4","_c"],"sources":["../../src/components/use-cursor-reveal.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { segmentsEqual, type PathSegment } from '../lib/ast-path';\n\n/**\n * Reveals a tree node as the editor cursor moves onto it or a descendant:\n * auto-expands it when it's an ancestor of the cursor's field, and (only when\n * the cursor lands exactly on it) flashes it, scrolls it into view, and marks it\n * as the current node so the row can show a persistent highlight. Ancestors\n * expand but neither flash nor highlight, to keep the \"you are here\" signal on\n * the one field the cursor sits in. Shared by field rows and inline-fragment\n * rows so both react to the cursor.\n */\nexport function useCursorReveal(\n fullPath: PathSegment[],\n cursorPath: PathSegment[] | undefined,\n) {\n const onCursorPath =\n cursorPath !== undefined &&\n cursorPath.length >= fullPath.length &&\n fullPath.every((seg, i) => segmentsEqual(cursorPath[i]!, seg));\n const isAncestor = onCursorPath && cursorPath.length > fullPath.length;\n const isTarget = onCursorPath && cursorPath.length === fullPath.length;\n\n const nodeRef = useRef<HTMLDivElement>(null);\n const [expanded, setExpanded] = useState(isAncestor);\n const [previousCursor, setPreviousCursor] = useState({\n path: cursorPath,\n isAncestor,\n isTarget,\n });\n const [expiredCursorPath, setExpiredCursorPath] = useState<PathSegment[]>();\n const flash = isTarget && expiredCursorPath !== cursorPath;\n\n // Manual collapse lasts until the next cursor event, even on the same field.\n if (\n cursorPath !== previousCursor.path ||\n isAncestor !== previousCursor.isAncestor ||\n isTarget !== previousCursor.isTarget\n ) {\n setPreviousCursor({ path: cursorPath, isAncestor, isTarget });\n if (isAncestor) {\n setExpanded(true);\n }\n if (isTarget && !previousCursor.isTarget) {\n setExpiredCursorPath(undefined);\n }\n }\n\n // Depend on the `cursorPath` array identity, not its contents: the editor\n // hands us a fresh array on every cursor event, so re-placing the cursor on\n // the same field re-flashes it (handy for getting your bearings).\n useEffect(() => {\n if (!isTarget) {\n return;\n }\n // Scroll the header row into view, not the whole node. For a composite field\n // the node also wraps its expanded children, so centering the node would\n // center that tall subtree and leave the field's own row off-center. The\n // first child is the row (the children, if any, follow it). Centered\n // vertically so it doesn't land under the sticky operation header.\n const row = nodeRef.current?.firstElementChild ?? nodeRef.current;\n row?.scrollIntoView({ block: 'center' });\n const timer = setTimeout(() => setExpiredCursorPath(cursorPath), 700);\n return () => clearTimeout(timer);\n }, [cursorPath, isTarget]);\n\n return { expanded, setExpanded, flash, current: isTarget, nodeRef };\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAOK,gBAAAC,UAAAC,YAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAD,cAAAC,EAAA,OAAAF,UAAA;EAKHI,KAAAH,eAAeI,KAAAA,KACfJ,WAAUK,UAAWN,SAAQM,UAC7BN,SAAQO,OAAOC,KAAAC,MAAYZ,cAAcI,WAAWQ,IAAKD,GAAG,CAAC;EAACN,EAAA,KAAAD;EAAAC,EAAA,KAAAF;EAAAE,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAHhE,MAAAQ,eACEN;CAGF,MAAAO,aAAmBD,gBAAgBT,WAAUK,SAAUN,SAAQM;CAC/D,MAAAM,WAAiBF,gBAAgBT,WAAUK,WAA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