Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-flat-list

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-flat-list - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

55

dist/index.d.ts

@@ -1,8 +0,6 @@

import { NodeType, ParseRule, DOMSerializer, Schema, DOMOutputSpec as DOMOutputSpec$1 } from '@remirror/pm/model';
import { Command } from '@remirror/pm/state';
import { NodeType, Attrs, Schema, ParseRule, NodeSpec, DOMOutputSpec, DOMSerializer } from '@remirror/pm/model';
import { Command, Plugin } from '@remirror/pm/state';
import { EditorView, NodeType as NodeType$1, ProsemirrorNode, Fragment } from '@remirror/pm';
import { NodeType as NodeType$2 } from '@remirror/pm/dist-types/model';
import { InputRule } from '@remirror/pm/inputrules';
import { NodeViewConstructor } from '@remirror/pm/view';
import { ApplySchemaAttributes, NodeSpecOverride, DOMOutputSpec } from '@remirror/core';

@@ -24,5 +22,26 @@ declare function createDedentListCommand(listType: NodeType): Command;

}
/**
* All the literal types
*/
declare type Literal = string | number | boolean | undefined | null | void | object;
/**
* A JSON representation of a prosemirror Mark.
*/
interface ObjectMark {
type: string;
attrs?: Record<string, Literal>;
}
interface ProsemirrorNodeJSON {
type: string;
marks?: Array<ObjectMark | string>;
text?: string;
content?: ProsemirrorNodeJSON[];
attrs?: Record<string, Literal>;
}
declare function createListInputRules(listType: NodeType$2): InputRule[];
declare function wrappingListInputRule<T extends Attrs = ListAttributes>(re: RegExp, listType: NodeType, getAttrs: T | ((matches: RegExpMatchArray) => T)): InputRule;
declare function createListInputRules(listType: NodeType): InputRule[];
declare function migrateDocJSON(docJSON: ProsemirrorNodeJSON): ProsemirrorNodeJSON;
/**

@@ -34,9 +53,20 @@ * A simple node view that is used to render the list node. It ensures that the

declare function createParseDomRules(extra: ApplySchemaAttributes, override: NodeSpecOverride): readonly ParseRule[];
declare function createListPlugin(schema: Schema, listType: NodeType): Plugin;
declare function listToDOM(node: ProsemirrorNode, nativeList: boolean, extra?: ApplySchemaAttributes): DOMOutputSpec;
declare function createParseDomRules(): readonly ParseRule[];
declare function createListSpec(): NodeSpec;
declare function listToDOM(node: ProsemirrorNode, nativeList: boolean): DOMOutputSpec;
/**
* Wrap the giving command function so that it always returns `true`. This is
* useful when we want pressing `Tab` and `Shift-Tab` won't blur the editor even
* if the keybinding command returns `false`
*/
declare function alwaysTrue<T extends (...args: any[]) => boolean>(func: T): T;
declare class ListDOMSerializer extends DOMSerializer {
static nodesFromSchema(schema: Schema): {
[node: string]: (node: ProsemirrorNode) => DOMOutputSpec$1;
[node: string]: (node: ProsemirrorNode) => DOMOutputSpec;
};

@@ -48,9 +78,2 @@ serializeFragment(fragment: Fragment, options?: {

/**
* Wrap the giving command function so that it always returns `true`. This is
* useful when we want pressing `Tab` and `Shift-Tab` won't blur the editor even
* if the keybinding command returns `false`
*/
declare function alwaysTrue<T extends (...args: any[]) => boolean>(func: T): T;
export { ListAttributes, ListDOMSerializer, ListType, alwaysTrue, createDedentListCommand, createIndentListCommand, createListInputRules, createListNodeView, createParseDomRules, createSplitListCommand, handleListMarkerMouseDown, listToDOM };
export { ListAttributes, ListDOMSerializer, ListType, alwaysTrue, createDedentListCommand, createIndentListCommand, createListInputRules, createListNodeView, createListPlugin, createListSpec, createParseDomRules, createSplitListCommand, handleListMarkerMouseDown, listToDOM, migrateDocJSON, wrappingListInputRule };

@@ -508,5 +508,6 @@ // src/commands/dedent-list.ts

function createListInputRules(listType) {
const bulletRegexp = /^\s?([*+-])\s$/;
const bulletRegexp = /^\s?([*-])\s$/;
const orderedRegexp = /^\s?(\d+)\.\s$/;
const taskRegexp = /^\s?\[([\sXx]?)]\s$/;
const toggleRegexp = /^\s?>>\s$/;
return [

@@ -518,6 +519,52 @@ wrappingListInputRule(bulletRegexp, listType, { type: "bullet" }),

checked: ["x", "X"].includes(match[1])
}))
})),
wrappingListInputRule(toggleRegexp, listType, { type: "toggle" })
];
}
// src/migrate.ts
function migrateNodes(nodes) {
var _a, _b, _c;
const content = [];
for (const node of nodes) {
if (node.type === "bullet_list" || node.type === "bulletList") {
for (const child of (_a = node.content) != null ? _a : []) {
content.push(migrateNode(child, { type: "bullet" }));
}
} else if (node.type === "ordered_list" || node.type === "orderedList") {
for (const child of (_b = node.content) != null ? _b : []) {
content.push(migrateNode(child, { type: "ordered" }));
}
} else if (node.type === "task_list" || node.type === "taskList") {
for (const child of (_c = node.content) != null ? _c : []) {
content.push(migrateNode(child, { type: "task" }));
}
} else {
content.push(node);
}
}
return content;
}
function migrateNode(node, attrs) {
if (node.type === "list_item" || node.type === "listItem" || node.type === "taskListItem") {
return {
...node,
type: "list",
attrs: {
...node.attrs,
type: "bullet",
...attrs
},
content: node.content ? migrateNodes(node.content) : void 0
};
}
return {
...node,
content: node.content ? migrateNodes(node.content) : void 0
};
}
function migrateDocJSON(docJSON) {
return migrateNode(docJSON);
}
// src/node-view.ts

