├── .eslintrc.js ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── package-lock.json ├── package.json ├── pagesconfig.json ├── rollup.config.js ├── rollup.test.config.js ├── src └── index.ts ├── tests ├── e2e.ts ├── index.html └── src │ └── App.svelte ├── tsconfig.json └── typedoc.json /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "browser": true, 4 | "es6": true 5 | }, 6 | "extends": [ 7 | "eslint:recommended", 8 | "plugin:import/errors", 9 | "plugin:@typescript-eslint/recommended" 10 | ], 11 | "parserOptions": { 12 | "ecmaVersion": 2019, 13 | "sourceType": "module" 14 | }, 15 | plugins: [ 16 | "import", 17 | "@typescript-eslint" 18 | ], 19 | "rules": { 20 | "indent": [ 21 | "error", 22 | 4 23 | ], 24 | "linebreak-style": [ 25 | "error", 26 | "unix" 27 | ], 28 | "quotes": [ 29 | "error", 30 | "double" 31 | ], 32 | "semi": [ 33 | "error", 34 | "never" 35 | ], 36 | "import/export": ["error"], 37 | "import/order": ["error", {"newlines-between": "always", "alphabetize": {"order": "asc", "caseInsensitive": true}}], 38 | "import/newline-after-import": ["error"], 39 | "import/no-absolute-path": ["error"] 40 | }, 41 | "settings": { 42 | "import/extensions": [".js"], 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /dist/ 3 | /types/ 4 | /docs/ 5 | /tests/build/ -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | 9 | ## [1.1.0] 10 | 11 | ### Added 12 | 13 | - Functional tests 14 | 15 | ### Changed 16 | 17 | - Migrate the code to TypeScript 18 | 19 | ## [1.0.0] - 2020-09-12 20 | 21 | First version 22 | 23 | [Unreleased]: https://github.com/MacFJA/svelte-undoable/compare/1.1.0...HEAD 24 | [1.1.0]: https://github.com/MacFJA/svelte-undoable/releases/tag/1.0.0...1.1.0 25 | [1.0.0]: https://github.com/MacFJA/svelte-undoable/releases/tag/1.0.0 26 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | ## Reporting and improving 4 | 5 | ### Did you find a bug? 6 | 7 | * **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/MacFJA/svelte-undoable/issues). 8 | 9 | * If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/MacFJA/svelte-undoable/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible 10 | 11 | ### Did you write a patch that fixes a bug? 12 | 13 | * Open a new GitHub pull request with the patch. 14 | 15 | * Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. 16 | 17 | ### Do you have an idea to improve the application? 18 | 19 | * **Ensure the suggestion was not already ask** by searching on GitHub under [Issues](https://github.com/MacFJA/svelte-undoable/issues). 20 | 21 | * If you're unable to find an open issue about your feature, [open a new one](https://github.com/MacFJA/svelte-undoable/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible 22 | 23 | ### Do you want to contribute to the application documentation? 24 | 25 | * **Ensure the documentation improvement was not already submitted** by searching on GitHub under [Issues](https://github.com/MacFJA/svelte-undoable/issues). 26 | 27 | * If you're unable to find an open issue addressing this, clone the wiki git on your computer 28 | 29 | * [Open a new issue](https://github.com/MacFJA/svelte-undoable/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible and the patch for the documentation 30 | 31 | ## Coding conventions 32 | 33 | Check your code by running the command: 34 | ```sh 35 | npm run lint 36 | npm run test 37 | ``` 38 | The command will output any information worth knowing. No error should be left. 39 | 40 | ---- 41 | 42 | Thanks! -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2020 [MacFJA](https://github.com/MacFJA) 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Svelte Undoable store 2 | 3 | Memento design pattern in Svelte 4 | 5 | ## Installation 6 | 7 | ``` 8 | npm install @macfja/svelte-undoable 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```javascript 14 | import { undoable } from "@macfja/svelte-undoable" 15 | 16 | let name = undoable("John") 17 | 18 | $name = "Jeanne" 19 | $name = "Doe" 20 | 21 | name.undo() 22 | // Now the value of $name is "Jeanne" 23 | 24 | name.undo() 25 | // Now $name is "John" 26 | 27 | name.redo() 28 | // Now $name is "Jeanne" again 29 | ``` 30 | 31 | ## Example 32 | 33 | ```html 34 | 46 | 47 |
20
, you can only go back to 2
)
57 |
58 |
61 |
62 |
63 | ```
64 | ([REPL](https://svelte.dev/repl/9412d77adca64a668055027e84619090?version=3.25.0))
65 |
66 | ## Contributing
67 |
68 | Contributions are welcome. Please open up an issue or create PR if you would like to help out.
69 |
70 | Read more in the [Contributing file](CONTRIBUTING.md)
71 |
72 | ## License
73 |
74 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@macfja/svelte-undoable",
3 | "version": "1.1.0",
4 | "description": "Memento design pattern in Svelte",
5 | "module": "dist/index.mjs",
6 | "main": "dist/index.js",
7 | "scripts": {
8 | "doc": "typedoc src/index.ts",
9 | "lint": "eslint src/",
10 | "pretest": "rollup -c rollup.test.config.js",
11 | "test": "testcafe all tests/e2e.ts --app 'npx sirv tests'",
12 | "prebuild": "tsc",
13 | "build": "rollup -c",
14 | "prepublishOnly": "npm run build"
15 | },
16 | "files": [
17 | "src/",
18 | "dist/",
19 | "types/",
20 | "LICENSE.md",
21 | "README.md"
22 | ],
23 | "repository": {
24 | "type": "git",
25 | "url": "git+https://github.com/macfja/svelte-undoable.git"
26 | },
27 | "keywords": [
28 | "undo",
29 | "redo",
30 | "store",
31 | "svelte",
32 | "sveltejs",
33 | "memento"
34 | ],
35 | "author": "MacFJA",
36 | "license": "MIT",
37 | "bugs": {
38 | "url": "https://github.com/macfja/svelte-undoable/issues"
39 | },
40 | "homepage": "https://github.com/macfja/svelte-undoable#readme",
41 | "devDependencies": {
42 | "@rollup/plugin-node-resolve": "^9.0.0",
43 | "@rollup/plugin-typescript": "^8.2.0",
44 | "@tsconfig/svelte": "^1.0.10",
45 | "@typescript-eslint/eslint-plugin": "^4.15.1",
46 | "@typescript-eslint/parser": "^4.15.1",
47 | "eslint": "^7.20.0",
48 | "eslint-plugin-import": "^2.22.1",
49 | "rollup": "^2.39.0",
50 | "rollup-plugin-svelte": "^6.1.1",
51 | "sirv-cli": "^1.0.11",
52 | "svelte": "^3.32.3",
53 | "svelte-check": "^1.1.35",
54 | "svelte-preprocess": "^4.6.9",
55 | "testcafe": "^1.11.0",
56 | "tslib": "^2.1.0",
57 | "typedoc": "^0.20.26",
58 | "typedoc-plugin-pages": "^1.1.0",
59 | "typescript": "^4.1.5"
60 | },
61 | "dependencies": {},
62 | "types": "types/index.d.ts"
63 | }
64 |
--------------------------------------------------------------------------------
/pagesconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "groups": [
3 | {
4 | "title": "Svelte Undoable store",
5 | "pages": [
6 | {"title": "Changelog", "source": "CHANGELOG.md"},
7 | {"title": "Contributing", "source": "CONTRIBUTING.md"},
8 | {"title": "License", "source": "LICENSE.md"}
9 | ]
10 | }
11 | ]
12 | }
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte';
2 | import resolve from '@rollup/plugin-node-resolve';
3 | import typescript from "@rollup/plugin-typescript";
4 | import autoPreprocess from 'svelte-preprocess';
5 | import pkg from './package.json';
6 |
7 | const name = pkg.name
8 | .replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3')
9 | .replace(/^\w/, m => m.toUpperCase())
10 | .replace(/-\w/g, m => m[1].toUpperCase());
11 |
12 | export default {
13 | input: 'src/index.ts',
14 | output: [
15 | { file: pkg.module, 'format': 'es' },
16 | { file: pkg.main, 'format': 'umd', name }
17 | ],
18 | plugins: [
19 | svelte({
20 | preprocess: autoPreprocess()
21 | }),
22 | typescript(),
23 | resolve()
24 | ]
25 | };
--------------------------------------------------------------------------------
/rollup.test.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte';
2 | import resolve from '@rollup/plugin-node-resolve';
3 | import typescript from "@rollup/plugin-typescript";
4 | import autoPreprocess from 'svelte-preprocess';
5 |
6 | export default {
7 | input: 'tests/src/App.svelte',
8 | output: [
9 | { file: 'tests/build/app.js', 'format': 'iife', name: 'app' }
10 | ],
11 | plugins: [
12 | svelte({
13 | preprocess: autoPreprocess()
14 | }),
15 | typescript(),
16 | resolve()
17 | ]
18 | };
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright MacFJA
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7 | * permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10 | * Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 | */
17 |
18 | import {Writable, writable} from "svelte/store"
19 |
20 | /**
21 | * Undoable store.
22 | *
23 | * A writable store with history.
24 | */
25 | export interface UndoableStore20
, you can only go back to 2
)
24 |
25 |
28 |
29 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@tsconfig/svelte/tsconfig.json",
3 |
4 | "include": ["src/*", "src/node_modules"],
5 | "exclude": ["node_modules/*", "docs/*", "dist/*"],
6 | "compilerOptions": {
7 | "emitDeclarationOnly": true,
8 | "declaration": true,
9 | "declarationDir": "types",
10 | "sourceMap": false
11 | },
12 | "files": ["src/index.ts"]
13 | }
--------------------------------------------------------------------------------
/typedoc.json:
--------------------------------------------------------------------------------
1 | {
2 | "entryPoints": ["src/"],
3 | "theme": "pages-plugin"
4 | }
5 |
--------------------------------------------------------------------------------