@tecof/theme-editor 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -170,6 +170,45 @@ import {
170
170
  | `lighten(hex, amount)` | Rengi açar |
171
171
  | `darken(hex, amount)` | Rengi koyulaştırır |
172
172
 
173
+ ## Custom Fields (Özel Alanlar)
174
+
175
+ Kütüphane içinde Tecof platformuna özel olarak hazırlanmış gelişmiş Puck alanları (`fields`) bulunmaktadır:
176
+
177
+ | Alan Adı | Özellikler |
178
+ |----------|------------|
179
+ | **`LanguageField`** | Çok dilli, sekmeli düz metin girişi. Uygulama ayarlarından tanımlı dilleri otomatik çeker. |
180
+ | **`EditorField`** | Çok dilli, zengin metin editörü (TipTap tabanlı). Bold, italic, link, liste gibi temel araç çubuğuna sahiptir. |
181
+ | **`UploadField`** | FilePond ve Vaul Drawer tabanlı medya yöneticisi. Yeni görsel yükleme ve sunucudaki eski medyaları seçme yeteneğine sahiptir. |
182
+ | **`CodeEditorField`** | Monaco Editor tabanlı kod editörü. HTML, CSS, JSON gibi özel kod alanları eklemek için kullanılır. |
183
+
184
+ **Örnek Kullanım:**
185
+
186
+ ```tsx
187
+ import {
188
+ createLanguageField,
189
+ createEditorField,
190
+ createUploadField,
191
+ createCodeEditorField
192
+ } from "@tecof/theme-editor";
193
+
194
+ const myComponent = {
195
+ fields: {
196
+ title: createLanguageField({ label: "Başlık" }),
197
+ content: createEditorField({ label: "İçerik" }),
198
+ images: createUploadField({
199
+ label: "Görseller",
200
+ allowMultiple: true,
201
+ maxFiles: 5
202
+ }),
203
+ customHtml: createCodeEditorField({
204
+ label: "Özel Kod",
205
+ defaultLanguage: "html"
206
+ })
207
+ },
208
+ // ...
209
+ };
210
+ ```
211
+
173
212
  ## iframe postMessage API
174
213
 
175
214
  `TecofEditor` iframe içinde çalıştığında parent ile iletişim kurar:
package/dist/index.d.mts CHANGED
@@ -1,4 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import react__default from 'react';
2
4
 
3
5
  interface ThemeColors {
4
6
  primary: string;
@@ -108,6 +110,32 @@ interface TecofRenderProps {
108
110
  /** Additional class name */
109
111
  className?: string;
110
112
  }
113
+ interface MerchantInfoData {
114
+ /** Available language codes (e.g. ["tr", "en", "de"]) */
115
+ languages: string[];
116
+ /** Default language code (e.g. "tr") */
117
+ defaultLanguage: string;
118
+ }
119
+ interface LanguageFieldValue {
120
+ code: string;
121
+ value: string;
122
+ }
123
+ interface UploadedFile {
124
+ _id: string;
125
+ name: string;
126
+ size: number;
127
+ type: string;
128
+ mimeType?: string;
129
+ meta?: {
130
+ width?: number;
131
+ height?: number;
132
+ webp?: string;
133
+ thumbnail?: string;
134
+ medium?: string;
135
+ large?: string;
136
+ [key: string]: any;
137
+ };
138
+ }
111
139
 
112
140
  /**
113
141
  * Tecof API Client — handles communication with the Tecof backend
@@ -116,6 +144,7 @@ interface TecofRenderProps {
116
144
  * Endpoints:
117
145
  * - GET /api/store/editor/:id → get page by ID
118
146
  * - PUT /api/store/editor/:id → save page by ID
147
+ * - GET /api/store/merchant-info → get merchant language config
119
148
  */
120
149
  declare class TecofApiClient {
121
150
  private apiUrl;
@@ -134,6 +163,21 @@ declare class TecofApiClient {
134
163
  * Fetch a published page by slug + locale (for rendering)
135
164
  */
136
165
  getPublishedPage(slug: string, locale?: string): Promise<ApiResponse<PageApiData>>;
166
+ /**
167
+ * Fetch merchant language config (for editor fields)
168
+ */
169
+ getMerchantInfo(): Promise<ApiResponse<MerchantInfoData>>;
170
+ /**
171
+ * Upload files via secretKey auth (for editor fields)
172
+ * Returns array of file records: [{ _id, name, size, type, meta }]
173
+ */
174
+ uploadFile(file: File, folder?: string): Promise<ApiResponse<any[]>>;
175
+ /**
176
+ * Fetch previously uploaded files (for media library selector)
177
+ */
178
+ getUploads(page?: number, limit?: number): Promise<ApiResponse<any[]>>;
179
+ /** CDN base URL (derived from apiUrl) */
180
+ get cdnUrl(): string;
137
181
  }
138
182
 
139
183
  interface TecofContextValue {
@@ -171,6 +215,153 @@ declare const TecofEditor: ({ pageId, config, accessToken, onSave, onChange, ove
171
215
  */
172
216
  declare const TecofRender: ({ data, config, className }: TecofRenderProps) => react_jsx_runtime.JSX.Element | null;
173
217
 
218
+ interface LanguageFieldProps {
219
+ field: any;
220
+ name: string;
221
+ id: string;
222
+ value: LanguageFieldValue[];
223
+ onChange: (value: LanguageFieldValue[]) => void;
224
+ readOnly?: boolean;
225
+ }
226
+ interface LanguageFieldOptions {
227
+ /** Whether to render as textarea instead of input */
228
+ isTextarea?: boolean;
229
+ /** Number of rows for textarea mode */
230
+ textareaRows?: number;
231
+ /** Placeholder text */
232
+ placeholder?: string;
233
+ }
234
+ declare const LanguageField: ({ value, onChange, readOnly, isTextarea, textareaRows, placeholder, }: LanguageFieldProps & LanguageFieldOptions) => react_jsx_runtime.JSX.Element | null;
235
+ declare const createLanguageField: (options?: LanguageFieldOptions & {
236
+ label?: string;
237
+ }) => {
238
+ type: "custom";
239
+ label: string | undefined;
240
+ render: ({ value, onChange, readOnly, field, name, id }: LanguageFieldProps) => react_jsx_runtime.JSX.Element;
241
+ };
242
+
243
+ interface EditorFieldProps {
244
+ field: any;
245
+ name: string;
246
+ id: string;
247
+ value: LanguageFieldValue[];
248
+ onChange: (value: LanguageFieldValue[]) => void;
249
+ readOnly?: boolean;
250
+ }
251
+ interface EditorFieldOptions {
252
+ /** Placeholder text for empty editor */
253
+ placeholder?: string;
254
+ }
255
+ /**
256
+ * EditorField — A multilingual TipTap rich text editor field for Puck.
257
+ *
258
+ * Uses the same language tab system as LanguageField, but renders a
259
+ * TipTap editor with toolbar (bold, italic, underline, headings, lists,
260
+ * alignment, links, blockquote, undo/redo) instead of a plain text input.
261
+ *
262
+ * Value format: [{ code: "tr", value: "<p>HTML content</p>" }, ...]
263
+ */
264
+ declare const EditorField: ({ value, onChange, readOnly, }: EditorFieldProps & EditorFieldOptions) => react_jsx_runtime.JSX.Element | null;
265
+ /**
266
+ * Creates a Puck custom field definition for multilingual rich text (TipTap) editor.
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * import { createEditorField } from '@tecof/theme-editor';
271
+ *
272
+ * const config = {
273
+ * components: {
274
+ * TextBlock: {
275
+ * fields: {
276
+ * content: createEditorField({ label: 'İçerik' }),
277
+ * },
278
+ * defaultProps: { content: [] },
279
+ * render: ({ content }) => { ... },
280
+ * },
281
+ * },
282
+ * };
283
+ * ```
284
+ */
285
+ declare const createEditorField: (options?: EditorFieldOptions & {
286
+ label?: string;
287
+ }) => {
288
+ type: "custom";
289
+ label: string | undefined;
290
+ render: ({ value, onChange, readOnly, field, name, id }: EditorFieldProps) => react_jsx_runtime.JSX.Element;
291
+ };
292
+
293
+ interface UploadFieldProps {
294
+ field: any;
295
+ name: string;
296
+ id: string;
297
+ value: UploadedFile[];
298
+ onChange: (value: UploadedFile[]) => void;
299
+ readOnly?: boolean;
300
+ }
301
+ interface UploadFieldOptions {
302
+ allowMultiple?: boolean;
303
+ maxFiles?: number;
304
+ acceptedTypes?: string[];
305
+ maxFileSize?: string;
306
+ folder?: string;
307
+ label?: string;
308
+ }
309
+ declare const UploadField: react.ForwardRefExoticComponent<UploadFieldProps & UploadFieldOptions & react.RefAttributes<any>>;
310
+ declare const createUploadField: (options?: UploadFieldOptions) => {
311
+ type: "custom";
312
+ label: string | undefined;
313
+ render: ({ value, onChange, readOnly, field, name, id }: UploadFieldProps) => react_jsx_runtime.JSX.Element;
314
+ };
315
+
316
+ interface CodeEditorFieldProps {
317
+ field: any;
318
+ name: string;
319
+ id: string;
320
+ value: string;
321
+ onChange: (value: string) => void;
322
+ readOnly?: boolean;
323
+ }
324
+ interface CodeEditorFieldOptions {
325
+ label?: string;
326
+ defaultLanguage?: string;
327
+ height?: string;
328
+ theme?: string;
329
+ }
330
+ /**
331
+ * CodeEditorField — A code editor custom field for Puck.
332
+ * Uses Monaco Editor (@monaco-editor/react).
333
+ */
334
+ declare const CodeEditorField: react__default.ForwardRefExoticComponent<CodeEditorFieldProps & CodeEditorFieldOptions & react__default.RefAttributes<any>>;
335
+ /**
336
+ * Creates a Puck custom field definition for code editing.
337
+ *
338
+ * @example
339
+ * ```ts
340
+ * import { createCodeEditorField } from '@tecof/theme-editor';
341
+ *
342
+ * const config = {
343
+ * components: {
344
+ * CustomHero: {
345
+ * fields: {
346
+ * customHtml: createCodeEditorField({
347
+ * label: 'Özel HTML Kodu',
348
+ * defaultLanguage: 'html',
349
+ * height: '400px',
350
+ * }),
351
+ * },
352
+ * defaultProps: { customHtml: '' },
353
+ * render: ({ customHtml }) => <div dangerouslySetInnerHTML={{ __html: customHtml }} />,
354
+ * },
355
+ * },
356
+ * };
357
+ * ```
358
+ */
359
+ declare const createCodeEditorField: (options?: CodeEditorFieldOptions) => {
360
+ type: "custom";
361
+ label: string | undefined;
362
+ render: ({ value, onChange, readOnly, field, name, id }: CodeEditorFieldProps) => react_jsx_runtime.JSX.Element;
363
+ };
364
+
174
365
  declare function hexToHsl(hex: string): HSL;
175
366
  declare function hslToHex(h: number, s: number, l: number): string;
176
367
  declare function lighten(hex: string, amount: number): string;
@@ -179,4 +370,4 @@ declare function generateCSSVariables(theme: ThemeConfig): string;
179
370
  declare function getDefaultTheme(): ThemeConfig;
180
371
  declare function mergeTheme(base: ThemeConfig, overrides: Partial<ThemeConfig>): ThemeConfig;
181
372
 
182
- 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 };
373
+ export { type ApiResponse, CodeEditorField, EditorField, type HSL, LanguageField, type LanguageFieldValue, type MerchantInfoData, type PageApiData, type PuckContentItem, type PuckPageData, TecofApiClient, TecofEditor, type TecofEditorProps, TecofProvider, type TecofProviderProps, TecofRender, type TecofRenderProps, type ThemeColors, type ThemeConfig, type ThemeSpacing, type ThemeTypography, UploadField, type UploadedFile, createCodeEditorField, createEditorField, createLanguageField, createUploadField, darken, generateCSSVariables, getDefaultTheme, hexToHsl, hslToHex, lighten, mergeTheme, useTecof };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import react__default from 'react';
2
4
 
3
5
  interface ThemeColors {
4
6
  primary: string;
@@ -108,6 +110,32 @@ interface TecofRenderProps {
108
110
  /** Additional class name */
109
111
  className?: string;
110
112
  }
113
+ interface MerchantInfoData {
114
+ /** Available language codes (e.g. ["tr", "en", "de"]) */
115
+ languages: string[];
116
+ /** Default language code (e.g. "tr") */
117
+ defaultLanguage: string;
118
+ }
119
+ interface LanguageFieldValue {
120
+ code: string;
121
+ value: string;
122
+ }
123
+ interface UploadedFile {
124
+ _id: string;
125
+ name: string;
126
+ size: number;
127
+ type: string;
128
+ mimeType?: string;
129
+ meta?: {
130
+ width?: number;
131
+ height?: number;
132
+ webp?: string;
133
+ thumbnail?: string;
134
+ medium?: string;
135
+ large?: string;
136
+ [key: string]: any;
137
+ };
138
+ }
111
139
 
112
140
  /**
113
141
  * Tecof API Client — handles communication with the Tecof backend
@@ -116,6 +144,7 @@ interface TecofRenderProps {
116
144
  * Endpoints:
117
145
  * - GET /api/store/editor/:id → get page by ID
118
146
  * - PUT /api/store/editor/:id → save page by ID
147
+ * - GET /api/store/merchant-info → get merchant language config
119
148
  */
120
149
  declare class TecofApiClient {
121
150
  private apiUrl;
@@ -134,6 +163,21 @@ declare class TecofApiClient {
134
163
  * Fetch a published page by slug + locale (for rendering)
135
164
  */
136
165
  getPublishedPage(slug: string, locale?: string): Promise<ApiResponse<PageApiData>>;
166
+ /**
167
+ * Fetch merchant language config (for editor fields)
168
+ */
169
+ getMerchantInfo(): Promise<ApiResponse<MerchantInfoData>>;
170
+ /**
171
+ * Upload files via secretKey auth (for editor fields)
172
+ * Returns array of file records: [{ _id, name, size, type, meta }]
173
+ */
174
+ uploadFile(file: File, folder?: string): Promise<ApiResponse<any[]>>;
175
+ /**
176
+ * Fetch previously uploaded files (for media library selector)
177
+ */
178
+ getUploads(page?: number, limit?: number): Promise<ApiResponse<any[]>>;
179
+ /** CDN base URL (derived from apiUrl) */
180
+ get cdnUrl(): string;
137
181
  }
138
182
 
139
183
  interface TecofContextValue {
@@ -171,6 +215,153 @@ declare const TecofEditor: ({ pageId, config, accessToken, onSave, onChange, ove
171
215
  */
172
216
  declare const TecofRender: ({ data, config, className }: TecofRenderProps) => react_jsx_runtime.JSX.Element | null;
173
217
 
218
+ interface LanguageFieldProps {
219
+ field: any;
220
+ name: string;
221
+ id: string;
222
+ value: LanguageFieldValue[];
223
+ onChange: (value: LanguageFieldValue[]) => void;
224
+ readOnly?: boolean;
225
+ }
226
+ interface LanguageFieldOptions {
227
+ /** Whether to render as textarea instead of input */
228
+ isTextarea?: boolean;
229
+ /** Number of rows for textarea mode */
230
+ textareaRows?: number;
231
+ /** Placeholder text */
232
+ placeholder?: string;
233
+ }
234
+ declare const LanguageField: ({ value, onChange, readOnly, isTextarea, textareaRows, placeholder, }: LanguageFieldProps & LanguageFieldOptions) => react_jsx_runtime.JSX.Element | null;
235
+ declare const createLanguageField: (options?: LanguageFieldOptions & {
236
+ label?: string;
237
+ }) => {
238
+ type: "custom";
239
+ label: string | undefined;
240
+ render: ({ value, onChange, readOnly, field, name, id }: LanguageFieldProps) => react_jsx_runtime.JSX.Element;
241
+ };
242
+
243
+ interface EditorFieldProps {
244
+ field: any;
245
+ name: string;
246
+ id: string;
247
+ value: LanguageFieldValue[];
248
+ onChange: (value: LanguageFieldValue[]) => void;
249
+ readOnly?: boolean;
250
+ }
251
+ interface EditorFieldOptions {
252
+ /** Placeholder text for empty editor */
253
+ placeholder?: string;
254
+ }
255
+ /**
256
+ * EditorField — A multilingual TipTap rich text editor field for Puck.
257
+ *
258
+ * Uses the same language tab system as LanguageField, but renders a
259
+ * TipTap editor with toolbar (bold, italic, underline, headings, lists,
260
+ * alignment, links, blockquote, undo/redo) instead of a plain text input.
261
+ *
262
+ * Value format: [{ code: "tr", value: "<p>HTML content</p>" }, ...]
263
+ */
264
+ declare const EditorField: ({ value, onChange, readOnly, }: EditorFieldProps & EditorFieldOptions) => react_jsx_runtime.JSX.Element | null;
265
+ /**
266
+ * Creates a Puck custom field definition for multilingual rich text (TipTap) editor.
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * import { createEditorField } from '@tecof/theme-editor';
271
+ *
272
+ * const config = {
273
+ * components: {
274
+ * TextBlock: {
275
+ * fields: {
276
+ * content: createEditorField({ label: 'İçerik' }),
277
+ * },
278
+ * defaultProps: { content: [] },
279
+ * render: ({ content }) => { ... },
280
+ * },
281
+ * },
282
+ * };
283
+ * ```
284
+ */
285
+ declare const createEditorField: (options?: EditorFieldOptions & {
286
+ label?: string;
287
+ }) => {
288
+ type: "custom";
289
+ label: string | undefined;
290
+ render: ({ value, onChange, readOnly, field, name, id }: EditorFieldProps) => react_jsx_runtime.JSX.Element;
291
+ };
292
+
293
+ interface UploadFieldProps {
294
+ field: any;
295
+ name: string;
296
+ id: string;
297
+ value: UploadedFile[];
298
+ onChange: (value: UploadedFile[]) => void;
299
+ readOnly?: boolean;
300
+ }
301
+ interface UploadFieldOptions {
302
+ allowMultiple?: boolean;
303
+ maxFiles?: number;
304
+ acceptedTypes?: string[];
305
+ maxFileSize?: string;
306
+ folder?: string;
307
+ label?: string;
308
+ }
309
+ declare const UploadField: react.ForwardRefExoticComponent<UploadFieldProps & UploadFieldOptions & react.RefAttributes<any>>;
310
+ declare const createUploadField: (options?: UploadFieldOptions) => {
311
+ type: "custom";
312
+ label: string | undefined;
313
+ render: ({ value, onChange, readOnly, field, name, id }: UploadFieldProps) => react_jsx_runtime.JSX.Element;
314
+ };
315
+
316
+ interface CodeEditorFieldProps {
317
+ field: any;
318
+ name: string;
319
+ id: string;
320
+ value: string;
321
+ onChange: (value: string) => void;
322
+ readOnly?: boolean;
323
+ }
324
+ interface CodeEditorFieldOptions {
325
+ label?: string;
326
+ defaultLanguage?: string;
327
+ height?: string;
328
+ theme?: string;
329
+ }
330
+ /**
331
+ * CodeEditorField — A code editor custom field for Puck.
332
+ * Uses Monaco Editor (@monaco-editor/react).
333
+ */
334
+ declare const CodeEditorField: react__default.ForwardRefExoticComponent<CodeEditorFieldProps & CodeEditorFieldOptions & react__default.RefAttributes<any>>;
335
+ /**
336
+ * Creates a Puck custom field definition for code editing.
337
+ *
338
+ * @example
339
+ * ```ts
340
+ * import { createCodeEditorField } from '@tecof/theme-editor';
341
+ *
342
+ * const config = {
343
+ * components: {
344
+ * CustomHero: {
345
+ * fields: {
346
+ * customHtml: createCodeEditorField({
347
+ * label: 'Özel HTML Kodu',
348
+ * defaultLanguage: 'html',
349
+ * height: '400px',
350
+ * }),
351
+ * },
352
+ * defaultProps: { customHtml: '' },
353
+ * render: ({ customHtml }) => <div dangerouslySetInnerHTML={{ __html: customHtml }} />,
354
+ * },
355
+ * },
356
+ * };
357
+ * ```
358
+ */
359
+ declare const createCodeEditorField: (options?: CodeEditorFieldOptions) => {
360
+ type: "custom";
361
+ label: string | undefined;
362
+ render: ({ value, onChange, readOnly, field, name, id }: CodeEditorFieldProps) => react_jsx_runtime.JSX.Element;
363
+ };
364
+
174
365
  declare function hexToHsl(hex: string): HSL;
175
366
  declare function hslToHex(h: number, s: number, l: number): string;
176
367
  declare function lighten(hex: string, amount: number): string;
@@ -179,4 +370,4 @@ declare function generateCSSVariables(theme: ThemeConfig): string;
179
370
  declare function getDefaultTheme(): ThemeConfig;
180
371
  declare function mergeTheme(base: ThemeConfig, overrides: Partial<ThemeConfig>): ThemeConfig;
181
372
 
182
- 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 };
373
+ export { type ApiResponse, CodeEditorField, EditorField, type HSL, LanguageField, type LanguageFieldValue, type MerchantInfoData, type PageApiData, type PuckContentItem, type PuckPageData, TecofApiClient, TecofEditor, type TecofEditorProps, TecofProvider, type TecofProviderProps, TecofRender, type TecofRenderProps, type ThemeColors, type ThemeConfig, type ThemeSpacing, type ThemeTypography, UploadField, type UploadedFile, createCodeEditorField, createEditorField, createLanguageField, createUploadField, darken, generateCSSVariables, getDefaultTheme, hexToHsl, hslToHex, lighten, mergeTheme, useTecof };