Skip to content

Commit

Permalink
Fix playground build
Browse files Browse the repository at this point in the history
  • Loading branch information
gohabereg committed Dec 26, 2023
1 parent dd6baa5 commit 6fe9d0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/model/src/EditorJSModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { BaseDocumentEvent } from './utils/EventBus/events/BaseEvent.js';
import type { Constructor } from './utils/types.js';
import { CaretManager } from './caret/index.js';

export interface EditorJSModel {
addEventListener<K extends keyof ModelEvents>(type: EventType.Changed, listener: (event: ModelEvents[K]) => void): void;
addEventListener(type: EventType.CaretUpdated, listener: (event: CaretUpdatedEvent) => void): void;
}

/**
* EditorJSModel is a wrapper around EditorDocument that prevent access to internal structures
*/
Expand Down
6 changes: 2 additions & 4 deletions packages/playground/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { Node, Input } from './components';
import { EditorDocument, EditorJSModel } from '@editorjs/model';
import { EditorDocument, EditorJSModel, EventType } from '@editorjs/model';
// import { data } from '@editorjs/model/dist/mocks/data.js';
import { ref } from 'vue';
Expand All @@ -19,13 +19,11 @@ const document = ref(new EditorDocument(model.serialized));
const serialized = ref(model.serialized);
model.addEventListener('changed', () => {
model.addEventListener(EventType.Changed, () => {
serialized.value = model.serialized;
document.value = new EditorDocument(model.serialized);
});
window.model = model;
</script>

<template>
Expand Down
11 changes: 9 additions & 2 deletions packages/playground/src/components/Input.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { BlockToolAdapter } from '@editorjs/dom-adapters';
import { CaretUpdatedEvent, createDataKey, type EditorJSModel, type TextIndex, type TextRange } from '@editorjs/model';
import {
CaretUpdatedEvent,
createDataKey,
type EditorJSModel,
EventType,
type TextIndex,
type TextRange
} from '@editorjs/model';
const input = ref<HTMLElement | null>(null);
const index = ref<TextRange | null>(null);
Expand All @@ -19,7 +26,7 @@ onMounted(() => {
if (input.value !== null) {
blockToolAdapter.attachInput(createDataKey('text'), input.value);
props.model.addEventListener('caret-updated', (evt: CaretUpdatedEvent) => {
props.model.addEventListener(EventType.CaretUpdated, (evt: CaretUpdatedEvent) => {
index.value = (evt.detail.index as TextIndex)[0];
});
}
Expand Down

0 comments on commit 6fe9d0a

Please sign in to comment.