@malloydata/malloy-explorer 0.0.295-dev250710213205 → 0.0.299-dev250804170242

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 (51) hide show
  1. package/@flowtypes/components/MalloyExplorerProvider.flow.js +1 -1
  2. package/dist/cjs/index.cjs +448 -285
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/esm/index.js +415 -252
  5. package/dist/esm/index.js.map +1 -1
  6. package/dist/types/components/FieldToken.d.ts +5 -1
  7. package/dist/types/components/MalloyExplorerProvider.d.ts +1 -1
  8. package/dist/types/components/QueryPanel/AddMenu/AddAggregate.d.ts +1 -3
  9. package/dist/types/components/QueryPanel/AddMenu/AddEmptyNest.d.ts +1 -3
  10. package/dist/types/components/QueryPanel/AddMenu/AddGroupBy.d.ts +1 -3
  11. package/dist/types/components/QueryPanel/AddMenu/AddLimit.d.ts +1 -3
  12. package/dist/types/components/QueryPanel/AddMenu/AddMenu.d.ts +1 -3
  13. package/dist/types/components/QueryPanel/AddMenu/AddOrderBy.d.ts +1 -3
  14. package/dist/types/components/QueryPanel/AddMenu/AddView.d.ts +1 -3
  15. package/dist/types/components/QueryPanel/AddMenu/AddWhere.d.ts +0 -2
  16. package/dist/types/components/QueryPanel/Operations.d.ts +2 -3
  17. package/dist/types/components/QueryPanel/Parameters.d.ts +3 -3
  18. package/dist/types/components/QueryPanel/Query.d.ts +3 -4
  19. package/dist/types/components/QueryPanel/Source.d.ts +3 -3
  20. package/dist/types/components/QueryPanel/View.d.ts +2 -3
  21. package/dist/types/components/QueryPanel/ViewDefinition.d.ts +2 -3
  22. package/dist/types/components/QueryPanel/Visualization.d.ts +1 -2
  23. package/dist/types/components/QueryPanel/VizEditor/VizEditor.d.ts +1 -2
  24. package/dist/types/components/QueryPanel/VizEditor/VizEditorDialog.d.ts +1 -2
  25. package/dist/types/components/QueryPanel/VizEditor/VizEditorPopover.d.ts +1 -2
  26. package/dist/types/components/QueryPanel/VizEditor/styles.d.ts +3 -0
  27. package/dist/types/components/QueryPanel/VizEditor/utils.d.ts +3 -0
  28. package/dist/types/components/QueryPanel/operations/AggregateOperations.d.ts +3 -4
  29. package/dist/types/components/QueryPanel/operations/DrillOperations.d.ts +1 -2
  30. package/dist/types/components/QueryPanel/operations/FilterOperations.d.ts +2 -3
  31. package/dist/types/components/QueryPanel/operations/GroupByOperations.d.ts +2 -3
  32. package/dist/types/components/QueryPanel/operations/LimitOperation.d.ts +2 -3
  33. package/dist/types/components/QueryPanel/operations/NestOperation.d.ts +3 -5
  34. package/dist/types/components/QueryPanel/operations/OperationActionTitle.d.ts +0 -2
  35. package/dist/types/components/QueryPanel/operations/OrderByOperations.d.ts +2 -3
  36. package/dist/types/components/QueryPanel/operations/RenameDialog.d.ts +3 -4
  37. package/dist/types/components/QueryPanel/operations/SortableOperations.d.ts +3 -4
  38. package/dist/types/components/SourcePanel/FieldGroupList.d.ts +3 -1
  39. package/dist/types/components/SourcePanel/FieldTokenWithActions.d.ts +3 -2
  40. package/dist/types/components/SourcePanel/SearchResultList.d.ts +3 -1
  41. package/dist/types/components/SourcePanel/hooks/useOperations.d.ts +0 -4
  42. package/dist/types/components/primitives/DropdownMenu.d.ts +1 -1
  43. package/dist/types/components/utils/axis.d.ts +10 -0
  44. package/dist/types/components/utils/icon.d.ts +3 -3
  45. package/dist/types/components/utils/segment.d.ts +1 -0
  46. package/dist/types/contexts/QueryEditorContext.d.ts +1 -10
  47. package/dist/types/hooks/useQueryBuilder.d.ts +2 -2
  48. package/dist/types/hooks/useQueryUpdate.d.ts +10 -0
  49. package/dist/types/hooks/useTopValues.d.ts +18 -0
  50. package/jest.config.ts +1 -1
  51. package/package.json +8 -8
@@ -17,7 +17,7 @@ var _a, _b, _captureMap, _compiled, _pattern, _nameMap, _strategy, __EmulatedReg
17
17
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
18
18
  const jsxRuntime = require("react/jsx-runtime");
19
19
  const React = require("react");
20
- const QB = require("@malloydata/malloy-query-builder");
20
+ const malloyQueryBuilder = require("@malloydata/malloy-query-builder");
21
21
  const malloyTag = require("@malloydata/malloy-tag");
22
22
  const render = require("@malloydata/render");
23
23
  const malloyFilter = require("@malloydata/malloy-filter");
@@ -39,7 +39,6 @@ function _interopNamespaceDefault(e) {
39
39
  return Object.freeze(n);
40
40
  }
41
41
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
42
- const QB__namespace = /* @__PURE__ */ _interopNamespaceDefault(QB);
43
42
  const ReactDOM__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactDOM);
44
43
  function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
