@josephomills/esign 0.9.2 → 0.9.4

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/ui/index.cjs CHANGED
@@ -370,6 +370,7 @@ function FieldDesigner({
370
370
  const [drawMode, setDrawMode] = react.useState(false);
371
371
  const [pendingType, setPendingType] = react.useState("signature");
372
372
  const [configId, setConfigId] = react.useState(null);
373
+ const [configPos, setConfigPos] = react.useState(null);
373
374
  const [drag, setDrag] = react.useState(null);
374
375
  const [live, setLive] = react.useState(null);
375
376
  const stageRef = react.useRef(null);
@@ -477,7 +478,6 @@ function FieldDesigner({
477
478
  onChange([...value, f]);
478
479
  setSelectedId(f.id);
479
480
  setDrawMode(false);
480
- if (isDate) setConfigId(f.id);
481
481
  } else {
482
482
  onChange(value.map((x) => x.id === drag.id ? { ...x, ...live } : x));
483
483
  }
@@ -496,6 +496,11 @@ function FieldDesigner({
496
496
  function setConfig(id, patch) {
497
497
  onChange(value.map((f) => f.id === id ? { ...f, ...patch } : f));
498
498
  }
499
+ function openConfig(id, e) {
500
+ const r = e.currentTarget.getBoundingClientRect();
501
+ setConfigPos({ x: r.left, y: r.bottom + 6 });
502
+ setConfigId(id);
503
+ }
499
504
  const configField = value.find((f) => f.id === configId && f.type === "date") ?? null;
500
505
  const handle = (id, geom, c) => {
501
506
  const cx = c[1] === "w" ? geom.x : geom.x + geom.w;
@@ -584,6 +589,7 @@ function FieldDesigner({
584
589
  {
585
590
  ref: stageRef,
586
591
  onPointerDown: (e) => {
592
+ setSelectedId(null);
587
593
  if (drawMode || e.pointerType === "mouse") setDrag({ mode: "new", start: rel(e) });
588
594
  },
589
595
  onPointerMove,
@@ -691,7 +697,7 @@ function FieldDesigner({
691
697
  onPointerDown: (e) => e.stopPropagation(),
692
698
  onClick: (e) => {
693
699
  e.stopPropagation();
694
- setConfigId(f.id);
700
+ openConfig(f.id, e);
695
701
  },
696
702
  style: {
697
703
  position: "absolute",
@@ -737,172 +743,163 @@ function FieldDesigner({
737
743
  ]
738
744
  }
739
745
  ),
740
- configField ? /* @__PURE__ */ jsxRuntime.jsxs(
741
- "div",
742
- {
743
- style: {
744
- marginTop: 10,
745
- border: `1px solid ${primaryColor}66`,
746
- borderRadius: 8,
747
- padding: 12,
748
- background: "#fff",
749
- fontSize: 13,
750
- color: "#374151"
751
- },
752
- children: [
753
- /* @__PURE__ */ jsxRuntime.jsxs(
754
- "div",
755
- {
756
- style: {
757
- display: "flex",
758
- alignItems: "center",
759
- justifyContent: "space-between",
760
- marginBottom: 8
761
- },
762
- children: [
763
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { children: [
764
- "\u{1F4C5} ",
765
- configField.label || "Date"
766
- ] }),
767
- /* @__PURE__ */ jsxRuntime.jsx(
768
- "button",
769
- {
770
- type: "button",
771
- onClick: () => setConfigId(null),
772
- style: {
773
- fontSize: 12,
774
- padding: "3px 10px",
775
- borderRadius: 6,
776
- border: `1px solid ${primaryColor}`,
777
- background: primaryColor,
778
- color: "#fff",
779
- cursor: "pointer"
780
- },
781
- children: "Done"
782
- }
783
- )
784
- ]
785
- }
786
- ),
787
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: 10 }, children: [
788
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, fontWeight: 600, marginBottom: 4 }, children: "Display format" }),
789
- /* @__PURE__ */ jsxRuntime.jsx(
746
+ configField && configPos ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
747
+ /* @__PURE__ */ jsxRuntime.jsx(
748
+ "div",
749
+ {
750
+ onClick: () => setConfigId(null),
751
+ style: { position: "fixed", inset: 0, zIndex: 50 }
752
+ }
753
+ ),
754
+ /* @__PURE__ */ jsxRuntime.jsxs(
755
+ "div",
756
+ {
757
+ style: {
758
+ position: "fixed",
759
+ left: Math.min(
760
+ configPos.x,
761
+ (typeof window !== "undefined" ? window.innerWidth : 1024) - 312
762
+ ),
763
+ top: configPos.y,
764
+ width: 300,
765
+ zIndex: 51,
766
+ border: "1px solid #e5e7eb",
767
+ borderRadius: 10,
768
+ padding: 12,
769
+ background: "#fff",
770
+ fontSize: 13,
771
+ color: "#374151",
772
+ boxShadow: "0 10px 30px rgba(0,0,0,0.18)"
773
+ },
774
+ children: [
775
+ /* @__PURE__ */ jsxRuntime.jsxs(
790
776
  "div",
791
777
  {
792
778
  style: {
793
779
  display: "flex",
794
- flexDirection: "column",
795
- border: "1px solid #e5e7eb",
796
- borderRadius: 8,
797
- overflow: "hidden"
780
+ alignItems: "center",
781
+ justifyContent: "space-between",
782
+ marginBottom: 8
798
783
  },
799
- children: DATE_FORMATS.map((fmt) => {
800
- const active = (configField.dateFormat ?? DEFAULT_DATE_FORMAT) === fmt;
801
- return /* @__PURE__ */ jsxRuntime.jsxs(
784
+ children: [
785
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { children: [
786
+ "\u{1F4C5} ",
787
+ configField.label || "Date"
788
+ ] }),
789
+ /* @__PURE__ */ jsxRuntime.jsx(
802
790
  "button",
803
791
  {
804
792
  type: "button",
805
- onClick: () => setConfig(configField.id, { dateFormat: fmt }),
793
+ onClick: () => setConfigId(null),
806
794
  style: {
807
- display: "flex",
808
- alignItems: "center",
809
- justifyContent: "space-between",
810
- padding: "7px 10px",
811
- border: "none",
812
- borderTop: "1px solid #f3f4f6",
813
- textAlign: "left",
814
- background: active ? `${primaryColor}14` : "#fff",
815
- color: active ? primaryColor : "#374151",
816
- fontWeight: active ? 600 : 400,
817
- fontSize: 13,
795
+ fontSize: 12,
796
+ padding: "3px 10px",
797
+ borderRadius: 6,
798
+ border: `1px solid ${primaryColor}`,
799
+ background: primaryColor,
800
+ color: "#fff",
818
801
  cursor: "pointer"
819
802
  },
820
- children: [
821
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: DATE_FORMAT_LABELS[fmt] }),
822
- active ? /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u2713" }) : null
823
- ]
824
- },
825
- fmt
826
- );
827
- })
803
+ children: "Done"
804
+ }
805
+ )
806
+ ]
828
807
  }
829
- )
830
- ] }),
831
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
832
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, fontWeight: 600, marginBottom: 4 }, children: "Earliest date" }),
833
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
834
- /* @__PURE__ */ jsxRuntime.jsxs(
835
- "div",
836
- {
837
- style: {
838
- display: "inline-flex",
839
- alignItems: "center",
840
- border: "1px solid #d1d5db",
841
- borderRadius: 6,
842
- background: "#fff"
843
- },
844
- children: [
845
- /* @__PURE__ */ jsxRuntime.jsx(
846
- "input",
847
- {
848
- ref: minDateRef,
849
- type: "date",
850
- value: configField.minDate ?? "",
851
- onChange: (e) => setConfig(configField.id, { minDate: e.target.value || null }),
852
- style: {
853
- border: "none",
854
- outline: "none",
855
- background: "transparent",
856
- padding: "5px 8px",
857
- fontSize: 13,
858
- appearance: "none",
859
- WebkitAppearance: "none"
860
- }
861
- }
862
- ),
863
- /* @__PURE__ */ jsxRuntime.jsx(
864
- "button",
865
- {
866
- type: "button",
867
- "aria-label": "Open calendar",
868
- onClick: () => minDateRef.current?.showPicker?.(),
869
- style: {
870
- border: "none",
871
- background: "transparent",
872
- cursor: "pointer",
873
- fontSize: 14,
874
- lineHeight: 1,
875
- padding: "4px 8px 4px 2px"
876
- },
877
- children: "\u{1F4C5}"
878
- }
879
- )
880
- ]
881
- }
882
- ),
883
- configField.minDate ? /* @__PURE__ */ jsxRuntime.jsx(
884
- "button",
808
+ ),
809
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: 10 }, children: [
810
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, fontWeight: 600, marginBottom: 4 }, children: "Display format" }),
811
+ /* @__PURE__ */ jsxRuntime.jsx(
812
+ "select",
885
813
  {
886
- type: "button",
887
- onClick: () => setConfig(configField.id, { minDate: null }),
814
+ value: configField.dateFormat ?? DEFAULT_DATE_FORMAT,
815
+ onChange: (e) => setConfig(configField.id, { dateFormat: e.target.value }),
888
816
  style: {
889
- padding: "5px 8px",
817
+ width: "100%",
818
+ padding: "6px 8px",
890
819
  borderRadius: 6,
891
820
  border: "1px solid #d1d5db",
892
- background: "#fff",
893
- color: "#6b7280",
894
- cursor: "pointer",
895
- fontSize: 12
821
+ fontSize: 13
896
822
  },
897
- children: "Clear"
823
+ children: DATE_FORMATS.map((fmt) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: fmt, children: DATE_FORMAT_LABELS[fmt] }, fmt))
898
824
  }
