@bpmn-io/form-js-viewer 1.14.1-alpha.0 → 1.15.0

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.es.js CHANGED
@@ -5903,10 +5903,15 @@ var SvgDownload = function SvgDownload(props) {
5903
5903
 
5904
5904
  const type = 'documentPreview';
5905
5905
 
5906
+ /**
5907
+ * @typedef DocumentEndpointBuilder
5908
+ * @property {(document: DocumentMetadata) => string} buildUrl
5909
+ */
5910
+
5906
5911
  /**
5907
5912
  * @typedef DocumentMetadata
5908
5913
  * @property {string} documentId
5909
- * @property {string} contentHash
5914
+ * @property {string} endpoint
5910
5915
  * @property {Object} metadata
5911
5916
  * @property {string|undefined} [metadata.contentType]
5912
5917
  * @property {string} metadata.fileName
@@ -5915,7 +5920,6 @@ const type = 'documentPreview';
5915
5920
  * @property {string} id
5916
5921
  * @property {string} [title]
5917
5922
  * @property {string} [dataSource]
5918
- * @property {string} [endpointKey]
5919
5923
  * @property {number} [maxHeight]
5920
5924
  * @property {string} [label]
5921
5925
  *
@@ -5927,18 +5931,18 @@ const type = 'documentPreview';
5927
5931
  * @returns {import("preact").JSX.Element}
5928
5932
  */
5929
5933
  function DocumentPreview(props) {
5934
+ /** @type {DocumentEndpointBuilder | null} */
5935
+ const documentEndpointBuilder = useService('documentEndpointBuilder', false);
5930
5936
  const {
5931
5937
  field,
5932
5938
  domId
5933
5939
  } = props;
5934
5940
  const {
5935
5941
  dataSource,
5936
- endpointKey,
5937
5942
  maxHeight,
5938
5943
  label
5939
5944
  } = field;
5940
5945
  const errorMessageId = `${domId}-error-message`;
5941
- const endpoint = useExpressionEvaluation(endpointKey || '');
5942
5946
  const data = useValidDocumentData(dataSource || '');
5943
5947
  const evaluatedLabel = useSingleLineTemplateEvaluation(label, {
5944
5948
  debug: true
@@ -5951,18 +5955,19 @@ function DocumentPreview(props) {
5951
5955
  }), jsx("div", {
5952
5956
  class: `fjs-${type}-document-container`,
5953
5957
  id: domId,
5954
- children: isValidDocumentEndpoint(endpoint) ? data.map((document, index) => jsx(DocumentRenderer, {
5955
- documentMetadata: document,
5956
- endpoint: endpoint,
5957
- maxHeight: maxHeight,
5958
- domId: `${domId}-${index}`
5959
- }, document.documentId)) : null
5958
+ children: data.map((document, index) => {
5959
+ const finalEndpoint = tryCatch(() => documentEndpointBuilder?.buildUrl(document)) ?? document.endpoint;
5960
+ return isValidDocumentEndpoint(finalEndpoint) ? jsx(DocumentRenderer, {
5961
+ documentMetadata: document,
5962
+ endpoint: finalEndpoint,
5963
+ maxHeight: maxHeight,
5964
+ domId: `${domId}-${index}`
5965
+ }, document.documentId) : null;
5966
+ })
5960
5967
  }), jsx(Errors, {
5961
5968
  id: errorMessageId,
5962
5969
  errors: getErrors({
5963
- dataSource,
5964
- endpoint,
5965
- endpointKey
5970
+ dataSource
5966
5971
  })
5967
5972
  })]
5968
5973
  });
@@ -5974,43 +5979,27 @@ DocumentPreview.config = {
5974
5979
  name: 'Document preview',
5975
5980
  create: (options = {}) => ({
5976
5981
  label: 'Document preview',
5977
- endpointKey: DEFAULT_ENDPOINT_KEY,
5978
5982
  ...options
5979
5983
  })
5980
5984
  };
5981
5985
 
5982
5986
  // helpers /////////////////////////////
5983
5987
 
