@alfresco/adf-core 9.2.0-42220028337 → 9.2.0-42260146052
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.
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { isValid, parseISO, format, addDays } from 'date-fns';
|
|
1
|
+
import { isValid, parseISO, format, addDays, parse } from 'date-fns';
|
|
2
2
|
import { DateFnsUtils, FullNamePipe } from '@alfresco/adf-core';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { InjectionToken, signal, inject, Injectable, computed, DestroyRef } from '@angular/core';
|
|
5
|
+
import { Subject } from 'rxjs';
|
|
6
|
+
import { createMetadataKey, form, applyEach, hidden, readonly, disabled, metadata, REQUIRED, validate } from '@angular/forms/signals';
|
|
3
7
|
|
|
4
8
|
/*!
|
|
5
9
|
* @license
|
|
@@ -1404,6 +1408,859 @@ const withProcessVariableValue = (field, variables) => {
|
|
|
1404
1408
|
* limitations under the License.
|
|
1405
1409
|
*/
|
|
1406
1410
|
|
|
1411
|
+
/*!
|
|
1412
|
+
* @license
|
|
1413
|
+
* Copyright © 2005-2026 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
1414
|
+
*
|
|
1415
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1416
|
+
* you may not use this file except in compliance with the License.
|
|
1417
|
+
* You may obtain a copy of the License at
|
|
1418
|
+
*
|
|
1419
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1420
|
+
*
|
|
1421
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1422
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1423
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1424
|
+
* See the License for the specific language governing permissions and
|
|
1425
|
+
* limitations under the License.
|
|
1426
|
+
*/
|
|
1427
|
+
const FIELD_TYPE_DEFINITIONS = new InjectionToken('FIELD_TYPE_DEFINITIONS');
|
|
1428
|
+
const FieldTypeState = {
|
|
1429
|
+
Registered: 'registered',
|
|
1430
|
+
Announced: 'announced',
|
|
1431
|
+
Unknown: 'unknown'
|
|
1432
|
+
};
|
|
1433
|
+
/**
|
|
1434
|
+
* Registers field type definitions at startup. Definitions provided later replace earlier ones for the same type, so
|
|
1435
|
+
* an application can override a built-in field type.
|
|
1436
|
+
*
|
|
1437
|
+
* @param definitions the field type definitions
|
|
1438
|
+
* @returns the provider
|
|
1439
|
+
*/
|
|
1440
|
+
const provideFieldTypes = (...definitions) => ({
|
|
1441
|
+
provide: FIELD_TYPE_DEFINITIONS,
|
|
1442
|
+
useValue: definitions,
|
|
1443
|
+
multi: true
|
|
1444
|
+
});
|
|
1445
|
+
class FieldTypeRegistry {
|
|
1446
|
+
constructor() {
|
|
1447
|
+
this.registered = signal(new Map([...BUILT_IN_FIELD_TYPES, ...(inject(FIELD_TYPE_DEFINITIONS, { optional: true }) ?? []).flat()].map((definition) => [
|
|
1448
|
+
definition.type,
|
|
1449
|
+
definition
|
|
1450
|
+
])), ...(ngDevMode ? [{ debugName: "registered" }] : /* istanbul ignore next */ []));
|
|
1451
|
+
this.announced = signal(new Set(), ...(ngDevMode ? [{ debugName: "announced" }] : /* istanbul ignore next */ []));
|
|
1452
|
+
this.definitions = this.registered.asReadonly();
|
|
1453
|
+
}
|
|
1454
|
+
definitionFor(type) {
|
|
1455
|
+
return this.registered().get(type);
|
|
1456
|
+
}
|
|
1457
|
+
register(definition) {
|
|
1458
|
+
this.registered.update((current) => new Map(current).set(definition.type, definition));
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Marks field types as coming, for example listed by a plugin manifest whose code is still loading.
|
|
1462
|
+
*
|
|
1463
|
+
* @param types the field types
|
|
1464
|
+
*/
|
|
1465
|
+
announce(...types) {
|
|
1466
|
+
this.announced.update((current) => new Set([...current, ...types]));
|
|
1467
|
+
}
|
|
1468
|
+
stateOf(type) {
|
|
1469
|
+
return this.stateOfField({ type });
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Tells how a field can be rendered: registered (its own definition, or a custom widget handled by its value type),
|
|
1473
|
+
* announced (its definition is still loading) or unknown.
|
|
1474
|
+
*
|
|
1475
|
+
* @param field the field
|
|
1476
|
+
* @returns the field's type state
|
|
1477
|
+
*/
|
|
1478
|
+
stateOfField(field) {
|
|
1479
|
+
if (resolveFieldType(this, field)) {
|
|
1480
|
+
return FieldTypeState.Registered;
|
|
1481
|
+
}
|
|
1482
|
+
return this.announced().has(field.type) ? FieldTypeState.Announced : FieldTypeState.Unknown;
|
|
1483
|
+
}
|
|
1484
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: FieldTypeRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1485
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: FieldTypeRegistry, providedIn: 'root' }); }
|
|
1486
|
+
}
|
|
1487
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: FieldTypeRegistry, decorators: [{
|
|
1488
|
+
type: Injectable,
|
|
1489
|
+
args: [{ providedIn: 'root' }]
|
|
1490
|
+
}] });
|
|
1491
|
+
|
|
1492
|
+
/*!
|
|
1493
|
+
* @license
|
|
1494
|
+
* Copyright © 2005-2026 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
1495
|
+
*
|
|
1496
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1497
|
+
* you may not use this file except in compliance with the License.
|
|
1498
|
+
* You may obtain a copy of the License at
|
|
1499
|
+
*
|
|
1500
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1501
|
+
*
|
|
1502
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1503
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1504
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1505
|
+
* See the License for the specific language governing permissions and
|
|
1506
|
+
* limitations under the License.
|
|
1507
|
+
*/
|
|
1508
|
+
const SAVE = SystemOutcomeName.Save;
|
|
1509
|
+
const COMPLETE = SystemOutcomeName.Complete;
|
|
1510
|
+
const START_PROCESS = SystemOutcomeName.StartProcess;
|
|
1511
|
+
const isOutcomeShown = (outcome, { readOnly, showCompleteButton, showSaveButton }) => {
|
|
1512
|
+
if (!outcome.name) {
|
|
1513
|
+
return false;
|
|
1514
|
+
}
|
|
1515
|
+
if (outcome.name === COMPLETE) {
|
|
1516
|
+
return showCompleteButton;
|
|
1517
|
+
}
|
|
1518
|
+
if (outcome.name === START_PROCESS) {
|
|
1519
|
+
return false;
|
|
1520
|
+
}
|
|
1521
|
+
if (readOnly) {
|
|
1522
|
+
return outcome.isSelected;
|
|
1523
|
+
}
|
|
1524
|
+
return outcome.name === SAVE ? showSaveButton : true;
|
|
1525
|
+
};
|
|
1526
|
+
const isOutcomeEnabled = (outcome, formValid, { readOnly }) => !readOnly && (outcome.name === SAVE || outcome.skipValidation || formValid);
|
|
1527
|
+
|
|
1528
|
+
/*!
|
|
1529
|
+
* @license
|
|
1530
|
+
* Copyright © 2005-2026 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
1531
|
+
*
|
|
1532
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1533
|
+
* you may not use this file except in compliance with the License.
|
|
1534
|
+
* You may obtain a copy of the License at
|
|
1535
|
+
*
|
|
1536
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1537
|
+
*
|
|
1538
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1539
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1540
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1541
|
+
* See the License for the specific language governing permissions and
|
|
1542
|
+
* limitations under the License.
|
|
1543
|
+
*/
|
|
1544
|
+
const EXPRESSION = /\$\{[a-zA-Z0-9_.]+\}/g;
|
|
1545
|
+
const FIELD_PREFIX = 'field.';
|
|
1546
|
+
const VARIABLE_PREFIX = 'variable.';
|
|
1547
|
+
const REFERENCE = /^\$\{((?:field|variable)\.[a-zA-Z_$][a-zA-Z0-9_$]*)\}$/;
|
|
1548
|
+
const HTML_ENTITIES = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
1549
|
+
/**
|
|
1550
|
+
* Replaces the `${field.<id>}` and `${variable.<name>}` expressions in a text with the current values, as today's
|
|
1551
|
+
* form does. Any other expression resolves to its own text.
|
|
1552
|
+
*
|
|
1553
|
+
* @param text the text
|
|
1554
|
+
* @param source where field and variable values come from
|
|
1555
|
+
* @param options how values are formatted and escaped
|
|
1556
|
+
* @returns the text with its expressions resolved
|
|
1557
|
+
*/
|
|
1558
|
+
const resolveTextExpressions = (text, source, options = {}) => (text || '').replace(EXPRESSION, (expression) => {
|
|
1559
|
+
const resolved = resolveReference(expression, source);
|
|
1560
|
+
const shown = resolved.value === null || resolved.value === undefined ? '' : referenceText(resolved, options);
|
|
1561
|
+
return options.escapeHtml ? escapeHtml(shown) : shown;
|
|
1562
|
+
});
|
|
1563
|
+
const resolveReference = (expression, source) => {
|
|
1564
|
+
const reference = REFERENCE.exec(expression)?.[1];
|
|
1565
|
+
if (!reference) {
|
|
1566
|
+
return { value: expression };
|
|
1567
|
+
}
|
|
1568
|
+
if (reference.startsWith(FIELD_PREFIX)) {
|
|
1569
|
+
const field = source.field(reference.slice(FIELD_PREFIX.length));
|
|
1570
|
+
return field ?? { value: undefined };
|
|
1571
|
+
}
|
|
1572
|
+
return { value: source.variableValue(reference.slice(VARIABLE_PREFIX.length)) };
|
|
1573
|
+
};
|
|
1574
|
+
const referenceText = (resolved, { formatFieldValue }) => {
|
|
1575
|
+
if (!formatFieldValue) {
|
|
1576
|
+
return typeof resolved.value === 'string' ? resolved.value : JSON.stringify(resolved.value);
|
|
1577
|
+
}
|
|
1578
|
+
return 'definition' in resolved ? formatFieldValue(resolved.definition, resolved.value) : valueAsText(resolved.value);
|
|
1579
|
+
};
|
|
1580
|
+
const escapeHtml = (value) => value.replace(/[&<>"']/g, (character) => HTML_ENTITIES[character]);
|
|
1581
|
+
|
|
1582
|
+
/*!
|
|
1583
|
+
* @license
|
|
1584
|
+
* Copyright © 2005-2026 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
1585
|
+
*
|
|
1586
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1587
|
+
* you may not use this file except in compliance with the License.
|
|
1588
|
+
* You may obtain a copy of the License at
|
|
1589
|
+
*
|
|
1590
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1591
|
+
*
|
|
1592
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1593
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1594
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1595
|
+
* See the License for the specific language governing permissions and
|
|
1596
|
+
* limitations under the License.
|
|
1597
|
+
*/
|
|
1598
|
+
const FIELD_OPERAND = 'field';
|
|
1599
|
+
const VARIABLE_OPERAND = 'variable';
|
|
1600
|
+
const VALUE_OPERAND = 'value';
|
|
1601
|
+
const evaluateVisibilityCondition = (condition, source) => {
|
|
1602
|
+
const left = leftOperand(condition);
|
|
1603
|
+
if (!condition || !(left.type || left.value) || left.value === 'null') {
|
|
1604
|
+
return true;
|
|
1605
|
+
}
|
|
1606
|
+
return combineResults(evaluateEachCondition(condition, source));
|
|
1607
|
+
};
|
|
1608
|
+
const evaluateEachCondition = (condition, source) => {
|
|
1609
|
+
const evaluated = [];
|
|
1610
|
+
let current = condition;
|
|
1611
|
+
while (current) {
|
|
1612
|
+
const result = evaluateOperator(leftValue(current, source), rightValue(current, source), current.operator);
|
|
1613
|
+
evaluated.push({ result: !!result, nextOperator: current.nextConditionOperator ?? '' });
|
|
1614
|
+
current = current.nextCondition?.operator ? current.nextCondition : null;
|
|
1615
|
+
}
|
|
1616
|
+
return evaluated;
|
|
1617
|
+
};
|
|
1618
|
+
const combineResults = (conditions) => {
|
|
1619
|
+
const orTerms = [];
|
|
1620
|
+
let term = conditions[0].result;
|
|
1621
|
+
for (let index = 1; index < conditions.length; index++) {
|
|
1622
|
+
const joining = conditions[index - 1].nextOperator;
|
|
1623
|
+
const next = conditions[index].result;
|
|
1624
|
+
if (joining === 'and') {
|
|
1625
|
+
term = term && next;
|
|
1626
|
+
}
|
|
1627
|
+
else if (joining === 'and-not') {
|
|
1628
|
+
term = term && !next;
|
|
1629
|
+
}
|
|
1630
|
+
else if (joining === 'or') {
|
|
1631
|
+
orTerms.push(term);
|
|
1632
|
+
term = next;
|
|
1633
|
+
}
|
|
1634
|
+
else if (joining === 'or-not') {
|
|
1635
|
+
orTerms.push(term);
|
|
1636
|
+
term = !next;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
orTerms.push(term);
|
|
1640
|
+
return orTerms.some(Boolean);
|
|
1641
|
+
};
|
|
1642
|
+
const leftOperand = (condition) => {
|
|
1643
|
+
if (!condition) {
|
|
1644
|
+
return { type: null, value: null };
|
|
1645
|
+
}
|
|
1646
|
+
const value = hasText(condition.leftValue) ? condition.leftValue : condition.leftFormFieldId || condition.leftRestResponseId || null;
|
|
1647
|
+
return { type: leftOperandType(condition), value };
|
|
1648
|
+
};
|
|
1649
|
+
/**
|
|
1650
|
+
* Returns what the left side of a condition reads, as today's form decides it: a field or a variable named by the
|
|
1651
|
+
* older id properties, else the condition's own left type.
|
|
1652
|
+
*
|
|
1653
|
+
* @param condition the condition
|
|
1654
|
+
* @returns the left operand type, `null` when the condition names none
|
|
1655
|
+
*/
|
|
1656
|
+
const leftOperandType = (condition) => {
|
|
1657
|
+
if (condition.leftFormFieldId) {
|
|
1658
|
+
return FIELD_OPERAND;
|
|
1659
|
+
}
|
|
1660
|
+
if (condition.leftRestResponseId) {
|
|
1661
|
+
return VARIABLE_OPERAND;
|
|
1662
|
+
}
|
|
1663
|
+
return condition.leftType ?? null;
|
|
1664
|
+
};
|
|
1665
|
+
const rightOperand = (condition) => {
|
|
1666
|
+
const value = hasText(condition.rightValue) ? condition.rightValue : condition.rightFormFieldId || condition.rightRestResponseId || null;
|
|
1667
|
+
return { type: rightOperandType(condition), value };
|
|
1668
|
+
};
|
|
1669
|
+
/**
|
|
1670
|
+
* Returns what the right side of a condition reads, as today's form decides it: the condition's own right type, else a
|
|
1671
|
+
* plain value when it has one, else a variable or a field named by the older id properties.
|
|
1672
|
+
*
|
|
1673
|
+
* @param condition the condition
|
|
1674
|
+
* @returns the right operand type, `null` when the condition names none
|
|
1675
|
+
*/
|
|
1676
|
+
const rightOperandType = (condition) => {
|
|
1677
|
+
if (condition.rightType) {
|
|
1678
|
+
return condition.rightType;
|
|
1679
|
+
}
|
|
1680
|
+
if (condition.rightValue) {
|
|
1681
|
+
return VALUE_OPERAND;
|
|
1682
|
+
}
|
|
1683
|
+
if (condition.rightRestResponseId) {
|
|
1684
|
+
return VARIABLE_OPERAND;
|
|
1685
|
+
}
|
|
1686
|
+
return condition.rightFormFieldId ? FIELD_OPERAND : null;
|
|
1687
|
+
};
|
|
1688
|
+
const leftValue = (condition, source) => {
|
|
1689
|
+
const left = leftOperand(condition);
|
|
1690
|
+
if (left.type === VARIABLE_OPERAND) {
|
|
1691
|
+
return source.variableValue(operandName(left));
|
|
1692
|
+
}
|
|
1693
|
+
if (left.type !== FIELD_OPERAND) {
|
|
1694
|
+
return '';
|
|
1695
|
+
}
|
|
1696
|
+
const value = source.fieldValue(operandName(left));
|
|
1697
|
+
if (value !== undefined && value !== '') {
|
|
1698
|
+
return value;
|
|
1699
|
+
}
|
|
1700
|
+
return source.variableValue(operandName(left)) ?? value;
|
|
1701
|
+
};
|
|
1702
|
+
const rightValue = (condition, source) => {
|
|
1703
|
+
const right = rightOperand(condition);
|
|
1704
|
+
if (right.type === FIELD_OPERAND) {
|
|
1705
|
+
return source.fieldValue(operandName(right));
|
|
1706
|
+
}
|
|
1707
|
+
if (right.type === VARIABLE_OPERAND) {
|
|
1708
|
+
return source.variableValue(operandName(right));
|
|
1709
|
+
}
|
|
1710
|
+
const asDate = parse(operandName(right), 'yyyy-MM-dd', new Date());
|
|
1711
|
+
return isValid(asDate) ? `${format(asDate, 'yyyy-MM-dd')}T00:00:00.000Z` : right.value;
|
|
1712
|
+
};
|
|
1713
|
+
const evaluateOperator = (left, right, operator) => {
|
|
1714
|
+
switch (operator) {
|
|
1715
|
+
case '==':
|
|
1716
|
+
return comparedText(left) === comparedText(right);
|
|
1717
|
+
case '!=':
|
|
1718
|
+
return comparedText(left) !== comparedText(right);
|
|
1719
|
+
case '<':
|
|
1720
|
+
return asComparable(left) < asComparable(right);
|
|
1721
|
+
case '>':
|
|
1722
|
+
return asComparable(left) > asComparable(right);
|
|
1723
|
+
case '>=':
|
|
1724
|
+
return asComparable(left) >= asComparable(right);
|
|
1725
|
+
case '<=':
|
|
1726
|
+
return asComparable(left) <= asComparable(right);
|
|
1727
|
+
case 'empty':
|
|
1728
|
+
return left ? left === '' : true;
|
|
1729
|
+
case '!empty':
|
|
1730
|
+
return left ? left !== '' : false;
|
|
1731
|
+
case 'contains':
|
|
1732
|
+
return containsAll(left, right);
|
|
1733
|
+
case '!contains':
|
|
1734
|
+
return !containsAll(left, right);
|
|
1735
|
+
default:
|
|
1736
|
+
return undefined;
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
/**
|
|
1740
|
+
* Returns the field id, variable name or constant an operand names, as text.
|
|
1741
|
+
*
|
|
1742
|
+
* @param operand the operand
|
|
1743
|
+
* @returns the text, `'null'` for an operand that names nothing, as today's form reads it
|
|
1744
|
+
*/
|
|
1745
|
+
const operandName = (operand) => `${operand.value}`;
|
|
1746
|
+
/**
|
|
1747
|
+
* Turns a condition value into the text `==` and `!=` compare, as today's form does: a list as its items joined by
|
|
1748
|
+
* commas, so a multiple selection `['a']` equals `'a'`; a date as its text; any other object as JSON.
|
|
1749
|
+
*
|
|
1750
|
+
* @param value the condition value
|
|
1751
|
+
* @returns the text
|
|
1752
|
+
*/
|
|
1753
|
+
const comparedText = (value) => {
|
|
1754
|
+
if (isPrimitive(value)) {
|
|
1755
|
+
return `${value}`;
|
|
1756
|
+
}
|
|
1757
|
+
if (Array.isArray(value)) {
|
|
1758
|
+
return value.map(listItemText).join(',');
|
|
1759
|
+
}
|
|
1760
|
+
if (value instanceof Date) {
|
|
1761
|
+
return value.toString();
|
|
1762
|
+
}
|
|
1763
|
+
return JSON.stringify(value) ?? '';
|
|
1764
|
+
};
|
|
1765
|
+
const listItemText = (item) => (item === null || item === undefined ? '' : comparedText(item));
|
|
1766
|
+
const isPrimitive = (value) => value === null || (typeof value !== 'object' && typeof value !== 'function' && typeof value !== 'symbol');
|
|
1767
|
+
/**
|
|
1768
|
+
* Lets two condition values be compared as JavaScript compares them, as today's form does: numbers as numbers, texts
|
|
1769
|
+
* (such as ISO dates) as texts.
|
|
1770
|
+
*
|
|
1771
|
+
* @param value the condition value
|
|
1772
|
+
* @returns the value, typed for comparison
|
|
1773
|
+
*/
|
|
1774
|
+
const asComparable = (value) => value;
|
|
1775
|
+
const containsAll = (left, right) => Array.isArray(left) && Array.isArray(right) && right.every((element) => left.includes(element));
|
|
1776
|
+
const hasText = (value) => value !== null && value !== undefined && `${value}` !== '';
|
|
1777
|
+
|
|
1778
|
+
/*!
|
|
1779
|
+
* @license
|
|
1780
|
+
* Copyright © 2005-2026 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
1781
|
+
*
|
|
1782
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1783
|
+
* you may not use this file except in compliance with the License.
|
|
1784
|
+
* You may obtain a copy of the License at
|
|
1785
|
+
*
|
|
1786
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1787
|
+
*
|
|
1788
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1789
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1790
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1791
|
+
* See the License for the specific language governing permissions and
|
|
1792
|
+
* limitations under the License.
|
|
1793
|
+
*/
|
|
1794
|
+
const TYPED_VALUE_FORMATTING = createMetadataKey();
|
|
1795
|
+
const LOCALE_AMOUNTS = createMetadataKey();
|
|
1796
|
+
|
|
1797
|
+
/*!
|
|
1798
|
+
* @license
|
|
1799
|
+
* Copyright © 2005-2026 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
1800
|
+
*
|
|
1801
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1802
|
+
* you may not use this file except in compliance with the License.
|
|
1803
|
+
* You may obtain a copy of the License at
|
|
1804
|
+
*
|
|
1805
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1806
|
+
*
|
|
1807
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1808
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1809
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1810
|
+
* See the License for the specific language governing permissions and
|
|
1811
|
+
* limitations under the License.
|
|
1812
|
+
*/
|
|
1813
|
+
const SignalFormEventType = {
|
|
1814
|
+
Click: 'click',
|
|
1815
|
+
RowCountChanged: 'onRowCountChanged',
|
|
1816
|
+
DataRefreshed: 'dataRefreshed'
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
/*!
|
|
1820
|
+
* @license
|
|
1821
|
+
* Copyright © 2005-2026 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
1822
|
+
*
|
|
1823
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1824
|
+
* you may not use this file except in compliance with the License.
|
|
1825
|
+
* You may obtain a copy of the License at
|
|
1826
|
+
*
|
|
1827
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1828
|
+
*
|
|
1829
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1830
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1831
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1832
|
+
* See the License for the specific language governing permissions and
|
|
1833
|
+
* limitations under the License.
|
|
1834
|
+
*/
|
|
1835
|
+
class SignalForm {
|
|
1836
|
+
constructor(definition, options, injector, fieldTypes = BUILT_IN_FIELD_TYPE_RESOLVER) {
|
|
1837
|
+
this.definition = definition;
|
|
1838
|
+
this.options = options;
|
|
1839
|
+
this.fieldTypes = fieldTypes;
|
|
1840
|
+
this.overrides = signal({ visible: {}, disabled: {}, required: {}, outcomes: {} }, ...(ngDevMode ? [{ debugName: "overrides" }] : /* istanbul ignore next */ []));
|
|
1841
|
+
this.eventStream = new Subject();
|
|
1842
|
+
this.outcomeRequestStream = new Subject();
|
|
1843
|
+
this.runtimeVariables = signal({}, ...(ngDevMode ? [{ debugName: "runtimeVariables" }] : /* istanbul ignore next */ []));
|
|
1844
|
+
this.allErrorsRequested = signal(false, ...(ngDevMode ? [{ debugName: "allErrorsRequested" }] : /* istanbul ignore next */ []));
|
|
1845
|
+
this.refreshedProcessVariables = signal([], ...(ngDevMode ? [{ debugName: "refreshedProcessVariables" }] : /* istanbul ignore next */ []));
|
|
1846
|
+
this.nextRowKey = 0;
|
|
1847
|
+
this.events = this.eventStream.asObservable();
|
|
1848
|
+
this.outcomeRequests = this.outcomeRequestStream.asObservable();
|
|
1849
|
+
this.allErrorsShown = this.allErrorsRequested.asReadonly();
|
|
1850
|
+
this.fields = new Map(definition.fields.map((field) => [field.id, field]));
|
|
1851
|
+
this.sections = new Map(definition.sections.map((section) => [section.id, section]));
|
|
1852
|
+
this.tabs = new Map(definition.tabs.map((tab) => [tab.id, tab]));
|
|
1853
|
+
this.values = signal({
|
|
1854
|
+
fields: Object.fromEntries(definition.fields.map((field) => [field.id, structuredClone(field.initialValue ?? null)])),
|
|
1855
|
+
sections: Object.fromEntries(definition.sections.map((section) => [section.id, this.startingRows(section)]))
|
|
1856
|
+
}, ...(ngDevMode ? [{ debugName: "values" }] : /* istanbul ignore next */ []));
|
|
1857
|
+
this.initialRows = signal(Object.fromEntries(definition.sections.map((section) => [
|
|
1858
|
+
section.id,
|
|
1859
|
+
[...Array(section.savedRows.length || section.initialRows).keys()].map((index) => index < section.initialRows)
|
|
1860
|
+
])), ...(ngDevMode ? [{ debugName: "initialRows" }] : /* istanbul ignore next */ []));
|
|
1861
|
+
this.keys = signal(Object.fromEntries(definition.sections.map((section) => [section.id, this.newRowKeys(this.values().sections[section.id].length)])), ...(ngDevMode ? [{ debugName: "keys" }] : /* istanbul ignore next */ []));
|
|
1862
|
+
this.rowCounts = new Map(definition.sections.map((section) => [section.id, computed(() => this.values().sections[section.id].length)]));
|
|
1863
|
+
this.submittedValues = computed(() => toSubmittedValues(this.fields, this.sections, this.values(), this.fieldTypes), ...(ngDevMode ? [{ debugName: "submittedValues" }] : /* istanbul ignore next */ []));
|
|
1864
|
+
this.fieldTree = form(this.values, (root) => this.applyRules(root), { injector });
|
|
1865
|
+
this.valid = computed(() => this.fieldTree().valid(), ...(ngDevMode ? [{ debugName: "valid" }] : /* istanbul ignore next */ []));
|
|
1866
|
+
this.visibleTabs = computed(() => definition.tabs.filter((tab) => this.isTabVisible(tab.id)), ...(ngDevMode ? [{ debugName: "visibleTabs" }] : /* istanbul ignore next */ []));
|
|
1867
|
+
injector.get(DestroyRef).onDestroy(() => {
|
|
1868
|
+
this.eventStream.complete();
|
|
1869
|
+
this.outcomeRequestStream.complete();
|
|
1870
|
+
});
|
|
1871
|
+
}
|
|
1872
|
+
get readOnly() {
|
|
1873
|
+
return !!this.options.readOnly;
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Whether a feature being rolled out is on for this form. Read inside a computed or a template, it follows a
|
|
1877
|
+
* feature given as a signal.
|
|
1878
|
+
*
|
|
1879
|
+
* @param feature the feature
|
|
1880
|
+
* @returns `true` when the feature is on
|
|
1881
|
+
*/
|
|
1882
|
+
isFeatureOn(feature) {
|
|
1883
|
+
const setting = this.options.features?.[feature];
|
|
1884
|
+
return typeof setting === 'function' ? setting() : !!setting;
|
|
1885
|
+
}
|
|
1886
|
+
fieldDefinition(fieldId, sectionId) {
|
|
1887
|
+
return sectionId ? this.sections.get(sectionId)?.fields.find((field) => field.id === fieldId) : this.fields.get(fieldId);
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Returns a field's Signal Forms node. A row field's node changes when rows are added or removed, so read inside a
|
|
1891
|
+
* computed or a template, it follows the row it addresses.
|
|
1892
|
+
*
|
|
1893
|
+
* @param fieldId the field
|
|
1894
|
+
* @param row the repeatable section row, for a field of a repeatable section
|
|
1895
|
+
* @returns the field's node, `undefined` for a row that no longer exists
|
|
1896
|
+
*/
|
|
1897
|
+
fieldNode(fieldId, row) {
|
|
1898
|
+
if (!row) {
|
|
1899
|
+
return this.fieldTree.fields[fieldId];
|
|
1900
|
+
}
|
|
1901
|
+
this.rowCount(row.sectionId);
|
|
1902
|
+
return this.fieldTree.sections[row.sectionId][row.index]?.[fieldId];
|
|
1903
|
+
}
|
|
1904
|
+
isLayoutElementVisible(element, row) {
|
|
1905
|
+
return this.isElementVisible(element.id, element.visibilityCondition, row);
|
|
1906
|
+
}
|
|
1907
|
+
isTabVisible(tabId) {
|
|
1908
|
+
const tab = tabId ? this.tabs.get(tabId) : undefined;
|
|
1909
|
+
return !tab || this.isConditionMet(tab.visibilityCondition);
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Whether a field is shown: its own condition, its tab and every layout element around it. In a repeatable
|
|
1913
|
+
* section row, conditions read the row's own fields first.
|
|
1914
|
+
*
|
|
1915
|
+
* @param field the field
|
|
1916
|
+
* @param row the repeatable section row the field is in, if any
|
|
1917
|
+
* @returns `true` when the field is shown
|
|
1918
|
+
*/
|
|
1919
|
+
isOnScreen(field, row) {
|
|
1920
|
+
return (this.isElementVisible(field.id, field.visibilityCondition, row) &&
|
|
1921
|
+
this.isTabVisible(field.tabId) &&
|
|
1922
|
+
field.ancestors.every((ancestor) => this.isElementVisible(ancestor.id, ancestor.visibilityCondition, row)));
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Whether a field is read-only: the whole form is, the field is (by its definition or a rule), or, for a field of
|
|
1926
|
+
* a repeatable section row, its section is. A section made editable again leaves each field as it is on its own.
|
|
1927
|
+
*
|
|
1928
|
+
* @param field the field
|
|
1929
|
+
* @param row the repeatable section row the field is in, if any
|
|
1930
|
+
* @returns `true` when the field is read-only
|
|
1931
|
+
*/
|
|
1932
|
+
isReadOnly(field, row) {
|
|
1933
|
+
return !!this.options.readOnly || (this.overrides().disabled[field.id] ?? field.readOnly) || (!!row && this.isSectionReadOnly(row.sectionId));
|
|
1934
|
+
}
|
|
1935
|
+
/**
|
|
1936
|
+
* Whether a repeatable section is read-only, by the form, its definition or a rule: its rows can't be added or
|
|
1937
|
+
* removed, and their fields are read-only.
|
|
1938
|
+
*
|
|
1939
|
+
* @param sectionId the repeatable section
|
|
1940
|
+
* @returns `true` when the section is read-only
|
|
1941
|
+
*/
|
|
1942
|
+
isSectionReadOnly(sectionId) {
|
|
1943
|
+
return !!this.options.readOnly || (this.overrides().disabled[sectionId] ?? this.sections.get(sectionId).readOnly);
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Resolves the `${field.<id>}` and `${variable.<name>}` expressions in a text with the current values. Read inside
|
|
1947
|
+
* a computed or a template, the result follows the values it depends on.
|
|
1948
|
+
*
|
|
1949
|
+
* @param text the text
|
|
1950
|
+
* @param options how the values are shown: typed values formatted as text, HTML-escaped
|
|
1951
|
+
* @returns the resolved text
|
|
1952
|
+
*/
|
|
1953
|
+
resolveText(text, options = {}) {
|
|
1954
|
+
return resolveTextExpressions(text, {
|
|
1955
|
+
field: (fieldId) => {
|
|
1956
|
+
const definition = this.fields.get(fieldId);
|
|
1957
|
+
return definition && { definition, value: this.values().fields[fieldId] };
|
|
1958
|
+
},
|
|
1959
|
+
variableValue: (identifier) => this.variableValue(identifier)
|
|
1960
|
+
}, {
|
|
1961
|
+
escapeHtml: options.escapeHtml,
|
|
1962
|
+
formatFieldValue: options.formatValues ? (definition, value) => this.displayValue(definition, value) : undefined
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Returns the text shown for a field value, by the field type's own formatter when it has one (options, people and
|
|
1967
|
+
* groups by name).
|
|
1968
|
+
*
|
|
1969
|
+
* @param definition the field
|
|
1970
|
+
* @param value the value
|
|
1971
|
+
* @returns the text
|
|
1972
|
+
*/
|
|
1973
|
+
displayValue(definition, value) {
|
|
1974
|
+
return displayFieldValue(this.fieldTypes, definition, value);
|
|
1975
|
+
}
|
|
1976
|
+
isOutcomeConditionMet(outcome) {
|
|
1977
|
+
return this.overrides().outcomes[outcome.id] ?? this.isConditionMet(outcome.visibilityCondition);
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Whether a visible tab holds a field, or a repeatable section row, that fails validation.
|
|
1981
|
+
*
|
|
1982
|
+
* @param tabId the tab
|
|
1983
|
+
* @returns `true` when the tab is visible and has an invalid field
|
|
1984
|
+
*/
|
|
1985
|
+
hasTabErrors(tabId) {
|
|
1986
|
+
return (this.isTabVisible(tabId) &&
|
|
1987
|
+
(this.definition.fields.some((field) => field.tabId === tabId && !this.isFieldValid(field.id)) ||
|
|
1988
|
+
this.definition.sections.some((section) => section.tabId === tabId && !this.fieldTree.sections[section.id]().valid())));
|
|
1989
|
+
}
|
|
1990
|
+
isFieldValid(fieldId, row) {
|
|
1991
|
+
return row ? this.fieldTree.sections[row.sectionId][row.index][fieldId]().valid() : this.fieldTree.fields[fieldId]().valid();
|
|
1992
|
+
}
|
|
1993
|
+
/**
|
|
1994
|
+
* Returns a stable key per row of a repeatable section, kept while the row exists, to track rows when rendering
|
|
1995
|
+
* them: removing a row then removes only that row's views.
|
|
1996
|
+
*
|
|
1997
|
+
* @param sectionId the repeatable section
|
|
1998
|
+
* @returns the row keys, in row order
|
|
1999
|
+
*/
|
|
2000
|
+
rowKeys(sectionId) {
|
|
2001
|
+
return this.keys()[sectionId];
|
|
2002
|
+
}
|
|
2003
|
+
rowCount(sectionId) {
|
|
2004
|
+
return this.rowCounts.get(sectionId)();
|
|
2005
|
+
}
|
|
2006
|
+
/**
|
|
2007
|
+
* Reads a value given as JSON, for example by a form rule, the way the field's type reads its saved value: a date
|
|
2008
|
+
* text becomes a date, a multi-select takes its options. The field's definition is left as it is.
|
|
2009
|
+
*
|
|
2010
|
+
* @param fieldId the field
|
|
2011
|
+
* @param value the JSON value
|
|
2012
|
+
* @param row the repeatable section row, for a field of a repeatable section
|
|
2013
|
+
* @returns the value the field holds for it
|
|
2014
|
+
*/
|
|
2015
|
+
readValue(fieldId, value, row) {
|
|
2016
|
+
const definition = this.fieldDefinition(fieldId, row?.sectionId);
|
|
2017
|
+
return definition ? readValueForField({ ...definition, options: [...definition.options] }, value, this.fieldTypes) : toFieldValue(value);
|
|
2018
|
+
}
|
|
2019
|
+
setValue(fieldId, value, row) {
|
|
2020
|
+
if (!row) {
|
|
2021
|
+
this.values.update((model) => ({ ...model, fields: { ...model.fields, [fieldId]: value } }));
|
|
2022
|
+
return;
|
|
2023
|
+
}
|
|
2024
|
+
this.updateRows(row.sectionId, (rows) => rows.map((current, index) => (index === row.index ? { ...current, [fieldId]: value } : current)));
|
|
2025
|
+
}
|
|
2026
|
+
canAddRow(sectionId) {
|
|
2027
|
+
const { maxRows } = this.sections.get(sectionId);
|
|
2028
|
+
return !maxRows || this.rowCount(sectionId) < maxRows;
|
|
2029
|
+
}
|
|
2030
|
+
canRemoveRow(sectionId, index) {
|
|
2031
|
+
return !this.initialRows()[sectionId][index] || !!this.sections.get(sectionId).rowOptions.allowInitialRowsDelete;
|
|
2032
|
+
}
|
|
2033
|
+
addRow(sectionId) {
|
|
2034
|
+
if (!this.canAddRow(sectionId) || this.isSectionReadOnly(sectionId)) {
|
|
2035
|
+
return;
|
|
2036
|
+
}
|
|
2037
|
+
const section = this.sections.get(sectionId);
|
|
2038
|
+
this.updateRows(sectionId, (rows) => [...rows, this.emptyRow(section)]);
|
|
2039
|
+
this.initialRows.update((current) => ({ ...current, [sectionId]: [...current[sectionId], false] }));
|
|
2040
|
+
this.keys.update((current) => ({ ...current, [sectionId]: [...current[sectionId], ...this.newRowKeys(1)] }));
|
|
2041
|
+
this.notify({ type: SignalFormEventType.RowCountChanged, fieldId: sectionId });
|
|
2042
|
+
}
|
|
2043
|
+
removeRow(sectionId, index) {
|
|
2044
|
+
if (this.isSectionReadOnly(sectionId)) {
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
const withoutRow = (items) => [...items.slice(0, index), ...items.slice(index + 1)];
|
|
2048
|
+
this.updateRows(sectionId, withoutRow);
|
|
2049
|
+
this.initialRows.update((current) => ({ ...current, [sectionId]: withoutRow(current[sectionId]) }));
|
|
2050
|
+
this.keys.update((current) => ({ ...current, [sectionId]: withoutRow(current[sectionId]) }));
|
|
2051
|
+
this.notify({ type: SignalFormEventType.RowCountChanged, fieldId: sectionId });
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* Sets the values the host refreshed (for example a task's data after an update), keyed as saved values are: by
|
|
2055
|
+
* field id or `variables.<name>`. Each is read by the field's type, as at load; a repeatable section's value gives
|
|
2056
|
+
* its rows. Only the given fields change, so what the user typed elsewhere stays. Constant-value types keep their
|
|
2057
|
+
* value.
|
|
2058
|
+
*
|
|
2059
|
+
* @param values the refreshed values
|
|
2060
|
+
*/
|
|
2061
|
+
refreshValues(values) {
|
|
2062
|
+
for (const field of this.refreshableFields()) {
|
|
2063
|
+
const saved = savedValueFor(values, field);
|
|
2064
|
+
if (saved !== undefined) {
|
|
2065
|
+
this.setValue(field.id, readValueForField(field, saved, this.fieldTypes));
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
for (const section of this.sections.values()) {
|
|
2069
|
+
const rows = values[section.id];
|
|
2070
|
+
if (Array.isArray(rows)) {
|
|
2071
|
+
this.replaceRows(section, rows);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
this.notify({ type: SignalFormEventType.DataRefreshed });
|
|
2075
|
+
}
|
|
2076
|
+
/**
|
|
2077
|
+
* Sets the given values only on fields still without one (an empty dropdown counts as without one), as today's
|
|
2078
|
+
* form does when values are requested only where missing.
|
|
2079
|
+
*
|
|
2080
|
+
* @param values the values, keyed as saved values are
|
|
2081
|
+
*/
|
|
2082
|
+
fillMissingValues(values) {
|
|
2083
|
+
for (const field of this.refreshableFields()) {
|
|
2084
|
+
const saved = savedValueFor(values, field);
|
|
2085
|
+
if (saved !== undefined && isMissingValue(this.values().fields[field.id])) {
|
|
2086
|
+
this.setValue(field.id, readValueForField(field, saved, this.fieldTypes));
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* Gives the form the process variables the host refreshed (for example a task's variables after an update). They
|
|
2092
|
+
* come before the form's own process variables, matched by id or name; conditions reading them follow.
|
|
2093
|
+
*
|
|
2094
|
+
* @param processVariables the refreshed process variables
|
|
2095
|
+
*/
|
|
2096
|
+
refreshProcessVariables(processVariables) {
|
|
2097
|
+
this.refreshedProcessVariables.set(processVariables);
|
|
2098
|
+
}
|
|
2099
|
+
/**
|
|
2100
|
+
* Shows the errors of every field, including fields added later (repeatable section rows), as today's form does
|
|
2101
|
+
* when it validates on request (a rule's validate action, an outcome requested on an invalid form).
|
|
2102
|
+
*/
|
|
2103
|
+
showAllErrors() {
|
|
2104
|
+
this.allErrorsRequested.set(true);
|
|
2105
|
+
}
|
|
2106
|
+
setVisibility(fieldId, visible) {
|
|
2107
|
+
this.setOverride('visible', fieldId, visible);
|
|
2108
|
+
}
|
|
2109
|
+
setDisabled(fieldId, isDisabled) {
|
|
2110
|
+
this.setOverride('disabled', fieldId, isDisabled);
|
|
2111
|
+
}
|
|
2112
|
+
setRequired(fieldId, required) {
|
|
2113
|
+
this.setOverride('required', fieldId, required);
|
|
2114
|
+
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Shows or hides an outcome whatever its visibility condition, as a form rule does.
|
|
2117
|
+
*
|
|
2118
|
+
* @param outcomeId the outcome
|
|
2119
|
+
* @param visible whether the outcome is shown
|
|
2120
|
+
*/
|
|
2121
|
+
setOutcomeVisibility(outcomeId, visible) {
|
|
2122
|
+
this.setOverride('outcomes', outcomeId, visible);
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Asks the host to run an outcome as if it were clicked, as a form rule does to submit the form. The host checks
|
|
2126
|
+
* it as for a click: a read-only form ignores it, and an invalid form shows its errors instead.
|
|
2127
|
+
*
|
|
2128
|
+
* @param outcomeId the outcome
|
|
2129
|
+
* @returns `false` when the form has no such outcome
|
|
2130
|
+
*/
|
|
2131
|
+
requestOutcome(outcomeId) {
|
|
2132
|
+
const outcome = this.definition.outcomes.find((candidate) => candidate.id === outcomeId);
|
|
2133
|
+
if (outcome) {
|
|
2134
|
+
this.outcomeRequestStream.next(outcome);
|
|
2135
|
+
}
|
|
2136
|
+
return !!outcome;
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Tells the form's listeners that something happened on a field, for example a widget click.
|
|
2140
|
+
*
|
|
2141
|
+
* @param event the event
|
|
2142
|
+
*/
|
|
2143
|
+
notify(event) {
|
|
2144
|
+
this.eventStream.next(event);
|
|
2145
|
+
}
|
|
2146
|
+
setVariable(variableId, value) {
|
|
2147
|
+
const variable = findVariable(variableId, this.definition.variables);
|
|
2148
|
+
if (variable) {
|
|
2149
|
+
this.runtimeVariables.update((values) => ({ ...values, [variable.id ?? variable.name]: value }));
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
/**
|
|
2153
|
+
* Returns the value of a form or process variable, by id or name: the value a rule set, the process value the host
|
|
2154
|
+
* refreshed, or the variable's own value.
|
|
2155
|
+
*
|
|
2156
|
+
* @param identifier the variable id or name
|
|
2157
|
+
* @returns the value, `undefined` for an unknown variable
|
|
2158
|
+
*/
|
|
2159
|
+
variableValue(identifier) {
|
|
2160
|
+
return resolveVariableValue(identifier, this.definition.variables, this.runtimeVariables(), this.refreshedProcessVariables());
|
|
2161
|
+
}
|
|
2162
|
+
applyRules(root) {
|
|
2163
|
+
applyEach(root.fields, (field) => this.applyFieldRules(field, (id) => this.fields.get(id)));
|
|
2164
|
+
for (const section of this.sections.values()) {
|
|
2165
|
+
const sectionFields = new Map(section.fields.map((field) => [field.id, field]));
|
|
2166
|
+
applyEach(root.sections[section.id], (row) => applyEach(row, (field) => this.applyFieldRules(field, (id) => sectionFields.get(id))));
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
applyFieldRules(field, definitionOf) {
|
|
2170
|
+
hidden(field, (context) => !this.isOnScreen(definitionOf(context.key()), rowOf(context.pathKeys())));
|
|
2171
|
+
readonly(field, (context) => this.isReadOnly(definitionOf(context.key()), rowOf(context.pathKeys())));
|
|
2172
|
+
disabled(field, (context) => this.isReadOnly(definitionOf(context.key()), rowOf(context.pathKeys())));
|
|
2173
|
+
metadata(field, REQUIRED, (context) => this.withRequiredOverride(definitionOf(context.key())).required);
|
|
2174
|
+
metadata(field, TYPED_VALUE_FORMATTING, () => this.isFeatureOn('typedValueFormatting'));
|
|
2175
|
+
metadata(field, LOCALE_AMOUNTS, () => this.isFeatureOn('localeAmounts'));
|
|
2176
|
+
validate(field, (context) => {
|
|
2177
|
+
const definition = this.withRequiredOverride(definitionOf(context.key()));
|
|
2178
|
+
const typeValidators = resolveFieldType(this.fieldTypes, definition)?.definition.validators ?? [];
|
|
2179
|
+
const kind = firstValidationError(definition, context.value(), [...typeValidators, ...(this.options.validators ?? [])]);
|
|
2180
|
+
return kind ? validationError(kind, definition) : null;
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
withRequiredOverride(field) {
|
|
2184
|
+
const required = this.overrides().required[field.id];
|
|
2185
|
+
return required === undefined ? field : { ...field, required };
|
|
2186
|
+
}
|
|
2187
|
+
isElementVisible(id, condition, row) {
|
|
2188
|
+
return this.overrides().visible[id] ?? this.isConditionMet(condition, row);
|
|
2189
|
+
}
|
|
2190
|
+
isConditionMet(condition, row) {
|
|
2191
|
+
return evaluateVisibilityCondition(condition, {
|
|
2192
|
+
fieldValue: (reference) => {
|
|
2193
|
+
const inRow = row && this.rowOperandValue(reference, row);
|
|
2194
|
+
return inRow ? inRow.value : this.operandValue(reference);
|
|
2195
|
+
},
|
|
2196
|
+
variableValue: (identifier) => this.variableValue(identifier)
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
operandValue(reference) {
|
|
2200
|
+
const id = matchingId(reference, this.fields.keys());
|
|
2201
|
+
if (!id || !this.isFieldValid(id)) {
|
|
2202
|
+
return undefined;
|
|
2203
|
+
}
|
|
2204
|
+
return fieldOperandValue(this.fields.get(id), reference, this.submittedValues()[id], this.values().fields[id]);
|
|
2205
|
+
}
|
|
2206
|
+
rowOperandValue(reference, row) {
|
|
2207
|
+
const section = this.sections.get(row.sectionId);
|
|
2208
|
+
const id = section &&
|
|
2209
|
+
matchingId(reference, section.fields.map((field) => field.id));
|
|
2210
|
+
if (!id) {
|
|
2211
|
+
return undefined;
|
|
2212
|
+
}
|
|
2213
|
+
const rowValues = this.values().sections[row.sectionId]?.[row.index];
|
|
2214
|
+
if (!rowValues || !this.isFieldValid(id, row)) {
|
|
2215
|
+
return { value: undefined };
|
|
2216
|
+
}
|
|
2217
|
+
const definition = section.fields.find((field) => field.id === id);
|
|
2218
|
+
return { value: fieldOperandValue(definition, reference, this.submittedRowValue(row, id), rowValues[id]) };
|
|
2219
|
+
}
|
|
2220
|
+
submittedRowValue(row, fieldId) {
|
|
2221
|
+
const rows = this.submittedValues()[row.sectionId];
|
|
2222
|
+
const submittedRow = Array.isArray(rows) ? rows[row.index] : undefined;
|
|
2223
|
+
return isRecord(submittedRow) ? toFieldValue(submittedRow[fieldId]) : undefined;
|
|
2224
|
+
}
|
|
2225
|
+
setOverride(kind, fieldId, enabled) {
|
|
2226
|
+
this.overrides.update((current) => ({ ...current, [kind]: { ...current[kind], [fieldId]: enabled } }));
|
|
2227
|
+
}
|
|
2228
|
+
newRowKeys(count) {
|
|
2229
|
+
return [...Array(count).keys()].map(() => this.nextRowKey++);
|
|
2230
|
+
}
|
|
2231
|
+
startingRows(section) {
|
|
2232
|
+
return section.savedRows.length
|
|
2233
|
+
? section.savedRows.map((saved) => ({ ...this.emptyRow(section), ...structuredClone(saved) }))
|
|
2234
|
+
: Array.from({ length: section.initialRows }, () => this.emptyRow(section));
|
|
2235
|
+
}
|
|
2236
|
+
refreshableFields() {
|
|
2237
|
+
return [...this.fields.values()].filter(isRefreshable);
|
|
2238
|
+
}
|
|
2239
|
+
replaceRows(section, savedRows) {
|
|
2240
|
+
const refreshableFields = section.fields.filter(isRefreshable);
|
|
2241
|
+
const rows = savedRows.map((saved) => ({ ...this.emptyRow(section), ...readSavedRow(refreshableFields, saved, this.fieldTypes) }));
|
|
2242
|
+
this.updateRows(section.id, () => rows);
|
|
2243
|
+
this.initialRows.update((current) => ({ ...current, [section.id]: [...rows.keys()].map((index) => index < section.initialRows) }));
|
|
2244
|
+
this.keys.update((current) => ({ ...current, [section.id]: this.newRowKeys(rows.length) }));
|
|
2245
|
+
}
|
|
2246
|
+
emptyRow(section) {
|
|
2247
|
+
return Object.fromEntries(section.fields.map((field) => [field.id, structuredClone(field.initialValue ?? null)]));
|
|
2248
|
+
}
|
|
2249
|
+
updateRows(sectionId, update) {
|
|
2250
|
+
this.values.update((model) => ({ ...model, sections: { ...model.sections, [sectionId]: update(model.sections[sectionId]) } }));
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
const PATTERN_ERROR = 'pattern';
|
|
2254
|
+
const SECTIONS_KEY = 'sections';
|
|
2255
|
+
const validationError = (kind, definition) => kind === PATTERN_ERROR && definition.customValidationMessage ? { kind, message: definition.customValidationMessage } : { kind };
|
|
2256
|
+
const matchingId = (reference, ids) => {
|
|
2257
|
+
const wanted = referencedFieldId(reference).toUpperCase();
|
|
2258
|
+
return [...ids].find((candidate) => candidate.toUpperCase() === wanted);
|
|
2259
|
+
};
|
|
2260
|
+
const rowOf = (pathKeys) => pathKeys[0] === SECTIONS_KEY ? { sectionId: pathKeys[1], index: Number(pathKeys[2]) } : undefined;
|
|
2261
|
+
const isRefreshable = (field) => !CONSTANT_VALUE_FIELD_TYPES.has(field.type);
|
|
2262
|
+
const isMissingValue = (value) => isBlank(value) || (Array.isArray(value) && value.length === 0) || (isRecord(value) && value['id'] === EMPTY_OPTION_ID);
|
|
2263
|
+
|
|
1407
2264
|
/*!
|
|
1408
2265
|
* @license
|
|
1409
2266
|
* Copyright © 2005-2026 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
@@ -1425,5 +2282,5 @@ const withProcessVariableValue = (field, variables) => {
|
|
|
1425
2282
|
* Generated bundle index. Do not edit.
|
|
1426
2283
|
*/
|
|
1427
2284
|
|
|
1428
|
-
export { BUILT_IN_FIELD_TYPES, BUILT_IN_FIELD_TYPE_RESOLVER, CONSTANT_VALUE_FIELD_TYPES, DEFAULT_EMPTY_OPTION, EMPTY_OPTION_ID, FormFieldType, LAYOUT_FIELD_TYPES, READ_ONLY_FIELD_TYPES, SystemOutcomeName, TYPEAHEAD_FIELD_TYPE, createFieldTypeResolver, fieldTypeAlias, parseFormJson, resolveFieldComponent, resolveFieldType };
|
|
2285
|
+
export { BUILT_IN_FIELD_TYPES, BUILT_IN_FIELD_TYPE_RESOLVER, CONSTANT_VALUE_FIELD_TYPES, DEFAULT_EMPTY_OPTION, EMPTY_OPTION_ID, FIELD_TYPE_DEFINITIONS, FieldTypeRegistry, FieldTypeState, FormFieldType, LAYOUT_FIELD_TYPES, LOCALE_AMOUNTS, READ_ONLY_FIELD_TYPES, SignalForm, SignalFormEventType, SystemOutcomeName, TYPEAHEAD_FIELD_TYPE, TYPED_VALUE_FORMATTING, createFieldTypeResolver, fieldTypeAlias, isOutcomeEnabled, isOutcomeShown, parseFormJson, provideFieldTypes, resolveFieldComponent, resolveFieldType };
|
|
1429
2286
|
//# sourceMappingURL=alfresco-adf-core-signal-form.mjs.map
|