Skip to content

Conversation

@civing
Copy link
Contributor

@civing civing commented Oct 28, 2024

Adds triggers to be used when detecting a certain string and starting a trigger session. A trigger session begins when the magic string sequence is inserted, for instance an @ and will keep on sending user input back to the consumer until certain stop conditions occur.

Fixes: Lundalogik/crm-feature#4430
Fixes: https://github.com/Lundalogik/crm-feature/issues/4060
Co-authored-by: John Traas [email protected]

Review:

  • Commits are atomic
  • Commits have the correct type for the changes made
  • Commits with breaking changes are marked as such

Browsers tested:

(Check any that applies, it's ok to leave boxes unchecked if testing something didn't seem relevant.)

Windows:

  • Chrome
  • Edge
  • Firefox

Linux:

  • Chrome
  • Firefox

macOS:

  • Chrome
  • Firefox
  • Safari

Mobile:

  • Chrome on Android
  • iOS

@github-actions
Copy link

Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-3268/

@civing civing force-pushed the trigger-plugin branch 2 times, most recently from 194963a to e4f4e39 Compare October 31, 2024 07:19
@civing civing marked this pull request as ready for review October 31, 2024 07:20
);

return [
<limel-portal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The portal is a private component, so I don't think we should use it in an example since that will be very confusing for the consumers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: (

shadow: true,
styleUrl: 'text-editor-custom-triggers.scss',
})
export class TextEditorCustomTriggersExample {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot going on in this example, is it possible to simplify it a bit? There's usually a lot of copy/pasting going on from these examples, so we want them to be as easy to understand as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LucyChyzhova was adding a lot of good things but yeah, maybe we can simplify

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure! will check what we can do

export class TextEditorCustomTriggersExample {
constructor() {
this.portalId = createRandomString();
this.globalClickListener = this.globalClickListener.bind(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need explicit binding like this if we use an arrow function instead

Comment on lines 209 to 221
const sendTriggerEvent = (
type: 'triggerStart' | 'triggerStop' | 'triggerChange',
view: EditorView,
trigger: TriggerCharacter,
value: string,
) => {
const event = new CustomEvent<TriggerEventDetail>(type, {
detail: getTriggerEventDetail(view, trigger, value),
bubbles: true,
composed: true,
});
view.dom.dispatchEvent(event);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be fine, but I think it would be better if we emit the events from the component instead. We can have a callback on the component that we invoke from here that emits the events, e.g.

class TextEditor {
    @Event()
    public triggerStart: EventEmitter<TriggerEventDetail>;

    private emitTriggerStart(data) {
        this.triggerStart.emit(...);
    }
}

transactions.forEach((transaction) => {
if (transaction.docChanged) {
transaction.steps.forEach((step) => {
if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some nested code, and also unnecessary inline code comments, but I'm ok merging it and get it in if it works as expected 😄

Change the name to `CustomElementDefinition` to better reflect the
meaning of this type and how it's supposed to be used.
@civing civing force-pushed the trigger-plugin branch 2 times, most recently from 16cc82a to 5ac9bb0 Compare November 1, 2024 12:38
@civing civing requested a review from a team as a code owner November 1, 2024 12:38
@civing civing requested a review from jgroth November 1, 2024 12:42
civing and others added 5 commits November 1, 2024 13:47
Add types for trigger functionality
Adds triggers to be used when detecting a certain string and starting a
trigger session. A trigger session begins with the magic string sequence
is inserted, for instance an @ and will keep on sending user input back
to the consumer until certain stop conditions occur.

fixes: Lundalogik/crm-feature#4430

Co-authored-by: John Traas <[email protected]>
Change the name of the property `plugins` to `customElements`. The idea
is the be more explicit and less generic.
@civing civing enabled auto-merge (rebase) November 1, 2024 13:05
@civing civing merged commit 70c26b6 into main Nov 1, 2024
@civing civing deleted the trigger-plugin branch November 1, 2024 13:08
@lime-opensource
Copy link
Collaborator

🎉 This PR is included in version 37.65.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Comment on lines +156 to +158
triggerText = '';
triggerPosition = state.selection.$from.pos - triggerText.length;
sendTriggerEvent('triggerStart', view, activeTrigger, triggerText);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came across this when working on #3307. What's triggerText for, and is it supposed to ever be anything other than an empty string? If not, we can make the following change:

             triggerText = '';
-            triggerPosition = state.selection.$from.pos - triggerText.length;
+            triggerPosition = state.selection.$from.pos;
             sendTriggerEvent('triggerStart', view, activeTrigger, triggerText);

On the other hand, since it's a variable everywhere, it kinda looks like the intention is that it's not always going to remain an empty string? 🙂

Copy link
Contributor Author

@civing civing Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used it on line 193 in this file. :)
So no, we can't change the code according to your proposal. That would mean that the triggerPosition would be moved as you type and mess with the implementation.

        if (updatedText !== triggerText) {
            triggerText = updatedText;
            sendTriggerEvent(
                'triggerChange',
                pluginView,
                activeTrigger,
                triggerText.slice(1),
            );
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants