-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Ability to insert variables, similar to suggestions #329
Comments
I think I have figured out a work-around: https://codesandbox.io/embed/vue-template-y0o5z (see Notably: .mention::after {
content: "}}";
} and new Mention({
matcher: {
char: "{{"
}, Seems to work! If you have any better suggestions, please let me know. If you think this is the best way, then please feel free to close this issue. Thanks! |
@moltar this is completely possible similiar to how you are using the Mention class already by defining your own custom node and plugin or use the suggestions plugin already available. As a working example your node would look something like:
Further if you want true variable previews you can find the tags in the html output and replace them (adding a tooltip with the original variable name) if you want to get a touch more complex. We have added a click event to that tooltip to allow it to be modified again by setting the replacement value to something a bit more complex. As an example of basic "variable preview":
For the Custom Plugin to support the class you could use the Mentions Suggestion Plugin as a base and slightly modify. Something to the following effect:
Hope that gives you or anyone else some further direction. |
I have opened a feature request for something like this. I would like to also suggest this be extended to be able to drag and drop from an arbitrary source component (such as a TreeView node, for example) and drop into specific location in text and have it result in a predefined "Suggestion". This suggestion could then be rearranged by dragging it around with the mouse or deleted by clicking an "X" icon in it. |
@softwareguy74 suggestions in the above example can be set to draggable as is within the document. As for dragging from outside the editor itself, we currently support that in our application by having the dropped variable simply insert the proper text into the editor. |
Oh boy that's quite a bit! Would be great to see this supported directly, so it can be simply configured. |
@asseti6 I have tried to get it working with your solution, but unfortunately without success. I know it has been quite a while since you replied to this issue, but could you give us a CodeSandbox or Repo URL with a working example? I would really appreciate it. |
Thanks for the guidance @asseti6 ! I have successfully implemented a variable solution where the user selects the variable by name, and tiptap displays the variable value inside of the document. The variable display within the document is reactive. For those wanting to display the value in the document, I would suggest - rather than doing a replace as below:
Use your vuex store instead:
|
@bbbford Very neat that you managed to get it working. Would you mind sharing a repo with us? That would be very, very helpful. |
Thanks for the suggestion! And thanks for the code snippets. It’s added to the list of community extensions in #819 and we consider to add it to the core in tiptap v2 at some point. I’m closing this here for now. ✌️ |
@hanspagel Is this still under consideration for v2 core? |
Does anyone have a working example using Livewire and/or AlpineJS? |
TinyMCE has an excellent Merge Tags feature: https://www.tiny.cloud/docs/tinymce/6/mergetags/ |
i have the exact same requirement as the mergetags. we would probably have to move to TinyMCE just for this. really liked tiptap though :/ |
I am going to need this same feature again for a new project. I'll update the original code as a node extension along with @bbbford's improvements and share it with the community. @hanspagel what the best way to share that for review and for the community? It will be towards the end of the month before I get to it. |
@asseti6 any progres =) <3 |
@hanspagel is there a way to recommend this for consideration again? thanks... sorry for the ping |
Hey @asseti6 , sorry for pinging. Have you released the code for it? |
Hey folks, I spend too much time creating this extension, thats an must have for a kind of application that i made to tiptap, after so many hours i decided to share what i've created. cheers 🚀 |
@joaomirandas Getting atom nodes to appear in the editor content isn’t really that hard – did you solve how to define the data source/values and get the values reflected? |
The best way I found to write variables and reflect the corresponding values was with node views. Basically I extended the mention extension passing my React component (could be in vue also, check the docs): export const VariablesExtension = MentionExtension.extend({
addNodeView() {
return ReactNodeViewRenderer(Variable);
},
parseHTML() {
return [
{
tag: "variable-component",
},
];
},
renderHTML({ HTMLAttributes }) {
return ["variable-component", mergeAttributes(HTMLAttributes)];
},
}); I also get the variables inside the VariableList to avoid using the export const VariablesList = forwardRef<
ReturnType<NonNullable<SuggestionOptions["render"]>>,
SuggestionProps<VariableOption>
>(({ command }, ref) => {
const [selectedIndex, setSelectedIndex] = useState(0);
const { data, isLoading } = useQuery({
queryKey: ["variable-options"],
queryFn: getVariables,
});
// component code Finally, through a // Provider
export function VariablesContextProvider({
children,
parseVariables,
}: {
children: React.ReactNode;
parseVariables: boolean;
}) {
const { data: values } = useQuery({
queryKey: ["variable-values"],
queryFn: getVariablesValues,
});
return (
<VariablesContext.Provider value={{ values, parseVariables }}>
{children}
</VariablesContext.Provider>
);
// VariableNode
export function Variable(props: NodeViewProps) {
const { parseVariables, values } = useVariablesContext();
return (
<NodeViewWrapper className="inline w-fit">
<span
className={cn(
"rounded bg-neutral-700 px-1 py-0.5 text-custom-primary-100"
)}
>
{parseVariables
? values?.find((value) => value.id === props.node.attrs.id)?.value ??
`variable not found`
: `@${props.node.attrs.label}`}
</span>
</NodeViewWrapper>
);
} The result: Here is the working example, I hope it helps someone. |
As someone being new to TipTap I found this very hard to implement gave up. Would be awesome if this would become an official extension. |
Hello, has anyone successfully implemented extension for merge tags? |
This worked for me, thanks to all your ideas:
|
|
Was able to generate something for this with v0.dev It generated the tiptap plugin and everything. It uses |
@Lau08 thanks for sharing your solution! |
Here is the MentionList.jsx:
|
Is your feature request related to a problem? Please describe.
Ability to insert pre-defined "variables" into the text.
E.g. user could type "today is {{ today }}" or "today is $today".
The editor would provide a list of suggested variables that are pre-defined.
The editor would also decorate these variables somehow once they are inserted.
The editor would allow to backspace and erase them.
Describe the solution you'd like
Similar to how suggestions work. But ability to use multiple characters, I guess. Like "{{" to begin suggestions.
Describe alternatives you've considered
N/A
Additional context
Integromat has a similar looking feature, but does not provide a suggest dropdown when typing. Can only use a mouse. http://take.ms/HSf3l
Zapier also has a similar one http://take.ms/NhODH
Thanks!
The text was updated successfully, but these errors were encountered: