diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fbaf1b95..5b3af79e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 2.24.2 + +- `Fix` — Scrolling issue when opening toolbox on mobile fixed +- `Fix` — Typo in toolbox empty placeholder fixed +- `Improvement` — *Dev Example Page* - Add popup example page + ### 2.24.1 — `Fix` — The I18n of Tools` titles at the Toolbox now works correctly [#2030](https://github.com/codex-team/editor.js/issues/2030) diff --git a/example/assets/demo.css b/example/assets/demo.css index cffebcd9..f1141266 100644 --- a/example/assets/demo.css +++ b/example/assets/demo.css @@ -270,6 +270,56 @@ body { padding: 30px; } + +/** + * Styles for the popup example page + */ +.ce-example--popup { + height: 100vh; + display: flex; + flex-direction: column; +} + +.ce-example--popup .ce-example__content { + flex-grow: 2; +} + +.ce-example-popup__overlay { + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + background: #00000085; +} + +.ce-example-popup__popup { + position: absolute; + left: 50%; + top: 50%; + transform: translate(-50%,-50%); + width: 800px; + max-width: 100%; + max-height: 90vh; + background: white; + padding: 20px; + border-radius: 8px; + overflow: auto; + box-sizing: border-box; +} + +@media all and (max-width: 730px){ + .ce-example-popup__popup { + top: 10px; + left: 10px; + width: calc(100% - 20px); + height: calc(100% - 20px); + transform: none; + max-height: none; + + } +} + .show-block-boundaries .ce-block { box-shadow: inset 0 0 0 1px #eff2f5; } diff --git a/example/example-i18n.html b/example/example-i18n.html index 0496fbbc..c123bd7b 100644 --- a/example/example-i18n.html +++ b/example/example-i18n.html @@ -195,7 +195,7 @@ "toolbox": { "Add": "Добавить", "Filter": "Поиск", - "Noting found": "Ничего не найдено" + "Nothing found": "Ничего не найдено" } } }, diff --git a/example/example-popup.html b/example/example-popup.html new file mode 100644 index 00000000..2579d27b --- /dev/null +++ b/example/example-popup.html @@ -0,0 +1,131 @@ + + + + + + + Editor.js 🤩🧦🤨 example: Popup + + + + +
+
+ + + +
+
+
+ No core bundle file found. Run yarn build +
+
+

Base concepts

+

+ Editor.js is a block-style editor for rich media stories. It outputs clean data in JSON instead of heavy HTML markup. And more important thing is that Editor.js is designed to be API extendable and pluggable. +

+

+ So there are a few key features: +

+
    +
  • Clean data output
  • +
  • API pluggable
  • +
  • Open source
  • +
+

+ What does it mean block-styled +

+

+ In other editors, the workspace is provided by single contenteditable element in where you can create different HTML markup. All of us saw permanent bugs with moving text fragments or scaling images, while page parts are jumping and twitches. Or highlighting big parts of the text in the case when you just want to make few words to be a heading or bold. +

+

+ The Editor.js workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor's Core. +

+

+ At the same time, most useful features as arrow-navigation, copy & paste, cross block selection, and others works almost as in the familiar editors. +

+

+ What is clean data +

+

+ But the more interesting thing is, as mentioned above, that Editor.js returns clean data instead of HTML-markup. Take a look at the example. +

+

+ If our entry consists of few paragraphs and a heading, in popular Medium editor after saving we will have something like this: +

+

+ As you can see, there are only data we need: a list of structural Blocks with their content description. +

+

+ You can use this data to easily render in Web, native mobile/desktop application, pass to Audio Readers, create templates for Facebook Instant Articles, AMP, RSS, create chat-bots, and many others. +

+

+ Also, the clean data can be useful for backend processing: sanitizing, validation, injecting an advertising or other stuff, extracting Headings, make covers for social networks from Image Blocks, and other. +

+

+ API pluggable? +

+

+ A key value of the Editor is the API. All main functional units of the editor — Blocks, Inline Formatting Tools, Block Tunes — are provided by external plugins that use Editor's API. +

+

+ We decide to extract all these Tools to separate scripts to make Editor's Core more abstract and make API more powerful. Any challenges and tasks you are facing can be implemented by your own plugins using the API. +

+

+ At the same time, API is created to be easy-to-understand and simple-to-use. +

+

+ Open Source, so? +

+

+ Editor.js is more than just an editor. It is a big open-source community of developers and contributors. Anyone can suggest an improvement or a bug fix. Anyone can create new cool API features and plugins. +

+

+ We will support each developer of Editor.js plugins: the best solutions will be collected to the Awesome List and promoted to the community. Together we can create a big suite of different Blocks, Inline Tools, Block Tunes that can hit a wide specter of tasks. +

+

+ Thanks for your interest. Hope you enjoy Editor.js. +

+
+
+
+
+
+
+
+
+
+ +
+
+ + + + + + + + + diff --git a/src/components/i18n/locales/en/messages.json b/src/components/i18n/locales/en/messages.json index 42a1520b..d44df52c 100644 --- a/src/components/i18n/locales/en/messages.json +++ b/src/components/i18n/locales/en/messages.json @@ -15,7 +15,7 @@ "toolbox": { "Add": "", "Filter": "", - "Noting found": "" + "Nothing found": "" } } }, diff --git a/src/components/modules/toolbar/index.ts b/src/components/modules/toolbar/index.ts index df48ad3d..9f5a1db2 100644 --- a/src/components/modules/toolbar/index.ts +++ b/src/components/modules/toolbar/index.ts @@ -409,7 +409,7 @@ export default class Toolbar extends Module { tools: this.Editor.Tools.blockTools, i18nLabels: { filter: I18n.ui(I18nInternalNS.ui.toolbar.toolbox, 'Filter'), - nothingFound: I18n.ui(I18nInternalNS.ui.toolbar.toolbox, 'Noting found'), + nothingFound: I18n.ui(I18nInternalNS.ui.toolbar.toolbox, 'Nothing found'), }, }); diff --git a/src/components/utils.ts b/src/components/utils.ts index ab824308..2f1650bf 100644 --- a/src/components/utils.ts +++ b/src/components/utils.ts @@ -769,3 +769,13 @@ export function cacheable 1)); \ No newline at end of file diff --git a/src/components/utils/popover.ts b/src/components/utils/popover.ts index 2afc2897..1f084324 100644 --- a/src/components/utils/popover.ts +++ b/src/components/utils/popover.ts @@ -4,6 +4,7 @@ import Flipper from '../flipper'; import SearchInput from './search-input'; import EventsDispatcher from './events'; import { isMobileScreen, keyCodes, cacheable } from '../utils'; +import ScrollLocker from './scroll-locker'; /** * Describe parameters for rendering the single item of Popover @@ -126,7 +127,6 @@ export default class Popover extends EventsDispatcher { noFoundMessageShown: string; popoverOverlay: string; popoverOverlayHidden: string; - documentScrollLocked: string; } { return { popover: 'ce-popover', @@ -142,10 +142,14 @@ export default class Popover extends EventsDispatcher { noFoundMessageShown: 'ce-popover__no-found--shown', popoverOverlay: 'ce-popover__overlay', popoverOverlayHidden: 'ce-popover__overlay--hidden', - documentScrollLocked: 'ce-scroll-locked', }; } + /** + * ScrollLocker instance + */ + private scrollLocker = new ScrollLocker() + /** * Creates the Popover * @@ -197,7 +201,7 @@ export default class Popover extends EventsDispatcher { } if (isMobileScreen()) { - document.documentElement.classList.add(Popover.CSS.documentScrollLocked); + this.scrollLocker.lock(); } } @@ -211,7 +215,7 @@ export default class Popover extends EventsDispatcher { this.flipper.deactivate(); if (isMobileScreen()) { - document.documentElement.classList.remove(Popover.CSS.documentScrollLocked); + this.scrollLocker.unlock(); } } diff --git a/src/components/utils/scroll-locker.ts b/src/components/utils/scroll-locker.ts new file mode 100644 index 00000000..394ddcec --- /dev/null +++ b/src/components/utils/scroll-locker.ts @@ -0,0 +1,64 @@ +import { isIosDevice } from '../utils'; + +/** + * Utility allowing to lock body scroll on demand + */ +export default class ScrollLocker { + /** + * Style classes + */ + private static CSS = { + scrollLocked: 'ce-scroll-locked', + scrollLockedHard: 'ce-scroll-locked--hard', + } + + /** + * Stores scroll position, used for hard scroll lock + */ + private scrollPosition: null|number + + /** + * Locks body element scroll + */ + public lock(): void { + if (isIosDevice) { + this.lockHard(); + } else { + document.body.classList.add(ScrollLocker.CSS.scrollLocked); + } + } + + /** + * Unlocks body element scroll + */ + public unlock(): void { + if (isIosDevice) { + this.unlockHard(); + } else { + document.body.classList.remove(ScrollLocker.CSS.scrollLocked); + } + } + + /** + * Locks scroll in a hard way (via setting fixed position to body element) + */ + private lockHard(): void { + this.scrollPosition = window.pageYOffset; + document.documentElement.style.setProperty( + '--window-scroll-offset', + `${this.scrollPosition}px` + ); + document.body.classList.add(ScrollLocker.CSS.scrollLockedHard); + } + + /** + * Unlocks hard scroll lock + */ + private unlockHard(): void { + document.body.classList.remove(ScrollLocker.CSS.scrollLockedHard); + if (this.scrollPosition !== null) { + window.scrollTo(0, this.scrollPosition); + } + this.scrollPosition = null; + } +} diff --git a/src/styles/ui.css b/src/styles/ui.css index da65fc37..e594e071 100644 --- a/src/styles/ui.css +++ b/src/styles/ui.css @@ -128,11 +128,13 @@ } } -.ce-scroll-locked, .ce-scroll-locked > body { - height: 100vh; +.ce-scroll-locked { overflow: hidden; - /** - * Mobile Safari fix - */ - position: relative; +} + +.ce-scroll-locked--hard { + overflow: hidden; + top: calc(-1 * var(--window-scroll-offset)); + position: fixed; + width: 100%; } \ No newline at end of file