monkey-style-guide 21.2.25 → 21.2.26

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.
@@ -6939,10 +6939,42 @@ const CONDITIONS = {
6939
6939
  date: ['EQ', 'NEQ', 'BETWEEN', 'BEFORE', 'AFTER'],
6940
6940
  status: ['EQ', 'NEQ']
6941
6941
  };
6942
+ const SUPPORTED = {
6943
+ text: new Set([
6944
+ 'EQ',
6945
+ 'NEQ',
6946
+ 'LIKE',
6947
+ 'NOT_LIKE',
6948
+ 'STARTS_WITH',
6949
+ 'ENDS_WITH',
6950
+ 'BETWEEN',
6951
+ 'IS_EMPTY'
6952
+ ]),
6953
+ currency: new Set(['EQ', 'NEQ', 'BETWEEN', 'GT', 'LT', 'IS_EMPTY']),
6954
+ date: new Set(['EQ', 'NEQ', 'BETWEEN', 'BEFORE', 'AFTER', 'IS_EMPTY']),
6955
+ status: new Set(['EQ', 'NEQ', 'IS_EMPTY'])
6956
+ };
6942
6957
  const NO_OPERAND = new Set(['IS_EMPTY']);
6943
6958
  const TWO_OPERANDS = new Set(['BETWEEN']);
