Ghost/ghost/admin/lib/koenig-editor/addon/options/cards.js

274 lines
8.7 KiB
JavaScript
Raw Normal View History

import createComponentCard from '../utils/create-component-card';
// map card names to component names
export const CARD_COMPONENT_MAP = {
hr: 'koenig-card-hr',
image: 'koenig-card-image',
markdown: 'koenig-card-markdown',
'card-markdown': 'koenig-card-markdown', // backwards-compat with markdown editor
html: 'koenig-card-html',
code: 'koenig-card-code',
embed: 'koenig-card-embed',
bookmark: 'koenig-card-bookmark',
gallery: 'koenig-card-gallery',
email: 'koenig-card-email',
button: 'koenig-card-button',
callout: 'koenig-card-callout',
2021-11-09 15:56:24 +03:00
nft: 'koenig-card-nft',
toggle: 'koenig-card-accordion',
'email-cta': 'koenig-card-email-cta',
paywall: 'koenig-card-paywall'
};
// map card names to generic icons (used for ghost elements when dragging)
export const CARD_ICON_MAP = {
hr: 'koenig/kg-card-type-divider',
image: 'koenig/kg-card-type-image',
markdown: 'koenig/kg-card-type-markdown',
'card-markdown': 'koenig/kg-card-type-markdown',
html: 'koenig/kg-card-type-html',
code: 'koenig/kg-card-type-gen-embed',
embed: 'koenig/kg-card-type-gen-embed',
bookmark: 'koenig/kg-card-type-bookmark',
gallery: 'koenig/kg-card-type-gallery',
email: 'koenig/kg-card-type-gen-embed',
button: 'koenig/kg-card-type-gen-embed',
callout: 'koenig/kg-card-type-gen-embed',
2021-11-09 15:56:24 +03:00
nft: 'koenig/kg-card-type-gen-embed',
toggle: 'koenig/kg-card-type-gen-embed',
'email-cta': 'koenig/kg-card-type-gen-embed',
paywall: 'koenig/kg-card-type-divider'
};
// TODO: move koenigOptions directly into cards now that card components register
// themselves so that they are available on card.component
export default [
createComponentCard('card-markdown'), // backwards-compat with markdown editor
Removed duplication of "delete if empty" card logic no issue The logic for "delete if empty" was duplicated in two places: 1. when `createComponentCard` is used to register a card, this option method was used when cleaning up a post when first rendering (cards in empty state can be saved before the editor auto-removes them but we don't want to show them again) 2. inside of card's own delete-if-empty handling on certain actions such as deselection or leaving edit mode - added an `ifEmpty` property to each card component - used by the editor's first-render cleanup routing if the property is present - can be re-used internally for the card's own deselect/exit-edit-mode behaviour - updated the cleanup routine in `<KoenigEditor>` - added a `allComponentCardsRegistered` property that will return `true` when the `.component` property is set on every card (the property is set during card component initialisation so we're at the mercy of Ember's render process so not all card components will be immediately registered) - swapped `_cleanup` for `_cleanupTask` that will wait for `allComponentCardsRegistered` to be `true` before performing cleanup, ensuring that we always have access to the card component's `isEmpty` property even when Ember renders cards across multiple render batches - checks for `isEmpty` being a boolean and will delete the card if it's value is `true` - updated all cards that had delete-if-empty behaviour - added `isEmpty` properties - removed duplicated logic in the `createComponentCard` calls
2021-11-10 17:45:54 +03:00
createComponentCard('code'),
createComponentCard('embed', {hasEditMode: false}),
createComponentCard('bookmark', {hasEditMode: false}),
createComponentCard('hr', {hasEditMode: false, selectAfterInsert: false}),
Removed duplication of "delete if empty" card logic no issue The logic for "delete if empty" was duplicated in two places: 1. when `createComponentCard` is used to register a card, this option method was used when cleaning up a post when first rendering (cards in empty state can be saved before the editor auto-removes them but we don't want to show them again) 2. inside of card's own delete-if-empty handling on certain actions such as deselection or leaving edit mode - added an `ifEmpty` property to each card component - used by the editor's first-render cleanup routing if the property is present - can be re-used internally for the card's own deselect/exit-edit-mode behaviour - updated the cleanup routine in `<KoenigEditor>` - added a `allComponentCardsRegistered` property that will return `true` when the `.component` property is set on every card (the property is set during card component initialisation so we're at the mercy of Ember's render process so not all card components will be immediately registered) - swapped `_cleanup` for `_cleanupTask` that will wait for `allComponentCardsRegistered` to be `true` before performing cleanup, ensuring that we always have access to the card component's `isEmpty` property even when Ember renders cards across multiple render batches - checks for `isEmpty` being a boolean and will delete the card if it's value is `true` - updated all cards that had delete-if-empty behaviour - added `isEmpty` properties - removed duplicated logic in the `createComponentCard` calls
2021-11-10 17:45:54 +03:00
createComponentCard('html'),
createComponentCard('image', {hasEditMode: false}),
createComponentCard('markdown'),
createComponentCard('gallery', {hasEditMode: false}),
Removed duplication of "delete if empty" card logic no issue The logic for "delete if empty" was duplicated in two places: 1. when `createComponentCard` is used to register a card, this option method was used when cleaning up a post when first rendering (cards in empty state can be saved before the editor auto-removes them but we don't want to show them again) 2. inside of card's own delete-if-empty handling on certain actions such as deselection or leaving edit mode - added an `ifEmpty` property to each card component - used by the editor's first-render cleanup routing if the property is present - can be re-used internally for the card's own deselect/exit-edit-mode behaviour - updated the cleanup routine in `<KoenigEditor>` - added a `allComponentCardsRegistered` property that will return `true` when the `.component` property is set on every card (the property is set during card component initialisation so we're at the mercy of Ember's render process so not all card components will be immediately registered) - swapped `_cleanup` for `_cleanupTask` that will wait for `allComponentCardsRegistered` to be `true` before performing cleanup, ensuring that we always have access to the card component's `isEmpty` property even when Ember renders cards across multiple render batches - checks for `isEmpty` being a boolean and will delete the card if it's value is `true` - updated all cards that had delete-if-empty behaviour - added `isEmpty` properties - removed duplicated logic in the `createComponentCard` calls
2021-11-10 17:45:54 +03:00
createComponentCard('email'),
createComponentCard('email-cta'),
createComponentCard('button'),
createComponentCard('callout'),
2021-11-09 15:56:24 +03:00
createComponentCard('nft', {hasEditMode: false}),
Removed duplication of "delete if empty" card logic no issue The logic for "delete if empty" was duplicated in two places: 1. when `createComponentCard` is used to register a card, this option method was used when cleaning up a post when first rendering (cards in empty state can be saved before the editor auto-removes them but we don't want to show them again) 2. inside of card's own delete-if-empty handling on certain actions such as deselection or leaving edit mode - added an `ifEmpty` property to each card component - used by the editor's first-render cleanup routing if the property is present - can be re-used internally for the card's own deselect/exit-edit-mode behaviour - updated the cleanup routine in `<KoenigEditor>` - added a `allComponentCardsRegistered` property that will return `true` when the `.component` property is set on every card (the property is set during card component initialisation so we're at the mercy of Ember's render process so not all card components will be immediately registered) - swapped `_cleanup` for `_cleanupTask` that will wait for `allComponentCardsRegistered` to be `true` before performing cleanup, ensuring that we always have access to the card component's `isEmpty` property even when Ember renders cards across multiple render batches - checks for `isEmpty` being a boolean and will delete the card if it's value is `true` - updated all cards that had delete-if-empty behaviour - added `isEmpty` properties - removed duplicated logic in the `createComponentCard` calls
2021-11-10 17:45:54 +03:00
createComponentCard('toggle'),
createComponentCard('paywall', {hasEditMode: false, selectAfterInsert: false})
];
export const CARD_MENU = [
{
title: 'Primary',
rowLength: 1,
items: [{
label: 'Image',
icon: 'koenig/kg-card-type-image',
desc: 'Upload, or embed with /image [url]',
iconClass: 'kg-card-type-native',
matches: ['image', 'img'],
type: 'card',
replaceArg: 'image',
params: ['src'],
payload: {
triggerBrowse: true
}
},
{
label: 'Markdown',
icon: 'koenig/kg-card-type-markdown',
desc: 'Insert a Markdown editor card',
iconClass: 'kg-card-type-native',
matches: ['markdown', 'md'],
type: 'card',
replaceArg: 'markdown'
},
{
label: 'HTML',
icon: 'koenig/kg-card-type-html',
desc: 'Insert a raw HTML card',
iconClass: 'kg-card-type-native',
matches: ['html'],
type: 'card',
replaceArg: 'html'
},
{
label: 'Gallery',
icon: 'koenig/kg-card-type-gallery',
desc: 'Create an image gallery',
iconClass: 'kg-card-type-native',
matches: ['gallery'],
type: 'card',
replaceArg: 'gallery'
},
{
label: 'Divider',
icon: 'koenig/kg-card-type-divider',
desc: 'Insert a dividing line',
iconClass: 'kg-card-type-native',
matches: ['divider', 'horizontal-rule', 'hr'],
type: 'card',
replaceArg: 'hr'
},
{
label: 'Bookmark',
icon: 'koenig/kg-card-type-bookmark',
desc: 'Embed a link as a visual bookmark',
matches: ['bookmark'],
type: 'card',
replaceArg: 'bookmark',
params: ['url']
},
{
label: 'Email content',
icon: 'koenig/kg-card-type-email',
desc: 'Only visible when delivered by email',
matches: ['email'],
type: 'card',
replaceArg: 'email',
postType: 'post'
},
{
label: 'Email call to action',
2021-07-28 14:25:21 +03:00
icon: 'koenig/kg-card-type-email-cta',
desc: 'Target free or paid members with a CTA',
matches: ['email', 'cta'],
type: 'card',
replaceArg: 'email-cta',
postType: 'post'
},
{
label: 'Public preview',
icon: 'koenig/kg-card-type-paywall',
desc: 'Attract signups with a public intro',
matches: ['public preview', 'preview', 'paywall'],
type: 'card',
replaceArg: 'paywall'
},
{
label: 'Button',
icon: 'koenig/kg-card-type-paywall',
desc: 'Clicky thing',
matches: ['button'],
type: 'card',
replaceArg: 'button',
feature: 'buttonCard'
},
{
label: 'Callout',
icon: 'koenig/kg-card-type-paywall',
desc: 'Info boxes that stand out',
matches: ['callout'],
type: 'card',
replaceArg: 'callout',
feature: 'calloutCard'
},
{
label: 'Toggle',
icon: 'koenig/kg-card-type-paywall',
desc: 'Add collapsible content',
matches: ['toggle'],
type: 'card',
replaceArg: 'toggle',
feature: 'accordionCard'
}]
},
{
title: 'Embed',
rowLength: 1,
items: [{
label: 'YouTube',
icon: 'koenig/kg-card-type-youtube',
desc: '/youtube [video url]',
matches: ['youtube'],
type: 'card',
replaceArg: 'embed',
params: ['url']
},
{
label: 'Twitter',
icon: 'koenig/kg-card-type-twitter',
desc: '/twitter [tweet url]',
matches: ['twitter'],
type: 'card',
replaceArg: 'embed',
params: ['url']
},
{
label: 'Unsplash',
icon: 'koenig/kg-card-type-unsplash',
desc: '/unsplash [search-term or url]',
iconClass: 'kg-card-type-unsplash',
matches: ['unsplash'],
type: 'card',
replaceArg: 'image',
params: ['searchTerm'],
payload: {
imageSelector: 'unsplash'
}
},
{
label: 'Vimeo',
icon: 'koenig/kg-card-type-vimeo',
desc: '/vimeo [video url]',
matches: ['vimeo'],
type: 'card',
replaceArg: 'embed',
params: ['url']
},
{
label: 'CodePen',
icon: 'koenig/kg-card-type-codepen',
2021-09-20 22:54:14 +03:00
desc: '/codepen [pen url]',
iconClass: 'kg-card-type-codepen',
matches: ['codepen'],
type: 'card',
replaceArg: 'embed',
params: ['url']
},
2018-08-15 19:11:16 +03:00
{
label: 'Spotify',
icon: 'koenig/kg-card-type-spotify',
desc: '/spotify [track or playlist url]',
2018-08-15 19:11:16 +03:00
matches: ['spotify'],
type: 'card',
replaceArg: 'embed',
params: ['url']
},
{
label: 'SoundCloud',
icon: 'koenig/kg-card-type-soundcloud',
desc: '/soundcloud [track or playlist url]',
matches: ['soundcloud'],
type: 'card',
replaceArg: 'embed',
params: ['url']
},
2021-11-09 15:56:24 +03:00
{
label: 'NFT',
icon: 'koenig/kg-card-type-other',
desc: '/nft [opensea url]',
iconClass: 'kg-card-type-native',
matches: ['nft', 'opensea'],
type: 'card',
replaceArg: 'embed',
params: ['url'],
feature: 'nftCard'
2021-11-09 15:56:24 +03:00
},
{
label: 'Other...',
icon: 'koenig/kg-card-type-other',
desc: '/embed [url]',
iconClass: 'kg-card-type-native',
matches: ['embed'],
type: 'card',
replaceArg: 'embed',
params: ['url']
}]
}
];