@embedpdf/plugin-commands 2.0.0-next.0
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/LICENSE +21 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +316 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions.d.ts +25 -0
- package/dist/lib/commands-plugin.d.ts +31 -0
- package/dist/lib/index.d.ts +8 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/lib/types.d.ts +98 -0
- package/dist/preact/adapter.d.ts +5 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -0
- package/dist/preact/index.cjs.map +1 -0
- package/dist/preact/index.d.ts +1 -0
- package/dist/preact/index.js +89 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +88 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared/components/index.d.ts +1 -0
- package/dist/shared/components/keyboard-shortcuts.d.ts +6 -0
- package/dist/shared/hooks/index.d.ts +1 -0
- package/dist/shared/hooks/use-commands.d.ts +23 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared/utils/index.d.ts +1 -0
- package/dist/shared/utils/keyboard-handler.d.ts +10 -0
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/keyboard-shortcuts.d.ts +6 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-commands.d.ts +23 -0
- package/dist/shared-preact/index.d.ts +4 -0
- package/dist/shared-preact/utils/index.d.ts +1 -0
- package/dist/shared-preact/utils/keyboard-handler.d.ts +10 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/keyboard-shortcuts.d.ts +6 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-commands.d.ts +23 -0
- package/dist/shared-react/index.d.ts +4 -0
- package/dist/shared-react/utils/index.d.ts +1 -0
- package/dist/shared-react/utils/keyboard-handler.d.ts +10 -0
- package/dist/shared-vue/utils/index.d.ts +1 -0
- package/dist/shared-vue/utils/keyboard-handler.d.ts +10 -0
- package/dist/svelte/components/KeyboardShortcuts.svelte.d.ts +18 -0
- package/dist/svelte/components/index.d.ts +1 -0
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-commands.svelte.d.ts +21 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +4 -0
- package/dist/svelte/index.js +90 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/components/keyboard-shortcuts.vue.d.ts +3 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-commands.d.ts +46 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +4 -0
- package/dist/vue/index.js +90 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CommandsPlugin, ResolvedCommand } from '../../lib/index.ts';
|
|
2
|
+
export declare const useCommandsCapability: () => {
|
|
3
|
+
provides: Readonly<import('../../lib/index.ts').CommandsCapability> | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useCommandsPlugin: () => {
|
|
8
|
+
plugin: CommandsPlugin | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
interface UseCommandReturn {
|
|
13
|
+
command: ResolvedCommand | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Hook to get a reactive command for a specific document
|
|
17
|
+
* @param getCommandId Function that returns the command ID
|
|
18
|
+
* @param getDocumentId Function that returns the document ID
|
|
19
|
+
*/
|
|
20
|
+
export declare const useCommand: (getCommandId: () => string, getDocumentId: () => string) => UseCommandReturn;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-commands");require("svelte/internal/disclose-version"),require("svelte/internal/flags/legacy");const n=require("svelte/internal/client"),r=require("svelte"),o=require("@embedpdf/core/svelte");function s(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const i=s(n),a=()=>o.useCapability(t.CommandsPlugin.id);function u(e,t){i.push(t,!1);const{provides:n}=a();r.onMount(()=>{if(!n)return;const e=function(e){return t=>{const n=t.target;if("INPUT"===n.tagName||"TEXTAREA"===n.tagName||n.isContentEditable)return;const r=function(e){const t=[];e.ctrlKey&&t.push("ctrl"),e.shiftKey&&t.push("shift"),e.altKey&&t.push("alt"),e.metaKey&&t.push("meta");const n=e.key.toLowerCase();return["control","shift","alt","meta"].includes(n)?null:[...t,n].sort().join("+")}(t);if(!r)return;const o=e.getCommandByShortcut(r);if(!o)return;const s=e.resolve(o.id);!s.disabled&&s.visible&&(t.preventDefault(),t.stopPropagation(),e.execute(o.id,void 0,"keyboard"))}}(n);return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)}),i.init(),i.pop()}const l=e.createPluginPackage(t.CommandsPluginPackage).addUtility(u).build();exports.CommandsPluginPackage=l,exports.KeyboardShortcuts=u,exports.useCommand=(e,t)=>{const n=a();let r=i.state(null);const o=i.derived(e),s=i.derived(t);return i.user_effect(()=>{const e=n.provides,t=i.get(o),a=i.get(s);if(e&&t&&a)return i.set(r,e.resolve(t,a),!0),e.onCommandStateChanged(n=>{n.commandId===t&&n.documentId===a&&i.set(r,e.resolve(t,a),!0)});i.set(r,null)}),{get command(){return i.get(r)}}},exports.useCommandsCapability=a,exports.useCommandsPlugin=()=>o.usePlugin(t.CommandsPlugin.id),Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-commands.svelte.ts","../../src/svelte/components/KeyboardShortcuts.svelte","../../src/shared/utils/keyboard-handler.ts","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { CommandsPlugin, ResolvedCommand } from '@embedpdf/plugin-commands';\n\nexport const useCommandsCapability = () => useCapability<CommandsPlugin>(CommandsPlugin.id);\nexport const useCommandsPlugin = () => usePlugin<CommandsPlugin>(CommandsPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseCommandReturn {\n command: ResolvedCommand | null;\n}\n\n/**\n * Hook to get a reactive command for a specific document\n * @param getCommandId Function that returns the command ID\n * @param getDocumentId Function that returns the document ID\n */\nexport const useCommand = (\n getCommandId: () => string,\n getDocumentId: () => string,\n): UseCommandReturn => {\n const capability = useCommandsCapability();\n\n let command = $state<ResolvedCommand | null>(null);\n\n // Reactive commandId and documentId\n const commandId = $derived(getCommandId());\n const documentId = $derived(getDocumentId());\n\n $effect(() => {\n const provides = capability.provides;\n const cmdId = commandId;\n const docId = documentId;\n\n if (!provides || !cmdId || !docId) {\n command = null;\n return;\n }\n\n command = provides.resolve(cmdId, docId);\n\n return provides.onCommandStateChanged((event) => {\n if (event.commandId === cmdId && event.documentId === docId) {\n command = provides.resolve(cmdId, docId);\n }\n });\n });\n\n return {\n get command() {\n return command;\n },\n };\n};\n","<script lang=\"ts\">\n import { onMount } from 'svelte';\n import { useCommandsCapability } from '../hooks';\n import { createKeyDownHandler } from '../../shared/utils';\n\n const { provides: commands } = useCommandsCapability();\n\n onMount(() => {\n if (!commands) return;\n\n const handleKeyDown = createKeyDownHandler(commands);\n\n document.addEventListener('keydown', handleKeyDown);\n return () => document.removeEventListener('keydown', handleKeyDown);\n });\n</script>\n\n<!-- This component is only used to set up keyboard shortcuts when the plugin is initialized. -->\n","import { CommandsCapability } from '../../lib/types';\n\n/**\n * Build a shortcut string from a keyboard event\n * @example Ctrl+Shift+A -> \"ctrl+shift+a\"\n */\nexport function buildShortcutString(event: KeyboardEvent): string | null {\n const modifiers: string[] = [];\n\n if (event.ctrlKey) modifiers.push('ctrl');\n if (event.shiftKey) modifiers.push('shift');\n if (event.altKey) modifiers.push('alt');\n if (event.metaKey) modifiers.push('meta');\n\n // Only add non-modifier keys\n const key = event.key.toLowerCase();\n const isModifier = ['control', 'shift', 'alt', 'meta'].includes(key);\n\n if (isModifier) {\n return null; // Just a modifier, no command\n }\n\n const parts = [...modifiers, key];\n return parts.sort().join('+');\n}\n\n/**\n * Handle keyboard events and execute commands based on shortcuts\n */\nexport function createKeyDownHandler(commands: CommandsCapability) {\n return (event: KeyboardEvent) => {\n // Don't handle shortcuts if target is an input, textarea, or contentEditable\n const target = event.target as HTMLElement;\n if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {\n return;\n }\n\n const shortcut = buildShortcutString(event);\n if (!shortcut) return;\n\n const command = commands.getCommandByShortcut(shortcut);\n if (!command) return;\n\n // Resolve without document ID - will use active document\n const resolved = commands.resolve(command.id);\n\n if (resolved.disabled || !resolved.visible) {\n return;\n }\n\n // Execute and prevent default (documentId is optional now)\n event.preventDefault();\n event.stopPropagation();\n commands.execute(command.id, undefined, 'keyboard');\n };\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { CommandsPluginPackage as BaseCommandsPackage } from '@embedpdf/plugin-commands';\n\nimport { KeyboardShortcuts } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-commands';\n\nexport const CommandsPluginPackage = createPluginPackage(BaseCommandsPackage)\n .addUtility(KeyboardShortcuts)\n .build();\n"],"names":["useCommandsCapability","useCapability","CommandsPlugin","id","provides","commands","onMount","handleKeyDown","event","target","tagName","isContentEditable","shortcut","modifiers","ctrlKey","push","shiftKey","altKey","metaKey","key","toLowerCase","includes","sort","join","buildShortcutString","command","getCommandByShortcut","resolved","resolve","disabled","visible","preventDefault","stopPropagation","execute","createKeyDownHandler","document","addEventListener","removeEventListener","CommandsPluginPackage","createPluginPackage","BaseCommandsPackage","addUtility","KeyboardShortcuts","build","getCommandId","getDocumentId","capability","commandId","documentId","$","user_effect","cmdId","docId","set","onCommandStateChanged","usePlugin"],"mappings":"smBAGaA,EAAA,IAA8BC,gBAA8BC,EAAAA,eAAeC,uCCE9EC,SAAUC,GAAaL,IAE/BM,EAAAA,QAAO,SACAD,EAAQ,aAEPE,ECmBH,SAA8BF,GACnC,OAAQG,IAEN,MAAMC,EAASD,EAAMC,OACrB,GAAuB,UAAnBA,EAAOC,SAA0C,aAAnBD,EAAOC,SAA0BD,EAAOE,kBACxE,OAGF,MAAMC,EA/BH,SAA6BJ,GAClC,MAAMK,EAAsB,GAExBL,EAAMM,SAASD,EAAUE,KAAK,QAC9BP,EAAMQ,UAAUH,EAAUE,KAAK,SAC/BP,EAAMS,QAAQJ,EAAUE,KAAK,OAC7BP,EAAMU,SAASL,EAAUE,KAAK,QAGlC,MAAMI,EAAMX,EAAMW,IAAIC,cAGtB,MAFmB,CAAC,UAAW,QAAS,MAAO,QAAQC,SAASF,GAGvD,KAGK,IAAIN,EAAWM,GAChBG,OAAOC,KAAK,IAC3B,CAaqBC,CAAoBhB,GACrC,IAAKI,EAAU,OAEf,MAAMa,EAAUpB,EAASqB,qBAAqBd,GAC9C,IAAKa,EAAS,OAGd,MAAME,EAAWtB,EAASuB,QAAQH,EAAQtB,KAEtCwB,EAASE,UAAaF,EAASG,UAKnCtB,EAAMuB,iBACNvB,EAAMwB,kBACN3B,EAAS4B,QAAQR,EAAQtB,QAAI,EAAW,aAE5C,CD7C0B+B,CAAqB7B,GAG9B,OADb8B,SAASC,iBAAiB,UAAW7B,GACxB,IAAA4B,SAASE,oBAAoB,UAAW9B,qBAEzD,CENO,MAAM+B,EAAwBC,EAAAA,oBAAoBC,EAAAA,uBACtDC,WAAWC,GACXC,uFHKU,CACXC,EACAC,KAEM,MAAAC,EAAa9C,IAEf,IAAAyB,UAAyC,MAGvC,MAAAsB,YAAqBH,GACrBI,YAAsBH,UAE5BI,EAAAC,uBACQ9C,EAAW0C,EAAW1C,SACtB+C,QAAQJ,GACRK,QAAQJ,GAET,GAAA5C,GAAa+C,GAAUC,EAOrB,OAFPH,EAAAI,IAAA5B,EAAUrB,EAASwB,QAAQuB,EAAOC,IAAK,GAEhChD,EAASkD,sBAAuB9C,IACjCA,EAAMuC,YAAcI,GAAS3C,EAAMwC,aAAeI,GACpDH,EAAAI,IAAA5B,EAAUrB,EAASwB,QAAQuB,EAAOC,IAAK,KARzCH,EAAAI,IAAA5B,EAAU,SAcR,WAAAA,gBACKA,EACT,8DA9CS,IAA0B8B,YAA0BrD,EAAAA,eAAeC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './hooks';
|
|
2
|
+
export * from './components';
|
|
3
|
+
export * from '../lib/index.ts';
|
|
4
|
+
export declare const CommandsPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').CommandsPlugin, import('../lib/index.ts').CommandsPluginConfig, import('../lib/index.ts').CommandsState, import('src/lib/actions').CommandsAction>>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createPluginPackage } from "@embedpdf/core";
|
|
2
|
+
import { CommandsPlugin, CommandsPluginPackage as CommandsPluginPackage$1 } from "@embedpdf/plugin-commands";
|
|
3
|
+
export * from "@embedpdf/plugin-commands";
|
|
4
|
+
import "svelte/internal/disclose-version";
|
|
5
|
+
import "svelte/internal/flags/legacy";
|
|
6
|
+
import * as $ from "svelte/internal/client";
|
|
7
|
+
import { onMount } from "svelte";
|
|
8
|
+
import { useCapability, usePlugin } from "@embedpdf/core/svelte";
|
|
9
|
+
const useCommandsCapability = () => useCapability(CommandsPlugin.id);
|
|
10
|
+
const useCommandsPlugin = () => usePlugin(CommandsPlugin.id);
|
|
11
|
+
const useCommand = (getCommandId, getDocumentId) => {
|
|
12
|
+
const capability = useCommandsCapability();
|
|
13
|
+
let command = $.state(null);
|
|
14
|
+
const commandId = $.derived(getCommandId);
|
|
15
|
+
const documentId = $.derived(getDocumentId);
|
|
16
|
+
$.user_effect(() => {
|
|
17
|
+
const provides = capability.provides;
|
|
18
|
+
const cmdId = $.get(commandId);
|
|
19
|
+
const docId = $.get(documentId);
|
|
20
|
+
if (!provides || !cmdId || !docId) {
|
|
21
|
+
$.set(command, null);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
$.set(command, provides.resolve(cmdId, docId), true);
|
|
25
|
+
return provides.onCommandStateChanged((event) => {
|
|
26
|
+
if (event.commandId === cmdId && event.documentId === docId) {
|
|
27
|
+
$.set(command, provides.resolve(cmdId, docId), true);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
get command() {
|
|
33
|
+
return $.get(command);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
function buildShortcutString(event) {
|
|
38
|
+
const modifiers = [];
|
|
39
|
+
if (event.ctrlKey) modifiers.push("ctrl");
|
|
40
|
+
if (event.shiftKey) modifiers.push("shift");
|
|
41
|
+
if (event.altKey) modifiers.push("alt");
|
|
42
|
+
if (event.metaKey) modifiers.push("meta");
|
|
43
|
+
const key = event.key.toLowerCase();
|
|
44
|
+
const isModifier = ["control", "shift", "alt", "meta"].includes(key);
|
|
45
|
+
if (isModifier) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const parts = [...modifiers, key];
|
|
49
|
+
return parts.sort().join("+");
|
|
50
|
+
}
|
|
51
|
+
function createKeyDownHandler(commands) {
|
|
52
|
+
return (event) => {
|
|
53
|
+
const target = event.target;
|
|
54
|
+
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const shortcut = buildShortcutString(event);
|
|
58
|
+
if (!shortcut) return;
|
|
59
|
+
const command = commands.getCommandByShortcut(shortcut);
|
|
60
|
+
if (!command) return;
|
|
61
|
+
const resolved = commands.resolve(command.id);
|
|
62
|
+
if (resolved.disabled || !resolved.visible) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
event.stopPropagation();
|
|
67
|
+
commands.execute(command.id, void 0, "keyboard");
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function KeyboardShortcuts($$anchor, $$props) {
|
|
71
|
+
$.push($$props, false);
|
|
72
|
+
const { provides: commands } = useCommandsCapability();
|
|
73
|
+
onMount(() => {
|
|
74
|
+
if (!commands) return;
|
|
75
|
+
const handleKeyDown = createKeyDownHandler(commands);
|
|
76
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
77
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
78
|
+
});
|
|
79
|
+
$.init();
|
|
80
|
+
$.pop();
|
|
81
|
+
}
|
|
82
|
+
const CommandsPluginPackage = createPluginPackage(CommandsPluginPackage$1).addUtility(KeyboardShortcuts).build();
|
|
83
|
+
export {
|
|
84
|
+
CommandsPluginPackage,
|
|
85
|
+
KeyboardShortcuts,
|
|
86
|
+
useCommand,
|
|
87
|
+
useCommandsCapability,
|
|
88
|
+
useCommandsPlugin
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-commands.svelte.ts","../../src/shared/utils/keyboard-handler.ts","../../src/svelte/components/KeyboardShortcuts.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { CommandsPlugin, ResolvedCommand } from '@embedpdf/plugin-commands';\n\nexport const useCommandsCapability = () => useCapability<CommandsPlugin>(CommandsPlugin.id);\nexport const useCommandsPlugin = () => usePlugin<CommandsPlugin>(CommandsPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseCommandReturn {\n command: ResolvedCommand | null;\n}\n\n/**\n * Hook to get a reactive command for a specific document\n * @param getCommandId Function that returns the command ID\n * @param getDocumentId Function that returns the document ID\n */\nexport const useCommand = (\n getCommandId: () => string,\n getDocumentId: () => string,\n): UseCommandReturn => {\n const capability = useCommandsCapability();\n\n let command = $state<ResolvedCommand | null>(null);\n\n // Reactive commandId and documentId\n const commandId = $derived(getCommandId());\n const documentId = $derived(getDocumentId());\n\n $effect(() => {\n const provides = capability.provides;\n const cmdId = commandId;\n const docId = documentId;\n\n if (!provides || !cmdId || !docId) {\n command = null;\n return;\n }\n\n command = provides.resolve(cmdId, docId);\n\n return provides.onCommandStateChanged((event) => {\n if (event.commandId === cmdId && event.documentId === docId) {\n command = provides.resolve(cmdId, docId);\n }\n });\n });\n\n return {\n get command() {\n return command;\n },\n };\n};\n","import { CommandsCapability } from '../../lib/types';\n\n/**\n * Build a shortcut string from a keyboard event\n * @example Ctrl+Shift+A -> \"ctrl+shift+a\"\n */\nexport function buildShortcutString(event: KeyboardEvent): string | null {\n const modifiers: string[] = [];\n\n if (event.ctrlKey) modifiers.push('ctrl');\n if (event.shiftKey) modifiers.push('shift');\n if (event.altKey) modifiers.push('alt');\n if (event.metaKey) modifiers.push('meta');\n\n // Only add non-modifier keys\n const key = event.key.toLowerCase();\n const isModifier = ['control', 'shift', 'alt', 'meta'].includes(key);\n\n if (isModifier) {\n return null; // Just a modifier, no command\n }\n\n const parts = [...modifiers, key];\n return parts.sort().join('+');\n}\n\n/**\n * Handle keyboard events and execute commands based on shortcuts\n */\nexport function createKeyDownHandler(commands: CommandsCapability) {\n return (event: KeyboardEvent) => {\n // Don't handle shortcuts if target is an input, textarea, or contentEditable\n const target = event.target as HTMLElement;\n if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {\n return;\n }\n\n const shortcut = buildShortcutString(event);\n if (!shortcut) return;\n\n const command = commands.getCommandByShortcut(shortcut);\n if (!command) return;\n\n // Resolve without document ID - will use active document\n const resolved = commands.resolve(command.id);\n\n if (resolved.disabled || !resolved.visible) {\n return;\n }\n\n // Execute and prevent default (documentId is optional now)\n event.preventDefault();\n event.stopPropagation();\n commands.execute(command.id, undefined, 'keyboard');\n };\n}\n","<script lang=\"ts\">\n import { onMount } from 'svelte';\n import { useCommandsCapability } from '../hooks';\n import { createKeyDownHandler } from '../../shared/utils';\n\n const { provides: commands } = useCommandsCapability();\n\n onMount(() => {\n if (!commands) return;\n\n const handleKeyDown = createKeyDownHandler(commands);\n\n document.addEventListener('keydown', handleKeyDown);\n return () => document.removeEventListener('keydown', handleKeyDown);\n });\n</script>\n\n<!-- This component is only used to set up keyboard shortcuts when the plugin is initialized. -->\n","import { createPluginPackage } from '@embedpdf/core';\nimport { CommandsPluginPackage as BaseCommandsPackage } from '@embedpdf/plugin-commands';\n\nimport { KeyboardShortcuts } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-commands';\n\nexport const CommandsPluginPackage = createPluginPackage(BaseCommandsPackage)\n .addUtility(KeyboardShortcuts)\n .build();\n"],"names":["BaseCommandsPackage"],"mappings":";;;;;;;;AAGa,MAAA,wBAAA,MAA8B,cAA8B,eAAe,EAAE;AAC7E,MAAA,oBAAA,MAA0B,UAA0B,eAAe,EAAE;AAYrE,MAAA,aAAA,CACX,cACA,kBACqB;AACf,QAAA,aAAa,sBAAA;AAEf,MAAA,kBAAyC,IAAI;AAG3C,QAAA,sBAAqB,YAAA;AACrB,QAAA,uBAAsB,aAAA;AAE5B,IAAA,kBAAc;UACN,WAAW,WAAW;AACtB,UAAA,cAAQ,SAAA;AACR,UAAA,cAAQ,UAAA;AAET,QAAA,CAAA,YAAA,CAAa,SAAA,CAAU,OAAO;AACjC,QAAA,IAAA,SAAU,IAAA;;IAEZ;AAEA,MAAA,IAAA,SAAU,SAAS,QAAQ,OAAO,KAAK,GAAA,IAAA;AAEhC,WAAA,SAAS,sBAAA,CAAuB,UAAU;UAC3C,MAAM,cAAc,SAAS,MAAM,eAAe,OAAO;AAC3D,UAAA,IAAA,SAAU,SAAS,QAAQ,OAAO,KAAK,GAAA,IAAA;AAAA,MACzC;AAAA,IACF,CAAC;AAAA,EACH,CAAC;;IAGK,IAAA,UAAU;mBACL,OAAA;AAAA,IACT;AAAA;AAEJ;AC9CO,SAAS,oBAAoB,OAAqC;AACvE,QAAM,YAAsB,CAAA;AAE5B,MAAI,MAAM,QAAS,WAAU,KAAK,MAAM;AACxC,MAAI,MAAM,SAAU,WAAU,KAAK,OAAO;AAC1C,MAAI,MAAM,OAAQ,WAAU,KAAK,KAAK;AACtC,MAAI,MAAM,QAAS,WAAU,KAAK,MAAM;AAGxC,QAAM,MAAM,MAAM,IAAI,YAAA;AACtB,QAAM,aAAa,CAAC,WAAW,SAAS,OAAO,MAAM,EAAE,SAAS,GAAG;AAEnE,MAAI,YAAY;AACd,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,CAAC,GAAG,WAAW,GAAG;AAChC,SAAO,MAAM,OAAO,KAAK,GAAG;AAC9B;AAKO,SAAS,qBAAqB,UAA8B;AACjE,SAAO,CAAC,UAAyB;AAE/B,UAAM,SAAS,MAAM;AACrB,QAAI,OAAO,YAAY,WAAW,OAAO,YAAY,cAAc,OAAO,mBAAmB;AAC3F;AAAA,IACF;AAEA,UAAM,WAAW,oBAAoB,KAAK;AAC1C,QAAI,CAAC,SAAU;AAEf,UAAM,UAAU,SAAS,qBAAqB,QAAQ;AACtD,QAAI,CAAC,QAAS;AAGd,UAAM,WAAW,SAAS,QAAQ,QAAQ,EAAE;AAE5C,QAAI,SAAS,YAAY,CAAC,SAAS,SAAS;AAC1C;AAAA,IACF;AAGA,UAAM,eAAA;AACN,UAAM,gBAAA;AACN,aAAS,QAAQ,QAAQ,IAAI,QAAW,UAAU;AAAA,EACpD;AACF;8CCvDA;;UAKU,UAAU,SAAQ,IAAK,sBAAqB;AAEpD,UAAO,MAAO;SACP,SAAQ;UAEP,gBAAgB,qBAAqB,QAAQ;AAEnD,aAAS,iBAAiB,WAAW,aAAa;AACrC,WAAA,MAAA,SAAS,oBAAoB,WAAW,aAAa;AAAA,EACpE,CAAC;;;AACH;ACNO,MAAM,wBAAwB,oBAAoBA,uBAAmB,EACzE,WAAW,iBAAiB,EAC5B,MAAA;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as KeyboardShortcuts } from './keyboard-shortcuts.vue';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-commands';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import { CommandsPlugin } from '../../lib/index.ts';
|
|
3
|
+
export declare const useCommandsCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').CommandsCapability>>;
|
|
4
|
+
export declare const useCommandsPlugin: () => import('@embedpdf/core/vue').PluginState<CommandsPlugin>;
|
|
5
|
+
/**
|
|
6
|
+
* Hook to get a reactive command for a specific document
|
|
7
|
+
* @param commandId Command ID (can be ref, computed, getter, or plain value)
|
|
8
|
+
* @param documentId Document ID (can be ref, computed, getter, or plain value)
|
|
9
|
+
*/
|
|
10
|
+
export declare const useCommand: (commandId: MaybeRefOrGetter<string>, documentId: MaybeRefOrGetter<string>) => Readonly<import('vue').Ref<{
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly label: string;
|
|
13
|
+
readonly icon?: string | undefined;
|
|
14
|
+
readonly iconProps?: {
|
|
15
|
+
readonly primaryColor?: string | undefined;
|
|
16
|
+
readonly secondaryColor?: string | undefined;
|
|
17
|
+
readonly className?: string | undefined;
|
|
18
|
+
readonly title?: string | undefined;
|
|
19
|
+
} | undefined;
|
|
20
|
+
readonly active: boolean;
|
|
21
|
+
readonly disabled: boolean;
|
|
22
|
+
readonly visible: boolean;
|
|
23
|
+
readonly shortcuts?: readonly string[] | undefined;
|
|
24
|
+
readonly shortcutLabel?: string | undefined;
|
|
25
|
+
readonly category?: string | undefined;
|
|
26
|
+
readonly description?: string | undefined;
|
|
27
|
+
readonly execute: () => void;
|
|
28
|
+
} | null, {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly label: string;
|
|
31
|
+
readonly icon?: string | undefined;
|
|
32
|
+
readonly iconProps?: {
|
|
33
|
+
readonly primaryColor?: string | undefined;
|
|
34
|
+
readonly secondaryColor?: string | undefined;
|
|
35
|
+
readonly className?: string | undefined;
|
|
36
|
+
readonly title?: string | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
readonly active: boolean;
|
|
39
|
+
readonly disabled: boolean;
|
|
40
|
+
readonly visible: boolean;
|
|
41
|
+
readonly shortcuts?: readonly string[] | undefined;
|
|
42
|
+
readonly shortcutLabel?: string | undefined;
|
|
43
|
+
readonly category?: string | undefined;
|
|
44
|
+
readonly description?: string | undefined;
|
|
45
|
+
readonly execute: () => void;
|
|
46
|
+
} | null>>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-commands"),n=require("vue"),o=require("@embedpdf/core/vue"),r=()=>o.useCapability(t.CommandsPlugin.id);const u=n.defineComponent({__name:"keyboard-shortcuts",setup(e){const{provides:t}=r();let o=null;return n.onMounted(()=>{if(!t.value)return;const e=function(e){return t=>{const n=t.target;if("INPUT"===n.tagName||"TEXTAREA"===n.tagName||n.isContentEditable)return;const o=function(e){const t=[];e.ctrlKey&&t.push("ctrl"),e.shiftKey&&t.push("shift"),e.altKey&&t.push("alt"),e.metaKey&&t.push("meta");const n=e.key.toLowerCase();return["control","shift","alt","meta"].includes(n)?null:[...t,n].sort().join("+")}(t);if(!o)return;const r=e.getCommandByShortcut(o);if(!r)return;const u=e.resolve(r.id);!u.disabled&&u.visible&&(t.preventDefault(),t.stopPropagation(),e.execute(r.id,void 0,"keyboard"))}}(t.value);document.addEventListener("keydown",e),o=()=>document.removeEventListener("keydown",e)}),n.onUnmounted(()=>{null==o||o()}),(e,t)=>null}}),a=e.createPluginPackage(t.CommandsPluginPackage).addUtility(u).build();exports.CommandsPluginPackage=a,exports.KeyboardShortcuts=u,exports.useCommand=(e,t)=>{const{provides:o}=r(),u=n.ref(null);return n.watch([o,()=>n.toValue(e),()=>n.toValue(t)],([e,t,n],o,r)=>{if(!e)return void(u.value=null);u.value=e.resolve(t,n);r(e.onCommandStateChanged(o=>{o.commandId===t&&o.documentId===n&&(u.value=e.resolve(t,n))}))},{immediate:!0}),n.readonly(u)},exports.useCommandsCapability=r,exports.useCommandsPlugin=()=>o.usePlugin(t.CommandsPlugin.id),Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-commands.ts","../../src/vue/components/keyboard-shortcuts.vue","../../src/shared/utils/keyboard-handler.ts","../../src/vue/index.ts"],"sourcesContent":["import { ref, watch, readonly, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { CommandsPlugin, ResolvedCommand } from '@embedpdf/plugin-commands';\n\nexport const useCommandsCapability = () => useCapability<CommandsPlugin>(CommandsPlugin.id);\nexport const useCommandsPlugin = () => usePlugin<CommandsPlugin>(CommandsPlugin.id);\n\n/**\n * Hook to get a reactive command for a specific document\n * @param commandId Command ID (can be ref, computed, getter, or plain value)\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useCommand = (\n commandId: MaybeRefOrGetter<string>,\n documentId: MaybeRefOrGetter<string>,\n) => {\n const { provides } = useCommandsCapability();\n const command = ref<ResolvedCommand | null>(null);\n\n watch(\n [provides, () => toValue(commandId), () => toValue(documentId)],\n ([providesValue, cmdId, docId], _, onCleanup) => {\n if (!providesValue) {\n command.value = null;\n return;\n }\n\n command.value = providesValue.resolve(cmdId, docId);\n\n const unsubscribe = providesValue.onCommandStateChanged((event) => {\n if (event.commandId === cmdId && event.documentId === docId) {\n command.value = providesValue.resolve(cmdId, docId);\n }\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n );\n\n return readonly(command);\n};\n","<template>\n <!-- This component is only used to set up keyboard shortcuts when the plugin is initialized -->\n</template>\n\n<script setup lang=\"ts\">\nimport { onMounted, onUnmounted } from 'vue';\nimport { useCommandsCapability } from '../hooks';\nimport { createKeyDownHandler } from '../../shared/utils';\n\nconst { provides: commands } = useCommandsCapability();\n\nlet cleanup: (() => void) | null = null;\n\nonMounted(() => {\n if (!commands.value) return;\n\n const handleKeyDown = createKeyDownHandler(commands.value);\n\n document.addEventListener('keydown', handleKeyDown);\n cleanup = () => document.removeEventListener('keydown', handleKeyDown);\n});\n\nonUnmounted(() => {\n cleanup?.();\n});\n</script>\n","import { CommandsCapability } from '../../lib/types';\n\n/**\n * Build a shortcut string from a keyboard event\n * @example Ctrl+Shift+A -> \"ctrl+shift+a\"\n */\nexport function buildShortcutString(event: KeyboardEvent): string | null {\n const modifiers: string[] = [];\n\n if (event.ctrlKey) modifiers.push('ctrl');\n if (event.shiftKey) modifiers.push('shift');\n if (event.altKey) modifiers.push('alt');\n if (event.metaKey) modifiers.push('meta');\n\n // Only add non-modifier keys\n const key = event.key.toLowerCase();\n const isModifier = ['control', 'shift', 'alt', 'meta'].includes(key);\n\n if (isModifier) {\n return null; // Just a modifier, no command\n }\n\n const parts = [...modifiers, key];\n return parts.sort().join('+');\n}\n\n/**\n * Handle keyboard events and execute commands based on shortcuts\n */\nexport function createKeyDownHandler(commands: CommandsCapability) {\n return (event: KeyboardEvent) => {\n // Don't handle shortcuts if target is an input, textarea, or contentEditable\n const target = event.target as HTMLElement;\n if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {\n return;\n }\n\n const shortcut = buildShortcutString(event);\n if (!shortcut) return;\n\n const command = commands.getCommandByShortcut(shortcut);\n if (!command) return;\n\n // Resolve without document ID - will use active document\n const resolved = commands.resolve(command.id);\n\n if (resolved.disabled || !resolved.visible) {\n return;\n }\n\n // Execute and prevent default (documentId is optional now)\n event.preventDefault();\n event.stopPropagation();\n commands.execute(command.id, undefined, 'keyboard');\n };\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { CommandsPluginPackage as BaseCommandsPackage } from '@embedpdf/plugin-commands';\n\nimport { KeyboardShortcuts } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-commands';\n\nexport const CommandsPluginPackage = createPluginPackage(BaseCommandsPackage)\n .addUtility(KeyboardShortcuts)\n .build();\n"],"names":["useCommandsCapability","useCapability","CommandsPlugin","id","provides","commands","cleanup","onMounted","value","handleKeyDown","event","target","tagName","isContentEditable","shortcut","modifiers","ctrlKey","push","shiftKey","altKey","metaKey","key","toLowerCase","includes","sort","join","buildShortcutString","command","getCommandByShortcut","resolved","resolve","disabled","visible","preventDefault","stopPropagation","execute","createKeyDownHandler","document","addEventListener","removeEventListener","onUnmounted","CommandsPluginPackage","createPluginPackage","BaseCommandsPackage","addUtility","KeyboardShortcuts","build","commandId","documentId","ref","watch","toValue","providesValue","cmdId","docId","_","onCleanup","onCommandStateChanged","immediate","readonly","usePlugin"],"mappings":"0MAIaA,EAAwB,IAAMC,gBAA8BC,EAAAA,eAAeC,oECKxF,MAAQC,SAAUC,GAAaL,IAE/B,IAAIM,EAA+B,YAEnCC,EAAAA,UAAU,KACR,IAAKF,EAASG,MAAO,OAErB,MAAMC,ECaD,SAA8BJ,GACnC,OAAQK,IAEN,MAAMC,EAASD,EAAMC,OACrB,GAAuB,UAAnBA,EAAOC,SAA0C,aAAnBD,EAAOC,SAA0BD,EAAOE,kBACxE,OAGF,MAAMC,EA/BH,SAA6BJ,GAClC,MAAMK,EAAsB,GAExBL,EAAMM,SAASD,EAAUE,KAAK,QAC9BP,EAAMQ,UAAUH,EAAUE,KAAK,SAC/BP,EAAMS,QAAQJ,EAAUE,KAAK,OAC7BP,EAAMU,SAASL,EAAUE,KAAK,QAGlC,MAAMI,EAAMX,EAAMW,IAAIC,cAGtB,MAFmB,CAAC,UAAW,QAAS,MAAO,QAAQC,SAASF,GAGvD,KAGK,IAAIN,EAAWM,GAChBG,OAAOC,KAAK,IAC3B,CAaqBC,CAAoBhB,GACrC,IAAKI,EAAU,OAEf,MAAMa,EAAUtB,EAASuB,qBAAqBd,GAC9C,IAAKa,EAAS,OAGd,MAAME,EAAWxB,EAASyB,QAAQH,EAAQxB,KAEtC0B,EAASE,UAAaF,EAASG,UAKnCtB,EAAMuB,iBACNvB,EAAMwB,kBACN7B,EAAS8B,QAAQR,EAAQxB,QAAI,EAAW,aAE5C,CDvCwBiC,CAAqB/B,EAASG,OAEpD6B,SAASC,iBAAiB,UAAW7B,GACrCH,EAAU,IAAM+B,SAASE,oBAAoB,UAAW9B,KAG1D+B,EAAAA,YAAY,KACV,MAAAlC,GAAAA,qBEdWmC,EAAwBC,EAAAA,oBAAoBC,EAAAA,uBACtDC,WAAWC,GACXC,uFHCuB,CACxBC,EACAC,KAEA,MAAM5C,SAAEA,GAAaJ,IACf2B,EAAUsB,EAAAA,IAA4B,MAuB5C,OArBAC,EAAAA,MACE,CAAC9C,EAAU,IAAM+C,UAAQJ,GAAY,IAAMI,EAAAA,QAAQH,IACnD,EAAEI,EAAeC,EAAOC,GAAQC,EAAGC,KACjC,IAAKJ,EAEH,YADAzB,EAAQnB,MAAQ,MAIlBmB,EAAQnB,MAAQ4C,EAActB,QAAQuB,EAAOC,GAQ7CE,EANoBJ,EAAcK,sBAAuB/C,IACnDA,EAAMqC,YAAcM,GAAS3C,EAAMsC,aAAeM,IACpD3B,EAAQnB,MAAQ4C,EAActB,QAAQuB,EAAOC,QAMnD,CAAEI,WAAW,IAGRC,EAAAA,SAAShC,8DAnCe,IAAMiC,YAA0B1D,EAAAA,eAAeC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './hooks';
|
|
2
|
+
export * from './components';
|
|
3
|
+
export * from '../lib/index.ts';
|
|
4
|
+
export declare const CommandsPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').CommandsPlugin, import('../lib/index.ts').CommandsPluginConfig, import('../lib/index.ts').CommandsState, import('src/lib/actions').CommandsAction>>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createPluginPackage } from "@embedpdf/core";
|
|
2
|
+
import { CommandsPlugin, CommandsPluginPackage as CommandsPluginPackage$1 } from "@embedpdf/plugin-commands";
|
|
3
|
+
export * from "@embedpdf/plugin-commands";
|
|
4
|
+
import { ref, watch, toValue, readonly, defineComponent, onMounted, onUnmounted } from "vue";
|
|
5
|
+
import { useCapability, usePlugin } from "@embedpdf/core/vue";
|
|
6
|
+
const useCommandsCapability = () => useCapability(CommandsPlugin.id);
|
|
7
|
+
const useCommandsPlugin = () => usePlugin(CommandsPlugin.id);
|
|
8
|
+
const useCommand = (commandId, documentId) => {
|
|
9
|
+
const { provides } = useCommandsCapability();
|
|
10
|
+
const command = ref(null);
|
|
11
|
+
watch(
|
|
12
|
+
[provides, () => toValue(commandId), () => toValue(documentId)],
|
|
13
|
+
([providesValue, cmdId, docId], _, onCleanup) => {
|
|
14
|
+
if (!providesValue) {
|
|
15
|
+
command.value = null;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
command.value = providesValue.resolve(cmdId, docId);
|
|
19
|
+
const unsubscribe = providesValue.onCommandStateChanged((event) => {
|
|
20
|
+
if (event.commandId === cmdId && event.documentId === docId) {
|
|
21
|
+
command.value = providesValue.resolve(cmdId, docId);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
onCleanup(unsubscribe);
|
|
25
|
+
},
|
|
26
|
+
{ immediate: true }
|
|
27
|
+
);
|
|
28
|
+
return readonly(command);
|
|
29
|
+
};
|
|
30
|
+
function buildShortcutString(event) {
|
|
31
|
+
const modifiers = [];
|
|
32
|
+
if (event.ctrlKey) modifiers.push("ctrl");
|
|
33
|
+
if (event.shiftKey) modifiers.push("shift");
|
|
34
|
+
if (event.altKey) modifiers.push("alt");
|
|
35
|
+
if (event.metaKey) modifiers.push("meta");
|
|
36
|
+
const key = event.key.toLowerCase();
|
|
37
|
+
const isModifier = ["control", "shift", "alt", "meta"].includes(key);
|
|
38
|
+
if (isModifier) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const parts = [...modifiers, key];
|
|
42
|
+
return parts.sort().join("+");
|
|
43
|
+
}
|
|
44
|
+
function createKeyDownHandler(commands) {
|
|
45
|
+
return (event) => {
|
|
46
|
+
const target = event.target;
|
|
47
|
+
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const shortcut = buildShortcutString(event);
|
|
51
|
+
if (!shortcut) return;
|
|
52
|
+
const command = commands.getCommandByShortcut(shortcut);
|
|
53
|
+
if (!command) return;
|
|
54
|
+
const resolved = commands.resolve(command.id);
|
|
55
|
+
if (resolved.disabled || !resolved.visible) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
event.stopPropagation();
|
|
60
|
+
commands.execute(command.id, void 0, "keyboard");
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
64
|
+
__name: "keyboard-shortcuts",
|
|
65
|
+
setup(__props) {
|
|
66
|
+
const { provides: commands } = useCommandsCapability();
|
|
67
|
+
let cleanup = null;
|
|
68
|
+
onMounted(() => {
|
|
69
|
+
if (!commands.value) return;
|
|
70
|
+
const handleKeyDown = createKeyDownHandler(commands.value);
|
|
71
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
72
|
+
cleanup = () => document.removeEventListener("keydown", handleKeyDown);
|
|
73
|
+
});
|
|
74
|
+
onUnmounted(() => {
|
|
75
|
+
cleanup == null ? void 0 : cleanup();
|
|
76
|
+
});
|
|
77
|
+
return (_ctx, _cache) => {
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const CommandsPluginPackage = createPluginPackage(CommandsPluginPackage$1).addUtility(_sfc_main).build();
|
|
83
|
+
export {
|
|
84
|
+
CommandsPluginPackage,
|
|
85
|
+
_sfc_main as KeyboardShortcuts,
|
|
86
|
+
useCommand,
|
|
87
|
+
useCommandsCapability,
|
|
88
|
+
useCommandsPlugin
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-commands.ts","../../src/shared/utils/keyboard-handler.ts","../../src/vue/components/keyboard-shortcuts.vue","../../src/vue/index.ts"],"sourcesContent":["import { ref, watch, readonly, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { CommandsPlugin, ResolvedCommand } from '@embedpdf/plugin-commands';\n\nexport const useCommandsCapability = () => useCapability<CommandsPlugin>(CommandsPlugin.id);\nexport const useCommandsPlugin = () => usePlugin<CommandsPlugin>(CommandsPlugin.id);\n\n/**\n * Hook to get a reactive command for a specific document\n * @param commandId Command ID (can be ref, computed, getter, or plain value)\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useCommand = (\n commandId: MaybeRefOrGetter<string>,\n documentId: MaybeRefOrGetter<string>,\n) => {\n const { provides } = useCommandsCapability();\n const command = ref<ResolvedCommand | null>(null);\n\n watch(\n [provides, () => toValue(commandId), () => toValue(documentId)],\n ([providesValue, cmdId, docId], _, onCleanup) => {\n if (!providesValue) {\n command.value = null;\n return;\n }\n\n command.value = providesValue.resolve(cmdId, docId);\n\n const unsubscribe = providesValue.onCommandStateChanged((event) => {\n if (event.commandId === cmdId && event.documentId === docId) {\n command.value = providesValue.resolve(cmdId, docId);\n }\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n );\n\n return readonly(command);\n};\n","import { CommandsCapability } from '../../lib/types';\n\n/**\n * Build a shortcut string from a keyboard event\n * @example Ctrl+Shift+A -> \"ctrl+shift+a\"\n */\nexport function buildShortcutString(event: KeyboardEvent): string | null {\n const modifiers: string[] = [];\n\n if (event.ctrlKey) modifiers.push('ctrl');\n if (event.shiftKey) modifiers.push('shift');\n if (event.altKey) modifiers.push('alt');\n if (event.metaKey) modifiers.push('meta');\n\n // Only add non-modifier keys\n const key = event.key.toLowerCase();\n const isModifier = ['control', 'shift', 'alt', 'meta'].includes(key);\n\n if (isModifier) {\n return null; // Just a modifier, no command\n }\n\n const parts = [...modifiers, key];\n return parts.sort().join('+');\n}\n\n/**\n * Handle keyboard events and execute commands based on shortcuts\n */\nexport function createKeyDownHandler(commands: CommandsCapability) {\n return (event: KeyboardEvent) => {\n // Don't handle shortcuts if target is an input, textarea, or contentEditable\n const target = event.target as HTMLElement;\n if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {\n return;\n }\n\n const shortcut = buildShortcutString(event);\n if (!shortcut) return;\n\n const command = commands.getCommandByShortcut(shortcut);\n if (!command) return;\n\n // Resolve without document ID - will use active document\n const resolved = commands.resolve(command.id);\n\n if (resolved.disabled || !resolved.visible) {\n return;\n }\n\n // Execute and prevent default (documentId is optional now)\n event.preventDefault();\n event.stopPropagation();\n commands.execute(command.id, undefined, 'keyboard');\n };\n}\n","<template>\n <!-- This component is only used to set up keyboard shortcuts when the plugin is initialized -->\n</template>\n\n<script setup lang=\"ts\">\nimport { onMounted, onUnmounted } from 'vue';\nimport { useCommandsCapability } from '../hooks';\nimport { createKeyDownHandler } from '../../shared/utils';\n\nconst { provides: commands } = useCommandsCapability();\n\nlet cleanup: (() => void) | null = null;\n\nonMounted(() => {\n if (!commands.value) return;\n\n const handleKeyDown = createKeyDownHandler(commands.value);\n\n document.addEventListener('keydown', handleKeyDown);\n cleanup = () => document.removeEventListener('keydown', handleKeyDown);\n});\n\nonUnmounted(() => {\n cleanup?.();\n});\n</script>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { CommandsPluginPackage as BaseCommandsPackage } from '@embedpdf/plugin-commands';\n\nimport { KeyboardShortcuts } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-commands';\n\nexport const CommandsPluginPackage = createPluginPackage(BaseCommandsPackage)\n .addUtility(KeyboardShortcuts)\n .build();\n"],"names":["BaseCommandsPackage","KeyboardShortcuts"],"mappings":";;;;;AAIO,MAAM,wBAAwB,MAAM,cAA8B,eAAe,EAAE;AACnF,MAAM,oBAAoB,MAAM,UAA0B,eAAe,EAAE;AAO3E,MAAM,aAAa,CACxB,WACA,eACG;AACH,QAAM,EAAE,SAAA,IAAa,sBAAA;AACrB,QAAM,UAAU,IAA4B,IAAI;AAEhD;AAAA,IACE,CAAC,UAAU,MAAM,QAAQ,SAAS,GAAG,MAAM,QAAQ,UAAU,CAAC;AAAA,IAC9D,CAAC,CAAC,eAAe,OAAO,KAAK,GAAG,GAAG,cAAc;AAC/C,UAAI,CAAC,eAAe;AAClB,gBAAQ,QAAQ;AAChB;AAAA,MACF;AAEA,cAAQ,QAAQ,cAAc,QAAQ,OAAO,KAAK;AAElD,YAAM,cAAc,cAAc,sBAAsB,CAAC,UAAU;AACjE,YAAI,MAAM,cAAc,SAAS,MAAM,eAAe,OAAO;AAC3D,kBAAQ,QAAQ,cAAc,QAAQ,OAAO,KAAK;AAAA,QACpD;AAAA,MACF,CAAC;AAED,gBAAU,WAAW;AAAA,IACvB;AAAA,IACA,EAAE,WAAW,KAAA;AAAA,EAAK;AAGpB,SAAO,SAAS,OAAO;AACzB;ACnCO,SAAS,oBAAoB,OAAqC;AACvE,QAAM,YAAsB,CAAA;AAE5B,MAAI,MAAM,QAAS,WAAU,KAAK,MAAM;AACxC,MAAI,MAAM,SAAU,WAAU,KAAK,OAAO;AAC1C,MAAI,MAAM,OAAQ,WAAU,KAAK,KAAK;AACtC,MAAI,MAAM,QAAS,WAAU,KAAK,MAAM;AAGxC,QAAM,MAAM,MAAM,IAAI,YAAA;AACtB,QAAM,aAAa,CAAC,WAAW,SAAS,OAAO,MAAM,EAAE,SAAS,GAAG;AAEnE,MAAI,YAAY;AACd,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,CAAC,GAAG,WAAW,GAAG;AAChC,SAAO,MAAM,OAAO,KAAK,GAAG;AAC9B;AAKO,SAAS,qBAAqB,UAA8B;AACjE,SAAO,CAAC,UAAyB;AAE/B,UAAM,SAAS,MAAM;AACrB,QAAI,OAAO,YAAY,WAAW,OAAO,YAAY,cAAc,OAAO,mBAAmB;AAC3F;AAAA,IACF;AAEA,UAAM,WAAW,oBAAoB,KAAK;AAC1C,QAAI,CAAC,SAAU;AAEf,UAAM,UAAU,SAAS,qBAAqB,QAAQ;AACtD,QAAI,CAAC,QAAS;AAGd,UAAM,WAAW,SAAS,QAAQ,QAAQ,EAAE;AAE5C,QAAI,SAAS,YAAY,CAAC,SAAS,SAAS;AAC1C;AAAA,IACF;AAGA,UAAM,eAAA;AACN,UAAM,gBAAA;AACN,aAAS,QAAQ,QAAQ,IAAI,QAAW,UAAU;AAAA,EACpD;AACF;;;;AC9CA,UAAM,EAAE,UAAU,SAAA,IAAa,sBAAA;AAE/B,QAAI,UAA+B;AAEnC,cAAU,MAAM;AACd,UAAI,CAAC,SAAS,MAAO;AAErB,YAAM,gBAAgB,qBAAqB,SAAS,KAAK;AAEzD,eAAS,iBAAiB,WAAW,aAAa;AAClD,gBAAU,MAAM,SAAS,oBAAoB,WAAW,aAAa;AAAA,IACvE,CAAC;AAED,gBAAY,MAAM;AAChB;AAAA,IACF,CAAC;;;;;;ACfM,MAAM,wBAAwB,oBAAoBA,uBAAmB,EACzE,WAAWC,SAAiB,EAC5B,MAAA;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@embedpdf/plugin-commands",
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./preact": {
|
|
16
|
+
"types": "./dist/preact/index.d.ts",
|
|
17
|
+
"import": "./dist/preact/index.js",
|
|
18
|
+
"require": "./dist/preact/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./react": {
|
|
21
|
+
"types": "./dist/react/index.d.ts",
|
|
22
|
+
"import": "./dist/react/index.js",
|
|
23
|
+
"require": "./dist/react/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./vue": {
|
|
26
|
+
"types": "./dist/vue/index.d.ts",
|
|
27
|
+
"import": "./dist/vue/index.js",
|
|
28
|
+
"require": "./dist/vue/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./svelte": {
|
|
31
|
+
"types": "./dist/svelte/index.d.ts",
|
|
32
|
+
"svelte": "./dist/svelte/index.js",
|
|
33
|
+
"import": "./dist/svelte/index.js",
|
|
34
|
+
"require": "./dist/svelte/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@embedpdf/models": "2.0.0-next.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/react": "^18.2.0",
|
|
42
|
+
"typescript": "^5.0.0",
|
|
43
|
+
"@embedpdf/build": "1.1.0",
|
|
44
|
+
"@embedpdf/core": "2.0.0-next.0",
|
|
45
|
+
"@embedpdf/plugin-i18n": "2.0.0-next.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react": ">=16.8.0",
|
|
49
|
+
"react-dom": ">=16.8.0",
|
|
50
|
+
"preact": "^10.26.4",
|
|
51
|
+
"vue": ">=3.2.0",
|
|
52
|
+
"svelte": ">=5 <6",
|
|
53
|
+
"@embedpdf/core": "2.0.0-next.0"
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"dist",
|
|
57
|
+
"README.md"
|
|
58
|
+
],
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/embedpdf/embed-pdf-viewer",
|
|
62
|
+
"directory": "packages/plugin-commands"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://www.embedpdf.com/docs",
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/embedpdf/embed-pdf-viewer/issues"
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build:base": "vite build --mode base",
|
|
73
|
+
"build:react": "vite build --mode react",
|
|
74
|
+
"build:preact": "vite build --mode preact",
|
|
75
|
+
"build:vue": "vite build --mode vue",
|
|
76
|
+
"build:svelte": "vite build --mode svelte",
|
|
77
|
+
"build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue,svelte \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\" \"vite build --mode svelte\"",
|
|
78
|
+
"clean": "rimraf dist",
|
|
79
|
+
"lint": "eslint src --color",
|
|
80
|
+
"lint:fix": "eslint src --color --fix"
|
|
81
|
+
}
|
|
82
|
+
}
|