callumalpass_tasknotes/esbuild.config.mjs
ac8318740 66b3ef1bd8 fix(drag-reorder): fix LexoRank bugs in filtered views and near-ceiling ranks
Several interrelated drag-to-reorder bugs fixed:

- computeSortOrder() now scans the full vault (ignoring swimlane filters)
  so invisible tasks in filtered views aren't leapfrogged during reorder
- Filter out tasks with undefined or non-LexoRank sort_orders (legacy
  numeric timestamps) from neighbor lookup to prevent rankBetween()
  from producing garbage values via ensureRank() fallbacks
- Fix safeGenNext() overflow: values starting with 'z' (near ceiling)
  now extend via the decimal part instead of appending an integer digit,
  which caused LexoRank.between() to wrap around
- Add sanity check in rankBetween() to detect out-of-range results from
  LexoRank.between() and fall back to safeGenNext()
- Reconstruct dropTarget from visible cards when column-level drop fires
  with null target (user drops in empty space below last card)
- Consolidate group/swimlane/sort_order into single atomic frontmatter
  write per task to prevent interleaved corruption
- Add DropOperationQueue to serialize rapid drops on the same task file
- Add optimistic DOM reorder on drop for instant visual feedback
- Add post-drop render suppression to prevent stale Bases data from
  overwriting optimistic positions
- Add esbuild copy-to-vault plugin for faster dev iteration
- Add .serena/ to .gitignore
2026-03-29 07:33:57 +11:00

102 lines
2.5 KiB
JavaScript

import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import { readFileSync, existsSync, copyFileSync, mkdirSync } from "fs";
import { resolve, join } from "path";
import { homedir } from "os";
const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const prod = (process.argv[2] === "production");
// Read copy destinations from .copy-files.local (same logic as copy-files.mjs)
function getCopyDestinations() {
const localFile = resolve(process.cwd(), '.copy-files.local');
if (!existsSync(localFile)) return [];
const expandTilde = (p) => p.startsWith('~/') ? join(homedir(), p.slice(2)) : p;
return readFileSync(localFile, 'utf8')
.split('\n')
.map(p => p.trim())
.filter(p => p && !p.startsWith('#'))
.map(expandTilde);
}
// esbuild plugin: copy build outputs to vault after each rebuild
const copyToVaultPlugin = {
name: 'copy-to-vault',
setup(build) {
const destinations = getCopyDestinations();
if (destinations.length === 0) return;
const filesToCopy = ['main.js', 'styles.css', 'manifest.json'];
build.onEnd((result) => {
if (result.errors.length > 0) return;
for (const dest of destinations) {
mkdirSync(dest, { recursive: true });
for (const file of filesToCopy) {
const src = resolve(process.cwd(), file);
if (existsSync(src)) {
copyFileSync(src, join(dest, file));
}
}
console.log(`\x1b[32m✓ Copied to ${dest}\x1b[0m`);
}
});
}
};
// Plugin to import markdown files as strings
const markdownPlugin = {
name: 'markdown',
setup(build) {
build.onLoad({ filter: /\.md$/ }, async (args) => {
const text = readFileSync(args.path, 'utf8');
return {
contents: `export default ${JSON.stringify(text)}`,
loader: 'js',
};
});
}
};
const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["main.ts"],
bundle: true,
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
minify: prod,
plugins: [markdownPlugin, ...(!prod ? [copyToVaultPlugin] : [])],
});
if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}