mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-29 00:07:30 +00:00
feat: compare @pierre/diffs with Monaco on the diff test page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6a1a0a3599
commit
2684c08c8d
Generated
+346
-60
@@ -24,6 +24,7 @@
|
||||
"@json2csv/plainjs": "^7.0.6",
|
||||
"@leeoniya/ufuzzy": "^1.0.8",
|
||||
"@melt-ui/svelte": "^0.86.2",
|
||||
"@pierre/diffs": "1.6.4",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@redocly/json-to-json-schema": "^0.0.1",
|
||||
"@scalar/openapi-parser": "^0.15.0",
|
||||
@@ -1687,6 +1688,87 @@
|
||||
"integrity": "sha512-8awtpHXCx/bNpFt4mt2xdkgtgVvKqty8VbjHI/WWWQuEw+KLzFot3f4+LkQY9YmOtq7A5GdOnqoIC8Pdygjk2g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@pierre/diffs": {
|
||||
"version": "1.6.4",
|
||||
"resolved": "https://registry.npmjs.org/@pierre/diffs/-/diffs-1.6.4.tgz",
|
||||
"integrity": "sha512-RsKoruCOp50qaDM3a7BQan5K77xMkGWT1NF01fiYP1PfT3v4CvIjwytNk5WjZG0BesBkMOP2UbrBIDigB1k0ug==",
|
||||
"license": "apache-2.0",
|
||||
"dependencies": {
|
||||
"@pierre/highlights": "0.4.0",
|
||||
"@pierre/theme": "2.0.0",
|
||||
"@pierre/theming": "1.0.2",
|
||||
"diff": "9.0.0",
|
||||
"hast-util-to-html": "9.0.5",
|
||||
"lru_map": "0.4.1",
|
||||
"shiki": "^3.0.0 || ^4.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^18.3.1 || ^19.0.0",
|
||||
"react-dom": "^18.3.1 || ^19.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react": {
|
||||
"optional": true
|
||||
},
|
||||
"react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@pierre/diffs/node_modules/diff": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-9.0.0.tgz",
|
||||
"integrity": "sha512-svtcdpS8CgJyqAjEQIXdb3OjhFVVYjzGAPO8WGCmRbrml64SPw/jJD4GoE98aR7r25A0XcgrK3F02yw9R/vhQw==",
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": ">=0.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@pierre/highlights": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@pierre/highlights/-/highlights-0.4.0.tgz",
|
||||
"integrity": "sha512-2a38H7ep3KweGi1fGQpJk+Krod2OMpDIXagKPlqBd1Y9P460T7zQmc66Wm2JAH1SpIG93wCyyhZVrkc5dnAJVQ==",
|
||||
"license": "apache-2.0"
|
||||
},
|
||||
"node_modules/@pierre/theme": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@pierre/theme/-/theme-2.0.0.tgz",
|
||||
"integrity": "sha512-yNDd9GYLQl1mEUJR8AneJ5e4ohLIHQd/wZLWr4fagt78vS2RwwZNW530vVgHqXFAyFVcFlRmGUD5ramXH46OXw==",
|
||||
"license": "apache-2.0",
|
||||
"engines": {
|
||||
"vscode": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@pierre/theming": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@pierre/theming/-/theming-1.0.2.tgz",
|
||||
"integrity": "sha512-RmXLLqtx31UGcR8kZyO5hGAQ1EXz6loT1Cu0BFAGsbnBboIxp2BlomkLfWyvdT4WZXnBGyu25onL1gKpFQuSUw==",
|
||||
"license": "apache-2.0",
|
||||
"peerDependencies": {
|
||||
"@pierre/theme": "^1.1.0 || ^2.0.0",
|
||||
"@shikijs/themes": "^3.0.0 || ^4.0.0",
|
||||
"react": "^18.3.1 || ^19.0.0",
|
||||
"react-dom": "^18.3.1 || ^19.0.0",
|
||||
"shiki": "^3.0.0 || ^4.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@pierre/theme": {
|
||||
"optional": true
|
||||
},
|
||||
"@shikijs/themes": {
|
||||
"optional": true
|
||||
},
|
||||
"react": {
|
||||
"optional": true
|
||||
},
|
||||
"react-dom": {
|
||||
"optional": true
|
||||
},
|
||||
"shiki": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@pkgjs/parseargs": {
|
||||
"version": "0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
|
||||
@@ -1744,7 +1826,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1761,7 +1842,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1778,7 +1858,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1795,7 +1874,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1812,7 +1890,6 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1829,7 +1906,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1846,7 +1922,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1863,7 +1938,6 @@
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1880,7 +1954,6 @@
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1897,7 +1970,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1914,7 +1986,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1931,7 +2002,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1948,7 +2018,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1965,7 +2034,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -1999,6 +2067,129 @@
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/core": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-4.6.0.tgz",
|
||||
"integrity": "sha512-bfd4OKgvoyXYiYmMRuleA656P4V7M/Du9lcTl38Ngm6KszMj7bq4J1IGZwSYR4c95Tv5UQALtYNWUwaI9UT3xw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/primitive": "4.6.0",
|
||||
"@shikijs/types": "4.6.0",
|
||||
"@shikijs/vscode-textmate": "^10.1.0",
|
||||
"@types/hast": "^3.0.5",
|
||||
"hast-util-to-html": "^9.0.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/core/node_modules/hast-util-to-html": {
|
||||
"version": "9.0.6",
|
||||
"resolved": "https://registry.npmjs.org/hast-util-to-html/-/hast-util-to-html-9.0.6.tgz",
|
||||
"integrity": "sha512-1SZUxCN3TtJAE7e2BQN2MBHsoZ1gnmi9GoCP5Di59CSWptIezSAW09yDZyVbanb78V9eCwrKqdQsjtfVTxYHWA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/hast": "^3.0.0",
|
||||
"@types/unist": "^3.0.0",
|
||||
"ccount": "^2.0.0",
|
||||
"comma-separated-tokens": "^2.0.0",
|
||||
"hast-util-whitespace": "^3.0.0",
|
||||
"html-void-elements": "^3.0.0",
|
||||
"mdast-util-to-hast": "^13.0.0",
|
||||
"property-information": "^7.0.0",
|
||||
"space-separated-tokens": "^2.0.0",
|
||||
"stringify-entities": "^4.0.0",
|
||||
"zwitch": "^2.0.4"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/engine-javascript": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-4.6.0.tgz",
|
||||
"integrity": "sha512-K0oqxFoL+kEMdz89mHLFO15Tsbv3kFZ6WR1cXZKMvLSc+oqaM00A6pyga1qSeXB22dP0tTiSApRcGBaKWsEccg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "4.6.0",
|
||||
"@shikijs/vscode-textmate": "^10.1.0",
|
||||
"oniguruma-to-es": "^4.3.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/engine-oniguruma": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-4.6.0.tgz",
|
||||
"integrity": "sha512-aggd6Q7SuJOXNnsUbfG2XesxBJKBMAw/PDTUo9PyRjMaaJJ2dNrI+q0C+25ARXAK9yLHAlwxc9oRT2u68YKZ7w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "4.6.0",
|
||||
"@shikijs/vscode-textmate": "^10.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/langs": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-4.6.0.tgz",
|
||||
"integrity": "sha512-1yMEX3oCVV54LUq/ovfpRkDQoYDkcvjSWFFa/YLUDMiSoRzMi2uxLJYbv41ahT8Lu9lFMaa7hecd3Q39trqUyg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "4.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/primitive": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/primitive/-/primitive-4.6.0.tgz",
|
||||
"integrity": "sha512-c54+TQEo9ToqgfL/AU8FpjnV09+GA9Oa7M5ROkkXteZfp5XzpAJGXjjvZQFQioJOwm/w/6Z3lIzQstAkl8coag==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "4.6.0",
|
||||
"@shikijs/vscode-textmate": "^10.1.0",
|
||||
"@types/hast": "^3.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/themes": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-4.6.0.tgz",
|
||||
"integrity": "sha512-qHAVAs80RiGD+IRuH9G+JPDOEc9A/kHsng4EzCUCwB9bLzW6Z0y9WETh2YyCcADJBmfrIaJ1Jp7KBNP6FHkgtQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "4.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/types": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/types/-/types-4.6.0.tgz",
|
||||
"integrity": "sha512-+ENG1adsKt/X7cRYw1Nl7BEpBmPOjmQ7bR/eGmHuMlT8gtOFf3KEi5l31DJYyAWhW6Y6bjP1plU7FmaxWGENFw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/vscode-textmate": "^10.1.0",
|
||||
"@types/hast": "^3.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/vscode-textmate": {
|
||||
"version": "10.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.1.0.tgz",
|
||||
"integrity": "sha512-cVBuhDQjBZaNMTwBquYfPydrUP+E3hE6oYGasx8h6ZrODIM7/r+gxLDXdd66oszbrggZHEntdE6j+5gYIVyMWQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@smithy/types": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@smithy/types/-/types-4.7.0.tgz",
|
||||
@@ -2549,9 +2740,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/hast": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz",
|
||||
"integrity": "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==",
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.5.tgz",
|
||||
"integrity": "sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/unist": "*"
|
||||
@@ -3977,6 +4168,26 @@
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/character-entities-html4": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/character-entities-html4/-/character-entities-html4-2.1.0.tgz",
|
||||
"integrity": "sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/character-entities-legacy": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-3.0.0.tgz",
|
||||
"integrity": "sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/chart.js": {
|
||||
"version": "4.5.1",
|
||||
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.5.1.tgz",
|
||||
@@ -6953,6 +7164,29 @@
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/hast-util-to-html": {
|
||||
"version": "9.0.5",
|
||||
"resolved": "https://registry.npmjs.org/hast-util-to-html/-/hast-util-to-html-9.0.5.tgz",
|
||||
"integrity": "sha512-OguPdidb+fbHQSU4Q4ZiLKnzWo8Wwsf5bZfbvu7//a9oTYoqD/fWpe96NuHkoS9h0ccGOTe0C4NGXdtS0iObOw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/hast": "^3.0.0",
|
||||
"@types/unist": "^3.0.0",
|
||||
"ccount": "^2.0.0",
|
||||
"comma-separated-tokens": "^2.0.0",
|
||||
"hast-util-whitespace": "^3.0.0",
|
||||
"html-void-elements": "^3.0.0",
|
||||
"mdast-util-to-hast": "^13.0.0",
|
||||
"property-information": "^7.0.0",
|
||||
"space-separated-tokens": "^2.0.0",
|
||||
"stringify-entities": "^4.0.0",
|
||||
"zwitch": "^2.0.4"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/hast-util-to-parse5": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/hast-util-to-parse5/-/hast-util-to-parse5-8.0.0.tgz",
|
||||
@@ -6982,6 +7216,19 @@
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/hast-util-whitespace": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz",
|
||||
"integrity": "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/hast": "^3.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/hastscript": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/hastscript/-/hastscript-9.0.1.tgz",
|
||||
@@ -7420,7 +7667,7 @@
|
||||
"version": "1.21.7",
|
||||
"resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.7.tgz",
|
||||
"integrity": "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"jiti": "bin/jiti.js"
|
||||
@@ -8126,7 +8373,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8147,7 +8393,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8168,7 +8413,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8189,7 +8433,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8210,7 +8453,6 @@
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8231,7 +8473,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8252,7 +8493,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8273,7 +8513,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8294,7 +8533,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8315,7 +8553,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8336,7 +8573,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MPL-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8469,6 +8705,12 @@
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/lru_map": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.4.1.tgz",
|
||||
"integrity": "sha512-I+lBvqMMFfqaV8CJCISjI3wbjmwVu/VyOoU7+qtu9d7ioW5klMgsTTiUOUp+DJvfTTzKXoPbyC6YfgkNcyPSOg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "11.5.2",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.2.tgz",
|
||||
@@ -10061,6 +10303,23 @@
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"node_modules/oniguruma-parser": {
|
||||
"version": "0.12.2",
|
||||
"resolved": "https://registry.npmjs.org/oniguruma-parser/-/oniguruma-parser-0.12.2.tgz",
|
||||
"integrity": "sha512-6HVa5oIrgMC6aA6WF6XyyqbhRPJrKR02L20+2+zpDtO5QAzGHAUGw5TKQvwi5vctNnRHkJYmjAhRVQF2EKdTQw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/oniguruma-to-es": {
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmjs.org/oniguruma-to-es/-/oniguruma-to-es-4.3.6.tgz",
|
||||
"integrity": "sha512-csuQ9x3Yr0cEIs/Zgx/OEt9iBw9vqIunAPQkx19R/fiMq2oGVTgcMqO/V3Ybqefr1TBvosI6jU539ksaBULJyA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"oniguruma-parser": "^0.12.2",
|
||||
"regex": "^6.1.0",
|
||||
"regex-recursion": "^6.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/openai": {
|
||||
"version": "6.9.1",
|
||||
"resolved": "https://registry.npmjs.org/openai/-/openai-6.9.1.tgz",
|
||||
@@ -11724,6 +11983,30 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/regex": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/regex/-/regex-6.1.0.tgz",
|
||||
"integrity": "sha512-6VwtthbV4o/7+OaAF9I5L5V3llLEsoPyq9P1JVXkedTP33c7MfCG0/5NOPcSJn0TzXcG9YUrR0gQSWioew3LDg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"regex-utilities": "^2.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/regex-recursion": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/regex-recursion/-/regex-recursion-6.0.2.tgz",
|
||||
"integrity": "sha512-0YCaSCq2VRIebiaUviZNs0cBz1kg5kVS2UKUfNIx8YVs1cN3AV7NTctO5FOKBA+UT2BPJIWZauYHPqJODG50cg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"regex-utilities": "^2.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/regex-utilities": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/regex-utilities/-/regex-utilities-2.3.0.tgz",
|
||||
"integrity": "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/rehype-github-alerts": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/rehype-github-alerts/-/rehype-github-alerts-3.0.0.tgz",
|
||||
@@ -12149,6 +12432,25 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/shiki": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/shiki/-/shiki-4.6.0.tgz",
|
||||
"integrity": "sha512-imjLsVHgPuWhvpU3P+zOekvMYqnel7QmKsFC4Sn0fCuAvaaalBsxwKEsrU8Ko5BdFnZA6Go/8a0RzahS634UgA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/core": "4.6.0",
|
||||
"@shikijs/engine-javascript": "4.6.0",
|
||||
"@shikijs/engine-oniguruma": "4.6.0",
|
||||
"@shikijs/langs": "4.6.0",
|
||||
"@shikijs/themes": "4.6.0",
|
||||
"@shikijs/types": "4.6.0",
|
||||
"@shikijs/vscode-textmate": "^10.1.0",
|
||||
"@types/hast": "^3.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/side-channel": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz",
|
||||
@@ -12500,6 +12802,20 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/stringify-entities": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz",
|
||||
"integrity": "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"character-entities-html4": "^2.0.0",
|
||||
"character-entities-legacy": "^3.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-ansi": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||
@@ -13007,21 +13323,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/svelte-check/node_modules/picomatch": {
|
||||
"version": "4.0.7",
|
||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
|
||||
"integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/svelte-eslint-parser": {
|
||||
"version": "0.43.0",
|
||||
"resolved": "https://registry.npmjs.org/svelte-eslint-parser/-/svelte-eslint-parser-0.43.0.tgz",
|
||||
@@ -13227,21 +13528,6 @@
|
||||
"svelte": "^4.2.19 || ^5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/svelte/node_modules/@typescript-eslint/types": {
|
||||
"version": "8.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.70.0.tgz",
|
||||
"integrity": "sha512-asTOIYhDg4zdzOScCyaytrsV3cR6B4ecPQlXw/dJIm7J/MZTtCtfVII9JD8Geh4jTCrK/Xe6cg5UevoleMcoJQ==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/svelte/node_modules/esrap": {
|
||||
"version": "2.3.7",
|
||||
"resolved": "https://registry.npmjs.org/esrap/-/esrap-2.3.7.tgz",
|
||||
@@ -13827,7 +14113,7 @@
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
"@json2csv/plainjs": "^7.0.6",
|
||||
"@leeoniya/ufuzzy": "^1.0.8",
|
||||
"@melt-ui/svelte": "^0.86.2",
|
||||
"@pierre/diffs": "1.6.4",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@redocly/json-to-json-schema": "^0.0.1",
|
||||
"@scalar/openapi-parser": "^0.15.0",
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte'
|
||||
import { CodeView, type CodeViewItem, type CodeViewOptions } from '@pierre/diffs'
|
||||
import type { WorkerPoolManager } from '@pierre/diffs/worker'
|
||||
import { useIsDarkMode } from '$lib/components/DarkModeObserver.svelte'
|
||||
import { PIERRE_THEME } from './pierre'
|
||||
|
||||
interface Props {
|
||||
items: CodeViewItem<undefined>[]
|
||||
options?: CodeViewOptions<undefined, undefined>
|
||||
workerPool?: WorkerPoolManager
|
||||
/** Fixed-height scroll container; CodeView virtualizes inside it. */
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { items, options, workerPool, class: className = '' }: Props = $props()
|
||||
|
||||
const isDark = useIsDarkMode()
|
||||
let root: HTMLDivElement | undefined = $state()
|
||||
let viewer: CodeView | undefined = $state()
|
||||
|
||||
function buildOptions(): CodeViewOptions<undefined, undefined> {
|
||||
return {
|
||||
theme: PIERRE_THEME,
|
||||
stickyHeaders: true,
|
||||
layout: { paddingTop: 8, paddingBottom: 8, gap: 8 },
|
||||
...options,
|
||||
themeType: isDark.val ? 'dark' : 'light'
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!root) return
|
||||
const r = root
|
||||
const v = untrack(() => new CodeView(buildOptions(), workerPool))
|
||||
v.setup(r)
|
||||
viewer = v
|
||||
return () => {
|
||||
v.cleanUp()
|
||||
viewer = undefined
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const opts = buildOptions()
|
||||
untrack(() => viewer?.setOptions(opts))
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
viewer?.setItems(items)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div bind:this={root} class={className}></div>
|
||||
@@ -0,0 +1,154 @@
|
||||
<script lang="ts" generics="A = undefined">
|
||||
import { onDestroy, untrack, type Snippet } from 'svelte'
|
||||
import {
|
||||
FileDiff,
|
||||
type DiffLineAnnotation,
|
||||
type FileContents,
|
||||
type FileDiffMetadata,
|
||||
type FileDiffOptions
|
||||
} from '@pierre/diffs'
|
||||
import type { WorkerPoolManager } from '@pierre/diffs/worker'
|
||||
import type { Editor, EditorOptions, Marker } from '@pierre/diffs/edit'
|
||||
import { useIsDarkMode } from '$lib/components/DarkModeObserver.svelte'
|
||||
import { PIERRE_THEME, pierreLang } from './pierre'
|
||||
import { snippetElements } from './snippetElements'
|
||||
|
||||
interface Props {
|
||||
/** Rendered from these two texts unless `fileDiff` is given. */
|
||||
before?: string
|
||||
after?: string
|
||||
fileDiff?: FileDiffMetadata
|
||||
filename?: string
|
||||
/** Monaco language id. */
|
||||
lang?: string
|
||||
/** Monaco language id of the old side, when it differs. */
|
||||
beforeLang?: string
|
||||
options?: Omit<FileDiffOptions<A, undefined>, 'renderAnnotation'>
|
||||
workerPool?: WorkerPoolManager
|
||||
annotations?: DiffLineAnnotation<A>[]
|
||||
annotation?: Snippet<[DiffLineAnnotation<A>]>
|
||||
headerMetadata?: Snippet<[FileDiffMetadata]>
|
||||
/** Attaches an editor to the new side; turning it off ends the session and calls `onEdited`. */
|
||||
editable?: boolean
|
||||
editorOptions?: EditorOptions<'file-diff', A, undefined>
|
||||
markers?: Marker[]
|
||||
onEdited?: (after: string, fileDiff: FileDiffMetadata) => void
|
||||
onEditChange?: (after: string) => void
|
||||
onEditor?: (editor: Editor<'file-diff', A, undefined> | undefined) => void
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
before = '',
|
||||
after = '',
|
||||
fileDiff,
|
||||
filename = 'file',
|
||||
lang,
|
||||
beforeLang,
|
||||
options,
|
||||
workerPool,
|
||||
annotations,
|
||||
annotation,
|
||||
headerMetadata,
|
||||
editable = false,
|
||||
editorOptions,
|
||||
markers,
|
||||
onEdited,
|
||||
onEditChange,
|
||||
onEditor,
|
||||
class: className = ''
|
||||
}: Props = $props()
|
||||
|
||||
const isDark = useIsDarkMode()
|
||||
const elements = snippetElements()
|
||||
let container: HTMLDivElement | undefined = $state()
|
||||
let instance: FileDiff<A> | undefined = $state()
|
||||
let editor: Editor<'file-diff', A, undefined> | undefined = $state()
|
||||
|
||||
// FileDiff compares inputs by reference, so a new object only when the text changes.
|
||||
const oldFile: FileContents = $derived({
|
||||
name: filename,
|
||||
contents: before,
|
||||
lang: pierreLang(beforeLang ?? lang)
|
||||
})
|
||||
const newFile: FileContents = $derived({
|
||||
name: filename,
|
||||
contents: after,
|
||||
lang: pierreLang(lang)
|
||||
})
|
||||
|
||||
function buildOptions(): FileDiffOptions<A, undefined> {
|
||||
return {
|
||||
theme: PIERRE_THEME,
|
||||
...options,
|
||||
themeType: isDark.val ? 'dark' : 'light',
|
||||
renderAnnotation: annotation ? (a) => elements.render(annotation, a) : undefined,
|
||||
renderHeaderMetadata: headerMetadata
|
||||
? (d) => elements.render(headerMetadata, d, 'span')
|
||||
: undefined,
|
||||
onEditChange: (event) => onEditChange?.(event.file.contents),
|
||||
onEditComplete: (event) => {
|
||||
const text = event.newFile?.contents ?? ''
|
||||
onEdited?.(text, event.fileDiff)
|
||||
return 'accept'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!container) return
|
||||
const fd = untrack(() => new FileDiff<A>(buildOptions(), workerPool))
|
||||
instance = fd
|
||||
return () => {
|
||||
fd.cleanUp()
|
||||
instance = undefined
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const opts = buildOptions()
|
||||
untrack(() => {
|
||||
if (!instance) return
|
||||
instance.setOptions(opts)
|
||||
instance.rerender()
|
||||
})
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (!instance || !container) return
|
||||
const input = fileDiff ? { fileDiff } : { oldFile, newFile }
|
||||
instance.render({ ...input, lineAnnotations: annotations, containerWrapper: container })
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (!instance || !editable) return
|
||||
const fd = instance
|
||||
let dispose: (() => void) | undefined
|
||||
let cancelled = false
|
||||
// The edit entry point is its own chunk; only editable views pay for it.
|
||||
import('@pierre/diffs/edit').then(({ Editor }) => {
|
||||
if (cancelled) return
|
||||
const e = new Editor<'file-diff', A, undefined>(
|
||||
'file-diff',
|
||||
untrack(() => editorOptions)
|
||||
)
|
||||
dispose = e.edit(fd)
|
||||
editor = e
|
||||
onEditor?.(e)
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
dispose?.()
|
||||
editor = undefined
|
||||
onEditor?.(undefined)
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
editor?.setMarkers(markers ?? [])
|
||||
})
|
||||
|
||||
onDestroy(() => elements.destroy())
|
||||
</script>
|
||||
|
||||
<div bind:this={container} class={className}></div>
|
||||
@@ -0,0 +1,124 @@
|
||||
<script lang="ts">
|
||||
import { onDestroy, untrack, type Snippet } from 'svelte'
|
||||
import { File, type FileContents, type FileOptions } from '@pierre/diffs'
|
||||
import type { WorkerPoolManager } from '@pierre/diffs/worker'
|
||||
import type { Editor, EditorOptions, Marker } from '@pierre/diffs/edit'
|
||||
import { useIsDarkMode } from '$lib/components/DarkModeObserver.svelte'
|
||||
import { PIERRE_THEME, pierreLang } from './pierre'
|
||||
import { snippetElements } from './snippetElements'
|
||||
|
||||
type FileEditorOptions = EditorOptions<'file', undefined, undefined>
|
||||
// The package does not export this type from `@pierre/diffs/edit`.
|
||||
type SelectionActionContext = Parameters<
|
||||
NonNullable<FileEditorOptions['renderSelectionAction']>
|
||||
>[0]
|
||||
|
||||
interface Props {
|
||||
/** Initial text. Changing it replaces the document, so never feed `onChange` back into it. */
|
||||
code: string
|
||||
filename?: string
|
||||
/** Monaco language id. */
|
||||
lang?: string
|
||||
options?: FileOptions<undefined, undefined>
|
||||
workerPool?: WorkerPoolManager
|
||||
editorOptions?: Omit<FileEditorOptions, 'renderSelectionAction'>
|
||||
selectionAction?: Snippet<[SelectionActionContext]>
|
||||
markers?: Marker[]
|
||||
onChange?: (code: string) => void
|
||||
onEditor?: (editor: Editor<'file', undefined, undefined> | undefined) => void
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
code,
|
||||
filename = 'file',
|
||||
lang,
|
||||
options,
|
||||
workerPool,
|
||||
editorOptions,
|
||||
selectionAction,
|
||||
markers,
|
||||
onChange,
|
||||
onEditor,
|
||||
class: className = ''
|
||||
}: Props = $props()
|
||||
|
||||
const isDark = useIsDarkMode()
|
||||
const elements = snippetElements()
|
||||
let container: HTMLDivElement | undefined = $state()
|
||||
let instance: File | undefined = $state()
|
||||
let editor: Editor<'file', undefined, undefined> | undefined = $state()
|
||||
|
||||
const file: FileContents = $derived({ name: filename, contents: code, lang: pierreLang(lang) })
|
||||
|
||||
function buildOptions(): FileOptions<undefined, undefined> {
|
||||
return {
|
||||
theme: PIERRE_THEME,
|
||||
...options,
|
||||
themeType: isDark.val ? 'dark' : 'light',
|
||||
onEditChange: (event) => onChange?.(event.file.contents),
|
||||
onEditComplete: () => 'accept'
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!container) return
|
||||
const f = untrack(() => new File(buildOptions(), workerPool))
|
||||
instance = f
|
||||
return () => {
|
||||
f.cleanUp()
|
||||
instance = undefined
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const opts = buildOptions()
|
||||
untrack(() => {
|
||||
if (!instance) return
|
||||
instance.setOptions(opts)
|
||||
instance.rerender()
|
||||
})
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (!instance || !container) return
|
||||
instance.render({ file, containerWrapper: container })
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (!instance) return
|
||||
const f = instance
|
||||
let dispose: (() => void) | undefined
|
||||
let cancelled = false
|
||||
import('@pierre/diffs/edit').then(({ Editor }) => {
|
||||
if (cancelled) return
|
||||
const e = new Editor<'file', undefined, undefined>(
|
||||
'file',
|
||||
untrack(() => ({
|
||||
...editorOptions,
|
||||
enabledSelectionAction: selectionAction !== undefined,
|
||||
renderSelectionAction: selectionAction
|
||||
? (ctx) => elements.render(selectionAction, ctx)
|
||||
: undefined
|
||||
}))
|
||||
)
|
||||
dispose = e.edit(f)
|
||||
editor = e
|
||||
onEditor?.(e)
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
dispose?.()
|
||||
editor = undefined
|
||||
onEditor?.(undefined)
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
editor?.setMarkers(markers ?? [])
|
||||
})
|
||||
|
||||
onDestroy(() => elements.destroy())
|
||||
</script>
|
||||
|
||||
<div bind:this={container} class={className}></div>
|
||||
@@ -0,0 +1,53 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte'
|
||||
import { UnresolvedFile, type FileContents } from '@pierre/diffs'
|
||||
import { useIsDarkMode } from '$lib/components/DarkModeObserver.svelte'
|
||||
import { PIERRE_THEME, pierreLang } from './pierre'
|
||||
|
||||
interface Props {
|
||||
/** Text with git conflict markers. */
|
||||
contents: string
|
||||
filename?: string
|
||||
lang?: string
|
||||
onResolved?: (contents: string) => void
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { contents, filename = 'file', lang, onResolved, class: className = '' }: Props = $props()
|
||||
|
||||
const isDark = useIsDarkMode()
|
||||
let container: HTMLDivElement | undefined = $state()
|
||||
let instance: UnresolvedFile | undefined = $state()
|
||||
|
||||
const file: FileContents = $derived({ name: filename, contents, lang: pierreLang(lang) })
|
||||
|
||||
$effect(() => {
|
||||
if (!container) return
|
||||
const u = untrack(
|
||||
() =>
|
||||
new UnresolvedFile({
|
||||
theme: PIERRE_THEME,
|
||||
themeType: isDark.val ? 'dark' : 'light',
|
||||
// Uncontrolled: the component applies each resolution itself.
|
||||
onMergeConflictResolve: (resolved) => onResolved?.(resolved.contents)
|
||||
})
|
||||
)
|
||||
instance = u
|
||||
return () => {
|
||||
u.cleanUp()
|
||||
instance = undefined
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const themeType = isDark.val ? 'dark' : 'light'
|
||||
untrack(() => instance?.setThemeType(themeType))
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (!instance || !container) return
|
||||
instance.render({ file, containerWrapper: container })
|
||||
})
|
||||
</script>
|
||||
|
||||
<div bind:this={container} class={className}></div>
|
||||
@@ -0,0 +1,7 @@
|
||||
<script lang="ts" generics="T">
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
let { snippet, arg }: { snippet: Snippet<[T]>; arg: T } = $props()
|
||||
</script>
|
||||
|
||||
{@render snippet(arg)}
|
||||
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
disposeHighlighter,
|
||||
type HighlighterTypes,
|
||||
type SupportedLanguages,
|
||||
type ThemesType
|
||||
} from '@pierre/diffs'
|
||||
import { WorkerPoolManager } from '@pierre/diffs/worker'
|
||||
import PierreWorkerUrl from '@pierre/diffs/worker/worker.js?worker&url'
|
||||
|
||||
export const PIERRE_THEME: ThemesType = { dark: 'pierre-dark', light: 'pierre-light' }
|
||||
|
||||
// Keyed by the editor language `scriptLangToEditorLang` returns. Every other id is passed
|
||||
// through, since Monaco and Shiki share most names.
|
||||
// for related places search: ADD_NEW_LANG
|
||||
const SHIKI_LANG_BY_MONACO: Record<string, string> = {
|
||||
shell: 'shellscript',
|
||||
nu: 'nushell',
|
||||
plaintext: 'text'
|
||||
}
|
||||
|
||||
export function pierreLang(monacoLang: string | undefined): SupportedLanguages | undefined {
|
||||
if (!monacoLang) return undefined
|
||||
return (SHIKI_LANG_BY_MONACO[monacoLang] ?? monacoLang) as SupportedLanguages
|
||||
}
|
||||
|
||||
let mainThreadHighlighter: HighlighterTypes | undefined
|
||||
|
||||
/**
|
||||
* Components without a pool share one main-thread highlighter, created with the first backend
|
||||
* any of them asked for; later `preferredHighlighter` values are ignored until it is disposed.
|
||||
* Call before mounting a component that needs another backend, after unmounting the old ones.
|
||||
*/
|
||||
export async function switchMainThreadHighlighter(type: HighlighterTypes): Promise<void> {
|
||||
if (mainThreadHighlighter !== undefined && mainThreadHighlighter !== type) {
|
||||
await disposeHighlighter()
|
||||
}
|
||||
mainThreadHighlighter = type
|
||||
}
|
||||
|
||||
const pools = new Map<HighlighterTypes, WorkerPoolManager>()
|
||||
|
||||
/** One pool per highlighter backend: a pool's backend is fixed when its workers start. */
|
||||
export function pierreWorkerPool(preferredHighlighter: HighlighterTypes): WorkerPoolManager {
|
||||
let pool = pools.get(preferredHighlighter)
|
||||
if (!pool) {
|
||||
pool = new WorkerPoolManager(
|
||||
{
|
||||
workerFactory: () => new Worker(PierreWorkerUrl, { type: 'module' }),
|
||||
poolSize: Math.min(4, navigator.hardwareConcurrency || 2)
|
||||
},
|
||||
{ theme: PIERRE_THEME, preferredHighlighter }
|
||||
)
|
||||
pools.set(preferredHighlighter, pool)
|
||||
}
|
||||
return pool
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { mount, unmount, type Snippet } from 'svelte'
|
||||
import SnippetHost from './SnippetHost.svelte'
|
||||
|
||||
/**
|
||||
* Pierre's render callbacks return detached DOM nodes. This mounts a Svelte snippet into one
|
||||
* and keeps every mount so the owner can unmount them all when it is destroyed.
|
||||
*/
|
||||
export function snippetElements() {
|
||||
const mounted: Record<string, any>[] = []
|
||||
let destroyed = false
|
||||
return {
|
||||
render<T>(snippet: Snippet<[T]>, arg: T, tag: 'div' | 'span' = 'div'): HTMLElement {
|
||||
const target = document.createElement(tag)
|
||||
// Pierre re-renders synchronously when an edit session ends, which can be inside an
|
||||
// effect teardown, where Svelte refuses to create the mounted component's effects.
|
||||
queueMicrotask(() => {
|
||||
if (destroyed) return
|
||||
mounted.push(mount(SnippetHost<T>, { target, props: { snippet, arg } }))
|
||||
})
|
||||
return target
|
||||
},
|
||||
destroy() {
|
||||
destroyed = true
|
||||
for (const m of mounted.splice(0)) unmount(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/common'
|
||||
import DiffEditor from '$lib/components/DiffEditor.svelte'
|
||||
import ToolCodeDiffView from '$lib/components/copilot/chat/ToolCodeDiffView.svelte'
|
||||
import type { ToolCodeDiff } from '$lib/components/copilot/chat/shared'
|
||||
import { Tab, Tabs } from '$lib/components/common'
|
||||
import DiffTab from './DiffTab.svelte'
|
||||
import ReviewTab from './ReviewTab.svelte'
|
||||
import MultiFileTab from './MultiFileTab.svelte'
|
||||
import EditorTab from './EditorTab.svelte'
|
||||
import MergeTab from './MergeTab.svelte'
|
||||
|
||||
type ComparisonCase = {
|
||||
id: string
|
||||
label: string
|
||||
diff: ToolCodeDiff
|
||||
}
|
||||
|
||||
const stableLines = Array.from(
|
||||
{ length: 14 },
|
||||
(_, index) => ` const stableValue${index + 1} = getStableValue(${index + 1})`
|
||||
)
|
||||
|
||||
const cases: ComparisonCase[] = [
|
||||
{
|
||||
id: 'typescript-replacement',
|
||||
label: 'TypeScript replacement',
|
||||
diff: {
|
||||
lang: 'typescript',
|
||||
before: `export function greeting(name: string) {
|
||||
return \`Hello, \${name}\`
|
||||
}`,
|
||||
after: `export function greeting(name: string) {
|
||||
const message = \`Hello, \${name}!\`
|
||||
return message
|
||||
}`
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'long-unchanged-sections',
|
||||
label: 'Long unchanged sections',
|
||||
diff: {
|
||||
lang: 'typescript',
|
||||
before: [
|
||||
'export function buildSummary() {',
|
||||
...stableLines,
|
||||
'\treturn formatSummary("draft")',
|
||||
'}'
|
||||
].join('\n'),
|
||||
after: [
|
||||
'export function buildSummary() {',
|
||||
...stableLines,
|
||||
'\treturn formatSummary("published")',
|
||||
'}'
|
||||
].join('\n')
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'json-structure',
|
||||
label: 'JSON structure',
|
||||
diff: {
|
||||
lang: 'json',
|
||||
before: `{
|
||||
"name": "daily-report",
|
||||
"schedule": "0 9 * * 1-5",
|
||||
"enabled": false
|
||||
}`,
|
||||
after: `{
|
||||
"name": "daily-report",
|
||||
"schedule": "0 9 * * 1-5",
|
||||
"timezone": "Europe/Paris",
|
||||
"enabled": true
|
||||
}`
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'python-add-remove',
|
||||
label: 'Python additions and removals',
|
||||
diff: {
|
||||
lang: 'python',
|
||||
before: `def notify(users):
|
||||
for user in users:
|
||||
send_email(user, "Weekly update")
|
||||
|
||||
return len(users)`,
|
||||
after: `def notify(users):
|
||||
active_users = [user for user in users if user.active]
|
||||
for user in active_users:
|
||||
send_email(user, "Your weekly update")
|
||||
|
||||
return len(active_users)`
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
let activeCaseId = $state(cases[0].id)
|
||||
let activeCase = $derived(cases.find((item) => item.id === activeCaseId) ?? cases[0])
|
||||
let tab = $state('diff')
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -96,44 +14,30 @@
|
||||
</svelte:head>
|
||||
|
||||
<main class="mx-auto max-w-[1440px] p-6">
|
||||
<div class="mb-5 flex flex-wrap gap-2">
|
||||
{#each cases as item}
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
selected={activeCaseId === item.id}
|
||||
aria-pressed={activeCaseId === item.id}
|
||||
onclick={() => (activeCaseId = item.id)}>{item.label}</Button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-2">
|
||||
<section class="min-w-0">
|
||||
<h1 class="mb-2 text-sm font-semibold">Monaco</h1>
|
||||
<div class="h-[400px] overflow-hidden border border-slate-200 bg-white">
|
||||
{#key activeCase.id}
|
||||
<DiffEditor
|
||||
className="h-full"
|
||||
defaultLang={activeCase.diff.lang}
|
||||
defaultModifiedLang={activeCase.diff.lang}
|
||||
defaultOriginal={activeCase.diff.before}
|
||||
defaultModified={activeCase.diff.after}
|
||||
inlineDiff
|
||||
open
|
||||
readOnly
|
||||
/>
|
||||
{/key}
|
||||
<h1 class="mb-1 text-lg font-semibold">Diff comparison</h1>
|
||||
<p class="mb-4 text-xs text-secondary">
|
||||
Monaco, our highlight.js diff view and <code>@pierre/diffs</code> on the same inputs.
|
||||
</p>
|
||||
<Tabs bind:selected={tab}>
|
||||
<Tab value="diff" label="Diff" />
|
||||
<Tab value="review" label="Review" />
|
||||
<Tab value="multi" label="Multi-file" />
|
||||
<Tab value="editor" label="Editor" />
|
||||
<Tab value="merge" label="Merge conflict" />
|
||||
{#snippet content()}
|
||||
<div class="pt-4">
|
||||
{#if tab === 'diff'}
|
||||
<DiffTab />
|
||||
{:else if tab === 'review'}
|
||||
<ReviewTab />
|
||||
{:else if tab === 'multi'}
|
||||
<MultiFileTab />
|
||||
{:else if tab === 'editor'}
|
||||
<EditorTab />
|
||||
{:else if tab === 'merge'}
|
||||
<MergeTab />
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="min-w-0">
|
||||
<h2 class="mb-2 text-sm font-semibold">Native</h2>
|
||||
<div class="h-[400px] overflow-auto border border-slate-200 bg-white">
|
||||
{#key activeCase.id}
|
||||
<ToolCodeDiffView diff={activeCase.diff} />
|
||||
{/key}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Tabs>
|
||||
</main>
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte'
|
||||
import { Button } from '$lib/components/common'
|
||||
import DiffEditor from '$lib/components/DiffEditor.svelte'
|
||||
import ToolCodeDiffView from '$lib/components/copilot/chat/ToolCodeDiffView.svelte'
|
||||
import PierreDiff from '$lib/components/pierre/PierreDiff.svelte'
|
||||
import PierreCodeView from '$lib/components/pierre/PierreCodeView.svelte'
|
||||
import { switchMainThreadHighlighter } from '$lib/components/pierre/pierre'
|
||||
import { caseFileDiff, type ComparisonCase } from './cases'
|
||||
import { countNodes, formatMs, observeLongTasks, sleep, waitForSelector } from './measure'
|
||||
import { diffOptions, settingsPool, type PierreSettings } from './pierreSettings'
|
||||
|
||||
let { diffCase, settings }: { diffCase: ComparisonCase; settings: PierreSettings } = $props()
|
||||
|
||||
type Renderer = {
|
||||
id: string
|
||||
label: string
|
||||
/** Matches once the first line is on screen. */
|
||||
painted: string
|
||||
/** Matches once syntax colors are applied. */
|
||||
highlighted: string
|
||||
pierre?: Partial<PierreSettings> & { virtualized?: boolean }
|
||||
}
|
||||
|
||||
const PIERRE_PAINTED = '[data-line]'
|
||||
const PIERRE_HIGHLIGHTED = '[data-line] span[style]'
|
||||
|
||||
const renderers: Renderer[] = [
|
||||
{
|
||||
id: 'monaco',
|
||||
label: 'Monaco',
|
||||
painted: '.view-line',
|
||||
highlighted: '.view-line span[class*="mtk"]:not(.mtk1)'
|
||||
},
|
||||
{
|
||||
id: 'native',
|
||||
label: 'Native (highlight.js)',
|
||||
painted: '[class*="diff-line-"]',
|
||||
highlighted: '[class*="hljs-"]'
|
||||
},
|
||||
...(
|
||||
[
|
||||
['shiki-js', false],
|
||||
['shiki-js', true],
|
||||
['shiki-wasm', false],
|
||||
['highlights', false],
|
||||
['highlights', true]
|
||||
] as const
|
||||
).map(([highlighter, useWorkers]) => ({
|
||||
id: `pierre-${highlighter}-${useWorkers}`,
|
||||
label: `Pierre ${highlighter}${useWorkers ? ' + workers' : ''}`,
|
||||
painted: PIERRE_PAINTED,
|
||||
highlighted: PIERRE_HIGHLIGHTED,
|
||||
pierre: { highlighter, useWorkers }
|
||||
})),
|
||||
...(['shiki-js', 'highlights'] as const).map((highlighter) => ({
|
||||
id: `pierre-codeview-${highlighter}`,
|
||||
label: `Pierre CodeView ${highlighter} (virtualized)`,
|
||||
painted: PIERRE_PAINTED,
|
||||
highlighted: PIERRE_HIGHLIGHTED,
|
||||
pierre: { virtualized: true, highlighter, useWorkers: false }
|
||||
}))
|
||||
]
|
||||
|
||||
type Result = {
|
||||
run: number
|
||||
label: string
|
||||
painted?: number
|
||||
highlighted?: number
|
||||
longTasks?: number
|
||||
nodes: number
|
||||
}
|
||||
|
||||
let results: Result[] = $state([])
|
||||
let current: Renderer | undefined = $state()
|
||||
let running = $state(false)
|
||||
let box: HTMLDivElement | undefined = $state()
|
||||
|
||||
const currentSettings = $derived(current?.pierre ? { ...settings, ...current.pierre } : settings)
|
||||
const fileDiff = $derived(caseFileDiff(diffCase))
|
||||
|
||||
async function runAll(rounds: number) {
|
||||
running = true
|
||||
results = []
|
||||
for (let run = 1; run <= rounds; run++) {
|
||||
for (const r of renderers) {
|
||||
current = undefined
|
||||
await tick()
|
||||
const s = { ...settings, ...r.pierre }
|
||||
if (r.pierre && !s.useWorkers) await switchMainThreadHighlighter(s.highlighter)
|
||||
await sleep(300)
|
||||
const longTasks = observeLongTasks()
|
||||
const start = performance.now()
|
||||
current = r
|
||||
await tick()
|
||||
const painted = await waitForSelector(() => box, r.painted)
|
||||
const highlighted = await waitForSelector(() => box, r.highlighted, 10_000)
|
||||
await sleep(1000)
|
||||
results.push({
|
||||
run,
|
||||
label: r.label,
|
||||
painted: painted && painted - start,
|
||||
highlighted: highlighted && highlighted - start,
|
||||
longTasks: longTasks.stop(),
|
||||
nodes: box ? countNodes(box) : 0
|
||||
})
|
||||
}
|
||||
}
|
||||
current = undefined
|
||||
running = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<section class="flex flex-col gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<h2 class="text-sm font-semibold">Benchmark</h2>
|
||||
<span class="text-2xs text-hint">
|
||||
Mounts each renderer alone on the current case. Run 1 includes loading code, grammars and
|
||||
workers; run 2 is warm. Long tasks are main-thread blocks over 50 ms (Chromium only). "–"
|
||||
under Highlighted means no colors within 10 s: the native view skips highlighting past 2,000
|
||||
lines.
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<Button unifiedSize="sm" variant="accent" disabled={running} onclick={() => runAll(2)}>
|
||||
Run benchmark
|
||||
</Button>
|
||||
{#if running && current}
|
||||
<span class="text-xs text-secondary">Rendering {current.label}…</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if results.length > 0}
|
||||
<table class="w-full text-xs">
|
||||
<thead>
|
||||
<tr class="text-left text-secondary">
|
||||
<th class="py-1 font-normal">Run</th>
|
||||
<th class="font-normal">Renderer</th>
|
||||
<th class="text-right font-normal">First line</th>
|
||||
<th class="text-right font-normal">Highlighted</th>
|
||||
<th class="text-right font-normal">Long tasks</th>
|
||||
<th class="text-right font-normal">DOM nodes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each results as r (`${r.run}:${r.label}`)}
|
||||
<tr class="border-t border-gray-200 dark:border-gray-700">
|
||||
<td class="py-1">{r.run === 1 ? 'cold' : 'warm'}</td>
|
||||
<td>{r.label}</td>
|
||||
<td class="text-right">{formatMs(r.painted)}</td>
|
||||
<td class="text-right">{formatMs(r.highlighted)}</td>
|
||||
<td class="text-right">{formatMs(r.longTasks)}</td>
|
||||
<td class="text-right">{r.nodes.toLocaleString()}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
{/if}
|
||||
|
||||
<div bind:this={box} class="h-[400px] overflow-auto border {current ? '' : 'hidden'}">
|
||||
{#if current?.id === 'monaco'}
|
||||
<DiffEditor
|
||||
className="h-full"
|
||||
defaultLang={diffCase.diff.beforeLang ?? diffCase.diff.lang}
|
||||
defaultModifiedLang={diffCase.diff.lang}
|
||||
defaultOriginal={diffCase.diff.before}
|
||||
defaultModified={diffCase.diff.after}
|
||||
inlineDiff={settings.diffStyle === 'unified'}
|
||||
open
|
||||
readOnly
|
||||
/>
|
||||
{:else if current?.id === 'native'}
|
||||
<ToolCodeDiffView diff={diffCase.diff} />
|
||||
{:else if current?.pierre?.virtualized}
|
||||
<PierreCodeView
|
||||
class="h-full overflow-auto"
|
||||
items={[{ type: 'diff', id: diffCase.id, fileDiff }]}
|
||||
options={diffOptions(currentSettings)}
|
||||
workerPool={settingsPool(currentSettings)}
|
||||
/>
|
||||
{:else if current?.pierre}
|
||||
<PierreDiff
|
||||
before={diffCase.diff.before}
|
||||
after={diffCase.diff.after}
|
||||
filename={diffCase.filename}
|
||||
lang={diffCase.diff.lang}
|
||||
options={diffOptions(currentSettings)}
|
||||
workerPool={settingsPool(currentSettings)}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,115 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/common'
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import DiffEditor from '$lib/components/DiffEditor.svelte'
|
||||
import ToolCodeDiffView from '$lib/components/copilot/chat/ToolCodeDiffView.svelte'
|
||||
import PierreDiff from '$lib/components/pierre/PierreDiff.svelte'
|
||||
import PierreCodeView from '$lib/components/pierre/PierreCodeView.svelte'
|
||||
import Benchmark from './Benchmark.svelte'
|
||||
import PierreSettingsBar from './PierreSettingsBar.svelte'
|
||||
import WorkspaceScriptPicker from './WorkspaceScriptPicker.svelte'
|
||||
import { switchMainThreadHighlighter } from '$lib/components/pierre/pierre'
|
||||
import { caseFileDiff, cases, type ComparisonCase } from './cases'
|
||||
import { DEFAULT_SETTINGS, diffOptions, settingsPool } from './pierreSettings'
|
||||
|
||||
let settings = $state({ ...DEFAULT_SETTINGS })
|
||||
let virtualized = $state(false)
|
||||
let workspaceCase: ComparisonCase | undefined = $state()
|
||||
let activeCaseId = $state(cases[0].id)
|
||||
const activeCase = $derived(
|
||||
activeCaseId === workspaceCase?.id
|
||||
? workspaceCase
|
||||
: (cases.find((c) => c.id === activeCaseId) ?? cases[0])
|
||||
)
|
||||
const options = $derived(diffOptions(settings))
|
||||
const pool = $derived(settingsPool(settings))
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{#each cases as item (item.id)}
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
selected={activeCaseId === item.id}
|
||||
aria-pressed={activeCaseId === item.id}
|
||||
onclick={() => (activeCaseId = item.id)}>{item.label}</Button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
<WorkspaceScriptPicker
|
||||
onLoaded={(c) => {
|
||||
workspaceCase = c
|
||||
activeCaseId = c.id
|
||||
}}
|
||||
/>
|
||||
|
||||
<div class="grid gap-4 lg:grid-cols-2">
|
||||
<section class="min-w-0">
|
||||
<h2 class="mb-2 text-sm font-semibold">Monaco</h2>
|
||||
<div class="h-[400px] overflow-hidden border">
|
||||
{#key `${activeCase.id}:${settings.diffStyle}`}
|
||||
<DiffEditor
|
||||
className="h-full"
|
||||
defaultLang={activeCase.diff.beforeLang ?? activeCase.diff.lang}
|
||||
defaultModifiedLang={activeCase.diff.lang}
|
||||
defaultOriginal={activeCase.diff.before}
|
||||
defaultModified={activeCase.diff.after}
|
||||
inlineDiff={settings.diffStyle === 'unified'}
|
||||
disableAutoInline
|
||||
open
|
||||
readOnly
|
||||
/>
|
||||
{/key}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="min-w-0">
|
||||
<h2 class="mb-2 text-sm font-semibold">Native (highlight.js)</h2>
|
||||
<div class="h-[400px] overflow-auto border">
|
||||
{#key activeCase.id}
|
||||
<ToolCodeDiffView diff={activeCase.diff} />
|
||||
{/key}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<div class="flex items-center gap-4">
|
||||
<h2 class="text-sm font-semibold">Pierre</h2>
|
||||
<Toggle size="xs" bind:checked={virtualized} options={{ right: 'Virtualized (CodeView)' }} />
|
||||
</div>
|
||||
<PierreSettingsBar bind:settings />
|
||||
<div class="h-[400px] overflow-auto border">
|
||||
<!-- A component's worker pool is fixed at construction. -->
|
||||
{#key `${settings.useWorkers}:${settings.highlighter}:${virtualized}`}
|
||||
{#await settings.useWorkers ? undefined : switchMainThreadHighlighter(settings.highlighter) then}
|
||||
{@render pierre()}
|
||||
{/await}
|
||||
{/key}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Benchmark diffCase={activeCase} {settings} />
|
||||
</div>
|
||||
|
||||
{#snippet pierre()}
|
||||
{#if virtualized}
|
||||
<PierreCodeView
|
||||
class="h-full overflow-auto"
|
||||
items={[{ type: 'diff', id: activeCase.id, fileDiff: caseFileDiff(activeCase) }]}
|
||||
{options}
|
||||
workerPool={pool}
|
||||
/>
|
||||
{:else}
|
||||
<PierreDiff
|
||||
before={activeCase.diff.before}
|
||||
after={activeCase.diff.after}
|
||||
filename={activeCase.filename}
|
||||
lang={activeCase.diff.lang}
|
||||
beforeLang={activeCase.diff.beforeLang}
|
||||
{options}
|
||||
workerPool={pool}
|
||||
/>
|
||||
{/if}
|
||||
{/snippet}
|
||||
@@ -0,0 +1,171 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import { get } from 'svelte/store'
|
||||
import type { Editor, EditPredictProvider, Marker } from '@pierre/diffs/edit'
|
||||
import { Button } from '$lib/components/common'
|
||||
import Select from '$lib/components/select/Select.svelte'
|
||||
import SimpleEditor from '$lib/components/SimpleEditor.svelte'
|
||||
import PierreFileEditor from '$lib/components/pierre/PierreFileEditor.svelte'
|
||||
import { getFimCompletion } from '$lib/components/copilot/lib'
|
||||
import { loadCopilot } from '$lib/components/copilot/loadCopilot'
|
||||
import { copilotInfo } from '$lib/aiStore'
|
||||
import { workspaceStore } from '$lib/stores'
|
||||
import { Redo2, Undo2 } from 'lucide-svelte'
|
||||
import { lint } from './lint'
|
||||
import { REVIEW_BEFORE } from './reviewSample'
|
||||
|
||||
let pierreCode = $state(REVIEW_BEFORE)
|
||||
let monacoCode = $state(REVIEW_BEFORE)
|
||||
let markers: Marker[] = $state.raw(lint(REVIEW_BEFORE))
|
||||
let editor: Editor<'file', undefined, undefined> | undefined = $state()
|
||||
let predictionMode = $state<'eager' | 'subtle' | 'off'>('eager')
|
||||
let lastPrediction: string | undefined = $state()
|
||||
|
||||
const model = $derived($copilotInfo.codeCompletionModel)
|
||||
|
||||
onMount(() => {
|
||||
if ($workspaceStore) loadCopilot($workspaceStore)
|
||||
})
|
||||
|
||||
let lintTimer: ReturnType<typeof setTimeout> | undefined
|
||||
function onChange(code: string) {
|
||||
pierreCode = code
|
||||
clearTimeout(lintTimer)
|
||||
lintTimer = setTimeout(() => (markers = lint(code)), 300)
|
||||
}
|
||||
|
||||
// Fill-in-the-middle at the caret, through the same AI proxy as Monaco's autocomplete.
|
||||
const provider: EditPredictProvider = {
|
||||
async predict(request, { signal }) {
|
||||
const providerModel = get(copilotInfo).codeCompletionModel
|
||||
if (!providerModel) throw new Error('No code completion model configured')
|
||||
const abort = new AbortController()
|
||||
signal.addEventListener('abort', () => abort.abort())
|
||||
const prefix = request.excerptText.slice(0, request.cursorOffsetInExcerpt)
|
||||
const suffix = request.excerptText.slice(request.cursorOffsetInExcerpt)
|
||||
const start = performance.now()
|
||||
const completion = await getFimCompletion(prefix, suffix, providerModel, abort)
|
||||
const prefixLines = prefix.split('\n')
|
||||
const at = {
|
||||
line: request.excerptStartLine + prefixLines.length - 1,
|
||||
character: prefixLines[prefixLines.length - 1].length
|
||||
}
|
||||
lastPrediction = `${Math.round(performance.now() - start)} ms: ${JSON.stringify(completion ?? '')}`
|
||||
if (!completion) return { edits: [], newCursor: at }
|
||||
const inserted = completion.split('\n')
|
||||
return {
|
||||
edits: [{ range: { start: at, end: at }, newText: completion }],
|
||||
newCursor:
|
||||
inserted.length === 1
|
||||
? { line: at.line, character: at.character + completion.length }
|
||||
: {
|
||||
line: at.line + inserted.length - 1,
|
||||
character: inserted[inserted.length - 1].length
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const editorOptions = $derived(
|
||||
predictionMode === 'off' ? {} : { editPrediction: { provider, mode: predictionMode } }
|
||||
)
|
||||
</script>
|
||||
|
||||
<div class="grid gap-4 xl:grid-cols-2">
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<h2 class="text-sm font-semibold">Pierre editor</h2>
|
||||
<div class="flex flex-wrap items-center gap-3 text-xs">
|
||||
<label class="flex items-center gap-1">
|
||||
Edit prediction
|
||||
<Select
|
||||
size="sm"
|
||||
items={[
|
||||
{ value: 'eager', label: 'eager (as you type)' },
|
||||
{ value: 'subtle', label: 'subtle (tap Alt)' },
|
||||
{ value: 'off', label: 'off' }
|
||||
]}
|
||||
bind:value={predictionMode}
|
||||
/>
|
||||
</label>
|
||||
<span class="text-secondary">
|
||||
{model
|
||||
? `Model: ${model.provider}/${model.model}`
|
||||
: 'No code completion model in this workspace: set one in workspace AI settings'}
|
||||
</span>
|
||||
{#if editor}
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
iconOnly
|
||||
startIcon={{ icon: Undo2 }}
|
||||
onclick={() => editor?.undo()}
|
||||
/>
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
iconOnly
|
||||
startIcon={{ icon: Redo2 }}
|
||||
onclick={() => editor?.redo()}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-2xs text-hint">
|
||||
Tab accepts a prediction, Esc dismisses it. Select text for the selection action. Markers come
|
||||
from a demo linter and re-anchor as you type. Last prediction: {lastPrediction ?? '–'}
|
||||
</p>
|
||||
<div class="h-[560px] overflow-auto border">
|
||||
{#key predictionMode}
|
||||
<PierreFileEditor
|
||||
code={REVIEW_BEFORE}
|
||||
filename="billing.ts"
|
||||
lang="typescript"
|
||||
{editorOptions}
|
||||
{markers}
|
||||
{onChange}
|
||||
onEditor={(e) => (editor = e)}
|
||||
>
|
||||
{#snippet selectionAction(ctx)}
|
||||
<div class="flex gap-1 rounded-md border bg-surface p-1 shadow-md">
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
onclick={() => {
|
||||
ctx.replaceSelectionText(
|
||||
ctx
|
||||
.getSelectionText()
|
||||
.split('\n')
|
||||
.map((l) => `// ${l}`)
|
||||
.join('\n')
|
||||
)
|
||||
ctx.close()
|
||||
}}>Comment out</Button
|
||||
>
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
onclick={() => {
|
||||
navigator.clipboard.writeText(ctx.getSelectionText())
|
||||
ctx.close()
|
||||
}}>Copy</Button
|
||||
>
|
||||
</div>
|
||||
{/snippet}
|
||||
</PierreFileEditor>
|
||||
{/key}
|
||||
</div>
|
||||
<span class="text-2xs text-hint">
|
||||
{pierreCode.split('\n').length} lines, {markers.length} markers
|
||||
</span>
|
||||
</section>
|
||||
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<h2 class="text-sm font-semibold">Monaco (SimpleEditor)</h2>
|
||||
<p class="text-2xs text-hint">
|
||||
Monaco brings the TypeScript language service (completions, hovers, real diagnostics) that
|
||||
Pierre's editor does not have.
|
||||
</p>
|
||||
<div class="h-[590px] border">
|
||||
<SimpleEditor lang="typescript" bind:code={monacoCode} class="h-full" />
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
@@ -0,0 +1,44 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/common'
|
||||
import PierreMergeConflict from '$lib/components/pierre/PierreMergeConflict.svelte'
|
||||
import { MERGE_CONFLICT_SAMPLE } from './cases'
|
||||
|
||||
let resolved: string | undefined = $state()
|
||||
let resetKey = $state(0)
|
||||
</script>
|
||||
|
||||
<div class="grid gap-4 xl:grid-cols-2">
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<h2 class="text-sm font-semibold">Pierre: merge conflicts (beta)</h2>
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
onclick={() => {
|
||||
resolved = undefined
|
||||
resetKey++
|
||||
}}>Reset</Button
|
||||
>
|
||||
</div>
|
||||
<p class="text-2xs text-hint">
|
||||
Each conflict offers current, incoming or both. Windmill has no conflict UI today: a fork
|
||||
merge or a git sync pull with diverged items would be the place for it.
|
||||
</p>
|
||||
<div class="h-[480px] overflow-auto border">
|
||||
{#key resetKey}
|
||||
<PierreMergeConflict
|
||||
contents={MERGE_CONFLICT_SAMPLE}
|
||||
filename="customer.ts"
|
||||
lang="typescript"
|
||||
onResolved={(c) => (resolved = c)}
|
||||
/>
|
||||
{/key}
|
||||
</div>
|
||||
</section>
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<h2 class="text-sm font-semibold">Resolved output</h2>
|
||||
<pre class="h-[510px] overflow-auto border p-2 text-2xs"
|
||||
>{resolved ?? 'Resolve a conflict to see the result'}</pre
|
||||
>
|
||||
</section>
|
||||
</div>
|
||||
@@ -0,0 +1,134 @@
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte'
|
||||
import { parseDiffFromFile, type CodeViewItem } from '@pierre/diffs'
|
||||
import { Button } from '$lib/components/common'
|
||||
import Select from '$lib/components/select/Select.svelte'
|
||||
import DiffEditor from '$lib/components/DiffEditor.svelte'
|
||||
import PierreCodeView from '$lib/components/pierre/PierreCodeView.svelte'
|
||||
import { countNodes, formatMs, observeLongTasks, sleep, waitForSelector } from './measure'
|
||||
import { DEFAULT_SETTINGS, diffOptions, settingsPool } from './pierreSettings'
|
||||
import PierreSettingsBar from './PierreSettingsBar.svelte'
|
||||
|
||||
type Side = 'pierre' | 'monaco'
|
||||
type Stats = { painted?: number; longTasks?: number; nodes: number }
|
||||
|
||||
// More Monaco editors than this freezes the tab for minutes.
|
||||
const MONACO_MAX = 200
|
||||
let count = $state(50)
|
||||
let settings = $state({ ...DEFAULT_SETTINGS, useWorkers: true })
|
||||
let shown: Side | undefined = $state()
|
||||
let stats: Partial<Record<Side, Stats>> = $state({})
|
||||
let box: HTMLDivElement | undefined = $state()
|
||||
|
||||
function fileVersions(i: number) {
|
||||
const lines = Array.from(
|
||||
{ length: 40 },
|
||||
(_, l) => `export const value_${i}_${l} = compute(${l}, 'item ${i}')`
|
||||
)
|
||||
const after = [...lines]
|
||||
after[5] = `export const value_${i}_5 = compute(5, 'item ${i}', { cached: true })`
|
||||
after.splice(
|
||||
20,
|
||||
2,
|
||||
`// merged 20 and 21`,
|
||||
`export const merged_${i} = [value_${i}_20, value_${i}_21]`
|
||||
)
|
||||
after.push(`export default value_${i}_0`)
|
||||
return { name: `f/module_${i}/index.ts`, before: lines.join('\n'), after: after.join('\n') }
|
||||
}
|
||||
|
||||
const files = $derived(Array.from({ length: count }, (_, i) => fileVersions(i)))
|
||||
const items: CodeViewItem<undefined>[] = $derived(
|
||||
files.map((f) => ({
|
||||
type: 'diff',
|
||||
id: f.name,
|
||||
fileDiff: parseDiffFromFile(
|
||||
{ name: f.name, contents: f.before },
|
||||
{ name: f.name, contents: f.after }
|
||||
)
|
||||
}))
|
||||
)
|
||||
const pool = $derived(settingsPool(settings))
|
||||
|
||||
async function show(side: Side) {
|
||||
stats[side] = undefined
|
||||
shown = undefined
|
||||
await tick()
|
||||
await sleep(300)
|
||||
const longTasks = observeLongTasks()
|
||||
const start = performance.now()
|
||||
shown = side
|
||||
await tick()
|
||||
const painted = await waitForSelector(
|
||||
() => box,
|
||||
side === 'pierre' ? '[data-line]' : '.view-line'
|
||||
)
|
||||
await sleep(1500)
|
||||
stats[side] = {
|
||||
painted: painted && painted - start,
|
||||
longTasks: longTasks.stop(),
|
||||
nodes: box ? countNodes(box) : 0
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-3">
|
||||
<p class="text-2xs text-hint">
|
||||
A review of many changed files in one scroll, as a deployment or fork-merge review would show
|
||||
them. Pierre's CodeView virtualizes the whole list; Monaco needs one editor per file.
|
||||
</p>
|
||||
<div class="flex flex-wrap items-center gap-3 text-xs">
|
||||
<label class="flex items-center gap-1">
|
||||
Files
|
||||
<Select
|
||||
size="sm"
|
||||
items={[10, 50, 200, 1000].map((n) => ({ value: n, label: `${n}` }))}
|
||||
bind:value={count}
|
||||
/>
|
||||
</label>
|
||||
<Button unifiedSize="sm" variant="accent" onclick={() => show('pierre')}>Render Pierre</Button>
|
||||
<Button unifiedSize="sm" variant="default" onclick={() => show('monaco')}>
|
||||
Render Monaco{count > MONACO_MAX ? ` (first ${MONACO_MAX})` : ''}
|
||||
</Button>
|
||||
{#each ['pierre', 'monaco'] as const as side (side)}
|
||||
{@const s = stats[side]}
|
||||
{#if s}
|
||||
<span class="text-secondary">
|
||||
{side}: first line {formatMs(s.painted)}, long tasks {formatMs(s.longTasks)},
|
||||
{s.nodes.toLocaleString()} nodes
|
||||
</span>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
<PierreSettingsBar bind:settings />
|
||||
|
||||
<div bind:this={box} class="h-[640px] overflow-auto border">
|
||||
{#if shown === 'pierre'}
|
||||
{#key `${settings.useWorkers}:${settings.highlighter}`}
|
||||
<PierreCodeView
|
||||
class="h-full overflow-auto"
|
||||
{items}
|
||||
options={diffOptions(settings)}
|
||||
workerPool={pool}
|
||||
/>
|
||||
{/key}
|
||||
{:else if shown === 'monaco'}
|
||||
{#each files.slice(0, MONACO_MAX) as f (f.name)}
|
||||
<div class="border-b px-2 py-1 text-xs font-semibold">{f.name}</div>
|
||||
<div class="h-[300px]">
|
||||
<DiffEditor
|
||||
className="h-full"
|
||||
defaultLang="typescript"
|
||||
defaultModifiedLang="typescript"
|
||||
defaultOriginal={f.before}
|
||||
defaultModified={f.after}
|
||||
inlineDiff={settings.diffStyle === 'unified'}
|
||||
disableAutoInline
|
||||
open
|
||||
readOnly
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,71 @@
|
||||
<script lang="ts">
|
||||
import Select from '$lib/components/select/Select.svelte'
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import { canUseWASM } from '@pierre/diffs'
|
||||
import { THEMES, type PierreSettings } from './pierreSettings'
|
||||
|
||||
let { settings = $bindable() }: { settings: PierreSettings } = $props()
|
||||
|
||||
const items = (values: string[]) => values.map((value) => ({ value, label: value }))
|
||||
const wasm = canUseWASM()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-x-4 gap-y-2 text-xs">
|
||||
<label class="flex items-center gap-1">
|
||||
Layout
|
||||
<Select size="sm" items={items(['unified', 'split'])} bind:value={settings.diffStyle} />
|
||||
</label>
|
||||
<label class="flex items-center gap-1">
|
||||
Indicators
|
||||
<Select
|
||||
size="sm"
|
||||
items={items(['bars', 'classic', 'none'])}
|
||||
bind:value={settings.diffIndicators}
|
||||
/>
|
||||
</label>
|
||||
<label class="flex items-center gap-1">
|
||||
Inline diff
|
||||
<Select
|
||||
size="sm"
|
||||
items={items(['word-alt', 'word', 'word-line', 'char', 'none'])}
|
||||
bind:value={settings.lineDiffType}
|
||||
/>
|
||||
</label>
|
||||
<label class="flex items-center gap-1">
|
||||
Hunk separators
|
||||
<Select
|
||||
size="sm"
|
||||
items={items(['line-info', 'line-info-basic', 'metadata', 'simple'])}
|
||||
bind:value={settings.hunkSeparators}
|
||||
/>
|
||||
</label>
|
||||
<label class="flex items-center gap-1">
|
||||
Highlighter
|
||||
<Select
|
||||
size="sm"
|
||||
items={[
|
||||
{ value: 'shiki-js', label: 'shiki-js' },
|
||||
{ value: 'shiki-wasm', label: 'shiki-wasm', disabled: !wasm },
|
||||
{ value: 'highlights', label: 'highlights (beta)', disabled: !wasm }
|
||||
]}
|
||||
bind:value={settings.highlighter}
|
||||
/>
|
||||
</label>
|
||||
<label class="flex items-center gap-1">
|
||||
Theme
|
||||
<Select size="sm" items={items(Object.keys(THEMES))} bind:value={settings.theme} />
|
||||
</label>
|
||||
<Toggle size="xs" bind:checked={settings.useWorkers} options={{ right: 'Worker pool' }} />
|
||||
<Toggle size="xs" bind:checked={settings.wrap} options={{ right: 'Wrap' }} />
|
||||
<Toggle size="xs" bind:checked={settings.expandUnchanged} options={{ right: 'Expand all' }} />
|
||||
<Toggle
|
||||
size="xs"
|
||||
bind:checked={settings.disableBackground}
|
||||
options={{ right: 'No line background' }}
|
||||
/>
|
||||
<Toggle
|
||||
size="xs"
|
||||
bind:checked={settings.disableLineNumbers}
|
||||
options={{ right: 'No line numbers' }}
|
||||
/>
|
||||
</div>
|
||||
@@ -0,0 +1,262 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
diffAcceptRejectHunk,
|
||||
type DiffLineAnnotation,
|
||||
type FileDiffMetadata,
|
||||
type SelectedLineRange
|
||||
} from '@pierre/diffs'
|
||||
import type { Editor } from '@pierre/diffs/edit'
|
||||
import { Badge, Button } from '$lib/components/common'
|
||||
import TextInput from '$lib/components/text_input/TextInput.svelte'
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import DiffEditor from '$lib/components/DiffEditor.svelte'
|
||||
import PierreDiff from '$lib/components/pierre/PierreDiff.svelte'
|
||||
import { randomUUID } from '$lib/utils/uuid'
|
||||
import { Check, Trash2, Undo2, Redo2, X } from 'lucide-svelte'
|
||||
import { caseFileDiff, type ComparisonCase } from './cases'
|
||||
import { lint } from './lint'
|
||||
import { REVIEW_AFTER, REVIEW_BEFORE } from './reviewSample'
|
||||
|
||||
type Note =
|
||||
| { kind: 'change'; hunk: number; change: number; additions: number; deletions: number }
|
||||
| { kind: 'comment'; id: string }
|
||||
|
||||
const reviewCase: ComparisonCase = {
|
||||
id: 'review',
|
||||
label: 'Review',
|
||||
filename: 'billing.ts',
|
||||
diff: { lang: 'typescript', before: REVIEW_BEFORE, after: REVIEW_AFTER }
|
||||
}
|
||||
|
||||
// Raw: Pierre compares diffs by reference and mutates them in place.
|
||||
let reviewDiff: FileDiffMetadata = $state.raw(caseFileDiff(reviewCase))
|
||||
let comments: DiffLineAnnotation<Note>[] = $state.raw([])
|
||||
let commentText: Record<string, string> = $state({})
|
||||
let editing = $state(false)
|
||||
let editor: Editor<'file-diff', Note, undefined> | undefined = $state()
|
||||
let liveAfter: string | undefined = $state()
|
||||
let selected: SelectedLineRange | null = $state(null)
|
||||
let hoveredToken: string | undefined = $state()
|
||||
let log: string[] = $state([])
|
||||
|
||||
function changeAnnotations(diff: FileDiffMetadata): DiffLineAnnotation<Note>[] {
|
||||
const out: DiffLineAnnotation<Note>[] = []
|
||||
diff.hunks.forEach((hunk, h) => {
|
||||
hunk.hunkContent.forEach((c, i) => {
|
||||
if (c.type !== 'change') return
|
||||
// Anchored under the block's last line; a pure deletion has no new-side line.
|
||||
const onAdditions = c.additions > 0
|
||||
out.push({
|
||||
side: onAdditions ? 'additions' : 'deletions',
|
||||
lineNumber: onAdditions
|
||||
? c.additionLineIndex + c.additions
|
||||
: c.deletionLineIndex + c.deletions,
|
||||
metadata: {
|
||||
kind: 'change',
|
||||
hunk: h,
|
||||
change: i,
|
||||
additions: c.additions,
|
||||
deletions: c.deletions
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
const annotations = $derived([...changeAnnotations(reviewDiff), ...comments])
|
||||
const resultText = $derived(reviewDiff.additionLines.join(''))
|
||||
const remaining = $derived(changeAnnotations(reviewDiff).length)
|
||||
const markers = $derived(lint(liveAfter ?? resultText))
|
||||
|
||||
function resolve(hunk: number, change: number, type: 'accept' | 'reject') {
|
||||
reviewDiff = diffAcceptRejectHunk(reviewDiff, hunk, { type, changeIndex: change })
|
||||
log = [`${type} hunk ${hunk + 1}, change ${change + 1}`, ...log]
|
||||
}
|
||||
|
||||
function resolveAll(type: 'accept' | 'reject') {
|
||||
// Resolving converts a change to context, so walk back to keep earlier indices valid.
|
||||
for (const a of changeAnnotations(reviewDiff).reverse()) {
|
||||
if (a.metadata.kind === 'change') {
|
||||
reviewDiff = diffAcceptRejectHunk(reviewDiff, a.metadata.hunk, {
|
||||
type,
|
||||
changeIndex: a.metadata.change
|
||||
})
|
||||
}
|
||||
}
|
||||
log = [`${type} all`, ...log]
|
||||
}
|
||||
|
||||
function addComment(range: SelectedLineRange) {
|
||||
const id = randomUUID()
|
||||
commentText[id] = ''
|
||||
comments = [
|
||||
...comments,
|
||||
{
|
||||
side: range.endSide ?? range.side ?? 'additions',
|
||||
lineNumber: range.end,
|
||||
metadata: { kind: 'comment', id }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
function reset() {
|
||||
reviewDiff = caseFileDiff(reviewCase)
|
||||
comments = []
|
||||
liveAfter = undefined
|
||||
log = []
|
||||
}
|
||||
|
||||
const options = {
|
||||
diffStyle: 'unified' as const,
|
||||
enableLineSelection: true,
|
||||
enableGutterUtility: true,
|
||||
lineHoverHighlight: 'both' as const,
|
||||
onLineSelected: (range: SelectedLineRange | null) => (selected = range),
|
||||
onGutterUtilityClick: addComment,
|
||||
onTokenEnter: ({ tokenText }: { tokenText: string }) => (hoveredToken = tokenText),
|
||||
onTokenLeave: () => (hoveredToken = undefined)
|
||||
}
|
||||
</script>
|
||||
|
||||
{#snippet headerMetadata(_diff: FileDiffMetadata)}
|
||||
<Badge color={remaining > 0 ? 'yellow' : 'green'}>
|
||||
{remaining > 0 ? `${remaining} to review` : 'reviewed'}
|
||||
</Badge>
|
||||
{/snippet}
|
||||
|
||||
{#snippet note(a: DiffLineAnnotation<Note>)}
|
||||
{#if a.metadata.kind === 'change'}
|
||||
{@const m = a.metadata}
|
||||
<div class="flex items-center gap-2 border-y bg-surface-secondary px-3 py-1 text-xs">
|
||||
<span class="text-secondary">
|
||||
Change {m.change + 1} of hunk {m.hunk + 1}: +{m.additions} −{m.deletions}
|
||||
</span>
|
||||
<Button
|
||||
unifiedSize="2xs"
|
||||
variant="accent-secondary"
|
||||
startIcon={{ icon: Check }}
|
||||
disabled={editing}
|
||||
onclick={() => resolve(m.hunk, m.change, 'accept')}>Accept</Button
|
||||
>
|
||||
<Button
|
||||
unifiedSize="2xs"
|
||||
variant="subtle"
|
||||
startIcon={{ icon: X }}
|
||||
disabled={editing}
|
||||
onclick={() => resolve(m.hunk, m.change, 'reject')}>Reject</Button
|
||||
>
|
||||
</div>
|
||||
{:else}
|
||||
{@const id = a.metadata.id}
|
||||
<div class="flex items-center gap-2 border-y bg-surface-secondary px-3 py-2">
|
||||
<TextInput
|
||||
size="sm"
|
||||
bind:value={commentText[id]}
|
||||
inputProps={{ placeholder: `Comment on line ${a.lineNumber}` }}
|
||||
/>
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
iconOnly
|
||||
startIcon={{ icon: Trash2 }}
|
||||
onclick={() => (comments = comments.filter((c) => c !== a))}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
<div class="grid gap-4 xl:grid-cols-[3fr_2fr]">
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<h2 class="text-sm font-semibold">Pierre: review an AI change</h2>
|
||||
<p class="text-2xs text-hint">
|
||||
Accept or reject each change block, add a comment from the gutter (+), select lines, hover a
|
||||
token, or edit the new side directly. Demo lint markers follow the edited text.
|
||||
</p>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
unifiedSize="sm"
|
||||
variant="accent"
|
||||
disabled={editing || remaining === 0}
|
||||
onclick={() => resolveAll('accept')}>Accept all ({remaining})</Button
|
||||
>
|
||||
<Button
|
||||
unifiedSize="sm"
|
||||
variant="default"
|
||||
disabled={editing || remaining === 0}
|
||||
onclick={() => resolveAll('reject')}>Reject all</Button
|
||||
>
|
||||
<Button unifiedSize="sm" variant="subtle" onclick={reset}>Reset</Button>
|
||||
<Toggle size="xs" bind:checked={editing} options={{ right: 'Edit new side' }} />
|
||||
{#if editor}
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
iconOnly
|
||||
startIcon={{ icon: Undo2 }}
|
||||
onclick={() => editor?.undo()}
|
||||
/>
|
||||
<Button
|
||||
unifiedSize="xs"
|
||||
variant="subtle"
|
||||
iconOnly
|
||||
startIcon={{ icon: Redo2 }}
|
||||
onclick={() => editor?.redo()}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex gap-4 text-2xs text-secondary">
|
||||
<span>
|
||||
Selection: {selected ? `${selected.side ?? ''} ${selected.start}–${selected.end}` : 'none'}
|
||||
</span>
|
||||
<span>Hovered token: <code>{hoveredToken ?? '–'}</code></span>
|
||||
<span>Markers: {markers.length}</span>
|
||||
</div>
|
||||
<div class="h-[560px] overflow-auto border">
|
||||
<PierreDiff
|
||||
fileDiff={reviewDiff}
|
||||
lang="typescript"
|
||||
filename={reviewCase.filename}
|
||||
{options}
|
||||
{annotations}
|
||||
annotation={note}
|
||||
{headerMetadata}
|
||||
editable={editing}
|
||||
markers={editing ? markers : undefined}
|
||||
onEditor={(e) => (editor = e)}
|
||||
onEditChange={(text) => (liveAfter = text)}
|
||||
onEdited={(_text, fileDiff) => {
|
||||
reviewDiff = fileDiff
|
||||
liveAfter = undefined
|
||||
log = ['edit session accepted', ...log]
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<h2 class="text-sm font-semibold">Monaco: editable diff</h2>
|
||||
<p class="text-2xs text-hint">
|
||||
Monaco's equivalent: the new side is editable and the gutter arrow reverts a change. No
|
||||
per-change accept, no inline comments.
|
||||
</p>
|
||||
<div class="h-[300px] overflow-hidden border">
|
||||
<DiffEditor
|
||||
className="h-full"
|
||||
defaultLang="typescript"
|
||||
defaultModifiedLang="typescript"
|
||||
defaultOriginal={REVIEW_BEFORE}
|
||||
defaultModified={REVIEW_AFTER}
|
||||
inlineDiff
|
||||
disableAutoInline
|
||||
open
|
||||
/>
|
||||
</div>
|
||||
<h3 class="text-xs font-semibold">Resulting file (Pierre side)</h3>
|
||||
<pre class="h-[160px] overflow-auto border p-2 text-2xs">{liveAfter ?? resultText}</pre>
|
||||
<h3 class="text-xs font-semibold">Events</h3>
|
||||
<ul class="h-[60px] overflow-auto text-2xs text-secondary">
|
||||
{#each log as entry, i (log.length - i)}<li>{entry}</li>{/each}
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
@@ -0,0 +1,84 @@
|
||||
<script lang="ts">
|
||||
import { ScriptService, type ScriptHistory } from '$lib/gen'
|
||||
import Select from '$lib/components/select/Select.svelte'
|
||||
import { workspaceStore } from '$lib/stores'
|
||||
import { scriptLangToEditorLang } from '$lib/scripts'
|
||||
import type { ComparisonCase } from './cases'
|
||||
|
||||
let { onLoaded }: { onLoaded: (c: ComparisonCase) => void } = $props()
|
||||
|
||||
let paths: string[] = $state([])
|
||||
let path: string | undefined = $state()
|
||||
let history: ScriptHistory[] = $state([])
|
||||
let fromHash: string | undefined = $state()
|
||||
let toHash: string | undefined = $state()
|
||||
let error: string | undefined = $state()
|
||||
|
||||
$effect(() => {
|
||||
const workspace = $workspaceStore
|
||||
if (!workspace) return
|
||||
ScriptService.listScriptPaths({ workspace })
|
||||
.then((p) => (paths = p))
|
||||
.catch((e) => (error = e.message))
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const workspace = $workspaceStore
|
||||
if (!workspace || !path) return
|
||||
ScriptService.getScriptHistoryByPath({ workspace, path }).then((h) => {
|
||||
history = h
|
||||
toHash = h[0]?.script_hash
|
||||
fromHash = h[1]?.script_hash ?? h[0]?.script_hash
|
||||
})
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const workspace = $workspaceStore
|
||||
if (!workspace || !path || !fromHash || !toHash) return
|
||||
const p = path
|
||||
Promise.all([
|
||||
ScriptService.getScriptByHash({ workspace, hash: fromHash }),
|
||||
ScriptService.getScriptByHash({ workspace, hash: toHash })
|
||||
]).then(([from, to]) => {
|
||||
onLoaded({
|
||||
id: `workspace:${p}:${from.hash}:${to.hash}`,
|
||||
label: p,
|
||||
filename: p.split('/').pop() ?? p,
|
||||
diff: {
|
||||
lang: scriptLangToEditorLang(to.language),
|
||||
beforeLang: scriptLangToEditorLang(from.language),
|
||||
before: from.content,
|
||||
after: to.content
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const versionItems = $derived(
|
||||
history.map((h) => ({
|
||||
value: h.script_hash,
|
||||
label: `${h.script_hash.slice(0, 8)} ${h.deployment_msg ?? ''}`.trim()
|
||||
}))
|
||||
)
|
||||
</script>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2 text-xs">
|
||||
<span class="text-secondary">Workspace script</span>
|
||||
{#if !$workspaceStore}
|
||||
<span class="text-hint">Log in and pick a workspace to diff real script versions</span>
|
||||
{:else if error}
|
||||
<span class="text-red-600">{error}</span>
|
||||
{:else}
|
||||
<Select
|
||||
size="sm"
|
||||
placeholder="Script path"
|
||||
items={paths.map((p) => ({ value: p, label: p }))}
|
||||
bind:value={path}
|
||||
/>
|
||||
{#if history.length > 0}
|
||||
<Select size="sm" items={versionItems} bind:value={fromHash} />
|
||||
<span class="text-hint">→</span>
|
||||
<Select size="sm" items={versionItems} bind:value={toHash} />
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,270 @@
|
||||
import { parseDiffFromFile, type FileDiffMetadata } from '@pierre/diffs'
|
||||
import type { ToolCodeDiff } from '$lib/components/copilot/chat/shared'
|
||||
import { pierreLang } from '$lib/components/pierre/pierre'
|
||||
|
||||
export type ComparisonCase = {
|
||||
id: string
|
||||
label: string
|
||||
filename: string
|
||||
diff: ToolCodeDiff
|
||||
}
|
||||
|
||||
export function caseFileDiff(c: ComparisonCase): FileDiffMetadata {
|
||||
return parseDiffFromFile(
|
||||
{
|
||||
name: c.filename,
|
||||
contents: c.diff.before,
|
||||
lang: pierreLang(c.diff.beforeLang ?? c.diff.lang)
|
||||
},
|
||||
{ name: c.filename, contents: c.diff.after, lang: pierreLang(c.diff.lang) }
|
||||
)
|
||||
}
|
||||
|
||||
const stableLines = Array.from(
|
||||
{ length: 14 },
|
||||
(_, index) => ` const stableValue${index + 1} = getStableValue(${index + 1})`
|
||||
)
|
||||
|
||||
/** A TypeScript module of `functions` functions, with every `editEvery`th one changed in `after`. */
|
||||
function largeModule(functions: number, editEvery: number): { before: string; after: string } {
|
||||
const before: string[] = []
|
||||
const after: string[] = []
|
||||
for (let i = 0; i < functions; i++) {
|
||||
const body = [
|
||||
`export async function handler${i}(input: { id: string; count: number }) {`,
|
||||
` const result = await fetchRecord(input.id)`,
|
||||
` if (!result.ok) {`,
|
||||
` throw new Error(\`record \${input.id} not found\`)`,
|
||||
` }`,
|
||||
` return { ...result.value, total: input.count * ${i} }`,
|
||||
`}`,
|
||||
``
|
||||
]
|
||||
before.push(...body)
|
||||
if (i % editEvery === 0) {
|
||||
after.push(
|
||||
`export async function handler${i}(input: { id: string; count: number; dryRun?: boolean }) {`,
|
||||
` const result = await fetchRecord(input.id, { cache: true })`,
|
||||
` if (!result.ok || input.dryRun) {`,
|
||||
` return { skipped: true }`,
|
||||
` }`,
|
||||
` return { ...result.value, total: input.count * ${i + 1} }`,
|
||||
`}`,
|
||||
``
|
||||
)
|
||||
} else {
|
||||
after.push(...body)
|
||||
}
|
||||
}
|
||||
return { before: before.join('\n'), after: after.join('\n') }
|
||||
}
|
||||
|
||||
const large = largeModule(1250, 25)
|
||||
|
||||
const longLine = (n: number) =>
|
||||
`const payload = ${JSON.stringify(
|
||||
Object.fromEntries(Array.from({ length: n }, (_, i) => [`field_${i}`, `value number ${i}`]))
|
||||
)}`
|
||||
|
||||
export const cases: ComparisonCase[] = [
|
||||
{
|
||||
id: 'typescript-replacement',
|
||||
label: 'TypeScript replacement',
|
||||
filename: 'greeting.ts',
|
||||
diff: {
|
||||
lang: 'typescript',
|
||||
before: `export function greeting(name: string) {
|
||||
return \`Hello, \${name}\`
|
||||
}`,
|
||||
after: `export function greeting(name: string) {
|
||||
const message = \`Hello, \${name}!\`
|
||||
return message
|
||||
}`
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'long-unchanged-sections',
|
||||
label: 'Long unchanged sections',
|
||||
filename: 'summary.ts',
|
||||
diff: {
|
||||
lang: 'typescript',
|
||||
before: [
|
||||
'export function buildSummary() {',
|
||||
...stableLines,
|
||||
'\treturn formatSummary("draft")',
|
||||
'}'
|
||||
].join('\n'),
|
||||
after: [
|
||||
'export function buildSummary() {',
|
||||
...stableLines,
|
||||
'\treturn formatSummary("published")',
|
||||
'}'
|
||||
].join('\n')
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'json-structure',
|
||||
label: 'JSON structure',
|
||||
filename: 'schedule.json',
|
||||
diff: {
|
||||
lang: 'json',
|
||||
before: `{
|
||||
"name": "daily-report",
|
||||
"schedule": "0 9 * * 1-5",
|
||||
"enabled": false
|
||||
}`,
|
||||
after: `{
|
||||
"name": "daily-report",
|
||||
"schedule": "0 9 * * 1-5",
|
||||
"timezone": "Europe/Paris",
|
||||
"enabled": true
|
||||
}`
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'python-add-remove',
|
||||
label: 'Python additions and removals',
|
||||
filename: 'notify.py',
|
||||
diff: {
|
||||
lang: 'python',
|
||||
before: `def notify(users):
|
||||
for user in users:
|
||||
send_email(user, "Weekly update")
|
||||
|
||||
return len(users)`,
|
||||
after: `def notify(users):
|
||||
active_users = [user for user in users if user.active]
|
||||
for user in active_users:
|
||||
send_email(user, "Your weekly update")
|
||||
|
||||
return len(active_users)`
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'flow-yaml',
|
||||
label: 'Flow YAML',
|
||||
filename: 'flow.yaml',
|
||||
diff: {
|
||||
lang: 'yaml',
|
||||
before: `summary: Sync customers
|
||||
value:
|
||||
modules:
|
||||
- id: a
|
||||
value:
|
||||
type: script
|
||||
path: f/sync/fetch_customers
|
||||
input_transforms:
|
||||
since:
|
||||
type: javascript
|
||||
expr: flow_input.since
|
||||
- id: b
|
||||
value:
|
||||
type: rawscript
|
||||
language: python3
|
||||
content: |
|
||||
def main(rows):
|
||||
return [r for r in rows if r["active"]]
|
||||
schema:
|
||||
properties:
|
||||
since:
|
||||
type: string
|
||||
`,
|
||||
after: `summary: Sync active customers
|
||||
value:
|
||||
modules:
|
||||
- id: a
|
||||
value:
|
||||
type: script
|
||||
path: f/sync/fetch_customers
|
||||
input_transforms:
|
||||
since:
|
||||
type: javascript
|
||||
expr: flow_input.since ?? "2024-01-01"
|
||||
retry:
|
||||
constant:
|
||||
attempts: 3
|
||||
seconds: 10
|
||||
- id: b
|
||||
value:
|
||||
type: rawscript
|
||||
language: python3
|
||||
content: |
|
||||
def main(rows):
|
||||
return [r for r in rows if r["active"] and not r.get("deleted")]
|
||||
schema:
|
||||
properties:
|
||||
since:
|
||||
type: string
|
||||
format: date
|
||||
`
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'long-lines',
|
||||
label: 'Long lines',
|
||||
filename: 'payload.ts',
|
||||
diff: {
|
||||
lang: 'typescript',
|
||||
before: [longLine(40), 'export default payload'].join('\n'),
|
||||
after: [longLine(41), 'export default payload'].join('\n')
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'new-file',
|
||||
label: 'New file',
|
||||
filename: 'new.py',
|
||||
diff: {
|
||||
lang: 'python',
|
||||
before: '',
|
||||
after: `import wmill
|
||||
|
||||
|
||||
def main(name: str = "world"):
|
||||
wmill.set_state({"last": name})
|
||||
return f"Hello {name}"
|
||||
`
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'deleted-file',
|
||||
label: 'Deleted file',
|
||||
filename: 'old.sql',
|
||||
diff: {
|
||||
lang: 'sql',
|
||||
before: `-- $1 email
|
||||
SELECT id, email, created_at
|
||||
FROM users
|
||||
WHERE email = $1
|
||||
ORDER BY created_at DESC;
|
||||
`,
|
||||
after: ''
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'large',
|
||||
label: `Large (${large.before.split('\n').length.toLocaleString()} lines)`,
|
||||
filename: 'handlers.ts',
|
||||
diff: { lang: 'typescript', ...large }
|
||||
}
|
||||
]
|
||||
|
||||
export const MERGE_CONFLICT_SAMPLE = `import * as wmill from 'windmill-client'
|
||||
|
||||
export async function main(customerId: string) {
|
||||
<<<<<<< HEAD
|
||||
const customer = await wmill.getResource('u/admin/crm')
|
||||
return fetchCustomer(customer, customerId, { retries: 3 })
|
||||
=======
|
||||
const crm = await wmill.getResource('f/sales/crm')
|
||||
return fetchCustomer(crm, customerId)
|
||||
>>>>>>> fork/sales-crm
|
||||
}
|
||||
|
||||
function fetchCustomer(resource: unknown, id: string, opts = { retries: 1 }) {
|
||||
<<<<<<< HEAD
|
||||
return { resource, id, opts }
|
||||
=======
|
||||
return { resource, id, opts, source: 'fork' }
|
||||
>>>>>>> fork/sales-crm
|
||||
}
|
||||
`
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { Marker } from '@pierre/diffs/edit'
|
||||
|
||||
type Rule = { pattern: RegExp; severity: Marker['severity']; message: string }
|
||||
|
||||
const RULES: Rule[] = [
|
||||
{ pattern: /(?<![=!])==(?!=)/g, severity: 'error', message: 'Expected === instead of ==.' },
|
||||
{ pattern: /\bvar\b/g, severity: 'warning', message: 'Unexpected var, use let or const.' },
|
||||
{ pattern: /\bconsole\.log\b|\bprint\(/g, severity: 'info', message: 'Debug output left in.' },
|
||||
{ pattern: /\bTODO\b/g, severity: 'hint', message: 'Unresolved TODO.' }
|
||||
]
|
||||
|
||||
/** A stand-in for a language server: enough to show how markers render and re-anchor. */
|
||||
export function lint(code: string): Marker[] {
|
||||
const markers: Marker[] = []
|
||||
code.split('\n').forEach((text, line) => {
|
||||
for (const rule of RULES) {
|
||||
for (const m of text.matchAll(rule.pattern)) {
|
||||
const start = m.index ?? 0
|
||||
markers.push({
|
||||
severity: rule.severity,
|
||||
message: rule.message,
|
||||
source: 'demo-lint',
|
||||
start: { line, character: start },
|
||||
end: { line, character: start + m[0].length }
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
return markers
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/** `querySelector` that also descends into open shadow roots, where Pierre renders its lines. */
|
||||
function findDeep(root: ParentNode, selector: string): Element | null {
|
||||
const direct = root.querySelector(selector)
|
||||
if (direct) return direct
|
||||
for (const el of Array.from(root.querySelectorAll('*'))) {
|
||||
if (el.shadowRoot) {
|
||||
const found = findDeep(el.shadowRoot, selector)
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** Resolves with `performance.now()` at the first frame where `selector` matches under `root`. */
|
||||
export function waitForSelector(
|
||||
root: () => HTMLElement | undefined,
|
||||
selector: string,
|
||||
timeoutMs = 30_000
|
||||
): Promise<number | undefined> {
|
||||
const start = performance.now()
|
||||
return new Promise((resolve) => {
|
||||
const check = () => {
|
||||
const r = root()
|
||||
if (r && findDeep(r, selector)) return resolve(performance.now())
|
||||
if (performance.now() - start > timeoutMs) return resolve(undefined)
|
||||
requestAnimationFrame(check)
|
||||
}
|
||||
check()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums main-thread long tasks (>50ms) until `stop()`. Chromium only; elsewhere the total
|
||||
* stays undefined.
|
||||
*/
|
||||
export function observeLongTasks(): { stop: () => number | undefined } {
|
||||
if (!PerformanceObserver.supportedEntryTypes?.includes('longtask')) {
|
||||
return { stop: () => undefined }
|
||||
}
|
||||
let total = 0
|
||||
const observer = new PerformanceObserver((list) => {
|
||||
for (const entry of list.getEntries()) total += entry.duration
|
||||
})
|
||||
observer.observe({ type: 'longtask' })
|
||||
return {
|
||||
stop: () => {
|
||||
for (const entry of observer.takeRecords()) total += entry.duration
|
||||
observer.disconnect()
|
||||
return total
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Counts DOM nodes under `root`, shadow roots included. */
|
||||
export function countNodes(root: ParentNode): number {
|
||||
let n = 0
|
||||
for (const el of Array.from(root.querySelectorAll('*'))) {
|
||||
n++
|
||||
if (el.shadowRoot) n += countNodes(el.shadowRoot)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
|
||||
|
||||
export function formatMs(ms: number | undefined): string {
|
||||
return ms === undefined ? '–' : `${Math.round(ms)} ms`
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import type { BaseDiffOptions, HighlighterTypes, LineDiffTypes, ThemesType } from '@pierre/diffs'
|
||||
import type { WorkerPoolManager } from '@pierre/diffs/worker'
|
||||
import { pierreWorkerPool } from '$lib/components/pierre/pierre'
|
||||
|
||||
export type PierreSettings = {
|
||||
diffStyle: 'split' | 'unified'
|
||||
diffIndicators: 'bars' | 'classic' | 'none'
|
||||
lineDiffType: LineDiffTypes
|
||||
hunkSeparators: 'line-info' | 'line-info-basic' | 'metadata' | 'simple'
|
||||
wrap: boolean
|
||||
disableBackground: boolean
|
||||
disableLineNumbers: boolean
|
||||
expandUnchanged: boolean
|
||||
highlighter: HighlighterTypes
|
||||
useWorkers: boolean
|
||||
theme: string
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: PierreSettings = {
|
||||
diffStyle: 'unified',
|
||||
diffIndicators: 'bars',
|
||||
lineDiffType: 'word-alt',
|
||||
hunkSeparators: 'line-info',
|
||||
wrap: false,
|
||||
disableBackground: false,
|
||||
disableLineNumbers: false,
|
||||
expandUnchanged: false,
|
||||
highlighter: 'shiki-js',
|
||||
useWorkers: false,
|
||||
theme: 'pierre'
|
||||
}
|
||||
|
||||
export const THEMES: Record<string, ThemesType> = {
|
||||
pierre: { light: 'pierre-light', dark: 'pierre-dark' },
|
||||
github: { light: 'github-light', dark: 'github-dark' },
|
||||
vitesse: { light: 'vitesse-light', dark: 'vitesse-dark' },
|
||||
one: { light: 'one-light', dark: 'one-dark-pro' },
|
||||
catppuccin: { light: 'catppuccin-latte', dark: 'catppuccin-mocha' }
|
||||
}
|
||||
|
||||
/** The options `FileDiff` and `CodeView` share. */
|
||||
export function diffOptions(
|
||||
s: PierreSettings
|
||||
): BaseDiffOptions & { hunkSeparators: PierreSettings['hunkSeparators'] } {
|
||||
return {
|
||||
theme: THEMES[s.theme],
|
||||
diffStyle: s.diffStyle,
|
||||
diffIndicators: s.diffIndicators,
|
||||
lineDiffType: s.lineDiffType,
|
||||
hunkSeparators: s.hunkSeparators,
|
||||
overflow: s.wrap ? 'wrap' : 'scroll',
|
||||
disableBackground: s.disableBackground,
|
||||
disableLineNumbers: s.disableLineNumbers,
|
||||
expandUnchanged: s.expandUnchanged,
|
||||
preferredHighlighter: s.highlighter
|
||||
}
|
||||
}
|
||||
|
||||
/** Theme and inline-diff granularity belong to the pool when one is used, not to the component. */
|
||||
export function settingsPool(s: PierreSettings): WorkerPoolManager | undefined {
|
||||
if (!s.useWorkers) return undefined
|
||||
const pool = pierreWorkerPool(s.highlighter)
|
||||
void pool.setRenderOptions({ theme: THEMES[s.theme], lineDiffType: s.lineDiffType })
|
||||
return pool
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
// Four changes far enough apart to land in separate hunks, plus two blocks in one hunk.
|
||||
export const REVIEW_BEFORE = `import * as wmill from 'windmill-client'
|
||||
|
||||
type Invoice = {
|
||||
id: string
|
||||
amount: number
|
||||
currency: string
|
||||
paid: boolean
|
||||
}
|
||||
|
||||
export async function main(customerId: string) {
|
||||
var invoices = await listInvoices(customerId)
|
||||
const unpaid = invoices.filter((i) => i.paid == false)
|
||||
|
||||
let total = 0
|
||||
for (const invoice of unpaid) {
|
||||
total += invoice.amount
|
||||
}
|
||||
|
||||
console.log('unpaid total', total)
|
||||
return { customerId, total, count: unpaid.length }
|
||||
}
|
||||
|
||||
async function listInvoices(customerId: string): Promise<Invoice[]> {
|
||||
const stripe = await wmill.getResource('u/admin/stripe')
|
||||
const response = await fetch(\`https://api.stripe.com/v1/invoices?customer=\${customerId}\`, {
|
||||
headers: { Authorization: \`Bearer \${stripe.token}\` }
|
||||
})
|
||||
const body = await response.json()
|
||||
return body.data.map(toInvoice)
|
||||
}
|
||||
|
||||
function toInvoice(raw: any): Invoice {
|
||||
return {
|
||||
id: raw.id,
|
||||
amount: raw.amount_due,
|
||||
currency: raw.currency,
|
||||
paid: raw.paid
|
||||
}
|
||||
}
|
||||
|
||||
export function formatAmount(invoice: Invoice) {
|
||||
return invoice.amount / 100 + ' ' + invoice.currency
|
||||
}
|
||||
`
|
||||
|
||||
export const REVIEW_AFTER = `import * as wmill from 'windmill-client'
|
||||
|
||||
type Invoice = {
|
||||
id: string
|
||||
amount: number
|
||||
currency: string
|
||||
paid: boolean
|
||||
dueDate: Date
|
||||
}
|
||||
|
||||
export async function main(customerId: string, overdueOnly = false) {
|
||||
const invoices = await listInvoices(customerId)
|
||||
const now = new Date()
|
||||
const unpaid = invoices.filter((i) => !i.paid && (!overdueOnly || i.dueDate < now))
|
||||
|
||||
const total = unpaid.reduce((sum, invoice) => sum + invoice.amount, 0)
|
||||
|
||||
return { customerId, total, count: unpaid.length }
|
||||
}
|
||||
|
||||
async function listInvoices(customerId: string): Promise<Invoice[]> {
|
||||
const stripe = await wmill.getResource('f/billing/stripe')
|
||||
const response = await fetch(\`https://api.stripe.com/v1/invoices?customer=\${customerId}\`, {
|
||||
headers: { Authorization: \`Bearer \${stripe.token}\` }
|
||||
})
|
||||
if (!response.ok) {
|
||||
throw new Error(\`Stripe returned \${response.status}\`)
|
||||
}
|
||||
const body = await response.json()
|
||||
return body.data.map(toInvoice)
|
||||
}
|
||||
|
||||
function toInvoice(raw: any): Invoice {
|
||||
return {
|
||||
id: raw.id,
|
||||
amount: raw.amount_due,
|
||||
currency: raw.currency,
|
||||
paid: raw.paid,
|
||||
dueDate: new Date(raw.due_date * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
export function formatAmount(invoice: Invoice) {
|
||||
return new Intl.NumberFormat('en', { style: 'currency', currency: invoice.currency }).format(
|
||||
invoice.amount / 100
|
||||
)
|
||||
}
|
||||
`
|
||||
Reference in New Issue
Block a user