@diy-website-builder/sdk 0.1.0 → 0.1.4
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 +98 -13
- package/dist/diy-website-builder-editor.js +53 -50
- package/dist/index.d.ts +40 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Framework-agnostic **v3** visual website builder editor. Mounts into any `HTMLElement`.
|
|
4
4
|
|
|
5
|
+
## Get an API key
|
|
6
|
+
|
|
7
|
+
1. Create an account or sign in at [diy-website-builder.com](https://diy-website-builder.com).
|
|
8
|
+
2. Open [Developers](https://diy-website-builder.com/developers) and enable the developer product for your account (free to start).
|
|
9
|
+
3. Go to [API keys](https://diy-website-builder.com/developer/keys) in the developer dashboard.
|
|
10
|
+
4. Create a key. Copy the full key when it is shown. You will only see the complete value at create or rotate time.
|
|
11
|
+
5. Optional: add allowed domains on the key so it only works from those hosts. Leave empty to allow any domain.
|
|
12
|
+
|
|
13
|
+
Use that key as `apiKey` in the examples below.
|
|
14
|
+
|
|
5
15
|
## Install
|
|
6
16
|
|
|
7
17
|
```bash
|
|
@@ -10,6 +20,8 @@ npm install @diy-website-builder/sdk
|
|
|
10
20
|
|
|
11
21
|
## Usage
|
|
12
22
|
|
|
23
|
+
### Hosted publish (default)
|
|
24
|
+
|
|
13
25
|
```ts
|
|
14
26
|
import DIYWebsiteBuilderEditor from "@diy-website-builder/sdk";
|
|
15
27
|
|
|
@@ -25,28 +37,101 @@ const editor = new DIYWebsiteBuilderEditor.Builder({
|
|
|
25
37
|
editor.destroy();
|
|
26
38
|
```
|
|
27
39
|
|
|
40
|
+
### Export HTML to your host
|
|
41
|
+
|
|
42
|
+
Paid developer plans can export compiled HTML instead of publishing to DIY hosting. Media (images, videos, fonts) stays on the DIY CDN.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import DIYWebsiteBuilderEditor from "@diy-website-builder/sdk";
|
|
46
|
+
|
|
47
|
+
const editor = new DIYWebsiteBuilderEditor.Builder({
|
|
48
|
+
apiKey: "YOUR_API_KEY",
|
|
49
|
+
shortId: "my-site",
|
|
50
|
+
container: document.getElementById("editor")!,
|
|
51
|
+
publishMode: "export",
|
|
52
|
+
onExport: async (site) => {
|
|
53
|
+
// site.pages[].html is ready to host. Asset URLs point at the DIY CDN.
|
|
54
|
+
await fetch("/api/sites/import", {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { "Content-Type": "application/json" },
|
|
57
|
+
body: JSON.stringify(site),
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
onExportProgress: ({ phase, current, total }) => {
|
|
61
|
+
console.log(phase, current, total);
|
|
62
|
+
},
|
|
63
|
+
onPaidFeatureClick: (event) => {
|
|
64
|
+
if (event === "websiteExportRestricted") {
|
|
65
|
+
window.location.href = "https://diy-website-builder.com/developers#pricing";
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Or trigger export from your own UI:
|
|
71
|
+
// const site = await editor.exportSite();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Site export requires a paid developer plan (`devBasic` and above). Free plans can still download a single page from the editor menu when allowed.
|
|
75
|
+
|
|
76
|
+
#### CSP
|
|
77
|
+
|
|
78
|
+
If your host sets a Content-Security-Policy, allow DIY CDN media:
|
|
79
|
+
|
|
80
|
+
```http
|
|
81
|
+
Content-Security-Policy: img-src 'self' https://cdn.diy-website-builder.com; media-src 'self' https://cdn.diy-website-builder.com; font-src 'self' https://cdn.diy-website-builder.com https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://cdn.diy-website-builder.com https://cdn.jsdelivr.net; script-src 'self' https://cdn.diy-website-builder.com;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Deleting assets or the DIY project can break exported sites that still reference those CDN URLs.
|
|
85
|
+
|
|
86
|
+
## CDN
|
|
87
|
+
|
|
88
|
+
Load the UMD bundle from a CDN, then use the global `DIYWebsiteBuilderEditor`:
|
|
89
|
+
|
|
90
|
+
```html
|
|
91
|
+
<div id="editor"></div>
|
|
92
|
+
<script src="https://cdn.jsdelivr.net/npm/@diy-website-builder/sdk/dist/diy-website-builder-editor.js"></script>
|
|
93
|
+
<script>
|
|
94
|
+
const editor = new DIYWebsiteBuilderEditor.Builder({
|
|
95
|
+
apiKey: "YOUR_API_KEY",
|
|
96
|
+
shortId: "my-site",
|
|
97
|
+
container: document.getElementById("editor"),
|
|
98
|
+
exitURL: "/dashboard",
|
|
99
|
+
onPublish: (url) => console.log("published", url),
|
|
100
|
+
});
|
|
101
|
+
</script>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Alternatives:
|
|
105
|
+
|
|
106
|
+
- jsDelivr: `https://cdn.jsdelivr.net/npm/@diy-website-builder/sdk/dist/diy-website-builder-editor.js`
|
|
107
|
+
- unpkg: `https://unpkg.com/@diy-website-builder/sdk/dist/diy-website-builder-editor.js`
|
|
108
|
+
|
|
109
|
+
Pin a version in production, for example:
|
|
110
|
+
|
|
111
|
+
`https://cdn.jsdelivr.net/npm/@diy-website-builder/sdk@0.1.0/dist/diy-website-builder-editor.js`
|
|
112
|
+
|
|
28
113
|
## API
|
|
29
114
|
|
|
30
115
|
| Option | Type | Required | Notes |
|
|
31
116
|
| --- | --- | --- | --- |
|
|
32
|
-
| `apiKey` | `string` | yes |
|
|
117
|
+
| `apiKey` | `string` | yes | From [API keys](https://diy-website-builder.com/developer/keys) |
|
|
33
118
|
| `shortId` | `string` | yes | Project short id |
|
|
34
119
|
| `container` | `HTMLElement` | yes | Mount node |
|
|
35
|
-
| `language` | `
|
|
120
|
+
| `language` | `"en" \| "fr" \| "de" \| "es"` | no | UI language (default `"en"`) |
|
|
36
121
|
| `exitURL` | `string` | no | Exit / back navigation |
|
|
37
|
-
| `
|
|
38
|
-
| `onPublish` | `(url?: string) => void` | no | After publish |
|
|
122
|
+
| `publishMode` | `"hosted" \| "export"` | no | Default `"hosted"`. `"export"` compiles HTML and calls `onExport` |
|
|
123
|
+
| `onPublish` | `(url?: string) => void` | no | After DIY hosted publish |
|
|
124
|
+
| `onExport` | `(site: SiteExport) => void \| Promise<void>` | no | Required when `publishMode` is `"export"` |
|
|
125
|
+
| `onExportProgress` | `(progress) => void` | no | Save/compile progress for site export |
|
|
39
126
|
| `onPaidFeatureClick` | `(event) => void` | no | Upgrade / paywall hooks |
|
|
40
127
|
| `showMessage` | `(message, type, options?) => void` | no | Toast host |
|
|
41
128
|
|
|
42
|
-
|
|
129
|
+
### Methods
|
|
43
130
|
|
|
44
|
-
|
|
131
|
+
| Method | Notes |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| `exportSite()` | Full-site HTML package (paid developer). Calls `onExport` when set. |
|
|
134
|
+
| `exportPage(pageId?)` | Single page HTML (uses page-download entitlement). |
|
|
135
|
+
| `destroy()` | Unmount and clean up |
|
|
45
136
|
|
|
46
|
-
|
|
47
|
-
npm install
|
|
48
|
-
npm run build
|
|
49
|
-
npm run pack # writes a publishable .tgz under dist/package/
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
The published package ships only the UMD bundle + public `dist/index.d.ts` (no workspace `file:` dependencies).
|
|
137
|
+
Styles are injected by the bundle (`injectStyles`).
|