@sobree/keyboard 0.1.9 → 0.1.11
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.
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * `@sobree/keyboard` — default keyboard shortcuts plugin.\n *\n * Registers no commands of its own. Subscribes to `editor.on(\"keydown\",\n * …)` and dispatches the standard combos through the command bus —\n * `mark.toggle.bold` for Ctrl/Cmd+B, `history.undo` for Cmd+Z, and so\n * on. Every command this plugin invokes is registered by the Editor\n * core itself.\n *\n * Recommended usage — pass the `keyboard()` factory to\n * `createSobree({ plugins: [...] })`. For custom Editor mounts that\n * skip the factory, use `attachKeyboard(editor, opts?)` directly.\n */\n\nimport type { Editor, KeyDownPayload, SobreePlugin } from \"@sobree/core\";\n\nexport interface KeyboardOptions {\n /**\n * Extra key→command mappings to add on top of the defaults. Last\n * matcher wins on conflict — pass your own to override a default.\n */\n bindings?: KeyBinding[];\n}\n\n/**\n * One key binding: a predicate over the editor's `KeyDownPayload`\n * plus the command name to dispatch when it matches. The predicate\n * is called for every keydown — keep it cheap (modifier checks +\n * `e.key` switch).\n */\nexport interface KeyBinding {\n match: (e: KeyDownPayload) => boolean;\n command: string;\n}\n\n/**\n * `SobreePlugin` factory — the recommended way to mount this. Hand\n * the result to `createSobree({ plugins: [...] })` and `createSobree`\n * wires up setup + destroy automatically.\n *\n * ```ts\n * import { keyboard } from \"@sobree/keyboard\";\n * createSobree(\"#editor\", { plugins: [keyboard()] });\n * // or with custom bindings layered on top of the defaults:\n * createSobree(\"#editor\", { plugins: [keyboard({ bindings: [...] })] });\n * ```\n */\nexport function keyboard(opts?: KeyboardOptions): SobreePlugin {\n return {\n name: \"keyboard\",\n setup({ editor }) {\n const detach = attachKeyboard(editor, opts);\n return { destroy: detach };\n },\n };\n}\n\n/**\n * Lower-level: mount the keyboard handler directly on an Editor.\n * Useful when you've skipped `createSobree()` and instantiated\n * `Sobree` / `Editor` yourself. Returns an unsubscribe.\n *\n * ```ts\n * import { Sobree } from \"@sobree/core\";\n * import { attachKeyboard } from \"@sobree/keyboard\";\n * const sobree = new Sobree(host);\n * const detach = attachKeyboard(sobree.editor);\n * ```\n */\nexport function attachKeyboard(
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * `@sobree/keyboard` — default keyboard shortcuts plugin.\n *\n * Registers no commands of its own. Subscribes to `editor.on(\"keydown\",\n * …)` and dispatches the standard combos through the command bus —\n * `mark.toggle.bold` for Ctrl/Cmd+B, `history.undo` for Cmd+Z, and so\n * on. Every command this plugin invokes is registered by the Editor\n * core itself.\n *\n * Recommended usage — pass the `keyboard()` factory to\n * `createSobree({ plugins: [...] })`. For custom Editor mounts that\n * skip the factory, use `attachKeyboard(editor, opts?)` directly.\n */\n\nimport type { Editor, KeyDownPayload, SobreePlugin } from \"@sobree/core\";\n\nexport interface KeyboardOptions {\n /**\n * Extra key→command mappings to add on top of the defaults. Last\n * matcher wins on conflict — pass your own to override a default.\n */\n bindings?: KeyBinding[];\n}\n\n/**\n * One key binding: a predicate over the editor's `KeyDownPayload`\n * plus the command name to dispatch when it matches. The predicate\n * is called for every keydown — keep it cheap (modifier checks +\n * `e.key` switch).\n */\nexport interface KeyBinding {\n match: (e: KeyDownPayload) => boolean;\n command: string;\n}\n\n/**\n * `SobreePlugin` factory — the recommended way to mount this. Hand\n * the result to `createSobree({ plugins: [...] })` and `createSobree`\n * wires up setup + destroy automatically.\n *\n * ```ts\n * import { keyboard } from \"@sobree/keyboard\";\n * createSobree(\"#editor\", { plugins: [keyboard()] });\n * // or with custom bindings layered on top of the defaults:\n * createSobree(\"#editor\", { plugins: [keyboard({ bindings: [...] })] });\n * ```\n */\nexport function keyboard(opts?: KeyboardOptions): SobreePlugin {\n return {\n name: \"keyboard\",\n setup({ editor }) {\n const detach = attachKeyboard(editor, opts);\n return { destroy: detach };\n },\n };\n}\n\n/**\n * Lower-level: mount the keyboard handler directly on an Editor.\n * Useful when you've skipped `createSobree()` and instantiated\n * `Sobree` / `Editor` yourself. Returns an unsubscribe.\n *\n * ```ts\n * import { Sobree } from \"@sobree/core\";\n * import { attachKeyboard } from \"@sobree/keyboard\";\n * const sobree = new Sobree(host);\n * const detach = attachKeyboard(sobree.editor);\n * ```\n */\nexport function attachKeyboard(editor: Editor, opts: KeyboardOptions = {}): () => void {\n const all = [...DEFAULT_BINDINGS, ...(opts.bindings ?? [])];\n return editor.on(\"keydown\", (e) => {\n // Reverse order so user-supplied overrides shadow defaults.\n for (let i = all.length - 1; i >= 0; i--) {\n const b = all[i]!;\n if (b.match(e)) {\n e.preventDefault();\n e.stopPropagation();\n editor.commands.execute(b.command);\n return;\n }\n }\n });\n}\n\n/**\n * Default keystroke → command mappings shipped with the plugin.\n * Exported so embedders extending the bindings can spread them in.\n */\nexport const DEFAULT_BINDINGS: readonly KeyBinding[] = [\n // Section break — Word uses Ctrl/Cmd+Shift+Enter for the same op.\n {\n match: (e) => cmd(e) && e.shift && !e.alt && (e.key === \"Enter\" || e.code === \"Enter\"),\n command: \"section.insertBreakAfter\",\n },\n // Undo / Redo. Cmd+Z is undo on every platform; Cmd+Shift+Z is the\n // macOS-native redo combo, Cmd+Y is the Windows-native one. Bind\n // both so muscle memory works either way.\n {\n match: (e) => cmd(e) && !e.shift && !e.alt && (e.key === \"z\" || e.key === \"Z\"),\n command: \"history.undo\",\n },\n {\n match: (e) => cmd(e) && e.shift && !e.alt && (e.key === \"z\" || e.key === \"Z\"),\n command: \"history.redo\",\n },\n {\n match: (e) => cmd(e) && !e.shift && !e.alt && (e.key === \"y\" || e.key === \"Y\"),\n command: \"history.redo\",\n },\n // Marks — single-letter combos, no shift (except Strike).\n { match: plain(\"b\"), command: \"mark.toggle.bold\" },\n { match: plain(\"i\"), command: \"mark.toggle.italic\" },\n { match: plain(\"u\"), command: \"mark.toggle.underline\" },\n { match: plain(\".\"), command: \"mark.toggle.superscript\" },\n { match: plain(\",\"), command: \"mark.toggle.subscript\" },\n {\n match: (e) => cmd(e) && e.shift && !e.alt && (e.key === \"s\" || e.key === \"S\"),\n command: \"mark.toggle.strike\",\n },\n];\n\nfunction cmd(e: KeyDownPayload): boolean {\n return e.ctrl || e.meta;\n}\n\nfunction plain(key: string): (e: KeyDownPayload) => boolean {\n return (e) => cmd(e) && !e.shift && !e.alt && e.key === key;\n}\n"],"names":["keyboard","opts","editor","attachKeyboard","all","DEFAULT_BINDINGS","e","i","b","cmd","plain","key"],"mappings":"AA+CO,SAASA,EAASC,GAAsC;AAC7D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,EAAE,QAAAC,KAAU;AAEhB,aAAO,EAAE,SADMC,EAAeD,GAAQD,CAAI,EACxB;AAAA,IACpB;AAAA,EAAA;AAEJ;AAcO,SAASE,EAAeD,GAAgBD,IAAwB,IAAgB;AACrF,QAAMG,IAAM,CAAC,GAAGC,GAAkB,GAAIJ,EAAK,YAAY,EAAG;AAC1D,SAAOC,EAAO,GAAG,WAAW,CAACI,MAAM;AAEjC,aAASC,IAAIH,EAAI,SAAS,GAAGG,KAAK,GAAGA,KAAK;AACxC,YAAMC,IAAIJ,EAAIG,CAAC;AACf,UAAIC,EAAE,MAAMF,CAAC,GAAG;AACd,QAAAA,EAAE,eAAA,GACFA,EAAE,gBAAA,GACFJ,EAAO,SAAS,QAAQM,EAAE,OAAO;AACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAMO,MAAMH,IAA0C;AAAA;AAAA,EAErD;AAAA,IACE,OAAO,CAACC,MAAMG,EAAIH,CAAC,KAAKA,EAAE,SAAS,CAACA,EAAE,QAAQA,EAAE,QAAQ,WAAWA,EAAE,SAAS;AAAA,IAC9E,SAAS;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAKX;AAAA,IACE,OAAO,CAACA,MAAMG,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",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"LICENSE"
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@sobree/core": "0.1.
|
|
43
|
+
"@sobree/core": "0.1.11"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"typecheck": "tsc --noEmit",
|