read an write value

This commit is contained in:
JesmoDev
2024-09-10 14:12:05 +02:00
parent 1cb7440efe
commit 688b83367d
2 changed files with 21 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/
import './tiptap-fixed-menu.element.js';
import { Editor, StarterKit } from '@umbraco-cms/backoffice/external/tiptap';
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
@customElement('umb-input-tiptap')
export class UmbInputTiptapElement extends UUIFormControlMixin(UmbLitElement, '') {
@@ -22,23 +23,7 @@ export class UmbInputTiptapElement extends UUIFormControlMixin(UmbLitElement, ''
if (!editor) return;
const json =
this.value && typeof this.value === 'string'
? JSON.parse(this.value)
: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Hello Umbraco',
},
],
},
],
};
const json = this.value && typeof this.value === 'string' ? JSON.parse(this.value) : this.value;
// TODO: Try Disable css inject to remove prosemirror css
this._editor = new Editor({
@@ -48,7 +33,7 @@ export class UmbInputTiptapElement extends UUIFormControlMixin(UmbLitElement, ''
onUpdate: ({ editor }) => {
const json = editor.getJSON();
this.value = JSON.stringify(json);
console.log('json', json);
this.dispatchEvent(new UmbChangeEvent());
},
});
}

View File

@@ -1,10 +1,12 @@
import type UmbInputTiptapElement from '../../components/input-tiptap/input-tiptap.element.js';
import { customElement, html, property, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor';
import {
UmbPropertyValueChangeEvent,
type UmbPropertyEditorConfigCollection,
} from '@umbraco-cms/backoffice/property-editor';
import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry';
import '../../components/input-tiptap/input-tiptap.element.js';
// Look at Tiny for correct types
export interface UmbRichTextEditorValueType {
markup?: string;
@@ -22,10 +24,10 @@ export class UmbPropertyEditorUITiptapElement extends UmbLitElement implements U
}
@property({ attribute: false })
public set value(value: UmbRichTextEditorValueType) {
public set value(value: string) {
this._value = value;
}
public get value(): UmbRichTextEditorValueType {
public get value(): string {
return this._value;
}
@@ -33,10 +35,19 @@ export class UmbPropertyEditorUITiptapElement extends UmbLitElement implements U
_config?: UmbPropertyEditorConfigCollection;
@state()
private _value: UmbRichTextEditorValueType = {};
private _value: string = '';
#onChange(event: CustomEvent & { target: UmbInputTiptapElement }) {
const value = event.target.value as string;
this._value = value;
this.dispatchEvent(new UmbPropertyValueChangeEvent());
}
override render() {
return html`<umb-input-tiptap></umb-input-tiptap>`;
return html`<umb-input-tiptap
.value=${this.value}
@change=${this.#onChange}
.configuration=${this._config}></umb-input-tiptap>`;
}
}