45
44
  return function handleEvent(event) {
@@ -3329,11 +3328,14 @@ var Root3$1 = Tooltip;
3329
3328
  var Trigger$4 = TooltipTrigger;
3330
3329
  var Portal$4 = TooltipPortal;
3331
3330
  var Content2$4 = TooltipContent;
3332
- const QueryEditorContext = /* @__PURE__ */ React__namespace.createContext({});
3331
+ const QueryEditorContext = /* @__PURE__ */ React__namespace.createContext({
3332
+ setQuery: () => {
3333
+ }
3334
+ });
3333
3335
  function useQueryBuilder(source, query) {
3334
3336
  return React.useMemo(() => {
3335
3337
  if (source) {
3336
- return new QB__namespace.ASTQuery({
3338
+ return new malloyQueryBuilder.ASTQuery({
3337
3339
  query,
3338
3340
  source
3339
3341
  });
@@ -3363,7 +3365,7 @@ function MalloyQueryFocusProvider({
3363
3365
  }
3364
3366
  if (rootQuery) {
3365
3367
  const queryDef = rootQuery.definition;
3366
- if (queryDef instanceof QB.ASTArrowQueryDefinition) {
3368
+ if (queryDef instanceof malloyQueryBuilder.ASTArrowQueryDefinition) {
3367
3369
  return findNestView(queryDef.view, [...focusedNestViewPath].reverse());
3368
3370
  }
3369
3371
  }
@@ -3397,12 +3399,12 @@ const findNestView = (currentView, remainingPath) => {
3397
3399
  if (remainingPath.length === 0) {
3398
3400
  return null;
3399
3401
  }
3400
- if (currentView instanceof QB.ASTArrowViewDefinition) {
3402
+ if (currentView instanceof malloyQueryBuilder.ASTArrowViewDefinition) {
3401
3403
  return findNestView(currentView.view, remainingPath);
3402
3404
  }
3403
- if (currentView instanceof QB.ASTSegmentViewDefinition) {
3405
+ if (currentView instanceof malloyQueryBuilder.ASTSegmentViewDefinition) {
3404
3406
  const currentNestName = remainingPath.pop();
3405
- const currentNestOperation = currentView.operations.items.find((operation) => operation instanceof QB.ASTNestViewOperation && operation.name === currentNestName);
3407
+ const currentNestOperation = currentView.operations.items.find((operation) => operation instanceof malloyQueryBuilder.ASTNestViewOperation && operation.name === currentNestName);
3406
3408
  if (currentNestOperation === void 0) {
3407
3409
  remainingPath.push(currentNestName);
3408
3410
  return null;
@@ -3412,15 +3414,34 @@ const findNestView = (currentView, remainingPath) => {
3412
3414
  return findNestView(currentNestOperation.view.definition, remainingPath);
3413
3415
  }
3414
3416
  }
3415
- if (currentView instanceof QB.ASTRefinementViewDefinition) {
3417
+ if (currentView instanceof malloyQueryBuilder.ASTRefinementViewDefinition) {
3416
3418
  return findNestView(currentView.refinement, remainingPath);
3417
3419
  }
3418
3420
  return null;
3419
3421
  };
3422
+ const UpdateQueryContext = /* @__PURE__ */ React.createContext({
3423
+ updateQuery: () => {
3424
+ console.warn("Missing <MalloyExplorerProvider>");
3425
+ }
3426
+ });
3427
+ function useUpdateQuery() {
3428
+ const {
3429
+ updateQuery
3430
+ } = React.useContext(UpdateQueryContext);
3431
+ return updateQuery;
3432
+ }
3433
+ const TopValuesContext = /* @__PURE__ */ React.createContext({});
3434
+ function useTopValues() {
3435
+ const {
3436
+ topValues
3437
+ } = React.useContext(TopValuesContext);
3438
+ return topValues;
3439
+ }
3420
3440
  function MalloyExplorerProvider({
3421
3441
  source,
3422
3442
  query,
3423
- onQueryChange,
3443
+ onQueryChange = () => {
3444
+ },
3424
3445
  focusedNestViewPath,
3425
3446
  onFocusedNestViewPathChange,
3426
3447
  children,
@@ -3428,20 +3449,32 @@ function MalloyExplorerProvider({
3428
3449
  onDrill
3429
3450
  }) {
3430
3451
  const rootQuery = useQueryBuilder(source, query);
3452
+ const updateQuery = React.useCallback(() => {
3453
+ onQueryChange == null ? void 0 : onQueryChange(rootQuery == null ? void 0 : rootQuery.build());
3454
+ }, [onQueryChange, rootQuery]);
3431
3455
  return /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, {
3432
3456
  children: /* @__PURE__ */ jsxRuntime.jsx(MalloyQueryFocusProvider, {
3433
3457
  rootQuery,
3434
3458
  focusedNestViewPath,
3435
3459
  onFocusedNestViewPathChange,
3436
- children: /* @__PURE__ */ jsxRuntime.jsx(QueryEditorContext.Provider, {
3460
+ children: /* @__PURE__ */ jsxRuntime.jsx(UpdateQueryContext.Provider, {
3437
3461
  value: {
3438
- source,
3439
- rootQuery,
3440
- setQuery: onQueryChange,
3441
- topValues,
3442
- onDrill
3462
+ updateQuery
3443
3463
  },
3444
- children
3464
+ children: /* @__PURE__ */ jsxRuntime.jsx(TopValuesContext.Provider, {
3465
+ value: {
3466
+ topValues
3467
+ },
3468
+ children: /* @__PURE__ */ jsxRuntime.jsx(QueryEditorContext.Provider, {
3469
+ value: {
3470
+ source,
3471
+ rootQuery,
3472
+ setQuery: onQueryChange,
3473
+ onDrill
3474
+ },
3475
+ children
3476
+ })
3477
+ })
3445
3478
  })
3446
3479
  })
3447
3480
  });
@@ -26004,9 +26037,9 @@ function QueryActionBar({
26004
26037
  children: [/* @__PURE__ */ jsxRuntime.jsx(Button, {
26005
26038
  onClick: () => {
26006
26039
  focusMainView();
26007
- setQuery == null ? void 0 : setQuery(void 0);
26040
+ setQuery(void 0);
26008
26041
  },
26009
- isDisabled: !rootQuery || (rootQuery == null ? void 0 : rootQuery.isEmpty()),
26042
+ isDisabled: !rootQuery || rootQuery.isEmpty(),
26010
26043
  label: "Clear",
26011
26044
  variant: "flat",
26012
26045
  size: "compact"
@@ -26216,6 +26249,7 @@ function fieldToIcon(field) {
26216
26249
  break;
26217
26250
  case "dimension":
26218
26251
  case "measure":
26252
+ case "calculate":
26219
26253
  icon = atomicTypeToIcon(field.type.kind);
26220
26254
  break;
26221
26255
  case "join":
@@ -26227,8 +26261,7 @@ function fieldToIcon(field) {
26227
26261
  function relationshipToIcon(relationship) {
26228
26262
  return relationshipMap[relationship];
26229
26263
  }
26230
- function viewToVisualizationIcon(view) {
26231
- const currentTag = view.getTag();
26264
+ function tagToVisualization(currentTag) {
26232
26265
  const currentRenderer = tagToRenderer(currentTag) ?? "table";
26233
26266
  return `viz_${currentRenderer}`;
26234
26267
  }
@@ -26248,6 +26281,7 @@ const fieldKindMap = {
26248
26281
  view: "purple",
26249
26282
  dimension: "cyan",
26250
26283
  measure: "green",
26284
+ calculate: "green",
26251
26285
  join: void 0
26252
26286
  };
26253
26287
  const relationshipMap = {
@@ -26257,6 +26291,7 @@ const relationshipMap = {
26257
26291
  };
26258
26292
  function FieldToken({
26259
26293
  field,
26294
+ additionalSiblings,
26260
26295
  hoverActions,
26261
26296
  hoverActionsVisible,
26262
26297
  ...props2
@@ -26281,7 +26316,7 @@ function FieldToken({
26281
26316
  color: fieldKindToColor(field.kind),
26282
26317
  icon: fieldToIcon(field),
26283
26318
  ...props2
26284
- }), hoverActions && /* @__PURE__ */ jsxRuntime.jsx("div", {
26319
+ }), additionalSiblings, hoverActions && /* @__PURE__ */ jsxRuntime.jsx("div", {
26285
26320
  ...{
26286
26321
  className: "mly1vsucm1 mly2lah0s"
26287
26322
  },
@@ -26312,7 +26347,7 @@ function DrillOperations({
26312
26347
  field
26313
26348
  }), /* @__PURE__ */ jsxRuntime.jsx(Token, {
26314
26349
  label: "="
26315
- }), drill.filter instanceof QB.ASTFilterWithLiteralEquality ? /* @__PURE__ */ jsxRuntime.jsx(LiteralValue, {
26350
+ }), drill.filter instanceof malloyQueryBuilder.ASTFilterWithLiteralEquality ? /* @__PURE__ */ jsxRuntime.jsx(LiteralValue, {
26316
26351
  value: drill.filter.value.node
26317
26352
  }) : /* @__PURE__ */ jsxRuntime.jsx(Token, {
26318
26353
  label: drill.filter.filterString
@@ -30230,7 +30265,7 @@ function isIndexView(field) {
30230
30265
  return allFields.size === INDEX_FIELDS.length;
30231
30266
  }
30232
30267
  function getViewDefinition(parent) {
30233
- return parent instanceof QB.ASTArrowQueryDefinition ? parent.view : parent.definition;
30268
+ return parent instanceof malloyQueryBuilder.ASTArrowQueryDefinition ? parent.view : parent.definition;
30234
30269
  }
30235
30270
  function getInputSchemaFromViewParent(parent) {
30236
30271
  if (!parent) {
@@ -30617,6 +30652,12 @@ const styles$s = {
30617
30652
  justifyContent: "mly1rfj78v",
30618
30653
  $$css: true
30619
30654
  },
30655
+ nest: {
30656
+ gridColumn: "mly623te4",
30657
+ gridColumnStart: null,
30658
+ gridColumnEnd: null,
30659
+ $$css: true
30660
+ },
30620
30661
  heading: {
30621
30662
  gridColumn: "mly623te4",
30622
30663
  gridColumnStart: null,
@@ -31129,6 +31170,20 @@ const colorVariants = {
31129
31170
  $$css: true
31130
31171
  }
31131
31172
  };
31173
+ function setAtPath(current, path, value) {
31174
+ const newCurrent = {
31175
+ ...current
31176
+ };
31177
+ let target = newCurrent;
31178
+ for (let i2 = 0; i2 < path.length - 1; i2++) {
31179
+ if (typeof target[path[i2]] !== "object") {
31180
+ target[path[i2]] = {};
31181
+ }
31182
+ target = target[path[i2]];
31183
+ }
31184
+ target[path[path.length - 1]] = value;
31185
+ return newCurrent;
31186
+ }
31132
31187
  function OneOfEditor({
31133
31188
  view,
31134
31189
  name,
@@ -31174,6 +31229,15 @@ function OneOfEditor({
31174
31229
  current,
31175
31230
  option: subOption
31176
31231
  }, key2);
31232
+ case "object":
31233
+ return /* @__PURE__ */ jsxRuntime.jsx(OneOfObjectEditor, {
31234
+ view,
31235
+ name,
31236
+ path,
31237
+ updateCurrent,
31238
+ current,
31239
+ option: subOption
31240
+ }, key2);
31177
31241
  }
31178
31242
  return null;
31179
31243
  })]
@@ -31283,7 +31347,7 @@ function OneOfNumberEditor({
31283
31347
  valueAsNumber
31284
31348
  }
31285
31349
  }) => {
31286
- setValue(value);
31350
+ setValue(valueAsNumber);
31287
31351
  updateCurrent(path, valueAsNumber);
31288
31352
  },
31289
31353
  ..._stylex.props(styles$s.input)
@@ -31322,6 +31386,48 @@ function OneOfArrayEditor({
31322
31386
  }), /* @__PURE__ */ jsxRuntime.jsx("div", {})]
31323
31387
  });
31324
31388
  }
31389
+ function OneOfObjectEditor({
31390
+ path,
31391
+ current,
31392
+ option: option2,
31393
+ updateCurrent,
31394
+ view
31395
+ }) {
31396
+ const isObject2 = current != null && typeof current === "object" && !Array.isArray(current);
31397
+ const [objectValue, setObjectValue] = React.useState(isObject2 ? current : {});
31398
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
31399
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
31400
+ ..._stylex.props(styles$s.left),
31401
+ children: /* @__PURE__ */ jsxRuntime.jsx("input", {
31402
+ type: "radio",
31403
+ checked: isObject2,
31404
+ onChange: ({
31405
+ target: {
31406
+ checked
31407
+ }
31408
+ }) => {
31409
+ if (checked) {
31410
+ updateCurrent(path, objectValue);
31411
+ }
31412
+ }
31413
+ })
31414
+ }), /* @__PURE__ */ jsxRuntime.jsx("div", {
31415
+ ..._stylex.props(styles$s.nest, styles$s.editorGrid),
31416
+ children: /* @__PURE__ */ jsxRuntime.jsx(ObjectEditor, {
31417
+ current: objectValue,
31418
+ updateCurrent: (path2, value) => {
31419
+ const [_2, ...subPath] = path2;
31420
+ setObjectValue(setAtPath(objectValue, subPath, value));
31421
+ updateCurrent(path2, value);
31422
+ },
31423
+ view,
31424
+ name: "",
31425
+ path,
31426
+ option: option2
31427
+ })
31428
+ })]
31429
+ });
31430
+ }
31325
31431
  function ArrayEditor({
31326
31432
  name,
31327
31433
  path,
@@ -31352,6 +31458,7 @@ function NumberEditor$1({
31352
31458
  option: option2,
31353
31459
  updateCurrent
31354
31460
  }) {
31461
+ const [value, setValue] = React__namespace.useState(current ?? option2.minimum);
31355
31462
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
31356
31463
  children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
31357
31464
  ..._stylex.props(styles$s.left, styles$s.label),
@@ -31359,7 +31466,7 @@ function NumberEditor$1({
31359
31466
  children: [option2.title ?? name, ":"]
31360
31467
  })
31361
31468
  }), /* @__PURE__ */ jsxRuntime.jsx("input", {
31362
- value: current,
31469
+ value,
31363
31470
  type: "number",
31364
31471
  min: option2.minimum,
31365
31472
  max: option2.maximum,
@@ -31368,6 +31475,7 @@ function NumberEditor$1({
31368
31475
  valueAsNumber
31369
31476
  }
31370
31477
  }) => {
31478
+ setValue(valueAsNumber);
31371
31479
  updateCurrent(path, valueAsNumber);
31372
31480
  },
31373
31481
  ..._stylex.props(styles$s.input)
@@ -31566,11 +31674,12 @@ function ObjectEditor({
31566
31674
  option: option2,
31567
31675
  updateCurrent
31568
31676
  }) {
31569
- const [isExpanded, setIsExpanded] = React.useState(path.length === 0);
31677
+ const [isExpanded, setIsExpanded] = React.useState(path.length === 0 || !name);
31570
31678
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
31571
31679
  children: [name ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
31572
31680
  children: [/* @__PURE__ */ jsxRuntime.jsxs("div", {
31573
31681
  ..._stylex.props(styles$s.label, styles$s.heading),
31682
+ onClick: () => setIsExpanded(!isExpanded),
31574
31683
  children: [/* @__PURE__ */ jsxRuntime.jsx("label", {
31575
31684
  children: option2.title ?? name
31576
31685
  }), option2.description ? /* @__PURE__ */ jsxRuntime.jsx(InfoHover, {
@@ -31662,31 +31771,20 @@ function ObjectEditor({
31662
31771
  });
31663
31772
  }
31664
31773
  function VizEditor({
31665
- rootQuery,
31666
31774
  view,
31667
31775
  plugin,
31668
31776
  setOpen
31669
31777
  }) {
31670
- const {
31671
- setQuery
31672
- } = React.useContext(QueryEditorContext);
31778
+ const updateQuery = useUpdateQuery();
31673
31779
  const [current, setCurrent] = React.useState(plugin.getSettings());
31674
- console.info("RendererEditor current settings:", current);
31675
31780
  const schema = plugin.getSchema();
31676
31781
  const updateCurrent = (path, value) => {
31677
- const newCurrent = {
31678
- ...current
31679
- };
31680
- let target = newCurrent;
31681
- for (let i2 = 0; i2 < path.length - 1; i2++) {
31682
- if (!(path[i2] in target)) {
31683
- target[path[i2]] = {};
31684
- }
31685
- target = target[path[i2]];
31686
- }
31687
- target[path[path.length - 1]] = value;
31782
+ const newCurrent = setAtPath(current, path, value);
31688
31783
  setCurrent(newCurrent);
31689
31784
  };
31785
+ React__namespace.useEffect(() => {
31786
+ console.info("RendererEditor current settings:", current);
31787
+ }, [current]);
31690
31788
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
31691
31789
  ..._stylex.props(styles$s.editor),
31692
31790
  children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -31718,10 +31816,10 @@ function VizEditor({
31718
31816
  if (old) {
31719
31817
  annotations.remove(old);
31720
31818
  }
31721
- view.getOrAddAnnotations().add(new QB.ASTAnnotation({
31819
+ view.getOrAddAnnotations().add(new malloyQueryBuilder.ASTAnnotation({
31722
31820
  value
31723
31821
  }));
31724
- setQuery == null ? void 0 : setQuery(rootQuery.build());
31822
+ updateQuery();
31725
31823
  setOpen(false);
31726
31824
  },
31727
31825
  customStyle: styles$s.editorCell
@@ -31934,7 +32032,6 @@ const dialogStyles = {
31934
32032
  }
31935
32033
  };
31936
32034
  function VizEditorDialog({
31937
- rootQuery,
31938
32035
  plugin,
31939
32036
  view,
31940
32037
  customStyle,
@@ -31964,7 +32061,6 @@ function VizEditorDialog({
31964
32061
  ..._stylex.props(dialogStyles.displayNone),
31965
32062
  children: "Edit visualization parameters"
31966
32063
  }), /* @__PURE__ */ jsxRuntime.jsx(VizEditor, {
31967
- rootQuery,
31968
32064
  view,
31969
32065
  plugin,
31970
32066
  setOpen
@@ -31983,12 +32079,9 @@ const styles$p = {
31983
32079
  }
31984
32080
  };
31985
32081
  function Visualization$1({
31986
- rootQuery,
31987
32082
  view
31988
32083
  }) {
31989
- const {
31990
- setQuery
31991
- } = React.useContext(QueryEditorContext);
32084
+ const updateQuery = useUpdateQuery();
31992
32085
  const renderer = React.useMemo(() => new render.MalloyRenderer(), []);
31993
32086
  const [currentRenderer, setCurrentRenderer] = React.useState("table");
31994
32087
  const [plugin, setPlugin] = React.useState();
@@ -32033,7 +32126,7 @@ function Visualization$1({
32033
32126
  }, [renderer, view, tag]);
32034
32127
  const updateViz = (renderer2) => {
32035
32128
  view.setTagProperty(["viz"], renderer2, RENDERER_PREFIX);
32036
- setQuery == null ? void 0 : setQuery(rootQuery.build());
32129
+ updateQuery();
32037
32130
  };
32038
32131
  const items = VIZ_RENDERERS.map((viz) => ({
32039
32132
  icon: /* @__PURE__ */ jsxRuntime.jsx(Icon, {
@@ -32072,7 +32165,6 @@ function Visualization$1({
32072
32165
  }), /* @__PURE__ */ jsxRuntime.jsx(VizEditorDialog, {
32073
32166
  open,
32074
32167
  setOpen,
32075
- rootQuery,
32076
32168
  plugin,
32077
32169
  view
32078
32170
  })]
@@ -32215,9 +32307,7 @@ function TopValuesTable({
32215
32307
  field,
32216
32308
  path
32217
32309
  }) {
32218
- const {
32219
- topValues
32220
- } = React.useContext(QueryEditorContext);
32310
+ const topValues = useTopValues();
32221
32311
  const fieldPath = [...path, field.name].join(".");
32222
32312
  const fieldTopValues = topValues == null ? void 0 : topValues.find((entry) => entry.fieldName === fieldPath);
32223
32313
  if (!fieldTopValues) {
@@ -32590,9 +32680,7 @@ function BooleanFilterCore({
32590
32680
  });
32591
32681
  }
32592
32682
  function useSearch(searchTerm, fieldPath) {
32593
- const {
32594
- topValues
32595
- } = React.useContext(QueryEditorContext);
32683
+ const topValues = useTopValues();
32596
32684
  if (topValues && searchTerm) {
32597
32685
  let searchValues = topValues;
32598
32686
  if (fieldPath) {
@@ -33994,19 +34082,55 @@ const styles$g = {
33994
34082
  $$css: true
33995
34083
  }
33996
34084
  };
34085
+ const getPrimaryAxis = (view) => {
34086
+ const schema = view.getOutputSchema();
34087
+ return getPrimaryAxisFromSchema(schema);
34088
+ };
34089
+ const getPrimaryAxisFromSchema = (schema) => {
34090
+ let primaryAxisField = void 0;
34091
+ primaryAxisField = findAxisFieldByAnnotation(schema.fields) || findAxisFieldByType(schema.fields) || findDefaultAxisField(schema.fields);
34092
+ return primaryAxisField;
34093
+ };
34094
+ const findAxisFieldByAnnotation = (fields) => {
34095
+ return fields.find((field) => {
34096
+ if (field.kind === "dimension" && field.annotations && field.annotations.find((annotation) => annotation.value === "# x")) {
34097
+ return true;
34098
+ }
34099
+ return false;
34100
+ });
34101
+ };
34102
+ const findAxisFieldByType = (fields) => {
34103
+ return fields.find((field) => {
34104
+ if (field.kind === "dimension") {
34105
+ const dimension = field;
34106
+ if (dimension.type.kind === "date_type" || dimension.type.kind === "timestamp_type") {
34107
+ return true;
34108
+ }
34109
+ }
34110
+ return false;
34111
+ });
34112
+ };
34113
+ const findDefaultAxisField = (fields) => {
34114
+ return fields.find((field) => {
34115
+ if (field.kind === "dimension") {
34116
+ return true;
34117
+ }
34118
+ return false;
34119
+ });
34120
+ };
33997
34121
  function toFullName(path, name) {
33998
34122
  return [...path || [], name].join(".");
33999
34123
  }
34000
34124
  function segmentHasLimit(segment) {
34001
- return segment.operations.items.find((operation) => operation instanceof QB.ASTLimitViewOperation) !== void 0;
34125
+ return segment.operations.items.find((operation) => operation instanceof malloyQueryBuilder.ASTLimitViewOperation) !== void 0;
34002
34126
  }
34003
34127
  function segmentHasOrderBy(segment, name) {
34004
- return segment.operations.items.find((operation) => operation instanceof QB.ASTOrderByViewOperation && operation.name === name) !== void 0;
34128
+ return segment.operations.items.find((operation) => operation instanceof malloyQueryBuilder.ASTOrderByViewOperation && operation.name === name) !== void 0;
34005
34129
  }
34006
34130
  function getOutputNameToInputNameMap(segment) {
34007
34131
  const nameMap = /* @__PURE__ */ new Map();
34008
34132
  for (const operation of segment.operations.items) {
34009
- if (operation instanceof QB.ASTGroupByViewOperation || operation instanceof QB.ASTAggregateViewOperation) {
34133
+ if (operation instanceof malloyQueryBuilder.ASTGroupByViewOperation || operation instanceof malloyQueryBuilder.ASTAggregateViewOperation) {
34010
34134
  const reference = operation.field.getReference();
34011
34135
  if (reference) {
34012
34136
  nameMap.set(operation.name, toFullName(reference.path, reference.name));
@@ -34019,7 +34143,7 @@ function segmentHasOrderBySourceField(segment, path, name) {
34019
34143
  const nameMap = getOutputNameToInputNameMap(segment);
34020
34144
  const fullInputName = toFullName(path, name);
34021
34145
  return !!segment.operations.items.find((operation) => {
34022
- if (operation instanceof QB.ASTOrderByViewOperation && nameMap.has(operation.name)) {
34146
+ if (operation instanceof malloyQueryBuilder.ASTOrderByViewOperation && nameMap.has(operation.name)) {
34023
34147
  return fullInputName === nameMap.get(operation.name);
34024
34148
  }
34025
34149
  return false;
@@ -34030,7 +34154,7 @@ function areReferencesEqual(path1, name1, path2, name2) {
34030
34154
  }
34031
34155
  function segmentHasFieldInOutputSpace(segment, path, name) {
34032
34156
  const match = segment.operations.items.find((operation) => {
34033
- if (operation instanceof QB.ASTGroupByViewOperation || operation instanceof QB.ASTAggregateViewOperation) {
34157
+ if (operation instanceof malloyQueryBuilder.ASTGroupByViewOperation || operation instanceof malloyQueryBuilder.ASTAggregateViewOperation) {
34034
34158
  const reference = operation.field.getReference();
34035
34159
  if (reference) {
34036
34160
  return areReferencesEqual(path, name, reference.path, reference.name);
@@ -34044,7 +34168,7 @@ function segmentHasFieldInOutputSpace(segment, path, name) {
34044
34168
  }
34045
34169
  function segmentNestNo(segment, name) {
34046
34170
  return segment.operations.items.reduce((acc, operation) => {
34047
- if (operation instanceof QB.ASTNestViewOperation) {
34171
+ if (operation instanceof malloyQueryBuilder.ASTNestViewOperation) {
34048
34172
  {
34049
34173
  if (operation.name === name) {
34050
34174
  do {
@@ -34072,6 +34196,34 @@ function addGroupBy(view, field, path) {
34072
34196
  segment.addTimestampGroupBy(field.name, path, "second");
34073
34197
  } else {
34074
34198
  segment.addGroupBy(field.name, path, rename);
34199
+ recomputePartitionByAndPrimaryAxis(segment);
34200
+ }
34201
+ }
34202
+ function recomputePartitionByAndPrimaryAxis(segment) {
34203
+ var _a2;
34204
+ const primaryAxis = getPrimaryAxisFromSchema(segment.getOutputSchema());
34205
+ const groupBys = segment.operations.items.filter((op) => op.kind === "group_by");
34206
+ const movingAverages = segment.operations.items.filter((op) => op.kind === "calculate" && op.expression.kind === "moving_average");
34207
+ const canSmooth = primaryAxis !== null && (primaryAxis == null ? void 0 : primaryAxis.kind) === "dimension" && (primaryAxis.type.kind === "timestamp_type" || primaryAxis.type.kind === "date_type");
34208
+ if (!canSmooth) {
34209
+ movingAverages.forEach((operation) => {
34210
+ operation.delete();
34211
+ segment.addAggregate(operation.getFieldInfo().name);
34212
+ });
34213
+ } else {
34214
+ const nonPrimaryGroupByNames = groupBys.filter((gb) => gb.name !== primaryAxis.name);
34215
+ movingAverages.forEach((operation) => {
34216
+ operation.expression.edit();
34217
+ operation.expression.setPartitionFields(nonPrimaryGroupByNames.map((gb) => gb.field.getReference()).filter((ref) => !!ref));
34218
+ });
34219
+ const primaryTimeAxisOperation = groupBys.find((gb) => gb.name === primaryAxis.name);
34220
+ if (primaryTimeAxisOperation) {
34221
+ const expression = (_a2 = primaryTimeAxisOperation.field) == null ? void 0 : _a2.expression;
34222
+ if (expression && expression.kind === "time_truncation") {
34223
+ const truncationExpression = primaryTimeAxisOperation.field.expression;
34224
+ truncationExpression.truncation = "day";
34225
+ }
34226
+ }
34075
34227
  }
34076
34228
  }
34077
34229
  function addAggregate(view, field, path) {
@@ -34126,10 +34278,10 @@ function getSegmentIfPresent(parent) {
34126
34278
  return void 0;
34127
34279
  }
34128
34280
  const definition = getViewDefinition(parent);
34129
- if (definition instanceof QB.ASTSegmentViewDefinition) {
34281
+ if (definition instanceof malloyQueryBuilder.ASTSegmentViewDefinition) {
34130
34282
  return definition;
34131
- } else if (definition instanceof QB.ASTRefinementViewDefinition) {
34132
- if (definition.refinement instanceof QB.ASTSegmentViewDefinition) {
34283
+ } else if (definition instanceof malloyQueryBuilder.ASTRefinementViewDefinition) {
34284
+ if (definition.refinement instanceof malloyQueryBuilder.ASTSegmentViewDefinition) {
34133
34285
  return definition.refinement;
34134
34286
  }
34135
34287
  }
@@ -34183,16 +34335,13 @@ function OperationActionTitle({
34183
34335
  });
34184
34336
  }
34185
34337
  function RenameDialog({
34186
- rootQuery,
34187
34338
  view,
34188
34339
  target,
34189
34340
  open,
34190
34341
  setOpen
34191
34342
  }) {
34192
34343
  const [name, setName] = React.useState("");
34193
- const {
34194
- setQuery
34195
- } = React.useContext(QueryEditorContext);
34344
+ const updateQuery = useUpdateQuery();
34196
34345
  React.useEffect(() => {
34197
34346
  if (target) {
34198
34347
  setName(target.name);
@@ -34202,8 +34351,9 @@ function RenameDialog({
34202
34351
  return null;
34203
34352
  }
34204
34353
  const onRename = () => {
34354
+ target.edit();
34205
34355
  target.name = name;
34206
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
34356
+ updateQuery();
34207
34357
  setOpen(false);
34208
34358
  };
34209
34359
  const {
@@ -34266,15 +34416,12 @@ function RenameDialog({
34266
34416
  });
34267
34417
  }
34268
34418
  function SortableOperations({
34269
- rootQuery,
34270
34419
  segment,
34271
34420
  view,
34272
34421
  operations,
34273
34422
  kind
34274
34423
  }) {
34275
- const {
34276
- setQuery
34277
- } = React.useContext(QueryEditorContext);
34424
+ const updateQuery = useUpdateQuery();
34278
34425
  const sensors = useSensors(useSensor(PointerSensor));
34279
34426
  const items = React.useMemo(() => {
34280
34427
  return operations.map((operation) => ({
@@ -34286,7 +34433,7 @@ function SortableOperations({
34286
34433
  return null;
34287
34434
  }
34288
34435
  function handleDragEnd(event) {
34289
- const operations2 = segment.operations.items.filter((operation) => operation instanceof QB.ASTAggregateViewOperation || operation instanceof QB.ASTGroupByViewOperation || operation instanceof QB.ASTNestViewOperation);
34436
+ const operations2 = segment.operations.items.filter((operation) => operation instanceof malloyQueryBuilder.ASTAggregateViewOperation || operation instanceof malloyQueryBuilder.ASTGroupByViewOperation || operation instanceof malloyQueryBuilder.ASTNestViewOperation);
34290
34437
  const names = operations2.map((operation) => operation.name);
34291
34438
  const {
34292
34439
  active,
@@ -34296,7 +34443,7 @@ function SortableOperations({
34296
34443
  const oldIndex = names.indexOf(active.id);
34297
34444
  const newIndex = names.indexOf(over.id);
34298
34445
  segment.reorderFields(arrayMove(names, oldIndex, newIndex));
34299
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34446
+ updateQuery();
34300
34447
  }
34301
34448
  }
34302
34449
  const {
@@ -34308,7 +34455,7 @@ function SortableOperations({
34308
34455
  types: ["dimension"],
34309
34456
  onClick: (field, path) => {
34310
34457
  addGroupBy(view, field, path);
34311
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34458
+ updateQuery();
34312
34459
  }
34313
34460
  } : {
34314
34461
  title: "aggregate",
@@ -34316,12 +34463,11 @@ function SortableOperations({
34316
34463
  types: ["measure"],
34317
34464
  onClick: (field, path) => {
34318
34465
  addAggregate(view, field, path);
34319
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34466
+ updateQuery();
34320
34467
  }
34321
34468
  };
34322
34469
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
34323
34470
  children: [/* @__PURE__ */ jsxRuntime.jsx(OperationActionTitle, {
34324
- rootQuery,
34325
34471
  view,
34326
34472
  fields,
34327
34473
  ...props2
@@ -34334,7 +34480,6 @@ function SortableOperations({
34334
34480
  children: /* @__PURE__ */ jsxRuntime.jsx(SortableContext, {
34335
34481
  items,
34336
34482
  children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(SortableOperation, {
34337
- rootQuery,
34338
34483
  id: item.id,
34339
34484
  color: kind === "group_by" ? "cyan" : "green",
34340
34485
  view,
@@ -34347,18 +34492,16 @@ function SortableOperations({
34347
34492
  }
34348
34493
  const NULL_PATH = [];
34349
34494
  function SortableOperation({
34350
- rootQuery,
34351
34495
  id,
34352
34496
  view,
34353
34497
  operation,
34354
34498
  color
34355
34499
  }) {
34356
34500
  var _a2;
34357
- const {
34358
- setQuery
34359
- } = React.useContext(QueryEditorContext);
34501
+ const updateQuery = useUpdateQuery();
34360
34502
  const fieldInfo = operation.getFieldInfo();
34361
- const path = ((_a2 = operation.field.getReference()) == null ? void 0 : _a2.path) ?? NULL_PATH;
34503
+ const field = operation instanceof malloyQueryBuilder.ASTCalculateViewOperation ? null : operation.field;
34504
+ const path = operation instanceof malloyQueryBuilder.ASTCalculateViewOperation ? operation.expression.node.field_reference.path ?? NULL_PATH : ((_a2 = operation.field.getReference()) == null ? void 0 : _a2.path) ?? NULL_PATH;
34362
34505
  const {
34363
34506
  attributes,
34364
34507
  listeners,
@@ -34378,6 +34521,18 @@ function SortableOperation({
34378
34521
  transform: CSS$1.Transform.toString(transform2),
34379
34522
  transition
34380
34523
  };
34524
+ const primaryAxis = React.useMemo(() => {
34525
+ return getPrimaryAxis(view);
34526
+ }, [view]);
34527
+ const canSmooth = operation.kind === "aggregate" && primaryAxis !== null && (primaryAxis == null ? void 0 : primaryAxis.kind) === "dimension" && (primaryAxis.type.kind === "timestamp_type" || primaryAxis.type.kind === "date_type");
34528
+ const enableSmoothing = React.useCallback((operation2) => {
34529
+ if (!canSmooth) {
34530
+ return;
34531
+ }
34532
+ operation2.convertToCalculateMovingAverage(operation2.name + "_smoothed", 7);
34533
+ recomputePartitionByAndPrimaryAxis(view.getOrAddDefaultSegment());
34534
+ updateQuery();
34535
+ }, [canSmooth, updateQuery, view]);
34381
34536
  const hoverActions = React.useMemo(() => {
34382
34537
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
34383
34538
  children: [/* @__PURE__ */ jsxRuntime.jsx(DropdownMenu, {
@@ -34388,7 +34543,14 @@ function SortableOperation({
34388
34543
  tooltip: "More Actions"
34389
34544
  }),
34390
34545
  onOpenChange: setHoverActionsVisible,
34391
- children: [/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, {
34546
+ children: [canSmooth ? /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, {
34547
+ label: "Add smoothing",
34548
+ onClick: () => {
34549
+ if (operation instanceof malloyQueryBuilder.ASTAggregateViewOperation) {
34550
+ enableSmoothing(operation);
34551
+ }
34552
+ }
34553
+ }, "smoothing") : null, /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, {
34392
34554
  label: "Rename",
34393
34555
  onClick: () => {
34394
34556
  setRenameTarget(operation);
@@ -34398,12 +34560,21 @@ function SortableOperation({
34398
34560
  }, [...path, fieldInfo.name].join(".")), /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34399
34561
  onClick: () => {
34400
34562
  operation.delete();
34401
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
34563
+ recomputePartitionByAndPrimaryAxis(view.getOrAddDefaultSegment());
34564
+ updateQuery();
34402
34565
  }
34403
34566
  })]
34404
34567
  });
34405
- }, [fieldInfo, operation, path, rootQuery, setQuery]);
34406
- const granular = granularityMenuItems(fieldInfo, operation.field);
34568
+ }, [canSmooth, enableSmoothing, fieldInfo.name, operation, path, updateQuery, view]);
34569
+ const hasSmoothedField = React.useMemo(() => {
34570
+ return view.getOrAddDefaultSegment().operations.items.some((operation2) => {
34571
+ return operation2.kind === "calculate";
34572
+ });
34573
+ }, [view]);
34574
+ const granular = granularityMenuItems(fieldInfo, field);
34575
+ if (hasSmoothedField && granular && operation.name === (primaryAxis == null ? void 0 : primaryAxis.name)) {
34576
+ granular.options = granular.options.filter((option2) => option2.value === "day");
34577
+ }
34407
34578
  let icon = "orderBy";
34408
34579
  if (fieldInfo.kind === "dimension" || fieldInfo.kind === "measure") {
34409
34580
  icon = atomicTypeToIcon(fieldInfo.type.kind);
@@ -34412,7 +34583,7 @@ function SortableOperation({
34412
34583
  id,
34413
34584
  ref: setNodeRef,
34414
34585
  style,
34415
- children: [granular ? /* @__PURE__ */ jsxRuntime.jsxs("div", {
34586
+ children: [field && granular ? /* @__PURE__ */ jsxRuntime.jsxs("div", {
34416
34587
  ...{
34417
34588
  0: {
34418
34589
  className: "mly78zum5 mly6s0dn4 mly1nhvcw1 mly1jnr06f mly11ogjb6 mly1g9of4s"
@@ -34435,8 +34606,8 @@ function SortableOperation({
34435
34606
  color,
34436
34607
  value: granular.value,
34437
34608
  onChange: (granulation) => {
34438
- if (operation.field.expression instanceof QB.ASTTimeTruncationExpression) operation.field.expression.truncation = granulation;
34439
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34609
+ if (field.expression instanceof malloyQueryBuilder.ASTTimeTruncationExpression) field.expression.truncation = granulation;
34610
+ updateQuery();
34440
34611
  },
34441
34612
  items: granular.options
34442
34613
  })]
@@ -34446,7 +34617,7 @@ function SortableOperation({
34446
34617
  },
34447
34618
  children: hoverActions
34448
34619
  })]
34449
- }) : /* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
34620
+ }) : operation instanceof malloyQueryBuilder.ASTCalculateViewOperation ? /* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
34450
34621
  field: fieldInfo,
34451
34622
  color,
34452
34623
  hoverActionsVisible,
@@ -34463,9 +34634,67 @@ function SortableOperation({
34463
34634
  dragProps: {
34464
34635
  attributes,
34465
34636
  listeners
34466
- }
34637
+ },
34638
+ additionalSiblings: /* @__PURE__ */ jsxRuntime.jsx(SelectorToken, {
34639
+ color,
34640
+ value: "" + (operation.expression.node.rows_preceding ?? 7),
34641
+ onChange: (value) => {
34642
+ if (value === "1") {
34643
+ view.getOrAddDefaultSegment().operations.add(new malloyQueryBuilder.ASTAggregateViewOperation({
34644
+ kind: "aggregate",
34645
+ field: {
34646
+ expression: {
34647
+ kind: "field_reference",
34648
+ name: operation.expression.node.field_reference.name
34649
+ }
34650
+ }
34651
+ }));
34652
+ operation.delete();
34653
+ updateQuery();
34654
+ } else {
34655
+ operation.expression.edit();
34656
+ operation.expression.rowsPreceding = parseInt(value, 10);
34657
+ updateQuery();
34658
+ }
34659
+ },
34660
+ items: [{
34661
+ label: "7d",
34662
+ value: "7"
34663
+ }, {
34664
+ label: "14d",
34665
+ value: "14"
34666
+ }, {
34667
+ label: "28d",
34668
+ value: "28"
34669
+ }, {
34670
+ label: "30d",
34671
+ value: "30"
34672
+ }, {
34673
+ label: "Remove smoothing",
34674
+ value: "1"
34675
+ }]
34676
+ })
34677
+ }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
34678
+ children: /* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
34679
+ field: fieldInfo,
34680
+ color,
34681
+ hoverActionsVisible,
34682
+ hoverActions,
34683
+ tooltip: /* @__PURE__ */ jsxRuntime.jsx(FieldHoverCard, {
34684
+ field: fieldInfo,
34685
+ path
34686
+ }),
34687
+ tooltipProps: {
34688
+ side: "right",
34689
+ align: "start",
34690
+ alignOffset: 28
34691
+ },
34692
+ dragProps: {
34693
+ attributes,
34694
+ listeners
34695
+ }
34696
+ })
34467
34697
  }), /* @__PURE__ */ jsxRuntime.jsx(RenameDialog, {
34468
- rootQuery,
34469
34698
  view,
34470
34699
  target: renameTarget,
34471
34700
  open: renameOpen,
@@ -34476,7 +34705,7 @@ function SortableOperation({
34476
34705
  const DateGranulation = ["day", "week", "month", "quarter", "year"];
34477
34706
  const TimestampGranulation = ["second", "minute", "hour", "day", "week", "month", "quarter", "year"];
34478
34707
  function granularityMenuItems(fieldInfo, field) {
34479
- if (fieldInfo.kind !== "dimension" || !(field.expression instanceof QB.ASTTimeTruncationExpression)) {
34708
+ if (!field || fieldInfo.kind !== "dimension" || !(field.expression instanceof malloyQueryBuilder.ASTTimeTruncationExpression)) {
34480
34709
  return null;
34481
34710
  }
34482
34711
  if (fieldInfo.type.kind === "timestamp_type") {
@@ -34506,13 +34735,11 @@ const customStyles = {
34506
34735
  }
34507
34736
  };
34508
34737
  function GroupByOperations({
34509
- rootQuery,
34510
34738
  segment,
34511
34739
  view,
34512
34740
  groupBys
34513
34741
  }) {
34514
34742
  return /* @__PURE__ */ jsxRuntime.jsx(SortableOperations, {
34515
- rootQuery,
34516
34743
  segment,
34517
34744
  view,
34518
34745
  operations: groupBys,
@@ -34755,12 +34982,9 @@ function displayTimeFromMoment(momentObj) {
34755
34982
  return momentObj.moment;
34756
34983
  }
34757
34984
  function FilterOperations({
34758
- rootQuery,
34759
34985
  filters
34760
34986
  }) {
34761
- const {
34762
- setQuery
34763
- } = React.useContext(QueryEditorContext);
34987
+ const updateQuery = useUpdateQuery();
34764
34988
  if (filters.length === 0) {
34765
34989
  return null;
34766
34990
  }
@@ -34776,13 +35000,12 @@ function FilterOperations({
34776
35000
  children: ["Invalid filter", /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34777
35001
  onClick: () => {
34778
35002
  filterOperation.delete();
34779
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35003
+ updateQuery();
34780
35004
  }
34781
35005
  })]
34782
35006
  }),
34783
35007
  children: /* @__PURE__ */ jsxRuntime.jsx(SingleFilterOperation, {
34784
- filterOperation,
34785
- rootQuery
35008
+ filterOperation
34786
35009
  })
34787
35010
  }, key2);
34788
35011
  })
@@ -34790,29 +35013,26 @@ function FilterOperations({
34790
35013
  });
34791
35014
  }
34792
35015
  function SingleFilterOperation({
34793
- rootQuery,
34794
35016
  filterOperation
34795
35017
  }) {
34796
- const {
34797
- setQuery
34798
- } = React.useContext(QueryEditorContext);
35018
+ const updateQuery = useUpdateQuery();
34799
35019
  const setFilter = React.useCallback((filter2) => {
34800
- if (filterOperation.filter instanceof QB.ASTFilterWithFilterString) {
35020
+ if (filterOperation.filter instanceof malloyQueryBuilder.ASTFilterWithFilterString) {
34801
35021
  filterOperation.filter.setFilter(filter2);
34802
35022
  }
34803
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34804
- }, [filterOperation.filter, rootQuery, setQuery]);
35023
+ updateQuery();
35024
+ }, [filterOperation.filter, updateQuery]);
34805
35025
  const {
34806
35026
  filter
34807
35027
  } = filterOperation;
34808
- if (!(filter instanceof QB.ASTFilterWithFilterString)) {
35028
+ if (!(filter instanceof malloyQueryBuilder.ASTFilterWithFilterString)) {
34809
35029
  return null;
34810
35030
  }
34811
35031
  const {
34812
35032
  expression,
34813
35033
  filterString
34814
35034
  } = filter;
34815
- if (!(expression instanceof QB.ASTReferenceExpression)) {
35035
+ if (!(expression instanceof malloyQueryBuilder.ASTReferenceExpression)) {
34816
35036
  return null;
34817
35037
  }
34818
35038
  const fieldInfo = filter.getFieldInfo();
@@ -34845,19 +35065,16 @@ function SingleFilterOperation({
34845
35065
  children: /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34846
35066
  onClick: () => {
34847
35067
  filterOperation.delete();
34848
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35068
+ updateQuery();
34849
35069
  }
34850
35070
  })
34851
35071
  })]
34852
35072
  });
34853
35073
  }
34854
35074
  function LimitOperation({
34855
- rootQuery,
34856
35075
  limit
34857
35076
  }) {
34858
- const {
34859
- setQuery
34860
- } = React.useContext(QueryEditorContext);
35077
+ const updateQuery = useUpdateQuery();
34861
35078
  if (!limit) {
34862
35079
  return null;
34863
35080
  }
@@ -34872,7 +35089,7 @@ function LimitOperation({
34872
35089
  value: limit.limit,
34873
35090
  onChange: (value) => {
34874
35091
  limit.limit = value;
34875
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35092
+ updateQuery();
34876
35093
  },
34877
35094
  errorMessage: limit.limit < 0 ? "Limit must be positive" : void 0
34878
35095
  }), /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -34880,7 +35097,7 @@ function LimitOperation({
34880
35097
  children: /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34881
35098
  onClick: () => {
34882
35099
  limit.delete();
34883
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35100
+ updateQuery();
34884
35101
  }
34885
35102
  })
34886
35103
  })]
@@ -34888,13 +35105,11 @@ function LimitOperation({
34888
35105
  });
34889
35106
  }
34890
35107
  function AggregateOperations({
34891
- rootQuery,
34892
35108
  segment,
34893
35109
  view,
34894
35110
  aggregates
34895
35111
  }) {
34896
35112
  return /* @__PURE__ */ jsxRuntime.jsx(SortableOperations, {
34897
- rootQuery,
34898
35113
  segment,
34899
35114
  view,
34900
35115
  operations: aggregates,
@@ -34902,12 +35117,9 @@ function AggregateOperations({
34902
35117
  });
34903
35118
  }
34904
35119
  function OrderByOperations({
34905
- rootQuery,
34906
35120
  orderBys
34907
35121
  }) {
34908
- const {
34909
- setQuery
34910
- } = React.useContext(QueryEditorContext);
35122
+ const updateQuery = useUpdateQuery();
34911
35123
  if (orderBys.length === 0) {
34912
35124
  return null;
34913
35125
  }
@@ -34947,7 +35159,7 @@ function OrderByOperations({
34947
35159
  value: orderBy.direction ?? "asc",
34948
35160
  onChange: (direction) => {
34949
35161
  orderBy.direction = direction;
34950
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35162
+ updateQuery();
34951
35163
  }
34952
35164
  })]
34953
35165
  }), /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -34955,7 +35167,7 @@ function OrderByOperations({
34955
35167
  children: /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34956
35168
  onClick: () => {
34957
35169
  orderBy.delete();
34958
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35170
+ updateQuery();
34959
35171
  }
34960
35172
  })
34961
35173
  })]
@@ -34965,7 +35177,6 @@ function OrderByOperations({
34965
35177
  });
34966
35178
  }
34967
35179
  function View({
34968
- rootQuery,
34969
35180
  view
34970
35181
  }) {
34971
35182
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -34975,10 +35186,8 @@ function View({
34975
35186
  gap: 8
34976
35187
  },
34977
35188
  children: [/* @__PURE__ */ jsxRuntime.jsx(Visualization$1, {
34978
- rootQuery,
34979
35189
  view
34980
35190
  }), /* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
34981
- rootQuery,
34982
35191
  view,
34983
35192
  viewDef: view.definition
34984
35193
  })]
@@ -35043,12 +35252,9 @@ const styles$f = {
35043
35252
  }
35044
35253
  };
35045
35254
  function AddLimit({
35046
- rootQuery,
35047
35255
  view
35048
35256
  }) {
35049
- const {
35050
- setQuery
35051
- } = React.useContext(QueryEditorContext);
35257
+ const updateQuery = useUpdateQuery();
35052
35258
  const segment = getSegmentIfPresent(view);
35053
35259
  const hasLimit = segment ? segmentHasLimit(segment) : false;
35054
35260
  return /* @__PURE__ */ jsxRuntime.jsx(AddItem, {
@@ -35060,17 +35266,14 @@ function AddLimit({
35060
35266
  onClick: () => {
35061
35267
  const segment2 = view.getOrAddDefaultSegment();
35062
35268
  segment2.setLimit(10);
35063
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35269
+ updateQuery();
35064
35270
  }
35065
35271
  });
35066
35272
  }
35067
35273
  function AddEmptyNest({
35068
- rootQuery,
35069
35274
  view
35070
35275
  }) {
35071
- const {
35072
- setQuery
35073
- } = React.useContext(QueryEditorContext);
35276
+ const updateQuery = useUpdateQuery();
35074
35277
  return /* @__PURE__ */ jsxRuntime.jsx(AddItem, {
35075
35278
  icon: /* @__PURE__ */ jsxRuntime.jsx(Icon, {
35076
35279
  name: "nest"
@@ -35080,7 +35283,7 @@ function AddEmptyNest({
35080
35283
  const segment = view.getOrAddDefaultSegment();
35081
35284
  const nestNo = segmentNestNo(segment, `Nest`);
35082
35285
  segment.addEmptyNest(nestNo > 1 ? `Nest ${nestNo}` : `Nest`);
35083
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35286
+ updateQuery();
35084
35287
  }
35085
35288
  });
35086
35289
  }
@@ -35112,13 +35315,10 @@ const styles$e = {
35112
35315
  }
35113
35316
  };
35114
35317
  function AddOrderBy({
35115
- rootQuery,
35116
35318
  view,
35117
35319
  search
35118
35320
  }) {
35119
- const {
35120
- setQuery
35121
- } = React.useContext(QueryEditorContext);
35321
+ const updateQuery = useUpdateQuery();
35122
35322
  const outputSchemaFields = view.getOutputSchema().fields;
35123
35323
  const segment = getSegmentIfPresent(view);
35124
35324
  const fields = React.useMemo(() => outputSchemaFields.filter((field) => field.kind === "dimension").filter((field) => ORDERABLE_TYPES$1.includes(field.type.kind)).filter((field) => segment ? !segmentHasOrderBy(segment, field.name) : true), [outputSchemaFields, segment]);
@@ -35130,7 +35330,7 @@ function AddOrderBy({
35130
35330
  types: ["dimension"],
35131
35331
  onAddOperation: (field) => {
35132
35332
  addOrderBy(view, field);
35133
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35333
+ updateQuery();
35134
35334
  },
35135
35335
  disabledMessage: "There must be at least one field in the output to order by.",
35136
35336
  search
@@ -35138,13 +35338,10 @@ function AddOrderBy({
35138
35338
  }
35139
35339
  const ORDERABLE_TYPES$1 = ["string_type", "number_type", "boolean_type", "date_type", "timestamp_type"];
35140
35340
  function AddGroupBy({
35141
- rootQuery,
35142
35341
  view,
35143
35342
  search
35144
35343
  }) {
35145
- const {
35146
- setQuery
35147
- } = React.useContext(QueryEditorContext);
35344
+ const updateQuery = useUpdateQuery();
35148
35345
  const {
35149
35346
  fields
35150
35347
  } = getInputSchemaFromViewParent(view);
@@ -35161,19 +35358,16 @@ function AddGroupBy({
35161
35358
  filter,
35162
35359
  onAddOperation: (field, path) => {
35163
35360
  addGroupBy(view, field, path);
35164
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35361
+ updateQuery();
35165
35362
  },
35166
35363
  search
35167
35364
  });
35168
35365
  }
35169
35366
  function AddAggregate({
35170
- rootQuery,
35171
35367
  view,
35172
35368
  search
35173
35369
  }) {
35174
- const {
35175
- setQuery
35176
- } = React.useContext(QueryEditorContext);
35370
+ const updateQuery = useUpdateQuery();
35177
35371
  const {
35178
35372
  fields
35179
35373
  } = getInputSchemaFromViewParent(view);
@@ -35190,7 +35384,7 @@ function AddAggregate({
35190
35384
  filter,
35191
35385
  onAddOperation: (field, path) => {
35192
35386
  addAggregate(view, field, path);
35193
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35387
+ updateQuery();
35194
35388
  },
35195
35389
  search
35196
35390
  });
@@ -35199,10 +35393,7 @@ function AddWhere({
35199
35393
  view,
35200
35394
  search
35201
35395
  }) {
35202
- const {
35203
- rootQuery,
35204
- setQuery
35205
- } = React__namespace.useContext(QueryEditorContext);
35396
+ const updateQuery = useUpdateQuery();
35206
35397
  const {
35207
35398
  fields
35208
35399
  } = getInputSchemaFromViewParent(view);
@@ -35216,7 +35407,7 @@ function AddWhere({
35216
35407
  onAddOperation: (field, path, filter) => {
35217
35408
  if (filter && (field.kind === "dimension" || field.kind === "measure")) {
35218
35409
  addFilter(view, field, path, filter);
35219
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
35410
+ updateQuery();
35220
35411
  }
35221
35412
  },
35222
35413
  isFilterOperation: true,
@@ -35225,15 +35416,18 @@ function AddWhere({
35225
35416
  }
35226
35417
  const FILTERABLE_TYPES$1 = /* @__PURE__ */ new Set(["string_type", "boolean_type", "number_type", "date_type", "timestamp_type"]);
35227
35418
  function AddView({
35228
- rootQuery,
35229
35419
  view,
35230
35420
  search
35231
35421
  }) {
35232
35422
  const {
35233
- setQuery
35423
+ rootQuery
35234
35424
  } = React.useContext(QueryEditorContext);
35425
+ const updateQuery = useUpdateQuery();
35235
35426
  const allFields = getInputSchemaFromViewParent(view).fields;
35236
35427
  const fields = React.useMemo(() => allFields.filter((field) => field.kind === "view" && !isIndexView(field)), [allFields]);
35428
+ if (!rootQuery) {
35429
+ return null;
35430
+ }
35237
35431
  return /* @__PURE__ */ jsxRuntime.jsx(AddFieldItem, {
35238
35432
  label: "Add view",
35239
35433
  icon: "view",
@@ -35247,20 +35441,17 @@ function AddView({
35247
35441
  } else {
35248
35442
  addNest(view, field);
35249
35443
  }
35250
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35444
+ updateQuery();
35251
35445
  },
35252
35446
  search
35253
35447
  });
35254
35448
  }
35255
35449
  function AddMenu({
35256
- rootQuery,
35257
35450
  view
35258
35451
  }) {
35259
35452
  const [open, setOpen] = React.useState(false);
35260
35453
  const [active, setActive] = React.useState("");
35261
- const {
35262
- setQuery
35263
- } = React.useContext(QueryEditorContext);
35454
+ const updateQuery = useUpdateQuery();
35264
35455
  const [search, setSearch] = React.useState("");
35265
35456
  const segment = getSegmentIfPresent(view);
35266
35457
  const toggleActive = (toggle) => {
@@ -35324,7 +35515,7 @@ function AddMenu({
35324
35515
  } else {
35325
35516
  addNest(view, field);
35326
35517
  }
35327
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35518
+ updateQuery();
35328
35519
  },
35329
35520
  search
35330
35521
  }), /* @__PURE__ */ jsxRuntime.jsx(Divider, {}), /* @__PURE__ */ jsxRuntime.jsx(ValueList, {
@@ -35340,7 +35531,7 @@ function AddMenu({
35340
35531
  values: [value.fieldValue ?? "∅"]
35341
35532
  }
35342
35533
  });
35343
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35534
+ updateQuery();
35344
35535
  }
35345
35536
  })]
35346
35537
  }) : /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -35377,7 +35568,6 @@ function AddMenu({
35377
35568
  onClick: () => toggleActive("view"),
35378
35569
  open: active === "view"
35379
35570
  }), /* @__PURE__ */ jsxRuntime.jsx(Divider, {}), /* @__PURE__ */ jsxRuntime.jsx(AddLimit, {
35380
- rootQuery,
35381
35571
  view
35382
35572
  }), /* @__PURE__ */ jsxRuntime.jsx(AddItem, {
35383
35573
  icon: /* @__PURE__ */ jsxRuntime.jsx(Icon, {
@@ -35387,7 +35577,6 @@ function AddMenu({
35387
35577
  onClick: () => toggleActive("order_by"),
35388
35578
  open: active === "order_by"
35389
35579
  }), /* @__PURE__ */ jsxRuntime.jsx(AddEmptyNest, {
35390
- rootQuery,
35391
35580
  view
35392
35581
  })]
35393
35582
  }), /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -35396,23 +35585,18 @@ function AddMenu({
35396
35585
  overflowY: "auto"
35397
35586
  },
35398
35587
  children: [active === "group_by" && /* @__PURE__ */ jsxRuntime.jsx(AddGroupBy, {
35399
- rootQuery,
35400
35588
  view,
35401
35589
  search
35402
35590
  }), active === "aggregate" && /* @__PURE__ */ jsxRuntime.jsx(AddAggregate, {
35403
- rootQuery,
35404
35591
  view,
35405
35592
  search
35406
35593
  }), active === "where" && /* @__PURE__ */ jsxRuntime.jsx(AddWhere, {
35407
- rootQuery,
35408
35594
  view,
35409
35595
  search
35410
35596
  }), active === "view" && /* @__PURE__ */ jsxRuntime.jsx(AddView, {
35411
- rootQuery,
35412
35597
  view,
35413
35598
  search
35414
35599
  }), active === "order_by" && /* @__PURE__ */ jsxRuntime.jsx(AddOrderBy, {
35415
- rootQuery,
35416
35600
  view,
35417
35601
  search
35418
35602
  })]
@@ -35458,7 +35642,6 @@ function FocusableView({
35458
35642
  });
35459
35643
  }
35460
35644
  function NestOperations({
35461
- rootQuery,
35462
35645
  view,
35463
35646
  nests
35464
35647
  }) {
@@ -35468,20 +35651,16 @@ function NestOperations({
35468
35651
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
35469
35652
  ..._stylex.props(styles$u.tokenContainer),
35470
35653
  children: nests.map((nest) => /* @__PURE__ */ jsxRuntime.jsx(NestOperation, {
35471
- rootQuery,
35472
35654
  view,
35473
35655
  nest
35474
35656
  }, nest.name))
35475
35657
  });
35476
35658
  }
35477
35659
  function NestOperation({
35478
- rootQuery,
35479
35660
  view,
35480
35661
  nest
35481
35662
  }) {
35482
- const {
35483
- setQuery
35484
- } = React.useContext(QueryEditorContext);
35663
+ const updateQuery = useUpdateQuery();
35485
35664
  const [renameOpen, setRenameOpen] = React.useState(false);
35486
35665
  const parentNestViewPath = React.useContext(NestViewPathContext);
35487
35666
  const {
@@ -35502,7 +35681,7 @@ function NestOperation({
35502
35681
  onClick: () => {
35503
35682
  focusNestView([...parentNestViewPath]);
35504
35683
  nest2.delete();
35505
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35684
+ updateQuery();
35506
35685
  }
35507
35686
  }), /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, {
35508
35687
  label: "Rename",
@@ -35511,7 +35690,6 @@ function NestOperation({
35511
35690
  }
35512
35691
  })]
35513
35692
  }), /* @__PURE__ */ jsxRuntime.jsx(AddMenu, {
35514
- rootQuery,
35515
35693
  view: nest2.view
35516
35694
  })]
35517
35695
  });
@@ -35523,17 +35701,15 @@ function NestOperation({
35523
35701
  },
35524
35702
  children: [/* @__PURE__ */ jsxRuntime.jsx(CollapsiblePanel, {
35525
35703
  title: nest.name,
35526
- icon: viewToVisualizationIcon(nest.view),
35704
+ icon: tagToVisualization(nest.view.getTag()),
35527
35705
  defaultOpen: true,
35528
35706
  controls: getControls(nest),
35529
35707
  collapsedControls: getControls(nest),
35530
35708
  isFocused: isNestViewFocused([...parentNestViewPath, nest.name]),
35531
35709
  children: /* @__PURE__ */ jsxRuntime.jsx(View, {
35532
- rootQuery,
35533
35710
  view: nest.view
35534
35711
  })
35535
35712
  }), /* @__PURE__ */ jsxRuntime.jsx(RenameDialog, {
35536
- rootQuery,
35537
35713
  view,
35538
35714
  target: nest,
35539
35715
  open: renameOpen,
@@ -35543,7 +35719,6 @@ function NestOperation({
35543
35719
  });
35544
35720
  }
35545
35721
  function Operations({
35546
- rootQuery,
35547
35722
  view,
35548
35723
  viewDef
35549
35724
  }) {
@@ -35554,24 +35729,24 @@ function Operations({
35554
35729
  const orderBys = [];
35555
35730
  const nests = [];
35556
35731
  let limit;
35557
- if (!(viewDef instanceof QB.ASTSegmentViewDefinition)) {
35732
+ if (!(viewDef instanceof malloyQueryBuilder.ASTSegmentViewDefinition)) {
35558
35733
  return null;
35559
35734
  }
35560
35735
  const segment = viewDef;
35561
35736
  segment.operations.items.forEach((operation) => {
35562
- if (operation instanceof QB.ASTGroupByViewOperation) {
35737
+ if (operation instanceof malloyQueryBuilder.ASTGroupByViewOperation) {
35563
35738
  groupBys.push(operation);
35564
- } else if (operation instanceof QB.ASTAggregateViewOperation) {
35739
+ } else if (operation instanceof malloyQueryBuilder.ASTAggregateViewOperation || operation instanceof malloyQueryBuilder.ASTCalculateViewOperation) {
35565
35740
  aggregates.push(operation);
35566
- } else if (operation instanceof QB.ASTWhereViewOperation) {
35741
+ } else if (operation instanceof malloyQueryBuilder.ASTWhereViewOperation) {
35567
35742
  filters.push(operation);
35568
- } else if (operation instanceof QB.ASTHavingViewOperation) {
35743
+ } else if (operation instanceof malloyQueryBuilder.ASTHavingViewOperation) {
35569
35744
  filters.push(operation);
35570
- } else if (operation instanceof QB.ASTOrderByViewOperation) {
35745
+ } else if (operation instanceof malloyQueryBuilder.ASTOrderByViewOperation) {
35571
35746
  orderBys.push(operation);
35572
- } else if (operation instanceof QB.ASTNestViewOperation) {
35747
+ } else if (operation instanceof malloyQueryBuilder.ASTNestViewOperation) {
35573
35748
  nests.push(operation);
35574
- } else if (operation instanceof QB.ASTDrillViewOperation) {
35749
+ } else if (operation instanceof malloyQueryBuilder.ASTDrillViewOperation) {
35575
35750
  drills.push(operation);
35576
35751
  } else {
35577
35752
  limit = operation;
@@ -35582,66 +35757,53 @@ function Operations({
35582
35757
  className: "mly1tpqehw mly10lvyaf"
35583
35758
  },
35584
35759
  children: [/* @__PURE__ */ jsxRuntime.jsx(GroupByOperations, {
35585
- rootQuery,
35586
35760
  segment,
35587
35761
  view,
35588
35762
  groupBys
35589
35763
  }), /* @__PURE__ */ jsxRuntime.jsx(AggregateOperations, {
35590
- rootQuery,
35591
35764
  segment,
35592
35765
  view,
35593
35766
  aggregates
35594
35767
  }), /* @__PURE__ */ jsxRuntime.jsx(DrillOperations, {
35595
- rootQuery,
35596
35768
  drills
35597
35769
  }), /* @__PURE__ */ jsxRuntime.jsx(FilterOperations, {
35598
- rootQuery,
35599
35770
  filters
35600
35771
  }), /* @__PURE__ */ jsxRuntime.jsx(OrderByOperations, {
35601
- rootQuery,
35602
35772
  orderBys
35603
35773
  }), /* @__PURE__ */ jsxRuntime.jsx(NestOperations, {
35604
- rootQuery,
35605
35774
  view,
35606
35775
  nests
35607
35776
  }), /* @__PURE__ */ jsxRuntime.jsx(LimitOperation, {
35608
- rootQuery,
35609
35777
  limit
35610
35778
  })]
35611
35779
  });
35612
35780
  }
35613
35781
  function ViewDefinition({
35614
- rootQuery,
35615
35782
  view,
35616
35783
  viewDef
35617
35784
  }) {
35618
- if (viewDef instanceof QB.ASTArrowViewDefinition) {
35785
+ if (viewDef instanceof malloyQueryBuilder.ASTArrowViewDefinition) {
35619
35786
  return /* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
35620
- rootQuery,
35621
35787
  view,
35622
35788
  viewDef: viewDef.view
35623
35789
  });
35624
- } else if (viewDef instanceof QB.ASTRefinementViewDefinition) {
35790
+ } else if (viewDef instanceof malloyQueryBuilder.ASTRefinementViewDefinition) {
35625
35791
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
35626
35792
  children: [/* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
35627
- rootQuery,
35628
35793
  view,
35629
35794
  viewDef: viewDef.base
35630
35795
  }), /* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
35631
- rootQuery,
35632
35796
  view,
35633
35797
  viewDef: viewDef.refinement
35634
35798
  })]
35635
35799
  });
35636
- } else if (viewDef instanceof QB.ASTSegmentViewDefinition) {
35800
+ } else if (viewDef instanceof malloyQueryBuilder.ASTSegmentViewDefinition) {
35637
35801
  return /* @__PURE__ */ jsxRuntime.jsx(Operations, {
35638
- rootQuery,
35639
35802
  view,
35640
35803
  viewDef
35641
35804
  });
35642
35805
  } else {
35643
35806
  return /* @__PURE__ */ jsxRuntime.jsx(CollapsingView, {
35644
- rootQuery,
35645
35807
  viewDef
35646
35808
  });
35647
35809
  }
@@ -35710,14 +35872,21 @@ const styles$c = {
35710
35872
  }
35711
35873
  };
35712
35874
  function Query({
35713
- rootQuery,
35714
- query,
35715
- setQuery
35875
+ definition
35716
35876
  }) {
35717
35877
  const {
35718
35878
  focusMainView,
35719
35879
  isMainViewFocused
35720
35880
  } = useQueryFocus();
35881
+ const {
35882
+ rootQuery,
35883
+ setQuery
35884
+ } = React.useContext(QueryEditorContext);
35885
+ const updateQuery = useUpdateQuery();
35886
+ if (!rootQuery) {
35887
+ return null;
35888
+ }
35889
+ const isEmpty = rootQuery.isEmpty();
35721
35890
  return /* @__PURE__ */ jsxRuntime.jsx(FocusableView, {
35722
35891
  children: /* @__PURE__ */ jsxRuntime.jsxs(CollapsiblePanel, {
35723
35892
  title: "Main query",
@@ -35736,44 +35905,41 @@ function Query({
35736
35905
  label: "Clear query",
35737
35906
  onClick: () => {
35738
35907
  focusMainView();
35739
- setQuery == null ? void 0 : setQuery(void 0);
35908
+ setQuery(void 0);
35740
35909
  },
35741
- disabled: rootQuery.isEmpty()
35910
+ disabled: isEmpty
35742
35911
  }), /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, {
35743
35912
  icon: "nest",
35744
35913
  label: "Nest query",
35745
35914
  onClick: () => {
35746
- if (rootQuery.definition instanceof QB.ASTArrowQueryDefinition) {
35747
- rootQuery.definition.view.convertToNest("Nest");
35915
+ if (definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition) {
35916
+ definition.view.convertToNest("Nest");
35748
35917
  }
35749
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35918
+ updateQuery();
35750
35919
  },
35751
- disabled: rootQuery.isEmpty() || !(rootQuery.definition instanceof QB.ASTArrowQueryDefinition)
35920
+ disabled: isEmpty || !(definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition)
35752
35921
  })]
35753
35922
  }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {})
35754
- }), query.definition instanceof QB.ASTArrowQueryDefinition ? /* @__PURE__ */ jsxRuntime.jsx(AddMenu, {
35755
- rootQuery,
35756
- view: query.definition
35923
+ }), definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition ? /* @__PURE__ */ jsxRuntime.jsx(AddMenu, {
35924
+ view: definition
35757
35925
  }) : null]
35758
35926
  }),
35759
35927
  collapsedControls: /* @__PURE__ */ jsxRuntime.jsx(Icon, {
35760
- name: viewToVisualizationIcon(query)
35928
+ name: tagToVisualization(rootQuery.getTag())
35761
35929
  }),
35762
- children: [query.definition instanceof QB.ASTArrowQueryDefinition ? /* @__PURE__ */ jsxRuntime.jsxs("div", {
35930
+ children: [definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition ? /* @__PURE__ */ jsxRuntime.jsxs("div", {
35763
35931
  style: {
35764
35932
  display: "flex",
35765
35933
  flexDirection: "column",
35766
35934
  gap: 8
35767
35935
  },
35768
- children: [!query.isEmpty() && /* @__PURE__ */ jsxRuntime.jsx(Visualization$1, {
35769
- rootQuery,
35770
- view: query
35936
+ children: [!isEmpty && /* @__PURE__ */ jsxRuntime.jsx(Visualization$1, {
35937
+ view: rootQuery
35771
35938
  }), /* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
35772
- rootQuery,
35773
- view: query.definition,
35774
- viewDef: query.definition.view
35939
+ view: definition,
35940
+ viewDef: definition.view
35775
35941
  })]
35776
- }) : null, query.isEmpty() ? /* @__PURE__ */ jsxRuntime.jsx("div", {
35942
+ }) : null, isEmpty ? /* @__PURE__ */ jsxRuntime.jsx("div", {
35777
35943
  ...{
35778
35944
  className: "mly78zum5 mlyl56j7k mly6s0dn4 mlyng8ra"
35779
35945
  },
@@ -35795,9 +35961,9 @@ function Query({
35795
35961
  });
35796
35962
  }
35797
35963
  function Source({
35798
- rootQuery
35964
+ definition
35799
35965
  }) {
35800
- if (rootQuery.definition instanceof QB.ASTArrowQueryDefinition) {
35966
+ if (definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition) {
35801
35967
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
35802
35968
  ..._stylex.props(styles$u.queryCard, styles$b.content),
35803
35969
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -35808,7 +35974,7 @@ function Source({
35808
35974
  ...{
35809
35975
  className: "mlyb3r6kr mlylyipyv mly117nqv4"
35810
35976
  },
35811
- children: rootQuery.definition.as.ArrowQueryDefinition().source.as.ReferenceQueryArrowSource().name
35977
+ children: definition.source.getSourceInfo().name
35812
35978
  })]
35813
35979
  })
35814
35980
  });
@@ -36145,13 +36311,13 @@ function LiteralValueEditor({
36145
36311
  }
36146
36312
  }
36147
36313
  function Parameters({
36148
- rootQuery
36314
+ definition
36149
36315
  }) {
36150
- const {
36151
- setQuery
36152
- } = React.useContext(QueryEditorContext);
36153
- if (rootQuery.definition instanceof QB.ASTArrowQueryDefinition) {
36154
- const source = rootQuery.definition.as.ArrowQueryDefinition().source.as.ReferenceQueryArrowSource();
36316
+ const updateQuery = useUpdateQuery();
36317
+ if (definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition && definition.source instanceof malloyQueryBuilder.ASTReferenceQueryArrowSource) {
36318
+ const {
36319
+ source
36320
+ } = definition;
36155
36321
  const sourceParameters = source.getSourceParameters();
36156
36322
  if (!sourceParameters || sourceParameters.length === 0) {
36157
36323
  return null;
@@ -36174,7 +36340,7 @@ function Parameters({
36174
36340
  value: ((_a2 = source.tryGetParameter(parameter.name)) == null ? void 0 : _a2.parameter.value) ?? parameter.default_value,
36175
36341
  setValue: (value) => {
36176
36342
  source.setParameter(parameter.name, value);
36177
- setQuery == null ? void 0 : setQuery(rootQuery.build());
36343
+ updateQuery();
36178
36344
  }
36179
36345
  })]
36180
36346
  }, parameter.name);
@@ -36192,23 +36358,23 @@ const styles$9 = {
36192
36358
  };
36193
36359
  function QueryEditor() {
36194
36360
  const {
36195
- rootQuery,
36196
- setQuery
36361
+ rootQuery
36197
36362
  } = React.useContext(QueryEditorContext);
36198
36363
  if (!rootQuery) {
36199
36364
  console.error("Missing <MalloyExplorerProvider>");
36200
36365
  return null;
36201
36366
  }
36367
+ const {
36368
+ definition
36369
+ } = rootQuery;
36202
36370
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
36203
36371
  ..._stylex.props(fontStyles.body, styles$8.main),
36204
36372
  children: [/* @__PURE__ */ jsxRuntime.jsx(Source, {
36205
- rootQuery
36373
+ definition
36206
36374
  }), /* @__PURE__ */ jsxRuntime.jsx(Parameters, {
36207
- rootQuery
36375
+ definition
36208
36376
  }), /* @__PURE__ */ jsxRuntime.jsx(Query, {
36209
- rootQuery,
36210
- query: rootQuery,
36211
- setQuery
36377
+ definition
36212
36378
  })]
36213
36379
  });
36214
36380
  }
@@ -36747,11 +36913,11 @@ function RenderedResult({
36747
36913
  const {
36748
36914
  stableQuery
36749
36915
  } = drillData;
36750
- const rootQuery = new QB.ASTQuery({
36916
+ const rootQuery = new malloyQueryBuilder.ASTQuery({
36751
36917
  query: stableQuery,
36752
36918
  source
36753
36919
  });
36754
- setQuery == null ? void 0 : setQuery(rootQuery.build());
36920
+ setQuery(rootQuery.build());
36755
36921
  },
36756
36922
  tableConfig: {
36757
36923
  enableDrill: true
@@ -37332,27 +37498,21 @@ function useOperations(view, field, path) {
37332
37498
  return "";
37333
37499
  }, [matchingFieldItem, view, path, field.name, fullName]);
37334
37500
  return {
37335
- isGroupByAllowed: !groupByDisabledReason,
37336
37501
  groupByDisabledReason,
37337
- isAggregateAllowed: !aggregateDisabledReason,
37338
37502
  aggregateDisabledReason,
37339
- isFilterAllowed: !filterDisabledReason,
37340
37503
  filterDisabledReason,
37341
- isOrderByAllowed: !orderByDisabledReason,
37342
37504
  orderByDisabledReason
37343
37505
  };
37344
37506
  }
37345
37507
  const FILTERABLE_TYPES = ["string_type", "boolean_type", "number_type", "date_type", "timestamp_type"];
37346
37508
  const ORDERABLE_TYPES = ["string_type", "number_type", "boolean_type", "date_type", "timestamp_type"];
37347
37509
  function FieldTokenWithActions({
37510
+ rootQuery,
37348
37511
  field,
37349
37512
  path,
37350
37513
  viewDef
37351
37514
  }) {
37352
- const {
37353
- rootQuery,
37354
- setQuery
37355
- } = React.useContext(QueryEditorContext);
37515
+ const updateQuery = useUpdateQuery();
37356
37516
  const {
37357
37517
  focusedNestView
37358
37518
  } = useQueryFocus();
@@ -37376,19 +37536,19 @@ function FieldTokenWithActions({
37376
37536
  } else if (operation === "filter" && !filterDisabledReason && filter) {
37377
37537
  addFilter(view, field, path, filter);
37378
37538
  }
37379
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
37539
+ updateQuery();
37380
37540
  }
37381
37541
  };
37382
37542
  const handleSetView = () => {
37383
- if (field.kind === "view" && (rootQuery == null ? void 0 : rootQuery.isEmpty())) {
37384
- rootQuery == null ? void 0 : rootQuery.setView(field.name);
37385
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
37543
+ if (field.kind === "view" && rootQuery.isEmpty()) {
37544
+ rootQuery.setView(field.name);
37545
+ updateQuery();
37386
37546
  }
37387
37547
  };
37388
37548
  const handleAddView = () => {
37389
37549
  if (field.kind === "view") {
37390
37550
  addNest(view, field);
37391
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
37551
+ updateQuery();
37392
37552
  }
37393
37553
  };
37394
37554
  return /* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
@@ -37396,9 +37556,9 @@ function FieldTokenWithActions({
37396
37556
  hoverActions: field.kind === "view" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
37397
37557
  children: [/* @__PURE__ */ jsxRuntime.jsx(ActionButton, {
37398
37558
  icon: "insert",
37399
- disabled: !(rootQuery == null ? void 0 : rootQuery.isEmpty()),
37559
+ disabled: !rootQuery.isEmpty(),
37400
37560
  onClick: handleSetView,
37401
- tooltip: !(rootQuery == null ? void 0 : rootQuery.isEmpty()) ? "Can only add a view to an empty query." : "Add view",
37561
+ tooltip: !rootQuery.isEmpty() ? "Can only add a view to an empty query." : "Add view",
37402
37562
  onTooltipOpenChange: setIsTooltipOpen
37403
37563
  }), /* @__PURE__ */ jsxRuntime.jsx(ActionButton, {
37404
37564
  icon: "nest",
@@ -37464,7 +37624,7 @@ function FieldTokenWithActions({
37464
37624
  })]
37465
37625
  }) : null,
37466
37626
  onClick: field.kind === "dimension" && !groupByDisabledReason ? () => handleAddOperationAction("groupBy") : field.kind === "measure" && !aggregateDisabledReason ? () => handleAddOperationAction("aggregate") : field.kind === "view" ? () => {
37467
- if (rootQuery == null ? void 0 : rootQuery.isEmpty()) {
37627
+ if (rootQuery.isEmpty()) {
37468
37628
  handleSetView();
37469
37629
  } else {
37470
37630
  handleAddView();
@@ -37508,6 +37668,7 @@ function ActionButton({
37508
37668
  }
37509
37669
  const FIELD_KIND_ORDER = ["dimension", "measure", "view"];
37510
37670
  function SearchResultList({
37671
+ rootQuery,
37511
37672
  source,
37512
37673
  items
37513
37674
  }) {
@@ -37517,11 +37678,8 @@ function SearchResultList({
37517
37678
  items: groupFieldItemsByPath(source, group.items)
37518
37679
  }));
37519
37680
  }, [source, items]);
37520
- const {
37521
- rootQuery
37522
- } = React__namespace.useContext(QueryEditorContext);
37523
- const viewDef = rootQuery == null ? void 0 : rootQuery.definition;
37524
- if (!(viewDef instanceof QB.ASTArrowQueryDefinition)) {
37681
+ const viewDef = rootQuery.definition;
37682
+ if (!(viewDef instanceof malloyQueryBuilder.ASTArrowQueryDefinition)) {
37525
37683
  return null;
37526
37684
  }
37527
37685
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -37557,6 +37715,7 @@ function SearchResultList({
37557
37715
  field,
37558
37716
  path
37559
37717
  }) => /* @__PURE__ */ jsxRuntime.jsx(FieldTokenWithActions, {
37718
+ rootQuery,
37560
37719
  field,
37561
37720
  path,
37562
37721
  viewDef
@@ -37583,6 +37742,7 @@ const getSublabelFromPath = (source, path) => {
37583
37742
  return path.length > 0 ? `joined to ${[...path.slice(0, -1), source.name].join(" > ")}` : void 0;
37584
37743
  };
37585
37744
  function FieldGroupList({
37745
+ rootQuery,
37586
37746
  source,
37587
37747
  fieldItems,
37588
37748
  fieldGroupType
@@ -37602,11 +37762,8 @@ function FieldGroupList({
37602
37762
  group
37603
37763
  }) => group === fieldGroupType)) == null ? void 0 : _a2.items) ?? [];
37604
37764
  }, [fieldGroupsByKindByPath, fieldGroupType]);
37605
- const {
37606
- rootQuery
37607
- } = React__namespace.useContext(QueryEditorContext);
37608
- const viewDef = rootQuery == null ? void 0 : rootQuery.definition;
37609
- if (!(viewDef instanceof QB.ASTArrowQueryDefinition)) {
37765
+ const viewDef = rootQuery.definition;
37766
+ if (!(viewDef instanceof malloyQueryBuilder.ASTArrowQueryDefinition)) {
37610
37767
  return null;
37611
37768
  }
37612
37769
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -37622,6 +37779,7 @@ function FieldGroupList({
37622
37779
  field,
37623
37780
  path
37624
37781
  }) => /* @__PURE__ */ jsxRuntime.jsx(FieldTokenWithActions, {
37782
+ rootQuery,
37625
37783
  field,
37626
37784
  path,
37627
37785
  viewDef
@@ -37634,7 +37792,8 @@ function SourcePanel({
37634
37792
  onRefresh
37635
37793
  }) {
37636
37794
  const {
37637
- source
37795
+ source,
37796
+ rootQuery
37638
37797
  } = React__namespace.useContext(QueryEditorContext);
37639
37798
  const [searchQuery, setSearchQuery] = React__namespace.useState("");
37640
37799
  const {
@@ -37657,7 +37816,7 @@ function SourcePanel({
37657
37816
  return [];
37658
37817
  }, [fieldItems, searchQuery]);
37659
37818
  const isSearchActive = !!searchQuery;
37660
- if (!source) {
37819
+ if (!source || !rootQuery) {
37661
37820
  return null;
37662
37821
  }
37663
37822
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -37712,6 +37871,7 @@ function SourcePanel({
37712
37871
  className: "mly78zum5 mlydt5ytf mlyysyzu8 mly1iyjqo2"
37713
37872
  },
37714
37873
  children: isSearchActive ? /* @__PURE__ */ jsxRuntime.jsx(SearchResultList, {
37874
+ rootQuery,
37715
37875
  source,
37716
37876
  items: searchResultItems
37717
37877
  }) : /* @__PURE__ */ jsxRuntime.jsxs(AccordionList, {
@@ -37728,6 +37888,7 @@ function SourcePanel({
37728
37888
  color: "cyan"
37729
37889
  }),
37730
37890
  children: /* @__PURE__ */ jsxRuntime.jsx(FieldGroupList, {
37891
+ rootQuery,
37731
37892
  source,
37732
37893
  fieldItems,
37733
37894
  fieldGroupType: "dimension"
@@ -37744,6 +37905,7 @@ function SourcePanel({
37744
37905
  color: "green"
37745
37906
  }),
37746
37907
  children: /* @__PURE__ */ jsxRuntime.jsx(FieldGroupList, {
37908
+ rootQuery,
37747
37909
  source,
37748
37910
  fieldItems,
37749
37911
  fieldGroupType: "measure"
@@ -37760,6 +37922,7 @@ function SourcePanel({
37760
37922
  color: "purple"
37761
37923
  }),
37762
37924
  children: /* @__PURE__ */ jsxRuntime.jsx(FieldGroupList, {
37925
+ rootQuery,
37763
37926
  source,
37764
37927
  fieldItems,
37765
37928
  fieldGroupType: "view"