@silexlabs/silex 3.3.1-2 → 3.3.1-4

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 (88) hide show
  1. package/dist/client/client/grapesjs/flex.d.ts +0 -4
  2. package/dist/client/client/grapesjs/sectors.d.ts +2 -1
  3. package/dist/client/css/admin.css +26 -9
  4. package/dist/client/index.html +3 -3
  5. package/dist/client/js/main.js +177 -106
  6. package/dist/client/js/main.js.LICENSE.txt +1 -1
  7. package/dist/client/page.d.ts +1 -1
  8. package/dist/client/types.d.ts +1 -17
  9. package/dist/plugins/client/types.d.ts +1 -17
  10. package/dist/plugins/client/types.js.map +1 -1
  11. package/dist/plugins/server/page.d.ts +1 -1
  12. package/dist/plugins/server/page.js.map +1 -1
  13. package/dist/plugins/server/plugins/server/GitlabConnector.js +94 -28
  14. package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -1
  15. package/dist/plugins/server/types.d.ts +1 -17
  16. package/dist/plugins/server/types.js.map +1 -1
  17. package/dist/server/server/cli.js +0 -0
  18. package/package.json +6 -6
  19. package/src/css/_variables.scss +4 -0
  20. package/src/css/grapesjs-plugins.scss +5 -0
  21. package/src/css/grapesjs.scss +8 -2
  22. package/src/css/loader.scss +9 -6
  23. package/src/css/page-panel.scss +3 -2
  24. package/src/css/project-bar.scss +0 -1
  25. package/src/html/index.pug +1 -1
  26. package/src/ts/client/assetUrl.ts +1 -1
  27. package/src/ts/client/grapesjs/css-props.ts +31 -18
  28. package/src/ts/client/grapesjs/dynamic-plugins.ts +63 -0
  29. package/src/ts/client/grapesjs/flex.ts +62 -57
  30. package/src/ts/client/grapesjs/img.ts +9 -3
  31. package/src/ts/client/grapesjs/index.ts +1 -0
  32. package/src/ts/client/grapesjs/li.ts +4 -1
  33. package/src/ts/client/grapesjs/plugin-options.ts +243 -0
  34. package/src/ts/client/grapesjs/sectors.ts +14 -14
  35. package/src/ts/client/grapesjs/static-plugins.ts +75 -0
  36. package/src/ts/client/grapesjs/storage.ts +25 -27
  37. package/src/ts/client/index.ts +3 -2
  38. package/src/ts/page.ts +1 -1
  39. package/src/ts/plugins/server/GitlabConnector.ts +99 -31
  40. package/src/ts/types.ts +2 -20
  41. package/dist/client/css/admin.css.map +0 -1
  42. package/dist/client/grapesjs-filter-styles/dist/index.d.ts +0 -4
  43. package/dist/client/grapesjs-fonts/dist/index.d.ts +0 -4
  44. package/dist/client/grapesjs-fonts/src/commands.d.ts +0 -3
  45. package/dist/client/grapesjs-fonts/src/fonts.d.ts +0 -4
  46. package/dist/client/grapesjs-storage-rate-limit/dist/index.d.ts +0 -4
  47. package/dist/client/grapesjs-ui-suggest-classes/dist/index.d.ts +0 -4
  48. package/dist/client/silex-lib/src/ts/client/api.d.ts +0 -90
  49. package/dist/client/silex-lib/src/ts/client/assetUrl.d.ts +0 -46
  50. package/dist/client/silex-lib/src/ts/client/config.d.ts +0 -102
  51. package/dist/client/silex-lib/src/ts/client/events.d.ts +0 -23
  52. package/dist/client/silex-lib/src/ts/client/expose.d.ts +0 -8
  53. package/dist/client/silex-lib/src/ts/client/grapesjs/LoginDialog.d.ts +0 -15
  54. package/dist/client/silex-lib/src/ts/client/grapesjs/PublicationManager.d.ts +0 -74
  55. package/dist/client/silex-lib/src/ts/client/grapesjs/PublicationUi.d.ts +0 -59
  56. package/dist/client/silex-lib/src/ts/client/grapesjs/blocks.d.ts +0 -1
  57. package/dist/client/silex-lib/src/ts/client/grapesjs/breadcrumbs.d.ts +0 -1
  58. package/dist/client/silex-lib/src/ts/client/grapesjs/css-props.d.ts +0 -6
  59. package/dist/client/silex-lib/src/ts/client/grapesjs/flex.d.ts +0 -7
  60. package/dist/client/silex-lib/src/ts/client/grapesjs/footer.d.ts +0 -2
  61. package/dist/client/silex-lib/src/ts/client/grapesjs/img.d.ts +0 -6
  62. package/dist/client/silex-lib/src/ts/client/grapesjs/index.d.ts +0 -9
  63. package/dist/client/silex-lib/src/ts/client/grapesjs/internal-links.d.ts +0 -1
  64. package/dist/client/silex-lib/src/ts/client/grapesjs/keymaps.d.ts +0 -123
  65. package/dist/client/silex-lib/src/ts/client/grapesjs/li.d.ts +0 -7
  66. package/dist/client/silex-lib/src/ts/client/grapesjs/new-page-dialog.d.ts +0 -2
  67. package/dist/client/silex-lib/src/ts/client/grapesjs/openImport.d.ts +0 -9
  68. package/dist/client/silex-lib/src/ts/client/grapesjs/page-panel.d.ts +0 -9
  69. package/dist/client/silex-lib/src/ts/client/grapesjs/project-bar.d.ts +0 -21
  70. package/dist/client/silex-lib/src/ts/client/grapesjs/resize-panel.d.ts +0 -1
  71. package/dist/client/silex-lib/src/ts/client/grapesjs/rich-text.d.ts +0 -4
  72. package/dist/client/silex-lib/src/ts/client/grapesjs/scroll.d.ts +0 -7
  73. package/dist/client/silex-lib/src/ts/client/grapesjs/sectors.d.ts +0 -11
  74. package/dist/client/silex-lib/src/ts/client/grapesjs/semantic.d.ts +0 -1
  75. package/dist/client/silex-lib/src/ts/client/grapesjs/settings-sections.d.ts +0 -16
  76. package/dist/client/silex-lib/src/ts/client/grapesjs/settings.d.ts +0 -4
  77. package/dist/client/silex-lib/src/ts/client/grapesjs/storage.d.ts +0 -3
  78. package/dist/client/silex-lib/src/ts/client/grapesjs/symbolDialogs.d.ts +0 -3
  79. package/dist/client/silex-lib/src/ts/client/grapesjs/upload-progress.d.ts +0 -2
  80. package/dist/client/silex-lib/src/ts/client/grapesjs/view-buttons.d.ts +0 -1
  81. package/dist/client/silex-lib/src/ts/client/index.d.ts +0 -10
  82. package/dist/client/silex-lib/src/ts/client/publication-transformers.d.ts +0 -42
  83. package/dist/client/silex-lib/src/ts/client/publish-custom-code-block.d.ts +0 -4
  84. package/dist/client/silex-lib/src/ts/client/publish-fonts.d.ts +0 -4
  85. package/dist/client/silex-lib/src/ts/client/utils.d.ts +0 -22
  86. package/dist/client/silex-lib/src/ts/constants.d.ts +0 -33
  87. package/dist/client/silex-lib/src/ts/page.d.ts +0 -2
  88. package/dist/client/silex-lib/src/ts/types.d.ts +0 -341
@@ -1,5 +1,5 @@
1
1
  import { API_PATH, API_WEBSITE_ASSET_READ, API_WEBSITE_PATH } from '../constants'
2
- import { Asset, ClientSideFileType, Component, ConnectorId, Page, Style, WebsiteId } from '../types'
2
+ import { Asset, ClientSideFileType, ConnectorId, Style, WebsiteId } from '../types'
3
3
 
4
4
  /**
5
5
  * @fileoverview Helpers to manage assets URL
@@ -16,6 +16,7 @@
16
16
  */
17
17
 
18
18
  import { Editor } from 'grapesjs'
19
+ import { registerSector } from './sectors'
19
20
 
20
21
  /**
21
22
  * @fileoverview Adds various css properties
@@ -120,15 +121,37 @@ export default (editor: Editor, opts) => {
120
121
  units: [ 'px', '%', 'em', 'rem', 'vh', 'vw' ],
121
122
  info: '',
122
123
  })
123
- const contentProp = editor.StyleManager.addProperty('general', {
124
+ registerSector(editor, {
125
+ id: 'content',
124
126
  name: 'Content',
125
- property: 'content',
126
- type: 'text',
127
- defaults: '',
128
- info: 'Generates content for an element.',
129
- full: true,
130
- visible: false,
131
- }, { at: 0 })
127
+ props: [{
128
+ name: 'Content',
129
+ property: 'content',
130
+ type: 'text',
131
+ defaults: '"Content in double quotes"',
132
+ info: 'Generates content for an element.',
133
+ full: true,
134
+ visible: false,
135
+ }],
136
+ shouldShow: async () => {
137
+ return new Promise<boolean>((resolve, reject) => {
138
+
139
+ requestAnimationFrame(() => {
140
+ try {
141
+ const state = editor.StyleManager
142
+ .getSelected()
143
+ ?.get('state')
144
+ if (state && ['before', 'after'].includes(state)) {
145
+ return resolve(true)
146
+ }
147
+ return resolve(false)
148
+ } catch(e) {
149
+ reject(e)
150
+ }
151
+ })
152
+ })
153
+ },
154
+ }, 0)
132
155
  /***************/
