@base-framework/organisms
Version:
This will add default organisms to the base framework.
3 lines (2 loc) • 1.35 kB
JavaScript
var r=class{constructor({layout:t,itemProperty:s,customCompare:e,skipFirst:i=!1}){this.layout=t,this.itemProperty=s,this.customCompare=e,this.skipFirst=i,this.lastAppend=null,this.lastPrepend=null,this.lastDividerValue=null,this.prependBoundary=null}reset(){this.lastAppend=null,this.lastPrepend=null,this.lastDividerValue=null,this.prependBoundary=null}setPrependBoundary(t){if(t){let s=this.getValue(t);this.lastPrepend=s,this.prependBoundary=s}else this.prependBoundary=null}setFirstValues(t){let s=this.lastAppend;return s||(this.lastAppend=t,this.lastPrepend=t),!s}append(t,s){this.prependBoundary=null;let e=this.getValue(t),i=this.setFirstValues(e);if(i&&!this.skipFirst){this.addDivider(e,s);return}i||(this.compare(this.lastAppend,e)&&this.addDivider(e,s),this.lastAppend=e)}getValue(t){return t[this.itemProperty]??null}prepend(t,s){let e=this.getValue(t);if(this.setFirstValues(e)){this.addDivider(e,s);return}this.compare(this.lastPrepend,e)&&this.addDivider(e,s),this.lastPrepend=e}compare(t,s){return this.customCompare?this.customCompare(t,s):t!==s}addDivider(t,s){if(!this.layout||!s||this.lastDividerValue!==null&&this.compare(this.lastDividerValue,t)===!1)return;let e=this.layout(t);e&&typeof e=="object"&&(e["data-divider"]="true"),s.push(e),this.lastDividerValue=t}};export{r as a};
//# sourceMappingURL=chunk-QSKZOXBV.js.map