@studiocms/devapps 0.1.0-beta.8
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 +21 -0
- package/README.md +92 -0
- package/assets/preview-embeddedapp.png +0 -0
- package/assets/preview-page.png +0 -0
- package/assets/preview-toolbar.png +0 -0
- package/assets/wp-importer.png +0 -0
- package/dist/apps/libsql-viewer.d.ts +46 -0
- package/dist/apps/libsql-viewer.js +95 -0
- package/dist/apps/wp-importer.d.ts +42 -0
- package/dist/apps/wp-importer.js +214 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +66 -0
- package/dist/routes/wp-importer.d.ts +27 -0
- package/dist/routes/wp-importer.js +57 -0
- package/dist/schema/index.d.ts +152 -0
- package/dist/schema/index.js +45 -0
- package/dist/schema/wp-api.d.ts +439 -0
- package/dist/schema/wp-api.js +72 -0
- package/dist/utils/app-utils.d.ts +21 -0
- package/dist/utils/app-utils.js +37 -0
- package/dist/utils/pathGenerator.d.ts +10 -0
- package/dist/utils/pathGenerator.js +37 -0
- package/dist/utils/wp-api/converters.d.ts +74 -0
- package/dist/utils/wp-api/converters.js +181 -0
- package/dist/utils/wp-api/index.d.ts +6 -0
- package/dist/utils/wp-api/index.js +3 -0
- package/dist/utils/wp-api/pages.d.ts +13 -0
- package/dist/utils/wp-api/pages.js +38 -0
- package/dist/utils/wp-api/posts.d.ts +10 -0
- package/dist/utils/wp-api/posts.js +38 -0
- package/dist/utils/wp-api/settings.d.ts +18 -0
- package/dist/utils/wp-api/settings.js +45 -0
- package/dist/utils/wp-api/utils.d.ts +66 -0
- package/dist/utils/wp-api/utils.js +138 -0
- package/dist/virt.d.js +0 -0
- package/dist/virt.d.ts +13 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 StudioCMS - Adam Matthiesen, Jacob Jenkins, Paul Valladares
|
|
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,92 @@
|
|
|
1
|
+
# StudioCMS - Development Apps
|
|
2
|
+
|
|
3
|
+
Collection* of useful tools available during dev mode in Astro
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the integration **automatically** using the Astro CLI:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm astro add @studiocms/devapps
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx astro add @studiocms/devapps
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn astro add @studiocms/devapps
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or install it **manually**:
|
|
22
|
+
|
|
23
|
+
1. Install the required dependencies
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm add @studiocms/devapps
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @studiocms/devapps
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
yarn add @studiocms/devapps
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. Add the integration to your astro config
|
|
38
|
+
|
|
39
|
+
```diff
|
|
40
|
+
+import devApps from "@studiocms/devapps";
|
|
41
|
+
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
integrations: [
|
|
44
|
+
+ devApps(),
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
All tools will only be available during `astro dev` and will not be available during production deployments!
|
|
52
|
+
|
|
53
|
+
### libSQL Viewer
|
|
54
|
+
|
|
55
|
+
#### Requires
|
|
56
|
+
|
|
57
|
+
The following env variables set (`@astrojs/db`):
|
|
58
|
+
- **`ASTRO_DB_REMOTE_URL`**
|
|
59
|
+
- **`ASTRO_DB_APP_TOKEN`**
|
|
60
|
+
|
|
61
|
+
#### Preview
|
|
62
|
+
|
|
63
|
+
- Toolbar app
|
|
64
|
+
|
|
65
|
+

|
|
66
|
+
|
|
67
|
+
- Toolbar app Embedded
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
|
|
71
|
+
- Full page View
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
### WordPress Importer
|
|
76
|
+
|
|
77
|
+
#### Requires
|
|
78
|
+
|
|
79
|
+
- StudioCMS Integration
|
|
80
|
+
- A current WP Install
|
|
81
|
+
- `@studiocms/blog` (Optional for importing Posts under a blog)
|
|
82
|
+
|
|
83
|
+
#### Preview
|
|
84
|
+
|
|
85
|
+
- Toolbar app
|
|
86
|
+
|
|
87
|
+

|
|
88
|
+
|
|
89
|
+
## Licensing
|
|
90
|
+
|
|
91
|
+
[MIT Licensed](https://github.com/astrolicious/studiocms/blob/main/LICENSE).
|
|
92
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates the source URL for an iframe based on the provided database URL.
|
|
3
|
+
*
|
|
4
|
+
* @param dbUrl - The URL of the database.
|
|
5
|
+
* @returns The source URL for the iframe. If the database URL contains 'turso.io',
|
|
6
|
+
* it returns `tursoURL`. Otherwise, it returns `sqlLiteUrl`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getIFrameSrc(dbUrl: string): "https://studio.outerbase.com/embed/sqlite?theme=dark" | "https://studio.outerbase.com/embed/turso?theme=dark";
|
|
9
|
+
/**
|
|
10
|
+
* Defines a toolbar application for viewing and interacting with a libSQL database.
|
|
11
|
+
*
|
|
12
|
+
* @param {HTMLCanvasElement} canvas - The canvas element where the app will be initialized.
|
|
13
|
+
* @param {EventTarget} eventTarget - The event target for handling outside click events.
|
|
14
|
+
*
|
|
15
|
+
* @returns {void}
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import libsqlViewer from './libsql-viewer';
|
|
20
|
+
*
|
|
21
|
+
* const canvas = document.getElementById('appCanvas') as HTMLCanvasElement;
|
|
22
|
+
* const eventTarget = new EventTarget();
|
|
23
|
+
*
|
|
24
|
+
* libsqlViewer.init(canvas, eventTarget);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* This function creates an iframe to display the libSQL database viewer and sets up
|
|
29
|
+
* event listeners to handle SQL query and transaction requests via postMessage.
|
|
30
|
+
*
|
|
31
|
+
* The iframe's source URL and authentication token are retrieved from the `dbEnv` object.
|
|
32
|
+
*
|
|
33
|
+
* The `createClient` function is used to create a client for executing SQL queries and transactions.
|
|
34
|
+
*
|
|
35
|
+
* The `closeOnOutsideClick` function is used to close the app window when a click is detected outside of it.
|
|
36
|
+
*
|
|
37
|
+
* The `transformTursoResult` function is used to transform the results of SQL queries and transactions.
|
|
38
|
+
*
|
|
39
|
+
* The `biome-ignore` comments are used to suppress linting warnings for non-null assertions.
|
|
40
|
+
*
|
|
41
|
+
* @see {@link createClient}
|
|
42
|
+
* @see {@link closeOnOutsideClick}
|
|
43
|
+
* @see {@link transformTursoResult}
|
|
44
|
+
*/
|
|
45
|
+
declare const _default: import("astro").DevToolbarApp;
|
|
46
|
+
export default _default;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { dbEnv } from "virtual:studiocms-devapps/config";
|
|
2
|
+
import { createClient } from "@libsql/client/web";
|
|
3
|
+
import { transformTursoResult } from "@outerbase/sdk-transform";
|
|
4
|
+
import { defineToolbarApp } from "astro/toolbar";
|
|
5
|
+
import { closeOnOutsideClick } from "../utils/app-utils.js";
|
|
6
|
+
const sqlLiteUrl = "https://studio.outerbase.com/embed/sqlite?theme=dark";
|
|
7
|
+
const tursoURL = "https://studio.outerbase.com/embed/turso?theme=dark";
|
|
8
|
+
function getIFrameSrc(dbUrl) {
|
|
9
|
+
if (dbUrl.includes("turso.io")) {
|
|
10
|
+
return tursoURL;
|
|
11
|
+
}
|
|
12
|
+
return sqlLiteUrl;
|
|
13
|
+
}
|
|
14
|
+
var libsql_viewer_default = defineToolbarApp({
|
|
15
|
+
init(canvas, eventTarget) {
|
|
16
|
+
const appWindow = document.createElement("astro-dev-toolbar-window");
|
|
17
|
+
appWindow.style.width = "95%";
|
|
18
|
+
appWindow.style.height = "95%";
|
|
19
|
+
closeOnOutsideClick(eventTarget);
|
|
20
|
+
const viewerIframe = document.createElement("iframe");
|
|
21
|
+
viewerIframe.src = getIFrameSrc(dbEnv.remoteUrl);
|
|
22
|
+
viewerIframe.id = "sqlIframe";
|
|
23
|
+
viewerIframe.title = "libSQL Database Viewer";
|
|
24
|
+
Object.assign(viewerIframe.dataset, {
|
|
25
|
+
url: dbEnv.remoteUrl,
|
|
26
|
+
authtoken: dbEnv.token
|
|
27
|
+
});
|
|
28
|
+
Object.assign(viewerIframe.style, {
|
|
29
|
+
height: "100%",
|
|
30
|
+
width: "100%",
|
|
31
|
+
border: "1px solid rgba(27, 30, 36, 1)"
|
|
32
|
+
});
|
|
33
|
+
appWindow.appendChild(viewerIframe);
|
|
34
|
+
const client = createClient({
|
|
35
|
+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
36
|
+
url: viewerIframe.dataset.url,
|
|
37
|
+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
38
|
+
authToken: viewerIframe.dataset.authtoken
|
|
39
|
+
});
|
|
40
|
+
window.addEventListener("message", async (e) => {
|
|
41
|
+
const contentWindow = viewerIframe.contentWindow;
|
|
42
|
+
if (contentWindow && e.data) {
|
|
43
|
+
const { type, id, statement, statements } = e.data;
|
|
44
|
+
if (type === "query" && statement) {
|
|
45
|
+
try {
|
|
46
|
+
const result = await client.execute(statement);
|
|
47
|
+
contentWindow.postMessage(
|
|
48
|
+
{
|
|
49
|
+
type,
|
|
50
|
+
id,
|
|
51
|
+
data: transformTursoResult(result)
|
|
52
|
+
},
|
|
53
|
+
"*"
|
|
54
|
+
);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
contentWindow.postMessage(
|
|
57
|
+
{
|
|
58
|
+
type,
|
|
59
|
+
id,
|
|
60
|
+
error: err.message
|
|
61
|
+
},
|
|
62
|
+
"*"
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
} else if (type === "transaction" && statements) {
|
|
66
|
+
try {
|
|
67
|
+
const result = await client.batch(statements, "write");
|
|
68
|
+
contentWindow.postMessage(
|
|
69
|
+
{
|
|
70
|
+
type,
|
|
71
|
+
id,
|
|
72
|
+
data: result.map(transformTursoResult)
|
|
73
|
+
},
|
|
74
|
+
"*"
|
|
75
|
+
);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
contentWindow.postMessage(
|
|
78
|
+
{
|
|
79
|
+
type,
|
|
80
|
+
id,
|
|
81
|
+
error: err.message
|
|
82
|
+
},
|
|
83
|
+
"*"
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
canvas.appendChild(appWindow);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
export {
|
|
93
|
+
libsql_viewer_default as default,
|
|
94
|
+
getIFrameSrc
|
|
95
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a toolbar application for importing content from a WordPress site into StudioCMS.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} canvas - The canvas element where the application will be rendered.
|
|
5
|
+
* @param {Object} eventTarget - The target element for event listeners.
|
|
6
|
+
*
|
|
7
|
+
* @returns {Object} - The toolbar application definition.
|
|
8
|
+
*
|
|
9
|
+
* @function init
|
|
10
|
+
* Initializes the toolbar application by creating the canvas and setting up event listeners.
|
|
11
|
+
*
|
|
12
|
+
* @function createCanvas
|
|
13
|
+
* Creates and appends the main window component to the canvas. Sets up the form and its event listeners.
|
|
14
|
+
*
|
|
15
|
+
* @function closeOnOutsideClick
|
|
16
|
+
* Closes the window component when a click is detected outside of the specified event target.
|
|
17
|
+
*
|
|
18
|
+
* @event 'astro:after-swap'
|
|
19
|
+
* Recreates the canvas when the 'astro:after-swap' event is triggered.
|
|
20
|
+
*
|
|
21
|
+
* @event 'submit'
|
|
22
|
+
* Handles the form submission, including validation, showing a loading spinner, and making a POST request to the WordPress API endpoint.
|
|
23
|
+
*
|
|
24
|
+
* @constant {string} wpAPIEndpoint - The endpoint URL for the WordPress API.
|
|
25
|
+
*
|
|
26
|
+
* @typedef {Object} FormData
|
|
27
|
+
* Represents the form data to be sent in the POST request.
|
|
28
|
+
*
|
|
29
|
+
* @typedef {Object} Response
|
|
30
|
+
* Represents the response from the WordPress API.
|
|
31
|
+
*
|
|
32
|
+
* @typedef {Object} HTMLFormElement
|
|
33
|
+
* Represents the form element in the DOM.
|
|
34
|
+
*
|
|
35
|
+
* @typedef {Object} HTMLInputElement
|
|
36
|
+
* Represents the input element in the DOM.
|
|
37
|
+
*
|
|
38
|
+
* @typedef {Object} HTMLSelectElement
|
|
39
|
+
* Represents the select element in the DOM.
|
|
40
|
+
*/
|
|
41
|
+
declare const _default: import("astro").DevToolbarApp;
|
|
42
|
+
export default _default;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { wpAPIEndpoint } from "virtual:studiocms-devapps/endpoints";
|
|
2
|
+
import { defineToolbarApp } from "astro/toolbar";
|
|
3
|
+
import { closeOnOutsideClick, createWindowElement } from "../utils/app-utils.js";
|
|
4
|
+
var wp_importer_default = defineToolbarApp({
|
|
5
|
+
init(canvas, eventTarget) {
|
|
6
|
+
createCanvas();
|
|
7
|
+
document.addEventListener("astro:after-swap", createCanvas);
|
|
8
|
+
closeOnOutsideClick(eventTarget);
|
|
9
|
+
function createCanvas() {
|
|
10
|
+
const windowComponent = createWindowElement(
|
|
11
|
+
`<style>
|
|
12
|
+
#main-container {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
height: 100%;
|
|
16
|
+
gap: 24px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
p {
|
|
20
|
+
margin-top: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
header {
|
|
24
|
+
display: flex;
|
|
25
|
+
justify-content: space-between;
|
|
26
|
+
align-items: center;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
header section {
|
|
30
|
+
display: flex;
|
|
31
|
+
gap: 0.8em;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
header h2 {
|
|
35
|
+
align-items: center;
|
|
36
|
+
font-size: 28px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
h2 {
|
|
40
|
+
color: white;
|
|
41
|
+
margin: 0;
|
|
42
|
+
font-size: 18px;
|
|
43
|
+
align-items: center;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.form-container {
|
|
47
|
+
max-width: 600px;
|
|
48
|
+
margin: 0 auto;
|
|
49
|
+
padding: 16px;
|
|
50
|
+
border: 1px solid #ccc;
|
|
51
|
+
border-radius: 8px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.form-group {
|
|
55
|
+
margin-bottom: 12px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
label {
|
|
59
|
+
display: block;
|
|
60
|
+
margin-bottom: 5px;
|
|
61
|
+
font-weight: bold;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
input[type="text"], select {
|
|
65
|
+
width: 100%;
|
|
66
|
+
padding: 10px;
|
|
67
|
+
border: 1px solid #ccc;
|
|
68
|
+
border-radius: 4px;
|
|
69
|
+
box-sizing: border-box;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.required {
|
|
73
|
+
color: red;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.checkbox-group {
|
|
77
|
+
display: flex;
|
|
78
|
+
flex-direction: column;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.checkbox-item {
|
|
82
|
+
margin-bottom: 10px;
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.submit-btn {
|
|
88
|
+
padding: 10px 20px;
|
|
89
|
+
background-color: #007bff;
|
|
90
|
+
color: white;
|
|
91
|
+
border: none;
|
|
92
|
+
border-radius: 4px;
|
|
93
|
+
cursor: pointer;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.submit-btn:hover {
|
|
97
|
+
background-color: #0056b3;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.loading-spinner {
|
|
101
|
+
display: none; /* Hidden by default */
|
|
102
|
+
margin: 0 1rem;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.loading-active .loading-spinner {
|
|
106
|
+
display: block;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.form-submit {
|
|
110
|
+
display: flex;
|
|
111
|
+
align-items: center;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
</style>
|
|
115
|
+
|
|
116
|
+
<header>
|
|
117
|
+
<section>
|
|
118
|
+
<h2><svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24"><path fill="currentColor" d="M12 2C6.49 2 2 6.49 2 12s4.49 10 10 10s10-4.49 10-10S17.51 2 12 2M3.01 12c0-1.3.28-2.54.78-3.66l4.29 11.75c-3-1.46-5.07-4.53-5.07-8.09M12 20.99c-.88 0-1.73-.13-2.54-.37l2.7-7.84l2.76 7.57c.02.04.04.09.06.12c-.93.34-1.93.52-2.98.52m1.24-13.21c.54-.03 1.03-.09 1.03-.09c.48-.06.43-.77-.06-.74c0 0-1.46.11-2.4.11c-.88 0-2.37-.11-2.37-.11c-.48-.02-.54.72-.05.75c0 0 .46.06.94.09l1.4 3.84l-1.97 5.9l-3.27-9.75c.54-.02 1.03-.08 1.03-.08c.48-.06.43-.77-.06-.74c0 0-1.46.11-2.4.11c-.17 0-.37 0-.58-.01C6.1 4.62 8.86 3.01 12 3.01c2.34 0 4.47.89 6.07 2.36c-.04 0-.08-.01-.12-.01c-.88 0-1.51.77-1.51 1.6c0 .74.43 1.37.88 2.11c.34.6.74 1.37.74 2.48c0 .77-.3 1.66-.68 2.91l-.9 3zm6.65-.09a8.99 8.99 0 0 1-3.37 12.08l2.75-7.94c.51-1.28.68-2.31.68-3.22c0-.33-.02-.64-.06-.92"/></svg> Wordpress Importer</h2>
|
|
119
|
+
</section>
|
|
120
|
+
</header>
|
|
121
|
+
<hr />
|
|
122
|
+
|
|
123
|
+
<div id="main-container">
|
|
124
|
+
<div class="importer">
|
|
125
|
+
<p class="importer-description">Import posts and pages into StudioCMS from a WordPress site. <br />(Requires StudioCMS)</p>
|
|
126
|
+
<section id="importer-body">
|
|
127
|
+
<form id="importer-form">
|
|
128
|
+
<div class="form-container">
|
|
129
|
+
<div class="form-group">
|
|
130
|
+
<label for="importer-url">WordPress URL<span class="required">*</span></label>
|
|
131
|
+
<input type="text" id="importer-url" name="importer-url" placeholder="https://your-domain.com" required>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<div class="form-group">
|
|
135
|
+
<label for="importer-type">Import Type<span class="required">*</span></label>
|
|
136
|
+
<select id="importer-type" name="importer-type" required>
|
|
137
|
+
<option value="pages" selected>Pages</option>
|
|
138
|
+
<option value="posts">Posts</option>
|
|
139
|
+
<option value="settings">Site Settings (This option will override your StudioCMS Site Config)</option>
|
|
140
|
+
</select>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<div class="form-group">
|
|
144
|
+
<label for="importer-plugins">Use Plugins</label>
|
|
145
|
+
<div class="checkbox-group">
|
|
146
|
+
<div class="checkbox-item">
|
|
147
|
+
<input type="checkbox" id="importer-plugins-0" name="importer-plugins[]" value="blog-plugin">
|
|
148
|
+
<label for="importer-plugins-0">@studiocms/blog (Available for the Posts type)</label>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
|
|
153
|
+
<div class="form-group form-submit">
|
|
154
|
+
<button type="submit" class="submit-btn">Submit</button>
|
|
155
|
+
<div class="loading-spinner">
|
|
156
|
+
<!-- SVG for loading -->
|
|
157
|
+
<svg xmlns="http://www.w3.org/2000/svg" style="margin:auto; background:none; display:block;" width="50px" height="50px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
|
|
158
|
+
<circle cx="50" cy="50" fill="none" stroke="#007bff" stroke-width="8" r="35" stroke-dasharray="164.93361431346415 56.97787143782138">
|
|
159
|
+
<animateTransform attributeName="transform" type="rotate" repeatCount="indefinite" dur="1s" values="0 50 50;360 50 50" keyTimes="0;1"></animateTransform>
|
|
160
|
+
</circle>
|
|
161
|
+
</svg>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
</form>
|
|
166
|
+
</section>
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
`
|
|
170
|
+
);
|
|
171
|
+
const form = windowComponent.querySelector("#importer-form");
|
|
172
|
+
form?.addEventListener("submit", async (event) => {
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
form.classList.add("loading-active");
|
|
175
|
+
const url = form.querySelector("#importer-url")?.value;
|
|
176
|
+
const type = form.querySelector("#importer-type")?.value;
|
|
177
|
+
const plugins = form.querySelectorAll(
|
|
178
|
+
'input[name="importer-plugins[]"]:checked'
|
|
179
|
+
);
|
|
180
|
+
const useBlogPlugin = Array.from(plugins).some(
|
|
181
|
+
(checkbox) => checkbox.value === "blog-plugin"
|
|
182
|
+
);
|
|
183
|
+
if (!url || !type) {
|
|
184
|
+
alert("Please fill in the required fields");
|
|
185
|
+
form.classList.remove("loading-active");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const formData = new FormData();
|
|
189
|
+
formData.append("url", url);
|
|
190
|
+
formData.append("type", type);
|
|
191
|
+
formData.append("useBlogPlugin", useBlogPlugin ? "true" : "false");
|
|
192
|
+
console.log("formData", formData);
|
|
193
|
+
const response = await fetch(wpAPIEndpoint, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
body: formData
|
|
196
|
+
});
|
|
197
|
+
const responseStatus = response.status;
|
|
198
|
+
const responseText = response.statusText;
|
|
199
|
+
form.classList.remove("loading-active");
|
|
200
|
+
if (responseStatus === 200) {
|
|
201
|
+
alert(
|
|
202
|
+
"Imported successfully! You can now view/edit the imported content in your StudioCMS dashboard."
|
|
203
|
+
);
|
|
204
|
+
} else {
|
|
205
|
+
alert(`Failed to import: ${responseText}`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
canvas.append(windowComponent);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
export {
|
|
213
|
+
wp_importer_default as default
|
|
214
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro';
|
|
2
|
+
import { type StudioCMSDevAppsOptions } from './schema/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Integrates StudioCMS development applications with Astro.
|
|
5
|
+
*
|
|
6
|
+
* @param {StudioCMSDevAppsOptions} [opts] - Optional configuration options for StudioCMS DevApps.
|
|
7
|
+
* @returns {AstroIntegration} The Astro integration object for StudioCMS DevApps.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This function sets up the StudioCMS development applications for use in an Astro project.
|
|
11
|
+
* It parses the provided options, sets up virtual imports, and adds development toolbar apps
|
|
12
|
+
* based on the configuration.
|
|
13
|
+
*
|
|
14
|
+
* The integration is enforced to run only in development mode.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { studioCMSDevApps } from '@studiocms/devapps';
|
|
19
|
+
*
|
|
20
|
+
* export default {
|
|
21
|
+
* integrations: [
|
|
22
|
+
* studioCMSDevApps({
|
|
23
|
+
* endpoint: '/api',
|
|
24
|
+
* appsConfig: {
|
|
25
|
+
* wpImporter: {
|
|
26
|
+
* enabled: true,
|
|
27
|
+
* endpoint: '/wp-import',
|
|
28
|
+
* },
|
|
29
|
+
* libSQLViewer: {
|
|
30
|
+
* enabled: true,
|
|
31
|
+
* },
|
|
32
|
+
* },
|
|
33
|
+
* verbose: true,
|
|
34
|
+
* }),
|
|
35
|
+
* ],
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function studioCMSDevApps(opts?: StudioCMSDevAppsOptions): AstroIntegration;
|
|
40
|
+
export default studioCMSDevApps;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { addVirtualImports, createResolver, injectDevRoute } from "astro-integration-kit";
|
|
2
|
+
import { loadEnv } from "vite";
|
|
3
|
+
import { StudioCMSDevAppsSchema } from "./schema/index.js";
|
|
4
|
+
import { pathGenerator } from "./utils/pathGenerator.js";
|
|
5
|
+
function studioCMSDevApps(opts) {
|
|
6
|
+
const options = StudioCMSDevAppsSchema.parse(opts);
|
|
7
|
+
const { resolve } = createResolver(import.meta.url);
|
|
8
|
+
let makeEndpointPath;
|
|
9
|
+
const astroDbEnv = loadEnv("all", process.cwd(), "ASTRO_DB");
|
|
10
|
+
return {
|
|
11
|
+
name: "@studiocms/devapps",
|
|
12
|
+
hooks: {
|
|
13
|
+
"astro:config:setup": (params) => {
|
|
14
|
+
const { config, logger, addDevToolbarApp, command } = params;
|
|
15
|
+
makeEndpointPath = pathGenerator(options.endpoint, config.base);
|
|
16
|
+
options.verbose && logger.info("Setting up StudioCMS DevApps");
|
|
17
|
+
if (command === "dev") {
|
|
18
|
+
const wpAPIPath = makeEndpointPath(options.appsConfig.wpImporter.endpoint);
|
|
19
|
+
addVirtualImports(params, {
|
|
20
|
+
name: "@studiocms/devapps",
|
|
21
|
+
imports: {
|
|
22
|
+
"virtual:studiocms-devapps/endpoints": `
|
|
23
|
+
export const wpAPIEndpoint = "${wpAPIPath}";
|
|
24
|
+
`,
|
|
25
|
+
"virtual:studiocms-devapps/config": `
|
|
26
|
+
export const userProjectRoot = "${config.root.pathname}";
|
|
27
|
+
|
|
28
|
+
export const dbEnv = {
|
|
29
|
+
remoteUrl: "${astroDbEnv.ASTRO_DB_REMOTE_URL}",
|
|
30
|
+
token: "${astroDbEnv.ASTRO_DB_APP_TOKEN}",
|
|
31
|
+
};
|
|
32
|
+
`
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (options.appsConfig.libSQLViewer.enabled) {
|
|
36
|
+
options.verbose && logger.info("Adding Dev Toolbar App: LibSQL Viewer");
|
|
37
|
+
addDevToolbarApp({
|
|
38
|
+
name: "LibSQL Viewer",
|
|
39
|
+
id: "studiocms-devapps-libsql-viewer",
|
|
40
|
+
entrypoint: resolve("./apps/libsql-viewer.js"),
|
|
41
|
+
icon: '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M20.25 6.375c0 2.278-3.694 4.125-8.25 4.125S3.75 8.653 3.75 6.375m16.5 0c0-2.278-3.694-4.125-8.25-4.125S3.75 4.097 3.75 6.375m16.5 0v11.25c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125V6.375m16.5 0v3.75m-16.5-3.75v3.75m16.5 0v3.75C20.25 16.153 16.556 18 12 18s-8.25-1.847-8.25-4.125v-3.75m16.5 0c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125" /></svg>'
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (options.appsConfig.wpImporter.enabled) {
|
|
45
|
+
options.verbose && logger.info("Adding Dev Toolbar App: WP API Importer");
|
|
46
|
+
injectDevRoute(params, {
|
|
47
|
+
entrypoint: resolve("./routes/wp-importer.js"),
|
|
48
|
+
pattern: wpAPIPath
|
|
49
|
+
});
|
|
50
|
+
addDevToolbarApp({
|
|
51
|
+
name: "Wordpress API Importer",
|
|
52
|
+
id: "studiocms-devapps-wp-api-importer",
|
|
53
|
+
entrypoint: resolve("./apps/wp-importer.js"),
|
|
54
|
+
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="currentColor" d="M12 2C6.49 2 2 6.49 2 12s4.49 10 10 10s10-4.49 10-10S17.51 2 12 2M3.01 12c0-1.3.28-2.54.78-3.66l4.29 11.75c-3-1.46-5.07-4.53-5.07-8.09M12 20.99c-.88 0-1.73-.13-2.54-.37l2.7-7.84l2.76 7.57c.02.04.04.09.06.12c-.93.34-1.93.52-2.98.52m1.24-13.21c.54-.03 1.03-.09 1.03-.09c.48-.06.43-.77-.06-.74c0 0-1.46.11-2.4.11c-.88 0-2.37-.11-2.37-.11c-.48-.02-.54.72-.05.75c0 0 .46.06.94.09l1.4 3.84l-1.97 5.9l-3.27-9.75c.54-.02 1.03-.08 1.03-.08c.48-.06.43-.77-.06-.74c0 0-1.46.11-2.4.11c-.17 0-.37 0-.58-.01C6.1 4.62 8.86 3.01 12 3.01c2.34 0 4.47.89 6.07 2.36c-.04 0-.08-.01-.12-.01c-.88 0-1.51.77-1.51 1.6c0 .74.43 1.37.88 2.11c.34.6.74 1.37.74 2.48c0 .77-.3 1.66-.68 2.91l-.9 3zm6.65-.09a8.99 8.99 0 0 1-3.37 12.08l2.75-7.94c.51-1.28.68-2.31.68-3.22c0-.33-.02-.64-.06-.92"/></svg>'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var index_default = studioCMSDevApps;
|
|
63
|
+
export {
|
|
64
|
+
index_default as default,
|
|
65
|
+
studioCMSDevApps
|
|
66
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
/**
|
|
3
|
+
* Handles the POST request for importing data from a WordPress site.
|
|
4
|
+
*
|
|
5
|
+
* @param {APIContext} context - The context of the API request.
|
|
6
|
+
* @param {Request} context.request - The incoming request object.
|
|
7
|
+
*
|
|
8
|
+
* @returns {Promise<Response>} The response object indicating the result of the import operation.
|
|
9
|
+
*
|
|
10
|
+
* The function expects the request to contain form data with the following fields:
|
|
11
|
+
* - `url`: The URL of the WordPress site to import data from.
|
|
12
|
+
* - `type`: The type of data to import (e.g., 'pages', 'posts', 'settings').
|
|
13
|
+
* - `useBlogPlugin` (optional): A boolean value indicating whether to use the blog plugin for importing posts.
|
|
14
|
+
*
|
|
15
|
+
* The function performs the following steps:
|
|
16
|
+
* 1. Extracts the form data from the request.
|
|
17
|
+
* 2. Validates the presence and types of the `url` and `type` fields.
|
|
18
|
+
* 3. Logs the import operation details.
|
|
19
|
+
* 4. Based on the `type` field, calls the appropriate import function:
|
|
20
|
+
* - `importPagesFromWPAPI` for importing pages.
|
|
21
|
+
* - `importPostsFromWPAPI` for importing posts, optionally using the blog plugin.
|
|
22
|
+
* - `importSettingsFromWPAPI` for importing settings.
|
|
23
|
+
* 5. Returns a response indicating success or failure.
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} If the `type` field contains an invalid value.
|
|
26
|
+
*/
|
|
27
|
+
export declare const POST: APIRoute;
|