6944
- function conditionsOf(type) {
6945
- return CONDITIONS[type] ?? [];
6959
+ function supportedConditionsOf(type) {
6960
+ return SUPPORTED[type] ? [...SUPPORTED[type]] : [];
6961
+ }
6962
+ function conditionsOf(type, requested) {
6963
+ const fallback = CONDITIONS[type] ?? [];
6964
+ if (!requested?.length)
6965
+ return fallback;
6966
+ const supported = SUPPORTED[type];
6967
+ if (!supported)
6968
+ return fallback;
6969
+ const picked = requested.filter((operator, index) => {
6970
+ return supported.has(operator) && requested.indexOf(operator) === index;
6971
+ });
6972
+ return picked.length > 0 ? picked : fallback;
6973
+ }
6974
+ function conditionsForOption(option, byType) {
6975
+ if (!option)
6976
+ return [];
6977
+ return conditionsOf(option.type, option.conditions ?? byType?.[option.type]);
6946
6978
  }
6947
6979
  function arityOf(condition) {
6948
6980
  if (NO_OPERAND.has(condition))
@@ -6983,10 +7015,8 @@ function withCondition(row, condition) {
6983
7015
  return { ...row, condition };
6984
7016
  return { ...row, condition, operands: [] };
6985
7017
  }
6986
- function withType(row, next) {
6987
- const condition = conditionsOf(next.type).includes(row.condition)
6988
- ? row.condition
6989
- : '';
7018
+ function withType(row, next, allowed = conditionsOf(next.type)) {
7019
+ const condition = allowed.includes(row.condition) ? row.condition : '';
6990
7020
  return { ...next, condition, operands: [] };
6991
7021
  }
6992
7022
 
@@ -7713,6 +7743,10 @@ class MonkeyFilterBarComponent {
7713
7743
  this.dateRange = { startDate: '', endDate: '' };
7714
7744
  this.dayValue = '';
7715
7745
  this.options = computed(() => this.config()?.filterOptions ?? [], ...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
7746
+ this.conditionsByKey = computed(() => {
7747
+ const byType = this.config()?.conditions;
7748
+ return new Map(this.options().map((option) => [option.key, conditionsForOption(option, byType)]));
7749
+ }, ...(ngDevMode ? [{ debugName: "conditionsByKey" }] : /* istanbul ignore next */ []));
7716
7750
  this.labels = computed(() => {
7717
7751
  const text = this._text();
7718
7752
  return {
@@ -7782,6 +7816,15 @@ class MonkeyFilterBarComponent {
7782
7816
  });
7783
7817
  inject(DestroyRef).onDestroy(() => this.cancelCommit());
7784
7818
  }
7819
+ /**
7820
+ * A field with a single condition has nothing to ask: the answer to "which
7821
+ * condition" is already known, so it is taken rather than put to the user.
7822
+ */
7823
+ autoCondition(row, allowed) {
7824
+ if (row.condition || allowed.length !== 1)
7825
+ return row;
7826
+ return { ...row, condition: allowed[0] };
7827
+ }
7785
7828
  askForAnswer(row) {
7786
7829
  if (isComplete(row)) {
7787
7830
  this.resetDraft();
@@ -8035,7 +8078,8 @@ class MonkeyFilterBarComponent {
8035
8078
  return index > 0 && options[index].type !== options[index - 1].type;
8036
8079
  }
8037
8080
  conditionsFor(row) {
8038
- return conditionsOf(row.type);
8081
+ return (this.conditionsByKey().get(row.key) ??
8082
+ conditionsForOption({ type: row.type }, this.config()?.conditions));
8039
8083
  }
8040
8084
  panelFor(row) {
8041
8085
  return panelOf(row.type, row.condition);
@@ -8098,24 +8142,27 @@ class MonkeyFilterBarComponent {
8098
8142
  if (!option)
8099
8143
  return;
8100
8144
  this.immediateTriggerExit.set(true);
8145
+ const row = this.autoCondition({
8146
+ key: option.key,
8147
+ label: option.label,
8148
+ icon: option.icon,
8149
+ type: option.type,
8150
+ condition: '',
8151
+ operands: []
8152
+ }, this.conditionsByKey().get(option.key) ?? []);
8101
8153
  this.withFlip(() => {
8102
8154
  this.triggerOpen.set(false);
8103
8155
  this.categorySearch.set('');
8104
8156
  this.resetDraft();
8105
8157
  this.calendarOpen.set(null);
8106
- this.rows.update((rows) => [
8107
- ...rows,
8108
- {
8109
- key: option.key,
8110
- label: option.label,
8111
- icon: option.icon,
8112
- type: option.type,
8113
- condition: '',
8114
- operands: []
8115
- }
8116
- ]);
8117
- this.openPanel.set({ key: option.key, part: 'condition' });
8158
+ this.rows.update((rows) => [...rows, row]);
8159
+ if (row.condition)
8160
+ this.askForAnswer(row);
8161
+ else
8162
+ this.openPanel.set({ key: option.key, part: 'condition' });
8118
8163
  });
8164
+ if (row.condition)
8165
+ this.commit();
8119
8166
  }
8120
8167
  onChangeCategory(row, index) {
8121
8168
  const option = this.changeOptions()[index];
@@ -8131,12 +8178,13 @@ class MonkeyFilterBarComponent {
8131
8178
  this.resetDraft();
8132
8179
  this.calendarOpen.set(null);
8133
8180
  this.categorySearch.set('');
8134
- const next = withType(row, {
8181
+ const allowed = conditionsForOption(option, this.config()?.conditions);
8182
+ const next = this.autoCondition(withType(row, {
8135
8183
  key: option.key,
8136
8184
  label: option.label,
8137
8185
  icon: option.icon,
8138
8186
  type: option.type
8139
- });
8187
+ }, allowed), allowed);
8140
8188
  this.rows.update((rows) => rows.map((item) => (item.key === row.key ? next : item)));
8141
8189
  if (next.condition)
8142
8190
  this.askForAnswer(next);
@@ -12920,5 +12968,5 @@ class MonkeyToastRef {
12920
12968
  * Generated bundle index. Do not edit.
12921
12969
  */
12922
12970
 
12923
- export { DOWNLOAD_TOAST_EXIT_MS, MECX_COUNTRY_ISO_CODE, MECX_GOOGLE_API_KEY, MECX_I18N_LANG, MECX_I18N_WRAPPER, MECX_MODAL_DATA, MECX_MODAL_DEFAULT_CONFIG, MECX_POPOVER_OPTIONS, MonkeyAccordionComponent, MonkeyActionBarComponent, MonkeyAlertComponent, MonkeyAutocompleteAddressComponent, MonkeyAutocompleteComponent, MonkeyAvatarComponent, MonkeyBadgeComponent, MonkeyBadgeDirective, MonkeyBreadcrumbComponent, MonkeyButtonComponent, MonkeyCheckboxComponent, MonkeyComplexFilterBarComponent, MonkeyDateRangeComponent, MonkeyDictionaryService, MonkeyDisplayDirective, MonkeyDividerComponent, MonkeyDownloadButtonComponent, MonkeyDownloadToastComponent, MonkeyDownloadToastService, MonkeyDownloadToastStackComponent, MonkeyEcxAddressService, MonkeyErrorDirective, MonkeyFilterBarComponent, MonkeyFilterBarService, MonkeyFilterChipComponent, MonkeyFilterMenuComponent, MonkeyFilterMenuItemComponent, MonkeyFilterSegmentComponent, MonkeyFilterTriggerComponent, MonkeyFormDirective, MonkeyFormFieldComponent, MonkeyFormFieldControl, MonkeyFormFieldModule, MonkeyHelperDirective, MonkeyIconButtonComponent, MonkeyInfoDirective, MonkeyInputCodeComponent, MonkeyInputCurrencyDirective, MonkeyInputDateRangeComponent, MonkeyInputDirective, MonkeyInputModule, MonkeyInputPhoneComponent, MonkeyInputUploadComponent, MonkeyLabelDirective, MonkeyModalActionsDirective, MonkeyModalComponent, MonkeyModalConfig, MonkeyModalContentDirective, MonkeyModalModule, MonkeyModalRef, MonkeyModalService, MonkeyModalSubtitleDirective, MonkeyModalTitleDirective, MonkeyOptionComponent, MonkeyPaginationActionComponent, MonkeyPaginationLabelComponent, MonkeyPaginationSizeComponent, MonkeyPassNumberComponent, MonkeyPassSecretNumberComponent, MonkeyPopoverContentComponent, MonkeyPopoverDirective, MonkeyPrefixDirective, MonkeyRadioButtonComponent, MonkeyScrollbarComponent, MonkeySecurityLevelComponent, MonkeySelectComponent, MonkeyStatusComponent, MonkeyStepComponent, MonkeyStepperComponent, MonkeyStepperModule, MonkeyStepperService, MonkeySuffixDirective, MonkeyTabComponent, MonkeyTabLinkDirective, MonkeyTableCellDirective, MonkeyTableColumnDirective, MonkeyTableComponent, MonkeyTableEmptyDirective, MonkeyTableHeaderCellDirective, MonkeyTableLoadingDirective, MonkeyTableRowDetailDirective, MonkeyTabsComponent, MonkeyTabsModule, MonkeyToastComponent, MonkeyToastRef, MonkeyToastService, MonkeyToggleComponent, MonkeyToggleLineButtonComponent, MonkeyToggleLineComponent, MonkeyTooltipComponent, MonkeyTooltipDirective, MonkeyUserProfileButtonComponent, MonkeyUserProfileComponent, addKeys, appliedFrom, ariaSortOf, arityOf, closeOnClickAttribute, conditionsOf, getCurrencySymbol, indexAtOffset, injectTokenWithWarning, interpolate, isComplete, mergeOrder, offsetOfIndex, panelOf, removeKeys, sameColumnState, selectionState, sortByOrder, toPx, toggleKey, totalHeight, withCondition, withType };
12971
+ export { DOWNLOAD_TOAST_EXIT_MS, MECX_COUNTRY_ISO_CODE, MECX_GOOGLE_API_KEY, MECX_I18N_LANG, MECX_I18N_WRAPPER, MECX_MODAL_DATA, MECX_MODAL_DEFAULT_CONFIG, MECX_POPOVER_OPTIONS, MonkeyAccordionComponent, MonkeyActionBarComponent, MonkeyAlertComponent, MonkeyAutocompleteAddressComponent, MonkeyAutocompleteComponent, MonkeyAvatarComponent, MonkeyBadgeComponent, MonkeyBadgeDirective, MonkeyBreadcrumbComponent, MonkeyButtonComponent, MonkeyCheckboxComponent, MonkeyComplexFilterBarComponent, MonkeyDateRangeComponent, MonkeyDictionaryService, MonkeyDisplayDirective, MonkeyDividerComponent, MonkeyDownloadButtonComponent, MonkeyDownloadToastComponent, MonkeyDownloadToastService, MonkeyDownloadToastStackComponent, MonkeyEcxAddressService, MonkeyErrorDirective, MonkeyFilterBarComponent, MonkeyFilterBarService, MonkeyFilterChipComponent, MonkeyFilterMenuComponent, MonkeyFilterMenuItemComponent, MonkeyFilterSegmentComponent, MonkeyFilterTriggerComponent, MonkeyFormDirective, MonkeyFormFieldComponent, MonkeyFormFieldControl, MonkeyFormFieldModule, MonkeyHelperDirective, MonkeyIconButtonComponent, MonkeyInfoDirective, MonkeyInputCodeComponent, MonkeyInputCurrencyDirective, MonkeyInputDateRangeComponent, MonkeyInputDirective, MonkeyInputModule, MonkeyInputPhoneComponent, MonkeyInputUploadComponent, MonkeyLabelDirective, MonkeyModalActionsDirective, MonkeyModalComponent, MonkeyModalConfig, MonkeyModalContentDirective, MonkeyModalModule, MonkeyModalRef, MonkeyModalService, MonkeyModalSubtitleDirective, MonkeyModalTitleDirective, MonkeyOptionComponent, MonkeyPaginationActionComponent, MonkeyPaginationLabelComponent, MonkeyPaginationSizeComponent, MonkeyPassNumberComponent, MonkeyPassSecretNumberComponent, MonkeyPopoverContentComponent, MonkeyPopoverDirective, MonkeyPrefixDirective, MonkeyRadioButtonComponent, MonkeyScrollbarComponent, MonkeySecurityLevelComponent, MonkeySelectComponent, MonkeyStatusComponent, MonkeyStepComponent, MonkeyStepperComponent, MonkeyStepperModule, MonkeyStepperService, MonkeySuffixDirective, MonkeyTabComponent, MonkeyTabLinkDirective, MonkeyTableCellDirective, MonkeyTableColumnDirective, MonkeyTableComponent, MonkeyTableEmptyDirective, MonkeyTableHeaderCellDirective, MonkeyTableLoadingDirective, MonkeyTableRowDetailDirective, MonkeyTabsComponent, MonkeyTabsModule, MonkeyToastComponent, MonkeyToastRef, MonkeyToastService, MonkeyToggleComponent, MonkeyToggleLineButtonComponent, MonkeyToggleLineComponent, MonkeyTooltipComponent, MonkeyTooltipDirective, MonkeyUserProfileButtonComponent, MonkeyUserProfileComponent, addKeys, appliedFrom, ariaSortOf, arityOf, closeOnClickAttribute, conditionsForOption, conditionsOf, getCurrencySymbol, indexAtOffset, injectTokenWithWarning, interpolate, isComplete, mergeOrder, offsetOfIndex, panelOf, removeKeys, sameColumnState, selectionState, sortByOrder, supportedConditionsOf, toPx, toggleKey, totalHeight, withCondition, withType };
12924
12972
  //# sourceMappingURL=monkey-style-guide.mjs.map