Expose py-editor code content read/write (#2087)

* Expose py-editor code content read/write

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andrea Giammarchi
2024-06-03 12:32:54 +02:00
committed by GitHub
parent cb9ee6f7e2
commit 2ac5ca79d7
3 changed files with 85 additions and 67 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@pyscript/core",
"version": "0.4.40",
"version": "0.4.41",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@pyscript/core",
"version": "0.4.40",
"version": "0.4.41",
"license": "APACHE-2.0",
"dependencies": {
"@ungap/with-resolvers": "^0.1.0",
@@ -29,10 +29,10 @@
"@webreflection/toml-j0.4": "^1.1.3",
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-web-links": "^0.11.0",
"bun": "^1.1.10",
"bun": "^1.1.12",
"chokidar": "^3.6.0",
"codemirror": "^6.0.1",
"eslint": "^9.3.0",
"eslint": "^9.4.0",
"rollup": "^4.18.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0",
@@ -185,6 +185,21 @@
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
}
},
"node_modules/@eslint/config-array": {
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.15.1.tgz",
"integrity": "sha512-K4gzNq+yymn/EVsXYmf+SBcBro8MTf+aXJZUphM96CdzUEr+ClGDvAbpmaEK+cGVigVXIgs9gNmvHAlrzzY5JQ==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"@eslint/object-schema": "^2.1.3",
"debug": "^4.3.1",
"minimatch": "^3.0.5"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
},
"node_modules/@eslint/eslintrc": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz",
@@ -210,28 +225,23 @@
}
},
"node_modules/@eslint/js": {
"version": "9.3.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.3.0.tgz",
"integrity": "sha512-niBqk8iwv96+yuTwjM6bWg8ovzAPF9qkICsGtcoa5/dmqcEMfdwNAX7+/OHcJHc7wj7XqPxH98oAHytFYlw6Sw==",
"version": "9.4.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.4.0.tgz",
"integrity": "sha512-fdI7VJjP3Rvc70lC4xkFXHB0fiPeojiL1PxVG6t1ZvXQrarj893PweuBTujxDUFk0Fxj4R7PIIAZ/aiiyZPZcg==",
"dev": true,
"license": "MIT",
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
},
"node_modules/@humanwhocodes/config-array": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz",
"integrity": "sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==",
"node_modules/@eslint/object-schema": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.3.tgz",
"integrity": "sha512-HAbhAYKfsAC2EkTqve00ibWIZlaU74Z1EHwAjYr4PXF0YU2VEA1zSIKSSpKszRLRWwHzzRZXvK632u+uXzvsvw==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"@humanwhocodes/object-schema": "^2.0.3",
"debug": "^4.3.1",
"minimatch": "^3.0.5"
},
"engines": {
"node": ">=10.10.0"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
},
"node_modules/@humanwhocodes/module-importer": {
@@ -248,13 +258,6 @@
"url": "https://github.com/sponsors/nzakas"
}
},
"node_modules/@humanwhocodes/object-schema": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz",
"integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@humanwhocodes/retry": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.0.tgz",
@@ -411,9 +414,9 @@
}
},
"node_modules/@oven/bun-darwin-aarch64": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.1.10.tgz",
"integrity": "sha512-5x6QGEzTurmCPZM3OLosIJE0QynhKfKZZ6uSVl7C36mNPFAZfTXjK64LgbM+4P9Kr0PyEQnZweLlScl+HaEJcw==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.1.12.tgz",
"integrity": "sha512-g8nmDXIYDmbEnP6moX3ZTS5BsikX8dz/XB0PAfL+LEBJEGECyor2Hv1yvhGQfeR1/lvfSXsWnk0Hhk9Mrj6uoQ==",
"cpu": [
"arm64"
],
@@ -425,9 +428,9 @@
]
},
"node_modules/@oven/bun-darwin-x64": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.1.10.tgz",
"integrity": "sha512-DYbp2koaATwWikMIyeWLq2LhLZtvxzr4WuFIBe4+KwoWLGXJEC8uK9QsTwis/tCLPH45ov9DMwDmBA31oX+0iA==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.1.12.tgz",
"integrity": "sha512-XWL6atcLxyh4KgOlqqyHUOh4Ylm46CExipJmAdKs30gyYqbw3E+HTFhADsyFEtugOe0qPUNlo0aMo+ZMc1yIQA==",
"cpu": [
"x64"
],
@@ -439,9 +442,9 @@
]
},
"node_modules/@oven/bun-darwin-x64-baseline": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64-baseline/-/bun-darwin-x64-baseline-1.1.10.tgz",
"integrity": "sha512-a/P612tHH86gpBiITwHmrpFMLT9Z/v6VxBKpPK+FgejIgLDGvzfIOxbNtBeGygWbZaAFDQfRRQJFGpVHvjwGQA==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64-baseline/-/bun-darwin-x64-baseline-1.1.12.tgz",
"integrity": "sha512-KXBwaeD9y4GuxSqC1uDNIktTC/jY2DtagiURuUOF1rniYxkkLRNgXotTvVA5NvP2PBCoWyrxZ67WJSBm0AIyjQ==",
"cpu": [
"x64"
],
@@ -453,9 +456,9 @@
]
},
"node_modules/@oven/bun-linux-aarch64": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.1.10.tgz",
"integrity": "sha512-iR7TRUWtVtrPe+iZu1ISQNbz7M6HxMRtn4PCr/a6dswuPkIhvXxTJUD6WTpHnHxsgioS5GHG9eonu03PTeBY0Q==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.1.12.tgz",
"integrity": "sha512-6Jen4+b5BzInF7bbRjMIWoy3xIuK/kQQn9xehvrAYnr3J9p3vCD5VhzDP20hW9yQcmZtO2kE6pIYCbaaxPNKtg==",
"cpu": [
"arm64"
],
@@ -467,9 +470,9 @@
]
},
"node_modules/@oven/bun-linux-x64": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.1.10.tgz",
"integrity": "sha512-pUgLdu/5Yn+hV8aIwZE0x2H/t2QQRIPWUibnUdDLglnNtGjaqNUyST9iVN5TD7NdMk1p342GDc9rouA8VxAHHA==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.1.12.tgz",
"integrity": "sha512-X4dqnIOv4M9HAL4tAj9bb14WjsfKby5xWNV/otUxtfSDsDrV2ukYUekivEmHqchxHFUHOHyc/cv+/jtfvedDZg==",
"cpu": [
"x64"
],
@@ -481,9 +484,9 @@
]
},
"node_modules/@oven/bun-linux-x64-baseline": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-baseline/-/bun-linux-x64-baseline-1.1.10.tgz",
"integrity": "sha512-TjBH/KIyI/4Ms3PJYRm2QEgI7HOyV5fXdwqwB/40SCPXND6wq0u4voHDIINc9rdHDRXpmO8RPUFWsKNuN3Mf5w==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-baseline/-/bun-linux-x64-baseline-1.1.12.tgz",
"integrity": "sha512-luwWf/QGMJ23+yIRBMDnhjYuxh9zXy+Vw4lAzwvLB7phYXCs7IPEhIhZxhcZQ3XMafWtHlWAVo5P6NZZdFRMUQ==",
"cpu": [
"x64"
],
@@ -495,9 +498,9 @@
]
},
"node_modules/@oven/bun-windows-x64": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.1.10.tgz",
"integrity": "sha512-+KiITh1xyrDGoRXM3HLHyO9iweaMZ9T41KP4cbov92D78SKxR5jpq1LDLPhWK668a0aNX/r9PGePkPNt4yg/HA==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.1.12.tgz",
"integrity": "sha512-ufvTeXXI9tJSJUhvdPnFUmGqCNBKBazEwjvQ5c8vhtZ8hdBHV54LoURVDIBYCgzfdv5NQT3sr8qRLFqy4mlMLg==",
"cpu": [
"x64"
],
@@ -509,9 +512,9 @@
]
},
"node_modules/@oven/bun-windows-x64-baseline": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64-baseline/-/bun-windows-x64-baseline-1.1.10.tgz",
"integrity": "sha512-+q2pDLq9VCXYJ89pcT5AevXUTGdDoqgq+scE3qlKLclSxtSR25K18C61D9rpqgiueC6jLrxIN13w5qOi4B3LfQ==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64-baseline/-/bun-windows-x64-baseline-1.1.12.tgz",
"integrity": "sha512-MRn+zcJO1hcVqwJmFxpUSdb6ZvrYC8Xp2N1fPOzdw3YSskz9iHkJuUKzx7s9iCC7jTpo6XI/H51EFr/M2U7Ipg==",
"cpu": [
"x64"
],
@@ -1134,9 +1137,9 @@
}
},
"node_modules/bun": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/bun/-/bun-1.1.10.tgz",
"integrity": "sha512-qOJXrQZSzJ5DbJMt47GZGWtUSmIkbwD7fPSN/XS/T46D4cTTnPK46QDHlyC8VD+Anvs6uKNwuwKIyB31kUdHmQ==",
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/bun/-/bun-1.1.12.tgz",
"integrity": "sha512-NZzeZuZk7VwCs8VAXnXUHCPOlTS/IyHCscChtT1M1FLSwhBcVMsGVStYlXaaoqsinBKgp0CGJdhnJw2gR3NkDw==",
"cpu": [
"arm64",
"x64"
@@ -1154,14 +1157,14 @@
"bunx": "bin/bun.exe"
},
"optionalDependencies": {
"@oven/bun-darwin-aarch64": "1.1.10",
"@oven/bun-darwin-x64": "1.1.10",
"@oven/bun-darwin-x64-baseline": "1.1.10",
"@oven/bun-linux-aarch64": "1.1.10",
"@oven/bun-linux-x64": "1.1.10",
"@oven/bun-linux-x64-baseline": "1.1.10",
"@oven/bun-windows-x64": "1.1.10",
"@oven/bun-windows-x64-baseline": "1.1.10"
"@oven/bun-darwin-aarch64": "1.1.12",
"@oven/bun-darwin-x64": "1.1.12",
"@oven/bun-darwin-x64-baseline": "1.1.12",
"@oven/bun-linux-aarch64": "1.1.12",
"@oven/bun-linux-x64": "1.1.12",
"@oven/bun-linux-x64-baseline": "1.1.12",
"@oven/bun-windows-x64": "1.1.12",
"@oven/bun-windows-x64-baseline": "1.1.12"
}
},
"node_modules/callsites": {
@@ -1677,17 +1680,17 @@
}
},
"node_modules/eslint": {
"version": "9.3.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-9.3.0.tgz",
"integrity": "sha512-5Iv4CsZW030lpUqHBapdPo3MJetAPtejVW8B84GIcIIv8+ohFaddXsrn1Gn8uD9ijDb+kcYKFUVmC8qG8B2ORQ==",
"version": "9.4.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-9.4.0.tgz",
"integrity": "sha512-sjc7Y8cUD1IlwYcTS9qPSvGjAC8Ne9LctpxKKu3x/1IC9bnOg98Zy6GxEJUfr1NojMgVPlyANXYns8oE2c1TAA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1",
"@eslint/config-array": "^0.15.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "9.3.0",
"@humanwhocodes/config-array": "^0.13.0",
"@eslint/js": "9.4.0",
"@humanwhocodes/module-importer": "^1.0.1",
"@humanwhocodes/retry": "^0.3.0",
"@nodelib/fs.walk": "^1.2.8",

View File

@@ -1,6 +1,6 @@
{
"name": "@pyscript/core",
"version": "0.4.40",
"version": "0.4.41",
"type": "module",
"description": "PyScript",
"module": "./index.js",
@@ -61,10 +61,10 @@
"@webreflection/toml-j0.4": "^1.1.3",
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-web-links": "^0.11.0",
"bun": "^1.1.10",
"bun": "^1.1.12",
"chokidar": "^3.6.0",
"codemirror": "^6.0.1",
"eslint": "^9.3.0",
"eslint": "^9.4.0",
"rollup": "^4.18.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0",

View File

@@ -184,6 +184,21 @@ const init = async (script, type, interpreter) => {
let target;
defineProperties(script, {
target: { get: () => target },
code: {
get: () => context.pySrc,
set: (insert) => {
if (isSetup) return;
editor.update([
editor.state.update({
changes: {
from: 0,
to: editor.state.doc.length,
insert,
},
}),
]);
},
},
process: {
/**
* Simulate a setup node overriding the source to evaluate.