From 71684fcbe959aa10695fbb84fbb34e82c6ecf6bb Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Mon, 25 Mar 2024 20:30:59 -0600 Subject: [PATCH] Begin prototyping a popout text editor for use across multiple sheet types --- module/dialogs/PopoutTextEditor.mjs | 51 +++++++++++++++++++++++++++++ styles/dialog/text-editor.scss | 5 +++ styles/root.scss | 1 + templates/dialogs/text-editor.hbs | 7 ++++ 4 files changed, 64 insertions(+) create mode 100644 module/dialogs/PopoutTextEditor.mjs create mode 100644 styles/dialog/text-editor.scss create mode 100644 templates/dialogs/text-editor.hbs diff --git a/module/dialogs/PopoutTextEditor.mjs b/module/dialogs/PopoutTextEditor.mjs new file mode 100644 index 0000000..fc74b62 --- /dev/null +++ b/module/dialogs/PopoutTextEditor.mjs @@ -0,0 +1,51 @@ +export class PopoutTextEditor extends FormApplication { + + /** + * Creates a form + */ + static create(value) {}; + + /** @override */ + constructor(actor, property, options = {}) { + super(actor, options); + this.property = property; + }; + + static get defaultOptions() { + const opts = mergeObject({ + ...super.defaultOptions, + title: `Rich Text Editor`, + template: `systems/dotdungeon/templates/dialogs/text-editor.hbs`, + width: 500, + height: 600, + submitOnClose: false, + resizable: true, + }); + return opts; + }; + + async getData() { + const ctx = await super.getData(); + + ctx.editor = { + engine: `prosemirror`, + collaborate: true, + content: await TextEditor.enrichHTML( + await getProperty(this.document, this.property), + { + relativeTo: this.object, + secrets: this.object.isOwner, + async: true + } + ), + target: this.property, + }; + + return ctx; + }; + + async _updateObject(_event, formData) { + console.log(formData); + this.document.update({ [this.property]: formData["text"] }) + }; +}; diff --git a/styles/dialog/text-editor.scss b/styles/dialog/text-editor.scss new file mode 100644 index 0000000..1c581c6 --- /dev/null +++ b/styles/dialog/text-editor.scss @@ -0,0 +1,5 @@ +.dialog--text-editor { + [role="application"] { + height: 100%; + } +} \ No newline at end of file diff --git a/styles/root.scss b/styles/root.scss index 2d2dd72..65c8cd5 100644 --- a/styles/root.scss +++ b/styles/root.scss @@ -9,6 +9,7 @@ @use "./global/design-v2.scss"; @use "./dialog/DiceList.scss"; +@use "./dialog/text-editor.scss"; @use "./sheets/partials/stat.scss"; @use "./sheets/partials/skill.scss"; diff --git a/templates/dialogs/text-editor.hbs b/templates/dialogs/text-editor.hbs new file mode 100644 index 0000000..77e2c21 --- /dev/null +++ b/templates/dialogs/text-editor.hbs @@ -0,0 +1,7 @@ +
+ {{editor + editor.content + target=editor.target + collaborate=editor.collaborate + }} +
\ No newline at end of file