@nuvler/theme-sdk 1.2.1 → 1.3.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/README.md +15 -0
- package/dist/index.d.ts +72 -2
- package/dist/index.js +55 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,3 +38,18 @@ protocolo `mount/unmount` e `sdkVersion` declara a faixa do SDK aceita.
|
|
|
38
38
|
`primary`, `secondary`, `background` e `text` permanecem obrigatórios para
|
|
39
39
|
compatibilidade. Os demais tokens semânticos são opcionais no contrato, mas o
|
|
40
40
|
starter atual já os declara e os runtimes aplicam fallbacks para temas antigos.
|
|
41
|
+
|
|
42
|
+
Use `productUrl(product)` ao gerar links de produto. Quando `categoryPath`
|
|
43
|
+
estiver presente, a URL inclui toda a hierarquia da categoria principal; com
|
|
44
|
+
APIs antigas, o helper mantém o fallback `/produto/slug`.
|
|
45
|
+
|
|
46
|
+
## Componentes da Home declarados pelo tema
|
|
47
|
+
|
|
48
|
+
Na Theme API 1.3, `manifest.presentation.homeComponents` declara componentes
|
|
49
|
+
que o Gestão pode editar sem conhecer previamente sua implementação. Cada
|
|
50
|
+
seção usa `type: "theme-component"` e carrega `componentKey`, `schemaVersion`
|
|
51
|
+
e `props`. Formulários usam a ação segura `contact.submit` e recebem a função
|
|
52
|
+
em `HomeProps.submitContact` ou `ThemeRuntimeSdk.contact.submit`.
|
|
53
|
+
|
|
54
|
+
O contrato completo e os exemplos estão em
|
|
55
|
+
[`docs/dynamic-home-components.md`](../../docs/dynamic-home-components.md).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from "react";
|
|
2
2
|
export declare const THEME_SCHEMA_VERSION: 1;
|
|
3
|
-
export declare const THEME_API_VERSION: "1.
|
|
3
|
+
export declare const THEME_API_VERSION: "1.3.0";
|
|
4
4
|
export declare const THEME_RUNTIME_VERSION: "1";
|
|
5
|
+
/** Decodifica entidades HTML comuns, inclusive conteúdo legado duplamente codificado. */
|
|
6
|
+
export declare function decodeHtmlEntities(value: string): string;
|
|
7
|
+
/** Converte HTML em texto adequado para resumos, cards e metadados. */
|
|
8
|
+
export declare function htmlToPlainText(value: string): string;
|
|
5
9
|
export interface ThemeApiCompatibility {
|
|
6
10
|
themeApi: string;
|
|
7
11
|
}
|
|
@@ -77,6 +81,45 @@ export interface ThemePresentation {
|
|
|
77
81
|
templateId?: string;
|
|
78
82
|
colors: ThemeSiteColors;
|
|
79
83
|
layout: ThemeSettings["layout"];
|
|
84
|
+
/** Catálogo declarativo usado pelo Gestão para montar editores sem código. */
|
|
85
|
+
homeComponents?: ThemeHomeComponentDefinition[];
|
|
86
|
+
}
|
|
87
|
+
export type ThemeHomeComponentCategory = "Destaques" | "Conteúdo" | "Listas" | "Mídia" | "Formulários";
|
|
88
|
+
export type ThemeHomeComponentControl = "text" | "textarea" | "rich-text" | "url" | "image" | "video" | "number" | "boolean" | "select" | "repeater" | "contact-fields";
|
|
89
|
+
export interface ThemeHomeComponentOption {
|
|
90
|
+
label: string;
|
|
91
|
+
value: string;
|
|
92
|
+
}
|
|
93
|
+
/** Campo seguro e declarativo; não permite HTML, CSS ou JavaScript arbitrário. */
|
|
94
|
+
export interface ThemeHomeComponentFieldDefinition {
|
|
95
|
+
key: string;
|
|
96
|
+
label: string;
|
|
97
|
+
control: ThemeHomeComponentControl;
|
|
98
|
+
help?: string;
|
|
99
|
+
placeholder?: string;
|
|
100
|
+
required?: boolean;
|
|
101
|
+
defaultValue?: string | number | boolean | null;
|
|
102
|
+
options?: ThemeHomeComponentOption[];
|
|
103
|
+
min?: number;
|
|
104
|
+
max?: number;
|
|
105
|
+
maxLength?: number;
|
|
106
|
+
maxItems?: number;
|
|
107
|
+
/** Campos de um item repetível. Repetidores aninhados não fazem parte do contrato. */
|
|
108
|
+
itemFields?: Array<Omit<ThemeHomeComponentFieldDefinition, "itemFields">>;
|
|
109
|
+
}
|
|
110
|
+
export interface ThemeHomeComponentActionDefinition {
|
|
111
|
+
type: "contact.submit";
|
|
112
|
+
/** Identificador persistido junto aos contatos recebidos. */
|
|
113
|
+
formKey: string;
|
|
114
|
+
}
|
|
115
|
+
export interface ThemeHomeComponentDefinition {
|
|
116
|
+
key: string;
|
|
117
|
+
name: string;
|
|
118
|
+
description: string;
|
|
119
|
+
category: ThemeHomeComponentCategory;
|
|
120
|
+
schemaVersion: number;
|
|
121
|
+
fields: ThemeHomeComponentFieldDefinition[];
|
|
122
|
+
action?: ThemeHomeComponentActionDefinition;
|
|
80
123
|
}
|
|
81
124
|
export interface ThemeContact {
|
|
82
125
|
email?: string;
|
|
@@ -119,7 +162,12 @@ export interface ThemeContextSite {
|
|
|
119
162
|
export interface ThemeSite extends ThemeContextSite {
|
|
120
163
|
tenant: ThemeStore;
|
|
121
164
|
}
|
|
122
|
-
export type ThemeHomeSectionType = "hero" | "banner-carousel" | "image-text" | "rich-text" | "cta" | "services-grid" | "blog-grid" | "cases-grid" | "products-grid" | "products-carousel";
|
|
165
|
+
export type ThemeHomeSectionType = "hero" | "banner-carousel" | "image-text" | "rich-text" | "cta" | "services-grid" | "blog-grid" | "cases-grid" | "products-grid" | "products-carousel" | "theme-component";
|
|
166
|
+
export interface ThemeComponentSectionData {
|
|
167
|
+
componentKey: string;
|
|
168
|
+
schemaVersion: number;
|
|
169
|
+
props: Record<string, unknown>;
|
|
170
|
+
}
|
|
123
171
|
export interface ThemeHomeSection {
|
|
124
172
|
id?: string;
|
|
125
173
|
type: ThemeHomeSectionType;
|
|
@@ -159,6 +207,8 @@ export interface ThemeProduct {
|
|
|
159
207
|
image: ThemeImage | null;
|
|
160
208
|
images: ThemeImage[];
|
|
161
209
|
categories: ThemeCategory[];
|
|
210
|
+
/** Caminho da categoria principal, da raiz até a categoria atribuída. */
|
|
211
|
+
categoryPath?: string[];
|
|
162
212
|
variantOptions: Array<{
|
|
163
213
|
name: string;
|
|
164
214
|
values: string[];
|
|
@@ -272,6 +322,19 @@ export interface HomeProps {
|
|
|
272
322
|
cases: ThemeEditorialItem[];
|
|
273
323
|
site: ThemeSite;
|
|
274
324
|
template: SiteTemplate;
|
|
325
|
+
submitContact?: (submission: ThemeContactSubmissionInput) => Promise<ThemeContactSubmissionResult>;
|
|
326
|
+
}
|
|
327
|
+
export type ThemeContactSubmissionValue = string | boolean | string[];
|
|
328
|
+
export interface ThemeContactSubmissionInput {
|
|
329
|
+
formKey: string;
|
|
330
|
+
sectionId?: string;
|
|
331
|
+
values: Record<string, ThemeContactSubmissionValue>;
|
|
332
|
+
pathname?: string;
|
|
333
|
+
}
|
|
334
|
+
export interface ThemeContactSubmissionResult {
|
|
335
|
+
id: string;
|
|
336
|
+
status: "received";
|
|
337
|
+
receivedAt: string;
|
|
275
338
|
}
|
|
276
339
|
export interface ProductGridProps {
|
|
277
340
|
products: ThemeProduct[];
|
|
@@ -281,6 +344,7 @@ export interface ProductGridProps {
|
|
|
281
344
|
}
|
|
282
345
|
export interface ThemeCartItem {
|
|
283
346
|
productSlug: string;
|
|
347
|
+
productUrl?: string;
|
|
284
348
|
title: string;
|
|
285
349
|
sku: string;
|
|
286
350
|
variantId?: string | null;
|
|
@@ -288,6 +352,8 @@ export interface ThemeCartItem {
|
|
|
288
352
|
image?: ThemeImage | null;
|
|
289
353
|
unitPrice?: number | null;
|
|
290
354
|
}
|
|
355
|
+
/** URL canônica relativa do produto, com fallback para lojas/APIs antigas. */
|
|
356
|
+
export declare function productUrl(product: Pick<ThemeProduct, "slug" | "categoryPath">): string;
|
|
291
357
|
export interface ProductDetailProps {
|
|
292
358
|
product: ThemeProduct;
|
|
293
359
|
contact?: ThemeContact;
|
|
@@ -373,6 +439,10 @@ export interface ThemeRuntimeSdk {
|
|
|
373
439
|
catalog: {
|
|
374
440
|
searchProducts(query: string): Promise<ThemeProduct[]>;
|
|
375
441
|
};
|
|
442
|
+
/** Disponível quando o host oferece o módulo público de contatos. */
|
|
443
|
+
contact?: {
|
|
444
|
+
submit(submission: ThemeContactSubmissionInput): Promise<ThemeContactSubmissionResult>;
|
|
445
|
+
};
|
|
376
446
|
}
|
|
377
447
|
export interface ThemeRuntimeMountOptions {
|
|
378
448
|
element: HTMLElement;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
export const THEME_SCHEMA_VERSION = 1;
|
|
2
|
-
export const THEME_API_VERSION = "1.
|
|
2
|
+
export const THEME_API_VERSION = "1.3.0";
|
|
3
3
|
export const THEME_RUNTIME_VERSION = "1";
|
|
4
|
+
const HTML_NAMED_ENTITIES = {
|
|
5
|
+
amp: "&", apos: "'", gt: ">", lt: "<", nbsp: " ", quot: '"',
|
|
6
|
+
agrave: "à", aacute: "á", acirc: "â", atilde: "ã", auml: "ä", aring: "å", aelig: "æ",
|
|
7
|
+
ccedil: "ç", egrave: "è", eacute: "é", ecirc: "ê", euml: "ë",
|
|
8
|
+
igrave: "ì", iacute: "í", icirc: "î", iuml: "ï", ntilde: "ñ",
|
|
9
|
+
ograve: "ò", oacute: "ó", ocirc: "ô", otilde: "õ", ouml: "ö", oslash: "ø",
|
|
10
|
+
ugrave: "ù", uacute: "ú", ucirc: "û", uuml: "ü", yacute: "ý", yuml: "ÿ",
|
|
11
|
+
laquo: "«", raquo: "»", lsquo: "‘", rsquo: "’", ldquo: "“", rdquo: "”",
|
|
12
|
+
ndash: "–", mdash: "—", hellip: "…", bull: "•", middot: "·",
|
|
13
|
+
copy: "©", reg: "®", trade: "™", deg: "°", plusmn: "±", times: "×", divide: "÷",
|
|
14
|
+
};
|
|
15
|
+
function decodeHtmlEntitiesOnce(value) {
|
|
16
|
+
return value.replace(/&(#(?:x[\da-f]+|\d+)|[a-z][a-z\d]+);/gi, (entity, code) => {
|
|
17
|
+
if (!code.startsWith("#"))
|
|
18
|
+
return HTML_NAMED_ENTITIES[code.toLowerCase()] ?? entity;
|
|
19
|
+
const hexadecimal = code[1]?.toLowerCase() === "x";
|
|
20
|
+
const codePoint = Number.parseInt(code.slice(hexadecimal ? 2 : 1), hexadecimal ? 16 : 10);
|
|
21
|
+
if (!Number.isFinite(codePoint))
|
|
22
|
+
return entity;
|
|
23
|
+
try {
|
|
24
|
+
return String.fromCodePoint(codePoint);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return entity;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Decodifica entidades HTML comuns, inclusive conteúdo legado duplamente codificado. */
|
|
32
|
+
export function decodeHtmlEntities(value) {
|
|
33
|
+
let decoded = value;
|
|
34
|
+
for (let pass = 0; pass < 2; pass += 1) {
|
|
35
|
+
const next = decodeHtmlEntitiesOnce(decoded);
|
|
36
|
+
if (next === decoded)
|
|
37
|
+
break;
|
|
38
|
+
decoded = next;
|
|
39
|
+
}
|
|
40
|
+
return decoded;
|
|
41
|
+
}
|
|
42
|
+
/** Converte HTML em texto adequado para resumos, cards e metadados. */
|
|
43
|
+
export function htmlToPlainText(value) {
|
|
44
|
+
return decodeHtmlEntities(value)
|
|
45
|
+
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, " ")
|
|
46
|
+
.replace(/<br\s*\/?>/gi, " ")
|
|
47
|
+
.replace(/<\/(p|div|li|h[1-6]|blockquote|tr)>/gi, " ")
|
|
48
|
+
.replace(/<[^>]+>/g, " ")
|
|
49
|
+
.replace(/\s+/g, " ")
|
|
50
|
+
.trim();
|
|
51
|
+
}
|
|
52
|
+
/** URL canônica relativa do produto, com fallback para lojas/APIs antigas. */
|
|
53
|
+
export function productUrl(product) {
|
|
54
|
+
const categoryPath = product.categoryPath?.filter(Boolean) ?? [];
|
|
55
|
+
const segments = categoryPath.length ? [...categoryPath, product.slug] : ["produto", product.slug];
|
|
56
|
+
return `/${segments.map(encodeURIComponent).join("/")}`;
|
|
57
|
+
}
|
|
4
58
|
export function defineTheme(theme) {
|
|
5
59
|
return theme;
|
|
6
60
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAgB,CAAC;AAClD,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAgB,CAAC;AAClD,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAY,CAAC;AAElD,MAAM,mBAAmB,GAA2B;IAClD,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;IAC3D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;IACpF,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;IAC5D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG;IAC5D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG;IACzE,MAAM,EAAE,GAAG,EAAE,MAAM,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