@pdfme/ui 6.1.13-dev.13 → 6.1.13-dev.22

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.js CHANGED
@@ -46125,6 +46125,21 @@ var evaluatePlaceholders = (arg) => {
46125
46125
  }
46126
46126
  return resultContent;
46127
46127
  };
46128
+ /**
46129
+ * Resolve a read-only schema's render value.
46130
+ * Text `content` is an expression template. MVT `content` is a variable JSON
46131
+ * map and must not go through {@link replacePlaceholders}. Other types (table,
46132
+ * image, …) keep the previous generate/UI behavior of evaluating expressions.
46133
+ */
46134
+ var resolveReadOnlyContent = (arg) => {
46135
+ const content = arg.schema.content || "";
46136
+ if (arg.schema.type === "multiVariableText") return content;
46137
+ return replacePlaceholders({
46138
+ content,
46139
+ variables: arg.variables,
46140
+ schemas: arg.schemas
46141
+ });
46142
+ };
46128
46143
  var replacePlaceholders = (arg) => {
46129
46144
  const { content, variables, schemas } = arg;
46130
46145
  if (!content || typeof content !== "string" || !content.includes("{") || !content.includes("}")) return content;
@@ -46152,10 +46167,23 @@ var replacePlaceholders = (arg) => {
46152
46167
  var EPSILON = .01;
46153
46168
  /** Calculate the content height of a page (drawable area excluding padding) */
46154
46169
  var getContentHeight = (basePdf) => basePdf.height - basePdf.padding[0] - basePdf.padding[2];
46170
+ /**
46171
+ * Resolve a readOnly table body.
46172
+ * Uses input[schema.name] when present (array or JSON string) and never runs
46173
+ * replacePlaceholders. Falls back to schema.content (Designer sample).
46174
+ */
46175
+ var getReadOnlyTableValue = (schema, input) => {
46176
+ if (input && Object.prototype.hasOwnProperty.call(input, schema.name)) {
46177
+ const value = input[schema.name];
46178
+ if (value !== void 0 && value !== null) return typeof value === "string" ? value : JSON.stringify(value);
46179
+ }
46180
+ return schema.content || "";
46181
+ };
46155
46182
  /** Get the input value for a schema */
46156
46183
  var getSchemaValue = (schema, input, schemas) => {
46157
46184
  if (!schema.readOnly) return input?.[schema.name] || "";
46158
- if (schema.type !== "text" && schema.type !== "multiVariableText") return schema.content || "";
46185
+ if (schema.type === "table") return getReadOnlyTableValue(schema, input);
46186
+ if (schema.type !== "text") return schema.content || "";
46159
46187
  return replacePlaceholders({
46160
46188
  content: schema.content || "",
46161
46189
  variables: input,
@@ -204746,7 +204774,16 @@ var useForm = function useForm() {
204746
204774
  //#region ../../node_modules/form-render/es/index.js
204747
204775
  var es_default = withProvider(FormCore, widgets_exports);
204748
204776
  //#endregion
204749
- //#region ../schemas/dist/helper-VroN19Ci.js
204777
+ //#region ../schemas/dist/helper-4iOJns1p.js
204778
+ var tryParseVariableMap = (variablesIn) => {
204779
+ if (!variablesIn) return;
204780
+ if (typeof variablesIn === "object" && !Array.isArray(variablesIn)) return variablesIn;
204781
+ if (typeof variablesIn !== "string") return;
204782
+ try {
204783
+ const parsed = JSON.parse(variablesIn);
204784
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
204785
+ } catch {}
204786
+ };
204750
204787
  var substituteVariables = (text, variablesIn, valueMapper = (value) => value) => {
204751
204788
  if (!text) return "";
204752
204789
  let substitutedText = text;
@@ -204767,6 +204804,20 @@ var substituteVariables = (text, variablesIn, valueMapper = (value) => value) =>
204767
204804
  return substitutedText;
204768
204805
  };
204769
204806
  var substituteVariablesAsInlineMarkdownLiterals = (text, variablesIn) => substituteVariables(text, variablesIn, escapeInlineMarkdown);
204807
+ /**
204808
+ * Resolve a read-only MVT field to display text.
204809
+ * jsx locked fields set `contentSnapshot` and store already-substituted text
204810
+ * in `content`. Designer templates omit that flag and store variable JSON.
204811
+ * Never treat `content` as an expression, and never infer a snapshot from keys.
204812
+ */
204813
+ var resolveReadOnlyMultiVariableText = (schema, value) => {
204814
+ if (schema.contentSnapshot) return schema.content ?? value ?? schema.text ?? "";
204815
+ if (!schema.variables?.length) return schema.text || "";
204816
+ const variableMap = tryParseVariableMap(schema.content) ?? tryParseVariableMap(value);
204817
+ if (variableMap) return isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(schema.text || "", variableMap) : substituteVariables(schema.text || "", variableMap);
204818
+ if (typeof value === "string" && value.length > 0) return value;
204819
+ return schema.content || schema.text || "";
204820
+ };
204770
204821
  var validateVariables = (value, schema) => {
204771
204822
  if (schema.variables.length === 0) return true;
204772
204823
  let values;
@@ -204782,13 +204833,14 @@ var validateVariables = (value, schema) => {
204782
204833
  return true;
204783
204834
  };
204784
204835
  //#endregion
204785
- //#region ../schemas/dist/dynamicTemplate-DFk_de1Y.js
204836
+ //#region ../schemas/dist/dynamicTemplate-CCCmLMvQ.js
204786
204837
  var getDynamicLayoutForMultiVariableText = async (value, args) => {
204787
204838
  if (args.schema.type !== "multiVariableText") return { heights: [args.schema.height] };
204788
204839
  const schema = args.schema;
204789
204840
  if (schema.overflow !== "expand") return { heights: [schema.height] };
204790
- let renderValue = schema.readOnly && schema.variables.length === 0 ? schema.text || "" : value;
204791
- if (!schema.readOnly) {
204841
+ let renderValue;
204842
+ if (schema.readOnly) renderValue = resolveReadOnlyMultiVariableText(schema, value);
204843
+ else {
204792
204844
  if (!validateVariables(value, schema)) return { heights: [schema.height] };
204793
204845
  renderValue = isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(schema.text || "", value) : substituteVariables(schema.text || "", value);
204794
204846
  }
@@ -225859,8 +225911,8 @@ var StaticSchema = (props) => {
225859
225911
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: schemasForUI.map((schema) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Renderer, {
225860
225912
  schema,
225861
225913
  basePdf,
225862
- value: schema.readOnly ? replacePlaceholders({
225863
- content: schema.content || "",
225914
+ value: schema.readOnly && schema.type === "table" ? getReadOnlyTableValue(schema, input) : schema.readOnly ? resolveReadOnlyContent({
225915
+ schema,
225864
225916
  variables: {
225865
225917
  ...input,
225866
225918
  totalPages,
@@ -226233,10 +226285,9 @@ var Canvas = (props, ref) => {
226233
226285
  ] }),
226234
226286
  renderSchema: ({ schema, index }) => {
226235
226287
  const mode = editing && activeElements.map((ae) => ae.id).includes(schema.id) ? "designer" : "viewer";
226236
- const content = schema.content || "";
226237
- let value = content;
226238
- if (mode !== "designer" && schema.readOnly) value = replacePlaceholders({
226239
- content,
226288
+ let value = schema.content || "";
226289
+ if (mode !== "designer" && schema.readOnly && schema.type !== "table") value = resolveReadOnlyContent({
226290
+ schema,
226240
226291
  variables: {
226241
226292
  ...schemasList.flat().reduce((acc, currSchema) => {
226242
226293
  acc[currSchema.name] = currSchema.content || "";
@@ -227664,8 +227715,8 @@ var Preview = ({ template, inputs, size, onChangeInput, onPageChange }) => {
227664
227715
  backgrounds,
227665
227716
  renderSchema: ({ schema, index }) => {
227666
227717
  const hasInputValue = Boolean(input && Object.prototype.hasOwnProperty.call(input, schema.name));
227667
- const value = schema.readOnly ? replacePlaceholders({
227668
- content: schema.content || "",
227718
+ const value = schema.readOnly && schema.type === "table" ? getReadOnlyTableValue(schema, input) : schema.readOnly ? resolveReadOnlyContent({
227719
+ schema,
227669
227720
  variables: {
227670
227721
  ...input,
227671
227722
  totalPages: schemasList.length,