-
-
Notifications
You must be signed in to change notification settings - Fork 508
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
CodeMirror element (continued) #2913
Conversation
Wow, @chrschorn that is awesome.
Yes, there may be some changes coming this way in 2.0. @falkoschindler has some ideas to improve dependency management. But just for my better understanding: would it not be possible to use the Rollup Bundler by hand and simply commit the resulting js files to the repository? |
I briefly considered bundling, but this being my first PR here, I didn't want to introduce a new dependency managment method without first getting input from you. We could follow the example here by creating a script (plus a Ideally we would follow this advice to load only the required languages:
What do you think? |
Sounds good to me. @falkoschindler are you ok with having a custom solution to create the delivered JavaScript for the time being? I think it would be good to have the latest version available in NiceGUI. In their version 5 repo they write
|
Yes, that sounds like a reasonable solution until we find a way to support such NPM dependency trees more conveniently in NiceGUI. 👍🏻 |
e5fcedf
to
2bb4508
Compare
.devcontainer/Dockerfile
Outdated
COPY nicegui pyproject.toml poetry.lock README.md ./ | ||
RUN poetry install --all-extras |
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.
These two lines caused the source to be copied to /
, which gave me recursive import errors when running pre-commit
. This fix only installes the dependencies, not nicegui itself. This is done in devcontainer.json
now which was previously disabled.
.devcontainer/devcontainer.json
Outdated
} | ||
} | ||
} | ||
}, |
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 is one too many }
here, causing the two lines below to never execute up until now.
Hi, this is what I got after digging deep into CodeMirror 6 and the packaging system 🙂 chrome_U6mOBmkveO.mp4This video is recorded with the Things implemented:
Please have a look and let me know if you want me to change things, move files around, clarify some code sections, etc.! |
Side note: Quite late into implementing this, I found a CodeMirror Vue component: https://github.surmon.me/vue-codemirror However I wasn't sure how to include this into NiceGUI and if its possible at all / would save work. |
Wow. That looks great. Thanks for all the hard work you've put in. I only glanced at it and want to share some thoughts:
|
@rodja Like other input elements ( |
btw, are there instructions to run the tests in the devcontainer or do you usually do that on your host machine? |
|
f7926f5
to
aeb0243
Compare
Alright, all implemented! Tests worked now. For some unknown reason they didn't work on the first try so I thought there were some extra steps required in the devcontainer to install selenium etc. |
Thanks for updating the branch with latest main and using the new |
Sure thing, sorry about that. It's a GitLab habit (rebase is the default in PRs over there). |
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.
Thanks a ton for this amazing pull request, @chrschorn!
Even though I don't yet understand every detail of the JavaScript code interacting with CodeMirror, the implementation looks pretty nice and the communication based on change sets seems to be very efficient. I just made a few changes:
-
I think I simplified the height definition by setting a default height of 16rem for the
ui.codemirror
element like we did for similar elements. Using a height of "100%" for the editor view makes it fill the whole element to reach the desired size. Applying Tailwind classes or CSS style seems to work as expected. -
I pre-generated lists for supported languages and themes. This simplifies the demo quite a bit, because we don't need to call async code. An extra pytests makes sure to stay in sync with the library in case the list grows with the next update.
-
I set the default language to
None
, because I think this is more intuitive - even though I noticed a visual difference between using "plaintext" vs. no language. -
Oh and I switched to "basicLight" as the default theme, because that's NiceGUI's default.
@rodja Can you have a look at the two Docker-related changes? Should we merge them or wait for PR #2964?
…rting, allow None in set_language
Hi, thank you for the review!
With the new changes I can't get any max or min height tailwind classes to work, have you tested those? Fixed sizes like I'd like to add an easy way to set min/max height back in.
The pre-generation is nice and makes the UI much easier to setup 👍 I had to add
I was torn here:
|
Min/max height Supported languages |
# Conflicts: # website/documentation/content/section_controls.py
@chrschorn Maybe I'm missing something, but it seems like all height classes are working as expected: with ui.row(wrap=False).classes('w-full'):
ui.codemirror('256px (default)')
ui.codemirror('300px min').classes('min-h-[300px]')
ui.codemirror('100px fix').classes('h-[100px]')
ui.codemirror('100px max').classes('max-h-[100px]')
|
What I can't get to work with just tailwind or css on the main element is an editor that has a dynamic size based on content, e.g. starting at 100px and it can expand up to 300px. The examples you posted are all stuck at exactly one height and don't allow the editor to grow. Maybe you have other ideas to make it work? with ui.row(wrap=False).classes('w-full'):
ui.codemirror('256px (default)')
ui.codemirror('300px min').classes('min-h-[300px]')
ui.codemirror('100px fix').classes('h-[100px]')
ui.codemirror('100px max').classes('max-h-[100px]')
ui.codemirror('500px max').classes('max-h-[500px]')
ui.codemirror('100px min 300px max' + "\n"*30).classes(replace='w-full min-h-[100px] max-h-[300px]')
ui.codemirror('100px min 300px max').classes(replace='w-full min-h-[100px] max-h-[300px]')
with ui.row():
for _ in range(200):
ui.label("text") We can also merge is at is though if you're fine with a fixed height for now, I'm happy with the rest 👍 |
Ah, I think I finally understand! A content-based height doesn't work. But actually I'd leave it this way for now, because:
So let's finish this PR and merge it into main. Great work, @chrschorn! 🚀 |
Sounds good. Happy to contribute - I really like NiceGUI! Looking forward to have this thing released! |
@chrschorn would you be interested in creating another pull request to introduce change sets from server to client? As mentioned that would be great for collaborative editing. But it could also be used as powerful alternative to |
@rodja Unfortunately I don't have a lot of time at the moment, but I do see the potential for cool features based on this as well. If you or someone else wants to work on this, please go ahead. |
Continuation of #2775
I was able to make things work reliably by chaining the loading of the js resources in the correct way. The value of the editor is also correctly in sync between client and backend.
Video of
codemirror_test.py
:chrome_yc4178WYoT.mp4
This element is using CodeMirror 5, even if some of the URLs say
6.x
. I spent a couple hours trying to make this work with CodeMirror 6 (the latest version), but this is not trivial because with v6, the distribution method (and APIs for that matter) have completely changed. Using CodeMirror 6 requires you to use a bundler since it is distributed in many small modules. We don't seem to have a reusable setup for that in the repository and I've tried extendingnpm.json
andnpm.py
to still make it work (you need like 7+ npm modules) but gave up in the end.If CodeMirror 5 is okay for everyone, I will continue finishing a first iteration.
Things still missing:
Is there anything else we should add for a first version?