react-semaphor 0.1.507 → 0.1.508
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DATA_APP_SDK.md +56 -0
- package/dist/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +194 -172
- package/dist/appearance/index.cjs +1 -1
- package/dist/appearance/index.js +1 -1
- package/dist/appearance-runtime/index.cjs +1 -1
- package/dist/appearance-runtime/index.js +1 -1
- package/dist/brand-studio/index.cjs +2 -2
- package/dist/brand-studio/index.js +139 -119
- package/dist/briefings/index.cjs +1 -1
- package/dist/briefings/index.js +3 -3
- package/dist/chunks/appearance-context-DzqCdhB4.cjs +1 -0
- package/dist/chunks/{appearance-context-XviHOhWJ.js → appearance-context-VJdrKi7r.js} +2 -1
- package/dist/chunks/{appearance-runtime-provider-D0xVQWnH.js → appearance-runtime-provider-CC4HT2Gi.js} +2 -2
- package/dist/chunks/{appearance-runtime-provider-Ca8rxO86.cjs → appearance-runtime-provider-D5pkvgE4.cjs} +1 -1
- package/dist/chunks/calculated-field-identity-BiTGmnST.cjs +1 -0
- package/dist/chunks/calculated-field-identity-CJL54uFx.js +1373 -0
- package/dist/chunks/{constants-NUleP4DY.js → card-config-utils-Bq1enstT.js} +260 -260
- package/dist/chunks/card-config-utils-CMO4_zVs.cjs +1 -0
- package/dist/chunks/{dashboard-briefing-launcher-DXTpU85p.js → dashboard-briefing-launcher-B9l0ZAbv.js} +12 -12
- package/dist/chunks/{dashboard-briefing-launcher-C8nDSDnV.cjs → dashboard-briefing-launcher-C4zsM3Hd.cjs} +1 -1
- package/dist/chunks/{dashboard-controls-CyL0yimg.js → dashboard-controls-BCQv4xWM.js} +16 -14
- package/dist/chunks/dashboard-controls-CWwllVOe.cjs +52 -0
- package/dist/chunks/{dashboard-json-5Jr3RudV.js → dashboard-json-BtU_q_0A.js} +9 -9
- package/dist/chunks/dashboard-json-DVj2xLsH.cjs +1 -0
- package/dist/chunks/edit-dashboard-visual-CO2IVBOq.cjs +172 -0
- package/dist/chunks/{edit-dashboard-visual-C7X-um9g.js → edit-dashboard-visual-RgFUx-py.js} +1986 -1990
- package/dist/chunks/{editor-action-buttons-CcDm8nA5.cjs → editor-action-buttons-BE8Fby6n.cjs} +2 -2
- package/dist/chunks/{editor-action-buttons-C5Wja_J4.js → editor-action-buttons-D-MaqTIs.js} +6 -6
- package/dist/chunks/field-aggregations-DUb0NU6c.js +1229 -0
- package/dist/chunks/field-aggregations-jSi77h9Z.cjs +1 -0
- package/dist/chunks/{field-dependencies-DVl2p1Nm.js → field-dependencies-Cl97kkHy.js} +30 -34
- package/dist/chunks/{field-dependencies-r_U0CGQ-.cjs → field-dependencies-DIab72rQ.cjs} +1 -1
- package/dist/chunks/{index-BVr4fcCB.js → index-0pdaQ9e1.js} +5 -5
- package/dist/chunks/index-BaIrLSBb.cjs +1422 -0
- package/dist/chunks/{index-De2QNsqV.js → index-ByiS9sB4.js} +45343 -43665
- package/dist/chunks/{index-C9KXfCkC.js → index-CLIro-EG.js} +3 -0
- package/dist/chunks/index-Cx3qmRUB.cjs +1 -0
- package/dist/chunks/{index-BlYf8gNa.cjs → index-DhlVxvyI.cjs} +1 -1
- package/dist/chunks/{matrix-card-DACDwdTq.js → matrix-card-CnKQpnsj.js} +1 -1
- package/dist/chunks/{matrix-card-CRXcmAjp.cjs → matrix-card-U4c72doZ.cjs} +1 -1
- package/dist/chunks/{matrix-control-sources-ClQzIk7E.js → matrix-control-sources-CRRdP03Q.js} +165 -134
- package/dist/chunks/matrix-control-sources-FjxGIbqk.cjs +1 -0
- package/dist/chunks/{matrix-formatter-7GLTcBuy.cjs → matrix-formatter-CveLJo6S.cjs} +1 -1
- package/dist/chunks/{matrix-formatter-xsq7n_e6.js → matrix-formatter-ZVS5QOuq.js} +2 -2
- package/dist/chunks/matrix-member-presentation-CFHjdrxT.cjs +1 -0
- package/dist/chunks/matrix-member-presentation-CzGZJd3a.js +182 -0
- package/dist/chunks/matrix-operation-contract-DoiWTUbT.cjs +1 -0
- package/dist/chunks/matrix-operation-contract-xL8IhFzp.js +1802 -0
- package/dist/chunks/{pivot-header-presentation-3wqWChFd.cjs → pivot-header-presentation-Cxz8-06f.cjs} +1 -1
- package/dist/chunks/{pivot-header-presentation-D44ODZGn.js → pivot-header-presentation-DVylCBHB.js} +2 -2
- package/dist/chunks/{pivot-result-lifecycle-DZ0ZSMoM.cjs → pivot-result-lifecycle-BiERyXnS.cjs} +1 -1
- package/dist/chunks/{pivot-result-lifecycle-BSmqVkVG.js → pivot-result-lifecycle-CmjpW7qG.js} +1 -1
- package/dist/chunks/{report-preferences-dialog-xADifRXs.js → report-preferences-dialog-BbkXcnnn.js} +4 -4
- package/dist/chunks/report-preferences-dialog-C9rpWgQZ.cjs +1 -0
- package/dist/chunks/{search-BHsQIWBV.js → selection-reducer-B94WgZ9V.js} +55 -11
- package/dist/chunks/selection-reducer-CGKKsaPa.cjs +26 -0
- package/dist/chunks/{semantic-format-BhIL1PXP.cjs → semantic-format-BzH69TRq.cjs} +1 -1
- package/dist/chunks/{semantic-format-C3amkGmY.js → semantic-format-CBlRO8Aw.js} +1 -1
- package/dist/chunks/{switch-DHGiC0aU.js → switch-CD4uGTZI.js} +7450 -7694
- package/dist/chunks/switch-iC1x2dcE.cjs +134 -0
- package/dist/chunks/token-types-Ahh5u4iT.cjs +1 -0
- package/dist/chunks/token-types-CPde8_LG.js +8 -0
- package/dist/chunks/{update-policy-Cc9h57pA.cjs → update-policy-COjFudhl.cjs} +1 -1
- package/dist/chunks/{update-policy-eTcz52jO.js → update-policy-D9q1Tz8k.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +3 -3
- package/dist/dashboard-authoring/index.js +734 -622
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +3 -3
- package/dist/data-app-codegen/index.cjs +1 -1
- package/dist/data-app-codegen/index.js +2 -2
- package/dist/data-app-codegen-node/index.cjs +94 -92
- package/dist/data-app-codegen-node/index.js +337 -333
- package/dist/data-app-sdk/index.cjs +9 -9
- package/dist/data-app-sdk/index.js +1091 -969
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +104 -96
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +2 -2
- package/dist/format-utils/index.cjs +1 -1
- package/dist/format-utils/index.js +8 -8
- package/dist/index.cjs +1 -1
- package/dist/index.js +15 -15
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/brand-studio/brand-studio-draft.d.ts +3 -1
- package/dist/types/components/dashboard/card-selection-pill.d.ts +5 -0
- package/dist/types/components/dashboard/dashboard-container.d.ts +1 -1
- package/dist/types/components/dashboard/drill-breadcrumb.d.ts +1 -0
- package/dist/types/components/dashboard/drill-navigation-controls.d.ts +3 -3
- package/dist/types/components/interactions/applied-filters-display.d.ts +6 -1
- package/dist/types/components/interactions/click-to-filter-review-dialog.d.ts +21 -0
- package/dist/types/components/interactions/dashboard-drill-host.d.ts +13 -0
- package/dist/types/components/interactions/filter-badge-tooltip.d.ts +4 -4
- package/dist/types/components/interactions/insight-modal.d.ts +4 -14
- package/dist/types/components/interactions/insight-viewer.d.ts +7 -19
- package/dist/types/components/interactions/interactions-sheet.d.ts +6 -0
- package/dist/types/components/interactions/panels/click-to-filter-panel.d.ts +20 -0
- package/dist/types/components/interactions/reusable/interaction-selection-popover.d.ts +2 -2
- package/dist/types/components/interactions/sheet/action-editor.d.ts +17 -0
- package/dist/types/components/interactions/sheet/action-meta.d.ts +45 -0
- package/dist/types/components/interactions/sheet/action-picker.d.ts +7 -0
- package/dist/types/components/interactions/sheet/click-outcome-preview.d.ts +10 -0
- package/dist/types/components/interactions/sheet/interactions-home.d.ts +28 -0
- package/dist/types/components/interactions/sheet/sheet-parts.d.ts +37 -0
- package/dist/types/components/surfboard/filter/dashboard-filter-mapping-panel.d.ts +28 -1
- package/dist/types/components/surfboard/filter/selection-chip.d.ts +11 -0
- package/dist/types/components/surfboard/filter/selection-filter-section.d.ts +4 -0
- package/dist/types/components/surfboard/filter/use-dashboard-filter-mapping-popover.d.ts +3 -0
- package/dist/types/components/ui/resizable.d.ts +1 -1
- package/dist/types/components/visual/matrix-table/matrix-interaction-actions.d.ts +13 -1
- package/dist/types/components/visual/matrix-table/matrix-selection-click.d.ts +6 -0
- package/dist/types/data-app-sdk/adapters.d.ts +3 -2
- package/dist/types/data-app-sdk/builders.d.ts +2 -1
- package/dist/types/data-app-sdk/contracts.d.ts +44 -2
- package/dist/types/data-app-sdk/index.d.ts +1 -0
- package/dist/types/data-app-sdk/query-request.d.ts +7 -2
- package/dist/types/data-app-sdk/selection.d.ts +2 -0
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.js +24 -23
- package/dist/types/lib/appearance/types.d.ts +3 -1
- package/dist/types/lib/briefings/briefing-attachment-model.d.ts +0 -2
- package/dist/types/lib/contexts/interactions-popover-context.d.ts +1 -8
- package/dist/types/lib/dashboard/click-to-filter-card-references.d.ts +23 -0
- package/dist/types/lib/dashboard-inputs/build-normalized-dashboard-inputs.d.ts +16 -2
- package/dist/types/lib/dashboard-inputs/build-selection-dashboard-inputs.d.ts +31 -0
- package/dist/types/lib/dashboard-inputs/click-to-filter-emitted-fields.d.ts +17 -0
- package/dist/types/lib/dashboard-inputs/click-to-filter-mapping-draft.d.ts +99 -0
- package/dist/types/lib/dashboard-inputs/click-to-filter-sheet-reach.d.ts +12 -0
- package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-authoring.d.ts +18 -1
- package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-candidate-metadata.d.ts +4 -1
- package/dist/types/lib/dashboard-inputs/dashboard-input-scope.d.ts +10 -0
- package/dist/types/lib/dashboard-inputs/dashboard-input-snapshot.d.ts +8 -1
- package/dist/types/lib/dashboard-inputs/index.d.ts +1 -0
- package/dist/types/lib/dashboard-inputs/resolve-dashboard-input-context.d.ts +18 -7
- package/dist/types/lib/dashboard-inputs/resolve-field-date-comparison-coverage.d.ts +5 -2
- package/dist/types/lib/dashboard-inputs/resolve-selection-input.d.ts +77 -0
- package/dist/types/lib/dashboard-inputs/selection-targets.d.ts +26 -0
- package/dist/types/lib/dashboard-inputs/transient-input-context.d.ts +102 -0
- package/dist/types/lib/dashboard-navigation/build-carried-click-context.d.ts +50 -0
- package/dist/types/lib/dashboard-navigation/describe-carried-context.d.ts +11 -0
- package/dist/types/lib/dashboard-navigation/index.d.ts +1 -0
- package/dist/types/lib/dashboard-navigation/navigation-state.d.ts +120 -0
- package/dist/types/lib/dashboard-navigation/run-one-off-drill.d.ts +11 -0
- package/dist/types/lib/dashboard-navigation/use-transient-contexts.d.ts +17 -0
- package/dist/types/lib/dashboard-view-state/card-view-state.d.ts +48 -0
- package/dist/types/lib/dashboard-view-state/drill-path.d.ts +20 -0
- package/dist/types/lib/dashboard-view-state/index.d.ts +2 -0
- package/dist/types/lib/download-pdf.d.ts +0 -3
- package/dist/types/lib/formatters/metric-formatting.d.ts +1 -1
- package/dist/types/lib/hooks/ai/dashboard-context.d.ts +15 -8
- package/dist/types/lib/hooks/chartjs/use-chart-blur.d.ts +10 -2
- package/dist/types/lib/hooks/interactions/{use-event-engine.d.ts → use-drill-actions.d.ts} +28 -7
- package/dist/types/lib/hooks/selection/use-active-selections.d.ts +15 -0
- package/dist/types/lib/hooks/selection/use-click-to-filter-mapping-draft.d.ts +20 -0
- package/dist/types/lib/hooks/selection/use-selection-click.d.ts +34 -0
- package/dist/types/lib/hooks/selection/use-selection-gestures.d.ts +38 -0
- package/dist/types/lib/hooks/selection/use-table-row-selection.d.ts +46 -0
- package/dist/types/lib/hooks/use-dashboard-card.d.ts +0 -2
- package/dist/types/lib/hooks/use-dashboard-filter-mapping-candidates.d.ts +18 -0
- package/dist/types/lib/hooks/use-dashboard-frame-query.d.ts +0 -1
- package/dist/types/lib/hooks/use-dashboard.d.ts +1 -3
- package/dist/types/lib/hooks/use-interactions-popover.d.ts +1 -8
- package/dist/types/lib/hooks/use-resolved-card-config.d.ts +6 -0
- package/dist/types/lib/interactions/click-outcome.d.ts +25 -0
- package/dist/types/lib/interactions/get-click-context-from-chartjs.d.ts +3 -1
- package/dist/types/lib/interactions/get-click-context-from-matrix.d.ts +1 -1
- package/dist/types/lib/interactions/get-click-context-from-table.d.ts +7 -0
- package/dist/types/lib/interactions/interaction-utils.d.ts +17 -1
- package/dist/types/lib/matrix-table/build-matrix-drill-to-detail.d.ts +15 -0
- package/dist/types/lib/matrix-table/matrix-card-interactions.d.ts +14 -3
- package/dist/types/lib/query-context/build-card-query-context.d.ts +19 -8
- package/dist/types/lib/query-context/build-dashboard-execution-snapshot.d.ts +5 -3
- package/dist/types/lib/query-context/build-dashboard-frame-base-query-contexts.d.ts +12 -4
- package/dist/types/lib/query-context/compile-selection-filters.d.ts +5 -0
- package/dist/types/lib/query-context/dashboard-filter-mapping-resolution.d.ts +46 -0
- package/dist/types/lib/query-context/filter-group-utils.d.ts +3 -0
- package/dist/types/lib/query-context/resolve-runtime-card-filters.d.ts +29 -0
- package/dist/types/lib/selection/click-to-filter-authoring-support.d.ts +9 -0
- package/dist/types/lib/selection/selection-from-click-context.d.ts +41 -0
- package/dist/types/lib/selection/selection-labels.d.ts +3 -0
- package/dist/types/lib/selection/selection-notices.d.ts +9 -0
- package/dist/types/lib/selection/selection-reducer.d.ts +46 -0
- package/dist/types/lib/stores/dashboard-store.d.ts +62 -17
- package/dist/types/lib/stores/editor-store.d.ts +1 -2
- package/dist/types/lib/stores/index.d.ts +0 -2
- package/dist/types/lib/types/common-types.d.ts +60 -6
- package/dist/types/lib/types/explorer-types.d.ts +1 -22
- package/dist/types/lib/types/interaction-types.d.ts +6 -198
- package/dist/types/lib/utils/calculate-context-aware-filters.d.ts +21 -12
- package/dist/types/lib/utils/card-utils.d.ts +11 -0
- package/dist/types/lib/utils/date-hierarchy-utils.d.ts +3 -1
- package/dist/types/lib/utils/drag-and-drop-utils.d.ts +1 -1
- package/dist/types/lib/utils/interaction-icons.d.ts +1 -1
- package/dist/types/shared/analytics-protocol/execution-input-schemas.d.ts +32 -32
- package/dist/types/shared/analytics-protocol/index.d.ts +2 -0
- package/dist/types/shared/analytics-protocol/selection-contract.d.ts +100 -0
- package/dist/types/shared/analytics-protocol/selection-filter-compiler.d.ts +12 -0
- package/dist/types/shared/dashboard-authoring/apply-group-by-override.d.ts +19 -0
- package/dist/types/shared/dashboard-authoring/click-to-filter-settings.d.ts +88 -0
- package/dist/types/shared/dashboard-authoring/contracts.d.ts +8 -0
- package/dist/types/shared/dashboard-authoring/index.d.ts +3 -0
- package/dist/types/shared/dashboard-authoring/linked-click-to-filter-overrides.d.ts +32 -0
- package/dist/types/shared/format-utils/matrix-continuation.d.ts +3 -3
- package/package.json +1 -1
- package/src/data-app-sdk/README.md +58 -1
- package/dist/chunks/appearance-context-tNjvTJj3.cjs +0 -1
- package/dist/chunks/calculated-field-identity-BTpUqfEu.js +0 -1276
- package/dist/chunks/calculated-field-identity-rMuXuzEY.cjs +0 -1
- package/dist/chunks/constants-vtu7_IUo.cjs +0 -1
- package/dist/chunks/dashboard-controls-DlxeddZN.cjs +0 -52
- package/dist/chunks/dashboard-json-DhS4yJfc.cjs +0 -1
- package/dist/chunks/edit-dashboard-visual-X3OCnivL.cjs +0 -172
- package/dist/chunks/field-aggregations-BU_3gHKR.js +0 -957
- package/dist/chunks/field-aggregations-CDCamEsQ.cjs +0 -1
- package/dist/chunks/index-C8XCKzB6.cjs +0 -1
- package/dist/chunks/index-DSa6RSdg.cjs +0 -1417
- package/dist/chunks/matrix-control-sources-CeC5EMyq.cjs +0 -1
- package/dist/chunks/matrix-member-presentation-E2B4k3ws.cjs +0 -1
- package/dist/chunks/matrix-member-presentation-qiHxv67e.js +0 -105
- package/dist/chunks/matrix-operation-contract-Cqy4EW2H.js +0 -1638
- package/dist/chunks/matrix-operation-contract-D9dLX-Wr.cjs +0 -1
- package/dist/chunks/report-preferences-dialog-7Vsc_fsG.cjs +0 -1
- package/dist/chunks/search-BqqhaMx9.cjs +0 -26
- package/dist/chunks/switch-BytP6QY8.cjs +0 -139
- package/dist/types/components/interactions/configuration-popover.d.ts +0 -1
- package/dist/types/components/interactions/interaction-card.d.ts +0 -59
- package/dist/types/components/interactions/interaction-event-handler.d.ts +0 -11
- package/dist/types/components/interactions/interactions-list.d.ts +0 -50
- package/dist/types/components/interactions/panels/cross-filter-panel.d.ts +0 -24
- package/dist/types/components/interactions/panels/inline-drill-panel.d.ts +0 -24
- package/dist/types/components/interactions/selectors/action-selector.d.ts +0 -31
- package/dist/types/components/interactions/selectors/trigger-selector.d.ts +0 -38
- package/dist/types/components/surfboard/filter/click-filter-section.d.ts +0 -5
- package/dist/types/lib/interactions/build-interaction-event.d.ts +0 -25
- package/dist/types/lib/interactions/convert-click-filters-to-filter-group.d.ts +0 -10
- package/dist/types/lib/interactions/execute-interaction-event.d.ts +0 -80
- package/dist/types/lib/interactions/field-utils.d.ts +0 -11
- package/dist/types/lib/interactions/handle-chart-click.d.ts +0 -75
- package/dist/types/lib/interactions/linked-interaction-utils.d.ts +0 -14
- package/dist/types/lib/interactions/source-card-filter-utils.d.ts +0 -9
- package/dist/types/lib/stores/drill-actions.d.ts +0 -139
- package/dist/types/lib/stores/interaction-store.d.ts +0 -113
- package/dist/types/lib/stores/pointer-interaction-store.d.ts +0 -18
package/dist/chunks/{editor-action-buttons-CcDm8nA5.cjs → editor-action-buttons-BE8Fby6n.cjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const J=require("./x-B6ghREd2.cjs"),C=require("react"),r=require("./switch-
|
|
1
|
+
"use strict";const J=require("./x-B6ghREd2.cjs"),C=require("react"),r=require("./switch-iC1x2dcE.cjs"),y=require("./index-BaIrLSBb.cjs"),e=require("react/jsx-runtime");require("./card-config-utils-CMO4_zVs.cjs");const Te=require("./validators-DVYAnnX0.cjs");require("./matrix-operation-contract-DoiWTUbT.cjs");require("../value-format-preferences/index.cjs");const ge=require("./selection-reducer-CGKKsaPa.cjs"),Fe=require("./index-DhlVxvyI.cjs"),Se=require("./save-3dYRmehL.cjs");/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const ke=J.createLucideIcon("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);function Ie(s){const[a,i]=C.useState(null),[n,c]=C.useState(null),u=y.useEnsureReactGlobals();return C.useEffect(()=>{if(!s||s.trim()===""){i(null),c(null);return}if(!u)return;(async()=>{try{if(!s.startsWith("http://")&&!s.startsWith("https://"))throw new Error(`Invalid URL format: ${s}`);try{new URL(s)}catch{throw new Error(`Invalid URL: ${s}`)}const p=`${s.endsWith("/")?s:`${s}/`}index.js`;try{if(!(await fetch(p,{method:"HEAD"})).ok)throw new Error(`Module not found at ${p}`)}catch{}const v=await import(p);if(typeof v.useChartStore!="function")throw new Error("useChartStore is not a function");i(()=>v.useChartStore),c(null)}catch(h){const p=h instanceof Error?h.message:"Unknown error";console.error("Failed to load remote chart store:",p),c(p),i(null)}})()},[s,u]),a}function Le(s,a){if(s.length===0)return"";const i=s.find(n=>{var c,u;return((c=n.customCardPreferences)==null?void 0:c.visualType)==="multiple"||!!((u=n.customCardPreferences)!=null&&u.dataInputCardIds)});if(i)return i.id;if(a){const n=s.find(c=>c.id===a);if(n){const c=n.tabTitle;if(c=="All__Header")return s[0].id;if(c&&c.endsWith("__Header")){const m=c.split("__")[0],h=s.find(p=>p.tabTitle===m);return h?h.id:s[0].id}return a}}return s[0].id}const Ae=s=>{if(!s||!("detailTableBackup"in s))return s;const{detailTableBackup:a,...i}=s;return i};async function be(s,a,i,n,c="Opening library visual..."){if(!a||!i)throw new Error("Missing auth token or visual ID");const u=["resource-by-id","visual",i],m=n.getQueryData(u);if(m)return console.log("Using cached visual data for:",i),{data:m,fromCache:!0};console.log("Fetching visual data from network for:",i);const h=r.ue.loading(c,{position:"top-center"});try{const p=await fetch(`${s}/management/v1/visuals/${i}`,{headers:{Authorization:`Bearer ${a}`}});if(!p.ok)throw new Error("Failed to load visual");const v=await p.json();return n.setQueryData(u,v),r.ue.dismiss(h),{data:v,fromCache:!1}}catch(p){throw r.ue.dismiss(h),p}}function Ne(s){if(typeof s=="string")return JSON.parse(s);if(typeof s=="object")return s;throw new Error("Invalid frame object format")}function _e(s,a){var u,m;const i=(s==null?void 0:s.frameObject)??((u=s==null?void 0:s.visual)==null?void 0:u.frameObject);if(!i)return!1;const n=Ne(i);if(!(n!=null&&n.cards)||n.cards.length===0)return!1;const c=(m=n.cards)==null?void 0:m.find(h=>h.id===n.activeCardId);return c?(y.setupEditorWithCard({...a,frame:n,card:c,visualId:(s==null?void 0:s.id)||n.visualId}),!0):!1}function qe(){const s=r.useEditorStore(n=>{var c;return((c=n.card.customCardPreferences)==null?void 0:c.url)||""}),a=Ie(s);return{getUpdatedFrame:C.useCallback(()=>{var L;y.flushPendingEditorDrafts();const{frame:n,card:c,isDevMode:u,isShowingVisual:m,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:b,selectedConnectionId:f}=r.useEditorStore.getState(),j=c.sql,D=(L=a==null?void 0:a.getState())==null?void 0:L.settings,k=r.buildSavedEditorCard(c,{isDevMode:u,cardSql:j,isShowingVisual:m,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:b,selectedConnectionId:f,remoteChartSettings:D,stripConfig:Ae}),E=n.cards.map(O=>O.id===c.id?k:O);return{...n,cards:E,activeCardId:Le(E,n.activeCardId)}},[a])}}function ae(){const{authToken:s,tokenProps:a}=y.useSemaphorContext(),i=y.useQueryClient(),n=y.useAddFrameWithFreshSemanticExecutionPayload(),c=y.useSelectedVisual(),{selectVisual:u}=y.useManagementActions(),{setFrame:m,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:b,updateDataSource:f,setQueryResultColumns:j,setSelectedConnectionId:D,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:L,setSelectedDatamodelId:O,setFilterValues:H,setInlineFilterValuesMap:U,setApplyFilters:R,clearEditorContext:W}=r.useEditorActions(),{setIsDashboardEditing:V,setIsVisualEditing:o,setSelectedFrameId:w,clearSelectedFrameId:Q}=r.useDashboardActions(),M=r.useDashboardStore(A=>A.selectedSheetId),K=r.useDashboardStore(A=>A.selectedFrameId),P=r.useDashboardStore(A=>A.dashboard),X=r.useDashboardStore(A=>A.filterValues),B=r.useDashboardStore(A=>A.inlineFilterValuesMap),Y=y.useVisualById((c==null?void 0:c.id)||"",{enabled:!!(c!=null&&c.id)&&!!(s!=null&&s.accessToken)}),Z=C.useCallback(async A=>{try{u(A),Q(),W();const{data:I,fromCache:$}=await be(a.apiServiceUrl,(s==null?void 0:s.accessToken)||"",A.id,i,"Opening library visual...");if(!_e(I,{setFrame:m,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:b,updateDataSource:f,setQueryResultColumns:j,setSelectedConnectionId:D,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:L,setSelectedDatamodelId:O,setFilterValues:H,setInlineFilterValuesMap:U,setApplyFilters:R,setIsDashboardEditing:V,setIsVisualEditing:o,dashboard:P,selectedSheetId:M,selectedFrameId:K,filterValues:X,inlineFilterValuesMap:B}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:$}}catch(I){return console.error("Error editing visual:",I),{success:!1,error:"Failed to load visual for editing"}}},[s==null?void 0:s.accessToken,a.apiServiceUrl,i,u,m,h,V,o,p,v,b,f,j,D,k,E,L,O,H,U,R,W,Q,P,M,K,X,B]),ne=C.useCallback(async A=>{var $;const I=q=>(r.ue.error(q),{success:!1,error:q});try{if(u(A),!M)return I("No sheet selected. Please select a sheet first.");const{data:q,fromCache:oe}=await be(a.apiServiceUrl,(s==null?void 0:s.accessToken)||"",A.id,i,"Adding visual to dashboard..."),re=(q==null?void 0:q.frameObject)??(($=q==null?void 0:q.visual)==null?void 0:$.frameObject);if(!re)return I("Visual has no frame data");const z=Ne(re);if(!(z!=null&&z.cards)||z.cards.length===0)return I("Visual frame is malformed");const te={...y.cloneLinkedFrameWithSourceMapping(z),visualId:A.id};return await n(M,te,"end"),V(!0),w(te.id),{success:!0,fromCache:oe}}catch(q){return console.error("Error adding visual:",q),I(q instanceof Error?q.message:"Failed to add visual to dashboard")}},[s==null?void 0:s.accessToken,a.apiServiceUrl,i,u,M,V,w,n]);return{visual:Y.data,isLoading:Y.isLoading,isError:Y.isError,error:Y.error,handleEditLibraryVisual:Z,handleAddLibraryVisual:ne,getUpdatedFrame:qe().getUpdatedFrame,refetch:Y.refetch}}function Be(){const s=r.useEditorStore(m=>m.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:i,setSelectedSchemaName:n,setSelectedTableName:c,setSelectedDatamodelId:u}=r.useEditorActions();C.useEffect(()=>{var D;if(!s)return;const{tableName:m,schemaName:h,databaseName:p,connectionId:v}=y.extractTableMetadata(s),b=(D=s.selectedEntities)==null?void 0:D[0],j=(b==null?void 0:b.type)==="model"&&"id"in b?b.id:"";a(v||""),i(p||""),n(h||""),c(m||""),u(j)},[s,a,i,n,c,u])}function Me(s,a){return{...s,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?s.customCardPreferences:void 0,visualizationMode:"builtin",type:a?s.type:"bar"}}function Ee(){const{setTempQueryData:s}=r.useEditorActions(),a=y.useQueryClient(),i=r.useEditorStore(U=>U.tempQueryData),n=r.useEditorStore(U=>U.card),c=y.useEffectiveEditorCardType(),u=C.useMemo(()=>c!==n.type?{...n,type:c}:n,[n,c]),{queryKey:m}=y.useEditorCardQuery(u),{setCardSql:h,setSqlGen:p,setCardPython:v,setCardCustomCfg:b,setCardPreferences:f,clearQueryConfig:j,setCardConfig:D,setCardType:k,setFrame:E,setCard:L,setActiveTabCardId:O}=r.useEditorActions();function H(){var Q,M,K,P;const U=a.getQueryData(m);i!=null&&i.queryData||s({queryKey:m,queryData:U}),a.setQueryData(m,null),a.removeQueries({queryKey:m,exact:!0}),h(""),p({}),j(),D(void 0),v(""),b(""),f({});const R=r.useEditorStore.getState().frame,W=r.useEditorStore.getState().card,V=Fe.findCustomVisualConfigCard(R,W),o=((Q=V==null?void 0:V.customCardPreferences)==null?void 0:Q.visualType)==="multiple"||!!((M=V==null?void 0:V.customCardPreferences)!=null&&M.dataInputCardIds)||(((K=V==null?void 0:V.customCardPreferences)==null?void 0:K.minInputs)||0)>1||(((P=V==null?void 0:V.customCardPreferences)==null?void 0:P.maxInputs)||0)>1,w=Me(W,o);E({...R,cards:R.cards.map(X=>X.id===w.id?w:X)}),O(w.id),L(w),o||k("bar")}return H}function Oe({type:s,isLinked:a,className:i,showLabel:n=!1,showLocal:c=!1}){const u=r.useDashboardStore(E=>E.selectedFrameId),m=y.useManagementStore(E=>E.selectedVisual),h=r.useEditorStore(E=>E.frame);let p;if(s)p=s;else if(a!==void 0)p=a?"linked":"library";else if(!!!(h!=null&&h.visualId||m!=null&&m.id)&&u)p="local";else if(m&&!u)p="library";else if(h!=null&&h.visualId&&u)p="linked";else if(m!=null&&m.id&&u)p="library";else return null;if(p==="local"&&!c)return null;const v={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},b={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},f={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},j={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},D={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(ke,{className:"h-3.5 w-3.5"}),library:e.jsx(je,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(r.TooltipProvider,{children:e.jsxs(r.Tooltip,{delayDuration:300,children:[e.jsx(r.TooltipTrigger,{asChild:!0,children:e.jsxs(y.Badge,{variant:"outline",className:r.cn("cursor-help select-none transition-all",v[p],i),children:[D[p],n&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[p]})]})}),e.jsxs(r.TooltipContent,{side:"bottom",className:r.cn("max-w-xs",f[p]),children:[e.jsx(r.TooltipArrow,{className:j[p]}),e.jsx("p",{children:b[p]})]})]})})}function we(s){const{control:a,onChange:i}=s;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(r.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:n=>i(n.target.value)})]})}function Ue(s){const{currentStep:a,labels:i}=s;return e.jsx("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:i.map((n,c)=>{const u=c+1,m=u===a,h=u<a;return e.jsxs(C.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:r.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",m?"border-foreground bg-foreground text-background":h?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:u}),e.jsx("span",{className:r.cn("text-[12px]",m?"font-medium text-foreground":"text-muted-foreground"),children:n})]}),c<i.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},n)})})})}function se(s){const{secondary:a,tertiary:i,primary:n}=s;return e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,i,n]})}function ze(s){const{control:a,scope:i,detail:n}=s;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(y.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[r.getFriendlyTypeOption(a.type).label," ·"," ",r.getControlOptionPreview(a)," ·"," ",r.getPlacementLabel(i,a.placement)]}),n?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:n}):null]})]})}function ye(s){const{control:a,defaultValue:i,availableFieldChoices:n,availableMetricChoices:c,previewControlDefinitions:u,previewControlValues:m,onControlChange:h,onLabelChange:p,onDefaultValueChange:v,onBack:b,onNext:f,nextDisabled:j}=s;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:a,onChange:p}),e.jsx(y.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:n,availableMetricChoices:c,previewControlDefinitions:u,previewControlValues:m,controlLifecycle:"create",onChange:h}),e.jsx(y.ControlDefaultValueEditor,{control:a,value:i,onChange:v,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:u,previewControlValues:m}),e.jsx(se,{secondary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:b,children:"Back"}),primary:e.jsx(r.Button,{type:"button",size:"xs",onClick:f,disabled:j,children:"Next"})})]})}const Re=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function Ce(s){const{text:a,ariaLabel:i}=s,[n,c]=C.useState(!1);return e.jsxs("button",{type:"button","aria-label":i,onClick:async()=>{try{await navigator.clipboard.writeText(a),c(!0),setTimeout(()=>c(!1),1200)}catch(u){console.error("Failed to copy",u)}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:n?"Copied":"Click to copy"})]})}function ve(s){const{control:a,scope:i,createdReference:n,explorerContent:c,sqlDescription:u,summaryDetail:m,onBack:h,onCancel:p,onDone:v}=s,b=Re.has(a.type),f=n.match(/\[\[param\.(.+?)\]\]/),j=f?`{{ param('${f[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ze,{control:a,scope:i,detail:m}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[b?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:c})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(Ce,{text:n,ariaLabel:"Copy SQL control reference"}),j?e.jsx(Ce,{text:j,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[u," ",e.jsx("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),e.jsx(se,{secondary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:h,children:"Back"}),tertiary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:p,children:"Cancel"}),primary:e.jsx(r.Button,{type:"button",size:"xs",onClick:v,children:"Done"})})]})}function Qe(s){const a=r.createBlankControl(s.scope,s.existingControls,s.reservedIds),i=s.type===a.type?{...a,label:r.DEFAULT_LABEL_BY_TYPE[s.type]}:{...r.applyControlTypeChange({controls:[{...a,label:r.DEFAULT_LABEL_BY_TYPE[s.type]}],controlId:a.id,nextType:s.type}).controls[0],label:r.DEFAULT_LABEL_BY_TYPE[s.type]};return{step:2,control:i,defaultValue:r.getDefaultValueForType(i,void 0)}}function $e({scope:s,controls:a,reservedControlIds:i,defaultValues:n,onChange:c,emptyMessage:u,initialCreateFlow:m=!1,usageByControlId:h,availableFieldChoices:p,availableMetricChoices:v,structuralParticipants:b,structuralParticipantIdsByControlId:f,card:j,allowedControlTypes:D,onCreateFlowActiveChange:k,onCreateFlowComplete:E}){const L=C.useMemo(()=>new Set(i||[]),[i]),O=r.getPlacementOptionsForScope(s),H=r.getDefaultPlacement(s),[U,R]=C.useState(null),[W,V]=C.useState(null),[o,w]=C.useState(()=>m?{step:1,control:r.createBlankControl(s,a,Array.from(L))}:null),Q=C.useRef({}),M=C.useRef(void 0),K=C.useRef(m),P=C.useMemo(()=>{const t=r.getFriendlyControlTypeOptions({scope:s,card:j});if(!D)return t;const d=new Set(D);return t.filter(l=>d.has(l.value))},[D,j,s]),X=C.useCallback(t=>{const d=r.getFriendlyControlTypeOptions({scope:s,card:j,includeType:D?void 0:t});if(!D)return d;const l=new Set(D);return d.filter(x=>l.has(x.value))},[D,j,s]),B=C.useCallback(t=>s==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[s]),Y=C.useMemo(()=>o?r.getEligibleParticipantsForStructuralControl(b||[],o.control.type):[],[o,b]),Z=C.useMemo(()=>{if(!o)return{fields:p||[],metrics:v||[]};if(!B(o.control.type))return{fields:p||[],metrics:v||[]};const t=o.selectedCardIds||[],d=r.getCompatibleStructuralChoiceCatalog({controlType:o.control.type,participants:b||[],selectedCardIds:t});return{fields:o.control.type==="field_selector"?d.choices.map(l=>({option:l,target:d.fieldTargetMap[l.value]})):[],metrics:o.control.type==="metric_selector"?d.choices.map(l=>({option:l,target:d.metricTargetMap[l.value]})):[]}},[p,v,o,B,b]);C.useEffect(()=>{k==null||k(!!o)},[o,k]),C.useEffect(()=>{const t=m&&!K.current;K.current=m,t&&(w({step:1,control:r.createBlankControl(s,a,Array.from(L))}),V(null),R(null))},[a,m,L,s]);const ne=t=>{if(!B(t.type))return{fields:p||[],metrics:v||[]};const d=(f==null?void 0:f[t.id])||[];if(d.length===0)return{fields:p||[],metrics:v||[]};const l=r.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:b||[],selectedCardIds:d});return{fields:t.type==="field_selector"?l.choices.map(x=>({option:x,target:l.fieldTargetMap[x.value]})):[],metrics:t.type==="metric_selector"?l.choices.map(x=>({option:x,target:l.metricTargetMap[x.value]})):[]}},A=t=>{if(!B(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const d=(f==null?void 0:f[t.control.id])||[],l=r.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:b||[],selectedCardIds:t.nextSelectedCardIds}),x=r.reconcileStructuralControlChoices({control:t.control,choices:l.choices}),S=Object.fromEntries(d.filter(N=>!t.nextSelectedCardIds.includes(N)).map(N=>[N,void 0]));return t.nextSelectedCardIds.length>0&&x.source.kind==="manual"&&x.source.options.length>0&&Object.assign(S,r.buildStructuralControlBindingsForParticipants({control:x,participants:b||[],selectedCardIds:t.nextSelectedCardIds,matrixTargetIds:t.matrixTargetIds})),{nextControl:x,cardBindingsById:S}},I=C.useCallback((t,d=n,l={type:"update"})=>{const x=t.map(S=>(r.resolveAuthoringControlDefaultValue({control:S,defaultValues:d}),r.syncSqlQueryControlExecutionRequirement(S)));c(x,d,l)},[n,c]),$=(t,d)=>{const l=a.find(F=>F.id===t);let x=a.map(F=>F.id!==t?F:d(F));const S=x.find(F=>F.id===t);let N,g;if(S&&(!l||r.structuralControlBindingsChanged({control:l},{control:S}))&&s==="dashboard"&&(S.type==="field_selector"||S.type==="metric_selector")){const F=(f==null?void 0:f[S.id])||[],ee=A({control:S,nextSelectedCardIds:F});x=x.map(G=>G.id===t?ee.nextControl:G),N=ee.cardBindingsById,g=[S.id]}else if(l&&(!S||!r.isStructuralSelectorControlType(S.type))&&s==="dashboard"&&(l.type==="field_selector"||l.type==="metric_selector")){const F=(f==null?void 0:f[l.id])||[];N=Object.fromEntries(F.map(ee=>[ee,void 0])),g=[l.id]}const T=x.find(F=>F.id===t);let _=n;if(l&&T){const F=r.resolveAuthoringControlDefaultValue({control:l,defaultValues:n});l.source.kind==="manual"&&T.source.kind==="sql_query"&&(Q.current[t]=F);const ee=F===void 0&&l.source.kind==="sql_query"&&T.source.kind==="manual"?Q.current[t]:F,G=r.getNextEditedControlDefaultValue({previousControl:l,nextControl:T,currentDefaultValue:ee});T.source.kind==="manual"&&(Q.current[t]=G),n&&(_={...n},G===void 0?delete _[t]:_[t]=G),x=x.map(he=>he.id===t?{...T,defaultValue:G}:he)}I(x,_,{type:"update",cardBindingsById:N,affectedBindingControlIds:g})},q=(t,d)=>{if(!d.trim())return;const l=r.normalizeDashboardInputVariableName(d);if(l===t||L.has(l)||a.some(N=>N.id===l&&N.id!==t))return;const x=a.map(N=>N.id===t?{...N,id:l}:N);if(!n){I(x,void 0,{type:"rename",oldId:t,newId:l});return}const S={...n};Object.prototype.hasOwnProperty.call(S,t)&&(S[l]=S[t],delete S[t]),I(x,S,{type:"rename",oldId:t,newId:l})},oe=t=>{const d=a.filter(x=>x.id!==t);if(!n){I(d,void 0,{type:"remove",controlId:t});return}const l={...n};delete l[t],I(d,l,{type:"remove",controlId:t})},re=C.useCallback(()=>{M.current=void 0,w({step:1,control:r.createBlankControl(s,a,Array.from(L))}),V(null),R(null)},[a,L,s]),z=t=>{w(d=>d&&(()=>{const l=t(d.control);d.control.source.kind==="manual"&&l.source.kind==="sql_query"&&(M.current=d.defaultValue);const x=d.defaultValue===void 0&&d.control.source.kind==="sql_query"&&l.source.kind==="manual"?M.current:d.defaultValue,S=r.getNextEditedControlDefaultValue({previousControl:d.control,nextControl:l,currentDefaultValue:x});return l.source.kind==="manual"&&(M.current=S),{...d,control:l,defaultValue:S}})())},te=t=>{w(d=>d&&(d.control.source.kind==="manual"&&(M.current=t),{...d,defaultValue:t}))},le=(()=>{if(!o)return!1;if(o.step===2&&B(o.control.type))return(o.selectedCardIds||[]).length>0&&r.hasStructuralMatrixTargets({participants:b||[],selectedCardIds:o.selectedCardIds||[],control:o.control,selected:o.matrixTargetIds});if(o.step!==2&&o.step!==3||!o.control.label.trim())return!1;const d=o.control.source.kind==="sql_query"?o.control:r.ensureManualSource(o.control);if(d.source.kind==="manual"&&(r.needsManualOptions(d)&&d.source.options.length===0||d.source.options.some(x=>x.label.trim().length===0||x.value.trim().length===0)))return!1;if(d.source.kind==="sql_query"){const{connectionId:l,sql:x,valueColumn:S}=d.source;return l.trim().length>0&&x.trim().length>0&&S.trim().length>0}return r.hasConcreteDefaultValue(r.getDefaultValueForType(d,o.defaultValue))})(),pe=()=>{var N;if(!o)return;const t=r.ensureManualSource(o.control),d=r.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(L)}),l={...t,id:d},x=s==="dashboard"&&(l.type==="field_selector"||l.type==="metric_selector")&&((N=o.selectedCardIds)!=null&&N.length)?r.buildStructuralControlBindingsForParticipants({control:l,participants:b||[],selectedCardIds:o.selectedCardIds,matrixTargetIds:o.matrixTargetIds}):void 0,S=r.getDefaultValueForType(l,o.defaultValue);w({step:s==="dashboard"&&(l.type==="field_selector"||l.type==="metric_selector")?4:3,control:l,defaultValue:S,createdControlId:d,selectedCardIds:o.selectedCardIds,matrixTargetIds:o.matrixTargetIds,cardBindingsById:x})},ie=C.useCallback(()=>{w(null)},[]),me=C.useCallback(()=>{if(!(o!=null&&o.createdControlId)){w(null);return}const t=o.control,d=o.createdControlId,l=r.getDefaultValueForType(t,o.defaultValue);if(n){const x={...n};l===void 0?delete x[d]:x[d]=l,I([...a,{...t,defaultValue:l}],x,{type:"add",cardBindingsById:o.cardBindingsById})}else I([...a,{...t,defaultValue:l}],void 0,{type:"add",cardBindingsById:o.cardBindingsById});V(d),w(null),E==null||E()},[a,o,n,I,E]),De=o?B(o.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],fe=o!=null&&o.createdControlId?`[[param.${o.createdControlId}]]`:o?`[[param.${r.slugifyControlValue(o.control.label)||o.control.id}]]`:"",de=r.buildAuthoringPreviewControlValues({controls:a,defaultValues:n}),ce=o?[...a,o.control]:a,xe=o?r.buildAuthoringPreviewControlValues({controls:ce,defaultValues:n,overrides:[{controlId:o.control.id,value:o.defaultValue}]}):de;return e.jsxs("div",{className:"space-y-4",children:[o?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx(Ue,{currentStep:o.step,labels:De}),o.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),d=new Set(["date","text"]),l=P.filter(N=>!t.has(N.value)&&!d.has(N.value)),x=P.filter(N=>t.has(N.value)),S=N=>e.jsxs("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>w(Qe({scope:s,existingControls:a,reservedIds:Array.from(L),type:N.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:N.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:N.description})]},N.value);return e.jsxs("div",{className:"space-y-4",children:[s==="card"&&(j==null?void 0:j.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,l.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:l.map(S)})]}),x.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:x.map(S)})]}),e.jsx(se,{secondary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:ie,children:"Back to controls"})})]})})(),o.step===2&&B(o.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:o.control,onChange:t=>z(d=>({...d,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),Y.length===0?e.jsx("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:Y.map(t=>{const d=(o.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(y.Checkbox,{checked:d,onCheckedChange:l=>w(x=>x&&{...x,selectedCardIds:l===!0?[...x.selectedCardIds||[],t.cardId]:(x.selectedCardIds||[]).filter(S=>S!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:o.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(y.MatrixStructuralTargets,{participants:Y,selectedCardIds:o.selectedCardIds||[],control:o.control,selected:o.matrixTargetIds,onChange:(t,d)=>w(l=>l&&{...l,matrixTargetIds:{...l.matrixTargetIds,[t]:d}})}),e.jsx(se,{secondary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>w(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(r.Button,{type:"button",size:"xs",onClick:()=>w(t=>t&&{...t,step:3}),disabled:!le,children:"Next"})})]}),o.step===2&&!B(o.control.type)&&e.jsx(ye,{control:o.control,defaultValue:o.defaultValue,availableFieldChoices:Z.fields,availableMetricChoices:Z.metrics,previewControlDefinitions:ce,previewControlValues:xe,onControlChange:t=>z(()=>t),onLabelChange:t=>z(d=>({...d,label:t})),onDefaultValueChange:te,onBack:()=>w(t=>t&&{...t,step:1}),onNext:pe,nextDisabled:!le}),o.step===3&&B(o.control.type)&&e.jsx(ye,{control:o.control,defaultValue:o.defaultValue,availableFieldChoices:Z.fields,availableMetricChoices:Z.metrics,previewControlDefinitions:ce,previewControlValues:xe,onControlChange:t=>z(()=>t),onLabelChange:t=>z(d=>({...d,label:t})),onDefaultValueChange:te,onBack:()=>w(t=>t&&{...t,step:2}),onNext:pe,nextDisabled:!le}),o.step===3&&!B(o.control.type)&&e.jsx(ve,{control:o.control,scope:s,createdReference:fe,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>w(t=>t&&{...t,step:2}),onCancel:ie,onDone:me}),o.step===4&&B(o.control.type)&&e.jsx(ve,{control:o.control,scope:s,createdReference:fe,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(o.selectedCardIds||[]).length," selected card",(o.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>w(t=>t&&{...t,step:3}),onCancel:ie,onDone:me})]}):null,!o&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:u}):null,!o&&a.map(t=>{const d=ne(t),l=h==null?void 0:h[t.id],x=r.resolveAuthoringControlDefaultValue({control:t,defaultValues:n}),S=W===t.id,N="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>V(g=>g===t.id?null:t.id),children:[S?e.jsx(J.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(ge.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:N,children:r.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:N,children:r.getPlacementLabel(s,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[r.getControlOptionPreview(t),l!=null&&l.status?` · ${l.status}`:""]})]})]}),e.jsx(r.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>oe(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(y.Trash2,{className:"h-3.5 w-3.5"})})]}),S&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(r.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:g=>$(t.id,T=>({...T,label:g.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(r.Select,{value:t.type,onValueChange:g=>{const T=r.applyControlTypeChange({controls:a,controlId:t.id,nextType:g,defaultValues:n});I(T.controls,T.defaultValues)},children:[e.jsx(r.SelectTrigger,{size:"xs",children:e.jsx(r.SelectValue,{})}),e.jsx(r.SelectContent,{children:X(t.type).map(g=>e.jsx(r.SelectItem,{value:g.value,children:g.label},g.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(r.Select,{value:t.placement||H,onValueChange:g=>$(t.id,T=>({...T,placement:g})),children:[e.jsx(r.SelectTrigger,{size:"xs",children:e.jsx(r.SelectValue,{})}),e.jsx(r.SelectContent,{children:O.map(g=>e.jsx(r.SelectItem,{value:g.value,children:g.label},g.value))})]})]})]}),B(t.type)?e.jsxs(e.Fragment,{children:[e.jsx(y.StructuralParticipantSelector,{type:t.type,participants:r.getEligibleParticipantsForStructuralControl(b||[],t.type).map(g=>({cardId:g.cardId,title:g.title,choiceCount:t.type==="field_selector"?g.fieldChoices.length:g.metricChoices.length})),selectedCardIds:(f==null?void 0:f[t.id])||[],onChange:g=>{const T=A({control:t,nextSelectedCardIds:g}),_=a.map(F=>F.id===t.id?T.nextControl:F);I(_,n,{type:"update",cardBindingsById:T.cardBindingsById})}}),e.jsx(y.MatrixStructuralTargets,{participants:b||[],selectedCardIds:(f==null?void 0:f[t.id])||[],control:t,onChange:(g,T)=>{const _=A({control:t,nextSelectedCardIds:(f==null?void 0:f[t.id])||[],matrixTargetIds:{[g]:T}});I(a.map(F=>F.id===t.id?_.nextControl:F),n,{type:"update",cardBindingsById:_.cardBindingsById})}})]}):null,e.jsx(y.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:d.fields,availableMetricChoices:d.metrics,previewControlDefinitions:a,previewControlValues:de,controlLifecycle:"edit",onChange:g=>$(t.id,()=>g)}),t.initialValueStrategy==="saved_default"&&e.jsx(y.ControlDefaultValueEditor,{control:t,value:x,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:de,onChange:g=>{const T=a.map(_=>_.id===t.id?{..._,defaultValue:g}:_);if(t.source.kind==="manual"&&(Q.current[t.id]=g),n){const _={...n};g===void 0?delete _[t.id]:_[t.id]=g,I(T,_);return}I(T,void 0)}}),e.jsxs(y.Collapsible,{open:U===t.id,onOpenChange:g=>R(g?t.id:null),children:[e.jsx(y.CollapsibleTrigger,{asChild:!0,children:e.jsxs(r.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[U===t.id?e.jsx(J.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(ge.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(y.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(y.ControlIdInput,{controlId:t.id,onCommit:g=>q(t.id,g)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(r.Select,{value:t.initialValueStrategy,onValueChange:g=>$(t.id,T=>({...T,initialValueStrategy:g})),children:[e.jsx(r.SelectTrigger,{size:"xs",children:e.jsx(r.SelectValue,{})}),e.jsx(r.SelectContent,{children:r.INITIAL_VALUE_STRATEGY_OPTIONS.map(g=>e.jsx(r.SelectItem,{value:g.value,children:g.label},g.value))})]})]})]}),e.jsx(y.ControlVisibilitySettings,{control:t,onChange:g=>$(t.id,()=>g)})]})]})]})]},t.id)}),!o&&e.jsxs(r.Button,{type:"button",variant:"outline",size:"xs",onClick:re,children:[e.jsx(y.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Ye(s){const{open:a,onOpenChange:i,initialCreateFlowActive:n=!1,dismissMode:c="passive"}=s,u=a!==void 0,[m,h]=C.useState(!1),[p,v]=C.useState(n),b=u?a:m,f=C.useCallback(k=>{!k&&p&&c==="passive"||(u||h(k),k||v(!1),i==null||i(k))},[u,p,c,i]),j=C.useCallback(()=>{u||h(!1),v(!1),i==null||i(!1)},[u,i]);C.useEffect(()=>{b||v(!1)},[b]);const D=C.useCallback(k=>{p&&k.preventDefault()},[p]);return{forceClose:j,handleOpenChange:f,isCreateFlowActive:p,preventPassiveDismissDuringCreate:D,resolvedOpen:b,setIsCreateFlowActive:v}}function ue(s){var i;for(const n of s.cards)if(n.type==="matrixTable"&&!Te.matrixConfigSchema.safeParse((i=n.config)==null?void 0:i.matrix).success)return r.ue.error("Matrix requires at least one row field, one metric, and valid settings."),!1;const a=r.getDynamicFrameSaveIssue(s);return a?(r.ue.error(a),!1):!0}function He({className:s,variant:a="outline"}){const i=r.useEditorStore(u=>u.onSave),{getUpdatedFrame:n}=ae();function c(){const u=n();ue(u)&&(i==null||i(u))}return e.jsxs(r.Button,{onClick:c,className:s,size:"xs",variant:a,children:[e.jsx(r.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function Ke({className:s,variant:a="default"}){const i=y.useQueryClient(),[n,c]=C.useState(!1),{setIsVisualEditing:u}=r.useDashboardActions(),{getUpdatedFrame:m}=ae(),h=y.useSelectedVisual(),p=r.useEditorStore(f=>f.frame),v=y.useUpdateVisualMutation(),b=()=>{const f=m();if(!ue(f))return;const j=(p==null?void 0:p.visualId)||(h==null?void 0:h.id);if(!j){r.ue.error("No visual to save");return}c(!0),v.mutate({visualId:j,data:{frameObject:f}},{onSuccess:()=>{c(!1),r.ue.success("Visual updated successfully"),i.invalidateQueries({queryKey:["resource-by-id","visual",j],exact:!0})},onError:()=>{c(!1),r.ue.error("Failed to update visual")}})};return e.jsx(r.Button,{onClick:b,className:s,size:"xs",variant:a,children:n?e.jsxs(e.Fragment,{children:[e.jsx(r.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Pe({className:s}){const a=y.useQueryClient(),[i,n]=C.useState(!1),c=y.useSelectedVisual(),u=r.useEditorStore(k=>k.frame),m=r.useDashboardStore(k=>k.selectedSheetId),h=r.useDashboardStore(k=>k.dashboard),{updateFrame:p,setIsVisualEditing:v}=r.useDashboardActions(),{getUpdatedFrame:b}=ae(),f=y.useUpdateVisualMutation(),j=y.useResolveExistingFrameSemanticExecutionPayload(),D=async()=>{if(!m){r.ue.error("No sheet selected");return}const k=(u==null?void 0:u.visualId)||(c==null?void 0:c.id);if(!k){r.ue.error("No visual to update");return}n(!0);try{const E=b();if(!ue(E)){n(!1);return}const L={...E,visualId:k},O=r.findDashboardFrameById(h,L.id),H=await j(L,{previousFrame:O});await f.mutateAsync({visualId:k,data:{frameObject:E}}),p(m,L,{semanticExecutionPayload:H}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",k]}),r.ue.success("Saved to library and applied locally"),setTimeout(()=>{v(!1)},300)}catch(E){console.error("Failed to save and apply:",E),r.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{n(!1)}};return e.jsx(r.Button,{onClick:D,className:s,size:"xs",variant:"default",disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(r.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function We({className:s}){const{setTempQueryData:a,setSqlGen:i}=r.useEditorActions(),n=y.useQueryClient(),c=r.useEditorStore(f=>f.tempQueryData),u=r.useEditorStore(f=>f.onClose),m=r.useEditorStore(f=>f.card),h=y.useEffectiveEditorCardType(),p=C.useMemo(()=>h!==m.type?{...m,type:h}:m,[m,h]),{queryKey:v}=y.useEditorCardQuery(p);function b(){if(c){const{queryKey:f,queryData:j}=c;f&&j&&n.setQueryData(f,j)}i({}),u==null||u()}return e.jsxs(r.Button,{onClick:b,className:s,size:"xs",variant:"outline",children:[e.jsx(J.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Xe({label:s="Clear",variant:a="secondary",className:i}={}){const n=Ee();return e.jsxs(r.Button,{onClick:n,className:i,size:"xs",variant:a,children:[e.jsx(J.X,{className:"h-3.5 w-3.5"}),s]})}exports.ControlDefinitionListEditor=$e;exports.EditorAcceptButton=He;exports.EditorCancelButton=We;exports.EditorClearButton=Xe;exports.FilterX=Ve;exports.Library=je;exports.Link2=ke;exports.VisualBadge=Oe;exports.VisualSaveAndApplyButton=Pe;exports.VisualSaveButton=Ke;exports.useCreateFlowOverlayState=Ye;exports.useEditorClearAction=Ee;exports.useSyncLegacyEditorState=Be;exports.useVisualUtils=ae;
|
|
16
|
+
*/const ke=J.createLucideIcon("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);function Ie(s){const[a,i]=C.useState(null),[n,c]=C.useState(null),u=y.useEnsureReactGlobals();return C.useEffect(()=>{if(!s||s.trim()===""){i(null),c(null);return}if(!u)return;(async()=>{try{if(!s.startsWith("http://")&&!s.startsWith("https://"))throw new Error(`Invalid URL format: ${s}`);try{new URL(s)}catch{throw new Error(`Invalid URL: ${s}`)}const p=`${s.endsWith("/")?s:`${s}/`}index.js`;try{if(!(await fetch(p,{method:"HEAD"})).ok)throw new Error(`Module not found at ${p}`)}catch{}const v=await import(p);if(typeof v.useChartStore!="function")throw new Error("useChartStore is not a function");i(()=>v.useChartStore),c(null)}catch(h){const p=h instanceof Error?h.message:"Unknown error";console.error("Failed to load remote chart store:",p),c(p),i(null)}})()},[s,u]),a}function Le(s,a){if(s.length===0)return"";const i=s.find(n=>{var c,u;return((c=n.customCardPreferences)==null?void 0:c.visualType)==="multiple"||!!((u=n.customCardPreferences)!=null&&u.dataInputCardIds)});if(i)return i.id;if(a){const n=s.find(c=>c.id===a);if(n){const c=n.tabTitle;if(c=="All__Header")return s[0].id;if(c&&c.endsWith("__Header")){const m=c.split("__")[0],h=s.find(p=>p.tabTitle===m);return h?h.id:s[0].id}return a}}return s[0].id}const Ae=s=>{if(!s||!("detailTableBackup"in s))return s;const{detailTableBackup:a,...i}=s;return i};async function be(s,a,i,n,c="Opening library visual..."){if(!a||!i)throw new Error("Missing auth token or visual ID");const u=["resource-by-id","visual",i],m=n.getQueryData(u);if(m)return console.log("Using cached visual data for:",i),{data:m,fromCache:!0};console.log("Fetching visual data from network for:",i);const h=r.ue.loading(c,{position:"top-center"});try{const p=await fetch(`${s}/management/v1/visuals/${i}`,{headers:{Authorization:`Bearer ${a}`}});if(!p.ok)throw new Error("Failed to load visual");const v=await p.json();return n.setQueryData(u,v),r.ue.dismiss(h),{data:v,fromCache:!1}}catch(p){throw r.ue.dismiss(h),p}}function Ne(s){if(typeof s=="string")return JSON.parse(s);if(typeof s=="object")return s;throw new Error("Invalid frame object format")}function _e(s,a){var u,m;const i=(s==null?void 0:s.frameObject)??((u=s==null?void 0:s.visual)==null?void 0:u.frameObject);if(!i)return!1;const n=Ne(i);if(!(n!=null&&n.cards)||n.cards.length===0)return!1;const c=(m=n.cards)==null?void 0:m.find(h=>h.id===n.activeCardId);return c?(y.setupEditorWithCard({...a,frame:n,card:c,visualId:(s==null?void 0:s.id)||n.visualId}),!0):!1}function qe(){const s=r.useEditorStore(n=>{var c;return((c=n.card.customCardPreferences)==null?void 0:c.url)||""}),a=Ie(s);return{getUpdatedFrame:C.useCallback(()=>{var L;y.flushPendingEditorDrafts();const{frame:n,card:c,isDevMode:u,isShowingVisual:m,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:b,selectedConnectionId:f}=r.useEditorStore.getState(),j=c.sql,D=(L=a==null?void 0:a.getState())==null?void 0:L.settings,k=r.buildSavedEditorCard(c,{isDevMode:u,cardSql:j,isShowingVisual:m,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:b,selectedConnectionId:f,remoteChartSettings:D,stripConfig:Ae}),E=n.cards.map(O=>O.id===c.id?k:O);return{...n,cards:E,activeCardId:Le(E,n.activeCardId)}},[a])}}function ae(){const{authToken:s,tokenProps:a}=y.useSemaphorContext(),i=y.useQueryClient(),n=y.useAddFrameWithFreshSemanticExecutionPayload(),c=y.useSelectedVisual(),{selectVisual:u}=y.useManagementActions(),{setFrame:m,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:b,updateDataSource:f,setQueryResultColumns:j,setSelectedConnectionId:D,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:L,setSelectedDatamodelId:O,setFilterValues:H,setInlineFilterValuesMap:U,setApplyFilters:z,clearEditorContext:W}=r.useEditorActions(),{setIsDashboardEditing:V,setIsVisualEditing:o,setSelectedFrameId:w,clearSelectedFrameId:Q}=r.useDashboardActions(),M=r.useDashboardStore(A=>A.selectedSheetId),K=r.useDashboardStore(A=>A.selectedFrameId),P=r.useDashboardStore(A=>A.dashboard),X=r.useDashboardStore(A=>A.filterValues),B=r.useDashboardStore(A=>A.inlineFilterValuesMap),Y=y.useVisualById((c==null?void 0:c.id)||"",{enabled:!!(c!=null&&c.id)&&!!(s!=null&&s.accessToken)}),Z=C.useCallback(async A=>{try{u(A),Q(),W();const{data:I,fromCache:$}=await be(a.apiServiceUrl,(s==null?void 0:s.accessToken)||"",A.id,i,"Opening library visual...");if(!_e(I,{setFrame:m,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:b,updateDataSource:f,setQueryResultColumns:j,setSelectedConnectionId:D,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:L,setSelectedDatamodelId:O,setFilterValues:H,setInlineFilterValuesMap:U,setApplyFilters:z,setIsDashboardEditing:V,setIsVisualEditing:o,dashboard:P,selectedSheetId:M,selectedFrameId:K,filterValues:X,inlineFilterValuesMap:B}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:$}}catch(I){return console.error("Error editing visual:",I),{success:!1,error:"Failed to load visual for editing"}}},[s==null?void 0:s.accessToken,a.apiServiceUrl,i,u,m,h,V,o,p,v,b,f,j,D,k,E,L,O,H,U,z,W,Q,P,M,K,X,B]),ne=C.useCallback(async A=>{var $;const I=q=>(r.ue.error(q),{success:!1,error:q});try{if(u(A),!M)return I("No sheet selected. Please select a sheet first.");const{data:q,fromCache:oe}=await be(a.apiServiceUrl,(s==null?void 0:s.accessToken)||"",A.id,i,"Adding visual to dashboard..."),re=(q==null?void 0:q.frameObject)??(($=q==null?void 0:q.visual)==null?void 0:$.frameObject);if(!re)return I("Visual has no frame data");const R=Ne(re);if(!(R!=null&&R.cards)||R.cards.length===0)return I("Visual frame is malformed");const te={...y.cloneLinkedFrameWithSourceMapping(R),visualId:A.id};return await n(M,te,"end"),V(!0),w(te.id),{success:!0,fromCache:oe}}catch(q){return console.error("Error adding visual:",q),I(q instanceof Error?q.message:"Failed to add visual to dashboard")}},[s==null?void 0:s.accessToken,a.apiServiceUrl,i,u,M,V,w,n]);return{visual:Y.data,isLoading:Y.isLoading,isError:Y.isError,error:Y.error,handleEditLibraryVisual:Z,handleAddLibraryVisual:ne,getUpdatedFrame:qe().getUpdatedFrame,refetch:Y.refetch}}function Be(){const s=r.useEditorStore(m=>m.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:i,setSelectedSchemaName:n,setSelectedTableName:c,setSelectedDatamodelId:u}=r.useEditorActions();C.useEffect(()=>{var D;if(!s)return;const{tableName:m,schemaName:h,databaseName:p,connectionId:v}=y.extractTableMetadata(s),b=(D=s.selectedEntities)==null?void 0:D[0],j=(b==null?void 0:b.type)==="model"&&"id"in b?b.id:"";a(v||""),i(p||""),n(h||""),c(m||""),u(j)},[s,a,i,n,c,u])}function Me(s,a){return{...s,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?s.customCardPreferences:void 0,visualizationMode:"builtin",type:a?s.type:"bar"}}function Ee(){const{setTempQueryData:s}=r.useEditorActions(),a=y.useQueryClient(),i=r.useEditorStore(U=>U.tempQueryData),n=r.useEditorStore(U=>U.card),c=y.useEffectiveEditorCardType(),u=C.useMemo(()=>c!==n.type?{...n,type:c}:n,[n,c]),{queryKey:m}=y.useEditorCardQuery(u),{setCardSql:h,setSqlGen:p,setCardPython:v,setCardCustomCfg:b,setCardPreferences:f,clearQueryConfig:j,setCardConfig:D,setCardType:k,setFrame:E,setCard:L,setActiveTabCardId:O}=r.useEditorActions();function H(){var Q,M,K,P;const U=a.getQueryData(m);i!=null&&i.queryData||s({queryKey:m,queryData:U}),a.setQueryData(m,null),a.removeQueries({queryKey:m,exact:!0}),h(""),p({}),j(),D(void 0),v(""),b(""),f({});const z=r.useEditorStore.getState().frame,W=r.useEditorStore.getState().card,V=Fe.findCustomVisualConfigCard(z,W),o=((Q=V==null?void 0:V.customCardPreferences)==null?void 0:Q.visualType)==="multiple"||!!((M=V==null?void 0:V.customCardPreferences)!=null&&M.dataInputCardIds)||(((K=V==null?void 0:V.customCardPreferences)==null?void 0:K.minInputs)||0)>1||(((P=V==null?void 0:V.customCardPreferences)==null?void 0:P.maxInputs)||0)>1,w=Me(W,o);E({...z,cards:z.cards.map(X=>X.id===w.id?w:X)}),O(w.id),L(w),o||k("bar")}return H}function Oe({type:s,isLinked:a,className:i,showLabel:n=!1,showLocal:c=!1}){const u=r.useDashboardStore(E=>E.selectedFrameId),m=y.useManagementStore(E=>E.selectedVisual),h=r.useEditorStore(E=>E.frame);let p;if(s)p=s;else if(a!==void 0)p=a?"linked":"library";else if(!!!(h!=null&&h.visualId||m!=null&&m.id)&&u)p="local";else if(m&&!u)p="library";else if(h!=null&&h.visualId&&u)p="linked";else if(m!=null&&m.id&&u)p="library";else return null;if(p==="local"&&!c)return null;const v={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},b={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},f={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},j={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},D={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(ke,{className:"h-3.5 w-3.5"}),library:e.jsx(je,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(r.TooltipProvider,{children:e.jsxs(r.Tooltip,{delayDuration:300,children:[e.jsx(r.TooltipTrigger,{asChild:!0,children:e.jsxs(y.Badge,{variant:"outline",className:r.cn("cursor-help select-none transition-all",v[p],i),children:[D[p],n&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[p]})]})}),e.jsxs(r.TooltipContent,{side:"bottom",className:r.cn("max-w-xs",f[p]),children:[e.jsx(r.TooltipArrow,{className:j[p]}),e.jsx("p",{children:b[p]})]})]})})}function we(s){const{control:a,onChange:i}=s;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(r.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:n=>i(n.target.value)})]})}function Ue(s){const{currentStep:a,labels:i}=s;return e.jsx("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:i.map((n,c)=>{const u=c+1,m=u===a,h=u<a;return e.jsxs(C.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:r.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",m?"border-foreground bg-foreground text-background":h?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:u}),e.jsx("span",{className:r.cn("text-[12px]",m?"font-medium text-foreground":"text-muted-foreground"),children:n})]}),c<i.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},n)})})})}function se(s){const{secondary:a,tertiary:i,primary:n}=s;return e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,i,n]})}function Re(s){const{control:a,scope:i,detail:n}=s;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(y.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[r.getFriendlyTypeOption(a.type).label," ·"," ",r.getControlOptionPreview(a)," ·"," ",r.getPlacementLabel(i,a.placement)]}),n?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:n}):null]})]})}function ye(s){const{control:a,defaultValue:i,availableFieldChoices:n,availableMetricChoices:c,previewControlDefinitions:u,previewControlValues:m,onControlChange:h,onLabelChange:p,onDefaultValueChange:v,onBack:b,onNext:f,nextDisabled:j}=s;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:a,onChange:p}),e.jsx(y.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:n,availableMetricChoices:c,previewControlDefinitions:u,previewControlValues:m,controlLifecycle:"create",onChange:h}),e.jsx(y.ControlDefaultValueEditor,{control:a,value:i,onChange:v,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:u,previewControlValues:m}),e.jsx(se,{secondary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:b,children:"Back"}),primary:e.jsx(r.Button,{type:"button",size:"xs",onClick:f,disabled:j,children:"Next"})})]})}const ze=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function Ce(s){const{text:a,ariaLabel:i}=s,[n,c]=C.useState(!1);return e.jsxs("button",{type:"button","aria-label":i,onClick:async()=>{try{await navigator.clipboard.writeText(a),c(!0),setTimeout(()=>c(!1),1200)}catch(u){console.error("Failed to copy",u)}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:n?"Copied":"Click to copy"})]})}function ve(s){const{control:a,scope:i,createdReference:n,explorerContent:c,sqlDescription:u,summaryDetail:m,onBack:h,onCancel:p,onDone:v}=s,b=ze.has(a.type),f=n.match(/\[\[param\.(.+?)\]\]/),j=f?`{{ param('${f[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Re,{control:a,scope:i,detail:m}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[b?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:c})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(Ce,{text:n,ariaLabel:"Copy SQL control reference"}),j?e.jsx(Ce,{text:j,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[u," ",e.jsx("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),e.jsx(se,{secondary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:h,children:"Back"}),tertiary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:p,children:"Cancel"}),primary:e.jsx(r.Button,{type:"button",size:"xs",onClick:v,children:"Done"})})]})}function Qe(s){const a=r.createBlankControl(s.scope,s.existingControls,s.reservedIds),i=s.type===a.type?{...a,label:r.DEFAULT_LABEL_BY_TYPE[s.type]}:{...r.applyControlTypeChange({controls:[{...a,label:r.DEFAULT_LABEL_BY_TYPE[s.type]}],controlId:a.id,nextType:s.type}).controls[0],label:r.DEFAULT_LABEL_BY_TYPE[s.type]};return{step:2,control:i,defaultValue:r.getDefaultValueForType(i,void 0)}}function $e({scope:s,controls:a,reservedControlIds:i,defaultValues:n,onChange:c,emptyMessage:u,initialCreateFlow:m=!1,usageByControlId:h,availableFieldChoices:p,availableMetricChoices:v,structuralParticipants:b,structuralParticipantIdsByControlId:f,card:j,allowedControlTypes:D,onCreateFlowActiveChange:k,onCreateFlowComplete:E}){const L=C.useMemo(()=>new Set(i||[]),[i]),O=r.getPlacementOptionsForScope(s),H=r.getDefaultPlacement(s),[U,z]=C.useState(null),[W,V]=C.useState(null),[o,w]=C.useState(()=>m?{step:1,control:r.createBlankControl(s,a,Array.from(L))}:null),Q=C.useRef({}),M=C.useRef(void 0),K=C.useRef(m),P=C.useMemo(()=>{const t=r.getFriendlyControlTypeOptions({scope:s,card:j});if(!D)return t;const d=new Set(D);return t.filter(l=>d.has(l.value))},[D,j,s]),X=C.useCallback(t=>{const d=r.getFriendlyControlTypeOptions({scope:s,card:j,includeType:D?void 0:t});if(!D)return d;const l=new Set(D);return d.filter(x=>l.has(x.value))},[D,j,s]),B=C.useCallback(t=>s==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[s]),Y=C.useMemo(()=>o?r.getEligibleParticipantsForStructuralControl(b||[],o.control.type):[],[o,b]),Z=C.useMemo(()=>{if(!o)return{fields:p||[],metrics:v||[]};if(!B(o.control.type))return{fields:p||[],metrics:v||[]};const t=o.selectedCardIds||[],d=r.getCompatibleStructuralChoiceCatalog({controlType:o.control.type,participants:b||[],selectedCardIds:t});return{fields:o.control.type==="field_selector"?d.choices.map(l=>({option:l,target:d.fieldTargetMap[l.value]})):[],metrics:o.control.type==="metric_selector"?d.choices.map(l=>({option:l,target:d.metricTargetMap[l.value]})):[]}},[p,v,o,B,b]);C.useEffect(()=>{k==null||k(!!o)},[o,k]),C.useEffect(()=>{const t=m&&!K.current;K.current=m,t&&(w({step:1,control:r.createBlankControl(s,a,Array.from(L))}),V(null),z(null))},[a,m,L,s]);const ne=t=>{if(!B(t.type))return{fields:p||[],metrics:v||[]};const d=(f==null?void 0:f[t.id])||[];if(d.length===0)return{fields:p||[],metrics:v||[]};const l=r.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:b||[],selectedCardIds:d});return{fields:t.type==="field_selector"?l.choices.map(x=>({option:x,target:l.fieldTargetMap[x.value]})):[],metrics:t.type==="metric_selector"?l.choices.map(x=>({option:x,target:l.metricTargetMap[x.value]})):[]}},A=t=>{if(!B(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const d=(f==null?void 0:f[t.control.id])||[],l=r.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:b||[],selectedCardIds:t.nextSelectedCardIds}),x=r.reconcileStructuralControlChoices({control:t.control,choices:l.choices}),S=Object.fromEntries(d.filter(N=>!t.nextSelectedCardIds.includes(N)).map(N=>[N,void 0]));return t.nextSelectedCardIds.length>0&&x.source.kind==="manual"&&x.source.options.length>0&&Object.assign(S,r.buildStructuralControlBindingsForParticipants({control:x,participants:b||[],selectedCardIds:t.nextSelectedCardIds,matrixTargetIds:t.matrixTargetIds})),{nextControl:x,cardBindingsById:S}},I=C.useCallback((t,d=n,l={type:"update"})=>{const x=t.map(S=>(r.resolveAuthoringControlDefaultValue({control:S,defaultValues:d}),r.syncSqlQueryControlExecutionRequirement(S)));c(x,d,l)},[n,c]),$=(t,d)=>{const l=a.find(F=>F.id===t);let x=a.map(F=>F.id!==t?F:d(F));const S=x.find(F=>F.id===t);let N,g;if(S&&(!l||r.structuralControlBindingsChanged({control:l},{control:S}))&&s==="dashboard"&&(S.type==="field_selector"||S.type==="metric_selector")){const F=(f==null?void 0:f[S.id])||[],ee=A({control:S,nextSelectedCardIds:F});x=x.map(G=>G.id===t?ee.nextControl:G),N=ee.cardBindingsById,g=[S.id]}else if(l&&(!S||!r.isStructuralSelectorControlType(S.type))&&s==="dashboard"&&(l.type==="field_selector"||l.type==="metric_selector")){const F=(f==null?void 0:f[l.id])||[];N=Object.fromEntries(F.map(ee=>[ee,void 0])),g=[l.id]}const T=x.find(F=>F.id===t);let _=n;if(l&&T){const F=r.resolveAuthoringControlDefaultValue({control:l,defaultValues:n});l.source.kind==="manual"&&T.source.kind==="sql_query"&&(Q.current[t]=F);const ee=F===void 0&&l.source.kind==="sql_query"&&T.source.kind==="manual"?Q.current[t]:F,G=r.getNextEditedControlDefaultValue({previousControl:l,nextControl:T,currentDefaultValue:ee});T.source.kind==="manual"&&(Q.current[t]=G),n&&(_={...n},G===void 0?delete _[t]:_[t]=G),x=x.map(he=>he.id===t?{...T,defaultValue:G}:he)}I(x,_,{type:"update",cardBindingsById:N,affectedBindingControlIds:g})},q=(t,d)=>{if(!d.trim())return;const l=r.normalizeDashboardInputVariableName(d);if(l===t||L.has(l)||a.some(N=>N.id===l&&N.id!==t))return;const x=a.map(N=>N.id===t?{...N,id:l}:N);if(!n){I(x,void 0,{type:"rename",oldId:t,newId:l});return}const S={...n};Object.prototype.hasOwnProperty.call(S,t)&&(S[l]=S[t],delete S[t]),I(x,S,{type:"rename",oldId:t,newId:l})},oe=t=>{const d=a.filter(x=>x.id!==t);if(!n){I(d,void 0,{type:"remove",controlId:t});return}const l={...n};delete l[t],I(d,l,{type:"remove",controlId:t})},re=C.useCallback(()=>{M.current=void 0,w({step:1,control:r.createBlankControl(s,a,Array.from(L))}),V(null),z(null)},[a,L,s]),R=t=>{w(d=>d&&(()=>{const l=t(d.control);d.control.source.kind==="manual"&&l.source.kind==="sql_query"&&(M.current=d.defaultValue);const x=d.defaultValue===void 0&&d.control.source.kind==="sql_query"&&l.source.kind==="manual"?M.current:d.defaultValue,S=r.getNextEditedControlDefaultValue({previousControl:d.control,nextControl:l,currentDefaultValue:x});return l.source.kind==="manual"&&(M.current=S),{...d,control:l,defaultValue:S}})())},te=t=>{w(d=>d&&(d.control.source.kind==="manual"&&(M.current=t),{...d,defaultValue:t}))},le=(()=>{if(!o)return!1;if(o.step===2&&B(o.control.type))return(o.selectedCardIds||[]).length>0&&r.hasStructuralMatrixTargets({participants:b||[],selectedCardIds:o.selectedCardIds||[],control:o.control,selected:o.matrixTargetIds});if(o.step!==2&&o.step!==3||!o.control.label.trim())return!1;const d=o.control.source.kind==="sql_query"?o.control:r.ensureManualSource(o.control);if(d.source.kind==="manual"&&(r.needsManualOptions(d)&&d.source.options.length===0||d.source.options.some(x=>x.label.trim().length===0||x.value.trim().length===0)))return!1;if(d.source.kind==="sql_query"){const{connectionId:l,sql:x,valueColumn:S}=d.source;return l.trim().length>0&&x.trim().length>0&&S.trim().length>0}return r.hasConcreteDefaultValue(r.getDefaultValueForType(d,o.defaultValue))})(),pe=()=>{var N;if(!o)return;const t=r.ensureManualSource(o.control),d=r.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(L)}),l={...t,id:d},x=s==="dashboard"&&(l.type==="field_selector"||l.type==="metric_selector")&&((N=o.selectedCardIds)!=null&&N.length)?r.buildStructuralControlBindingsForParticipants({control:l,participants:b||[],selectedCardIds:o.selectedCardIds,matrixTargetIds:o.matrixTargetIds}):void 0,S=r.getDefaultValueForType(l,o.defaultValue);w({step:s==="dashboard"&&(l.type==="field_selector"||l.type==="metric_selector")?4:3,control:l,defaultValue:S,createdControlId:d,selectedCardIds:o.selectedCardIds,matrixTargetIds:o.matrixTargetIds,cardBindingsById:x})},ie=C.useCallback(()=>{w(null)},[]),me=C.useCallback(()=>{if(!(o!=null&&o.createdControlId)){w(null);return}const t=o.control,d=o.createdControlId,l=r.getDefaultValueForType(t,o.defaultValue);if(n){const x={...n};l===void 0?delete x[d]:x[d]=l,I([...a,{...t,defaultValue:l}],x,{type:"add",cardBindingsById:o.cardBindingsById})}else I([...a,{...t,defaultValue:l}],void 0,{type:"add",cardBindingsById:o.cardBindingsById});V(d),w(null),E==null||E()},[a,o,n,I,E]),De=o?B(o.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],fe=o!=null&&o.createdControlId?`[[param.${o.createdControlId}]]`:o?`[[param.${r.slugifyControlValue(o.control.label)||o.control.id}]]`:"",de=r.buildAuthoringPreviewControlValues({controls:a,defaultValues:n}),ce=o?[...a,o.control]:a,xe=o?r.buildAuthoringPreviewControlValues({controls:ce,defaultValues:n,overrides:[{controlId:o.control.id,value:o.defaultValue}]}):de;return e.jsxs("div",{className:"space-y-4",children:[o?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx(Ue,{currentStep:o.step,labels:De}),o.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),d=new Set(["date","text"]),l=P.filter(N=>!t.has(N.value)&&!d.has(N.value)),x=P.filter(N=>t.has(N.value)),S=N=>e.jsxs("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>w(Qe({scope:s,existingControls:a,reservedIds:Array.from(L),type:N.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:N.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:N.description})]},N.value);return e.jsxs("div",{className:"space-y-4",children:[s==="card"&&(j==null?void 0:j.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,l.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:l.map(S)})]}),x.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:x.map(S)})]}),e.jsx(se,{secondary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:ie,children:"Back to controls"})})]})})(),o.step===2&&B(o.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:o.control,onChange:t=>R(d=>({...d,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),Y.length===0?e.jsx("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:Y.map(t=>{const d=(o.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(y.Checkbox,{checked:d,onCheckedChange:l=>w(x=>x&&{...x,selectedCardIds:l===!0?[...x.selectedCardIds||[],t.cardId]:(x.selectedCardIds||[]).filter(S=>S!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:o.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(y.MatrixStructuralTargets,{participants:Y,selectedCardIds:o.selectedCardIds||[],control:o.control,selected:o.matrixTargetIds,onChange:(t,d)=>w(l=>l&&{...l,matrixTargetIds:{...l.matrixTargetIds,[t]:d}})}),e.jsx(se,{secondary:e.jsx(r.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>w(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(r.Button,{type:"button",size:"xs",onClick:()=>w(t=>t&&{...t,step:3}),disabled:!le,children:"Next"})})]}),o.step===2&&!B(o.control.type)&&e.jsx(ye,{control:o.control,defaultValue:o.defaultValue,availableFieldChoices:Z.fields,availableMetricChoices:Z.metrics,previewControlDefinitions:ce,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(d=>({...d,label:t})),onDefaultValueChange:te,onBack:()=>w(t=>t&&{...t,step:1}),onNext:pe,nextDisabled:!le}),o.step===3&&B(o.control.type)&&e.jsx(ye,{control:o.control,defaultValue:o.defaultValue,availableFieldChoices:Z.fields,availableMetricChoices:Z.metrics,previewControlDefinitions:ce,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(d=>({...d,label:t})),onDefaultValueChange:te,onBack:()=>w(t=>t&&{...t,step:2}),onNext:pe,nextDisabled:!le}),o.step===3&&!B(o.control.type)&&e.jsx(ve,{control:o.control,scope:s,createdReference:fe,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>w(t=>t&&{...t,step:2}),onCancel:ie,onDone:me}),o.step===4&&B(o.control.type)&&e.jsx(ve,{control:o.control,scope:s,createdReference:fe,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(o.selectedCardIds||[]).length," selected card",(o.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>w(t=>t&&{...t,step:3}),onCancel:ie,onDone:me})]}):null,!o&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:u}):null,!o&&a.map(t=>{const d=ne(t),l=h==null?void 0:h[t.id],x=r.resolveAuthoringControlDefaultValue({control:t,defaultValues:n}),S=W===t.id,N="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>V(g=>g===t.id?null:t.id),children:[S?e.jsx(J.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(ge.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:N,children:r.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:N,children:r.getPlacementLabel(s,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[r.getControlOptionPreview(t),l!=null&&l.status?` · ${l.status}`:""]})]})]}),e.jsx(r.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>oe(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(y.Trash2,{className:"h-3.5 w-3.5"})})]}),S&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(r.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:g=>$(t.id,T=>({...T,label:g.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(r.Select,{value:t.type,onValueChange:g=>{const T=r.applyControlTypeChange({controls:a,controlId:t.id,nextType:g,defaultValues:n});I(T.controls,T.defaultValues)},children:[e.jsx(r.SelectTrigger,{size:"xs",children:e.jsx(r.SelectValue,{})}),e.jsx(r.SelectContent,{children:X(t.type).map(g=>e.jsx(r.SelectItem,{value:g.value,children:g.label},g.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(r.Select,{value:t.placement||H,onValueChange:g=>$(t.id,T=>({...T,placement:g})),children:[e.jsx(r.SelectTrigger,{size:"xs",children:e.jsx(r.SelectValue,{})}),e.jsx(r.SelectContent,{children:O.map(g=>e.jsx(r.SelectItem,{value:g.value,children:g.label},g.value))})]})]})]}),B(t.type)?e.jsxs(e.Fragment,{children:[e.jsx(y.StructuralParticipantSelector,{type:t.type,participants:r.getEligibleParticipantsForStructuralControl(b||[],t.type).map(g=>({cardId:g.cardId,title:g.title,choiceCount:t.type==="field_selector"?g.fieldChoices.length:g.metricChoices.length})),selectedCardIds:(f==null?void 0:f[t.id])||[],onChange:g=>{const T=A({control:t,nextSelectedCardIds:g}),_=a.map(F=>F.id===t.id?T.nextControl:F);I(_,n,{type:"update",cardBindingsById:T.cardBindingsById})}}),e.jsx(y.MatrixStructuralTargets,{participants:b||[],selectedCardIds:(f==null?void 0:f[t.id])||[],control:t,onChange:(g,T)=>{const _=A({control:t,nextSelectedCardIds:(f==null?void 0:f[t.id])||[],matrixTargetIds:{[g]:T}});I(a.map(F=>F.id===t.id?_.nextControl:F),n,{type:"update",cardBindingsById:_.cardBindingsById})}})]}):null,e.jsx(y.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:d.fields,availableMetricChoices:d.metrics,previewControlDefinitions:a,previewControlValues:de,controlLifecycle:"edit",onChange:g=>$(t.id,()=>g)}),t.initialValueStrategy==="saved_default"&&e.jsx(y.ControlDefaultValueEditor,{control:t,value:x,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:de,onChange:g=>{const T=a.map(_=>_.id===t.id?{..._,defaultValue:g}:_);if(t.source.kind==="manual"&&(Q.current[t.id]=g),n){const _={...n};g===void 0?delete _[t.id]:_[t.id]=g,I(T,_);return}I(T,void 0)}}),e.jsxs(y.Collapsible,{open:U===t.id,onOpenChange:g=>z(g?t.id:null),children:[e.jsx(y.CollapsibleTrigger,{asChild:!0,children:e.jsxs(r.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[U===t.id?e.jsx(J.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(ge.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(y.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(y.ControlIdInput,{controlId:t.id,onCommit:g=>q(t.id,g)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(r.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(r.Select,{value:t.initialValueStrategy,onValueChange:g=>$(t.id,T=>({...T,initialValueStrategy:g})),children:[e.jsx(r.SelectTrigger,{size:"xs",children:e.jsx(r.SelectValue,{})}),e.jsx(r.SelectContent,{children:r.INITIAL_VALUE_STRATEGY_OPTIONS.map(g=>e.jsx(r.SelectItem,{value:g.value,children:g.label},g.value))})]})]})]}),e.jsx(y.ControlVisibilitySettings,{control:t,onChange:g=>$(t.id,()=>g)})]})]})]})]},t.id)}),!o&&e.jsxs(r.Button,{type:"button",variant:"outline",size:"xs",onClick:re,children:[e.jsx(y.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Ye(s){const{open:a,onOpenChange:i,initialCreateFlowActive:n=!1,dismissMode:c="passive"}=s,u=a!==void 0,[m,h]=C.useState(!1),[p,v]=C.useState(n),b=u?a:m,f=C.useCallback(k=>{!k&&p&&c==="passive"||(u||h(k),k||v(!1),i==null||i(k))},[u,p,c,i]),j=C.useCallback(()=>{u||h(!1),v(!1),i==null||i(!1)},[u,i]);C.useEffect(()=>{b||v(!1)},[b]);const D=C.useCallback(k=>{p&&k.preventDefault()},[p]);return{forceClose:j,handleOpenChange:f,isCreateFlowActive:p,preventPassiveDismissDuringCreate:D,resolvedOpen:b,setIsCreateFlowActive:v}}function ue(s){var i;for(const n of s.cards)if(n.type==="matrixTable"&&!Te.matrixConfigSchema.safeParse((i=n.config)==null?void 0:i.matrix).success)return r.ue.error("Matrix requires at least one row field, one metric, and valid settings."),!1;const a=r.getDynamicFrameSaveIssue(s);return a?(r.ue.error(a),!1):!0}function He({className:s,variant:a="outline"}){const i=r.useEditorStore(u=>u.onSave),{getUpdatedFrame:n}=ae();function c(){const u=n();ue(u)&&(i==null||i(u))}return e.jsxs(r.Button,{onClick:c,className:s,size:"xs",variant:a,children:[e.jsx(r.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function Ke({className:s,variant:a="default"}){const i=y.useQueryClient(),[n,c]=C.useState(!1),{setIsVisualEditing:u}=r.useDashboardActions(),{getUpdatedFrame:m}=ae(),h=y.useSelectedVisual(),p=r.useEditorStore(f=>f.frame),v=y.useUpdateVisualMutation(),b=()=>{const f=m();if(!ue(f))return;const j=(p==null?void 0:p.visualId)||(h==null?void 0:h.id);if(!j){r.ue.error("No visual to save");return}c(!0),v.mutate({visualId:j,data:{frameObject:f}},{onSuccess:()=>{c(!1),r.ue.success("Visual updated successfully"),i.invalidateQueries({queryKey:["resource-by-id","visual",j],exact:!0})},onError:()=>{c(!1),r.ue.error("Failed to update visual")}})};return e.jsx(r.Button,{onClick:b,className:s,size:"xs",variant:a,children:n?e.jsxs(e.Fragment,{children:[e.jsx(r.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Pe({className:s}){const a=y.useQueryClient(),[i,n]=C.useState(!1),c=y.useSelectedVisual(),u=r.useEditorStore(k=>k.frame),m=r.useDashboardStore(k=>k.selectedSheetId),h=r.useDashboardStore(k=>k.dashboard),{updateFrame:p,setIsVisualEditing:v}=r.useDashboardActions(),{getUpdatedFrame:b}=ae(),f=y.useUpdateVisualMutation(),j=y.useResolveExistingFrameSemanticExecutionPayload(),D=async()=>{if(!m){r.ue.error("No sheet selected");return}const k=(u==null?void 0:u.visualId)||(c==null?void 0:c.id);if(!k){r.ue.error("No visual to update");return}n(!0);try{const E=b();if(!ue(E)){n(!1);return}const L={...E,visualId:k},O=r.findDashboardFrameById(h,L.id),H=await j(L,{previousFrame:O});await f.mutateAsync({visualId:k,data:{frameObject:E}}),p(m,L,{semanticExecutionPayload:H}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",k]}),r.ue.success("Saved to library and applied locally"),setTimeout(()=>{v(!1)},300)}catch(E){console.error("Failed to save and apply:",E),r.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{n(!1)}};return e.jsx(r.Button,{onClick:D,className:s,size:"xs",variant:"default",disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(r.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function We({className:s}){const{setTempQueryData:a,setSqlGen:i}=r.useEditorActions(),n=y.useQueryClient(),c=r.useEditorStore(f=>f.tempQueryData),u=r.useEditorStore(f=>f.onClose),m=r.useEditorStore(f=>f.card),h=y.useEffectiveEditorCardType(),p=C.useMemo(()=>h!==m.type?{...m,type:h}:m,[m,h]),{queryKey:v}=y.useEditorCardQuery(p);function b(){if(c){const{queryKey:f,queryData:j}=c;f&&j&&n.setQueryData(f,j)}i({}),u==null||u()}return e.jsxs(r.Button,{onClick:b,className:s,size:"xs",variant:"outline",children:[e.jsx(J.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Xe({label:s="Clear",variant:a="secondary",className:i}={}){const n=Ee();return e.jsxs(r.Button,{onClick:n,className:i,size:"xs",variant:a,children:[e.jsx(J.X,{className:"h-3.5 w-3.5"}),s]})}exports.ControlDefinitionListEditor=$e;exports.EditorAcceptButton=He;exports.EditorCancelButton=We;exports.EditorClearButton=Xe;exports.FilterX=Ve;exports.Library=je;exports.Link2=ke;exports.VisualBadge=Oe;exports.VisualSaveAndApplyButton=Pe;exports.VisualSaveButton=Ke;exports.useCreateFlowOverlayState=Ye;exports.useEditorClearAction=Ee;exports.useSyncLegacyEditorState=Be;exports.useVisualUtils=ae;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { c as Ve, C as Re, X as et } from "./x-CXDkqdur.js";
|
|
2
2
|
import { useState as K, useEffect as ie, useCallback as j, useMemo as oe, useRef as Se, Fragment as gt } from "react";
|
|
3
|
-
import { E as de, z as _e, u as P, a4 as U, D as z, a5 as bt, Q as yt, V as xt, W as vt, c as fe, Y as Ct, a6 as St, a7 as kt, a8 as me, a9 as Qe, aa as Be, ab as ke, ac as Ne, ad as Nt, ae as wt, af as $e, ag as Dt, ah as Et, ai as pe, aj as Tt, ak as We, B as q, al as tt, am as at, an as rt, O as ne, Z as st, _ as we, $ as De, a0 as Ee, a1 as Te, a2 as Fe, ao as nt, ap as Ft, aq as It, ar as He, as as Vt, at as Ke, au as _t, av as At, aw as Lt, ax as qt, ay as Ie, d as Mt, L as ot, az as Ot, aA as zt } from "./switch-
|
|
4
|
-
import { b5 as Ut, ay as jt, b6 as ce, b7 as Rt, b8 as Ae, b9 as Qt, ba as Bt, bb as $t, bc as Wt, bd as Ht, be as Kt, bf as lt, bg as it, u as Yt, bh as Xt, bi as Gt, bj as Ye, bk as Jt, bl as Pt, bm as dt, bn as ct, bo as Zt, bp as ea, bq as ta, br as aa, bs as ra, aX as sa, bt as na, bu as ut, bv as oa } from "./index-
|
|
3
|
+
import { E as de, z as _e, u as P, a4 as U, D as z, a5 as bt, Q as yt, V as xt, W as vt, c as fe, Y as Ct, a6 as St, a7 as kt, a8 as me, a9 as Qe, aa as Be, ab as ke, ac as Ne, ad as Nt, ae as wt, af as $e, ag as Dt, ah as Et, ai as pe, aj as Tt, ak as We, B as q, al as tt, am as at, an as rt, O as ne, Z as st, _ as we, $ as De, a0 as Ee, a1 as Te, a2 as Fe, ao as nt, ap as Ft, aq as It, ar as He, as as Vt, at as Ke, au as _t, av as At, aw as Lt, ax as qt, ay as Ie, d as Mt, L as ot, az as Ot, aA as zt } from "./switch-CD4uGTZI.js";
|
|
4
|
+
import { b5 as Ut, ay as jt, b6 as ce, b7 as Rt, b8 as Ae, b9 as Qt, ba as Bt, bb as $t, bc as Wt, bd as Ht, be as Kt, bf as lt, bg as it, u as Yt, bh as Xt, bi as Gt, bj as Ye, bk as Jt, bl as Pt, bm as dt, bn as ct, bo as Zt, bp as ea, bq as ta, br as aa, bs as ra, aX as sa, bt as na, bu as ut, bv as oa } from "./index-ByiS9sB4.js";
|
|
5
5
|
import { jsx as a, jsxs as m, Fragment as Z } from "react/jsx-runtime";
|
|
6
|
-
import "./
|
|
6
|
+
import "./card-config-utils-Bq1enstT.js";
|
|
7
7
|
import { t as la } from "./validators-BDYzZFgs.js";
|
|
8
|
-
import "./matrix-operation-contract-
|
|
8
|
+
import "./matrix-operation-contract-xL8IhFzp.js";
|
|
9
9
|
import "../value-format-preferences/index.js";
|
|
10
|
-
import { C as Xe } from "./
|
|
11
|
-
import { f as ia } from "./index-
|
|
10
|
+
import { C as Xe } from "./selection-reducer-B94WgZ9V.js";
|
|
11
|
+
import { f as ia } from "./index-0pdaQ9e1.js";
|
|
12
12
|
import { S as mt } from "./save-DgMfP0j8.js";
|
|
13
13
|
/**
|
|
14
14
|
* @license lucide-react v0.453.0 - ISC
|