@pdfme/schemas 6.1.12-dev.13 → 6.1.12-dev.14

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.
@@ -1,7 +1,7 @@
1
1
  import { a as createListItemSplitRange, c as getListItemRange, i as TEXT_LINE_SPLIT_UNIT, l as getTableBodyRange, n as LIST_ITEM_SPLIT_UNIT, o as createTableBodySplitRange, r as TABLE_BODY_SPLIT_UNIT, s as createTextLineSplitRange, t as BUILT_IN_DYNAMIC_LAYOUT_SPLIT_UNITS, u as getTextLineRange } from "./splitRange-BHV0vb0Q.js";
2
2
  import { n as getDynamicLayoutForTable } from "./dynamicTemplate-Bs3HHtDw.js";
3
3
  import { t as getDynamicLayoutForList } from "./dynamicTemplate-DQF7c6NR.js";
4
- import { n as getDynamicLayoutForMultiVariableText, t as getDynamicLayoutForText } from "./dynamicTemplate-BcCrm2SZ.js";
4
+ import { n as getDynamicLayoutForMultiVariableText, t as getDynamicLayoutForText } from "./dynamicTemplate-DFk_de1Y.js";
5
5
  //#region src/dynamicLayout.ts
6
6
  var isExpandableTextSchema = (schema) => (schema.type === "text" || schema.type === "multiVariableText") && schema.overflow === "expand";
7
7
  var isDynamicLayoutSchema = (schema) => schema.type === "table" || schema.type === "list" || isExpandableTextSchema(schema);