@@ -546,78 +593,10 @@ import { DOMSerializer } from "@remirror/pm/model";

// src/utils/parse-integer.ts
function parseInteger(attr) {
if (attr == null)
return null;
const int = Number.parseInt(attr, 10);
if (Number.isInteger(int))
return int;
return null;
}
// src/plugin.ts
import { Plugin } from "@remirror/pm/state";
// src/schema/parse-dom.ts
function createParseDomRules(extra, override) {
var _a;
return [
{
tag: "div[data-list]",
getAttrs: (element) => {
if (typeof element === "string") {
return {};
}
return {
type: element.getAttribute("data-list-type") || "bullet",
order: parseInteger(element.getAttribute("data-list-order")),
checked: element.hasAttribute("data-list-checked"),
collapsed: element.hasAttribute("data-list-collapsed")
};
}
},
{
tag: "ul > li",
getAttrs: (element) => {
if (typeof element !== "string") {
const checkbox = element.firstChild;
if (checkbox && checkbox.nodeName === "INPUT" && checkbox.getAttribute("type") === "checkbox") {
return {
type: "task",
checked: checkbox.hasAttribute("checked"),
...extra.parse(element)
};
}
if (element.hasAttribute("data-task-list-item") || element.getAttribute("data-list-type") === "task") {
return {
type: "task",
checked: element.hasAttribute("data-checked"),
...extra.parse(element)
};
}
if (element.hasAttribute("data-toggle-list-item") || element.getAttribute("data-list-type") === "toggle") {
return {
type: "toggle",
collapsed: element.hasAttribute("data-list-collapsed"),
...extra.parse(element)
};
}
}
return {
type: "bullet",
...extra.parse(element)
};
}
},
{
tag: "ol > li",
getAttrs: (element) => {
return {
type: "ordered",
...extra.parse(element)
};
}
},
...(_a = override.parseDOM) != null ? _a : []
];
}
// src/utils/list-serializer.ts
import { DOMSerializer as DOMSerializer2 } from "@remirror/pm/model";
// src/schema/to-dom.ts
function listToDOM(node, nativeList, extra) {
function listToDOM(node, nativeList) {
var _a;

@@ -650,4 +629,3 @@ const attrs = node.attrs;

"data-list-collapsed": markerType === "toggle" && attrs.collapsed ? "" : void 0,
"data-list-disabled": markerType === "toggle" && node.childCount < 2 ? "" : void 0,
...extra == null ? void 0 : extra.dom(node)
"data-list-disabled": markerType === "toggle" && node.childCount < 2 ? "" : void 0
};

@@ -677,3 +655,2 @@ const contentContainer = ["div", { class: "list-content" }, 0];

// src/utils/list-serializer.ts
import { DOMSerializer as DOMSerializer2 } from "@remirror/pm/model";
var ListDOMSerializer = class extends DOMSerializer2 {

@@ -706,2 +683,112 @@ static nodesFromSchema(schema) {

// src/plugin.ts
function createListPlugin(schema, listType) {
return new Plugin({
props: {
handleDOMEvents: {
mousedown: (view, event) => {
return handleListMarkerMouseDown(view, event, listType);
}
},
clipboardSerializer: new ListDOMSerializer(
ListDOMSerializer.nodesFromSchema(schema),
ListDOMSerializer.marksFromSchema(schema)
)
}
});
}
// src/utils/parse-integer.ts
function parseInteger(attr) {
if (attr == null)
return null;
const int = Number.parseInt(attr, 10);
if (Number.isInteger(int))
return int;
return null;
}
// src/schema/parse-dom.ts
function createParseDomRules() {
return [
{
tag: "div[data-list]",
getAttrs: (element) => {
if (typeof element === "string") {
return {};
}
return {
type: element.getAttribute("data-list-type") || "bullet",
order: parseInteger(element.getAttribute("data-list-order")),
checked: element.hasAttribute("data-list-checked"),
collapsed: element.hasAttribute("data-list-collapsed")
};
}
},
{
tag: "ul > li",
getAttrs: (element) => {
if (typeof element !== "string") {
const checkbox = element.firstChild;
if (checkbox && checkbox.nodeName === "INPUT" && checkbox.getAttribute("type") === "checkbox") {
return {
type: "task",
checked: checkbox.hasAttribute("checked")
};
}
if (element.hasAttribute("data-task-list-item") || element.getAttribute("data-list-type") === "task") {
return {
type: "task",
checked: element.hasAttribute("data-checked")
};
}
if (element.hasAttribute("data-toggle-list-item") || element.getAttribute("data-list-type") === "toggle") {
return {
type: "toggle",
collapsed: element.hasAttribute("data-list-collapsed")
};
}
}
return {
type: "bullet"
};
}
},
{
tag: "ol > li",
getAttrs: (_element) => {
return {
type: "ordered"
};
}
}
];
}
// src/schema/spec.ts
function createListSpec() {
return {
content: "block+",
defining: true,
attrs: {
type: {
default: "bullet"
},
counter: {
default: null
},
checked: {
default: false
},
collapsed: {
default: false
}
},
toDOM: (node) => {
return listToDOM(node, false);
},
parseDOM: createParseDomRules()
};
}
// src/utils/always-true.ts

@@ -721,6 +808,10 @@ function alwaysTrue(func) {

createListNodeView,
createListPlugin,
createListSpec,
createParseDomRules,
createSplitListCommand,
handleListMarkerMouseDown,
listToDOM
listToDOM,
migrateDocJSON,
wrappingListInputRule
};
{
"name": "prosemirror-flat-list",
"type": "module",
"version": "0.0.5",
"version": "0.0.6",
"description": "",

@@ -6,0 +6,0 @@ "author": "ocavue <ocavue@gmail.com>",

# prosemirror-flat-list
[![NPM version](https://img.shields.io/npm/v/prosemirror-flat-list?color=a1b858&label=)](https://www.npmjs.com/package/prosemirror-flat-list)
## Install

@@ -4,0 +6,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc