fix: resolve TypeScript errors in frontend build

This commit is contained in:
Hiro
2026-03-30 23:16:07 +00:00
parent b733306773
commit 24925e1acb
2941 changed files with 418042 additions and 49 deletions

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025, Tiptap GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,18 @@
# @tiptap/extension-code-block-lowlight
[![Version](https://img.shields.io/npm/v/@tiptap/extension-code-block-lowlight.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-code-block-lowlight)
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-code-block-lowlight.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
[![License](https://img.shields.io/npm/l/@tiptap/extension-code-block-lowlight.svg)](https://www.npmjs.com/package/@tiptap/extension-code-block-lowlight)
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
## Introduction
Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
## Official Documentation
Documentation can be found on the [Tiptap website](https://tiptap.dev).
## License
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).

View File

@@ -0,0 +1,188 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
CodeBlockLowlight: () => CodeBlockLowlight,
default: () => index_default
});
module.exports = __toCommonJS(index_exports);
// src/code-block-lowlight.ts
var import_extension_code_block = require("@tiptap/extension-code-block");
// src/lowlight-plugin.ts
var import_core = require("@tiptap/core");
var import_state = require("@tiptap/pm/state");
var import_view = require("@tiptap/pm/view");
var import_core2 = __toESM(require("highlight.js/lib/core"), 1);
function parseNodes(nodes, className = []) {
return nodes.flatMap((node) => {
const classes = [...className, ...node.properties ? node.properties.className : []];
if (node.children) {
return parseNodes(node.children, classes);
}
return {
text: node.value,
classes
};
});
}
function getHighlightNodes(result) {
return result.value || result.children || [];
}
function registered(aliasOrLanguage) {
return Boolean(import_core2.default.getLanguage(aliasOrLanguage));
}
function getDecorations({
doc,
name,
lowlight,
defaultLanguage
}) {
const decorations = [];
(0, import_core.findChildren)(doc, (node) => node.type.name === name).forEach((block) => {
var _a;
let from = block.pos + 1;
const language = block.node.attrs.language || defaultLanguage;
const languages = lowlight.listLanguages();
const nodes = language && (languages.includes(language) || registered(language) || ((_a = lowlight.registered) == null ? void 0 : _a.call(lowlight, language))) ? getHighlightNodes(lowlight.highlight(language, block.node.textContent)) : getHighlightNodes(lowlight.highlightAuto(block.node.textContent));
parseNodes(nodes).forEach((node) => {
const to = from + node.text.length;
if (node.classes.length) {
const decoration = import_view.Decoration.inline(from, to, {
class: node.classes.join(" ")
});
decorations.push(decoration);
}
from = to;
});
});
return import_view.DecorationSet.create(doc, decorations);
}
function isFunction(param) {
return typeof param === "function";
}
function LowlightPlugin({
name,
lowlight,
defaultLanguage
}) {
if (!["highlight", "highlightAuto", "listLanguages"].every((api) => isFunction(lowlight[api]))) {
throw Error("You should provide an instance of lowlight to use the code-block-lowlight extension");
}
const lowlightPlugin = new import_state.Plugin({
key: new import_state.PluginKey("lowlight"),
state: {
init: (_, { doc }) => getDecorations({
doc,
name,
lowlight,
defaultLanguage
}),
apply: (transaction, decorationSet, oldState, newState) => {
const oldNodeName = oldState.selection.$head.parent.type.name;
const newNodeName = newState.selection.$head.parent.type.name;
const oldNodes = (0, import_core.findChildren)(oldState.doc, (node) => node.type.name === name);
const newNodes = (0, import_core.findChildren)(newState.doc, (node) => node.type.name === name);
if (transaction.docChanged && // Apply decorations if:
// selection includes named node,
([oldNodeName, newNodeName].includes(name) || // OR transaction adds/removes named node,
newNodes.length !== oldNodes.length || // OR transaction has changes that completely encapsulte a node
// (for example, a transaction that affects the entire document).
// Such transactions can happen during collab syncing via y-prosemirror, for example.
transaction.steps.some((step) => {
return (
// @ts-ignore
step.from !== void 0 && // @ts-ignore
step.to !== void 0 && oldNodes.some((node) => {
return (
// @ts-ignore
node.pos >= step.from && // @ts-ignore
node.pos + node.node.nodeSize <= step.to
);
})
);
}))) {
return getDecorations({
doc: transaction.doc,
name,
lowlight,
defaultLanguage
});
}
return decorationSet.map(transaction.mapping, transaction.doc);
}
},
props: {
decorations(state) {
return lowlightPlugin.getState(state);
}
}
});
return lowlightPlugin;
}
// src/code-block-lowlight.ts
var CodeBlockLowlight = import_extension_code_block.CodeBlock.extend({
addOptions() {
var _a;
return {
...(_a = this.parent) == null ? void 0 : _a.call(this),
lowlight: {},
languageClassPrefix: "language-",
exitOnTripleEnter: true,
exitOnArrowDown: true,
defaultLanguage: null,
enableTabIndentation: false,
tabSize: 4,
HTMLAttributes: {}
};
},
addProseMirrorPlugins() {
var _a;
return [
...((_a = this.parent) == null ? void 0 : _a.call(this)) || [],
LowlightPlugin({
name: this.name,
lowlight: this.options.lowlight,
defaultLanguage: this.options.defaultLanguage
})
];
}
});
// src/index.ts
var index_default = CodeBlockLowlight;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CodeBlockLowlight
});
//# sourceMappingURL=index.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,16 @@
import * as _tiptap_core from '@tiptap/core';
import { CodeBlockOptions } from '@tiptap/extension-code-block';
interface CodeBlockLowlightOptions extends CodeBlockOptions {
/**
* The lowlight instance.
*/
lowlight: any;
}
/**
* This extension allows you to highlight code blocks with lowlight.
* @see https://tiptap.dev/api/nodes/code-block-lowlight
*/
declare const CodeBlockLowlight: _tiptap_core.Node<CodeBlockLowlightOptions, any>;
export { CodeBlockLowlight, type CodeBlockLowlightOptions, CodeBlockLowlight as default };

