A platform for community discussion. Free, open, simple.
DEV: replaces elkjs by dagre (#40455)
Joffrey JAFFEUX85fc647f5f42
diff --git a/frontend/discourse/app/static/rete-bundle.js b/frontend/discourse/app/static/rete-bundle.jsindex 9fcf49bec9a..150a26117d2 100644--- a/frontend/discourse/app/static/rete-bundle.js+++ b/frontend/discourse/app/static/rete-bundle.js@@ -5,8 +5,5 @@ export {Presets as ConnectionPresets,} from "rete-connection-plugin";export { HistoryPlugin, HistoryExtensions } from "rete-history-plugin";-export {- AutoArrangePlugin,- Presets as ArrangePresets,-} from "rete-auto-arrange-plugin";+export { default as dagre } from "@dagrejs/dagre";export { classicConnectionPath, getElementCenter } from "rete-render-utils";diff --git a/frontend/discourse/package.json b/frontend/discourse/package.jsonindex 8daf1fd2b3d..d184d09931d 100644--- a/frontend/discourse/package.json+++ b/frontend/discourse/package.json@@ -30,6 +30,7 @@"@codemirror/language": "^6.12.3","@codemirror/state": "^6.6.0","@codemirror/view": "^6.40.0",+ "@dagrejs/dagre": "^3.0.0","@discourse/gif": "^1.0.0","@discourse/heic": "^1.0.0","@discourse/jpeg": "^1.0.0",@@ -59,11 +60,10 @@"chart.js": "4.5.1","chartjs-adapter-moment": "^1.0.1","chartjs-plugin-datalabels": "2.2.0",- "decorator-transforms": "^2.3.2","codemirror": "^6.0.2",+ "decorator-transforms": "^2.3.2","diff": "^9.0.0","ember-curry-component": "^0.4.0",- "elkjs": "^0.8.2","ember-resolver": "^13.2.0","ember-route-template": "^1.0.3","ember-source": "~6.10.0",@@ -95,12 +95,10 @@"prosemirror-view": "^1.41.8","rete": "^2.0.6","rete-area-plugin": "^2.1.5",- "rete-auto-arrange-plugin": "^2.0.2","rete-connection-plugin": "^2.0.5","rete-history-plugin": "^2.1.1","rete-render-utils": "^2.0.3",- "rrule": "^2.8.1",- "web-worker": "^1.5.0"+ "rrule": "^2.8.1"},"devDependencies": {"@babel/core": "^7.28.5",diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/rete-editor.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/rete-editor.jsindex 905ee42d46e..dfee3c4617d 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/rete-editor.js+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/rete-editor.js@@ -33,8 +33,7 @@ export class ReteEditorBridge {ConnectionPlugin,ConnectionPresets,Zoom,- AutoArrangePlugin,- ArrangePresets,+ dagre,classicConnectionPath,getElementCenter,} = await loadRete();@@ -112,13 +111,9 @@ export class ReteEditorBridge {connectionPlugin.addPreset(ConnectionPresets.classic.setup());- const arrange = new AutoArrangePlugin();- arrange.addPreset(ArrangePresets.classic.setup());-editor.use(area);area.use(connectionPlugin);area.use(renderer);- area.use(arrange);area.area.setZoomHandler(new Zoom(0.05));AreaExtensions.simpleNodesOrder(area);@@ -185,7 +180,7 @@ export class ReteEditorBridge {selector,selectableNodes,connectionPlugin,- arrange,+ dagre,container,callbacks,WorkflowNode,@@ -216,7 +211,7 @@ export class ReteEditorBridge {selector,selectableNodes,connectionPlugin,- arrange,+ dagre,container,callbacks,WorkflowNode,@@ -235,7 +230,7 @@ export class ReteEditorBridge {this.selector = selector;this.selectableNodes = selectableNodes;this.connectionPlugin = connectionPlugin;- this.arrange = arrange;+ this.dagre = dagre;this.container = container;this.callbacks = callbacks;this.accumulating = accumulating;@@ -741,13 +736,10 @@ export class ReteEditorBridge {await this.editor.removeConnection(conn.id);}- await this.arrange.layout({- options: {- "elk.algorithm": "layered",- "elk.direction": "RIGHT",- "elk.spacing.nodeNode": "30",- "elk.layered.spacing.nodeNodeBetweenLayers": "20",- },+ await this.runDagreLayout({+ rankdir: "LR",+ nodesep: 30,+ ranksep: 20,});for (const conn of removedConns) {@@ -819,6 +811,42 @@ export class ReteEditorBridge {}}+ async runDagreLayout({ rankdir = "LR", nodesep = 30, ranksep = 20 } = {}) {+ const graph = new this.dagre.graphlib.Graph();+ graph.setGraph({ rankdir, nodesep, ranksep });+ graph.setDefaultEdgeLabel(() => ({}));++ const nodes = this.editor.getNodes();+ for (const node of nodes) {+ graph.setNode(node.id, {+ width: node.width || NODE_WIDTH,+ height: node.height || 90,+ });+ }++ for (const conn of this.editor.getConnections()) {+ if (+ conn.source !== conn.target &&+ graph.hasNode(conn.source) &&+ graph.hasNode(conn.target)+ ) {+ graph.setEdge(conn.source, conn.target);+ }+ }++ this.dagre.layout(graph);++ await Promise.all(+ nodes.map((node) => {+ const { x, y, width, height } = graph.node(node.id);+ return this.area.translate(node.id, {+ x: x - width / 2,+ y: y - height / 2,+ });+ })+ );+ }+get areaContentElement() {return this.area.area.content.holder;}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex e7a94fefa3c..354864b0115 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -47,7 +47,7 @@ importers:devDependencies:'@discourse/lint-configs':specifier: ^3.0.1+ version: 3.0.1([email protected]([email protected]))([email protected])([email protected])([email protected]([email protected]))'@discourse/moment-timezone-names-translations':specifier: ^1.0.0version: 1.0.0@@ -104,7 +104,7 @@ importers:devDependencies:'@discourse/lint-configs':specifier: ^3.0.1+ version: 3.0.1([email protected]([email protected]))([email protected])([email protected])([email protected]([email protected]))prettier:specifier: 3.8.1version: 3.8.1@@ -210,6 +210,9 @@ importers:'@codemirror/view':specifier: ^6.40.0version: 6.43.0+ '@dagrejs/dagre':+ specifier: ^3.0.0+ version: 3.0.0'@discourse/gif':specifier: ^1.0.0version: 1.0.0@@ -306,9 +309,6 @@ importers:diff:specifier: ^9.0.0version: 9.0.0- elkjs:- specifier: ^0.8.2- version: 0.8.2ember-curry-component:specifier: ^0.4.0version: 0.4.0(@babel/[email protected])@@ -405,9 +405,6 @@ importers:rete-area-plugin:specifier: ^2.1.5version: 2.1.5([email protected])- rete-auto-arrange-plugin:- specifier: ^2.0.2- version: 2.0.2([email protected])([email protected]([email protected]))([email protected])([email protected])rete-connection-plugin:specifier: ^2.0.5@@ -420,9 +417,6 @@ importers:rrule:specifier: ^2.8.1version: 2.8.1- web-worker:- specifier: ^1.5.0- version: 1.5.0devDependencies:'@babel/core':specifier: ^7.28.5@@ -1652,6 +1646,12 @@ packages:'@dabh/[email protected]':resolution: {integrity: sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==}+ '@dagrejs/[email protected]':+ resolution: {integrity: sha512-ZzhnTy1rfuoew9Ez3EIw4L2znPGnYYhfn8vc9c4oB8iw6QAsszbiU0vRhlxWPFnmmNSFAkrYeF1PhM5m4lAN0Q==}++ '@dagrejs/[email protected]':+ resolution: {integrity: sha512-IvcV6FduIIAmLwnH+yun+QtV36SC7mERqa86aClNqmMN09WhmPPYU8ckHrZBozErf+UvHPWOTJYaGYiIcs0DgA==}+'@discourse/[email protected]':resolution: {integrity: sha512-hh4EI0yoNWDuPp0CC/8N1NiUcwsCznTXrIefODxHP/c3hE97N9z2RkyKfhINEaTfiWoZx3XyOujDn6L0Pm8nRQ==}@@ -1670,7 +1670,9 @@ packages:'@discourse/[email protected]':resolution: {integrity: sha512-G8gy82GcQRpNoc1IS7Ke91dinJiJMHEHE1vn+WmTzUCmd2ZnTLc58n32Ow1wmBjzXW3v0WCl3GqfMzPU3MrvMg==}peerDependencies:+ eslint: 9.39.2prettier: 3.8.1+ stylelint: 17.5.0'@discourse/[email protected]':resolution: {integrity: sha512-4xr1QWQ0nzmFa2ZXQgWZA+dtE/BU2ePA+qkJWPFzNpq4ZnQi8MmMMAS2285t3rc2ySMBQqYaAArmcSUiufUgRA==}@@ -4269,9 +4271,6 @@ packages:resolution: {integrity: sha512-VjUKPyWzGnT1fujlkEGC/BvN70Hh70KXtAqcmniXviYlJC/ivcT+BWGPyxWVbJZLfvtKR6dqg1L7T7pgAMBtWA==}- resolution: {integrity: sha512-L6uRgvZTH+4OF5NE/MBbzQx/WYpru1xCBE9respNj6qznEewGUIfhzmm7horWWxbNO2M0WckQypGctR8lH79xQ==}-resolution: {integrity: sha512-yCQlVR3NLgjGA09LMc1NYX0XiAd0tHTM4/AmIHD0wq87QpHGmWcpMxyKGEe/TBczyCwBEJifaZNtAjMDsW1YdA==}@@ -7069,14 +7068,6 @@ packages:peerDependencies:rete: ^2.0.0- resolution: {integrity: sha512-VLTnVb9tqHfQKkFMZzpYgYxDWcIa+nXHRC+Po0k+gUh2zJqegkx8bFSA1n6VkMv+wPYa9EnWsTMfUDD3k1QEzg==}- peerDependencies:- elkjs: ^0.8.2- rete: ^2.0.1- rete-area-plugin: ^2.0.0- web-worker: ^1.2.0-resolution: {integrity: sha512-KFtlOyEJRc0y9STVgo2T+t+j9u5fxiTxbyzPbMCm0uqncb3b8d2ABDIzvWoNo5zQAh2Oz/OvlUovupbzrGzpSg==}peerDependencies:@@ -7625,11 +7616,6 @@ packages:peerDependencies:stylelint: ^16.8.2 || ^17.0.0- resolution: {integrity: sha512-KIlzWXMHUvgfPUR0R7TK3H80yCIi0uoivUwf+6Az4yrHJD1Q3c1qIkh/H5Z0i/K3QXgtq/UMEkWyBUSUwnpnOg==}- engines: {node: '>=20.19.0'}- hasBin: true-resolution: {integrity: sha512-3kQ2/cHv3Zt8OBg+h2B8XCx9evEABQIrv4hh3uXahGz/ZEHrTR80zxBiK2NfXNaSoyBzxO1pjsz1Vhdzwn5XSw==}engines: {node: '>=20.19.0'}@@ -8155,9 +8141,6 @@ packages:resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==}- resolution: {integrity: sha512-RiMReJrTAiA+mBjGONMnjVDP2u3p9R1vkcGz6gDIrOMT3oGuYwX2WRMYI9ipkphSuE5XKEhydbhNEJh4NY9mlw==}-resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}@@ -9295,6 +9278,12 @@ snapshots:enabled: 2.0.0kuler: 2.0.0+ '@dagrejs/[email protected]':+ dependencies:+ '@dagrejs/graphlib': 4.0.1++ '@dagrejs/[email protected]': {}+'@discourse/[email protected]': {}'@discourse/[email protected]': {}@@ -9307,7 +9296,7 @@ snapshots:dependencies:wasm-feature-detect: 1.8.0+ '@discourse/[email protected]([email protected]([email protected]))([email protected])([email protected])([email protected]([email protected]))':dependencies:'@babel/core': 7.29.0@@ -9323,16 +9312,15 @@ snapshots:globals: 17.4.0prettier: 3.8.1prettier-plugin-ember-template-tag: 2.1.3([email protected])- stylelint: 17.12.0([email protected])- stylelint-config-standard: 40.0.0([email protected]([email protected]))- stylelint-scss: 7.0.0([email protected]([email protected]))+ stylelint: 17.4.0([email protected])+ stylelint-config-standard: 40.0.0([email protected]([email protected]))+ stylelint-scss: 7.0.0([email protected]([email protected]))typescript: 5.9.3transitivePeerDependencies:- '@typescript-eslint/parser'- eslint-import-resolver-typescript- eslint-import-resolver-webpack- - jiti- postcss- supports-color@@ -12156,8 +12144,6 @@ snapshots:- [email protected]: {}-dependencies:'@ember/test-waiters': 4.1.1(@babel/[email protected])(@glint/[email protected])@@ -15676,14 +15662,6 @@ snapshots:'@babel/runtime': 7.29.7rete: 2.0.6- [email protected]([email protected])([email protected]([email protected]))([email protected])([email protected]):- dependencies:- '@babel/runtime': 7.29.7- elkjs: 0.8.2- rete: 2.0.6- rete-area-plugin: 2.1.5([email protected])- web-worker: 1.5.0-dependencies:'@babel/runtime': 7.29.7@@ -16315,33 +16293,33 @@ snapshots:dependencies:postcss-scss: 4.0.9([email protected])- stylelint: 17.12.0([email protected])- stylelint-config-recommended: 18.0.0([email protected]([email protected]))- stylelint-scss: 7.0.0([email protected]([email protected]))+ stylelint: 17.4.0([email protected])+ stylelint-config-recommended: 18.0.0([email protected]([email protected]))+ stylelint-scss: 7.0.0([email protected]([email protected]))optionalDependencies:postcss: 8.5.15dependencies:- stylelint: 17.12.0([email protected])+ stylelint: 17.4.0([email protected])dependencies:- stylelint: 17.12.0([email protected])- stylelint-config-recommended-scss: 17.0.0([email protected])([email protected]([email protected]))- stylelint-config-standard: 40.0.0([email protected]([email protected]))+ stylelint: 17.4.0([email protected])+ stylelint-config-recommended-scss: 17.0.0([email protected])([email protected]([email protected]))+ stylelint-config-standard: 40.0.0([email protected]([email protected]))optionalDependencies:postcss: 8.5.15dependencies:- stylelint: 17.12.0([email protected])- stylelint-config-recommended: 18.0.0([email protected]([email protected]))+ stylelint: 17.4.0([email protected])+ stylelint-config-recommended: 18.0.0([email protected]([email protected]))dependencies:css-tree: 3.2.1is-plain-object: 5.0.0@@ -16351,48 +16329,7 @@ snapshots:postcss-resolve-nested-selector: 0.1.6postcss-selector-parser: 7.1.1postcss-value-parser: 4.2.0- stylelint: 17.12.0([email protected])-- dependencies:- '@csstools/css-calc': 3.2.1(@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])- '@csstools/css-parser-algorithms': 4.0.0(@csstools/[email protected])- '@csstools/css-syntax-patches-for-csstree': 1.1.4([email protected])- '@csstools/css-tokenizer': 4.0.0- '@csstools/media-query-list-parser': 5.0.0(@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])- '@csstools/selector-resolve-nested': 4.0.0([email protected])- '@csstools/selector-specificity': 6.0.0([email protected])- colord: 2.9.3- cosmiconfig: 9.0.1([email protected])- css-functions-list: 3.3.3- css-tree: 3.2.1- debug: 4.4.3- fast-glob: 3.3.3- fastest-levenshtein: 1.0.16- file-entry-cache: 11.1.3- global-modules: 2.0.0- globby: 16.2.0- globjoin: 0.1.4- html-tags: 5.1.0- ignore: 7.0.5- import-meta-resolve: 4.2.0- mathml-tag-names: 4.0.0- meow: 14.1.0- micromatch: 4.0.8- normalize-path: 3.0.0- picocolors: 1.1.1- postcss: 8.5.15- postcss-safe-parser: 7.0.1([email protected])- postcss-selector-parser: 7.1.1- postcss-value-parser: 4.2.0- string-width: 8.2.1- supports-hyperlinks: 4.4.0- svg-tags: 1.0.0- table: 6.9.0- write-file-atomic: 7.0.1- transitivePeerDependencies:- - supports-color- - typescript+ stylelint: 17.4.0([email protected])dependencies:@@ -17048,8 +16985,6 @@ snapshots:dependencies:defaults: 1.0.4- [email protected]: {}-