@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.cjs +38 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +38 -61
- package/dist/index.es.js.map +1 -1
- package/dist/types/render/components/form-fields/DocumentPreview.d.ts +9 -7
- package/dist/types/render/components/index.d.ts +1 -1
- package/dist/types/util/constants/DatetimeConstants.d.ts +6 -2
- package/dist/types/util/constants/OptionsSourceConstants.d.ts +9 -3
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -5923,10 +5923,15 @@ var SvgDownload = function SvgDownload(props) {
|
|
|
5923
5923
|
|
|
5924
5924
|
const type = 'documentPreview';
|
|
5925
5925
|
|
|
5926
|
+
/**
|
|
5927
|
+
* @typedef DocumentEndpointBuilder
|
|
5928
|
+
* @property {(document: DocumentMetadata) => string} buildUrl
|
|
5929
|
+
*/
|
|
5930
|
+
|
|
5926
5931
|
/**
|
|
5927
5932
|
* @typedef DocumentMetadata
|
|
5928
5933
|
* @property {string} documentId
|
|
5929
|
-
* @property {string}
|
|
5934
|
+
* @property {string} endpoint
|
|
5930
5935
|
* @property {Object} metadata
|
|
5931
5936
|
* @property {string|undefined} [metadata.contentType]
|
|
5932
5937
|
* @property {string} metadata.fileName
|
|
@@ -5935,7 +5940,6 @@ const type = 'documentPreview';
|
|
|
5935
5940
|
* @property {string} id
|
|
5936
5941
|
* @property {string} [title]
|
|
5937
5942
|
* @property {string} [dataSource]
|
|
5938
|
-
* @property {string} [endpointKey]
|
|
5939
5943
|
* @property {number} [maxHeight]
|
|
5940
5944
|
* @property {string} [label]
|
|
5941
5945
|
*
|
|
@@ -5947,18 +5951,18 @@ const type = 'documentPreview';
|
|
|
5947
5951
|
* @returns {import("preact").JSX.Element}
|
|
5948
5952
|
*/
|
|
5949
5953
|
function DocumentPreview(props) {
|
|
5954
|
+
/** @type {DocumentEndpointBuilder | null} */
|
|
5955
|
+
const documentEndpointBuilder = useService('documentEndpointBuilder', false);
|
|
5950
5956
|
const {
|
|
5951
5957
|
field,
|
|
5952
5958
|
domId
|
|
5953
5959
|
} = props;
|
|
5954
5960
|
const {
|
|
5955
5961
|
dataSource,
|
|
5956
|
-
endpointKey,
|
|
5957
5962
|
maxHeight,
|
|
5958
5963
|
label
|
|
5959
5964
|
} = field;
|
|
5960
5965
|
const errorMessageId = `${domId}-error-message`;
|
|
5961
|
-
const endpoint = useExpressionEvaluation(endpointKey || '');
|
|
5962
5966
|
const data = useValidDocumentData(dataSource || '');
|
|
5963
5967
|
const evaluatedLabel = useSingleLineTemplateEvaluation(label, {
|
|
5964
5968
|
debug: true
|
|
@@ -5971,18 +5975,19 @@ function DocumentPreview(props) {
|
|
|
5971
5975
|
}), jsxRuntime.jsx("div", {
|
|
5972
5976
|
class: `fjs-${type}-document-container`,
|
|
5973
5977
|
id: domId,
|
|
5974
|
-
children:
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5978
|
+
children: data.map((document, index) => {
|
|
5979
|
+
const finalEndpoint = tryCatch(() => documentEndpointBuilder?.buildUrl(document)) ?? document.endpoint;
|
|
5980
|
+
return isValidDocumentEndpoint(finalEndpoint) ? jsxRuntime.jsx(DocumentRenderer, {
|
|
5981
|
+
documentMetadata: document,
|
|
5982
|
+
endpoint: finalEndpoint,
|
|
5983
|
+
maxHeight: maxHeight,
|
|
5984
|
+
domId: `${domId}-${index}`
|
|
5985
|
+
}, document.documentId) : null;
|
|
5986
|
+
})
|
|
5980
5987
|
}), jsxRuntime.jsx(Errors, {
|
|
5981
5988
|
id: errorMessageId,
|
|
5982
5989
|
errors: getErrors({
|
|
5983
|
-
dataSource
|
|
5984
|
-
endpoint,
|
|
5985
|
-
endpointKey
|
|
5990
|
+
dataSource
|
|
5986
5991
|
})
|
|
5987
5992
|
})]
|
|
5988
5993
|
});
|
|
@@ -5994,43 +5999,27 @@ DocumentPreview.config = {
|
|
|
5994
5999
|
name: 'Document preview',
|
|
5995
6000
|
create: (options = {}) => ({
|
|
5996
6001
|
label: 'Document preview',
|
|
5997
|
-
endpointKey: DEFAULT_ENDPOINT_KEY,
|
|
5998
6002
|
...options
|
|
5999
6003
|
})
|
|
6000
6004
|
};
|
|
6001
6005
|
|
|
6002
6006
|
// helpers /////////////////////////////
|
|
6003
6007
|
|
|
6004
|
-
const DOCUMENT_ID_PLACEHOLDER = '{documentId}';
|
|
6005
|
-
const DEFAULT_ENDPOINT_KEY = '=defaultDocumentsEndpointKey';
|
|
6006
|
-
|
|
6007
6008
|
/**
|
|
6008
6009
|
* @typedef GetErrorOptions
|
|
6009
6010
|
* @property {string|undefined} dataSource
|
|
6010
|
-
* @property {string|undefined} endpointKey
|
|
6011
|
-
* @property {string|null} endpoint
|
|
6012
6011
|
*
|
|
6013
6012
|
* @param {GetErrorOptions} options
|
|
6014
6013
|
* @returns {string[]}
|
|
6015
6014
|
*/
|
|
6016
6015
|
function getErrors(options) {
|
|
6017
6016
|
const {
|
|
6018
|
-
dataSource
|
|
6019
|
-
endpointKey,
|
|
6020
|
-
endpoint
|
|
6017
|
+
dataSource
|
|
6021
6018
|
} = options;
|
|
6022
6019
|
let errors = [];
|
|
6023
6020
|
if (!minDash.isString(dataSource) || dataSource.length < 1) {
|
|
6024
6021
|
errors.push('Document reference is not defined.');
|
|
6025
6022
|
}
|
|
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
6023
|
return errors;
|
|
6035
6024
|
}
|
|
6036
6025
|
|
|
@@ -6040,7 +6029,7 @@ function getErrors(options) {
|
|
|
6040
6029
|
* @returns boolean
|
|
6041
6030
|
*/
|
|
6042
6031
|
function isValidDocumentEndpoint(endpoint) {
|
|
6043
|
-
return typeof endpoint === 'string' && URL.canParse(endpoint)
|
|
6032
|
+
return typeof endpoint === 'string' && URL.canParse(endpoint);
|
|
6044
6033
|
}
|
|
6045
6034
|
|
|
6046
6035
|
/**
|
|
@@ -6077,9 +6066,11 @@ function PdfRenderer(props) {
|
|
|
6077
6066
|
onError,
|
|
6078
6067
|
errorMessageId
|
|
6079
6068
|
} = props;
|
|
6069
|
+
/** @type {ReturnType<typeof import("preact/hooks").useState<null | string>>} */
|
|
6080
6070
|
const [pdfObjectUrl, setPdfObjectUrl] = hooks.useState(null);
|
|
6081
6071
|
const [hasError, setHasError] = hooks.useState(false);
|
|
6082
6072
|
hooks.useEffect(() => {
|
|
6073
|
+
/** @type {null | string} */
|
|
6083
6074
|
let objectUrl = null;
|
|
6084
6075
|
const fetchPdf = async () => {
|
|
6085
6076
|
try {
|
|
@@ -6105,7 +6096,7 @@ function PdfRenderer(props) {
|
|
|
6105
6096
|
};
|
|
6106
6097
|
}, [url, onError]);
|
|
6107
6098
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
6108
|
-
children: [pdfObjectUrl ? jsxRuntime.jsx("embed", {
|
|
6099
|
+
children: [pdfObjectUrl !== null ? jsxRuntime.jsx("embed", {
|
|
6109
6100
|
src: pdfObjectUrl,
|
|
6110
6101
|
type: "application/pdf",
|
|
6111
6102
|
class: `fjs-${type}-pdf-viewer`
|
|
@@ -6139,11 +6130,6 @@ function DocumentRenderer(props) {
|
|
|
6139
6130
|
const [hasError, setHasError] = hooks.useState(false);
|
|
6140
6131
|
const ref = hooks.useRef(null);
|
|
6141
6132
|
const isInViewport = useInViewport(ref);
|
|
6142
|
-
const fullUrl = buildUrl({
|
|
6143
|
-
baseUrl: endpoint,
|
|
6144
|
-
documentId: documentMetadata.documentId,
|
|
6145
|
-
contentHash: documentMetadata.contentHash
|
|
6146
|
-
});
|
|
6147
6133
|
const singleDocumentContainerClassName = `fjs-${type}-single-document-container`;
|
|
6148
6134
|
const errorMessageId = `${domId}-error-message`;
|
|
6149
6135
|
const errorMessage = 'Unable to download document';
|
|
@@ -6156,11 +6142,11 @@ function DocumentRenderer(props) {
|
|
|
6156
6142
|
},
|
|
6157
6143
|
"aria-describedby": hasError ? errorMessageId : undefined,
|
|
6158
6144
|
children: [jsxRuntime.jsx("img", {
|
|
6159
|
-
src:
|
|
6145
|
+
src: endpoint,
|
|
6160
6146
|
alt: metadata.fileName,
|
|
6161
6147
|
class: `fjs-${type}-image`
|
|
6162
6148
|
}), jsxRuntime.jsx(DownloadButton, {
|
|
6163
|
-
endpoint:
|
|
6149
|
+
endpoint: endpoint,
|
|
6164
6150
|
fileName: metadata.fileName,
|
|
6165
6151
|
onDownloadError: () => {
|
|
6166
6152
|
setHasError(true);
|
|
@@ -6179,7 +6165,7 @@ function DocumentRenderer(props) {
|
|
|
6179
6165
|
},
|
|
6180
6166
|
"aria-describedby": hasError ? errorMessageId : undefined,
|
|
6181
6167
|
children: jsxRuntime.jsx(PdfRenderer, {
|
|
6182
|
-
url:
|
|
6168
|
+
url: endpoint,
|
|
6183
6169
|
fileName: metadata.fileName,
|
|
6184
6170
|
onError: () => setHasError(true),
|
|
6185
6171
|
errorMessageId: errorMessageId
|
|
@@ -6199,7 +6185,7 @@ function DocumentRenderer(props) {
|
|
|
6199
6185
|
errors: [errorMessage]
|
|
6200
6186
|
}) : null]
|
|
6201
6187
|
}), jsxRuntime.jsx(DownloadButton, {
|
|
6202
|
-
endpoint:
|
|
6188
|
+
endpoint: endpoint,
|
|
6203
6189
|
fileName: metadata.fileName,
|
|
6204
6190
|
onDownloadError: () => {
|
|
6205
6191
|
setHasError(true);
|
|
@@ -6279,27 +6265,18 @@ function useInViewport(ref) {
|
|
|
6279
6265
|
}
|
|
6280
6266
|
|
|
6281
6267
|
/**
|
|
6282
|
-
*
|
|
6283
|
-
*
|
|
6284
|
-
* @
|
|
6285
|
-
* @param {string} options.baseUrl
|
|
6286
|
-
* @param {string} options.documentId
|
|
6287
|
-
* @param {string} [options.contentHash]
|
|
6288
|
-
*
|
|
6289
|
-
* @returns {string}
|
|
6268
|
+
* @template T
|
|
6269
|
+
* @param {() => T} fn - Function to execute
|
|
6270
|
+
* @returns {T | null}
|
|
6290
6271
|
*/
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
const finalUrl = new URL(baseUrl.replace(DOCUMENT_ID_PLACEHOLDER, documentId));
|
|
6298
|
-
if (contentHash !== undefined) {
|
|
6299
|
-
finalUrl.searchParams.set('contentHash', contentHash);
|
|
6272
|
+
const tryCatch = fn => {
|
|
6273
|
+
try {
|
|
6274
|
+
return fn();
|
|
6275
|
+
} catch (error) {
|
|
6276
|
+
console.error(error);
|
|
6277
|
+
return null;
|
|
6300
6278
|
}
|
|
6301
|
-
|
|
6302
|
-
}
|
|
6279
|
+
};
|
|
6303
6280
|
|
|
6304
6281
|
/**
|
|
6305
6282
|
* This file must not be changed or exchanged.
|
|
@@ -6458,7 +6435,7 @@ class FormFields {
|
|
|
6458
6435
|
}
|
|
6459
6436
|
}
|
|
6460
6437
|
|
|
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', '
|
|
6438
|
+
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
6439
|
const TEMPLATE_PROPERTIES = ['alt', 'appearance.prefixAdorner', 'appearance.suffixAdorner', 'description', 'label', 'source', 'text', 'content', 'url', 'title'];
|
|
6463
6440
|
|
|
6464
6441
|
/**
|