@embedpdf/react 3.0.0-next.10 → 3.0.0-next.12
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/{AnnotationListSnapshot-DDxHpJQU-BG32YXxG.d.ts → AnnotationListSnapshot-x6tKulNV-B799rYyi.d.cts} +223 -24
- package/dist/{AnnotationListSnapshot-DDxHpJQU-BG32YXxG.d.cts → AnnotationListSnapshot-x6tKulNV-B799rYyi.d.ts} +223 -24
- package/dist/actions.cjs +42 -0
- package/dist/actions.cjs.map +1 -0
- package/dist/actions.d.cts +18 -0
- package/dist/actions.d.ts +18 -0
- package/dist/actions.js +34 -0
- package/dist/actions.js.map +1 -0
- package/dist/annotation-BCED_p9H.d.cts +160 -0
- package/dist/annotation-anchors-CetwM1g7.js +15 -0
- package/dist/annotation-anchors-CetwM1g7.js.map +1 -0
- package/dist/annotation-anchors-DuYRBJLl.cjs +26 -0
- package/dist/annotation-anchors-DuYRBJLl.cjs.map +1 -0
- package/dist/annotation-hooks-BB5ZhPpf.cjs +16 -0
- package/dist/annotation-hooks-BB5ZhPpf.cjs.map +1 -0
- package/dist/annotation-hooks-Df8EmzDO.js +11 -0
- package/dist/annotation-hooks-Df8EmzDO.js.map +1 -0
- package/dist/annotation-k38KDlIZ.d.ts +160 -0
- package/dist/annotation-menu.cjs +5 -5
- package/dist/annotation-menu.cjs.map +1 -1
- package/dist/annotation-menu.js +2 -2
- package/dist/annotation-menu.js.map +1 -1
- package/dist/annotation.cjs +24 -29
- package/dist/annotation.cjs.map +1 -1
- package/dist/annotation.d.cts +2 -159
- package/dist/annotation.d.ts +2 -159
- package/dist/annotation.js +22 -27
- package/dist/annotation.js.map +1 -1
- package/dist/form-BwrLFpKN.js +805 -0
- package/dist/form-BwrLFpKN.js.map +1 -0
- package/dist/form-D-ZSfGmB.cjs +836 -0
- package/dist/form-D-ZSfGmB.cjs.map +1 -0
- package/dist/form.cjs +8 -551
- package/dist/form.d.cts +4 -21
- package/dist/form.d.ts +4 -21
- package/dist/form.js +3 -544
- package/dist/index.cjs +21 -11
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +9 -6
- package/dist/link.cjs +48 -8
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +2 -2
- package/dist/link.d.ts +2 -2
- package/dist/link.js +49 -9
- package/dist/link.js.map +1 -1
- package/dist/{runtime-Cvi0wQ4d.d.cts → runtime-DE76hlnl.d.ts} +13 -5
- package/dist/{runtime-DXxr8T4L.d.ts → runtime-umHA_xHt.d.cts} +13 -5
- package/dist/runtime.cjs +19 -0
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.cts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +19 -1
- package/dist/runtime.js.map +1 -1
- package/dist/scrollbar.cjs +3 -3
- package/dist/scrollbar.cjs.map +1 -1
- package/dist/scrollbar.d.cts +1 -1
- package/dist/scrollbar.d.ts +1 -1
- package/dist/scrollbar.js +1 -1
- package/dist/scrollbar.js.map +1 -1
- package/dist/search.d.cts +1 -1
- package/dist/search.d.ts +1 -1
- package/dist/selection.cjs +2 -2
- package/dist/selection.cjs.map +1 -1
- package/dist/selection.d.cts +1 -1
- package/dist/selection.d.ts +1 -1
- package/dist/selection.js +1 -1
- package/dist/selection.js.map +1 -1
- package/dist/stage.cjs +2 -2
- package/dist/stage.cjs.map +1 -1
- package/dist/stage.d.cts +1 -1
- package/dist/stage.d.ts +1 -1
- package/dist/stage.js +1 -1
- package/dist/stage.js.map +1 -1
- package/dist/stamp.cjs +7 -0
- package/dist/stamp.cjs.map +1 -1
- package/dist/stamp.d.cts +2 -1
- package/dist/stamp.d.ts +2 -1
- package/dist/stamp.js +2 -1
- package/dist/stamp.js.map +1 -1
- package/dist/toolbar.cjs +4 -4
- package/dist/toolbar.cjs.map +1 -1
- package/dist/toolbar.d.cts +1 -1
- package/dist/toolbar.d.ts +1 -1
- package/dist/toolbar.js +1 -1
- package/dist/toolbar.js.map +1 -1
- package/package.json +30 -24
- package/dist/form.cjs.map +0 -1
- package/dist/form.js.map +0 -1
package/dist/form.js
CHANGED
|
@@ -1,545 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
import { useEffect, useRef, useState } from "react";
|
|
5
|
-
import { StageToken } from "@embedpdf/plugin-stage";
|
|
6
|
-
import { InteractionToken } from "@embedpdf/plugin-interaction";
|
|
7
|
-
import { FormToken } from "@embedpdf/plugin-form";
|
|
1
|
+
import "./runtime.js";
|
|
2
|
+
import { a as useFormSnapshot, i as useFormField, n as formWidgetRenderer, r as useForm, t as FormLayer } from "./form-BwrLFpKN.js";
|
|
8
3
|
export * from "@embedpdf/plugin-form";
|
|
9
|
-
|
|
10
|
-
/** Content rect → a view-px box (the page wrapper's own coordinate space). */
|
|
11
|
-
function viewBox(r, page) {
|
|
12
|
-
const tl = page.transform.toPixels({
|
|
13
|
-
x: r.x,
|
|
14
|
-
y: r.y
|
|
15
|
-
});
|
|
16
|
-
const br = page.transform.toPixels({
|
|
17
|
-
x: r.x + r.width,
|
|
18
|
-
y: r.y + r.height
|
|
19
|
-
});
|
|
20
|
-
return {
|
|
21
|
-
left: tl.x,
|
|
22
|
-
top: tl.y,
|
|
23
|
-
width: br.x - tl.x,
|
|
24
|
-
height: br.y - tl.y
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Keep the interaction hub out of gestures that begin inside a fill control.
|
|
29
|
-
* Native listener (not React's) so it runs during real DOM bubbling, before
|
|
30
|
-
* the Stage's own native listener on an ancestor — same trick as FreeText.
|
|
31
|
-
*/
|
|
32
|
-
function useIsolated() {
|
|
33
|
-
const ref = useRef(null);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
const el = ref.current;
|
|
36
|
-
if (!el) return;
|
|
37
|
-
const stop = (e) => e.stopPropagation();
|
|
38
|
-
el.addEventListener("pointerdown", stop);
|
|
39
|
-
return () => el.removeEventListener("pointerdown", stop);
|
|
40
|
-
}, []);
|
|
41
|
-
return ref;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Fulfil form-script UI requests for the active document. By default alerts use
|
|
45
|
-
* the browser dialog, page navigation uses the main Stage, and print delegates
|
|
46
|
-
* to the browser. Pass handlers (or one raw provider) to replace that policy.
|
|
47
|
-
*/
|
|
48
|
-
function useFormScriptingProvider(adapter) {
|
|
49
|
-
const form = useOptionalCapability(FormToken);
|
|
50
|
-
const stage = useOptionalCapability(StageToken);
|
|
51
|
-
const adapterRef = useRef(adapter);
|
|
52
|
-
adapterRef.current = adapter;
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (!form) return;
|
|
55
|
-
const provider = (effect) => {
|
|
56
|
-
const current = adapterRef.current;
|
|
57
|
-
if (typeof current === "function") {
|
|
58
|
-
current(effect);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
switch (effect.kind) {
|
|
62
|
-
case "alert":
|
|
63
|
-
if (current?.alert) current.alert(effect.message, effect);
|
|
64
|
-
else if (typeof globalThis.alert === "function") globalThis.alert(effect.message);
|
|
65
|
-
break;
|
|
66
|
-
case "gotoPage":
|
|
67
|
-
if (current?.gotoPage) current.gotoPage(effect.page, effect);
|
|
68
|
-
else stage?.goToPage(effect.page);
|
|
69
|
-
break;
|
|
70
|
-
case "print":
|
|
71
|
-
if (current?.print) current.print(effect);
|
|
72
|
-
else if (typeof globalThis.print === "function") globalThis.print();
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
form.setUiEffectProvider(provider);
|
|
77
|
-
return () => form.setUiEffectProvider(null);
|
|
78
|
-
}, [form, stage]);
|
|
79
|
-
}
|
|
80
|
-
/** The baked /AP raster, blitted by its OWN box (exactly like BakedImage). */
|
|
81
|
-
function Picture({ page, appearance, apBox, frame, hidden }) {
|
|
82
|
-
if (!appearance) return null;
|
|
83
|
-
const b = viewBox(apBox ?? appearance.box, page);
|
|
84
|
-
return /* @__PURE__ */ jsx("img", {
|
|
85
|
-
src: appearance.url,
|
|
86
|
-
alt: "",
|
|
87
|
-
draggable: false,
|
|
88
|
-
style: {
|
|
89
|
-
position: "absolute",
|
|
90
|
-
left: b.left - (frame?.left ?? 0),
|
|
91
|
-
top: b.top - (frame?.top ?? 0),
|
|
92
|
-
width: b.width,
|
|
93
|
-
height: b.height,
|
|
94
|
-
maxWidth: "none",
|
|
95
|
-
pointerEvents: "none",
|
|
96
|
-
visibility: hidden ? "hidden" : "visible"
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Dispatch one engaged widget to its fill control. The FIELD plane (value,
|
|
102
|
-
* behavior, disabled) comes from the form plugin's single-widget projection;
|
|
103
|
-
* the WIDGET plane (live box, /DA font, baked raster) rides in on the
|
|
104
|
-
* renderer props — no geometry is read from the form model here.
|
|
105
|
-
*/
|
|
106
|
-
function FormWidget({ item, page, appearance }) {
|
|
107
|
-
const annot = item.ref?.kind === "objectNumber" ? item.ref.annotObjectNumber : 0;
|
|
108
|
-
const fill = useSelector(FormToken, (c) => annot > 0 ? c.fillItem(annot) : null);
|
|
109
|
-
if (!fill) return /* @__PURE__ */ jsx(Picture, {
|
|
110
|
-
page,
|
|
111
|
-
appearance,
|
|
112
|
-
apBox: item.apBox
|
|
113
|
-
});
|
|
114
|
-
switch (fill.control) {
|
|
115
|
-
case "text": return /* @__PURE__ */ jsx(TextWidget, {
|
|
116
|
-
fill,
|
|
117
|
-
item,
|
|
118
|
-
page,
|
|
119
|
-
appearance
|
|
120
|
-
});
|
|
121
|
-
case "toggle": return /* @__PURE__ */ jsx(ToggleWidget, {
|
|
122
|
-
fill,
|
|
123
|
-
item,
|
|
124
|
-
page,
|
|
125
|
-
appearance
|
|
126
|
-
});
|
|
127
|
-
case "choice": return /* @__PURE__ */ jsx(ChoiceWidget, {
|
|
128
|
-
fill,
|
|
129
|
-
item,
|
|
130
|
-
page,
|
|
131
|
-
appearance
|
|
132
|
-
});
|
|
133
|
-
case "button": return /* @__PURE__ */ jsx(ButtonWidget, {
|
|
134
|
-
fill,
|
|
135
|
-
item,
|
|
136
|
-
page,
|
|
137
|
-
appearance
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function ButtonWidget({ fill, item, page, appearance }) {
|
|
142
|
-
const form = useCapability(FormToken);
|
|
143
|
-
const wrap = useIsolated();
|
|
144
|
-
const b = viewBox(item.box, page);
|
|
145
|
-
return /* @__PURE__ */ jsx("button", {
|
|
146
|
-
ref: wrap,
|
|
147
|
-
type: "button",
|
|
148
|
-
"aria-label": fill.label,
|
|
149
|
-
disabled: fill.disabled,
|
|
150
|
-
onClick: () => {
|
|
151
|
-
if (item.ref) form.activateWidget(fill.key, item.ref);
|
|
152
|
-
},
|
|
153
|
-
style: {
|
|
154
|
-
position: "absolute",
|
|
155
|
-
left: b.left,
|
|
156
|
-
top: b.top,
|
|
157
|
-
width: b.width,
|
|
158
|
-
height: b.height,
|
|
159
|
-
boxSizing: "border-box",
|
|
160
|
-
padding: 0,
|
|
161
|
-
border: 0,
|
|
162
|
-
background: "transparent",
|
|
163
|
-
cursor: fill.disabled ? "default" : "pointer",
|
|
164
|
-
pointerEvents: fill.disabled ? "none" : "auto"
|
|
165
|
-
},
|
|
166
|
-
children: /* @__PURE__ */ jsx(Picture, {
|
|
167
|
-
page,
|
|
168
|
-
appearance,
|
|
169
|
-
apBox: item.apBox,
|
|
170
|
-
frame: b
|
|
171
|
-
})
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
function TextWidget({ fill, item, page, appearance }) {
|
|
175
|
-
const form = useCapability(FormToken);
|
|
176
|
-
const wrap = useIsolated();
|
|
177
|
-
const [focused, setFocused] = useState(false);
|
|
178
|
-
const [draft, setDraft] = useState(fill.value);
|
|
179
|
-
const cancelled = useRef(false);
|
|
180
|
-
useEffect(() => {
|
|
181
|
-
if (!focused) setDraft(fill.value);
|
|
182
|
-
}, [fill.value, focused]);
|
|
183
|
-
const b = viewBox(item.box, page);
|
|
184
|
-
const scale = item.box.width > 0 ? b.width / item.box.width : 1;
|
|
185
|
-
const fontSize = item.text && item.text.fontSize > 0 ? item.text.fontSize * scale : fill.multiline ? 12 * scale : Math.max(6, b.height * .72);
|
|
186
|
-
const editorStyle = {
|
|
187
|
-
position: "absolute",
|
|
188
|
-
inset: 0,
|
|
189
|
-
width: "100%",
|
|
190
|
-
height: "100%",
|
|
191
|
-
boxSizing: "border-box",
|
|
192
|
-
border: "none",
|
|
193
|
-
outline: focused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
|
|
194
|
-
outlineOffset: -2,
|
|
195
|
-
padding: "0 2px",
|
|
196
|
-
margin: 0,
|
|
197
|
-
background: item.style.interiorColor ?? "#fff",
|
|
198
|
-
color: item.text?.fontColor ?? "#000",
|
|
199
|
-
fontFamily: item.text?.fontFamily ?? "Helvetica, Arial, sans-serif",
|
|
200
|
-
fontSize,
|
|
201
|
-
textAlign: item.text?.textAlign ?? "left",
|
|
202
|
-
resize: "none",
|
|
203
|
-
cursor: "text",
|
|
204
|
-
opacity: focused ? 1 : 0
|
|
205
|
-
};
|
|
206
|
-
const editorProps = {
|
|
207
|
-
value: draft,
|
|
208
|
-
maxLength: fill.maxLength ?? void 0,
|
|
209
|
-
"aria-label": fill.label,
|
|
210
|
-
disabled: fill.disabled,
|
|
211
|
-
onFocus: () => setFocused(true),
|
|
212
|
-
onChange: (e) => setDraft(e.target.value),
|
|
213
|
-
onBlur: () => {
|
|
214
|
-
setFocused(false);
|
|
215
|
-
if (cancelled.current) {
|
|
216
|
-
cancelled.current = false;
|
|
217
|
-
setDraft(fill.value);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (draft !== fill.value) form.setText(fill.key, draft);
|
|
221
|
-
},
|
|
222
|
-
style: editorStyle
|
|
223
|
-
};
|
|
224
|
-
const onKeys = (e) => {
|
|
225
|
-
if (e.key === "Escape") {
|
|
226
|
-
cancelled.current = true;
|
|
227
|
-
e.currentTarget.blur();
|
|
228
|
-
}
|
|
229
|
-
if (e.key === "Enter" && !fill.multiline) e.currentTarget.blur();
|
|
230
|
-
};
|
|
231
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
232
|
-
ref: wrap,
|
|
233
|
-
style: {
|
|
234
|
-
position: "absolute",
|
|
235
|
-
left: b.left,
|
|
236
|
-
top: b.top,
|
|
237
|
-
width: b.width,
|
|
238
|
-
height: b.height,
|
|
239
|
-
pointerEvents: fill.disabled ? "none" : "auto"
|
|
240
|
-
},
|
|
241
|
-
children: [/* @__PURE__ */ jsx(Picture, {
|
|
242
|
-
page,
|
|
243
|
-
appearance,
|
|
244
|
-
apBox: item.apBox,
|
|
245
|
-
frame: b,
|
|
246
|
-
hidden: focused
|
|
247
|
-
}), fill.multiline ? /* @__PURE__ */ jsx("textarea", {
|
|
248
|
-
...editorProps,
|
|
249
|
-
onKeyDown: onKeys
|
|
250
|
-
}) : /* @__PURE__ */ jsx("input", {
|
|
251
|
-
...editorProps,
|
|
252
|
-
type: fill.password ? "password" : "text",
|
|
253
|
-
onKeyDown: onKeys
|
|
254
|
-
})]
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
function ToggleWidget({ fill, item, page, appearance }) {
|
|
258
|
-
const form = useCapability(FormToken);
|
|
259
|
-
const wrap = useIsolated();
|
|
260
|
-
const [focused, setFocused] = useState(false);
|
|
261
|
-
const b = viewBox(item.box, page);
|
|
262
|
-
const toggle = () => {
|
|
263
|
-
if (fill.disabled) return;
|
|
264
|
-
form.toggle(fill.key, fill.kind === "checkbox" && fill.checked ? null : fill.onState);
|
|
265
|
-
};
|
|
266
|
-
return /* @__PURE__ */ jsx("div", {
|
|
267
|
-
ref: wrap,
|
|
268
|
-
role: fill.kind === "checkbox" ? "checkbox" : "radio",
|
|
269
|
-
"aria-checked": fill.checked,
|
|
270
|
-
"aria-label": fill.label,
|
|
271
|
-
tabIndex: fill.disabled ? -1 : 0,
|
|
272
|
-
onClick: toggle,
|
|
273
|
-
onFocus: () => setFocused(true),
|
|
274
|
-
onBlur: () => setFocused(false),
|
|
275
|
-
onKeyDown: (e) => {
|
|
276
|
-
if (e.key === " " || e.key === "Enter") {
|
|
277
|
-
e.preventDefault();
|
|
278
|
-
toggle();
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
style: {
|
|
282
|
-
position: "absolute",
|
|
283
|
-
left: b.left,
|
|
284
|
-
top: b.top,
|
|
285
|
-
width: b.width,
|
|
286
|
-
height: b.height,
|
|
287
|
-
cursor: fill.disabled ? "default" : "pointer",
|
|
288
|
-
pointerEvents: fill.disabled ? "none" : "auto",
|
|
289
|
-
outline: focused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
|
|
290
|
-
outlineOffset: -2
|
|
291
|
-
},
|
|
292
|
-
children: /* @__PURE__ */ jsx(Picture, {
|
|
293
|
-
page,
|
|
294
|
-
appearance,
|
|
295
|
-
apBox: item.apBox,
|
|
296
|
-
frame: b
|
|
297
|
-
})
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
function ChoiceWidget({ fill, item, page, appearance }) {
|
|
301
|
-
const form = useCapability(FormToken);
|
|
302
|
-
const wrap = useIsolated();
|
|
303
|
-
const [focused, setFocused] = useState(false);
|
|
304
|
-
const b = viewBox(item.box, page);
|
|
305
|
-
const multiple = fill.kind === "list" && fill.multi;
|
|
306
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
307
|
-
ref: wrap,
|
|
308
|
-
style: {
|
|
309
|
-
position: "absolute",
|
|
310
|
-
left: b.left,
|
|
311
|
-
top: b.top,
|
|
312
|
-
width: b.width,
|
|
313
|
-
height: b.height,
|
|
314
|
-
pointerEvents: fill.disabled ? "none" : "auto",
|
|
315
|
-
outline: focused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
|
|
316
|
-
outlineOffset: -2
|
|
317
|
-
},
|
|
318
|
-
children: [/* @__PURE__ */ jsx(Picture, {
|
|
319
|
-
page,
|
|
320
|
-
appearance,
|
|
321
|
-
apBox: item.apBox,
|
|
322
|
-
frame: b
|
|
323
|
-
}), /* @__PURE__ */ jsx("select", {
|
|
324
|
-
multiple,
|
|
325
|
-
size: fill.kind === "list" ? Math.max(2, fill.options.length) : void 0,
|
|
326
|
-
defaultValue: multiple ? fill.selected : fill.selected[0] ?? "",
|
|
327
|
-
"aria-label": fill.label,
|
|
328
|
-
disabled: fill.disabled,
|
|
329
|
-
onFocus: () => setFocused(true),
|
|
330
|
-
onBlur: () => setFocused(false),
|
|
331
|
-
onChange: (e) => {
|
|
332
|
-
const values = Array.from(e.currentTarget.selectedOptions).map((o) => o.value);
|
|
333
|
-
form.choose(fill.key, values);
|
|
334
|
-
},
|
|
335
|
-
style: {
|
|
336
|
-
position: "absolute",
|
|
337
|
-
inset: 0,
|
|
338
|
-
width: "100%",
|
|
339
|
-
height: "100%",
|
|
340
|
-
opacity: 0,
|
|
341
|
-
cursor: fill.disabled ? "default" : "pointer"
|
|
342
|
-
},
|
|
343
|
-
children: fill.options.map((o, i) => /* @__PURE__ */ jsx("option", {
|
|
344
|
-
value: o.value,
|
|
345
|
-
children: o.label
|
|
346
|
-
}, i))
|
|
347
|
-
}, fill.selected.join("\0"))]
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* The form plugin's renderer entry, ready for
|
|
352
|
-
* `<AnnotationLayer renderers={[formWidgetRenderer]} />`. It answers for the
|
|
353
|
-
* PLUGIN-registered 'form-widgets' Behavior — the form plugin decides when
|
|
354
|
-
* widgets are fill controls vs. editable annotations, never the app.
|
|
355
|
-
*/
|
|
356
|
-
const formWidgetRenderer = {
|
|
357
|
-
behavior: "form-widgets",
|
|
358
|
-
component: FormWidget
|
|
359
|
-
};
|
|
360
|
-
const controlBase = {
|
|
361
|
-
position: "absolute",
|
|
362
|
-
boxSizing: "border-box",
|
|
363
|
-
border: "1px solid rgba(56, 88, 233, 0.55)",
|
|
364
|
-
background: "rgba(255, 255, 255, 0.92)",
|
|
365
|
-
borderRadius: 2,
|
|
366
|
-
font: "inherit"
|
|
367
|
-
};
|
|
368
|
-
const fillBox = (item, page) => viewBox(item.box, page);
|
|
369
|
-
/** Text control: keystrokes stay LOCAL (the input is the draft store);
|
|
370
|
-
* the engine write happens on blur or Enter. */
|
|
371
|
-
function FillText({ item, page }) {
|
|
372
|
-
const form = useCapability(FormToken);
|
|
373
|
-
const [draft, setDraft] = useState(item.value);
|
|
374
|
-
useEffect(() => setDraft(item.value), [item.value]);
|
|
375
|
-
const css = fillBox(item, page);
|
|
376
|
-
const fontSize = Math.max(9, Math.min(css.height * .62, 24));
|
|
377
|
-
const commit = () => {
|
|
378
|
-
if (draft !== item.value) form.setText(item.key, draft).catch(() => setDraft(item.value));
|
|
379
|
-
};
|
|
380
|
-
const shared = {
|
|
381
|
-
...controlBase,
|
|
382
|
-
...css,
|
|
383
|
-
fontSize,
|
|
384
|
-
padding: "0 3px",
|
|
385
|
-
...item.comb ? { letterSpacing: css.width / Math.max(1, item.maxLength ?? 1) / 2 } : {}
|
|
386
|
-
};
|
|
387
|
-
return item.multiline ? /* @__PURE__ */ jsx("textarea", {
|
|
388
|
-
"aria-label": item.label,
|
|
389
|
-
value: draft,
|
|
390
|
-
disabled: item.disabled,
|
|
391
|
-
onChange: (e) => setDraft(e.target.value),
|
|
392
|
-
onBlur: commit,
|
|
393
|
-
style: {
|
|
394
|
-
...shared,
|
|
395
|
-
resize: "none"
|
|
396
|
-
}
|
|
397
|
-
}) : /* @__PURE__ */ jsx("input", {
|
|
398
|
-
"aria-label": item.label,
|
|
399
|
-
type: item.password ? "password" : "text",
|
|
400
|
-
value: draft,
|
|
401
|
-
maxLength: item.maxLength ?? void 0,
|
|
402
|
-
disabled: item.disabled,
|
|
403
|
-
onChange: (e) => setDraft(e.target.value),
|
|
404
|
-
onBlur: commit,
|
|
405
|
-
onKeyDown: (e) => {
|
|
406
|
-
if (e.key === "Enter") e.target.blur();
|
|
407
|
-
},
|
|
408
|
-
style: shared
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
function FillToggle({ item, page }) {
|
|
412
|
-
const form = useCapability(FormToken);
|
|
413
|
-
const css = fillBox(item, page);
|
|
414
|
-
const glyphSize = Math.min(css.width, css.height) * .72;
|
|
415
|
-
return /* @__PURE__ */ jsx("button", {
|
|
416
|
-
role: item.kind,
|
|
417
|
-
"aria-checked": item.checked,
|
|
418
|
-
"aria-label": item.label,
|
|
419
|
-
disabled: item.disabled,
|
|
420
|
-
onClick: () => void form.toggle(item.key, item.kind === "checkbox" && item.checked ? null : item.onState),
|
|
421
|
-
style: {
|
|
422
|
-
...controlBase,
|
|
423
|
-
...css,
|
|
424
|
-
cursor: item.disabled ? "default" : "pointer",
|
|
425
|
-
display: "grid",
|
|
426
|
-
placeItems: "center",
|
|
427
|
-
padding: 0,
|
|
428
|
-
borderRadius: item.kind === "radio" ? "50%" : 2,
|
|
429
|
-
fontSize: glyphSize,
|
|
430
|
-
lineHeight: 1,
|
|
431
|
-
color: "#1f2a44"
|
|
432
|
-
},
|
|
433
|
-
children: item.checked ? item.kind === "radio" ? "●" : "✓" : ""
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
function FillChoice({ item, page }) {
|
|
437
|
-
const form = useCapability(FormToken);
|
|
438
|
-
const css = fillBox(item, page);
|
|
439
|
-
return /* @__PURE__ */ jsxs("select", {
|
|
440
|
-
"aria-label": item.label,
|
|
441
|
-
multiple: item.multi,
|
|
442
|
-
disabled: item.disabled,
|
|
443
|
-
value: item.multi ? item.selected : item.selected[0] ?? "",
|
|
444
|
-
onChange: (e) => {
|
|
445
|
-
const values = item.multi ? Array.from(e.target.selectedOptions).map((o) => o.value) : [e.target.value];
|
|
446
|
-
form.choose(item.key, values);
|
|
447
|
-
},
|
|
448
|
-
style: {
|
|
449
|
-
...controlBase,
|
|
450
|
-
...css,
|
|
451
|
-
fontSize: Math.max(9, Math.min(css.height * .55, 18))
|
|
452
|
-
},
|
|
453
|
-
children: [!item.multi && item.selected.length === 0 && /* @__PURE__ */ jsx("option", { value: "" }), item.options.map((o) => /* @__PURE__ */ jsx("option", {
|
|
454
|
-
value: o.value,
|
|
455
|
-
children: o.label
|
|
456
|
-
}, o.value))]
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
function FillButton({ item, page }) {
|
|
460
|
-
const form = useCapability(FormToken);
|
|
461
|
-
const css = fillBox(item, page);
|
|
462
|
-
return /* @__PURE__ */ jsx("button", {
|
|
463
|
-
type: "button",
|
|
464
|
-
"aria-label": item.label,
|
|
465
|
-
disabled: item.disabled,
|
|
466
|
-
onClick: () => void form.activateWidget(item.key, {
|
|
467
|
-
kind: "objectNumber",
|
|
468
|
-
pageObjectNumber: page.pon,
|
|
469
|
-
annotObjectNumber: item.annotObjectNumber
|
|
470
|
-
}),
|
|
471
|
-
style: {
|
|
472
|
-
...controlBase,
|
|
473
|
-
...css,
|
|
474
|
-
padding: 0,
|
|
475
|
-
border: 0,
|
|
476
|
-
background: "transparent",
|
|
477
|
-
cursor: item.disabled ? "default" : "pointer"
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Fill-mode form controls for one page, positioned from the form model's own
|
|
483
|
-
* widget geometry — the ANNOTATION-LESS path (a fill-only viewer whose page
|
|
484
|
-
* pixels come from an annotated RenderLayer raster). Active whenever the
|
|
485
|
-
* active tool carries the 'form-fill' tag (the built-in pointer/pan tools
|
|
486
|
-
* do); any other tool stands the controls down. Do not mount next to an
|
|
487
|
-
* AnnotationLayer wired with `formWidgetBehaviors`.
|
|
488
|
-
*/
|
|
489
|
-
function FormLayer() {
|
|
490
|
-
const page = usePage();
|
|
491
|
-
const form = useCapability(FormToken);
|
|
492
|
-
const active = useSelector(InteractionToken, (c) => c.activeTool().enables.has("form-fill"));
|
|
493
|
-
useEffect(() => {
|
|
494
|
-
if (active) form.ensureGeom(page.pon);
|
|
495
|
-
}, [
|
|
496
|
-
active,
|
|
497
|
-
form,
|
|
498
|
-
page.pon
|
|
499
|
-
]);
|
|
500
|
-
const items = useSelector(FormToken, (c) => c.fillItems(page.pon), shallowArray);
|
|
501
|
-
if (!active) return null;
|
|
502
|
-
return /* @__PURE__ */ jsx("div", {
|
|
503
|
-
style: {
|
|
504
|
-
position: "absolute",
|
|
505
|
-
inset: 0
|
|
506
|
-
},
|
|
507
|
-
children: items.map((item) => item.control === "text" ? /* @__PURE__ */ jsx(FillText, {
|
|
508
|
-
item,
|
|
509
|
-
page
|
|
510
|
-
}, `${item.key}:${item.annotObjectNumber}`) : item.control === "toggle" ? /* @__PURE__ */ jsx(FillToggle, {
|
|
511
|
-
item,
|
|
512
|
-
page
|
|
513
|
-
}, `${item.key}:${item.annotObjectNumber}`) : item.control === "choice" ? /* @__PURE__ */ jsx(FillChoice, {
|
|
514
|
-
item,
|
|
515
|
-
page
|
|
516
|
-
}, `${item.key}:${item.annotObjectNumber}`) : item.control === "button" ? /* @__PURE__ */ jsx(FillButton, {
|
|
517
|
-
item,
|
|
518
|
-
page
|
|
519
|
-
}, `${item.key}:${item.annotObjectNumber}`) : null)
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
/** The form capability — values, interchange, design-mode verbs. */
|
|
523
|
-
function useForm() {
|
|
524
|
-
return useCapability(FormToken);
|
|
525
|
-
}
|
|
526
|
-
/** The reconciled form snapshot (null until the first load lands),
|
|
527
|
-
* re-rendering on every form model change. */
|
|
528
|
-
function useFormSnapshot() {
|
|
529
|
-
return useSelector(FormToken, (c) => c.snapshot());
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* The FIELD behind the currently selected widget annotation (single
|
|
533
|
-
* selection), or null. The design-mode join: widget selection lives in the
|
|
534
|
-
* annotation plane, field properties live here.
|
|
535
|
-
*/
|
|
536
|
-
function useFormField() {
|
|
537
|
-
const selected = useAnnotationSelected();
|
|
538
|
-
const widget = selected.length === 1 && selected[0].subtype === "widget" ? selected[0] : null;
|
|
539
|
-
const objnum = widget && widget.ref.kind === "objectNumber" ? widget.ref.annotObjectNumber : 0;
|
|
540
|
-
return useSelector(FormToken, (c) => objnum > 0 ? c.fieldForWidget(objnum) : null);
|
|
541
|
-
}
|
|
542
|
-
//#endregion
|
|
543
|
-
export { FormLayer, formWidgetRenderer, useForm, useFormField, useFormScriptingProvider, useFormSnapshot };
|
|
544
|
-
|
|
545
|
-
//# sourceMappingURL=form.js.map
|
|
4
|
+
export { FormLayer, formWidgetRenderer, useForm, useFormField, useFormSnapshot };
|
package/dist/index.cjs
CHANGED
|
@@ -8,14 +8,17 @@ const require_page_view = require("./page-view.cjs");
|
|
|
8
8
|
const require_render = require("./render.cjs");
|
|
9
9
|
const require_interaction = require("./interaction.cjs");
|
|
10
10
|
const require_selection = require("./selection.cjs");
|
|
11
|
+
const require_annotation_anchors = require("./annotation-anchors-DuYRBJLl.cjs");
|
|
12
|
+
const require_annotation_hooks = require("./annotation-hooks-BB5ZhPpf.cjs");
|
|
11
13
|
const require_annotation = require("./annotation.cjs");
|
|
12
14
|
const require_annotation_menu = require("./annotation-menu.cjs");
|
|
13
15
|
const require_link = require("./link.cjs");
|
|
16
|
+
const require_actions = require("./actions.cjs");
|
|
14
17
|
const require_views = require("./views.cjs");
|
|
15
18
|
const require_page_edit = require("./page-edit.cjs");
|
|
16
19
|
const require_metadata = require("./metadata.cjs");
|
|
17
20
|
const require_redaction = require("./redaction.cjs");
|
|
18
|
-
const require_form = require("./form.cjs");
|
|
21
|
+
const require_form = require("./form-D-ZSfGmB.cjs");
|
|
19
22
|
const require_search = require("./search.cjs");
|
|
20
23
|
const require_stamp = require("./stamp.cjs");
|
|
21
24
|
const require_i18n = require("./i18n.cjs");
|
|
@@ -55,19 +58,27 @@ Object.defineProperty(exports, "copySelection", {
|
|
|
55
58
|
exports.createClickCounter = require_interaction.createClickCounter;
|
|
56
59
|
exports.enrichCommentThreads = require_annotation.enrichCommentThreads;
|
|
57
60
|
exports.filePickerProvider = require_annotation.filePickerProvider;
|
|
61
|
+
Object.defineProperty(exports, "indexedDbByteStore", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function() {
|
|
64
|
+
return _embedpdf_web.indexedDbByteStore;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
58
67
|
exports.isMacPlatform = require_commands.isMacPlatform;
|
|
59
68
|
exports.makePageContext = require_runtime.makePageContext;
|
|
60
69
|
exports.openLinkTarget = require_link.openLinkTarget;
|
|
61
|
-
exports.sameAnchor =
|
|
62
|
-
exports.sameCreationDraftAnchor =
|
|
70
|
+
exports.sameAnchor = require_annotation_anchors.sameAnchor;
|
|
71
|
+
exports.sameCreationDraftAnchor = require_annotation_anchors.sameCreationDraftAnchor;
|
|
63
72
|
exports.shallowArray = require_runtime.shallowArray;
|
|
73
|
+
exports.useActionsUiAdapter = require_actions.useActionsUiAdapter;
|
|
64
74
|
exports.useActiveDocumentId = require_runtime.useActiveDocumentId;
|
|
65
75
|
exports.useAnnotation = require_annotation.useAnnotation;
|
|
66
76
|
exports.useAnnotationDefaults = require_annotation.useAnnotationDefaults;
|
|
67
|
-
exports.useAnnotationSelected =
|
|
77
|
+
exports.useAnnotationSelected = require_annotation_hooks.useAnnotationSelected;
|
|
68
78
|
exports.useAnnotationSelection = require_annotation.useAnnotationSelection;
|
|
69
79
|
exports.useArmStampAsset = require_stamp.useArmStampAsset;
|
|
70
80
|
exports.useCapability = require_runtime.useCapability;
|
|
81
|
+
exports.useCapabilityEvent = require_runtime.useCapabilityEvent;
|
|
71
82
|
exports.useCommand = require_commands.useCommand;
|
|
72
83
|
exports.useCommandShortcuts = require_commands.useCommandShortcuts;
|
|
73
84
|
exports.useCommands = require_commands.useCommands;
|
|
@@ -81,7 +92,6 @@ exports.useDocuments = require_runtime.useDocuments;
|
|
|
81
92
|
exports.useFilePickerProvider = require_annotation.useFilePickerProvider;
|
|
82
93
|
exports.useForm = require_form.useForm;
|
|
83
94
|
exports.useFormField = require_form.useFormField;
|
|
84
|
-
exports.useFormScriptingProvider = require_form.useFormScriptingProvider;
|
|
85
95
|
exports.useI18n = require_i18n.useI18n;
|
|
86
96
|
exports.useKernel = require_runtime.useKernel;
|
|
87
97
|
exports.useKernelValue = require_runtime.useKernelValue;
|
|
@@ -150,21 +160,21 @@ Object.keys(_embedpdf_plugin_stage).forEach(function(k) {
|
|
|
150
160
|
}
|
|
151
161
|
});
|
|
152
162
|
});
|
|
153
|
-
var
|
|
154
|
-
Object.keys(
|
|
163
|
+
var _embedpdf_plugin_render = require("@embedpdf/plugin-render");
|
|
164
|
+
Object.keys(_embedpdf_plugin_render).forEach(function(k) {
|
|
155
165
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
156
166
|
enumerable: true,
|
|
157
167
|
get: function() {
|
|
158
|
-
return
|
|
168
|
+
return _embedpdf_plugin_render[k];
|
|
159
169
|
}
|
|
160
170
|
});
|
|
161
171
|
});
|
|
162
|
-
var
|
|
163
|
-
Object.keys(
|
|
172
|
+
var _embedpdf_plugin_interaction = require("@embedpdf/plugin-interaction");
|
|
173
|
+
Object.keys(_embedpdf_plugin_interaction).forEach(function(k) {
|
|
164
174
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
165
175
|
enumerable: true,
|
|
166
176
|
get: function() {
|
|
167
|
-
return
|
|
177
|
+
return _embedpdf_plugin_interaction[k];
|
|
168
178
|
}
|
|
169
179
|
});
|
|
170
180
|
});
|