@@ -6,7 +6,7 @@ var getDynamicLayoutForMultiVariableText = async (value, args) => {
6
6
  if (args.schema.type !== "multiVariableText") return { heights: [args.schema.height] };
7
7
  const schema = args.schema;
8
8
  if (schema.overflow !== "expand") return { heights: [schema.height] };
9
- let renderValue = value;
9
+ let renderValue = schema.readOnly && schema.variables.length === 0 ? schema.text || "" : value;
10
10
  if (!schema.readOnly) {
11
11
  if (!validateVariables(value, schema)) return { heights: [schema.height] };
12
12
  renderValue = isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(schema.text || "", value) : substituteVariables(schema.text || "", value);
@@ -72,4 +72,4 @@ var getDynamicLayoutForText = async (value, args) => {
72
72
  //#endregion
73
73
  export { getDynamicLayoutForMultiVariableText as n, getDynamicLayoutForText as t };
74
74
 
75
- //# sourceMappingURL=dynamicTemplate-BcCrm2SZ.js.map
75
+ //# sourceMappingURL=dynamicTemplate-DFk_de1Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamicTemplate-DFk_de1Y.js","names":[],"sources":["../src/multiVariableText/dynamicTemplate.ts","../src/text/dynamicTemplate.ts"],"sourcesContent":["import type { DynamicLayoutArgs, DynamicLayoutResult } from '@pdfme/common';\nimport { TEXT_OVERFLOW_EXPAND } from '../text/constants.js';\nimport {\n getTextLineHeightsWithBox,\n getTextSplitBoxStyle,\n measureTextLines,\n sumLineHeights,\n} from '../text/measure.js';\nimport { isInlineMarkdownTextSchema } from '../text/richText.js';\nimport type { MultiVariableTextSchema } from './types.js';\nimport {\n substituteVariables,\n substituteVariablesAsInlineMarkdownLiterals,\n validateVariables,\n} from './helper.js';\nimport { createTextLineSplitRange } from '../splitRange.js';\n\nexport const getDynamicLayoutForMultiVariableText = async (\n value: string,\n args: DynamicLayoutArgs,\n): Promise<DynamicLayoutResult> => {\n if (args.schema.type !== 'multiVariableText') return { heights: [args.schema.height] };\n\n const schema = args.schema as MultiVariableTextSchema;\n if (schema.overflow !== TEXT_OVERFLOW_EXPAND) {\n return { heights: [schema.height] };\n }\n\n let renderValue = schema.readOnly && schema.variables.length === 0 ? schema.text || '' : value;\n if (!schema.readOnly) {\n if (!validateVariables(value, schema)) {\n return { heights: [schema.height] };\n }\n\n renderValue = isInlineMarkdownTextSchema(schema)\n ? substituteVariablesAsInlineMarkdownLiterals(schema.text || '', value)\n : substituteVariables(schema.text || '', value);\n }\n const { lineHeights } = await measureTextLines({\n value: renderValue,\n schema,\n font: args.options.font,\n _cache: args._cache,\n // `expand` owns the height decision, so measuring against a shrink-to-fit font size\n // would make the field keep its original box instead of growing.\n ignoreDynamicFontSize: true,\n });\n const heights = getTextLineHeightsWithBox(lineHeights, schema);\n const measuredHeight = sumLineHeights(heights);\n\n if (measuredHeight <= schema.height || lineHeights.length === 0) {\n return {\n heights: [schema.height],\n patchSplitSchema: () => ({ dynamicFontSize: undefined }),\n };\n }\n\n return {\n heights: lineHeights.length === 1 ? [Math.max(schema.height, measuredHeight)] : heights,\n patchSplitSchema: ({ start, end, isSplit }) => ({\n dynamicFontSize: undefined,\n __splitRange: lineHeights.length === 1 ? undefined : createTextLineSplitRange(start, end),\n __isSplit: isSplit,\n ...getTextSplitBoxStyle(schema, { start, end }, lineHeights.length),\n }),\n };\n};\n","import type { DynamicLayoutArgs, DynamicLayoutResult } from '@pdfme/common';\nimport { TEXT_OVERFLOW_EXPAND } from './constants.js';\nimport {\n getTextLineHeightsWithBox,\n getTextSplitBoxStyle,\n measureTextLines,\n sumLineHeights,\n} from './measure.js';\nimport type { TextSchema } from './types.js';\nimport { createTextLineSplitRange } from '../splitRange.js';\n\nexport const getDynamicLayoutForText = async (\n value: string,\n args: DynamicLayoutArgs,\n): Promise<DynamicLayoutResult> => {\n if (args.schema.type !== 'text') return { heights: [args.schema.height] };\n\n const schema = args.schema as TextSchema;\n if (schema.overflow !== TEXT_OVERFLOW_EXPAND) {\n return { heights: [schema.height] };\n }\n\n const { lineHeights } = await measureTextLines({\n value,\n schema,\n font: args.options.font,\n _cache: args._cache,\n // `expand` owns the height decision, so measuring against a shrink-to-fit font size\n // would make the field keep its original box instead of growing.\n ignoreDynamicFontSize: true,\n });\n const heights = getTextLineHeightsWithBox(lineHeights, schema);\n const measuredHeight = sumLineHeights(heights);\n\n if (measuredHeight <= schema.height || lineHeights.length === 0) {\n return {\n heights: [schema.height],\n patchSplitSchema: () => ({ dynamicFontSize: undefined }),\n };\n }\n\n return {\n heights: lineHeights.length === 1 ? [Math.max(schema.height, measuredHeight)] : heights,\n patchSplitSchema: ({ start, end, isSplit }) => ({\n dynamicFontSize: undefined,\n __splitRange: lineHeights.length === 1 ? undefined : createTextLineSplitRange(start, end),\n __isSplit: isSplit,\n ...getTextSplit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a,0BAA0B,OACrC,OACA,SACiC;CACjC,IAAI,KAAK,OAAO,SAAS,QAAQ,OAAO,EAAE,SAAS,CAAC,KAAK,OAAO,MAAM,EAAE;CAExE,MAAM,SAAS,KAAK;CACpB,IAAI,OAAO,aAAA,UACT,OAAO,EAAE,SAAS,CAAC,OAAO,MAAM,EAAE;CAGpC,MAAM,EAAE,gBAAgB,MAAM,iBAAiB;EAC7C;EACA;EACA,MAAM,KAAK,QAAQ;EACnB,QAAQ,KAAK;EAGb,uBAAuB;CACzB,CAAC;CACD,MAAM,UAAU,0BAA0B,aAAa,MAAM;CAC7D,MAAM,iBAAiB,eAAe,OAAO;CAE7C,IAAI,kBAAkB,OAAO,UAAU,YAAY,WAAW,GAC5D,OAAO;EACL,SAAS,CAAC,OAAO,MAAM;EACvB,yBAAyB,EAAE,iBAAiB,KAAA,EAAU;CACxD;CAGF,OAAO;EACL,SAAS,YAAY,WAAW,IAAI,CAAC,KAAK,IAAI,OAAO,QAAQ,cAAc,CAAC,IAAI;EAChF,mBAAmB,EAAE,OAAO,KAAK,eAAe;GAC9C,iBAAiB,KAAA;GACjB,cAAc,YAAY,WAAW,IAAI,KAAA,IAAY,yBAAyB,OAAO,GAAG;GACxF,WAAW;GACX,GAAG,qBAAqB,QAAQ;IAAE;IAAO;GAAI,GAAG,YAAY,MAAM;EACpE;CACF;AACF"}
package/dist/index.js CHANGED
@@ -43,8 +43,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
43
43
  var pdfRender$3 = async (arg) => {
44
44
  const { value, schema, ...rest } = arg;
45
45
  if (schema.readOnly) {
46
+ const readOnlyValue = schema.variables.length > 0 ? value : schema.text || "";
46
47
  await pdfRender$4({
47
- value,
48
+ value: readOnlyValue,
48
49
  schema,
49
50
  ...rest
50
51
  });
@@ -210,7 +211,7 @@ var uiRender$3 = async (arg) => {
210
211
  let text = schema.text;
211
212
  let numVariables = schema.variables.length;
212
213
  const renderResolvedValue = schema.readOnly === true && mode !== "designer";
213
- const renderValue = renderResolvedValue ? value : isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(text, value) : substituteVariables(text, value);
214
+ const renderValue = renderResolvedValue ? numVariables > 0 ? value : text || "" : isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(text, value) : substituteVariables(text, value);
214
215
  if (mode === "form" && numVariables > 0 && !renderResolvedValue) {
215
216
  await formUiRender(arg);
216
217
  return;
@@ -233,7 +234,7 @@ var uiRender$3 = async (arg) => {
233
234
  const textBlock = rootElement.querySelector("#text-" + String(schema.id));
234
235
  if (!textBlock) throw new Error("Text block not found. Ensure the text block has an id of \"text-\" + schema.id");
235
236
  if (mode === "designer") textBlock.addEventListener("keyup", (event) => {
236
- text = textBlock.textContent || "";
237
+ text = textBlock.innerText || "";
237
238
  if (keyPressShouldBeChecked(event)) {
238
239
  const newNumVariables = countUniqueVariableNames(text);
239
240
  if (numVariables !== newNumVariables) {