Skip to content

Commit

Permalink
Simplify composable even more
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Aug 16, 2024
1 parent e1ecb13 commit d19fc84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 6 additions & 7 deletions demos/editor-cdn/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</template>

<script setup lang="ts">
import { ref, reactive, watchEffect } from 'vue';
import { ref, reactive, computed } from 'vue';
import type * as CKEditor5 from 'https://cdn.ckeditor.com/typings/ckeditor5.d.ts';
import { useCKEditorCloud } from '../../src/plugin.js';
Expand All @@ -54,17 +54,14 @@ const config = reactive( {
toolbar: [ 'heading', '|', 'bold', 'italic' ]
} );
const EditorConstructor = ref<typeof CKEditor5.ClassicEditor | null>( null );
const editorInstance = ref<CKEditor5.ClassicEditor | null>( null );
watchEffect( () => {
const EditorConstructor = computed<typeof CKEditor5.ClassicEditor | null>( () => {
if ( !cloud.data.value ) {
return;
return null;
}
const { ClassicEditor, Paragraph, Essentials, Heading, Bold, Italic } = cloud.data.value.CKEditor;
EditorConstructor.value = class TestEditor extends ClassicEditor {
return class TestEditor extends ClassicEditor {
static builtinPlugins = [
Essentials,
Paragraph,
Expand All @@ -75,6 +72,8 @@ watchEffect( () => {
};
} );
const editorInstance = ref<CKEditor5.ClassicEditor | null>( null );
// Methods
function setEditorData() {
data.value = editorInstance.value?.getData() ?? '';
Expand Down
8 changes: 5 additions & 3 deletions src/useCKEditorCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md.
*/

import { toValue, type ComputedRef, type MaybeRefOrGetter } from 'vue';
import { toValue, type MaybeRefOrGetter } from 'vue';
import { useAsync, type AsyncComposableResult } from './composables/useAsync';

import {
Expand Down Expand Up @@ -35,9 +35,11 @@ import {
* }
*/
export default function useCKEditorCloud<A extends CKExternalPluginsMap>(
config: MaybeRefOrGetter<CKEditorCloudConfig<A>> | ComputedRef<CKEditorCloudConfig<A>>
config: MaybeRefOrGetter<CKEditorCloudConfig<A>>
): AsyncComposableResult<CKEditorCloudResult<A>> {
return useAsync(
(): Promise<CKEditorCloudResult<A>> => loadCKEditorCloud( toValue( config ) )
(): Promise<CKEditorCloudResult<A>> => loadCKEditorCloud(
toValue( config )
)
);
}

0 comments on commit d19fc84

Please sign in to comment.