@pdfme/ui 6.1.8 → 6.1.9-dev.1

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.
@@ -6,7 +6,9 @@ type RendererProps = Omit<UIRenderProps<Schema>, 'schema' | 'rootElement' | 'opt
6
6
  value: string;
7
7
  outline: string;
8
8
  onChangeHoveringSchemaId?: (id: string | null) => void;
9
+ onChangeActiveSchemaId?: (id: string | null) => void;
9
10
  scale: number;
11
+ isActive?: boolean;
10
12
  selectable?: boolean;
11
13
  };
12
14
  declare const Renderer: (props: RendererProps) => React.JSX.Element;
package/dist/index.js CHANGED
@@ -44411,7 +44411,7 @@ pp$3.currentThisScope = function() {
44411
44411
  if (scope.flags & (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK) && !(scope.flags & SCOPE_ARROW)) return scope;
44412
44412
  }
44413
44413
  };
44414
- var Node = function Node(parser, pos, loc) {
44414
+ var Node$1 = function Node(parser, pos, loc) {
44415
44415
  this.type = "";
44416
44416
  this.start = pos;
44417
44417
  this.end = 0;
@@ -44421,10 +44421,10 @@ var Node = function Node(parser, pos, loc) {
44421
44421
  };
44422
44422
  var pp$2 = Parser.prototype;
44423
44423
  pp$2.startNode = function() {
44424
- return new Node(this, this.start, this.startLoc);
44424
+ return new Node$1(this, this.start, this.startLoc);
44425
44425
  };
44426
44426
  pp$2.startNodeAt = function(pos, loc) {
44427
- return new Node(this, pos, loc);
44427
+ return new Node$1(this, pos, loc);
44428
44428
  };
44429
44429
  function finishNodeAt(node, type, pos, loc) {
44430
44430
  node.type = type;
@@ -44440,7 +44440,7 @@ pp$2.finishNodeAt = function(node, type, pos, loc) {
44440
44440
  return finishNodeAt.call(this, node, type, pos, loc);
44441
44441
  };
44442
44442
  pp$2.copyNode = function(node) {
44443
- var newNode = new Node(this, node.start, this.startLoc);
44443
+ var newNode = new Node$1(this, node.start, this.startLoc);
44444
44444
  for (var prop in node) newNode[prop] = node[prop];
44445
44445
  return newNode;
44446
44446
  };
@@ -46006,7 +46006,7 @@ Parser.acorn = {
46006
46006
  Position,
46007
46007
  SourceLocation,
46008
46008
  getLineInfo,
46009
- Node,
46009
+ Node: Node$1,
46010
46010
  TokenType,
46011
46011
  tokTypes: types$1,
46012
46012
  keywordTypes: keywords,
@@ -46025,7 +46025,7 @@ function parseExpressionAt(input, pos, options) {
46025
46025
  }
46026
46026
  //#endregion
46027
46027
  //#region ../common/dist/index.js
46028
- var PDFME_VERSION = "6.1.8";
46028
+ var PDFME_VERSION = "6.1.9";
46029
46029
  var PAGE_SIZE_PRESETS = {
46030
46030
  A3: {
46031
46031
  width: 297,
@@ -190243,35 +190243,51 @@ var useRenderKey = (arg) => {
190243
190243
  plugin
190244
190244
  ]);
190245
190245
  };
190246
- var Wrapper = ({ children, outline, onChangeHoveringSchemaId, schema, selectable = true }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
190247
- title: schema.name,
190248
- onMouseEnter: () => onChangeHoveringSchemaId && onChangeHoveringSchemaId(schema.id),
190249
- onMouseLeave: () => onChangeHoveringSchemaId && onChangeHoveringSchemaId(null),
190250
- className: selectable ? SELECTABLE_CLASSNAME : "",
190251
- id: schema.id,
190252
- style: {
190253
- position: "absolute",
190254
- cursor: schema.readOnly ? "initial" : "pointer",
190255
- height: schema.height * ZOOM,
190256
- width: schema.width * ZOOM,
190257
- top: schema.position.y * ZOOM,
190258
- left: schema.position.x * ZOOM,
190259
- transform: `rotate(${schema.rotate ?? 0}deg)`,
190260
- opacity: schema.opacity ?? 1,
190261
- outline
190262
- },
190263
- children: [schema.required && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
190246
+ var Wrapper = ({ children, outline, onChangeHoveringSchemaId, onChangeActiveSchemaId, schema, mode, isActive = false, selectable = true }) => {
190247
+ const { token } = theme_default.useToken();
190248
+ const isFormEditable = mode === "form" && !schema.readOnly;
190249
+ const activateSchema = () => {
190250
+ if (isFormEditable) onChangeActiveSchemaId?.(schema.id);
190251
+ };
190252
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
190253
+ title: schema.name,
190254
+ onMouseEnter: () => onChangeHoveringSchemaId && onChangeHoveringSchemaId(schema.id),
190255
+ onMouseLeave: () => onChangeHoveringSchemaId && onChangeHoveringSchemaId(null),
190256
+ onPointerDownCapture: activateSchema,
190257
+ onClickCapture: activateSchema,
190258
+ onFocusCapture: activateSchema,
190259
+ onBlurCapture: (event) => {
190260
+ const nextTarget = event.relatedTarget;
190261
+ if (!(nextTarget instanceof Node) || !event.currentTarget.contains(nextTarget)) onChangeActiveSchemaId?.(null);
190262
+ },
190263
+ className: selectable ? SELECTABLE_CLASSNAME : "",
190264
+ id: schema.id,
190264
190265
  style: {
190265
- color: "red",
190266
190266
  position: "absolute",
190267
- top: -12,
190268
- left: -12,
190269
- fontSize: 18,
190270
- fontWeight: 700
190271
- },
190272
- children: "*"
190273
- }), children]
190274
- });
190267
+ cursor: schema.readOnly ? "initial" : "pointer",
190268
+ height: schema.height * ZOOM,
190269
+ width: schema.width * ZOOM,
190270
+ top: schema.position.y * ZOOM,
190271
+ left: schema.position.x * ZOOM,
190272
+ transform: `rotate(${schema.rotate ?? 0}deg)`,
190273
+ opacity: schema.opacity ?? 1,
190274
+ outline,
190275
+ boxShadow: isActive ? `0 0 0 2px ${token.colorPrimary}, 0 0 0 4px ${token.colorPrimaryBg}` : void 0,
190276
+ zIndex: isActive ? 1 : void 0
190277
+ },
190278
+ children: [schema.required && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
190279
+ style: {
190280
+ color: "red",
190281
+ position: "absolute",
190282
+ top: -12,
190283
+ left: -12,
190284
+ fontSize: 18,
190285
+ fontWeight: 700
190286
+ },
190287
+ children: "*"
190288
+ }), children]
190289
+ });
190290
+ };
190275
190291
  var Renderer = (props) => {
190276
190292
  const { schema, basePdf, value, mode, onChange, stopEditing, tabIndex, placeholder, scale } = props;
190277
190293
  const pluginsRegistry = (0, import_react$9.useContext)(PluginsRegistry);
@@ -211005,6 +211021,14 @@ var ErrorScreen = ({ size, error }) => {
211005
211021
  //#endregion
211006
211022
  //#region src/components/CtlBar.tsx
211007
211023
  var { Text: Text$1 } = Typography;
211024
+ var CONTROL_BUTTON_SIZE = 32;
211025
+ var getControlButtonStyle = (active) => ({
211026
+ width: CONTROL_BUTTON_SIZE,
211027
+ minWidth: CONTROL_BUTTON_SIZE,
211028
+ height: CONTROL_BUTTON_SIZE,
211029
+ padding: 0,
211030
+ ...active ? { backgroundColor: "rgba(255, 255, 255, 0.18)" } : {}
211031
+ });
211008
211032
  var ToolbarButton = ({ className, label, disabled, active, onClick, children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tooltip$2, {
211009
211033
  title: label,
211010
211034
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(button_default$1, {
@@ -211014,7 +211038,7 @@ var ToolbarButton = ({ className, label, disabled, active, onClick, children })
211014
211038
  title: label,
211015
211039
  disabled,
211016
211040
  onClick,
211017
- style: active ? { backgroundColor: "rgba(255, 255, 255, 0.18)" } : void 0,
211041
+ style: getControlButtonStyle(active),
211018
211042
  children
211019
211043
  })
211020
211044
  });
@@ -211037,7 +211061,10 @@ var Zoom = ({ zoomLevel, setZoomLevel, zoomMode, fitWidth, fitHeight, style, lab
211037
211061
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
211038
211062
  style: {
211039
211063
  display: "flex",
211040
- alignItems: "center"
211064
+ alignItems: "center",
211065
+ justifyContent: "center",
211066
+ flexWrap: "wrap",
211067
+ rowGap: 0
211041
211068
  },
211042
211069
  children: [
211043
211070
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolbarButton, {
@@ -211049,7 +211076,12 @@ var Zoom = ({ zoomLevel, setZoomLevel, zoomMode, fitWidth, fitHeight, style, lab
211049
211076
  }),
211050
211077
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text$1, {
211051
211078
  strong: true,
211052
- style: style.textStyle,
211079
+ style: {
211080
+ ...style.textStyle,
211081
+ minWidth: 44,
211082
+ textAlign: "center",
211083
+ whiteSpace: "nowrap"
211084
+ },
211053
211085
  children: [Math.round(zoomLevel * 100), "%"]
211054
211086
  }),
211055
211087
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolbarButton, {
@@ -211089,6 +211121,7 @@ var Pager = ({ pageCursor, pageNum, setPageCursor, style }) => {
211089
211121
  type: "text",
211090
211122
  disabled: pageCursor <= 0,
211091
211123
  onClick: () => setPageCursor(pageCursor - 1),
211124
+ style: getControlButtonStyle(),
211092
211125
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronLeft, {
211093
211126
  size: 16,
211094
211127
  color: style.textStyle.color
@@ -211096,7 +211129,12 @@ var Pager = ({ pageCursor, pageNum, setPageCursor, style }) => {
211096
211129
  }),
211097
211130
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text$1, {
211098
211131
  strong: true,
211099
- style: style.textStyle,
211132
+ style: {
211133
+ ...style.textStyle,
211134
+ minWidth: 36,
211135
+ textAlign: "center",
211136
+ whiteSpace: "nowrap"
211137
+ },
211100
211138
  children: [
211101
211139
  pageCursor + 1,
211102
211140
  "/",
@@ -211108,6 +211146,7 @@ var Pager = ({ pageCursor, pageNum, setPageCursor, style }) => {
211108
211146
  type: "text",
211109
211147
  disabled: pageCursor + 1 >= pageNum,
211110
211148
  onClick: () => setPageCursor(pageCursor + 1),
211149
+ style: getControlButtonStyle(),
211111
211150
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, {
211112
211151
  size: 16,
211113
211152
  color: style.textStyle.color
@@ -211124,6 +211163,7 @@ var ContextMenu = ({ items, style }) => /* @__PURE__ */ (0, import_jsx_runtime.j
211124
211163
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(button_default$1, {
211125
211164
  className: UI_CLASSNAME + "context-menu",
211126
211165
  type: "text",
211166
+ style: getControlButtonStyle(),
211127
211167
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ellipsis, {
211128
211168
  size: 16,
211129
211169
  color: style.textStyle.color
@@ -211162,6 +211202,8 @@ var CtlBar = (props) => {
211162
211202
  width: size.width,
211163
211203
  display: "flex",
211164
211204
  justifyContent: "center",
211205
+ boxSizing: "border-box",
211206
+ padding: `0 ${token.paddingXS}px`,
211165
211207
  pointerEvents: "none"
211166
211208
  },
211167
211209
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
@@ -211172,10 +211214,13 @@ var CtlBar = (props) => {
211172
211214
  justifyContent: "center",
211173
211215
  position: "relative",
211174
211216
  zIndex: 1,
211175
- height: 40,
211217
+ minHeight: 40,
211218
+ maxWidth: "100%",
211176
211219
  boxSizing: "border-box",
211177
- padding: token.paddingSM,
211178
- gap: token.marginXS,
211220
+ padding: `${token.paddingXXS}px ${token.paddingSM}px`,
211221
+ columnGap: token.marginXS,
211222
+ rowGap: token.marginXXS,
211223
+ flexWrap: "wrap",
211179
211224
  borderRadius: token.borderRadius,
211180
211225
  backgroundColor: token.colorBgMask,
211181
211226
  pointerEvents: "auto"
@@ -211183,6 +211228,7 @@ var CtlBar = (props) => {
211183
211228
  children: [
211184
211229
  pageNum > 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
211185
211230
  className: "pdfme-ui-pager",
211231
+ style: { flexShrink: 0 },
211186
211232
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pager, {
211187
211233
  style: { textStyle },
211188
211234
  pageCursor,
@@ -211192,6 +211238,7 @@ var CtlBar = (props) => {
211192
211238
  }),
211193
211239
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
211194
211240
  className: UI_CLASSNAME + "zoom",
211241
+ style: { minWidth: 0 },
211195
211242
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Zoom, {
211196
211243
  style: { textStyle },
211197
211244
  zoomLevel,
@@ -212003,6 +212050,7 @@ var Preview = ({ template, inputs, size, onChangeInput, onPageChange }) => {
212003
212050
  const paperRefs = (0, import_react$9.useRef)([]);
212004
212051
  const [unitCursor, setUnitCursor] = (0, import_react$9.useState)(0);
212005
212052
  const [pageCursor, setPageCursor] = (0, import_react$9.useState)(0);
212053
+ const [activeSchemaId, setActiveSchemaId] = (0, import_react$9.useState)(null);
212006
212054
  const [schemasList, setSchemasList] = (0, import_react$9.useState)([[]]);
212007
212055
  const { backgrounds, pageSizes, baseScale, error, refresh } = useUIPreProcessor({
212008
212056
  template,
@@ -212076,6 +212124,9 @@ var Preview = ({ template, inputs, size, onChangeInput, onPageChange }) => {
212076
212124
  template,
212077
212125
  unitCursor
212078
212126
  ]);
212127
+ (0, import_react$9.useEffect)(() => {
212128
+ setActiveSchemaId(null);
212129
+ }, [unitCursor]);
212079
212130
  useScrollPageCursor({
212080
212131
  ref: containerRef,
212081
212132
  paperRefs,
@@ -212172,6 +212223,11 @@ var Preview = ({ template, inputs, size, onChangeInput, onPageChange }) => {
212172
212223
  }),
212173
212224
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
212174
212225
  ref: containerRef,
212226
+ onPointerDown: (event) => {
212227
+ if (!isForm) return;
212228
+ const target = event.target;
212229
+ if (!(target instanceof Element) || !target.closest(`.selectable`)) setActiveSchemaId(null);
212230
+ },
212175
212231
  style: {
212176
212232
  ...size,
212177
212233
  position: "relative",
@@ -212206,7 +212262,9 @@ var Preview = ({ template, inputs, size, onChangeInput, onPageChange }) => {
212206
212262
  handleOnChangeRenderer(Array.isArray(arg) ? arg : [arg], schema);
212207
212263
  },
212208
212264
  outline: isForm && !schema.readOnly ? `1px dashed ${token.colorPrimary}` : "transparent",
212209
- scale: renderScale
212265
+ scale: renderScale,
212266
+ isActive: isForm && activeSchemaId === schema.id,
212267
+ onChangeActiveSchemaId: isForm ? setActiveSchemaId : void 0
212210
212268
  }, schema.id);
212211
212269
  },
212212
212270
  renderPaper: ({ index }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StaticSchema, {