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

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.cjs CHANGED
@@ -5164,13 +5164,22 @@ function Textfield(props) {
5164
5164
  const {
5165
5165
  required
5166
5166
  } = validate;
5167
- const [onInputChange, flushOnChange] = useFlushDebounce(({
5167
+ const [onChange, flushOnChange] = useFlushDebounce(({
5168
5168
  target
5169
5169
  }) => {
5170
5170
  props.onChange({
5171
5171
  value: target.value
5172
5172
  });
5173
5173
  });
5174
+
5175
+ /**
5176
+ * @param {import('preact').JSX.TargetedEvent<HTMLInputElement, Event>} event
5177
+ */
5178
+ const onInputChange = event => {
5179
+ onChange({
5180
+ target: event.target
5181
+ });
5182
+ };
5174
5183
  const onInputBlur = () => {
5175
5184
  flushOnChange && flushOnChange();
5176
5185
  onBlur && onBlur();
@@ -5923,10 +5932,15 @@ var SvgDownload = function SvgDownload(props) {
5923
5932
 
5924
5933
  const type = 'documentPreview';
5925
5934
 
5935
+ /**
5936
+ * @typedef DocumentEndpointBuilder
5937
+ * @property {(document: DocumentMetadata) => string} buildUrl
5938
+ */
5939
+
5926
5940
  /**
5927
5941
  * @typedef DocumentMetadata
5928
5942
  * @property {string} documentId
5929
- * @property {string} contentHash
5943
+ * @property {string} endpoint
5930
5944
  * @property {Object} metadata
5931
5945
  * @property {string|undefined} [metadata.contentType]
5932
5946
  * @property {string} metadata.fileName
@@ -5935,7 +5949,6 @@ const type = 'documentPreview';
5935
5949
  * @property {string} id
5936
5950
  * @property {string} [title]
5937
5951
  * @property {string} [dataSource]
5938
- * @property {string} [endpointKey]
5939
5952
  * @property {number} [maxHeight]
5940
5953
  * @property {string} [label]
5941
5954
  *
@@ -5947,18 +5960,18 @@ const type = 'documentPreview';
5947
5960
  * @returns {import("preact").JSX.Element}
5948
5961
  */
5949
5962
  function DocumentPreview(props) {
5963
+ /** @type {DocumentEndpointBuilder | null} */
5964
+ const documentEndpointBuilder = useService('documentEndpointBuilder', false);
5950
5965
  const {
5951
5966
  field,
5952
5967
  domId
5953
5968
  } = props;
5954
5969
  const {
5955
5970
  dataSource,
5956
- endpointKey,
5957
5971
  maxHeight,
5958
5972
  label
5959
5973
  } = field;
5960
5974
  const errorMessageId = `${domId}-error-message`;
5961
- const endpoint = useExpressionEvaluation(endpointKey || '');
5962
5975
  const data = useValidDocumentData(dataSource || '');
5963
5976
  const evaluatedLabel = useSingleLineTemplateEvaluation(label, {
5964
5977
  debug: true
@@ -5971,18 +5984,19 @@ function DocumentPreview(props) {
5971
5984
  }), jsxRuntime.jsx("div", {
5972
5985
  class: `fjs-${type}-document-container`,
5973
5986
  id: domId,
5974
- children: isValidDocumentEndpoint(endpoint) ? data.map((document, index) => jsxRuntime.jsx(DocumentRenderer, {
5975
- documentMetadata: document,
5976
- endpoint: endpoint,
5977
- maxHeight: maxHeight,
5978
- domId: `${domId}-${index}`
5979
- }, document.documentId)) : null
5987
+ children: data.map((document, index) => {
5988
+ const finalEndpoint = tryCatch(() => documentEndpointBuilder?.buildUrl(document)) ?? document.endpoint;
5989
+ return isValidDocumentEndpoint(finalEndpoint) ? jsxRuntime.jsx(DocumentRenderer, {
5990
+ documentMetadata: document,
5991
+ endpoint: finalEndpoint,
5992
+ maxHeight: maxHeight,
5993
+ domId: `${domId}-${index}`
5994
+ }, document.documentId) : null;
5995
+ })
5980
5996
  }), jsxRuntime.jsx(Errors, {
5981
5997
  id: errorMessageId,
5982
5998
  errors: getErrors({
5983
- dataSource,
5984
- endpoint,
5985
- endpointKey
5999
+ dataSource
5986
6000
  })
5987
6001
  })]
5988
6002
  });
@@ -5994,43 +6008,27 @@ DocumentPreview.config = {
5994
6008
  name: 'Document preview',
5995
6009
  create: (options = {}) => ({
5996
6010
  label: 'Document preview',
5997
- endpointKey: DEFAULT_ENDPOINT_KEY,
5998
6011
  ...options
5999
6012
  })
6000
6013
  };
6001
6014
 
6002
6015
  // helpers /////////////////////////////
6003
6016
 
6004
- const DOCUMENT_ID_PLACEHOLDER = '{documentId}';
6005
- const DEFAULT_ENDPOINT_KEY = '=defaultDocumentsEndpointKey';
6006
-
6007
6017
  /**
6008
6018
  * @typedef GetErrorOptions
6009
6019
  * @property {string|undefined} dataSource
6010
- * @property {string|undefined} endpointKey
6011
- * @property {string|null} endpoint
6012
6020
  *
6013
6021
  * @param {GetErrorOptions} options
6014
6022
  * @returns {string[]}
6015
6023
  */
6016
6024
  function getErrors(options) {
6017
6025
  const {
6018
- dataSource,
6019
- endpointKey,
6020
- endpoint
6026
+ dataSource
6021
6027
  } = options;
6022
6028
  let errors = [];
6023
6029
  if (!minDash.isString(dataSource) || dataSource.length < 1) {
6024
6030
  errors.push('Document reference is not defined.');
6025
6031
  }
6026
- if (!minDash.isString(endpointKey) || endpointKey.length < 1) {
6027
- errors.push('Endpoint key is not defined.');
6028
- }
6029
- if (endpointKey !== DEFAULT_ENDPOINT_KEY && !URL.canParse(endpoint)) {
6030
- 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.`);
6031
- } else if (endpointKey !== DEFAULT_ENDPOINT_KEY && !isValidDocumentEndpoint(endpoint)) {
6032
- errors.push('Endpoint must contain "{documentId}".');
6033
- }
6034
6032
  return errors;
6035
6033
  }
6036
6034
 
@@ -6040,7 +6038,7 @@ function getErrors(options) {
6040
6038
  * @returns boolean
6041
6039
  */
6042
6040
  function isValidDocumentEndpoint(endpoint) {
6043
- return typeof endpoint === 'string' && URL.canParse(endpoint) && endpoint.includes(DOCUMENT_ID_PLACEHOLDER);
6041
+ return typeof endpoint === 'string' && URL.canParse(endpoint);
6044
6042
  }
6045
6043
 
6046
6044
  /**
@@ -6077,9 +6075,11 @@ function PdfRenderer(props) {
6077
6075
  onError,
6078
6076
  errorMessageId
6079
6077
  } = props;
6078
+ /** @type {ReturnType<typeof import("preact/hooks").useState<null | string>>} */
6080
6079
  const [pdfObjectUrl, setPdfObjectUrl] = hooks.useState(null);
6081
6080
  const [hasError, setHasError] = hooks.useState(false);
6082
6081
  hooks.useEffect(() => {
6082
+ /** @type {null | string} */
6083
6083
  let objectUrl = null;
6084
6084
  const fetchPdf = async () => {
6085
6085
  try {
@@ -6105,7 +6105,7 @@ function PdfRenderer(props) {
6105
6105
  };
6106
6106
  }, [url, onError]);
6107
6107
  return jsxRuntime.jsxs(jsxRuntime.Fragment, {
6108
- children: [pdfObjectUrl ? jsxRuntime.jsx("embed", {
6108
+ children: [pdfObjectUrl !== null ? jsxRuntime.jsx("embed", {
6109
6109
  src: pdfObjectUrl,
6110
6110
  type: "application/pdf",
6111
6111
  class: `fjs-${type}-pdf-viewer`
@@ -6139,11 +6139,6 @@ function DocumentRenderer(props) {
6139
6139
  const [hasError, setHasError] = hooks.useState(false);
6140
6140
  const ref = hooks.useRef(null);
6141
6141
  const isInViewport = useInViewport(ref);
6142
- const fullUrl = buildUrl({
6143
- baseUrl: endpoint,
6144
- documentId: documentMetadata.documentId,
6145
- contentHash: documentMetadata.contentHash
6146
- });
6147
6142
  const singleDocumentContainerClassName = `fjs-${type}-single-document-container`;
6148
6143
  const errorMessageId = `${domId}-error-message`;
6149
6144
  const errorMessage = 'Unable to download document';
@@ -6156,11 +6151,11 @@ function DocumentRenderer(props) {
6156
6151
  },
6157
6152
  "aria-describedby": hasError ? errorMessageId : undefined,
6158
6153
  children: [jsxRuntime.jsx("img", {
6159
- src: fullUrl,
6154
+ src: endpoint,
6160
6155
  alt: metadata.fileName,
6161
6156
  class: `fjs-${type}-image`
6162
6157
  }), jsxRuntime.jsx(DownloadButton, {
6163
- endpoint: fullUrl,
6158
+ endpoint: endpoint,
6164
6159
  fileName: metadata.fileName,
6165
6160
  onDownloadError: () => {
6166
6161
  setHasError(true);
@@ -6179,7 +6174,7 @@ function DocumentRenderer(props) {
6179
6174
  },
6180
6175
  "aria-describedby": hasError ? errorMessageId : undefined,
6181
6176
  children: jsxRuntime.jsx(PdfRenderer, {
6182
- url: fullUrl,
6177
+ url: endpoint,
6183
6178
  fileName: metadata.fileName,
6184
6179
  onError: () => setHasError(true),
6185
6180
  errorMessageId: errorMessageId
@@ -6199,7 +6194,7 @@ function DocumentRenderer(props) {
6199
6194
  errors: [errorMessage]
6200
6195
  }) : null]
6201
6196
  }), jsxRuntime.jsx(DownloadButton, {
6202
- endpoint: fullUrl,
6197
+ endpoint: endpoint,
6203
6198
  fileName: metadata.fileName,
6204
6199
  onDownloadError: () => {
6205
6200
  setHasError(true);
@@ -6279,27 +6274,18 @@ function useInViewport(ref) {
6279
6274
  }
6280
6275
 
6281
6276
  /**
6282
- * This solution should be a temporary fix, we should try to remove it via: https://github.com/bpmn-io/form-js/issues/1341
6283
- *
6284
- * @param {Object} options
6285
- * @param {string} options.baseUrl
6286
- * @param {string} options.documentId
6287
- * @param {string} [options.contentHash]
6288
- *
6289
- * @returns {string}
6277
+ * @template T
6278
+ * @param {() => T} fn - Function to execute
6279
+ * @returns {T | null}
6290
6280
  */
6291
- function buildUrl(options) {
6292
- const {
6293
- baseUrl,
6294
- documentId,
6295
- contentHash
6296
- } = options;
6297
- const finalUrl = new URL(baseUrl.replace(DOCUMENT_ID_PLACEHOLDER, documentId));
6298
- if (contentHash !== undefined) {
6299
- finalUrl.searchParams.set('contentHash', contentHash);
6281
+ const tryCatch = fn => {
6282
+ try {
6283
+ return fn();
6284
+ } catch (error) {
6285
+ console.error(error);
6286
+ return null;
6300
6287
  }
6301
- return decodeURI(finalUrl.toString());
6302
- }
6288
+ };
6303
6289
 
6304
6290
  /**
6305
6291
  * This file must not be changed or exchanged.
@@ -6458,7 +6444,7 @@ class FormFields {
6458
6444
  }
6459
6445
  }
6460
6446
 
6461
- 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'];
6447
+ 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'];
6462
6448
  const TEMPLATE_PROPERTIES = ['alt', 'appearance.prefixAdorner', 'appearance.suffixAdorner', 'description', 'label', 'source', 'text', 'content', 'url', 'title'];
6463
6449
 
6464
6450
  /**