@silexlabs/silex 3.0.0-alpha.100

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 (282) hide show
  1. package/.env.default +19 -0
  2. package/.silex.js +37 -0
  3. package/LICENSE +661 -0
  4. package/README.md +96 -0
  5. package/dist/client/client/api.d.ts +85 -0
  6. package/dist/client/client/assetUrl.d.ts +51 -0
  7. package/dist/client/client/config.d.ts +58 -0
  8. package/dist/client/client/events.d.ts +14 -0
  9. package/dist/client/client/expose.d.ts +8 -0
  10. package/dist/client/client/grapesjs/LoginDialog.d.ts +15 -0
  11. package/dist/client/client/grapesjs/PublicationManager.d.ts +72 -0
  12. package/dist/client/client/grapesjs/PublicationUi.d.ts +62 -0
  13. package/dist/client/client/grapesjs/blocks.d.ts +1 -0
  14. package/dist/client/client/grapesjs/breadcrumbs.d.ts +1 -0
  15. package/dist/client/client/grapesjs/footer.d.ts +2 -0
  16. package/dist/client/client/grapesjs/index.d.ts +5 -0
  17. package/dist/client/client/grapesjs/internal-links.d.ts +1 -0
  18. package/dist/client/client/grapesjs/new-page-dialog.d.ts +2 -0
  19. package/dist/client/client/grapesjs/openImport.d.ts +9 -0
  20. package/dist/client/client/grapesjs/page-panel.d.ts +3 -0
  21. package/dist/client/client/grapesjs/project-bar.d.ts +1 -0
  22. package/dist/client/client/grapesjs/rich-text.d.ts +1 -0
  23. package/dist/client/client/grapesjs/semantic.d.ts +1 -0
  24. package/dist/client/client/grapesjs/settings.d.ts +2 -0
  25. package/dist/client/client/grapesjs/storage.d.ts +1 -0
  26. package/dist/client/client/grapesjs/symbolDialogs.d.ts +3 -0
  27. package/dist/client/client/index.d.ts +5 -0
  28. package/dist/client/client/publication-transformers.d.ts +41 -0
  29. package/dist/client/client/utils.d.ts +2 -0
  30. package/dist/client/constants.d.ts +29 -0
  31. package/dist/client/css/admin.css +4491 -0
  32. package/dist/client/index.html +9 -0
  33. package/dist/client/js/main.js +321 -0
  34. package/dist/client/js/main.js.LICENSE.txt +24 -0
  35. package/dist/client/page.d.ts +2 -0
  36. package/dist/client/types.d.ts +334 -0
  37. package/dist/plugins/client/client/api.d.ts +85 -0
  38. package/dist/plugins/client/client/api.js +114 -0
  39. package/dist/plugins/client/client/api.js.map +1 -0
  40. package/dist/plugins/client/client/assetUrl.d.ts +51 -0
  41. package/dist/plugins/client/client/assetUrl.js +224 -0
  42. package/dist/plugins/client/client/assetUrl.js.map +1 -0
  43. package/dist/plugins/client/client/config.d.ts +58 -0
  44. package/dist/plugins/client/client/config.js +90 -0
  45. package/dist/plugins/client/client/config.js.map +1 -0
  46. package/dist/plugins/client/client/events.d.ts +14 -0
  47. package/dist/plugins/client/client/events.js +34 -0
  48. package/dist/plugins/client/client/events.js.map +1 -0
  49. package/dist/plugins/client/client/grapesjs/LoginDialog.d.ts +15 -0
  50. package/dist/plugins/client/client/grapesjs/LoginDialog.js +195 -0
  51. package/dist/plugins/client/client/grapesjs/LoginDialog.js.map +1 -0
  52. package/dist/plugins/client/client/grapesjs/PublicationManager.d.ts +72 -0
  53. package/dist/plugins/client/client/grapesjs/PublicationManager.js +356 -0
  54. package/dist/plugins/client/client/grapesjs/PublicationManager.js.map +1 -0
  55. package/dist/plugins/client/client/grapesjs/PublicationUi.d.ts +62 -0
  56. package/dist/plugins/client/client/grapesjs/PublicationUi.js +336 -0
  57. package/dist/plugins/client/client/grapesjs/PublicationUi.js.map +1 -0
  58. package/dist/plugins/client/client/grapesjs/blocks.d.ts +1 -0
  59. package/dist/plugins/client/client/grapesjs/blocks.js +37 -0
  60. package/dist/plugins/client/client/grapesjs/blocks.js.map +1 -0
  61. package/dist/plugins/client/client/grapesjs/breadcrumbs.d.ts +1 -0
  62. package/dist/plugins/client/client/grapesjs/breadcrumbs.js +75 -0
  63. package/dist/plugins/client/client/grapesjs/breadcrumbs.js.map +1 -0
  64. package/dist/plugins/client/client/grapesjs/footer.d.ts +2 -0
  65. package/dist/plugins/client/client/grapesjs/footer.js +28 -0
  66. package/dist/plugins/client/client/grapesjs/footer.js.map +1 -0
  67. package/dist/plugins/client/client/grapesjs/index.d.ts +5 -0
  68. package/dist/plugins/client/client/grapesjs/index.js +313 -0
  69. package/dist/plugins/client/client/grapesjs/index.js.map +1 -0
  70. package/dist/plugins/client/client/grapesjs/internal-links.d.ts +1 -0
  71. package/dist/plugins/client/client/grapesjs/internal-links.js +219 -0
  72. package/dist/plugins/client/client/grapesjs/internal-links.js.map +1 -0
  73. package/dist/plugins/client/client/grapesjs/new-page-dialog.d.ts +2 -0
  74. package/dist/plugins/client/client/grapesjs/new-page-dialog.js +83 -0
  75. package/dist/plugins/client/client/grapesjs/new-page-dialog.js.map +1 -0
  76. package/dist/plugins/client/client/grapesjs/openImport.d.ts +9 -0
  77. package/dist/plugins/client/client/grapesjs/openImport.js +74 -0
  78. package/dist/plugins/client/client/grapesjs/openImport.js.map +1 -0
  79. package/dist/plugins/client/client/grapesjs/page-panel.d.ts +3 -0
  80. package/dist/plugins/client/client/grapesjs/page-panel.js +113 -0
  81. package/dist/plugins/client/client/grapesjs/page-panel.js.map +1 -0
  82. package/dist/plugins/client/client/grapesjs/project-bar.d.ts +1 -0
  83. package/dist/plugins/client/client/grapesjs/project-bar.js +104 -0
  84. package/dist/plugins/client/client/grapesjs/project-bar.js.map +1 -0
  85. package/dist/plugins/client/client/grapesjs/rich-text.d.ts +1 -0
  86. package/dist/plugins/client/client/grapesjs/rich-text.js +31 -0
  87. package/dist/plugins/client/client/grapesjs/rich-text.js.map +1 -0
  88. package/dist/plugins/client/client/grapesjs/semantic.d.ts +1 -0
  89. package/dist/plugins/client/client/grapesjs/semantic.js +110 -0
  90. package/dist/plugins/client/client/grapesjs/semantic.js.map +1 -0
  91. package/dist/plugins/client/client/grapesjs/settings.d.ts +2 -0
  92. package/dist/plugins/client/client/grapesjs/settings.js +198 -0
  93. package/dist/plugins/client/client/grapesjs/settings.js.map +1 -0
  94. package/dist/plugins/client/client/grapesjs/storage.d.ts +1 -0
  95. package/dist/plugins/client/client/grapesjs/storage.js +126 -0
  96. package/dist/plugins/client/client/grapesjs/storage.js.map +1 -0
  97. package/dist/plugins/client/client/grapesjs/symbolDialogs.d.ts +3 -0
  98. package/dist/plugins/client/client/grapesjs/symbolDialogs.js +36 -0
  99. package/dist/plugins/client/client/grapesjs/symbolDialogs.js.map +1 -0
  100. package/dist/plugins/client/client/publication-transformers.d.ts +41 -0
  101. package/dist/plugins/client/client/publication-transformers.js +238 -0
  102. package/dist/plugins/client/client/publication-transformers.js.map +1 -0
  103. package/dist/plugins/client/client/utils.d.ts +2 -0
  104. package/dist/plugins/client/client/utils.js +25 -0
  105. package/dist/plugins/client/client/utils.js.map +1 -0
  106. package/dist/plugins/client/constants.d.ts +29 -0
  107. package/dist/plugins/client/constants.js +46 -0
  108. package/dist/plugins/client/constants.js.map +1 -0
  109. package/dist/plugins/client/page.d.ts +2 -0
  110. package/dist/plugins/client/page.js +31 -0
  111. package/dist/plugins/client/page.js.map +1 -0
  112. package/dist/plugins/client/plugins/client/11ty.d.ts +17 -0
  113. package/dist/plugins/client/plugins/client/11ty.js +86 -0
  114. package/dist/plugins/client/plugins/client/11ty.js.map +1 -0
  115. package/dist/plugins/client/plugins/client/publicationRenderer.d.ts +2 -0
  116. package/dist/plugins/client/plugins/client/publicationRenderer.js +170 -0
  117. package/dist/plugins/client/plugins/client/publicationRenderer.js.map +1 -0
  118. package/dist/plugins/client/plugins/client/template.d.ts +2 -0
  119. package/dist/plugins/client/plugins/client/template.js +183 -0
  120. package/dist/plugins/client/plugins/client/template.js.map +1 -0
  121. package/dist/plugins/client/plugins/client/website-info.d.ts +1 -0
  122. package/dist/plugins/client/plugins/client/website-info.js +72 -0
  123. package/dist/plugins/client/plugins/client/website-info.js.map +1 -0
  124. package/dist/plugins/client/types.d.ts +334 -0
  125. package/dist/plugins/client/types.js +74 -0
  126. package/dist/plugins/client/types.js.map +1 -0
  127. package/dist/plugins/server/constants.d.ts +29 -0
  128. package/dist/plugins/server/constants.js +49 -0
  129. package/dist/plugins/server/constants.js.map +1 -0
  130. package/dist/plugins/server/plugins/server/AuthPlugin.d.ts +1 -0
  131. package/dist/plugins/server/plugins/server/AuthPlugin.js +40 -0
  132. package/dist/plugins/server/plugins/server/AuthPlugin.js.map +1 -0
  133. package/dist/plugins/server/plugins/server/Cache.d.ts +2 -0
  134. package/dist/plugins/server/plugins/server/Cache.js +32 -0
  135. package/dist/plugins/server/plugins/server/Cache.js.map +1 -0
  136. package/dist/plugins/server/plugins/server/DownloadConnector.d.ts +29 -0
  137. package/dist/plugins/server/plugins/server/DownloadConnector.js +129 -0
  138. package/dist/plugins/server/plugins/server/DownloadConnector.js.map +1 -0
  139. package/dist/plugins/server/plugins/server/FtpConnector.d.ts +86 -0
  140. package/dist/plugins/server/plugins/server/FtpConnector.js +526 -0
  141. package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -0
  142. package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +87 -0
  143. package/dist/plugins/server/plugins/server/GitlabConnector.js +564 -0
  144. package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -0
  145. package/dist/plugins/server/plugins/server/PublicationOptimizer.d.ts +0 -0
  146. package/dist/plugins/server/plugins/server/PublicationOptimizer.js +14 -0
  147. package/dist/plugins/server/plugins/server/PublicationOptimizer.js.map +1 -0
  148. package/dist/plugins/server/plugins/server/SslPlugin.d.ts +1 -0
  149. package/dist/plugins/server/plugins/server/SslPlugin.js +86 -0
  150. package/dist/plugins/server/plugins/server/SslPlugin.js.map +1 -0
  151. package/dist/plugins/server/plugins/server/StaticPlugin.d.ts +1 -0
  152. package/dist/plugins/server/plugins/server/StaticPlugin.js +78 -0
  153. package/dist/plugins/server/plugins/server/StaticPlugin.js.map +1 -0
  154. package/dist/plugins/server/server/config.d.ts +59 -0
  155. package/dist/plugins/server/server/config.js +181 -0
  156. package/dist/plugins/server/server/config.js.map +1 -0
  157. package/dist/plugins/server/server/connectors/FsHosting.d.ts +13 -0
  158. package/dist/plugins/server/server/connectors/FsHosting.js +54 -0
  159. package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -0
  160. package/dist/plugins/server/server/connectors/FsStorage.d.ts +43 -0
  161. package/dist/plugins/server/server/connectors/FsStorage.js +257 -0
  162. package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -0
  163. package/dist/plugins/server/server/connectors/connectors.d.ts +87 -0
  164. package/dist/plugins/server/server/connectors/connectors.js +127 -0
  165. package/dist/plugins/server/server/connectors/connectors.js.map +1 -0
  166. package/dist/plugins/server/server/events.d.ts +26 -0
  167. package/dist/plugins/server/server/events.js +31 -0
  168. package/dist/plugins/server/server/events.js.map +1 -0
  169. package/dist/plugins/server/server/jobs.d.ts +12 -0
  170. package/dist/plugins/server/server/jobs.js +77 -0
  171. package/dist/plugins/server/server/jobs.js.map +1 -0
  172. package/dist/plugins/server/server/utils/validation.d.ts +7 -0
  173. package/dist/plugins/server/server/utils/validation.js +38 -0
  174. package/dist/plugins/server/server/utils/validation.js.map +1 -0
  175. package/dist/plugins/server/types.d.ts +334 -0
  176. package/dist/plugins/server/types.js +78 -0
  177. package/dist/plugins/server/types.js.map +1 -0
  178. package/dist/server/constants.js +29 -0
  179. package/dist/server/plugins/server/Cache.js +15 -0
  180. package/dist/server/server/api/api.js +20 -0
  181. package/dist/server/server/api/connectorApi.js +216 -0
  182. package/dist/server/server/api/publicationApi.js +108 -0
  183. package/dist/server/server/api/websiteApi.js +296 -0
  184. package/dist/server/server/cli.js +68 -0
  185. package/dist/server/server/config.js +120 -0
  186. package/dist/server/server/connectors/FsHosting.js +35 -0
  187. package/dist/server/server/connectors/FsStorage.js +225 -0
  188. package/dist/server/server/connectors/connectors.js +89 -0
  189. package/dist/server/server/events.js +14 -0
  190. package/dist/server/server/expose.js +27 -0
  191. package/dist/server/server/express.js +47 -0
  192. package/dist/server/server/index.js +90 -0
  193. package/dist/server/server/jobs.js +48 -0
  194. package/dist/server/server/utils/validation.js +15 -0
  195. package/dist/server/types.js +34 -0
  196. package/package.json +209 -0
  197. package/public/assets/container.png +0 -0
  198. package/public/assets/favicon.png +0 -0
  199. package/public/assets/logo-silex-small.png +0 -0
  200. package/public/robots.txt +2 -0
  201. package/public/silex.js +24 -0
  202. package/src/css/_mixins.scss +8 -0
  203. package/src/css/_variables.scss +33 -0
  204. package/src/css/dialog.scss +41 -0
  205. package/src/css/footer.scss +12 -0
  206. package/src/css/grapesjs-light.scss +180 -0
  207. package/src/css/grapesjs.scss +152 -0
  208. package/src/css/index.scss +32 -0
  209. package/src/css/light.scss +7 -0
  210. package/src/css/loader.scss +12 -0
  211. package/src/css/page-panel.scss +65 -0
  212. package/src/css/project-bar.scss +102 -0
  213. package/src/css/silex.scss +189 -0
  214. package/src/css/website-info.scss +14 -0
  215. package/src/html/debug.pug +8 -0
  216. package/src/html/index.pug +39 -0
  217. package/src/html/templates/includes.pug +1 -0
  218. package/src/html/templates/workspace.pug +2 -0
  219. package/src/ts/client/api.ts +144 -0
  220. package/src/ts/client/assetUrl.test.ts +125 -0
  221. package/src/ts/client/assetUrl.ts +235 -0
  222. package/src/ts/client/config.ts +105 -0
  223. package/src/ts/client/events.ts +34 -0
  224. package/src/ts/client/expose.ts +30 -0
  225. package/src/ts/client/grapesjs/LoginDialog.ts +204 -0
  226. package/src/ts/client/grapesjs/PublicationManager.ts +370 -0
  227. package/src/ts/client/grapesjs/PublicationUi.ts +342 -0
  228. package/src/ts/client/grapesjs/blocks.ts +37 -0
  229. package/src/ts/client/grapesjs/breadcrumbs.ts +79 -0
  230. package/src/ts/client/grapesjs/eleventy.ts +47 -0
  231. package/src/ts/client/grapesjs/footer.ts +27 -0
  232. package/src/ts/client/grapesjs/index.ts +335 -0
  233. package/src/ts/client/grapesjs/internal-links.test.ts +105 -0
  234. package/src/ts/client/grapesjs/internal-links.ts +225 -0
  235. package/src/ts/client/grapesjs/new-page-dialog.ts +90 -0
  236. package/src/ts/client/grapesjs/openImport.ts +81 -0
  237. package/src/ts/client/grapesjs/page-panel.ts +118 -0
  238. package/src/ts/client/grapesjs/project-bar.ts +107 -0
  239. package/src/ts/client/grapesjs/rich-text.ts +33 -0
  240. package/src/ts/client/grapesjs/semantic.ts +114 -0
  241. package/src/ts/client/grapesjs/settings.ts +208 -0
  242. package/src/ts/client/grapesjs/storage.ts +121 -0
  243. package/src/ts/client/grapesjs/symbolDialogs.ts +38 -0
  244. package/src/ts/client/index.ts +98 -0
  245. package/src/ts/client/publication-transformers.test.ts +199 -0
  246. package/src/ts/client/publication-transformers.ts +263 -0
  247. package/src/ts/client/utils.ts +28 -0
  248. package/src/ts/constants.ts +52 -0
  249. package/src/ts/externs.ts +18 -0
  250. package/src/ts/page.ts +31 -0
  251. package/src/ts/plugins/client/11ty.ts +104 -0
  252. package/src/ts/plugins/client/publicationRenderer.ts +174 -0
  253. package/src/ts/plugins/client/template.ts +192 -0
  254. package/src/ts/plugins/client/website-info.ts +84 -0
  255. package/src/ts/plugins/server/AuthPlugin.ts +38 -0
  256. package/src/ts/plugins/server/Cache.ts +28 -0
  257. package/src/ts/plugins/server/DownloadConnector.ts +148 -0
  258. package/src/ts/plugins/server/FtpConnector.test.ts +82 -0
  259. package/src/ts/plugins/server/FtpConnector.ts +609 -0
  260. package/src/ts/plugins/server/GitlabConnector.ts +644 -0
  261. package/src/ts/plugins/server/PublicationOptimizer.ts +14 -0
  262. package/src/ts/plugins/server/SslPlugin.ts +84 -0
  263. package/src/ts/plugins/server/StaticPlugin.ts +79 -0
  264. package/src/ts/server/api/api.ts +19 -0
  265. package/src/ts/server/api/connectorApi.ts +345 -0
  266. package/src/ts/server/api/publicationApi.ts +159 -0
  267. package/src/ts/server/api/websiteApi.ts +432 -0
  268. package/src/ts/server/cli.ts +65 -0
  269. package/src/ts/server/config.ts +189 -0
  270. package/src/ts/server/connectors/FsHosting.ts +60 -0
  271. package/src/ts/server/connectors/FsStorage.test.ts +51 -0
  272. package/src/ts/server/connectors/FsStorage.ts +261 -0
  273. package/src/ts/server/connectors/connectors.ts +203 -0
  274. package/src/ts/server/events.ts +37 -0
  275. package/src/ts/server/expose.ts +19 -0
  276. package/src/ts/server/express.ts +70 -0
  277. package/src/ts/server/index.ts +100 -0
  278. package/src/ts/server/jobs.test.ts +75 -0
  279. package/src/ts/server/jobs.ts +87 -0
  280. package/src/ts/server/utils/BackwardCompat.ts +552 -0
  281. package/src/ts/server/utils/validation.ts +34 -0
  282. package/src/ts/types.ts +339 -0
