@bpmn-io/form-js-viewer 1.24.0 → 1.25.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
@@ -39,7 +39,26 @@ const getFlavouredFeelVariableNames = (feelString, feelFlavour = 'expression', o
39
39
  // if using special depth accessors, use a more complex extraction
40
40
  return Array.from(_smartExtractVariableNames(node, depth, specialDepthAccessors));
41
41
  }
42
- if (depth === 0 && node.name === 'VariableName') return [node.variableName];
42
+ if (depth === 0 && node.name === 'VariableName') return [_cleanupVariableName(node.variableName)];
43
+
44
+ // skip function names - the function name is the only direct VariableName child of a
45
+ // FunctionInvocation (arguments are nested under Positional/NamedParameters), so drop it
46
+ if (node.name === 'FunctionInvocation') {
47
+ const args = node.children.filter(child => child.name !== 'VariableName');
48
+ return args.reduce((acc, child) => acc.concat(_unfoldVariables(child)), []);
49
+ }
50
+
51
+ // skip type names in instance of expressions
52
+ if (node.name === 'Type') {
53
+ return [];
54
+ }
55
+
56
+ // handle quantified (some...satisfies) and for expressions - exclude bound iteration variables
57
+ if (node.name === 'QuantifiedExpression' || node.name === 'ForExpression') {
58
+ const boundNames = _collectBoundVariableNames(node);
59
+ const variables = node.children.reduce((acc, child) => acc.concat(_unfoldVariables(child)), []);
60
+ return variables.filter(name => !boundNames.includes(name));
61
+ }
43
62
 
44
63
  // for any other kind of node, traverse its children and flatten the result
