Ghost/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.hbs
Kevin Ansfield 7e98f1b9f4 Fixed editor cards being accessible when their availability checks failed
no issue

Using the slash menu it was possible to insert cards that shouldn't have been accessible based on their availability checks. This was happening because we were only hiding the visibility of the cards in the template rather than completely removing them from the slash command matching logic.

- added `{{card-menu-items}}` helper that combines the availability matching and snippet section addition to return a complete array of sections+items that match the current system state and post type
- added `@menuItems` argument set to the output of `{{card-menu-items}}` to the two card menu components so they are working against a pre-filtered list of menu items
  - lets us remove duplication of code that handled pushing snippets section into the menus
- removed availability check conditionals from `<KoenigMenuContent>` as the menu items passed in are now pre-filtered
2023-01-19 12:38:49 +00:00

127 lines
4.5 KiB
Handlebars

<div class="koenig-editor__editor-wrapper" data-kg="editor-wrapper">
<div class="koenig-editor__editor" data-kg="editor"></div>
</div>
{{!-- pop-up markup toolbar is shown when there's a selection --}}
<KoenigToolbar
@editor={{this.editor}}
@editorRange={{this.selectedRange}}
@activeMarkupTagNames={{this.activeMarkupTagNames}}
@activeSectionTagNames={{this.activeSectionTagNames}}
@toggleMarkup={{action "toggleMarkup"}}
@toggleSection={{action "toggleSection"}}
@toggleHeaderSection={{action "toggleHeaderSection"}}
@editLink={{action "editLink"}}
@addSnippet={{this.addSnippetIfPossible}}
/>
{{!-- pop-up link hover toolbar --}}
<KoenigLinkToolbar
@editor={{this.editor}}
@container={{this.element}}
@linkRange={{this.linkRange}}
@selectedRange={{this.selectedRange}}
@editLink={{action "editLink"}}
/>
{{!-- pop-up link editing toolbar --}}
{{#if this.linkRange}}
<KoenigLinkInput
@editor={{this.editor}}
@linkRange={{this.linkRange}}
@linkRect={{this.linkRect}}
@selectedRange={{this.selectedRange}}
@cancel={{action "cancelEditLink"}}
/>
{{/if}}
{{!-- pop-up snippet editing toolbar --}}
{{#if this.snippetRange}}
<KoenigSnippetInput
@editor={{this.editor}}
@snippetRange={{this.snippetRange}}
@snippetRect={{this.snippetRect}}
@snippets={{@snippets}}
@save={{@saveSnippet}}
@update={{@updateSnippet}}
@cancel={{this.cancelAddSnippet}}
/>
{{/if}}
{{!-- pop-up media selector --}}
{{#if this.activeSelectorComponent}}
<KoenigMediaSelector
@editor={{this.editor}}
@editorRange={{this.selectedRange}}
@replaceWithCardSection={{action "replaceWithCardSection"}}
@scrollContainerSelector={{this.scrollContainerSelector}}
@close={{action "closeSelectorComponent"}}
as |selector|
>
{{component this.activeSelectorComponent selector=selector}}
</KoenigMediaSelector>
{{/if}}
{{!-- (+) icon and pop-up menu --}}
<KoenigPlusMenu
@editor={{this.editor}}
@editorRange={{this.selectedRange}}
@snippets={{this.snippets}}
@replaceWithCardSection={{action "replaceWithCardSection"}}
@replaceWithPost={{action "replaceWithPost"}}
@openSelectorComponent={{action "openSelectorComponent"}}
@menuItems={{card-menu-items postType=@postType snippets=this.snippets deleteSnippet=this.deleteSnippet}}
/>
{{!-- slash menu popup --}}
<KoenigSlashMenu
@editor={{this.editor}}
@editorRange={{this.selectedRange}}
@snippets={{this.snippets}}
@replaceWithCardSection={{action "replaceWithCardSection"}}
@replaceWithPost={{action "replaceWithPost"}}
@openSelectorComponent={{action "openSelectorComponent"}}
@menuItems={{card-menu-items postType=@postType snippets=this.snippets deleteSnippet=this.deleteSnippet}}
/>
{{!-- all component cards wormholed into the editor canvas --}}
{{#each this.componentCards as |card|}}
{{#in-element card.destinationElement}}
{{component card.componentName
editor=this.editor
postModel=card.postModel
cardName=card.cardName
payload=card.payload
env=card.env
options=card.options
headerOffset=this.headerOffset
saveCard=(action card.env.save)
cancelCard=(action card.env.cancel)
removeCard=(action card.env.remove)
scrollToCard=(action "_scrollToCard" card)
isSelected=card.isSelected
isEditing=card.isEditing
selectCard=(action "_selectCard" card)
deselectCard=(action "_deselectCard" card)
editCard=(action "_editCard" card)
deleteCard=(action "_deleteCard" card)
saveAsSnippet=(if this.saveCardAsSnippetIfPossible (fn (optional this.saveCardAsSnippetIfPossible) card))
moveCursorToPrevSection=(action "moveCursorToPrevSection" card)
moveCursorToNextSection=(action "moveCursorToNextSection" card)
addParagraphAfterCard=(action "addParagraphAfterCard" card)
registerComponent=(action (mut card.component))
}}
{{/in-element}}
{{/each}}
{{!-- all component atoms wormholed into the editor canvas --}}
{{#each this.componentAtoms as |atom|}}
{{#in-element atom.destinationElement}}
{{component atom.componentName
editor=this.editor
atom=atom
saveAtom=(fn atom.env.save atom.env.value atom.env.payload)
registerComponent=(action (mut atom.component))
}}
{{/in-element}}
{{/each}}