@prosekit/extensions 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -235,7 +235,7 @@ function createLazyParser(highlighterOptions) {
235
235
  *
236
236
  * @public
237
237
  */
238
- function defineCodeBlockShiki({ themes = ["one-dark-pro"], langs = ["text"],...rest } = {}) {
238
+ function defineCodeBlockShiki({ themes = ["one-dark-pro"], langs = ["text"], ...rest } = {}) {
239
239
  return defineCodeBlockHighlight({ parser: createLazyParser({
240
240
  themes,
241
241
  langs,
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-code-block.js","names":["existCodeBlock: Command","loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined","createOrGetHighlighter","parser: Parser | undefined"],"sources":["../src/code-block/code-block-commands.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts","../src/code-block/code-block-highlight.ts","../src/code-block/shiki-highlighter.ts","../src/code-block/shiki-parser.ts","../src/code-block/code-block-shiki.ts"],"sourcesContent":["import {\n defineCommands,\n insertNode,\n setBlockType,\n setNodeAttrs,\n toggleNode,\n type Extension,\n} from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * @internal\n */\nexport type CodeBlockCommandsExtension = Extension<{\n Commands: {\n setCodeBlock: [attrs?: CodeBlockAttrs]\n insertCodeBlock: [attrs?: CodeBlockAttrs]\n toggleCodeBlock: [attrs?: CodeBlockAttrs]\n setCodeBlockAttrs: [attrs: CodeBlockAttrs]\n }\n}>\n\n/**\n * Adds commands for working with `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockCommands(): CodeBlockCommandsExtension {\n return defineCommands({\n setCodeBlock: (attrs?: CodeBlockAttrs) => {\n return setBlockType({ type: 'codeBlock', attrs })\n },\n insertCodeBlock: (attrs?: CodeBlockAttrs) => {\n return insertNode({ type: 'codeBlock', attrs })\n },\n toggleCodeBlock: (attrs?: CodeBlockAttrs) => {\n return toggleNode({ type: 'codeBlock', attrs })\n },\n setCodeBlockAttrs: (attrs: CodeBlockAttrs) => {\n return setNodeAttrs({ type: 'codeBlock', attrs })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockEnterRule } from '../enter-rule'\nimport { defineTextBlockInputRule } from '../input-rule'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * Adds input rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^```(\\S*)\\s$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\n/**\n * Adds enter rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockEnterRule(): PlainExtension {\n return defineTextBlockEnterRule({\n regex: /^```(\\S*)$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\nfunction getAttrs(match: RegExpMatchArray): CodeBlockAttrs {\n return { language: match[1] || '' }\n}\n","import {\n defaultBlockAt,\n defineKeymap,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n TextSelection,\n type Command,\n} from '@prosekit/pm/state'\n\n/**\n * Defines the keymap for code blocks.\n */\nexport function defineCodeBlockKeymap(): PlainExtension {\n return defineKeymap({\n Enter: existCodeBlock,\n })\n}\n\n/**\n * Exit a code block and insert a default block below if the cursor is at the\n * end of the code block and the code block is ended with two new lines.\n */\nconst existCodeBlock: Command = (state, dispatch) => {\n if (!state.selection.empty) {\n return false\n }\n\n const { $head } = state.selection\n const parent = $head.parent\n if (\n parent.isTextblock\n && parent.type.spec.code\n && $head.parentOffset === parent.content.size\n && parent.textContent.endsWith('\\n\\n')\n ) {\n const grandParent = $head.node(-1)\n const insertIndex = $head.indexAfter(-1)\n const type = defaultBlockAt(grandParent.contentMatchAt(insertIndex))\n\n if (!type || !grandParent.canReplaceWith(insertIndex, insertIndex, type)) {\n return false\n }\n\n if (dispatch) {\n const { tr } = state\n tr.delete($head.pos - 2, $head.pos)\n const pos = tr.selection.$head.after()\n const node = type.createAndFill()\n if (node) {\n tr.replaceWith(pos, pos, node)\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1))\n dispatch(tr.scrollIntoView())\n }\n }\n\n return true\n }\n\n return false\n}\n","import {\n defineNodeSpec,\n type Extension,\n} from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * @internal\n */\nexport type CodeBlockSpecExtension = Extension<{\n Nodes: {\n codeBlock: CodeBlockAttrs\n }\n}>\n\n/**\n * Defines the `codeBlock` node spec.\n *\n * @public\n */\nexport function defineCodeBlockSpec(): CodeBlockSpecExtension {\n return defineNodeSpec({\n name: 'codeBlock',\n content: 'text*',\n group: 'block',\n code: true,\n defining: true,\n marks: '',\n attrs: { language: { default: '', validate: 'string' } },\n parseDOM: [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n getAttrs: (node): CodeBlockAttrs => {\n const language = extractLanguageFromElement(node)\n || extractLanguageFromElement(node.querySelector('code'))\n return { language }\n },\n },\n ],\n toDOM(node) {\n const { language } = node.attrs as CodeBlockAttrs\n return [\n 'pre',\n { 'data-language': language || undefined },\n // `class: language-${language}` is used by remark-rehype to highlight the code block\n ['code', { class: language ? `language-${language}` : undefined }, 0],\n ]\n },\n })\n}\n\nfunction extractLanguageFromElement(element: HTMLElement | null | undefined): string {\n if (!element) {\n return ''\n }\n\n const attr = element.getAttribute('data-language')\n if (attr) {\n return attr\n }\n\n const className = element.className\n const match = className.match(/language-(\\w+)/)\n if (match) {\n return match[1]\n }\n\n return ''\n}\n","import {\n union,\n type Union,\n} from '@prosekit/core'\n\nimport {\n defineCodeBlockCommands,\n type CodeBlockCommandsExtension,\n} from './code-block-commands'\nimport {\n defineCodeBlockEnterRule,\n defineCodeBlockInputRule,\n} from './code-block-input-rule'\nimport { defineCodeBlockKeymap } from './code-block-keymap'\nimport {\n defineCodeBlockSpec,\n type CodeBlockSpecExtension,\n} from './code-block-spec'\n\n/**\n * @internal\n */\nexport type CodeBlockExtension = Union<\n [CodeBlockSpecExtension, CodeBlockCommandsExtension]\n>\n\n/**\n * Adds `codeBlock` nodes to the editor. This includes the following extensions:\n *\n * - {@link defineCodeBlockSpec}\n * - {@link defineCodeBlockInputRule}\n * - {@link defineCodeBlockEnterRule}\n * - {@link defineCodeBlockKeymap}\n * - {@link defineCodeBlockCommands}.\n *\n * @public\n */\nexport function defineCodeBlock(): CodeBlockExtension {\n return union(\n defineCodeBlockSpec(),\n defineCodeBlockInputRule(),\n defineCodeBlockEnterRule(),\n defineCodeBlockKeymap(),\n defineCodeBlockCommands(),\n )\n}\n","import {\n definePlugin,\n type Extension,\n} from '@prosekit/core'\nimport {\n createHighlightPlugin,\n type Parser,\n} from 'prosemirror-highlight'\n\n/**\n * @public\n *\n * An alias for the `Parser` type from the `prosemirror-highlight` package.\n */\nexport type HighlightParser = Parser\n\n/**\n * @public\n */\nexport type CodeBlockHighlightOptions = {\n parser: HighlightParser\n}\n\n/**\n * Adds syntax highlighting to code blocks. This function requires a `Parser`\n * instance from the `prosemirror-highlight` package. See the\n * [documentation](https://github.com/ocavue/prosemirror-highlight) for more\n * information.\n *\n * @param options\n *\n * @public\n */\nexport function defineCodeBlockHighlight({\n parser,\n}: CodeBlockHighlightOptions): Extension {\n return definePlugin(\n createHighlightPlugin({ parser }),\n )\n}\n","import type {\n HighlighterOptions,\n HighlighterResult,\n} from './shiki-highlighter-chunk'\n\nlet loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined\n\nasync function load() {\n const { createOrGetHighlighter } = await import('./shiki-highlighter-chunk')\n loaded = createOrGetHighlighter\n}\n\nexport function createOrGetHighlighter(\n options: HighlighterOptions,\n): HighlighterResult {\n if (!loaded) {\n return { promise: load() }\n }\n return loaded(options)\n}\n\nexport type { HighlighterOptions }\n","import type { Parser } from 'prosemirror-highlight'\nimport { createParser } from 'prosemirror-highlight/shiki'\n\nimport type { ShikiBundledLanguage } from './shiki-bundle'\nimport {\n createOrGetHighlighter,\n type HighlighterOptions,\n} from './shiki-highlighter'\n\n/**\n * @internal\n */\nexport function createLazyParser(\n highlighterOptions: HighlighterOptions,\n): Parser {\n let parser: Parser | undefined\n\n return function lazyParser(options) {\n const language = (options.language || '') as ShikiBundledLanguage\n const { highlighter, promise } = createOrGetHighlighter({\n ...highlighterOptions,\n langs: [language],\n })\n\n if (!highlighter) {\n return promise\n }\n\n if (!parser) {\n parser = createParser(highlighter, {\n theme: highlighterOptions.themes[0],\n })\n }\n return parser(options)\n }\n}\n","import type { Extension } from '@prosekit/core'\nimport type { SpecialLanguage } from 'shiki'\n\nimport { defineCodeBlockHighlight } from './code-block-highlight'\nimport type {\n ShikiBundledLanguage,\n ShikiBundledTheme,\n} from './shiki-bundle'\nimport type { ShikiHighlighterOptions } from './shiki-highlighter-chunk'\nimport { createLazyParser } from './shiki-parser'\n\n/**\n * The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {\n /**\n * A list of Shiki themes to pre-load. The first theme in the list will be\n * used to render the code block.\n *\n * @default ['one-dark-pro']\n */\n themes?: ShikiBundledTheme[]\n\n /**\n * A list of Shiki languages to pre-load.\n *\n * @default ['text']\n */\n langs?: (ShikiBundledLanguage | SpecialLanguage)[]\n\n /**\n * The RegExp engine to use. By default, the JavaScript engine is used.\n */\n engine?: ShikiHighlighterOptions['engine']\n}\n\n/**\n * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.\n *\n * It will set two CSS variables on the code block elements:\n *\n * - `--prosemirror-highlight`: sets text color\n * - `--prosemirror-highlight-bg`: sets background color\n *\n * @param options - The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport function defineCodeBlockShiki({\n themes = ['one-dark-pro'],\n langs = ['text'],\n ...rest\n}: CodeBlockShikiOptions = {}): Extension {\n const parser = createLazyParser({ themes, langs,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ACL,sBAAsB,EAAE,QAAQ,CAAC,CAClC;;;;;ACjCH,IAAIC;AAEJ,eAAe,OAAO;CACpB,MAAM,EAAE,qDAA2B,MAAM,OAAO;AAChD,UAASC;;AAGX,SAAgB,uBACd,SACmB;AACnB,KAAI,CAAC,OACH,QAAO,EAAE,SAAS,MAAM,EAAE;AAE5B,QAAO,OAAO,QAAQ;;;;;;;;ACNxB,SAAgB,iBACd,oBACQ;CACR,IAAIC;AAEJ,QAAO,SAAS,WAAW,SAAS;EAClC,MAAM,WAAY,QAAQ,YAAY;EACtC,MAAM,EAAE,aAAa,YAAY,uBAAuB;GACtD,GAAG;GACH,OAAO,CAAC,SAAS;GAClB,CAAC;AAEF,MAAI,CAAC,YACH,QAAO;AAGT,MAAI,CAAC,OACH,UAAS,aAAa,aAAa,EACjC,OAAO,mBAAmB,OAAO,IAClC,CAAC;AAEJ,SAAO,OAAO,QAAQ;;;;;;;;;;;;;;;;;;ACiB1B,SAAgB,qBAAqB,EACnC,SAAS,CAAC,eAAe,EACzB,QAAQ,CAAC,OAAO,CAChB,GAAG,SACsB,EAAE,EAAa;AAExC,QAAO,yBAAyB,EAAE,QADnB,iBAAiB;EAAE;EAAQ;EAAO,GAAG;EAAM,CAAC,EACjB,CAAC"}
1
+ {"version":3,"file":"prosekit-extensions-code-block.js","names":["existCodeBlock: Command","loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined","createOrGetHighlighter","parser: Parser | undefined"],"sources":["../src/code-block/code-block-commands.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts","../src/code-block/code-block-highlight.ts","../src/code-block/shiki-highlighter.ts","../src/code-block/shiki-parser.ts","../src/code-block/code-block-shiki.ts"],"sourcesContent":["import {\n defineCommands,\n insertNode,\n setBlockType,\n setNodeAttrs,\n toggleNode,\n type Extension,\n} from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * @internal\n */\nexport type CodeBlockCommandsExtension = Extension<{\n Commands: {\n setCodeBlock: [attrs?: CodeBlockAttrs]\n insertCodeBlock: [attrs?: CodeBlockAttrs]\n toggleCodeBlock: [attrs?: CodeBlockAttrs]\n setCodeBlockAttrs: [attrs: CodeBlockAttrs]\n }\n}>\n\n/**\n * Adds commands for working with `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockCommands(): CodeBlockCommandsExtension {\n return defineCommands({\n setCodeBlock: (attrs?: CodeBlockAttrs) => {\n return setBlockType({ type: 'codeBlock', attrs })\n },\n insertCodeBlock: (attrs?: CodeBlockAttrs) => {\n return insertNode({ type: 'codeBlock', attrs })\n },\n toggleCodeBlock: (attrs?: CodeBlockAttrs) => {\n return toggleNode({ type: 'codeBlock', attrs })\n },\n setCodeBlockAttrs: (attrs: CodeBlockAttrs) => {\n return setNodeAttrs({ type: 'codeBlock', attrs })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockEnterRule } from '../enter-rule'\nimport { defineTextBlockInputRule } from '../input-rule'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * Adds input rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^```(\\S*)\\s$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\n/**\n * Adds enter rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockEnterRule(): PlainExtension {\n return defineTextBlockEnterRule({\n regex: /^```(\\S*)$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\nfunction getAttrs(match: RegExpMatchArray): CodeBlockAttrs {\n return { language: match[1] || '' }\n}\n","import {\n defaultBlockAt,\n defineKeymap,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n TextSelection,\n type Command,\n} from '@prosekit/pm/state'\n\n/**\n * Defines the keymap for code blocks.\n */\nexport function defineCodeBlockKeymap(): PlainExtension {\n return defineKeymap({\n Enter: existCodeBlock,\n })\n}\n\n/**\n * Exit a code block and insert a default block below if the cursor is at the\n * end of the code block and the code block is ended with two new lines.\n */\nconst existCodeBlock: Command = (state, dispatch) => {\n if (!state.selection.empty) {\n return false\n }\n\n const { $head } = state.selection\n const parent = $head.parent\n if (\n parent.isTextblock\n && parent.type.spec.code\n && $head.parentOffset === parent.content.size\n && parent.textContent.endsWith('\\n\\n')\n ) {\n const grandParent = $head.node(-1)\n const insertIndex = $head.indexAfter(-1)\n const type = defaultBlockAt(grandParent.contentMatchAt(insertIndex))\n\n if (!type || !grandParent.canReplaceWith(insertIndex, insertIndex, type)) {\n return false\n }\n\n if (dispatch) {\n const { tr } = state\n tr.delete($head.pos - 2, $head.pos)\n const pos = tr.selection.$head.after()\n const node = type.createAndFill()\n if (node) {\n tr.replaceWith(pos, pos, node)\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1))\n dispatch(tr.scrollIntoView())\n }\n }\n\n return true\n }\n\n return false\n}\n","import {\n defineNodeSpec,\n type Extension,\n} from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * @internal\n */\nexport type CodeBlockSpecExtension = Extension<{\n Nodes: {\n codeBlock: CodeBlockAttrs\n }\n}>\n\n/**\n * Defines the `codeBlock` node spec.\n *\n * @public\n */\nexport function defineCodeBlockSpec(): CodeBlockSpecExtension {\n return defineNodeSpec({\n name: 'codeBlock',\n content: 'text*',\n group: 'block',\n code: true,\n defining: true,\n marks: '',\n attrs: { language: { default: '', validate: 'string' } },\n parseDOM: [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n getAttrs: (node): CodeBlockAttrs => {\n const language = extractLanguageFromElement(node)\n || extractLanguageFromElement(node.querySelector('code'))\n return { language }\n },\n },\n ],\n toDOM(node) {\n const { language } = node.attrs as CodeBlockAttrs\n return [\n 'pre',\n { 'data-language': language || undefined },\n // `class: language-${language}` is used by remark-rehype to highlight the code block\n ['code', { class: language ? `language-${language}` : undefined }, 0],\n ]\n },\n })\n}\n\nfunction extractLanguageFromElement(element: HTMLElement | null | undefined): string {\n if (!element) {\n return ''\n }\n\n const attr = element.getAttribute('data-language')\n if (attr) {\n return attr\n }\n\n const className = element.className\n const match = className.match(/language-(\\w+)/)\n if (match) {\n return match[1]\n }\n\n return ''\n}\n","import {\n union,\n type Union,\n} from '@prosekit/core'\n\nimport {\n defineCodeBlockCommands,\n type CodeBlockCommandsExtension,\n} from './code-block-commands'\nimport {\n defineCodeBlockEnterRule,\n defineCodeBlockInputRule,\n} from './code-block-input-rule'\nimport { defineCodeBlockKeymap } from './code-block-keymap'\nimport {\n defineCodeBlockSpec,\n type CodeBlockSpecExtension,\n} from './code-block-spec'\n\n/**\n * @internal\n */\nexport type CodeBlockExtension = Union<\n [CodeBlockSpecExtension, CodeBlockCommandsExtension]\n>\n\n/**\n * Adds `codeBlock` nodes to the editor. This includes the following extensions:\n *\n * - {@link defineCodeBlockSpec}\n * - {@link defineCodeBlockInputRule}\n * - {@link defineCodeBlockEnterRule}\n * - {@link defineCodeBlockKeymap}\n * - {@link defineCodeBlockCommands}.\n *\n * @public\n */\nexport function defineCodeBlock(): CodeBlockExtension {\n return union(\n defineCodeBlockSpec(),\n defineCodeBlockInputRule(),\n defineCodeBlockEnterRule(),\n defineCodeBlockKeymap(),\n defineCodeBlockCommands(),\n )\n}\n","import {\n definePlugin,\n type Extension,\n} from '@prosekit/core'\nimport {\n createHighlightPlugin,\n type Parser,\n} from 'prosemirror-highlight'\n\n/**\n * @public\n *\n * An alias for the `Parser` type from the `prosemirror-highlight` package.\n */\nexport type HighlightParser = Parser\n\n/**\n * @public\n */\nexport type CodeBlockHighlightOptions = {\n parser: HighlightParser\n}\n\n/**\n * Adds syntax highlighting to code blocks. This function requires a `Parser`\n * instance from the `prosemirror-highlight` package. See the\n * [documentation](https://github.com/ocavue/prosemirror-highlight) for more\n * information.\n *\n * @param options\n *\n * @public\n */\nexport function defineCodeBlockHighlight({\n parser,\n}: CodeBlockHighlightOptions): Extension {\n return definePlugin(\n createHighlightPlugin({ parser }),\n )\n}\n","import type {\n HighlighterOptions,\n HighlighterResult,\n} from './shiki-highlighter-chunk'\n\nlet loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined\n\nasync function load() {\n const { createOrGetHighlighter } = await import('./shiki-highlighter-chunk')\n loaded = createOrGetHighlighter\n}\n\nexport function createOrGetHighlighter(\n options: HighlighterOptions,\n): HighlighterResult {\n if (!loaded) {\n return { promise: load() }\n }\n return loaded(options)\n}\n\nexport type { HighlighterOptions }\n","import type { Parser } from 'prosemirror-highlight'\nimport { createParser } from 'prosemirror-highlight/shiki'\n\nimport type { ShikiBundledLanguage } from './shiki-bundle'\nimport {\n createOrGetHighlighter,\n type HighlighterOptions,\n} from './shiki-highlighter'\n\n/**\n * @internal\n */\nexport function createLazyParser(\n highlighterOptions: HighlighterOptions,\n): Parser {\n let parser: Parser | undefined\n\n return function lazyParser(options) {\n const language = (options.language || '') as ShikiBundledLanguage\n const { highlighter, promise } = createOrGetHighlighter({\n ...highlighterOptions,\n langs: [language],\n })\n\n if (!highlighter) {\n return promise\n }\n\n if (!parser) {\n parser = createParser(highlighter, {\n theme: highlighterOptions.themes[0],\n })\n }\n return parser(options)\n }\n}\n","import type { Extension } from '@prosekit/core'\nimport type { SpecialLanguage } from 'shiki'\n\nimport { defineCodeBlockHighlight } from './code-block-highlight'\nimport type {\n ShikiBundledLanguage,\n ShikiBundledTheme,\n} from './shiki-bundle'\nimport type { ShikiHighlighterOptions } from './shiki-highlighter-chunk'\nimport { createLazyParser } from './shiki-parser'\n\n/**\n * The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {\n /**\n * A list of Shiki themes to pre-load. The first theme in the list will be\n * used to render the code block.\n *\n * @default ['one-dark-pro']\n */\n themes?: ShikiBundledTheme[]\n\n /**\n * A list of Shiki languages to pre-load.\n *\n * @default ['text']\n */\n langs?: (ShikiBundledLanguage | SpecialLanguage)[]\n\n /**\n * The RegExp engine to use. By default, the JavaScript engine is used.\n */\n engine?: ShikiHighlighterOptions['engine']\n}\n\n/**\n * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.\n *\n * It will set two CSS variables on the code block elements:\n *\n * - `--prosemirror-highlight`: sets text color\n * - `--prosemirror-highlight-bg`: sets background color\n *\n * @param options - The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport function defineCodeBlockShiki({\n themes = ['one-dark-pro'],\n langs = ['text'],\n ...rest\n}: CodeBlockShikiOptions = {}): Extension {\n const parser = createLazyParser({ themes, langs, ...rest })\n return defineCodeBlockHighlight({ parser })\n}\n"],"mappings":";;;;;;;;;;;;;;AA4BA,SAAgB,0BAAsD;AACpE,QAAO,eAAe;EACpB,eAAe,UAA2B;AACxC,UAAO,aAAa;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEnD,kBAAkB,UAA2B;AAC3C,UAAO,WAAW;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEjD,kBAAkB,UAA2B;AAC3C,UAAO,WAAW;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEjD,oBAAoB,UAA0B;AAC5C,UAAO,aAAa;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEpD,CAAC;;;;;;;;;;AC9BJ,SAAgB,2BAA2C;AACzD,QAAO,yBAAyB;EAC9B,OAAO;EACP,MAAM;EACN,OAAO;EACR,CAAC;;;;;;;AAQJ,SAAgB,2BAA2C;AACzD,QAAO,yBAAyB;EAC9B,OAAO;EACP,MAAM;EACN,OAAO;EACR,CAAC;;AAGJ,SAAS,SAAS,OAAyC;AACzD,QAAO,EAAE,UAAU,MAAM,MAAM,IAAI;;;;;;;;ACrBrC,SAAgB,wBAAwC;AACtD,QAAO,aAAa,EAClB,OAAO,gBACR,CAAC;;;;;;AAOJ,MAAMA,kBAA2B,OAAO,aAAa;AACnD,KAAI,CAAC,MAAM,UAAU,MACnB,QA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ts","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-spec.ts","../src/code/code.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts"],"sourcesContent":[],"mappings":";;;;;;;AASY,KAAA,qBAAA,GAAwB,SAAA,CAAA;EASpB,QAAA,EAAA;;;;ACThB;AASA;;iBDAgB,kBAAA,CAAA,GAAsB;;;;;AATtC;AASgB,KCTJ,iBAAA,GAAoB,SDSM,CAAA;;UCP5B;;AAFV,CAAA,CAAA;AASA;;;iBAAgB,cAAA,CAAA,GAAkB;;;;ADTlC;AASA;KECY,aAAA,GAAgB,OAAO,mBAAmB;;;ADVtD;AASgB,iBCMA,UAAA,CAAA,CDNkB,ECMJ,aDNI;;;;;;ADTtB,iBGCI,mBAAA,CAAA,CHDoB,EGCG,cHDM;;;;;;AAAjC,iBIAI,gBAAA,CAAA,CJAoB,EIAA,cJAS"}
1
+ {"version":3,"file":"prosekit-extensions-code.d.ts","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-spec.ts","../src/code/code.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts"],"sourcesContent":[],"mappings":";;;;;;;AASY,KAAA,qBAAA,GAAwB,SAAA,CAAA;EASpB,QAAA,EAAA;;;;ACThB;AASA;;iBDAgB,kBAAA,CAAA,GAAsB;;;;;AATtC;AASgB,KCTJ,iBAAA,GAAoB,SDSM,CAAA;;UCP5B;;AAFV,CAAA,CAAA;AASA;;;iBAAgB,cAAA,CAAA,GAAkB;;;;ADTlC;AASA;KECY,aAAA,GAAgB,OAAO,mBAAmB;;;ADVtD;AASgB,iBCMA,UAAA,CAAA,CDNkB,ECMJ,aDNqB;;;;;;ADTvC,iBGCI,mBAAA,CAAA,CHDoB,EGCG,cHDM;;;;;;AAAjC,iBIAI,gBAAA,CAAA,CJAoB,EIAA,cJAS"}
@@ -13,7 +13,7 @@ function defineLoroCommands() {
13
13
  //#endregion
14
14
  //#region src/loro/loro-cursor-plugin.ts
15
15
  function defineLoroCursorPlugin(options) {
16
- const { awareness,...rest } = options;
16
+ const { awareness, ...rest } = options;
17
17
  return definePlugin(LoroCursorPlugin(awareness, rest));
18
18
  }
19
19
 
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-loro.js","names":["keymap: Keymap","undo"],"sources":["../src/loro/loro-commands.ts","../src/loro/loro-cursor-plugin.ts","../src/loro/loro-keymap.ts","../src/loro/loro-sync-plugin.ts","../src/loro/loro-undo-plugin.ts","../src/loro/loro.ts"],"sourcesContent":["import {\n defineCommands,\n type Extension,\n} from '@prosekit/core'\nimport {\n redo,\n undo,\n} from 'loro-prosemirror'\n\nconst commands = {\n undo: () => undo,\n redo: () => redo,\n} as const\n\n/**\n * @internal\n */\nexport type LoroCommandsExtension = Extension<{\n Commands: {\n undo: []\n redo: []\n }\n}>\n\nexport function defineLoroCommands(): LoroCommandsExtension {\n return defineCommands(commands)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport type {\n EditorState,\n Selection,\n} from '@prosekit/pm/state'\nimport type { DecorationAttrs } from '@prosekit/pm/view'\nimport type { PeerID } from 'loro-crdt'\nimport {\n LoroCursorPlugin,\n type CursorAwareness,\n} from 'loro-prosemirror'\n\nexport interface LoroCursorOptions {\n awareness: CursorAwareness\n getSelection?: (state: EditorState) => Selection\n createCursor?: (user: PeerID) => Element\n createSelection?: (user: PeerID) => DecorationAttrs\n}\n\nexport function defineLoroCursorPlugin(\n options: LoroCursorOptions,\n): PlainExtension {\n const { awareness, ...rest } = options\n return definePlugin(LoroCursorPlugin(awareness, rest))\n}\n","import {\n defineKeymap,\n isApple,\n type Keymap,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n redo,\n undo,\n} from 'loro-prosemirror'\n\nconst keymap: Keymap = {\n 'Mod-z': undo,\n 'Shift-Mod-z': redo,\n}\n\nif (!isApple) {\n keymap['Mod-y'] = redo\n}\n\nexport function defineLoroKeymap(): PlainExtension {\n return defineKeymap(keymap)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n LoroSyncPlugin,\n type LoroSyncPluginProps,\n} from 'loro-prosemirror'\n\nexport function defineLoroSyncPlugin(\n options: LoroSyncPluginProps,\n): PlainExtension {\n return definePlugin(LoroSyncPlugin(options))\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n LoroUndoPlugin,\n type LoroUndoPluginProps,\n} from 'loro-prosemirror'\n\nexport function defineLoroUndoPlugin(options: LoroUndoPluginProps): PlainExtension {\n return definePlugin(LoroUndoPlugin(options))\n}\n","import {\n Priority,\n union,\n withPriority,\n type PlainExtension,\n type Union,\n} from '@prosekit/core'\nimport type {\n CursorAwareness,\n LoroDocType,\n LoroSyncPluginProps,\n LoroUndoPluginProps,\n} from 'loro-prosemirror'\n\nimport {\n defineLoroCommands,\n type LoroCommandsExtension,\n} from './loro-commands'\nimport {\n defineLoroCursorPlugin,\n type LoroCursorOptions,\n} from './loro-cursor-plugin'\nimport { defineLoroKeymap } from './loro-keymap'\nimport { defineLoroSyncPlugin } from './loro-sync-plugin'\nimport { defineLoroUndoPlugin } from './loro-undo-plugin'\n\nexport interface LoroOptions {\n /**\n * The Loro instance handles the state of shared data.\n */\n doc: LoroDocType\n\n /**\n * The Awareness instance.\n */\n awareness: CursorAwareness\n\n /**\n * Extra options for `LoroSyncPlugin`.\n */\n sync?: Omit<LoroSyncPluginProps, 'doc'>\n\n /**\n * Extra options for the `LoroUndoPlugin`.\n */\n undo?: Omit<LoroUndoPluginProps, 'doc'>\n\n /**\n * Extra options for `LoroCursorPlugin`.\n */\n cursor?: Omit<LoroCursorOptions, 'awareness'>\n}\n\n/**\n * @internal\n */\nexport type LoroExtension = Union<[LoroCommandsExtension, PlainExtension]>\n\n/**\n * @public\n */\nexport function defineLoro(options: LoroOptions): LoroExtension {\n const { doc, awareness, sync, undo, cursor } = options\n\n return withPriority(\n union([\n defineLoroKeymap(),\n defineLoroCommands(),\n defineLoroCursorPlugin({ ...cursor, awareness }),\n defineLoroUndoPlugin({ ...undo, doc }),\n defineLoroSyncPlugin({ ...sync, doc }),\n ]),\n Priority.high,\n )\n}\n"],"mappings":";;;;AASA,MAAM,WAAW;CACf,YAAY;CACZ,YAAY;CACb;AAYD,SAAgB,qBAA4C;AAC1D,QAAO,eAAe,SAAS;;;;;ACHjC,SAAgB,uBACd,SACgB;CAChB,MAAM,EAAE,UAAW,GAAG,SAAS;AAC/B,QAAO,aAAa,iBAAiB,WAAW,KAAK,CAAC;;;;;ACfxD,MAAMA,SAAiB;CACrB,SAAS;CACT,eAAe;CAChB;AAED,IAAI,CAAC,QACH,QAAO,WAAW;AAGpB,SAAgB,mBAAmC;AACjD,QAAO,aAAa,OAAO;;;;;ACZ7B,SAAgB,qBACd,SACgB;AAChB,QAAO,aAAa,eAAe,QAAQ,CAAC;;;;;ACH9C,SAAgB,qBAAqB,SAA8C;AACjF,QAAO,aAAa,eAAe,QAAQ,CAAC;;;;;;;;ACmD9C,SAAgB,WAAW,SAAqC;CAC9D,MAAM,EAAE,KAAK,WAAW,MAAM,cAAM,WAAW;AAE/C,QAAO,aACL,MAAM;EACJ,kBAAkB;EAClB,oBAAoB;EACpB,uBAAuB;GAAE,GAAG;GAAQ;GAAW,CAAC;EAChD,qBAAqB;GAAE,GAAGC;GAAM;GAAK,CAAC;EACtC,qBAAqB;GAAE,GAAG;GAAM;GAAK,CAAC;EACvC,CAAC,EACF,SAAS,KACV"}
1
+ {"version":3,"file":"prosekit-extensions-loro.js","names":["keymap: Keymap","undo"],"sources":["../src/loro/loro-commands.ts","../src/loro/loro-cursor-plugin.ts","../src/loro/loro-keymap.ts","../src/loro/loro-sync-plugin.ts","../src/loro/loro-undo-plugin.ts","../src/loro/loro.ts"],"sourcesContent":["import {\n defineCommands,\n type Extension,\n} from '@prosekit/core'\nimport {\n redo,\n undo,\n} from 'loro-prosemirror'\n\nconst commands = {\n undo: () => undo,\n redo: () => redo,\n} as const\n\n/**\n * @internal\n */\nexport type LoroCommandsExtension = Extension<{\n Commands: {\n undo: []\n redo: []\n }\n}>\n\nexport function defineLoroCommands(): LoroCommandsExtension {\n return defineCommands(commands)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport type {\n EditorState,\n Selection,\n} from '@prosekit/pm/state'\nimport type { DecorationAttrs } from '@prosekit/pm/view'\nimport type { PeerID } from 'loro-crdt'\nimport {\n LoroCursorPlugin,\n type CursorAwareness,\n} from 'loro-prosemirror'\n\nexport interface LoroCursorOptions {\n awareness: CursorAwareness\n getSelection?: (state: EditorState) => Selection\n createCursor?: (user: PeerID) => Element\n createSelection?: (user: PeerID) => DecorationAttrs\n}\n\nexport function defineLoroCursorPlugin(\n options: LoroCursorOptions,\n): PlainExtension {\n const { awareness, ...rest } = options\n return definePlugin(LoroCursorPlugin(awareness, rest))\n}\n","import {\n defineKeymap,\n isApple,\n type Keymap,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n redo,\n undo,\n} from 'loro-prosemirror'\n\nconst keymap: Keymap = {\n 'Mod-z': undo,\n 'Shift-Mod-z': redo,\n}\n\nif (!isApple) {\n keymap['Mod-y'] = redo\n}\n\nexport function defineLoroKeymap(): PlainExtension {\n return defineKeymap(keymap)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n LoroSyncPlugin,\n type LoroSyncPluginProps,\n} from 'loro-prosemirror'\n\nexport function defineLoroSyncPlugin(\n options: LoroSyncPluginProps,\n): PlainExtension {\n return definePlugin(LoroSyncPlugin(options))\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n LoroUndoPlugin,\n type LoroUndoPluginProps,\n} from 'loro-prosemirror'\n\nexport function defineLoroUndoPlugin(options: LoroUndoPluginProps): PlainExtension {\n return definePlugin(LoroUndoPlugin(options))\n}\n","import {\n Priority,\n union,\n withPriority,\n type PlainExtension,\n type Union,\n} from '@prosekit/core'\nimport type {\n CursorAwareness,\n LoroDocType,\n LoroSyncPluginProps,\n LoroUndoPluginProps,\n} from 'loro-prosemirror'\n\nimport {\n defineLoroCommands,\n type LoroCommandsExtension,\n} from './loro-commands'\nimport {\n defineLoroCursorPlugin,\n type LoroCursorOptions,\n} from './loro-cursor-plugin'\nimport { defineLoroKeymap } from './loro-keymap'\nimport { defineLoroSyncPlugin } from './loro-sync-plugin'\nimport { defineLoroUndoPlugin } from './loro-undo-plugin'\n\nexport interface LoroOptions {\n /**\n * The Loro instance handles the state of shared data.\n */\n doc: LoroDocType\n\n /**\n * The Awareness instance.\n */\n awareness: CursorAwareness\n\n /**\n * Extra options for `LoroSyncPlugin`.\n */\n sync?: Omit<LoroSyncPluginProps, 'doc'>\n\n /**\n * Extra options for the `LoroUndoPlugin`.\n */\n undo?: Omit<LoroUndoPluginProps, 'doc'>\n\n /**\n * Extra options for `LoroCursorPlugin`.\n */\n cursor?: Omit<LoroCursorOptions, 'awareness'>\n}\n\n/**\n * @internal\n */\nexport type LoroExtension = Union<[LoroCommandsExtension, PlainExtension]>\n\n/**\n * @public\n */\nexport function defineLoro(options: LoroOptions): LoroExtension {\n const { doc, awareness, sync, undo, cursor } = options\n\n return withPriority(\n union([\n defineLoroKeymap(),\n defineLoroCommands(),\n defineLoroCursorPlugin({ ...cursor, awareness }),\n defineLoroUndoPlugin({ ...undo, doc }),\n defineLoroSyncPlugin({ ...sync, doc }),\n ]),\n Priority.high,\n )\n}\n"],"mappings":";;;;AASA,MAAM,WAAW;CACf,YAAY;CACZ,YAAY;CACb;AAYD,SAAgB,qBAA4C;AAC1D,QAAO,eAAe,SAAS;;;;;ACHjC,SAAgB,uBACd,SACgB;CAChB,MAAM,EAAE,WAAW,GAAG,SAAS;AAC/B,QAAO,aAAa,iBAAiB,WAAW,KAAK,CAAC;;;;;ACfxD,MAAMA,SAAiB;CACrB,SAAS;CACT,eAAe;CAChB;AAED,IAAI,CAAC,QACH,QAAO,WAAW;AAGpB,SAAgB,mBAAmC;AACjD,QAAO,aAAa,OAAO;;;;;ACZ7B,SAAgB,qBACd,SACgB;AAChB,QAAO,aAAa,eAAe,QAAQ,CAAC;;;;;ACH9C,SAAgB,qBAAqB,SAA8C;AACjF,QAAO,aAAa,eAAe,QAAQ,CAAC;;;;;;;;ACmD9C,SAAgB,WAAW,SAAqC;CAC9D,MAAM,EAAE,KAAK,WAAW,MAAM,cAAM,WAAW;AAE/C,QAAO,aACL,MAAM;EACJ,kBAAkB;EAClB,oBAAoB;EACpB,uBAAuB;GAAE,GAAG;GAAQ;GAAW,CAAC;EAChD,qBAAqB;GAAE,GAAGC;GAAM;GAAK,CAAC;EACtC,qBAAqB;GAAE,GAAG;GAAM;GAAK,CAAC;EACvC,CAAC,EACF,SAAS,KACV"}
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-yjs.d.ts","names":[],"sources":["../src/yjs/yjs-commands.ts","../src/yjs/yjs-cursor-plugin.ts","../src/yjs/yjs-sync-plugin.ts","../src/yjs/yjs-undo-plugin.ts","../src/yjs/yjs.ts","../src/yjs/yjs-keymap.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAiBY,oBAAA,GAAuB;;IAAvB,IAAA,EAAA,EAAA;IAOI,IAAA,EAAA,EAAA;;;iBAAA,iBAAA,CAAA,GAAqB;;;;;;AAPzB,KCNA,sBAAA,GAAyB,WDMF,CCLjC,UDK0C,CAAA,OCLxB,aDKwB,CAAA,CAAA,CAAA,CAAA,CAAA;AAO5B,UCTC,gBAAA,SAAyB,sBDSe,CAAA;aCR5C;;iBAGG,qBAAA,UACL,mBACR;;;;;;ADJS,KENA,oBAAA,GAAuB,WFMA,CELjC,UFK0C,CAAA,OELxB,WFKwB,CAAA,CAAA,CAAA,CAAA,CAAA;AAO5B,UETC,cAAA,SAAuB,oBFSiB,CAAA;YER7C,CAAA,CAAE;;iBAGE,mBAAA,UAA6B,iBAAiB;;;;;;KC+ClD,oBAAA,GAAuB,YACjC,kBAAkB;AHlDR,UGqDK,cAAA,SAAuB,oBHrDI,CAAA,CAO5C;;;;ACbY,iBEyEI,mBAAA,CFzEkB,OAAA,EEyEW,cFzEX,CAAA,EEyE4B,cFzE5B;;;ADalB,UIIC,UAAA,CJJgB;;;;ECbrB,GAAA,EGqBL,CAAA,CAAE,GHrBG;EACQ;;;EAD4B,SAAA,EG0BnC,SH1BmC;EAI/B;AAIjB;;;aGwBa,CAAA,CAAE;EFhCH;;;EAAuB,IAAA,CAAA,EEqC1B,oBFrC0B;EAAW;AAI9C;AAIA;SEkCS;;;ADaT;EACoB,MAAA,CAAA,ECTT,sBDSS;;;;AAGpB;AAcgB,KCpBJ,YAAA,GAAe,KDoBQ,CAAA,CCpBD,oBDoB4B,ECpBN,cDoBoB,CAAA,CAAA;;;;ACxD3D,iBAyCD,SAAA,CAzCW,OAAA,EAyCQ,UAzCR,CAAA,EAyCqB,YAzCrB;;;iBCRX,eAAA,CAAA,GAAmB"}
1
+ {"version":3,"file":"prosekit-extensions-yjs.d.ts","names":[],"sources":["../src/yjs/yjs-commands.ts","../src/yjs/yjs-cursor-plugin.ts","../src/yjs/yjs-sync-plugin.ts","../src/yjs/yjs-undo-plugin.ts","../src/yjs/yjs.ts","../src/yjs/yjs-keymap.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAiBY,oBAAA,GAAuB;;IAAvB,IAAA,EAAA,EAAA;IAOI,IAAA,EAAA,EAAA;;;iBAAA,iBAAA,CAAA,GAAqB;;;;;;AAPzB,KCNA,sBAAA,GAAyB,WDMF,CCLjC,UDK0C,CAAA,OCLxB,aDKwB,CAAA,CAAA,CAAA,CAAA,CAAA;AAO5B,UCTC,gBAAA,SAAyB,sBDSe,CAAA;aCR5C;;iBAGG,qBAAA,UACL,mBACR;;;;;;ADJS,KENA,oBAAA,GAAuB,WFMA,CELjC,UFK0C,CAAA,OELxB,WFKwB,CAAA,CAAA,CAAA,CAAA,CAAA;AAO5B,UETC,cAAA,SAAuB,oBFSiB,CAAA;YER7C,CAAA,CAAE;;iBAGE,mBAAA,UAA6B,iBAAiB;;;;;;KC+ClD,oBAAA,GAAuB,YACjC,kBAAkB;AHlDR,UGqDK,cAAA,SAAuB,oBHrDI,CAAA,CAO5C;;;;ACbY,iBEyEI,mBAAA,CFzEkB,OAAA,EEyEW,cFzEX,CAAA,EEyE4B,cFzE5B;;;ADalB,UIIC,UAAA,CJJgB;;;;ECbrB,GAAA,EGqBL,CAAA,CAAE,GHrBG;EACQ;;;EAD4B,SAAA,EG0BnC,SH1BmC;EAI/B;AAIjB;;;aGwBa,CAAA,CAAE;EFhCH;;;EAAuB,IAAA,CAAA,EEqC1B,oBFrC0B;EAAW;AAI9C;AAIA;SEkCS;;;ADaT;EACoB,MAAA,CAAA,ECTT,sBDSS;;;;AAGpB;AAcgB,KCpBJ,YAAA,GAAe,KDoBQ,CAAA,CCpBD,oBDoBW,ECpBW,cDoBoB,CAAA,CAAA;;;;ACxD3D,iBAyCD,SAAA,CAzCW,OAAA,EAyCQ,UAzCR,CAAA,EAyCqB,YAzCrB;;;iBCRX,eAAA,CAAA,GAAmB"}
@@ -13,7 +13,7 @@ function defineYjsCommands() {
13
13
  //#endregion
14
14
  //#region src/yjs/yjs-cursor-plugin.ts
15
15
  function defineYjsCursorPlugin(options) {
16
- const { awareness,...rest } = options;
16
+ const { awareness, ...rest } = options;
17
17
  return definePlugin(yCursorPlugin(awareness, rest));
18
18
  }
19
19
 
@@ -31,7 +31,7 @@ function defineYjsKeymap() {
31
31
  //#endregion
32
32
  //#region src/yjs/yjs-sync-plugin.ts
33
33
  function defineYjsSyncPlugin(options) {
34
- const { fragment,...rest } = options;
34
+ const { fragment, ...rest } = options;
35
35
  return definePlugin(ySyncPlugin(fragment, rest));
36
36
  }
37
37
 
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-yjs.js","names":["keymap: Keymap","yUndoPlugin","originalYUndoPlugin"],"sources":["../src/yjs/yjs-commands.ts","../src/yjs/yjs-cursor-plugin.ts","../src/yjs/yjs-keymap.ts","../src/yjs/yjs-sync-plugin.ts","../src/yjs/yjs-undo-plugin.ts","../src/yjs/yjs.ts"],"sourcesContent":["import {\n defineCommands,\n type Extension,\n} from '@prosekit/core'\nimport {\n redoCommand,\n undoCommand,\n} from 'y-prosemirror'\n\nconst commands = {\n undo: () => undoCommand,\n redo: () => redoCommand,\n} as const\n\n/**\n * @internal\n */\nexport type YjsCommandsExtension = Extension<{\n Commands: {\n undo: []\n redo: []\n }\n}>\n\nexport function defineYjsCommands(): YjsCommandsExtension {\n return defineCommands(commands)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport type { Plugin } from '@prosekit/pm/state'\nimport { yCursorPlugin } from 'y-prosemirror'\nimport type { Awareness } from 'y-protocols/awareness'\n\n/**\n * Options for `y-prosemirror`'s `yCursorPlugin`.\n */\nexport type YjsCursorPluginOptions = NonNullable<\n Parameters<typeof yCursorPlugin>[1]\n>\n\nexport interface YjsCursorOptions extends YjsCursorPluginOptions {\n awareness: Awareness\n}\n\nexport function defineYjsCursorPlugin(\n options: YjsCursorOptions,\n): PlainExtension {\n const { awareness, ...rest } = options\n return definePlugin(yCursorPlugin(awareness, rest) as Plugin)\n}\n","import {\n defineKeymap,\n isApple,\n type Keymap,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n redoCommand,\n undoCommand,\n} from 'y-prosemirror'\n\nconst keymap: Keymap = {\n 'Mod-z': undoCommand,\n 'Shift-Mod-z': redoCommand,\n}\n\nif (!isApple) {\n keymap['Mod-y'] = redoCommand\n}\n\nexport function defineYjsKeymap(): PlainExtension {\n return defineKeymap(keymap)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport type { Plugin } from '@prosekit/pm/state'\nimport { ySyncPlugin } from 'y-prosemirror'\nimport type * as Y from 'yjs'\n\n/**\n * Options for `y-prosemirror`'s `ySyncPlugin`.\n */\nexport type YjsSyncPluginOptions = NonNullable<\n Parameters<typeof ySyncPlugin>[1]\n>\n\nexport interface YjsSyncOptions extends YjsSyncPluginOptions {\n fragment: Y.XmlFragment\n}\n\nexport function defineYjsSyncPlugin(options: YjsSyncOptions): PlainExtension {\n const { fragment, ...rest } = options\n return definePlugin(ySyncPlugin(fragment, rest) as Plugin)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport type { ProseMirrorPlugin } from '@prosekit/pm/state'\nimport type { EditorView } from '@prosekit/pm/view'\nimport {\n yUndoPlugin as originalYUndoPlugin,\n yUndoPluginKey,\n} from 'y-prosemirror'\nimport type { UndoManager as YjsUndoManager } from 'yjs'\n\ntype UndoManager = YjsUndoManager & { restore: () => void }\n\n/**\n * @see https://github.com/yjs/y-prosemirror/issues/114 and https://github.com/yjs/y-prosemirror/issues/102\n */\nfunction fixYUndoPlugin(yUndoPluginInstance: ProseMirrorPlugin) {\n const originalUndoPluginView = yUndoPluginInstance.spec.view\n yUndoPluginInstance.spec.view = (view: EditorView) => {\n const pluginState = yUndoPluginKey.getState(view.state)\n if (!pluginState) {\n return {}\n }\n\n const undoManager = pluginState.undoManager as UndoManager\n\n if (undoManager.restore) {\n undoManager.restore()\n undoManager.restore = () => {}\n }\n\n const viewRet = originalUndoPluginView\n ? originalUndoPluginView(view)\n : undefined\n\n return {\n destroy: () => {\n const hasUndoManSelf = undoManager.trackedOrigins.has(undoManager)\n\n const observers = undoManager._observers\n\n undoManager.restore = () => {\n if (hasUndoManSelf) {\n undoManager.trackedOrigins.add(undoManager)\n }\n\n undoManager.doc.on(\n 'afterTransaction',\n undoManager.afterTransactionHandler,\n )\n\n undoManager._observers = observers\n }\n\n if (viewRet?.destroy) {\n viewRet.destroy()\n }\n },\n }\n }\n}\n\n/**\n * Options for the `y-prosemirror`'s `yUndoPlugin`.\n */\nexport type YjsUndoPluginOptions = NonNullable<\n Parameters<typeof originalYUndoPlugin>[0]\n>\n\nexport interface YjsUndoOptions extends YjsUndoPluginOptions {}\n\n/**\n * @internal\n */\nfunction yUndoPlugin(options?: YjsUndoOptions) {\n const yUndoPluginInstance = originalYUndoPlugin(options)\n fixYUndoPlugin(yUndoPluginInstance)\n return yUndoPluginInstance\n}\n\n/**\n * @internal\n */\nexport function defineYjsUndoPlugin(options: YjsUndoOptions): PlainExtension {\n return definePlugin(yUndoPlugin(options))\n}\n","import {\n Priority,\n union,\n withPriority,\n type PlainExtension,\n type Union,\n} from '@prosekit/core'\nimport type { Awareness } from 'y-protocols/awareness'\nimport type * as Y from 'yjs'\n\nimport {\n defineYjsCommands,\n type YjsCommandsExtension,\n} from './yjs-commands'\nimport {\n defineYjsCursorPlugin,\n type YjsCursorPluginOptions,\n} from './yjs-cursor-plugin'\nimport { defineYjsKeymap } from './yjs-keymap'\nimport {\n defineYjsSyncPlugin,\n type YjsSyncPluginOptions,\n} from './yjs-sync-plugin'\nimport {\n defineYjsUndoPlugin,\n type YjsUndoPluginOptions,\n} from './yjs-undo-plugin'\n\nexport interface YjsOptions {\n /**\n * The Yjs instance handles the state of shared data.\n */\n doc: Y.Doc\n\n /**\n * The Awareness instance.\n */\n awareness: Awareness\n\n /**\n * The Yjs XmlFragment to use. If not provided,\n * `doc.getXmlFragment('prosemirror')` will be used.\n */\n fragment?: Y.XmlFragment\n\n /**\n * Options for `y-prosemirror`'s `ySyncPlugin`.\n */\n sync?: YjsSyncPluginOptions\n\n /**\n * Options for the `y-prosemirror`'s `yUndoPlugin`.\n */\n undo?: YjsUndoPluginOptions\n\n /**\n * Options for `y-prosemirror`'s `yCursorPlugin`.\n */\n cursor?: YjsCursorPluginOptions\n}\n\n/**\n * @internal\n */\nexport type YjsExtension = Union<[YjsCommandsExtension, PlainExtension]>\n\n/**\n * @public\n */\nexport function defineYjs(options: YjsOptions): YjsExtension {\n const { doc, awareness, sync, undo, cursor } = options\n const fragment = options.fragment ?? doc.getXmlFragment('prosemirror')\n\n return withPriority(\n union([\n defineYjsKeymap(),\n defineYjsCommands(),\n defineYjsCursorPlugin({ ...cursor, awareness }),\n defineYjsUndoPlugin({ ...undo }),\n defineYjsSyncPlugin({ ...sync, fragment }),\n ]),\n Priority.high,\n )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C;;;;;;;;AChB3C,SAAgB,UAAU,SAAmC;CAC3D,MAAM,EAAE,KAAK,WAAW,MAAM,MAAM,WAAW;CAC/C,MAAM,WAAW,QAAQ,YAAY,IAAI,eAAe,cAAc;AAEtE,QAAO,aACL,MAAM;EACJ,iBAAiB;EACjB,mBAAmB;EACnB,sBAAsB;GAAE,GAAG;GAAQ;GAAW,CAAC;EAC/C,oBAAoB,EAAE,GAAG,MAAM,CAAC;EAChC,oBAAoB;GAAE,GAAG;GAAM;GAAU,CAAC;EAC3C,CAAC,EACF,SAAS,KACV"}
1
+ {"version":3,"file":"prosekit-extensions-yjs.js","names":["keymap: Keymap","yUndoPlugin","originalYUndoPlugin"],"sources":["../src/yjs/yjs-commands.ts","../src/yjs/yjs-cursor-plugin.ts","../src/yjs/yjs-keymap.ts","../src/yjs/yjs-sync-plugin.ts","../src/yjs/yjs-undo-plugin.ts","../src/yjs/yjs.ts"],"sourcesContent":["import {\n defineCommands,\n type Extension,\n} from '@prosekit/core'\nimport {\n redoCommand,\n undoCommand,\n} from 'y-prosemirror'\n\nconst commands = {\n undo: () => undoCommand,\n redo: () => redoCommand,\n} as const\n\n/**\n * @internal\n */\nexport type YjsCommandsExtension = Extension<{\n Commands: {\n undo: []\n redo: []\n }\n}>\n\nexport function defineYjsCommands(): YjsCommandsExtension {\n return defineCommands(commands)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport type { Plugin } from '@prosekit/pm/state'\nimport { yCursorPlugin } from 'y-prosemirror'\nimport type { Awareness } from 'y-protocols/awareness'\n\n/**\n * Options for `y-prosemirror`'s `yCursorPlugin`.\n */\nexport type YjsCursorPluginOptions = NonNullable<\n Parameters<typeof yCursorPlugin>[1]\n>\n\nexport interface YjsCursorOptions extends YjsCursorPluginOptions {\n awareness: Awareness\n}\n\nexport function defineYjsCursorPlugin(\n options: YjsCursorOptions,\n): PlainExtension {\n const { awareness, ...rest } = options\n return definePlugin(yCursorPlugin(awareness, rest) as Plugin)\n}\n","import {\n defineKeymap,\n isApple,\n type Keymap,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n redoCommand,\n undoCommand,\n} from 'y-prosemirror'\n\nconst keymap: Keymap = {\n 'Mod-z': undoCommand,\n 'Shift-Mod-z': redoCommand,\n}\n\nif (!isApple) {\n keymap['Mod-y'] = redoCommand\n}\n\nexport function defineYjsKeymap(): PlainExtension {\n return defineKeymap(keymap)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport type { Plugin } from '@prosekit/pm/state'\nimport { ySyncPlugin } from 'y-prosemirror'\nimport type * as Y from 'yjs'\n\n/**\n * Options for `y-prosemirror`'s `ySyncPlugin`.\n */\nexport type YjsSyncPluginOptions = NonNullable<\n Parameters<typeof ySyncPlugin>[1]\n>\n\nexport interface YjsSyncOptions extends YjsSyncPluginOptions {\n fragment: Y.XmlFragment\n}\n\nexport function defineYjsSyncPlugin(options: YjsSyncOptions): PlainExtension {\n const { fragment, ...rest } = options\n return definePlugin(ySyncPlugin(fragment, rest) as Plugin)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport type { ProseMirrorPlugin } from '@prosekit/pm/state'\nimport type { EditorView } from '@prosekit/pm/view'\nimport {\n yUndoPlugin as originalYUndoPlugin,\n yUndoPluginKey,\n} from 'y-prosemirror'\nimport type { UndoManager as YjsUndoManager } from 'yjs'\n\ntype UndoManager = YjsUndoManager & { restore: () => void }\n\n/**\n * @see https://github.com/yjs/y-prosemirror/issues/114 and https://github.com/yjs/y-prosemirror/issues/102\n */\nfunction fixYUndoPlugin(yUndoPluginInstance: ProseMirrorPlugin) {\n const originalUndoPluginView = yUndoPluginInstance.spec.view\n yUndoPluginInstance.spec.view = (view: EditorView) => {\n const pluginState = yUndoPluginKey.getState(view.state)\n if (!pluginState) {\n return {}\n }\n\n const undoManager = pluginState.undoManager as UndoManager\n\n if (undoManager.restore) {\n undoManager.restore()\n undoManager.restore = () => {}\n }\n\n const viewRet = originalUndoPluginView\n ? originalUndoPluginView(view)\n : undefined\n\n return {\n destroy: () => {\n const hasUndoManSelf = undoManager.trackedOrigins.has(undoManager)\n\n const observers = undoManager._observers\n\n undoManager.restore = () => {\n if (hasUndoManSelf) {\n undoManager.trackedOrigins.add(undoManager)\n }\n\n undoManager.doc.on(\n 'afterTransaction',\n undoManager.afterTransactionHandler,\n )\n\n undoManager._observers = observers\n }\n\n if (viewRet?.destroy) {\n viewRet.destroy()\n }\n },\n }\n }\n}\n\n/**\n * Options for the `y-prosemirror`'s `yUndoPlugin`.\n */\nexport type YjsUndoPluginOptions = NonNullable<\n Parameters<typeof originalYUndoPlugin>[0]\n>\n\nexport interface YjsUndoOptions extends YjsUndoPluginOptions {}\n\n/**\n * @internal\n */\nfunction yUndoPlugin(options?: YjsUndoOptions) {\n const yUndoPluginInstance = originalYUndoPlugin(options)\n fixYUndoPlugin(yUndoPluginInstance)\n return yUndoPluginInstance\n}\n\n/**\n * @internal\n */\nexport function defineYjsUndoPlugin(options: YjsUndoOptions): PlainExtension {\n return definePlugin(yUndoPlugin(options))\n}\n","import {\n Priority,\n union,\n withPriority,\n type PlainExtension,\n type Union,\n} from '@prosekit/core'\nimport type { Awareness } from 'y-protocols/awareness'\nimport type * as Y from 'yjs'\n\nimport {\n defineYjsCommands,\n type YjsCommandsExtension,\n} from './yjs-commands'\nimport {\n defineYjsCursorPlugin,\n type YjsCursorPluginOptions,\n} from './yjs-cursor-plugin'\nimport { defineYjsKeymap } from './yjs-keymap'\nimport {\n defineYjsSyncPlugin,\n type YjsSyncPluginOptions,\n} from './yjs-sync-plugin'\nimport {\n defineYjsUndoPlugin,\n type YjsUndoPluginOptions,\n} from './yjs-undo-plugin'\n\nexport interface YjsOptions {\n /**\n * The Yjs instance handles the state of shared data.\n */\n doc: Y.Doc\n\n /**\n * The Awareness instance.\n */\n awareness: Awareness\n\n /**\n * The Yjs XmlFragment to use. If not provided,\n * `doc.getXmlFragment('prosemirror')` will be used.\n */\n fragment?: Y.XmlFragment\n\n /**\n * Options for `y-prosemirror`'s `ySyncPlugin`.\n */\n sync?: YjsSyncPluginOptions\n\n /**\n * Options for the `y-prosemirror`'s `yUndoPlugin`.\n */\n undo?: YjsUndoPluginOptions\n\n /**\n * Options for `y-prosemirror`'s `yCursorPlugin`.\n */\n cursor?: YjsCursorPluginOptions\n}\n\n/**\n * @internal\n */\nexport type YjsExtension = Union<[YjsCommandsExtension, PlainExtension]>\n\n/**\n * @public\n */\nexport function defineYjs(options: YjsOptions): YjsExtension {\n const { doc, awareness, sync, undo, cursor } = options\n const fragment = options.fragment ?? doc.getXmlFragment('prosemirror')\n\n return withPriority(\n union([\n defineYjsKeymap(),\n defineYjsCommands(),\n defineYjsCursorPlugin({ ...cursor, awareness }),\n defineYjsUndoPlugin({ ...undo }),\n defineYjsSyncPlugin({ ...sync, fragment }),\n ]),\n Priority.high,\n )\n}\n"],"mappings":";;;;AASA,MAAM,WAAW;CACf,YAAY;CACZ,YAAY;CACb;AAYD,SAAgB,oBAA0C;AACxD,QAAO,eAAe,SAAS;;;;;ACNjC,SAAgB,sBACd,SACgB;CAChB,MAAM,EAAE,WAAW,GAAG,SAAS;AAC/B,QAAO,aAAa,cAAc,WAAW,KAAK,CAAW;;;;;ACZ/D,MAAMA,SAAiB;CACrB,SAAS;CACT,eAAe;CAChB;AAED,IAAI,CAAC,QACH,QAAO,WAAW;AAGpB,SAAgB,kBAAkC;AAChD,QAAO,aAAa,OAAO;;;;;ACF7B,SAAgB,oBAAoB,SAAyC;CAC3E,MAAM,EAAE,UAAU,GAAG,SAAS;AAC9B,QAAO,aAAa,YAAY,UAAU,KAAK,CAAW;;;;;;;;ACJ5D,SAAS,eAAe,qBAAwC;CAC9D,MAAM,yBAAyB,oBAAoB,KAAK;AACxD,qBAAoB,KAAK,QAAQ,SAAqB;EACpD,MAAM,cAAc,eAAe,SAAS,KAAK,MAAM;AACvD,MAAI,CAAC,YACH,QAAO,EAAE;EAGX,MAAM,cAAc,YAAY;AAEhC,MAAI,YAAY,SAAS;AACvB,eAAY,SAAS;AACrB,eAAY,gBAAgB;;EAG9B,MAAM,UAAU,yBACZ,uBAAuB,KAAK,GAC5B;AAEJ,SAAO,EACL,eAAe;GACb,MAAM,iBAAiB,YAAY,eAAe,IAAI,YAAY;GAElE,MAAM,YAAY,YAAY;AAE9B,eAAY,gBAAgB;AAC1B,QAAI,eACF,aAAY,eAAe,IAAI,YAAY;AAG7C,gBAAY,IAAI,GACd,oBACA,YAAY,wBACb;AAED,gBAAY,aAAa;;AAG3B,OAAI,SAAS,QACX,SAAQ,SAAS;KAGtB;;;;;;AAgBL,SAASC,cAAY,SAA0B;CAC7C,MAAM,sBAAsBC,YAAoB,QAAQ;AACxD,gBAAe,oBAAoB;AACnC,QAAO;;;;;AAMT,SAAgB,oBAAoB,SAAyC;AAC3E,QAAO,aAAaD,cAAY,QAAQ,CAAC;;;;;;;;AChB3C,SAAgB,UAAU,SAAmC;CAC3D,MAAM,EAAE,KAAK,WAAW,MAAM,MAAM,WAAW;CAC/C,MAAM,WAAW,QAAQ,YAAY,IAAI,eAAe,cAAc;AAEtE,QAAO,aACL,MAAM;EACJ,iBAAiB;EACjB,mBAAmB;EACnB,sBAAsB;GAAE,GAAG;GAAQ;GAAW,CAAC;EAC/C,oBAAoB,EAAE,GAAG,MAAM,CAAC;EAChC,oBAAoB;GAAE,GAAG;GAAM;GAAU,CAAC;EAC3C,CAAC,EACF,SAAS,KACV"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.12.1",
4
+ "version": "0.12.2",
5
5
  "private": false,
6
6
  "description": "A collection of common extensions for ProseKit",
7
7
  "author": {
@@ -217,8 +217,8 @@
217
217
  "prosemirror-search": "^1.1.0",
218
218
  "prosemirror-tables": "^1.8.1",
219
219
  "shiki": "^3.15.0",
220
- "@prosekit/core": "^0.8.6",
221
- "@prosekit/pm": "^0.1.14"
220
+ "@prosekit/pm": "^0.1.14",
221
+ "@prosekit/core": "^0.8.7"
222
222
  },
223
223
  "peerDependencies": {
224
224
  "loro-crdt": ">= 0.16.7",
@@ -252,11 +252,11 @@
252
252
  "remark-html": "^16.0.1",
253
253
  "remark-parse": "^11.0.0",
254
254
  "remark-stringify": "^11.0.0",
255
- "tsdown": "^0.16.2",
255
+ "tsdown": "^0.16.5",
256
256
  "type-fest": "^5.2.0",
257
257
  "typescript": "~5.9.3",
258
258
  "unified": "^11.0.5",
259
- "vitest": "^4.0.8",
259
+ "vitest": "^4.0.10",
260
260
  "y-prosemirror": "^1.3.7",
261
261
  "y-protocols": "^1.0.6",
262
262
  "yjs": "^13.6.27",
@@ -11,8 +11,7 @@ import { userEvent } from 'vitest/browser'
11
11
  *
12
12
  * @internal
13
13
  */
14
-
15
- export async function pressKey(input: string) {
14
+ export async function pressKey(input: string): Promise<void> {
16
15
  const keys = input.split('-').map((key) => {
17
16
  if (key.toLowerCase() === 'mod') {
18
17
  return isApple ? 'Meta' : 'Control'
@@ -31,6 +30,6 @@ export async function pressKey(input: string) {
31
30
  return await userEvent.keyboard(seq.join(''))
32
31
  }
33
32
 
34
- export async function inputText(input: string) {
33
+ export async function inputText(input: string): Promise<void> {
35
34
  return await userEvent.keyboard(input)
36
35
  }