@silexlabs/silex 3.0.0-alpha.55 → 3.0.0-alpha.56
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/assetUrl.d.ts +8 -1
- package/dist/client/client/utils.d.ts +2 -1
- package/dist/client/js/main.js +74 -74
- package/dist/client/types.d.ts +1 -0
- package/dist/plugins/client/client/assetUrl.d.ts +8 -1
- package/dist/plugins/client/client/assetUrl.js +59 -21
- package/dist/plugins/client/client/assetUrl.js.map +1 -1
- package/dist/plugins/client/client/grapesjs/PublicationManager.js +13 -14
- package/dist/plugins/client/client/grapesjs/PublicationManager.js.map +1 -1
- package/dist/plugins/client/client/grapesjs/index.js +1 -1
- package/dist/plugins/client/client/grapesjs/index.js.map +1 -1
- package/dist/plugins/client/client/publication-transformers.js +4 -4
- package/dist/plugins/client/client/publication-transformers.js.map +1 -1
- package/dist/plugins/client/client/utils.d.ts +2 -1
- package/dist/plugins/client/client/utils.js.map +1 -1
- package/dist/plugins/client/types.d.ts +1 -0
- package/dist/plugins/server/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/ts/client/assetUrl.ts +60 -22
- package/src/ts/client/grapesjs/PublicationManager.ts +13 -14
- package/src/ts/client/grapesjs/index.ts +1 -1
- package/src/ts/client/index.ts +4 -0
- package/src/ts/client/publication-transformers.ts +4 -4
- package/src/ts/client/utils.ts +3 -1
- package/src/ts/types.ts +1 -1
|
@@ -23,7 +23,7 @@ import { getUser, logout, publicationStatus, publish } from '../api'
|
|
|
23
23
|
import { API_CONNECTOR_LOGIN, API_CONNECTOR_PATH, API_PATH } from '../../constants'
|
|
24
24
|
import { ClientEvent } from '../events'
|
|
25
25
|
import { resetRenderComponents, resetRenderCssRules, transformPermalink, transformFiles, transformPath, renderComponents } from '../publication-transformers'
|
|
26
|
-
import { removeTempDataFromAssetUrl } from '../assetUrl'
|
|
26
|
+
import { removeTempDataFromAssetUrl, removeTempDataFromPages, removeTempDataFromStyles } from '../assetUrl'
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* @fileoverview Publication manager for Silex
|
|
@@ -206,10 +206,15 @@ export class PublicationManager {
|
|
|
206
206
|
this.dialog && this.dialog.displayPending(this.job, this.status)
|
|
207
207
|
this.editor.trigger(ClientEvent.PUBLISH_START)
|
|
208
208
|
this.setPublicationTransformers()
|
|
209
|
+
// User and where to publish
|
|
210
|
+
const storageUser = this.editor.getModel().get('user') as ConnectorUser
|
|
211
|
+
if(!storageUser) throw new Error('User not logged in to a storage connector')
|
|
212
|
+
if(!this.settings.connector?.connectorId) throw new Error('User not logged in to a hosting connector')
|
|
213
|
+
const websiteId = this.options.websiteId
|
|
214
|
+
const storageId = storageUser.storage.connectorId
|
|
215
|
+
// Data to publish
|
|
209
216
|
const projectData = this.editor.getProjectData() as WebsiteData
|
|
210
217
|
const siteSettings = this.editor.getModel().get('settings') as WebsiteSettings
|
|
211
|
-
// Remove temporary data for editing
|
|
212
|
-
projectData.assets = removeTempDataFromAssetUrl(projectData.assets)
|
|
213
218
|
// Build the files structure
|
|
214
219
|
const files: ClientSideFile[] = (await this.getHtmlFiles(siteSettings))
|
|
215
220
|
.flatMap(file => ([{
|
|
@@ -223,20 +228,19 @@ export class PublicationManager {
|
|
|
223
228
|
} as ClientSideFile]))
|
|
224
229
|
.concat(projectData.assets
|
|
225
230
|
.map(asset => {
|
|
226
|
-
// Remove /assets that is added by grapesjs
|
|
227
|
-
const initialPath = asset.src
|
|
228
231
|
// Remove /assets that is added by grapesjs
|
|
232
|
+
const initialPath = asset.src
|
|
229
233
|
.replace(/^\/assets/, '')
|
|
230
234
|
// Transform the file paths with the transformers
|
|
231
235
|
const path = transformPath(this.editor, initialPath, ClientSideFileType.ASSET)
|
|
232
|
-
|
|
236
|
+
const src = transformPermalink(this.editor, initialPath, ClientSideFileType.ASSET)
|
|
233
237
|
return {
|
|
234
238
|
...asset,
|
|
235
239
|
path,
|
|
240
|
+
src,
|
|
236
241
|
type: ClientSideFileType.ASSET, // Replaces grapesjs's 'image' type
|
|
237
242
|
} as ClientSideFile
|
|
238
243
|
}))
|
|
239
|
-
|
|
240
244
|
// Create the data to send to the server
|
|
241
245
|
const data: PublicationData = {
|
|
242
246
|
...projectData,
|
|
@@ -244,17 +248,14 @@ export class PublicationManager {
|
|
|
244
248
|
publication: this.settings,
|
|
245
249
|
files,
|
|
246
250
|
}
|
|
251
|
+
this.resetPublicationTransformers()
|
|
247
252
|
transformFiles(this.editor, data)
|
|
248
253
|
this.editor.trigger(ClientEvent.PUBLISH_DATA, data)
|
|
249
|
-
const storageUser = this.editor.getModel().get('user') as ConnectorUser
|
|
250
|
-
if(!storageUser) throw new Error('User not logged in to a storage connector')
|
|
251
|
-
if(!this.settings.connector?.connectorId) throw new Error('User not logged in to a hosting connector')
|
|
252
254
|
try {
|
|
253
|
-
const websiteId = this.options.websiteId
|
|
254
255
|
const [url, job] = await publish({
|
|
255
256
|
websiteId,
|
|
256
257
|
hostingId: this.settings.connector.connectorId,
|
|
257
|
-
storageId
|
|
258
|
+
storageId,
|
|
258
259
|
data: data as ApiPublicationPublishBody,
|
|
259
260
|
options: this.settings.options,
|
|
260
261
|
})
|
|
@@ -329,7 +330,6 @@ export class PublicationManager {
|
|
|
329
330
|
} catch (e) {
|
|
330
331
|
this.status = PublicationStatus.STATUS_ERROR
|
|
331
332
|
this.dialog && this.dialog.displayError(`An error occured, your site is not published. ${e.message}`, this.job, this.status)
|
|
332
|
-
this.resetPublicationTransformers()
|
|
333
333
|
this.editor.trigger(ClientEvent.PUBLISH_END, { success: false, message: e.message })
|
|
334
334
|
this.editor.trigger(ClientEvent.PUBLISH_ERROR, { success: false, message: e.message })
|
|
335
335
|
return
|
|
@@ -337,7 +337,6 @@ export class PublicationManager {
|
|
|
337
337
|
if (this.job.status === JobStatus.IN_PROGRESS) {
|
|
338
338
|
setTimeout(() => this.trackProgress(), 2000)
|
|
339
339
|
} else {
|
|
340
|
-
this.resetPublicationTransformers()
|
|
341
340
|
this.editor.trigger(ClientEvent.PUBLISH_END, { success: this.job.status === JobStatus.SUCCESS, message: this.job.message })
|
|
342
341
|
}
|
|
343
342
|
this.dialog && this.dialog.displayPending(this.job, this.status)
|
|
@@ -210,7 +210,7 @@ export function getEditorConfig(id: WebsiteId, connectorId: ConnectorId, rootUrl
|
|
|
210
210
|
},
|
|
211
211
|
[internalLinksPlugin as any]: {
|
|
212
212
|
// FIXME: warn the user about links in error
|
|
213
|
-
onError: (errors) => console.
|
|
213
|
+
onError: (errors) => console.warn('Links errors:', errors),
|
|
214
214
|
},
|
|
215
215
|
[codePlugin as any]: {
|
|
216
216
|
blockLabel: 'HTML',
|
package/src/ts/client/index.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { assetsPublicationTransformer } from './assetUrl'
|
|
24
25
|
import { ClientConfig } from './config'
|
|
25
26
|
import { ClientEvent } from './events'
|
|
26
27
|
import { initEditor, getEditor } from './grapesjs/index'
|
|
@@ -35,6 +36,9 @@ export async function start(options = {}) {
|
|
|
35
36
|
const config = new ClientConfig()
|
|
36
37
|
Object.assign(config, options)
|
|
37
38
|
|
|
39
|
+
// Add the publication transformers which are used to cleanup assets URLs
|
|
40
|
+
config.addPublicationTransformers(assetsPublicationTransformer)
|
|
41
|
+
|
|
38
42
|
// Config file in root folder which may be generated by the server
|
|
39
43
|
await config.addPlugin(config.clientConfigUrl, {})
|
|
40
44
|
|
|
@@ -194,9 +194,9 @@ export function transformPermalink(editor: Editor, path: string, type: ClientSid
|
|
|
194
194
|
const config = editor.getModel().get('config')
|
|
195
195
|
return config.publicationTransformers.reduce((result: string, transformer: PublicationTransformer) => {
|
|
196
196
|
try {
|
|
197
|
-
return transformer.transformPermalink ? transformer.transformPermalink(
|
|
197
|
+
return transformer.transformPermalink ? transformer.transformPermalink(result, type) ?? result : result
|
|
198
198
|
} catch (e) {
|
|
199
|
-
console.error('Publication transformer: error transforming path',
|
|
199
|
+
console.error('Publication transformer: error transforming path', result, e)
|
|
200
200
|
return result
|
|
201
201
|
}
|
|
202
202
|
}, path)
|
|
@@ -206,9 +206,9 @@ export function transformPath(editor: Editor, path: string, type: ClientSideFile
|
|
|
206
206
|
const config = editor.getModel().get('config')
|
|
207
207
|
return config.publicationTransformers.reduce((result: string, transformer: PublicationTransformer) => {
|
|
208
208
|
try {
|
|
209
|
-
return transformer.transformPath ? transformer.transformPath(
|
|
209
|
+
return transformer.transformPath ? transformer.transformPath(result, type) ?? result : result
|
|
210
210
|
} catch (e) {
|
|
211
|
-
console.error('Publication transformer: error transforming path',
|
|
211
|
+
console.error('Publication transformer: error transforming path', result, e)
|
|
212
212
|
return result
|
|
213
213
|
}
|
|
214
214
|
}, path)
|
package/src/ts/client/utils.ts
CHANGED
|
@@ -15,9 +15,11 @@
|
|
|
15
15
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import { Component, Editor } from 'grapesjs'
|
|
19
|
+
|
|
18
20
|
|
|
19
21
|
// Browse all elements of all pages
|
|
20
|
-
export function onAll(editor, cbk) {
|
|
22
|
+
export function onAll(editor: Editor, cbk: (c: Component) => void) {
|
|
21
23
|
editor.Pages.getAll()
|
|
22
24
|
.forEach(page => {
|
|
23
25
|
page.getMainComponent()
|
package/src/ts/types.ts
CHANGED
|
@@ -111,7 +111,7 @@ export interface Page {
|
|
|
111
111
|
id: string,
|
|
112
112
|
name: string,
|
|
113
113
|
slug: string,
|
|
114
|
-
// TODO: why is this here?
|
|
114
|
+
settings: WebsiteSettings, // TODO: why is this here? It is used in the publication manager
|
|
115
115
|
frames: {
|
|
116
116
|
component: Component,
|
|
117
117
|
}[]
|