react-semaphor 0.1.287 → 0.1.289

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/chunks/{dashboard-controls-B8xnCPTZ.js → dashboard-controls-BZpyFg-k.js} +4 -4
  2. package/dist/chunks/{dashboard-controls-C25JMBLV.js → dashboard-controls-Dsh15H8E.js} +1 -1
  3. package/dist/chunks/{dashboard-filter-controls-button-D-o6ofi2.js → dashboard-filter-controls-button-CG5DgZpQ.js} +3 -3
  4. package/dist/chunks/{dashboard-filter-controls-button-BOJUiKGk.js → dashboard-filter-controls-button-DJvp8skg.js} +1 -1
  5. package/dist/chunks/{dashboard-json-DFuRB4cG.js → dashboard-json-CPhdiaLF.js} +1 -1
  6. package/dist/chunks/{dashboard-json-BYCWtm_z.js → dashboard-json-cootX4Nq.js} +1 -1
  7. package/dist/chunks/{dashboard-summary-settings-dialog-CsnHeIhi.js → dashboard-summary-settings-dialog-DOaMWikr.js} +1 -1
  8. package/dist/chunks/{dashboard-summary-settings-dialog-CFTJNcmp.js → dashboard-summary-settings-dialog-F6Dl15za.js} +1 -1
  9. package/dist/chunks/{edit-dashboard-visual-YmESbDUP.js → edit-dashboard-visual-DIpn7oJy.js} +4354 -4315
  10. package/dist/chunks/edit-dashboard-visual-fAiZdiCV.js +188 -0
  11. package/dist/chunks/{index-Bz0-3JKw.js → index-Cab2h5Fi.js} +1917 -1915
  12. package/dist/chunks/{index-BDE8cMG8.js → index-CnmC-NR5.js} +38 -38
  13. package/dist/chunks/{resource-management-panel-Lxjcn4i0.js → resource-management-panel-AZ46U35q.js} +2 -2
  14. package/dist/chunks/{resource-management-panel-C6qnO0ID.js → resource-management-panel-gJirpIDQ.js} +1 -1
  15. package/dist/chunks/{use-create-flow-overlay-state-AXNDXDqV.js → use-create-flow-overlay-state-3oPHFeIs.js} +1 -1
  16. package/dist/chunks/{use-create-flow-overlay-state-CJiyn4FY.js → use-create-flow-overlay-state-B6yjr4UZ.js} +2 -2
  17. package/dist/chunks/use-visual-utils-CyzOMb7j.js +334 -0
  18. package/dist/chunks/use-visual-utils-DmENJikx.js +1 -0
  19. package/dist/dashboard/index.cjs +1 -1
  20. package/dist/dashboard/index.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +5 -5
  23. package/dist/surfboard/index.cjs +1 -1
  24. package/dist/surfboard/index.js +2 -2
  25. package/dist/types/main.d.ts +5 -0
  26. package/dist/types/types.d.ts +5 -0
  27. package/package.json +1 -1
  28. package/dist/chunks/edit-dashboard-visual-DU3NzdD5.js +0 -193
  29. package/dist/chunks/use-visual-utils-BygqTxyR.js +0 -1
  30. package/dist/chunks/use-visual-utils-CWVz-eYg.js +0 -353
