Skip to content

Commit

Permalink
Merge pull request #52 from tailor-cms/chore/tweak-extension-installa…
Browse files Browse the repository at this point in the history
…tion

Improve extension support
  • Loading branch information
underscope committed May 14, 2024
2 parents b370751 + c6a0576 commit aafb073
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 32 deletions.
2 changes: 2 additions & 0 deletions apps/frontend/components/editor/ActivityContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const editorStore = useEditorStore();
const activityStore = useActivityStore();
const contentElementStore = useContentElementStore();
const commentStore = useCommentStore();
const storageService = useStorageService();
const doTheMagic = ({ type }: { type: string }) => {
if (!type) throw new Error('Type is required');
Expand All @@ -120,6 +121,7 @@ const doTheMagic = ({ type }: { type: string }) => {
const editorChannel = $eventBus.channel('editor');
provide('$editorBus', editorChannel);
provide('$eventBus', $eventBus);
provide('$storageService', storageService);
if (runtimeConfig.public.aiUiEnabled) provide('$doTheMagic', doTheMagic);
const isLoading = ref(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</template>

<script lang="ts" setup>
import { getElementId } from '@tailor-cms/utils';
import MetaInput from '@/components/common/MetaInput.vue';
const props = defineProps({
Expand Down
12 changes: 8 additions & 4 deletions apps/frontend/components/editor/Sidebar/ElementSidebar/index.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div class="element-sidebar">
<div class="pb-3 text-body-2 font-weight-bold text-primary-lighten-4">
<div class="pb-8 text-body-2 font-weight-bold text-primary-lighten-4">
Additional settings
</div>
<component :is="sidebarName" :element="element" @save="onSave" />
<ElementMeta :element="element" v-bind="metadata" />
<component :is="sidebarName" :element="element" />
</div>
</template>

Expand All @@ -13,17 +13,21 @@ import { getElementId, getSidebarName } from '@tailor-cms/utils';
import ElementMeta from './ElementMeta/index.vue';
const eventBus = inject('$eventBus') as any;
const storageService = useStorageService();
const props = defineProps({
element: { type: Object, required: true },
metadata: { type: Object, default: () => ({}) },
});
const eventBus = inject('$eventBus') as any;
const elementBus = eventBus.channel(`element:${getElementId(props.element)}`);
provide('$elementBus', elementBus);
provide('$storageService', storageService);
const sidebarName = getSidebarName(props.element?.type);
const onSave = (data: any) => elementBus.emit('save', data);
</script>

<style lang="scss" scoped>
Expand Down
7 changes: 4 additions & 3 deletions apps/frontend/components/editor/Toolbar/ElementToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import * as utils from '@tailor-cms/utils';
import DefaultToolbar from './DefaultToolbar.vue';
const { $ceRegistry } = useNuxtApp() as any;
const elementBus = inject('$elementBus') as any;
const props = defineProps({
element: { type: Object, required: true },
embed: { type: Object, default: null },
});
const { $ceRegistry } = useNuxtApp() as any;
const componentName = computed(() => {
const { type } = props.element;
if (utils.isQuestion(props.element.type)) return;
Expand All @@ -50,7 +51,7 @@ const config = computed(() => {
});
const componentExists = computed(() => !!$ceRegistry.get(props.element.type));
const save = () => null; // store.dispatch('repository/contentElements/save');
const save = (data: any) => elementBus.emit('save', data);
</script>

<style lang="scss" scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ const props = defineProps({
});
const elementBus = useContentElementBus(props.element);
const storageService = useStorageService();
provide('$elementBus', elementBus);
provide('$storageService', storageService);
</script>
11 changes: 11 additions & 0 deletions apps/frontend/composables/useStorageService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useCurrentRepository } from '@/stores/current-repository';

export const useStorageService = () => {
const { $storageService: storage } = useNuxtApp() as any;
const repositoryStore = useCurrentRepository();

return {
getUrl: (key: string) => storage.getUrl(repositoryStore.repositoryId, key),
upload: (file: any) => storage.upload(repositoryStore.repositoryId, file),
};
};
4 changes: 2 additions & 2 deletions extensions/content-elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@tailor-cms/ce-html-default-edit": "^0.0.5",
"@tailor-cms/ce-html-default-server": "^0.0.5",
"@tailor-cms/ce-image-edit": "^0.0.3",
"@tailor-cms/ce-image-server": "^0.0.1"
"@tailor-cms/ce-image-edit": "^1.0.0",
"@tailor-cms/ce-image-server": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const focus = () => {
onMounted(() => {
elementBus.on('delete', () => emit('delete'));
elementBus.on('save:meta', (meta) => emit('save:meta', meta));
elementBus.on('save', (data) => emit('save', onSave(data)));
const deferSaveFlag = () => setTimeout(() => (isSaving.value = false), 1000);
elementBus.on('saved', deferSaveFlag);
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-installer/src/ExtensionRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export class ExtensionRegistry {

// prettier-ignore
const exportModuleTemplate = _.template(
`<% _.forEach(entries, function(it, index) { %>import pkg<%- index %> from '<%- it %>';<%}); %>
`<% _.forEach(entries, function(it, index) { %>import pkg<%- index %> from '<%- it %>';
<%});%>
// prettier-ignore
export const elements = [
<% entries.forEach(function(it, index) { %>pkg<%- index %>,
Expand Down
26 changes: 16 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions schemas/course-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,14 @@ export const SCHEMA = {
// Temporary target both CE_IMAGE and IMAGE, will be removed once the
// old frontend is removed
elementMeta: [
{
type: 'IMAGE',
inputs: [
{
key: 'alt',
type: 'TEXTAREA',
label: 'Alt text',
},
],
},
{
type: 'CE_IMAGE',
inputs: [
{
key: 'alt',
key: 'captions',
type: 'TEXTAREA',
label: 'Alt text',
label: 'Captions',
placeholder: 'Enter captions...',
},
],
},
Expand Down

0 comments on commit aafb073

Please sign in to comment.