@@ -0,0 +1,90 @@
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
+ import * as grapesjs from 'grapesjs/dist/grapes.min.js'
19
+ import {html, render} from 'lit-html'
20
+ import {live} from 'lit-html/directives/live.js'
21
+
22
+
23
+ const name = 'new-page-dialog'
24
+ const el = document.createElement('div')
25
+ let modal
26
+
27
+ export const cmdOpenNewPageDialog = 'new-page-dialog'
28
+
29
+ export const newPageDialog = grapesjs.plugins.add(name, (editor, opts) => {
30
+ editor.Commands.add(cmdOpenNewPageDialog, {
31
+ run: (_, sender, {page}) => {
32
+ modal = editor.Modal.open({
33
+ title: 'New Page',
34
+ content: '',
35
+ attributes: { class: 'new-page-dialog' },
36
+ })
37
+ .onceClose(() => {
38
+ editor.stopCommand(cmdOpenNewPageDialog) // apparently this is needed to be able to run the command several times
39
+ })
40
+ displayDialog(editor, opts, page)
41
+ modal.setContent(el)
42
+ const form = el.querySelector('form')
43
+ form.onsubmit = event => {
44
+ event.preventDefault()
45
+ saveDialog(editor, opts, page)
46
+ editor.stopCommand(cmdOpenNewPageDialog)
47
+ }
48
+ form.querySelector('input')?.focus()
49
+ return modal
50
+ },
51
+ stop: () => {
52
+ modal.close()
53
+ // el.innerHTML = ''
54
+ },
55
+ })
56
+ })
57
+
58
+ function onImport(editor, page) {
59
+ editor.Pages.select(page)
60
+ editor.runCommand('gjs-open-import-webpage')
61
+ }
62
+
63
+ function displayDialog(editor, config, page) {
64
+ render(html`
65
+ <form class="silex-form">
66
+ <label class="silex-form__element">
67
+ <h3>Name</h3>
68
+ <input type="text" name="name" .value=${live(page.getName() || '')}/>
69
+ </label>
70
+ <footer>
71
+ <input class="silex-button" type="button" @click=${e => onImport(editor, page)} value="Import from website">
72
+ <input class="silex-button" type="button" @click=${e => editor.stopCommand(cmdOpenNewPageDialog)} value="Cancel">
73
+ <input class="silex-button" type="submit" value="Ok">
74
+ </footer>
75
+ </form>
76
+ `, el)
77
+ }
78
+
79
+ function saveDialog(editor, config, page) {
80
+ const form = el.querySelector('form')
81
+ const formData = new FormData(form)
82
+ const data = Array.from(formData)
83
+ .reduce((aggregate, [key, value]) => {
84
+ aggregate[key] = value
85
+ return aggregate
86
+ }, {})
87
+ page.set(data)
88
+ // save if auto save is on
89
+ editor.getModel().set('changesCount', editor.getDirtyCount() + 1)
90
+ }
@@ -0,0 +1,81 @@
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
+ /**
19
+ * @fileoverview Import feature
20
+ * Let the user import HTML code when she creates a new page
21
+ *
22
+ */
23
+ // from https://github.com/artf/grapesjs-preset-webpage/blob/3e5a9e12998c9a32b6f1199953084163678e6c17/src/commands/openImport.js
24
+ export default function openImport(editor, config) {
25
+ const pfx = editor.getConfig('stylePrefix')
26
+ const modal = editor.Modal
27
+ const codeViewer = editor.CodeManager.getViewer('CodeMirror').clone()
28
+ const container = document.createElement('div')
29
+ const importLabel = config.modalImportLabel
30
+ const importCnt = config.modalImportContent
31
+ let viewerEditor = codeViewer.editor
32
+
33
+ // Init import button
34
+ const btnImp = document.createElement('button')
35
+ btnImp.type = 'button'
36
+ btnImp.innerHTML = config.modalImportButton
37
+ btnImp.className = `${pfx}btn-prim ${pfx}btn-import`
38
+ btnImp.onclick = e => {
39
+ editor.setComponents(viewerEditor.getValue().trim())
40
+ modal.close()
41
+ }
42
+
43
+ // Init code viewer
44
+ codeViewer.set({ ...{
45
+ codeName: 'htmlmixed',
46
+ theme: 'hopscotch',
47
+ readOnly: 0
48
+ }, ...config.importViewerOptions})
49
+
50
+ return {
51
+ run(_) {
52
+ if (!viewerEditor) {
53
+ const txtarea = document.createElement('textarea')
54
+
55
+ if (importLabel) {
56
+ const labelEl = document.createElement('div')
57
+ labelEl.className = `${pfx}import-label`
58
+ labelEl.innerHTML = importLabel
59
+ container.appendChild(labelEl)
60
+ }
61
+
62
+ container.appendChild(txtarea)
63
+ container.appendChild(btnImp)
64
+ codeViewer.init(txtarea)
65
+ viewerEditor = codeViewer.editor
66
+ }
67
+
68
+ modal.setTitle(config.modalImportTitle)
69
+ modal.setContent(container)
70
+ const cnt = typeof importCnt === 'function' ? importCnt(editor) : importCnt
71
+ codeViewer.setContent(cnt || '')
72
+ modal.open().getModel()
73
+ .once('change:open', () => editor.stopCommand(this.id))
74
+ viewerEditor.refresh()
75
+ },
76
+
77
+ stop() {
78
+ modal.close()
79
+ }
80
+ }
81
+ }
@@ -0,0 +1,118 @@
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
+ import * as grapesjs from 'grapesjs/dist/grapes.min.js'
19
+ import {html, render} from 'lit-html'
20
+
21
+ const pluginName = 'page-panel'
22
+ let open
23
+
24
+ export const cmdTogglePages = 'pages:open-panel'
25
+ export const cmdAddPage = 'pages:add'
26
+
27
+ function selectPage(editor, page) {
28
+ editor.Pages.select(page)
29
+ }
30
+ function addPage(editor, config) {
31
+ const pages = editor.Pages.getAll()
32
+ let idx = 1
33
+ const newPageName = config.newPageName || 'New page'
34
+ let pageName = newPageName
35
+ while(pages.find(p => p.getName() === pageName)) {
36
+ pageName = `${newPageName} ${idx++}`
37
+ }
38
+ const page = editor.Pages.add({ name: pageName })
39
+ editor.runCommand(config.cmdOpenNewPageDialog, {page})
40
+ }
41
+
42
+ function removePage(editor, page) {
43
+ if(editor.Pages.getAll().length === 1) {
44
+ console.error('can not delete the only page')
45
+ } else {
46
+ const isMain = page.get('type') === 'main'
47
+ const isSelected = editor.Pages.getSelected() === page
48
+ editor.Pages.remove(page.id)
49
+ const firstPage = editor.Pages.getAll()[0]
50
+ if(isMain) firstPage.set('type', 'main')
51
+ if(isSelected) selectPage(editor, firstPage)
52
+ }
53
+ }
54
+
55
+ function settingsPage(editor, config, page) {
56
+ editor.runCommand(config.cmdOpenSettings, {page})
57
+ }
58
+
59
+ function renderPages(editor, config) {
60
+ const pages = editor.Pages.getAll()
61
+ const selected = editor.Pages.getSelected()
62
+ const getPageFromEvent = (e) => {
63
+ const el = e.target.hasAttribute('data-page-id') ? e.target : e.target.parentNode
64
+ e.stopPropagation()
65
+ return editor.Pages.get(el.getAttribute('data-page-id'))
66
+ }
67
+ return html`<section class="pages">
68
+ <main class="pages__main ${pages.length === 1 ? 'pages__single-page' : ''}">
69
+ <div class="pages__list">
70
+ ${ pages.map(page => {
71
+ const name = page.getName() || page.attributes.type
72
+ // keep the same structure as the layers panel
73
+ return html`
74
+ <div class="pages__page ${selected === page ? 'pages__page-selected' : ''}" data-page-id=${page.id} @click=${e => selectPage(editor, getPageFromEvent(e))}>
75
+ <div class="pages__page-name">
76
+ ${ name }
77
+ </div>
78
+ <i class="pages__icon pages__remove-btn fa fa-trash" @click=${e => removePage(editor, getPageFromEvent(e))}></i>
79
+ <i class="pages__icon fa fa-cog" @click=${e => settingsPage(editor, config, getPageFromEvent(e))}></i>
80
+ </div>
81
+ </div>
82
+ `
83
+ })}
84
+ </div>
85
+ ${pages.length ? '' : html`<div class="flex-row">
86
+ No page yet.
87
+ </div>
88
+ `}
89
+ </main></section>`
90
+ }
91
+
92
+ export const pagePanelPlugin = grapesjs.plugins.add(pluginName, (editor, opts) => {
93
+ // create wrapper
94
+ const el = document.createElement('div')
95
+ el.classList.add('pages__wrapper')
96
+ // update
97
+ const doRender = () => render(renderPages(editor, opts), el)
98
+ editor.on('page', () => {
99
+ doRender()
100
+ })
101
+ editor.on('load', () => {
102
+ open = false
103
+ document.querySelector(opts.appendTo)
104
+ .appendChild(el)
105
+ doRender()
106
+ // click anywhere close it
107
+ // const close = (event) => {
108
+ // if(open) {
109
+ // editor.stopCommand(cmdTogglePages)
110
+ // //event.preventDefault()
111
+ // }
112
+ // }
113
+ // document.addEventListener('mousedown', close)
114
+ // add command to add pages
115
+ editor.Commands.add(cmdAddPage, () => addPage(editor, opts))
116
+ })
117
+ })
118
+
@@ -0,0 +1,107 @@
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
+ import {html, render} from 'lit-html'
19
+
20
+ const panelId = 'project-bar-panel'
21
+ const containerPanelId = 'project-bar-container'
22
+
23
+ export const projectBarPlugin = (editor, opts) => {
24
+ // create the panels container for all panels in grapesjs
25
+ const containerPanel = editor.Panels.addPanel({
26
+ id: containerPanelId,
27
+ visible : false,
28
+ })
29
+ // create the project bar panel in grapesjs
30
+ editor.Panels.addPanel({
31
+ id: panelId,
32
+ buttons: opts.panels,
33
+ visible : true,
34
+ })
35
+ const panelsEl = opts.panels.map(panel => {
36
+ const el = document.createElement('div')
37
+
38
+ // create container for panel
39
+ if(panel.attributes.containerClassName) {
40
+ el.classList.add('project-bar__panel', panel.attributes.containerClassName, 'gjs-hidden')
41
+
42
+ // add header
43
+ if(panel.attributes.title) {
44
+ render(html`
45
+ <header class="project-bar__panel-header">
46
+ <h3 class="project-bar__panel-header-title">${ panel.attributes.title }</h3>
47
+ ${ panel.buttons?.map(button => {
48
+ return html`
49
+ <div
50
+ class="project-bar__panel-header-button ${ button.className }"
51
+ @click=${e => editor.runCommand(button.command)}
52
+ ><span>${ button.text }</span></div>
53
+ `
54
+ }) }
55
+ </header>
56
+ `, el)
57
+ }
58
+
59
+ // temporarily attach it to the body
60
+ // this lets the block manager and other plugins attach to their container
61
+ document.body.appendChild(el)
62
+
63
+ // on load attach the panels to the main container
64
+ // this is when the main containerPanel has an element
65
+ editor.on('load', () => {
66
+ const containerPanelEl = containerPanel.view.el
67
+ containerPanelEl.appendChild(el)
68
+ })
69
+ }
70
+
71
+ // commands for show / hide panels
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, {
74
+ run() {
75
+ if(panel.attributes.containerClassName) {
76
+ containerPanel.set('visible', true)
77
+ el.classList.remove('gjs-hidden')
78
+ editor.Canvas.getFrameEl().classList.add('silex-squeeze-left')
79
+ }
80
+ },
81
+ stop() {
82
+ if(panel.attributes.containerClassName) {
83
+ containerPanel.set('visible', false)
84
+ el.classList.add('gjs-hidden')
85
+ editor.Canvas.getFrameEl().classList.remove('silex-squeeze-left')
86
+ }
87
+ },
88
+ })
89
+ })
90
+ function updateSqueez() {
91
+ const containerPanelEl = containerPanel.view.el
92
+ const iframe = editor.Canvas.getFrameEl()
93
+ iframe.classList.remove('enable-squeeze')
94
+ setTimeout(() => {
95
+ const left = iframe.getClientRects()[0]?.left
96
+ const right = containerPanelEl.getClientRects()[0]?.right
97
+ if(left < right || !right) iframe.classList.add('enable-squeeze')
98
+ else iframe.classList.remove('enable-squeeze')
99
+ }, 400) // More than the transition duration
100
+ // make sure the squeez corresponds to the state (reset when change page)
101
+ if(containerPanel.get('visible')) iframe.classList.add('silex-squeeze-left')
102
+ else iframe.classList.remove('silex-squeeze-left')
103
+ }
104
+ editor.on('load device:select page', () => {
105
+ updateSqueez()
106
+ })
107
+ }
@@ -0,0 +1,33 @@
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
+ import * as grapesjs from 'grapesjs/dist/grapes.min.js'
19
+
20
+ const pluginName = 'richText'
21
+
22
+ export const richTextPlugin = grapesjs.plugins.add(pluginName, (editor, opts) => {
23
+ editor.RichTextEditor.add('orderedList', {
24
+ icon: '1.',
25
+ attributes: {title: 'Ordered List'},
26
+ result: rte => rte.exec('insertOrderedList'),
27
+ })
28
+ editor.RichTextEditor.add('unorderedList', {
29
+ icon: '<i class="fa fa-list-ul"></i>',
30
+ attributes: {title: 'Unordered List'},
31
+ result: rte => rte.exec('insertUnorderedList'),
32
+ })
33
+ })
@@ -0,0 +1,114 @@
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
+ import {html, render} from 'lit-html'
19
+ import {map} from 'lit-html/directives/map.js'
20
+ import grapesjs from 'grapesjs/dist/grapes.min.js'
21
+
22
+ // constants
23
+ const pluginName = 'semantic'
24
+
25
+ const tags = [
26
+ 'DIV',
27
+ 'P',
28
+ 'H1',
29
+ 'H2',
30
+ 'H3',
31
+ 'H4',
32
+ 'H5',
33
+ 'H6',
34
+ 'SPAN',
35
+ 'MAIN',
36
+ 'ASIDE',
37
+ 'SECTION',
38
+ 'ADDRESS',
39
+ 'ARTICLE',
40
+ 'BUTTON',
41
+ 'NAV',
42
+ 'HEADER',
43
+ 'FOOTER',
44
+ 'DETAILS',
45
+ 'SUMMARY',
46
+ 'PRE',
47
+ 'BLOCKQUOTE',
48
+ ]
49
+
50
+ // plugin code
51
+ export const semanticPlugin = grapesjs.plugins.add(pluginName, (editor, opts) => {
52
+ // Add the new trait to all component types
53
+ editor.DomComponents.getTypes().map(type => {
54
+ editor.DomComponents.addType(type.id, {
55
+ model: {
56
+ defaults: {
57
+ traits: [
58
+ // Keep the type original traits
59
+ ...editor.DomComponents.getType(type.id).model.prototype.defaults.traits,
60
+ // Add the new trait
61
+ {
62
+ label: 'Tag name',
63
+ type: 'tag-name',
64
+ },
65
+ ]
66
+ }
67
+ }
68
+ })
69
+ })
70
+
71
+ function doRender(el: HTMLElement, tagName: string) {
72
+ const tagsWithCurrent = tags.includes(tagName.toUpperCase()) ? tags : tags.concat(tagName.toUpperCase())
73
+ render(html`
74
+ <label for="semantic__select" class="gjs-one-bg silex-label">Type</label>
75
+ <select id="semantic__select" @change=${event => doRender(el, event.target.value)}>
76
+ ${map<string>(tagsWithCurrent, tag => html`
77
+ <option value="${tag}" ?selected=${tagName.toUpperCase() === tag}>${tag}</option>
78
+ `)}
79
+ </select>
80
+ `, el)
81
+ }
82
+ function doRenderCurrent(el: HTMLElement) {
83
+ doRender(el, editor.getSelected()?.get('tagName') || '')
84
+ }
85
+
86
+ // Add semantic traits
87
+ // inspired by https://github.com/olivmonnier/grapesjs-plugin-header/blob/master/src/components.js
88
+ editor.TraitManager.addType('tag-name', {
89
+ createInput({ trait }) {
90
+ // Create a new element container and add some content
91
+ const el = document.createElement('div')
92
+ // update the UI when a page is added/renamed/removed
93
+ editor.on('page', () => doRenderCurrent(el))
94
+ doRenderCurrent(el)
95
+ // this will be the element passed to onEvent and onUpdate
96
+ return el
97
+ },
98
+ // Update the component based on UI changes
99
+ // `elInput` is the result HTMLElement you get from `createInput`
100
+ onEvent({ elInput, component, event }) {
101
+ const value = elInput.querySelector('#semantic__select').value
102
+ if(component.get('tagName').toUpperCase() === value.toUpperCase()){
103
+ // Already done
104
+ } else {
105
+ component.set('tagName', value)
106
+ }
107
+ },
108
+ // Update UI on the component change
109
+ onUpdate({ elInput, component }) {
110
+ const tagName = component.get('tagName')
111
+ doRender(elInput, tagName)
112
+ },
113
+ })
114
+ })