From ef5f0b1e4d18d5fda77c09bb086834f7497e16c0 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Wed, 24 Sep 2025 08:42:46 +0200 Subject: [PATCH 01/19] le nouveau code --- .husky/post-checkout | 12 ++ .husky/pre-commit | 15 ++ demo/minimalist.html | 2 +- package-lock.json | 183 +++++++++--------- package.json | 50 +++-- packages/o-spreadsheet-engine/package.json | 74 +++++++ .../o-spreadsheet-engine/rollup.config.js | 77 ++++++++ .../o-spreadsheet-engine/src/helpers/uuid.ts | 50 +++++ packages/o-spreadsheet-engine/src/index.ts | 1 + .../o-spreadsheet-engine/tests/index.test.ts | 5 + .../o-spreadsheet-engine/tsconfig.jest.json | 7 + packages/o-spreadsheet-engine/tsconfig.json | 8 + rollup.config.js | 44 ++++- src/helpers/uuid.ts | 51 +---- src/index.ts | 2 + tsconfig.jest.json | 3 +- tsconfig.json | 5 +- 17 files changed, 422 insertions(+), 167 deletions(-) create mode 100644 packages/o-spreadsheet-engine/package.json create mode 100644 packages/o-spreadsheet-engine/rollup.config.js create mode 100644 packages/o-spreadsheet-engine/src/helpers/uuid.ts create mode 100644 packages/o-spreadsheet-engine/src/index.ts create mode 100644 packages/o-spreadsheet-engine/tests/index.test.ts create mode 100644 packages/o-spreadsheet-engine/tsconfig.jest.json create mode 100644 packages/o-spreadsheet-engine/tsconfig.json diff --git a/.husky/post-checkout b/.husky/post-checkout index 06336fb057..d53af76677 100755 --- a/.husky/post-checkout +++ b/.husky/post-checkout @@ -6,3 +6,15 @@ if [ "$HUSKY_POST_CHECKOUT" != 0 ]; then npm install >/dev/null 2>&1 fi fi + +if [ ! -d "build/js/src" ]; then + if [ -d "build" ]; then + if [ "$OSTYPE" = "msys" ]; then + # Windows (Git Bash/MSYS) + cmd.exe /C "rmdir /s /q build" + else + # POSIX + rm -rf build + fi + fi +fi diff --git a/.husky/pre-commit b/.husky/pre-commit index f9b68dec5b..7aa2a09d54 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -37,4 +37,19 @@ if [ "$HUSKY_PRE_COMMIT" != 0 ]; then # Css wrap check node .husky/css_check.js + + # Check that all package.json versions are the same as the root + root_version=$(node -p "require('./package.json').version") + mismatch=0 + for pkg in $(find packages -name package.json); do + pkg_version=$(node -p "require('./$pkg').version") + if [ "$pkg_version" != "$root_version" ]; then + echo "Version mismatch: $pkg ($pkg_version) != root ($root_version)" + mismatch=1 + fi + done + if [ $mismatch -ne 0 ]; then + echo "❌ All package.json versions must match the root version." + exit 1 + fi fi diff --git a/demo/minimalist.html b/demo/minimalist.html index 22acc6f821..113213e051 100644 --- a/demo/minimalist.html +++ b/demo/minimalist.html @@ -24,7 +24,7 @@ - + diff --git a/package-lock.json b/package-lock.json index f10a83c331..3bec71a72f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,11 @@ "name": "@odoo/o-spreadsheet", "version": "19.1.0-alpha.3", "license": "LGPL-3.0-or-later", + "workspaces": [ + "packages/o-spreadsheet-engine" + ], "dependencies": { + "@odoo/o-spreadsheet-engine": "*", "@odoo/owl": "2.5.1", "bootstrap": "^5.3.3", "font-awesome": "^4.7.0", @@ -16,6 +20,7 @@ }, "devDependencies": { "@prettier/plugin-xml": "^2.2.0", + "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-node-resolve": "^15.2.0", "@rollup/plugin-terser": "^0.4.3", "@swc/core": "1.6.7", @@ -1098,11 +1103,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@jest/core/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/@jest/core/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -1356,11 +1356,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/@jest/reporters/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/@jest/reporters/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -1417,11 +1412,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/source-map/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/@jest/test-result": { "version": "29.6.1", "dev": true, @@ -1450,11 +1440,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/@jest/test-sequencer/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/@jest/transform": { "version": "29.6.1", "dev": true, @@ -1530,11 +1515,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@jest/transform/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/@jest/transform/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -1735,6 +1715,10 @@ "node": ">= 8" } }, + "node_modules/@odoo/o-spreadsheet-engine": { + "resolved": "packages/o-spreadsheet-engine", + "link": true + }, "node_modules/@odoo/owl": { "version": "2.5.1", "resolved": "https://registry.npmjs.org/@odoo/owl/-/owl-2.5.1.tgz", @@ -1748,6 +1732,7 @@ "version": "2.11.8", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==", + "license": "MIT", "peer": true, "funding": { "type": "opencollective", @@ -1764,6 +1749,24 @@ "prettier": ">=2.4.0" } }, + "node_modules/@rollup/plugin-alias": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-alias/-/plugin-alias-5.1.1.tgz", + "integrity": "sha512-PR9zDb+rOzkRb2VD+EuKB7UC41vU5DIwZ5qqCpk0KJudcWAyi8rvYOhS7+L5aZCspw1stTViLgN5v6FF1p5cgQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/plugin-node-resolve": { "version": "15.2.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.0.tgz", @@ -2871,11 +2874,6 @@ "dev": true, "license": "MIT" }, - "node_modules/babel-jest/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/babel-jest/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -3115,9 +3113,9 @@ "license": "MIT" }, "node_modules/bootstrap": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.3.tgz", - "integrity": "sha512-8HLCdWgyoMguSO9o+aH+iuZ+aht+mzW0u3HIMzVu7Srrpv7EBBxTnrFlSCskwdY1+EOFQSm7uMJhNQHkdPcmjg==", + "version": "5.3.8", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.8.tgz", + "integrity": "sha512-HP1SZDqaLDPwsNiqRqi5NcP0SSXciX2s9E+RyqJIIqGo+vJeN5AJVM98CXmW/Wux0nQ5L7jeWUdplCEf0Ee+tg==", "funding": [ { "type": "github", @@ -3128,6 +3126,7 @@ "url": "https://opencollective.com/bootstrap" } ], + "license": "MIT", "peerDependencies": { "@popperjs/core": "^2.11.8" } @@ -5266,6 +5265,7 @@ "version": "4.7.0", "resolved": "https://registry.npmjs.org/font-awesome/-/font-awesome-4.7.0.tgz", "integrity": "sha512-U6kGnykA/6bFmg1M/oT9EkFeIYv7JlX3bozwQJWiiLz6L0w3F5vBVPxHlwyX/vtNq1ckcpRKOB9f2Qal/VtFpg==", + "license": "(OFL-1.1 AND MIT)", "engines": { "node": ">=0.10.3" } @@ -5429,11 +5429,6 @@ "node": ">=10" } }, - "node_modules/fs-extra/node_modules/graceful-fs": { - "version": "4.2.10", - "dev": true, - "license": "ISC" - }, "node_modules/fs-extra/node_modules/universalify": { "version": "2.0.0", "dev": true, @@ -5605,7 +5600,9 @@ } }, "node_modules/graceful-fs": { - "version": "4.1.15", + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true, "license": "ISC" }, @@ -6651,11 +6648,6 @@ "dev": true, "license": "MIT" }, - "node_modules/jest-cli/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-cli/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -6786,11 +6778,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/jest-config/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-config/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -7143,11 +7130,6 @@ "fsevents": "^2.3.2" } }, - "node_modules/jest-haste-map/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-leak-detector": { "version": "29.6.1", "dev": true, @@ -7398,11 +7380,6 @@ "dev": true, "license": "MIT" }, - "node_modules/jest-message-util/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-message-util/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -7564,11 +7541,6 @@ "dev": true, "license": "MIT" }, - "node_modules/jest-resolve/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-resolve/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -7664,11 +7636,6 @@ "dev": true, "license": "MIT" }, - "node_modules/jest-runner/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-runner/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -7816,11 +7783,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/jest-runtime/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-runtime/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -7924,11 +7886,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-snapshot/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-snapshot/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -8074,11 +8031,6 @@ "dev": true, "license": "MIT" }, - "node_modules/jest-util/node_modules/graceful-fs": { - "version": "4.2.11", - "dev": true, - "license": "ISC" - }, "node_modules/jest-util/node_modules/has-flag": { "version": "4.0.0", "dev": true, @@ -10132,7 +10084,8 @@ "node_modules/quickselect": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/quickselect/-/quickselect-2.0.0.tgz", - "integrity": "sha512-RKJ22hX8mHe3Y6wH/N3wCM6BWtjaxIyyUIkpHOvfFnxdI4yD4tBXEBKSbriGujF6jnSVkJrffuo6vxACiSSxIw==" + "integrity": "sha512-RKJ22hX8mHe3Y6wH/N3wCM6BWtjaxIyyUIkpHOvfFnxdI4yD4tBXEBKSbriGujF6jnSVkJrffuo6vxACiSSxIw==", + "license": "ISC" }, "node_modules/random-bytes": { "version": "1.0.0", @@ -10176,6 +10129,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/rbush/-/rbush-3.0.1.tgz", "integrity": "sha512-XRaVO0YecOpEuIvbhbpTrZgoiI6xBlz6hnlr6EHhd+0x9ase6EmeN+hdwwUaJvLcsFFQ8iWVF1GAK1yB0BWi0w==", + "license": "MIT", "dependencies": { "quickselect": "^2.0.0" } @@ -10581,11 +10535,6 @@ "node": ">=12" } }, - "node_modules/rollup-plugin-typescript2/node_modules/graceful-fs": { - "version": "4.2.10", - "dev": true, - "license": "ISC" - }, "node_modules/rollup-plugin-typescript2/node_modules/semver": { "version": "7.3.8", "dev": true, @@ -12325,6 +12274,60 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "packages/o-spreadsheet": { + "extraneous": true + }, + "packages/o-spreadsheet-engine": { + "name": "@odoo/o-spreadsheet-engine", + "version": "19.1.0-alpha.3", + "dependencies": { + "rbush": "^3.0.1" + }, + "devDependencies": { + "@prettier/plugin-xml": "^2.2.0", + "@rollup/plugin-alias": "^5.1.1", + "@rollup/plugin-node-resolve": "^15.2.0", + "@rollup/plugin-terser": "^0.4.3", + "@swc/core": "1.6.7", + "@swc/jest": "0.2.36", + "@types/jest": "^27.0.1", + "@types/node": "^20.17.24", + "@types/rbush": "^3.0.3", + "@typescript-eslint/eslint-plugin": "^8.30.1", + "babel-eslint": "^10.1.0", + "fs": "^0.0.1-security", + "glob": "^11.0.1", + "husky": "^7.0.4", + "jest": "^29.5.0", + "jest-environment-jsdom": "^29.5.0", + "mockdate": "^3.0.2", + "npm-run-all": "^4.1.5", + "prettier": "^2.8.0", + "prettier-plugin-organize-imports": "^3.2.2", + "rollup": "^3.28.0", + "rollup-plugin-dts": "^5.3.1", + "rollup-plugin-typescript2": "^0.35.0", + "seedrandom": "^3.0.5", + "typescript": "^5.8.2", + "typescript-eslint": "^8.30.1", + "xml-formatter": "^2.4.0" + }, + "engines": { + "node": ">=22.0.0" + } + }, + "packages/o-spreadsheet-ui": { + "name": "@odoo/o-spreadsheet-ui", + "version": "19.1.0-alpha.3", + "extraneous": true, + "dependencies": { + "@odoo/o-spreadsheet-engine": "*", + "@odoo/owl": "2.5.1", + "bootstrap": "^5.3.3", + "font-awesome": "^4.7.0", + "rbush": "^3.0.1" + } } } } diff --git a/package.json b/package.json index 1d898a5b28..f46a0ea6f7 100644 --- a/package.json +++ b/package.json @@ -15,31 +15,38 @@ "engines": { "node": ">=22.0.0" }, + "workspaces": [ + "packages/o-spreadsheet-engine" + ], "scripts": { - "serve-static": "live-server --open=demo --watch=build/o_spreadsheet.iife.js,build/o_spreadsheet.xml,build/o_spreadsheet.css,main.css,demo", - "dev": "npm-run-all --print-label bundle:dev --parallel server serve-static watch", - "server": "node tools/server/main.cjs", + "prepare": "husky install", + "prettier": "prettier . --write", + "check-formatting": "prettier . --check && eslint", + "lint": "eslint --fix", + "dev": "npm-run-all --print-label build --parallel build:watch:engine build:watch server serve-static", + "prebuild": "npm run build --workspaces --if-present", + "build": "npm-run-all build:js bundle:esm bundle:iife \"bundle:xml -- --outDir build\" \"bundle:css -- --out build\"", + "build:watch": "npm-run-all --parallel build:watch:engine build:js:watch bundle:iife:watch bundle:xml:watch bundle:css:watch", + "build:watch:engine": "npm run build:watch --workspace=@odoo/o-spreadsheet-engine", "build:js": "tsc --module es6 --incremental", + "build:js:watch": "npm run build:js -- --watch", "bundle:iife": "rollup -c -m -- --format iife", + "bundle:iife:watch": "npm run bundle:iife -- --watch", "bundle:esm": "rollup -c -m -- --format esm", "bundle:xml": "node tools/bundle_xml/main.cjs", - "bundle:dev": "npm-run-all build:js bundle:iife \"bundle:xml -- --outDir build\" && node tools/bundle_css/main.cjs --out build", - "dist": "tsc --module es6 --declaration --declarationDir dist/types && rollup -c && npm run bundle:xml -- --outDir dist && node tools/bundle_css/main.cjs --out dist", - "monkey": "SPREADSHEET_MONKEY_COUNT=$npm_config_monkey_count jest 'tests/collaborative/collaborative_monkey_party.test.ts'", + "bundle:xml:watch": "node tools/bundle_xml/watch_xml_templates.cjs", + "bundle:css": "node tools/bundle_css/main.cjs", + "bundle:css:watch": "node tools/bundle_css/watch_css_files.cjs", + "serve-static": "live-server --open=demo --watch=build/o-spreadsheet.iife.js,build/o_spreadsheet.xml,build/o_spreadsheet.css,demo", + "server": "node tools/server/main.cjs", + "predist": "npm run dist --workspaces --if-present", + "dist": "tsc --module es6 --declaration --declarationDir dist/types && rollup -c", + "postdist": " npm run bundle:xml -- --outDir dist && npm run bundle:css -- --out dist", + "pretest": "npm run test --workspaces --if-present", "test": "tsc --noEmit --project tsconfig.jest.json && jest", - "test:watch": "jest --watch", - "prettier": "prettier . --write", - "check-formatting": "prettier . --check && eslint", - "prepare": "husky install", - "watch": "npm-run-all -p watch:*", - "watch:bundle": "npm run bundle:iife -- --watch", - "watch:ts": "npm run build:js -- --watch", - "watch:xml": "node tools/bundle_xml/watch_xml_templates.cjs", - "watch:css": "node tools/bundle_css/watch_css_files.cjs", - "unzipXlsx": "node tools/bundle_xlsx/unzip_xlsx_demo.cjs", + "monkey": "SPREADSHEET_MONKEY_COUNT=$npm_config_monkey_count jest 'tests/collaborative/collaborative_monkey_party.test.ts'", "zipXlsx": "node tools/bundle_xlsx/zip_xlsx_demo.cjs", - "build": "npm-run-all build:js bundle:esm \"bundle:xml -- --outDir build\" && node tools/bundle_css/main.cjs --out build", - "lint": "eslint --fix" + "unzipXlsx": "node tools/bundle_xlsx/unzip_xlsx_demo.cjs" }, "browserslist": [ "last 1 Chrome versions" @@ -62,6 +69,7 @@ "homepage": "https://github.com/odoo/o-spreadsheet#readme", "devDependencies": { "@prettier/plugin-xml": "^2.2.0", + "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-node-resolve": "^15.2.0", "@rollup/plugin-terser": "^0.4.3", "@swc/jest": "0.2.36", @@ -125,7 +133,8 @@ "@odoo/owl": "2.5.1", "bootstrap": "^5.3.3", "font-awesome": "^4.7.0", - "rbush": "^3.0.1" + "rbush": "^3.0.1", + "@odoo/o-spreadsheet-engine": "*" }, "jest": { "roots": [ @@ -137,6 +146,9 @@ "@swc/jest" ] }, + "moduleNameMapper": { + "^@odoo/o-spreadsheet-engine$": "/packages/o-spreadsheet-engine/src" + }, "verbose": false, "testEnvironment": "jsdom", "testRegex": "(/tests/.*(test|spec))\\.ts?$", diff --git a/packages/o-spreadsheet-engine/package.json b/packages/o-spreadsheet-engine/package.json new file mode 100644 index 0000000000..8b251e0442 --- /dev/null +++ b/packages/o-spreadsheet-engine/package.json @@ -0,0 +1,74 @@ +{ + "name": "@odoo/o-spreadsheet-engine", + "version": "19.1.0-alpha.3", + "type": "module", + "scripts": { + "build": "npm-run-all build:js bundle:iife", + "build:watch": "npm-run-all --parallel build:js:watch bundle:iife:watch", + "build:js": "tsc --module es6 --incremental", + "build:js:watch": "npm run build:js -- --watch", + "bundle:esm": "rollup -c -m -- --format esm", + "bundle:iife": "rollup -c -m -- --format iife", + "bundle:iife:watch": "npm run bundle:iife -- --watch", + "dist": "tsc --module es6 --declaration --declarationDir ../../dist/types/packages/o-spreadsheet-engine/ && rollup -c", + "test": "tsc --noEmit --project tsconfig.jest.json && jest" + }, + "engines": { + "node": ">=22.0.0" + }, + "dependencies": { + "rbush": "^3.0.1" + }, + "devDependencies": { + "@prettier/plugin-xml": "^2.2.0", + "@rollup/plugin-alias": "^5.1.1", + "@rollup/plugin-node-resolve": "^15.2.0", + "@rollup/plugin-terser": "^0.4.3", + "@swc/core": "1.6.7", + "@swc/jest": "0.2.36", + "@types/jest": "^27.0.1", + "@types/node": "^20.17.24", + "@types/rbush": "^3.0.3", + "@typescript-eslint/eslint-plugin": "^8.30.1", + "babel-eslint": "^10.1.0", + "fs": "^0.0.1-security", + "glob": "^11.0.1", + "husky": "^7.0.4", + "jest": "^29.5.0", + "jest-environment-jsdom": "^29.5.0", + "mockdate": "^3.0.2", + "npm-run-all": "^4.1.5", + "prettier": "^2.8.0", + "prettier-plugin-organize-imports": "^3.2.2", + "rollup": "^3.28.0", + "rollup-plugin-dts": "^5.3.1", + "rollup-plugin-typescript2": "^0.35.0", + "seedrandom": "^3.0.5", + "typescript": "^5.8.2", + "typescript-eslint": "^8.30.1", + "xml-formatter": "^2.4.0" + }, + "jest": { + "roots": [ + "/src", + "/tests" + ], + "transform": { + "^.+\\.ts?$": [ + "@swc/jest" + ] + }, + "verbose": false, + "testEnvironment": "jsdom", + "testRegex": "(/tests/.*(test|spec))\\.ts?$", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json", + "node" + ], + "workerIdleMemoryLimit": "800MB" + } +} diff --git a/packages/o-spreadsheet-engine/rollup.config.js b/packages/o-spreadsheet-engine/rollup.config.js new file mode 100644 index 0000000000..c10a2978c4 --- /dev/null +++ b/packages/o-spreadsheet-engine/rollup.config.js @@ -0,0 +1,77 @@ +import { nodeResolve } from "@rollup/plugin-node-resolve"; +import terser from "@rollup/plugin-terser"; +import dts from "rollup-plugin-dts"; +import typescript from "rollup-plugin-typescript2"; +import { bundle } from "../../tools/bundle.cjs"; + +const outro = bundle.outro(); + +/** + * Get the rollup config based on the arguments + * @param {"esm" | "cjs" | "iife"} format format of the bundle + * @param {string} generatedFileName generated file name + * @param {boolean} minified should it be minified + */ +function getConfigForFormat(format, minified = false) { + return { + file: minified + ? `../../dist/o-spreadsheet-engine.${format}.min.js` + : `../../dist/o-spreadsheet-engine.${format}.js`, + format, + name: "o_spreadsheet_engine", + extend: true, + outro, + banner: bundle.jsBanner(), + plugins: minified ? [terser()] : [], + }; +} + +export default (commandLineArgs) => { + let output = []; + let input = ""; + let plugins = [nodeResolve()]; + let config = {}; + + if (commandLineArgs.format) { + // Only build one version to improve speed + config = { + input: "build/js/o-spreadsheet-engine/src/index.js", + external: [], + output: [ + { + name: "o_spreadsheet_engine", + extend: true, + outro, + banner: bundle.jsBanner(), + file: `build/o-spreadsheet-engine.${commandLineArgs.format}.js`, + format: commandLineArgs.format, + }, + ], + plugins, + }; + } else { + input = "src/index.ts"; + output = [ + getConfigForFormat("esm"), + getConfigForFormat("cjs"), + getConfigForFormat("iife"), + getConfigForFormat("iife", true), + ]; + plugins.push(typescript({ useTsconfigDeclarationDir: true })); + config = [ + { + input, + external: [], + output, + plugins, + }, + { + input: "../../dist/types/packages/o-spreadsheet-engine/index.d.ts", + output: [{ file: "../../dist/o-spreadsheet-engine.d.ts", format: "es" }], + plugins: [dts(), nodeResolve()], + }, + ]; + } + + return config; +}; diff --git a/packages/o-spreadsheet-engine/src/helpers/uuid.ts b/packages/o-spreadsheet-engine/src/helpers/uuid.ts new file mode 100644 index 0000000000..85b6cb9fb9 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/helpers/uuid.ts @@ -0,0 +1,50 @@ +/* + * https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript + * */ + +export class UuidGenerator { + /** + * Generates a custom UUID using a simple 36^12 method (8-character alphanumeric string with lowercase letters) + * This has a higher chance of collision than a UUIDv4, but not only faster to generate than an UUIDV4, + * it also has a smaller size, which is preferable to alleviate the overall data size. + * + * This method is preferable when generating uuids for the core data (sheetId, figureId, etc) + * as they will appear several times in the revisions and local history. + * + */ + smallUuid(): string { + if (window.crypto) { + return "10000000-1000".replace(/[01]/g, (c) => { + const n = Number(c); + return (n ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (n / 4)))).toString(16); + }); + } else { + // mainly for jest and other browsers that do not have the crypto functionality + return "xxxxxxxx-xxxx".replace(/[xy]/g, function (c) { + const r = (Math.random() * 16) | 0, + v = c === "x" ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); + } + } + + /** + * Generates an UUIDV4, has astronomically low chance of collision, but is larger in size than the smallUuid. + * This method should be used when you need to avoid collisions at all costs, like the id of a revision. + */ + uuidv4(): string { + if (window.crypto) { + return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => { + const n = Number(c); + return (n ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (n / 4)))).toString(16); + }); + } else { + // mainly for jest and other browsers that do not have the crypto functionality + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) { + const r = (Math.random() * 16) | 0, + v = c === "x" ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); + } + } +} diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts new file mode 100644 index 0000000000..3eead65b54 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -0,0 +1 @@ +export { UuidGenerator } from "./helpers/uuid"; diff --git a/packages/o-spreadsheet-engine/tests/index.test.ts b/packages/o-spreadsheet-engine/tests/index.test.ts new file mode 100644 index 0000000000..3d2f415fe2 --- /dev/null +++ b/packages/o-spreadsheet-engine/tests/index.test.ts @@ -0,0 +1,5 @@ +describe("dummy", () => { + test("dummy", () => { + expect(true).toBe(true); + }); +}); diff --git a/packages/o-spreadsheet-engine/tsconfig.jest.json b/packages/o-spreadsheet-engine/tsconfig.jest.json new file mode 100644 index 0000000000..8bbe1edf31 --- /dev/null +++ b/packages/o-spreadsheet-engine/tsconfig.jest.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": ["src", "tests"] +} diff --git a/packages/o-spreadsheet-engine/tsconfig.json b/packages/o-spreadsheet-engine/tsconfig.json new file mode 100644 index 0000000000..7111e9b4e9 --- /dev/null +++ b/packages/o-spreadsheet-engine/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "build/js/o-spreadsheet-engine/src", + "preserveWatchOutput": true + }, + "include": ["src"] +} diff --git a/rollup.config.js b/rollup.config.js index 3585d20966..243f243a14 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,7 +1,10 @@ +import alias from "@rollup/plugin-alias"; import { nodeResolve } from "@rollup/plugin-node-resolve"; import terser from "@rollup/plugin-terser"; +import path from "path"; import dts from "rollup-plugin-dts"; import typescript from "rollup-plugin-typescript2"; +import { fileURLToPath } from "url"; import { bundle } from "./tools/bundle.cjs"; const outro = bundle.outro(); @@ -14,7 +17,7 @@ const outro = bundle.outro(); */ function getConfigForFormat(format, minified = false) { return { - file: minified ? `dist/o-spreadsheet.${format}.min.js` : `dist/o-spreadsheet.${format}.js`, + file: minified ? `dist/o_spreadsheet.${format}.min.js` : `dist/o_spreadsheet.${format}.js`, format, name: "o_spreadsheet", extend: true, @@ -24,17 +27,31 @@ function getConfigForFormat(format, minified = false) { plugins: minified ? [terser()] : [], }; } +const __dirname = fileURLToPath(new URL(".", import.meta.url)); export default (commandLineArgs) => { let output = []; let input = ""; - let plugins = [nodeResolve()]; + let plugins = [ + alias({ + entries: [ + { + find: "@odoo/o-spreadsheet-engine", + replacement: path.resolve( + __dirname, + "./packages/o-spreadsheet-engine/build/js/o-spreadsheet-engine/src/index.js" + ), + }, + ], + }), + nodeResolve(), + ]; let config = {}; if (commandLineArgs.format) { // Only build one version to improve speed config = { - input: "build/js/index.js", + input: "build/js/src/index.js", external: ["@odoo/owl"], output: [ { @@ -48,6 +65,9 @@ export default (commandLineArgs) => { }, ], plugins, + watch: { + include: ["src/**", "./packages/o-spreadsheet-engine/src/**"], + }, }; } else { input = "src/index.ts"; @@ -66,9 +86,23 @@ export default (commandLineArgs) => { plugins, }, { - input: "dist/types/index.d.ts", + input: "dist/types/src/index.d.ts", output: [{ file: "dist/o-spreadsheet.d.ts", format: "es" }], - plugins: [dts(), nodeResolve()], + plugins: [ + dts(), + nodeResolve(), + alias({ + entries: [ + { + find: "@odoo/o-spreadsheet-engine", + replacement: path.resolve( + __dirname, + "./dist/types/packages/o-spreadsheet-engine/index.d.ts" + ), + }, + ], + }), + ], }, ]; } diff --git a/src/helpers/uuid.ts b/src/helpers/uuid.ts index 85b6cb9fb9..eecad570ce 100644 --- a/src/helpers/uuid.ts +++ b/src/helpers/uuid.ts @@ -1,50 +1 @@ -/* - * https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript - * */ - -export class UuidGenerator { - /** - * Generates a custom UUID using a simple 36^12 method (8-character alphanumeric string with lowercase letters) - * This has a higher chance of collision than a UUIDv4, but not only faster to generate than an UUIDV4, - * it also has a smaller size, which is preferable to alleviate the overall data size. - * - * This method is preferable when generating uuids for the core data (sheetId, figureId, etc) - * as they will appear several times in the revisions and local history. - * - */ - smallUuid(): string { - if (window.crypto) { - return "10000000-1000".replace(/[01]/g, (c) => { - const n = Number(c); - return (n ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (n / 4)))).toString(16); - }); - } else { - // mainly for jest and other browsers that do not have the crypto functionality - return "xxxxxxxx-xxxx".replace(/[xy]/g, function (c) { - const r = (Math.random() * 16) | 0, - v = c === "x" ? r : (r & 0x3) | 0x8; - return v.toString(16); - }); - } - } - - /** - * Generates an UUIDV4, has astronomically low chance of collision, but is larger in size than the smallUuid. - * This method should be used when you need to avoid collisions at all costs, like the id of a revision. - */ - uuidv4(): string { - if (window.crypto) { - return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => { - const n = Number(c); - return (n ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (n / 4)))).toString(16); - }); - } else { - // mainly for jest and other browsers that do not have the crypto functionality - return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) { - const r = (Math.random() * 16) | 0, - v = c === "x" ? r : (r & 0x3) | 0x8; - return v.toString(16); - }); - } - } -} +export { UuidGenerator } from "@odoo/o-spreadsheet-engine"; diff --git a/src/index.ts b/src/index.ts index dc4ec60d64..03c6ece0f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -502,3 +502,5 @@ export type { FunctionRegistry }; export { AbstractCellClipboardHandler } from "./clipboard_handlers/abstract_cell_clipboard_handler"; export { AbstractFigureClipboardHandler } from "./clipboard_handlers/abstract_figure_clipboard_handler"; + +export * from "@odoo/o-spreadsheet-engine"; diff --git a/tsconfig.jest.json b/tsconfig.jest.json index 05fe2c8c11..26bf4e6c97 100644 --- a/tsconfig.jest.json +++ b/tsconfig.jest.json @@ -1,8 +1,9 @@ { - "extends": "./tsconfig.base.json", + "extends": "./tsconfig.json", "compilerOptions": { "outDir": "dist" }, "include": ["src", "tests"], + "exclude": ["packages"], "files": ["global.d.ts"] } diff --git a/tsconfig.json b/tsconfig.json index e8195e9eae..f0015381ef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,10 @@ "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "build/js", - "preserveWatchOutput": true + "preserveWatchOutput": true, + "paths": { + "@odoo/o-spreadsheet-engine": ["./packages/o-spreadsheet-engine/src/"] + } }, "include": ["src"] } From cf0681b30b497b99fa8b3848073a28ab35458b79 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 08:02:58 +0200 Subject: [PATCH 02/19] first codex test --- package.json | 3 +- .../o-spreadsheet-engine/src/constants.ts | 1 + .../src/formulas/tokenizer.ts | 223 +++++++++++++++ .../o-spreadsheet-engine/src/helpers/index.ts | 4 + .../o-spreadsheet-engine/src/helpers/misc.ts | 129 +++++++++ .../src/helpers/numbers.ts | 101 +++++++ .../src/helpers/references.ts | 53 ++++ packages/o-spreadsheet-engine/src/index.ts | 7 +- .../o-spreadsheet-engine/src/translation.ts | 64 +++++ .../o-spreadsheet-engine/src/types/errors.ts | 67 +++++ .../o-spreadsheet-engine/src/types/locale.ts | 38 +++ src/formulas/tokenizer.ts | 265 +----------------- src/helpers/misc.ts | 158 +---------- src/helpers/numbers.ts | 109 +------ src/helpers/references.ts | 91 +----- src/index.ts | 2 - src/translation.ts | 70 +---- src/types/errors.ts | 80 +----- src/types/locale.ts | 44 +-- tsconfig.json | 3 +- 20 files changed, 749 insertions(+), 763 deletions(-) create mode 100644 packages/o-spreadsheet-engine/src/constants.ts create mode 100644 packages/o-spreadsheet-engine/src/formulas/tokenizer.ts create mode 100644 packages/o-spreadsheet-engine/src/helpers/index.ts create mode 100644 packages/o-spreadsheet-engine/src/helpers/misc.ts create mode 100644 packages/o-spreadsheet-engine/src/helpers/numbers.ts create mode 100644 packages/o-spreadsheet-engine/src/helpers/references.ts create mode 100644 packages/o-spreadsheet-engine/src/translation.ts create mode 100644 packages/o-spreadsheet-engine/src/types/errors.ts create mode 100644 packages/o-spreadsheet-engine/src/types/locale.ts diff --git a/package.json b/package.json index f46a0ea6f7..ba0d61cac8 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,8 @@ ] }, "moduleNameMapper": { - "^@odoo/o-spreadsheet-engine$": "/packages/o-spreadsheet-engine/src" + "^@odoo/o-spreadsheet-engine$": "/packages/o-spreadsheet-engine/src", + "^@odoo/o-spreadsheet-engine/(.*)$": "/packages/o-spreadsheet-engine/src/$1" }, "verbose": false, "testEnvironment": "jsdom", diff --git a/packages/o-spreadsheet-engine/src/constants.ts b/packages/o-spreadsheet-engine/src/constants.ts new file mode 100644 index 0000000000..ac3d016072 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/constants.ts @@ -0,0 +1 @@ +export const NEWLINE = "\n"; diff --git a/packages/o-spreadsheet-engine/src/formulas/tokenizer.ts b/packages/o-spreadsheet-engine/src/formulas/tokenizer.ts new file mode 100644 index 0000000000..8530c076d3 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/formulas/tokenizer.ts @@ -0,0 +1,223 @@ +import { NEWLINE } from "../constants"; +import { TokenizingChars, replaceNewLines, specialWhiteSpaceRegexp } from "../helpers/misc"; +import { getFormulaNumberRegex } from "../helpers/numbers"; +import { rangeReference } from "../helpers/references"; +import { CellErrorType } from "../types/errors"; +import { DEFAULT_LOCALE, type Locale } from "../types/locale"; + +export const POSTFIX_UNARY_OPERATORS = ["%"]; +const OPERATORS = "+,-,*,/,:,=,<>,>=,>,<=,<,^,&".split(",").concat(POSTFIX_UNARY_OPERATORS); + +type TokenType = + | "OPERATOR" + | "NUMBER" + | "STRING" + | "SYMBOL" + | "SPACE" + | "DEBUGGER" + | "ARG_SEPARATOR" + | "LEFT_PAREN" + | "RIGHT_PAREN" + | "REFERENCE" + | "INVALID_REFERENCE" + | "UNKNOWN"; + +export interface Token { + readonly type: TokenType; + readonly value: string; +} + +export function tokenize(str: string, locale: Locale = DEFAULT_LOCALE): Token[] { + str = replaceNewLines(str); + const chars = new TokenizingChars(str); + const result: Token[] = []; + const tokenizeSpace = specialWhiteSpaceRegexp.test(str) + ? tokenizeSpecialCharacterSpace + : tokenizeSimpleSpace; + + while (!chars.isOver()) { + let token = + tokenizeNewLine(chars) || + tokenizeSpace(chars) || + tokenizeArgsSeparator(chars, locale) || + tokenizeParenthesis(chars) || + tokenizeOperator(chars) || + tokenizeString(chars) || + tokenizeDebugger(chars) || + tokenizeInvalidRange(chars) || + tokenizeNumber(chars, locale) || + tokenizeSymbol(chars); + + if (!token) { + token = { type: "UNKNOWN", value: chars.shift() }; + } + + result.push(token); + } + return result; +} + +function tokenizeDebugger(chars: TokenizingChars): Token | null { + if (chars.current === "?") { + chars.shift(); + return { type: "DEBUGGER", value: "?" }; + } + return null; +} + +const parenthesis = { + "(": { type: "LEFT_PAREN", value: "(" }, + ")": { type: "RIGHT_PAREN", value: ")" }, +} as const; + +function tokenizeParenthesis(chars: TokenizingChars): Token | null { + if (chars.current === "(" || chars.current === ")") { + const value = chars.shift(); + return parenthesis[value]; + } + return null; +} + +function tokenizeArgsSeparator(chars: TokenizingChars, locale: Locale): Token | null { + if (chars.current === locale.formulaArgSeparator) { + const value = chars.shift(); + const type = "ARG_SEPARATOR"; + return { type, value }; + } + + return null; +} + +function tokenizeOperator(chars: TokenizingChars): Token | null { + for (const op of OPERATORS) { + if (chars.currentStartsWith(op)) { + chars.advanceBy(op.length); + return { type: "OPERATOR", value: op }; + } + } + return null; +} + +const FIRST_POSSIBLE_NUMBER_CHARS = new Set("0123456789"); + +function tokenizeNumber(chars: TokenizingChars, locale: Locale): Token | null { + if ( + !FIRST_POSSIBLE_NUMBER_CHARS.has(chars.current) && + chars.current !== locale.decimalSeparator + ) { + return null; + } + const match = chars.remaining().match(getFormulaNumberRegex(locale.decimalSeparator)); + if (match) { + chars.advanceBy(match[0].length); + return { type: "NUMBER", value: match[0] }; + } + return null; +} + +function tokenizeString(chars: TokenizingChars): Token | null { + if (chars.current === '"') { + const startChar = chars.shift(); + let letters: string = startChar; + while (chars.current && (chars.current !== startChar || letters[letters.length - 1] === "\\")) { + letters += chars.shift(); + } + if (chars.current === '"') { + letters += chars.shift(); + } + return { + type: "STRING", + value: letters, + }; + } + return null; +} + +const unicodeSymbolCharRegexp = /\p{L}|\p{N}|_|\.|!|\$/u; +const SYMBOL_CHARS = new Set("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.!$"); + +function tokenizeSymbol(chars: TokenizingChars): Token | null { + let result: string = ""; + if (chars.current === "'") { + let lastChar = chars.shift(); + result += lastChar; + while (chars.current) { + lastChar = chars.shift(); + result += lastChar; + if (lastChar === "'") { + if (chars.current && chars.current === "'") { + lastChar = chars.shift(); + result += lastChar; + } else { + break; + } + } + } + + if (lastChar !== "'") { + return { + type: "UNKNOWN", + value: result, + }; + } + } + while ( + chars.current && + (SYMBOL_CHARS.has(chars.current) || chars.current.match(unicodeSymbolCharRegexp)) + ) { + result += chars.shift(); + } + if (result.length) { + const value = result; + const isReference = rangeReference.test(value); + if (isReference) { + return { type: "REFERENCE", value }; + } + return { type: "SYMBOL", value }; + } + return null; +} + +function tokenizeSpecialCharacterSpace(chars: TokenizingChars): Token | null { + let spaces = ""; + while (chars.current === " " || (chars.current && chars.current.match(specialWhiteSpaceRegexp))) { + spaces += chars.shift(); + } + + if (spaces) { + return { type: "SPACE", value: spaces }; + } + return null; +} + +function tokenizeSimpleSpace(chars: TokenizingChars): Token | null { + let spaces = ""; + while (chars.current === " ") { + spaces += chars.shift(); + } + + if (spaces) { + return { type: "SPACE", value: spaces }; + } + return null; +} + +function tokenizeNewLine(chars: TokenizingChars): Token | null { + let length = 0; + while (chars.current === NEWLINE) { + length++; + chars.shift(); + } + if (length) { + return { type: "SPACE", value: NEWLINE.repeat(length) }; + } + return null; +} + +function tokenizeInvalidRange(chars: TokenizingChars): Token | null { + if (chars.currentStartsWith(CellErrorType.InvalidReference)) { + chars.advanceBy(CellErrorType.InvalidReference.length); + return { type: "INVALID_REFERENCE", value: CellErrorType.InvalidReference }; + } + return null; +} diff --git a/packages/o-spreadsheet-engine/src/helpers/index.ts b/packages/o-spreadsheet-engine/src/helpers/index.ts new file mode 100644 index 0000000000..a466535aa0 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/helpers/index.ts @@ -0,0 +1,4 @@ +export * from "./misc"; +export * from "./numbers"; +export * from "./references"; +export * from "./uuid"; diff --git a/packages/o-spreadsheet-engine/src/helpers/misc.ts b/packages/o-spreadsheet-engine/src/helpers/misc.ts new file mode 100644 index 0000000000..bfbb28a718 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/helpers/misc.ts @@ -0,0 +1,129 @@ +import { NEWLINE } from "../constants"; + +/** + * Escapes a string to use as a literal string in a RegExp. + */ +export function escapeRegExp(str: string): string { + return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); +} + +/** + * Remove quotes from a quoted string. + */ +export function unquote(string: string, quoteChar: "'" | '"' = '"'): string { + if (string.startsWith(quoteChar)) { + string = string.slice(1); + } + if (string.endsWith(quoteChar)) { + string = string.slice(0, -1); + } + return string; +} + +/** + * Sanitize the name of a sheet, by eventually removing quotes. + */ +export function getUnquotedSheetName(sheetName: string): string { + return unquote(sheetName, "'"); +} + +/** + * Add quotes around the sheet name or any symbol name if it contains at least one non alphanumeric character. + */ +export function getCanonicalSymbolName(symbolName: string): string { + if (symbolName.match(/\w/g)?.length !== symbolName.length) { + symbolName = `'${symbolName}'`; + } + return symbolName; +} + +const specialWhiteSpaceSpecialCharacters = [ + "\t", + "\f", + "\v", + String.fromCharCode(parseInt("00a0", 16)), + String.fromCharCode(parseInt("1680", 16)), + String.fromCharCode(parseInt("2000", 16)), + String.fromCharCode(parseInt("200a", 16)), + String.fromCharCode(parseInt("2028", 16)), + String.fromCharCode(parseInt("2029", 16)), + String.fromCharCode(parseInt("202f", 16)), + String.fromCharCode(parseInt("205f", 16)), + String.fromCharCode(parseInt("3000", 16)), + String.fromCharCode(parseInt("feff", 16)), +]; + +export const specialWhiteSpaceRegexp = new RegExp( + specialWhiteSpaceSpecialCharacters.join("|"), + "g" +); +const newLineRegexp = /(\r\n|\r)/g; + +export const whiteSpaceCharacters = specialWhiteSpaceSpecialCharacters.concat([" "]); + +/** + * Replace all different newlines characters by \n. + */ +export function replaceNewLines(text: string | undefined): string { + if (!text) return ""; + return text.replace(newLineRegexp, NEWLINE); +} + +/** + * Creates a version of the function that's memoized on the value of its first argument, if any. + */ +export function memoize(func: (...args: T) => U): (...args: T) => U { + const cache = new Map(); + const funcName = func.name ? func.name + " (memoized)" : "memoized"; + return { + [funcName](...args: T) { + if (!cache.has(args[0])) { + cache.set(args[0], func(...args)); + } + return cache.get(args[0])!; + }, + }[funcName]; +} + +export class TokenizingChars { + private text: string; + private currentIndex: number = 0; + current: string; + + constructor(text: string) { + this.text = text; + this.current = text[0]; + } + + shift() { + const current = this.current; + const next = this.text[++this.currentIndex]; + this.current = next; + return current; + } + + advanceBy(length: number) { + this.currentIndex += length; + this.current = this.text[this.currentIndex]; + } + + isOver() { + return this.currentIndex >= this.text.length; + } + + remaining() { + return this.text.substring(this.currentIndex); + } + + currentStartsWith(str: string) { + if (this.current !== str[0]) { + return false; + } + for (let j = 1; j < str.length; j++) { + if (this.text[this.currentIndex + j] !== str[j]) { + return false; + } + } + return true; + } +} diff --git a/packages/o-spreadsheet-engine/src/helpers/numbers.ts b/packages/o-spreadsheet-engine/src/helpers/numbers.ts new file mode 100644 index 0000000000..053bd29c00 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/helpers/numbers.ts @@ -0,0 +1,101 @@ +import { Locale } from "../types/locale"; +import { escapeRegExp, memoize } from "./misc"; + +/** + * This function returns a regexp that is supposed to be as close as possible as the numberRegexp, + * but its purpose is to be used by the tokenizer. + * + * - it tolerates extra characters at the end. This is useful because the tokenizer + * only needs to find the number at the start of a string + * - it does not support % symbol, in formulas % is an operator + */ +export const getFormulaNumberRegex = memoize(function getFormulaNumberRegex( + decimalSeparator: string +) { + decimalSeparator = escapeRegExp(decimalSeparator); + return new RegExp( + `(?:^-?\\d+(?:${decimalSeparator}?\\d*(?:e(\\+|-)?\\d+)?)?|^-?${decimalSeparator}\\d+)(?!\\w|!)` + ); +}); + +const getNumberRegex = memoize(function getNumberRegex(locale: Locale) { + const decimalSeparator = escapeRegExp(locale.decimalSeparator); + const thousandsSeparator = escapeRegExp(locale.thousandsSeparator || ""); + + const pIntegerAndDecimals = `(?:\\d+(?:${thousandsSeparator}\\d{3,})*(?:${decimalSeparator}\\d*)?)`; + const pOnlyDecimals = `(?:${decimalSeparator}\\d+)`; + const pScientificFormat = "(?:e(?:\\+|-)?\\d+)?"; + const pPercentFormat = "(?:\\s*%)?"; + const pNumber = + "(?:\\s*" + + pIntegerAndDecimals + + "|" + + pOnlyDecimals + + ")" + + pScientificFormat + + pPercentFormat; + const pMinus = "(?:\\s*-)?"; + const pCurrencyFormat = "(?:\\s*[\\$€])?"; + + const p1 = pMinus + pCurrencyFormat + pNumber; + const p2 = pMinus + pNumber + pCurrencyFormat; + const p3 = pCurrencyFormat + pMinus + pNumber; + + const pNumberExp = "^(?:(?:" + [p1, p2, p3].join(")|(?:") + "))$"; + + return new RegExp(pNumberExp, "i"); +}); + +/** + * Return true if the argument is a "number string". + * + * Note that "" (empty string) does not count as a number string + */ +export function isNumber(value: string | undefined, locale: Locale): boolean { + if (!value) return false; + return getNumberRegex(locale).test(value.trim()); +} + +const getInvaluableSymbolsRegexp = memoize(function getInvaluableSymbolsRegexp(locale: Locale) { + return new RegExp(`[\$€${escapeRegExp(locale.thousandsSeparator || "")}]`, "g"); +}); +/** + * Convert a string into a number. It assumes that the string actually represents + * a number (as determined by the isNumber function) + * + * Note that it accepts "" (empty string), even though it does not count as a + * number from the point of view of the isNumber function. + */ +export function parseNumber(str: string, locale: Locale): number { + str = str.replace(getInvaluableSymbolsRegexp(locale), ""); + + if (locale.decimalSeparator !== ".") { + str = str.replace(locale.decimalSeparator, "."); + } + let n = Number(str); + if (isNaN(n) && str.includes("%")) { + n = Number(str.split("%")[0]); + if (!isNaN(n)) { + return n / 100; + } + } + return n; +} + +export function percentile(values: number[], percent: number, isInclusive: boolean) { + const sortedValues = [...values].sort((a, b) => a - b); + + let percentIndex = (sortedValues.length + (isInclusive ? -1 : 1)) * percent; + if (!isInclusive) { + percentIndex--; + } + if (Number.isInteger(percentIndex)) { + return sortedValues[percentIndex]; + } + const indexSup = Math.ceil(percentIndex); + const indexLow = Math.floor(percentIndex); + return ( + sortedValues[indexSup] * (percentIndex - indexLow) + + sortedValues[indexLow] * (indexSup - percentIndex) + ); +} diff --git a/packages/o-spreadsheet-engine/src/helpers/references.ts b/packages/o-spreadsheet-engine/src/helpers/references.ts new file mode 100644 index 0000000000..60e1c83c59 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/helpers/references.ts @@ -0,0 +1,53 @@ +import { getCanonicalSymbolName, getUnquotedSheetName } from "./misc"; + +export const cellReference = new RegExp(/\$?([A-Z]{1,3})\$?([0-9]{1,7})/, "i"); +const singleCellReference = new RegExp(/^\$?([A-Z]{1,3})\$?([0-9]{1,7})$/, "i"); +const colHeader = new RegExp(/^\$?([A-Z]{1,3})+$/, "i"); +const rowHeader = new RegExp(/^\$?([0-9]{1,7})+$/, "i"); +const colReference = new RegExp(/^\s*('.+'!|[^']+!)?\$?([A-Z]{1,3})$/, "i"); +const rowReference = new RegExp(/^\s*('.+'!|[^']+!)?\$?([0-9]{1,7})$/, "i"); +const fullRowXc = /(\$?[A-Z]{1,3})?\$?[0-9]{1,7}\s*:\s*(\$?[A-Z]{1,3})?\$?[0-9]{1,7}\s*/i; +const fullColXc = /\$?[A-Z]{1,3}(\$?[0-9]{1,7})?\s*:\s*\$?[A-Z]{1,3}(\$?[0-9]{1,7})?\s*/i; + +export const rangeReference = new RegExp( + /^\s*('.+'!|[^']+!)?/.source + + "(" + + [cellReference.source, fullRowXc.source, fullColXc.source].join("|") + + ")" + + /$/.source, + "i" +); + +export function isColReference(xc: string): boolean { + return colReference.test(xc); +} + +export function isRowReference(xc: string): boolean { + return rowReference.test(xc); +} + +export function isColHeader(str: string): boolean { + return colHeader.test(str); +} + +export function isRowHeader(str: string): boolean { + return rowHeader.test(str); +} + +export function isSingleCellReference(xc: string): boolean { + return singleCellReference.test(xc); +} + +export function splitReference(ref: string): { sheetName?: string; xc: string } { + if (!ref.includes("!")) { + return { xc: ref }; + } + const parts = ref.split("!"); + const xc = parts.pop()!; + const sheetName = getUnquotedSheetName(parts.join("!")) || undefined; + return { sheetName, xc }; +} + +export function getFullReference(sheetName: string | undefined, xc: string): string { + return sheetName !== undefined ? `${getCanonicalSymbolName(sheetName)}!${xc}` : xc; +} diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts index 3eead65b54..aadbc0e833 100644 --- a/packages/o-spreadsheet-engine/src/index.ts +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -1 +1,6 @@ -export { UuidGenerator } from "./helpers/uuid"; +export { POSTFIX_UNARY_OPERATORS, tokenize } from "./formulas/tokenizer"; +export type { Token } from "./formulas/tokenizer"; +export * from "./helpers"; +export * from "./translation"; +export * from "./types/errors"; +export * from "./types/locale"; diff --git a/packages/o-spreadsheet-engine/src/translation.ts b/packages/o-spreadsheet-engine/src/translation.ts new file mode 100644 index 0000000000..f8cfeffefe --- /dev/null +++ b/packages/o-spreadsheet-engine/src/translation.ts @@ -0,0 +1,64 @@ +type SprintfValues = (string | String | number)[] | [{ [key: string]: string | number }]; + +export type TranslationFunction = (string: string, ...values: SprintfValues) => string; + +const defaultTranslate: TranslationFunction = (s: string) => s; +const defaultLoaded: () => boolean = () => false; + +let _translate = defaultTranslate; +let _loaded = defaultLoaded; + +function sprintf(s: string, ...values: SprintfValues): string { + if (values.length === 1 && typeof values[0] === "object" && !(values[0] instanceof String)) { + const valuesDict = values[0] as { [key: string]: string }; + s = s.replace(/\%\(([^\)]+)\)s/g, (match, value) => valuesDict[value]); + } else if (values.length > 0) { + s = s.replace(/\%s/g, () => values.shift() as string); + } + return s; +} + +/*** + * Allow to inject a translation function from outside o-spreadsheet. This should be called before instantiating + * a model. + * @param tfn the function that will do the translation + * @param loaded a function that returns true when the translation is loaded + */ +export function setTranslationMethod(tfn: TranslationFunction, loaded: () => boolean = () => true) { + _translate = tfn; + _loaded = loaded; +} + +/** + * If no translation function has been set, this will mark the translation are loaded. + * + * By default, the translations should not be set as loaded, otherwise top-level translated constants will never be + * translated. But if by the time the model is instantiated no custom translation function has been set, we can set + * the default translation function as loaded so o-spreadsheet can be run in standalone with no translations. + */ +export function setDefaultTranslationMethod() { + if (_translate === defaultTranslate && _loaded === defaultLoaded) { + _loaded = () => true; + } +} + +export const _t: TranslationFunction = function (s: string, ...values: SprintfValues) { + if (!_loaded()) { + return new LazyTranslatedString(s, values) as unknown as string; + } + return sprintf(_translate(s), ...values); +}; + +class LazyTranslatedString extends String { + constructor(str: string, private values: SprintfValues) { + super(str); + } + + valueOf() { + const str = super.valueOf(); + return _loaded() ? sprintf(_translate(str), ...this.values) : sprintf(str, ...this.values); + } + toString() { + return this.valueOf(); + } +} diff --git a/packages/o-spreadsheet-engine/src/types/errors.ts b/packages/o-spreadsheet-engine/src/types/errors.ts new file mode 100644 index 0000000000..c1f1ca0674 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/errors.ts @@ -0,0 +1,67 @@ +import { _t } from "../translation"; + +export const CellErrorType = { + NotAvailable: "#N/A", + InvalidReference: "#REF", + BadExpression: "#BAD_EXPR", + CircularDependency: "#CYCLE", + UnknownFunction: "#NAME?", + DivisionByZero: "#DIV/0!", + SpilledBlocked: "#SPILL!", + GenericError: "#ERROR", + NullError: "#NULL!", +} as const; + +export type ErrorValue = (typeof CellErrorType)[keyof typeof CellErrorType]; + +export const errorTypes: Set = new Set(Object.values(CellErrorType)); + +export class EvaluationError { + constructor( + readonly message: string = _t("Error"), + readonly value: string = CellErrorType.GenericError + ) { + this.message = message.toString(); + } +} + +export class BadExpressionError extends EvaluationError { + constructor(message = _t("Invalid expression")) { + super(message, CellErrorType.BadExpression); + } +} +export class CircularDependencyError extends EvaluationError { + constructor(message = _t("Circular reference")) { + super(message, CellErrorType.CircularDependency); + } +} + +export class InvalidReferenceError extends EvaluationError { + constructor(message = _t("Invalid reference")) { + super(message, CellErrorType.InvalidReference); + } +} + +export class NotAvailableError extends EvaluationError { + constructor(message = _t("Data not available")) { + super(message, CellErrorType.NotAvailable); + } +} + +export class UnknownFunctionError extends EvaluationError { + constructor(message = _t("Unknown function")) { + super(message, CellErrorType.UnknownFunction); + } +} + +export class SplillBlockedError extends EvaluationError { + constructor(message = _t("Spill range is not empty")) { + super(message, CellErrorType.SpilledBlocked); + } +} + +export class DivisionByZeroError extends EvaluationError { + constructor(message = _t("Division by zero")) { + super(message, CellErrorType.DivisionByZero); + } +} diff --git a/packages/o-spreadsheet-engine/src/types/locale.ts b/packages/o-spreadsheet-engine/src/types/locale.ts new file mode 100644 index 0000000000..e2cdb9cf78 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/locale.ts @@ -0,0 +1,38 @@ +type Alias = {} & {}; + +export type LocaleCode = string & Alias; + +export interface Locale { + name: string; + code: LocaleCode; + thousandsSeparator?: string; + decimalSeparator: string; + weekStart: number; //1 = Monday, 7 = Sunday + dateFormat: string; + timeFormat: string; + formulaArgSeparator: string; +} + +export const DEFAULT_LOCALES: Locale[] = [ + { + name: "English (US)", + code: "en_US" as LocaleCode, + thousandsSeparator: ",", + decimalSeparator: ".", + weekStart: 7, // Sunday + dateFormat: "m/d/yyyy", + timeFormat: "hh:mm:ss a", + formulaArgSeparator: ",", + }, + { + name: "French", + code: "fr_FR" as LocaleCode, + thousandsSeparator: " ", + decimalSeparator: ",", + weekStart: 1, // Monday + dateFormat: "dd/mm/yyyy", + timeFormat: "hh:mm:ss", + formulaArgSeparator: ";", + }, +]; +export const DEFAULT_LOCALE: Locale = DEFAULT_LOCALES[0]; diff --git a/src/formulas/tokenizer.ts b/src/formulas/tokenizer.ts index 4c0dc5b975..1231933a13 100644 --- a/src/formulas/tokenizer.ts +++ b/src/formulas/tokenizer.ts @@ -1,263 +1,2 @@ -import { NEWLINE } from "../constants"; -import { - TokenizingChars, - getFormulaNumberRegex, - rangeReference, - replaceNewLines, - specialWhiteSpaceRegexp, -} from "../helpers/index"; -import { DEFAULT_LOCALE, Locale } from "../types"; -import { CellErrorType } from "../types/errors"; - -/** - * Tokenizer - * - * A tokenizer is a piece of code whose job is to transform a string into a list - * of "tokens". For example, "(12+" is converted into: - * [{type: "LEFT_PAREN", value: "("}, - * {type: "NUMBER", value: "12"}, - * {type: "OPERATOR", value: "+"}] - * - * As the example shows, a tokenizer does not care about the meaning behind those - * tokens. It only cares about the structure. - * - * The tokenizer is usually the first step in a compilation pipeline. Also, it - * is useful for the composer, which needs to be able to work with incomplete - * formulas. - */ - -export const POSTFIX_UNARY_OPERATORS = ["%"]; -const OPERATORS = "+,-,*,/,:,=,<>,>=,>,<=,<,^,&".split(",").concat(POSTFIX_UNARY_OPERATORS); - -type TokenType = - | "OPERATOR" - | "NUMBER" - | "STRING" - | "SYMBOL" - | "SPACE" - | "DEBUGGER" - | "ARG_SEPARATOR" - | "LEFT_PAREN" - | "RIGHT_PAREN" - | "REFERENCE" - | "INVALID_REFERENCE" - | "UNKNOWN"; - -export interface Token { - readonly type: TokenType; - readonly value: string; -} - -export function tokenize(str: string, locale = DEFAULT_LOCALE): Token[] { - str = replaceNewLines(str); - const chars = new TokenizingChars(str); - const result: Token[] = []; - const tokenizeSpace = specialWhiteSpaceRegexp.test(str) - ? tokenizeSpecialCharacterSpace - : tokenizeSimpleSpace; - - while (!chars.isOver()) { - let token = - tokenizeNewLine(chars) || - tokenizeSpace(chars) || - tokenizeArgsSeparator(chars, locale) || - tokenizeParenthesis(chars) || - tokenizeOperator(chars) || - tokenizeString(chars) || - tokenizeDebugger(chars) || - tokenizeInvalidRange(chars) || - tokenizeNumber(chars, locale) || - tokenizeSymbol(chars); - - if (!token) { - token = { type: "UNKNOWN", value: chars.shift() }; - } - - result.push(token); - } - return result; -} - -function tokenizeDebugger(chars: TokenizingChars): Token | null { - if (chars.current === "?") { - chars.shift(); - return { type: "DEBUGGER", value: "?" }; - } - return null; -} - -const parenthesis = { - "(": { type: "LEFT_PAREN", value: "(" }, - ")": { type: "RIGHT_PAREN", value: ")" }, -} as const; - -function tokenizeParenthesis(chars: TokenizingChars): Token | null { - if (chars.current === "(" || chars.current === ")") { - const value = chars.shift(); - return parenthesis[value]; - } - return null; -} - -function tokenizeArgsSeparator(chars: TokenizingChars, locale: Locale): Token | null { - if (chars.current === locale.formulaArgSeparator) { - const value = chars.shift(); - const type = "ARG_SEPARATOR"; - return { type, value }; - } - - return null; -} - -function tokenizeOperator(chars: TokenizingChars): Token | null { - for (const op of OPERATORS) { - if (chars.currentStartsWith(op)) { - chars.advanceBy(op.length); - return { type: "OPERATOR", value: op }; - } - } - return null; -} - -const FIRST_POSSIBLE_NUMBER_CHARS = new Set("0123456789"); - -function tokenizeNumber(chars: TokenizingChars, locale: Locale): Token | null { - if ( - !FIRST_POSSIBLE_NUMBER_CHARS.has(chars.current) && - chars.current !== locale.decimalSeparator - ) { - return null; - } - const match = chars.remaining().match(getFormulaNumberRegex(locale.decimalSeparator)); - if (match) { - chars.advanceBy(match[0].length); - return { type: "NUMBER", value: match[0] }; - } - return null; -} - -function tokenizeString(chars: TokenizingChars): Token | null { - if (chars.current === '"') { - const startChar = chars.shift(); - let letters: string = startChar; - while (chars.current && (chars.current !== startChar || letters[letters.length - 1] === "\\")) { - letters += chars.shift(); - } - if (chars.current === '"') { - letters += chars.shift(); - } - return { - type: "STRING", - value: letters, - }; - } - return null; -} - -/** - - \p{L} is for any letter (from any language) - - \p{N} is for any number - - the u flag at the end is for unicode, which enables the `\p{...}` syntax - */ -const unicodeSymbolCharRegexp = /\p{L}|\p{N}|_|\.|!|\$/u; -const SYMBOL_CHARS = new Set("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.!$"); - -/** - * A "Symbol" is just basically any word-like element that can appear in a - * formula, which is not a string. So: - * A1 - * SUM - * CEILING.MATH - * A$1 - * Sheet2!A2 - * 'Sheet 2'!A2 - * - * are examples of symbols - */ -function tokenizeSymbol(chars: TokenizingChars): Token | null { - let result: string = ""; - // there are two main cases to manage: either something which starts with - // a ', like 'Sheet 2'A2, or a word-like element. - if (chars.current === "'") { - let lastChar = chars.shift(); - result += lastChar; - while (chars.current) { - lastChar = chars.shift(); - result += lastChar; - if (lastChar === "'") { - if (chars.current && chars.current === "'") { - lastChar = chars.shift(); - result += lastChar; - } else { - break; - } - } - } - - if (lastChar !== "'") { - return { - type: "UNKNOWN", - value: result, - }; - } - } - while ( - chars.current && - (SYMBOL_CHARS.has(chars.current) || chars.current.match(unicodeSymbolCharRegexp)) - ) { - result += chars.shift(); - } - if (result.length) { - const value = result; - const isReference = rangeReference.test(value); - if (isReference) { - return { type: "REFERENCE", value }; - } - return { type: "SYMBOL", value }; - } - return null; -} - -function tokenizeSpecialCharacterSpace(chars: TokenizingChars): Token | null { - let spaces = ""; - while (chars.current === " " || (chars.current && chars.current.match(specialWhiteSpaceRegexp))) { - spaces += chars.shift(); - } - - if (spaces) { - return { type: "SPACE", value: spaces }; - } - return null; -} - -function tokenizeSimpleSpace(chars: TokenizingChars): Token | null { - let spaces = ""; - while (chars.current === " ") { - spaces += chars.shift(); - } - - if (spaces) { - return { type: "SPACE", value: spaces }; - } - return null; -} - -function tokenizeNewLine(chars: TokenizingChars): Token | null { - let length = 0; - while (chars.current === NEWLINE) { - length++; - chars.shift(); - } - if (length) { - return { type: "SPACE", value: NEWLINE.repeat(length) }; - } - return null; -} - -function tokenizeInvalidRange(chars: TokenizingChars): Token | null { - if (chars.currentStartsWith(CellErrorType.InvalidReference)) { - chars.advanceBy(CellErrorType.InvalidReference.length); - return { type: "INVALID_REFERENCE", value: CellErrorType.InvalidReference }; - } - return null; -} +export { POSTFIX_UNARY_OPERATORS, tokenize } from "@odoo/o-spreadsheet-engine/formulas/tokenizer"; +export type { Token } from "@odoo/o-spreadsheet-engine/formulas/tokenizer"; diff --git a/src/helpers/misc.ts b/src/helpers/misc.ts index 67992f71a7..5df1764927 100644 --- a/src/helpers/misc.ts +++ b/src/helpers/misc.ts @@ -1,25 +1,30 @@ //------------------------------------------------------------------------------ // Miscellaneous //------------------------------------------------------------------------------ -import { FORBIDDEN_SHEETNAME_CHARS_IN_EXCEL_REGEX, NEWLINE } from "../constants"; +import { escapeRegExp as engineEscapeRegExp } from "@odoo/o-spreadsheet-engine/helpers/misc"; +import { FORBIDDEN_SHEETNAME_CHARS_IN_EXCEL_REGEX } from "../constants"; import { ChartStyle, ConsecutiveIndexes, Lazy, UID } from "../types"; import { SearchOptions } from "../types/find_and_replace"; import { Cloneable, DebouncedFunction, Style } from "./../types/misc"; +export { + escapeRegExp, + getCanonicalSymbolName, + getUnquotedSheetName, + memoize, + replaceNewLines, + specialWhiteSpaceRegexp, + TokenizingChars, + unquote, + whiteSpaceCharacters, +} from "@odoo/o-spreadsheet-engine/helpers/misc"; + const sanitizeSheetNameRegex = new RegExp(FORBIDDEN_SHEETNAME_CHARS_IN_EXCEL_REGEX, "g"); function isCloneable(obj: T | Cloneable): obj is Cloneable { return "clone" in obj && obj.clone instanceof Function; } -/** - * Escapes a string to use as a literal string in a RegExp. - * @url https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping - */ -export function escapeRegExp(str: string): string { - return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); -} - /** * Deep copy arrays, plain objects and primitive values. * Throws an error for other types such as class instances. @@ -72,43 +77,6 @@ function isPlainObject(obj: unknown): boolean { ); } -/** - * Sanitize the name of a sheet, by eventually removing quotes - * @param sheetName name of the sheet, potentially quoted with single quotes - */ -export function getUnquotedSheetName(sheetName: string): string { - return unquote(sheetName, "'"); -} - -/** - * Remove quotes from a quoted string - * ```js - * unquote('"Hello"') - * > 'Hello' - * ``` - */ -export function unquote(string: string, quoteChar: "'" | '"' = '"'): string { - if (string.startsWith(quoteChar)) { - string = string.slice(1); - } - if (string.endsWith(quoteChar)) { - string = string.slice(0, -1); - } - return string; -} - -/** - * Add quotes around the sheet name or any symbol name if it contains at least one non alphanumeric character - * '\w' captures [0-9][a-z][A-Z] and _. - * @param symbolName Name of the sheet or symbol - */ -export function getCanonicalSymbolName(symbolName: string): string { - if (symbolName.match(/\w/g)?.length !== symbolName.length) { - symbolName = `'${symbolName}'`; - } - return symbolName; -} - /** Replace the excel-excluded characters of a sheetName */ export function sanitizeSheetName(sheetName: string, replacementChar: string = " "): string { return sheetName.replace(sanitizeSheetNameRegex, replacementChar); @@ -453,42 +421,6 @@ export function removeFalsyAttributes(obj: return cleanObject; } -/** - * Equivalent to "\s" in regexp, minus the new lines characters - * - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes - */ -const specialWhiteSpaceSpecialCharacters = [ - "\t", - "\f", - "\v", - String.fromCharCode(parseInt("00a0", 16)), - String.fromCharCode(parseInt("1680", 16)), - String.fromCharCode(parseInt("2000", 16)), - String.fromCharCode(parseInt("200a", 16)), - String.fromCharCode(parseInt("2028", 16)), - String.fromCharCode(parseInt("2029", 16)), - String.fromCharCode(parseInt("202f", 16)), - String.fromCharCode(parseInt("205f", 16)), - String.fromCharCode(parseInt("3000", 16)), - String.fromCharCode(parseInt("feff", 16)), -]; -export const specialWhiteSpaceRegexp = new RegExp( - specialWhiteSpaceSpecialCharacters.join("|"), - "g" -); -const newLineRegexp = /(\r\n|\r)/g; - -export const whiteSpaceCharacters = specialWhiteSpaceSpecialCharacters.concat([" "]); - -/** - * Replace all different newlines characters by \n - */ -export function replaceNewLines(text: string | undefined): string { - if (!text) return ""; - return text.replace(newLineRegexp, NEWLINE); -} - /** * Determine if the numbers are consecutive. */ @@ -502,23 +434,6 @@ export function isConsecutive(iterable: Iterable): boolean { return true; } -/** - * Creates a version of the function that's memoized on the value of its first - * argument, if any. - */ -export function memoize(func: (...args: T) => U): (...args: T) => U { - const cache = new Map(); - const funcName = func.name ? func.name + " (memoized)" : "memoized"; - return { - [funcName](...args: T) { - if (!cache.has(args[0])) { - cache.set(args[0], func(...args)); - } - return cache.get(args[0])!; - }, - }[funcName]; -} - /** * Removes the specified indexes from the array. * Sparse (empty) elements are transformed to undefined (unless their index is explicitly removed). @@ -562,7 +477,7 @@ export function isNumberBetween(value: number, min: number, max: number): boolea * Get a Regex for the find & replace that matches the given search string and options. */ export function getSearchRegex(searchStr: string, searchOptions: SearchOptions): RegExp { - let searchValue = escapeRegExp(searchStr); + let searchValue = engineEscapeRegExp(searchStr); const flags = !searchOptions.matchCase ? "i" : ""; if (searchOptions.exactMatch) { searchValue = `^${searchValue}$`; @@ -602,49 +517,6 @@ export function largeMin(array: number[]) { return min; } -export class TokenizingChars { - private text: string; - private currentIndex: number = 0; - current: string; - - constructor(text: string) { - this.text = text; - this.current = text[0]; - } - - shift() { - const current = this.current; - const next = this.text[++this.currentIndex]; - this.current = next; - return current; - } - - advanceBy(length: number) { - this.currentIndex += length; - this.current = this.text[this.currentIndex]; - } - - isOver() { - return this.currentIndex >= this.text.length; - } - - remaining() { - return this.text.substring(this.currentIndex); - } - - currentStartsWith(str: string) { - if (this.current !== str[0]) { - return false; - } - for (let j = 1; j < str.length; j++) { - if (this.text[this.currentIndex + j] !== str[j]) { - return false; - } - } - return true; - } -} - /** * Remove duplicates from an array. * diff --git a/src/helpers/numbers.ts b/src/helpers/numbers.ts index 39a36d37d4..2970ea3d5e 100644 --- a/src/helpers/numbers.ts +++ b/src/helpers/numbers.ts @@ -1,103 +1,6 @@ -import { Locale } from "../types"; -import { escapeRegExp, memoize } from "./misc"; - -/** - * This function returns a regexp that is supposed to be as close as possible as the numberRegexp, - * but its purpose is to be used by the tokenizer. - * - * - it tolerates extra characters at the end. This is useful because the tokenizer - * only needs to find the number at the start of a string - * - it does not support % symbol, in formulas % is an operator - */ -export const getFormulaNumberRegex = memoize(function getFormulaNumberRegex( - decimalSeparator: string -) { - decimalSeparator = escapeRegExp(decimalSeparator); - return new RegExp( - `(?:^-?\\d+(?:${decimalSeparator}?\\d*(?:e(\\+|-)?\\d+)?)?|^-?${decimalSeparator}\\d+)(?!\\w|!)` - ); -}); - -const getNumberRegex = memoize(function getNumberRegex(locale: Locale) { - const decimalSeparator = escapeRegExp(locale.decimalSeparator); - const thousandsSeparator = escapeRegExp(locale.thousandsSeparator || ""); - - const pIntegerAndDecimals = `(?:\\d+(?:${thousandsSeparator}\\d{3,})*(?:${decimalSeparator}\\d*)?)`; // pattern that match integer number with or without decimal digits - const pOnlyDecimals = `(?:${decimalSeparator}\\d+)`; // pattern that match only expression with decimal digits - const pScientificFormat = "(?:e(?:\\+|-)?\\d+)?"; // pattern that match scientific format between zero and one time (should be placed before pPercentFormat) - const pPercentFormat = "(?:\\s*%)?"; // pattern that match percent symbol between zero and one time - const pNumber = - "(?:\\s*" + - pIntegerAndDecimals + - "|" + - pOnlyDecimals + - ")" + - pScientificFormat + - pPercentFormat; - const pMinus = "(?:\\s*-)?"; // pattern that match negative symbol between zero and one time - const pCurrencyFormat = "(?:\\s*[\\$€])?"; - - const p1 = pMinus + pCurrencyFormat + pNumber; - const p2 = pMinus + pNumber + pCurrencyFormat; - const p3 = pCurrencyFormat + pMinus + pNumber; - - const pNumberExp = "^(?:(?:" + [p1, p2, p3].join(")|(?:") + "))$"; - - return new RegExp(pNumberExp, "i"); -}); - -/** - * Return true if the argument is a "number string". - * - * Note that "" (empty string) does not count as a number string - */ -export function isNumber(value: string | undefined, locale: Locale): boolean { - if (!value) return false; - // TO DO: add regexp for DATE string format (ex match: "28 02 2020") - return getNumberRegex(locale).test(value.trim()); -} - -const getInvaluableSymbolsRegexp = memoize(function getInvaluableSymbolsRegexp(locale: Locale) { - return new RegExp(`[\$€${escapeRegExp(locale.thousandsSeparator || "")}]`, "g"); -}); -/** - * Convert a string into a number. It assumes that the string actually represents - * a number (as determined by the isNumber function) - * - * Note that it accepts "" (empty string), even though it does not count as a - * number from the point of view of the isNumber function. - */ -export function parseNumber(str: string, locale: Locale): number { - // remove invaluable characters - str = str.replace(getInvaluableSymbolsRegexp(locale), ""); - - if (locale.decimalSeparator !== ".") { - str = str.replace(locale.decimalSeparator, "."); - } - let n = Number(str); - if (isNaN(n) && str.includes("%")) { - n = Number(str.split("%")[0]); - if (!isNaN(n)) { - return n / 100; - } - } - return n; -} - -export function percentile(values: number[], percent: number, isInclusive: boolean) { - const sortedValues = [...values].sort((a, b) => a - b); - - let percentIndex = (sortedValues.length + (isInclusive ? -1 : 1)) * percent; - if (!isInclusive) { - percentIndex--; - } - if (Number.isInteger(percentIndex)) { - return sortedValues[percentIndex]; - } - const indexSup = Math.ceil(percentIndex); - const indexLow = Math.floor(percentIndex); - return ( - sortedValues[indexSup] * (percentIndex - indexLow) + - sortedValues[indexLow] * (indexSup - percentIndex) - ); -} +export { + getFormulaNumberRegex, + isNumber, + parseNumber, + percentile, +} from "@odoo/o-spreadsheet-engine/helpers/numbers"; diff --git a/src/helpers/references.ts b/src/helpers/references.ts index 05c7af4d1f..26d47c1c4b 100644 --- a/src/helpers/references.ts +++ b/src/helpers/references.ts @@ -1,80 +1,11 @@ -import { getCanonicalSymbolName, getUnquotedSheetName } from "./misc"; - -/** Reference of a cell (eg. A1, $B$5) */ -export const cellReference = new RegExp(/\$?([A-Z]{1,3})\$?([0-9]{1,7})/, "i"); - -// Same as above, but matches the exact string (nothing before or after) -const singleCellReference = new RegExp(/^\$?([A-Z]{1,3})\$?([0-9]{1,7})$/, "i"); - -/** Reference of a column header (eg. A, AB, $A) */ -const colHeader = new RegExp(/^\$?([A-Z]{1,3})+$/, "i"); - -/** Reference of a row header (eg. 1, $1) */ -const rowHeader = new RegExp(/^\$?([0-9]{1,7})+$/, "i"); - -/** Reference of a column (eg. A, $CA, Sheet1!B) */ -const colReference = new RegExp(/^\s*('.+'!|[^']+!)?\$?([A-Z]{1,3})$/, "i"); - -/** Reference of a row (eg. 1, 59, Sheet1!9) */ -const rowReference = new RegExp(/^\s*('.+'!|[^']+!)?\$?([0-9]{1,7})$/, "i"); - -/** Reference of a normal range or a full row range (eg. A1:B1, 1:$5, $A2:5) */ -const fullRowXc = /(\$?[A-Z]{1,3})?\$?[0-9]{1,7}\s*:\s*(\$?[A-Z]{1,3})?\$?[0-9]{1,7}\s*/i; - -/** Reference of a normal range or a column row range (eg. A1:B1, A:$B, $A1:C) */ -const fullColXc = /\$?[A-Z]{1,3}(\$?[0-9]{1,7})?\s*:\s*\$?[A-Z]{1,3}(\$?[0-9]{1,7})?\s*/i; - -/** Reference of a cell or a range, it can be a bounded range, a full row or a full column */ -export const rangeReference = new RegExp( - /^\s*('.+'!|[^']+!)?/.source + - "(" + - [cellReference.source, fullRowXc.source, fullColXc.source].join("|") + - ")" + - /$/.source, - "i" -); - -/** - * Return true if the given xc is the reference of a column (e.g. A or AC or Sheet1!A) - */ -export function isColReference(xc: string): boolean { - return colReference.test(xc); -} - -/** - * Return true if the given xc is the reference of a column (e.g. 1 or Sheet1!1) - */ -export function isRowReference(xc: string): boolean { - return rowReference.test(xc); -} - -export function isColHeader(str: string): boolean { - return colHeader.test(str); -} - -export function isRowHeader(str: string): boolean { - return rowHeader.test(str); -} - -/** - * Return true if the given xc is the reference of a single cell, - * without any specified sheet (e.g. A1) - */ -export function isSingleCellReference(xc: string): boolean { - return singleCellReference.test(xc); -} - -export function splitReference(ref: string): { sheetName?: string; xc: string } { - if (!ref.includes("!")) { - return { xc: ref }; - } - const parts = ref.split("!"); - const xc = parts.pop()!; - const sheetName = getUnquotedSheetName(parts.join("!")) || undefined; - return { sheetName, xc }; -} - -/** Return a reference SheetName!xc from the given arguments */ -export function getFullReference(sheetName: string | undefined, xc: string): string { - return sheetName !== undefined ? `${getCanonicalSymbolName(sheetName)}!${xc}` : xc; -} +export { + cellReference, + getFullReference, + isColHeader, + isColReference, + isRowHeader, + isRowReference, + isSingleCellReference, + rangeReference, + splitReference, +} from "@odoo/o-spreadsheet-engine/helpers/references"; diff --git a/src/index.ts b/src/index.ts index 03c6ece0f3..dc4ec60d64 100644 --- a/src/index.ts +++ b/src/index.ts @@ -502,5 +502,3 @@ export type { FunctionRegistry }; export { AbstractCellClipboardHandler } from "./clipboard_handlers/abstract_cell_clipboard_handler"; export { AbstractFigureClipboardHandler } from "./clipboard_handlers/abstract_figure_clipboard_handler"; - -export * from "@odoo/o-spreadsheet-engine"; diff --git a/src/translation.ts b/src/translation.ts index f8cfeffefe..73d7e5b1e9 100644 --- a/src/translation.ts +++ b/src/translation.ts @@ -1,64 +1,6 @@ -type SprintfValues = (string | String | number)[] | [{ [key: string]: string | number }]; - -export type TranslationFunction = (string: string, ...values: SprintfValues) => string; - -const defaultTranslate: TranslationFunction = (s: string) => s; -const defaultLoaded: () => boolean = () => false; - -let _translate = defaultTranslate; -let _loaded = defaultLoaded; - -function sprintf(s: string, ...values: SprintfValues): string { - if (values.length === 1 && typeof values[0] === "object" && !(values[0] instanceof String)) { - const valuesDict = values[0] as { [key: string]: string }; - s = s.replace(/\%\(([^\)]+)\)s/g, (match, value) => valuesDict[value]); - } else if (values.length > 0) { - s = s.replace(/\%s/g, () => values.shift() as string); - } - return s; -} - -/*** - * Allow to inject a translation function from outside o-spreadsheet. This should be called before instantiating - * a model. - * @param tfn the function that will do the translation - * @param loaded a function that returns true when the translation is loaded - */ -export function setTranslationMethod(tfn: TranslationFunction, loaded: () => boolean = () => true) { - _translate = tfn; - _loaded = loaded; -} - -/** - * If no translation function has been set, this will mark the translation are loaded. - * - * By default, the translations should not be set as loaded, otherwise top-level translated constants will never be - * translated. But if by the time the model is instantiated no custom translation function has been set, we can set - * the default translation function as loaded so o-spreadsheet can be run in standalone with no translations. - */ -export function setDefaultTranslationMethod() { - if (_translate === defaultTranslate && _loaded === defaultLoaded) { - _loaded = () => true; - } -} - -export const _t: TranslationFunction = function (s: string, ...values: SprintfValues) { - if (!_loaded()) { - return new LazyTranslatedString(s, values) as unknown as string; - } - return sprintf(_translate(s), ...values); -}; - -class LazyTranslatedString extends String { - constructor(str: string, private values: SprintfValues) { - super(str); - } - - valueOf() { - const str = super.valueOf(); - return _loaded() ? sprintf(_translate(str), ...this.values) : sprintf(str, ...this.values); - } - toString() { - return this.valueOf(); - } -} +export { + _t, + setDefaultTranslationMethod, + setTranslationMethod, + type TranslationFunction, +} from "@odoo/o-spreadsheet-engine/translation"; diff --git a/src/types/errors.ts b/src/types/errors.ts index c1f1ca0674..20fde3e446 100644 --- a/src/types/errors.ts +++ b/src/types/errors.ts @@ -1,67 +1,13 @@ -import { _t } from "../translation"; - -export const CellErrorType = { - NotAvailable: "#N/A", - InvalidReference: "#REF", - BadExpression: "#BAD_EXPR", - CircularDependency: "#CYCLE", - UnknownFunction: "#NAME?", - DivisionByZero: "#DIV/0!", - SpilledBlocked: "#SPILL!", - GenericError: "#ERROR", - NullError: "#NULL!", -} as const; - -export type ErrorValue = (typeof CellErrorType)[keyof typeof CellErrorType]; - -export const errorTypes: Set = new Set(Object.values(CellErrorType)); - -export class EvaluationError { - constructor( - readonly message: string = _t("Error"), - readonly value: string = CellErrorType.GenericError - ) { - this.message = message.toString(); - } -} - -export class BadExpressionError extends EvaluationError { - constructor(message = _t("Invalid expression")) { - super(message, CellErrorType.BadExpression); - } -} -export class CircularDependencyError extends EvaluationError { - constructor(message = _t("Circular reference")) { - super(message, CellErrorType.CircularDependency); - } -} - -export class InvalidReferenceError extends EvaluationError { - constructor(message = _t("Invalid reference")) { - super(message, CellErrorType.InvalidReference); - } -} - -export class NotAvailableError extends EvaluationError { - constructor(message = _t("Data not available")) { - super(message, CellErrorType.NotAvailable); - } -} - -export class UnknownFunctionError extends EvaluationError { - constructor(message = _t("Unknown function")) { - super(message, CellErrorType.UnknownFunction); - } -} - -export class SplillBlockedError extends EvaluationError { - constructor(message = _t("Spill range is not empty")) { - super(message, CellErrorType.SpilledBlocked); - } -} - -export class DivisionByZeroError extends EvaluationError { - constructor(message = _t("Division by zero")) { - super(message, CellErrorType.DivisionByZero); - } -} +export { + BadExpressionError, + CellErrorType, + CircularDependencyError, + DivisionByZeroError, + EvaluationError, + InvalidReferenceError, + NotAvailableError, + SplillBlockedError, + UnknownFunctionError, + errorTypes, + type ErrorValue, +} from "@odoo/o-spreadsheet-engine/types/errors"; diff --git a/src/types/locale.ts b/src/types/locale.ts index 0007462140..4620846789 100644 --- a/src/types/locale.ts +++ b/src/types/locale.ts @@ -1,38 +1,6 @@ -import { Alias } from "./misc"; - -export type LocaleCode = string & Alias; - -export interface Locale { - name: string; - code: LocaleCode; - thousandsSeparator?: string; - decimalSeparator: string; - weekStart: number; //1 = Monday, 7 = Sunday - dateFormat: string; - timeFormat: string; - formulaArgSeparator: string; -} - -export const DEFAULT_LOCALES: Locale[] = [ - { - name: "English (US)", - code: "en_US", - thousandsSeparator: ",", - decimalSeparator: ".", - weekStart: 7, // Sunday - dateFormat: "m/d/yyyy", - timeFormat: "hh:mm:ss a", - formulaArgSeparator: ",", - }, - { - name: "French", - code: "fr_FR", - thousandsSeparator: " ", - decimalSeparator: ",", - weekStart: 1, // Monday - dateFormat: "dd/mm/yyyy", - timeFormat: "hh:mm:ss", - formulaArgSeparator: ";", - }, -]; -export const DEFAULT_LOCALE: Locale = DEFAULT_LOCALES[0]; +export { + DEFAULT_LOCALE, + DEFAULT_LOCALES, + type Locale, + type LocaleCode, +} from "@odoo/o-spreadsheet-engine/types/locale"; diff --git a/tsconfig.json b/tsconfig.json index f0015381ef..5bba300655 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,8 @@ "outDir": "build/js", "preserveWatchOutput": true, "paths": { - "@odoo/o-spreadsheet-engine": ["./packages/o-spreadsheet-engine/src/"] + "@odoo/o-spreadsheet-engine": ["./packages/o-spreadsheet-engine/src/index.ts"], + "@odoo/o-spreadsheet-engine/*": ["./packages/o-spreadsheet-engine/src/*"] } }, "include": ["src"] From c0683de99550e0fc7ae2644161484b05a47d5813 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 08:21:18 +0200 Subject: [PATCH 03/19] second codex test --- .../src/formulas/parser.ts | 384 ++++++++++++++++ .../src/formulas/range_tokenizer.ts | 121 +++++ packages/o-spreadsheet-engine/src/index.ts | 17 + src/formulas/parser.ts | 430 +----------------- src/formulas/range_tokenizer.ts | 163 +------ 5 files changed, 539 insertions(+), 576 deletions(-) create mode 100644 packages/o-spreadsheet-engine/src/formulas/parser.ts create mode 100644 packages/o-spreadsheet-engine/src/formulas/range_tokenizer.ts diff --git a/packages/o-spreadsheet-engine/src/formulas/parser.ts b/packages/o-spreadsheet-engine/src/formulas/parser.ts new file mode 100644 index 0000000000..ffba10afef --- /dev/null +++ b/packages/o-spreadsheet-engine/src/formulas/parser.ts @@ -0,0 +1,384 @@ +import { parseNumber, unquote } from "../helpers"; +import { _t } from "../translation"; +import { BadExpressionError, CellErrorType } from "../types/errors"; +import { DEFAULT_LOCALE } from "../types/locale"; +import { rangeTokenize } from "./range_tokenizer"; +import { Token } from "./tokenizer"; + +const functionRegex = /[a-zA-Z0-9\_]+(\.[a-zA-Z0-9\_]+)*/; + +const UNARY_OPERATORS_PREFIX = ["-", "+"]; +const UNARY_OPERATORS_POSTFIX = ["%"]; + +interface RichToken extends Token { + tokenIndex: number; +} + +export class TokenList { + private tokens: RichToken[]; + currentIndex = 0; + current: RichToken | undefined; + length: number; + + constructor(tokens: RichToken[]) { + this.tokens = tokens; + this.current = tokens[0]; + this.length = tokens.length; + } + + shift() { + const current = this.tokens[this.currentIndex]; + this.current = this.tokens[++this.currentIndex]; + return current; + } + + get next(): RichToken | undefined { + return this.tokens[this.currentIndex + 1]; + } +} + +interface ASTBase { + debug?: boolean; + tokenStartIndex: number; + tokenEndIndex: number; +} + +interface ASTNumber extends ASTBase { + type: "NUMBER"; + value: number; +} + +interface ASTReference extends ASTBase { + type: "REFERENCE"; + value: string; +} + +export interface ASTString extends ASTBase { + type: "STRING"; + value: string; +} + +interface ASTBoolean extends ASTBase { + type: "BOOLEAN"; + value: boolean; +} + +export interface ASTUnaryOperation extends ASTBase { + type: "UNARY_OPERATION"; + value: any; + operand: AST; + postfix?: boolean; +} + +export interface ASTOperation extends ASTBase { + type: "BIN_OPERATION"; + value: any; + left: AST; + right: AST; +} + +export interface ASTFuncall extends ASTBase { + type: "FUNCALL"; + value: string; + args: AST[]; +} + +export interface ASTSymbol extends ASTBase { + type: "SYMBOL"; + value: string; +} + +interface ASTEmpty extends ASTBase { + type: "EMPTY"; + value: ""; +} + +export type AST = + | ASTOperation + | ASTUnaryOperation + | ASTFuncall + | ASTSymbol + | ASTNumber + | ASTBoolean + | ASTString + | ASTReference + | ASTEmpty; + +export const OP_PRIORITY = { + "%": 40, + "^": 30, + "*": 20, + "/": 20, + "+": 15, + "-": 15, + "&": 13, + ">": 10, + "<>": 10, + ">=": 10, + "<": 10, + "<=": 10, + "=": 10, +}; + +function parseOperand(tokens: TokenList): AST { + const current = tokens.shift(); + if (!current) { + throw new BadExpressionError(); + } + switch (current.type) { + case "DEBUGGER": + const next = parseExpression(tokens, 1000); + next.debug = true; + return next; + case "NUMBER": + return { + type: "NUMBER", + value: parseNumber(current.value, DEFAULT_LOCALE), + tokenStartIndex: current.tokenIndex, + tokenEndIndex: current.tokenIndex, + }; + case "STRING": + return { + type: "STRING", + value: unquote(current.value), + tokenStartIndex: current.tokenIndex, + tokenEndIndex: current.tokenIndex, + }; + case "INVALID_REFERENCE": + return { + type: "REFERENCE", + value: CellErrorType.InvalidReference, + tokenStartIndex: current.tokenIndex, + tokenEndIndex: current.tokenIndex, + }; + case "REFERENCE": + if (tokens.current?.value === ":" && tokens.next?.type === "REFERENCE") { + tokens.shift(); + const rightReference = tokens.shift(); + return { + type: "REFERENCE", + value: `${current.value}:${rightReference?.value}`, + tokenStartIndex: current.tokenIndex, + tokenEndIndex: rightReference.tokenIndex, + }; + } + return { + type: "REFERENCE", + value: current.value, + tokenStartIndex: current.tokenIndex, + tokenEndIndex: current.tokenIndex, + }; + case "SYMBOL": + const value = current.value; + const nextToken = tokens.current; + if ( + nextToken?.type === "LEFT_PAREN" && + functionRegex.test(current.value) && + value === unquote(value, "'") + ) { + const { args, rightParen } = parseFunctionArgs(tokens); + return { + type: "FUNCALL", + value, + args, + tokenStartIndex: current.tokenIndex, + tokenEndIndex: rightParen.tokenIndex, + }; + } + const upperCaseValue = value.toUpperCase(); + if (upperCaseValue === "TRUE" || upperCaseValue === "FALSE") { + return { + type: "BOOLEAN", + value: upperCaseValue === "TRUE", + tokenStartIndex: current.tokenIndex, + tokenEndIndex: current.tokenIndex, + }; + } + return { + type: "SYMBOL", + value: unquote(current.value, "'"), + tokenStartIndex: current.tokenIndex, + tokenEndIndex: current.tokenIndex, + }; + case "LEFT_PAREN": + const result = parseExpression(tokens); + const rightParen = consumeOrThrow(tokens, "RIGHT_PAREN", _t("Missing closing parenthesis")); + return { + ...result, + tokenStartIndex: current.tokenIndex, + tokenEndIndex: rightParen.tokenIndex, + }; + case "OPERATOR": + const operator = current.value; + if (UNARY_OPERATORS_PREFIX.includes(operator)) { + const operand = parseExpression(tokens, OP_PRIORITY[operator]); + return { + type: "UNARY_OPERATION", + value: operator, + operand, + tokenStartIndex: current.tokenIndex, + tokenEndIndex: operand.tokenEndIndex, + }; + } + throw new BadExpressionError(_t("Unexpected token: %s", current.value)); + default: + throw new BadExpressionError(_t("Unexpected token: %s", current.value)); + } +} + +function parseFunctionArgs(tokens: TokenList) { + consumeOrThrow(tokens, "LEFT_PAREN", _t("Missing opening parenthesis")); + const nextToken = tokens.current; + if (nextToken?.type === "RIGHT_PAREN") { + const rightParen = consumeOrThrow(tokens, "RIGHT_PAREN"); + return { args: [], rightParen }; + } + const args: AST[] = []; + args.push(parseOneFunctionArg(tokens)); + while (tokens.current?.type !== "RIGHT_PAREN") { + consumeOrThrow(tokens, "ARG_SEPARATOR", _t("Wrong function call")); + args.push(parseOneFunctionArg(tokens)); + } + const rightParen = consumeOrThrow(tokens, "RIGHT_PAREN"); + return { args, rightParen }; +} + +function parseOneFunctionArg(tokens: TokenList): AST { + const nextToken = tokens.current; + if (nextToken?.type === "ARG_SEPARATOR" || nextToken?.type === "RIGHT_PAREN") { + return { + type: "EMPTY", + value: "", + tokenStartIndex: nextToken.tokenIndex, + tokenEndIndex: nextToken.tokenIndex, + }; + } + return parseExpression(tokens); +} + +function consumeOrThrow(tokens: TokenList, type, message?: string) { + const token = tokens.shift(); + if (!token || token.type !== type) { + throw new BadExpressionError(message); + } + return token; +} + +function parseExpression(tokens: TokenList, parentPriority = 0): AST { + if (tokens.length === 0) { + throw new BadExpressionError(); + } + let left = parseOperand(tokens); + while ( + tokens.current?.type === "OPERATOR" && + OP_PRIORITY[tokens.current.value] > parentPriority + ) { + const operatorToken = tokens.shift(); + const operator = operatorToken.value; + if (UNARY_OPERATORS_POSTFIX.includes(operator)) { + left = { + type: "UNARY_OPERATION", + value: operator, + operand: left, + postfix: true, + tokenStartIndex: left.tokenStartIndex, + tokenEndIndex: operatorToken.tokenIndex, + }; + } else { + const right = parseExpression(tokens, OP_PRIORITY[operator]); + left = { + type: "BIN_OPERATION", + value: operator, + left, + right, + tokenStartIndex: left.tokenStartIndex, + tokenEndIndex: right.tokenEndIndex, + }; + } + } + return left; +} + +export function parse(str: string): AST { + return parseTokens(rangeTokenize(str)); +} + +export function parseTokens(tokens: Token[]): AST { + const richTokens = tokens.map((token, index) => ({ + type: token.type, + value: token.value, + tokenIndex: index, + })); + const tokensToParse = richTokens.filter((token) => token.type !== "SPACE"); + const tokenList = new TokenList(tokensToParse); + if (tokenList.current?.value === "=") { + tokenList.shift(); + } + const result = parseExpression(tokenList); + if (tokenList.current) { + throw new BadExpressionError(); + } + return result; +} + +export function convertAstNodes( + ast: AST, + type: T, + fn: (ast: Extract) => AST +): AST { + return mapAst(ast, (candidate) => { + if (candidate.type === type) { + return fn(candidate as Extract); + } + return candidate; + }); +} + +export function iterateAstNodes(ast: AST): AST[] { + return Array.from(astIterator(ast)); +} + +function* astIterator(ast: AST): Iterable { + yield ast; + switch (ast.type) { + case "FUNCALL": + for (const arg of ast.args) { + yield* astIterator(arg); + } + break; + case "UNARY_OPERATION": + yield* astIterator(ast.operand); + break; + case "BIN_OPERATION": + yield* astIterator(ast.left); + yield* astIterator(ast.right); + break; + } +} + +export function mapAst( + ast: AST, + fn: (ast: Extract) => AST +): AST { + ast = fn(ast as Extract); + switch (ast.type) { + case "FUNCALL": + return { + ...ast, + args: ast.args.map((child) => mapAst(child, fn)), + }; + case "UNARY_OPERATION": + return { + ...ast, + operand: mapAst(ast.operand, fn), + }; + case "BIN_OPERATION": + return { + ...ast, + right: mapAst(ast.right, fn), + left: mapAst(ast.left, fn), + }; + default: + return ast; + } +} diff --git a/packages/o-spreadsheet-engine/src/formulas/range_tokenizer.ts b/packages/o-spreadsheet-engine/src/formulas/range_tokenizer.ts new file mode 100644 index 0000000000..e0de49485d --- /dev/null +++ b/packages/o-spreadsheet-engine/src/formulas/range_tokenizer.ts @@ -0,0 +1,121 @@ +import { + isColHeader, + isColReference, + isRowHeader, + isRowReference, + isSingleCellReference, +} from "../helpers"; +import { DEFAULT_LOCALE } from "../types/locale"; +import { Token, tokenize } from "./tokenizer"; + +enum State { + LeftRef, + RightRef, + Separator, + FullColumnSeparator, + FullRowSeparator, + RightColumnRef, + RightRowRef, + Found, +} + +const goTo = (state: State, guard: (token: Token) => boolean = () => true) => [ + { + goTo: state, + guard, + }, +]; + +const goToMulti = (state: State, guard: (token: Token) => boolean = () => true) => ({ + goTo: state, + guard, +}); + +interface Transition { + goTo: State; + guard: (token: Token) => boolean; +} + +type Machine = { + [s in State]: Record; +}; + +const machine: Machine = { + [State.LeftRef]: { + REFERENCE: goTo(State.Separator), + NUMBER: goTo(State.FullRowSeparator), + SYMBOL: [ + goToMulti(State.FullColumnSeparator, (token) => isColReference(token.value)), + goToMulti(State.FullRowSeparator, (token) => isRowReference(token.value)), + ], + }, + [State.FullColumnSeparator]: { + SPACE: goTo(State.FullColumnSeparator), + OPERATOR: goTo(State.RightColumnRef, (token) => token.value === ":"), + }, + [State.FullRowSeparator]: { + SPACE: goTo(State.FullRowSeparator), + OPERATOR: goTo(State.RightRowRef, (token) => token.value === ":"), + }, + [State.Separator]: { + SPACE: goTo(State.Separator), + OPERATOR: goTo(State.RightRef, (token) => token.value === ":"), + }, + [State.RightRef]: { + SPACE: goTo(State.RightRef), + NUMBER: goTo(State.Found), + REFERENCE: goTo(State.Found, (token) => isSingleCellReference(token.value)), + SYMBOL: goTo(State.Found, (token) => isColHeader(token.value) || isRowHeader(token.value)), + }, + [State.RightColumnRef]: { + SPACE: goTo(State.RightColumnRef), + SYMBOL: goTo(State.Found, (token) => isColHeader(token.value)), + REFERENCE: goTo(State.Found, (token) => isSingleCellReference(token.value)), + }, + [State.RightRowRef]: { + SPACE: goTo(State.RightRowRef), + NUMBER: goTo(State.Found), + REFERENCE: goTo(State.Found, (token) => isSingleCellReference(token.value)), + SYMBOL: goTo(State.Found, (token) => isRowHeader(token.value)), + }, + [State.Found]: {}, +}; + +function matchReference(tokens: Token[]): Token | null { + let head = 0; + let transitions = machine[State.LeftRef]; + let matchedTokens = ""; + while (transitions !== undefined) { + const token = tokens[head++]; + if (!token) { + return null; + } + const transition = transitions[token.type]?.find((candidate) => candidate.guard(token)); + const nextState = transition ? transition.goTo : undefined; + switch (nextState) { + case undefined: + return null; + case State.Found: + matchedTokens += token.value; + tokens.splice(0, head); + return { + type: "REFERENCE", + value: matchedTokens, + }; + default: + transitions = machine[nextState]; + matchedTokens += token.value; + break; + } + } + return null; +} + +export function rangeTokenize(formula: string, locale = DEFAULT_LOCALE): Token[] { + const tokens = tokenize(formula, locale); + const result: Token[] = []; + while (tokens.length) { + result.push(matchReference(tokens) || tokens.shift()!); + } + return result; +} diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts index aadbc0e833..e11e122c32 100644 --- a/packages/o-spreadsheet-engine/src/index.ts +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -1,3 +1,20 @@ +export { + OP_PRIORITY, + convertAstNodes, + iterateAstNodes, + mapAst, + parse, + parseTokens, +} from "./formulas/parser"; +export type { + AST, + ASTFuncall, + ASTOperation, + ASTString, + ASTSymbol, + ASTUnaryOperation, +} from "./formulas/parser"; +export { rangeTokenize } from "./formulas/range_tokenizer"; export { POSTFIX_UNARY_OPERATORS, tokenize } from "./formulas/tokenizer"; export type { Token } from "./formulas/tokenizer"; export * from "./helpers"; diff --git a/src/formulas/parser.ts b/src/formulas/parser.ts index 059b649c9d..c2bb30803c 100644 --- a/src/formulas/parser.ts +++ b/src/formulas/parser.ts @@ -1,414 +1,16 @@ -import { parseNumber, unquote } from "../helpers/index"; -import { _t } from "../translation"; -import { DEFAULT_LOCALE } from "../types"; -import { BadExpressionError, CellErrorType } from "../types/errors"; -import { rangeTokenize } from "./range_tokenizer"; -import { Token } from "./tokenizer"; - -const functionRegex = /[a-zA-Z0-9\_]+(\.[a-zA-Z0-9\_]+)*/; - -const UNARY_OPERATORS_PREFIX = ["-", "+"]; -const UNARY_OPERATORS_POSTFIX = ["%"]; - -interface RichToken extends Token { - tokenIndex: number; -} - -export class TokenList { - private tokens: RichToken[]; - currentIndex: number = 0; - current: RichToken | undefined; - length: number; - - constructor(tokens: RichToken[]) { - this.tokens = tokens; - this.current = tokens[0]; - this.length = tokens.length; - } - - shift() { - const current = this.tokens[this.currentIndex]; - this.current = this.tokens[++this.currentIndex]; - return current; - } - - get next(): RichToken | undefined { - return this.tokens[this.currentIndex + 1]; - } -} - -// ----------------------------------------------------------------------------- -// PARSER -// ----------------------------------------------------------------------------- -interface ASTBase { - debug?: boolean; - tokenStartIndex: number; - tokenEndIndex: number; -} - -interface ASTNumber extends ASTBase { - type: "NUMBER"; - value: number; -} - -interface ASTReference extends ASTBase { - type: "REFERENCE"; - value: string; -} - -export interface ASTString extends ASTBase { - type: "STRING"; - value: string; -} - -interface ASTBoolean extends ASTBase { - type: "BOOLEAN"; - value: boolean; -} - -export interface ASTUnaryOperation extends ASTBase { - type: "UNARY_OPERATION"; - value: any; - operand: AST; - postfix?: boolean; // needed to rebuild string from ast -} - -export interface ASTOperation extends ASTBase { - type: "BIN_OPERATION"; - value: any; - left: AST; - right: AST; -} - -export interface ASTFuncall extends ASTBase { - type: "FUNCALL"; - value: string; - args: AST[]; -} - -export interface ASTSymbol extends ASTBase { - type: "SYMBOL"; - value: string; -} - -interface ASTEmpty extends ASTBase { - type: "EMPTY"; - value: ""; -} - -export type AST = - | ASTOperation - | ASTUnaryOperation - | ASTFuncall - | ASTSymbol - | ASTNumber - | ASTBoolean - | ASTString - | ASTReference - | ASTEmpty; - -export const OP_PRIORITY = { - "%": 40, - "^": 30, - "*": 20, - "/": 20, - "+": 15, - "-": 15, - "&": 13, - ">": 10, - "<>": 10, - ">=": 10, - "<": 10, - "<=": 10, - "=": 10, -}; - -/** - * Parse the next operand in an arithmetic expression. - * e.g. - * for 1+2*3, the next operand is 1 - * for (1+2)*3, the next operand is (1+2) - * for SUM(1,2)+3, the next operand is SUM(1,2) - */ -function parseOperand(tokens: TokenList): AST { - const current = tokens.shift(); - if (!current) { - throw new BadExpressionError(); - } - switch (current.type) { - case "DEBUGGER": - const next = parseExpression(tokens, 1000); - next.debug = true; - return next; - case "NUMBER": - return { - type: "NUMBER", - value: parseNumber(current.value, DEFAULT_LOCALE), - tokenStartIndex: current.tokenIndex, - tokenEndIndex: current.tokenIndex, - }; - case "STRING": - return { - type: "STRING", - value: unquote(current.value), - tokenStartIndex: current.tokenIndex, - tokenEndIndex: current.tokenIndex, - }; - case "INVALID_REFERENCE": - return { - type: "REFERENCE", - value: CellErrorType.InvalidReference, - tokenStartIndex: current.tokenIndex, - tokenEndIndex: current.tokenIndex, - }; - - case "REFERENCE": - if (tokens.current?.value === ":" && tokens.next?.type === "REFERENCE") { - tokens.shift(); - const rightReference = tokens.shift(); - return { - type: "REFERENCE", - value: `${current.value}:${rightReference?.value}`, - tokenStartIndex: current.tokenIndex, - tokenEndIndex: rightReference.tokenIndex, - }; - } - return { - type: "REFERENCE", - value: current.value, - tokenStartIndex: current.tokenIndex, - tokenEndIndex: current.tokenIndex, - }; - case "SYMBOL": - const value = current.value; - const nextToken = tokens.current; - if ( - nextToken?.type === "LEFT_PAREN" && - functionRegex.test(current.value) && - value === unquote(value, "'") - ) { - const { args, rightParen } = parseFunctionArgs(tokens); - return { - type: "FUNCALL", - value: value, - args, - tokenStartIndex: current.tokenIndex, - tokenEndIndex: rightParen.tokenIndex, - }; - } - const upperCaseValue = value.toUpperCase(); - if (upperCaseValue === "TRUE" || upperCaseValue === "FALSE") { - return { - type: "BOOLEAN", - value: upperCaseValue === "TRUE", - tokenStartIndex: current.tokenIndex, - tokenEndIndex: current.tokenIndex, - }; - } - return { - type: "SYMBOL", - value: unquote(current.value, "'"), - tokenStartIndex: current.tokenIndex, - tokenEndIndex: current.tokenIndex, - }; - case "LEFT_PAREN": - const result = parseExpression(tokens); - const rightParen = consumeOrThrow(tokens, "RIGHT_PAREN", _t("Missing closing parenthesis")); - return { - ...result, - tokenStartIndex: current.tokenIndex, - tokenEndIndex: rightParen.tokenIndex, - }; - case "OPERATOR": - const operator = current.value; - if (UNARY_OPERATORS_PREFIX.includes(operator)) { - const operand = parseExpression(tokens, OP_PRIORITY[operator]); - return { - type: "UNARY_OPERATION", - value: operator, - operand, - tokenStartIndex: current.tokenIndex, - tokenEndIndex: operand.tokenEndIndex, - }; - } - throw new BadExpressionError(_t("Unexpected token: %s", current.value)); - default: - throw new BadExpressionError(_t("Unexpected token: %s", current.value)); - } -} - -function parseFunctionArgs(tokens: TokenList) { - consumeOrThrow(tokens, "LEFT_PAREN", _t("Missing opening parenthesis")); - const nextToken = tokens.current; - if (nextToken?.type === "RIGHT_PAREN") { - const rightParen = consumeOrThrow(tokens, "RIGHT_PAREN"); - return { args: [], rightParen }; - } - const args: AST[] = []; - args.push(parseOneFunctionArg(tokens)); - while (tokens.current?.type !== "RIGHT_PAREN") { - consumeOrThrow(tokens, "ARG_SEPARATOR", _t("Wrong function call")); - args.push(parseOneFunctionArg(tokens)); - } - const rightParen = consumeOrThrow(tokens, "RIGHT_PAREN"); - return { args, rightParen }; -} - -function parseOneFunctionArg(tokens: TokenList): AST { - const nextToken = tokens.current; - if (nextToken?.type === "ARG_SEPARATOR" || nextToken?.type === "RIGHT_PAREN") { - // arg is empty: "sum(1,,2)" "sum(,1)" "sum(1,)" - return { - type: "EMPTY", - value: "", - tokenStartIndex: nextToken.tokenIndex, - tokenEndIndex: nextToken.tokenIndex, - }; - } - return parseExpression(tokens); -} - -function consumeOrThrow(tokens: TokenList, type, message?: string) { - const token = tokens.shift(); - if (!token || token.type !== type) { - throw new BadExpressionError(message); - } - return token; -} - -function parseExpression(tokens: TokenList, parent_priority: number = 0): AST { - if (tokens.length === 0) { - throw new BadExpressionError(); - } - let left = parseOperand(tokens); - // as long as we have operators with higher priority than the parent one, - // continue parsing the expression because it is a child sub-expression - while ( - tokens.current?.type === "OPERATOR" && - OP_PRIORITY[tokens.current.value] > parent_priority - ) { - const operatorToken = tokens.shift(); - const operator = operatorToken.value; - if (UNARY_OPERATORS_POSTFIX.includes(operator)) { - left = { - type: "UNARY_OPERATION", - value: operator, - operand: left, - postfix: true, - tokenStartIndex: left.tokenStartIndex, - tokenEndIndex: operatorToken.tokenIndex, - }; - } else { - const right = parseExpression(tokens, OP_PRIORITY[operator]); - left = { - type: "BIN_OPERATION", - value: operator, - left, - right, - tokenStartIndex: left.tokenStartIndex, - tokenEndIndex: right.tokenEndIndex, - }; - } - } - return left; -} - -/** - * Parse an expression (as a string) into an AST. - */ -export function parse(str: string): AST { - return parseTokens(rangeTokenize(str)); -} - -export function parseTokens(tokens: Token[]): AST { - const richTokens = tokens.map((token, index) => ({ - type: token.type, - value: token.value, - tokenIndex: index, - })); - const tokensToParse = richTokens.filter((x) => x.type !== "SPACE"); - const tokenList = new TokenList(tokensToParse); - if (tokenList.current?.value === "=") { - tokenList.shift(); - } - const result = parseExpression(tokenList); - if (tokenList.current) { - throw new BadExpressionError(); - } - return result; -} - -/** - * Allows to visit all nodes of an AST and apply a mapping function - * to nodes of a specific type. - * Useful if you want to convert some part of a formula. - * - * @example - * convertAstNodes(ast, "FUNCALL", convertFormulaToExcel) - * - * function convertFormulaToExcel(ast: ASTFuncall) { - * // ... - * return modifiedAst - * } - */ -export function convertAstNodes( - ast: AST, - type: T, - fn: (ast: Extract) => AST -): AST { - return mapAst(ast, (ast) => { - if (ast.type === type) { - return fn(ast as Extract); - } - return ast; - }); -} - -export function iterateAstNodes(ast: AST): AST[] { - return Array.from(astIterator(ast)); -} - -function* astIterator(ast: AST): Iterable { - yield ast; - switch (ast.type) { - case "FUNCALL": - for (const arg of ast.args) { - yield* astIterator(arg); - } - break; - case "UNARY_OPERATION": - yield* astIterator(ast.operand); - break; - case "BIN_OPERATION": - yield* astIterator(ast.left); - yield* astIterator(ast.right); - break; - } -} - -export function mapAst( - ast: AST, - fn: (ast: Extract) => AST -): AST { - ast = fn(ast as Extract); - switch (ast.type) { - case "FUNCALL": - return { - ...ast, - args: ast.args.map((child) => mapAst(child, fn)), - }; - case "UNARY_OPERATION": - return { - ...ast, - operand: mapAst(ast.operand, fn), - }; - case "BIN_OPERATION": - return { - ...ast, - right: mapAst(ast.right, fn), - left: mapAst(ast.left, fn), - }; - default: - return ast; - } -} +export { + OP_PRIORITY, + convertAstNodes, + iterateAstNodes, + mapAst, + parse, + parseTokens, +} from "@odoo/o-spreadsheet-engine/formulas/parser"; +export type { + AST, + ASTFuncall, + ASTOperation, + ASTString, + ASTSymbol, + ASTUnaryOperation, +} from "@odoo/o-spreadsheet-engine/formulas/parser"; diff --git a/src/formulas/range_tokenizer.ts b/src/formulas/range_tokenizer.ts index 37c99bf642..31c9a487cc 100644 --- a/src/formulas/range_tokenizer.ts +++ b/src/formulas/range_tokenizer.ts @@ -1,162 +1 @@ -import { - isColHeader, - isColReference, - isRowHeader, - isRowReference, - isSingleCellReference, -} from "../helpers"; -import { DEFAULT_LOCALE } from "./../types/locale"; -import { Token, tokenize } from "./tokenizer"; - -enum State { - /** - * Initial state. - * Expecting any reference for the left part of a range - * e.g. "A1", "1", "A", "Sheet1!A1", "Sheet1!A" - */ - LeftRef, - /** - * Expecting any reference for the right part of a range - * e.g. "A1", "1", "A", "Sheet1!A1", "Sheet1!A" - */ - RightRef, - /** - * Expecting the separator without any constraint on the right part - */ - Separator, - /** - * Expecting the separator for a full column range - */ - FullColumnSeparator, - /** - * Expecting the separator for a full row range - */ - FullRowSeparator, - /** - * Expecting the right part of a full column range - * e.g. "1", "A1" - */ - RightColumnRef, - /** - * Expecting the right part of a full row range - * e.g. "A", "A1" - */ - RightRowRef, - /** - * Final state. A range has been matched - */ - Found, -} - -const goTo = (state: State, guard: (token: Token) => boolean = () => true) => [ - { - goTo: state, - guard, - }, -]; - -const goToMulti = (state: State, guard: (token: Token) => boolean = () => true) => ({ - goTo: state, - guard, -}); - -interface Transition { - goTo: State; - guard: (token: Token) => boolean; -} - -type Machine = { - [s in State]: Record; -}; - -const machine: Machine = { - [State.LeftRef]: { - REFERENCE: goTo(State.Separator), - NUMBER: goTo(State.FullRowSeparator), - SYMBOL: [ - goToMulti(State.FullColumnSeparator, (token) => isColReference(token.value)), - goToMulti(State.FullRowSeparator, (token) => isRowReference(token.value)), - ], - }, - [State.FullColumnSeparator]: { - SPACE: goTo(State.FullColumnSeparator), - OPERATOR: goTo(State.RightColumnRef, (token) => token.value === ":"), - }, - [State.FullRowSeparator]: { - SPACE: goTo(State.FullRowSeparator), - OPERATOR: goTo(State.RightRowRef, (token) => token.value === ":"), - }, - [State.Separator]: { - SPACE: goTo(State.Separator), - OPERATOR: goTo(State.RightRef, (token) => token.value === ":"), - }, - [State.RightRef]: { - SPACE: goTo(State.RightRef), - NUMBER: goTo(State.Found), - REFERENCE: goTo(State.Found, (token) => isSingleCellReference(token.value)), - SYMBOL: goTo(State.Found, (token) => isColHeader(token.value) || isRowHeader(token.value)), - }, - [State.RightColumnRef]: { - SPACE: goTo(State.RightColumnRef), - SYMBOL: goTo(State.Found, (token) => isColHeader(token.value)), - REFERENCE: goTo(State.Found, (token) => isSingleCellReference(token.value)), - }, - [State.RightRowRef]: { - SPACE: goTo(State.RightRowRef), - NUMBER: goTo(State.Found), - REFERENCE: goTo(State.Found, (token) => isSingleCellReference(token.value)), - SYMBOL: goTo(State.Found, (token) => isRowHeader(token.value)), - }, - [State.Found]: {}, -}; - -/** - * Check if the list of tokens starts with a sequence of tokens representing - * a range. - * If a range is found, the sequence is removed from the list and is returned - * as a single token. - */ -function matchReference(tokens: Token[]): Token | null { - let head = 0; - let transitions = machine[State.LeftRef]; - let matchedTokens: string = ""; - while (transitions !== undefined) { - const token = tokens[head++]; - if (!token) { - return null; - } - const transition = transitions[token.type]?.find((transition) => transition.guard(token)); - const nextState = transition ? transition.goTo : undefined; - switch (nextState) { - case undefined: - return null; - case State.Found: - matchedTokens += token.value; - tokens.splice(0, head); - return { - type: "REFERENCE", - value: matchedTokens, - }; - default: - transitions = machine[nextState]; - matchedTokens += token.value; - break; - } - } - return null; -} - -/** - * Take the result of the tokenizer and transform it to be usable in the - * manipulations of range - * - * @param formula - */ -export function rangeTokenize(formula: string, locale = DEFAULT_LOCALE): Token[] { - const tokens = tokenize(formula, locale); - const result: Token[] = []; - while (tokens.length) { - result.push(matchReference(tokens) || tokens.shift()!); - } - return result; -} +export { rangeTokenize } from "@odoo/o-spreadsheet-engine/formulas/range_tokenizer"; From 1f757a7f86503606f049f538bea3b04ee63c5094 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 08:54:58 +0200 Subject: [PATCH 04/19] third codex test --- .../o-spreadsheet-engine/src/types/base.ts | 38 +++ .../o-spreadsheet-engine/src/types/pivot.ts | 247 ++++++++++++++++++ .../src/types/pivot_runtime.ts | 58 ++++ 3 files changed, 343 insertions(+) create mode 100644 packages/o-spreadsheet-engine/src/types/base.ts create mode 100644 packages/o-spreadsheet-engine/src/types/pivot.ts create mode 100644 packages/o-spreadsheet-engine/src/types/pivot_runtime.ts diff --git a/packages/o-spreadsheet-engine/src/types/base.ts b/packages/o-spreadsheet-engine/src/types/base.ts new file mode 100644 index 0000000000..fc50531112 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/base.ts @@ -0,0 +1,38 @@ +export type Alias = {} & {}; + +export type UID = string & Alias; + +export type HeaderIndex = number & Alias; + +export interface CellPosition { + col: HeaderIndex; + row: HeaderIndex; + sheetId: UID; +} + +export interface Zone { + left: HeaderIndex; + right: HeaderIndex; + top: HeaderIndex; + bottom: HeaderIndex; +} + +export type CellValue = string | number | boolean | null; + +export type Format = string & Alias; + +export type Maybe = T | undefined; + +export type Matrix = T[][]; + +export type Dimension = "COL" | "ROW"; + +export type SortDirection = "asc" | "desc"; + +export interface FunctionResultObject { + value: CellValue; + format?: Format; + errorOriginPosition?: CellPosition; + message?: string; + origin?: CellPosition; +} diff --git a/packages/o-spreadsheet-engine/src/types/pivot.ts b/packages/o-spreadsheet-engine/src/types/pivot.ts new file mode 100644 index 0000000000..d5bc0ffec5 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/pivot.ts @@ -0,0 +1,247 @@ +import { + CellValue, + Dimension, + Format, + FunctionResultObject, + SortDirection, + UID, + Zone, +} from "./base"; +import { Locale } from "./locale"; + +export const PREVIOUS_VALUE = "(previous)" as const; +export const NEXT_VALUE = "(next)" as const; + +export type Aggregator = + | "array_agg" + | "count" + | "count_distinct" + | "bool_and" + | "bool_or" + | "max" + | "min" + | "avg" + | "sum"; + +export type Granularity = + | "day" + | "week" + | "month" + | "quarter" + | "year" + | "second_number" + | "minute_number" + | "hour_number" + | "day_of_week" + | "day_of_month" + | "iso_week_number" + | "month_number" + | "quarter_number"; + +export interface PivotCoreDimension { + fieldName: string; + order?: SortDirection; + granularity?: Granularity | string; + isCustomField?: boolean; + parentField?: string; + customGroups?: PivotCustomGroup[]; +} + +export interface PivotCoreMeasure { + id: string; + userDefinedName?: string; + fieldName: string; + aggregator: Aggregator | string; + isHidden?: boolean; + format?: Format; + computedBy?: { sheetId: UID; formula: string }; + display?: PivotMeasureDisplay; +} + +export interface CommonPivotCoreDefinition { + columns: PivotCoreDimension[]; + rows: PivotCoreDimension[]; + measures: PivotCoreMeasure[]; + name: string; + deferUpdates?: boolean; + sortedColumn?: PivotSortedColumn; + collapsedDomains?: PivotCollapsedDomains; + customFields?: Record; +} + +export interface PivotSortedColumn { + order: SortDirection; + domain: PivotDomain; + measure: string; +} + +export interface PivotCollapsedDomains { + COL: PivotDomain[]; + ROW: PivotDomain[]; +} + +export interface PivotCustomGroupedField { + parentField: string; + name: string; + groups: PivotCustomGroup[]; +} + +export interface PivotCustomGroup { + name: string; + values: CellValue[]; + isOtherGroup?: boolean; +} + +export interface SpreadsheetPivotCoreDefinition extends CommonPivotCoreDefinition { + type: "SPREADSHEET"; + dataSet?: { + sheetId: UID; + zone: Zone; + }; +} + +interface FakePivotDefinition extends CommonPivotCoreDefinition { + type: "FAKE"; +} + +export type PivotCoreDefinition = SpreadsheetPivotCoreDefinition | FakePivotDefinition; + +export type TechnicalName = string; + +export interface PivotField { + name: TechnicalName; + type: string; + string: string; + aggregator?: string; + help?: string; + isCustomField?: boolean; + parentField?: string; + customGroups?: PivotCustomGroup[]; +} + +export type PivotFields = Record; + +export interface PivotMeasure extends PivotCoreMeasure { + displayName: string; + type: string; + isValid: boolean; +} + +export interface PivotDimension extends PivotCoreDimension { + nameWithGranularity: string; + displayName: string; + type: string; + isValid: boolean; +} + +export interface PivotTableColumn { + fields: string[]; + values: CellValue[]; + width: number; + offset: number; +} + +export interface PivotTableRow { + fields: string[]; + values: CellValue[]; + indent: number; +} + +export interface PivotTableData { + cols: PivotTableColumn[][]; + rows: PivotTableRow[]; + measures: string[]; + fieldsType?: Record; +} + +export interface PivotHeaderCell { + type: "HEADER"; + domain: PivotDomain; + dimension: Dimension; +} + +export interface PivotMeasureHeaderCell { + type: "MEASURE_HEADER"; + domain: PivotDomain; + measure: string; +} + +export interface PivotValueCell { + type: "VALUE"; + domain: PivotDomain; + measure: string; +} + +export interface PivotEmptyCell { + type: "EMPTY"; +} + +export type PivotTableCell = + | PivotHeaderCell + | PivotMeasureHeaderCell + | PivotValueCell + | PivotEmptyCell; + +export interface PivotTimeAdapterNotNull { + normalizeFunctionValue: (value: Exclude) => T; + toValueAndFormat: (normalizedValue: T, locale?: Locale) => FunctionResultObject; + toFunctionValue: (normalizedValue: T) => string; +} + +export interface PivotTimeAdapter { + normalizeFunctionValue: (value: CellValue) => T | null; + toValueAndFormat: (normalizedValue: T, locale?: Locale) => FunctionResultObject; + toFunctionValue: (normalizedValue: T) => string; +} + +export interface PivotNode { + field: string; + type: string; + value: CellValue; +} + +export type PivotDomain = PivotNode[]; + +export interface PivotColRowDomain { + colDomain: PivotDomain; + rowDomain: PivotDomain; +} + +export interface PivotMeasureDisplay { + type: PivotMeasureDisplayType; + fieldNameWithGranularity?: string; + value?: string | boolean | number | typeof PREVIOUS_VALUE | typeof NEXT_VALUE; +} + +export type PivotMeasureDisplayType = + | "no_calculations" + | "%_of_grand_total" + | "%_of_col_total" + | "%_of_row_total" + | "%_of_parent_row_total" + | "%_of_parent_col_total" + | "index" + | "%_of_parent_total" + | "running_total" + | "%_running_total" + | "rank_asc" + | "rank_desc" + | "%_of" + | "difference_from" + | "%_difference_from"; + +export interface DimensionTreeNode { + value: CellValue; + field: string; + type: string; + children: DimensionTree; + width: number; +} + +export type DimensionTree = DimensionTreeNode[]; + +export interface PivotVisibilityOptions { + displayColumnHeaders: boolean; + displayTotals: boolean; + displayMeasuresRow: boolean; +} diff --git a/packages/o-spreadsheet-engine/src/types/pivot_runtime.ts b/packages/o-spreadsheet-engine/src/types/pivot_runtime.ts new file mode 100644 index 0000000000..b0c8585406 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/pivot_runtime.ts @@ -0,0 +1,58 @@ +import { FunctionResultObject, Maybe } from "./base"; +import { + PivotCollapsedDomains, + PivotCoreDefinition, + PivotCustomGroupedField, + PivotDimension, + PivotDomain, + PivotFields, + PivotMeasure, + PivotSortedColumn, +} from "./pivot"; + +export interface PivotRuntimeDefinition { + readonly measures: PivotMeasure[]; + readonly columns: PivotDimension[]; + readonly rows: PivotDimension[]; + readonly sortedColumn?: PivotSortedColumn; + readonly collapsedDomains?: PivotCollapsedDomains; + readonly customFields?: Record; + getDimension(nameWithGranularity: string): PivotDimension; + getMeasure(id: string): PivotMeasure; + [key: string]: unknown; +} + +export interface SpreadsheetPivotTable { + columns: unknown; + rows: unknown; + measures: string[]; + fieldsType: Record; + [key: string]: unknown; +} + +export interface InitPivotParams { + reload?: boolean; +} + +export interface Pivot { + type: PivotCoreDefinition["type"]; + definition: T; + init(params?: InitPivotParams): void; + isValid(): boolean; + onDefinitionChange(nextDefinition: PivotCoreDefinition): void; + getCollapsedTableStructure(): SpreadsheetPivotTable; + getExpandedTableStructure(): SpreadsheetPivotTable; + getFields(): PivotFields; + getPivotHeaderValueAndFormat(domain: PivotDomain): FunctionResultObject; + getPivotCellValueAndFormat(measure: string, domain: PivotDomain): FunctionResultObject; + getPivotMeasureValue(measure: string, domain: PivotDomain): FunctionResultObject; + getMeasure(id: string): PivotMeasure; + parseArgsToPivotDomain(args: Maybe[]): PivotDomain; + areDomainArgsFieldsValid(args: Maybe[]): boolean; + assertIsValid(options: { throwOnError: boolean }): FunctionResultObject | undefined; + getPossibleFieldValues( + dimension: PivotDimension + ): { value: string | boolean | number; label: string }[]; + needsReevaluation: boolean; + markAsDirtyForEvaluation?(): void; +} From a22cd4047883836a64ccf7bed28d4e62e8e38e44 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 09:04:36 +0200 Subject: [PATCH 05/19] compiler codex test --- .../src/functions/function_registry.ts | 58 +++++++++++++++++++ packages/o-spreadsheet-engine/src/index.ts | 5 ++ packages/o-spreadsheet-engine/src/registry.ts | 39 +++++++++++++ src/functions/index.ts | 42 ++++++-------- 4 files changed, 121 insertions(+), 23 deletions(-) create mode 100644 packages/o-spreadsheet-engine/src/functions/function_registry.ts create mode 100644 packages/o-spreadsheet-engine/src/registry.ts diff --git a/packages/o-spreadsheet-engine/src/functions/function_registry.ts b/packages/o-spreadsheet-engine/src/functions/function_registry.ts new file mode 100644 index 0000000000..29d617d5f9 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/functions/function_registry.ts @@ -0,0 +1,58 @@ +import { Registry } from "../registry"; + +interface ProcessResult { + key: string; + stored: TStored; + mapped: TMapped; +} + +export abstract class FunctionRegistry { + private registry = new Registry(); + mapping: Record = {} as Record; + + get content(): Record { + return this.registry.content; + } + + add(name: string, descriptor: TInput): this { + const prepared = this.process(name, descriptor); + if (this.registry.contains(prepared.key)) { + throw new Error(`${prepared.key} is already present in this registry!`); + } + return this.set(prepared); + } + + replace(name: string, descriptor: TInput): this { + const prepared = this.process(name, descriptor); + return this.set(prepared); + } + + get(key: string): TStored { + return this.registry.get(key); + } + + contains(key: string): boolean { + return this.registry.contains(key); + } + + getAll(): TStored[] { + return this.registry.getAll(); + } + + getKeys(): string[] { + return this.registry.getKeys(); + } + + remove(key: string): void { + delete this.mapping[key]; + this.registry.remove(key); + } + + protected abstract process(name: string, descriptor: TInput): ProcessResult; + + private set(prepared: ProcessResult): this { + this.mapping[prepared.key] = prepared.mapped; + this.registry.replace(prepared.key, prepared.stored); + return this; + } +} diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts index e11e122c32..2b25b721e7 100644 --- a/packages/o-spreadsheet-engine/src/index.ts +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -17,7 +17,12 @@ export type { export { rangeTokenize } from "./formulas/range_tokenizer"; export { POSTFIX_UNARY_OPERATORS, tokenize } from "./formulas/tokenizer"; export type { Token } from "./formulas/tokenizer"; +export { FunctionRegistry } from "./functions/function_registry"; export * from "./helpers"; +export { Registry } from "./registry"; export * from "./translation"; +export * from "./types/base"; export * from "./types/errors"; export * from "./types/locale"; +export * from "./types/pivot"; +export * from "./types/pivot_runtime"; diff --git a/packages/o-spreadsheet-engine/src/registry.ts b/packages/o-spreadsheet-engine/src/registry.ts new file mode 100644 index 0000000000..76e952a57b --- /dev/null +++ b/packages/o-spreadsheet-engine/src/registry.ts @@ -0,0 +1,39 @@ +export class Registry { + content: Record = {}; + + add(key: string, value: T): this { + if (key in this.content) { + throw new Error(`${key} is already present in this registry!`); + } + return this.replace(key, value); + } + + replace(key: string, value: T): this { + this.content[key] = value; + return this; + } + + get(key: string): T { + const content = this.content[key]; + if (!content && !(key in this.content)) { + throw new Error(`Cannot find ${key} in this registry!`); + } + return content; + } + + contains(key: string): boolean { + return key in this.content; + } + + getAll(): T[] { + return Object.values(this.content); + } + + getKeys(): string[] { + return Object.keys(this.content); + } + + remove(key: string): void { + delete this.content[key]; + } +} diff --git a/src/functions/index.ts b/src/functions/index.ts index 59ae1b120c..f19e348c72 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -1,3 +1,4 @@ +import { FunctionRegistry as EngineFunctionRegistry } from "@odoo/o-spreadsheet-engine"; import { CellComposerStore } from "../components/composer/composer/cell_composer_store"; import { tokenColors } from "../constants"; import { EnrichedToken } from "../formulas/composer_tokenizer"; @@ -5,7 +6,6 @@ import { AutoCompleteProposal, autoCompleteProviders, } from "../registries/auto_completes/auto_complete_registry"; -import { Registry } from "../registries/registry"; import { _t } from "../translation"; import { AddFunctionDescription, @@ -38,6 +38,7 @@ import * as parser from "./module_parser"; import * as statistical from "./module_statistical"; import * as text from "./module_text"; import * as web from "./module_web"; +export { FunctionRegistry } from "@odoo/o-spreadsheet-engine"; export { arg } from "./arguments"; @@ -68,38 +69,33 @@ const functionNameRegex = /^[A-Z0-9\_\.]+$/; // Function registry //------------------------------------------------------------------------------ -export class FunctionRegistry extends Registry { - mapping: { - [key: string]: ComputeFunction | FunctionResultObject>; - } = {}; - - add(name: string, addDescr: AddFunctionDescription) { - name = name.toUpperCase(); - if (name in this.content) { - throw new Error(`${name} is already present in this registry!`); - } - return this.replace(name, addDescr); - } - - replace(name: string, addDescr: AddFunctionDescription) { - name = name.toUpperCase(); - if (!functionNameRegex.test(name)) { +class SpreadsheetFunctionRegistry extends EngineFunctionRegistry< + AddFunctionDescription, + FunctionDescription, + ComputeFunction | FunctionResultObject> +> { + protected process(name: string, addDescr: AddFunctionDescription) { + const normalizedName = name.toUpperCase(); + if (!functionNameRegex.test(normalizedName)) { throw new Error( _t( "Invalid function name %s. Function names can exclusively contain alphanumerical values separated by dots (.) or underscore (_)", - name + normalizedName ) ); } - const descr = addMetaInfoFromArg(name, addDescr); + const descr = addMetaInfoFromArg(normalizedName, addDescr); validateArguments(descr); - this.mapping[name] = createComputeFunction(descr); - super.replace(name, descr); - return this; + const compute = createComputeFunction(descr); + return { + key: normalizedName, + stored: descr, + mapped: compute, + }; } } -export const functionRegistry: FunctionRegistry = new FunctionRegistry(); +export const functionRegistry = new SpreadsheetFunctionRegistry(); for (const category of categories) { const fns = category.functions; From 4c0ddad750734446a48fcf63117f5702d7a61b67 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 09:12:44 +0200 Subject: [PATCH 06/19] compiler codex test --- .../src/formulas/code_builder.ts | 82 ++++ .../src/formulas/compiler.ts | 355 +++++++++++++++++ packages/o-spreadsheet-engine/src/index.ts | 10 + .../o-spreadsheet-engine/src/types/base.ts | 29 ++ src/formulas/code_builder.ts | 97 +---- src/formulas/compiler.ts | 368 +----------------- 6 files changed, 498 insertions(+), 443 deletions(-) create mode 100644 packages/o-spreadsheet-engine/src/formulas/code_builder.ts create mode 100644 packages/o-spreadsheet-engine/src/formulas/compiler.ts diff --git a/packages/o-spreadsheet-engine/src/formulas/code_builder.ts b/packages/o-spreadsheet-engine/src/formulas/code_builder.ts new file mode 100644 index 0000000000..c1308350a5 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/formulas/code_builder.ts @@ -0,0 +1,82 @@ +export interface FunctionCode { + readonly returnExpression: string; + assignResultToVariable(): FunctionCode; +} + +export class FunctionCodeBuilder { + private code = ""; + + constructor(private scope: Scope = new Scope()) {} + + append(...lines: (string | FunctionCode)[]) { + this.code += lines.map((line) => line.toString()).join("\n") + "\n"; + } + + return(expression: string): FunctionCode { + return new FunctionCodeImpl(this.scope, this.code, expression); + } + + toString(): string { + return indentCode(this.code); + } +} + +class FunctionCodeImpl implements FunctionCode { + private readonly code: string; + constructor(private readonly scope: Scope, code: string, readonly returnExpression: string) { + this.code = indentCode(code); + } + + toString(): string { + return this.code; + } + + assignResultToVariable(): FunctionCode { + if (this.scope.isAlreadyDeclared(this.returnExpression)) { + return this; + } + const variableName = this.scope.nextVariableName(); + const code = new FunctionCodeBuilder(this.scope); + code.append(this.code); + code.append(`const ${variableName} = ${this.returnExpression};`); + return code.return(variableName); + } +} + +export class Scope { + private nextId = 1; + private declaredVariables: Set = new Set(); + + nextVariableName(): string { + const name = `_${this.nextId++}`; + this.declaredVariables.add(name); + return name; + } + + isAlreadyDeclared(name: string): boolean { + return this.declaredVariables.has(name); + } +} + +function splitLines(str: string): string[] { + return str + .split("\n") + .map((line) => line.trim()) + .filter((line) => line !== ""); +} + +function indentCode(code: string): string { + let result = ""; + let indentLevel = 0; + const lines = splitLines(code); + for (const line of lines) { + if (line.startsWith("}")) { + indentLevel--; + } + result += "\t".repeat(indentLevel) + line + "\n"; + if (line.endsWith("{")) { + indentLevel++; + } + } + return result.trim(); +} diff --git a/packages/o-spreadsheet-engine/src/formulas/compiler.ts b/packages/o-spreadsheet-engine/src/formulas/compiler.ts new file mode 100644 index 0000000000..d0930942f7 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/formulas/compiler.ts @@ -0,0 +1,355 @@ +import { unquote } from "../helpers/misc"; +import { parseNumber } from "../helpers/numbers"; +import { _t } from "../translation"; +import { CompiledFormula, FormulaToExecute } from "../types/base"; +import { BadExpressionError, UnknownFunctionError } from "../types/errors"; +import { DEFAULT_LOCALE } from "../types/locale"; +import { FunctionCode, FunctionCodeBuilder, Scope } from "./code_builder"; +import { parseTokens } from "./parser"; +import { rangeTokenize } from "./range_tokenizer"; +import { Token } from "./tokenizer"; + +interface ArgDefinitionLike { + type?: string[]; +} + +interface FunctionDescriptionLike { + args: ArgDefinitionLike[]; + minArgRequired: number; + maxArgPossible: number; + nbrArgRepeating: number; + nbrArgOptional: number; +} + +interface FunctionRegistryLike { + content: Record; +} + +type ArgTargetingFn = ( + fn: FunctionDescriptionLike, + argCount: number +) => (argIndex: number) => number | undefined; + +let functionRegistryProvider: (() => FunctionRegistryLike) | null = null; +let argTargetingImpl: ArgTargetingFn | null = null; + +export function setFunctionRegistryProvider(provider: () => FunctionRegistryLike) { + functionRegistryProvider = provider; +} + +export function setArgTargetingImplementation(fn: ArgTargetingFn) { + argTargetingImpl = fn; +} + +function getFunctionRegistry(): FunctionRegistryLike { + if (!functionRegistryProvider) { + throw new Error("Function registry provider has not been set."); + } + return functionRegistryProvider(); +} + +function getArgTargeting(): ArgTargetingFn { + if (!argTargetingImpl) { + throw new Error("argTargeting implementation has not been set."); + } + return argTargetingImpl; +} + +export const OPERATOR_MAP = { + "=": "EQ", + "+": "ADD", + "-": "MINUS", + "*": "MULTIPLY", + "/": "DIVIDE", + ">=": "GTE", + "<>": "NE", + ">": "GT", + "<=": "LTE", + "<": "LT", + "^": "POWER", + "&": "CONCATENATE", +} as const; + +export const UNARY_OPERATOR_MAP = { + "-": "UMINUS", + "+": "UPLUS", + "%": "UNARY.PERCENT", +} as const; + +interface LiteralValues { + numbers: { value: number }[]; + strings: { value: string }[]; +} + +type InternalCompiledFormula = CompiledFormula & { + literalValues: LiteralValues; + symbols: string[]; +}; + +export const functionCache: Record = {}; + +export function compile(formula: string): CompiledFormula { + const tokens = rangeTokenize(formula); + return compileTokens(tokens); +} + +export function compileTokens(tokens: Token[]): CompiledFormula { + try { + return compileTokensOrThrow(tokens); + } catch (error) { + return { + tokens, + dependencies: [], + execute() { + return error; + }, + isBadExpression: true, + normalizedFormula: tokens.map((t) => t.value).join(""), + }; + } +} + +function compileTokensOrThrow(tokens: Token[]): CompiledFormula { + const registry = getFunctionRegistry(); + const functions = registry.content; + const argTargeting = getArgTargeting(); + + const { dependencies, literalValues, symbols } = formulaArguments(tokens); + const cacheKey = compilationCacheKey(tokens); + if (!functionCache[cacheKey]) { + const ast = parseTokens([...tokens]); + const scope = new Scope(); + + let stringCount = 0; + let numberCount = 0; + let dependencyCount = 0; + + if (ast.type === "BIN_OPERATION" && ast.value === ":") { + throw new BadExpressionError(_t("Invalid formula")); + } + if (ast.type === "EMPTY") { + throw new BadExpressionError(_t("Invalid formula")); + } + + const compiledAST = compileAST(ast); + const code = new FunctionCodeBuilder(); + code.append(`// ${cacheKey}`); + code.append(compiledAST); + code.append(`return ${compiledAST.returnExpression};`); + const baseFunction = new Function( + "deps", + "ref", + "range", + "getSymbolValue", + "ctx", + code.toString() + ); + + // @ts-ignore - constructed function + functionCache[cacheKey] = baseFunction; + + function compileFunctionArgs(astFuncall: any): FunctionCode[] { + const { args } = astFuncall; + const functionName = astFuncall.value.toUpperCase(); + const functionDefinition = functions[functionName]; + + if (!functionDefinition) { + throw new UnknownFunctionError(_t('Unknown function: "%s"', astFuncall.value)); + } + + assertEnoughArgs(args, functionDefinition, functionName); + + const compiledArgs: FunctionCode[] = []; + const argToFocus = argTargeting(functionDefinition, args.length); + + for (let i = 0; i < args.length; i++) { + const argIndex = argToFocus(i) ?? -1; + const argDefinition = + functionDefinition.args[argIndex] ?? + functionDefinition.args[i] ?? + ({} as ArgDefinitionLike); + const currentArg = args[i]; + const argTypes = argDefinition?.type || []; + const isMeta = argTypes.includes("META") || argTypes.includes("RANGE"); + const hasRange = argTypes.some((t: string) => isRangeType(t)); + compiledArgs.push(compileAST(currentArg, isMeta, hasRange)); + } + + return compiledArgs; + } + + function compileAST(ast: any, isMeta = false, hasRange = false): FunctionCode { + const codeBuilder = new FunctionCodeBuilder(scope); + if (ast.type !== "REFERENCE" && !(ast.type === "BIN_OPERATION" && ast.value === ":")) { + if (isMeta) { + throw new BadExpressionError(_t("Argument must be a reference to a cell or range.")); + } + } + if (ast.debug) { + codeBuilder.append("debugger;"); + codeBuilder.append(`ctx["debug"] = true;`); + } + switch (ast.type) { + case "BOOLEAN": + return codeBuilder.return(`{ value: ${ast.value} }`); + case "NUMBER": + return codeBuilder.return(`this.literalValues.numbers[${numberCount++}]`); + case "STRING": + return codeBuilder.return(`this.literalValues.strings[${stringCount++}]`); + case "REFERENCE": + return codeBuilder.return( + `${ast.value.includes(":") || hasRange ? "range" : "ref"}(deps[${dependencyCount++}], ${ + isMeta ? "true" : "false" + })` + ); + case "FUNCALL": { + const args = compileFunctionArgs(ast).map((argCode) => argCode.assignResultToVariable()); + codeBuilder.append(...args); + const fnName = ast.value.toUpperCase(); + return codeBuilder.return(`ctx['${fnName}'](${args.map((arg) => arg.returnExpression)})`); + } + case "UNARY_OPERATION": { + const fnName = UNARY_OPERATOR_MAP[ast.value as keyof typeof UNARY_OPERATOR_MAP]; + const operand = compileAST(ast.operand, false, false).assignResultToVariable(); + codeBuilder.append(operand); + return codeBuilder.return(`ctx['${fnName}'](${operand.returnExpression})`); + } + case "BIN_OPERATION": { + const fnName = OPERATOR_MAP[ast.value as keyof typeof OPERATOR_MAP]; + const left = compileAST(ast.left, false, false).assignResultToVariable(); + const right = compileAST(ast.right, false, false).assignResultToVariable(); + codeBuilder.append(left); + codeBuilder.append(right); + return codeBuilder.return( + `ctx['${fnName}'](${left.returnExpression}, ${right.returnExpression})` + ); + } + case "SYMBOL": { + const symbolIndex = symbols.indexOf(ast.value); + return codeBuilder.return(`getSymbolValue(this.symbols[${symbolIndex}])`); + } + case "EMPTY": + return codeBuilder.return("undefined"); + default: + return codeBuilder.return("undefined"); + } + } + } + + const compiledFormula: InternalCompiledFormula = { + execute: functionCache[cacheKey], + dependencies, + literalValues, + symbols, + tokens, + isBadExpression: false, + normalizedFormula: cacheKey, + }; + return compiledFormula; +} + +function compilationCacheKey(tokens: Token[]): string { + let cacheKey = ""; + for (const token of tokens) { + switch (token.type) { + case "STRING": + cacheKey += "|S|"; + break; + case "NUMBER": + cacheKey += "|N|"; + break; + case "REFERENCE": + case "INVALID_REFERENCE": + cacheKey += token.value.includes(":") ? "|R|" : "|C|"; + break; + case "SPACE": + break; + default: + cacheKey += token.value; + } + } + return cacheKey; +} + +function formulaArguments(tokens: Token[]) { + const literalValues: LiteralValues = { + numbers: [], + strings: [], + }; + const dependencies: string[] = []; + const symbols: string[] = []; + for (const token of tokens) { + switch (token.type) { + case "INVALID_REFERENCE": + case "REFERENCE": + dependencies.push(token.value); + break; + case "STRING": + literalValues.strings.push({ value: unquote(token.value) }); + break; + case "NUMBER": + literalValues.numbers.push({ value: parseNumber(token.value, DEFAULT_LOCALE) }); + break; + case "SYMBOL": + symbols.push(unquote(token.value, "'")); + break; + default: + break; + } + } + return { dependencies, literalValues, symbols }; +} + +function assertEnoughArgs( + args: any[], + functionDefinition: FunctionDescriptionLike, + functionName: string +) { + const nbrArgSupplied = args.length; + const { nbrArgRepeating, minArgRequired } = functionDefinition; + + if (nbrArgSupplied < minArgRequired) { + throw new BadExpressionError( + _t( + "Invalid number of arguments for the %s function. Expected %s minimum, but got %s instead.", + functionName, + minArgRequired, + nbrArgSupplied + ) + ); + } + + if (nbrArgSupplied > functionDefinition.maxArgPossible) { + throw new BadExpressionError( + _t( + "Invalid number of arguments for the %s function. Expected %s maximum, but got %s instead.", + functionName, + functionDefinition.maxArgPossible, + nbrArgSupplied + ) + ); + } + + if (nbrArgRepeating > 1) { + const nbrValueRepeating = + nbrArgRepeating * Math.floor((nbrArgSupplied - minArgRequired) / nbrArgRepeating); + const nbrValueRemaining = + nbrArgSupplied - minArgRequired - nbrValueRepeating - functionDefinition.nbrArgOptional; + + if (nbrValueRemaining > 0) { + throw new BadExpressionError( + _t( + "Invalid number of arguments for the %s function. Repeatable arguments should be supplied in groups of %s, with up to %s optional. Got %s too many.", + functionName, + nbrArgRepeating, + functionDefinition.nbrArgOptional, + nbrValueRemaining + ) + ); + } + } +} + +function isRangeType(type: string) { + return type.startsWith("RANGE"); +} diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts index 2b25b721e7..1ae08dde57 100644 --- a/packages/o-spreadsheet-engine/src/index.ts +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -1,3 +1,13 @@ +export { FunctionCodeBuilder, Scope, type FunctionCode } from "./formulas/code_builder"; +export { + OPERATOR_MAP, + UNARY_OPERATOR_MAP, + compile, + compileTokens, + functionCache, + setArgTargetingImplementation, + setFunctionRegistryProvider, +} from "./formulas/compiler"; export { OP_PRIORITY, convertAstNodes, diff --git a/packages/o-spreadsheet-engine/src/types/base.ts b/packages/o-spreadsheet-engine/src/types/base.ts index fc50531112..8e2186d191 100644 --- a/packages/o-spreadsheet-engine/src/types/base.ts +++ b/packages/o-spreadsheet-engine/src/types/base.ts @@ -17,6 +17,8 @@ export interface Zone { bottom: HeaderIndex; } +export type Range = unknown; + export type CellValue = string | number | boolean | null; export type Format = string & Alias; @@ -36,3 +38,30 @@ export interface FunctionResultObject { message?: string; origin?: CellPosition; } + +export type ReferenceDenormalizer = ( + range: Range, + isMeta: boolean, + functionName: string, + paramNumber: number +) => FunctionResultObject; + +export type EnsureRange = (range: Range, isMeta: boolean) => Matrix; + +export type GetSymbolValue = (symbolName: string) => unknown; + +export type FormulaToExecute = ( + deps: Range[], + refFn: ReferenceDenormalizer, + range: EnsureRange, + getSymbolValue: GetSymbolValue, + ctx: Record +) => Matrix | FunctionResultObject; + +export interface CompiledFormula { + execute: FormulaToExecute; + tokens: unknown[]; + dependencies: string[]; + isBadExpression: boolean; + normalizedFormula: string; +} diff --git a/src/formulas/code_builder.ts b/src/formulas/code_builder.ts index 63a84aa562..b96db6dde0 100644 --- a/src/formulas/code_builder.ts +++ b/src/formulas/code_builder.ts @@ -1,92 +1,5 @@ -/** - * Block of code that produces a value. - */ -export interface FunctionCode { - readonly returnExpression: string; - /** - * Return the same function code but with the return expression assigned to a variable. - */ - assignResultToVariable(): FunctionCode; -} - -export class FunctionCodeBuilder { - private code: string = ""; - - constructor(private scope: Scope = new Scope()) {} - - append(...lines: (string | FunctionCode)[]) { - this.code += lines.map((line) => line.toString()).join("\n") + "\n"; - } - - return(expression: string): FunctionCode { - return new FunctionCodeImpl(this.scope, this.code, expression); - } - - toString(): string { - return indentCode(this.code); - } -} - -class FunctionCodeImpl implements FunctionCode { - private readonly code: string; - constructor(private readonly scope: Scope, code: string, readonly returnExpression: string) { - this.code = indentCode(code); - } - - toString(): string { - return this.code; - } - - assignResultToVariable(): FunctionCode { - if (this.scope.isAlreadyDeclared(this.returnExpression)) { - return this; - } - const variableName = this.scope.nextVariableName(); - const code = new FunctionCodeBuilder(this.scope); - code.append(this.code); - code.append(`const ${variableName} = ${this.returnExpression};`); - return code.return(variableName); - } -} - -export class Scope { - private nextId = 1; - private declaredVariables: Set = new Set(); - - nextVariableName(): string { - const name = `_${this.nextId++}`; - this.declaredVariables.add(name); - return name; - } - - isAlreadyDeclared(name: string): boolean { - return this.declaredVariables.has(name); - } -} - -/** - * Takes a list of strings that might be single or multiline - * and maps them in a list of single line strings. - */ -function splitLines(str: string): string[] { - return str - .split("\n") - .map((line) => line.trim()) - .filter((line) => line !== ""); -} - -function indentCode(code: string): string { - let result = ""; - let indentLevel = 0; - const lines = splitLines(code); - for (const line of lines) { - if (line.startsWith("}")) { - indentLevel--; - } - result += "\t".repeat(indentLevel) + line + "\n"; - if (line.endsWith("{")) { - indentLevel++; - } - } - return result.trim(); -} +export { + FunctionCodeBuilder, + Scope, + type FunctionCode, +} from "@odoo/o-spreadsheet-engine/formulas/code_builder"; diff --git a/src/formulas/compiler.ts b/src/formulas/compiler.ts index b42b5ae2dc..a105bca6ad 100644 --- a/src/formulas/compiler.ts +++ b/src/formulas/compiler.ts @@ -1,362 +1,28 @@ -import { Token } from "."; +import { + OPERATOR_MAP, + UNARY_OPERATOR_MAP, + compile as engineCompile, + compileTokens as engineCompileTokens, + functionCache as engineFunctionCache, + setArgTargetingImplementation, + setFunctionRegistryProvider, +} from "@odoo/o-spreadsheet-engine/formulas/compiler"; import { argTargeting } from "../functions/arguments"; import { functionRegistry } from "../functions/index"; -import { parseNumber, unquote } from "../helpers"; -import { _t } from "../translation"; -import { CompiledFormula, DEFAULT_LOCALE, FormulaToExecute } from "../types"; -import { BadExpressionError, UnknownFunctionError } from "../types/errors"; -import { FunctionCode, FunctionCodeBuilder, Scope } from "./code_builder"; -import { AST, ASTFuncall, parseTokens } from "./parser"; -import { rangeTokenize } from "./range_tokenizer"; +import type { CompiledFormula, FormulaToExecute } from "../types"; +import type { Token } from "./tokenizer"; -const functions = functionRegistry.content; +setFunctionRegistryProvider(() => functionRegistry); +setArgTargetingImplementation(argTargeting); -export const OPERATOR_MAP = { - // export for test - "=": "EQ", - "+": "ADD", - "-": "MINUS", - "*": "MULTIPLY", - "/": "DIVIDE", - ">=": "GTE", - "<>": "NE", - ">": "GT", - "<=": "LTE", - "<": "LT", - "^": "POWER", - "&": "CONCATENATE", -}; - -export const UNARY_OPERATOR_MAP = { - // export for test - "-": "UMINUS", - "+": "UPLUS", - "%": "UNARY.PERCENT", -}; - -interface LiteralValues { - numbers: { value: number }[]; - strings: { value: string }[]; -} - -type InternalCompiledFormula = CompiledFormula & { - literalValues: LiteralValues; - symbols: string[]; -}; - -// this cache contains all compiled function code, grouped by "structure". For -// example, "=2*sum(A1:A4)" and "=2*sum(B1:B4)" are compiled into the same -// structural function. -// It is only exported for testing purposes -export const functionCache: { [key: string]: FormulaToExecute } = {}; - -// ----------------------------------------------------------------------------- -// COMPILER -// ----------------------------------------------------------------------------- +export { OPERATOR_MAP, UNARY_OPERATOR_MAP }; export function compile(formula: string): CompiledFormula { - const tokens = rangeTokenize(formula); - return compileTokens(tokens); + return engineCompile(formula) as unknown as CompiledFormula; } export function compileTokens(tokens: Token[]): CompiledFormula { - try { - return compileTokensOrThrow(tokens); - } catch (error) { - return { - tokens, - dependencies: [], - execute: function () { - return error; - }, - isBadExpression: true, - normalizedFormula: tokens.map((t) => t.value).join(""), - }; - } -} - -function compileTokensOrThrow(tokens: Token[]): CompiledFormula { - const { dependencies, literalValues, symbols } = formulaArguments(tokens); - const cacheKey = compilationCacheKey(tokens); - if (!functionCache[cacheKey]) { - const ast = parseTokens([...tokens]); - const scope = new Scope(); - - let stringCount = 0; - let numberCount = 0; - let dependencyCount = 0; - - if (ast.type === "BIN_OPERATION" && ast.value === ":") { - throw new BadExpressionError(_t("Invalid formula")); - } - if (ast.type === "EMPTY") { - throw new BadExpressionError(_t("Invalid formula")); - } - const compiledAST = compileAST(ast); - const code = new FunctionCodeBuilder(); - code.append(`// ${cacheKey}`); - code.append(compiledAST); - code.append(`return ${compiledAST.returnExpression};`); - const baseFunction = new Function( - "deps", // the dependencies in the current formula - "ref", // a function to access a certain dependency at a given index - "range", // same as above, but guarantee that the result is in the form of a range - "getSymbolValue", - "ctx", - code.toString() - ); - - // @ts-ignore - functionCache[cacheKey] = baseFunction; - - /** - * This function compile the function arguments. It is mostly straightforward, - * except that there is a non trivial transformation in one situation: - * - * If a function argument is asking for a range, and get a cell, we transform - * the cell value into a range. This allow the grid model to differentiate - * between a cell value and a non cell value. - */ - function compileFunctionArgs(ast: ASTFuncall): FunctionCode[] { - const { args } = ast; - const functionName = ast.value.toUpperCase(); - const functionDefinition = functions[functionName]; - - if (!functionDefinition) { - throw new UnknownFunctionError(_t('Unknown function: "%s"', ast.value)); - } - - assertEnoughArgs(ast); - - const compiledArgs: FunctionCode[] = []; - - const argToFocus = argTargeting(functionDefinition, args.length); - - for (let i = 0; i < args.length; i++) { - const argDefinition = functionDefinition.args[argToFocus(i) ?? -1]; - const currentArg = args[i]; - const argTypes = argDefinition.type || []; - - // detect when an argument need to be evaluated as a meta argument - const isMeta = argTypes.includes("META") || argTypes.includes("RANGE"); - const hasRange = argTypes.some((t) => isRangeType(t)); - - compiledArgs.push(compileAST(currentArg, isMeta, hasRange)); - } - - return compiledArgs; - } - - /** - * This function compiles all the information extracted by the parser into an - * executable code for the evaluation of the cells content. It uses a cache to - * not reevaluate identical code structures. - * - * The function is sensitive to parameter “isMeta”. This - * parameter may vary when compiling function arguments: - * isMeta: In some cases the function arguments expects information on the - * cell/range other than the associated value(s). For example the COLUMN - * function needs to receive as argument the coordinates of a cell rather - * than its value. For this we have meta arguments. - */ - function compileAST(ast: AST, isMeta = false, hasRange = false): FunctionCode { - const code = new FunctionCodeBuilder(scope); - if (ast.type !== "REFERENCE" && !(ast.type === "BIN_OPERATION" && ast.value === ":")) { - if (isMeta) { - throw new BadExpressionError(_t("Argument must be a reference to a cell or range.")); - } - } - if (ast.debug) { - code.append("debugger;"); - code.append(`ctx["debug"] = true;`); - } - switch (ast.type) { - case "BOOLEAN": - return code.return(`{ value: ${ast.value} }`); - case "NUMBER": - return code.return(`this.literalValues.numbers[${numberCount++}]`); - case "STRING": - return code.return(`this.literalValues.strings[${stringCount++}]`); - case "REFERENCE": - return code.return( - `${ast.value.includes(":") || hasRange ? `range` : `ref`}(deps[${dependencyCount++}], ${ - isMeta ? "true" : "false" - })` - ); - case "FUNCALL": - const args = compileFunctionArgs(ast).map((arg) => arg.assignResultToVariable()); - code.append(...args); - const fnName = ast.value.toUpperCase(); - return code.return(`ctx['${fnName}'](${args.map((arg) => arg.returnExpression)})`); - case "UNARY_OPERATION": { - const fnName = UNARY_OPERATOR_MAP[ast.value]; - const operand = compileAST(ast.operand, false, false).assignResultToVariable(); - code.append(operand); - return code.return(`ctx['${fnName}'](${operand.returnExpression})`); - } - case "BIN_OPERATION": { - const fnName = OPERATOR_MAP[ast.value]; - const left = compileAST(ast.left, false, false).assignResultToVariable(); - const right = compileAST(ast.right, false, false).assignResultToVariable(); - code.append(left); - code.append(right); - return code.return( - `ctx['${fnName}'](${left.returnExpression}, ${right.returnExpression})` - ); - } - case "SYMBOL": - const symbolIndex = symbols.indexOf(ast.value); - return code.return(`getSymbolValue(this.symbols[${symbolIndex}])`); - case "EMPTY": - return code.return("undefined"); - } - } - } - const compiledFormula: InternalCompiledFormula = { - execute: functionCache[cacheKey], - dependencies, - literalValues, - symbols, - tokens, - isBadExpression: false, - normalizedFormula: cacheKey, - }; - return compiledFormula; -} - -/** - * Compute a cache key for the formula. - * References, numbers and strings are replaced with placeholders because - * the compiled formula does not depend on their actual value. - * Both `=A1+1+"2"` and `=A2+2+"3"` are compiled to the exact same function. - * Spaces are also ignored to compute the cache key. - * - * A formula `=A1+A2+SUM(2, 2, "2")` have the cache key `=|C|+|C|+SUM(|N|,|N|,|S|)` - */ -function compilationCacheKey(tokens: Token[]): string { - let cacheKey = ""; - for (const token of tokens) { - switch (token.type) { - case "STRING": - cacheKey += "|S|"; - break; - case "NUMBER": - cacheKey += "|N|"; - break; - case "REFERENCE": - case "INVALID_REFERENCE": - if (token.value.includes(":")) { - cacheKey += "|R|"; - } else { - cacheKey += "|C|"; - } - break; - case "SPACE": - // ignore spaces - break; - default: - cacheKey += token.value; - break; - } - } - return cacheKey; -} - -/** - * Return formula arguments which are references, strings and numbers. - */ -function formulaArguments(tokens: Token[]) { - const literalValues: LiteralValues = { - numbers: [], - strings: [], - }; - const dependencies: string[] = []; - const symbols: string[] = []; - for (const token of tokens) { - switch (token.type) { - case "INVALID_REFERENCE": - case "REFERENCE": - dependencies.push(token.value); - break; - case "STRING": - const value = unquote(token.value); - literalValues.strings.push({ value }); - break; - case "NUMBER": { - const value = parseNumber(token.value, DEFAULT_LOCALE); - literalValues.numbers.push({ value }); - break; - } - case "SYMBOL": { - // function name symbols are also included here - symbols.push(unquote(token.value, "'")); - } - } - } - return { - dependencies, - literalValues, - symbols, - }; -} - -/** - * Check if arguments are supplied in the correct quantities - */ -function assertEnoughArgs(ast: ASTFuncall) { - const nbrArgSupplied = ast.args.length; - const functionName = ast.value.toUpperCase(); - const functionDefinition = functions[functionName]; - const { nbrArgRepeating, minArgRequired } = functionDefinition; - - if (nbrArgSupplied < minArgRequired) { - throw new BadExpressionError( - _t( - "Invalid number of arguments for the %(functionName)s function. Expected %(minArgRequired)s minimum, but got %(nbrArgSupplied)s instead.", - { - functionName, - minArgRequired, - nbrArgSupplied, - } - ) - ); - } - - if (nbrArgSupplied > functionDefinition.maxArgPossible) { - throw new BadExpressionError( - _t( - "Invalid number of arguments for the %(functionName)s function. Expected %(maxArgPossible)s maximum, but got %(nbrArgSupplied)s instead.", - { - functionName, - maxArgPossible: functionDefinition.maxArgPossible, - nbrArgSupplied, - } - ) - ); - } - - if (nbrArgRepeating > 1) { - const nbrValueRepeating = - nbrArgRepeating * Math.floor((nbrArgSupplied - minArgRequired) / nbrArgRepeating); - const nbrValueRemaining = - nbrArgSupplied - minArgRequired - nbrValueRepeating - functionDefinition.nbrArgOptional; - - if (nbrValueRemaining > 0) { - throw new BadExpressionError( - _t( - "Invalid number of arguments for the %(functionName)s function. Repeatable arguments should be supplied in groups of %(nbrArgRepeating)s, with up to %(nbrArgOptional)s optional. Got %(nbrValueRemaining)s too many.", - { - functionName, - nbrArgRepeating, - nbrArgOptional: functionDefinition.nbrArgOptional, - nbrValueRemaining, - } - ) - ); - } - } + return engineCompileTokens(tokens) as unknown as CompiledFormula; } -function isRangeType(type: string) { - return type.startsWith("RANGE"); -} +export const functionCache = engineFunctionCache as Record; From a748183733b532f71a902474ab8e201194f1b9ac Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 09:17:17 +0200 Subject: [PATCH 07/19] build is still working --- rollup.config.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index 243f243a14..7d83df36b5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -39,7 +39,14 @@ export default (commandLineArgs) => { find: "@odoo/o-spreadsheet-engine", replacement: path.resolve( __dirname, - "./packages/o-spreadsheet-engine/build/js/o-spreadsheet-engine/src/index.js" + "./packages/o-spreadsheet-engine/build/js/o-spreadsheet-engine/src" + ), + }, + { + find: "@odoo/o-spreadsheet-engine/*", + replacement: path.resolve( + __dirname, + "./packages/o-spreadsheet-engine/build/js/o-spreadsheet-engine/src/*" ), }, ], From d7215142a976f8f6d22eaa01f863df79e268cf78 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 09:52:26 +0200 Subject: [PATCH 08/19] state observer --- .../o-spreadsheet-engine/src/helpers/index.ts | 1 + .../src}/helpers/state_manager_helpers.ts | 0 packages/o-spreadsheet-engine/src/index.ts | 1 + .../src}/state_observer.ts | 24 ++++++++++++------- src/history/factory.ts | 4 ++-- src/model.ts | 7 +++--- src/plugins/base_plugin.ts | 2 +- src/plugins/core_plugin.ts | 5 ++-- src/plugins/core_view_plugin.ts | 14 ++++++++--- src/plugins/ui_plugin.ts | 6 +++-- tests/history/history_plugin.test.ts | 2 +- 11 files changed, 44 insertions(+), 22 deletions(-) rename {src => packages/o-spreadsheet-engine/src}/helpers/state_manager_helpers.ts (100%) rename {src => packages/o-spreadsheet-engine/src}/state_observer.ts (70%) diff --git a/packages/o-spreadsheet-engine/src/helpers/index.ts b/packages/o-spreadsheet-engine/src/helpers/index.ts index a466535aa0..78f559ea3c 100644 --- a/packages/o-spreadsheet-engine/src/helpers/index.ts +++ b/packages/o-spreadsheet-engine/src/helpers/index.ts @@ -1,4 +1,5 @@ export * from "./misc"; export * from "./numbers"; export * from "./references"; +export * from "./state_manager_helpers"; export * from "./uuid"; diff --git a/src/helpers/state_manager_helpers.ts b/packages/o-spreadsheet-engine/src/helpers/state_manager_helpers.ts similarity index 100% rename from src/helpers/state_manager_helpers.ts rename to packages/o-spreadsheet-engine/src/helpers/state_manager_helpers.ts diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts index 1ae08dde57..172551a2b6 100644 --- a/packages/o-spreadsheet-engine/src/index.ts +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -30,6 +30,7 @@ export type { Token } from "./formulas/tokenizer"; export { FunctionRegistry } from "./functions/function_registry"; export * from "./helpers"; export { Registry } from "./registry"; +export { StateObserver, type StateObserverChange } from "./state_observer"; export * from "./translation"; export * from "./types/base"; export * from "./types/errors"; diff --git a/src/state_observer.ts b/packages/o-spreadsheet-engine/src/state_observer.ts similarity index 70% rename from src/state_observer.ts rename to packages/o-spreadsheet-engine/src/state_observer.ts index 05217f9494..b290f03067 100644 --- a/src/state_observer.ts +++ b/packages/o-spreadsheet-engine/src/state_observer.ts @@ -1,24 +1,32 @@ import { createEmptyStructure } from "./helpers/state_manager_helpers"; -import { CoreCommand, HistoryChange } from "./types"; type HistoryPath = [any, ...(number | string)[]]; -export class StateObserver { - private changes: HistoryChange[] | undefined; - private commands: CoreCommand[] = []; +export interface StateObserverChange { + key: PropertyKey; + target: unknown; + before: unknown; +} + +export class StateObserver< + Command = unknown, + Change extends StateObserverChange = StateObserverChange +> { + private changes: Change[] | undefined; + private commands: Command[] = []; /** * Record the changes which could happen in the given callback, save them in a * new revision with the given id and userId. */ - recordChanges(callback: () => void): { changes: HistoryChange[]; commands: CoreCommand[] } { + recordChanges(callback: () => void): { changes: Change[]; commands: Command[] } { this.changes = []; this.commands = []; callback(); return { changes: this.changes, commands: this.commands }; } - addCommand(command: CoreCommand) { + addCommand(command: Command) { this.commands.push(command); } @@ -26,7 +34,7 @@ export class StateObserver { const val: any = args.pop(); const root = args[0]; let value = root as any; - const key = args.at(-1); + const key = args.at(-1) as Change["key"]; const pathLength = args.length - 2; for (let pathIndex = 1; pathIndex <= pathLength; pathIndex++) { const p = args[pathIndex]; @@ -43,7 +51,7 @@ export class StateObserver { key, target: value, before: value[key], - }); + } as Change); if (val === undefined) { delete value[key]; } else { diff --git a/src/history/factory.ts b/src/history/factory.ts index c8ff3e9c2c..1fd4cf3a44 100644 --- a/src/history/factory.ts +++ b/src/history/factory.ts @@ -1,13 +1,13 @@ +import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; import { transformAll } from "../collaborative/ot/ot"; import { Revision } from "../collaborative/revisions"; import { inverseCommand } from "../helpers/inverse_commands"; -import { StateObserver } from "../state_observer"; import { CoreCommand, HistoryChange, UID } from "../types"; import { SelectiveHistory } from "./selective_history"; export function buildRevisionLog(args: { initialRevisionId: UID; - recordChanges: StateObserver["recordChanges"]; + recordChanges: StateObserver["recordChanges"]; dispatch: (command: CoreCommand) => void; }) { return new SelectiveHistory({ diff --git a/src/model.ts b/src/model.ts index d22a6268a5..446430772c 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1,3 +1,4 @@ +import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; import { markRaw } from "@odoo/owl"; import { LocalTransportService } from "./collaborative/local_transport_service"; import { ReadonlyTransportFilter } from "./collaborative/readonly_transport_filter"; @@ -27,7 +28,6 @@ import { SelectionStreamProcessor, SelectionStreamProcessorImpl, } from "./selection_stream/selection_stream_processor"; -import { StateObserver } from "./state_observer"; import { _t, setDefaultTranslationMethod } from "./translation"; import { GeoChartRegion } from "./types/chart/geo_chart"; import { StateUpdateMessage, TransportService } from "./types/collaborative/transport_service"; @@ -48,6 +48,7 @@ import { DispatchResult, Getters, GridRenderingContext, + HistoryChange, InformationNotification, LayerName, LocalCommand, @@ -168,7 +169,7 @@ export class Model extends EventBus implements CommandDispatcher { private coreViewPluginConfig: CoreViewPluginConfig; private uiPluginConfig: UIPluginConfig; - private state: StateObserver; + private state: StateObserver; readonly selection: SelectionStreamProcessor; @@ -207,7 +208,7 @@ export class Model extends EventBus implements CommandDispatcher { const workbookData = load(data, verboseImport); - this.state = new StateObserver(); + this.state = new StateObserver(); this.uuidGenerator = uuidGenerator; diff --git a/src/plugins/base_plugin.ts b/src/plugins/base_plugin.ts index 6756fdbe62..625330bef3 100644 --- a/src/plugins/base_plugin.ts +++ b/src/plugins/base_plugin.ts @@ -1,4 +1,4 @@ -import { StateObserver } from "../state_observer"; +import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; import { CommandHandler, CommandResult, diff --git a/src/plugins/core_plugin.ts b/src/plugins/core_plugin.ts index 808ca85cf0..66e2165d78 100644 --- a/src/plugins/core_plugin.ts +++ b/src/plugins/core_plugin.ts @@ -1,10 +1,11 @@ +import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; import { ModelConfig } from "../model"; -import { StateObserver } from "../state_observer"; import { AdaptSheetName, ApplyRangeChange, CoreCommand, CoreCommandDispatcher, + HistoryChange, RangeProvider, UID, WorkbookData, @@ -15,7 +16,7 @@ import { RangeAdapter } from "./core/range"; export interface CorePluginConfig { readonly getters: CoreGetters; - readonly stateObserver: StateObserver; + readonly stateObserver: StateObserver; readonly range: RangeAdapter; readonly dispatch: CoreCommandDispatcher["dispatch"]; readonly canDispatch: CoreCommandDispatcher["dispatch"]; diff --git a/src/plugins/core_view_plugin.ts b/src/plugins/core_view_plugin.ts index a0776a4ad4..266c4c37f7 100644 --- a/src/plugins/core_view_plugin.ts +++ b/src/plugins/core_view_plugin.ts @@ -1,14 +1,22 @@ +import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; import { Session } from "../collaborative/session"; import { ModelConfig } from "../model"; import { SelectionStreamProcessor } from "../selection_stream/selection_stream_processor"; -import { StateObserver } from "../state_observer"; -import { ClientPosition, Color, Command, Currency, Getters } from "../types/index"; +import { + ClientPosition, + Color, + Command, + CoreCommand, + Currency, + Getters, + HistoryChange, +} from "../types/index"; import { BasePlugin } from "./base_plugin"; import { UIActions } from "./ui_plugin"; export interface CoreViewPluginConfig { readonly getters: Getters; - readonly stateObserver: StateObserver; + readonly stateObserver: StateObserver; readonly selection: SelectionStreamProcessor; readonly moveClient: (position: ClientPosition) => void; readonly uiActions: UIActions; diff --git a/src/plugins/ui_plugin.ts b/src/plugins/ui_plugin.ts index 945ad267a5..bb2a136e49 100644 --- a/src/plugins/ui_plugin.ts +++ b/src/plugins/ui_plugin.ts @@ -1,15 +1,17 @@ +import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; import { Session } from "../collaborative/session"; import { ModelConfig } from "../model"; import { SelectionStreamProcessor } from "../selection_stream/selection_stream_processor"; -import { StateObserver } from "../state_observer"; import { ClientPosition, Color, Command, CommandDispatcher, + CoreCommand, Currency, Getters, GridRenderingContext, + HistoryChange, LayerName, } from "../types/index"; import { BasePlugin } from "./base_plugin"; @@ -18,7 +20,7 @@ export type UIActions = Pick; export interface UIPluginConfig { readonly getters: Getters; - readonly stateObserver: StateObserver; + readonly stateObserver: StateObserver; readonly dispatch: CommandDispatcher["dispatch"]; readonly canDispatch: CommandDispatcher["dispatch"]; readonly selection: SelectionStreamProcessor; diff --git a/tests/history/history_plugin.test.ts b/tests/history/history_plugin.test.ts index 05300b60a3..ba07a5d88f 100644 --- a/tests/history/history_plugin.test.ts +++ b/tests/history/history_plugin.test.ts @@ -1,6 +1,6 @@ +import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; import { MAX_HISTORY_STEPS } from "../../src/constants"; import { Model } from "../../src/model"; -import { StateObserver } from "../../src/state_observer"; import { CommandResult, UpdateCellCommand } from "../../src/types/commands"; import { activateSheet, From 41eacfd10b15472180df7a34dbe4ea0d4412913a Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 10:08:09 +0200 Subject: [PATCH 09/19] tsconfig jest --- tests/tsconfig.json | 3 +++ tsconfig.jest.json | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/tsconfig.json diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 0000000000..e615eef2a0 --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../tsconfig.jest.json" +} diff --git a/tsconfig.jest.json b/tsconfig.jest.json index 26bf4e6c97..fa63a0e239 100644 --- a/tsconfig.jest.json +++ b/tsconfig.jest.json @@ -1,7 +1,11 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "dist" + "outDir": "dist", + "paths": { + "@odoo/o-spreadsheet-engine": ["./packages/o-spreadsheet-engine/src/index.ts"], + "@odoo/o-spreadsheet-engine/*": ["./packages/o-spreadsheet-engine/src/*"] + } }, "include": ["src", "tests"], "exclude": ["packages"], From a542500e3c302450c25ee6f254f0f820f2ee9e3a Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 10:32:52 +0200 Subject: [PATCH 10/19] base plugin --- packages/o-spreadsheet-engine/src/index.ts | 3 + .../src}/plugins/base_plugin.ts | 78 +++++++++++-------- .../o-spreadsheet-engine/src/types/history.ts | 62 +++++++++++++++ .../src/types/validator.ts | 21 +++++ src/helpers/figures/charts/gauge_chart.ts | 6 +- src/model.ts | 3 +- src/plugins/core_plugin.ts | 9 ++- src/plugins/core_view_plugin.ts | 15 +++- src/plugins/ui_plugin.ts | 15 +++- src/types/history.ts | 63 +-------------- src/types/misc.ts | 5 +- src/types/validator.ts | 25 ++---- tests/test_helpers/helpers.ts | 2 +- 13 files changed, 174 insertions(+), 133 deletions(-) rename {src => packages/o-spreadsheet-engine/src}/plugins/base_plugin.ts (52%) create mode 100644 packages/o-spreadsheet-engine/src/types/history.ts create mode 100644 packages/o-spreadsheet-engine/src/types/validator.ts diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts index 172551a2b6..600a195bed 100644 --- a/packages/o-spreadsheet-engine/src/index.ts +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -29,11 +29,14 @@ export { POSTFIX_UNARY_OPERATORS, tokenize } from "./formulas/tokenizer"; export type { Token } from "./formulas/tokenizer"; export { FunctionRegistry } from "./functions/function_registry"; export * from "./helpers"; +export { BasePlugin } from "./plugins/base_plugin"; export { Registry } from "./registry"; export { StateObserver, type StateObserverChange } from "./state_observer"; export * from "./translation"; export * from "./types/base"; export * from "./types/errors"; +export * from "./types/history"; export * from "./types/locale"; export * from "./types/pivot"; export * from "./types/pivot_runtime"; +export * from "./types/validator"; diff --git a/src/plugins/base_plugin.ts b/packages/o-spreadsheet-engine/src/plugins/base_plugin.ts similarity index 52% rename from src/plugins/base_plugin.ts rename to packages/o-spreadsheet-engine/src/plugins/base_plugin.ts index 625330bef3..cadd5c10fb 100644 --- a/src/plugins/base_plugin.ts +++ b/packages/o-spreadsheet-engine/src/plugins/base_plugin.ts @@ -1,12 +1,6 @@ -import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; -import { - CommandHandler, - CommandResult, - ExcelWorkbookData, - Validation, - WorkbookHistory, -} from "../types/index"; -import { Validator } from "../types/validator"; +import { StateObserver, type StateObserverChange } from "../state_observer"; +import type { WorkbookHistory } from "../types/history"; +import type { Validation, Validator } from "../types/validator"; /** * BasePlugin @@ -14,18 +8,26 @@ import { Validator } from "../types/validator"; * Since the spreadsheet internal state is quite complex, it is split into * multiple parts, each managing a specific concern. * - * This file introduce the BasePlugin, which is the common class that defines + * This file introduces the BasePlugin, which is the common class that defines * how each of these model sub parts should interact with each other. - * There are two kind of plugins: core plugins handling persistent data + * There are two kinds of plugins: core plugins handling persistent data * and UI plugins handling transient data. */ - -export class BasePlugin implements CommandHandler, Validator { +export class BasePlugin< + State = unknown, + Command = unknown, + Result = unknown, + Change extends StateObserverChange = StateObserverChange, + ExcelData = unknown +> implements Validator +{ static getters: readonly string[] = []; protected history: WorkbookHistory; + protected readonly successResult: Result; - constructor(stateObserver: StateObserver) { + constructor(stateObserver: StateObserver, successResult: Result) { + this.successResult = successResult; this.history = Object.assign(Object.create(stateObserver), { update: stateObserver.addChange.bind(stateObserver, this), selectCell: () => {}, @@ -34,10 +36,10 @@ export class BasePlugin implements CommandHandler, Vali /** * Export for excel should be available for all plugins, even for the UI. - * In some case, we need to export evaluated value, which is available from + * In some cases, we need to export evaluated value, which is available from * UI plugin only. */ - exportForExcel(data: ExcelWorkbookData) {} + exportForExcel(_data: ExcelData) {} // --------------------------------------------------------------------------- // Command handling @@ -45,42 +47,52 @@ export class BasePlugin implements CommandHandler, Vali /** * Before a command is accepted, the model will ask each plugin if the command - * is allowed. If all of then return true, then we can proceed. Otherwise, + * is allowed. If all of them return true, then we can proceed. Otherwise, * the command is cancelled. * * There should not be any side effects in this method. */ - allowDispatch(command: C): CommandResult | CommandResult[] { - return CommandResult.Success; + allowDispatch(_command: Command): Result | Result[] { + return this.successResult; } /** - * This method is useful when a plugin need to perform some action before a + * This method is useful when a plugin needs to perform some action before a * command is handled in another plugin. This should only be used if it is not * possible to do the work in the handle method. */ - beforeHandle(command: C): void {} + beforeHandle(_command: Command): void {} /** * This is the standard place to handle any command. Most of the plugin * command handling work should take place here. */ - handle(command: C): void {} + handle(_command: Command): void {} /** * Sometimes, it is useful to perform some work after a command (and all its - * subcommands) has been completely handled. For example, when we paste + * subcommands) has been completely handled. For example, when we paste * multiple cells, we only want to reevaluate the cell values once at the end. */ finalize(): void {} /** * Combine multiple validation functions into a single function - * returning the list of result of every validation. + * returning the list of results of every validation. */ - batchValidations(...validations: Validation[]): Validation { - return (toValidate: T) => - validations.map((validation) => validation.call(this, toValidate)).flat(); + batchValidations(...validations: Validation[]): Validation { + return (toValidate: T) => { + const outcomes: Result[] = []; + for (const validation of validations) { + const result = validation.call(this, toValidate); + if (Array.isArray(result)) { + outcomes.push(...result); + } else { + outcomes.push(result); + } + } + return outcomes; + }; } /** @@ -88,26 +100,26 @@ export class BasePlugin implements CommandHandler, Vali * the other. As soon as one validation fails, it stops and the cancelled reason * is returned. */ - chainValidations(...validations: Validation[]): Validation { + chainValidations(...validations: Validation[]): Validation { return (toValidate: T) => { for (const validation of validations) { - let results: CommandResult | CommandResult[] = validation.call(this, toValidate); + let results = validation.call(this, toValidate); if (!Array.isArray(results)) { results = [results]; } - const cancelledReasons = results.filter((result) => result !== CommandResult.Success); + const cancelledReasons = results.filter((result) => result !== this.successResult); if (cancelledReasons.length) { return cancelledReasons; } } - return CommandResult.Success; + return this.successResult; }; } checkValidations( command: T, - ...validations: Validation>[] - ): CommandResult | CommandResult[] { + ...validations: Validation, Result>[] + ): Result | Result[] { return this.batchValidations(...validations)(command); } } diff --git a/packages/o-spreadsheet-engine/src/types/history.ts b/packages/o-spreadsheet-engine/src/types/history.ts new file mode 100644 index 0000000000..47603e9984 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/history.ts @@ -0,0 +1,62 @@ +export interface WorkbookHistory { + update(key: T, val: Plugin[T]): void; + update>( + key1: T, + key2: U, + val: NonNullable[U] + ): void; + update< + T extends keyof Plugin, + U extends keyof NonNullable, + K extends keyof NonNullable[U]> + >( + key1: T, + key2: U, + key3: K, + val: NonNullable[U]>[K] + ): void; + update< + T extends keyof Plugin, + U extends keyof NonNullable, + K extends keyof NonNullable[U]>, + V extends keyof NonNullable[U]>[K]> + >( + key1: T, + key2: U, + key3: K, + key4: V, + val: NonNullable[U]>[K]>[V] + ): void; + update< + T extends keyof Plugin, + U extends keyof NonNullable, + K extends keyof NonNullable[U]>, + V extends keyof NonNullable[U]>[K]>, + W extends keyof NonNullable[U]>[K]>[V]> + >( + key1: T, + key2: U, + key3: K, + key4: V, + key5: W, + val: NonNullable[U]>[K]>[V]>[W] + ): void; + update< + T extends keyof Plugin, + U extends keyof NonNullable, + K extends keyof NonNullable[U]>, + V extends keyof NonNullable[U]>[K]>, + W extends keyof NonNullable[U]>[K]>[V]>, + Y extends keyof NonNullable< + NonNullable[U]>[K]>[V]>[W] + > + >( + key1: T, + key2: U, + key3: K, + key4: V, + key5: W, + key6: Y, + val: NonNullable[U]>[K]>[V]>[W]>[Y] + ): void; +} diff --git a/packages/o-spreadsheet-engine/src/types/validator.ts b/packages/o-spreadsheet-engine/src/types/validator.ts new file mode 100644 index 0000000000..f007bb4a9a --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/validator.ts @@ -0,0 +1,21 @@ +export type Validation = (toValidate: T) => Result | Result[]; + +export interface Validator { + /** + * Combine multiple validation functions into a single function + * returning the list of results of every validation. + */ + batchValidations(...validations: Validation[]): Validation; + + /** + * Combine multiple validation functions. Every validation is executed one after + * the other. As soon as one validation fails, it stops and the cancelled reason + * is returned. + */ + chainValidations(...validations: Validation[]): Validation; + + checkValidations( + command: T, + ...validations: Validation, Result>[] + ): Result | Result[]; +} diff --git a/src/helpers/figures/charts/gauge_chart.ts b/src/helpers/figures/charts/gauge_chart.ts index 104080b67e..8443733a5f 100644 --- a/src/helpers/figures/charts/gauge_chart.ts +++ b/src/helpers/figures/charts/gauge_chart.ts @@ -1,3 +1,4 @@ +import { BasePlugin } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_GAUGE_LOWER_COLOR, DEFAULT_GAUGE_MIDDLE_COLOR, @@ -5,7 +6,6 @@ import { } from "../../../constants"; import { isMultipleElementMatrix, toScalar } from "../../../functions/helper_matrices"; import { tryToNumber } from "../../../functions/helpers"; -import { BasePlugin } from "../../../plugins/base_plugin"; import { AdaptSheetName, ApplyRangeChange, @@ -51,7 +51,7 @@ function isDataRangeValid(definition: GaugeChartDefinition): CommandResult { function checkRangeLimits( check: RangeLimitsValidation, - batchValidations: BasePlugin["batchValidations"] + batchValidations: BasePlugin["batchValidations"] ): Validation { return batchValidations( (definition) => { @@ -71,7 +71,7 @@ function checkRangeLimits( function checkInflectionPointsValue( check: InflectionPointValueValidation, - batchValidations: BasePlugin["batchValidations"] + batchValidations: BasePlugin["batchValidations"] ): Validation { return batchValidations( (definition) => { diff --git a/src/model.ts b/src/model.ts index 446430772c..67aff80617 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1,4 +1,4 @@ -import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; +import { BasePlugin, StateObserver } from "@odoo/o-spreadsheet-engine"; import { markRaw } from "@odoo/owl"; import { LocalTransportService } from "./collaborative/local_transport_service"; import { ReadonlyTransportFilter } from "./collaborative/readonly_transport_filter"; @@ -13,7 +13,6 @@ import { load, repairInitialMessages, } from "./migrations/data"; -import { BasePlugin } from "./plugins/base_plugin"; import { RangeAdapter } from "./plugins/core/range"; import { CorePlugin, CorePluginConfig, CorePluginConstructor } from "./plugins/core_plugin"; import { CoreViewPluginConfig, CoreViewPluginConstructor } from "./plugins/core_view_plugin"; diff --git a/src/plugins/core_plugin.ts b/src/plugins/core_plugin.ts index 66e2165d78..6d870f29cd 100644 --- a/src/plugins/core_plugin.ts +++ b/src/plugins/core_plugin.ts @@ -1,17 +1,18 @@ -import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; +import { BasePlugin, StateObserver } from "@odoo/o-spreadsheet-engine"; import { ModelConfig } from "../model"; import { AdaptSheetName, ApplyRangeChange, + CommandResult, CoreCommand, CoreCommandDispatcher, + ExcelWorkbookData, HistoryChange, RangeProvider, UID, WorkbookData, } from "../types"; import { CoreGetters } from "../types/getters"; -import { BasePlugin } from "./base_plugin"; import { RangeAdapter } from "./core/range"; export interface CorePluginConfig { @@ -36,7 +37,7 @@ export interface CorePluginConstructor { * They should not be concerned about UI parts or transient state. */ export class CorePlugin - extends BasePlugin + extends BasePlugin implements RangeProvider { protected getters: CoreGetters; @@ -44,7 +45,7 @@ export class CorePlugin protected canDispatch: CoreCommandDispatcher["dispatch"]; constructor({ getters, stateObserver, range, dispatch, canDispatch }: CorePluginConfig) { - super(stateObserver); + super(stateObserver, CommandResult.Success); range.addRangeProvider(this.adaptRanges.bind(this)); this.getters = getters; this.dispatch = dispatch; diff --git a/src/plugins/core_view_plugin.ts b/src/plugins/core_view_plugin.ts index 266c4c37f7..3797b19721 100644 --- a/src/plugins/core_view_plugin.ts +++ b/src/plugins/core_view_plugin.ts @@ -1,4 +1,4 @@ -import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; +import { BasePlugin, StateObserver } from "@odoo/o-spreadsheet-engine"; import { Session } from "../collaborative/session"; import { ModelConfig } from "../model"; import { SelectionStreamProcessor } from "../selection_stream/selection_stream_processor"; @@ -6,12 +6,13 @@ import { ClientPosition, Color, Command, + CommandResult, CoreCommand, Currency, + ExcelWorkbookData, Getters, HistoryChange, } from "../types/index"; -import { BasePlugin } from "./base_plugin"; import { UIActions } from "./ui_plugin"; export interface CoreViewPluginConfig { @@ -36,10 +37,16 @@ export interface CoreViewPluginConstructor { * Core view plugins handle any data derived from core date (i.e. evaluation). * They cannot impact the model data (i.e. cannot dispatch commands). */ -export class CoreViewPlugin extends BasePlugin { +export class CoreViewPlugin extends BasePlugin< + State, + Command, + CommandResult, + HistoryChange, + ExcelWorkbookData +> { protected getters: Getters; constructor({ getters, stateObserver }: CoreViewPluginConfig) { - super(stateObserver); + super(stateObserver, CommandResult.Success); this.getters = getters; } } diff --git a/src/plugins/ui_plugin.ts b/src/plugins/ui_plugin.ts index bb2a136e49..c036f721a5 100644 --- a/src/plugins/ui_plugin.ts +++ b/src/plugins/ui_plugin.ts @@ -1,4 +1,4 @@ -import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; +import { BasePlugin, StateObserver } from "@odoo/o-spreadsheet-engine"; import { Session } from "../collaborative/session"; import { ModelConfig } from "../model"; import { SelectionStreamProcessor } from "../selection_stream/selection_stream_processor"; @@ -7,14 +7,15 @@ import { Color, Command, CommandDispatcher, + CommandResult, CoreCommand, Currency, + ExcelWorkbookData, Getters, GridRenderingContext, HistoryChange, LayerName, } from "../types/index"; -import { BasePlugin } from "./base_plugin"; export type UIActions = Pick; @@ -43,7 +44,13 @@ export interface UIPluginConstructor { * UI plugins handle any transient data required to display a spreadsheet. * They can draw on the grid canvas. */ -export class UIPlugin extends BasePlugin { +export class UIPlugin extends BasePlugin< + State, + Command, + CommandResult, + HistoryChange, + ExcelWorkbookData +> { static layers: Readonly = []; protected getters: Getters; @@ -60,7 +67,7 @@ export class UIPlugin extends BasePlugin { uiActions, selection, }: UIPluginConfig) { - super(stateObserver); + super(stateObserver, CommandResult.Success); this.getters = getters; this.ui = uiActions; this.selection = selection; diff --git a/src/types/history.ts b/src/types/history.ts index a9311f1f3f..905685e6dc 100644 --- a/src/types/history.ts +++ b/src/types/history.ts @@ -14,68 +14,7 @@ export interface HistoryChange { before: any; } -export interface WorkbookHistory { - update(key: T, val: Plugin[T]): void; - update>( - key1: T, - key2: U, - val: NonNullable[U] - ): void; - update< - T extends keyof Plugin, - U extends keyof NonNullable, - K extends keyof NonNullable[U]> - >( - key1: T, - key2: U, - key3: K, - val: NonNullable[U]>[K] - ): void; - update< - T extends keyof Plugin, - U extends keyof NonNullable, - K extends keyof NonNullable[U]>, - V extends keyof NonNullable[U]>[K]> - >( - key1: T, - key2: U, - key3: K, - key4: V, - val: NonNullable[U]>[K]>[V] - ): void; - update< - T extends keyof Plugin, - U extends keyof NonNullable, - K extends keyof NonNullable[U]>, - V extends keyof NonNullable[U]>[K]>, - W extends keyof NonNullable[U]>[K]>[V]> - >( - key1: T, - key2: U, - key3: K, - key4: V, - key5: W, - val: NonNullable[U]>[K]>[V]>[W] - ): void; - update< - T extends keyof Plugin, - U extends keyof NonNullable, - K extends keyof NonNullable[U]>, - V extends keyof NonNullable[U]>[K]>, - W extends keyof NonNullable[U]>[K]>[V]>, - Y extends keyof NonNullable< - NonNullable[U]>[K]>[V]>[W] - > - >( - key1: T, - key2: U, - key3: K, - key4: V, - key5: W, - key6: Y, - val: NonNullable[U]>[K]>[V]>[W]>[Y] - ): void; -} +export type { WorkbookHistory } from "@odoo/o-spreadsheet-engine/types/history"; export type Transformation = (dataToTransform: T) => T; diff --git a/src/types/misc.ts b/src/types/misc.ts index d8b9cfcda6..0d1b13bcef 100644 --- a/src/types/misc.ts +++ b/src/types/misc.ts @@ -1,6 +1,7 @@ import { CellValue, EvaluatedCell } from "./cells"; -import { CommandResult } from "./commands"; +import type { Validation as EngineValidation } from "@odoo/o-spreadsheet-engine/types/validator"; +import type { CommandResult } from "./commands"; // ----------------------------------------------------------------------------- // MISC // ----------------------------------------------------------------------------- @@ -316,7 +317,7 @@ export interface RangeProvider { adaptRanges: (applyChange: ApplyRangeChange, sheetId: UID, sheetName: AdaptSheetName) => void; } -export type Validation = (toValidate: T) => CommandResult | CommandResult[]; +export type Validation = EngineValidation; export type Increment = 1 | -1 | 0; diff --git a/src/types/validator.ts b/src/types/validator.ts index 4921eb161e..fb336c1eca 100644 --- a/src/types/validator.ts +++ b/src/types/validator.ts @@ -1,19 +1,8 @@ -import { CommandResult } from "./commands"; -import { Validation } from "./misc"; +import type { + Validation as EngineValidation, + Validator as EngineValidator, +} from "@odoo/o-spreadsheet-engine/types/validator"; +import type { CommandResult } from "./commands"; -export interface Validator { - /** - * Combine multiple validation functions into a single function - * returning the list of result of every validation. - */ - batchValidations(...validations: Validation[]): Validation; - - /** - * Combine multiple validation functions. Every validation is executed one after - * the other. As soon as one validation fails, it stops and the cancelled reason - * is returned. - */ - chainValidations(...validations: Validation[]): Validation; - - checkValidations(command: T, ...validations: Validation[]): CommandResult | CommandResult[]; -} +export type Validation = EngineValidation; +export type Validator = EngineValidator; diff --git a/tests/test_helpers/helpers.ts b/tests/test_helpers/helpers.ts index d2840c2d1c..0b1ad28eae 100644 --- a/tests/test_helpers/helpers.ts +++ b/tests/test_helpers/helpers.ts @@ -1,3 +1,4 @@ +import { BasePlugin } from "@odoo/o-spreadsheet-engine"; import { App, Component, ComponentConstructor, useState, xml } from "@odoo/owl"; import type { ChartConfiguration } from "chart.js"; import format from "xml-formatter"; @@ -24,7 +25,6 @@ import { } from "../../src/helpers/index"; import { createEmptyExcelWorkbookData } from "../../src/migrations/data"; import { Model, ModelExternalConfig } from "../../src/model"; -import { BasePlugin } from "../../src/plugins/base_plugin"; import { MergePlugin } from "../../src/plugins/core/merge"; import { CorePluginConstructor } from "../../src/plugins/core_plugin"; import { SheetUIPlugin } from "../../src/plugins/ui_feature"; From 42db5e6aafc56fc10f1b536d155ea39d3a44077a Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 11:06:55 +0200 Subject: [PATCH 11/19] wip --- .../src/functions/function_registry.ts | 2 +- packages/o-spreadsheet-engine/src/index.ts | 2 - .../o-spreadsheet-engine/src/types/pivot.ts | 247 ------------------ .../src/types/pivot_runtime.ts | 58 ---- rollup.config.js | 18 +- src/index.ts | 4 +- 6 files changed, 14 insertions(+), 317 deletions(-) delete mode 100644 packages/o-spreadsheet-engine/src/types/pivot.ts delete mode 100644 packages/o-spreadsheet-engine/src/types/pivot_runtime.ts diff --git a/packages/o-spreadsheet-engine/src/functions/function_registry.ts b/packages/o-spreadsheet-engine/src/functions/function_registry.ts index 29d617d5f9..77b28478d2 100644 --- a/packages/o-spreadsheet-engine/src/functions/function_registry.ts +++ b/packages/o-spreadsheet-engine/src/functions/function_registry.ts @@ -1,6 +1,6 @@ import { Registry } from "../registry"; -interface ProcessResult { +export interface ProcessResult { key: string; stored: TStored; mapped: TMapped; diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts index 600a195bed..7250fca281 100644 --- a/packages/o-spreadsheet-engine/src/index.ts +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -37,6 +37,4 @@ export * from "./types/base"; export * from "./types/errors"; export * from "./types/history"; export * from "./types/locale"; -export * from "./types/pivot"; -export * from "./types/pivot_runtime"; export * from "./types/validator"; diff --git a/packages/o-spreadsheet-engine/src/types/pivot.ts b/packages/o-spreadsheet-engine/src/types/pivot.ts deleted file mode 100644 index d5bc0ffec5..0000000000 --- a/packages/o-spreadsheet-engine/src/types/pivot.ts +++ /dev/null @@ -1,247 +0,0 @@ -import { - CellValue, - Dimension, - Format, - FunctionResultObject, - SortDirection, - UID, - Zone, -} from "./base"; -import { Locale } from "./locale"; - -export const PREVIOUS_VALUE = "(previous)" as const; -export const NEXT_VALUE = "(next)" as const; - -export type Aggregator = - | "array_agg" - | "count" - | "count_distinct" - | "bool_and" - | "bool_or" - | "max" - | "min" - | "avg" - | "sum"; - -export type Granularity = - | "day" - | "week" - | "month" - | "quarter" - | "year" - | "second_number" - | "minute_number" - | "hour_number" - | "day_of_week" - | "day_of_month" - | "iso_week_number" - | "month_number" - | "quarter_number"; - -export interface PivotCoreDimension { - fieldName: string; - order?: SortDirection; - granularity?: Granularity | string; - isCustomField?: boolean; - parentField?: string; - customGroups?: PivotCustomGroup[]; -} - -export interface PivotCoreMeasure { - id: string; - userDefinedName?: string; - fieldName: string; - aggregator: Aggregator | string; - isHidden?: boolean; - format?: Format; - computedBy?: { sheetId: UID; formula: string }; - display?: PivotMeasureDisplay; -} - -export interface CommonPivotCoreDefinition { - columns: PivotCoreDimension[]; - rows: PivotCoreDimension[]; - measures: PivotCoreMeasure[]; - name: string; - deferUpdates?: boolean; - sortedColumn?: PivotSortedColumn; - collapsedDomains?: PivotCollapsedDomains; - customFields?: Record; -} - -export interface PivotSortedColumn { - order: SortDirection; - domain: PivotDomain; - measure: string; -} - -export interface PivotCollapsedDomains { - COL: PivotDomain[]; - ROW: PivotDomain[]; -} - -export interface PivotCustomGroupedField { - parentField: string; - name: string; - groups: PivotCustomGroup[]; -} - -export interface PivotCustomGroup { - name: string; - values: CellValue[]; - isOtherGroup?: boolean; -} - -export interface SpreadsheetPivotCoreDefinition extends CommonPivotCoreDefinition { - type: "SPREADSHEET"; - dataSet?: { - sheetId: UID; - zone: Zone; - }; -} - -interface FakePivotDefinition extends CommonPivotCoreDefinition { - type: "FAKE"; -} - -export type PivotCoreDefinition = SpreadsheetPivotCoreDefinition | FakePivotDefinition; - -export type TechnicalName = string; - -export interface PivotField { - name: TechnicalName; - type: string; - string: string; - aggregator?: string; - help?: string; - isCustomField?: boolean; - parentField?: string; - customGroups?: PivotCustomGroup[]; -} - -export type PivotFields = Record; - -export interface PivotMeasure extends PivotCoreMeasure { - displayName: string; - type: string; - isValid: boolean; -} - -export interface PivotDimension extends PivotCoreDimension { - nameWithGranularity: string; - displayName: string; - type: string; - isValid: boolean; -} - -export interface PivotTableColumn { - fields: string[]; - values: CellValue[]; - width: number; - offset: number; -} - -export interface PivotTableRow { - fields: string[]; - values: CellValue[]; - indent: number; -} - -export interface PivotTableData { - cols: PivotTableColumn[][]; - rows: PivotTableRow[]; - measures: string[]; - fieldsType?: Record; -} - -export interface PivotHeaderCell { - type: "HEADER"; - domain: PivotDomain; - dimension: Dimension; -} - -export interface PivotMeasureHeaderCell { - type: "MEASURE_HEADER"; - domain: PivotDomain; - measure: string; -} - -export interface PivotValueCell { - type: "VALUE"; - domain: PivotDomain; - measure: string; -} - -export interface PivotEmptyCell { - type: "EMPTY"; -} - -export type PivotTableCell = - | PivotHeaderCell - | PivotMeasureHeaderCell - | PivotValueCell - | PivotEmptyCell; - -export interface PivotTimeAdapterNotNull { - normalizeFunctionValue: (value: Exclude) => T; - toValueAndFormat: (normalizedValue: T, locale?: Locale) => FunctionResultObject; - toFunctionValue: (normalizedValue: T) => string; -} - -export interface PivotTimeAdapter { - normalizeFunctionValue: (value: CellValue) => T | null; - toValueAndFormat: (normalizedValue: T, locale?: Locale) => FunctionResultObject; - toFunctionValue: (normalizedValue: T) => string; -} - -export interface PivotNode { - field: string; - type: string; - value: CellValue; -} - -export type PivotDomain = PivotNode[]; - -export interface PivotColRowDomain { - colDomain: PivotDomain; - rowDomain: PivotDomain; -} - -export interface PivotMeasureDisplay { - type: PivotMeasureDisplayType; - fieldNameWithGranularity?: string; - value?: string | boolean | number | typeof PREVIOUS_VALUE | typeof NEXT_VALUE; -} - -export type PivotMeasureDisplayType = - | "no_calculations" - | "%_of_grand_total" - | "%_of_col_total" - | "%_of_row_total" - | "%_of_parent_row_total" - | "%_of_parent_col_total" - | "index" - | "%_of_parent_total" - | "running_total" - | "%_running_total" - | "rank_asc" - | "rank_desc" - | "%_of" - | "difference_from" - | "%_difference_from"; - -export interface DimensionTreeNode { - value: CellValue; - field: string; - type: string; - children: DimensionTree; - width: number; -} - -export type DimensionTree = DimensionTreeNode[]; - -export interface PivotVisibilityOptions { - displayColumnHeaders: boolean; - displayTotals: boolean; - displayMeasuresRow: boolean; -} diff --git a/packages/o-spreadsheet-engine/src/types/pivot_runtime.ts b/packages/o-spreadsheet-engine/src/types/pivot_runtime.ts deleted file mode 100644 index b0c8585406..0000000000 --- a/packages/o-spreadsheet-engine/src/types/pivot_runtime.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { FunctionResultObject, Maybe } from "./base"; -import { - PivotCollapsedDomains, - PivotCoreDefinition, - PivotCustomGroupedField, - PivotDimension, - PivotDomain, - PivotFields, - PivotMeasure, - PivotSortedColumn, -} from "./pivot"; - -export interface PivotRuntimeDefinition { - readonly measures: PivotMeasure[]; - readonly columns: PivotDimension[]; - readonly rows: PivotDimension[]; - readonly sortedColumn?: PivotSortedColumn; - readonly collapsedDomains?: PivotCollapsedDomains; - readonly customFields?: Record; - getDimension(nameWithGranularity: string): PivotDimension; - getMeasure(id: string): PivotMeasure; - [key: string]: unknown; -} - -export interface SpreadsheetPivotTable { - columns: unknown; - rows: unknown; - measures: string[]; - fieldsType: Record; - [key: string]: unknown; -} - -export interface InitPivotParams { - reload?: boolean; -} - -export interface Pivot { - type: PivotCoreDefinition["type"]; - definition: T; - init(params?: InitPivotParams): void; - isValid(): boolean; - onDefinitionChange(nextDefinition: PivotCoreDefinition): void; - getCollapsedTableStructure(): SpreadsheetPivotTable; - getExpandedTableStructure(): SpreadsheetPivotTable; - getFields(): PivotFields; - getPivotHeaderValueAndFormat(domain: PivotDomain): FunctionResultObject; - getPivotCellValueAndFormat(measure: string, domain: PivotDomain): FunctionResultObject; - getPivotMeasureValue(measure: string, domain: PivotDomain): FunctionResultObject; - getMeasure(id: string): PivotMeasure; - parseArgsToPivotDomain(args: Maybe[]): PivotDomain; - areDomainArgsFieldsValid(args: Maybe[]): boolean; - assertIsValid(options: { throwOnError: boolean }): FunctionResultObject | undefined; - getPossibleFieldValues( - dimension: PivotDimension - ): { value: string | boolean | number; label: string }[]; - needsReevaluation: boolean; - markAsDirtyForEvaluation?(): void; -} diff --git a/rollup.config.js b/rollup.config.js index 7d83df36b5..09f796f26e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -86,12 +86,12 @@ export default (commandLineArgs) => { ]; plugins.push(typescript({ useTsconfigDeclarationDir: true })); config = [ - { - input, - external: ["@odoo/owl"], - output, - plugins, - }, + // { + // input, + // external: ["@odoo/owl"], + // output, + // plugins, + // }, { input: "dist/types/src/index.d.ts", output: [{ file: "dist/o-spreadsheet.d.ts", format: "es" }], @@ -102,9 +102,13 @@ export default (commandLineArgs) => { entries: [ { find: "@odoo/o-spreadsheet-engine", + replacement: path.resolve(__dirname, "./dist/types/packages/o-spreadsheet-engine"), + }, + { + find: "@odoo/o-spreadsheet-engine/*", replacement: path.resolve( __dirname, - "./dist/types/packages/o-spreadsheet-engine/index.d.ts" + "./dist/types/packages/o-spreadsheet-engine/*" ), }, ], diff --git a/src/index.ts b/src/index.ts index dc4ec60d64..24e2fa0df1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -267,7 +267,7 @@ export const SPREADSHEET_DIMENSIONS = { SCROLLBAR_WIDTH, }; -export const registries = { +export const registries: Record = { autoCompleteProviders, autofillModifiersRegistry, autofillRulesRegistry, @@ -307,7 +307,7 @@ export const registries = { pivotToFunctionValueRegistry, migrationStepRegistry, chartJsExtensionRegistry, -}; +} as const; export const helpers = { arg, isEvaluationError, From ba08c5332b73aed07ff1b5118f77fed32202933f Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 11:10:21 +0200 Subject: [PATCH 12/19] wip --- rollup.config.js | 12 ++++++------ src/index.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 09f796f26e..fc30518e10 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -86,12 +86,12 @@ export default (commandLineArgs) => { ]; plugins.push(typescript({ useTsconfigDeclarationDir: true })); config = [ - // { - // input, - // external: ["@odoo/owl"], - // output, - // plugins, - // }, + { + input, + external: ["@odoo/owl"], + output, + plugins, + }, { input: "dist/types/src/index.d.ts", output: [{ file: "dist/o-spreadsheet.d.ts", format: "es" }], diff --git a/src/index.ts b/src/index.ts index 24e2fa0df1..70fa63165e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -267,7 +267,7 @@ export const SPREADSHEET_DIMENSIONS = { SCROLLBAR_WIDTH, }; -export const registries: Record = { +export const registries = { autoCompleteProviders, autofillModifiersRegistry, autofillRulesRegistry, @@ -275,7 +275,7 @@ export const registries: Record = { colMenuRegistry, errorTypes, linkMenuRegistry, - functionRegistry, + functionRegistry: typeof functionRegistry, featurePluginRegistry, iconsOnCellRegistry, statefulUIPluginRegistry, @@ -307,7 +307,7 @@ export const registries: Record = { pivotToFunctionValueRegistry, migrationStepRegistry, chartJsExtensionRegistry, -} as const; +}; export const helpers = { arg, isEvaluationError, From da90936d873c438687489c415020732519edb19e Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Tue, 30 Sep 2025 11:24:01 +0200 Subject: [PATCH 13/19] extract pivot functions from lookup --- src/functions/index.ts | 4 +- src/functions/module_lookup.ts | 226 +-------------------------------- src/functions/module_pivot.ts | 226 +++++++++++++++++++++++++++++++++ 3 files changed, 231 insertions(+), 225 deletions(-) create mode 100644 src/functions/module_pivot.ts diff --git a/src/functions/index.ts b/src/functions/index.ts index f19e348c72..312e6eb1c9 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -35,9 +35,11 @@ import * as lookup from "./module_lookup"; import * as math from "./module_math"; import * as operators from "./module_operators"; import * as parser from "./module_parser"; +import * as pivots from "./module_pivot"; import * as statistical from "./module_statistical"; import * as text from "./module_text"; import * as web from "./module_web"; + export { FunctionRegistry } from "@odoo/o-spreadsheet-engine"; export { arg } from "./arguments"; @@ -51,7 +53,7 @@ const categories: Category[] = [ { name: _t("Filter"), functions: filter }, { name: _t("Financial"), functions: financial }, { name: _t("Info"), functions: info }, - { name: _t("Lookup"), functions: lookup }, + { name: _t("Lookup"), functions: { ...lookup, ...pivots } }, { name: _t("Logical"), functions: logical }, { name: _t("Math"), functions: math }, { name: _t("Misc"), functions: misc }, diff --git a/src/functions/module_lookup.ts b/src/functions/module_lookup.ts index 6ed95bf8e9..e6ed65c91b 100644 --- a/src/functions/module_lookup.ts +++ b/src/functions/module_lookup.ts @@ -1,26 +1,9 @@ -import { getPivotTooBigErrorMessage } from "../components/translations_terms"; -import { PIVOT_MAX_NUMBER_OF_CELLS } from "../constants"; -import { getFullReference, range, splitReference, toXC, toZone } from "../helpers/index"; -import { addAlignFormatToPivotHeader } from "../helpers/pivot/pivot_helpers"; +import { getFullReference, splitReference, toXC, toZone } from "../helpers/index"; import { _t } from "../translation"; -import { - AddFunctionDescription, - Arg, - FunctionResultObject, - Matrix, - Maybe, - PivotVisibilityOptions, - Zone, -} from "../types"; +import { AddFunctionDescription, Arg, FunctionResultObject, Matrix, Maybe, Zone } from "../types"; import { CellErrorType, EvaluationError, InvalidReferenceError } from "../types/errors"; import { arg } from "./arguments"; import { expectNumberGreaterThanOrEqualToOne } from "./helper_assert"; -import { - addPivotDependencies, - assertDomainLength, - assertMeasureExist, - getPivotId, -} from "./helper_lookup"; import { LinearSearchMode, dichotomicSearch, @@ -783,211 +766,6 @@ export const XLOOKUP = { isExported: true, } satisfies AddFunctionDescription; -//-------------------------------------------------------------------------- -// Pivot functions -//-------------------------------------------------------------------------- - -// PIVOT.VALUE - -export const PIVOT_VALUE = { - description: _t("Get the value from a pivot."), - args: [ - arg("pivot_id (number,string)", _t("ID of the pivot.")), - arg("measure_name (string)", _t("Name of the measure.")), - arg("domain_field_name (string,repeating)", _t("Field name.")), - arg("domain_value (number,string,boolean,repeating)", _t("Value.")), - ], - compute: function ( - formulaId: Maybe, - measureName: Maybe, - ...domainArgs: Maybe[] - ) { - const _pivotFormulaId = toString(formulaId); - const _measure = toString(measureName); - const pivotId = getPivotId(_pivotFormulaId, this.getters); - assertMeasureExist(pivotId, _measure, this.getters); - assertDomainLength(domainArgs); - const pivot = this.getters.getPivot(pivotId); - const coreDefinition = this.getters.getPivotCoreDefinition(pivotId); - - addPivotDependencies( - this, - coreDefinition, - coreDefinition.measures.filter((m) => m.id === _measure) - ); - pivot.init({ reload: pivot.needsReevaluation }); - const error = pivot.assertIsValid({ throwOnError: false }); - if (error) { - return error; - } - - if (!pivot.areDomainArgsFieldsValid(domainArgs)) { - const suggestion = _t( - "Consider using a dynamic pivot formula: %s. Or re-insert the static pivot from the Data menu.", - `=PIVOT(${_pivotFormulaId})` - ); - return { - value: CellErrorType.GenericError, - message: _t("Dimensions don't match the pivot definition") + ". " + suggestion, - }; - } - const domain = pivot.parseArgsToPivotDomain(domainArgs); - if (this.getters.getActiveSheetId() === this.__originSheetId) { - this.getters.getPivotPresenceTracker(pivotId)?.trackValue(_measure, domain); - } - return pivot.getPivotCellValueAndFormat(_measure, domain); - }, -} satisfies AddFunctionDescription; - -// PIVOT.HEADER - -export const PIVOT_HEADER = { - description: _t("Get the header of a pivot."), - args: [ - arg("pivot_id (number,string)", _t("ID of the pivot.")), - arg("domain_field_name (string,repeating)", _t("Field name.")), - arg("domain_value (number,string,value,repeating)", _t("Value.")), - ], - compute: function ( - pivotId: Maybe, - ...domainArgs: Maybe[] - ) { - const _pivotFormulaId = toString(pivotId); - const _pivotId = getPivotId(_pivotFormulaId, this.getters); - assertDomainLength(domainArgs); - const pivot = this.getters.getPivot(_pivotId); - const coreDefinition = this.getters.getPivotCoreDefinition(_pivotId); - addPivotDependencies(this, coreDefinition, []); - pivot.init({ reload: pivot.needsReevaluation }); - const error = pivot.assertIsValid({ throwOnError: false }); - if (error) { - return error; - } - if (!pivot.areDomainArgsFieldsValid(domainArgs)) { - const suggestion = _t( - "Consider using a dynamic pivot formula: %s. Or re-insert the static pivot from the Data menu.", - `=PIVOT(${_pivotFormulaId})` - ); - return { - value: CellErrorType.GenericError, - message: _t("Dimensions don't match the pivot definition") + ". " + suggestion, - }; - } - const domain = pivot.parseArgsToPivotDomain(domainArgs); - if (this.getters.getActiveSheetId() === this.__originSheetId) { - this.getters.getPivotPresenceTracker(_pivotId)?.trackHeader(domain); - } - const lastNode = domain.at(-1); - if (lastNode?.field === "measure") { - return pivot.getPivotMeasureValue(toString(lastNode.value), domain); - } - const { value, format } = pivot.getPivotHeaderValueAndFormat(domain); - return { - value, - format: - !lastNode || lastNode.field === "measure" || lastNode.value === "false" - ? undefined - : format, - }; - }, -} satisfies AddFunctionDescription; - -export const PIVOT = { - description: _t("Get a pivot table."), - args: [ - arg("pivot_id (string)", _t("ID of the pivot.")), - arg("row_count (number, optional)", _t("number of rows")), - arg("include_total (boolean, default=TRUE)", _t("Whether to include total/sub-totals or not.")), - arg( - "include_column_titles (boolean, default=TRUE)", - _t("Whether to include the column titles or not.") - ), - arg("column_count (number, optional)", _t("number of columns")), - arg( - "include_measure_titles (boolean, default=TRUE)", - _t("Whether to include the measure titles row or not.") - ), - ], - compute: function ( - pivotFormulaId: Maybe, - rowCount: Maybe = { value: 10000 }, - includeTotal: Maybe = { value: true }, - includeColumnHeaders: Maybe = { value: true }, - columnCount: Maybe = { value: Number.MAX_VALUE }, - includeMeasureTitles: Maybe = { value: true } - ) { - const _pivotFormulaId = toString(pivotFormulaId); - const _rowCount = toNumber(rowCount, this.locale); - if (_rowCount < 0) { - return new EvaluationError(_t("The number of rows must be positive.")); - } - const _columnCount = toNumber(columnCount, this.locale); - if (_columnCount < 0) { - return new EvaluationError(_t("The number of columns must be positive.")); - } - const visibilityOptions: PivotVisibilityOptions = { - displayColumnHeaders: toBoolean(includeColumnHeaders), - displayTotals: toBoolean(includeTotal), - displayMeasuresRow: toBoolean(includeMeasureTitles), - }; - - const pivotId = getPivotId(_pivotFormulaId, this.getters); - const pivot = this.getters.getPivot(pivotId); - const coreDefinition = this.getters.getPivotCoreDefinition(pivotId); - addPivotDependencies(this, coreDefinition, coreDefinition.measures); - pivot.init({ reload: pivot.needsReevaluation }); - const error = pivot.assertIsValid({ throwOnError: false }); - if (error) { - return error; - } - const table = pivot.getCollapsedTableStructure(); - if (table.numberOfCells > PIVOT_MAX_NUMBER_OF_CELLS) { - return new EvaluationError(getPivotTooBigErrorMessage(table.numberOfCells, this.locale)); - } - const cells = table.getPivotCells(visibilityOptions); - - let headerRows = 0; - if (visibilityOptions.displayColumnHeaders) { - headerRows = table.columns.length - 1; - } - if (visibilityOptions.displayMeasuresRow) { - headerRows++; - } - const pivotTitle = this.getters.getPivotName(pivotId); - const tableHeight = Math.min(headerRows + _rowCount, cells[0].length); - if (tableHeight === 0) { - return [[{ value: pivotTitle }]]; - } - const tableWidth = Math.min(1 + _columnCount, cells.length); - const result: Matrix = []; - for (const col of range(0, tableWidth)) { - result[col] = []; - for (const row of range(0, tableHeight)) { - const pivotCell = cells[col][row]; - switch (pivotCell.type) { - case "EMPTY": - result[col].push({ value: "" }); - break; - case "HEADER": - const valueAndFormat = pivot.getPivotHeaderValueAndFormat(pivotCell.domain); - result[col].push(addAlignFormatToPivotHeader(pivotCell.domain, valueAndFormat)); - break; - case "MEASURE_HEADER": - result[col].push(pivot.getPivotMeasureValue(pivotCell.measure, pivotCell.domain)); - break; - case "VALUE": - result[col].push(pivot.getPivotCellValueAndFormat(pivotCell.measure, pivotCell.domain)); - break; - } - } - } - if (visibilityOptions.displayColumnHeaders || visibilityOptions.displayMeasuresRow) { - result[0][0] = { value: pivotTitle }; - } - return result; - }, -} satisfies AddFunctionDescription; - //-------------------------------------------------------------------------- // OFFSET //-------------------------------------------------------------------------- diff --git a/src/functions/module_pivot.ts b/src/functions/module_pivot.ts new file mode 100644 index 0000000000..d401f43580 --- /dev/null +++ b/src/functions/module_pivot.ts @@ -0,0 +1,226 @@ +import { getPivotTooBigErrorMessage } from "../components/translations_terms"; +import { PIVOT_MAX_NUMBER_OF_CELLS } from "../constants"; +import { range } from "../helpers/index"; +import { addAlignFormatToPivotHeader } from "../helpers/pivot/pivot_helpers"; +import { _t } from "../translation"; +import { + AddFunctionDescription, + FunctionResultObject, + Matrix, + Maybe, + PivotVisibilityOptions, +} from "../types"; +import { CellErrorType, EvaluationError } from "../types/errors"; +import { arg } from "./arguments"; +import { + addPivotDependencies, + assertDomainLength, + assertMeasureExist, + getPivotId, +} from "./helper_lookup"; +import { toBoolean, toNumber, toString } from "./helpers"; + +//-------------------------------------------------------------------------- +// Pivot functions +//-------------------------------------------------------------------------- + +// PIVOT.VALUE + +export const PIVOT_VALUE = { + description: _t("Get the value from a pivot."), + args: [ + arg("pivot_id (number,string)", _t("ID of the pivot.")), + arg("measure_name (string)", _t("Name of the measure.")), + arg("domain_field_name (string,repeating)", _t("Field name.")), + arg("domain_value (number,string,boolean,repeating)", _t("Value.")), + ], + compute: function ( + formulaId: Maybe, + measureName: Maybe, + ...domainArgs: Maybe[] + ) { + const _pivotFormulaId = toString(formulaId); + const _measure = toString(measureName); + const pivotId = getPivotId(_pivotFormulaId, this.getters); + assertMeasureExist(pivotId, _measure, this.getters); + assertDomainLength(domainArgs); + const pivot = this.getters.getPivot(pivotId); + const coreDefinition = this.getters.getPivotCoreDefinition(pivotId); + + addPivotDependencies( + this, + coreDefinition, + coreDefinition.measures.filter((m) => m.id === _measure) + ); + pivot.init({ reload: pivot.needsReevaluation }); + const error = pivot.assertIsValid({ throwOnError: false }); + if (error) { + return error; + } + + if (!pivot.areDomainArgsFieldsValid(domainArgs)) { + const suggestion = _t( + "Consider using a dynamic pivot formula: %s. Or re-insert the static pivot from the Data menu.", + `=PIVOT(${_pivotFormulaId})` + ); + return { + value: CellErrorType.GenericError, + message: _t("Dimensions don't match the pivot definition") + ". " + suggestion, + }; + } + const domain = pivot.parseArgsToPivotDomain(domainArgs); + if (this.getters.getActiveSheetId() === this.__originSheetId) { + this.getters.getPivotPresenceTracker(pivotId)?.trackValue(_measure, domain); + } + return pivot.getPivotCellValueAndFormat(_measure, domain); + }, +} satisfies AddFunctionDescription; + +// PIVOT.HEADER + +export const PIVOT_HEADER = { + description: _t("Get the header of a pivot."), + args: [ + arg("pivot_id (number,string)", _t("ID of the pivot.")), + arg("domain_field_name (string,repeating)", _t("Field name.")), + arg("domain_value (number,string,value,repeating)", _t("Value.")), + ], + compute: function ( + pivotId: Maybe, + ...domainArgs: Maybe[] + ) { + const _pivotFormulaId = toString(pivotId); + const _pivotId = getPivotId(_pivotFormulaId, this.getters); + assertDomainLength(domainArgs); + const pivot = this.getters.getPivot(_pivotId); + const coreDefinition = this.getters.getPivotCoreDefinition(_pivotId); + addPivotDependencies(this, coreDefinition, []); + pivot.init({ reload: pivot.needsReevaluation }); + const error = pivot.assertIsValid({ throwOnError: false }); + if (error) { + return error; + } + if (!pivot.areDomainArgsFieldsValid(domainArgs)) { + const suggestion = _t( + "Consider using a dynamic pivot formula: %s. Or re-insert the static pivot from the Data menu.", + `=PIVOT(${_pivotFormulaId})` + ); + return { + value: CellErrorType.GenericError, + message: _t("Dimensions don't match the pivot definition") + ". " + suggestion, + }; + } + const domain = pivot.parseArgsToPivotDomain(domainArgs); + if (this.getters.getActiveSheetId() === this.__originSheetId) { + this.getters.getPivotPresenceTracker(_pivotId)?.trackHeader(domain); + } + const lastNode = domain.at(-1); + if (lastNode?.field === "measure") { + return pivot.getPivotMeasureValue(toString(lastNode.value), domain); + } + const { value, format } = pivot.getPivotHeaderValueAndFormat(domain); + return { + value, + format: + !lastNode || lastNode.field === "measure" || lastNode.value === "false" + ? undefined + : format, + }; + }, +} satisfies AddFunctionDescription; + +export const PIVOT = { + description: _t("Get a pivot table."), + args: [ + arg("pivot_id (string)", _t("ID of the pivot.")), + arg("row_count (number, optional)", _t("number of rows")), + arg("include_total (boolean, default=TRUE)", _t("Whether to include total/sub-totals or not.")), + arg( + "include_column_titles (boolean, default=TRUE)", + _t("Whether to include the column titles or not.") + ), + arg("column_count (number, optional)", _t("number of columns")), + arg( + "include_measure_titles (boolean, default=TRUE)", + _t("Whether to include the measure titles row or not.") + ), + ], + compute: function ( + pivotFormulaId: Maybe, + rowCount: Maybe = { value: 10000 }, + includeTotal: Maybe = { value: true }, + includeColumnHeaders: Maybe = { value: true }, + columnCount: Maybe = { value: Number.MAX_VALUE }, + includeMeasureTitles: Maybe = { value: true } + ) { + const _pivotFormulaId = toString(pivotFormulaId); + const _rowCount = toNumber(rowCount, this.locale); + if (_rowCount < 0) { + return new EvaluationError(_t("The number of rows must be positive.")); + } + const _columnCount = toNumber(columnCount, this.locale); + if (_columnCount < 0) { + return new EvaluationError(_t("The number of columns must be positive.")); + } + const visibilityOptions: PivotVisibilityOptions = { + displayColumnHeaders: toBoolean(includeColumnHeaders), + displayTotals: toBoolean(includeTotal), + displayMeasuresRow: toBoolean(includeMeasureTitles), + }; + + const pivotId = getPivotId(_pivotFormulaId, this.getters); + const pivot = this.getters.getPivot(pivotId); + const coreDefinition = this.getters.getPivotCoreDefinition(pivotId); + addPivotDependencies(this, coreDefinition, coreDefinition.measures); + pivot.init({ reload: pivot.needsReevaluation }); + const error = pivot.assertIsValid({ throwOnError: false }); + if (error) { + return error; + } + const table = pivot.getCollapsedTableStructure(); + if (table.numberOfCells > PIVOT_MAX_NUMBER_OF_CELLS) { + return new EvaluationError(getPivotTooBigErrorMessage(table.numberOfCells, this.locale)); + } + const cells = table.getPivotCells(visibilityOptions); + + let headerRows = 0; + if (visibilityOptions.displayColumnHeaders) { + headerRows = table.columns.length - 1; + } + if (visibilityOptions.displayMeasuresRow) { + headerRows++; + } + const pivotTitle = this.getters.getPivotName(pivotId); + const tableHeight = Math.min(headerRows + _rowCount, cells[0].length); + if (tableHeight === 0) { + return [[{ value: pivotTitle }]]; + } + const tableWidth = Math.min(1 + _columnCount, cells.length); + const result: Matrix = []; + for (const col of range(0, tableWidth)) { + result[col] = []; + for (const row of range(0, tableHeight)) { + const pivotCell = cells[col][row]; + switch (pivotCell.type) { + case "EMPTY": + result[col].push({ value: "" }); + break; + case "HEADER": + const valueAndFormat = pivot.getPivotHeaderValueAndFormat(pivotCell.domain); + result[col].push(addAlignFormatToPivotHeader(pivotCell.domain, valueAndFormat)); + break; + case "MEASURE_HEADER": + result[col].push(pivot.getPivotMeasureValue(pivotCell.measure, pivotCell.domain)); + break; + case "VALUE": + result[col].push(pivot.getPivotCellValueAndFormat(pivotCell.measure, pivotCell.domain)); + break; + } + } + } + if (visibilityOptions.displayColumnHeaders || visibilityOptions.displayMeasuresRow) { + result[0][0] = { value: pivotTitle }; + } + return result; + }, +} satisfies AddFunctionDescription; From dd9fcb59831bff78c7b03f24a838800030786558 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 12:37:22 +0200 Subject: [PATCH 14/19] wip --- src/formulas/code_builder.ts | 5 ----- tests/collaborative/collaborative_monkey_party.test.ts | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 src/formulas/code_builder.ts diff --git a/src/formulas/code_builder.ts b/src/formulas/code_builder.ts deleted file mode 100644 index b96db6dde0..0000000000 --- a/src/formulas/code_builder.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { - FunctionCodeBuilder, - Scope, - type FunctionCode, -} from "@odoo/o-spreadsheet-engine/formulas/code_builder"; diff --git a/tests/collaborative/collaborative_monkey_party.test.ts b/tests/collaborative/collaborative_monkey_party.test.ts index 39ddc05b52..6f61b2af99 100644 --- a/tests/collaborative/collaborative_monkey_party.test.ts +++ b/tests/collaborative/collaborative_monkey_party.test.ts @@ -1,6 +1,6 @@ +import { FunctionCodeBuilder } from "@odoo/o-spreadsheet-engine/formulas/code_builder"; import seedrandom from "seedrandom"; import { Model } from "../../src"; -import { FunctionCodeBuilder } from "../../src/formulas/code_builder"; import { deepCopy, deepEquals, range, reorderZone } from "../../src/helpers"; import { Command, From b226bc5809b575751744f8a29161e41838c8fa24 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 30 Sep 2025 12:41:10 +0200 Subject: [PATCH 15/19] wip --- src/formulas/compiler.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/formulas/compiler.ts b/src/formulas/compiler.ts index a105bca6ad..9f21697137 100644 --- a/src/formulas/compiler.ts +++ b/src/formulas/compiler.ts @@ -12,6 +12,8 @@ import { functionRegistry } from "../functions/index"; import type { CompiledFormula, FormulaToExecute } from "../types"; import type { Token } from "./tokenizer"; +//TODO When the getters will be moved to o-spreadsheet-engine, we will be able +// to remove this file and directly use the one from o-spreadsheet-engine setFunctionRegistryProvider(() => functionRegistry); setArgTargetingImplementation(argTargeting); From aa9ea60544e068acf90354fb144c540b523fa4cd Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Tue, 30 Sep 2025 17:23:50 +0200 Subject: [PATCH 16/19] backup --- doc/add_function.md | 2 +- .../src/formulas/isExportableToExcel.ts | 2 +- .../src}/functions/arguments.ts | 11 +- .../src/functions/functionRegistry.ts | 199 +++++++++++ .../src/functions/function_registry.ts | 2 +- .../src}/functions/helper_matrices.ts | 0 .../src}/functions/helpers.ts | 17 +- packages/o-spreadsheet-engine/src/index.ts | 77 +++++ .../src}/types/functions.ts | 12 +- .../o-spreadsheet-engine/src/types/index.ts | 7 + .../src/types/isMatrix.ts | 271 +++++++++++++++ src/actions/action.ts | 3 +- src/actions/figure_menu_actions.ts | 2 +- src/actions/format_actions.ts | 13 +- src/actions/insert_actions.ts | 2 +- src/actions/menu_items_actions.ts | 3 +- .../abstract_cell_clipboard_handler.ts | 10 +- .../abstract_clipboard_handler.ts | 3 +- src/clipboard_handlers/borders_clipboard.ts | 11 +- src/clipboard_handlers/carousel_clipboard.ts | 3 +- src/clipboard_handlers/cell_clipboard.ts | 6 +- src/clipboard_handlers/chart_clipboard.ts | 3 +- .../conditional_format_clipboard.ts | 6 +- .../data_validation_clipboard.ts | 6 +- src/clipboard_handlers/image_clipboard.ts | 3 +- src/clipboard_handlers/merge_clipboard.ts | 12 +- .../references_clipboard.ts | 5 +- src/clipboard_handlers/sheet_clipboard.ts | 5 +- src/clipboard_handlers/tables_clipboard.ts | 7 +- src/collaborative/local_transport_service.ts | 2 +- src/collaborative/ot/ot.ts | 3 +- src/collaborative/ot/ot_helpers.ts | 3 +- src/collaborative/ot/ot_specific.ts | 3 +- src/collaborative/ot/srt_specific.ts | 3 +- .../readonly_transport_filter.ts | 2 +- src/collaborative/revisions.ts | 3 +- src/collaborative/session.ts | 3 +- src/components/autofill/autofill.ts | 3 +- src/components/border_editor/border_editor.ts | 9 +- .../border_editor/border_editor_widget.ts | 6 +- src/components/bottom_bar/bottom_bar.ts | 3 +- .../collaborative_client_tag.ts | 4 +- src/components/color_picker/color_picker.ts | 5 +- .../color_picker/color_picker_widget.ts | 3 +- .../composer/abstract_composer_store.ts | 32 +- .../composer/composer/cell_composer_store.ts | 4 +- src/components/composer/composer/composer.ts | 8 +- .../formula_assistant/formula_assistant.ts | 3 +- .../composer/grid_composer/grid_composer.ts | 9 +- .../standalone_composer.ts | 5 +- .../standalone_composer_store.ts | 4 +- .../clickable_cell_sort_icon.ts | 5 +- .../dashboard/clickable_cell_store.ts | 10 +- src/components/dashboard/dashboard.ts | 10 +- src/components/error_tooltip/error_tooltip.ts | 3 +- .../figures/chart/chartJs/chartjs.ts | 3 +- .../chart/chartJs/chartjs_animation_store.ts | 3 +- .../chartJs/chartjs_show_values_plugin.ts | 3 +- .../chartJs/chartjs_sunburst_labels_plugin.ts | 2 +- .../zoomable_chart/zoomable_chart_store.ts | 3 +- .../chart_dashboard_menu.ts | 3 +- .../chart/gauge/gauge_chart_component.ts | 3 +- .../chart/scorecard/chart_scorecard.ts | 3 +- src/components/figures/figure/figure.ts | 5 +- .../figure_carousel/figure_carousel.ts | 2 +- .../figures/figure_chart/figure_chart.ts | 3 +- .../figure_container/figure_container.ts | 2 +- .../figures/figure_image/figure_image.ts | 3 +- .../filters/filter_menu/filter_menu.ts | 2 +- .../filter_menu_criterion.ts | 8 +- .../filter_menu_value_list.ts | 3 +- .../full_screen_chart_store.ts | 3 +- .../grid/delayed_hovered_cell_store.ts | 3 +- src/components/grid/grid.ts | 4 +- src/components/grid_overlay/grid_overlay.ts | 14 +- .../grid_overlay/hovered_icon_store.ts | 3 +- src/components/header_group/header_group.ts | 3 +- .../header_group/header_group_container.ts | 5 +- .../headers_overlay/headers_overlay.ts | 11 +- .../headers_overlay/unhide_headers.ts | 4 +- src/components/helpers/css.ts | 3 +- .../helpers/drag_and_drop_dom_items_hook.ts | 6 +- .../helpers/drag_and_drop_grid_hook.ts | 4 +- src/components/helpers/figure_drag_helper.ts | 3 +- src/components/helpers/figure_snap_helper.ts | 4 +- src/components/highlight/border/border.ts | 3 +- src/components/highlight/corner/corner.ts | 5 +- .../highlight/highlight/highlight.ts | 12 +- src/components/icons/icons.ts | 2 +- .../link/link_display/link_display.ts | 3 +- .../link/link_editor/link_editor.ts | 3 +- src/components/menu/menu.ts | 3 +- src/components/menu_popover/menu_popover.ts | 3 +- .../paint_format_button/paint_format_store.ts | 4 +- .../pivot_html_renderer.ts | 9 +- src/components/popover/cell_popover_store.ts | 3 +- src/components/popover/popover.ts | 3 +- src/components/scrollbar.ts | 2 +- src/components/scrollbar/scrollbar.ts | 3 +- .../selection_input/selection_input.ts | 3 +- .../selection_input/selection_input_store.ts | 4 +- .../carousel_panel/carousel_panel.ts | 3 +- .../axis_design/axis_design_editor.ts | 2 +- .../data_series/data_series.ts | 2 +- .../general_design/general_design_editor.ts | 3 +- .../generic_side_panel/config_panel.ts | 3 +- .../humanize_numbers/humanize_numbers.ts | 2 +- .../chart/building_blocks/legend/legend.ts | 2 +- .../series_design/series_design_editor.ts | 2 +- .../series_with_axis_design_editor.ts | 3 +- .../show_data_markers/show_data_markers.ts | 2 +- .../show_values/show_values.ts | 2 +- .../text_styler/text_styler.ts | 5 +- .../chart_type_picker/chart_type_picker.ts | 3 +- .../chart/chart_with_axis/design_panel.ts | 2 +- .../combo_chart/combo_chart_design_panel.ts | 3 +- .../funnel_chart_design_panel.ts | 3 +- .../gauge_chart_config_panel.ts | 2 +- .../gauge_chart_design_panel.ts | 9 +- .../geo_chart_panel/geo_chart_design_panel.ts | 5 +- .../geo_chart_region_select_section.ts | 3 +- .../line_chart/line_chart_design_panel.ts | 3 +- .../main_chart_panel/main_chart_panel.ts | 12 +- .../main_chart_panel_store.ts | 3 +- .../chart/pie_chart/pie_chart_design_panel.ts | 3 +- .../radar_chart/radar_chart_design_panel.ts | 8 +- .../scorecard_chart_config_panel.ts | 3 +- .../scorecard_chart_design_panel.ts | 9 +- .../sunburst_chart_design_panel.ts | 3 +- .../treemap_category_color.ts | 3 +- .../treemap_chart_design_panel.ts | 3 +- .../treemap_color_scale.ts | 3 +- .../waterfall_chart_design_panel.ts | 9 +- .../chart/zoomable_chart/design_panel.ts | 2 +- .../cog_wheel_menu/cog_wheel_menu.ts | 2 +- .../cf_editor/cf_editor.ts | 2 +- .../cf_preview/cf_preview.ts | 3 +- .../cf_preview_list/cf_preview_list.ts | 3 +- .../conditional_formatting.ts | 5 +- .../value_in_list_criterion.ts | 3 +- .../value_in_range_criterion.ts | 3 +- .../data_validation/data_validation_panel.ts | 3 +- .../data_validation/dv_preview/dv_preview.ts | 3 +- .../find_and_replace_store.ts | 5 +- .../pivot_custom_groups_collapsible.ts | 2 +- .../pivot_layout_configurator.ts | 3 +- .../pivot_measure/pivot_measure.ts | 3 +- .../pivot_sort_section/pivot_sort_section.ts | 3 +- .../pivot_measure_display_panel.ts | 3 +- .../pivot_measure_display_panel_store.ts | 2 +- .../pivot_side_panel/pivot_side_panel.ts | 3 +- .../pivot_side_panel_store.ts | 3 +- .../pivot_spreadsheet_side_panel.ts | 3 +- .../pivot_title_section.ts | 3 +- .../remove_duplicates/remove_duplicates.ts | 3 +- .../side_panel/select_menu/select_menu.ts | 3 +- .../side_panel/table_panel/table_panel.ts | 2 +- .../table_style_editor_panel.ts | 2 +- src/components/spreadsheet/spreadsheet.ts | 9 +- src/components/tables/hovered_table_store.ts | 3 +- .../tables/table_resizer/table_resizer.ts | 5 +- src/components/top_bar/top_bar.ts | 5 +- src/constants.ts | 2 - src/formulas/compiler.ts | 3 +- src/formulas/composer_tokenizer.ts | 3 +- src/formulas/index.ts | 1 - .../createAutocompleteArgumentsProvider.ts | 85 +++++ src/functions/get_moving_average_values.ts | 22 ++ src/functions/helper_assert.ts | 5 +- src/functions/helper_logical.ts | 2 +- src/functions/helper_lookup.ts | 5 +- src/functions/helper_math.ts | 3 +- src/functions/helper_statistical.ts | 40 +-- src/functions/index.ts | 311 +----------------- src/functions/module_array.ts | 42 +-- src/functions/module_custom.ts | 10 +- src/functions/module_database.ts | 35 +- src/functions/module_date.ts | 73 ++-- src/functions/module_engineering.ts | 4 +- src/functions/module_filter.ts | 25 +- src/functions/module_financial.ts | 101 +++--- src/functions/module_info.ts | 29 +- src/functions/module_logical.ts | 24 +- src/functions/module_lookup.ts | 50 ++- src/functions/module_math.ts | 137 ++++---- src/functions/module_operators.ts | 38 +-- src/functions/module_parser.ts | 4 +- src/functions/module_pivot.ts | 15 +- src/functions/module_statistical.ts | 121 ++++--- src/functions/module_text.ts | 52 +-- src/functions/module_web.ts | 4 +- src/helpers/cells/cell_evaluation.ts | 5 +- src/helpers/cells/position_map.ts | 2 +- src/helpers/chart_date.ts | 3 +- src/helpers/clipboard/clipboard_helpers.ts | 3 +- src/helpers/color.ts | 3 +- src/helpers/coordinates.ts | 3 +- src/helpers/data_normalization.ts | 4 +- src/helpers/figures/charts/abstract_chart.ts | 12 +- src/helpers/figures/charts/bar_chart.ts | 12 +- src/helpers/figures/charts/chart_common.ts | 14 +- src/helpers/figures/charts/chart_factory.ts | 3 +- src/helpers/figures/charts/combo_chart.ts | 5 +- src/helpers/figures/charts/funnel_chart.ts | 12 +- src/helpers/figures/charts/gauge_chart.ts | 6 - .../figures/charts/gauge_chart_rendering.ts | 5 +- src/helpers/figures/charts/geo_chart.ts | 12 +- src/helpers/figures/charts/line_chart.ts | 12 +- src/helpers/figures/charts/pie_chart.ts | 12 +- src/helpers/figures/charts/pyramid_chart.ts | 12 +- src/helpers/figures/charts/radar_chart.ts | 13 +- .../charts/runtime/chart_data_extractor.ts | 2 +- .../figures/charts/runtime/chartjs_dataset.ts | 3 +- src/helpers/figures/charts/scatter_chart.ts | 12 +- src/helpers/figures/charts/scorecard_chart.ts | 5 +- .../charts/scorecard_chart_config_builder.ts | 3 +- .../figures/charts/smart_chart_engine.ts | 3 +- src/helpers/figures/charts/sunburst_chart.ts | 12 +- src/helpers/figures/charts/tree_map_chart.ts | 12 +- src/helpers/figures/charts/waterfall_chart.ts | 12 +- src/helpers/format/format.ts | 12 +- src/helpers/formulas.ts | 6 +- src/helpers/internal_viewport.ts | 14 +- src/helpers/misc.ts | 6 +- src/helpers/pivot/pivot_composer_helpers.ts | 3 +- src/helpers/pivot/pivot_helpers.ts | 13 +- src/helpers/pivot/pivot_highlight.ts | 3 +- src/helpers/pivot/pivot_menu_items.ts | 2 +- src/helpers/pivot/pivot_presentation.ts | 6 +- .../spreadsheet_pivot/spreadsheet_pivot.ts | 14 +- src/helpers/pivot/table_spreadsheet_pivot.ts | 3 +- src/helpers/range.ts | 14 +- src/helpers/recompute_zones.ts | 2 +- src/helpers/rectangle.ts | 3 +- src/helpers/rendering.ts | 3 +- src/helpers/sheet.ts | 4 +- src/helpers/sort.ts | 4 +- src/helpers/table_helpers.ts | 6 +- src/helpers/table_presets.ts | 2 +- src/helpers/text_helper.ts | 5 +- src/helpers/ui/freeze_interactive.ts | 3 +- src/helpers/ui/merge_interactive.ts | 3 +- src/helpers/ui/paste_interactive.ts | 2 +- src/helpers/ui/sheet_interactive.ts | 3 +- src/helpers/ui/table_interactive.ts | 3 +- src/helpers/ui/toggle_group_interactive.ts | 3 +- src/helpers/zones.ts | 2 +- src/history/branch.ts | 3 +- src/history/factory.ts | 3 +- src/history/operation.ts | 3 +- src/history/operation_sequence.ts | 3 +- src/history/selective_history.ts | 3 +- src/history/tree.ts | 3 +- src/index.ts | 6 +- src/migrations/data.ts | 2 +- src/migrations/migration_steps.ts | 3 +- src/model.ts | 4 - src/plugins/core/borders.ts | 22 +- src/plugins/core/carousel.ts | 2 +- src/plugins/core/cell.ts | 22 +- src/plugins/core/chart.ts | 23 +- src/plugins/core/conditional_format.ts | 5 +- src/plugins/core/data_validation.ts | 17 +- src/plugins/core/figures.ts | 17 +- src/plugins/core/header_grouping.ts | 6 +- src/plugins/core/header_size.ts | 4 +- src/plugins/core/header_visibility.ts | 3 +- src/plugins/core/image.ts | 6 +- src/plugins/core/merge.ts | 14 +- src/plugins/core/pivot.ts | 19 +- src/plugins/core/range.ts | 16 +- src/plugins/core/sheet.ts | 20 +- src/plugins/core/spreadsheet_pivot.ts | 9 +- src/plugins/core/tables.ts | 6 +- src/plugins/core_plugin.ts | 6 - src/plugins/core_view_plugin.ts | 3 - .../cell_evaluation/binary_grid.ts | 2 +- .../cell_evaluation/compilation_parameters.ts | 15 +- .../cell_evaluation/evaluation_plugin.ts | 22 +- .../cell_evaluation/evaluator.ts | 19 +- .../formula_dependency_graph.ts | 2 +- .../cell_evaluation/position_set.ts | 4 +- .../ui_core_views/cell_evaluation/r_tree.ts | 2 +- .../cell_evaluation/spreading_relation.ts | 2 +- src/plugins/ui_core_views/cell_icon_plugin.ts | 2 +- src/plugins/ui_core_views/custom_colors.ts | 5 +- src/plugins/ui_core_views/dynamic_tables.ts | 6 +- src/plugins/ui_core_views/evaluation_chart.ts | 5 +- .../evaluation_conditional_format.ts | 16 +- .../evaluation_data_validation.ts | 6 +- src/plugins/ui_core_views/header_sizes_ui.ts | 4 +- src/plugins/ui_core_views/pivot_ui.ts | 9 +- src/plugins/ui_feature/autofill.ts | 6 +- src/plugins/ui_feature/automatic_sum.ts | 13 +- src/plugins/ui_feature/cell_computed_style.ts | 2 +- src/plugins/ui_feature/checkbox_toggle.ts | 3 +- src/plugins/ui_feature/data_cleanup.ts | 10 +- .../ui_feature/datavalidation_insertion.ts | 3 +- src/plugins/ui_feature/format.ts | 5 +- .../ui_feature/header_visibility_ui.ts | 3 +- src/plugins/ui_feature/insert_pivot.ts | 3 +- src/plugins/ui_feature/local_history.ts | 3 +- .../ui_feature/pivot_presence_plugin.ts | 3 +- src/plugins/ui_feature/sort.ts | 6 +- src/plugins/ui_feature/split_to_columns.ts | 3 +- src/plugins/ui_feature/table_autofill.ts | 3 +- .../ui_feature/table_computed_style.ts | 17 +- src/plugins/ui_feature/ui_sheet.ts | 12 +- src/plugins/ui_plugin.ts | 3 - src/plugins/ui_stateful/carousel_ui.ts | 3 +- src/plugins/ui_stateful/clipboard.ts | 6 +- src/plugins/ui_stateful/filter_evaluation.ts | 4 +- src/plugins/ui_stateful/header_positions.ts | 5 +- src/plugins/ui_stateful/selection.ts | 22 +- src/plugins/ui_stateful/sheetview.ts | 17 +- .../auto_completes/auto_complete_registry.ts | 3 +- .../auto_completes/function_auto_complete.ts | 2 +- .../auto_completes/pivot_auto_complete.ts | 2 +- src/registries/autofill_modifiers.ts | 2 +- src/registries/autofill_rules.ts | 3 +- src/registries/cell_clickable_registry.ts | 3 +- src/registries/chart_types.ts | 3 +- src/registries/criterion_registry.ts | 2 +- src/registries/figures_registry.ts | 3 +- src/registries/icons_on_cell_registry.ts | 5 +- src/registries/menus/header_group_registry.ts | 3 +- src/registries/side_panel_registry.ts | 3 +- src/registries/srt_registry.ts | 3 +- src/registries/topbar_component_registry.ts | 2 +- .../selection_stream_processor.ts | 6 +- src/stores/array_formula_highlight.ts | 2 +- src/stores/formula_fingerprints_store.ts | 11 +- src/stores/grid_renderer_store.ts | 7 +- src/stores/highlight_store.ts | 3 +- src/types/autofill.ts | 5 +- src/types/cell_popovers.ts | 3 +- src/types/cells.ts | 4 +- src/types/chart/bar_chart.ts | 3 +- src/types/chart/chart.ts | 5 +- src/types/chart/combo_chart.ts | 2 +- src/types/chart/common_chart.ts | 2 +- src/types/chart/funnel_chart.ts | 2 +- src/types/chart/gauge_chart.ts | 2 +- src/types/chart/geo_chart.ts | 2 +- src/types/chart/line_chart.ts | 2 +- src/types/chart/pie_chart.ts | 2 +- src/types/chart/pyramid_chart.ts | 2 +- src/types/chart/radar_chart.ts | 2 +- src/types/chart/scorecard_chart.ts | 2 +- src/types/chart/sunburst_chart.ts | 2 +- src/types/chart/tree_map_chart.ts | 2 +- src/types/chart/waterfall_chart.ts | 2 +- src/types/clipboard.ts | 4 +- src/types/collaborative/revisions.ts | 3 +- src/types/collaborative/session.ts | 4 +- src/types/collaborative/transport_service.ts | 2 +- src/types/commands.ts | 21 +- src/types/conditional_formatting.ts | 2 +- src/types/data_validation.ts | 2 +- src/types/event_stream/selection_events.ts | 2 +- src/types/figure.ts | 2 +- src/types/format.ts | 3 +- src/types/history.ts | 3 +- src/types/image.ts | 2 +- src/types/misc.ts | 296 ----------------- src/types/pivot.ts | 4 +- src/types/pivot_runtime.ts | 10 +- src/types/range.ts | 2 - src/types/rendering.ts | 14 +- src/types/table.ts | 3 +- src/types/workbook_data.ts | 14 +- src/types/xlsx.ts | 3 +- src/xlsx/conversion/color_conversion.ts | 2 +- src/xlsx/conversion/conversion_maps.ts | 12 +- src/xlsx/conversion/figure_conversion.ts | 5 +- src/xlsx/conversion/sheet_conversion.ts | 3 +- src/xlsx/conversion/style_conversion.ts | 4 +- src/xlsx/functions/cells.ts | 2 +- src/xlsx/functions/charts.ts | 3 +- src/xlsx/functions/drawings.ts | 3 +- src/xlsx/functions/worksheet.ts | 2 +- src/xlsx/helpers/colors.ts | 2 +- src/xlsx/helpers/content_helpers.ts | 9 +- src/xlsx/helpers/xml_helpers.ts | 3 +- tests/__mocks__/transport_service.ts | 3 +- tests/autofill/autofill_plugin.test.ts | 7 +- .../border_editor_widget_component.test.ts | 5 +- tests/borders/border_plugin.test.ts | 3 +- .../aggregate_statistics_store.test.ts | 2 +- tests/bottom_bar/bottom_bar_component.test.ts | 5 +- tests/cells/cell_plugin.test.ts | 3 +- .../clipboard/clipboard_figure_plugin.test.ts | 2 +- tests/collaborative/collaborative.test.ts | 2 +- .../collaborative_monkey_party.test.ts | 2 +- tests/collaborative/ot/ot_helper.ts | 2 +- tests/colors/color_helpers.test.ts | 3 +- tests/colors/color_picker_component.test.ts | 2 +- tests/colors/custom_colors_plugin.test.ts | 3 +- tests/components/pivot_html_renderer.test.ts | 3 +- .../autocomplete_dropdown_component.test.ts | 2 +- .../composer_integration_component.test.ts | 3 +- .../formula_assistant_component.test.ts | 3 +- ...itional_formatting_panel_component.test.ts | 2 +- .../conditional_formatting_plugin.test.ts | 3 +- ...data_validation_blocking_component.test.ts | 2 +- .../data_validation_checkbox_plugin.test.ts | 3 +- .../data_validation_clipboard_plugin.test.ts | 3 +- .../data_validation_core_plugin.test.ts | 3 +- ...tion_generics_side_panel_component.test.ts | 2 +- .../data_validation_list_component.test.ts | 3 +- .../data_validation_registry.test.ts | 2 +- .../evaluation_data_validation_plugin.test.ts | 3 +- tests/evaluation/compiler.test.ts | 5 +- tests/evaluation/evaluation.test.ts | 5 +- .../evaluation_formula_array.test.ts | 7 +- .../carousel_figure_component.test.ts | 3 +- .../carousel/carousel_panel_component.test.ts | 3 +- .../figures/carousel/carousel_plugin.test.ts | 3 +- tests/figures/chart/chart_tooltip.test.ts | 3 +- tests/figures/chart/charts_component.test.ts | 2 +- tests/figures/chart/charts_zoom.test.ts | 3 +- .../figures/chart/common_chart_plugin.test.ts | 2 +- .../chart/funnel/funnel_chart_plugin.test.ts | 3 +- .../geo_chart_panel_component.test.ts | 3 +- .../scorecard_chart_component.test.ts | 9 +- .../sunburst/sunburst_chart_plugin.test.ts | 3 +- .../sunburst/sunburst_panel_component.test.ts | 3 +- .../treemap/treemap_chart_plugin.test.ts | 3 +- .../treemap/treemap_panel_component.test.ts | 3 +- .../waterfall/waterfall_chart_plugin.test.ts | 3 +- .../waterfall_panel_component.test.ts | 3 +- tests/figures/figure_component.test.ts | 3 +- .../find_and_replace_store.test.ts | 3 +- tests/formats/formatting_plugin.test.ts | 7 +- tests/functions/arguments.test.ts | 23 +- tests/functions/functions.test.ts | 5 +- tests/functions/vectorization.test.ts | 2 +- tests/grid/grid_component.test.ts | 3 +- .../grid/grid_drag_and_drop_component.test.ts | 3 +- tests/grid/highlight_component.test.ts | 3 +- tests/grid/highlight_store.test.ts | 4 +- .../header_group_component.test.ts | 3 +- .../header_group/header_group_plugin.test.ts | 25 +- tests/headers/resizing_plugin.test.ts | 5 +- tests/helpers/coordinates_helpers.test.ts | 3 +- tests/helpers/ui_helpers.test.ts | 5 +- tests/helpers/zones_helpers.test.ts | 2 +- .../history/selective_history_plugin.test.ts | 3 +- tests/menus/menu_items_registry.test.ts | 4 +- tests/model/core.test.ts | 3 +- tests/model/model_import_export.test.ts | 9 +- .../pivot_custom_groups_model.test.ts | 3 +- .../pivot_measure_display_panel.test.ts | 3 +- .../spreadsheet_pivot.test.ts | 3 +- tests/popover/popover_component.test.ts | 3 +- tests/range_plugin.test.ts | 3 +- tests/renderer/renderer_store.test.ts | 11 +- tests/repeat_commands_plugin.test.ts | 3 +- .../selection_input_component.test.ts | 3 +- tests/setup/jest_extend.ts | 3 +- tests/sheet/sheetview_plugin.test.ts | 2 +- tests/sort_plugin.test.ts | 3 +- .../split_to_column_plugin.test.ts | 3 +- .../spreadsheet/spreadsheet_component.test.ts | 2 +- tests/table/dynamic_table_plugin.test.ts | 2 +- tests/table/filter_evaluation_plugin.test.ts | 3 +- tests/table/filter_menu_component.test.ts | 2 +- tests/table/hovered_table_store.test.ts | 3 +- tests/table/table_autofill_plugin.test.ts | 3 +- .../table/table_computed_style_plugin.test.ts | 2 +- tests/table/table_core_style_plugin.test.ts | 3 +- .../table_dropdown_button_component.test.ts | 3 +- tests/table/table_helpers.test.ts | 4 +- tests/table/table_panel_component.test.ts | 3 +- tests/table/table_resize_ui_plugin.test.ts | 3 +- tests/table/table_resizer_component.test.ts | 3 +- tests/table/tables_plugin.test.ts | 2 +- tests/test_helpers/chart_helpers.ts | 3 +- tests/test_helpers/commands_helpers.ts | 20 +- tests/test_helpers/debug_helpers.ts | 2 +- tests/test_helpers/dom_helper.ts | 7 +- tests/test_helpers/getters_helpers.ts | 14 +- tests/test_helpers/helpers.ts | 12 +- tests/test_helpers/pivot_helpers.ts | 3 +- tests/test_helpers/renderer_helpers.ts | 3 +- tests/test_helpers/xlsx.ts | 5 +- tests/top_bar_component.test.ts | 3 +- tests/xlsx/xlsx_export.test.ts | 3 +- tests/xlsx/xlsx_import_export.test.ts | 10 +- 489 files changed, 1956 insertions(+), 2428 deletions(-) rename src/formulas/helpers.ts => packages/o-spreadsheet-engine/src/formulas/isExportableToExcel.ts (95%) rename {src => packages/o-spreadsheet-engine/src}/functions/arguments.ts (98%) create mode 100644 packages/o-spreadsheet-engine/src/functions/functionRegistry.ts rename {src => packages/o-spreadsheet-engine/src}/functions/helper_matrices.ts (100%) rename {src => packages/o-spreadsheet-engine/src}/functions/helpers.ts (99%) rename {src => packages/o-spreadsheet-engine/src}/types/functions.ts (84%) create mode 100644 packages/o-spreadsheet-engine/src/types/index.ts create mode 100644 packages/o-spreadsheet-engine/src/types/isMatrix.ts create mode 100644 src/functions/createAutocompleteArgumentsProvider.ts create mode 100644 src/functions/get_moving_average_values.ts diff --git a/doc/add_function.md b/doc/add_function.md index 414756ae0f..4d5a127961 100644 --- a/doc/add_function.md +++ b/doc/add_function.md @@ -17,7 +17,7 @@ ## Adding a new custom function The `addFunction` method takes a name, and a function description which should -implement the [`AddFunctionDescription`](https://github.com/odoo/o-spreadsheet/blob/49285322f75dda2d5bab4aea04daa2a3d6c28370/src/types/functions.ts#L31) interface. `addFunction` will return an object to allow chain calls. +implement the [`Functions`](https://github.com/odoo/o-spreadsheet/blob/49285322f75dda2d5bab4aea04daa2a3d6c28370/src/types/functions.ts#L31) interface. `addFunction` will return an object to allow chain calls. Below is a skeleton example to add multiple functions. diff --git a/src/formulas/helpers.ts b/packages/o-spreadsheet-engine/src/formulas/isExportableToExcel.ts similarity index 95% rename from src/formulas/helpers.ts rename to packages/o-spreadsheet-engine/src/formulas/isExportableToExcel.ts index f3c2f270df..b0b0ac7755 100644 --- a/src/formulas/helpers.ts +++ b/packages/o-spreadsheet-engine/src/formulas/isExportableToExcel.ts @@ -1,4 +1,4 @@ -import { functionRegistry } from "../functions"; +import { functionRegistry } from "../functions/functionRegistry"; import { AST, ASTFuncall, iterateAstNodes, parseTokens } from "./parser"; import { Token } from "./tokenizer"; diff --git a/src/functions/arguments.ts b/packages/o-spreadsheet-engine/src/functions/arguments.ts similarity index 98% rename from src/functions/arguments.ts rename to packages/o-spreadsheet-engine/src/functions/arguments.ts index 9c4c80ac97..503f167e58 100644 --- a/src/functions/arguments.ts +++ b/packages/o-spreadsheet-engine/src/functions/arguments.ts @@ -1,13 +1,13 @@ import { - AddFunctionDescription, ArgDefinition, ArgProposal, ArgType, FunctionDescription, -} from "../types"; + Functions, +} from "../types/functions"; //------------------------------------------------------------------------------ -// Arg description DSL +// Arg description DSLÒ //------------------------------------------------------------------------------ const ARG_REGEXP = /(.*?)\((.*?)\)(.*)/; @@ -97,10 +97,7 @@ function makeArg(str: string, description: string, proposals?: ArgProposal[]): A * * This information is useful during compilation. */ -export function addMetaInfoFromArg( - name: string, - addDescr: AddFunctionDescription -): FunctionDescription { +export function addMetaInfoFromArg(name: string, addDescr: Functions): FunctionDescription { let countArg = 0; let minArg = 0; let repeatingArg = 0; diff --git a/packages/o-spreadsheet-engine/src/functions/functionRegistry.ts b/packages/o-spreadsheet-engine/src/functions/functionRegistry.ts new file mode 100644 index 0000000000..836697e520 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/functions/functionRegistry.ts @@ -0,0 +1,199 @@ +import { _t } from "../translation"; +import { ComputeFunction, FunctionDescription, Functions, Matrix } from "../types"; + +import * as array from "./module_array"; +import * as misc from "./module_custom"; +import * as database from "./module_database"; +import * as date from "./module_date"; +import * as engineering from "./module_engineering"; +import * as filter from "./module_filter"; +import * as financial from "./module_financial"; +import * as info from "./module_info"; +import * as logical from "./module_logical"; +import * as lookup from "./module_lookup"; +import * as math from "./module_math"; +import * as operators from "./module_operators"; +import * as parser from "./module_parser"; +import * as pivots from "./module_pivot"; +import * as statistical from "./module_statistical"; +import * as text from "./module_text"; +import * as web from "./module_web"; + +type Functions = { [functionName: string]: Functions }; +export type Category = { name: string; functions: Functions }; +export const categories: Category[] = [ + { name: _t("Array"), functions: array }, + { name: _t("Database"), functions: database }, + { name: _t("Date"), functions: date }, + { name: _t("Filter"), functions: filter }, + { name: _t("Financial"), functions: financial }, + { name: _t("Info"), functions: info }, + { name: _t("Lookup"), functions: { ...lookup, ...pivots } }, + { name: _t("Logical"), functions: logical }, + { name: _t("Math"), functions: math }, + { name: _t("Misc"), functions: misc }, + { name: _t("Operator"), functions: operators }, + { name: _t("Statistical"), functions: statistical }, + { name: _t("Text"), functions: text }, + { name: _t("Engineering"), functions: engineering }, + { name: _t("Web"), functions: web }, + { name: _t("Parser"), functions: parser }, +]; +const functionNameRegex = /^[A-Z0-9\_\.]+$/; + +class SpreadsheetFunctionRegistry extends FunctionRegistry< + Functions, + FunctionDescription, + ComputeFunction | FunctionResultObject> +> { + protected process(name: string, addDescr: Functions) { + const normalizedName = name.toUpperCase(); + if (!functionNameRegex.test(normalizedName)) { + throw new Error( + _t( + "Invalid function name %s. Function names can exclusively contain alphanumerical values separated by dots (.) or underscore (_)", + normalizedName + ) + ); + } + const descr = addMetaInfoFromArg(normalizedName, addDescr); + validateArguments(descr); + const compute = createComputeFunction(descr); + return { + key: normalizedName, + stored: descr, + mapped: compute, + }; + } +} + +export const functionRegistry = new SpreadsheetFunctionRegistry(); + +function createComputeFunction( + descr: FunctionDescription +): ComputeFunction | FunctionResultObject> { + function vectorizedCompute( + this: EvalContext, + ...args: Arg[] + ): FunctionResultObject | Matrix { + const acceptToVectorize: boolean[] = []; + + const getArgToFocus = argTargeting(descr, args.length); + //#region Compute vectorisation limits + for (let i = 0; i < args.length; i++) { + const argIndex = getArgToFocus(i) ?? -1; + const argDefinition = descr.args[argIndex]; + const arg = args[i]; + if (!isMatrix(arg) && argDefinition.acceptMatrixOnly) { + throw new BadExpressionError( + _t( + "Function %s expects the parameter '%s' to be reference to a cell or range.", + descr.name, + (i + 1).toString() + ) + ); + } + acceptToVectorize.push(!argDefinition.acceptMatrix); + } + + return applyVectorization(errorHandlingCompute.bind(this), args, acceptToVectorize); + } + + function errorHandlingCompute( + this: EvalContext, + ...args: Arg[] + ): Matrix | FunctionResultObject { + for (let i = 0; i < args.length; i++) { + const arg = args[i]; + const getArgToFocus = argTargeting(descr, args.length); + const argDefinition = descr.args[getArgToFocus(i) || i]; + + // Early exit if the argument is an error and the function does not accept errors + // We only check scalar arguments, not matrix arguments for performance reasons. + // Casting helpers are responsible for handling errors in matrix arguments. + if (!argDefinition.acceptErrors && !isMatrix(arg) && isEvaluationError(arg?.value)) { + return arg; + } + } + try { + return computeFunctionToObject.apply(this, args); + } catch (e) { + return handleError(e, descr.name); + } + } + + function computeFunctionToObject( + this: EvalContext, + ...args: Arg[] + ): FunctionResultObject | Matrix { + if (this.debug) { + // eslint-disable-next-line no-debugger + debugger; + } + const result = descr.compute.apply(this, args); + + if (!isMatrix(result)) { + if (typeof result === "object" && result !== null && "value" in result) { + replaceFunctionNamePlaceholder(result, descr.name); + return result; + } + return { value: result }; + } + + if (typeof result[0][0] === "object" && result[0][0] !== null && "value" in result[0][0]) { + matrixForEach(result as Matrix, (result) => + replaceFunctionNamePlaceholder(result, descr.name) + ); + return result as Matrix; + } + + return matrixMap(result as Matrix, (row) => ({ value: row })); + } + + return vectorizedCompute; +} + +export function handleError(e: unknown, functionName: string): FunctionResultObject { + // the error could be an user error (instance of EvaluationError) + // or a javascript error (instance of Error) + // we don't want block the user with an implementation error + // so we fallback to a generic error + if (hasStringValue(e) && isEvaluationError(e.value)) { + if (hasStringMessage(e)) { + replaceFunctionNamePlaceholder(e, functionName); + } + return e; + } + console.error(e); + return new EvaluationError( + implementationErrorMessage + (hasStringMessage(e) ? " " + e.message : "") + ); +} + +function hasStringValue(obj: unknown): obj is { value: string } { + return ( + (obj as { value: string })?.value !== undefined && + typeof (obj as { value: string }).value === "string" + ); +} + +function replaceFunctionNamePlaceholder( + functionResult: FunctionResultObject, + functionName: string +) { + // for performance reasons: change in place and only if needed + if (functionResult.message?.includes("[[FUNCTION_NAME]]")) { + functionResult.message = functionResult.message.replace("[[FUNCTION_NAME]]", functionName); + } +} + +export const implementationErrorMessage = _t( + "An unexpected error occurred. Submit a support ticket at odoo.com/help." +); + +function hasStringMessage(obj: unknown): obj is { message: string } { + return ( + (obj as { message: string })?.message !== undefined && + typeof (obj as { message: string }).message === "string" + ); +} diff --git a/packages/o-spreadsheet-engine/src/functions/function_registry.ts b/packages/o-spreadsheet-engine/src/functions/function_registry.ts index 77b28478d2..c0cc895c5b 100644 --- a/packages/o-spreadsheet-engine/src/functions/function_registry.ts +++ b/packages/o-spreadsheet-engine/src/functions/function_registry.ts @@ -10,7 +10,7 @@ export abstract class FunctionRegistry { private registry = new Registry(); mapping: Record = {} as Record; - get content(): Record { + public get content(): Record { return this.registry.content; } diff --git a/src/functions/helper_matrices.ts b/packages/o-spreadsheet-engine/src/functions/helper_matrices.ts similarity index 100% rename from src/functions/helper_matrices.ts rename to packages/o-spreadsheet-engine/src/functions/helper_matrices.ts diff --git a/src/functions/helpers.ts b/packages/o-spreadsheet-engine/src/functions/helpers.ts similarity index 99% rename from src/functions/helpers.ts rename to packages/o-spreadsheet-engine/src/functions/helpers.ts index ed21181f4a..8426c2d446 100644 --- a/src/functions/helpers.ts +++ b/packages/o-spreadsheet-engine/src/functions/helpers.ts @@ -3,25 +3,16 @@ import { DateTime, isDateTime, numberToJsDate, parseDateTime } from "../helpers/ import { memoize } from "../helpers/misc"; import { isNumber, parseNumber } from "../helpers/numbers"; import { _t } from "../translation"; -import { - Arg, - CellValue, - FunctionResultNumber, - FunctionResultObject, - Locale, - Matrix, - Maybe, - SortDirection, - isMatrix, -} from "../types"; +import { CellValue, FunctionResultNumber, Locale, SortDirection } from "../types"; import { CellErrorType, + errorTypes, ErrorValue, EvaluationError, NotAvailableError, - errorTypes, } from "../types/errors"; -import { LookupCaches } from "../types/functions"; + +import { Arg, FunctionResultObject, isMatrix, LookupCaches, Matrix, Maybe } from "../types"; const SORT_TYPES_ORDER = ["number", "string", "boolean", "undefined"]; diff --git a/packages/o-spreadsheet-engine/src/index.ts b/packages/o-spreadsheet-engine/src/index.ts index 7250fca281..629854c360 100644 --- a/packages/o-spreadsheet-engine/src/index.ts +++ b/packages/o-spreadsheet-engine/src/index.ts @@ -8,6 +8,7 @@ export { setArgTargetingImplementation, setFunctionRegistryProvider, } from "./formulas/compiler"; +export { getFunctionsFromTokens, isExportableToExcel } from "./formulas/isExportableToExcel"; export { OP_PRIORITY, convertAstNodes, @@ -28,6 +29,14 @@ export { rangeTokenize } from "./formulas/range_tokenizer"; export { POSTFIX_UNARY_OPERATORS, tokenize } from "./formulas/tokenizer"; export type { Token } from "./formulas/tokenizer"; export { FunctionRegistry } from "./functions/function_registry"; +export { + Category, + categories, + functionRegistry, + handleError, + implementationErrorMessage, + type, +} from "./functions/functionRegistry"; export * from "./helpers"; export { BasePlugin } from "./plugins/base_plugin"; export { Registry } from "./registry"; @@ -35,6 +44,74 @@ export { StateObserver, type StateObserverChange } from "./state_observer"; export * from "./translation"; export * from "./types/base"; export * from "./types/errors"; +export { + ArgDefinition, + ArgProposal, + ArgType, + ComputeFunction, + EvalContext, + FunctionDescription, + Functions, + LookupCaches, +} from "./types/functions"; export * from "./types/history"; +export { + AdaptSheetName, + AdjacentEdge, + Alias, + Align, + AnchorZone, + ApplyRangeChange, + ApplyRangeChangeResult, + Arg, + Border, + BorderData, + BorderDescr, + BorderPosition, + BorderStyle, + CellPosition, + ChangeType, + ClipboardCell, + Color, + CompiledFormula, + ConsecutiveIndexes, + DIRECTION, + DataBarFill, + EnsureRange, + FilterId, + FormulaToExecute, + FunctionResultObject, + GetSymbolValue, + HeaderDimensions, + HeaderGroup, + HeaderIndex, + Highlight, + Matrix, + Maybe, + MenuMouseEvent, + Merge, + PaneDivision, + Pixel, + PixelPosition, + Position, + RangeAdapter, + RangeCompiledFormula, + RangeProvider, + ReferenceDenormalizer, + Row, + Selection, + Sheet, + Style, + TableId, + UID, + UnboundedZone, + UpdateCellData, + VerticalAlign, + Wrapping, + Zone, + ZoneDimension, + borderStyles, + isMatrix, +} from "./types/isMatrix"; export * from "./types/locale"; export * from "./types/validator"; diff --git a/src/types/functions.ts b/packages/o-spreadsheet-engine/src/types/functions.ts similarity index 84% rename from src/types/functions.ts rename to packages/o-spreadsheet-engine/src/types/functions.ts index 9f2aafd0cd..e1018bb20c 100644 --- a/src/types/functions.ts +++ b/packages/o-spreadsheet-engine/src/types/functions.ts @@ -1,8 +1,5 @@ -import { CellValue } from "./cells"; -import { Getters } from "./getters"; +import { CellPosition } from "./base"; import { Locale } from "./locale"; -import { Arg, CellPosition, FunctionResultObject, Matrix, UID } from "./misc"; -import { Range } from "./range"; export type ArgType = | "ANY" @@ -34,10 +31,9 @@ export interface ArgDefinition { } export type ArgProposal = { value: CellValue; label?: string }; - export type ComputeFunction = (this: EvalContext, ...args: Arg[]) => R; -export interface AddFunctionDescription { +export interface Functions { compute: ComputeFunction< FunctionResultObject | Matrix | CellValue | Matrix >; @@ -48,14 +44,13 @@ export interface AddFunctionDescription { hidden?: boolean; } -export type FunctionDescription = AddFunctionDescription & { +export type FunctionDescription = Functions & { name: string; minArgRequired: number; maxArgPossible: number; nbrArgRepeating: number; nbrArgOptional: number; }; - export type EvalContext = { __originSheetId: UID; __originCellPosition?: CellPosition; @@ -67,7 +62,6 @@ export type EvalContext = { debug?: boolean; lookupCaches?: LookupCaches; }; - /** * used to cache lookup values for linear search **/ diff --git a/packages/o-spreadsheet-engine/src/types/index.ts b/packages/o-spreadsheet-engine/src/types/index.ts new file mode 100644 index 0000000000..523568b652 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/index.ts @@ -0,0 +1,7 @@ +export * from "./base"; +export * from "./errors"; +export * from "./functions"; +export * from "./history"; +export * from "./isMatrix"; +export * from "./locale"; +export * from "./validator"; diff --git a/packages/o-spreadsheet-engine/src/types/isMatrix.ts b/packages/o-spreadsheet-engine/src/types/isMatrix.ts new file mode 100644 index 0000000000..ae580cbd9d --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/isMatrix.ts @@ -0,0 +1,271 @@ +/** + * The following type is meant to be used in union with other aliases to prevent + * Intellisense from resolving it. + * See https://github.com/microsoft/TypeScript/issues/31940#issuecomment-841712377 + */ +export type Alias = {} & {}; +// Col/row Index +export type HeaderIndex = number & Alias; +// any DOM pixel value +export type Pixel = number & Alias; +// Unique identifier +export type UID = string & Alias; +export type FilterId = UID & Alias; +export type TableId = UID & Alias; +/** + * CSS style color string + * e.g. "#ABC", "#AAAFFF", "rgb(30, 80, 16)" + */ +export type Color = string & Alias; + +export interface Zone { + left: HeaderIndex; + right: HeaderIndex; + top: HeaderIndex; + bottom: HeaderIndex; +} + +export interface AnchorZone { + zone: Zone; + cell: Position; +} + +export interface Selection { + anchor: AnchorZone; + zones: Zone[]; +} + +export type AdjacentEdge = { + position: "left" | "top" | "bottom" | "right"; + start: HeaderIndex; + stop: HeaderIndex; +}; + +export interface UnboundedZone { + top: HeaderIndex; + bottom: HeaderIndex | undefined; + left: HeaderIndex; + right: HeaderIndex | undefined; + /** + * The hasHeader flag is used to determine if the zone has a header (eg. A2:A or C3:3). + * + * The main issue is that the zone A1:A and A:A have different behavior. The "correct" way to handle this would be to + * allow the top/left to be undefined, but this make typing and using unbounded zones VERY annoying. So we use this + * boolean instead. + */ + hasHeader?: boolean; +} + +export interface ZoneDimension { + numberOfRows: HeaderIndex; + numberOfCols: HeaderIndex; +} + +export type Align = "left" | "right" | "center" | undefined; +export type VerticalAlign = "top" | "middle" | "bottom" | undefined; +export type Wrapping = "overflow" | "wrap" | "clip" | undefined; + +export interface Style { + bold?: boolean; + italic?: boolean; + strikethrough?: boolean; + underline?: boolean; + align?: Align; + wrapping?: Wrapping; + verticalAlign?: VerticalAlign; + fillColor?: Color; + textColor?: Color; + fontSize?: number; // in pt, not in px! +} + +export interface DataBarFill { + color: Color; + percentage: number; +} + +export interface UpdateCellData { + content?: string; + formula?: string; + style?: Style | null; + format?: Format; +} + +export interface Sheet { + id: UID; + name: string; + numberOfCols: number; + rows: Row[]; + areGridLinesVisible: boolean; + isVisible: boolean; + panes: PaneDivision; + color?: Color; +} + +export interface CellPosition { + col: HeaderIndex; + row: HeaderIndex; + sheetId: UID; +} + +export const borderStyles = ["thin", "medium", "thick", "dashed", "dotted"] as const; +export type BorderStyle = (typeof borderStyles)[number]; +// A complete border description is a pair [style, color] +export type BorderDescr = { style: BorderStyle; color: Color }; +/** + * A complete border(s) data is a set of position-color-style information + */ +export type BorderData = { + position: BorderPosition; + color?: Color; + style?: BorderStyle; +}; + +export interface Border { + top?: BorderDescr; + left?: BorderDescr; + bottom?: BorderDescr; + right?: BorderDescr; +} + +export type ReferenceDenormalizer = ( + range: Range, + isMeta: boolean, + functionName: string, + paramNumber: number +) => FunctionResultObject; +export type EnsureRange = (range: Range, isMeta: boolean) => Matrix; +export type GetSymbolValue = (symbolName: string) => Arg; +export type FormulaToExecute = ( + deps: Range[], + refFn: ReferenceDenormalizer, + range: EnsureRange, + getSymbolValue: GetSymbolValue, + ctx: object +) => Matrix | FunctionResultObject; + +export interface CompiledFormula { + execute: FormulaToExecute; + tokens: Token[]; + dependencies: string[]; + isBadExpression: boolean; + normalizedFormula: string; +} + +export interface RangeCompiledFormula extends Omit { + dependencies: Range[]; +} + +export type Matrix = T[][]; +export type FunctionResultObject = { + value: CellValue; + format?: Format; + errorOriginPosition?: CellPosition; + message?: string; + origin?: CellPosition; +}; +// FORMULA FUNCTION VALUE AND FORMAT INPUT +export type Arg = Maybe | Matrix; // undefined corresponds to the lack of argument, e.g. =SUM(1,2,,4) +export function isMatrix(x: any): x is Matrix { + return Array.isArray(x) && Array.isArray(x[0]); +} + +export interface ClipboardCell { + evaluatedCell: EvaluatedCell; + position: CellPosition; + content: string; + style?: Style | undefined; + format?: Format | undefined; + tokens?: Token[]; + border?: Border; +} + +export interface HeaderDimensions { + start: Pixel; + size: Pixel; + end: Pixel; +} + +export interface Row { + cells: Record; // number is a column index +} + +export interface Position { + col: HeaderIndex; + row: HeaderIndex; +} + +export interface PixelPosition { + x: Pixel; + y: Pixel; +} + +export interface Merge extends Zone { + id: number; +} + +export interface Highlight { + range: Range; + color: Color; + interactive?: boolean; + thinLine?: boolean; + noFill?: boolean; + /** transparency of the fill color (0-1) */ + fillAlpha?: number; + noBorder?: boolean; + dashed?: boolean; +} + +export interface PaneDivision { + /** Represents the number of frozen columns */ + xSplit: number; + /** Represents the number of frozen rows */ + ySplit: number; +} + +export type BorderPosition = + | "all" + | "hv" + | "h" + | "v" + | "external" + | "left" + | "top" + | "right" + | "bottom" + | "clear"; + +export const enum DIRECTION { + UP = "up", + DOWN = "down", + LEFT = "left", + RIGHT = "right", +} + +export type ChangeType = "REMOVE" | "RESIZE" | "MOVE" | "CHANGE" | "NONE"; +export type ApplyRangeChangeResult = + | { changeType: Exclude; range: Range } + | { changeType: "NONE" }; +export type ApplyRangeChange = (range: Range) => ApplyRangeChangeResult; +export type AdaptSheetName = { old: string; current: string }; +export type RangeAdapter = { + sheetId: UID; + sheetName: AdaptSheetName; + applyChange: ApplyRangeChange; +}; +export type ConsecutiveIndexes = HeaderIndex[]; + +export interface RangeProvider { + adaptRanges: (applyChange: ApplyRangeChange, sheetId: UID, sheetName: AdaptSheetName) => void; +} + +export type Maybe = T | undefined; + +export interface MenuMouseEvent extends MouseEvent { + closedMenuId?: UID; +} + +export interface HeaderGroup { + start: HeaderIndex; + end: HeaderIndex; + isFolded?: boolean; +} diff --git a/src/actions/action.ts b/src/actions/action.ts index 84d36a443f..0f595bde4e 100644 --- a/src/actions/action.ts +++ b/src/actions/action.ts @@ -1,4 +1,5 @@ -import { Color, SpreadsheetChildEnv } from "../types"; +import { Color } from "@odoo/o-spreadsheet-engine"; +import { SpreadsheetChildEnv } from "../types"; /* * An Action represent a menu item for the menus of the top bar diff --git a/src/actions/figure_menu_actions.ts b/src/actions/figure_menu_actions.ts index ff5ddafe0d..e753785c8f 100644 --- a/src/actions/figure_menu_actions.ts +++ b/src/actions/figure_menu_actions.ts @@ -1,4 +1,4 @@ -import { UID } from ".."; +import { UID } from "@odoo/o-spreadsheet-engine"; import { downloadFile } from "../components/helpers/dom_helpers"; import { chartToImageFile, chartToImageUrl } from "../helpers/figures/charts"; import { getMaxFigureSize } from "../helpers/figures/figure/figure"; diff --git a/src/actions/format_actions.ts b/src/actions/format_actions.ts index 40619433a8..608e9c0061 100644 --- a/src/actions/format_actions.ts +++ b/src/actions/format_actions.ts @@ -1,3 +1,4 @@ +import { Align, VerticalAlign, Wrapping } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CURRENCY, DEFAULT_FONT_SIZE, @@ -9,19 +10,9 @@ import { createAccountingFormat, createCurrencyFormat, formatValue, roundFormat import { parseLiteral } from "../helpers/cells"; import { getDateTimeFormat } from "../helpers/locale"; import { _t } from "../translation"; -import { - Align, - CellValue, - DEFAULT_LOCALE, - Format, - SpreadsheetChildEnv, - VerticalAlign, - Wrapping, -} from "../types"; +import { CellValue, DEFAULT_LOCALE, Format, SpreadsheetChildEnv } from "../types"; import { ActionSpec } from "./action"; import * as ACTIONS from "./menu_items_actions"; -import { setFormatter, setStyle } from "./menu_items_actions"; - export interface NumberFormatActionSpec extends ActionSpec { format?: Format | ((env: SpreadsheetChildEnv) => Format); } diff --git a/src/actions/insert_actions.ts b/src/actions/insert_actions.ts index 60506541a2..68565b47bb 100644 --- a/src/actions/insert_actions.ts +++ b/src/actions/insert_actions.ts @@ -1,4 +1,4 @@ -import { functionRegistry } from "../functions"; +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { isDefined } from "../helpers"; import { localizeDataValidationRule } from "../helpers/locale"; import { handlePasteResult } from "../helpers/ui/paste_interactive"; diff --git a/src/actions/menu_items_actions.ts b/src/actions/menu_items_actions.ts index 0ae7349984..9f3cdaa0d0 100644 --- a/src/actions/menu_items_actions.ts +++ b/src/actions/menu_items_actions.ts @@ -1,3 +1,4 @@ +import { Style } from "@odoo/o-spreadsheet-engine"; import { CellPopoverStore } from "../components/popover"; import { getPivotTooBigErrorMessage } from "../components/translations_terms"; import { @@ -23,7 +24,7 @@ import { interactiveCreateTable } from "../helpers/ui/table_interactive"; import { _t } from "../translation"; import { ClipboardMIMEType, ClipboardPasteOptions } from "../types/clipboard"; import { Image } from "../types/image"; -import { Dimension, Format, SpreadsheetChildEnv, Style } from "../types/index"; +import { Dimension, Format, SpreadsheetChildEnv } from "../types/index"; import { ActionSpec } from "./action"; //------------------------------------------------------------------------------ diff --git a/src/clipboard_handlers/abstract_cell_clipboard_handler.ts b/src/clipboard_handlers/abstract_cell_clipboard_handler.ts index cacaaf3a73..a72be2861e 100644 --- a/src/clipboard_handlers/abstract_cell_clipboard_handler.ts +++ b/src/clipboard_handlers/abstract_cell_clipboard_handler.ts @@ -1,13 +1,7 @@ +import { HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { recomputeZones } from "../helpers"; import { getPasteZones } from "../helpers/clipboard/clipboard_helpers"; -import { - ClipboardCellData, - ClipboardCopyOptions, - ClipboardOptions, - HeaderIndex, - UID, - Zone, -} from "../types"; +import { ClipboardCellData, ClipboardCopyOptions, ClipboardOptions } from "../types"; import { ClipboardHandler } from "./abstract_clipboard_handler"; export class AbstractCellClipboardHandler extends ClipboardHandler { diff --git a/src/clipboard_handlers/abstract_clipboard_handler.ts b/src/clipboard_handlers/abstract_clipboard_handler.ts index 9d22510e7b..9ca3f95743 100644 --- a/src/clipboard_handlers/abstract_clipboard_handler.ts +++ b/src/clipboard_handlers/abstract_clipboard_handler.ts @@ -1,3 +1,4 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { ClipboardCopyOptions, ClipboardData, @@ -6,8 +7,6 @@ import { CommandDispatcher, CommandResult, Getters, - UID, - Zone, } from "../types"; export class ClipboardHandler { diff --git a/src/clipboard_handlers/borders_clipboard.ts b/src/clipboard_handlers/borders_clipboard.ts index 5a14c9e0fd..f3401114de 100644 --- a/src/clipboard_handlers/borders_clipboard.ts +++ b/src/clipboard_handlers/borders_clipboard.ts @@ -1,15 +1,8 @@ +import { BorderDescr, BorderPosition, HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; import { splitZoneForPaste } from "../helpers/clipboard/clipboard_helpers"; import { deepEquals, groupConsecutive } from "../helpers/misc"; import { ZoneBorder, ZoneBorderData } from "../plugins/core"; -import { - BorderDescr, - BorderPosition, - ClipboardCellData, - ClipboardOptions, - ClipboardPasteTarget, - HeaderIndex, - UID, -} from "../types"; +import { ClipboardCellData, ClipboardOptions, ClipboardPasteTarget } from "../types"; import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; type ClipboardContent = { diff --git a/src/clipboard_handlers/carousel_clipboard.ts b/src/clipboard_handlers/carousel_clipboard.ts index 5bbafdfe9c..368a8203d0 100644 --- a/src/clipboard_handlers/carousel_clipboard.ts +++ b/src/clipboard_handlers/carousel_clipboard.ts @@ -1,3 +1,4 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { deepCopy, UuidGenerator } from "../helpers"; import { AbstractChart } from "../helpers/figures/charts"; import { @@ -7,8 +8,6 @@ import { ClipboardPasteTarget, CommandResult, Figure, - UID, - Zone, } from "../types"; import { AbstractFigureClipboardHandler } from "./abstract_figure_clipboard_handler"; diff --git a/src/clipboard_handlers/cell_clipboard.ts b/src/clipboard_handlers/cell_clipboard.ts index 64651153c3..a157f903cd 100644 --- a/src/clipboard_handlers/cell_clipboard.ts +++ b/src/clipboard_handlers/cell_clipboard.ts @@ -1,18 +1,14 @@ +import { CellPosition, ClipboardCell, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { deepEquals, formatValue, isZoneInside } from "../helpers"; import { getPasteZones } from "../helpers/clipboard/clipboard_helpers"; import { canonicalizeNumberValue } from "../helpers/locale"; import { createPivotFormula } from "../helpers/pivot/pivot_helpers"; import { - CellPosition, - ClipboardCell, ClipboardCellData, ClipboardCopyOptions, ClipboardOptions, ClipboardPasteTarget, CommandResult, - HeaderIndex, - UID, - Zone, } from "../types"; import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; diff --git a/src/clipboard_handlers/chart_clipboard.ts b/src/clipboard_handlers/chart_clipboard.ts index 9d8519d795..e5e367c701 100644 --- a/src/clipboard_handlers/chart_clipboard.ts +++ b/src/clipboard_handlers/chart_clipboard.ts @@ -1,3 +1,4 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { UuidGenerator } from "../helpers"; import { AbstractChart } from "../helpers/figures/charts"; import { @@ -6,8 +7,6 @@ import { ClipboardPasteTarget, CommandResult, Figure, - UID, - Zone, } from "../types"; import { AbstractFigureClipboardHandler } from "./abstract_figure_clipboard_handler"; diff --git a/src/clipboard_handlers/conditional_format_clipboard.ts b/src/clipboard_handlers/conditional_format_clipboard.ts index a406109ac3..43065a6a0b 100644 --- a/src/clipboard_handlers/conditional_format_clipboard.ts +++ b/src/clipboard_handlers/conditional_format_clipboard.ts @@ -1,14 +1,10 @@ +import { CellPosition, HeaderIndex, Maybe, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { UuidGenerator, deepEquals, positionToZone } from "../helpers"; import { - CellPosition, ClipboardCellData, ClipboardOptions, ClipboardPasteTarget, ConditionalFormat, - HeaderIndex, - Maybe, - UID, - Zone, } from "../types"; import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; diff --git a/src/clipboard_handlers/data_validation_clipboard.ts b/src/clipboard_handlers/data_validation_clipboard.ts index e6014a31a5..704d909d48 100644 --- a/src/clipboard_handlers/data_validation_clipboard.ts +++ b/src/clipboard_handlers/data_validation_clipboard.ts @@ -1,14 +1,10 @@ +import { CellPosition, HeaderIndex, Maybe, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { UuidGenerator, deepEquals, positionToZone, recomputeZones } from "../helpers"; import { - CellPosition, ClipboardCellData, ClipboardOptions, ClipboardPasteTarget, DataValidationRule, - HeaderIndex, - Maybe, - UID, - Zone, } from "../types"; import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; diff --git a/src/clipboard_handlers/image_clipboard.ts b/src/clipboard_handlers/image_clipboard.ts index 8485cdad44..3ff31a9c3a 100644 --- a/src/clipboard_handlers/image_clipboard.ts +++ b/src/clipboard_handlers/image_clipboard.ts @@ -1,3 +1,4 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { UuidGenerator, deepCopy } from "../helpers"; import { ClipboardFigureData, @@ -5,8 +6,6 @@ import { ClipboardPasteTarget, CommandResult, Figure, - UID, - Zone, } from "../types"; import { Image } from "../types/image"; import { AbstractFigureClipboardHandler } from "./abstract_figure_clipboard_handler"; diff --git a/src/clipboard_handlers/merge_clipboard.ts b/src/clipboard_handlers/merge_clipboard.ts index faaf6ecf3d..7279933bc1 100644 --- a/src/clipboard_handlers/merge_clipboard.ts +++ b/src/clipboard_handlers/merge_clipboard.ts @@ -1,14 +1,6 @@ +import { CellPosition, HeaderIndex, Maybe, Merge, UID } from "@odoo/o-spreadsheet-engine"; import { isDefined } from "../helpers"; -import { - CellPosition, - ClipboardCellData, - ClipboardOptions, - ClipboardPasteTarget, - HeaderIndex, - Maybe, - Merge, - UID, -} from "../types"; +import { ClipboardCellData, ClipboardOptions, ClipboardPasteTarget } from "../types"; import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; interface ClipboardContent { diff --git a/src/clipboard_handlers/references_clipboard.ts b/src/clipboard_handlers/references_clipboard.ts index e6b6b1b81d..7d7f4153b9 100644 --- a/src/clipboard_handlers/references_clipboard.ts +++ b/src/clipboard_handlers/references_clipboard.ts @@ -1,6 +1,5 @@ -import { ClipboardCellData, ClipboardOptions, ClipboardPasteTarget, UID, Zone } from "../types"; -import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; - +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { ClipboardCellData, ClipboardOptions, ClipboardPasteTarget } from "../types"; interface ClipboardContent { zones: Zone[]; sheetId: UID; diff --git a/src/clipboard_handlers/sheet_clipboard.ts b/src/clipboard_handlers/sheet_clipboard.ts index fd96d82b9d..1ae430c2c7 100644 --- a/src/clipboard_handlers/sheet_clipboard.ts +++ b/src/clipboard_handlers/sheet_clipboard.ts @@ -1,8 +1,7 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { doesAnyZoneCrossFrozenPane } from "../helpers"; import { getPasteZones } from "../helpers/clipboard/clipboard_helpers"; -import { ClipboardOptions, CommandResult, UID, Zone } from "../types"; -import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; - +import { ClipboardOptions, CommandResult } from "../types"; type ClipboardContent = { cells: any[][]; zones: Zone[]; diff --git a/src/clipboard_handlers/tables_clipboard.ts b/src/clipboard_handlers/tables_clipboard.ts index 23c49c9a33..d80cb819ba 100644 --- a/src/clipboard_handlers/tables_clipboard.ts +++ b/src/clipboard_handlers/tables_clipboard.ts @@ -1,18 +1,13 @@ +import { Border, CellPosition, HeaderIndex, Style, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { isZoneInside, removeFalsyAttributes, zoneToDimension } from "../helpers"; import { - Border, - CellPosition, ClipboardCellData, ClipboardCopyOptions, ClipboardOptions, ClipboardPasteTarget, CoreTableType, - HeaderIndex, RangeData, - Style, TableConfig, - UID, - Zone, } from "../types"; import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; diff --git a/src/collaborative/local_transport_service.ts b/src/collaborative/local_transport_service.ts index 45c47313c1..9390f14629 100644 --- a/src/collaborative/local_transport_service.ts +++ b/src/collaborative/local_transport_service.ts @@ -1,4 +1,4 @@ -import { UID } from "../types"; +import { UID } from "@odoo/o-spreadsheet-engine"; import { CollaborationMessage, NewMessageCallback, diff --git a/src/collaborative/ot/ot.ts b/src/collaborative/ot/ot.ts index 65cd99284a..9a0715f81e 100644 --- a/src/collaborative/ot/ot.ts +++ b/src/collaborative/ot/ot.ts @@ -1,3 +1,4 @@ +import { HeaderIndex, Zone } from "@odoo/o-spreadsheet-engine"; import { getAddHeaderStartIndex, getRangeAdapter, @@ -13,12 +14,10 @@ import { AddColumnsRowsCommand, AddMergeCommand, CoreCommand, - HeaderIndex, PositionDependentCommand, RemoveColumnsRowsCommand, SheetDependentCommand, TargetDependentCommand, - Zone, isPositionDependent, isSheetDependent, isTargetDependent, diff --git a/src/collaborative/ot/ot_helpers.ts b/src/collaborative/ot/ot_helpers.ts index 3acd42230c..8fe3c04e51 100644 --- a/src/collaborative/ot/ot_helpers.ts +++ b/src/collaborative/ot/ot_helpers.ts @@ -1,5 +1,6 @@ +import { UnboundedZone, Zone } from "@odoo/o-spreadsheet-engine"; import { expandZoneOnInsertion, reduceZoneOnDeletion } from "../../helpers"; -import { CoreCommand, RangeData, UnboundedZone, Zone } from "../../types"; +import { CoreCommand } from "../../types"; export function transformZone( zone: Z, diff --git a/src/collaborative/ot/ot_specific.ts b/src/collaborative/ot/ot_specific.ts index 2160717fdf..93aa2a7206 100644 --- a/src/collaborative/ot/ot_specific.ts +++ b/src/collaborative/ot/ot_specific.ts @@ -1,3 +1,4 @@ +import { HeaderIndex, Zone } from "@odoo/o-spreadsheet-engine"; import { getAddHeaderStartIndex, moveHeaderIndexesOnHeaderAddition, @@ -22,7 +23,6 @@ import { FreezeColumnsCommand, FreezeRowsCommand, GroupHeadersCommand, - HeaderIndex, InsertPivotCommand, MoveRangeCommand, RemoveColumnsRowsCommand, @@ -37,7 +37,6 @@ import { UpdateFigureCommand, UpdatePivotCommand, UpdateTableCommand, - Zone, } from "../../types"; import { transformRangeData, transformZone } from "./ot_helpers"; diff --git a/src/collaborative/ot/srt_specific.ts b/src/collaborative/ot/srt_specific.ts index 02d4b8b2b0..2544a2c724 100644 --- a/src/collaborative/ot/srt_specific.ts +++ b/src/collaborative/ot/srt_specific.ts @@ -11,7 +11,8 @@ import { UpdateChartCommand, UpdatePivotCommand, } from "../../types/commands"; -import { RangeAdapter } from "../../types/misc"; + +import { RangeAdapter } from "@odoo/o-spreadsheet-engine"; function updateCellCommandAdaptRange( cmd: UpdateCellCommand, diff --git a/src/collaborative/readonly_transport_filter.ts b/src/collaborative/readonly_transport_filter.ts index 0cb4fd37e5..17f1a47e88 100644 --- a/src/collaborative/readonly_transport_filter.ts +++ b/src/collaborative/readonly_transport_filter.ts @@ -1,4 +1,4 @@ -import { UID } from "../types"; +import { UID } from "@odoo/o-spreadsheet-engine"; import { CollaborationMessage, NewMessageCallback, diff --git a/src/collaborative/revisions.ts b/src/collaborative/revisions.ts index 6ceba2f022..1a7e272b2c 100644 --- a/src/collaborative/revisions.ts +++ b/src/collaborative/revisions.ts @@ -1,4 +1,5 @@ -import { ClientId, Command, CoreCommand, HistoryChange, RevisionData, UID } from "../types"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { ClientId, Command, CoreCommand, HistoryChange, RevisionData } from "../types"; export class Revision implements RevisionData { public readonly id: UID; diff --git a/src/collaborative/session.ts b/src/collaborative/session.ts index bcbc977a02..b4b0044a89 100644 --- a/src/collaborative/session.ts +++ b/src/collaborative/session.ts @@ -1,9 +1,10 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { DEBOUNCE_TIME, DEFAULT_REVISION_ID, MESSAGE_VERSION } from "../constants"; import { EventBus } from "../helpers/event_bus"; import { debounce, isDefined } from "../helpers/misc"; import { UuidGenerator } from "../helpers/uuid"; import { SelectiveHistory as RevisionLog } from "../history/selective_history"; -import { CoreCommand, HistoryChange, Lazy, UID, WorkbookData } from "../types"; +import { CoreCommand, HistoryChange, Lazy, WorkbookData } from "../types"; import { Client, ClientId, diff --git a/src/components/autofill/autofill.ts b/src/components/autofill/autofill.ts index ebe4679988..cd942faf46 100644 --- a/src/components/autofill/autofill.ts +++ b/src/components/autofill/autofill.ts @@ -1,6 +1,7 @@ +import { HeaderIndex } from "@odoo/o-spreadsheet-engine"; import { Component, useState, xml } from "@odoo/owl"; import { clip } from "../../helpers"; -import { HeaderIndex, SpreadsheetChildEnv } from "../../types"; +import { SpreadsheetChildEnv } from "../../types"; import { cssPropertiesToCss } from "../helpers/css"; import { useDragAndDropBeyondTheViewport } from "../helpers/drag_and_drop_grid_hook"; diff --git a/src/components/border_editor/border_editor.ts b/src/components/border_editor/border_editor.ts index 7ad89d6a28..5750ea686b 100644 --- a/src/components/border_editor/border_editor.ts +++ b/src/components/border_editor/border_editor.ts @@ -1,13 +1,12 @@ -import { Component, useRef, useState } from "@odoo/owl"; import { BorderPosition, BorderStyle, + borderStyles, Color, Pixel, - Rect, - SpreadsheetChildEnv, - borderStyles, -} from "../../types/index"; +} from "@odoo/o-spreadsheet-engine"; +import { Component, useRef, useState } from "@odoo/owl"; +import { Rect, SpreadsheetChildEnv } from "../../types/index"; import { ColorPickerWidget } from "../color_picker/color_picker_widget"; import { Popover, PopoverProps } from "../popover/popover"; diff --git a/src/components/border_editor/border_editor_widget.ts b/src/components/border_editor/border_editor_widget.ts index a0aa96134b..e0b8d4715d 100644 --- a/src/components/border_editor/border_editor_widget.ts +++ b/src/components/border_editor/border_editor_widget.ts @@ -1,9 +1,7 @@ +import { BorderPosition, BorderStyle, Color, Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef, useState } from "@odoo/owl"; import { DEFAULT_BORDER_DESC } from "../../constants"; -import { BorderPosition, BorderStyle, Color, Pixel, Rect, SpreadsheetChildEnv } from "../../types"; -import { ToolBarDropdownStore, useToolBarDropdownStore } from "../helpers/top_bar_tool_hook"; -import { BorderEditor } from "./border_editor"; - +import { Rect, SpreadsheetChildEnv } from "../../types"; interface Props { disabled?: boolean; dropdownMaxHeight?: Pixel; diff --git a/src/components/bottom_bar/bottom_bar.ts b/src/components/bottom_bar/bottom_bar.ts index 790984e9b7..9349c1a193 100644 --- a/src/components/bottom_bar/bottom_bar.ts +++ b/src/components/bottom_bar/bottom_bar.ts @@ -1,8 +1,9 @@ +import { MenuMouseEvent, Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef, useState } from "@odoo/owl"; import { deepEquals } from "../../helpers"; import { MenuItemRegistry } from "../../registries/menu_items_registry"; import { _t } from "../../translation"; -import { MenuMouseEvent, Pixel, Rect, SpreadsheetChildEnv, UID } from "../../types"; +import { Rect, SpreadsheetChildEnv } from "../../types"; import { Ripple } from "../animation/ripple"; import { useDragAndDropListItems } from "../helpers/drag_and_drop_dom_items_hook"; import { MenuPopover, MenuState } from "../menu_popover/menu_popover"; diff --git a/src/components/collaborative_client_tag/collaborative_client_tag.ts b/src/components/collaborative_client_tag/collaborative_client_tag.ts index 21b30d69b7..651565a148 100644 --- a/src/components/collaborative_client_tag/collaborative_client_tag.ts +++ b/src/components/collaborative_client_tag/collaborative_client_tag.ts @@ -1,7 +1,5 @@ +import { Color, HeaderIndex } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; -import { Color, HeaderIndex, SpreadsheetChildEnv } from "../../types"; -import { cssPropertiesToCss } from "../helpers/css"; - interface ClientTagProps { active: boolean; name: string; diff --git a/src/components/color_picker/color_picker.ts b/src/components/color_picker/color_picker.ts index 11ca424e88..a1b577433f 100644 --- a/src/components/color_picker/color_picker.ts +++ b/src/components/color_picker/color_picker.ts @@ -1,3 +1,4 @@ +import { Color, Pixel, PixelPosition } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { COLOR_PICKER_DEFAULTS, ICON_EDGE_LENGTH } from "../../constants"; import { @@ -10,12 +11,10 @@ import { toHex, } from "../../helpers"; import { chartFontColor } from "../../helpers/figures/charts"; -import { Color, HSLA, Pixel, PixelPosition, Rect } from "../../types"; +import { HSLA, Rect } from "../../types"; import { SpreadsheetChildEnv } from "../../types/env"; import { cssPropertiesToCss } from "../helpers/css"; import { startDnd } from "../helpers/drag_and_drop"; -import { Popover, PopoverProps } from "../popover/popover"; - const ITEM_BORDER_WIDTH = 1; const ITEM_EDGE_LENGTH = 18; const ITEMS_PER_LINE = 10; diff --git a/src/components/color_picker/color_picker_widget.ts b/src/components/color_picker/color_picker_widget.ts index 61cc5b8291..af6c96de48 100644 --- a/src/components/color_picker/color_picker_widget.ts +++ b/src/components/color_picker/color_picker_widget.ts @@ -1,5 +1,6 @@ +import { Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, useRef } from "@odoo/owl"; -import { Pixel, Rect, SpreadsheetChildEnv } from "../../types"; +import { Rect, SpreadsheetChildEnv } from "../../types"; import { ColorPicker } from "./color_picker"; interface Props { diff --git a/src/components/composer/composer/abstract_composer_store.ts b/src/components/composer/composer/abstract_composer_store.ts index 306db5308c..f71414cdd3 100644 --- a/src/components/composer/composer/abstract_composer_store.ts +++ b/src/components/composer/composer/abstract_composer_store.ts @@ -1,8 +1,20 @@ +import { + CellPosition, + Color, + functionRegistry, + FunctionResultObject, + HeaderIndex, + Highlight, + isMatrix, + Matrix, + UID, + UnboundedZone, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { DEFAULT_TOKEN_COLOR, tokenColors } from "../../../constants"; import { composerTokenize, EnrichedToken } from "../../../formulas/composer_tokenizer"; import { AST, iterateAstNodes, parseTokens } from "../../../formulas/parser"; import { POSTFIX_UNARY_OPERATORS } from "../../../formulas/tokenizer"; -import { functionRegistry } from "../../../functions"; import { isEvaluationError, transposeMatrix } from "../../../functions/helpers"; import { KeepLast } from "../../../helpers/concurrency"; import { @@ -32,23 +44,7 @@ import { SpreadsheetStore } from "../../../stores"; import { HighlightStore } from "../../../stores/highlight_store"; import { NotificationStore } from "../../../stores/notification_store"; import { _t } from "../../../translation"; -import { - CellPosition, - Color, - Command, - Direction, - EditionMode, - FunctionResultObject, - HeaderIndex, - Highlight, - isMatrix, - Matrix, - Range, - RangePart, - UID, - UnboundedZone, - Zone, -} from "../../../types"; +import { Command, Direction, EditionMode, Range, RangePart } from "../../../types"; import { EvaluationError } from "../../../types/errors"; import { SelectionEvent } from "../../../types/event_stream"; import { AutoCompleteStore } from "../autocomplete_dropdown/autocomplete_dropdown_store"; diff --git a/src/components/composer/composer/cell_composer_store.ts b/src/components/composer/composer/cell_composer_store.ts index 6d3d30dac6..8eb1cbab93 100644 --- a/src/components/composer/composer/cell_composer_store.ts +++ b/src/components/composer/composer/cell_composer_store.ts @@ -1,3 +1,4 @@ +import { CellPosition, isMatrix } from "@odoo/o-spreadsheet-engine"; import { prettify } from "../../../formulas/formula_formatter"; import { parseTokens } from "../../../formulas/parser"; import { isMultipleElementMatrix, toScalar } from "../../../functions/helper_matrices"; @@ -19,7 +20,6 @@ import { criterionEvaluatorRegistry } from "../../../registries/criterion_regist import { _t } from "../../../translation"; import { AddColumnsRowsCommand, - CellPosition, CellValueType, Command, Direction, @@ -27,10 +27,8 @@ import { FormulaCell, Locale, RemoveColumnsRowsCommand, - isMatrix, } from "../../../types"; import { AbstractComposerStore } from "./abstract_composer_store"; - const CELL_DELETED_MESSAGE = _t("The cell you are trying to edit has been deleted."); export class CellComposerStore extends AbstractComposerStore { diff --git a/src/components/composer/composer/composer.ts b/src/components/composer/composer/composer.ts index 2b1aacb29b..c6f1c0cb05 100644 --- a/src/components/composer/composer/composer.ts +++ b/src/components/composer/composer/composer.ts @@ -1,20 +1,17 @@ import { Component, onMounted, onWillUnmount, useEffect, useRef, useState } from "@odoo/owl"; import { NEWLINE, SCROLLBAR_WIDTH } from "../../../constants"; -import { functionRegistry } from "../../../functions/index"; import { debounce, deepEquals, isFormula, setColorAlpha } from "../../../helpers/index"; -import { DEFAULT_TOKEN_COLOR } from "../../../constants"; +import { FunctionDescription, functionRegistry } from "@odoo/o-spreadsheet-engine"; import { EnrichedToken } from "../../../formulas/composer_tokenizer"; import { argTargeting } from "../../../functions/arguments"; import { Store, useStore } from "../../../store_engine"; import { DOMFocusableElementStore } from "../../../stores/DOM_focus_store"; import { CSSProperties, - Color, ComposerFocusType, DOMDimension, Direction, - FunctionDescription, Rect, SpreadsheetChildEnv, } from "../../../types/index"; @@ -25,9 +22,6 @@ import { updateSelectionWithArrowKeys } from "../../helpers/selection_helpers"; import { TextValueProvider } from "../autocomplete_dropdown/autocomplete_dropdown"; import { ContentEditableHelper } from "../content_editable_helper"; import { FunctionDescriptionProvider } from "../formula_assistant/formula_assistant"; -import { SpeechBubble } from "../speech_bubble/speech_bubble"; -import { CellComposerStore } from "./cell_composer_store"; - const functions = functionRegistry.content; const ASSISTANT_WIDTH = 300; diff --git a/src/components/composer/formula_assistant/formula_assistant.ts b/src/components/composer/formula_assistant/formula_assistant.ts index 5bb6d6244e..16ee21316d 100644 --- a/src/components/composer/formula_assistant/formula_assistant.ts +++ b/src/components/composer/formula_assistant/formula_assistant.ts @@ -1,5 +1,6 @@ +import { FunctionDescription } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; -import { FunctionDescription, SpreadsheetChildEnv } from "../../../types"; +import { SpreadsheetChildEnv } from "../../../types"; import { Collapse } from "../../side_panel/components/collapse/collapse"; interface Props { diff --git a/src/components/composer/grid_composer/grid_composer.ts b/src/components/composer/grid_composer/grid_composer.ts index b767decbe9..c13a9fd51e 100644 --- a/src/components/composer/grid_composer/grid_composer.ts +++ b/src/components/composer/grid_composer/grid_composer.ts @@ -1,3 +1,4 @@ +import { CellPosition } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps } from "@odoo/owl"; import { SELECTION_BORDER_COLOR } from "../../../constants"; import { @@ -9,13 +10,7 @@ import { toXC, } from "../../../helpers"; import { Store, useStore } from "../../../store_engine"; -import { - CellPosition, - ComposerFocusType, - DOMDimension, - Rect, - SpreadsheetChildEnv, -} from "../../../types/index"; +import { ComposerFocusType, DOMDimension, Rect, SpreadsheetChildEnv } from "../../../types/index"; import { getTextDecoration } from "../../helpers"; import { cssPropertiesToCss } from "../../helpers/css"; import { CellComposerStore } from "../composer/cell_composer_store"; diff --git a/src/components/composer/standalone_composer/standalone_composer.ts b/src/components/composer/standalone_composer/standalone_composer.ts index cbad065224..2f2956dcaa 100644 --- a/src/components/composer/standalone_composer/standalone_composer.ts +++ b/src/components/composer/standalone_composer/standalone_composer.ts @@ -1,15 +1,14 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { Token } from "../../../formulas"; import { AutoCompleteProviderDefinition } from "../../../registries/auto_completes"; import { Store, useLocalStore, useStore } from "../../../store_engine"; -import { Color, ComposerFocusType, SpreadsheetChildEnv, UID } from "../../../types/index"; +import { ComposerFocusType, SpreadsheetChildEnv } from "../../../types/index"; import { cssPropertiesToCss } from "../../helpers/css"; import { useSpreadsheetRect } from "../../helpers/position_hook"; import { ComposerSelection } from "../composer/abstract_composer_store"; import { Composer } from "../composer/composer"; import { ComposerFocusStore, ComposerInterface } from "../composer_focus_store"; -import { StandaloneComposerStore } from "./standalone_composer_store"; - interface Props { onConfirm: (content: string) => void; composerContent: string; diff --git a/src/components/composer/standalone_composer/standalone_composer_store.ts b/src/components/composer/standalone_composer/standalone_composer_store.ts index 58f838f299..438aa32c92 100644 --- a/src/components/composer/standalone_composer/standalone_composer_store.ts +++ b/src/components/composer/standalone_composer/standalone_composer_store.ts @@ -1,12 +1,10 @@ +import { Color, UID, UnboundedZone, Zone } from "@odoo/o-spreadsheet-engine"; import { Token, rangeTokenize } from "../../../formulas"; import { EnrichedToken } from "../../../formulas/composer_tokenizer"; import { localizeContent } from "../../../helpers/locale"; import { setXcToFixedReferenceType } from "../../../helpers/reference_type"; import { AutoCompleteProviderDefinition } from "../../../registries/auto_completes"; import { Get } from "../../../store_engine"; -import { Color, UID, UnboundedZone, Zone } from "../../../types"; -import { AbstractComposerStore } from "../composer/abstract_composer_store"; - export interface StandaloneComposerArgs { onConfirm: (content: string) => void; content: string; diff --git a/src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts b/src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts index 333dd63be2..70ffce54ad 100644 --- a/src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts +++ b/src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts @@ -1,11 +1,10 @@ +import { CellPosition, Color, Style } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { TEXT_BODY_MUTED } from "../../../constants"; import { blendColors } from "../../../helpers"; import { Store, useStore } from "../../../store_engine"; -import { CellPosition, Color, SortDirection, SpreadsheetChildEnv, Style } from "../../../types"; +import { SortDirection, SpreadsheetChildEnv } from "../../../types"; import { cssPropertiesToCss } from "../../helpers"; -import { HoveredTableStore } from "../../tables/hovered_table_store"; - interface Props { position: CellPosition; sortDirection: SortDirection | "none"; diff --git a/src/components/dashboard/clickable_cell_store.ts b/src/components/dashboard/clickable_cell_store.ts index 53cdf35234..98b25a8993 100644 --- a/src/components/dashboard/clickable_cell_store.ts +++ b/src/components/dashboard/clickable_cell_store.ts @@ -1,15 +1,9 @@ +import { CellPosition, UID } from "@odoo/o-spreadsheet-engine"; import { ComponentConstructor, markRaw } from "@odoo/owl"; import { positionToZone, toXC } from "../../helpers"; import { CellClickableItem, clickableCellRegistry } from "../../registries/cell_clickable_registry"; import { SpreadsheetStore } from "../../stores/spreadsheet_store"; -import { - CellPosition, - Command, - Rect, - SpreadsheetChildEnv, - UID, - invalidateEvaluationCommands, -} from "../../types"; +import { Rect, SpreadsheetChildEnv } from "../../types"; export interface ClickableCell { coordinates: Rect; diff --git a/src/components/dashboard/dashboard.ts b/src/components/dashboard/dashboard.ts index a727090d61..b436d319e2 100644 --- a/src/components/dashboard/dashboard.ts +++ b/src/components/dashboard/dashboard.ts @@ -1,13 +1,7 @@ +import { Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, toRaw, useChildSubEnv, useRef } from "@odoo/owl"; import { Store, useStore } from "../../store_engine"; -import { - DOMCoordinates, - DOMDimension, - Pixel, - Rect, - Ref, - SpreadsheetChildEnv, -} from "../../types/index"; +import { DOMCoordinates, DOMDimension, Rect, Ref, SpreadsheetChildEnv } from "../../types/index"; import { DelayedHoveredCellStore } from "../grid/delayed_hovered_cell_store"; import { GridOverlay } from "../grid_overlay/grid_overlay"; import { GridPopover } from "../grid_popover/grid_popover"; diff --git a/src/components/error_tooltip/error_tooltip.ts b/src/components/error_tooltip/error_tooltip.ts index 1ce653ce22..eb672a8c5b 100644 --- a/src/components/error_tooltip/error_tooltip.ts +++ b/src/components/error_tooltip/error_tooltip.ts @@ -1,6 +1,7 @@ +import { CellPosition } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { deepEquals, positionToZone } from "../../helpers"; -import { CellPosition, CellValueType, SpreadsheetChildEnv } from "../../types"; +import { CellValueType, SpreadsheetChildEnv } from "../../types"; import { CellPopoverComponent, PopoverBuilders } from "../../types/cell_popovers"; const ERROR_TOOLTIP_MAX_HEIGHT = 80; diff --git a/src/components/figures/chart/chartJs/chartjs.ts b/src/components/figures/chart/chartJs/chartjs.ts index 487efcce52..b5f61c04b4 100644 --- a/src/components/figures/chart/chartJs/chartjs.ts +++ b/src/components/figures/chart/chartJs/chartjs.ts @@ -1,8 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, onWillUnmount, useEffect, useRef } from "@odoo/owl"; import { Chart, ChartConfiguration } from "chart.js/auto"; import { deepCopy, deepEquals } from "../../../../helpers"; import { Store, useStore } from "../../../../store_engine"; -import { SpreadsheetChildEnv, UID } from "../../../../types"; +import { SpreadsheetChildEnv } from "../../../../types"; import { ChartJSRuntime } from "../../../../types/chart/chart"; import { chartJsExtensionRegistry, registerChartJSExtensions } from "./chart_js_extension"; import { ChartAnimationStore } from "./chartjs_animation_store"; diff --git a/src/components/figures/chart/chartJs/chartjs_animation_store.ts b/src/components/figures/chart/chartJs/chartjs_animation_store.ts index 543a9a5d88..6be126e684 100644 --- a/src/components/figures/chart/chartJs/chartjs_animation_store.ts +++ b/src/components/figures/chart/chartJs/chartjs_animation_store.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { SpreadsheetStore } from "../../../../stores/spreadsheet_store"; -import { ChartType, UID } from "../../../../types"; +import { ChartType } from "../../../../types"; export class ChartAnimationStore extends SpreadsheetStore { mutators = ["disableAnimationForChart", "enableAnimationForChart"] as const; diff --git a/src/components/figures/chart/chartJs/chartjs_show_values_plugin.ts b/src/components/figures/chart/chartJs/chartjs_show_values_plugin.ts index f4aa7039be..bc846d0380 100644 --- a/src/components/figures/chart/chartJs/chartjs_show_values_plugin.ts +++ b/src/components/figures/chart/chartJs/chartjs_show_values_plugin.ts @@ -1,7 +1,8 @@ import { ChartMeta, ChartType, Plugin } from "chart.js"; import { computeTextWidth } from "../../../../helpers"; import { chartFontColor, isTrendLineAxis } from "../../../../helpers/figures/charts/chart_common"; -import { Color } from "../../../../types"; + +import { Color } from "@odoo/o-spreadsheet-engine"; export interface ChartShowValuesPluginOptions { showValues: boolean; diff --git a/src/components/figures/chart/chartJs/chartjs_sunburst_labels_plugin.ts b/src/components/figures/chart/chartJs/chartjs_sunburst_labels_plugin.ts index 59c76eb89a..e3bc74b059 100644 --- a/src/components/figures/chart/chartJs/chartjs_sunburst_labels_plugin.ts +++ b/src/components/figures/chart/chartJs/chartjs_sunburst_labels_plugin.ts @@ -1,3 +1,4 @@ +import { Style } from "@odoo/o-spreadsheet-engine"; import { ChartType, Plugin } from "chart.js"; import { getDefaultContextFont, @@ -6,7 +7,6 @@ import { sliceTextToFitWidth, } from "../../../../helpers"; import { GHOST_SUNBURST_VALUE } from "../../../../helpers/figures/charts/runtime/chartjs_dataset"; -import { Style } from "../../../../types"; import { SunburstChartRawData } from "../../../../types/chart"; export interface ChartSunburstLabelsPluginOptions { diff --git a/src/components/figures/chart/chartJs/zoomable_chart/zoomable_chart_store.ts b/src/components/figures/chart/chartJs/zoomable_chart/zoomable_chart_store.ts index ae2e92d3cd..8b7caeee43 100644 --- a/src/components/figures/chart/chartJs/zoomable_chart/zoomable_chart_store.ts +++ b/src/components/figures/chart/chartJs/zoomable_chart/zoomable_chart_store.ts @@ -1,4 +1,5 @@ -import { Command, UID } from "../../../../.."; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Command } from "../../../../.."; import { MOVING_AVERAGE_TREND_LINE_XAXIS_ID, TREND_LINE_XAXIS_ID, diff --git a/src/components/figures/chart/chart_dashboard_menu/chart_dashboard_menu.ts b/src/components/figures/chart/chart_dashboard_menu/chart_dashboard_menu.ts index 5585bdd878..add88bb570 100644 --- a/src/components/figures/chart/chart_dashboard_menu/chart_dashboard_menu.ts +++ b/src/components/figures/chart/chart_dashboard_menu/chart_dashboard_menu.ts @@ -1,10 +1,11 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { getChartMenuActions } from "../../../../actions/figure_menu_actions"; import { BACKGROUND_CHART_COLOR } from "../../../../constants"; import { isDefined } from "../../../../helpers"; import { Store, useStore } from "../../../../store_engine"; import { _t } from "../../../../translation"; -import { SpreadsheetChildEnv, UID } from "../../../../types"; +import { SpreadsheetChildEnv } from "../../../../types"; import { FullScreenChartStore } from "../../../full_screen_chart/full_screen_chart_store"; import { MenuPopover, MenuState } from "../../../menu_popover/menu_popover"; diff --git a/src/components/figures/chart/gauge/gauge_chart_component.ts b/src/components/figures/chart/gauge/gauge_chart_component.ts index 931f9138ac..c9799918a3 100644 --- a/src/components/figures/chart/gauge/gauge_chart_component.ts +++ b/src/components/figures/chart/gauge/gauge_chart_component.ts @@ -1,9 +1,10 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useEffect, useRef } from "@odoo/owl"; import { deepEquals } from "../../../../helpers"; import { drawGaugeChart } from "../../../../helpers/figures/charts/gauge_chart_rendering"; import { EASING_FN } from "../../../../registries/cell_animation_registry"; import { Store, useStore } from "../../../../store_engine"; -import { SpreadsheetChildEnv, UID } from "../../../../types"; +import { SpreadsheetChildEnv } from "../../../../types"; import { GaugeChartRuntime } from "../../../../types/chart"; import { ChartAnimationStore } from "../chartJs/chartjs_animation_store"; diff --git a/src/components/figures/chart/scorecard/chart_scorecard.ts b/src/components/figures/chart/scorecard/chart_scorecard.ts index a6670ee8b5..4f43e0cc58 100644 --- a/src/components/figures/chart/scorecard/chart_scorecard.ts +++ b/src/components/figures/chart/scorecard/chart_scorecard.ts @@ -1,7 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useEffect, useRef } from "@odoo/owl"; import { drawScoreChart } from "../../../../helpers/figures/charts/scorecard_chart"; import { getScorecardConfiguration } from "../../../../helpers/figures/charts/scorecard_chart_config_builder"; -import { SpreadsheetChildEnv, UID } from "../../../../types"; +import { SpreadsheetChildEnv } from "../../../../types"; import { ScorecardChartRuntime } from "../../../../types/chart/scorecard_chart"; interface Props { diff --git a/src/components/figures/figure/figure.ts b/src/components/figures/figure/figure.ts index f858729651..bac51d7790 100644 --- a/src/components/figures/figure/figure.ts +++ b/src/components/figures/figure/figure.ts @@ -1,3 +1,4 @@ +import { Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUnmount, useEffect, useRef, useState } from "@odoo/owl"; import { FIGURE_BORDER_COLOR, SELECTION_BORDER_COLOR } from "../../../constants"; import { figureRegistry } from "../../../registries/figures_registry"; @@ -5,16 +6,12 @@ import { AnchorOffset, CSSProperties, FigureUI, - Pixel, Rect, ResizeDirection, SpreadsheetChildEnv, - UID, } from "../../../types/index"; import { cssPropertiesToCss } from "../../helpers/css"; import { getRefBoundingRect, keyboardEventToShortcutString } from "../../helpers/dom_helpers"; -import { MenuPopover, MenuState } from "../../menu_popover/menu_popover"; - type ResizeAnchor = | "top left" | "top" diff --git a/src/components/figures/figure_carousel/figure_carousel.ts b/src/components/figures/figure_carousel/figure_carousel.ts index 8e53bde51b..90bb2e4ae7 100644 --- a/src/components/figures/figure_carousel/figure_carousel.ts +++ b/src/components/figures/figure_carousel/figure_carousel.ts @@ -1,3 +1,4 @@ +import { MenuMouseEvent } from "@odoo/o-spreadsheet-engine"; import { Component, useEffect, useRef, useState } from "@odoo/owl"; import { ActionSpec, createActions } from "../../../actions/action"; import { DEFAULT_CAROUSEL_TITLE_STYLE } from "../../../constants"; @@ -10,7 +11,6 @@ import { CarouselItem, CSSProperties, FigureUI, - MenuMouseEvent, SpreadsheetChildEnv, } from "../../../types"; import { cellTextStyleToCss, cssPropertiesToCss } from "../../helpers"; diff --git a/src/components/figures/figure_chart/figure_chart.ts b/src/components/figures/figure_chart/figure_chart.ts index 1436fb7fad..aba29a4425 100644 --- a/src/components/figures/figure_chart/figure_chart.ts +++ b/src/components/figures/figure_chart/figure_chart.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { chartComponentRegistry } from "../../../registries/chart_types"; -import { ChartType, CSSProperties, FigureUI, SpreadsheetChildEnv, UID } from "../../../types"; +import { ChartType, CSSProperties, FigureUI, SpreadsheetChildEnv } from "../../../types"; import { ChartDashboardMenu } from "../chart/chart_dashboard_menu/chart_dashboard_menu"; interface Props { diff --git a/src/components/figures/figure_container/figure_container.ts b/src/components/figures/figure_container/figure_container.ts index 5549a56128..52dbf53f3c 100644 --- a/src/components/figures/figure_container/figure_container.ts +++ b/src/components/figures/figure_container/figure_container.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, onWillUpdateProps, useState } from "@odoo/owl"; import { DRAG_THRESHOLD, MIN_FIG_SIZE } from "../../../constants"; import { isDefined } from "../../../helpers"; @@ -10,7 +11,6 @@ import { Rect, ResizeDirection, SpreadsheetChildEnv, - UID, } from "../../../types/index"; import { cssPropertiesToCss } from "../../helpers"; import { startDnd } from "../../helpers/drag_and_drop"; diff --git a/src/components/figures/figure_image/figure_image.ts b/src/components/figures/figure_image/figure_image.ts index 2e603f1f6f..f3be325daa 100644 --- a/src/components/figures/figure_image/figure_image.ts +++ b/src/components/figures/figure_image/figure_image.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; -import { CSSProperties, FigureUI, SpreadsheetChildEnv, UID } from "../../../types"; +import { CSSProperties, FigureUI, SpreadsheetChildEnv } from "../../../types"; interface Props { figureUI: FigureUI; diff --git a/src/components/filters/filter_menu/filter_menu.ts b/src/components/filters/filter_menu/filter_menu.ts index 8f15d477a2..5406511c3e 100644 --- a/src/components/filters/filter_menu/filter_menu.ts +++ b/src/components/filters/filter_menu/filter_menu.ts @@ -1,3 +1,4 @@ +import { Position } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps } from "@odoo/owl"; import { deepEquals, isDateTimeFormat } from "../../../helpers"; import { interactiveSort } from "../../../helpers/sort"; @@ -5,7 +6,6 @@ import { CellValueType, CriterionFilter, DataFilterValue, - Position, SortDirection, SpreadsheetChildEnv, filterDateCriterionOperators, diff --git a/src/components/filters/filter_menu_criterion/filter_menu_criterion.ts b/src/components/filters/filter_menu_criterion/filter_menu_criterion.ts index 1d5ae0fe05..9730ccfdb2 100644 --- a/src/components/filters/filter_menu_criterion/filter_menu_criterion.ts +++ b/src/components/filters/filter_menu_criterion/filter_menu_criterion.ts @@ -1,3 +1,4 @@ +import { Position } from "@odoo/o-spreadsheet-engine"; import { Component, ComponentConstructor, onWillUpdateProps, useState } from "@odoo/owl"; import { Action, createAction } from "../../../actions/action"; import { deepCopy, deepEquals } from "../../../helpers"; @@ -7,12 +8,7 @@ import { } from "../../../registries/criterion_component_registry"; import { criterionEvaluatorRegistry } from "../../../registries/criterion_registry"; import { _t } from "../../../translation"; -import { - CriterionFilter, - GenericCriterionType, - Position, - SpreadsheetChildEnv, -} from "../../../types"; +import { CriterionFilter, GenericCriterionType, SpreadsheetChildEnv } from "../../../types"; import { SelectMenu } from "../../side_panel/select_menu/select_menu"; interface Props { diff --git a/src/components/filters/filter_menu_value_list/filter_menu_value_list.ts b/src/components/filters/filter_menu_value_list/filter_menu_value_list.ts index 38dd48571a..a4206491c8 100644 --- a/src/components/filters/filter_menu_value_list/filter_menu_value_list.ts +++ b/src/components/filters/filter_menu_value_list/filter_menu_value_list.ts @@ -1,7 +1,8 @@ +import { Position } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef, useState } from "@odoo/owl"; import { deepEquals, positions, toLowerCase } from "../../../helpers"; import { fuzzyLookup } from "../../../helpers/search"; -import { Position, SpreadsheetChildEnv } from "../../../types"; +import { SpreadsheetChildEnv } from "../../../types"; import { FilterMenuValueItem } from "../filter_menu_item/filter_menu_value_item"; interface Props { diff --git a/src/components/full_screen_chart/full_screen_chart_store.ts b/src/components/full_screen_chart/full_screen_chart_store.ts index a6bdc73064..7c723f8cbc 100644 --- a/src/components/full_screen_chart/full_screen_chart_store.ts +++ b/src/components/full_screen_chart/full_screen_chart_store.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { SpreadsheetStore } from "../../stores"; -import { FigureUI, UID } from "../../types"; +import { FigureUI } from "../../types"; export class FullScreenChartStore extends SpreadsheetStore { mutators = ["toggleFullScreenChart"] as const; diff --git a/src/components/grid/delayed_hovered_cell_store.ts b/src/components/grid/delayed_hovered_cell_store.ts index ea330c79e5..11f242ef42 100644 --- a/src/components/grid/delayed_hovered_cell_store.ts +++ b/src/components/grid/delayed_hovered_cell_store.ts @@ -1,5 +1,6 @@ +import { Position } from "@odoo/o-spreadsheet-engine"; import { SpreadsheetStore } from "../../stores"; -import { Command, Position } from "../../types"; +import { Command } from "../../types"; export class DelayedHoveredCellStore extends SpreadsheetStore { mutators = ["clear", "hover"] as const; diff --git a/src/components/grid/grid.ts b/src/components/grid/grid.ts index daaac21860..c5b779514f 100644 --- a/src/components/grid/grid.ts +++ b/src/components/grid/grid.ts @@ -1,3 +1,4 @@ +import { Align, HeaderIndex, Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, @@ -41,7 +42,6 @@ import { ClientFocusStore } from "../../stores/client_focus_store"; import { HighlightStore } from "../../stores/highlight_store"; import { AllowedImageMimeTypes } from "../../types/image"; import { - Align, CellValueType, Client, ClipboardMIMEType, @@ -50,8 +50,6 @@ import { Dimension, Direction, GridClickModifiers, - HeaderIndex, - Pixel, Rect, Ref, SpreadsheetChildEnv, diff --git a/src/components/grid_overlay/grid_overlay.ts b/src/components/grid_overlay/grid_overlay.ts index bdf673e739..db42345567 100644 --- a/src/components/grid_overlay/grid_overlay.ts +++ b/src/components/grid_overlay/grid_overlay.ts @@ -1,17 +1,9 @@ +import { HeaderIndex, Pixel, Position } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, onWillUnmount, useExternalListener, useRef } from "@odoo/owl"; import { deepEquals, positionToZone } from "../../helpers"; import { isPointInsideRect } from "../../helpers/rectangle"; import { Store, useStore } from "../../store_engine"; -import { - DOMCoordinates, - GridClickModifiers, - HeaderIndex, - Pixel, - Position, - Rect, - Ref, - SpreadsheetChildEnv, -} from "../../types"; +import { DOMCoordinates, GridClickModifiers, Rect, Ref, SpreadsheetChildEnv } from "../../types"; import { FiguresContainer } from "../figures/figure_container/figure_container"; import { DelayedHoveredCellStore } from "../grid/delayed_hovered_cell_store"; import { GridAddRowsFooter } from "../grid_add_rows_footer/grid_add_rows_footer"; @@ -27,8 +19,6 @@ import { useInterval } from "../helpers/time_hooks"; import { PaintFormatStore } from "../paint_format_button/paint_format_store"; import { CellPopoverStore } from "../popover"; import { HoveredTableStore } from "../tables/hovered_table_store"; -import { HoveredIconStore } from "./hovered_icon_store"; - function useCellHovered(env: SpreadsheetChildEnv, gridRef: Ref): Partial { const delayedHoveredCell = useStore(DelayedHoveredCellStore); const hoveredTable = useStore(HoveredTableStore); diff --git a/src/components/grid_overlay/hovered_icon_store.ts b/src/components/grid_overlay/hovered_icon_store.ts index 710b21adc5..f765603295 100644 --- a/src/components/grid_overlay/hovered_icon_store.ts +++ b/src/components/grid_overlay/hovered_icon_store.ts @@ -1,5 +1,6 @@ import { SpreadsheetStore } from "../../stores"; -import { CellPosition } from "../../types"; + +import { CellPosition } from "@odoo/o-spreadsheet-engine"; interface HoveredIcon { id: string; diff --git a/src/components/header_group/header_group.ts b/src/components/header_group/header_group.ts index a81e1806a3..920ed21f4a 100644 --- a/src/components/header_group/header_group.ts +++ b/src/components/header_group/header_group.ts @@ -1,3 +1,4 @@ +import { HeaderGroup } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { Action } from "../../actions/action"; import { @@ -8,7 +9,7 @@ import { } from "../../constants"; import { interactiveToggleGroup } from "../../helpers/ui/toggle_group_interactive"; import { getHeaderGroupContextMenu } from "../../registries/menus/header_group_registry"; -import { DOMCoordinates, Dimension, HeaderGroup, Rect } from "../../types"; +import { DOMCoordinates, Dimension, Rect } from "../../types"; import { SpreadsheetChildEnv } from "../../types/env"; import { cssPropertiesToCss } from "../helpers"; diff --git a/src/components/header_group/header_group_container.ts b/src/components/header_group/header_group_container.ts index a4ad343e3d..6866e996c6 100644 --- a/src/components/header_group/header_group_container.ts +++ b/src/components/header_group/header_group_container.ts @@ -1,14 +1,13 @@ +import { HeaderGroup, Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { Action } from "../../actions/action"; import { GROUP_LAYER_WIDTH } from "../../constants"; import { createHeaderGroupContainerContextMenu } from "../../registries/menus/header_group_registry"; import { DOMCoordinates, SpreadsheetChildEnv } from "../../types"; -import { CSSProperties, Dimension, HeaderGroup, Pixel } from "../../types/misc"; +import { CSSProperties, Dimension } from "../../types/misc"; import { cssPropertiesToCss } from "../helpers"; import { MenuPopover, MenuState } from "../menu_popover/menu_popover"; import { HEADER_HEIGHT, HEADER_WIDTH } from "./../../constants"; -import { ColGroup, RowGroup } from "./header_group"; - interface Props { dimension: Dimension; layers: HeaderGroup[][]; diff --git a/src/components/headers_overlay/headers_overlay.ts b/src/components/headers_overlay/headers_overlay.ts index ccd1b5fcfe..458c2ffffb 100644 --- a/src/components/headers_overlay/headers_overlay.ts +++ b/src/components/headers_overlay/headers_overlay.ts @@ -1,15 +1,8 @@ +import { HeaderDimensions, HeaderIndex, Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, useRef, useState } from "@odoo/owl"; import { MIN_COL_WIDTH, MIN_ROW_HEIGHT } from "../../constants"; import { Store, useStore } from "../../store_engine"; -import { - CommandResult, - EdgeScrollInfo, - HeaderDimensions, - HeaderIndex, - Pixel, - Ref, - SpreadsheetChildEnv, -} from "../../types/index"; +import { CommandResult, EdgeScrollInfo, Ref, SpreadsheetChildEnv } from "../../types/index"; import { ContextMenuType } from "../grid/grid"; import { cssPropertiesToCss } from "../helpers/css"; import { isCtrlKey } from "../helpers/dom_helpers"; diff --git a/src/components/headers_overlay/unhide_headers.ts b/src/components/headers_overlay/unhide_headers.ts index e4915493d1..49c92df5c1 100644 --- a/src/components/headers_overlay/unhide_headers.ts +++ b/src/components/headers_overlay/unhide_headers.ts @@ -1,9 +1,7 @@ +import { ConsecutiveIndexes, HeaderIndex } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { HEADER_HEIGHT, HEADER_WIDTH } from "../../constants"; import { positionToZone } from "../../helpers"; -import { ConsecutiveIndexes, HeaderIndex, SpreadsheetChildEnv } from "../../types"; -import { cssPropertiesToCss } from "../helpers"; - interface Props { headersGroups: ConsecutiveIndexes[]; offset: number; diff --git a/src/components/helpers/css.ts b/src/components/helpers/css.ts index 86a39a68ef..21d704ae01 100644 --- a/src/components/helpers/css.ts +++ b/src/components/helpers/css.ts @@ -7,7 +7,8 @@ * created for the first time. */ -import { CSSProperties, Style } from "../../types"; +import { Style } from "@odoo/o-spreadsheet-engine"; +import { CSSProperties } from "../../types"; export function getTextDecoration({ strikethrough, diff --git a/src/components/helpers/drag_and_drop_dom_items_hook.ts b/src/components/helpers/drag_and_drop_dom_items_hook.ts index 3d426453a4..af12618361 100644 --- a/src/components/helpers/drag_and_drop_dom_items_hook.ts +++ b/src/components/helpers/drag_and_drop_dom_items_hook.ts @@ -1,8 +1,6 @@ +import { Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { onWillUnmount, useState } from "@odoo/owl"; -import { CSSProperties, Pixel, UID } from "../../types"; -import { cssPropertiesToCss } from "./css"; -import { startDnd } from "./drag_and_drop"; - +import { CSSProperties } from "../../types"; type Direction = "horizontal" | "vertical"; interface DragAndDropItemsPartial { diff --git a/src/components/helpers/drag_and_drop_grid_hook.ts b/src/components/helpers/drag_and_drop_grid_hook.ts index 530ccda327..22b95fbaa8 100644 --- a/src/components/helpers/drag_and_drop_grid_hook.ts +++ b/src/components/helpers/drag_and_drop_grid_hook.ts @@ -1,10 +1,8 @@ +import { HeaderIndex, Pixel } from "@odoo/o-spreadsheet-engine"; import { onWillUnmount, useEffect } from "@odoo/owl"; import { MAX_DELAY } from "../../helpers"; import { SpreadsheetChildEnv } from "../../types/env"; -import { HeaderIndex, Pixel } from "../../types/misc"; import { gridOverlayPosition } from "./dom_helpers"; -import { startDnd } from "./drag_and_drop"; - export type DnDDirection = "all" | "vertical" | "horizontal"; /** diff --git a/src/components/helpers/figure_drag_helper.ts b/src/components/helpers/figure_drag_helper.ts index ed0e10aa80..ff62c72909 100644 --- a/src/components/helpers/figure_drag_helper.ts +++ b/src/components/helpers/figure_drag_helper.ts @@ -1,5 +1,6 @@ +import { PixelPosition } from "@odoo/o-spreadsheet-engine"; import { clip } from "../../helpers"; -import { FigureUI, PixelPosition, SheetDOMScrollInfo } from "../../types"; +import { FigureUI, SheetDOMScrollInfo } from "../../types"; export function dragFigureForMove( { x: mouseX, y: mouseY }: PixelPosition, diff --git a/src/components/helpers/figure_snap_helper.ts b/src/components/helpers/figure_snap_helper.ts index 82fdcdba4d..4727df1bcf 100644 --- a/src/components/helpers/figure_snap_helper.ts +++ b/src/components/helpers/figure_snap_helper.ts @@ -1,6 +1,4 @@ -import { FigureUI, Getters, Pixel, PixelPosition, UID } from "../../types"; -import { FIGURE_BORDER_WIDTH } from "./../../constants"; - +import { Pixel, PixelPosition, UID } from "@odoo/o-spreadsheet-engine"; const SNAP_MARGIN: Pixel = 5; export type HFigureAxisType = "top" | "bottom" | "vCenter"; diff --git a/src/components/highlight/border/border.ts b/src/components/highlight/border/border.ts index a5c92b6f4d..0a365244eb 100644 --- a/src/components/highlight/border/border.ts +++ b/src/components/highlight/border/border.ts @@ -1,5 +1,6 @@ +import { Zone } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; -import { SpreadsheetChildEnv, Zone } from "../../../types"; +import { SpreadsheetChildEnv } from "../../../types"; import { cssPropertiesToCss } from "../../helpers/css"; type Orientation = "n" | "s" | "w" | "e"; diff --git a/src/components/highlight/corner/corner.ts b/src/components/highlight/corner/corner.ts index 3ac4df8d6f..7bd41a5f4d 100644 --- a/src/components/highlight/corner/corner.ts +++ b/src/components/highlight/corner/corner.ts @@ -1,8 +1,7 @@ +import { Color, Zone } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { AUTOFILL_EDGE_LENGTH } from "../../../constants"; -import { Color, ResizeDirection, SpreadsheetChildEnv, Zone } from "../../../types"; -import { cssPropertiesToCss } from "../../helpers/css"; - +import { ResizeDirection, SpreadsheetChildEnv } from "../../../types"; const MOBILE_HANDLER_WIDTH = 40; type Orientation = "nw" | "ne" | "sw" | "se" | "n" | "s" | "e" | "w"; diff --git a/src/components/highlight/highlight/highlight.ts b/src/components/highlight/highlight/highlight.ts index 1adc15226b..451b70d586 100644 --- a/src/components/highlight/highlight/highlight.ts +++ b/src/components/highlight/highlight/highlight.ts @@ -1,21 +1,13 @@ +import { Color, HeaderIndex, Zone } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { clip, isEqual } from "../../../helpers"; -import { - Color, - HeaderIndex, - Range, - ResizeDirection, - SpreadsheetChildEnv, - Zone, -} from "../../../types"; +import { Range, ResizeDirection, SpreadsheetChildEnv } from "../../../types"; import { gridOverlayPosition } from "../../helpers/dom_helpers"; import { DnDDirection, useDragAndDropBeyondTheViewport, } from "../../helpers/drag_and_drop_grid_hook"; import { Border } from "../border/border"; -import { Corner } from "../corner/corner"; - export interface HighlightProps { range: Range; color: Color; diff --git a/src/components/icons/icons.ts b/src/components/icons/icons.ts index cff2ecd56d..41681dfad1 100644 --- a/src/components/icons/icons.ts +++ b/src/components/icons/icons.ts @@ -1,3 +1,4 @@ +import { Style } from "@odoo/o-spreadsheet-engine"; import { ACTION_COLOR, FILTERS_COLOR, @@ -7,7 +8,6 @@ import { TEXT_BODY_MUTED, } from "../../constants"; import { isDefined } from "../../helpers"; -import { Style } from "../../types"; import { ImageSVG } from "../../types/image"; export type IconSetType = keyof typeof ICON_SETS; diff --git a/src/components/link/link_display/link_display.ts b/src/components/link/link_display/link_display.ts index dbab483287..8d9b8119f3 100644 --- a/src/components/link/link_display/link_display.ts +++ b/src/components/link/link_display/link_display.ts @@ -1,9 +1,10 @@ +import { Position } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { LINK_COLOR } from "../../../constants"; import { toXC } from "../../../helpers"; import { openLink, urlRepresentation } from "../../../helpers/links"; import { Store, useStore } from "../../../store_engine"; -import { EvaluatedCell, Link, Position, SpreadsheetChildEnv } from "../../../types"; +import { EvaluatedCell, Link, SpreadsheetChildEnv } from "../../../types"; import { CellPopoverComponent, PopoverBuilders } from "../../../types/cell_popovers"; import { isMiddleClickOrCtrlClick } from "../../helpers/dom_helpers"; import { CellPopoverStore } from "../../popover/cell_popover_store"; diff --git a/src/components/link/link_editor/link_editor.ts b/src/components/link/link_editor/link_editor.ts index f9dcbeba5f..1a0470e8f7 100644 --- a/src/components/link/link_editor/link_editor.ts +++ b/src/components/link/link_editor/link_editor.ts @@ -1,9 +1,10 @@ +import { Position } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, useRef, useState } from "@odoo/owl"; import { markdownLink } from "../../../helpers"; import { detectLink, urlRepresentation } from "../../../helpers/links"; import { canonicalizeNumberContent } from "../../../helpers/locale"; import { linkMenuRegistry } from "../../../registries/menus/link_menu_registry"; -import { Link, Position, Rect, SpreadsheetChildEnv } from "../../../types"; +import { Link, Rect, SpreadsheetChildEnv } from "../../../types"; import { CellPopoverComponent, PopoverBuilders } from "../../../types/cell_popovers"; import { getRefBoundingRect } from "../../helpers/dom_helpers"; import { MenuPopover } from "../../menu_popover/menu_popover"; diff --git a/src/components/menu/menu.ts b/src/components/menu/menu.ts index 584d73912e..f7b8f32def 100644 --- a/src/components/menu/menu.ts +++ b/src/components/menu/menu.ts @@ -1,6 +1,7 @@ +import { Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUnmount } from "@odoo/owl"; import { Action } from "../../actions/action"; -import { Pixel, SpreadsheetChildEnv } from "../../types"; +import { SpreadsheetChildEnv } from "../../types"; import { cssPropertiesToCss } from "../helpers/css"; //------------------------------------------------------------------------------ diff --git a/src/components/menu_popover/menu_popover.ts b/src/components/menu_popover/menu_popover.ts index f2257c9f1e..b345b48437 100644 --- a/src/components/menu_popover/menu_popover.ts +++ b/src/components/menu_popover/menu_popover.ts @@ -1,3 +1,4 @@ +import { MenuMouseEvent, Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUnmount, @@ -8,7 +9,7 @@ import { } from "@odoo/owl"; import { Action } from "../../actions/action"; import { DESKTOP_MENU_ITEM_HEIGHT, MENU_VERTICAL_PADDING, MENU_WIDTH } from "../../constants"; -import { MenuMouseEvent, Pixel, Rect, SpreadsheetChildEnv, UID } from "../../types"; +import { Rect, SpreadsheetChildEnv } from "../../types"; import { PopoverPropsPosition } from "../../types/cell_popovers"; import { cssPropertiesToCss } from "../helpers/css"; import { diff --git a/src/components/paint_format_button/paint_format_store.ts b/src/components/paint_format_button/paint_format_store.ts index 664269cf05..53ad6fef9d 100644 --- a/src/components/paint_format_button/paint_format_store.ts +++ b/src/components/paint_format_button/paint_format_store.ts @@ -1,3 +1,4 @@ +import { ClipboardCell, Highlight, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { clipboardHandlersRegistries } from "../../clipboard_handlers"; import { ClipboardHandler } from "../../clipboard_handlers/abstract_clipboard_handler"; import { SELECTION_BORDER_COLOR } from "../../constants"; @@ -9,9 +10,6 @@ import { } from "../../helpers/clipboard/clipboard_helpers"; import { Get } from "../../store_engine"; import { SpreadsheetStore } from "../../stores"; -import { HighlightStore } from "../../stores/highlight_store"; -import { ClipboardCell, ClipboardOptions, Command, Highlight, UID, Zone } from "../../types"; - interface ClipboardContent { cells: ClipboardCell[][]; zones: Zone[]; diff --git a/src/components/pivot_html_renderer/pivot_html_renderer.ts b/src/components/pivot_html_renderer/pivot_html_renderer.ts index 35c1149bc4..0ee768bd4d 100644 --- a/src/components/pivot_html_renderer/pivot_html_renderer.ts +++ b/src/components/pivot_html_renderer/pivot_html_renderer.ts @@ -1,11 +1,6 @@ +import { FunctionResultObject, Maybe, UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; -import { - FunctionResultObject, - Maybe, - SpreadsheetChildEnv, - SpreadsheetPivotTable, - UID, -} from "../.."; +import { SpreadsheetChildEnv, SpreadsheetPivotTable } from "../.."; import { toString } from "../../functions/helpers"; import { formatValue } from "../../helpers"; import { generatePivotArgs } from "../../helpers/pivot/pivot_helpers"; diff --git a/src/components/popover/cell_popover_store.ts b/src/components/popover/cell_popover_store.ts index 7d8e2aa49f..667a65c0bb 100644 --- a/src/components/popover/cell_popover_store.ts +++ b/src/components/popover/cell_popover_store.ts @@ -1,7 +1,8 @@ +import { CellPosition, Position } from "@odoo/o-spreadsheet-engine"; import { positionToZone } from "../../helpers"; import { cellPopoverRegistry } from "../../registries/cell_popovers_registry"; import { SpreadsheetStore } from "../../stores"; -import { CellPosition, Command, Position, Rect } from "../../types"; +import { Command, Rect } from "../../types"; import { CellPopoverType, ClosedCellPopover, diff --git a/src/components/popover/popover.ts b/src/components/popover/popover.ts index d2afae76d8..722bd24245 100644 --- a/src/components/popover/popover.ts +++ b/src/components/popover/popover.ts @@ -1,6 +1,7 @@ +import { Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, onWillUnmount, useEffect, useRef } from "@odoo/owl"; import { rectIntersection } from "../../helpers/rectangle"; -import { DOMCoordinates, DOMDimension, Pixel, Rect, SpreadsheetChildEnv } from "../../types"; +import { DOMCoordinates, DOMDimension, Rect, SpreadsheetChildEnv } from "../../types"; import { PopoverPropsPosition } from "../../types/cell_popovers"; import { usePopoverContainer, useSpreadsheetRect } from "../helpers/position_hook"; import { CSSProperties } from "./../../types/misc"; diff --git a/src/components/scrollbar.ts b/src/components/scrollbar.ts index 15f7948dfe..e1b3232546 100644 --- a/src/components/scrollbar.ts +++ b/src/components/scrollbar.ts @@ -1,4 +1,4 @@ -import { Pixel } from "../types"; +import { Pixel } from "@odoo/o-spreadsheet-engine"; export type ScrollDirection = "horizontal" | "vertical"; diff --git a/src/components/scrollbar/scrollbar.ts b/src/components/scrollbar/scrollbar.ts index 07ff7f1875..7478835c58 100644 --- a/src/components/scrollbar/scrollbar.ts +++ b/src/components/scrollbar/scrollbar.ts @@ -1,5 +1,6 @@ +import { Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, useEffect, useRef, xml } from "@odoo/owl"; -import { CSSProperties, Pixel, Ref } from "../../types"; +import { CSSProperties, Ref } from "../../types"; import { cssPropertiesToCss } from "../helpers"; import { ScrollBar as ScrollBarElement, ScrollDirection } from "../scrollbar"; diff --git a/src/components/selection_input/selection_input.ts b/src/components/selection_input/selection_input.ts index 22045cc1f8..721fa7648c 100644 --- a/src/components/selection_input/selection_input.ts +++ b/src/components/selection_input/selection_input.ts @@ -1,7 +1,8 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useEffect, useRef, useState } from "@odoo/owl"; import { deepEquals, range } from "../../helpers"; import { Store, useLocalStore } from "../../store_engine"; -import { Color, SpreadsheetChildEnv } from "../../types"; +import { SpreadsheetChildEnv } from "../../types"; import { cssPropertiesToCss } from "../helpers/css"; import { useDragAndDropListItems } from "../helpers/drag_and_drop_dom_items_hook"; import { updateSelectionWithArrowKeys } from "../helpers/selection_helpers"; diff --git a/src/components/selection_input/selection_input_store.ts b/src/components/selection_input/selection_input_store.ts index 5975c93c19..0495d9db45 100644 --- a/src/components/selection_input/selection_input_store.ts +++ b/src/components/selection_input/selection_input_store.ts @@ -1,11 +1,9 @@ +import { Color, Highlight, UID } from "@odoo/o-spreadsheet-engine"; import { ColorGenerator, isEqual, positionToZone, splitReference } from "../../helpers/index"; import { Get } from "../../store_engine"; import { SpreadsheetStore } from "../../stores"; import { HighlightStore } from "../../stores/highlight_store"; import { SelectionEvent } from "../../types/event_stream"; -import { Color, Command, Highlight, UID } from "../../types/index"; -import { FocusStore } from "../focus_store"; - export interface RangeInputValue { id: number; xc: string; diff --git a/src/components/side_panel/carousel_panel/carousel_panel.ts b/src/components/side_panel/carousel_panel/carousel_panel.ts index 546c12965e..cf496a066c 100644 --- a/src/components/side_panel/carousel_panel/carousel_panel.ts +++ b/src/components/side_panel/carousel_panel/carousel_panel.ts @@ -1,10 +1,11 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef } from "@odoo/owl"; import { ActionSpec } from "../../../actions/action"; import { DEFAULT_CAROUSEL_TITLE_STYLE } from "../../../constants"; import { deepEquals } from "../../../helpers"; import { getCarouselItemPreview, getCarouselItemTitle } from "../../../helpers/carousel_helpers"; import { _t } from "../../../translation"; -import { CarouselItem, SpreadsheetChildEnv, TitleDesign, UID } from "../../../types"; +import { CarouselItem, SpreadsheetChildEnv, TitleDesign } from "../../../types"; import { getBoundingRectAsPOJO } from "../../helpers/dom_helpers"; import { useDragAndDropListItems } from "../../helpers/drag_and_drop_dom_items_hook"; import { TextInput } from "../../text_input/text_input"; diff --git a/src/components/side_panel/chart/building_blocks/axis_design/axis_design_editor.ts b/src/components/side_panel/chart/building_blocks/axis_design/axis_design_editor.ts index b327739766..7b9a55b4be 100644 --- a/src/components/side_panel/chart/building_blocks/axis_design/axis_design_editor.ts +++ b/src/components/side_panel/chart/building_blocks/axis_design/axis_design_editor.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { CHART_AXIS_TITLE_FONT_SIZE } from "../../../../../constants"; import { deepCopy } from "../../../../../helpers"; @@ -6,7 +7,6 @@ import { DispatchResult, SpreadsheetChildEnv, TitleDesign, - UID, } from "../../../../../types"; import { BadgeSelection } from "../../../components/badge_selection/badge_selection"; import { Section } from "../../../components/section/section"; diff --git a/src/components/side_panel/chart/building_blocks/data_series/data_series.ts b/src/components/side_panel/chart/building_blocks/data_series/data_series.ts index c4ee7c6b67..5ccf8047bf 100644 --- a/src/components/side_panel/chart/building_blocks/data_series/data_series.ts +++ b/src/components/side_panel/chart/building_blocks/data_series/data_series.ts @@ -1,8 +1,8 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { _t } from "../../../../../translation"; import { ChartDatasetOrientation, - Color, CustomizedDataSet, SpreadsheetChildEnv, } from "../../../../../types"; diff --git a/src/components/side_panel/chart/building_blocks/general_design/general_design_editor.ts b/src/components/side_panel/chart/building_blocks/general_design/general_design_editor.ts index b520757fa8..029cec1c63 100644 --- a/src/components/side_panel/chart/building_blocks/general_design/general_design_editor.ts +++ b/src/components/side_panel/chart/building_blocks/general_design/general_design_editor.ts @@ -1,12 +1,11 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { CHART_TITLE_FONT_SIZE } from "../../../../../constants"; import { ChartDefinition, - Color, DispatchResult, SpreadsheetChildEnv, TitleDesign, - UID, } from "../../../../../types"; import { SidePanelCollapsible } from "../../../components/collapsible/side_panel_collapsible"; import { RadioSelection } from "../../../components/radio_selection/radio_selection"; diff --git a/src/components/side_panel/chart/building_blocks/generic_side_panel/config_panel.ts b/src/components/side_panel/chart/building_blocks/generic_side_panel/config_panel.ts index d621dcad8b..42e7601ff2 100644 --- a/src/components/side_panel/chart/building_blocks/generic_side_panel/config_panel.ts +++ b/src/components/side_panel/chart/building_blocks/generic_side_panel/config_panel.ts @@ -1,3 +1,4 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { createValidRange, @@ -21,8 +22,6 @@ import { CustomizedDataSet, DispatchResult, SpreadsheetChildEnv, - UID, - Zone, } from "../../../../../types"; import { ChartTerms } from "../../../../translations_terms"; import { Checkbox } from "../../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/chart/building_blocks/humanize_numbers/humanize_numbers.ts b/src/components/side_panel/chart/building_blocks/humanize_numbers/humanize_numbers.ts index 0767e90096..9d1c422dbe 100644 --- a/src/components/side_panel/chart/building_blocks/humanize_numbers/humanize_numbers.ts +++ b/src/components/side_panel/chart/building_blocks/humanize_numbers/humanize_numbers.ts @@ -1,9 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { ChartWithDataSetDefinition, DispatchResult, SpreadsheetChildEnv, - UID, } from "../../../../../types"; import { Checkbox } from "../../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/chart/building_blocks/legend/legend.ts b/src/components/side_panel/chart/building_blocks/legend/legend.ts index c772137bfc..357b11850a 100644 --- a/src/components/side_panel/chart/building_blocks/legend/legend.ts +++ b/src/components/side_panel/chart/building_blocks/legend/legend.ts @@ -1,9 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { ChartWithDataSetDefinition, DispatchResult, SpreadsheetChildEnv, - UID, } from "../../../../../types"; import { Section } from "../../../components/section/section"; diff --git a/src/components/side_panel/chart/building_blocks/series_design/series_design_editor.ts b/src/components/side_panel/chart/building_blocks/series_design/series_design_editor.ts index c890c4dc75..03d7b32339 100644 --- a/src/components/side_panel/chart/building_blocks/series_design/series_design_editor.ts +++ b/src/components/side_panel/chart/building_blocks/series_design/series_design_editor.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { getColorsPalette, getNthColor, toHex } from "../../../../../helpers"; import { isTrendLineAxis } from "../../../../../helpers/figures/charts"; @@ -5,7 +6,6 @@ import { ChartWithDataSetDefinition, DispatchResult, SpreadsheetChildEnv, - UID, } from "../../../../../types"; import { SidePanelCollapsible } from "../../../components/collapsible/side_panel_collapsible"; import { RoundColorPicker } from "../../../components/round_color_picker/round_color_picker"; diff --git a/src/components/side_panel/chart/building_blocks/series_design/series_with_axis_design_editor.ts b/src/components/side_panel/chart/building_blocks/series_design/series_with_axis_design_editor.ts index 9c9ea25f8b..1ef0fba34c 100644 --- a/src/components/side_panel/chart/building_blocks/series_design/series_with_axis_design_editor.ts +++ b/src/components/side_panel/chart/building_blocks/series_design/series_with_axis_design_editor.ts @@ -1,3 +1,4 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { DEFAULT_WINDOW_SIZE } from "../../../../../constants"; import { getColorsPalette, getNthColor, range, setColorAlpha, toHex } from "../../../../../helpers"; @@ -5,11 +6,9 @@ import { CHART_AXIS_CHOICES } from "../../../../../helpers/figures/charts"; import { ChartJSRuntime, ChartWithDataSetDefinition, - Color, DispatchResult, SpreadsheetChildEnv, TrendConfiguration, - UID, } from "../../../../../types"; import { Checkbox } from "../../../components/checkbox/checkbox"; import { RadioSelection } from "../../../components/radio_selection/radio_selection"; diff --git a/src/components/side_panel/chart/building_blocks/show_data_markers/show_data_markers.ts b/src/components/side_panel/chart/building_blocks/show_data_markers/show_data_markers.ts index fd62c840a2..490aa5524b 100644 --- a/src/components/side_panel/chart/building_blocks/show_data_markers/show_data_markers.ts +++ b/src/components/side_panel/chart/building_blocks/show_data_markers/show_data_markers.ts @@ -1,9 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { ChartWithDataSetDefinition, DispatchResult, SpreadsheetChildEnv, - UID, } from "../../../../../types"; import { Checkbox } from "../../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/chart/building_blocks/show_values/show_values.ts b/src/components/side_panel/chart/building_blocks/show_values/show_values.ts index 8a438925db..f7f8b15101 100644 --- a/src/components/side_panel/chart/building_blocks/show_values/show_values.ts +++ b/src/components/side_panel/chart/building_blocks/show_values/show_values.ts @@ -1,9 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { ChartWithDataSetDefinition, DispatchResult, SpreadsheetChildEnv, - UID, } from "../../../../../types"; import { Checkbox } from "../../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/chart/building_blocks/text_styler/text_styler.ts b/src/components/side_panel/chart/building_blocks/text_styler/text_styler.ts index 50aa930432..c13375115b 100644 --- a/src/components/side_panel/chart/building_blocks/text_styler/text_styler.ts +++ b/src/components/side_panel/chart/building_blocks/text_styler/text_styler.ts @@ -1,12 +1,11 @@ +import { Align, Color, VerticalAlign } from "@odoo/o-spreadsheet-engine"; import { Component, useExternalListener, useState } from "@odoo/owl"; import { ActionSpec } from "../../../../../actions/action"; import { DEFAULT_STYLE } from "../../../../../constants"; import { _t } from "../../../../../translation"; -import { Align, ChartStyle, Color, SpreadsheetChildEnv, VerticalAlign } from "../../../../../types"; +import { ChartStyle, SpreadsheetChildEnv } from "../../../../../types"; import { ActionButton } from "../../../../action_button/action_button"; import { ColorPickerWidget } from "../../../../color_picker/color_picker_widget"; -import { FontSizeEditor } from "../../../../font_size_editor/font_size_editor"; - interface Props { class?: string; style: ChartStyle; diff --git a/src/components/side_panel/chart/chart_type_picker/chart_type_picker.ts b/src/components/side_panel/chart/chart_type_picker/chart_type_picker.ts index 113f6de559..1fee5266a3 100644 --- a/src/components/side_panel/chart/chart_type_picker/chart_type_picker.ts +++ b/src/components/side_panel/chart/chart_type_picker/chart_type_picker.ts @@ -1,10 +1,11 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useExternalListener, useRef, useState } from "@odoo/owl"; import { ChartSubtypeProperties, chartCategories, chartSubtypeRegistry, } from "../../../../registries/chart_types"; -import { ChartDefinition, ChartType, SpreadsheetChildEnv, UID } from "../../../../types/index"; +import { ChartDefinition, ChartType, SpreadsheetChildEnv } from "../../../../types/index"; import { cssPropertiesToCss } from "../../../helpers/css"; import { isChildEvent } from "../../../helpers/dom_helpers"; import { Popover, PopoverProps } from "../../../popover"; diff --git a/src/components/side_panel/chart/chart_with_axis/design_panel.ts b/src/components/side_panel/chart/chart_with_axis/design_panel.ts index e8377f1c2a..dd7d447d43 100644 --- a/src/components/side_panel/chart/chart_with_axis/design_panel.ts +++ b/src/components/side_panel/chart/chart_with_axis/design_panel.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { getDefinedAxis } from "../../../../helpers/figures/charts"; import { _t } from "../../../../translation"; @@ -6,7 +7,6 @@ import { DispatchResult, GenericDefinition, SpreadsheetChildEnv, - UID, } from "../../../../types/index"; import { SidePanelCollapsible } from "../../components/collapsible/side_panel_collapsible"; import { Section } from "../../components/section/section"; diff --git a/src/components/side_panel/chart/combo_chart/combo_chart_design_panel.ts b/src/components/side_panel/chart/combo_chart/combo_chart_design_panel.ts index 914014e352..15eadab117 100644 --- a/src/components/side_panel/chart/combo_chart/combo_chart_design_panel.ts +++ b/src/components/side_panel/chart/combo_chart/combo_chart_design_panel.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { _t } from "../../../../translation"; import { ComboChartDefinition } from "../../../../types/chart/combo_chart"; -import { DispatchResult, GenericDefinition, UID } from "../../../../types/index"; +import { DispatchResult, GenericDefinition } from "../../../../types/index"; import { RadioSelection } from "../../components/radio_selection/radio_selection"; import { ChartShowDataMarkers } from "../building_blocks/show_data_markers/show_data_markers"; import { GenericZoomableChartDesignPanel } from "../zoomable_chart/design_panel"; diff --git a/src/components/side_panel/chart/funnel_chart_panel/funnel_chart_design_panel.ts b/src/components/side_panel/chart/funnel_chart_panel/funnel_chart_design_panel.ts index 3892f71c75..4f755012ff 100644 --- a/src/components/side_panel/chart/funnel_chart_panel/funnel_chart_design_panel.ts +++ b/src/components/side_panel/chart/funnel_chart_panel/funnel_chart_design_panel.ts @@ -1,9 +1,10 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { replaceItemAtIndex } from "../../../../helpers"; import { getFunnelLabelColors } from "../../../../helpers/figures/charts/runtime"; import { _t } from "../../../../translation"; import { FunnelChartDefinition, FunnelChartRuntime } from "../../../../types/chart"; -import { DispatchResult, SpreadsheetChildEnv, UID } from "../../../../types/index"; +import { DispatchResult, SpreadsheetChildEnv } from "../../../../types/index"; import { SidePanelCollapsible } from "../../components/collapsible/side_panel_collapsible"; import { RoundColorPicker } from "../../components/round_color_picker/round_color_picker"; import { Section } from "../../components/section/section"; diff --git a/src/components/side_panel/chart/gauge_chart_panel/gauge_chart_config_panel.ts b/src/components/side_panel/chart/gauge_chart_panel/gauge_chart_config_panel.ts index 28e2aa77ae..e9c123f2e4 100644 --- a/src/components/side_panel/chart/gauge_chart_panel/gauge_chart_config_panel.ts +++ b/src/components/side_panel/chart/gauge_chart_panel/gauge_chart_config_panel.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { GaugeChartDefinition } from "../../../../types/chart/gauge_chart"; import { @@ -5,7 +6,6 @@ import { CustomizedDataSet, DispatchResult, SpreadsheetChildEnv, - UID, } from "../../../../types/index"; import { ChartTerms } from "../../../translations_terms"; import { ChartDataSeries } from "../building_blocks/data_series/data_series"; diff --git a/src/components/side_panel/chart/gauge_chart_panel/gauge_chart_design_panel.ts b/src/components/side_panel/chart/gauge_chart_panel/gauge_chart_design_panel.ts index e6f43ba60c..489e9a50a8 100644 --- a/src/components/side_panel/chart/gauge_chart_panel/gauge_chart_design_panel.ts +++ b/src/components/side_panel/chart/gauge_chart_panel/gauge_chart_design_panel.ts @@ -1,16 +1,11 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { isMultipleElementMatrix, toScalar } from "../../../../functions/helper_matrices"; import { tryToNumber } from "../../../../functions/helpers"; import { deepCopy } from "../../../../helpers/index"; import { _t } from "../../../../translation"; import { GaugeChartDefinition, SectionRule } from "../../../../types/chart/gauge_chart"; -import { - Color, - CommandResult, - DispatchResult, - SpreadsheetChildEnv, - UID, -} from "../../../../types/index"; +import { CommandResult, DispatchResult, SpreadsheetChildEnv } from "../../../../types/index"; import { StandaloneComposer } from "../../../composer/standalone_composer/standalone_composer"; import { ChartTerms } from "../../../translations_terms"; import { SidePanelCollapsible } from "../../components/collapsible/side_panel_collapsible"; diff --git a/src/components/side_panel/chart/geo_chart_panel/geo_chart_design_panel.ts b/src/components/side_panel/chart/geo_chart_panel/geo_chart_design_panel.ts index 8679c226b3..e76e9b4e40 100644 --- a/src/components/side_panel/chart/geo_chart_panel/geo_chart_design_panel.ts +++ b/src/components/side_panel/chart/geo_chart_panel/geo_chart_design_panel.ts @@ -1,14 +1,13 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { LegendPosition } from "../../../../types/chart"; import { GeoChartColorScale, GeoChartCustomColorScale, GeoChartDefinition, } from "../../../../types/chart/geo_chart"; -import { Color, DispatchResult, UID } from "../../../../types/index"; +import { DispatchResult } from "../../../../types/index"; import { ChartTerms } from "../../../translations_terms"; import { RoundColorPicker } from "../../components/round_color_picker/round_color_picker"; -import { ChartWithAxisDesignPanel } from "../chart_with_axis/design_panel"; - interface Props { chartId: UID; definition: GeoChartDefinition; diff --git a/src/components/side_panel/chart/geo_chart_panel/geo_chart_region_select_section.ts b/src/components/side_panel/chart/geo_chart_panel/geo_chart_region_select_section.ts index 8a92cae9b1..d9327e089b 100644 --- a/src/components/side_panel/chart/geo_chart_panel/geo_chart_region_select_section.ts +++ b/src/components/side_panel/chart/geo_chart_panel/geo_chart_region_select_section.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { GeoChartDefinition } from "../../../../types/chart/geo_chart"; -import { DispatchResult, SpreadsheetChildEnv, UID } from "../../../../types/index"; +import { DispatchResult, SpreadsheetChildEnv } from "../../../../types/index"; import { Section } from "../../components/section/section"; interface Props { diff --git a/src/components/side_panel/chart/line_chart/line_chart_design_panel.ts b/src/components/side_panel/chart/line_chart/line_chart_design_panel.ts index 2cdc1a305f..4d059bbde0 100644 --- a/src/components/side_panel/chart/line_chart/line_chart_design_panel.ts +++ b/src/components/side_panel/chart/line_chart/line_chart_design_panel.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { LineChartDefinition } from "../../../../types/chart"; -import { DispatchResult, UID } from "../../../../types/index"; +import { DispatchResult } from "../../../../types/index"; import { ChartShowDataMarkers } from "../building_blocks/show_data_markers/show_data_markers"; import { GenericZoomableChartDesignPanel } from "../zoomable_chart/design_panel"; diff --git a/src/components/side_panel/chart/main_chart_panel/main_chart_panel.ts b/src/components/side_panel/chart/main_chart_panel/main_chart_panel.ts index 7169ac46c9..bc164da655 100644 --- a/src/components/side_panel/chart/main_chart_panel/main_chart_panel.ts +++ b/src/components/side_panel/chart/main_chart_panel/main_chart_panel.ts @@ -1,18 +1,10 @@ +import { Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { Component, useEffect, useRef } from "@odoo/owl"; import { ChartSidePanel, chartSidePanelComponentRegistry } from ".."; import { Store, useLocalStore } from "../../../../store_engine"; -import { - ChartDefinition, - ChartType, - Pixel, - Ref, - SpreadsheetChildEnv, - UID, -} from "../../../../types/index"; +import { ChartDefinition, ChartType, Ref, SpreadsheetChildEnv } from "../../../../types/index"; import { Section } from "../../components/section/section"; import { ChartTypePicker } from "../chart_type_picker/chart_type_picker"; -import { MainChartPanelStore } from "./main_chart_panel_store"; - interface Props { onCloseSidePanel: () => void; chartId: UID; diff --git a/src/components/side_panel/chart/main_chart_panel/main_chart_panel_store.ts b/src/components/side_panel/chart/main_chart_panel/main_chart_panel_store.ts index a2ed5b79b2..c492e366a7 100644 --- a/src/components/side_panel/chart/main_chart_panel/main_chart_panel_store.ts +++ b/src/components/side_panel/chart/main_chart_panel/main_chart_panel_store.ts @@ -1,7 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { deepEquals } from "../../../../helpers"; import { chartRegistry, chartSubtypeRegistry } from "../../../../registries/chart_types"; import { SpreadsheetStore } from "../../../../stores"; -import { ChartCreationContext, ChartDefinition, UID } from "../../../../types"; +import { ChartCreationContext, ChartDefinition } from "../../../../types"; export class MainChartPanelStore extends SpreadsheetStore { mutators = ["activatePanel", "changeChartType"] as const; diff --git a/src/components/side_panel/chart/pie_chart/pie_chart_design_panel.ts b/src/components/side_panel/chart/pie_chart/pie_chart_design_panel.ts index 51300e921a..ec999850c5 100644 --- a/src/components/side_panel/chart/pie_chart/pie_chart_design_panel.ts +++ b/src/components/side_panel/chart/pie_chart/pie_chart_design_panel.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; -import { DispatchResult, SpreadsheetChildEnv, UID } from "../../../../types"; +import { DispatchResult, SpreadsheetChildEnv } from "../../../../types"; import { GenericDefinition, PieChartDefinition } from "../../../../types/chart"; import { DEFAULT_DOUGHNUT_CHART_HOLE_SIZE } from "../../../../xlsx/constants"; import { Checkbox } from "../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/chart/radar_chart/radar_chart_design_panel.ts b/src/components/side_panel/chart/radar_chart/radar_chart_design_panel.ts index 5fd4617341..91aa4987d4 100644 --- a/src/components/side_panel/chart/radar_chart/radar_chart_design_panel.ts +++ b/src/components/side_panel/chart/radar_chart/radar_chart_design_panel.ts @@ -1,11 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { RadarChartDefinition } from "../../../../types/chart/radar_chart"; -import { - DispatchResult, - GenericDefinition, - SpreadsheetChildEnv, - UID, -} from "../../../../types/index"; +import { DispatchResult, GenericDefinition, SpreadsheetChildEnv } from "../../../../types/index"; import { Checkbox } from "../../components/checkbox/checkbox"; import { Section } from "../../components/section/section"; import { GeneralDesignEditor } from "../building_blocks/general_design/general_design_editor"; diff --git a/src/components/side_panel/chart/scorecard_chart_panel/scorecard_chart_config_panel.ts b/src/components/side_panel/chart/scorecard_chart_panel/scorecard_chart_config_panel.ts index b1e162d692..1862025644 100644 --- a/src/components/side_panel/chart/scorecard_chart_panel/scorecard_chart_config_panel.ts +++ b/src/components/side_panel/chart/scorecard_chart_panel/scorecard_chart_config_panel.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { ScorecardChartDefinition } from "../../../../types/chart/scorecard_chart"; -import { CommandResult, DispatchResult, SpreadsheetChildEnv, UID } from "../../../../types/index"; +import { CommandResult, DispatchResult, SpreadsheetChildEnv } from "../../../../types/index"; import { SelectionInput } from "../../../selection_input/selection_input"; import { ChartTerms } from "../../../translations_terms"; import { Section } from "../../components/section/section"; diff --git a/src/components/side_panel/chart/scorecard_chart_panel/scorecard_chart_design_panel.ts b/src/components/side_panel/chart/scorecard_chart_panel/scorecard_chart_design_panel.ts index 0c0b4c6abf..21d6c0af97 100644 --- a/src/components/side_panel/chart/scorecard_chart_panel/scorecard_chart_design_panel.ts +++ b/src/components/side_panel/chart/scorecard_chart_panel/scorecard_chart_design_panel.ts @@ -1,3 +1,4 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { DEFAULT_SCORECARD_BASELINE_FONT_SIZE, @@ -6,13 +7,7 @@ import { } from "../../../../constants"; import { _t } from "../../../../translation"; import { ScorecardChartDefinition } from "../../../../types/chart/scorecard_chart"; -import { - Color, - DispatchResult, - SpreadsheetChildEnv, - TitleDesign, - UID, -} from "../../../../types/index"; +import { DispatchResult, SpreadsheetChildEnv, TitleDesign } from "../../../../types/index"; import { Checkbox } from "../../components/checkbox/checkbox"; import { SidePanelCollapsible } from "../../components/collapsible/side_panel_collapsible"; import { RoundColorPicker } from "../../components/round_color_picker/round_color_picker"; diff --git a/src/components/side_panel/chart/sunburst_chart/sunburst_chart_design_panel.ts b/src/components/side_panel/chart/sunburst_chart/sunburst_chart_design_panel.ts index 0bd2df0f03..0b168d9704 100644 --- a/src/components/side_panel/chart/sunburst_chart/sunburst_chart_design_panel.ts +++ b/src/components/side_panel/chart/sunburst_chart/sunburst_chart_design_panel.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { deepCopy } from "../../../../helpers"; import { @@ -6,7 +7,7 @@ import { SunburstChartJSDataset, SunburstChartRuntime, } from "../../../../types/chart"; -import { DispatchResult, SpreadsheetChildEnv, UID } from "../../../../types/index"; +import { DispatchResult, SpreadsheetChildEnv } from "../../../../types/index"; import { Checkbox } from "../../components/checkbox/checkbox"; import { SidePanelCollapsible } from "../../components/collapsible/side_panel_collapsible"; import { RoundColorPicker } from "../../components/round_color_picker/round_color_picker"; diff --git a/src/components/side_panel/chart/treemap_chart/treemap_category_color/treemap_category_color.ts b/src/components/side_panel/chart/treemap_chart/treemap_category_color/treemap_category_color.ts index fc67f2fc95..4aa63c0a8f 100644 --- a/src/components/side_panel/chart/treemap_chart/treemap_category_color/treemap_category_color.ts +++ b/src/components/side_panel/chart/treemap_chart/treemap_category_color/treemap_category_color.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { ChartConfiguration } from "chart.js"; -import { DispatchResult, UID } from "../../../../.."; +import { DispatchResult } from "../../../../.."; import { deepCopy } from "../../../../../helpers"; import { SpreadsheetChildEnv } from "../../../../../types"; import { diff --git a/src/components/side_panel/chart/treemap_chart/treemap_chart_design_panel.ts b/src/components/side_panel/chart/treemap_chart/treemap_chart_design_panel.ts index 502669accb..58ee95fc1c 100644 --- a/src/components/side_panel/chart/treemap_chart/treemap_chart_design_panel.ts +++ b/src/components/side_panel/chart/treemap_chart/treemap_chart_design_panel.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { _t } from "../../../../translation"; import { @@ -6,7 +7,7 @@ import { TreeMapChartDefinition, TreeMapColorScaleOptions, } from "../../../../types/chart/tree_map_chart"; -import { DispatchResult, SpreadsheetChildEnv, UID } from "../../../../types/index"; +import { DispatchResult, SpreadsheetChildEnv } from "../../../../types/index"; import { BadgeSelection } from "../../components/badge_selection/badge_selection"; import { Checkbox } from "../../components/checkbox/checkbox"; import { SidePanelCollapsible } from "../../components/collapsible/side_panel_collapsible"; diff --git a/src/components/side_panel/chart/treemap_chart/treemap_color_scale/treemap_color_scale.ts b/src/components/side_panel/chart/treemap_chart/treemap_color_scale/treemap_color_scale.ts index fd7df7b588..e984049b3b 100644 --- a/src/components/side_panel/chart/treemap_chart/treemap_color_scale/treemap_color_scale.ts +++ b/src/components/side_panel/chart/treemap_chart/treemap_color_scale/treemap_color_scale.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; -import { DispatchResult, UID } from "../../../../.."; +import { DispatchResult } from "../../../../.."; import { SpreadsheetChildEnv } from "../../../../../types"; import { TreeMapChartDefaults, diff --git a/src/components/side_panel/chart/waterfall_chart/waterfall_chart_design_panel.ts b/src/components/side_panel/chart/waterfall_chart/waterfall_chart_design_panel.ts index 0ff0dfb4fe..77a38ec963 100644 --- a/src/components/side_panel/chart/waterfall_chart/waterfall_chart_design_panel.ts +++ b/src/components/side_panel/chart/waterfall_chart/waterfall_chart_design_panel.ts @@ -1,3 +1,4 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { CHART_WATERFALL_NEGATIVE_COLOR, @@ -6,13 +7,7 @@ import { } from "../../../../constants"; import { CHART_AXIS_CHOICES } from "../../../../helpers/figures/charts"; import { _t } from "../../../../translation"; -import { - Color, - DispatchResult, - GenericDefinition, - SpreadsheetChildEnv, - UID, -} from "../../../../types"; +import { DispatchResult, GenericDefinition, SpreadsheetChildEnv } from "../../../../types"; import { WaterfallChartDefinition } from "../../../../types/chart/waterfall_chart"; import { SidePanelCollapsible } from "../../components/collapsible/side_panel_collapsible"; import { RadioSelection } from "../../components/radio_selection/radio_selection"; diff --git a/src/components/side_panel/chart/zoomable_chart/design_panel.ts b/src/components/side_panel/chart/zoomable_chart/design_panel.ts index 0e9e8389ff..e544a856fc 100644 --- a/src/components/side_panel/chart/zoomable_chart/design_panel.ts +++ b/src/components/side_panel/chart/zoomable_chart/design_panel.ts @@ -1,7 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { DispatchResult, GenericDefinition, - UID, ZoomableChartDefinition, } from "../../../../types/index"; import { Checkbox } from "../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/components/cog_wheel_menu/cog_wheel_menu.ts b/src/components/side_panel/components/cog_wheel_menu/cog_wheel_menu.ts index 467eb9d34d..db5c0a3f0e 100644 --- a/src/components/side_panel/components/cog_wheel_menu/cog_wheel_menu.ts +++ b/src/components/side_panel/components/cog_wheel_menu/cog_wheel_menu.ts @@ -1,6 +1,6 @@ +import { MenuMouseEvent } from "@odoo/o-spreadsheet-engine"; import { Component, useRef, useState } from "@odoo/owl"; import { ActionSpec, createActions } from "../../../../actions/action"; -import { MenuMouseEvent } from "../../../../types"; import { SpreadsheetChildEnv } from "../../../../types/env"; import { getBoundingRectAsPOJO } from "../../../helpers/dom_helpers"; import { MenuPopover, MenuState } from "../../../menu_popover/menu_popover"; diff --git a/src/components/side_panel/conditional_formatting/cf_editor/cf_editor.ts b/src/components/side_panel/conditional_formatting/cf_editor/cf_editor.ts index 34ba3ca501..8732c52a83 100644 --- a/src/components/side_panel/conditional_formatting/cf_editor/cf_editor.ts +++ b/src/components/side_panel/conditional_formatting/cf_editor/cf_editor.ts @@ -1,3 +1,4 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { Component, ComponentConstructor, useExternalListener, useState } from "@odoo/owl"; import { Action } from "../../../../actions/action"; import { DEFAULT_COLOR_SCALE_MIDPOINT_COLOR } from "../../../../constants"; @@ -13,7 +14,6 @@ import { _t } from "../../../../translation"; import { CancelledReason, CellIsRule, - Color, ColorScaleRule, ColorScaleThreshold, CommandResult, diff --git a/src/components/side_panel/conditional_formatting/cf_preview/cf_preview.ts b/src/components/side_panel/conditional_formatting/cf_preview/cf_preview.ts index 402375ed1e..573fccb075 100644 --- a/src/components/side_panel/conditional_formatting/cf_preview/cf_preview.ts +++ b/src/components/side_panel/conditional_formatting/cf_preview/cf_preview.ts @@ -1,8 +1,9 @@ +import { Highlight } from "@odoo/o-spreadsheet-engine"; import { Component, useRef } from "@odoo/owl"; import { HIGHLIGHT_COLOR } from "../../../../constants"; import { colorNumberToHex } from "../../../../helpers"; import { criterionEvaluatorRegistry } from "../../../../registries/criterion_registry"; -import { ConditionalFormat, Highlight, SpreadsheetChildEnv } from "../../../../types"; +import { ConditionalFormat, SpreadsheetChildEnv } from "../../../../types"; import { cellStyleToCss, cssPropertiesToCss } from "../../../helpers"; import { useHighlightsOnHover } from "../../../helpers/highlight_hook"; import { ICONS } from "../../../icons/icons"; diff --git a/src/components/side_panel/conditional_formatting/cf_preview_list/cf_preview_list.ts b/src/components/side_panel/conditional_formatting/cf_preview_list/cf_preview_list.ts index 2092a11524..ad6f891a8b 100644 --- a/src/components/side_panel/conditional_formatting/cf_preview_list/cf_preview_list.ts +++ b/src/components/side_panel/conditional_formatting/cf_preview_list/cf_preview_list.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef } from "@odoo/owl"; import { deepEquals } from "../../../../helpers"; -import { ConditionalFormat, SpreadsheetChildEnv, UID } from "../../../../types"; +import { ConditionalFormat, SpreadsheetChildEnv } from "../../../../types"; import { getBoundingRectAsPOJO } from "../../../helpers/dom_helpers"; import { useDragAndDropListItems } from "../../../helpers/drag_and_drop_dom_items_hook"; import { ICONS } from "../../../icons/icons"; diff --git a/src/components/side_panel/conditional_formatting/conditional_formatting.ts b/src/components/side_panel/conditional_formatting/conditional_formatting.ts index 144e954e07..5fd36b40ce 100644 --- a/src/components/side_panel/conditional_formatting/conditional_formatting.ts +++ b/src/components/side_panel/conditional_formatting/conditional_formatting.ts @@ -1,10 +1,9 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useState } from "@odoo/owl"; import { localizeCFRule } from "../../../helpers/locale"; -import { ConditionalFormat, SpreadsheetChildEnv, UID, Zone } from "../../../types"; +import { ConditionalFormat, SpreadsheetChildEnv } from "../../../types"; import { Section } from "../components/section/section"; import { ConditionalFormattingEditor } from "./cf_editor/cf_editor"; -import { ConditionalFormatPreviewList } from "./cf_preview_list/cf_preview_list"; - interface Props { selection?: Zone[]; onCloseSidePanel: () => void; diff --git a/src/components/side_panel/criterion_form/value_in_list_criterion/value_in_list_criterion.ts b/src/components/side_panel/criterion_form/value_in_list_criterion/value_in_list_criterion.ts index 0fe891f20e..8999c33874 100644 --- a/src/components/side_panel/criterion_form/value_in_list_criterion/value_in_list_criterion.ts +++ b/src/components/side_panel/criterion_form/value_in_list_criterion/value_in_list_criterion.ts @@ -1,5 +1,6 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { onWillStart, onWillUpdateProps, useState } from "@odoo/owl"; -import { Color, IsValueInListCriterion } from "../../../../types"; +import { IsValueInListCriterion } from "../../../../types"; import { RoundColorPicker } from "../../components/round_color_picker/round_color_picker"; import { CriterionForm } from "../criterion_form"; import { CriterionInput } from "../criterion_input/criterion_input"; diff --git a/src/components/side_panel/criterion_form/value_in_range_criterion/value_in_range_criterion.ts b/src/components/side_panel/criterion_form/value_in_range_criterion/value_in_range_criterion.ts index bbf8350dae..f9dedf5e38 100644 --- a/src/components/side_panel/criterion_form/value_in_range_criterion/value_in_range_criterion.ts +++ b/src/components/side_panel/criterion_form/value_in_range_criterion/value_in_range_criterion.ts @@ -1,5 +1,6 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { onWillStart, onWillUpdateProps } from "@odoo/owl"; -import { Color, IsValueInRangeCriterion } from "../../../../types"; +import { IsValueInRangeCriterion } from "../../../../types"; import { SelectionInput } from "../../../selection_input/selection_input"; import { RoundColorPicker } from "../../components/round_color_picker/round_color_picker"; import { CriterionForm } from "../criterion_form"; diff --git a/src/components/side_panel/data_validation/data_validation_panel.ts b/src/components/side_panel/data_validation/data_validation_panel.ts index fdaf487535..522d611de6 100644 --- a/src/components/side_panel/data_validation/data_validation_panel.ts +++ b/src/components/side_panel/data_validation/data_validation_panel.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; import { localizeDataValidationRule } from "../../../helpers/locale"; -import { DataValidationRule, SpreadsheetChildEnv, UID } from "../../../types"; +import { DataValidationRule, SpreadsheetChildEnv } from "../../../types"; import { DataValidationEditor } from "./dv_editor/dv_editor"; import { DataValidationPreview } from "./dv_preview/dv_preview"; diff --git a/src/components/side_panel/data_validation/dv_preview/dv_preview.ts b/src/components/side_panel/data_validation/dv_preview/dv_preview.ts index ffb998dd1d..a663b098d1 100644 --- a/src/components/side_panel/data_validation/dv_preview/dv_preview.ts +++ b/src/components/side_panel/data_validation/dv_preview/dv_preview.ts @@ -1,7 +1,8 @@ +import { Highlight } from "@odoo/o-spreadsheet-engine"; import { Component, useRef } from "@odoo/owl"; import { HIGHLIGHT_COLOR } from "../../../../constants"; import { criterionEvaluatorRegistry } from "../../../../registries/criterion_registry"; -import { DataValidationRule, Highlight, SpreadsheetChildEnv } from "../../../../types"; +import { DataValidationRule, SpreadsheetChildEnv } from "../../../../types"; import { useHighlightsOnHover } from "../../../helpers/highlight_hook"; interface Props { diff --git a/src/components/side_panel/find_and_replace/find_and_replace_store.ts b/src/components/side_panel/find_and_replace/find_and_replace_store.ts index b6f3b9e127..1313fd7560 100644 --- a/src/components/side_panel/find_and_replace/find_and_replace_store.ts +++ b/src/components/side_panel/find_and_replace/find_and_replace_store.ts @@ -1,14 +1,13 @@ import { getSearchRegex, isInside, positionToZone } from "../../../helpers"; import { HighlightProvider, HighlightStore } from "../../../stores/highlight_store"; -import { CellPosition, Color, Command, Highlight } from "../../../types"; +import { Command } from "../../../types"; +import { CellPosition, Color, Highlight } from "@odoo/o-spreadsheet-engine"; import { canonicalizeNumberContent } from "../../../helpers/locale"; import { Get } from "../../../store_engine"; import { SpreadsheetStore } from "../../../stores"; import { NotificationStore } from "../../../stores/notification_store"; import { _t } from "../../../translation"; -import { SearchOptions } from "../../../types/find_and_replace"; - const FIND_AND_REPLACE_HIGHLIGHT_COLOR: Color = "#8B008B"; enum Direction { diff --git a/src/components/side_panel/pivot/pivot_custom_groups_collapsible/pivot_custom_groups_collapsible.ts b/src/components/side_panel/pivot/pivot_custom_groups_collapsible/pivot_custom_groups_collapsible.ts index 43dbe0cf28..b89df95aaf 100644 --- a/src/components/side_panel/pivot/pivot_custom_groups_collapsible/pivot_custom_groups_collapsible.ts +++ b/src/components/side_panel/pivot/pivot_custom_groups_collapsible/pivot_custom_groups_collapsible.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { deepCopy } from "../../../../helpers"; import { getUniquePivotGroupName } from "../../../../helpers/pivot/pivot_helpers"; @@ -7,7 +8,6 @@ import { PivotCustomGroup, PivotCustomGroupedField, SpreadsheetChildEnv, - UID, } from "../../../../types"; import { TextInput } from "../../../text_input/text_input"; import { Checkbox } from "../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/pivot/pivot_layout_configurator/pivot_layout_configurator.ts b/src/components/side_panel/pivot/pivot_layout_configurator/pivot_layout_configurator.ts index 8411189694..709d11ee89 100644 --- a/src/components/side_panel/pivot/pivot_layout_configurator/pivot_layout_configurator.ts +++ b/src/components/side_panel/pivot/pivot_layout_configurator/pivot_layout_configurator.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useRef } from "@odoo/owl"; import { isDefined } from "../../../../helpers"; import { @@ -8,7 +9,7 @@ import { import { PivotRuntimeDefinition } from "../../../../helpers/pivot/pivot_runtime_definition"; import { Store, useStore } from "../../../../store_engine"; import { _t } from "../../../../translation"; -import { SortDirection, SpreadsheetChildEnv, UID } from "../../../../types"; +import { SortDirection, SpreadsheetChildEnv } from "../../../../types"; import { Aggregator, Granularity, diff --git a/src/components/side_panel/pivot/pivot_layout_configurator/pivot_measure/pivot_measure.ts b/src/components/side_panel/pivot/pivot_layout_configurator/pivot_measure/pivot_measure.ts index 25e88f4fe7..b446514ccc 100644 --- a/src/components/side_panel/pivot/pivot_layout_configurator/pivot_measure/pivot_measure.ts +++ b/src/components/side_panel/pivot/pivot_layout_configurator/pivot_measure/pivot_measure.ts @@ -1,10 +1,11 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { PIVOT_TOKEN_COLOR } from "../../../../../constants"; import { Token, compile } from "../../../../../formulas"; import { unquote } from "../../../../../helpers"; import { PivotRuntimeDefinition } from "../../../../../helpers/pivot/pivot_runtime_definition"; import { createMeasureAutoComplete } from "../../../../../registries/auto_completes/pivot_dimension_auto_complete"; -import { Color, PivotMeasure } from "../../../../../types"; +import { PivotMeasure } from "../../../../../types"; import { StandaloneComposer } from "../../../../composer/standalone_composer/standalone_composer"; import { PivotDimension } from "../pivot_dimension/pivot_dimension"; diff --git a/src/components/side_panel/pivot/pivot_layout_configurator/pivot_sort_section/pivot_sort_section.ts b/src/components/side_panel/pivot/pivot_layout_configurator/pivot_sort_section/pivot_sort_section.ts index 0aa5ae47b8..55d3c00118 100644 --- a/src/components/side_panel/pivot/pivot_layout_configurator/pivot_sort_section/pivot_sort_section.ts +++ b/src/components/side_panel/pivot/pivot_layout_configurator/pivot_sort_section/pivot_sort_section.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { SpreadsheetChildEnv } from "../../../../.."; import { formatValue } from "../../../../../helpers"; @@ -7,7 +8,7 @@ import { } from "../../../../../helpers/pivot/pivot_helpers"; import { PivotRuntimeDefinition } from "../../../../../helpers/pivot/pivot_runtime_definition"; import { _t } from "../../../../../translation"; -import { PivotDomain, UID } from "../../../../../types"; +import { PivotDomain } from "../../../../../types"; import { Section } from "../../../components/section/section"; interface Props { diff --git a/src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel.ts b/src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel.ts index 8a707e1c37..38e76a54c1 100644 --- a/src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel.ts +++ b/src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; -import { PivotCoreMeasure, SpreadsheetChildEnv, UID } from "../../../.."; +import { PivotCoreMeasure, SpreadsheetChildEnv } from "../../../.."; import { Store, useLocalStore } from "../../../../store_engine"; import { measureDisplayTerms } from "../../../translations_terms"; import { Checkbox } from "../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel_store.ts b/src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel_store.ts index ea76205c41..628c89bd65 100644 --- a/src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel_store.ts +++ b/src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel_store.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { deepCopy } from "../../../../helpers"; import { NEXT_VALUE, PREVIOUS_VALUE } from "../../../../helpers/pivot/pivot_domain_helpers"; import { getFieldDisplayName } from "../../../../helpers/pivot/pivot_helpers"; @@ -9,7 +10,6 @@ import { PivotCoreMeasure, PivotMeasureDisplay, PivotMeasureDisplayType, - UID, } from "../../../../types"; export class PivotMeasureDisplayPanelStore extends SpreadsheetStore { diff --git a/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel.ts b/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel.ts index 51bad42fac..2cf66b8c22 100644 --- a/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel.ts +++ b/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel.ts @@ -1,7 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { getPivotHighlights } from "../../../../helpers/pivot/pivot_highlight"; import { pivotSidePanelRegistry } from "../../../../helpers/pivot/pivot_side_panel_registry"; -import { SpreadsheetChildEnv, UID } from "../../../../types"; +import { SpreadsheetChildEnv } from "../../../../types"; import { useHighlights } from "../../../helpers/highlight_hook"; import { Section } from "../../components/section/section"; import { PivotLayoutConfigurator } from "../pivot_layout_configurator/pivot_layout_configurator"; diff --git a/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts b/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts index 3b970b5dfa..ea3461cf72 100644 --- a/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts +++ b/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { PIVOT_MAX_NUMBER_OF_CELLS } from "../../../../constants"; import { deepCopy, deepEquals } from "../../../../helpers"; import { getFirstPivotFunction } from "../../../../helpers/pivot/pivot_composer_helpers"; @@ -7,7 +8,7 @@ import { Get } from "../../../../store_engine"; import { NotificationStore } from "../../../../stores/notification_store"; import { SpreadsheetStore } from "../../../../stores/spreadsheet_store"; import { _t } from "../../../../translation"; -import { Command, UID } from "../../../../types"; +import { Command } from "../../../../types"; import { PivotCoreDefinition, PivotCoreDimension, diff --git a/src/components/side_panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.ts b/src/components/side_panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.ts index 305d2da612..b3ba03f101 100644 --- a/src/components/side_panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.ts +++ b/src/components/side_panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.ts @@ -1,8 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, useRef, useState } from "@odoo/owl"; import { SpreadsheetPivotRuntimeDefinition } from "../../../../../helpers/pivot/spreadsheet_pivot/runtime_definition_spreadsheet_pivot"; import { SpreadsheetPivot } from "../../../../../helpers/pivot/spreadsheet_pivot/spreadsheet_pivot"; import { Store, useLocalStore } from "../../../../../store_engine"; -import { Ref, SpreadsheetChildEnv, UID } from "../../../../../types"; +import { Ref, SpreadsheetChildEnv } from "../../../../../types"; import { SpreadsheetPivotCoreDefinition } from "../../../../../types/pivot"; import { SelectionInput } from "../../../../selection_input/selection_input"; import { Checkbox } from "../../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/pivot/pivot_title_section/pivot_title_section.ts b/src/components/side_panel/pivot/pivot_title_section/pivot_title_section.ts index 94ac21e186..05dbdb451b 100644 --- a/src/components/side_panel/pivot/pivot_title_section/pivot_title_section.ts +++ b/src/components/side_panel/pivot/pivot_title_section/pivot_title_section.ts @@ -1,7 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { ActionSpec } from "../../../../actions/action"; import { _t } from "../../../../translation"; -import { CommandResult, SpreadsheetChildEnv, UID } from "../../../../types"; +import { CommandResult, SpreadsheetChildEnv } from "../../../../types"; import { TextInput } from "../../../text_input/text_input"; import { CogWheelMenu } from "../../components/cog_wheel_menu/cog_wheel_menu"; import { Section } from "../../components/section/section"; diff --git a/src/components/side_panel/remove_duplicates/remove_duplicates.ts b/src/components/side_panel/remove_duplicates/remove_duplicates.ts index a127bcd937..3038793ef8 100644 --- a/src/components/side_panel/remove_duplicates/remove_duplicates.ts +++ b/src/components/side_panel/remove_duplicates/remove_duplicates.ts @@ -1,7 +1,8 @@ +import { HeaderIndex } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useState } from "@odoo/owl"; import { numberToLetters, zoneToDimension } from "../../../helpers"; import { _t } from "../../../translation"; -import { HeaderIndex, SpreadsheetChildEnv } from "../../../types/index"; +import { SpreadsheetChildEnv } from "../../../types/index"; import { RemoveDuplicateTerms } from "../../translations_terms"; import { ValidationMessages } from "../../validation_messages/validation_messages"; import { Checkbox } from "../components/checkbox/checkbox"; diff --git a/src/components/side_panel/select_menu/select_menu.ts b/src/components/side_panel/select_menu/select_menu.ts index 2c6f9a3224..bee55afe11 100644 --- a/src/components/side_panel/select_menu/select_menu.ts +++ b/src/components/side_panel/select_menu/select_menu.ts @@ -1,7 +1,8 @@ +import { MenuMouseEvent } from "@odoo/o-spreadsheet-engine"; import { Component, useRef, useState } from "@odoo/owl"; import { Action } from "../../../actions/action"; import { UuidGenerator } from "../../../helpers"; -import { MenuMouseEvent, Rect, SpreadsheetChildEnv } from "../../../types"; +import { Rect, SpreadsheetChildEnv } from "../../../types"; import { getRefBoundingRect } from "../../helpers/dom_helpers"; import { MenuPopover } from "../../menu_popover/menu_popover"; diff --git a/src/components/side_panel/table_panel/table_panel.ts b/src/components/side_panel/table_panel/table_panel.ts index d460f3efe5..4679238176 100644 --- a/src/components/side_panel/table_panel/table_panel.ts +++ b/src/components/side_panel/table_panel/table_panel.ts @@ -7,9 +7,9 @@ import { Range, SpreadsheetChildEnv, TableConfig, - Zone, } from "../../../types"; +import { Zone } from "@odoo/o-spreadsheet-engine"; import { getTableTopLeft } from "../../../helpers/table_helpers"; import { SelectionInput } from "../../selection_input/selection_input"; import { TableStylePicker } from "../../tables/table_style_picker/table_style_picker"; diff --git a/src/components/side_panel/table_style_editor_panel/table_style_editor_panel.ts b/src/components/side_panel/table_style_editor_panel/table_style_editor_panel.ts index 2f1cf8af8a..62837b46f9 100644 --- a/src/components/side_panel/table_style_editor_panel/table_style_editor_panel.ts +++ b/src/components/side_panel/table_style_editor_panel/table_style_editor_panel.ts @@ -1,8 +1,8 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { Component, useExternalListener, useState } from "@odoo/owl"; import { isColorValid } from "../../../helpers"; import { TABLE_STYLES_TEMPLATES, buildTableStyle } from "../../../helpers/table_presets"; import { - Color, SpreadsheetChildEnv, TableConfig, TableStyle, diff --git a/src/components/spreadsheet/spreadsheet.ts b/src/components/spreadsheet/spreadsheet.ts index f86f5704b5..9ac41b7bce 100644 --- a/src/components/spreadsheet/spreadsheet.ts +++ b/src/components/spreadsheet/spreadsheet.ts @@ -1,3 +1,4 @@ +import { HeaderGroup, Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, @@ -18,13 +19,7 @@ import { ModelStore } from "../../stores"; import { NotificationStore, NotificationStoreMethods } from "../../stores/notification_store"; import { ScreenWidthStore } from "../../stores/screen_width_store"; import { _t } from "../../translation"; -import { - CSSProperties, - HeaderGroup, - InformationNotification, - Pixel, - SpreadsheetChildEnv, -} from "../../types"; +import { CSSProperties, InformationNotification, SpreadsheetChildEnv } from "../../types"; import { BottomBar } from "../bottom_bar/bottom_bar"; import { ComposerFocusStore } from "../composer/composer_focus_store"; import { SpreadsheetDashboard } from "../dashboard/dashboard"; diff --git a/src/components/tables/hovered_table_store.ts b/src/components/tables/hovered_table_store.ts index f65ae6bb84..74be583d5e 100644 --- a/src/components/tables/hovered_table_store.ts +++ b/src/components/tables/hovered_table_store.ts @@ -1,8 +1,9 @@ +import { Color, Position } from "@odoo/o-spreadsheet-engine"; import { TABLE_HOVER_BACKGROUND_COLOR } from "../../constants"; import { range } from "../../helpers"; import { PositionMap } from "../../helpers/cells/position_map"; import { SpreadsheetStore } from "../../stores"; -import { Color, Command, Position } from "../../types"; +import { Command } from "../../types"; export class HoveredTableStore extends SpreadsheetStore { mutators = ["clear", "hover"] as const; diff --git a/src/components/tables/table_resizer/table_resizer.ts b/src/components/tables/table_resizer/table_resizer.ts index 3803d9212e..61d0c8fa91 100644 --- a/src/components/tables/table_resizer/table_resizer.ts +++ b/src/components/tables/table_resizer/table_resizer.ts @@ -1,9 +1,8 @@ +import { HeaderIndex, Highlight, Zone } from "@odoo/o-spreadsheet-engine"; import { Component, useState } from "@odoo/owl"; -import { HeaderIndex, Highlight, SpreadsheetChildEnv, Table, Zone } from "../../../types"; +import { SpreadsheetChildEnv, Table } from "../../../types"; import { cssPropertiesToCss } from "../../helpers"; import { useDragAndDropBeyondTheViewport } from "../../helpers/drag_and_drop_grid_hook"; -import { useHighlights } from "../../helpers/highlight_hook"; - const SIZE = 3; const COLOR = "#777"; diff --git a/src/components/top_bar/top_bar.ts b/src/components/top_bar/top_bar.ts index 506f0b1e7e..91acd00497 100644 --- a/src/components/top_bar/top_bar.ts +++ b/src/components/top_bar/top_bar.ts @@ -1,3 +1,4 @@ +import { Color, Pixel } from "@odoo/o-spreadsheet-engine"; import { Component, onWillStart, @@ -15,7 +16,7 @@ import { topbarMenuRegistry } from "../../registries/menus/topbar_menu_registry" import { topbarComponentRegistry } from "../../registries/topbar_component_registry"; import { Store, useStore } from "../../store_engine"; import { FormulaFingerprintStore } from "../../stores/formula_fingerprints_store"; -import { Color, Pixel, SpreadsheetChildEnv } from "../../types/index"; +import { SpreadsheetChildEnv } from "../../types/index"; import { ComposerFocusStore } from "../composer/composer_focus_store"; import { TopBarComposer } from "../composer/top_bar_composer/top_bar_composer"; import { getBoundingRectAsPOJO } from "../helpers/dom_helpers"; @@ -23,8 +24,6 @@ import { useSpreadsheetRect } from "../helpers/position_hook"; import { MenuPopover, MenuState } from "../menu_popover/menu_popover"; import { Popover, PopoverProps } from "../popover"; import { TopBarToolStore } from "./top_bar_tool_store"; -import { topBarToolBarRegistry } from "./top_bar_tools_registry"; - interface State { menuState: MenuState; invisibleToolsCategories: string[]; diff --git a/src/constants.ts b/src/constants.ts index a408ba8941..74be050a4b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,3 @@ -import { BorderDescr, ChartStyle, Color, Currency, Style } from "./types"; - export const CANVAS_SHIFT = 0.5; // Colors diff --git a/src/formulas/compiler.ts b/src/formulas/compiler.ts index 9f21697137..7ddc09fd9f 100644 --- a/src/formulas/compiler.ts +++ b/src/formulas/compiler.ts @@ -1,3 +1,4 @@ +import { CompiledFormula, FormulaToExecute, functionRegistry } from "@odoo/o-spreadsheet-engine"; import { OPERATOR_MAP, UNARY_OPERATOR_MAP, @@ -8,8 +9,6 @@ import { setFunctionRegistryProvider, } from "@odoo/o-spreadsheet-engine/formulas/compiler"; import { argTargeting } from "../functions/arguments"; -import { functionRegistry } from "../functions/index"; -import type { CompiledFormula, FormulaToExecute } from "../types"; import type { Token } from "./tokenizer"; //TODO When the getters will be moved to o-spreadsheet-engine, we will be able diff --git a/src/formulas/composer_tokenizer.ts b/src/formulas/composer_tokenizer.ts index e17df8bdbf..4cc0910c9b 100644 --- a/src/formulas/composer_tokenizer.ts +++ b/src/formulas/composer_tokenizer.ts @@ -1,4 +1,5 @@ -import { Color, Locale } from "../types"; +import { Color } from "@odoo/o-spreadsheet-engine"; +import { Locale } from "../types"; import { Token } from "./index"; import { AST, parseTokens } from "./parser"; import { rangeTokenize } from "./range_tokenizer"; diff --git a/src/formulas/index.ts b/src/formulas/index.ts index 7fce7c353b..24aad6b1fa 100644 --- a/src/formulas/index.ts +++ b/src/formulas/index.ts @@ -8,7 +8,6 @@ */ export { compile } from "./compiler"; -export * from "./helpers"; export { parse } from "./parser"; export { rangeTokenize } from "./range_tokenizer"; export { Token, tokenize } from "./tokenizer"; diff --git a/src/functions/createAutocompleteArgumentsProvider.ts b/src/functions/createAutocompleteArgumentsProvider.ts new file mode 100644 index 0000000000..971d66bf66 --- /dev/null +++ b/src/functions/createAutocompleteArgumentsProvider.ts @@ -0,0 +1,85 @@ +import { ArgDefinition } from "@odoo/o-spreadsheet-engine"; +import { CellComposerStore } from "../components/composer/composer/cell_composer_store"; +import { tokenColors } from "../constants"; +import { EnrichedToken } from "../formulas/composer_tokenizer"; +import { AutoCompleteProposal, autoCompleteProviders } from "../registries/auto_completes"; + +export function createAutocompleteArgumentsProvider(formulaName: string, args: ArgDefinition[]) { + for (let i = 0; i < args.length; i++) { + const proposalValues = args[i].proposalValues; + if (proposalValues === undefined || proposalValues.length === 0) { + continue; + } + + const getProposals = (tokenAtCursor: EnrichedToken) => { + const functionContext = tokenAtCursor.functionContext; + if ( + !functionContext || + functionContext.parent.toUpperCase() !== formulaName.toUpperCase() || + functionContext.argPosition !== i + ) { + return; + } + + const proposals: AutoCompleteProposal[] = []; + let text = ""; + for (const { value, label } of proposalValues) { + switch (typeof value) { + case "string": + text = `"${value}"`; + break; + case "number": + text = value.toString(); + break; + case "boolean": + text = value ? "TRUE" : "FALSE"; + break; + default: + } + + proposals.push({ + text, + description: label, + htmlContent: [ + { + value: text, + color: typeof value === "string" ? tokenColors.STRING : tokenColors.NUMBER, + }, + ], + fuzzySearchKey: text, + alwaysExpanded: true, + }); + } + + return proposals; + }; + + autoCompleteProviders.add(`${formulaName}_function_${args[i].name}_argument_proposals`, { + sequence: 50, + autoSelectFirstProposal: true, + selectProposal: insertTokenAtArgStartingPosition, + getProposals, + }); + } +} + +/** + * Perform the autocomplete of the composer by inserting the value + * at the cursor position, replacing the current token if necessary. + * Must be bound to the autocomplete provider. + */ +export function insertTokenAtArgStartingPosition( + this: { composer: CellComposerStore }, + tokenAtCursor: EnrichedToken, + value: string +) { + let start = tokenAtCursor.end; + const end = tokenAtCursor.end; + if (!["LEFT_PAREN", "ARG_SEPARATOR"].includes(tokenAtCursor.type)) { + // replace the whole token + start = tokenAtCursor.start; + } + this.composer.stopComposerRangeSelection(); + this.composer.changeComposerCursorSelection(start, end); + this.composer.replaceComposerCursorSelection(value); +} diff --git a/src/functions/get_moving_average_values.ts b/src/functions/get_moving_average_values.ts new file mode 100644 index 0000000000..103d25982f --- /dev/null +++ b/src/functions/get_moving_average_values.ts @@ -0,0 +1,22 @@ +import { Point } from "chart.js"; +import { DEFAULT_WINDOW_SIZE } from "../constants"; + +export function getMovingAverageValues( + dataset: number[], + labels: number[], + windowSize = DEFAULT_WINDOW_SIZE +): Point[] { + const values: Point[] = []; + // Fill the starting values with null until we have a full window + for (let i = 0; i < windowSize - 1; i++) { + values.push({ x: labels[i], y: NaN }); + } + for (let i = 0; i <= dataset.length - windowSize; i++) { + let sum = 0; + for (let j = i; j < i + windowSize; j++) { + sum += dataset[j]; + } + values.push({ x: labels[i + windowSize - 1], y: sum / windowSize }); + } + return values; +} diff --git a/src/functions/helper_assert.ts b/src/functions/helper_assert.ts index e27ff4da17..16bbed16cf 100644 --- a/src/functions/helper_assert.ts +++ b/src/functions/helper_assert.ts @@ -1,6 +1,7 @@ +import { Arg, FunctionResultObject, isMatrix, Matrix } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { Arg, FunctionResultNumber, FunctionResultObject, Matrix, isMatrix } from "../types"; -import { DivisionByZeroError, EvaluationError } from "../types/errors"; +import { FunctionResultNumber } from "../types"; +import { EvaluationError } from "../types/errors"; export function assert(condition: boolean, message: string): asserts condition { if (!condition) { diff --git a/src/functions/helper_logical.ts b/src/functions/helper_logical.ts index 9d2f52e61e..fac9598db4 100644 --- a/src/functions/helper_logical.ts +++ b/src/functions/helper_logical.ts @@ -1,4 +1,4 @@ -import { Arg } from "../types"; +import { Arg } from "@odoo/o-spreadsheet-engine"; import { conditionalVisitBoolean } from "./helpers"; export function boolAnd(args: Arg[]) { diff --git a/src/functions/helper_lookup.ts b/src/functions/helper_lookup.ts index 825d5e697e..02fc257170 100644 --- a/src/functions/helper_lookup.ts +++ b/src/functions/helper_lookup.ts @@ -1,9 +1,8 @@ +import { EvalContext, FunctionResultObject, Maybe, UID } from "@odoo/o-spreadsheet-engine"; import { isZoneInside, positionToZone, zoneToXc } from "../helpers"; import { _t } from "../translation"; -import { EvalContext, FunctionResultObject, Getters, Maybe, Range, UID } from "../types"; +import { Getters, Range } from "../types"; import { CircularDependencyError, EvaluationError, InvalidReferenceError } from "../types/errors"; -import { PivotCoreDefinition, PivotCoreMeasure } from "../types/pivot"; - /** * Get the pivot ID from the formula pivot ID. */ diff --git a/src/functions/helper_math.ts b/src/functions/helper_math.ts index fa78dfd26a..9a497886f7 100644 --- a/src/functions/helper_math.ts +++ b/src/functions/helper_math.ts @@ -1,4 +1,5 @@ -import { Arg, Locale } from "../types"; +import { Arg } from "@odoo/o-spreadsheet-engine"; +import { Locale } from "../types"; import { isDataNonEmpty, reduceAny, reduceNumbers } from "./helpers"; export function sum(values: Arg[], locale: Locale): number { diff --git a/src/functions/helper_statistical.ts b/src/functions/helper_statistical.ts index 0e13d8855b..a37fbd483f 100644 --- a/src/functions/helper_statistical.ts +++ b/src/functions/helper_statistical.ts @@ -1,18 +1,20 @@ -import { Point } from "chart.js"; -import { DEFAULT_WINDOW_SIZE } from "../constants"; -import { isNumber, parseDateTime, range } from "../helpers"; -import { _t } from "../translation"; -import { Arg, Locale, Matrix, isMatrix } from "../types"; -import { EvaluationError } from "../types/errors"; -import { assert, assertNotZero } from "./helper_assert"; -import { invertMatrix, multiplyMatrices } from "./helper_matrices"; +import { isMatrix } from "@odoo/o-spreadsheet-engine"; +import { + invertMatrix, + multiplyMatrices, +} from "@odoo/o-spreadsheet-engine/functions/helper_matrices"; import { isEvaluationError, reduceAny, reduceNumbers, transposeMatrix, visitNumbers, -} from "./helpers"; +} from "@odoo/o-spreadsheet-engine/functions/helpers"; +import { Arg, EvaluationError, Locale } from "@odoo/o-spreadsheet-engine/types"; +import { Matrix } from "@odoo/o-spreadsheet-engine/types/base"; +import { isNumber, parseDateTime, range } from "../helpers"; +import { _t } from "../translation"; +import { assert, assertNotZero } from "./helper_assert"; export function assertSameNumberOfElements(...args: any[][]) { const dims = args[0].length; @@ -285,23 +287,3 @@ export function predictLinearValues( }); return newY.length === newX.length ? newY : transposeMatrix(newY); } - -export function getMovingAverageValues( - dataset: number[], - labels: number[], - windowSize = DEFAULT_WINDOW_SIZE -): Point[] { - const values: Point[] = []; - // Fill the starting values with null until we have a full window - for (let i = 0; i < windowSize - 1; i++) { - values.push({ x: labels[i], y: NaN }); - } - for (let i = 0; i <= dataset.length - windowSize; i++) { - let sum = 0; - for (let j = i; j < i + windowSize; j++) { - sum += dataset[j]; - } - values.push({ x: labels[i + windowSize - 1], y: sum / windowSize }); - } - return values; -} diff --git a/src/functions/index.ts b/src/functions/index.ts index 312e6eb1c9..593a8d25e7 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -1,104 +1,12 @@ -import { FunctionRegistry as EngineFunctionRegistry } from "@odoo/o-spreadsheet-engine"; -import { CellComposerStore } from "../components/composer/composer/cell_composer_store"; -import { tokenColors } from "../constants"; -import { EnrichedToken } from "../formulas/composer_tokenizer"; -import { - AutoCompleteProposal, - autoCompleteProviders, -} from "../registries/auto_completes/auto_complete_registry"; -import { _t } from "../translation"; -import { - AddFunctionDescription, - Arg, - ArgDefinition, - CellValue, - ComputeFunction, - EvalContext, - FunctionDescription, - FunctionResultObject, - Matrix, - isMatrix, -} from "../types"; -import { BadExpressionError, EvaluationError } from "../types/errors"; -import { addMetaInfoFromArg, argTargeting, validateArguments } from "./arguments"; -import { applyVectorization, isEvaluationError, matrixForEach, matrixMap } from "./helpers"; -import * as array from "./module_array"; -import * as misc from "./module_custom"; -import * as database from "./module_database"; -import * as date from "./module_date"; -import * as engineering from "./module_engineering"; -import * as filter from "./module_filter"; -import * as financial from "./module_financial"; -import * as info from "./module_info"; -import * as logical from "./module_logical"; -import * as lookup from "./module_lookup"; -import * as math from "./module_math"; -import * as operators from "./module_operators"; -import * as parser from "./module_parser"; -import * as pivots from "./module_pivot"; -import * as statistical from "./module_statistical"; -import * as text from "./module_text"; -import * as web from "./module_web"; +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; +import { createAutocompleteArgumentsProvider } from "./createAutocompleteArgumentsProvider"; -export { FunctionRegistry } from "@odoo/o-spreadsheet-engine"; - -export { arg } from "./arguments"; - -type Functions = { [functionName: string]: AddFunctionDescription }; -type Category = { name: string; functions: Functions }; -const categories: Category[] = [ - { name: _t("Array"), functions: array }, - { name: _t("Database"), functions: database }, - { name: _t("Date"), functions: date }, - { name: _t("Filter"), functions: filter }, - { name: _t("Financial"), functions: financial }, - { name: _t("Info"), functions: info }, - { name: _t("Lookup"), functions: { ...lookup, ...pivots } }, - { name: _t("Logical"), functions: logical }, - { name: _t("Math"), functions: math }, - { name: _t("Misc"), functions: misc }, - { name: _t("Operator"), functions: operators }, - { name: _t("Statistical"), functions: statistical }, - { name: _t("Text"), functions: text }, - { name: _t("Engineering"), functions: engineering }, - { name: _t("Web"), functions: web }, - { name: _t("Parser"), functions: parser }, -]; - -const functionNameRegex = /^[A-Z0-9\_\.]+$/; +import { categories } from "@odoo/o-spreadsheet-engine"; //------------------------------------------------------------------------------ // Function registry //------------------------------------------------------------------------------ -class SpreadsheetFunctionRegistry extends EngineFunctionRegistry< - AddFunctionDescription, - FunctionDescription, - ComputeFunction | FunctionResultObject> -> { - protected process(name: string, addDescr: AddFunctionDescription) { - const normalizedName = name.toUpperCase(); - if (!functionNameRegex.test(normalizedName)) { - throw new Error( - _t( - "Invalid function name %s. Function names can exclusively contain alphanumerical values separated by dots (.) or underscore (_)", - normalizedName - ) - ); - } - const descr = addMetaInfoFromArg(normalizedName, addDescr); - validateArguments(descr); - const compute = createComputeFunction(descr); - return { - key: normalizedName, - stored: descr, - mapped: compute, - }; - } -} - -export const functionRegistry = new SpreadsheetFunctionRegistry(); - for (const category of categories) { const fns = category.functions; for (let name in fns) { @@ -110,216 +18,3 @@ for (const category of categories) { createAutocompleteArgumentsProvider(name, addDescr.args); } } - -//------------------------------------------------------------------------------ -// CREATE COMPUTE FUNCTION -//------------------------------------------------------------------------------ - -function createComputeFunction( - descr: FunctionDescription -): ComputeFunction | FunctionResultObject> { - function vectorizedCompute( - this: EvalContext, - ...args: Arg[] - ): FunctionResultObject | Matrix { - const acceptToVectorize: boolean[] = []; - - const getArgToFocus = argTargeting(descr, args.length); - //#region Compute vectorisation limits - for (let i = 0; i < args.length; i++) { - const argIndex = getArgToFocus(i) ?? -1; - const argDefinition = descr.args[argIndex]; - const arg = args[i]; - if (!isMatrix(arg) && argDefinition.acceptMatrixOnly) { - throw new BadExpressionError( - _t( - "Function %s expects the parameter '%s' to be reference to a cell or range.", - descr.name, - (i + 1).toString() - ) - ); - } - acceptToVectorize.push(!argDefinition.acceptMatrix); - } - - return applyVectorization(errorHandlingCompute.bind(this), args, acceptToVectorize); - } - - function errorHandlingCompute( - this: EvalContext, - ...args: Arg[] - ): Matrix | FunctionResultObject { - for (let i = 0; i < args.length; i++) { - const arg = args[i]; - const getArgToFocus = argTargeting(descr, args.length); - const argDefinition = descr.args[getArgToFocus(i) || i]; - - // Early exit if the argument is an error and the function does not accept errors - // We only check scalar arguments, not matrix arguments for performance reasons. - // Casting helpers are responsible for handling errors in matrix arguments. - if (!argDefinition.acceptErrors && !isMatrix(arg) && isEvaluationError(arg?.value)) { - return arg; - } - } - try { - return computeFunctionToObject.apply(this, args); - } catch (e) { - return handleError(e, descr.name); - } - } - - function computeFunctionToObject( - this: EvalContext, - ...args: Arg[] - ): FunctionResultObject | Matrix { - if (this.debug) { - // eslint-disable-next-line no-debugger - debugger; - } - const result = descr.compute.apply(this, args); - - if (!isMatrix(result)) { - if (typeof result === "object" && result !== null && "value" in result) { - replaceFunctionNamePlaceholder(result, descr.name); - return result; - } - return { value: result }; - } - - if (typeof result[0][0] === "object" && result[0][0] !== null && "value" in result[0][0]) { - matrixForEach(result as Matrix, (result) => - replaceFunctionNamePlaceholder(result, descr.name) - ); - return result as Matrix; - } - - return matrixMap(result as Matrix, (row) => ({ value: row })); - } - - return vectorizedCompute; -} - -export function handleError(e: unknown, functionName: string): FunctionResultObject { - // the error could be an user error (instance of EvaluationError) - // or a javascript error (instance of Error) - // we don't want block the user with an implementation error - // so we fallback to a generic error - if (hasStringValue(e) && isEvaluationError(e.value)) { - if (hasStringMessage(e)) { - replaceFunctionNamePlaceholder(e, functionName); - } - return e; - } - console.error(e); - return new EvaluationError( - implementationErrorMessage + (hasStringMessage(e) ? " " + e.message : "") - ); -} - -function hasStringValue(obj: unknown): obj is { value: string } { - return ( - (obj as { value: string })?.value !== undefined && - typeof (obj as { value: string }).value === "string" - ); -} - -function replaceFunctionNamePlaceholder( - functionResult: FunctionResultObject, - functionName: string -) { - // for performance reasons: change in place and only if needed - if (functionResult.message?.includes("[[FUNCTION_NAME]]")) { - functionResult.message = functionResult.message.replace("[[FUNCTION_NAME]]", functionName); - } -} - -export const implementationErrorMessage = _t( - "An unexpected error occurred. Submit a support ticket at odoo.com/help." -); - -function hasStringMessage(obj: unknown): obj is { message: string } { - return ( - (obj as { message: string })?.message !== undefined && - typeof (obj as { message: string }).message === "string" - ); -} - -function createAutocompleteArgumentsProvider(formulaName: string, args: ArgDefinition[]) { - for (let i = 0; i < args.length; i++) { - const proposalValues = args[i].proposalValues; - if (proposalValues === undefined || proposalValues.length === 0) { - continue; - } - - const getProposals = (tokenAtCursor: EnrichedToken) => { - const functionContext = tokenAtCursor.functionContext; - if ( - !functionContext || - functionContext.parent.toUpperCase() !== formulaName.toUpperCase() || - functionContext.argPosition !== i - ) { - return; - } - - const proposals: AutoCompleteProposal[] = []; - let text = ""; - for (const { value, label } of proposalValues) { - switch (typeof value) { - case "string": - text = `"${value}"`; - break; - case "number": - text = value.toString(); - break; - case "boolean": - text = value ? "TRUE" : "FALSE"; - break; - default: - } - - proposals.push({ - text, - description: label, - htmlContent: [ - { - value: text, - color: typeof value === "string" ? tokenColors.STRING : tokenColors.NUMBER, - }, - ], - fuzzySearchKey: text, - alwaysExpanded: true, - }); - } - - return proposals; - }; - - autoCompleteProviders.add(`${formulaName}_function_${args[i].name}_argument_proposals`, { - sequence: 50, - autoSelectFirstProposal: true, - selectProposal: insertTokenAtArgStartingPosition, - getProposals, - }); - } -} - -/** - * Perform the autocomplete of the composer by inserting the value - * at the cursor position, replacing the current token if necessary. - * Must be bound to the autocomplete provider. - */ -export function insertTokenAtArgStartingPosition( - this: { composer: CellComposerStore }, - tokenAtCursor: EnrichedToken, - value: string -) { - let start = tokenAtCursor.end; - const end = tokenAtCursor.end; - if (!["LEFT_PAREN", "ARG_SEPARATOR"].includes(tokenAtCursor.type)) { - // replace the whole token - start = tokenAtCursor.start; - } - this.composer.stopComposerRangeSelection(); - this.composer.changeComposerCursorSelection(start, end); - this.composer.replaceComposerCursorSelection(value); -} diff --git a/src/functions/module_array.ts b/src/functions/module_array.ts index 68caa11334..e1a249d892 100644 --- a/src/functions/module_array.ts +++ b/src/functions/module_array.ts @@ -1,5 +1,5 @@ +import { Arg, FunctionResultObject, Functions, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { AddFunctionDescription, Arg, FunctionResultObject, Matrix, Maybe } from "../types"; import { EvaluationError, NotAvailableError } from "../types/errors"; import { arg } from "./arguments"; import { areSameDimensions, isSingleColOrRow, isSquareMatrix } from "./helper_assert"; @@ -52,7 +52,7 @@ export const ARRAY_CONSTRAIN = { return generateMatrix(_nbColumns, _nbRows, (col, row) => _array[col][row]); }, isExported: false, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CHOOSECOLS @@ -98,7 +98,7 @@ export const CHOOSECOLS = { return result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CHOOSEROWS @@ -138,7 +138,7 @@ export const CHOOSEROWS = { }); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // EXPAND @@ -191,7 +191,7 @@ export const EXPAND = { ); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FLATTEN @@ -206,7 +206,7 @@ export const FLATTEN = { return [flattenRowFirst(ranges, (val) => (val === undefined ? { value: "" } : val))]; }, isExported: false, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FREQUENCY @@ -266,7 +266,7 @@ export const FREQUENCY = { return [result]; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // HSTACK @@ -296,7 +296,7 @@ export const HSTACK = { return result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MDETERM @@ -321,7 +321,7 @@ export const MDETERM = { return invertMatrix(_matrix).determinant; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MINVERSE @@ -350,7 +350,7 @@ export const MINVERSE = { return inverted; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MMULT @@ -391,7 +391,7 @@ export const MMULT = { return multiplyMatrices(_matrix1, _matrix2); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUMPRODUCT @@ -435,7 +435,7 @@ export const SUMPRODUCT = { return result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUMX2MY2 @@ -500,7 +500,7 @@ export const SUMX2MY2 = { return getSumXAndY(arrayX, arrayY, (x, y) => x ** 2 - y ** 2); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUMX2PY2 @@ -525,7 +525,7 @@ export const SUMX2PY2 = { return getSumXAndY(arrayX, arrayY, (x, y) => x ** 2 + y ** 2); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUMXMY2 @@ -550,7 +550,7 @@ export const SUMXMY2 = { return getSumXAndY(arrayX, arrayY, (x, y) => (x - y) ** 2); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TOCOL @@ -617,7 +617,7 @@ export const TOCOL = { return [result]; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TOROW @@ -644,7 +644,7 @@ export const TOROW = { return result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TRANSPOSE @@ -660,7 +660,7 @@ export const TRANSPOSE = { return generateMatrix(nbColumns, nbRows, (col, row) => _array[row][col]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VSTACK @@ -693,7 +693,7 @@ export const VSTACK = { return result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // WRAPCOLS @@ -734,7 +734,7 @@ export const WRAPCOLS = { }); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // WRAPROWS @@ -775,4 +775,4 @@ export const WRAPROWS = { }); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_custom.ts b/src/functions/module_custom.ts index 1bae8277da..bcc7936e2d 100644 --- a/src/functions/module_custom.ts +++ b/src/functions/module_custom.ts @@ -1,11 +1,7 @@ +import { FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { formatLargeNumber } from "../helpers"; import { _t } from "../translation"; -import { - AddFunctionDescription, - FunctionResultNumber, - FunctionResultObject, - Maybe, -} from "../types"; +import { FunctionResultNumber } from "../types"; import { arg } from "./arguments"; import { toNumber } from "./helpers"; @@ -36,4 +32,4 @@ export const FORMAT_LARGE_NUMBER = { format: formatLargeNumber(value, unite, this.locale), }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_database.ts b/src/functions/module_database.ts index 285441243a..5722a92fd0 100644 --- a/src/functions/module_database.ts +++ b/src/functions/module_database.ts @@ -1,13 +1,6 @@ +import { Arg, FunctionResultObject, Functions, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { - AddFunctionDescription, - Arg, - FunctionResultNumber, - FunctionResultObject, - Locale, - Matrix, - Maybe, -} from "../types"; +import { FunctionResultNumber, Locale } from "../types"; import { EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { toString, visitMatchingRanges } from "./helpers"; @@ -178,7 +171,7 @@ export const DAVERAGE = { return AVERAGE.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DCOUNT @@ -195,7 +188,7 @@ export const DCOUNT = { return COUNT.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DCOUNTA @@ -212,7 +205,7 @@ export const DCOUNTA = { return COUNTA.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DGET @@ -232,7 +225,7 @@ export const DGET = { return cells[0]; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DMAX @@ -249,7 +242,7 @@ export const DMAX = { return MAX.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DMIN @@ -266,7 +259,7 @@ export const DMIN = { return MIN.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DPRODUCT @@ -283,7 +276,7 @@ export const DPRODUCT = { return PRODUCT.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DSTDEV @@ -300,7 +293,7 @@ export const DSTDEV = { return STDEV.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DSTDEVP @@ -317,7 +310,7 @@ export const DSTDEVP = { return STDEVP.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DSUM @@ -334,7 +327,7 @@ export const DSUM = { return SUM.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DVAR @@ -351,7 +344,7 @@ export const DVAR = { return VAR.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DVARP @@ -368,4 +361,4 @@ export const DVARP = { return VARP.compute.bind(this)([cells]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_date.ts b/src/functions/module_date.ts index ff150d99e0..462dd5d470 100644 --- a/src/functions/module_date.ts +++ b/src/functions/module_date.ts @@ -1,3 +1,4 @@ +import { Arg, FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { addMonthsToDate, areTwoDatesWithinOneYear, @@ -15,13 +16,7 @@ import { } from "../helpers/dates"; import { getDateTimeFormat } from "../helpers/locale"; import { _t } from "../translation"; -import { - AddFunctionDescription, - Arg, - FunctionResultNumber, - FunctionResultObject, - Maybe, -} from "../types"; +import { FunctionResultNumber } from "../types"; import { EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { assert } from "./helper_assert"; @@ -85,7 +80,7 @@ export const DATE = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DATEDIF @@ -199,7 +194,7 @@ export const DATEDIF = { } }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DATEVALUE @@ -220,7 +215,7 @@ export const DATEVALUE = { return Math.trunc(internalDate!.value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DAY @@ -232,7 +227,7 @@ export const DAY = { return toJsDate(date, this.locale).getDate(); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DAYS @@ -254,7 +249,7 @@ export const DAYS = { return Math.round(dateDif / MS_PER_DAY); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DAYS360 @@ -287,7 +282,7 @@ export const DAYS360 = { return Math.sign(_endDate - _startDate) * Math.round(yearFrac * 360); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // EDATE @@ -315,7 +310,7 @@ export const EDATE = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // EOMONTH @@ -345,7 +340,7 @@ export const EOMONTH = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // HOUR @@ -357,7 +352,7 @@ export const HOUR = { return toJsDate(date, this.locale).getHours(); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISOWEEKNUM @@ -445,7 +440,7 @@ export const ISOWEEKNUM = { return Math.floor(diff / 7) + 1; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MINUTE @@ -457,7 +452,7 @@ export const MINUTE = { return toJsDate(date, this.locale).getMinutes(); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MONTH @@ -469,7 +464,7 @@ export const MONTH = { return toJsDate(date, this.locale).getMonth() + 1; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NETWORKDAYS @@ -498,7 +493,7 @@ export const NETWORKDAYS = { return NETWORKDAYS_INTL.compute.bind(this)(startDate, endDate, { value: 1 }, holidays); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NETWORKDAYS.INTL @@ -648,7 +643,7 @@ export const NETWORKDAYS_INTL = { return invertDate ? -netWorkingDay : netWorkingDay; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NOW @@ -667,7 +662,7 @@ export const NOW = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SECOND @@ -679,7 +674,7 @@ export const SECOND = { return toJsDate(date, this.locale).getSeconds(); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TIME @@ -718,7 +713,7 @@ export const TIME = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TIMEVALUE @@ -740,7 +735,7 @@ export const TIMEVALUE = { return result < 0 ? 1 + result : result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TODAY @@ -757,7 +752,7 @@ export const TODAY = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // WEEKDAY @@ -817,7 +812,7 @@ export const WEEKDAY = { return result === 0 ? 7 : result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // WEEKNUM @@ -888,7 +883,7 @@ export const WEEKNUM = { return Math.floor(dif / 7) + (dayStart === 1 ? 1 : 2); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // WORKDAY @@ -914,7 +909,7 @@ export const WORKDAY = { return WORKDAY_INTL.compute.bind(this)(startDate, numDays, { value: 1 }, holidays); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // WORKDAY.INTL @@ -981,7 +976,7 @@ export const WORKDAY_INTL = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // YEAR @@ -993,7 +988,7 @@ export const YEAR = { return toJsDate(date, this.locale).getFullYear(); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // YEARFRAC @@ -1043,7 +1038,7 @@ export const YEARFRAC = { return getYearFrac(_startDate, _endDate, _dayCountConvention); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MONTH.START @@ -1061,7 +1056,7 @@ export const MONTH_START = { format: this.locale.dateFormat, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MONTH.END @@ -1072,7 +1067,7 @@ export const MONTH_END = { compute: function (date: Maybe): FunctionResultNumber { return EOMONTH.compute.bind(this)(date, { value: 0 }); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // QUARTER @@ -1083,7 +1078,7 @@ export const QUARTER = { compute: function (date: Maybe): number { return Math.ceil((toJsDate(date, this.locale).getMonth() + 1) / 3); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // QUARTER.START @@ -1100,7 +1095,7 @@ export const QUARTER_START = { format: this.locale.dateFormat, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // QUARTER.END @@ -1117,7 +1112,7 @@ export const QUARTER_END = { format: this.locale.dateFormat, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // YEAR.START @@ -1133,7 +1128,7 @@ export const YEAR_START = { format: this.locale.dateFormat, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // YEAR.END @@ -1149,4 +1144,4 @@ export const YEAR_END = { format: this.locale.dateFormat, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_engineering.ts b/src/functions/module_engineering.ts index c6d7e24f6b..4ee9a23782 100644 --- a/src/functions/module_engineering.ts +++ b/src/functions/module_engineering.ts @@ -1,5 +1,5 @@ +import { FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { AddFunctionDescription, FunctionResultObject, Maybe } from "../types"; import { arg } from "./arguments"; import { toNumber } from "./helpers"; @@ -23,4 +23,4 @@ export const DELTA = { return _number1 === _number2 ? 1 : 0; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_filter.ts b/src/functions/module_filter.ts index 970fda3cc3..5af2197b21 100644 --- a/src/functions/module_filter.ts +++ b/src/functions/module_filter.ts @@ -1,18 +1,15 @@ -import { range } from "../helpers"; -import { cellsSortingCriterion } from "../helpers/sort"; -import { _t } from "../translation"; import { - AddFunctionDescription, Arg, - CellValue, - CellValueType, FunctionResultObject, - Locale, + Functions, + isMatrix, Matrix, Maybe, - SortDirection, - isMatrix, -} from "../types"; +} from "@odoo/o-spreadsheet-engine"; +import { range } from "../helpers"; +import { cellsSortingCriterion } from "../helpers/sort"; +import { _t } from "../translation"; +import { CellValue, CellValueType, Locale, SortDirection } from "../types"; import { EvaluationError, NotAvailableError } from "../types/errors"; import { arg } from "./arguments"; import { areSameDimensions, assert, isSingleColOrRow } from "./helper_assert"; @@ -159,12 +156,12 @@ export const FILTER = { return mode === "row" ? transposeMatrix(result) : result; }, isExported: false, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SORT // ----------------------------------------------------------------------------- -export const SORT: AddFunctionDescription = { +export const SORT: Functions = { description: _t("Sorts the rows of a given array or range by the values in one or more columns."), args: [ arg("range (range)", _t("The data to be sorted.")), @@ -196,7 +193,7 @@ export const SORT: AddFunctionDescription = { // ----------------------------------------------------------------------------- // SORTN // ----------------------------------------------------------------------------- -export const SORTN: AddFunctionDescription = { +export const SORTN: Functions = { description: _t("Returns the first n items in a data set after performing a sort."), args: [ arg("range (range)", _t("The data to be sorted.")), @@ -366,4 +363,4 @@ export const UNIQUE = { return _byColumn ? result : transposeMatrix(result); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_financial.ts b/src/functions/module_financial.ts index abbd60b070..b23e0c8e12 100644 --- a/src/functions/module_financial.ts +++ b/src/functions/module_financial.ts @@ -1,3 +1,4 @@ +import { Arg, FunctionResultObject, Functions, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; import { addMonthsToDate, getYearFrac, @@ -6,7 +7,7 @@ import { range, } from "../helpers"; import { _t } from "../translation"; -import { AddFunctionDescription, Arg, FunctionResultObject, Locale, Matrix, Maybe } from "../types"; +import { Locale } from "../types"; import { EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { areSameDimensions, assert } from "./helper_assert"; @@ -216,7 +217,7 @@ export const ACCRINTM = { return _redemption * _rate * yearFrac; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // AMORLINC @@ -313,7 +314,7 @@ export const AMORLINC = { return _salvage - valueAtPeriod < deprec ? deprec - (_salvage - valueAtPeriod) : 0; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUPDAYS @@ -364,7 +365,7 @@ export const COUPDAYS = { return daysInYear / _frequency; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUPDAYBS @@ -447,7 +448,7 @@ export const COUPDAYBS = { return (y2 - y1) * 360 + (m2 - m1) * 30 + (d2 - d1); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUPDAYSNC @@ -508,7 +509,7 @@ export const COUPDAYSNC = { return toNumber(coupDays, this.locale) - toNumber(coupDayBs, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUPNCD @@ -552,7 +553,7 @@ export const COUPNCD = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUPNUM @@ -595,7 +596,7 @@ export const COUPNUM = { return num - 1; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUPPCD @@ -635,7 +636,7 @@ export const COUPPCD = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CUMIPMT @@ -705,7 +706,7 @@ export const CUMIPMT = { return cumSum; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CUMPRINC @@ -775,7 +776,7 @@ export const CUMPRINC = { return cumSum; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DB @@ -849,7 +850,7 @@ export const DB = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DDB @@ -929,7 +930,7 @@ export const DDB = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DISC @@ -998,7 +999,7 @@ export const DISC = { return (_redemption - _price) / _redemption / yearsFrac; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DOLLARDE @@ -1031,7 +1032,7 @@ export const DOLLARDE = { return truncatedPrice + priceFractionalPart * frac; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DOLLARFR @@ -1061,7 +1062,7 @@ export const DOLLARFR = { return truncatedPrice + priceFractionalPart * frac; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DURATION @@ -1146,7 +1147,7 @@ export const DURATION = { return count === 0 ? 0 : sum / count; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // EFFECT @@ -1175,7 +1176,7 @@ export const EFFECT = { return Math.pow(1 + nominal / periods, periods) - 1; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FV @@ -1226,7 +1227,7 @@ export const FV = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FVSCHEDULE @@ -1249,7 +1250,7 @@ export const FVSCHEDULE = { ); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // INTRATE @@ -1314,7 +1315,7 @@ export const INTRATE = { return (_redemption - _investment) / _investment / yearFrac; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // IPMT @@ -1360,7 +1361,7 @@ export const IPMT = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // IRR @@ -1448,7 +1449,7 @@ export const IRR = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISPMT @@ -1480,7 +1481,7 @@ export const ISPMT = { return -1 * currentInvestment * interestRate; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MDURATION @@ -1531,7 +1532,7 @@ export const MDURATION = { return toNumber(duration, this.locale) / (1 + y / k); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MIRR @@ -1603,7 +1604,7 @@ export const MIRR = { return (-fv / pv) ** exponent - 1; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NOMINAL @@ -1632,7 +1633,7 @@ export const NOMINAL = { return (Math.pow(effective + 1, 1 / periods) - 1) * periods; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NPER @@ -1689,7 +1690,7 @@ export const NPER = { return Math.log((c - fv) / (pv + c)) / Math.log(1 + r); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NPV @@ -1731,7 +1732,7 @@ export const NPV = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PDURATION @@ -1765,7 +1766,7 @@ export const PDURATION = { return (Math.log(_futureValue) - Math.log(_presentValue)) / Math.log(1 + _rate); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PMT @@ -1822,7 +1823,7 @@ export const PMT = { return { value: pmt(r, n, pv, fv, t), format: "#,##0.00" }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PPMT @@ -1887,7 +1888,7 @@ export const PPMT = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PV @@ -1932,7 +1933,7 @@ export const PV = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PRICE @@ -2032,7 +2033,7 @@ export const PRICE = { ); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PRICEDISC @@ -2100,7 +2101,7 @@ export const PRICEDISC = { return _redemption - _discount * _redemption * yearsFrac; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PRICEMAT @@ -2199,7 +2200,7 @@ export const PRICEMAT = { return numerator / denominator - term2; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // RATE @@ -2278,7 +2279,7 @@ export const RATE = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // RECEIVED @@ -2351,7 +2352,7 @@ export const RECEIVED = { return _investment / (1 - _discount * yearsFrac); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // RRI @@ -2386,7 +2387,7 @@ export const RRI = { return (fv / pv) ** (1 / n) - 1; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SLN @@ -2416,7 +2417,7 @@ export const SLN = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SYD @@ -2471,7 +2472,7 @@ export const SYD = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TBILLPRICE @@ -2531,7 +2532,7 @@ export const TBILLPRICE = { return tBillPrice(start, end, disc); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TBILLEQ @@ -2615,7 +2616,7 @@ export const TBILLEQ = { return num / denom; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TBILLYIELD @@ -2671,7 +2672,7 @@ export const TBILLYIELD = { return ((100 - p) / p) * (1 / yearFrac); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VDB @@ -2789,7 +2790,7 @@ export const VDB = { return resultDeprec; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // XIRR @@ -2884,7 +2885,7 @@ export const XIRR = { return newtonMethod(func, derivFunc, guess, 40, 1e-5, nanFallback); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // XNPV @@ -2961,7 +2962,7 @@ export const XNPV = { return pv; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // YIELD @@ -3113,7 +3114,7 @@ export const YIELD = { return (methodResult - 1) * _frequency; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // YIELDDISC @@ -3179,7 +3180,7 @@ export const YIELDDISC = { return (_redemption / _price - 1) / yearFrac; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // YIELDMAT @@ -3251,4 +3252,4 @@ export const YIELDMAT = { return numerator / settlementToMaturity; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_info.ts b/src/functions/module_info.ts index 393d8ee29c..8ca86229b6 100644 --- a/src/functions/module_info.ts +++ b/src/functions/module_info.ts @@ -1,13 +1,8 @@ +import { FunctionResultObject, Functions, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; import { getFullReference, splitReference } from "../helpers"; import { setXcToFixedReferenceType } from "../helpers/reference_type"; import { _t } from "../translation"; -import { - AddFunctionDescription, - CellValueType, - FunctionResultObject, - Matrix, - Maybe, -} from "../types"; +import { CellValueType } from "../types"; import { CellErrorType, EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { isEvaluationError, toString } from "./helpers"; @@ -89,7 +84,7 @@ export const CELL = { return ""; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISERR @@ -102,7 +97,7 @@ export const ISERR = { return isEvaluationError(value) && value !== CellErrorType.NotAvailable; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISERROR @@ -115,7 +110,7 @@ export const ISERROR = { return isEvaluationError(value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISLOGICAL @@ -127,7 +122,7 @@ export const ISLOGICAL = { return typeof value?.value === "boolean"; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISNA @@ -139,7 +134,7 @@ export const ISNA = { return data?.value === CellErrorType.NotAvailable; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISNONTEXT @@ -151,7 +146,7 @@ export const ISNONTEXT = { return !ISTEXT.compute.bind(this)(value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISNUMBER @@ -164,7 +159,7 @@ export const ISNUMBER = { return typeof value?.value === "number"; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISTEXT @@ -176,7 +171,7 @@ export const ISTEXT = { return typeof value?.value === "string" && isEvaluationError(value?.value) === false; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISBLANK @@ -188,7 +183,7 @@ export const ISBLANK = { return value?.value === null; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NA @@ -200,4 +195,4 @@ export const NA = { return { value: CellErrorType.NotAvailable }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_logical.ts b/src/functions/module_logical.ts index d94af564bd..23221f4ab3 100644 --- a/src/functions/module_logical.ts +++ b/src/functions/module_logical.ts @@ -1,5 +1,5 @@ +import { Arg, FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { AddFunctionDescription, Arg, FunctionResultObject, Maybe } from "../types"; import { CellErrorType, EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { boolAnd, boolOr } from "./helper_logical"; @@ -38,12 +38,12 @@ export const AND = { return result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FALSE // ----------------------------------------------------------------------------- -export const FALSE: AddFunctionDescription = { +export const FALSE: Functions = { description: _t("Logical value `false`."), args: [], compute: function (): boolean { @@ -81,7 +81,7 @@ export const IF = { return result ?? { value: 0 }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // IFERROR @@ -103,7 +103,7 @@ export const IFERROR = { return result ?? { value: 0 }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // IFNA @@ -125,7 +125,7 @@ export const IFNA = { return result ?? { value: 0 }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // IFS @@ -168,7 +168,7 @@ export const IFS = { return new EvaluationError(_t("No match.")); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NOT @@ -187,7 +187,7 @@ export const NOT = { return !toBoolean(logicalExpression); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // OR @@ -214,7 +214,7 @@ export const OR = { return result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SWITCH @@ -261,12 +261,12 @@ export const SWITCH = { return defaultValue || { value: 0 }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TRUE // ----------------------------------------------------------------------------- -export const TRUE: AddFunctionDescription = { +export const TRUE: Functions = { description: _t("Logical value `true`."), args: [], compute: function (): boolean { @@ -306,4 +306,4 @@ export const XOR = { return acc; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_lookup.ts b/src/functions/module_lookup.ts index e6ed65c91b..9ccc4ed9e4 100644 --- a/src/functions/module_lookup.ts +++ b/src/functions/module_lookup.ts @@ -1,24 +1,16 @@ +import { + Arg, + FunctionResultObject, + Functions, + Matrix, + Maybe, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { getFullReference, splitReference, toXC, toZone } from "../helpers/index"; import { _t } from "../translation"; -import { AddFunctionDescription, Arg, FunctionResultObject, Matrix, Maybe, Zone } from "../types"; import { CellErrorType, EvaluationError, InvalidReferenceError } from "../types/errors"; import { arg } from "./arguments"; import { expectNumberGreaterThanOrEqualToOne } from "./helper_assert"; -import { - LinearSearchMode, - dichotomicSearch, - expectNumberRangeError, - generateMatrix, - isEvaluationError, - linearSearch, - strictToInteger, - toBoolean, - toMatrix, - toNumber, - toString, - valueNotAvailable, -} from "./helpers"; - const DEFAULT_IS_SORTED = true; const DEFAULT_MATCH_MODE = 0; const DEFAULT_SEARCH_MODE = 1; @@ -103,7 +95,7 @@ export const ADDRESS = { return cellReference; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COLUMN @@ -146,7 +138,7 @@ export const COLUMN = { return generateMatrix(cellReference.length, 1, (col, row) => ({ value: left + col + 1 })); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COLUMNS @@ -166,7 +158,7 @@ export const COLUMNS = { return _range.length; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // HLOOKUP @@ -231,12 +223,12 @@ export const HLOOKUP = { return col[_index - 1]; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // INDEX // ----------------------------------------------------------------------------- -export const INDEX: AddFunctionDescription = { +export const INDEX: Functions = { description: _t("Returns the content of a cell, specified by row and column offset."), args: [ arg("reference (any, range)", _t("The range of cells from which the values are returned.")), @@ -282,7 +274,7 @@ export const INDEX: AddFunctionDescription = { // ----------------------------------------------------------------------------- // INDIRECT // ----------------------------------------------------------------------------- -export const INDIRECT: AddFunctionDescription = { +export const INDIRECT: Functions = { description: _t("Returns the content of a cell, specified by a string."), args: [ arg("reference (string)", _t("The range of cells from which the values are returned.")), @@ -421,7 +413,7 @@ export const LOOKUP = { return _resultRange[0][index]; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MATCH @@ -497,7 +489,7 @@ export const MATCH = { return index + 1; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ROW @@ -540,7 +532,7 @@ export const ROW = { return generateMatrix(1, cellReference[0].length, (col, row) => ({ value: top + row + 1 })); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ROWS @@ -560,7 +552,7 @@ export const ROWS = { return _range[0].length; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VLOOKUP @@ -634,7 +626,7 @@ export const VLOOKUP = { return value; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // XLOOKUP @@ -764,7 +756,7 @@ export const XLOOKUP = { return [[defaultValue]]; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; //-------------------------------------------------------------------------- // OFFSET @@ -878,4 +870,4 @@ export const OFFSET = { }) ); }, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_math.ts b/src/functions/module_math.ts index c79d13cd4c..6bcb6f4d90 100644 --- a/src/functions/module_math.ts +++ b/src/functions/module_math.ts @@ -1,16 +1,15 @@ -import { splitReference, toZone } from "../helpers"; -import { isSubtotalCell } from "../plugins/ui_feature/subtotal_evaluation"; -import { _t } from "../translation"; import { - AddFunctionDescription, Arg, - EvaluatedCell, - FunctionResultNumber, FunctionResultObject, + Functions, + isMatrix, Matrix, Maybe, - isMatrix, -} from "../types"; +} from "@odoo/o-spreadsheet-engine"; +import { splitReference, toZone } from "../helpers"; +import { isSubtotalCell } from "../plugins/ui_feature/subtotal_evaluation"; +import { _t } from "../translation"; +import { EvaluatedCell, FunctionResultNumber } from "../types"; import { DivisionByZeroError, EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { assertNotZero } from "./helper_assert"; @@ -47,7 +46,7 @@ export const ABS = { return Math.abs(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ACOS @@ -70,7 +69,7 @@ export const ACOS = { return Math.acos(_value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ACOSH @@ -93,7 +92,7 @@ export const ACOSH = { return Math.acosh(_value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ACOT @@ -110,7 +109,7 @@ export const ACOT = { return (sign * Math.PI) / 2 - Math.atan(_value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ACOTH @@ -135,7 +134,7 @@ export const ACOTH = { return Math.log((_value + 1) / (_value - 1)) / 2; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ASIN @@ -156,7 +155,7 @@ export const ASIN = { return Math.asin(_value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ASINH @@ -170,7 +169,7 @@ export const ASINH = { return Math.asinh(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ATAN @@ -182,7 +181,7 @@ export const ATAN = { return Math.atan(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ATAN2 @@ -214,7 +213,7 @@ export const ATAN2 = { return Math.atan2(_y, _x); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ATANH @@ -237,7 +236,7 @@ export const ATANH = { return Math.atanh(_value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CEILING @@ -269,7 +268,7 @@ export const CEILING = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CEILING.MATH @@ -322,7 +321,7 @@ export const CEILING_MATH = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CEILING.PRECISE @@ -351,7 +350,7 @@ export const CEILING_PRECISE = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COS @@ -363,7 +362,7 @@ export const COS = { return Math.cos(toNumber(angle, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COSH @@ -375,7 +374,7 @@ export const COSH = { return Math.cosh(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COT @@ -393,7 +392,7 @@ export const COT = { return 1 / Math.tan(_angle); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COTH @@ -411,7 +410,7 @@ export const COTH = { return 1 / Math.tanh(_value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUNTBLANK @@ -447,7 +446,7 @@ export const COUNTBLANK = { ); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUNTIF @@ -470,7 +469,7 @@ export const COUNTIF = { return count; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUNTIFS @@ -500,7 +499,7 @@ export const COUNTIFS = { return count; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUNTUNIQUE @@ -518,7 +517,7 @@ export const COUNTUNIQUE = { compute: function (...args: Arg[]): number { return countUnique(args); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUNTUNIQUEIFS @@ -560,7 +559,7 @@ export const COUNTUNIQUEIFS = { ); return uniqueValues.size; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CSC @@ -578,7 +577,7 @@ export const CSC = { return 1 / Math.sin(_angle); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CSCH @@ -596,7 +595,7 @@ export const CSCH = { return 1 / Math.sinh(_value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DECIMAL @@ -640,7 +639,7 @@ export const DECIMAL = { return deci; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DEGREES @@ -652,7 +651,7 @@ export const DEGREES = { return (toNumber(angle, this.locale) * 180) / Math.PI; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // EXP @@ -664,7 +663,7 @@ export const EXP = { return Math.exp(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FLOOR @@ -695,7 +694,7 @@ export const FLOOR = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FLOOR.MATH @@ -749,7 +748,7 @@ export const FLOOR_MATH = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FLOOR.PRECISE @@ -778,7 +777,7 @@ export const FLOOR_PRECISE = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISEVEN @@ -792,7 +791,7 @@ export const ISEVEN = { return Math.floor(Math.abs(_value)) & 1 ? false : true; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISO.CEILING @@ -821,7 +820,7 @@ export const ISO_CEILING = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ISODD @@ -835,7 +834,7 @@ export const ISODD = { return Math.floor(Math.abs(_value)) & 1 ? true : false; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // LN @@ -851,7 +850,7 @@ export const LN = { return Math.log(_value); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // LOG @@ -880,7 +879,7 @@ export const LOG = { return Math.log10(_value) / Math.log10(_base); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MOD @@ -913,7 +912,7 @@ export const MOD = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MUNIT @@ -934,7 +933,7 @@ export const MUNIT = { return getUnitMatrix(_n); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ODD @@ -953,7 +952,7 @@ export const ODD = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PI @@ -965,7 +964,7 @@ export const PI = { return Math.PI; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // POWER @@ -987,7 +986,7 @@ export const POWER = { return { value: Math.pow(_base, _exponent), format: base?.format }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PRODUCT @@ -1032,7 +1031,7 @@ export const PRODUCT = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // RAND @@ -1044,7 +1043,7 @@ export const RAND = { return Math.random(); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // RANDARRAY @@ -1111,7 +1110,7 @@ export const RANDARRAY = { return result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // RANDBETWEEN @@ -1144,7 +1143,7 @@ export const RANDBETWEEN = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ROUND @@ -1181,7 +1180,7 @@ export const ROUND = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ROUNDDOWN @@ -1221,7 +1220,7 @@ export const ROUNDDOWN = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // ROUNDUP @@ -1258,7 +1257,7 @@ export const ROUNDUP = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SEC @@ -1270,7 +1269,7 @@ export const SEC = { return 1 / Math.cos(toNumber(angle, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SECH @@ -1282,7 +1281,7 @@ export const SECH = { return 1 / Math.cosh(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SEQUENCE @@ -1321,7 +1320,7 @@ export const SEQUENCE = { }); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SIN @@ -1333,7 +1332,7 @@ export const SIN = { return Math.sin(toNumber(angle, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SINH @@ -1345,7 +1344,7 @@ export const SINH = { return Math.sinh(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SQRT @@ -1361,7 +1360,7 @@ export const SQRT = { return { value: Math.sqrt(_value), format: value?.format }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUBTOTAL @@ -1453,7 +1452,7 @@ export const SUBTOTAL = { return this[subtotalFunctionAggregateByCode[code]].apply(this, [[evaluatedCellToKeep]]); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUM @@ -1475,7 +1474,7 @@ export const SUM = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUMIF @@ -1513,7 +1512,7 @@ export const SUMIF = { return sum; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUMIFS @@ -1542,7 +1541,7 @@ export const SUMIFS = { return sum; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TAN @@ -1554,7 +1553,7 @@ export const TAN = { return Math.tan(toNumber(angle, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TANH @@ -1566,7 +1565,7 @@ export const TANH = { return Math.tanh(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TRUNC @@ -1599,7 +1598,7 @@ export const TRUNC = { return { value: trunc(_value, _places), format: value?.format }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // INT @@ -1611,4 +1610,4 @@ export const INT = { return Math.floor(toNumber(value, this.locale)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_operators.ts b/src/functions/module_operators.ts index 1edc722b6e..da461efe1f 100644 --- a/src/functions/module_operators.ts +++ b/src/functions/module_operators.ts @@ -1,10 +1,6 @@ +import { FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { - AddFunctionDescription, - FunctionResultNumber, - FunctionResultObject, - Maybe, -} from "../types"; +import { FunctionResultNumber } from "../types"; import { DivisionByZeroError } from "../types/errors"; import { arg } from "./arguments"; import { isEvaluationError, toNumber, toString } from "./helpers"; @@ -28,7 +24,7 @@ export const ADD = { format: value1?.format || value2?.format, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CONCAT @@ -46,7 +42,7 @@ export const CONCAT = { return toString(value1) + toString(value2); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // DIVIDE @@ -67,7 +63,7 @@ export const DIVIDE = { format: dividend?.format || divisor?.format, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // EQ @@ -108,7 +104,7 @@ export const EQ = { } return { value: _value1 === _value2 }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // GT @@ -157,7 +153,7 @@ export const GT = { return v1 > v2; }); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // GTE @@ -179,7 +175,7 @@ export const GTE = { return v1 >= v2; }); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // LT @@ -197,7 +193,7 @@ export const LT = { } return { value: !result.value }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // LTE @@ -218,7 +214,7 @@ export const LTE = { } return { value: !result.value }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MINUS @@ -238,7 +234,7 @@ export const MINUS = { format: value1?.format || value2?.format, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MULTIPLY @@ -258,7 +254,7 @@ export const MULTIPLY = { format: factor1?.format || factor2?.format, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // NE @@ -276,7 +272,7 @@ export const NE = { } return { value: !result.value }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // POW @@ -290,7 +286,7 @@ export const POW = { compute: function (base: Maybe, exponent: Maybe) { return POWER.compute.bind(this)(base, exponent); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // UMINUS @@ -309,7 +305,7 @@ export const UMINUS = { format: value?.format, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // UNARY_PERCENT @@ -320,7 +316,7 @@ export const UNARY_PERCENT = { compute: function (percentage: Maybe): number { return toNumber(percentage, this.locale) / 100; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // UPLUS @@ -331,4 +327,4 @@ export const UPLUS = { compute: function (value: Maybe = { value: null }): FunctionResultObject { return value; }, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_parser.ts b/src/functions/module_parser.ts index d33c1502cb..fd4e1ccfee 100644 --- a/src/functions/module_parser.ts +++ b/src/functions/module_parser.ts @@ -1,5 +1,5 @@ +import { FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { AddFunctionDescription, FunctionResultObject, Maybe } from "../types"; import { CellErrorType } from "../types/errors"; import { arg } from "./arguments"; import { getTransformation, getTranslatedCategory, UNIT_OPTIONS } from "./helper_parser"; @@ -60,4 +60,4 @@ export const CONVERT = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_pivot.ts b/src/functions/module_pivot.ts index d401f43580..1cda17f3d7 100644 --- a/src/functions/module_pivot.ts +++ b/src/functions/module_pivot.ts @@ -1,15 +1,10 @@ +import { FunctionResultObject, Functions, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; import { getPivotTooBigErrorMessage } from "../components/translations_terms"; import { PIVOT_MAX_NUMBER_OF_CELLS } from "../constants"; import { range } from "../helpers/index"; import { addAlignFormatToPivotHeader } from "../helpers/pivot/pivot_helpers"; import { _t } from "../translation"; -import { - AddFunctionDescription, - FunctionResultObject, - Matrix, - Maybe, - PivotVisibilityOptions, -} from "../types"; +import { PivotVisibilityOptions } from "../types"; import { CellErrorType, EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { @@ -74,7 +69,7 @@ export const PIVOT_VALUE = { } return pivot.getPivotCellValueAndFormat(_measure, domain); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // PIVOT.HEADER @@ -127,7 +122,7 @@ export const PIVOT_HEADER = { : format, }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; export const PIVOT = { description: _t("Get a pivot table."), @@ -223,4 +218,4 @@ export const PIVOT = { } return result; }, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_statistical.ts b/src/functions/module_statistical.ts index a3f82d280f..5102142fd0 100644 --- a/src/functions/module_statistical.ts +++ b/src/functions/module_statistical.ts @@ -1,15 +1,14 @@ -import { percentile } from "../helpers/index"; -import { _t } from "../translation"; import { - AddFunctionDescription, Arg, - FunctionResultNumber, FunctionResultObject, - Locale, + Functions, + isMatrix, Matrix, Maybe, - isMatrix, -} from "../types"; +} from "@odoo/o-spreadsheet-engine"; +import { percentile } from "../helpers/index"; +import { _t } from "../translation"; +import { FunctionResultNumber, Locale } from "../types"; import { DivisionByZeroError, EvaluationError, NotAvailableError } from "../types/errors"; import { arg } from "./arguments"; import { areSameDimensions, assert, assertNotZero } from "./helper_assert"; @@ -237,7 +236,7 @@ export const AVEDEV = { return reduceNumbers(values, (acc, a) => acc + Math.abs(average - a), 0, this.locale) / count; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // AVERAGE @@ -261,7 +260,7 @@ export const AVERAGE = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // AVERAGE.WEIGHTED @@ -332,7 +331,7 @@ export const AVERAGE_WEIGHTED = { } return { value: sum / count, format: inferFormat(args[0]) }; }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // AVERAGEA @@ -371,7 +370,7 @@ export const AVERAGEA = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // AVERAGEIF @@ -416,7 +415,7 @@ export const AVERAGEIF = { return sum / count; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // AVERAGEIFS @@ -456,7 +455,7 @@ export const AVERAGEIFS = { return sum / count; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUNT @@ -477,7 +476,7 @@ export const COUNT = { return countNumbers(values, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COUNTA @@ -495,7 +494,7 @@ export const COUNTA = { return countAny(values); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COVAR @@ -516,7 +515,7 @@ export const COVAR = { return covariance(dataY, dataX, false); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COVARIANCE.P @@ -534,7 +533,7 @@ export const COVARIANCE_P = { return covariance(dataY, dataX, false); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // COVARIANCE.S @@ -552,12 +551,12 @@ export const COVARIANCE_S = { return covariance(dataY, dataX, true); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FORECAST // ----------------------------------------------------------------------------- -export const FORECAST: AddFunctionDescription = { +export const FORECAST: Functions = { description: _t( "Calculates the expected y-value for a specified x based on a linear regression of a dataset." ), @@ -595,7 +594,7 @@ export const FORECAST: AddFunctionDescription = { // ----------------------------------------------------------------------------- // GROWTH // ----------------------------------------------------------------------------- -export const GROWTH: AddFunctionDescription = { +export const GROWTH: Functions = { description: _t("Fits points to exponential growth trend."), args: [ arg( @@ -643,7 +642,7 @@ export const GROWTH: AddFunctionDescription = { // ----------------------------------------------------------------------------- // INTERCEPT // ----------------------------------------------------------------------------- -export const INTERCEPT: AddFunctionDescription = { +export const INTERCEPT: Functions = { description: _t("Compute the intercept of the linear regression."), args: [ arg( @@ -710,12 +709,12 @@ export const LARGE = { return result!; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // LINEST // ----------------------------------------------------------------------------- -export const LINEST: AddFunctionDescription = { +export const LINEST: Functions = { description: _t( "Given partial data about a linear trend, calculates various parameters about the ideal linear trend using the least-squares method." ), @@ -763,7 +762,7 @@ export const LINEST: AddFunctionDescription = { // ----------------------------------------------------------------------------- // LOGEST // ----------------------------------------------------------------------------- -export const LOGEST: AddFunctionDescription = { +export const LOGEST: Functions = { description: _t( "Given partial data about an exponential growth curve, calculates various parameters about the best fit ideal exponential growth curve." ), @@ -815,7 +814,7 @@ export const LOGEST: AddFunctionDescription = { // ----------------------------------------------------------------------------- // MATTHEWS // ----------------------------------------------------------------------------- -export const MATTHEWS: AddFunctionDescription = { +export const MATTHEWS: Functions = { description: _t("Compute the Matthews correlation coefficient of a dataset."), args: [ arg("data_x (range)", _t("The range representing the array or matrix of observed data.")), @@ -878,7 +877,7 @@ export const MAX = { return max(values, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MAXA @@ -907,7 +906,7 @@ export const MAXA = { return { value: maxa === -Infinity ? 0 : maxa, format: inferFormat(args[0]) }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MAXIFS @@ -946,7 +945,7 @@ export const MAXIFS = { return result === -Infinity ? 0 : result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MEDIAN @@ -978,7 +977,7 @@ export const MEDIAN = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MIN @@ -999,7 +998,7 @@ export const MIN = { return min(values, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MINA @@ -1028,7 +1027,7 @@ export const MINA = { return { value: mina === Infinity ? 0 : mina, format: inferFormat(args[0]) }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MINIFS @@ -1067,7 +1066,7 @@ export const MINIFS = { return result === Infinity ? 0 : result; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PEARSON @@ -1100,7 +1099,7 @@ function pearson(dataY: Matrix, dataX: Matrix)", _t("The value(s) on the x-axis to forecast.")), @@ -1291,7 +1290,7 @@ export const QUARTILE = { return QUARTILE_INC.compute.bind(this)(data, quartileNumber); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // QUARTILE.EXC @@ -1315,7 +1314,7 @@ export const QUARTILE_EXC = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // QUARTILE.INC @@ -1334,11 +1333,11 @@ export const QUARTILE_INC = { }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // RANK // ----------------------------------------------------------------------------- -export const RANK: AddFunctionDescription = { +export const RANK: Functions = { description: _t("Returns the rank of a specified value in a dataset."), args: [ arg("value (number)", _t("The value whose rank will be determined.")), @@ -1385,7 +1384,7 @@ export const RANK: AddFunctionDescription = { // ----------------------------------------------------------------------------- // RSQ // ----------------------------------------------------------------------------- -export const RSQ: AddFunctionDescription = { +export const RSQ: Functions = { description: _t( "Compute the square of r, the Pearson product-moment correlation coefficient of a dataset." ), @@ -1415,7 +1414,7 @@ export const RSQ: AddFunctionDescription = { // ----------------------------------------------------------------------------- // SLOPE // ----------------------------------------------------------------------------- -export const SLOPE: AddFunctionDescription = { +export const SLOPE: Functions = { description: _t("Compute the slope of the linear regression."), args: [ arg( @@ -1482,12 +1481,12 @@ export const SMALL = { return result!; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SPEARMAN // ----------------------------------------------------------------------------- -export const SPEARMAN: AddFunctionDescription = { +export const SPEARMAN: Functions = { description: _t("Compute the Spearman rank correlation coefficient of a dataset."), args: [ arg( @@ -1539,7 +1538,7 @@ export const STDEV = { return Math.sqrt(VAR.compute.bind(this)(...args)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // STDEV.P @@ -1557,7 +1556,7 @@ export const STDEV_P = { return Math.sqrt(VAR_P.compute.bind(this)(...args)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // STDEV.S @@ -1575,7 +1574,7 @@ export const STDEV_S = { return Math.sqrt(VAR_S.compute.bind(this)(...args)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // STDEVA @@ -1593,7 +1592,7 @@ export const STDEVA = { return Math.sqrt(VARA.compute.bind(this)(...args)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // STDEVP @@ -1611,7 +1610,7 @@ export const STDEVP = { return Math.sqrt(VARP.compute.bind(this)(...args)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // STDEVPA @@ -1629,12 +1628,12 @@ export const STDEVPA = { return Math.sqrt(VARPA.compute.bind(this)(...args)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // STEYX // ----------------------------------------------------------------------------- -export const STEYX: AddFunctionDescription = { +export const STEYX: Functions = { description: _t( "Calculates the standard error of the predicted y-value for each x in the regression of a dataset." ), @@ -1662,7 +1661,7 @@ export const STEYX: AddFunctionDescription = { // ----------------------------------------------------------------------------- // TREND // ----------------------------------------------------------------------------- -export const TREND: AddFunctionDescription = { +export const TREND: Functions = { description: _t("Fits points to linear trend derived via least-squares."), args: [ arg( @@ -1721,7 +1720,7 @@ export const VAR = { return variance(args, true, false, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VAR.P @@ -1739,7 +1738,7 @@ export const VAR_P = { return variance(args, false, false, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VAR.S @@ -1757,7 +1756,7 @@ export const VAR_S = { return variance(args, true, false, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VARA @@ -1775,7 +1774,7 @@ export const VARA = { return variance(args, true, true, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VARP @@ -1793,7 +1792,7 @@ export const VARP = { return variance(args, false, false, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VARPA @@ -1811,4 +1810,4 @@ export const VARPA = { return variance(args, false, true, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_text.ts b/src/functions/module_text.ts index 1ed156f524..8914945af8 100644 --- a/src/functions/module_text.ts +++ b/src/functions/module_text.ts @@ -1,6 +1,6 @@ +import { Arg, FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { escapeRegExp, formatValue, trimContent } from "../helpers"; import { _t } from "../translation"; -import { AddFunctionDescription, Arg, FunctionResultObject, Maybe } from "../types"; import { CellErrorType, EvaluationError, NotAvailableError } from "../types/errors"; import { arg } from "./arguments"; import { reduceAny, toBoolean, toMatrix, toNumber, toString, transposeMatrix } from "./helpers"; @@ -38,7 +38,7 @@ export const CHAR = { return String.fromCharCode(_tableNumber); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CLEAN @@ -57,7 +57,7 @@ export const CLEAN = { return cleanedStr; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // CONCATENATE @@ -72,7 +72,7 @@ export const CONCATENATE = { return reduceAny(datas, (acc, a) => acc + toString(a), ""); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // EXACT @@ -90,7 +90,7 @@ export const EXACT = { return toString(string1) === toString(string2); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // FIND @@ -141,7 +141,7 @@ export const FIND = { return result + 1; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // JOIN @@ -166,7 +166,7 @@ export const JOIN = { const _delimiter = toString(delimiter); return reduceAny(valuesOrArrays, (acc, a) => (acc ? acc + _delimiter : "") + toString(a), ""); }, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // LEFT @@ -191,7 +191,7 @@ export const LEFT = { return toString(text).substring(0, _numberOfCharacters); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // LEN @@ -203,7 +203,7 @@ export const LEN = { return toString(text).length; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // LOWER @@ -215,7 +215,7 @@ export const LOWER = { return toString(text).toLowerCase(); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // MID @@ -258,7 +258,7 @@ export const MID = { return _text.slice(_starting_at - 1, _starting_at + _extract_length - 1); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // PROPER @@ -280,7 +280,7 @@ export const PROPER = { }); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; const REGEXEXTRACT_DEFAULT_MODE = 0; const REGEXEXTRACT_DEFAULT_CASE_SENSITIVITY = 0; @@ -354,7 +354,7 @@ export const REGEXEXTRACT = { } }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // REPLACE @@ -389,7 +389,7 @@ export const REPLACE = { return _text.substring(0, _position - 1) + _newText + _text.substring(_position - 1 + _length); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // RIGHT @@ -415,7 +415,7 @@ export const RIGHT = { return _text.substring(stringLength - _numberOfCharacters, stringLength); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SEARCH @@ -468,7 +468,7 @@ export const SEARCH = { return { value: result + 1 }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SPLIT @@ -517,7 +517,7 @@ export const SPLIT = { return transposeMatrix([result]); }, isExported: false, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // SUBSTITUTE @@ -565,7 +565,7 @@ export const SUBSTITUTE = { return _textToSearch.replace(reg, (text) => (++n === _occurrenceNumber ? _replaceWith : text)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TEXTJOIN @@ -614,7 +614,7 @@ export const TEXTJOIN = { ); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TEXTSPLIT @@ -718,7 +718,7 @@ export const TEXTSPLIT = { return transposeMatrix(cells); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TRIM @@ -732,7 +732,7 @@ export const TRIM = { return trimContent(toString(text)); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // UPPER @@ -744,7 +744,7 @@ export const UPPER = { return toString(text).toUpperCase(); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TEXT @@ -768,7 +768,7 @@ export const TEXT = { return formatValue(_number, { format: toString(format), locale: this.locale }); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // VALUE @@ -780,7 +780,7 @@ export const VALUE = { return toNumber(value, this.locale); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TEXTAFTER @@ -862,7 +862,7 @@ export const TEXTAFTER = { return targetIndex === undefined ? ifNotFound : { value: _text.substring(targetIndex) }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; // ----------------------------------------------------------------------------- // TEXTBEFORE @@ -942,4 +942,4 @@ export const TEXTBEFORE = { : { value: _text.substring(0, targetIndex - _delimiter.length) }; }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/functions/module_web.ts b/src/functions/module_web.ts index 182ca9b0bc..507ae3223a 100644 --- a/src/functions/module_web.ts +++ b/src/functions/module_web.ts @@ -1,6 +1,6 @@ +import { FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { markdownLink } from "../helpers"; import { _t } from "../translation"; -import { AddFunctionDescription, FunctionResultObject, Maybe } from "../types"; import { arg } from "./arguments"; import { toString } from "./helpers"; @@ -26,4 +26,4 @@ export const HYPERLINK = { return markdownLink(processedLabel, processedUrl); }, isExported: true, -} satisfies AddFunctionDescription; +} satisfies Functions; diff --git a/src/helpers/cells/cell_evaluation.ts b/src/helpers/cells/cell_evaluation.ts index 3f4f3d5f0c..0686246461 100644 --- a/src/helpers/cells/cell_evaluation.ts +++ b/src/helpers/cells/cell_evaluation.ts @@ -1,15 +1,14 @@ +import { CellPosition, FunctionResultObject } from "@odoo/o-spreadsheet-engine"; import { isEvaluationError, toString } from "../../functions/helpers"; import { BooleanCell, Cell, - CellPosition, CellValue, CellValueType, DEFAULT_LOCALE, EmptyCell, ErrorCell, EvaluatedCell, - FunctionResultObject, LiteralCell, Locale, LocaleFormat, @@ -25,8 +24,6 @@ import { } from "../format/format"; import { detectLink } from "../links"; import { isBoolean, memoize } from "../misc"; -import { isNumber, parseNumber } from "../numbers"; - export function evaluateLiteral( literalCell: LiteralCell, localeFormat: LocaleFormat, diff --git a/src/helpers/cells/position_map.ts b/src/helpers/cells/position_map.ts index 190950f54a..a65753d121 100644 --- a/src/helpers/cells/position_map.ts +++ b/src/helpers/cells/position_map.ts @@ -1,4 +1,4 @@ -import { CellPosition, UID } from "../.."; +import { CellPosition, UID } from "@odoo/o-spreadsheet-engine"; export class PositionMap { private map: Record>> = {}; diff --git a/src/helpers/chart_date.ts b/src/helpers/chart_date.ts index a6cc36eb42..5b6f8a3946 100644 --- a/src/helpers/chart_date.ts +++ b/src/helpers/chart_date.ts @@ -1,7 +1,8 @@ +import { Alias } from "@odoo/o-spreadsheet-engine"; import type { TimeScaleOptions } from "chart.js"; import { DeepPartial } from "chart.js/dist/types/utils"; import { largeMax, largeMin, parseDateTime } from "."; -import { Alias, Format, Locale } from "../types"; +import { Format, Locale } from "../types"; // ----------------------------------------------------------------------------- // File for helpers needed to use time axis in ChartJS diff --git a/src/helpers/clipboard/clipboard_helpers.ts b/src/helpers/clipboard/clipboard_helpers.ts index 6d62158c48..a96ecabfb2 100644 --- a/src/helpers/clipboard/clipboard_helpers.ts +++ b/src/helpers/clipboard/clipboard_helpers.ts @@ -1,3 +1,4 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { ClipboardHandler } from "../../clipboard_handlers/abstract_clipboard_handler"; import { SpreadsheetClipboardData } from "../../plugins/ui_stateful"; import { SelectionStreamProcessor } from "../../selection_stream/selection_stream_processor"; @@ -9,8 +10,6 @@ import { MinimalClipboardData, OSClipboardContent, ParsedOSClipboardContent, - UID, - Zone, } from "../../types"; import { AllowedImageMimeTypes } from "../../types/image"; import { mergeOverlappingZones, positions, union } from "../zones"; diff --git a/src/helpers/color.ts b/src/helpers/color.ts index 9e0d43c08a..1f48957e20 100644 --- a/src/helpers/color.ts +++ b/src/helpers/color.ts @@ -1,5 +1,6 @@ -import { Color, HSLA, RGBA } from "../types"; +import { HSLA, RGBA } from "../types"; +import { Color } from "@odoo/o-spreadsheet-engine"; import { concat } from "./misc"; const RBA_REGEX = /rgba?\(|\s+|\)/gi; diff --git a/src/helpers/coordinates.ts b/src/helpers/coordinates.ts index 6829912cfc..6e6fc9c11a 100644 --- a/src/helpers/coordinates.ts +++ b/src/helpers/coordinates.ts @@ -2,7 +2,8 @@ // Coordinate //------------------------------------------------------------------------------ -import { HeaderIndex, Position, RangePart } from "../types"; +import { HeaderIndex, Position } from "@odoo/o-spreadsheet-engine"; +import { RangePart } from "../types"; import { TokenizingChars } from "./misc"; /** diff --git a/src/helpers/data_normalization.ts b/src/helpers/data_normalization.ts index 182e283dc2..2303d0801a 100644 --- a/src/helpers/data_normalization.ts +++ b/src/helpers/data_normalization.ts @@ -1,7 +1,5 @@ -import { Position, UID } from "../types"; +import { Position, UID } from "@odoo/o-spreadsheet-engine"; import { recomputeZones } from "./recompute_zones"; -import { positionToZone, toZone, zoneToXc } from "./zones"; - type ReverseLookup = Map; type ItemsDic = { [id: number]: T }; diff --git a/src/helpers/figures/charts/abstract_chart.ts b/src/helpers/figures/charts/abstract_chart.ts index 893a5bd7fa..14f4940ce1 100644 --- a/src/helpers/figures/charts/abstract_chart.ts +++ b/src/helpers/figures/charts/abstract_chart.ts @@ -1,13 +1,5 @@ -import { - AdaptSheetName, - ApplyRangeChange, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { AdaptSheetName, ApplyRangeChange, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { ChartCreationContext, ChartDefinition, diff --git a/src/helpers/figures/charts/bar_chart.ts b/src/helpers/figures/charts/bar_chart.ts index d757aa0163..27c9304411 100644 --- a/src/helpers/figures/charts/bar_chart.ts +++ b/src/helpers/figures/charts/bar_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { BarChartDefinition, BarChartRuntime } from "../../../types/chart/bar_chart"; import { AxesDesign, diff --git a/src/helpers/figures/charts/chart_common.ts b/src/helpers/figures/charts/chart_common.ts index 5663f06c37..23754c4022 100644 --- a/src/helpers/figures/charts/chart_common.ts +++ b/src/helpers/figures/charts/chart_common.ts @@ -1,8 +1,14 @@ -import { DEFAULT_WINDOW_SIZE, MAX_CHAR_LABEL } from "../../../constants"; -import { _t } from "../../../translation"; import { ApplyRangeChange, Color, + RangeAdapter, + UID, + UnboundedZone, + Zone, +} from "@odoo/o-spreadsheet-engine"; +import { DEFAULT_WINDOW_SIZE, MAX_CHAR_LABEL } from "../../../constants"; +import { _t } from "../../../translation"; +import { CommandResult, CoreGetters, DOMCoordinates, @@ -11,10 +17,6 @@ import { Locale, LocaleFormat, Range, - RangeAdapter, - UID, - UnboundedZone, - Zone, } from "../../../types"; import { ChartAxisFormats, diff --git a/src/helpers/figures/charts/chart_factory.ts b/src/helpers/figures/charts/chart_factory.ts index fcc71bdff7..7f8a3d33a3 100644 --- a/src/helpers/figures/charts/chart_factory.ts +++ b/src/helpers/figures/charts/chart_factory.ts @@ -1,6 +1,7 @@ +import { RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { chartRegistry } from "../../../registries/chart_types"; -import { CommandResult, RangeAdapter, UID } from "../../../types"; +import { CommandResult } from "../../../types"; import { ChartDefinition, ChartRuntime } from "../../../types/chart/chart"; import { CoreGetters, Getters } from "../../../types/getters"; import { Validator } from "../../../types/validator"; diff --git a/src/helpers/figures/charts/combo_chart.ts b/src/helpers/figures/charts/combo_chart.ts index e7598f1688..ee8570a2a8 100644 --- a/src/helpers/figures/charts/combo_chart.ts +++ b/src/helpers/figures/charts/combo_chart.ts @@ -1,17 +1,14 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; import { - ApplyRangeChange, ChartCreationContext, - Color, CommandResult, CoreGetters, DataSet, ExcelChartDefinition, Getters, Range, - RangeAdapter, - UID, } from "../../../types"; import { AxesDesign, CustomizedDataSet, LegendPosition } from "../../../types/chart"; import { diff --git a/src/helpers/figures/charts/funnel_chart.ts b/src/helpers/figures/charts/funnel_chart.ts index 3e70a0f1a7..dc694df61c 100644 --- a/src/helpers/figures/charts/funnel_chart.ts +++ b/src/helpers/figures/charts/funnel_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { FunnelChartColors, FunnelChartDefinition, diff --git a/src/helpers/figures/charts/gauge_chart.ts b/src/helpers/figures/charts/gauge_chart.ts index 8443733a5f..aa21b96a39 100644 --- a/src/helpers/figures/charts/gauge_chart.ts +++ b/src/helpers/figures/charts/gauge_chart.ts @@ -1,4 +1,3 @@ -import { BasePlugin } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_GAUGE_LOWER_COLOR, DEFAULT_GAUGE_MIDDLE_COLOR, @@ -7,17 +6,12 @@ import { import { isMultipleElementMatrix, toScalar } from "../../../functions/helper_matrices"; import { tryToNumber } from "../../../functions/helpers"; import { - AdaptSheetName, - ApplyRangeChange, CellValueType, - Color, CommandResult, CoreGetters, Format, Getters, Range, - RangeAdapter, - UID, Validation, } from "../../../types"; import { ChartCreationContext } from "../../../types/chart/chart"; diff --git a/src/helpers/figures/charts/gauge_chart_rendering.ts b/src/helpers/figures/charts/gauge_chart_rendering.ts index d71aa2d0a8..9b7310c1c7 100644 --- a/src/helpers/figures/charts/gauge_chart_rendering.ts +++ b/src/helpers/figures/charts/gauge_chart_rendering.ts @@ -1,10 +1,11 @@ +import { Color, PixelPosition } from "@odoo/o-spreadsheet-engine"; import { CHART_PADDING, CHART_PADDING_TOP, CHART_TITLE_FONT_SIZE, DEFAULT_FONT, } from "../../../constants"; -import { Color, PixelPosition, Rect } from "../../../types"; +import { Rect } from "../../../types"; import { GaugeAnimatedRuntime } from "../../../types/chart"; import { clip } from "../../misc"; import { @@ -13,8 +14,6 @@ import { getDefaultContextFont, getFontSizeMatchingWidth, } from "../../text_helper"; -import { chartMutedFontColor } from "./chart_common"; - export const GAUGE_PADDING_SIDE = 30; export const GAUGE_PADDING_TOP = 10; export const GAUGE_PADDING_BOTTOM = 20; diff --git a/src/helpers/figures/charts/geo_chart.ts b/src/helpers/figures/charts/geo_chart.ts index 7f988cb7e7..59c0e6b9e0 100644 --- a/src/helpers/figures/charts/geo_chart.ts +++ b/src/helpers/figures/charts/geo_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { LegendPosition } from "../../../types/chart"; import { ChartCreationContext, diff --git a/src/helpers/figures/charts/line_chart.ts b/src/helpers/figures/charts/line_chart.ts index cfda4a7ff9..7139027a18 100644 --- a/src/helpers/figures/charts/line_chart.ts +++ b/src/helpers/figures/charts/line_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { AxesDesign, ChartCreationContext, diff --git a/src/helpers/figures/charts/pie_chart.ts b/src/helpers/figures/charts/pie_chart.ts index f3d5bd27c3..faf5ba432a 100644 --- a/src/helpers/figures/charts/pie_chart.ts +++ b/src/helpers/figures/charts/pie_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { ChartCreationContext, DataSet, ExcelChartDefinition } from "../../../types/chart/chart"; import { LegendPosition } from "../../../types/chart/common_chart"; import { PieChartDefinition, PieChartRuntime } from "../../../types/chart/pie_chart"; diff --git a/src/helpers/figures/charts/pyramid_chart.ts b/src/helpers/figures/charts/pyramid_chart.ts index c4e7071b6f..f2e4d993af 100644 --- a/src/helpers/figures/charts/pyramid_chart.ts +++ b/src/helpers/figures/charts/pyramid_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { AxesDesign, ChartCreationContext, diff --git a/src/helpers/figures/charts/radar_chart.ts b/src/helpers/figures/charts/radar_chart.ts index 380036689b..96893d3c15 100644 --- a/src/helpers/figures/charts/radar_chart.ts +++ b/src/helpers/figures/charts/radar_chart.ts @@ -1,16 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - DatasetDesign, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, DatasetDesign, Getters, Range } from "../../../types"; import { ChartCreationContext, CustomizedDataSet, diff --git a/src/helpers/figures/charts/runtime/chart_data_extractor.ts b/src/helpers/figures/charts/runtime/chart_data_extractor.ts index 6ceacb27ef..67aef2417d 100644 --- a/src/helpers/figures/charts/runtime/chart_data_extractor.ts +++ b/src/helpers/figures/charts/runtime/chart_data_extractor.ts @@ -1,9 +1,9 @@ import { Point } from "chart.js"; import { ChartTerms } from "../../../../components/translations_terms"; +import { getMovingAverageValues } from "../../../../functions/get_moving_average_values"; import { evaluatePolynomial, expM, - getMovingAverageValues, logM, polynomialRegression, predictLinearValues, diff --git a/src/helpers/figures/charts/runtime/chartjs_dataset.ts b/src/helpers/figures/charts/runtime/chartjs_dataset.ts index 0090b54937..aa44d119cb 100644 --- a/src/helpers/figures/charts/runtime/chartjs_dataset.ts +++ b/src/helpers/figures/charts/runtime/chartjs_dataset.ts @@ -1,3 +1,4 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { ChartDataset, Point } from "chart.js"; import { BACKGROUND_CHART_COLOR, @@ -9,7 +10,7 @@ import { LINE_FILL_TRANSPARENCY, } from "../../../../constants"; import { _t } from "../../../../translation"; -import { ChartRuntimeGenerationArgs, Color, GenericDefinition } from "../../../../types"; +import { ChartRuntimeGenerationArgs, GenericDefinition } from "../../../../types"; import { BarChartDefinition, ChartWithDataSetDefinition, diff --git a/src/helpers/figures/charts/scatter_chart.ts b/src/helpers/figures/charts/scatter_chart.ts index 964e9e3035..4188f6c84b 100644 --- a/src/helpers/figures/charts/scatter_chart.ts +++ b/src/helpers/figures/charts/scatter_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { AxesDesign, ChartCreationContext, diff --git a/src/helpers/figures/charts/scorecard_chart.ts b/src/helpers/figures/charts/scorecard_chart.ts index ddce97f032..3a47e14889 100644 --- a/src/helpers/figures/charts/scorecard_chart.ts +++ b/src/helpers/figures/charts/scorecard_chart.ts @@ -1,3 +1,4 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { CHART_PADDING, DEFAULT_SCORECARD_BASELINE_COLOR_DOWN, @@ -6,17 +7,13 @@ import { } from "../../../constants"; import { toNumber } from "../../../functions/helpers"; import { - ApplyRangeChange, CellValueType, - Color, CommandResult, CoreGetters, EvaluatedCell, Getters, Locale, Range, - RangeAdapter, - UID, } from "../../../types"; import { ChartCreationContext, TitleDesign } from "../../../types/chart/chart"; import { diff --git a/src/helpers/figures/charts/scorecard_chart_config_builder.ts b/src/helpers/figures/charts/scorecard_chart_config_builder.ts index 9e3906e796..5dafe6ab2c 100644 --- a/src/helpers/figures/charts/scorecard_chart_config_builder.ts +++ b/src/helpers/figures/charts/scorecard_chart_config_builder.ts @@ -1,3 +1,4 @@ +import { Pixel, PixelPosition } from "@odoo/o-spreadsheet-engine"; import { Color } from "chart.js"; import { CHART_PADDING, @@ -6,7 +7,7 @@ import { DEFAULT_SCORECARD_KEY_VALUE_FONT_SIZE, SCORECARD_CHART_TITLE_FONT_SIZE, } from "../../../constants"; -import { DOMDimension, Pixel, PixelPosition } from "../../../types"; +import { DOMDimension } from "../../../types"; import { BaselineArrowDirection, ScorecardChartRuntime } from "../../../types/chart"; import { getDefaultContextFont } from "../../text_helper"; import { chartMutedFontColor } from "./chart_common"; diff --git a/src/helpers/figures/charts/smart_chart_engine.ts b/src/helpers/figures/charts/smart_chart_engine.ts index 940afd114b..e9dbf44f84 100644 --- a/src/helpers/figures/charts/smart_chart_engine.ts +++ b/src/helpers/figures/charts/smart_chart_engine.ts @@ -1,9 +1,10 @@ +import { Zone } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_SCORECARD_BASELINE_COLOR_DOWN, DEFAULT_SCORECARD_BASELINE_COLOR_UP, DEFAULT_SCORECARD_BASELINE_MODE, } from "../../../constants"; -import { CellValueType, ChartDefinition, EvaluatedCell, Getters, Zone } from "../../../types"; +import { CellValueType, ChartDefinition, EvaluatedCell, Getters } from "../../../types"; import { isDateTimeFormat } from "../../format/format"; import { recomputeZones } from "../../recompute_zones"; import { getZoneArea, getZonesByColumns, zoneToXc } from "../../zones"; diff --git a/src/helpers/figures/charts/sunburst_chart.ts b/src/helpers/figures/charts/sunburst_chart.ts index b5f36636da..83594539cd 100644 --- a/src/helpers/figures/charts/sunburst_chart.ts +++ b/src/helpers/figures/charts/sunburst_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration, ChartOptions } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { SunburstChartDefinition, SunburstChartRuntime } from "../../../types/chart"; import { ChartCreationContext, diff --git a/src/helpers/figures/charts/tree_map_chart.ts b/src/helpers/figures/charts/tree_map_chart.ts index 0d6d57f78c..b2f6f54c8c 100644 --- a/src/helpers/figures/charts/tree_map_chart.ts +++ b/src/helpers/figures/charts/tree_map_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { ChartCreationContext, CustomizedDataSet, diff --git a/src/helpers/figures/charts/waterfall_chart.ts b/src/helpers/figures/charts/waterfall_chart.ts index da567ad08c..526552e91a 100644 --- a/src/helpers/figures/charts/waterfall_chart.ts +++ b/src/helpers/figures/charts/waterfall_chart.ts @@ -1,15 +1,7 @@ +import { ApplyRangeChange, Color, RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration } from "chart.js"; import { BACKGROUND_CHART_COLOR } from "../../../constants"; -import { - ApplyRangeChange, - Color, - CommandResult, - CoreGetters, - Getters, - Range, - RangeAdapter, - UID, -} from "../../../types"; +import { CommandResult, CoreGetters, Getters, Range } from "../../../types"; import { AxesDesign, ChartCreationContext, diff --git a/src/helpers/format/format.ts b/src/helpers/format/format.ts index e17c64f7fa..5354a2cb04 100644 --- a/src/helpers/format/format.ts +++ b/src/helpers/format/format.ts @@ -1,15 +1,7 @@ +import { FunctionResultObject, Maybe } from "@odoo/o-spreadsheet-engine"; import { toNumber } from "../../functions/helpers"; import { _t } from "../../translation"; -import { - CellValue, - Currency, - Format, - FormattedValue, - FunctionResultObject, - Locale, - LocaleFormat, - Maybe, -} from "../../types"; +import { CellValue, Currency, Format, FormattedValue, Locale, LocaleFormat } from "../../types"; import { EvaluationError } from "../../types/errors"; import { DateTime, INITIAL_1900_DAY, isDateTime, numberToJsDate, parseDateTime } from "../dates"; import { diff --git a/src/helpers/formulas.ts b/src/helpers/formulas.ts index 6e67babbd2..e1f5c9b3f1 100644 --- a/src/helpers/formulas.ts +++ b/src/helpers/formulas.ts @@ -1,10 +1,8 @@ +import { RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { rangeTokenize } from "../formulas"; -import { Range, RangeAdapter, UID } from "../types"; +import { Range } from "../types"; import { concat } from "./misc"; import { createInvalidRange, createRangeFromXc, getRangeString } from "./range"; -import { rangeReference, splitReference } from "./references"; -import { isSheetNameEqual } from "./sheet"; - export function adaptFormulaStringRanges( defaultSheetId: string, formula: string, diff --git a/src/helpers/internal_viewport.ts b/src/helpers/internal_viewport.ts index f6b0455802..babdbcbdd8 100644 --- a/src/helpers/internal_viewport.ts +++ b/src/helpers/internal_viewport.ts @@ -1,16 +1,6 @@ +import { HeaderIndex, Pixel, Position, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { FOOTER_HEIGHT } from "../constants"; -import { - DOMCoordinates, - DOMDimension, - Dimension, - Getters, - HeaderIndex, - Pixel, - Position, - Rect, - UID, - Zone, -} from "../types"; +import { DOMCoordinates, DOMDimension, Dimension, Getters, Rect } from "../types"; import { intersection, isInside } from "./zones"; export class InternalViewport { diff --git a/src/helpers/misc.ts b/src/helpers/misc.ts index 5df1764927..d6aa37edf3 100644 --- a/src/helpers/misc.ts +++ b/src/helpers/misc.ts @@ -1,12 +1,10 @@ //------------------------------------------------------------------------------ // Miscellaneous //------------------------------------------------------------------------------ +import { ConsecutiveIndexes, Style, UID } from "@odoo/o-spreadsheet-engine"; import { escapeRegExp as engineEscapeRegExp } from "@odoo/o-spreadsheet-engine/helpers/misc"; import { FORBIDDEN_SHEETNAME_CHARS_IN_EXCEL_REGEX } from "../constants"; -import { ChartStyle, ConsecutiveIndexes, Lazy, UID } from "../types"; -import { SearchOptions } from "../types/find_and_replace"; -import { Cloneable, DebouncedFunction, Style } from "./../types/misc"; - +import { ChartStyle, Lazy } from "../types"; export { escapeRegExp, getCanonicalSymbolName, diff --git a/src/helpers/pivot/pivot_composer_helpers.ts b/src/helpers/pivot/pivot_composer_helpers.ts index fc1e1a0107..6bf3032613 100644 --- a/src/helpers/pivot/pivot_composer_helpers.ts +++ b/src/helpers/pivot/pivot_composer_helpers.ts @@ -1,6 +1,7 @@ +import { getFunctionsFromTokens } from "@odoo/o-spreadsheet-engine"; import { CellComposerStore } from "../../components/composer/composer/cell_composer_store"; import { tokenColors } from "../../constants"; -import { Token, getFunctionsFromTokens } from "../../formulas"; +import { Token } from "../../formulas"; import { EnrichedToken } from "../../formulas/composer_tokenizer"; import { Granularity, PivotField, PivotMeasure } from "../../types"; diff --git a/src/helpers/pivot/pivot_helpers.ts b/src/helpers/pivot/pivot_helpers.ts index 8a88e42b17..d4c34a59ba 100644 --- a/src/helpers/pivot/pivot_helpers.ts +++ b/src/helpers/pivot/pivot_helpers.ts @@ -1,3 +1,4 @@ +import { FunctionResultObject, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; import { boolAnd, boolOr } from "../../functions/helper_logical"; import { countUnique, sum } from "../../functions/helper_math"; import { average, countAny, max, min } from "../../functions/helper_statistical"; @@ -11,15 +12,7 @@ import { } from "../../functions/helpers"; import { Registry } from "../../registries/registry"; import { _t } from "../../translation"; -import { - CellValue, - DEFAULT_LOCALE, - FunctionResultObject, - Locale, - Matrix, - Maybe, - Pivot, -} from "../../types"; +import { CellValue, DEFAULT_LOCALE, Locale, Pivot } from "../../types"; import { EvaluationError } from "../../types/errors"; import { Granularity, @@ -35,8 +28,6 @@ import { } from "../../types/pivot"; import { getUniqueText, isDefined } from "../misc"; import { PivotRuntimeDefinition } from "./pivot_runtime_definition"; -import { pivotTimeAdapter } from "./pivot_time_adapter"; - const AGGREGATOR_NAMES = { count: _t("Count"), count_distinct: _t("Count Distinct"), diff --git a/src/helpers/pivot/pivot_highlight.ts b/src/helpers/pivot/pivot_highlight.ts index f1990798eb..ea090a4634 100644 --- a/src/helpers/pivot/pivot_highlight.ts +++ b/src/helpers/pivot/pivot_highlight.ts @@ -1,5 +1,6 @@ +import { CellPosition, Highlight, UID } from "@odoo/o-spreadsheet-engine"; import { HIGHLIGHT_COLOR } from "../../constants"; -import { CellPosition, Getters, Highlight, UID } from "../../types"; +import { Getters } from "../../types"; import { mergeContiguousZones, positionToZone } from "../zones"; export function getPivotHighlights(getters: Getters, pivotId: UID): Highlight[] { diff --git a/src/helpers/pivot/pivot_menu_items.ts b/src/helpers/pivot/pivot_menu_items.ts index a257a76e4a..1e9ba08219 100644 --- a/src/helpers/pivot/pivot_menu_items.ts +++ b/src/helpers/pivot/pivot_menu_items.ts @@ -1,5 +1,5 @@ +import { CellPosition } from "@odoo/o-spreadsheet-engine"; import { - CellPosition, CellValue, Getters, PivotCoreDefinition, diff --git a/src/helpers/pivot/pivot_presentation.ts b/src/helpers/pivot/pivot_presentation.ts index 0cdba373de..ce6dc00582 100644 --- a/src/helpers/pivot/pivot_presentation.ts +++ b/src/helpers/pivot/pivot_presentation.ts @@ -1,18 +1,16 @@ -import { handleError } from "../../functions"; +import { FunctionResultObject, handleError, isMatrix } from "@odoo/o-spreadsheet-engine"; import { transposeMatrix } from "../../functions/helpers"; import { ModelConfig } from "../../model"; import { _t } from "../../translation"; import { CellValue, DimensionTree, - FunctionResultObject, Getters, PivotDomain, PivotMeasure, PivotMeasureDisplay, PivotValueCell, SortDirection, - isMatrix, } from "../../types"; import { CellErrorType, NotAvailableError } from "../../types/errors"; import { deepEquals, removeDuplicates, transpose2dPOJO } from "../misc"; @@ -35,8 +33,6 @@ import { } from "./pivot_domain_helpers"; import { AGGREGATORS_FN, isSortedColumnValid, toNormalizedPivotValue } from "./pivot_helpers"; import { PivotParams, PivotUIConstructor } from "./pivot_registry"; -import { SpreadsheetPivotTable } from "./table_spreadsheet_pivot"; - const PERCENT_FORMAT = "0.00%"; type CacheForMeasureAndField = { [measureId: string]: { [field: string]: T } }; diff --git a/src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts b/src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts index d2ae0e7eb6..62324b0ee3 100644 --- a/src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts +++ b/src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts @@ -1,18 +1,8 @@ -import { handleError } from "../../../functions"; +import { FunctionResultObject, handleError, Maybe, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { toString } from "../../../functions/helpers"; import { ModelConfig } from "../../../model"; import { _t } from "../../../translation"; -import { - CellValueType, - EvaluatedCell, - FunctionResultObject, - Getters, - Maybe, - Range, - UID, - ValueAndLabel, - Zone, -} from "../../../types"; +import { CellValueType, EvaluatedCell, Getters, Range, ValueAndLabel } from "../../../types"; import { CellErrorType, EvaluationError } from "../../../types/errors"; import { Granularity, diff --git a/src/helpers/pivot/table_spreadsheet_pivot.ts b/src/helpers/pivot/table_spreadsheet_pivot.ts index 96b92b3251..0552189272 100644 --- a/src/helpers/pivot/table_spreadsheet_pivot.ts +++ b/src/helpers/pivot/table_spreadsheet_pivot.ts @@ -1,4 +1,5 @@ -import { FunctionResultObject, Lazy } from "../../types"; +import { FunctionResultObject } from "@odoo/o-spreadsheet-engine"; +import { Lazy } from "../../types"; import { DimensionTree, DimensionTreeNode, diff --git a/src/helpers/range.ts b/src/helpers/range.ts index 4d8d66750b..e4386335ea 100644 --- a/src/helpers/range.ts +++ b/src/helpers/range.ts @@ -1,23 +1,25 @@ -import { Registry } from "../registries/registry"; import { - AddColumnsRowsCommand, ApplyRangeChange, CellPosition, ChangeType, + RangeAdapter, + UID, + UnboundedZone, + ZoneDimension, +} from "@odoo/o-spreadsheet-engine"; +import { Registry } from "../registries/registry"; +import { + AddColumnsRowsCommand, CoreCommand, CoreCommandTypes, CoreGetters, DeleteSheetCommand, MoveRangeCommand, Range, - RangeAdapter, RangePart, RangeStringOptions, RemoveColumnsRowsCommand, RenameSheetCommand, - UID, - UnboundedZone, - ZoneDimension, } from "../types"; import { CellErrorType } from "../types/errors"; import { numberToLetters } from "./coordinates"; diff --git a/src/helpers/recompute_zones.ts b/src/helpers/recompute_zones.ts index 1760a2370e..7dbff44cc5 100644 --- a/src/helpers/recompute_zones.ts +++ b/src/helpers/recompute_zones.ts @@ -1,5 +1,5 @@ +import { UnboundedZone, Zone } from "@odoo/o-spreadsheet-engine"; import { deepEqualsArray } from "../helpers/misc"; -import { UnboundedZone, Zone } from "../types"; /** * #################################################### diff --git a/src/helpers/rectangle.ts b/src/helpers/rectangle.ts index bdd241db25..dea39d09e9 100644 --- a/src/helpers/rectangle.ts +++ b/src/helpers/rectangle.ts @@ -1,4 +1,5 @@ -import { Rect, Zone } from "../types"; +import { Zone } from "@odoo/o-spreadsheet-engine"; +import { Rect } from "../types"; import { intersection, union } from "./zones"; /** diff --git a/src/helpers/rendering.ts b/src/helpers/rendering.ts index 97f3804763..a0b970f78b 100644 --- a/src/helpers/rendering.ts +++ b/src/helpers/rendering.ts @@ -1,6 +1,7 @@ -import { GridRenderingContext, Highlight, Rect } from "../types"; +import { GridRenderingContext, Rect } from "../types"; import { toHex } from "./color"; +import { Highlight } from "@odoo/o-spreadsheet-engine"; import { HIGHLIGHT_COLOR } from "../constants"; import { setColorAlpha } from "./color"; diff --git a/src/helpers/sheet.ts b/src/helpers/sheet.ts index 9e42da224d..2763897c3a 100644 --- a/src/helpers/sheet.ts +++ b/src/helpers/sheet.ts @@ -1,7 +1,5 @@ +import { HeaderIndex, Row } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { HeaderIndex, Row } from "../types"; -import { getUnquotedSheetName, isDefined } from "./misc"; - export function createDefaultRows(rowNumber: number): Row[] { const rows: Row[] = []; for (let i = 0; i < rowNumber; i++) { diff --git a/src/helpers/sort.ts b/src/helpers/sort.ts index b39cfe93e4..9322cb15ce 100644 --- a/src/helpers/sort.ts +++ b/src/helpers/sort.ts @@ -1,15 +1,13 @@ +import { Position, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; import { CellValue, CellValueType, CommandResult, EvaluatedCell, - Position, SortDirection, SortOptions, SpreadsheetChildEnv, - UID, - Zone, } from "../types"; import { isEqual } from "./zones"; diff --git a/src/helpers/table_helpers.ts b/src/helpers/table_helpers.ts index be16815dc2..a23463f546 100644 --- a/src/helpers/table_helpers.ts +++ b/src/helpers/table_helpers.ts @@ -1,9 +1,7 @@ -import { Border, BorderDescr, CellPosition, Range, Style, UID, Zone } from "../types"; +import { Range } from "../types"; import { CoreTable, Filter, StaticTable, Table, TableConfig, TableStyle } from "../types/table"; -import { generateMatrix } from "../functions/helpers"; -import { ComputedTableStyle } from "./../types/table"; - +import { Border, BorderDescr, CellPosition, Style, UID, Zone } from "@odoo/o-spreadsheet-engine"; type TableElement = keyof Omit< TableStyle, "category" | "displayName" | "templateName" | "primaryColor" diff --git a/src/helpers/table_presets.ts b/src/helpers/table_presets.ts index 35702a841d..3454972ae1 100644 --- a/src/helpers/table_presets.ts +++ b/src/helpers/table_presets.ts @@ -1,6 +1,6 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { darkenColor, lightenColor } from "."; import { _t } from "../translation"; -import { Color } from "../types"; import { TableConfig, TableStyle, TableStyleTemplateName } from "../types/table"; export const TABLE_STYLE_CATEGORIES = { diff --git a/src/helpers/text_helper.ts b/src/helpers/text_helper.ts index cadc389e68..67981b0012 100644 --- a/src/helpers/text_helper.ts +++ b/src/helpers/text_helper.ts @@ -1,3 +1,4 @@ +import { Pixel, PixelPosition, Style } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT, DEFAULT_FONT, @@ -7,9 +8,7 @@ import { NEWLINE, PADDING_AUTORESIZE_VERTICAL, } from "../constants"; -import { Cell, Pixel, PixelPosition, Style } from "../types"; -import { isMarkdownLink, parseMarkdownLink } from "./misc"; - +import { Cell } from "../types"; export function computeTextLinesHeight(textLineHeight: number, numberOfLines: number = 1) { return numberOfLines * (textLineHeight + MIN_CELL_TEXT_MARGIN) - MIN_CELL_TEXT_MARGIN; } diff --git a/src/helpers/ui/freeze_interactive.ts b/src/helpers/ui/freeze_interactive.ts index ef24463e24..234fec569f 100644 --- a/src/helpers/ui/freeze_interactive.ts +++ b/src/helpers/ui/freeze_interactive.ts @@ -1,5 +1,6 @@ +import { HeaderIndex } from "@odoo/o-spreadsheet-engine"; import { MergeErrorMessage } from "../../components/translations_terms"; -import { CommandResult, Dimension, HeaderIndex, SpreadsheetChildEnv } from "../../types"; +import { CommandResult, Dimension, SpreadsheetChildEnv } from "../../types"; export function interactiveFreezeColumnsRows( env: SpreadsheetChildEnv, diff --git a/src/helpers/ui/merge_interactive.ts b/src/helpers/ui/merge_interactive.ts index 2e69e6ff86..a38a3585c8 100644 --- a/src/helpers/ui/merge_interactive.ts +++ b/src/helpers/ui/merge_interactive.ts @@ -1,6 +1,5 @@ +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; import { _t } from "../../translation"; -import { CommandResult, SpreadsheetChildEnv, UID, Zone } from "../../types"; - export const AddMergeInteractiveContent = { MergeIsDestructive: _t( "Merging these cells will only preserve the top-leftmost value. Merge anyway?" diff --git a/src/helpers/ui/paste_interactive.ts b/src/helpers/ui/paste_interactive.ts index ea2ad61991..cfb44dccfe 100644 --- a/src/helpers/ui/paste_interactive.ts +++ b/src/helpers/ui/paste_interactive.ts @@ -1,3 +1,4 @@ +import { Zone } from "@odoo/o-spreadsheet-engine"; import { RemoveDuplicateTerms } from "../../components/translations_terms"; import { getCurrentVersion } from "../../migrations/data"; import { _t } from "../../translation"; @@ -8,7 +9,6 @@ import { ParsedOSClipboardContent, ParsedOsClipboardContentWithImageData, SpreadsheetChildEnv, - Zone, } from "../../types"; export const PasteInteractiveContent = { diff --git a/src/helpers/ui/sheet_interactive.ts b/src/helpers/ui/sheet_interactive.ts index b1e892844e..cd95846c5c 100644 --- a/src/helpers/ui/sheet_interactive.ts +++ b/src/helpers/ui/sheet_interactive.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { FORBIDDEN_SHEETNAME_CHARS } from "../../constants"; import { _t } from "../../translation"; -import { CommandResult, SpreadsheetChildEnv, UID } from "../../types"; +import { CommandResult, SpreadsheetChildEnv } from "../../types"; export function interactiveRenameSheet( env: SpreadsheetChildEnv, diff --git a/src/helpers/ui/table_interactive.ts b/src/helpers/ui/table_interactive.ts index 8da9ec1603..7251767aab 100644 --- a/src/helpers/ui/table_interactive.ts +++ b/src/helpers/ui/table_interactive.ts @@ -1,5 +1,6 @@ -import { CommandResult, DispatchResult, SpreadsheetChildEnv, UID } from "../../types"; +import { CommandResult, DispatchResult, SpreadsheetChildEnv } from "../../types"; +import { UID } from "@odoo/o-spreadsheet-engine"; import { TableTerms } from "../../components/translations_terms"; import { TableConfig } from "../../types/table"; import { DEFAULT_TABLE_CONFIG } from "../table_presets"; diff --git a/src/helpers/ui/toggle_group_interactive.ts b/src/helpers/ui/toggle_group_interactive.ts index 7849fd7e22..525759cf3a 100644 --- a/src/helpers/ui/toggle_group_interactive.ts +++ b/src/helpers/ui/toggle_group_interactive.ts @@ -1,6 +1,5 @@ +import { HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; import { _t } from "../../translation"; -import { CommandResult, Dimension, HeaderIndex, SpreadsheetChildEnv, UID } from "../../types"; - export const ToggleGroupInteractiveContent = { CannotHideAllRows: _t("Cannot hide all the rows of a sheet."), CannotHideAllColumns: _t("Cannot hide all the columns of a sheet."), diff --git a/src/helpers/zones.ts b/src/helpers/zones.ts index a7c7765cbc..84c4f26025 100644 --- a/src/helpers/zones.ts +++ b/src/helpers/zones.ts @@ -6,7 +6,7 @@ import { UnboundedZone, Zone, ZoneDimension, -} from "../types"; +} from "@odoo/o-spreadsheet-engine"; import { MAX_COL, MAX_ROW, diff --git a/src/history/branch.ts b/src/history/branch.ts index 71c93b9211..224b25e547 100644 --- a/src/history/branch.ts +++ b/src/history/branch.ts @@ -1,4 +1,5 @@ -import { Transformation, TransformationFactory, UID } from "../types"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Transformation, TransformationFactory } from "../types"; import { Operation } from "./operation"; /** diff --git a/src/history/factory.ts b/src/history/factory.ts index 1fd4cf3a44..c34147789d 100644 --- a/src/history/factory.ts +++ b/src/history/factory.ts @@ -1,8 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { StateObserver } from "@odoo/o-spreadsheet-engine/state_observer"; import { transformAll } from "../collaborative/ot/ot"; import { Revision } from "../collaborative/revisions"; import { inverseCommand } from "../helpers/inverse_commands"; -import { CoreCommand, HistoryChange, UID } from "../types"; +import { CoreCommand, HistoryChange } from "../types"; import { SelectiveHistory } from "./selective_history"; export function buildRevisionLog(args: { diff --git a/src/history/operation.ts b/src/history/operation.ts index 26c1ec0e71..1e241f582b 100644 --- a/src/history/operation.ts +++ b/src/history/operation.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { lazy } from "../helpers"; -import { Lazy, Transformation, UID } from "../types"; +import { Lazy, Transformation } from "../types"; /** * An Operation can be executed to change a data structure from state A diff --git a/src/history/operation_sequence.ts b/src/history/operation_sequence.ts index 43392ad590..dbc950851f 100644 --- a/src/history/operation_sequence.ts +++ b/src/history/operation_sequence.ts @@ -1,4 +1,5 @@ -import { OperationSequenceNode, UID } from "../types"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { OperationSequenceNode } from "../types"; /** * An execution object is a sequence of executionSteps (each execution step is an operation in a branch). diff --git a/src/history/selective_history.ts b/src/history/selective_history.ts index ff149484ea..1a15e599d4 100644 --- a/src/history/selective_history.ts +++ b/src/history/selective_history.ts @@ -1,4 +1,5 @@ -import { TransformationFactory, UID } from "../types"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { TransformationFactory } from "../types"; import { Branch } from "./branch"; import { Operation } from "./operation"; import { OperationSequence } from "./operation_sequence"; diff --git a/src/history/tree.ts b/src/history/tree.ts index 8235bace3e..97bc216839 100644 --- a/src/history/tree.ts +++ b/src/history/tree.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { linkNext } from "../helpers"; -import { OperationSequenceNode, Transformation, TransformationFactory, UID } from "../types"; +import { OperationSequenceNode, Transformation, TransformationFactory } from "../types"; import { Branch } from "./branch"; import { Operation } from "./operation"; import { OperationSequence } from "./operation_sequence"; diff --git a/src/index.ts b/src/index.ts index 70fa63165e..08c85e58e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,9 +64,8 @@ import { PIVOT_TABLE_CONFIG, SCROLLBAR_WIDTH, } from "./constants"; -import { getFunctionsFromTokens } from "./formulas"; import { isEvaluationError, toBoolean, toJsDate, toNumber, toString } from "./functions/helpers"; -import { FunctionRegistry, arg, functionRegistry } from "./functions/index"; +import { FunctionRegistry, arg } from "./functions/index"; import { ColorGenerator, UuidGenerator, @@ -112,7 +111,7 @@ import { } from "./helpers/pivot/pivot_composer_helpers"; import { supportedPivotPositionalFormulaRegistry } from "./helpers/pivot/pivot_positional_formula_registry"; -import { CellComposerStore } from "./components/composer/composer/cell_composer_store"; +import { isMatrix } from "@odoo/o-spreadsheet-engine"; import { ClickableCellSortIcon } from "./components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon"; import { chartJsExtensionRegistry } from "./components/figures/chart/chartJs/chart_js_extension"; import { ZoomableChartJsComponent } from "./components/figures/chart/chartJs/zoomable_chart/zoomable_chartjs"; @@ -204,7 +203,6 @@ import { HighlightStore } from "./stores/highlight_store"; import { ModelStore } from "./stores/model_store"; import { NotificationStore } from "./stores/notification_store"; import { RendererStore } from "./stores/renderer_store"; -import { AddFunctionDescription, isMatrix } from "./types"; import { errorTypes } from "./types/errors"; import { DEFAULT_LOCALE } from "./types/locale"; diff --git a/src/migrations/data.ts b/src/migrations/data.ts index 8fea83ea14..99493efe90 100644 --- a/src/migrations/data.ts +++ b/src/migrations/data.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_REVISION_ID } from "../constants"; import { UuidGenerator, getDuplicateSheetName, getNextSheetName } from "../helpers/index"; import { isValidLocale } from "../helpers/locale"; @@ -8,7 +9,6 @@ import { ExcelSheetData, ExcelWorkbookData, SheetData, - UID, WorkbookData, } from "../types/index"; import { XlsxReader } from "../xlsx/xlsx_reader"; diff --git a/src/migrations/migration_steps.ts b/src/migrations/migration_steps.ts index f692e59add..f2b75aaae7 100644 --- a/src/migrations/migration_steps.ts +++ b/src/migrations/migration_steps.ts @@ -1,3 +1,4 @@ +import { Zone } from "@odoo/o-spreadsheet-engine"; import { BACKGROUND_CHART_COLOR, FORMULA_REF_IDENTIFIER } from "../constants"; import { getItemId, getUniqueText, sanitizeSheetName } from "../helpers"; import { toXC } from "../helpers/coordinates"; @@ -5,7 +6,7 @@ import { getMaxObjectId } from "../helpers/pivot/pivot_helpers"; import { DEFAULT_TABLE_CONFIG } from "../helpers/table_presets"; import { overlap, toZone, zoneToXc } from "../helpers/zones"; import { Registry } from "../registries/registry"; -import { CustomizedDataSet, DEFAULT_LOCALE, Format, WorkbookData, Zone } from "../types"; +import { CustomizedDataSet, DEFAULT_LOCALE, Format, WorkbookData } from "../types"; import { normalizeV9 } from "./legacy_tools"; import { WEEK_START } from "./locale"; diff --git a/src/model.ts b/src/model.ts index 67aff80617..c733abd12f 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1,5 +1,3 @@ -import { BasePlugin, StateObserver } from "@odoo/o-spreadsheet-engine"; -import { markRaw } from "@odoo/owl"; import { LocalTransportService } from "./collaborative/local_transport_service"; import { ReadonlyTransportFilter } from "./collaborative/readonly_transport_filter"; import { Session } from "./collaborative/session"; @@ -34,7 +32,6 @@ import { FileStore } from "./types/files"; import { Client, ClientPosition, - Color, Command, CommandDispatcher, CommandHandler, @@ -52,7 +49,6 @@ import { LayerName, LocalCommand, Locale, - UID, canExecuteInReadonly, isCoreCommand, } from "./types/index"; diff --git a/src/plugins/core/borders.ts b/src/plugins/core/borders.ts index d9e32a1710..395ab9f3ae 100644 --- a/src/plugins/core/borders.ts +++ b/src/plugins/core/borders.ts @@ -1,3 +1,15 @@ +import { + ApplyRangeChange, + Border, + BorderData, + BorderDescr, + CellPosition, + Color, + HeaderIndex, + UID, + UnboundedZone, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { PositionMap } from "../../helpers/cells/position_map"; import { deepCopy, @@ -11,22 +23,12 @@ import { } from "../../helpers/index"; import { adjacent, overlap, splitIfAdjacent, zoneToXc } from "../../helpers/zones"; import { - ApplyRangeChange, - Border, - BorderData, - BorderDescr, - CellPosition, - Color, CommandResult, CoreCommand, ExcelWorkbookData, - HeaderIndex, SetBorderCommand, SetZoneBordersCommand, - UID, - UnboundedZone, WorkbookData, - Zone, } from "../../types/index"; import { CorePlugin } from "../core_plugin"; diff --git a/src/plugins/core/carousel.ts b/src/plugins/core/carousel.ts index 4acd4e7984..de1efe6f0d 100644 --- a/src/plugins/core/carousel.ts +++ b/src/plugins/core/carousel.ts @@ -1,10 +1,10 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { FIGURE_ID_SPLITTER } from "../../constants"; import { Carousel, CarouselItem, CommandResult, CoreCommand, - UID, UpdateCarouselCommand, WorkbookData, } from "../../types/index"; diff --git a/src/plugins/core/cell.ts b/src/plugins/core/cell.ts index 3554768026..abb48dbfaa 100644 --- a/src/plugins/core/cell.ts +++ b/src/plugins/core/cell.ts @@ -1,3 +1,15 @@ +import { + AdaptSheetName, + ApplyRangeChange, + CellPosition, + CompiledFormula, + HeaderIndex, + RangeCompiledFormula, + Style, + UID, + UpdateCellData, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { DEFAULT_STYLE } from "../../constants"; import { Token, compile } from "../../formulas"; import { compileTokens } from "../../formulas/compiler"; @@ -21,30 +33,20 @@ import { toXC, } from "../../helpers/index"; import { - AdaptSheetName, AddColumnsRowsCommand, - ApplyRangeChange, Cell, - CellPosition, ClearCellCommand, CommandResult, - CompiledFormula, CoreCommand, ExcelWorkbookData, Format, FormulaCell, - HeaderIndex, LiteralCell, PositionDependentCommand, Range, - RangeCompiledFormula, RangePart, - Style, - UID, UpdateCellCommand, - UpdateCellData, WorkbookData, - Zone, } from "../../types/index"; import { CorePlugin } from "../core_plugin"; diff --git a/src/plugins/core/chart.ts b/src/plugins/core/chart.ts index 48cc8380af..054b635e75 100644 --- a/src/plugins/core/chart.ts +++ b/src/plugins/core/chart.ts @@ -1,26 +1,15 @@ -import { DEFAULT_FIGURE_HEIGHT, DEFAULT_FIGURE_WIDTH, FIGURE_ID_SPLITTER } from "../../constants"; -import { deepEquals } from "../../helpers"; -import { AbstractChart } from "../../helpers/figures/charts/abstract_chart"; -import { chartFactory, validateChartDefinition } from "../../helpers/figures/charts/chart_factory"; -import { ChartCreationContext, ChartDefinition, ChartType } from "../../types/chart/chart"; import { AdaptSheetName, ApplyRangeChange, - Command, - CommandResult, - CoreCommand, - CreateChartCommand, - DeleteChartCommand, - DOMDimension, - FigureData, HeaderIndex, PixelPosition, UID, - UpdateChartCommand, - WorkbookData, -} from "../../types/index"; -import { CorePlugin } from "../core_plugin"; - +} from "@odoo/o-spreadsheet-engine"; +import { DEFAULT_FIGURE_HEIGHT, DEFAULT_FIGURE_WIDTH, FIGURE_ID_SPLITTER } from "../../constants"; +import { deepEquals } from "../../helpers"; +import { AbstractChart } from "../../helpers/figures/charts/abstract_chart"; +import { chartFactory, validateChartDefinition } from "../../helpers/figures/charts/chart_factory"; +import { ChartCreationContext, ChartDefinition, ChartType } from "../../types/chart/chart"; interface FigureChart { figureId: UID; chart: AbstractChart; diff --git a/src/plugins/core/conditional_format.ts b/src/plugins/core/conditional_format.ts index 1b17925c17..abac001716 100644 --- a/src/plugins/core/conditional_format.ts +++ b/src/plugins/core/conditional_format.ts @@ -1,9 +1,9 @@ +import { ApplyRangeChange, UID, UnboundedZone, Zone } from "@odoo/o-spreadsheet-engine"; import { compile } from "../../formulas/compiler"; import { deepEquals, isInside, recomputeZones, toUnboundedZone } from "../../helpers/index"; import { criterionEvaluatorRegistry } from "../../registries/criterion_registry"; import { AddConditionalFormatCommand, - ApplyRangeChange, CancelledReason, CellIsRule, ColorScaleMidPointThreshold, @@ -18,11 +18,8 @@ import { IconSetRule, IconThreshold, RangeData, - UID, - UnboundedZone, Validation, WorkbookData, - Zone, } from "../../types"; import { CorePlugin } from "../core_plugin"; diff --git a/src/plugins/core/data_validation.ts b/src/plugins/core/data_validation.ts index c00700b373..f4974afa69 100644 --- a/src/plugins/core/data_validation.ts +++ b/src/plugins/core/data_validation.ts @@ -1,3 +1,4 @@ +import { ApplyRangeChange, CellPosition, Style, UID } from "@odoo/o-spreadsheet-engine"; import { compile } from "../../formulas"; import { deepCopy, @@ -8,21 +9,7 @@ import { toXC, } from "../../helpers"; import { criterionEvaluatorRegistry } from "../../registries/criterion_registry"; -import { - AddDataValidationCommand, - ApplyRangeChange, - CellPosition, - Command, - CommandResult, - CoreCommand, - DataValidationRule, - ExcelWorkbookData, - Range, - Style, - UID, - WorkbookData, -} from "../../types"; -import { CorePlugin } from "../core_plugin"; +import { DataValidationRule } from "../../types"; interface DataValidationState { readonly rules: { [sheet: string]: DataValidationRule[] }; diff --git a/src/plugins/core/figures.ts b/src/plugins/core/figures.ts index 9a2f4f3595..64d4704892 100644 --- a/src/plugins/core/figures.ts +++ b/src/plugins/core/figures.ts @@ -1,21 +1,8 @@ +import { ApplyRangeChange, HeaderIndex, PixelPosition, UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT, FIGURE_ID_SPLITTER } from "../../constants"; import { clip } from "../../helpers/index"; import { AnchorOffset } from "../../types/figure"; -import { - ApplyRangeChange, - CommandResult, - CoreCommand, - CreateFigureCommand, - DeleteFigureCommand, - ExcelWorkbookData, - Figure, - HeaderIndex, - PixelPosition, - UID, - UpdateFigureCommand, - WorkbookData, -} from "../../types/index"; -import { CorePlugin } from "../core_plugin"; +import { Figure } from "../../types/index"; interface FigureState { readonly figures: { [sheet: string]: Record | undefined }; diff --git a/src/plugins/core/header_grouping.ts b/src/plugins/core/header_grouping.ts index 6e6d79a862..de1872300c 100644 --- a/src/plugins/core/header_grouping.ts +++ b/src/plugins/core/header_grouping.ts @@ -1,3 +1,4 @@ +import { HeaderGroup, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { deepCopy, getAddHeaderStartIndex, @@ -6,10 +7,9 @@ import { moveHeaderIndexesOnHeaderDeletion, range, } from "../../helpers"; -import { CommandResult, CoreCommand, ExcelWorkbookData, UID, WorkbookData } from "../../types"; +import { CommandResult, CoreCommand, ExcelWorkbookData, WorkbookData } from "../../types"; import { getSheetDataHeader } from "../../xlsx/helpers/misc"; -import { Dimension, HeaderGroup, HeaderIndex, Zone } from "./../../types/misc"; -import { CorePlugin } from "./../core_plugin"; +import { Dimension } from "./../../types/misc"; interface State { groups: Record>; diff --git a/src/plugins/core/header_size.ts b/src/plugins/core/header_size.ts index 48e9aa4b3d..ec3379d6a0 100644 --- a/src/plugins/core/header_size.ts +++ b/src/plugins/core/header_size.ts @@ -1,8 +1,8 @@ +import { HeaderIndex, Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../constants"; import { deepCopy, getAddHeaderStartIndex, range, removeIndexesFromArray } from "../../helpers"; import { Command, ExcelWorkbookData, WorkbookData } from "../../types"; -import { Dimension, HeaderIndex, Pixel, UID } from "../../types/misc"; -import { CorePlugin } from "../core_plugin"; +import { Dimension } from "../../types/misc"; interface HeaderSizeState { sizes: Record>>; diff --git a/src/plugins/core/header_visibility.ts b/src/plugins/core/header_visibility.ts index 967a6b29b4..55a15240bd 100644 --- a/src/plugins/core/header_visibility.ts +++ b/src/plugins/core/header_visibility.ts @@ -1,3 +1,4 @@ +import { ConsecutiveIndexes, HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; import { deepCopy, getAddHeaderStartIndex, @@ -7,7 +8,7 @@ import { range, } from "../../helpers"; import { Command, CommandResult, ExcelWorkbookData, WorkbookData } from "../../types"; -import { ConsecutiveIndexes, Dimension, HeaderIndex, UID } from "../../types/misc"; +import { Dimension } from "../../types/misc"; import { CorePlugin } from "../core_plugin"; export class HeaderVisibilityPlugin extends CorePlugin { diff --git a/src/plugins/core/image.ts b/src/plugins/core/image.ts index 76802ae1f0..447b5147c8 100644 --- a/src/plugins/core/image.ts +++ b/src/plugins/core/image.ts @@ -1,3 +1,4 @@ +import { HeaderIndex, PixelPosition, UID } from "@odoo/o-spreadsheet-engine"; import { FIGURE_ID_SPLITTER } from "../../constants"; import { deepCopy, isDefined } from "../../helpers"; import { FileStore } from "../../types/files"; @@ -9,13 +10,8 @@ import { ExcelWorkbookData, FigureData, FigureSize, - HeaderIndex, - PixelPosition, - UID, WorkbookData, } from "../../types/index"; -import { CorePlugin, CorePluginConfig } from "../core_plugin"; - interface ImageState { readonly images: Record | undefined>; } diff --git a/src/plugins/core/merge.ts b/src/plugins/core/merge.ts index 17b4381db1..16f4dc310e 100644 --- a/src/plugins/core/merge.ts +++ b/src/plugins/core/merge.ts @@ -1,3 +1,11 @@ +import { + ApplyRangeChange, + CellPosition, + HeaderIndex, + Merge, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { clip, createRange, @@ -19,19 +27,13 @@ import { } from "../../helpers/index"; import { AddMergeCommand, - ApplyRangeChange, - CellPosition, CommandResult, CoreCommand, ExcelWorkbookData, - HeaderIndex, - Merge, Range, TargetDependentCommand, - UID, UpdateCellCommand, WorkbookData, - Zone, } from "../../types/index"; import { CorePlugin } from "../core_plugin"; diff --git a/src/plugins/core/pivot.ts b/src/plugins/core/pivot.ts index fe7540f914..28b7463ddf 100644 --- a/src/plugins/core/pivot.ts +++ b/src/plugins/core/pivot.ts @@ -1,21 +1,16 @@ -import { compile } from "../../formulas"; -import { deepCopy, deepEquals } from "../../helpers"; -import { createPivotFormula, getMaxObjectId } from "../../helpers/pivot/pivot_helpers"; -import { SpreadsheetPivotTable } from "../../helpers/pivot/table_spreadsheet_pivot"; import { ApplyRangeChange, CellPosition, - CellValue, - CommandResult, - CoreCommand, Position, - Range, RangeCompiledFormula, UID, - WorkbookData, -} from "../../types"; -import { PivotCoreDefinition, PivotCoreMeasure } from "../../types/pivot"; -import { CorePlugin } from "../core_plugin"; +} from "@odoo/o-spreadsheet-engine"; +import { compile } from "../../formulas"; +import { deepCopy, deepEquals } from "../../helpers"; +import { createPivotFormula, getMaxObjectId } from "../../helpers/pivot/pivot_helpers"; +import { SpreadsheetPivotTable } from "../../helpers/pivot/table_spreadsheet_pivot"; +import { CellValue, CommandResult, CoreCommand, Range, WorkbookData } from "../../types"; +import { PivotCoreDefinition } from "../../types/pivot"; interface Pivot { definition: PivotCoreDefinition; diff --git a/src/plugins/core/range.ts b/src/plugins/core/range.ts index ff99651910..00797aaaa9 100644 --- a/src/plugins/core/range.ts +++ b/src/plugins/core/range.ts @@ -1,3 +1,12 @@ +import { + AdaptSheetName, + ApplyRangeChange, + ApplyRangeChangeResult, + RangeProvider, + UID, + UnboundedZone, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { compile } from "../../formulas"; import { createInvalidRange, @@ -17,9 +26,6 @@ import { } from "../../helpers/index"; import { CellErrorType } from "../../types/errors"; import { - AdaptSheetName, - ApplyRangeChange, - ApplyRangeChangeResult, Command, CommandHandler, CommandResult, @@ -28,11 +34,7 @@ import { Dimension, Range, RangeData, - RangeProvider, RangeStringOptions, - UID, - UnboundedZone, - Zone, } from "../../types/index"; export class RangeAdapter implements CommandHandler { diff --git a/src/plugins/core/sheet.ts b/src/plugins/core/sheet.ts index f69110bb9b..0af06edcf7 100644 --- a/src/plugins/core/sheet.ts +++ b/src/plugins/core/sheet.ts @@ -1,3 +1,14 @@ +import { + CellPosition, + HeaderIndex, + PaneDivision, + Row, + Sheet, + UID, + UnboundedZone, + Zone, + ZoneDimension, +} from "@odoo/o-spreadsheet-engine"; import { FORBIDDEN_SHEETNAME_CHARS_IN_EXCEL_REGEX } from "../../constants"; import { createDefaultRows, @@ -19,7 +30,6 @@ import { import { isSheetNameEqual } from "../../helpers/sheet"; import { Cell, - CellPosition, Command, CommandResult, CoreCommand, @@ -28,18 +38,10 @@ import { ExcelWorkbookData, FreezeColumnsCommand, FreezeRowsCommand, - HeaderIndex, - PaneDivision, RenameSheetCommand, - Row, - Sheet, SheetData, - UID, - UnboundedZone, UpdateCellPositionCommand, WorkbookData, - Zone, - ZoneDimension, } from "../../types/index"; import { CorePlugin } from "../core_plugin"; diff --git a/src/plugins/core/spreadsheet_pivot.ts b/src/plugins/core/spreadsheet_pivot.ts index 3e10620375..0b1cf3ca1d 100644 --- a/src/plugins/core/spreadsheet_pivot.ts +++ b/src/plugins/core/spreadsheet_pivot.ts @@ -1,11 +1,6 @@ +import { ApplyRangeChange } from "@odoo/o-spreadsheet-engine"; import { isZoneValid } from "../../helpers"; -import { - ApplyRangeChange, - CommandResult, - CoreCommand, - PivotCoreDefinition, - Range, -} from "../../types"; +import { CommandResult, CoreCommand, PivotCoreDefinition, Range } from "../../types"; import { CorePlugin } from "../core_plugin"; function adaptPivotRange( diff --git a/src/plugins/core/tables.ts b/src/plugins/core/tables.ts index 4d79d7b847..6e789c1df6 100644 --- a/src/plugins/core/tables.ts +++ b/src/plugins/core/tables.ts @@ -16,8 +16,6 @@ import { import { createFilter } from "../../helpers/table_helpers"; import { DEFAULT_TABLE_CONFIG } from "../../helpers/table_presets"; import { - ApplyRangeChange, - CellPosition, CommandResult, CoreCommand, CoreTable, @@ -30,14 +28,12 @@ import { Table, TableConfig, TableData, - TableId, - UID, UpdateCellCommand, UpdateTableCommand, WorkbookData, - Zone, } from "../../types/index"; +import { ApplyRangeChange, CellPosition, TableId, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { CorePlugin } from "../core_plugin"; interface TableState { diff --git a/src/plugins/core_plugin.ts b/src/plugins/core_plugin.ts index 6d870f29cd..3950b21e70 100644 --- a/src/plugins/core_plugin.ts +++ b/src/plugins/core_plugin.ts @@ -1,15 +1,9 @@ -import { BasePlugin, StateObserver } from "@odoo/o-spreadsheet-engine"; -import { ModelConfig } from "../model"; import { - AdaptSheetName, - ApplyRangeChange, CommandResult, CoreCommand, CoreCommandDispatcher, ExcelWorkbookData, HistoryChange, - RangeProvider, - UID, WorkbookData, } from "../types"; import { CoreGetters } from "../types/getters"; diff --git a/src/plugins/core_view_plugin.ts b/src/plugins/core_view_plugin.ts index 3797b19721..c6761df698 100644 --- a/src/plugins/core_view_plugin.ts +++ b/src/plugins/core_view_plugin.ts @@ -1,10 +1,7 @@ -import { BasePlugin, StateObserver } from "@odoo/o-spreadsheet-engine"; -import { Session } from "../collaborative/session"; import { ModelConfig } from "../model"; import { SelectionStreamProcessor } from "../selection_stream/selection_stream_processor"; import { ClientPosition, - Color, Command, CommandResult, CoreCommand, diff --git a/src/plugins/ui_core_views/cell_evaluation/binary_grid.ts b/src/plugins/ui_core_views/cell_evaluation/binary_grid.ts index c4a6804e13..e608e17b85 100644 --- a/src/plugins/ui_core_views/cell_evaluation/binary_grid.ts +++ b/src/plugins/ui_core_views/cell_evaluation/binary_grid.ts @@ -1,4 +1,4 @@ -import { CellPosition } from "../../../types"; +import { CellPosition } from "@odoo/o-spreadsheet-engine"; type Bit = 0 | 1; diff --git a/src/plugins/ui_core_views/cell_evaluation/compilation_parameters.ts b/src/plugins/ui_core_views/cell_evaluation/compilation_parameters.ts index 74092dcf19..49b71e4b78 100644 --- a/src/plugins/ui_core_views/cell_evaluation/compilation_parameters.ts +++ b/src/plugins/ui_core_views/cell_evaluation/compilation_parameters.ts @@ -1,20 +1,7 @@ -import { functionRegistry } from "../../../functions"; import { getFullReference, intersection, isZoneValid, toXC, zoneToXc } from "../../../helpers"; import { ModelConfig } from "../../../model"; import { _t } from "../../../translation"; -import { - CellPosition, - EnsureRange, - EvalContext, - EvaluatedCell, - FunctionResultObject, - Getters, - Matrix, - Range, - ReferenceDenormalizer, -} from "../../../types"; -import { EvaluationError, InvalidReferenceError } from "../../../types/errors"; - +import { EvaluatedCell, Getters, Range } from "../../../types"; export type CompilationParameters = { referenceDenormalizer: ReferenceDenormalizer; ensureRange: EnsureRange; diff --git a/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts b/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts index bac2bb3235..480e75601c 100644 --- a/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts +++ b/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts @@ -1,8 +1,17 @@ -import { isExportableToExcel } from "../../../formulas/index"; +import { + CellPosition, + FunctionResultObject, + GetSymbolValue, + isExportableToExcel, + isMatrix, + Matrix, + RangeCompiledFormula, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { matrixMap } from "../../../functions/helpers"; import { getItemId, positions, toXC } from "../../../helpers/index"; import { - CellPosition, CellValue, CellValueType, Command, @@ -11,15 +20,8 @@ import { Format, FormattedValue, FormulaCell, - FunctionResultObject, - GetSymbolValue, - Matrix, - Range, - RangeCompiledFormula, - UID, - Zone, invalidateDependenciesCommands, - isMatrix, + Range, } from "../../../types/index"; import { FormulaCellWithDependencies } from "../../core"; import { CoreViewPlugin, CoreViewPluginConfig } from "../../core_view_plugin"; diff --git a/src/plugins/ui_core_views/cell_evaluation/evaluator.ts b/src/plugins/ui_core_views/cell_evaluation/evaluator.ts index 2b8d6ae25f..cd397a55a5 100644 --- a/src/plugins/ui_core_views/cell_evaluation/evaluator.ts +++ b/src/plugins/ui_core_views/cell_evaluation/evaluator.ts @@ -1,5 +1,4 @@ import { compile } from "../../../formulas"; -import { handleError, implementationErrorMessage } from "../../../functions"; import { matrixMap } from "../../../functions/helpers"; import { aggregatePositionsToZones, @@ -14,28 +13,14 @@ import { PositionMap } from "../../../helpers/cells/position_map"; import { ModelConfig } from "../../../model"; import { onIterationEndEvaluationRegistry } from "../../../registries/evaluation_registry"; import { _t } from "../../../translation"; -import { - CellPosition, - CellValueType, - EvaluatedCell, - FormulaCell, - FunctionResultObject, - GetSymbolValue, - Getters, - Matrix, - Range, - RangeCompiledFormula, - UID, - Zone, - isMatrix, -} from "../../../types"; +import { CellValueType, EvaluatedCell, FormulaCell, Getters, Range } from "../../../types"; import { BadExpressionError, CellErrorType, CircularDependencyError, SplillBlockedError, } from "../../../types/errors"; -import { CompilationParameters, buildCompilationParameters } from "./compilation_parameters"; +import { buildCompilationParameters, CompilationParameters } from "./compilation_parameters"; import { FormulaDependencyGraph } from "./formula_dependency_graph"; import { PositionSet, SheetSizes } from "./position_set"; import { RTreeBoundingBox } from "./r_tree"; diff --git a/src/plugins/ui_core_views/cell_evaluation/formula_dependency_graph.ts b/src/plugins/ui_core_views/cell_evaluation/formula_dependency_graph.ts index ac3764f7ef..628f95231c 100644 --- a/src/plugins/ui_core_views/cell_evaluation/formula_dependency_graph.ts +++ b/src/plugins/ui_core_views/cell_evaluation/formula_dependency_graph.ts @@ -1,7 +1,7 @@ +import { CellPosition, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { positionToZone } from "../../../helpers"; import { PositionMap } from "../../../helpers/cells/position_map"; import { recomputeZones } from "../../../helpers/recompute_zones"; -import { CellPosition, UID, Zone } from "../../../types"; import { PositionSet } from "./position_set"; import { RTreeBoundingBox, RTreeItem, SpreadsheetRTree } from "./r_tree"; diff --git a/src/plugins/ui_core_views/cell_evaluation/position_set.ts b/src/plugins/ui_core_views/cell_evaluation/position_set.ts index 4fa9f962aa..678fa7e188 100644 --- a/src/plugins/ui_core_views/cell_evaluation/position_set.ts +++ b/src/plugins/ui_core_views/cell_evaluation/position_set.ts @@ -1,6 +1,4 @@ -import { CellPosition, UID } from "../../../types"; -import { BinaryGrid } from "./binary_grid"; - +import { CellPosition, UID } from "@odoo/o-spreadsheet-engine"; export type SheetSizes = Record; export class PositionSet { diff --git a/src/plugins/ui_core_views/cell_evaluation/r_tree.ts b/src/plugins/ui_core_views/cell_evaluation/r_tree.ts index efd66a4a28..3bcb7af27e 100644 --- a/src/plugins/ui_core_views/cell_evaluation/r_tree.ts +++ b/src/plugins/ui_core_views/cell_evaluation/r_tree.ts @@ -1,6 +1,6 @@ import RBush from "rbush"; -import { UID, Zone } from "../../../types"; +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; /** * R-Tree Data Structure diff --git a/src/plugins/ui_core_views/cell_evaluation/spreading_relation.ts b/src/plugins/ui_core_views/cell_evaluation/spreading_relation.ts index d41d5de635..19913ed29f 100644 --- a/src/plugins/ui_core_views/cell_evaluation/spreading_relation.ts +++ b/src/plugins/ui_core_views/cell_evaluation/spreading_relation.ts @@ -1,6 +1,6 @@ +import { CellPosition, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { positionToZone } from "../../../helpers"; import { PositionMap } from "../../../helpers/cells/position_map"; -import { CellPosition, UID, Zone } from "../../../types"; import { SpreadsheetRTree } from "./r_tree"; /** diff --git a/src/plugins/ui_core_views/cell_icon_plugin.ts b/src/plugins/ui_core_views/cell_icon_plugin.ts index 597d680ce9..62116cb870 100644 --- a/src/plugins/ui_core_views/cell_icon_plugin.ts +++ b/src/plugins/ui_core_views/cell_icon_plugin.ts @@ -1,3 +1,4 @@ +import { Align, CellPosition } from "@odoo/o-spreadsheet-engine"; import { isDefined } from "../../helpers/index"; import { GridIcon, @@ -5,7 +6,6 @@ import { iconsOnCellRegistry, } from "../../registries/icons_on_cell_registry"; import { Command, Rect } from "../../types"; -import { Align, CellPosition } from "../../types/misc"; import { CoreViewPlugin } from "../core_view_plugin"; export class CellIconPlugin extends CoreViewPlugin { diff --git a/src/plugins/ui_core_views/custom_colors.ts b/src/plugins/ui_core_views/custom_colors.ts index 7b3d5b083d..30508d46e1 100644 --- a/src/plugins/ui_core_views/custom_colors.ts +++ b/src/plugins/ui_core_views/custom_colors.ts @@ -1,3 +1,4 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { COLOR_PICKER_DEFAULTS } from "../../constants"; import { colorNumberToHex, @@ -9,9 +10,7 @@ import { rgbaToHSLA, toHex, } from "../../helpers"; -import { Color, Command, Immutable, RGBA, TableElementStyle, UID } from "../../types"; -import { CoreViewPlugin, CoreViewPluginConfig } from "../core_view_plugin"; - +import { Command, Immutable, RGBA, TableElementStyle } from "../../types"; const chartColorRegex = /"(#[0-9a-fA-F]{6})"/g; /** diff --git a/src/plugins/ui_core_views/dynamic_tables.ts b/src/plugins/ui_core_views/dynamic_tables.ts index 4eae767472..ba7d80ae46 100644 --- a/src/plugins/ui_core_views/dynamic_tables.ts +++ b/src/plugins/ui_core_views/dynamic_tables.ts @@ -1,3 +1,4 @@ +import { CellPosition, FilterId, TableId, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { areZonesContinuous, deepEquals, @@ -10,17 +11,12 @@ import { } from "../../helpers"; import { createFilter } from "../../helpers/table_helpers"; import { - CellPosition, Command, CoreTable, DynamicTable, ExcelWorkbookData, Filter, - FilterId, Table, - TableId, - UID, - Zone, invalidateEvaluationCommands, } from "../../types/index"; import { CoreViewPlugin } from "../core_view_plugin"; diff --git a/src/plugins/ui_core_views/evaluation_chart.ts b/src/plugins/ui_core_views/evaluation_chart.ts index f46b2ceac6..a35d997ad6 100644 --- a/src/plugins/ui_core_views/evaluation_chart.ts +++ b/src/plugins/ui_core_views/evaluation_chart.ts @@ -1,6 +1,7 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { BACKGROUND_CHART_COLOR } from "../../constants"; import { chartFontColor, chartRuntimeFactory, chartToImageUrl } from "../../helpers/figures/charts"; -import { Color, ExcelWorkbookData, FigureData, Range, UID } from "../../types"; +import { ExcelWorkbookData, FigureData, Range } from "../../types"; import { ChartRuntime, ExcelChartDefinition } from "../../types/chart/chart"; import { CoreViewCommand, @@ -8,8 +9,6 @@ import { invalidateChartEvaluationCommands, invalidateEvaluationCommands, } from "../../types/commands"; -import { CoreViewPlugin } from "../core_view_plugin"; - interface EvaluationChartStyle { background: Color; fontColor: Color; diff --git a/src/plugins/ui_core_views/evaluation_conditional_format.ts b/src/plugins/ui_core_views/evaluation_conditional_format.ts index 9721c66650..cbe959ec00 100644 --- a/src/plugins/ui_core_views/evaluation_conditional_format.ts +++ b/src/plugins/ui_core_views/evaluation_conditional_format.ts @@ -1,3 +1,11 @@ +import { + CellPosition, + DataBarFill, + HeaderIndex, + Style, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { compile } from "../../formulas"; import { isMultipleElementMatrix, toScalar } from "../../functions/helper_matrices"; import { parseLiteral } from "../../helpers/cells"; @@ -6,28 +14,20 @@ import { clip, largeMax, largeMin, lazy } from "../../helpers/misc"; import { criterionEvaluatorRegistry } from "../../registries/criterion_registry"; import { CellIsRule, - CellPosition, CellValueType, ColorScaleMidPointThreshold, ColorScaleRule, ColorScaleThreshold, DEFAULT_LOCALE, - DataBarFill, DataBarRule, EvaluatedCell, - HeaderIndex, IconSetRule, IconThreshold, Lazy, NumberCell, - Style, - UID, - Zone, invalidateCFEvaluationCommands, } from "../../types/index"; import { CoreViewPlugin } from "../core_view_plugin"; -import { CoreViewCommand, invalidateEvaluationCommands } from "./../../types/commands"; - type ComputedStyles = { [col: HeaderIndex]: (Style | undefined)[] }; type ComputedIcons = { [col: HeaderIndex]: (string | undefined)[] }; type ComputedDataBars = { [col: HeaderIndex]: (DataBarFill | undefined)[] }; diff --git a/src/plugins/ui_core_views/evaluation_data_validation.ts b/src/plugins/ui_core_views/evaluation_data_validation.ts index 16b316e65a..ee5f2d6559 100644 --- a/src/plugins/ui_core_views/evaluation_data_validation.ts +++ b/src/plugins/ui_core_views/evaluation_data_validation.ts @@ -1,3 +1,4 @@ +import { CellPosition, HeaderIndex, Matrix, Style, UID } from "@odoo/o-spreadsheet-engine"; import { DVTerms } from "../../components/translations_terms"; import { GRAY_200 } from "../../constants"; import { compile } from "../../formulas"; @@ -6,7 +7,6 @@ import { chipTextColor, getCellPositionsInRanges, isInside, lazy, positions } fr import { parseLiteral } from "../../helpers/cells"; import { criterionEvaluatorRegistry } from "../../registries/criterion_registry"; import { - CellPosition, CellValue, CellValueType, DEFAULT_LOCALE, @@ -14,12 +14,8 @@ import { DataValidationCriterionType, DataValidationRule, EvaluatedCriterion, - HeaderIndex, Lazy, - Matrix, Offset, - Style, - UID, } from "../../types"; import { CoreViewCommand, invalidateEvaluationCommands } from "../../types/commands"; import { CoreViewPlugin } from "../core_view_plugin"; diff --git a/src/plugins/ui_core_views/header_sizes_ui.ts b/src/plugins/ui_core_views/header_sizes_ui.ts index ee2fefddf0..141e88fcff 100644 --- a/src/plugins/ui_core_views/header_sizes_ui.ts +++ b/src/plugins/ui_core_views/header_sizes_ui.ts @@ -1,3 +1,4 @@ +import { CellPosition, HeaderIndex, Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT } from "../../constants"; import { deepCopy, @@ -9,8 +10,7 @@ import { removeIndexesFromArray, } from "../../helpers"; import { AnchorOffset, Command } from "../../types"; -import { CellPosition, Dimension, HeaderIndex, Immutable, Pixel, UID } from "../../types/misc"; -import { CoreViewPlugin } from "../core_view_plugin"; +import { Immutable } from "../../types/misc"; interface HeaderSizeState { tallestCellInRow: Immutable>>; diff --git a/src/plugins/ui_core_views/pivot_ui.ts b/src/plugins/ui_core_views/pivot_ui.ts index 670942c7ba..278095da76 100644 --- a/src/plugins/ui_core_views/pivot_ui.ts +++ b/src/plugins/ui_core_views/pivot_ui.ts @@ -1,3 +1,4 @@ +import { CellPosition, FunctionResultObject, isMatrix, UID } from "@odoo/o-spreadsheet-engine"; import { Token } from "../../formulas"; import { astToFormula } from "../../formulas/formula_formatter"; import { toScalar } from "../../functions/helper_matrices"; @@ -15,23 +16,17 @@ import { EMPTY_PIVOT_CELL } from "../../helpers/pivot/table_spreadsheet_pivot"; import { _t } from "../../translation"; import { AddPivotCommand, - CellPosition, Command, CoreCommand, - FunctionResultObject, + invalidateEvaluationCommands, PivotCoreMeasure, PivotTableCell, PivotVisibilityOptions, SortDirection, - UID, UpdatePivotCommand, - invalidateEvaluationCommands, - isMatrix, } from "../../types"; import { Pivot } from "../../types/pivot_runtime"; import { CoreViewPlugin, CoreViewPluginConfig } from "../core_view_plugin"; -import { UIPluginConfig } from "../ui_plugin"; - export const UNDO_REDO_PIVOT_COMMANDS = ["ADD_PIVOT", "UPDATE_PIVOT", "REMOVE_PIVOT"]; function isPivotCommand(cmd: CoreCommand): cmd is AddPivotCommand | UpdatePivotCommand { diff --git a/src/plugins/ui_feature/autofill.ts b/src/plugins/ui_feature/autofill.ts index a4c3756bcb..8f05b6ea31 100644 --- a/src/plugins/ui_feature/autofill.ts +++ b/src/plugins/ui_feature/autofill.ts @@ -14,22 +14,18 @@ import { AutofillData, AutofillModifier, AutofillResult, - Border, Cell, CellValueType, Command, CommandResult, - DIRECTION, GeneratorCell, Getters, GridRenderingContext, - HeaderIndex, LocalCommand, Tooltip, - UID, - Zone, } from "../../types/index"; +import { Border, DIRECTION, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { UIPlugin } from "../ui_plugin"; type AutofillCellData = Omit; diff --git a/src/plugins/ui_feature/automatic_sum.ts b/src/plugins/ui_feature/automatic_sum.ts index ddb2adfb8e..93795d0120 100644 --- a/src/plugins/ui_feature/automatic_sum.ts +++ b/src/plugins/ui_feature/automatic_sum.ts @@ -1,3 +1,4 @@ +import { HeaderIndex, Position, Sheet, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { groupConsecutive, isDateTimeFormat, @@ -10,17 +11,7 @@ import { union, zoneToDimension, } from "../../helpers"; -import { - CellValueType, - Command, - Dimension, - EvaluatedCell, - Position, - Sheet, - UID, - Zone, -} from "../../types"; -import { HeaderIndex } from "../../types/misc"; +import { CellValueType, Command, Dimension, EvaluatedCell } from "../../types"; import { UIPlugin } from "../ui_plugin"; interface AutomaticSum { diff --git a/src/plugins/ui_feature/cell_computed_style.ts b/src/plugins/ui_feature/cell_computed_style.ts index 66d755cfca..3a6d244ae6 100644 --- a/src/plugins/ui_feature/cell_computed_style.ts +++ b/src/plugins/ui_feature/cell_computed_style.ts @@ -1,3 +1,4 @@ +import { Border, CellPosition, Style, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { LINK_COLOR } from "../../constants"; import { PositionMap } from "../../helpers/cells/position_map"; import { isObjectEmptyRecursive, positionToZone, removeFalsyAttributes } from "../../helpers/index"; @@ -7,7 +8,6 @@ import { invalidateCFEvaluationCommands, invalidateEvaluationCommands, } from "../../types"; -import { Border, CellPosition, Style, UID, Zone } from "../../types/misc"; import { UIPlugin } from "../ui_plugin"; import { doesCommandInvalidatesTableStyle } from "./table_computed_style"; diff --git a/src/plugins/ui_feature/checkbox_toggle.ts b/src/plugins/ui_feature/checkbox_toggle.ts index f765e45196..69eb4d08b0 100644 --- a/src/plugins/ui_feature/checkbox_toggle.ts +++ b/src/plugins/ui_feature/checkbox_toggle.ts @@ -1,4 +1,5 @@ -import { Command, UID, Zone } from "../../types/index"; +import { UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { Command } from "../../types/index"; import { UIPlugin } from "../ui_plugin"; export class CheckboxTogglePlugin extends UIPlugin { diff --git a/src/plugins/ui_feature/data_cleanup.ts b/src/plugins/ui_feature/data_cleanup.ts index 1cf3a9823c..d7dbd9bf06 100644 --- a/src/plugins/ui_feature/data_cleanup.ts +++ b/src/plugins/ui_feature/data_cleanup.ts @@ -1,3 +1,4 @@ +import { HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { CellClipboardHandler } from "../../clipboard_handlers/cell_clipboard"; import { deepEquals, @@ -9,14 +10,7 @@ import { } from "../../helpers"; import { getClipboardDataPositions } from "../../helpers/clipboard/clipboard_helpers"; import { _t } from "../../translation"; -import { - Command, - CommandResult, - HeaderIndex, - RemoveDuplicatesCommand, - UID, - Zone, -} from "../../types/index"; +import { Command, CommandResult, RemoveDuplicatesCommand } from "../../types/index"; import { UIPlugin } from "../ui_plugin"; export class DataCleanupPlugin extends UIPlugin { diff --git a/src/plugins/ui_feature/datavalidation_insertion.ts b/src/plugins/ui_feature/datavalidation_insertion.ts index 59ac27f46f..09648f9c66 100644 --- a/src/plugins/ui_feature/datavalidation_insertion.ts +++ b/src/plugins/ui_feature/datavalidation_insertion.ts @@ -1,5 +1,6 @@ +import { isMatrix } from "@odoo/o-spreadsheet-engine"; import { getCellPositionsInRanges, isBoolean } from "../../helpers"; -import { CellValueType, Command, isMatrix } from "../../types/index"; +import { CellValueType, Command } from "../../types/index"; import { UIPlugin } from "../ui_plugin"; export class DataValidationInsertionPlugin extends UIPlugin { diff --git a/src/plugins/ui_feature/format.ts b/src/plugins/ui_feature/format.ts index 6056051054..56a0aff1d6 100644 --- a/src/plugins/ui_feature/format.ts +++ b/src/plugins/ui_feature/format.ts @@ -1,3 +1,4 @@ +import { CellPosition, Position, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { changeDecimalPlaces, createDefaultFormat, @@ -7,16 +8,12 @@ import { recomputeZones, } from "../../helpers"; import { - CellPosition, CellValueType, Command, Format, PivotTableCell, PivotValueCell, - Position, SetDecimalStep, - UID, - Zone, } from "../../types/index"; import { UIPlugin } from "../ui_plugin"; diff --git a/src/plugins/ui_feature/header_visibility_ui.ts b/src/plugins/ui_feature/header_visibility_ui.ts index d24577a58e..2881a27906 100644 --- a/src/plugins/ui_feature/header_visibility_ui.ts +++ b/src/plugins/ui_feature/header_visibility_ui.ts @@ -1,5 +1,6 @@ +import { CellPosition, HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; import { range } from "../../helpers"; -import { CellPosition, Dimension, ExcelWorkbookData, HeaderIndex, UID } from "../../types"; +import { Dimension, ExcelWorkbookData } from "../../types"; import { UIPlugin } from "../ui_plugin"; export class HeaderVisibilityUIPlugin extends UIPlugin { diff --git a/src/plugins/ui_feature/insert_pivot.ts b/src/plugins/ui_feature/insert_pivot.ts index 134c7e7e31..a534157e2d 100644 --- a/src/plugins/ui_feature/insert_pivot.ts +++ b/src/plugins/ui_feature/insert_pivot.ts @@ -1,10 +1,11 @@ +import { CellPosition, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { PIVOT_TABLE_CONFIG } from "../../constants"; import { getUniqueText, sanitizeSheetName } from "../../helpers"; import { createPivotFormula } from "../../helpers/pivot/pivot_helpers"; import { SpreadsheetPivotTable } from "../../helpers/pivot/table_spreadsheet_pivot"; import { getZoneArea, positionToZone } from "../../helpers/zones"; import { _t } from "../../translation"; -import { CellPosition, HeaderIndex, PivotTableCell, PivotTableData, UID, Zone } from "../../types"; +import { PivotTableCell, PivotTableData } from "../../types"; import { Command, CommandResult } from "../../types/commands"; import { UIPlugin } from "../ui_plugin"; diff --git a/src/plugins/ui_feature/local_history.ts b/src/plugins/ui_feature/local_history.ts index 3cb6f62a59..7634890522 100644 --- a/src/plugins/ui_feature/local_history.ts +++ b/src/plugins/ui_feature/local_history.ts @@ -1,7 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Session } from "../../collaborative/session"; import { MAX_HISTORY_STEPS } from "../../constants"; import { canRepeatRevision, repeatRevision } from "../../history/repeat_commands/repeat_revision"; -import { Command, CommandResult, UID } from "../../types"; +import { Command, CommandResult } from "../../types"; import { UIPlugin, UIPluginConfig } from "../ui_plugin"; /** diff --git a/src/plugins/ui_feature/pivot_presence_plugin.ts b/src/plugins/ui_feature/pivot_presence_plugin.ts index 222f6e4ed5..5e16f5a501 100644 --- a/src/plugins/ui_feature/pivot_presence_plugin.ts +++ b/src/plugins/ui_feature/pivot_presence_plugin.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { PivotPresenceTracker } from "../../helpers/pivot/pivot_presence_tracker"; -import { Command, UID } from "../../types"; +import { Command } from "../../types"; import { UIPlugin } from "../ui_plugin"; export class PivotPresencePlugin extends UIPlugin { diff --git a/src/plugins/ui_feature/sort.ts b/src/plugins/ui_feature/sort.ts index 9e98155c05..0e42e3f86f 100644 --- a/src/plugins/ui_feature/sort.ts +++ b/src/plugins/ui_feature/sort.ts @@ -1,3 +1,4 @@ +import { CellPosition, HeaderIndex, Position, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { deepEquals, isInside, @@ -8,19 +9,14 @@ import { } from "../../helpers/index"; import { sortCells } from "../../helpers/sort"; import { - CellPosition, CellValueType, Command, CommandResult, - HeaderIndex, LocalCommand, - Position, SortCommand, SortDirection, SortOptions, - UID, UpdateCellCommand, - Zone, } from "../../types/index"; import { UIPlugin } from "../ui_plugin"; diff --git a/src/plugins/ui_feature/split_to_columns.ts b/src/plugins/ui_feature/split_to_columns.ts index e44eafa2c7..75e791f191 100644 --- a/src/plugins/ui_feature/split_to_columns.ts +++ b/src/plugins/ui_feature/split_to_columns.ts @@ -1,13 +1,12 @@ +import { CellPosition, Zone } from "@odoo/o-spreadsheet-engine"; import { NEWLINE } from "../../constants"; import { range } from "../../helpers"; import { canonicalizeNumberContent } from "../../helpers/locale"; import { - CellPosition, CellValueType, Command, CommandResult, SplitTextIntoColumnsCommand, - Zone, } from "../../types/index"; import { UIPlugin } from "../ui_plugin"; diff --git a/src/plugins/ui_feature/table_autofill.ts b/src/plugins/ui_feature/table_autofill.ts index a8f6b0e518..bf316e8171 100644 --- a/src/plugins/ui_feature/table_autofill.ts +++ b/src/plugins/ui_feature/table_autofill.ts @@ -1,6 +1,7 @@ +import { CellPosition, Zone } from "@odoo/o-spreadsheet-engine"; import { isInside } from "../../helpers"; import { getTableContentZone } from "../../helpers/table_helpers"; -import { CellPosition, CellValueType, Command, Zone } from "../../types"; +import { CellValueType, Command } from "../../types"; import { UIPlugin } from "../ui_plugin"; export class TableAutofillPlugin extends UIPlugin { diff --git a/src/plugins/ui_feature/table_computed_style.ts b/src/plugins/ui_feature/table_computed_style.ts index 1a197433aa..1a553ab61a 100644 --- a/src/plugins/ui_feature/table_computed_style.ts +++ b/src/plugins/ui_feature/table_computed_style.ts @@ -1,22 +1,7 @@ +import { Border, CellPosition, Style, TableId, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { lazy } from "../../helpers"; import { PositionMap } from "../../helpers/cells/position_map"; import { getComputedTableStyle } from "../../helpers/table_helpers"; -import { - Border, - CellPosition, - Command, - CommandTypes, - Lazy, - Style, - Table, - TableConfig, - TableId, - UID, - Zone, - invalidateEvaluationCommands, -} from "../../types"; -import { UIPlugin } from "../ui_plugin"; - interface ComputedTableStyle { styles: Record>; borders: Record>; diff --git a/src/plugins/ui_feature/ui_sheet.ts b/src/plugins/ui_feature/ui_sheet.ts index d0d49b7f27..f154f4f568 100644 --- a/src/plugins/ui_feature/ui_sheet.ts +++ b/src/plugins/ui_feature/ui_sheet.ts @@ -1,3 +1,12 @@ +import { + CellPosition, + HeaderIndex, + Pixel, + Style, + UID, + VerticalAlign, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { DATA_VALIDATION_CHIP_MARGIN, DEFAULT_CELL_HEIGHT, @@ -18,8 +27,7 @@ import { splitTextToWidth, } from "../../helpers/index"; import { localizeFormula } from "../../helpers/locale"; -import { CellValueType, Command, CommandResult, LocalCommand, Rect, UID } from "../../types"; -import { CellPosition, HeaderIndex, Pixel, Style, VerticalAlign, Zone } from "../../types/misc"; +import { CellValueType, Command, CommandResult, LocalCommand, Rect } from "../../types"; import { UIPlugin } from "../ui_plugin"; export class SheetUIPlugin extends UIPlugin { diff --git a/src/plugins/ui_plugin.ts b/src/plugins/ui_plugin.ts index c036f721a5..01001adee0 100644 --- a/src/plugins/ui_plugin.ts +++ b/src/plugins/ui_plugin.ts @@ -1,10 +1,7 @@ -import { BasePlugin, StateObserver } from "@odoo/o-spreadsheet-engine"; -import { Session } from "../collaborative/session"; import { ModelConfig } from "../model"; import { SelectionStreamProcessor } from "../selection_stream/selection_stream_processor"; import { ClientPosition, - Color, Command, CommandDispatcher, CommandResult, diff --git a/src/plugins/ui_stateful/carousel_ui.ts b/src/plugins/ui_stateful/carousel_ui.ts index 8a792a8d26..3539e9f78f 100644 --- a/src/plugins/ui_stateful/carousel_ui.ts +++ b/src/plugins/ui_stateful/carousel_ui.ts @@ -1,4 +1,5 @@ -import { AbstractChart, Carousel, CarouselItem, Command, UID } from "../.."; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { AbstractChart, Carousel, CarouselItem, Command } from "../.."; import { deepEquals, UuidGenerator } from "../../helpers"; import { CAROUSEL_DEFAULT_CHART_DEFINITION } from "../../helpers/carousel_helpers"; import { CommandResult, LocalCommand } from "../../types"; diff --git a/src/plugins/ui_stateful/clipboard.ts b/src/plugins/ui_stateful/clipboard.ts index c312622033..a378287f93 100644 --- a/src/plugins/ui_stateful/clipboard.ts +++ b/src/plugins/ui_stateful/clipboard.ts @@ -1,3 +1,4 @@ +import { HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { clipboardHandlersRegistries } from "../../clipboard_handlers"; import { ClipboardHandler } from "../../clipboard_handlers/abstract_clipboard_handler"; import { cellStyleToCss, cssPropertiesToCss } from "../../components/helpers"; @@ -27,15 +28,10 @@ import { CommandResult, Dimension, GridRenderingContext, - HeaderIndex, LocalCommand, - UID, - Zone, isCoreCommand, } from "../../types/index"; import { xmlEscape } from "../../xlsx/helpers/xml_helpers"; -import { UIPlugin, UIPluginConfig } from "../ui_plugin"; - export const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5 MB interface InsertDeleteCellsTargets { diff --git a/src/plugins/ui_stateful/filter_evaluation.ts b/src/plugins/ui_stateful/filter_evaluation.ts index 1fa4a7d76d..2c9f61e22b 100644 --- a/src/plugins/ui_stateful/filter_evaluation.ts +++ b/src/plugins/ui_stateful/filter_evaluation.ts @@ -1,3 +1,4 @@ +import { CellPosition, FilterId, UID } from "@odoo/o-spreadsheet-engine"; import { isMultipleElementMatrix, toScalar } from "../../functions/helper_matrices"; import { deepCopy, @@ -12,7 +13,6 @@ import { import { parseLiteral } from "../../helpers/cells"; import { criterionEvaluatorRegistry } from "../../registries/criterion_registry"; import { - CellPosition, Command, CommandResult, CriterionFilter, @@ -20,9 +20,7 @@ import { DataFilterValue, ExcelFilterData, ExcelWorkbookData, - FilterId, Table, - UID, } from "../../types"; import { LocalCommand, UpdateFilterCommand } from "../../types/commands"; import { UIPlugin } from "../ui_plugin"; diff --git a/src/plugins/ui_stateful/header_positions.ts b/src/plugins/ui_stateful/header_positions.ts index 739161f6b7..d1d85f69db 100644 --- a/src/plugins/ui_stateful/header_positions.ts +++ b/src/plugins/ui_stateful/header_positions.ts @@ -1,7 +1,8 @@ +import { HeaderDimensions, HeaderIndex, Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { deepCopy } from "../../helpers/index"; -import { Command, UID } from "../../types"; +import { Command } from "../../types"; import { invalidateEvaluationCommands } from "../../types/commands"; -import { Dimension, HeaderDimensions, HeaderIndex, Pixel } from "../../types/misc"; +import { Dimension } from "../../types/misc"; import { UIPlugin } from "../ui_plugin"; export class HeaderPositionsUIPlugin extends UIPlugin { diff --git a/src/plugins/ui_stateful/selection.ts b/src/plugins/ui_stateful/selection.ts index a935c861b1..86c907ee94 100644 --- a/src/plugins/ui_stateful/selection.ts +++ b/src/plugins/ui_stateful/selection.ts @@ -1,3 +1,15 @@ +import { + AnchorZone, + CellPosition, + HeaderIndex, + Pixel, + Selection, + Sheet, + Style, + UID, + UnboundedZone, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { clipboardHandlersRegistries } from "../../clipboard_handlers"; import { AbstractCellClipboardHandler } from "../../clipboard_handlers/abstract_cell_clipboard_handler"; import { SELECTION_BORDER_COLOR } from "../../constants"; @@ -15,26 +27,16 @@ import { import { SelectionEvent } from "../../types/event_stream"; import { AddColumnsRowsCommand, - AnchorZone, - CellPosition, ClientPosition, Command, CommandResult, Dimension, EvaluatedCell, GridRenderingContext, - HeaderIndex, LocalCommand, MoveColumnsRowsCommand, - Pixel, RemoveColumnsRowsCommand, - Selection, - Sheet, - Style, - UID, - UnboundedZone, UpdateFigureCommand, - Zone, } from "../../types/index"; import { UIPlugin, UIPluginConfig } from "../ui_plugin"; diff --git a/src/plugins/ui_stateful/sheetview.ts b/src/plugins/ui_stateful/sheetview.ts index 8f026af6ac..bfdbf2fea6 100644 --- a/src/plugins/ui_stateful/sheetview.ts +++ b/src/plugins/ui_stateful/sheetview.ts @@ -1,3 +1,13 @@ +import { + CellPosition, + HeaderDimensions, + HeaderIndex, + Pixel, + PixelPosition, + Position, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { getDefaultSheetViewSize } from "../../constants"; import { clip, findCellInNewZone, isDefined, positionToZone, range } from "../../helpers"; import { scrollDelay } from "../../helpers/index"; @@ -5,7 +15,6 @@ import { InternalViewport } from "../../helpers/internal_viewport"; import { SelectionEvent } from "../../types/event_stream"; import { AnchorOffset, - CellPosition, Command, CommandResult, DOMCoordinates, @@ -14,21 +23,15 @@ import { EdgeScrollInfo, Figure, FigureUI, - HeaderIndex, LocalCommand, - Pixel, - Position, Rect, ResizeViewportCommand, ScrollDirection, SetViewportOffsetCommand, SheetDOMScrollInfo, - UID, Viewport, - Zone, invalidateEvaluationCommands, } from "../../types/index"; -import { HeaderDimensions, PixelPosition } from "../../types/misc"; import { UIPlugin } from "../ui_plugin"; type SheetViewports = { diff --git a/src/registries/auto_completes/auto_complete_registry.ts b/src/registries/auto_completes/auto_complete_registry.ts index 9143d10126..f8df195ac1 100644 --- a/src/registries/auto_completes/auto_complete_registry.ts +++ b/src/registries/auto_completes/auto_complete_registry.ts @@ -1,6 +1,7 @@ +import { CellPosition } from "@odoo/o-spreadsheet-engine"; import { HtmlContent } from "../../components/composer/composer/composer"; import { EnrichedToken } from "../../formulas/composer_tokenizer"; -import { CellPosition, Getters } from "../../types"; +import { Getters } from "../../types"; import { Registry } from "../registry"; export interface AutoCompleteProposal { diff --git a/src/registries/auto_completes/function_auto_complete.ts b/src/registries/auto_completes/function_auto_complete.ts index ccda242a05..5849cee0b8 100644 --- a/src/registries/auto_completes/function_auto_complete.ts +++ b/src/registries/auto_completes/function_auto_complete.ts @@ -1,6 +1,6 @@ +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { getHtmlContentFromPattern } from "../../components/helpers/html_content_helpers"; import { COMPOSER_ASSISTANT_COLOR } from "../../constants"; -import { functionRegistry } from "../../functions"; import { isFormula } from "../../helpers"; import { autoCompleteProviders } from "./auto_complete_registry"; diff --git a/src/registries/auto_completes/pivot_auto_complete.ts b/src/registries/auto_completes/pivot_auto_complete.ts index 04eba4b1ae..fe0fca78b6 100644 --- a/src/registries/auto_completes/pivot_auto_complete.ts +++ b/src/registries/auto_completes/pivot_auto_complete.ts @@ -1,6 +1,6 @@ +import { insertTokenAtArgStartingPosition } from "@odoo/o-spreadsheet-engine"; import { tokenColors } from "../../constants"; import { EnrichedToken } from "../../formulas/composer_tokenizer"; -import { insertTokenAtArgStartingPosition } from "../../functions"; import { MONTHS, isDefined, range } from "../../helpers"; import { extractFormulaIdFromToken, diff --git a/src/registries/autofill_modifiers.ts b/src/registries/autofill_modifiers.ts index ba816da939..eaf5e69830 100644 --- a/src/registries/autofill_modifiers.ts +++ b/src/registries/autofill_modifiers.ts @@ -1,3 +1,4 @@ +import { DIRECTION } from "@odoo/o-spreadsheet-engine"; import { toJsDate } from "../functions/helpers"; import { jsDateToNumber } from "../helpers"; import { evaluateLiteral } from "../helpers/cells"; @@ -6,7 +7,6 @@ import { AutofillData, AutofillModifierImplementation, CopyModifier, - DIRECTION, FormulaModifier, Getters, IncrementModifier, diff --git a/src/registries/autofill_rules.ts b/src/registries/autofill_rules.ts index 43e1c28440..956e562579 100644 --- a/src/registries/autofill_rules.ts +++ b/src/registries/autofill_rules.ts @@ -1,3 +1,4 @@ +import { DIRECTION } from "@odoo/o-spreadsheet-engine"; import { toJsDate } from "../functions/helpers"; import { DateTime, @@ -7,7 +8,7 @@ import { isDateTimeFormat, } from "../helpers"; import { evaluateLiteral } from "../helpers/cells"; -import { AutofillModifier, Cell, CellValueType, DEFAULT_LOCALE, DIRECTION } from "../types/index"; +import { AutofillModifier, Cell, CellValueType, DEFAULT_LOCALE } from "../types/index"; import { EvaluatedCell, LiteralCell } from "./../types/cells"; import { Registry } from "./registry"; diff --git a/src/registries/cell_clickable_registry.ts b/src/registries/cell_clickable_registry.ts index fbe806ffe3..b862119536 100644 --- a/src/registries/cell_clickable_registry.ts +++ b/src/registries/cell_clickable_registry.ts @@ -1,9 +1,10 @@ +import { CellPosition } from "@odoo/o-spreadsheet-engine"; import { ComponentConstructor } from "@odoo/owl"; import { ClickableCellSortIcon } from "../components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon"; import { openLink } from "../helpers/links"; import { canSortPivot, sortPivot } from "../helpers/pivot/pivot_menu_items"; import { _t } from "../translation"; -import { CellPosition, Getters, SortDirection, SpreadsheetChildEnv } from "../types"; +import { Getters, SortDirection, SpreadsheetChildEnv } from "../types"; import { Registry } from "./registry"; export interface CellClickableItem { diff --git a/src/registries/chart_types.ts b/src/registries/chart_types.ts index 462c5326da..2995343bf1 100644 --- a/src/registries/chart_types.ts +++ b/src/registries/chart_types.ts @@ -1,3 +1,4 @@ +import { RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { ChartJsComponent } from "../components/figures/chart/chartJs/chartjs"; import { ZoomableChartJsComponent } from "../components/figures/chart/chartJs/zoomable_chart/zoomable_chartjs"; @@ -28,7 +29,7 @@ import { createWaterfallChartRuntime, } from "../helpers/figures/charts/waterfall_chart"; import { _t } from "../translation"; -import { CommandResult, CoreGetters, Getters, RangeAdapter, UID } from "../types"; +import { CommandResult, CoreGetters, Getters } from "../types"; import { BarChartDefinition, GaugeChartDefinition, diff --git a/src/registries/criterion_registry.ts b/src/registries/criterion_registry.ts index 46ecf86535..cabaa6e651 100644 --- a/src/registries/criterion_registry.ts +++ b/src/registries/criterion_registry.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { DVTerms } from "../components/translations_terms"; import { tryToNumber } from "../functions/helpers"; import { @@ -35,7 +36,6 @@ import { GenericCriterionType, Getters, Locale, - UID, } from "../types"; import { CellErrorType } from "../types/errors"; import { Registry } from "./registry"; diff --git a/src/registries/figures_registry.ts b/src/registries/figures_registry.ts index 86faaa5edf..0c7f2239c7 100644 --- a/src/registries/figures_registry.ts +++ b/src/registries/figures_registry.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Action } from "../actions/action"; import { getCarouselMenuActions, @@ -7,7 +8,7 @@ import { import { CarouselFigure } from "../components/figures/figure_carousel/figure_carousel"; import { ChartFigure } from "../components/figures/figure_chart/figure_chart"; import { ImageFigure } from "../components/figures/figure_image/figure_image"; -import { SpreadsheetChildEnv, UID } from "../types"; +import { SpreadsheetChildEnv } from "../types"; import { Registry } from "./registry"; //------------------------------------------------------------------------------ diff --git a/src/registries/icons_on_cell_registry.ts b/src/registries/icons_on_cell_registry.ts index 5f87ca80d1..e49a136327 100644 --- a/src/registries/icons_on_cell_registry.ts +++ b/src/registries/icons_on_cell_registry.ts @@ -1,3 +1,4 @@ +import { Align, CellPosition } from "@odoo/o-spreadsheet-engine"; import { CHECKBOX_CHECKED, CHECKBOX_UNCHECKED, @@ -20,10 +21,8 @@ import { PIVOT_INDENT, } from "../constants"; import { computeTextFontSizeInPixels, deepEquals, relativeLuminance } from "../helpers"; -import { Align, CellPosition, Getters, SpreadsheetChildEnv } from "../types"; +import { Getters, SpreadsheetChildEnv } from "../types"; import { ImageSVG } from "../types/image"; -import { Registry } from "./registry"; - export type IconsOfCell = Record, GridIcon | undefined>; export interface GridIcon { diff --git a/src/registries/menus/header_group_registry.ts b/src/registries/menus/header_group_registry.ts index be2c4ff39a..c22943202e 100644 --- a/src/registries/menus/header_group_registry.ts +++ b/src/registries/menus/header_group_registry.ts @@ -1,8 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Action, createActions } from "../../actions/action"; import * as ACTION_VIEW from "../../actions/view_actions"; import { interactiveToggleGroup } from "../../helpers/ui/toggle_group_interactive"; import { _t } from "../../translation"; -import { Dimension, UID } from "../../types"; +import { Dimension } from "../../types"; import { MenuItemRegistry } from "../menu_items_registry"; export function createHeaderGroupContainerContextMenu( diff --git a/src/registries/side_panel_registry.ts b/src/registries/side_panel_registry.ts index a6d158e761..f2649e24af 100644 --- a/src/registries/side_panel_registry.ts +++ b/src/registries/side_panel_registry.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { CarouselPanel } from "../components/side_panel/carousel_panel/carousel_panel"; import { ChartPanel } from "../components/side_panel/chart/main_chart_panel/main_chart_panel"; import { ConditionalFormattingPanel } from "../components/side_panel/conditional_formatting/conditional_formatting"; @@ -19,7 +20,7 @@ import { } from "../components/side_panel/table_style_editor_panel/table_style_editor_panel"; import { getTableTopLeft } from "../helpers/table_helpers"; import { _t } from "../translation"; -import { Getters, SpreadsheetChildEnv, UID } from "../types"; +import { Getters, SpreadsheetChildEnv } from "../types"; import { Registry } from "./registry"; //------------------------------------------------------------------------------ diff --git a/src/registries/srt_registry.ts b/src/registries/srt_registry.ts index 3e9a2bf0fa..35771de354 100644 --- a/src/registries/srt_registry.ts +++ b/src/registries/srt_registry.ts @@ -1,4 +1,5 @@ -import { CoreCommand, RangeAdapter } from "../types"; +import { RangeAdapter } from "@odoo/o-spreadsheet-engine"; +import { CoreCommand } from "../types"; import { Registry } from "./registry"; /* diff --git a/src/registries/topbar_component_registry.ts b/src/registries/topbar_component_registry.ts index 45cb8e778d..b0058bff06 100644 --- a/src/registries/topbar_component_registry.ts +++ b/src/registries/topbar_component_registry.ts @@ -1,5 +1,5 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { UuidGenerator } from "../helpers"; -import { UID } from "../types"; import { SpreadsheetChildEnv } from "../types/env"; import { Registry } from "./registry"; diff --git a/src/selection_stream/selection_stream_processor.ts b/src/selection_stream/selection_stream_processor.ts index 50349bbcd6..5e0e54286a 100644 --- a/src/selection_stream/selection_stream_processor.ts +++ b/src/selection_stream/selection_stream_processor.ts @@ -1,3 +1,4 @@ +import { AnchorZone, CellPosition, HeaderIndex, Position, Zone } from "@odoo/o-spreadsheet-engine"; import { deepCopy, deepEquals, @@ -8,18 +9,15 @@ import { union, } from "../helpers"; import { - AnchorZone, CellValueType, CommandResult, Direction, DispatchResult, Getters, - Position, SelectionStep, - Zone, } from "../types"; import { SelectionEvent, SelectionEventOptions } from "../types/event_stream"; -import { CellPosition, Dimension, HeaderIndex } from "./../types/misc"; +import { Dimension } from "./../types/misc"; import { EventStream, StreamCallbacks } from "./event_stream"; type Delta = [number, number]; diff --git a/src/stores/array_formula_highlight.ts b/src/stores/array_formula_highlight.ts index 89ffabeaad..1d39820b04 100644 --- a/src/stores/array_formula_highlight.ts +++ b/src/stores/array_formula_highlight.ts @@ -1,5 +1,5 @@ +import { Highlight } from "@odoo/o-spreadsheet-engine"; import { Get } from "../store_engine"; -import { Highlight } from "../types"; import { CellErrorType } from "../types/errors"; import { HighlightStore } from "./highlight_store"; import { SpreadsheetStore } from "./spreadsheet_store"; diff --git a/src/stores/formula_fingerprints_store.ts b/src/stores/formula_fingerprints_store.ts index 917a337732..fdb20250b2 100644 --- a/src/stores/formula_fingerprints_store.ts +++ b/src/stores/formula_fingerprints_store.ts @@ -1,3 +1,4 @@ +import { CellPosition, Color } from "@odoo/o-spreadsheet-engine"; import { AlternatingColorGenerator, isFullColRange, @@ -6,15 +7,7 @@ import { setColorAlpha, } from "../helpers"; import { PositionMap } from "../helpers/cells/position_map"; -import { - Cell, - CellPosition, - CellValueType, - Color, - Command, - FormulaCell, - isCoreCommand, -} from "../types/index"; +import { Cell, CellValueType, Command, FormulaCell, isCoreCommand } from "../types/index"; import { SpreadsheetStore } from "./spreadsheet_store"; /** diff --git a/src/stores/grid_renderer_store.ts b/src/stores/grid_renderer_store.ts index 50ad7df959..da03df6e0b 100644 --- a/src/stores/grid_renderer_store.ts +++ b/src/stores/grid_renderer_store.ts @@ -1,3 +1,4 @@ +import { Align, CellPosition, HeaderIndex, Pixel, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { ModelStore, SpreadsheetStore } from "."; import { HoveredIconStore } from "../components/grid_overlay/hovered_icon_store"; import { getPath2D } from "../components/icons/icons"; @@ -38,20 +39,14 @@ import { import { cellAnimationRegistry } from "../registries/cell_animation_registry"; import { Get, Store } from "../store_engine"; import { - Align, BorderDescrWithOpacity, Box, - CellPosition, CellValueType, Command, GridRenderingContext, - HeaderIndex, LayerName, - Pixel, RenderingBox, - UID, Viewport, - Zone, } from "../types/index"; import { FormulaFingerprintStore } from "./formula_fingerprints_store"; diff --git a/src/stores/highlight_store.ts b/src/stores/highlight_store.ts index 2d2493bc06..54333f8bfc 100644 --- a/src/stores/highlight_store.ts +++ b/src/stores/highlight_store.ts @@ -1,7 +1,8 @@ +import { Highlight } from "@odoo/o-spreadsheet-engine"; import { zoneToDimension } from "../helpers"; import { drawHighlight } from "../helpers/rendering"; import { Get } from "../store_engine"; -import { GridRenderingContext, Highlight, LayerName } from "../types"; +import { GridRenderingContext, LayerName } from "../types"; import { SpreadsheetStore } from "./spreadsheet_store"; export interface HighlightProvider { diff --git a/src/types/autofill.ts b/src/types/autofill.ts index ab95077775..bfcdf08217 100644 --- a/src/types/autofill.ts +++ b/src/types/autofill.ts @@ -8,10 +8,7 @@ * - Formula: update the formula, with the same behavior than paste */ -import { Getters } from "."; -import { Cell } from "./cells"; -import { Border, DIRECTION, UID, UpdateCellData } from "./misc"; - +import { Border, DIRECTION, UID, UpdateCellData } from "@odoo/o-spreadsheet-engine"; export interface IncrementModifier { type: "INCREMENT_MODIFIER"; increment: number; diff --git a/src/types/cell_popovers.ts b/src/types/cell_popovers.ts index 9283803754..2c53176926 100644 --- a/src/types/cell_popovers.ts +++ b/src/types/cell_popovers.ts @@ -1,6 +1,7 @@ +import { CellPosition } from "@odoo/o-spreadsheet-engine"; import { ComponentConstructor } from "@odoo/owl"; import { Getters } from "./index"; -import { CellPosition, PropsOf } from "./misc"; +import { PropsOf } from "./misc"; import { Rect } from "./rendering"; export type CellPopoverType = "ErrorToolTip" | "LinkDisplay" | "FilterMenu" | "LinkEditor"; diff --git a/src/types/cells.ts b/src/types/cells.ts index fccb10d8c6..41f30ad595 100644 --- a/src/types/cells.ts +++ b/src/types/cells.ts @@ -1,5 +1,5 @@ -import { Format, FormattedValue } from "./format"; -import { FunctionResultObject, Link, RangeCompiledFormula, Style, UID } from "./misc"; +import { Style, UID } from "@odoo/o-spreadsheet-engine"; +import { Format } from "./format"; interface CellAttributes { readonly id: UID; diff --git a/src/types/chart/bar_chart.ts b/src/types/chart/bar_chart.ts index a3c2c7e838..6f628a28c8 100644 --- a/src/types/chart/bar_chart.ts +++ b/src/types/chart/bar_chart.ts @@ -1,6 +1,7 @@ import { ChartConfiguration } from "chart.js"; import { CommonChartDefinition } from "."; -import { Color } from "../misc"; + +import { Color } from "@odoo/o-spreadsheet-engine"; export interface BarChartDefinition extends CommonChartDefinition { readonly type: "bar"; diff --git a/src/types/chart/chart.ts b/src/types/chart/chart.ts index 26dbea6b17..e052961d09 100644 --- a/src/types/chart/chart.ts +++ b/src/types/chart/chart.ts @@ -1,5 +1,6 @@ +import { Align, Color, VerticalAlign } from "@odoo/o-spreadsheet-engine"; import { Point } from "chart.js"; -import { Align, Color, Format, Locale, Range, VerticalAlign } from "../../types"; +import { Format, Locale, Range } from "../../types"; import { XlsxHexColor } from "../xlsx"; import { BarChartDefinition, BarChartRuntime } from "./bar_chart"; import { ComboChartDefinition, ComboChartRuntime } from "./combo_chart"; @@ -19,8 +20,6 @@ import { TreeMapChartRuntime, TreeMapColoringOptions, } from "./tree_map_chart"; -import { WaterfallChartDefinition, WaterfallChartRuntime } from "./waterfall_chart"; - export const CHART_TYPES = [ "line", "bar", diff --git a/src/types/chart/combo_chart.ts b/src/types/chart/combo_chart.ts index cd0485854a..320f7fe846 100644 --- a/src/types/chart/combo_chart.ts +++ b/src/types/chart/combo_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { CustomizedDataSet } from "./chart"; import { CommonChartDefinition } from "./common_chart"; diff --git a/src/types/chart/common_chart.ts b/src/types/chart/common_chart.ts index ebc2ef428b..7b02e59892 100644 --- a/src/types/chart/common_chart.ts +++ b/src/types/chart/common_chart.ts @@ -1,4 +1,4 @@ -import { Color } from "../.."; +import { Color } from "@odoo/o-spreadsheet-engine"; import { AxesDesign, CustomizedDataSet, TitleDesign } from "./chart"; export type VerticalAxisPosition = "left" | "right"; diff --git a/src/types/chart/funnel_chart.ts b/src/types/chart/funnel_chart.ts index de633d3b21..bbe2ef70f2 100644 --- a/src/types/chart/funnel_chart.ts +++ b/src/types/chart/funnel_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { AxesDesign, CustomizedDataSet, TitleDesign } from "./chart"; import { LegendPosition } from "./common_chart"; diff --git a/src/types/chart/gauge_chart.ts b/src/types/chart/gauge_chart.ts index a6c667e532..81105d7b88 100644 --- a/src/types/chart/gauge_chart.ts +++ b/src/types/chart/gauge_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import type { ChartOptions } from "chart.js"; -import { Color } from "../misc"; import { TitleDesign } from "./chart"; export interface GaugeChartDefinition { diff --git a/src/types/chart/geo_chart.ts b/src/types/chart/geo_chart.ts index 8077c12926..53cff81b0c 100644 --- a/src/types/chart/geo_chart.ts +++ b/src/types/chart/geo_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { ChartRuntimeGenerationArgs, CustomizedDataSet, TitleDesign } from "./chart"; import { LegendPosition } from "./common_chart"; diff --git a/src/types/chart/line_chart.ts b/src/types/chart/line_chart.ts index 4216093bbc..5ac411e4ae 100644 --- a/src/types/chart/line_chart.ts +++ b/src/types/chart/line_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { CommonChartDefinition } from "./common_chart"; export interface LineChartDefinition extends CommonChartDefinition { diff --git a/src/types/chart/pie_chart.ts b/src/types/chart/pie_chart.ts index 6070949b93..969dad8130 100644 --- a/src/types/chart/pie_chart.ts +++ b/src/types/chart/pie_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { CommonChartDefinition } from "./common_chart"; export interface PieChartDefinition extends CommonChartDefinition { diff --git a/src/types/chart/pyramid_chart.ts b/src/types/chart/pyramid_chart.ts index ed4a737099..d01084d667 100644 --- a/src/types/chart/pyramid_chart.ts +++ b/src/types/chart/pyramid_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { BarChartDefinition } from "./bar_chart"; export interface PyramidChartDefinition extends Omit { diff --git a/src/types/chart/radar_chart.ts b/src/types/chart/radar_chart.ts index d7ffe4c57a..eaf5fb9a5b 100644 --- a/src/types/chart/radar_chart.ts +++ b/src/types/chart/radar_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { CommonChartDefinition } from "./common_chart"; export interface RadarChartDefinition extends CommonChartDefinition { diff --git a/src/types/chart/scorecard_chart.ts b/src/types/chart/scorecard_chart.ts index df27cb43c2..ad26c1df48 100644 --- a/src/types/chart/scorecard_chart.ts +++ b/src/types/chart/scorecard_chart.ts @@ -1,4 +1,4 @@ -import { Color, Style } from "../misc"; +import { Color, Style } from "@odoo/o-spreadsheet-engine"; import { TitleDesign } from "./chart"; export interface ScorecardChartDefinition { diff --git a/src/types/chart/sunburst_chart.ts b/src/types/chart/sunburst_chart.ts index 608243dada..6c5ea6b9d6 100644 --- a/src/types/chart/sunburst_chart.ts +++ b/src/types/chart/sunburst_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration, ChartDataset } from "chart.js"; -import { Color } from "../misc"; import { ChartStyle, CustomizedDataSet, TitleDesign } from "./chart"; import { LegendPosition } from "./common_chart"; diff --git a/src/types/chart/tree_map_chart.ts b/src/types/chart/tree_map_chart.ts index e014fedadf..34d6e9b863 100644 --- a/src/types/chart/tree_map_chart.ts +++ b/src/types/chart/tree_map_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { CustomizedDataSet, TitleDesign } from "./chart"; import { TreemapDataPoint } from "./chartjs_tree_map_type"; import { LegendPosition } from "./common_chart"; diff --git a/src/types/chart/waterfall_chart.ts b/src/types/chart/waterfall_chart.ts index bbafe0b16d..4ee9359719 100644 --- a/src/types/chart/waterfall_chart.ts +++ b/src/types/chart/waterfall_chart.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration } from "chart.js"; -import { Color } from "../misc"; import { CommonChartDefinition, VerticalAxisPosition } from "./common_chart"; export interface WaterfallChartDefinition extends CommonChartDefinition { diff --git a/src/types/clipboard.ts b/src/types/clipboard.ts index be2cb90096..210db3a5ab 100644 --- a/src/types/clipboard.ts +++ b/src/types/clipboard.ts @@ -1,7 +1,5 @@ +import { ClipboardCell, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { SpreadsheetClipboardData } from "../plugins/ui_stateful"; -import { AllowedImageMimeTypes, Image } from "./image"; -import { ClipboardCell, HeaderIndex, UID, Zone } from "./misc"; - export enum ClipboardMIMEType { PlainText = "text/plain", Html = "text/html", diff --git a/src/types/collaborative/revisions.ts b/src/types/collaborative/revisions.ts index 8394860ee0..879de1feb2 100644 --- a/src/types/collaborative/revisions.ts +++ b/src/types/collaborative/revisions.ts @@ -1,4 +1,5 @@ -import { CoreCommand, UID } from ".."; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { CoreCommand } from ".."; import { ClientId } from "./session"; export interface RevisionData { diff --git a/src/types/collaborative/session.ts b/src/types/collaborative/session.ts index d83c269bd4..d883b87af2 100644 --- a/src/types/collaborative/session.ts +++ b/src/types/collaborative/session.ts @@ -1,6 +1,4 @@ -import { CoreCommand } from "../commands"; -import { Color, HeaderIndex, UID } from "../misc"; - +import { Color, HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; export type ClientId = string; export interface Client { diff --git a/src/types/collaborative/transport_service.ts b/src/types/collaborative/transport_service.ts index f37ca48ee8..b71f8d5edb 100644 --- a/src/types/collaborative/transport_service.ts +++ b/src/types/collaborative/transport_service.ts @@ -1,5 +1,5 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { CoreCommand } from "../commands"; -import { UID } from "../misc"; import { WorkbookData } from "../workbook_data"; import { ClientId, ClientWithPosition } from "./session"; diff --git a/src/types/commands.ts b/src/types/commands.ts index 5a7a3f3cd6..56edb19295 100644 --- a/src/types/commands.ts +++ b/src/types/commands.ts @@ -1,27 +1,18 @@ -import { - ConditionalFormat, - DataValidationRule, - Figure, - Format, - Locale, - Style, - Zone, -} from "./index"; +import { ConditionalFormat, DataValidationRule, Figure, Format, Locale } from "./index"; +import { Dimension, SetDecimalStep, SortDirection, SortOptions } from "./misc"; + import { Border, BorderData, CellPosition, Color, - Dimension, HeaderIndex, Pixel, PixelPosition, - SetDecimalStep, - SortDirection, - SortOptions, + Style, UID, -} from "./misc"; - + Zone, +} from "@odoo/o-spreadsheet-engine"; import { ChartDefinition } from "./chart/chart"; import { ClipboardPasteOptions, ParsedOsClipboardContentWithImageData } from "./clipboard"; import { Carousel, CarouselItem, FigureSize } from "./figure"; diff --git a/src/types/conditional_formatting.ts b/src/types/conditional_formatting.ts index 3e4d082c67..d65af5acca 100644 --- a/src/types/conditional_formatting.ts +++ b/src/types/conditional_formatting.ts @@ -1,4 +1,4 @@ -import { Style, UID } from "./misc"; +import { Style, UID } from "@odoo/o-spreadsheet-engine"; import { Range } from "./range"; // ----------------------------------------------------------------------------- diff --git a/src/types/data_validation.ts b/src/types/data_validation.ts index 800be95e36..ec4056c04b 100644 --- a/src/types/data_validation.ts +++ b/src/types/data_validation.ts @@ -1,5 +1,5 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { DateCriterionValue } from "./generic_criterion"; -import { Color, UID } from "./misc"; import { Range } from "./range"; export interface DataValidationRule { diff --git a/src/types/event_stream/selection_events.ts b/src/types/event_stream/selection_events.ts index 76b753314d..419de8895d 100644 --- a/src/types/event_stream/selection_events.ts +++ b/src/types/event_stream/selection_events.ts @@ -1,4 +1,4 @@ -import { AnchorZone } from ".."; +import { AnchorZone } from "@odoo/o-spreadsheet-engine"; export type SelectionEventOptions = { scrollIntoView?: boolean; diff --git a/src/types/figure.ts b/src/types/figure.ts index e0a523957d..9c87c58eec 100644 --- a/src/types/figure.ts +++ b/src/types/figure.ts @@ -1,4 +1,4 @@ -import { DOMCoordinates, HeaderIndex, Pixel, PixelPosition, TitleDesign, UID } from "."; +import { Pixel, UID } from "@odoo/o-spreadsheet-engine"; export interface FigureInfo { id: UID; diff --git a/src/types/format.ts b/src/types/format.ts index 7d196528bd..9d0003cdb0 100644 --- a/src/types/format.ts +++ b/src/types/format.ts @@ -1,5 +1,6 @@ import { Locale } from "./locale"; -import { Alias } from "./misc"; + +import { Alias } from "@odoo/o-spreadsheet-engine"; export type Format = string & Alias; diff --git a/src/types/history.ts b/src/types/history.ts index 905685e6dc..0ced37c00b 100644 --- a/src/types/history.ts +++ b/src/types/history.ts @@ -1,6 +1,7 @@ import { Branch } from "../history/branch"; import { Operation } from "../history/operation"; -import { UID } from "./misc"; + +import { UID } from "@odoo/o-spreadsheet-engine"; export interface CreateRevisionOptions { revisionId?: UID; diff --git a/src/types/image.ts b/src/types/image.ts index aec91e1f42..e540fb150a 100644 --- a/src/types/image.ts +++ b/src/types/image.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { FigureSize } from "./figure"; -import { Color } from "./misc"; import { XLSXFigureSize } from "./xlsx"; export type ImageSVG = { diff --git a/src/types/misc.ts b/src/types/misc.ts index 0d1b13bcef..c7cd02ee5d 100644 --- a/src/types/misc.ts +++ b/src/types/misc.ts @@ -1,40 +1,8 @@ -import { CellValue, EvaluatedCell } from "./cells"; - -import type { Validation as EngineValidation } from "@odoo/o-spreadsheet-engine/types/validator"; -import type { CommandResult } from "./commands"; // ----------------------------------------------------------------------------- // MISC // ----------------------------------------------------------------------------- -import { ComponentConstructor } from "@odoo/owl"; -import { Token } from "../formulas"; -import { Format } from "./format"; -import { Range } from "./range"; - -/** - * The following type is meant to be used in union with other aliases to prevent - * Intellisense from resolving it. - * See https://github.com/microsoft/TypeScript/issues/31940#issuecomment-841712377 - */ -export type Alias = {} & {}; - -// Col/row Index -export type HeaderIndex = number & Alias; - -// any DOM pixel value -export type Pixel = number & Alias; - -// Unique identifier -export type UID = string & Alias; export type SetDecimalStep = 1 | -1; -export type FilterId = UID & Alias; -export type TableId = UID & Alias; - -/** - * CSS style color string - * e.g. "#ABC", "#AAAFFF", "rgb(30, 80, 16)" - */ -export type Color = string & Alias; export interface RGBA { a: number; @@ -61,262 +29,10 @@ export interface Link { readonly isUrlEditable: boolean; } -export interface Zone { - left: HeaderIndex; - right: HeaderIndex; - top: HeaderIndex; - bottom: HeaderIndex; -} - -export interface AnchorZone { - zone: Zone; - cell: Position; -} - -export interface Selection { - anchor: AnchorZone; - zones: Zone[]; -} - -export type AdjacentEdge = { - position: "left" | "top" | "bottom" | "right"; - start: HeaderIndex; - stop: HeaderIndex; -}; - -export interface UnboundedZone { - top: HeaderIndex; - bottom: HeaderIndex | undefined; - left: HeaderIndex; - right: HeaderIndex | undefined; - /** - * The hasHeader flag is used to determine if the zone has a header (eg. A2:A or C3:3). - * - * The main issue is that the zone A1:A and A:A have different behavior. The "correct" way to handle this would be to - * allow the top/left to be undefined, but this make typing and using unbounded zones VERY annoying. So we use this - * boolean instead. - */ - hasHeader?: boolean; -} - -export interface ZoneDimension { - numberOfRows: HeaderIndex; - numberOfCols: HeaderIndex; -} - -export type Align = "left" | "right" | "center" | undefined; - -export type VerticalAlign = "top" | "middle" | "bottom" | undefined; - -export type Wrapping = "overflow" | "wrap" | "clip" | undefined; - -export interface Style { - bold?: boolean; - italic?: boolean; - strikethrough?: boolean; - underline?: boolean; - align?: Align; - wrapping?: Wrapping; - verticalAlign?: VerticalAlign; - fillColor?: Color; - textColor?: Color; - fontSize?: number; // in pt, not in px! -} - -export interface DataBarFill { - color: Color; - percentage: number; -} - -export interface UpdateCellData { - content?: string; - formula?: string; - style?: Style | null; - format?: Format; -} - -export interface Sheet { - id: UID; - name: string; - numberOfCols: number; - rows: Row[]; - areGridLinesVisible: boolean; - isVisible: boolean; - panes: PaneDivision; - color?: Color; -} - -export interface CellPosition { - col: HeaderIndex; - row: HeaderIndex; - sheetId: UID; -} - -export const borderStyles = ["thin", "medium", "thick", "dashed", "dotted"] as const; -export type BorderStyle = (typeof borderStyles)[number]; -// A complete border description is a pair [style, color] -export type BorderDescr = { style: BorderStyle; color: Color }; - -/** - * A complete border(s) data is a set of position-color-style information - */ -export type BorderData = { - position: BorderPosition; - color?: Color; - style?: BorderStyle; -}; - -export interface Border { - top?: BorderDescr; - left?: BorderDescr; - bottom?: BorderDescr; - right?: BorderDescr; -} - -export type ReferenceDenormalizer = ( - range: Range, - isMeta: boolean, - functionName: string, - paramNumber: number -) => FunctionResultObject; - -export type EnsureRange = (range: Range, isMeta: boolean) => Matrix; - -export type GetSymbolValue = (symbolName: string) => Arg; - -export type FormulaToExecute = ( - deps: Range[], - refFn: ReferenceDenormalizer, - range: EnsureRange, - getSymbolValue: GetSymbolValue, - ctx: object -) => Matrix | FunctionResultObject; - -export interface CompiledFormula { - execute: FormulaToExecute; - tokens: Token[]; - dependencies: string[]; - isBadExpression: boolean; - normalizedFormula: string; -} - -export interface RangeCompiledFormula extends Omit { - dependencies: Range[]; -} - -export type Matrix = T[][]; - -export type FunctionResultObject = { - value: CellValue; - format?: Format; - errorOriginPosition?: CellPosition; - message?: string; - origin?: CellPosition; -}; - export type FunctionResultNumber = { value: number; format?: string }; -// FORMULA FUNCTION VALUE AND FORMAT INPUT -export type Arg = Maybe | Matrix; // undefined corresponds to the lack of argument, e.g. =SUM(1,2,,4) - -export function isMatrix(x: any): x is Matrix { - return Array.isArray(x) && Array.isArray(x[0]); -} - -export interface ClipboardCell { - evaluatedCell: EvaluatedCell; - position: CellPosition; - content: string; - style?: Style | undefined; - format?: Format | undefined; - tokens?: Token[]; - border?: Border; -} - -export interface HeaderDimensions { - start: Pixel; - size: Pixel; - end: Pixel; -} - -export interface Row { - cells: Record; // number is a column index -} - -export interface Position { - col: HeaderIndex; - row: HeaderIndex; -} - -export interface PixelPosition { - x: Pixel; - y: Pixel; -} - -export interface Merge extends Zone { - id: number; -} - -export interface Highlight { - range: Range; - color: Color; - interactive?: boolean; - thinLine?: boolean; - noFill?: boolean; - /** transparency of the fill color (0-1) */ - fillAlpha?: number; - noBorder?: boolean; - dashed?: boolean; -} - -export interface PaneDivision { - /** Represents the number of frozen columns */ - xSplit: number; - /** Represents the number of frozen rows */ - ySplit: number; -} - -export type BorderPosition = - | "all" - | "hv" - | "h" - | "v" - | "external" - | "left" - | "top" - | "right" - | "bottom" - | "clear"; - -export const enum DIRECTION { - UP = "up", - DOWN = "down", - LEFT = "left", - RIGHT = "right", -} - -export type ChangeType = "REMOVE" | "RESIZE" | "MOVE" | "CHANGE" | "NONE"; -export type ApplyRangeChangeResult = - | { changeType: Exclude; range: Range } - | { changeType: "NONE" }; -export type ApplyRangeChange = (range: Range) => ApplyRangeChangeResult; - -export type AdaptSheetName = { old: string; current: string }; - -export type RangeAdapter = { - sheetId: UID; - sheetName: AdaptSheetName; - applyChange: ApplyRangeChange; -}; - export type Dimension = "COL" | "ROW"; -export type ConsecutiveIndexes = HeaderIndex[]; - -export interface RangeProvider { - adaptRanges: (applyChange: ApplyRangeChange, sheetId: UID, sheetName: AdaptSheetName) => void; -} - export type Validation = EngineValidation; export type Increment = 1 | -1 | 0; @@ -353,8 +69,6 @@ export interface Lazy { map: (callback: (value: T) => U) => Lazy; } -export type Maybe = T | undefined; - export interface Cloneable { clone: (args?: Partial) => T; } @@ -368,10 +82,6 @@ export interface SortOptions { emptyCellAsZero?: boolean; } -export interface MenuMouseEvent extends MouseEvent { - closedMenuId?: UID; -} - // https://github.com/Microsoft/TypeScript/issues/13923#issuecomment-557509399 // prettier-ignore export type Immutable = @@ -387,12 +97,6 @@ type ImmutableMap = ReadonlyMap, Immutable>; type ImmutableSet = ReadonlySet>; type ImmutableObject = { readonly [K in keyof T]: Immutable }; -export interface HeaderGroup { - start: HeaderIndex; - end: HeaderIndex; - isFolded?: boolean; -} - export type Direction = "up" | "down" | "left" | "right"; export type SelectionStep = number | "end"; diff --git a/src/types/pivot.ts b/src/types/pivot.ts index f4b43d1bcd..c9b6670562 100644 --- a/src/types/pivot.ts +++ b/src/types/pivot.ts @@ -1,9 +1,7 @@ +import { FunctionResultObject, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { NEXT_VALUE, PREVIOUS_VALUE } from "../helpers/pivot/pivot_domain_helpers"; import { CellValue } from "./cells"; import { Format } from "./format"; -import { Locale } from "./locale"; -import { Dimension, FunctionResultObject, SortDirection, UID, Zone } from "./misc"; - export type Aggregator = | "array_agg" | "count" diff --git a/src/types/pivot_runtime.ts b/src/types/pivot_runtime.ts index 22dbec62b3..4d22293fe3 100644 --- a/src/types/pivot_runtime.ts +++ b/src/types/pivot_runtime.ts @@ -1,14 +1,6 @@ +import { FunctionResultObject, Maybe } from "@odoo/o-spreadsheet-engine"; import { PivotRuntimeDefinition } from "../helpers/pivot/pivot_runtime_definition"; import { SpreadsheetPivotTable } from "../helpers/pivot/table_spreadsheet_pivot"; -import { FunctionResultObject, Maybe } from "./misc"; -import { - PivotCoreDefinition, - PivotDimension, - PivotDomain, - PivotFields, - PivotMeasure, -} from "./pivot"; - export interface InitPivotParams { reload?: boolean; } diff --git a/src/types/range.ts b/src/types/range.ts index 4819f1f7a1..118e275376 100644 --- a/src/types/range.ts +++ b/src/types/range.ts @@ -1,5 +1,3 @@ -import { UID, UnboundedZone, Zone } from "./misc"; - export interface RangePart { readonly colFixed: boolean; readonly rowFixed: boolean; diff --git a/src/types/rendering.ts b/src/types/rendering.ts index 608b01bd95..6a6f263a57 100644 --- a/src/types/rendering.ts +++ b/src/types/rendering.ts @@ -1,8 +1,14 @@ +import { + Alias, + Align, + BorderDescr, + Color, + DataBarFill, + Pixel, + Style, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { memoize } from "../helpers/misc"; -import { GridIcon } from "../registries/icons_on_cell_registry"; -import { ImageSVG } from "./image"; -import { Alias, Align, BorderDescr, Color, DataBarFill, Pixel, Style, Zone } from "./misc"; - /** * Coordinate in pixels */ diff --git a/src/types/table.ts b/src/types/table.ts index ebdcd784e6..a5a100d0d4 100644 --- a/src/types/table.ts +++ b/src/types/table.ts @@ -1,5 +1,4 @@ -import { DateCriterionValue, GenericCriterionType } from "./generic_criterion"; -import { Border, BorderDescr, Style, TableId, UID } from "./misc"; +import { Border, BorderDescr, Style, TableId, UID } from "@odoo/o-spreadsheet-engine"; import { Range } from "./range"; export interface Table { diff --git a/src/types/workbook_data.ts b/src/types/workbook_data.ts index 2e2a270bed..610ff2f7a5 100644 --- a/src/types/workbook_data.ts +++ b/src/types/workbook_data.ts @@ -1,11 +1,5 @@ -import { CellValue, DataValidationRule, Format, Locale } from "."; -import { ZoneBorderData } from "../plugins/core"; -import { ExcelChartDefinition } from "./chart/chart"; -import { ConditionalFormat } from "./conditional_formatting"; -import { Image } from "./image"; import { Color, - Dimension, HeaderGroup, HeaderIndex, PaneDivision, @@ -13,7 +7,13 @@ import { PixelPosition, Style, UID, -} from "./misc"; +} from "@odoo/o-spreadsheet-engine"; +import { CellValue, DataValidationRule, Format, Locale } from "."; +import { ZoneBorderData } from "../plugins/core"; +import { ExcelChartDefinition } from "./chart/chart"; +import { ConditionalFormat } from "./conditional_formatting"; +import { Image } from "./image"; +import { Dimension } from "./misc"; import { PivotCoreDefinition } from "./pivot"; import { CoreTableType, TableConfig, TableStyleTemplateName } from "./table"; diff --git a/src/types/xlsx.ts b/src/types/xlsx.ts index 2289499c29..a4b372a531 100644 --- a/src/types/xlsx.ts +++ b/src/types/xlsx.ts @@ -1,4 +1,5 @@ -import { Alias, ExcelChartDefinition, Format, PaneDivision, UID } from "."; +import { Alias, PaneDivision, UID } from "@odoo/o-spreadsheet-engine"; +import { ExcelChartDefinition, Format } from "."; import { ExcelImage } from "../types/image"; import { ExcelFigureSize } from "./figure"; diff --git a/src/xlsx/conversion/color_conversion.ts b/src/xlsx/conversion/color_conversion.ts index b5e8ab4160..dfa25cd508 100644 --- a/src/xlsx/conversion/color_conversion.ts +++ b/src/xlsx/conversion/color_conversion.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { colorToRGBA, hslaToRGBA, rgbaToHex, rgbaToHSLA } from "../../helpers"; -import { Color } from "../../types"; import { XLSXColor } from "../../types/xlsx"; import { AUTO_COLOR } from "../constants"; import { XLSX_INDEXED_COLORS } from "./conversion_maps"; diff --git a/src/xlsx/conversion/conversion_maps.ts b/src/xlsx/conversion/conversion_maps.ts index 6edc08c96b..e30695d360 100644 --- a/src/xlsx/conversion/conversion_maps.ts +++ b/src/xlsx/conversion/conversion_maps.ts @@ -1,12 +1,6 @@ +import { Align, BorderStyle, VerticalAlign } from "@odoo/o-spreadsheet-engine"; import { IconSetType } from "../../components/icons/icons"; -import { - Align, - BorderStyle, - ConditionalFormattingOperatorValues, - ExcelChartType, - ThresholdType, - VerticalAlign, -} from "../../types"; +import { ConditionalFormattingOperatorValues, ExcelChartType, ThresholdType } from "../../types"; import { LegendPosition } from "../../types/chart/common_chart"; import { AllowedImageMimeTypes } from "../../types/image"; import { @@ -21,8 +15,6 @@ import { XLSXDataValidationOperatorType, XLSXHorizontalAlignment, } from "../../types/xlsx"; -import { XLSXVerticalAlignment } from "./../../types/xlsx"; - export const SUPPORTED_BORDER_STYLES = ["thin", "medium", "thick", "dashed", "dotted"]; export const SUPPORTED_HORIZONTAL_ALIGNMENTS: XLSXHorizontalAlignment[] = [ "general", diff --git a/src/xlsx/conversion/figure_conversion.ts b/src/xlsx/conversion/figure_conversion.ts index aad75d3492..1eceaeb8bd 100644 --- a/src/xlsx/conversion/figure_conversion.ts +++ b/src/xlsx/conversion/figure_conversion.ts @@ -1,3 +1,4 @@ +import { HeaderIndex, PixelPosition } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_WINDOW_SIZE, FIGURE_BORDER_WIDTH } from "../../constants"; import { getFullReference, @@ -13,8 +14,6 @@ import { ExcelChartDefinition, ExcelChartTrendConfiguration, FigureData, - HeaderIndex, - PixelPosition, TrendConfiguration, } from "../../types"; import { AnchorOffset } from "../../types/figure"; @@ -23,8 +22,6 @@ import { XLSXFigure, XLSXWorksheet } from "../../types/xlsx"; import { convertEMUToDotValue, getColPosition, getRowPosition } from "../helpers/content_helpers"; import { XLSXFigureAnchor } from "./../../types/xlsx"; import { convertColor } from "./color_conversion"; -import { EXCEL_TO_SPREADSHEET_TRENDLINE_TYPE_MAPPING } from "./conversion_maps"; - export function convertFigures(sheetData: XLSXWorksheet): FigureData[] { let id = 1; return sheetData.figures diff --git a/src/xlsx/conversion/sheet_conversion.ts b/src/xlsx/conversion/sheet_conversion.ts index 2599e30ef3..0f6be335b7 100644 --- a/src/xlsx/conversion/sheet_conversion.ts +++ b/src/xlsx/conversion/sheet_conversion.ts @@ -1,3 +1,4 @@ +import { HeaderGroup } from "@odoo/o-spreadsheet-engine"; import { buildSheetLink, largeMax, @@ -7,7 +8,7 @@ import { toCartesian, toXC, } from "../../helpers"; -import { Dimension, HeaderData, HeaderGroup, SheetData } from "../../types"; +import { Dimension, HeaderData, SheetData } from "../../types"; import { XLSXCell, XLSXColumn, diff --git a/src/xlsx/conversion/style_conversion.ts b/src/xlsx/conversion/style_conversion.ts index 9755a0ef80..d08a1f98cf 100644 --- a/src/xlsx/conversion/style_conversion.ts +++ b/src/xlsx/conversion/style_conversion.ts @@ -1,4 +1,4 @@ -import { Border, BorderDescr, Style } from "../../types"; +import { Border, BorderDescr, Style } from "@odoo/o-spreadsheet-engine"; import { XLSXBorder, XLSXBorderDescr, @@ -22,8 +22,6 @@ import { SUPPORTED_VERTICAL_ALIGNMENTS, V_ALIGNMENT_CONVERSION_MAP, } from "./conversion_maps"; -import { convertXlsxFormat } from "./format_conversion"; - interface StyleStruct { fontStyle?: XLSXFont; fillStyle?: XLSXFill; diff --git a/src/xlsx/functions/cells.ts b/src/xlsx/functions/cells.ts index e1ab14cb9c..e34f412c10 100644 --- a/src/xlsx/functions/cells.ts +++ b/src/xlsx/functions/cells.ts @@ -1,6 +1,6 @@ +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { astToFormula } from "../../formulas/formula_formatter"; import { AST, ASTFuncall, ASTString, convertAstNodes, parse } from "../../formulas/parser"; -import { functionRegistry } from "../../functions"; import { formatValue, isNumber } from "../../helpers"; import { mdyDateRegexp, parseDateTime, timeRegexp, ymdDateRegexp } from "../../helpers/dates"; import { CellValue, Format } from "../../types"; diff --git a/src/xlsx/functions/charts.ts b/src/xlsx/functions/charts.ts index 6d017a0c12..bb7627a3dc 100644 --- a/src/xlsx/functions/charts.ts +++ b/src/xlsx/functions/charts.ts @@ -1,7 +1,8 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { CHART_AXIS_TITLE_FONT_SIZE, CHART_TITLE_FONT_SIZE } from "../../constants"; import { ColorGenerator, largeMax, lightenColor, range } from "../../helpers"; import { chartMutedFontColor } from "../../helpers/figures/charts"; -import { Color, ExcelWorkbookData, FigureData } from "../../types"; +import { ExcelWorkbookData, FigureData } from "../../types"; import { ExcelChartDataset, ExcelChartDefinition, TitleDesign } from "../../types/chart/chart"; import { XMLAttributes, XMLString, XlsxHexColor } from "../../types/xlsx"; import { diff --git a/src/xlsx/functions/drawings.ts b/src/xlsx/functions/drawings.ts index b8b6f3d9bc..e4410f224c 100644 --- a/src/xlsx/functions/drawings.ts +++ b/src/xlsx/functions/drawings.ts @@ -1,5 +1,6 @@ +import { HeaderIndex } from "@odoo/o-spreadsheet-engine"; import { FIGURE_BORDER_WIDTH } from "../../constants"; -import { HeaderIndex, SheetData } from "../../types"; +import { SheetData } from "../../types"; import { ExcelChartDefinition } from "../../types/chart/chart"; import { XLSXStructure, XMLAttributes, XMLString } from "../../types/xlsx"; import { DRAWING_NS_A, DRAWING_NS_C, NAMESPACE, RELATIONSHIP_NSR } from "../constants"; diff --git a/src/xlsx/functions/worksheet.ts b/src/xlsx/functions/worksheet.ts index b9df118c54..61c3904136 100644 --- a/src/xlsx/functions/worksheet.ts +++ b/src/xlsx/functions/worksheet.ts @@ -1,3 +1,4 @@ +import { HeaderIndex } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../constants"; import { isInside, @@ -25,7 +26,6 @@ import { normalizeStyle, } from "../helpers/content_helpers"; import { escapeXml, formatAttributes, joinXmlNodes } from "../helpers/xml_helpers"; -import { HeaderIndex } from "./../../types/misc"; import { addContent, addFormula } from "./cells"; export function addColumns(cols: { [key: number]: ExcelHeaderData }): XMLString { diff --git a/src/xlsx/helpers/colors.ts b/src/xlsx/helpers/colors.ts index 425669d765..e7a0421631 100644 --- a/src/xlsx/helpers/colors.ts +++ b/src/xlsx/helpers/colors.ts @@ -1,5 +1,5 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { toHex } from "../../helpers"; -import { Color } from "../../types"; import { XlsxHexColor } from "../../types/xlsx"; /** diff --git a/src/xlsx/helpers/content_helpers.ts b/src/xlsx/helpers/content_helpers.ts index eb52a1ccf8..85dcb00c29 100644 --- a/src/xlsx/helpers/content_helpers.ts +++ b/src/xlsx/helpers/content_helpers.ts @@ -1,3 +1,4 @@ +import { Style, UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_FONT_SIZE, NEWLINE } from "../../constants"; import { getCanonicalRepresentation, @@ -5,13 +6,7 @@ import { splitReference, toUnboundedZone, } from "../../helpers"; -import { - ConditionalFormattingOperatorValues, - ExcelWorkbookData, - Style, - UID, - WorkbookData, -} from "../../types"; +import { ConditionalFormattingOperatorValues, ExcelWorkbookData, WorkbookData } from "../../types"; import { ExtractedStyle, XLSXDataValidationDateOperatorType, diff --git a/src/xlsx/helpers/xml_helpers.ts b/src/xlsx/helpers/xml_helpers.ts index ee1a845305..23c8701213 100644 --- a/src/xlsx/helpers/xml_helpers.ts +++ b/src/xlsx/helpers/xml_helpers.ts @@ -1,6 +1,7 @@ +import { BorderDescr } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_FONT_SIZE } from "../../constants"; import { concat } from "../../helpers"; -import { BorderDescr, ExcelWorkbookData } from "../../types"; +import { ExcelWorkbookData } from "../../types"; import { XLSXBorder, XLSXBorderDescr, diff --git a/tests/__mocks__/transport_service.ts b/tests/__mocks__/transport_service.ts index ce07779010..15a2e89290 100644 --- a/tests/__mocks__/transport_service.ts +++ b/tests/__mocks__/transport_service.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_REVISION_ID } from "../../src/constants"; import { deepCopy } from "../../src/helpers"; -import { UID, WorkbookData } from "../../src/types"; +import { WorkbookData } from "../../src/types"; import { CollaborationMessage, NewMessageCallback, diff --git a/tests/autofill/autofill_plugin.test.ts b/tests/autofill/autofill_plugin.test.ts index 5e0e3bc947..ce6c596dcd 100644 --- a/tests/autofill/autofill_plugin.test.ts +++ b/tests/autofill/autofill_plugin.test.ts @@ -1,7 +1,7 @@ import "../test_helpers/helpers"; import { buildSheetLink, toCartesian, toZone } from "../../src/helpers"; -import { Border, ConditionalFormat, Style } from "../../src/types"; +import { ConditionalFormat } from "../../src/types"; import { addDataValidation, createSheet, @@ -23,19 +23,18 @@ import { getStyle, } from "../test_helpers/getters_helpers"; import { - XCToMergeCellMap, addToRegistry, getDataValidationRules, getMergeCellMap, getPlugin, makeTestComposerStore, toRangesData, + XCToMergeCellMap, } from "../test_helpers/helpers"; +import { Border, DIRECTION, functionRegistry, Style } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; -import { functionRegistry } from "../../src/functions"; import { AutofillPlugin } from "../../src/plugins/ui_feature/autofill"; -import { DIRECTION } from "../../src/types/index"; let autoFill: AutofillPlugin; let model: Model; diff --git a/tests/borders/border_editor_widget_component.test.ts b/tests/borders/border_editor_widget_component.test.ts index f3e07ddd2f..a05c327d18 100644 --- a/tests/borders/border_editor_widget_component.test.ts +++ b/tests/borders/border_editor_widget_component.test.ts @@ -1,11 +1,10 @@ +import { BorderPosition, BorderStyle, Color } from "@odoo/o-spreadsheet-engine"; import { Component, useState, xml } from "@odoo/owl"; -import { BorderPosition, BorderStyle, Color, Model, SpreadsheetChildEnv } from "../../src"; +import { Model, SpreadsheetChildEnv } from "../../src"; import { BorderEditorWidget } from "../../src/components/border_editor/border_editor_widget"; import { toHex, toZone } from "../../src/helpers"; import { click, simulateClick } from "../test_helpers/dom_helper"; import { mountComponent } from "../test_helpers/helpers"; -import { extendMockGetBoundingClientRect } from "../test_helpers/mock_helpers"; - let fixture: HTMLElement; let model: Model; type Props = BorderEditorWidget["props"]; diff --git a/tests/borders/border_plugin.test.ts b/tests/borders/border_plugin.test.ts index 129dceae91..6c2ae57cc5 100644 --- a/tests/borders/border_plugin.test.ts +++ b/tests/borders/border_plugin.test.ts @@ -1,9 +1,10 @@ +import { BorderDescr } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_BORDER_DESC } from "../../src/constants"; import { toZone } from "../../src/helpers"; import { removeFalsyAttributes } from "../../src/helpers/misc"; import { Model } from "../../src/model"; import { BordersPlugin } from "../../src/plugins/core"; -import { BorderDescr, CommandResult } from "../../src/types/index"; +import { CommandResult } from "../../src/types/index"; import { addColumns, addRows, diff --git a/tests/bottom_bar/aggregate_statistics_store.test.ts b/tests/bottom_bar/aggregate_statistics_store.test.ts index 16ebaa7d3a..a8e1587975 100644 --- a/tests/bottom_bar/aggregate_statistics_store.test.ts +++ b/tests/bottom_bar/aggregate_statistics_store.test.ts @@ -1,6 +1,6 @@ +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { AggregateStatisticsStore } from "../../src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store"; -import { functionRegistry } from "../../src/functions"; import { activateSheet, addCellToSelection, diff --git a/tests/bottom_bar/bottom_bar_component.test.ts b/tests/bottom_bar/bottom_bar_component.test.ts index a2e0cbf586..25cc2946a5 100644 --- a/tests/bottom_bar/bottom_bar_component.test.ts +++ b/tests/bottom_bar/bottom_bar_component.test.ts @@ -1,10 +1,11 @@ +import { Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { BottomBar } from "../../src/components/bottom_bar/bottom_bar"; import { toHex } from "../../src/helpers"; import { interactiveRenameSheet } from "../../src/helpers/ui/sheet_interactive"; import { Model } from "../../src/model"; import { DOMFocusableElementStore } from "../../src/stores/DOM_focus_store"; -import { Pixel, SpreadsheetChildEnv, UID } from "../../src/types"; +import { SpreadsheetChildEnv } from "../../src/types"; import { activateSheet, createSheet, @@ -34,8 +35,6 @@ import { nextTick, setMobileMode, } from "../test_helpers/helpers"; -import { extendMockGetBoundingClientRect } from "../test_helpers/mock_helpers"; - let fixture: HTMLElement; function isDragAndDropActive(): boolean { diff --git a/tests/cells/cell_plugin.test.ts b/tests/cells/cell_plugin.test.ts index 73e7857817..98a6fc2cd6 100644 --- a/tests/cells/cell_plugin.test.ts +++ b/tests/cells/cell_plugin.test.ts @@ -1,9 +1,10 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { CoreCommand, CorePlugin, Model } from "../../src"; import { LINK_COLOR } from "../../src/constants"; import { buildSheetLink, toZone } from "../../src/helpers"; import { urlRepresentation } from "../../src/helpers/links"; import { corePluginRegistry } from "../../src/plugins"; -import { CellValueType, CommandResult, UID } from "../../src/types"; +import { CellValueType, CommandResult } from "../../src/types"; import { addColumns, addRows, diff --git a/tests/clipboard/clipboard_figure_plugin.test.ts b/tests/clipboard/clipboard_figure_plugin.test.ts index f7f915b940..5b12124f75 100644 --- a/tests/clipboard/clipboard_figure_plugin.test.ts +++ b/tests/clipboard/clipboard_figure_plugin.test.ts @@ -1,7 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { CommandResult, Model } from "../../src"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../src/constants"; import { parseOSClipboardContent } from "../../src/helpers/clipboard/clipboard_helpers"; -import { UID } from "../../src/types"; import { BarChartDefinition } from "../../src/types/chart"; import { activateSheet, diff --git a/tests/collaborative/collaborative.test.ts b/tests/collaborative/collaborative.test.ts index 2c735a14a1..4311701c09 100644 --- a/tests/collaborative/collaborative.test.ts +++ b/tests/collaborative/collaborative.test.ts @@ -1,6 +1,6 @@ +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { Model, UIPlugin } from "../../src"; import { DEBOUNCE_TIME, DEFAULT_REVISION_ID, MESSAGE_VERSION } from "../../src/constants"; -import { functionRegistry } from "../../src/functions"; import { getDefaultCellHeight, range, toZone, zoneToXc } from "../../src/helpers"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { featurePluginRegistry } from "../../src/plugins"; diff --git a/tests/collaborative/collaborative_monkey_party.test.ts b/tests/collaborative/collaborative_monkey_party.test.ts index 6f61b2af99..194da3d5f6 100644 --- a/tests/collaborative/collaborative_monkey_party.test.ts +++ b/tests/collaborative/collaborative_monkey_party.test.ts @@ -1,3 +1,4 @@ +import { UnboundedZone } from "@odoo/o-spreadsheet-engine"; import { FunctionCodeBuilder } from "@odoo/o-spreadsheet-engine/formulas/code_builder"; import seedrandom from "seedrandom"; import { Model } from "../../src"; @@ -5,7 +6,6 @@ import { deepCopy, deepEquals, range, reorderZone } from "../../src/helpers"; import { Command, CoreCommand, - UnboundedZone, isPositionDependent, isRangeDependant, isSheetDependent, diff --git a/tests/collaborative/ot/ot_helper.ts b/tests/collaborative/ot/ot_helper.ts index 43f6b8e5af..8f403b7945 100644 --- a/tests/collaborative/ot/ot_helper.ts +++ b/tests/collaborative/ot/ot_helper.ts @@ -1,9 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { AddConditionalFormatCommand, AddDataValidationCommand, AddPivotCommand, CoreCommand, - UID, UpdateCellCommand, } from "../../../src"; import { deepCopy } from "../../../src/helpers"; diff --git a/tests/colors/color_helpers.test.ts b/tests/colors/color_helpers.test.ts index 7900ef42ca..1c0dddefad 100644 --- a/tests/colors/color_helpers.test.ts +++ b/tests/colors/color_helpers.test.ts @@ -1,3 +1,4 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { colorToNumber, colorToRGBA, @@ -9,7 +10,7 @@ import { rgbaToHSLA, toHex, } from "../../src/helpers/color"; -import { Color, HSLA, RGBA } from "../../src/types"; +import { HSLA, RGBA } from "../../src/types"; const testColors: { input: Color; hex: Color; rgba: RGBA; hsla: HSLA }[] = [ { diff --git a/tests/colors/color_picker_component.test.ts b/tests/colors/color_picker_component.test.ts index 37a6fffb0b..49c18861d4 100644 --- a/tests/colors/color_picker_component.test.ts +++ b/tests/colors/color_picker_component.test.ts @@ -1,7 +1,7 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { ColorPicker, ColorPickerProps } from "../../src/components/color_picker/color_picker"; import { toHex } from "../../src/helpers"; -import { Color } from "../../src/types"; import { setStyle } from "../test_helpers/commands_helpers"; import { getElComputedStyle, diff --git a/tests/colors/custom_colors_plugin.test.ts b/tests/colors/custom_colors_plugin.test.ts index 21d7bef6f8..401fb14dd3 100644 --- a/tests/colors/custom_colors_plugin.test.ts +++ b/tests/colors/custom_colors_plugin.test.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { TABLE_PRESETS } from "../../src/helpers/table_presets"; -import { TableStyle, UID } from "../../src/types"; +import { TableStyle } from "../../src/types"; import { createChart, createScorecardChart, diff --git a/tests/components/pivot_html_renderer.test.ts b/tests/components/pivot_html_renderer.test.ts index c3ff1959f6..784888b1a2 100644 --- a/tests/components/pivot_html_renderer.test.ts +++ b/tests/components/pivot_html_renderer.test.ts @@ -1,4 +1,5 @@ -import { Model, UID } from "../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model } from "../../src"; import { PivotHTMLRenderer } from "../../src/components/pivot_html_renderer/pivot_html_renderer"; import { createSheet } from "../test_helpers/commands_helpers"; import { click } from "../test_helpers/dom_helper"; diff --git a/tests/composer/autocomplete_dropdown_component.test.ts b/tests/composer/autocomplete_dropdown_component.test.ts index faf856fb17..4195ee01bb 100644 --- a/tests/composer/autocomplete_dropdown_component.test.ts +++ b/tests/composer/autocomplete_dropdown_component.test.ts @@ -1,7 +1,7 @@ +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { registries } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../src/constants"; -import { functionRegistry } from "../../src/functions/index"; import { Model } from "../../src/model"; import { autoCompleteProviders } from "../../src/registries/auto_completes"; import { Store } from "../../src/store_engine"; diff --git a/tests/composer/composer_integration_component.test.ts b/tests/composer/composer_integration_component.test.ts index 7bda1e804a..74364f09bf 100644 --- a/tests/composer/composer_integration_component.test.ts +++ b/tests/composer/composer_integration_component.test.ts @@ -1,4 +1,5 @@ -import { HeaderIndex, Model } from "../../src"; +import { HeaderIndex } from "@odoo/o-spreadsheet-engine"; +import { Model } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { DEFAULT_CELL_HEIGHT, diff --git a/tests/composer/formula_assistant_component.test.ts b/tests/composer/formula_assistant_component.test.ts index 1c8a830093..673c8b3f36 100644 --- a/tests/composer/formula_assistant_component.test.ts +++ b/tests/composer/formula_assistant_component.test.ts @@ -1,6 +1,7 @@ +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { setTranslationMethod } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; -import { arg, functionRegistry } from "../../src/functions/index"; +import { arg } from "../../src/functions/index"; import { Store } from "../../src/store_engine"; import { _t } from "../../src/translation"; import { DEFAULT_LOCALE } from "../../src/types"; diff --git a/tests/conditional_formatting/conditional_formatting_panel_component.test.ts b/tests/conditional_formatting/conditional_formatting_panel_component.test.ts index b9aabfed50..8117bd469e 100644 --- a/tests/conditional_formatting/conditional_formatting_panel_component.test.ts +++ b/tests/conditional_formatting/conditional_formatting_panel_component.test.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; import { Model } from "../../src"; import { ConditionalFormattingPanel } from "../../src/components/side_panel/conditional_formatting/conditional_formatting"; @@ -8,7 +9,6 @@ import { CommandResult, ConditionalFormattingOperatorValues, SpreadsheetChildEnv, - UID, } from "../../src/types"; import { activateSheet, diff --git a/tests/conditional_formatting/conditional_formatting_plugin.test.ts b/tests/conditional_formatting/conditional_formatting_plugin.test.ts index 7e41e785c9..d0eea1e853 100644 --- a/tests/conditional_formatting/conditional_formatting_plugin.test.ts +++ b/tests/conditional_formatting/conditional_formatting_plugin.test.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src/model"; -import { CommandResult, ConditionalFormattingOperatorValues, UID } from "../../src/types"; +import { CommandResult, ConditionalFormattingOperatorValues } from "../../src/types"; import { ConditionalFormat, ConditionalFormatRule } from "../../src/types/conditional_formatting"; import { activateSheet, diff --git a/tests/data_validation/data_validation_blocking_component.test.ts b/tests/data_validation/data_validation_blocking_component.test.ts index d0a9d3e424..5411cfa496 100644 --- a/tests/data_validation/data_validation_blocking_component.test.ts +++ b/tests/data_validation/data_validation_blocking_component.test.ts @@ -1,7 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { Store } from "../../src/store_engine"; -import { UID } from "../../src/types"; import { addDataValidation, setCellContent, updateLocale } from "../test_helpers/commands_helpers"; import { FR_LOCALE } from "../test_helpers/constants"; import { keyDown } from "../test_helpers/dom_helper"; diff --git a/tests/data_validation/data_validation_checkbox_plugin.test.ts b/tests/data_validation/data_validation_checkbox_plugin.test.ts index 7bc7935e88..c09e984650 100644 --- a/tests/data_validation/data_validation_checkbox_plugin.test.ts +++ b/tests/data_validation/data_validation_checkbox_plugin.test.ts @@ -1,4 +1,5 @@ -import { Model, UID } from "../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model } from "../../src"; import { addDataValidation, deleteContent, diff --git a/tests/data_validation/data_validation_clipboard_plugin.test.ts b/tests/data_validation/data_validation_clipboard_plugin.test.ts index 8affcb8475..50184db102 100644 --- a/tests/data_validation/data_validation_clipboard_plugin.test.ts +++ b/tests/data_validation/data_validation_clipboard_plugin.test.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model, UIPlugin } from "../../src"; import { featurePluginRegistry } from "../../src/plugins"; -import { Command, DataValidationCriterion, UID } from "../../src/types"; +import { Command, DataValidationCriterion } from "../../src/types"; import { activateSheet, addDataValidation, diff --git a/tests/data_validation/data_validation_core_plugin.test.ts b/tests/data_validation/data_validation_core_plugin.test.ts index 9b3a47a38c..8f0fb944cc 100644 --- a/tests/data_validation/data_validation_core_plugin.test.ts +++ b/tests/data_validation/data_validation_core_plugin.test.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { CommandResult, Model } from "../../src"; -import { DataValidationCriterion, UID } from "../../src/types"; +import { DataValidationCriterion } from "../../src/types"; import { addColumns, addDataValidation, diff --git a/tests/data_validation/data_validation_generics_side_panel_component.test.ts b/tests/data_validation/data_validation_generics_side_panel_component.test.ts index 75a6c1324d..ac21a858dc 100644 --- a/tests/data_validation/data_validation_generics_side_panel_component.test.ts +++ b/tests/data_validation/data_validation_generics_side_panel_component.test.ts @@ -1,6 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { DataValidationPanel } from "../../src/components/side_panel/data_validation/data_validation_panel"; -import { UID } from "../../src/types"; import { addDataValidation, updateLocale } from "../test_helpers/commands_helpers"; import { FR_LOCALE } from "../test_helpers/constants"; import { click, setInputValueAndTrigger, simulateClick } from "../test_helpers/dom_helper"; diff --git a/tests/data_validation/data_validation_list_component.test.ts b/tests/data_validation/data_validation_list_component.test.ts index 7f5bac58b7..381975f9a9 100644 --- a/tests/data_validation/data_validation_list_component.test.ts +++ b/tests/data_validation/data_validation_list_component.test.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { @@ -8,7 +9,7 @@ import { MIN_CELL_TEXT_MARGIN, } from "../../src/constants"; import { toZone } from "../../src/helpers"; -import { IsValueInListCriterion, SpreadsheetChildEnv, UID } from "../../src/types"; +import { IsValueInListCriterion, SpreadsheetChildEnv } from "../../src/types"; import { addDataValidation, createTableWithFilter, diff --git a/tests/data_validation/data_validation_registry.test.ts b/tests/data_validation/data_validation_registry.test.ts index 8200ea5e25..22ebd66be2 100644 --- a/tests/data_validation/data_validation_registry.test.ts +++ b/tests/data_validation/data_validation_registry.test.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { parseLiteral } from "../../src/helpers/cells"; import { @@ -11,7 +12,6 @@ import { EvaluatedCriterion, GenericDateCriterion, Getters, - UID, } from "../../src/types"; import { addDataValidation, setCellContent, updateLocale } from "../test_helpers/commands_helpers"; import { FR_LOCALE } from "../test_helpers/constants"; diff --git a/tests/data_validation/evaluation_data_validation_plugin.test.ts b/tests/data_validation/evaluation_data_validation_plugin.test.ts index 8f3be263d5..ab9d95a218 100644 --- a/tests/data_validation/evaluation_data_validation_plugin.test.ts +++ b/tests/data_validation/evaluation_data_validation_plugin.test.ts @@ -1,5 +1,6 @@ +import { CellPosition, UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; -import { CellPosition, DataValidationCriterion, UID } from "../../src/types"; +import { DataValidationCriterion } from "../../src/types"; import { addDataValidation, duplicateSheet, diff --git a/tests/evaluation/compiler.test.ts b/tests/evaluation/compiler.test.ts index e2a4aeb772..c000a2a3d8 100644 --- a/tests/evaluation/compiler.test.ts +++ b/tests/evaluation/compiler.test.ts @@ -1,11 +1,8 @@ +import { CompiledFormula, functionRegistry } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { functionCache } from "../../src/formulas/compiler"; import { compile } from "../../src/formulas/index"; -import { functionRegistry } from "../../src/functions"; import { createValidRange } from "../../src/helpers"; -import { CompiledFormula } from "../../src/types"; -import { addToRegistry, evaluateCell, evaluateCellFormat } from "../test_helpers/helpers"; - function compiledBaseFunction(formula: string): CompiledFormula { for (const f in functionCache) { delete functionCache[f]; diff --git a/tests/evaluation/evaluation.test.ts b/tests/evaluation/evaluation.test.ts index 75efb66ece..42bbdb999d 100644 --- a/tests/evaluation/evaluation.test.ts +++ b/tests/evaluation/evaluation.test.ts @@ -1,8 +1,9 @@ -import { arg, functionRegistry } from "../../src/functions"; +import { functionRegistry, UID } from "@odoo/o-spreadsheet-engine"; +import { arg } from "../../src/functions"; import { toMatrix } from "../../src/functions/helpers"; import { toCartesian } from "../../src/helpers/coordinates"; import { Model } from "../../src/model"; -import { CellValueType, ErrorCell, UID } from "../../src/types"; +import { CellValueType, ErrorCell } from "../../src/types"; import { CellErrorType, EvaluationError } from "../../src/types/errors"; import { activateSheet, diff --git a/tests/evaluation/evaluation_formula_array.test.ts b/tests/evaluation/evaluation_formula_array.test.ts index 81b12c80b9..9972cc17a1 100644 --- a/tests/evaluation/evaluation_formula_array.test.ts +++ b/tests/evaluation/evaluation_formula_array.test.ts @@ -1,9 +1,10 @@ -import { arg, functionRegistry } from "../../src/functions"; +import { functionRegistry, UID } from "@odoo/o-spreadsheet-engine"; +import { arg } from "../../src/functions"; import { toScalar } from "../../src/functions/helper_matrices"; import { toMatrix, toNumber } from "../../src/functions/helpers"; import { toCartesian, toZone } from "../../src/helpers"; import { Model } from "../../src/model"; -import { DEFAULT_LOCALE, ErrorCell, UID } from "../../src/types"; +import { DEFAULT_LOCALE, ErrorCell } from "../../src/types"; import { addColumns, addRows, @@ -18,8 +19,6 @@ import { unMerge, } from "../test_helpers/commands_helpers"; import { getCellContent, getCellError, getEvaluatedCell } from "../test_helpers/getters_helpers"; -import { addToRegistry } from "../test_helpers/helpers"; - let model: Model; let sheetId: UID; diff --git a/tests/figures/carousel/carousel_figure_component.test.ts b/tests/figures/carousel/carousel_figure_component.test.ts index e80bb30e78..076d4412f5 100644 --- a/tests/figures/carousel/carousel_figure_component.test.ts +++ b/tests/figures/carousel/carousel_figure_component.test.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { ChartConfiguration } from "chart.js"; -import { Model, SpreadsheetChildEnv, UID } from "../../../src"; +import { Model, SpreadsheetChildEnv } from "../../../src"; import { getCarouselMenuActions } from "../../../src/actions/figure_menu_actions"; import { ChartAnimationStore } from "../../../src/components/figures/chart/chartJs/chartjs_animation_store"; import { downloadFile } from "../../../src/components/helpers/dom_helpers"; diff --git a/tests/figures/carousel/carousel_panel_component.test.ts b/tests/figures/carousel/carousel_panel_component.test.ts index a53997a805..765b8be73f 100644 --- a/tests/figures/carousel/carousel_panel_component.test.ts +++ b/tests/figures/carousel/carousel_panel_component.test.ts @@ -1,4 +1,5 @@ -import { Model, SpreadsheetChildEnv, UID } from "../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model, SpreadsheetChildEnv } from "../../../src"; import { SidePanels } from "../../../src/components/side_panel/side_panels/side_panels"; import { addNewChartToCarousel, diff --git a/tests/figures/carousel/carousel_plugin.test.ts b/tests/figures/carousel/carousel_plugin.test.ts index 586fb7f7ed..adc3b693ae 100644 --- a/tests/figures/carousel/carousel_plugin.test.ts +++ b/tests/figures/carousel/carousel_plugin.test.ts @@ -1,4 +1,5 @@ -import { CommandResult, Model, UID } from "../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { CommandResult, Model } from "../../../src"; import { CAROUSEL_DEFAULT_CHART_DEFINITION } from "../../../src/helpers/carousel_helpers"; import { addChartFigureToCarousel, diff --git a/tests/figures/chart/chart_tooltip.test.ts b/tests/figures/chart/chart_tooltip.test.ts index 7d8a028b8c..5d5cef5a07 100644 --- a/tests/figures/chart/chart_tooltip.test.ts +++ b/tests/figures/chart/chart_tooltip.test.ts @@ -1,4 +1,5 @@ -import { ChartJSRuntime, Color, Model } from "../../../src"; +import { Color } from "@odoo/o-spreadsheet-engine"; +import { ChartJSRuntime, Model } from "../../../src"; import { createChart, updateChart } from "../../test_helpers/commands_helpers"; interface TooltipArgs { diff --git a/tests/figures/chart/charts_component.test.ts b/tests/figures/chart/charts_component.test.ts index 3a1ab18102..ada37bed91 100644 --- a/tests/figures/chart/charts_component.test.ts +++ b/tests/figures/chart/charts_component.test.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { App } from "@odoo/owl"; import { CommandResult, Model, Spreadsheet } from "../../../src"; import { ChartPanel } from "../../../src/components/side_panel/chart/main_chart_panel/main_chart_panel"; @@ -17,7 +18,6 @@ import { ChartWithDataSetDefinition, CreateFigureCommand, SpreadsheetChildEnv, - UID, } from "../../../src/types"; import { PieChartRuntime, TrendConfiguration } from "../../../src/types/chart"; import { BarChartDefinition, BarChartRuntime } from "../../../src/types/chart/bar_chart"; diff --git a/tests/figures/chart/charts_zoom.test.ts b/tests/figures/chart/charts_zoom.test.ts index edc548d396..a0094663dd 100644 --- a/tests/figures/chart/charts_zoom.test.ts +++ b/tests/figures/chart/charts_zoom.test.ts @@ -1,7 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../../src"; import { ZoomableChartStore } from "../../../src/components/figures/chart/chartJs/zoomable_chart/zoomable_chart_store"; import { ChartPanel } from "../../../src/components/side_panel/chart/main_chart_panel/main_chart_panel"; -import { CreateFigureCommand, SpreadsheetChildEnv, UID } from "../../../src/types"; +import { CreateFigureCommand, SpreadsheetChildEnv } from "../../../src/types"; import { LineChartDefinition } from "../../../src/types/chart/line_chart"; import { openChartDesignSidePanel } from "../../test_helpers/chart_helpers"; import { createChart, setCellContent } from "../../test_helpers/commands_helpers"; diff --git a/tests/figures/chart/common_chart_plugin.test.ts b/tests/figures/chart/common_chart_plugin.test.ts index 75a5a2a4a4..0df701dd26 100644 --- a/tests/figures/chart/common_chart_plugin.test.ts +++ b/tests/figures/chart/common_chart_plugin.test.ts @@ -1,6 +1,6 @@ +import { Color, UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../../src"; import { BACKGROUND_CHART_COLOR } from "../../../src/constants"; -import { Color, UID } from "../../../src/types"; import { activateSheet, createChart, diff --git a/tests/figures/chart/funnel/funnel_chart_plugin.test.ts b/tests/figures/chart/funnel/funnel_chart_plugin.test.ts index 9accf6f120..9246bcfdb4 100644 --- a/tests/figures/chart/funnel/funnel_chart_plugin.test.ts +++ b/tests/figures/chart/funnel/funnel_chart_plugin.test.ts @@ -1,4 +1,5 @@ -import { ChartCreationContext, Model, UID } from "../../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { ChartCreationContext, Model } from "../../../../src"; import { ColorGenerator } from "../../../../src/helpers"; import { FunnelChart } from "../../../../src/helpers/figures/charts/funnel_chart"; import { FunnelChartRuntime } from "../../../../src/types/chart/funnel_chart"; diff --git a/tests/figures/chart/geochart/geo_chart_panel_component.test.ts b/tests/figures/chart/geochart/geo_chart_panel_component.test.ts index 6f055e93b4..20c60f5f4d 100644 --- a/tests/figures/chart/geochart/geo_chart_panel_component.test.ts +++ b/tests/figures/chart/geochart/geo_chart_panel_component.test.ts @@ -1,4 +1,5 @@ -import { Model, SpreadsheetChildEnv, UID } from "../../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model, SpreadsheetChildEnv } from "../../../../src"; import { SidePanels } from "../../../../src/components/side_panel/side_panels/side_panels"; import { GeoChartDefinition } from "../../../../src/types/chart/geo_chart"; import { diff --git a/tests/figures/chart/scorecard/scorecard_chart_component.test.ts b/tests/figures/chart/scorecard/scorecard_chart_component.test.ts index 4b771bac57..243a7dfcb5 100644 --- a/tests/figures/chart/scorecard/scorecard_chart_component.test.ts +++ b/tests/figures/chart/scorecard/scorecard_chart_component.test.ts @@ -1,3 +1,4 @@ +import { Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../../../src"; import { SidePanels } from "../../../../src/components/side_panel/side_panels/side_panels"; import { @@ -10,7 +11,7 @@ import { ScorecardChartConfig, getScorecardConfiguration, } from "../../../../src/helpers/figures/charts/scorecard_chart_config_builder"; -import { Pixel, SpreadsheetChildEnv, UID } from "../../../../src/types"; +import { SpreadsheetChildEnv } from "../../../../src/types"; import { ScorecardChartDefinition, ScorecardChartRuntime, @@ -28,12 +29,6 @@ import { } from "../../../test_helpers/commands_helpers"; import { FR_LOCALE } from "../../../test_helpers/constants"; import { getCellContent } from "../../../test_helpers/getters_helpers"; -import { - mountComponentWithPortalTarget, - nextTick, - toRangesData, -} from "../../../test_helpers/helpers"; - let model: Model; let chartId: string; let sheetId: string; diff --git a/tests/figures/chart/sunburst/sunburst_chart_plugin.test.ts b/tests/figures/chart/sunburst/sunburst_chart_plugin.test.ts index 268101dccf..33fe8c0424 100644 --- a/tests/figures/chart/sunburst/sunburst_chart_plugin.test.ts +++ b/tests/figures/chart/sunburst/sunburst_chart_plugin.test.ts @@ -1,4 +1,5 @@ -import { Model, UID } from "../../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model } from "../../../../src"; import { COLOR_TRANSPARENT } from "../../../../src/constants"; import { ColorGenerator } from "../../../../src/helpers"; import { GHOST_SUNBURST_VALUE } from "../../../../src/helpers/figures/charts/runtime"; diff --git a/tests/figures/chart/sunburst/sunburst_panel_component.test.ts b/tests/figures/chart/sunburst/sunburst_panel_component.test.ts index 6b4ad7e9db..ab11997038 100644 --- a/tests/figures/chart/sunburst/sunburst_panel_component.test.ts +++ b/tests/figures/chart/sunburst/sunburst_panel_component.test.ts @@ -1,4 +1,5 @@ -import { Model, SpreadsheetChildEnv, UID } from "../../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model, SpreadsheetChildEnv } from "../../../../src"; import { SidePanels } from "../../../../src/components/side_panel/side_panels/side_panels"; import { ColorGenerator } from "../../../../src/helpers"; import { SunburstChartDefinition } from "../../../../src/types/chart"; diff --git a/tests/figures/chart/treemap/treemap_chart_plugin.test.ts b/tests/figures/chart/treemap/treemap_chart_plugin.test.ts index 5b95864824..3a87f1fd00 100644 --- a/tests/figures/chart/treemap/treemap_chart_plugin.test.ts +++ b/tests/figures/chart/treemap/treemap_chart_plugin.test.ts @@ -1,4 +1,5 @@ -import { ChartCreationContext, Model, UID } from "../../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { ChartCreationContext, Model } from "../../../../src"; import { ColorGenerator, lightenColor } from "../../../../src/helpers"; import { TreeMapChart } from "../../../../src/helpers/figures/charts/tree_map_chart"; import { TreeMapChartRuntime } from "../../../../src/types/chart/tree_map_chart"; diff --git a/tests/figures/chart/treemap/treemap_panel_component.test.ts b/tests/figures/chart/treemap/treemap_panel_component.test.ts index 3b0422c5aa..873ad7268f 100644 --- a/tests/figures/chart/treemap/treemap_panel_component.test.ts +++ b/tests/figures/chart/treemap/treemap_panel_component.test.ts @@ -1,4 +1,5 @@ -import { Model, SpreadsheetChildEnv, UID } from "../../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model, SpreadsheetChildEnv } from "../../../../src"; import { SidePanels } from "../../../../src/components/side_panel/side_panels/side_panels"; import { ColorGenerator } from "../../../../src/helpers"; import { TreeMapChartDefinition } from "../../../../src/types/chart/tree_map_chart"; diff --git a/tests/figures/chart/waterfall/waterfall_chart_plugin.test.ts b/tests/figures/chart/waterfall/waterfall_chart_plugin.test.ts index 5ada8a27c1..31b0554ec7 100644 --- a/tests/figures/chart/waterfall/waterfall_chart_plugin.test.ts +++ b/tests/figures/chart/waterfall/waterfall_chart_plugin.test.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { ChartMeta } from "chart.js"; -import { ChartCreationContext, Model, UID } from "../../../../src"; +import { ChartCreationContext, Model } from "../../../../src"; import { CHART_WATERFALL_NEGATIVE_COLOR, CHART_WATERFALL_POSITIVE_COLOR, diff --git a/tests/figures/chart/waterfall/waterfall_panel_component.test.ts b/tests/figures/chart/waterfall/waterfall_panel_component.test.ts index 38ef0616af..64976559ba 100644 --- a/tests/figures/chart/waterfall/waterfall_panel_component.test.ts +++ b/tests/figures/chart/waterfall/waterfall_panel_component.test.ts @@ -1,4 +1,5 @@ -import { Model, SpreadsheetChildEnv, UID } from "../../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model, SpreadsheetChildEnv } from "../../../../src"; import { SidePanels } from "../../../../src/components/side_panel/side_panels/side_panels"; import { WaterfallChartDefinition } from "../../../../src/types/chart/waterfall_chart"; import { diff --git a/tests/figures/figure_component.test.ts b/tests/figures/figure_component.test.ts index 3829995e14..f03c12f06e 100644 --- a/tests/figures/figure_component.test.ts +++ b/tests/figures/figure_component.test.ts @@ -8,8 +8,9 @@ import { MENU_WIDTH, SELECTION_BORDER_COLOR, } from "../../src/constants"; -import { Figure, Pixel, Position, SpreadsheetChildEnv, UID } from "../../src/types"; +import { Figure, SpreadsheetChildEnv } from "../../src/types"; +import { Pixel, Position, UID } from "@odoo/o-spreadsheet-engine"; import { FigureComponent } from "../../src/components/figures/figure/figure"; import { ChartFigure } from "../../src/components/figures/figure_chart/figure_chart"; import { downloadFile } from "../../src/components/helpers/dom_helpers"; diff --git a/tests/find_and_replace/find_and_replace_store.test.ts b/tests/find_and_replace/find_and_replace_store.test.ts index cd250edcc1..46d7e6e52c 100644 --- a/tests/find_and_replace/find_and_replace_store.test.ts +++ b/tests/find_and_replace/find_and_replace_store.test.ts @@ -1,10 +1,9 @@ +import { functionRegistry, UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { FindAndReplaceStore } from "../../src/components/side_panel/find_and_replace/find_and_replace_store"; -import { functionRegistry } from "../../src/functions"; import { toZone, zoneToXc } from "../../src/helpers"; import { DependencyContainer } from "../../src/store_engine"; import { NotificationStore } from "../../src/stores/notification_store"; -import { UID } from "../../src/types"; import { SearchOptions } from "../../src/types/find_and_replace"; import { DEFAULT_LOCALE } from "../../src/types/locale"; import { diff --git a/tests/formats/formatting_plugin.test.ts b/tests/formats/formatting_plugin.test.ts index 020962f4a7..3d506c6751 100644 --- a/tests/formats/formatting_plugin.test.ts +++ b/tests/formats/formatting_plugin.test.ts @@ -1,3 +1,4 @@ +import { functionRegistry, UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH, @@ -10,12 +11,12 @@ import { PADDING_AUTORESIZE_HORIZONTAL, PADDING_AUTORESIZE_VERTICAL, } from "../../src/constants"; -import { arg, functionRegistry } from "../../src/functions"; +import { arg } from "../../src/functions"; import { toScalar } from "../../src/functions/helper_matrices"; import { toString } from "../../src/functions/helpers"; import { fontSizeInPixels, getCellContentHeight, toCartesian } from "../../src/helpers"; import { Model } from "../../src/model"; -import { CommandResult, Format, SetDecimalStep, UID } from "../../src/types"; +import { CommandResult, Format, SetDecimalStep } from "../../src/types"; import { createSheet, createTableWithFilter, @@ -41,8 +42,6 @@ import { spyUiPluginHandle, target, } from "../test_helpers/helpers"; -import { addPivot } from "../test_helpers/pivot_helpers"; - function setDecimal(model: Model, targetXc: string, step: SetDecimalStep) { model.dispatch("SET_DECIMAL", { sheetId: model.getters.getActiveSheetId(), diff --git a/tests/functions/arguments.test.ts b/tests/functions/arguments.test.ts index 1916598258..eb56e9f226 100644 --- a/tests/functions/arguments.test.ts +++ b/tests/functions/arguments.test.ts @@ -4,7 +4,8 @@ import { argTargeting, validateArguments, } from "../../src/functions/arguments"; -import { AddFunctionDescription } from "../../src/types"; + +import { Functions } from "@odoo/o-spreadsheet-engine"; describe("args", () => { test("various", () => { @@ -126,7 +127,7 @@ describe("args", () => { }); describe("arguments validation", () => { - const aRandomFunction: Omit = { + const aRandomFunction: Omit = { description: "a random function", compute: () => 0, }; @@ -197,7 +198,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg1", description: "", type: ["ANY"] }, { name: "arg2", description: "", type: ["ANY"] }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("basicFunction", basicFunction); expect(descr.minArgRequired).toBe(2); @@ -220,7 +221,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg1", description: "", type: ["ANY"] }, { name: "arg2", description: "", type: ["ANY"], optional: true }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("useOptional", useOptional); expect(descr.minArgRequired).toBe(1); @@ -246,7 +247,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg1", description: "", type: ["ANY"] }, { name: "arg2", description: "", type: ["ANY"], repeating: true }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("useRepeatable", useRepeatable); expect(descr.minArgRequired).toBe(1); @@ -275,7 +276,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg2", description: "", type: ["ANY"], repeating: true }, { name: "arg3", description: "", type: ["ANY"], repeating: true }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("useRepeatables1", useRepeatables); expect(descr.minArgRequired).toBe(1); @@ -304,7 +305,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg3", description: "", type: ["ANY"], repeating: true }, { name: "arg4", description: "", type: ["ANY"], optional: true }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("useRepeatables2", useRepeatables); expect(descr.minArgRequired).toBe(1); @@ -349,7 +350,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg5", description: "", type: ["ANY"], optional: true }, { name: "arg6", description: "", type: ["ANY"], optional: true }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("useRepeatables3", useRepeatables); expect(descr.minArgRequired).toBe(1); @@ -391,7 +392,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg3", description: "", type: ["ANY"], repeating: true }, { name: "arg4", description: "", type: ["ANY"] }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("useRepeatables4", useRepeatables); expect(descr.minArgRequired).toBe(2); @@ -431,7 +432,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg3", description: "", type: ["ANY"], optional: true }, { name: "arg4", description: "", type: ["ANY"] }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("useRepeatables5", useRepeatables); expect(descr.minArgRequired).toBe(2); @@ -474,7 +475,7 @@ describe("function addMetaInfoFromArg", () => { { name: "arg9", description: "", type: ["ANY"], optional: true }, { name: "arg10", description: "", type: ["ANY"] }, ], - } as AddFunctionDescription; + } as Functions; const descr = addMetaInfoFromArg("useRepeatables6", useRepeatables); expect(descr.minArgRequired).toBe(3); diff --git a/tests/functions/functions.test.ts b/tests/functions/functions.test.ts index 7e7ec5394e..22d1ad0fe1 100644 --- a/tests/functions/functions.test.ts +++ b/tests/functions/functions.test.ts @@ -1,8 +1,9 @@ +import { Arg, functionRegistry } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { toScalar } from "../../src/functions/helper_matrices"; import { isEvaluationError, toBoolean, toNumber } from "../../src/functions/helpers"; -import { arg, functionRegistry } from "../../src/functions/index"; -import { Arg, DEFAULT_LOCALE } from "../../src/types"; +import { arg } from "../../src/functions/index"; +import { DEFAULT_LOCALE } from "../../src/types"; import { CellErrorType, EvaluationError } from "../../src/types/errors"; import { setCellContent, setCellFormat } from "../test_helpers/commands_helpers"; import { getCellError, getEvaluatedCell } from "../test_helpers/getters_helpers"; diff --git a/tests/functions/vectorization.test.ts b/tests/functions/vectorization.test.ts index 6f3b38cc3e..790eb44627 100644 --- a/tests/functions/vectorization.test.ts +++ b/tests/functions/vectorization.test.ts @@ -1,5 +1,5 @@ +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { OPERATOR_MAP, UNARY_OPERATOR_MAP } from "../../src/formulas/compiler"; -import { functionRegistry } from "../../src/functions"; import { toScalar } from "../../src/functions/helper_matrices"; import { toString } from "../../src/functions/helpers"; import { splitReference } from "../../src/helpers"; diff --git a/tests/grid/grid_component.test.ts b/tests/grid/grid_component.test.ts index 7d732c9bfa..09aff42000 100644 --- a/tests/grid/grid_component.test.ts +++ b/tests/grid/grid_component.test.ts @@ -1,3 +1,4 @@ +import { Align } from "@odoo/o-spreadsheet-engine"; import { Spreadsheet, TransportService } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { ComposerFocusStore } from "../../src/components/composer/composer_focus_store"; @@ -25,7 +26,7 @@ import { ClipboardPlugin } from "../../src/plugins/ui_stateful"; import { Store } from "../../src/store_engine"; import { ClientFocusStore } from "../../src/stores/client_focus_store"; import { HighlightStore } from "../../src/stores/highlight_store"; -import { Align, ClipboardMIMEType, SpreadsheetChildEnv } from "../../src/types"; +import { ClipboardMIMEType, SpreadsheetChildEnv } from "../../src/types"; import { xmlEscape } from "../../src/xlsx/helpers/xml_helpers"; import { FileStore } from "../__mocks__/mock_file_store"; import { MockTransportService } from "../__mocks__/transport_service"; diff --git a/tests/grid/grid_drag_and_drop_component.test.ts b/tests/grid/grid_drag_and_drop_component.test.ts index 2b6848227e..7324073db1 100644 --- a/tests/grid/grid_drag_and_drop_component.test.ts +++ b/tests/grid/grid_drag_and_drop_component.test.ts @@ -1,9 +1,10 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { App, Component, xml } from "@odoo/owl"; import { Model } from "../../src"; import { useDragAndDropBeyondTheViewport } from "../../src/components/helpers/drag_and_drop_grid_hook"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../src/constants"; import { numberToLetters } from "../../src/helpers"; -import { SpreadsheetChildEnv, UID } from "../../src/types"; +import { SpreadsheetChildEnv } from "../../src/types"; import { addColumns, addRows, diff --git a/tests/grid/highlight_component.test.ts b/tests/grid/highlight_component.test.ts index a5dc78a60b..03bad55cff 100644 --- a/tests/grid/highlight_component.test.ts +++ b/tests/grid/highlight_component.test.ts @@ -1,3 +1,4 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { Component, useSubEnv, xml } from "@odoo/owl"; import { Model } from "../../src"; import { Highlight } from "../../src/components/highlight/highlight/highlight"; @@ -7,7 +8,7 @@ import { getDefaultSheetViewSize, } from "../../src/constants"; import { toHex, toZone } from "../../src/helpers"; -import { Color, Range } from "../../src/types"; +import { Range } from "../../src/types"; import { merge } from "../test_helpers/commands_helpers"; import { edgeScrollDelay, triggerMouseEvent } from "../test_helpers/dom_helper"; import { diff --git a/tests/grid/highlight_store.test.ts b/tests/grid/highlight_store.test.ts index 106ea76e76..c64757f994 100644 --- a/tests/grid/highlight_store.test.ts +++ b/tests/grid/highlight_store.test.ts @@ -1,12 +1,10 @@ import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH, HIGHLIGHT_COLOR } from "../../src/constants"; import { HighlightProvider, HighlightStore } from "../../src/stores/highlight_store"; -import { Highlight, UID } from "../../src/types"; +import { Highlight, UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { toZone } from "../../src/helpers"; import { MockGridRenderingContext } from "../test_helpers/renderer_helpers"; -import { makeStoreWithModel } from "../test_helpers/stores"; - let highlightStore: HighlightStore; let ctx: MockGridRenderingContext; let ctxInstructions: string[]; diff --git a/tests/header_group/header_group_component.test.ts b/tests/header_group/header_group_component.test.ts index 305d303911..1ad6572c87 100644 --- a/tests/header_group/header_group_component.test.ts +++ b/tests/header_group/header_group_component.test.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { HeaderGroupContainer } from "../../src/components/header_group/header_group_container"; import { @@ -7,7 +8,7 @@ import { HEADER_HEIGHT, HEADER_WIDTH, } from "../../src/constants"; -import { Dimension, UID } from "../../src/types"; +import { Dimension } from "../../src/types"; import { foldHeaderGroup, freezeColumns, diff --git a/tests/header_group/header_group_plugin.test.ts b/tests/header_group/header_group_plugin.test.ts index ce0d8d79b1..46e14b1e8a 100644 --- a/tests/header_group/header_group_plugin.test.ts +++ b/tests/header_group/header_group_plugin.test.ts @@ -1,27 +1,6 @@ +import { HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; import { CommandResult, Model } from "../../src"; -import { UID } from "../../src/types"; -import { Dimension, HeaderIndex } from "../../src/types/misc"; -import { - addColumns, - addRows, - deleteColumns, - deleteHeaders, - deleteRows, - duplicateSheet, - foldAllHeaderGroups, - foldHeaderGroup, - foldHeaderGroupsInZone, - groupColumns, - groupHeaders, - groupRows, - redo, - undo, - unfoldAllHeaderGroups, - unfoldHeaderGroup, - unfoldHeaderGroupsInZone, - ungroupHeaders, -} from "../test_helpers/commands_helpers"; - +import { Dimension } from "../../src/types/misc"; function getSortedGroups(model: Model, sheetId: UID, dimension: Dimension) { return model.getters .getHeaderGroups(sheetId, dimension) diff --git a/tests/headers/resizing_plugin.test.ts b/tests/headers/resizing_plugin.test.ts index 137f6c9f98..5209ab3de3 100644 --- a/tests/headers/resizing_plugin.test.ts +++ b/tests/headers/resizing_plugin.test.ts @@ -1,3 +1,4 @@ +import { Sheet, Wrapping } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH, @@ -6,7 +7,7 @@ import { } from "../../src/constants"; import { getDefaultCellHeight as getDefaultCellHeightHelper, toXC } from "../../src/helpers"; import { Model } from "../../src/model"; -import { Cell, CommandResult, Sheet, Wrapping } from "../../src/types"; +import { Cell, CommandResult } from "../../src/types"; import { activateSheet, addColumns, @@ -26,8 +27,6 @@ import { unMerge, undo, } from "../test_helpers/commands_helpers"; -import { getCell } from "../test_helpers/getters_helpers"; - const ctx = document.createElement("canvas").getContext("2d")!; function getDefaultCellHeight(cell: Cell | undefined, colSize = DEFAULT_CELL_WIDTH) { return Math.round(getDefaultCellHeightHelper(ctx, cell, colSize)); diff --git a/tests/helpers/coordinates_helpers.test.ts b/tests/helpers/coordinates_helpers.test.ts index 8eec8384db..f852379ff1 100644 --- a/tests/helpers/coordinates_helpers.test.ts +++ b/tests/helpers/coordinates_helpers.test.ts @@ -1,5 +1,6 @@ import { numberToLetters, toCartesian, toXC } from "../../src/helpers/index"; -import { Position } from "../../src/types"; + +import { Position } from "@odoo/o-spreadsheet-engine"; function toPosition(col: number, row: number): Position { return { col, row }; diff --git a/tests/helpers/ui_helpers.test.ts b/tests/helpers/ui_helpers.test.ts index c7f7e567b5..abc462d4a5 100644 --- a/tests/helpers/ui_helpers.test.ts +++ b/tests/helpers/ui_helpers.test.ts @@ -1,3 +1,4 @@ +import { Position, UID } from "@odoo/o-spreadsheet-engine"; import { TableTerms } from "../../src/components/translations_terms"; import { toCartesian, toXC, toZone, zoneToXc } from "../../src/helpers/index"; import { interactiveSortSelection } from "../../src/helpers/sort"; @@ -19,7 +20,7 @@ import { interactiveToggleGroup, } from "../../src/helpers/ui/toggle_group_interactive"; import { Model } from "../../src/model"; -import { CommandResult, Dimension, Position, SpreadsheetChildEnv, UID } from "../../src/types"; +import { CommandResult, Dimension, SpreadsheetChildEnv } from "../../src/types"; import { addCellToSelection, copy, @@ -38,8 +39,6 @@ import { undo, } from "../test_helpers/commands_helpers"; import { getCell, getCellContent, getCellText } from "../test_helpers/getters_helpers"; -import { createModelFromGrid, makeTestEnv, target } from "../test_helpers/helpers"; - function getCellsObject(model: Model, sheetId: UID) { const cells = {}; for (const cell of Object.values(model.getters.getCells(sheetId))) { diff --git a/tests/helpers/zones_helpers.test.ts b/tests/helpers/zones_helpers.test.ts index b3b51ff17e..518ac4f00f 100644 --- a/tests/helpers/zones_helpers.test.ts +++ b/tests/helpers/zones_helpers.test.ts @@ -13,7 +13,7 @@ import { zoneToXc, } from "../../src/helpers/index"; -import { Zone } from "../../src/types"; +import { Zone } from "@odoo/o-spreadsheet-engine"; import { target } from "../test_helpers/helpers"; describe("overlap", () => { diff --git a/tests/history/selective_history_plugin.test.ts b/tests/history/selective_history_plugin.test.ts index ced67d8a0e..22206982b5 100644 --- a/tests/history/selective_history_plugin.test.ts +++ b/tests/history/selective_history_plugin.test.ts @@ -1,6 +1,7 @@ import { UuidGenerator } from "../../src/helpers"; import { SelectiveHistory } from "../../src/history/selective_history"; -import { UID } from "../../src/types"; + +import { UID } from "@odoo/o-spreadsheet-engine"; interface Command { position: number; diff --git a/tests/menus/menu_items_registry.test.ts b/tests/menus/menu_items_registry.test.ts index d0c3d59b2a..8f929da105 100644 --- a/tests/menus/menu_items_registry.test.ts +++ b/tests/menus/menu_items_registry.test.ts @@ -1,5 +1,5 @@ import { toUnboundedZone, toZone, zoneToXc } from "../../src/helpers"; -import { SpreadsheetChildEnv, UID } from "../../src/types"; +import { SpreadsheetChildEnv } from "../../src/types"; import { copy, createDynamicTable, @@ -45,10 +45,10 @@ import { import { Currency, Model } from "../../src"; +import { functionRegistry, UID } from "@odoo/o-spreadsheet-engine"; import { ActionSpec, createAction } from "../../src/actions/action"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { FONT_SIZES } from "../../src/constants"; -import { functionRegistry } from "../../src/functions"; import { interactivePaste } from "../../src/helpers/ui/paste_interactive"; import { MenuItemRegistry } from "../../src/registries/menu_items_registry"; import { diff --git a/tests/model/core.test.ts b/tests/model/core.test.ts index 25d2f2e74c..fb9b6d7c1b 100644 --- a/tests/model/core.test.ts +++ b/tests/model/core.test.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { zoneToXc } from "../../src/helpers"; import { Model } from "../../src/model"; -import { CommandResult, coreTypes, UID } from "../../src/types"; +import { CommandResult, coreTypes } from "../../src/types"; import { activateSheet, addColumns, diff --git a/tests/model/model_import_export.test.ts b/tests/model/model_import_export.test.ts index a346fc7b8e..22a065ff08 100644 --- a/tests/model/model_import_export.test.ts +++ b/tests/model/model_import_export.test.ts @@ -1,3 +1,4 @@ +import { BorderDescr } from "@odoo/o-spreadsheet-engine"; import { CellIsRule, Model } from "../../src"; import { BACKGROUND_CHART_COLOR, @@ -9,13 +10,7 @@ import { import { toCartesian, toZone } from "../../src/helpers"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { getCurrentVersion } from "../../src/migrations/data"; -import { - BorderDescr, - ColorScaleRule, - DEFAULT_LOCALE, - DEFAULT_LOCALES, - IconSetRule, -} from "../../src/types"; +import { ColorScaleRule, DEFAULT_LOCALE, DEFAULT_LOCALES, IconSetRule } from "../../src/types"; import { activateSheet, resizeColumns, diff --git a/tests/pivots/pivot_custom_groups/pivot_custom_groups_model.test.ts b/tests/pivots/pivot_custom_groups/pivot_custom_groups_model.test.ts index 0865642e24..fa74894a87 100644 --- a/tests/pivots/pivot_custom_groups/pivot_custom_groups_model.test.ts +++ b/tests/pivots/pivot_custom_groups/pivot_custom_groups_model.test.ts @@ -1,4 +1,5 @@ -import { CommandResult, Model, PivotCustomGroupedField, UID } from "../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { CommandResult, Model, PivotCustomGroupedField } from "../../../src"; import { setCellContent } from "../../test_helpers/commands_helpers"; import { getFormattedGrid, target } from "../../test_helpers/helpers"; import { createModelWithPivot, updatePivot } from "../../test_helpers/pivot_helpers"; diff --git a/tests/pivots/pivot_measure/pivot_measure_display_panel.test.ts b/tests/pivots/pivot_measure/pivot_measure_display_panel.test.ts index d29b5ee191..caa1fe2f79 100644 --- a/tests/pivots/pivot_measure/pivot_measure_display_panel.test.ts +++ b/tests/pivots/pivot_measure/pivot_measure_display_panel.test.ts @@ -1,4 +1,5 @@ -import { Model, PivotCoreMeasure, SpreadsheetChildEnv, UID } from "../../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model, PivotCoreMeasure, SpreadsheetChildEnv } from "../../../src"; import { PivotMeasureDisplayPanel } from "../../../src/components/side_panel/pivot/pivot_measure_display_panel/pivot_measure_display_panel"; import { toZone } from "../../../src/helpers"; import { PREVIOUS_VALUE } from "../../../src/helpers/pivot/pivot_domain_helpers"; diff --git a/tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts b/tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts index ff6e75577d..f7916a9629 100644 --- a/tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts +++ b/tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts @@ -1,4 +1,5 @@ -import { CellErrorType, EvaluatedCell, FunctionResultObject, Model } from "../../../src"; +import { FunctionResultObject } from "@odoo/o-spreadsheet-engine"; +import { CellErrorType, EvaluatedCell, Model } from "../../../src"; import { GRID_ICON_MARGIN, PIVOT_INDENT } from "../../../src/constants"; import { positions, toZone } from "../../../src/helpers"; import { resetMapValueDimensionDate } from "../../../src/helpers/pivot/spreadsheet_pivot/date_spreadsheet_pivot"; diff --git a/tests/popover/popover_component.test.ts b/tests/popover/popover_component.test.ts index 62b8c4d5cf..00fa96357b 100644 --- a/tests/popover/popover_component.test.ts +++ b/tests/popover/popover_component.test.ts @@ -1,7 +1,8 @@ +import { Pixel } from "@odoo/o-spreadsheet-engine"; import { App, Component, useSubEnv, xml } from "@odoo/owl"; import { Model } from "../../src"; import { Popover, PopoverProps } from "../../src/components/popover/popover"; -import { Pixel, Rect } from "../../src/types"; +import { Rect } from "../../src/types"; import { getStylePropertyInPx, mountComponent } from "../test_helpers/helpers"; import { extendMockGetBoundingClientRect } from "../test_helpers/mock_helpers"; diff --git a/tests/range_plugin.test.ts b/tests/range_plugin.test.ts index 7f00701ec4..ac6de8acc4 100644 --- a/tests/range_plugin.test.ts +++ b/tests/range_plugin.test.ts @@ -1,7 +1,8 @@ +import { ApplyRangeChange } from "@odoo/o-spreadsheet-engine"; import { CorePlugin, coreTypes, Model } from "../src"; import { duplicateRangeInDuplicatedSheet } from "../src/helpers"; import { corePluginRegistry } from "../src/plugins"; -import { ApplyRangeChange, Command, Range } from "../src/types"; +import { Command, Range } from "../src/types"; import { CellErrorType } from "../src/types/errors"; import { addColumns, diff --git a/tests/renderer/renderer_store.test.ts b/tests/renderer/renderer_store.test.ts index b8a982e7c9..cd323d30ce 100644 --- a/tests/renderer/renderer_store.test.ts +++ b/tests/renderer/renderer_store.test.ts @@ -1,3 +1,4 @@ +import { Align, BorderPosition, Zone } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { HoveredTableStore } from "../../src/components/tables/hovered_table_store"; import { @@ -19,15 +20,7 @@ import { Mode } from "../../src/model"; import { FormulaFingerprintStore } from "../../src/stores/formula_fingerprints_store"; import { GridRenderer } from "../../src/stores/grid_renderer_store"; import { RendererStore } from "../../src/stores/renderer_store"; -import { - Align, - BorderPosition, - Box, - DataValidationCriterion, - GridRenderingContext, - Viewport, - Zone, -} from "../../src/types"; +import { Box, DataValidationCriterion, GridRenderingContext, Viewport } from "../../src/types"; import { MockCanvasRenderingContext2D } from "../setup/canvas.mock"; import { addColumns, diff --git a/tests/repeat_commands_plugin.test.ts b/tests/repeat_commands_plugin.test.ts index 3e31f86b06..94430d87c2 100644 --- a/tests/repeat_commands_plugin.test.ts +++ b/tests/repeat_commands_plugin.test.ts @@ -1,3 +1,4 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../src"; import { DEFAULT_CELL_HEIGHT } from "../src/constants"; import { toZone } from "../src/helpers"; @@ -6,7 +7,7 @@ import { repeatCoreCommand, repeatLocalCommandTransformRegistry, } from "../src/registries/repeat_commands_registry"; -import { CoreCommand, Dimension, UID } from "../src/types"; +import { CoreCommand, Dimension } from "../src/types"; import { AddColumnsRowsCommand, CreateChartCommand, diff --git a/tests/selection_input/selection_input_component.test.ts b/tests/selection_input/selection_input_component.test.ts index eed4568598..342f430352 100644 --- a/tests/selection_input/selection_input_component.test.ts +++ b/tests/selection_input/selection_input_component.test.ts @@ -1,3 +1,4 @@ +import { Color } from "@odoo/o-spreadsheet-engine"; import { App, Component, useSubEnv, xml } from "@odoo/owl"; import { Model } from "../../src"; import { OPEN_CF_SIDEPANEL_ACTION } from "../../src/actions/menu_items_actions"; @@ -6,7 +7,7 @@ import { ColorGenerator, toCartesian, toZone } from "../../src/helpers"; import { useStoreProvider } from "../../src/store_engine"; import { ModelStore } from "../../src/stores"; import { HighlightStore } from "../../src/stores/highlight_store"; -import { Color, SpreadsheetChildEnv } from "../../src/types"; +import { SpreadsheetChildEnv } from "../../src/types"; import { activateSheet, addCellToSelection, diff --git a/tests/setup/jest_extend.ts b/tests/setup/jest_extend.ts index cb22ba7761..a68022d07d 100644 --- a/tests/setup/jest_extend.ts +++ b/tests/setup/jest_extend.ts @@ -1,9 +1,10 @@ +import { Zone } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { isSameColor, toHex } from "../../src/helpers/color"; import { toXC } from "../../src/helpers/coordinates"; import { deepEquals } from "../../src/helpers/misc"; import { positions } from "../../src/helpers/zones"; -import { CancelledReason, DispatchResult, Zone } from "../../src/types"; +import { CancelledReason, DispatchResult } from "../../src/types"; type DOMTarget = string | Element | Document | Window | null; diff --git a/tests/sheet/sheetview_plugin.test.ts b/tests/sheet/sheetview_plugin.test.ts index 565f261e84..55b620db62 100644 --- a/tests/sheet/sheetview_plugin.test.ts +++ b/tests/sheet/sheetview_plugin.test.ts @@ -1,3 +1,4 @@ +import { Zone } from "@odoo/o-spreadsheet-engine"; import { CommandResult } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { @@ -10,7 +11,6 @@ import { import { isDefined, numberToLetters, range, toXC, toZone, zoneToXc } from "../../src/helpers"; import { Model } from "../../src/model"; import { SheetViewPlugin } from "../../src/plugins/ui_stateful/sheetview"; -import { Zone } from "../../src/types"; import { StateUpdateMessage } from "../../src/types/collaborative/transport_service"; import { activateSheet, diff --git a/tests/sort_plugin.test.ts b/tests/sort_plugin.test.ts index 7829a24169..f26a8daecb 100644 --- a/tests/sort_plugin.test.ts +++ b/tests/sort_plugin.test.ts @@ -1,7 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { parseDateTime } from "../src/helpers/dates"; import { toZone, zoneToXc } from "../src/helpers/index"; import { Model } from "../src/model"; -import { CellValueType, CommandResult, DEFAULT_LOCALE, UID } from "../src/types"; +import { CellValueType, CommandResult, DEFAULT_LOCALE } from "../src/types"; import { CellErrorType } from "../src/types/errors"; import { merge, redo, setCellContent, sort, undo } from "./test_helpers/commands_helpers"; import { getEvaluatedCell } from "./test_helpers/getters_helpers"; diff --git a/tests/split_to_column/split_to_column_plugin.test.ts b/tests/split_to_column/split_to_column_plugin.test.ts index 37d7b05fe6..8e8f582306 100644 --- a/tests/split_to_column/split_to_column_plugin.test.ts +++ b/tests/split_to_column/split_to_column_plugin.test.ts @@ -1,6 +1,7 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { toZone } from "../../src/helpers"; import { Model } from "../../src/model"; -import { CommandResult, DEFAULT_LOCALE, UID } from "../../src/types"; +import { CommandResult, DEFAULT_LOCALE } from "../../src/types"; import { merge, redo, diff --git a/tests/spreadsheet/spreadsheet_component.test.ts b/tests/spreadsheet/spreadsheet_component.test.ts index 3d007831e3..4677047638 100644 --- a/tests/spreadsheet/spreadsheet_component.test.ts +++ b/tests/spreadsheet/spreadsheet_component.test.ts @@ -1,3 +1,4 @@ +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { Component, useSubEnv, xml } from "@odoo/owl"; import { Model, Spreadsheet, setDefaultSheetViewSize } from "../../src"; import { OPEN_CF_SIDEPANEL_ACTION } from "../../src/actions/menu_items_actions"; @@ -9,7 +10,6 @@ import { DEFAULT_CELL_WIDTH, getDefaultSheetViewSize, } from "../../src/constants"; -import { functionRegistry } from "../../src/functions"; import { toZone } from "../../src/helpers"; import { HighlightStore } from "../../src/stores/highlight_store"; import { SpreadsheetChildEnv } from "../../src/types"; diff --git a/tests/table/dynamic_table_plugin.test.ts b/tests/table/dynamic_table_plugin.test.ts index f178cab04a..c8d5a40084 100644 --- a/tests/table/dynamic_table_plugin.test.ts +++ b/tests/table/dynamic_table_plugin.test.ts @@ -1,6 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { toZone, zoneToXc } from "../../src/helpers"; -import { UID } from "../../src/types"; import { copy, createDynamicTable, diff --git a/tests/table/filter_evaluation_plugin.test.ts b/tests/table/filter_evaluation_plugin.test.ts index 437cce7535..9138305727 100644 --- a/tests/table/filter_evaluation_plugin.test.ts +++ b/tests/table/filter_evaluation_plugin.test.ts @@ -1,7 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { range } from "../../src/helpers"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; -import { CommandResult, FilterCriterionType, UID } from "../../src/types"; +import { CommandResult, FilterCriterionType } from "../../src/types"; import { addRows, createSheet, diff --git a/tests/table/filter_menu_component.test.ts b/tests/table/filter_menu_component.test.ts index 7585218cf5..c777f67425 100644 --- a/tests/table/filter_menu_component.test.ts +++ b/tests/table/filter_menu_component.test.ts @@ -1,9 +1,9 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { filterDateCriterionOperators, filterNumberCriterionOperators, filterTextCriterionOperators, - UID, } from "../../src/types"; import { createDynamicTable, diff --git a/tests/table/hovered_table_store.test.ts b/tests/table/hovered_table_store.test.ts index 2e0ce0d3dd..36d0bd76b8 100644 --- a/tests/table/hovered_table_store.test.ts +++ b/tests/table/hovered_table_store.test.ts @@ -1,4 +1,5 @@ -import { Model, UID } from "../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model } from "../../src"; import { HoveredTableStore } from "../../src/components/tables/hovered_table_store"; import { TABLE_HOVER_BACKGROUND_COLOR } from "../../src/constants"; import { createTable, setCellContent } from "../test_helpers/commands_helpers"; diff --git a/tests/table/table_autofill_plugin.test.ts b/tests/table/table_autofill_plugin.test.ts index d961c8bc07..bec5c2ee17 100644 --- a/tests/table/table_autofill_plugin.test.ts +++ b/tests/table/table_autofill_plugin.test.ts @@ -1,4 +1,5 @@ -import { Model, UID } from "../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { diff --git a/tests/table/table_computed_style_plugin.test.ts b/tests/table/table_computed_style_plugin.test.ts index 7e7a004624..d937114b93 100644 --- a/tests/table/table_computed_style_plugin.test.ts +++ b/tests/table/table_computed_style_plugin.test.ts @@ -1,8 +1,8 @@ +import { Style, UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { toXC, toZone } from "../../src/helpers"; import { TABLE_PRESETS } from "../../src/helpers/table_presets"; import { GridRenderer } from "../../src/stores/grid_renderer_store"; -import { Style, UID } from "../../src/types"; import { createTable, createTableWithFilter, diff --git a/tests/table/table_core_style_plugin.test.ts b/tests/table/table_core_style_plugin.test.ts index fe18a895f8..8d4784aa5d 100644 --- a/tests/table/table_core_style_plugin.test.ts +++ b/tests/table/table_core_style_plugin.test.ts @@ -1,4 +1,5 @@ -import { CommandResult, TableStyle, TableStyleTemplateName, UID } from "../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { CommandResult, TableStyle, TableStyleTemplateName } from "../../src"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { Model } from "../../src/model"; import { createTable, createTableStyle, redo, undo } from "../test_helpers/commands_helpers"; diff --git a/tests/table/table_dropdown_button_component.test.ts b/tests/table/table_dropdown_button_component.test.ts index 5e41bca41a..18d7af942e 100644 --- a/tests/table/table_dropdown_button_component.test.ts +++ b/tests/table/table_dropdown_button_component.test.ts @@ -1,9 +1,10 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Component, xml } from "@odoo/owl"; import { Model } from "../../src"; import { SidePanels } from "../../src/components/side_panel/side_panels/side_panels"; import { TableDropdownButton } from "../../src/components/tables/table_dropdown_button/table_dropdown_button"; import { toZone, zoneToXc } from "../../src/helpers"; -import { SpreadsheetChildEnv, UID } from "../../src/types"; +import { SpreadsheetChildEnv } from "../../src/types"; import { createTable, setSelection } from "../test_helpers/commands_helpers"; import { click } from "../test_helpers/dom_helper"; import { mountComponent, nextTick } from "../test_helpers/helpers"; diff --git a/tests/table/table_helpers.test.ts b/tests/table/table_helpers.test.ts index ba46a205bf..c311ead1ec 100644 --- a/tests/table/table_helpers.test.ts +++ b/tests/table/table_helpers.test.ts @@ -1,7 +1,7 @@ +import { Border, BorderDescr } from "@odoo/o-spreadsheet-engine"; import { deepCopy } from "../../src/helpers"; import { getComputedTableStyle } from "../../src/helpers/table_helpers"; -import { Border, BorderDescr } from "../../src/types"; -import { ComputedTableStyle, TableConfig, TableStyle } from "../../src/types/table"; +import { TableStyle } from "../../src/types/table"; const TEST_TABLE_STYLE: TableStyle = { category: "light", diff --git a/tests/table/table_panel_component.test.ts b/tests/table/table_panel_component.test.ts index 300876da33..2e3452c6aa 100644 --- a/tests/table/table_panel_component.test.ts +++ b/tests/table/table_panel_component.test.ts @@ -1,5 +1,5 @@ import { toUnboundedZone, toZone, zoneToXc } from "../../src/helpers"; -import { SpreadsheetChildEnv, Table, UID } from "../../src/types"; +import { SpreadsheetChildEnv, Table } from "../../src/types"; import { createTable, createTableStyle, @@ -12,6 +12,7 @@ import { click, setInputValueAndTrigger, simulateClick } from "../test_helpers/d import { getCell } from "../test_helpers/getters_helpers"; import { mountComponentWithPortalTarget, nextTick } from "../test_helpers/helpers"; +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { SidePanels } from "../../src/components/side_panel/side_panels/side_panels"; import { TableTerms } from "../../src/components/translations_terms"; diff --git a/tests/table/table_resize_ui_plugin.test.ts b/tests/table/table_resize_ui_plugin.test.ts index 76066c2147..1f52cc09e2 100644 --- a/tests/table/table_resize_ui_plugin.test.ts +++ b/tests/table/table_resize_ui_plugin.test.ts @@ -1,4 +1,5 @@ -import { CommandResult, Model, UID } from "../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { CommandResult, Model } from "../../src"; import { toZone } from "../../src/helpers"; import { createDynamicTable, diff --git a/tests/table/table_resizer_component.test.ts b/tests/table/table_resizer_component.test.ts index acd2a3cd1b..d3558133f5 100644 --- a/tests/table/table_resizer_component.test.ts +++ b/tests/table/table_resizer_component.test.ts @@ -1,4 +1,5 @@ -import { Model, SpreadsheetChildEnv, UID } from "../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { Model, SpreadsheetChildEnv } from "../../src"; import { Grid } from "../../src/components/grid/grid"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../src/constants"; import { toZone, zoneToXc } from "../../src/helpers"; diff --git a/tests/table/tables_plugin.test.ts b/tests/table/tables_plugin.test.ts index f3f4b58b6a..0a25fc8a1b 100644 --- a/tests/table/tables_plugin.test.ts +++ b/tests/table/tables_plugin.test.ts @@ -1,6 +1,5 @@ import { CommandResult, Model } from "../../src"; import { toUnboundedZone, toZone, zoneToXc } from "../../src/helpers"; -import { UID } from "../../src/types"; import { activateSheet, addColumns, @@ -39,6 +38,7 @@ import { toRangesData, } from "../test_helpers/helpers"; +import { UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_BORDER_DESC } from "../../src/constants"; import { TABLE_PRESETS } from "../../src/helpers/table_presets"; import { EvaluationPlugin } from "../../src/plugins/ui_core_views"; diff --git a/tests/test_helpers/chart_helpers.ts b/tests/test_helpers/chart_helpers.ts index 4164200a69..b790ceb984 100644 --- a/tests/test_helpers/chart_helpers.ts +++ b/tests/test_helpers/chart_helpers.ts @@ -1,5 +1,6 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { TooltipItem } from "chart.js"; -import { ChartCreationContext, ChartJSRuntime, Model, SpreadsheetChildEnv, UID } from "../../src"; +import { ChartCreationContext, ChartJSRuntime, Model, SpreadsheetChildEnv } from "../../src"; import { range, toHex } from "../../src/helpers"; import { click, simulateClick } from "./dom_helper"; import { nextTick } from "./helpers"; diff --git a/tests/test_helpers/commands_helpers.ts b/tests/test_helpers/commands_helpers.ts index 69edb15621..2b48a493d1 100644 --- a/tests/test_helpers/commands_helpers.ts +++ b/tests/test_helpers/commands_helpers.ts @@ -14,14 +14,10 @@ import { import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { Model } from "../../src/model"; import { - AnchorZone, - Border, - BorderData, Carousel, ChartDefinition, ChartWithDataSetDefinition, ClipboardPasteOptions, - Color, CreateFigureCommand, CreateSheetCommand, CreateTableStyleCommand, @@ -29,20 +25,26 @@ import { Dimension, Direction, DispatchResult, - HeaderIndex, Locale, ParsedOsClipboardContentWithImageData, - Pixel, - PixelPosition, SelectionStep, SortDirection, SortOptions, SplitTextIntoColumnsCommand, - Style, - UID, } from "../../src/types"; import { createEqualCF, target, toRangeData, toRangesData } from "./helpers"; +import { + AnchorZone, + Border, + BorderData, + Color, + HeaderIndex, + Pixel, + PixelPosition, + Style, + UID, +} from "@odoo/o-spreadsheet-engine"; import { ICON_SETS } from "../../src/components/icons/icons"; import { SunburstChartDefinition } from "../../src/types/chart"; import { ComboChartDefinition } from "../../src/types/chart/combo_chart"; diff --git a/tests/test_helpers/debug_helpers.ts b/tests/test_helpers/debug_helpers.ts index e945eb2dd5..c410be1f13 100644 --- a/tests/test_helpers/debug_helpers.ts +++ b/tests/test_helpers/debug_helpers.ts @@ -1,8 +1,8 @@ +import { UID } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { concat, zoneToXc } from "../../src/helpers"; import { Branch } from "../../src/history/branch"; import { Tree } from "../../src/history/tree"; -import { UID } from "../../src/types"; import { getEvaluatedGrid } from "./getters_helpers"; import { toCellPosition } from "./helpers"; diff --git a/tests/test_helpers/dom_helper.ts b/tests/test_helpers/dom_helper.ts index a9088ced5b..4386608be4 100644 --- a/tests/test_helpers/dom_helper.ts +++ b/tests/test_helpers/dom_helper.ts @@ -1,4 +1,5 @@ -import { Color, Model } from "../../src"; +import { Color, Pixel } from "@odoo/o-spreadsheet-engine"; +import { Model } from "../../src"; import { iterateChildren } from "../../src/components/helpers/dom_helpers"; import { HEADER_HEIGHT, HEADER_WIDTH } from "../../src/constants"; import { @@ -10,9 +11,7 @@ import { toHex, toZone, } from "../../src/helpers"; -import { DOMCoordinates, Pixel } from "../../src/types"; -import { nextTick } from "./helpers"; - +import { DOMCoordinates } from "../../src/types"; export type DOMTarget = string | Element | Document | Window | null; export async function simulateClick( diff --git a/tests/test_helpers/getters_helpers.ts b/tests/test_helpers/getters_helpers.ts index 77ff48b7ba..cfc0a29efb 100644 --- a/tests/test_helpers/getters_helpers.ts +++ b/tests/test_helpers/getters_helpers.ts @@ -1,18 +1,8 @@ +import { Border, Merge, Style, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { toCartesian, toXC, toZone } from "../../src/helpers/index"; import { Model } from "../../src/model"; import { ClipboardPlugin } from "../../src/plugins/ui_stateful"; -import { - Border, - Cell, - CellValue, - CellValueType, - EvaluatedCell, - FormattedValue, - Merge, - Style, - UID, - Zone, -} from "../../src/types"; +import { Cell, CellValue, CellValueType, EvaluatedCell, FormattedValue } from "../../src/types"; import { setSelection } from "./commands_helpers"; import { getPlugin } from "./helpers"; diff --git a/tests/test_helpers/helpers.ts b/tests/test_helpers/helpers.ts index 0b1ad28eae..c4f2c07210 100644 --- a/tests/test_helpers/helpers.ts +++ b/tests/test_helpers/helpers.ts @@ -1,5 +1,4 @@ -import { BasePlugin } from "@odoo/o-spreadsheet-engine"; -import { App, Component, ComponentConstructor, useState, xml } from "@odoo/owl"; +import { CellPosition, Highlight, Matrix, Style, UID, Zone } from "@odoo/o-spreadsheet-engine"; import type { ChartConfiguration } from "chart.js"; import format from "xml-formatter"; import { functionCache } from "../../src"; @@ -12,7 +11,6 @@ import { getCurrentSelection, isMobileOS } from "../../src/components/helpers/do import { SidePanelStore } from "../../src/components/side_panel/side_panel/side_panel_store"; import { Spreadsheet, SpreadsheetProps } from "../../src/components/spreadsheet/spreadsheet"; import { matrixMap } from "../../src/functions/helpers"; -import { functionRegistry } from "../../src/functions/index"; import { ImageProvider } from "../../src/helpers/figures/images/image_provider"; import { batched, @@ -46,7 +44,6 @@ import { NotificationStore } from "../../src/stores/notification_store"; import { RendererStore } from "../../src/stores/renderer_store"; import { _t } from "../../src/translation"; import { - CellPosition, CellValue, ChartDefinition, ColorScaleMidPointThreshold, @@ -61,14 +58,9 @@ import { ExcelWorkbookData, Format, GridRenderingContext, - Highlight, - Matrix, OrderedLayers, RangeData, SpreadsheetChildEnv, - Style, - UID, - Zone, } from "../../src/types"; import { Image } from "../../src/types/image"; import { XLSXExport } from "../../src/types/xlsx"; @@ -79,8 +71,6 @@ import { registerCleanup } from "../setup/jest.setup"; import { MockClipboard } from "./clipboard"; import { redo, setCellContent, setFormat, setStyle, undo } from "./commands_helpers"; import { DOMTarget, click, getTarget, getTextNodes, keyDown, keyUp } from "./dom_helper"; -import { getCellContent, getEvaluatedCell } from "./getters_helpers"; - const functionsContent = functionRegistry.content; const functionMap = functionRegistry.mapping; diff --git a/tests/test_helpers/pivot_helpers.ts b/tests/test_helpers/pivot_helpers.ts index 743ad5dcc0..203e02f004 100644 --- a/tests/test_helpers/pivot_helpers.ts +++ b/tests/test_helpers/pivot_helpers.ts @@ -1,4 +1,5 @@ -import { DispatchResult, Model, UID } from "../../src"; +import { UID } from "@odoo/o-spreadsheet-engine"; +import { DispatchResult, Model } from "../../src"; import { deepCopy, toZone } from "../../src/helpers"; import { PivotMeasureDisplay, SpreadsheetPivotCoreDefinition } from "../../src/types/pivot"; import { pivotModelData } from "../pivots/pivot_data"; diff --git a/tests/test_helpers/renderer_helpers.ts b/tests/test_helpers/renderer_helpers.ts index 7b6e65b671..ba0af20fee 100644 --- a/tests/test_helpers/renderer_helpers.ts +++ b/tests/test_helpers/renderer_helpers.ts @@ -1,6 +1,7 @@ +import { Zone } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { getDefaultSheetViewSize } from "../../src/constants"; -import { GridRenderingContext, Viewport, Zone } from "../../src/types"; +import { GridRenderingContext, Viewport } from "../../src/types"; import { MockCanvasRenderingContext2D } from "../setup/canvas.mock"; MockCanvasRenderingContext2D.prototype.measureText = function () { diff --git a/tests/test_helpers/xlsx.ts b/tests/test_helpers/xlsx.ts index e68a2d0b5c..85580fd20c 100644 --- a/tests/test_helpers/xlsx.ts +++ b/tests/test_helpers/xlsx.ts @@ -1,7 +1,8 @@ +import { Border, Color, Style } from "@odoo/o-spreadsheet-engine"; import { isSheetNameEqual, toCartesian, toXC, toZone } from "../../src/helpers"; -import { Border, Color, ConditionalFormat, Style } from "../../src/types"; +import { ConditionalFormat } from "../../src/types"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "./../../src/constants"; -import { DataValidationRuleData, SheetData, WorkbookData } from "./../../src/types/workbook_data"; +import { SheetData, WorkbookData } from "./../../src/types/workbook_data"; export function getWorkbookSheet(sheetName: string, data: WorkbookData): SheetData | undefined { return data.sheets.find((sheet) => isSheetNameEqual(sheet.name, sheetName)); diff --git a/tests/top_bar_component.test.ts b/tests/top_bar_component.test.ts index 989c26d2c4..e53541bfcc 100644 --- a/tests/top_bar_component.test.ts +++ b/tests/top_bar_component.test.ts @@ -1,3 +1,4 @@ +import { Pixel, Style } from "@odoo/o-spreadsheet-engine"; import { Component, xml } from "@odoo/owl"; import { Model } from "../src"; import { CellComposerStore } from "../src/components/composer/composer/cell_composer_store"; @@ -8,7 +9,7 @@ import { DEBOUNCE_TIME, DEFAULT_FONT_SIZE } from "../src/constants"; import { toZone, zoneToXc } from "../src/helpers"; import { topbarMenuRegistry } from "../src/registries/menus"; import { topbarComponentRegistry } from "../src/registries/topbar_component_registry"; -import { ConditionalFormat, Currency, Pixel, SpreadsheetChildEnv, Style } from "../src/types"; +import { ConditionalFormat, Currency, SpreadsheetChildEnv } from "../src/types"; import { FileStore } from "./__mocks__/mock_file_store"; import { MockTransportService } from "./__mocks__/transport_service"; import { diff --git a/tests/xlsx/xlsx_export.test.ts b/tests/xlsx/xlsx_export.test.ts index 6ffbf1e1e8..f18b8b7926 100644 --- a/tests/xlsx/xlsx_export.test.ts +++ b/tests/xlsx/xlsx_export.test.ts @@ -1,4 +1,4 @@ -import { arg, functionRegistry } from "../../src/functions"; +import { arg } from "../../src/functions"; import { NOW, TODAY } from "../../src/functions/module_date"; import { RAND, RANDARRAY, RANDBETWEEN } from "../../src/functions/module_math"; import { buildSheetLink, toXC } from "../../src/helpers"; @@ -10,6 +10,7 @@ import { hexaToInt } from "../../src/xlsx/conversion"; import { adaptFormulaToExcel } from "../../src/xlsx/functions/cells"; import { escapeXml, parseXML } from "../../src/xlsx/helpers/xml_helpers"; +import { functionRegistry } from "@odoo/o-spreadsheet-engine"; import { createChart, createGaugeChart, diff --git a/tests/xlsx/xlsx_import_export.test.ts b/tests/xlsx/xlsx_import_export.test.ts index 4efc3f64dc..031ff94364 100644 --- a/tests/xlsx/xlsx_import_export.test.ts +++ b/tests/xlsx/xlsx_import_export.test.ts @@ -1,13 +1,7 @@ +import { Align, BorderDescr, Style, VerticalAlign, Wrapping } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { buildSheetLink, toZone } from "../../src/helpers"; -import { - Align, - BorderDescr, - ConditionalFormatRule, - Style, - VerticalAlign, - Wrapping, -} from "../../src/types"; +import { ConditionalFormatRule } from "../../src/types"; import { isXLSXExportXMLFile } from "../../src/xlsx/helpers/xlsx_helper"; import { createChart, From 302531f67e50c7c8f5107b1d2555061c9bc1b686 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Wed, 1 Oct 2025 11:39:41 +0200 Subject: [PATCH 17/19] I'm having so much fun --- .../src/functions/functionRegistry.ts | 14 ++- .../src}/functions/helper_assert.ts | 6 +- .../src}/functions/helper_math.ts | 2 +- .../src}/functions/helper_statistical.ts | 12 +- .../src}/functions/module_custom.ts | 3 +- .../src}/functions/module_database.ts | 6 +- .../src}/functions/module_engineering.ts | 2 +- .../src}/functions/module_filter.ts | 19 ++- .../src}/functions/module_financial.ts | 0 .../src}/functions/module_lookup.ts | 27 +++-- .../src}/functions/module_math.ts | 14 +-- .../src}/functions/module_operators.ts | 2 +- .../src}/functions/module_statistical.ts | 9 +- .../src}/helpers/coordinates.ts | 2 +- .../src}/helpers/dates.ts | 0 .../o-spreadsheet-engine/src/helpers/index.ts | 4 + .../src/helpers/is_subtotal_cell.ts | 10 ++ .../o-spreadsheet-engine/src/helpers/misc.ts | 61 ++++++++++ .../src}/helpers/recompute_zones.ts | 2 +- .../o-spreadsheet-engine/src/helpers/sort.ts | 52 +++++++++ .../src}/helpers/zones.ts | 2 +- .../o-spreadsheet-engine/src/types/base.ts | 60 +--------- .../o-spreadsheet-engine/src}/types/cells.ts | 5 +- .../o-spreadsheet-engine/src}/types/format.ts | 2 +- .../o-spreadsheet-engine/src/types/index.ts | 21 ++++ .../src/types/isMatrix.ts | 3 + .../o-spreadsheet-engine/src/types/misc.ts | 100 ++++++++++++++++ .../o-spreadsheet-engine/src}/types/range.ts | 3 + src/actions/figure_menu_actions.ts | 3 +- src/actions/insert_actions.ts | 3 - src/actions/menu_items_actions.ts | 3 +- src/actions/view_actions.ts | 2 +- src/clipboard_handlers/borders_clipboard.ts | 10 +- src/clipboard_handlers/cell_clipboard.ts | 11 +- .../conditional_format_clipboard.ts | 11 +- .../data_validation_clipboard.ts | 11 +- src/clipboard_handlers/merge_clipboard.ts | 3 - src/collaborative/ot/ot.ts | 10 -- src/collaborative/session.ts | 7 +- src/components/bottom_bar/bottom_bar.ts | 3 +- .../aggregate_statistics_store.ts | 2 +- src/components/color_picker/color_picker.ts | 3 +- .../composer/abstract_composer_store.ts | 3 +- .../composer/composer/cell_composer_store.ts | 2 +- src/components/composer/composer/composer.ts | 8 +- .../composer/content_editable_helper.ts | 3 +- .../composer/grid_composer/grid_composer.ts | 3 +- .../clickable_cell_sort_icon.ts | 3 +- src/components/dashboard/dashboard.ts | 3 +- src/components/error_tooltip/error_tooltip.ts | 4 +- .../figures/chart/chartJs/chartjs.ts | 4 +- .../chartJs/chartjs_sunburst_labels_plugin.ts | 9 +- .../chart_dashboard_menu.ts | 3 - .../chart/gauge/gauge_chart_component.ts | 3 +- .../figure_carousel/figure_carousel.ts | 4 +- .../figure_container/figure_container.ts | 7 +- .../filters/filter_menu/filter_menu.ts | 8 +- .../filter_menu_criterion.ts | 4 +- .../filter_menu_value_list.ts | 4 +- src/components/grid/grid.ts | 4 +- src/components/grid_overlay/grid_overlay.ts | 7 +- src/components/header_group/header_group.ts | 3 +- .../header_group/header_group_container.ts | 3 +- .../headers_overlay/headers_overlay.ts | 3 +- src/components/helpers/dom_helpers.ts | 2 +- src/components/helpers/highlight_hook.ts | 4 +- src/components/helpers/listener_hook.ts | 3 +- src/components/helpers/touch_scroll_hook.ts | 2 +- src/components/icons/icons.ts | 10 -- .../link/link_display/link_display.ts | 3 +- .../link/link_editor/link_editor.ts | 3 +- src/components/scrollbar/scrollbar.ts | 3 +- .../selection_input/selection_input.ts | 4 +- .../carousel_panel/carousel_panel.ts | 3 +- .../generic_side_panel/config_panel.ts | 3 - .../main_chart_panel/main_chart_panel.ts | 3 +- .../main_chart_panel_store.ts | 3 +- .../cf_preview_list/cf_preview_list.ts | 3 +- .../custom_currency/custom_currency.ts | 8 +- .../find_and_replace/find_and_replace.ts | 3 +- .../pivot_layout_configurator.ts | 6 +- .../pivot_side_panel_store.ts | 4 +- .../pivot_spreadsheet_side_panel.ts | 3 +- .../side_panel/settings/settings_panel.ts | 3 +- .../table_style_preview.ts | 2 +- src/components/text_input/text_input.ts | 4 +- src/functions/module_date.ts | 2 +- src/helpers/color.ts | 4 - src/helpers/data_normalization.ts | 3 +- src/helpers/figures/charts/chart_common.ts | 11 +- src/helpers/figures/charts/gauge_chart.ts | 11 +- .../figures/charts/runtime/chartjs_dataset.ts | 4 +- .../figures/charts/runtime/chartjs_scales.ts | 3 +- src/helpers/format/format_parser.ts | 2 +- src/helpers/internal_viewport.ts | 3 +- src/helpers/links.ts | 3 +- src/helpers/misc.ts | 65 +---------- src/helpers/pivot/pivot_domain_helpers.ts | 3 +- src/helpers/pivot/pivot_helpers.ts | 4 +- src/helpers/pivot/pivot_menu_items.ts | 2 +- src/helpers/pivot/pivot_presentation.ts | 15 ++- .../spreadsheet_pivot/spreadsheet_pivot.ts | 6 +- src/helpers/pivot/table_spreadsheet_pivot.ts | 6 +- src/helpers/sort.ts | 63 +--------- src/helpers/ui/freeze_interactive.ts | 3 +- src/history/operation.ts | 3 +- src/index.ts | 7 +- src/plugins/core/borders.ts | 2 +- src/plugins/core/cell.ts | 5 +- src/plugins/core/chart.ts | 2 +- src/plugins/core/conditional_format.ts | 6 +- src/plugins/core/header_grouping.ts | 3 +- src/plugins/core/header_size.ts | 3 +- src/plugins/core/header_visibility.ts | 2 +- src/plugins/core/image.ts | 4 +- src/plugins/core/merge.ts | 27 ----- src/plugins/core/pivot.ts | 3 +- src/plugins/core/range.ts | 2 +- src/plugins/core/sheet.ts | 15 +-- src/plugins/core/tables.ts | 5 +- src/plugins/ui_core_views/cell_icon_plugin.ts | 7 -- src/plugins/ui_core_views/custom_colors.ts | 14 +-- src/plugins/ui_core_views/dynamic_tables.ts | 5 +- .../evaluation_conditional_format.ts | 2 +- .../evaluation_data_validation.ts | 5 +- src/plugins/ui_core_views/header_sizes_ui.ts | 3 +- src/plugins/ui_core_views/pivot_ui.ts | 12 +- src/plugins/ui_feature/automatic_sum.ts | 3 +- src/plugins/ui_feature/data_cleanup.ts | 11 +- src/plugins/ui_feature/format.ts | 10 +- .../ui_feature/header_visibility_ui.ts | 3 +- src/plugins/ui_feature/sort.ts | 19 ++- src/plugins/ui_feature/subtotal_evaluation.ts | 12 +- src/plugins/ui_stateful/carousel_ui.ts | 4 +- src/plugins/ui_stateful/clipboard.ts | 2 +- src/plugins/ui_stateful/header_positions.ts | 2 +- src/plugins/ui_stateful/selection.ts | 2 +- src/plugins/ui_stateful/sheetview.ts | 15 +-- .../auto_completes/pivot_auto_complete.ts | 4 +- src/registries/cell_clickable_registry.ts | 3 +- src/registries/icons_on_cell_registry.ts | 4 +- src/registries/menus/header_group_registry.ts | 2 +- .../selection_stream_processor.ts | 28 ++--- src/stores/grid_renderer_store.ts | 11 +- src/types/commands.ts | 7 +- src/types/index.ts | 3 - src/types/misc.ts | 109 ------------------ src/types/workbook_data.ts | 2 +- src/xlsx/conversion/figure_conversion.ts | 10 +- src/xlsx/conversion/sheet_conversion.ts | 3 +- src/xlsx/extraction/base_extractor.ts | 2 +- src/xlsx/helpers/misc.ts | 3 +- tests/__mocks__/mock_misc_helpers.ts | 2 +- .../collaborative_monkey_party.test.ts | 4 +- tests/colors/color_helpers.test.ts | 14 +-- tests/formats/formatting_plugin.test.ts | 3 +- tests/functions/helper.test.ts | 3 +- .../header_group_component.test.ts | 2 +- .../header_group/header_group_plugin.test.ts | 3 +- tests/helpers/misc_helpers.test.ts | 3 +- tests/helpers/ui_helpers.test.ts | 3 +- tests/pivots/pivot_menu_items.test.ts | 9 +- tests/repeat_commands_plugin.test.ts | 3 +- tests/setup/jest_extend.ts | 3 +- tests/sheet/navigation_plugin.test.ts | 3 +- tests/sheet/selection_plugin.test.ts | 3 +- tests/sheet/sheetview_plugin.test.ts | 6 +- tests/test_helpers/commands_helpers.ts | 14 +-- tests/xlsx/xlsx_export.test.ts | 3 +- 169 files changed, 619 insertions(+), 788 deletions(-) rename {src => packages/o-spreadsheet-engine/src}/functions/helper_assert.ts (87%) rename {src => packages/o-spreadsheet-engine/src}/functions/helper_math.ts (88%) rename {src => packages/o-spreadsheet-engine/src}/functions/helper_statistical.ts (95%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_custom.ts (88%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_database.ts (98%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_engineering.ts (91%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_filter.ts (97%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_financial.ts (100%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_lookup.ts (98%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_math.ts (99%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_operators.ts (99%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_statistical.ts (99%) rename {src => packages/o-spreadsheet-engine/src}/helpers/coordinates.ts (98%) rename {src => packages/o-spreadsheet-engine/src}/helpers/dates.ts (100%) create mode 100644 packages/o-spreadsheet-engine/src/helpers/is_subtotal_cell.ts rename {src => packages/o-spreadsheet-engine/src}/helpers/recompute_zones.ts (99%) create mode 100644 packages/o-spreadsheet-engine/src/helpers/sort.ts rename {src => packages/o-spreadsheet-engine/src}/helpers/zones.ts (99%) rename {src => packages/o-spreadsheet-engine/src}/types/cells.ts (92%) rename {src => packages/o-spreadsheet-engine/src}/types/format.ts (78%) create mode 100644 packages/o-spreadsheet-engine/src/types/misc.ts rename {src => packages/o-spreadsheet-engine/src}/types/range.ts (89%) diff --git a/packages/o-spreadsheet-engine/src/functions/functionRegistry.ts b/packages/o-spreadsheet-engine/src/functions/functionRegistry.ts index 836697e520..38045bf712 100644 --- a/packages/o-spreadsheet-engine/src/functions/functionRegistry.ts +++ b/packages/o-spreadsheet-engine/src/functions/functionRegistry.ts @@ -1,6 +1,18 @@ import { _t } from "../translation"; -import { ComputeFunction, FunctionDescription, Functions, Matrix } from "../types"; +import { + Arg, + BadExpressionError, + ComputeFunction, + EvalContext, + FunctionDescription, + FunctionResultObject, + Functions, + isMatrix, + Matrix, +} from "../types"; +import { addMetaInfoFromArg, validateArguments } from "./arguments"; +import { FunctionRegistry } from "./function_registry"; import * as array from "./module_array"; import * as misc from "./module_custom"; import * as database from "./module_database"; diff --git a/src/functions/helper_assert.ts b/packages/o-spreadsheet-engine/src/functions/helper_assert.ts similarity index 87% rename from src/functions/helper_assert.ts rename to packages/o-spreadsheet-engine/src/functions/helper_assert.ts index 16bbed16cf..c1d4577acd 100644 --- a/src/functions/helper_assert.ts +++ b/packages/o-spreadsheet-engine/src/functions/helper_assert.ts @@ -1,7 +1,7 @@ -import { Arg, FunctionResultObject, isMatrix, Matrix } from "@odoo/o-spreadsheet-engine"; import { _t } from "../translation"; -import { FunctionResultNumber } from "../types"; -import { EvaluationError } from "../types/errors"; +import { Arg, FunctionResultObject, Matrix, isMatrix } from "../types"; +import { DivisionByZeroError, EvaluationError } from "../types/errors"; +import { FunctionResultNumber } from "../types/misc"; export function assert(condition: boolean, message: string): asserts condition { if (!condition) { diff --git a/src/functions/helper_math.ts b/packages/o-spreadsheet-engine/src/functions/helper_math.ts similarity index 88% rename from src/functions/helper_math.ts rename to packages/o-spreadsheet-engine/src/functions/helper_math.ts index 9a497886f7..c28d0aed2a 100644 --- a/src/functions/helper_math.ts +++ b/packages/o-spreadsheet-engine/src/functions/helper_math.ts @@ -1,4 +1,4 @@ -import { Arg } from "@odoo/o-spreadsheet-engine"; +import { Arg } from "../index"; import { Locale } from "../types"; import { isDataNonEmpty, reduceAny, reduceNumbers } from "./helpers"; diff --git a/src/functions/helper_statistical.ts b/packages/o-spreadsheet-engine/src/functions/helper_statistical.ts similarity index 95% rename from src/functions/helper_statistical.ts rename to packages/o-spreadsheet-engine/src/functions/helper_statistical.ts index a37fbd483f..b7d3b75db9 100644 --- a/src/functions/helper_statistical.ts +++ b/packages/o-spreadsheet-engine/src/functions/helper_statistical.ts @@ -1,19 +1,15 @@ -import { isMatrix } from "@odoo/o-spreadsheet-engine"; -import { - invertMatrix, - multiplyMatrices, -} from "@odoo/o-spreadsheet-engine/functions/helper_matrices"; +import { isMatrix } from ".."; +import { invertMatrix, multiplyMatrices } from "../functions/helper_matrices"; import { isEvaluationError, reduceAny, reduceNumbers, transposeMatrix, visitNumbers, -} from "@odoo/o-spreadsheet-engine/functions/helpers"; -import { Arg, EvaluationError, Locale } from "@odoo/o-spreadsheet-engine/types"; -import { Matrix } from "@odoo/o-spreadsheet-engine/types/base"; +} from "../functions/helpers"; import { isNumber, parseDateTime, range } from "../helpers"; import { _t } from "../translation"; +import { Arg, EvaluationError, Locale, Matrix } from "../types"; import { assert, assertNotZero } from "./helper_assert"; export function assertSameNumberOfElements(...args: any[][]) { diff --git a/src/functions/module_custom.ts b/packages/o-spreadsheet-engine/src/functions/module_custom.ts similarity index 88% rename from src/functions/module_custom.ts rename to packages/o-spreadsheet-engine/src/functions/module_custom.ts index bcc7936e2d..0a7c9950b2 100644 --- a/src/functions/module_custom.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_custom.ts @@ -1,7 +1,6 @@ -import { FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; import { formatLargeNumber } from "../helpers"; import { _t } from "../translation"; -import { FunctionResultNumber } from "../types"; +import { FunctionResultNumber, FunctionResultObject, Functions, Maybe } from "../types"; import { arg } from "./arguments"; import { toNumber } from "./helpers"; diff --git a/src/functions/module_database.ts b/packages/o-spreadsheet-engine/src/functions/module_database.ts similarity index 98% rename from src/functions/module_database.ts rename to packages/o-spreadsheet-engine/src/functions/module_database.ts index 5722a92fd0..12489ea711 100644 --- a/src/functions/module_database.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_database.ts @@ -1,9 +1,9 @@ -import { Arg, FunctionResultObject, Functions, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; +import { arg } from "../functions/arguments"; +import { toString, visitMatchingRanges } from "../functions/helpers"; +import { Arg, FunctionResultObject, Functions, Matrix, Maybe } from "../index"; import { _t } from "../translation"; import { FunctionResultNumber, Locale } from "../types"; import { EvaluationError } from "../types/errors"; -import { arg } from "./arguments"; -import { toString, visitMatchingRanges } from "./helpers"; import { PRODUCT, SUM } from "./module_math"; import { AVERAGE, COUNT, COUNTA, MAX, MIN, STDEV, STDEVP, VAR, VARP } from "./module_statistical"; diff --git a/src/functions/module_engineering.ts b/packages/o-spreadsheet-engine/src/functions/module_engineering.ts similarity index 91% rename from src/functions/module_engineering.ts rename to packages/o-spreadsheet-engine/src/functions/module_engineering.ts index 4ee9a23782..9aac64cc37 100644 --- a/src/functions/module_engineering.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_engineering.ts @@ -1,4 +1,4 @@ -import { FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; +import { FunctionResultObject, Functions, Maybe } from "../index"; import { _t } from "../translation"; import { arg } from "./arguments"; import { toNumber } from "./helpers"; diff --git a/src/functions/module_filter.ts b/packages/o-spreadsheet-engine/src/functions/module_filter.ts similarity index 97% rename from src/functions/module_filter.ts rename to packages/o-spreadsheet-engine/src/functions/module_filter.ts index 5af2197b21..d2d16c7dc5 100644 --- a/src/functions/module_filter.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_filter.ts @@ -1,16 +1,15 @@ -import { - Arg, - FunctionResultObject, - Functions, - isMatrix, - Matrix, - Maybe, -} from "@odoo/o-spreadsheet-engine"; import { range } from "../helpers"; import { cellsSortingCriterion } from "../helpers/sort"; +import { Arg, FunctionResultObject, Functions, isMatrix, Matrix, Maybe } from "../index"; import { _t } from "../translation"; -import { CellValue, CellValueType, Locale, SortDirection } from "../types"; -import { EvaluationError, NotAvailableError } from "../types/errors"; +import { + CellValue, + CellValueType, + EvaluationError, + Locale, + NotAvailableError, + SortDirection, +} from "../types"; import { arg } from "./arguments"; import { areSameDimensions, assert, isSingleColOrRow } from "./helper_assert"; import { toScalar } from "./helper_matrices"; diff --git a/src/functions/module_financial.ts b/packages/o-spreadsheet-engine/src/functions/module_financial.ts similarity index 100% rename from src/functions/module_financial.ts rename to packages/o-spreadsheet-engine/src/functions/module_financial.ts diff --git a/src/functions/module_lookup.ts b/packages/o-spreadsheet-engine/src/functions/module_lookup.ts similarity index 98% rename from src/functions/module_lookup.ts rename to packages/o-spreadsheet-engine/src/functions/module_lookup.ts index 9ccc4ed9e4..da88851a9b 100644 --- a/src/functions/module_lookup.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_lookup.ts @@ -1,16 +1,23 @@ -import { - Arg, - FunctionResultObject, - Functions, - Matrix, - Maybe, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { getFullReference, splitReference, toXC, toZone } from "../helpers/index"; +import { getFullReference, splitReference, toXC, toZone } from "../helpers"; +import { Arg, FunctionResultObject, Functions, Matrix, Maybe, Zone } from "../index"; import { _t } from "../translation"; -import { CellErrorType, EvaluationError, InvalidReferenceError } from "../types/errors"; +import { CellErrorType, EvaluationError, InvalidReferenceError } from "../types"; import { arg } from "./arguments"; import { expectNumberGreaterThanOrEqualToOne } from "./helper_assert"; +import { + LinearSearchMode, + dichotomicSearch, + expectNumberRangeError, + generateMatrix, + isEvaluationError, + linearSearch, + strictToInteger, + toBoolean, + toMatrix, + toNumber, + toString, + valueNotAvailable, +} from "./helpers"; const DEFAULT_IS_SORTED = true; const DEFAULT_MATCH_MODE = 0; const DEFAULT_SEARCH_MODE = 1; diff --git a/src/functions/module_math.ts b/packages/o-spreadsheet-engine/src/functions/module_math.ts similarity index 99% rename from src/functions/module_math.ts rename to packages/o-spreadsheet-engine/src/functions/module_math.ts index 6bcb6f4d90..2a7d5cb59b 100644 --- a/src/functions/module_math.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_math.ts @@ -1,15 +1,9 @@ -import { - Arg, - FunctionResultObject, - Functions, - isMatrix, - Matrix, - Maybe, -} from "@odoo/o-spreadsheet-engine"; +import { FunctionResultNumber } from "@odoo/o-spreadsheet-engine/types"; import { splitReference, toZone } from "../helpers"; -import { isSubtotalCell } from "../plugins/ui_feature/subtotal_evaluation"; +import { isSubtotalCell } from "../helpers/is_subtotal_cell"; +import { Arg, FunctionResultObject, Functions, isMatrix, Matrix, Maybe } from "../index"; import { _t } from "../translation"; -import { EvaluatedCell, FunctionResultNumber } from "../types"; +import { EvaluatedCell } from "../types"; import { DivisionByZeroError, EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { assertNotZero } from "./helper_assert"; diff --git a/src/functions/module_operators.ts b/packages/o-spreadsheet-engine/src/functions/module_operators.ts similarity index 99% rename from src/functions/module_operators.ts rename to packages/o-spreadsheet-engine/src/functions/module_operators.ts index da461efe1f..827a0d90fc 100644 --- a/src/functions/module_operators.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_operators.ts @@ -1,4 +1,4 @@ -import { FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; +import { FunctionResultObject, Functions, Maybe } from "../index"; import { _t } from "../translation"; import { FunctionResultNumber } from "../types"; import { DivisionByZeroError } from "../types/errors"; diff --git a/src/functions/module_statistical.ts b/packages/o-spreadsheet-engine/src/functions/module_statistical.ts similarity index 99% rename from src/functions/module_statistical.ts rename to packages/o-spreadsheet-engine/src/functions/module_statistical.ts index 5102142fd0..050c5039f6 100644 --- a/src/functions/module_statistical.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_statistical.ts @@ -1,12 +1,5 @@ -import { - Arg, - FunctionResultObject, - Functions, - isMatrix, - Matrix, - Maybe, -} from "@odoo/o-spreadsheet-engine"; import { percentile } from "../helpers/index"; +import { Arg, FunctionResultObject, Functions, isMatrix, Matrix, Maybe } from "../index"; import { _t } from "../translation"; import { FunctionResultNumber, Locale } from "../types"; import { DivisionByZeroError, EvaluationError, NotAvailableError } from "../types/errors"; diff --git a/src/helpers/coordinates.ts b/packages/o-spreadsheet-engine/src/helpers/coordinates.ts similarity index 98% rename from src/helpers/coordinates.ts rename to packages/o-spreadsheet-engine/src/helpers/coordinates.ts index 6e6fc9c11a..6069759e14 100644 --- a/src/helpers/coordinates.ts +++ b/packages/o-spreadsheet-engine/src/helpers/coordinates.ts @@ -2,7 +2,7 @@ // Coordinate //------------------------------------------------------------------------------ -import { HeaderIndex, Position } from "@odoo/o-spreadsheet-engine"; +import { HeaderIndex, Position } from "../index"; import { RangePart } from "../types"; import { TokenizingChars } from "./misc"; diff --git a/src/helpers/dates.ts b/packages/o-spreadsheet-engine/src/helpers/dates.ts similarity index 100% rename from src/helpers/dates.ts rename to packages/o-spreadsheet-engine/src/helpers/dates.ts diff --git a/packages/o-spreadsheet-engine/src/helpers/index.ts b/packages/o-spreadsheet-engine/src/helpers/index.ts index 78f559ea3c..d97d5e2f2a 100644 --- a/packages/o-spreadsheet-engine/src/helpers/index.ts +++ b/packages/o-spreadsheet-engine/src/helpers/index.ts @@ -1,5 +1,9 @@ +export * from "./coordinates"; +export * from "./dates"; export * from "./misc"; export * from "./numbers"; export * from "./references"; +export * from "./sort"; export * from "./state_manager_helpers"; export * from "./uuid"; +export * from "./zones"; diff --git a/packages/o-spreadsheet-engine/src/helpers/is_subtotal_cell.ts b/packages/o-spreadsheet-engine/src/helpers/is_subtotal_cell.ts new file mode 100644 index 0000000000..d1604d2d20 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/helpers/is_subtotal_cell.ts @@ -0,0 +1,10 @@ +import { Cell } from "../../../../src"; + +export function isSubtotalCell(cell: Cell): boolean { + return ( + cell.isFormula && + cell.compiledFormula.tokens.some( + (t) => t.type === "SYMBOL" && t.value.toUpperCase() === "SUBTOTAL" + ) + ); +} diff --git a/packages/o-spreadsheet-engine/src/helpers/misc.ts b/packages/o-spreadsheet-engine/src/helpers/misc.ts index bfbb28a718..dd240b4e4e 100644 --- a/packages/o-spreadsheet-engine/src/helpers/misc.ts +++ b/packages/o-spreadsheet-engine/src/helpers/misc.ts @@ -1,5 +1,59 @@ import { NEWLINE } from "../constants"; +/** + * Compares n objects. + */ + +export function deepEquals(...o: any[]): boolean { + if (o.length <= 1) return true; + for (let index = 1; index < o.length; index++) { + if (!_deepEquals(o[0], o[index])) return false; + } + return true; +} + +function _deepEquals(o1: any, o2: any): boolean { + if (o1 === o2) return true; + if ((o1 && !o2) || (o2 && !o1)) return false; + if (typeof o1 !== typeof o2) return false; + if (typeof o1 !== "object") return false; + + // Objects can have different keys if the values are undefined + for (const key in o2) { + if (!(key in o1) && o2[key] !== undefined) { + return false; + } + } + + for (const key in o1) { + if (typeof o1[key] !== typeof o2[key]) return false; + if (typeof o1[key] === "object") { + if (!_deepEquals(o1[key], o2[key])) return false; + } else { + if (o1[key] !== o2[key]) return false; + } + } + + return true; +} + +/** + * Compares two arrays. + * For performance reasons, this function is to be preferred + * to 'deepEquals' in the case we know that the inputs are arrays. + */ +export function deepEqualsArray(arr1: unknown[], arr2: unknown[]): boolean { + if (arr1.length !== arr2.length) { + return false; + } + for (let i = 0; i < arr1.length; i++) { + if (!deepEquals(arr1[i], arr2[i])) { + return false; + } + } + return true; +} + /** * Escapes a string to use as a literal string in a RegExp. */ @@ -127,3 +181,10 @@ export class TokenizingChars { return true; } } +/** + * This helper function can be used as a type guard when filtering arrays. + * const foo: number[] = [1, 2, undefined, 4].filter(isDefined) + */ +export function isDefined(argument: T | undefined): argument is T { + return argument !== undefined; +} diff --git a/src/helpers/recompute_zones.ts b/packages/o-spreadsheet-engine/src/helpers/recompute_zones.ts similarity index 99% rename from src/helpers/recompute_zones.ts rename to packages/o-spreadsheet-engine/src/helpers/recompute_zones.ts index 7dbff44cc5..5c2151f62b 100644 --- a/src/helpers/recompute_zones.ts +++ b/packages/o-spreadsheet-engine/src/helpers/recompute_zones.ts @@ -1,5 +1,5 @@ -import { UnboundedZone, Zone } from "@odoo/o-spreadsheet-engine"; import { deepEqualsArray } from "../helpers/misc"; +import { UnboundedZone, Zone } from "../index"; /** * #################################################### diff --git a/packages/o-spreadsheet-engine/src/helpers/sort.ts b/packages/o-spreadsheet-engine/src/helpers/sort.ts new file mode 100644 index 0000000000..7b3ce32b69 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/helpers/sort.ts @@ -0,0 +1,52 @@ +import { CellValue, CellValueType, EvaluatedCell, SortDirection } from "../index"; + +type CellWithIndex = { index: number; type: CellValueType; value: any }; +const SORT_TYPES: CellValueType[] = [ + CellValueType.number, + CellValueType.error, + CellValueType.text, + CellValueType.boolean, +]; + +export function cellsSortingCriterion(sortingOrder: string) { + const inverse = sortingOrder === "asc" ? 1 : -1; + return ( + left: { type: CellValueType; value: CellValue }, + right: { type: CellValueType; value: CellValue } + ) => { + if (left.type === CellValueType.empty) { + return right.type === CellValueType.empty ? 0 : 1; + } else if (right.type === CellValueType.empty) { + return -1; + } + let typeOrder = SORT_TYPES.indexOf(left.type) - SORT_TYPES.indexOf(right.type); + if (typeOrder === 0) { + if (left.type === CellValueType.text || left.type === CellValueType.error) { + typeOrder = (left.value as string).localeCompare(right.value as string); + } else { + typeOrder = (left.value as number) - (right.value as number); + } + } + return inverse * typeOrder; + }; +} + +export function sort( + cells: EvaluatedCell[], + sortDirection: SortDirection, + emptyCellAsZero: boolean +): CellWithIndex[] { + const cellsWithIndex: CellWithIndex[] = cells.map((cell, index) => ({ + index, + type: cell.type, + value: cell.value, + })); + + const cellsToSort = emptyCellAsZero + ? cellsWithIndex.map((cell) => + cell.type === CellValueType.empty ? { ...cell, type: CellValueType.number, value: 0 } : cell + ) + : cellsWithIndex; + + return cellsToSort.sort(cellsSortingCriterion(sortDirection)); +} diff --git a/src/helpers/zones.ts b/packages/o-spreadsheet-engine/src/helpers/zones.ts similarity index 99% rename from src/helpers/zones.ts rename to packages/o-spreadsheet-engine/src/helpers/zones.ts index 84c4f26025..a7c7765cbc 100644 --- a/src/helpers/zones.ts +++ b/packages/o-spreadsheet-engine/src/helpers/zones.ts @@ -6,7 +6,7 @@ import { UnboundedZone, Zone, ZoneDimension, -} from "@odoo/o-spreadsheet-engine"; +} from "../types"; import { MAX_COL, MAX_ROW, diff --git a/packages/o-spreadsheet-engine/src/types/base.ts b/packages/o-spreadsheet-engine/src/types/base.ts index 8e2186d191..ba2d87e558 100644 --- a/packages/o-spreadsheet-engine/src/types/base.ts +++ b/packages/o-spreadsheet-engine/src/types/base.ts @@ -1,67 +1,9 @@ -export type Alias = {} & {}; - -export type UID = string & Alias; - -export type HeaderIndex = number & Alias; - -export interface CellPosition { - col: HeaderIndex; - row: HeaderIndex; - sheetId: UID; -} - -export interface Zone { - left: HeaderIndex; - right: HeaderIndex; - top: HeaderIndex; - bottom: HeaderIndex; -} +import { Alias } from "./isMatrix"; export type Range = unknown; -export type CellValue = string | number | boolean | null; - export type Format = string & Alias; -export type Maybe = T | undefined; - -export type Matrix = T[][]; - export type Dimension = "COL" | "ROW"; export type SortDirection = "asc" | "desc"; - -export interface FunctionResultObject { - value: CellValue; - format?: Format; - errorOriginPosition?: CellPosition; - message?: string; - origin?: CellPosition; -} - -export type ReferenceDenormalizer = ( - range: Range, - isMeta: boolean, - functionName: string, - paramNumber: number -) => FunctionResultObject; - -export type EnsureRange = (range: Range, isMeta: boolean) => Matrix; - -export type GetSymbolValue = (symbolName: string) => unknown; - -export type FormulaToExecute = ( - deps: Range[], - refFn: ReferenceDenormalizer, - range: EnsureRange, - getSymbolValue: GetSymbolValue, - ctx: Record -) => Matrix | FunctionResultObject; - -export interface CompiledFormula { - execute: FormulaToExecute; - tokens: unknown[]; - dependencies: string[]; - isBadExpression: boolean; - normalizedFormula: string; -} diff --git a/src/types/cells.ts b/packages/o-spreadsheet-engine/src/types/cells.ts similarity index 92% rename from src/types/cells.ts rename to packages/o-spreadsheet-engine/src/types/cells.ts index 41f30ad595..30dc6753ae 100644 --- a/src/types/cells.ts +++ b/packages/o-spreadsheet-engine/src/types/cells.ts @@ -1,5 +1,6 @@ -import { Style, UID } from "@odoo/o-spreadsheet-engine"; -import { Format } from "./format"; +import { FunctionResultObject, RangeCompiledFormula, Style, UID } from "../index"; +import { Format, FormattedValue } from "./format"; +import { Link } from "./misc"; interface CellAttributes { readonly id: UID; diff --git a/src/types/format.ts b/packages/o-spreadsheet-engine/src/types/format.ts similarity index 78% rename from src/types/format.ts rename to packages/o-spreadsheet-engine/src/types/format.ts index 9d0003cdb0..812fbd488f 100644 --- a/src/types/format.ts +++ b/packages/o-spreadsheet-engine/src/types/format.ts @@ -1,6 +1,6 @@ import { Locale } from "./locale"; -import { Alias } from "@odoo/o-spreadsheet-engine"; +import { Alias } from "../index"; export type Format = string & Alias; diff --git a/packages/o-spreadsheet-engine/src/types/index.ts b/packages/o-spreadsheet-engine/src/types/index.ts index 523568b652..b3808f22ce 100644 --- a/packages/o-spreadsheet-engine/src/types/index.ts +++ b/packages/o-spreadsheet-engine/src/types/index.ts @@ -1,7 +1,28 @@ export * from "./base"; +export * from "./cells"; export * from "./errors"; export * from "./functions"; export * from "./history"; export * from "./isMatrix"; export * from "./locale"; +export { + Cloneable, + DebouncedFunction, + Dimension, + Direction, + FunctionResultNumber, + HSLA, + Immutable, + Increment, + Lazy, + Link, + Offset, + RGBA, + Ref, + SelectionStep, + SetDecimalStep, + SortDirection, + SortOptions, + ValueAndLabel, +} from "./misc"; export * from "./validator"; diff --git a/packages/o-spreadsheet-engine/src/types/isMatrix.ts b/packages/o-spreadsheet-engine/src/types/isMatrix.ts index ae580cbd9d..4f70005793 100644 --- a/packages/o-spreadsheet-engine/src/types/isMatrix.ts +++ b/packages/o-spreadsheet-engine/src/types/isMatrix.ts @@ -1,3 +1,6 @@ +import { Token } from "../formulas/tokenizer"; +import { CellValue, EvaluatedCell, Format } from "./index"; + /** * The following type is meant to be used in union with other aliases to prevent * Intellisense from resolving it. diff --git a/packages/o-spreadsheet-engine/src/types/misc.ts b/packages/o-spreadsheet-engine/src/types/misc.ts new file mode 100644 index 0000000000..76ab971422 --- /dev/null +++ b/packages/o-spreadsheet-engine/src/types/misc.ts @@ -0,0 +1,100 @@ +export type FunctionResultNumber = { value: number; format?: string }; +export type SetDecimalStep = 1 | -1; + +export interface RGBA { + a: number; + r: number; + g: number; + b: number; +} + +export interface HSLA { + a: number; + h: number; + s: number; + l: number; +} + +export interface Link { + readonly label: string; + readonly url: string; + readonly isExternal: boolean; + /** + * Specifies if the URL is editable by the end user. + * Special links might not allow it. + */ + readonly isUrlEditable: boolean; +} + +export type Dimension = "COL" | "ROW"; +export type Increment = 1 | -1 | 0; + +export interface Ref { + el: T | null; +} + +/** + * Container for a lazy computed value + */ +export interface Lazy { + /** + * Return the computed value. + * The value is computed only once and memoized. + */ + (): T; + /** + * Map a lazy value to another lazy value. + * + * ```ts + * // neither function is called here + * const lazyValue = lazy(() => veryExpensive(...)).map((result) => alsoVeryExpensive(result)); + * + * // both values are computed now + * const value = lazyValue() + * ``` + */ + map: (callback: (value: T) => U) => Lazy; +} + +export interface Cloneable { + clone: (args?: Partial) => T; +} + +export interface SortOptions { + /** If true sort the headers of the range along with the rest */ + sortHeaders?: boolean; + /** If true treat empty cells as "0" instead of undefined */ + emptyCellAsZero?: boolean; +} + +// https://github.com/Microsoft/TypeScript/issues/13923#issuecomment-557509399 +// prettier-ignore +export type Immutable = + T extends ImmutablePrimitive ? T : + T extends Array ? ImmutableArray : + T extends Map ? ImmutableMap : + T extends Set ? ImmutableSet : + ImmutableObject; +type ImmutablePrimitive = undefined | null | boolean | string | number | Function; +type ImmutableArray = ReadonlyArray>; +type ImmutableMap = ReadonlyMap, Immutable>; +type ImmutableSet = ReadonlySet>; +type ImmutableObject = { readonly [K in keyof T]: Immutable }; +export type Direction = "up" | "down" | "left" | "right"; +export type SelectionStep = number | "end"; + +export interface Offset { + col: number; + row: number; +} + +export type DebouncedFunction = T & { + stopDebounce: () => void; + isDebouncePending: () => boolean; +}; +export type SortDirection = "asc" | "desc"; + +export interface ValueAndLabel { + value: T; + label: string; +} diff --git a/src/types/range.ts b/packages/o-spreadsheet-engine/src/types/range.ts similarity index 89% rename from src/types/range.ts rename to packages/o-spreadsheet-engine/src/types/range.ts index 118e275376..7236369d54 100644 --- a/src/types/range.ts +++ b/packages/o-spreadsheet-engine/src/types/range.ts @@ -1,3 +1,6 @@ +import { UID, Zone } from "./base"; +import { UnboundedZone } from "./isMatrix"; + export interface RangePart { readonly colFixed: boolean; readonly rowFixed: boolean; diff --git a/src/actions/figure_menu_actions.ts b/src/actions/figure_menu_actions.ts index e753785c8f..83e65d005e 100644 --- a/src/actions/figure_menu_actions.ts +++ b/src/actions/figure_menu_actions.ts @@ -1,8 +1,7 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, UID } from "@odoo/o-spreadsheet-engine"; import { downloadFile } from "../components/helpers/dom_helpers"; import { chartToImageFile, chartToImageUrl } from "../helpers/figures/charts"; import { getMaxFigureSize } from "../helpers/figures/figure/figure"; -import { deepEquals } from "../helpers/misc"; import { _t } from "../translation"; import { SpreadsheetChildEnv } from "../types"; import { xmlEscape } from "../xlsx/helpers/xml_helpers"; diff --git a/src/actions/insert_actions.ts b/src/actions/insert_actions.ts index 68565b47bb..f66be97fb5 100644 --- a/src/actions/insert_actions.ts +++ b/src/actions/insert_actions.ts @@ -1,6 +1,3 @@ -import { functionRegistry } from "@odoo/o-spreadsheet-engine"; -import { isDefined } from "../helpers"; -import { localizeDataValidationRule } from "../helpers/locale"; import { handlePasteResult } from "../helpers/ui/paste_interactive"; import { _t } from "../translation"; import { ActionBuilder, ActionSpec } from "./action"; diff --git a/src/actions/menu_items_actions.ts b/src/actions/menu_items_actions.ts index 9f3cdaa0d0..aaa336b4fb 100644 --- a/src/actions/menu_items_actions.ts +++ b/src/actions/menu_items_actions.ts @@ -1,4 +1,5 @@ import { Style } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { CellPopoverStore } from "../components/popover"; import { getPivotTooBigErrorMessage } from "../components/translations_terms"; import { @@ -24,7 +25,7 @@ import { interactiveCreateTable } from "../helpers/ui/table_interactive"; import { _t } from "../translation"; import { ClipboardMIMEType, ClipboardPasteOptions } from "../types/clipboard"; import { Image } from "../types/image"; -import { Dimension, Format, SpreadsheetChildEnv } from "../types/index"; +import { Format, SpreadsheetChildEnv } from "../types/index"; import { ActionSpec } from "./action"; //------------------------------------------------------------------------------ diff --git a/src/actions/view_actions.ts b/src/actions/view_actions.ts index ab42be2582..d74848c130 100644 --- a/src/actions/view_actions.ts +++ b/src/actions/view_actions.ts @@ -1,9 +1,9 @@ +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { numberToLetters } from "../helpers"; import { interactiveFreezeColumnsRows } from "../helpers/ui/freeze_interactive"; import { FormulaFingerprintStore } from "../stores/formula_fingerprints_store"; import { _t } from "../translation"; import { SpreadsheetChildEnv } from "../types"; -import { Dimension } from "./../types/misc"; import { ActionSpec } from "./action"; import * as ACTIONS from "./menu_items_actions"; diff --git a/src/clipboard_handlers/borders_clipboard.ts b/src/clipboard_handlers/borders_clipboard.ts index f3401114de..35529d07a9 100644 --- a/src/clipboard_handlers/borders_clipboard.ts +++ b/src/clipboard_handlers/borders_clipboard.ts @@ -1,6 +1,12 @@ -import { BorderDescr, BorderPosition, HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; +import { + BorderDescr, + BorderPosition, + deepEquals, + HeaderIndex, + UID, +} from "@odoo/o-spreadsheet-engine"; import { splitZoneForPaste } from "../helpers/clipboard/clipboard_helpers"; -import { deepEquals, groupConsecutive } from "../helpers/misc"; +import { groupConsecutive } from "../helpers/misc"; import { ZoneBorder, ZoneBorderData } from "../plugins/core"; import { ClipboardCellData, ClipboardOptions, ClipboardPasteTarget } from "../types"; import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; diff --git a/src/clipboard_handlers/cell_clipboard.ts b/src/clipboard_handlers/cell_clipboard.ts index a157f903cd..4ebac22783 100644 --- a/src/clipboard_handlers/cell_clipboard.ts +++ b/src/clipboard_handlers/cell_clipboard.ts @@ -1,5 +1,12 @@ -import { CellPosition, ClipboardCell, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { deepEquals, formatValue, isZoneInside } from "../helpers"; +import { + CellPosition, + ClipboardCell, + deepEquals, + HeaderIndex, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; +import { formatValue, isZoneInside } from "../helpers"; import { getPasteZones } from "../helpers/clipboard/clipboard_helpers"; import { canonicalizeNumberValue } from "../helpers/locale"; import { createPivotFormula } from "../helpers/pivot/pivot_helpers"; diff --git a/src/clipboard_handlers/conditional_format_clipboard.ts b/src/clipboard_handlers/conditional_format_clipboard.ts index 43065a6a0b..a7816384da 100644 --- a/src/clipboard_handlers/conditional_format_clipboard.ts +++ b/src/clipboard_handlers/conditional_format_clipboard.ts @@ -1,5 +1,12 @@ -import { CellPosition, HeaderIndex, Maybe, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { UuidGenerator, deepEquals, positionToZone } from "../helpers"; +import { + CellPosition, + deepEquals, + HeaderIndex, + Maybe, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; +import { positionToZone, UuidGenerator } from "../helpers"; import { ClipboardCellData, ClipboardOptions, diff --git a/src/clipboard_handlers/data_validation_clipboard.ts b/src/clipboard_handlers/data_validation_clipboard.ts index 704d909d48..1ed52fdb4f 100644 --- a/src/clipboard_handlers/data_validation_clipboard.ts +++ b/src/clipboard_handlers/data_validation_clipboard.ts @@ -1,5 +1,12 @@ -import { CellPosition, HeaderIndex, Maybe, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { UuidGenerator, deepEquals, positionToZone, recomputeZones } from "../helpers"; +import { + CellPosition, + deepEquals, + HeaderIndex, + Maybe, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; +import { positionToZone, recomputeZones, UuidGenerator } from "../helpers"; import { ClipboardCellData, ClipboardOptions, diff --git a/src/clipboard_handlers/merge_clipboard.ts b/src/clipboard_handlers/merge_clipboard.ts index 7279933bc1..9cd5bf44c1 100644 --- a/src/clipboard_handlers/merge_clipboard.ts +++ b/src/clipboard_handlers/merge_clipboard.ts @@ -1,6 +1,3 @@ -import { CellPosition, HeaderIndex, Maybe, Merge, UID } from "@odoo/o-spreadsheet-engine"; -import { isDefined } from "../helpers"; -import { ClipboardCellData, ClipboardOptions, ClipboardPasteTarget } from "../types"; import { AbstractCellClipboardHandler } from "./abstract_cell_clipboard_handler"; interface ClipboardContent { diff --git a/src/collaborative/ot/ot.ts b/src/collaborative/ot/ot.ts index 9a0715f81e..ca13a1ac77 100644 --- a/src/collaborative/ot/ot.ts +++ b/src/collaborative/ot/ot.ts @@ -1,13 +1,3 @@ -import { HeaderIndex, Zone } from "@odoo/o-spreadsheet-engine"; -import { - getAddHeaderStartIndex, - getRangeAdapter, - isDefined, - isInside, - moveHeaderIndexesOnHeaderAddition, - moveHeaderIndexesOnHeaderDeletion, - rangeAdapterRegistry, -} from "../../helpers/index"; import { otRegistry } from "../../registries/ot_registry"; import { specificRangeTransformRegistry } from "../../registries/srt_registry"; import { diff --git a/src/collaborative/session.ts b/src/collaborative/session.ts index b4b0044a89..4eb8c7f792 100644 --- a/src/collaborative/session.ts +++ b/src/collaborative/session.ts @@ -1,10 +1,9 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { DEBOUNCE_TIME, DEFAULT_REVISION_ID, MESSAGE_VERSION } from "../constants"; +import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { EventBus } from "../helpers/event_bus"; -import { debounce, isDefined } from "../helpers/misc"; +import { debounce } from "../helpers/misc"; import { UuidGenerator } from "../helpers/uuid"; import { SelectiveHistory as RevisionLog } from "../history/selective_history"; -import { CoreCommand, HistoryChange, Lazy, WorkbookData } from "../types"; +import { CoreCommand, HistoryChange, WorkbookData } from "../types"; import { Client, ClientId, diff --git a/src/components/bottom_bar/bottom_bar.ts b/src/components/bottom_bar/bottom_bar.ts index 9349c1a193..25d1af5a94 100644 --- a/src/components/bottom_bar/bottom_bar.ts +++ b/src/components/bottom_bar/bottom_bar.ts @@ -1,6 +1,5 @@ -import { MenuMouseEvent, Pixel, UID } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, MenuMouseEvent, Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef, useState } from "@odoo/owl"; -import { deepEquals } from "../../helpers"; import { MenuItemRegistry } from "../../registries/menu_items_registry"; import { _t } from "../../translation"; import { Rect, SpreadsheetChildEnv } from "../../types"; diff --git a/src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store.ts b/src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store.ts index 5b28758806..75b4b6b929 100644 --- a/src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store.ts +++ b/src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store.ts @@ -1,3 +1,4 @@ +import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { sum } from "../../../functions/helper_math"; import { average, countAny, countNumbers, max, min } from "../../../functions/helper_statistical"; import { lazy, memoize, recomputeZones } from "../../../helpers"; @@ -8,7 +9,6 @@ import { CellValueType, Command, EvaluatedCell, - Lazy, Locale, invalidateEvaluationCommands, } from "../../../types"; diff --git a/src/components/color_picker/color_picker.ts b/src/components/color_picker/color_picker.ts index a1b577433f..20445130ec 100644 --- a/src/components/color_picker/color_picker.ts +++ b/src/components/color_picker/color_picker.ts @@ -1,4 +1,5 @@ import { Color, Pixel, PixelPosition } from "@odoo/o-spreadsheet-engine"; +import { HSLA } from "@odoo/o-spreadsheet-engine/types"; import { Component, useState } from "@odoo/owl"; import { COLOR_PICKER_DEFAULTS, ICON_EDGE_LENGTH } from "../../constants"; import { @@ -11,7 +12,7 @@ import { toHex, } from "../../helpers"; import { chartFontColor } from "../../helpers/figures/charts"; -import { HSLA, Rect } from "../../types"; +import { Rect } from "../../types"; import { SpreadsheetChildEnv } from "../../types/env"; import { cssPropertiesToCss } from "../helpers/css"; import { startDnd } from "../helpers/drag_and_drop"; diff --git a/src/components/composer/composer/abstract_composer_store.ts b/src/components/composer/composer/abstract_composer_store.ts index f71414cdd3..0a4cbec920 100644 --- a/src/components/composer/composer/abstract_composer_store.ts +++ b/src/components/composer/composer/abstract_composer_store.ts @@ -11,6 +11,7 @@ import { UnboundedZone, Zone, } from "@odoo/o-spreadsheet-engine"; +import { Direction } from "@odoo/o-spreadsheet-engine/types"; import { DEFAULT_TOKEN_COLOR, tokenColors } from "../../../constants"; import { composerTokenize, EnrichedToken } from "../../../formulas/composer_tokenizer"; import { AST, iterateAstNodes, parseTokens } from "../../../formulas/parser"; @@ -44,7 +45,7 @@ import { SpreadsheetStore } from "../../../stores"; import { HighlightStore } from "../../../stores/highlight_store"; import { NotificationStore } from "../../../stores/notification_store"; import { _t } from "../../../translation"; -import { Command, Direction, EditionMode, Range, RangePart } from "../../../types"; +import { Command, EditionMode, Range, RangePart } from "../../../types"; import { EvaluationError } from "../../../types/errors"; import { SelectionEvent } from "../../../types/event_stream"; import { AutoCompleteStore } from "../autocomplete_dropdown/autocomplete_dropdown_store"; diff --git a/src/components/composer/composer/cell_composer_store.ts b/src/components/composer/composer/cell_composer_store.ts index 8eb1cbab93..f935efd512 100644 --- a/src/components/composer/composer/cell_composer_store.ts +++ b/src/components/composer/composer/cell_composer_store.ts @@ -1,4 +1,5 @@ import { CellPosition, isMatrix } from "@odoo/o-spreadsheet-engine"; +import { Direction } from "@odoo/o-spreadsheet-engine/types"; import { prettify } from "../../../formulas/formula_formatter"; import { parseTokens } from "../../../formulas/parser"; import { isMultipleElementMatrix, toScalar } from "../../../functions/helper_matrices"; @@ -22,7 +23,6 @@ import { AddColumnsRowsCommand, CellValueType, Command, - Direction, Format, FormulaCell, Locale, diff --git a/src/components/composer/composer/composer.ts b/src/components/composer/composer/composer.ts index c6f1c0cb05..fd46f4db4a 100644 --- a/src/components/composer/composer/composer.ts +++ b/src/components/composer/composer/composer.ts @@ -1,17 +1,17 @@ import { Component, onMounted, onWillUnmount, useEffect, useRef, useState } from "@odoo/owl"; import { NEWLINE, SCROLLBAR_WIDTH } from "../../../constants"; -import { debounce, deepEquals, isFormula, setColorAlpha } from "../../../helpers/index"; +import { debounce, isFormula, setColorAlpha } from "../../../helpers/index"; -import { FunctionDescription, functionRegistry } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, FunctionDescription, functionRegistry } from "@odoo/o-spreadsheet-engine"; +import { Direction } from "@odoo/o-spreadsheet-engine/types"; import { EnrichedToken } from "../../../formulas/composer_tokenizer"; import { argTargeting } from "../../../functions/arguments"; import { Store, useStore } from "../../../store_engine"; import { DOMFocusableElementStore } from "../../../stores/DOM_focus_store"; import { - CSSProperties, ComposerFocusType, + CSSProperties, DOMDimension, - Direction, Rect, SpreadsheetChildEnv, } from "../../../types/index"; diff --git a/src/components/composer/content_editable_helper.ts b/src/components/composer/content_editable_helper.ts index 14ca648b88..b82628971e 100644 --- a/src/components/composer/content_editable_helper.ts +++ b/src/components/composer/content_editable_helper.ts @@ -1,4 +1,5 @@ -import { deepEquals, toHex } from "../../helpers"; +import { deepEquals } from "@odoo/o-spreadsheet-engine"; +import { toHex } from "../../helpers"; import { getBoundingRectAsPOJO, getCurrentSelection, diff --git a/src/components/composer/grid_composer/grid_composer.ts b/src/components/composer/grid_composer/grid_composer.ts index c13a9fd51e..8a40fa764d 100644 --- a/src/components/composer/grid_composer/grid_composer.ts +++ b/src/components/composer/grid_composer/grid_composer.ts @@ -1,8 +1,7 @@ -import { CellPosition } from "@odoo/o-spreadsheet-engine"; +import { CellPosition, deepEquals } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps } from "@odoo/owl"; import { SELECTION_BORDER_COLOR } from "../../../constants"; import { - deepEquals, fontSizeInPixels, getFullReference, isFormula, diff --git a/src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts b/src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts index 70ffce54ad..46eb5da121 100644 --- a/src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts +++ b/src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts @@ -1,9 +1,10 @@ import { CellPosition, Color, Style } from "@odoo/o-spreadsheet-engine"; +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { Component } from "@odoo/owl"; import { TEXT_BODY_MUTED } from "../../../constants"; import { blendColors } from "../../../helpers"; import { Store, useStore } from "../../../store_engine"; -import { SortDirection, SpreadsheetChildEnv } from "../../../types"; +import { SpreadsheetChildEnv } from "../../../types"; import { cssPropertiesToCss } from "../../helpers"; interface Props { position: CellPosition; diff --git a/src/components/dashboard/dashboard.ts b/src/components/dashboard/dashboard.ts index b436d319e2..310eb564c6 100644 --- a/src/components/dashboard/dashboard.ts +++ b/src/components/dashboard/dashboard.ts @@ -1,7 +1,8 @@ import { Pixel } from "@odoo/o-spreadsheet-engine"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { Component, toRaw, useChildSubEnv, useRef } from "@odoo/owl"; import { Store, useStore } from "../../store_engine"; -import { DOMCoordinates, DOMDimension, Rect, Ref, SpreadsheetChildEnv } from "../../types/index"; +import { DOMCoordinates, DOMDimension, Rect, SpreadsheetChildEnv } from "../../types/index"; import { DelayedHoveredCellStore } from "../grid/delayed_hovered_cell_store"; import { GridOverlay } from "../grid_overlay/grid_overlay"; import { GridPopover } from "../grid_popover/grid_popover"; diff --git a/src/components/error_tooltip/error_tooltip.ts b/src/components/error_tooltip/error_tooltip.ts index eb672a8c5b..d6a5b71217 100644 --- a/src/components/error_tooltip/error_tooltip.ts +++ b/src/components/error_tooltip/error_tooltip.ts @@ -1,6 +1,6 @@ -import { CellPosition } from "@odoo/o-spreadsheet-engine"; +import { CellPosition, deepEquals } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; -import { deepEquals, positionToZone } from "../../helpers"; +import { positionToZone } from "../../helpers"; import { CellValueType, SpreadsheetChildEnv } from "../../types"; import { CellPopoverComponent, PopoverBuilders } from "../../types/cell_popovers"; diff --git a/src/components/figures/chart/chartJs/chartjs.ts b/src/components/figures/chart/chartJs/chartjs.ts index b5f61c04b4..85954b76a8 100644 --- a/src/components/figures/chart/chartJs/chartjs.ts +++ b/src/components/figures/chart/chartJs/chartjs.ts @@ -1,7 +1,7 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, UID } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, onWillUnmount, useEffect, useRef } from "@odoo/owl"; import { Chart, ChartConfiguration } from "chart.js/auto"; -import { deepCopy, deepEquals } from "../../../../helpers"; +import { deepCopy } from "../../../../helpers"; import { Store, useStore } from "../../../../store_engine"; import { SpreadsheetChildEnv } from "../../../../types"; import { ChartJSRuntime } from "../../../../types/chart/chart"; diff --git a/src/components/figures/chart/chartJs/chartjs_sunburst_labels_plugin.ts b/src/components/figures/chart/chartJs/chartjs_sunburst_labels_plugin.ts index e3bc74b059..d4d66cecdb 100644 --- a/src/components/figures/chart/chartJs/chartjs_sunburst_labels_plugin.ts +++ b/src/components/figures/chart/chartJs/chartjs_sunburst_labels_plugin.ts @@ -1,11 +1,4 @@ -import { Style } from "@odoo/o-spreadsheet-engine"; -import { ChartType, Plugin } from "chart.js"; -import { - getDefaultContextFont, - isDefined, - relativeLuminance, - sliceTextToFitWidth, -} from "../../../../helpers"; +import { getDefaultContextFont, relativeLuminance, sliceTextToFitWidth } from "../../../../helpers"; import { GHOST_SUNBURST_VALUE } from "../../../../helpers/figures/charts/runtime/chartjs_dataset"; import { SunburstChartRawData } from "../../../../types/chart"; diff --git a/src/components/figures/chart/chart_dashboard_menu/chart_dashboard_menu.ts b/src/components/figures/chart/chart_dashboard_menu/chart_dashboard_menu.ts index add88bb570..7ab5d67791 100644 --- a/src/components/figures/chart/chart_dashboard_menu/chart_dashboard_menu.ts +++ b/src/components/figures/chart/chart_dashboard_menu/chart_dashboard_menu.ts @@ -1,8 +1,5 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { Component, useState } from "@odoo/owl"; import { getChartMenuActions } from "../../../../actions/figure_menu_actions"; import { BACKGROUND_CHART_COLOR } from "../../../../constants"; -import { isDefined } from "../../../../helpers"; import { Store, useStore } from "../../../../store_engine"; import { _t } from "../../../../translation"; import { SpreadsheetChildEnv } from "../../../../types"; diff --git a/src/components/figures/chart/gauge/gauge_chart_component.ts b/src/components/figures/chart/gauge/gauge_chart_component.ts index c9799918a3..78d36ebcc3 100644 --- a/src/components/figures/chart/gauge/gauge_chart_component.ts +++ b/src/components/figures/chart/gauge/gauge_chart_component.ts @@ -1,6 +1,5 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, UID } from "@odoo/o-spreadsheet-engine"; import { Component, useEffect, useRef } from "@odoo/owl"; -import { deepEquals } from "../../../../helpers"; import { drawGaugeChart } from "../../../../helpers/figures/charts/gauge_chart_rendering"; import { EASING_FN } from "../../../../registries/cell_animation_registry"; import { Store, useStore } from "../../../../store_engine"; diff --git a/src/components/figures/figure_carousel/figure_carousel.ts b/src/components/figures/figure_carousel/figure_carousel.ts index 90bb2e4ae7..794d78e059 100644 --- a/src/components/figures/figure_carousel/figure_carousel.ts +++ b/src/components/figures/figure_carousel/figure_carousel.ts @@ -1,8 +1,8 @@ -import { MenuMouseEvent } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, MenuMouseEvent } from "@odoo/o-spreadsheet-engine"; import { Component, useEffect, useRef, useState } from "@odoo/owl"; import { ActionSpec, createActions } from "../../../actions/action"; import { DEFAULT_CAROUSEL_TITLE_STYLE } from "../../../constants"; -import { chartStyleToCellStyle, deepEquals } from "../../../helpers"; +import { chartStyleToCellStyle } from "../../../helpers"; import { getCarouselItemTitle } from "../../../helpers/carousel_helpers"; import { chartComponentRegistry } from "../../../registries/chart_types"; import { Store, useStore } from "../../../store_engine"; diff --git a/src/components/figures/figure_container/figure_container.ts b/src/components/figures/figure_container/figure_container.ts index 52dbf53f3c..8ccdf79a5b 100644 --- a/src/components/figures/figure_container/figure_container.ts +++ b/src/components/figures/figure_container/figure_container.ts @@ -1,7 +1,4 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { Component, onMounted, onWillUpdateProps, useState } from "@odoo/owl"; import { DRAG_THRESHOLD, MIN_FIG_SIZE } from "../../../constants"; -import { isDefined } from "../../../helpers"; import { rectUnion } from "../../../helpers/rectangle"; import { figureRegistry } from "../../../registries/figures_registry"; import { @@ -17,10 +14,10 @@ import { startDnd } from "../../helpers/drag_and_drop"; import { dragFigureForMove, dragFigureForResize } from "../../helpers/figure_drag_helper"; import { HFigureAxisType, - SnapLine, - VFigureAxisType, snapForMove, snapForResize, + SnapLine, + VFigureAxisType, } from "../../helpers/figure_snap_helper"; import { FigureComponent } from "../figure/figure"; diff --git a/src/components/filters/filter_menu/filter_menu.ts b/src/components/filters/filter_menu/filter_menu.ts index 5406511c3e..43495f82b2 100644 --- a/src/components/filters/filter_menu/filter_menu.ts +++ b/src/components/filters/filter_menu/filter_menu.ts @@ -1,16 +1,16 @@ -import { Position } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, Position } from "@odoo/o-spreadsheet-engine"; +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { Component, onWillUpdateProps } from "@odoo/owl"; -import { deepEquals, isDateTimeFormat } from "../../../helpers"; +import { isDateTimeFormat } from "../../../helpers"; import { interactiveSort } from "../../../helpers/sort"; import { CellValueType, CriterionFilter, DataFilterValue, - SortDirection, - SpreadsheetChildEnv, filterDateCriterionOperators, filterNumberCriterionOperators, filterTextCriterionOperators, + SpreadsheetChildEnv, } from "../../../types"; import { CellPopoverComponent, PopoverBuilders } from "../../../types/cell_popovers"; import { SidePanelCollapsible } from "../../side_panel/components/collapsible/side_panel_collapsible"; diff --git a/src/components/filters/filter_menu_criterion/filter_menu_criterion.ts b/src/components/filters/filter_menu_criterion/filter_menu_criterion.ts index 9730ccfdb2..1148f6d370 100644 --- a/src/components/filters/filter_menu_criterion/filter_menu_criterion.ts +++ b/src/components/filters/filter_menu_criterion/filter_menu_criterion.ts @@ -1,7 +1,7 @@ -import { Position } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, Position } from "@odoo/o-spreadsheet-engine"; import { Component, ComponentConstructor, onWillUpdateProps, useState } from "@odoo/owl"; import { Action, createAction } from "../../../actions/action"; -import { deepCopy, deepEquals } from "../../../helpers"; +import { deepCopy } from "../../../helpers"; import { criterionComponentRegistry, getCriterionMenuItems, diff --git a/src/components/filters/filter_menu_value_list/filter_menu_value_list.ts b/src/components/filters/filter_menu_value_list/filter_menu_value_list.ts index a4206491c8..2c6eb9517c 100644 --- a/src/components/filters/filter_menu_value_list/filter_menu_value_list.ts +++ b/src/components/filters/filter_menu_value_list/filter_menu_value_list.ts @@ -1,6 +1,6 @@ -import { Position } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, Position } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef, useState } from "@odoo/owl"; -import { deepEquals, positions, toLowerCase } from "../../../helpers"; +import { positions, toLowerCase } from "../../../helpers"; import { fuzzyLookup } from "../../../helpers/search"; import { SpreadsheetChildEnv } from "../../../types"; import { FilterMenuValueItem } from "../filter_menu_item/filter_menu_value_item"; diff --git a/src/components/grid/grid.ts b/src/components/grid/grid.ts index c5b779514f..d9ba8abb1c 100644 --- a/src/components/grid/grid.ts +++ b/src/components/grid/grid.ts @@ -1,4 +1,5 @@ import { Align, HeaderIndex, Pixel } from "@odoo/o-spreadsheet-engine"; +import { Dimension, Direction, Ref } from "@odoo/o-spreadsheet-engine/types"; import { Component, onMounted, @@ -47,11 +48,8 @@ import { ClipboardMIMEType, DOMCoordinates, DOMDimension, - Dimension, - Direction, GridClickModifiers, Rect, - Ref, SpreadsheetChildEnv, Table, } from "../../types/index"; diff --git a/src/components/grid_overlay/grid_overlay.ts b/src/components/grid_overlay/grid_overlay.ts index db42345567..0fa6c867dc 100644 --- a/src/components/grid_overlay/grid_overlay.ts +++ b/src/components/grid_overlay/grid_overlay.ts @@ -1,9 +1,10 @@ -import { HeaderIndex, Pixel, Position } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, HeaderIndex, Pixel, Position } from "@odoo/o-spreadsheet-engine"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { Component, onMounted, onWillUnmount, useExternalListener, useRef } from "@odoo/owl"; -import { deepEquals, positionToZone } from "../../helpers"; +import { positionToZone } from "../../helpers"; import { isPointInsideRect } from "../../helpers/rectangle"; import { Store, useStore } from "../../store_engine"; -import { DOMCoordinates, GridClickModifiers, Rect, Ref, SpreadsheetChildEnv } from "../../types"; +import { DOMCoordinates, GridClickModifiers, Rect, SpreadsheetChildEnv } from "../../types"; import { FiguresContainer } from "../figures/figure_container/figure_container"; import { DelayedHoveredCellStore } from "../grid/delayed_hovered_cell_store"; import { GridAddRowsFooter } from "../grid_add_rows_footer/grid_add_rows_footer"; diff --git a/src/components/header_group/header_group.ts b/src/components/header_group/header_group.ts index 920ed21f4a..19d10308da 100644 --- a/src/components/header_group/header_group.ts +++ b/src/components/header_group/header_group.ts @@ -1,4 +1,5 @@ import { HeaderGroup } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { Component } from "@odoo/owl"; import { Action } from "../../actions/action"; import { @@ -9,7 +10,7 @@ import { } from "../../constants"; import { interactiveToggleGroup } from "../../helpers/ui/toggle_group_interactive"; import { getHeaderGroupContextMenu } from "../../registries/menus/header_group_registry"; -import { DOMCoordinates, Dimension, Rect } from "../../types"; +import { DOMCoordinates, Rect } from "../../types"; import { SpreadsheetChildEnv } from "../../types/env"; import { cssPropertiesToCss } from "../helpers"; diff --git a/src/components/header_group/header_group_container.ts b/src/components/header_group/header_group_container.ts index 6866e996c6..33be52f75d 100644 --- a/src/components/header_group/header_group_container.ts +++ b/src/components/header_group/header_group_container.ts @@ -1,10 +1,11 @@ import { HeaderGroup, Pixel } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { Component, useState } from "@odoo/owl"; import { Action } from "../../actions/action"; import { GROUP_LAYER_WIDTH } from "../../constants"; import { createHeaderGroupContainerContextMenu } from "../../registries/menus/header_group_registry"; import { DOMCoordinates, SpreadsheetChildEnv } from "../../types"; -import { CSSProperties, Dimension } from "../../types/misc"; +import { CSSProperties } from "../../types/misc"; import { cssPropertiesToCss } from "../helpers"; import { MenuPopover, MenuState } from "../menu_popover/menu_popover"; import { HEADER_HEIGHT, HEADER_WIDTH } from "./../../constants"; diff --git a/src/components/headers_overlay/headers_overlay.ts b/src/components/headers_overlay/headers_overlay.ts index 458c2ffffb..960d03711f 100644 --- a/src/components/headers_overlay/headers_overlay.ts +++ b/src/components/headers_overlay/headers_overlay.ts @@ -1,8 +1,9 @@ import { HeaderDimensions, HeaderIndex, Pixel } from "@odoo/o-spreadsheet-engine"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { Component, useRef, useState } from "@odoo/owl"; import { MIN_COL_WIDTH, MIN_ROW_HEIGHT } from "../../constants"; import { Store, useStore } from "../../store_engine"; -import { CommandResult, EdgeScrollInfo, Ref, SpreadsheetChildEnv } from "../../types/index"; +import { CommandResult, EdgeScrollInfo, SpreadsheetChildEnv } from "../../types/index"; import { ContextMenuType } from "../grid/grid"; import { cssPropertiesToCss } from "../helpers/css"; import { isCtrlKey } from "../helpers/dom_helpers"; diff --git a/src/components/helpers/dom_helpers.ts b/src/components/helpers/dom_helpers.ts index 0ef84785a2..57605feab9 100644 --- a/src/components/helpers/dom_helpers.ts +++ b/src/components/helpers/dom_helpers.ts @@ -1,4 +1,4 @@ -import { Ref } from "../../types/misc"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { Rect } from "./../../types/rendering"; const macRegex = /Mac/i; diff --git a/src/components/helpers/highlight_hook.ts b/src/components/helpers/highlight_hook.ts index 2d628a6d13..fe95736105 100644 --- a/src/components/helpers/highlight_hook.ts +++ b/src/components/helpers/highlight_hook.ts @@ -1,8 +1,8 @@ +import { deepEquals } from "@odoo/o-spreadsheet-engine"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { onMounted, useEffect } from "@odoo/owl"; -import { deepEquals } from "../../helpers"; import { useLocalStore, useStoreProvider } from "../../store_engine"; import { HighlightProvider, HighlightStore } from "../../stores/highlight_store"; -import { Ref } from "../../types"; import { useHoveredElement } from "./listener_hook"; export function useHighlightsOnHover(ref: Ref, highlightProvider: HighlightProvider) { diff --git a/src/components/helpers/listener_hook.ts b/src/components/helpers/listener_hook.ts index a871ecca75..3738ab407f 100644 --- a/src/components/helpers/listener_hook.ts +++ b/src/components/helpers/listener_hook.ts @@ -1,5 +1,6 @@ import { useEffect, useState } from "@odoo/owl"; -import { Ref } from "../../types"; + +import { Ref } from "@odoo/o-spreadsheet-engine/types"; /** * Manages an event listener on a ref. Useful for hooks that want to manage diff --git a/src/components/helpers/touch_scroll_hook.ts b/src/components/helpers/touch_scroll_hook.ts index 7598f8df51..80d7cbcc6f 100644 --- a/src/components/helpers/touch_scroll_hook.ts +++ b/src/components/helpers/touch_scroll_hook.ts @@ -1,4 +1,4 @@ -import { Ref } from "../../types"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { useRefListener } from "./listener_hook"; const friction = 0.95; diff --git a/src/components/icons/icons.ts b/src/components/icons/icons.ts index 41681dfad1..bf18cefd7f 100644 --- a/src/components/icons/icons.ts +++ b/src/components/icons/icons.ts @@ -1,13 +1,3 @@ -import { Style } from "@odoo/o-spreadsheet-engine"; -import { - ACTION_COLOR, - FILTERS_COLOR, - GRAY_200, - GRAY_300, - GRAY_900, - TEXT_BODY_MUTED, -} from "../../constants"; -import { isDefined } from "../../helpers"; import { ImageSVG } from "../../types/image"; export type IconSetType = keyof typeof ICON_SETS; diff --git a/src/components/link/link_display/link_display.ts b/src/components/link/link_display/link_display.ts index 8d9b8119f3..2dd5cc01b0 100644 --- a/src/components/link/link_display/link_display.ts +++ b/src/components/link/link_display/link_display.ts @@ -1,10 +1,11 @@ import { Position } from "@odoo/o-spreadsheet-engine"; +import { Link } from "@odoo/o-spreadsheet-engine/types"; import { Component } from "@odoo/owl"; import { LINK_COLOR } from "../../../constants"; import { toXC } from "../../../helpers"; import { openLink, urlRepresentation } from "../../../helpers/links"; import { Store, useStore } from "../../../store_engine"; -import { EvaluatedCell, Link, SpreadsheetChildEnv } from "../../../types"; +import { EvaluatedCell, SpreadsheetChildEnv } from "../../../types"; import { CellPopoverComponent, PopoverBuilders } from "../../../types/cell_popovers"; import { isMiddleClickOrCtrlClick } from "../../helpers/dom_helpers"; import { CellPopoverStore } from "../../popover/cell_popover_store"; diff --git a/src/components/link/link_editor/link_editor.ts b/src/components/link/link_editor/link_editor.ts index 1a0470e8f7..662ce30a9f 100644 --- a/src/components/link/link_editor/link_editor.ts +++ b/src/components/link/link_editor/link_editor.ts @@ -1,10 +1,11 @@ import { Position } from "@odoo/o-spreadsheet-engine"; +import { Link } from "@odoo/o-spreadsheet-engine/types"; import { Component, onMounted, useRef, useState } from "@odoo/owl"; import { markdownLink } from "../../../helpers"; import { detectLink, urlRepresentation } from "../../../helpers/links"; import { canonicalizeNumberContent } from "../../../helpers/locale"; import { linkMenuRegistry } from "../../../registries/menus/link_menu_registry"; -import { Link, Rect, SpreadsheetChildEnv } from "../../../types"; +import { Rect, SpreadsheetChildEnv } from "../../../types"; import { CellPopoverComponent, PopoverBuilders } from "../../../types/cell_popovers"; import { getRefBoundingRect } from "../../helpers/dom_helpers"; import { MenuPopover } from "../../menu_popover/menu_popover"; diff --git a/src/components/scrollbar/scrollbar.ts b/src/components/scrollbar/scrollbar.ts index 7478835c58..54df61c556 100644 --- a/src/components/scrollbar/scrollbar.ts +++ b/src/components/scrollbar/scrollbar.ts @@ -1,6 +1,7 @@ import { Pixel } from "@odoo/o-spreadsheet-engine"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { Component, onMounted, useEffect, useRef, xml } from "@odoo/owl"; -import { CSSProperties, Ref } from "../../types"; +import { CSSProperties } from "../../types"; import { cssPropertiesToCss } from "../helpers"; import { ScrollBar as ScrollBarElement, ScrollDirection } from "../scrollbar"; diff --git a/src/components/selection_input/selection_input.ts b/src/components/selection_input/selection_input.ts index 721fa7648c..7e3589fb3d 100644 --- a/src/components/selection_input/selection_input.ts +++ b/src/components/selection_input/selection_input.ts @@ -1,6 +1,6 @@ -import { Color } from "@odoo/o-spreadsheet-engine"; +import { Color, deepEquals } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useEffect, useRef, useState } from "@odoo/owl"; -import { deepEquals, range } from "../../helpers"; +import { range } from "../../helpers"; import { Store, useLocalStore } from "../../store_engine"; import { SpreadsheetChildEnv } from "../../types"; import { cssPropertiesToCss } from "../helpers/css"; diff --git a/src/components/side_panel/carousel_panel/carousel_panel.ts b/src/components/side_panel/carousel_panel/carousel_panel.ts index cf496a066c..baaa762834 100644 --- a/src/components/side_panel/carousel_panel/carousel_panel.ts +++ b/src/components/side_panel/carousel_panel/carousel_panel.ts @@ -1,8 +1,7 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, UID } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef } from "@odoo/owl"; import { ActionSpec } from "../../../actions/action"; import { DEFAULT_CAROUSEL_TITLE_STYLE } from "../../../constants"; -import { deepEquals } from "../../../helpers"; import { getCarouselItemPreview, getCarouselItemTitle } from "../../../helpers/carousel_helpers"; import { _t } from "../../../translation"; import { CarouselItem, SpreadsheetChildEnv, TitleDesign } from "../../../types"; diff --git a/src/components/side_panel/chart/building_blocks/generic_side_panel/config_panel.ts b/src/components/side_panel/chart/building_blocks/generic_side_panel/config_panel.ts index 42e7601ff2..e65e774cfb 100644 --- a/src/components/side_panel/chart/building_blocks/generic_side_panel/config_panel.ts +++ b/src/components/side_panel/chart/building_blocks/generic_side_panel/config_panel.ts @@ -1,8 +1,5 @@ -import { UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { Component, useState } from "@odoo/owl"; import { createValidRange, - isDefined, isXcRepresentation, mergeContiguousZones, numberToLetters, diff --git a/src/components/side_panel/chart/main_chart_panel/main_chart_panel.ts b/src/components/side_panel/chart/main_chart_panel/main_chart_panel.ts index bc164da655..80f16af04a 100644 --- a/src/components/side_panel/chart/main_chart_panel/main_chart_panel.ts +++ b/src/components/side_panel/chart/main_chart_panel/main_chart_panel.ts @@ -1,8 +1,9 @@ import { Pixel, UID } from "@odoo/o-spreadsheet-engine"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { Component, useEffect, useRef } from "@odoo/owl"; import { ChartSidePanel, chartSidePanelComponentRegistry } from ".."; import { Store, useLocalStore } from "../../../../store_engine"; -import { ChartDefinition, ChartType, Ref, SpreadsheetChildEnv } from "../../../../types/index"; +import { ChartDefinition, ChartType, SpreadsheetChildEnv } from "../../../../types/index"; import { Section } from "../../components/section/section"; import { ChartTypePicker } from "../chart_type_picker/chart_type_picker"; interface Props { diff --git a/src/components/side_panel/chart/main_chart_panel/main_chart_panel_store.ts b/src/components/side_panel/chart/main_chart_panel/main_chart_panel_store.ts index c492e366a7..e380daaf66 100644 --- a/src/components/side_panel/chart/main_chart_panel/main_chart_panel_store.ts +++ b/src/components/side_panel/chart/main_chart_panel/main_chart_panel_store.ts @@ -1,5 +1,4 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { deepEquals } from "../../../../helpers"; +import { deepEquals, UID } from "@odoo/o-spreadsheet-engine"; import { chartRegistry, chartSubtypeRegistry } from "../../../../registries/chart_types"; import { SpreadsheetStore } from "../../../../stores"; import { ChartCreationContext, ChartDefinition } from "../../../../types"; diff --git a/src/components/side_panel/conditional_formatting/cf_preview_list/cf_preview_list.ts b/src/components/side_panel/conditional_formatting/cf_preview_list/cf_preview_list.ts index ad6f891a8b..1615ba4be0 100644 --- a/src/components/side_panel/conditional_formatting/cf_preview_list/cf_preview_list.ts +++ b/src/components/side_panel/conditional_formatting/cf_preview_list/cf_preview_list.ts @@ -1,6 +1,5 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, UID } from "@odoo/o-spreadsheet-engine"; import { Component, onWillUpdateProps, useRef } from "@odoo/owl"; -import { deepEquals } from "../../../../helpers"; import { ConditionalFormat, SpreadsheetChildEnv } from "../../../../types"; import { getBoundingRectAsPOJO } from "../../../helpers/dom_helpers"; import { useDragAndDropListItems } from "../../../helpers/drag_and_drop_dom_items_hook"; diff --git a/src/components/side_panel/custom_currency/custom_currency.ts b/src/components/side_panel/custom_currency/custom_currency.ts index 9474a72ddf..e15a1b97db 100644 --- a/src/components/side_panel/custom_currency/custom_currency.ts +++ b/src/components/side_panel/custom_currency/custom_currency.ts @@ -1,10 +1,6 @@ +import { isDefined } from "@odoo/o-spreadsheet-engine"; import { Component, onWillStart, useState } from "@odoo/owl"; -import { - createAccountingFormat, - createCurrencyFormat, - formatValue, - isDefined, -} from "../../../helpers"; +import { createAccountingFormat, createCurrencyFormat, formatValue } from "../../../helpers"; import { currenciesRegistry } from "../../../registries/currencies_registry"; import { _t } from "../../../translation"; import { Currency, Format, SpreadsheetChildEnv } from "../../../types"; diff --git a/src/components/side_panel/find_and_replace/find_and_replace.ts b/src/components/side_panel/find_and_replace/find_and_replace.ts index 857bbcd391..5b61ffce6a 100644 --- a/src/components/side_panel/find_and_replace/find_and_replace.ts +++ b/src/components/side_panel/find_and_replace/find_and_replace.ts @@ -1,3 +1,4 @@ +import { DebouncedFunction } from "@odoo/o-spreadsheet-engine/types"; import { Component, onMounted, @@ -9,7 +10,7 @@ import { import { debounce, zoneToXc } from "../../../helpers"; import { Store, useLocalStore } from "../../../store_engine"; import { _t } from "../../../translation"; -import { DebouncedFunction, SpreadsheetChildEnv } from "../../../types/index"; +import { SpreadsheetChildEnv } from "../../../types/index"; import { keyboardEventToShortcutString } from "../../helpers/dom_helpers"; import { SelectionInput } from "../../selection_input/selection_input"; import { ValidationMessages } from "../../validation_messages/validation_messages"; diff --git a/src/components/side_panel/pivot/pivot_layout_configurator/pivot_layout_configurator.ts b/src/components/side_panel/pivot/pivot_layout_configurator/pivot_layout_configurator.ts index 709d11ee89..4e75d5b748 100644 --- a/src/components/side_panel/pivot/pivot_layout_configurator/pivot_layout_configurator.ts +++ b/src/components/side_panel/pivot/pivot_layout_configurator/pivot_layout_configurator.ts @@ -1,6 +1,4 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { Component, useRef } from "@odoo/owl"; -import { isDefined } from "../../../../helpers"; +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { AGGREGATORS, getFieldDisplayName, @@ -9,7 +7,7 @@ import { import { PivotRuntimeDefinition } from "../../../../helpers/pivot/pivot_runtime_definition"; import { Store, useStore } from "../../../../store_engine"; import { _t } from "../../../../translation"; -import { SortDirection, SpreadsheetChildEnv } from "../../../../types"; +import { SpreadsheetChildEnv } from "../../../../types"; import { Aggregator, Granularity, diff --git a/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts b/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts index ea3461cf72..216b7ad82f 100644 --- a/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts +++ b/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts @@ -1,6 +1,6 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, UID } from "@odoo/o-spreadsheet-engine"; import { PIVOT_MAX_NUMBER_OF_CELLS } from "../../../../constants"; -import { deepCopy, deepEquals } from "../../../../helpers"; +import { deepCopy } from "../../../../helpers"; import { getFirstPivotFunction } from "../../../../helpers/pivot/pivot_composer_helpers"; import { isDateOrDatetimeField } from "../../../../helpers/pivot/pivot_helpers"; import { pivotRegistry } from "../../../../helpers/pivot/pivot_registry"; diff --git a/src/components/side_panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.ts b/src/components/side_panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.ts index b3ba03f101..eee0cf0df4 100644 --- a/src/components/side_panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.ts +++ b/src/components/side_panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.ts @@ -1,9 +1,10 @@ import { UID } from "@odoo/o-spreadsheet-engine"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { Component, useRef, useState } from "@odoo/owl"; import { SpreadsheetPivotRuntimeDefinition } from "../../../../../helpers/pivot/spreadsheet_pivot/runtime_definition_spreadsheet_pivot"; import { SpreadsheetPivot } from "../../../../../helpers/pivot/spreadsheet_pivot/spreadsheet_pivot"; import { Store, useLocalStore } from "../../../../../store_engine"; -import { Ref, SpreadsheetChildEnv } from "../../../../../types"; +import { SpreadsheetChildEnv } from "../../../../../types"; import { SpreadsheetPivotCoreDefinition } from "../../../../../types/pivot"; import { SelectionInput } from "../../../../selection_input/selection_input"; import { Checkbox } from "../../../components/checkbox/checkbox"; diff --git a/src/components/side_panel/settings/settings_panel.ts b/src/components/side_panel/settings/settings_panel.ts index bbda1469dd..9e5297f4a1 100644 --- a/src/components/side_panel/settings/settings_panel.ts +++ b/src/components/side_panel/settings/settings_panel.ts @@ -1,5 +1,6 @@ +import { deepEquals } from "@odoo/o-spreadsheet-engine"; import { Component, onWillStart } from "@odoo/owl"; -import { DAYS, deepEquals, formatValue } from "../../../helpers"; +import { DAYS, formatValue } from "../../../helpers"; import { getDateTimeFormat, isValidLocale } from "../../../helpers/locale"; import { Locale, LocaleCode, SpreadsheetChildEnv } from "../../../types"; import { ValidationMessages } from "../../validation_messages/validation_messages"; diff --git a/src/components/tables/table_style_preview/table_style_preview.ts b/src/components/tables/table_style_preview/table_style_preview.ts index d329833452..dfedbea9a4 100644 --- a/src/components/tables/table_style_preview/table_style_preview.ts +++ b/src/components/tables/table_style_preview/table_style_preview.ts @@ -1,5 +1,5 @@ +import { deepEquals } from "@odoo/o-spreadsheet-engine"; import { Component, onMounted, onWillUpdateProps, useRef, useState } from "@odoo/owl"; -import { deepEquals } from "../../../helpers"; import { getComputedTableStyle } from "../../../helpers/table_helpers"; import { createTableStyleContextMenuActions } from "../../../registries/menus/table_style_menu_registry"; import { SpreadsheetChildEnv } from "../../../types"; diff --git a/src/components/text_input/text_input.ts b/src/components/text_input/text_input.ts index 86b41340af..c579c05c14 100644 --- a/src/components/text_input/text_input.ts +++ b/src/components/text_input/text_input.ts @@ -1,7 +1,7 @@ +import { isDefined } from "@odoo/o-spreadsheet-engine"; +import { Ref } from "@odoo/o-spreadsheet-engine/types"; import { Component, useExternalListener, useRef } from "@odoo/owl"; import { SpreadsheetChildEnv } from "../.."; -import { isDefined } from "../../helpers"; -import { Ref } from "../../types"; import { useAutofocus } from "../helpers/autofocus_hook"; interface Props { diff --git a/src/functions/module_date.ts b/src/functions/module_date.ts index 462dd5d470..f1507eb251 100644 --- a/src/functions/module_date.ts +++ b/src/functions/module_date.ts @@ -1,4 +1,5 @@ import { Arg, FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; +import { FunctionResultNumber } from "@odoo/o-spreadsheet-engine/types"; import { addMonthsToDate, areTwoDatesWithinOneYear, @@ -16,7 +17,6 @@ import { } from "../helpers/dates"; import { getDateTimeFormat } from "../helpers/locale"; import { _t } from "../translation"; -import { FunctionResultNumber } from "../types"; import { EvaluationError } from "../types/errors"; import { arg } from "./arguments"; import { assert } from "./helper_assert"; diff --git a/src/helpers/color.ts b/src/helpers/color.ts index 1f48957e20..8bd8054198 100644 --- a/src/helpers/color.ts +++ b/src/helpers/color.ts @@ -1,8 +1,4 @@ -import { HSLA, RGBA } from "../types"; - import { Color } from "@odoo/o-spreadsheet-engine"; -import { concat } from "./misc"; - const RBA_REGEX = /rgba?\(|\s+|\)/gi; const HEX_MATCH = /^#([A-F\d]{2}){3,4}$/; diff --git a/src/helpers/data_normalization.ts b/src/helpers/data_normalization.ts index 2303d0801a..9d36e1dd9a 100644 --- a/src/helpers/data_normalization.ts +++ b/src/helpers/data_normalization.ts @@ -1,5 +1,6 @@ import { Position, UID } from "@odoo/o-spreadsheet-engine"; -import { recomputeZones } from "./recompute_zones"; +import { recomputeZones } from "@odoo/o-spreadsheet-engine/helpers/recompute_zones"; +import { positionToZone, toZone, zoneToXc } from "@odoo/o-spreadsheet-engine/helpers/zones"; type ReverseLookup = Map; type ItemsDic = { [id: number]: T }; diff --git a/src/helpers/figures/charts/chart_common.ts b/src/helpers/figures/charts/chart_common.ts index 23754c4022..131dc15479 100644 --- a/src/helpers/figures/charts/chart_common.ts +++ b/src/helpers/figures/charts/chart_common.ts @@ -1,12 +1,3 @@ -import { - ApplyRangeChange, - Color, - RangeAdapter, - UID, - UnboundedZone, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { DEFAULT_WINDOW_SIZE, MAX_CHAR_LABEL } from "../../../constants"; import { _t } from "../../../translation"; import { CommandResult, @@ -33,7 +24,7 @@ import { MAX_XLSX_POLYNOMIAL_DEGREE } from "../../../xlsx/constants"; import { ColorGenerator, relativeLuminance } from "../../color"; import { formatValue, humanizeNumber } from "../../format/format"; import { adaptStringRange } from "../../formulas"; -import { isDefined, largeMax } from "../../misc"; +import { largeMax } from "../../misc"; import { createRange, duplicateRangeInDuplicatedSheet } from "../../range"; import { rangeReference } from "../../references"; import { getZoneArea, isFullRow, toUnboundedZone, zoneToDimension, zoneToXc } from "../../zones"; diff --git a/src/helpers/figures/charts/gauge_chart.ts b/src/helpers/figures/charts/gauge_chart.ts index aa21b96a39..5707366fb7 100644 --- a/src/helpers/figures/charts/gauge_chart.ts +++ b/src/helpers/figures/charts/gauge_chart.ts @@ -1,3 +1,4 @@ +import { Validation } from "@odoo/o-spreadsheet-engine/types"; import { DEFAULT_GAUGE_LOWER_COLOR, DEFAULT_GAUGE_MIDDLE_COLOR, @@ -5,15 +6,7 @@ import { } from "../../../constants"; import { isMultipleElementMatrix, toScalar } from "../../../functions/helper_matrices"; import { tryToNumber } from "../../../functions/helpers"; -import { - CellValueType, - CommandResult, - CoreGetters, - Format, - Getters, - Range, - Validation, -} from "../../../types"; +import { CellValueType, CommandResult, CoreGetters, Format, Getters, Range } from "../../../types"; import { ChartCreationContext } from "../../../types/chart/chart"; import { GaugeChartDefinition, diff --git a/src/helpers/figures/charts/runtime/chartjs_dataset.ts b/src/helpers/figures/charts/runtime/chartjs_dataset.ts index aa44d119cb..49a6da51c0 100644 --- a/src/helpers/figures/charts/runtime/chartjs_dataset.ts +++ b/src/helpers/figures/charts/runtime/chartjs_dataset.ts @@ -1,5 +1,3 @@ -import { Color } from "@odoo/o-spreadsheet-engine"; -import { ChartDataset, Point } from "chart.js"; import { BACKGROUND_CHART_COLOR, CHART_WATERFALL_NEGATIVE_COLOR, @@ -52,7 +50,7 @@ import { setColorAlpha, } from "../../../color"; import { formatValue } from "../../../format/format"; -import { isDefined, range } from "../../../misc"; +import { range } from "../../../misc"; import { MOVING_AVERAGE_TREND_LINE_XAXIS_ID, TREND_LINE_XAXIS_ID, diff --git a/src/helpers/figures/charts/runtime/chartjs_scales.ts b/src/helpers/figures/charts/runtime/chartjs_scales.ts index 71d32eb54b..2b03cbcb52 100644 --- a/src/helpers/figures/charts/runtime/chartjs_scales.ts +++ b/src/helpers/figures/charts/runtime/chartjs_scales.ts @@ -1,3 +1,4 @@ +import { isDefined } from "@odoo/o-spreadsheet-engine"; import { LinearScaleOptions, ScaleChartOptions, Tick } from "chart.js"; import { DeepPartial } from "chart.js/dist/types/utils"; import { @@ -30,7 +31,7 @@ import { RadarChartDefinition } from "../../../../types/chart/radar_chart"; import { getChartTimeOptions } from "../../../chart_date"; import { getColorScale } from "../../../color"; import { formatValue, humanizeNumber } from "../../../format/format"; -import { isDefined, range, removeFalsyAttributes } from "../../../misc"; +import { range, removeFalsyAttributes } from "../../../misc"; import { MOVING_AVERAGE_TREND_LINE_XAXIS_ID, TREND_LINE_XAXIS_ID, diff --git a/src/helpers/format/format_parser.ts b/src/helpers/format/format_parser.ts index 579fb4afbb..ea8aaa422a 100644 --- a/src/helpers/format/format_parser.ts +++ b/src/helpers/format/format_parser.ts @@ -1,5 +1,5 @@ +import { isDefined } from "@odoo/o-spreadsheet-engine"; import { Format } from "../../types"; -import { isDefined } from "../misc"; import { CharToken, DatePartToken, diff --git a/src/helpers/internal_viewport.ts b/src/helpers/internal_viewport.ts index babdbcbdd8..7fa94f7330 100644 --- a/src/helpers/internal_viewport.ts +++ b/src/helpers/internal_viewport.ts @@ -1,6 +1,7 @@ import { HeaderIndex, Pixel, Position, UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { FOOTER_HEIGHT } from "../constants"; -import { DOMCoordinates, DOMDimension, Dimension, Getters, Rect } from "../types"; +import { DOMCoordinates, DOMDimension, Getters, Rect } from "../types"; import { intersection, isInside } from "./zones"; export class InternalViewport { diff --git a/src/helpers/links.ts b/src/helpers/links.ts index e501c138cb..2785710b64 100644 --- a/src/helpers/links.ts +++ b/src/helpers/links.ts @@ -1,6 +1,7 @@ +import { Link } from "@odoo/o-spreadsheet-engine/types"; import { Registry } from "../registries/registry"; import { _t } from "../translation"; -import { CellValue, CommandResult, Getters, Link, SpreadsheetChildEnv } from "../types"; +import { CellValue, CommandResult, Getters, SpreadsheetChildEnv } from "../types"; import { isMarkdownLink, isSheetUrl, isWebLink, parseMarkdownLink, parseSheetUrl } from "./misc"; /** diff --git a/src/helpers/misc.ts b/src/helpers/misc.ts index d6aa37edf3..351dd9e531 100644 --- a/src/helpers/misc.ts +++ b/src/helpers/misc.ts @@ -3,8 +3,7 @@ //------------------------------------------------------------------------------ import { ConsecutiveIndexes, Style, UID } from "@odoo/o-spreadsheet-engine"; import { escapeRegExp as engineEscapeRegExp } from "@odoo/o-spreadsheet-engine/helpers/misc"; -import { FORBIDDEN_SHEETNAME_CHARS_IN_EXCEL_REGEX } from "../constants"; -import { ChartStyle, Lazy } from "../types"; +import { Cloneable, DebouncedFunction, Lazy } from "@odoo/o-spreadsheet-engine/types"; export { escapeRegExp, getCanonicalSymbolName, @@ -209,14 +208,6 @@ export function parseSheetUrl(sheetLink: string) { throw new Error(`${sheetLink} is not a valid sheet link`); } -/** - * This helper function can be used as a type guard when filtering arrays. - * const foo: number[] = [1, 2, undefined, 4].filter(isDefined) - */ -export function isDefined(argument: T | undefined): argument is T { - return argument !== undefined; -} - export function isNotNull(argument: T | null): argument is T { return argument !== null; } @@ -342,60 +333,6 @@ export function getAddHeaderStartIndex(position: "before" | "after", base: numbe return position === "after" ? base + 1 : base; } -/** - * Compares n objects. - */ - -export function deepEquals(...o: any[]): boolean { - if (o.length <= 1) return true; - for (let index = 1; index < o.length; index++) { - if (!_deepEquals(o[0], o[index])) return false; - } - return true; -} - -function _deepEquals(o1: any, o2: any): boolean { - if (o1 === o2) return true; - if ((o1 && !o2) || (o2 && !o1)) return false; - if (typeof o1 !== typeof o2) return false; - if (typeof o1 !== "object") return false; - - // Objects can have different keys if the values are undefined - for (const key in o2) { - if (!(key in o1) && o2[key] !== undefined) { - return false; - } - } - - for (const key in o1) { - if (typeof o1[key] !== typeof o2[key]) return false; - if (typeof o1[key] === "object") { - if (!_deepEquals(o1[key], o2[key])) return false; - } else { - if (o1[key] !== o2[key]) return false; - } - } - - return true; -} - -/** - * Compares two arrays. - * For performance reasons, this function is to be preferred - * to 'deepEquals' in the case we know that the inputs are arrays. - */ -export function deepEqualsArray(arr1: unknown[], arr2: unknown[]): boolean { - if (arr1.length !== arr2.length) { - return false; - } - for (let i = 0; i < arr1.length; i++) { - if (!deepEquals(arr1[i], arr2[i])) { - return false; - } - } - return true; -} - /** * Check if the given array contains all the values of the other array. * It makes the assumption that both array do not contain duplicates. diff --git a/src/helpers/pivot/pivot_domain_helpers.ts b/src/helpers/pivot/pivot_domain_helpers.ts index 931a34a3ce..770de77b3a 100644 --- a/src/helpers/pivot/pivot_domain_helpers.ts +++ b/src/helpers/pivot/pivot_domain_helpers.ts @@ -1,3 +1,4 @@ +import { deepEquals } from "@odoo/o-spreadsheet-engine"; import { CellValue, DimensionTree, @@ -6,7 +7,7 @@ import { PivotDomain, PivotNode, } from "../../types"; -import { clip, deepCopy, deepEquals } from "../misc"; +import { clip, deepCopy } from "../misc"; export const PREVIOUS_VALUE = "(previous)"; export const NEXT_VALUE = "(next)"; diff --git a/src/helpers/pivot/pivot_helpers.ts b/src/helpers/pivot/pivot_helpers.ts index d4c34a59ba..070e876bfc 100644 --- a/src/helpers/pivot/pivot_helpers.ts +++ b/src/helpers/pivot/pivot_helpers.ts @@ -1,5 +1,3 @@ -import { FunctionResultObject, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; -import { boolAnd, boolOr } from "../../functions/helper_logical"; import { countUnique, sum } from "../../functions/helper_math"; import { average, countAny, max, min } from "../../functions/helper_statistical"; import { @@ -26,7 +24,7 @@ import { PivotSortedColumn, PivotTableCell, } from "../../types/pivot"; -import { getUniqueText, isDefined } from "../misc"; +import { getUniqueText } from "../misc"; import { PivotRuntimeDefinition } from "./pivot_runtime_definition"; const AGGREGATOR_NAMES = { count: _t("Count"), diff --git a/src/helpers/pivot/pivot_menu_items.ts b/src/helpers/pivot/pivot_menu_items.ts index 1e9ba08219..b2ae8bf192 100644 --- a/src/helpers/pivot/pivot_menu_items.ts +++ b/src/helpers/pivot/pivot_menu_items.ts @@ -1,4 +1,5 @@ import { CellPosition } from "@odoo/o-spreadsheet-engine"; +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { CellValue, Getters, @@ -8,7 +9,6 @@ import { PivotField, PivotFields, PivotHeaderCell, - SortDirection, SpreadsheetChildEnv, } from "../.."; import { ActionSpec } from "../../actions/action"; diff --git a/src/helpers/pivot/pivot_presentation.ts b/src/helpers/pivot/pivot_presentation.ts index ce6dc00582..2d909b05e3 100644 --- a/src/helpers/pivot/pivot_presentation.ts +++ b/src/helpers/pivot/pivot_presentation.ts @@ -1,4 +1,10 @@ -import { FunctionResultObject, handleError, isMatrix } from "@odoo/o-spreadsheet-engine"; +import { + deepEquals, + FunctionResultObject, + handleError, + isMatrix, +} from "@odoo/o-spreadsheet-engine"; +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { transposeMatrix } from "../../functions/helpers"; import { ModelConfig } from "../../model"; import { _t } from "../../translation"; @@ -10,13 +16,10 @@ import { PivotMeasure, PivotMeasureDisplay, PivotValueCell, - SortDirection, } from "../../types"; import { CellErrorType, NotAvailableError } from "../../types/errors"; -import { deepEquals, removeDuplicates, transpose2dPOJO } from "../misc"; +import { removeDuplicates, transpose2dPOJO } from "../misc"; import { - NEXT_VALUE, - PREVIOUS_VALUE, domainToColRowDomain, domainToString, getDimensionDomain, @@ -29,6 +32,8 @@ import { getRunningTotalDomainKey, isDomainIsInPivot, isFieldInDomain, + NEXT_VALUE, + PREVIOUS_VALUE, replaceFieldValueInDomain, } from "./pivot_domain_helpers"; import { AGGREGATORS_FN, isSortedColumnValid, toNormalizedPivotValue } from "./pivot_helpers"; diff --git a/src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts b/src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts index 62324b0ee3..79b05558df 100644 --- a/src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts +++ b/src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts @@ -1,8 +1,7 @@ -import { FunctionResultObject, handleError, Maybe, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { toString } from "../../../functions/helpers"; +import { ValueAndLabel } from "@odoo/o-spreadsheet-engine/types"; import { ModelConfig } from "../../../model"; import { _t } from "../../../translation"; -import { CellValueType, EvaluatedCell, Getters, Range, ValueAndLabel } from "../../../types"; +import { CellValueType, EvaluatedCell, Getters, Range } from "../../../types"; import { CellErrorType, EvaluationError } from "../../../types/errors"; import { Granularity, @@ -17,7 +16,6 @@ import { import { InitPivotParams, Pivot } from "../../../types/pivot_runtime"; import { toXC } from "../../coordinates"; import { formatValue, isDateTimeFormat } from "../../format/format"; -import { deepEquals, isDefined } from "../../misc"; import { AGGREGATORS_FN, areDomainArgsFieldsValid, diff --git a/src/helpers/pivot/table_spreadsheet_pivot.ts b/src/helpers/pivot/table_spreadsheet_pivot.ts index 0552189272..6e9145469a 100644 --- a/src/helpers/pivot/table_spreadsheet_pivot.ts +++ b/src/helpers/pivot/table_spreadsheet_pivot.ts @@ -1,5 +1,5 @@ -import { FunctionResultObject } from "@odoo/o-spreadsheet-engine"; -import { Lazy } from "../../types"; +import { deepEquals, FunctionResultObject } from "@odoo/o-spreadsheet-engine"; +import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { DimensionTree, DimensionTreeNode, @@ -11,7 +11,7 @@ import { PivotTableRow, PivotVisibilityOptions, } from "../../types/pivot"; -import { deepEquals, lazy } from "../misc"; +import { lazy } from "../misc"; import { isParentDomain, sortPivotTree } from "./pivot_domain_helpers"; import { parseDimension, toNormalizedPivotValue } from "./pivot_helpers"; diff --git a/src/helpers/sort.ts b/src/helpers/sort.ts index 9322cb15ce..7bfaa127e9 100644 --- a/src/helpers/sort.ts +++ b/src/helpers/sort.ts @@ -1,68 +1,9 @@ import { Position, UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { SortDirection, SortOptions } from "@odoo/o-spreadsheet-engine/types"; import { _t } from "../translation"; -import { - CellValue, - CellValueType, - CommandResult, - EvaluatedCell, - SortDirection, - SortOptions, - SpreadsheetChildEnv, -} from "../types"; +import { SpreadsheetChildEnv } from "../types"; import { isEqual } from "./zones"; -type CellWithIndex = { index: number; type: CellValueType; value: any }; - -const SORT_TYPES: CellValueType[] = [ - CellValueType.number, - CellValueType.error, - CellValueType.text, - CellValueType.boolean, -]; - -export function cellsSortingCriterion(sortingOrder: string) { - const inverse = sortingOrder === "asc" ? 1 : -1; - return ( - left: { type: CellValueType; value: CellValue }, - right: { type: CellValueType; value: CellValue } - ) => { - if (left.type === CellValueType.empty) { - return right.type === CellValueType.empty ? 0 : 1; - } else if (right.type === CellValueType.empty) { - return -1; - } - let typeOrder = SORT_TYPES.indexOf(left.type) - SORT_TYPES.indexOf(right.type); - if (typeOrder === 0) { - if (left.type === CellValueType.text || left.type === CellValueType.error) { - typeOrder = (left.value as string).localeCompare(right.value as string); - } else { - typeOrder = (left.value as number) - (right.value as number); - } - } - return inverse * typeOrder; - }; -} - -export function sortCells( - cells: EvaluatedCell[], - sortDirection: SortDirection, - emptyCellAsZero: boolean -): CellWithIndex[] { - const cellsWithIndex: CellWithIndex[] = cells.map((cell, index) => ({ - index, - type: cell.type, - value: cell.value, - })); - - const cellsToSort = emptyCellAsZero - ? cellsWithIndex.map((cell) => - cell.type === CellValueType.empty ? { ...cell, type: CellValueType.number, value: 0 } : cell - ) - : cellsWithIndex; - - return cellsToSort.sort(cellsSortingCriterion(sortDirection)); -} - export function interactiveSortSelection( env: SpreadsheetChildEnv, sheetId: UID, diff --git a/src/helpers/ui/freeze_interactive.ts b/src/helpers/ui/freeze_interactive.ts index 234fec569f..b69f75a364 100644 --- a/src/helpers/ui/freeze_interactive.ts +++ b/src/helpers/ui/freeze_interactive.ts @@ -1,6 +1,7 @@ import { HeaderIndex } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { MergeErrorMessage } from "../../components/translations_terms"; -import { CommandResult, Dimension, SpreadsheetChildEnv } from "../../types"; +import { CommandResult, SpreadsheetChildEnv } from "../../types"; export function interactiveFreezeColumnsRows( env: SpreadsheetChildEnv, diff --git a/src/history/operation.ts b/src/history/operation.ts index 1e241f582b..5e7fc306bd 100644 --- a/src/history/operation.ts +++ b/src/history/operation.ts @@ -1,6 +1,7 @@ import { UID } from "@odoo/o-spreadsheet-engine"; +import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { lazy } from "../helpers"; -import { Lazy, Transformation } from "../types"; +import { Transformation } from "../types"; /** * An Operation can be executed to change a data structure from state A diff --git a/src/index.ts b/src/index.ts index 08c85e58e5..ea3adcdf53 100644 --- a/src/index.ts +++ b/src/index.ts @@ -73,12 +73,10 @@ import { computeTextWidth, createCurrencyFormat, deepCopy, - deepEquals, expandZoneOnInsertion, formatValue, getUniqueText, isDateTime, - isDefined, isInside, isMarkdownLink, isNumber, @@ -111,9 +109,8 @@ import { } from "./helpers/pivot/pivot_composer_helpers"; import { supportedPivotPositionalFormulaRegistry } from "./helpers/pivot/pivot_positional_formula_registry"; -import { isMatrix } from "@odoo/o-spreadsheet-engine"; -import { ClickableCellSortIcon } from "./components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon"; -import { chartJsExtensionRegistry } from "./components/figures/chart/chartJs/chart_js_extension"; +import { deepEquals, isDefined, isMatrix } from "@odoo/o-spreadsheet-engine"; + import { ZoomableChartJsComponent } from "./components/figures/chart/chartJs/zoomable_chart/zoomable_chartjs"; import { ChartDashboardMenu } from "./components/figures/chart/chart_dashboard_menu/chart_dashboard_menu"; import { FullScreenChart } from "./components/full_screen_chart/full_screen_chart"; diff --git a/src/plugins/core/borders.ts b/src/plugins/core/borders.ts index 395ab9f3ae..ae8ac333c4 100644 --- a/src/plugins/core/borders.ts +++ b/src/plugins/core/borders.ts @@ -5,6 +5,7 @@ import { BorderDescr, CellPosition, Color, + deepEquals, HeaderIndex, UID, UnboundedZone, @@ -13,7 +14,6 @@ import { import { PositionMap } from "../../helpers/cells/position_map"; import { deepCopy, - deepEquals, getItemId, intersection, positionToZone, diff --git a/src/plugins/core/cell.ts b/src/plugins/core/cell.ts index abb48dbfaa..9e473b0703 100644 --- a/src/plugins/core/cell.ts +++ b/src/plugins/core/cell.ts @@ -3,6 +3,7 @@ import { ApplyRangeChange, CellPosition, CompiledFormula, + deepEquals, HeaderIndex, RangeCompiledFormula, Style, @@ -11,10 +12,10 @@ import { Zone, } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_STYLE } from "../../constants"; -import { Token, compile } from "../../formulas"; +import { compile, Token } from "../../formulas"; import { compileTokens } from "../../formulas/compiler"; import { isEvaluationError, toString } from "../../functions/helpers"; -import { deepEquals, isExcelCompatible, isTextFormat, recomputeZones } from "../../helpers"; +import { isExcelCompatible, isTextFormat, recomputeZones } from "../../helpers"; import { parseLiteral } from "../../helpers/cells"; import { PositionMap } from "../../helpers/cells/position_map"; import { diff --git a/src/plugins/core/chart.ts b/src/plugins/core/chart.ts index 054b635e75..1f5d7940f9 100644 --- a/src/plugins/core/chart.ts +++ b/src/plugins/core/chart.ts @@ -1,12 +1,12 @@ import { AdaptSheetName, ApplyRangeChange, + deepEquals, HeaderIndex, PixelPosition, UID, } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_FIGURE_HEIGHT, DEFAULT_FIGURE_WIDTH, FIGURE_ID_SPLITTER } from "../../constants"; -import { deepEquals } from "../../helpers"; import { AbstractChart } from "../../helpers/figures/charts/abstract_chart"; import { chartFactory, validateChartDefinition } from "../../helpers/figures/charts/chart_factory"; import { ChartCreationContext, ChartDefinition, ChartType } from "../../types/chart/chart"; diff --git a/src/plugins/core/conditional_format.ts b/src/plugins/core/conditional_format.ts index abac001716..18e9bd5e98 100644 --- a/src/plugins/core/conditional_format.ts +++ b/src/plugins/core/conditional_format.ts @@ -1,6 +1,7 @@ -import { ApplyRangeChange, UID, UnboundedZone, Zone } from "@odoo/o-spreadsheet-engine"; +import { ApplyRangeChange, deepEquals, UID, UnboundedZone, Zone } from "@odoo/o-spreadsheet-engine"; +import { Validation } from "@odoo/o-spreadsheet-engine/types"; import { compile } from "../../formulas/compiler"; -import { deepEquals, isInside, recomputeZones, toUnboundedZone } from "../../helpers/index"; +import { isInside, recomputeZones, toUnboundedZone } from "../../helpers/index"; import { criterionEvaluatorRegistry } from "../../registries/criterion_registry"; import { AddConditionalFormatCommand, @@ -18,7 +19,6 @@ import { IconSetRule, IconThreshold, RangeData, - Validation, WorkbookData, } from "../../types"; import { CorePlugin } from "../core_plugin"; diff --git a/src/plugins/core/header_grouping.ts b/src/plugins/core/header_grouping.ts index de1872300c..6ebe8a1b2b 100644 --- a/src/plugins/core/header_grouping.ts +++ b/src/plugins/core/header_grouping.ts @@ -9,7 +9,8 @@ import { } from "../../helpers"; import { CommandResult, CoreCommand, ExcelWorkbookData, WorkbookData } from "../../types"; import { getSheetDataHeader } from "../../xlsx/helpers/misc"; -import { Dimension } from "./../../types/misc"; + +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; interface State { groups: Record>; diff --git a/src/plugins/core/header_size.ts b/src/plugins/core/header_size.ts index ec3379d6a0..d767a019ed 100644 --- a/src/plugins/core/header_size.ts +++ b/src/plugins/core/header_size.ts @@ -2,7 +2,8 @@ import { HeaderIndex, Pixel, UID } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../constants"; import { deepCopy, getAddHeaderStartIndex, range, removeIndexesFromArray } from "../../helpers"; import { Command, ExcelWorkbookData, WorkbookData } from "../../types"; -import { Dimension } from "../../types/misc"; + +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; interface HeaderSizeState { sizes: Record>>; diff --git a/src/plugins/core/header_visibility.ts b/src/plugins/core/header_visibility.ts index 55a15240bd..140e6e4cef 100644 --- a/src/plugins/core/header_visibility.ts +++ b/src/plugins/core/header_visibility.ts @@ -1,4 +1,5 @@ import { ConsecutiveIndexes, HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { deepCopy, getAddHeaderStartIndex, @@ -8,7 +9,6 @@ import { range, } from "../../helpers"; import { Command, CommandResult, ExcelWorkbookData, WorkbookData } from "../../types"; -import { Dimension } from "../../types/misc"; import { CorePlugin } from "../core_plugin"; export class HeaderVisibilityPlugin extends CorePlugin { diff --git a/src/plugins/core/image.ts b/src/plugins/core/image.ts index 447b5147c8..a59d6724a1 100644 --- a/src/plugins/core/image.ts +++ b/src/plugins/core/image.ts @@ -1,6 +1,4 @@ -import { HeaderIndex, PixelPosition, UID } from "@odoo/o-spreadsheet-engine"; -import { FIGURE_ID_SPLITTER } from "../../constants"; -import { deepCopy, isDefined } from "../../helpers"; +import { deepCopy } from "../../helpers"; import { FileStore } from "../../types/files"; import { Image } from "../../types/image"; import { diff --git a/src/plugins/core/merge.ts b/src/plugins/core/merge.ts index 16f4dc310e..ebb3edc562 100644 --- a/src/plugins/core/merge.ts +++ b/src/plugins/core/merge.ts @@ -1,30 +1,3 @@ -import { - ApplyRangeChange, - CellPosition, - HeaderIndex, - Merge, - UID, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { - clip, - createRange, - deepEquals, - doesAnyZoneCrossFrozenPane, - getFullReference, - isDefined, - isEqual, - isFullColRange, - isFullRowRange, - overlap, - positions, - splitReference, - toXC, - toZone, - union, - zoneToDimension, - zoneToXc, -} from "../../helpers/index"; import { AddMergeCommand, CommandResult, diff --git a/src/plugins/core/pivot.ts b/src/plugins/core/pivot.ts index 28b7463ddf..605aea2cc8 100644 --- a/src/plugins/core/pivot.ts +++ b/src/plugins/core/pivot.ts @@ -1,12 +1,13 @@ import { ApplyRangeChange, CellPosition, + deepEquals, Position, RangeCompiledFormula, UID, } from "@odoo/o-spreadsheet-engine"; import { compile } from "../../formulas"; -import { deepCopy, deepEquals } from "../../helpers"; +import { deepCopy } from "../../helpers"; import { createPivotFormula, getMaxObjectId } from "../../helpers/pivot/pivot_helpers"; import { SpreadsheetPivotTable } from "../../helpers/pivot/table_spreadsheet_pivot"; import { CellValue, CommandResult, CoreCommand, Range, WorkbookData } from "../../types"; diff --git a/src/plugins/core/range.ts b/src/plugins/core/range.ts index 00797aaaa9..d6a65bcf16 100644 --- a/src/plugins/core/range.ts +++ b/src/plugins/core/range.ts @@ -7,6 +7,7 @@ import { UnboundedZone, Zone, } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { compile } from "../../formulas"; import { createInvalidRange, @@ -31,7 +32,6 @@ import { CommandResult, CoreCommand, CoreGetters, - Dimension, Range, RangeData, RangeStringOptions, diff --git a/src/plugins/core/sheet.ts b/src/plugins/core/sheet.ts index 0af06edcf7..515441175e 100644 --- a/src/plugins/core/sheet.ts +++ b/src/plugins/core/sheet.ts @@ -1,15 +1,4 @@ -import { - CellPosition, - HeaderIndex, - PaneDivision, - Row, - Sheet, - UID, - UnboundedZone, - Zone, - ZoneDimension, -} from "@odoo/o-spreadsheet-engine"; -import { FORBIDDEN_SHEETNAME_CHARS_IN_EXCEL_REGEX } from "../../constants"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { createDefaultRows, deepCopy, @@ -19,7 +8,6 @@ import { groupConsecutive, includesAll, isColorValid, - isDefined, isZoneInside, isZoneValid, largeMax, @@ -34,7 +22,6 @@ import { CommandResult, CoreCommand, CreateSheetCommand, - Dimension, ExcelWorkbookData, FreezeColumnsCommand, FreezeRowsCommand, diff --git a/src/plugins/core/tables.ts b/src/plugins/core/tables.ts index 6e789c1df6..88207c3b1f 100644 --- a/src/plugins/core/tables.ts +++ b/src/plugins/core/tables.ts @@ -1,9 +1,7 @@ import { areZonesContinuous, deepCopy, - deepEquals, intersection, - isDefined, isInside, isZoneInside, overlap, @@ -33,8 +31,7 @@ import { WorkbookData, } from "../../types/index"; -import { ApplyRangeChange, CellPosition, TableId, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { CorePlugin } from "../core_plugin"; +import { TableId, UID } from "@odoo/o-spreadsheet-engine"; interface TableState { tables: Record>; diff --git a/src/plugins/ui_core_views/cell_icon_plugin.ts b/src/plugins/ui_core_views/cell_icon_plugin.ts index 62116cb870..414c1be196 100644 --- a/src/plugins/ui_core_views/cell_icon_plugin.ts +++ b/src/plugins/ui_core_views/cell_icon_plugin.ts @@ -1,10 +1,3 @@ -import { Align, CellPosition } from "@odoo/o-spreadsheet-engine"; -import { isDefined } from "../../helpers/index"; -import { - GridIcon, - IconsOfCell, - iconsOnCellRegistry, -} from "../../registries/icons_on_cell_registry"; import { Command, Rect } from "../../types"; import { CoreViewPlugin } from "../core_view_plugin"; diff --git a/src/plugins/ui_core_views/custom_colors.ts b/src/plugins/ui_core_views/custom_colors.ts index 30508d46e1..b4b4875a82 100644 --- a/src/plugins/ui_core_views/custom_colors.ts +++ b/src/plugins/ui_core_views/custom_colors.ts @@ -1,16 +1,4 @@ -import { Color, UID } from "@odoo/o-spreadsheet-engine"; -import { COLOR_PICKER_DEFAULTS } from "../../constants"; -import { - colorNumberToHex, - colorToRGBA, - isColorValid, - isDefined, - rgba, - rgbaToHex, - rgbaToHSLA, - toHex, -} from "../../helpers"; -import { Command, Immutable, RGBA, TableElementStyle } from "../../types"; +import { Immutable, RGBA } from "@odoo/o-spreadsheet-engine/types"; const chartColorRegex = /"(#[0-9a-fA-F]{6})"/g; /** diff --git a/src/plugins/ui_core_views/dynamic_tables.ts b/src/plugins/ui_core_views/dynamic_tables.ts index ba7d80ae46..0507bdcf0f 100644 --- a/src/plugins/ui_core_views/dynamic_tables.ts +++ b/src/plugins/ui_core_views/dynamic_tables.ts @@ -1,7 +1,6 @@ -import { CellPosition, FilterId, TableId, UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { CellPosition, deepEquals, FilterId, TableId, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { areZonesContinuous, - deepEquals, getZoneArea, isInside, overlap, @@ -16,8 +15,8 @@ import { DynamicTable, ExcelWorkbookData, Filter, - Table, invalidateEvaluationCommands, + Table, } from "../../types/index"; import { CoreViewPlugin } from "../core_view_plugin"; diff --git a/src/plugins/ui_core_views/evaluation_conditional_format.ts b/src/plugins/ui_core_views/evaluation_conditional_format.ts index cbe959ec00..b870ca00cf 100644 --- a/src/plugins/ui_core_views/evaluation_conditional_format.ts +++ b/src/plugins/ui_core_views/evaluation_conditional_format.ts @@ -6,6 +6,7 @@ import { UID, Zone, } from "@odoo/o-spreadsheet-engine"; +import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { compile } from "../../formulas"; import { isMultipleElementMatrix, toScalar } from "../../functions/helper_matrices"; import { parseLiteral } from "../../helpers/cells"; @@ -23,7 +24,6 @@ import { EvaluatedCell, IconSetRule, IconThreshold, - Lazy, NumberCell, invalidateCFEvaluationCommands, } from "../../types/index"; diff --git a/src/plugins/ui_core_views/evaluation_data_validation.ts b/src/plugins/ui_core_views/evaluation_data_validation.ts index ee5f2d6559..f2f3035957 100644 --- a/src/plugins/ui_core_views/evaluation_data_validation.ts +++ b/src/plugins/ui_core_views/evaluation_data_validation.ts @@ -1,4 +1,5 @@ import { CellPosition, HeaderIndex, Matrix, Style, UID } from "@odoo/o-spreadsheet-engine"; +import { Lazy, Offset } from "@odoo/o-spreadsheet-engine/types"; import { DVTerms } from "../../components/translations_terms"; import { GRAY_200 } from "../../constants"; import { compile } from "../../formulas"; @@ -14,13 +15,9 @@ import { DataValidationCriterionType, DataValidationRule, EvaluatedCriterion, - Lazy, - Offset, } from "../../types"; import { CoreViewCommand, invalidateEvaluationCommands } from "../../types/commands"; import { CoreViewPlugin } from "../core_view_plugin"; -import { _t } from "./../../translation"; - interface InvalidValidationResult { readonly isValid: false; readonly rule: DataValidationRule; diff --git a/src/plugins/ui_core_views/header_sizes_ui.ts b/src/plugins/ui_core_views/header_sizes_ui.ts index 141e88fcff..c3bd04095a 100644 --- a/src/plugins/ui_core_views/header_sizes_ui.ts +++ b/src/plugins/ui_core_views/header_sizes_ui.ts @@ -10,7 +10,8 @@ import { removeIndexesFromArray, } from "../../helpers"; import { AnchorOffset, Command } from "../../types"; -import { Immutable } from "../../types/misc"; + +import { Immutable } from "@odoo/o-spreadsheet-engine/types"; interface HeaderSizeState { tallestCellInRow: Immutable>>; diff --git a/src/plugins/ui_core_views/pivot_ui.ts b/src/plugins/ui_core_views/pivot_ui.ts index 278095da76..a18209341c 100644 --- a/src/plugins/ui_core_views/pivot_ui.ts +++ b/src/plugins/ui_core_views/pivot_ui.ts @@ -1,9 +1,16 @@ -import { CellPosition, FunctionResultObject, isMatrix, UID } from "@odoo/o-spreadsheet-engine"; +import { + CellPosition, + deepEquals, + FunctionResultObject, + isMatrix, + UID, +} from "@odoo/o-spreadsheet-engine"; +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { Token } from "../../formulas"; import { astToFormula } from "../../formulas/formula_formatter"; import { toScalar } from "../../functions/helper_matrices"; import { toBoolean } from "../../functions/helpers"; -import { deepEquals, getUniqueText } from "../../helpers"; +import { getUniqueText } from "../../helpers"; import { getFirstPivotFunction, getNumberOfPivotFunctions, @@ -22,7 +29,6 @@ import { PivotCoreMeasure, PivotTableCell, PivotVisibilityOptions, - SortDirection, UpdatePivotCommand, } from "../../types"; import { Pivot } from "../../types/pivot_runtime"; diff --git a/src/plugins/ui_feature/automatic_sum.ts b/src/plugins/ui_feature/automatic_sum.ts index 93795d0120..e6a120a584 100644 --- a/src/plugins/ui_feature/automatic_sum.ts +++ b/src/plugins/ui_feature/automatic_sum.ts @@ -1,4 +1,5 @@ import { HeaderIndex, Position, Sheet, UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { groupConsecutive, isDateTimeFormat, @@ -11,7 +12,7 @@ import { union, zoneToDimension, } from "../../helpers"; -import { CellValueType, Command, Dimension, EvaluatedCell } from "../../types"; +import { CellValueType, Command, EvaluatedCell } from "../../types"; import { UIPlugin } from "../ui_plugin"; interface AutomaticSum { diff --git a/src/plugins/ui_feature/data_cleanup.ts b/src/plugins/ui_feature/data_cleanup.ts index d7dbd9bf06..cce90dc625 100644 --- a/src/plugins/ui_feature/data_cleanup.ts +++ b/src/plugins/ui_feature/data_cleanup.ts @@ -1,13 +1,6 @@ -import { HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { CellClipboardHandler } from "../../clipboard_handlers/cell_clipboard"; -import { - deepEquals, - positions, - range, - recomputeZones, - trimContent, - zoneToDimension, -} from "../../helpers"; +import { positions, range, recomputeZones, trimContent, zoneToDimension } from "../../helpers"; import { getClipboardDataPositions } from "../../helpers/clipboard/clipboard_helpers"; import { _t } from "../../translation"; import { Command, CommandResult, RemoveDuplicatesCommand } from "../../types/index"; diff --git a/src/plugins/ui_feature/format.ts b/src/plugins/ui_feature/format.ts index 56a0aff1d6..23de7c07b7 100644 --- a/src/plugins/ui_feature/format.ts +++ b/src/plugins/ui_feature/format.ts @@ -1,4 +1,5 @@ import { CellPosition, Position, UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { SetDecimalStep } from "@odoo/o-spreadsheet-engine/types"; import { changeDecimalPlaces, createDefaultFormat, @@ -7,14 +8,7 @@ import { positionToZone, recomputeZones, } from "../../helpers"; -import { - CellValueType, - Command, - Format, - PivotTableCell, - PivotValueCell, - SetDecimalStep, -} from "../../types/index"; +import { CellValueType, Command, Format, PivotTableCell, PivotValueCell } from "../../types/index"; import { UIPlugin } from "../ui_plugin"; export class FormatPlugin extends UIPlugin { diff --git a/src/plugins/ui_feature/header_visibility_ui.ts b/src/plugins/ui_feature/header_visibility_ui.ts index 2881a27906..8ccd5a5659 100644 --- a/src/plugins/ui_feature/header_visibility_ui.ts +++ b/src/plugins/ui_feature/header_visibility_ui.ts @@ -1,6 +1,7 @@ import { CellPosition, HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { range } from "../../helpers"; -import { Dimension, ExcelWorkbookData } from "../../types"; +import { ExcelWorkbookData } from "../../types"; import { UIPlugin } from "../ui_plugin"; export class HeaderVisibilityUIPlugin extends UIPlugin { diff --git a/src/plugins/ui_feature/sort.ts b/src/plugins/ui_feature/sort.ts index 0e42e3f86f..24b60b8061 100644 --- a/src/plugins/ui_feature/sort.ts +++ b/src/plugins/ui_feature/sort.ts @@ -1,21 +1,20 @@ -import { CellPosition, HeaderIndex, Position, UID, Zone } from "@odoo/o-spreadsheet-engine"; import { + CellPosition, deepEquals, - isInside, - overlap, - positions, - range, - zoneToDimension, -} from "../../helpers/index"; -import { sortCells } from "../../helpers/sort"; + HeaderIndex, + Position, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; +import { sortCells } from "@odoo/o-spreadsheet-engine/helpers/sortCells"; +import { SortDirection, SortOptions } from "@odoo/o-spreadsheet-engine/types"; +import { isInside, overlap, positions, range, zoneToDimension } from "../../helpers/index"; import { CellValueType, Command, CommandResult, LocalCommand, SortCommand, - SortDirection, - SortOptions, UpdateCellCommand, } from "../../types/index"; import { UIPlugin } from "../ui_plugin"; diff --git a/src/plugins/ui_feature/subtotal_evaluation.ts b/src/plugins/ui_feature/subtotal_evaluation.ts index a56e35f7f8..65e67367ea 100644 --- a/src/plugins/ui_feature/subtotal_evaluation.ts +++ b/src/plugins/ui_feature/subtotal_evaluation.ts @@ -1,4 +1,5 @@ -import { Cell, Command, invalidSubtotalFormulasCommands } from "../../types"; +import { isSubtotalCell } from "@odoo/o-spreadsheet-engine/helpers/is_subtotal_cell"; +import { Command, invalidSubtotalFormulasCommands } from "../../types"; import { UIPlugin } from "../ui_plugin"; export class SubtotalEvaluationPlugin extends UIPlugin { @@ -36,12 +37,3 @@ export class SubtotalEvaluationPlugin extends UIPlugin { } } } - -export function isSubtotalCell(cell: Cell): boolean { - return ( - cell.isFormula && - cell.compiledFormula.tokens.some( - (t) => t.type === "SYMBOL" && t.value.toUpperCase() === "SUBTOTAL" - ) - ); -} diff --git a/src/plugins/ui_stateful/carousel_ui.ts b/src/plugins/ui_stateful/carousel_ui.ts index 3539e9f78f..eb0915e3a1 100644 --- a/src/plugins/ui_stateful/carousel_ui.ts +++ b/src/plugins/ui_stateful/carousel_ui.ts @@ -1,6 +1,6 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, UID } from "@odoo/o-spreadsheet-engine"; import { AbstractChart, Carousel, CarouselItem, Command } from "../.."; -import { deepEquals, UuidGenerator } from "../../helpers"; +import { UuidGenerator } from "../../helpers"; import { CAROUSEL_DEFAULT_CHART_DEFINITION } from "../../helpers/carousel_helpers"; import { CommandResult, LocalCommand } from "../../types"; import { UIPlugin } from "../ui_plugin"; diff --git a/src/plugins/ui_stateful/clipboard.ts b/src/plugins/ui_stateful/clipboard.ts index a378287f93..c16fc46efd 100644 --- a/src/plugins/ui_stateful/clipboard.ts +++ b/src/plugins/ui_stateful/clipboard.ts @@ -1,4 +1,5 @@ import { HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { clipboardHandlersRegistries } from "../../clipboard_handlers"; import { ClipboardHandler } from "../../clipboard_handlers/abstract_clipboard_handler"; import { cellStyleToCss, cssPropertiesToCss } from "../../components/helpers"; @@ -26,7 +27,6 @@ import { FileStore } from "../../types/files"; import { Command, CommandResult, - Dimension, GridRenderingContext, LocalCommand, isCoreCommand, diff --git a/src/plugins/ui_stateful/header_positions.ts b/src/plugins/ui_stateful/header_positions.ts index d1d85f69db..13030e46ba 100644 --- a/src/plugins/ui_stateful/header_positions.ts +++ b/src/plugins/ui_stateful/header_positions.ts @@ -1,8 +1,8 @@ import { HeaderDimensions, HeaderIndex, Pixel, UID } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { deepCopy } from "../../helpers/index"; import { Command } from "../../types"; import { invalidateEvaluationCommands } from "../../types/commands"; -import { Dimension } from "../../types/misc"; import { UIPlugin } from "../ui_plugin"; export class HeaderPositionsUIPlugin extends UIPlugin { diff --git a/src/plugins/ui_stateful/selection.ts b/src/plugins/ui_stateful/selection.ts index 86c907ee94..d6e22570e4 100644 --- a/src/plugins/ui_stateful/selection.ts +++ b/src/plugins/ui_stateful/selection.ts @@ -10,6 +10,7 @@ import { UnboundedZone, Zone, } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { clipboardHandlersRegistries } from "../../clipboard_handlers"; import { AbstractCellClipboardHandler } from "../../clipboard_handlers/abstract_cell_clipboard_handler"; import { SELECTION_BORDER_COLOR } from "../../constants"; @@ -30,7 +31,6 @@ import { ClientPosition, Command, CommandResult, - Dimension, EvaluatedCell, GridRenderingContext, LocalCommand, diff --git a/src/plugins/ui_stateful/sheetview.ts b/src/plugins/ui_stateful/sheetview.ts index bfdbf2fea6..cfd5f4379d 100644 --- a/src/plugins/ui_stateful/sheetview.ts +++ b/src/plugins/ui_stateful/sheetview.ts @@ -1,15 +1,5 @@ -import { - CellPosition, - HeaderDimensions, - HeaderIndex, - Pixel, - PixelPosition, - Position, - UID, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { getDefaultSheetViewSize } from "../../constants"; -import { clip, findCellInNewZone, isDefined, positionToZone, range } from "../../helpers"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; +import { clip, findCellInNewZone, positionToZone, range } from "../../helpers"; import { scrollDelay } from "../../helpers/index"; import { InternalViewport } from "../../helpers/internal_viewport"; import { SelectionEvent } from "../../types/event_stream"; @@ -19,7 +9,6 @@ import { CommandResult, DOMCoordinates, DOMDimension, - Dimension, EdgeScrollInfo, Figure, FigureUI, diff --git a/src/registries/auto_completes/pivot_auto_complete.ts b/src/registries/auto_completes/pivot_auto_complete.ts index fe0fca78b6..f5c5c572b3 100644 --- a/src/registries/auto_completes/pivot_auto_complete.ts +++ b/src/registries/auto_completes/pivot_auto_complete.ts @@ -1,7 +1,5 @@ -import { insertTokenAtArgStartingPosition } from "@odoo/o-spreadsheet-engine"; -import { tokenColors } from "../../constants"; import { EnrichedToken } from "../../formulas/composer_tokenizer"; -import { MONTHS, isDefined, range } from "../../helpers"; +import { MONTHS, range } from "../../helpers"; import { extractFormulaIdFromToken, makeFieldProposal, diff --git a/src/registries/cell_clickable_registry.ts b/src/registries/cell_clickable_registry.ts index b862119536..9a2cc99357 100644 --- a/src/registries/cell_clickable_registry.ts +++ b/src/registries/cell_clickable_registry.ts @@ -1,10 +1,11 @@ import { CellPosition } from "@odoo/o-spreadsheet-engine"; +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { ComponentConstructor } from "@odoo/owl"; import { ClickableCellSortIcon } from "../components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon"; import { openLink } from "../helpers/links"; import { canSortPivot, sortPivot } from "../helpers/pivot/pivot_menu_items"; import { _t } from "../translation"; -import { Getters, SortDirection, SpreadsheetChildEnv } from "../types"; +import { Getters, SpreadsheetChildEnv } from "../types"; import { Registry } from "./registry"; export interface CellClickableItem { diff --git a/src/registries/icons_on_cell_registry.ts b/src/registries/icons_on_cell_registry.ts index e49a136327..42b2e0ae23 100644 --- a/src/registries/icons_on_cell_registry.ts +++ b/src/registries/icons_on_cell_registry.ts @@ -1,4 +1,4 @@ -import { Align, CellPosition } from "@odoo/o-spreadsheet-engine"; +import { Align, CellPosition, deepEquals } from "@odoo/o-spreadsheet-engine"; import { CHECKBOX_CHECKED, CHECKBOX_UNCHECKED, @@ -20,7 +20,7 @@ import { PIVOT_COLLAPSE_ICON_SIZE, PIVOT_INDENT, } from "../constants"; -import { computeTextFontSizeInPixels, deepEquals, relativeLuminance } from "../helpers"; +import { computeTextFontSizeInPixels, relativeLuminance } from "../helpers"; import { Getters, SpreadsheetChildEnv } from "../types"; import { ImageSVG } from "../types/image"; export type IconsOfCell = Record, GridIcon | undefined>; diff --git a/src/registries/menus/header_group_registry.ts b/src/registries/menus/header_group_registry.ts index c22943202e..bbf06cd574 100644 --- a/src/registries/menus/header_group_registry.ts +++ b/src/registries/menus/header_group_registry.ts @@ -1,9 +1,9 @@ import { UID } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { Action, createActions } from "../../actions/action"; import * as ACTION_VIEW from "../../actions/view_actions"; import { interactiveToggleGroup } from "../../helpers/ui/toggle_group_interactive"; import { _t } from "../../translation"; -import { Dimension } from "../../types"; import { MenuItemRegistry } from "../menu_items_registry"; export function createHeaderGroupContainerContextMenu( diff --git a/src/selection_stream/selection_stream_processor.ts b/src/selection_stream/selection_stream_processor.ts index 5e0e54286a..638d574f9b 100644 --- a/src/selection_stream/selection_stream_processor.ts +++ b/src/selection_stream/selection_stream_processor.ts @@ -1,24 +1,16 @@ -import { AnchorZone, CellPosition, HeaderIndex, Position, Zone } from "@odoo/o-spreadsheet-engine"; import { - deepCopy, + AnchorZone, + CellPosition, deepEquals, - isEqual, - isInside, - positionToZone, - reorderZone, - union, -} from "../helpers"; -import { - CellValueType, - CommandResult, - Direction, - DispatchResult, - Getters, - SelectionStep, -} from "../types"; + HeaderIndex, + Position, + Zone, +} from "@odoo/o-spreadsheet-engine"; +import { Dimension, Direction, SelectionStep } from "@odoo/o-spreadsheet-engine/types"; +import { deepCopy, isEqual, isInside, positionToZone, reorderZone, union } from "../helpers"; +import { CellValueType, CommandResult, DispatchResult, Getters } from "../types"; import { SelectionEvent, SelectionEventOptions } from "../types/event_stream"; -import { Dimension } from "./../types/misc"; -import { EventStream, StreamCallbacks } from "./event_stream"; +import { StreamCallbacks } from "./event_stream"; type Delta = [number, number]; diff --git a/src/stores/grid_renderer_store.ts b/src/stores/grid_renderer_store.ts index da03df6e0b..274825be3f 100644 --- a/src/stores/grid_renderer_store.ts +++ b/src/stores/grid_renderer_store.ts @@ -1,4 +1,12 @@ -import { Align, CellPosition, HeaderIndex, Pixel, UID, Zone } from "@odoo/o-spreadsheet-engine"; +import { + Align, + CellPosition, + deepEquals, + HeaderIndex, + Pixel, + UID, + Zone, +} from "@odoo/o-spreadsheet-engine"; import { ModelStore, SpreadsheetStore } from "."; import { HoveredIconStore } from "../components/grid_overlay/hovered_icon_store"; import { getPath2D } from "../components/icons/icons"; @@ -25,7 +33,6 @@ import { computeTextFontSizeInPixels, computeTextLinesHeight, deepCopy, - deepEquals, drawDecoratedText, getZonesCols, getZonesRows, diff --git a/src/types/commands.ts b/src/types/commands.ts index 56edb19295..4dc3bdfed0 100644 --- a/src/types/commands.ts +++ b/src/types/commands.ts @@ -1,5 +1,4 @@ import { ConditionalFormat, DataValidationRule, Figure, Format, Locale } from "./index"; -import { Dimension, SetDecimalStep, SortDirection, SortOptions } from "./misc"; import { Border, @@ -13,6 +12,12 @@ import { UID, Zone, } from "@odoo/o-spreadsheet-engine"; +import { + Dimension, + SetDecimalStep, + SortDirection, + SortOptions, +} from "@odoo/o-spreadsheet-engine/types"; import { ChartDefinition } from "./chart/chart"; import { ClipboardPasteOptions, ParsedOsClipboardContentWithImageData } from "./clipboard"; import { Carousel, CarouselItem, FigureSize } from "./figure"; diff --git a/src/types/index.ts b/src/types/index.ts index 2925ae8c1b..5a7b4bbb7d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -12,7 +12,6 @@ import * as Chart from "chart.js"; import * as ChartGeo from "chartjs-chart-geo"; export * from "./autofill"; -export * from "./cells"; export * from "./chart/chart"; export * from "./clipboard"; export * from "./collaborative/revisions"; @@ -23,8 +22,6 @@ export * from "./currency"; export * from "./data_validation"; export * from "./env"; export * from "./figure"; -export * from "./format"; -export * from "./functions"; export * from "./generic_criterion"; export * from "./getters"; export * from "./history"; diff --git a/src/types/misc.ts b/src/types/misc.ts index c7cd02ee5d..b331d46eb9 100644 --- a/src/types/misc.ts +++ b/src/types/misc.ts @@ -2,115 +2,13 @@ // MISC // ----------------------------------------------------------------------------- -export type SetDecimalStep = 1 | -1; - -export interface RGBA { - a: number; - r: number; - g: number; - b: number; -} - -export interface HSLA { - a: number; - h: number; - s: number; - l: number; -} - -export interface Link { - readonly label: string; - readonly url: string; - readonly isExternal: boolean; - /** - * Specifies if the URL is editable by the end user. - * Special links might not allow it. - */ - readonly isUrlEditable: boolean; -} - -export type FunctionResultNumber = { value: number; format?: string }; - -export type Dimension = "COL" | "ROW"; - -export type Validation = EngineValidation; - -export type Increment = 1 | -1 | 0; - -export interface Ref { - el: T | null; -} - /** * Return the prop's type of a component */ export type PropsOf = C extends ComponentConstructor ? Props : never; -/** - * Container for a lazy computed value - */ -export interface Lazy { - /** - * Return the computed value. - * The value is computed only once and memoized. - */ - (): T; - /** - * Map a lazy value to another lazy value. - * - * ```ts - * // neither function is called here - * const lazyValue = lazy(() => veryExpensive(...)).map((result) => alsoVeryExpensive(result)); - * - * // both values are computed now - * const value = lazyValue() - * ``` - */ - map: (callback: (value: T) => U) => Lazy; -} - -export interface Cloneable { - clone: (args?: Partial) => T; -} - export type CSSProperties

= Record; -export interface SortOptions { - /** If true sort the headers of the range along with the rest */ - sortHeaders?: boolean; - /** If true treat empty cells as "0" instead of undefined */ - emptyCellAsZero?: boolean; -} - -// https://github.com/Microsoft/TypeScript/issues/13923#issuecomment-557509399 -// prettier-ignore -export type Immutable = - T extends ImmutablePrimitive ? T : - T extends Array ? ImmutableArray : - T extends Map ? ImmutableMap : - T extends Set ? ImmutableSet : - ImmutableObject; - -type ImmutablePrimitive = undefined | null | boolean | string | number | Function; -type ImmutableArray = ReadonlyArray>; -type ImmutableMap = ReadonlyMap, Immutable>; -type ImmutableSet = ReadonlySet>; -type ImmutableObject = { readonly [K in keyof T]: Immutable }; - -export type Direction = "up" | "down" | "left" | "right"; - -export type SelectionStep = number | "end"; - -export interface Offset { - col: number; - row: number; -} - -export type DebouncedFunction = T & { - stopDebounce: () => void; - isDebouncePending: () => boolean; -}; - export interface GridClickModifiers { addZone: boolean; expandZone: boolean; @@ -122,10 +20,3 @@ export type EditionMode = | "editing" | "selecting" // should tell if you need to underline the current range selected. | "inactive"; - -export type SortDirection = "asc" | "desc"; - -export interface ValueAndLabel { - value: T; - label: string; -} diff --git a/src/types/workbook_data.ts b/src/types/workbook_data.ts index 610ff2f7a5..fb08c09980 100644 --- a/src/types/workbook_data.ts +++ b/src/types/workbook_data.ts @@ -8,12 +8,12 @@ import { Style, UID, } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { CellValue, DataValidationRule, Format, Locale } from "."; import { ZoneBorderData } from "../plugins/core"; import { ExcelChartDefinition } from "./chart/chart"; import { ConditionalFormat } from "./conditional_formatting"; import { Image } from "./image"; -import { Dimension } from "./misc"; import { PivotCoreDefinition } from "./pivot"; import { CoreTableType, TableConfig, TableStyleTemplateName } from "./table"; diff --git a/src/xlsx/conversion/figure_conversion.ts b/src/xlsx/conversion/figure_conversion.ts index 1eceaeb8bd..0ec95410fd 100644 --- a/src/xlsx/conversion/figure_conversion.ts +++ b/src/xlsx/conversion/figure_conversion.ts @@ -1,12 +1,4 @@ -import { HeaderIndex, PixelPosition } from "@odoo/o-spreadsheet-engine"; -import { DEFAULT_WINDOW_SIZE, FIGURE_BORDER_WIDTH } from "../../constants"; -import { - getFullReference, - isDefined, - splitReference, - toUnboundedZone, - zoneToXc, -} from "../../helpers"; +import { getFullReference, splitReference, toUnboundedZone, zoneToXc } from "../../helpers"; import { chartRegistry } from "../../registries/chart_types"; import { ChartCreationContext, diff --git a/src/xlsx/conversion/sheet_conversion.ts b/src/xlsx/conversion/sheet_conversion.ts index 0f6be335b7..9579692325 100644 --- a/src/xlsx/conversion/sheet_conversion.ts +++ b/src/xlsx/conversion/sheet_conversion.ts @@ -1,4 +1,5 @@ import { HeaderGroup } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { buildSheetLink, largeMax, @@ -8,7 +9,7 @@ import { toCartesian, toXC, } from "../../helpers"; -import { Dimension, HeaderData, SheetData } from "../../types"; +import { HeaderData, SheetData } from "../../types"; import { XLSXCell, XLSXColumn, diff --git a/src/xlsx/extraction/base_extractor.ts b/src/xlsx/extraction/base_extractor.ts index 2804544fe3..f55aa9dc98 100644 --- a/src/xlsx/extraction/base_extractor.ts +++ b/src/xlsx/extraction/base_extractor.ts @@ -1,4 +1,4 @@ -import { isDefined } from "../../helpers"; +import { isDefined } from "@odoo/o-spreadsheet-engine"; import { XLSXColor, XLSXColorScheme, diff --git a/src/xlsx/helpers/misc.ts b/src/xlsx/helpers/misc.ts index 169fe369a2..03868a635b 100644 --- a/src/xlsx/helpers/misc.ts +++ b/src/xlsx/helpers/misc.ts @@ -1,4 +1,5 @@ -import { Dimension, ExcelHeaderData, ExcelSheetData } from "../../types"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; +import { ExcelHeaderData, ExcelSheetData } from "../../types"; /** * Get the relative path between two files diff --git a/tests/__mocks__/mock_misc_helpers.ts b/tests/__mocks__/mock_misc_helpers.ts index b628913e41..2a677f22ea 100644 --- a/tests/__mocks__/mock_misc_helpers.ts +++ b/tests/__mocks__/mock_misc_helpers.ts @@ -1,4 +1,4 @@ -import { DebouncedFunction } from "../../src/types"; +import { DebouncedFunction } from "@odoo/o-spreadsheet-engine/types"; /** Mocked debounce that doesn't actually do any debouncing, but just calls the function directly */ export function debounce void>(func: T): DebouncedFunction { diff --git a/tests/collaborative/collaborative_monkey_party.test.ts b/tests/collaborative/collaborative_monkey_party.test.ts index 194da3d5f6..c47a8d78d7 100644 --- a/tests/collaborative/collaborative_monkey_party.test.ts +++ b/tests/collaborative/collaborative_monkey_party.test.ts @@ -1,8 +1,8 @@ -import { UnboundedZone } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, UnboundedZone } from "@odoo/o-spreadsheet-engine"; import { FunctionCodeBuilder } from "@odoo/o-spreadsheet-engine/formulas/code_builder"; import seedrandom from "seedrandom"; import { Model } from "../../src"; -import { deepCopy, deepEquals, range, reorderZone } from "../../src/helpers"; +import { deepCopy, range, reorderZone } from "../../src/helpers"; import { Command, CoreCommand, diff --git a/tests/colors/color_helpers.test.ts b/tests/colors/color_helpers.test.ts index 1c0dddefad..4cf509f84f 100644 --- a/tests/colors/color_helpers.test.ts +++ b/tests/colors/color_helpers.test.ts @@ -1,17 +1,5 @@ import { Color } from "@odoo/o-spreadsheet-engine"; -import { - colorToNumber, - colorToRGBA, - getColorScale, - hslaToRGBA, - isColorValid, - rgba, - rgbaToHex, - rgbaToHSLA, - toHex, -} from "../../src/helpers/color"; -import { HSLA, RGBA } from "../../src/types"; - +import { HSLA, RGBA } from "@odoo/o-spreadsheet-engine/types"; const testColors: { input: Color; hex: Color; rgba: RGBA; hsla: HSLA }[] = [ { input: "#000000", diff --git a/tests/formats/formatting_plugin.test.ts b/tests/formats/formatting_plugin.test.ts index 3d506c6751..1e8adf1db8 100644 --- a/tests/formats/formatting_plugin.test.ts +++ b/tests/formats/formatting_plugin.test.ts @@ -1,4 +1,5 @@ import { functionRegistry, UID } from "@odoo/o-spreadsheet-engine"; +import { SetDecimalStep } from "@odoo/o-spreadsheet-engine/types"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH, @@ -16,7 +17,7 @@ import { toScalar } from "../../src/functions/helper_matrices"; import { toString } from "../../src/functions/helpers"; import { fontSizeInPixels, getCellContentHeight, toCartesian } from "../../src/helpers"; import { Model } from "../../src/model"; -import { CommandResult, Format, SetDecimalStep } from "../../src/types"; +import { CommandResult, Format } from "../../src/types"; import { createSheet, createTableWithFilter, diff --git a/tests/functions/helper.test.ts b/tests/functions/helper.test.ts index c598c1ef6a..a028eb4a6b 100644 --- a/tests/functions/helper.test.ts +++ b/tests/functions/helper.test.ts @@ -1,6 +1,7 @@ +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { dichotomicSearch as dichotomicSearchUniteData } from "../../src/functions/helpers"; import { isValidLocale } from "../../src/helpers/locale"; -import { CellValue, DEFAULT_LOCALE, SortDirection } from "../../src/types"; +import { CellValue, DEFAULT_LOCALE } from "../../src/types"; function getItem(arr: any[], i: number) { return arr[i]; diff --git a/tests/header_group/header_group_component.test.ts b/tests/header_group/header_group_component.test.ts index 1ad6572c87..830369f731 100644 --- a/tests/header_group/header_group_component.test.ts +++ b/tests/header_group/header_group_component.test.ts @@ -1,4 +1,5 @@ import { UID } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { Model } from "../../src"; import { HeaderGroupContainer } from "../../src/components/header_group/header_group_container"; import { @@ -8,7 +9,6 @@ import { HEADER_HEIGHT, HEADER_WIDTH, } from "../../src/constants"; -import { Dimension } from "../../src/types"; import { foldHeaderGroup, freezeColumns, diff --git a/tests/header_group/header_group_plugin.test.ts b/tests/header_group/header_group_plugin.test.ts index 46e14b1e8a..13ca0304d5 100644 --- a/tests/header_group/header_group_plugin.test.ts +++ b/tests/header_group/header_group_plugin.test.ts @@ -1,6 +1,7 @@ import { HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; import { CommandResult, Model } from "../../src"; -import { Dimension } from "../../src/types/misc"; + +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; function getSortedGroups(model: Model, sheetId: UID, dimension: Dimension) { return model.getters .getHeaderGroups(sheetId, dimension) diff --git a/tests/helpers/misc_helpers.test.ts b/tests/helpers/misc_helpers.test.ts index 461e9130f5..23f34c55d1 100644 --- a/tests/helpers/misc_helpers.test.ts +++ b/tests/helpers/misc_helpers.test.ts @@ -1,5 +1,6 @@ +import { deepEquals } from "@odoo/o-spreadsheet-engine"; import seedrandom from "seedrandom"; -import { DateTime, deepCopy, deepEquals, UuidGenerator } from "../../src/helpers"; +import { DateTime, deepCopy, UuidGenerator } from "../../src/helpers"; import { getUniqueText, groupConsecutive, diff --git a/tests/helpers/ui_helpers.test.ts b/tests/helpers/ui_helpers.test.ts index abc462d4a5..dcbd4da109 100644 --- a/tests/helpers/ui_helpers.test.ts +++ b/tests/helpers/ui_helpers.test.ts @@ -1,4 +1,5 @@ import { Position, UID } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { TableTerms } from "../../src/components/translations_terms"; import { toCartesian, toXC, toZone, zoneToXc } from "../../src/helpers/index"; import { interactiveSortSelection } from "../../src/helpers/sort"; @@ -20,7 +21,7 @@ import { interactiveToggleGroup, } from "../../src/helpers/ui/toggle_group_interactive"; import { Model } from "../../src/model"; -import { CommandResult, Dimension, SpreadsheetChildEnv } from "../../src/types"; +import { CommandResult, SpreadsheetChildEnv } from "../../src/types"; import { addCellToSelection, copy, diff --git a/tests/pivots/pivot_menu_items.test.ts b/tests/pivots/pivot_menu_items.test.ts index da89a3cca1..4465618bf6 100644 --- a/tests/pivots/pivot_menu_items.test.ts +++ b/tests/pivots/pivot_menu_items.test.ts @@ -1,10 +1,5 @@ -import { - Model, - PivotCustomGroup, - SortDirection, - SpreadsheetChildEnv, - SpreadsheetPivotTable, -} from "../../src"; +import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; +import { Model, PivotCustomGroup, SpreadsheetChildEnv, SpreadsheetPivotTable } from "../../src"; import { Action } from "../../src/actions/action"; import { getPivotTooBigErrorMessage } from "../../src/components/translations_terms"; import { PIVOT_TABLE_CONFIG } from "../../src/constants"; diff --git a/tests/repeat_commands_plugin.test.ts b/tests/repeat_commands_plugin.test.ts index 94430d87c2..bf2ac5ea1d 100644 --- a/tests/repeat_commands_plugin.test.ts +++ b/tests/repeat_commands_plugin.test.ts @@ -1,4 +1,5 @@ import { UID } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { Model } from "../src"; import { DEFAULT_CELL_HEIGHT } from "../src/constants"; import { toZone } from "../src/helpers"; @@ -7,7 +8,7 @@ import { repeatCoreCommand, repeatLocalCommandTransformRegistry, } from "../src/registries/repeat_commands_registry"; -import { CoreCommand, Dimension } from "../src/types"; +import { CoreCommand } from "../src/types"; import { AddColumnsRowsCommand, CreateChartCommand, diff --git a/tests/setup/jest_extend.ts b/tests/setup/jest_extend.ts index a68022d07d..60030b2dcb 100644 --- a/tests/setup/jest_extend.ts +++ b/tests/setup/jest_extend.ts @@ -1,8 +1,7 @@ -import { Zone } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, Zone } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { isSameColor, toHex } from "../../src/helpers/color"; import { toXC } from "../../src/helpers/coordinates"; -import { deepEquals } from "../../src/helpers/misc"; import { positions } from "../../src/helpers/zones"; import { CancelledReason, DispatchResult } from "../../src/types"; diff --git a/tests/sheet/navigation_plugin.test.ts b/tests/sheet/navigation_plugin.test.ts index c62fbb0c7b..92086b579d 100644 --- a/tests/sheet/navigation_plugin.test.ts +++ b/tests/sheet/navigation_plugin.test.ts @@ -1,6 +1,7 @@ +import { Direction } from "@odoo/o-spreadsheet-engine/types"; import { toCartesian, toXC } from "../../src/helpers"; import { Model } from "../../src/model"; -import { CommandResult, Direction, Viewport } from "../../src/types"; +import { CommandResult, Viewport } from "../../src/types"; import { hideColumns, hideRows, diff --git a/tests/sheet/selection_plugin.test.ts b/tests/sheet/selection_plugin.test.ts index 2b8bae0be5..290a8ec8c4 100644 --- a/tests/sheet/selection_plugin.test.ts +++ b/tests/sheet/selection_plugin.test.ts @@ -1,3 +1,4 @@ +import { Direction } from "@odoo/o-spreadsheet-engine/types"; import { CoreCommand, CorePlugin } from "../../src"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../src/constants"; import { @@ -10,7 +11,7 @@ import { } from "../../src/helpers"; import { Model } from "../../src/model"; import { corePluginRegistry } from "../../src/plugins"; -import { CommandResult, Direction } from "../../src/types"; +import { CommandResult } from "../../src/types"; import { activateSheet, addCellToSelection, diff --git a/tests/sheet/sheetview_plugin.test.ts b/tests/sheet/sheetview_plugin.test.ts index 55b620db62..9c899910f6 100644 --- a/tests/sheet/sheetview_plugin.test.ts +++ b/tests/sheet/sheetview_plugin.test.ts @@ -1,14 +1,12 @@ -import { Zone } from "@odoo/o-spreadsheet-engine"; -import { CommandResult } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH, DEFAULT_REVISION_ID, - MESSAGE_VERSION, getDefaultSheetViewSize, + MESSAGE_VERSION, } from "../../src/constants"; -import { isDefined, numberToLetters, range, toXC, toZone, zoneToXc } from "../../src/helpers"; +import { numberToLetters, range, toXC, toZone, zoneToXc } from "../../src/helpers"; import { Model } from "../../src/model"; import { SheetViewPlugin } from "../../src/plugins/ui_stateful/sheetview"; import { StateUpdateMessage } from "../../src/types/collaborative/transport_service"; diff --git a/tests/test_helpers/commands_helpers.ts b/tests/test_helpers/commands_helpers.ts index 2b48a493d1..701cdf1053 100644 --- a/tests/test_helpers/commands_helpers.ts +++ b/tests/test_helpers/commands_helpers.ts @@ -22,14 +22,9 @@ import { CreateSheetCommand, CreateTableStyleCommand, DataValidationCriterion, - Dimension, - Direction, DispatchResult, Locale, ParsedOsClipboardContentWithImageData, - SelectionStep, - SortDirection, - SortOptions, SplitTextIntoColumnsCommand, } from "../../src/types"; import { createEqualCF, target, toRangeData, toRangesData } from "./helpers"; @@ -45,6 +40,13 @@ import { Style, UID, } from "@odoo/o-spreadsheet-engine"; +import { + Dimension, + Direction, + SelectionStep, + SortDirection, + SortOptions, +} from "@odoo/o-spreadsheet-engine/types"; import { ICON_SETS } from "../../src/components/icons/icons"; import { SunburstChartDefinition } from "../../src/types/chart"; import { ComboChartDefinition } from "../../src/types/chart/combo_chart"; @@ -57,8 +59,6 @@ import { TreeMapChartDefinition } from "../../src/types/chart/tree_map_chart"; import { WaterfallChartDefinition } from "../../src/types/chart/waterfall_chart"; import { Image } from "../../src/types/image"; import { CoreTableType, CriterionFilter, TableConfig } from "../../src/types/table"; -import { CarouselItem, FigureSize } from "./../../src/types/figure"; - /** * Dispatch an UNDO to the model */ diff --git a/tests/xlsx/xlsx_export.test.ts b/tests/xlsx/xlsx_export.test.ts index f18b8b7926..8607c7b19a 100644 --- a/tests/xlsx/xlsx_export.test.ts +++ b/tests/xlsx/xlsx_export.test.ts @@ -4,13 +4,14 @@ import { RAND, RANDARRAY, RANDBETWEEN } from "../../src/functions/module_math"; import { buildSheetLink, toXC } from "../../src/helpers"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { Model } from "../../src/model"; -import { CustomizedDataSet, Dimension } from "../../src/types"; +import { CustomizedDataSet } from "../../src/types"; import { XLSXExportXMLFile, XMLString } from "../../src/types/xlsx"; import { hexaToInt } from "../../src/xlsx/conversion"; import { adaptFormulaToExcel } from "../../src/xlsx/functions/cells"; import { escapeXml, parseXML } from "../../src/xlsx/helpers/xml_helpers"; import { functionRegistry } from "@odoo/o-spreadsheet-engine"; +import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { createChart, createGaugeChart, From d587acdc87aa8b4e19ddde7aec411816abe1f385 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Wed, 1 Oct 2025 12:55:06 +0200 Subject: [PATCH 18/19] so much fun --- .../src}/functions/helper_logical.ts | 2 +- .../src}/functions/module_array.ts | 2 +- .../src}/functions/module_date.ts | 0 .../src}/helpers/format/format.ts | 13 ++++++++++--- .../src}/helpers/format/format_parser.ts | 0 .../src}/helpers/format/format_tokenizer.ts | 0 .../o-spreadsheet-engine/src}/helpers/locale.ts | 0 packages/o-spreadsheet-engine/src/helpers/sort.ts | 2 +- .../o-spreadsheet-engine/src/types/functions.ts | 2 +- 9 files changed, 14 insertions(+), 7 deletions(-) rename {src => packages/o-spreadsheet-engine/src}/functions/helper_logical.ts (91%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_array.ts (99%) rename {src => packages/o-spreadsheet-engine/src}/functions/module_date.ts (100%) rename {src => packages/o-spreadsheet-engine/src}/helpers/format/format.ts (99%) rename {src => packages/o-spreadsheet-engine/src}/helpers/format/format_parser.ts (100%) rename {src => packages/o-spreadsheet-engine/src}/helpers/format/format_tokenizer.ts (100%) rename {src => packages/o-spreadsheet-engine/src}/helpers/locale.ts (100%) diff --git a/src/functions/helper_logical.ts b/packages/o-spreadsheet-engine/src/functions/helper_logical.ts similarity index 91% rename from src/functions/helper_logical.ts rename to packages/o-spreadsheet-engine/src/functions/helper_logical.ts index fac9598db4..1a0d4c20fd 100644 --- a/src/functions/helper_logical.ts +++ b/packages/o-spreadsheet-engine/src/functions/helper_logical.ts @@ -1,4 +1,4 @@ -import { Arg } from "@odoo/o-spreadsheet-engine"; +import { Arg } from "../index"; import { conditionalVisitBoolean } from "./helpers"; export function boolAnd(args: Arg[]) { diff --git a/src/functions/module_array.ts b/packages/o-spreadsheet-engine/src/functions/module_array.ts similarity index 99% rename from src/functions/module_array.ts rename to packages/o-spreadsheet-engine/src/functions/module_array.ts index e1a249d892..01f73dd97b 100644 --- a/src/functions/module_array.ts +++ b/packages/o-spreadsheet-engine/src/functions/module_array.ts @@ -1,4 +1,4 @@ -import { Arg, FunctionResultObject, Functions, Matrix, Maybe } from "@odoo/o-spreadsheet-engine"; +import { Arg, FunctionResultObject, Functions, Matrix, Maybe } from "../index"; import { _t } from "../translation"; import { EvaluationError, NotAvailableError } from "../types/errors"; import { arg } from "./arguments"; diff --git a/src/functions/module_date.ts b/packages/o-spreadsheet-engine/src/functions/module_date.ts similarity index 100% rename from src/functions/module_date.ts rename to packages/o-spreadsheet-engine/src/functions/module_date.ts diff --git a/src/helpers/format/format.ts b/packages/o-spreadsheet-engine/src/helpers/format/format.ts similarity index 99% rename from src/helpers/format/format.ts rename to packages/o-spreadsheet-engine/src/helpers/format/format.ts index 5354a2cb04..762c5b38f0 100644 --- a/src/helpers/format/format.ts +++ b/packages/o-spreadsheet-engine/src/helpers/format/format.ts @@ -1,8 +1,15 @@ -import { FunctionResultObject, Maybe } from "@odoo/o-spreadsheet-engine"; import { toNumber } from "../../functions/helpers"; +import { FunctionResultObject, Maybe } from "../../index"; import { _t } from "../../translation"; -import { CellValue, Currency, Format, FormattedValue, Locale, LocaleFormat } from "../../types"; -import { EvaluationError } from "../../types/errors"; +import { + CellValue, + Currency, + EvaluationError, + Format, + FormattedValue, + Locale, + LocaleFormat, +} from "../../types"; import { DateTime, INITIAL_1900_DAY, isDateTime, numberToJsDate, parseDateTime } from "../dates"; import { escapeRegExp, diff --git a/src/helpers/format/format_parser.ts b/packages/o-spreadsheet-engine/src/helpers/format/format_parser.ts similarity index 100% rename from src/helpers/format/format_parser.ts rename to packages/o-spreadsheet-engine/src/helpers/format/format_parser.ts diff --git a/src/helpers/format/format_tokenizer.ts b/packages/o-spreadsheet-engine/src/helpers/format/format_tokenizer.ts similarity index 100% rename from src/helpers/format/format_tokenizer.ts rename to packages/o-spreadsheet-engine/src/helpers/format/format_tokenizer.ts diff --git a/src/helpers/locale.ts b/packages/o-spreadsheet-engine/src/helpers/locale.ts similarity index 100% rename from src/helpers/locale.ts rename to packages/o-spreadsheet-engine/src/helpers/locale.ts diff --git a/packages/o-spreadsheet-engine/src/helpers/sort.ts b/packages/o-spreadsheet-engine/src/helpers/sort.ts index 7b3ce32b69..f4f3ac9682 100644 --- a/packages/o-spreadsheet-engine/src/helpers/sort.ts +++ b/packages/o-spreadsheet-engine/src/helpers/sort.ts @@ -1,4 +1,4 @@ -import { CellValue, CellValueType, EvaluatedCell, SortDirection } from "../index"; +import { CellValue, CellValueType, EvaluatedCell, SortDirection } from "../types"; type CellWithIndex = { index: number; type: CellValueType; value: any }; const SORT_TYPES: CellValueType[] = [ diff --git a/packages/o-spreadsheet-engine/src/types/functions.ts b/packages/o-spreadsheet-engine/src/types/functions.ts index e1018bb20c..0356538de7 100644 --- a/packages/o-spreadsheet-engine/src/types/functions.ts +++ b/packages/o-spreadsheet-engine/src/types/functions.ts @@ -1,4 +1,4 @@ -import { CellPosition } from "./base"; +import { Arg, CellPosition, CellValue, FunctionResultObject, Matrix, UID } from "./index"; import { Locale } from "./locale"; export type ArgType = From ff339454844dbb651756d1abf5128bd1e4c6987f Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Wed, 1 Oct 2025 14:01:55 +0200 Subject: [PATCH 19/19] soo soo much fun --- .../o-spreadsheet-engine/src/helpers/misc.ts | 322 ++++++++++++++++++ src/actions/menu_items_actions.ts | 12 +- src/actions/sheet_actions.ts | 3 +- src/clipboard_handlers/tables_clipboard.ts | 2 - src/collaborative/session.ts | 2 +- .../aggregate_statistics_store.ts | 3 +- .../composer/abstract_composer_store.ts | 16 - .../composer/composer/cell_composer_store.ts | 3 - src/components/composer/composer/composer.ts | 4 +- .../composer/grid_composer/grid_composer.ts | 10 +- .../pie_hole_size/pie_hole_size.ts | 3 +- .../funnel_chart_design_panel.ts | 3 - .../find_and_replace/find_and_replace.ts | 3 +- .../find_and_replace_store.ts | 4 +- src/components/spreadsheet/spreadsheet.ts | 13 - src/functions/module_text.ts | 2 - src/helpers/chart_date.ts | 4 +- src/helpers/figures/charts/chart_common.ts | 2 +- .../charts/runtime/chart_data_extractor.ts | 3 +- .../figures/charts/runtime/chartjs_scales.ts | 4 +- src/helpers/formulas.ts | 3 - src/helpers/links.ts | 3 +- src/helpers/misc.ts | 282 +-------------- src/helpers/pivot/pivot_helpers.ts | 2 +- src/helpers/pivot/pivot_presentation.ts | 8 - src/helpers/pivot/table_spreadsheet_pivot.ts | 3 - src/helpers/range.ts | 12 +- src/history/operation.ts | 3 - src/index.ts | 6 +- src/migrations/migration_steps.ts | 4 +- src/model.ts | 3 +- src/plugins/core/borders.ts | 15 - src/plugins/core/cell.ts | 15 - src/plugins/core/header_grouping.ts | 9 - src/plugins/core/header_size.ts | 4 +- src/plugins/core/header_visibility.ts | 11 +- src/plugins/core/sheet.ts | 6 +- src/plugins/core/table_style.ts | 3 +- .../cell_evaluation/evaluator.ts | 2 +- .../evaluation_conditional_format.ts | 11 +- .../evaluation_data_validation.ts | 6 +- src/plugins/ui_core_views/header_sizes_ui.ts | 4 - src/plugins/ui_core_views/pivot_ui.ts | 9 - src/plugins/ui_feature/automatic_sum.ts | 4 - src/plugins/ui_feature/cell_computed_style.ts | 4 +- src/plugins/ui_feature/data_cleanup.ts | 4 +- src/plugins/ui_feature/insert_pivot.ts | 4 +- .../ui_feature/table_computed_style.ts | 3 - src/plugins/ui_feature/ui_sheet.ts | 17 - src/plugins/ui_stateful/filter_evaluation.ts | 5 +- .../data_validation_auto_complete.ts | 3 +- .../auto_completes/function_auto_complete.ts | 3 - src/registries/criterion_registry.ts | 3 - src/xlsx/conversion/sheet_conversion.ts | 12 +- src/xlsx/functions/charts.ts | 4 +- src/xlsx/functions/styles.ts | 2 +- src/xlsx/functions/worksheet.ts | 4 - src/xlsx/helpers/xml_helpers.ts | 3 - src/xlsx/xlsx_reader.ts | 2 +- src/xlsx/xlsx_writer.ts | 3 +- tests/autofill/autofill_plugin.test.ts | 6 +- tests/borders/border_plugin.test.ts | 3 - tests/cells/cell_plugin.test.ts | 4 +- .../collaborative_session.test.ts | 2 +- tests/grid/grid_component.test.ts | 4 +- tests/helpers/misc_helpers.test.ts | 11 +- tests/link/link_display_component.test.ts | 2 +- tests/link/link_editor_component.test.ts | 2 +- tests/test_helpers/debug_helpers.ts | 4 +- tests/test_helpers/helpers.ts | 3 - tests/xlsx/xlsx_export.test.ts | 4 +- tests/xlsx/xlsx_import.test.ts | 9 +- tests/xlsx/xlsx_import_export.test.ts | 4 +- 73 files changed, 383 insertions(+), 597 deletions(-) diff --git a/packages/o-spreadsheet-engine/src/helpers/misc.ts b/packages/o-spreadsheet-engine/src/helpers/misc.ts index dd240b4e4e..ac070506bd 100644 --- a/packages/o-spreadsheet-engine/src/helpers/misc.ts +++ b/packages/o-spreadsheet-engine/src/helpers/misc.ts @@ -1,4 +1,5 @@ import { NEWLINE } from "../constants"; +import { DebouncedFunction, Lazy, UID } from "../types"; /** * Compares n objects. @@ -181,6 +182,9 @@ export class TokenizingChars { return true; } } + +const O_SPREADSHEET_LINK_PREFIX = "o-spreadsheet://"; + /** * This helper function can be used as a type guard when filtering arrays. * const foo: number[] = [1, 2, undefined, 4].filter(isDefined) @@ -188,3 +192,321 @@ export class TokenizingChars { export function isDefined(argument: T | undefined): argument is T { return argument !== undefined; } +export function isSheetUrl(url: string) { + return url.startsWith(O_SPREADSHEET_LINK_PREFIX); +} + +export function buildSheetLink(sheetId: UID) { + return `${O_SPREADSHEET_LINK_PREFIX}${sheetId}`; +} + +/** + * Parse a sheet link and return the sheet id + */ +export function parseSheetUrl(sheetLink: string) { + if (sheetLink.startsWith(O_SPREADSHEET_LINK_PREFIX)) { + return sheetLink.slice(O_SPREADSHEET_LINK_PREFIX.length); + } + throw new Error(`${sheetLink} is not a valid sheet link`); +} + +export function isNotNull(argument: T | null): argument is T { + return argument !== null; +} + +/** + * Check if all the values of an object, and all the values of the objects inside of it, are undefined. + */ +export function isObjectEmptyRecursive(argument: T | undefined): boolean { + if (argument === undefined) return true; + return Object.values(argument).every((value) => + typeof value === "object" ? isObjectEmptyRecursive(value) : !value + ); +} + +/** + * Returns a function, that, as long as it continues to be invoked, will not + * be triggered. The function will be called after it stops being called for + * N milliseconds. If `immediate` is passed, trigger the function on the + * leading edge, instead of the trailing. + * + * Also decorate the argument function with two methods: stopDebounce and isDebouncePending. + * + * Inspired by https://davidwalsh.name/javascript-debounce-function + */ +export function debounce void>( + func: T, + wait: number, + immediate?: boolean +): DebouncedFunction { + let timeout: any | undefined = undefined; + const debounced = function (this: any): void { + const context = this; + const args = Array.from(arguments); + function later() { + timeout = undefined; + if (!immediate) { + func.apply(context, args); + } + } + const callNow = immediate && !timeout; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + if (callNow) { + func.apply(context, args); + } + }; + debounced.isDebouncePending = () => timeout !== undefined; + debounced.stopDebounce = () => { + clearTimeout(timeout); + }; + return debounced as DebouncedFunction; +} + +/** + * Creates a batched version of a callback so that all calls to it in the same + * microtick will only call the original callback once. + * + * @param callback the callback to batch + * @returns a batched version of the original callback + * + * Copied from odoo/owl repo. + */ +export function batched(callback: () => void): () => void { + let scheduled = false; + return async (...args) => { + if (!scheduled) { + scheduled = true; + await Promise.resolve(); + scheduled = false; + callback(...args); + } + }; +} + +/* + * Concatenate an array of strings. + */ +export function concat(chars: string[]): string { + // ~40% faster than chars.join("") + let output = ""; + for (let i = 0, len = chars.length; i < len; i++) { + output += chars[i]; + } + return output; +} + +/** + * Lazy value computed by the provided function. + */ +export function lazy(fn: (() => T) | T): Lazy { + let isMemoized = false; + let memo: T | undefined; + const lazyValue = () => { + if (!isMemoized) { + memo = fn instanceof Function ? fn() : fn; + isMemoized = true; + } + return memo!; + }; + lazyValue.map = (callback) => lazy(() => callback(lazyValue())); + return lazyValue as Lazy; +} + +/** + * Find the next defined value after the given index in an array of strings. If there is no defined value + * after the index, return the closest defined value before the index. Return an empty string if no + * defined value was found. + * + */ +export function findNextDefinedValue(arr: string[], index: number): string { + let value = arr.slice(index).find((val) => val); + if (!value) { + value = arr + .slice(0, index) + .reverse() + .find((val) => val); + } + return value || ""; +} + +/** + * Check if the given array contains all the values of the other array. + * It makes the assumption that both array do not contain duplicates. + */ +export function includesAll(arr: T[], values: T[]): boolean { + if (arr.length < values.length) { + return false; + } + + const set = new Set(arr); + return values.every((value) => set.has(value)); +} + +/** + * Return an object with all the keys in the object that have a falsy value removed. + */ +export function removeFalsyAttributes(obj: T): T { + if (!obj) return obj; + const cleanObject = { ...obj }; + Object.keys(cleanObject).forEach((key) => !cleanObject[key] && delete cleanObject[key]); + return cleanObject; +} + +/** + * Determine if the numbers are consecutive. + */ +export function isConsecutive(iterable: Iterable): boolean { + const array = Array.from(iterable).sort((a, b) => a - b); // sort numerically rather than lexicographically + for (let i = 1; i < array.length; i++) { + if (array[i] - array[i - 1] !== 1) { + return false; + } + } + return true; +} + +/** + * Removes the specified indexes from the array. + * Sparse (empty) elements are transformed to undefined (unless their index is explicitly removed). + */ +export function removeIndexesFromArray(array: readonly T[], indexes: number[]): T[] { + const toRemove = new Set(indexes); + const newArray: T[] = []; + for (let i = 0; i < array.length; i++) { + if (!toRemove.has(i)) { + newArray.push(array[i]); + } + } + return newArray; +} + +export function insertItemsAtIndex(array: readonly T[], items: T[], index: number): T[] { + const newArray = [...array]; + newArray.splice(index, 0, ...items); + return newArray; +} + +export function replaceItemAtIndex(array: readonly T[], newItem: T, index: number): T[] { + const newArray = [...array]; + newArray[index] = newItem; + return newArray; +} + +export function trimContent(content: string): string { + const contentLines = content.split("\n"); + return contentLines.map((line) => line.replace(/\s+/g, " ").trim()).join("\n"); +} + +export function isNumberBetween(value: number, min: number, max: number): boolean { + if (min > max) { + return isNumberBetween(value, max, min); + } + return value >= min && value <= max; +} + +/** + * Get a Regex for the find & replace that matches the given search string and options. + */ +export function getSearchRegex(searchStr: string, searchOptions: SearchOptions): RegExp { + let searchValue = engineEscapeRegExp(searchStr); + const flags = !searchOptions.matchCase ? "i" : ""; + if (searchOptions.exactMatch) { + searchValue = `^${searchValue}$`; + } + return RegExp(searchValue, flags); +} + +/** + * Alternative to Math.max that works with large arrays. + * Typically useful for arrays bigger than 100k elements. + */ +export function largeMax(array: number[]) { + let len = array.length; + + if (len < 100_000) return Math.max(...array); + + let max: number = -Infinity; + while (len--) { + max = array[len] > max ? array[len] : max; + } + return max; +} + +/** + * Alternative to Math.min that works with large arrays. + * Typically useful for arrays bigger than 100k elements. + */ +export function largeMin(array: number[]) { + let len = array.length; + + if (len < 100_000) return Math.min(...array); + + let min: number = +Infinity; + while (len--) { + min = array[len] < min ? array[len] : min; + } + return min; +} + +/** + * Remove duplicates from an array. + * + * @param array The array to remove duplicates from. + * @param cb A callback to get an element value. + */ +export function removeDuplicates(array: T[], cb: (a: T) => any = (a) => a): T[] { + const set = new Set(); + return array.filter((item) => { + const key = cb(item); + if (set.has(key)) { + return false; + } + set.add(key); + return true; + }); +} + +/** + * Similar to transposing and array, but with POJOs instead of arrays. Useful, for example, when manipulating + * a POJO grid[col][row] and you want to transpose it to grid[row][col]. + * + * The resulting object is created such as result[key1][key2] = pojo[key2][key1] + */ +export function transpose2dPOJO( + pojo: Record> +): Record> { + const result: Record> = {}; + for (const key in pojo) { + for (const subKey in pojo[key]) { + if (!result[subKey]) { + result[subKey] = {}; + } + result[subKey][key] = pojo[key][subKey]; + } + } + return result; +} + +export function getUniqueText( + text: string, + texts: string[], + options: { + compute?: (text: string, increment: number) => string; + start?: number; + computeFirstOne?: boolean; + } = {} +): string { + const compute = options.compute ?? ((text, i) => `${text} (${i})`); + const computeFirstOne = options.computeFirstOne ?? false; + let i = options.start ?? 1; + let newText = computeFirstOne ? compute(text, i) : text; + while (texts.includes(newText)) { + newText = compute(text, i++); + } + return newText; +} + +export function isFormula(content: string): boolean { + return content.startsWith("=") || content.startsWith("+"); +} diff --git a/src/actions/menu_items_actions.ts b/src/actions/menu_items_actions.ts index aaa336b4fb..ddee2b198f 100644 --- a/src/actions/menu_items_actions.ts +++ b/src/actions/menu_items_actions.ts @@ -1,5 +1,3 @@ -import { Style } from "@odoo/o-spreadsheet-engine"; -import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { CellPopoverStore } from "../components/popover"; import { getPivotTooBigErrorMessage } from "../components/translations_terms"; import { @@ -10,15 +8,7 @@ import { import { parseOSClipboardContent } from "../helpers/clipboard/clipboard_helpers"; import { getSmartChartDefinition } from "../helpers/figures/charts/smart_chart_engine"; import { centerFigurePosition, getMaxFigureSize } from "../helpers/figures/figure/figure"; -import { - areZonesContinuous, - getZoneArea, - isConsecutive, - isEqual, - largeMax, - largeMin, - numberToLetters, -} from "../helpers/index"; +import { areZonesContinuous, getZoneArea, isEqual, numberToLetters } from "../helpers/index"; import { DEFAULT_TABLE_CONFIG } from "../helpers/table_presets"; import { interactivePaste, interactivePasteFromOS } from "../helpers/ui/paste_interactive"; import { interactiveCreateTable } from "../helpers/ui/table_interactive"; diff --git a/src/actions/sheet_actions.ts b/src/actions/sheet_actions.ts index a941ef50f0..cf52275fb7 100644 --- a/src/actions/sheet_actions.ts +++ b/src/actions/sheet_actions.ts @@ -1,4 +1,5 @@ -import { buildSheetLink, markdownLink } from "../helpers"; +import { buildSheetLink } from "@odoo/o-spreadsheet-engine"; +import { markdownLink } from "../helpers"; import { _t } from "../translation"; import { ActionSpec } from "./action"; diff --git a/src/clipboard_handlers/tables_clipboard.ts b/src/clipboard_handlers/tables_clipboard.ts index d80cb819ba..82ae9f6191 100644 --- a/src/clipboard_handlers/tables_clipboard.ts +++ b/src/clipboard_handlers/tables_clipboard.ts @@ -1,5 +1,3 @@ -import { Border, CellPosition, HeaderIndex, Style, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { isZoneInside, removeFalsyAttributes, zoneToDimension } from "../helpers"; import { ClipboardCellData, ClipboardCopyOptions, diff --git a/src/collaborative/session.ts b/src/collaborative/session.ts index 4eb8c7f792..1490cf65b1 100644 --- a/src/collaborative/session.ts +++ b/src/collaborative/session.ts @@ -1,6 +1,6 @@ +import { debounce } from "@odoo/o-spreadsheet-engine"; import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { EventBus } from "../helpers/event_bus"; -import { debounce } from "../helpers/misc"; import { UuidGenerator } from "../helpers/uuid"; import { SelectiveHistory as RevisionLog } from "../history/selective_history"; import { CoreCommand, HistoryChange, WorkbookData } from "../types"; diff --git a/src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store.ts b/src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store.ts index 75b4b6b929..c647bba50f 100644 --- a/src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store.ts +++ b/src/components/bottom_bar/bottom_bar_statistic/aggregate_statistics_store.ts @@ -1,7 +1,8 @@ +import { lazy } from "@odoo/o-spreadsheet-engine"; import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { sum } from "../../../functions/helper_math"; import { average, countAny, countNumbers, max, min } from "../../../functions/helper_statistical"; -import { lazy, memoize, recomputeZones } from "../../../helpers"; +import { memoize, recomputeZones } from "../../../helpers"; import { Get } from "../../../store_engine"; import { SpreadsheetStore } from "../../../stores"; import { _t } from "../../../translation"; diff --git a/src/components/composer/composer/abstract_composer_store.ts b/src/components/composer/composer/abstract_composer_store.ts index 0a4cbec920..f8fb1571e7 100644 --- a/src/components/composer/composer/abstract_composer_store.ts +++ b/src/components/composer/composer/abstract_composer_store.ts @@ -1,17 +1,3 @@ -import { - CellPosition, - Color, - functionRegistry, - FunctionResultObject, - HeaderIndex, - Highlight, - isMatrix, - Matrix, - UID, - UnboundedZone, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { Direction } from "@odoo/o-spreadsheet-engine/types"; import { DEFAULT_TOKEN_COLOR, tokenColors } from "../../../constants"; import { composerTokenize, EnrichedToken } from "../../../formulas/composer_tokenizer"; import { AST, iterateAstNodes, parseTokens } from "../../../formulas/parser"; @@ -21,12 +7,10 @@ import { KeepLast } from "../../../helpers/concurrency"; import { clip, colors, - concat, formatValue, fuzzyLookup, getZoneArea, isEqual, - isFormula, isNumber, isSheetNameEqual, positionToZone, diff --git a/src/components/composer/composer/cell_composer_store.ts b/src/components/composer/composer/cell_composer_store.ts index f935efd512..f4df85ce52 100644 --- a/src/components/composer/composer/cell_composer_store.ts +++ b/src/components/composer/composer/cell_composer_store.ts @@ -1,5 +1,3 @@ -import { CellPosition, isMatrix } from "@odoo/o-spreadsheet-engine"; -import { Direction } from "@odoo/o-spreadsheet-engine/types"; import { prettify } from "../../../formulas/formula_formatter"; import { parseTokens } from "../../../formulas/parser"; import { isMultipleElementMatrix, toScalar } from "../../../functions/helper_matrices"; @@ -7,7 +5,6 @@ import { parseLiteral } from "../../../helpers/cells"; import { formatValue, isDateTimeFormat, - isFormula, markdownLink, numberToString, parseDateTime, diff --git a/src/components/composer/composer/composer.ts b/src/components/composer/composer/composer.ts index fd46f4db4a..c6943dc4b1 100644 --- a/src/components/composer/composer/composer.ts +++ b/src/components/composer/composer/composer.ts @@ -1,9 +1,7 @@ import { Component, onMounted, onWillUnmount, useEffect, useRef, useState } from "@odoo/owl"; import { NEWLINE, SCROLLBAR_WIDTH } from "../../../constants"; -import { debounce, isFormula, setColorAlpha } from "../../../helpers/index"; +import { setColorAlpha } from "../../../helpers/index"; -import { deepEquals, FunctionDescription, functionRegistry } from "@odoo/o-spreadsheet-engine"; -import { Direction } from "@odoo/o-spreadsheet-engine/types"; import { EnrichedToken } from "../../../formulas/composer_tokenizer"; import { argTargeting } from "../../../functions/arguments"; import { Store, useStore } from "../../../store_engine"; diff --git a/src/components/composer/grid_composer/grid_composer.ts b/src/components/composer/grid_composer/grid_composer.ts index 8a40fa764d..b9fd50ff0a 100644 --- a/src/components/composer/grid_composer/grid_composer.ts +++ b/src/components/composer/grid_composer/grid_composer.ts @@ -1,13 +1,5 @@ -import { CellPosition, deepEquals } from "@odoo/o-spreadsheet-engine"; -import { Component, onWillUpdateProps } from "@odoo/owl"; import { SELECTION_BORDER_COLOR } from "../../../constants"; -import { - fontSizeInPixels, - getFullReference, - isFormula, - positionToZone, - toXC, -} from "../../../helpers"; +import { fontSizeInPixels, getFullReference, positionToZone, toXC } from "../../../helpers"; import { Store, useStore } from "../../../store_engine"; import { ComposerFocusType, DOMDimension, Rect, SpreadsheetChildEnv } from "../../../types/index"; import { getTextDecoration } from "../../helpers"; diff --git a/src/components/side_panel/chart/building_blocks/pie_hole_size/pie_hole_size.ts b/src/components/side_panel/chart/building_blocks/pie_hole_size/pie_hole_size.ts index 4b7b8236de..fdd170b46c 100644 --- a/src/components/side_panel/chart/building_blocks/pie_hole_size/pie_hole_size.ts +++ b/src/components/side_panel/chart/building_blocks/pie_hole_size/pie_hole_size.ts @@ -1,5 +1,6 @@ +import { debounce } from "@odoo/o-spreadsheet-engine"; import { Component } from "@odoo/owl"; -import { clip, debounce } from "../../../../../helpers"; +import { clip } from "../../../../../helpers"; import { SpreadsheetChildEnv } from "../../../../../types"; import { Section } from "../../../components/section/section"; diff --git a/src/components/side_panel/chart/funnel_chart_panel/funnel_chart_design_panel.ts b/src/components/side_panel/chart/funnel_chart_panel/funnel_chart_design_panel.ts index 4f755012ff..eedcc81605 100644 --- a/src/components/side_panel/chart/funnel_chart_panel/funnel_chart_design_panel.ts +++ b/src/components/side_panel/chart/funnel_chart_panel/funnel_chart_design_panel.ts @@ -1,6 +1,3 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { Component } from "@odoo/owl"; -import { replaceItemAtIndex } from "../../../../helpers"; import { getFunnelLabelColors } from "../../../../helpers/figures/charts/runtime"; import { _t } from "../../../../translation"; import { FunnelChartDefinition, FunnelChartRuntime } from "../../../../types/chart"; diff --git a/src/components/side_panel/find_and_replace/find_and_replace.ts b/src/components/side_panel/find_and_replace/find_and_replace.ts index 5b61ffce6a..7f27c4c553 100644 --- a/src/components/side_panel/find_and_replace/find_and_replace.ts +++ b/src/components/side_panel/find_and_replace/find_and_replace.ts @@ -1,3 +1,4 @@ +import { debounce } from "@odoo/o-spreadsheet-engine"; import { DebouncedFunction } from "@odoo/o-spreadsheet-engine/types"; import { Component, @@ -7,7 +8,7 @@ import { useRef, useState, } from "@odoo/owl"; -import { debounce, zoneToXc } from "../../../helpers"; +import { zoneToXc } from "../../../helpers"; import { Store, useLocalStore } from "../../../store_engine"; import { _t } from "../../../translation"; import { SpreadsheetChildEnv } from "../../../types/index"; diff --git a/src/components/side_panel/find_and_replace/find_and_replace_store.ts b/src/components/side_panel/find_and_replace/find_and_replace_store.ts index 1313fd7560..aad3080be4 100644 --- a/src/components/side_panel/find_and_replace/find_and_replace_store.ts +++ b/src/components/side_panel/find_and_replace/find_and_replace_store.ts @@ -1,9 +1,7 @@ -import { getSearchRegex, isInside, positionToZone } from "../../../helpers"; +import { isInside, positionToZone } from "../../../helpers"; import { HighlightProvider, HighlightStore } from "../../../stores/highlight_store"; import { Command } from "../../../types"; -import { CellPosition, Color, Highlight } from "@odoo/o-spreadsheet-engine"; -import { canonicalizeNumberContent } from "../../../helpers/locale"; import { Get } from "../../../store_engine"; import { SpreadsheetStore } from "../../../stores"; import { NotificationStore } from "../../../stores/notification_store"; diff --git a/src/components/spreadsheet/spreadsheet.ts b/src/components/spreadsheet/spreadsheet.ts index 9ac41b7bce..f5ebf3b721 100644 --- a/src/components/spreadsheet/spreadsheet.ts +++ b/src/components/spreadsheet/spreadsheet.ts @@ -1,17 +1,4 @@ -import { HeaderGroup, Pixel } from "@odoo/o-spreadsheet-engine"; -import { - Component, - onMounted, - onPatched, - onWillUnmount, - onWillUpdateProps, - useEffect, - useExternalListener, - useRef, - useSubEnv, -} from "@odoo/owl"; import { GROUP_LAYER_WIDTH, MAXIMAL_FREEZABLE_RATIO, SCROLLBAR_WIDTH } from "../../constants"; -import { batched } from "../../helpers"; import { ImageProvider } from "../../helpers/figures/images/image_provider"; import { Model } from "../../model"; import { Store, useStore, useStoreProvider } from "../../store_engine"; diff --git a/src/functions/module_text.ts b/src/functions/module_text.ts index 8914945af8..f8bdd67d58 100644 --- a/src/functions/module_text.ts +++ b/src/functions/module_text.ts @@ -1,5 +1,3 @@ -import { Arg, FunctionResultObject, Functions, Maybe } from "@odoo/o-spreadsheet-engine"; -import { escapeRegExp, formatValue, trimContent } from "../helpers"; import { _t } from "../translation"; import { CellErrorType, EvaluationError, NotAvailableError } from "../types/errors"; import { arg } from "./arguments"; diff --git a/src/helpers/chart_date.ts b/src/helpers/chart_date.ts index 5b6f8a3946..83f54230db 100644 --- a/src/helpers/chart_date.ts +++ b/src/helpers/chart_date.ts @@ -1,7 +1,5 @@ -import { Alias } from "@odoo/o-spreadsheet-engine"; -import type { TimeScaleOptions } from "chart.js"; import { DeepPartial } from "chart.js/dist/types/utils"; -import { largeMax, largeMin, parseDateTime } from "."; +import { parseDateTime } from "."; import { Format, Locale } from "../types"; // ----------------------------------------------------------------------------- diff --git a/src/helpers/figures/charts/chart_common.ts b/src/helpers/figures/charts/chart_common.ts index 131dc15479..1b5a8f5944 100644 --- a/src/helpers/figures/charts/chart_common.ts +++ b/src/helpers/figures/charts/chart_common.ts @@ -1,3 +1,4 @@ +import { largeMax } from "@odoo/o-spreadsheet-engine"; import { _t } from "../../../translation"; import { CommandResult, @@ -24,7 +25,6 @@ import { MAX_XLSX_POLYNOMIAL_DEGREE } from "../../../xlsx/constants"; import { ColorGenerator, relativeLuminance } from "../../color"; import { formatValue, humanizeNumber } from "../../format/format"; import { adaptStringRange } from "../../formulas"; -import { largeMax } from "../../misc"; import { createRange, duplicateRangeInDuplicatedSheet } from "../../range"; import { rangeReference } from "../../references"; import { getZoneArea, isFullRow, toUnboundedZone, zoneToDimension, zoneToXc } from "../../zones"; diff --git a/src/helpers/figures/charts/runtime/chart_data_extractor.ts b/src/helpers/figures/charts/runtime/chart_data_extractor.ts index 67aef2417d..0123c17400 100644 --- a/src/helpers/figures/charts/runtime/chart_data_extractor.ts +++ b/src/helpers/figures/charts/runtime/chart_data_extractor.ts @@ -1,3 +1,4 @@ +import { findNextDefinedValue } from "@odoo/o-spreadsheet-engine"; import { Point } from "chart.js"; import { ChartTerms } from "../../../../components/translations_terms"; import { getMovingAverageValues } from "../../../../functions/get_moving_average_values"; @@ -40,7 +41,7 @@ import { RadarChartDefinition } from "../../../../types/chart/radar_chart"; import { TreeMapChartDefinition } from "../../../../types/chart/tree_map_chart"; import { timeFormatLuxonCompatible } from "../../../chart_date"; import { isDateTimeFormat } from "../../../format/format"; -import { deepCopy, findNextDefinedValue, range } from "../../../misc"; +import { deepCopy, range } from "../../../misc"; import { isNumber } from "../../../numbers"; import { recomputeZones } from "../../../recompute_zones"; import { positions } from "../../../zones"; diff --git a/src/helpers/figures/charts/runtime/chartjs_scales.ts b/src/helpers/figures/charts/runtime/chartjs_scales.ts index 2b03cbcb52..9d7b219867 100644 --- a/src/helpers/figures/charts/runtime/chartjs_scales.ts +++ b/src/helpers/figures/charts/runtime/chartjs_scales.ts @@ -1,5 +1,3 @@ -import { isDefined } from "@odoo/o-spreadsheet-engine"; -import { LinearScaleOptions, ScaleChartOptions, Tick } from "chart.js"; import { DeepPartial } from "chart.js/dist/types/utils"; import { CHART_AXIS_TITLE_FONT_SIZE, @@ -31,7 +29,7 @@ import { RadarChartDefinition } from "../../../../types/chart/radar_chart"; import { getChartTimeOptions } from "../../../chart_date"; import { getColorScale } from "../../../color"; import { formatValue, humanizeNumber } from "../../../format/format"; -import { range, removeFalsyAttributes } from "../../../misc"; +import { range } from "../../../misc"; import { MOVING_AVERAGE_TREND_LINE_XAXIS_ID, TREND_LINE_XAXIS_ID, diff --git a/src/helpers/formulas.ts b/src/helpers/formulas.ts index e1f5c9b3f1..df4338c1ed 100644 --- a/src/helpers/formulas.ts +++ b/src/helpers/formulas.ts @@ -1,7 +1,4 @@ -import { RangeAdapter, UID } from "@odoo/o-spreadsheet-engine"; -import { rangeTokenize } from "../formulas"; import { Range } from "../types"; -import { concat } from "./misc"; import { createInvalidRange, createRangeFromXc, getRangeString } from "./range"; export function adaptFormulaStringRanges( defaultSheetId: string, diff --git a/src/helpers/links.ts b/src/helpers/links.ts index 2785710b64..424e664891 100644 --- a/src/helpers/links.ts +++ b/src/helpers/links.ts @@ -1,8 +1,9 @@ +import { parseSheetUrl } from "@odoo/o-spreadsheet-engine"; import { Link } from "@odoo/o-spreadsheet-engine/types"; import { Registry } from "../registries/registry"; import { _t } from "../translation"; import { CellValue, CommandResult, Getters, SpreadsheetChildEnv } from "../types"; -import { isMarkdownLink, isSheetUrl, isWebLink, parseMarkdownLink, parseSheetUrl } from "./misc"; +import { isMarkdownLink, isSheetUrl, isWebLink, parseMarkdownLink } from "./misc"; /** * Add the `https` prefix to the url if it's missing diff --git a/src/helpers/misc.ts b/src/helpers/misc.ts index 351dd9e531..f635cde860 100644 --- a/src/helpers/misc.ts +++ b/src/helpers/misc.ts @@ -1,9 +1,8 @@ //------------------------------------------------------------------------------ // Miscellaneous //------------------------------------------------------------------------------ -import { ConsecutiveIndexes, Style, UID } from "@odoo/o-spreadsheet-engine"; -import { escapeRegExp as engineEscapeRegExp } from "@odoo/o-spreadsheet-engine/helpers/misc"; -import { Cloneable, DebouncedFunction, Lazy } from "@odoo/o-spreadsheet-engine/types"; +import { ConsecutiveIndexes, Style } from "@odoo/o-spreadsheet-engine"; +import { Cloneable } from "@odoo/o-spreadsheet-engine/types"; export { escapeRegExp, getCanonicalSymbolName, @@ -188,288 +187,11 @@ export function parseMarkdownLink(str: string): { url: string; label: string } { }; } -const O_SPREADSHEET_LINK_PREFIX = "o-spreadsheet://"; - -export function isSheetUrl(url: string) { - return url.startsWith(O_SPREADSHEET_LINK_PREFIX); -} - -export function buildSheetLink(sheetId: UID) { - return `${O_SPREADSHEET_LINK_PREFIX}${sheetId}`; -} - -/** - * Parse a sheet link and return the sheet id - */ -export function parseSheetUrl(sheetLink: string) { - if (sheetLink.startsWith(O_SPREADSHEET_LINK_PREFIX)) { - return sheetLink.slice(O_SPREADSHEET_LINK_PREFIX.length); - } - throw new Error(`${sheetLink} is not a valid sheet link`); -} - -export function isNotNull(argument: T | null): argument is T { - return argument !== null; -} - -/** - * Check if all the values of an object, and all the values of the objects inside of it, are undefined. - */ -export function isObjectEmptyRecursive(argument: T | undefined): boolean { - if (argument === undefined) return true; - return Object.values(argument).every((value) => - typeof value === "object" ? isObjectEmptyRecursive(value) : !value - ); -} - -/** - * Returns a function, that, as long as it continues to be invoked, will not - * be triggered. The function will be called after it stops being called for - * N milliseconds. If `immediate` is passed, trigger the function on the - * leading edge, instead of the trailing. - * - * Also decorate the argument function with two methods: stopDebounce and isDebouncePending. - * - * Inspired by https://davidwalsh.name/javascript-debounce-function - */ -export function debounce void>( - func: T, - wait: number, - immediate?: boolean -): DebouncedFunction { - let timeout: any | undefined = undefined; - const debounced = function (this: any): void { - const context = this; - const args = Array.from(arguments); - function later() { - timeout = undefined; - if (!immediate) { - func.apply(context, args); - } - } - const callNow = immediate && !timeout; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - if (callNow) { - func.apply(context, args); - } - }; - debounced.isDebouncePending = () => timeout !== undefined; - debounced.stopDebounce = () => { - clearTimeout(timeout); - }; - return debounced as DebouncedFunction; -} - -/** - * Creates a batched version of a callback so that all calls to it in the same - * microtick will only call the original callback once. - * - * @param callback the callback to batch - * @returns a batched version of the original callback - * - * Copied from odoo/owl repo. - */ -export function batched(callback: () => void): () => void { - let scheduled = false; - return async (...args) => { - if (!scheduled) { - scheduled = true; - await Promise.resolve(); - scheduled = false; - callback(...args); - } - }; -} - -/* - * Concatenate an array of strings. - */ -export function concat(chars: string[]): string { - // ~40% faster than chars.join("") - let output = ""; - for (let i = 0, len = chars.length; i < len; i++) { - output += chars[i]; - } - return output; -} - -/** - * Lazy value computed by the provided function. - */ -export function lazy(fn: (() => T) | T): Lazy { - let isMemoized = false; - let memo: T | undefined; - const lazyValue = () => { - if (!isMemoized) { - memo = fn instanceof Function ? fn() : fn; - isMemoized = true; - } - return memo!; - }; - lazyValue.map = (callback) => lazy(() => callback(lazyValue())); - return lazyValue as Lazy; -} - -/** - * Find the next defined value after the given index in an array of strings. If there is no defined value - * after the index, return the closest defined value before the index. Return an empty string if no - * defined value was found. - * - */ -export function findNextDefinedValue(arr: string[], index: number): string { - let value = arr.slice(index).find((val) => val); - if (!value) { - value = arr - .slice(0, index) - .reverse() - .find((val) => val); - } - return value || ""; -} - /** Get index of first header added by an ADD_COLUMNS_ROWS command */ export function getAddHeaderStartIndex(position: "before" | "after", base: number): number { return position === "after" ? base + 1 : base; } -/** - * Check if the given array contains all the values of the other array. - * It makes the assumption that both array do not contain duplicates. - */ -export function includesAll(arr: T[], values: T[]): boolean { - if (arr.length < values.length) { - return false; - } - - const set = new Set(arr); - return values.every((value) => set.has(value)); -} - -/** - * Return an object with all the keys in the object that have a falsy value removed. - */ -export function removeFalsyAttributes(obj: T): T { - if (!obj) return obj; - const cleanObject = { ...obj }; - Object.keys(cleanObject).forEach((key) => !cleanObject[key] && delete cleanObject[key]); - return cleanObject; -} - -/** - * Determine if the numbers are consecutive. - */ -export function isConsecutive(iterable: Iterable): boolean { - const array = Array.from(iterable).sort((a, b) => a - b); // sort numerically rather than lexicographically - for (let i = 1; i < array.length; i++) { - if (array[i] - array[i - 1] !== 1) { - return false; - } - } - return true; -} - -/** - * Removes the specified indexes from the array. - * Sparse (empty) elements are transformed to undefined (unless their index is explicitly removed). - */ -export function removeIndexesFromArray(array: readonly T[], indexes: number[]): T[] { - const toRemove = new Set(indexes); - const newArray: T[] = []; - for (let i = 0; i < array.length; i++) { - if (!toRemove.has(i)) { - newArray.push(array[i]); - } - } - return newArray; -} - -export function insertItemsAtIndex(array: readonly T[], items: T[], index: number): T[] { - const newArray = [...array]; - newArray.splice(index, 0, ...items); - return newArray; -} - -export function replaceItemAtIndex(array: readonly T[], newItem: T, index: number): T[] { - const newArray = [...array]; - newArray[index] = newItem; - return newArray; -} - -export function trimContent(content: string): string { - const contentLines = content.split("\n"); - return contentLines.map((line) => line.replace(/\s+/g, " ").trim()).join("\n"); -} - -export function isNumberBetween(value: number, min: number, max: number): boolean { - if (min > max) { - return isNumberBetween(value, max, min); - } - return value >= min && value <= max; -} - -/** - * Get a Regex for the find & replace that matches the given search string and options. - */ -export function getSearchRegex(searchStr: string, searchOptions: SearchOptions): RegExp { - let searchValue = engineEscapeRegExp(searchStr); - const flags = !searchOptions.matchCase ? "i" : ""; - if (searchOptions.exactMatch) { - searchValue = `^${searchValue}$`; - } - return RegExp(searchValue, flags); -} - -/** - * Alternative to Math.max that works with large arrays. - * Typically useful for arrays bigger than 100k elements. - */ -export function largeMax(array: number[]) { - let len = array.length; - - if (len < 100_000) return Math.max(...array); - - let max: number = -Infinity; - while (len--) { - max = array[len] > max ? array[len] : max; - } - return max; -} - -/** - * Alternative to Math.min that works with large arrays. - * Typically useful for arrays bigger than 100k elements. - */ -export function largeMin(array: number[]) { - let len = array.length; - - if (len < 100_000) return Math.min(...array); - - let min: number = +Infinity; - while (len--) { - min = array[len] < min ? array[len] : min; - } - return min; -} - -/** - * Remove duplicates from an array. - * - * @param array The array to remove duplicates from. - * @param cb A callback to get an element value. - */ -export function removeDuplicates(array: T[], cb: (a: T) => any = (a) => a): T[] { - const set = new Set(); - return array.filter((item) => { - const key = cb(item); - if (set.has(key)) { - return false; - } - set.add(key); - return true; - }); -} - /** * Similar to transposing and array, but with POJOs instead of arrays. Useful, for example, when manipulating * a POJO grid[col][row] and you want to transpose it to grid[row][col]. diff --git a/src/helpers/pivot/pivot_helpers.ts b/src/helpers/pivot/pivot_helpers.ts index 070e876bfc..557199dc64 100644 --- a/src/helpers/pivot/pivot_helpers.ts +++ b/src/helpers/pivot/pivot_helpers.ts @@ -1,3 +1,4 @@ +import { getUniqueText } from "@odoo/o-spreadsheet-engine"; import { countUnique, sum } from "../../functions/helper_math"; import { average, countAny, max, min } from "../../functions/helper_statistical"; import { @@ -24,7 +25,6 @@ import { PivotSortedColumn, PivotTableCell, } from "../../types/pivot"; -import { getUniqueText } from "../misc"; import { PivotRuntimeDefinition } from "./pivot_runtime_definition"; const AGGREGATOR_NAMES = { count: _t("Count"), diff --git a/src/helpers/pivot/pivot_presentation.ts b/src/helpers/pivot/pivot_presentation.ts index 2d909b05e3..00be6c3ec4 100644 --- a/src/helpers/pivot/pivot_presentation.ts +++ b/src/helpers/pivot/pivot_presentation.ts @@ -1,10 +1,3 @@ -import { - deepEquals, - FunctionResultObject, - handleError, - isMatrix, -} from "@odoo/o-spreadsheet-engine"; -import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { transposeMatrix } from "../../functions/helpers"; import { ModelConfig } from "../../model"; import { _t } from "../../translation"; @@ -18,7 +11,6 @@ import { PivotValueCell, } from "../../types"; import { CellErrorType, NotAvailableError } from "../../types/errors"; -import { removeDuplicates, transpose2dPOJO } from "../misc"; import { domainToColRowDomain, domainToString, diff --git a/src/helpers/pivot/table_spreadsheet_pivot.ts b/src/helpers/pivot/table_spreadsheet_pivot.ts index 6e9145469a..e8f65ab38e 100644 --- a/src/helpers/pivot/table_spreadsheet_pivot.ts +++ b/src/helpers/pivot/table_spreadsheet_pivot.ts @@ -1,5 +1,3 @@ -import { deepEquals, FunctionResultObject } from "@odoo/o-spreadsheet-engine"; -import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { DimensionTree, DimensionTreeNode, @@ -11,7 +9,6 @@ import { PivotTableRow, PivotVisibilityOptions, } from "../../types/pivot"; -import { lazy } from "../misc"; import { isParentDomain, sortPivotTree } from "./pivot_domain_helpers"; import { parseDimension, toNormalizedPivotValue } from "./pivot_helpers"; diff --git a/src/helpers/range.ts b/src/helpers/range.ts index e4386335ea..3e69ad16fa 100644 --- a/src/helpers/range.ts +++ b/src/helpers/range.ts @@ -1,13 +1,3 @@ -import { - ApplyRangeChange, - CellPosition, - ChangeType, - RangeAdapter, - UID, - UnboundedZone, - ZoneDimension, -} from "@odoo/o-spreadsheet-engine"; -import { Registry } from "../registries/registry"; import { AddColumnsRowsCommand, CoreCommand, @@ -23,7 +13,7 @@ import { } from "../types"; import { CellErrorType } from "../types/errors"; import { numberToLetters } from "./coordinates"; -import { getCanonicalSymbolName, groupConsecutive, largeMax, largeMin } from "./misc"; +import { getCanonicalSymbolName, groupConsecutive } from "./misc"; import { isRowReference, splitReference } from "./references"; import { isSheetNameEqual } from "./sheet"; import { diff --git a/src/history/operation.ts b/src/history/operation.ts index 5e7fc306bd..3221bb9291 100644 --- a/src/history/operation.ts +++ b/src/history/operation.ts @@ -1,6 +1,3 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { Lazy } from "@odoo/o-spreadsheet-engine/types"; -import { lazy } from "../helpers"; import { Transformation } from "../types"; /** diff --git a/src/index.ts b/src/index.ts index ea3adcdf53..df20987efb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,12 +75,10 @@ import { deepCopy, expandZoneOnInsertion, formatValue, - getUniqueText, isDateTime, isInside, isMarkdownLink, isNumber, - lazy, lettersToNumber, markdownLink, mergeContiguousZones, @@ -109,10 +107,8 @@ import { } from "./helpers/pivot/pivot_composer_helpers"; import { supportedPivotPositionalFormulaRegistry } from "./helpers/pivot/pivot_positional_formula_registry"; -import { deepEquals, isDefined, isMatrix } from "@odoo/o-spreadsheet-engine"; +import { deepEquals, getUniqueText, isDefined, isMatrix, lazy } from "@odoo/o-spreadsheet-engine"; -import { ZoomableChartJsComponent } from "./components/figures/chart/chartJs/zoomable_chart/zoomable_chartjs"; -import { ChartDashboardMenu } from "./components/figures/chart/chart_dashboard_menu/chart_dashboard_menu"; import { FullScreenChart } from "./components/full_screen_chart/full_screen_chart"; import { PivotHTMLRenderer } from "./components/pivot_html_renderer/pivot_html_renderer"; import { ComboChartDesignPanel } from "./components/side_panel/chart/combo_chart/combo_chart_design_panel"; diff --git a/src/migrations/migration_steps.ts b/src/migrations/migration_steps.ts index f2b75aaae7..6c3dd48f48 100644 --- a/src/migrations/migration_steps.ts +++ b/src/migrations/migration_steps.ts @@ -1,6 +1,4 @@ -import { Zone } from "@odoo/o-spreadsheet-engine"; -import { BACKGROUND_CHART_COLOR, FORMULA_REF_IDENTIFIER } from "../constants"; -import { getItemId, getUniqueText, sanitizeSheetName } from "../helpers"; +import { getItemId, sanitizeSheetName } from "../helpers"; import { toXC } from "../helpers/coordinates"; import { getMaxObjectId } from "../helpers/pivot/pivot_helpers"; import { DEFAULT_TABLE_CONFIG } from "../helpers/table_presets"; diff --git a/src/model.ts b/src/model.ts index c733abd12f..599aec3ecb 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1,9 +1,10 @@ +import { lazy } from "@odoo/o-spreadsheet-engine"; import { LocalTransportService } from "./collaborative/local_transport_service"; import { ReadonlyTransportFilter } from "./collaborative/readonly_transport_filter"; import { Session } from "./collaborative/session"; import { DEFAULT_REVISION_ID } from "./constants"; import { EventBus } from "./helpers/event_bus"; -import { UuidGenerator, deepCopy, lazy } from "./helpers/index"; +import { UuidGenerator, deepCopy } from "./helpers/index"; import { buildRevisionLog } from "./history/factory"; import { createEmptyExcelWorkbookData, diff --git a/src/plugins/core/borders.ts b/src/plugins/core/borders.ts index ae8ac333c4..48fb9448b6 100644 --- a/src/plugins/core/borders.ts +++ b/src/plugins/core/borders.ts @@ -1,24 +1,9 @@ -import { - ApplyRangeChange, - Border, - BorderData, - BorderDescr, - CellPosition, - Color, - deepEquals, - HeaderIndex, - UID, - UnboundedZone, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { PositionMap } from "../../helpers/cells/position_map"; import { deepCopy, getItemId, intersection, positionToZone, recomputeZones, - removeFalsyAttributes, toZone, } from "../../helpers/index"; import { adjacent, overlap, splitIfAdjacent, zoneToXc } from "../../helpers/zones"; diff --git a/src/plugins/core/cell.ts b/src/plugins/core/cell.ts index 9e473b0703..10df1fef04 100644 --- a/src/plugins/core/cell.ts +++ b/src/plugins/core/cell.ts @@ -1,17 +1,3 @@ -import { - AdaptSheetName, - ApplyRangeChange, - CellPosition, - CompiledFormula, - deepEquals, - HeaderIndex, - RangeCompiledFormula, - Style, - UID, - UpdateCellData, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { DEFAULT_STYLE } from "../../constants"; import { compile, Token } from "../../formulas"; import { compileTokens } from "../../formulas/compiler"; import { isEvaluationError, toString } from "../../functions/helpers"; @@ -24,7 +10,6 @@ import { iterateItemIdsPositions, } from "../../helpers/data_normalization"; import { - concat, detectDateFormat, detectNumberFormat, isInside, diff --git a/src/plugins/core/header_grouping.ts b/src/plugins/core/header_grouping.ts index 6ebe8a1b2b..d09cf3be0b 100644 --- a/src/plugins/core/header_grouping.ts +++ b/src/plugins/core/header_grouping.ts @@ -1,12 +1,3 @@ -import { HeaderGroup, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { - deepCopy, - getAddHeaderStartIndex, - isConsecutive, - moveHeaderIndexesOnHeaderAddition, - moveHeaderIndexesOnHeaderDeletion, - range, -} from "../../helpers"; import { CommandResult, CoreCommand, ExcelWorkbookData, WorkbookData } from "../../types"; import { getSheetDataHeader } from "../../xlsx/helpers/misc"; diff --git a/src/plugins/core/header_size.ts b/src/plugins/core/header_size.ts index d767a019ed..3f187602bf 100644 --- a/src/plugins/core/header_size.ts +++ b/src/plugins/core/header_size.ts @@ -1,6 +1,4 @@ -import { HeaderIndex, Pixel, UID } from "@odoo/o-spreadsheet-engine"; -import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../constants"; -import { deepCopy, getAddHeaderStartIndex, range, removeIndexesFromArray } from "../../helpers"; +import { deepCopy, getAddHeaderStartIndex, range } from "../../helpers"; import { Command, ExcelWorkbookData, WorkbookData } from "../../types"; import { Dimension } from "@odoo/o-spreadsheet-engine/types"; diff --git a/src/plugins/core/header_visibility.ts b/src/plugins/core/header_visibility.ts index 140e6e4cef..7f852f3a24 100644 --- a/src/plugins/core/header_visibility.ts +++ b/src/plugins/core/header_visibility.ts @@ -1,13 +1,4 @@ -import { ConsecutiveIndexes, HeaderIndex, UID } from "@odoo/o-spreadsheet-engine"; -import { Dimension } from "@odoo/o-spreadsheet-engine/types"; -import { - deepCopy, - getAddHeaderStartIndex, - includesAll, - largeMax, - largeMin, - range, -} from "../../helpers"; +import { deepCopy, getAddHeaderStartIndex, range } from "../../helpers"; import { Command, CommandResult, ExcelWorkbookData, WorkbookData } from "../../types"; import { CorePlugin } from "../core_plugin"; diff --git a/src/plugins/core/sheet.ts b/src/plugins/core/sheet.ts index 515441175e..8bcb4a2781 100644 --- a/src/plugins/core/sheet.ts +++ b/src/plugins/core/sheet.ts @@ -1,3 +1,4 @@ +import { includesAll, largeMax, largeMin } from "@odoo/o-spreadsheet-engine"; import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { createDefaultRows, @@ -6,12 +7,9 @@ import { getNextSheetName, getUnquotedSheetName, groupConsecutive, - includesAll, isColorValid, isZoneInside, isZoneValid, - largeMax, - largeMin, range, toCartesian, } from "../../helpers/index"; @@ -30,8 +28,6 @@ import { UpdateCellPositionCommand, WorkbookData, } from "../../types/index"; -import { CorePlugin } from "../core_plugin"; - interface SheetState { readonly sheets: Record; readonly orderedSheetIds: UID[]; diff --git a/src/plugins/core/table_style.ts b/src/plugins/core/table_style.ts index ff359dcb2d..47be39cabb 100644 --- a/src/plugins/core/table_style.ts +++ b/src/plugins/core/table_style.ts @@ -1,4 +1,5 @@ -import { getUniqueText, toHex } from "../../helpers"; +import { getUniqueText } from "@odoo/o-spreadsheet-engine"; +import { toHex } from "../../helpers"; import { DEFAULT_TABLE_CONFIG, TABLE_PRESETS, diff --git a/src/plugins/ui_core_views/cell_evaluation/evaluator.ts b/src/plugins/ui_core_views/cell_evaluation/evaluator.ts index cd397a55a5..c186fd7aa3 100644 --- a/src/plugins/ui_core_views/cell_evaluation/evaluator.ts +++ b/src/plugins/ui_core_views/cell_evaluation/evaluator.ts @@ -1,9 +1,9 @@ +import { lazy } from "@odoo/o-spreadsheet-engine"; import { compile } from "../../../formulas"; import { matrixMap } from "../../../functions/helpers"; import { aggregatePositionsToZones, excludeTopLeft, - lazy, positionToZone, toXC, union, diff --git a/src/plugins/ui_core_views/evaluation_conditional_format.ts b/src/plugins/ui_core_views/evaluation_conditional_format.ts index b870ca00cf..2486871d83 100644 --- a/src/plugins/ui_core_views/evaluation_conditional_format.ts +++ b/src/plugins/ui_core_views/evaluation_conditional_format.ts @@ -1,17 +1,8 @@ -import { - CellPosition, - DataBarFill, - HeaderIndex, - Style, - UID, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { Lazy } from "@odoo/o-spreadsheet-engine/types"; import { compile } from "../../formulas"; import { isMultipleElementMatrix, toScalar } from "../../functions/helper_matrices"; import { parseLiteral } from "../../helpers/cells"; import { colorNumberToHex, getColorScale, isInside, percentile } from "../../helpers/index"; -import { clip, largeMax, largeMin, lazy } from "../../helpers/misc"; +import { clip } from "../../helpers/misc"; import { criterionEvaluatorRegistry } from "../../registries/criterion_registry"; import { CellIsRule, diff --git a/src/plugins/ui_core_views/evaluation_data_validation.ts b/src/plugins/ui_core_views/evaluation_data_validation.ts index f2f3035957..782f062e5b 100644 --- a/src/plugins/ui_core_views/evaluation_data_validation.ts +++ b/src/plugins/ui_core_views/evaluation_data_validation.ts @@ -1,19 +1,17 @@ -import { CellPosition, HeaderIndex, Matrix, Style, UID } from "@odoo/o-spreadsheet-engine"; -import { Lazy, Offset } from "@odoo/o-spreadsheet-engine/types"; import { DVTerms } from "../../components/translations_terms"; import { GRAY_200 } from "../../constants"; import { compile } from "../../formulas"; import { isMultipleElementMatrix, toScalar } from "../../functions/helper_matrices"; -import { chipTextColor, getCellPositionsInRanges, isInside, lazy, positions } from "../../helpers"; +import { chipTextColor, getCellPositionsInRanges, isInside, positions } from "../../helpers"; import { parseLiteral } from "../../helpers/cells"; import { criterionEvaluatorRegistry } from "../../registries/criterion_registry"; import { CellValue, CellValueType, - DEFAULT_LOCALE, DataValidationCriterion, DataValidationCriterionType, DataValidationRule, + DEFAULT_LOCALE, EvaluatedCriterion, } from "../../types"; import { CoreViewCommand, invalidateEvaluationCommands } from "../../types/commands"; diff --git a/src/plugins/ui_core_views/header_sizes_ui.ts b/src/plugins/ui_core_views/header_sizes_ui.ts index c3bd04095a..20b90fc28a 100644 --- a/src/plugins/ui_core_views/header_sizes_ui.ts +++ b/src/plugins/ui_core_views/header_sizes_ui.ts @@ -1,13 +1,9 @@ -import { CellPosition, HeaderIndex, Pixel, UID } from "@odoo/o-spreadsheet-engine"; -import { DEFAULT_CELL_HEIGHT } from "../../constants"; import { deepCopy, getAddHeaderStartIndex, getDefaultCellHeight, - insertItemsAtIndex, positions, range, - removeIndexesFromArray, } from "../../helpers"; import { AnchorOffset, Command } from "../../types"; diff --git a/src/plugins/ui_core_views/pivot_ui.ts b/src/plugins/ui_core_views/pivot_ui.ts index a18209341c..3687980bed 100644 --- a/src/plugins/ui_core_views/pivot_ui.ts +++ b/src/plugins/ui_core_views/pivot_ui.ts @@ -1,16 +1,7 @@ -import { - CellPosition, - deepEquals, - FunctionResultObject, - isMatrix, - UID, -} from "@odoo/o-spreadsheet-engine"; -import { SortDirection } from "@odoo/o-spreadsheet-engine/types"; import { Token } from "../../formulas"; import { astToFormula } from "../../formulas/formula_formatter"; import { toScalar } from "../../functions/helper_matrices"; import { toBoolean } from "../../functions/helpers"; -import { getUniqueText } from "../../helpers"; import { getFirstPivotFunction, getNumberOfPivotFunctions, diff --git a/src/plugins/ui_feature/automatic_sum.ts b/src/plugins/ui_feature/automatic_sum.ts index e6a120a584..25460335c9 100644 --- a/src/plugins/ui_feature/automatic_sum.ts +++ b/src/plugins/ui_feature/automatic_sum.ts @@ -1,12 +1,8 @@ -import { HeaderIndex, Position, Sheet, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { groupConsecutive, isDateTimeFormat, isInside, isOneDimensional, - largeMax, - largeMin, positions, range, union, diff --git a/src/plugins/ui_feature/cell_computed_style.ts b/src/plugins/ui_feature/cell_computed_style.ts index 3a6d244ae6..fc26f7c143 100644 --- a/src/plugins/ui_feature/cell_computed_style.ts +++ b/src/plugins/ui_feature/cell_computed_style.ts @@ -1,7 +1,5 @@ -import { Border, CellPosition, Style, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { LINK_COLOR } from "../../constants"; import { PositionMap } from "../../helpers/cells/position_map"; -import { isObjectEmptyRecursive, positionToZone, removeFalsyAttributes } from "../../helpers/index"; +import { positionToZone } from "../../helpers/index"; import { Command, invalidateBordersCommands, diff --git a/src/plugins/ui_feature/data_cleanup.ts b/src/plugins/ui_feature/data_cleanup.ts index cce90dc625..b89804d22f 100644 --- a/src/plugins/ui_feature/data_cleanup.ts +++ b/src/plugins/ui_feature/data_cleanup.ts @@ -1,6 +1,4 @@ -import { deepEquals, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { CellClipboardHandler } from "../../clipboard_handlers/cell_clipboard"; -import { positions, range, recomputeZones, trimContent, zoneToDimension } from "../../helpers"; +import { positions, range, recomputeZones, zoneToDimension } from "../../helpers"; import { getClipboardDataPositions } from "../../helpers/clipboard/clipboard_helpers"; import { _t } from "../../translation"; import { Command, CommandResult, RemoveDuplicatesCommand } from "../../types/index"; diff --git a/src/plugins/ui_feature/insert_pivot.ts b/src/plugins/ui_feature/insert_pivot.ts index a534157e2d..ce3e2f7a22 100644 --- a/src/plugins/ui_feature/insert_pivot.ts +++ b/src/plugins/ui_feature/insert_pivot.ts @@ -1,6 +1,4 @@ -import { CellPosition, HeaderIndex, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { PIVOT_TABLE_CONFIG } from "../../constants"; -import { getUniqueText, sanitizeSheetName } from "../../helpers"; +import { sanitizeSheetName } from "../../helpers"; import { createPivotFormula } from "../../helpers/pivot/pivot_helpers"; import { SpreadsheetPivotTable } from "../../helpers/pivot/table_spreadsheet_pivot"; import { getZoneArea, positionToZone } from "../../helpers/zones"; diff --git a/src/plugins/ui_feature/table_computed_style.ts b/src/plugins/ui_feature/table_computed_style.ts index 1a553ab61a..671b10a13e 100644 --- a/src/plugins/ui_feature/table_computed_style.ts +++ b/src/plugins/ui_feature/table_computed_style.ts @@ -1,6 +1,3 @@ -import { Border, CellPosition, Style, TableId, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import { lazy } from "../../helpers"; -import { PositionMap } from "../../helpers/cells/position_map"; import { getComputedTableStyle } from "../../helpers/table_helpers"; interface ComputedTableStyle { styles: Record>; diff --git a/src/plugins/ui_feature/ui_sheet.ts b/src/plugins/ui_feature/ui_sheet.ts index f154f4f568..84a833ab5e 100644 --- a/src/plugins/ui_feature/ui_sheet.ts +++ b/src/plugins/ui_feature/ui_sheet.ts @@ -1,19 +1,3 @@ -import { - CellPosition, - HeaderIndex, - Pixel, - Style, - UID, - VerticalAlign, - Zone, -} from "@odoo/o-spreadsheet-engine"; -import { - DATA_VALIDATION_CHIP_MARGIN, - DEFAULT_CELL_HEIGHT, - DEFAULT_VERTICAL_ALIGN, - MIN_CELL_TEXT_MARGIN, - PADDING_AUTORESIZE_HORIZONTAL, -} from "../../constants"; import { computeTextLinesHeight, computeTextWidth, @@ -21,7 +5,6 @@ import { getCellContentHeight, groupConsecutive, isEqual, - largeMax, positions, range, splitTextToWidth, diff --git a/src/plugins/ui_stateful/filter_evaluation.ts b/src/plugins/ui_stateful/filter_evaluation.ts index 2c9f61e22b..c53309226c 100644 --- a/src/plugins/ui_stateful/filter_evaluation.ts +++ b/src/plugins/ui_stateful/filter_evaluation.ts @@ -1,8 +1,5 @@ -import { CellPosition, FilterId, UID } from "@odoo/o-spreadsheet-engine"; -import { isMultipleElementMatrix, toScalar } from "../../functions/helper_matrices"; import { deepCopy, - getUniqueText, positions, range, toLowerCase, @@ -16,8 +13,8 @@ import { Command, CommandResult, CriterionFilter, - DEFAULT_LOCALE, DataFilterValue, + DEFAULT_LOCALE, ExcelFilterData, ExcelWorkbookData, Table, diff --git a/src/registries/auto_completes/data_validation_auto_complete.ts b/src/registries/auto_completes/data_validation_auto_complete.ts index 3f6f6e79d2..dc589b79d5 100644 --- a/src/registries/auto_completes/data_validation_auto_complete.ts +++ b/src/registries/auto_completes/data_validation_auto_complete.ts @@ -1,5 +1,6 @@ +import { isFormula } from "@odoo/o-spreadsheet-engine"; import { GRAY_200 } from "../../constants"; -import { chipTextColor, isFormula } from "../../helpers"; +import { chipTextColor } from "../../helpers"; import { autoCompleteProviders } from "./auto_complete_registry"; autoCompleteProviders.add("dataValidation", { diff --git a/src/registries/auto_completes/function_auto_complete.ts b/src/registries/auto_completes/function_auto_complete.ts index 5849cee0b8..42aa3b3153 100644 --- a/src/registries/auto_completes/function_auto_complete.ts +++ b/src/registries/auto_completes/function_auto_complete.ts @@ -1,7 +1,4 @@ -import { functionRegistry } from "@odoo/o-spreadsheet-engine"; -import { getHtmlContentFromPattern } from "../../components/helpers/html_content_helpers"; import { COMPOSER_ASSISTANT_COLOR } from "../../constants"; -import { isFormula } from "../../helpers"; import { autoCompleteProviders } from "./auto_complete_registry"; autoCompleteProviders.add("functions", { diff --git a/src/registries/criterion_registry.ts b/src/registries/criterion_registry.ts index cabaa6e651..dc190c5068 100644 --- a/src/registries/criterion_registry.ts +++ b/src/registries/criterion_registry.ts @@ -1,5 +1,3 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { DVTerms } from "../components/translations_terms"; import { tryToNumber } from "../functions/helpers"; import { DateTime, @@ -12,7 +10,6 @@ import { isDateBetween, isDateStrictlyAfter, isDateStrictlyBefore, - isNumberBetween, jsDateToRoundNumber, valueToDateNumber, } from "../helpers"; diff --git a/src/xlsx/conversion/sheet_conversion.ts b/src/xlsx/conversion/sheet_conversion.ts index 9579692325..9319a51eb8 100644 --- a/src/xlsx/conversion/sheet_conversion.ts +++ b/src/xlsx/conversion/sheet_conversion.ts @@ -1,14 +1,4 @@ -import { HeaderGroup } from "@odoo/o-spreadsheet-engine"; -import { Dimension } from "@odoo/o-spreadsheet-engine/types"; -import { - buildSheetLink, - largeMax, - markdownLink, - replaceNewLines, - splitReference, - toCartesian, - toXC, -} from "../../helpers"; +import { markdownLink, replaceNewLines, splitReference, toCartesian, toXC } from "../../helpers"; import { HeaderData, SheetData } from "../../types"; import { XLSXCell, diff --git a/src/xlsx/functions/charts.ts b/src/xlsx/functions/charts.ts index bb7627a3dc..4a4b435e8c 100644 --- a/src/xlsx/functions/charts.ts +++ b/src/xlsx/functions/charts.ts @@ -1,6 +1,4 @@ -import { Color } from "@odoo/o-spreadsheet-engine"; -import { CHART_AXIS_TITLE_FONT_SIZE, CHART_TITLE_FONT_SIZE } from "../../constants"; -import { ColorGenerator, largeMax, lightenColor, range } from "../../helpers"; +import { ColorGenerator, lightenColor, range } from "../../helpers"; import { chartMutedFontColor } from "../../helpers/figures/charts"; import { ExcelWorkbookData, FigureData } from "../../types"; import { ExcelChartDataset, ExcelChartDefinition, TitleDesign } from "../../types/chart/chart"; diff --git a/src/xlsx/functions/styles.ts b/src/xlsx/functions/styles.ts index 05fbd6682d..87b21acc3e 100644 --- a/src/xlsx/functions/styles.ts +++ b/src/xlsx/functions/styles.ts @@ -1,4 +1,4 @@ -import { isObjectEmptyRecursive } from "../../helpers"; +import { isObjectEmptyRecursive } from "@odoo/o-spreadsheet-engine"; import { XLSXBorder, XLSXBorderDescr, diff --git a/src/xlsx/functions/worksheet.ts b/src/xlsx/functions/worksheet.ts index 61c3904136..1d9e5b92f4 100644 --- a/src/xlsx/functions/worksheet.ts +++ b/src/xlsx/functions/worksheet.ts @@ -1,13 +1,9 @@ -import { HeaderIndex } from "@odoo/o-spreadsheet-engine"; -import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../constants"; import { isInside, isMarkdownLink, - isSheetUrl, isTextFormat, iterateItemIdsPositions, parseMarkdownLink, - parseSheetUrl, toXC, toZone, } from "../../helpers"; diff --git a/src/xlsx/helpers/xml_helpers.ts b/src/xlsx/helpers/xml_helpers.ts index 23c8701213..549489cbc0 100644 --- a/src/xlsx/helpers/xml_helpers.ts +++ b/src/xlsx/helpers/xml_helpers.ts @@ -1,6 +1,3 @@ -import { BorderDescr } from "@odoo/o-spreadsheet-engine"; -import { DEFAULT_FONT_SIZE } from "../../constants"; -import { concat } from "../../helpers"; import { ExcelWorkbookData } from "../../types"; import { XLSXBorder, diff --git a/src/xlsx/xlsx_reader.ts b/src/xlsx/xlsx_reader.ts index d06ef715e7..1ed4ce688b 100644 --- a/src/xlsx/xlsx_reader.ts +++ b/src/xlsx/xlsx_reader.ts @@ -1,5 +1,5 @@ +import { removeFalsyAttributes } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_REVISION_ID } from "../constants"; -import { removeFalsyAttributes } from "../helpers"; import { _t } from "../translation"; import { ImportedFiles, diff --git a/src/xlsx/xlsx_writer.ts b/src/xlsx/xlsx_writer.ts index eeb1e7dc03..77e70b40c4 100644 --- a/src/xlsx/xlsx_writer.ts +++ b/src/xlsx/xlsx_writer.ts @@ -1,5 +1,6 @@ +import { getUniqueText } from "@odoo/o-spreadsheet-engine"; import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../constants"; -import { escapeRegExp, getUniqueText, toZone, zoneToDimension } from "../helpers"; +import { escapeRegExp, toZone, zoneToDimension } from "../helpers"; import { ExcelSheetData, ExcelWorkbookData } from "../types"; import { XLSXExport, diff --git a/tests/autofill/autofill_plugin.test.ts b/tests/autofill/autofill_plugin.test.ts index ce6c596dcd..58a967e219 100644 --- a/tests/autofill/autofill_plugin.test.ts +++ b/tests/autofill/autofill_plugin.test.ts @@ -1,6 +1,6 @@ import "../test_helpers/helpers"; -import { buildSheetLink, toCartesian, toZone } from "../../src/helpers"; +import { toCartesian, toZone } from "../../src/helpers"; import { ConditionalFormat } from "../../src/types"; import { addDataValidation, @@ -32,10 +32,6 @@ import { XCToMergeCellMap, } from "../test_helpers/helpers"; -import { Border, DIRECTION, functionRegistry, Style } from "@odoo/o-spreadsheet-engine"; -import { Model } from "../../src"; -import { AutofillPlugin } from "../../src/plugins/ui_feature/autofill"; - let autoFill: AutofillPlugin; let model: Model; diff --git a/tests/borders/border_plugin.test.ts b/tests/borders/border_plugin.test.ts index 6c2ae57cc5..d8de997118 100644 --- a/tests/borders/border_plugin.test.ts +++ b/tests/borders/border_plugin.test.ts @@ -1,7 +1,4 @@ -import { BorderDescr } from "@odoo/o-spreadsheet-engine"; -import { DEFAULT_BORDER_DESC } from "../../src/constants"; import { toZone } from "../../src/helpers"; -import { removeFalsyAttributes } from "../../src/helpers/misc"; import { Model } from "../../src/model"; import { BordersPlugin } from "../../src/plugins/core"; import { CommandResult } from "../../src/types/index"; diff --git a/tests/cells/cell_plugin.test.ts b/tests/cells/cell_plugin.test.ts index 98a6fc2cd6..a717ba42de 100644 --- a/tests/cells/cell_plugin.test.ts +++ b/tests/cells/cell_plugin.test.ts @@ -1,7 +1,5 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { CoreCommand, CorePlugin, Model } from "../../src"; import { LINK_COLOR } from "../../src/constants"; -import { buildSheetLink, toZone } from "../../src/helpers"; +import { toZone } from "../../src/helpers"; import { urlRepresentation } from "../../src/helpers/links"; import { corePluginRegistry } from "../../src/plugins"; import { CellValueType, CommandResult } from "../../src/types"; diff --git a/tests/collaborative/collaborative_session.test.ts b/tests/collaborative/collaborative_session.test.ts index 6acb25715c..6c98a743ac 100644 --- a/tests/collaborative/collaborative_session.test.ts +++ b/tests/collaborative/collaborative_session.test.ts @@ -1,7 +1,7 @@ +import { lazy } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; import { Session } from "../../src/collaborative/session"; import { DEBOUNCE_TIME, MESSAGE_VERSION } from "../../src/constants"; -import { lazy } from "../../src/helpers"; import { buildRevisionLog } from "../../src/history/factory"; import { Client, CommandResult, WorkbookData } from "../../src/types"; import { MockTransportService } from "../__mocks__/transport_service"; diff --git a/tests/grid/grid_component.test.ts b/tests/grid/grid_component.test.ts index 09aff42000..f1b29ede00 100644 --- a/tests/grid/grid_component.test.ts +++ b/tests/grid/grid_component.test.ts @@ -1,5 +1,3 @@ -import { Align } from "@odoo/o-spreadsheet-engine"; -import { Spreadsheet, TransportService } from "../../src"; import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store"; import { ComposerFocusStore } from "../../src/components/composer/composer_focus_store"; import { resetTimeoutDuration } from "../../src/components/helpers/touch_scroll_hook"; @@ -19,7 +17,7 @@ import { MIN_CELL_TEXT_MARGIN, SCROLLBAR_WIDTH, } from "../../src/constants"; -import { buildSheetLink, toCartesian, toZone, zoneToXc } from "../../src/helpers"; +import { toCartesian, toZone, zoneToXc } from "../../src/helpers"; import { createEmptyWorkbookData } from "../../src/migrations/data"; import { Model } from "../../src/model"; import { ClipboardPlugin } from "../../src/plugins/ui_stateful"; diff --git a/tests/helpers/misc_helpers.test.ts b/tests/helpers/misc_helpers.test.ts index 23f34c55d1..2a205d82e8 100644 --- a/tests/helpers/misc_helpers.test.ts +++ b/tests/helpers/misc_helpers.test.ts @@ -1,14 +1,5 @@ -import { deepEquals } from "@odoo/o-spreadsheet-engine"; -import seedrandom from "seedrandom"; import { DateTime, deepCopy, UuidGenerator } from "../../src/helpers"; -import { - getUniqueText, - groupConsecutive, - isConsecutive, - lazy, - memoize, - range, -} from "../../src/helpers/misc"; +import { groupConsecutive, memoize, range } from "../../src/helpers/misc"; describe("Misc", () => { test("range", () => { diff --git a/tests/link/link_display_component.test.ts b/tests/link/link_display_component.test.ts index 87cc3f37d8..b90f2c815c 100644 --- a/tests/link/link_display_component.test.ts +++ b/tests/link/link_display_component.test.ts @@ -1,5 +1,5 @@ +import { buildSheetLink } from "@odoo/o-spreadsheet-engine"; import { Model, Spreadsheet } from "../../src"; -import { buildSheetLink } from "../../src/helpers"; import { clearCell, createSheet, diff --git a/tests/link/link_editor_component.test.ts b/tests/link/link_editor_component.test.ts index fb035d6e59..c487b243df 100644 --- a/tests/link/link_editor_component.test.ts +++ b/tests/link/link_editor_component.test.ts @@ -1,5 +1,5 @@ +import { buildSheetLink } from "@odoo/o-spreadsheet-engine"; import { Model } from "../../src"; -import { buildSheetLink } from "../../src/helpers"; import { DEFAULT_LOCALE } from "../../src/types"; import { CellValueType } from "../../src/types/cells"; import { diff --git a/tests/test_helpers/debug_helpers.ts b/tests/test_helpers/debug_helpers.ts index c410be1f13..492e63c8d1 100644 --- a/tests/test_helpers/debug_helpers.ts +++ b/tests/test_helpers/debug_helpers.ts @@ -1,6 +1,4 @@ -import { UID } from "@odoo/o-spreadsheet-engine"; -import { Model } from "../../src"; -import { concat, zoneToXc } from "../../src/helpers"; +import { zoneToXc } from "../../src/helpers"; import { Branch } from "../../src/history/branch"; import { Tree } from "../../src/history/tree"; import { getEvaluatedGrid } from "./getters_helpers"; diff --git a/tests/test_helpers/helpers.ts b/tests/test_helpers/helpers.ts index c4f2c07210..44d5b6a2ef 100644 --- a/tests/test_helpers/helpers.ts +++ b/tests/test_helpers/helpers.ts @@ -1,5 +1,3 @@ -import { CellPosition, Highlight, Matrix, Style, UID, Zone } from "@odoo/o-spreadsheet-engine"; -import type { ChartConfiguration } from "chart.js"; import format from "xml-formatter"; import { functionCache } from "../../src"; import { Action } from "../../src/actions/action"; @@ -13,7 +11,6 @@ import { Spreadsheet, SpreadsheetProps } from "../../src/components/spreadsheet/ import { matrixMap } from "../../src/functions/helpers"; import { ImageProvider } from "../../src/helpers/figures/images/image_provider"; import { - batched, range, toCartesian, toUnboundedZone, diff --git a/tests/xlsx/xlsx_export.test.ts b/tests/xlsx/xlsx_export.test.ts index 8607c7b19a..dee5b3101f 100644 --- a/tests/xlsx/xlsx_export.test.ts +++ b/tests/xlsx/xlsx_export.test.ts @@ -1,7 +1,7 @@ import { arg } from "../../src/functions"; import { NOW, TODAY } from "../../src/functions/module_date"; import { RAND, RANDARRAY, RANDBETWEEN } from "../../src/functions/module_math"; -import { buildSheetLink, toXC } from "../../src/helpers"; +import { toXC } from "../../src/helpers"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { Model } from "../../src/model"; import { CustomizedDataSet } from "../../src/types"; @@ -10,8 +10,6 @@ import { hexaToInt } from "../../src/xlsx/conversion"; import { adaptFormulaToExcel } from "../../src/xlsx/functions/cells"; import { escapeXml, parseXML } from "../../src/xlsx/helpers/xml_helpers"; -import { functionRegistry } from "@odoo/o-spreadsheet-engine"; -import { Dimension } from "@odoo/o-spreadsheet-engine/types"; import { createChart, createGaugeChart, diff --git a/tests/xlsx/xlsx_import.test.ts b/tests/xlsx/xlsx_import.test.ts index be8acb715f..f3163d3fb1 100644 --- a/tests/xlsx/xlsx_import.test.ts +++ b/tests/xlsx/xlsx_import.test.ts @@ -1,11 +1,6 @@ +import { buildSheetLink } from "@odoo/o-spreadsheet-engine"; import { ICON_SETS } from "../../src/components/icons/icons"; -import { - buildSheetLink, - formatValue, - lettersToNumber, - markdownLink, - toZone, -} from "../../src/helpers"; +import { formatValue, lettersToNumber, markdownLink, toZone } from "../../src/helpers"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { CellIsRule, DEFAULT_LOCALE, IconSetRule } from "../../src/types"; import { BarChartDefinition } from "../../src/types/chart/bar_chart"; diff --git a/tests/xlsx/xlsx_import_export.test.ts b/tests/xlsx/xlsx_import_export.test.ts index 031ff94364..632a384092 100644 --- a/tests/xlsx/xlsx_import_export.test.ts +++ b/tests/xlsx/xlsx_import_export.test.ts @@ -1,6 +1,4 @@ -import { Align, BorderDescr, Style, VerticalAlign, Wrapping } from "@odoo/o-spreadsheet-engine"; -import { Model } from "../../src"; -import { buildSheetLink, toZone } from "../../src/helpers"; +import { toZone } from "../../src/helpers"; import { ConditionalFormatRule } from "../../src/types"; import { isXLSXExportXMLFile } from "../../src/xlsx/helpers/xlsx_helper"; import {