@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 +48 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +48 -62
- 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.es.js
CHANGED
|
@@ -5144,13 +5144,22 @@ function Textfield(props) {
|
|
|
5144
5144
|
const {
|
|
5145
5145
|
required
|
|
5146
5146
|
} = validate;
|
|
5147
|
-
const [
|
|
5147
|
+
const [onChange, flushOnChange] = useFlushDebounce(({
|
|
5148
5148
|
target
|
|
5149
5149
|
}) => {
|
|
5150
5150
|
props.onChange({
|
|
5151
5151
|
value: target.value
|
|
5152
5152
|
});
|
|
5153
5153
|
});
|
|
5154
|
+
|
|
5155
|
+
/**
|
|
5156
|
+
* @param {import('preact').JSX.TargetedEvent<HTMLInputElement, Event>} event
|
|
5157
|
+
*/
|
|
5158
|
+
const onInputChange = event => {
|
|
5159
|
+
onChange({
|
|
5160
|
+
target: event.target
|
|
5161
|
+
});
|
|
5162
|
+
};
|
|
5154
5163
|
const onInputBlur = () => {
|
|
5155
5164
|
flushOnChange && flushOnChange();
|
|
5156
5165
|
onBlur && onBlur();
|
|
@@ -5903,10 +5912,15 @@ var SvgDownload = function SvgDownload(props) {
|
|
|
5903
5912
|
|
|
5904
5913
|
const type = 'documentPreview';
|
|
5905
5914
|
|
|
5915
|
+
/**
|
|
5916
|
+
* @typedef DocumentEndpointBuilder
|
|
5917
|
+
* @property {(document: DocumentMetadata) => string} buildUrl
|
|
5918
|
+
*/
|
|
5919
|
+
|
|
5906
5920
|
/**
|
|
5907
5921
|
* @typedef DocumentMetadata
|
|
5908
5922
|
* @property {string} documentId
|
|
5909
|
-
* @property {string}
|
|
5923
|
+
* @property {string} endpoint
|
|
5910
5924
|
* @property {Object} metadata
|
|
5911
5925
|
* @property {string|undefined} [metadata.contentType]
|
|
5912
5926
|
* @property {string} metadata.fileName
|
|
@@ -5915,7 +5929,6 @@ const type = 'documentPreview';
|
|
|
5915
5929
|
* @property {string} id
|
|
5916
5930
|
* @property {string} [title]
|
|
5917
5931
|
* @property {string} [dataSource]
|
|
5918
|
-
* @property {string} [endpointKey]
|
|
5919
5932
|
* @property {number} [maxHeight]
|
|
5920
5933
|
* @property {string} [label]
|
|
5921
5934
|
*
|
|
@@ -5927,18 +5940,18 @@ const type = 'documentPreview';
|
|
|
5927
5940
|
* @returns {import("preact").JSX.Element}
|
|
5928
5941
|
*/
|
|
5929
5942
|
function DocumentPreview(props) {
|
|
5943
|
+
/** @type {DocumentEndpointBuilder | null} */
|
|
5944
|
+
const documentEndpointBuilder = useService('documentEndpointBuilder', false);
|
|
5930
5945
|
const {
|
|
5931
5946
|
field,
|
|
5932
5947
|
domId
|
|
5933
5948
|
} = props;
|
|
5934
5949
|
const {
|
|
5935
5950
|
dataSource,
|
|
5936
|
-
endpointKey,
|
|
5937
5951
|
maxHeight,
|
|
5938
5952
|
label
|
|
5939
5953
|
} = field;
|
|
5940
5954
|
const errorMessageId = `${domId}-error-message`;
|
|
5941
|
-
const endpoint = useExpressionEvaluation(endpointKey || '');
|
|
5942
5955
|
const data = useValidDocumentData(dataSource || '');
|
|
5943
5956
|
const evaluatedLabel = useSingleLineTemplateEvaluation(label, {
|
|
5944
5957
|
debug: true
|
|
@@ -5951,18 +5964,19 @@ function DocumentPreview(props) {
|
|
|
5951
5964
|
}), jsx("div", {
|
|
5952
5965
|
class: `fjs-${type}-document-container`,
|
|
5953
5966
|
id: domId,
|
|
5954
|
-
children:
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5967
|
+
children: data.map((document, index) => {
|
|
5968
|
+
const finalEndpoint = tryCatch(() => documentEndpointBuilder?.buildUrl(document)) ?? document.endpoint;
|
|
5969
|
+
return isValidDocumentEndpoint(finalEndpoint) ? jsx(DocumentRenderer, {
|
|
5970
|
+
documentMetadata: document,
|
|
5971
|
+
endpoint: finalEndpoint,
|
|
5972
|
+
maxHeight: maxHeight,
|
|
5973
|
+
domId: `${domId}-${index}`
|
|
5974
|
+
}, document.documentId) : null;
|
|
5975
|
+
})
|
|
5960
5976
|
}), jsx(Errors, {
|
|
5961
5977
|
id: errorMessageId,
|
|
5962
5978
|
errors: getErrors({
|
|
5963
|
-
dataSource
|
|
5964
|
-
endpoint,
|
|
5965
|
-
endpointKey
|
|
5979
|
+
dataSource
|
|
5966
5980
|
})
|
|
5967
5981
|
})]
|
|
5968
5982
|
});
|
|
@@ -5974,43 +5988,27 @@ DocumentPreview.config = {
|
|
|
5974
5988
|
name: 'Document preview',
|
|
5975
5989
|
create: (options = {}) => ({
|
|
5976
5990
|
label: 'Document preview',
|
|
5977
|
-
endpointKey: DEFAULT_ENDPOINT_KEY,
|
|
5978
5991
|
...options
|
|
5979
5992
|
})
|
|
5980
5993
|
};
|
|
5981
5994
|
|
|
5982
5995
|
// helpers /////////////////////////////
|
|
5983
5996
|
|
|
5984
|
-
const DOCUMENT_ID_PLACEHOLDER = '{documentId}';
|
|
5985
|
-
const DEFAULT_ENDPOINT_KEY = '=defaultDocumentsEndpointKey';
|
|
5986
|
-
|
|
5987
5997
|
/**
|
|
5988
5998
|
* @typedef GetErrorOptions
|
|
5989
5999
|
* @property {string|undefined} dataSource
|
|
5990
|
-
* @property {string|undefined} endpointKey
|
|
5991
|
-
* @property {string|null} endpoint
|
|
5992
6000
|
*
|
|
5993
6001
|
* @param {GetErrorOptions} options
|
|
5994
6002
|
* @returns {string[]}
|
|
5995
6003
|
*/
|
|
5996
6004
|
function getErrors(options) {
|
|
5997
6005
|
const {
|
|
5998
|
-
dataSource
|
|
5999
|
-
endpointKey,
|
|
6000
|
-
endpoint
|
|
6006
|
+
dataSource
|
|
6001
6007
|
} = options;
|
|
6002
6008
|
let errors = [];
|
|
6003
6009
|
if (!isString(dataSource) || dataSource.length < 1) {
|
|
6004
6010
|
errors.push('Document reference is not defined.');
|
|
6005
6011
|
}
|
|
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
6012
|
return errors;
|
|
6015
6013
|
}
|
|
6016
6014
|
|
|
@@ -6020,7 +6018,7 @@ function getErrors(options) {
|
|
|
6020
6018
|
* @returns boolean
|
|
6021
6019
|
*/
|
|
6022
6020
|
function isValidDocumentEndpoint(endpoint) {
|
|
6023
|
-
return typeof endpoint === 'string' && URL.canParse(endpoint)
|
|
6021
|
+
return typeof endpoint === 'string' && URL.canParse(endpoint);
|
|
6024
6022
|
}
|
|
6025
6023
|
|
|
6026
6024
|
/**
|
|
@@ -6057,9 +6055,11 @@ function PdfRenderer(props) {
|
|
|
6057
6055
|
onError,
|
|
6058
6056
|
errorMessageId
|
|
6059
6057
|
} = props;
|
|
6058
|
+
/** @type {ReturnType<typeof import("preact/hooks").useState<null | string>>} */
|
|
6060
6059
|
const [pdfObjectUrl, setPdfObjectUrl] = useState(null);
|
|
6061
6060
|
const [hasError, setHasError] = useState(false);
|
|
6062
6061
|
useEffect(() => {
|
|
6062
|
+
/** @type {null | string} */
|
|
6063
6063
|
let objectUrl = null;
|
|
6064
6064
|
const fetchPdf = async () => {
|
|
6065
6065
|
try {
|
|
@@ -6085,7 +6085,7 @@ function PdfRenderer(props) {
|
|
|
6085
6085
|
};
|
|
6086
6086
|
}, [url, onError]);
|
|
6087
6087
|
return jsxs(Fragment, {
|
|
6088
|
-
children: [pdfObjectUrl ? jsx("embed", {
|
|
6088
|
+
children: [pdfObjectUrl !== null ? jsx("embed", {
|
|
6089
6089
|
src: pdfObjectUrl,
|
|
6090
6090
|
type: "application/pdf",
|
|
6091
6091
|
class: `fjs-${type}-pdf-viewer`
|
|
@@ -6119,11 +6119,6 @@ function DocumentRenderer(props) {
|
|
|
6119
6119
|
const [hasError, setHasError] = useState(false);
|
|
6120
6120
|
const ref = useRef(null);
|
|
6121
6121
|
const isInViewport = useInViewport(ref);
|
|
6122
|
-
const fullUrl = buildUrl({
|
|
6123
|
-
baseUrl: endpoint,
|
|
6124
|
-
documentId: documentMetadata.documentId,
|
|
6125
|
-
contentHash: documentMetadata.contentHash
|
|
6126
|
-
});
|
|
6127
6122
|
const singleDocumentContainerClassName = `fjs-${type}-single-document-container`;
|
|
6128
6123
|
const errorMessageId = `${domId}-error-message`;
|
|
6129
6124
|
const errorMessage = 'Unable to download document';
|
|
@@ -6136,11 +6131,11 @@ function DocumentRenderer(props) {
|
|
|
6136
6131
|
},
|
|
6137
6132
|
"aria-describedby": hasError ? errorMessageId : undefined,
|
|
6138
6133
|
children: [jsx("img", {
|
|
6139
|
-
src:
|
|
6134
|
+
src: endpoint,
|
|
6140
6135
|
alt: metadata.fileName,
|
|
6141
6136
|
class: `fjs-${type}-image`
|
|
6142
6137
|
}), jsx(DownloadButton, {
|
|
6143
|
-
endpoint:
|
|
6138
|
+
endpoint: endpoint,
|
|
6144
6139
|
fileName: metadata.fileName,
|
|
6145
6140
|
onDownloadError: () => {
|
|
6146
6141
|
setHasError(true);
|
|
@@ -6159,7 +6154,7 @@ function DocumentRenderer(props) {
|
|
|
6159
6154
|
},
|
|
6160
6155
|
"aria-describedby": hasError ? errorMessageId : undefined,
|
|
6161
6156
|
children: jsx(PdfRenderer, {
|
|
6162
|
-
url:
|
|
6157
|
+
url: endpoint,
|
|
6163
6158
|
fileName: metadata.fileName,
|
|
6164
6159
|
onError: () => setHasError(true),
|
|
6165
6160
|
errorMessageId: errorMessageId
|
|
@@ -6179,7 +6174,7 @@ function DocumentRenderer(props) {
|
|
|
6179
6174
|
errors: [errorMessage]
|
|
6180
6175
|
}) : null]
|
|
6181
6176
|
}), jsx(DownloadButton, {
|
|
6182
|
-
endpoint:
|
|
6177
|
+
endpoint: endpoint,
|
|
6183
6178
|
fileName: metadata.fileName,
|
|
6184
6179
|
onDownloadError: () => {
|
|
6185
6180
|
setHasError(true);
|
|
@@ -6259,27 +6254,18 @@ function useInViewport(ref) {
|
|
|
6259
6254
|
}
|
|
6260
6255
|
|
|
6261
6256
|
/**
|
|
6262
|
-
*
|
|
6263
|
-
*
|
|
6264
|
-
* @
|
|
6265
|
-
* @param {string} options.baseUrl
|
|
6266
|
-
* @param {string} options.documentId
|
|
6267
|
-
* @param {string} [options.contentHash]
|
|
6268
|
-
*
|
|
6269
|
-
* @returns {string}
|
|
6257
|
+
* @template T
|
|
6258
|
+
* @param {() => T} fn - Function to execute
|
|
6259
|
+
* @returns {T | null}
|
|
6270
6260
|
*/
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
const finalUrl = new URL(baseUrl.replace(DOCUMENT_ID_PLACEHOLDER, documentId));
|
|
6278
|
-
if (contentHash !== undefined) {
|
|
6279
|
-
finalUrl.searchParams.set('contentHash', contentHash);
|
|
6261
|
+
const tryCatch = fn => {
|
|
6262
|
+
try {
|
|
6263
|
+
return fn();
|
|
6264
|
+
} catch (error) {
|
|
6265
|
+
console.error(error);
|
|
6266
|
+
return null;
|
|
6280
6267
|
}
|
|
6281
|
-
|
|
6282
|
-
}
|
|
6268
|
+
};
|
|
6283
6269
|
|
|
6284
6270
|
/**
|
|
6285
6271
|
* This file must not be changed or exchanged.
|
|
@@ -6438,7 +6424,7 @@ class FormFields {
|
|
|
6438
6424
|
}
|
|
6439
6425
|
}
|
|
6440
6426
|
|
|
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', '
|
|
6427
|
+
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
6428
|
const TEMPLATE_PROPERTIES = ['alt', 'appearance.prefixAdorner', 'appearance.suffixAdorner', 'description', 'label', 'source', 'text', 'content', 'url', 'title'];
|
|
6443
6429
|
|
|
6444
6430
|
/**
|