Use wrapper in example

This commit is contained in:
Andras Schmelczer 2025-07-04 03:09:11 +01:00
parent 1bc6117045
commit ae5940718e
6 changed files with 44 additions and 40 deletions

View file

@ -3,5 +3,6 @@
"**/snapshots": true, // cargo-insta outputs "**/snapshots": true, // cargo-insta outputs
"pkg": true, // wasm-pack build directory "pkg": true, // wasm-pack build directory
"target": true, // rust build directory "target": true, // rust build directory
"**/node_modules": true, // node.js dependencies
} }
} }

View file

@ -1,3 +0,0 @@
reconcile.js
reconcile_bg.wasm

View file

@ -1,4 +1,4 @@
import init, { mergeTextWithHistory } from "./reconcile.js"; import { init, reconcileWithHistory } from "./dist/index.js";
const originalTextArea = document.getElementById("original"); const originalTextArea = document.getElementById("original");
const leftTextArea = document.getElementById("left"); const leftTextArea = document.getElementById("left");
@ -37,16 +37,15 @@ function updateMergedText() {
const left = leftTextArea.value; const left = leftTextArea.value;
const right = rightTextArea.value; const right = rightTextArea.value;
const results = mergeTextWithHistory(original, left, right); const results = reconcileWithHistory(original, left, right);
mergedTextArea.innerHTML = ""; mergedTextArea.innerHTML = "";
for (const result of results) { for (const {text, history} of results.history) {
const span = document.createElement("span"); const span = document.createElement("span");
span.className = result.history(); span.className = history;
span.textContent = result.text(); span.textContent = text;
mergedTextArea.appendChild(span); mergedTextArea.appendChild(span);
result.free();
} }
} }

View file

@ -4,9 +4,14 @@
"target": "ESNext", "target": "ESNext",
"strict": true, "strict": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"moduleResolution": "bundler", "moduleResolution": "bundler",
"declaration": true, "declaration": true,
"declarationDir": "./dist/types" "declarationDir": "./dist/types",
"outDir": "./dist",
"rootDir": "./src",
"skipLibCheck": true,
"inlineSourceMap": true
}, },
"exclude": [ "exclude": [
"./dist" "./dist"

View file

@ -1,33 +1,37 @@
const path = require("path"); const path = require("path");
const webpack = require("webpack");
const packageJson = require("./package.json");
module.exports = { module.exports = {
entry: "./src/index.ts", entry: "./src/index.ts",
module: { module: {
rules: [ rules: [
{ {
test: /\.ts$/, test: /\.ts$/,
use: ["ts-loader"] use: ["ts-loader"]
}, },
{ {
test: /\.wasm$/, test: /\.wasm$/,
type: "asset/inline" type: "asset/inline"
} }
] ]
}, },
resolve: { optimization: {
extensions: [".ts"], // the consuming project should take care of minification
alias: { minimize: false
root: __dirname, },
src: path.resolve(__dirname, "src") resolve: {
} extensions: [".ts"],
}, alias: {
root: __dirname,
src: path.resolve(__dirname, "src")
}
},
output: { output: {
path: path.resolve(__dirname, "dist"), path: path.resolve(__dirname, "dist"),
filename: "index.js", filename: "index.js",
libraryTarget: "commonjs2" libraryTarget: "module"
},
experiments: {
outputModule: true
}, },
}; };

View file

@ -2,13 +2,11 @@
set -e set -e
rm -rf pkg
wasm-pack build --target web --features wasm wasm-pack build --target web --features wasm
cd reconcile-js
npm run build
cp -R dist ../examples/website
cp -R pkg/reconcile.js examples/website/ cd ../examples/website
cp -R pkg/reconcile_bg.wasm examples/website/
cd examples/website/
python3 -m http.server $1 --bind 0.0.0.0 python3 -m http.server $1 --bind 0.0.0.0