refactor: consolidate widget workbench modules
This commit is contained in:
1 parent
29c94be821
commit
84058544a4
50 files changed
+1529
-1597
No files matched your search
@@ -0,0 +1,9 @@
|
||||
export const downloadJson = (data: unknown, filename: string) => {
|
||||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = url;
|
||||
anchor.download = filename;
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import dayjs from "dayjs";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
|
||||
@@ -42,3 +42,15 @@ export const useIntegrationConnected = (updatedAt: Date, { timeout = 30000 }) =>
|
||||
|
||||
return connected;
|
||||
};
|
||||
|
||||
/** Track overlapping preparations without allowing one completion to clear another's pending state. */
|
||||
export function usePendingOperations() {
|
||||
const [count, setCount] = useState(0);
|
||||
const trackPending = useCallback((pending: boolean) => {
|
||||
setCount((current) => {
|
||||
if (pending) return current + 1;
|
||||
return current - 1;
|
||||
});
|
||||
}, []);
|
||||
return [count > 0, trackPending] as const;
|
||||
}
|
||||
@@ -12,3 +12,4 @@ export * from "./error";
|
||||
export * from "./theme";
|
||||
export * from "./function";
|
||||
export * from "./grid-algorithm";
|
||||
export * from "./browser";
|
||||
@@ -99,3 +99,13 @@ const parseHttpUrl = (value: unknown, baseUrl?: string): URL | undefined => {
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
/** Offer an explicit prefix; preserve the owner's hostname, port and path text. */
|
||||
export function getConnectionUrlSuggestion(value: string): string | undefined {
|
||||
const input = value.trim();
|
||||
if (!input || input.includes("://") || (input.startsWith("/") && !input.startsWith("//"))) return undefined;
|
||||
let candidate = `http://${input}`;
|
||||
if (input.startsWith("//")) candidate = `http:${input}`;
|
||||
if (!getSafeApplicationUrl(candidate)) return undefined;
|
||||
return candidate;
|
||||
}
|
||||
Reference in new issue
Block a user