@malloydata/malloy-explorer 0.0.294-dev250630221944 → 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 (57) hide show
  1. package/.gitmodules +3 -0
  2. package/@flowtypes/components/MalloyExplorerProvider.flow.js +3 -6
  3. package/README.md +7 -0
  4. package/dist/cjs/index.cjs +553 -356
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/esm/index.js +523 -326
  7. package/dist/esm/index.js.map +1 -1
  8. package/dist/malloy-explorer.css +2 -0
  9. package/dist/types/components/FieldToken.d.ts +5 -1
  10. package/dist/types/components/MalloyExplorerProvider.d.ts +3 -5
  11. package/dist/types/components/QueryPanel/AddMenu/AddAggregate.d.ts +1 -3
  12. package/dist/types/components/QueryPanel/AddMenu/AddEmptyNest.d.ts +1 -3
  13. package/dist/types/components/QueryPanel/AddMenu/AddGroupBy.d.ts +1 -3
  14. package/dist/types/components/QueryPanel/AddMenu/AddLimit.d.ts +1 -3
  15. package/dist/types/components/QueryPanel/AddMenu/AddMenu.d.ts +1 -3
  16. package/dist/types/components/QueryPanel/AddMenu/AddOrderBy.d.ts +1 -3
  17. package/dist/types/components/QueryPanel/AddMenu/AddView.d.ts +1 -3
  18. package/dist/types/components/QueryPanel/AddMenu/AddWhere.d.ts +0 -2
  19. package/dist/types/components/QueryPanel/AddMenu/ValueList.d.ts +2 -1
  20. package/dist/types/components/QueryPanel/Operations.d.ts +2 -3
  21. package/dist/types/components/QueryPanel/Parameters.d.ts +3 -3
  22. package/dist/types/components/QueryPanel/Query.d.ts +3 -4
  23. package/dist/types/components/QueryPanel/Source.d.ts +3 -3
  24. package/dist/types/components/QueryPanel/View.d.ts +2 -3
  25. package/dist/types/components/QueryPanel/ViewDefinition.d.ts +2 -3
  26. package/dist/types/components/QueryPanel/Visualization.d.ts +1 -2
  27. package/dist/types/components/QueryPanel/VizEditor/VizEditor.d.ts +1 -2
  28. package/dist/types/components/QueryPanel/VizEditor/VizEditorDialog.d.ts +1 -2
  29. package/dist/types/components/QueryPanel/VizEditor/VizEditorPopover.d.ts +1 -2
  30. package/dist/types/components/QueryPanel/VizEditor/styles.d.ts +3 -0
  31. package/dist/types/components/QueryPanel/VizEditor/utils.d.ts +3 -0
  32. package/dist/types/components/QueryPanel/operations/AggregateOperations.d.ts +3 -4
  33. package/dist/types/components/QueryPanel/operations/DrillOperations.d.ts +1 -2
  34. package/dist/types/components/QueryPanel/operations/FilterOperations.d.ts +2 -3
  35. package/dist/types/components/QueryPanel/operations/GroupByOperations.d.ts +2 -3
  36. package/dist/types/components/QueryPanel/operations/LimitOperation.d.ts +2 -3
  37. package/dist/types/components/QueryPanel/operations/NestOperation.d.ts +3 -5
  38. package/dist/types/components/QueryPanel/operations/OperationActionTitle.d.ts +0 -2
  39. package/dist/types/components/QueryPanel/operations/OrderByOperations.d.ts +2 -3
  40. package/dist/types/components/QueryPanel/operations/RenameDialog.d.ts +3 -4
  41. package/dist/types/components/QueryPanel/operations/SortableOperations.d.ts +3 -4
  42. package/dist/types/components/ResultPanel/ResultDisplay.d.ts +0 -4
  43. package/dist/types/components/SourcePanel/FieldGroupList.d.ts +3 -1
  44. package/dist/types/components/SourcePanel/FieldTokenWithActions.d.ts +3 -2
  45. package/dist/types/components/SourcePanel/SearchResultList.d.ts +3 -1
  46. package/dist/types/components/SourcePanel/hooks/useOperations.d.ts +0 -4
  47. package/dist/types/components/primitives/DropdownMenu.d.ts +1 -1
  48. package/dist/types/components/utils/axis.d.ts +10 -0
  49. package/dist/types/components/utils/icon.d.ts +3 -3
  50. package/dist/types/components/utils/segment.d.ts +1 -0
  51. package/dist/types/contexts/QueryEditorContext.d.ts +3 -14
  52. package/dist/types/hooks/useQueryBuilder.d.ts +2 -2
  53. package/dist/types/hooks/useQueryUpdate.d.ts +10 -0
  54. package/dist/types/hooks/useTopValues.d.ts +18 -0
  55. package/jest.config.ts +1 -1
  56. package/package.json +8 -6
  57. package/vite.config.mts +5 -0
@@ -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
  });
@@ -8010,16 +8043,14 @@ function SelectorToken({
8010
8043
  onValueChange: handleValueChange,
8011
8044
  required: true,
8012
8045
  children: [/* @__PURE__ */ jsxRuntime.jsxs(Trigger$3, {
8013
- ..._stylex.props(tokenStyles.main, styles$H.selectTrigger, tokenColorVariants[color], tokenSizeVariants[size2], fontStyles.body, tokenStyles.label, customStyle),
8046
+ ..._stylex.props(tokenStyles.main, styles$H.selectTrigger, tokenColorVariants[color], tokenSizeVariants[size2], customStyle),
8014
8047
  children: [icon && /* @__PURE__ */ jsxRuntime.jsx(Icon, {
8015
8048
  name: icon,
8016
8049
  customStyle: tokenStyles.icon
8017
8050
  }), /* @__PURE__ */ jsxRuntime.jsx(Value$1, {
8018
8051
  asChild: true,
8019
8052
  children: /* @__PURE__ */ jsxRuntime.jsx("div", {
8020
- ...{
8021
- className: "mlyb3r6kr mlylyipyv"
8022
- },
8053
+ ..._stylex.props(fontStyles.body, tokenStyles.label),
8023
8054
  children: label
8024
8055
  })
8025
8056
  })]
@@ -8048,17 +8079,15 @@ function SelectorToken({
8048
8079
  }, 10);
8049
8080
  }
8050
8081
  }
8051
- }), /* @__PURE__ */ jsxRuntime.jsx(ScrollableArea, {
8052
- children: /* @__PURE__ */ jsxRuntime.jsx(Group$1, {
8053
- ...{
8054
- className: "mly78zum5 mlydt5ytf mlyuyqlj2 mlyfawy5m mly195vfkc"
8055
- },
8056
- children: filteredItems.map((item) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, {
8057
- value: item.value,
8058
- selectedValue: value,
8059
- children: item.label
8060
- }, item.value))
8061
- })
8082
+ }), /* @__PURE__ */ jsxRuntime.jsx(Group$1, {
8083
+ ...{
8084
+ className: "mly78zum5 mlydt5ytf mlyuyqlj2 mlyfawy5m mly195vfkc mlyysyzu8"
8085
+ },
8086
+ children: filteredItems.map((item) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, {
8087
+ value: item.value,
8088
+ selectedValue: value,
8089
+ children: item.label
8090
+ }, item.value))
8062
8091
  })]
8063
8092
  })
8064
8093
  })
