@hmcts/ccd-case-ui-toolkit 4.7.0-rc.4 → 4.7.0-rc.5

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.umd.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @hmcts/ccd-case-ui-toolkit - Case UI Toolkit
3
- * @version v4.7.0-rc.4
3
+ * @version v4.7.0-rc.5
4
4
  * @link undefined
5
5
  * @license MIT
6
6
  */
@@ -28717,6 +28717,232 @@ var ConditionalShowFormDirective = /** @class */ (function () {
28717
28717
  exports.ConditionalShowFormDirective = ConditionalShowFormDirective;
28718
28718
 
28719
28719
 
28720
+ /***/ }),
28721
+
28722
+ /***/ 74015:
28723
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
28724
+
28725
+ "use strict";
28726
+
28727
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
28728
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28729
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28730
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
28731
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
28732
+ };
28733
+ var __metadata = (this && this.__metadata) || function (k, v) {
28734
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
28735
+ };
28736
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
28737
+ var core_1 = __webpack_require__(57208);
28738
+ var forms_1 = __webpack_require__(92985);
28739
+ var case_field_model_1 = __webpack_require__(13930);
28740
+ var conditional_show_model_1 = __webpack_require__(5369);
28741
+ var fields_utils_1 = __webpack_require__(40980);
28742
+ var conditional_show_registrar_service_1 = __webpack_require__(49532);
28743
+ var grey_bar_service_1 = __webpack_require__(100);
28744
+ var operators_1 = __webpack_require__(19443);
28745
+ var ConditionalShowDirective = /** @class */ (function () {
28746
+ function ConditionalShowDirective(el, fieldsUtils, registry, renderer, greyBarService) {
28747
+ this.el = el;
28748
+ this.fieldsUtils = fieldsUtils;
28749
+ this.registry = registry;
28750
+ this.renderer = renderer;
28751
+ this.greyBarService = greyBarService;
28752
+ this.contextFields = [];
28753
+ this.greyBarEnabled = false;
28754
+ }
28755
+ ConditionalShowDirective.prototype.ngAfterViewInit = function () {
28756
+ // Ensure this.caseField is actually a CaseField instance even if instantiated with {}
28757
+ // this.caseField = FieldsUtils.convertToCaseField(this.caseField);
28758
+ if (this.caseField.show_condition) {
28759
+ this.condition = conditional_show_model_1.ShowCondition.getInstance(this.caseField.show_condition);
28760
+ this.formGroup = this.formGroup || new forms_1.FormGroup({});
28761
+ this.complexFormGroup = this.complexFormGroup || new forms_1.FormGroup({});
28762
+ this.formField = this.complexFormGroup.get(this.caseField.id) || this.formGroup.get(this.caseField.id);
28763
+ this.updateVisibility(this.getCurrentPagesReadOnlyAndFormFieldValues());
28764
+ if (this.greyBarEnabled && this.greyBarService.wasToggledToShow(this.caseField.id)) {
28765
+ this.greyBarService.showGreyBar(this.caseField, this.el);
28766
+ }
28767
+ this.subscribeToFormChanges();
28768
+ this.registry.register(this);
28769
+ }
28770
+ };
28771
+ ConditionalShowDirective.prototype.refreshVisibility = function () {
28772
+ this.updateVisibility(this.getCurrentPagesReadOnlyAndFormFieldValues(), true);
28773
+ this.subscribeToFormChanges();
28774
+ };
28775
+ ConditionalShowDirective.prototype.ngOnDestroy = function () {
28776
+ this.unsubscribeFromFormChanges();
28777
+ };
28778
+ ConditionalShowDirective.prototype.subscribeToFormChanges = function () {
28779
+ var _this = this;
28780
+ this.unsubscribeFromFormChanges();
28781
+ this.formChangesSubscription = this.formGroup
28782
+ .valueChanges
28783
+ .pipe(operators_1.debounceTime(200))
28784
+ .subscribe(function (_) {
28785
+ var shown = _this.updateVisibility(_this.getCurrentPagesReadOnlyAndFormFieldValues());
28786
+ if (_this.greyBarEnabled && shown !== undefined) {
28787
+ _this.updateGreyBar(shown);
28788
+ }
28789
+ });
28790
+ };
28791
+ /**
28792
+ * returns whether the field visibility has changed, or undefined if not
28793
+ */
28794
+ ConditionalShowDirective.prototype.updateVisibility = function (fields, forced) {
28795
+ if (forced === void 0) { forced = false; }
28796
+ if (this.shouldToggleToHide(fields, forced)) {
28797
+ this.onHide();
28798
+ return false;
28799
+ }
28800
+ else if (this.shouldToggleToShow(fields)) {
28801
+ this.onShow();
28802
+ return true;
28803
+ }
28804
+ };
28805
+ ConditionalShowDirective.prototype.onHide = function () {
28806
+ if (this.formField) {
28807
+ this.unsubscribeFromFormChanges();
28808
+ this.formField.disable({ emitEvent: false });
28809
+ this.subscribeToFormChanges();
28810
+ }
28811
+ this.hideField();
28812
+ this.greyBarService.removeGreyBar(this.el);
28813
+ };
28814
+ ConditionalShowDirective.prototype.onShow = function () {
28815
+ if (this.formField) {
28816
+ this.unsubscribeFromFormChanges();
28817
+ this.formField.enable({ emitEvent: false });
28818
+ this.subscribeToFormChanges();
28819
+ }
28820
+ this.showField();
28821
+ if (this.formField) {
28822
+ this.checkHideShowCondition(this.caseField.id, this.formField);
28823
+ }
28824
+ };
28825
+ ConditionalShowDirective.prototype.hideField = function () {
28826
+ this.el.nativeElement.hidden = true;
28827
+ };
28828
+ ConditionalShowDirective.prototype.showField = function () {
28829
+ this.el.nativeElement.hidden = false;
28830
+ };
28831
+ ConditionalShowDirective.prototype.shouldToggleToHide = function (fields, forced) {
28832
+ return (!this.isHidden() || forced) && !this.condition.match(fields, this.buildPath());
28833
+ };
28834
+ ConditionalShowDirective.prototype.shouldToggleToShow = function (fields) {
28835
+ return this.isHidden() && this.condition.match(fields, this.buildPath());
28836
+ };
28837
+ ConditionalShowDirective.prototype.buildPath = function () {
28838
+ if (this.idPrefix) {
28839
+ return this.idPrefix + this.caseField.id;
28840
+ }
28841
+ return this.caseField.id;
28842
+ };
28843
+ ConditionalShowDirective.prototype.getCurrentPagesReadOnlyAndFormFieldValues = function () {
28844
+ var formFields = this.getFormFieldsValuesIncludingDisabled();
28845
+ return this.fieldsUtils.mergeCaseFieldsAndFormFields(this.contextFields, formFields);
28846
+ };
28847
+ ConditionalShowDirective.prototype.getFormFieldsValuesIncludingDisabled = function () {
28848
+ if (this.formGroupRawValue) {
28849
+ return this.formGroupRawValue;
28850
+ }
28851
+ this.formGroupRawValue = this.formGroup.getRawValue();
28852
+ return this.formGroupRawValue;
28853
+ };
28854
+ ConditionalShowDirective.prototype.isHidden = function () {
28855
+ return this.el.nativeElement.hidden;
28856
+ };
28857
+ ConditionalShowDirective.prototype.unsubscribeFromFormChanges = function () {
28858
+ if (this.formChangesSubscription) {
28859
+ this.formChangesSubscription.unsubscribe();
28860
+ }
28861
+ };
28862
+ // TODO This must be extracted to a generic service for traversing see RDM-2233
28863
+ ConditionalShowDirective.prototype.checkHideShowCondition = function (key, aControl) {
28864
+ var _this = this;
28865
+ if (aControl instanceof forms_1.FormArray) { // We're in a collection
28866
+ aControl.controls.forEach(function (formControl, i) {
28867
+ _this.checkHideShowCondition('' + i, formControl);
28868
+ });
28869
+ }
28870
+ else if (aControl instanceof forms_1.FormGroup) {
28871
+ if (aControl.get('value')) { // Complex Field
28872
+ var complexControl_1 = aControl.get('value');
28873
+ Object.keys(complexControl_1.controls).forEach(function (controlKey) {
28874
+ _this.checkHideShowCondition(controlKey, complexControl_1.get(controlKey));
28875
+ });
28876
+ }
28877
+ else if (aControl.controls) { // Special Field like AddressUK, AddressGlobal
28878
+ Object.keys(aControl.controls).forEach(function (controlKey) {
28879
+ _this.checkHideShowCondition(controlKey, aControl.get(controlKey));
28880
+ });
28881
+ }
28882
+ }
28883
+ else if (aControl instanceof forms_1.FormControl) { // FormControl
28884
+ if (aControl.invalid) {
28885
+ this.registry.refresh();
28886
+ }
28887
+ }
28888
+ };
28889
+ ConditionalShowDirective.prototype.updateGreyBar = function (shown) {
28890
+ if (shown) {
28891
+ this.greyBarService.addToggledToShow(this.caseField.id);
28892
+ this.greyBarService.showGreyBar(this.caseField, this.el);
28893
+ }
28894
+ else {
28895
+ this.greyBarService.removeToggledToShow(this.caseField.id);
28896
+ this.greyBarService.removeGreyBar(this.el);
28897
+ }
28898
+ };
28899
+ __decorate([
28900
+ core_1.Input(),
28901
+ __metadata("design:type", case_field_model_1.CaseField)
28902
+ ], ConditionalShowDirective.prototype, "caseField", void 0);
28903
+ __decorate([
28904
+ core_1.Input(),
28905
+ __metadata("design:type", String)
28906
+ ], ConditionalShowDirective.prototype, "idPrefix", void 0);
28907
+ __decorate([
28908
+ core_1.Input(),
28909
+ __metadata("design:type", Array)
28910
+ ], ConditionalShowDirective.prototype, "contextFields", void 0);
28911
+ __decorate([
28912
+ core_1.Input(),
28913
+ __metadata("design:type", forms_1.FormGroup)
28914
+ ], ConditionalShowDirective.prototype, "formGroup", void 0);
28915
+ __decorate([
28916
+ core_1.Input(),
28917
+ __metadata("design:type", Object)
28918
+ ], ConditionalShowDirective.prototype, "greyBarEnabled", void 0);
28919
+ __decorate([
28920
+ core_1.Input(),
28921
+ __metadata("design:type", forms_1.FormGroup)
28922
+ ], ConditionalShowDirective.prototype, "complexFormGroup", void 0);
28923
+ ConditionalShowDirective = __decorate([
28924
+ core_1.Directive({ selector: '[ccdConditionalShow]' })
28925
+ /** Hides and shows the host element based on the show condition if the condition is not empty. Works on read only fields and form fields.
28926
+ * The show condition is evaluated on all the fields of the page. i.e. read only and form fields. When a form field is hidden, if its
28927
+ * initial value was changed then the field is cleared. Otherwise the original value is kept and will display next time the field is
28928
+ * shown. Evaluation of the show condition includes disabled fields, which can be on their initial value or empty. Executes on the
28929
+ * host field initialization and when any field of the form changes.
28930
+ * Collaborates with the GreyBarService to show a vertical grey bar when a field initially hidden on the page is shown. When returning
28931
+ * to the page after the page has been left, the grey bar has to be redisplayed. If instead on initial page load the field renders as
28932
+ * initially shown, the grey bar is not displayed.
28933
+ */
28934
+ ,
28935
+ __metadata("design:paramtypes", [core_1.ElementRef,
28936
+ fields_utils_1.FieldsUtils,
28937
+ conditional_show_registrar_service_1.ConditionalShowRegistrarService,
28938
+ core_1.Renderer2,
28939
+ grey_bar_service_1.GreyBarService])
28940
+ ], ConditionalShowDirective);
28941
+ return ConditionalShowDirective;
28942
+ }());
28943
+ exports.ConditionalShowDirective = ConditionalShowDirective;
28944
+
28945
+
28720
28946
  /***/ }),
28721
28947
 
28722
28948
  /***/ 95844:
@@ -28732,6 +28958,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
28732
28958
  };
28733
28959
  Object.defineProperty(exports, "__esModule", ({ value: true }));
28734
28960
  var core_1 = __webpack_require__(57208);
28961
+ var conditional_show_directive_1 = __webpack_require__(74015);
28735
28962
  var fields_utils_1 = __webpack_require__(40980);
28736
28963
  var conditional_show_registrar_service_1 = __webpack_require__(49532);
28737
28964
  var grey_bar_service_1 = __webpack_require__(100);
@@ -28742,9 +28969,11 @@ var ConditionalShowModule = /** @class */ (function () {
28742
28969
  ConditionalShowModule = __decorate([
28743
28970
  core_1.NgModule({
28744
28971
  declarations: [
28972
+ conditional_show_directive_1.ConditionalShowDirective,
28745
28973
  conditional_show_form_directive_1.ConditionalShowFormDirective
28746
28974
  ],
28747
28975
  exports: [
28976
+ conditional_show_directive_1.ConditionalShowDirective,
28748
28977
  conditional_show_form_directive_1.ConditionalShowFormDirective
28749
28978
  ],
28750
28979
  providers: [