@silexlabs/silex 3.0.0-alpha.68 → 3.0.0-alpha.70

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.
Files changed (47) hide show
  1. package/dist/client/css/admin.css +1 -3
  2. package/dist/client/js/main.js +9 -10
  3. package/dist/plugins/client/client/api.js +3 -1
  4. package/dist/plugins/client/client/api.js.map +1 -1
  5. package/dist/plugins/client/client/assetUrl.js +14 -14
  6. package/dist/plugins/client/client/assetUrl.js.map +1 -1
  7. package/dist/plugins/client/client/config.js.map +1 -1
  8. package/dist/plugins/client/client/grapesjs/PublicationManager.js +19 -5
  9. package/dist/plugins/client/client/grapesjs/PublicationManager.js.map +1 -1
  10. package/dist/plugins/client/client/grapesjs/PublicationUi.js +13 -9
  11. package/dist/plugins/client/client/grapesjs/PublicationUi.js.map +1 -1
  12. package/dist/plugins/client/client/grapesjs/index.js +12 -7
  13. package/dist/plugins/client/client/grapesjs/index.js.map +1 -1
  14. package/dist/plugins/client/client/grapesjs/project-bar.js +2 -4
  15. package/dist/plugins/client/client/grapesjs/project-bar.js.map +1 -1
  16. package/dist/plugins/client/client/grapesjs/storage.js +4 -1
  17. package/dist/plugins/client/client/grapesjs/storage.js.map +1 -1
  18. package/dist/plugins/client/plugins/client/publicationRenderer.js +1 -1
  19. package/dist/plugins/client/plugins/client/template.js +4 -2
  20. package/dist/plugins/client/plugins/client/template.js.map +1 -1
  21. package/dist/plugins/server/plugins/server/DownloadConnector.d.ts +29 -0
  22. package/dist/plugins/server/plugins/server/DownloadConnector.js +129 -0
  23. package/dist/plugins/server/plugins/server/DownloadConnector.js.map +1 -0
  24. package/dist/plugins/server/plugins/server/StaticPlugin.js +5 -2
  25. package/dist/plugins/server/plugins/server/StaticPlugin.js.map +1 -1
  26. package/dist/plugins/server/server/api/publicationApi.d.ts +23 -0
  27. package/dist/plugins/server/server/api/publicationApi.js +148 -0
  28. package/dist/plugins/server/server/api/publicationApi.js.map +1 -0
  29. package/dist/plugins/server/server/connectors/connectors.d.ts +3 -3
  30. package/dist/plugins/server/server/events.js +16 -0
  31. package/dist/plugins/server/server/events.js.map +1 -1
  32. package/package.json +3 -1
  33. package/src/css/website-info.scss +1 -3
  34. package/src/ts/client/api.ts +6 -1
  35. package/src/ts/client/assetUrl.ts +14 -14
  36. package/src/ts/client/config.ts +0 -1
  37. package/src/ts/client/grapesjs/PublicationManager.ts +19 -5
  38. package/src/ts/client/grapesjs/PublicationUi.ts +13 -9
  39. package/src/ts/client/grapesjs/index.ts +12 -7
  40. package/src/ts/client/grapesjs/project-bar.ts +2 -4
  41. package/src/ts/client/grapesjs/storage.ts +4 -1
  42. package/src/ts/plugins/client/publicationRenderer.ts +1 -1
  43. package/src/ts/plugins/client/template.ts +5 -3
  44. package/src/ts/plugins/server/DownloadConnector.ts +150 -0
  45. package/src/ts/plugins/server/StaticPlugin.ts +5 -2
  46. package/src/ts/server/connectors/connectors.ts +4 -4
  47. package/src/ts/server/events.ts +18 -0