@@ -26008,9 +26037,9 @@ function QueryActionBar({
26008
26037
  children: [/* @__PURE__ */ jsxRuntime.jsx(Button, {
26009
26038
  onClick: () => {
26010
26039
  focusMainView();
26011
- setQuery == null ? void 0 : setQuery(void 0);
26040
+ setQuery(void 0);
26012
26041
  },
26013
- isDisabled: !rootQuery || (rootQuery == null ? void 0 : rootQuery.isEmpty()),
26042
+ isDisabled: !rootQuery || rootQuery.isEmpty(),
26014
26043
  label: "Clear",
26015
26044
  variant: "flat",
26016
26045
  size: "compact"
@@ -26220,6 +26249,7 @@ function fieldToIcon(field) {
26220
26249
  break;
26221
26250
  case "dimension":
26222
26251
  case "measure":
26252
+ case "calculate":
26223
26253
  icon = atomicTypeToIcon(field.type.kind);
26224
26254
  break;
26225
26255
  case "join":
@@ -26231,8 +26261,7 @@ function fieldToIcon(field) {
26231
26261
  function relationshipToIcon(relationship) {
26232
26262
  return relationshipMap[relationship];
26233
26263
  }
26234
- function viewToVisualizationIcon(view) {
26235
- const currentTag = view.getTag();
26264
+ function tagToVisualization(currentTag) {
26236
26265
  const currentRenderer = tagToRenderer(currentTag) ?? "table";
26237
26266
  return `viz_${currentRenderer}`;
26238
26267
  }
@@ -26252,6 +26281,7 @@ const fieldKindMap = {
26252
26281
  view: "purple",
26253
26282
  dimension: "cyan",
26254
26283
  measure: "green",
26284
+ calculate: "green",
26255
26285
  join: void 0
26256
26286
  };
26257
26287
  const relationshipMap = {
@@ -26261,6 +26291,7 @@ const relationshipMap = {
26261
26291
  };
26262
26292
  function FieldToken({
26263
26293
  field,
26294
+ additionalSiblings,
26264
26295
  hoverActions,
26265
26296
  hoverActionsVisible,
26266
26297
  ...props2
@@ -26285,7 +26316,7 @@ function FieldToken({
26285
26316
  color: fieldKindToColor(field.kind),
26286
26317
  icon: fieldToIcon(field),
26287
26318
  ...props2
26288
- }), hoverActions && /* @__PURE__ */ jsxRuntime.jsx("div", {
26319
+ }), additionalSiblings, hoverActions && /* @__PURE__ */ jsxRuntime.jsx("div", {
26289
26320
  ...{
26290
26321
  className: "mly1vsucm1 mly2lah0s"
26291
26322
  },
@@ -26307,19 +26338,22 @@ function DrillOperations({
26307
26338
  ...{
26308
26339
  className: "mly78zum5 mlydt5ytf mly1jnr06f"
26309
26340
  },
26310
- children: drills.map((drill, key2) => /* @__PURE__ */ jsxRuntime.jsxs(TokenGroup, {
26311
- color: "cyan",
26312
- customStyle: localStyles.tokenGroup,
26313
- children: [/* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
26314
- field: drill.filter.fieldReference.getFieldInfo()
26315
- }), /* @__PURE__ */ jsxRuntime.jsx(Token, {
26316
- label: "="
26317
- }), drill.filter instanceof QB.ASTFilterWithLiteralEquality ? /* @__PURE__ */ jsxRuntime.jsx(LiteralValue, {
26318
- value: drill.filter.value.node
26319
- }) : /* @__PURE__ */ jsxRuntime.jsx(Token, {
26320
- label: drill.filter.filterString
26321
- })]
26322
- }, key2))
26341
+ children: drills.map((drill, key2) => {
26342
+ const field = drill.filter.expression.getFieldInfo();
26343
+ return field ? /* @__PURE__ */ jsxRuntime.jsxs(TokenGroup, {
26344
+ color: "cyan",
26345
+ customStyle: localStyles.tokenGroup,
26346
+ children: [/* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
26347
+ field
26348
+ }), /* @__PURE__ */ jsxRuntime.jsx(Token, {
26349
+ label: "="
26350
+ }), drill.filter instanceof malloyQueryBuilder.ASTFilterWithLiteralEquality ? /* @__PURE__ */ jsxRuntime.jsx(LiteralValue, {
26351
+ value: drill.filter.value.node
26352
+ }) : /* @__PURE__ */ jsxRuntime.jsx(Token, {
26353
+ label: drill.filter.filterString
26354
+ })]
26355
+ }, key2) : null;
26356
+ })
26323
26357
  })]
26324
26358
  });
26325
26359
  }
@@ -30231,7 +30265,7 @@ function isIndexView(field) {
30231
30265
  return allFields.size === INDEX_FIELDS.length;
30232
30266
  }
30233
30267
  function getViewDefinition(parent) {
30234
- return parent instanceof QB.ASTArrowQueryDefinition ? parent.view : parent.definition;
30268
+ return parent instanceof malloyQueryBuilder.ASTArrowQueryDefinition ? parent.view : parent.definition;
30235
30269
  }
30236
30270
  function getInputSchemaFromViewParent(parent) {
30237
30271
  if (!parent) {
@@ -30618,6 +30652,12 @@ const styles$s = {
30618
30652
  justifyContent: "mly1rfj78v",
30619
30653
  $$css: true
30620
30654
  },
30655
+ nest: {
30656
+ gridColumn: "mly623te4",
30657
+ gridColumnStart: null,
30658
+ gridColumnEnd: null,
30659
+ $$css: true
30660
+ },
30621
30661
  heading: {
30622
30662
  gridColumn: "mly623te4",
30623
30663
  gridColumnStart: null,
@@ -31130,6 +31170,20 @@ const colorVariants = {
31130
31170
  $$css: true
31131
31171
  }
31132
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
+ }
31133
31187
  function OneOfEditor({
31134
31188
  view,
31135
31189
  name,
@@ -31175,6 +31229,15 @@ function OneOfEditor({
31175
31229
  current,
31176
31230
  option: subOption
31177
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);
31178
31241
  }
31179
31242
  return null;
31180
31243
  })]
@@ -31284,7 +31347,7 @@ function OneOfNumberEditor({
31284
31347
  valueAsNumber
31285
31348
  }
31286
31349
  }) => {
31287
- setValue(value);
31350
+ setValue(valueAsNumber);
31288
31351
  updateCurrent(path, valueAsNumber);
31289
31352
  },
31290
31353
  ..._stylex.props(styles$s.input)
@@ -31323,6 +31386,48 @@ function OneOfArrayEditor({
31323
31386
  }), /* @__PURE__ */ jsxRuntime.jsx("div", {})]
31324
31387
  });
31325
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
+ }
31326
31431
  function ArrayEditor({
31327
31432
  name,
31328
31433
  path,
@@ -31353,6 +31458,7 @@ function NumberEditor$1({
31353
31458
  option: option2,
31354
31459
  updateCurrent
31355
31460
  }) {
31461
+ const [value, setValue] = React__namespace.useState(current ?? option2.minimum);
31356
31462
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
31357
31463
  children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
31358
31464
  ..._stylex.props(styles$s.left, styles$s.label),
@@ -31360,7 +31466,7 @@ function NumberEditor$1({
31360
31466
  children: [option2.title ?? name, ":"]
31361
31467
  })
31362
31468
  }), /* @__PURE__ */ jsxRuntime.jsx("input", {
31363
- value: current,
31469
+ value,
31364
31470
  type: "number",
31365
31471
  min: option2.minimum,
31366
31472
  max: option2.maximum,
@@ -31369,6 +31475,7 @@ function NumberEditor$1({
31369
31475
  valueAsNumber
31370
31476
  }
31371
31477
  }) => {
31478
+ setValue(valueAsNumber);
31372
31479
  updateCurrent(path, valueAsNumber);
31373
31480
  },
31374
31481
  ..._stylex.props(styles$s.input)
@@ -31567,11 +31674,12 @@ function ObjectEditor({
31567
31674
  option: option2,
31568
31675
  updateCurrent
31569
31676
  }) {
31570
- const [isExpanded, setIsExpanded] = React.useState(path.length === 0);
31677
+ const [isExpanded, setIsExpanded] = React.useState(path.length === 0 || !name);
31571
31678
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
31572
31679
  children: [name ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
31573
31680
  children: [/* @__PURE__ */ jsxRuntime.jsxs("div", {
31574
31681
  ..._stylex.props(styles$s.label, styles$s.heading),
31682
+ onClick: () => setIsExpanded(!isExpanded),
31575
31683
  children: [/* @__PURE__ */ jsxRuntime.jsx("label", {
31576
31684
  children: option2.title ?? name
31577
31685
  }), option2.description ? /* @__PURE__ */ jsxRuntime.jsx(InfoHover, {
@@ -31663,31 +31771,20 @@ function ObjectEditor({
31663
31771
  });
31664
31772
  }
31665
31773
  function VizEditor({
31666
- rootQuery,
31667
31774
  view,
31668
31775
  plugin,
31669
31776
  setOpen
31670
31777
  }) {
31671
- const {
31672
- setQuery
31673
- } = React.useContext(QueryEditorContext);
31778
+ const updateQuery = useUpdateQuery();
31674
31779
  const [current, setCurrent] = React.useState(plugin.getSettings());
31675
- console.info("RendererEditor current settings:", current);
31676
31780
  const schema = plugin.getSchema();
31677
31781
  const updateCurrent = (path, value) => {
31678
- const newCurrent = {
31679
- ...current
31680
- };
31681
- let target = newCurrent;
31682
- for (let i2 = 0; i2 < path.length - 1; i2++) {
31683
- if (!(path[i2] in target)) {
31684
- target[path[i2]] = {};
31685
- }
31686
- target = target[path[i2]];
31687
- }
31688
- target[path[path.length - 1]] = value;
31782
+ const newCurrent = setAtPath(current, path, value);
31689
31783
  setCurrent(newCurrent);
31690
31784
  };
31785
+ React__namespace.useEffect(() => {
31786
+ console.info("RendererEditor current settings:", current);
31787
+ }, [current]);
31691
31788
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
31692
31789
  ..._stylex.props(styles$s.editor),
31693
31790
  children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -31719,10 +31816,10 @@ function VizEditor({
31719
31816
  if (old) {
31720
31817
  annotations.remove(old);
31721
31818
  }
31722
- view.getOrAddAnnotations().add(new QB.ASTAnnotation({
31819
+ view.getOrAddAnnotations().add(new malloyQueryBuilder.ASTAnnotation({
31723
31820
  value
31724
31821
  }));
31725
- setQuery == null ? void 0 : setQuery(rootQuery.build());
31822
+ updateQuery();
31726
31823
  setOpen(false);
31727
31824
  },
31728
31825
  customStyle: styles$s.editorCell
@@ -31935,7 +32032,6 @@ const dialogStyles = {
31935
32032
  }
31936
32033
  };
31937
32034
  function VizEditorDialog({
31938
- rootQuery,
31939
32035
  plugin,
31940
32036
  view,
31941
32037
  customStyle,
@@ -31965,7 +32061,6 @@ function VizEditorDialog({
31965
32061
  ..._stylex.props(dialogStyles.displayNone),
31966
32062
  children: "Edit visualization parameters"
31967
32063
  }), /* @__PURE__ */ jsxRuntime.jsx(VizEditor, {
31968
- rootQuery,
31969
32064
  view,
31970
32065
  plugin,
31971
32066
  setOpen
@@ -31984,26 +32079,27 @@ const styles$p = {
31984
32079
  }
31985
32080
  };
31986
32081
  function Visualization$1({
31987
- rootQuery,
31988
32082
  view
31989
32083
  }) {
31990
- const {
31991
- setQuery
31992
- } = React.useContext(QueryEditorContext);
32084
+ const updateQuery = useUpdateQuery();
31993
32085
  const renderer = React.useMemo(() => new render.MalloyRenderer(), []);
31994
32086
  const [currentRenderer, setCurrentRenderer] = React.useState("table");
31995
32087
  const [plugin, setPlugin] = React.useState();
32088
+ const [error, setError] = React.useState("");
31996
32089
  const [open, setOpen] = React.useState(false);
32090
+ const tag = view.getTag().toString();
31997
32091
  React.useEffect(() => {
31998
32092
  var _a2;
32093
+ setError("");
31999
32094
  const viz = renderer.createViz({
32000
- onError: (error) => {
32001
- console.error("Malloy render error", error);
32095
+ onError: (error2) => {
32096
+ console.error("Malloy render error", error2);
32097
+ setError(error2.message);
32002
32098
  }
32003
32099
  });
32004
32100
  viz.setResult({
32005
32101
  schema: view.definition.getOutputSchema(),
32006
- annotations: view.getTag().toString().split("\n").map((value) => ({
32102
+ annotations: tag.split("\n").map((value) => ({
32007
32103
  value
32008
32104
  })),
32009
32105
  connection_name: ""
@@ -32011,20 +32107,26 @@ function Visualization$1({
32011
32107
  const metadata = viz.getMetadata();
32012
32108
  if (metadata) {
32013
32109
  const plugin2 = viz.getActivePlugin(metadata.getRootField().key);
32014
- if (plugin2 && render.isCoreVizPluginInstance(plugin2)) {
32015
- setCurrentRenderer(plugin2.name);
32016
- setPlugin(plugin2);
32110
+ if (plugin2) {
32111
+ if (render.isCoreVizPluginInstance(plugin2)) {
32112
+ setCurrentRenderer(plugin2.name);
32113
+ setPlugin(plugin2);
32114
+ return;
32115
+ }
32116
+ if (plugin2.name === "error") {
32117
+ setError(plugin2.getMetadata().message);
32118
+ }
32017
32119
  }
32018
- } else {
32019
- const currentTag = view.getTag();
32020
- const rendererTag = view.getTag(RENDERER_PREFIX);
32021
- const currentRenderer2 = ((_a2 = rendererTag.tag("viz")) == null ? void 0 : _a2.text()) ?? legacyToViz(tagToRenderer(currentTag) ?? "table");
32022
- setCurrentRenderer(currentRenderer2);
32023
32120
  }
32024
- }, [renderer, view]);
32121
+ const currentTag = view.getTag();
32122
+ const rendererTag = view.getTag(RENDERER_PREFIX);
32123
+ const currentRenderer2 = ((_a2 = rendererTag.tag("viz")) == null ? void 0 : _a2.text()) ?? legacyToViz(tagToRenderer(currentTag) ?? "table");
32124
+ setCurrentRenderer(currentRenderer2);
32125
+ setPlugin(void 0);
32126
+ }, [renderer, view, tag]);
32025
32127
  const updateViz = (renderer2) => {
32026
32128
  view.setTagProperty(["viz"], renderer2, RENDERER_PREFIX);
32027
- setQuery == null ? void 0 : setQuery(rootQuery.build());
32129
+ updateQuery();
32028
32130
  };
32029
32131
  const items = VIZ_RENDERERS.map((viz) => ({
32030
32132
  icon: /* @__PURE__ */ jsxRuntime.jsx(Icon, {
@@ -32049,6 +32151,13 @@ function Visualization$1({
32049
32151
  tooltip: "Edit Settings..."
32050
32152
  }, "gear"));
32051
32153
  }
32154
+ if (error) {
32155
+ tokens2.push(/* @__PURE__ */ jsxRuntime.jsx(Token, {
32156
+ icon: "warning",
32157
+ tooltip: error,
32158
+ customStyle: styles$o.trigger
32159
+ }));
32160
+ }
32052
32161
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
32053
32162
  children: [/* @__PURE__ */ jsxRuntime.jsx(TokenGroup, {
32054
32163
  customStyle: styles$o.group,
@@ -32056,7 +32165,6 @@ function Visualization$1({
32056
32165
  }), /* @__PURE__ */ jsxRuntime.jsx(VizEditorDialog, {
32057
32166
  open,
32058
32167
  setOpen,
32059
- rootQuery,
32060
32168
  plugin,
32061
32169
  view
32062
32170
  })]
@@ -32199,9 +32307,7 @@ function TopValuesTable({
32199
32307
  field,
32200
32308
  path
32201
32309
  }) {
32202
- const {
32203
- topValues
32204
- } = React.useContext(QueryEditorContext);
32310
+ const topValues = useTopValues();
32205
32311
  const fieldPath = [...path, field.name].join(".");
32206
32312
  const fieldTopValues = topValues == null ? void 0 : topValues.find((entry) => entry.fieldName === fieldPath);
32207
32313
  if (!fieldTopValues) {
@@ -32574,9 +32680,7 @@ function BooleanFilterCore({
32574
32680
  });
32575
32681
  }
32576
32682
  function useSearch(searchTerm, fieldPath) {
32577
- const {
32578
- topValues
32579
- } = React.useContext(QueryEditorContext);
32683
+ const topValues = useTopValues();
32580
32684
  if (topValues && searchTerm) {
32581
32685
  let searchValues = topValues;
32582
32686
  if (fieldPath) {
@@ -32618,7 +32722,8 @@ function ValueList({
32618
32722
  fieldPath,
32619
32723
  ref,
32620
32724
  customStyle,
32621
- showPath = true
32725
+ showPath = true,
32726
+ hideNoMatchMessage = false
32622
32727
  }) {
32623
32728
  const {
32624
32729
  searchResults
@@ -32640,7 +32745,7 @@ function ValueList({
32640
32745
  },
32641
32746
  children: value.fieldName
32642
32747
  }) : null]
32643
- }, value.fieldName + ":" + value.fieldValue)) : search ? /* @__PURE__ */ jsxRuntime.jsx("div", {
32748
+ }, value.fieldName + ":" + value.fieldValue)) : search && !hideNoMatchMessage ? /* @__PURE__ */ jsxRuntime.jsx("div", {
32644
32749
  ..._stylex.props(addMenuStyles.item),
32645
32750
  "data-disabled": "true",
32646
32751
  children: "No matching values"
@@ -32835,7 +32940,8 @@ const StringFilterCore = ({
32835
32940
  },
32836
32941
  customStyle: styles$i.valueList,
32837
32942
  showPath: false,
32838
- filter: (value) => !currentFilter.values.includes(value)
32943
+ filter: (value) => !currentFilter.values.includes(value),
32944
+ hideNoMatchMessage: true
32839
32945
  })
32840
32946
  })]
32841
32947
  }) : currentFilter.operator === "~" ? /* @__PURE__ */ jsxRuntime.jsx(StringEditor, {
@@ -33976,19 +34082,55 @@ const styles$g = {
33976
34082
  $$css: true
33977
34083
  }
33978
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
+ };
33979
34121
  function toFullName(path, name) {
33980
34122
  return [...path || [], name].join(".");
33981
34123
  }
33982
34124
  function segmentHasLimit(segment) {
33983
- 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;
33984
34126
  }
33985
34127
  function segmentHasOrderBy(segment, name) {
33986
- 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;
33987
34129
  }
33988
34130
  function getOutputNameToInputNameMap(segment) {
33989
34131
  const nameMap = /* @__PURE__ */ new Map();
33990
34132
  for (const operation of segment.operations.items) {
33991
- if (operation instanceof QB.ASTGroupByViewOperation || operation instanceof QB.ASTAggregateViewOperation) {
34133
+ if (operation instanceof malloyQueryBuilder.ASTGroupByViewOperation || operation instanceof malloyQueryBuilder.ASTAggregateViewOperation) {
33992
34134
  const reference = operation.field.getReference();
33993
34135
  if (reference) {
33994
34136
  nameMap.set(operation.name, toFullName(reference.path, reference.name));
@@ -34001,7 +34143,7 @@ function segmentHasOrderBySourceField(segment, path, name) {
34001
34143
  const nameMap = getOutputNameToInputNameMap(segment);
34002
34144
  const fullInputName = toFullName(path, name);
34003
34145
  return !!segment.operations.items.find((operation) => {
34004
- if (operation instanceof QB.ASTOrderByViewOperation && nameMap.has(operation.name)) {
34146
+ if (operation instanceof malloyQueryBuilder.ASTOrderByViewOperation && nameMap.has(operation.name)) {
34005
34147
  return fullInputName === nameMap.get(operation.name);
34006
34148
  }
34007
34149
  return false;
@@ -34012,7 +34154,7 @@ function areReferencesEqual(path1, name1, path2, name2) {
34012
34154
  }
34013
34155
  function segmentHasFieldInOutputSpace(segment, path, name) {
34014
34156
  const match = segment.operations.items.find((operation) => {
34015
- if (operation instanceof QB.ASTGroupByViewOperation || operation instanceof QB.ASTAggregateViewOperation) {
34157
+ if (operation instanceof malloyQueryBuilder.ASTGroupByViewOperation || operation instanceof malloyQueryBuilder.ASTAggregateViewOperation) {
34016
34158
  const reference = operation.field.getReference();
34017
34159
  if (reference) {
34018
34160
  return areReferencesEqual(path, name, reference.path, reference.name);
@@ -34026,7 +34168,7 @@ function segmentHasFieldInOutputSpace(segment, path, name) {
34026
34168
  }
34027
34169
  function segmentNestNo(segment, name) {
34028
34170
  return segment.operations.items.reduce((acc, operation) => {
34029
- if (operation instanceof QB.ASTNestViewOperation) {
34171
+ if (operation instanceof malloyQueryBuilder.ASTNestViewOperation) {
34030
34172
  {
34031
34173
  if (operation.name === name) {
34032
34174
  do {
@@ -34054,6 +34196,34 @@ function addGroupBy(view, field, path) {
34054
34196
  segment.addTimestampGroupBy(field.name, path, "second");
34055
34197
  } else {
34056
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
+ }
34057
34227
  }
34058
34228
  }
34059
34229
  function addAggregate(view, field, path) {
@@ -34108,10 +34278,10 @@ function getSegmentIfPresent(parent) {
34108
34278
  return void 0;
34109
34279
  }
34110
34280
  const definition = getViewDefinition(parent);
34111
- if (definition instanceof QB.ASTSegmentViewDefinition) {
34281
+ if (definition instanceof malloyQueryBuilder.ASTSegmentViewDefinition) {
34112
34282
  return definition;
34113
- } else if (definition instanceof QB.ASTRefinementViewDefinition) {
34114
- if (definition.refinement instanceof QB.ASTSegmentViewDefinition) {
34283
+ } else if (definition instanceof malloyQueryBuilder.ASTRefinementViewDefinition) {
34284
+ if (definition.refinement instanceof malloyQueryBuilder.ASTSegmentViewDefinition) {
34115
34285
  return definition.refinement;
34116
34286
  }
34117
34287
  }
@@ -34165,16 +34335,13 @@ function OperationActionTitle({
34165
34335
  });
34166
34336
  }
34167
34337
  function RenameDialog({
34168
- rootQuery,
34169
34338
  view,
34170
34339
  target,
34171
34340
  open,
34172
34341
  setOpen
34173
34342
  }) {
34174
34343
  const [name, setName] = React.useState("");
34175
- const {
34176
- setQuery
34177
- } = React.useContext(QueryEditorContext);
34344
+ const updateQuery = useUpdateQuery();
34178
34345
  React.useEffect(() => {
34179
34346
  if (target) {
34180
34347
  setName(target.name);
@@ -34184,8 +34351,9 @@ function RenameDialog({
34184
34351
  return null;
34185
34352
  }
34186
34353
  const onRename = () => {
34354
+ target.edit();
34187
34355
  target.name = name;
34188
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
34356
+ updateQuery();
34189
34357
  setOpen(false);
34190
34358
  };
34191
34359
  const {
@@ -34248,15 +34416,12 @@ function RenameDialog({
34248
34416
  });
34249
34417
  }
34250
34418
  function SortableOperations({
34251
- rootQuery,
34252
34419
  segment,
34253
34420
  view,
34254
34421
  operations,
34255
34422
  kind
34256
34423
  }) {
34257
- const {
34258
- setQuery
34259
- } = React.useContext(QueryEditorContext);
34424
+ const updateQuery = useUpdateQuery();
34260
34425
  const sensors = useSensors(useSensor(PointerSensor));
34261
34426
  const items = React.useMemo(() => {
34262
34427
  return operations.map((operation) => ({
@@ -34268,7 +34433,7 @@ function SortableOperations({
34268
34433
  return null;
34269
34434
  }
34270
34435
  function handleDragEnd(event) {
34271
- 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);
34272
34437
  const names = operations2.map((operation) => operation.name);
34273
34438
  const {
34274
34439
  active,
@@ -34278,7 +34443,7 @@ function SortableOperations({
34278
34443
  const oldIndex = names.indexOf(active.id);
34279
34444
  const newIndex = names.indexOf(over.id);
34280
34445
  segment.reorderFields(arrayMove(names, oldIndex, newIndex));
34281
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34446
+ updateQuery();
34282
34447
  }
34283
34448
  }
34284
34449
  const {
@@ -34290,7 +34455,7 @@ function SortableOperations({
34290
34455
  types: ["dimension"],
34291
34456
  onClick: (field, path) => {
34292
34457
  addGroupBy(view, field, path);
34293
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34458
+ updateQuery();
34294
34459
  }
34295
34460
  } : {
34296
34461
  title: "aggregate",
@@ -34298,12 +34463,11 @@ function SortableOperations({
34298
34463
  types: ["measure"],
34299
34464
  onClick: (field, path) => {
34300
34465
  addAggregate(view, field, path);
34301
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34466
+ updateQuery();
34302
34467
  }
34303
34468
  };
34304
34469
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
34305
34470
  children: [/* @__PURE__ */ jsxRuntime.jsx(OperationActionTitle, {
34306
- rootQuery,
34307
34471
  view,
34308
34472
  fields,
34309
34473
  ...props2
@@ -34316,7 +34480,6 @@ function SortableOperations({
34316
34480
  children: /* @__PURE__ */ jsxRuntime.jsx(SortableContext, {
34317
34481
  items,
34318
34482
  children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(SortableOperation, {
34319
- rootQuery,
34320
34483
  id: item.id,
34321
34484
  color: kind === "group_by" ? "cyan" : "green",
34322
34485
  view,
@@ -34329,18 +34492,16 @@ function SortableOperations({
34329
34492
  }
34330
34493
  const NULL_PATH = [];
34331
34494
  function SortableOperation({
34332
- rootQuery,
34333
34495
  id,
34334
34496
  view,
34335
34497
  operation,
34336
34498
  color
34337
34499
  }) {
34338
34500
  var _a2;
34339
- const {
34340
- setQuery
34341
- } = React.useContext(QueryEditorContext);
34501
+ const updateQuery = useUpdateQuery();
34342
34502
  const fieldInfo = operation.getFieldInfo();
34343
- 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;
34344
34505
  const {
34345
34506
  attributes,
34346
34507
  listeners,
@@ -34360,6 +34521,18 @@ function SortableOperation({
34360
34521
  transform: CSS$1.Transform.toString(transform2),
34361
34522
  transition
34362
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]);
34363
34536
  const hoverActions = React.useMemo(() => {
34364
34537
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
34365
34538
  children: [/* @__PURE__ */ jsxRuntime.jsx(DropdownMenu, {
@@ -34370,7 +34543,14 @@ function SortableOperation({
34370
34543
  tooltip: "More Actions"
34371
34544
  }),
34372
34545
  onOpenChange: setHoverActionsVisible,
34373
- 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, {
34374
34554
  label: "Rename",
34375
34555
  onClick: () => {
34376
34556
  setRenameTarget(operation);
@@ -34380,12 +34560,21 @@ function SortableOperation({
34380
34560
  }, [...path, fieldInfo.name].join(".")), /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34381
34561
  onClick: () => {
34382
34562
  operation.delete();
34383
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
34563
+ recomputePartitionByAndPrimaryAxis(view.getOrAddDefaultSegment());
34564
+ updateQuery();
34384
34565
  }
34385
34566
  })]
34386
34567
  });
34387
- }, [fieldInfo, operation, path, rootQuery, setQuery]);
34388
- 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
+ }
34389
34578
  let icon = "orderBy";
34390
34579
  if (fieldInfo.kind === "dimension" || fieldInfo.kind === "measure") {
34391
34580
  icon = atomicTypeToIcon(fieldInfo.type.kind);
@@ -34394,26 +34583,41 @@ function SortableOperation({
34394
34583
  id,
34395
34584
  ref: setNodeRef,
34396
34585
  style,
34397
- children: [granular ? /* @__PURE__ */ jsxRuntime.jsxs(TokenGroup, {
34398
- customStyle: customStyles.tokenGroup,
34399
- children: [/* @__PURE__ */ jsxRuntime.jsx(Token, {
34400
- color,
34401
- icon,
34402
- label: fieldInfo.name,
34403
- dragProps: {
34404
- attributes,
34405
- listeners
34586
+ children: [field && granular ? /* @__PURE__ */ jsxRuntime.jsxs("div", {
34587
+ ...{
34588
+ 0: {
34589
+ className: "mly78zum5 mly6s0dn4 mly1nhvcw1 mly1jnr06f mly11ogjb6 mly1g9of4s"
34590
+ },
34591
+ 1: {
34592
+ className: "mly78zum5 mly6s0dn4 mly1nhvcw1 mly1jnr06f mly1ae5hkt"
34406
34593
  }
34407
- }), /* @__PURE__ */ jsxRuntime.jsx(SelectorToken, {
34408
- color,
34409
- value: granular.value,
34410
- onChange: (granulation) => {
34411
- if (operation.field.expression instanceof QB.ASTTimeTruncationExpression) operation.field.expression.truncation = granulation;
34412
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34594
+ }[!!hoverActionsVisible << 0],
34595
+ children: [/* @__PURE__ */ jsxRuntime.jsxs(TokenGroup, {
34596
+ customStyle: customStyles.tokenGroup,
34597
+ children: [/* @__PURE__ */ jsxRuntime.jsx(Token, {
34598
+ color,
34599
+ icon,
34600
+ label: fieldInfo.name,
34601
+ dragProps: {
34602
+ attributes,
34603
+ listeners
34604
+ }
34605
+ }), /* @__PURE__ */ jsxRuntime.jsx(SelectorToken, {
34606
+ color,
34607
+ value: granular.value,
34608
+ onChange: (granulation) => {
34609
+ if (field.expression instanceof malloyQueryBuilder.ASTTimeTruncationExpression) field.expression.truncation = granulation;
34610
+ updateQuery();
34611
+ },
34612
+ items: granular.options
34613
+ })]
34614
+ }), hoverActions && /* @__PURE__ */ jsxRuntime.jsx("div", {
34615
+ ...{
34616
+ className: "mly2b4tyj mly2lah0s"
34413
34617
  },
34414
- items: granular.options
34618
+ children: hoverActions
34415
34619
  })]
34416
- }) : /* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
34620
+ }) : operation instanceof malloyQueryBuilder.ASTCalculateViewOperation ? /* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
34417
34621
  field: fieldInfo,
34418
34622
  color,
34419
34623
  hoverActionsVisible,
@@ -34430,9 +34634,67 @@ function SortableOperation({
34430
34634
  dragProps: {
34431
34635
  attributes,
34432
34636
  listeners
34433
- }
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
+ })
34434
34697
  }), /* @__PURE__ */ jsxRuntime.jsx(RenameDialog, {
34435
- rootQuery,
34436
34698
  view,
34437
34699
  target: renameTarget,
34438
34700
  open: renameOpen,
@@ -34443,7 +34705,7 @@ function SortableOperation({
34443
34705
  const DateGranulation = ["day", "week", "month", "quarter", "year"];
34444
34706
  const TimestampGranulation = ["second", "minute", "hour", "day", "week", "month", "quarter", "year"];
34445
34707
  function granularityMenuItems(fieldInfo, field) {
34446
- if (fieldInfo.kind !== "dimension" || !(field.expression instanceof QB.ASTTimeTruncationExpression)) {
34708
+ if (!field || fieldInfo.kind !== "dimension" || !(field.expression instanceof malloyQueryBuilder.ASTTimeTruncationExpression)) {
34447
34709
  return null;
34448
34710
  }
34449
34711
  if (fieldInfo.type.kind === "timestamp_type") {
@@ -34473,13 +34735,11 @@ const customStyles = {
34473
34735
  }
34474
34736
  };
34475
34737
  function GroupByOperations({
34476
- rootQuery,
34477
34738
  segment,
34478
34739
  view,
34479
34740
  groupBys
34480
34741
  }) {
34481
34742
  return /* @__PURE__ */ jsxRuntime.jsx(SortableOperations, {
34482
- rootQuery,
34483
34743
  segment,
34484
34744
  view,
34485
34745
  operations: groupBys,
@@ -34722,12 +34982,9 @@ function displayTimeFromMoment(momentObj) {
34722
34982
  return momentObj.moment;
34723
34983
  }
34724
34984
  function FilterOperations({
34725
- rootQuery,
34726
34985
  filters
34727
34986
  }) {
34728
- const {
34729
- setQuery
34730
- } = React.useContext(QueryEditorContext);
34987
+ const updateQuery = useUpdateQuery();
34731
34988
  if (filters.length === 0) {
34732
34989
  return null;
34733
34990
  }
@@ -34743,13 +35000,12 @@ function FilterOperations({
34743
35000
  children: ["Invalid filter", /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34744
35001
  onClick: () => {
34745
35002
  filterOperation.delete();
34746
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35003
+ updateQuery();
34747
35004
  }
34748
35005
  })]
34749
35006
  }),
34750
35007
  children: /* @__PURE__ */ jsxRuntime.jsx(SingleFilterOperation, {
34751
- filterOperation,
34752
- rootQuery
35008
+ filterOperation
34753
35009
  })
34754
35010
  }, key2);
34755
35011
  })
@@ -34757,41 +35013,42 @@ function FilterOperations({
34757
35013
  });
34758
35014
  }
34759
35015
  function SingleFilterOperation({
34760
- rootQuery,
34761
35016
  filterOperation
34762
35017
  }) {
34763
- const {
34764
- setQuery
34765
- } = React.useContext(QueryEditorContext);
35018
+ const updateQuery = useUpdateQuery();
34766
35019
  const setFilter = React.useCallback((filter2) => {
34767
- if (filterOperation.filter instanceof QB.ASTFilterWithFilterString) {
35020
+ if (filterOperation.filter instanceof malloyQueryBuilder.ASTFilterWithFilterString) {
34768
35021
  filterOperation.filter.setFilter(filter2);
34769
35022
  }
34770
- setQuery == null ? void 0 : setQuery(rootQuery.build());
34771
- }, [filterOperation.filter, rootQuery, setQuery]);
34772
- if (!(filterOperation.filter instanceof QB.ASTFilterWithFilterString)) {
35023
+ updateQuery();
35024
+ }, [filterOperation.filter, updateQuery]);
35025
+ const {
35026
+ filter
35027
+ } = filterOperation;
35028
+ if (!(filter instanceof malloyQueryBuilder.ASTFilterWithFilterString)) {
34773
35029
  return null;
34774
35030
  }
34775
35031
  const {
34776
- fieldReference,
35032
+ expression,
34777
35033
  filterString
34778
- } = filterOperation.filter;
34779
- const filter = filterOperation.filter.getFilter();
34780
- const fieldInfo = fieldReference.getFieldInfo();
34781
- if (fieldInfo.kind !== "dimension" && fieldInfo.kind !== "measure") {
34782
- throw new Error(`Invalid filter field kind: ${fieldInfo.kind}`);
35034
+ } = filter;
35035
+ if (!(expression instanceof malloyQueryBuilder.ASTReferenceExpression)) {
35036
+ return null;
34783
35037
  }
35038
+ const fieldInfo = filter.getFieldInfo();
35039
+ const parsedFilter = filter.getFilter();
35040
+ const path = expression.path ?? [];
34784
35041
  const {
34785
35042
  op,
34786
35043
  value
34787
- } = parsedToLabels(filter, filterString);
35044
+ } = parsedToLabels(parsedFilter, filterString);
34788
35045
  const label = `${fieldInfo.name} ${op} ${value}`;
34789
35046
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
34790
35047
  ..._stylex.props(hoverStyles.main),
34791
35048
  children: [/* @__PURE__ */ jsxRuntime.jsx(FilterPopover, {
34792
35049
  fieldInfo,
34793
- path: fieldReference.path ?? [],
34794
- filter,
35050
+ path,
35051
+ filter: parsedFilter,
34795
35052
  setFilter,
34796
35053
  trigger: /* @__PURE__ */ jsxRuntime.jsx(Token, {
34797
35054
  icon: "filter",
@@ -34808,19 +35065,16 @@ function SingleFilterOperation({
34808
35065
  children: /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34809
35066
  onClick: () => {
34810
35067
  filterOperation.delete();
34811
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35068
+ updateQuery();
34812
35069
  }
34813
35070
  })
34814
35071
  })]
34815
35072
  });
34816
35073
  }
34817
35074
  function LimitOperation({
34818
- rootQuery,
34819
35075
  limit
34820
35076
  }) {
34821
- const {
34822
- setQuery
34823
- } = React.useContext(QueryEditorContext);
35077
+ const updateQuery = useUpdateQuery();
34824
35078
  if (!limit) {
34825
35079
  return null;
34826
35080
  }
@@ -34835,7 +35089,7 @@ function LimitOperation({
34835
35089
  value: limit.limit,
34836
35090
  onChange: (value) => {
34837
35091
  limit.limit = value;
34838
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35092
+ updateQuery();
34839
35093
  },
34840
35094
  errorMessage: limit.limit < 0 ? "Limit must be positive" : void 0
34841
35095
  }), /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -34843,7 +35097,7 @@ function LimitOperation({
34843
35097
  children: /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34844
35098
  onClick: () => {
34845
35099
  limit.delete();
34846
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35100
+ updateQuery();
34847
35101
  }
34848
35102
  })
34849
35103
  })]
@@ -34851,13 +35105,11 @@ function LimitOperation({
34851
35105
  });
34852
35106
  }
34853
35107
  function AggregateOperations({
34854
- rootQuery,
34855
35108
  segment,
34856
35109
  view,
34857
35110
  aggregates
34858
35111
  }) {
34859
35112
  return /* @__PURE__ */ jsxRuntime.jsx(SortableOperations, {
34860
- rootQuery,
34861
35113
  segment,
34862
35114
  view,
34863
35115
  operations: aggregates,
@@ -34865,12 +35117,9 @@ function AggregateOperations({
34865
35117
  });
34866
35118
  }
34867
35119
  function OrderByOperations({
34868
- rootQuery,
34869
35120
  orderBys
34870
35121
  }) {
34871
- const {
34872
- setQuery
34873
- } = React.useContext(QueryEditorContext);
35122
+ const updateQuery = useUpdateQuery();
34874
35123
  if (orderBys.length === 0) {
34875
35124
  return null;
34876
35125
  }
@@ -34910,7 +35159,7 @@ function OrderByOperations({
34910
35159
  value: orderBy.direction ?? "asc",
34911
35160
  onChange: (direction) => {
34912
35161
  orderBy.direction = direction;
34913
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35162
+ updateQuery();
34914
35163
  }
34915
35164
  })]
34916
35165
  }), /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -34918,7 +35167,7 @@ function OrderByOperations({
34918
35167
  children: /* @__PURE__ */ jsxRuntime.jsx(ClearButton, {
34919
35168
  onClick: () => {
34920
35169
  orderBy.delete();
34921
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35170
+ updateQuery();
34922
35171
  }
34923
35172
  })
34924
35173
  })]
@@ -34928,7 +35177,6 @@ function OrderByOperations({
34928
35177
  });
34929
35178
  }
34930
35179
  function View({
34931
- rootQuery,
34932
35180
  view
34933
35181
  }) {
34934
35182
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -34938,10 +35186,8 @@ function View({
34938
35186
  gap: 8
34939
35187
  },
34940
35188
  children: [/* @__PURE__ */ jsxRuntime.jsx(Visualization$1, {
34941
- rootQuery,
34942
35189
  view
34943
35190
  }), /* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
34944
- rootQuery,
34945
35191
  view,
34946
35192
  viewDef: view.definition
34947
35193
  })]
@@ -35006,12 +35252,9 @@ const styles$f = {
35006
35252
  }
35007
35253
  };
35008
35254
  function AddLimit({
35009
- rootQuery,
35010
35255
  view
35011
35256
  }) {
35012
- const {
35013
- setQuery
35014
- } = React.useContext(QueryEditorContext);
35257
+ const updateQuery = useUpdateQuery();
35015
35258
  const segment = getSegmentIfPresent(view);
35016
35259
  const hasLimit = segment ? segmentHasLimit(segment) : false;
35017
35260
  return /* @__PURE__ */ jsxRuntime.jsx(AddItem, {
@@ -35023,17 +35266,14 @@ function AddLimit({
35023
35266
  onClick: () => {
35024
35267
  const segment2 = view.getOrAddDefaultSegment();
35025
35268
  segment2.setLimit(10);
35026
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35269
+ updateQuery();
35027
35270
  }
35028
35271
  });
35029
35272
  }
35030
35273
  function AddEmptyNest({
35031
- rootQuery,
35032
35274
  view
35033
35275
  }) {
35034
- const {
35035
- setQuery
35036
- } = React.useContext(QueryEditorContext);
35276
+ const updateQuery = useUpdateQuery();
35037
35277
  return /* @__PURE__ */ jsxRuntime.jsx(AddItem, {
35038
35278
  icon: /* @__PURE__ */ jsxRuntime.jsx(Icon, {
35039
35279
  name: "nest"
@@ -35043,7 +35283,7 @@ function AddEmptyNest({
35043
35283
  const segment = view.getOrAddDefaultSegment();
35044
35284
  const nestNo = segmentNestNo(segment, `Nest`);
35045
35285
  segment.addEmptyNest(nestNo > 1 ? `Nest ${nestNo}` : `Nest`);
35046
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35286
+ updateQuery();
35047
35287
  }
35048
35288
  });
35049
35289
  }
@@ -35075,13 +35315,10 @@ const styles$e = {
35075
35315
  }
35076
35316
  };
35077
35317
  function AddOrderBy({
35078
- rootQuery,
35079
35318
  view,
35080
35319
  search
35081
35320
  }) {
35082
- const {
35083
- setQuery
35084
- } = React.useContext(QueryEditorContext);
35321
+ const updateQuery = useUpdateQuery();
35085
35322
  const outputSchemaFields = view.getOutputSchema().fields;
35086
35323
  const segment = getSegmentIfPresent(view);
35087
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]);
@@ -35093,7 +35330,7 @@ function AddOrderBy({
35093
35330
  types: ["dimension"],
35094
35331
  onAddOperation: (field) => {
35095
35332
  addOrderBy(view, field);
35096
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35333
+ updateQuery();
35097
35334
  },
35098
35335
  disabledMessage: "There must be at least one field in the output to order by.",
35099
35336
  search
@@ -35101,13 +35338,10 @@ function AddOrderBy({
35101
35338
  }
35102
35339
  const ORDERABLE_TYPES$1 = ["string_type", "number_type", "boolean_type", "date_type", "timestamp_type"];
35103
35340
  function AddGroupBy({
35104
- rootQuery,
35105
35341
  view,
35106
35342
  search
35107
35343
  }) {
35108
- const {
35109
- setQuery
35110
- } = React.useContext(QueryEditorContext);
35344
+ const updateQuery = useUpdateQuery();
35111
35345
  const {
35112
35346
  fields
35113
35347
  } = getInputSchemaFromViewParent(view);
@@ -35124,19 +35358,16 @@ function AddGroupBy({
35124
35358
  filter,
35125
35359
  onAddOperation: (field, path) => {
35126
35360
  addGroupBy(view, field, path);
35127
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35361
+ updateQuery();
35128
35362
  },
35129
35363
  search
35130
35364
  });
35131
35365
  }
35132
35366
  function AddAggregate({
35133
- rootQuery,
35134
35367
  view,
35135
35368
  search
35136
35369
  }) {
35137
- const {
35138
- setQuery
35139
- } = React.useContext(QueryEditorContext);
35370
+ const updateQuery = useUpdateQuery();
35140
35371
  const {
35141
35372
  fields
35142
35373
  } = getInputSchemaFromViewParent(view);
@@ -35153,7 +35384,7 @@ function AddAggregate({
35153
35384
  filter,
35154
35385
  onAddOperation: (field, path) => {
35155
35386
  addAggregate(view, field, path);
35156
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35387
+ updateQuery();
35157
35388
  },
35158
35389
  search
35159
35390
  });
@@ -35162,10 +35393,7 @@ function AddWhere({
35162
35393
  view,
35163
35394
  search
35164
35395
  }) {
35165
- const {
35166
- rootQuery,
35167
- setQuery
35168
- } = React__namespace.useContext(QueryEditorContext);
35396
+ const updateQuery = useUpdateQuery();
35169
35397
  const {
35170
35398
  fields
35171
35399
  } = getInputSchemaFromViewParent(view);
@@ -35179,7 +35407,7 @@ function AddWhere({
35179
35407
  onAddOperation: (field, path, filter) => {
35180
35408
  if (filter && (field.kind === "dimension" || field.kind === "measure")) {
35181
35409
  addFilter(view, field, path, filter);
35182
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
35410
+ updateQuery();
35183
35411
  }
35184
35412
  },
35185
35413
  isFilterOperation: true,
@@ -35188,15 +35416,18 @@ function AddWhere({
35188
35416
  }
35189
35417
  const FILTERABLE_TYPES$1 = /* @__PURE__ */ new Set(["string_type", "boolean_type", "number_type", "date_type", "timestamp_type"]);
35190
35418
  function AddView({
35191
- rootQuery,
35192
35419
  view,
35193
35420
  search
35194
35421
  }) {
35195
35422
  const {
35196
- setQuery
35423
+ rootQuery
35197
35424
  } = React.useContext(QueryEditorContext);
35425
+ const updateQuery = useUpdateQuery();
35198
35426
  const allFields = getInputSchemaFromViewParent(view).fields;
35199
35427
  const fields = React.useMemo(() => allFields.filter((field) => field.kind === "view" && !isIndexView(field)), [allFields]);
35428
+ if (!rootQuery) {
35429
+ return null;
35430
+ }
35200
35431
  return /* @__PURE__ */ jsxRuntime.jsx(AddFieldItem, {
35201
35432
  label: "Add view",
35202
35433
  icon: "view",
@@ -35210,20 +35441,17 @@ function AddView({
35210
35441
  } else {
35211
35442
  addNest(view, field);
35212
35443
  }
35213
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35444
+ updateQuery();
35214
35445
  },
35215
35446
  search
35216
35447
  });
35217
35448
  }
35218
35449
  function AddMenu({
35219
- rootQuery,
35220
35450
  view
35221
35451
  }) {
35222
35452
  const [open, setOpen] = React.useState(false);
35223
35453
  const [active, setActive] = React.useState("");
35224
- const {
35225
- setQuery
35226
- } = React.useContext(QueryEditorContext);
35454
+ const updateQuery = useUpdateQuery();
35227
35455
  const [search, setSearch] = React.useState("");
35228
35456
  const segment = getSegmentIfPresent(view);
35229
35457
  const toggleActive = (toggle) => {
@@ -35287,7 +35515,7 @@ function AddMenu({
35287
35515
  } else {
35288
35516
  addNest(view, field);
35289
35517
  }
35290
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35518
+ updateQuery();
35291
35519
  },
35292
35520
  search
35293
35521
  }), /* @__PURE__ */ jsxRuntime.jsx(Divider, {}), /* @__PURE__ */ jsxRuntime.jsx(ValueList, {
@@ -35303,7 +35531,7 @@ function AddMenu({
35303
35531
  values: [value.fieldValue ?? "∅"]
35304
35532
  }
35305
35533
  });
35306
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35534
+ updateQuery();
35307
35535
  }
35308
35536
  })]
35309
35537
  }) : /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -35340,7 +35568,6 @@ function AddMenu({
35340
35568
  onClick: () => toggleActive("view"),
35341
35569
  open: active === "view"
35342
35570
  }), /* @__PURE__ */ jsxRuntime.jsx(Divider, {}), /* @__PURE__ */ jsxRuntime.jsx(AddLimit, {
35343
- rootQuery,
35344
35571
  view
35345
35572
  }), /* @__PURE__ */ jsxRuntime.jsx(AddItem, {
35346
35573
  icon: /* @__PURE__ */ jsxRuntime.jsx(Icon, {
@@ -35350,7 +35577,6 @@ function AddMenu({
35350
35577
  onClick: () => toggleActive("order_by"),
35351
35578
  open: active === "order_by"
35352
35579
  }), /* @__PURE__ */ jsxRuntime.jsx(AddEmptyNest, {
35353
- rootQuery,
35354
35580
  view
35355
35581
  })]
35356
35582
  }), /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -35359,23 +35585,18 @@ function AddMenu({
35359
35585
  overflowY: "auto"
35360
35586
  },
35361
35587
  children: [active === "group_by" && /* @__PURE__ */ jsxRuntime.jsx(AddGroupBy, {
35362
- rootQuery,
35363
35588
  view,
35364
35589
  search
35365
35590
  }), active === "aggregate" && /* @__PURE__ */ jsxRuntime.jsx(AddAggregate, {
35366
- rootQuery,
35367
35591
  view,
35368
35592
  search
35369
35593
  }), active === "where" && /* @__PURE__ */ jsxRuntime.jsx(AddWhere, {
35370
- rootQuery,
35371
35594
  view,
35372
35595
  search
35373
35596
  }), active === "view" && /* @__PURE__ */ jsxRuntime.jsx(AddView, {
35374
- rootQuery,
35375
35597
  view,
35376
35598
  search
35377
35599
  }), active === "order_by" && /* @__PURE__ */ jsxRuntime.jsx(AddOrderBy, {
35378
- rootQuery,
35379
35600
  view,
35380
35601
  search
35381
35602
  })]
@@ -35421,7 +35642,6 @@ function FocusableView({
35421
35642
  });
35422
35643
  }
35423
35644
  function NestOperations({
35424
- rootQuery,
35425
35645
  view,
35426
35646
  nests
35427
35647
  }) {
@@ -35431,20 +35651,16 @@ function NestOperations({
35431
35651
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
35432
35652
  ..._stylex.props(styles$u.tokenContainer),
35433
35653
  children: nests.map((nest) => /* @__PURE__ */ jsxRuntime.jsx(NestOperation, {
35434
- rootQuery,
35435
35654
  view,
35436
35655
  nest
35437
35656
  }, nest.name))
35438
35657
  });
35439
35658
  }
35440
35659
  function NestOperation({
35441
- rootQuery,
35442
35660
  view,
35443
35661
  nest
35444
35662
  }) {
35445
- const {
35446
- setQuery
35447
- } = React.useContext(QueryEditorContext);
35663
+ const updateQuery = useUpdateQuery();
35448
35664
  const [renameOpen, setRenameOpen] = React.useState(false);
35449
35665
  const parentNestViewPath = React.useContext(NestViewPathContext);
35450
35666
  const {
@@ -35465,7 +35681,7 @@ function NestOperation({
35465
35681
  onClick: () => {
35466
35682
  focusNestView([...parentNestViewPath]);
35467
35683
  nest2.delete();
35468
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35684
+ updateQuery();
35469
35685
  }
35470
35686
  }), /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, {
35471
35687
  label: "Rename",
@@ -35474,7 +35690,6 @@ function NestOperation({
35474
35690
  }
35475
35691
  })]
35476
35692
  }), /* @__PURE__ */ jsxRuntime.jsx(AddMenu, {
35477
- rootQuery,
35478
35693
  view: nest2.view
35479
35694
  })]
35480
35695
  });
@@ -35486,17 +35701,15 @@ function NestOperation({
35486
35701
  },
35487
35702
  children: [/* @__PURE__ */ jsxRuntime.jsx(CollapsiblePanel, {
35488
35703
  title: nest.name,
35489
- icon: viewToVisualizationIcon(nest.view),
35704
+ icon: tagToVisualization(nest.view.getTag()),
35490
35705
  defaultOpen: true,
35491
35706
  controls: getControls(nest),
35492
35707
  collapsedControls: getControls(nest),
35493
35708
  isFocused: isNestViewFocused([...parentNestViewPath, nest.name]),
35494
35709
  children: /* @__PURE__ */ jsxRuntime.jsx(View, {
35495
- rootQuery,
35496
35710
  view: nest.view
35497
35711
  })
35498
35712
  }), /* @__PURE__ */ jsxRuntime.jsx(RenameDialog, {
35499
- rootQuery,
35500
35713
  view,
35501
35714
  target: nest,
35502
35715
  open: renameOpen,
@@ -35506,7 +35719,6 @@ function NestOperation({
35506
35719
  });
35507
35720
  }
35508
35721
  function Operations({
35509
- rootQuery,
35510
35722
  view,
35511
35723
  viewDef
35512
35724
  }) {
@@ -35517,24 +35729,24 @@ function Operations({
35517
35729
  const orderBys = [];
35518
35730
  const nests = [];
35519
35731
  let limit;
35520
- if (!(viewDef instanceof QB.ASTSegmentViewDefinition)) {
35732
+ if (!(viewDef instanceof malloyQueryBuilder.ASTSegmentViewDefinition)) {
35521
35733
  return null;
35522
35734
  }
35523
35735
  const segment = viewDef;
35524
35736
  segment.operations.items.forEach((operation) => {
35525
- if (operation instanceof QB.ASTGroupByViewOperation) {
35737
+ if (operation instanceof malloyQueryBuilder.ASTGroupByViewOperation) {
35526
35738
  groupBys.push(operation);
35527
- } else if (operation instanceof QB.ASTAggregateViewOperation) {
35739
+ } else if (operation instanceof malloyQueryBuilder.ASTAggregateViewOperation || operation instanceof malloyQueryBuilder.ASTCalculateViewOperation) {
35528
35740
  aggregates.push(operation);
35529
- } else if (operation instanceof QB.ASTWhereViewOperation) {
35741
+ } else if (operation instanceof malloyQueryBuilder.ASTWhereViewOperation) {
35530
35742
  filters.push(operation);
35531
- } else if (operation instanceof QB.ASTHavingViewOperation) {
35743
+ } else if (operation instanceof malloyQueryBuilder.ASTHavingViewOperation) {
35532
35744
  filters.push(operation);
35533
- } else if (operation instanceof QB.ASTOrderByViewOperation) {
35745
+ } else if (operation instanceof malloyQueryBuilder.ASTOrderByViewOperation) {
35534
35746
  orderBys.push(operation);
35535
- } else if (operation instanceof QB.ASTNestViewOperation) {
35747
+ } else if (operation instanceof malloyQueryBuilder.ASTNestViewOperation) {
35536
35748
  nests.push(operation);
35537
- } else if (operation instanceof QB.ASTDrillViewOperation) {
35749
+ } else if (operation instanceof malloyQueryBuilder.ASTDrillViewOperation) {
35538
35750
  drills.push(operation);
35539
35751
  } else {
35540
35752
  limit = operation;
@@ -35545,66 +35757,53 @@ function Operations({
35545
35757
  className: "mly1tpqehw mly10lvyaf"
35546
35758
  },
35547
35759
  children: [/* @__PURE__ */ jsxRuntime.jsx(GroupByOperations, {
35548
- rootQuery,
35549
35760
  segment,
35550
35761
  view,
35551
35762
  groupBys
35552
35763
  }), /* @__PURE__ */ jsxRuntime.jsx(AggregateOperations, {
35553
- rootQuery,
35554
35764
  segment,
35555
35765
  view,
35556
35766
  aggregates
35557
35767
  }), /* @__PURE__ */ jsxRuntime.jsx(DrillOperations, {
35558
- rootQuery,
35559
35768
  drills
35560
35769
  }), /* @__PURE__ */ jsxRuntime.jsx(FilterOperations, {
35561
- rootQuery,
35562
35770
  filters
35563
35771
  }), /* @__PURE__ */ jsxRuntime.jsx(OrderByOperations, {
35564
- rootQuery,
35565
35772
  orderBys
35566
35773
  }), /* @__PURE__ */ jsxRuntime.jsx(NestOperations, {
35567
- rootQuery,
35568
35774
  view,
35569
35775
  nests
35570
35776
  }), /* @__PURE__ */ jsxRuntime.jsx(LimitOperation, {
35571
- rootQuery,
35572
35777
  limit
35573
35778
  })]
35574
35779
  });
35575
35780
  }
35576
35781
  function ViewDefinition({
35577
- rootQuery,
35578
35782
  view,
35579
35783
  viewDef
35580
35784
  }) {
35581
- if (viewDef instanceof QB.ASTArrowViewDefinition) {
35785
+ if (viewDef instanceof malloyQueryBuilder.ASTArrowViewDefinition) {
35582
35786
  return /* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
35583
- rootQuery,
35584
35787
  view,
35585
35788
  viewDef: viewDef.view
35586
35789
  });
35587
- } else if (viewDef instanceof QB.ASTRefinementViewDefinition) {
35790
+ } else if (viewDef instanceof malloyQueryBuilder.ASTRefinementViewDefinition) {
35588
35791
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
35589
35792
  children: [/* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
35590
- rootQuery,
35591
35793
  view,
35592
35794
  viewDef: viewDef.base
35593
35795
  }), /* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
35594
- rootQuery,
35595
35796
  view,
35596
35797
  viewDef: viewDef.refinement
35597
35798
  })]
35598
35799
  });
35599
- } else if (viewDef instanceof QB.ASTSegmentViewDefinition) {
35800
+ } else if (viewDef instanceof malloyQueryBuilder.ASTSegmentViewDefinition) {
35600
35801
  return /* @__PURE__ */ jsxRuntime.jsx(Operations, {
35601
- rootQuery,
35602
35802
  view,
35603
35803
  viewDef
35604
35804
  });
35605
35805
  } else {
35606
35806
  return /* @__PURE__ */ jsxRuntime.jsx(CollapsingView, {
35607
- rootQuery,
35608
35807
  viewDef
35609
35808
  });
35610
35809
  }
@@ -35673,14 +35872,21 @@ const styles$c = {
35673
35872
  }
35674
35873
  };
35675
35874
  function Query({
35676
- rootQuery,
35677
- query,
35678
- setQuery
35875
+ definition
35679
35876
  }) {
35680
35877
  const {
35681
35878
  focusMainView,
35682
35879
  isMainViewFocused
35683
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();
35684
35890
  return /* @__PURE__ */ jsxRuntime.jsx(FocusableView, {
35685
35891
  children: /* @__PURE__ */ jsxRuntime.jsxs(CollapsiblePanel, {
35686
35892
  title: "Main query",
@@ -35699,44 +35905,41 @@ function Query({
35699
35905
  label: "Clear query",
35700
35906
  onClick: () => {
35701
35907
  focusMainView();
35702
- setQuery == null ? void 0 : setQuery(void 0);
35908
+ setQuery(void 0);
35703
35909
  },
35704
- disabled: rootQuery.isEmpty()
35910
+ disabled: isEmpty
35705
35911
  }), /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, {
35706
35912
  icon: "nest",
35707
35913
  label: "Nest query",
35708
35914
  onClick: () => {
35709
- if (rootQuery.definition instanceof QB.ASTArrowQueryDefinition) {
35710
- rootQuery.definition.view.convertToNest("Nest");
35915
+ if (definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition) {
35916
+ definition.view.convertToNest("Nest");
35711
35917
  }
35712
- setQuery == null ? void 0 : setQuery(rootQuery.build());
35918
+ updateQuery();
35713
35919
  },
35714
- disabled: rootQuery.isEmpty() || !(rootQuery.definition instanceof QB.ASTArrowQueryDefinition)
35920
+ disabled: isEmpty || !(definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition)
35715
35921
  })]
35716
35922
  }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {})
35717
- }), query.definition instanceof QB.ASTArrowQueryDefinition ? /* @__PURE__ */ jsxRuntime.jsx(AddMenu, {
35718
- rootQuery,
35719
- view: query.definition
35923
+ }), definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition ? /* @__PURE__ */ jsxRuntime.jsx(AddMenu, {
35924
+ view: definition
35720
35925
  }) : null]
35721
35926
  }),
35722
35927
  collapsedControls: /* @__PURE__ */ jsxRuntime.jsx(Icon, {
35723
- name: viewToVisualizationIcon(query)
35928
+ name: tagToVisualization(rootQuery.getTag())
35724
35929
  }),
35725
- children: [query.definition instanceof QB.ASTArrowQueryDefinition ? /* @__PURE__ */ jsxRuntime.jsxs("div", {
35930
+ children: [definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition ? /* @__PURE__ */ jsxRuntime.jsxs("div", {
35726
35931
  style: {
35727
35932
  display: "flex",
35728
35933
  flexDirection: "column",
35729
35934
  gap: 8
35730
35935
  },
35731
- children: [!query.isEmpty() && /* @__PURE__ */ jsxRuntime.jsx(Visualization$1, {
35732
- rootQuery,
35733
- view: query
35936
+ children: [!isEmpty && /* @__PURE__ */ jsxRuntime.jsx(Visualization$1, {
35937
+ view: rootQuery
35734
35938
  }), /* @__PURE__ */ jsxRuntime.jsx(ViewDefinition, {
35735
- rootQuery,
35736
- view: query.definition,
35737
- viewDef: query.definition.view
35939
+ view: definition,
35940
+ viewDef: definition.view
35738
35941
  })]
35739
- }) : null, query.isEmpty() ? /* @__PURE__ */ jsxRuntime.jsx("div", {
35942
+ }) : null, isEmpty ? /* @__PURE__ */ jsxRuntime.jsx("div", {
35740
35943
  ...{
35741
35944
  className: "mly78zum5 mlyl56j7k mly6s0dn4 mlyng8ra"
35742
35945
  },
@@ -35758,9 +35961,9 @@ function Query({
35758
35961
  });
35759
35962
  }
35760
35963
  function Source({
35761
- rootQuery
35964
+ definition
35762
35965
  }) {
35763
- if (rootQuery.definition instanceof QB.ASTArrowQueryDefinition) {
35966
+ if (definition instanceof malloyQueryBuilder.ASTArrowQueryDefinition) {
35764
35967
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
35765
35968
  ..._stylex.props(styles$u.queryCard, styles$b.content),
35766
35969
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -35771,7 +35974,7 @@ function Source({
35771
35974
  ...{
35772
35975
  className: "mlyb3r6kr mlylyipyv mly117nqv4"
35773
35976
  },
35774
- children: rootQuery.definition.as.ArrowQueryDefinition().source.as.ReferenceQueryArrowSource().name
35977
+ children: definition.source.getSourceInfo().name
35775
35978
  })]
35776
35979
  })
35777
35980
  });
@@ -36108,13 +36311,13 @@ function LiteralValueEditor({
36108
36311
  }
36109
36312
  }
36110
36313
  function Parameters({
36111
- rootQuery
36314
+ definition
36112
36315
  }) {
36113
- const {
36114
- setQuery
36115
- } = React.useContext(QueryEditorContext);
36116
- if (rootQuery.definition instanceof QB.ASTArrowQueryDefinition) {
36117
- 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;
36118
36321
  const sourceParameters = source.getSourceParameters();
36119
36322
  if (!sourceParameters || sourceParameters.length === 0) {
36120
36323
  return null;
@@ -36137,7 +36340,7 @@ function Parameters({
36137
36340
  value: ((_a2 = source.tryGetParameter(parameter.name)) == null ? void 0 : _a2.parameter.value) ?? parameter.default_value,
36138
36341
  setValue: (value) => {
36139
36342
  source.setParameter(parameter.name, value);
36140
- setQuery == null ? void 0 : setQuery(rootQuery.build());
36343
+ updateQuery();
36141
36344
  }
36142
36345
  })]
36143
36346
  }, parameter.name);
@@ -36155,23 +36358,23 @@ const styles$9 = {
36155
36358
  };
36156
36359
  function QueryEditor() {
36157
36360
  const {
36158
- rootQuery,
36159
- setQuery
36361
+ rootQuery
36160
36362
  } = React.useContext(QueryEditorContext);
36161
36363
  if (!rootQuery) {
36162
36364
  console.error("Missing <MalloyExplorerProvider>");
36163
36365
  return null;
36164
36366
  }
36367
+ const {
36368
+ definition
36369
+ } = rootQuery;
36165
36370
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
36166
36371
  ..._stylex.props(fontStyles.body, styles$8.main),
36167
36372
  children: [/* @__PURE__ */ jsxRuntime.jsx(Source, {
36168
- rootQuery
36373
+ definition
36169
36374
  }), /* @__PURE__ */ jsxRuntime.jsx(Parameters, {
36170
- rootQuery
36375
+ definition
36171
36376
  }), /* @__PURE__ */ jsxRuntime.jsx(Query, {
36172
- rootQuery,
36173
- query: rootQuery,
36174
- setQuery
36377
+ definition
36175
36378
  })]
36176
36379
  });
36177
36380
  }
@@ -36702,22 +36905,19 @@ function RenderedResult({
36702
36905
  const viz = React.useMemo(() => {
36703
36906
  const renderer = new render.MalloyRenderer();
36704
36907
  const viz2 = renderer.createViz({
36705
- onDrill: ({
36706
- stableQuery,
36707
- stableDrillClauses
36708
- }) => {
36908
+ onDrill: (drillData) => {
36709
36909
  if (onDrill) {
36710
- onDrill({
36711
- stableQuery,
36712
- stableDrillClauses
36713
- });
36910
+ onDrill(drillData);
36714
36911
  return;
36715
36912
  }
36716
- const rootQuery = new QB.ASTQuery({
36913
+ const {
36914
+ stableQuery
36915
+ } = drillData;
36916
+ const rootQuery = new malloyQueryBuilder.ASTQuery({
36717
36917
  query: stableQuery,
36718
36918
  source
36719
36919
  });
36720
- setQuery == null ? void 0 : setQuery(rootQuery.build());
36920
+ setQuery(rootQuery.build());
36721
36921
  },
36722
36922
  tableConfig: {
36723
36923
  enableDrill: true
@@ -37298,27 +37498,21 @@ function useOperations(view, field, path) {
37298
37498
  return "";
37299
37499
  }, [matchingFieldItem, view, path, field.name, fullName]);
37300
37500
  return {
37301
- isGroupByAllowed: !groupByDisabledReason,
37302
37501
  groupByDisabledReason,
37303
- isAggregateAllowed: !aggregateDisabledReason,
37304
37502
  aggregateDisabledReason,
37305
- isFilterAllowed: !filterDisabledReason,
37306
37503
  filterDisabledReason,
37307
- isOrderByAllowed: !orderByDisabledReason,
37308
37504
  orderByDisabledReason
37309
37505
  };
37310
37506
  }
37311
37507
  const FILTERABLE_TYPES = ["string_type", "boolean_type", "number_type", "date_type", "timestamp_type"];
37312
37508
  const ORDERABLE_TYPES = ["string_type", "number_type", "boolean_type", "date_type", "timestamp_type"];
37313
37509
  function FieldTokenWithActions({
37510
+ rootQuery,
37314
37511
  field,
37315
37512
  path,
37316
37513
  viewDef
37317
37514
  }) {
37318
- const {
37319
- rootQuery,
37320
- setQuery
37321
- } = React.useContext(QueryEditorContext);
37515
+ const updateQuery = useUpdateQuery();
37322
37516
  const {
37323
37517
  focusedNestView
37324
37518
  } = useQueryFocus();
@@ -37342,19 +37536,19 @@ function FieldTokenWithActions({
37342
37536
  } else if (operation === "filter" && !filterDisabledReason && filter) {
37343
37537
  addFilter(view, field, path, filter);
37344
37538
  }
37345
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
37539
+ updateQuery();
37346
37540
  }
37347
37541
  };
37348
37542
  const handleSetView = () => {
37349
- if (field.kind === "view" && (rootQuery == null ? void 0 : rootQuery.isEmpty())) {
37350
- rootQuery == null ? void 0 : rootQuery.setView(field.name);
37351
- 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();
37352
37546
  }
37353
37547
  };
37354
37548
  const handleAddView = () => {
37355
37549
  if (field.kind === "view") {
37356
37550
  addNest(view, field);
37357
- setQuery == null ? void 0 : setQuery(rootQuery == null ? void 0 : rootQuery.build());
37551
+ updateQuery();
37358
37552
  }
37359
37553
  };
37360
37554
  return /* @__PURE__ */ jsxRuntime.jsx(FieldToken, {
@@ -37362,9 +37556,9 @@ function FieldTokenWithActions({
37362
37556
  hoverActions: field.kind === "view" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
37363
37557
  children: [/* @__PURE__ */ jsxRuntime.jsx(ActionButton, {
37364
37558
  icon: "insert",
37365
- disabled: !(rootQuery == null ? void 0 : rootQuery.isEmpty()),
37559
+ disabled: !rootQuery.isEmpty(),
37366
37560
  onClick: handleSetView,
37367
- 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",
37368
37562
  onTooltipOpenChange: setIsTooltipOpen
37369
37563
  }), /* @__PURE__ */ jsxRuntime.jsx(ActionButton, {
37370
37564
  icon: "nest",
@@ -37430,7 +37624,7 @@ function FieldTokenWithActions({
37430
37624
  })]
37431
37625
  }) : null,
37432
37626
  onClick: field.kind === "dimension" && !groupByDisabledReason ? () => handleAddOperationAction("groupBy") : field.kind === "measure" && !aggregateDisabledReason ? () => handleAddOperationAction("aggregate") : field.kind === "view" ? () => {
37433
- if (rootQuery == null ? void 0 : rootQuery.isEmpty()) {
37627
+ if (rootQuery.isEmpty()) {
37434
37628
  handleSetView();
37435
37629
  } else {
37436
37630
  handleAddView();
@@ -37474,6 +37668,7 @@ function ActionButton({
37474
37668
  }
37475
37669
  const FIELD_KIND_ORDER = ["dimension", "measure", "view"];
37476
37670
  function SearchResultList({
37671
+ rootQuery,
37477
37672
  source,
37478
37673
  items
37479
37674
  }) {
@@ -37483,11 +37678,8 @@ function SearchResultList({
37483
37678
  items: groupFieldItemsByPath(source, group.items)
37484
37679
  }));
37485
37680
  }, [source, items]);
37486
- const {
37487
- rootQuery
37488
- } = React__namespace.useContext(QueryEditorContext);
37489
- const viewDef = rootQuery == null ? void 0 : rootQuery.definition;
37490
- if (!(viewDef instanceof QB.ASTArrowQueryDefinition)) {
37681
+ const viewDef = rootQuery.definition;
37682
+ if (!(viewDef instanceof malloyQueryBuilder.ASTArrowQueryDefinition)) {
37491
37683
  return null;
37492
37684
  }
37493
37685
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -37523,6 +37715,7 @@ function SearchResultList({
37523
37715
  field,
37524
37716
  path
37525
37717
  }) => /* @__PURE__ */ jsxRuntime.jsx(FieldTokenWithActions, {
37718
+ rootQuery,
37526
37719
  field,
37527
37720
  path,
37528
37721
  viewDef
@@ -37549,6 +37742,7 @@ const getSublabelFromPath = (source, path) => {
37549
37742
  return path.length > 0 ? `joined to ${[...path.slice(0, -1), source.name].join(" > ")}` : void 0;
37550
37743
  };
37551
37744
  function FieldGroupList({
37745
+ rootQuery,
37552
37746
  source,
37553
37747
  fieldItems,
37554
37748
  fieldGroupType
@@ -37568,11 +37762,8 @@ function FieldGroupList({
37568
37762
  group
37569
37763
  }) => group === fieldGroupType)) == null ? void 0 : _a2.items) ?? [];
37570
37764
  }, [fieldGroupsByKindByPath, fieldGroupType]);
37571
- const {
37572
- rootQuery
37573
- } = React__namespace.useContext(QueryEditorContext);
37574
- const viewDef = rootQuery == null ? void 0 : rootQuery.definition;
37575
- if (!(viewDef instanceof QB.ASTArrowQueryDefinition)) {
37765
+ const viewDef = rootQuery.definition;
37766
+ if (!(viewDef instanceof malloyQueryBuilder.ASTArrowQueryDefinition)) {
37576
37767
  return null;
37577
37768
  }
37578
37769
  return /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -37588,6 +37779,7 @@ function FieldGroupList({
37588
37779
  field,
37589
37780
  path
37590
37781
  }) => /* @__PURE__ */ jsxRuntime.jsx(FieldTokenWithActions, {
37782
+ rootQuery,
37591
37783
  field,
37592
37784
  path,
37593
37785
  viewDef
@@ -37600,7 +37792,8 @@ function SourcePanel({
37600
37792
  onRefresh
37601
37793
  }) {
37602
37794
  const {
37603
- source
37795
+ source,
37796
+ rootQuery
37604
37797
  } = React__namespace.useContext(QueryEditorContext);
37605
37798
  const [searchQuery, setSearchQuery] = React__namespace.useState("");
37606
37799
  const {
@@ -37623,7 +37816,7 @@ function SourcePanel({
37623
37816
  return [];
37624
37817
  }, [fieldItems, searchQuery]);
37625
37818
  const isSearchActive = !!searchQuery;
37626
- if (!source) {
37819
+ if (!source || !rootQuery) {
37627
37820
  return null;
37628
37821
  }
37629
37822
  return /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -37678,6 +37871,7 @@ function SourcePanel({
37678
37871
  className: "mly78zum5 mlydt5ytf mlyysyzu8 mly1iyjqo2"
37679
37872
  },
37680
37873
  children: isSearchActive ? /* @__PURE__ */ jsxRuntime.jsx(SearchResultList, {
37874
+ rootQuery,
37681
37875
  source,
37682
37876
  items: searchResultItems
37683
37877
  }) : /* @__PURE__ */ jsxRuntime.jsxs(AccordionList, {
@@ -37694,6 +37888,7 @@ function SourcePanel({
37694
37888
  color: "cyan"
37695
37889
  }),
37696
37890
  children: /* @__PURE__ */ jsxRuntime.jsx(FieldGroupList, {
37891
+ rootQuery,
37697
37892
  source,
37698
37893
  fieldItems,
37699
37894
  fieldGroupType: "dimension"
@@ -37710,6 +37905,7 @@ function SourcePanel({
37710
37905
  color: "green"
37711
37906
  }),
37712
37907
  children: /* @__PURE__ */ jsxRuntime.jsx(FieldGroupList, {
37908
+ rootQuery,
37713
37909
  source,
37714
37910
  fieldItems,
37715
37911
  fieldGroupType: "measure"
@@ -37726,6 +37922,7 @@ function SourcePanel({
37726
37922
  color: "purple"
37727
37923
  }),
37728
37924
  children: /* @__PURE__ */ jsxRuntime.jsx(FieldGroupList, {
37925
+ rootQuery,
37729
37926
  source,
37730
37927
  fieldItems,
37731
37928
  fieldGroupType: "view"