@peak-ai/canvas 1.4.20 → 1.4.21
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/declaration.d.js +2 -0
- package/declaration.d.js.map +1 -0
- package/package.json +1 -1
- package/plugins/grapejs-plugin.js +3 -3
- package/plugins/grapejs-plugin.js.map +1 -1
- package/plugins/helpers/custom-modal.js +1 -1
- package/plugins/helpers/custom-modal.js.map +1 -1
- package/plugins/helpers/query-cache-context.d.ts +18 -0
- package/plugins/helpers/query-cache-context.js +2 -0
- package/plugins/helpers/query-cache-context.js.map +1 -0
- package/plugins/helpers/query-cache-singleton.d.ts +25 -0
- package/plugins/helpers/query-cache-singleton.js +4 -0
- package/plugins/helpers/query-cache-singleton.js.map +1 -0
- package/plugins/helpers/query-cache-utils.d.ts +48 -0
- package/plugins/helpers/query-cache-utils.js +6 -0
- package/plugins/helpers/query-cache-utils.js.map +1 -0
- package/plugins/helpers/query-details-modal.d.ts +7 -2
- package/plugins/helpers/query-details-modal.js +3 -3
- package/plugins/helpers/query-details-modal.js.map +1 -1
- package/plugins/helpers/query-heading-formatter.d.ts +1 -0
- package/plugins/helpers/query-heading-formatter.js +5 -0
- package/plugins/helpers/query-heading-formatter.js.map +1 -0
- package/plugins/helpers/query-loading-modal.d.ts +2 -1
- package/plugins/helpers/query-loading-modal.js +1 -1
- package/plugins/helpers/query-loading-modal.js.map +1 -1
- package/plugins/helpers/render-components.js +3 -3
- package/plugins/helpers/render-components.js.map +1 -1
- package/plugins/helpers/styled-info-button.d.ts +2 -1
- package/plugins/helpers/styled-info-button.js +5 -1
- package/plugins/helpers/styled-info-button.js.map +1 -1
- package/shadcn/components/icons/thinking.gif +0 -0
- package/types/images.d.js +2 -0
- package/types/images.d.js.map +1 -0
package/declaration.d.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.d.js","names":[],"sources":["../src/declaration.d.ts"],"sourcesContent":["declare module '*.gif';"],"mappings":"","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _extends from"@babel/runtime/helpers/extends";/* eslint-disable import/no-named-as-default-member *//* eslint-disable func-names *//* eslint-disable @typescript-eslint/no-explicit-any */import ReactDOM from"react-dom";import{getRenderers}from"./helpers/render-components";import{jsx as _jsx}from"react/jsx-runtime";export function createGrapesjsShadcnGenericPlugin(mode,performInteraction,renderedComponents,setHasChanged){if(renderedComponents===void 0){renderedComponents={}}return function grapesjsShadcnGenericPlugin(editor){editor.DomComponents.addType("shadcn-generic",{model:{defaults:{tagName:"div",droppable:false,componentName:"Card",componentProps:{},traits:[]}},view:{events:{"input [data-slot]":"handleSlotInput"},handleSlotInput:function handleSlotInput(e){var target=e.target;var slot=target.dataset.slot;var text=target.innerText;var props=this.model.get("componentProps")||{};if(!slot){return}if(slot.startsWith("table-header-")){var _props$data;var idx=parseInt(slot.split("-")[2],10);var dataKeys=Object.keys(((_props$data=props.data)==null?void 0:_props$data[0])||{});if(!props.headerMapper){props.headerMapper={}}var key=dataKeys[idx];if(key){props.headerMapper[key]=text}}else{props[slot]=text}this.model.set("componentProps",_extends({},props));if(!["search-input"].includes(slot)){setHasChanged(true)}},render:function render(){var _this=this;var compName=this.model.get("componentName");var compProps=this.model.get("componentProps");if(typeof compProps==="string"){try{compProps=JSON.parse(compProps)}catch(err){// eslint-disable-next-line no-console
|
|
2
|
-
console.error("Invalid JSON in componentProps",err);compProps={}}}compProps.isEditable=mode==="editor";compProps.performInteraction=performInteraction;compProps.onChange=function(data){_this.model.set("componentProps",_extends({},_this.model.get("componentProps"),data))};var renderers=getRenderers();var Renderer=renderers[compName];if(Renderer){if(compName==="Tabs"){ReactDOM.render(/*#__PURE__*/_jsx(Renderer,_extends({},compProps,{gjsModel:this.model})),this.el);var children=this.model.components();var tabsContent=this.el.querySelectorAll(".tabs-content");var tabAttributes=this.model.get("attributes")||{};var hasTabsError=tabAttributes.error||compProps.error;var hasTabsMissing=tabAttributes.isMissing||compProps.isMissing;var isFallback=Array.from(tabsContent).some(function(el){return el.dataset.fallback==="true"});if(!isFallback&&tabsContent.length>0){// Helper function to sync child attributes
|
|
1
|
+
import _extends from"@babel/runtime/helpers/extends";/* eslint-disable import/no-named-as-default-member *//* eslint-disable func-names *//* eslint-disable @typescript-eslint/no-explicit-any */import ReactDOM from"react-dom";import{getRenderers}from"./helpers/render-components";import{QueryCacheProvider}from"./helpers/query-cache-context";import{jsx as _jsx}from"react/jsx-runtime";export function createGrapesjsShadcnGenericPlugin(mode,performInteraction,renderedComponents,setHasChanged){if(renderedComponents===void 0){renderedComponents={}}return function grapesjsShadcnGenericPlugin(editor){editor.DomComponents.addType("shadcn-generic",{model:{defaults:{tagName:"div",droppable:false,componentName:"Card",componentProps:{},traits:[]}},view:{events:{"input [data-slot]":"handleSlotInput"},handleSlotInput:function handleSlotInput(e){var target=e.target;var slot=target.dataset.slot;var text=target.innerText;var props=this.model.get("componentProps")||{};if(!slot){return}if(slot.startsWith("table-header-")){var _props$data;var idx=parseInt(slot.split("-")[2],10);var dataKeys=Object.keys(((_props$data=props.data)==null?void 0:_props$data[0])||{});if(!props.headerMapper){props.headerMapper={}}var key=dataKeys[idx];if(key){props.headerMapper[key]=text}}else{props[slot]=text}this.model.set("componentProps",_extends({},props));if(!["search-input"].includes(slot)){setHasChanged(true)}},render:function render(){var _this=this;var compName=this.model.get("componentName");var compProps=this.model.get("componentProps");if(typeof compProps==="string"){try{compProps=JSON.parse(compProps)}catch(err){// eslint-disable-next-line no-console
|
|
2
|
+
console.error("Invalid JSON in componentProps",err);compProps={}}}compProps.isEditable=mode==="editor";compProps.performInteraction=performInteraction;compProps.onChange=function(data){_this.model.set("componentProps",_extends({},_this.model.get("componentProps"),data))};var renderers=getRenderers();var Renderer=renderers[compName];if(Renderer){if(compName==="Tabs"){ReactDOM.render(/*#__PURE__*/_jsx(QueryCacheProvider,{maxCacheSize:100,maxCacheAge:5*60*1000,children:/*#__PURE__*/_jsx(Renderer,_extends({},compProps,{gjsModel:this.model}))}),this.el);var children=this.model.components();var tabsContent=this.el.querySelectorAll(".tabs-content");var tabAttributes=this.model.get("attributes")||{};var hasTabsError=tabAttributes.error||compProps.error;var hasTabsMissing=tabAttributes.isMissing||compProps.isMissing;var isFallback=Array.from(tabsContent).some(function(el){return el.dataset.fallback==="true"});if(!isFallback&&tabsContent.length>0){// Helper function to sync child attributes
|
|
3
3
|
// eslint-disable-next-line no-inner-declarations
|
|
4
|
-
var syncChildAttributes=function syncChildAttributes(childModel){var childAttributes=childModel.get("attributes")||{};var childProps=childModel.get("componentProps")||{};var hasError=hasTabsError||childAttributes.error||childProps.error;var hasMissing=hasTabsMissing||childAttributes.isMissing||childProps.isMissing;if(hasError||hasMissing){var newAttributes=_extends({},childAttributes,{loading:false,error:hasError,isMissing:hasMissing,inheritedFromParent:!!(hasTabsError||hasTabsMissing)});childModel.set("attributes",newAttributes,{silent:false})}};children.each(function(childModel,i){var childView=_this.createView(childModel);if(childView&&tabsContent[i]){childView.render();tabsContent[i].appendChild(childView.el);setTimeout(function(){syncChildAttributes(childModel)},100);childModel.on("change:attributes",function(){syncChildAttributes(childModel)})}})}}else{ReactDOM.render(/*#__PURE__*/_jsx(Renderer,_extends({},compProps,{gjsModel:this.model})),this.el)}}else{this.el.innerHTML="<div>Unsupported component: "+compName+"</div>"}renderedComponents[this.model.get("id")]=this.model;return this},createView:function createView(model){var _this$em$get$getType;var ComponentView=(_this$em$get$getType=this.em.get("DomComponents").getType(model.get("type")))==null?void 0:_this$em$get$getType.view;if(!ComponentView){// eslint-disable-next-line no-console
|
|
4
|
+
var syncChildAttributes=function syncChildAttributes(childModel){var childAttributes=childModel.get("attributes")||{};var childProps=childModel.get("componentProps")||{};var hasError=hasTabsError||childAttributes.error||childProps.error;var hasMissing=hasTabsMissing||childAttributes.isMissing||childProps.isMissing;if(hasError||hasMissing){var newAttributes=_extends({},childAttributes,{loading:false,error:hasError,isMissing:hasMissing,inheritedFromParent:!!(hasTabsError||hasTabsMissing)});childModel.set("attributes",newAttributes,{silent:false})}};children.each(function(childModel,i){var childView=_this.createView(childModel);if(childView&&tabsContent[i]){childView.render();tabsContent[i].appendChild(childView.el);setTimeout(function(){syncChildAttributes(childModel)},100);childModel.on("change:attributes",function(){syncChildAttributes(childModel)})}})}}else{ReactDOM.render(/*#__PURE__*/_jsx(QueryCacheProvider,{maxCacheSize:100,maxCacheAge:5*60*1000,children:/*#__PURE__*/_jsx(Renderer,_extends({},compProps,{gjsModel:this.model}))}),this.el)}}else{this.el.innerHTML="<div>Unsupported component: "+compName+"</div>"}renderedComponents[this.model.get("id")]=this.model;return this},createView:function createView(model){var _this$em$get$getType;var ComponentView=(_this$em$get$getType=this.em.get("DomComponents").getType(model.get("type")))==null?void 0:_this$em$get$getType.view;if(!ComponentView){// eslint-disable-next-line no-console
|
|
5
5
|
console.warn("No view found for component type:",model.get("type"));return null}var view=new ComponentView({model:model,config:this.config,componentTypes:this.componentTypes});return view},remove:function remove(){// eslint-disable-next-line import/no-named-as-default-member
|
|
6
6
|
ReactDOM.unmountComponentAtNode(this.el);return this}}})}}
|
|
7
7
|
//# sourceMappingURL=grapejs-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grapejs-plugin.js","names":["ReactDOM","getRenderers","jsx","_jsx","createGrapesjsShadcnGenericPlugin","mode","performInteraction","renderedComponents","setHasChanged","grapesjsShadcnGenericPlugin","editor","DomComponents","addType","model","defaults","tagName","droppable","componentName","componentProps","traits","view","events","handleSlotInput","e","target","slot","dataset","text","innerText","props","get","startsWith","_props$data","idx","parseInt","split","dataKeys","Object","keys","data","headerMapper","key","set","_extends","includes","render","_this","compName","compProps","JSON","parse","err","console","error","isEditable","onChange","renderers","Renderer","gjsModel","el","children","components","tabsContent","querySelectorAll","tabAttributes","hasTabsError","hasTabsMissing","isMissing","isFallback","Array","from","some","fallback","length","syncChildAttributes","childModel","childAttributes","childProps","hasError","hasMissing","newAttributes","loading","inheritedFromParent","silent","each","i","childView","createView","appendChild","setTimeout","on","innerHTML","_this$em$get$getType","ComponentView","em","getType","warn","config","componentTypes","remove","unmountComponentAtNode"],"sources":["../../src/plugins/grapejs-plugin.tsx"],"sourcesContent":["/* eslint-disable import/no-named-as-default-member */\n/* eslint-disable func-names */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport ReactDOM from 'react-dom';\nimport { Editor, Component } from 'grapesjs';\nimport { getRenderers } from './helpers/render-components';\n\nexport function createGrapesjsShadcnGenericPlugin(\n mode: 'editor' | 'preview',\n performInteraction: (payload: Record<string, any>) => void,\n renderedComponents: Record<string, Component> = {},\n setHasChanged: (hasChanged: boolean) => void,\n) {\n return function grapesjsShadcnGenericPlugin(editor: Editor): void {\n editor.DomComponents.addType('shadcn-generic', {\n model: {\n defaults: {\n tagName: 'div',\n droppable: false,\n componentName: 'Card',\n componentProps: {},\n traits: [],\n },\n },\n view: {\n events: {\n 'input [data-slot]': 'handleSlotInput',\n } as any,\n handleSlotInput(e: Event) {\n const target = e.target as HTMLElement;\n const slot = target.dataset.slot;\n const text = target.innerText;\n\n const props = this.model.get('componentProps') || {};\n\n if (!slot) {\n return;\n }\n\n if (slot.startsWith('table-header-')) {\n const idx = parseInt(slot.split('-')[2], 10);\n const dataKeys = Object.keys(props.data?.[0] || {});\n\n if (!props.headerMapper) {\n props.headerMapper = {};\n }\n\n const key = dataKeys[idx];\n\n if (key) {\n props.headerMapper[key] = text;\n }\n } else {\n props[slot] = text;\n }\n\n this.model.set('componentProps', {\n ...props,\n });\n\n if (!['search-input'].includes(slot)) {\n setHasChanged(true);\n }\n },\n render: function () {\n const compName: string = this.model.get('componentName');\n let compProps: any = this.model.get('componentProps');\n\n if (typeof compProps === 'string') {\n try {\n compProps = JSON.parse(compProps);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('Invalid JSON in componentProps', err);\n compProps = {};\n }\n }\n\n compProps.isEditable = mode === 'editor';\n compProps.performInteraction = performInteraction;\n\n compProps.onChange = (data: Record<string, any>) => {\n this.model.set('componentProps', {\n ...this.model.get('componentProps'),\n ...data,\n });\n };\n\n const renderers = getRenderers();\n const Renderer = renderers[compName];\n\n if (Renderer) {\n if (compName === 'Tabs') {\n ReactDOM.render(<Renderer {...compProps} gjsModel={this.model} />, this.el);\n\n const children = this.model.components();\n const tabsContent = this.el.querySelectorAll('.tabs-content');\n\n const tabAttributes = this.model.get('attributes') || {};\n const hasTabsError = tabAttributes.error || compProps.error;\n const hasTabsMissing = tabAttributes.isMissing || compProps.isMissing;\n const isFallback = Array.from(tabsContent).some(\n (el: Element) => (el as HTMLElement).dataset.fallback === 'true',\n );\n\n if (!isFallback && tabsContent.length > 0) {\n // Helper function to sync child attributes\n // eslint-disable-next-line no-inner-declarations\n function syncChildAttributes(childModel: any) {\n const childAttributes = childModel.get('attributes') || {};\n const childProps = childModel.get('componentProps') || {};\n\n const hasError = hasTabsError || childAttributes.error || childProps.error;\n const hasMissing =\n hasTabsMissing || childAttributes.isMissing || childProps.isMissing;\n\n if (hasError || hasMissing) {\n const newAttributes = {\n ...childAttributes,\n loading: false,\n error: hasError,\n isMissing: hasMissing,\n inheritedFromParent: !!(hasTabsError || hasTabsMissing),\n };\n\n childModel.set('attributes', newAttributes, { silent: false });\n }\n }\n\n children.each((childModel, i) => {\n const childView = this.createView(childModel);\n\n if (childView && tabsContent[i]) {\n childView.render();\n tabsContent[i].appendChild(childView.el);\n\n setTimeout(() => {\n syncChildAttributes(childModel);\n }, 100);\n\n childModel.on('change:attributes', () => {\n syncChildAttributes(childModel);\n });\n }\n });\n }\n } else {\n ReactDOM.render(<Renderer {...compProps} gjsModel={this.model} />, this.el);\n }\n } else {\n this.el.innerHTML = `<div>Unsupported component: ${compName}</div>`;\n }\n\n renderedComponents[this.model.get('id')] = this.model;\n\n return this;\n },\n createView(model: any) {\n const ComponentView = this.em.get('DomComponents').getType(model.get('type'))?.view;\n\n if (!ComponentView) {\n // eslint-disable-next-line no-console\n console.warn('No view found for component type:', model.get('type'));\n\n return null;\n }\n\n const view = new ComponentView({\n model,\n config: this.config,\n componentTypes: this.componentTypes,\n });\n\n return view;\n },\n remove: function () {\n // eslint-disable-next-line import/no-named-as-default-member\n ReactDOM.unmountComponentAtNode(this.el);\n\n return this;\n },\n },\n });\n };\n}\n"],"mappings":"qDAAA,sDACA,+BACA,uDACA,MAAO,CAAAA,QAAQ,KAAM,WAAW,CAEhC,OAASC,YAAY,KAAQ,6BAA6B,CAAC,OAAAC,GAAA,IAAAC,IAAA,yBAE3D,MAAO,SAAS,CAAAC,iCAAiCA,CAC/CC,IAA0B,CAC1BC,kBAA0D,CAC1DC,kBAA6C,CAC7CC,aAA4C,CAC5C,IAFAD,kBAA6C,WAA7CA,kBAA6C,CAAG,CAAC,CAAC,CAGlD,MAAO,SAAS,CAAAE,2BAA2BA,CAACC,MAAc,CAAQ,CAChEA,MAAM,CAACC,aAAa,CAACC,OAAO,CAAC,gBAAgB,CAAE,CAC7CC,KAAK,CAAE,CACLC,QAAQ,CAAE,CACRC,OAAO,CAAE,KAAK,CACdC,SAAS,CAAE,KAAK,CAChBC,aAAa,CAAE,MAAM,CACrBC,cAAc,CAAE,CAAC,CAAC,CAClBC,MAAM,CAAE,EACV,CACF,CAAC,CACDC,IAAI,CAAE,CACJC,MAAM,CAAE,CACN,mBAAmB,CAAE,iBACvB,CAAQ,CACRC,eAAe,SAAf,CAAAA,eAAeA,CAACC,CAAQ,CAAE,CACxB,GAAM,CAAAC,MAAM,CAAGD,CAAC,CAACC,MAAqB,CACtC,GAAM,CAAAC,IAAI,CAAGD,MAAM,CAACE,OAAO,CAACD,IAAI,CAChC,GAAM,CAAAE,IAAI,CAAGH,MAAM,CAACI,SAAS,CAE7B,GAAM,CAAAC,KAAK,CAAG,IAAI,CAAChB,KAAK,CAACiB,GAAG,CAAC,gBAAgB,CAAC,EAAI,CAAC,CAAC,CAEpD,GAAI,CAACL,IAAI,CAAE,CACT,MACF,CAEA,GAAIA,IAAI,CAACM,UA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,CAAC,CACD+E,MAAM,CAAE,QAAR,CAAAA,MAAMA,CAAA,CAAc,CAClB;AACAnG,QAAQ,CAACoG,sBAAsB,CAAC,IAAI,CAACzC,EAAE,CAAC,CAExC,MAAO,KACT,CACF,CACF,CAAC,CACH,CACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"grapejs-plugin.js","names":["ReactDOM","getRenderers","QueryCacheProvider","jsx","_jsx","createGrapesjsShadcnGenericPlugin","mode","performInteraction","renderedComponents","setHasChanged","grapesjsShadcnGenericPlugin","editor","DomComponents","addType","model","defaults","tagName","droppable","componentName","componentProps","traits","view","events","handleSlotInput","e","target","slot","dataset","text","innerText","props","get","startsWith","_props$data","idx","parseInt","split","dataKeys","Object","keys","data","headerMapper","key","set","_extends","includes","render","_this","compName","compProps","JSON","parse","err","console","error","isEditable","onChange","renderers","Renderer","maxCacheSize","maxCacheAge","children","gjsModel","el","components","tabsContent","querySelectorAll","tabAttributes","hasTabsError","hasTabsMissing","isMissing","isFallback","Array","from","some","fallback","length","syncChildAttributes","childModel","childAttributes","childProps","hasError","hasMissing","newAttributes","loading","inheritedFromParent","silent","each","i","childView","createView","appendChild","setTimeout","on","innerHTML","_this$em$get$getType","ComponentView","em","getType","warn","config","componentTypes","remove","unmountComponentAtNode"],"sources":["../../src/plugins/grapejs-plugin.tsx"],"sourcesContent":["/* eslint-disable import/no-named-as-default-member */\n/* eslint-disable func-names */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport ReactDOM from 'react-dom';\nimport { Editor, Component } from 'grapesjs';\nimport { getRenderers } from './helpers/render-components';\nimport { QueryCacheProvider } from './helpers/query-cache-context';\n\nexport function createGrapesjsShadcnGenericPlugin(\n mode: 'editor' | 'preview',\n performInteraction: (payload: Record<string, any>) => void,\n renderedComponents: Record<string, Component> = {},\n setHasChanged: (hasChanged: boolean) => void,\n) {\n return function grapesjsShadcnGenericPlugin(editor: Editor): void {\n editor.DomComponents.addType('shadcn-generic', {\n model: {\n defaults: {\n tagName: 'div',\n droppable: false,\n componentName: 'Card',\n componentProps: {},\n traits: [],\n },\n },\n view: {\n events: {\n 'input [data-slot]': 'handleSlotInput',\n } as any,\n handleSlotInput(e: Event) {\n const target = e.target as HTMLElement;\n const slot = target.dataset.slot;\n const text = target.innerText;\n\n const props = this.model.get('componentProps') || {};\n\n if (!slot) {\n return;\n }\n\n if (slot.startsWith('table-header-')) {\n const idx = parseInt(slot.split('-')[2], 10);\n const dataKeys = Object.keys(props.data?.[0] || {});\n\n if (!props.headerMapper) {\n props.headerMapper = {};\n }\n\n const key = dataKeys[idx];\n\n if (key) {\n props.headerMapper[key] = text;\n }\n } else {\n props[slot] = text;\n }\n\n this.model.set('componentProps', {\n ...props,\n });\n\n if (!['search-input'].includes(slot)) {\n setHasChanged(true);\n }\n },\n render: function () {\n const compName: string = this.model.get('componentName');\n let compProps: any = this.model.get('componentProps');\n\n if (typeof compProps === 'string') {\n try {\n compProps = JSON.parse(compProps);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('Invalid JSON in componentProps', err);\n compProps = {};\n }\n }\n\n compProps.isEditable = mode === 'editor';\n compProps.performInteraction = performInteraction;\n\n compProps.onChange = (data: Record<string, any>) => {\n this.model.set('componentProps', {\n ...this.model.get('componentProps'),\n ...data,\n });\n };\n\n const renderers = getRenderers();\n const Renderer = renderers[compName];\n\n if (Renderer) {\n if (compName === 'Tabs') {\n ReactDOM.render(\n <QueryCacheProvider maxCacheSize={100} maxCacheAge={5 * 60 * 1000}>\n <Renderer {...compProps} gjsModel={this.model} />\n </QueryCacheProvider>,\n this.el\n );\n\n const children = this.model.components();\n const tabsContent = this.el.querySelectorAll('.tabs-content');\n\n const tabAttributes = this.model.get('attributes') || {};\n const hasTabsError = tabAttributes.error || compProps.error;\n const hasTabsMissing = tabAttributes.isMissing || compProps.isMissing;\n const isFallback = Array.from(tabsContent).some(\n (el: Element) => (el as HTMLElement).dataset.fallback === 'true',\n );\n\n if (!isFallback && tabsContent.length > 0) {\n // Helper function to sync child attributes\n // eslint-disable-next-line no-inner-declarations\n function syncChildAttributes(childModel: any) {\n const childAttributes = childModel.get('attributes') || {};\n const childProps = childModel.get('componentProps') || {};\n\n const hasError = hasTabsError || childAttributes.error || childProps.error;\n const hasMissing =\n hasTabsMissing || childAttributes.isMissing || childProps.isMissing;\n\n if (hasError || hasMissing) {\n const newAttributes = {\n ...childAttributes,\n loading: false,\n error: hasError,\n isMissing: hasMissing,\n inheritedFromParent: !!(hasTabsError || hasTabsMissing),\n };\n\n childModel.set('attributes', newAttributes, { silent: false });\n }\n }\n\n children.each((childModel, i) => {\n const childView = this.createView(childModel);\n\n if (childView && tabsContent[i]) {\n childView.render();\n tabsContent[i].appendChild(childView.el);\n\n setTimeout(() => {\n syncChildAttributes(childModel);\n }, 100);\n\n childModel.on('change:attributes', () => {\n syncChildAttributes(childModel);\n });\n }\n });\n }\n } else {\n ReactDOM.render(\n <QueryCacheProvider maxCacheSize={100} maxCacheAge={5 * 60 * 1000}>\n <Renderer {...compProps} gjsModel={this.model} />\n </QueryCacheProvider>,\n this.el\n );\n }\n } else {\n this.el.innerHTML = `<div>Unsupported component: ${compName}</div>`;\n }\n\n renderedComponents[this.model.get('id')] = this.model;\n\n return this;\n },\n createView(model: any) {\n const ComponentView = this.em.get('DomComponents').getType(model.get('type'))?.view;\n\n if (!ComponentView) {\n // eslint-disable-next-line no-console\n console.warn('No view found for component type:', model.get('type'));\n\n return null;\n }\n\n const view = new ComponentView({\n model,\n config: this.config,\n componentTypes: this.componentTypes,\n });\n\n return view;\n },\n remove: function () {\n // eslint-disable-next-line import/no-named-as-default-member\n ReactDOM.unmountComponentAtNode(this.el);\n\n return this;\n },\n },\n });\n };\n}\n"],"mappings":"qDAAA,sDACA,+BACA,uDACA,MAAO,CAAAA,QAAQ,KAAM,WAAW,CAEhC,OAASC,YAAY,KAAQ,6BAA6B,CAC1D,OAASC,kBAAkB,KAAQ,+BAA+B,CAAC,OAAAC,GAAA,IAAAC,IAAA,yBAEnE,M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ACuG,sBAAsB,CAAC,IAAI,CAACxC,EAAE,CAAC,CAExC,MAAO,KACT,CACF,CACF,CAAC,CACH,CACF","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import React,{useEffect}from"react";import{X}from"lucide-react";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function CustomModal(_ref){var isOpen=_ref.isOpen,onClose=_ref.onClose,title=_ref.title,children=_ref.children,_ref$className=_ref.className,className=_ref$className===void 0?"":_ref$className,titleIcon=_ref.titleIcon;useEffect(function(){function handleEscapeKey(event){if(event.key==="Escape"&&isOpen){onClose()}}if(isOpen){document.addEventListener("keydown",handleEscapeKey);document.
|
|
1
|
+
import React,{useEffect}from"react";import{X}from"lucide-react";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function CustomModal(_ref){var isOpen=_ref.isOpen,onClose=_ref.onClose,title=_ref.title,children=_ref.children,_ref$className=_ref.className,className=_ref$className===void 0?"":_ref$className,titleIcon=_ref.titleIcon;useEffect(function(){function handleEscapeKey(event){if(event.key==="Escape"&&isOpen){onClose()}}if(isOpen){var _iframe$contentWindow;document.addEventListener("keydown",handleEscapeKey);var iframe=document.querySelector(".gjs-frame");var iframeDocument=(iframe==null?void 0:iframe.contentDocument)||(iframe==null||(_iframe$contentWindow=iframe.contentWindow)==null?void 0:_iframe$contentWindow.document);if(iframeDocument){var _iframeDocument$docum;(_iframeDocument$docum=iframeDocument.documentElement)==null||_iframeDocument$docum.style.setProperty("overflow","hidden","important")}return function(){document.removeEventListener("keydown",handleEscapeKey);if(iframeDocument){var _iframeDocument$docum2;(_iframeDocument$docum2=iframeDocument.documentElement)==null||_iframeDocument$docum2.style.removeProperty("overflow")}}}return function(){document.removeEventListener("keydown",handleEscapeKey)}},[isOpen,onClose]);function handleBackdropClick(event){if(event.target===event.currentTarget){onClose()}}if(!isOpen){return null}return/*#__PURE__*/_jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 bg-black bg-opacity-30 "+className,onClick:handleBackdropClick,children:[/*#__PURE__*/_jsxs("div",{className:"relative w-full max-w-2xl max-h-[90vh] min-h-[45vh] bg-white rounded-lg shadow-xl overflow-hidden animate-modal-fade-in",onClick:function onClick(e){return e.stopPropagation()},children:[/*#__PURE__*/_jsxs("div",{className:"p-6 border-b border-gray-200 bg-gray-50 relative flex items-center justify-between",children:[/*#__PURE__*/_jsxs("h2",{className:"flex items-center text-lg font-semibold text-gray-900",children:[titleIcon&&/*#__PURE__*/_jsx("span",{className:"mr-2",children:titleIcon}),title]}),/*#__PURE__*/_jsx("button",{onClick:onClose,className:"transition-colors duration-200 hover:bg-gray-100 rounded p-1 flex items-center justify-center",type:"button","aria-label":"Close modal",style:{width:"24px",height:"24px"},children:/*#__PURE__*/_jsx(X,{size:12,className:"text-gray-600",style:{opacity:1,transform:"rotate(0deg)"}})})]}),/*#__PURE__*/_jsx("div",{className:"overflow-y-auto max-h-[calc(90vh-160px)]",children:children})]}),/*#__PURE__*/_jsx("style",{children:"\n .animate-modal-fade-in {\n animation: modalFadeIn 0.2s ease-out;\n }\n \n @keyframes modalFadeIn {\n from {\n opacity: 0;\n transform: scale(0.95) translateY(-10px);\n }\n to {\n opacity: 1;\n transform: scale(1) translateY(0);\n }\n }\n "})]})}export default CustomModal;
|
|
2
2
|
//# sourceMappingURL=custom-modal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-modal.js","names":["React","useEffect","X","jsx","_jsx","jsxs","_jsxs","CustomModal","_ref","isOpen","onClose","title","children","_ref$className","className","titleIcon","handleEscapeKey","event","key","document","addEventListener","
|
|
1
|
+
{"version":3,"file":"custom-modal.js","names":["React","useEffect","X","jsx","_jsx","jsxs","_jsxs","CustomModal","_ref","isOpen","onClose","title","children","_ref$className","className","titleIcon","handleEscapeKey","event","key","_iframe$contentWindow","document","addEventListener","iframe","querySelector","iframeDocument","contentDocument","contentWindow","_iframeDocument$docum","documentElement","style","setProperty","removeEventListener","_iframeDocument$docum2","removeProperty","handleBackdropClick","target","currentTarget","onClick","e","stopPropagation","type","width","height","size","opacity","transform"],"sources":["../../../src/plugins/helpers/custom-modal.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { X } from 'lucide-react';\n\ntype CustomModalProps = {\n isOpen: boolean;\n onClose: () => void;\n title: string;\n children: React.ReactNode;\n className?: string;\n titleIcon?: React.ReactNode;\n}\n\nexport function CustomModal({\n isOpen,\n onClose,\n title,\n children,\n className = '',\n titleIcon\n}: CustomModalProps) {\n\n useEffect(() => {\n function handleEscapeKey(event: KeyboardEvent) {\n if (event.key === 'Escape' && isOpen) {\n onClose();\n }\n }\n\n if (isOpen) {\n document.addEventListener('keydown', handleEscapeKey);\n const iframe = document.querySelector('.gjs-frame') as HTMLIFrameElement;\n const iframeDocument = iframe?.contentDocument || iframe?.contentWindow?.document;\n \n if (iframeDocument) {\n iframeDocument.documentElement?.style.setProperty('overflow', 'hidden', 'important');\n }\n\n return () => {\n document.removeEventListener('keydown', handleEscapeKey);\n \n if (iframeDocument) {\n iframeDocument.documentElement?.style.removeProperty('overflow');\n }\n };\n }\n\n return () => {\n document.removeEventListener('keydown', handleEscapeKey);\n };\n }, [isOpen, onClose]);\n\n function handleBackdropClick(event: React.MouseEvent<HTMLDivElement>) {\n if (event.target === event.currentTarget) {\n onClose();\n }\n }\n\n if (!isOpen) {\n return null;\n }\n\n return (\n <div\n className={`fixed inset-0 z-[9999] flex items-center justify-center p-4 bg-black bg-opacity-30 ${className}`}\n onClick={handleBackdropClick}\n >\n <div\n className=\"relative w-full max-w-2xl max-h-[90vh] min-h-[45vh] bg-white rounded-lg shadow-xl overflow-hidden animate-modal-fade-in\"\n onClick={(e) => e.stopPropagation()}\n >\n <div className=\"p-6 border-b border-gray-200 bg-gray-50 relative flex items-center justify-between\">\n <h2 className=\"flex items-center text-lg font-semibold text-gray-900\">\n {titleIcon && <span className=\"mr-2\">{titleIcon}</span>}\n {title}\n </h2>\n\n <button\n onClick={onClose}\n className=\"transition-colors duration-200 hover:bg-gray-100 rounded p-1 flex items-center justify-center\"\n type=\"button\"\n aria-label=\"Close modal\"\n style={{\n width: '24px',\n height: '24px'\n }}\n >\n <X \n size={12}\n className=\"text-gray-600\"\n style={{ \n opacity: 1,\n transform: 'rotate(0deg)'\n }}\n />\n </button>\n </div>\n\n <div className=\"overflow-y-auto max-h-[calc(90vh-160px)]\">\n {children}\n </div>\n </div>\n\n <style>{`\n .animate-modal-fade-in {\n animation: modalFadeIn 0.2s ease-out;\n }\n \n @keyframes modalFadeIn {\n from {\n opacity: 0;\n transform: scale(0.95) translateY(-10px);\n }\n to {\n opacity: 1;\n transform: scale(1) translateY(0);\n }\n }\n `}</style>\n </div>\n );\n}\n\nexport default CustomModal;\n"],"mappings":"AAAA,MAAO,CAAAA,KAAK,EAAIC,SAAS,KAAQ,OAAO,CACxC,OAASC,CAAC,KAAQ,cAAc,CAAC,OAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBAWjC,MAAO,SAAS,CAAAC,WAAWA,CAAAC,IAAA,CAON,IANnB,CAAAC,MAAM,CAAAD,IAAA,CAANC,MAAM,CACNC,OAAO,CAAAF,IAAA,CAAPE,OAAO,CACPC,KAAK,CAAAH,IAAA,CAALG,KAAK,CACLC,QAAQ,CAAAJ,IAAA,CAARI,QAAQ,CAAAC,cAAA,CAAAL,IAAA,CACRM,SAAS,CAATA,SAAS,CAAAD,cAAA,UAAG,EAAE,CAAAA,cAAA,CACdE,SAAS,CAAAP,IAAA,CAATO,SAAS,CAGTd,SAAS,CAAC,UAAM,CACd,QAAS,CAAAe,eAAeA,CAACC,KAAoB,CAAE,CAC7C,GAAIA,KAAK,CAACC,GAAG,GAAK,QAAQ,EAAIT,MAAM,CAAE,CACpCC,OAAO,CAAC,CACV,CACF,CAEA,GAAID,MAAM,CAAE,KAAAU,qBAAA,CACVC,QAAQ,CAACC,gBAAgB,CAAC,SAAS,CAAEL,eAAe,CAAC,CACrD,G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C,oFAAoF,CAAAF,QAAA,eACjGN,KAAA,OAAIQ,SAAS,CAAC,uDAAuD,CAAAF,QAAA,EAClEG,SAAS,eAAIX,IAAA,SAAMU,SAAS,CAAC,MAAM,CAAAF,QAAA,CAAEG,SAAS,CAAO,CAAC,CACtDJ,KAAK,EACJ,CAAC,cAELP,IAAA,WACEiC,OAAO,CAAE3B,OAAQ,CACjBI,SAAS,CAAC,+FAA+F,CACzG0B,IAAI,CAAC,QAAQ,CACb,aAAW,aAAa,CACxBX,KAAK,CAAE,CACLY,KAAK,CAAE,MAAM,CACbC,MAAM,CAAE,MACV,CAAE,CAAA9B,QAAA,cAEFR,IAAA,CAACF,CAAC,EACAyC,IAAI,CAAE,EAAG,CACT7B,SAAS,CAAC,eAAe,CACzBe,KAAK,CAAE,CACLe,OAAO,CAAE,CAAC,CACVC,SAAS,CAAE,cACb,CAAE,CACH,CAAC,CACI,CAAC,EACN,CAAC,cAENzC,IAAA,QAAKU,SAAS,CAAC,0CAA0C,CAAAF,QAAA,CACtDA,QAAQ,CACN,CAAC,EACH,CAAC,cAENR,IAAA,UAAAQ,QAAA,sXAeS,CAAC,EACP,CAET,CAEA,cAAe,CAAAL,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { QueryCacheEntry, InteractionType, InteractionState } from './query-cache-utils';
|
|
3
|
+
type QueryCacheContextValue = {
|
|
4
|
+
getCachedQuery: (componentId: string, interactionType: InteractionType, state: InteractionState) => QueryCacheEntry | null;
|
|
5
|
+
setCachedQuery: (componentId: string, interactionType: InteractionType, state: InteractionState, entry: QueryCacheEntry) => void;
|
|
6
|
+
invalidateComponent: (componentId: string) => void;
|
|
7
|
+
invalidateAll: () => void;
|
|
8
|
+
isCached: (componentId: string, interactionType: InteractionType, state: InteractionState) => boolean;
|
|
9
|
+
};
|
|
10
|
+
type QueryCacheProviderProps = {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
maxCacheSize?: number;
|
|
13
|
+
maxCacheAge?: number;
|
|
14
|
+
};
|
|
15
|
+
export declare function QueryCacheProvider({ children, maxCacheSize, maxCacheAge, }: QueryCacheProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare function useQueryCache(): QueryCacheContextValue;
|
|
17
|
+
export declare function useInvalidateCacheOnChange(componentId: string | undefined, dependencies: unknown[]): void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import React,{createContext,useContext,useCallback,useRef,useMemo}from"react";import{getGlobalQueryCache,configureGlobalQueryCache}from"./query-cache-singleton";import{jsx as _jsx}from"react/jsx-runtime";var QueryCacheContext=/*#__PURE__*/createContext(null);export function QueryCacheProvider(_ref){var children=_ref.children,_ref$maxCacheSize=_ref.maxCacheSize,maxCacheSize=_ref$maxCacheSize===void 0?100:_ref$maxCacheSize,_ref$maxCacheAge=_ref.maxCacheAge,maxCacheAge=_ref$maxCacheAge===void 0?5*60*1000:_ref$maxCacheAge;var isConfigured=useRef(false);if(!isConfigured.current){configureGlobalQueryCache(maxCacheSize,maxCacheAge);isConfigured.current=true}var cacheManager=useRef(getGlobalQueryCache()).current;var getCachedQuery=useCallback(function(componentId,interactionType,state){return cacheManager.getCachedQuery(componentId,interactionType,state)},[cacheManager]);var setCachedQuery=useCallback(function(componentId,interactionType,state,entry){cacheManager.setCachedQuery(componentId,interactionType,state,entry)},[cacheManager]);var invalidateComponent=useCallback(function(componentId){cacheManager.invalidateComponent(componentId)},[cacheManager]);var invalidateAll=useCallback(function(){cacheManager.invalidateAll()},[cacheManager]);var isCached=useCallback(function(componentId,interactionType,state){return cacheManager.isCached(componentId,interactionType,state)},[cacheManager]);var value=useMemo(function(){return{getCachedQuery:getCachedQuery,setCachedQuery:setCachedQuery,invalidateComponent:invalidateComponent,invalidateAll:invalidateAll,isCached:isCached}},[getCachedQuery,setCachedQuery,invalidateComponent,invalidateAll,isCached]);return/*#__PURE__*/_jsx(QueryCacheContext.Provider,{value:value,children:children})}export function useQueryCache(){var context=useContext(QueryCacheContext);if(!context){throw new Error("useQueryCache must be used within a QueryCacheProvider")}return context}export function useInvalidateCacheOnChange(componentId,dependencies){var _useQueryCache=useQueryCache(),invalidateComponent=_useQueryCache.invalidateComponent;var prevDepsRef=useRef([]);React.useEffect(function(){if(prevDepsRef.current.length===0){prevDepsRef.current=dependencies;return}var hasChanged=dependencies.some(function(dep,index){return dep!==prevDepsRef.current[index]});if(hasChanged&&componentId){invalidateComponent(componentId)}prevDepsRef.current=dependencies},[componentId,invalidateComponent,dependencies])}
|
|
2
|
+
//# sourceMappingURL=query-cache-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-cache-context.js","names":["React","createContext","useContext","useCallback","useRef","useMemo","getGlobalQueryCache","configureGlobalQueryCache","jsx","_jsx","QueryCacheContext","QueryCacheProvider","_ref","children","_ref$maxCacheSize","maxCacheSize","_ref$maxCacheAge","maxCacheAge","isConfigured","current","cacheManager","getCachedQuery","componentId","interactionType","state","setCachedQuery","entry","invalidateComponent","invalidateAll","isCached","value","Provider","useQueryCache","context","Error","useInvalidateCacheOnChange","dependencies","_useQueryCache","prevDepsRef","useEffect","length","hasChanged","some","dep","index"],"sources":["../../../src/plugins/helpers/query-cache-context.tsx"],"sourcesContent":["import React, { createContext, useContext, useCallback, useRef, useMemo } from 'react';\nimport {\n QueryCacheEntry,\n InteractionType,\n InteractionState,\n} from './query-cache-utils';\nimport { getGlobalQueryCache, configureGlobalQueryCache } from './query-cache-singleton';\n\ntype QueryCacheContextValue = {\n getCachedQuery: (\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState\n ) => QueryCacheEntry | null;\n \n setCachedQuery: (\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState,\n entry: QueryCacheEntry\n ) => void;\n \n invalidateComponent: (componentId: string) => void;\n\n invalidateAll: () => void;\n\n isCached: (\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState\n ) => boolean;\n};\n\nconst QueryCacheContext = createContext<QueryCacheContextValue | null>(null);\n\ntype QueryCacheProviderProps = {\n children: React.ReactNode;\n maxCacheSize?: number;\n maxCacheAge?: number;\n};\n\nexport function QueryCacheProvider({\n children,\n maxCacheSize = 100,\n maxCacheAge = 5 * 60 * 1000, // 5 minutes\n}: QueryCacheProviderProps) {\n const isConfigured = useRef(false);\n \n if (!isConfigured.current) {\n configureGlobalQueryCache(maxCacheSize, maxCacheAge);\n isConfigured.current = true;\n }\n\n const cacheManager = useRef(getGlobalQueryCache()).current;\n \n const getCachedQuery = useCallback(\n (\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState\n ): QueryCacheEntry | null => {\n return cacheManager.getCachedQuery(componentId, interactionType, state);\n },\n [cacheManager]\n );\n \n const setCachedQuery = useCallback(\n (\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState,\n entry: QueryCacheEntry\n ) => {\n cacheManager.setCachedQuery(componentId, interactionType, state, entry);\n },\n [cacheManager]\n );\n \n const invalidateComponent = useCallback(\n (componentId: string) => {\n cacheManager.invalidateComponent(componentId);\n },\n [cacheManager]\n );\n \n const invalidateAll = useCallback(() => {\n cacheManager.invalidateAll();\n }, [cacheManager]);\n \n const isCached = useCallback(\n (\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState\n ): boolean => {\n return cacheManager.isCached(componentId, interactionType, state);\n },\n [cacheManager]\n );\n \n const value = useMemo(\n () => ({\n getCachedQuery,\n setCachedQuery,\n invalidateComponent,\n invalidateAll,\n isCached,\n }),\n [getCachedQuery, setCachedQuery, invalidateComponent, invalidateAll, isCached]\n );\n \n return (\n <QueryCacheContext.Provider value={value}>\n {children}\n </QueryCacheContext.Provider>\n );\n}\n\nexport function useQueryCache(): QueryCacheContextValue {\n const context = useContext(QueryCacheContext);\n \n if (!context) {\n throw new Error('useQueryCache must be used within a QueryCacheProvider');\n }\n \n return context;\n}\n\nexport function useInvalidateCacheOnChange(\n componentId: string | undefined,\n dependencies: unknown[]\n): void {\n const { invalidateComponent } = useQueryCache();\n const prevDepsRef = useRef<unknown[]>([]);\n \n React.useEffect(() => {\n if (prevDepsRef.current.length === 0) {\n prevDepsRef.current = dependencies;\n\n return;\n }\n \n const hasChanged = dependencies.some(\n (dep, index) => dep !== prevDepsRef.current[index]\n );\n \n if (hasChanged && componentId) {\n invalidateComponent(componentId);\n }\n \n prevDepsRef.current = dependencies;\n }, [componentId, invalidateComponent, dependencies]);\n}\n\n"],"mappings":"AAAA,MAAO,CAAAA,KAAK,EAAIC,aAAa,CAAEC,UAAU,CAAEC,WAAW,CAAEC,MAAM,CAAEC,OAAO,KAAQ,OAAO,CAMtF,OAASC,mBAAmB,CAAEC,yBAAyB,KAAQ,yBAAyB,CAAC,OAAAC,GAAA,IAAAC,IAAA,yBA2BzF,GAAM,CAAAC,iBAAiB,cAAGT,aAAa,CAAgC,IAAI,CAAC,CAQ5E,MAAO,SAAS,CAAAU,kBAAkBA,CAAAC,IAAA,CAIN,IAH1B,CAAAC,QAAQ,CAAAD,IAAA,CAARC,QAAQ,CAAAC,iBAAA,CAAAF,IAAA,CACRG,YAAY,CAAZA,YAAY,CAAAD,iBAAA,UAAG,GAAG,CAAAA,iBAAA,CAAAE,gBAAA,CAAAJ,IAAA,CAClBK,WAAW,CAAXA,WAAW,CAAAD,gBAAA,UAAG,CAAC,CAAG,EAAE,CAAG,IAAI,CAAAA,gBAAA,CAE3B,GAAM,CAAAE,YAAY,CAAGd,MAAM,CAAC,KAAK,CAAC,CAElC,GAAI,CAACc,YAAY,CAACC,OAAO,CAAE,CACzBZ,yBAAyB,CAACQ,YAAY,CAAEE,WAAW,CAAC,CACpDC,YAAY,CAACC,OAAO,CAAG,IACzB,CAEA,GAAM,CAAAC,YAAY,CAAGhB,MAAM,CAACE,mBAAmB,CAAC,CAAC,CAAC,CAACa,OAAO,CAE1D,GAAM,CAAAE,cAAc,CAAGlB,WAAW,CAChC,SACEmB,WAAmB,CACnBC,eAAgC,CAChCC,KAAuB,CACI,CAC3B,M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MAAO,SAAS,CAAAmB,aAAaA,CAAA,CAA2B,CACtD,GAAM,CAAAC,OAAO,CAAG/B,UAAU,CAACQ,iBAAiB,CAAC,CAE7C,GAAI,CAACuB,OAAO,CAAE,CACZ,KAAM,IAAI,CAAAC,KAAK,CAAC,wDAAwD,CAC1E,CAEA,MAAO,CAAAD,OACT,CAEA,MAAO,SAAS,CAAAE,0BAA0BA,CACxCb,WAA+B,CAC/Bc,YAAuB,CACjB,CACN,IAAAC,cAAA,CAAgCL,aAAa,CAAC,CAAC,CAAvCL,mBAAmB,CAAAU,cAAA,CAAnBV,mBAAmB,CAC3B,GAAM,CAAAW,WAAW,CAAGlC,MAAM,CAAY,EAAE,CAAC,CAEzCJ,KAAK,CAACuC,SAAS,CAAC,UAAM,CACpB,GAAID,WAAW,CAACnB,OAAO,CAACqB,MAAM,GAAK,CAAC,CAAE,CACpCF,WAAW,CAACnB,OAAO,CAAGiB,YAAY,CAElC,MACF,CAEA,GAAM,CAAAK,UAAU,CAAGL,YAAY,CAACM,IAAI,CAClC,SAACC,GAAG,CAAEC,KAAK,QAAK,CAAAD,GAAG,GAAKL,WAAW,CAACnB,OAAO,CAACyB,KAAK,CAAC,CACpD,CAAC,CAED,GAAIH,UAAU,EAAInB,WAAW,CAAE,CAC7BK,mBAAmB,CAACL,WAAW,CACjC,CAEAgB,WAAW,CAACnB,OAAO,CAAGiB,YACxB,CAAC,CAAE,CAACd,WAAW,CAAEK,mBAAmB,CAAES,YAAY,CAAC,CACrD","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { QueryCacheEntry, InteractionType, InteractionState } from './query-cache-utils';
|
|
2
|
+
declare class QueryCacheManager {
|
|
3
|
+
private cache;
|
|
4
|
+
private totalEntries;
|
|
5
|
+
private maxCacheSize;
|
|
6
|
+
private maxCacheAge;
|
|
7
|
+
constructor(maxCacheSize?: number, maxCacheAge?: number);
|
|
8
|
+
getCachedQuery(componentId: string, interactionType: InteractionType, state: InteractionState): QueryCacheEntry | null;
|
|
9
|
+
setCachedQuery(componentId: string, interactionType: InteractionType, state: InteractionState, entry: QueryCacheEntry): void;
|
|
10
|
+
invalidateComponent(componentId: string): void;
|
|
11
|
+
invalidateAll(): void;
|
|
12
|
+
isCached(componentId: string, interactionType: InteractionType, state: InteractionState): boolean;
|
|
13
|
+
private cleanupCache;
|
|
14
|
+
private getTotalCacheSize;
|
|
15
|
+
getStats(): {
|
|
16
|
+
componentCount: number;
|
|
17
|
+
maxAge: number;
|
|
18
|
+
maxSize: number;
|
|
19
|
+
size: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare function getGlobalQueryCache(): QueryCacheManager;
|
|
23
|
+
export declare function resetGlobalQueryCache(): void;
|
|
24
|
+
export declare function configureGlobalQueryCache(maxCacheSize?: number, maxCacheAge?: number): void;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import _extends from"@babel/runtime/helpers/extends";function _createForOfIteratorHelperLoose(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}import{createInteractionKey}from"./query-cache-utils";var QueryCacheManager=/*#__PURE__*/function(){// 5 minutes
|
|
2
|
+
function QueryCacheManager(maxCacheSize,maxCacheAge){if(maxCacheSize===void 0){maxCacheSize=100}if(maxCacheAge===void 0){maxCacheAge=5*60*1000}this.cache=new Map;this.totalEntries=0;this.maxCacheSize=100;this.maxCacheAge=5*60*1000;this.maxCacheSize=maxCacheSize;this.maxCacheAge=maxCacheAge}var _proto=QueryCacheManager.prototype;_proto.getCachedQuery=function getCachedQuery(componentId,interactionType,state){var componentCache=this.cache.get(componentId);if(!componentCache){return null}var key=createInteractionKey(interactionType,state);var entry=componentCache.get(key);if(!entry){return null}var now=Date.now();if(now-entry.timestamp>this.maxCacheAge){componentCache["delete"](key);this.totalEntries-=1;if(componentCache.size===0){this.cache["delete"](componentId)}return null}return entry};_proto.setCachedQuery=function setCachedQuery(componentId,interactionType,state,entry){var componentCache=this.cache.get(componentId);if(!componentCache){componentCache=new Map;this.cache.set(componentId,componentCache)}var key=createInteractionKey(interactionType,state);var isNewEntry=!componentCache.has(key);componentCache.set(key,_extends({},entry,{timestamp:Date.now()}));if(isNewEntry){this.totalEntries+=1}if(this.totalEntries>this.maxCacheSize){this.cleanupCache()}};_proto.invalidateComponent=function invalidateComponent(componentId){var componentCache=this.cache.get(componentId);if(componentCache){this.totalEntries-=componentCache.size;this.cache["delete"](componentId)}};_proto.invalidateAll=function invalidateAll(){this.cache.clear();this.totalEntries=0};_proto.isCached=function isCached(componentId,interactionType,state){return this.getCachedQuery(componentId,interactionType,state)!==null};_proto.cleanupCache=function cleanupCache(){var now=Date.now();var allEntries=[];for(var _iterator=_createForOfIteratorHelperLoose(this.cache.entries()),_step;!(_step=_iterator()).done;){var _step$value=_step.value,_componentId=_step$value[0],_componentCache=_step$value[1];for(var _iterator3=_createForOfIteratorHelperLoose(_componentCache.entries()),_step3;!(_step3=_iterator3()).done;){var _step3$value=_step3.value,_key=_step3$value[0],entry=_step3$value[1];if(now-entry.timestamp>this.maxCacheAge){_componentCache["delete"](_key);this.totalEntries-=1}else{allEntries.push({componentId:_componentId,key:_key,timestamp:entry.timestamp})}}if(_componentCache.size===0){this.cache["delete"](_componentId)}}if(allEntries.length>this.maxCacheSize){allEntries.sort(function(a,b){return a.timestamp-b.timestamp});var entriesToRemove=allEntries.slice(0,allEntries.length-this.maxCacheSize);for(var _iterator2=_createForOfIteratorHelperLoose(entriesToRemove),_step2;!(_step2=_iterator2()).done;){var _step2$value=_step2.value,componentId=_step2$value.componentId,key=_step2$value.key;var componentCache=this.cache.get(componentId);if(componentCache){componentCache["delete"](key);this.totalEntries-=1;// Remove empty component caches
|
|
3
|
+
if(componentCache.size===0){this.cache["delete"](componentId)}}}}};_proto.getTotalCacheSize=function getTotalCacheSize(){return this.totalEntries};_proto.getStats=function getStats(){return{componentCount:this.cache.size,maxAge:this.maxCacheAge,maxSize:this.maxCacheSize,size:this.getTotalCacheSize()}};return QueryCacheManager}();var globalCacheInstance=null;export function getGlobalQueryCache(){if(!globalCacheInstance){globalCacheInstance=new QueryCacheManager}return globalCacheInstance}export function resetGlobalQueryCache(){globalCacheInstance=null}export function configureGlobalQueryCache(maxCacheSize,maxCacheAge){if(maxCacheSize===void 0){maxCacheSize=100}if(maxCacheAge===void 0){maxCacheAge=5*60*1000}globalCacheInstance=new QueryCacheManager(maxCacheSize,maxCacheAge)}
|
|
4
|
+
//# sourceMappingURL=query-cache-singleton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-cache-singleton.js","names":["createInteractionKey","QueryCacheManager","maxCacheSize","maxCacheAge","cache","Map","totalEntries","_proto","prototype","getCachedQuery","componentId","interactionType","state","componentCache","get","key","entry","now","Date","timestamp","size","setCachedQuery","set","isNewEntry","has","_extends","cleanupCache","invalidateComponent","invalidateAll","clear","isCached","allEntries","_iterator","_createForOfIteratorHelperLoose","entries","_step","done","_step$value","value","_iterator3","_step3","_step3$value","push","length","sort","a","b","entriesToRemove","slice","_iterator2","_step2","_step2$value","getTotalCacheSize","getStats","componentCount","maxAge","maxSize","globalCacheInstance","getGlobalQueryCache","resetGlobalQueryCache","configureGlobalQueryCache"],"sources":["../../../src/plugins/helpers/query-cache-singleton.ts"],"sourcesContent":["import {\n QueryCacheEntry,\n InteractionType,\n InteractionState,\n createInteractionKey\n} from './query-cache-utils';\n\nclass QueryCacheManager {\n private cache: Map<string, Map<string, QueryCacheEntry>> = new Map();\n private totalEntries = 0;\n private maxCacheSize = 100;\n private maxCacheAge: number = 5 * 60 * 1000; // 5 minutes\n\n constructor(maxCacheSize = 100, maxCacheAge = 5 * 60 * 1000) {\n this.maxCacheSize = maxCacheSize;\n this.maxCacheAge = maxCacheAge;\n }\n\n getCachedQuery(\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState\n ): QueryCacheEntry | null {\n const componentCache = this.cache.get(componentId);\n \n if (!componentCache) {\n return null;\n }\n \n const key = createInteractionKey(interactionType, state);\n const entry = componentCache.get(key);\n \n if (!entry) {\n return null;\n }\n \n const now = Date.now();\n\n if (now - entry.timestamp > this.maxCacheAge) {\n componentCache.delete(key);\n this.totalEntries -= 1;\n \n if (componentCache.size === 0) {\n this.cache.delete(componentId);\n }\n\n return null;\n }\n \n return entry;\n }\n\n setCachedQuery(\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState,\n entry: QueryCacheEntry\n ): void {\n let componentCache = this.cache.get(componentId);\n \n if (!componentCache) {\n componentCache = new Map();\n this.cache.set(componentId, componentCache);\n }\n \n const key = createInteractionKey(interactionType, state);\n const isNewEntry = !componentCache.has(key);\n\n componentCache.set(key, {\n ...entry,\n timestamp: Date.now(),\n });\n \n if (isNewEntry) {\n this.totalEntries += 1;\n }\n\n if (this.totalEntries > this.maxCacheSize) {\n this.cleanupCache();\n }\n }\n\n invalidateComponent(componentId: string): void {\n const componentCache = this.cache.get(componentId);\n\n if (componentCache) {\n this.totalEntries -= componentCache.size;\n this.cache.delete(componentId);\n }\n }\n\n invalidateAll(): void {\n this.cache.clear();\n this.totalEntries = 0;\n }\n\n isCached(\n componentId: string,\n interactionType: InteractionType,\n state: InteractionState\n ): boolean {\n return this.getCachedQuery(componentId, interactionType, state) !== null;\n }\n\n private cleanupCache(): void {\n const now = Date.now();\n const allEntries: Array<{ componentId: string; key: string; timestamp: number }> = [];\n \n for (const [componentId, componentCache] of this.cache.entries()) {\n for (const [key, entry] of componentCache.entries()) {\n if (now - entry.timestamp > this.maxCacheAge) {\n componentCache.delete(key);\n this.totalEntries -= 1;\n } else {\n allEntries.push({ componentId, key, timestamp: entry.timestamp });\n }\n }\n \n if (componentCache.size === 0) {\n this.cache.delete(componentId);\n }\n }\n \n if (allEntries.length > this.maxCacheSize) {\n allEntries.sort((a, b) => a.timestamp - b.timestamp);\n \n const entriesToRemove = allEntries.slice(0, allEntries.length - this.maxCacheSize);\n \n for (const { componentId, key } of entriesToRemove) {\n const componentCache = this.cache.get(componentId);\n\n if (componentCache) {\n componentCache.delete(key);\n this.totalEntries -= 1;\n \n // Remove empty component caches\n if (componentCache.size === 0) {\n this.cache.delete(componentId);\n }\n }\n }\n }\n }\n \n private getTotalCacheSize(): number {\n return this.totalEntries;\n }\n\n getStats(): { componentCount: number; maxAge: number; maxSize: number; size: number } {\n return {\n componentCount: this.cache.size,\n maxAge: this.maxCacheAge,\n maxSize: this.maxCacheSize,\n size: this.getTotalCacheSize(),\n };\n }\n}\n\nlet globalCacheInstance: QueryCacheManager | null = null;\n\nexport function getGlobalQueryCache(): QueryCacheManager {\n if (!globalCacheInstance) {\n globalCacheInstance = new QueryCacheManager();\n }\n\n return globalCacheInstance;\n}\n\nexport function resetGlobalQueryCache(): void {\n globalCacheInstance = null;\n}\n\nexport function configureGlobalQueryCache(maxCacheSize = 100, maxCacheAge = 5 * 60 * 1000): void {\n globalCacheInstance = new QueryCacheManager(maxCacheSize, maxCacheAge);\n}\n\n"],"mappings":"89BAAA,OAIEA,oBAAoB,KACf,qBAAqB,CAAC,GAEvB,CAAAC,iBAAiB,yBAIwB;AAE7C,SAAAA,kBAAYC,YAAY,CAAQC,WA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,MAAO,SAAS,CAAAC,mBAAmBA,CAAA,CAAsB,CACvD,GAAI,CAACD,mBAAmB,CAAE,CACxBA,mBAAmB,CAAG,GAAI,CAAAxD,iBAC5B,CAEA,MAAO,CAAAwD,mBACT,CAEA,MAAO,SAAS,CAAAE,qBAAqBA,CAAA,CAAS,CAC5CF,mBAAmB,CAAG,IACxB,CAEA,MAAO,SAAS,CAAAG,yBAAyBA,CAAC1D,YAAY,CAAQC,WAAW,CAAwB,IAAvDD,YAAY,WAAZA,YAAY,CAAG,GAAG,IAAEC,WAAW,WAAXA,WAAW,CAAG,CAAC,CAAG,EAAE,CAAG,IAAI,CACvFsD,mBAAmB,CAAG,GAAI,CAAAxD,iBAAiB,CAACC,YAAY,CAAEC,WAAW,CACvE","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type InteractionType = 'semanticLayerQuery' | 'tableButton';
|
|
2
|
+
export type InteractionState = {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
bodyContent?: unknown;
|
|
5
|
+
chartData?: unknown;
|
|
6
|
+
chartDataFingerprint?: string;
|
|
7
|
+
chartDataLength?: number;
|
|
8
|
+
dataFingerprint?: string;
|
|
9
|
+
dataLength?: number;
|
|
10
|
+
error?: unknown;
|
|
11
|
+
filterValue?: unknown;
|
|
12
|
+
filters?: Record<string, unknown>;
|
|
13
|
+
footerContent?: unknown;
|
|
14
|
+
headerContent?: unknown;
|
|
15
|
+
isMissing?: unknown;
|
|
16
|
+
pageNumber?: number;
|
|
17
|
+
pageSize?: number;
|
|
18
|
+
searchQuery?: string;
|
|
19
|
+
searchValue?: string;
|
|
20
|
+
sortColumn?: string | null;
|
|
21
|
+
sortDirection?: 'asc' | 'desc' | null;
|
|
22
|
+
summaryText?: unknown;
|
|
23
|
+
};
|
|
24
|
+
export type QueryCacheEntry = {
|
|
25
|
+
queryHeadings: string[];
|
|
26
|
+
sqlQuery: string | string[];
|
|
27
|
+
tableButtonExplanations: Array<{
|
|
28
|
+
action: string;
|
|
29
|
+
buttonClassName?: string;
|
|
30
|
+
buttonStyle?: Record<string, unknown>;
|
|
31
|
+
explanation: string;
|
|
32
|
+
formFields?: Record<string, unknown>;
|
|
33
|
+
jsonBody?: unknown;
|
|
34
|
+
operationDescription?: string;
|
|
35
|
+
operationSummary?: string;
|
|
36
|
+
requestUrl?: string;
|
|
37
|
+
}>;
|
|
38
|
+
timestamp: number;
|
|
39
|
+
};
|
|
40
|
+
export type CacheKey = {
|
|
41
|
+
componentId: string;
|
|
42
|
+
interactionType: InteractionType;
|
|
43
|
+
state: InteractionState;
|
|
44
|
+
};
|
|
45
|
+
export declare function createCacheKey(componentId: string, interactionType: InteractionType, interactionState: InteractionState): string;
|
|
46
|
+
export declare function createInteractionKey(interactionType: InteractionType, interactionState: InteractionState): string;
|
|
47
|
+
export declare function extractInteractionState(componentProps: Record<string, unknown>): InteractionState;
|
|
48
|
+
export declare function areStatesEqual(state1: InteractionState, state2: InteractionState): boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
function _createForOfIteratorHelperLoose(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}export function createCacheKey(componentId,interactionType,interactionState){var sortedState=sortObjectKeys(interactionState);try{var stateString=JSON.stringify(sortedState);return componentId+"::"+interactionType+"::"+stateString}catch(error){// eslint-disable-next-line no-console
|
|
2
|
+
console.warn("Failed to serialize interaction state:",error);return componentId+"::"+interactionType+"::"+Date.now()+"::"+Math.random()}}export function createInteractionKey(interactionType,interactionState){var sortedState=sortObjectKeys(interactionState);try{var stateString=JSON.stringify(sortedState);return interactionType+"::"+stateString}catch(error){// eslint-disable-next-line no-console
|
|
3
|
+
console.warn("Failed to serialize interaction state:",error);return interactionType+"::"+Date.now()+"::"+Math.random()}}function sortObjectKeys(obj){if(obj===null||obj===undefined){return obj}if(Array.isArray(obj)){return obj.map(function(item){return sortObjectKeys(item)})}if(typeof obj==="object"){var sorted={};var keys=Object.keys(obj).sort();for(var _iterator=_createForOfIteratorHelperLoose(keys),_step;!(_step=_iterator()).done;){var _key=_step.value;sorted[_key]=sortObjectKeys(obj[_key])}return sorted}return obj}export function extractInteractionState(componentProps){var state={};if("pagination"in componentProps&&typeof componentProps.pagination==="object"&&componentProps.pagination){var pagination=componentProps.pagination;if("pageNumber"in pagination&&typeof pagination.pageNumber==="number"){state.pageNumber=pagination.pageNumber}if("pageSize"in pagination&&typeof pagination.pageSize==="number"){state.pageSize=pagination.pageSize}}if("sortColumn"in componentProps){state.sortColumn=componentProps.sortColumn}if("sortDirection"in componentProps){state.sortDirection=componentProps.sortDirection}if("filters"in componentProps&&typeof componentProps.filters==="object"){state.filters=componentProps.filters}if("value"in componentProps){state.filterValue=componentProps.value}if("searchQuery"in componentProps&&typeof componentProps.searchQuery==="string"){state.searchQuery=componentProps.searchQuery}if("searchValue"in componentProps&&typeof componentProps.searchValue==="string"){state.searchValue=componentProps.searchValue}if("data"in componentProps){var data=componentProps.data;if(Array.isArray(data)&&data.length>0){state.dataLength=data.length;var firstRow=data[0];var lastRow=data[data.length-1];if(firstRow&&typeof firstRow==="object"){try{state.dataFingerprint=JSON.stringify({firstId:firstRow.id||Object.values(firstRow)[0],lastId:lastRow&&typeof lastRow==="object"?lastRow.id||Object.values(lastRow)[0]:null,length:data.length})}catch(error){// eslint-disable-next-line no-console
|
|
4
|
+
console.warn("Failed to serialize data fingerprint:",error);state.dataFingerprint="fallback_"+data.length+"_"+Date.now()}}}else if(data&&typeof data==="object"&&data.name==="__peak_placeholder"){state.dataFingerprint="__peak_placeholder"}else{state.dataFingerprint="empty"}}if("bodyContent"in componentProps){state.bodyContent=componentProps.bodyContent}if("headerContent"in componentProps){state.headerContent=componentProps.headerContent}if("footerContent"in componentProps){state.footerContent=componentProps.footerContent}if("chartData"in componentProps){var chartData=componentProps.chartData;if(Array.isArray(chartData)){state.chartDataLength=chartData.length;try{state.chartDataFingerprint=JSON.stringify(chartData)}catch(error){// eslint-disable-next-line no-console
|
|
5
|
+
console.warn("Failed to serialize chart data fingerprint:",error);state.chartDataFingerprint="fallback_"+chartData.length+"_"+Date.now()}}}if("summaryText"in componentProps){state.summaryText=componentProps.summaryText}if("error"in componentProps){state.error=componentProps.error}if("isMissing"in componentProps){state.isMissing=componentProps.isMissing}return state}export function areStatesEqual(state1,state2){return createCacheKey("test","semanticLayerQuery",state1)===createCacheKey("test","semanticLayerQuery",state2)}
|
|
6
|
+
//# sourceMappingURL=query-cache-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-cache-utils.js","names":["createCacheKey","componentId","interactionType","interactionState","sortedState","sortObjectKeys","stateString","JSON","stringify","error","console","warn","Date","now","Math","random","createInteractionKey","obj","undefined","Array","isArray","map","item","sorted","keys","Object","sort","_iterator","_createForOfIteratorHelperLoose","_step","done","key","value","extractInteractionState","componentProps","state","pagination","pageNumber","pageSize","sortColumn","sortDirection","filters","filterValue","searchQuery","searchValue","data","length","dataLength","firstRow","lastRow","dataFingerprint","firstId","id","values","lastId","name","bodyContent","headerContent","footerContent","chartData","chartDataLength","chartDataFingerprint","summaryText","isMissing","areStatesEqual","state1","state2"],"sources":["../../../src/plugins/helpers/query-cache-utils.ts"],"sourcesContent":["\nexport type InteractionType = 'semanticLayerQuery' | 'tableButton';\n\nexport type InteractionState = {\n [key: string]: unknown;\n bodyContent?: unknown;\n chartData?: unknown;\n chartDataFingerprint?: string;\n chartDataLength?: number;\n dataFingerprint?: string;\n dataLength?: number;\n error?: unknown;\n filterValue?: unknown;\n filters?: Record<string, unknown>;\n footerContent?: unknown;\n headerContent?: unknown;\n isMissing?: unknown;\n pageNumber?: number;\n pageSize?: number;\n searchQuery?: string;\n searchValue?: string;\n sortColumn?: string | null;\n sortDirection?: 'asc' | 'desc' | null;\n summaryText?: unknown;\n};\n\nexport type QueryCacheEntry = {\n queryHeadings: string[];\n sqlQuery: string | string[];\n tableButtonExplanations: Array<{\n action: string;\n buttonClassName?: string;\n buttonStyle?: Record<string, unknown>;\n explanation: string;\n formFields?: Record<string, unknown>;\n jsonBody?: unknown;\n operationDescription?: string;\n operationSummary?: string;\n requestUrl?: string;\n }>;\n timestamp: number;\n};\n\nexport type CacheKey = {\n componentId: string;\n interactionType: InteractionType;\n state: InteractionState;\n};\n\nexport function createCacheKey(\n componentId: string,\n interactionType: InteractionType,\n interactionState: InteractionState\n): string {\n const sortedState = sortObjectKeys(interactionState);\n \n try {\n const stateString = JSON.stringify(sortedState);\n \n return `${componentId}::${interactionType}::${stateString}`;\n } catch (error) {\n // eslint-disable-next-line no-console\n console.warn('Failed to serialize interaction state:', error);\n \n return `${componentId}::${interactionType}::${Date.now()}::${Math.random()}`;\n }\n}\n\nexport function createInteractionKey(\n interactionType: InteractionType,\n interactionState: InteractionState\n): string {\n const sortedState = sortObjectKeys(interactionState);\n \n try {\n const stateString = JSON.stringify(sortedState);\n \n return `${interactionType}::${stateString}`;\n } catch (error) {\n // eslint-disable-next-line no-console\n console.warn('Failed to serialize interaction state:', error);\n \n return `${interactionType}::${Date.now()}::${Math.random()}`;\n }\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || obj === undefined) {\n return obj;\n }\n \n if (Array.isArray(obj)) {\n return obj.map(item => sortObjectKeys(item));\n }\n \n if (typeof obj === 'object') {\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj as Record<string, unknown>).sort();\n \n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n \n return sorted;\n }\n \n return obj;\n}\n\nexport function extractInteractionState(componentProps: Record<string, unknown>): InteractionState {\n const state: InteractionState = {};\n \n if ('pagination' in componentProps && typeof componentProps.pagination === 'object' && componentProps.pagination) {\n const pagination = componentProps.pagination as Record<string, unknown>;\n\n if ('pageNumber' in pagination && typeof pagination.pageNumber === 'number') {\n state.pageNumber = pagination.pageNumber;\n }\n\n if ('pageSize' in pagination && typeof pagination.pageSize === 'number') {\n state.pageSize = pagination.pageSize;\n }\n }\n \n if ('sortColumn' in componentProps) {\n state.sortColumn = componentProps.sortColumn as string | null;\n }\n \n if ('sortDirection' in componentProps) {\n state.sortDirection = componentProps.sortDirection as 'asc' | 'desc' | null;\n }\n \n if ('filters' in componentProps && typeof componentProps.filters === 'object') {\n state.filters = componentProps.filters as Record<string, unknown>;\n }\n \n if ('value' in componentProps) {\n state.filterValue = componentProps.value as unknown;\n }\n \n if ('searchQuery' in componentProps && typeof componentProps.searchQuery === 'string') {\n state.searchQuery = componentProps.searchQuery;\n }\n \n if ('searchValue' in componentProps && typeof componentProps.searchValue === 'string') {\n state.searchValue = componentProps.searchValue;\n }\n\n if ('data' in componentProps) {\n const data = componentProps.data;\n \n if (Array.isArray(data) && data.length > 0) {\n state.dataLength = data.length;\n const firstRow = data[0];\n const lastRow = data[data.length - 1];\n \n if (firstRow && typeof firstRow === 'object') {\n try {\n state.dataFingerprint = JSON.stringify({\n firstId: (firstRow as Record<string, unknown>).id || Object.values(firstRow)[0],\n lastId: lastRow && typeof lastRow === 'object' \n ? ((lastRow as Record<string, unknown>).id || Object.values(lastRow)[0])\n : null,\n length: data.length\n });\n } catch (error) {\n // eslint-disable-next-line no-console\n console.warn('Failed to serialize data fingerprint:', error);\n state.dataFingerprint = `fallback_${data.length}_${Date.now()}`;\n }\n }\n } else if (data && typeof data === 'object' && (data as Record<string, unknown>).name === '__peak_placeholder') {\n state.dataFingerprint = '__peak_placeholder';\n } else {\n state.dataFingerprint = 'empty';\n }\n }\n \n if ('bodyContent' in componentProps) {\n state.bodyContent = componentProps.bodyContent as unknown;\n }\n \n if ('headerContent' in componentProps) {\n state.headerContent = componentProps.headerContent as unknown;\n }\n \n if ('footerContent' in componentProps) {\n state.footerContent = componentProps.footerContent as unknown;\n }\n \n if ('chartData' in componentProps) {\n const chartData = componentProps.chartData;\n\n if (Array.isArray(chartData)) {\n state.chartDataLength = chartData.length;\n\n try {\n state.chartDataFingerprint = JSON.stringify(chartData);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.warn('Failed to serialize chart data fingerprint:', error);\n state.chartDataFingerprint = `fallback_${chartData.length}_${Date.now()}`;\n }\n }\n }\n \n if ('summaryText' in componentProps) {\n state.summaryText = componentProps.summaryText as unknown;\n }\n \n if ('error' in componentProps) {\n state.error = componentProps.error as unknown;\n }\n \n if ('isMissing' in componentProps) {\n state.isMissing = componentProps.isMissing as unknown;\n }\n \n return state;\n}\n\nexport function areStatesEqual(state1: InteractionState, state2: InteractionState): boolean {\n return createCacheKey('test', 'semanticLayerQuery', state1) === \n createCacheKey('test', 'semanticLayerQuery', state2);\n}\n\n"],"mappings":"y6BAiDA,MAAO,SAAS,CAAAA,cAAcA,CAC5BC,WAAmB,CACnBC,eAAgC,CAChCC,gBAAkC,CAC1B,CACR,GAAM,CAAAC,WAAW,CAAGC,cAAc,CAACF,gBAAgB,CAAC,CAEpD,GAAI,CACF,GAAM,CAAAG,WAAW,CAAGC,IAAI,CAACC,SAAS,CAACJ,WAAW,CAAC,CAE/C,MAAU,CAAAH,WAAW,MAAKC,eAAe,MAAKI,WAChD,CAAE,MAAOG,KAAK,CAAE,CACd;AACAC,OAAO,CAACC,IAAI,CAA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AyB,cAAc,CAAE,CACjCC,KAAK,CAAC4B,SAAS,CAAG7B,cAAc,CAAC6B,SACnC,CAEA,MAAO,CAAA5B,KACT,CAEA,MAAO,SAAS,CAAA6B,cAAcA,CAACC,MAAwB,CAAEC,MAAwB,CAAW,CAC1F,MAAO,CAAAlE,cAAc,CAAC,MAAM,CAAE,oBAAoB,CAAEiE,MAAM,CAAC,GACpDjE,cAAc,CAAC,MAAM,CAAE,oBAAoB,CAAEkE,MAAM,CAC5D","ignoreList":[]}
|
|
@@ -4,14 +4,19 @@ type QueryDetailsModalProps = {
|
|
|
4
4
|
isLoading: boolean;
|
|
5
5
|
error: string;
|
|
6
6
|
sqlQuery: string | string[];
|
|
7
|
+
queryHeadings?: string[];
|
|
7
8
|
tableButtonExplanations?: Array<{
|
|
8
9
|
action: string;
|
|
9
10
|
explanation: string;
|
|
10
|
-
|
|
11
|
+
operationSummary?: string;
|
|
12
|
+
operationDescription?: string;
|
|
11
13
|
buttonClassName?: string;
|
|
12
14
|
buttonStyle?: Record<string, unknown>;
|
|
15
|
+
formFields?: Record<string, unknown>;
|
|
16
|
+
jsonBody?: unknown;
|
|
17
|
+
requestUrl?: string;
|
|
13
18
|
}>;
|
|
14
19
|
onRetry: () => void;
|
|
15
20
|
};
|
|
16
|
-
export declare function QueryDetailsModal({ isOpen, onClose, isLoading, error, sqlQuery, tableButtonExplanations, onRetry }: QueryDetailsModalProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function QueryDetailsModal({ isOpen, onClose, isLoading, error, sqlQuery, queryHeadings, tableButtonExplanations, onRetry }: QueryDetailsModalProps): import("react/jsx-runtime").JSX.Element;
|
|
17
22
|
export default QueryDetailsModal;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _extends from"@babel/runtime/helpers/extends";import _asyncToGenerator from"@babel/runtime/helpers/asyncToGenerator";import _regeneratorRuntime from"@babel/runtime/regenerator";import React,{useState,useEffect}from"react";import{CustomModal}from"./custom-modal";import{Copy,Check,ChevronDown}from"lucide-react";import{jsx as _jsx,
|
|
2
|
-
useEffect(function(){if(!isOpen){setExpandedButtons({})}},[isOpen]);function copyToClipboard(_x,_x2){return _copyToClipboard.apply(this,arguments)}function _copyToClipboard(){_copyToClipboard=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(queryToCopy,copyId){var textToCopy,id;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:textToCopy=queryToCopy;if(!textToCopy){if(Array.isArray(sqlQuery)){textToCopy=sqlQuery.filter(function(q){return q&&typeof q==="string"}).join("\n\n-- Next Query --\n\n")}else if(typeof sqlQuery==="string"){textToCopy=sqlQuery}else{textToCopy=""}}if(textToCopy){_context.next=4;break}return _context.abrupt("return");case 4:id=copyId||"main";_context.prev=5;_context.next=8;return navigator.clipboard.writeText(textToCopy);case 8:setCopied(function(prev){var _extends3;return _extends({},prev,(_extends3={},_extends3[id]=true,_extends3))});setTimeout(function(){return setCopied(function(prev){var _extends4;return _extends({},prev,(_extends4={},_extends4[id]=false,_extends4))})},2000);_context.next=14;break;case 12:_context.prev=12;_context.t0=_context["catch"](5);case 14:case"end":return _context.stop()}},_callee,null,[[5,12]])}));return _copyToClipboard.apply(this,arguments)}function toggleButtonExpansion(buttonIndex){setExpandedButtons(function(prev){var _extends2;return _extends({},prev,(_extends2={},_extends2[buttonIndex]=!prev[buttonIndex],_extends2))})}function renderTableButtonExplanations(){if(!tableButtonExplanations||tableButtonExplanations.length===0){return null}return/*#__PURE__*/_jsx("div",{className:"mb-6",children:tableButtonExplanations.map(function(button,index){var _button$buttonStyle,_button$buttonStyle2,_button$buttonStyle3;return/*#__PURE__*/_jsxs("div",{className:"mb-3 border border-gray-200 rounded-lg",children:[/*#__PURE__*/_jsxs("div",{className:"w-full px-4 py-3 flex items-center justify-between rounded-lg",children:[/*#__PURE__*/
|
|
3
|
-
if(Array.isArray(sqlQuery)){return/*#__PURE__*/_jsxs("div",{className:"p-6 space-y-4",children:[sqlQuery.filter(function(query){return query&&typeof query==="string"&&query.trim()}).map(function(query,index){
|
|
1
|
+
import _extends from"@babel/runtime/helpers/extends";import _asyncToGenerator from"@babel/runtime/helpers/asyncToGenerator";import _regeneratorRuntime from"@babel/runtime/regenerator";import React,{useState,useEffect}from"react";import{CustomModal}from"./custom-modal";import{Copy,Check,ChevronDown,ChevronUp}from"lucide-react";import{formatQueryHeading}from"./query-heading-formatter";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";function CopyButton(_ref){var onClick=_ref.onClick,isCopied=_ref.isCopied,_ref$variant=_ref.variant,variant=_ref$variant===void 0?"default":_ref$variant;var baseClasses="flex items-center gap-1 px-2 py-1 text-xs border rounded transition-colors";var variantClasses=variant==="light"?"bg-gray-50 border-gray-300 hover:bg-gray-100":"bg-gray-100 border-gray-300 hover:bg-gray-200";return/*#__PURE__*/_jsx("button",{onClick:onClick,className:baseClasses+" "+variantClasses,type:"button",children:isCopied?/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(Check,{className:"w-3 h-3 text-green-600"}),/*#__PURE__*/_jsx("span",{className:"text-green-600",children:"Copied!"})]}):/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(Copy,{className:"w-3 h-3 text-gray-600"}),/*#__PURE__*/_jsx("span",{className:"text-gray-600",children:"Copy"})]})})}function ContentText(_ref2){var children=_ref2.children,_ref2$hasOverflowHand=_ref2.hasOverflowHandling,hasOverflowHandling=_ref2$hasOverflowHand===void 0?true:_ref2$hasOverflowHand;var overflowClasses=hasOverflowHandling?"overflow-hidden break-words":"";return/*#__PURE__*/_jsx("pre",{className:"whitespace-pre-wrap leading-relaxed text-xs text-gray-700 m-0 p-0 "+overflowClasses,children:children})}function ContentBlock(_ref3){var title=_ref3.title,children=_ref3.children,copyContent=_ref3.copyContent,copyId=_ref3.copyId,copied=_ref3.copied,onCopy=_ref3.onCopy,_ref3$variant=_ref3.variant,variant=_ref3$variant===void 0?"bordered":_ref3$variant,_ref3$copyButtonVaria=_ref3.copyButtonVariant,copyButtonVariant=_ref3$copyButtonVaria===void 0?"default":_ref3$copyButtonVaria;var containerClasses=variant==="bordered"?"rounded-lg p-3":"bg-white border border-gray-200 rounded-lg p-4";var containerStyle=variant==="bordered"?{border:"1px solid #E9EAF5"}:{};var titleClasses=variant==="bordered"?"text-sm font-medium text-gray-600":"font-semibold text-sm text-gray-500 m-0";return/*#__PURE__*/_jsxs("div",{className:containerClasses,style:containerStyle,children:[/*#__PURE__*/_jsxs("div",{className:"flex justify-between items-start mb-2",children:[/*#__PURE__*/_jsx("span",{className:titleClasses,children:title}),copyContent&&/*#__PURE__*/_jsx(CopyButton,{onClick:function onClick(){return onCopy(copyContent,copyId)},isCopied:copied[copyId]||false,variant:copyButtonVariant})]}),children]})}export function QueryDetailsModal(_ref4){var isOpen=_ref4.isOpen,onClose=_ref4.onClose,isLoading=_ref4.isLoading,error=_ref4.error,sqlQuery=_ref4.sqlQuery,_ref4$queryHeadings=_ref4.queryHeadings,queryHeadings=_ref4$queryHeadings===void 0?[]:_ref4$queryHeadings,_ref4$tableButtonExpl=_ref4.tableButtonExplanations,tableButtonExplanations=_ref4$tableButtonExpl===void 0?[]:_ref4$tableButtonExpl,onRetry=_ref4.onRetry;var _useState=useState({}),copied=_useState[0],setCopied=_useState[1];var _useState2=useState({}),expandedButtons=_useState2[0],setExpandedButtons=_useState2[1];// Reset expanded state when modal closes
|
|
2
|
+
useEffect(function(){if(!isOpen){setExpandedButtons({})}},[isOpen]);function copyToClipboard(_x,_x2){return _copyToClipboard.apply(this,arguments)}function _copyToClipboard(){_copyToClipboard=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(queryToCopy,copyId){var textToCopy,id;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:textToCopy=queryToCopy;if(!textToCopy){if(Array.isArray(sqlQuery)){textToCopy=sqlQuery.filter(function(q){return q&&typeof q==="string"}).join("\n\n-- Next Query --\n\n")}else if(typeof sqlQuery==="string"){textToCopy=sqlQuery}else{textToCopy=""}}if(textToCopy){_context.next=4;break}return _context.abrupt("return");case 4:id=copyId||"main";_context.prev=5;_context.next=8;return navigator.clipboard.writeText(textToCopy);case 8:setCopied(function(prev){var _extends3;return _extends({},prev,(_extends3={},_extends3[id]=true,_extends3))});setTimeout(function(){return setCopied(function(prev){var _extends4;return _extends({},prev,(_extends4={},_extends4[id]=false,_extends4))})},2000);_context.next=14;break;case 12:_context.prev=12;_context.t0=_context["catch"](5);case 14:case"end":return _context.stop()}},_callee,null,[[5,12]])}));return _copyToClipboard.apply(this,arguments)}function toggleButtonExpansion(buttonIndex){setExpandedButtons(function(prev){var _extends2;return _extends({},prev,(_extends2={},_extends2[buttonIndex]=!prev[buttonIndex],_extends2))})}function renderTableButtonExplanations(){if(!tableButtonExplanations||tableButtonExplanations.length===0){return null}function hasValidJsonBody(jsonBody){return jsonBody!==null&&jsonBody!==undefined&&jsonBody!==""}function hasValidFormFields(formFields){return formFields!==null&&formFields!==undefined&&Object.keys(formFields||{}).length>0}return/*#__PURE__*/_jsx("div",{className:"mb-6",children:tableButtonExplanations.map(function(button,index){var _button$buttonStyle,_button$buttonStyle2,_button$buttonStyle3;return/*#__PURE__*/_jsxs("div",{className:"mb-3 border border-gray-200 rounded-lg",children:[/*#__PURE__*/_jsxs("div",{className:"w-full px-4 py-3 flex items-center justify-between rounded-lg",children:[/*#__PURE__*/_jsxs("div",{className:"flex items-center",children:[/*#__PURE__*/_jsx("button",{onClick:function onClick(){return toggleButtonExpansion(index)},className:button.buttonClassName||"flex items-center justify-center px-3 rounded text-xs font-medium",style:_extends({height:"35px",width:"fit-content",minWidth:"fit-content",backgroundColor:(_button$buttonStyle=button.buttonStyle)==null?void 0:_button$buttonStyle.backgroundColor,color:(_button$buttonStyle2=button.buttonStyle)==null?void 0:_button$buttonStyle2.color,border:(_button$buttonStyle3=button.buttonStyle)==null?void 0:_button$buttonStyle3.border},button.buttonStyle||{},button.buttonStyle||{},{display:"flex",alignItems:"center",justifyContent:"center"}),children:button.action}),/*#__PURE__*/_jsx("div",{className:"ml-3 flex flex-col",children:button.operationSummary&&/*#__PURE__*/_jsx("span",{className:"text-xs text-gray-700 font-medium",children:button.operationSummary})})]}),expandedButtons[index]?/*#__PURE__*/_jsx(ChevronUp,{className:"w-4 h-4 text-gray-500 transition-transform cursor-pointer",onClick:function onClick(){return toggleButtonExpansion(index)}}):/*#__PURE__*/_jsx(ChevronDown,{className:"w-4 h-4 text-gray-500 transition-transform cursor-pointer",onClick:function onClick(){return toggleButtonExpansion(index)}})]}),expandedButtons[index]&&/*#__PURE__*/_jsx("div",{className:"px-4 pb-3 border-t border-gray-200",children:/*#__PURE__*/_jsxs("div",{className:"mt-2 space-y-3",children:[button.operationDescription&&/*#__PURE__*/_jsx(ContentBlock,{title:"Description",copyId:"description-"+index,copied:copied,onCopy:copyToClipboard,variant:"bordered",children:/*#__PURE__*/_jsx(ContentText,{children:button.operationDescription})}),(button.requestUrl||button.explanation)&&/*#__PURE__*/_jsx(ContentBlock,{title:"URL",copyContent:button.requestUrl||button.explanation,copyId:"url-"+index,copied:copied,onCopy:copyToClipboard,variant:"bordered",children:/*#__PURE__*/_jsx(ContentText,{children:button.requestUrl||button.explanation})}),(hasValidJsonBody(button.jsonBody)||hasValidFormFields(button.formFields))&&/*#__PURE__*/_jsx(ContentBlock,{title:"Payload",copyContent:JSON.stringify(hasValidJsonBody(button.jsonBody)?button.jsonBody:button.formFields,null,2),copyId:"payload-"+index,copied:copied,onCopy:copyToClipboard,variant:"bordered",children:/*#__PURE__*/_jsx(ContentText,{children:hasValidJsonBody(button.jsonBody)?JSON.stringify(button.jsonBody,null,2):JSON.stringify(button.formFields,null,2)})})]})})]},index)})})}function renderModalContent(){if(isLoading){return/*#__PURE__*/_jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[/*#__PURE__*/_jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-purple-600 mb-4"}),/*#__PURE__*/_jsx("span",{className:"text-xs text-gray-600",children:"Fetching query details from semantic layer..."}),/*#__PURE__*/_jsx("span",{className:"text-xs text-gray-400 mt-2",children:"This may take a few moments"})]})}if(error){return/*#__PURE__*/_jsxs("div",{className:"text-red-600 p-4 bg-red-50 rounded-lg border border-red-200 m-6",children:[/*#__PURE__*/_jsx("p",{className:"font-medium mb-2 text-xs",children:"Unable to fetch query details"}),/*#__PURE__*/_jsx("p",{className:"text-xs mb-3",children:error}),/*#__PURE__*/_jsx("button",{onClick:onRetry,className:"px-4 py-2 bg-red-100 hover:bg-red-200 rounded text-xs font-medium transition-colors",type:"button",children:"Retry"})]})}if(!sqlQuery||Array.isArray(sqlQuery)&&sqlQuery.length===0){return/*#__PURE__*/_jsx("div",{className:"text-gray-600 p-6",children:/*#__PURE__*/_jsx("p",{className:"text-xs",children:"No query details available"})})}// Handle multiple queries
|
|
3
|
+
if(Array.isArray(sqlQuery)){return/*#__PURE__*/_jsxs("div",{className:"p-6 space-y-4",children:[sqlQuery.filter(function(query){return query&&typeof query==="string"&&query.trim()}).map(function(query,index){var rawHeading=queryHeadings[index]||"Query "+(index+1);var heading=formatQueryHeading(rawHeading);return/*#__PURE__*/_jsx(ContentBlock,{title:heading,copyContent:query,copyId:"query-"+index,copied:copied,onCopy:copyToClipboard,variant:"default",copyButtonVariant:"light",children:/*#__PURE__*/_jsx(ContentText,{hasOverflowHandling:false,children:query})},index)}),renderTableButtonExplanations()]})}return/*#__PURE__*/_jsxs("div",{className:"p-6 space-y-4",children:[/*#__PURE__*/_jsx(ContentBlock,{title:formatQueryHeading(queryHeadings[0]||"Query details"),copyContent:typeof sqlQuery==="string"?sqlQuery:"",copyId:"single",copied:copied,onCopy:copyToClipboard,variant:"default",copyButtonVariant:"light",children:/*#__PURE__*/_jsx(ContentText,{hasOverflowHandling:false,children:sqlQuery})}),renderTableButtonExplanations()]})}return/*#__PURE__*/_jsx(CustomModal,{isOpen:isOpen,onClose:onClose,title:"How was this metric calculated?",children:renderModalContent()})}export default QueryDetailsModal;
|
|
4
4
|
//# sourceMappingURL=query-details-modal.js.map
|