899
- ) : null
825
+ )
900
826
  ] }),
901
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#9ca3af", fontSize: 11 }, children: "Leave blank to use the document's creation date." })
902
- ] })
903
- ]
904
- }
905
- ) : null
827
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
828
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, fontWeight: 600, marginBottom: 4 }, children: "Earliest date" }),
829
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
830
+ /* @__PURE__ */ jsxRuntime.jsxs(
831
+ "div",
832
+ {
833
+ style: {
834
+ display: "inline-flex",
835
+ alignItems: "center",
836
+ border: "1px solid #d1d5db",
837
+ borderRadius: 6,
838
+ background: "#fff"
839
+ },
840
+ children: [
841
+ /* @__PURE__ */ jsxRuntime.jsx(
842
+ "input",
843
+ {
844
+ ref: minDateRef,
845
+ type: "date",
846
+ value: configField.minDate ?? "",
847
+ onChange: (e) => setConfig(configField.id, { minDate: e.target.value || null }),
848
+ style: {
849
+ border: "none",
850
+ outline: "none",
851
+ background: "transparent",
852
+ padding: "5px 8px",
853
+ fontSize: 13,
854
+ appearance: "none",
855
+ WebkitAppearance: "none"
856
+ }
857
+ }
858
+ ),
859
+ /* @__PURE__ */ jsxRuntime.jsx(
860
+ "button",
861
+ {
862
+ type: "button",
863
+ "aria-label": "Open calendar",
864
+ onClick: () => minDateRef.current?.showPicker?.(),
865
+ style: {
866
+ border: "none",
867
+ background: "transparent",
868
+ cursor: "pointer",
869
+ fontSize: 14,
870
+ lineHeight: 1,
871
+ padding: "4px 8px 4px 2px"
872
+ },
873
+ children: "\u{1F4C5}"
874
+ }
875
+ )
876
+ ]
877
+ }
878
+ ),
879
+ configField.minDate ? /* @__PURE__ */ jsxRuntime.jsx(
880
+ "button",
881
+ {
882
+ type: "button",
883
+ onClick: () => setConfig(configField.id, { minDate: null }),
884
+ style: {
885
+ padding: "5px 8px",
886
+ borderRadius: 6,
887
+ border: "1px solid #d1d5db",
888
+ background: "#fff",
889
+ color: "#6b7280",
890
+ cursor: "pointer",
891
+ fontSize: 12
892
+ },
893
+ children: "Clear"
894
+ }
895
+ ) : null
896
+ ] }),
897
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#9ca3af", fontSize: 11 }, children: "Leave blank to use the document's creation date." })
898
+ ] })
899
+ ]
900
+ }
901
+ )
902
+ ] }) : null
906
903
  ] }),
907
904
  hideFieldList ? null : /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: "1 1 200px", minWidth: 180, maxWidth: 300 }, children: [
908
905
  /* @__PURE__ */ jsxRuntime.jsxs("p", { style: { fontSize: 13, fontWeight: 600, color: "#374151", margin: "0 0 8px" }, children: [
@@ -957,7 +954,7 @@ function FieldDesigner({
957
954
  "aria-label": `Configure ${f.label}`,
958
955
  onClick: (e) => {
959
956
  e.stopPropagation();
960
- setConfigId(f.id);
957
+ openConfig(f.id, e);
961
958
  },
962
959
  style: {
963
960
  border: "none",