45
64
  if (node.children) {
@@ -164,6 +183,9 @@ const _buildSimpleFeelStructureTree = (parseTree, feelString) => {
164
183
  if (node.type.name === 'VariableName') {
165
184
  nodeRepresentation.variableName = feelString.slice(node.from, node.to);
166
185
  }
186
+ if (node.type.name === 'Name') {
187
+ nodeRepresentation.variableName = feelString.slice(node.from, node.to);
188
+ }
167
189
  stack.push(nodeRepresentation);
168
190
  },
169
191
  leave: () => {
@@ -213,6 +235,53 @@ const _extractFilterExpressions = tree => {
213
235
  return flattenedExpressionTree;
214
236
  };
215
237
 
238
+ /**
239
+ * FEEL keywords that may be incorrectly absorbed into variable names by the parser.
240
+ * For example, `variable1 not in (...)` parses as VariableName "variable1 not".
241
+ */
242
+ const FEEL_TRAILING_KEYWORDS = ['not'];
243
+
244
+ /**
245
+ * Cleans up a variable name by stripping trailing FEEL keywords that the parser
246
+ * may have incorrectly included as part of the variable name.
247
+ *
248
+ * @param {string} variableName - The raw variable name from the parse tree.
249
+ * @returns {string} The cleaned variable name.
250
+ */
251
+ const _cleanupVariableName = variableName => {
252
+ for (const keyword of FEEL_TRAILING_KEYWORDS) {
253
+ if (variableName.endsWith(' ' + keyword)) {
254
+ return variableName.slice(0, -(keyword.length + 1));
255
+ }
256
+ }
257
+ return variableName;
258
+ };
259
+
260
+ /**
261
+ * Collects the names of variables bound by iteration constructs (e.g. `for x in ...`, `some x in ...`).
262
+ * These are locally scoped and should be excluded from the extracted variable set.
263
+ *
264
+ * @param {Object} node - A QuantifiedExpression or ForExpression node.
265
+ * @returns {string[]} The bound variable names.
266
+ */
267
+ const _collectBoundVariableNames = node => {
268
+ const boundNames = [];
269
+ const collect = n => {
270
+ if (n.name === 'InExpression') {
271
+ // The Name node inside an InExpression is the bound iteration variable
272
+ const nameNode = n.children.find(child => child.name === 'Name');
273
+ if (nameNode && nameNode.variableName) {
274
+ boundNames.push(nameNode.variableName);
275
+ }
276
+ }
277
+ if (n.children) {
278
+ n.children.forEach(collect);
279
+ }
280
+ };
281
+ collect(node);
282
+ return boundNames;
283
+ };
284
+
216
285
  class FeelExpressionLanguage {
217
286
  constructor(eventBus) {
218
287
  this._eventBus = eventBus;
@@ -1871,10 +1940,13 @@ function Label(props) {
1871
1940
  class: classNames('fjs-form-field-label', {
1872
1941
  'fjs-incollapsible-label': !collapseOnEmpty
1873
1942
  }, props['class']),
1874
- children: [props.children, evaluatedLabel, required && jsx("span", {
1875
- class: "fjs-asterix",
1876
- "aria-hidden": true,
1877
- children: "*"
1943
+ children: [props.children, jsxs("span", {
1944
+ class: "fjs-label-content",
1945
+ children: [evaluatedLabel, required && jsx("span", {
1946
+ class: "fjs-asterix",
1947
+ "aria-hidden": true,
1948
+ children: "*"
1949
+ })]
1878
1950
  })]
1879
1951
  });
1880
1952
  }
@@ -6071,11 +6143,10 @@ function DocumentPreview(props) {
6071
6143
  if (!isValidDocumentEndpoint(finalEndpoint)) {
6072
6144
  return null;
6073
6145
  }
6074
- const requestInit = getDocumentRequestInit(documentEndpointBuilder, document);
6075
6146
  return jsx(DocumentRenderer, {
6076
6147
  documentMetadata: document,
6148
+ documentEndpointBuilder: documentEndpointBuilder,
6077
6149
  endpoint: finalEndpoint,
6078
- requestInit: requestInit,
6079
6150
  maxHeight: maxHeight,
6080
6151
  domId: `${domId}-${index}`
6081
6152
  }, document.documentId);
@@ -6257,9 +6328,9 @@ function ImageRenderer(props) {
6257
6328
  *
6258
6329
  * @param {Object} props
6259
6330
  * @param {DocumentMetadata} props.documentMetadata
6331
+ * @param {DocumentEndpointBuilder | null} props.documentEndpointBuilder
6260
6332
  * @param {string} props.endpoint
6261
6333
  * @param {string} props.domId
6262
- * @param {RequestInit|undefined} props.requestInit
6263
6334
  * @param {number|undefined} props.maxHeight
6264
6335
  *
6265
6336
  * @returns {import("preact").JSX.Element}
@@ -6267,10 +6338,10 @@ function ImageRenderer(props) {
6267
6338
  function DocumentRenderer(props) {
6268
6339
  const {
6269
6340
  documentMetadata,
6341
+ documentEndpointBuilder,
6270
6342
  endpoint,
6271
6343
  maxHeight,
6272
- domId,
6273
- requestInit
6344
+ domId
6274
6345
  } = props;
6275
6346
  const {
6276
6347
  metadata
@@ -6278,6 +6349,8 @@ function DocumentRenderer(props) {
6278
6349
  const [hasError, setHasError] = useState(false);
6279
6350
  const ref = useRef(null);
6280
6351
  const isInViewport = useInViewport(ref);
6352
+ const onError = useCallback(() => setHasError(true), []);
6353
+ const requestInit = useMemo(() => getDocumentRequestInit(documentEndpointBuilder, documentMetadata), [documentEndpointBuilder, documentMetadata]);
6281
6354
  const singleDocumentContainerClassName = `fjs-${type}-single-document-container`;
6282
6355
  const errorMessageId = `${domId}-error-message`;
6283
6356
  const errorMessage = 'Unable to download document';
@@ -6293,14 +6366,12 @@ function DocumentRenderer(props) {
6293
6366
  url: endpoint,
6294
6367
  alt: metadata.fileName,
6295
6368
  requestInit: requestInit,
6296
- onError: () => setHasError(true)
6369
+ onError: onError
6297
6370
  }), jsx(DownloadButton, {
6298
6371
  endpoint: endpoint,
6299
6372
  fileName: metadata.fileName,
6300
6373
  requestInit: requestInit,
6301
- onDownloadError: () => {
6302
- setHasError(true);
6303
- }
6374
+ onDownloadError: onError
6304
6375
  }), hasError ? jsx(Errors, {
6305
6376
  id: errorMessageId,
6306
6377
  errors: [errorMessage]
@@ -6318,7 +6389,7 @@ function DocumentRenderer(props) {
6318
6389
  url: endpoint,
6319
6390
  fileName: metadata.fileName,
6320
6391
  requestInit: requestInit,
6321
- onError: () => setHasError(true),
6392
+ onError: onError,
6322
6393
  errorMessageId: errorMessageId
6323
6394
  })
6324
6395
  });
@@ -6339,9 +6410,7 @@ function DocumentRenderer(props) {
6339
6410
  endpoint: endpoint,
6340
6411
  fileName: metadata.fileName,
6341
6412
  requestInit: requestInit,
6342
- onDownloadError: () => {
6343
- setHasError(true);
6344
- }
6413
+ onDownloadError: onError
6345
6414
  })]
6346
6415
  });
6347
6416
  }