move indentation lines from tweaks to its own mod (#287)

* move indentation lines from tweaks to its own mod

* changed indentation lines author to runargs

* refactor indentation lines to use the map function
This commit is contained in:
Ryo Hilmawan 2020-12-02 19:10:35 +07:00 committed by GitHub
parent 039670e639
commit b7e80cf25b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 50 deletions

View File

@ -0,0 +1,105 @@
/*
* indentation lines
* (c) 2020 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (c) 2020 Alexa Baldon (https://github.com/runargs)
* (c) 2020 CloudHill
* under the MIT license
*/
'use strict';
const { createElement } = require('../../pkg/helpers.js');
module.exports = {
id: '35815b3b-3916-4dc6-8769-c9c2448f8b57',
tags: ['extension'],
name: 'indentation lines',
desc: 'adds vertical relationship lines to make list trees easier to follow.',
version: '1.0.0',
author: 'runargs',
options: [
{
key: 'style',
label: 'style',
type: 'select',
value: ['solid', 'dashed', 'dotted', 'soft'],
},
{
key: 'bulleted_list',
label: 'bulleted list',
type: 'toggle',
value: true,
},
{
key: 'numbered_list',
label: 'numbered list',
type: 'toggle',
value: true,
},
{
key: 'to_do',
label: 'to-do list',
type: 'toggle',
value: true,
},
{
key: 'toggle',
label: 'toggle list',
type: 'toggle',
value: true,
},
],
hacks: {
'renderer/preload.js'(store, __exports) {
document.addEventListener('readystatechange', (event) => {
if (document.readyState !== 'complete') return false;
const selectors =
['bulleted_list', 'numbered_list', 'to_do', 'toggle']
.filter(l => store()[l])
.map(l => `.notion-page-content .notion-${l}-block > div > div:last-child`);
let style = 'solid';
let opacity = 1;
switch(store().style) {
case 'dashed':
style = 'dashed';
break;
case 'dotted':
style = 'dotted';
break;
case 'soft':
opacity = 0.25;
break;
}
if (selectors.length > 0) {
document
.querySelector('head')
.appendChild(
createElement(`
<style type="text/css">
.notion-app-inner {
--indentation-lines-style: ${style};
--indentation-lines-opacity: ${opacity};
}
${selectors.join(',\n')} {
position: relative;
}
${selectors.join('::before,\n')}::before {
content: "";
position: absolute;
height: calc(100% - 2em);
top: 2em;
left: -14.48px;
border-left: 1px var(--indentation-lines-style);
opacity: var(--indentation-lines-opacity);
}
</style>
`)
)
}
});
},
},
};

View File

@ -54,42 +54,6 @@
margin-bottom: -1.5px !important; margin-bottom: -1.5px !important;
} }
[data-tweaks*='[indentation_lines']
div.notion-selectable.notion-bulleted_list-block > div > div:last-child,
[data-tweaks*='[indentation_lines']
div.notion-selectable.notion-numbered_list-block > div > div:last-child {
position: relative;
}
[data-tweaks*='[indentation_lines']
div.notion-selectable.notion-bulleted_list-block > div > div:last-child::before,
[data-tweaks*='[indentation_lines']
div.notion-selectable.notion-numbered_list-block > div > div:last-child::before {
content: "";
position: absolute;
height: calc(100% - 2em);
top: 2em;
left: -14.48px;
border-left: 1px solid;
}
[data-tweaks*='[indentation_lines_dashed]']
div.notion-selectable.notion-bulleted_list-block > div > div:last-child::before,
[data-tweaks*='[indentation_lines_dashed]']
div.notion-selectable.notion-numbered_list-block > div > div:last-child::before {
border-left-style: dashed;
}
[data-tweaks*='[indentation_lines_dotted]']
div.notion-selectable.notion-bulleted_list-block > div > div:last-child::before,
[data-tweaks*='[indentation_lines_dotted]']
div.notion-selectable.notion-numbered_list-block > div > div:last-child::before {
border-left-style: dotted;
}
[data-tweaks*='[indentation_lines_soft]']
div.notion-selectable.notion-bulleted_list-block > div > div:last-child::before,
[data-tweaks*='[indentation_lines_soft]']
div.notion-selectable.notion-numbered_list-block > div > div:last-child::before {
opacity: 0.25;
}
[data-tweaks*='[scroll_db_toolbars]'] .notion-frame > .notion-scroller > [style*="overflow: visible;"], [data-tweaks*='[scroll_db_toolbars]'] .notion-frame > .notion-scroller > [style*="overflow: visible;"],
[data-tweaks*='[scroll_db_toolbars]'] .notion-page-content .notion-collection_view-block > :first-child { [data-tweaks*='[scroll_db_toolbars]'] .notion-page-content .notion-collection_view-block > :first-child {
overflow-x: auto !important; overflow-x: auto !important;

View File

@ -74,15 +74,6 @@ module.exports = {
type: 'toggle', type: 'toggle',
value: false, value: false,
}, },
{
key: 'indentation_lines',
label: 'indentation lines for lists',
desc:
'adds vertical indentation or relationship lines to make list trees\
easier to follow',
type: 'select',
value: ['none', 'solid', 'dashed', 'dotted', 'soft'],
},
{ {
key: 'scroll_db_toolbars', key: 'scroll_db_toolbars',
label: 'scroll database toolbars', label: 'scroll database toolbars',
@ -123,11 +114,6 @@ module.exports = {
}; };
window.addEventListener('resize', addResponsiveBreakpoint); window.addEventListener('resize', addResponsiveBreakpoint);
addResponsiveBreakpoint(); addResponsiveBreakpoint();
if (store().indentation_lines !== 'none') {
document.body.dataset.tweaks += `[indentation_lines_${
store().indentation_lines
}]`;
}
}); });
}, },
}, },