@graphiql/plugin-query-builder 1.0.0-beta.0 → 1.0.0-beta.2

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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/arg-input/arg-input-by-type.js +441 -444
  3. package/dist/components/arg-input/arg-input-by-type.js.map +1 -1
  4. package/dist/components/arg-input/enum-arg-control.js +49 -52
  5. package/dist/components/arg-input/enum-arg-control.js.map +1 -1
  6. package/dist/components/arg-input/index.js +44 -36
  7. package/dist/components/arg-input/index.js.map +1 -1
  8. package/dist/components/arg-input/scalar-arg-control.js +58 -63
  9. package/dist/components/arg-input/scalar-arg-control.js.map +1 -1
  10. package/dist/components/field-row.js +212 -197
  11. package/dist/components/field-row.js.map +1 -1
  12. package/dist/components/field-tree-context.js +23 -27
  13. package/dist/components/field-tree-context.js.map +1 -1
  14. package/dist/components/field-tree-node.js +128 -105
  15. package/dist/components/field-tree-node.js.map +1 -1
  16. package/dist/components/field-tree.js +178 -199
  17. package/dist/components/field-tree.js.map +1 -1
  18. package/dist/components/fragment-editor.js +157 -151
  19. package/dist/components/fragment-editor.js.map +1 -1
  20. package/dist/components/fragment-section.js +215 -203
  21. package/dist/components/fragment-section.js.map +1 -1
  22. package/dist/components/query-builder.js +205 -181
  23. package/dist/components/query-builder.js.map +1 -1
  24. package/dist/components/type-condition-selector.js +417 -462
  25. package/dist/components/type-condition-selector.js.map +1 -1
  26. package/dist/components/use-cursor-path.js +69 -70
  27. package/dist/components/use-cursor-path.js.map +1 -1
  28. package/dist/components/use-cursor-reveal.js +83 -89
  29. package/dist/components/use-cursor-reveal.js.map +1 -1
  30. package/dist/components/use-working-document.js +432 -527
  31. package/dist/components/use-working-document.js.map +1 -1
  32. package/dist/index.js +11 -11
  33. package/dist/index.js.map +1 -1
  34. package/dist/lib/arg-value.js +132 -139
  35. package/dist/lib/arg-value.js.map +1 -1
  36. package/dist/lib/arguments.js +54 -55
  37. package/dist/lib/arguments.js.map +1 -1
  38. package/dist/lib/ast-path.js +266 -291
  39. package/dist/lib/ast-path.js.map +1 -1
  40. package/dist/lib/field-list-view.js +33 -43
  41. package/dist/lib/field-list-view.js.map +1 -1
  42. package/dist/lib/field-selection.js +63 -67
  43. package/dist/lib/field-selection.js.map +1 -1
  44. package/dist/lib/fragments.js +166 -152
  45. package/dist/lib/fragments.js.map +1 -1
  46. package/dist/lib/inline-fragments.js +64 -62
  47. package/dist/lib/inline-fragments.js.map +1 -1
  48. package/dist/lib/schema-walk.js +141 -158
  49. package/dist/lib/schema-walk.js.map +1 -1
  50. package/dist/lib/variables.js +96 -90
  51. package/dist/lib/variables.js.map +1 -1
  52. package/dist/style.css +4 -22
  53. package/package.json +21 -18
