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
Mobile, Desktop: Make table horizontally scrollable by give table a div parent, so the width of the table is limited to the screen width. #10161
Mobile, Desktop: Make table horizontally scrollable by give table a div parent, so the width of the table is limited to the screen width. #10161
Conversation
…le is limited to the screen width on mobile devices
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.
Thank you for working on this!
I've left a few comments below.
@@ -249,6 +250,10 @@ function shimInit() { | |||
}); | |||
}; | |||
|
|||
platformUtil.mobilePlatform = () => { |
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.
Be aware that shim-init-react.js
isn't run within the mobile WebView
where rendering happens. As such, platform.mobilePlatform()
may return ''
while rendering.
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.
Fixed
packages/renderer/noteStyle.ts
Outdated
} | ||
|
||
.joplin-table-div{ | ||
overflow-x: overlay; |
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.
overflow-x: overlay; | |
overflow-x: auto; |
It looks like overflow: overlay;
is a legacy alias for overflow: auto
— consider using overflow-x: auto
here instead.
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.
Fixed
packages/renderer/noteStyle.ts
Outdated
@@ -58,6 +59,9 @@ export default function(theme: any, options: Options = null) { | |||
|
|||
const fontFamily = '\'Avenir\', \'Arial\', sans-serif'; | |||
|
|||
const isMobile = platformUtil.isMobile(); |
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.
Consider adding an option to Options
rather than moving platformUtil
to utils
. Because rendering now happens within a WebView (see e92f89d), after merging with dev
, platformUtil.isMobile
will return false
in the renderer on mobile platforms.
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.
Fixed
packages/renderer/noteStyle.ts
Outdated
.mce-content-body .joplin-editable { | ||
cursor: pointer !important; | ||
${overflowHidden} | ||
} |
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 think .mce-content-body
should apply to the TinyMCE rich text editor. Consider removing this or adding a comment explaining why this style is applied here.
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.
Fixed
} | ||
const cur = String(self.renderToken(tokens, idx, options)); | ||
logger.info(`cur:${cur}`); | ||
return platformUtil.isMobile() ? `<div class="joplin-table-div" data-handy-scroll>\n${cur}` : cur; |
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.
return platformUtil.isMobile() ? `<div class="joplin-table-div" data-handy-scroll>\n${cur}` : cur; | |
return platformUtil.isMobile() ? `<div class="joplin-table-div" >\n${cur}` : cur; |
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.
Fixed
tokens[idx].attrSet('source-line-end', `${lineEnd}`); | ||
} | ||
const cur = String(self.renderToken(tokens, idx, options)); | ||
logger.info(`cur:${cur}`); |
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.
Consider removing this and the other similar logger.info
statement.
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.
Fixed
@personalizedrefrigerator Thank you for patient guidance. I will try to add an option to control whether the table is restricted to div; I did not fully understand the design and multiple running environments of Joplin, and I will no longer modify shim.ts . |
overflow: overlay; is a legacy alias for overflow: auto Co-authored-by: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com>
Remove joplin-table-div incorrect CSS attribute Co-authored-by: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com>
…le is limited to the screen width on mobile devices, add an option to control whether the table is restricted to div
packages/renderer/MdToHtml.ts
Outdated
table_open: require('./MdToHtml/rules/table_open').default, | ||
table_close: require('./MdToHtml/rules/table_close').default, |
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.
Since these two functions work together, could you put them together in the same file and use a meaningful name please? The basic structure would be like this:
export default {
plugin: (markdownIt: any, params: any) => {
markdownIt.renderer.rules.table_close = function(tokens: any[], idx: number, options: any, _env: any, self: any) {
// ...
};
markdownIt.renderer.rules.table_open = function(tokens: any[], idx: number, options: any, _env: any, self: any) {
// ...
};
},
};
What does the plugin do exactly? It makes the table horizontally scrollable on mobile, is that correct?
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.
Yes, this plugin makes the table horizontally scrollable on mobile, so the maximum width of the table is the screen width. When dragging notes down, the interface does not sway left or right.
<div class="joplin-table-div" >
<table class="maps-to-line" source-line="186" source-line-end="312">
.....
</table>
</div>
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.
@laurent22 I didn't have a deep understanding of Joplin before, and under your guidance, I have re implemented it by adding options. And I found that makes the table horizontally scrollable on desktop platforms, operating experience is also good.
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.
export default { plugin: (markdownIt: any, params: any) => { markdownIt.renderer.rules.table_close = function(tokens: any[], idx: number, options: any, _env: any, self: any) { // ... }; markdownIt.renderer.rules.table_open = function(tokens: any[], idx: number, options: any, _env: any, self: any) { // ... }; }, };
Rebuild to: packages/renderer/MdToHtml/rules/tableHorizontallyScrollable.ts
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.
Do you agree with the option name "tableHorizontalyScrollable"? If you agree, I will try to commit modifications of
introduction options(readme/apps/markdown.md) and translations file(packages/tools/locales)
…zontally scrollable
Thanks for taking the time to implement this @wljince007. Just two things:
|
@laurent22 At that time, I wanted to distinguish the use of floating scrollbars when loading plugins on the desktop, but now it seems unnecessary to add an option, already remove this option. |
…crollable setting option
if (tokens[idx].map) { | ||
const line = tokens[idx].map[0]; | ||
const lineEnd = tokens[idx].map[1]; | ||
tokens[idx].attrJoin('class', 'maps-to-line'); | ||
tokens[idx].attrSet('source-line', `${line}`); | ||
tokens[idx].attrSet('source-line-end', `${lineEnd}`); | ||
} |
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.
Why is this necessary?
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.
copy from packages/renderer/MdToHtml/rules/source_map.ts, I will remove it.
@@ -0,0 +1,19 @@ | |||
export default { | |||
plugin: (markdownIt: any) => { | |||
markdownIt.renderer.rules.table_open = function(tokens: any[], idx: number, options: any, _env: any, self: any) { |
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.
Please don't use any
for any of the variables that you use. So tokens, options and self should have a type. You can get it from the markdown-it package
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 code is copy from packages/renderer/MdToHtml/rules/source_map.ts.
The exact type of self
variable is Renderer, but type Renderer has not been exported by markdown-it.
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.
change to
markdownIt.renderer.rules.table_open = function(tokens: MarkdownIt.Token[], idx: number, options: MarkdownIt.Options, _env: any, renderer: any) {
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.
@laurent22 Need I refactoring packages/renderer/MdToHtml/rules/{checkbox.ts, code_inline.ts, fence.ts, fountain.ts, highlight_keywords.ts, html_image.ts, image.ts, katex.ts, link_close.ts, link_open.ts, mermaid.ts, sanitize_html.ts, source_map.ts}
to add tokens, options
types?
tokens[idx].attrSet('source-line', `${line}`); | ||
tokens[idx].attrSet('source-line-end', `${lineEnd}`); | ||
} | ||
const cur = String(self.renderToken(tokens, idx, options)); |
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.
What is the return type of self.renderToken()
- isn't it already a string?
Also please avoid abbreviations, so cur => current
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.
Yes, redundant operations will be removed.
markdownIt.renderer.rules.table_close = function(tokens: any[], idx: number, options: any, _env: any, self: any) { | ||
const cur = String(self.renderToken(tokens, idx, options)); | ||
return `${cur}</div>\n`; | ||
}; |
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.
Same comments here
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.
added
packages/renderer/noteStyle.ts
Outdated
@@ -434,6 +434,11 @@ export default function(theme: any, options: Options = null) { | |||
overflow-x: auto; | |||
} | |||
|
|||
.joplin-table-div{ |
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.
Name it joplin-table-wrapper
please
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.
changed
It looks good now, thank you @wljince007! |
Summary
Table adds div parent, so the width of the table is limited to the screen width. #8994 use jQuery or handy-scroll to implement scrollbar floating on Desktop end, introducing too much code, this PR does not dependent on jQuery or handy-scroll, do not modify table layout logic on desktop.
Mobile Screen
android test:
android_test_small.mp4
Ios test:
ios_test_small.mp4
desktop test:
desktop_test_small.mp4
Implementation Description
Add a markdown option in packages/lib/models/Setting.ts:
packages/renderer/MdToHtml/rules/tableHorizontallyScrollable.ts: make table adds div parent, make table horizontally scrollable.