@cmssy/react 0.1.0

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/dist/index.cjs ADDED
@@ -0,0 +1,529 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+
6
+ // src/fields.ts
7
+ function control(type) {
8
+ return (opts = {}) => ({
9
+ type,
10
+ label: opts.label ?? "",
11
+ ...opts
12
+ });
13
+ }
14
+ var fields = {
15
+ singleLine: control("singleLine"),
16
+ multiLine: control("multiLine"),
17
+ richText: control("richText"),
18
+ numeric: control("numeric"),
19
+ date: control("date"),
20
+ media: control("media"),
21
+ link: control("link"),
22
+ select: control("select"),
23
+ multiselect: control("multiselect"),
24
+ boolean: control("boolean"),
25
+ color: control("color"),
26
+ repeater: control("repeater")
27
+ };
28
+
29
+ // src/registry.ts
30
+ function defineBlock(def) {
31
+ return def;
32
+ }
33
+ function buildBlockMap(blocks) {
34
+ const map = /* @__PURE__ */ Object.create(null);
35
+ for (const block of blocks) map[block.type] = block.component;
36
+ return map;
37
+ }
38
+ function blocksToSchemas(blocks) {
39
+ const out = /* @__PURE__ */ Object.create(null);
40
+ for (const block of blocks) {
41
+ const schema = {};
42
+ for (const [key, def] of Object.entries(block.props)) {
43
+ schema[key] = { ...def, label: def.label || key };
44
+ }
45
+ out[block.type] = schema;
46
+ }
47
+ return out;
48
+ }
49
+ function blocksToMeta(blocks, defaults = {}) {
50
+ const out = /* @__PURE__ */ Object.create(null);
51
+ for (const block of blocks) {
52
+ const category = block.category ?? defaults.category;
53
+ out[block.type] = {
54
+ label: block.label ?? block.type,
55
+ ...category ? { category } : {},
56
+ ...block.icon ? { icon: block.icon } : {},
57
+ ...block.layoutPositions ? { layoutPositions: block.layoutPositions } : {}
58
+ };
59
+ }
60
+ return out;
61
+ }
62
+
63
+ // src/content/get-block-content.ts
64
+ function isPlainObject(value) {
65
+ return typeof value === "object" && value !== null && !Array.isArray(value);
66
+ }
67
+ function looksLikeLocaleKey(key) {
68
+ return /^[a-z]{2}(-[A-Za-z]{2})?$/.test(key);
69
+ }
70
+ function getBlockContentForLanguage(content, locale, defaultLocale = "en", availableLocales) {
71
+ if (!isPlainObject(content)) return {};
72
+ const isLocale = availableLocales ? (key) => availableLocales.includes(key) : looksLikeLocaleKey;
73
+ const localeEntries = Object.entries(content).filter(
74
+ ([key, value]) => isLocale(key) && isPlainObject(value)
75
+ );
76
+ if (localeEntries.length === 0) return { ...content };
77
+ const localeMap = Object.fromEntries(localeEntries);
78
+ const nonTranslatable = {};
79
+ for (const [key, value] of Object.entries(content)) {
80
+ if (!(isLocale(key) && isPlainObject(value))) nonTranslatable[key] = value;
81
+ }
82
+ const fallbackKey = Object.keys(localeMap)[0];
83
+ const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
84
+ return { ...nonTranslatable, ...chosen };
85
+ }
86
+ var WARN_CAP = 256;
87
+ var warned = /* @__PURE__ */ new Set();
88
+ function UnknownBlock({ type }) {
89
+ if (typeof window !== "undefined" && !warned.has(type)) {
90
+ if (warned.size >= WARN_CAP) warned.clear();
91
+ warned.add(type);
92
+ console.warn(`[cmssy] no component registered for block type "${type}"`);
93
+ }
94
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-cmssy-unknown-block": type });
95
+ }
96
+ function renderResolvedBlock(block, map, locale, defaultLocale) {
97
+ const Component = map[block.type];
98
+ const content = getBlockContentForLanguage(
99
+ block.content,
100
+ locale,
101
+ defaultLocale
102
+ );
103
+ return /* @__PURE__ */ jsxRuntime.jsx(
104
+ "div",
105
+ {
106
+ "data-block-id": block.id,
107
+ "data-block-type": block.type,
108
+ style: Component ? void 0 : { display: "none" },
109
+ children: Component ? /* @__PURE__ */ jsxRuntime.jsx(Component, { content }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
110
+ },
111
+ block.id
112
+ );
113
+ }
114
+ function CmssyServerPage({
115
+ page,
116
+ blocks,
117
+ locale = "en",
118
+ defaultLocale = "en"
119
+ }) {
120
+ if (!page) return null;
121
+ const map = buildBlockMap(blocks);
122
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: page.blocks.map(
123
+ (block) => renderResolvedBlock(block, map, locale, defaultLocale)
124
+ ) });
125
+ }
126
+ function CmssyServerLayout({
127
+ groups,
128
+ blocks,
129
+ position,
130
+ locale = "en",
131
+ defaultLocale = "en"
132
+ }) {
133
+ const group = groups.find((g) => g.position === position);
134
+ const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
135
+ if (layoutBlocks.length === 0) return null;
136
+ const map = buildBlockMap(blocks);
137
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: layoutBlocks.map(
138
+ (block) => renderResolvedBlock(block, map, locale, defaultLocale)
139
+ ) });
140
+ }
141
+
142
+ // src/bridge/protocol.ts
143
+ var PROTOCOL_VERSION = 1;
144
+ function isProtocolCompatible(version) {
145
+ return version === PROTOCOL_VERSION;
146
+ }
147
+
148
+ // src/bridge/messages.ts
149
+ function normalizeOrigin(origin) {
150
+ if (origin === "*") return "*";
151
+ try {
152
+ return new URL(origin).origin;
153
+ } catch {
154
+ return origin;
155
+ }
156
+ }
157
+ function postToEditor(target, editorOrigin, message) {
158
+ target.postMessage(message, normalizeOrigin(editorOrigin));
159
+ }
160
+ function isObject(value) {
161
+ return typeof value === "object" && value !== null && !Array.isArray(value);
162
+ }
163
+ function parseEditorMessage(data, origin, expectedOrigin) {
164
+ const expected = normalizeOrigin(expectedOrigin);
165
+ if (expected !== "*" && origin !== expected) return null;
166
+ if (!isObject(data)) return null;
167
+ switch (data.type) {
168
+ case "cmssy:select":
169
+ return typeof data.blockId === "string" && data.protocolVersion === PROTOCOL_VERSION ? {
170
+ type: "cmssy:select",
171
+ protocolVersion: PROTOCOL_VERSION,
172
+ blockId: data.blockId
173
+ } : null;
174
+ case "cmssy:patch":
175
+ return typeof data.blockId === "string" && isObject(data.content) && data.protocolVersion === PROTOCOL_VERSION ? {
176
+ type: "cmssy:patch",
177
+ blockId: data.blockId,
178
+ content: data.content,
179
+ protocolVersion: PROTOCOL_VERSION,
180
+ ...typeof data.layoutPosition === "string" ? { layoutPosition: data.layoutPosition } : {}
181
+ } : null;
182
+ case "cmssy:parent-ready":
183
+ return data.protocolVersion === PROTOCOL_VERSION ? { type: "cmssy:parent-ready", protocolVersion: PROTOCOL_VERSION } : null;
184
+ case "cmssy:insert":
185
+ return typeof data.blockId === "string" && typeof data.blockType === "string" && isObject(data.content) && typeof data.index === "number" && data.protocolVersion === PROTOCOL_VERSION ? {
186
+ type: "cmssy:insert",
187
+ protocolVersion: PROTOCOL_VERSION,
188
+ blockId: data.blockId,
189
+ blockType: data.blockType,
190
+ content: data.content,
191
+ index: data.index
192
+ } : null;
193
+ case "cmssy:reorder":
194
+ return Array.isArray(data.blockIds) && data.blockIds.every((id) => typeof id === "string") && data.protocolVersion === PROTOCOL_VERSION ? {
195
+ type: "cmssy:reorder",
196
+ protocolVersion: PROTOCOL_VERSION,
197
+ blockIds: data.blockIds
198
+ } : null;
199
+ case "cmssy:remove":
200
+ return typeof data.blockId === "string" && data.protocolVersion === PROTOCOL_VERSION ? {
201
+ type: "cmssy:remove",
202
+ protocolVersion: PROTOCOL_VERSION,
203
+ blockId: data.blockId
204
+ } : null;
205
+ case "cmssy:drag-over":
206
+ return typeof data.y === "number" && data.protocolVersion === PROTOCOL_VERSION ? {
207
+ type: "cmssy:drag-over",
208
+ protocolVersion: PROTOCOL_VERSION,
209
+ y: data.y
210
+ } : null;
211
+ case "cmssy:drag-end":
212
+ return data.protocolVersion === PROTOCOL_VERSION ? { type: "cmssy:drag-end", protocolVersion: PROTOCOL_VERSION } : null;
213
+ default:
214
+ return null;
215
+ }
216
+ }
217
+
218
+ // src/content/content-client.ts
219
+ var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
220
+ publicPage(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret) {
221
+ id
222
+ blocks { id type content }
223
+ publishedBlocks { id type content }
224
+ }
225
+ }`;
226
+ var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!, $pageSlug: String!, $previewSecret: String) {
227
+ publicPageLayouts(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug, previewSecret: $previewSecret) {
228
+ position
229
+ blocks { id type content order isActive }
230
+ }
231
+ }`;
232
+ function normalizeSlug(path) {
233
+ if (Array.isArray(path)) {
234
+ const joined = path.filter(Boolean).join("/");
235
+ return joined ? `/${joined}` : "/";
236
+ }
237
+ if (!path || path === "/") return "/";
238
+ return path.startsWith("/") ? path : `/${path}`;
239
+ }
240
+ async function fetchPage(config, path, options = {}) {
241
+ const slug = normalizeSlug(path);
242
+ const doFetch = options.fetch ?? globalThis.fetch;
243
+ if (typeof doFetch !== "function") {
244
+ throw new Error(
245
+ "cmssy: no fetch implementation available - pass options.fetch"
246
+ );
247
+ }
248
+ const trimmedSecret = options.previewSecret?.trim();
249
+ const previewSecret = trimmedSecret ? trimmedSecret : null;
250
+ const response = await doFetch(config.apiUrl, {
251
+ method: "POST",
252
+ headers: { "content-type": "application/json" },
253
+ body: JSON.stringify({
254
+ query: PUBLIC_PAGE_QUERY,
255
+ variables: {
256
+ workspaceSlug: config.workspaceSlug,
257
+ slug,
258
+ previewSecret
259
+ }
260
+ }),
261
+ signal: options.signal
262
+ });
263
+ if (!response.ok) {
264
+ let detail = "";
265
+ try {
266
+ const body = await response.json();
267
+ if (body.errors && body.errors.length > 0) {
268
+ detail = ` - ${body.errors.map((error) => error.message ?? "GraphQL error").join("; ")}`;
269
+ }
270
+ } catch {
271
+ detail = "";
272
+ }
273
+ throw new Error(`cmssy: page fetch failed (${response.status})${detail}`);
274
+ }
275
+ let json;
276
+ try {
277
+ json = await response.json();
278
+ } catch {
279
+ throw new Error("cmssy: invalid JSON response from the page query");
280
+ }
281
+ if (json.errors && json.errors.length > 0) {
282
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
283
+ throw new Error(`cmssy: page fetch error - ${message}`);
284
+ }
285
+ const page = json.data?.publicPage;
286
+ if (!page) return null;
287
+ const draft = previewSecret !== null;
288
+ const blocks = (draft ? page.blocks : page.publishedBlocks) ?? [];
289
+ return { id: page.id, blocks };
290
+ }
291
+ async function fetchLayouts(config, path, options = {}) {
292
+ const pageSlug = normalizeSlug(path);
293
+ const doFetch = options.fetch ?? globalThis.fetch;
294
+ if (typeof doFetch !== "function") {
295
+ throw new Error(
296
+ "cmssy: no fetch implementation available - pass options.fetch"
297
+ );
298
+ }
299
+ const trimmedSecret = options.previewSecret?.trim();
300
+ const previewSecret = trimmedSecret ? trimmedSecret : null;
301
+ const response = await doFetch(config.apiUrl, {
302
+ method: "POST",
303
+ headers: { "content-type": "application/json" },
304
+ body: JSON.stringify({
305
+ query: PUBLIC_PAGE_LAYOUTS_QUERY,
306
+ variables: {
307
+ workspaceSlug: config.workspaceSlug,
308
+ pageSlug,
309
+ previewSecret
310
+ }
311
+ }),
312
+ signal: options.signal
313
+ });
314
+ if (!response.ok) {
315
+ throw new Error(`cmssy: layouts fetch failed (${response.status})`);
316
+ }
317
+ let json;
318
+ try {
319
+ json = await response.json();
320
+ } catch {
321
+ throw new Error("cmssy: invalid JSON response from the layouts query");
322
+ }
323
+ if (json.errors && json.errors.length > 0) {
324
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
325
+ throw new Error(`cmssy: layouts fetch error - ${message}`);
326
+ }
327
+ return json.data?.publicPageLayouts ?? [];
328
+ }
329
+
330
+ // src/data/graphql-request.ts
331
+ async function graphqlRequest(config, query, variables, options = {}, label = "request") {
332
+ const doFetch = options.fetch ?? globalThis.fetch;
333
+ if (typeof doFetch !== "function") {
334
+ throw new Error(
335
+ "cmssy: no fetch implementation available - pass options.fetch"
336
+ );
337
+ }
338
+ const response = await doFetch(config.apiUrl, {
339
+ method: "POST",
340
+ headers: { "content-type": "application/json", ...options.headers },
341
+ body: JSON.stringify({ query, variables }),
342
+ signal: options.signal
343
+ });
344
+ if (!response.ok) {
345
+ let detail = "";
346
+ try {
347
+ const body = await response.json();
348
+ if (body.errors && body.errors.length > 0) {
349
+ detail = ` - ${body.errors.map((error) => error.message ?? "GraphQL error").join("; ")}`;
350
+ }
351
+ } catch {
352
+ detail = "";
353
+ }
354
+ throw new Error(`cmssy: ${label} failed (${response.status})${detail}`);
355
+ }
356
+ let json;
357
+ try {
358
+ json = await response.json();
359
+ } catch {
360
+ throw new Error(`cmssy: invalid JSON response from the ${label}`);
361
+ }
362
+ if (json.errors && json.errors.length > 0) {
363
+ const message = json.errors.map((error) => error.message ?? "GraphQL error").join("; ");
364
+ throw new Error(`cmssy: ${label} error - ${message}`);
365
+ }
366
+ return json.data;
367
+ }
368
+
369
+ // src/data/queries.ts
370
+ var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
371
+ publicSiteConfig(workspaceSlug: $workspaceSlug) {
372
+ id
373
+ workspaceId
374
+ siteName
375
+ defaultLanguage
376
+ enabledLanguages
377
+ enabledFeatures
378
+ notFoundPageId
379
+ previewUrl
380
+ }
381
+ }`;
382
+ var MODEL_DEFINITIONS_QUERY = `query PublicModelDefinitions($workspaceId: String!) {
383
+ publicModelDefinitions(workspaceId: $workspaceId) {
384
+ id name slug description icon color displayField recordCount
385
+ }
386
+ }`;
387
+ var MODEL_RECORDS_QUERY = `query PublicModelRecords($workspaceId: String!, $modelSlug: String!, $filter: JSON, $sort: String, $limit: Int, $offset: Int, $populate: [String!]) {
388
+ publicModelRecords(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, sort: $sort, limit: $limit, offset: $offset, populate: $populate) {
389
+ items { id modelId data status createdAt updatedAt }
390
+ total
391
+ hasMore
392
+ }
393
+ }`;
394
+ var FORM_QUERY = `query PublicForm($formId: ID!) {
395
+ publicForm(formId: $formId) {
396
+ id
397
+ name
398
+ slug
399
+ description
400
+ fields {
401
+ id name fieldType label placeholder helpText
402
+ defaultValue options validation width order showIf
403
+ }
404
+ settings {
405
+ actionType submitButtonLabel successMessage errorMessage
406
+ redirectUrl requireLogin enableCaptcha
407
+ }
408
+ }
409
+ }`;
410
+ var SUBMIT_FORM_MUTATION = `mutation SubmitForm($formId: ID!, $input: SubmitFormInput!) {
411
+ submitForm(formId: $formId, input: $input) {
412
+ success message submissionId redirectUrl accessToken customer
413
+ }
414
+ }`;
415
+
416
+ // src/data/settings-client.ts
417
+ async function fetchSiteConfig(config, options = {}) {
418
+ const data = await graphqlRequest(
419
+ config,
420
+ SITE_CONFIG_QUERY,
421
+ { workspaceSlug: config.workspaceSlug },
422
+ options,
423
+ "site config query"
424
+ );
425
+ return data.publicSiteConfig ?? null;
426
+ }
427
+ async function resolveWorkspaceId(config, options = {}) {
428
+ const siteConfig = await fetchSiteConfig(config, options);
429
+ if (!siteConfig?.workspaceId) {
430
+ throw new Error(
431
+ `cmssy: could not resolve workspaceId for "${config.workspaceSlug}"`
432
+ );
433
+ }
434
+ return siteConfig.workspaceId;
435
+ }
436
+
437
+ // src/data/client.ts
438
+ function createCmssyClient(config) {
439
+ let cachedWorkspaceId;
440
+ let inFlight;
441
+ function resolveWorkspaceId2(options) {
442
+ if (cachedWorkspaceId) return Promise.resolve(cachedWorkspaceId);
443
+ if (!inFlight) {
444
+ inFlight = resolveWorkspaceId(config, options).then((id) => {
445
+ cachedWorkspaceId = id;
446
+ return id;
447
+ }).finally(() => {
448
+ inFlight = void 0;
449
+ });
450
+ }
451
+ return inFlight;
452
+ }
453
+ return {
454
+ config,
455
+ resolveWorkspaceId: resolveWorkspaceId2,
456
+ query(document, variables = {}, options) {
457
+ return graphqlRequest(
458
+ config,
459
+ document,
460
+ variables,
461
+ options,
462
+ "graphql operation"
463
+ );
464
+ },
465
+ async queryScoped(document, variables = {}, options = {}) {
466
+ const { workspaceId: provided, headers, ...rest } = options;
467
+ const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
468
+ const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
469
+ const scopedVariables = /\$workspaceId\b/.test(document) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
470
+ return graphqlRequest(
471
+ config,
472
+ document,
473
+ scopedVariables,
474
+ { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
475
+ "graphql operation"
476
+ );
477
+ }
478
+ };
479
+ }
480
+ function CmssyBlock({
481
+ block,
482
+ locale,
483
+ defaultLocale,
484
+ blockMap,
485
+ patchedContent,
486
+ editable,
487
+ layoutPosition
488
+ }) {
489
+ const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
490
+ const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
491
+ const content = patchedContent ? { ...base, ...patchedContent } : base;
492
+ return /* @__PURE__ */ jsxRuntime.jsx(
493
+ "div",
494
+ {
495
+ "data-block-id": block.id,
496
+ "data-block-type": block.type,
497
+ "data-layout-position": layoutPosition,
498
+ draggable: editable || void 0,
499
+ style: Component ? void 0 : { display: "none" },
500
+ children: Component ? react.createElement(Component, { content }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
501
+ }
502
+ );
503
+ }
504
+
505
+ exports.CmssyBlock = CmssyBlock;
506
+ exports.CmssyServerLayout = CmssyServerLayout;
507
+ exports.CmssyServerPage = CmssyServerPage;
508
+ exports.FORM_QUERY = FORM_QUERY;
509
+ exports.MODEL_DEFINITIONS_QUERY = MODEL_DEFINITIONS_QUERY;
510
+ exports.MODEL_RECORDS_QUERY = MODEL_RECORDS_QUERY;
511
+ exports.PROTOCOL_VERSION = PROTOCOL_VERSION;
512
+ exports.SITE_CONFIG_QUERY = SITE_CONFIG_QUERY;
513
+ exports.SUBMIT_FORM_MUTATION = SUBMIT_FORM_MUTATION;
514
+ exports.UnknownBlock = UnknownBlock;
515
+ exports.blocksToMeta = blocksToMeta;
516
+ exports.blocksToSchemas = blocksToSchemas;
517
+ exports.buildBlockMap = buildBlockMap;
518
+ exports.createCmssyClient = createCmssyClient;
519
+ exports.defineBlock = defineBlock;
520
+ exports.fetchLayouts = fetchLayouts;
521
+ exports.fetchPage = fetchPage;
522
+ exports.fields = fields;
523
+ exports.getBlockContentForLanguage = getBlockContentForLanguage;
524
+ exports.graphqlRequest = graphqlRequest;
525
+ exports.isProtocolCompatible = isProtocolCompatible;
526
+ exports.normalizeOrigin = normalizeOrigin;
527
+ exports.normalizeSlug = normalizeSlug;
528
+ exports.parseEditorMessage = parseEditorMessage;
529
+ exports.postToEditor = postToEditor;
@@ -0,0 +1,166 @@
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, d as FetchLike, e as CmssyClientConfig, R as RawBlock, f as BlockMap } from './registry-BoxAyw4_.cjs';
2
+ export { a as BlockMeta, g as BlockRect, B as BlockSchema, h as BoundsMessage, i as ClickMessage, j as FetchLikeResponse, k as FetchPageOptions, l as FieldType, P as PROTOCOL_VERSION, m as ParentReadyMessage, n as PatchMessage, o as RawLayoutBlock, p as ReadyMessage, S as SelectMessage, q as blocksToMeta, r as blocksToSchemas, s as buildBlockMap, t as defineBlock, u as fetchLayouts, v as fetchPage, w as isProtocolCompatible, x as normalizeSlug } from './registry-BoxAyw4_.cjs';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import 'react';
5
+
6
+ type FieldControl = Omit<FieldDefinition, "type" | "label"> & {
7
+ label?: string;
8
+ };
9
+ declare const fields: {
10
+ singleLine: (opts?: FieldControl) => FieldDefinition;
11
+ multiLine: (opts?: FieldControl) => FieldDefinition;
12
+ richText: (opts?: FieldControl) => FieldDefinition;
13
+ numeric: (opts?: FieldControl) => FieldDefinition;
14
+ date: (opts?: FieldControl) => FieldDefinition;
15
+ media: (opts?: FieldControl) => FieldDefinition;
16
+ link: (opts?: FieldControl) => FieldDefinition;
17
+ select: (opts?: FieldControl) => FieldDefinition;
18
+ multiselect: (opts?: FieldControl) => FieldDefinition;
19
+ boolean: (opts?: FieldControl) => FieldDefinition;
20
+ color: (opts?: FieldControl) => FieldDefinition;
21
+ repeater: (opts?: FieldControl) => FieldDefinition;
22
+ };
23
+
24
+ interface CmssyServerPageProps {
25
+ page: CmssyPageData | null;
26
+ blocks: BlockDefinition[];
27
+ locale?: string;
28
+ defaultLocale?: string;
29
+ }
30
+ declare function CmssyServerPage({ page, blocks, locale, defaultLocale, }: CmssyServerPageProps): react_jsx_runtime.JSX.Element | null;
31
+
32
+ interface CmssyServerLayoutProps {
33
+ groups: CmssyLayoutGroup[];
34
+ blocks: BlockDefinition[];
35
+ position: string;
36
+ locale?: string;
37
+ defaultLocale?: string;
38
+ }
39
+ declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, }: CmssyServerLayoutProps): react_jsx_runtime.JSX.Element | null;
40
+
41
+ interface PostTarget {
42
+ postMessage: (message: unknown, targetOrigin: string) => void;
43
+ }
44
+ declare function normalizeOrigin(origin: string): string;
45
+ declare function postToEditor(target: PostTarget, editorOrigin: string, message: AppToEditorMessage): void;
46
+ declare function parseEditorMessage(data: unknown, origin: string, expectedOrigin: string): EditorToAppMessage | null;
47
+
48
+ declare function getBlockContentForLanguage(content: unknown, locale: string, defaultLocale?: string, availableLocales?: string[]): Record<string, unknown>;
49
+
50
+ interface GraphqlRequestOptions {
51
+ fetch?: FetchLike;
52
+ signal?: AbortSignal;
53
+ headers?: Record<string, string>;
54
+ }
55
+ declare function graphqlRequest<T>(config: CmssyClientConfig, query: string, variables: Record<string, unknown>, options?: GraphqlRequestOptions, label?: string): Promise<T>;
56
+
57
+ interface QueryScopedOptions extends GraphqlRequestOptions {
58
+ workspaceId?: string;
59
+ }
60
+ interface CmssyClient {
61
+ readonly config: CmssyClientConfig;
62
+ query<T = unknown>(document: string, variables?: Record<string, unknown>, options?: GraphqlRequestOptions): Promise<T>;
63
+ queryScoped<T = unknown>(document: string, variables?: Record<string, unknown>, options?: QueryScopedOptions): Promise<T>;
64
+ resolveWorkspaceId(options?: GraphqlRequestOptions): Promise<string>;
65
+ }
66
+ declare function createCmssyClient(config: CmssyClientConfig): CmssyClient;
67
+
68
+ interface CmssySiteConfig {
69
+ id: string;
70
+ workspaceId: string;
71
+ siteName: unknown;
72
+ defaultLanguage: string | null;
73
+ enabledLanguages: string[];
74
+ enabledFeatures: string[];
75
+ notFoundPageId: string | null;
76
+ previewUrl: string | null;
77
+ }
78
+ declare const SITE_CONFIG_QUERY = "query PublicSiteConfig($workspaceSlug: String!) {\n publicSiteConfig(workspaceSlug: $workspaceSlug) {\n id\n workspaceId\n siteName\n defaultLanguage\n enabledLanguages\n enabledFeatures\n notFoundPageId\n previewUrl\n }\n}";
79
+ interface CmssyModelDefinition {
80
+ id: string;
81
+ name: string;
82
+ slug: string;
83
+ description: string | null;
84
+ icon: string | null;
85
+ color: string | null;
86
+ displayField: string | null;
87
+ recordCount: number | null;
88
+ }
89
+ interface CmssyModelRecord {
90
+ id: string;
91
+ modelId: string;
92
+ data: Record<string, unknown>;
93
+ status: string | null;
94
+ createdAt: string | null;
95
+ updatedAt: string | null;
96
+ }
97
+ interface CmssyRecordList {
98
+ items: CmssyModelRecord[];
99
+ total: number;
100
+ hasMore: boolean;
101
+ }
102
+ declare const MODEL_DEFINITIONS_QUERY = "query PublicModelDefinitions($workspaceId: String!) {\n publicModelDefinitions(workspaceId: $workspaceId) {\n id name slug description icon color displayField recordCount\n }\n}";
103
+ declare const MODEL_RECORDS_QUERY = "query PublicModelRecords($workspaceId: String!, $modelSlug: String!, $filter: JSON, $sort: String, $limit: Int, $offset: Int, $populate: [String!]) {\n publicModelRecords(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, sort: $sort, limit: $limit, offset: $offset, populate: $populate) {\n items { id modelId data status createdAt updatedAt }\n total\n hasMore\n }\n}";
104
+ interface CmssyFormField {
105
+ id: string;
106
+ name: string;
107
+ fieldType: string;
108
+ label: string | null;
109
+ placeholder: string | null;
110
+ helpText: string | null;
111
+ defaultValue: unknown;
112
+ options: unknown;
113
+ validation: unknown;
114
+ width: string | null;
115
+ order: number | null;
116
+ showIf: unknown;
117
+ }
118
+ interface CmssyFormSettings {
119
+ actionType: string | null;
120
+ submitButtonLabel: unknown;
121
+ successMessage: unknown;
122
+ errorMessage: unknown;
123
+ redirectUrl: string | null;
124
+ requireLogin: boolean | null;
125
+ enableCaptcha: boolean | null;
126
+ }
127
+ interface CmssyFormDefinition {
128
+ id: string;
129
+ name: string;
130
+ slug: string | null;
131
+ description: string | null;
132
+ fields: CmssyFormField[];
133
+ settings: CmssyFormSettings | null;
134
+ }
135
+ interface CmssyFormSubmitResponse {
136
+ success: boolean;
137
+ message: string | null;
138
+ submissionId: string | null;
139
+ redirectUrl: string | null;
140
+ accessToken: string | null;
141
+ customer: unknown;
142
+ }
143
+ interface SubmitFormInput {
144
+ data: Record<string, unknown>;
145
+ website?: string;
146
+ }
147
+ declare const FORM_QUERY = "query PublicForm($formId: ID!) {\n publicForm(formId: $formId) {\n id\n name\n slug\n description\n fields {\n id name fieldType label placeholder helpText\n defaultValue options validation width order showIf\n }\n settings {\n actionType submitButtonLabel successMessage errorMessage\n redirectUrl requireLogin enableCaptcha\n }\n }\n}";
148
+ declare const SUBMIT_FORM_MUTATION = "mutation SubmitForm($formId: ID!, $input: SubmitFormInput!) {\n submitForm(formId: $formId, input: $input) {\n success message submissionId redirectUrl accessToken customer\n }\n}";
149
+
150
+ interface CmssyBlockProps {
151
+ block: RawBlock;
152
+ locale: string;
153
+ defaultLocale: string;
154
+ blockMap: BlockMap;
155
+ patchedContent?: Record<string, unknown>;
156
+ editable?: boolean;
157
+ layoutPosition?: string;
158
+ }
159
+ declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
160
+
161
+ interface UnknownBlockProps {
162
+ type: string;
163
+ }
164
+ declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
165
+
166
+ export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, type CmssyFormDefinition, type CmssyFormField, type CmssyFormSettings, type CmssyFormSubmitResponse, CmssyLayoutGroup, type CmssyModelDefinition, type CmssyModelRecord, CmssyPageData, type CmssyRecordList, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type CmssySiteConfig, EditorToAppMessage, FORM_QUERY, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, type PostTarget, type QueryScopedOptions, RawBlock, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, type SubmitFormInput, UnknownBlock, type UnknownBlockProps, createCmssyClient, fields, getBlockContentForLanguage, graphqlRequest, normalizeOrigin, parseEditorMessage, postToEditor };