133
156
  /* Dimension */
134
157
  /***************/
@@ -825,16 +848,6 @@ export default (editor: Editor, opts) => {
825
848
  info: 'Aligns elements to scroll snaps.',
826
849
  }, { at: 11 })
827
850
 
828
- function refreshContentProp() {
829
- const state = editor.SelectorManager.getState()
830
- if (['before', 'after'].includes(state)) {
831
- contentProp.set('visible', true)
832
- } else {
833
- contentProp.set('visible', false)
834
- }
835
- }
836
- editor.on('selector:state component:selected component:styleUpdate style:sector:update', (state, opts) => setTimeout(() => refreshContentProp()))
837
- editor.StyleManager.getSector('general').on('change', () => refreshContentProp())
838
851
  editor.SelectorManager.states.add({name: 'before', label: 'Before'})
839
852
  editor.SelectorManager.states.add({name: 'after', label: 'After'})
840
853
  editor.SelectorManager.states.add({name: 'active', label: 'Active'})
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Dynamic plugin loader for external GrapesJS plugins
3
+ * These plugins are loaded at runtime to reduce initial bundle size
4
+ */
5
+
6
+ export interface PluginDefinition {
7
+ name: string
8
+ value: any
9
+ }
10
+
11
+ /**
12
+ * Load all external plugins dynamically
13
+ */
14
+ export async function loadDynamicPlugins(): Promise<PluginDefinition[]> {
15
+ const [
16
+ blocksBasicPlugin,
17
+ styleFilterPlugin,
18
+ formPlugin,
19
+ codePlugin,
20
+ filterStyles,
21
+ symbolsPlugin,
22
+ loadingPlugin,
23
+ fontsDialogPlugin,
24
+ selectorPlugin,
25
+ rateLimitPlugin,
26
+ borderPlugin,
27
+ backgroundPlugin,
28
+ notificationsPlugin,
29
+ keymapsDialogPlugin,
30
+ ] = await Promise.all([
31
+ import('grapesjs-blocks-basic').then(m => m.default),
32
+ import('grapesjs-style-filter').then(m => m.default),
33
+ import('grapesjs-plugin-forms').then(m => m.default),
34
+ import('grapesjs-custom-code').then(m => m.default),
35
+ import('@silexlabs/grapesjs-filter-styles').then(m => m.default),
36
+ import('@silexlabs/grapesjs-symbols').then(m => m.default),
37
+ import('@silexlabs/grapesjs-loading').then(m => m.default),
38
+ import('@silexlabs/grapesjs-fonts').then(m => m.default),
39
+ import('@silexlabs/grapesjs-advanced-selector').then(m => m.default),
40
+ import('@silexlabs/grapesjs-storage-rate-limit').then(m => m.default),
41
+ import('grapesjs-style-border').then(m => m.default),
42
+ import('grapesjs-style-bg').then(m => m.default),
43
+ import('@silexlabs/grapesjs-notifications').then(m => m.default),
44
+ import('@silexlabs/grapesjs-keymaps-dialog').then(m => m.default),
45
+ ])
46
+
47
+ return [
48
+ { name: 'grapesjs-blocks-basic', value: blocksBasicPlugin },
49
+ { name: 'grapesjs-style-filter', value: styleFilterPlugin },
50
+ { name: 'grapesjs-plugin-forms', value: formPlugin },
51
+ { name: 'grapesjs-custom-code', value: codePlugin },
52
+ { name: '@silexlabs/grapesjs-filter-styles', value: filterStyles },
53
+ { name: '@silexlabs/grapesjs-symbols', value: symbolsPlugin },
54
+ { name: '@silexlabs/grapesjs-loading', value: loadingPlugin },
55
+ { name: '@silexlabs/grapesjs-fonts', value: fontsDialogPlugin },
56
+ { name: '@silexlabs/grapesjs-advanced-selector', value: selectorPlugin },
57
+ { name: '@silexlabs/grapesjs-storage-rate-limit', value: rateLimitPlugin },
58
+ { name: 'grapesjs-style-border', value: borderPlugin },
59
+ { name: 'grapesjs-style-bg', value: backgroundPlugin },
60
+ { name: '@silexlabs/grapesjs-notifications', value: notificationsPlugin },
61
+ { name: '@silexlabs/grapesjs-keymaps-dialog', value: keymapsDialogPlugin },
62
+ ]
63
+ }
@@ -14,70 +14,75 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
  */