View File

@@ -0,0 +1,16 @@
import * as _tiptap_core from '@tiptap/core';
import { CodeBlockOptions } from '@tiptap/extension-code-block';
interface CodeBlockLowlightOptions extends CodeBlockOptions {
/**
* The lowlight instance.
*/
lowlight: any;
}
/**
* This extension allows you to highlight code blocks with lowlight.
* @see https://tiptap.dev/api/nodes/code-block-lowlight
*/
declare const CodeBlockLowlight: _tiptap_core.Node<CodeBlockLowlightOptions, any>;
export { CodeBlockLowlight, type CodeBlockLowlightOptions, CodeBlockLowlight as default };

View File

@@ -0,0 +1,151 @@
// src/code-block-lowlight.ts
import { CodeBlock } from "@tiptap/extension-code-block";
// src/lowlight-plugin.ts
import { findChildren } from "@tiptap/core";
import { Plugin, PluginKey } from "@tiptap/pm/state";
import { Decoration, DecorationSet } from "@tiptap/pm/view";
import highlight from "highlight.js/lib/core";
function parseNodes(nodes, className = []) {
return nodes.flatMap((node) => {
const classes = [...className, ...node.properties ? node.properties.className : []];
if (node.children) {
return parseNodes(node.children, classes);
}
return {
text: node.value,
classes
};
});
}
function getHighlightNodes(result) {
return result.value || result.children || [];
}
function registered(aliasOrLanguage) {
return Boolean(highlight.getLanguage(aliasOrLanguage));
}
function getDecorations({
doc,
name,
lowlight,
defaultLanguage
}) {
const decorations = [];
findChildren(doc, (node) => node.type.name === name).forEach((block) => {
var _a;
let from = block.pos + 1;
const language = block.node.attrs.language || defaultLanguage;
const languages = lowlight.listLanguages();
const nodes = language && (languages.includes(language) || registered(language) || ((_a = lowlight.registered) == null ? void 0 : _a.call(lowlight, language))) ? getHighlightNodes(lowlight.highlight(language, block.node.textContent)) : getHighlightNodes(lowlight.highlightAuto(block.node.textContent));
parseNodes(nodes).forEach((node) => {
const to = from + node.text.length;
if (node.classes.length) {
const decoration = Decoration.inline(from, to, {
class: node.classes.join(" ")
});
decorations.push(decoration);
}
from = to;
});
});
return DecorationSet.create(doc, decorations);
}
function isFunction(param) {
return typeof param === "function";
}
function LowlightPlugin({
name,
lowlight,
defaultLanguage
}) {
if (!["highlight", "highlightAuto", "listLanguages"].every((api) => isFunction(lowlight[api]))) {
throw Error("You should provide an instance of lowlight to use the code-block-lowlight extension");
}
const lowlightPlugin = new Plugin({
key: new PluginKey("lowlight"),
state: {
init: (_, { doc }) => getDecorations({
doc,
name,
lowlight,
defaultLanguage
}),
apply: (transaction, decorationSet, oldState, newState) => {
const oldNodeName = oldState.selection.$head.parent.type.name;
const newNodeName = newState.selection.$head.parent.type.name;
const oldNodes = findChildren(oldState.doc, (node) => node.type.name === name);
const newNodes = findChildren(newState.doc, (node) => node.type.name === name);
if (transaction.docChanged && // Apply decorations if:
// selection includes named node,
([oldNodeName, newNodeName].includes(name) || // OR transaction adds/removes named node,
newNodes.length !== oldNodes.length || // OR transaction has changes that completely encapsulte a node
// (for example, a transaction that affects the entire document).
// Such transactions can happen during collab syncing via y-prosemirror, for example.
transaction.steps.some((step) => {
return (
// @ts-ignore
step.from !== void 0 && // @ts-ignore
step.to !== void 0 && oldNodes.some((node) => {
return (
// @ts-ignore
node.pos >= step.from && // @ts-ignore
node.pos + node.node.nodeSize <= step.to
);
})
);
}))) {
return getDecorations({
doc: transaction.doc,
name,
lowlight,
defaultLanguage
});
}
return decorationSet.map(transaction.mapping, transaction.doc);
}
},
props: {
decorations(state) {
return lowlightPlugin.getState(state);
}
}
});
return lowlightPlugin;
}
// src/code-block-lowlight.ts
var CodeBlockLowlight = CodeBlock.extend({
addOptions() {
var _a;
return {
...(_a = this.parent) == null ? void 0 : _a.call(this),
lowlight: {},
languageClassPrefix: "language-",
exitOnTripleEnter: true,
exitOnArrowDown: true,
defaultLanguage: null,
enableTabIndentation: false,
tabSize: 4,
HTMLAttributes: {}
};
},
addProseMirrorPlugins() {
var _a;
return [
...((_a = this.parent) == null ? void 0 : _a.call(this)) || [],
LowlightPlugin({
name: this.name,
lowlight: this.options.lowlight,
defaultLanguage: this.options.defaultLanguage
})
];
}
});
// src/index.ts
var index_default = CodeBlockLowlight;
export {
CodeBlockLowlight,
index_default as default
};
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,55 @@
{
"name": "@tiptap/extension-code-block-lowlight",
"description": "code block extension for tiptap",
"version": "3.21.0",
"homepage": "https://tiptap.dev",
"keywords": [
"tiptap",
"tiptap extension"
],
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/ueberdosis"
},
"type": "module",
"exports": {
".": {
"types": {
"import": "./dist/index.d.ts",
"require": "./dist/index.d.cts"
},
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"src",
"dist"
],
"devDependencies": {
"lowlight": "^3.3.0",
"@tiptap/core": "^3.21.0",
"@tiptap/extension-code-block": "^3.21.0",
"@tiptap/pm": "^3.21.0"
},
"peerDependencies": {
"lowlight": "^2 || ^3",
"highlight.js": "^11",
"@tiptap/core": "^3.21.0",
"@tiptap/extension-code-block": "^3.21.0",
"@tiptap/pm": "^3.21.0"
},
"repository": {
"type": "git",
"url": "https://github.com/ueberdosis/tiptap",
"directory": "packages/extension-code-block-lowlight"
},
"scripts": {
"build": "tsup",
"lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
}
}

