Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no way to refresh the composer's preview except by modifying its content #3720

Open
n-peugnet opened this issue Jan 12, 2023 · 2 comments

Comments

@n-peugnet
Copy link
Contributor

Current Behavior

TextFormatter does not allow to use asynchronous calls in the Javascript part of a filter, so I need to refresh the preview once the Promise is resolved (see s9e/TextFormatter#208), but there is currently no way to do this in Flarum.

Steps to Reproduce

  1. In an extension, try to refresh the composer preview
  2. There is no way

Expected Behavior

There should be some kind of function, maybe in EditorDriverInterface, or directly in app.composer (ComposerState).

Screenshots

No response

Environment

  • Flarum version: 1.6.2
  • Website URL: localhost
  • Webserver: PBP built-in web server
  • Hosting environment: local
  • PHP version: 8.1.12 (cli) (built: Nov 10 2022 02:42:46) (NTS)
  • Browser: Mozilla Firefox 108.0

Output of php flarum info

Flarum core 1.6.2
PHP version: 8.1.12
MySQL version: 10.6.11-MariaDB-1
Loaded extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, intl, exif, mysqli, pdo_mysql, pdo_sqlite, Phar, posix, readline, shmop, SimpleXML, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, Zend OPcache
+-------------------------+-------------------------+------------------------------------------+
| Flarum Extensions       |                         |                                          |
+-------------------------+-------------------------+------------------------------------------+
| ID                      | Version                 | Commit                                   |
+-------------------------+-------------------------+------------------------------------------+
| flarum-flags            | v1.6.1                  |                                          |
| flarum-tags             | v1.6.1                  |                                          |
| flarum-approval         | v1.6.1                  |                                          |
| ianm-syndication        | dev-master              | b65feab8bc3514fe7e83b1b5d5ce4c9ff07b6b48 |
| flarum-suspend          | v1.6.1                  |                                          |
| flarum-subscriptions    | v1.6.1                  |                                          |
| flarum-sticky           | v1.6.1                  |                                          |
| flarum-statistics       | v1.6.1                  |                                          |
| flarum-mentions         | v1.6.1                  |                                          |
| flarum-markdown         | v1.6.1                  |                                          |
| flarum-lock             | v1.6.1                  |                                          |
| flarum-likes            | v1.6.1                  |                                          |
| flarum-lang-french      | v4.4.0                  |                                          |
| flarum-lang-english     | v1.6.0                  |                                          |
| flarum-emoji            | v1.6.1                  |                                          |
| flarum-bbcode           | v1.6.0                  |                                          |
| club-1-cross-references | dev-feat/text-formatter | 294ec30939e1a89239baae02f74c898bcd27fa5c |
+-------------------------+-------------------------+------------------------------------------+
Base URL: http://localhost:8080
Installation path: /home/nicolas/Source/www/flarum
Queue driver: sync
Session driver: file
Mail driver: smtp
Debug mode: ON

Possible Solution

No response

Additional Context

No response

@SychO9
Copy link
Member

SychO9 commented Jan 12, 2023

It's not clear to me what it is you're trying to do or why you need an async call in the filter. I don't consider this a bug at the moment, it seems more like feature.

Can you please explain your use case.

@n-peugnet
Copy link
Contributor Author

I don't consider this a bug at the moment, it seems more like feature.

Sorry you're right, this is not exactly a bug request. But as it was a technical request for the extension API, the bug tracker seemed more adequate.

It's not clear to me what it is you're trying to do or why you need an async call in the filter.
Can you please explain your use case.

I am writing an extension that modifies the content of CommentPosts. Among other features, it replaces bare links to discussions into a link that contains the title of the discussion. For now this is done in the frontend.

To make the modifications in the backend instead, and to get a preview of the modifications while writing a post, I figured that I needed to add a TextFormatter configuration (club-1/flarum-ext-cross-references#4).

As explained in s9e/TextFormatter#208, I need to make an asynchronous call in the Javascript part of the filter, in order to fetch the title of the discussion from the API (using app.store.find()). But TextFormatter filters only works synchronously, so I was pointed to refreshing the preview once the Promise resolves.

This is indeed working, as I tried to modify the content of the composer using app.composer.editor.insertAt() to trigger a refresh. But I would need to refresh the preview without editing the content of the composer.

From what I see here (ligne 40) there seem to be no way to trigger a refresh with an unchanged content:

const updatePreview = () => {
// Since we're polling, the composer may have been closed in the meantime,
// so we bail in that case.
if (!this.attrs.composer.isVisible()) return;
const content = this.attrs.composer.fields.content();
if (preview === content) return;
preview = content;
this.attrs.surround(() => s9e.TextFormatter.preview(preview || '', vnode.dom));
};

n-peugnet added a commit to club-1/flarum-ext-cross-references that referenced this issue Jan 29, 2023
This currently relies on a hack while the following issue is open:
<flarum/framework#3720>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants