@pdfme/ui 6.1.13-dev.17 → 6.1.13-dev.23

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;
@@ -46168,7 +46183,7 @@ var getReadOnlyTableValue = (schema, input) => {
46168
46183
  var getSchemaValue = (schema, input, schemas) => {
46169
46184
  if (!schema.readOnly) return input?.[schema.name] || "";
46170
46185
  if (schema.type === "table") return getReadOnlyTableValue(schema, input);
46171
- if (schema.type !== "text" && schema.type !== "multiVariableText") return schema.content || "";
46186
+ if (schema.type !== "text") return schema.content || "";
46172
46187
  return replacePlaceholders({
46173
46188
  content: schema.content || "",
46174
46189
  variables: input,
@@ -204759,7 +204774,16 @@ var useForm = function useForm() {
204759
204774
  //#region ../../node_modules/form-render/es/index.js
204760
204775
  var es_default = withProvider(FormCore, widgets_exports);
204761
204776
  //#endregion
204762
- //#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
+ };
204763
204787
  var substituteVariables = (text, variablesIn, valueMapper = (value) => value) => {
204764
204788
  if (!text) return "";
204765
204789
  let substitutedText = text;
@@ -204780,6 +204804,20 @@ var substituteVariables = (text, variablesIn, valueMapper = (value) => value) =>
204780
204804
  return substitutedText;
204781
204805
  };
204782
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
+ };
204783
204821
  var validateVariables = (value, schema) => {
204784
204822
  if (schema.variables.length === 0) return true;
204785
204823
  let values;
@@ -204795,13 +204833,14 @@ var validateVariables = (value, schema) => {
204795
204833
  return true;
204796
204834
  };
204797
204835
  //#endregion
204798
- //#region ../schemas/dist/dynamicTemplate-DFk_de1Y.js
204836
+ //#region ../schemas/dist/dynamicTemplate-CCCmLMvQ.js
204799
204837
  var getDynamicLayoutForMultiVariableText = async (value, args) => {
204800
204838
  if (args.schema.type !== "multiVariableText") return { heights: [args.schema.height] };
204801
204839
  const schema = args.schema;
204802
204840
  if (schema.overflow !== "expand") return { heights: [schema.height] };
204803
- let renderValue = schema.readOnly && schema.variables.length === 0 ? schema.text || "" : value;
204804
- if (!schema.readOnly) {
204841
+ let renderValue;
204842
+ if (schema.readOnly) renderValue = resolveReadOnlyMultiVariableText(schema, value);
204843
+ else {
204805
204844
  if (!validateVariables(value, schema)) return { heights: [schema.height] };
204806
204845
  renderValue = isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(schema.text || "", value) : substituteVariables(schema.text || "", value);
204807
204846
  }
@@ -225872,8 +225911,8 @@ var StaticSchema = (props) => {
225872
225911
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: schemasForUI.map((schema) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Renderer, {
225873
225912
  schema,
225874
225913
  basePdf,
225875
- value: schema.readOnly && schema.type === "table" ? getReadOnlyTableValue(schema, input) : schema.readOnly ? replacePlaceholders({
225876
- content: schema.content || "",
225914
+ value: schema.readOnly && schema.type === "table" ? getReadOnlyTableValue(schema, input) : schema.readOnly ? resolveReadOnlyContent({
225915
+ schema,
225877
225916
  variables: {
225878
225917
  ...input,
225879
225918
  totalPages,
@@ -226246,10 +226285,9 @@ var Canvas = (props, ref) => {
226246
226285
  ] }),
226247
226286
  renderSchema: ({ schema, index }) => {
226248
226287
  const mode = editing && activeElements.map((ae) => ae.id).includes(schema.id) ? "designer" : "viewer";
226249
- const content = schema.content || "";
226250
- let value = content;
226251
- if (mode !== "designer" && schema.readOnly && schema.type !== "table") value = replacePlaceholders({
226252
- content,
226288
+ let value = schema.content || "";
226289
+ if (mode !== "designer" && schema.readOnly && schema.type !== "table") value = resolveReadOnlyContent({
226290
+ schema,
226253
226291
  variables: {
226254
226292
  ...schemasList.flat().reduce((acc, currSchema) => {
226255
226293
  acc[currSchema.name] = currSchema.content || "";
@@ -227677,8 +227715,8 @@ var Preview = ({ template, inputs, size, onChangeInput, onPageChange }) => {
227677
227715
  backgrounds,
227678
227716
  renderSchema: ({ schema, index }) => {
227679
227717
  const hasInputValue = Boolean(input && Object.prototype.hasOwnProperty.call(input, schema.name));
227680
- const value = schema.readOnly && schema.type === "table" ? getReadOnlyTableValue(schema, input) : schema.readOnly ? replacePlaceholders({
227681
- content: schema.content || "",
227718
+ const value = schema.readOnly && schema.type === "table" ? getReadOnlyTableValue(schema, input) : schema.readOnly ? resolveReadOnlyContent({
227719
+ schema,
227682
227720
  variables: {
227683
227721
  ...input,
227684
227722
  totalPages: schemasList.length,