Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- color: v4.0.0 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/color/CHANGELOG.md))
- core: v8.1.6 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/core/CHANGELOG.md))
- highlight-code: v2.6.0 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/highlight-code/CHANGELOG.md))
- inline-editor: v4.0.0 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/inline-editor/CHANGELOG.md))
- inline-editor: v4.0.2 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/inline-editor/CHANGELOG.md))
- markdown: v2.0.2 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/markdown/CHANGELOG.md))

### Others
Expand Down
8 changes: 7 additions & 1 deletion webcomponents/inline-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# 4.0.0 (2021-05-09)
# 4.0.2 (2021-05-09)

### Fix

- do not loose range selection focus on color input

# 4.0.1 (2021-05-09)

### Features

Expand Down
2 changes: 1 addition & 1 deletion webcomponents/inline-editor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webcomponents/inline-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deckdeckgo/inline-editor",
"version": "4.0.1",
"version": "4.0.2",
"description": "A WYSIWYG HTML Inline Editor Web Component",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {DeckdeckgoPalette} from '@deckdeckgo/color';

import {hexToRgb} from '@deckdeckgo/utils';

import {clearTheSelection, getSelection} from '../../../utils/selection.utils';
import {getSelection} from '../../../utils/selection.utils';
import {findStyleNode, getAnchorNode} from '../../../utils/node.utils';

import {ExecCommandAction} from '../../../interfaces/interfaces';
Expand Down Expand Up @@ -33,12 +33,17 @@ export class ColorActions {
@Event()
private execCommand: EventEmitter<ExecCommandAction>;

private range: Range | undefined;

async componentWillLoad() {
await this.initColor();
}

private async initColor() {
const selection: Selection | undefined = await getSelection();

this.range = selection?.getRangeAt(0);

const container: HTMLElement | undefined = getAnchorNode(selection);

if (!container) {
Expand Down Expand Up @@ -67,21 +72,19 @@ export class ColorActions {
return;
}

if (selection.rangeCount <= 0 || !document) {
return;
}
selection?.removeAllRanges();
selection?.addRange(this.range);

const range: Range | undefined = selection.getRangeAt(0);
const observer: MutationObserver = new MutationObserver( (_mutations: MutationRecord[]) => {
observer.disconnect();

const text: string = range?.toString();

if (!text || text.length <= 0) {
return;
}
// No node were added so the style was modified
this.range = selection?.getRangeAt(0);
});

await clearTheSelection();
const anchorNode: HTMLElement | undefined = getAnchorNode(selection);

selection?.addRange(range);
observer.observe(anchorNode, {childList: true});

this.execCommand.emit({
cmd: 'style',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ export class DeckdeckgoInlineEditor {
}

private async handleSelectionChange(_$event: UIEvent) {
if (this.toolbarActions === ToolbarActions.COLOR || this.toolbarActions === ToolbarActions.BACKGROUND_COLOR) {
return;
}

if (document && document.activeElement && !this.isContainer(document.activeElement)) {
if (document.activeElement.nodeName.toLowerCase() !== 'deckgo-inline-editor') {
await this.reset(false);
Expand Down Expand Up @@ -831,15 +835,15 @@ export class DeckdeckgoInlineEditor {
}

private onAttributesChangesInitStyle() {
const anchoreNode: HTMLElement | undefined = getAnchorNode(this.selection);
const anchorNode: HTMLElement | undefined = getAnchorNode(this.selection);

const observer: MutationObserver = new MutationObserver(async () => {
observer.disconnect();

await this.initStyleForNode(anchoreNode);
await this.initStyleForNode(anchorNode);
});

observer.observe(anchoreNode, {attributes: true});
observer.observe(anchorNode, {attributes: true});
}

render() {
Expand Down