View File

@@ -0,0 +1,42 @@
import type { CodeBlockOptions } from '@tiptap/extension-code-block'
import { CodeBlock } from '@tiptap/extension-code-block'
import { LowlightPlugin } from './lowlight-plugin.js'
export interface CodeBlockLowlightOptions extends CodeBlockOptions {
/**
* The lowlight instance.
*/
lowlight: any
}
/**
* This extension allows you to highlight code blocks with lowlight.
* @see https://tiptap.dev/api/nodes/code-block-lowlight
*/
export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
addOptions() {
return {
...this.parent?.(),
lowlight: {},
languageClassPrefix: 'language-',
exitOnTripleEnter: true,
exitOnArrowDown: true,
defaultLanguage: null,
enableTabIndentation: false,
tabSize: 4,
HTMLAttributes: {},
}
},
addProseMirrorPlugins() {
return [
...(this.parent?.() || []),
LowlightPlugin({
name: this.name,
lowlight: this.options.lowlight,
defaultLanguage: this.options.defaultLanguage,
}),
]
},
})

View File

@@ -0,0 +1,5 @@
import { CodeBlockLowlight } from './code-block-lowlight.js'
export * from './code-block-lowlight.js'
export default CodeBlockLowlight

View File

@@ -0,0 +1,157 @@
import { findChildren } from '@tiptap/core'
import type { Node as ProsemirrorNode } from '@tiptap/pm/model'
import { Plugin, PluginKey } from '@tiptap/pm/state'
import { Decoration, DecorationSet } from '@tiptap/pm/view'
// @ts-ignore
import highlight from 'highlight.js/lib/core'
function parseNodes(nodes: any[], className: string[] = []): { text: string; classes: string[] }[] {
return nodes.flatMap(node => {
const classes = [...className, ...(node.properties ? node.properties.className : [])]
if (node.children) {
return parseNodes(node.children, classes)
}
return {
text: node.value,
classes,
}
})
}
function getHighlightNodes(result: any) {
// `.value` for lowlight v1, `.children` for lowlight v2
return result.value || result.children || []
}
function registered(aliasOrLanguage: string) {
return Boolean(highlight.getLanguage(aliasOrLanguage))
}
function getDecorations({
doc,
name,
lowlight,
defaultLanguage,
}: {
doc: ProsemirrorNode
name: string
lowlight: any
defaultLanguage: string | null | undefined
}) {
const decorations: Decoration[] = []
findChildren(doc, node => node.type.name === name).forEach(block => {
let from = block.pos + 1
const language = block.node.attrs.language || defaultLanguage
const languages = lowlight.listLanguages()
const nodes =
language && (languages.includes(language) || registered(language) || lowlight.registered?.(language))
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
: getHighlightNodes(lowlight.highlightAuto(block.node.textContent))
parseNodes(nodes).forEach(node => {
const to = from + node.text.length
if (node.classes.length) {
const decoration = Decoration.inline(from, to, {
class: node.classes.join(' '),
})
decorations.push(decoration)
}
from = to
})
})
return DecorationSet.create(doc, decorations)
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
function isFunction(param: any): param is Function {
return typeof param === 'function'
}
export function LowlightPlugin({
name,
lowlight,
defaultLanguage,
}: {
name: string
lowlight: any
defaultLanguage: string | null | undefined
}) {
if (!['highlight', 'highlightAuto', 'listLanguages'].every(api => isFunction(lowlight[api]))) {
throw Error('You should provide an instance of lowlight to use the code-block-lowlight extension')
}
const lowlightPlugin: Plugin<any> = new Plugin({
key: new PluginKey('lowlight'),
state: {
init: (_, { doc }) =>
getDecorations({
doc,
name,
lowlight,
defaultLanguage,
}),
apply: (transaction, decorationSet, oldState, newState) => {
const oldNodeName = oldState.selection.$head.parent.type.name
const newNodeName = newState.selection.$head.parent.type.name
const oldNodes = findChildren(oldState.doc, node => node.type.name === name)
const newNodes = findChildren(newState.doc, node => node.type.name === name)
if (
transaction.docChanged &&
// Apply decorations if:
// selection includes named node,
([oldNodeName, newNodeName].includes(name) ||
// OR transaction adds/removes named node,
newNodes.length !== oldNodes.length ||
// OR transaction has changes that completely encapsulte a node
// (for example, a transaction that affects the entire document).
// Such transactions can happen during collab syncing via y-prosemirror, for example.
transaction.steps.some(step => {
// @ts-ignore
return (
// @ts-ignore
step.from !== undefined &&
// @ts-ignore
step.to !== undefined &&
oldNodes.some(node => {
// @ts-ignore
return (
// @ts-ignore
node.pos >= step.from &&
// @ts-ignore
node.pos + node.node.nodeSize <= step.to
)
})
)
}))
) {
return getDecorations({
doc: transaction.doc,
name,
lowlight,
defaultLanguage,
})
}
return decorationSet.map(transaction.mapping, transaction.doc)
},
},
props: {
decorations(state) {
return lowlightPlugin.getState(state)
},
},
})
return lowlightPlugin
}