@silexlabs/silex 3.0.0-alpha.49 → 3.0.0-alpha.51
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/client/client/config.d.ts +14 -1
- package/dist/client/client/grapesjs/PublicationManager.d.ts +2 -7
- package/dist/client/client/publication-transformers.d.ts +41 -0
- package/dist/client/css/admin.css +4 -1
- package/dist/client/js/main.js +3 -3
- package/dist/client/types.d.ts +18 -16
- package/dist/plugins/client/client/api.d.ts +83 -0
- package/dist/plugins/client/client/api.js +105 -0
- package/dist/plugins/client/client/api.js.map +1 -0
- package/dist/plugins/client/client/config.d.ts +58 -0
- package/dist/plugins/client/client/config.js +80 -0
- package/dist/plugins/client/client/config.js.map +1 -0
- package/dist/plugins/client/client/events.js +2 -0
- package/dist/plugins/client/client/events.js.map +1 -1
- package/dist/plugins/client/client/grapesjs/LoginDialog.d.ts +15 -0
- package/dist/plugins/client/client/grapesjs/LoginDialog.js +193 -0
- package/dist/plugins/client/client/grapesjs/LoginDialog.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.d.ts +70 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.js +310 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.d.ts +61 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.js +324 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/blocks.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/blocks.js +37 -0
- package/dist/plugins/client/client/grapesjs/blocks.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/index.d.ts +5 -0
- package/dist/plugins/client/client/grapesjs/index.js +264 -0
- package/dist/plugins/client/client/grapesjs/index.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/internal-links.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/internal-links.js +220 -0
- package/dist/plugins/client/client/grapesjs/internal-links.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.d.ts +2 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.js +83 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/openImport.d.ts +9 -0
- package/dist/plugins/client/client/grapesjs/openImport.js +74 -0
- package/dist/plugins/client/client/grapesjs/openImport.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/page-panel.d.ts +3 -0
- package/dist/plugins/client/client/grapesjs/page-panel.js +113 -0
- package/dist/plugins/client/client/grapesjs/page-panel.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/project-bar.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/project-bar.js +106 -0
- package/dist/plugins/client/client/grapesjs/project-bar.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/rich-text.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/rich-text.js +31 -0
- package/dist/plugins/client/client/grapesjs/rich-text.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/semantic.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/semantic.js +110 -0
- package/dist/plugins/client/client/grapesjs/semantic.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/settings.d.ts +2 -0
- package/dist/plugins/client/client/grapesjs/settings.js +197 -0
- package/dist/plugins/client/client/grapesjs/settings.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/storage.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/storage.js +124 -0
- package/dist/plugins/client/client/grapesjs/storage.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.d.ts +3 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.js +36 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.js.map +1 -0
- package/dist/plugins/client/client/publication-transformers.d.ts +41 -0
- package/dist/plugins/client/client/publication-transformers.js +165 -0
- package/dist/plugins/client/client/publication-transformers.js.map +1 -0
- package/dist/plugins/client/constants.d.ts +29 -0
- package/dist/plugins/client/constants.js +46 -0
- package/dist/plugins/client/constants.js.map +1 -0
- package/dist/plugins/client/plugins/client/11ty.d.ts +17 -0
- package/dist/plugins/client/plugins/client/11ty.js +70 -0
- package/dist/plugins/client/plugins/client/11ty.js.map +1 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.js +59 -21
- package/dist/plugins/client/plugins/client/publicationRenderer.js.map +1 -1
- package/dist/plugins/client/plugins/client/website-info.js +1 -1
- package/dist/plugins/client/plugins/client/website-info.js.map +1 -1
- package/dist/plugins/client/types.d.ts +18 -16
- package/dist/plugins/client/types.js.map +1 -1
- package/dist/plugins/server/plugins/server/FtpConnector.d.ts +2 -1
- package/dist/plugins/server/plugins/server/FtpConnector.js +5 -6
- package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -1
- package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +1 -7
- package/dist/plugins/server/plugins/server/GitlabConnector.js +124 -112
- package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -1
- package/dist/plugins/server/server/connectors/FsHosting.d.ts +2 -1
- package/dist/plugins/server/server/connectors/FsHosting.js +4 -5
- package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -1
- package/dist/plugins/server/server/connectors/FsStorage.js +1 -0
- package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -1
- package/dist/plugins/server/server/connectors/connectors.d.ts +2 -1
- package/dist/plugins/server/server/connectors/connectors.js.map +1 -1
- package/dist/plugins/server/server/jobs.d.ts +6 -0
- package/dist/plugins/server/server/jobs.js +3 -1
- package/dist/plugins/server/server/jobs.js.map +1 -1
- package/dist/plugins/server/types.d.ts +18 -16
- package/dist/plugins/server/types.js.map +1 -1
- package/dist/server/server/api/publicationApi.js +14 -20
- package/dist/server/server/connectors/FsHosting.js +4 -5
- package/dist/server/server/connectors/FsStorage.js +1 -0
- package/dist/server/server/jobs.js +2 -1
- package/package.json +1 -1
- package/public/silex.js +23 -0
- package/src/css/website-info.scss +4 -1
- package/src/ts/client/config.ts +22 -2
- package/src/ts/client/events.ts +3 -0
- package/src/ts/client/grapesjs/PublicationManager.ts +23 -3
- package/src/ts/client/grapesjs/internal-links.ts +0 -2
- package/src/ts/client/grapesjs/storage.ts +1 -1
- package/src/ts/client/index.ts +4 -0
- package/src/ts/client/publication-transformers.test.ts +146 -0
- package/src/ts/client/publication-transformers.ts +188 -0
- package/src/ts/plugins/client/11ty.ts +89 -0
- package/src/ts/plugins/client/publicationRenderer.ts +64 -22
- package/src/ts/plugins/client/website-info.ts +1 -1
- package/src/ts/plugins/server/FtpConnector.ts +3 -3
- package/src/ts/plugins/server/GitlabConnector.ts +128 -109
- package/src/ts/server/api/publicationApi.ts +16 -23
- package/src/ts/server/connectors/FsHosting.ts +2 -2
- package/src/ts/server/connectors/FsStorage.ts +1 -0
- package/src/ts/server/connectors/connectors.ts +3 -1
- package/src/ts/server/jobs.ts +10 -0
- package/src/ts/server/utils/BackwardCompat.ts +530 -529
- package/src/ts/types.ts +20 -17
package/dist/client/types.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export interface PublicationSettings {
|
|
|
5
5
|
connector?: ConnectorData;
|
|
6
6
|
options?: ConnectorOptions;
|
|
7
7
|
url?: string;
|
|
8
|
-
autoHomePage?: boolean;
|
|
9
8
|
}
|
|
10
9
|
export interface WebsiteFile {
|
|
11
10
|
html: string;
|
|
@@ -137,7 +136,7 @@ export type ApiConnectorUserQuery = {
|
|
|
137
136
|
export type ApiConnectorUserResponse = ConnectorUser;
|
|
138
137
|
export declare const defaultWebsiteData: WebsiteData;
|
|
139
138
|
export interface WebsiteData {
|
|
140
|
-
pages:
|
|
139
|
+
pages: any[];
|
|
141
140
|
assets: Asset[];
|
|
142
141
|
styles: Style[];
|
|
143
142
|
settings: WebsiteSettings;
|
|
@@ -146,7 +145,7 @@ export interface WebsiteData {
|
|
|
146
145
|
publication: PublicationSettings;
|
|
147
146
|
}
|
|
148
147
|
export interface PublicationData extends WebsiteData {
|
|
149
|
-
files?:
|
|
148
|
+
files?: ClientSideFile[];
|
|
150
149
|
}
|
|
151
150
|
export interface WebsiteSettings {
|
|
152
151
|
description?: string;
|
|
@@ -163,16 +162,6 @@ export interface Font {
|
|
|
163
162
|
value: string;
|
|
164
163
|
variants: string[];
|
|
165
164
|
}
|
|
166
|
-
export interface Page {
|
|
167
|
-
name?: string;
|
|
168
|
-
id: string;
|
|
169
|
-
type?: string;
|
|
170
|
-
frames: Frame[];
|
|
171
|
-
settings?: WebsiteSettings;
|
|
172
|
-
cssExt?: string;
|
|
173
|
-
htmlExt?: string;
|
|
174
|
-
slug?: string;
|
|
175
|
-
}
|
|
176
165
|
export interface Frame {
|
|
177
166
|
component: {
|
|
178
167
|
type: string;
|
|
@@ -216,13 +205,26 @@ export type Selector = string | {
|
|
|
216
205
|
export type ConnectorId = string;
|
|
217
206
|
export type ConnectorOptions = object;
|
|
218
207
|
/**
|
|
219
|
-
* Type for a client side file
|
|
220
|
-
* @see connector/File
|
|
208
|
+
* Type for a client side file when the content is available as a string
|
|
221
209
|
*/
|
|
222
|
-
export interface
|
|
210
|
+
export interface ClientSideFileWithContent {
|
|
223
211
|
path: string;
|
|
224
212
|
content: string;
|
|
213
|
+
type: 'html' | 'asset' | 'css';
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Type for a client side file when the content is in the storage connector
|
|
217
|
+
*/
|
|
218
|
+
export interface ClientSideFileWithSrc {
|
|
219
|
+
path: string;
|
|
220
|
+
src: string;
|
|
221
|
+
type: 'html' | 'asset' | 'css';
|
|
225
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Type for a client side file
|
|
225
|
+
* @see connector/File
|
|
226
|
+
*/
|
|
227
|
+
export type ClientSideFile = ClientSideFileWithContent | ClientSideFileWithSrc;
|
|
226
228
|
/**
|
|
227
229
|
* Type for file listing
|
|
228
230
|
*/
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ConnectorId, JobId, PublicationJobData, WebsiteId, ConnectorData, ConnectorType, WebsiteData, ClientSideFile, PublicationData, ConnectorUser, WebsiteMeta, WebsiteMetaFileContent, ConnectorOptions } from '../types';
|
|
2
|
+
export declare enum ApiRoute {
|
|
3
|
+
PUBLICATION_PUBLISH = "/api/publication/",
|
|
4
|
+
PUBLICATION_STATUS = "/api/publication/publication/status",
|
|
5
|
+
CONNECTOR_USER = "/api/connector/user",
|
|
6
|
+
CONNECTOR_LOGOUT = "/api/connector/logout",
|
|
7
|
+
CONNECTOR_LIST = "/api/connector/",
|
|
8
|
+
WEBSITE_READ = "/api/website/",
|
|
9
|
+
WEBSITE_WRITE = "/api/website/",
|
|
10
|
+
WEBSITE_DELETE = "/api/website/",
|
|
11
|
+
WEBSITE_CREATE = "/api/website/",
|
|
12
|
+
WEBSITE_LIST = "/api/website/",
|
|
13
|
+
WEBSITE_ASSETS_READ = "/api/website/assets",
|
|
14
|
+
WEBSITE_ASSETS_WRITE = "/api/website/assets",
|
|
15
|
+
WEBSITE_META_READ = "/api/website/meta",
|
|
16
|
+
WEBSITE_META_WRITE = "/api/website/meta"
|
|
17
|
+
}
|
|
18
|
+
export declare function getUser({ type, connectorId }: {
|
|
19
|
+
type: ConnectorType;
|
|
20
|
+
connectorId?: ConnectorId;
|
|
21
|
+
}): Promise<ConnectorUser>;
|
|
22
|
+
export declare function logout({ type, connectorId }: {
|
|
23
|
+
type: ConnectorType;
|
|
24
|
+
connectorId?: ConnectorId;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
export declare function publish({ websiteId, hostingId, storageId, data, options }: {
|
|
27
|
+
websiteId: WebsiteId;
|
|
28
|
+
hostingId: ConnectorId;
|
|
29
|
+
storageId: ConnectorId;
|
|
30
|
+
data: PublicationData;
|
|
31
|
+
options: ConnectorOptions;
|
|
32
|
+
}): Promise<[url: string, job: PublicationJobData]>;
|
|
33
|
+
export declare function publicationStatus({ jobId }: {
|
|
34
|
+
jobId: JobId;
|
|
35
|
+
}): Promise<PublicationJobData>;
|
|
36
|
+
export declare function connectorList({ type }: {
|
|
37
|
+
type: ConnectorType;
|
|
38
|
+
}): Promise<ConnectorData[]>;
|
|
39
|
+
export declare function websiteList({ connectorId }: {
|
|
40
|
+
connectorId?: ConnectorId;
|
|
41
|
+
}): Promise<WebsiteMeta[]>;
|
|
42
|
+
export declare function websiteLoad({ websiteId, connectorId }: {
|
|
43
|
+
websiteId: WebsiteId;
|
|
44
|
+
connectorId?: ConnectorId;
|
|
45
|
+
}): Promise<WebsiteData>;
|
|
46
|
+
export declare function websiteSave({ websiteId, data, connectorId }: {
|
|
47
|
+
websiteId: WebsiteId;
|
|
48
|
+
data: WebsiteData;
|
|
49
|
+
connectorId?: ConnectorId;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
export declare function websiteDelete({ websiteId, connectorId }: {
|
|
52
|
+
websiteId: WebsiteId;
|
|
53
|
+
connectorId?: ConnectorId;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
export declare function websiteCreate({ websiteId, data, connectorId }: {
|
|
56
|
+
websiteId: WebsiteId;
|
|
57
|
+
data: WebsiteMetaFileContent;
|
|
58
|
+
connectorId?: ConnectorId;
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
export declare function websiteMetaWrite({ websiteId, data, connectorId }: {
|
|
61
|
+
websiteId: WebsiteId;
|
|
62
|
+
data: WebsiteMetaFileContent;
|
|
63
|
+
connectorId?: ConnectorId;
|
|
64
|
+
}): Promise<void>;
|
|
65
|
+
export declare function websiteMetaRead({ websiteId, connectorId }: {
|
|
66
|
+
websiteId: WebsiteId;
|
|
67
|
+
connectorId?: ConnectorId;
|
|
68
|
+
}): Promise<WebsiteMeta>;
|
|
69
|
+
export declare function websiteAssetsLoad({ path, websiteId, connectorId }: {
|
|
70
|
+
path: string;
|
|
71
|
+
websiteId: WebsiteId;
|
|
72
|
+
connectorId: ConnectorId;
|
|
73
|
+
}): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Not used directly, grapesjs handles the upload
|
|
76
|
+
* @see assetManager in src/ts/client/grapesjs/index.ts
|
|
77
|
+
*/
|
|
78
|
+
export declare function websiteAssetsSave({ websiteId, connectorId, files }: {
|
|
79
|
+
websiteId: WebsiteId;
|
|
80
|
+
connectorId: ConnectorId;
|
|
81
|
+
files: ClientSideFile[];
|
|
82
|
+
}): Promise<string[]>;
|
|
83
|
+
export declare function api<ReqQuery, ReqBody, ResBody>(route: ApiRoute | string, method: string, query?: ReqQuery, payload?: ReqBody): Promise<ResBody>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
import { API_CONNECTOR_LIST, API_CONNECTOR_USER, API_CONNECTOR_LOGOUT, API_CONNECTOR_PATH, API_PATH, API_PUBLICATION_PATH, API_PUBLICATION_PUBLISH, API_PUBLICATION_STATUS, API_WEBSITE_ASSET_READ, API_WEBSITE_ASSETS_WRITE, API_WEBSITE_DELETE, API_WEBSITE_LIST, API_WEBSITE_PATH, API_WEBSITE_READ, API_WEBSITE_WRITE, API_WEBSITE_META_READ, API_WEBSITE_META_WRITE, API_WEBSITE_CREATE } from '../constants';
|
|
18
|
+
import { ApiError } from '../types';
|
|
19
|
+
export var ApiRoute;
|
|
20
|
+
(function (ApiRoute) {
|
|
21
|
+
ApiRoute["PUBLICATION_PUBLISH"] = "/api/publication/";
|
|
22
|
+
ApiRoute["PUBLICATION_STATUS"] = "/api/publication/publication/status";
|
|
23
|
+
ApiRoute["CONNECTOR_USER"] = "/api/connector/user";
|
|
24
|
+
ApiRoute["CONNECTOR_LOGOUT"] = "/api/connector/logout";
|
|
25
|
+
ApiRoute["CONNECTOR_LIST"] = "/api/connector/";
|
|
26
|
+
ApiRoute["WEBSITE_READ"] = "/api/website/";
|
|
27
|
+
ApiRoute["WEBSITE_WRITE"] = "/api/website/";
|
|
28
|
+
ApiRoute["WEBSITE_DELETE"] = "/api/website/";
|
|
29
|
+
ApiRoute["WEBSITE_CREATE"] = "/api/website/";
|
|
30
|
+
ApiRoute["WEBSITE_LIST"] = "/api/website/";
|
|
31
|
+
ApiRoute["WEBSITE_ASSETS_READ"] = "/api/website/assets";
|
|
32
|
+
ApiRoute["WEBSITE_ASSETS_WRITE"] = "/api/website/assets";
|
|
33
|
+
ApiRoute["WEBSITE_META_READ"] = "/api/website/meta";
|
|
34
|
+
ApiRoute["WEBSITE_META_WRITE"] = "/api/website/meta";
|
|
35
|
+
})(ApiRoute || (ApiRoute = {}));
|
|
36
|
+
const ROOT_URL = window.location.origin;
|
|
37
|
+
export async function getUser({ type, connectorId }) {
|
|
38
|
+
return api(ApiRoute.CONNECTOR_USER, 'GET', {
|
|
39
|
+
type,
|
|
40
|
+
connectorId,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export async function logout({ type, connectorId }) {
|
|
44
|
+
return api(ApiRoute.CONNECTOR_LOGOUT, 'POST', { connectorId, type });
|
|
45
|
+
}
|
|
46
|
+
export async function publish({ websiteId, hostingId, storageId, data, options }) {
|
|
47
|
+
const { url, job } = await api(ApiRoute.PUBLICATION_PUBLISH, 'POST', { websiteId, hostingId, storageId, options }, data);
|
|
48
|
+
return [url, job];
|
|
49
|
+
}
|
|
50
|
+
export async function publicationStatus({ jobId }) {
|
|
51
|
+
return api(ApiRoute.PUBLICATION_STATUS, 'GET', { jobId });
|
|
52
|
+
}
|
|
53
|
+
export async function connectorList({ type }) {
|
|
54
|
+
const list = await api(ApiRoute.CONNECTOR_LIST, 'GET', { type });
|
|
55
|
+
return list;
|
|
56
|
+
}
|
|
57
|
+
export async function websiteList({ connectorId }) {
|
|
58
|
+
return api(ApiRoute.WEBSITE_LIST, 'GET', { connectorId });
|
|
59
|
+
}
|
|
60
|
+
export async function websiteLoad({ websiteId, connectorId }) {
|
|
61
|
+
return api(ApiRoute.WEBSITE_READ, 'GET', { websiteId, connectorId: connectorId });
|
|
62
|
+
}
|
|
63
|
+
export async function websiteSave({ websiteId, data, connectorId }) {
|
|
64
|
+
const { message } = await api(ApiRoute.WEBSITE_WRITE, 'POST', { websiteId, connectorId: connectorId }, data);
|
|
65
|
+
}
|
|
66
|
+
export async function websiteDelete({ websiteId, connectorId }) {
|
|
67
|
+
await api(ApiRoute.WEBSITE_DELETE, 'DELETE', { websiteId, connectorId: connectorId });
|
|
68
|
+
}
|
|
69
|
+
export async function websiteCreate({ websiteId, data, connectorId }) {
|
|
70
|
+
await api(ApiRoute.WEBSITE_CREATE, 'PUT', { connectorId: connectorId }, data);
|
|
71
|
+
}
|
|
72
|
+
export async function websiteMetaWrite({ websiteId, data, connectorId }) {
|
|
73
|
+
await api(ApiRoute.WEBSITE_META_WRITE, 'POST', { websiteId, connectorId: connectorId }, data);
|
|
74
|
+
}
|
|
75
|
+
export async function websiteMetaRead({ websiteId, connectorId }) {
|
|
76
|
+
return api(ApiRoute.WEBSITE_META_WRITE, 'GET', { websiteId, connectorId });
|
|
77
|
+
}
|
|
78
|
+
export async function websiteAssetsLoad({ path, websiteId, connectorId }) {
|
|
79
|
+
return api(`${ApiRoute.WEBSITE_ASSETS_READ}/${path}`, 'GET', { websiteId, connectorId: connectorId });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Not used directly, grapesjs handles the upload
|
|
83
|
+
* @see assetManager in src/ts/client/grapesjs/index.ts
|
|
84
|
+
*/
|
|
85
|
+
export async function websiteAssetsSave({ websiteId, connectorId, files }) {
|
|
86
|
+
const { data } = await api(ApiRoute.WEBSITE_ASSETS_WRITE, 'POST', { websiteId, connectorId: connectorId }, files);
|
|
87
|
+
return data;
|
|
88
|
+
}
|
|
89
|
+
export async function api(route, method, query, payload) {
|
|
90
|
+
const url = `${ROOT_URL}${route.toString()}?${new URLSearchParams(Object.entries(query).filter(([key, value]) => !!value)).toString()}`;
|
|
91
|
+
const response = await fetch(url, {
|
|
92
|
+
method,
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/json',
|
|
95
|
+
},
|
|
96
|
+
body: payload && JSON.stringify(payload),
|
|
97
|
+
credentials: 'include', // sends the cookies with the request
|
|
98
|
+
});
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
const json = await response.json();
|
|
101
|
+
throw new ApiError(json.message, response.status);
|
|
102
|
+
}
|
|
103
|
+
return response.json();
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/ts/client/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAClZ,OAAO,EAA0+B,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE3gC,MAAM,CAAN,IAAY,QAeX;AAfD,WAAY,QAAQ;IACl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,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAA;IACvI,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM;QACN,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QACxC,WAAW,EAAE,SAAS,EAAE,qCAAqC;KAC9D,CAAC,CAAA;IAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;QAChB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAClC,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;KAClD;IAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Config } from '@silexlabs/silex-plugins';
|
|
2
|
+
import { ConnectorId, WebsiteId } from '../types';
|
|
3
|
+
import { Editor, EditorConfig } from 'grapesjs';
|
|
4
|
+
import { PublicationTransformer } from './publication-transformers';
|
|
5
|
+
import * as api from './api';
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Silex client side config
|
|
8
|
+
*/
|
|
9
|
+
export declare class ClientConfig extends Config {
|
|
10
|
+
api: typeof api;
|
|
11
|
+
/**
|
|
12
|
+
* The website to load
|
|
13
|
+
* This is the id of the website in the storage connector
|
|
14
|
+
*/
|
|
15
|
+
websiteId: WebsiteId;
|
|
16
|
+
/**
|
|
17
|
+
* The storage connector to use
|
|
18
|
+
* If not found in the URL and the user is not logged in to any storage, use the first storage
|
|
19
|
+
*/
|
|
20
|
+
storageId: ConnectorId;
|
|
21
|
+
/**
|
|
22
|
+
* language for I18n module
|
|
23
|
+
*/
|
|
24
|
+
lang: string;
|
|
25
|
+
/**
|
|
26
|
+
* root url of Silex app
|
|
27
|
+
*/
|
|
28
|
+
rootUrl: string;
|
|
29
|
+
/**
|
|
30
|
+
* debug mode
|
|
31
|
+
*/
|
|
32
|
+
debug: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Grapesjs config
|
|
35
|
+
*/
|
|
36
|
+
grapesJsConfig: EditorConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Client config url
|
|
39
|
+
* This is the url of the config file which is a plugin
|
|
40
|
+
*/
|
|
41
|
+
clientConfigUrl: string;
|
|
42
|
+
/**
|
|
43
|
+
* Init GrapesJS config which depend on the config file properties
|
|
44
|
+
*/
|
|
45
|
+
initGrapesConfig(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get grapesjs editor
|
|
48
|
+
*/
|
|
49
|
+
getEditor(): Editor;
|
|
50
|
+
/**
|
|
51
|
+
* Publication transformers let plugins change files before they are published
|
|
52
|
+
*/
|
|
53
|
+
publicationTransformers: Array<PublicationTransformer>;
|
|
54
|
+
/**
|
|
55
|
+
* Add a publication transformer(s)
|
|
56
|
+
*/
|
|
57
|
+
addPublicationTransformers(transformers: PublicationTransformer | PublicationTransformer[]): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
import { Config } from '@silexlabs/silex-plugins';
|
|
18
|
+
import { getEditor, getEditorConfig } from './grapesjs';
|
|
19
|
+
import { CLIENT_CONFIG_FILE_NAME, DEFAULT_LANGUAGE, DEFAULT_WEBSITE_ID } from '../constants';
|
|
20
|
+
import * as api from './api';
|
|
21
|
+
/**
|
|
22
|
+
* @fileoverview Silex client side config
|
|
23
|
+
*/
|
|
24
|
+
export class ClientConfig extends Config {
|
|
25
|
+
api = api;
|
|
26
|
+
/**
|
|
27
|
+
* The website to load
|
|
28
|
+
* This is the id of the website in the storage connector
|
|
29
|
+
*/
|
|
30
|
+
websiteId = new URL(location.href).searchParams.get('id') ?? DEFAULT_WEBSITE_ID;
|
|
31
|
+
/**
|
|
32
|
+
* The storage connector to use
|
|
33
|
+
* If not found in the URL and the user is not logged in to any storage, use the first storage
|
|
34
|
+
*/
|
|
35
|
+
storageId = new URL(location.href).searchParams.get('connectorId');
|
|
36
|
+
/**
|
|
37
|
+
* language for I18n module
|
|
38
|
+
*/
|
|
39
|
+
lang = new URL(location.href).searchParams.get('lang') ?? DEFAULT_LANGUAGE;
|
|
40
|
+
/**
|
|
41
|
+
* root url of Silex app
|
|
42
|
+
*/
|
|
43
|
+
rootUrl = window.location.origin;
|
|
44
|
+
/**
|
|
45
|
+
* debug mode
|
|
46
|
+
*/
|
|
47
|
+
debug = false;
|
|
48
|
+
/**
|
|
49
|
+
* Grapesjs config
|
|
50
|
+
*/
|
|
51
|
+
grapesJsConfig;
|
|
52
|
+
/**
|
|
53
|
+
* Client config url
|
|
54
|
+
* This is the url of the config file which is a plugin
|
|
55
|
+
*/
|
|
56
|
+
clientConfigUrl = `${this.rootUrl}/${CLIENT_CONFIG_FILE_NAME}`;
|
|
57
|
+
/**
|
|
58
|
+
* Init GrapesJS config which depend on the config file properties
|
|
59
|
+
*/
|
|
60
|
+
initGrapesConfig() {
|
|
61
|
+
this.grapesJsConfig = getEditorConfig(this.websiteId, this.storageId, this.rootUrl);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get grapesjs editor
|
|
65
|
+
*/
|
|
66
|
+
getEditor() {
|
|
67
|
+
return getEditor();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Publication transformers let plugins change files before they are published
|
|
71
|
+
*/
|
|
72
|
+
publicationTransformers = [];
|
|
73
|
+
/**
|
|
74
|
+
* Add a publication transformer(s)
|
|
75
|
+
*/
|
|
76
|
+
addPublicationTransformers(transformers) {
|
|
77
|
+
this.publicationTransformers = this.publicationTransformers.concat(transformers);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/ts/client/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAI5F,OAAO,KAAK,GAAG,MAAM,OAAO,CAAA;AAE5B;;GAEG;AAEH,MAAM,OAAO,YAAa,SAAQ,MAAM;IACtC,GAAG,GAAG,GAAG,CAAA;IAET;;;OAGG;IACH,SAAS,GAAc,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAA;IAE1F;;;OAGG;IACH,SAAS,GAAgB,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAE/E;;OAEG;IACH,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,gBAAgB,CAAA;IAE1E;;OAEG;IACH,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAA;IAEhC;;OAEG;IACH,KAAK,GAAG,KAAK,CAAA;IAEb;;OAEG;IACH,cAAc,CAAc;IAE5B;;;OAGG;IACH,eAAe,GAAG,GAAG,IAAI,CAAC,OAAO,IAAI,uBAAuB,EAAE,CAAA;IAE9D;;OAEG;IACH,gBAAgB;QACd,IAAI,CAAC,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IACrF,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,SAAS,EAAE,CAAA;IACpB,CAAC;IAED;;OAEG;IACH,uBAAuB,GAAkC,EAAE,CAAA;IAE3D;;OAEG;IACH,0BAA0B,CAAC,YAA+D;QACxF,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IAClF,CAAC;CACF"}
|
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export var ClientEvent;
|
|
18
18
|
(function (ClientEvent) {
|
|
19
|
+
// Sent on the config object
|
|
19
20
|
ClientEvent["STARTUP_START"] = "silex:startup:start";
|
|
20
21
|
ClientEvent["STARTUP_END"] = "silex:startup:end";
|
|
21
22
|
ClientEvent["GRAPESJS_START"] = "silex:grapesjs:start";
|
|
22
23
|
ClientEvent["GRAPESJS_END"] = "silex:grapesjs:end";
|
|
24
|
+
// Sent on the editor object
|
|
23
25
|
ClientEvent["PUBLISH_START"] = "silex:publish:start";
|
|
24
26
|
ClientEvent["PUBLISH_DATA"] = "silex:publish:data";
|
|
25
27
|
ClientEvent["PUBLISH_END"] = "silex:publish:end";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/ts/client/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/ts/client/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAN,IAAY,WAgBX;AAhBD,WAAY,WAAW;IACrB,4BAA4B;IAC5B,oDAAqC,CAAA;IACrC,gDAAiC,CAAA;IACjC,sDAAuC,CAAA;IACvC,kDAAmC,CAAA;IAEnC,4BAA4B;IAC5B,oDAAqC,CAAA;IACrC,kDAAmC,CAAA;IACnC,gDAAiC,CAAA;IACjC,oDAAqC,CAAA;IACrC,gEAAiD,CAAA;IACjD,4DAA6C,CAAA;IAC7C,wDAAyC,CAAA;IACzC,4CAA6B,CAAA;AAC/B,CAAC,EAhBW,WAAW,KAAX,WAAW,QAgBtB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Editor } from 'grapesjs';
|
|
2
|
+
import { ConnectorId, ConnectorType, ConnectorUser } from '../../types';
|
|
3
|
+
import { WebsiteId } from '../../types';
|
|
4
|
+
export declare const cmdLogin = "silex:auth:login";
|
|
5
|
+
export declare const cmdLogout = "silex:auth:logout";
|
|
6
|
+
export declare const eventLoggingIn = "silex:auth:logging-in";
|
|
7
|
+
export declare const eventLoggedIn = "silex:auth:logged-in";
|
|
8
|
+
export declare const eventLoginFailed = "silex:auth:login-failed";
|
|
9
|
+
export declare const eventLoggedOut = "silex:auth:logged-out";
|
|
10
|
+
export interface LoginDialogOptions {
|
|
11
|
+
id: WebsiteId;
|
|
12
|
+
}
|
|
13
|
+
export declare function getCurrentUser(editor: Editor): Promise<ConnectorUser>;
|
|
14
|
+
export declare function updateUser(editor: Editor, type: ConnectorType, connectorId?: ConnectorId): Promise<ConnectorUser>;
|
|
15
|
+
export default function loginDialogPlugin(editor: any, opts: any): void;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { html, render } from 'lit-html';
|
|
2
|
+
import { ConnectorType } from '../../types';
|
|
3
|
+
import { connectorList, getUser, logout } from '../api';
|
|
4
|
+
import { API_CONNECTOR_LOGIN, API_CONNECTOR_PATH, API_PATH } from '../../constants';
|
|
5
|
+
export const cmdLogin = 'silex:auth:login';
|
|
6
|
+
export const cmdLogout = 'silex:auth:logout';
|
|
7
|
+
export const eventLoggingIn = 'silex:auth:logging-in';
|
|
8
|
+
export const eventLoggedIn = 'silex:auth:logged-in';
|
|
9
|
+
export const eventLoginFailed = 'silex:auth:login-failed';
|
|
10
|
+
export const eventLoggedOut = 'silex:auth:logged-out';
|
|
11
|
+
export async function getCurrentUser(editor) {
|
|
12
|
+
return editor.getModel().get('user');
|
|
13
|
+
}
|
|
14
|
+
export async function updateUser(editor, type, connectorId) {
|
|
15
|
+
const user = await getUser({ type, connectorId });
|
|
16
|
+
editor.getModel().set('user', user);
|
|
17
|
+
return user;
|
|
18
|
+
}
|
|
19
|
+
let open = false;
|
|
20
|
+
let body = null;
|
|
21
|
+
export default function loginDialogPlugin(editor, opts) {
|
|
22
|
+
// Options
|
|
23
|
+
const options = {
|
|
24
|
+
...opts,
|
|
25
|
+
};
|
|
26
|
+
// Commands and events
|
|
27
|
+
editor.Commands.add(cmdLogin, {
|
|
28
|
+
async run(editor) { await openDialog(); },
|
|
29
|
+
stop(editor) { closeDialog(); },
|
|
30
|
+
});
|
|
31
|
+
editor.Commands.add(cmdLogout, {
|
|
32
|
+
async run(editor) {
|
|
33
|
+
await logout({ type: ConnectorType.STORAGE });
|
|
34
|
+
editor.getModel().set('user', null);
|
|
35
|
+
editor.trigger(eventLoggedOut);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
editor.on(eventLoggedOut, async () => openDialog());
|
|
39
|
+
// Dialog API
|
|
40
|
+
function closeDialog() {
|
|
41
|
+
if (open) {
|
|
42
|
+
editor.Modal.close();
|
|
43
|
+
open = false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function openDialog() {
|
|
47
|
+
editor.trigger(eventLoggingIn);
|
|
48
|
+
open = true;
|
|
49
|
+
editor.Modal.open({
|
|
50
|
+
title: 'Login',
|
|
51
|
+
content: '<div id="LoginDialog__content"></div>',
|
|
52
|
+
}, {
|
|
53
|
+
closeOnConfirm: false,
|
|
54
|
+
closeOnEscape: false,
|
|
55
|
+
closeOnOverlayClick: false,
|
|
56
|
+
});
|
|
57
|
+
body = document.querySelector('#LoginDialog__content');
|
|
58
|
+
if (!body) {
|
|
59
|
+
throw new Error('Dialog creation failed');
|
|
60
|
+
}
|
|
61
|
+
render(html `Logging in...`, body);
|
|
62
|
+
return loadStorageList(async (list) => onStorageList(list));
|
|
63
|
+
}
|
|
64
|
+
async function onStorageList(list) {
|
|
65
|
+
const loggedIn = list.find(connector => connector.isLoggedIn);
|
|
66
|
+
if (loggedIn) {
|
|
67
|
+
try {
|
|
68
|
+
const status = await updateUser(editor, loggedIn.type, loggedIn.connectorId);
|
|
69
|
+
editor.trigger(eventLoggedIn, status);
|
|
70
|
+
return closeDialog();
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.error('Error with updating login status', err);
|
|
74
|
+
render(html `
|
|
75
|
+
<main>
|
|
76
|
+
<p>There was an error with updating the login status. ${err.message}</p>
|
|
77
|
+
</main>
|
|
78
|
+
<footer>
|
|
79
|
+
<button class="silex-button silex-button--primary" @click=${() => loadStorageList(async (list) => onStorageList(list))}>Retry</button>
|
|
80
|
+
<button class="silex-button" @click=${async () => {
|
|
81
|
+
await logout({ type: loggedIn.type, connectorId: loggedIn.connectorId });
|
|
82
|
+
openDialog();
|
|
83
|
+
}}>Login with another connector</button>
|
|
84
|
+
</footer>
|
|
85
|
+
`, body);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// Display the list of storage and continue to login
|
|
90
|
+
render(html `
|
|
91
|
+
<main>
|
|
92
|
+
<p>Login and give Silex access to a file storage.</p>
|
|
93
|
+
${list.map(connector => html `
|
|
94
|
+
<button
|
|
95
|
+
class="silex-button silex-button--primary"
|
|
96
|
+
id="publish-button--primary"
|
|
97
|
+
@click=${() => loginWithConnector(connector)}
|
|
98
|
+
>Login with ${connector.displayName}</button>
|
|
99
|
+
`)}
|
|
100
|
+
</main>
|
|
101
|
+
<footer>
|
|
102
|
+
</footer>
|
|
103
|
+
`, body);
|
|
104
|
+
}
|
|
105
|
+
// Auth management
|
|
106
|
+
async function loadStorageList(done) {
|
|
107
|
+
try {
|
|
108
|
+
const storageConnectors = await connectorList({ type: ConnectorType.STORAGE });
|
|
109
|
+
await done(storageConnectors);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error('Error with loading storage connectors', err);
|
|
113
|
+
render(html `
|
|
114
|
+
<main>
|
|
115
|
+
An error occured while loading the storage connectors: ${err.message}
|
|
116
|
+
</main>
|
|
117
|
+
<footer>
|
|
118
|
+
<button type="button" class="gjs-btn-prim" @click=${() => loadStorageList(done)}>Retry</button>
|
|
119
|
+
</footer>
|
|
120
|
+
`, body);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function loginWithConnector(connector) {
|
|
124
|
+
const nonOAuthUrl = `${API_PATH}${API_CONNECTOR_PATH}${API_CONNECTOR_LOGIN}?connectorId=${connector.connectorId}&type=${connector.type}`;
|
|
125
|
+
window.open(connector.oauthUrl ?? nonOAuthUrl, '_blank');
|
|
126
|
+
return new Promise(resolve => {
|
|
127
|
+
render(html `
|
|
128
|
+
<main>
|
|
129
|
+
<p>Waiting for your authorization in popup window...</p>
|
|
130
|
+
</main>
|
|
131
|
+
<footer>
|
|
132
|
+
<button type="button" class="gjs-btn-prim" @click=${() => openDialog()}>Cancel</button>
|
|
133
|
+
</footer>
|
|
134
|
+
`, body);
|
|
135
|
+
const onMessage = async (event) => {
|
|
136
|
+
const data = event.data;
|
|
137
|
+
if (data?.type === 'login') {
|
|
138
|
+
window.removeEventListener('message', onMessage);
|
|
139
|
+
const { connectorId, error, message } = data; // TODO: use options from the connector? For now they are stored in the session
|
|
140
|
+
if (error) {
|
|
141
|
+
// Error, start over
|
|
142
|
+
console.error('login error', message);
|
|
143
|
+
render(html `
|
|
144
|
+
<main>
|
|
145
|
+
<p>Login failed with error: ${message}</p>
|
|
146
|
+
<footer>
|
|
147
|
+
<button type="button" class="gjs-btn-prim" @click=${() => openDialog()}>Retry</button>
|
|
148
|
+
${connectorId ? html `<button class="silex-button" @click=${async () => {
|
|
149
|
+
await logout({ type: connector.type, connectorId });
|
|
150
|
+
openDialog();
|
|
151
|
+
}}>Login with another connector</button>` : ''}
|
|
152
|
+
|
|
153
|
+
</footer>
|
|
154
|
+
`, body);
|
|
155
|
+
editor.trigger(eventLoginFailed);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
try {
|
|
159
|
+
render(html `
|
|
160
|
+
<main>
|
|
161
|
+
<p>Loging in...</p>
|
|
162
|
+
</main>
|
|
163
|
+
<footer>
|
|
164
|
+
</footer>
|
|
165
|
+
`, body);
|
|
166
|
+
const status = await updateUser(editor, connector.type, connectorId);
|
|
167
|
+
editor.trigger(eventLoggedIn, status);
|
|
168
|
+
closeDialog();
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
console.error('Error with loading login status', err);
|
|
172
|
+
render(html `
|
|
173
|
+
<main>
|
|
174
|
+
An error occured, could not get your data.
|
|
175
|
+
${err.message}
|
|
176
|
+
</main>
|
|
177
|
+
<footer>
|
|
178
|
+
<button type="button" class="gjs-btn-prim" @click=${() => openDialog()}>Retry</button>
|
|
179
|
+
<button class="silex-button" @click=${async () => {
|
|
180
|
+
await logout({ type: connector.type, connectorId });
|
|
181
|
+
openDialog();
|
|
182
|
+
}}>Login with another connector</button>
|
|
183
|
+
</footer>
|
|
184
|
+
`, body);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
window.addEventListener('message', onMessage, false);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=LoginDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoginDialog.js","sourceRoot":"","sources":["../../../../../src/ts/client/grapesjs/LoginDialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEvC,OAAO,EAA+D,aAAa,EAAiB,MAAM,aAAa,CAAA;AACvH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEvD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAEnF,MAAM,CAAC,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,mBAAmB,CAAA;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAA;AACrD,MAAM,CAAC,MAAM,aAAa,GAAG,sBAAsB,CAAA;AACnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAA;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAA;AAMrD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAc;IACjD,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,MAAM,CAAkB,CAAA;AACvD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAc,EAAE,IAAmB,EAAE,WAAyB;IAC7F,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,EAAC,IAAI,EAAE,WAAW,EAAC,CAAC,CAAA;IAC/C,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,MAA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