@milkdown/exception
Advanced tools
+82
-158
@@ -1,190 +0,114 @@ | ||
| var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => { | ||
| ErrorCode2["docTypeError"] = "docTypeError"; | ||
| ErrorCode2["contextNotFound"] = "contextNotFound"; | ||
| ErrorCode2["timerNotFound"] = "timerNotFound"; | ||
| ErrorCode2["ctxCallOutOfScope"] = "ctxCallOutOfScope"; | ||
| ErrorCode2["createNodeInParserFail"] = "createNodeInParserFail"; | ||
| ErrorCode2["stackOverFlow"] = "stackOverFlow"; | ||
| ErrorCode2["parserMatchError"] = "parserMatchError"; | ||
| ErrorCode2["serializerMatchError"] = "serializerMatchError"; | ||
| ErrorCode2["getAtomFromSchemaFail"] = "getAtomFromSchemaFail"; | ||
| ErrorCode2["expectDomTypeError"] = "expectDomTypeError"; | ||
| ErrorCode2["callCommandBeforeEditorView"] = "callCommandBeforeEditorView"; | ||
| ErrorCode2["missingRootElement"] = "missingRootElement"; | ||
| ErrorCode2["missingNodeInSchema"] = "missingNodeInSchema"; | ||
| ErrorCode2["missingMarkInSchema"] = "missingMarkInSchema"; | ||
| ErrorCode2["ctxNotBind"] = "ctxNotBind"; | ||
| ErrorCode2["missingYjsDoc"] = "missingYjsDoc"; | ||
| return ErrorCode2; | ||
| })(ErrorCode || {}); | ||
| class MilkdownError extends Error { | ||
| constructor(code, message) { | ||
| super(message); | ||
| this.name = "MilkdownError"; | ||
| this.code = code; | ||
| } | ||
| } | ||
| const functionReplacer = (_, value) => typeof value === "function" ? "[Function]" : value; | ||
| const stringify = (x) => JSON.stringify(x, functionReplacer); | ||
| //#region src/code.ts | ||
| var ErrorCode = /* @__PURE__ */ function(ErrorCode) { | ||
| ErrorCode["docTypeError"] = "docTypeError"; | ||
| ErrorCode["contextNotFound"] = "contextNotFound"; | ||
| ErrorCode["timerNotFound"] = "timerNotFound"; | ||
| ErrorCode["ctxCallOutOfScope"] = "ctxCallOutOfScope"; | ||
| ErrorCode["createNodeInParserFail"] = "createNodeInParserFail"; | ||
| ErrorCode["stackOverFlow"] = "stackOverFlow"; | ||
| ErrorCode["parserMatchError"] = "parserMatchError"; | ||
| ErrorCode["serializerMatchError"] = "serializerMatchError"; | ||
| ErrorCode["getAtomFromSchemaFail"] = "getAtomFromSchemaFail"; | ||
| ErrorCode["expectDomTypeError"] = "expectDomTypeError"; | ||
| ErrorCode["callCommandBeforeEditorView"] = "callCommandBeforeEditorView"; | ||
| ErrorCode["missingRootElement"] = "missingRootElement"; | ||
| ErrorCode["missingNodeInSchema"] = "missingNodeInSchema"; | ||
| ErrorCode["missingMarkInSchema"] = "missingMarkInSchema"; | ||
| ErrorCode["ctxNotBind"] = "ctxNotBind"; | ||
| ErrorCode["missingYjsDoc"] = "missingYjsDoc"; | ||
| return ErrorCode; | ||
| }({}); | ||
| //#endregion | ||
| //#region src/error.ts | ||
| var MilkdownError = class extends Error { | ||
| constructor(code, message) { | ||
| super(message); | ||
| this.name = "MilkdownError"; | ||
| this.code = code; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/index.ts | ||
| var functionReplacer = (_, value) => typeof value === "function" ? "[Function]" : value; | ||
| var stringify = (x) => JSON.stringify(x, functionReplacer); | ||
| function docTypeError(type) { | ||
| return new MilkdownError( | ||
| ErrorCode.docTypeError, | ||
| `Doc type error, unsupported type: ${stringify(type)}` | ||
| ); | ||
| return new MilkdownError(ErrorCode.docTypeError, `Doc type error, unsupported type: ${stringify(type)}`); | ||
| } | ||
| function contextNotFound(name) { | ||
| return new MilkdownError( | ||
| ErrorCode.contextNotFound, | ||
| `Context "${name}" not found, do you forget to inject it?` | ||
| ); | ||
| return new MilkdownError(ErrorCode.contextNotFound, `Context "${name}" not found, do you forget to inject it?`); | ||
| } | ||
| function timerNotFound(name) { | ||
| return new MilkdownError( | ||
| ErrorCode.timerNotFound, | ||
| `Timer "${name}" not found, do you forget to record it?` | ||
| ); | ||
| return new MilkdownError(ErrorCode.timerNotFound, `Timer "${name}" not found, do you forget to record it?`); | ||
| } | ||
| function ctxCallOutOfScope() { | ||
| return new MilkdownError( | ||
| ErrorCode.ctxCallOutOfScope, | ||
| "Should not call a context out of the plugin." | ||
| ); | ||
| return new MilkdownError(ErrorCode.ctxCallOutOfScope, "Should not call a context out of the plugin."); | ||
| } | ||
| function createNodeInParserFail(nodeType, attrs, content) { | ||
| const nodeTypeName = "name" in nodeType ? nodeType.name : nodeType; | ||
| const heading = `Cannot create node for ${nodeTypeName}`; | ||
| const serialize = (x) => { | ||
| if (x == null) return "null"; | ||
| if (Array.isArray(x)) { | ||
| return `[${x.map(serialize).join(", ")}]`; | ||
| } | ||
| if (typeof x === "object") { | ||
| if ("toJSON" in x && typeof x.toJSON === "function") { | ||
| return JSON.stringify(x.toJSON()); | ||
| } | ||
| if ("spec" in x) { | ||
| return JSON.stringify(x.spec); | ||
| } | ||
| return JSON.stringify(x); | ||
| } | ||
| if (typeof x === "string" || typeof x === "number" || typeof x === "boolean") { | ||
| return JSON.stringify(x); | ||
| } | ||
| if (typeof x === "function") { | ||
| return `[Function: ${x.name || "anonymous"}]`; | ||
| } | ||
| try { | ||
| return String(x); | ||
| } catch { | ||
| return "[Unserializable]"; | ||
| } | ||
| }; | ||
| const headingMessage = ["[Description]", heading]; | ||
| const attrsMessage = ["[Attributes]", attrs]; | ||
| const contentMessage = [ | ||
| "[Content]", | ||
| (content ?? []).map((node) => { | ||
| if (!node) return "null"; | ||
| if (typeof node === "object" && "type" in node) { | ||
| return `${node}`; | ||
| } | ||
| return serialize(node); | ||
| }) | ||
| ]; | ||
| const messages = [headingMessage, attrsMessage, contentMessage].reduce( | ||
| (acc, [title, value]) => { | ||
| const message = `${title}: ${serialize(value)}.`; | ||
| return acc.concat(message); | ||
| }, | ||
| [] | ||
| ); | ||
| return new MilkdownError( | ||
| ErrorCode.createNodeInParserFail, | ||
| messages.join("\n") | ||
| ); | ||
| const heading = `Cannot create node for ${"name" in nodeType ? nodeType.name : nodeType}`; | ||
| const serialize = (x) => { | ||
| if (x == null) return "null"; | ||
| if (Array.isArray(x)) return `[${x.map(serialize).join(", ")}]`; | ||
| if (typeof x === "object") { | ||
| if ("toJSON" in x && typeof x.toJSON === "function") return JSON.stringify(x.toJSON()); | ||
| if ("spec" in x) return JSON.stringify(x.spec); | ||
| return JSON.stringify(x); | ||
| } | ||
| if (typeof x === "string" || typeof x === "number" || typeof x === "boolean") return JSON.stringify(x); | ||
| if (typeof x === "function") return `[Function: ${x.name || "anonymous"}]`; | ||
| try { | ||
| return String(x); | ||
| } catch { | ||
| return "[Unserializable]"; | ||
| } | ||
| }; | ||
| const messages = [ | ||
| ["[Description]", heading], | ||
| ["[Attributes]", attrs], | ||
| ["[Content]", (content ?? []).map((node) => { | ||
| if (!node) return "null"; | ||
| if (typeof node === "object" && "type" in node) return `${node}`; | ||
| return serialize(node); | ||
| })] | ||
| ].reduce((acc, [title, value]) => { | ||
| const message = `${title}: ${serialize(value)}.`; | ||
| return acc.concat(message); | ||
| }, []); | ||
| return new MilkdownError(ErrorCode.createNodeInParserFail, messages.join("\n")); | ||
| } | ||
| function stackOverFlow() { | ||
| return new MilkdownError( | ||
| ErrorCode.stackOverFlow, | ||
| "Stack over flow, cannot pop on an empty stack." | ||
| ); | ||
| return new MilkdownError(ErrorCode.stackOverFlow, "Stack over flow, cannot pop on an empty stack."); | ||
| } | ||
| function parserMatchError(node) { | ||
| return new MilkdownError( | ||
| ErrorCode.parserMatchError, | ||
| `Cannot match target parser for node: ${stringify(node)}.` | ||
| ); | ||
| return new MilkdownError(ErrorCode.parserMatchError, `Cannot match target parser for node: ${stringify(node)}.`); | ||
| } | ||
| function serializerMatchError(node) { | ||
| return new MilkdownError( | ||
| ErrorCode.serializerMatchError, | ||
| `Cannot match target serializer for node: ${stringify(node)}.` | ||
| ); | ||
| return new MilkdownError(ErrorCode.serializerMatchError, `Cannot match target serializer for node: ${stringify(node)}.`); | ||
| } | ||
| function getAtomFromSchemaFail(type, name) { | ||
| return new MilkdownError( | ||
| ErrorCode.getAtomFromSchemaFail, | ||
| `Cannot get ${type}: ${name} from schema.` | ||
| ); | ||
| return new MilkdownError(ErrorCode.getAtomFromSchemaFail, `Cannot get ${type}: ${name} from schema.`); | ||
| } | ||
| function expectDomTypeError(node) { | ||
| return new MilkdownError( | ||
| ErrorCode.expectDomTypeError, | ||
| `Expect to be a dom, but get: ${stringify(node)}.` | ||
| ); | ||
| return new MilkdownError(ErrorCode.expectDomTypeError, `Expect to be a dom, but get: ${stringify(node)}.`); | ||
| } | ||
| function callCommandBeforeEditorView() { | ||
| return new MilkdownError( | ||
| ErrorCode.callCommandBeforeEditorView, | ||
| "You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized" | ||
| ); | ||
| return new MilkdownError(ErrorCode.callCommandBeforeEditorView, "You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized"); | ||
| } | ||
| function missingRootElement() { | ||
| return new MilkdownError( | ||
| ErrorCode.missingRootElement, | ||
| "Missing root element, milkdown cannot find root element of the editor." | ||
| ); | ||
| return new MilkdownError(ErrorCode.missingRootElement, "Missing root element, milkdown cannot find root element of the editor."); | ||
| } | ||
| function missingNodeInSchema(name) { | ||
| return new MilkdownError( | ||
| ErrorCode.missingNodeInSchema, | ||
| `Missing node in schema, milkdown cannot find "${name}" in schema.` | ||
| ); | ||
| return new MilkdownError(ErrorCode.missingNodeInSchema, `Missing node in schema, milkdown cannot find "${name}" in schema.`); | ||
| } | ||
| function missingMarkInSchema(name) { | ||
| return new MilkdownError( | ||
| ErrorCode.missingMarkInSchema, | ||
| `Missing mark in schema, milkdown cannot find "${name}" in schema.` | ||
| ); | ||
| return new MilkdownError(ErrorCode.missingMarkInSchema, `Missing mark in schema, milkdown cannot find "${name}" in schema.`); | ||
| } | ||
| function ctxNotBind() { | ||
| return new MilkdownError( | ||
| ErrorCode.ctxNotBind, | ||
| "Context not bind, please make sure the plugin has been initialized." | ||
| ); | ||
| return new MilkdownError(ErrorCode.ctxNotBind, "Context not bind, please make sure the plugin has been initialized."); | ||
| } | ||
| function missingYjsDoc() { | ||
| return new MilkdownError( | ||
| ErrorCode.missingYjsDoc, | ||
| "Missing yjs doc, please make sure you have bind one." | ||
| ); | ||
| return new MilkdownError(ErrorCode.missingYjsDoc, "Missing yjs doc, please make sure you have bind one."); | ||
| } | ||
| export { | ||
| callCommandBeforeEditorView, | ||
| contextNotFound, | ||
| createNodeInParserFail, | ||
| ctxCallOutOfScope, | ||
| ctxNotBind, | ||
| docTypeError, | ||
| expectDomTypeError, | ||
| getAtomFromSchemaFail, | ||
| missingMarkInSchema, | ||
| missingNodeInSchema, | ||
| missingRootElement, | ||
| missingYjsDoc, | ||
| parserMatchError, | ||
| serializerMatchError, | ||
| stackOverFlow, | ||
| timerNotFound | ||
| }; | ||
| //# sourceMappingURL=index.js.map | ||
| //#endregion | ||
| export { callCommandBeforeEditorView, contextNotFound, createNodeInParserFail, ctxCallOutOfScope, ctxNotBind, docTypeError, expectDomTypeError, getAtomFromSchemaFail, missingMarkInSchema, missingNodeInSchema, missingRootElement, missingYjsDoc, parserMatchError, serializerMatchError, stackOverFlow, timerNotFound }; | ||
| //# sourceMappingURL=index.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sources":["../src/code.ts","../src/error.ts","../src/index.ts"],"sourcesContent":["export enum ErrorCode {\n docTypeError = 'docTypeError',\n contextNotFound = 'contextNotFound',\n timerNotFound = 'timerNotFound',\n ctxCallOutOfScope = 'ctxCallOutOfScope',\n createNodeInParserFail = 'createNodeInParserFail',\n stackOverFlow = 'stackOverFlow',\n parserMatchError = 'parserMatchError',\n serializerMatchError = 'serializerMatchError',\n getAtomFromSchemaFail = 'getAtomFromSchemaFail',\n expectDomTypeError = 'expectDomTypeError',\n callCommandBeforeEditorView = 'callCommandBeforeEditorView',\n missingRootElement = 'missingRootElement',\n missingNodeInSchema = 'missingNodeInSchema',\n missingMarkInSchema = 'missingMarkInSchema',\n\n // collab plugin\n ctxNotBind = 'ctxNotBind',\n missingYjsDoc = 'missingYjsDoc',\n}\n","import type { ErrorCode } from './code'\n\nexport class MilkdownError extends Error {\n public code: string\n constructor(code: ErrorCode, message: string) {\n super(message)\n this.name = 'MilkdownError'\n this.code = code\n }\n}\n","import { ErrorCode } from './code'\nimport { MilkdownError } from './error'\n\nconst functionReplacer = (_: string, value: unknown) =>\n typeof value === 'function' ? '[Function]' : value\n\nconst stringify = (x: unknown): string => JSON.stringify(x, functionReplacer)\n\nexport function docTypeError(type: unknown) {\n return new MilkdownError(\n ErrorCode.docTypeError,\n `Doc type error, unsupported type: ${stringify(type)}`\n )\n}\n\nexport function contextNotFound(name: string) {\n return new MilkdownError(\n ErrorCode.contextNotFound,\n `Context \"${name}\" not found, do you forget to inject it?`\n )\n}\n\nexport function timerNotFound(name: string) {\n return new MilkdownError(\n ErrorCode.timerNotFound,\n `Timer \"${name}\" not found, do you forget to record it?`\n )\n}\n\nexport function ctxCallOutOfScope() {\n return new MilkdownError(\n ErrorCode.ctxCallOutOfScope,\n 'Should not call a context out of the plugin.'\n )\n}\n\nexport function createNodeInParserFail(\n nodeType: object,\n attrs?: unknown,\n content?: unknown[]\n) {\n const nodeTypeName = 'name' in nodeType ? nodeType.name : nodeType\n const heading = `Cannot create node for ${nodeTypeName}`\n const serialize = (x: unknown): string => {\n if (x == null) return 'null'\n\n if (Array.isArray(x)) {\n return `[${x.map(serialize).join(', ')}]`\n }\n\n if (typeof x === 'object') {\n if ('toJSON' in x && typeof (x as any).toJSON === 'function') {\n return JSON.stringify((x as any).toJSON())\n }\n\n if ('spec' in x) {\n return JSON.stringify((x as any).spec)\n }\n\n return JSON.stringify(x)\n }\n\n if (\n typeof x === 'string' ||\n typeof x === 'number' ||\n typeof x === 'boolean'\n ) {\n return JSON.stringify(x)\n }\n\n if (typeof x === 'function') {\n return `[Function: ${(x as Function).name || 'anonymous'}]`\n }\n\n try {\n return String(x)\n } catch {\n return '[Unserializable]'\n }\n }\n\n const headingMessage = ['[Description]', heading] as const\n const attrsMessage = ['[Attributes]', attrs] as const\n const contentMessage = [\n '[Content]',\n (content ?? []).map((node) => {\n if (!node) return 'null'\n\n if (typeof node === 'object' && 'type' in node) {\n return `${node}`\n }\n\n return serialize(node)\n }),\n ] as const\n\n const messages = [headingMessage, attrsMessage, contentMessage].reduce(\n (acc, [title, value]) => {\n const message = `${title}: ${serialize(value)}.`\n return acc.concat(message)\n },\n [] as string[]\n )\n\n return new MilkdownError(\n ErrorCode.createNodeInParserFail,\n messages.join('\\n')\n )\n}\n\nexport function stackOverFlow() {\n return new MilkdownError(\n ErrorCode.stackOverFlow,\n 'Stack over flow, cannot pop on an empty stack.'\n )\n}\n\nexport function parserMatchError(node: unknown) {\n return new MilkdownError(\n ErrorCode.parserMatchError,\n `Cannot match target parser for node: ${stringify(node)}.`\n )\n}\n\nexport function serializerMatchError(node: unknown) {\n return new MilkdownError(\n ErrorCode.serializerMatchError,\n `Cannot match target serializer for node: ${stringify(node)}.`\n )\n}\n\nexport function getAtomFromSchemaFail(type: 'mark' | 'node', name: string) {\n return new MilkdownError(\n ErrorCode.getAtomFromSchemaFail,\n `Cannot get ${type}: ${name} from schema.`\n )\n}\n\nexport function expectDomTypeError(node: unknown) {\n return new MilkdownError(\n ErrorCode.expectDomTypeError,\n `Expect to be a dom, but get: ${stringify(node)}.`\n )\n}\n\nexport function callCommandBeforeEditorView() {\n return new MilkdownError(\n ErrorCode.callCommandBeforeEditorView,\n \"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized\"\n )\n}\n\nexport function missingRootElement() {\n return new MilkdownError(\n ErrorCode.missingRootElement,\n 'Missing root element, milkdown cannot find root element of the editor.'\n )\n}\n\nexport function missingNodeInSchema(name: string) {\n return new MilkdownError(\n ErrorCode.missingNodeInSchema,\n `Missing node in schema, milkdown cannot find \"${name}\" in schema.`\n )\n}\n\nexport function missingMarkInSchema(name: string) {\n return new MilkdownError(\n ErrorCode.missingMarkInSchema,\n `Missing mark in schema, milkdown cannot find \"${name}\" in schema.`\n )\n}\n\nexport function ctxNotBind() {\n return new MilkdownError(\n ErrorCode.ctxNotBind,\n 'Context not bind, please make sure the plugin has been initialized.'\n )\n}\n\nexport function missingYjsDoc() {\n return new MilkdownError(\n ErrorCode.missingYjsDoc,\n 'Missing yjs doc, please make sure you have bind one.'\n )\n}\n"],"names":["ErrorCode"],"mappings":"AAAO,IAAK,8BAAAA,eAAL;AACLA,aAAA,cAAA,IAAe;AACfA,aAAA,iBAAA,IAAkB;AAClBA,aAAA,eAAA,IAAgB;AAChBA,aAAA,mBAAA,IAAoB;AACpBA,aAAA,wBAAA,IAAyB;AACzBA,aAAA,eAAA,IAAgB;AAChBA,aAAA,kBAAA,IAAmB;AACnBA,aAAA,sBAAA,IAAuB;AACvBA,aAAA,uBAAA,IAAwB;AACxBA,aAAA,oBAAA,IAAqB;AACrBA,aAAA,6BAAA,IAA8B;AAC9BA,aAAA,oBAAA,IAAqB;AACrBA,aAAA,qBAAA,IAAsB;AACtBA,aAAA,qBAAA,IAAsB;AAGtBA,aAAA,YAAA,IAAa;AACbA,aAAA,eAAA,IAAgB;AAlBN,SAAAA;AAAA,GAAA,aAAA,CAAA,CAAA;ACEL,MAAM,sBAAsB,MAAM;AAAA,EAEvC,YAAY,MAAiB,SAAiB;AAC5C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;ACNA,MAAM,mBAAmB,CAAC,GAAW,UACnC,OAAO,UAAU,aAAa,eAAe;AAE/C,MAAM,YAAY,CAAC,MAAuB,KAAK,UAAU,GAAG,gBAAgB;AAErE,SAAS,aAAa,MAAe;AAC1C,SAAO,IAAI;AAAA,IACT,UAAU;AAAA,IACV,qCAAqC,UAAU,IAAI,CAAC;AAAA,EAAA;AAExD;AAEO,SAAS,gBAAgB,MAAc;AAC5C,SAAO,IAAI;AAAA,IACT,UAAU;AAAA,IACV,YAAY,IAAI;AAAA,EAAA;AAEpB;AAEO,SAAS,cAAc,MAAc;AAC1C,SAAO,IA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AAI;AAAA,IACT,UAAU;AAAA,IACV,iDAAiD,IAAI;AAAA,EAAA;AAEzD;AAEO,SAAS,aAAa;AAC3B,SAAO,IAAI;AAAA,IACT,UAAU;AAAA,IACV;AAAA,EAAA;AAEJ;AAEO,SAAS,gBAAgB;AAC9B,SAAO,IAAI;AAAA,IACT,UAAU;AAAA,IACV;AAAA,EAAA;AAEJ;"} | ||
| {"version":3,"file":"index.js","names":[],"sources":["../src/code.ts","../src/error.ts","../src/index.ts"],"sourcesContent":["export enum ErrorCode {\n docTypeError = 'docTypeError',\n contextNotFound = 'contextNotFound',\n timerNotFound = 'timerNotFound',\n ctxCallOutOfScope = 'ctxCallOutOfScope',\n createNodeInParserFail = 'createNodeInParserFail',\n stackOverFlow = 'stackOverFlow',\n parserMatchError = 'parserMatchError',\n serializerMatchError = 'serializerMatchError',\n getAtomFromSchemaFail = 'getAtomFromSchemaFail',\n expectDomTypeError = 'expectDomTypeError',\n callCommandBeforeEditorView = 'callCommandBeforeEditorView',\n missingRootElement = 'missingRootElement',\n missingNodeInSchema = 'missingNodeInSchema',\n missingMarkInSchema = 'missingMarkInSchema',\n\n // collab plugin\n ctxNotBind = 'ctxNotBind',\n missingYjsDoc = 'missingYjsDoc',\n}\n","import type { ErrorCode } from './code'\n\nexport class MilkdownError extends Error {\n public code: string\n constructor(code: ErrorCode, message: string) {\n super(message)\n this.name = 'MilkdownError'\n this.code = code\n }\n}\n","import { ErrorCode } from './code'\nimport { MilkdownError } from './error'\n\nconst functionReplacer = (_: string, value: unknown) =>\n typeof value === 'function' ? '[Function]' : value\n\nconst stringify = (x: unknown): string => JSON.stringify(x, functionReplacer)\n\nexport function docTypeError(type: unknown) {\n return new MilkdownError(\n ErrorCode.docTypeError,\n `Doc type error, unsupported type: ${stringify(type)}`\n )\n}\n\nexport function contextNotFound(name: string) {\n return new MilkdownError(\n ErrorCode.contextNotFound,\n `Context \"${name}\" not found, do you forget to inject it?`\n )\n}\n\nexport function timerNotFound(name: string) {\n return new MilkdownError(\n ErrorCode.timerNotFound,\n `Timer \"${name}\" not found, do you forget to record it?`\n )\n}\n\nexport function ctxCallOutOfScope() {\n return new MilkdownError(\n ErrorCode.ctxCallOutOfScope,\n 'Should not call a context out of the plugin.'\n )\n}\n\nexport function createNodeInParserFail(\n nodeType: object,\n attrs?: unknown,\n content?: unknown[]\n) {\n const nodeTypeName = 'name' in nodeType ? nodeType.name : nodeType\n const heading = `Cannot create node for ${nodeTypeName}`\n const serialize = (x: unknown): string => {\n if (x == null) return 'null'\n\n if (Array.isArray(x)) {\n return `[${x.map(serialize).join(', ')}]`\n }\n\n if (typeof x === 'object') {\n if ('toJSON' in x && typeof (x as any).toJSON === 'function') {\n return JSON.stringify((x as any).toJSON())\n }\n\n if ('spec' in x) {\n return JSON.stringify((x as any).spec)\n }\n\n return JSON.stringify(x)\n }\n\n if (\n typeof x === 'string' ||\n typeof x === 'number' ||\n typeof x === 'boolean'\n ) {\n return JSON.stringify(x)\n }\n\n if (typeof x === 'function') {\n return `[Function: ${(x as Function).name || 'anonymous'}]`\n }\n\n try {\n return String(x)\n } catch {\n return '[Unserializable]'\n }\n }\n\n const headingMessage = ['[Description]', heading] as const\n const attrsMessage = ['[Attributes]', attrs] as const\n const contentMessage = [\n '[Content]',\n (content ?? []).map((node) => {\n if (!node) return 'null'\n\n if (typeof node === 'object' && 'type' in node) {\n return `${node}`\n }\n\n return serialize(node)\n }),\n ] as const\n\n const messages = [headingMessage, attrsMessage, contentMessage].reduce(\n (acc, [title, value]) => {\n const message = `${title}: ${serialize(value)}.`\n return acc.concat(message)\n },\n [] as string[]\n )\n\n return new MilkdownError(\n ErrorCode.createNodeInParserFail,\n messages.join('\\n')\n )\n}\n\nexport function stackOverFlow() {\n return new MilkdownError(\n ErrorCode.stackOverFlow,\n 'Stack over flow, cannot pop on an empty stack.'\n )\n}\n\nexport function parserMatchError(node: unknown) {\n return new MilkdownError(\n ErrorCode.parserMatchError,\n `Cannot match target parser for node: ${stringify(node)}.`\n )\n}\n\nexport function serializerMatchError(node: unknown) {\n return new MilkdownError(\n ErrorCode.serializerMatchError,\n `Cannot match target serializer for node: ${stringify(node)}.`\n )\n}\n\nexport function getAtomFromSchemaFail(type: 'mark' | 'node', name: string) {\n return new MilkdownError(\n ErrorCode.getAtomFromSchemaFail,\n `Cannot get ${type}: ${name} from schema.`\n )\n}\n\nexport function expectDomTypeError(node: unknown) {\n return new MilkdownError(\n ErrorCode.expectDomTypeError,\n `Expect to be a dom, but get: ${stringify(node)}.`\n )\n}\n\nexport function callCommandBeforeEditorView() {\n return new MilkdownError(\n ErrorCode.callCommandBeforeEditorView,\n \"You're trying to call a command before editor view initialized, make sure to get commandManager from ctx after editor view has been initialized\"\n )\n}\n\nexport function missingRootElement() {\n return new MilkdownError(\n ErrorCode.missingRootElement,\n 'Missing root element, milkdown cannot find root element of the editor.'\n )\n}\n\nexport function missingNodeInSchema(name: string) {\n return new MilkdownError(\n ErrorCode.missingNodeInSchema,\n `Missing node in schema, milkdown cannot find \"${name}\" in schema.`\n )\n}\n\nexport function missingMarkInSchema(name: string) {\n return new MilkdownError(\n ErrorCode.missingMarkInSchema,\n `Missing mark in schema, milkdown cannot find \"${name}\" in schema.`\n )\n}\n\nexport function ctxNotBind() {\n return new MilkdownError(\n ErrorCode.ctxNotBind,\n 'Context not bind, please make sure the plugin has been initialized.'\n )\n}\n\nexport function missingYjsDoc() {\n return new MilkdownError(\n ErrorCode.missingYjsDoc,\n 'Missing yjs doc, please make sure you have bind one.'\n )\n}\n"],"mappings":";AAAA,IAAY,YAAL,yBAAA,WAAA;AACL,WAAA,kBAAA;AACA,WAAA,qBAAA;AACA,WAAA,mBAAA;AACA,WAAA,uBAAA;AACA,WAAA,4BAAA;AACA,WAAA,mBAAA;AACA,WAAA,sBAAA;AACA,WAAA,0BAAA;AACA,WAAA,2BAAA;AACA,WAAA,wBAAA;AACA,WAAA,iCAAA;AACA,WAAA,wBAAA;AACA,WAAA,yBAAA;AACA,WAAA,yBAAA;AAGA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AAO,IAAI,cACT,UAAU,YACV,sEACD;;AAGH,SAAgB,gBAAgB;AAC9B,QAAO,IAAI,cACT,UAAU,eACV,uDACD"} |
+1
-1
| { | ||
| "name": "@milkdown/exception", | ||
| "type": "module", | ||
| "version": "7.19.0", | ||
| "version": "7.19.1", | ||
| "license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
64261
-1.88%337
-18.6%