]> BookStack Code Mirror - bookstack/commitdiff
Lexical: Split helpers to utils, refactored files
authorDan Brown <redacted>
Sat, 3 Aug 2024 17:14:01 +0000 (18:14 +0100)
committerDan Brown <redacted>
Sat, 3 Aug 2024 17:14:01 +0000 (18:14 +0100)
39 files changed:
resources/js/wysiwyg/index.ts
resources/js/wysiwyg/nodes/code-block.ts
resources/js/wysiwyg/nodes/custom-list-item.ts
resources/js/wysiwyg/nodes/custom-table.ts
resources/js/wysiwyg/nodes/details.ts
resources/js/wysiwyg/nodes/diagram.ts
resources/js/wysiwyg/nodes/image.ts
resources/js/wysiwyg/nodes/media.ts
resources/js/wysiwyg/services/common-events.ts [moved from resources/js/wysiwyg/common-events.ts with 97% similarity]
resources/js/wysiwyg/services/drop-handling.ts [moved from resources/js/wysiwyg/drop-handling.ts with 93% similarity]
resources/js/wysiwyg/ui/decorators/code-block.ts
resources/js/wysiwyg/ui/decorators/diagram.ts
resources/js/wysiwyg/ui/decorators/image.ts
resources/js/wysiwyg/ui/defaults/buttons/alignments.ts
resources/js/wysiwyg/ui/defaults/buttons/block-formats.ts
resources/js/wysiwyg/ui/defaults/buttons/controls.ts
resources/js/wysiwyg/ui/defaults/buttons/inline-formats.ts
resources/js/wysiwyg/ui/defaults/buttons/lists.ts
resources/js/wysiwyg/ui/defaults/buttons/objects.ts
resources/js/wysiwyg/ui/defaults/buttons/tables.ts
resources/js/wysiwyg/ui/defaults/forms/controls.ts
resources/js/wysiwyg/ui/defaults/forms/objects.ts
resources/js/wysiwyg/ui/framework/blocks/color-picker.ts
resources/js/wysiwyg/ui/framework/blocks/dropdown-button.ts
resources/js/wysiwyg/ui/framework/blocks/format-menu.ts
resources/js/wysiwyg/ui/framework/blocks/format-preview-button.ts
resources/js/wysiwyg/ui/framework/blocks/overflow-container.ts
resources/js/wysiwyg/ui/framework/blocks/table-creator.ts
resources/js/wysiwyg/ui/framework/buttons.ts
resources/js/wysiwyg/ui/framework/core.ts
resources/js/wysiwyg/ui/framework/forms.ts
resources/js/wysiwyg/ui/framework/helpers/table-resizer.ts
resources/js/wysiwyg/ui/framework/modals.ts
resources/js/wysiwyg/ui/framework/toolbars.ts
resources/js/wysiwyg/ui/toolbars.ts
resources/js/wysiwyg/utils/actions.ts [moved from resources/js/wysiwyg/actions.ts with 97% similarity]
resources/js/wysiwyg/utils/dom.ts [new file with mode: 0644]
resources/js/wysiwyg/utils/nodes.ts [new file with mode: 0644]
resources/js/wysiwyg/utils/selection.ts [moved from resources/js/wysiwyg/helpers.ts with 53% similarity]

index 71a007f590ea6ff5c371e147cd27438afe8ace31..9da646a771aae72e3b3ef6b43d1b2b785c8d9569 100644 (file)
@@ -4,14 +4,14 @@ import {registerRichText} from '@lexical/rich-text';
 import {mergeRegister} from '@lexical/utils';
 import {getNodesForPageEditor, registerCommonNodeMutationListeners} from './nodes';
 import {buildEditorUI} from "./ui";
-import {getEditorContentAsHtml, setEditorContentFromHtml} from "./actions";
+import {getEditorContentAsHtml, setEditorContentFromHtml} from "./utils/actions";
 import {registerTableResizer} from "./ui/framework/helpers/table-resizer";
-import {el} from "./helpers";
 import {EditorUiContext} from "./ui/framework/core";
-import {listen as listenToCommonEvents} from "./common-events";
-import {handleDropEvents} from "./drop-handling";
+import {listen as listenToCommonEvents} from "./services/common-events";
+import {handleDropEvents} from "./services/drop-handling";
 import {registerTaskListHandler} from "./ui/framework/helpers/task-list-handler";
 import {registerTableSelectionHandler} from "./ui/framework/helpers/table-selection-handler";
