Format files with prettier
This commit is contained in:
parent
a2df120e66
commit
1ce0f9c059
9 changed files with 5988 additions and 5997 deletions
|
|
@ -3,8 +3,5 @@
|
|||
"printWidth": 90,
|
||||
"tabWidth": 2,
|
||||
"singleQuote": true,
|
||||
"endOfLine": "lf",
|
||||
"importOrder": ["^[./]", ".*", ".scss$"],
|
||||
"importOrderSeparation": true,
|
||||
"importOrderSortSpecifiers": true
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
|
|
@ -1,38 +1,32 @@
|
|||
{
|
||||
"name": "portfolio",
|
||||
"description": "An easily configurable timeline of projects.",
|
||||
"name": "reconcile-example-website",
|
||||
"description": "",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "webpack serve --open --mode development",
|
||||
"format": "prettier --write \"src/**/*.(ts|scss|json|html)\"",
|
||||
"format": "prettier --write \"./**/*.(ts|scss|json|html)\"",
|
||||
"build": "webpack --mode production"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/schmelczer/schmelczer.github.io.git"
|
||||
"url": "git+https://github.com/schmelczer/reconcile.git"
|
||||
},
|
||||
"keywords": [
|
||||
"CV",
|
||||
"curriculum",
|
||||
"vitae",
|
||||
"portfolio",
|
||||
"resumé"
|
||||
],
|
||||
"keywords": [],
|
||||
"author": "Andras Schmelczer",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/schmelczer/schmelczer.github.io/issues"
|
||||
"url": "https://github.com/schmelczer/reconcile/issues"
|
||||
},
|
||||
"browserslist": [
|
||||
"defaults"
|
||||
],
|
||||
"homepage": "https://github.com/schmelczer/schmelczer.github.io#readme",
|
||||
"homepage": "https://github.com/schmelczer/reconcile#readme",
|
||||
"devDependencies": {
|
||||
"reconcile": "file:../../reconcile-js",
|
||||
"css-loader": "^7.1.2",
|
||||
"html-webpack-plugin": "^5.6.3",
|
||||
"inline-source-webpack-plugin": "^3.0.1",
|
||||
"mini-css-extract-plugin": "^2.9.2",
|
||||
"inline-source-webpack-plugin": "^3.0.1",
|
||||
"prettier": "^3.6.2",
|
||||
"resolve-url-loader": "^5.0.0",
|
||||
"sass": "^1.89.2",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,5 @@
|
|||
"skipLibCheck": true,
|
||||
"inlineSourceMap": true
|
||||
},
|
||||
"exclude": [
|
||||
"./dist"
|
||||
]
|
||||
"exclude": ["./dist"]
|
||||
}
|
||||
17
reconcile-js/package-lock.json
generated
17
reconcile-js/package-lock.json
generated
|
|
@ -10,6 +10,7 @@
|
|||
"devDependencies": {
|
||||
"@types/jest": "^30.0.0",
|
||||
"jest": "^30.0.4",
|
||||
"prettier": "^3.6.2",
|
||||
"reconcile": "file:../pkg",
|
||||
"ts-jest": "^29.4.0",
|
||||
"ts-loader": "^9.5.2",
|
||||
|
|
@ -4449,6 +4450,22 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.6.2",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz",
|
||||
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/pretty-format": {
|
||||
"version": "30.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-30.0.2.tgz",
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
],
|
||||
"scripts": {
|
||||
"build": "webpack --mode production",
|
||||
"format": "prettier --write \"./**/*.(ts|scss|json|html)\"",
|
||||
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -19,6 +20,7 @@
|
|||
"tslib": "2.8.1",
|
||||
"typescript": "5.8.3",
|
||||
"webpack": "^5.99.9",
|
||||
"webpack-cli": "^6.0.1"
|
||||
"webpack-cli": "^6.0.1",
|
||||
"prettier": "^3.6.2"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +1,28 @@
|
|||
import { init, reconcile, reconcileWithHistory } from "./index";
|
||||
import * as fs from "fs";
|
||||
import { init, reconcile, reconcileWithHistory } from './index';
|
||||
import * as fs from 'fs';
|
||||
|
||||
describe("reconcile", () => {
|
||||
it("tries calling functions without init", () => {
|
||||
expect(() => reconcile("Hello", "Hello world", "Hi world")).toThrow(
|
||||
describe('reconcile', () => {
|
||||
it('tries calling functions without init', () => {
|
||||
expect(() => reconcile('Hello', 'Hello world', 'Hi world')).toThrow(/call init()/);
|
||||
|
||||
expect(() => reconcileWithHistory('Hello', 'Hello world', 'Hi world')).toThrow(
|
||||
/call init()/
|
||||
);
|
||||
|
||||
expect(() =>
|
||||
reconcileWithHistory("Hello", "Hello world", "Hi world")
|
||||
).toThrow(/call init()/);
|
||||
});
|
||||
|
||||
it("call reconcile without cursors", async () => {
|
||||
it('call reconcile without cursors', async () => {
|
||||
await initWasm();
|
||||
|
||||
expect(reconcile("Hello", "Hello world", "Hi world").text).toEqual(
|
||||
"Hi world"
|
||||
);
|
||||
expect(reconcile('Hello', 'Hello world', 'Hi world').text).toEqual('Hi world');
|
||||
});
|
||||
|
||||
it("call reconcile with cursors", async () => {
|
||||
it('call reconcile with cursors', async () => {
|
||||
await initWasm();
|
||||
|
||||
const result = reconcile(
|
||||
"Hello",
|
||||
'Hello',
|
||||
{
|
||||
text: "Hello world",
|
||||
text: 'Hello world',
|
||||
cursors: [
|
||||
{
|
||||
id: 3,
|
||||
|
|
@ -35,7 +31,7 @@ describe("reconcile", () => {
|
|||
],
|
||||
},
|
||||
{
|
||||
text: "Hi world",
|
||||
text: 'Hi world',
|
||||
cursors: [
|
||||
{
|
||||
id: 4,
|
||||
|
|
@ -46,7 +42,7 @@ describe("reconcile", () => {
|
|||
}
|
||||
);
|
||||
|
||||
expect(result.text).toEqual("Hi world");
|
||||
expect(result.text).toEqual('Hi world');
|
||||
expect(result.cursors).toEqual([
|
||||
{ id: 3, position: 0 },
|
||||
{ id: 4, position: 0 },
|
||||
|
|
@ -54,17 +50,17 @@ describe("reconcile", () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it("call reconcileWithHistory", async () => {
|
||||
it('call reconcileWithHistory', async () => {
|
||||
await initWasm();
|
||||
|
||||
const result = reconcileWithHistory("Hello", "Hello world", "Hi world");
|
||||
const result = reconcileWithHistory('Hello', 'Hello world', 'Hi world');
|
||||
|
||||
expect(result.text).toEqual("Hi world");
|
||||
expect(result.text).toEqual('Hi world');
|
||||
expect(result.history.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
async function initWasm() {
|
||||
const wasmBin = fs.readFileSync("../pkg/reconcile_bg.wasm");
|
||||
const wasmBin = fs.readFileSync('../pkg/reconcile_bg.wasm');
|
||||
await init({ module_or_path: wasmBin });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import wasmInit, {
|
|||
reconcileWithHistory as wasmReconcileWithHistory,
|
||||
History,
|
||||
InitInput,
|
||||
} from "reconcile";
|
||||
} from 'reconcile';
|
||||
|
||||
export interface TextWithCursors {
|
||||
/** The document's entire content */
|
||||
|
|
@ -39,16 +39,16 @@ export interface SpanWithHistory {
|
|||
history: History;
|
||||
}
|
||||
|
||||
export type Tokenizer = "Line" | "Word" | "Character";
|
||||
const TOKENIZERS = ["Line", "Word", "Character"];
|
||||
export type Tokenizer = 'Line' | 'Word' | 'Character';
|
||||
const TOKENIZERS = ['Line', 'Word', 'Character'];
|
||||
|
||||
let isInitialised = false;
|
||||
|
||||
const UNINITIALISED_MODULE_ERROR =
|
||||
"Reconcile module has not been initialized. Please call init() before using any other functions.";
|
||||
'Reconcile module has not been initialized. Please call init() before using any other functions.';
|
||||
|
||||
const UNSUPPORTED_TOKENIZER_ERROR = `Unsupported tokenizer. Only ${TOKENIZERS.join(
|
||||
", "
|
||||
', '
|
||||
)} are supported.`;
|
||||
|
||||
/**
|
||||
|
|
@ -83,7 +83,7 @@ export function reconcile(
|
|||
original: string,
|
||||
left: string | TextWithCursors,
|
||||
right: string | TextWithCursors,
|
||||
tokenizer: BuiltinTokenizer = "Word"
|
||||
tokenizer: BuiltinTokenizer = 'Word'
|
||||
): TextWithCursors {
|
||||
if (!isInitialised) {
|
||||
throw new Error(UNINITIALISED_MODULE_ERROR);
|
||||
|
|
@ -122,7 +122,7 @@ export function reconcileWithHistory(
|
|||
original: string,
|
||||
left: string | TextWithCursors,
|
||||
right: string | TextWithCursors,
|
||||
tokenizer: BuiltinTokenizer = "Word"
|
||||
tokenizer: BuiltinTokenizer = 'Word'
|
||||
): TextWithCursorsAndHistory {
|
||||
if (!isInitialised) {
|
||||
throw new Error(UNINITIALISED_MODULE_ERROR);
|
||||
|
|
@ -135,12 +135,7 @@ export function reconcileWithHistory(
|
|||
const leftCursor = toWasmTextWithCursors(left);
|
||||
const rightCursor = toWasmTextWithCursors(right);
|
||||
|
||||
const result = wasmReconcileWithHistory(
|
||||
original,
|
||||
leftCursor,
|
||||
rightCursor,
|
||||
tokenizer
|
||||
);
|
||||
const result = wasmReconcileWithHistory(original, leftCursor, rightCursor, tokenizer);
|
||||
|
||||
leftCursor.free();
|
||||
rightCursor.free();
|
||||
|
|
@ -155,29 +150,19 @@ export function reconcileWithHistory(
|
|||
};
|
||||
}
|
||||
|
||||
function toWasmTextWithCursors(
|
||||
text: string | TextWithCursors
|
||||
): wasmTextWithCursors {
|
||||
const isInputString = typeof text == "string";
|
||||
function toWasmTextWithCursors(text: string | TextWithCursors): wasmTextWithCursors {
|
||||
const isInputString = typeof text == 'string';
|
||||
const leftText = isInputString ? text : text.text;
|
||||
const leftCursors = isInputString ? [] : text.cursors ?? [];
|
||||
const leftCursors = isInputString ? [] : (text.cursors ?? []);
|
||||
|
||||
return new wasmTextWithCursors(
|
||||
leftText,
|
||||
leftCursors.map(toWasmCursorPosition)
|
||||
);
|
||||
return new wasmTextWithCursors(leftText, leftCursors.map(toWasmCursorPosition));
|
||||
}
|
||||
|
||||
function toWasmCursorPosition({
|
||||
id,
|
||||
position,
|
||||
}: CursorPosition): wasmCursorPosition {
|
||||
function toWasmCursorPosition({ id, position }: CursorPosition): wasmCursorPosition {
|
||||
return new wasmCursorPosition(id, position);
|
||||
}
|
||||
|
||||
function toTextWithCursors(
|
||||
textWithCursor: wasmTextWithCursors
|
||||
): TextWithCursors {
|
||||
function toTextWithCursors(textWithCursor: wasmTextWithCursors): TextWithCursors {
|
||||
return {
|
||||
text: textWithCursor.text(),
|
||||
cursors: textWithCursor.cursors().map(toCursorPosition),
|
||||
|
|
@ -191,9 +176,7 @@ function toCursorPosition(cursor: wasmCursorPosition): CursorPosition {
|
|||
};
|
||||
}
|
||||
|
||||
function toSpanWithHistory(
|
||||
textWithHistory: wasmSpanWithHistory
|
||||
): SpanWithHistory {
|
||||
function toSpanWithHistory(textWithHistory: wasmSpanWithHistory): SpanWithHistory {
|
||||
return {
|
||||
text: textWithHistory.text(),
|
||||
history: textWithHistory.history(),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,5 @@
|
|||
"skipLibCheck": true,
|
||||
"inlineSourceMap": true
|
||||
},
|
||||
"exclude": [
|
||||
"./dist"
|
||||
]
|
||||
"exclude": ["./dist"]
|
||||
}
|
||||
|
|
@ -5,4 +5,10 @@ set -e
|
|||
cargo clippy --all-targets --all-features --fix --allow-dirty --allow-staged
|
||||
cargo fmt --all
|
||||
|
||||
cd reconcile-js
|
||||
npm run format
|
||||
|
||||
cd ../examples/website
|
||||
npm run format
|
||||
|
||||
echo "Success!"
|
||||
Loading…
Add table
Add a link
Reference in a new issue