17
- import { Editor } from 'grapesjs'
18
- import { SectorConfig, registerSector } from './sectors'
17
+ import { Component, Editor } from 'grapesjs'
19
18
 
20
19
  /**
21
20
  * @fileoverview This plugin adds CSS properties for the UL, OL and LI elements
22
21
  *
23
22
  */
24
23
 
25
- export default (editor: Editor) => {
26
- const sectorConfigs: SectorConfig[] = [{
27
- name: 'Flex Item',
28
- props: [
29
- {
30
- id: 'order',
31
- name: 'Order',
32
- property: 'order',
33
- type: 'integer',
34
- defaults: 0,
35
- },
36
- {
37
- id: 'flex-grow',
38
- name: 'Flex Grow',
39
- property: 'flex-grow',
40
- type: 'integer',
41
- defaults: 0,
42
- },
43
- {
44
- id: 'flex-shrink',
45
- name: 'Flex Shrink',
46
- property: 'flex-shrink',
47
- type: 'integer',
48
- defaults: 1,
49
- },
50
- {
51
- id: 'flex-basis',
52
- name: 'Flex Basis',
53
- property: 'flex-basis',
54
- type: 'text',
55
- defaults: 'auto',
56
- },
57
- {
58
- id: 'align-self',
59
- name: 'Align Self',
60
- property: 'align-self',
61
- type: 'select',
62
- options: [
63
- { id: '', label: '' },
64
- { id: 'auto', label: 'auto' },
65
- { id: 'flex-start', label: 'flex-start' },
66
- { id: 'flex-end', label: 'flex-end' },
67
- { id: 'center', label: 'center' },
68
- { id: 'baseline', label: 'baseline' },
69
- { id: 'stretch', label: 'stretch' },
70
- ],
71
- },
72
- ],
73
- shouldShow: comp => {
74
- const parent = comp.parent()
75
- const display = parent?.getStyle()['display'] as string || ''
76
- return display.includes('flex')
77
- }
78
- }]
24
+ const FLEX_PROPS = [
25
+ 'flex-direction',
26
+ 'flex-wrap',
27
+ 'justify-content',
28
+ 'align-items',
29
+ 'align-content',
30
+ 'row-gap',
31
+ 'column-gap',
32
+ ]
33
+
34
+ const FLEX_ITEM_PROPS = [
35
+ 'flex-grow',
36
+ 'flex-shrink',
37
+ 'flex-basis',
38
+ 'order',
39
+ 'align-self',
40
+ ]
79
41
 
42
+ export default (editor: Editor) => {
80
43
  editor.on('load', () => {
81
- sectorConfigs.forEach(sectorConfig => registerSector(editor, sectorConfig, 2))
44
+ const sector = editor.StyleManager.getSector('flex')
45
+ // Add missing sectors
46
+ // FIXME: this makes grapesjs bug, all other props disappear
47
+ // FLEX_PROPS
48
+ // .concat(FLEX_ITEM_PROPS)
49
+ // .forEach(id => {
50
+ // if (!sector.getProperty(id)) {
51
+ // editor.StyleManager.addProperty('flex', {
52
+ // id,
53
+ // })
54
+ // }
55
+ // })
56
+ // Listen to the events that should trigger a visibility check
57
+ editor.on('component:selected', comp => applyVisibility(comp))
58
+ // `change:visible` is a workaround grapesjs behavior: https://github.com/GrapesJS/grapesjs/issues/3123
59
+ editor.on('change:visible', applyVisibility)
60
+ // `style:property:update` is useful for instantly display the flex sector when selecting display: inline-flex;
61
+ editor.on('style:property:update', () => applyVisibility())
62
+ function applyVisibility(comp: Component = editor.getSelected()) {
63
+ editor.off('change:visible', applyVisibility) // Avoid infinite loop
64
+ requestAnimationFrame(() => {
65
+ if(!comp) return // No selection yet
66
+ const computedDisplay = comp?.view?.el && getComputedStyle(comp.view.el)['display'] as string || ''
67
+ const isFlex = computedDisplay === 'flex' || computedDisplay === 'inline-flex'
68
+ const parent = comp.parent()
69
+ const parentComputedDisplay = parent?.view?.el && getComputedStyle(parent.view.el)['display'] as string || ''
70
+ const parentIsFlex = parentComputedDisplay === 'flex' || parentComputedDisplay === 'inline-flex'
71
+ if (parentIsFlex || isFlex) {
72
+ sector.set('visible', true)
73
+ }
74
+ if (parentIsFlex && isFlex) {
75
+ sector.getProperties()
76
+ .forEach(p => p.set('visible', true))
77
+ } else if (isFlex) {
78
+ sector.getProperties()
79
+ .forEach(p => p.set('visible', FLEX_PROPS.includes(p.getId())))
80
+ } else if (parentIsFlex) {
81
+ sector.getProperties()
82
+ .forEach(p => p.set('visible', FLEX_ITEM_PROPS.includes(p.getId())))
83
+ }
84
+ editor.on('change:visible', applyVisibility)
85
+ })
86
+ }
82
87
  })
83
88
  }
@@ -144,9 +144,15 @@ export default (editor: Editor, opts) => {
144
144
  }
145
145
  })
