-
Notifications
You must be signed in to change notification settings - Fork 16
Trigger plugin #3268
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
Trigger plugin #3268
Conversation
|
Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-3268/ |
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
194963a to
e4f4e39
Compare
e4f4e39 to
29d1df5
Compare
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
| ); | ||
|
|
||
| return [ | ||
| <limel-portal |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
| 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); | ||
| }; |
There was a problem hiding this comment.
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(...);
}
}
src/components/text-editor/prosemirror-adapter/plugins/trigger-plugin.ts
Outdated
Show resolved
Hide resolved
| transactions.forEach((transaction) => { | ||
| if (transaction.docChanged) { | ||
| transaction.steps.forEach((step) => { | ||
| if ( |
There was a problem hiding this comment.
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.
16cc82a to
5ac9bb0
Compare
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.
5ac9bb0 to
d8ebb50
Compare
|
🎉 This PR is included in version 37.65.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
| triggerText = ''; | ||
| triggerPosition = state.selection.$from.pos - triggerText.length; | ||
| sendTriggerEvent('triggerStart', view, activeTrigger, triggerText); |
There was a problem hiding this comment.
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? 🙂
There was a problem hiding this comment.
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),
);
}
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:
Browsers tested:
(Check any that applies, it's ok to leave boxes unchecked if testing something didn't seem relevant.)
Windows:
Linux:
macOS:
Mobile: