From 6ceca21be391a7c23fe5e322f30ef84e33b3cfec Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Tue, 28 May 2024 21:30:57 +1000 Subject: [PATCH] feat(right-to-left): update api compat, rtl + right-indent tocs --- src/extensions/right-to-left/client.css | 21 ++----- src/extensions/right-to-left/client.mjs | 55 +++++++++--------- src/extensions/right-to-left/mod.json | 24 ++++---- .../right-to-left/right-to-left.jpg | Bin 13795 -> 0 bytes src/registry.json | 1 + 5 files changed, 43 insertions(+), 58 deletions(-) delete mode 100644 src/extensions/right-to-left/right-to-left.jpg diff --git a/src/extensions/right-to-left/client.css b/src/extensions/right-to-left/client.css index 3597fcc..daebfb6 100644 --- a/src/extensions/right-to-left/client.css +++ b/src/extensions/right-to-left/client.css @@ -1,26 +1,15 @@ /** * notion-enhancer: right to left * (c) 2021 obahareth (https://omar.engineer) - * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (c) 2024 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ -.notion-page-content - .notion-table_of_contents-block - > div - > div - > a - > div - > div[style*='margin-left: 24px'] { +/* indent rtl toc header levels, + * https://github.com/notion-enhancer/notion-enhancer/issues/616 */ +.notion-table_of_contents-block div[style*="margin-left: 24px"] { margin-inline-start: 24px; } - -.notion-page-content - .notion-table_of_contents-block - > div - > div - > a - > div - > div[style*='margin-left: 48px'] { +.notion-table_of_contents-block div[style*="margin-left: 48px"] { margin-inline-start: 48px; } diff --git a/src/extensions/right-to-left/client.mjs b/src/extensions/right-to-left/client.mjs index decba98..dbc7c4f 100644 --- a/src/extensions/right-to-left/client.mjs +++ b/src/extensions/right-to-left/client.mjs @@ -1,50 +1,47 @@ /** * notion-enhancer: right to left * (c) 2021 obahareth (https://omar.engineer) - * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (c) 2024 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ -'use strict'; - -export default async function ({ web }, db) { - const pageContentSelector = ` - .notion-page-content > - div[data-block-id]:not([dir]):not(.notion-column_list-block):not(.notion-collection_view_page-block), - [placeholder="Untitled"]:not([dir]), - .notion-column-block > div[data-block-id]:not([dir]), - .notion-collection_view-block:not([dir]), - .notion-table-view:not([dir]), - .notion-board-view:not([dir]), - .notion-gallery-view:not([dir])`, - listItemSelector = ` - div[placeholder="List"]:not([style*="text-align: start"]), - div[placeholder="To-do"]:not([style*="text-align: start"]), - div[placeholder="Toggle"]:not([style*="text-align: start"])`, +export default async (api) => { + const { addMutationListener } = api, + pageContentSelector = ` + :is(.notion-page-content > + div[data-block-id]:not(.notion-column_list-block):not(.notion-collection_view_page-block), + .notion-page-content .notion-table_of_contents-block a, + [placeholder="Untitled"], + .notion-column-block > div[data-block-id], + .notion-collection_view-block, + .notion-table-view, + .notion-board-view, + .notion-gallery-view):not([dir])`, + listItemSelector = `:is(div[placeholder="List"], div[placeholder="To-do"], + div[placeholder="Toggle"]):not([style*="text-align: start"])`, inlineEquationSelector = '.notion-text-equation-token .katex-html:not([style*="direction: rtl;"])'; - const autoAlignText = () => { document .querySelectorAll(pageContentSelector) - .forEach(($block) => $block.setAttribute('dir', 'auto')); + .forEach(($block) => $block.setAttribute("dir", "auto")); document.querySelectorAll(listItemSelector).forEach(($item) => { - $item.style['text-align'] = 'start'; + $item.style["text-align"] = "start"; }); document.querySelectorAll(inlineEquationSelector).forEach(($equation) => { - $equation.style.direction = 'rtl'; - $equation.style.display = 'inline-flex'; - $equation.style.flexDirection = 'row-reverse'; + $equation.style.direction = "rtl"; + $equation.style.display = "inline-flex"; + $equation.style.flexDirection = "row-reverse"; for (const $symbol of $equation.children) { - $symbol.style.direction = 'ltr'; + $symbol.style.direction = "ltr"; } }); }; - web.addDocumentObserver(autoAlignText, [ + + const textareas = [ pageContentSelector, listItemSelector, inlineEquationSelector, - ]); - await web.whenReady(); - autoAlignText(); -} + ].join(","); + addMutationListener(textareas, autoAlignText); +}; diff --git a/src/extensions/right-to-left/mod.json b/src/extensions/right-to-left/mod.json index 1a1d396..9ff86a5 100644 --- a/src/extensions/right-to-left/mod.json +++ b/src/extensions/right-to-left/mod.json @@ -1,23 +1,21 @@ { - "name": "right to left", - "id": "b28ee2b9-4d34-4e36-be8a-ab5be3d79f51", + "name": "Right To Left", "version": "1.5.0", - "description": "enables auto rtl/ltr text direction detection.", - "preview": "right-to-left.jpg", - "tags": ["extension", "usability"], + "id": "b28ee2b9-4d34-4e36-be8a-ab5be3d79f51", + "description": "Enables automatic writing direction detection for languages that read right-to-left.", + "tags": ["rtl", "language-support"], "authors": [ + { + "name": "dragonwocky", + "homepage": "https://dragonwocky.me/", + "avatar": "https://dragonwocky.me/avatar.jpg" + }, { "name": "obahareth", - "email": "omar@omar.engineer", "homepage": "https://omar.engineer", "avatar": "https://avatars.githubusercontent.com/u/3428118" } ], - "js": { - "client": ["client.mjs"] - }, - "css": { - "client": ["client.css"] - }, - "options": [] + "clientStyles": ["client.css"], + "clientScripts": ["client.mjs"] } diff --git a/src/extensions/right-to-left/right-to-left.jpg b/src/extensions/right-to-left/right-to-left.jpg deleted file mode 100644 index 38956ed3de2b8b63cab1c37cdbc9b30631b2e254..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13795 zcmd6N1y~(fw(b!QE(dpa4esvl?!ny&?g{P?Gz1Oq!9xfT0>LeKAh^2(2=?f{Gu?gP z%)67GJ9FP%wZGcC*8bPOrOsEYR;}|e`>+gv%1g^h1Assv!1VC|JS+et0ALX4m+~ku zj|Bn`fxy5(5aHlp;gJ!Mk&zIQkWf%DpeU&5s7Odq94I;_7B)6EG8!%(4i+8;7BpSB4fw|Tx-5uqp>tTcHRI;BW z0RY^O0mShwKMNDiEzvCiTh&X3jm7El9{xiCz0d9S;!s;S56SAc z^Lv^#uVw0`pG-ACde*MFu~xo#4I}@g{hx!uZbg3`W%2DuwXbpb zTob~_JNC2o+;`an5g&XG!;QAylqLRdMNg6ZHzj3`7vp!O;PciSE3VUi75^QMMRTmJ zJ)-2~zqL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