@embedpdf/plugin-form 3.0.0-next.1 → 3.0.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +72 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +11 -3
- package/dist/index.js +72 -49
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@ let _embedpdf_core = require("@embedpdf/core");
|
|
|
3
3
|
let _embedpdf_plugin_annotation = require("@embedpdf/plugin-annotation");
|
|
4
4
|
let _embedpdf_plugin_annotation_internal = require("@embedpdf/plugin-annotation/internal");
|
|
5
5
|
let _embedpdf_plugin_interaction = require("@embedpdf/plugin-interaction");
|
|
6
|
+
let _embedpdf_engine_core_runtime = require("@embedpdf/engine-core/runtime");
|
|
6
7
|
let _embedpdf_core_acrojs = require("@embedpdf/core-acrojs");
|
|
7
8
|
//#region src/core/model.ts
|
|
8
9
|
const fieldKeyOf = (field) => field.fieldObjectNumber > 0 ? `obj:${field.fieldObjectNumber}` : `fqn:${field.name}`;
|
|
@@ -781,10 +782,12 @@ function createFormCapability(ctx, options = {}) {
|
|
|
781
782
|
for (const diagnostic of result.diagnostics) observe(options.scripting?.onDiagnostic ? () => options.scripting.onDiagnostic(diagnostic) : void 0);
|
|
782
783
|
if (result.error) observe(options.scripting?.onError ? () => options.scripting.onError(result.error) : void 0);
|
|
783
784
|
};
|
|
785
|
+
const can = (cap) => ctx.doc?.security.allows(cap) ?? false;
|
|
784
786
|
let refreshPromise = null;
|
|
785
787
|
const refresh = async (force = false) => {
|
|
786
788
|
const doc = ctx.doc;
|
|
787
789
|
if (!doc) return;
|
|
790
|
+
if (!can("doc.forms.read")) return;
|
|
788
791
|
if (refreshPromise) {
|
|
789
792
|
await refreshPromise;
|
|
790
793
|
if (!force) return;
|
|
@@ -792,7 +795,9 @@ function createFormCapability(ctx, options = {}) {
|
|
|
792
795
|
refreshPromise = doc.forms.list().then((snapshot) => apply({
|
|
793
796
|
t: "snapshot",
|
|
794
797
|
snapshot
|
|
795
|
-
})).
|
|
798
|
+
})).catch((err) => {
|
|
799
|
+
console.warn("[form] form snapshot failed to load", err);
|
|
800
|
+
}).finally(() => {
|
|
796
801
|
refreshPromise = null;
|
|
797
802
|
});
|
|
798
803
|
return refreshPromise;
|
|
@@ -820,14 +825,20 @@ function createFormCapability(ctx, options = {}) {
|
|
|
820
825
|
geomLoading.delete(pon);
|
|
821
826
|
});
|
|
822
827
|
};
|
|
828
|
+
const fuseFill = (item, fillable) => item === null || fillable || item.disabled ? item : {
|
|
829
|
+
...item,
|
|
830
|
+
disabled: true
|
|
831
|
+
};
|
|
823
832
|
const fillCache = /* @__PURE__ */ new Map();
|
|
824
833
|
const fillItems$1 = (pon) => {
|
|
825
834
|
const m = model();
|
|
835
|
+
const fillable = can("doc.forms.fill");
|
|
826
836
|
const hit = fillCache.get(pon);
|
|
827
|
-
if (hit && hit.seq === m.seq) return hit.items;
|
|
828
|
-
const items = fillItems(m, pon);
|
|
837
|
+
if (hit && hit.seq === m.seq && hit.fillable === fillable) return hit.items;
|
|
838
|
+
const items = fillItems(m, pon).map((item) => fuseFill(item, fillable));
|
|
829
839
|
fillCache.set(pon, {
|
|
830
840
|
seq: m.seq,
|
|
841
|
+
fillable,
|
|
831
842
|
items
|
|
832
843
|
});
|
|
833
844
|
return items;
|
|
@@ -835,11 +846,13 @@ function createFormCapability(ctx, options = {}) {
|
|
|
835
846
|
const fillItemCache = /* @__PURE__ */ new Map();
|
|
836
847
|
const fillItem = (annotObjectNumber) => {
|
|
837
848
|
const m = model();
|
|
849
|
+
const fillable = can("doc.forms.fill");
|
|
838
850
|
const hit = fillItemCache.get(annotObjectNumber);
|
|
839
|
-
if (hit && hit.seq === m.seq) return hit.item;
|
|
840
|
-
const item = fillItemForWidget(m, annotObjectNumber);
|
|
851
|
+
if (hit && hit.seq === m.seq && hit.fillable === fillable) return hit.item;
|
|
852
|
+
const item = fuseFill(fillItemForWidget(m, annotObjectNumber), fillable);
|
|
841
853
|
fillItemCache.set(annotObjectNumber, {
|
|
842
854
|
seq: m.seq,
|
|
855
|
+
fillable,
|
|
843
856
|
item
|
|
844
857
|
});
|
|
845
858
|
return item;
|
|
@@ -863,31 +876,33 @@ function createFormCapability(ctx, options = {}) {
|
|
|
863
876
|
diagnostics: []
|
|
864
877
|
};
|
|
865
878
|
};
|
|
866
|
-
const write = (key, value) =>
|
|
867
|
-
if (!
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
key
|
|
871
|
-
});
|
|
872
|
-
try {
|
|
873
|
-
const result = await commitValueNow(refKeyOf(key), value);
|
|
874
|
-
if (result.status === "rejected" || result.status === "failed") apply({
|
|
875
|
-
t: "writeFailed",
|
|
876
|
-
key
|
|
877
|
-
});
|
|
878
|
-
else if (result.effectsResult === null && result.scripted) apply({
|
|
879
|
-
t: "writeFailed",
|
|
880
|
-
key
|
|
881
|
-
});
|
|
882
|
-
} catch (err) {
|
|
879
|
+
const write = (key, value) => {
|
|
880
|
+
if (!can("doc.forms.fill")) return Promise.reject(new _embedpdf_engine_core_runtime.PermissionDenied("doc.forms.fill", "form.fill"));
|
|
881
|
+
return enqueueMutation(async () => {
|
|
882
|
+
if (!ctx.doc) return;
|
|
883
883
|
apply({
|
|
884
|
-
t: "
|
|
884
|
+
t: "writeStart",
|
|
885
885
|
key
|
|
886
886
|
});
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
887
|
+
try {
|
|
888
|
+
const result = await commitValueNow(refKeyOf(key), value);
|
|
889
|
+
if (result.status === "rejected" || result.status === "failed") apply({
|
|
890
|
+
t: "writeFailed",
|
|
891
|
+
key
|
|
892
|
+
});
|
|
893
|
+
else if (result.effectsResult === null && result.scripted) apply({
|
|
894
|
+
t: "writeFailed",
|
|
895
|
+
key
|
|
896
|
+
});
|
|
897
|
+
} catch (err) {
|
|
898
|
+
apply({
|
|
899
|
+
t: "writeFailed",
|
|
900
|
+
key
|
|
901
|
+
});
|
|
902
|
+
throw err;
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
};
|
|
891
906
|
const annotationHost = ctx.tryGet(_embedpdf_plugin_annotation_internal.AnnotationToken);
|
|
892
907
|
const annotationActivation = async (ref) => {
|
|
893
908
|
const doc = ctx.doc;
|
|
@@ -1064,28 +1079,31 @@ function createFormCapability(ctx, options = {}) {
|
|
|
1064
1079
|
type: "choice",
|
|
1065
1080
|
values
|
|
1066
1081
|
}),
|
|
1067
|
-
reset: (key) =>
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
key
|
|
1073
|
-
});
|
|
1074
|
-
try {
|
|
1075
|
-
const result = await doc.forms.reset(refKeyOf(key));
|
|
1082
|
+
reset: (key) => {
|
|
1083
|
+
if (!can("doc.forms.fill")) return Promise.reject(new _embedpdf_engine_core_runtime.PermissionDenied("doc.forms.fill", "form.reset"));
|
|
1084
|
+
return enqueueMutation(async () => {
|
|
1085
|
+
const doc = ctx.doc;
|
|
1086
|
+
if (!doc) return;
|
|
1076
1087
|
apply({
|
|
1077
|
-
t: "
|
|
1078
|
-
key,
|
|
1079
|
-
field: result.field
|
|
1080
|
-
});
|
|
1081
|
-
} catch (err) {
|
|
1082
|
-
apply({
|
|
1083
|
-
t: "writeFailed",
|
|
1088
|
+
t: "writeStart",
|
|
1084
1089
|
key
|
|
1085
1090
|
});
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1091
|
+
try {
|
|
1092
|
+
const result = await doc.forms.reset(refKeyOf(key));
|
|
1093
|
+
apply({
|
|
1094
|
+
t: "writeDone",
|
|
1095
|
+
key,
|
|
1096
|
+
field: result.field
|
|
1097
|
+
});
|
|
1098
|
+
} catch (err) {
|
|
1099
|
+
apply({
|
|
1100
|
+
t: "writeFailed",
|
|
1101
|
+
key
|
|
1102
|
+
});
|
|
1103
|
+
throw err;
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
},
|
|
1089
1107
|
commitValue: (ref, value) => enqueueMutation(() => commitValueNow(ref, value)),
|
|
1090
1108
|
activateWidget: (key, annotationRef) => enqueueMutation(() => activateWidgetNow(key, annotationRef)),
|
|
1091
1109
|
setUiEffectProvider: (provider) => {
|
|
@@ -1125,8 +1143,9 @@ function createFormCapability(ctx, options = {}) {
|
|
|
1125
1143
|
updateField: (key, patch) => enqueueMutation(() => updateFieldNow(key, patch)),
|
|
1126
1144
|
deleteField: (key) => enqueueMutation(() => deleteFieldNow(key)),
|
|
1127
1145
|
detachWidget: (key, annotObjectNumber) => enqueueMutation(() => detachWidgetNow(key, annotObjectNumber)),
|
|
1146
|
+
canRead: () => can("doc.forms.read"),
|
|
1128
1147
|
canFill: () => can("doc.forms.fill"),
|
|
1129
|
-
|
|
1148
|
+
canDesign: () => can("doc.forms.modify")
|
|
1130
1149
|
};
|
|
1131
1150
|
}
|
|
1132
1151
|
//#endregion
|
|
@@ -1160,7 +1179,11 @@ function registerFormEffects(ctx) {
|
|
|
1160
1179
|
}
|
|
1161
1180
|
};
|
|
1162
1181
|
const unsubscribe = doc.events.subscribe((event) => {
|
|
1163
|
-
if (
|
|
1182
|
+
if (event.type === "stream.desynced") {
|
|
1183
|
+
refresh();
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
if (!event.type.startsWith("form.") || !("origin" in event)) return;
|
|
1164
1187
|
const structural = STRUCTURAL.has(event.type);
|
|
1165
1188
|
if (event.origin.kind !== "remote" && !structural) return;
|
|
1166
1189
|
if (structural) ctx.dispatch({
|
|
@@ -1276,7 +1299,7 @@ function createPlaceHandler(form, interaction, annotation) {
|
|
|
1276
1299
|
enabledFor: (t) => t.enables.has("form-place"),
|
|
1277
1300
|
onDown: (s) => {
|
|
1278
1301
|
if (!s.page || !FORM_TOOL_BY_ID.has(interaction.activeToolId())) return false;
|
|
1279
|
-
if (!form.
|
|
1302
|
+
if (!form.canDesign()) return false;
|
|
1280
1303
|
origin = {
|
|
1281
1304
|
pon: s.page.pon,
|
|
1282
1305
|
start: s.page.point,
|