@@ -1 +0,0 @@
1
- "use strict";const i=require("./index-BDE8cMG8.js"),g=require("react");function G(e){const n=e.toUpperCase().indexOf("WHERE"),r=e.toUpperCase().indexOf("GROUP BY"),s=e.toUpperCase().indexOf("LIMIT"),t=e.toUpperCase().indexOf("ORDER BY");let o=e.length;if(t!==-1&&(o=t),s!==-1&&s<o&&(o=s),n!==-1){const c=e.substring(0,n),a=e.substring(n);return`${c} {{ filters | where }} AND ${a.substring(6)}`}else if(r!==-1){const c=e.substring(0,r),a=e.substring(r);return`${c} {{ filters | where }} ${a}`}else{const c=e.substring(0,o),a=e.substring(o);return console.log("beforeClause",c),console.log("afterClause",a),a?`${c} {{ filters | where }} ${a}`:`${c.replace(/;$/,"")} {{ filters | where }}`}}function Y(e){const[n,r]=g.useState(null),[s,t]=g.useState(null),o=i.useEnsureReactGlobals();return g.useEffect(()=>{if(!e||e.trim()===""){r(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const d=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(d,{method:"HEAD"})).ok)throw new Error(`Module not found at ${d}`)}catch{}const f=await import(d);if(typeof f.useChartStore!="function")throw new Error("useChartStore is not a function");r(()=>f.useChartStore),t(null)}catch(a){const d=a instanceof Error?a.message:"Unknown error";console.error("Failed to load remote chart store:",d),t(d),r(null)}})()},[e,o]),n}function J(e,n){if(e.length===0)return"";const r=e.find(s=>{var t,o;return((t=s.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=s.customCardPreferences)!=null&&o.dataInputCardIds)});if(r)return r.id;if(n){const s=e.find(t=>t.id===n);if(s){const t=s.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const c=t.split("__")[0],a=e.find(d=>d.tabTitle===c);return a?a.id:e[0].id}return n}}return e[0].id}const $=new Set;function K(e){return $.add(e),()=>{$.delete(e)}}function _(){$.forEach(e=>{e()})}const X=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:n,...r}=e;return r};async function j(e,n,r,s){if(!n||!r)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",r],o=s.getQueryData(t);if(o)return console.log("Using cached visual data for:",r),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",r);const c=i.ue.loading("Loading visual...",{position:"top-center"});try{const a=await fetch(`${e}/management/v1/visuals/${r}`,{headers:{Authorization:`Bearer ${n}`}});if(!a.ok)throw new Error("Failed to load visual");const d=await a.json();return s.setQueryData(t,d),i.ue.dismiss(c),{data:d,fromCache:!1}}catch(a){throw i.ue.dismiss(c),a}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function Z(e,n){var o,c;const r=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!r)return!1;const s=H(r);if(!(s!=null&&s.cards)||s.cards.length===0)return!1;const t=(c=s.cards)==null?void 0:c.find(a=>a.id===s.activeCardId);return t?(i.setupEditorWithCard({...n,frame:s,card:t,visualId:(e==null?void 0:e.id)||s.visualId}),!0):!1}function q(){const{setCardSql:e}=i.useEditorActions(),n=i.useEditorStore(t=>{var o;return((o=t.card.customCardPreferences)==null?void 0:o.url)||""}),r=Y(n);return{getUpdatedFrame:g.useCallback(()=>{var C;_();const{frame:t,card:o,isDevMode:c,isShowingVisual:a,selectedSchemaName:d,selectedDatamodelId:f,selectedDatabaseName:h,selectedTableName:F,selectedConnectionId:U}=i.useEditorStore.getState(),p=o.sql;let m=p;p&&!p.includes("{{")&&(m=G(p),e(m));const v=(C=r==null?void 0:r.getState())==null?void 0:C.settings,V=i.buildSavedEditorCard(o,{isDevMode:c,cardSql:m,isShowingVisual:a,selectedSchemaName:d,selectedDatamodelId:f,selectedDatabaseName:h,selectedTableName:F,selectedConnectionId:U,remoteChartSettings:v,stripConfig:X}),S=t.cards.map(E=>E.id===o.id?V:E);return{...t,cards:S,activeCardId:J(S,t.activeCardId)}},[r,e])}}function ee(){const{authToken:e,tokenProps:n}=i.useSemaphorContext(),r=i.useQueryClient(),s=i.useSelectedVisual(),{selectVisual:t}=i.useManagementActions(),{setFrame:o,setCard:c,setIsDevMode:a,initializeModeDrafts:d,setActiveTabCardId:f,updateDataSource:h,setQueryResultColumns:F,setSelectedConnectionId:U,setSelectedDatabaseName:p,setSelectedSchemaName:m,setSelectedTableName:v,setSelectedDatamodelId:V,setFilterValues:S,setInlineFilterValuesMap:C,setApplyFilters:E}=i.useEditorActions(),{setIsDashboardEditing:D,setIsVisualEditing:A,setSelectedFrameId:M,clearSelectedFrameId:P,addFrame:O,setIsDashboardPanelOpen:R}=i.useDashboardActions(),w=i.useDashboardStore(l=>l.selectedSheetId),x=i.useDashboardStore(l=>l.selectedFrameId),B=i.useDashboardStore(l=>l.dashboard),W=i.useDashboardStore(l=>l.filterValues),k=i.useDashboardStore(l=>l.inlineFilterValuesMap),y=i.useVisualById((s==null?void 0:s.id)||"",{enabled:!!(s!=null&&s.id)&&!!(e!=null&&e.accessToken)}),Q=g.useCallback(async l=>{try{t(l),P();const{data:b,fromCache:u}=await j(n.apiServiceUrl,(e==null?void 0:e.accessToken)||"",l.id,r);if(!Z(b,{setFrame:o,setCard:c,setIsDevMode:a,initializeModeDrafts:d,setActiveTabCardId:f,updateDataSource:h,setQueryResultColumns:F,setSelectedConnectionId:U,setSelectedDatabaseName:p,setSelectedSchemaName:m,setSelectedTableName:v,setSelectedDatamodelId:V,setFilterValues:S,setInlineFilterValuesMap:C,setApplyFilters:E,setIsDashboardEditing:D,setIsVisualEditing:A,dashboard:B,selectedSheetId:w,selectedFrameId:x,filterValues:W,inlineFilterValuesMap:k}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:u}}catch(b){return console.error("Error editing visual:",b),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,n.apiServiceUrl,r,t,o,c,D,A,a,d,f,h,F,U,p,m,v,V,S,C,E,P,B,w,x,W,k]),z=g.useCallback(async l=>{var b;try{if(t(l),!w)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:u,fromCache:L}=await j(n.apiServiceUrl,(e==null?void 0:e.accessToken)||"",l.id,r),T=(u==null?void 0:u.frameObject)??((b=u==null?void 0:u.visual)==null?void 0:b.frameObject);if(!T)return{success:!1,error:"Visual has no frame data"};const I=H(T);if(!(I!=null&&I.cards)||I.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const N={...i.cloneLinkedFrameWithSourceMapping(I),visualId:l.id};return O(w,N,"end"),D(!0),M(N.id),R(!1),{success:!0,fromCache:L}}catch(u){return console.error("Error adding visual:",u),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,n.apiServiceUrl,r,t,w,O,D,M,R]);return{visual:y.data,isLoading:y.isLoading,isError:y.isError,error:y.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:z,getUpdatedFrame:q().getUpdatedFrame,refetch:y.refetch}}exports.flushPendingEditorDrafts=_;exports.registerPendingEditorDraftFlusher=K;exports.useVisualUtils=ee;
@@ -1,353 +0,0 @@
1
- import { G as Y, b as X, H as Z, J as q, K as ee, M as G, N as te, u as y, O as re, Q as se, x as $, T as oe, U as H, V as ae } from "./index-Bz0-3JKw.js";
2
- import { useState as Q, useEffect as ne, useCallback as M } from "react";
3
- function ie(e) {
4
- const n = e.toUpperCase().indexOf("WHERE"), r = e.toUpperCase().indexOf("GROUP BY"), s = e.toUpperCase().indexOf("LIMIT"), t = e.toUpperCase().indexOf("ORDER BY");
5
- let o = e.length;
6
- if (t !== -1 && (o = t), s !== -1 && s < o && (o = s), n !== -1) {
7
- const i = e.substring(0, n), a = e.substring(n);
8
- return `${i} {{ filters | where }} AND ${a.substring(
9
- 6
10
- )}`;
11
- } else if (r !== -1) {
12
- const i = e.substring(0, r), a = e.substring(r);
13
- return `${i} {{ filters | where }} ${a}`;
14
- } else {
15
- const i = e.substring(0, o), a = e.substring(o);
16
- return console.log("beforeClause", i), console.log("afterClause", a), a ? `${i} {{ filters | where }} ${a}` : `${i.replace(/;$/, "")} {{ filters | where }}`;
17
- }
18
- }
19
- function ce(e) {
20
- const [n, r] = Q(null), [s, t] = Q(null), o = Y();
21
- return ne(() => {
22
- if (!e || e.trim() === "") {
23
- r(null), t(null);
24
- return;
25
- }
26
- if (!o)
27
- return;
28
- (async () => {
29
- try {
30
- if (!e.startsWith("http://") && !e.startsWith("https://"))
31
- throw new Error(`Invalid URL format: ${e}`);
32
- try {
33
- new URL(e);
34
- } catch {
35
- throw new Error(`Invalid URL: ${e}`);
36
- }
37
- const c = `${e.endsWith("/") ? e : `${e}/`}index.js`;
38
- try {
39
- if (!(await fetch(c, { method: "HEAD" })).ok)
40
- throw new Error(`Module not found at ${c}`);
41
- } catch {
42
- }
43
- const u = await import(
44
- /* @vite-ignore */
45
- /* webpackIgnore: true */
46
- c
47
- );
48
- if (typeof u.useChartStore != "function")
49
- throw new Error("useChartStore is not a function");
50
- r(() => u.useChartStore), t(null);
51
- } catch (a) {
52
- const c = a instanceof Error ? a.message : "Unknown error";
53
- console.error("Failed to load remote chart store:", c), t(c), r(null);
54
- }
55
- })();
56
- }, [e, o]), n;
57
- }
58
- function de(e, n) {
59
- if (e.length === 0)
60
- return "";
61
- const r = e.find(
62
- (s) => {
63
- var t, o;
64
- return ((t = s.customCardPreferences) == null ? void 0 : t.visualType) === "multiple" || !!((o = s.customCardPreferences) != null && o.dataInputCardIds);
65
- }
66
- );
67
- if (r)
68
- return r.id;
69
- if (n) {
70
- const s = e.find((t) => t.id === n);
71
- if (s) {
72
- const t = s.tabTitle;
73
- if (t == "All__Header")
74
- return e[0].id;
75
- if (t && t.endsWith("__Header")) {
76
- const i = t.split("__")[0], a = e.find(
77
- (c) => c.tabTitle === i
78
- );
79
- return a ? a.id : e[0].id;
80
- }
81
- return n;
82
- }
83
- }
84
- return e[0].id;
85
- }
86
- const O = /* @__PURE__ */ new Set();
87
- function ge(e) {
88
- return O.add(e), () => {
89
- O.delete(e);
90
- };
91
- }
92
- function le() {
93
- O.forEach((e) => {
94
- e();
95
- });
96
- }
97
- const ue = (e) => {
98
- if (!e || !("detailTableBackup" in e))
99
- return e;
100
- const { detailTableBackup: n, ...r } = e;
101
- return r;
102
- };
103
- async function _(e, n, r, s) {
104
- if (!n || !r)
105
- throw new Error("Missing auth token or visual ID");
106
- const t = ["resource-by-id", "visual", r], o = s.getQueryData(t);
107
- if (o)
108
- return console.log("Using cached visual data for:", r), { data: o, fromCache: !0 };
109
- console.log("Fetching visual data from network for:", r);
110
- const i = $.loading("Loading visual...", {
111
- position: "top-center"
112
- });
113
- try {
114
- const a = await fetch(
115
- `${e}/management/v1/visuals/${r}`,
116
- {
117
- headers: {
118
- Authorization: `Bearer ${n}`
119
- }
120
- }
121
- );
122
- if (!a.ok)
123
- throw new Error("Failed to load visual");
124
- const c = await a.json();
125
- return s.setQueryData(t, c), $.dismiss(i), { data: c, fromCache: !1 };
126
- } catch (a) {
127
- throw $.dismiss(i), a;
128
- }
129
- }
130
- function z(e) {
131
- if (typeof e == "string")
132
- return JSON.parse(e);
133
- if (typeof e == "object")
134
- return e;
135
- throw new Error("Invalid frame object format");
136
- }
137
- function fe(e, n) {
138
- var o, i;
139
- const r = (e == null ? void 0 : e.frameObject) ?? ((o = e == null ? void 0 : e.visual) == null ? void 0 : o.frameObject);
140
- if (!r)
141
- return !1;
142
- const s = z(r);
143
- if (!(s != null && s.cards) || s.cards.length === 0)
144
- return !1;
145
- const t = (i = s.cards) == null ? void 0 : i.find(
146
- (a) => a.id === s.activeCardId
147
- );
148
- return t ? (oe({
149
- ...n,
150
- frame: s,
151
- card: t,
152
- visualId: (e == null ? void 0 : e.id) || s.visualId
153
- }), !0) : !1;
154
- }
155
- function he() {
156
- const { setCardSql: e } = G(), n = H(
157
- (t) => {
158
- var o;
159
- return ((o = t.card.customCardPreferences) == null ? void 0 : o.url) || "";
160
- }
161
- ), r = ce(n);
162
- return { getUpdatedFrame: M(() => {
163
- var b;
164
- le();
165
- const {
166
- frame: t,
167
- card: o,
168
- isDevMode: i,
169
- isShowingVisual: a,
170
- selectedSchemaName: c,
171
- selectedDatamodelId: u,
172
- selectedDatabaseName: f,
173
- selectedTableName: I,
174
- selectedConnectionId: F
175
- } = H.getState(), h = o.sql;
176
- let p = h;
177
- h && !h.includes("{{") && (p = ie(h), e(p));
178
- const U = (b = r == null ? void 0 : r.getState()) == null ? void 0 : b.settings, v = ae(o, {
179
- isDevMode: i,
180
- cardSql: p,
181
- isShowingVisual: a,
182
- selectedSchemaName: c,
183
- selectedDatamodelId: u,
184
- selectedDatabaseName: f,
185
- selectedTableName: I,
186
- selectedConnectionId: F,
187
- remoteChartSettings: U,
188
- stripConfig: ue
189
- }), g = t.cards.map(
190
- (C) => C.id === o.id ? v : C
191
- );
192
- return {
193
- ...t,
194
- cards: g,
195
- activeCardId: de(g, t.activeCardId)
196
- };
197
- }, [r, e]) };
198
- }
199
- function be() {
200
- const { authToken: e, tokenProps: n } = X(), r = Z(), s = q(), { selectVisual: t } = ee(), {
201
- setFrame: o,
202
- setCard: i,
203
- setIsDevMode: a,
204
- initializeModeDrafts: c,
205
- setActiveTabCardId: u,
206
- updateDataSource: f,
207
- setQueryResultColumns: I,
208
- setSelectedConnectionId: F,
209
- setSelectedDatabaseName: h,
210
- setSelectedSchemaName: p,
211
- setSelectedTableName: U,
212
- setSelectedDatamodelId: v,
213
- setFilterValues: g,
214
- setInlineFilterValuesMap: b,
215
- setApplyFilters: C
216
- } = G(), {
217
- setIsDashboardEditing: V,
218
- setIsVisualEditing: x,
219
- setSelectedFrameId: A,
220
- clearSelectedFrameId: B,
221
- addFrame: D,
222
- setIsDashboardPanelOpen: P
223
- } = te(), S = y((d) => d.selectedSheetId), R = y((d) => d.selectedFrameId), T = y((d) => d.dashboard), W = y((d) => d.filterValues), L = y(
224
- (d) => d.inlineFilterValuesMap
225
- ), w = re((s == null ? void 0 : s.id) || "", {
226
- enabled: !!(s != null && s.id) && !!(e != null && e.accessToken)
227
- }), J = M(
228
- async (d) => {
229
- try {
230
- t(d), B();
231
- const { data: m, fromCache: l } = await _(
232
- n.apiServiceUrl,
233
- (e == null ? void 0 : e.accessToken) || "",
234
- d.id,
235
- r
236
- );
237
- if (!fe(m, {
238
- setFrame: o,
239
- setCard: i,
240
- setIsDevMode: a,
241
- initializeModeDrafts: c,
242
- setActiveTabCardId: u,
243
- updateDataSource: f,
244
- setQueryResultColumns: I,
245
- setSelectedConnectionId: F,
246
- setSelectedDatabaseName: h,
247
- setSelectedSchemaName: p,
248
- setSelectedTableName: U,
249
- setSelectedDatamodelId: v,
250
- setFilterValues: g,
251
- setInlineFilterValuesMap: b,
252
- setApplyFilters: C,
253
- setIsDashboardEditing: V,
254
- setIsVisualEditing: x,
255
- dashboard: T,
256
- selectedSheetId: S,
257
- selectedFrameId: R,
258
- filterValues: W,
259
- inlineFilterValuesMap: L
260
- }))
261
- throw new Error("Failed to setup editor with visual data");
262
- return { success: !0, fromCache: l };
263
- } catch (m) {
264
- return console.error("Error editing visual:", m), { success: !1, error: "Failed to load visual for editing" };
265
- }
266
- },
267
- [
268
- e == null ? void 0 : e.accessToken,
269
- n.apiServiceUrl,
270
- r,
271
- t,
272
- o,
273
- i,
274
- V,
275
- x,
276
- a,
277
- c,
278
- u,
279
- f,
280
- I,
281
- F,
282
- h,
283
- p,
284
- U,
285
- v,
286
- g,
287
- b,
288
- C,
289
- B,
290
- T,
291
- S,
292
- R,
293
- W,
294
- L
295
- ]
296
- ), K = M(
297
- async (d) => {
298
- var m;
299
- try {
300
- if (t(d), !S)
301
- return {
302
- success: !1,
303
- error: "No sheet selected. Please select a sheet first."
304
- };
305
- const { data: l, fromCache: N } = await _(
306
- n.apiServiceUrl,
307
- (e == null ? void 0 : e.accessToken) || "",
308
- d.id,
309
- r
310
- ), j = (l == null ? void 0 : l.frameObject) ?? ((m = l == null ? void 0 : l.visual) == null ? void 0 : m.frameObject);
311
- if (!j)
312
- return { success: !1, error: "Visual has no frame data" };
313
- const E = z(j);
314
- if (!(E != null && E.cards) || E.cards.length === 0)
315
- return { success: !1, error: "Visual frame is malformed" };
316
- const k = {
317
- ...se(E),
318
- visualId: d.id
319
- // Link this frame to the library visual
320
- };
321
- return D(S, k, "end"), V(!0), A(k.id), P(!1), { success: !0, fromCache: N };
322
- } catch (l) {
323
- return console.error("Error adding visual:", l), { success: !1, error: "Failed to add visual to dashboard" };
324
- }
325
- },
326
- [
327
- e == null ? void 0 : e.accessToken,
328
- n.apiServiceUrl,
329
- r,
330
- t,
331
- S,
332
- D,
333
- V,
334
- A,
335
- P
336
- ]
337
- );
338
- return {
339
- visual: w.data,
340
- isLoading: w.isLoading,
341
- isError: w.isError,
342
- error: w.error,
343
- handleEditLibraryVisual: J,
344
- handleAddLibraryVisual: K,
345
- getUpdatedFrame: he().getUpdatedFrame,
346
- refetch: w.refetch
347
- };
348
- }
349
- export {
350
- le as f,
351
- ge as r,
352
- be as u
353
- };