@embedpdf/plugin-actions 3.0.0-next.15 → 3.0.0-next.16
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/contract/host.d.cts +2 -2
- package/dist/contract/host.d.ts +2 -2
- package/dist/{contract-DSQysTqU.d.cts → contract-BTPW8b4L.d.cts} +12 -2
- package/dist/{contract-CNKZHb6w.d.ts → contract-Cn-7mBY8.d.ts} +12 -2
- package/dist/contract-CwN3NAXU.js.map +1 -1
- package/dist/contract-_HB_UliT.cjs.map +1 -1
- package/dist/contract.d.cts +1 -1
- package/dist/contract.d.ts +1 -1
- package/dist/{host-contract-CRNO2oZN.d.ts → host-contract-BbODswDs.d.ts} +2 -2
- package/dist/{host-contract-DJ8TqDr3.d.cts → host-contract-D22Gz-qt.d.cts} +2 -2
- package/dist/index.cjs +78 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +79 -11
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as DocumentTriggerEvent, B as SubmitIntent, C as ActionUiAdapter, D as ActionsScriptEnvironment, E as ActionsConfig, F as PdfAnnotationEventKind, G as HoverTarget, H as triggerOriginOf, I as PdfFieldEventKind, K as createHoverPump, L as PdfNamedAction, M as PdfActionNode, N as PdfActionTree, O as ActionsScriptIdentity, P as PdfActionType, R as ScriptDiagnosticReportedEvent, S as ActionTriggerResult, T as ActionsCapability, U as submitEntriesToUrlEncoded, V as eventOf, W as HoverPump, _ as ActionSubmitHandler, a as ActionDispatchResult, b as ActionTrigger, c as ActionExecutorResult, d as ActionOrigin, f as ActionPolicy, g as ActionStepResult, h as ActionSource, i as ActionDiagnosticReportedEvent, j as OpenSequenceCompletedEvent, k as ActionsSettings, l as ActionNodeResult, m as ActionPolicyRow, n as ActionContext, o as ActionExecutedEvent, p as ActionPolicyDecision, q as ActionsToken, r as ActionDiagnostic, s as ActionExecutor, t as ACTIONS_DEFAULTS, u as ActionNodeStatus, v as ActionSubmitRequest, w as ActionUiContext, x as ActionTriggerEvent, y as ActionTreeSource, z as ScriptFailedEvent } from "./contract-
|
|
2
|
-
import { t as ActionsHostCapability } from "./host-contract-
|
|
1
|
+
import { A as DocumentTriggerEvent, B as SubmitIntent, C as ActionUiAdapter, D as ActionsScriptEnvironment, E as ActionsConfig, F as PdfAnnotationEventKind, G as HoverTarget, H as triggerOriginOf, I as PdfFieldEventKind, K as createHoverPump, L as PdfNamedAction, M as PdfActionNode, N as PdfActionTree, O as ActionsScriptIdentity, P as PdfActionType, R as ScriptDiagnosticReportedEvent, S as ActionTriggerResult, T as ActionsCapability, U as submitEntriesToUrlEncoded, V as eventOf, W as HoverPump, _ as ActionSubmitHandler, a as ActionDispatchResult, b as ActionTrigger, c as ActionExecutorResult, d as ActionOrigin, f as ActionPolicy, g as ActionStepResult, h as ActionSource, i as ActionDiagnosticReportedEvent, j as OpenSequenceCompletedEvent, k as ActionsSettings, l as ActionNodeResult, m as ActionPolicyRow, n as ActionContext, o as ActionExecutedEvent, p as ActionPolicyDecision, q as ActionsToken, r as ActionDiagnostic, s as ActionExecutor, t as ACTIONS_DEFAULTS, u as ActionNodeStatus, v as ActionSubmitRequest, w as ActionUiContext, x as ActionTriggerEvent, y as ActionTreeSource, z as ScriptFailedEvent } from "./contract-BTPW8b4L.cjs";
|
|
2
|
+
import { t as ActionsHostCapability } from "./host-contract-D22Gz-qt.cjs";
|
|
3
3
|
//#region src/actions.plugin.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The action engine, the dependency root of the action architecture. It
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as DocumentTriggerEvent, B as SubmitIntent, C as ActionUiAdapter, D as ActionsScriptEnvironment, E as ActionsConfig, F as PdfAnnotationEventKind, G as HoverTarget, H as triggerOriginOf, I as PdfFieldEventKind, K as createHoverPump, L as PdfNamedAction, M as PdfActionNode, N as PdfActionTree, O as ActionsScriptIdentity, P as PdfActionType, R as ScriptDiagnosticReportedEvent, S as ActionTriggerResult, T as ActionsCapability, U as submitEntriesToUrlEncoded, V as eventOf, W as HoverPump, _ as ActionSubmitHandler, a as ActionDispatchResult, b as ActionTrigger, c as ActionExecutorResult, d as ActionOrigin, f as ActionPolicy, g as ActionStepResult, h as ActionSource, i as ActionDiagnosticReportedEvent, j as OpenSequenceCompletedEvent, k as ActionsSettings, l as ActionNodeResult, m as ActionPolicyRow, n as ActionContext, o as ActionExecutedEvent, p as ActionPolicyDecision, q as ActionsToken, r as ActionDiagnostic, s as ActionExecutor, t as ACTIONS_DEFAULTS, u as ActionNodeStatus, v as ActionSubmitRequest, w as ActionUiContext, x as ActionTriggerEvent, y as ActionTreeSource, z as ScriptFailedEvent } from "./contract-
|
|
2
|
-
import { t as ActionsHostCapability } from "./host-contract-
|
|
1
|
+
import { A as DocumentTriggerEvent, B as SubmitIntent, C as ActionUiAdapter, D as ActionsScriptEnvironment, E as ActionsConfig, F as PdfAnnotationEventKind, G as HoverTarget, H as triggerOriginOf, I as PdfFieldEventKind, K as createHoverPump, L as PdfNamedAction, M as PdfActionNode, N as PdfActionTree, O as ActionsScriptIdentity, P as PdfActionType, R as ScriptDiagnosticReportedEvent, S as ActionTriggerResult, T as ActionsCapability, U as submitEntriesToUrlEncoded, V as eventOf, W as HoverPump, _ as ActionSubmitHandler, a as ActionDispatchResult, b as ActionTrigger, c as ActionExecutorResult, d as ActionOrigin, f as ActionPolicy, g as ActionStepResult, h as ActionSource, i as ActionDiagnosticReportedEvent, j as OpenSequenceCompletedEvent, k as ActionsSettings, l as ActionNodeResult, m as ActionPolicyRow, n as ActionContext, o as ActionExecutedEvent, p as ActionPolicyDecision, q as ActionsToken, r as ActionDiagnostic, s as ActionExecutor, t as ACTIONS_DEFAULTS, u as ActionNodeStatus, v as ActionSubmitRequest, w as ActionUiContext, x as ActionTriggerEvent, y as ActionTreeSource, z as ScriptFailedEvent } from "./contract-Cn-7mBY8.js";
|
|
2
|
+
import { t as ActionsHostCapability } from "./host-contract-BbODswDs.js";
|
|
3
3
|
//#region src/actions.plugin.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The action engine, the dependency root of the action architecture. It
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as createHoverPump, i as submitEntriesToUrlEncoded, n as eventOf, o as ActionsToken, r as triggerOriginOf, t as ACTIONS_DEFAULTS } from "./contract-CwN3NAXU.js";
|
|
2
2
|
import { ActionsToken as ActionsToken$1 } from "./contract/host.js";
|
|
3
|
-
import { PluginError, composeApi, definePlugin, isPluginError, toPageRef } from "@embedpdf/core";
|
|
3
|
+
import { DocumentsToken, PluginError, composeApi, definePlugin, isPluginError, toPageRef } from "@embedpdf/core";
|
|
4
4
|
import { annotationKey, pdfRectOf, rgbOf, toPageRef as toPageRef$1 } from "@embedpdf/engine-core/runtime";
|
|
5
5
|
import { DEFAULT_SCRIPT_BUDGET, createScriptHost, javaScriptProgramFromActionTree, resolveScriptIdentity, scriptFieldsFromSnapshot, seedFrom } from "@embedpdf/core-acrojs";
|
|
6
6
|
//#region src/services/annotation-rows.ts
|
|
@@ -253,6 +253,10 @@ function createDispatcher(ctx, services, { run }, { triggerEnabled, lifecycleAnn
|
|
|
253
253
|
return fields.find((candidate) => target.kind === "objectNumber" ? candidate.ref.kind === "objectNumber" && candidate.ref.objectNumber === target.objectNumber : candidate.name === target.name)?.actions?.[source.event] ?? null;
|
|
254
254
|
}
|
|
255
255
|
case "page": return ctx.getPage(source.page)?.actions?.[source.event ?? "open"] ?? null;
|
|
256
|
+
case "outline": {
|
|
257
|
+
const { items } = await ctx.doc.outline.get();
|
|
258
|
+
return items.find((candidate) => candidate.ref.objectNumber === source.item.objectNumber)?.action ?? null;
|
|
259
|
+
}
|
|
256
260
|
case "document": {
|
|
257
261
|
const snapshot = await readDocumentActions();
|
|
258
262
|
if (!snapshot) return null;
|
|
@@ -754,8 +758,8 @@ function createTriggers(ctx, { settings, form }) {
|
|
|
754
758
|
* The verb-shaped document events (/WC, /WS, /DS, /WP, /DP) and the print
|
|
755
759
|
* door: one catalog lifecycle tree per event, run inside the current queue
|
|
756
760
|
* operation and never throwing (a broken script must not cancel the user's
|
|
757
|
-
* save or print), and
|
|
758
|
-
* print latch.
|
|
761
|
+
* save or print), and a print request sent to the kernel's print, or, without
|
|
762
|
+
* a printer, to the adapter, wrapped /WP → print → /DP under the print latch.
|
|
759
763
|
*/
|
|
760
764
|
function createDocumentEvents(services, { ensureOpenSequenceBeforeDocEvent }, { runAndEmit }) {
|
|
761
765
|
const { reportDiagnostic } = services.events;
|
|
@@ -763,6 +767,7 @@ function createDocumentEvents(services, { ensureOpenSequenceBeforeDocEvent }, {
|
|
|
763
767
|
const { enqueue, budget } = services.queue;
|
|
764
768
|
const ports = services.ports.slots;
|
|
765
769
|
const { allowsPrint } = services.authority;
|
|
770
|
+
const { documentPrint } = services;
|
|
766
771
|
const printLatch = services.printLatch;
|
|
767
772
|
/**
|
|
768
773
|
* Run one catalog lifecycle tree inside the current queue operation, shared
|
|
@@ -802,13 +807,21 @@ function createDocumentEvents(services, { ensureOpenSequenceBeforeDocEvent }, {
|
|
|
802
807
|
return foldSteps(step ? [step] : [], diagnostics);
|
|
803
808
|
};
|
|
804
809
|
/**
|
|
805
|
-
* Both
|
|
806
|
-
*
|
|
807
|
-
* `
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
* returns
|
|
810
|
+
* Both print paths (the Named Print verb, and script `doc.print()` effects
|
|
811
|
+
* from the actions plane) go through here. While the latch is held
|
|
812
|
+
* (including `runDocumentVerb('print')`'s body) a nested request is
|
|
813
|
+
* suppressed with `reentrant-print`.
|
|
814
|
+
*
|
|
815
|
+
* With the kernel's print, a user's request starts `documents.print()` and
|
|
816
|
+
* returns: the kernel runs /WP and /DP around the dialog through this
|
|
817
|
+
* plugin's `aroundPrint` wrap, a `runDocumentVerb('print')` that waits for
|
|
818
|
+
* the current queue operation, so it is never awaited here. A hover or
|
|
819
|
+
* lifecycle request never opens the dialog.
|
|
820
|
+
*
|
|
821
|
+
* Without a printer: /WP → `ports.uiAdapter.print` exactly once → /DP,
|
|
822
|
+
* with the latch reset in `finally`. An adapter throw skips /DP (the latch
|
|
823
|
+
* still resets). /DP fires when the adapter call returns, since a browser
|
|
824
|
+
* cannot observe dialog completion.
|
|
812
825
|
*/
|
|
813
826
|
const firePrintThroughAdapter = async (uiContext, diagnose) => {
|
|
814
827
|
if (printLatch.active) {
|
|
@@ -831,6 +844,23 @@ function createDocumentEvents(services, { ensureOpenSequenceBeforeDocEvent }, {
|
|
|
831
844
|
detail: "doc.print is not allowed"
|
|
832
845
|
};
|
|
833
846
|
}
|
|
847
|
+
if (documentPrint.available()) {
|
|
848
|
+
if (uiContext && uiContext.origin !== "user") {
|
|
849
|
+
diagnose({
|
|
850
|
+
code: "blocked",
|
|
851
|
+
message: `print: a ${uiContext.origin} request never prints`
|
|
852
|
+
});
|
|
853
|
+
return {
|
|
854
|
+
status: "blocked",
|
|
855
|
+
detail: `${uiContext.origin} print request`
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
documentPrint.start().catch((error) => diagnose({
|
|
859
|
+
code: "trigger-failed",
|
|
860
|
+
message: `print: ${error instanceof Error ? error.message : String(error)}`
|
|
861
|
+
}));
|
|
862
|
+
return { status: "executed" };
|
|
863
|
+
}
|
|
834
864
|
if (!ports.uiAdapter) {
|
|
835
865
|
diagnose({
|
|
836
866
|
code: "no-adapter",
|
|
@@ -1205,7 +1235,7 @@ function createScriptWorld(ctx, { form }) {
|
|
|
1205
1235
|
};
|
|
1206
1236
|
const scriptEventFor = (actionContext, snapshot) => {
|
|
1207
1237
|
const provenance = actionContext.event;
|
|
1208
|
-
const type = provenance.scope === "page" ? "Page" : provenance.scope === "document" ? "Doc" : actionContext.source.kind === "widget" ? "Field" : actionContext.source.kind === "link" ? "Link" : "Annot";
|
|
1238
|
+
const type = provenance.scope === "page" ? "Page" : provenance.scope === "document" ? "Doc" : actionContext.source.kind === "widget" ? "Field" : actionContext.source.kind === "link" ? "Link" : actionContext.source.kind === "outline" ? "Bookmark" : "Annot";
|
|
1209
1239
|
const name = provenance.scope === "activate" ? "Mouse Up" : provenance.scope === "annotation" ? ANNOTATION_EVENT_NAMES[provenance.name] ?? "Mouse Up" : provenance.scope === "page" ? PAGE_EVENT_NAMES[provenance.name] ?? "Open" : DOC_EVENT_NAMES[provenance.name] ?? "Open";
|
|
1210
1240
|
const targetRef = actionContext.source.kind === "widget" ? actionContext.source.field : void 0;
|
|
1211
1241
|
const targetField = targetRef ? snapshot.fields.find((field) => targetRef.kind === "objectNumber" && field.ref.kind === "objectNumber" ? field.ref.objectNumber === targetRef.objectNumber : targetRef.kind === "fqn" && field.name === targetRef.name) : void 0;
|
|
@@ -1438,6 +1468,7 @@ function createScriptSurface(services, { performSubmit }) {
|
|
|
1438
1468
|
const { reportDiagnostic, scriptDiagnosticReported, scriptFailed } = services.events;
|
|
1439
1469
|
const ports = services.ports.slots;
|
|
1440
1470
|
const { allowsPrint } = services.authority;
|
|
1471
|
+
const { documentPrint } = services;
|
|
1441
1472
|
const printLatch = services.printLatch;
|
|
1442
1473
|
const surfaceScriptResult = (result) => {
|
|
1443
1474
|
const uiContext = {
|
|
@@ -1478,6 +1509,23 @@ function createScriptSurface(services, { performSubmit }) {
|
|
|
1478
1509
|
});
|
|
1479
1510
|
continue;
|
|
1480
1511
|
}
|
|
1512
|
+
if (effect.kind === "print" && documentPrint.available()) {
|
|
1513
|
+
if (result.origin !== "user") {
|
|
1514
|
+
scriptDiagnosticReported.emit({
|
|
1515
|
+
code: "ui-effect-suppressed",
|
|
1516
|
+
message: `script print request from a ${result.origin} event suppressed`
|
|
1517
|
+
});
|
|
1518
|
+
continue;
|
|
1519
|
+
}
|
|
1520
|
+
documentPrint.start().catch((error) => reportDiagnostic({
|
|
1521
|
+
code: "trigger-failed",
|
|
1522
|
+
message: `print: ${error instanceof Error ? error.message : String(error)}`
|
|
1523
|
+
}, {
|
|
1524
|
+
action: "javascript",
|
|
1525
|
+
source
|
|
1526
|
+
}));
|
|
1527
|
+
continue;
|
|
1528
|
+
}
|
|
1481
1529
|
if (!ports.uiAdapter) {
|
|
1482
1530
|
reportDiagnostic({
|
|
1483
1531
|
code: "no-adapter",
|
|
@@ -1563,6 +1611,24 @@ function createCatalog(ctx) {
|
|
|
1563
1611
|
};
|
|
1564
1612
|
}
|
|
1565
1613
|
//#endregion
|
|
1614
|
+
//#region src/services/document-print.ts
|
|
1615
|
+
/**
|
|
1616
|
+
* The kernel's print, where the document's own print requests go (the Named Print verb, a
|
|
1617
|
+
* script's `print()`) when the host gave the kernel a printer. The kernel prints the
|
|
1618
|
+
* document's pages, and runs the document's /WP and /DP around the dialog through the wrap
|
|
1619
|
+
* this plugin registers (`ctx.aroundPrint`). Without a printer, requests fall back to the UI
|
|
1620
|
+
* adapter's `print`.
|
|
1621
|
+
*/
|
|
1622
|
+
function createDocumentPrint(ctx) {
|
|
1623
|
+
const documents = () => ctx.get(DocumentsToken);
|
|
1624
|
+
return {
|
|
1625
|
+
/** Whether the kernel prints this document: `doc.print`, and the host gave a printer. */
|
|
1626
|
+
available: () => documents().canPrint(),
|
|
1627
|
+
/** Print the document through the kernel. */
|
|
1628
|
+
start: () => documents().print()
|
|
1629
|
+
};
|
|
1630
|
+
}
|
|
1631
|
+
//#endregion
|
|
1566
1632
|
//#region src/services/events.ts
|
|
1567
1633
|
function createEvents(ctx) {
|
|
1568
1634
|
const executed = ctx.events.source();
|
|
@@ -1674,6 +1740,7 @@ function createServices(ctx) {
|
|
|
1674
1740
|
catalog: createCatalog(ctx),
|
|
1675
1741
|
form: createForm(ctx, ports.slots),
|
|
1676
1742
|
authority: createAuthority(ctx),
|
|
1743
|
+
documentPrint: createDocumentPrint(ctx),
|
|
1677
1744
|
printLatch: createPrintLatch()
|
|
1678
1745
|
};
|
|
1679
1746
|
}
|
|
@@ -1828,6 +1895,7 @@ function createActionsController(ctx, config = {}) {
|
|
|
1828
1895
|
ctx.listen(ctx.doc.events, (event) => triggers.invalidate(event));
|
|
1829
1896
|
openSequence.arm();
|
|
1830
1897
|
ctx.aroundDownload((read) => documentEvents.api.runDocumentVerb("save", read));
|
|
1898
|
+
ctx.aroundPrint((print) => documentEvents.api.runDocumentVerb("print", print));
|
|
1831
1899
|
}
|
|
1832
1900
|
};
|
|
1833
1901
|
}
|