Make Parchment an ESM package

This commit is contained in:
Zihua Li 2024-03-11 23:53:08 +08:00
parent c69ce72917
commit dbf42a12b1
43 changed files with 1118 additions and 314 deletions

View File

@ -6,11 +6,12 @@
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"plugin:require-extensions/recommended"
],
"ignorePatterns": ["vite.config.ts", "scripts"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "require-extensions"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",

View File

@ -31,7 +31,7 @@ jobs:
node-version: 20
- run: npm ci
- run: ./scripts/release.js --version ${{ github.event.inputs.version }} ${{ github.event.inputs.dry-run == 'true' && '--dry-run' || '' }}
- run: ./scripts/release.cjs --version ${{ github.event.inputs.version }} ${{ github.event.inputs.dry-run == 'true' && '--dry-run' || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

1107
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,16 +4,17 @@
"description": "A document model for rich text editors",
"author": "Jason Chen <jhchen7@gmail.com>",
"homepage": "http://quilljs.com/docs/parchment",
"main": "./dist/parchment.umd.js",
"module": "./dist/parchment.mjs",
"main": "./dist/parchment.js",
"types": "./dist/parchment.d.ts",
"type": "module",
"files": [
"tsconfig.json",
"dist",
"src"
],
"devDependencies": {
"@microsoft/api-extractor": "^7.36.3",
"@arethetypeswrong/cli": "^0.15.1",
"@microsoft/api-extractor": "^7.42.3",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
@ -22,6 +23,7 @@
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.9.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-require-extensions": "^0.1.3",
"playwright": "^1.36.2",
"prettier": "^3.0.0",
"typescript": "^5.1.6",
@ -41,7 +43,8 @@
"prepare": "npm run build",
"test": "npm run test:unit && npm run test:types",
"test:unit": "vitest",
"test:types": "vitest typecheck"
"test:types": "vitest typecheck",
"test:pkg": "attw $(npm pack)"
},
"bugs": {
"url": "https://github.com/quilljs/parchment/issues"

View File

@ -122,6 +122,8 @@ exec(`npm version ${version} -f`);
const pushCommand = `git push origin ${process.env.GITHUB_REF_NAME} --follow-tags`;
if (dryRun) {
console.log(`Skipping: "${pushCommand}" in dry-run mode`);
} else if (version === 'experimental') {
console.log(`Skipping: "${pushCommand}" for experimental version`);
} else {
exec(pushCommand);
}

View File

@ -1,4 +1,4 @@
import Scope from '../scope';
import Scope from '../scope.js';
export interface AttributorOptions {
scope?: Scope;

View File

@ -1,4 +1,4 @@
import Attributor from './attributor';
import Attributor from './attributor.js';
function match(node: HTMLElement, prefix: string): string[] {
const className = node.getAttribute('class') || '';

View File

@ -1,9 +1,9 @@
import type { Formattable } from '../blot/abstract/blot';
import Registry from '../registry';
import Scope from '../scope';
import Attributor from './attributor';
import ClassAttributor from './class';
import StyleAttributor from './style';
import type { Formattable } from '../blot/abstract/blot.js';
import Registry from '../registry.js';
import Scope from '../scope.js';
import Attributor from './attributor.js';
import ClassAttributor from './class.js';
import StyleAttributor from './style.js';
class AttributorStore {
private attributes: { [key: string]: Attributor } = {};

View File

@ -1,4 +1,4 @@
import Attributor from './attributor';
import Attributor from './attributor.js';
function camelize(name: string): string {
const parts = name.split('-');

View File

@ -1,7 +1,7 @@
import type LinkedList from '../../collection/linked-list';
import type LinkedNode from '../../collection/linked-node';
import type { RegistryDefinition } from '../../registry';
import Scope from '../../scope';
import type LinkedList from '../../collection/linked-list.js';
import type LinkedNode from '../../collection/linked-node.js';
import type { RegistryDefinition } from '../../registry.js';
import Scope from '../../scope.js';
export interface BlotConstructor {
blotName: string;

View File

@ -1,6 +1,6 @@
import Scope from '../../scope';
import BlockBlot from '../block';
import ParentBlot from './parent';
import Scope from '../../scope.js';
import BlockBlot from '../block.js';
import ParentBlot from './parent.js';
class ContainerBlot extends ParentBlot {
public static blotName = 'container';

View File

@ -1,6 +1,6 @@
import Scope from '../../scope';
import type { Leaf } from './blot';
import ShadowBlot from './shadow';
import Scope from '../../scope.js';
import type { Leaf } from './blot.js';
import ShadowBlot from './shadow.js';
class LeafBlot extends ShadowBlot implements Leaf {
public static scope = Scope.INLINE_BLOT;

View File

@ -1,8 +1,8 @@
import LinkedList from '../../collection/linked-list';
import ParchmentError from '../../error';
import Scope from '../../scope';
import type { Blot, BlotConstructor, Parent, Root } from './blot';
import ShadowBlot from './shadow';
import LinkedList from '../../collection/linked-list.js';
import ParchmentError from '../../error.js';
import Scope from '../../scope.js';
import type { Blot, BlotConstructor, Parent, Root } from './blot.js';
import ShadowBlot from './shadow.js';
function makeAttachedBlot(node: Node, scroll: Root): Blot {
const found = scroll.find(node);

View File

@ -1,7 +1,13 @@
import ParchmentError from '../../error';
import Registry from '../../registry';
import Scope from '../../scope';
import type { Blot, BlotConstructor, Formattable, Parent, Root } from './blot';
import ParchmentError from '../../error.js';
import Registry from '../../registry.js';
import Scope from '../../scope.js';
import type {
Blot,
BlotConstructor,
Formattable,
Parent,
Root,
} from './blot.js';
class ShadowBlot implements Blot {
public static blotName = 'abstract';

View File

@ -1,10 +1,15 @@
import Attributor from '../attributor/attributor';
import AttributorStore from '../attributor/store';
import Scope from '../scope';
import type { Blot, BlotConstructor, Formattable, Root } from './abstract/blot';
import LeafBlot from './abstract/leaf';
import ParentBlot from './abstract/parent';
import InlineBlot from './inline';
import Attributor from '../attributor/attributor.js';
import AttributorStore from '../attributor/store.js';
import Scope from '../scope.js';
import type {
Blot,
BlotConstructor,
Formattable,
Root,
} from './abstract/blot.js';
import LeafBlot from './abstract/leaf.js';
import ParentBlot from './abstract/parent.js';
import InlineBlot from './inline.js';
class BlockBlot extends ParentBlot implements Formattable {
public static blotName = 'block';

View File

@ -1,5 +1,5 @@
import type { Formattable, Root } from './abstract/blot';
import LeafBlot from './abstract/leaf';
import type { Formattable, Root } from './abstract/blot.js';
import LeafBlot from './abstract/leaf.js';
class EmbedBlot extends LeafBlot implements Formattable {
public static formats(_domNode: HTMLElement, _scroll: Root): any {

View File

@ -1,15 +1,15 @@
import Attributor from '../attributor/attributor';
import AttributorStore from '../attributor/store';
import Scope from '../scope';
import Attributor from '../attributor/attributor.js';
import AttributorStore from '../attributor/store.js';
import Scope from '../scope.js';
import type {
Blot,
BlotConstructor,
Formattable,
Parent,
Root,
} from './abstract/blot';
import LeafBlot from './abstract/leaf';
import ParentBlot from './abstract/parent';
} from './abstract/blot.js';
import LeafBlot from './abstract/leaf.js';
import ParentBlot from './abstract/parent.js';
// Shallow object comparison
function isEqual(

View File

@ -1,9 +1,9 @@
import Registry, { type RegistryDefinition } from '../registry';
import Scope from '../scope';
import type { Blot, BlotConstructor, Root } from './abstract/blot';
import ContainerBlot from './abstract/container';
import ParentBlot from './abstract/parent';
import BlockBlot from './block';
import Registry, { type RegistryDefinition } from '../registry.js';
import Scope from '../scope.js';
import type { Blot, BlotConstructor, Root } from './abstract/blot.js';
import ContainerBlot from './abstract/container.js';
import ParentBlot from './abstract/parent.js';
import BlockBlot from './block.js';
const OBSERVER_CONFIG = {
attributes: true,

View File

@ -1,6 +1,6 @@
import Scope from '../scope';
import type { Blot, Leaf, Root } from './abstract/blot';
import LeafBlot from './abstract/leaf';
import Scope from '../scope.js';
import type { Blot, Leaf, Root } from './abstract/blot.js';
import LeafBlot from './abstract/leaf.js';
class TextBlot extends LeafBlot implements Leaf {
public static readonly blotName = 'text';

View File

@ -1,4 +1,4 @@
import type LinkedNode from './linked-node';
import type LinkedNode from './linked-node.js';
class LinkedList<T extends LinkedNode> {
public head: T | null;

View File

@ -1,20 +1,20 @@
import ContainerBlot from './blot/abstract/container';
import LeafBlot from './blot/abstract/leaf';
import ParentBlot from './blot/abstract/parent';
import ContainerBlot from './blot/abstract/container.js';
import LeafBlot from './blot/abstract/leaf.js';
import ParentBlot from './blot/abstract/parent.js';
import BlockBlot from './blot/block';
import EmbedBlot from './blot/embed';
import InlineBlot from './blot/inline';
import ScrollBlot from './blot/scroll';
import TextBlot from './blot/text';
import BlockBlot from './blot/block.js';
import EmbedBlot from './blot/embed.js';
import InlineBlot from './blot/inline.js';
import ScrollBlot from './blot/scroll.js';
import TextBlot from './blot/text.js';
import Attributor from './attributor/attributor';
import ClassAttributor from './attributor/class';
import AttributorStore from './attributor/store';
import StyleAttributor from './attributor/style';
import Attributor from './attributor/attributor.js';
import ClassAttributor from './attributor/class.js';
import AttributorStore from './attributor/store.js';
import StyleAttributor from './attributor/style.js';
import Registry from './registry';
import Scope from './scope';
import Registry from './registry.js';
import Scope from './scope.js';
export {
ParentBlot,
@ -33,11 +33,11 @@ export {
Scope,
};
export type { RegistryInterface, RegistryDefinition } from './registry';
export type { default as ShadowBlot } from './blot/abstract/shadow';
export type { default as LinkedList } from './collection/linked-list';
export type { default as LinkedNode } from './collection/linked-node';
export type { AttributorOptions } from './attributor/attributor';
export type { RegistryInterface, RegistryDefinition } from './registry.js';
export type { default as ShadowBlot } from './blot/abstract/shadow.js';
export type { default as LinkedList } from './collection/linked-list.js';
export type { default as LinkedNode } from './collection/linked-node.js';
export type { AttributorOptions } from './attributor/attributor.js';
export type {
Blot,
BlotConstructor,
@ -45,4 +45,4 @@ export type {
Leaf,
Parent,
Root,
} from './blot/abstract/blot';
} from './blot/abstract/blot.js';

View File

@ -1,11 +1,11 @@
import Attributor from './attributor/attributor';
import Attributor from './attributor/attributor.js';
import {
type Blot,
type BlotConstructor,
type Root,
} from './blot/abstract/blot';
import ParchmentError from './error';
import Scope from './scope';
} from './blot/abstract/blot.js';
import ParchmentError from './error.js';
import Scope from './scope.js';
export type RegistryDefinition = Attributor | BlotConstructor;

View File

@ -1,7 +1,7 @@
import Attributor from '../../../src/attributor/attributor';
import ClassAttributor from '../../../src/attributor/class';
import StyleAttributor from '../../../src/attributor/style';
import Scope from '../../../src/scope';
import Attributor from '../../../src/attributor/attributor.js';
import ClassAttributor from '../../../src/attributor/class.js';
import StyleAttributor from '../../../src/attributor/style.js';
import Scope from '../../../src/scope.js';
export const Color = new StyleAttributor('color', 'color', {
scope: Scope.INLINE_ATTRIBUTE,

View File

@ -1,4 +1,4 @@
import BlockBlot from '../../../src/blot/block';
import BlockBlot from '../../../src/blot/block.js';
export class HeaderBlot extends BlockBlot {
static readonly blotName = 'header';

View File

@ -1,4 +1,4 @@
import EmbedBlot from '../../../src/blot/embed';
import EmbedBlot from '../../../src/blot/embed.js';
export class BreakBlot extends EmbedBlot {
static readonly blotName = 'break';

View File

@ -1,5 +1,5 @@
import EmbedBlot from '../../../src/blot/embed';
import Scope from '../../../src/scope';
import EmbedBlot from '../../../src/blot/embed.js';
import Scope from '../../../src/scope.js';
export class ImageBlot extends EmbedBlot {
declare domNode: HTMLImageElement;

View File

@ -1,4 +1,4 @@
import InlineBlot from '../../../src/blot/inline';
import InlineBlot from '../../../src/blot/inline.js';
export class AuthorBlot extends InlineBlot {
static readonly blotName = 'author';

View File

@ -1,5 +1,5 @@
import ContainerBlot from '../../../src/blot/abstract/container';
import BlockBlot from '../../../src/blot/block';
import ContainerBlot from '../../../src/blot/abstract/container.js';
import BlockBlot from '../../../src/blot/block.js';
export class ListItem extends BlockBlot {
static readonly blotName = 'list';

View File

@ -7,13 +7,13 @@ import {
InlineBlot,
TextBlot,
type BlotConstructor,
} from '../src/parchment';
} from '../src/parchment.js';
import {
AuthorBlot,
BoldBlot,
ItalicBlot,
ScriptBlot,
} from './__helpers__/registry/inline';
} from './__helpers__/registry/inline.js';
import {
Align,
Color,
@ -21,11 +21,11 @@ import {
Id,
Indent,
Size,
} from './__helpers__/registry/attributor';
import { HeaderBlot } from './__helpers__/registry/block';
import { ImageBlot, VideoBlot } from './__helpers__/registry/embed';
import { ListContainer, ListItem } from './__helpers__/registry/list';
import { BreakBlot } from './__helpers__/registry/break';
} from './__helpers__/registry/attributor.js';
import { HeaderBlot } from './__helpers__/registry/block.js';
import { ImageBlot, VideoBlot } from './__helpers__/registry/embed.js';
import { ListContainer, ListItem } from './__helpers__/registry/list.js';
import { BreakBlot } from './__helpers__/registry/break.js';
const getTestRegistry = () => {
const reg = new Registry();

View File

@ -1,5 +1,5 @@
import { assertType } from 'vitest';
import { ClassAttributor } from '../../src/parchment';
import { ClassAttributor } from '../../src/parchment.js';
class IndentAttributor extends ClassAttributor {
value(node: HTMLElement) {

View File

@ -5,7 +5,7 @@ import {
Registry,
ScrollBlot,
ParentBlot,
} from '../../src/parchment';
} from '../../src/parchment.js';
const registry = new Registry();
const root = document.createElement('div');

View File

@ -4,10 +4,10 @@ import type {
BlockBlot,
Formattable,
InlineBlot,
} from '../../src/parchment';
import type { HeaderBlot } from '../__helpers__/registry/block';
import type { BoldBlot } from '../__helpers__/registry/inline';
import { setupContextBeforeEach } from '../setup';
} from '../../src/parchment.js';
import type { HeaderBlot } from '../__helpers__/registry/block.js';
import type { BoldBlot } from '../__helpers__/registry/inline.js';
import { setupContextBeforeEach } from '../setup.js';
describe('Attributor', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
import type { BlockBlot } from '../../src/parchment';
import type { HeaderBlot } from '../__helpers__/registry/block';
import { setupContextBeforeEach } from '../setup';
import type { BlockBlot } from '../../src/parchment.js';
import type { HeaderBlot } from '../__helpers__/registry/block.js';
import { setupContextBeforeEach } from '../setup.js';
describe('Block', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,8 +1,8 @@
import { describe, it, expect } from 'vitest';
import type { BlockBlot, Parent } from '../../src/parchment';
import Registry from '../../src/registry';
import type { ItalicBlot } from '../__helpers__/registry/inline';
import { setupContextBeforeEach } from '../setup';
import type { BlockBlot, Parent } from '../../src/parchment.js';
import Registry from '../../src/registry.js';
import type { ItalicBlot } from '../__helpers__/registry/inline.js';
import { setupContextBeforeEach } from '../setup.js';
describe('Blot', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { setupContextBeforeEach } from '../setup';
import { setupContextBeforeEach } from '../setup.js';
describe('Container', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
import type { BlockBlot, InlineBlot } from '../../src/parchment';
import type { ImageBlot } from '../__helpers__/registry/embed';
import { setupContextBeforeEach } from '../setup';
import type { BlockBlot, InlineBlot } from '../../src/parchment.js';
import type { ImageBlot } from '../__helpers__/registry/embed.js';
import { setupContextBeforeEach } from '../setup.js';
describe('EmbedBlot', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,11 +1,11 @@
import { describe, it, expect } from 'vitest';
import type { BlockBlot, Leaf } from '../../src/parchment';
import type { BlockBlot, Leaf } from '../../src/parchment.js';
import type {
BoldBlot,
ItalicBlot,
ScriptBlot,
} from '../__helpers__/registry/inline';
import { setupContextBeforeEach } from '../setup';
} from '../__helpers__/registry/inline.js';
import { setupContextBeforeEach } from '../setup.js';
describe('InlineBlot', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,17 +1,17 @@
import { vi, describe, it, expect, beforeEach } from 'vitest';
import LeafBlot from '../../src/blot/abstract/leaf';
import ShadowBlot from '../../src/blot/abstract/shadow';
import LeafBlot from '../../src/blot/abstract/leaf.js';
import ShadowBlot from '../../src/blot/abstract/shadow.js';
import type {
BlockBlot,
Blot,
InlineBlot,
TextBlot,
} from '../../src/parchment';
import { HeaderBlot } from '../__helpers__/registry/block';
import { ImageBlot } from '../__helpers__/registry/embed';
import type { ItalicBlot } from '../__helpers__/registry/inline';
import { BoldBlot } from '../__helpers__/registry/inline';
import { setupContextBeforeEach } from '../setup';
} from '../../src/parchment.js';
import { HeaderBlot } from '../__helpers__/registry/block.js';
import { ImageBlot } from '../__helpers__/registry/embed.js';
import type { ItalicBlot } from '../__helpers__/registry/inline.js';
import { BoldBlot } from '../__helpers__/registry/inline.js';
import { setupContextBeforeEach } from '../setup.js';
describe('Lifecycle', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,6 +1,6 @@
import { vi, describe, it, expect, beforeEach } from 'vitest';
import LinkedList from '../../src/collection/linked-list';
import type { LinkedNode } from '../../src/parchment';
import LinkedList from '../../src/collection/linked-list.js';
import type { LinkedNode } from '../../src/parchment.js';
interface StrNode extends LinkedNode {
str: string;

View File

@ -1,16 +1,16 @@
import { describe, it, expect, beforeEach } from 'vitest';
import LeafBlot from '../../src/blot/abstract/leaf';
import ParentBlot from '../../src/blot/abstract/parent';
import ShadowBlot from '../../src/blot/abstract/shadow';
import EmbedBlot from '../../src/blot/embed';
import LeafBlot from '../../src/blot/abstract/leaf.js';
import ParentBlot from '../../src/blot/abstract/parent.js';
import ShadowBlot from '../../src/blot/abstract/shadow.js';
import EmbedBlot from '../../src/blot/embed.js';
import { VideoBlot } from '../__helpers__/registry/embed';
import { ItalicBlot } from '../__helpers__/registry/inline';
import { VideoBlot } from '../__helpers__/registry/embed.js';
import { ItalicBlot } from '../__helpers__/registry/inline.js';
import Registry from '../../src/registry';
import TextBlot from '../../src/blot/text';
import { setupContextBeforeEach } from '../setup';
import type { BlockBlot, Blot } from '../../src/parchment';
import Registry from '../../src/registry.js';
import TextBlot from '../../src/blot/text.js';
import { setupContextBeforeEach } from '../setup.js';
import type { BlockBlot, Blot } from '../../src/parchment.js';
describe('Parent', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,18 +1,18 @@
import { describe, it, expect } from 'vitest';
import Scope from '../../src/scope';
import { HeaderBlot } from '../__helpers__/registry/block';
import Scope from '../../src/scope.js';
import { HeaderBlot } from '../__helpers__/registry/block.js';
import {
AuthorBlot,
BoldBlot,
ItalicBlot,
} from '../__helpers__/registry/inline';
} from '../__helpers__/registry/inline.js';
import ShadowBlot from '../../src/blot/abstract/shadow';
import InlineBlot from '../../src/blot/inline';
import BlockBlot from '../../src/blot/block';
import type { Parent } from '../../src/parchment';
import ShadowBlot from '../../src/blot/abstract/shadow.js';
import InlineBlot from '../../src/blot/inline.js';
import BlockBlot from '../../src/blot/block.js';
import type { Parent } from '../../src/parchment.js';
import { setupContextBeforeEach } from '../setup';
import { setupContextBeforeEach } from '../setup.js';
describe('ctx.registry', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,5 +1,5 @@
import { vi, describe, it, expect, beforeEach } from 'vitest';
import { setupContextBeforeEach } from '../setup';
import { setupContextBeforeEach } from '../setup.js';
describe('scroll', function () {
const ctx = setupContextBeforeEach();

View File

@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
import TextBlot from '../../src/blot/text';
import type { BlockBlot, InlineBlot } from '../../src/parchment';
import { setupContextBeforeEach } from '../setup';
import TextBlot from '../../src/blot/text.js';
import type { BlockBlot, InlineBlot } from '../../src/parchment.js';
import { setupContextBeforeEach } from '../setup.js';
describe('TextBlot', function () {
const ctx = setupContextBeforeEach();