@tecof/theme-editor 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tecof
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,212 @@
1
+ # @tecof/theme-editor
2
+
3
+ Tecof platform için Puck CMS tabanlı sayfa editörü ve render kütüphanesi. API client, context provider ve Puck wrapper bileşenleri içerir.
4
+
5
+ ## Kurulum
6
+
7
+ ```bash
8
+ npm install @tecof/theme-editor @puckeditor/core react react-dom
9
+ ```
10
+
11
+ ## Hızlı Başlangıç
12
+
13
+ ### 1. Puck Config Oluştur
14
+
15
+ ```tsx
16
+ // puck-config.tsx
17
+ import type { Config } from "@puckeditor/core";
18
+ import { Header } from "./components/puck/Header";
19
+ import { HeroSection } from "./components/puck/Hero";
20
+ import { Footer } from "./components/puck/Footer";
21
+
22
+ export const puckConfig: Config = {
23
+ components: {
24
+ Header,
25
+ HeroSection,
26
+ Footer,
27
+ },
28
+ };
29
+ ```
30
+
31
+ ### 2. Editör Sayfası
32
+
33
+ ```tsx
34
+ // app/editor/[slug]/page.tsx
35
+ "use client";
36
+
37
+ import { TecofProvider, TecofEditor } from "@tecof/theme-editor";
38
+ import "@tecof/theme-editor/styles.css";
39
+ import "@puckeditor/core/puck.css";
40
+ import { puckConfig } from "@/puck-config";
41
+
42
+ export default function EditorPage() {
43
+ return (
44
+ <TecofProvider
45
+ apiUrl="https://api.example.com"
46
+ accessToken="your-merchant-token"
47
+ config={puckConfig}
48
+ >
49
+ <TecofEditor
50
+ slug="home"
51
+ onSave={(data) => console.log("Saved:", data)}
52
+ />
53
+ </TecofProvider>
54
+ );
55
+ }
56
+ ```
57
+
58
+ ### 3. Public Sayfa (Render)
59
+
60
+ ```tsx
61
+ // app/[slug]/page.tsx
62
+ import { TecofProvider, TecofRender } from "@tecof/theme-editor";
63
+ import { puckConfig } from "@/puck-config";
64
+
65
+ export default function PublicPage() {
66
+ return (
67
+ <TecofProvider
68
+ apiUrl="https://api.example.com"
69
+ accessToken="your-merchant-token"
70
+ config={puckConfig}
71
+ >
72
+ <TecofRender slug="home" />
73
+ </TecofProvider>
74
+ );
75
+ }
76
+ ```
77
+
78
+ Direkt data ile de render edebilirsiniz:
79
+
80
+ ```tsx
81
+ <TecofRender data={puckData} />
82
+ ```
83
+
84
+ ## API
85
+
86
+ ### `<TecofProvider />`
87
+
88
+ Tüm Tecof bileşenlerini sarar, API client ve Puck config context'i sağlar.
89
+
90
+ | Prop | Tip | Açıklama |
91
+ |------|-----|----------|
92
+ | `apiUrl` | `string` | Backend API base URL |
93
+ | `accessToken` | `string` | Merchant access token |
94
+ | `config` | `Config` | Puck component configuration |
95
+ | `children` | `ReactNode` | Alt bileşenler |
96
+
97
+ ### `<TecofEditor />`
98
+
99
+ Puck `<Puck>` wrapper — sayfa editörü. Otomatik fetch/save ve iframe postMessage desteği.
100
+
101
+ | Prop | Tip | Açıklama |
102
+ |------|-----|----------|
103
+ | `slug` | `string` | Düzenlenecek sayfa slug'ı |
104
+ | `onSave` | `(data) => void` | Kayıt sonrası callback |
105
+ | `onPublish` | `(data) => void` | Yayınlama sonrası callback |
106
+ | `onChange` | `(data) => void` | Her değişiklikte callback |
107
+ | `overrides` | `object` | Puck UI override'ları |
108
+ | `plugins` | `any[]` | Ek Puck plugin'leri |
109
+ | `className` | `string` | CSS class |
110
+
111
+ ### `<TecofRender />`
112
+
113
+ Puck `<Render>` wrapper — yayınlanmış sayfaları render eder.
114
+
115
+ | Prop | Tip | Açıklama |
116
+ |------|-----|----------|
117
+ | `slug` | `string` | Sayfa slug'ı (otomatik fetch) |
118
+ | `data` | `PuckPageData` | Direkt puck data (fetch yapmaz) |
119
+ | `fallback` | `ReactNode` | Yükleme sırasında gösterilecek bileşen |
120
+ | `className` | `string` | CSS class |
121
+
122
+ ### `useTecof()`
123
+
124
+ Provider context'ine erişim hook'u:
125
+
126
+ ```tsx
127
+ const { apiClient, config, accessToken, apiUrl } = useTecof();
128
+ ```
129
+
130
+ ### `TecofApiClient`
131
+
132
+ Standalone API client:
133
+
134
+ ```tsx
135
+ import { TecofApiClient } from "@tecof/theme-editor";
136
+
137
+ const client = new TecofApiClient("https://api.example.com", "token");
138
+
139
+ // Sayfa draft'ını getir
140
+ const page = await client.getPage("home");
141
+
142
+ // Sayfa kaydet
143
+ await client.savePage("home", puckData);
144
+
145
+ // Yayınlanmış sayfayı getir
146
+ const published = await client.getPublishedPage("about");
147
+ ```
148
+
149
+ ### Utility Fonksiyonları
150
+
151
+ ```tsx
152
+ import {
153
+ getDefaultTheme,
154
+ generateCSSVariables,
155
+ mergeTheme,
156
+ hexToHsl,
157
+ hslToHex,
158
+ lighten,
159
+ darken,
160
+ } from "@tecof/theme-editor";
161
+ ```
162
+
163
+ | Fonksiyon | Açıklama |
164
+ |-----------|----------|
165
+ | `getDefaultTheme()` | Varsayılan tema config'i döner |
166
+ | `generateCSSVariables(theme)` | ThemeConfig → CSS custom properties |
167
+ | `mergeTheme(base, overrides)` | Tema config deep-merge |
168
+ | `hexToHsl(hex)` | Hex → HSL dönüşümü |
169
+ | `hslToHex(h, s, l)` | HSL → Hex dönüşümü |
170
+ | `lighten(hex, amount)` | Rengi açar |
171
+ | `darken(hex, amount)` | Rengi koyulaştırır |
172
+
173
+ ## iframe postMessage API
174
+
175
+ `TecofEditor` iframe içinde çalıştığında parent ile iletişim kurar:
176
+
177
+ ```ts
178
+ // Parent → Editor
179
+ iframe.postMessage({ type: "puck:publish" }, "*"); // Kaydet
180
+ iframe.postMessage({ type: "puck:undo" }, "*"); // Geri al
181
+ iframe.postMessage({ type: "puck:redo" }, "*"); // Yinele
182
+ iframe.postMessage({ type: "puck:viewport", width: "375px" }, "*"); // Viewport
183
+
184
+ // Editor → Parent
185
+ window.addEventListener("message", (e) => {
186
+ if (e.data.type === "puck:save") { /* değişiklik var */ }
187
+ if (e.data.type === "puck:saved") { /* başarıyla kaydedildi */ }
188
+ });
189
+ ```
190
+
191
+ ## Backend API Endpoints
192
+
193
+ Kütüphane aşağıdaki endpoint'leri kullanır (`Authorization` header ile):
194
+
195
+ | Method | Endpoint | Açıklama |
196
+ |--------|----------|----------|
197
+ | `GET` | `/api/store/page/:slug` | Sayfa draft'ını getir |
198
+ | `PUT` | `/api/store/page/:slug` | Sayfa draft'ını kaydet |
199
+ | `GET` | `/api/store/published/:slug` | Yayınlanmış sayfayı getir |
200
+
201
+ ## Geliştirme
202
+
203
+ ```bash
204
+ npm run dev # Watch mode
205
+ npm run build # Production build
206
+ npm run lint # ESLint
207
+ npm run test # Vitest
208
+ ```
209
+
210
+ ## Lisans
211
+
212
+ MIT
@@ -0,0 +1,170 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface ThemeColors {
4
+ primary: string;
5
+ secondary: string;
6
+ accent: string;
7
+ background: string;
8
+ foreground: string;
9
+ muted: string;
10
+ mutedForeground: string;
11
+ border: string;
12
+ card: string;
13
+ cardForeground: string;
14
+ destructive: string;
15
+ }
16
+ interface ThemeTypography {
17
+ fontFamily: string;
18
+ headingFontFamily: string;
19
+ baseFontSize: number;
20
+ lineHeight: number;
21
+ headingScale: {
22
+ h1: number;
23
+ h2: number;
24
+ h3: number;
25
+ h4: number;
26
+ h5: number;
27
+ h6: number;
28
+ };
29
+ fontWeightNormal: number;
30
+ fontWeightMedium: number;
31
+ fontWeightBold: number;
32
+ }
33
+ interface ThemeSpacing {
34
+ containerMaxWidth: number;
35
+ sectionPaddingY: number;
36
+ sectionPaddingX: number;
37
+ componentGap: number;
38
+ borderRadius: number;
39
+ borderRadiusLg: number;
40
+ borderRadiusSm: number;
41
+ }
42
+ interface ThemeConfig {
43
+ colors: ThemeColors;
44
+ typography: ThemeTypography;
45
+ spacing: ThemeSpacing;
46
+ customTokens?: Record<string, string>;
47
+ }
48
+ interface HSL {
49
+ h: number;
50
+ s: number;
51
+ l: number;
52
+ }
53
+ interface PuckContentItem {
54
+ type: string;
55
+ props: Record<string, any>;
56
+ }
57
+ interface PuckPageData {
58
+ content: PuckContentItem[];
59
+ root: {
60
+ props: Record<string, any>;
61
+ };
62
+ zones: Record<string, any>;
63
+ }
64
+ interface ApiResponse<T = any> {
65
+ success: boolean;
66
+ data?: T;
67
+ message?: string;
68
+ }
69
+ interface PageApiData {
70
+ _id?: string;
71
+ slug: string;
72
+ title?: string;
73
+ puckData: PuckPageData;
74
+ status?: string;
75
+ [key: string]: any;
76
+ }
77
+ interface TecofProviderProps {
78
+ /** Tecof backend API base URL */
79
+ apiUrl: string;
80
+ /** Merchant secret key */
81
+ secretKey: string;
82
+ /** React children */
83
+ children: React.ReactNode;
84
+ }
85
+ interface TecofEditorProps {
86
+ /** Page ID to load and edit */
87
+ pageId: string;
88
+ /** Puck component configuration (Config from @puckeditor/core) */
89
+ config: any;
90
+ /** Called after successful save */
91
+ onSave?: (data: PuckPageData) => void;
92
+ /** Called after successful publish */
93
+ onPublish?: (data: PuckPageData) => void;
94
+ /** Called on every editor change */
95
+ onChange?: (data: PuckPageData) => void;
96
+ /** Puck UI overrides */
97
+ overrides?: Record<string, any>;
98
+ /** Additional Puck plugins */
99
+ plugins?: any[];
100
+ /** Additional class name */
101
+ className?: string;
102
+ }
103
+ interface TecofRenderProps {
104
+ /** Pre-fetched puck data */
105
+ data: PuckPageData;
106
+ /** Puck component configuration (Config from @puckeditor/core) */
107
+ config: any;
108
+ /** Additional class name */
109
+ className?: string;
110
+ }
111
+
112
+ /**
113
+ * Tecof API Client — handles communication with the Tecof backend
114
+ * for page CRUD operations using merchant secret key.
115
+ *
116
+ * Endpoints:
117
+ * - GET /api/store/editor/:id → get page by ID
118
+ * - PUT /api/store/editor/:id → save page by ID
119
+ */
120
+ declare class TecofApiClient {
121
+ private apiUrl;
122
+ private secretKey;
123
+ constructor(apiUrl: string, secretKey: string);
124
+ private get headers();
125
+ /**
126
+ * Fetch a page by ID (for the editor)
127
+ */
128
+ getPage(pageId: string): Promise<ApiResponse<PageApiData>>;
129
+ /**
130
+ * Save a page by ID
131
+ */
132
+ savePage(pageId: string, puckData: PuckPageData, title?: string): Promise<ApiResponse<PageApiData>>;
133
+ }
134
+
135
+ interface TecofContextValue {
136
+ apiClient: TecofApiClient;
137
+ secretKey: string;
138
+ apiUrl: string;
139
+ }
140
+ declare const TecofProvider: ({ apiUrl, secretKey, children }: TecofProviderProps) => react_jsx_runtime.JSX.Element;
141
+ declare function useTecof(): TecofContextValue;
142
+
143
+ /**
144
+ * TecofEditor — Puck CMS page editor.
145
+ *
146
+ * - Fetches page by ID via secretKey auth
147
+ * - Saves on publish
148
+ * - Supports iframe postMessage (undo/redo/publish/viewport)
149
+ *
150
+ * Requires `<TecofProvider>` ancestor for API client.
151
+ */
152
+ declare const TecofEditor: ({ pageId, config, onSave, onPublish, onChange, overrides, plugins: extraPlugins, className, }: TecofEditorProps) => react_jsx_runtime.JSX.Element;
153
+
154
+ /**
155
+ * TecofRender — Puck page renderer.
156
+ *
157
+ * Pass `data` (PuckPageData) and `config` (Puck Config) directly.
158
+ * No API fetch, no provider required.
159
+ */
160
+ declare const TecofRender: ({ data, config, className }: TecofRenderProps) => react_jsx_runtime.JSX.Element | null;
161
+
162
+ declare function hexToHsl(hex: string): HSL;
163
+ declare function hslToHex(h: number, s: number, l: number): string;
164
+ declare function lighten(hex: string, amount: number): string;
165
+ declare function darken(hex: string, amount: number): string;
166
+ declare function generateCSSVariables(theme: ThemeConfig): string;
167
+ declare function getDefaultTheme(): ThemeConfig;
168
+ declare function mergeTheme(base: ThemeConfig, overrides: Partial<ThemeConfig>): ThemeConfig;
169
+
170
+ export { type ApiResponse, type HSL, type PageApiData, type PuckContentItem, type PuckPageData, TecofApiClient, TecofEditor, type TecofEditorProps, TecofProvider, type TecofProviderProps, TecofRender, type TecofRenderProps, type ThemeColors, type ThemeConfig, type ThemeSpacing, type ThemeTypography, darken, generateCSSVariables, getDefaultTheme, hexToHsl, hslToHex, lighten, mergeTheme, useTecof };
@@ -0,0 +1,170 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface ThemeColors {
4
+ primary: string;
5
+ secondary: string;
6
+ accent: string;
7
+ background: string;
8
+ foreground: string;
9
+ muted: string;
10
+ mutedForeground: string;
11
+ border: string;
12
+ card: string;
13
+ cardForeground: string;
14
+ destructive: string;
15
+ }
16
+ interface ThemeTypography {
17
+ fontFamily: string;
18
+ headingFontFamily: string;
19
+ baseFontSize: number;
20
+ lineHeight: number;
21
+ headingScale: {
22
+ h1: number;
23
+ h2: number;
24
+ h3: number;
25
+ h4: number;
26
+ h5: number;
27
+ h6: number;
28
+ };
29
+ fontWeightNormal: number;
30
+ fontWeightMedium: number;
31
+ fontWeightBold: number;
32
+ }
33
+ interface ThemeSpacing {
34
+ containerMaxWidth: number;
35
+ sectionPaddingY: number;
36
+ sectionPaddingX: number;
37
+ componentGap: number;
38
+ borderRadius: number;
39
+ borderRadiusLg: number;
40
+ borderRadiusSm: number;
41
+ }
42
+ interface ThemeConfig {
43
+ colors: ThemeColors;
44
+ typography: ThemeTypography;
45
+ spacing: ThemeSpacing;
46
+ customTokens?: Record<string, string>;
47
+ }
48
+ interface HSL {
49
+ h: number;
50
+ s: number;
51
+ l: number;
52
+ }
53
+ interface PuckContentItem {
54
+ type: string;
55
+ props: Record<string, any>;
56
+ }
57
+ interface PuckPageData {
58
+ content: PuckContentItem[];
59
+ root: {
60
+ props: Record<string, any>;
61
+ };
62
+ zones: Record<string, any>;
63
+ }
64
+ interface ApiResponse<T = any> {
65
+ success: boolean;
66
+ data?: T;
67
+ message?: string;
68
+ }
69
+ interface PageApiData {
70
+ _id?: string;
71
+ slug: string;
72
+ title?: string;
73
+ puckData: PuckPageData;
74
+ status?: string;
75
+ [key: string]: any;
76
+ }
77
+ interface TecofProviderProps {
78
+ /** Tecof backend API base URL */
79
+ apiUrl: string;
80
+ /** Merchant secret key */
81
+ secretKey: string;
82
+ /** React children */
83
+ children: React.ReactNode;
84
+ }
85
+ interface TecofEditorProps {
86
+ /** Page ID to load and edit */
87
+ pageId: string;
88
+ /** Puck component configuration (Config from @puckeditor/core) */
89
+ config: any;
90
+ /** Called after successful save */
91
+ onSave?: (data: PuckPageData) => void;
92
+ /** Called after successful publish */
93
+ onPublish?: (data: PuckPageData) => void;
94
+ /** Called on every editor change */
95
+ onChange?: (data: PuckPageData) => void;
96
+ /** Puck UI overrides */
97
+ overrides?: Record<string, any>;
98
+ /** Additional Puck plugins */
99
+ plugins?: any[];
100
+ /** Additional class name */
101
+ className?: string;
102
+ }
103
+ interface TecofRenderProps {
104
+ /** Pre-fetched puck data */
105
+ data: PuckPageData;
106
+ /** Puck component configuration (Config from @puckeditor/core) */
107
+ config: any;
108
+ /** Additional class name */
109
+ className?: string;
110
+ }
111
+
112
+ /**
113
+ * Tecof API Client — handles communication with the Tecof backend
114
+ * for page CRUD operations using merchant secret key.
115
+ *
116
+ * Endpoints:
117
+ * - GET /api/store/editor/:id → get page by ID
118
+ * - PUT /api/store/editor/:id → save page by ID
119
+ */
120
+ declare class TecofApiClient {
121
+ private apiUrl;
122
+ private secretKey;
123
+ constructor(apiUrl: string, secretKey: string);
124
+ private get headers();
125
+ /**
126
+ * Fetch a page by ID (for the editor)
127
+ */
128
+ getPage(pageId: string): Promise<ApiResponse<PageApiData>>;
129
+ /**
130
+ * Save a page by ID
131
+ */
132
+ savePage(pageId: string, puckData: PuckPageData, title?: string): Promise<ApiResponse<PageApiData>>;
133
+ }
134
+
135
+ interface TecofContextValue {
136
+ apiClient: TecofApiClient;
137
+ secretKey: string;
138
+ apiUrl: string;
139
+ }
140
+ declare const TecofProvider: ({ apiUrl, secretKey, children }: TecofProviderProps) => react_jsx_runtime.JSX.Element;
141
+ declare function useTecof(): TecofContextValue;
142
+
143
+ /**
144
+ * TecofEditor — Puck CMS page editor.
145
+ *
146
+ * - Fetches page by ID via secretKey auth
147
+ * - Saves on publish
148
+ * - Supports iframe postMessage (undo/redo/publish/viewport)
149
+ *
150
+ * Requires `<TecofProvider>` ancestor for API client.
151
+ */
152
+ declare const TecofEditor: ({ pageId, config, onSave, onPublish, onChange, overrides, plugins: extraPlugins, className, }: TecofEditorProps) => react_jsx_runtime.JSX.Element;
153
+
154
+ /**
155
+ * TecofRender — Puck page renderer.
156
+ *
157
+ * Pass `data` (PuckPageData) and `config` (Puck Config) directly.
158
+ * No API fetch, no provider required.
159
+ */
160
+ declare const TecofRender: ({ data, config, className }: TecofRenderProps) => react_jsx_runtime.JSX.Element | null;
161
+
162
+ declare function hexToHsl(hex: string): HSL;
163
+ declare function hslToHex(h: number, s: number, l: number): string;
164
+ declare function lighten(hex: string, amount: number): string;
165
+ declare function darken(hex: string, amount: number): string;
166
+ declare function generateCSSVariables(theme: ThemeConfig): string;
167
+ declare function getDefaultTheme(): ThemeConfig;
168
+ declare function mergeTheme(base: ThemeConfig, overrides: Partial<ThemeConfig>): ThemeConfig;
169
+
170
+ export { type ApiResponse, type HSL, type PageApiData, type PuckContentItem, type PuckPageData, TecofApiClient, TecofEditor, type TecofEditorProps, TecofProvider, type TecofProviderProps, TecofRender, type TecofRenderProps, type ThemeColors, type ThemeConfig, type ThemeSpacing, type ThemeTypography, darken, generateCSSVariables, getDefaultTheme, hexToHsl, hslToHex, lighten, mergeTheme, useTecof };