@aiquants/contact-map 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { b as ContactRecordForTree, c as ContactMapTreeNaming, C as ContactMapDirectoryEntry } from "./tree-types-CDq16q63.mjs";
2
2
  export { D as DEFAULT_LIST_LAYOUT_SPEC, d as DEFAULT_TREE_LAYOUT_SPEC, R as ResponsiveLayoutSpec, a as ResponsiveThresholds, e as calculateResponsiveThresholds, g as getHysteresisBreakpointState } from "./tree-types-CDq16q63.mjs";
3
- import { e as SearchResultEntry, C as ContactRecord } from "./wire-hAxBVVH6.mjs";
4
- export { d as ContactMapLogger, c as ContactMapOutletContext, b as ContactMapSearchOutletContext, a as ContactMapStreamPhase, f as ContactMapStreamState, F as FieldPerformanceMetric, I as IndexWorkerMetrics, J as JsonSerialized, L as LevenshteinWorkerMetrics, S as SerializedContactStreamRow, g as StreamChunkWire, h as StreamCursor, i as StreamErrorWire, j as StreamLineWire, k as StreamMetadataWire, l as defaultLogger } from "./wire-hAxBVVH6.mjs";
3
+ import { e as SearchResultEntry, C as ContactRecord } from "./wire-BghOEeyw.mjs";
4
+ export { d as ContactMapLogger, c as ContactMapOutletContext, b as ContactMapSearchOutletContext, a as ContactMapStreamPhase, f as ContactMapStreamState, F as FieldPerformanceMetric, I as IndexWorkerMetrics, J as JsonSerialized, L as LevenshteinWorkerMetrics, S as SerializedContactStreamRow, g as StreamChunkWire, h as StreamCursor, i as StreamErrorWire, j as StreamLineWire, k as StreamMetadataWire, l as defaultLogger } from "./wire-BghOEeyw.mjs";
5
5
  import { z } from "zod";
6
6
  declare const assertContactMapTreeNaming: (naming: ContactMapTreeNaming) => void;
