@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/client.cjs +696 -0
- package/dist/client.d.cts +77 -0
- package/dist/client.d.ts +77 -0
- package/dist/client.js +690 -0
- package/dist/index.cjs +529 -0
- package/dist/index.d.cts +166 -0
- package/dist/index.d.ts +166 -0
- package/dist/index.js +503 -0
- package/dist/registry-BoxAyw4_.d.cts +189 -0
- package/dist/registry-BoxAyw4_.d.ts +189 -0
- package/package.json +47 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
interface CmssyClientConfig {
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
workspaceSlug: string;
|
|
6
|
+
}
|
|
7
|
+
interface FetchLikeResponse {
|
|
8
|
+
ok: boolean;
|
|
9
|
+
status: number;
|
|
10
|
+
json: () => Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
type FetchLike = (url: string, init: {
|
|
13
|
+
method: string;
|
|
14
|
+
headers: Record<string, string>;
|
|
15
|
+
body: string;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}) => Promise<FetchLikeResponse>;
|
|
18
|
+
interface FetchPageOptions {
|
|
19
|
+
previewSecret?: string;
|
|
20
|
+
fetch?: FetchLike;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
interface RawBlock {
|
|
24
|
+
id: string;
|
|
25
|
+
type: string;
|
|
26
|
+
content: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface CmssyPageData {
|
|
29
|
+
id: string;
|
|
30
|
+
blocks: RawBlock[];
|
|
31
|
+
}
|
|
32
|
+
interface RawLayoutBlock {
|
|
33
|
+
id: string;
|
|
34
|
+
type: string;
|
|
35
|
+
content: unknown;
|
|
36
|
+
order: number;
|
|
37
|
+
isActive: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface CmssyLayoutGroup {
|
|
40
|
+
position: string;
|
|
41
|
+
blocks: RawLayoutBlock[];
|
|
42
|
+
}
|
|
43
|
+
declare function normalizeSlug(path: string | string[] | undefined): string;
|
|
44
|
+
declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
|
|
45
|
+
declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
|
|
46
|
+
|
|
47
|
+
declare const PROTOCOL_VERSION = 1;
|
|
48
|
+
type FieldType = "singleLine" | "multiLine" | "richText" | "numeric" | "date" | "media" | "link" | "select" | "multiselect" | "boolean" | "color" | "repeater";
|
|
49
|
+
interface FieldDefinition {
|
|
50
|
+
type: FieldType;
|
|
51
|
+
label: string;
|
|
52
|
+
defaultValue?: unknown;
|
|
53
|
+
helperText?: string;
|
|
54
|
+
required?: boolean;
|
|
55
|
+
placeholder?: string;
|
|
56
|
+
options?: string[];
|
|
57
|
+
itemSchema?: Record<string, FieldDefinition>;
|
|
58
|
+
itemLabel?: string;
|
|
59
|
+
addButtonLabel?: string;
|
|
60
|
+
minItems?: number;
|
|
61
|
+
maxItems?: number;
|
|
62
|
+
collapsible?: boolean;
|
|
63
|
+
}
|
|
64
|
+
type BlockSchema = Record<string, FieldDefinition>;
|
|
65
|
+
interface BlockMeta {
|
|
66
|
+
label: string;
|
|
67
|
+
category?: string;
|
|
68
|
+
icon?: string;
|
|
69
|
+
layoutPositions?: string[];
|
|
70
|
+
}
|
|
71
|
+
interface BlockRect {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
}
|
|
77
|
+
interface ReadyMessage {
|
|
78
|
+
type: "cmssy:ready";
|
|
79
|
+
protocolVersion: number;
|
|
80
|
+
blocks: Array<{
|
|
81
|
+
id: string;
|
|
82
|
+
type: string;
|
|
83
|
+
bounds: BlockRect;
|
|
84
|
+
layoutPosition?: string;
|
|
85
|
+
}>;
|
|
86
|
+
schemas: Record<string, BlockSchema>;
|
|
87
|
+
blockMeta?: Record<string, BlockMeta>;
|
|
88
|
+
}
|
|
89
|
+
interface BoundsMessage {
|
|
90
|
+
type: "cmssy:bounds";
|
|
91
|
+
blockId: string;
|
|
92
|
+
rect: BlockRect;
|
|
93
|
+
}
|
|
94
|
+
interface ClickMessage {
|
|
95
|
+
type: "cmssy:click";
|
|
96
|
+
blockId: string;
|
|
97
|
+
rect: BlockRect;
|
|
98
|
+
layoutPosition?: string;
|
|
99
|
+
}
|
|
100
|
+
interface MoveMessage {
|
|
101
|
+
type: "cmssy:move";
|
|
102
|
+
protocolVersion: number;
|
|
103
|
+
blockId: string;
|
|
104
|
+
index: number;
|
|
105
|
+
}
|
|
106
|
+
interface DragIndexMessage {
|
|
107
|
+
type: "cmssy:drag-index";
|
|
108
|
+
protocolVersion: number;
|
|
109
|
+
index: number;
|
|
110
|
+
}
|
|
111
|
+
type AppToEditorMessage = ReadyMessage | BoundsMessage | ClickMessage | MoveMessage | DragIndexMessage;
|
|
112
|
+
interface SelectMessage {
|
|
113
|
+
type: "cmssy:select";
|
|
114
|
+
protocolVersion: number;
|
|
115
|
+
blockId: string;
|
|
116
|
+
}
|
|
117
|
+
interface PatchMessage {
|
|
118
|
+
type: "cmssy:patch";
|
|
119
|
+
protocolVersion: number;
|
|
120
|
+
blockId: string;
|
|
121
|
+
content: Record<string, unknown>;
|
|
122
|
+
layoutPosition?: string;
|
|
123
|
+
}
|
|
124
|
+
interface ParentReadyMessage {
|
|
125
|
+
type: "cmssy:parent-ready";
|
|
126
|
+
protocolVersion: number;
|
|
127
|
+
}
|
|
128
|
+
interface InsertMessage {
|
|
129
|
+
type: "cmssy:insert";
|
|
130
|
+
protocolVersion: number;
|
|
131
|
+
blockId: string;
|
|
132
|
+
blockType: string;
|
|
133
|
+
content: Record<string, unknown>;
|
|
134
|
+
index: number;
|
|
135
|
+
}
|
|
136
|
+
interface ReorderMessage {
|
|
137
|
+
type: "cmssy:reorder";
|
|
138
|
+
protocolVersion: number;
|
|
139
|
+
blockIds: string[];
|
|
140
|
+
}
|
|
141
|
+
interface RemoveMessage {
|
|
142
|
+
type: "cmssy:remove";
|
|
143
|
+
protocolVersion: number;
|
|
144
|
+
blockId: string;
|
|
145
|
+
}
|
|
146
|
+
interface DragOverMessage {
|
|
147
|
+
type: "cmssy:drag-over";
|
|
148
|
+
protocolVersion: number;
|
|
149
|
+
y: number;
|
|
150
|
+
}
|
|
151
|
+
interface DragEndMessage {
|
|
152
|
+
type: "cmssy:drag-end";
|
|
153
|
+
protocolVersion: number;
|
|
154
|
+
}
|
|
155
|
+
type EditorToAppMessage = SelectMessage | PatchMessage | ParentReadyMessage | InsertMessage | ReorderMessage | RemoveMessage | DragOverMessage | DragEndMessage;
|
|
156
|
+
declare function isProtocolCompatible(version: number): boolean;
|
|
157
|
+
|
|
158
|
+
interface BlockDefinition {
|
|
159
|
+
type: string;
|
|
160
|
+
label?: string;
|
|
161
|
+
category?: string;
|
|
162
|
+
icon?: string;
|
|
163
|
+
layoutPositions?: string[];
|
|
164
|
+
props: Record<string, FieldDefinition>;
|
|
165
|
+
component: ComponentType<{
|
|
166
|
+
content: Record<string, unknown>;
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
declare function defineBlock<C extends Record<string, unknown>>(def: {
|
|
170
|
+
type: string;
|
|
171
|
+
label?: string;
|
|
172
|
+
category?: string;
|
|
173
|
+
icon?: string;
|
|
174
|
+
layoutPositions?: string[];
|
|
175
|
+
props: Record<string, FieldDefinition>;
|
|
176
|
+
component: ComponentType<{
|
|
177
|
+
content: C;
|
|
178
|
+
}>;
|
|
179
|
+
}): BlockDefinition;
|
|
180
|
+
type BlockMap = Record<string, ComponentType<{
|
|
181
|
+
content: Record<string, unknown>;
|
|
182
|
+
}>>;
|
|
183
|
+
declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
|
|
184
|
+
declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
|
|
185
|
+
declare function blocksToMeta(blocks: BlockDefinition[], defaults?: {
|
|
186
|
+
category?: string;
|
|
187
|
+
}): Record<string, BlockMeta>;
|
|
188
|
+
|
|
189
|
+
export { type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type EditorToAppMessage as E, type FieldDefinition as F, PROTOCOL_VERSION as P, type RawBlock as R, type SelectMessage as S, type BlockMeta as a, type BlockDefinition as b, type CmssyLayoutGroup as c, type FetchLike as d, type CmssyClientConfig as e, type BlockMap as f, type BlockRect as g, type BoundsMessage as h, type ClickMessage as i, type FetchLikeResponse as j, type FetchPageOptions as k, type FieldType as l, type ParentReadyMessage as m, type PatchMessage as n, type RawLayoutBlock as o, type ReadyMessage as p, blocksToMeta as q, blocksToSchemas as r, buildBlockMap as s, defineBlock as t, fetchLayouts as u, fetchPage as v, isProtocolCompatible as w, normalizeSlug as x };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
interface CmssyClientConfig {
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
workspaceSlug: string;
|
|
6
|
+
}
|
|
7
|
+
interface FetchLikeResponse {
|
|
8
|
+
ok: boolean;
|
|
9
|
+
status: number;
|
|
10
|
+
json: () => Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
type FetchLike = (url: string, init: {
|
|
13
|
+
method: string;
|
|
14
|
+
headers: Record<string, string>;
|
|
15
|
+
body: string;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}) => Promise<FetchLikeResponse>;
|
|
18
|
+
interface FetchPageOptions {
|
|
19
|
+
previewSecret?: string;
|
|
20
|
+
fetch?: FetchLike;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
interface RawBlock {
|
|
24
|
+
id: string;
|
|
25
|
+
type: string;
|
|
26
|
+
content: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface CmssyPageData {
|
|
29
|
+
id: string;
|
|
30
|
+
blocks: RawBlock[];
|
|
31
|
+
}
|
|
32
|
+
interface RawLayoutBlock {
|
|
33
|
+
id: string;
|
|
34
|
+
type: string;
|
|
35
|
+
content: unknown;
|
|
36
|
+
order: number;
|
|
37
|
+
isActive: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface CmssyLayoutGroup {
|
|
40
|
+
position: string;
|
|
41
|
+
blocks: RawLayoutBlock[];
|
|
42
|
+
}
|
|
43
|
+
declare function normalizeSlug(path: string | string[] | undefined): string;
|
|
44
|
+
declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
|
|
45
|
+
declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
|
|
46
|
+
|
|
47
|
+
declare const PROTOCOL_VERSION = 1;
|
|
48
|
+
type FieldType = "singleLine" | "multiLine" | "richText" | "numeric" | "date" | "media" | "link" | "select" | "multiselect" | "boolean" | "color" | "repeater";
|
|
49
|
+
interface FieldDefinition {
|
|
50
|
+
type: FieldType;
|
|
51
|
+
label: string;
|
|
52
|
+
defaultValue?: unknown;
|
|
53
|
+
helperText?: string;
|
|
54
|
+
required?: boolean;
|
|
55
|
+
placeholder?: string;
|
|
56
|
+
options?: string[];
|
|
57
|
+
itemSchema?: Record<string, FieldDefinition>;
|
|
58
|
+
itemLabel?: string;
|
|
59
|
+
addButtonLabel?: string;
|
|
60
|
+
minItems?: number;
|
|
61
|
+
maxItems?: number;
|
|
62
|
+
collapsible?: boolean;
|
|
63
|
+
}
|
|
64
|
+
type BlockSchema = Record<string, FieldDefinition>;
|
|
65
|
+
interface BlockMeta {
|
|
66
|
+
label: string;
|
|
67
|
+
category?: string;
|
|
68
|
+
icon?: string;
|
|
69
|
+
layoutPositions?: string[];
|
|
70
|
+
}
|
|
71
|
+
interface BlockRect {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
}
|
|
77
|
+
interface ReadyMessage {
|
|
78
|
+
type: "cmssy:ready";
|
|
79
|
+
protocolVersion: number;
|
|
80
|
+
blocks: Array<{
|
|
81
|
+
id: string;
|
|
82
|
+
type: string;
|
|
83
|
+
bounds: BlockRect;
|
|
84
|
+
layoutPosition?: string;
|
|
85
|
+
}>;
|
|
86
|
+
schemas: Record<string, BlockSchema>;
|
|
87
|
+
blockMeta?: Record<string, BlockMeta>;
|
|
88
|
+
}
|
|
89
|
+
interface BoundsMessage {
|
|
90
|
+
type: "cmssy:bounds";
|
|
91
|
+
blockId: string;
|
|
92
|
+
rect: BlockRect;
|
|
93
|
+
}
|
|
94
|
+
interface ClickMessage {
|
|
95
|
+
type: "cmssy:click";
|
|
96
|
+
blockId: string;
|
|
97
|
+
rect: BlockRect;
|
|
98
|
+
layoutPosition?: string;
|
|
99
|
+
}
|
|
100
|
+
interface MoveMessage {
|
|
101
|
+
type: "cmssy:move";
|
|
102
|
+
protocolVersion: number;
|
|
103
|
+
blockId: string;
|
|
104
|
+
index: number;
|
|
105
|
+
}
|
|
106
|
+
interface DragIndexMessage {
|
|
107
|
+
type: "cmssy:drag-index";
|
|
108
|
+
protocolVersion: number;
|
|
109
|
+
index: number;
|
|
110
|
+
}
|
|
111
|
+
type AppToEditorMessage = ReadyMessage | BoundsMessage | ClickMessage | MoveMessage | DragIndexMessage;
|
|
112
|
+
interface SelectMessage {
|
|
113
|
+
type: "cmssy:select";
|
|
114
|
+
protocolVersion: number;
|
|
115
|
+
blockId: string;
|
|
116
|
+
}
|
|
117
|
+
interface PatchMessage {
|
|
118
|
+
type: "cmssy:patch";
|
|
119
|
+
protocolVersion: number;
|
|
120
|
+
blockId: string;
|
|
121
|
+
content: Record<string, unknown>;
|
|
122
|
+
layoutPosition?: string;
|
|
123
|
+
}
|
|
124
|
+
interface ParentReadyMessage {
|
|
125
|
+
type: "cmssy:parent-ready";
|
|
126
|
+
protocolVersion: number;
|
|
127
|
+
}
|
|
128
|
+
interface InsertMessage {
|
|
129
|
+
type: "cmssy:insert";
|
|
130
|
+
protocolVersion: number;
|
|
131
|
+
blockId: string;
|
|
132
|
+
blockType: string;
|
|
133
|
+
content: Record<string, unknown>;
|
|
134
|
+
index: number;
|
|
135
|
+
}
|
|
136
|
+
interface ReorderMessage {
|
|
137
|
+
type: "cmssy:reorder";
|
|
138
|
+
protocolVersion: number;
|
|
139
|
+
blockIds: string[];
|
|
140
|
+
}
|
|
141
|
+
interface RemoveMessage {
|
|
142
|
+
type: "cmssy:remove";
|
|
143
|
+
protocolVersion: number;
|
|
144
|
+
blockId: string;
|
|
145
|
+
}
|
|
146
|
+
interface DragOverMessage {
|
|
147
|
+
type: "cmssy:drag-over";
|
|
148
|
+
protocolVersion: number;
|
|
149
|
+
y: number;
|
|
150
|
+
}
|
|
151
|
+
interface DragEndMessage {
|
|
152
|
+
type: "cmssy:drag-end";
|
|
153
|
+
protocolVersion: number;
|
|
154
|
+
}
|
|
155
|
+
type EditorToAppMessage = SelectMessage | PatchMessage | ParentReadyMessage | InsertMessage | ReorderMessage | RemoveMessage | DragOverMessage | DragEndMessage;
|
|
156
|
+
declare function isProtocolCompatible(version: number): boolean;
|
|
157
|
+
|
|
158
|
+
interface BlockDefinition {
|
|
159
|
+
type: string;
|
|
160
|
+
label?: string;
|
|
161
|
+
category?: string;
|
|
162
|
+
icon?: string;
|
|
163
|
+
layoutPositions?: string[];
|
|
164
|
+
props: Record<string, FieldDefinition>;
|
|
165
|
+
component: ComponentType<{
|
|
166
|
+
content: Record<string, unknown>;
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
declare function defineBlock<C extends Record<string, unknown>>(def: {
|
|
170
|
+
type: string;
|
|
171
|
+
label?: string;
|
|
172
|
+
category?: string;
|
|
173
|
+
icon?: string;
|
|
174
|
+
layoutPositions?: string[];
|
|
175
|
+
props: Record<string, FieldDefinition>;
|
|
176
|
+
component: ComponentType<{
|
|
177
|
+
content: C;
|
|
178
|
+
}>;
|
|
179
|
+
}): BlockDefinition;
|
|
180
|
+
type BlockMap = Record<string, ComponentType<{
|
|
181
|
+
content: Record<string, unknown>;
|
|
182
|
+
}>>;
|
|
183
|
+
declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
|
|
184
|
+
declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
|
|
185
|
+
declare function blocksToMeta(blocks: BlockDefinition[], defaults?: {
|
|
186
|
+
category?: string;
|
|
187
|
+
}): Record<string, BlockMeta>;
|
|
188
|
+
|
|
189
|
+
export { type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type EditorToAppMessage as E, type FieldDefinition as F, PROTOCOL_VERSION as P, type RawBlock as R, type SelectMessage as S, type BlockMeta as a, type BlockDefinition as b, type CmssyLayoutGroup as c, type FetchLike as d, type CmssyClientConfig as e, type BlockMap as f, type BlockRect as g, type BoundsMessage as h, type ClickMessage as i, type FetchLikeResponse as j, type FetchPageOptions as k, type FieldType as l, type ParentReadyMessage as m, type PatchMessage as n, type RawLayoutBlock as o, type ReadyMessage as p, blocksToMeta as q, blocksToSchemas as r, buildBlockMap as s, defineBlock as t, fetchLayouts as u, fetchPage as v, isProtocolCompatible as w, normalizeSlug as x };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cmssy/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./client": {
|
|
17
|
+
"types": "./dist/client.d.ts",
|
|
18
|
+
"import": "./dist/client.js",
|
|
19
|
+
"require": "./dist/client.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^18.2.0 || ^19.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@testing-library/react": "^16.1.0",
|
|
33
|
+
"@types/react": "^19.0.0",
|
|
34
|
+
"@types/react-dom": "^19.0.0",
|
|
35
|
+
"jsdom": "^25.0.0",
|
|
36
|
+
"react": "^19.0.0",
|
|
37
|
+
"react-dom": "^19.0.0",
|
|
38
|
+
"tsup": "^8.3.0",
|
|
39
|
+
"typescript": "^5.6.0",
|
|
40
|
+
"vitest": "^2.1.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"typecheck": "tsc --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|