@bpmn-io/form-js-viewer 1.14.0 → 1.14.1-alpha.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 CHANGED
@@ -927,7 +927,6 @@ function useDeepCompareMemoize(value) {
927
927
  * @enum { String }
928
928
  */
929
929
  const LOAD_STATES = {
930
- LOADING: 'loading',
931
930
  LOADED: 'loaded',
932
931
  ERROR: 'error'
933
932
  };
@@ -1138,6 +1137,9 @@ function _isElementScrollable(el) {
1138
1137
  return (overflowY === 'auto' || overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
1139
1138
  }
1140
1139
 
1140
+ const EMPTY_OBJECT = {};
1141
+ const EMPTY_ARRAY$2 = [];
1142
+
1141
1143
  /**
1142
1144
  * Custom hook to scroll an element within a scrollable container.
1143
1145
  *
@@ -1151,8 +1153,8 @@ function _isElementScrollable(el) {
1151
1153
  * @param {Array} [flagRefs] - An array of refs that are used as flags to control when to scroll.
1152
1154
  */
1153
1155
  function useScrollIntoView(scrolledElementRef, deps, scrollOptions, flagRefs) {
1154
- const _scrollOptions = scrollOptions;
1155
- const _flagRefs = flagRefs;
1156
+ const _scrollOptions = scrollOptions || EMPTY_OBJECT;
1157
+ const _flagRefs = flagRefs || EMPTY_ARRAY$2;
1156
1158
  hooks.useEffect(() => {
1157
1159
  // return early if flags are not raised, or component is not mounted
1158
1160
  if (minDash.some(_flagRefs, ref => !ref.current) || !scrolledElementRef.current) {
@@ -6061,6 +6063,59 @@ function useValidDocumentData(dataSource) {
6061
6063
  return data.filter(isValidDocument);
6062
6064
  }
6063
6065
 
6066
+ /**
6067
+ * @param {Object} props
6068
+ * @param {string} props.url
6069
+ * @param {string} props.fileName
6070
+ * @param {Function} props.onError
6071
+ * @param {string} props.errorMessageId
6072
+ * @returns {import("preact").JSX.Element}
6073
+ */
6074
+ function PdfRenderer(props) {
6075
+ const {
6076
+ url,
6077
+ onError,
6078
+ errorMessageId
6079
+ } = props;
6080
+ const [pdfObjectUrl, setPdfObjectUrl] = hooks.useState(null);
6081
+ const [hasError, setHasError] = hooks.useState(false);
6082
+ hooks.useEffect(() => {
6083
+ let objectUrl = null;
6084
+ const fetchPdf = async () => {
6085
+ try {
6086
+ const response = await fetch(url);
6087
+ if (!response.ok) {
6088
+ setHasError(true);
6089
+ onError();
6090
+ return;
6091
+ }
6092
+ const blob = await response.blob();
6093
+ objectUrl = URL.createObjectURL(blob);
6094
+ setPdfObjectUrl(objectUrl);
6095
+ } catch {
6096
+ setHasError(true);
6097
+ onError();
6098
+ }
6099
+ };
6100
+ fetchPdf();
6101
+ return () => {
6102
+ if (objectUrl) {
6103
+ URL.revokeObjectURL(objectUrl);
6104
+ }
6105
+ };
6106
+ }, [url, onError]);
6107
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
6108
+ children: [pdfObjectUrl ? jsxRuntime.jsx("embed", {
6109
+ src: pdfObjectUrl,
6110
+ type: "application/pdf",
6111
+ class: `fjs-${type}-pdf-viewer`
6112
+ }) : null, hasError ? jsxRuntime.jsx(Errors, {
6113
+ id: errorMessageId,
6114
+ errors: ['Unable to download document']
6115
+ }) : null]
6116
+ });
6117
+ }
6118
+
6064
6119
  /**
6065
6120
  *
6066
6121
  * @param {Object} props
@@ -6117,20 +6172,18 @@ function DocumentRenderer(props) {
6117
6172
  });
6118
6173
  }
6119
6174
  if (isContentTypePresent && metadata.contentType.toLowerCase() === 'application/pdf' && isInViewport) {
6120
- return jsxRuntime.jsxs("div", {
6175
+ return jsxRuntime.jsx("div", {
6121
6176
  class: singleDocumentContainerClassName,
6122
6177
  style: {
6123
6178
  maxHeight
6124
6179
  },
6125
6180
  "aria-describedby": hasError ? errorMessageId : undefined,
6126
- children: [jsxRuntime.jsx("embed", {
6127
- src: fullUrl,
6128
- type: "application/pdf",
6129
- class: `fjs-${type}-pdf-viewer`
6130
- }), hasError ? jsxRuntime.jsx(Errors, {
6131
- id: errorMessageId,
6132
- errors: [errorMessage]
6133
- }) : null]
6181
+ children: jsxRuntime.jsx(PdfRenderer, {
6182
+ url: fullUrl,
6183
+ fileName: metadata.fileName,
6184
+ onError: () => setHasError(true),
6185
+ errorMessageId: errorMessageId
6186
+ })
6134
6187
  });
6135
6188
  }
6136
6189
  return jsxRuntime.jsxs("div", {