Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
flow-text-editor events tested
Browse files Browse the repository at this point in the history
  • Loading branch information
vikas-cldcvr committed Jul 10, 2024
1 parent 9b0b8b9 commit 592d23a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/flow-text-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ollion/flow-text-editor",
"version": "2.1.0",
"version": "0.0.1",
"description": "Code editor component for flow library",
"module": "dist/flow-text-editor.es.js",
"main": "dist/flow-text-editor.es.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { unsafeCSS, html, PropertyValues } from "lit";
import { unsafeCSS, html, PropertyValues, PropertyValueMap } from "lit";
import { FRoot, flowElement } from "@ollion/flow-core";
import globalStyle from "./f-text-editor-global.scss?inline";
import { FTextArea } from "@ollion/flow-core";
import { property } from "lit/decorators.js";
import { injectCss } from "@ollion/flow-core-config";
import { createRef, ref } from "lit-html/directives/ref.js";
import Quill from "quill";
import { keyed } from "lit-html/directives/keyed.js";
import { unsafeHTML } from "lit/directives/unsafe-html.js";

injectCss("f-text-editor", globalStyle);

Expand All @@ -31,6 +33,10 @@ export type FTextEditorToolbarAction =
| { align: ("left" | "center" | "right" | "justify")[] };
@flowElement("f-text-editor")
export class FTextEditor extends FRoot {
/**
* To force re-render
*/
key = 0;
/**
* css loaded from scss file
*/
Expand Down Expand Up @@ -76,15 +82,23 @@ export class FTextEditor extends FRoot {
createRenderRoot() {
return this;
}
protected willUpdate(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
super.willUpdate(changedProperties);

this.key += 1;
}

render() {
return html`<div
${ref(this.editorRoot)}
@input=${(ev: InputEvent) => ev.stopPropagation()}
class="f-text-editor-root"
>
${this.value}
</div>`;
return keyed(
this.key,
html`<div
${ref(this.editorRoot)}
@input=${(ev: InputEvent) => ev.stopPropagation()}
class="f-text-editor-root"
>
${unsafeHTML(this.value)}
</div>`
);
}

protected updated(changedProperties: PropertyValues): void {
Expand Down
4 changes: 2 additions & 2 deletions stories/flow-text-editor/f-text-editor.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {

export const Playground = {
render: (args: Record<string, any>) => {
const handleInput = function (ev: Event) {
const handleInput = function (ev: CustomEvent) {
console.log(ev);
};

Expand All @@ -38,7 +38,7 @@ export const Playground = {
},

args: {
value: `Hello World!`,
value: `<h1>Hello World!</h1>`,
placeholder: `Enter rich text here...`
}
};

0 comments on commit 592d23a

Please sign in to comment.