+import {el} from "./utils/dom";
 
 export function createPageEditorInstance(container: HTMLElement, htmlContent: string, options: Record<string, any> = {}): SimpleWysiwygEditorInterface {
     const config: CreateEditorArgs = {
index 2478ba24900d0447eabe7b4ee9495d894bb1a383..e240a38870a16670ae5947c304be949d0b81a72b 100644 (file)
@@ -8,9 +8,9 @@ import {
     Spread
 } from "lexical";
 import type {EditorConfig} from "lexical/LexicalEditor";
-import {el} from "../helpers";
 import {EditorDecoratorAdapter} from "../ui/framework/decorator";
 import {CodeEditor} from "../../components";
+import {el} from "../utils/dom";
 
 export type SerializedCodeBlockNode = Spread<{
     language: string;
index 21b9f6d5f932b004e0d7b4f198e467cd3be3c418..2b4d7414632a8402ffdc58f318c59e8c23eb0a85 100644 (file)
@@ -1,7 +1,8 @@
 import {$isListNode, ListItemNode, SerializedListItemNode} from "@lexical/list";
 import {EditorConfig} from "lexical/LexicalEditor";
 import {DOMExportOutput, LexicalEditor, LexicalNode} from "lexical";
-import {el} from "../helpers";
+
+import {el} from "../utils/dom";
 
 function updateListItemChecked(
     dom: HTMLElement,
index 7dda24a7a30da71c0008f1d378257791798e4a1a..32f3ec4fa571a851d5ab047581bdd745e39d7c77 100644 (file)
@@ -1,7 +1,8 @@
 import {SerializedTableNode, TableNode, TableRowNode} from "@lexical/table";
 import {DOMConversion, DOMConversionMap, DOMConversionOutput, LexicalEditor, LexicalNode, Spread} from "lexical";
 import {EditorConfig} from "lexical/LexicalEditor";
-import {el} from "../helpers";
+
+import {el} from "../utils/dom";
 
 export type SerializedCustomTableNode = Spread<{
     id: string;
index a18c4d858d50bad053733e1819e8d04b35746743..8071d5e8fd98017368fba2c0ef97cdc42bec87cd 100644 (file)
@@ -7,7 +7,8 @@ import {
     SerializedElementNode,
 } from 'lexical';
 import type {EditorConfig} from "lexical/LexicalEditor";
-import {el} from "../helpers";
+
+import {el} from "../utils/dom";
 
 export class DetailsNode extends ElementNode {
 
index 1aff06400374ec45375d9da55371a8bc1cdc9194..76d9392480fc1560576afaac3baa565b33f084b8 100644 (file)
@@ -8,11 +8,11 @@ import {
     Spread
 } from "lexical";
 import type {EditorConfig} from "lexical/LexicalEditor";
-import {el} from "../helpers";
 import {EditorDecoratorAdapter} from "../ui/framework/decorator";
 import * as DrawIO from '../../services/drawio';
 import {EditorUiContext} from "../ui/framework/core";
 import {HttpError} from "../../services/http";
+import {el} from "../utils/dom";
 
 export type SerializedDiagramNode = Spread<{
     id: string;
index 92d5518dbc7ccacf814762e3f9fc4ac947d8620e..ef6bf35724a6f98e827febfdedd38a2ec3cb99ba 100644 (file)
@@ -8,8 +8,8 @@ import {
     Spread
 } from "lexical";
 import type {EditorConfig} from "lexical/LexicalEditor";
-import {el} from "../helpers";
 import {EditorDecoratorAdapter} from "../ui/framework/decorator";
+import {el} from "../utils/dom";
 
 export interface ImageNodeOptions {
     alt?: string;
index 751f420fa504f71a66893927b6b0870aa184ae78..aba4f6c37b46b5b53cc176a5524852271f3d65d3 100644 (file)
@@ -7,7 +7,8 @@ import {
     SerializedElementNode, Spread
 } from 'lexical';
 import type {EditorConfig} from "lexical/LexicalEditor";
-import {el} from "../helpers";
+
+import {el} from "../utils/dom";
 
 export type MediaNodeTag = 'iframe' | 'embed' | 'object' | 'video' | 'audio';
 export type MediaNodeSource = {
similarity index 97%
rename from resources/js/wysiwyg/common-events.ts
rename to resources/js/wysiwyg/services/common-events.ts
index 7355d977ba61ab7534ec0b8e579575ac22510452..16522d66b713ad0e475d7c90cb67a4e76f1ce243 100644 (file)
@@ -5,7 +5,7 @@ import {
     insertHtmlIntoEditor,
     prependHtmlToEditor,
     setEditorContentFromHtml
-} from "./actions";
+} from "../utils/actions";
 
 type EditorEventContent = {
     html: string;
similarity index 93%
rename from resources/js/wysiwyg/drop-handling.ts
rename to resources/js/wysiwyg/services/drop-handling.ts
index 5d541365ab5fbcdcb1ab2ae41cf3fdd2d466818a..7c9bb2713bab3e5879bb9f224f8db4658570145f 100644 (file)
@@ -3,12 +3,8 @@ import {
     LexicalEditor,
     LexicalNode
 } from "lexical";
-import {
-    $getNearestBlockNodeForCoords,
-    $htmlToBlockNodes,
-    $insertNewBlockNodesAtSelection,
-    $selectSingleNode
-} from "./helpers";
+import {$insertNewBlockNodesAtSelection, $selectSingleNode} from "../utils/selection";
+import {$getNearestBlockNodeForCoords, $htmlToBlockNodes} from "../utils/nodes";
 
 function $getNodeFromMouseEvent(event: MouseEvent, editor: LexicalEditor): LexicalNode|null {
     const x = event.clientX;
index d6947ea756dffefef2f8c2c4458dbb99e9073ee8..650bd64c550435fb5ea6374e9a17d2dbea36c6de 100644 (file)
@@ -1,8 +1,8 @@
 import {EditorDecorator} from "../framework/decorator";
 import {EditorUiContext} from "../framework/core";
 import {$openCodeEditorForNode, CodeBlockNode} from "../../nodes/code-block";
-import {$selectionContainsNode, $selectSingleNode} from "../../helpers";
 import {BaseSelection} from "lexical";
+import {$selectionContainsNode, $selectSingleNode} from "../../utils/selection";
 
 
 export class CodeBlockDecorator extends EditorDecorator {
index 0f1263f38f408a223df3a41e99a1cc2f9cf13788..7c79f9f41d8cb39d12dce9ab67727392d8cf809f 100644 (file)
@@ -1,8 +1,8 @@
 import {EditorDecorator} from "../framework/decorator";
 import {EditorUiContext} from "../framework/core";
-import {$selectionContainsNode, $selectSingleNode} from "../../helpers";
 import {BaseSelection} from "lexical";
 import {$openDrawingEditorForNode, DiagramNode} from "../../nodes/diagram";
+import {$selectionContainsNode, $selectSingleNode} from "../../utils/selection";
 
 
 export class DiagramDecorator extends EditorDecorator {
index 2046260a02352f41c214c5d150bf20a30dd62363..d110bc4993057293b38d0197829afa01932f64b2 100644 (file)
@@ -1,9 +1,10 @@
 import {EditorDecorator} from "../framework/decorator";
-import {el, $selectSingleNode} from "../../helpers";
 import {$createNodeSelection, $setSelection} from "lexical";
 import {EditorUiContext} from "../framework/core";
 import {ImageNode} from "../../nodes/image";
 import {MouseDragTracker, MouseDragTrackerDistance} from "../framework/helpers/mouse-drag-tracker";
+import {$selectSingleNode} from "../../utils/selection";
+import {el} from "../../utils/dom";
 
 
 export class ImageDecorator extends EditorDecorator {
index 2b441e5da87f31dd2155d05c09ce84a51cb60b8b..40d9c89dce8c95cbdd3ba5b8c2e92201ddf473aa 100644 (file)
@@ -1,11 +1,11 @@
 import {$getSelection, BaseSelection, ElementFormatType} from "lexical";
-import {$getBlockElementNodesInSelection, $selectionContainsElementFormat} from "../../../helpers";
 import {EditorButtonDefinition} from "../../framework/buttons";
 import alignLeftIcon from "@icons/editor/align-left.svg";
 import {EditorUiContext} from "../../framework/core";
 import alignCenterIcon from "@icons/editor/align-center.svg";
 import alignRightIcon from "@icons/editor/align-right.svg";
 import alignJustifyIcon from "@icons/editor/align-justify.svg";
+import {$getBlockElementNodesInSelection, $selectionContainsElementFormat} from "../../../utils/selection";
 
 
 function setAlignmentForSection(alignment: ElementFormatType): void {
index 0eb07ecf1f000968a47273dae650977bae6461a4..eba903263b3c51c951be66c3373eba48263c1d71 100644 (file)
@@ -1,7 +1,6 @@
 import {$createCalloutNode, $isCalloutNodeOfCategory, CalloutCategory} from "../../../nodes/callout";
 import {EditorButtonDefinition} from "../../framework/buttons";
 import {EditorUiContext} from "../../framework/core";
-import {$selectionContainsNodeType, $toggleSelectionBlockNodeType} from "../../../helpers";
 import {$createParagraphNode, $isParagraphNode, BaseSelection, LexicalNode} from "lexical";
 import {
     $createHeadingNode,
@@ -11,6 +10,7 @@ import {
     HeadingNode,
     HeadingTagType
 } from "@lexical/rich-text";
+import {$selectionContainsNodeType, $toggleSelectionBlockNodeType} from "../../../utils/selection";
 
 function buildCalloutButton(category: CalloutCategory, name: string): EditorButtonDefinition {
     return {
index ad69d69d13c43fb90d07ca941003a7fd868e0a2f..2a2fecc40c41c216bfb68b65d5cc30c84844b453 100644 (file)
@@ -11,7 +11,7 @@ import {
 } from "lexical";
 import redoIcon from "@icons/editor/redo.svg";
 import sourceIcon from "@icons/editor/source-view.svg";
-import {getEditorContentAsHtml} from "../../../actions";
+import {getEditorContentAsHtml} from "../../../utils/actions";
 import fullscreenIcon from "@icons/editor/fullscreen.svg";
 
 export const undo: EditorButtonDefinition = {
index d04f72a2e571da85e81b079bf0ec31f97ed10d5d..a967ecb2fc026eb32afe0bdcff87587003f0c97a 100644 (file)
@@ -1,7 +1,6 @@
 import {$getSelection, $isTextNode, BaseSelection, FORMAT_TEXT_COMMAND, TextFormatType} from "lexical";
 import {EditorBasicButtonDefinition, EditorButtonDefinition} from "../../framework/buttons";
 import {EditorUiContext} from "../../framework/core";
-import {$selectionContainsTextFormat} from "../../../helpers";
 import boldIcon from "@icons/editor/bold.svg";
 import italicIcon from "@icons/editor/italic.svg";
 import underlinedIcon from "@icons/editor/underlined.svg";
@@ -12,6 +11,7 @@ import superscriptIcon from "@icons/editor/superscript.svg";
 import subscriptIcon from "@icons/editor/subscript.svg";
 import codeIcon from "@icons/editor/code.svg";
 import formatClearIcon from "@icons/editor/format-clear.svg";
+import {$selectionContainsTextFormat} from "../../../utils/selection";
 
 function buildFormatButton(label: string, format: TextFormatType, icon: string): EditorButtonDefinition {
     return {
index ecda290a12cf7998bd1f1370851c34e748ce3acb..10500eb671875c7611a6aa200d334a0193591aa6 100644 (file)
@@ -2,10 +2,10 @@ import {$isListNode, insertList, ListNode, ListType, removeList} from "@lexical/
 import {EditorButtonDefinition} from "../../framework/buttons";
 import {EditorUiContext} from "../../framework/core";
 import {$getSelection, BaseSelection, LexicalNode} from "lexical";
-import {$selectionContainsNodeType} from "../../../helpers";
 import listBulletIcon from "@icons/editor/list-bullet.svg";
 import listNumberedIcon from "@icons/editor/list-numbered.svg";
 import listCheckIcon from "@icons/editor/list-check.svg";
+import {$selectionContainsNodeType} from "../../../utils/selection";
 
 
 function buildListButton(label: string, type: ListType, icon: string): EditorButtonDefinition {
index 3c14052baa43518eb42a97484b0e4fa51ecaec78..0eac497fce8de43d24c0f226a484ffa4c7848f8a 100644 (file)
@@ -10,7 +10,6 @@ import {
     BaseSelection,
     ElementNode
 } from "lexical";
-import {$getNodeFromSelection, $insertNewBlockNodeAtSelection, $selectionContainsNodeType} from "../../../helpers";
 import {$isLinkNode, LinkNode} from "@lexical/link";
 import unlinkIcon from "@icons/editor/unlink.svg";
 import imageIcon from "@icons/editor/image.svg";
@@ -26,6 +25,11 @@ import detailsIcon from "@icons/editor/details.svg";
 import mediaIcon from "@icons/editor/media.svg";
 import {$createDetailsNode, $isDetailsNode} from "../../../nodes/details";
 import {$isMediaNode, MediaNode} from "../../../nodes/media";
+import {
+    $getNodeFromSelection,
+    $insertNewBlockNodeAtSelection,
+    $selectionContainsNodeType
+} from "../../../utils/selection";
 
 export const link: EditorButtonDefinition = {
     label: 'Insert/edit link',
index b0f0bf346a999b2348044e2fbdb3e4a83bfced79..2cc2e701b69ad5dbb8c7e3ee3783ec37fcfe14af 100644 (file)
@@ -8,10 +8,6 @@ import insertColumnBeforeIcon from "@icons/editor/table-insert-column-before.svg
 import insertRowAboveIcon from "@icons/editor/table-insert-row-above.svg";
 import insertRowBelowIcon from "@icons/editor/table-insert-row-below.svg";
 import {EditorUiContext} from "../../framework/core";
-import {
-    $getNodeFromSelection, $getParentOfType,
-    $selectionContainsNodeType
-} from "../../../helpers";
 import {$getSelection, BaseSelection} from "lexical";
 import {$isCustomTableNode} from "../../../nodes/custom-table";
 import {
@@ -22,6 +18,8 @@ import {
     $insertTableRow__EXPERIMENTAL, $isTableCellNode,
     $isTableNode, $isTableRowNode, $isTableSelection, $unmergeCell, TableCellNode, TableNode,
 } from "@lexical/table";
+import {$getNodeFromSelection, $selectionContainsNodeType} from "../../../utils/selection";
+import {$getParentOfType} from "../../../utils/nodes";
 
 const neverActive = (): boolean => false;
 const cellNotSelected = (selection: BaseSelection|null) => !$selectionContainsNodeType(selection, $isTableCellNode);
index bcb2f5bad6eb09916f1bd818884fe3975d182af0..fc461f6626f9407e3faaefc260540f4875239cb7 100644 (file)
@@ -1,6 +1,6 @@
 import {EditorFormDefinition} from "../../framework/forms";
 import {EditorUiContext} from "../../framework/core";
-import {setEditorContentFromHtml} from "../../../actions";
+import {setEditorContentFromHtml} from "../../../utils/actions";
 
 export const source: EditorFormDefinition = {
     submitText: 'Save',
index 7a388751bc420733df52ecfce6605fb178ea139a..dbb89b18f9daa0639d7fee098e50c8de1da0a305 100644 (file)
@@ -4,8 +4,8 @@ import {$createTextNode, $getSelection} from "lexical";
 import {$createImageNode} from "../../../nodes/image";
 import {$createLinkNode} from "@lexical/link";
 import {$createMediaNodeFromHtml, $createMediaNodeFromSrc, $isMediaNode, MediaNode} from "../../../nodes/media";
-import {$getNodeFromSelection} from "../../../helpers";
 import {$insertNodeToNearestRoot} from "@lexical/utils";
+import {$getNodeFromSelection} from "../../../utils/selection";
 
 export const image: EditorFormDefinition = {
     submitText: 'Apply',
index 6972d7a8e44be581b169c84e5fc68c662fcfd2e6..48e313f5cca213e49309f3c0d9bace0771a2941f 100644 (file)
@@ -1,7 +1,7 @@
-import {el} from "../../../helpers";
 import {EditorUiElement} from "../core";
 import {$getSelection} from "lexical";
 import {$patchStyleText} from "@lexical/selection";
+import {el} from "../../../utils/dom";
 
 const colorChoices = [
     '#000000',
index da0d3e5d0cf1fc63546580eac64b7d25fae0e259..a7905a6dde2ab0899d54c30110c4cae88ca40542 100644 (file)
@@ -1,7 +1,7 @@
-import {el} from "../../../helpers";
 import {handleDropdown} from "../helpers/dropdowns";
 import {EditorContainerUiElement, EditorUiElement} from "../core";
 import {EditorBasicButtonDefinition, EditorButton} from "../buttons";
+import {el} from "../../../utils/dom";
 
 export type EditorDropdownButtonOptions = {
     showOnHover?: boolean;
index b0834fe4d48777ecc9f2584ac1111d775d3c54f7..d666954bf057aab72192f87d0e0b427bc7cbf1b3 100644 (file)
@@ -1,7 +1,7 @@
-import {el} from "../../../helpers";
 import {EditorUiStateUpdate, EditorContainerUiElement} from "../core";
 import {EditorButton} from "../buttons";
 import {handleDropdown} from "../helpers/dropdowns";
+import {el} from "../../../utils/dom";
 
 export class EditorFormatMenu extends EditorContainerUiElement {
     buildDOM(): HTMLElement {
index f83035aa6bda26c86ee0cbb2dcc0e6ed299488dc..2371983dd5f10149661acf57baa0840a6504bfb7 100644 (file)
@@ -1,5 +1,5 @@
-import {el} from "../../../helpers";
 import {EditorButton, EditorButtonDefinition} from "../buttons";
+import {el} from "../../../utils/dom";
 
 export class FormatPreviewButton extends EditorButton {
     protected previewSampleElement: HTMLElement;
index 108992db889cd4fbf290e668ddff7535f93f5931..cd07805341554419e7f983224281d98e5e869449 100644 (file)
@@ -1,7 +1,7 @@
 import {EditorContainerUiElement, EditorUiElement} from "../core";
-import {el} from "../../../helpers";
 import {EditorDropdownButton} from "./dropdown-button";
 import moreHorizontal from "@icons/editor/more-horizontal.svg"
+import {el} from "../../../utils/dom";
 
 
 export class EditorOverflowContainer extends EditorContainerUiElement {
index 1981fcb8624029085e86f14b26f67db322af02bb..a8a142df5a14438f616c3848a7230164c8337e51 100644 (file)
@@ -1,7 +1,8 @@
-import {el, $insertNewBlockNodeAtSelection} from "../../../helpers";
 import {EditorUiElement} from "../core";
 import {$createTableNodeWithDimensions} from "@lexical/table";
 import {CustomTableNode} from "../../../nodes/custom-table";
+import {$insertNewBlockNodeAtSelection} from "../../../utils/selection";
+import {el} from "../../../utils/dom";
 
 
 export class EditorTableCreator extends EditorUiElement {
index 9a23edfb7f68108b66508c273eefc3a041b5df58..cf114aa021256c9e075591a06331500c88162580 100644 (file)
@@ -1,6 +1,7 @@
 import {BaseSelection} from "lexical";
 import {EditorUiContext, EditorUiElement, EditorUiStateUpdate} from "./core";
-import {el} from "../../helpers";
+
+import {el} from "../../utils/dom";
 
 export interface EditorBasicButtonDefinition {
     label: string;
index f644bc37a700f58280c5ef88ecdfcd53a035fcc7..3e9f1e3d935d6b4b5eff1e98b88fee97d0e05c83 100644 (file)
@@ -1,6 +1,7 @@
 import {BaseSelection, LexicalEditor} from "lexical";
 import {EditorUIManager} from "./manager";
-import {el} from "../../helpers";
+
+import {el} from "../../utils/dom";
 
 export type EditorUiStateUpdate = {
     editor: LexicalEditor;
index b225a3de2c2a190145995c152b95b67acf004dc5..a2db34dd7a12ade9f94b6a5a4deedbb68e41e7b4 100644 (file)
@@ -5,8 +5,8 @@ import {
     EditorUiBuilderDefinition,
     isUiBuilderDefinition
 } from "./core";
-import {el} from "../../helpers";
 import {uniqueId} from "../../../services/util";
+import {el} from "../../utils/dom";
 
 export interface EditorFormFieldDefinition {
     label: string;
index 2d995883a5be46623a484e672ea0b888509efda0..f312294c59d45a7030524140b62b6f563bf22ee4 100644 (file)
@@ -1,8 +1,8 @@
 import {$getNearestNodeFromDOMNode, LexicalEditor} from "lexical";
-import {el} from "../../../helpers";
 import {MouseDragTracker, MouseDragTrackerDistance} from "./mouse-drag-tracker";
 import {$getTableColumnWidth, $setTableColumnWidth, CustomTableNode} from "../../../nodes/custom-table";
 import {TableRowNode} from "@lexical/table";
+import {el} from "../../../utils/dom";
 
 type MarkerDomRecord = {x: HTMLElement, y: HTMLElement};
 
index 6b09accdc8b930c2b00f7135d354dfc261ede34b..1768f6f545bf9c54e636fc6696c748ab89068375 100644 (file)
@@ -1,7 +1,7 @@
 import {EditorForm, EditorFormDefinition} from "./forms";
-import {el} from "../../helpers";
 import {EditorContainerUiElement} from "./core";
 import closeIcon from "@icons/close.svg";
+import {el} from "../../utils/dom";
 
 export interface EditorModalDefinition {
     title: string;
index d7c48193479266ae51d3739b8bca005afb407d34..b4e49af950c93342a216b90931b1f7af4aaaa861 100644 (file)
@@ -1,5 +1,6 @@
 import {EditorContainerUiElement, EditorUiElement} from "./core";
-import {el} from "../../helpers";
+
+import {el} from "../../utils/dom";
 
 export type EditorContextToolbarDefinition = {
     selector: string;
index 3346e0a0724ca78cfaf3fa73bde56838fdb8e288..48e11837c953445894deb1d9da08be6e0015d0db 100644 (file)
@@ -1,6 +1,5 @@
 import {EditorButton} from "./framework/buttons";
 import {EditorContainerUiElement, EditorSimpleClassContainer, EditorUiElement} from "./framework/core";
-import {$selectionContainsNodeType, el} from "../helpers";
 import {EditorFormatMenu} from "./framework/blocks/format-menu";
 import {FormatPreviewButton} from "./framework/blocks/format-preview-button";
 import {EditorDropdownButton} from "./framework/blocks/dropdown-button";
@@ -65,6 +64,8 @@ import {
     unlink
 } from "./defaults/buttons/objects";
 import {$isTableNode} from "@lexical/table";
+import {$selectionContainsNodeType} from "../utils/selection";
+import {el} from "../utils/dom";
 
 export function getMainEditorFullToolbar(): EditorContainerUiElement {
     return new EditorSimpleClassContainer('editor-toolbar-main', [
similarity index 97%
rename from resources/js/wysiwyg/actions.ts
rename to resources/js/wysiwyg/utils/actions.ts
index a3d2f0ef60347e7ed38867c4bb03d97fa40f9664..ae829bae3a3c7cfbbb28fc88138b58a87facbd8f 100644 (file)
@@ -1,8 +1,6 @@
 import {$getRoot, $getSelection, LexicalEditor} from "lexical";
 import {$generateHtmlFromNodes} from "@lexical/html";
-import {$htmlToBlockNodes} from "./helpers";
-
-
+import {$htmlToBlockNodes} from "./nodes";
 
 export function setEditorContentFromHtml(editor: LexicalEditor, html: string) {
     editor.update(() => {
diff --git a/resources/js/wysiwyg/utils/dom.ts b/resources/js/wysiwyg/utils/dom.ts
new file mode 100644 (file)
index 0000000..dc0872e
--- /dev/null
@@ -0,0 +1,24 @@
+export function el(tag: string, attrs: Record<string, string | null> = {}, children: (string | HTMLElement)[] = []): HTMLElement {
+    const el = document.createElement(tag);
+    const attrKeys = Object.keys(attrs);
+    for (const attr of attrKeys) {
+        if (attrs[attr] !== null) {
+            el.setAttribute(attr, attrs[attr] as string);
+        }
+    }
+
+    for (const child of children) {
+        if (typeof child === 'string') {
+            el.append(document.createTextNode(child));
+        } else {
+            el.append(child);
+        }
+    }
+
+    return el;
+}
+
+export function htmlToDom(html: string): Document {
+    const parser = new DOMParser();
+    return parser.parseFromString(html, 'text/html');
+}
\ No newline at end of file
diff --git a/resources/js/wysiwyg/utils/nodes.ts b/resources/js/wysiwyg/utils/nodes.ts
new file mode 100644 (file)
index 0000000..8e6c666
--- /dev/null
@@ -0,0 +1,53 @@
+import {$getRoot, $isTextNode, LexicalEditor, LexicalNode} from "lexical";
+import {LexicalNodeMatcher} from "../nodes";
+import {$createCustomParagraphNode} from "../nodes/custom-paragraph";
+import {$generateNodesFromDOM} from "@lexical/html";
+import {htmlToDom} from "./dom";
+
+function wrapTextNodes(nodes: LexicalNode[]): LexicalNode[] {
+    return nodes.map(node => {
+        if ($isTextNode(node)) {
+            const paragraph = $createCustomParagraphNode();
+            paragraph.append(node);
+            return paragraph;
+        }
+        return node;
+    });
+}
+
+export function $htmlToBlockNodes(editor: LexicalEditor, html: string): LexicalNode[] {
+    const dom = htmlToDom(html);
+    const nodes = $generateNodesFromDOM(editor, dom);
+    return wrapTextNodes(nodes);
+}
+
+export function $getParentOfType(node: LexicalNode, matcher: LexicalNodeMatcher): LexicalNode | null {
+    for (const parent of node.getParents()) {
+        if (matcher(parent)) {
+            return parent;
+        }
+    }
+
+    return null;
+}
+
+/**
+ * Get the nearest root/block level node for the given position.
+ */
+export function $getNearestBlockNodeForCoords(editor: LexicalEditor, x: number, y: number): LexicalNode | null {
+    // TODO - Take into account x for floated blocks?
+    const rootNodes = $getRoot().getChildren();
+    for (const node of rootNodes) {
+        const nodeDom = editor.getElementByKey(node.__key);
+        if (!nodeDom) {
+            continue;
+        }
+
+        const bounds = nodeDom.getBoundingClientRect();
+        if (y <= bounds.bottom) {
+            return node;
+        }
+    }
+
+    return null;
+}
\ No newline at end of file
similarity index 53%
rename from resources/js/wysiwyg/helpers.ts
rename to resources/js/wysiwyg/utils/selection.ts
index 07755f449e658d2f0f3d8730aae7141266b0de87..e34afbe36e86f89ac517f7a40307943d9c7f6b7e 100644 (file)
@@ -1,64 +1,28 @@
 import {
     $createNodeSelection,
-    $createParagraphNode, $getRoot,
-    $getSelection, $isElementNode,
-    $isTextNode, $setSelection,
-    BaseSelection, ElementFormatType, ElementNode, LexicalEditor,
-    LexicalNode, TextFormatType
+    $createParagraphNode,
+    $getRoot,
+    $getSelection,
+    $isElementNode,
+    $isTextNode,
+    $setSelection,
+    BaseSelection,
+    ElementFormatType,
+    ElementNode,
+    LexicalNode,
+    TextFormatType
 } from "lexical";
-import {LexicalElementNodeCreator, LexicalNodeMatcher} from "./nodes";
 import {$findMatchingParent, $getNearestBlockElementAncestorOrThrow} from "@lexical/utils";
+import {LexicalElementNodeCreator, LexicalNodeMatcher} from "../nodes";
 import {$setBlocksType} from "@lexical/selection";
-import {$createCustomParagraphNode} from "./nodes/custom-paragraph";
-import {$generateNodesFromDOM} from "@lexical/html";
-
-export function el(tag: string, attrs: Record<string, string|null> = {}, children: (string|HTMLElement)[] = []): HTMLElement {
-    const el = document.createElement(tag);
-    const attrKeys = Object.keys(attrs);
-    for (const attr of attrKeys) {
-        if (attrs[attr] !== null) {
-            el.setAttribute(attr, attrs[attr] as string);
-        }
-    }
-
-    for (const child of children) {
-        if (typeof child === 'string') {
-            el.append(document.createTextNode(child));
-        } else {
-            el.append(child);
-        }
-    }
 
-    return el;
-}
+import {$getParentOfType} from "./nodes";
 
-function htmlToDom(html: string): Document {
-    const parser = new DOMParser();
-    return parser.parseFromString(html, 'text/html');
-}
-
-function wrapTextNodes(nodes: LexicalNode[]): LexicalNode[] {
-    return nodes.map(node => {
-        if ($isTextNode(node)) {
-            const paragraph = $createCustomParagraphNode();
-            paragraph.append(node);
-            return paragraph;
-        }
-        return node;
-    });
-}
-
-export function $htmlToBlockNodes(editor: LexicalEditor, html: string): LexicalNode[] {
-    const dom = htmlToDom(html);
-    const nodes = $generateNodesFromDOM(editor, dom);
-    return wrapTextNodes(nodes);
-}
-
-export function $selectionContainsNodeType(selection: BaseSelection|null, matcher: LexicalNodeMatcher): boolean {
+export function $selectionContainsNodeType(selection: BaseSelection | null, matcher: LexicalNodeMatcher): boolean {
     return $getNodeFromSelection(selection, matcher) !== null;
 }
 
-export function $getNodeFromSelection(selection: BaseSelection|null, matcher: LexicalNodeMatcher): LexicalNode|null {
+export function $getNodeFromSelection(selection: BaseSelection | null, matcher: LexicalNodeMatcher): LexicalNode | null {
     if (!selection) {
         return null;
     }
@@ -77,17 +41,7 @@ export function $getNodeFromSelection(selection: BaseSelection|null, matcher: Le
     return null;
 }
 
-export function $getParentOfType(node: LexicalNode, matcher: LexicalNodeMatcher): LexicalNode|null {
-    for (const parent of node.getParents()) {
-        if (matcher(parent)) {
-            return parent;
-        }
-    }
-
-    return null;
-}
-
-export function $selectionContainsTextFormat(selection: BaseSelection|null, format: TextFormatType): boolean {
+export function $selectionContainsTextFormat(selection: BaseSelection | null, format: TextFormatType): boolean {
     if (!selection) {
         return false;
     }
@@ -140,7 +94,7 @@ export function $selectSingleNode(node: LexicalNode) {
     $setSelection(nodeSelection);
 }
 
-export function $selectionContainsNode(selection: BaseSelection|null, node: LexicalNode): boolean {
+export function $selectionContainsNode(selection: BaseSelection | null, node: LexicalNode): boolean {
     if (!selection) {
         return false;
     }
@@ -155,7 +109,7 @@ export function $selectionContainsNode(selection: BaseSelection|null, node: Lexi
     return false;
 }
 
-export function $selectionContainsElementFormat(selection: BaseSelection|null, format: ElementFormatType): boolean {
+export function $selectionContainsElementFormat(selection: BaseSelection | null, format: ElementFormatType): boolean {
     const nodes = $getBlockElementNodesInSelection(selection);
     for (const node of nodes) {
         if (node.getFormatType() === format) {
@@ -166,7 +120,7 @@ export function $selectionContainsElementFormat(selection: BaseSelection|null, f
     return false;
 }
 
-export function $getBlockElementNodesInSelection(selection: BaseSelection|null): ElementNode[] {
+export function $getBlockElementNodesInSelection(selection: BaseSelection | null): ElementNode[] {
     if (!selection) {
         return [];
     }
@@ -175,7 +129,7 @@ export function $getBlockElementNodesInSelection(selection: BaseSelection|null):
     for (const node of selection.getNodes()) {
         const blockElement = $findMatchingParent(node, (node) => {
             return $isElementNode(node) && !node.isInline();
-        }) as ElementNode|null;
+        }) as ElementNode | null;
 
         if (blockElement) {
             blockNodes.set(blockElement.getKey(), blockElement);
@@ -183,25 +137,4 @@ export function $getBlockElementNodesInSelection(selection: BaseSelection|null):
     }
 
     return Array.from(blockNodes.values());
-}
-
-/**
- * Get the nearest root/block level node for the given position.
- */
-export function $getNearestBlockNodeForCoords(editor: LexicalEditor, x: number, y: number): LexicalNode|null {
-    // TODO - Take into account x for floated blocks?
-    const rootNodes = $getRoot().getChildren();
-    for (const node of rootNodes) {
-        const nodeDom = editor.getElementByKey(node.__key);
-        if (!nodeDom) {
-            continue;
-        }
-
-        const bounds = nodeDom.getBoundingClientRect();
-        if (y <= bounds.bottom) {
-            return node;
-        }
-    }
-
-    return null;
 }
\ No newline at end of file