@@ -1 +1 @@
1
- {"version":3,"file":"type-condition-selector.js","sources":["../../src/components/type-condition-selector.tsx"],"sourcesContent":["import { ChevronDownIcon } from '@graphiql/react';\nimport {\n isInterfaceType,\n isUnionType,\n type GraphQLAbstractType,\n type GraphQLInterfaceType,\n type GraphQLObjectType,\n type GraphQLSchema,\n} from 'graphql';\nimport { type FC, useEffect, useState } from 'react';\nimport {\n inlineFragmentSegment,\n isInlineFragmentPresent,\n segmentsEqual,\n} from '../lib/document-mutator';\nimport { type PathSegment } from '../lib/ast-path';\nimport { useFieldTreeContext } from './field-tree-context';\nimport { FieldTreeList } from './field-tree';\nimport { useCursorReveal } from './use-cursor-reveal';\n\n/**\n * The type conditions worth offering for an abstract field: every concrete\n * object type, plus (for interface fields) the other interfaces that share an\n * implementor, so you can narrow to a sibling/sub-interface (`... on Node`).\n * The field's own interface and the interfaces it already implements are\n * skipped, since those fields are selectable directly. A union contributes just\n * its member object types.\n */\nexport function applicableTypeConditions(\n abstractType: GraphQLAbstractType,\n schema: GraphQLSchema,\n): (GraphQLObjectType | GraphQLInterfaceType)[] {\n const objects = schema.getPossibleTypes(abstractType);\n if (!isInterfaceType(abstractType)) {\n return [...objects];\n }\n\n const skip = new Set<string>([\n abstractType.name,\n ...abstractType.getInterfaces().map(i => i.name),\n ]);\n const interfaces = new Map<string, GraphQLInterfaceType>();\n for (const object of objects) {\n for (const iface of object.getInterfaces()) {\n if (!skip.has(iface.name)) {\n interfaces.set(iface.name, iface);\n }\n }\n }\n return [...objects, ...interfaces.values()];\n}\n\n// ---------------------------------------------------------------------------\n// TypeConditionSelector\n// ---------------------------------------------------------------------------\n\ntype TypeConditionSelectorProps = {\n fieldPath: PathSegment[];\n abstractType: GraphQLAbstractType;\n};\n\nexport const TypeConditionSelector: FC<TypeConditionSelectorProps> = ({\n fieldPath,\n abstractType,\n}) => {\n const { doc, schema, target, cursorPath } = useFieldTreeContext();\n // Whether the document currently has a type condition selected under this\n // field. Recomputed each render so a fragment added after mount can open the\n // section (see the effect below).\n const hasSelectedCondition = (\n schema ? applicableTypeConditions(abstractType, schema) : []\n ).some(t => isInlineFragmentPresent(doc, fieldPath, t.name, target));\n const [expanded, setExpanded] = useState(hasSelectedCondition);\n\n // Open the section when a type condition becomes selected in the document.\n // Only opens, never force-closes, so the user can still collapse it manually.\n useEffect(() => {\n if (hasSelectedCondition) {\n setExpanded(true);\n }\n }, [hasSelectedCondition]);\n\n // Open the section when the editor cursor sits inside one of its type\n // conditions, so the reveal can cascade down to a field nested in a\n // `... on TypeName`. (A condition contributes an inlineFragment path segment\n // right after this field's path; a directly-selectable interface field does\n // not, so it won't force the section open.)\n const cursorInCondition =\n cursorPath !== undefined &&\n cursorPath.length > fieldPath.length &&\n fieldPath.every((seg, i) => segmentsEqual(cursorPath[i]!, seg)) &&\n cursorPath[fieldPath.length]?.kind === 'inlineFragment';\n useEffect(() => {\n if (cursorInCondition) {\n setExpanded(true);\n }\n }, [cursorPath, cursorInCondition]);\n\n if (!schema) {\n return null;\n }\n\n const typeConditions = applicableTypeConditions(abstractType, schema);\n\n if (typeConditions.length === 0) {\n return null;\n }\n\n const entries = (\n <div\n className=\"graphiql-qb-type-condition\"\n role=\"group\"\n aria-label={`Possible types for ${abstractType.name}`}\n >\n {typeConditions.map(conditionType => {\n const isSelected = isInlineFragmentPresent(\n doc,\n fieldPath,\n conditionType.name,\n target,\n );\n\n return (\n <TypeConditionEntry\n key={conditionType.name}\n fieldPath={fieldPath}\n typeName={conditionType.name}\n concreteType={conditionType}\n isInterface={isInterfaceType(conditionType)}\n isSelected={isSelected}\n />\n );\n })}\n </div>\n );\n\n // A union has no fields of its own, so its type conditions are the only\n // content under the field; render them directly rather than behind a\n // collapse. Interfaces fold them into a labeled, collapsible section.\n if (isUnionType(abstractType)) {\n return entries;\n }\n\n return (\n <div className=\"graphiql-qb-possible-types\">\n <button\n type=\"button\"\n className=\"graphiql-qb-field-toggle graphiql-qb-possible-types-header\"\n style={{\n paddingLeft: `calc(${fieldPath.length * 12}px + var(--px-8))`,\n }}\n onClick={() => setExpanded(prev => !prev)}\n aria-expanded={expanded}\n >\n <span\n className={\n expanded\n ? 'graphiql-qb-chevron-expanded'\n : 'graphiql-qb-chevron-collapsed'\n }\n >\n <ChevronDownIcon />\n </span>\n <span className=\"graphiql-qb-possible-types-label\">Possible types</span>\n <span className=\"graphiql-qb-possible-types-count\">\n {typeConditions.length}\n </span>\n </button>\n {expanded && entries}\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// TypeConditionEntry\n// ---------------------------------------------------------------------------\n\ntype TypeConditionEntryProps = {\n fieldPath: PathSegment[];\n typeName: string;\n concreteType: GraphQLObjectType | GraphQLInterfaceType;\n /** Whether this type condition is an interface (matches several types). */\n isInterface: boolean;\n isSelected: boolean;\n};\n\nconst TypeConditionEntry: FC<TypeConditionEntryProps> = ({\n fieldPath,\n typeName,\n concreteType,\n isInterface,\n isSelected,\n}) => {\n const { cursorPath, onAddInlineFragment, onRemoveInlineFragment } =\n useFieldTreeContext();\n const [expanded, setExpanded] = useState(false);\n const fragmentPath = [...fieldPath, inlineFragmentSegment(typeName)];\n const { flash, current, nodeRef } = useCursorReveal(\n fragmentPath,\n cursorPath,\n setExpanded,\n );\n\n function handleToggle() {\n if (isSelected) {\n onRemoveInlineFragment?.(fieldPath, typeName);\n } else {\n onAddInlineFragment?.(fieldPath, typeName);\n }\n }\n\n return (\n <div\n className={`graphiql-qb-inline-fragment${\n flash ? ' graphiql-qb-flash' : ''\n }${current ? ' graphiql-qb-current' : ''}`}\n ref={nodeRef}\n >\n <div\n className=\"graphiql-qb-inline-fragment-header\"\n style={{\n paddingLeft: `calc(${fieldPath.length * 12}px + var(--px-8))`,\n }}\n >\n <input\n type=\"checkbox\"\n checked={isSelected}\n onChange={handleToggle}\n aria-label={`Toggle ... on ${typeName}`}\n className=\"graphiql-qb-field-checkbox\"\n />\n <button\n type=\"button\"\n className=\"graphiql-qb-field-toggle\"\n onClick={() => setExpanded(prev => !prev)}\n aria-expanded={expanded}\n aria-label={`${expanded ? 'Collapse' : 'Expand'} ... on ${typeName}`}\n >\n <span\n className={\n expanded\n ? 'graphiql-qb-chevron-expanded'\n : 'graphiql-qb-chevron-collapsed'\n }\n >\n <ChevronDownIcon />\n </span>\n <span className=\"graphiql-qb-inline-fragment-label\">\n <span className=\"graphiql-qb-spread\">...</span>\n {' on '}\n <span className=\"graphiql-qb-type-name\">{typeName}</span>\n {isInterface && (\n <span className=\"graphiql-qb-type-kind-tag\">interface</span>\n )}\n </span>\n </button>\n </div>\n {expanded && (\n <>\n <FieldTreeList type={concreteType} path={fragmentPath} />\n {/* When the condition is itself an interface, keep recursing: offer\n its own possible types so you can narrow further (`... on Node`\n then `... on Concrete`). */}\n {isInterface && (\n <TypeConditionSelector\n fieldPath={fragmentPath}\n abstractType={concreteType as GraphQLAbstractType}\n />\n )}\n </>\n )}\n </div>\n );\n};\n"],"names":["applicableTypeConditions","abstractType","schema","objects","getPossibleTypes","isInterfaceType","skip","Set","name","getInterfaces","map","i","interfaces","Map","object","iface","has","set","values","TypeConditionSelector","t0","$","_c","fieldPath","doc","target","cursorPath","useFieldTreeContext","t1","t2","t","isInlineFragmentPresent","some","hasSelectedCondition","expanded","setExpanded","useState","t3","useEffect","t4","undefined","length","every","seg","segmentsEqual","kind","cursorInCondition","t5","t6","t10","t11","t7","t8","t9","typeConditions","Symbol","for","bb0","t12","conditionType","isSelected","entries","isUnionType","t13","t14","paddingLeft","t15","_temp","t16","t17","t18","t19","t20","t21","t22","t23","TypeConditionEntry","typeName","concreteType","isInterface","onAddInlineFragment","onRemoveInlineFragment","inlineFragmentSegment","fragmentPath","flash","current","nodeRef","useCursorReveal","handleToggle","_temp2","prev"],"mappings":";;;;;;;;;;AA4BgBA,SAAAA,yBACdC,cACAC,QAC8C;AACxCC,QAAAA,UAAUD,OAAOE,iBAAiBH,YAAY;AAChD,MAAA,CAACI,gBAAgBJ,YAAY,GAAG;AAC3B,WAAA,CAAC,GAAGE,OAAO;AAAA,EAAA;AAGpB,QAAMG,OAAO,oBAAIC,IAAY,CAC3BN,aAAaO,MACb,GAAGP,aAAaQ,gBAAgBC,IAAIC,CAAAA,MAAKA,EAAEH,IAAI,CAAC,CACjD;AACKI,QAAAA,iCAAiBC,IAAkC;AACzD,aAAWC,UAAUX,SAAS;AACjBY,eAAAA,SAASD,OAAOL,iBAAiB;AAC1C,UAAI,CAACH,KAAKU,IAAID,MAAMP,IAAI,GAAG;AACdS,mBAAAA,IAAIF,MAAMP,MAAMO,KAAK;AAAA,MAAA;AAAA,IAClC;AAAA,EACF;AAEF,SAAO,CAAC,GAAGZ,SAAS,GAAGS,WAAWM,QAAQ;AAC5C;AAWO,MAAMC,wBAAwDC,CAAA,OAAA;;AAAAC,QAAAA,IAAAC,EAAA,EAAA;AAAC,QAAA;AAAA,IAAAC;AAAAA,IAAAtB;AAAAA,EAAAA,IAAAmB;AAIpE,QAAA;AAAA,IAAAI;AAAAA,IAAAtB;AAAAA,IAAAuB;AAAAA,IAAAC;AAAAA,MAA4CC,oBAAoB;AAAEC,MAAAA;AAAA,MAAAP,EAAApB,CAAAA,MAAAA,gBAAAoB,EAAA,CAAA,MAAAG,OAAAH,EAAAE,CAAAA,MAAAA,aAAA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AAmCQ,SAAAD,OAAAC,MAAA;AAAA,SAAA,CAgDVA;AAAI;"}
1
+ {"version":3,"file":"type-condition-selector.js","names":["ChevronDownIcon","isInterfaceType","isUnionType","GraphQLAbstractType","GraphQLInterfaceType","GraphQLObjectType","GraphQLSchema","FC","useEffect","useState","inlineFragmentSegment","isInlineFragmentPresent","segmentsEqual","PathSegment","useFieldTreeContext","FieldTreeList","useCursorReveal","applicableTypeConditions","abstractType","schema","objects","getPossibleTypes","skip","Set","name","getInterfaces","map","i","interfaces","Map","object","iface","has","set","values","TypeConditionSelectorProps","fieldPath","TypeConditionSelector","t0","$","_c","doc","target","cursorPath","t1","t2","t","some","hasSelectedCondition","expanded","setExpanded","t3","t4","undefined","length","every","seg","kind","cursorInCondition","t5","t6","t10","t11","t7","t8","t9","typeConditions","Symbol","for","bb0","t12","conditionType","isSelected","entries","t13","t14","paddingLeft","t15","_temp","t16","t17","t18","t19","t20","t21","t22","t23","TypeConditionEntryProps","typeName","concreteType","isInterface","TypeConditionEntry","onAddInlineFragment","onRemoveInlineFragment","fragmentPath","flash","current","nodeRef","handleToggle","_temp2","prev"],"sources":["../../src/components/type-condition-selector.tsx"],"sourcesContent":["import { ChevronDownIcon } from '@graphiql/react';\nimport {\n isInterfaceType,\n isUnionType,\n type GraphQLAbstractType,\n type GraphQLInterfaceType,\n type GraphQLObjectType,\n type GraphQLSchema,\n} from 'graphql';\nimport { type FC, useEffect, useState } from 'react';\nimport {\n inlineFragmentSegment,\n isInlineFragmentPresent,\n segmentsEqual,\n} from '../lib/document-mutator';\nimport { type PathSegment } from '../lib/ast-path';\nimport { useFieldTreeContext } from './field-tree-context';\nimport { FieldTreeList } from './field-tree';\nimport { useCursorReveal } from './use-cursor-reveal';\n\n/**\n * The type conditions worth offering for an abstract field: every concrete\n * object type, plus (for interface fields) the other interfaces that share an\n * implementor, so you can narrow to a sibling/sub-interface (`... on Node`).\n * The field's own interface and the interfaces it already implements are\n * skipped, since those fields are selectable directly. A union contributes just\n * its member object types.\n */\nexport function applicableTypeConditions(\n abstractType: GraphQLAbstractType,\n schema: GraphQLSchema,\n): (GraphQLObjectType | GraphQLInterfaceType)[] {\n const objects = schema.getPossibleTypes(abstractType);\n if (!isInterfaceType(abstractType)) {\n return [...objects];\n }\n\n const skip = new Set<string>([\n abstractType.name,\n ...abstractType.getInterfaces().map(i => i.name),\n ]);\n const interfaces = new Map<string, GraphQLInterfaceType>();\n for (const object of objects) {\n for (const iface of object.getInterfaces()) {\n if (!skip.has(iface.name)) {\n interfaces.set(iface.name, iface);\n }\n }\n }\n return [...objects, ...interfaces.values()];\n}\n\n// ---------------------------------------------------------------------------\n// TypeConditionSelector\n// ---------------------------------------------------------------------------\n\ntype TypeConditionSelectorProps = {\n fieldPath: PathSegment[];\n abstractType: GraphQLAbstractType;\n};\n\nexport const TypeConditionSelector: FC<TypeConditionSelectorProps> = ({\n fieldPath,\n abstractType,\n}) => {\n const { doc, schema, target, cursorPath } = useFieldTreeContext();\n // Whether the document currently has a type condition selected under this\n // field. Recomputed each render so a fragment added after mount can open the\n // section (see the effect below).\n const hasSelectedCondition = (\n schema ? applicableTypeConditions(abstractType, schema) : []\n ).some(t => isInlineFragmentPresent(doc, fieldPath, t.name, target));\n const [expanded, setExpanded] = useState(hasSelectedCondition);\n\n // Open the section when a type condition becomes selected in the document.\n // Only opens, never force-closes, so the user can still collapse it manually.\n useEffect(() => {\n if (hasSelectedCondition) {\n setExpanded(true);\n }\n }, [hasSelectedCondition]);\n\n // Open the section when the editor cursor sits inside one of its type\n // conditions, so the reveal can cascade down to a field nested in a\n // `... on TypeName`. (A condition contributes an inlineFragment path segment\n // right after this field's path; a directly-selectable interface field does\n // not, so it won't force the section open.)\n const cursorInCondition =\n cursorPath !== undefined &&\n cursorPath.length > fieldPath.length &&\n fieldPath.every((seg, i) => segmentsEqual(cursorPath[i]!, seg)) &&\n cursorPath[fieldPath.length]?.kind === 'inlineFragment';\n useEffect(() => {\n if (cursorInCondition) {\n setExpanded(true);\n }\n }, [cursorPath, cursorInCondition]);\n\n if (!schema) {\n return null;\n }\n\n const typeConditions = applicableTypeConditions(abstractType, schema);\n\n if (typeConditions.length === 0) {\n return null;\n }\n\n const entries = (\n <div\n className=\"graphiql-qb-type-condition\"\n role=\"group\"\n aria-label={`Possible types for ${abstractType.name}`}\n >\n {typeConditions.map(conditionType => {\n const isSelected = isInlineFragmentPresent(\n doc,\n fieldPath,\n conditionType.name,\n target,\n );\n\n return (\n <TypeConditionEntry\n key={conditionType.name}\n fieldPath={fieldPath}\n typeName={conditionType.name}\n concreteType={conditionType}\n isInterface={isInterfaceType(conditionType)}\n isSelected={isSelected}\n />\n );\n })}\n </div>\n );\n\n // A union has no fields of its own, so its type conditions are the only\n // content under the field; render them directly rather than behind a\n // collapse. Interfaces fold them into a labeled, collapsible section.\n if (isUnionType(abstractType)) {\n return entries;\n }\n\n return (\n <div className=\"graphiql-qb-possible-types\">\n <button\n type=\"button\"\n className=\"graphiql-qb-field-toggle graphiql-qb-possible-types-header\"\n style={{\n paddingLeft: `calc(${fieldPath.length * 12}px + var(--px-8))`,\n }}\n onClick={() => setExpanded(prev => !prev)}\n aria-expanded={expanded}\n >\n <span\n className={\n expanded\n ? 'graphiql-qb-chevron-expanded'\n : 'graphiql-qb-chevron-collapsed'\n }\n >\n <ChevronDownIcon />\n </span>\n <span className=\"graphiql-qb-possible-types-label\">Possible types</span>\n <span className=\"graphiql-qb-possible-types-count\">\n {typeConditions.length}\n </span>\n </button>\n {expanded && entries}\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// TypeConditionEntry\n// ---------------------------------------------------------------------------\n\ntype TypeConditionEntryProps = {\n fieldPath: PathSegment[];\n typeName: string;\n concreteType: GraphQLObjectType | GraphQLInterfaceType;\n /** Whether this type condition is an interface (matches several types). */\n isInterface: boolean;\n isSelected: boolean;\n};\n\nconst TypeConditionEntry: FC<TypeConditionEntryProps> = ({\n fieldPath,\n typeName,\n concreteType,\n isInterface,\n isSelected,\n}) => {\n const { cursorPath, onAddInlineFragment, onRemoveInlineFragment } =\n useFieldTreeContext();\n const [expanded, setExpanded] = useState(false);\n const fragmentPath = [...fieldPath, inlineFragmentSegment(typeName)];\n const { flash, current, nodeRef } = useCursorReveal(\n fragmentPath,\n cursorPath,\n setExpanded,\n );\n\n function handleToggle() {\n if (isSelected) {\n onRemoveInlineFragment?.(fieldPath, typeName);\n } else {\n onAddInlineFragment?.(fieldPath, typeName);\n }\n }\n\n return (\n <div\n className={`graphiql-qb-inline-fragment${\n flash ? ' graphiql-qb-flash' : ''\n }${current ? ' graphiql-qb-current' : ''}`}\n ref={nodeRef}\n >\n <div\n className=\"graphiql-qb-inline-fragment-header\"\n style={{\n paddingLeft: `calc(${fieldPath.length * 12}px + var(--px-8))`,\n }}\n >\n <input\n type=\"checkbox\"\n checked={isSelected}\n onChange={handleToggle}\n aria-label={`Toggle ... on ${typeName}`}\n className=\"graphiql-qb-field-checkbox\"\n />\n <button\n type=\"button\"\n className=\"graphiql-qb-field-toggle\"\n onClick={() => setExpanded(prev => !prev)}\n aria-expanded={expanded}\n aria-label={`${expanded ? 'Collapse' : 'Expand'} ... on ${typeName}`}\n >\n <span\n className={\n expanded\n ? 'graphiql-qb-chevron-expanded'\n : 'graphiql-qb-chevron-collapsed'\n }\n >\n <ChevronDownIcon />\n </span>\n <span className=\"graphiql-qb-inline-fragment-label\">\n <span className=\"graphiql-qb-spread\">...</span>\n {' on '}\n <span className=\"graphiql-qb-type-name\">{typeName}</span>\n {isInterface && (\n <span className=\"graphiql-qb-type-kind-tag\">interface</span>\n )}\n </span>\n </button>\n </div>\n {expanded && (\n <>\n <FieldTreeList type={concreteType} path={fragmentPath} />\n {/* When the condition is itself an interface, keep recursing: offer\n its own possible types so you can narrow further (`... on Node`\n then `... on Concrete`). */}\n {isInterface && (\n <TypeConditionSelector\n fieldPath={fragmentPath}\n abstractType={concreteType as GraphQLAbstractType}\n />\n )}\n </>\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;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zB,EAAA,MAAA2C;CAAA,OAAAA,MAAA3C,EAAA;CAAA,IAAA4C;CAAA,IAAA5C,EAAA,QAAAkD,gBAAAlD,EAAA,QAAAU,YAAAV,EAAA,QAAAuD,gBAAAvD,EAAA,QAAAmD,aAAA;EACLP,MAAAlC,YAAQ,qBAAA,UAAA,EAAA,UAAA,CAEL,oBAAC,eAAD;GAAqBwC,MAAAA;GAAoBK,MAAAA;EAAY,CAAA,GAIpDJ,eACC,oBAAC,uBAAD;GACaI,WAAAA;GACG,cAAAL;EAAmC,CAAA,CAEpD,EAAA,CAAA;EAEJlD,EAAA,MAAAkD;EAAAlD,EAAA,MAAAU;EAAAV,EAAA,MAAAuD;EAAAvD,EAAA,MAAAmD;EAAAnD,EAAA,MAAA4C;CAAA,OAAAA,MAAA5C,EAAA;CAAA,IAAA6C;CAAA,IAAA7C,EAAA,QAAA0D,WAAA1D,EAAA,QAAA2C,OAAA3C,EAAA,QAAA4C,OAAA5C,EAAA,QAAAa,IAAA;EA1DHgC,MAAA,qBAAA,OAAA;GACa,WAAAhC;GAGN6C,KAAAA;GAJP,UAAA,CAMEf,KAuCCC,GAcG;;EAAA5C,EAAA,MAAA0D;EAAA1D,EAAA,MAAA2C;EAAA3C,EAAA,MAAA4C;EAAA5C,EAAA,MAAAa;EAAAb,EAAA,MAAA6C;CAAA,OAAAA,MAAA7C,EAAA;CAAA,OA3DN6C;AA2DM;AAlN2D,SAAAN,MAAAsB,MAAA;CAAA,OAAA,CA0FzBA;AAAI;AAmCQ,SAAAD,OAAAC,MAAA;CAAA,OAAA,CAgDVA;AAAI"}
@@ -1,79 +1,78 @@
1
- import { c } from "react-compiler-runtime";
1
+ import { cursorContextAtOffset } from "../lib/schema-walk.js";
2
2
  import { useGraphiQL, useMonaco } from "@graphiql/react";
3
+ import { c } from "react-compiler-runtime";
3
4
  import { parse } from "graphql";
4
- import { useState, useEffect } from "react";
5
- import { cursorContextAtOffset } from "../lib/schema-walk.js";
6
- const EMPTY_CONTEXT = {
7
- target: void 0,
8
- path: []
5
+ import { useEffect, useState } from "react";
6
+ //#region src/components/use-cursor-path.ts
7
+ var EMPTY_CONTEXT = {
8
+ target: void 0,
9
+ path: []
9
10
  };
11
+ /**
12
+ * Tracks the definition (operation or fragment) and field path under the editor
13
+ * cursor. The builder follows this: the cursor's definition is the one being
14
+ * edited, and the path expands the tree down to the cursor. Subscribes to the
15
+ * query editor directly (debounced to avoid thrashing while typing), reacting
16
+ * only to explicit user cursor moves — not the cursor resets our own writes
17
+ * cause.
18
+ */
10
19
  function useCursorContext() {
11
- const $ = c(6);
12
- const queryEditor = useGraphiQL(_temp);
13
- const monaco = useMonaco(_temp2);
14
- const [context, setContext] = useState(EMPTY_CONTEXT);
15
- let t0;
16
- if ($[0] !== (monaco == null ? void 0 : monaco.editor) || $[1] !== queryEditor) {
17
- t0 = () => {
18
- if (!queryEditor) {
19
- return;
20
- }
21
- let timer;
22
- const recompute = () => {
23
- const model = queryEditor.getModel();
24
- const pos = queryEditor.getPosition();
25
- if (!model || !pos) {
26
- return;
27
- }
28
- const offset = model.getOffsetAt(pos);
29
- let resolved;
30
- try {
31
- resolved = cursorContextAtOffset(parse(model.getValue()), offset);
32
- } catch {
33
- return;
34
- }
35
- setContext(resolved ?? EMPTY_CONTEXT);
36
- };
37
- const schedule = () => {
38
- clearTimeout(timer);
39
- timer = setTimeout(recompute, 80);
40
- };
41
- const disposable = queryEditor.onDidChangeCursorPosition((e) => {
42
- if (e.reason === (monaco == null ? void 0 : monaco.editor.CursorChangeReason.Explicit)) {
43
- schedule();
44
- }
45
- });
46
- recompute();
47
- return () => {
48
- clearTimeout(timer);
49
- disposable.dispose();
50
- };
51
- };
52
- $[0] = monaco == null ? void 0 : monaco.editor;
53
- $[1] = queryEditor;
54
- $[2] = t0;
55
- } else {
56
- t0 = $[2];
57
- }
58
- let t1;
59
- if ($[3] !== monaco || $[4] !== queryEditor) {
60
- t1 = [queryEditor, monaco];
61
- $[3] = monaco;
62
- $[4] = queryEditor;
63
- $[5] = t1;
64
- } else {
65
- t1 = $[5];
66
- }
67
- useEffect(t0, t1);
68
- return context;
20
+ const $ = c(6);
21
+ const queryEditor = useGraphiQL(_temp);
22
+ const monaco = useMonaco(_temp2);
23
+ const [context, setContext] = useState(EMPTY_CONTEXT);
24
+ let t0;
25
+ if ($[0] !== monaco?.editor || $[1] !== queryEditor) {
26
+ t0 = () => {
27
+ if (!queryEditor) return;
28
+ let timer;
29
+ const recompute = () => {
30
+ const model = queryEditor.getModel();
31
+ const pos = queryEditor.getPosition();
32
+ if (!model || !pos) return;
33
+ const offset = model.getOffsetAt(pos);
34
+ let resolved;
35
+ try {
36
+ resolved = cursorContextAtOffset(parse(model.getValue()), offset);
37
+ } catch {
38
+ return;
39
+ }
40
+ setContext(resolved ?? EMPTY_CONTEXT);
41
+ };
42
+ const schedule = () => {
43
+ clearTimeout(timer);
44
+ timer = setTimeout(recompute, 80);
45
+ };
46
+ const disposable = queryEditor.onDidChangeCursorPosition((e) => {
47
+ if (e.reason === monaco?.editor.CursorChangeReason.Explicit) schedule();
48
+ });
49
+ recompute();
50
+ return () => {
51
+ clearTimeout(timer);
52
+ disposable.dispose();
53
+ };
54
+ };
55
+ $[0] = monaco?.editor;
56
+ $[1] = queryEditor;
57
+ $[2] = t0;
58
+ } else t0 = $[2];
59
+ let t1;
60
+ if ($[3] !== monaco || $[4] !== queryEditor) {
61
+ t1 = [queryEditor, monaco];
62
+ $[3] = monaco;
63
+ $[4] = queryEditor;
64
+ $[5] = t1;
65
+ } else t1 = $[5];
66
+ useEffect(t0, t1);
67
+ return context;
69
68
  }
70
69
  function _temp2(state_0) {
71
- return state_0.monaco;
70
+ return state_0.monaco;
72
71
  }
73
72
  function _temp(state) {
74
- return state.queryEditor;
73
+ return state.queryEditor;
75
74
  }
76
- export {
77
- useCursorContext
78
- };
79
- //# sourceMappingURL=use-cursor-path.js.map
75
+ //#endregion
76
+ export { useCursorContext };
77
+
78
+ //# sourceMappingURL=use-cursor-path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-cursor-path.js","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 * only to explicit user cursor moves — not the cursor resets our own writes\n * cause.\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 disposable = 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 recompute();\n return () => {\n clearTimeout(timer);\n disposable.dispose();\n };\n }, [queryEditor, monaco]);\n\n return context;\n}\n"],"names":["EMPTY_CONTEXT","target","undefined","path","useCursorContext","$","_c","queryEditor","useGraphiQL","_temp","monaco","useMonaco","_temp2","context","setContext","useState","t0","editor","timer","recompute","model","getModel","pos","getPosition","offset","getOffsetAt","resolved","getValue","schedule","clearTimeout","disposable","onDidChangeCursorPosition","e","reason","CursorChangeReason","Explicit","dispose","t1","useEffect","state_0","state"],"mappings":";;;;;AAaA,MAAMA,gBAA+B;AAAA,EAAEC,QAAQC;AAAAA,EAAWC,MAAM,CAAA;AAAG;AAU5D,SAAAC,mBAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA;AACLC,QAAAA,cAAoBC,YAAAC,KAAsC;AAC1DC,QAAAA,SAAeC,UAAAC,MAA+B;AAE9C,QAAA,CAAAC,SAAAC,UAAA,IAA8BC,SAAAf,aAAqC;AAAEgB,MAAAA;AAAAX,MAAAA,UAAAK,iCAAAO,WAAAZ,SAAAE,aAAA;AAC3DS,SAAAA,MAAA;AAAA,UAAA,CACHT,aAAW;AAAA;AAAA,MAAA;AAGZW,UAAAA;AACJ,YAAAC,YAAAA,MAAA;AACEC,cAAAA,QAAcb,YAAWc,SAAU;AACnCC,cAAAA,MAAYf,YAAWgB,YAAa;AAChC,YAAA,CAACH,SAAK,CAAKE,KAAG;AAAA;AAAA,QAAA;AAGlBE,cAAAA,SAAeJ,MAAKK,YAAaH,GAAG;AAChCI,YAAAA;AAES,YAAA;AAEXA,qBAAWA,sBAAsBA,MAAMN,MAAKO,SAAU,CAAC,GAAGH,MAAM;AAAA,QAAA,QAAxD;AAAA;AAAA,QAAA;AAKVV,mBAAWY,YAAQ1B,aAAiB;AAAA,MAAC;AAEvC,YAAA4B,WAAAA,MAAA;AACEC,qBAAaX,KAAK;AACVA,gBAAAA,WAAWC,aAAa;AAAA,MAA3B;AAEPW,YAAAA,aAAmBvB,YAAWwB,0BAAAC,CAAA,MAAA;AAAA,YAExBA,EAACC,YAAYvB,iCAAMO,OAAAiB,mBAAAC,WAAoC;AAChD,mBAAA;AAAA,QAAA;AAAA,MAAC,CAEb;AACS,gBAAA;AAAC,aAAA,MAAA;AAETN,qBAAaX,KAAK;AAClBY,mBAAUM,QAAS;AAAA,MAAC;AAAA,IAAA;AAEvB,MAAA,CAAA,IAAA1B,iCAAAO;AAAAZ,WAAAE;AAAAF,WAAAW;AAAAA,EAAAA,OAAA;AAAAA,SAAAX,EAAA,CAAA;AAAA,EAAA;AAAAgC,MAAAA;AAAA,MAAAhC,EAAAK,CAAAA,MAAAA,UAAAL,SAAAE,aAAA;AAAE,SAAA,CAACA,aAAaG,MAAM;AAACL,WAAAK;AAAAL,WAAAE;AAAAF,WAAAgC;AAAAA,EAAAA,OAAA;AAAAA,SAAAhC,EAAA,CAAA;AAAA,EAAA;AAtCxBiC,YAAUtB,IAsCPqB,EAAqB;AAEjBxB,SAAAA;AAAO;AA7CT,SAAAD,OAAA2B,SAAA;AAAA,SAE6BC,QAAK9B;AAAA;AAFlC,SAAAD,MAAA+B,OAAA;AAAA,SACoCA,MAAKjC;AAAA;"}
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","disposable","onDidChangeCursorPosition","e","reason","CursorChangeReason","Explicit","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 * only to explicit user cursor moves — not the cursor resets our own writes\n * cause.\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 disposable = 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 recompute();\n return () => {\n clearTimeout(timer);\n disposable.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,YAAAiB,KAAsC;CAC1D,MAAAC,SAAejB,UAAAkB,MAA+B;CAE9C,MAAA,CAAAC,SAAAC,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,86 @@
1
- import { c } from "react-compiler-runtime";
2
- import { useRef, useState, useEffect } from "react";
3
1
  import { segmentsEqual } from "../lib/ast-path.js";
2
+ import { c } from "react-compiler-runtime";
3
+ import { useEffect, useRef, useState } from "react";
4
+ //#region src/components/use-cursor-reveal.ts
5
+ /**
6
+ * Reveals a tree node as the editor cursor moves onto it or a descendant:
7
+ * auto-expands it when it's an ancestor of the cursor's field, and (only when
8
+ * the cursor lands exactly on it) flashes it, scrolls it into view, and marks it
9
+ * as the current node so the row can show a persistent highlight. Ancestors
10
+ * expand but neither flash nor highlight, to keep the "you are here" signal on
11
+ * the one field the cursor sits in. Shared by field rows and inline-fragment
12
+ * rows so both react to the cursor.
13
+ */
4
14
  function useCursorReveal(fullPath, cursorPath, setExpanded) {
5
- const $ = c(18);
6
- let t0;
7
- if ($[0] !== cursorPath || $[1] !== fullPath) {
8
- t0 = cursorPath !== void 0 && cursorPath.length >= fullPath.length && fullPath.every((seg, i) => segmentsEqual(cursorPath[i], seg));
9
- $[0] = cursorPath;
10
- $[1] = fullPath;
11
- $[2] = t0;
12
- } else {
13
- t0 = $[2];
14
- }
15
- const onCursorPath = t0;
16
- const isAncestor = onCursorPath && cursorPath.length > fullPath.length;
17
- const isTarget = onCursorPath && cursorPath.length === fullPath.length;
18
- const nodeRef = useRef(null);
19
- const [flash, setFlash] = useState(false);
20
- let t1;
21
- if ($[3] !== isAncestor || $[4] !== setExpanded) {
22
- t1 = () => {
23
- if (isAncestor) {
24
- setExpanded(true);
25
- }
26
- };
27
- $[3] = isAncestor;
28
- $[4] = setExpanded;
29
- $[5] = t1;
30
- } else {
31
- t1 = $[5];
32
- }
33
- let t2;
34
- if ($[6] !== cursorPath || $[7] !== isAncestor || $[8] !== setExpanded) {
35
- t2 = [cursorPath, isAncestor, setExpanded];
36
- $[6] = cursorPath;
37
- $[7] = isAncestor;
38
- $[8] = setExpanded;
39
- $[9] = t2;
40
- } else {
41
- t2 = $[9];
42
- }
43
- useEffect(t1, t2);
44
- let t3;
45
- if ($[10] !== isTarget) {
46
- t3 = () => {
47
- var _a;
48
- if (!isTarget) {
49
- return;
50
- }
51
- setFlash(true);
52
- const row = ((_a = nodeRef.current) == null ? void 0 : _a.firstElementChild) ?? nodeRef.current;
53
- row == null ? void 0 : row.scrollIntoView({
54
- block: "center"
55
- });
56
- const timer = setTimeout(() => setFlash(false), 700);
57
- return () => clearTimeout(timer);
58
- };
59
- $[10] = isTarget;
60
- $[11] = t3;
61
- } else {
62
- t3 = $[11];
63
- }
64
- let t4;
65
- if ($[12] !== cursorPath || $[13] !== isTarget) {
66
- t4 = [cursorPath, isTarget];
67
- $[12] = cursorPath;
68
- $[13] = isTarget;
69
- $[14] = t4;
70
- } else {
71
- t4 = $[14];
72
- }
73
- useEffect(t3, t4);
74
- let t5;
75
- if ($[15] !== flash || $[16] !== isTarget) {
76
- t5 = {
77
- flash,
78
- current: isTarget,
79
- nodeRef
80
- };
81
- $[15] = flash;
82
- $[16] = isTarget;
83
- $[17] = t5;
84
- } else {
85
- t5 = $[17];
86
- }
87
- return t5;
15
+ const $ = c(18);
16
+ let t0;
17
+ if ($[0] !== cursorPath || $[1] !== fullPath) {
18
+ t0 = cursorPath !== void 0 && cursorPath.length >= fullPath.length && fullPath.every((seg, i) => segmentsEqual(cursorPath[i], seg));
19
+ $[0] = cursorPath;
20
+ $[1] = fullPath;
21
+ $[2] = t0;
22
+ } else t0 = $[2];
23
+ const onCursorPath = t0;
24
+ const isAncestor = onCursorPath && cursorPath.length > fullPath.length;
25
+ const isTarget = onCursorPath && cursorPath.length === fullPath.length;
26
+ const nodeRef = useRef(null);
27
+ const [flash, setFlash] = useState(false);
28
+ let t1;
29
+ if ($[3] !== isAncestor || $[4] !== setExpanded) {
30
+ t1 = () => {
31
+ if (isAncestor) setExpanded(true);
32
+ };
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,
41
+ isAncestor,
42
+ setExpanded
43
+ ];
44
+ $[6] = cursorPath;
45
+ $[7] = isAncestor;
46
+ $[8] = setExpanded;
47
+ $[9] = t2;
48
+ } else t2 = $[9];
49
+ useEffect(t1, t2);
50
+ let t3;
51
+ if ($[10] !== isTarget) {
52
+ t3 = () => {
53
+ if (!isTarget) return;
54
+ setFlash(true);
55
+ (nodeRef.current?.firstElementChild ?? nodeRef.current)?.scrollIntoView({ block: "center" });
56
+ const timer = setTimeout(() => setFlash(false), 700);
57
+ return () => clearTimeout(timer);
58
+ };
59
+ $[10] = isTarget;
60
+ $[11] = t3;
61
+ } else t3 = $[11];
62
+ 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 = {
73
+ flash,
74
+ current: isTarget,
75
+ nodeRef
76
+ };
77
+ $[15] = flash;
78
+ $[16] = isTarget;
79
+ $[17] = t5;
80
+ } else t5 = $[17];
81
+ return t5;
88
82
  }
89
- export {
90
- useCursorReveal
91
- };
92
- //# sourceMappingURL=use-cursor-reveal.js.map
83
+ //#endregion
84
+ export { useCursorReveal };
85
+
86
+ //# sourceMappingURL=use-cursor-reveal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-cursor-reveal.js","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"],"names":["useCursorReveal","fullPath","cursorPath","setExpanded","$","_c","t0","undefined","length","every","seg","i","segmentsEqual","onCursorPath","isAncestor","isTarget","nodeRef","useRef","flash","setFlash","useState","t1","t2","useEffect","t3","row","current","firstElementChild","scrollIntoView","block","timer","setTimeout","clearTimeout","t4","t5"],"mappings":";;;AAYOA,SA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AAAA,MAAA;AAGbI,mBAAa;AAMb,YAAAM,QAAYT,aAAOU,YAAPV,mBAAOW,sBAA+BX,QAAOU;AACzDD,iCAAGG,eAAA;AAAA,QAAAC,OAA0B;AAAA,MAAA;AAC7B,YAAAC,QAAcC,WAAA,MAAiBZ,SAAc,KAAA,MAAM;AACtCa,aAAAA,MAAAA,aAAaF,KAAK;AAAA,IAAC;AACjC1B,YAAAW;AAAAX,YAAAoB;AAAAA,EAAAA,OAAA;AAAAA,SAAApB,EAAA,EAAA;AAAA,EAAA;AAAA6B,MAAAA;AAAA,MAAA7B,EAAAF,EAAAA,MAAAA,cAAAE,UAAAW,UAAA;AAAE,SAAA,CAACb,YAAYa,QAAQ;AAACX,YAAAF;AAAAE,YAAAW;AAAAX,YAAA6B;AAAAA,EAAAA,OAAA;AAAAA,SAAA7B,EAAA,EAAA;AAAA,EAAA;AAdzBmB,YAAUC,IAcPS,EAAsB;AAACC,MAAAA;AAAA,MAAA9B,EAAAc,EAAAA,MAAAA,SAAAd,UAAAW,UAAA;AAEnB,SAAA;AAAA,MAAAG;AAAAA,MAAAQ,SAAkBX;AAAAA,MAAQC;AAAAA,IAAA;AAAWZ,YAAAc;AAAAd,YAAAW;AAAAX,YAAA8B;AAAAA,EAAAA,OAAA;AAAAA,SAAA9B,EAAA,EAAA;AAAA,EAAA;AAArC8B,SAAAA;AAAqC;"}
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;CA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