@embedpdf/react 3.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 +192 -0
- package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.cts +2593 -0
- package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.ts +2593 -0
- package/dist/annotation-B6jwfTCh.d.cts +173 -0
- package/dist/annotation-Ct6dFtzJ.cjs +913 -0
- package/dist/annotation-Ct6dFtzJ.cjs.map +1 -0
- package/dist/annotation-DjGWJljY.js +829 -0
- package/dist/annotation-DjGWJljY.js.map +1 -0
- package/dist/annotation-menu.cjs +115 -0
- package/dist/annotation-menu.cjs.map +1 -0
- package/dist/annotation-menu.d.cts +7 -0
- package/dist/annotation-menu.d.ts +7 -0
- package/dist/annotation-menu.js +99 -0
- package/dist/annotation-menu.js.map +1 -0
- package/dist/annotation-nUMefyjw.d.ts +173 -0
- package/dist/annotation.cjs +25 -0
- package/dist/annotation.d.cts +3 -0
- package/dist/annotation.d.ts +3 -0
- package/dist/annotation.js +4 -0
- package/dist/commands.cjs +59 -0
- package/dist/commands.cjs.map +1 -0
- package/dist/commands.d.cts +20 -0
- package/dist/commands.d.ts +20 -0
- package/dist/commands.js +47 -0
- package/dist/commands.js.map +1 -0
- package/dist/form.cjs +560 -0
- package/dist/form.cjs.map +1 -0
- package/dist/form.d.cts +52 -0
- package/dist/form.d.ts +52 -0
- package/dist/form.js +545 -0
- package/dist/form.js.map +1 -0
- package/dist/i18n.cjs +52 -0
- package/dist/i18n.cjs.map +1 -0
- package/dist/i18n.d.cts +30 -0
- package/dist/i18n.d.ts +30 -0
- package/dist/i18n.js +42 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.cjs +240 -0
- package/dist/index.d.cts +37 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +37 -0
- package/dist/interaction.cjs +152 -0
- package/dist/interaction.cjs.map +1 -0
- package/dist/interaction.d.cts +46 -0
- package/dist/interaction.d.ts +46 -0
- package/dist/interaction.js +139 -0
- package/dist/interaction.js.map +1 -0
- package/dist/link.cjs +108 -0
- package/dist/link.cjs.map +1 -0
- package/dist/link.d.cts +16 -0
- package/dist/link.d.ts +16 -0
- package/dist/link.js +98 -0
- package/dist/link.js.map +1 -0
- package/dist/metadata.cjs +25 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +11 -0
- package/dist/metadata.d.ts +11 -0
- package/dist/metadata.js +16 -0
- package/dist/metadata.js.map +1 -0
- package/dist/page-edit.cjs +20 -0
- package/dist/page-edit.cjs.map +1 -0
- package/dist/page-edit.d.cts +7 -0
- package/dist/page-edit.d.ts +7 -0
- package/dist/page-edit.js +11 -0
- package/dist/page-edit.js.map +1 -0
- package/dist/page-view.cjs +107 -0
- package/dist/page-view.cjs.map +1 -0
- package/dist/page-view.d.cts +23 -0
- package/dist/page-view.d.ts +23 -0
- package/dist/page-view.js +95 -0
- package/dist/page-view.js.map +1 -0
- package/dist/redaction.cjs +35 -0
- package/dist/redaction.cjs.map +1 -0
- package/dist/redaction.d.cts +14 -0
- package/dist/redaction.d.ts +14 -0
- package/dist/redaction.js +25 -0
- package/dist/redaction.js.map +1 -0
- package/dist/render.cjs +142 -0
- package/dist/render.cjs.map +1 -0
- package/dist/render.d.cts +32 -0
- package/dist/render.d.ts +32 -0
- package/dist/render.js +131 -0
- package/dist/render.js.map +1 -0
- package/dist/rolldown-runtime-DDXJien1.cjs +50 -0
- package/dist/runtime-CMxIuF2O.d.cts +195 -0
- package/dist/runtime-DV98q7I0.d.ts +195 -0
- package/dist/runtime.cjs +314 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +3 -0
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.js +287 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scrollbar.cjs +241 -0
- package/dist/scrollbar.cjs.map +1 -0
- package/dist/scrollbar.d.cts +42 -0
- package/dist/scrollbar.d.ts +42 -0
- package/dist/scrollbar.js +213 -0
- package/dist/scrollbar.js.map +1 -0
- package/dist/search.cjs +70 -0
- package/dist/search.cjs.map +1 -0
- package/dist/search.d.cts +35 -0
- package/dist/search.d.ts +35 -0
- package/dist/search.js +58 -0
- package/dist/search.js.map +1 -0
- package/dist/selection.cjs +60 -0
- package/dist/selection.cjs.map +1 -0
- package/dist/selection.d.cts +12 -0
- package/dist/selection.d.ts +12 -0
- package/dist/selection.js +49 -0
- package/dist/selection.js.map +1 -0
- package/dist/shell.cjs +57 -0
- package/dist/shell.cjs.map +1 -0
- package/dist/shell.d.cts +27 -0
- package/dist/shell.d.ts +27 -0
- package/dist/shell.js +46 -0
- package/dist/shell.js.map +1 -0
- package/dist/stage.cjs +343 -0
- package/dist/stage.cjs.map +1 -0
- package/dist/stage.d.cts +104 -0
- package/dist/stage.d.ts +104 -0
- package/dist/stage.js +327 -0
- package/dist/stage.js.map +1 -0
- package/dist/stamp.cjs +76 -0
- package/dist/stamp.cjs.map +1 -0
- package/dist/stamp.d.cts +28 -0
- package/dist/stamp.d.ts +28 -0
- package/dist/stamp.js +63 -0
- package/dist/stamp.js.map +1 -0
- package/dist/toolbar.cjs +515 -0
- package/dist/toolbar.cjs.map +1 -0
- package/dist/toolbar.d.cts +100 -0
- package/dist/toolbar.d.ts +100 -0
- package/dist/toolbar.js +505 -0
- package/dist/toolbar.js.map +1 -0
- package/dist/views.cjs +35 -0
- package/dist/views.cjs.map +1 -0
- package/dist/views.d.cts +21 -0
- package/dist/views.d.ts +21 -0
- package/dist/views.js +26 -0
- package/dist/views.js.map +1 -0
- package/package.json +158 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { A as useAnnotation, C as SelectionProps, D as filePickerProvider, E as TextStyle, F as useSelectionFlags, I as useSelectionProps, L as AnnotationMenuPlacement, M as useAnnotationSelected, N as useAnnotationSelection, O as sameAnchor, P as useFilePickerProvider, S as SelectionFlags, T as TextAlign, _ as PageAnnotationMenu, a as AnnotationLayerProps, b as RenderItem, c as AnnotationProps, d as AnnotationRendererProps, f as Border, g as PageAnnotationDraftMenu, h as LineEndings, i as AnnotationLayer, j as useAnnotationDefaults, k as sameCreationDraftAnchor, l as AnnotationPropsPatch, m as LineEnding, n as AnnotationDraftMenuRenderArgs, o as AnnotationMenuProps, p as Geom, r as AnnotationFlags, s as AnnotationMenuRenderArgs, t as AnnotationDraftMenuProps, u as AnnotationRenderer, v as PropKey, w as Style, x as SelectionAnchor, y as PropSpec } from "./annotation-nUMefyjw.js";
|
|
2
|
+
export * from "@embedpdf/plugin-annotation";
|
|
3
|
+
export { AnnotationDraftMenuProps, AnnotationDraftMenuRenderArgs, type AnnotationFlags, AnnotationLayer, AnnotationLayerProps, type AnnotationMenuPlacement, AnnotationMenuProps, AnnotationMenuRenderArgs, type AnnotationProps, type AnnotationPropsPatch, AnnotationRenderer, AnnotationRendererProps, type Border, type Geom, type LineEnding, type LineEndings, PageAnnotationDraftMenu, PageAnnotationMenu, type PropKey, type PropSpec, type RenderItem, SelectionAnchor, type SelectionFlags, type SelectionProps, type Style, type TextAlign, type TextStyle, filePickerProvider, sameAnchor, sameCreationDraftAnchor, useAnnotation, useAnnotationDefaults, useAnnotationSelected, useAnnotationSelection, useFilePickerProvider, useSelectionFlags, useSelectionProps };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import "./runtime.js";
|
|
2
|
+
import { a as sameAnchor, c as useAnnotationDefaults, d as useFilePickerProvider, f as useSelectionFlags, i as filePickerProvider, l as useAnnotationSelected, n as PageAnnotationDraftMenu, o as sameCreationDraftAnchor, p as useSelectionProps, r as PageAnnotationMenu, s as useAnnotation, t as AnnotationLayer, u as useAnnotationSelection } from "./annotation-DjGWJljY.js";
|
|
3
|
+
export * from "@embedpdf/plugin-annotation";
|
|
4
|
+
export { AnnotationLayer, PageAnnotationDraftMenu, PageAnnotationMenu, filePickerProvider, sameAnchor, sameCreationDraftAnchor, useAnnotation, useAnnotationDefaults, useAnnotationSelected, useAnnotationSelection, useFilePickerProvider, useSelectionFlags, useSelectionProps };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./rolldown-runtime-DDXJien1.cjs");
|
|
3
|
+
const require_runtime = require("./runtime.cjs");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let _embedpdf_plugin_commands = require("@embedpdf/plugin-commands");
|
|
6
|
+
//#region src/commands.ts
|
|
7
|
+
/** The commands capability (register/execute/search/categories). */
|
|
8
|
+
function useCommands() {
|
|
9
|
+
return require_runtime.useCapability(_embedpdf_plugin_commands.CommandsToken);
|
|
10
|
+
}
|
|
11
|
+
/** A command resolved against this subtree's document, reactively. */
|
|
12
|
+
function useCommand(id) {
|
|
13
|
+
const commands = require_runtime.useCapability(_embedpdf_plugin_commands.CommandsToken);
|
|
14
|
+
const documentId = require_runtime.useDocumentId();
|
|
15
|
+
return require_runtime.useKernelValue(() => commands.resolve(id, documentId ?? void 0), _embedpdf_plugin_commands.resolvedCommandsEqual);
|
|
16
|
+
}
|
|
17
|
+
/** Is this environment mac-like? Decides how 'Mod' resolves and displays. */
|
|
18
|
+
const isMacPlatform = () => typeof navigator !== "undefined" && /Mac|iP(hone|ad|od)/.test(navigator.platform);
|
|
19
|
+
const isEditableTarget = (target) => {
|
|
20
|
+
const el = target;
|
|
21
|
+
if (!el || !el.tagName) return false;
|
|
22
|
+
return el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Bind every registered shortcut. One listener for the whole registry —
|
|
26
|
+
* matching is pure (ui-core), execution goes through the one command path.
|
|
27
|
+
* Strokes from editable elements are ignored.
|
|
28
|
+
*/
|
|
29
|
+
function useCommandShortcuts(options) {
|
|
30
|
+
const commands = require_runtime.useCapability(_embedpdf_plugin_commands.CommandsToken);
|
|
31
|
+
const isMac = options?.isMac;
|
|
32
|
+
(0, react.useEffect)(() => {
|
|
33
|
+
const mac = isMac ?? isMacPlatform();
|
|
34
|
+
const onKeyDown = (event) => {
|
|
35
|
+
if (event.defaultPrevented || isEditableTarget(event.target)) return;
|
|
36
|
+
const id = commands.matchStroke(event, { isMac: mac });
|
|
37
|
+
if (!id) return;
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
commands.execute(id);
|
|
40
|
+
};
|
|
41
|
+
window.addEventListener("keydown", onKeyDown);
|
|
42
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
43
|
+
}, [commands, isMac]);
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.isMacPlatform = isMacPlatform;
|
|
47
|
+
exports.useCommand = useCommand;
|
|
48
|
+
exports.useCommandShortcuts = useCommandShortcuts;
|
|
49
|
+
exports.useCommands = useCommands;
|
|
50
|
+
Object.keys(_embedpdf_plugin_commands).forEach(function(k) {
|
|
51
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return _embedpdf_plugin_commands[k];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=commands.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.cjs","names":["useCapability","CommandsToken","useDocumentId","useKernelValue","resolvedCommandsEqual"],"sources":["../src/commands.ts"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-commands.\n *\n * Command state is a pure derivation over the store, so these hooks are thin:\n * `useCommand` re-resolves on the kernel's one change stream (cached by value\n * equality — locale flips, permission changes, and active-tool changes all\n * propagate with zero events), and `useCommandShortcuts` is the ~20 lines of\n * DOM that turn the registry's pure stroke matcher into a live keymap.\n */\n\n// One-line-per-feature: registration travels with the UI.\n// (resolvedCommandsEqual lives in the plugin now — it's pure value equality\n// over ResolvedCommand, framework-free — and arrives through this star.)\nexport * from '@embedpdf/plugin-commands';\nimport { useEffect } from 'react';\nimport { CommandsToken, resolvedCommandsEqual } from '@embedpdf/plugin-commands';\nimport type { CommandsCapability, ResolvedCommand } from '@embedpdf/plugin-commands';\nimport { useCapability, useDocumentId, useKernelValue } from './runtime';\n\n/** The commands capability (register/execute/search/categories). */\nexport function useCommands(): CommandsCapability {\n return useCapability(CommandsToken);\n}\n\n/** A command resolved against this subtree's document, reactively. */\nexport function useCommand(id: string): ResolvedCommand | null {\n const commands = useCapability(CommandsToken);\n const documentId = useDocumentId();\n return useKernelValue(() => commands.resolve(id, documentId ?? undefined), resolvedCommandsEqual);\n}\n\n/** Is this environment mac-like? Decides how 'Mod' resolves and displays. */\nexport const isMacPlatform = (): boolean =>\n typeof navigator !== 'undefined' && /Mac|iP(hone|ad|od)/.test(navigator.platform);\n\nconst isEditableTarget = (target: EventTarget | null): boolean => {\n const el = target as HTMLElement | null;\n if (!el || !el.tagName) return false;\n return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable;\n};\n\n/**\n * Bind every registered shortcut. One listener for the whole registry —\n * matching is pure (ui-core), execution goes through the one command path.\n * Strokes from editable elements are ignored.\n */\nexport function useCommandShortcuts(options?: { isMac?: boolean }): void {\n const commands = useCapability(CommandsToken);\n const isMac = options?.isMac;\n useEffect(() => {\n const mac = isMac ?? isMacPlatform();\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.defaultPrevented || isEditableTarget(event.target)) return;\n const id = commands.matchStroke(event, { isMac: mac });\n if (!id) return;\n event.preventDefault();\n commands.execute(id);\n };\n window.addEventListener('keydown', onKeyDown);\n return () => window.removeEventListener('keydown', onKeyDown);\n }, [commands, isMac]);\n}\n"],"mappings":";;;;;;;AAoBA,SAAgB,cAAkC;CAChD,OAAOA,gBAAAA,cAAcC,0BAAAA,aAAa;AACpC;;AAGA,SAAgB,WAAW,IAAoC;CAC7D,MAAM,WAAWD,gBAAAA,cAAcC,0BAAAA,aAAa;CAC5C,MAAM,aAAaC,gBAAAA,cAAc;CACjC,OAAOC,gBAAAA,qBAAqB,SAAS,QAAQ,IAAI,cAAc,KAAA,CAAS,GAAGC,0BAAAA,qBAAqB;AAClG;;AAGA,MAAa,sBACX,OAAO,cAAc,eAAe,qBAAqB,KAAK,UAAU,QAAQ;AAElF,MAAM,oBAAoB,WAAwC;CAChE,MAAM,KAAK;CACX,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,OAAO;CAC/B,OAAO,GAAG,YAAY,WAAW,GAAG,YAAY,cAAc,GAAG;AACnE;;;;;;AAOA,SAAgB,oBAAoB,SAAqC;CACvE,MAAM,WAAWJ,gBAAAA,cAAcC,0BAAAA,aAAa;CAC5C,MAAM,QAAQ,SAAS;CACvB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,MAAM,SAAS,cAAc;EACnC,MAAM,aAAa,UAAyB;GAC1C,IAAI,MAAM,oBAAoB,iBAAiB,MAAM,MAAM,GAAG;GAC9D,MAAM,KAAK,SAAS,YAAY,OAAO,EAAE,OAAO,IAAI,CAAC;GACrD,IAAI,CAAC,IAAI;GACT,MAAM,eAAe;GACrB,SAAS,QAAQ,EAAE;EACrB;EACA,OAAO,iBAAiB,WAAW,SAAS;EAC5C,aAAa,OAAO,oBAAoB,WAAW,SAAS;CAC9D,GAAG,CAAC,UAAU,KAAK,CAAC;AACtB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommandsCapability, ResolvedCommand } from "@embedpdf/plugin-commands";
|
|
2
|
+
export * from "@embedpdf/plugin-commands";
|
|
3
|
+
//#region src/commands.d.ts
|
|
4
|
+
/** The commands capability (register/execute/search/categories). */
|
|
5
|
+
declare function useCommands(): CommandsCapability;
|
|
6
|
+
/** A command resolved against this subtree's document, reactively. */
|
|
7
|
+
declare function useCommand(id: string): ResolvedCommand | null;
|
|
8
|
+
/** Is this environment mac-like? Decides how 'Mod' resolves and displays. */
|
|
9
|
+
declare const isMacPlatform: () => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Bind every registered shortcut. One listener for the whole registry —
|
|
12
|
+
* matching is pure (ui-core), execution goes through the one command path.
|
|
13
|
+
* Strokes from editable elements are ignored.
|
|
14
|
+
*/
|
|
15
|
+
declare function useCommandShortcuts(options?: {
|
|
16
|
+
isMac?: boolean;
|
|
17
|
+
}): void;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isMacPlatform, useCommand, useCommandShortcuts, useCommands };
|
|
20
|
+
//# sourceMappingURL=commands.d.cts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommandsCapability, ResolvedCommand } from "@embedpdf/plugin-commands";
|
|
2
|
+
export * from "@embedpdf/plugin-commands";
|
|
3
|
+
//#region src/commands.d.ts
|
|
4
|
+
/** The commands capability (register/execute/search/categories). */
|
|
5
|
+
declare function useCommands(): CommandsCapability;
|
|
6
|
+
/** A command resolved against this subtree's document, reactively. */
|
|
7
|
+
declare function useCommand(id: string): ResolvedCommand | null;
|
|
8
|
+
/** Is this environment mac-like? Decides how 'Mod' resolves and displays. */
|
|
9
|
+
declare const isMacPlatform: () => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Bind every registered shortcut. One listener for the whole registry —
|
|
12
|
+
* matching is pure (ui-core), execution goes through the one command path.
|
|
13
|
+
* Strokes from editable elements are ignored.
|
|
14
|
+
*/
|
|
15
|
+
declare function useCommandShortcuts(options?: {
|
|
16
|
+
isMac?: boolean;
|
|
17
|
+
}): void;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isMacPlatform, useCommand, useCommandShortcuts, useCommands };
|
|
20
|
+
//# sourceMappingURL=commands.d.ts.map
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useCapability, useDocumentId, useKernelValue } from "./runtime.js";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { CommandsToken, resolvedCommandsEqual } from "@embedpdf/plugin-commands";
|
|
4
|
+
export * from "@embedpdf/plugin-commands";
|
|
5
|
+
//#region src/commands.ts
|
|
6
|
+
/** The commands capability (register/execute/search/categories). */
|
|
7
|
+
function useCommands() {
|
|
8
|
+
return useCapability(CommandsToken);
|
|
9
|
+
}
|
|
10
|
+
/** A command resolved against this subtree's document, reactively. */
|
|
11
|
+
function useCommand(id) {
|
|
12
|
+
const commands = useCapability(CommandsToken);
|
|
13
|
+
const documentId = useDocumentId();
|
|
14
|
+
return useKernelValue(() => commands.resolve(id, documentId ?? void 0), resolvedCommandsEqual);
|
|
15
|
+
}
|
|
16
|
+
/** Is this environment mac-like? Decides how 'Mod' resolves and displays. */
|
|
17
|
+
const isMacPlatform = () => typeof navigator !== "undefined" && /Mac|iP(hone|ad|od)/.test(navigator.platform);
|
|
18
|
+
const isEditableTarget = (target) => {
|
|
19
|
+
const el = target;
|
|
20
|
+
if (!el || !el.tagName) return false;
|
|
21
|
+
return el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Bind every registered shortcut. One listener for the whole registry —
|
|
25
|
+
* matching is pure (ui-core), execution goes through the one command path.
|
|
26
|
+
* Strokes from editable elements are ignored.
|
|
27
|
+
*/
|
|
28
|
+
function useCommandShortcuts(options) {
|
|
29
|
+
const commands = useCapability(CommandsToken);
|
|
30
|
+
const isMac = options?.isMac;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const mac = isMac ?? isMacPlatform();
|
|
33
|
+
const onKeyDown = (event) => {
|
|
34
|
+
if (event.defaultPrevented || isEditableTarget(event.target)) return;
|
|
35
|
+
const id = commands.matchStroke(event, { isMac: mac });
|
|
36
|
+
if (!id) return;
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
commands.execute(id);
|
|
39
|
+
};
|
|
40
|
+
window.addEventListener("keydown", onKeyDown);
|
|
41
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
42
|
+
}, [commands, isMac]);
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { isMacPlatform, useCommand, useCommandShortcuts, useCommands };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","names":[],"sources":["../src/commands.ts"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-commands.\n *\n * Command state is a pure derivation over the store, so these hooks are thin:\n * `useCommand` re-resolves on the kernel's one change stream (cached by value\n * equality — locale flips, permission changes, and active-tool changes all\n * propagate with zero events), and `useCommandShortcuts` is the ~20 lines of\n * DOM that turn the registry's pure stroke matcher into a live keymap.\n */\n\n// One-line-per-feature: registration travels with the UI.\n// (resolvedCommandsEqual lives in the plugin now — it's pure value equality\n// over ResolvedCommand, framework-free — and arrives through this star.)\nexport * from '@embedpdf/plugin-commands';\nimport { useEffect } from 'react';\nimport { CommandsToken, resolvedCommandsEqual } from '@embedpdf/plugin-commands';\nimport type { CommandsCapability, ResolvedCommand } from '@embedpdf/plugin-commands';\nimport { useCapability, useDocumentId, useKernelValue } from './runtime';\n\n/** The commands capability (register/execute/search/categories). */\nexport function useCommands(): CommandsCapability {\n return useCapability(CommandsToken);\n}\n\n/** A command resolved against this subtree's document, reactively. */\nexport function useCommand(id: string): ResolvedCommand | null {\n const commands = useCapability(CommandsToken);\n const documentId = useDocumentId();\n return useKernelValue(() => commands.resolve(id, documentId ?? undefined), resolvedCommandsEqual);\n}\n\n/** Is this environment mac-like? Decides how 'Mod' resolves and displays. */\nexport const isMacPlatform = (): boolean =>\n typeof navigator !== 'undefined' && /Mac|iP(hone|ad|od)/.test(navigator.platform);\n\nconst isEditableTarget = (target: EventTarget | null): boolean => {\n const el = target as HTMLElement | null;\n if (!el || !el.tagName) return false;\n return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable;\n};\n\n/**\n * Bind every registered shortcut. One listener for the whole registry —\n * matching is pure (ui-core), execution goes through the one command path.\n * Strokes from editable elements are ignored.\n */\nexport function useCommandShortcuts(options?: { isMac?: boolean }): void {\n const commands = useCapability(CommandsToken);\n const isMac = options?.isMac;\n useEffect(() => {\n const mac = isMac ?? isMacPlatform();\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.defaultPrevented || isEditableTarget(event.target)) return;\n const id = commands.matchStroke(event, { isMac: mac });\n if (!id) return;\n event.preventDefault();\n commands.execute(id);\n };\n window.addEventListener('keydown', onKeyDown);\n return () => window.removeEventListener('keydown', onKeyDown);\n }, [commands, isMac]);\n}\n"],"mappings":";;;;;;AAoBA,SAAgB,cAAkC;CAChD,OAAO,cAAc,aAAa;AACpC;;AAGA,SAAgB,WAAW,IAAoC;CAC7D,MAAM,WAAW,cAAc,aAAa;CAC5C,MAAM,aAAa,cAAc;CACjC,OAAO,qBAAqB,SAAS,QAAQ,IAAI,cAAc,KAAA,CAAS,GAAG,qBAAqB;AAClG;;AAGA,MAAa,sBACX,OAAO,cAAc,eAAe,qBAAqB,KAAK,UAAU,QAAQ;AAElF,MAAM,oBAAoB,WAAwC;CAChE,MAAM,KAAK;CACX,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,OAAO;CAC/B,OAAO,GAAG,YAAY,WAAW,GAAG,YAAY,cAAc,GAAG;AACnE;;;;;;AAOA,SAAgB,oBAAoB,SAAqC;CACvE,MAAM,WAAW,cAAc,aAAa;CAC5C,MAAM,QAAQ,SAAS;CACvB,gBAAgB;EACd,MAAM,MAAM,SAAS,cAAc;EACnC,MAAM,aAAa,UAAyB;GAC1C,IAAI,MAAM,oBAAoB,iBAAiB,MAAM,MAAM,GAAG;GAC9D,MAAM,KAAK,SAAS,YAAY,OAAO,EAAE,OAAO,IAAI,CAAC;GACrD,IAAI,CAAC,IAAI;GACT,MAAM,eAAe;GACrB,SAAS,QAAQ,EAAE;EACrB;EACA,OAAO,iBAAiB,WAAW,SAAS;EAC5C,aAAa,OAAO,oBAAoB,WAAW,SAAS;CAC9D,GAAG,CAAC,UAAU,KAAK,CAAC;AACtB"}
|