@chaibuilder/sdk 1.2.2 → 1.2.3
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/{AddBlocks-QvCc-oag.js → AddBlocks-gbfzju1d.js} +15 -15
- package/dist/{AddBlocks-57-vroWk.cjs → AddBlocks-wuKI1ieB.cjs} +1 -1
- package/dist/{CanvasArea-59Gm0EZx.js → CanvasArea-lBmLPSqX.js} +2 -2
- package/dist/{CanvasArea-jRg53jrS.cjs → CanvasArea-yDkGNbGZ.cjs} +1 -1
- package/dist/{CurrentPage-MLObvs0K.cjs → CurrentPage-0VSOB-Hb.cjs} +1 -1
- package/dist/{CurrentPage-YPI5QTjk.js → CurrentPage-B6hjYNzI.js} +2 -2
- package/dist/{Layers-no2keK4N.js → Layers-IDVZrVlL.js} +2 -2
- package/dist/{Layers-x_mWeT_q.cjs → Layers-y2knU0bT.cjs} +1 -1
- package/dist/{PagesPanel-pOIuFPOA.cjs → PagesPanel-Q_uSjTW1.cjs} +1 -1
- package/dist/{PagesPanel-Q08uN4X3.js → PagesPanel-j_Fpa3sl.js} +3 -3
- package/dist/{ProjectPanel-4bN_GyNm.cjs → ProjectPanel-qEwohLIY.cjs} +1 -1
- package/dist/{ProjectPanel-zzYV9yrV.js → ProjectPanel-vjK_4VSG.js} +3 -3
- package/dist/{Settings-28A7R61i.js → Settings-V07siWr-.js} +2 -2
- package/dist/{Settings-KlTtgu3w.cjs → Settings-ky8B7ncY.cjs} +1 -1
- package/dist/{SidePanels--ZK6Iqou.js → SidePanels-0B2_uHyb.js} +3 -3
- package/dist/{SidePanels-eJBA_cUu.cjs → SidePanels-Rf7LJBOR.cjs} +1 -1
- package/dist/{add-page-modal-OvNXLGf0.cjs → add-page-modal-ELiuGxwH.cjs} +1 -1
- package/dist/{add-page-modal-EHIYTW4T.js → add-page-modal-dQ4vsAOV.js} +2 -2
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +24 -15
- package/dist/core.js +2 -2
- package/dist/{delete-page-modal-U4yiuhx0.cjs → delete-page-modal-gViErMeG.cjs} +1 -1
- package/dist/{delete-page-modal-qZJCk_JH.js → delete-page-modal-gWvIto0r.js} +2 -2
- package/dist/email-blocks.cjs +1 -1
- package/dist/email-blocks.d.ts +1 -1
- package/dist/email-blocks.js +5 -5
- package/dist/html-to-json-5UoswV2Q.cjs +1 -0
- package/dist/html-to-json-yjzEN9OX.js +184 -0
- package/dist/{index-hMoPNZVn.cjs → index-99vxkDWJ.cjs} +2 -2
- package/dist/{index-QEchoZ98.js → index-aHQmo59Y.js} +3 -3
- package/dist/lib.cjs +1 -1
- package/dist/lib.js +1 -1
- package/dist/{page-viewer-zFLkUu2I.js → page-viewer-YU2ON-TT.js} +3 -3
- package/dist/{page-viewer-WhM1FSU0.cjs → page-viewer-vW3LE2Lt.cjs} +1 -1
- package/dist/{project-general-setting-MWGOOurD.js → project-general-setting-m6C3KOQm.js} +2 -2
- package/dist/{project-general-setting-y8daY7V9.cjs → project-general-setting-vDHVl9_W.cjs} +1 -1
- package/dist/{single-page-detail-C48IPzbd.js → single-page-detail-GxzBw_k6.js} +3 -3
- package/dist/{single-page-detail--xPv74bX.cjs → single-page-detail-MFwjDf9d.cjs} +1 -1
- package/dist/studio.cjs +1 -1
- package/dist/studio.js +2 -2
- package/dist/web-blocks.cjs +2 -2
- package/dist/web-blocks.js +252 -234
- package/package.json +5 -4
- package/dist/html-to-json-dfALTAdG.cjs +0 -1
- package/dist/html-to-json-xKBERAI1.js +0 -177
package/dist/core.d.ts
CHANGED
|
@@ -48,36 +48,39 @@ export declare const ChaiBuilderEditor: (props: ChaiBuilderEditorProps) => JSX_2
|
|
|
48
48
|
|
|
49
49
|
export declare interface ChaiBuilderEditorProps {
|
|
50
50
|
breakpoints?: Breakpoint[];
|
|
51
|
-
blocks?: ChaiBlock[];
|
|
52
51
|
editable?: boolean;
|
|
52
|
+
loading?: boolean;
|
|
53
53
|
locale?: string;
|
|
54
54
|
nonEditableComponent?: ReactComponentType;
|
|
55
|
-
brandingOptions?: Record<string, string>;
|
|
56
55
|
canvas?: React_2.FC<any>;
|
|
57
|
-
previewLink?: string;
|
|
58
56
|
canvasTopBarComponents?: {
|
|
59
57
|
right?: ReactComponentType[];
|
|
60
58
|
};
|
|
59
|
+
previewLink?: string;
|
|
61
60
|
dataBindingSupport?: boolean;
|
|
62
|
-
dataProviders?:
|
|
63
|
-
providerKey: string;
|
|
64
|
-
args: Record<string, any>;
|
|
65
|
-
}[];
|
|
61
|
+
dataProviders?: DataProvider[];
|
|
66
62
|
darkMode?: boolean;
|
|
67
63
|
dndOptions?: any;
|
|
64
|
+
importHTMLSupport?: boolean;
|
|
68
65
|
fetchMediaCallback?: (limit?: number, offset?: number) => Promise<any[]>;
|
|
66
|
+
uploadMediaCallback?: (file: File) => Promise<{
|
|
67
|
+
url: string;
|
|
68
|
+
}>;
|
|
69
69
|
getExternalPredefinedBlock?: (block: PredefinedBlock) => Promise<PredefinedBlock & {
|
|
70
70
|
blocks: ChaiBlock[];
|
|
71
71
|
html: string;
|
|
72
72
|
}>;
|
|
73
73
|
getUILibraryBlocks?: (libraryUuid: string) => Promise<PredefinedBlock[]>;
|
|
74
|
+
uiLibraries?: UILibrary[];
|
|
74
75
|
subPages?: Block[];
|
|
75
76
|
subPagesSupport?: boolean;
|
|
76
|
-
|
|
77
|
-
loading?: boolean;
|
|
77
|
+
blocks?: ChaiBlock[];
|
|
78
78
|
onSaveBlocks?: ({ blocks, providers }: any) => Promise<any>;
|
|
79
|
-
onSavePage
|
|
80
|
-
|
|
79
|
+
onSavePage?: ({ blocks, providers }: SavePageData) => Promise<boolean | Error>;
|
|
80
|
+
brandingOptions?: Record<string, string>;
|
|
81
|
+
onSaveBrandingOptions?: (brandingOptions: Record<string, any>) => Promise<boolean | Error>;
|
|
82
|
+
container?: ChaiBlock | "Body" | "Container";
|
|
83
|
+
onSaveContainer?: (container: ChaiBlock) => Promise<boolean | Error>;
|
|
81
84
|
onSyncStatusChange?: (syncStatus: "UNSAVED" | "SAVED") => void;
|
|
82
85
|
previewComponent?: ReactComponentType;
|
|
83
86
|
sideBarComponents?: {
|
|
@@ -93,10 +96,6 @@ export declare interface ChaiBuilderEditorProps {
|
|
|
93
96
|
left?: ReactComponentType[];
|
|
94
97
|
right?: ReactComponentType[];
|
|
95
98
|
};
|
|
96
|
-
uiLibraries?: UILibrary[];
|
|
97
|
-
uploadMediaCallback?: (file: File) => Promise<{
|
|
98
|
-
url: string;
|
|
99
|
-
}>;
|
|
100
99
|
getPages?: () => Promise<ChaiPage[]>;
|
|
101
100
|
unsplashAccessKey?: string;
|
|
102
101
|
}
|
|
@@ -120,6 +119,11 @@ declare type ClassDerivedObject = {
|
|
|
120
119
|
property: string;
|
|
121
120
|
};
|
|
122
121
|
|
|
122
|
+
declare type DataProvider = {
|
|
123
|
+
providerKey: string;
|
|
124
|
+
args: Record<string, any>;
|
|
125
|
+
};
|
|
126
|
+
|
|
123
127
|
declare type PredefinedBlock = {
|
|
124
128
|
uuid: string;
|
|
125
129
|
name: string;
|
|
@@ -130,6 +134,11 @@ declare type PredefinedBlock = {
|
|
|
130
134
|
|
|
131
135
|
declare type ReactComponentType = React_2.ComponentType<any>;
|
|
132
136
|
|
|
137
|
+
declare type SavePageData = {
|
|
138
|
+
blocks: ChaiBlock[];
|
|
139
|
+
providers?: DataProvider[];
|
|
140
|
+
};
|
|
141
|
+
|
|
133
142
|
declare type TBlockTranslation = {
|
|
134
143
|
[_path: string]: any;
|
|
135
144
|
};
|
package/dist/core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { k as J } from "./index-
|
|
1
|
+
import { k as J } from "./index-aHQmo59Y.js";
|
|
2
2
|
import { N as ss, af as es, O as as, ah as os, P as ts, ae as rs, x as is, i as ps, y as ls, Q as ms, p as us, R as cs, U as ds, k as Bs, V as ks, n as ns, W as Ss, X as Cs, m as Ps, L as vs, Y as gs, Z as ys, _ as As, $ as Ms, a0 as hs, o as Ds, h as Is, a1 as Rs, M as fs, l as xs, a3 as Ts, ag as Us, a6 as bs, a5 as js, a4 as ws, j as Hs, ad as Os, ai as Fs, aj as Gs, w as Ls, a7 as Ws, a9 as Zs, a2 as Es, aa as Ns, a8 as Qs, ab as Vs, ac as Xs } from "./index-_OgCuSUz.js";
|
|
3
3
|
import { useTranslation as _s } from "react-i18next";
|
|
4
4
|
import "i18next";
|
|
@@ -21,7 +21,7 @@ import "react-hotkeys-hook";
|
|
|
21
21
|
import "@chaibuilder/runtime";
|
|
22
22
|
import "@radix-ui/react-icons";
|
|
23
23
|
import "sonner";
|
|
24
|
-
import "./html-to-json-
|
|
24
|
+
import "./html-to-json-yjzEN9OX.js";
|
|
25
25
|
import "himalaya";
|
|
26
26
|
import "./MODIFIERS-RiXS5Mn1.js";
|
|
27
27
|
import "lodash";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-runtime-Z_BpKhVy.cjs"),r=require("./index-IIJ_o44s.cjs"),l=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-runtime-Z_BpKhVy.cjs"),r=require("./index-IIJ_o44s.cjs"),l=require("./index-99vxkDWJ.cjs"),q=require("@radix-ui/react-icons");require("./_commonjsHelpers-wDK0ZLPo.cjs");require("react");require("@radix-ui/react-toggle");require("class-variance-authority");require("./utils-PTxFk6qT.cjs");require("lodash-es");require("./MODIFIERS-2FeVfZQ9.cjs");require("clsx");require("tailwind-merge");require("@radix-ui/react-switch");require("@radix-ui/react-slot");require("@radix-ui/react-accordion");require("@radix-ui/react-alert-dialog");require("@radix-ui/react-dialog");require("@radix-ui/react-label");require("@radix-ui/react-scroll-area");require("@radix-ui/react-tabs");require("@radix-ui/react-tooltip");require("@radix-ui/react-popover");require("@radix-ui/react-menubar");require("@radix-ui/react-hover-card");require("@radix-ui/react-select");require("@radix-ui/react-dropdown-menu");require("@radix-ui/react-separator");require("@radix-ui/react-toast");require("cmdk");require("@radix-ui/react-context-menu");require("react-icons-picker");require("react-dom");require("react-quill");require("jotai");require("flat-to-nested");require("./Functions-N3yhPYKY.cjs");require("redux-undo");require("@chaibuilder/runtime");require("@react-hookz/web");require("react-i18next");require("i18next");require("@floating-ui/react-dom");require("react-textarea-autosize");require("flagged");require("react-dnd");require("@minoru/react-dnd-treeview");require("react-hotkeys-hook");require("sonner");require("./html-to-json-5UoswV2Q.cjs");require("himalaya");require("lodash");require("lucide-react");const d=({pageData:i,projectData:t})=>{const n={},u=l.useDeletePage(),s=i.uuid===t.homepage,o=()=>{u.mutate(i,{onSuccess:()=>{n({uuid:t.homepage,slug:"/home"})}})};return e.jsxRuntimeExports.jsxs(r.AlertDialog,{children:[e.jsxRuntimeExports.jsx(r.AlertDialogTrigger,{disabled:s,children:e.jsxRuntimeExports.jsx("div",{className:`flex h-full items-center justify-center rounded-md border px-2 py-2 font-medium hover:bg-red-400 hover:text-white ${s?"cursor-not-allowed border-red-200 text-red-200":"cursor-pointer border-red-400 text-red-400"}`,children:e.jsxRuntimeExports.jsx(q.TrashIcon,{})})}),e.jsxRuntimeExports.jsxs(r.AlertDialogContent,{children:[e.jsxRuntimeExports.jsxs(r.AlertDialogTitle,{children:["Are you sure you want to delete ",e.jsxRuntimeExports.jsx("i",{className:"text-red-500",children:i.name})," page?"]}),e.jsxRuntimeExports.jsx(r.AlertDialogDescription,{children:"This action cannot be undone. This will permanently delete your page."}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-end gap-x-3",children:[e.jsxRuntimeExports.jsx(r.AlertDialogCancel,{disabled:u.isPending,children:"Cancel"}),e.jsxRuntimeExports.jsx(r.Button,{variant:"destructive",onClick:o,disabled:u.isPending,children:"Yes, Delete"})]})]})]})};exports.default=d;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { j as e } from "./jsx-runtime-WbnYoNE9.js";
|
|
2
2
|
import { D as s, E as l, F as n, H as d, I as a, K as c, B as u } from "./index-_OgCuSUz.js";
|
|
3
|
-
import { j as x } from "./index-
|
|
3
|
+
import { j as x } from "./index-aHQmo59Y.js";
|
|
4
4
|
import { TrashIcon as h } from "@radix-ui/react-icons";
|
|
5
5
|
import "./_commonjsHelpers-UyOWmZb0.js";
|
|
6
6
|
import "react";
|
|
@@ -47,7 +47,7 @@ import "react-dnd";
|
|
|
47
47
|
import "@minoru/react-dnd-treeview";
|
|
48
48
|
import "react-hotkeys-hook";
|
|
49
49
|
import "sonner";
|
|
50
|
-
import "./html-to-json-
|
|
50
|
+
import "./html-to-json-yjzEN9OX.js";
|
|
51
51
|
import "himalaya";
|
|
52
52
|
import "lodash";
|
|
53
53
|
import "lucide-react";
|
package/dist/email-blocks.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-runtime-Z_BpKhVy.cjs"),r=require("@react-email/components"),s=require("@chaibuilder/runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-runtime-Z_BpKhVy.cjs"),r=require("@react-email/components"),s=require("@chaibuilder/runtime"),i=require("./controls-Dy1qa8Dc.cjs"),c=require("lodash-es");require("./_commonjsHelpers-wDK0ZLPo.cjs");require("react");const l=({blockProps:o,styles:t,children:n})=>e.jsxRuntimeExports.jsxs(r.Container,{...o,...t,children:[e.jsxRuntimeExports.jsx("h1",{children:"Hello"}),e.jsxRuntimeExports.jsx(r.Button,{href:"https://example.com",className:"c-bg-red-500 c-px-4 c-py-1 c-border c-rounded-md c-inline-block c-text-white c-font-bold",children:"Click me"}),e.jsxRuntimeExports.jsx(r.Hr,{}),e.jsxRuntimeExports.jsx(r.CodeInline,{children:"@react-email/code-inline"}),";",n]});s.registerChaiBlock(l,{type:"Container",label:"Container",group:"basic",category:"core",props:{styles:i.S({default:""})}});const u=c.noop;exports.loadEmailBlocks=u;
|
package/dist/email-blocks.d.ts
CHANGED
package/dist/email-blocks.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { j as o } from "./jsx-runtime-WbnYoNE9.js";
|
|
2
2
|
import { Container as i, Button as c, Hr as n, CodeInline as l } from "@react-email/components";
|
|
3
|
-
import { registerChaiBlock as
|
|
4
|
-
import { S as
|
|
3
|
+
import { registerChaiBlock as m } from "@chaibuilder/runtime";
|
|
4
|
+
import { S as s } from "./controls-XPXGHKht.js";
|
|
5
5
|
import { noop as p } from "lodash-es";
|
|
6
6
|
import "./_commonjsHelpers-UyOWmZb0.js";
|
|
7
7
|
import "react";
|
|
@@ -20,16 +20,16 @@ const a = ({ blockProps: e, styles: r, children: t }) => /* @__PURE__ */ o.jsxs(
|
|
|
20
20
|
";",
|
|
21
21
|
t
|
|
22
22
|
] });
|
|
23
|
-
|
|
23
|
+
m(a, {
|
|
24
24
|
type: "Container",
|
|
25
25
|
label: "Container",
|
|
26
26
|
group: "basic",
|
|
27
27
|
category: "core",
|
|
28
28
|
props: {
|
|
29
|
-
styles:
|
|
29
|
+
styles: s({ default: "" })
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
const u = p;
|
|
33
33
|
export {
|
|
34
|
-
u as
|
|
34
|
+
u as loadEmailBlocks
|
|
35
35
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const u=require("himalaya"),p=require("./Functions-N3yhPYKY.cjs"),e=require("lodash-es"),o=require("./MODIFIERS-2FeVfZQ9.cjs"),h=require("lodash"),v=t=>{const s=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,r=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return s.test(t)||r.test(t)},w=t=>{if(h.isEmpty(t))return t;const s=/<video[^>]+src=['"]([^'">]+)['"]/,r=/<iframe[^>]+src=['"]([^'">]+)['"]/,a=t.match(s),l=t.match(r),i=a?a[1]:l?l[1]:null,c=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,n=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return i&&(c.test(i)||n.test(i))?i:t},x={img:{alt:"alt",width:"width",height:"height",src:"image"},video:{src:"url",autoplay:"controls.autoPlay",muted:"controls.muted",loop:"controls.loop",controls:"controls.widgets"},a:{href:"link.href",target:"link.target",type:""},input:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},textarea:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},select:{placeholder:"placeholder",required:"required",multiple:"multiple",name:"fieldName"}},S=(t,s)=>t.children.length===1&&e.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link"],s._type),m=t=>t.map(s=>s.type==="text"?e.get(s,"content",""):e.isEmpty(s.children)?"":m(s.children)).join(""),g=t=>t===null?!0:t,y=t=>{const s={},r=x[t.tagName]||{},a=t.attributes;return e.forEach(a,({key:l,value:i})=>{if(r[l]){if(t.tagName==="img"&&l==="src"&&!i.startsWith("http")){const c=e.find(t.attributes,{key:"width"}),n=e.find(t.attributes,{key:"height"});c&&n?i=`https://via.placeholder.com/${c==null?void 0:c.value}x${n==null?void 0:n.value}`:i="https://via.placeholder.com/150x150"}e.set(s,r[l],g(i))}else e.includes(["style","class","srcset"],l)||e.set(s,`styles_attrs.${l}`,g(i))}),delete s.class,s},L=(t,s="styles")=>{if(!t.attributes)return{[s]:`${o.STYLES_KEY},`};const r=e.find(t.attributes,{key:"class"});if(r){const a=r.value;return{[s]:`${o.STYLES_KEY},${a}`}}return{[s]:`${o.STYLES_KEY},`}},N=t=>{switch(t.tagName){case"img":return{_type:"Image"};case"input":return{_type:"Input",showLabel:!1};case"hr":return{_type:"Divider"};case"br":return{_type:"LineBreak"};case"textarea":return{_type:"TextArea",showLabel:!1};case"audio":return{_type:"Audio"};case"canvas":return{_type:"Canvas"};case"video":case"iframe":return{_type:"CustomHTML"};case"svg":return{_type:"Icon"};case"select":return{_type:"Select",options:[]};case"option":return{_type:"Option"};case"ul":case"ol":case"dl":return{_type:"List",tag:t.tagName,_listType:t.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:t.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:t.tagName};case"p":return{_type:"Paragraph",content:""};case"a":return{_type:"Link"};case"form":return{_type:"Form"};case"label":return{_type:"Label"};case"button":return{_type:"Button"};case"code":return{_type:"Code"};case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return{_type:"Heading",tag:t.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:t.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:return{_type:"Box",tag:t.tagName,_name:t.tagName==="div"?"Box":e.capitalize(t.tagName)}}},f=(t,s=null)=>e.flatMapDeep(t,r=>{var i;if(r.type==="comment")return[];let a={_id:p.generateUUID()};if(s&&(a._parent=s.block._id),r.type==="text")return e.isEmpty(e.get(r,"content",""))?[]:s&&S(s.node,s.block)?(e.set(s,"block.content",e.get(r,"content","")),[]):{...a,_type:"Text",content:e.get(r,"content","")};if(a={...a,...N(r),...y(r),...L(r)},a._type==="Input"){const c=a.inputType||"text";c==="checkbox"?e.set(a,"_type","Checkbox"):c==="radio"&&e.set(a,"_type","Radio")}else if(r.tagName==="video"||r.tagName==="iframe"){const c=u.stringify([r]);return v(c)&&(e.set(a,"_type","Video"),e.set(a,"url",w(c)),e.set(a,"styles",`${o.STYLES_KEY},absolute top-0 left-0 w-full h-full`),e.set(a,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),a.content=c,[a]}else if(r.tagName==="svg"){const c=e.find(r.attributes,{key:"height"}),n=e.find(r.attributes,{key:"width"}),d=e.get(c,"value")?`[${e.get(c,"value")}px]`:"24px",b=e.get(n,"value")?`[${e.get(n,"value")}px]`:"24px",_=e.get(e.find(r.attributes,{key:"class"}),"value","w-full h-full");return a.styles=`${o.STYLES_KEY}, ${p.cn(`w-${b} h-${d}`,_)}`.trim(),r.attributes=e.filter(r.attributes,T=>!e.includes(["style","width","height","class"],T.key)),a.icon=u.stringify([r]),e.set(a,"styles_attrs",h.omit(e.get(a,"styles_attrs")||{},["height","width","style","class"])),[a]}else if(r.tagName=="option"&&s&&((i=s.block)==null?void 0:i._type)==="Select")return s.block.options.push({label:m(r.children),...y(r)}),[];const l=f(r.children,{block:a,node:r});return[a,...l]}),k=t=>{const s=t.match(/<body[^>]*>[\s\S]*?<\/body>/);return(s&&s.length>0?s[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):t).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},E=t=>{const s=u.parse(k(t));return e.isEmpty(t)?[]:e.flatten(f(s))};exports.getBlocksFromHTML=E;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { stringify as m, parse as x } from "himalaya";
|
|
2
|
+
import { g as N, c as k } from "./Functions-7jnEwJyw.js";
|
|
3
|
+
import { includes as y, get as l, isEmpty as g, forEach as L, find as u, set as o, capitalize as S, flatMapDeep as $, filter as C, flatten as A } from "lodash-es";
|
|
4
|
+
import { a as p } from "./MODIFIERS-RiXS5Mn1.js";
|
|
5
|
+
import { isEmpty as R, omit as B } from "lodash";
|
|
6
|
+
const H = (t) => {
|
|
7
|
+
const e = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, a = /(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;
|
|
8
|
+
return e.test(t) || a.test(t);
|
|
9
|
+
}, M = (t) => {
|
|
10
|
+
if (R(t))
|
|
11
|
+
return t;
|
|
12
|
+
const e = /<video[^>]+src=['"]([^'">]+)['"]/, a = /<iframe[^>]+src=['"]([^'">]+)['"]/, r = t.match(e), i = t.match(a), c = r ? r[1] : i ? i[1] : null, s = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, n = /(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;
|
|
13
|
+
return c && (s.test(c) || n.test(c)) ? c : t;
|
|
14
|
+
}, E = {
|
|
15
|
+
img: { alt: "alt", width: "width", height: "height", src: "image" },
|
|
16
|
+
video: {
|
|
17
|
+
src: "url",
|
|
18
|
+
autoplay: "controls.autoPlay",
|
|
19
|
+
muted: "controls.muted",
|
|
20
|
+
loop: "controls.loop",
|
|
21
|
+
controls: "controls.widgets"
|
|
22
|
+
},
|
|
23
|
+
a: {
|
|
24
|
+
href: "link.href",
|
|
25
|
+
target: "link.target",
|
|
26
|
+
type: ""
|
|
27
|
+
// @TODO: Detect here what to url, email, phone, elementId
|
|
28
|
+
},
|
|
29
|
+
input: {
|
|
30
|
+
placeholder: "placeholder",
|
|
31
|
+
required: "required",
|
|
32
|
+
type: "inputType",
|
|
33
|
+
name: "fieldName"
|
|
34
|
+
},
|
|
35
|
+
textarea: {
|
|
36
|
+
placeholder: "placeholder",
|
|
37
|
+
required: "required",
|
|
38
|
+
type: "inputType",
|
|
39
|
+
name: "fieldName"
|
|
40
|
+
},
|
|
41
|
+
select: {
|
|
42
|
+
placeholder: "placeholder",
|
|
43
|
+
required: "required",
|
|
44
|
+
multiple: "multiple",
|
|
45
|
+
name: "fieldName"
|
|
46
|
+
}
|
|
47
|
+
}, I = (t, e) => t.children.length === 1 && y(["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link"], e._type), b = (t) => t.map((e) => e.type === "text" ? l(e, "content", "") : g(e.children) ? "" : b(e.children)).join(""), h = (t) => t === null ? !0 : t, f = (t) => {
|
|
48
|
+
const e = {}, a = E[t.tagName] || {}, r = t.attributes;
|
|
49
|
+
return L(r, ({ key: i, value: c }) => {
|
|
50
|
+
if (a[i]) {
|
|
51
|
+
if (t.tagName === "img" && i === "src" && !c.startsWith("http")) {
|
|
52
|
+
const s = u(t.attributes, { key: "width" }), n = u(t.attributes, { key: "height" });
|
|
53
|
+
s && n ? c = `https://via.placeholder.com/${s == null ? void 0 : s.value}x${n == null ? void 0 : n.value}` : c = "https://via.placeholder.com/150x150";
|
|
54
|
+
}
|
|
55
|
+
o(e, a[i], h(c));
|
|
56
|
+
} else
|
|
57
|
+
y(["style", "class", "srcset"], i) || o(e, `styles_attrs.${i}`, h(c));
|
|
58
|
+
}), delete e.class, e;
|
|
59
|
+
}, q = (t, e = "styles") => {
|
|
60
|
+
if (!t.attributes)
|
|
61
|
+
return { [e]: `${p},` };
|
|
62
|
+
const a = u(t.attributes, { key: "class" });
|
|
63
|
+
if (a) {
|
|
64
|
+
const r = a.value;
|
|
65
|
+
return { [e]: `${p},${r}` };
|
|
66
|
+
}
|
|
67
|
+
return { [e]: `${p},` };
|
|
68
|
+
}, P = (t) => {
|
|
69
|
+
switch (t.tagName) {
|
|
70
|
+
case "img":
|
|
71
|
+
return { _type: "Image" };
|
|
72
|
+
case "input":
|
|
73
|
+
return { _type: "Input", showLabel: !1 };
|
|
74
|
+
case "hr":
|
|
75
|
+
return { _type: "Divider" };
|
|
76
|
+
case "br":
|
|
77
|
+
return { _type: "LineBreak" };
|
|
78
|
+
case "textarea":
|
|
79
|
+
return { _type: "TextArea", showLabel: !1 };
|
|
80
|
+
case "audio":
|
|
81
|
+
return { _type: "Audio" };
|
|
82
|
+
case "canvas":
|
|
83
|
+
return { _type: "Canvas" };
|
|
84
|
+
case "video":
|
|
85
|
+
case "iframe":
|
|
86
|
+
return { _type: "CustomHTML" };
|
|
87
|
+
case "svg":
|
|
88
|
+
return { _type: "Icon" };
|
|
89
|
+
case "select":
|
|
90
|
+
return { _type: "Select", options: [] };
|
|
91
|
+
case "option":
|
|
92
|
+
return { _type: "Option" };
|
|
93
|
+
case "ul":
|
|
94
|
+
case "ol":
|
|
95
|
+
case "dl":
|
|
96
|
+
return {
|
|
97
|
+
_type: "List",
|
|
98
|
+
tag: t.tagName,
|
|
99
|
+
_listType: t.tagName === "ol" ? "list-decimal" : "list-none"
|
|
100
|
+
};
|
|
101
|
+
case "li":
|
|
102
|
+
case "dt":
|
|
103
|
+
return { _type: "ListItem", tag: t.tagName };
|
|
104
|
+
case "span":
|
|
105
|
+
case "figcaption":
|
|
106
|
+
case "legend":
|
|
107
|
+
return { _type: "Span", tag: t.tagName };
|
|
108
|
+
case "p":
|
|
109
|
+
return { _type: "Paragraph", content: "" };
|
|
110
|
+
case "a":
|
|
111
|
+
return { _type: "Link" };
|
|
112
|
+
case "form":
|
|
113
|
+
return { _type: "Form" };
|
|
114
|
+
case "label":
|
|
115
|
+
return { _type: "Label" };
|
|
116
|
+
case "button":
|
|
117
|
+
return { _type: "Button" };
|
|
118
|
+
case "code":
|
|
119
|
+
return { _type: "Code" };
|
|
120
|
+
case "h1":
|
|
121
|
+
case "h2":
|
|
122
|
+
case "h3":
|
|
123
|
+
case "h4":
|
|
124
|
+
case "h5":
|
|
125
|
+
case "h6":
|
|
126
|
+
return { _type: "Heading", tag: t.tagName };
|
|
127
|
+
case "table":
|
|
128
|
+
return { _type: "Table" };
|
|
129
|
+
case "tr":
|
|
130
|
+
return { _type: "TableRow" };
|
|
131
|
+
case "td":
|
|
132
|
+
case "th":
|
|
133
|
+
return { _type: "TableCell", tag: t.tagName };
|
|
134
|
+
case "thead":
|
|
135
|
+
return { _type: "TableHead" };
|
|
136
|
+
case "tbody":
|
|
137
|
+
return { _type: "TableBody" };
|
|
138
|
+
case "tfoot":
|
|
139
|
+
return { _type: "TableFooter" };
|
|
140
|
+
default:
|
|
141
|
+
return {
|
|
142
|
+
_type: "Box",
|
|
143
|
+
tag: t.tagName,
|
|
144
|
+
_name: t.tagName === "div" ? "Box" : S(t.tagName)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}, d = (t, e = null) => $(t, (a) => {
|
|
148
|
+
var c;
|
|
149
|
+
if (a.type === "comment")
|
|
150
|
+
return [];
|
|
151
|
+
let r = { _id: N() };
|
|
152
|
+
if (e && (r._parent = e.block._id), a.type === "text")
|
|
153
|
+
return g(l(a, "content", "")) ? [] : e && I(e.node, e.block) ? (o(e, "block.content", l(a, "content", "")), []) : { ...r, _type: "Text", content: l(a, "content", "") };
|
|
154
|
+
if (r = {
|
|
155
|
+
...r,
|
|
156
|
+
...P(a),
|
|
157
|
+
...f(a),
|
|
158
|
+
...q(a)
|
|
159
|
+
}, r._type === "Input") {
|
|
160
|
+
const s = r.inputType || "text";
|
|
161
|
+
s === "checkbox" ? o(r, "_type", "Checkbox") : s === "radio" && o(r, "_type", "Radio");
|
|
162
|
+
} else if (a.tagName === "video" || a.tagName === "iframe") {
|
|
163
|
+
const s = m([a]);
|
|
164
|
+
return H(s) && (o(r, "_type", "Video"), o(r, "url", M(s)), o(r, "styles", `${p},absolute top-0 left-0 w-full h-full`), o(r, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), r.content = s, [r];
|
|
165
|
+
} else if (a.tagName === "svg") {
|
|
166
|
+
const s = u(a.attributes, { key: "height" }), n = u(a.attributes, { key: "width" }), _ = l(s, "value") ? `[${l(s, "value")}px]` : "24px", v = l(n, "value") ? `[${l(n, "value")}px]` : "24px", T = l(u(a.attributes, { key: "class" }), "value", "w-full h-full");
|
|
167
|
+
return r.styles = `${p}, ${k(`w-${v} h-${_}`, T)}`.trim(), a.attributes = C(a.attributes, (w) => !y(["style", "width", "height", "class"], w.key)), r.icon = m([a]), o(r, "styles_attrs", B(l(r, "styles_attrs") || {}, ["height", "width", "style", "class"])), [r];
|
|
168
|
+
} else if (a.tagName == "option" && e && ((c = e.block) == null ? void 0 : c._type) === "Select")
|
|
169
|
+
return e.block.options.push({
|
|
170
|
+
label: b(a.children),
|
|
171
|
+
...f(a)
|
|
172
|
+
}), [];
|
|
173
|
+
const i = d(a.children, { block: r, node: a });
|
|
174
|
+
return [r, ...i];
|
|
175
|
+
}), z = (t) => {
|
|
176
|
+
const e = t.match(/<body[^>]*>[\s\S]*?<\/body>/);
|
|
177
|
+
return (e && e.length > 0 ? e[0].replace(/<body/, "<div").replace(/<\/body>/, "</div>") : t).replace(/\s+/g, " ").replaceAll("> <", "><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").trim();
|
|
178
|
+
}, Y = (t) => {
|
|
179
|
+
const e = x(z(t));
|
|
180
|
+
return g(t) ? [] : A(d(e));
|
|
181
|
+
};
|
|
182
|
+
export {
|
|
183
|
+
Y as g
|
|
184
|
+
};
|