diff --git a/canvas/src/sme/ImportExportMenu.tsx b/canvas/src/sme/ImportExportMenu.tsx index bb62046..5b7d7f4 100644 --- a/canvas/src/sme/ImportExportMenu.tsx +++ b/canvas/src/sme/ImportExportMenu.tsx @@ -117,9 +117,10 @@ export function ImportExportMenu({ )} {formats.map((f) => { - // erwin export honours a single active subject-area filter (exports just that - // slice); every other format always exports the whole model. - const scoped = f.id === "erwin" ? scopeSubjectArea : null; + // erwin and SQL DDL export honour a single active subject-area filter (export just + // that slice, like erwin's own subject-area export); every other format always + // exports the whole model. + const scoped = f.id === "erwin" || f.id === "sql" ? scopeSubjectArea : null; return ( None: """Export CREATE TABLE DDL (PK/FK/UNIQUE/NOT NULL) for a chosen SQL dialect.""" from mdl_emit_erd import emit_sql_ddl repo = _load(model_dir) - _emit_text(emit_sql_ddl(repo.model, dialect=dialect), out, "sql") + _emit_text( + emit_sql_ddl(repo.model, dialect=dialect, subject_area=subject_area or None), out, "sql" + ) @export_app.command("mermaid") diff --git a/packages/emit-erd/src/mdl_emit_erd/model_view.py b/packages/emit-erd/src/mdl_emit_erd/model_view.py index fa646fd..5a244bb 100644 --- a/packages/emit-erd/src/mdl_emit_erd/model_view.py +++ b/packages/emit-erd/src/mdl_emit_erd/model_view.py @@ -48,13 +48,26 @@ class Table: pk_columns: list[str] = field(default_factory=list) # ordered +def _dedupe(ids: list[str]) -> list[str]: + """Order-preserving de-duplication. A key group whose members list the same attribute twice + (seen in real erwin-imported models) would otherwise emit `PRIMARY KEY (col, col)`, which + erwin's DDL importer rejects with 'Cannot add the same Attribute to Key'.""" + seen: set[str] = set() + out: list[str] = [] + for i in ids: + if i not in seen: + seen.add(i) + out.append(i) + return out + + def _pk_attr_ids(model: Model, le: LogicalEntity) -> list[str]: - """Ordered PK attribute ids: a `pk` KeyGroup wins (member order preserved), else - the `role: business_key` attributes. Mirrors the dbt emitter.""" + """Ordered, de-duplicated PK attribute ids: a `pk` KeyGroup wins (member order preserved), + else the `role: business_key` attributes. Mirrors the dbt emitter.""" for kg in model.key_groups.values(): if kg.entity == le.id and kg.type == "pk": - return list(kg.members) - return [a.id for a in le.attributes if a.role == "business_key"] + return _dedupe(list(kg.members)) + return _dedupe([a.id for a in le.attributes if a.role == "business_key"]) def _single_unique_attr_ids(model: Model, le: LogicalEntity) -> set[str]: @@ -65,12 +78,34 @@ def _single_unique_attr_ids(model: Model, le: LogicalEntity) -> set[str]: return out -def build_tables(model: Model, adapter) -> list[Table]: +def _scope_entity_ids(model: Model, subject_area: str) -> set[str]: + """The logical-entity ids that belong to `subject_area` (its name or id). SubjectArea.members + are CONCEPTUAL ids, so map each to the logical entity that realises it.""" + le_by_ce = {le.realises: le.id for le in model.logical_entities.values() if le.realises} + ids: set[str] = set() + for sa in model.subject_areas.values(): + if sa.name == subject_area or sa.id == subject_area: + for m in sa.members: + if m in le_by_ce: + ids.add(le_by_ce[m]) + return ids + + +def build_tables(model: Model, adapter, *, subject_area: str | None = None) -> list[Table]: """Project the model's logical entities into ER tables with columns, PKs, and FKs. `adapter` is a dbt PlatformAdapter (from mdl_emit_dbt.platforms.get_adapter) used - only for domain -> SQL type mapping, so DDL types match what dbt would emit.""" - ent_by_id = model.logical_entities + only for domain -> SQL type mapping, so DDL types match what dbt would emit. + + `subject_area` (a name or id) scopes the projection to ONE subject area, like erwin's + export: only that area's entities become tables, and a relationship with an end OUTSIDE + the area is DROPPED (no stub table for the neighbour). The neighbours already exist in the + target model; cross-area FKs are re-established there by hand. None = the whole model.""" + scope = _scope_entity_ids(model, subject_area) if subject_area else None + ent_by_id = { + eid: le for eid, le in model.logical_entities.items() + if scope is None or eid in scope + } name_by_id = {le.id: le.name for le in ent_by_id.values()} tables: dict[str, Table] = {} @@ -112,6 +147,14 @@ def build_tables(model: Model, adapter) -> list[Table]: parent_ent = ent_by_id.get(rel.to.entity) c_names = _resolve_names(child_ent, rel.from_.attributes) p_names = _resolve_names(parent_ent, rel.to.attributes) if parent_ent else [] + # A FK must reference the PARENT's key, or erwin refuses to create it ("there is not a + # primary or unique key in table '' that contains column ..."). When the + # relationship doesn't name the parent columns, default to the parent's PK so the + # REFERENCES points at a real key. + if not p_names and parent_ent is not None: + pk_ids = _pk_attr_ids(model, parent_ent) + by_id = {a.id: a.name for a in parent_ent.attributes} + p_names = [by_id[i] for i in pk_ids if i in by_id] if not c_names: continue # nothing concrete to anchor a FK to child_unique = rel.cardinality in ("one_to_one",) or _cols_unique(model, child_ent, c_names) @@ -132,7 +175,9 @@ def _resolve_names(entity, attr_ids: list[str]) -> list[str]: if entity is None: return [] by_id = {a.id: a.name for a in entity.attributes} - return [by_id[i] for i in attr_ids if i in by_id] + # de-dupe: a FK column set with a repeated member would emit `FOREIGN KEY (col, col)`, + # which erwin rejects the same way a duplicated PK column does. + return _dedupe([by_id[i] for i in attr_ids if i in by_id]) def _cols_unique(model: Model, entity, col_names: list[str]) -> bool: diff --git a/packages/emit-erd/src/mdl_emit_erd/sql_ddl.py b/packages/emit-erd/src/mdl_emit_erd/sql_ddl.py index 868461d..f11139e 100644 --- a/packages/emit-erd/src/mdl_emit_erd/sql_ddl.py +++ b/packages/emit-erd/src/mdl_emit_erd/sql_ddl.py @@ -20,12 +20,18 @@ def _ident(name: str, dialect: str) -> str: return f"{q}{name}{q}" -def emit_sql_ddl(model: Model, *, dialect: str = "postgres") -> str: +def emit_sql_ddl( + model: Model, *, dialect: str = "postgres", subject_area: str | None = None +) -> str: """CREATE TABLE statements with PK/UNIQUE/NOT NULL and FK REFERENCES. `dialect` selects the SQL type mapping via the dbt platform adapters (postgres|snowflake|redshift|duckdb|...); an unknown dialect falls back to duckdb's - generic types.""" + generic types. + + `subject_area` (a name or id) scopes the export to ONE subject area, like the erwin export: + only that area's tables are emitted and cross-area FKs are dropped (no stub table for the + out-of-area neighbour). None = the whole model.""" from mdl_emit_dbt.platforms import available_adapters, get_adapter adapter_name = dialect if dialect in available_adapters() else "duckdb" @@ -33,7 +39,7 @@ def emit_sql_ddl(model: Model, *, dialect: str = "postgres") -> str: if dialect == "postgres": adapter_name = "duckdb" adapter = get_adapter(adapter_name) - tables = build_tables(model, adapter) + tables = build_tables(model, adapter, subject_area=subject_area) out: list[str] = [f"-- SQL DDL ({dialect}) generated by Modelith", ""] for t in tables: diff --git a/packages/emit-erd/tests/test_emit_erd.py b/packages/emit-erd/tests/test_emit_erd.py index a1692be..78ead4a 100644 --- a/packages/emit-erd/tests/test_emit_erd.py +++ b/packages/emit-erd/tests/test_emit_erd.py @@ -49,6 +49,153 @@ def test_sql_ddl_has_tables_pk_and_fk(model): assert "REFERENCES" in ddl +def test_ddl_dedupes_a_duplicated_pk_member(): + """A `pk` key group with the same attribute listed twice (seen in real erwin-imported + models) must NOT emit `PRIMARY KEY (col, col)` — erwin's DDL importer rejects that with + 'Cannot add the same Attribute to Key'. The column appears exactly once.""" + from mdl_core.ids import new_ulid + from mdl_core.ir import ( + Attribute, + ConceptualEntity, + KeyGroup, + LogicalEntity, + Model, + ProjectConfig, + ) + + m = Model(ProjectConfig(name="dup")) + ce = ConceptualEntity(id=new_ulid(), name="Account") + m.add(ce) + acc_id = Attribute(id=new_ulid(), name="account_id", role="business_key", nullable=False, + domain="integer") + le = LogicalEntity(id=new_ulid(), name="account", realises=ce.id, attributes=[acc_id]) + m.add(le) + # the bug condition: the PK key group lists account_id TWICE + m.add(KeyGroup(id=new_ulid(), entity=le.id, name="pk_account", type="pk", + members=[acc_id.id, acc_id.id])) + + ddl = emit_sql_ddl(m, dialect="postgres") + pk_line = next(ln for ln in ddl.splitlines() if "PRIMARY KEY" in ln) + assert pk_line.count("account_id") == 1, pk_line + + +def test_ddl_fk_defaults_to_parent_pk_when_unspecified(): + """When a relationship doesn't name the parent columns, the FK REFERENCES the parent's PK + (not nothing), so erwin can actually create the key instead of dropping it with 'there is + not a primary or unique key in table ... that contains column'.""" + from mdl_core.ids import new_ulid + from mdl_core.ir import ( + Attribute, + ConceptualEntity, + KeyGroup, + LogicalEntity, + Model, + ProjectConfig, + Relationship, + RelationshipEnd, + ) + + m = Model(ProjectConfig(name="fk")) + pce = ConceptualEntity(id=new_ulid(), name="Account") + m.add(pce) + pk_attr = Attribute(id=new_ulid(), name="account_id", role="business_key", nullable=False, + domain="integer") + parent = LogicalEntity(id=new_ulid(), name="account", realises=pce.id, attributes=[pk_attr]) + m.add(parent) + m.add(KeyGroup(id=new_ulid(), entity=parent.id, name="pk_account", type="pk", + members=[pk_attr.id])) + cce = ConceptualEntity(id=new_ulid(), name="Trade") + m.add(cce) + c_pk = Attribute(id=new_ulid(), name="trade_id", role="business_key", nullable=False, + domain="integer") + c_fk = Attribute(id=new_ulid(), name="account_id", role="attribute", nullable=False, + domain="integer") + child = LogicalEntity(id=new_ulid(), name="trade", realises=cce.id, attributes=[c_pk, c_fk]) + m.add(child) + # relationship names the CHILD FK column but NOT the parent column + m.add(Relationship( + id=new_ulid(), name="trade_for_account", + **{"from": RelationshipEnd(entity=child.id, attributes=[c_fk.id])}, + to=RelationshipEnd(entity=parent.id, attributes=[]), + cardinality="many_to_one")) + + ddl = emit_sql_ddl(m, dialect="postgres") + fk_line = next(ln for ln in ddl.splitlines() if "FOREIGN KEY" in ln) + assert "REFERENCES account (account_id)" in fk_line, fk_line + + +def test_sql_ddl_scopes_to_a_subject_area_and_drops_cross_area_fk(): + """A scoped DDL export emits only the subject area's tables, keeps within-area FKs, and + DROPS cross-area FKs with NO stub table for the out-of-area neighbour (it already exists in + the target model; the FK is re-established there by hand).""" + from mdl_core.ids import new_ulid + from mdl_core.ir import ( + Attribute, + ConceptualEntity, + KeyGroup, + LogicalEntity, + Model, + ProjectConfig, + Relationship, + RelationshipEnd, + SubjectArea, + ) + + m = Model(ProjectConfig(name="mart")) + # out-of-area neighbour + acc_ce = ConceptualEntity(id=new_ulid(), name="Account") + m.add(acc_ce) + acc_pk = Attribute(id=new_ulid(), name="account_id", role="business_key", nullable=False, + domain="integer") + acc = LogicalEntity(id=new_ulid(), name="account", realises=acc_ce.id, attributes=[acc_pk]) + m.add(acc) + m.add(KeyGroup(id=new_ulid(), entity=acc.id, name="pk_acc", type="pk", members=[acc_pk.id])) + m.add(SubjectArea(id=new_ulid(), name="Core", members=[acc_ce.id])) + # in-area entities: trade (pk) and trade_leg (within-area FK to trade), plus a cross-area + # FK trade -> account + t_ce = ConceptualEntity(id=new_ulid(), name="Trade") + m.add(t_ce) + t_pk = Attribute(id=new_ulid(), name="trade_id", role="business_key", nullable=False, + domain="integer") + t_fk = Attribute(id=new_ulid(), name="account_id", role="attribute", nullable=False, + domain="integer") + trade = LogicalEntity(id=new_ulid(), name="trade", realises=t_ce.id, attributes=[t_pk, t_fk]) + m.add(trade) + m.add(KeyGroup(id=new_ulid(), entity=trade.id, name="pk_trade", type="pk", + members=[t_pk.id])) + leg_ce = ConceptualEntity(id=new_ulid(), name="TradeLeg") + m.add(leg_ce) + leg_pk = Attribute(id=new_ulid(), name="leg_id", role="business_key", nullable=False, + domain="integer") + leg_fk = Attribute(id=new_ulid(), name="trade_id", role="attribute", nullable=False, + domain="integer") + leg = LogicalEntity(id=new_ulid(), name="trade_leg", realises=leg_ce.id, + attributes=[leg_pk, leg_fk]) + m.add(leg) + m.add(KeyGroup(id=new_ulid(), entity=leg.id, name="pk_leg", type="pk", members=[leg_pk.id])) + m.add(SubjectArea(id=new_ulid(), name="Trading", members=[t_ce.id, leg_ce.id])) + # within-area FK: trade_leg -> trade + m.add(Relationship( + id=new_ulid(), name="leg_of_trade", + **{"from": RelationshipEnd(entity=leg.id, attributes=[leg_fk.id])}, + to=RelationshipEnd(entity=trade.id, attributes=[t_pk.id]), cardinality="many_to_one")) + # cross-area FK: trade -> account (Core) + m.add(Relationship( + id=new_ulid(), name="trade_for_account", + **{"from": RelationshipEnd(entity=trade.id, attributes=[t_fk.id])}, + to=RelationshipEnd(entity=acc.id, attributes=[acc_pk.id]), cardinality="many_to_one")) + + ddl = emit_sql_ddl(m, dialect="postgres", subject_area="Trading") + # only the Trading tables are present; the Core neighbour is NOT emitted (no stub) + assert "CREATE TABLE trade (" in ddl + assert "CREATE TABLE trade_leg (" in ddl + assert "CREATE TABLE account" not in ddl + # the within-area FK survives; the cross-area FK CONSTRAINT to account is dropped (the + # account_id COLUMN on trade stays as an ordinary attribute). + assert "REFERENCES trade (" in ddl + assert "REFERENCES account" not in ddl + + def test_mermaid_is_an_erdiagram_with_markers(model): mer = emit_mermaid(model) assert mer.startswith("erDiagram") diff --git a/packages/server/src/mdl_server/app.py b/packages/server/src/mdl_server/app.py index baf6e9f..44b3b45 100644 --- a/packages/server/src/mdl_server/app.py +++ b/packages/server/src/mdl_server/app.py @@ -212,15 +212,19 @@ def delete_layout(view: str | None = None) -> JSONResponse: @app.get("/api/export/{fmt}") def export_model(fmt: str, dialect: str = "postgres", subject_area: str = None): """Export the model to an interchange format. Returns text/plain (or CSV) so - the browser can offer it as a download. `subject_area` (erwin only) scopes the export - to one subject area.""" + the browser can offer it as a download. `subject_area` (erwin and sql) scopes the + export to one subject area.""" from fastapi.responses import PlainTextResponse from mdl_emit_erd import emit_csv, emit_dbml, emit_erwin, emit_mermaid, emit_sql_ddl model = _load().model try: if fmt == "sql": - text, media, ext = emit_sql_ddl(model, dialect=dialect), "text/plain", "sql" + text, media, ext = ( + emit_sql_ddl(model, dialect=dialect, subject_area=subject_area or None), + "text/plain", + "sql", + ) elif fmt == "mermaid": text, media, ext = emit_mermaid(model), "text/plain", "mmd" elif fmt == "dbml": diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-B8BNKKus.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-yDpS9fVd.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-B8BNKKus.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-yDpS9fVd.js index 6885343..f8d4f80 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-B8BNKKus.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-yDpS9fVd.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-DpTWo4Jc.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-Cw-0u507.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-CBJYBl0L.js b/packages/server/src/mdl_server/static/assets/main-W1aXYKPl.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-CBJYBl0L.js rename to packages/server/src/mdl_server/static/assets/main-W1aXYKPl.js index 18b08fe..75837f5 100644 --- a/packages/server/src/mdl_server/static/assets/main-CBJYBl0L.js +++ b/packages/server/src/mdl_server/static/assets/main-W1aXYKPl.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as J,h as ue,f as Z,a as ee,g as se,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-DpTWo4Jc.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function o({size:s=16,children:i}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:i})}const ye=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(o,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(o,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(o,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(o,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(o,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(o,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:i,countByArea:m,activeAreas:h,onSetActive:x,open:v,onClose:y}){const f=s.subject_areas,p=h.size>0,b=r=>x(new Set([r])),g=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},M=m.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(v?" open":""),"aria-hidden":!v,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:y,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${f.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[f.map(r=>{const u=h.has(r.id),k=m.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>b(r.id),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),b(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:w=>w.stopPropagation(),onChange:()=>g(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:i.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),M>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:M})]})]})]})}function _e({doc:s,diagnostics:i,query:m,onQuery:h,onSubmitQuery:x,showTypes:v,onToggleTypes:y,collapseDetail:f,onToggleCollapse:p,onFitView:b,onRelayout:g,onResetLayout:M,onRefresh:r,readOnly:u,dirty:k,panelTab:w,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:E,drawerOpen:D,filterCount:K,scopeSubjectArea:L}){const F=(i==null?void 0:i.items.filter(l=>l.severity==="error").length)??0,R=(i==null?void 0:i.items.filter(l=>l.severity==="warning").length)??0,j=(l,B,O,H,U)=>e.jsxs("button",{className:"grp-btn"+(w===l?" active":""),onClick:()=>q(l),title:H,children:[B,e.jsx("span",{children:O}),U&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:E,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:m,onChange:l=>h(l.target.value),onKeyDown:l=>{l.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),i&&e.jsx("span",{className:"diag-chip"+(F?" err":R?" warn":" ok"),title:i.items.map(l=>`${l.code} ${l.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as J,h as ue,f as Z,a as ee,g as se,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-Cw-0u507.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function o({size:s=16,children:i}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:i})}const ye=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(o,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(o,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(o,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(o,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(o,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(o,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(o,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(o,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:i,countByArea:m,activeAreas:h,onSetActive:x,open:v,onClose:y}){const f=s.subject_areas,p=h.size>0,b=r=>x(new Set([r])),g=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},M=m.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(v?" open":""),"aria-hidden":!v,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:y,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${f.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[f.map(r=>{const u=h.has(r.id),k=m.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>b(r.id),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),b(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:w=>w.stopPropagation(),onChange:()=>g(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:i.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),M>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:M})]})]})]})}function _e({doc:s,diagnostics:i,query:m,onQuery:h,onSubmitQuery:x,showTypes:v,onToggleTypes:y,collapseDetail:f,onToggleCollapse:p,onFitView:b,onRelayout:g,onResetLayout:M,onRefresh:r,readOnly:u,dirty:k,panelTab:w,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:E,drawerOpen:D,filterCount:K,scopeSubjectArea:L}){const F=(i==null?void 0:i.items.filter(l=>l.severity==="error").length)??0,R=(i==null?void 0:i.items.filter(l=>l.severity==="warning").length)??0,j=(l,B,O,H,U)=>e.jsxs("button",{className:"grp-btn"+(w===l?" active":""),onClick:()=>q(l),title:H,children:[B,e.jsx("span",{children:O}),U&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:E,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:m,onChange:l=>h(l.target.value),onKeyDown:l=>{l.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),i&&e.jsx("span",{className:"diag-chip"+(F?" err":R?" warn":" ok"),title:i.items.map(l=>`${l.code} ${l.message}`).join(` `)||"model valid",children:F?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),F]}):R?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),R]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),j("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),j("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),j("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),j("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(v?" active":""),onClick:y,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(f?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:g,onReset:M}),e.jsx("button",{className:"grp-btn icon-only",onClick:b,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$,scopeSubjectArea:L})]})]})]})}const W=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},te={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:i}){const[m,h]=a.useState(!1),[x,v]=a.useState("LR"),[y,f]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!m)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[m]);const b=r=>{f(r),s(r,x)},g=r=>{b(r),h(!1)},M=()=>{const r=W[(W.indexOf(x)+1)%W.length];v(r),s(y,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>b("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(m?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:M,title:`Flow direction: ${te[x]} (click to rotate)`,"aria-label":`Flow direction: ${te[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),m&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>g("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>g("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>g("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>g("grid"),children:"Grid"}),i&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{i(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,i]=a.useState(null),[m,h]=a.useState(null),[x,v]=a.useState(null),[y,f]=a.useState(null),[p,b]=a.useState(""),[g,M]=a.useState(!0),[r,u]=a.useState(!1),[k,w]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[E,D]=a.useState(()=>new Set),[K,L]=a.useState(!1),[F,R]=a.useState(0),j=a.useRef(null),l=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,J[n%J.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,Y;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((Y=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:Y.id)??"";t.set(n.id,P)}),t},[s]),U=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),T=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(T),[T]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),z=V.get("minimal")==="1";a.useEffect(()=>{z&&u(!0)},[z]);const re=a.useCallback(t=>{w(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",G=a.useRef(!1),C=a.useCallback(()=>{Z().then(i).catch(t=>v(String(t))),ee().then(h).catch(()=>h(null)),se().then(t=>L(!!(t.git&&!t.clean))).catch(()=>L(!1)),R(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{Z().then(c=>{i(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(l.current=c.fingerprint),z||(ee().then(h).catch(()=>h(null)),se().then(d=>L(!!(d.git&&!d.clean))).catch(()=>L(!1))),R(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[z]),a.useEffect(()=>{s!=null&&s.fingerprint&&(l.current=s.fingerprint)},[s]);const X=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,l.current||s.fingerprint);return n!=null&&n.fingerprint&&(l.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(f("Model changed on disk — view refreshed, please retry."),C()):f(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!y)return;const t=setTimeout(()=>f(null),5e3);return()=>clearTimeout(t)},[y]),a.useEffect(()=>{if(!s||G.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(G.current=!0,requestAnimationFrame(()=>{var n;return(n=j.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=j.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!T&&((N=j.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),b(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[T]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!z&&e.jsx(_e,{doc:s,diagnostics:m,query:p,onQuery:b,onSubmitQuery:oe,showTypes:g,onToggleTypes:()=>M(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=j.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=j.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=j.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:T,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=j.current)==null?void 0:t.newEntity()},exec:X,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:E.size,scopeSubjectArea:E.size===1?[...E][0]:null}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:X,selectedId:S?null:q,onSelect:A,query:p,showTypes:g,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:E,onError:f,handleRef:j,layoutStore:ae}),!z&&e.jsx(Ae,{doc:s,saColors:O,countByArea:U,activeAreas:E,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:T,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=j.current)==null||c.focusEntity(t)}}),y&&e.jsx("div",{className:"toast",children:y})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-C-aE5Tdu.js b/packages/server/src/mdl_server/static/assets/sme-CoLqAg47.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-C-aE5Tdu.js rename to packages/server/src/mdl_server/static/assets/sme-CoLqAg47.js index 849617a..2293eef 100644 --- a/packages/server/src/mdl_server/static/assets/sme-C-aE5Tdu.js +++ b/packages/server/src/mdl_server/static/assets/sme-CoLqAg47.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-B8BNKKus.js","assets/client-DOmNpTln.js","assets/styles-DpTWo4Jc.js","assets/styles-BqI6o68D.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-DpTWo4Jc.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-B8BNKKus.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-yDpS9fVd.js","assets/client-DOmNpTln.js","assets/styles-Cw-0u507.js","assets/styles-BqI6o68D.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-Cw-0u507.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-yDpS9fVd.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-DpTWo4Jc.js b/packages/server/src/mdl_server/static/assets/styles-Cw-0u507.js similarity index 98% rename from packages/server/src/mdl_server/static/assets/styles-DpTWo4Jc.js rename to packages/server/src/mdl_server/static/assets/styles-Cw-0u507.js index e9ca911..e9138c9 100644 --- a/packages/server/src/mdl_server/static/assets/styles-DpTWo4Jc.js +++ b/packages/server/src/mdl_server/static/assets/styles-Cw-0u507.js @@ -20,4 +20,4 @@ var dc=Object.defineProperty;var fc=(e,t,n)=>t in e?dc(e,t,{enumerable:!0,config `))).catch(()=>i(""))},[]);return x.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:o.split(` `).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` -`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:u,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(l(!0),Lm().then(()=>{l(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:u||!a.trim(),onClick:()=>{l(!0),Om(a).then(()=>{l(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Dx({readOnly:e}){const[t,n]=x.useState([]),r=x.useCallback(()=>{Dm().then(o=>n(o.decisions)).catch(()=>n([]))},[]);if(x.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(o=>h.jsxs("div",{className:"decision "+o.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[o.verdict]}),h.jsx("span",{className:"chip",children:o.confidence}),h.jsx("span",{className:"chip",children:o.signal})]}),h.jsx("p",{className:"decision-subject",children:o.subject}),!e&&o.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Zs(o.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Zs(o.signal_key,"rejected").then(r),children:"Reject"})]})]},o.signal_key))})}function uw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:o,openImport:i=!1,prefillImport:a="",onPreview:c,scopeSubjectArea:u=null}){const[l,d]=x.useState(i&&t?"import":null),[m,f]=x.useState([]),[p,y]=x.useState("postgres"),_=x.useRef(null);x.useEffect(()=>{Pm().then(v=>f(v.formats)).catch(()=>f([]))},[]),x.useEffect(()=>{if(!l)return;const v=C=>{_.current&&!_.current.contains(C.target)&&d(null)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[l]);const w=m.find(v=>v.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:_,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>d(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>d(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(w==null?void 0:w.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:p,onChange:v=>y(v.target.value),children:w.dialects.map(v=>h.jsx("option",{value:v,children:v},v))})]}),m.map(v=>{const C=v.id==="erwin"?u:null;return h.jsxs("a",{className:"ie-item",href:zm(v.id,v.id==="sql"?p:void 0,C),download:!0,onClick:()=>d(null),children:[v.label,C&&h.jsx("span",{className:"ie-scope",children:" · filtered area only"})]},v.id)})]}),l==="import"&&h.jsx(Px,{exec:e,submitLabel:r,buttonClass:s,applyBatch:o,onClose:()=>d(null),onImported:v=>{d(null),n==null||n(v)},onPreview:c,prefillImport:a})]})}const To=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Px({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:o,onPreview:i,prefillImport:a}){var j;const[c,u]=x.useState(i?"erwin":"sql"),[l,d]=x.useState("postgres"),[m,f]=x.useState(a??""),[p,y]=x.useState(!1),[_,w]=x.useState(null),[v,C]=x.useState([]);x.useEffect(()=>{a&&f(a)},[a]);const b=E=>{E&&E.text().then(f).catch(()=>w("could not read that file"))},$=async()=>{y(!0),w(null),C([]);try{if(i&&c==="erwin"){const R=await Fm(c,m);if(!R.changes.length){w(R.warnings[0]??"nothing to import from that document"),y(!1);return}s(),i(R),y(!1);return}const E=await Hm(c,m,c==="sql"?l:void 0);if(!E.changes.length){w(E.warnings[0]??"nothing to import from that document"),y(!1);return}if(r)await r(E.changes);else for(const R of E.changes)await e(R.op,R.payload);C(E.warnings),o(E.tables)}catch(E){w(E instanceof Error?E.message:String(E))}finally{y(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:To.map(E=>h.jsx("button",{className:"ie-tab"+(c===E.id?" active":""),onClick:()=>u(E.id),children:E.label},E.id))}),h.jsx("p",{className:"ie-hint",children:(j=To.find(E=>E.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:l,onChange:E=>d(E.target.value),children:["postgres","snowflake","mysql","duckdb"].map(E=>h.jsx("option",{children:E},E))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:E=>f(E.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:E=>{var R;return b(((R=E.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),v.map((E,R)=>h.jsx("p",{className:"ie-warn",children:E},R)),_&&h.jsx("p",{className:"ie-error",children:_}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:$,children:p?"Importing…":t})]})]})}export{la as A,Cm as B,_m as C,Gm as E,uw as I,Ox as L,cw as M,Ix as O,Ao as P,na as R,lw as S,Vx as a,Jx as b,Kx as c,tw as d,nw as e,Fx as f,Im as g,sw as h,rw as i,Zx as j,Yx as k,Xx as l,Wx as m,qx as n,ua as o,ew as p,Qx as q,Ux as r,Rm as s,Bx as t,Gx as u,yr as v,sa as w,Cx as x,pm as y}; +`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:u,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(l(!0),Lm().then(()=>{l(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:u||!a.trim(),onClick:()=>{l(!0),Om(a).then(()=>{l(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Dx({readOnly:e}){const[t,n]=x.useState([]),r=x.useCallback(()=>{Dm().then(o=>n(o.decisions)).catch(()=>n([]))},[]);if(x.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(o=>h.jsxs("div",{className:"decision "+o.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[o.verdict]}),h.jsx("span",{className:"chip",children:o.confidence}),h.jsx("span",{className:"chip",children:o.signal})]}),h.jsx("p",{className:"decision-subject",children:o.subject}),!e&&o.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Zs(o.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Zs(o.signal_key,"rejected").then(r),children:"Reject"})]})]},o.signal_key))})}function uw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:o,openImport:i=!1,prefillImport:a="",onPreview:c,scopeSubjectArea:u=null}){const[l,d]=x.useState(i&&t?"import":null),[m,f]=x.useState([]),[p,y]=x.useState("postgres"),_=x.useRef(null);x.useEffect(()=>{Pm().then(v=>f(v.formats)).catch(()=>f([]))},[]),x.useEffect(()=>{if(!l)return;const v=C=>{_.current&&!_.current.contains(C.target)&&d(null)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[l]);const w=m.find(v=>v.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:_,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>d(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>d(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(w==null?void 0:w.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:p,onChange:v=>y(v.target.value),children:w.dialects.map(v=>h.jsx("option",{value:v,children:v},v))})]}),m.map(v=>{const C=v.id==="erwin"||v.id==="sql"?u:null;return h.jsxs("a",{className:"ie-item",href:zm(v.id,v.id==="sql"?p:void 0,C),download:!0,onClick:()=>d(null),children:[v.label,C&&h.jsx("span",{className:"ie-scope",children:" · filtered area only"})]},v.id)})]}),l==="import"&&h.jsx(Px,{exec:e,submitLabel:r,buttonClass:s,applyBatch:o,onClose:()=>d(null),onImported:v=>{d(null),n==null||n(v)},onPreview:c,prefillImport:a})]})}const To=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Px({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:o,onPreview:i,prefillImport:a}){var j;const[c,u]=x.useState(i?"erwin":"sql"),[l,d]=x.useState("postgres"),[m,f]=x.useState(a??""),[p,y]=x.useState(!1),[_,w]=x.useState(null),[v,C]=x.useState([]);x.useEffect(()=>{a&&f(a)},[a]);const b=E=>{E&&E.text().then(f).catch(()=>w("could not read that file"))},$=async()=>{y(!0),w(null),C([]);try{if(i&&c==="erwin"){const R=await Fm(c,m);if(!R.changes.length){w(R.warnings[0]??"nothing to import from that document"),y(!1);return}s(),i(R),y(!1);return}const E=await Hm(c,m,c==="sql"?l:void 0);if(!E.changes.length){w(E.warnings[0]??"nothing to import from that document"),y(!1);return}if(r)await r(E.changes);else for(const R of E.changes)await e(R.op,R.payload);C(E.warnings),o(E.tables)}catch(E){w(E instanceof Error?E.message:String(E))}finally{y(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:To.map(E=>h.jsx("button",{className:"ie-tab"+(c===E.id?" active":""),onClick:()=>u(E.id),children:E.label},E.id))}),h.jsx("p",{className:"ie-hint",children:(j=To.find(E=>E.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:l,onChange:E=>d(E.target.value),children:["postgres","snowflake","mysql","duckdb"].map(E=>h.jsx("option",{children:E},E))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:E=>f(E.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:E=>{var R;return b(((R=E.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),v.map((E,R)=>h.jsx("p",{className:"ie-warn",children:E},R)),_&&h.jsx("p",{className:"ie-error",children:_}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:$,children:p?"Importing…":t})]})]})}export{la as A,Cm as B,_m as C,Gm as E,uw as I,Ox as L,cw as M,Ix as O,Ao as P,na as R,lw as S,Vx as a,Jx as b,Kx as c,tw as d,nw as e,Fx as f,Im as g,sw as h,rw as i,Zx as j,Yx as k,Xx as l,Wx as m,qx as n,ua as o,ew as p,Qx as q,Ux as r,Rm as s,Bx as t,Gx as u,yr as v,sa as w,Cx as x,pm as y}; diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 5ff1145..ae59934 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,9 +4,9 @@ Modelith - + - + diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index c9ac8fc..9c565c3 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,9 +4,9 @@ Modelith Glossary - + - +