5984
- const DOCUMENT_ID_PLACEHOLDER = '{documentId}';
5985
- const DEFAULT_ENDPOINT_KEY = '=defaultDocumentsEndpointKey';
5986
-
5987
5988
  /**
5988
5989
  * @typedef GetErrorOptions
5989
5990
  * @property {string|undefined} dataSource
5990
- * @property {string|undefined} endpointKey
5991
- * @property {string|null} endpoint
5992
5991
  *
5993
5992
  * @param {GetErrorOptions} options
5994
5993
  * @returns {string[]}
5995
5994
  */
5996
5995
  function getErrors(options) {
5997
5996
  const {
5998
- dataSource,
5999
- endpointKey,
6000
- endpoint
5997
+ dataSource
6001
5998
  } = options;
6002
5999
  let errors = [];
6003
6000
  if (!isString(dataSource) || dataSource.length < 1) {
6004
6001
  errors.push('Document reference is not defined.');
6005
6002
  }
6006
- if (!isString(endpointKey) || endpointKey.length < 1) {
6007
- errors.push('Endpoint key is not defined.');
6008
- }
6009
- if (endpointKey !== DEFAULT_ENDPOINT_KEY && !URL.canParse(endpoint)) {
6010
- errors.push(`If you change the endpoint key from "${DEFAULT_ENDPOINT_KEY}", the document preview won't work with Camunda Tasklist and you must provide a valid URL.`);
6011
- } else if (endpointKey !== DEFAULT_ENDPOINT_KEY && !isValidDocumentEndpoint(endpoint)) {
6012
- errors.push('Endpoint must contain "{documentId}".');
6013
- }
6014
6003
  return errors;
6015
6004
  }
6016
6005
 
@@ -6020,7 +6009,7 @@ function getErrors(options) {
6020
6009
  * @returns boolean
6021
6010
  */
6022
6011
  function isValidDocumentEndpoint(endpoint) {
6023
- return typeof endpoint === 'string' && URL.canParse(endpoint) && endpoint.includes(DOCUMENT_ID_PLACEHOLDER);
6012
+ return typeof endpoint === 'string' && URL.canParse(endpoint);
6024
6013
  }
6025
6014
 
6026
6015
  /**
@@ -6057,9 +6046,11 @@ function PdfRenderer(props) {
6057
6046
  onError,
6058
6047
  errorMessageId
6059
6048
  } = props;
6049
+ /** @type {ReturnType<typeof import("preact/hooks").useState<null | string>>} */
6060
6050
  const [pdfObjectUrl, setPdfObjectUrl] = useState(null);
6061
6051
  const [hasError, setHasError] = useState(false);
6062
6052
  useEffect(() => {
6053
+ /** @type {null | string} */
6063
6054
  let objectUrl = null;
6064
6055
  const fetchPdf = async () => {
6065
6056
  try {
@@ -6085,7 +6076,7 @@ function PdfRenderer(props) {
6085
6076
  };
6086
6077
  }, [url, onError]);
6087
6078
  return jsxs(Fragment, {
6088
- children: [pdfObjectUrl ? jsx("embed", {
6079
+ children: [pdfObjectUrl !== null ? jsx("embed", {
6089
6080
  src: pdfObjectUrl,
6090
6081
  type: "application/pdf",
6091
6082
  class: `fjs-${type}-pdf-viewer`
@@ -6119,11 +6110,6 @@ function DocumentRenderer(props) {
6119
6110
  const [hasError, setHasError] = useState(false);
6120
6111
  const ref = useRef(null);
6121
6112
  const isInViewport = useInViewport(ref);
6122
- const fullUrl = buildUrl({
6123
- baseUrl: endpoint,
6124
- documentId: documentMetadata.documentId,
6125
- contentHash: documentMetadata.contentHash
6126
- });
6127
6113
  const singleDocumentContainerClassName = `fjs-${type}-single-document-container`;
6128
6114
  const errorMessageId = `${domId}-error-message`;
6129
6115
  const errorMessage = 'Unable to download document';
@@ -6136,11 +6122,11 @@ function DocumentRenderer(props) {
6136
6122
  },
6137
6123
  "aria-describedby": hasError ? errorMessageId : undefined,
6138
6124
  children: [jsx("img", {
6139
- src: fullUrl,
6125
+ src: endpoint,
6140
6126
  alt: metadata.fileName,
6141
6127
  class: `fjs-${type}-image`
6142
6128
  }), jsx(DownloadButton, {
6143
- endpoint: fullUrl,
6129
+ endpoint: endpoint,
6144
6130
  fileName: metadata.fileName,
6145
6131
  onDownloadError: () => {
6146
6132
  setHasError(true);
@@ -6159,7 +6145,7 @@ function DocumentRenderer(props) {
6159
6145
  },
6160
6146
  "aria-describedby": hasError ? errorMessageId : undefined,
6161
6147
  children: jsx(PdfRenderer, {
6162
- url: fullUrl,
6148
+ url: endpoint,
6163
6149
  fileName: metadata.fileName,
6164
6150
  onError: () => setHasError(true),
6165
6151
  errorMessageId: errorMessageId
@@ -6179,7 +6165,7 @@ function DocumentRenderer(props) {
6179
6165
  errors: [errorMessage]
6180
6166
  }) : null]
6181
6167
  }), jsx(DownloadButton, {
6182
- endpoint: fullUrl,
6168
+ endpoint: endpoint,
6183
6169
  fileName: metadata.fileName,
6184
6170
  onDownloadError: () => {
6185
6171
  setHasError(true);
@@ -6259,27 +6245,18 @@ function useInViewport(ref) {
6259
6245
  }
6260
6246
 
6261
6247
  /**
6262
- * This solution should be a temporary fix, we should try to remove it via: https://github.com/bpmn-io/form-js/issues/1341
6263
- *
6264
- * @param {Object} options
6265
- * @param {string} options.baseUrl
6266
- * @param {string} options.documentId
6267
- * @param {string} [options.contentHash]
6268
- *
6269
- * @returns {string}
6248
+ * @template T
6249
+ * @param {() => T} fn - Function to execute
6250
+ * @returns {T | null}
6270
6251
  */
6271
- function buildUrl(options) {
6272
- const {
6273
- baseUrl,
6274
- documentId,
6275
- contentHash
6276
- } = options;
6277
- const finalUrl = new URL(baseUrl.replace(DOCUMENT_ID_PLACEHOLDER, documentId));
6278
- if (contentHash !== undefined) {
6279
- finalUrl.searchParams.set('contentHash', contentHash);
6252
+ const tryCatch = fn => {
6253
+ try {
6254
+ return fn();
6255
+ } catch (error) {
6256
+ console.error(error);
6257
+ return null;
6280
6258
  }
6281
- return decodeURI(finalUrl.toString());
6282
- }
6259
+ };
6283
6260
 
6284
6261
  /**
6285
6262
  * This file must not be changed or exchanged.
@@ -6438,7 +6415,7 @@ class FormFields {
6438
6415
  }
6439
6416
  }
6440
6417
 
6441
- const EXPRESSION_PROPERTIES = ['alt', 'appearance.prefixAdorner', 'appearance.suffixAdorner', 'conditional.hide', 'description', 'label', 'source', 'readonly', 'text', 'validate.min', 'validate.max', 'validate.minLength', 'validate.maxLength', 'valuesExpression', 'url', 'dataSource', 'columnsExpression', 'expression', 'multiple', 'accept', 'endpointKey', 'title'];
6418
+ const EXPRESSION_PROPERTIES = ['alt', 'appearance.prefixAdorner', 'appearance.suffixAdorner', 'conditional.hide', 'description', 'label', 'source', 'readonly', 'text', 'validate.min', 'validate.max', 'validate.minLength', 'validate.maxLength', 'valuesExpression', 'url', 'dataSource', 'columnsExpression', 'expression', 'multiple', 'accept', 'title'];
6442
6419
  const TEMPLATE_PROPERTIES = ['alt', 'appearance.prefixAdorner', 'appearance.suffixAdorner', 'description', 'label', 'source', 'text', 'content', 'url', 'title'];
6443
6420
 
6444
6421
  /**