7
7
  declare class IncrementalTreeBuilder<T extends ContactRecordForTree = ContactRecordForTree> {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { b as ContactRecordForTree, c as ContactMapTreeNaming, C as ContactMapDirectoryEntry } from "./tree-types-CDq16q63.js";
2
2
  export { D as DEFAULT_LIST_LAYOUT_SPEC, d as DEFAULT_TREE_LAYOUT_SPEC, R as ResponsiveLayoutSpec, a as ResponsiveThresholds, e as calculateResponsiveThresholds, g as getHysteresisBreakpointState } from "./tree-types-CDq16q63.js";
3
- import { e as SearchResultEntry, C as ContactRecord } from "./wire-hAxBVVH6.js";
4
- export { d as ContactMapLogger, c as ContactMapOutletContext, b as ContactMapSearchOutletContext, a as ContactMapStreamPhase, f as ContactMapStreamState, F as FieldPerformanceMetric, I as IndexWorkerMetrics, J as JsonSerialized, L as LevenshteinWorkerMetrics, S as SerializedContactStreamRow, g as StreamChunkWire, h as StreamCursor, i as StreamErrorWire, j as StreamLineWire, k as StreamMetadataWire, l as defaultLogger } from "./wire-hAxBVVH6.js";
3
+ import { e as SearchResultEntry, C as ContactRecord } from "./wire-BghOEeyw.js";
4
+ export { d as ContactMapLogger, c as ContactMapOutletContext, b as ContactMapSearchOutletContext, a as ContactMapStreamPhase, f as ContactMapStreamState, F as FieldPerformanceMetric, I as IndexWorkerMetrics, J as JsonSerialized, L as LevenshteinWorkerMetrics, S as SerializedContactStreamRow, g as StreamChunkWire, h as StreamCursor, i as StreamErrorWire, j as StreamLineWire, k as StreamMetadataWire, l as defaultLogger } from "./wire-BghOEeyw.js";
5
5
  import { z } from "zod";
6
6
  declare const assertContactMapTreeNaming: (naming: ContactMapTreeNaming) => void;
7
7
  declare class IncrementalTreeBuilder<T extends ContactRecordForTree = ContactRecordForTree> {
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var L=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var le=(e,t)=>{for(var r in t)L(e,r,{get:t[r],enumerable:!0})},pe=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of ie(t))!se.call(e,a)&&a!==r&&L(e,a,{get:()=>t[a],enumerable:!(o=ae(t,a))||o.enumerable});return e};var ce=e=>pe(L({},"__esModule",{value:!0}),e);var je={};le(je,{DEFAULT_LIST_LAYOUT_SPEC:()=>_e,DEFAULT_TREE_LAYOUT_SPEC:()=>Ee,IncrementalTreeBuilder:()=>N,StandardDepartmentParser:()=>F,TitleBasedDepartmentParser:()=>A,assertContactMapTreeNaming:()=>Q,buildDirectoryTree:()=>De,calculateResponsiveThresholds:()=>Me,createExactMatchRanker:()=>Be,createSearchQueryPattern:()=>ne,defaultLogger:()=>We,extractContactData:()=>Te,extractDepartmentsFromTitle:()=>I,formatDate:()=>ke,formatDateTime:()=>X,getEmailLinkHref:()=>Se,getHysteresisBreakpointState:()=>Oe,getPhoneDialHref:()=>Pe,getPrimaryEmail:()=>xe,getPrimaryPhone:()=>Ce,getSearchQuerySpellings:()=>te,normalizeLabel:()=>E,normalizeSearchInput:()=>ee,normalizeString:()=>O,schemaContactRecord:()=>re,schemaContactRecords:()=>Ke,splitDepartment:()=>U,toDisplayValue:()=>Re});module.exports=ce(je);var E=(e,t)=>e&&e.trim()||t;var ue={\u672C\u90E8:{rank:10,type:"Organization"},\u30AB\u30F3\u30D1\u30CB\u30FC:{rank:10,type:"Organization"},\u672C\u793E:{rank:10,type:"Location"},\u30D6\u30ED\u30C3\u30AF:{rank:11,type:"Location"},\u652F\u5E97:{rank:12,type:"Location"},\u7814\u7A76\u6240:{rank:15,type:"Location"},\u5DE5\u5834:{rank:15,type:"Location"},\u4E8B\u696D\u90E8:{rank:18,type:"Organization"},\u90E8\u9580:{rank:18,type:"Organization"},\u7D71\u62EC\u90E8:{rank:19,type:"Organization"},\u90E8:{rank:20,type:"Organization"},\u958B\u767A:{rank:20,type:"Organization"},\u30B0\u30EB\u30FC\u30D7:{rank:22,type:"Organization"},\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8:{rank:25,type:"Organization"},\u63A8\u9032:{rank:20,type:"Organization"},\u4E8B\u696D\u6240:{rank:25,type:"Location"},\u55B6\u696D\u6240:{rank:28,type:"Location"},\u5BA4:{rank:30,type:"Organization"},\u8AB2:{rank:30,type:"Organization"},\u30BB\u30F3\u30BF\u30FC:{rank:30,type:"Location"},\u30D3\u30B8\u30CD\u30B9\u30D7\u30ED\u30C7\u30E5\u30FC\u30B9\u30BB\u30F3\u30BF\u30FC:{rank:30,type:"Location"},\u30C1\u30FC\u30E0:{rank:40,type:"Organization"},\u4FC2:{rank:50,type:"Organization"},Department:{rank:20,type:"Organization"},Dept:{rank:20,type:"Organization"},"Dept.":{rank:20,type:"Organization"},Division:{rank:20,type:"Organization"},Div:{rank:20,type:"Organization"},"Div.":{rank:20,type:"Organization"},Section:{rank:30,type:"Organization"},Sect:{rank:30,type:"Organization"},"Sect.":{rank:30,type:"Organization"},Unit:{rank:30,type:"Organization"},Group:{rank:22,type:"Organization"},Team:{rank:40,type:"Organization"},Branch:{rank:12,type:"Location"},Office:{rank:28,type:"Location"},Center:{rank:30,type:"Location"},Centre:{rank:30,type:"Location"},HQ:{rank:10,type:"Organization"},Headquarters:{rank:10,type:"Organization"}},R=e=>{for(let[t,r]of Object.entries(ue))if(e.endsWith(t))return r;return{rank:99,type:"Other"}},j=e=>R(e).rank,de=["\u30B0\u30EB\u30FC\u30D7","\u30C1\u30FC\u30E0","Group","Team","\u5BA4","\u8AB2","Unit","Area","\u90E8","Department","Dept","Division","Div","\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8","\u63A8\u9032"],_=e=>de.find(t=>e.endsWith(t)),me=new Set(["&","Quality","Innovation","R&D","Solutions","Development","Laboratory","and","Food","Beverage"]),fe=(e,t)=>t>1&&(e.endsWith("\u652F\u5E97")||e.endsWith("\u672C\u90E8")||e.endsWith("\u4E8B\u696D\u6240")||e.endsWith("\u5DE5\u5834")),he=(e,t)=>{if(!t)return!0;let r=R(e),o=R(t);if(r.rank<o.rank||e.endsWith("\u672C\u90E8")&&t.endsWith("\u672C\u90E8"))return!1;let a=_(e),m=_(t);return!(a&&m&&a!==m)},W=(e,t)=>{if(!e)return[];if(e==="\u517C")return["\u517C"];if(e==="\u517C\u52D9")return["\u517C"];if(e.startsWith("\u517C ")||e.startsWith("\u517C\u3000")){let o=e.slice(1).trim();return["\u517C",...W(o,t)]}if(e.startsWith("\u517C\u52D9 ")||e.startsWith("\u517C\u52D9\u3000")){let o=e.slice(2).trim();return["\u517C",...W(o,t)]}let r="";for(let o=e.length-1;o>0;o--){if(e[o]!==" ")continue;let a=e.slice(0,o);if(!me.has(a)&&t.has(a)){r=a;break}}if(r){let o=r,a=e.slice(r.length),m=/^\s+(and|&)\s+([A-Za-z0-9]+)/i,b=a.match(m);b&&(o=e.slice(0,r.length+b[0].length));let c=e.slice(o.length),n=["Department","Dept","Division","Div","Section","Sect","Unit","Group","Team","Branch","Office","Center","Centre","HQ","Headquarters"];for(let i of n){let y=new RegExp(`^\\s+${i}\\.?(?=$|[\\s,])`,"i"),p=c.match(y);if(p){o=e.slice(0,o.length+p[0].length);break}}let f=e.slice(o.length).trim();return[o,...W(f,t)]}return[e]},U=(e,t)=>{let o=e.replace(/[\s\u3000]+(?:兼務|兼)[\s\u3000]+/g,"\u3000\u517C\u3000").replace(/^(?:兼務|兼)[\s\u3000]+/,"\u517C\u3000").replace(/[\s\u3000]+(?:兼務|兼)$/,"\u3000\u517C").split(/\u3000/),a=[];for(let m of o){let b=m.trim();b&&a.push(...W(b,t))}return a},I=(e,t)=>{let r=[],o=["\u90E8","\u8AB2","\u5BA4","\u672C\u90E8","\u652F\u5E97","\u55B6\u696D\u6240","\u30B0\u30EB\u30FC\u30D7","\u30C1\u30FC\u30E0","\u30BB\u30F3\u30BF\u30FC","\u30AB\u30F3\u30D1\u30CB\u30FC","\u4E8B\u696D\u6240","\u5DE5\u5834","\u7814\u7A76\u6240","\u4FC2","\u90E8\u9580","\u4E8B\u696D\u90E8","\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8","\u63A8\u9032","\u958B\u767A","Department","Dept","Division","Div","Section","Sect","Unit","Group","Team","Branch","Office","Center","Centre","HQ","Headquarters"],a=e.split(/[\s\u3000,()()[\]]+/).filter(Boolean),m=a.length,b=new Set;for(let c=m;c>=1;c--)for(let n=0;n<=m-c;n++){let f=!1;for(let y=n;y<n+c;y++)if(b.has(y)){f=!0;break}if(f)continue;let i=a.slice(n,n+c).join(" ");if(!(i==="\u517C"||i==="\u517C\u52D9"||i==="\u4FC2"||i==="of"||i==="&"||i==="Quality"||i==="Innovation"||i==="R&D"||i==="Solutions"||i==="Development"||i==="Laboratory"||i==="and"||i==="Food"||i==="Beverage")&&t.allKnownDepartments.has(i)){r.push({name:i,index:n});for(let y=n;y<n+c;y++)b.add(y)}}for(let c=0;c<m;c++){if(b.has(c))continue;let n=a[c];for(n.endsWith("\u9577")&&n.length>1?n=n.slice(0,-1):n.endsWith("\u7D71\u62EC")&&n.length>2&&(n=n.slice(0,-2));;){let p=!1;if(n.startsWith("\u62C5\u5F53")&&n.length>2||n.startsWith("\u5C02\u4EFB")&&n.length>2||n.startsWith("\u517C\u52D9")&&n.length>2?(n=n.slice(2),p=!0):(n.startsWith("\u526F")||n.startsWith("\u517C"))&&n.length>1&&(n=n.slice(1),p=!0),!p)break}if(n.includes("\u30FB")&&!t.allKnownDepartments.has(n)){let p=n.split("\u30FB"),D=p[p.length-1],x=o.find(k=>D.endsWith(k));if(x){for(let k of p){let C=k;o.some(s=>C.endsWith(s))||(C=C+x);let P=n!=="\u517C"&&n!=="\u4FC2"&&n!=="of"&&n!=="&"&&n!=="Quality"&&n!=="Innovation"&&n!=="R&D"&&n!=="Solutions"&&n!=="Development"&&n!=="Laboratory"&&n!=="and"&&n!=="Food"&&n!=="Beverage"&&t.allKnownDepartments.has(C),d=o.some(s=>C.endsWith(s)),l=o.includes(C);(P||d&&!l)&&r.push({name:C,index:c})}continue}}let f=n!=="\u517C"&&n!=="\u4FC2"&&n!=="of"&&n!=="&"&&n!=="Quality"&&n!=="Innovation"&&n!=="R&D"&&n!=="Solutions"&&n!=="Development"&&n!=="Laboratory"&&n!=="and"&&n!=="Food"&&n!=="Beverage"&&t.allKnownDepartments.has(n),i=o.some(p=>n.endsWith(p)),y=o.includes(n);(f||i&&!y)&&r.push({name:n,index:c})}return r.sort((c,n)=>c.index-n.index),r.map(c=>c.name)},v=(e,t)=>{let r=0;for(let o of t)r<e.length&&o===e[r]&&r++;return r===e.length},F={name:"Standard",parse:(e,t,r="full")=>{let o=E(e.department,"");if(!o)return null;let a=U(o,t.allKnownDepartments),m=new Map;for(let n of a)m.set(n,(m.get(n)||0)+1);let b=n=>{let f=[],i=[];for(let y=0;y<n.length;y++){let p=n[y];if(p==="\u517C"){i.length>0&&(f.push(i),i=[]);continue}let D=R(p),x=D.rank,k=m.get(p)||0,C=fe(p,k);if(i.length===0)i.push(p);else{let P=i[i.length-1],d=R(P),l=d.rank;if(i.includes(p))f.push(i),i=[p];else{let s=!1;if(C)s=!0;else if(d.type===D.type){let g=_(P),h=_(p);g&&h&&g!==h||P.endsWith("\u672C\u90E8")&&p.endsWith("\u672C\u90E8")||P.endsWith("\u90E8\u9580")&&p.endsWith("\u4E8B\u696D\u90E8")||P.endsWith("\u4E8B\u696D\u90E8")&&p.endsWith("\u90E8\u9580")||P.endsWith("\u90E8\u9580")&&p.endsWith("\u672C\u90E8")||d.type==="Other"&&D.type==="Other"?s=!0:s=l<x}else s=x>=10,s&&d.type==="Location"&&D.type==="Organization"&&l>=x&&n.slice(y+1).includes(P)&&(s=!1);s?i.push(p):(f.push(i),i=[p])}}if(C){let P=y+1<n.length?n[y+1]:void 0;he(p,P)&&i.length>0&&(f.push(i),i=[])}}return i.length>0&&f.push(i),f},c=[];if(r==="full"&&c.push(...b(a)),r==="pure_org"){let n=a.filter(f=>R(f).type!=="Location");n.length>0&&c.push(...b(n))}if(e.title){let f=/[^\x20-\x7E]/.test(e.title)?/[\s\u3000]*(?:兼務|兼)[\s\u3000]*/:/[,;]|(?:兼務|兼)/,i=e.title.split(f).filter(Boolean),y=[],p=(d,l)=>{let s=j(d),g=j(l),h=s<g;if(!h){let T=_(d),S=_(l);if(T&&S&&T!==S)h=!0;else if(d.endsWith("\u672C\u90E8")&&l.endsWith("\u672C\u90E8"))h=!0;else if(d.endsWith("\u90E8\u9580")&&l.endsWith("\u4E8B\u696D\u90E8")||d.endsWith("\u4E8B\u696D\u90E8")&&l.endsWith("\u90E8\u9580"))h=!0;else if(d.endsWith("\u90E8\u9580")&&l.endsWith("\u672C\u90E8"))h=!0;else{let w=R(d),oe=R(l);w.type==="Other"&&oe.type==="Other"&&(h=!0)}}return h};for(let d of i){let l=I(d,t);if(l.length===0)continue;let s=[];for(let g of l)if(s.length===0)s.push(g);else{let h=s[s.length-1];if(p(h,g))s.push(g);else{y.push([...s]);let T=!1;for(let S=s.length-2;S>=0;S--){let w=s[S];if(p(w,g)){s=[...s.slice(0,S+1),g],T=!0;break}}T||(s=[g])}}s.length>0&&y.push(s)}let D=[...c],x=d=>i.some(l=>l.includes(d)&&l.length>d.length);for(let d of y){let l=!1;for(let s of c){let g=s.findIndex(h=>d.includes(h));if(g!==-1){let h=s[g],T=d.indexOf(h);if(g>0&&T===0){let S=s.slice(0,g);D.push([...S,...d]),l=!0}else if(T>0&&g===0){let S=d.slice(0,T);D.push([...S,...s]),D.push(d),l=!0}else d.length>s.length-g,l=!0}if(!l){let h=s[s.length-1],T=d[0];p(h,T)&&(D.push([...s,...d]),l=!0)}}l||D.push(d)}let k=[],C=[],P=new Set;for(let d of D){let l=d.join("|");P.has(l)||(P.add(l),C.push(d))}for(let d=0;d<C.length;d++){let l=C[d],s=!1;for(let g=0;g<C.length;g++){if(d===g)continue;let h=C[g];if(h.length>l.length&&h.slice(0,l.length).join("|")===l.join("|")){let T=l[l.length-1];if(!x(T)){s=!0;break}}if(h.length>l.length&&v(l,h)){let T=l[l.length-1];if(!x(T)){s=!0;break}}if(l.length===1&&h.length>0){let T=l[0],S=h[h.length-1];if(T!==S&&S.endsWith(T)){s=!0;break}}}s||k.push(l)}return k.length>0?k:null}if(c.length>0){let n=[];for(let f=0;f<c.length;f++){let i=c[f],y=!1;for(let p=0;p<c.length;p++){if(f===p)continue;let D=c[p];if(D.length>i.length&&v(i,D)){y=!0;break}}y||n.push(i)}return n.length>0?n:null}return null}},A={name:"TitleBased",parse:(e,t,r="full")=>{let o=e.title;if(!o)return null;let a=I(o,t);return a.length>0?[a]:null}};var z=e=>{switch(typeof e){case"string":return JSON.stringify(e);case"bigint":return`${e}n`;case"symbol":return e.toString();case"object":return e===null?"null":H(e);case"function":return H(e);case"number":return Object.is(e,-0)?"-0":String(e);default:return String(e)}},H=e=>{try{return Object.prototype.toString.call(e)}catch{return"[object ?]"}};var ge=["uncategorizedCompany","unnamedPerson"],Q=e=>{if(typeof e!="object"||e===null)throw new TypeError(`[contact-map] tree naming must be an object; got ${z(e)}`);for(let t of ge){let r=e[t];if(typeof r!="string")throw new TypeError(`[contact-map] tree naming.${t} must be a string; got ${z(r)}`);if(r.trim()==="")throw new RangeError(`[contact-map] tree naming.${t} must not be empty or blank; got ${z(r)}`)}},ye=[F,A],be=(e,t)=>{let r=E(e.full_name,t),o=E(e.title,"");return o.length>0?`${r} (${o})`:r},K=e=>e.sort((t,r)=>t.label.localeCompare(r.label,"ja")),$=(e,t,r)=>{let o=e.get(t);if(o)return o;let a=r();return e.set(t,a),a},B=e=>encodeURIComponent(e.replace(/\//g,"\uFF0F")),V=e=>e.sort((t,r)=>{let o=!!(t.contact.title&&t.contact.title.trim().length>0),a=!!(r.contact.title&&r.contact.title.trim().length>0);return o&&!a?-1:!o&&a?1:t.label.localeCompare(r.label,"ja")}),q=e=>({name:e.label,type:"file",absolutePath:e.path,relativePath:e.segment,personId:e.contact.person_id,title:e.contact.title||void 0,isPrimary:e.isPrimary}),G=e=>{let t=K(Array.from(e.children.values())).map(G),r=V([...e.persons]).map(q);return{name:e.label,type:"directory",absolutePath:e.path,relativePath:e.segment,children:[...r,...t],memberCount:e.personCount}},N=class{constructor(t){this.companyMap=new Map;this.processedPersonIds=new Set;this.allDepts=new Set;this.cachedResult=null;Q(t),this.naming=t}appendRecords(t){if(!t||t.length===0)return;let r="full",o=!1;for(let a of t)if(!this.processedPersonIds.has(a.person_id)&&a.department){let m=a.department.split(/\u3000/);for(let b of m){let c=b.trim();if(!c||c==="\u517C"||c==="\u4FC2")continue;if(/[^\x20-\x7E]/.test(c)){let f=c.split(" ").filter(i=>i.length>0&&i!=="\u517C"&&i!=="\u4FC2");for(let i of f)this.allDepts.add(i)}else this.allDepts.add(c)}}for(let a of t){let m=a.person_id;if(!Number.isFinite(m)||this.processedPersonIds.has(m))continue;this.processedPersonIds.add(m),o=!0;let b=E(a.company_name,this.naming.uncategorizedCompany),c=be(a,this.naming.unnamedPerson),n=`company:${B(b)}`,f=$(this.companyMap,n,()=>({label:b,segment:n,path:`/${n}`,departments:new Map,persons:[],personCount:0})),i=[],y={allKnownDepartments:this.allDepts};for(let p of ye){let D=p.parse(a,y,r);if(D&&D.length>0){i=D;break}}i.length===0&&i.push([]);for(let p=0;p<i.length;p++){let D=i[p];if(D.length===0){let l=`person:${m}`,s=`${f.path}/${l}`;f.persons.some(h=>h.contact.person_id===m)||f.persons.push({contact:a,label:c,path:s,segment:l,isPrimary:!0});continue}let x=null,k=f.path;if(D.length>0){let l=D[0],s=`department:${B(l)}`;x=$(f.departments,s,()=>({label:l,segment:s,path:`${k}/${s}`,children:new Map,persons:[],personCount:0})),k=x.path,x.personCount+=1;for(let g=1;g<D.length;g++){let h=D[g],T=`department:${B(h)}`;if(!x)throw new Error("[contact-map] unexpected null currentDepartmentNode");x=$(x.children,T,()=>({label:h,segment:T,path:`${k}/${T}`,children:new Map,persons:[],personCount:0})),k=x.path,x.personCount+=1}}else continue;let C=`person:${m}`,P=`${x.path}/${C}`;x.persons.some(l=>l.contact.person_id===m)||x.persons.push({contact:a,label:c,path:P,segment:C,isPrimary:p===0})}f.personCount+=1}o&&(this.cachedResult=null)}getSnapshot(){if(this.cachedResult)return this.cachedResult;let t={},r=K(Array.from(this.companyMap.values())).map(o=>{let a=K(Array.from(o.departments.values())).map(G),m=V([...o.persons]).map(q),b={name:o.label,type:"directory",absolutePath:o.path,relativePath:o.segment,children:[...m,...a],memberCount:o.personCount};return t[o.label]=b,b});return this.cachedResult={tree:r,companyMap:t},this.cachedResult}append(t){this.appendRecords(t)}build(){return this.getSnapshot().tree}reset(){this.companyMap.clear(),this.processedPersonIds.clear(),this.allDepts.clear(),this.cachedResult=null}getUniquePersonCount(){return this.processedPersonIds.size}get size(){return this.processedPersonIds.size}},De=(e,t)=>{let r=new N(t);return r.appendRecords(e),r.getSnapshot()};var O=e=>{if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null},Te=e=>!e||typeof e!="object"?null:"item"in e?e.item??null:"person_id"in e?e:null,J=(e,t)=>{if(!e)return{value:null,fieldKey:null};for(let r of t){let o=O(e[r]);if(o)return{value:o,fieldKey:r}}return{value:null,fieldKey:null}},xe=e=>J(e,["custom_email","email"]),Ce=e=>J(e,["custom_mobile_phone_number","mobile_phone_number","company_phone_number"]),Pe=e=>{let t=O(e);if(!t)return null;let r=t.replace(/[^0-9+#*]/g,"");return r.length===0?null:`tel:${r}`},Se=(e,t)=>{let r=O(e);return r?t?`https://mail.google.com/mail/?view=cm&fs=1&to=${encodeURIComponent(r)}`:`mailto:${encodeURIComponent(r)}`:null},ke=e=>{if(!e)return"-";let t=typeof e=="string"||typeof e=="number"?new Date(e):e;return!(t instanceof Date)||Number.isNaN(t.getTime())?typeof e=="string"?e:"-":t.toISOString().split("T")[0]},X=e=>{if(!e)return"-";let t=typeof e=="string"||typeof e=="number"?new Date(e):e;return!(t instanceof Date)||Number.isNaN(t.getTime())?typeof e=="string"?e:"-":t.toISOString()},Re=e=>e==null?"-":typeof e=="string"?O(e)??"-":typeof e=="number"?Number.isFinite(e)?String(e):"-":e instanceof Date?X(e):String(e);var _e={listPanelMinWidth:320,detailPanelMinWidth:260,handleThickness:10,listPaddingAndBorder:0,detailPaddingAndBorder:0,scrollbarSafetyBuffer:20,hysteresisSafetyMargin:35},Ee={listPanelMinWidth:280,detailPanelMinWidth:260,handleThickness:10,listPaddingAndBorder:0,detailPaddingAndBorder:0,scrollbarSafetyBuffer:20,hysteresisSafetyMargin:35};function Me(e){let t=e.listPanelMinWidth+e.detailPanelMinWidth+e.handleThickness+e.listPaddingAndBorder+e.detailPaddingAndBorder,r=t+e.scrollbarSafetyBuffer,o=r+e.hysteresisSafetyMargin,a=o-r;return{physicalMinWidth:t,collapseThreshold:r,expandThreshold:o,hysteresisWidth:a}}function Oe(e,t,r){return e<=0||!Number.isFinite(e)?!1:t?e>=r.collapseThreshold:e>=r.expandThreshold}var We={info:(e,...t)=>console.info(`[contact-map] ${e}`,...t),warn:(e,...t)=>console.warn(`[contact-map] ${e}`,...t),error:(e,...t)=>console.error(`[contact-map] ${e}`,...t)};var M=require("@aiquants/select-box"),ze=/[​]/g,Ne=/^[\s  ]+|[\s  ]+$/g,we=/\s+/,Le=/^[\p{Script=Latin}\s]+$/u,Ie=/\p{Script=Latin}/u,Z=Object.freeze({convertWidth:!0,convertKana:!0,convertCase:!0,convertRomaji:!1}),Fe=e=>(0,M.normalizeText)(e.replace(ze,"").replace(Ne,""),Z),Ae=e=>{if(!Le.test(e))return null;let t=(0,M.romajiToKatakana)(e);return Ie.test(t)?null:t},Y=e=>e.split(we).filter(Boolean),ee=e=>{let t=Fe(e),r=Ae(t);return r===null?t:r},te=e=>{let t=new Set([...Y(e),...Y(ee(e))]),r=new Set;for(let o of t)for(let a of(0,M.getNormalizedVariants)(o,Z)){let m=a.trim();m&&r.add(m)}return Array.from(r)},$e=/[.*+?^${}()|[\]\\]/g,ne=e=>{let t=te(e);if(t.length===0)return null;let r=t.map(o=>o.replace($e,"\\$&")).sort((o,a)=>a.length-o.length);return new RegExp(r.join("|"),"gi")},Be=(e,t)=>{let r=ne(e);if(r===null)return a=>a;let o=a=>t.some(m=>{let b=a[m];return typeof b=="string"&&b.search(r)!==-1});return a=>{let m=[],b=[];for(let c of a)o(c.item)?m.push(c):b.push(c);return[...m,...b]}};var u=require("zod"),re=u.z.object({person_id:u.z.union([u.z.string(),u.z.number()]).transform(e=>{if(typeof e=="number")return e;let t=e.trim();return parseInt(t,10)}).pipe(u.z.number()),person_id_redirect_to:u.z.union([u.z.string(),u.z.number()]).nullable().optional().transform(e=>{if(e==null)return null;if(typeof e=="number")return e;let t=e.trim();if(t.length===0)return null;let r=parseInt(t,10);return Number.isNaN(r)?null:r}),full_name:u.z.string().nullable().optional(),full_name_reading:u.z.string().nullable().optional(),company_name:u.z.string().nullable().optional(),company_name_reading:u.z.string().nullable().optional(),department:u.z.string().nullable().optional(),title:u.z.string().nullable().optional(),address:u.z.string().nullable().optional(),postal_code:u.z.string().nullable().optional(),email:u.z.string().nullable().optional(),custom_email:u.z.string().nullable().optional(),company_phone_number:u.z.string().nullable().optional(),custom_company_phone_number:u.z.string().nullable().optional(),company_fax_number:u.z.string().nullable().optional(),mobile_phone_number:u.z.string().nullable().optional(),custom_mobile_phone_number:u.z.string().nullable().optional(),url:u.z.string().nullable().optional(),contacted_at:u.z.union([u.z.date(),u.z.string()]).nullable().optional(),contacted_by:u.z.string().nullable().optional(),is_in_eight:u.z.boolean().nullable().optional(),is_contact_synced:u.z.boolean().nullable().optional(),is_active:u.z.boolean(),is_incomplete:u.z.boolean().nullable().optional(),created_at:u.z.union([u.z.date(),u.z.string()]).optional(),created_by:u.z.string().optional(),updated_at:u.z.union([u.z.date(),u.z.string()]).optional(),updated_by:u.z.string().optional()}),Ke=u.z.array(re);0&&(module.exports={DEFAULT_LIST_LAYOUT_SPEC,DEFAULT_TREE_LAYOUT_SPEC,IncrementalTreeBuilder,StandardDepartmentParser,TitleBasedDepartmentParser,assertContactMapTreeNaming,buildDirectoryTree,calculateResponsiveThresholds,createExactMatchRanker,createSearchQueryPattern,defaultLogger,extractContactData,extractDepartmentsFromTitle,formatDate,formatDateTime,getEmailLinkHref,getHysteresisBreakpointState,getPhoneDialHref,getPrimaryEmail,getPrimaryPhone,getSearchQuerySpellings,normalizeLabel,normalizeSearchInput,normalizeString,schemaContactRecord,schemaContactRecords,splitDepartment,toDisplayValue});
1
+ "use strict";var I=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var r in t)I(e,r,{get:t[r],enumerable:!0})},he=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of de(t))!me.call(e,a)&&a!==r&&I(e,a,{get:()=>t[a],enumerable:!(o=ue(t,a))||o.enumerable});return e};var ge=e=>he(I({},"__esModule",{value:!0}),e);var Ve={};fe(Ve,{DEFAULT_LIST_LAYOUT_SPEC:()=>ze,DEFAULT_TREE_LAYOUT_SPEC:()=>Ne,IncrementalTreeBuilder:()=>z,StandardDepartmentParser:()=>A,TitleBasedDepartmentParser:()=>$,assertContactMapTreeNaming:()=>V,buildDirectoryTree:()=>ke,calculateResponsiveThresholds:()=>Le,createExactMatchRanker:()=>Qe,createSearchQueryPattern:()=>le,defaultLogger:()=>Fe,extractContactData:()=>Re,extractDepartmentsFromTitle:()=>F,formatDate:()=>we,formatDateTime:()=>Y,getEmailLinkHref:()=>Oe,getHysteresisBreakpointState:()=>Ie,getPhoneDialHref:()=>Me,getPrimaryEmail:()=>_e,getPrimaryPhone:()=>Ee,getSearchQuerySpellings:()=>ie,normalizeLabel:()=>E,normalizeSearchInput:()=>se,normalizeString:()=>O,schemaContactRecord:()=>pe,schemaContactRecords:()=>He,splitDepartment:()=>Q,toDisplayValue:()=>We});module.exports=ge(Ve);var E=(e,t)=>e&&e.trim()||t;var ye={\u672C\u90E8:{rank:10,type:"Organization"},\u30AB\u30F3\u30D1\u30CB\u30FC:{rank:10,type:"Organization"},\u672C\u793E:{rank:10,type:"Location"},\u30D6\u30ED\u30C3\u30AF:{rank:11,type:"Location"},\u652F\u5E97:{rank:12,type:"Location"},\u7814\u7A76\u6240:{rank:15,type:"Location"},\u5DE5\u5834:{rank:15,type:"Location"},\u4E8B\u696D\u90E8:{rank:18,type:"Organization"},\u90E8\u9580:{rank:18,type:"Organization"},\u7D71\u62EC\u90E8:{rank:19,type:"Organization"},\u90E8:{rank:20,type:"Organization"},\u958B\u767A:{rank:20,type:"Organization"},\u30B0\u30EB\u30FC\u30D7:{rank:22,type:"Organization"},\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8:{rank:25,type:"Organization"},\u63A8\u9032:{rank:20,type:"Organization"},\u4E8B\u696D\u6240:{rank:25,type:"Location"},\u55B6\u696D\u6240:{rank:28,type:"Location"},\u5BA4:{rank:30,type:"Organization"},\u8AB2:{rank:30,type:"Organization"},\u30BB\u30F3\u30BF\u30FC:{rank:30,type:"Location"},\u30D3\u30B8\u30CD\u30B9\u30D7\u30ED\u30C7\u30E5\u30FC\u30B9\u30BB\u30F3\u30BF\u30FC:{rank:30,type:"Location"},\u30C1\u30FC\u30E0:{rank:40,type:"Organization"},\u4FC2:{rank:50,type:"Organization"},Department:{rank:20,type:"Organization"},Dept:{rank:20,type:"Organization"},"Dept.":{rank:20,type:"Organization"},Division:{rank:20,type:"Organization"},Div:{rank:20,type:"Organization"},"Div.":{rank:20,type:"Organization"},Section:{rank:30,type:"Organization"},Sect:{rank:30,type:"Organization"},"Sect.":{rank:30,type:"Organization"},Unit:{rank:30,type:"Organization"},Group:{rank:22,type:"Organization"},Team:{rank:40,type:"Organization"},Branch:{rank:12,type:"Location"},Office:{rank:28,type:"Location"},Center:{rank:30,type:"Location"},Centre:{rank:30,type:"Location"},HQ:{rank:10,type:"Organization"},Headquarters:{rank:10,type:"Organization"}},R=e=>{for(let[t,r]of Object.entries(ye))if(e.endsWith(t))return r;return{rank:99,type:"Other"}},v=e=>R(e).rank,be=["\u30B0\u30EB\u30FC\u30D7","\u30C1\u30FC\u30E0","Group","Team","\u5BA4","\u8AB2","Unit","Area","\u90E8","Department","Dept","Division","Div","\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8","\u63A8\u9032"],_=e=>be.find(t=>e.endsWith(t)),De=new Set(["&","Quality","Innovation","R&D","Solutions","Development","Laboratory","and","Food","Beverage"]),Te=(e,t)=>t>1&&(e.endsWith("\u652F\u5E97")||e.endsWith("\u672C\u90E8")||e.endsWith("\u4E8B\u696D\u6240")||e.endsWith("\u5DE5\u5834")),xe=(e,t)=>{if(!t)return!0;let r=R(e),o=R(t);if(r.rank<o.rank||e.endsWith("\u672C\u90E8")&&t.endsWith("\u672C\u90E8"))return!1;let a=_(e),m=_(t);return!(a&&m&&a!==m)},w=(e,t)=>{if(!e)return[];if(e==="\u517C")return["\u517C"];if(e==="\u517C\u52D9")return["\u517C"];if(e.startsWith("\u517C ")||e.startsWith("\u517C\u3000")){let o=e.slice(1).trim();return["\u517C",...w(o,t)]}if(e.startsWith("\u517C\u52D9 ")||e.startsWith("\u517C\u52D9\u3000")){let o=e.slice(2).trim();return["\u517C",...w(o,t)]}let r="";for(let o=e.length-1;o>0;o--){if(e[o]!==" ")continue;let a=e.slice(0,o);if(!De.has(a)&&t.has(a)){r=a;break}}if(r){let o=r,a=e.slice(r.length),m=/^\s+(and|&)\s+([A-Za-z0-9]+)/i,b=a.match(m);b&&(o=e.slice(0,r.length+b[0].length));let c=e.slice(o.length),n=["Department","Dept","Division","Div","Section","Sect","Unit","Group","Team","Branch","Office","Center","Centre","HQ","Headquarters"];for(let s of n){let y=new RegExp(`^\\s+${s}\\.?(?=$|[\\s,])`,"i"),p=c.match(y);if(p){o=e.slice(0,o.length+p[0].length);break}}let f=e.slice(o.length).trim();return[o,...w(f,t)]}return[e]},Q=(e,t)=>{let o=e.replace(/[\s\u3000]+(?:兼務|兼)[\s\u3000]+/g,"\u3000\u517C\u3000").replace(/^(?:兼務|兼)[\s\u3000]+/,"\u517C\u3000").replace(/[\s\u3000]+(?:兼務|兼)$/,"\u3000\u517C").split(/\u3000/),a=[];for(let m of o){let b=m.trim();b&&a.push(...w(b,t))}return a},F=(e,t)=>{let r=[],o=["\u90E8","\u8AB2","\u5BA4","\u672C\u90E8","\u652F\u5E97","\u55B6\u696D\u6240","\u30B0\u30EB\u30FC\u30D7","\u30C1\u30FC\u30E0","\u30BB\u30F3\u30BF\u30FC","\u30AB\u30F3\u30D1\u30CB\u30FC","\u4E8B\u696D\u6240","\u5DE5\u5834","\u7814\u7A76\u6240","\u4FC2","\u90E8\u9580","\u4E8B\u696D\u90E8","\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8","\u63A8\u9032","\u958B\u767A","Department","Dept","Division","Div","Section","Sect","Unit","Group","Team","Branch","Office","Center","Centre","HQ","Headquarters"],a=e.split(/[\s\u3000,()()[\]]+/).filter(Boolean),m=a.length,b=new Set;for(let c=m;c>=1;c--)for(let n=0;n<=m-c;n++){let f=!1;for(let y=n;y<n+c;y++)if(b.has(y)){f=!0;break}if(f)continue;let s=a.slice(n,n+c).join(" ");if(!(s==="\u517C"||s==="\u517C\u52D9"||s==="\u4FC2"||s==="of"||s==="&"||s==="Quality"||s==="Innovation"||s==="R&D"||s==="Solutions"||s==="Development"||s==="Laboratory"||s==="and"||s==="Food"||s==="Beverage")&&t.allKnownDepartments.has(s)){r.push({name:s,index:n});for(let y=n;y<n+c;y++)b.add(y)}}for(let c=0;c<m;c++){if(b.has(c))continue;let n=a[c];for(n.endsWith("\u9577")&&n.length>1?n=n.slice(0,-1):n.endsWith("\u7D71\u62EC")&&n.length>2&&(n=n.slice(0,-2));;){let p=!1;if(n.startsWith("\u62C5\u5F53")&&n.length>2||n.startsWith("\u5C02\u4EFB")&&n.length>2||n.startsWith("\u517C\u52D9")&&n.length>2?(n=n.slice(2),p=!0):(n.startsWith("\u526F")||n.startsWith("\u517C"))&&n.length>1&&(n=n.slice(1),p=!0),!p)break}if(n.includes("\u30FB")&&!t.allKnownDepartments.has(n)){let p=n.split("\u30FB"),D=p[p.length-1],x=o.find(k=>D.endsWith(k));if(x){for(let k of p){let C=k;o.some(i=>C.endsWith(i))||(C=C+x);let S=n!=="\u517C"&&n!=="\u4FC2"&&n!=="of"&&n!=="&"&&n!=="Quality"&&n!=="Innovation"&&n!=="R&D"&&n!=="Solutions"&&n!=="Development"&&n!=="Laboratory"&&n!=="and"&&n!=="Food"&&n!=="Beverage"&&t.allKnownDepartments.has(C),d=o.some(i=>C.endsWith(i)),l=o.includes(C);(S||d&&!l)&&r.push({name:C,index:c})}continue}}let f=n!=="\u517C"&&n!=="\u4FC2"&&n!=="of"&&n!=="&"&&n!=="Quality"&&n!=="Innovation"&&n!=="R&D"&&n!=="Solutions"&&n!=="Development"&&n!=="Laboratory"&&n!=="and"&&n!=="Food"&&n!=="Beverage"&&t.allKnownDepartments.has(n),s=o.some(p=>n.endsWith(p)),y=o.includes(n);(f||s&&!y)&&r.push({name:n,index:c})}return r.sort((c,n)=>c.index-n.index),r.map(c=>c.name)},U=(e,t)=>{let r=0;for(let o of t)r<e.length&&o===e[r]&&r++;return r===e.length},A={name:"Standard",parse:(e,t,r="full")=>{let o=E(e.department,"");if(!o)return null;let a=Q(o,t.allKnownDepartments),m=new Map;for(let n of a)m.set(n,(m.get(n)||0)+1);let b=n=>{let f=[],s=[];for(let y=0;y<n.length;y++){let p=n[y];if(p==="\u517C"){s.length>0&&(f.push(s),s=[]);continue}let D=R(p),x=D.rank,k=m.get(p)||0,C=Te(p,k);if(s.length===0)s.push(p);else{let S=s[s.length-1],d=R(S),l=d.rank;if(s.includes(p))f.push(s),s=[p];else{let i=!1;if(C)i=!0;else if(d.type===D.type){let g=_(S),h=_(p);g&&h&&g!==h||S.endsWith("\u672C\u90E8")&&p.endsWith("\u672C\u90E8")||S.endsWith("\u90E8\u9580")&&p.endsWith("\u4E8B\u696D\u90E8")||S.endsWith("\u4E8B\u696D\u90E8")&&p.endsWith("\u90E8\u9580")||S.endsWith("\u90E8\u9580")&&p.endsWith("\u672C\u90E8")||d.type==="Other"&&D.type==="Other"?i=!0:i=l<x}else i=x>=10,i&&d.type==="Location"&&D.type==="Organization"&&l>=x&&n.slice(y+1).includes(S)&&(i=!1);i?s.push(p):(f.push(s),s=[p])}}if(C){let S=y+1<n.length?n[y+1]:void 0;xe(p,S)&&s.length>0&&(f.push(s),s=[])}}return s.length>0&&f.push(s),f},c=[];if(r==="full"&&c.push(...b(a)),r==="pure_org"){let n=a.filter(f=>R(f).type!=="Location");n.length>0&&c.push(...b(n))}if(e.title){let f=/[^\x20-\x7E]/.test(e.title)?/[\s\u3000]*(?:兼務|兼)[\s\u3000]*/:/[,;]|(?:兼務|兼)/,s=e.title.split(f).filter(Boolean),y=[],p=(d,l)=>{let i=v(d),g=v(l),h=i<g;if(!h){let T=_(d),P=_(l);if(T&&P&&T!==P)h=!0;else if(d.endsWith("\u672C\u90E8")&&l.endsWith("\u672C\u90E8"))h=!0;else if(d.endsWith("\u90E8\u9580")&&l.endsWith("\u4E8B\u696D\u90E8")||d.endsWith("\u4E8B\u696D\u90E8")&&l.endsWith("\u90E8\u9580"))h=!0;else if(d.endsWith("\u90E8\u9580")&&l.endsWith("\u672C\u90E8"))h=!0;else{let L=R(d),ce=R(l);L.type==="Other"&&ce.type==="Other"&&(h=!0)}}return h};for(let d of s){let l=F(d,t);if(l.length===0)continue;let i=[];for(let g of l)if(i.length===0)i.push(g);else{let h=i[i.length-1];if(p(h,g))i.push(g);else{y.push([...i]);let T=!1;for(let P=i.length-2;P>=0;P--){let L=i[P];if(p(L,g)){i=[...i.slice(0,P+1),g],T=!0;break}}T||(i=[g])}}i.length>0&&y.push(i)}let D=[...c],x=d=>s.some(l=>l.includes(d)&&l.length>d.length);for(let d of y){let l=!1;for(let i of c){let g=i.findIndex(h=>d.includes(h));if(g!==-1){let h=i[g],T=d.indexOf(h);if(g>0&&T===0){let P=i.slice(0,g);D.push([...P,...d]),l=!0}else if(T>0&&g===0){let P=d.slice(0,T);D.push([...P,...i]),D.push(d),l=!0}else d.length>i.length-g,l=!0}if(!l){let h=i[i.length-1],T=d[0];p(h,T)&&(D.push([...i,...d]),l=!0)}}l||D.push(d)}let k=[],C=[],S=new Set;for(let d of D){let l=d.join("|");S.has(l)||(S.add(l),C.push(d))}for(let d=0;d<C.length;d++){let l=C[d],i=!1;for(let g=0;g<C.length;g++){if(d===g)continue;let h=C[g];if(h.length>l.length&&h.slice(0,l.length).join("|")===l.join("|")){let T=l[l.length-1];if(!x(T)){i=!0;break}}if(h.length>l.length&&U(l,h)){let T=l[l.length-1];if(!x(T)){i=!0;break}}if(l.length===1&&h.length>0){let T=l[0],P=h[h.length-1];if(T!==P&&P.endsWith(T)){i=!0;break}}}i||k.push(l)}return k.length>0?k:null}if(c.length>0){let n=[];for(let f=0;f<c.length;f++){let s=c[f],y=!1;for(let p=0;p<c.length;p++){if(f===p)continue;let D=c[p];if(D.length>s.length&&U(s,D)){y=!0;break}}y||n.push(s)}return n.length>0?n:null}return null}},$={name:"TitleBased",parse:(e,t,r="full")=>{let o=e.title;if(!o)return null;let a=F(o,t);return a.length>0?[a]:null}};var W=e=>{switch(typeof e){case"string":return JSON.stringify(e);case"bigint":return`${e}n`;case"symbol":return e.toString();case"object":return e===null?"null":H(e);case"function":return H(e);case"number":return Object.is(e,-0)?"-0":String(e);default:return String(e)}},H=e=>{try{return Object.prototype.toString.call(e)}catch{return"[object ?]"}};var Ce=["uncategorizedCompany","unnamedPerson"],V=e=>{if(typeof e!="object"||e===null)throw new TypeError(`[contact-map] tree naming must be an object; got ${W(e)}`);for(let t of Ce){let r=e[t];if(typeof r!="string")throw new TypeError(`[contact-map] tree naming.${t} must be a string; got ${W(r)}`);if(r.trim()==="")throw new RangeError(`[contact-map] tree naming.${t} must not be empty or blank; got ${W(r)}`)}},Se=[A,$],Pe=(e,t)=>{let r=E(e.full_name,t),o=E(e.title,"");return o.length>0?`${r} (${o})`:r},j=e=>e.sort((t,r)=>t.label.localeCompare(r.label,"ja")),B=(e,t,r)=>{let o=e.get(t);if(o)return o;let a=r();return e.set(t,a),a},K=e=>encodeURIComponent(e.replace(/\//g,"\uFF0F")),q=e=>e.sort((t,r)=>{let o=!!(t.contact.title&&t.contact.title.trim().length>0),a=!!(r.contact.title&&r.contact.title.trim().length>0);return o&&!a?-1:!o&&a?1:t.label.localeCompare(r.label,"ja")}),G=e=>({name:e.label,type:"file",absolutePath:e.path,relativePath:e.segment,personId:e.contact.person_id,title:e.contact.title||void 0,isPrimary:e.isPrimary}),J=e=>{let t=j(Array.from(e.children.values())).map(J),r=q([...e.persons]).map(G);return{name:e.label,type:"directory",absolutePath:e.path,relativePath:e.segment,children:[...r,...t],memberCount:e.personCount}},z=class{constructor(t){this.companyMap=new Map;this.processedPersonIds=new Set;this.allDepts=new Set;this.cachedResult=null;V(t),this.naming=t}appendRecords(t){if(!t||t.length===0)return;let r="full",o=!1;for(let a of t)if(!this.processedPersonIds.has(a.person_id)&&a.department){let m=a.department.split(/\u3000/);for(let b of m){let c=b.trim();if(!c||c==="\u517C"||c==="\u4FC2")continue;if(/[^\x20-\x7E]/.test(c)){let f=c.split(" ").filter(s=>s.length>0&&s!=="\u517C"&&s!=="\u4FC2");for(let s of f)this.allDepts.add(s)}else this.allDepts.add(c)}}for(let a of t){let m=a.person_id;if(!Number.isFinite(m)||this.processedPersonIds.has(m))continue;this.processedPersonIds.add(m),o=!0;let b=E(a.company_name,this.naming.uncategorizedCompany),c=Pe(a,this.naming.unnamedPerson),n=`company:${K(b)}`,f=B(this.companyMap,n,()=>({label:b,segment:n,path:`/${n}`,departments:new Map,persons:[],personCount:0})),s=[],y={allKnownDepartments:this.allDepts};for(let p of Se){let D=p.parse(a,y,r);if(D&&D.length>0){s=D;break}}s.length===0&&s.push([]);for(let p=0;p<s.length;p++){let D=s[p];if(D.length===0){let l=`person:${m}`,i=`${f.path}/${l}`;f.persons.some(h=>h.contact.person_id===m)||f.persons.push({contact:a,label:c,path:i,segment:l,isPrimary:!0});continue}let x=null,k=f.path;if(D.length>0){let l=D[0],i=`department:${K(l)}`;x=B(f.departments,i,()=>({label:l,segment:i,path:`${k}/${i}`,children:new Map,persons:[],personCount:0})),k=x.path,x.personCount+=1;for(let g=1;g<D.length;g++){let h=D[g],T=`department:${K(h)}`;if(!x)throw new Error("[contact-map] unexpected null currentDepartmentNode");x=B(x.children,T,()=>({label:h,segment:T,path:`${k}/${T}`,children:new Map,persons:[],personCount:0})),k=x.path,x.personCount+=1}}else continue;let C=`person:${m}`,S=`${x.path}/${C}`;x.persons.some(l=>l.contact.person_id===m)||x.persons.push({contact:a,label:c,path:S,segment:C,isPrimary:p===0})}f.personCount+=1}o&&(this.cachedResult=null)}getSnapshot(){if(this.cachedResult)return this.cachedResult;let t={},r=j(Array.from(this.companyMap.values())).map(o=>{let a=j(Array.from(o.departments.values())).map(J),m=q([...o.persons]).map(G),b={name:o.label,type:"directory",absolutePath:o.path,relativePath:o.segment,children:[...m,...a],memberCount:o.personCount};return t[o.label]=b,b});return this.cachedResult={tree:r,companyMap:t},this.cachedResult}append(t){this.appendRecords(t)}build(){return this.getSnapshot().tree}reset(){this.companyMap.clear(),this.processedPersonIds.clear(),this.allDepts.clear(),this.cachedResult=null}getUniquePersonCount(){return this.processedPersonIds.size}get size(){return this.processedPersonIds.size}},ke=(e,t)=>{let r=new z(t);return r.appendRecords(e),r.getSnapshot()};var O=e=>{if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null},Re=e=>!e||typeof e!="object"?null:"item"in e?e.item??null:"person_id"in e?e:null,X=(e,t)=>{if(!e)return{value:null,fieldKey:null};for(let r of t){let o=O(e[r]);if(o)return{value:o,fieldKey:r}}return{value:null,fieldKey:null}},_e=e=>X(e,["custom_email","email"]),Ee=e=>X(e,["custom_mobile_phone_number","mobile_phone_number","company_phone_number"]),Me=e=>{let t=O(e);if(!t)return null;let r=t.replace(/[^0-9+#*]/g,"");return r.length===0?null:`tel:${r}`},Oe=(e,t)=>{let r=O(e);return r?t?`https://mail.google.com/mail/?view=cm&fs=1&to=${encodeURIComponent(r)}`:`mailto:${encodeURIComponent(r)}`:null},we=e=>{if(!e)return"-";let t=typeof e=="string"||typeof e=="number"?new Date(e):e;return!(t instanceof Date)||Number.isNaN(t.getTime())?typeof e=="string"?e:"-":t.toISOString().split("T")[0]},Y=e=>{if(!e)return"-";let t=typeof e=="string"||typeof e=="number"?new Date(e):e;return!(t instanceof Date)||Number.isNaN(t.getTime())?typeof e=="string"?e:"-":t.toISOString()},We=e=>e==null?"-":typeof e=="string"?O(e)??"-":typeof e=="number"?Number.isFinite(e)?String(e):"-":e instanceof Date?Y(e):String(e);var ze={listPanelMinWidth:320,detailPanelMinWidth:260,handleThickness:10,listPaddingAndBorder:0,detailPaddingAndBorder:0,scrollbarSafetyBuffer:20,hysteresisSafetyMargin:35},Ne={listPanelMinWidth:280,detailPanelMinWidth:260,handleThickness:10,listPaddingAndBorder:0,detailPaddingAndBorder:0,scrollbarSafetyBuffer:20,hysteresisSafetyMargin:35};function Le(e){let t=e.listPanelMinWidth+e.detailPanelMinWidth+e.handleThickness+e.listPaddingAndBorder+e.detailPaddingAndBorder,r=t+e.scrollbarSafetyBuffer,o=r+e.hysteresisSafetyMargin,a=o-r;return{physicalMinWidth:t,collapseThreshold:r,expandThreshold:o,hysteresisWidth:a}}function Ie(e,t,r){return e<=0||!Number.isFinite(e)?!1:t?e>=r.collapseThreshold:e>=r.expandThreshold}var Fe={info:(e,...t)=>console.info(`[contact-map] ${e}`,...t),warn:(e,...t)=>console.warn(`[contact-map] ${e}`,...t),error:(e,...t)=>console.error(`[contact-map] ${e}`,...t)};var N=require("@aiquants/fuzzy-search"),M=require("@aiquants/select-box"),te=/[​]/g,Ae=/^[\s  ]+|[\s  ]+$/g,$e=/\s+/,Be=/^[\p{Script=Latin}\s]+$/u,Ke=/\p{Script=Latin}/u,ne=Object.freeze({convertWidth:!0,convertKana:!0,convertCase:!0,convertRomaji:!1}),re="union",je=e=>(0,M.normalizeText)(e.replace(te,"").replace(Ae,""),ne),ve=e=>{if(!Be.test(e))return null;let t=(0,M.romajiToKatakana)(e);return Ke.test(t)?null:t},oe=e=>e.split($e).filter(Boolean),ae=e=>(0,N.parseQuerySets)(e,re).sets.map(({query:t})=>t),Z=e=>ae(e).flatMap(t=>oe(t)),ee=e=>(0,N.formatQuerySets)({combine:re,sets:Array.from(new Set(e),t=>({query:t}))}),se=e=>{let t=ae(e.replace(te,"")).map(o=>oe(je(o)).join(" ")).filter(o=>o!==""),r=[];for(let o of t){let a=ve(o);if(a===null)return ee(t);r.push(a)}return ee(r)},ie=e=>{let t=new Set([...Z(e),...Z(se(e))]),r=new Set;for(let o of t)for(let a of(0,M.getNormalizedVariants)(o,ne)){let m=a.trim();m&&r.add(m)}return Array.from(r)},Ue=/[.*+?^${}()|[\]\\]/g,le=e=>{let t=ie(e);if(t.length===0)return null;let r=t.map(o=>o.replace(Ue,"\\$&")).sort((o,a)=>a.length-o.length);return new RegExp(r.join("|"),"gi")},Qe=(e,t)=>{let r=le(e);if(r===null)return a=>a;let o=a=>t.some(m=>{let b=a[m];return typeof b=="string"&&b.search(r)!==-1});return a=>{let m=[],b=[];for(let c of a)o(c.item)?m.push(c):b.push(c);return[...m,...b]}};var u=require("zod"),pe=u.z.object({person_id:u.z.union([u.z.string(),u.z.number()]).transform(e=>{if(typeof e=="number")return e;let t=e.trim();return parseInt(t,10)}).pipe(u.z.number()),person_id_redirect_to:u.z.union([u.z.string(),u.z.number()]).nullable().optional().transform(e=>{if(e==null)return null;if(typeof e=="number")return e;let t=e.trim();if(t.length===0)return null;let r=parseInt(t,10);return Number.isNaN(r)?null:r}),full_name:u.z.string().nullable().optional(),full_name_reading:u.z.string().nullable().optional(),company_name:u.z.string().nullable().optional(),company_name_reading:u.z.string().nullable().optional(),department:u.z.string().nullable().optional(),title:u.z.string().nullable().optional(),address:u.z.string().nullable().optional(),postal_code:u.z.string().nullable().optional(),email:u.z.string().nullable().optional(),custom_email:u.z.string().nullable().optional(),company_phone_number:u.z.string().nullable().optional(),custom_company_phone_number:u.z.string().nullable().optional(),company_fax_number:u.z.string().nullable().optional(),mobile_phone_number:u.z.string().nullable().optional(),custom_mobile_phone_number:u.z.string().nullable().optional(),url:u.z.string().nullable().optional(),contacted_at:u.z.union([u.z.date(),u.z.string()]).nullable().optional(),contacted_by:u.z.string().nullable().optional(),is_in_eight:u.z.boolean().nullable().optional(),is_contact_synced:u.z.boolean().nullable().optional(),is_active:u.z.boolean(),is_incomplete:u.z.boolean().nullable().optional(),created_at:u.z.union([u.z.date(),u.z.string()]).optional(),created_by:u.z.string().optional(),updated_at:u.z.union([u.z.date(),u.z.string()]).optional(),updated_by:u.z.string().optional()}),He=u.z.array(pe);0&&(module.exports={DEFAULT_LIST_LAYOUT_SPEC,DEFAULT_TREE_LAYOUT_SPEC,IncrementalTreeBuilder,StandardDepartmentParser,TitleBasedDepartmentParser,assertContactMapTreeNaming,buildDirectoryTree,calculateResponsiveThresholds,createExactMatchRanker,createSearchQueryPattern,defaultLogger,extractContactData,extractDepartmentsFromTitle,formatDate,formatDateTime,getEmailLinkHref,getHysteresisBreakpointState,getPhoneDialHref,getPrimaryEmail,getPrimaryPhone,getSearchQuerySpellings,normalizeLabel,normalizeSearchInput,normalizeString,schemaContactRecord,schemaContactRecords,splitDepartment,toDisplayValue});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var E=(e,t)=>e&&e.trim()||t;var J={\u672C\u90E8:{rank:10,type:"Organization"},\u30AB\u30F3\u30D1\u30CB\u30FC:{rank:10,type:"Organization"},\u672C\u793E:{rank:10,type:"Location"},\u30D6\u30ED\u30C3\u30AF:{rank:11,type:"Location"},\u652F\u5E97:{rank:12,type:"Location"},\u7814\u7A76\u6240:{rank:15,type:"Location"},\u5DE5\u5834:{rank:15,type:"Location"},\u4E8B\u696D\u90E8:{rank:18,type:"Organization"},\u90E8\u9580:{rank:18,type:"Organization"},\u7D71\u62EC\u90E8:{rank:19,type:"Organization"},\u90E8:{rank:20,type:"Organization"},\u958B\u767A:{rank:20,type:"Organization"},\u30B0\u30EB\u30FC\u30D7:{rank:22,type:"Organization"},\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8:{rank:25,type:"Organization"},\u63A8\u9032:{rank:20,type:"Organization"},\u4E8B\u696D\u6240:{rank:25,type:"Location"},\u55B6\u696D\u6240:{rank:28,type:"Location"},\u5BA4:{rank:30,type:"Organization"},\u8AB2:{rank:30,type:"Organization"},\u30BB\u30F3\u30BF\u30FC:{rank:30,type:"Location"},\u30D3\u30B8\u30CD\u30B9\u30D7\u30ED\u30C7\u30E5\u30FC\u30B9\u30BB\u30F3\u30BF\u30FC:{rank:30,type:"Location"},\u30C1\u30FC\u30E0:{rank:40,type:"Organization"},\u4FC2:{rank:50,type:"Organization"},Department:{rank:20,type:"Organization"},Dept:{rank:20,type:"Organization"},"Dept.":{rank:20,type:"Organization"},Division:{rank:20,type:"Organization"},Div:{rank:20,type:"Organization"},"Div.":{rank:20,type:"Organization"},Section:{rank:30,type:"Organization"},Sect:{rank:30,type:"Organization"},"Sect.":{rank:30,type:"Organization"},Unit:{rank:30,type:"Organization"},Group:{rank:22,type:"Organization"},Team:{rank:40,type:"Organization"},Branch:{rank:12,type:"Location"},Office:{rank:28,type:"Location"},Center:{rank:30,type:"Location"},Centre:{rank:30,type:"Location"},HQ:{rank:10,type:"Organization"},Headquarters:{rank:10,type:"Organization"}},R=e=>{for(let[t,r]of Object.entries(J))if(e.endsWith(t))return r;return{rank:99,type:"Other"}},F=e=>R(e).rank,X=["\u30B0\u30EB\u30FC\u30D7","\u30C1\u30FC\u30E0","Group","Team","\u5BA4","\u8AB2","Unit","Area","\u90E8","Department","Dept","Division","Div","\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8","\u63A8\u9032"],_=e=>X.find(t=>e.endsWith(t)),Y=new Set(["&","Quality","Innovation","R&D","Solutions","Development","Laboratory","and","Food","Beverage"]),Z=(e,t)=>t>1&&(e.endsWith("\u652F\u5E97")||e.endsWith("\u672C\u90E8")||e.endsWith("\u4E8B\u696D\u6240")||e.endsWith("\u5DE5\u5834")),ee=(e,t)=>{if(!t)return!0;let r=R(e),o=R(t);if(r.rank<o.rank||e.endsWith("\u672C\u90E8")&&t.endsWith("\u672C\u90E8"))return!1;let i=_(e),m=_(t);return!(i&&m&&i!==m)},M=(e,t)=>{if(!e)return[];if(e==="\u517C")return["\u517C"];if(e==="\u517C\u52D9")return["\u517C"];if(e.startsWith("\u517C ")||e.startsWith("\u517C\u3000")){let o=e.slice(1).trim();return["\u517C",...M(o,t)]}if(e.startsWith("\u517C\u52D9 ")||e.startsWith("\u517C\u52D9\u3000")){let o=e.slice(2).trim();return["\u517C",...M(o,t)]}let r="";for(let o=e.length-1;o>0;o--){if(e[o]!==" ")continue;let i=e.slice(0,o);if(!Y.has(i)&&t.has(i)){r=i;break}}if(r){let o=r,i=e.slice(r.length),m=/^\s+(and|&)\s+([A-Za-z0-9]+)/i,b=i.match(m);b&&(o=e.slice(0,r.length+b[0].length));let c=e.slice(o.length),n=["Department","Dept","Division","Div","Section","Sect","Unit","Group","Team","Branch","Office","Center","Centre","HQ","Headquarters"];for(let a of n){let y=new RegExp(`^\\s+${a}\\.?(?=$|[\\s,])`,"i"),p=c.match(y);if(p){o=e.slice(0,o.length+p[0].length);break}}let f=e.slice(o.length).trim();return[o,...M(f,t)]}return[e]},te=(e,t)=>{let o=e.replace(/[\s\u3000]+(?:兼務|兼)[\s\u3000]+/g,"\u3000\u517C\u3000").replace(/^(?:兼務|兼)[\s\u3000]+/,"\u517C\u3000").replace(/[\s\u3000]+(?:兼務|兼)$/,"\u3000\u517C").split(/\u3000/),i=[];for(let m of o){let b=m.trim();b&&i.push(...M(b,t))}return i},$=(e,t)=>{let r=[],o=["\u90E8","\u8AB2","\u5BA4","\u672C\u90E8","\u652F\u5E97","\u55B6\u696D\u6240","\u30B0\u30EB\u30FC\u30D7","\u30C1\u30FC\u30E0","\u30BB\u30F3\u30BF\u30FC","\u30AB\u30F3\u30D1\u30CB\u30FC","\u4E8B\u696D\u6240","\u5DE5\u5834","\u7814\u7A76\u6240","\u4FC2","\u90E8\u9580","\u4E8B\u696D\u90E8","\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8","\u63A8\u9032","\u958B\u767A","Department","Dept","Division","Div","Section","Sect","Unit","Group","Team","Branch","Office","Center","Centre","HQ","Headquarters"],i=e.split(/[\s\u3000,()()[\]]+/).filter(Boolean),m=i.length,b=new Set;for(let c=m;c>=1;c--)for(let n=0;n<=m-c;n++){let f=!1;for(let y=n;y<n+c;y++)if(b.has(y)){f=!0;break}if(f)continue;let a=i.slice(n,n+c).join(" ");if(!(a==="\u517C"||a==="\u517C\u52D9"||a==="\u4FC2"||a==="of"||a==="&"||a==="Quality"||a==="Innovation"||a==="R&D"||a==="Solutions"||a==="Development"||a==="Laboratory"||a==="and"||a==="Food"||a==="Beverage")&&t.allKnownDepartments.has(a)){r.push({name:a,index:n});for(let y=n;y<n+c;y++)b.add(y)}}for(let c=0;c<m;c++){if(b.has(c))continue;let n=i[c];for(n.endsWith("\u9577")&&n.length>1?n=n.slice(0,-1):n.endsWith("\u7D71\u62EC")&&n.length>2&&(n=n.slice(0,-2));;){let p=!1;if(n.startsWith("\u62C5\u5F53")&&n.length>2||n.startsWith("\u5C02\u4EFB")&&n.length>2||n.startsWith("\u517C\u52D9")&&n.length>2?(n=n.slice(2),p=!0):(n.startsWith("\u526F")||n.startsWith("\u517C"))&&n.length>1&&(n=n.slice(1),p=!0),!p)break}if(n.includes("\u30FB")&&!t.allKnownDepartments.has(n)){let p=n.split("\u30FB"),D=p[p.length-1],x=o.find(k=>D.endsWith(k));if(x){for(let k of p){let C=k;o.some(s=>C.endsWith(s))||(C=C+x);let P=n!=="\u517C"&&n!=="\u4FC2"&&n!=="of"&&n!=="&"&&n!=="Quality"&&n!=="Innovation"&&n!=="R&D"&&n!=="Solutions"&&n!=="Development"&&n!=="Laboratory"&&n!=="and"&&n!=="Food"&&n!=="Beverage"&&t.allKnownDepartments.has(C),d=o.some(s=>C.endsWith(s)),l=o.includes(C);(P||d&&!l)&&r.push({name:C,index:c})}continue}}let f=n!=="\u517C"&&n!=="\u4FC2"&&n!=="of"&&n!=="&"&&n!=="Quality"&&n!=="Innovation"&&n!=="R&D"&&n!=="Solutions"&&n!=="Development"&&n!=="Laboratory"&&n!=="and"&&n!=="Food"&&n!=="Beverage"&&t.allKnownDepartments.has(n),a=o.some(p=>n.endsWith(p)),y=o.includes(n);(f||a&&!y)&&r.push({name:n,index:c})}return r.sort((c,n)=>c.index-n.index),r.map(c=>c.name)},A=(e,t)=>{let r=0;for(let o of t)r<e.length&&o===e[r]&&r++;return r===e.length},B={name:"Standard",parse:(e,t,r="full")=>{let o=E(e.department,"");if(!o)return null;let i=te(o,t.allKnownDepartments),m=new Map;for(let n of i)m.set(n,(m.get(n)||0)+1);let b=n=>{let f=[],a=[];for(let y=0;y<n.length;y++){let p=n[y];if(p==="\u517C"){a.length>0&&(f.push(a),a=[]);continue}let D=R(p),x=D.rank,k=m.get(p)||0,C=Z(p,k);if(a.length===0)a.push(p);else{let P=a[a.length-1],d=R(P),l=d.rank;if(a.includes(p))f.push(a),a=[p];else{let s=!1;if(C)s=!0;else if(d.type===D.type){let g=_(P),h=_(p);g&&h&&g!==h||P.endsWith("\u672C\u90E8")&&p.endsWith("\u672C\u90E8")||P.endsWith("\u90E8\u9580")&&p.endsWith("\u4E8B\u696D\u90E8")||P.endsWith("\u4E8B\u696D\u90E8")&&p.endsWith("\u90E8\u9580")||P.endsWith("\u90E8\u9580")&&p.endsWith("\u672C\u90E8")||d.type==="Other"&&D.type==="Other"?s=!0:s=l<x}else s=x>=10,s&&d.type==="Location"&&D.type==="Organization"&&l>=x&&n.slice(y+1).includes(P)&&(s=!1);s?a.push(p):(f.push(a),a=[p])}}if(C){let P=y+1<n.length?n[y+1]:void 0;ee(p,P)&&a.length>0&&(f.push(a),a=[])}}return a.length>0&&f.push(a),f},c=[];if(r==="full"&&c.push(...b(i)),r==="pure_org"){let n=i.filter(f=>R(f).type!=="Location");n.length>0&&c.push(...b(n))}if(e.title){let f=/[^\x20-\x7E]/.test(e.title)?/[\s\u3000]*(?:兼務|兼)[\s\u3000]*/:/[,;]|(?:兼務|兼)/,a=e.title.split(f).filter(Boolean),y=[],p=(d,l)=>{let s=F(d),g=F(l),h=s<g;if(!h){let T=_(d),S=_(l);if(T&&S&&T!==S)h=!0;else if(d.endsWith("\u672C\u90E8")&&l.endsWith("\u672C\u90E8"))h=!0;else if(d.endsWith("\u90E8\u9580")&&l.endsWith("\u4E8B\u696D\u90E8")||d.endsWith("\u4E8B\u696D\u90E8")&&l.endsWith("\u90E8\u9580"))h=!0;else if(d.endsWith("\u90E8\u9580")&&l.endsWith("\u672C\u90E8"))h=!0;else{let z=R(d),G=R(l);z.type==="Other"&&G.type==="Other"&&(h=!0)}}return h};for(let d of a){let l=$(d,t);if(l.length===0)continue;let s=[];for(let g of l)if(s.length===0)s.push(g);else{let h=s[s.length-1];if(p(h,g))s.push(g);else{y.push([...s]);let T=!1;for(let S=s.length-2;S>=0;S--){let z=s[S];if(p(z,g)){s=[...s.slice(0,S+1),g],T=!0;break}}T||(s=[g])}}s.length>0&&y.push(s)}let D=[...c],x=d=>a.some(l=>l.includes(d)&&l.length>d.length);for(let d of y){let l=!1;for(let s of c){let g=s.findIndex(h=>d.includes(h));if(g!==-1){let h=s[g],T=d.indexOf(h);if(g>0&&T===0){let S=s.slice(0,g);D.push([...S,...d]),l=!0}else if(T>0&&g===0){let S=d.slice(0,T);D.push([...S,...s]),D.push(d),l=!0}else d.length>s.length-g,l=!0}if(!l){let h=s[s.length-1],T=d[0];p(h,T)&&(D.push([...s,...d]),l=!0)}}l||D.push(d)}let k=[],C=[],P=new Set;for(let d of D){let l=d.join("|");P.has(l)||(P.add(l),C.push(d))}for(let d=0;d<C.length;d++){let l=C[d],s=!1;for(let g=0;g<C.length;g++){if(d===g)continue;let h=C[g];if(h.length>l.length&&h.slice(0,l.length).join("|")===l.join("|")){let T=l[l.length-1];if(!x(T)){s=!0;break}}if(h.length>l.length&&A(l,h)){let T=l[l.length-1];if(!x(T)){s=!0;break}}if(l.length===1&&h.length>0){let T=l[0],S=h[h.length-1];if(T!==S&&S.endsWith(T)){s=!0;break}}}s||k.push(l)}return k.length>0?k:null}if(c.length>0){let n=[];for(let f=0;f<c.length;f++){let a=c[f],y=!1;for(let p=0;p<c.length;p++){if(f===p)continue;let D=c[p];if(D.length>a.length&&A(a,D)){y=!0;break}}y||n.push(a)}return n.length>0?n:null}return null}},K={name:"TitleBased",parse:(e,t,r="full")=>{let o=e.title;if(!o)return null;let i=$(o,t);return i.length>0?[i]:null}};var O=e=>{switch(typeof e){case"string":return JSON.stringify(e);case"bigint":return`${e}n`;case"symbol":return e.toString();case"object":return e===null?"null":j(e);case"function":return j(e);case"number":return Object.is(e,-0)?"-0":String(e);default:return String(e)}},j=e=>{try{return Object.prototype.toString.call(e)}catch{return"[object ?]"}};var ne=["uncategorizedCompany","unnamedPerson"],re=e=>{if(typeof e!="object"||e===null)throw new TypeError(`[contact-map] tree naming must be an object; got ${O(e)}`);for(let t of ne){let r=e[t];if(typeof r!="string")throw new TypeError(`[contact-map] tree naming.${t} must be a string; got ${O(r)}`);if(r.trim()==="")throw new RangeError(`[contact-map] tree naming.${t} must not be empty or blank; got ${O(r)}`)}},oe=[B,K],ae=(e,t)=>{let r=E(e.full_name,t),o=E(e.title,"");return o.length>0?`${r} (${o})`:r},L=e=>e.sort((t,r)=>t.label.localeCompare(r.label,"ja")),N=(e,t,r)=>{let o=e.get(t);if(o)return o;let i=r();return e.set(t,i),i},w=e=>encodeURIComponent(e.replace(/\//g,"\uFF0F")),v=e=>e.sort((t,r)=>{let o=!!(t.contact.title&&t.contact.title.trim().length>0),i=!!(r.contact.title&&r.contact.title.trim().length>0);return o&&!i?-1:!o&&i?1:t.label.localeCompare(r.label,"ja")}),U=e=>({name:e.label,type:"file",absolutePath:e.path,relativePath:e.segment,personId:e.contact.person_id,title:e.contact.title||void 0,isPrimary:e.isPrimary}),H=e=>{let t=L(Array.from(e.children.values())).map(H),r=v([...e.persons]).map(U);return{name:e.label,type:"directory",absolutePath:e.path,relativePath:e.segment,children:[...r,...t],memberCount:e.personCount}},I=class{constructor(t){this.companyMap=new Map;this.processedPersonIds=new Set;this.allDepts=new Set;this.cachedResult=null;re(t),this.naming=t}appendRecords(t){if(!t||t.length===0)return;let r="full",o=!1;for(let i of t)if(!this.processedPersonIds.has(i.person_id)&&i.department){let m=i.department.split(/\u3000/);for(let b of m){let c=b.trim();if(!c||c==="\u517C"||c==="\u4FC2")continue;if(/[^\x20-\x7E]/.test(c)){let f=c.split(" ").filter(a=>a.length>0&&a!=="\u517C"&&a!=="\u4FC2");for(let a of f)this.allDepts.add(a)}else this.allDepts.add(c)}}for(let i of t){let m=i.person_id;if(!Number.isFinite(m)||this.processedPersonIds.has(m))continue;this.processedPersonIds.add(m),o=!0;let b=E(i.company_name,this.naming.uncategorizedCompany),c=ae(i,this.naming.unnamedPerson),n=`company:${w(b)}`,f=N(this.companyMap,n,()=>({label:b,segment:n,path:`/${n}`,departments:new Map,persons:[],personCount:0})),a=[],y={allKnownDepartments:this.allDepts};for(let p of oe){let D=p.parse(i,y,r);if(D&&D.length>0){a=D;break}}a.length===0&&a.push([]);for(let p=0;p<a.length;p++){let D=a[p];if(D.length===0){let l=`person:${m}`,s=`${f.path}/${l}`;f.persons.some(h=>h.contact.person_id===m)||f.persons.push({contact:i,label:c,path:s,segment:l,isPrimary:!0});continue}let x=null,k=f.path;if(D.length>0){let l=D[0],s=`department:${w(l)}`;x=N(f.departments,s,()=>({label:l,segment:s,path:`${k}/${s}`,children:new Map,persons:[],personCount:0})),k=x.path,x.personCount+=1;for(let g=1;g<D.length;g++){let h=D[g],T=`department:${w(h)}`;if(!x)throw new Error("[contact-map] unexpected null currentDepartmentNode");x=N(x.children,T,()=>({label:h,segment:T,path:`${k}/${T}`,children:new Map,persons:[],personCount:0})),k=x.path,x.personCount+=1}}else continue;let C=`person:${m}`,P=`${x.path}/${C}`;x.persons.some(l=>l.contact.person_id===m)||x.persons.push({contact:i,label:c,path:P,segment:C,isPrimary:p===0})}f.personCount+=1}o&&(this.cachedResult=null)}getSnapshot(){if(this.cachedResult)return this.cachedResult;let t={},r=L(Array.from(this.companyMap.values())).map(o=>{let i=L(Array.from(o.departments.values())).map(H),m=v([...o.persons]).map(U),b={name:o.label,type:"directory",absolutePath:o.path,relativePath:o.segment,children:[...m,...i],memberCount:o.personCount};return t[o.label]=b,b});return this.cachedResult={tree:r,companyMap:t},this.cachedResult}append(t){this.appendRecords(t)}build(){return this.getSnapshot().tree}reset(){this.companyMap.clear(),this.processedPersonIds.clear(),this.allDepts.clear(),this.cachedResult=null}getUniquePersonCount(){return this.processedPersonIds.size}get size(){return this.processedPersonIds.size}},Re=(e,t)=>{let r=new I(t);return r.appendRecords(e),r.getSnapshot()};var W=e=>{if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null},Ee=e=>!e||typeof e!="object"?null:"item"in e?e.item??null:"person_id"in e?e:null,Q=(e,t)=>{if(!e)return{value:null,fieldKey:null};for(let r of t){let o=W(e[r]);if(o)return{value:o,fieldKey:r}}return{value:null,fieldKey:null}},Me=e=>Q(e,["custom_email","email"]),Oe=e=>Q(e,["custom_mobile_phone_number","mobile_phone_number","company_phone_number"]),We=e=>{let t=W(e);if(!t)return null;let r=t.replace(/[^0-9+#*]/g,"");return r.length===0?null:`tel:${r}`},ze=(e,t)=>{let r=W(e);return r?t?`https://mail.google.com/mail/?view=cm&fs=1&to=${encodeURIComponent(r)}`:`mailto:${encodeURIComponent(r)}`:null},Ne=e=>{if(!e)return"-";let t=typeof e=="string"||typeof e=="number"?new Date(e):e;return!(t instanceof Date)||Number.isNaN(t.getTime())?typeof e=="string"?e:"-":t.toISOString().split("T")[0]},ie=e=>{if(!e)return"-";let t=typeof e=="string"||typeof e=="number"?new Date(e):e;return!(t instanceof Date)||Number.isNaN(t.getTime())?typeof e=="string"?e:"-":t.toISOString()},we=e=>e==null?"-":typeof e=="string"?W(e)??"-":typeof e=="number"?Number.isFinite(e)?String(e):"-":e instanceof Date?ie(e):String(e);var Ie={listPanelMinWidth:320,detailPanelMinWidth:260,handleThickness:10,listPaddingAndBorder:0,detailPaddingAndBorder:0,scrollbarSafetyBuffer:20,hysteresisSafetyMargin:35},Fe={listPanelMinWidth:280,detailPanelMinWidth:260,handleThickness:10,listPaddingAndBorder:0,detailPaddingAndBorder:0,scrollbarSafetyBuffer:20,hysteresisSafetyMargin:35};function Ae(e){let t=e.listPanelMinWidth+e.detailPanelMinWidth+e.handleThickness+e.listPaddingAndBorder+e.detailPaddingAndBorder,r=t+e.scrollbarSafetyBuffer,o=r+e.hysteresisSafetyMargin,i=o-r;return{physicalMinWidth:t,collapseThreshold:r,expandThreshold:o,hysteresisWidth:i}}function $e(e,t,r){return e<=0||!Number.isFinite(e)?!1:t?e>=r.collapseThreshold:e>=r.expandThreshold}var Ke={info:(e,...t)=>console.info(`[contact-map] ${e}`,...t),warn:(e,...t)=>console.warn(`[contact-map] ${e}`,...t),error:(e,...t)=>console.error(`[contact-map] ${e}`,...t)};import{getNormalizedVariants as se,normalizeText as le,romajiToKatakana as pe}from"@aiquants/select-box";var ce=/[​]/g,ue=/^[\s  ]+|[\s  ]+$/g,de=/\s+/,me=/^[\p{Script=Latin}\s]+$/u,fe=/\p{Script=Latin}/u,q=Object.freeze({convertWidth:!0,convertKana:!0,convertCase:!0,convertRomaji:!1}),he=e=>le(e.replace(ce,"").replace(ue,""),q),ge=e=>{if(!me.test(e))return null;let t=pe(e);return fe.test(t)?null:t},V=e=>e.split(de).filter(Boolean),ye=e=>{let t=he(e),r=ge(t);return r===null?t:r},be=e=>{let t=new Set([...V(e),...V(ye(e))]),r=new Set;for(let o of t)for(let i of se(o,q)){let m=i.trim();m&&r.add(m)}return Array.from(r)},De=/[.*+?^${}()|[\]\\]/g,Te=e=>{let t=be(e);if(t.length===0)return null;let r=t.map(o=>o.replace(De,"\\$&")).sort((o,i)=>i.length-o.length);return new RegExp(r.join("|"),"gi")},Ue=(e,t)=>{let r=Te(e);if(r===null)return i=>i;let o=i=>t.some(m=>{let b=i[m];return typeof b=="string"&&b.search(r)!==-1});return i=>{let m=[],b=[];for(let c of i)o(c.item)?m.push(c):b.push(c);return[...m,...b]}};import{z as u}from"zod";var xe=u.object({person_id:u.union([u.string(),u.number()]).transform(e=>{if(typeof e=="number")return e;let t=e.trim();return parseInt(t,10)}).pipe(u.number()),person_id_redirect_to:u.union([u.string(),u.number()]).nullable().optional().transform(e=>{if(e==null)return null;if(typeof e=="number")return e;let t=e.trim();if(t.length===0)return null;let r=parseInt(t,10);return Number.isNaN(r)?null:r}),full_name:u.string().nullable().optional(),full_name_reading:u.string().nullable().optional(),company_name:u.string().nullable().optional(),company_name_reading:u.string().nullable().optional(),department:u.string().nullable().optional(),title:u.string().nullable().optional(),address:u.string().nullable().optional(),postal_code:u.string().nullable().optional(),email:u.string().nullable().optional(),custom_email:u.string().nullable().optional(),company_phone_number:u.string().nullable().optional(),custom_company_phone_number:u.string().nullable().optional(),company_fax_number:u.string().nullable().optional(),mobile_phone_number:u.string().nullable().optional(),custom_mobile_phone_number:u.string().nullable().optional(),url:u.string().nullable().optional(),contacted_at:u.union([u.date(),u.string()]).nullable().optional(),contacted_by:u.string().nullable().optional(),is_in_eight:u.boolean().nullable().optional(),is_contact_synced:u.boolean().nullable().optional(),is_active:u.boolean(),is_incomplete:u.boolean().nullable().optional(),created_at:u.union([u.date(),u.string()]).optional(),created_by:u.string().optional(),updated_at:u.union([u.date(),u.string()]).optional(),updated_by:u.string().optional()}),Ve=u.array(xe);export{Ie as DEFAULT_LIST_LAYOUT_SPEC,Fe as DEFAULT_TREE_LAYOUT_SPEC,I as IncrementalTreeBuilder,B as StandardDepartmentParser,K as TitleBasedDepartmentParser,re as assertContactMapTreeNaming,Re as buildDirectoryTree,Ae as calculateResponsiveThresholds,Ue as createExactMatchRanker,Te as createSearchQueryPattern,Ke as defaultLogger,Ee as extractContactData,$ as extractDepartmentsFromTitle,Ne as formatDate,ie as formatDateTime,ze as getEmailLinkHref,$e as getHysteresisBreakpointState,We as getPhoneDialHref,Me as getPrimaryEmail,Oe as getPrimaryPhone,be as getSearchQuerySpellings,E as normalizeLabel,ye as normalizeSearchInput,W as normalizeString,xe as schemaContactRecord,Ve as schemaContactRecords,te as splitDepartment,we as toDisplayValue};
1
+ var E=(e,t)=>e&&e.trim()||t;var te={\u672C\u90E8:{rank:10,type:"Organization"},\u30AB\u30F3\u30D1\u30CB\u30FC:{rank:10,type:"Organization"},\u672C\u793E:{rank:10,type:"Location"},\u30D6\u30ED\u30C3\u30AF:{rank:11,type:"Location"},\u652F\u5E97:{rank:12,type:"Location"},\u7814\u7A76\u6240:{rank:15,type:"Location"},\u5DE5\u5834:{rank:15,type:"Location"},\u4E8B\u696D\u90E8:{rank:18,type:"Organization"},\u90E8\u9580:{rank:18,type:"Organization"},\u7D71\u62EC\u90E8:{rank:19,type:"Organization"},\u90E8:{rank:20,type:"Organization"},\u958B\u767A:{rank:20,type:"Organization"},\u30B0\u30EB\u30FC\u30D7:{rank:22,type:"Organization"},\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8:{rank:25,type:"Organization"},\u63A8\u9032:{rank:20,type:"Organization"},\u4E8B\u696D\u6240:{rank:25,type:"Location"},\u55B6\u696D\u6240:{rank:28,type:"Location"},\u5BA4:{rank:30,type:"Organization"},\u8AB2:{rank:30,type:"Organization"},\u30BB\u30F3\u30BF\u30FC:{rank:30,type:"Location"},\u30D3\u30B8\u30CD\u30B9\u30D7\u30ED\u30C7\u30E5\u30FC\u30B9\u30BB\u30F3\u30BF\u30FC:{rank:30,type:"Location"},\u30C1\u30FC\u30E0:{rank:40,type:"Organization"},\u4FC2:{rank:50,type:"Organization"},Department:{rank:20,type:"Organization"},Dept:{rank:20,type:"Organization"},"Dept.":{rank:20,type:"Organization"},Division:{rank:20,type:"Organization"},Div:{rank:20,type:"Organization"},"Div.":{rank:20,type:"Organization"},Section:{rank:30,type:"Organization"},Sect:{rank:30,type:"Organization"},"Sect.":{rank:30,type:"Organization"},Unit:{rank:30,type:"Organization"},Group:{rank:22,type:"Organization"},Team:{rank:40,type:"Organization"},Branch:{rank:12,type:"Location"},Office:{rank:28,type:"Location"},Center:{rank:30,type:"Location"},Centre:{rank:30,type:"Location"},HQ:{rank:10,type:"Organization"},Headquarters:{rank:10,type:"Organization"}},R=e=>{for(let[t,r]of Object.entries(te))if(e.endsWith(t))return r;return{rank:99,type:"Other"}},F=e=>R(e).rank,ne=["\u30B0\u30EB\u30FC\u30D7","\u30C1\u30FC\u30E0","Group","Team","\u5BA4","\u8AB2","Unit","Area","\u90E8","Department","Dept","Division","Div","\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8","\u63A8\u9032"],_=e=>ne.find(t=>e.endsWith(t)),re=new Set(["&","Quality","Innovation","R&D","Solutions","Development","Laboratory","and","Food","Beverage"]),oe=(e,t)=>t>1&&(e.endsWith("\u652F\u5E97")||e.endsWith("\u672C\u90E8")||e.endsWith("\u4E8B\u696D\u6240")||e.endsWith("\u5DE5\u5834")),ae=(e,t)=>{if(!t)return!0;let r=R(e),o=R(t);if(r.rank<o.rank||e.endsWith("\u672C\u90E8")&&t.endsWith("\u672C\u90E8"))return!1;let s=_(e),m=_(t);return!(s&&m&&s!==m)},M=(e,t)=>{if(!e)return[];if(e==="\u517C")return["\u517C"];if(e==="\u517C\u52D9")return["\u517C"];if(e.startsWith("\u517C ")||e.startsWith("\u517C\u3000")){let o=e.slice(1).trim();return["\u517C",...M(o,t)]}if(e.startsWith("\u517C\u52D9 ")||e.startsWith("\u517C\u52D9\u3000")){let o=e.slice(2).trim();return["\u517C",...M(o,t)]}let r="";for(let o=e.length-1;o>0;o--){if(e[o]!==" ")continue;let s=e.slice(0,o);if(!re.has(s)&&t.has(s)){r=s;break}}if(r){let o=r,s=e.slice(r.length),m=/^\s+(and|&)\s+([A-Za-z0-9]+)/i,b=s.match(m);b&&(o=e.slice(0,r.length+b[0].length));let c=e.slice(o.length),n=["Department","Dept","Division","Div","Section","Sect","Unit","Group","Team","Branch","Office","Center","Centre","HQ","Headquarters"];for(let a of n){let y=new RegExp(`^\\s+${a}\\.?(?=$|[\\s,])`,"i"),p=c.match(y);if(p){o=e.slice(0,o.length+p[0].length);break}}let f=e.slice(o.length).trim();return[o,...M(f,t)]}return[e]},se=(e,t)=>{let o=e.replace(/[\s\u3000]+(?:兼務|兼)[\s\u3000]+/g,"\u3000\u517C\u3000").replace(/^(?:兼務|兼)[\s\u3000]+/,"\u517C\u3000").replace(/[\s\u3000]+(?:兼務|兼)$/,"\u3000\u517C").split(/\u3000/),s=[];for(let m of o){let b=m.trim();b&&s.push(...M(b,t))}return s},$=(e,t)=>{let r=[],o=["\u90E8","\u8AB2","\u5BA4","\u672C\u90E8","\u652F\u5E97","\u55B6\u696D\u6240","\u30B0\u30EB\u30FC\u30D7","\u30C1\u30FC\u30E0","\u30BB\u30F3\u30BF\u30FC","\u30AB\u30F3\u30D1\u30CB\u30FC","\u4E8B\u696D\u6240","\u5DE5\u5834","\u7814\u7A76\u6240","\u4FC2","\u90E8\u9580","\u4E8B\u696D\u90E8","\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8","\u63A8\u9032","\u958B\u767A","Department","Dept","Division","Div","Section","Sect","Unit","Group","Team","Branch","Office","Center","Centre","HQ","Headquarters"],s=e.split(/[\s\u3000,()()[\]]+/).filter(Boolean),m=s.length,b=new Set;for(let c=m;c>=1;c--)for(let n=0;n<=m-c;n++){let f=!1;for(let y=n;y<n+c;y++)if(b.has(y)){f=!0;break}if(f)continue;let a=s.slice(n,n+c).join(" ");if(!(a==="\u517C"||a==="\u517C\u52D9"||a==="\u4FC2"||a==="of"||a==="&"||a==="Quality"||a==="Innovation"||a==="R&D"||a==="Solutions"||a==="Development"||a==="Laboratory"||a==="and"||a==="Food"||a==="Beverage")&&t.allKnownDepartments.has(a)){r.push({name:a,index:n});for(let y=n;y<n+c;y++)b.add(y)}}for(let c=0;c<m;c++){if(b.has(c))continue;let n=s[c];for(n.endsWith("\u9577")&&n.length>1?n=n.slice(0,-1):n.endsWith("\u7D71\u62EC")&&n.length>2&&(n=n.slice(0,-2));;){let p=!1;if(n.startsWith("\u62C5\u5F53")&&n.length>2||n.startsWith("\u5C02\u4EFB")&&n.length>2||n.startsWith("\u517C\u52D9")&&n.length>2?(n=n.slice(2),p=!0):(n.startsWith("\u526F")||n.startsWith("\u517C"))&&n.length>1&&(n=n.slice(1),p=!0),!p)break}if(n.includes("\u30FB")&&!t.allKnownDepartments.has(n)){let p=n.split("\u30FB"),D=p[p.length-1],x=o.find(k=>D.endsWith(k));if(x){for(let k of p){let C=k;o.some(i=>C.endsWith(i))||(C=C+x);let S=n!=="\u517C"&&n!=="\u4FC2"&&n!=="of"&&n!=="&"&&n!=="Quality"&&n!=="Innovation"&&n!=="R&D"&&n!=="Solutions"&&n!=="Development"&&n!=="Laboratory"&&n!=="and"&&n!=="Food"&&n!=="Beverage"&&t.allKnownDepartments.has(C),d=o.some(i=>C.endsWith(i)),l=o.includes(C);(S||d&&!l)&&r.push({name:C,index:c})}continue}}let f=n!=="\u517C"&&n!=="\u4FC2"&&n!=="of"&&n!=="&"&&n!=="Quality"&&n!=="Innovation"&&n!=="R&D"&&n!=="Solutions"&&n!=="Development"&&n!=="Laboratory"&&n!=="and"&&n!=="Food"&&n!=="Beverage"&&t.allKnownDepartments.has(n),a=o.some(p=>n.endsWith(p)),y=o.includes(n);(f||a&&!y)&&r.push({name:n,index:c})}return r.sort((c,n)=>c.index-n.index),r.map(c=>c.name)},A=(e,t)=>{let r=0;for(let o of t)r<e.length&&o===e[r]&&r++;return r===e.length},B={name:"Standard",parse:(e,t,r="full")=>{let o=E(e.department,"");if(!o)return null;let s=se(o,t.allKnownDepartments),m=new Map;for(let n of s)m.set(n,(m.get(n)||0)+1);let b=n=>{let f=[],a=[];for(let y=0;y<n.length;y++){let p=n[y];if(p==="\u517C"){a.length>0&&(f.push(a),a=[]);continue}let D=R(p),x=D.rank,k=m.get(p)||0,C=oe(p,k);if(a.length===0)a.push(p);else{let S=a[a.length-1],d=R(S),l=d.rank;if(a.includes(p))f.push(a),a=[p];else{let i=!1;if(C)i=!0;else if(d.type===D.type){let g=_(S),h=_(p);g&&h&&g!==h||S.endsWith("\u672C\u90E8")&&p.endsWith("\u672C\u90E8")||S.endsWith("\u90E8\u9580")&&p.endsWith("\u4E8B\u696D\u90E8")||S.endsWith("\u4E8B\u696D\u90E8")&&p.endsWith("\u90E8\u9580")||S.endsWith("\u90E8\u9580")&&p.endsWith("\u672C\u90E8")||d.type==="Other"&&D.type==="Other"?i=!0:i=l<x}else i=x>=10,i&&d.type==="Location"&&D.type==="Organization"&&l>=x&&n.slice(y+1).includes(S)&&(i=!1);i?a.push(p):(f.push(a),a=[p])}}if(C){let S=y+1<n.length?n[y+1]:void 0;ae(p,S)&&a.length>0&&(f.push(a),a=[])}}return a.length>0&&f.push(a),f},c=[];if(r==="full"&&c.push(...b(s)),r==="pure_org"){let n=s.filter(f=>R(f).type!=="Location");n.length>0&&c.push(...b(n))}if(e.title){let f=/[^\x20-\x7E]/.test(e.title)?/[\s\u3000]*(?:兼務|兼)[\s\u3000]*/:/[,;]|(?:兼務|兼)/,a=e.title.split(f).filter(Boolean),y=[],p=(d,l)=>{let i=F(d),g=F(l),h=i<g;if(!h){let T=_(d),P=_(l);if(T&&P&&T!==P)h=!0;else if(d.endsWith("\u672C\u90E8")&&l.endsWith("\u672C\u90E8"))h=!0;else if(d.endsWith("\u90E8\u9580")&&l.endsWith("\u4E8B\u696D\u90E8")||d.endsWith("\u4E8B\u696D\u90E8")&&l.endsWith("\u90E8\u9580"))h=!0;else if(d.endsWith("\u90E8\u9580")&&l.endsWith("\u672C\u90E8"))h=!0;else{let W=R(d),ee=R(l);W.type==="Other"&&ee.type==="Other"&&(h=!0)}}return h};for(let d of a){let l=$(d,t);if(l.length===0)continue;let i=[];for(let g of l)if(i.length===0)i.push(g);else{let h=i[i.length-1];if(p(h,g))i.push(g);else{y.push([...i]);let T=!1;for(let P=i.length-2;P>=0;P--){let W=i[P];if(p(W,g)){i=[...i.slice(0,P+1),g],T=!0;break}}T||(i=[g])}}i.length>0&&y.push(i)}let D=[...c],x=d=>a.some(l=>l.includes(d)&&l.length>d.length);for(let d of y){let l=!1;for(let i of c){let g=i.findIndex(h=>d.includes(h));if(g!==-1){let h=i[g],T=d.indexOf(h);if(g>0&&T===0){let P=i.slice(0,g);D.push([...P,...d]),l=!0}else if(T>0&&g===0){let P=d.slice(0,T);D.push([...P,...i]),D.push(d),l=!0}else d.length>i.length-g,l=!0}if(!l){let h=i[i.length-1],T=d[0];p(h,T)&&(D.push([...i,...d]),l=!0)}}l||D.push(d)}let k=[],C=[],S=new Set;for(let d of D){let l=d.join("|");S.has(l)||(S.add(l),C.push(d))}for(let d=0;d<C.length;d++){let l=C[d],i=!1;for(let g=0;g<C.length;g++){if(d===g)continue;let h=C[g];if(h.length>l.length&&h.slice(0,l.length).join("|")===l.join("|")){let T=l[l.length-1];if(!x(T)){i=!0;break}}if(h.length>l.length&&A(l,h)){let T=l[l.length-1];if(!x(T)){i=!0;break}}if(l.length===1&&h.length>0){let T=l[0],P=h[h.length-1];if(T!==P&&P.endsWith(T)){i=!0;break}}}i||k.push(l)}return k.length>0?k:null}if(c.length>0){let n=[];for(let f=0;f<c.length;f++){let a=c[f],y=!1;for(let p=0;p<c.length;p++){if(f===p)continue;let D=c[p];if(D.length>a.length&&A(a,D)){y=!0;break}}y||n.push(a)}return n.length>0?n:null}return null}},K={name:"TitleBased",parse:(e,t,r="full")=>{let o=e.title;if(!o)return null;let s=$(o,t);return s.length>0?[s]:null}};var O=e=>{switch(typeof e){case"string":return JSON.stringify(e);case"bigint":return`${e}n`;case"symbol":return e.toString();case"object":return e===null?"null":j(e);case"function":return j(e);case"number":return Object.is(e,-0)?"-0":String(e);default:return String(e)}},j=e=>{try{return Object.prototype.toString.call(e)}catch{return"[object ?]"}};var ie=["uncategorizedCompany","unnamedPerson"],le=e=>{if(typeof e!="object"||e===null)throw new TypeError(`[contact-map] tree naming must be an object; got ${O(e)}`);for(let t of ie){let r=e[t];if(typeof r!="string")throw new TypeError(`[contact-map] tree naming.${t} must be a string; got ${O(r)}`);if(r.trim()==="")throw new RangeError(`[contact-map] tree naming.${t} must not be empty or blank; got ${O(r)}`)}},pe=[B,K],ce=(e,t)=>{let r=E(e.full_name,t),o=E(e.title,"");return o.length>0?`${r} (${o})`:r},L=e=>e.sort((t,r)=>t.label.localeCompare(r.label,"ja")),z=(e,t,r)=>{let o=e.get(t);if(o)return o;let s=r();return e.set(t,s),s},N=e=>encodeURIComponent(e.replace(/\//g,"\uFF0F")),v=e=>e.sort((t,r)=>{let o=!!(t.contact.title&&t.contact.title.trim().length>0),s=!!(r.contact.title&&r.contact.title.trim().length>0);return o&&!s?-1:!o&&s?1:t.label.localeCompare(r.label,"ja")}),U=e=>({name:e.label,type:"file",absolutePath:e.path,relativePath:e.segment,personId:e.contact.person_id,title:e.contact.title||void 0,isPrimary:e.isPrimary}),Q=e=>{let t=L(Array.from(e.children.values())).map(Q),r=v([...e.persons]).map(U);return{name:e.label,type:"directory",absolutePath:e.path,relativePath:e.segment,children:[...r,...t],memberCount:e.personCount}},I=class{constructor(t){this.companyMap=new Map;this.processedPersonIds=new Set;this.allDepts=new Set;this.cachedResult=null;le(t),this.naming=t}appendRecords(t){if(!t||t.length===0)return;let r="full",o=!1;for(let s of t)if(!this.processedPersonIds.has(s.person_id)&&s.department){let m=s.department.split(/\u3000/);for(let b of m){let c=b.trim();if(!c||c==="\u517C"||c==="\u4FC2")continue;if(/[^\x20-\x7E]/.test(c)){let f=c.split(" ").filter(a=>a.length>0&&a!=="\u517C"&&a!=="\u4FC2");for(let a of f)this.allDepts.add(a)}else this.allDepts.add(c)}}for(let s of t){let m=s.person_id;if(!Number.isFinite(m)||this.processedPersonIds.has(m))continue;this.processedPersonIds.add(m),o=!0;let b=E(s.company_name,this.naming.uncategorizedCompany),c=ce(s,this.naming.unnamedPerson),n=`company:${N(b)}`,f=z(this.companyMap,n,()=>({label:b,segment:n,path:`/${n}`,departments:new Map,persons:[],personCount:0})),a=[],y={allKnownDepartments:this.allDepts};for(let p of pe){let D=p.parse(s,y,r);if(D&&D.length>0){a=D;break}}a.length===0&&a.push([]);for(let p=0;p<a.length;p++){let D=a[p];if(D.length===0){let l=`person:${m}`,i=`${f.path}/${l}`;f.persons.some(h=>h.contact.person_id===m)||f.persons.push({contact:s,label:c,path:i,segment:l,isPrimary:!0});continue}let x=null,k=f.path;if(D.length>0){let l=D[0],i=`department:${N(l)}`;x=z(f.departments,i,()=>({label:l,segment:i,path:`${k}/${i}`,children:new Map,persons:[],personCount:0})),k=x.path,x.personCount+=1;for(let g=1;g<D.length;g++){let h=D[g],T=`department:${N(h)}`;if(!x)throw new Error("[contact-map] unexpected null currentDepartmentNode");x=z(x.children,T,()=>({label:h,segment:T,path:`${k}/${T}`,children:new Map,persons:[],personCount:0})),k=x.path,x.personCount+=1}}else continue;let C=`person:${m}`,S=`${x.path}/${C}`;x.persons.some(l=>l.contact.person_id===m)||x.persons.push({contact:s,label:c,path:S,segment:C,isPrimary:p===0})}f.personCount+=1}o&&(this.cachedResult=null)}getSnapshot(){if(this.cachedResult)return this.cachedResult;let t={},r=L(Array.from(this.companyMap.values())).map(o=>{let s=L(Array.from(o.departments.values())).map(Q),m=v([...o.persons]).map(U),b={name:o.label,type:"directory",absolutePath:o.path,relativePath:o.segment,children:[...m,...s],memberCount:o.personCount};return t[o.label]=b,b});return this.cachedResult={tree:r,companyMap:t},this.cachedResult}append(t){this.appendRecords(t)}build(){return this.getSnapshot().tree}reset(){this.companyMap.clear(),this.processedPersonIds.clear(),this.allDepts.clear(),this.cachedResult=null}getUniquePersonCount(){return this.processedPersonIds.size}get size(){return this.processedPersonIds.size}},We=(e,t)=>{let r=new I(t);return r.appendRecords(e),r.getSnapshot()};var w=e=>{if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null},Ne=e=>!e||typeof e!="object"?null:"item"in e?e.item??null:"person_id"in e?e:null,H=(e,t)=>{if(!e)return{value:null,fieldKey:null};for(let r of t){let o=w(e[r]);if(o)return{value:o,fieldKey:r}}return{value:null,fieldKey:null}},Le=e=>H(e,["custom_email","email"]),Ie=e=>H(e,["custom_mobile_phone_number","mobile_phone_number","company_phone_number"]),Fe=e=>{let t=w(e);if(!t)return null;let r=t.replace(/[^0-9+#*]/g,"");return r.length===0?null:`tel:${r}`},Ae=(e,t)=>{let r=w(e);return r?t?`https://mail.google.com/mail/?view=cm&fs=1&to=${encodeURIComponent(r)}`:`mailto:${encodeURIComponent(r)}`:null},$e=e=>{if(!e)return"-";let t=typeof e=="string"||typeof e=="number"?new Date(e):e;return!(t instanceof Date)||Number.isNaN(t.getTime())?typeof e=="string"?e:"-":t.toISOString().split("T")[0]},ue=e=>{if(!e)return"-";let t=typeof e=="string"||typeof e=="number"?new Date(e):e;return!(t instanceof Date)||Number.isNaN(t.getTime())?typeof e=="string"?e:"-":t.toISOString()},Be=e=>e==null?"-":typeof e=="string"?w(e)??"-":typeof e=="number"?Number.isFinite(e)?String(e):"-":e instanceof Date?ue(e):String(e);var je={listPanelMinWidth:320,detailPanelMinWidth:260,handleThickness:10,listPaddingAndBorder:0,detailPaddingAndBorder:0,scrollbarSafetyBuffer:20,hysteresisSafetyMargin:35},ve={listPanelMinWidth:280,detailPanelMinWidth:260,handleThickness:10,listPaddingAndBorder:0,detailPaddingAndBorder:0,scrollbarSafetyBuffer:20,hysteresisSafetyMargin:35};function Ue(e){let t=e.listPanelMinWidth+e.detailPanelMinWidth+e.handleThickness+e.listPaddingAndBorder+e.detailPaddingAndBorder,r=t+e.scrollbarSafetyBuffer,o=r+e.hysteresisSafetyMargin,s=o-r;return{physicalMinWidth:t,collapseThreshold:r,expandThreshold:o,hysteresisWidth:s}}function Qe(e,t,r){return e<=0||!Number.isFinite(e)?!1:t?e>=r.collapseThreshold:e>=r.expandThreshold}var Ve={info:(e,...t)=>console.info(`[contact-map] ${e}`,...t),warn:(e,...t)=>console.warn(`[contact-map] ${e}`,...t),error:(e,...t)=>console.error(`[contact-map] ${e}`,...t)};import{formatQuerySets as de,parseQuerySets as me}from"@aiquants/fuzzy-search";import{getNormalizedVariants as fe,normalizeText as he,romajiToKatakana as ge}from"@aiquants/select-box";var G=/[​]/g,ye=/^[\s  ]+|[\s  ]+$/g,be=/\s+/,De=/^[\p{Script=Latin}\s]+$/u,Te=/\p{Script=Latin}/u,J=Object.freeze({convertWidth:!0,convertKana:!0,convertCase:!0,convertRomaji:!1}),X="union",xe=e=>he(e.replace(G,"").replace(ye,""),J),Ce=e=>{if(!De.test(e))return null;let t=ge(e);return Te.test(t)?null:t},Y=e=>e.split(be).filter(Boolean),Z=e=>me(e,X).sets.map(({query:t})=>t),V=e=>Z(e).flatMap(t=>Y(t)),q=e=>de({combine:X,sets:Array.from(new Set(e),t=>({query:t}))}),Se=e=>{let t=Z(e.replace(G,"")).map(o=>Y(xe(o)).join(" ")).filter(o=>o!==""),r=[];for(let o of t){let s=Ce(o);if(s===null)return q(t);r.push(s)}return q(r)},Pe=e=>{let t=new Set([...V(e),...V(Se(e))]),r=new Set;for(let o of t)for(let s of fe(o,J)){let m=s.trim();m&&r.add(m)}return Array.from(r)},ke=/[.*+?^${}()|[\]\\]/g,Re=e=>{let t=Pe(e);if(t.length===0)return null;let r=t.map(o=>o.replace(ke,"\\$&")).sort((o,s)=>s.length-o.length);return new RegExp(r.join("|"),"gi")},Xe=(e,t)=>{let r=Re(e);if(r===null)return s=>s;let o=s=>t.some(m=>{let b=s[m];return typeof b=="string"&&b.search(r)!==-1});return s=>{let m=[],b=[];for(let c of s)o(c.item)?m.push(c):b.push(c);return[...m,...b]}};import{z as u}from"zod";var _e=u.object({person_id:u.union([u.string(),u.number()]).transform(e=>{if(typeof e=="number")return e;let t=e.trim();return parseInt(t,10)}).pipe(u.number()),person_id_redirect_to:u.union([u.string(),u.number()]).nullable().optional().transform(e=>{if(e==null)return null;if(typeof e=="number")return e;let t=e.trim();if(t.length===0)return null;let r=parseInt(t,10);return Number.isNaN(r)?null:r}),full_name:u.string().nullable().optional(),full_name_reading:u.string().nullable().optional(),company_name:u.string().nullable().optional(),company_name_reading:u.string().nullable().optional(),department:u.string().nullable().optional(),title:u.string().nullable().optional(),address:u.string().nullable().optional(),postal_code:u.string().nullable().optional(),email:u.string().nullable().optional(),custom_email:u.string().nullable().optional(),company_phone_number:u.string().nullable().optional(),custom_company_phone_number:u.string().nullable().optional(),company_fax_number:u.string().nullable().optional(),mobile_phone_number:u.string().nullable().optional(),custom_mobile_phone_number:u.string().nullable().optional(),url:u.string().nullable().optional(),contacted_at:u.union([u.date(),u.string()]).nullable().optional(),contacted_by:u.string().nullable().optional(),is_in_eight:u.boolean().nullable().optional(),is_contact_synced:u.boolean().nullable().optional(),is_active:u.boolean(),is_incomplete:u.boolean().nullable().optional(),created_at:u.union([u.date(),u.string()]).optional(),created_by:u.string().optional(),updated_at:u.union([u.date(),u.string()]).optional(),updated_by:u.string().optional()}),et=u.array(_e);export{je as DEFAULT_LIST_LAYOUT_SPEC,ve as DEFAULT_TREE_LAYOUT_SPEC,I as IncrementalTreeBuilder,B as StandardDepartmentParser,K as TitleBasedDepartmentParser,le as assertContactMapTreeNaming,We as buildDirectoryTree,Ue as calculateResponsiveThresholds,Xe as createExactMatchRanker,Re as createSearchQueryPattern,Ve as defaultLogger,Ne as extractContactData,$ as extractDepartmentsFromTitle,$e as formatDate,ue as formatDateTime,Ae as getEmailLinkHref,Qe as getHysteresisBreakpointState,Fe as getPhoneDialHref,Le as getPrimaryEmail,Ie as getPrimaryPhone,Pe as getSearchQuerySpellings,E as normalizeLabel,Se as normalizeSearchInput,w as normalizeString,_e as schemaContactRecord,et as schemaContactRecords,se as splitDepartment,Be as toDisplayValue};
package/dist/server.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as ContactMapLogger, C as ContactRecord, h as StreamCursor } from "./wire-hAxBVVH6.mjs";
1
+ import { d as ContactMapLogger, C as ContactRecord, h as StreamCursor } from "./wire-BghOEeyw.mjs";
2
2
  import { AnyMsSqlColumn, mssqlSchema } from "drizzle-orm/mssql-core";
3
3
  interface ContactRecordTable {
4
4
  person_id: AnyMsSqlColumn;
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as ContactMapLogger, C as ContactRecord, h as StreamCursor } from "./wire-hAxBVVH6.js";
1
+ import { d as ContactMapLogger, C as ContactRecord, h as StreamCursor } from "./wire-BghOEeyw.js";
2
2
  import { AnyMsSqlColumn, mssqlSchema } from "drizzle-orm/mssql-core";
3
3
  interface ContactRecordTable {
4
4
  person_id: AnyMsSqlColumn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiquants/contact-map",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Reusable contact-map feature package: shared types/schemas, React (Router v7 / v8) UI with virtual scrolling + tree view + incremental Web Worker + fuzzy search + resize panels, and a drizzle (mssql) server layer with DI ports.",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -59,12 +59,12 @@
59
59
  "tailwind-merge": "^3.5.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@aiquants/directory-tree": "^4.0.0",
63
- "@aiquants/fuzzy-search": "^3.0.0",
64
- "@aiquants/resize-panels": "^2.0.1",
65
- "@aiquants/select-box": "^0.16.0",
62
+ "@aiquants/directory-tree": "^4.1.0",
63
+ "@aiquants/fuzzy-search": "^3.2.0",
64
+ "@aiquants/resize-panels": "^2.1.0",
65
+ "@aiquants/select-box": "^0.16.3",
66
66
  "@aiquants/swipe-overlay": "^1.2.5",
67
- "@aiquants/virtualscroll": "^3.11.1",
67
+ "@aiquants/virtualscroll": "^3.12.0",
68
68
  "@tailwindcss/cli": "^4.1.18",
69
69
  "@testing-library/jest-dom": "^6.9.1",
70
70
  "@testing-library/react": "^16.3.2",
@@ -85,12 +85,12 @@
85
85
  "zod": "^3.25.76"
86
86
  },
87
87
  "peerDependencies": {
88
- "@aiquants/directory-tree": "^4.0.0",
89
- "@aiquants/fuzzy-search": "^3.0.0",
90
- "@aiquants/resize-panels": "^2.0.1",
91
- "@aiquants/select-box": "^0.16.0",
88
+ "@aiquants/directory-tree": "^4.1.0",
89
+ "@aiquants/fuzzy-search": "^3.2.0",
90
+ "@aiquants/resize-panels": "^2.1.0",
91
+ "@aiquants/select-box": "^0.16.3",
92
92
  "@aiquants/swipe-overlay": "^1.2.5",
93
- "@aiquants/virtualscroll": "^3.11.1",
93
+ "@aiquants/virtualscroll": "^3.12.0",
94
94
  "drizzle-orm": ">=1.0.0-beta.4 <2.0.0",
95
95
  "react": ">=18",
96
96
  "react-dom": ">=18",
File without changes