Skip to content

Commit

Permalink
feat: update typescript to v5.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m1d0v committed Feb 4, 2025
1 parent 6497fc4 commit 4c911ff
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 54 deletions.
25 changes: 5 additions & 20 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
"stylelint": "15.11.0",
"ts-dedent": "2.2.0",
"ts-jest": "^29.2.5",
"typescript": "^4.5.2"
"typescript": "^5.7.3"
},
"peerDependenciesMeta": {
"@diplodoc/folding-headings-extension": {
Expand Down
10 changes: 5 additions & 5 deletions src/core/types/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export interface ActionSpec {
meta?(state: EditorState): any;
}

export interface Action<A extends {} = never, M = unknown> {
isActive(): boolean;
isEnable(args?: Record<string, unknown>): boolean;
run(...args: A extends never ? [] : [A]): void;
meta(): M;
export interface Action<A extends {} | unknown = unknown, M = unknown> {
isActive: () => boolean;
isEnable: (args?: Record<string, unknown>) => boolean;
run: A extends {} ? (arg: A) => void : () => void;
meta: () => M;
}

export interface ActionStorage {
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/markdown/Image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type {AddImageAttrs} from './actions';

export type ImageOptions = ImageUrlPasteOptions;

export const Image: ExtensionAuto<ImageOptions | undefined> = (builder, opts) => {
export const Image: ExtensionAuto<ImageOptions> = (builder, opts) => {
builder.use(ImageSpecs);

builder.addAction(addImageAction, ({schema}) => addImage(schema));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Action} from '../../../../../core';

import './floating.scss';

export type TableCellFloatingButtonAction = {action: Action; text: string};
export type TableCellFloatingButtonAction = {action: Action<Record<string, unknown>>; text: string};
export type TableCellFloatingButtonMixed =
| TableCellFloatingButtonAction
| TableCellFloatingButtonAction[];
Expand Down Expand Up @@ -54,7 +54,7 @@ function buildMenuItem(floatingAction: TableCellFloatingButtonMixed): DropdownMe

return {
text,
action: () => action.run(),
action: () => action.run({}),
active,
disabled,
};
Expand Down
9 changes: 5 additions & 4 deletions src/presets/commonmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ export const CommonMarkPreset: ExtensionAuto<CommonMarkPresetOptions> = (builder
.use(Blockquote, opts.blockquote ?? {});

if (opts.image !== false) {
builder.use(
isFunction(opts.image) ? opts.image : Image,
isFunction(opts.image) ? undefined : opts.image,
);
if (isFunction(opts.image)) {
builder.use(opts.image);
} else {
builder.use(Image, opts.image ?? {});
}
}

if (opts.heading !== false) {
Expand Down
7 changes: 0 additions & 7 deletions src/selection.d.ts

This file was deleted.

14 changes: 4 additions & 10 deletions src/utils/selection.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import type {Node, NodeType, ResolvedPos} from 'prosemirror-model';
import {AllSelection, NodeSelection, Selection, TextSelection} from 'prosemirror-state';

NodeSelection.prototype.selectionName = 'NodeSelection';
TextSelection.prototype.selectionName = 'TextSelection';
AllSelection.prototype.selectionName = 'AllSelection';

export const isTextSelection = (selection: Selection): selection is TextSelection =>
selection.selectionName === TextSelection.prototype.selectionName;
selection instanceof TextSelection;

export const isNodeSelection = (selection: Selection): selection is NodeSelection =>
selection.selectionName === NodeSelection.prototype.selectionName;
selection instanceof NodeSelection;

// ts broke down when use "selection is AllSelection" return type
// maybe because AllSelection has same class type with different constructor
export const isWholeSelection = (selection: Selection): boolean =>
selection.selectionName === AllSelection.prototype.selectionName;
export const isWholeSelection = (selection: Selection): selection is AllSelection =>
selection instanceof AllSelection;

export const get$Cursor = (selection: Selection): ResolvedPos | null => {
return isTextSelection(selection) ? selection.$cursor : null;
Expand Down
8 changes: 4 additions & 4 deletions tests/event-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export class ClipboardEventMock implements ClipboardEvent {
readonly target: EventTarget | null = null;
readonly timeStamp: DOMHighResTimeStamp = Date.now();
readonly type: string;
readonly AT_TARGET: number = 0;
readonly BUBBLING_PHASE: number = 0;
readonly CAPTURING_PHASE: number = 0;
readonly NONE: number = 0;
readonly NONE: 0 = 0;
readonly CAPTURING_PHASE: 1 = 1;
readonly AT_TARGET: 2 = 2;
readonly BUBBLING_PHASE: 3 = 3;
constructor(type: string, eventInitDict?: ClipboardEventInit) {
this.type = type;
this.bubbles = eventInitDict?.bubbles ?? false;
Expand Down

0 comments on commit 4c911ff

Please sign in to comment.