@embedpdf/plugin-commands 2.15.0 → 3.0.0-next.1
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 +192 -21
- package/dist/index.cjs +196 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +150 -0
- package/dist/index.d.ts +150 -1
- package/dist/index.js +189 -379
- package/dist/index.js.map +1 -1
- package/package.json +21 -59
- package/dist/lib/actions.d.ts +0 -8
- package/dist/lib/commands-plugin.d.ts +0 -40
- package/dist/lib/index.d.ts +0 -8
- package/dist/lib/manifest.d.ts +0 -4
- package/dist/lib/reducer.d.ts +0 -5
- package/dist/lib/types.d.ts +0 -116
- package/dist/preact/adapter.d.ts +0 -5
- package/dist/preact/core.d.ts +0 -1
- package/dist/preact/index.cjs +0 -2
- package/dist/preact/index.cjs.map +0 -1
- package/dist/preact/index.d.ts +0 -1
- package/dist/preact/index.js +0 -91
- package/dist/preact/index.js.map +0 -1
- package/dist/react/adapter.d.ts +0 -2
- package/dist/react/core.d.ts +0 -1
- package/dist/react/index.cjs +0 -2
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -90
- package/dist/react/index.js.map +0 -1
- package/dist/shared/components/index.d.ts +0 -1
- package/dist/shared/components/keyboard-shortcuts.d.ts +0 -6
- package/dist/shared/hooks/index.d.ts +0 -1
- package/dist/shared/hooks/use-commands.d.ts +0 -23
- package/dist/shared/index.d.ts +0 -4
- package/dist/shared/utils/index.d.ts +0 -1
- package/dist/shared/utils/keyboard-handler.d.ts +0 -10
- package/dist/shared-preact/components/index.d.ts +0 -1
- package/dist/shared-preact/components/keyboard-shortcuts.d.ts +0 -6
- package/dist/shared-preact/hooks/index.d.ts +0 -1
- package/dist/shared-preact/hooks/use-commands.d.ts +0 -23
- package/dist/shared-preact/index.d.ts +0 -4
- package/dist/shared-preact/utils/index.d.ts +0 -1
- package/dist/shared-preact/utils/keyboard-handler.d.ts +0 -10
- package/dist/shared-react/components/index.d.ts +0 -1
- package/dist/shared-react/components/keyboard-shortcuts.d.ts +0 -6
- package/dist/shared-react/hooks/index.d.ts +0 -1
- package/dist/shared-react/hooks/use-commands.d.ts +0 -23
- package/dist/shared-react/index.d.ts +0 -4
- package/dist/shared-react/utils/index.d.ts +0 -1
- package/dist/shared-react/utils/keyboard-handler.d.ts +0 -10
- package/dist/shared-vue/utils/index.d.ts +0 -1
- package/dist/shared-vue/utils/keyboard-handler.d.ts +0 -10
- package/dist/svelte/components/KeyboardShortcuts.svelte.d.ts +0 -18
- package/dist/svelte/components/index.d.ts +0 -1
- package/dist/svelte/hooks/index.d.ts +0 -1
- package/dist/svelte/hooks/use-commands.svelte.d.ts +0 -21
- package/dist/svelte/index.cjs +0 -2
- package/dist/svelte/index.cjs.map +0 -1
- package/dist/svelte/index.d.ts +0 -4
- package/dist/svelte/index.js +0 -92
- package/dist/svelte/index.js.map +0 -1
- package/dist/vue/components/index.d.ts +0 -1
- package/dist/vue/components/keyboard-shortcuts.vue.d.ts +0 -3
- package/dist/vue/hooks/index.d.ts +0 -1
- package/dist/vue/hooks/use-commands.d.ts +0 -46
- package/dist/vue/index.cjs +0 -2
- package/dist/vue/index.cjs.map +0 -1
- package/dist/vue/index.d.ts +0 -4
- package/dist/vue/index.js +0 -92
- package/dist/vue/index.js.map +0 -1
package/dist/vue/index.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
let key = event.key.toLowerCase();
|
|
37
|
-
if (key === " ") key = "space";
|
|
38
|
-
const isModifier = ["control", "shift", "alt", "meta"].includes(key);
|
|
39
|
-
if (isModifier) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
const parts = [...modifiers, key];
|
|
43
|
-
return parts.sort().join("+");
|
|
44
|
-
}
|
|
45
|
-
function createKeyDownHandler(commands) {
|
|
46
|
-
return (event) => {
|
|
47
|
-
const composedPath = event.composedPath();
|
|
48
|
-
const target = composedPath[0] || event.target;
|
|
49
|
-
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) {
|
|
50
|
-
if (event.key !== "Tab") return;
|
|
51
|
-
}
|
|
52
|
-
const shortcut = buildShortcutString(event);
|
|
53
|
-
if (!shortcut) return;
|
|
54
|
-
const command = commands.getCommandByShortcut(shortcut);
|
|
55
|
-
if (!command) return;
|
|
56
|
-
const resolved = commands.resolve(command.id);
|
|
57
|
-
if (resolved.disabled || !resolved.visible) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
event.preventDefault();
|
|
61
|
-
event.stopPropagation();
|
|
62
|
-
commands.execute(command.id, void 0, "keyboard");
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
66
|
-
__name: "keyboard-shortcuts",
|
|
67
|
-
setup(__props) {
|
|
68
|
-
const { provides: commands } = useCommandsCapability();
|
|
69
|
-
let cleanup = null;
|
|
70
|
-
onMounted(() => {
|
|
71
|
-
if (!commands.value) return;
|
|
72
|
-
const handleKeyDown = createKeyDownHandler(commands.value);
|
|
73
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
74
|
-
cleanup = () => document.removeEventListener("keydown", handleKeyDown);
|
|
75
|
-
});
|
|
76
|
-
onUnmounted(() => {
|
|
77
|
-
cleanup == null ? void 0 : cleanup();
|
|
78
|
-
});
|
|
79
|
-
return (_ctx, _cache) => {
|
|
80
|
-
return null;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
const CommandsPluginPackage = createPluginPackage(CommandsPluginPackage$1).addUtility(_sfc_main).build();
|
|
85
|
-
export {
|
|
86
|
-
CommandsPluginPackage,
|
|
87
|
-
_sfc_main as KeyboardShortcuts,
|
|
88
|
-
useCommand,
|
|
89
|
-
useCommandsCapability,
|
|
90
|
-
useCommandsPlugin
|
|
91
|
-
};
|
|
92
|
-
//# sourceMappingURL=index.js.map
|
package/dist/vue/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 let key = event.key.toLowerCase();\n if (key === ' ') key = 'space';\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 // Use composedPath to get the actual target element, even inside Shadow DOM\n const composedPath = event.composedPath();\n const target = (composedPath[0] || event.target) as HTMLElement;\n\n // Don't handle shortcuts if target is an input, textarea, or contentEditable\n // Exception: allow Tab/Shift+Tab through for form field navigation\n if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {\n if (event.key !== 'Tab') 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,wB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