Skip to content

Commit f823037

Browse files
committed
First version
0 parents  commit f823037

File tree

11 files changed

+3515
-0
lines changed

11 files changed

+3515
-0
lines changed

.esdoc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"source": "./src",
3+
"destination": "./docs",
4+
"plugins": [
5+
{
6+
"name": "esdoc-standard-plugin",
7+
"option": {
8+
"manual": {
9+
"globalIndex": true,
10+
"files": [
11+
"./README.md",
12+
"./CHANGELOG.md",
13+
"./LICENSE.md",
14+
"./CONTRIBUTING.md"
15+
]
16+
}
17+
}
18+
},
19+
{
20+
"name": "esdoc-importpath-plugin",
21+
"option": {
22+
"stripPackageName": false,
23+
"replaces": [
24+
{"from": "^src/index.js", "to": ""}
25+
]
26+
}
27+
}
28+
]
29+
}

.eslintrc.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"extends": ["eslint:recommended", "plugin:import/errors"],
7+
"parserOptions": {
8+
"ecmaVersion": 2019,
9+
"sourceType": "module"
10+
},
11+
plugins: [
12+
"import"
13+
],
14+
"rules": {
15+
"indent": [
16+
"error",
17+
4
18+
],
19+
"linebreak-style": [
20+
"error",
21+
"unix"
22+
],
23+
"quotes": [
24+
"error",
25+
"double"
26+
],
27+
"semi": [
28+
"error",
29+
"never"
30+
],
31+
"import/export": ["error"],
32+
"import/order": ["error", {"newlines-between": "always", "alphabetize": {"order": "asc", "caseInsensitive": true}}],
33+
"import/newline-after-import": ["error"],
34+
"import/no-absolute-path": ["error"]
35+
},
36+
"settings": {
37+
"import/extensions": [".js"],
38+
}
39+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules/
2+
/dist/
3+
/docs/

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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.0.0] - 2020-09-12
10+
11+
First version
12+
13+
[Unreleased]: https://github.com/MacFJA/svelte-undoable/compare/1.0.0...HEAD
14+
[1.0.0]: https://github.com/MacFJA/svelte-undoable/releases/tag/1.0.0

CONTRIBUTING.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
```
37+
The command will output any information worth knowing. No error should be left.
38+
39+
----
40+
41+
Thanks!

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
```sveltehtml
34+
<script>
35+
import { undoable, undo, redo, reset, canUndo, canRedo } from "@macfja/svelte-undoable"
36+
import { derived } from "svelte/store"
37+
38+
let name = undoable("John")
39+
let canUndoName = derived([name], () => canUndo(name))
40+
let canRedoName = derived([name], () => canRedo(name))
41+
42+
let counter = undoable(0, 10, value => value%2 === 0)
43+
let canUndoCounter = derived([counter], () => counter.canUndo())
44+
let canRedoCounter = derived([counter], () => counter.canRedo())
45+
</script>
46+
47+
<h1>Hello {$name}</h1>
48+
49+
<input bind:value={$name} />
50+
<button disabled={!$canUndoName} on:click={() => undo(name)}>Undo</button>
51+
<button disabled={!$canRedoName} on:click={() => redo(name)}>Redo</button>
52+
<button disabled={!$canUndoName} on:click={() => reset(name)}>Reset</button>
53+
54+
<hr />
55+
Only even number as saved in the store history. The maximum number of remembered value is 10.
56+
(If you go to <code>20</code>, you can only go back to <code>2</code>)
57+
58+
<button on:click={() => $counter++}>
59+
Clicked {$counter} {$counter === 1 ? 'time' : 'times'}
60+
</button>
61+
<button disabled={!$canUndoCounter} on:click={() => undo(counter)}>Undo</button>
62+
<button disabled={!$canRedoCounter} on:click={() => redo(counter)}>Redo</button>
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.

0 commit comments

Comments
 (0)