Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
kudlajz committed Nov 19, 2024
1 parent 893b735 commit d8a4896
Show file tree
Hide file tree
Showing 33 changed files with 129 additions and 65 deletions.
6 changes: 5 additions & 1 deletion packages/slate-commons/src/commands/alignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function isAlignmentRoot([node, path]: NodeEntry): boolean {
return path.length === 0 || isTableCellNode(node);
}

function isTopLevelAlignableElement(editor: SlateEditor, node: Node, path: Path): node is AlignableNode {
function isTopLevelAlignableElement(
editor: SlateEditor,
node: Node,
path: Path,
): node is AlignableNode {
const parent = editor.above({ at: path });
return parent !== undefined && isAlignmentRoot(parent) && isAlignableElement(node);
}
9 changes: 6 additions & 3 deletions packages/slate-commons/src/commands/findLeafPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { Node, Text } from 'slate';

export type Edge = 'highest' | 'lowest';

export function findLeafPath(editor: SlateEditor, path: Path, edge: Edge = 'highest'): Path | undefined {
export function findLeafPath(
editor: SlateEditor,
path: Path,
edge: Edge = 'highest',
): Path | undefined {
if (!Node.has(editor, path)) {
return undefined;
}
Expand All @@ -15,8 +19,7 @@ export function findLeafPath(editor: SlateEditor, path: Path, edge: Edge = 'high
return path;
}

const [, nestedPath] =
edge === 'highest' ? editor.first(path) : editor.last(path);
const [, nestedPath] = edge === 'highest' ? editor.first(path) : editor.last(path);

return findLeafPath(editor, nestedPath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import type { Node } from 'slate';

import { isNodeEmpty } from './isNodeEmpty';

export function isEmptyParagraphElement(editor: SlateEditor, node?: Node | null, trim = false): boolean {
export function isEmptyParagraphElement(
editor: SlateEditor,
node?: Node | null,
trim = false,
): boolean {
return isParagraphNode(node) && isNodeEmpty(editor, node, trim);
}
5 changes: 4 additions & 1 deletion packages/slate-commons/src/commands/isMarkActive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { SlateEditor } from '@udecode/plate-common';
import type { Text } from 'slate';

export function isMarkActive<T extends Text>(editor: SlateEditor, mark: keyof Omit<T, 'text'>): boolean {
export function isMarkActive<T extends Text>(
editor: SlateEditor,
mark: keyof Omit<T, 'text'>,
): boolean {
const marks = editor.getMarks() as Record<keyof T, boolean>;
return marks ? marks[mark] === true : false;
}
2 changes: 1 addition & 1 deletion packages/slate-commons/src/commands/isVoid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SlateEditor } from '@udecode/plate-common';
import { isElement } from '@udecode/slate';
import { isElement } from '@udecode/slate';
import type { Node } from 'slate';

export function isVoid(editor: SlateEditor, node: Node): boolean {
Expand Down
6 changes: 5 additions & 1 deletion packages/slate-commons/src/commands/resetNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { fixSelection } from './isValidSelection';
* Based on the snippet from the Slate issue discussion:
* @see https://github.com/ianstormtaylor/slate/pull/4540#issuecomment-951903419
*/
export function resetNodes(editor: SlateEditor, nodes: TDescendant[], selection?: TSelection): void {
export function resetNodes(
editor: SlateEditor,
nodes: TDescendant[],
selection?: TSelection,
): void {
const children = [...editor.children];

editor.withoutNormalizing(() => {
Expand Down
4 changes: 1 addition & 3 deletions packages/slate-commons/src/commands/roughly-normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export function roughlyNormalizeNode<T extends Node>(node: T): T | null {
}

if ('children' in node) {
const children = Array.isArray(node.children)
? roughlyNormalizeNodes(node.children)
: [];
const children = Array.isArray(node.children) ? roughlyNormalizeNodes(node.children) : [];

if (children.length > 0) {
return node.children === children ? node : { ...node, children };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ interface Parameters {
unit: 'character' | 'word' | 'line' | 'block';
}

export function deleteCurrentNodeIfEmpty(editor: SlateEditor, { reverse, unit }: Parameters): boolean {
export function deleteCurrentNodeIfEmpty(
editor: SlateEditor,
{ reverse, unit }: Parameters,
): boolean {
const [currentNode] = getCurrentNodeEntry(editor) || [];
const targetNode = getDeletionTargetNode(editor, { reverse, unit });

Expand Down
6 changes: 5 additions & 1 deletion packages/slate-commons/src/types/OnKeyDown.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { SlateEditor } from '@udecode/plate-common';
import type { KeyboardEvent } from 'react';

export type OnKeyDown = (event: KeyboardEvent, editor: SlateEditor, options?: any) => boolean | void;
export type OnKeyDown = (
event: KeyboardEvent,
editor: SlateEditor,
options?: any,
) => boolean | void;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SlateEditor } from '@udecode/plate-common';
// import { getPointBefore } from '@udecode/plate-core';
import type { Point/*, Range*/ } from 'slate';
import type { Point /*, Range*/ } from 'slate';

import type { MatchRange } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const shape: Record<keyof QuoteNode, true> = {

const ALLOWED_ATTRIBUTES = Object.keys(shape);

export function normalizeRedundantAttributes(editor: SlateEditor, [node, path]: NodeEntry): boolean {
export function normalizeRedundantAttributes(
editor: SlateEditor,
[node, path]: NodeEntry,
): boolean {
if (isQuoteNode(node)) {
return EditorCommands.normalizeRedundantAttributes(
editor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export function normalizeAttributes(editor: SlateEditor, [node, path]: NodeEntry
return false;
}

function normalizeIconAttribute(editor: SlateEditor, [node, path]: NodeEntry<CalloutNode>): boolean {
function normalizeIconAttribute(
editor: SlateEditor,
[node, path]: NodeEntry<CalloutNode>,
): boolean {
// If there's no icon, the attribute should be absent.
// We replace `null` and "" empty string values with `undefined`.
if (!node.icon && typeof node.icon !== 'undefined') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Decorate } from '@prezly/slate-commons';
import { isExpanded, isText} from '@udecode/plate-common';
import { isExpanded, isText } from '@udecode/plate-common';
import type { SlateEditor, TNodeEntry } from '@udecode/plate-common';
import { Range } from 'slate';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import { useEditorRef } from '@udecode/plate-common/react';
// import type { RefObject } from 'react';
import React, { /*useEffect, useState*/ } from 'react';
import React /*useEffect, useState*/ from 'react';
// import type { Editor, Node } from 'slate';
// import { ReactEditor } from 'slate-react';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { isGalleryNode, validateGalleryNode } from '@prezly/slate-types';
import type { SlateEditor } from '@udecode/plate-common';
import type { Node, NodeEntry } from 'slate';

export function normalizeInvalidGallery(editor: SlateEditor, [node, path]: NodeEntry<Node>): boolean {
export function normalizeInvalidGallery(
editor: SlateEditor,
[node, path]: NodeEntry<Node>,
): boolean {
if (isGalleryNode(node) && !validateGalleryNode(node)) {
editor.removeNodes({ at: path });
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const shape: Record<keyof HeadingNode, true> = {

const ALLOWED_ATTRIBUTES = Object.keys(shape);

export function normalizeRedundantAttributes(editor: SlateEditor, [node, path]: NodeEntry): boolean {
export function normalizeRedundantAttributes(
editor: SlateEditor,
[node, path]: NodeEntry,
): boolean {
if (isHeadingNode(node)) {
return EditorCommands.normalizeRedundantAttributes(
editor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export function withSelectionAutolinking<T extends SlateEditor>(editor: T): T {
const href = data.getData('text');

if (isUrl(href) && !EditorCommands.isSelectionEmpty(editor)) {
const nodes = Array.from(
editor.nodes({ match: isElementNode, mode: 'highest' }),
);
const nodes = Array.from(editor.nodes({ match: isElementNode, mode: 'highest' }));

const isOnlyAllowedNodes = nodes.every(([node]) =>
isElementNode(node, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const shape: Record<keyof LinkNode, true> = {

const ALLOWED_LINK_ATTRIBUTES = Object.keys(shape);

export function normalizeRedundantLinkAttributes(editor: SlateEditor, [node, path]: NodeEntry<Node>) {
export function normalizeRedundantLinkAttributes(
editor: SlateEditor,
[node, path]: NodeEntry<Node>,
) {
if (isLinkNode(node)) {
return EditorCommands.normalizeRedundantAttributes(
editor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export function insertBlockBelow(editor: SlateEditor, createElement: () => Eleme
return insertBlock(editor, createElement, Direction.BELOW);
}

function insertBlock(editor: SlateEditor, createElement: () => Element, direction: Direction): boolean {
function insertBlock(
editor: SlateEditor,
createElement: () => Element,
direction: Direction,
): boolean {
const path = editor.selection?.focus.path ?? [];

if (path.length === 0) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const ALLOWED_LIST_ATTRIBUTES = Object.keys(LIST_SHAPE);
const ALLOWED_LIST_ITEM_ATTRIBUTES = Object.keys(LIST_ITEM_SHAPE);
const ALLOWED_LIST_ITEM_TEXT_ATTRIBUTES = Object.keys(LIST_ITEM_TEXT_SHAPE);

export function normalizeRedundantAttributes(editor: SlateEditor, [node, path]: NodeEntry): boolean {
export function normalizeRedundantAttributes(
editor: SlateEditor,
[node, path]: NodeEntry,
): boolean {
if (isListNode(node)) {
return EditorCommands.normalizeRedundantAttributes(
editor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ function getMatchingTextRange(
* It should probably not happen in this case, because we're computing the distance based
* on the matched text. But just in case, use start of the editor as the fallback point.
*/
const triggerPoint =
editor.before(at, { distance, unit: 'character' }) || editor.start([]);
const triggerPoint = editor.before(at, { distance, unit: 'character' }) || editor.start([]);

/**
* Compute a new range to match the exact range of `trigger` + `text`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { Element } from 'slate';
/**
* If there's an Element node without a `type` attribute - mark it as paragraph.
*/
export function normalizeUnknownElement(editor: SlateEditor, [node, path]: NodeEntry<Node>): boolean {
export function normalizeUnknownElement(
editor: SlateEditor,
[node, path]: NodeEntry<Node>,
): boolean {
if (!Element.isElement(node)) {
// This function does not know how to normalize other nodes.
return false;
Expand Down
8 changes: 7 additions & 1 deletion packages/slate-editor/src/extensions/placeholders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ export {
} from './PlaceholdersExtension';
export { PlaceholderNode } from './PlaceholderNode';
export { PlaceholdersManager } from './PlaceholdersManager';
export { createPlaceholder, insertPlaceholder, insertPlaceholders, removePlaceholder, replacePlaceholder } from './lib';
export {
createPlaceholder,
insertPlaceholder,
insertPlaceholders,
removePlaceholder,
replacePlaceholder,
} from './lib';
export type { FetchOEmbedFn } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@ const SHAPE: Record<keyof ContactNode, boolean> = {

const ALLOWED_ATTRIBUTES = Object.keys(SHAPE);

export function normalizeContactNodeAttributes(editor: SlateEditor, [node, path]: NodeEntry): boolean {
export function normalizeContactNodeAttributes(
editor: SlateEditor,
[node, path]: NodeEntry,
): boolean {
if (!isContactNode(node)) {
return false;
}

return EditorCommands.normalizeRedundantAttributes(editor, [node, path], ALLOWED_ATTRIBUTES);
}

export function normalizeContactInfoAttributes(editor: SlateEditor, [node, path]: NodeEntry): boolean {
export function normalizeContactInfoAttributes(
editor: SlateEditor,
[node, path]: NodeEntry,
): boolean {
if (!isContactNode(node)) {
return false;
}
if (isEqual(node.contact, ContactInfo.normalize(node.contact))) {
return false;
}

editor.setNodes<ContactNode>(
{ contact: ContactInfo.normalize(node.contact) },
{ at: path },
);
editor.setNodes<ContactNode>({ contact: ContactInfo.normalize(node.contact) }, { at: path });
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { type NodeEntry } from 'slate';
*/
const PLACEHOLDER_NODE_TYPE = 'placeholder';

export function convertLegacyPlaceholderNodesToVariables(editor: SlateEditor, [node, path]: NodeEntry) {
export function convertLegacyPlaceholderNodesToVariables(
editor: SlateEditor,
[node, path]: NodeEntry,
) {
if (isElementNode(node, PLACEHOLDER_NODE_TYPE)) {
editor.setNodes({ type: VARIABLE_NODE_TYPE }, { at: path });
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { type VariableNode, isVariableNode } from '@prezly/slate-types';
import type { SlateEditor } from '@udecode/plate-common';
import { type NodeEntry } from 'slate';

export function removeFallbackPropertyIfEmpty(editor: SlateEditor, [node, path]: NodeEntry): boolean {
export function removeFallbackPropertyIfEmpty(
editor: SlateEditor,
[node, path]: NodeEntry,
): boolean {
if (!isVariableNode(node)) {
return false;
}
Expand Down
15 changes: 8 additions & 7 deletions packages/slate-editor/src/modules/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
import { Events } from '@prezly/events';
import { EditorCommands } from '@prezly/slate-commons';
import { TablesEditor } from '@prezly/slate-tables';
import type {
HeadingNode,
ParagraphNode,
QuoteNode} from '@prezly/slate-types';
import type { HeadingNode, ParagraphNode, QuoteNode } from '@prezly/slate-types';
import {
Alignment,
HEADING_1_NODE_TYPE,
HEADING_2_NODE_TYPE,
PARAGRAPH_NODE_TYPE,
QUOTE_NODE_TYPE
QUOTE_NODE_TYPE,
} from '@prezly/slate-types';
import { noop } from '@technically/lodash';
import { Plate } from '@udecode/plate-common/react';
Expand All @@ -32,7 +29,12 @@ import { useFunction, useGetSet, useSize } from '#lib';
import { insertButtonBlock } from '#extensions/button-block';
import { insertCallout } from '#extensions/callout';
import { FloatingAddMenu, type Option } from '#extensions/floating-add-menu';
import { insertPlaceholder, PlaceholderNode, PlaceholdersManager, replacePlaceholder } from '#extensions/placeholders';
import {
insertPlaceholder,
PlaceholderNode,
PlaceholdersManager,
replacePlaceholder,
} from '#extensions/placeholders';
import { useFloatingSnippetInput } from '#extensions/snippet';
import { UserMentionsDropdown, useUserMentions } from '#extensions/user-mentions';
import { useVariables, VariablesDropdown } from '#extensions/variables';
Expand All @@ -59,7 +61,6 @@ import type { EditorProps, EditorRef, Value } from './types';
import { useCreateEditor } from './useCreateEditor';
import { useOnChange } from './useOnChange';


export const Editor = forwardRef<EditorRef, EditorProps>((props, forwardedRef) => {
const {
align = Alignment.LEFT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { isEqual } from '@technically/lodash';
import { isVoid, type SlateEditor } from '@udecode/plate-common';
import type { Element, Text, Descendant } from 'slate';

export function isEditorValueEqual<T extends Descendant>(editor: SlateEditor, a: T[], b: T[]): boolean {
export function isEditorValueEqual<T extends Descendant>(
editor: SlateEditor,
a: T[],
b: T[],
): boolean {
const compareNodes = cached(editor, (node: Descendant, another: Descendant): boolean => {
const isNodeText = isText(node);
const isAnotherText = isText(another);
Expand Down Expand Up @@ -44,7 +48,10 @@ function isText(node: Descendant): node is Text {

// CACHE

const CACHE: WeakMap<SlateEditor, WeakMap<Descendant, WeakMap<Descendant, boolean>>> = new WeakMap();
const CACHE: WeakMap<
SlateEditor,
WeakMap<Descendant, WeakMap<Descendant, boolean>>
> = new WeakMap();

type WeakMatrix = WeakMap<SlateEditor, WeakMap<Descendant, WeakMap<Descendant, boolean>>>;
type NodesComparator = (node: Descendant, another: Descendant) => boolean;
Expand Down
Loading

0 comments on commit d8a4896

Please sign in to comment.