udp-stencil-component-library 26.3.0-beta.17 → 26.3.0-beta.19
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/cjs/udp-advanced-search-builder.cjs.entry.js +7 -4
- package/dist/collection/components/advanced-search-builder/udp-advanced-search-builder.js +7 -4
- package/dist/components/udp-advanced-search-builder.js +1 -1
- package/dist/docs.json +1 -1
- package/dist/esm/udp-advanced-search-builder.entry.js +7 -4
- package/dist/stencil-library/udp-advanced-search-builder.entry.js +1 -1
- package/package.json +1 -1
|
@@ -803,10 +803,13 @@ const UdpAdvancedSearchBuilder = class {
|
|
|
803
803
|
verifyFilterState(data) {
|
|
804
804
|
const errors = [];
|
|
805
805
|
const guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
806
|
-
// Validate groups:
|
|
806
|
+
// Validate groups: a group must contribute something — either its own direct
|
|
807
|
+
// filter or a child group. A container group (children only, no direct filters)
|
|
808
|
+
// is valid; only a truly empty group (no filters and no children) is an error.
|
|
807
809
|
for (const group of data.filterGroups) {
|
|
808
810
|
const hasDirectFilters = data.filterElements.some(f => f.groupId === group.groupId);
|
|
809
|
-
|
|
811
|
+
const hasChildGroups = data.filterGroups.some(g => g.parentGroupId === group.groupId);
|
|
812
|
+
if (!hasDirectFilters && !hasChildGroups) {
|
|
810
813
|
const label = group.parentGroupId === null ? 'Root group' : 'A group';
|
|
811
814
|
errors.push(`${label} has no filters. Add a filter or remove the group.`);
|
|
812
815
|
}
|
|
@@ -960,11 +963,11 @@ const UdpAdvancedSearchBuilder = class {
|
|
|
960
963
|
if (this.isExpanded && this.config.height) {
|
|
961
964
|
hostStyles['height'] = this.config.height;
|
|
962
965
|
}
|
|
963
|
-
return (index.h(index.Host, { key: '
|
|
966
|
+
return (index.h(index.Host, { key: 'ab3132a409df0b83da567793d635d13ee9b49d65', style: hostStyles, class: {
|
|
964
967
|
'is-resizable': isResizable,
|
|
965
968
|
'host-expanded': this.isExpanded,
|
|
966
969
|
'host-collapsed': !this.isExpanded,
|
|
967
|
-
} }, index.h("div", { key: '
|
|
970
|
+
} }, index.h("div", { key: 'b1afe1b4d06b93bf2f2ff5be3cf86ba1b8aa28d8', class: containerClasses }, isCollapsible && (index.h("div", { key: '208924a3e7652fb3cece053e28049ca33d956af5', class: "collapsed-view" }, index.h("udp-fluent-text-input", { key: 'b4752482a768ee8cb202e2b22c3243a66597b8ae', value: this.filterString, readonly: true, appearance: "filled-darker", includeErrorPadding: false, class: "string-display-input" }), index.h("udp-fluent-button", { key: '728968a44a5c47e21e0e229522c23e4b7c5d24b3', class: "toggle-button", size: "small", appearance: "transparent", onClick: this.toggleExpanded }, index.h("span", { key: '480b0e5695de7662d52da5f93747e9e5640794cb' }, this.isExpanded ? 'Collapse' : 'Expand'), index.h("svg", { key: '56693d725e73fa795a209a06a8edaccf1d2b6fb4', class: "toggle-icon", viewBox: "0 0 16 16", slot: "end" }, index.h("path", { key: '98699d880181e345bc91f70644c0f9c981d40c3b', d: "M4 6L8 10L12 6", stroke: "currentColor", "stroke-width": "2" }))))), index.h("div", { key: '1b389df7790880e47e946888e7fe501a2ad5f07d', class: "anim-container", ref: el => (this.animContainerEl = el) }, index.h("div", { key: '80e0830959f3513ed6ba0fb2fe866038e636bb2e', class: "content-wrapper" }, (this.isExpanded || !isCollapsible) && rootGroup && (index.h("udp-advanced-search-filter-group", { key: rootGroup.groupId, groupId: rootGroup.groupId, filterData: this.currentFilterData, fields: this.fieldsArray, isRoot: true, isFilterValid: this.isFilterValid, errorMessages: this.errorMessages, maxDepth: this.currentMaxDepth, onAddFilter: e => this.handleAddFilter(e.detail), onAddGroup: e => this.handleAddGroup(e.detail), onRemoveFilter: e => this.handleRemoveFilter(e.detail), onRemoveGroup: e => this.handleRemoveGroup(e.detail), onFilterChange: this.handleFilterChange, onGroupChange: this.handleGroupChange, onDepthChange: this.handleDepthChange, openAddMenuForGroupId: this.openAddMenuForGroupId, onToggleAddMenu: this.handleToggleAddMenu })))), showFooter && (index.h("div", { key: 'fc72bbb8d13c9d07de966b480e91a082587122a1', class: "advanced-filter-footer" }, index.h("validation-chip", { key: 'c2e5d0fa78b7ab310fd43963350214f78ca762be', isValid: this.isFilterValid, errorMessages: this.errorMessages }), index.h("udp-fluent-button", { key: '6ec8b756b23463bdfdc54cf766d11fd9d40af309', disabled: !this.isFilterValid, onClick: this.handleSearch, appearance: "primary" }, "Search"))))));
|
|
968
971
|
}
|
|
969
972
|
get el() { return index.getElement(this); }
|
|
970
973
|
static get watchers() { return {
|
|
@@ -257,10 +257,13 @@ export class UdpAdvancedSearchBuilder {
|
|
|
257
257
|
verifyFilterState(data) {
|
|
258
258
|
const errors = [];
|
|
259
259
|
const guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
260
|
-
// Validate groups:
|
|
260
|
+
// Validate groups: a group must contribute something — either its own direct
|
|
261
|
+
// filter or a child group. A container group (children only, no direct filters)
|
|
262
|
+
// is valid; only a truly empty group (no filters and no children) is an error.
|
|
261
263
|
for (const group of data.filterGroups) {
|
|
262
264
|
const hasDirectFilters = data.filterElements.some(f => f.groupId === group.groupId);
|
|
263
|
-
|
|
265
|
+
const hasChildGroups = data.filterGroups.some(g => g.parentGroupId === group.groupId);
|
|
266
|
+
if (!hasDirectFilters && !hasChildGroups) {
|
|
264
267
|
const label = group.parentGroupId === null ? 'Root group' : 'A group';
|
|
265
268
|
errors.push(`${label} has no filters. Add a filter or remove the group.`);
|
|
266
269
|
}
|
|
@@ -414,11 +417,11 @@ export class UdpAdvancedSearchBuilder {
|
|
|
414
417
|
if (this.isExpanded && this.config.height) {
|
|
415
418
|
hostStyles['height'] = this.config.height;
|
|
416
419
|
}
|
|
417
|
-
return (h(Host, { key: '
|
|
420
|
+
return (h(Host, { key: 'ab3132a409df0b83da567793d635d13ee9b49d65', style: hostStyles, class: {
|
|
418
421
|
'is-resizable': isResizable,
|
|
419
422
|
'host-expanded': this.isExpanded,
|
|
420
423
|
'host-collapsed': !this.isExpanded,
|
|
421
|
-
} }, h("div", { key: '
|
|
424
|
+
} }, h("div", { key: 'b1afe1b4d06b93bf2f2ff5be3cf86ba1b8aa28d8', class: containerClasses }, isCollapsible && (h("div", { key: '208924a3e7652fb3cece053e28049ca33d956af5', class: "collapsed-view" }, h("udp-fluent-text-input", { key: 'b4752482a768ee8cb202e2b22c3243a66597b8ae', value: this.filterString, readonly: true, appearance: "filled-darker", includeErrorPadding: false, class: "string-display-input" }), h("udp-fluent-button", { key: '728968a44a5c47e21e0e229522c23e4b7c5d24b3', class: "toggle-button", size: "small", appearance: "transparent", onClick: this.toggleExpanded }, h("span", { key: '480b0e5695de7662d52da5f93747e9e5640794cb' }, this.isExpanded ? 'Collapse' : 'Expand'), h("svg", { key: '56693d725e73fa795a209a06a8edaccf1d2b6fb4', class: "toggle-icon", viewBox: "0 0 16 16", slot: "end" }, h("path", { key: '98699d880181e345bc91f70644c0f9c981d40c3b', d: "M4 6L8 10L12 6", stroke: "currentColor", "stroke-width": "2" }))))), h("div", { key: '1b389df7790880e47e946888e7fe501a2ad5f07d', class: "anim-container", ref: el => (this.animContainerEl = el) }, h("div", { key: '80e0830959f3513ed6ba0fb2fe866038e636bb2e', class: "content-wrapper" }, (this.isExpanded || !isCollapsible) && rootGroup && (h("udp-advanced-search-filter-group", { key: rootGroup.groupId, groupId: rootGroup.groupId, filterData: this.currentFilterData, fields: this.fieldsArray, isRoot: true, isFilterValid: this.isFilterValid, errorMessages: this.errorMessages, maxDepth: this.currentMaxDepth, onAddFilter: e => this.handleAddFilter(e.detail), onAddGroup: e => this.handleAddGroup(e.detail), onRemoveFilter: e => this.handleRemoveFilter(e.detail), onRemoveGroup: e => this.handleRemoveGroup(e.detail), onFilterChange: this.handleFilterChange, onGroupChange: this.handleGroupChange, onDepthChange: this.handleDepthChange, openAddMenuForGroupId: this.openAddMenuForGroupId, onToggleAddMenu: this.handleToggleAddMenu })))), showFooter && (h("div", { key: 'fc72bbb8d13c9d07de966b480e91a082587122a1', class: "advanced-filter-footer" }, h("validation-chip", { key: 'c2e5d0fa78b7ab310fd43963350214f78ca762be', isValid: this.isFilterValid, errorMessages: this.errorMessages }), h("udp-fluent-button", { key: '6ec8b756b23463bdfdc54cf766d11fd9d40af309', disabled: !this.isFilterValid, onClick: this.handleSearch, appearance: "primary" }, "Search"))))));
|
|
422
425
|
}
|
|
423
426
|
static get is() { return "udp-advanced-search-builder"; }
|
|
424
427
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import "../stencil-library/stencil-library.css";
|
|
2
|
-
import{p as t,H as e,c as i,h as s,d as o,t as n}from"./index2.js";import{L as r,a}from"./searchObject.js";import{g as l,d as h}from"./filter-group.js";import{d}from"./udp-autocomplete2.js";import{d as u}from"./udp-date-input2.js";import{d as c}from"./udp-date-range-selector2.js";import{d as p}from"./udp-date-time-input2.js";import{d as f}from"./udp-fluent-badge2.js";import{d as m}from"./udp-fluent-button2.js";import{d as b}from"./udp-fluent-dropdown2.js";import{d as v}from"./udp-fluent-icon2.js";import{d as g}from"./udp-fluent-icon-button2.js";import{d as x}from"./udp-fluent-menu2.js";import{d as y}from"./udp-fluent-text-input2.js";import{d as w}from"./udp-popover2.js";import{d as k}from"./udp-spinner2.js";import{d as F}from"./udp-text2.js";import{d as j}from"./udp-time-input2.js";import{d as E}from"./udp-tooltip2.js";import{d as D}from"./validation-chip2.js";import{b as I}from"./catalogTree.js";class O{constructor(t,e){this.scrollContainer=null,this.isDragStarted=!1,this.pendingItem=null,this.pendingLabel="",this.sourceRowEl=null,this.startX=0,this.startY=0,this.currentState={isDragging:!1,dragItem:null,insertionPoint:null},this.sourceOriginalStyle="",this.draggedItemHeight=0,this.ghostOriginalTop=0,this.placeholder=null,this.overlay=null,this.dropTargets=[],this.previousGapEls=[],this.lockedTarget=null,this.lockedPosition="before",this.autoScrollRAF=null,this.hostEl=t,this.callbacks=e,this.boundPointerDown=this.onPointerDown.bind(this),this.boundPointerMove=this.onPointerMove.bind(this),this.boundPointerUp=this.onPointerUp.bind(this),this.boundKeyDown=this.onKeyDown.bind(this),this.boundScroll=this.onScroll.bind(this),this.hostEl.addEventListener("pointerdown",this.boundPointerDown,!0)}destroy(){this.hostEl.removeEventListener("pointerdown",this.boundPointerDown,!0),this.cleanup()}setScrollContainer(t){this.scrollContainer=t}onPointerDown(t){if(0!==t.button)return;const e=t.composedPath(),i=e.find((t=>t instanceof HTMLElement&&t.hasAttribute("data-drag-handle")));if(!i)return;t.preventDefault();const s=i.dataset.dragType,o=i.dataset.dragId;if(!s||!o)return;const n=e.find((t=>t instanceof HTMLElement&&("filter"===s?t.classList.contains("filter-row"):t.classList.contains("group-box")&&!t.classList.contains("root-group"))));this.pendingItem={type:s,id:o},this.pendingLabel=i.dataset.dragLabel||("filter"===s?"Filter":"Group"),this.sourceRowEl=n||null,this.startX=t.clientX,this.startY=t.clientY,this.isDragStarted=!1,document.addEventListener("pointermove",this.boundPointerMove),document.addEventListener("pointerup",this.boundPointerUp),document.addEventListener("keydown",this.boundKeyDown)}onPointerMove(t){const e=t.clientX-this.startX,i=t.clientY-this.startY;if(!this.isDragStarted){if(Math.sqrt(e*e+i*i)<5)return;this.beginDrag()}this.moveOverlay(t.clientX,t.clientY),this.updateInsertionPoint(t.clientY),this.handleAutoScroll(t.clientY)}onPointerUp(){this.isDragStarted&&this.currentState.insertionPoint&&this.currentState.dragItem&&this.callbacks.onDrop(this.currentState.dragItem,this.currentState.insertionPoint),this.cleanup()}onKeyDown(t){"Escape"===t.key&&this.cleanup()}beginDrag(){var t;if(this.isDragStarted=!0,this.sourceRowEl){const e=this.sourceRowEl.getBoundingClientRect();this.draggedItemHeight=e.height,this.ghostOriginalTop=e.top,this.sourceOriginalStyle=this.sourceRowEl.style.cssText,this.placeholder=document.createElement("div"),this.placeholder.style.height=e.height+"px",this.placeholder.style.pointerEvents="none",null===(t=this.sourceRowEl.parentNode)||void 0===t||t.insertBefore(this.placeholder,this.sourceRowEl.nextSibling),this.sourceRowEl.style.position="fixed",this.sourceRowEl.style.top=e.top+"px",this.sourceRowEl.style.left=e.left+"px",this.sourceRowEl.style.width=e.width+"px",this.sourceRowEl.style.height=e.height+"px",this.sourceRowEl.style.zIndex="10000",this.sourceRowEl.style.opacity="0.35",this.sourceRowEl.style.pointerEvents="none",this.sourceRowEl.style.transition="top 80ms ease-out, left 80ms ease-out, width 80ms ease-out",this.sourceRowEl.style.border="1px dashed var(--colorNeutralStroke1, #d1d1d1)",this.sourceRowEl.style.borderRadius="4px",this.sourceRowEl.style.boxSizing="border-box"}this.collectDropTargets(),this.createOverlay(),this.scrollContainer&&this.scrollContainer.addEventListener("scroll",this.boundScroll,{passive:!0}),document.body.style.cursor="grabbing",document.body.style.userSelect="none",this.currentState={isDragging:!0,dragItem:this.pendingItem,insertionPoint:null},this.callbacks.onStateChange(Object.assign({},this.currentState))}cleanup(){this.placeholder&&(this.placeholder.remove(),this.placeholder=null),this.sourceRowEl&&(this.sourceRowEl.style.cssText=this.sourceOriginalStyle,this.sourceRowEl=null),this.overlay&&(this.overlay.remove(),this.overlay=null),this.clearGap(),null!==this.autoScrollRAF&&(cancelAnimationFrame(this.autoScrollRAF),this.autoScrollRAF=null),this.scrollContainer&&this.scrollContainer.removeEventListener("scroll",this.boundScroll),document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("pointermove",this.boundPointerMove),document.removeEventListener("pointerup",this.boundPointerUp),document.removeEventListener("keydown",this.boundKeyDown),this.pendingItem=null,this.pendingLabel="",this.isDragStarted=!1,this.dropTargets=[],this.draggedItemHeight=0,this.ghostOriginalTop=0,this.sourceOriginalStyle="",this.lockedTarget=null;const t=this.currentState.isDragging;this.currentState={isDragging:!1,dragItem:null,insertionPoint:null},t&&this.callbacks.onStateChange(Object.assign({},this.currentState))}createOverlay(){var t;this.overlay=document.createElement("div"),this.overlay.className="drag-overlay",this.overlay.textContent=this.pendingLabel,null===(t=this.hostEl.shadowRoot)||void 0===t||t.appendChild(this.overlay)}moveOverlay(t,e){this.overlay&&(this.overlay.style.left=t+12+"px",this.overlay.style.top=e-20+"px")}positionGhost(t,e){if(!this.sourceRowEl)return;const i=this.getGapElement(t,e).getBoundingClientRect();let s;s="before"===e?i.top-this.draggedItemHeight:i.bottom;const o=this.getGhostReferenceRect(t,e);this.sourceRowEl.style.top=s+"px",this.sourceRowEl.style.left=o.left+"px",this.sourceRowEl.style.width=o.width+"px"}getGhostReferenceRect(t,e){if("group"===t.type&&"after"===e){const e=t.element.nextElementSibling;if(e){const t=Array.from(e.querySelectorAll(".filter-row, udp-advanced-search-filter-group"));for(const e of t)if(e!==this.sourceRowEl)return e.getBoundingClientRect();const i=e.querySelector(".add-new-container");if(i)return i.getBoundingClientRect()}}return t.element.getBoundingClientRect()}resetGhostPosition(){this.sourceRowEl&&(this.sourceRowEl.style.top=this.ghostOriginalTop+"px")}getGapElement(t,e){if("filter"===t.type)return t.element;if("after"===e)return t.element;const i=t.element.getRootNode();return i instanceof ShadowRoot&&i.host?i.host:t.element}applyGap(t,e){this.placeholder&&(this.placeholder.style.height="0px");const i=this.getGapElement(t,e);for(const t of this.previousGapEls)t!==i&&(t.style.marginTop="",t.style.marginBottom="");i.style.marginTop="",i.style.marginBottom="","before"===e?i.style.marginTop=this.draggedItemHeight+"px":i.style.marginBottom=this.draggedItemHeight+"px",this.previousGapEls=[i]}clearGap(){for(const t of this.previousGapEls)t.style.marginTop="",t.style.marginBottom="";this.previousGapEls=[],this.placeholder&&(this.placeholder.style.height=this.draggedItemHeight+"px")}collectDropTargets(){var t;this.dropTargets=[];const e=this.pendingItem,i=t=>{const s=t.shadowRoot;if(!s)return;s.querySelectorAll(".filter-row[data-filter-id]").forEach((t=>{const i=t.dataset.filterId;"filter"===(null==e?void 0:e.type)&&e.id===i||this.dropTargets.push({type:"filter",id:i,element:t,rect:t.getBoundingClientRect(),midY:0})}));const o=s.querySelector(".group-box[data-group-id]");if(o&&!o.classList.contains("root-group")){const t=o.dataset.groupId;if("group"!==(null==e?void 0:e.type)||e.id!==t){const e=o.querySelector(":scope > .group-header");e&&this.dropTargets.push({type:"group",id:t,element:e,rect:e.getBoundingClientRect(),midY:0})}}s.querySelectorAll("udp-advanced-search-filter-group").forEach((t=>i(t)))},s=null===(t=this.hostEl.shadowRoot)||void 0===t?void 0:t.querySelector("udp-advanced-search-filter-group");s&&i(s);for(const t of this.dropTargets)t.midY=t.rect.top+t.rect.height/2;this.dropTargets.sort(((t,e)=>t.rect.top-e.rect.top))}updateInsertionPoint(t){var e,i;if(0===this.dropTargets.length)return this.clearGap(),this.resetGhostPosition(),this.lockedTarget=null,void this.commitInsertionPoint(null);let s=null,o="before";for(const e of this.dropTargets){const i=e.element.getBoundingClientRect();if(t>=i.top&&t<=i.bottom){s=e,o=t<i.top+i.height/2?"before":"after";break}}if(!s){const n=null===(e=this.dropTargets[0])||void 0===e?void 0:e.element,r=null===(i=this.dropTargets[this.dropTargets.length-1])||void 0===i?void 0:i.element;if(n&&t<n.getBoundingClientRect().top)s=this.dropTargets[0],o="before";else{if(!(r&&t>r.getBoundingClientRect().bottom))return;s=this.dropTargets[this.dropTargets.length-1],o="after"}}if("before"===o){const t=this.dropTargets.indexOf(s);t>0&&(s=this.dropTargets[t-1],o="after")}if(s===this.lockedTarget&&o===this.lockedPosition)return;const n=this.currentState.dragItem||this.pendingItem;if(this.callbacks.isValidDrop&&n&&!this.callbacks.isValidDrop(n,s.type,s.id))return this.clearGap(),this.resetGhostPosition(),this.lockedTarget=null,void this.commitInsertionPoint(null);this.lockedTarget=s,this.lockedPosition=o,this.applyGap(s,o),this.positionGhost(s,o),this.commitInsertionPoint({position:o,targetId:s.id,targetType:s.type})}commitInsertionPoint(t){const e=this.currentState.insertionPoint;(null==e?void 0:e.position)===(null==t?void 0:t.position)&&(null==e?void 0:e.targetId)===(null==t?void 0:t.targetId)&&(null==e?void 0:e.targetType)===(null==t?void 0:t.targetType)||(this.currentState=Object.assign(Object.assign({},this.currentState),{insertionPoint:t}),this.callbacks.onStateChange(Object.assign({},this.currentState)))}handleAutoScroll(t){if(!this.scrollContainer)return;const e=this.scrollContainer.getBoundingClientRect(),i=t-e.top,s=e.bottom-t;let o=0;if(i>0&&i<50?o=-10*(1-i/50):s>0&&s<50&&(o=10*(1-s/50)),null!==this.autoScrollRAF&&(cancelAnimationFrame(this.autoScrollRAF),this.autoScrollRAF=null),0!==o){const t=()=>{this.scrollContainer&&(this.scrollContainer.scrollTop+=o,this.refreshDropTargetRects(),this.autoScrollRAF=requestAnimationFrame(t))};this.autoScrollRAF=requestAnimationFrame(t)}}onScroll(){this.refreshDropTargetRects()}refreshDropTargetRects(){for(const t of this.dropTargets)t.rect=t.element.getBoundingClientRect(),t.midY=t.rect.top+t.rect.height/2}}const A=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.filterSave=i(this,"filterSave",7),this.searchChange=i(this,"searchChange",7),this.config={},this.maxDepth=2,this.fieldsArray=[],this.openAddMenuForGroupId=null,this.filterString="",this.isExpanded=!0,this.isFilterValid=!0,this.errorMessages=[],this.nextGroupId=1,this.handleSearch=()=>{this.isFilterValid&&this.filterSave?(this.filterSave.emit(this.currentFilterData),this.filterString=(t=>{if(!t||!t.filterGroups||0===t.filterGroups.length)return"";const e=i=>{const s=t.filterGroups.find((t=>t.groupId===i));if(!s)return"";const o=s.logicalSearchOperator===r.AND?"AND":"OR",n=[];return t.filterElements.filter((t=>t.groupId===i)).forEach((t=>{n.push(`[${t.searchField}] ${t.searchOperator} ${"string"==typeof t.searchValue?`"${t.searchValue}"`:t.searchValue}`)})),t.filterGroups.filter((t=>t.parentGroupId===i)).forEach((t=>{const i=e(t.groupId);i&&n.push(`(${i})`)})),n.join(` ${o} `)},i=t.filterGroups.find((t=>null===t.parentGroupId));return i?e(i.groupId):""})(this.currentFilterData),this.config.collapsible&&this.toggleExpanded()):console.warn("Cannot run search: filter is invalid.")},this.toggleExpanded=()=>{this.isExpanded=!this.isExpanded,this.updateHostClasses()},this.handleToggleAddMenu=t=>{const e=t.detail;if(this.openAddMenuForGroupId=this.openAddMenuForGroupId===e?null:e,null!==this.openAddMenuForGroupId){const t=this.animContainerEl;t&&requestAnimationFrame((()=>{t.scrollTop=t.scrollHeight}))}},this.handleDragStateChange=()=>{},this.isValidDragDrop=(t,e,i)=>{if("group"===t.type&&"group"===e){const e=parseInt(t.id,10),s=parseInt(i,10);if(e===s)return!1;if(this.isDescendant(s,e,this.currentFilterData.filterGroups))return!1}if("group"===t.type&&"filter"===e){const e=parseInt(t.id,10),s=this.currentFilterData.filterElements.find((t=>t._id===i));if(s){const t=s.groupId;if(t===e||this.isDescendant(t,e,this.currentFilterData.filterGroups))return!1}}return!0},this.handleDragDrop=(t,e)=>{this.runUpdateCycle((i=>{"filter"===t.type?this.applyFilterDrop(i,t,e):"group"===t.type&&this.applyGroupDrop(i,t,e)}))},this.handleAddFilter=t=>{this.runUpdateCycle((e=>{var i,s;const o=null===(i=this.fieldsArray)||void 0===i?void 0:i[0],n=l(o),r=(null===(s=null==n?void 0:n[0])||void 0===s?void 0:s.value)||"";e.filterElements.push({_id:"filter_"+Math.random(),_type:null==o?void 0:o.type,groupId:t,searchField:null==o?void 0:o.name,searchOperator:r,searchValue:""})})),this.openAddMenuForGroupId=null},this.handleAddGroup=t=>{this.runUpdateCycle((e=>{e.filterGroups.push({groupId:this.nextGroupId++,parentGroupId:t,logicalSearchOperator:r.AND})})),this.openAddMenuForGroupId=null},this.handleRemoveFilter=t=>{this.runUpdateCycle((e=>{const i=e.filterElements.findIndex((e=>e._id===t));i>-1&&e.filterElements.splice(i,1)}))},this.handleRemoveGroup=t=>{this.runUpdateCycle((e=>{const i=t=>{const s=e.filterGroups.filter((e=>e.parentGroupId===t));let o=s.map((t=>t.groupId));return s.forEach((t=>{o=[...o,...i(t.groupId)]})),o},s=[t,...i(t)];e.filterGroups=e.filterGroups.filter((t=>!s.includes(t.groupId))),e.filterElements=e.filterElements.filter((t=>!s.includes(t.groupId)))}))},this.handleFilterChange=t=>{const{filterId:e,field:i,value:s,updates:o}=t.detail;this.runUpdateCycle((t=>{const n=t.filterElements.find((t=>t._id===e));n&&(o?Object.assign(n,o):n[i]=s)}))},this.handleDepthChange=t=>{const e=t.detail;"number"==typeof e&&e!==this.currentMaxDepth&&(this.currentMaxDepth=e,this.buildFieldTree())},this.handleGroupChange=t=>{const{groupId:e,logicalSearchOperator:i}=t.detail;this.runUpdateCycle((t=>{const s=t.filterGroups.find((t=>t.groupId===e));s&&(s.logicalSearchOperator=i)}))}}buildFieldTree(){if(this.entityName&&this.catalogObjectList){const t=(t=>{if(!t)return"";const e=t.split(".");return e[e.length-1]})(this.entityName),e=t[0].toUpperCase()+t.slice(1);this.fieldsArray=I(this.catalogObjectList,e,this.currentMaxDepth)}}rebuildFieldTree(){this.buildFieldTree()}syncMaxDepth(t){this.currentMaxDepth=t,this.buildFieldTree()}syncInitialFilterData(t){this.currentFilterData=this.getNormalizedData(t),this.updateNextGroupId(this.currentFilterData)}componentWillLoad(){this.currentMaxDepth=this.maxDepth,this.buildFieldTree(),this.currentFilterData=this.getNormalizedData(this.initialFilterData),this.updateNextGroupId(this.currentFilterData)}componentDidLoad(){this.updateHostClasses(),this.dragManager=new O(this.el,{onStateChange:this.handleDragStateChange,onDrop:this.handleDragDrop,isValidDrop:this.isValidDragDrop}),this.animContainerEl&&this.dragManager.setScrollContainer(this.animContainerEl)}disconnectedCallback(){var t;null===(t=this.dragManager)||void 0===t||t.destroy()}async addFilterElement(t,e){var i,s,o,n;console.log("[addFilterElement] fieldName:",t,"fieldType:",e),console.log("[addFilterElement] fieldsArray names:",this.fieldsArray.map((t=>{var e;return{name:t.name,type:t.type,children:null===(e=t.childFields)||void 0===e?void 0:e.map((t=>t.name))}})));const r=new Set(["object","array"]),a=this.fieldsArray.find((e=>e.name===t));console.log("[addFilterElement] matchedField:",null!==(i=null==a?void 0:a.name)&&void 0!==i?i:"NONE");const h=null!==(o=null!==(s=null==a?void 0:a.type)&&void 0!==s?s:null==e?void 0:e.toLowerCase())&&void 0!==o?o:"string";if(r.has(h))return;const d=l(null!=a?a:{type:h}),u=(null===(n=null==d?void 0:d[0])||void 0===n?void 0:n.value)||"=",c=this.currentFilterData.filterGroups.find((t=>null===t.parentGroupId));this.runUpdateCycle((e=>{var i;e.filterElements.push({_id:"filter_"+Math.random(),_type:h,groupId:null!==(i=null==c?void 0:c.groupId)&&void 0!==i?i:1,searchField:t,searchOperator:u,searchValue:""})}))}updateHostClasses(){this.isExpanded?(this.el.classList.add("host-expanded"),this.el.classList.remove("host-collapsed")):(this.el.classList.add("host-collapsed"),this.el.classList.remove("host-expanded"),this.el.style.height=null)}updateNextGroupId(t){this.nextGroupId=t&&t.filterGroups.length>0?Math.max(...t.filterGroups.map((t=>t.groupId)))+1:2}verifyFilterState(t){const e=[],i=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;for(const i of t.filterGroups)t.filterElements.some((t=>t.groupId===i.groupId))||e.push((null===i.parentGroupId?"Root group":"A group")+" has no filters. Add a filter or remove the group.");return t.filterElements.forEach((t=>{delete t._error;const s=!t.searchValue,o=t.searchOperator===a.NULL||t.searchOperator===a.NOT_NULL;if(null==t.searchField||""===t.searchField){const i="Search Field cannot be empty.";t._error=i,e.push(i)}else if(t.searchOperator===a.BETWEEN){const i=(t.searchValue||"").split(",");if(2!==i.length||!i[0]||!i[1]){const i=`Two values required when using BETWEEN operator for field "${t.searchField}".`;t._error=i,e.push(i)}}else if(s&&!o){const i=`Value cannot be empty for field "${t.searchField}".`;t._error=i,e.push(i)}else if("guid"===t._type&&!s&&!i.test(t.searchValue)){const i=`Invalid GUID for field "${t.searchField}".`;t._error=i,e.push(i)}})),{isValid:0===e.length,errors:e}}getNormalizedData(t){var e,i;if(t&&(null===(e=t.filterGroups)||void 0===e?void 0:e.length)>0)return t;if(t&&(null===(i=t.filterElements)||void 0===i?void 0:i.length)>0){const e=1;return Object.assign(Object.assign({},t),{filterGroups:[{groupId:e,parentGroupId:null,logicalSearchOperator:t.logicalSearchOperator||r.AND}],filterElements:t.filterElements.map((t=>Object.assign(Object.assign({},t),{groupId:e})))})}return Object.assign(Object.assign({},t),{logicalSearchOperator:r.AND,filterGroups:[{groupId:1,parentGroupId:null,logicalSearchOperator:r.AND}],filterElements:[]})}runUpdateCycle(t){const e=JSON.parse(JSON.stringify(this.currentFilterData));t(e),this.currentFilterData=e;const i=this.verifyFilterState(e);this.isFilterValid=i.isValid,this.errorMessages=i.errors,this.searchChange.emit(e)}applyFilterDrop(t,e,i){const s=t.filterElements.find((t=>t._id===e.id));if(!s)return;const o=t.filterElements.indexOf(s);if(t.filterElements.splice(o,1),"filter"===i.targetType){const e=t.filterElements.find((t=>t._id===i.targetId));if(!e)return void t.filterElements.push(s);s.groupId=e.groupId;const o=t.filterElements.indexOf(e);t.filterElements.splice("before"===i.position?o:o+1,0,s)}else{const e=parseInt(i.targetId,10),o=t.filterGroups.find((t=>t.groupId===e));s.groupId="before"===i.position&&null!=(null==o?void 0:o.parentGroupId)?o.parentGroupId:e,t.filterElements.push(s)}}applyGroupDrop(t,e,i){const s=parseInt(e.id,10),o=t.filterGroups.find((t=>t.groupId===s));if(o)if("group"===i.targetType){const e=parseInt(i.targetId,10);if(this.isDescendant(e,s,t.filterGroups))return;if(s===e)return;const n=t.filterGroups.find((t=>t.groupId===e));if(!n)return;o.parentGroupId="before"===i.position?n.parentGroupId:e;const r=t.filterGroups.indexOf(o);t.filterGroups.splice(r,1);const a=t.filterGroups.indexOf(n);t.filterGroups.splice("before"===i.position?a:a+1,0,o)}else if("filter"===i.targetType){const e=t.filterElements.find((t=>t._id===i.targetId));e&&(o.parentGroupId=e.groupId)}}isDescendant(t,e,i){let s=i.find((e=>e.groupId===t));for(;s&&null!==s.parentGroupId;){if(s.parentGroupId===e)return!0;s=i.find((t=>t.groupId===s.parentGroupId))}return!1}render(){const t=this.currentFilterData.filterGroups.find((t=>null===t.parentGroupId)),e=!0===this.config.collapsible,i=!1!==this.config.resizable,n=!1!==this.config.showFooter,r={"advanced-filter-container":!0,"is-expanded":this.isExpanded},a={};return this.isExpanded&&this.config.height&&(a.height=this.config.height),s(o,{key:"e08370213e684a3ebed9605b0167010964b03c2a",style:a,class:{"is-resizable":i,"host-expanded":this.isExpanded,"host-collapsed":!this.isExpanded}},s("div",{key:"cec9d9109278df5211e3da4c98aa34f354c7a26a",class:r},e&&s("div",{key:"381f3c02bcbf40aae3db6e7a99803dfe5a0759db",class:"collapsed-view"},s("udp-fluent-text-input",{key:"94c6f902eba20017d3de1c269acb64c7c70d00bf",value:this.filterString,readonly:!0,appearance:"filled-darker",includeErrorPadding:!1,class:"string-display-input"}),s("udp-fluent-button",{key:"94292e13802f60bf7568a3dce0ea28875bacc7df",class:"toggle-button",size:"small",appearance:"transparent",onClick:this.toggleExpanded},s("span",{key:"d1192c982762cb18aad810d435b60271b9486cbb"},this.isExpanded?"Collapse":"Expand"),s("svg",{key:"dd08e210edb45c356190cbd9bb10e8ccaaa6fc36",class:"toggle-icon",viewBox:"0 0 16 16",slot:"end"},s("path",{key:"d946c26d8719e03cd7e21123b471545564df7f76",d:"M4 6L8 10L12 6",stroke:"currentColor","stroke-width":"2"})))),s("div",{key:"6d6771073bed1c5cc5325da92f9eb736d54d2425",class:"anim-container",ref:t=>this.animContainerEl=t},s("div",{key:"b8335dfd2f4a6c6a00f989a00b69af1b93ba1907",class:"content-wrapper"},(this.isExpanded||!e)&&t&&s("udp-advanced-search-filter-group",{key:t.groupId,groupId:t.groupId,filterData:this.currentFilterData,fields:this.fieldsArray,isRoot:!0,isFilterValid:this.isFilterValid,errorMessages:this.errorMessages,maxDepth:this.currentMaxDepth,onAddFilter:t=>this.handleAddFilter(t.detail),onAddGroup:t=>this.handleAddGroup(t.detail),onRemoveFilter:t=>this.handleRemoveFilter(t.detail),onRemoveGroup:t=>this.handleRemoveGroup(t.detail),onFilterChange:this.handleFilterChange,onGroupChange:this.handleGroupChange,onDepthChange:this.handleDepthChange,openAddMenuForGroupId:this.openAddMenuForGroupId,onToggleAddMenu:this.handleToggleAddMenu}))),n&&s("div",{key:"be5d0210862e2a6ef50c4c34e92baac3d7342719",class:"advanced-filter-footer"},s("validation-chip",{key:"d25fd6065f9c7cf9b9879b280738aab85d175344",isValid:this.isFilterValid,errorMessages:this.errorMessages}),s("udp-fluent-button",{key:"bcfb6f8f90c3167aac8ebfdd990a2c145012fb50",disabled:!this.isFilterValid,onClick:this.handleSearch,appearance:"primary"},"Search"))))}get el(){return this}static get watchers(){return{entityName:[{rebuildFieldTree:0}],catalogObjectList:[{rebuildFieldTree:0}],maxDepth:[{syncMaxDepth:0}],initialFilterData:[{syncInitialFilterData:0}]}}static get style(){return":host{display:flex;flex-direction:column;font-family:sans-serif;box-sizing:border-box;overflow:visible}:host(.host-collapsed){resize:none;height:auto}:host(.host-expanded){overflow-y:auto}:host(.is-resizable.host-expanded){resize:vertical;min-height:180px;max-height:80vh;overflow:auto}.advanced-filter-container{display:flex;flex-direction:column;height:100%;width:100%;overflow:hidden}.collapsed-view{display:flex;align-items:center;gap:0.5rem;padding:10px;border-bottom:1px solid #eee}.anim-container{flex-grow:1;overflow-y:auto;overflow-x:auto;display:flex}.content-wrapper{padding-bottom:15px;flex-grow:1}.advanced-filter-footer{display:flex;justify-content:flex-end;border-top:1px solid #eee;padding:10px;flex-shrink:0;gap:10px;align-items:center}.string-display-input{width:100%}.search-button{opacity:0;transform:scale(0.95);pointer-events:none;margin-right:10px}.advanced-filter-container.is-expanded .anim-container{overflow-y:auto;min-height:130px}.advanced-filter-container.is-expanded .collapsed-view{display:none}.advanced-filter-container.is-expanded .search-button{opacity:1;transform:scale(1);pointer-events:auto}.advanced-filter-container:not(.is-expanded) .anim-container{max-height:0;min-height:0;overflow:hidden}.advanced-filter-container:not(.is-expanded) .advanced-filter-footer{opacity:0;height:0;padding:0;border:none;pointer-events:none;overflow:hidden}.drag-overlay{position:fixed;pointer-events:none;z-index:10001;background:var(--colorNeutralBackground1, #ffffff);border:1px solid var(--colorNeutralStroke1, #d1d1d1);border-radius:4px;box-shadow:0 4px 12px rgba(0, 0, 0, 0.12);opacity:0.92;padding:0 12px;height:32px;line-height:32px;font-size:13px;font-family:var(--fontFamilyBase, 'Segoe UI', sans-serif);color:var(--colorNeutralForeground1, #242424);white-space:nowrap;max-width:220px;overflow:hidden;text-overflow:ellipsis}"}},[1,"udp-advanced-search-builder",{catalogObjectList:[16],entityName:[1,"entity-name"],initialFilterData:[16],config:[16],maxDepth:[2,"max-depth"],fieldsArray:[32],openAddMenuForGroupId:[32],filterString:[32],isExpanded:[32],currentFilterData:[32],isFilterValid:[32],errorMessages:[32],currentMaxDepth:[32],addFilterElement:[64]},void 0,{entityName:[{rebuildFieldTree:0}],catalogObjectList:[{rebuildFieldTree:0}],maxDepth:[{syncMaxDepth:0}],initialFilterData:[{syncInitialFilterData:0}]}]),S=A,G=function(){"undefined"!=typeof customElements&&["udp-advanced-search-builder","udp-advanced-search-filter-group","udp-autocomplete","udp-date-input","udp-date-range-selector","udp-date-time-input","udp-fluent-badge","udp-fluent-button","udp-fluent-dropdown","udp-fluent-icon","udp-fluent-icon-button","udp-fluent-menu","udp-fluent-text-input","udp-popover","udp-spinner","udp-text","udp-time-input","udp-tooltip","validation-chip"].forEach((t=>{switch(t){case"udp-advanced-search-builder":customElements.get(n(t))||customElements.define(n(t),A);break;case"udp-advanced-search-filter-group":customElements.get(n(t))||h();break;case"udp-autocomplete":customElements.get(n(t))||d();break;case"udp-date-input":customElements.get(n(t))||u();break;case"udp-date-range-selector":customElements.get(n(t))||c();break;case"udp-date-time-input":customElements.get(n(t))||p();break;case"udp-fluent-badge":customElements.get(n(t))||f();break;case"udp-fluent-button":customElements.get(n(t))||m();break;case"udp-fluent-dropdown":customElements.get(n(t))||b();break;case"udp-fluent-icon":customElements.get(n(t))||v();break;case"udp-fluent-icon-button":customElements.get(n(t))||g();break;case"udp-fluent-menu":customElements.get(n(t))||x();break;case"udp-fluent-text-input":customElements.get(n(t))||y();break;case"udp-popover":customElements.get(n(t))||w();break;case"udp-spinner":customElements.get(n(t))||k();break;case"udp-text":customElements.get(n(t))||F();break;case"udp-time-input":customElements.get(n(t))||j();break;case"udp-tooltip":customElements.get(n(t))||E();break;case"validation-chip":customElements.get(n(t))||D()}}))};export{S as UdpAdvancedSearchBuilder,G as defineCustomElement}
|
|
2
|
+
import{p as t,H as e,c as i,h as s,d as o,t as n}from"./index2.js";import{L as r,a}from"./searchObject.js";import{g as l,d as h}from"./filter-group.js";import{d}from"./udp-autocomplete2.js";import{d as u}from"./udp-date-input2.js";import{d as c}from"./udp-date-range-selector2.js";import{d as p}from"./udp-date-time-input2.js";import{d as f}from"./udp-fluent-badge2.js";import{d as m}from"./udp-fluent-button2.js";import{d as b}from"./udp-fluent-dropdown2.js";import{d as v}from"./udp-fluent-icon2.js";import{d as g}from"./udp-fluent-icon-button2.js";import{d as x}from"./udp-fluent-menu2.js";import{d as y}from"./udp-fluent-text-input2.js";import{d as w}from"./udp-popover2.js";import{d as k}from"./udp-spinner2.js";import{d as F}from"./udp-text2.js";import{d as j}from"./udp-time-input2.js";import{d as E}from"./udp-tooltip2.js";import{d as D}from"./validation-chip2.js";import{b as I}from"./catalogTree.js";class O{constructor(t,e){this.scrollContainer=null,this.isDragStarted=!1,this.pendingItem=null,this.pendingLabel="",this.sourceRowEl=null,this.startX=0,this.startY=0,this.currentState={isDragging:!1,dragItem:null,insertionPoint:null},this.sourceOriginalStyle="",this.draggedItemHeight=0,this.ghostOriginalTop=0,this.placeholder=null,this.overlay=null,this.dropTargets=[],this.previousGapEls=[],this.lockedTarget=null,this.lockedPosition="before",this.autoScrollRAF=null,this.hostEl=t,this.callbacks=e,this.boundPointerDown=this.onPointerDown.bind(this),this.boundPointerMove=this.onPointerMove.bind(this),this.boundPointerUp=this.onPointerUp.bind(this),this.boundKeyDown=this.onKeyDown.bind(this),this.boundScroll=this.onScroll.bind(this),this.hostEl.addEventListener("pointerdown",this.boundPointerDown,!0)}destroy(){this.hostEl.removeEventListener("pointerdown",this.boundPointerDown,!0),this.cleanup()}setScrollContainer(t){this.scrollContainer=t}onPointerDown(t){if(0!==t.button)return;const e=t.composedPath(),i=e.find((t=>t instanceof HTMLElement&&t.hasAttribute("data-drag-handle")));if(!i)return;t.preventDefault();const s=i.dataset.dragType,o=i.dataset.dragId;if(!s||!o)return;const n=e.find((t=>t instanceof HTMLElement&&("filter"===s?t.classList.contains("filter-row"):t.classList.contains("group-box")&&!t.classList.contains("root-group"))));this.pendingItem={type:s,id:o},this.pendingLabel=i.dataset.dragLabel||("filter"===s?"Filter":"Group"),this.sourceRowEl=n||null,this.startX=t.clientX,this.startY=t.clientY,this.isDragStarted=!1,document.addEventListener("pointermove",this.boundPointerMove),document.addEventListener("pointerup",this.boundPointerUp),document.addEventListener("keydown",this.boundKeyDown)}onPointerMove(t){const e=t.clientX-this.startX,i=t.clientY-this.startY;if(!this.isDragStarted){if(Math.sqrt(e*e+i*i)<5)return;this.beginDrag()}this.moveOverlay(t.clientX,t.clientY),this.updateInsertionPoint(t.clientY),this.handleAutoScroll(t.clientY)}onPointerUp(){this.isDragStarted&&this.currentState.insertionPoint&&this.currentState.dragItem&&this.callbacks.onDrop(this.currentState.dragItem,this.currentState.insertionPoint),this.cleanup()}onKeyDown(t){"Escape"===t.key&&this.cleanup()}beginDrag(){var t;if(this.isDragStarted=!0,this.sourceRowEl){const e=this.sourceRowEl.getBoundingClientRect();this.draggedItemHeight=e.height,this.ghostOriginalTop=e.top,this.sourceOriginalStyle=this.sourceRowEl.style.cssText,this.placeholder=document.createElement("div"),this.placeholder.style.height=e.height+"px",this.placeholder.style.pointerEvents="none",null===(t=this.sourceRowEl.parentNode)||void 0===t||t.insertBefore(this.placeholder,this.sourceRowEl.nextSibling),this.sourceRowEl.style.position="fixed",this.sourceRowEl.style.top=e.top+"px",this.sourceRowEl.style.left=e.left+"px",this.sourceRowEl.style.width=e.width+"px",this.sourceRowEl.style.height=e.height+"px",this.sourceRowEl.style.zIndex="10000",this.sourceRowEl.style.opacity="0.35",this.sourceRowEl.style.pointerEvents="none",this.sourceRowEl.style.transition="top 80ms ease-out, left 80ms ease-out, width 80ms ease-out",this.sourceRowEl.style.border="1px dashed var(--colorNeutralStroke1, #d1d1d1)",this.sourceRowEl.style.borderRadius="4px",this.sourceRowEl.style.boxSizing="border-box"}this.collectDropTargets(),this.createOverlay(),this.scrollContainer&&this.scrollContainer.addEventListener("scroll",this.boundScroll,{passive:!0}),document.body.style.cursor="grabbing",document.body.style.userSelect="none",this.currentState={isDragging:!0,dragItem:this.pendingItem,insertionPoint:null},this.callbacks.onStateChange(Object.assign({},this.currentState))}cleanup(){this.placeholder&&(this.placeholder.remove(),this.placeholder=null),this.sourceRowEl&&(this.sourceRowEl.style.cssText=this.sourceOriginalStyle,this.sourceRowEl=null),this.overlay&&(this.overlay.remove(),this.overlay=null),this.clearGap(),null!==this.autoScrollRAF&&(cancelAnimationFrame(this.autoScrollRAF),this.autoScrollRAF=null),this.scrollContainer&&this.scrollContainer.removeEventListener("scroll",this.boundScroll),document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("pointermove",this.boundPointerMove),document.removeEventListener("pointerup",this.boundPointerUp),document.removeEventListener("keydown",this.boundKeyDown),this.pendingItem=null,this.pendingLabel="",this.isDragStarted=!1,this.dropTargets=[],this.draggedItemHeight=0,this.ghostOriginalTop=0,this.sourceOriginalStyle="",this.lockedTarget=null;const t=this.currentState.isDragging;this.currentState={isDragging:!1,dragItem:null,insertionPoint:null},t&&this.callbacks.onStateChange(Object.assign({},this.currentState))}createOverlay(){var t;this.overlay=document.createElement("div"),this.overlay.className="drag-overlay",this.overlay.textContent=this.pendingLabel,null===(t=this.hostEl.shadowRoot)||void 0===t||t.appendChild(this.overlay)}moveOverlay(t,e){this.overlay&&(this.overlay.style.left=t+12+"px",this.overlay.style.top=e-20+"px")}positionGhost(t,e){if(!this.sourceRowEl)return;const i=this.getGapElement(t,e).getBoundingClientRect();let s;s="before"===e?i.top-this.draggedItemHeight:i.bottom;const o=this.getGhostReferenceRect(t,e);this.sourceRowEl.style.top=s+"px",this.sourceRowEl.style.left=o.left+"px",this.sourceRowEl.style.width=o.width+"px"}getGhostReferenceRect(t,e){if("group"===t.type&&"after"===e){const e=t.element.nextElementSibling;if(e){const t=Array.from(e.querySelectorAll(".filter-row, udp-advanced-search-filter-group"));for(const e of t)if(e!==this.sourceRowEl)return e.getBoundingClientRect();const i=e.querySelector(".add-new-container");if(i)return i.getBoundingClientRect()}}return t.element.getBoundingClientRect()}resetGhostPosition(){this.sourceRowEl&&(this.sourceRowEl.style.top=this.ghostOriginalTop+"px")}getGapElement(t,e){if("filter"===t.type)return t.element;if("after"===e)return t.element;const i=t.element.getRootNode();return i instanceof ShadowRoot&&i.host?i.host:t.element}applyGap(t,e){this.placeholder&&(this.placeholder.style.height="0px");const i=this.getGapElement(t,e);for(const t of this.previousGapEls)t!==i&&(t.style.marginTop="",t.style.marginBottom="");i.style.marginTop="",i.style.marginBottom="","before"===e?i.style.marginTop=this.draggedItemHeight+"px":i.style.marginBottom=this.draggedItemHeight+"px",this.previousGapEls=[i]}clearGap(){for(const t of this.previousGapEls)t.style.marginTop="",t.style.marginBottom="";this.previousGapEls=[],this.placeholder&&(this.placeholder.style.height=this.draggedItemHeight+"px")}collectDropTargets(){var t;this.dropTargets=[];const e=this.pendingItem,i=t=>{const s=t.shadowRoot;if(!s)return;s.querySelectorAll(".filter-row[data-filter-id]").forEach((t=>{const i=t.dataset.filterId;"filter"===(null==e?void 0:e.type)&&e.id===i||this.dropTargets.push({type:"filter",id:i,element:t,rect:t.getBoundingClientRect(),midY:0})}));const o=s.querySelector(".group-box[data-group-id]");if(o&&!o.classList.contains("root-group")){const t=o.dataset.groupId;if("group"!==(null==e?void 0:e.type)||e.id!==t){const e=o.querySelector(":scope > .group-header");e&&this.dropTargets.push({type:"group",id:t,element:e,rect:e.getBoundingClientRect(),midY:0})}}s.querySelectorAll("udp-advanced-search-filter-group").forEach((t=>i(t)))},s=null===(t=this.hostEl.shadowRoot)||void 0===t?void 0:t.querySelector("udp-advanced-search-filter-group");s&&i(s);for(const t of this.dropTargets)t.midY=t.rect.top+t.rect.height/2;this.dropTargets.sort(((t,e)=>t.rect.top-e.rect.top))}updateInsertionPoint(t){var e,i;if(0===this.dropTargets.length)return this.clearGap(),this.resetGhostPosition(),this.lockedTarget=null,void this.commitInsertionPoint(null);let s=null,o="before";for(const e of this.dropTargets){const i=e.element.getBoundingClientRect();if(t>=i.top&&t<=i.bottom){s=e,o=t<i.top+i.height/2?"before":"after";break}}if(!s){const n=null===(e=this.dropTargets[0])||void 0===e?void 0:e.element,r=null===(i=this.dropTargets[this.dropTargets.length-1])||void 0===i?void 0:i.element;if(n&&t<n.getBoundingClientRect().top)s=this.dropTargets[0],o="before";else{if(!(r&&t>r.getBoundingClientRect().bottom))return;s=this.dropTargets[this.dropTargets.length-1],o="after"}}if("before"===o){const t=this.dropTargets.indexOf(s);t>0&&(s=this.dropTargets[t-1],o="after")}if(s===this.lockedTarget&&o===this.lockedPosition)return;const n=this.currentState.dragItem||this.pendingItem;if(this.callbacks.isValidDrop&&n&&!this.callbacks.isValidDrop(n,s.type,s.id))return this.clearGap(),this.resetGhostPosition(),this.lockedTarget=null,void this.commitInsertionPoint(null);this.lockedTarget=s,this.lockedPosition=o,this.applyGap(s,o),this.positionGhost(s,o),this.commitInsertionPoint({position:o,targetId:s.id,targetType:s.type})}commitInsertionPoint(t){const e=this.currentState.insertionPoint;(null==e?void 0:e.position)===(null==t?void 0:t.position)&&(null==e?void 0:e.targetId)===(null==t?void 0:t.targetId)&&(null==e?void 0:e.targetType)===(null==t?void 0:t.targetType)||(this.currentState=Object.assign(Object.assign({},this.currentState),{insertionPoint:t}),this.callbacks.onStateChange(Object.assign({},this.currentState)))}handleAutoScroll(t){if(!this.scrollContainer)return;const e=this.scrollContainer.getBoundingClientRect(),i=t-e.top,s=e.bottom-t;let o=0;if(i>0&&i<50?o=-10*(1-i/50):s>0&&s<50&&(o=10*(1-s/50)),null!==this.autoScrollRAF&&(cancelAnimationFrame(this.autoScrollRAF),this.autoScrollRAF=null),0!==o){const t=()=>{this.scrollContainer&&(this.scrollContainer.scrollTop+=o,this.refreshDropTargetRects(),this.autoScrollRAF=requestAnimationFrame(t))};this.autoScrollRAF=requestAnimationFrame(t)}}onScroll(){this.refreshDropTargetRects()}refreshDropTargetRects(){for(const t of this.dropTargets)t.rect=t.element.getBoundingClientRect(),t.midY=t.rect.top+t.rect.height/2}}const A=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.filterSave=i(this,"filterSave",7),this.searchChange=i(this,"searchChange",7),this.config={},this.maxDepth=2,this.fieldsArray=[],this.openAddMenuForGroupId=null,this.filterString="",this.isExpanded=!0,this.isFilterValid=!0,this.errorMessages=[],this.nextGroupId=1,this.handleSearch=()=>{this.isFilterValid&&this.filterSave?(this.filterSave.emit(this.currentFilterData),this.filterString=(t=>{if(!t||!t.filterGroups||0===t.filterGroups.length)return"";const e=i=>{const s=t.filterGroups.find((t=>t.groupId===i));if(!s)return"";const o=s.logicalSearchOperator===r.AND?"AND":"OR",n=[];return t.filterElements.filter((t=>t.groupId===i)).forEach((t=>{n.push(`[${t.searchField}] ${t.searchOperator} ${"string"==typeof t.searchValue?`"${t.searchValue}"`:t.searchValue}`)})),t.filterGroups.filter((t=>t.parentGroupId===i)).forEach((t=>{const i=e(t.groupId);i&&n.push(`(${i})`)})),n.join(` ${o} `)},i=t.filterGroups.find((t=>null===t.parentGroupId));return i?e(i.groupId):""})(this.currentFilterData),this.config.collapsible&&this.toggleExpanded()):console.warn("Cannot run search: filter is invalid.")},this.toggleExpanded=()=>{this.isExpanded=!this.isExpanded,this.updateHostClasses()},this.handleToggleAddMenu=t=>{const e=t.detail;if(this.openAddMenuForGroupId=this.openAddMenuForGroupId===e?null:e,null!==this.openAddMenuForGroupId){const t=this.animContainerEl;t&&requestAnimationFrame((()=>{t.scrollTop=t.scrollHeight}))}},this.handleDragStateChange=()=>{},this.isValidDragDrop=(t,e,i)=>{if("group"===t.type&&"group"===e){const e=parseInt(t.id,10),s=parseInt(i,10);if(e===s)return!1;if(this.isDescendant(s,e,this.currentFilterData.filterGroups))return!1}if("group"===t.type&&"filter"===e){const e=parseInt(t.id,10),s=this.currentFilterData.filterElements.find((t=>t._id===i));if(s){const t=s.groupId;if(t===e||this.isDescendant(t,e,this.currentFilterData.filterGroups))return!1}}return!0},this.handleDragDrop=(t,e)=>{this.runUpdateCycle((i=>{"filter"===t.type?this.applyFilterDrop(i,t,e):"group"===t.type&&this.applyGroupDrop(i,t,e)}))},this.handleAddFilter=t=>{this.runUpdateCycle((e=>{var i,s;const o=null===(i=this.fieldsArray)||void 0===i?void 0:i[0],n=l(o),r=(null===(s=null==n?void 0:n[0])||void 0===s?void 0:s.value)||"";e.filterElements.push({_id:"filter_"+Math.random(),_type:null==o?void 0:o.type,groupId:t,searchField:null==o?void 0:o.name,searchOperator:r,searchValue:""})})),this.openAddMenuForGroupId=null},this.handleAddGroup=t=>{this.runUpdateCycle((e=>{e.filterGroups.push({groupId:this.nextGroupId++,parentGroupId:t,logicalSearchOperator:r.AND})})),this.openAddMenuForGroupId=null},this.handleRemoveFilter=t=>{this.runUpdateCycle((e=>{const i=e.filterElements.findIndex((e=>e._id===t));i>-1&&e.filterElements.splice(i,1)}))},this.handleRemoveGroup=t=>{this.runUpdateCycle((e=>{const i=t=>{const s=e.filterGroups.filter((e=>e.parentGroupId===t));let o=s.map((t=>t.groupId));return s.forEach((t=>{o=[...o,...i(t.groupId)]})),o},s=[t,...i(t)];e.filterGroups=e.filterGroups.filter((t=>!s.includes(t.groupId))),e.filterElements=e.filterElements.filter((t=>!s.includes(t.groupId)))}))},this.handleFilterChange=t=>{const{filterId:e,field:i,value:s,updates:o}=t.detail;this.runUpdateCycle((t=>{const n=t.filterElements.find((t=>t._id===e));n&&(o?Object.assign(n,o):n[i]=s)}))},this.handleDepthChange=t=>{const e=t.detail;"number"==typeof e&&e!==this.currentMaxDepth&&(this.currentMaxDepth=e,this.buildFieldTree())},this.handleGroupChange=t=>{const{groupId:e,logicalSearchOperator:i}=t.detail;this.runUpdateCycle((t=>{const s=t.filterGroups.find((t=>t.groupId===e));s&&(s.logicalSearchOperator=i)}))}}buildFieldTree(){if(this.entityName&&this.catalogObjectList){const t=(t=>{if(!t)return"";const e=t.split(".");return e[e.length-1]})(this.entityName),e=t[0].toUpperCase()+t.slice(1);this.fieldsArray=I(this.catalogObjectList,e,this.currentMaxDepth)}}rebuildFieldTree(){this.buildFieldTree()}syncMaxDepth(t){this.currentMaxDepth=t,this.buildFieldTree()}syncInitialFilterData(t){this.currentFilterData=this.getNormalizedData(t),this.updateNextGroupId(this.currentFilterData)}componentWillLoad(){this.currentMaxDepth=this.maxDepth,this.buildFieldTree(),this.currentFilterData=this.getNormalizedData(this.initialFilterData),this.updateNextGroupId(this.currentFilterData)}componentDidLoad(){this.updateHostClasses(),this.dragManager=new O(this.el,{onStateChange:this.handleDragStateChange,onDrop:this.handleDragDrop,isValidDrop:this.isValidDragDrop}),this.animContainerEl&&this.dragManager.setScrollContainer(this.animContainerEl)}disconnectedCallback(){var t;null===(t=this.dragManager)||void 0===t||t.destroy()}async addFilterElement(t,e){var i,s,o,n;console.log("[addFilterElement] fieldName:",t,"fieldType:",e),console.log("[addFilterElement] fieldsArray names:",this.fieldsArray.map((t=>{var e;return{name:t.name,type:t.type,children:null===(e=t.childFields)||void 0===e?void 0:e.map((t=>t.name))}})));const r=new Set(["object","array"]),a=this.fieldsArray.find((e=>e.name===t));console.log("[addFilterElement] matchedField:",null!==(i=null==a?void 0:a.name)&&void 0!==i?i:"NONE");const h=null!==(o=null!==(s=null==a?void 0:a.type)&&void 0!==s?s:null==e?void 0:e.toLowerCase())&&void 0!==o?o:"string";if(r.has(h))return;const d=l(null!=a?a:{type:h}),u=(null===(n=null==d?void 0:d[0])||void 0===n?void 0:n.value)||"=",c=this.currentFilterData.filterGroups.find((t=>null===t.parentGroupId));this.runUpdateCycle((e=>{var i;e.filterElements.push({_id:"filter_"+Math.random(),_type:h,groupId:null!==(i=null==c?void 0:c.groupId)&&void 0!==i?i:1,searchField:t,searchOperator:u,searchValue:""})}))}updateHostClasses(){this.isExpanded?(this.el.classList.add("host-expanded"),this.el.classList.remove("host-collapsed")):(this.el.classList.add("host-collapsed"),this.el.classList.remove("host-expanded"),this.el.style.height=null)}updateNextGroupId(t){this.nextGroupId=t&&t.filterGroups.length>0?Math.max(...t.filterGroups.map((t=>t.groupId)))+1:2}verifyFilterState(t){const e=[],i=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;for(const i of t.filterGroups){const s=t.filterElements.some((t=>t.groupId===i.groupId)),o=t.filterGroups.some((t=>t.parentGroupId===i.groupId));s||o||e.push((null===i.parentGroupId?"Root group":"A group")+" has no filters. Add a filter or remove the group.")}return t.filterElements.forEach((t=>{delete t._error;const s=!t.searchValue,o=t.searchOperator===a.NULL||t.searchOperator===a.NOT_NULL;if(null==t.searchField||""===t.searchField){const i="Search Field cannot be empty.";t._error=i,e.push(i)}else if(t.searchOperator===a.BETWEEN){const i=(t.searchValue||"").split(",");if(2!==i.length||!i[0]||!i[1]){const i=`Two values required when using BETWEEN operator for field "${t.searchField}".`;t._error=i,e.push(i)}}else if(s&&!o){const i=`Value cannot be empty for field "${t.searchField}".`;t._error=i,e.push(i)}else if("guid"===t._type&&!s&&!i.test(t.searchValue)){const i=`Invalid GUID for field "${t.searchField}".`;t._error=i,e.push(i)}})),{isValid:0===e.length,errors:e}}getNormalizedData(t){var e,i;if(t&&(null===(e=t.filterGroups)||void 0===e?void 0:e.length)>0)return t;if(t&&(null===(i=t.filterElements)||void 0===i?void 0:i.length)>0){const e=1;return Object.assign(Object.assign({},t),{filterGroups:[{groupId:e,parentGroupId:null,logicalSearchOperator:t.logicalSearchOperator||r.AND}],filterElements:t.filterElements.map((t=>Object.assign(Object.assign({},t),{groupId:e})))})}return Object.assign(Object.assign({},t),{logicalSearchOperator:r.AND,filterGroups:[{groupId:1,parentGroupId:null,logicalSearchOperator:r.AND}],filterElements:[]})}runUpdateCycle(t){const e=JSON.parse(JSON.stringify(this.currentFilterData));t(e),this.currentFilterData=e;const i=this.verifyFilterState(e);this.isFilterValid=i.isValid,this.errorMessages=i.errors,this.searchChange.emit(e)}applyFilterDrop(t,e,i){const s=t.filterElements.find((t=>t._id===e.id));if(!s)return;const o=t.filterElements.indexOf(s);if(t.filterElements.splice(o,1),"filter"===i.targetType){const e=t.filterElements.find((t=>t._id===i.targetId));if(!e)return void t.filterElements.push(s);s.groupId=e.groupId;const o=t.filterElements.indexOf(e);t.filterElements.splice("before"===i.position?o:o+1,0,s)}else{const e=parseInt(i.targetId,10),o=t.filterGroups.find((t=>t.groupId===e));s.groupId="before"===i.position&&null!=(null==o?void 0:o.parentGroupId)?o.parentGroupId:e,t.filterElements.push(s)}}applyGroupDrop(t,e,i){const s=parseInt(e.id,10),o=t.filterGroups.find((t=>t.groupId===s));if(o)if("group"===i.targetType){const e=parseInt(i.targetId,10);if(this.isDescendant(e,s,t.filterGroups))return;if(s===e)return;const n=t.filterGroups.find((t=>t.groupId===e));if(!n)return;o.parentGroupId="before"===i.position?n.parentGroupId:e;const r=t.filterGroups.indexOf(o);t.filterGroups.splice(r,1);const a=t.filterGroups.indexOf(n);t.filterGroups.splice("before"===i.position?a:a+1,0,o)}else if("filter"===i.targetType){const e=t.filterElements.find((t=>t._id===i.targetId));e&&(o.parentGroupId=e.groupId)}}isDescendant(t,e,i){let s=i.find((e=>e.groupId===t));for(;s&&null!==s.parentGroupId;){if(s.parentGroupId===e)return!0;s=i.find((t=>t.groupId===s.parentGroupId))}return!1}render(){const t=this.currentFilterData.filterGroups.find((t=>null===t.parentGroupId)),e=!0===this.config.collapsible,i=!1!==this.config.resizable,n=!1!==this.config.showFooter,r={"advanced-filter-container":!0,"is-expanded":this.isExpanded},a={};return this.isExpanded&&this.config.height&&(a.height=this.config.height),s(o,{key:"ab3132a409df0b83da567793d635d13ee9b49d65",style:a,class:{"is-resizable":i,"host-expanded":this.isExpanded,"host-collapsed":!this.isExpanded}},s("div",{key:"b1afe1b4d06b93bf2f2ff5be3cf86ba1b8aa28d8",class:r},e&&s("div",{key:"208924a3e7652fb3cece053e28049ca33d956af5",class:"collapsed-view"},s("udp-fluent-text-input",{key:"b4752482a768ee8cb202e2b22c3243a66597b8ae",value:this.filterString,readonly:!0,appearance:"filled-darker",includeErrorPadding:!1,class:"string-display-input"}),s("udp-fluent-button",{key:"728968a44a5c47e21e0e229522c23e4b7c5d24b3",class:"toggle-button",size:"small",appearance:"transparent",onClick:this.toggleExpanded},s("span",{key:"480b0e5695de7662d52da5f93747e9e5640794cb"},this.isExpanded?"Collapse":"Expand"),s("svg",{key:"56693d725e73fa795a209a06a8edaccf1d2b6fb4",class:"toggle-icon",viewBox:"0 0 16 16",slot:"end"},s("path",{key:"98699d880181e345bc91f70644c0f9c981d40c3b",d:"M4 6L8 10L12 6",stroke:"currentColor","stroke-width":"2"})))),s("div",{key:"1b389df7790880e47e946888e7fe501a2ad5f07d",class:"anim-container",ref:t=>this.animContainerEl=t},s("div",{key:"80e0830959f3513ed6ba0fb2fe866038e636bb2e",class:"content-wrapper"},(this.isExpanded||!e)&&t&&s("udp-advanced-search-filter-group",{key:t.groupId,groupId:t.groupId,filterData:this.currentFilterData,fields:this.fieldsArray,isRoot:!0,isFilterValid:this.isFilterValid,errorMessages:this.errorMessages,maxDepth:this.currentMaxDepth,onAddFilter:t=>this.handleAddFilter(t.detail),onAddGroup:t=>this.handleAddGroup(t.detail),onRemoveFilter:t=>this.handleRemoveFilter(t.detail),onRemoveGroup:t=>this.handleRemoveGroup(t.detail),onFilterChange:this.handleFilterChange,onGroupChange:this.handleGroupChange,onDepthChange:this.handleDepthChange,openAddMenuForGroupId:this.openAddMenuForGroupId,onToggleAddMenu:this.handleToggleAddMenu}))),n&&s("div",{key:"fc72bbb8d13c9d07de966b480e91a082587122a1",class:"advanced-filter-footer"},s("validation-chip",{key:"c2e5d0fa78b7ab310fd43963350214f78ca762be",isValid:this.isFilterValid,errorMessages:this.errorMessages}),s("udp-fluent-button",{key:"6ec8b756b23463bdfdc54cf766d11fd9d40af309",disabled:!this.isFilterValid,onClick:this.handleSearch,appearance:"primary"},"Search"))))}get el(){return this}static get watchers(){return{entityName:[{rebuildFieldTree:0}],catalogObjectList:[{rebuildFieldTree:0}],maxDepth:[{syncMaxDepth:0}],initialFilterData:[{syncInitialFilterData:0}]}}static get style(){return":host{display:flex;flex-direction:column;font-family:sans-serif;box-sizing:border-box;overflow:visible}:host(.host-collapsed){resize:none;height:auto}:host(.host-expanded){overflow-y:auto}:host(.is-resizable.host-expanded){resize:vertical;min-height:180px;max-height:80vh;overflow:auto}.advanced-filter-container{display:flex;flex-direction:column;height:100%;width:100%;overflow:hidden}.collapsed-view{display:flex;align-items:center;gap:0.5rem;padding:10px;border-bottom:1px solid #eee}.anim-container{flex-grow:1;overflow-y:auto;overflow-x:auto;display:flex}.content-wrapper{padding-bottom:15px;flex-grow:1}.advanced-filter-footer{display:flex;justify-content:flex-end;border-top:1px solid #eee;padding:10px;flex-shrink:0;gap:10px;align-items:center}.string-display-input{width:100%}.search-button{opacity:0;transform:scale(0.95);pointer-events:none;margin-right:10px}.advanced-filter-container.is-expanded .anim-container{overflow-y:auto;min-height:130px}.advanced-filter-container.is-expanded .collapsed-view{display:none}.advanced-filter-container.is-expanded .search-button{opacity:1;transform:scale(1);pointer-events:auto}.advanced-filter-container:not(.is-expanded) .anim-container{max-height:0;min-height:0;overflow:hidden}.advanced-filter-container:not(.is-expanded) .advanced-filter-footer{opacity:0;height:0;padding:0;border:none;pointer-events:none;overflow:hidden}.drag-overlay{position:fixed;pointer-events:none;z-index:10001;background:var(--colorNeutralBackground1, #ffffff);border:1px solid var(--colorNeutralStroke1, #d1d1d1);border-radius:4px;box-shadow:0 4px 12px rgba(0, 0, 0, 0.12);opacity:0.92;padding:0 12px;height:32px;line-height:32px;font-size:13px;font-family:var(--fontFamilyBase, 'Segoe UI', sans-serif);color:var(--colorNeutralForeground1, #242424);white-space:nowrap;max-width:220px;overflow:hidden;text-overflow:ellipsis}"}},[1,"udp-advanced-search-builder",{catalogObjectList:[16],entityName:[1,"entity-name"],initialFilterData:[16],config:[16],maxDepth:[2,"max-depth"],fieldsArray:[32],openAddMenuForGroupId:[32],filterString:[32],isExpanded:[32],currentFilterData:[32],isFilterValid:[32],errorMessages:[32],currentMaxDepth:[32],addFilterElement:[64]},void 0,{entityName:[{rebuildFieldTree:0}],catalogObjectList:[{rebuildFieldTree:0}],maxDepth:[{syncMaxDepth:0}],initialFilterData:[{syncInitialFilterData:0}]}]),S=A,G=function(){"undefined"!=typeof customElements&&["udp-advanced-search-builder","udp-advanced-search-filter-group","udp-autocomplete","udp-date-input","udp-date-range-selector","udp-date-time-input","udp-fluent-badge","udp-fluent-button","udp-fluent-dropdown","udp-fluent-icon","udp-fluent-icon-button","udp-fluent-menu","udp-fluent-text-input","udp-popover","udp-spinner","udp-text","udp-time-input","udp-tooltip","validation-chip"].forEach((t=>{switch(t){case"udp-advanced-search-builder":customElements.get(n(t))||customElements.define(n(t),A);break;case"udp-advanced-search-filter-group":customElements.get(n(t))||h();break;case"udp-autocomplete":customElements.get(n(t))||d();break;case"udp-date-input":customElements.get(n(t))||u();break;case"udp-date-range-selector":customElements.get(n(t))||c();break;case"udp-date-time-input":customElements.get(n(t))||p();break;case"udp-fluent-badge":customElements.get(n(t))||f();break;case"udp-fluent-button":customElements.get(n(t))||m();break;case"udp-fluent-dropdown":customElements.get(n(t))||b();break;case"udp-fluent-icon":customElements.get(n(t))||v();break;case"udp-fluent-icon-button":customElements.get(n(t))||g();break;case"udp-fluent-menu":customElements.get(n(t))||x();break;case"udp-fluent-text-input":customElements.get(n(t))||y();break;case"udp-popover":customElements.get(n(t))||w();break;case"udp-spinner":customElements.get(n(t))||k();break;case"udp-text":customElements.get(n(t))||F();break;case"udp-time-input":customElements.get(n(t))||j();break;case"udp-tooltip":customElements.get(n(t))||E();break;case"validation-chip":customElements.get(n(t))||D()}}))};export{S as UdpAdvancedSearchBuilder,G as defineCustomElement}
|
package/dist/docs.json
CHANGED
|
@@ -801,10 +801,13 @@ const UdpAdvancedSearchBuilder = class {
|
|
|
801
801
|
verifyFilterState(data) {
|
|
802
802
|
const errors = [];
|
|
803
803
|
const guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
804
|
-
// Validate groups:
|
|
804
|
+
// Validate groups: a group must contribute something — either its own direct
|
|
805
|
+
// filter or a child group. A container group (children only, no direct filters)
|
|
806
|
+
// is valid; only a truly empty group (no filters and no children) is an error.
|
|
805
807
|
for (const group of data.filterGroups) {
|
|
806
808
|
const hasDirectFilters = data.filterElements.some(f => f.groupId === group.groupId);
|
|
807
|
-
|
|
809
|
+
const hasChildGroups = data.filterGroups.some(g => g.parentGroupId === group.groupId);
|
|
810
|
+
if (!hasDirectFilters && !hasChildGroups) {
|
|
808
811
|
const label = group.parentGroupId === null ? 'Root group' : 'A group';
|
|
809
812
|
errors.push(`${label} has no filters. Add a filter or remove the group.`);
|
|
810
813
|
}
|
|
@@ -958,11 +961,11 @@ const UdpAdvancedSearchBuilder = class {
|
|
|
958
961
|
if (this.isExpanded && this.config.height) {
|
|
959
962
|
hostStyles['height'] = this.config.height;
|
|
960
963
|
}
|
|
961
|
-
return (h(Host, { key: '
|
|
964
|
+
return (h(Host, { key: 'ab3132a409df0b83da567793d635d13ee9b49d65', style: hostStyles, class: {
|
|
962
965
|
'is-resizable': isResizable,
|
|
963
966
|
'host-expanded': this.isExpanded,
|
|
964
967
|
'host-collapsed': !this.isExpanded,
|
|
965
|
-
} }, h("div", { key: '
|
|
968
|
+
} }, h("div", { key: 'b1afe1b4d06b93bf2f2ff5be3cf86ba1b8aa28d8', class: containerClasses }, isCollapsible && (h("div", { key: '208924a3e7652fb3cece053e28049ca33d956af5', class: "collapsed-view" }, h("udp-fluent-text-input", { key: 'b4752482a768ee8cb202e2b22c3243a66597b8ae', value: this.filterString, readonly: true, appearance: "filled-darker", includeErrorPadding: false, class: "string-display-input" }), h("udp-fluent-button", { key: '728968a44a5c47e21e0e229522c23e4b7c5d24b3', class: "toggle-button", size: "small", appearance: "transparent", onClick: this.toggleExpanded }, h("span", { key: '480b0e5695de7662d52da5f93747e9e5640794cb' }, this.isExpanded ? 'Collapse' : 'Expand'), h("svg", { key: '56693d725e73fa795a209a06a8edaccf1d2b6fb4', class: "toggle-icon", viewBox: "0 0 16 16", slot: "end" }, h("path", { key: '98699d880181e345bc91f70644c0f9c981d40c3b', d: "M4 6L8 10L12 6", stroke: "currentColor", "stroke-width": "2" }))))), h("div", { key: '1b389df7790880e47e946888e7fe501a2ad5f07d', class: "anim-container", ref: el => (this.animContainerEl = el) }, h("div", { key: '80e0830959f3513ed6ba0fb2fe866038e636bb2e', class: "content-wrapper" }, (this.isExpanded || !isCollapsible) && rootGroup && (h("udp-advanced-search-filter-group", { key: rootGroup.groupId, groupId: rootGroup.groupId, filterData: this.currentFilterData, fields: this.fieldsArray, isRoot: true, isFilterValid: this.isFilterValid, errorMessages: this.errorMessages, maxDepth: this.currentMaxDepth, onAddFilter: e => this.handleAddFilter(e.detail), onAddGroup: e => this.handleAddGroup(e.detail), onRemoveFilter: e => this.handleRemoveFilter(e.detail), onRemoveGroup: e => this.handleRemoveGroup(e.detail), onFilterChange: this.handleFilterChange, onGroupChange: this.handleGroupChange, onDepthChange: this.handleDepthChange, openAddMenuForGroupId: this.openAddMenuForGroupId, onToggleAddMenu: this.handleToggleAddMenu })))), showFooter && (h("div", { key: 'fc72bbb8d13c9d07de966b480e91a082587122a1', class: "advanced-filter-footer" }, h("validation-chip", { key: 'c2e5d0fa78b7ab310fd43963350214f78ca762be', isValid: this.isFilterValid, errorMessages: this.errorMessages }), h("udp-fluent-button", { key: '6ec8b756b23463bdfdc54cf766d11fd9d40af309', disabled: !this.isFilterValid, onClick: this.handleSearch, appearance: "primary" }, "Search"))))));
|
|
966
969
|
}
|
|
967
970
|
get el() { return getElement(this); }
|
|
968
971
|
static get watchers() { return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t,c as i,h as e,H as s,a as o}from"./index-Cgpvu-iV.js";import{L as n,a as r}from"./searchObject-CDJVsMG_.js";import{g as h}from"./udpOperatorHelper-Tmn9i7-P.js";import{b as l}from"./catalogTree-Ca8SiTsU.js";class a{constructor(t,i){this.scrollContainer=null,this.isDragStarted=!1,this.pendingItem=null,this.pendingLabel="",this.sourceRowEl=null,this.startX=0,this.startY=0,this.currentState={isDragging:!1,dragItem:null,insertionPoint:null},this.sourceOriginalStyle="",this.draggedItemHeight=0,this.ghostOriginalTop=0,this.placeholder=null,this.overlay=null,this.dropTargets=[],this.previousGapEls=[],this.lockedTarget=null,this.lockedPosition="before",this.autoScrollRAF=null,this.hostEl=t,this.callbacks=i,this.boundPointerDown=this.onPointerDown.bind(this),this.boundPointerMove=this.onPointerMove.bind(this),this.boundPointerUp=this.onPointerUp.bind(this),this.boundKeyDown=this.onKeyDown.bind(this),this.boundScroll=this.onScroll.bind(this),this.hostEl.addEventListener("pointerdown",this.boundPointerDown,!0)}destroy(){this.hostEl.removeEventListener("pointerdown",this.boundPointerDown,!0),this.cleanup()}setScrollContainer(t){this.scrollContainer=t}onPointerDown(t){if(0!==t.button)return;const i=t.composedPath(),e=i.find((t=>t instanceof HTMLElement&&t.hasAttribute("data-drag-handle")));if(!e)return;t.preventDefault();const s=e.dataset.dragType,o=e.dataset.dragId;if(!s||!o)return;const n=i.find((t=>t instanceof HTMLElement&&("filter"===s?t.classList.contains("filter-row"):t.classList.contains("group-box")&&!t.classList.contains("root-group"))));this.pendingItem={type:s,id:o},this.pendingLabel=e.dataset.dragLabel||("filter"===s?"Filter":"Group"),this.sourceRowEl=n||null,this.startX=t.clientX,this.startY=t.clientY,this.isDragStarted=!1,document.addEventListener("pointermove",this.boundPointerMove),document.addEventListener("pointerup",this.boundPointerUp),document.addEventListener("keydown",this.boundKeyDown)}onPointerMove(t){const i=t.clientX-this.startX,e=t.clientY-this.startY;if(!this.isDragStarted){if(Math.sqrt(i*i+e*e)<5)return;this.beginDrag()}this.moveOverlay(t.clientX,t.clientY),this.updateInsertionPoint(t.clientY),this.handleAutoScroll(t.clientY)}onPointerUp(){this.isDragStarted&&this.currentState.insertionPoint&&this.currentState.dragItem&&this.callbacks.onDrop(this.currentState.dragItem,this.currentState.insertionPoint),this.cleanup()}onKeyDown(t){"Escape"===t.key&&this.cleanup()}beginDrag(){var t;if(this.isDragStarted=!0,this.sourceRowEl){const i=this.sourceRowEl.getBoundingClientRect();this.draggedItemHeight=i.height,this.ghostOriginalTop=i.top,this.sourceOriginalStyle=this.sourceRowEl.style.cssText,this.placeholder=document.createElement("div"),this.placeholder.style.height=`${i.height}px`,this.placeholder.style.pointerEvents="none",null===(t=this.sourceRowEl.parentNode)||void 0===t||t.insertBefore(this.placeholder,this.sourceRowEl.nextSibling),this.sourceRowEl.style.position="fixed",this.sourceRowEl.style.top=`${i.top}px`,this.sourceRowEl.style.left=`${i.left}px`,this.sourceRowEl.style.width=`${i.width}px`,this.sourceRowEl.style.height=`${i.height}px`,this.sourceRowEl.style.zIndex="10000",this.sourceRowEl.style.opacity="0.35",this.sourceRowEl.style.pointerEvents="none",this.sourceRowEl.style.transition="top 80ms ease-out, left 80ms ease-out, width 80ms ease-out",this.sourceRowEl.style.border="1px dashed var(--colorNeutralStroke1, #d1d1d1)",this.sourceRowEl.style.borderRadius="4px",this.sourceRowEl.style.boxSizing="border-box"}this.collectDropTargets(),this.createOverlay(),this.scrollContainer&&this.scrollContainer.addEventListener("scroll",this.boundScroll,{passive:!0}),document.body.style.cursor="grabbing",document.body.style.userSelect="none",this.currentState={isDragging:!0,dragItem:this.pendingItem,insertionPoint:null},this.callbacks.onStateChange(Object.assign({},this.currentState))}cleanup(){this.placeholder&&(this.placeholder.remove(),this.placeholder=null),this.sourceRowEl&&(this.sourceRowEl.style.cssText=this.sourceOriginalStyle,this.sourceRowEl=null),this.overlay&&(this.overlay.remove(),this.overlay=null),this.clearGap(),null!==this.autoScrollRAF&&(cancelAnimationFrame(this.autoScrollRAF),this.autoScrollRAF=null),this.scrollContainer&&this.scrollContainer.removeEventListener("scroll",this.boundScroll),document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("pointermove",this.boundPointerMove),document.removeEventListener("pointerup",this.boundPointerUp),document.removeEventListener("keydown",this.boundKeyDown),this.pendingItem=null,this.pendingLabel="",this.isDragStarted=!1,this.dropTargets=[],this.draggedItemHeight=0,this.ghostOriginalTop=0,this.sourceOriginalStyle="",this.lockedTarget=null;const t=this.currentState.isDragging;this.currentState={isDragging:!1,dragItem:null,insertionPoint:null},t&&this.callbacks.onStateChange(Object.assign({},this.currentState))}createOverlay(){var t;this.overlay=document.createElement("div"),this.overlay.className="drag-overlay",this.overlay.textContent=this.pendingLabel,null===(t=this.hostEl.shadowRoot)||void 0===t||t.appendChild(this.overlay)}moveOverlay(t,i){this.overlay&&(this.overlay.style.left=`${t+12}px`,this.overlay.style.top=i-20+"px")}positionGhost(t,i){if(!this.sourceRowEl)return;const e=this.getGapElement(t,i).getBoundingClientRect();let s;s="before"===i?e.top-this.draggedItemHeight:e.bottom;const o=this.getGhostReferenceRect(t,i);this.sourceRowEl.style.top=`${s}px`,this.sourceRowEl.style.left=`${o.left}px`,this.sourceRowEl.style.width=`${o.width}px`}getGhostReferenceRect(t,i){if("group"===t.type&&"after"===i){const i=t.element.nextElementSibling;if(i){const t=Array.from(i.querySelectorAll(".filter-row, udp-advanced-search-filter-group"));for(const i of t)if(i!==this.sourceRowEl)return i.getBoundingClientRect();const e=i.querySelector(".add-new-container");if(e)return e.getBoundingClientRect()}}return t.element.getBoundingClientRect()}resetGhostPosition(){this.sourceRowEl&&(this.sourceRowEl.style.top=`${this.ghostOriginalTop}px`)}getGapElement(t,i){if("filter"===t.type)return t.element;if("after"===i)return t.element;const e=t.element.getRootNode();return e instanceof ShadowRoot&&e.host?e.host:t.element}applyGap(t,i){this.placeholder&&(this.placeholder.style.height="0px");const e=this.getGapElement(t,i);for(const t of this.previousGapEls)t!==e&&(t.style.marginTop="",t.style.marginBottom="");e.style.marginTop="",e.style.marginBottom="","before"===i?e.style.marginTop=`${this.draggedItemHeight}px`:e.style.marginBottom=`${this.draggedItemHeight}px`,this.previousGapEls=[e]}clearGap(){for(const t of this.previousGapEls)t.style.marginTop="",t.style.marginBottom="";this.previousGapEls=[],this.placeholder&&(this.placeholder.style.height=`${this.draggedItemHeight}px`)}collectDropTargets(){var t;this.dropTargets=[];const i=this.pendingItem,e=t=>{const s=t.shadowRoot;if(!s)return;s.querySelectorAll(".filter-row[data-filter-id]").forEach((t=>{const e=t.dataset.filterId;"filter"===(null==i?void 0:i.type)&&i.id===e||this.dropTargets.push({type:"filter",id:e,element:t,rect:t.getBoundingClientRect(),midY:0})}));const o=s.querySelector(".group-box[data-group-id]");if(o&&!o.classList.contains("root-group")){const t=o.dataset.groupId;if("group"!==(null==i?void 0:i.type)||i.id!==t){const i=o.querySelector(":scope > .group-header");i&&this.dropTargets.push({type:"group",id:t,element:i,rect:i.getBoundingClientRect(),midY:0})}}s.querySelectorAll("udp-advanced-search-filter-group").forEach((t=>e(t)))},s=null===(t=this.hostEl.shadowRoot)||void 0===t?void 0:t.querySelector("udp-advanced-search-filter-group");s&&e(s);for(const t of this.dropTargets)t.midY=t.rect.top+t.rect.height/2;this.dropTargets.sort(((t,i)=>t.rect.top-i.rect.top))}updateInsertionPoint(t){var i,e;if(0===this.dropTargets.length)return this.clearGap(),this.resetGhostPosition(),this.lockedTarget=null,void this.commitInsertionPoint(null);let s=null,o="before";for(const i of this.dropTargets){const e=i.element.getBoundingClientRect();if(t>=e.top&&t<=e.bottom){s=i,o=t<e.top+e.height/2?"before":"after";break}}if(!s){const n=null===(i=this.dropTargets[0])||void 0===i?void 0:i.element,r=null===(e=this.dropTargets[this.dropTargets.length-1])||void 0===e?void 0:e.element;if(n&&t<n.getBoundingClientRect().top)s=this.dropTargets[0],o="before";else{if(!(r&&t>r.getBoundingClientRect().bottom))return;s=this.dropTargets[this.dropTargets.length-1],o="after"}}if("before"===o){const t=this.dropTargets.indexOf(s);t>0&&(s=this.dropTargets[t-1],o="after")}if(s===this.lockedTarget&&o===this.lockedPosition)return;const n=this.currentState.dragItem||this.pendingItem;if(this.callbacks.isValidDrop&&n&&!this.callbacks.isValidDrop(n,s.type,s.id))return this.clearGap(),this.resetGhostPosition(),this.lockedTarget=null,void this.commitInsertionPoint(null);this.lockedTarget=s,this.lockedPosition=o,this.applyGap(s,o),this.positionGhost(s,o),this.commitInsertionPoint({position:o,targetId:s.id,targetType:s.type})}commitInsertionPoint(t){const i=this.currentState.insertionPoint;(null==i?void 0:i.position)===(null==t?void 0:t.position)&&(null==i?void 0:i.targetId)===(null==t?void 0:t.targetId)&&(null==i?void 0:i.targetType)===(null==t?void 0:t.targetType)||(this.currentState=Object.assign(Object.assign({},this.currentState),{insertionPoint:t}),this.callbacks.onStateChange(Object.assign({},this.currentState)))}handleAutoScroll(t){if(!this.scrollContainer)return;const i=this.scrollContainer.getBoundingClientRect(),e=t-i.top,s=i.bottom-t;let o=0;if(e>0&&e<50?o=-10*(1-e/50):s>0&&s<50&&(o=10*(1-s/50)),null!==this.autoScrollRAF&&(cancelAnimationFrame(this.autoScrollRAF),this.autoScrollRAF=null),0!==o){const t=()=>{this.scrollContainer&&(this.scrollContainer.scrollTop+=o,this.refreshDropTargetRects(),this.autoScrollRAF=requestAnimationFrame(t))};this.autoScrollRAF=requestAnimationFrame(t)}}onScroll(){this.refreshDropTargetRects()}refreshDropTargetRects(){for(const t of this.dropTargets)t.rect=t.element.getBoundingClientRect(),t.midY=t.rect.top+t.rect.height/2}}const d=class{constructor(e){t(this,e),this.filterSave=i(this,"filterSave",7),this.searchChange=i(this,"searchChange",7),this.config={},this.maxDepth=2,this.fieldsArray=[],this.openAddMenuForGroupId=null,this.filterString="",this.isExpanded=!0,this.isFilterValid=!0,this.errorMessages=[],this.nextGroupId=1,this.handleSearch=()=>{this.isFilterValid&&this.filterSave?(this.filterSave.emit(this.currentFilterData),this.filterString=(t=>{if(!t||!t.filterGroups||0===t.filterGroups.length)return"";const i=e=>{const s=t.filterGroups.find((t=>t.groupId===e));if(!s)return"";const o=s.logicalSearchOperator===n.AND?"AND":"OR",r=[];return t.filterElements.filter((t=>t.groupId===e)).forEach((t=>{r.push(`[${t.searchField}] ${t.searchOperator} ${"string"==typeof t.searchValue?`"${t.searchValue}"`:t.searchValue}`)})),t.filterGroups.filter((t=>t.parentGroupId===e)).forEach((t=>{const e=i(t.groupId);e&&r.push(`(${e})`)})),r.join(` ${o} `)},e=t.filterGroups.find((t=>null===t.parentGroupId));return e?i(e.groupId):""})(this.currentFilterData),this.config.collapsible&&this.toggleExpanded()):console.warn("Cannot run search: filter is invalid.")},this.toggleExpanded=()=>{this.isExpanded=!this.isExpanded,this.updateHostClasses()},this.handleToggleAddMenu=t=>{const i=t.detail;if(this.openAddMenuForGroupId=this.openAddMenuForGroupId===i?null:i,null!==this.openAddMenuForGroupId){const t=this.animContainerEl;t&&requestAnimationFrame((()=>{t.scrollTop=t.scrollHeight}))}},this.handleDragStateChange=()=>{},this.isValidDragDrop=(t,i,e)=>{if("group"===t.type&&"group"===i){const i=parseInt(t.id,10),s=parseInt(e,10);if(i===s)return!1;if(this.isDescendant(s,i,this.currentFilterData.filterGroups))return!1}if("group"===t.type&&"filter"===i){const i=parseInt(t.id,10),s=this.currentFilterData.filterElements.find((t=>t._id===e));if(s){const t=s.groupId;if(t===i||this.isDescendant(t,i,this.currentFilterData.filterGroups))return!1}}return!0},this.handleDragDrop=(t,i)=>{this.runUpdateCycle((e=>{"filter"===t.type?this.applyFilterDrop(e,t,i):"group"===t.type&&this.applyGroupDrop(e,t,i)}))},this.handleAddFilter=t=>{this.runUpdateCycle((i=>{var e,s;const o=null===(e=this.fieldsArray)||void 0===e?void 0:e[0],n=h(o),r=(null===(s=null==n?void 0:n[0])||void 0===s?void 0:s.value)||"";i.filterElements.push({_id:`filter_${Math.random()}`,_type:null==o?void 0:o.type,groupId:t,searchField:null==o?void 0:o.name,searchOperator:r,searchValue:""})})),this.openAddMenuForGroupId=null},this.handleAddGroup=t=>{this.runUpdateCycle((i=>{i.filterGroups.push({groupId:this.nextGroupId++,parentGroupId:t,logicalSearchOperator:n.AND})})),this.openAddMenuForGroupId=null},this.handleRemoveFilter=t=>{this.runUpdateCycle((i=>{const e=i.filterElements.findIndex((i=>i._id===t));e>-1&&i.filterElements.splice(e,1)}))},this.handleRemoveGroup=t=>{this.runUpdateCycle((i=>{const e=t=>{const s=i.filterGroups.filter((i=>i.parentGroupId===t));let o=s.map((t=>t.groupId));return s.forEach((t=>{o=[...o,...e(t.groupId)]})),o},s=[t,...e(t)];i.filterGroups=i.filterGroups.filter((t=>!s.includes(t.groupId))),i.filterElements=i.filterElements.filter((t=>!s.includes(t.groupId)))}))},this.handleFilterChange=t=>{const{filterId:i,field:e,value:s,updates:o}=t.detail;this.runUpdateCycle((t=>{const n=t.filterElements.find((t=>t._id===i));n&&(o?Object.assign(n,o):n[e]=s)}))},this.handleDepthChange=t=>{const i=t.detail;"number"==typeof i&&i!==this.currentMaxDepth&&(this.currentMaxDepth=i,this.buildFieldTree())},this.handleGroupChange=t=>{const{groupId:i,logicalSearchOperator:e}=t.detail;this.runUpdateCycle((t=>{const s=t.filterGroups.find((t=>t.groupId===i));s&&(s.logicalSearchOperator=e)}))}}buildFieldTree(){if(this.entityName&&this.catalogObjectList){const t=(t=>{if(!t)return"";const i=t.split(".");return i[i.length-1]})(this.entityName),i=t[0].toUpperCase()+t.slice(1);this.fieldsArray=l(this.catalogObjectList,i,this.currentMaxDepth)}}rebuildFieldTree(){this.buildFieldTree()}syncMaxDepth(t){this.currentMaxDepth=t,this.buildFieldTree()}syncInitialFilterData(t){this.currentFilterData=this.getNormalizedData(t),this.updateNextGroupId(this.currentFilterData)}componentWillLoad(){this.currentMaxDepth=this.maxDepth,this.buildFieldTree(),this.currentFilterData=this.getNormalizedData(this.initialFilterData),this.updateNextGroupId(this.currentFilterData)}componentDidLoad(){this.updateHostClasses(),this.dragManager=new a(this.el,{onStateChange:this.handleDragStateChange,onDrop:this.handleDragDrop,isValidDrop:this.isValidDragDrop}),this.animContainerEl&&this.dragManager.setScrollContainer(this.animContainerEl)}disconnectedCallback(){var t;null===(t=this.dragManager)||void 0===t||t.destroy()}async addFilterElement(t,i){var e,s,o,n;console.log("[addFilterElement] fieldName:",t,"fieldType:",i),console.log("[addFilterElement] fieldsArray names:",this.fieldsArray.map((t=>{var i;return{name:t.name,type:t.type,children:null===(i=t.childFields)||void 0===i?void 0:i.map((t=>t.name))}})));const r=new Set(["object","array"]),l=this.fieldsArray.find((i=>i.name===t));console.log("[addFilterElement] matchedField:",null!==(e=null==l?void 0:l.name)&&void 0!==e?e:"NONE");const a=null!==(o=null!==(s=null==l?void 0:l.type)&&void 0!==s?s:null==i?void 0:i.toLowerCase())&&void 0!==o?o:"string";if(r.has(a))return;const d=h(null!=l?l:{type:a}),c=(null===(n=null==d?void 0:d[0])||void 0===n?void 0:n.value)||"=",u=this.currentFilterData.filterGroups.find((t=>null===t.parentGroupId));this.runUpdateCycle((i=>{var e;i.filterElements.push({_id:`filter_${Math.random()}`,_type:a,groupId:null!==(e=null==u?void 0:u.groupId)&&void 0!==e?e:1,searchField:t,searchOperator:c,searchValue:""})}))}updateHostClasses(){this.isExpanded?(this.el.classList.add("host-expanded"),this.el.classList.remove("host-collapsed")):(this.el.classList.add("host-collapsed"),this.el.classList.remove("host-expanded"),this.el.style.height=null)}updateNextGroupId(t){this.nextGroupId=t&&t.filterGroups.length>0?Math.max(...t.filterGroups.map((t=>t.groupId)))+1:2}verifyFilterState(t){const i=[],e=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;for(const e of t.filterGroups)t.filterElements.some((t=>t.groupId===e.groupId))||i.push((null===e.parentGroupId?"Root group":"A group")+" has no filters. Add a filter or remove the group.");return t.filterElements.forEach((t=>{delete t._error;const s=!t.searchValue,o=t.searchOperator===r.NULL||t.searchOperator===r.NOT_NULL;if(null==t.searchField||""===t.searchField){const e="Search Field cannot be empty.";t._error=e,i.push(e)}else if(t.searchOperator===r.BETWEEN){const e=(t.searchValue||"").split(",");if(2!==e.length||!e[0]||!e[1]){const e=`Two values required when using BETWEEN operator for field "${t.searchField}".`;t._error=e,i.push(e)}}else if(s&&!o){const e=`Value cannot be empty for field "${t.searchField}".`;t._error=e,i.push(e)}else if("guid"===t._type&&!s&&!e.test(t.searchValue)){const e=`Invalid GUID for field "${t.searchField}".`;t._error=e,i.push(e)}})),{isValid:0===i.length,errors:i}}getNormalizedData(t){var i,e;if(t&&(null===(i=t.filterGroups)||void 0===i?void 0:i.length)>0)return t;if(t&&(null===(e=t.filterElements)||void 0===e?void 0:e.length)>0){const i=1;return Object.assign(Object.assign({},t),{filterGroups:[{groupId:i,parentGroupId:null,logicalSearchOperator:t.logicalSearchOperator||n.AND}],filterElements:t.filterElements.map((t=>Object.assign(Object.assign({},t),{groupId:i})))})}return Object.assign(Object.assign({},t),{logicalSearchOperator:n.AND,filterGroups:[{groupId:1,parentGroupId:null,logicalSearchOperator:n.AND}],filterElements:[]})}runUpdateCycle(t){const i=JSON.parse(JSON.stringify(this.currentFilterData));t(i),this.currentFilterData=i;const e=this.verifyFilterState(i);this.isFilterValid=e.isValid,this.errorMessages=e.errors,this.searchChange.emit(i)}applyFilterDrop(t,i,e){const s=t.filterElements.find((t=>t._id===i.id));if(!s)return;const o=t.filterElements.indexOf(s);if(t.filterElements.splice(o,1),"filter"===e.targetType){const i=t.filterElements.find((t=>t._id===e.targetId));if(!i)return void t.filterElements.push(s);s.groupId=i.groupId;const o=t.filterElements.indexOf(i);t.filterElements.splice("before"===e.position?o:o+1,0,s)}else{const i=parseInt(e.targetId,10),o=t.filterGroups.find((t=>t.groupId===i));s.groupId="before"===e.position&&null!=(null==o?void 0:o.parentGroupId)?o.parentGroupId:i,t.filterElements.push(s)}}applyGroupDrop(t,i,e){const s=parseInt(i.id,10),o=t.filterGroups.find((t=>t.groupId===s));if(o)if("group"===e.targetType){const i=parseInt(e.targetId,10);if(this.isDescendant(i,s,t.filterGroups))return;if(s===i)return;const n=t.filterGroups.find((t=>t.groupId===i));if(!n)return;o.parentGroupId="before"===e.position?n.parentGroupId:i;const r=t.filterGroups.indexOf(o);t.filterGroups.splice(r,1);const h=t.filterGroups.indexOf(n);t.filterGroups.splice("before"===e.position?h:h+1,0,o)}else if("filter"===e.targetType){const i=t.filterElements.find((t=>t._id===e.targetId));i&&(o.parentGroupId=i.groupId)}}isDescendant(t,i,e){let s=e.find((i=>i.groupId===t));for(;s&&null!==s.parentGroupId;){if(s.parentGroupId===i)return!0;s=e.find((t=>t.groupId===s.parentGroupId))}return!1}render(){const t=this.currentFilterData.filterGroups.find((t=>null===t.parentGroupId)),i=!0===this.config.collapsible,o=!1!==this.config.resizable,n=!1!==this.config.showFooter,r={"advanced-filter-container":!0,"is-expanded":this.isExpanded},h={};return this.isExpanded&&this.config.height&&(h.height=this.config.height),e(s,{key:"e08370213e684a3ebed9605b0167010964b03c2a",style:h,class:{"is-resizable":o,"host-expanded":this.isExpanded,"host-collapsed":!this.isExpanded}},e("div",{key:"cec9d9109278df5211e3da4c98aa34f354c7a26a",class:r},i&&e("div",{key:"381f3c02bcbf40aae3db6e7a99803dfe5a0759db",class:"collapsed-view"},e("udp-fluent-text-input",{key:"94c6f902eba20017d3de1c269acb64c7c70d00bf",value:this.filterString,readonly:!0,appearance:"filled-darker",includeErrorPadding:!1,class:"string-display-input"}),e("udp-fluent-button",{key:"94292e13802f60bf7568a3dce0ea28875bacc7df",class:"toggle-button",size:"small",appearance:"transparent",onClick:this.toggleExpanded},e("span",{key:"d1192c982762cb18aad810d435b60271b9486cbb"},this.isExpanded?"Collapse":"Expand"),e("svg",{key:"dd08e210edb45c356190cbd9bb10e8ccaaa6fc36",class:"toggle-icon",viewBox:"0 0 16 16",slot:"end"},e("path",{key:"d946c26d8719e03cd7e21123b471545564df7f76",d:"M4 6L8 10L12 6",stroke:"currentColor","stroke-width":"2"})))),e("div",{key:"6d6771073bed1c5cc5325da92f9eb736d54d2425",class:"anim-container",ref:t=>this.animContainerEl=t},e("div",{key:"b8335dfd2f4a6c6a00f989a00b69af1b93ba1907",class:"content-wrapper"},(this.isExpanded||!i)&&t&&e("udp-advanced-search-filter-group",{key:t.groupId,groupId:t.groupId,filterData:this.currentFilterData,fields:this.fieldsArray,isRoot:!0,isFilterValid:this.isFilterValid,errorMessages:this.errorMessages,maxDepth:this.currentMaxDepth,onAddFilter:t=>this.handleAddFilter(t.detail),onAddGroup:t=>this.handleAddGroup(t.detail),onRemoveFilter:t=>this.handleRemoveFilter(t.detail),onRemoveGroup:t=>this.handleRemoveGroup(t.detail),onFilterChange:this.handleFilterChange,onGroupChange:this.handleGroupChange,onDepthChange:this.handleDepthChange,openAddMenuForGroupId:this.openAddMenuForGroupId,onToggleAddMenu:this.handleToggleAddMenu}))),n&&e("div",{key:"be5d0210862e2a6ef50c4c34e92baac3d7342719",class:"advanced-filter-footer"},e("validation-chip",{key:"d25fd6065f9c7cf9b9879b280738aab85d175344",isValid:this.isFilterValid,errorMessages:this.errorMessages}),e("udp-fluent-button",{key:"bcfb6f8f90c3167aac8ebfdd990a2c145012fb50",disabled:!this.isFilterValid,onClick:this.handleSearch,appearance:"primary"},"Search"))))}get el(){return o(this)}static get watchers(){return{entityName:[{rebuildFieldTree:0}],catalogObjectList:[{rebuildFieldTree:0}],maxDepth:[{syncMaxDepth:0}],initialFilterData:[{syncInitialFilterData:0}]}}};d.style=":host{display:flex;flex-direction:column;font-family:sans-serif;box-sizing:border-box;overflow:visible}:host(.host-collapsed){resize:none;height:auto}:host(.host-expanded){overflow-y:auto}:host(.is-resizable.host-expanded){resize:vertical;min-height:180px;max-height:80vh;overflow:auto}.advanced-filter-container{display:flex;flex-direction:column;height:100%;width:100%;overflow:hidden}.collapsed-view{display:flex;align-items:center;gap:0.5rem;padding:10px;border-bottom:1px solid #eee}.anim-container{flex-grow:1;overflow-y:auto;overflow-x:auto;display:flex}.content-wrapper{padding-bottom:15px;flex-grow:1}.advanced-filter-footer{display:flex;justify-content:flex-end;border-top:1px solid #eee;padding:10px;flex-shrink:0;gap:10px;align-items:center}.string-display-input{width:100%}.search-button{opacity:0;transform:scale(0.95);pointer-events:none;margin-right:10px}.advanced-filter-container.is-expanded .anim-container{overflow-y:auto;min-height:130px}.advanced-filter-container.is-expanded .collapsed-view{display:none}.advanced-filter-container.is-expanded .search-button{opacity:1;transform:scale(1);pointer-events:auto}.advanced-filter-container:not(.is-expanded) .anim-container{max-height:0;min-height:0;overflow:hidden}.advanced-filter-container:not(.is-expanded) .advanced-filter-footer{opacity:0;height:0;padding:0;border:none;pointer-events:none;overflow:hidden}.drag-overlay{position:fixed;pointer-events:none;z-index:10001;background:var(--colorNeutralBackground1, #ffffff);border:1px solid var(--colorNeutralStroke1, #d1d1d1);border-radius:4px;box-shadow:0 4px 12px rgba(0, 0, 0, 0.12);opacity:0.92;padding:0 12px;height:32px;line-height:32px;font-size:13px;font-family:var(--fontFamilyBase, 'Segoe UI', sans-serif);color:var(--colorNeutralForeground1, #242424);white-space:nowrap;max-width:220px;overflow:hidden;text-overflow:ellipsis}";export{d as udp_advanced_search_builder}
|
|
1
|
+
import{r as t,c as i,h as e,H as s,a as o}from"./index-Cgpvu-iV.js";import{L as n,a as r}from"./searchObject-CDJVsMG_.js";import{g as h}from"./udpOperatorHelper-Tmn9i7-P.js";import{b as l}from"./catalogTree-Ca8SiTsU.js";class a{constructor(t,i){this.scrollContainer=null,this.isDragStarted=!1,this.pendingItem=null,this.pendingLabel="",this.sourceRowEl=null,this.startX=0,this.startY=0,this.currentState={isDragging:!1,dragItem:null,insertionPoint:null},this.sourceOriginalStyle="",this.draggedItemHeight=0,this.ghostOriginalTop=0,this.placeholder=null,this.overlay=null,this.dropTargets=[],this.previousGapEls=[],this.lockedTarget=null,this.lockedPosition="before",this.autoScrollRAF=null,this.hostEl=t,this.callbacks=i,this.boundPointerDown=this.onPointerDown.bind(this),this.boundPointerMove=this.onPointerMove.bind(this),this.boundPointerUp=this.onPointerUp.bind(this),this.boundKeyDown=this.onKeyDown.bind(this),this.boundScroll=this.onScroll.bind(this),this.hostEl.addEventListener("pointerdown",this.boundPointerDown,!0)}destroy(){this.hostEl.removeEventListener("pointerdown",this.boundPointerDown,!0),this.cleanup()}setScrollContainer(t){this.scrollContainer=t}onPointerDown(t){if(0!==t.button)return;const i=t.composedPath(),e=i.find((t=>t instanceof HTMLElement&&t.hasAttribute("data-drag-handle")));if(!e)return;t.preventDefault();const s=e.dataset.dragType,o=e.dataset.dragId;if(!s||!o)return;const n=i.find((t=>t instanceof HTMLElement&&("filter"===s?t.classList.contains("filter-row"):t.classList.contains("group-box")&&!t.classList.contains("root-group"))));this.pendingItem={type:s,id:o},this.pendingLabel=e.dataset.dragLabel||("filter"===s?"Filter":"Group"),this.sourceRowEl=n||null,this.startX=t.clientX,this.startY=t.clientY,this.isDragStarted=!1,document.addEventListener("pointermove",this.boundPointerMove),document.addEventListener("pointerup",this.boundPointerUp),document.addEventListener("keydown",this.boundKeyDown)}onPointerMove(t){const i=t.clientX-this.startX,e=t.clientY-this.startY;if(!this.isDragStarted){if(Math.sqrt(i*i+e*e)<5)return;this.beginDrag()}this.moveOverlay(t.clientX,t.clientY),this.updateInsertionPoint(t.clientY),this.handleAutoScroll(t.clientY)}onPointerUp(){this.isDragStarted&&this.currentState.insertionPoint&&this.currentState.dragItem&&this.callbacks.onDrop(this.currentState.dragItem,this.currentState.insertionPoint),this.cleanup()}onKeyDown(t){"Escape"===t.key&&this.cleanup()}beginDrag(){var t;if(this.isDragStarted=!0,this.sourceRowEl){const i=this.sourceRowEl.getBoundingClientRect();this.draggedItemHeight=i.height,this.ghostOriginalTop=i.top,this.sourceOriginalStyle=this.sourceRowEl.style.cssText,this.placeholder=document.createElement("div"),this.placeholder.style.height=`${i.height}px`,this.placeholder.style.pointerEvents="none",null===(t=this.sourceRowEl.parentNode)||void 0===t||t.insertBefore(this.placeholder,this.sourceRowEl.nextSibling),this.sourceRowEl.style.position="fixed",this.sourceRowEl.style.top=`${i.top}px`,this.sourceRowEl.style.left=`${i.left}px`,this.sourceRowEl.style.width=`${i.width}px`,this.sourceRowEl.style.height=`${i.height}px`,this.sourceRowEl.style.zIndex="10000",this.sourceRowEl.style.opacity="0.35",this.sourceRowEl.style.pointerEvents="none",this.sourceRowEl.style.transition="top 80ms ease-out, left 80ms ease-out, width 80ms ease-out",this.sourceRowEl.style.border="1px dashed var(--colorNeutralStroke1, #d1d1d1)",this.sourceRowEl.style.borderRadius="4px",this.sourceRowEl.style.boxSizing="border-box"}this.collectDropTargets(),this.createOverlay(),this.scrollContainer&&this.scrollContainer.addEventListener("scroll",this.boundScroll,{passive:!0}),document.body.style.cursor="grabbing",document.body.style.userSelect="none",this.currentState={isDragging:!0,dragItem:this.pendingItem,insertionPoint:null},this.callbacks.onStateChange(Object.assign({},this.currentState))}cleanup(){this.placeholder&&(this.placeholder.remove(),this.placeholder=null),this.sourceRowEl&&(this.sourceRowEl.style.cssText=this.sourceOriginalStyle,this.sourceRowEl=null),this.overlay&&(this.overlay.remove(),this.overlay=null),this.clearGap(),null!==this.autoScrollRAF&&(cancelAnimationFrame(this.autoScrollRAF),this.autoScrollRAF=null),this.scrollContainer&&this.scrollContainer.removeEventListener("scroll",this.boundScroll),document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("pointermove",this.boundPointerMove),document.removeEventListener("pointerup",this.boundPointerUp),document.removeEventListener("keydown",this.boundKeyDown),this.pendingItem=null,this.pendingLabel="",this.isDragStarted=!1,this.dropTargets=[],this.draggedItemHeight=0,this.ghostOriginalTop=0,this.sourceOriginalStyle="",this.lockedTarget=null;const t=this.currentState.isDragging;this.currentState={isDragging:!1,dragItem:null,insertionPoint:null},t&&this.callbacks.onStateChange(Object.assign({},this.currentState))}createOverlay(){var t;this.overlay=document.createElement("div"),this.overlay.className="drag-overlay",this.overlay.textContent=this.pendingLabel,null===(t=this.hostEl.shadowRoot)||void 0===t||t.appendChild(this.overlay)}moveOverlay(t,i){this.overlay&&(this.overlay.style.left=`${t+12}px`,this.overlay.style.top=i-20+"px")}positionGhost(t,i){if(!this.sourceRowEl)return;const e=this.getGapElement(t,i).getBoundingClientRect();let s;s="before"===i?e.top-this.draggedItemHeight:e.bottom;const o=this.getGhostReferenceRect(t,i);this.sourceRowEl.style.top=`${s}px`,this.sourceRowEl.style.left=`${o.left}px`,this.sourceRowEl.style.width=`${o.width}px`}getGhostReferenceRect(t,i){if("group"===t.type&&"after"===i){const i=t.element.nextElementSibling;if(i){const t=Array.from(i.querySelectorAll(".filter-row, udp-advanced-search-filter-group"));for(const i of t)if(i!==this.sourceRowEl)return i.getBoundingClientRect();const e=i.querySelector(".add-new-container");if(e)return e.getBoundingClientRect()}}return t.element.getBoundingClientRect()}resetGhostPosition(){this.sourceRowEl&&(this.sourceRowEl.style.top=`${this.ghostOriginalTop}px`)}getGapElement(t,i){if("filter"===t.type)return t.element;if("after"===i)return t.element;const e=t.element.getRootNode();return e instanceof ShadowRoot&&e.host?e.host:t.element}applyGap(t,i){this.placeholder&&(this.placeholder.style.height="0px");const e=this.getGapElement(t,i);for(const t of this.previousGapEls)t!==e&&(t.style.marginTop="",t.style.marginBottom="");e.style.marginTop="",e.style.marginBottom="","before"===i?e.style.marginTop=`${this.draggedItemHeight}px`:e.style.marginBottom=`${this.draggedItemHeight}px`,this.previousGapEls=[e]}clearGap(){for(const t of this.previousGapEls)t.style.marginTop="",t.style.marginBottom="";this.previousGapEls=[],this.placeholder&&(this.placeholder.style.height=`${this.draggedItemHeight}px`)}collectDropTargets(){var t;this.dropTargets=[];const i=this.pendingItem,e=t=>{const s=t.shadowRoot;if(!s)return;s.querySelectorAll(".filter-row[data-filter-id]").forEach((t=>{const e=t.dataset.filterId;"filter"===(null==i?void 0:i.type)&&i.id===e||this.dropTargets.push({type:"filter",id:e,element:t,rect:t.getBoundingClientRect(),midY:0})}));const o=s.querySelector(".group-box[data-group-id]");if(o&&!o.classList.contains("root-group")){const t=o.dataset.groupId;if("group"!==(null==i?void 0:i.type)||i.id!==t){const i=o.querySelector(":scope > .group-header");i&&this.dropTargets.push({type:"group",id:t,element:i,rect:i.getBoundingClientRect(),midY:0})}}s.querySelectorAll("udp-advanced-search-filter-group").forEach((t=>e(t)))},s=null===(t=this.hostEl.shadowRoot)||void 0===t?void 0:t.querySelector("udp-advanced-search-filter-group");s&&e(s);for(const t of this.dropTargets)t.midY=t.rect.top+t.rect.height/2;this.dropTargets.sort(((t,i)=>t.rect.top-i.rect.top))}updateInsertionPoint(t){var i,e;if(0===this.dropTargets.length)return this.clearGap(),this.resetGhostPosition(),this.lockedTarget=null,void this.commitInsertionPoint(null);let s=null,o="before";for(const i of this.dropTargets){const e=i.element.getBoundingClientRect();if(t>=e.top&&t<=e.bottom){s=i,o=t<e.top+e.height/2?"before":"after";break}}if(!s){const n=null===(i=this.dropTargets[0])||void 0===i?void 0:i.element,r=null===(e=this.dropTargets[this.dropTargets.length-1])||void 0===e?void 0:e.element;if(n&&t<n.getBoundingClientRect().top)s=this.dropTargets[0],o="before";else{if(!(r&&t>r.getBoundingClientRect().bottom))return;s=this.dropTargets[this.dropTargets.length-1],o="after"}}if("before"===o){const t=this.dropTargets.indexOf(s);t>0&&(s=this.dropTargets[t-1],o="after")}if(s===this.lockedTarget&&o===this.lockedPosition)return;const n=this.currentState.dragItem||this.pendingItem;if(this.callbacks.isValidDrop&&n&&!this.callbacks.isValidDrop(n,s.type,s.id))return this.clearGap(),this.resetGhostPosition(),this.lockedTarget=null,void this.commitInsertionPoint(null);this.lockedTarget=s,this.lockedPosition=o,this.applyGap(s,o),this.positionGhost(s,o),this.commitInsertionPoint({position:o,targetId:s.id,targetType:s.type})}commitInsertionPoint(t){const i=this.currentState.insertionPoint;(null==i?void 0:i.position)===(null==t?void 0:t.position)&&(null==i?void 0:i.targetId)===(null==t?void 0:t.targetId)&&(null==i?void 0:i.targetType)===(null==t?void 0:t.targetType)||(this.currentState=Object.assign(Object.assign({},this.currentState),{insertionPoint:t}),this.callbacks.onStateChange(Object.assign({},this.currentState)))}handleAutoScroll(t){if(!this.scrollContainer)return;const i=this.scrollContainer.getBoundingClientRect(),e=t-i.top,s=i.bottom-t;let o=0;if(e>0&&e<50?o=-10*(1-e/50):s>0&&s<50&&(o=10*(1-s/50)),null!==this.autoScrollRAF&&(cancelAnimationFrame(this.autoScrollRAF),this.autoScrollRAF=null),0!==o){const t=()=>{this.scrollContainer&&(this.scrollContainer.scrollTop+=o,this.refreshDropTargetRects(),this.autoScrollRAF=requestAnimationFrame(t))};this.autoScrollRAF=requestAnimationFrame(t)}}onScroll(){this.refreshDropTargetRects()}refreshDropTargetRects(){for(const t of this.dropTargets)t.rect=t.element.getBoundingClientRect(),t.midY=t.rect.top+t.rect.height/2}}const d=class{constructor(e){t(this,e),this.filterSave=i(this,"filterSave",7),this.searchChange=i(this,"searchChange",7),this.config={},this.maxDepth=2,this.fieldsArray=[],this.openAddMenuForGroupId=null,this.filterString="",this.isExpanded=!0,this.isFilterValid=!0,this.errorMessages=[],this.nextGroupId=1,this.handleSearch=()=>{this.isFilterValid&&this.filterSave?(this.filterSave.emit(this.currentFilterData),this.filterString=(t=>{if(!t||!t.filterGroups||0===t.filterGroups.length)return"";const i=e=>{const s=t.filterGroups.find((t=>t.groupId===e));if(!s)return"";const o=s.logicalSearchOperator===n.AND?"AND":"OR",r=[];return t.filterElements.filter((t=>t.groupId===e)).forEach((t=>{r.push(`[${t.searchField}] ${t.searchOperator} ${"string"==typeof t.searchValue?`"${t.searchValue}"`:t.searchValue}`)})),t.filterGroups.filter((t=>t.parentGroupId===e)).forEach((t=>{const e=i(t.groupId);e&&r.push(`(${e})`)})),r.join(` ${o} `)},e=t.filterGroups.find((t=>null===t.parentGroupId));return e?i(e.groupId):""})(this.currentFilterData),this.config.collapsible&&this.toggleExpanded()):console.warn("Cannot run search: filter is invalid.")},this.toggleExpanded=()=>{this.isExpanded=!this.isExpanded,this.updateHostClasses()},this.handleToggleAddMenu=t=>{const i=t.detail;if(this.openAddMenuForGroupId=this.openAddMenuForGroupId===i?null:i,null!==this.openAddMenuForGroupId){const t=this.animContainerEl;t&&requestAnimationFrame((()=>{t.scrollTop=t.scrollHeight}))}},this.handleDragStateChange=()=>{},this.isValidDragDrop=(t,i,e)=>{if("group"===t.type&&"group"===i){const i=parseInt(t.id,10),s=parseInt(e,10);if(i===s)return!1;if(this.isDescendant(s,i,this.currentFilterData.filterGroups))return!1}if("group"===t.type&&"filter"===i){const i=parseInt(t.id,10),s=this.currentFilterData.filterElements.find((t=>t._id===e));if(s){const t=s.groupId;if(t===i||this.isDescendant(t,i,this.currentFilterData.filterGroups))return!1}}return!0},this.handleDragDrop=(t,i)=>{this.runUpdateCycle((e=>{"filter"===t.type?this.applyFilterDrop(e,t,i):"group"===t.type&&this.applyGroupDrop(e,t,i)}))},this.handleAddFilter=t=>{this.runUpdateCycle((i=>{var e,s;const o=null===(e=this.fieldsArray)||void 0===e?void 0:e[0],n=h(o),r=(null===(s=null==n?void 0:n[0])||void 0===s?void 0:s.value)||"";i.filterElements.push({_id:`filter_${Math.random()}`,_type:null==o?void 0:o.type,groupId:t,searchField:null==o?void 0:o.name,searchOperator:r,searchValue:""})})),this.openAddMenuForGroupId=null},this.handleAddGroup=t=>{this.runUpdateCycle((i=>{i.filterGroups.push({groupId:this.nextGroupId++,parentGroupId:t,logicalSearchOperator:n.AND})})),this.openAddMenuForGroupId=null},this.handleRemoveFilter=t=>{this.runUpdateCycle((i=>{const e=i.filterElements.findIndex((i=>i._id===t));e>-1&&i.filterElements.splice(e,1)}))},this.handleRemoveGroup=t=>{this.runUpdateCycle((i=>{const e=t=>{const s=i.filterGroups.filter((i=>i.parentGroupId===t));let o=s.map((t=>t.groupId));return s.forEach((t=>{o=[...o,...e(t.groupId)]})),o},s=[t,...e(t)];i.filterGroups=i.filterGroups.filter((t=>!s.includes(t.groupId))),i.filterElements=i.filterElements.filter((t=>!s.includes(t.groupId)))}))},this.handleFilterChange=t=>{const{filterId:i,field:e,value:s,updates:o}=t.detail;this.runUpdateCycle((t=>{const n=t.filterElements.find((t=>t._id===i));n&&(o?Object.assign(n,o):n[e]=s)}))},this.handleDepthChange=t=>{const i=t.detail;"number"==typeof i&&i!==this.currentMaxDepth&&(this.currentMaxDepth=i,this.buildFieldTree())},this.handleGroupChange=t=>{const{groupId:i,logicalSearchOperator:e}=t.detail;this.runUpdateCycle((t=>{const s=t.filterGroups.find((t=>t.groupId===i));s&&(s.logicalSearchOperator=e)}))}}buildFieldTree(){if(this.entityName&&this.catalogObjectList){const t=(t=>{if(!t)return"";const i=t.split(".");return i[i.length-1]})(this.entityName),i=t[0].toUpperCase()+t.slice(1);this.fieldsArray=l(this.catalogObjectList,i,this.currentMaxDepth)}}rebuildFieldTree(){this.buildFieldTree()}syncMaxDepth(t){this.currentMaxDepth=t,this.buildFieldTree()}syncInitialFilterData(t){this.currentFilterData=this.getNormalizedData(t),this.updateNextGroupId(this.currentFilterData)}componentWillLoad(){this.currentMaxDepth=this.maxDepth,this.buildFieldTree(),this.currentFilterData=this.getNormalizedData(this.initialFilterData),this.updateNextGroupId(this.currentFilterData)}componentDidLoad(){this.updateHostClasses(),this.dragManager=new a(this.el,{onStateChange:this.handleDragStateChange,onDrop:this.handleDragDrop,isValidDrop:this.isValidDragDrop}),this.animContainerEl&&this.dragManager.setScrollContainer(this.animContainerEl)}disconnectedCallback(){var t;null===(t=this.dragManager)||void 0===t||t.destroy()}async addFilterElement(t,i){var e,s,o,n;console.log("[addFilterElement] fieldName:",t,"fieldType:",i),console.log("[addFilterElement] fieldsArray names:",this.fieldsArray.map((t=>{var i;return{name:t.name,type:t.type,children:null===(i=t.childFields)||void 0===i?void 0:i.map((t=>t.name))}})));const r=new Set(["object","array"]),l=this.fieldsArray.find((i=>i.name===t));console.log("[addFilterElement] matchedField:",null!==(e=null==l?void 0:l.name)&&void 0!==e?e:"NONE");const a=null!==(o=null!==(s=null==l?void 0:l.type)&&void 0!==s?s:null==i?void 0:i.toLowerCase())&&void 0!==o?o:"string";if(r.has(a))return;const d=h(null!=l?l:{type:a}),c=(null===(n=null==d?void 0:d[0])||void 0===n?void 0:n.value)||"=",u=this.currentFilterData.filterGroups.find((t=>null===t.parentGroupId));this.runUpdateCycle((i=>{var e;i.filterElements.push({_id:`filter_${Math.random()}`,_type:a,groupId:null!==(e=null==u?void 0:u.groupId)&&void 0!==e?e:1,searchField:t,searchOperator:c,searchValue:""})}))}updateHostClasses(){this.isExpanded?(this.el.classList.add("host-expanded"),this.el.classList.remove("host-collapsed")):(this.el.classList.add("host-collapsed"),this.el.classList.remove("host-expanded"),this.el.style.height=null)}updateNextGroupId(t){this.nextGroupId=t&&t.filterGroups.length>0?Math.max(...t.filterGroups.map((t=>t.groupId)))+1:2}verifyFilterState(t){const i=[],e=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;for(const e of t.filterGroups){const s=t.filterElements.some((t=>t.groupId===e.groupId)),o=t.filterGroups.some((t=>t.parentGroupId===e.groupId));s||o||i.push((null===e.parentGroupId?"Root group":"A group")+" has no filters. Add a filter or remove the group.")}return t.filterElements.forEach((t=>{delete t._error;const s=!t.searchValue,o=t.searchOperator===r.NULL||t.searchOperator===r.NOT_NULL;if(null==t.searchField||""===t.searchField){const e="Search Field cannot be empty.";t._error=e,i.push(e)}else if(t.searchOperator===r.BETWEEN){const e=(t.searchValue||"").split(",");if(2!==e.length||!e[0]||!e[1]){const e=`Two values required when using BETWEEN operator for field "${t.searchField}".`;t._error=e,i.push(e)}}else if(s&&!o){const e=`Value cannot be empty for field "${t.searchField}".`;t._error=e,i.push(e)}else if("guid"===t._type&&!s&&!e.test(t.searchValue)){const e=`Invalid GUID for field "${t.searchField}".`;t._error=e,i.push(e)}})),{isValid:0===i.length,errors:i}}getNormalizedData(t){var i,e;if(t&&(null===(i=t.filterGroups)||void 0===i?void 0:i.length)>0)return t;if(t&&(null===(e=t.filterElements)||void 0===e?void 0:e.length)>0){const i=1;return Object.assign(Object.assign({},t),{filterGroups:[{groupId:i,parentGroupId:null,logicalSearchOperator:t.logicalSearchOperator||n.AND}],filterElements:t.filterElements.map((t=>Object.assign(Object.assign({},t),{groupId:i})))})}return Object.assign(Object.assign({},t),{logicalSearchOperator:n.AND,filterGroups:[{groupId:1,parentGroupId:null,logicalSearchOperator:n.AND}],filterElements:[]})}runUpdateCycle(t){const i=JSON.parse(JSON.stringify(this.currentFilterData));t(i),this.currentFilterData=i;const e=this.verifyFilterState(i);this.isFilterValid=e.isValid,this.errorMessages=e.errors,this.searchChange.emit(i)}applyFilterDrop(t,i,e){const s=t.filterElements.find((t=>t._id===i.id));if(!s)return;const o=t.filterElements.indexOf(s);if(t.filterElements.splice(o,1),"filter"===e.targetType){const i=t.filterElements.find((t=>t._id===e.targetId));if(!i)return void t.filterElements.push(s);s.groupId=i.groupId;const o=t.filterElements.indexOf(i);t.filterElements.splice("before"===e.position?o:o+1,0,s)}else{const i=parseInt(e.targetId,10),o=t.filterGroups.find((t=>t.groupId===i));s.groupId="before"===e.position&&null!=(null==o?void 0:o.parentGroupId)?o.parentGroupId:i,t.filterElements.push(s)}}applyGroupDrop(t,i,e){const s=parseInt(i.id,10),o=t.filterGroups.find((t=>t.groupId===s));if(o)if("group"===e.targetType){const i=parseInt(e.targetId,10);if(this.isDescendant(i,s,t.filterGroups))return;if(s===i)return;const n=t.filterGroups.find((t=>t.groupId===i));if(!n)return;o.parentGroupId="before"===e.position?n.parentGroupId:i;const r=t.filterGroups.indexOf(o);t.filterGroups.splice(r,1);const h=t.filterGroups.indexOf(n);t.filterGroups.splice("before"===e.position?h:h+1,0,o)}else if("filter"===e.targetType){const i=t.filterElements.find((t=>t._id===e.targetId));i&&(o.parentGroupId=i.groupId)}}isDescendant(t,i,e){let s=e.find((i=>i.groupId===t));for(;s&&null!==s.parentGroupId;){if(s.parentGroupId===i)return!0;s=e.find((t=>t.groupId===s.parentGroupId))}return!1}render(){const t=this.currentFilterData.filterGroups.find((t=>null===t.parentGroupId)),i=!0===this.config.collapsible,o=!1!==this.config.resizable,n=!1!==this.config.showFooter,r={"advanced-filter-container":!0,"is-expanded":this.isExpanded},h={};return this.isExpanded&&this.config.height&&(h.height=this.config.height),e(s,{key:"ab3132a409df0b83da567793d635d13ee9b49d65",style:h,class:{"is-resizable":o,"host-expanded":this.isExpanded,"host-collapsed":!this.isExpanded}},e("div",{key:"b1afe1b4d06b93bf2f2ff5be3cf86ba1b8aa28d8",class:r},i&&e("div",{key:"208924a3e7652fb3cece053e28049ca33d956af5",class:"collapsed-view"},e("udp-fluent-text-input",{key:"b4752482a768ee8cb202e2b22c3243a66597b8ae",value:this.filterString,readonly:!0,appearance:"filled-darker",includeErrorPadding:!1,class:"string-display-input"}),e("udp-fluent-button",{key:"728968a44a5c47e21e0e229522c23e4b7c5d24b3",class:"toggle-button",size:"small",appearance:"transparent",onClick:this.toggleExpanded},e("span",{key:"480b0e5695de7662d52da5f93747e9e5640794cb"},this.isExpanded?"Collapse":"Expand"),e("svg",{key:"56693d725e73fa795a209a06a8edaccf1d2b6fb4",class:"toggle-icon",viewBox:"0 0 16 16",slot:"end"},e("path",{key:"98699d880181e345bc91f70644c0f9c981d40c3b",d:"M4 6L8 10L12 6",stroke:"currentColor","stroke-width":"2"})))),e("div",{key:"1b389df7790880e47e946888e7fe501a2ad5f07d",class:"anim-container",ref:t=>this.animContainerEl=t},e("div",{key:"80e0830959f3513ed6ba0fb2fe866038e636bb2e",class:"content-wrapper"},(this.isExpanded||!i)&&t&&e("udp-advanced-search-filter-group",{key:t.groupId,groupId:t.groupId,filterData:this.currentFilterData,fields:this.fieldsArray,isRoot:!0,isFilterValid:this.isFilterValid,errorMessages:this.errorMessages,maxDepth:this.currentMaxDepth,onAddFilter:t=>this.handleAddFilter(t.detail),onAddGroup:t=>this.handleAddGroup(t.detail),onRemoveFilter:t=>this.handleRemoveFilter(t.detail),onRemoveGroup:t=>this.handleRemoveGroup(t.detail),onFilterChange:this.handleFilterChange,onGroupChange:this.handleGroupChange,onDepthChange:this.handleDepthChange,openAddMenuForGroupId:this.openAddMenuForGroupId,onToggleAddMenu:this.handleToggleAddMenu}))),n&&e("div",{key:"fc72bbb8d13c9d07de966b480e91a082587122a1",class:"advanced-filter-footer"},e("validation-chip",{key:"c2e5d0fa78b7ab310fd43963350214f78ca762be",isValid:this.isFilterValid,errorMessages:this.errorMessages}),e("udp-fluent-button",{key:"6ec8b756b23463bdfdc54cf766d11fd9d40af309",disabled:!this.isFilterValid,onClick:this.handleSearch,appearance:"primary"},"Search"))))}get el(){return o(this)}static get watchers(){return{entityName:[{rebuildFieldTree:0}],catalogObjectList:[{rebuildFieldTree:0}],maxDepth:[{syncMaxDepth:0}],initialFilterData:[{syncInitialFilterData:0}]}}};d.style=":host{display:flex;flex-direction:column;font-family:sans-serif;box-sizing:border-box;overflow:visible}:host(.host-collapsed){resize:none;height:auto}:host(.host-expanded){overflow-y:auto}:host(.is-resizable.host-expanded){resize:vertical;min-height:180px;max-height:80vh;overflow:auto}.advanced-filter-container{display:flex;flex-direction:column;height:100%;width:100%;overflow:hidden}.collapsed-view{display:flex;align-items:center;gap:0.5rem;padding:10px;border-bottom:1px solid #eee}.anim-container{flex-grow:1;overflow-y:auto;overflow-x:auto;display:flex}.content-wrapper{padding-bottom:15px;flex-grow:1}.advanced-filter-footer{display:flex;justify-content:flex-end;border-top:1px solid #eee;padding:10px;flex-shrink:0;gap:10px;align-items:center}.string-display-input{width:100%}.search-button{opacity:0;transform:scale(0.95);pointer-events:none;margin-right:10px}.advanced-filter-container.is-expanded .anim-container{overflow-y:auto;min-height:130px}.advanced-filter-container.is-expanded .collapsed-view{display:none}.advanced-filter-container.is-expanded .search-button{opacity:1;transform:scale(1);pointer-events:auto}.advanced-filter-container:not(.is-expanded) .anim-container{max-height:0;min-height:0;overflow:hidden}.advanced-filter-container:not(.is-expanded) .advanced-filter-footer{opacity:0;height:0;padding:0;border:none;pointer-events:none;overflow:hidden}.drag-overlay{position:fixed;pointer-events:none;z-index:10001;background:var(--colorNeutralBackground1, #ffffff);border:1px solid var(--colorNeutralStroke1, #d1d1d1);border-radius:4px;box-shadow:0 4px 12px rgba(0, 0, 0, 0.12);opacity:0.92;padding:0 12px;height:32px;line-height:32px;font-size:13px;font-family:var(--fontFamilyBase, 'Segoe UI', sans-serif);color:var(--colorNeutralForeground1, #242424);white-space:nowrap;max-width:220px;overflow:hidden;text-overflow:ellipsis}";export{d as udp_advanced_search_builder}
|