@@ -165,8 +165,9 @@ export function getEditorConfig(id: WebsiteId, connectorId: ConnectorId, rootUrl
165
165
  id: 'dash',
166
166
  className: 'logo',
167
167
  attributes: { title: 'Dashboard' },
168
- link: '/',
169
- command: 'open-dash',
168
+ command: () => {
169
+ window.location.href = '/'
170
+ },
170
171
  }, {
171
172
  id: 'block-manager-btn',
172
173
  className: 'block-manager-btn fa fa-fw fa-plus',
@@ -204,7 +205,9 @@ export function getEditorConfig(id: WebsiteId, connectorId: ConnectorId, rootUrl
204
205
  id: 'font-dialog-btn',
205
206
  className: 'font-manager-btn fa-solid fa-font',
206
207
  attributes: { title: 'Fonts' },
207
- command: cmdOpenFonts,
208
+ command: () => {
209
+ editor.runCommand(cmdOpenFonts)
210
+ },
208
211
  }, {
209
212
  id: 'settings-dialog-btn',
210
213
  className: 'page-panel-btn fa-solid fa-gears',
@@ -218,14 +221,16 @@ export function getEditorConfig(id: WebsiteId, connectorId: ConnectorId, rootUrl
218
221
  id: 'dash2',
219
222
  className: 'fa-solid fa-house',
220
223
  attributes: { title: 'Dashboard' },
221
- link: '/',
222
- command: 'open-dash',
224
+ command: () => {
225
+ window.location.href = '/'
226
+ },
223
227
  }, {
224
228
  id: 'help',
225
229
  className: 'fa fa-fw fa-question-circle',
226
230
  attributes: { title: 'Documentation' },
227
- link: 'https://docs.silex.me/',
228
- command: 'open-help',
231
+ command: () => {
232
+ window.open('https://docs.silex.me/', '_blank')
233
+ },
229
234
  }, {
230
235
  id: 'logout-button',
231
236
  className: 'page-panel-btn fa fa-fw fa-sign-out',
@@ -69,11 +69,9 @@ export const projectBarPlugin = (editor, opts) => {
69
69
  }
70
70
 
71
71
  // commands for show / hide panels
72
- editor.Commands.add(panel.command, {
72
+ // handle the case where command is a normal command, then let the Panel handle it
73
+ typeof panel.command === 'string' && editor.Commands.add(panel.command, {
73
74
  run() {
74
- if(panel.link) {
75
- window.open(panel.link)
76
- }
77
75
  if(panel.attributes.containerClassName) {
78
76
  containerPanel.set('visible', true)
79
77
  el.classList.remove('gjs-hidden')
@@ -55,16 +55,19 @@ export const storagePlugin = (editor) => {
55
55
  },
56
56
 
57
57
  async store(data: WebsiteData, options: { id: WebsiteId, connectorId: ConnectorId }) {
58
+ console.log('connectorPlugin store', data, options)
58
59
  try {
59
60
  if(await getCurrentUser(editor)) {
61
+ console.log('connectorPlugin store2', data, options)
60
62
  const user = await getCurrentUser(editor)
61
63
  data.assets = removeTempDataFromAssetUrl(data.assets)
62
64
  data.pages = removeTempDataFromPages(data.pages)
63
65
  data.styles = removeTempDataFromStyles(data.styles)
66
+ console.log('connectorPlugin store3', data, options)
64
67
  await websiteSave({websiteId: options.id, connectorId: user.storage.connectorId, data})
65
68
  } else {
66
69
  editor.once(eventLoggedIn, () => {
67
- return editor.Storage.save(options)
70
+ return editor.Storage.store()
68
71
  })
69
72
  editor.Commands.run(cmdLogin)
70
73
  }
@@ -23,7 +23,7 @@ console.warn('This plugin is deprecated. Use the publication renderer plugin ins
23
23
  throw 'This plugin is deprecated. Use the publication renderer plugin instead.'
24
24
 
25
25
  /* Usage:
26
- import publicationRenderer from '/node_modules/@silexlabs/silex/dist/plugins/client/plugins/client/publicationRenderer.js'
26
+ import publicationRenderer from 'https://unpkg.com/@silexlabs/silex@latest/dist/plugins/client/plugins/client/publicationRenderer'
27
27
  await config.addPlugin(publicationRenderer, {
28
28
  css: {
29
29
  frontMatter: true,
@@ -34,9 +34,11 @@ const templateKey = 'template'
34
34
 
35
35
  export default async (config, opts: any = {}) => {
36
36
  // @ts-ignore
37
- const { html, render } = await import('/node_modules/lit-html/lit-html.js')
37
+ const { html, render } = await import('https://unpkg.com/lit-html/lit-html.js')
38
+ //const { html, render } = await import('/node_modules/lit-html/lit-html.js')
38
39
  // @ts-ignore
39
- const { styleMap } = await import('/node_modules/lit-html/directives/style-map.js')
40
+ const { styleMap } = await import('https://unpkg.com/lit-html/directives/style-map.js')
41
+ //const { styleMap } = await import('/node_modules/lit-html/directives/style-map.js')
40
42
 
41
43
  config.on(ClientEvent.GRAPESJS_END, () => {
42
44
  const editor = silex.getEditor()
@@ -176,7 +178,7 @@ export default async (config, opts: any = {}) => {
176
178
  c.toHTML = () => {
177
179
  return `${before
178
180
  }${c.get('tagName') ? `<${c.get('tagName')}
179
- ${Object.entries(c.get('attributes')).map(([key, value]) => makeAttribute(key, value)).join(' ')}
181
+ ${Object.entries(c.get('attributes') as object).map(([key, value]) => makeAttribute(key, value)).join(' ')}
180
182
  ${classes.length || classname ? `class="${classes.join(' ')} ${classname}"` : ''}
181
183
  ${attributes}
182
184
  ${style ? `style="${style}"` : ''}
@@ -0,0 +1,150 @@
1
+ import { createWriteStream } from 'fs'
2
+ import archiver from 'archiver'
3
+ import { ConnectorOptions, ConnectorType, ConnectorUser, JobData, JobStatus, PublicationJobData, WebsiteId } from '../../types'
4
+ import { ConnectorFile, ConnectorSession, HostingConnector } from '../../server/connectors/connectors'
5
+ import { tmpdir } from 'os'
6
+ import { JobManager } from '../../server/jobs'
7
+ import { Readable } from 'stream'
8
+ import { ServerConfig } from '../../server/config'
9
+ import { ServerEvent } from '../../server/events'
10
+ import { getHostingConnector } from '../../server/api/publicationApi'
11
+
12
+ import { Request, Response } from 'express'
13
+
14
+ type DownloadConnectorSession = ConnectorSession;
15
+
16
+ type DownloadConnectorOptions = object
17
+
18
+ const svg = '<svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 384 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M64 464c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16h48c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16h48v80c0 17.7 14.3 32 32 32h80V448c0 8.8-7.2 16-16 16H64zM64 0C28.7 0 0 28.7 0 64V448c0 35.3 28.7 64 64 64H320c35.3 0 64-28.7 64-64V154.5c0-17-6.7-33.3-18.7-45.3L274.7 18.7C262.7 6.7 246.5 0 229.5 0H64zm48 112c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16s-7.2-16-16-16H128c-8.8 0-16 7.2-16 16zm0 64c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16s-7.2-16-16-16H128c-8.8 0-16 7.2-16 16zm-6.3 71.8L82.1 335.9c-1.4 5.4-2.1 10.9-2.1 16.4c0 35.2 28.8 63.7 64 63.7s64-28.5 64-63.7c0-5.5-.7-11.1-2.1-16.4l-23.5-88.2c-3.7-14-16.4-23.8-30.9-23.8H136.6c-14.5 0-27.2 9.7-30.9 23.8zM128 336h32c8.8 0 16 7.2 16 16s-7.2 16-16 16H128c-8.8 0-16-7.2-16-16s7.2-16 16-16z"/></svg>'
19
+ const encodedSvg = encodeURIComponent(svg)
20
+ const ZIP_ICON = `data:image/svg+xml,${encodedSvg}`
21
+
22
+ export default class implements HostingConnector<DownloadConnectorSession> {
23
+ connectorId = 'download-connector'
24
+ displayName = 'Download zip file'
25
+ icon = ZIP_ICON
26
+ disableLogout = false
27
+ options: DownloadConnectorOptions
28
+ connectorType = ConnectorType.HOSTING
29
+ color = '#ffffff'
30
+ background = '#006400'
31
+
32
+ constructor(config: ServerConfig) {
33
+ // Add a route to serve the zip file
34
+ config.on(ServerEvent.STARTUP_END, ({app}) => {
35
+ app.get('/download/:tmpZipFile', async (req: Request, res: Response) => {
36
+ const path = `${tmpdir()}/${req.params.tmpZipFile}`
37
+ res.sendFile(path, {}, (err) => {
38
+ if (err) {
39
+ console.error('[DownloadConnector] Error while sending file', err)
40
+ res.status(500).send(`
41
+ <h1>Error</h1>
42
+ <p>There was an error while getting the zip file of your website</p>
43
+ <p>${err.message}</p>
44
+ `)
45
+ }
46
+ })
47
+ })
48
+ })
49
+ }
50
+
51
+ getOptions(formData: object): ConnectorOptions {
52
+ return {}
53
+ }
54
+
55
+ async getOAuthUrl(session: DownloadConnectorSession): Promise<null> { return null }
56
+
57
+ async getLoginForm(session: DownloadConnectorSession, redirectTo: string): Promise<string | null> {
58
+ return null
59
+ }
60
+ async getSettingsForm(session: DownloadConnectorSession, redirectTo: string): Promise<string | null> {
61
+ return null
62
+ }
63
+
64
+ async isLoggedIn(session: DownloadConnectorSession): Promise<boolean> {
65
+ return true
66
+ }
67
+
68
+ async setToken(session: DownloadConnectorSession, query: object): Promise<void> {}
69
+
70
+ async logout(session: DownloadConnectorSession): Promise<void> {}
71
+
72
+ async getUser(session: DownloadConnectorSession): Promise<ConnectorUser | null> {
73
+ return null
74
+ }
75
+
76
+ async publish(session: DownloadConnectorSession, websiteId: WebsiteId, files: ConnectorFile[], jobManager: JobManager): Promise<JobData> {
77
+ const job = jobManager.startJob(`Publishing to ${this.displayName}`) as PublicationJobData
78
+ this.startPublishingInBackground(session, websiteId, files, job)
79
+ return job
80
+ }
81
+
82
+ async startPublishingInBackground(session: DownloadConnectorSession, websiteId: WebsiteId, files: ConnectorFile[], job: PublicationJobData): Promise<void> {
83
+ const fileName = `${websiteId}-${Date.now()}-${Math.random().toString(36).substring(7)}.zip`
84
+ return new Promise<string>((resolve, reject) => {
85
+ let resolved = false
86
+ try {
87
+ // Generate a temporary path for the zip file, in the OS tmp folder, with the website id, the date and random string
88
+ const path = `${tmpdir()}/${fileName}`
89
+ // create a file to stream archive data to.
90
+ const output = createWriteStream(path)
91
+ const archive = archiver('zip', {
92
+ zlib: { level: 9 } // Sets the compression level.
93
+ })
94
+
95
+ // Listen to archive events
96
+ // listen for all archive data to be written
97
+ // 'close' event is fired only when a file descriptor is involved
98
+ output.on('close', function () {
99
+ !resolved && resolve(path)
100
+ resolved = true
101
+ })
102
+
103
+ // good practice to catch warnings (ie stat failures and other non-blocking errors)
104
+ archive.on('warning', function (err) {
105
+ if (err.code === 'ENOENT') {
106
+ // log warning
107
+ } else {
108
+ !resolved && reject(err)
109
+ resolved = true
110
+ }
111
+ })
112
+
113
+ // good practice to catch this error explicitly
114
+ archive.on('error', function (err) {
115
+ !resolved && reject(err)
116
+ resolved = true
117
+ })
118
+
119
+ // pipe archive data to the filey
120
+ archive.pipe(output)
121
+
122
+ // append files
123
+ for (const file of files) {
124
+ job.message = `Adding ${file.path} to the zip file`
125
+ // Handle content as string, buffer or readable
126
+ archive.append(file.content, { name: file.path })
127
+ }
128
+
129
+ // finalize the archive (ie we are done appending files but streams have to finish yet)
130
+ job.message = 'Finalizing the zip file'
131
+ return archive.finalize()
132
+ .then(() => path)
133
+ } catch (err) {
134
+ console.error('Error while creating the zip file', err)
135
+ job.message = `Error while creating the zip file: ${err.message}`
136
+ job.status = JobStatus.ERROR
137
+ !resolved && reject(err)
138
+ resolved = true
139
+ }
140
+ })
141
+ .then(path => {
142
+ job.message = `Zip file created, <a href="/download/${fileName}" target="_blank">download it now</a>`
143
+ job.status = JobStatus.SUCCESS
144
+ })
145
+ }
146
+
147
+ async getUrl(session: DownloadConnectorSession, websiteId: WebsiteId): Promise<string> {
148
+ return ''
149
+ }
150
+ }
@@ -43,8 +43,11 @@ export default async function(config, opts = {}) {
43
43
  route: '/webfonts/',
44
44
  path: nodeModules('@fortawesome/fontawesome-free') + '/@fortawesome/fontawesome-free/webfonts/',
45
45
  }, {
46
- route: '/node_modules/',
47
- path: nodeModules(),
46
+ route: '/css/files/',
47
+ path: nodeModules('@fontsource/ubuntu') + '/@fontsource/ubuntu/files/',
48
+ //}, {
49
+ // route: '/node_modules/',
50
+ // path: nodeModules(),
48
51
  }, {
49
52
  route: '/',
50
53
  path: join(__dirname, '../../../../..', 'dist', 'client'),
@@ -67,10 +67,7 @@ export interface Connector<Session extends ConnectorSession = ConnectorSession>
67
67
  isLoggedIn(session: Session): Promise<boolean>
68
68
  setToken(session: Session, token: object): Promise<void>
69
69
  logout(session: Session): Promise<void>
70
- getUser(session: Session): Promise<ConnectorUser>
71
- // Handle website meta file
72
- getWebsiteMeta(session: Session, websiteId: WebsiteId): Promise<WebsiteMeta>
73
- setWebsiteMeta(session: Session, websiteId: WebsiteId, data: WebsiteMetaFileContent): Promise<void>
70
+ getUser(session: Session): Promise<ConnectorUser | null>
74
71
  // Get the connector options from login form
75
72
  // They are stored in the website meta file for hosting connectors
76
73
  // And in the user session for storage connectors
@@ -94,6 +91,9 @@ export interface StorageConnector<Session extends ConnectorSession = ConnectorSe
94
91
  readAsset(session: Session, websiteId: WebsiteId, fileName: string): Promise<ConnectorFileContent>
95
92
  deleteAssets(session: Session, websiteId: WebsiteId, fileNames: string[]): Promise<void>
96
93
  //getFileUrl(session: Session, websiteId: WebsiteId, path: string): Promise<string>
94
+ // Handle website meta file
95
+ getWebsiteMeta(session: Session, websiteId: WebsiteId): Promise<WebsiteMeta>
96
+ setWebsiteMeta(session: Session, websiteId: WebsiteId, data: WebsiteMetaFileContent): Promise<void>
97
97
  }
98
98
 
99
99
  /**
@@ -1,3 +1,21 @@
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
+
18
+ // FIXME: this is for client and server, it is confusing, split in 2 files
1
19
  import { ConnectorId, PublicationData, WebsiteData, WebsiteId } from '../types'
2
20
  import { ConnectorFile } from './connectors/connectors'
3
21