146
146
  // Watch changes made by grapesjs and revert them if needed
147
- sector.on('change:visible', () => {
148
- if(sector.get('visible') !== showSector) sector.set('visible', showSector)
149
- })
147
+ function doubleCheck() {
148
+ if(sector.get('visible') !== showSector){
149
+ sector.off('change:visible', doubleCheck)
150
+ sector.set('visible', showSector)
151
+ sector.on('change:visible', doubleCheck)
152
+ }
153
+ }
154
+ sector.on('change:visible', doubleCheck)
155
+
150
156
  // Add a new image type that handles the storage URL vs displayed URL
151
157
  domc.addType('image', {
152
158
  ...imgType,
@@ -143,6 +143,7 @@ export function getEditorConfig(config: ClientConfig): EditorConfig {
143
143
  showDevices: true,
144
144
 
145
145
  //pageManager: {},
146
+ telemetry: false,
146
147
 
147
148
  layerManager: {
148
149
  appendTo: '.layer-manager-container',
@@ -25,6 +25,7 @@ import { SectorConfig, registerSector } from './sectors'
25
25
  export default (editor: Editor) => {
26
26
  const sectorConfigs: SectorConfig[] = [
27
27
  {
28
+ id: 'list',
28
29
  name: 'List',
29
30
  props: [
30
31
  {
@@ -67,7 +68,9 @@ export default (editor: Editor) => {
67
68
  defaults: '',
68
69
  },
69
70
  ],
70
- shouldShow: comp => ['ul', 'ol', 'li'].includes(comp.get('tagName')?.toLowerCase() || ''),
71
+ shouldShow: comp => {
72
+ return comp && ['ul', 'ol', 'li'].includes(comp.get('tagName')?.toLowerCase() || '')
73
+ },
71
74
  },
72
75
  ]
73
76
 
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Plugin options configuration for all GrapesJS plugins
3
+ */
4
+
5
+ import { EditorConfig } from 'grapesjs'
6
+ import { PluginDefinition } from './dynamic-plugins'
7
+ import { staticPlugins, cmdPromptAddSymbol, cmdTogglePages, cmdAddPage, cmdOpenSettings, PROJECT_BAR_PANEL_ID, cmdOpenNewPageDialog } from './static-plugins'
8
+ import { NotificationEditor } from '@silexlabs/grapesjs-notifications'
9
+ import { cmdKeymapsDialog } from '@silexlabs/grapesjs-keymaps-dialog'
10
+ // Commands will be imported from the main index file
11
+ export const cmdToggleLayers = 'open-layers'
12
+ export const cmdToggleBlocks = 'open-blocks'
13
+ export const cmdToggleSymbols = 'open-symbols'
14
+ export const cmdToggleNotifications = 'open-notifications'
15
+ import { ClientConfig } from '../config'
16
+ import { titleCase } from '../utils'
17
+ import { defaultKms } from './keymaps'
18
+
19
+ // Constants
20
+ const PRIMARY_COLOR = '#333333'
21
+ const SECONDARY_COLOR = '#ddd'
22
+ const TERTIARY_COLOR = '#8873FE'
23
+ const QUATERNARY_COLOR = '#A291FF'
24
+ const catBasic = 'Containers'
25
+ const catComponents = 'Components'
26
+
27
+ // Create notification container
28
+ const notificationContainer = document.createElement('div')
29
+
30
+ /**
31
+ * Get plugin options for static plugins
32
+ */
33
+ export function getStaticPluginOptions(config: ClientConfig) {
34
+ const { websiteId, storageId } = config
35
+
36
+ const projectBarPluginValue = staticPlugins.find(p => p.name === './project-bar')?.value
37
+ const imgPluginValue = staticPlugins.find(p => p.name === './img')?.value
38
+ const pagePanelPluginValue = staticPlugins.find(p => p.name === './page-panel')?.value
39
+ const internalLinksPluginValue = staticPlugins.find(p => p.name === './internal-links')?.value
40
+ const keymapsPluginValue = staticPlugins.find(p => p.name === './keymaps')?.value
41
+ const loginDialogPluginValue = staticPlugins.find(p => p.name === './LoginDialog')?.value
42
+
43
+ return {
44
+ [projectBarPluginValue?.toString()]: {
45
+ panels: [
46
+ {
47
+ id: 'dash',
48
+ className: 'logo',
49
+ attributes: { title: 'Dashboard' },
50
+ command: () => {
51
+ window.location.href = '/'
52
+ },
53
+ }, {
54
+ id: 'block-manager-btn',
55
+ className: 'block-manager-btn fa fa-fw fa-plus',
56
+ name: 'Blocks',
57
+ attributes: { title: `Blocks (${titleCase(defaultKms.kmBlocks.keys, '+')})`, containerClassName: 'block-manager-container', },
58
+ command: cmdToggleBlocks,
59
+ }, {
60
+ id: 'symbols-btn',
61
+ className: 'symbols-btn fa-regular fa-gem',
62
+ name: 'Symbols',
63
+ attributes: { title: `Symbols (${titleCase(defaultKms.kmSymbols.keys, '+')})`, containerClassName: 'symbols-list-container', },
64
+ command: cmdToggleSymbols,
65
+ buttons: [
66
+ {
67
+ id: 'symbol-create-button',
68
+ className: 'gjs-pn-btn',
69
+ command: cmdPromptAddSymbol,
70
+ text: '\u271A',
71
+ },
72
+ ],
73
+ }, {
74
+ id: 'page-panel-btn',
75
+ className: 'page-panel-btn fa fa-fw fa-file',
76
+ name: 'Pages',
77
+ attributes: { title: `Pages (${titleCase(defaultKms.kmPages.keys, '+')})`, containerClassName: 'page-panel-container', },
78
+ command: cmdTogglePages,
79
+ buttons: [{
80
+ className: 'gjs-pn-btn',
81
+ command: cmdAddPage,
82
+ text: '\u271A',
83
+ }],
84
+ }, {
85
+ id: 'layer-manager-btn',
86
+ className: 'layer-manager-btn fa-solid fa-layer-group',
87
+ name: 'Layers',
88
+ attributes: { title: `Layers (${titleCase(defaultKms.kmLayers.keys, '+')})`, containerClassName: 'layer-manager-container', },
89
+ command: cmdToggleLayers,
90
+ }, {
91
+ id: 'font-dialog-btn',
92
+ className: 'font-manager-btn fa-solid fa-font',
93
+ name: 'Fonts',
94
+ attributes: { title: `Fonts (${titleCase(defaultKms.kmOpenFonts.keys, '+')})` },
95
+ command: () => {
96
+ // @ts-ignore - editor will be available at runtime
97
+ editor.runCommand('open-fonts')
98
+ },
99
+ }, {
100
+ id: 'settings-dialog-btn',
101
+ className: 'page-panel-btn fa-solid fa-gears',
102
+ name: 'Settings',
103
+ attributes: { title: `Settings (${titleCase(defaultKms.kmOpenSettings.keys, '+')})` },
104
+ command: cmdOpenSettings,
105
+ }, {
106
+ id: 'spacer',
107
+ attributes: {},
108
+ className: 'project-bar-spacer',
109
+ }, {
110
+ id: 'keymaps-btn',
111
+ className: 'keymaps-btn fa-solid fa-keyboard',
112
+ name: 'Shortcuts',
113
+ attributes: { title: 'Keyboard Shortcuts (Shift+H)' },
114
+ command: cmdKeymapsDialog,
115
+ }, {
116
+ id: 'notifications-btn',
117
+ className: 'notifications-btn fa-regular fa-bell',
118
+ name: 'Notifications',
119
+ attributes: { title: `Notifications (${titleCase(defaultKms.kmNotifications.keys, '+')})`, containerClassName: 'notifications-container', },
120
+ command: cmdToggleNotifications,
121
+ }, {
122
+ id: 'logout-btn',
123
+ className: 'logout-btn fa fa-fw fa-power-off',
124
+ name: 'Logout',
125
+ attributes: { title: 'Logout' },
126
+ command: () => {
127
+ // @ts-ignore - editor will be available at runtime
128
+ editor.runCommand('logout')
129
+ },
130
+ }],
131
+ },
132
+ ...(pagePanelPluginValue && {
133
+ [pagePanelPluginValue.toString()]: {
134
+ cmdOpenNewPageDialog,
135
+ cmdOpenSettings,
136
+ appendTo: '.page-panel-container',
137
+ }
138
+ }),
139
+ ...(internalLinksPluginValue && {
140
+ [internalLinksPluginValue.toString()]: {
141
+ // FIXME: warn the user about links in error
142
+ onError: (errors: any) => console.warn('Links errors:', errors),
143
+ }
144
+ }),
145
+ ...(keymapsPluginValue && {
146
+ [keymapsPluginValue.toString()]: {
147
+ disableKeymaps: false,
148
+ }
149
+ }),
150
+ ...(loginDialogPluginValue && {
151
+ [loginDialogPluginValue.toString()]: {
152
+ id: websiteId,
153
+ }
154
+ }),
155
+ ...(imgPluginValue && {
156
+ [imgPluginValue.toString()]: {
157
+ replacedElements: config.replacedElements,
158
+ websiteId,
159
+ storageId,
160
+ }
161
+ }),
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Get plugin options for dynamic plugins
167
+ */
168
+ export function getDynamicPluginOptions(dynamicPlugins: PluginDefinition[], config: ClientConfig) {
169
+ const options: any = {}
170
+
171
+ dynamicPlugins.forEach(plugin => {
172
+ const pluginKey = plugin.value.toString()
173
+
174
+ switch (plugin.name) {
175
+ case 'grapesjs-blocks-basic':
176
+ options[pluginKey] = {
177
+ blocks: ['text', 'image', 'video', 'map'],
178
+ category: catBasic,
179
+ }
180
+ break
181
+
182
+ case '@silexlabs/grapesjs-fonts':
183
+ options[pluginKey] = {
184
+ api_key: (config as any).fontsApiKey || 'dummy-key-for-development',
185
+ server_url: (config as any).fontsServerUrl,
186
+ api_url: (config as any).fontsApiUrl,
187
+ }
188
+ break
189
+
190
+ case '@silexlabs/grapesjs-filter-styles':
191
+ options[pluginKey] = {
192
+ appendBefore: '.gjs-sm-sectors',
193
+ }
194
+ break
195
+
196
+ case 'grapesjs-custom-code':
197
+ options[pluginKey] = {
198
+ blockLabel: 'HTML',
199
+ blockCustomCode: {
200
+ category: catComponents,
201
+ },
202
+ codeViewOptions: {
203
+ autoFormat: false,
204
+ },
205
+ }
206
+ break
207
+
208
+ case '@silexlabs/grapesjs-symbols':
209
+ options[pluginKey] = {
210
+ appendTo: '.symbols-list-container',
211
+ emptyText: 'No symbol yet.',
212
+ primaryColor: PRIMARY_COLOR,
213
+ secondaryColor: SECONDARY_COLOR,
214
+ highlightColor: TERTIARY_COLOR,
215
+ }
216
+ break
217
+
218
+ case '@silexlabs/grapesjs-storage-rate-limit':
219
+ options[pluginKey] = {
220
+ time: 5000,
221
+ }
222
+ break
223
+
224
+ case '@silexlabs/grapesjs-notifications':
225
+ options[pluginKey] = {
226
+ container: notificationContainer,
227
+ reverse: true,
228
+ }
229
+ break
230
+
231
+ case '@silexlabs/grapesjs-keymaps-dialog':
232
+ options[pluginKey] = {
233
+ longPressDuration: null,
234
+ shortcut: 'shift+h',
235
+ }
236
+ break
237
+ }
238
+ })
239
+
240
+ return options
241
+ }
242
+
243
+ export { notificationContainer }
@@ -22,16 +22,17 @@ import { Component, Editor } from 'grapesjs'
22
22
  */
23
23
 
24
24
  export type SectorConfig = {
25
+ id: string
25
26
  name: string
26
27
  props: any[]
27
- shouldShow: (comp: Component) => boolean
28
+ shouldShow: (comp: Component) => boolean | Promise<boolean>
28
29
  }
29
30
 
30
31
  export function registerSector(editor: Editor, config: SectorConfig, at?: number) {
31
32
  const sm = editor.StyleManager
32
- let sector = sm.getSector(config.name)
33
+ let sector = sm.getSector(config.id)
33
34
  if (!sector) {
34
- sector = sm.addSector(config.name, { name: config.name, open: false, visible: false }, { at })
35
+ sector = sm.addSector(config.id, { name: config.name, open: false, visible: false }, { at })
35
36
  }
36
37
 
37
38
  // Add props if not already present
@@ -42,18 +43,17 @@ export function registerSector(editor: Editor, config: SectorConfig, at?: number
42
43
  }
43
44
  })
44
45
 
45
- // Keep sector in sync with internal visibility state
46
- sector.on('change:visible', () => {
47
- const shouldBeVisible = sector.get('visible')
48
- if (shouldBeVisible !== config.shouldShow(editor.getSelected() as Component)) {
49
- sector.set('visible', !shouldBeVisible)
50
- }
51
- })
52
-
53
- editor.on('component:selected', comp => {
54
- const shouldShow = config.shouldShow(comp)
46
+ async function applyVisibility(comp: Component = editor.getSelected()) {
47
+ const shouldShow = await config.shouldShow(comp)
55
48
  if (sector.get('visible') !== shouldShow) {
49
+ sector.off('change:visible', applyVisibility)
56
50
  sector.set('visible', shouldShow)
51
+ sector.on('change:visible', applyVisibility)
52
+ // sector.getProperties()
53
+ // .forEach(p => p.set('visible', shouldShow))
57
54
  }
58
- })
55
+ }
56
+
57
+ sector.on('change:visible', applyVisibility)
58
+ editor.on('component:selected', comp => applyVisibility(comp))
59
59
  }