@parhelia/alpaca 0.4.13049 → 0.4.13170

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.
@@ -0,0 +1,2 @@
1
+ export declare function GraphQL(): import("react").JSX.Element | null;
2
+ //# sourceMappingURL=GraphQL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphQL.d.ts","sourceRoot":"","sources":["../src/GraphQL.tsx"],"names":[],"mappings":"AA6BA,wBAAgB,OAAO,uCAsRtB"}
@@ -0,0 +1,200 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useState } from "react";
3
+ import { ActionButton, createAgentCommand, getComponentById, ParheliaAgentIcon, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, useCanvasSelection, useEditContext, } from "@parhelia/core";
4
+ import { getGraphQLSchema } from "./graphqlService";
5
+ import { GraphiQLPanel } from "./GraphiQLPanel";
6
+ function sameItem(left, right) {
7
+ return (!!left &&
8
+ !!right &&
9
+ left.id === right.id &&
10
+ left.language === right.language &&
11
+ left.version === right.version);
12
+ }
13
+ export function GraphQL() {
14
+ const editContext = useEditContext();
15
+ const canvasSelection = useCanvasSelection();
16
+ const pageItem = editContext?.page?.item ?? editContext?.item;
17
+ const selectionKey = canvasSelection.join("|");
18
+ const [query, setQuery] = useState("");
19
+ const [schemaResult, setSchemaResult] = useState({});
20
+ const [showSchemaSpinner, setShowSchemaSpinner] = useState(false);
21
+ const [schemaLoadKey, setSchemaLoadKey] = useState("");
22
+ const [aiGeneratedQuery, setAiGeneratedQuery] = useState("");
23
+ const [graphiqlVariables, setGraphiqlVariables] = useState("{}");
24
+ const [baseItem, setBaseItem] = useState(null);
25
+ const selectedComponent = useMemo(() => {
26
+ if (!editContext?.page || canvasSelection.length !== 1) {
27
+ return null;
28
+ }
29
+ return getComponentById(canvasSelection[0], editContext.page) || null;
30
+ // eslint-disable-next-line react-hooks/exhaustive-deps
31
+ }, [editContext?.page, selectionKey]);
32
+ const baseItemDescriptor = useMemo(() => {
33
+ const componentItem = selectedComponent?.datasourceItem || selectedComponent?.items?.[0];
34
+ return componentItem || pageItem?.descriptor || pageItem || null;
35
+ }, [selectedComponent, pageItem]);
36
+ const currentItem = useMemo(() => baseItemDescriptor
37
+ ? {
38
+ id: baseItemDescriptor.id,
39
+ language: baseItemDescriptor.language,
40
+ version: baseItemDescriptor.version,
41
+ }
42
+ : null, [
43
+ baseItemDescriptor?.id,
44
+ baseItemDescriptor?.language,
45
+ baseItemDescriptor?.version,
46
+ ]);
47
+ const baseItemLabel = useMemo(() => {
48
+ const componentItem = selectedComponent?.datasourceItem || selectedComponent?.items?.[0];
49
+ return componentItem?.name || pageItem?.name || currentItem?.id || "";
50
+ }, [selectedComponent, pageItem?.name, currentItem?.id]);
51
+ useEffect(() => {
52
+ let isCancelled = false;
53
+ const loadBaseItem = async () => {
54
+ if (!editContext || !baseItemDescriptor) {
55
+ setBaseItem(null);
56
+ return;
57
+ }
58
+ if (pageItem &&
59
+ sameItem({
60
+ id: pageItem.id,
61
+ language: pageItem.language,
62
+ version: pageItem.version,
63
+ }, {
64
+ id: baseItemDescriptor.id,
65
+ language: baseItemDescriptor.language,
66
+ version: baseItemDescriptor.version,
67
+ })) {
68
+ setBaseItem(pageItem);
69
+ return;
70
+ }
71
+ try {
72
+ const nextItem = await editContext.itemsRepository.getItem(baseItemDescriptor);
73
+ if (!isCancelled) {
74
+ setBaseItem(nextItem || null);
75
+ }
76
+ }
77
+ catch (error) {
78
+ console.error("Failed to load base item for GraphQL panel:", error);
79
+ if (!isCancelled) {
80
+ setBaseItem(null);
81
+ }
82
+ }
83
+ };
84
+ void loadBaseItem();
85
+ return () => {
86
+ isCancelled = true;
87
+ };
88
+ }, [
89
+ editContext,
90
+ baseItemDescriptor?.id,
91
+ baseItemDescriptor?.language,
92
+ baseItemDescriptor?.version,
93
+ pageItem,
94
+ ]);
95
+ const queryField = useMemo(() => baseItem?.fields?.find((field) => field.name === "_GraphQL" || field.name === "graphql_query") || null, [baseItem]);
96
+ useEffect(() => {
97
+ setQuery(queryField?.rawValue || "");
98
+ }, [queryField?.id, queryField?.rawValue]);
99
+ useEffect(() => {
100
+ setSchemaResult({});
101
+ setSchemaLoadKey("");
102
+ setGraphiqlVariables("{}");
103
+ setAiGeneratedQuery("");
104
+ }, [currentItem?.id, currentItem?.language, currentItem?.version]);
105
+ const currentItemKey = currentItem
106
+ ? `${currentItem.id}:${currentItem.language}:${currentItem.version}`
107
+ : "";
108
+ useEffect(() => {
109
+ if (currentItem &&
110
+ !schemaResult?.data &&
111
+ !schemaResult?.error &&
112
+ !showSchemaSpinner &&
113
+ schemaLoadKey !== currentItemKey) {
114
+ setSchemaLoadKey(currentItemKey);
115
+ void fetchSchema();
116
+ }
117
+ }, [
118
+ currentItem?.id,
119
+ currentItem?.language,
120
+ currentItem?.version,
121
+ currentItemKey,
122
+ schemaLoadKey,
123
+ schemaResult?.data,
124
+ schemaResult?.error,
125
+ showSchemaSpinner,
126
+ ]);
127
+ useEffect(() => {
128
+ if (!editContext || !currentItem)
129
+ return;
130
+ const factoryName = "graphql:context:v1";
131
+ const factory = async () => ({
132
+ schema: schemaResult?.data || "",
133
+ currentQuery: query,
134
+ itemContext: {
135
+ id: currentItem.id,
136
+ language: currentItem.language,
137
+ version: currentItem.version,
138
+ },
139
+ });
140
+ editContext.registerContextFactory?.(factoryName, factory);
141
+ return () => editContext.unregisterContextFactory?.(factoryName);
142
+ }, [
143
+ editContext,
144
+ currentItem?.id,
145
+ currentItem?.language,
146
+ currentItem?.version,
147
+ query,
148
+ schemaResult?.data,
149
+ ]);
150
+ if (!currentItem)
151
+ return null;
152
+ const activeItem = currentItem;
153
+ async function fetchSchema() {
154
+ setShowSchemaSpinner(true);
155
+ try {
156
+ const response = await getGraphQLSchema({
157
+ id: activeItem.id,
158
+ language: activeItem.language,
159
+ version: activeItem.version,
160
+ mode: "edit",
161
+ siteName: "website",
162
+ });
163
+ setSchemaResult(response.error
164
+ ? {
165
+ status: response.status,
166
+ error: response.error,
167
+ transport: response.transport,
168
+ }
169
+ : {
170
+ data: response.data,
171
+ status: response.status,
172
+ transport: response.transport,
173
+ });
174
+ }
175
+ catch (error) {
176
+ console.error("Schema fetch error:", error);
177
+ setSchemaResult({ error: String(error) });
178
+ }
179
+ finally {
180
+ setShowSchemaSpinner(false);
181
+ }
182
+ }
183
+ const applyQueryToEditor = (newQuery) => {
184
+ setQuery(newQuery);
185
+ setAiGeneratedQuery(newQuery);
186
+ };
187
+ return (_jsxs("div", { className: "relative flex h-full min-h-0 flex-col overflow-hidden text-xs", children: [aiGeneratedQuery && aiGeneratedQuery !== query && (_jsxs("div", { className: "shrink-0 flex items-center gap-2 border-b border-feedback-orange/30 bg-feedback-orange-light p-2 text-xs", children: [_jsx("span", { className: "text-feedback-orange", children: "AI generated a new query" }), _jsx(ActionButton, { onClick: () => applyQueryToEditor(aiGeneratedQuery), className: "p-1 text-xs", variant: "outline", children: "Apply" }), _jsx(ActionButton, { onClick: () => setAiGeneratedQuery(""), className: "p-1", variant: "ghost", children: "x" })] })), _jsx(GraphiQLPanel, { item: currentItem, itemLabel: baseItemLabel, query: query, variables: graphiqlVariables, onQueryChange: setQuery, onVariablesChange: setGraphiqlVariables, onExecutionResult: () => { }, headerActions: _jsx(TooltipProvider, { delayDuration: 300, children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs(ActionButton, { variant: "outline", className: "h-8 w-8 rounded-full p-0", onClick: () => {
188
+ editContext?.executeCommand?.({
189
+ command: createAgentCommand,
190
+ data: {
191
+ profileName: "GraphQL Assistant",
192
+ contextFactory: "graphql:context:v1",
193
+ initialPrompt: "Help with the current GraphQL query and schema.",
194
+ additionalData: {
195
+ source: "GraphQLPanel",
196
+ },
197
+ },
198
+ });
199
+ }, children: [_jsx(ParheliaAgentIcon, { size: 16, strokeWidth: 1 }), _jsx("span", { className: "sr-only", children: "Start GraphQL Agent" })] }) }), _jsx(TooltipContent, { children: "Start GraphQL Agent" })] }) }) })] }));
200
+ }
@@ -0,0 +1,15 @@
1
+ import "graphiql/style.css";
2
+ import "@graphiql/plugin-explorer/style.css";
3
+ import "graphiql/setup-workers/webpack";
4
+ import { GraphiQLExecutionResult, GraphQLPanelItem } from "./graphqlService";
5
+ export declare function GraphiQLPanel({ item, query, variables, onQueryChange, onVariablesChange, onExecutionResult, itemLabel, headerActions, }: {
6
+ item: GraphQLPanelItem;
7
+ query: string;
8
+ variables: string;
9
+ onQueryChange: (query: string) => void;
10
+ onVariablesChange: (variables: string) => void;
11
+ onExecutionResult: (result: GraphiQLExecutionResult) => void;
12
+ itemLabel?: string;
13
+ headerActions?: React.ReactNode;
14
+ }): import("react").JSX.Element;
15
+ //# sourceMappingURL=GraphiQLPanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphiQLPanel.d.ts","sourceRoot":"","sources":["../src/GraphiQLPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAC5B,OAAO,qCAAqC,CAAC;AAC7C,OAAO,gCAAgC,CAAC;AAQxC,OAAO,EAGL,uBAAuB,EAEvB,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;AAiF1B,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,KAAK,EACL,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,aAAa,GACd,EAAE;IACD,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,iBAAiB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,iBAAiB,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACjC,+BAmOA"}
@@ -0,0 +1,207 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import "graphiql/style.css";
3
+ import "@graphiql/plugin-explorer/style.css";
4
+ import "graphiql/setup-workers/webpack";
5
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
6
+ import { GraphiQL as GraphiQLIDE } from "graphiql";
7
+ import { useGraphiQL, useGraphiQLActions } from "@graphiql/react";
8
+ import { explorerPlugin } from "@graphiql/plugin-explorer";
9
+ import { ActionButton } from "@parhelia/core";
10
+ import { RefreshCw } from "lucide-react";
11
+ import { executeGraphiQLRequest, fetchGraphiQLSchema, isSchemaIntrospectionQuery, } from "./graphqlService";
12
+ function GraphiQLSyncBridge({ query, variables, }) {
13
+ const { updateActiveTabValues } = useGraphiQLActions();
14
+ const activeQuery = useGraphiQL((state) => state.tabs[state.activeTabIndex]?.query ?? "");
15
+ const activeVariables = useGraphiQL((state) => state.tabs[state.activeTabIndex]?.variables ?? "");
16
+ const pendingExternalState = useRef(null);
17
+ useEffect(() => {
18
+ if (activeQuery !== query || activeVariables !== variables) {
19
+ pendingExternalState.current = { query, variables };
20
+ updateActiveTabValues({ query, variables });
21
+ }
22
+ }, [activeQuery, activeVariables, query, updateActiveTabValues, variables]);
23
+ useEffect(() => {
24
+ if (pendingExternalState.current &&
25
+ pendingExternalState.current.query === activeQuery &&
26
+ pendingExternalState.current.variables === activeVariables) {
27
+ pendingExternalState.current = null;
28
+ }
29
+ }, [activeQuery, activeVariables]);
30
+ return null;
31
+ }
32
+ function parseVariables(variables) {
33
+ if (!variables.trim()) {
34
+ return null;
35
+ }
36
+ try {
37
+ return JSON.parse(variables);
38
+ }
39
+ catch (error) {
40
+ throw new Error(error instanceof Error
41
+ ? `Variables JSON is invalid: ${error.message}`
42
+ : "Variables JSON is invalid.");
43
+ }
44
+ }
45
+ function getSchemaErrorMessage(result) {
46
+ if (result.error) {
47
+ return result.error;
48
+ }
49
+ const firstError = Array.isArray(result.errors)
50
+ ? result.errors[0]
51
+ : result.errors;
52
+ if (firstError) {
53
+ if (typeof firstError.message === "string") {
54
+ return firstError.message;
55
+ }
56
+ if (typeof firstError === "string") {
57
+ return firstError;
58
+ }
59
+ }
60
+ if (result.status && result.status !== 200) {
61
+ return "Schema introspection failed";
62
+ }
63
+ return undefined;
64
+ }
65
+ export function GraphiQLPanel({ item, query, variables, onQueryChange, onVariablesChange, onExecutionResult, itemLabel, headerActions, }) {
66
+ const [schemaResult, setSchemaResult] = useState({});
67
+ const [isRefreshingSchema, setIsRefreshingSchema] = useState(false);
68
+ const [autoSchemaLoadKey, setAutoSchemaLoadKey] = useState("");
69
+ const activeSchemaRequestRef = useRef(0);
70
+ const failedSchemaRequestKeyRef = useRef("");
71
+ const explorer = useMemo(() => explorerPlugin(), []);
72
+ const plugins = useMemo(() => [explorer], [explorer]);
73
+ const handleEditHeaders = useCallback(() => { }, []);
74
+ const graphiqlSchema = schemaResult.schema ?? null;
75
+ const schemaRequestKey = useMemo(() => `${item.id}:${item.language}:${item.version}`, [item.id, item.language, item.version]);
76
+ const refreshSchema = useCallback(async () => {
77
+ const requestKey = schemaRequestKey;
78
+ const requestId = activeSchemaRequestRef.current + 1;
79
+ activeSchemaRequestRef.current = requestId;
80
+ setIsRefreshingSchema(true);
81
+ try {
82
+ const result = await fetchGraphiQLSchema(item);
83
+ if (activeSchemaRequestRef.current === requestId) {
84
+ const error = getSchemaErrorMessage(result);
85
+ if (error) {
86
+ failedSchemaRequestKeyRef.current = requestKey;
87
+ setSchemaResult({ ...result, error });
88
+ }
89
+ else {
90
+ failedSchemaRequestKeyRef.current = "";
91
+ setSchemaResult(result);
92
+ }
93
+ }
94
+ }
95
+ finally {
96
+ if (activeSchemaRequestRef.current === requestId) {
97
+ setIsRefreshingSchema(false);
98
+ }
99
+ }
100
+ }, [item.id, item.language, item.version, schemaRequestKey]);
101
+ useEffect(() => {
102
+ activeSchemaRequestRef.current += 1;
103
+ failedSchemaRequestKeyRef.current = "";
104
+ setAutoSchemaLoadKey("");
105
+ setSchemaResult({});
106
+ setIsRefreshingSchema(false);
107
+ }, [schemaRequestKey]);
108
+ useEffect(() => {
109
+ if (!graphiqlSchema &&
110
+ !schemaResult.error &&
111
+ !isRefreshingSchema &&
112
+ autoSchemaLoadKey !== schemaRequestKey) {
113
+ setAutoSchemaLoadKey(schemaRequestKey);
114
+ void refreshSchema();
115
+ }
116
+ }, [
117
+ autoSchemaLoadKey,
118
+ graphiqlSchema,
119
+ isRefreshingSchema,
120
+ refreshSchema,
121
+ schemaRequestKey,
122
+ schemaResult.error,
123
+ ]);
124
+ const handleRefreshSchema = useCallback(() => {
125
+ failedSchemaRequestKeyRef.current = "";
126
+ setSchemaResult({});
127
+ setAutoSchemaLoadKey(schemaRequestKey);
128
+ void refreshSchema();
129
+ }, [refreshSchema, schemaRequestKey]);
130
+ const fetcher = useCallback(async (graphQLParams) => {
131
+ if (!graphQLParams.query) {
132
+ return {
133
+ errors: [{ message: "No GraphQL query was provided." }],
134
+ };
135
+ }
136
+ let parsedVariables = null;
137
+ try {
138
+ parsedVariables = parseVariables(variables);
139
+ }
140
+ catch (error) {
141
+ return {
142
+ errors: [
143
+ { message: error instanceof Error ? error.message : String(error) },
144
+ ],
145
+ };
146
+ }
147
+ const isIntrospectionQuery = isSchemaIntrospectionQuery(graphQLParams.query);
148
+ if (isIntrospectionQuery &&
149
+ failedSchemaRequestKeyRef.current === schemaRequestKey) {
150
+ const message = schemaResult.error ||
151
+ "Schema introspection failed. Use Retry to try loading the schema again.";
152
+ return {
153
+ data: null,
154
+ errors: [{ message }],
155
+ };
156
+ }
157
+ const result = await executeGraphiQLRequest({
158
+ item,
159
+ query: graphQLParams.query,
160
+ variables: graphQLParams.variables ?? parsedVariables,
161
+ operationName: graphQLParams.operationName,
162
+ });
163
+ if (isIntrospectionQuery) {
164
+ const error = getSchemaErrorMessage(result);
165
+ if (error) {
166
+ failedSchemaRequestKeyRef.current = schemaRequestKey;
167
+ setSchemaResult({ ...result, error });
168
+ }
169
+ else {
170
+ failedSchemaRequestKeyRef.current = "";
171
+ setSchemaResult(result);
172
+ }
173
+ }
174
+ else {
175
+ onExecutionResult(result);
176
+ }
177
+ if (result.error) {
178
+ return {
179
+ data: result.data,
180
+ errors: [{ message: result.error }],
181
+ };
182
+ }
183
+ return {
184
+ data: result.data ?? null,
185
+ errors: result.errors,
186
+ };
187
+ }, [
188
+ item.id,
189
+ item.language,
190
+ item.version,
191
+ onExecutionResult,
192
+ schemaRequestKey,
193
+ schemaResult.error,
194
+ variables,
195
+ ]);
196
+ const lastTransportMessage = useMemo(() => {
197
+ if (schemaResult.transport?.used === "v1-fallback") {
198
+ return `Schema fetch fell back to v1 after v2 status ${schemaResult.transport.fallbackFromStatus}.`;
199
+ }
200
+ return "";
201
+ }, [schemaResult.transport]);
202
+ return (_jsxs("div", { className: "flex min-h-0 flex-1 flex-col bg-white", children: [_jsx("style", { children: `
203
+ .alpaca-graphiql-shell .graphiql-logo {
204
+ display: none;
205
+ }
206
+ ` }), _jsxs("div", { className: "flex items-center justify-between gap-3 border-b border-border-default bg-neutral-grey-5 px-3 py-2 text-xs text-neutral-grey-50", children: [_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [_jsxs("span", { children: ["Base item: ", _jsx("span", { className: "font-mono", children: itemLabel || item.id })] }), _jsxs("span", { children: [item.language, " v", item.version] })] }), headerActions && (_jsx("div", { className: "ml-auto flex shrink-0 items-center gap-2", children: headerActions }))] }), !!lastTransportMessage && (_jsx("div", { className: "border-b border-feedback-orange/30 bg-feedback-orange-light px-3 py-2 text-xs text-feedback-orange", children: lastTransportMessage })), schemaResult.error && (_jsxs("div", { className: "flex items-center justify-between gap-3 border-b border-feedback-red bg-feedback-red-light px-3 py-2 text-xs text-feedback-red", children: [_jsx("span", { children: schemaResult.error }), _jsxs(ActionButton, { className: "shrink-0", disabled: isRefreshingSchema, isLoading: isRefreshingSchema, loadingText: "Retrying", onClick: handleRefreshSchema, variant: "outline", children: [_jsx(RefreshCw, { strokeWidth: 1, className: "h-3.5 w-3.5" }), _jsx("span", { children: "Retry" })] })] })), _jsx("div", { className: "alpaca-graphiql-shell min-h-0 flex-1 bg-white [&_.graphiql-container]:h-full", children: _jsx(GraphiQLIDE, { className: "h-full", fetcher: fetcher, schema: graphiqlSchema, forcedTheme: "light", initialQuery: query, initialVariables: variables, initialHeaders: "", onEditQuery: onQueryChange, onEditVariables: onVariablesChange, onEditHeaders: handleEditHeaders, isHeadersEditorEnabled: false, defaultEditorToolsVisibility: "variables", plugins: plugins, children: _jsx(GraphiQLSyncBridge, { query: query, variables: variables }) }) })] }));
207
+ }
@@ -0,0 +1,2 @@
1
+ export declare function Layout(): import("react").JSX.Element | null;
2
+ //# sourceMappingURL=Layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Layout.d.ts","sourceRoot":"","sources":["../src/Layout.tsx"],"names":[],"mappings":"AAaA,wBAAgB,MAAM,uCA8GrB"}
package/dist/Layout.js ADDED
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { ObjectInspector, ObjectLabel, ObjectRootLabel } from "react-inspector";
4
+ import { CopyButton, getComponentByIdFromHeadlessLayout, SimpleTabs, useCanvasSelection, useEditContext, usePageViewContext, } from "@parhelia/core";
5
+ import { getPageJson } from "./services";
6
+ export function Layout() {
7
+ const [activeTab, setActiveTab] = useState(0);
8
+ const [pageLayout, setPageLayout] = useState(null);
9
+ const editContext = useEditContext();
10
+ const canvasSelection = useCanvasSelection();
11
+ if (!editContext)
12
+ return null;
13
+ usePageViewContext({
14
+ pageItemDescriptor: editContext.item?.descriptor,
15
+ itemsRepository: editContext.itemsRepository,
16
+ configuration: editContext.configuration,
17
+ });
18
+ useEffect(() => {
19
+ const loadLayout = async () => {
20
+ if (!editContext.item)
21
+ return;
22
+ const layout = await getPageJson(editContext.item.descriptor);
23
+ setPageLayout(layout);
24
+ };
25
+ loadLayout();
26
+ }, [editContext.item]);
27
+ const page = pageLayout;
28
+ let component = null;
29
+ if (page) {
30
+ const selectedComponents = canvasSelection
31
+ .map((x) => getComponentByIdFromHeadlessLayout(x, page))
32
+ .filter((x) => x);
33
+ component = selectedComponents.length === 1 ? selectedComponents[0] : null;
34
+ }
35
+ if (!component && !page)
36
+ return null;
37
+ const replacer = function (key, value) {
38
+ if (key === "parentComponent" ||
39
+ key === "placeholderReference" ||
40
+ key === "_editor") {
41
+ return undefined;
42
+ }
43
+ return value;
44
+ };
45
+ const tabs = [];
46
+ const defaultNodeRenderer = ({ depth, name, data, isNonenumerable }) => {
47
+ if (name == "__editor" ||
48
+ name == "parentComponent" ||
49
+ name == "placeholderReference") {
50
+ return null;
51
+ }
52
+ return depth === 0 ? (_jsx(ObjectRootLabel, { name: name, data: data })) : (_jsx(ObjectLabel, { name: name, data: data, isNonenumerable: isNonenumerable }));
53
+ };
54
+ if (component) {
55
+ tabs.push({
56
+ label: "Component",
57
+ id: "component",
58
+ content: (_jsx("div", { className: "relative h-full min-h-0", children: _jsx("div", { className: "absolute inset-0 overflow-auto p-2", children: _jsx(ObjectInspector, { data: component, nodeRenderer: defaultNodeRenderer }) }) })),
59
+ });
60
+ }
61
+ tabs.push({
62
+ label: "Page",
63
+ id: "page",
64
+ content: (_jsx("div", { className: "relative h-full min-h-0", children: _jsx("div", { className: "absolute inset-0 overflow-auto p-2", children: _jsx(ObjectInspector, { data: page, nodeRenderer: defaultNodeRenderer }) }) })),
65
+ });
66
+ return (_jsxs("div", { className: "relative flex h-full min-h-0 flex-col", children: [_jsx(SimpleTabs, { tabs: tabs, activeTab: activeTab, setActiveTab: setActiveTab, className: "border-border-default flex border-b px-2 pt-2" }), _jsx("div", { className: "absolute top-2 right-1 h-4 w-4", children: _jsx(CopyButton, { textToCopy: JSON.stringify(activeTab === 0 && component ? component : page, replacer, 2), iconOnly: true }) })] }));
67
+ }
@@ -43,12 +43,8 @@ async function getCheckboxCommand(components, editContext, fieldName, label) {
43
43
  const items = await editContext.itemsRepository.getItems(datasourceItems);
44
44
  if (!items.length)
45
45
  return null;
46
- // W12 phase 3 (fecanon lane): a routed read carries the canonical "true" (payload
47
- // `canonical: true`), an old-route read the checkbox's "1"; both mean checked. The save below
48
- // keeps posting the store's own "1"/"" unmarked, which both backends still accept.
49
- const isChecked = (raw) => raw === "1" || (raw ?? "").toLowerCase() === "true";
50
- const someLinked = items.some((item) => isChecked(item.fields.find((field) => field.name === fieldName)?.rawValue));
51
- const allLinked = items.every((item) => isChecked(item.fields.find((field) => field.name === fieldName)?.rawValue));
46
+ const someLinked = items.some((item) => item.fields.find((field) => field.name === fieldName)?.rawValue === "1");
47
+ const allLinked = items.every((item) => item.fields.find((field) => field.name === fieldName)?.rawValue === "1");
52
48
  return {
53
49
  id: fieldName,
54
50
  icon: allLinked ? (_jsx(Check, { strokeWidth: 1, size: defaultIconSize })) : someLinked ? (_jsx(StopCircle, { strokeWidth: 1, size: defaultIconSize })) : (_jsx(Square, { strokeWidth: 1, size: defaultIconSize })),
@@ -0,0 +1,77 @@
1
+ import { GraphQLSchema } from "graphql";
2
+ export type ExecuteGraphQLParams = {
3
+ query: string;
4
+ tags?: string[];
5
+ host?: string;
6
+ path?: string;
7
+ language?: string;
8
+ mode?: string;
9
+ itemId?: string;
10
+ version?: number;
11
+ revalidate?: number;
12
+ siteName?: string;
13
+ sessionId?: string;
14
+ schema?: string;
15
+ };
16
+ export type GraphQLTransport = {
17
+ requested: "v2";
18
+ used: "v2" | "v1-fallback";
19
+ fallbackFromStatus?: number;
20
+ };
21
+ export type GraphQLQueryResult = {
22
+ data?: any;
23
+ status: number;
24
+ errors?: any;
25
+ transport: GraphQLTransport;
26
+ };
27
+ export type GraphQLSchemaResult = {
28
+ data?: string;
29
+ status: number;
30
+ error?: string;
31
+ transport: GraphQLTransport;
32
+ };
33
+ export declare const INTROSPECTION_QUERY: string;
34
+ export type GraphQLPanelItem = {
35
+ id: string;
36
+ language: string;
37
+ version: number;
38
+ };
39
+ export type QueryNormalizationResult = {
40
+ query?: string;
41
+ warning?: string;
42
+ error?: string;
43
+ };
44
+ export type GraphiQLExecutionResult = {
45
+ status?: number;
46
+ data?: any;
47
+ errors?: any;
48
+ error?: string;
49
+ warning?: string;
50
+ transport?: GraphQLTransport;
51
+ compiledQuery?: string;
52
+ };
53
+ export type GraphiQLSchemaResult = GraphiQLExecutionResult & {
54
+ rawSchemaText?: string;
55
+ schema?: GraphQLSchema;
56
+ };
57
+ export declare function isSchemaIntrospectionQuery(query: string): boolean;
58
+ export declare function createExplicitItemArgs(item: GraphQLPanelItem): string;
59
+ export declare function createStarterQuery(item: GraphQLPanelItem): string;
60
+ export declare function normalizePanelQuery(query: string, item: GraphQLPanelItem): QueryNormalizationResult;
61
+ export declare function executeGraphQLQuery({ query, host, path, language, mode, itemId, version, siteName, schema, sessionId, }: ExecuteGraphQLParams): Promise<GraphQLQueryResult>;
62
+ export declare function getGraphQLSchema({ id, language, version, mode, siteName, }: {
63
+ id: string;
64
+ language?: string;
65
+ version?: number;
66
+ mode?: string;
67
+ siteName?: string;
68
+ }): Promise<GraphQLSchemaResult>;
69
+ export declare function executeGraphiQLRequest(options: {
70
+ item: GraphQLPanelItem;
71
+ query: string;
72
+ variables?: Record<string, unknown> | null;
73
+ operationName?: string | null;
74
+ }): Promise<GraphiQLExecutionResult>;
75
+ export declare function fetchGraphiQLSchema(item: GraphQLPanelItem): Promise<GraphiQLSchemaResult>;
76
+ export declare function getSchemaContextValue(schemaResult: GraphiQLSchemaResult): string;
77
+ //# sourceMappingURL=graphqlService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphqlService.d.ts","sourceRoot":"","sources":["../src/graphqlService.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,aAAa,EAKd,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM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