{"id":13447844,"url":"https://github.com/samthor/undoer","last_synced_at":"2025-03-21T15:32:24.477Z","repository":{"id":57385945,"uuid":"174636572","full_name":"samthor/undoer","owner":"samthor","description":"Native undo/redo behavior for web","archived":false,"fork":false,"pushed_at":"2019-05-24T23:32:47.000Z","size":11,"stargazers_count":56,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-13T07:48:03.475Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://codepen.io/samthor/pen/WJvLxd","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samthor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-09T02:01:15.000Z","updated_at":"2024-07-30T09:00:44.000Z","dependencies_parsed_at":"2022-09-01T18:01:05.405Z","dependency_job_id":null,"html_url":"https://github.com/samthor/undoer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fundoer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fundoer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fundoer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fundoer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samthor","download_url":"https://codeload.github.com/samthor/undoer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221816540,"owners_count":16885355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T05:01:28.423Z","updated_at":"2024-10-28T10:23:05.669Z","avatar_url":"https://github.com/samthor.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"Native undo/redo behavior for web.\nThis lets you push native undo stack events onto your pages, so that users can use Ctrl/Cmd-Z—or even use some other gesture (e.g., on iOS devices, you can shake your phone to Undo).\n\nSee a [writeup on how this works](https://dev.to/chromiumdev/-native-undo--redo-for-the-web-3fl3) or an [awesome maze-based demo](https://codepen.io/samthor/pen/WJvLxd) for more.\n\n## Usage\n\nInstall on NPM/Yarn via `undoer`.\nYou can use this element as a Web Component or as pure, imperative JavaScript.\n\n### Web Component\n\nAdd the dependency to your JS and register it as a CE:\n\n```js\nimport UndoerElement from './node_modules/undoer/element.js';\ncustomElements.define('undoer-element', UndoerElement);\n```\n\nThen add the element to your page, optionally adding `state` attribute to set its zero initial state (otherwise it will be `null`):\n\n```html\n\u003cundoer-element state=\"initial state\"\u003e\u003c/undoer-element\u003e\n```\n\nFinally, use the element's JavaScript API:\n\n```js\nconst undoerEl = document.querySelector('undoer-element');\n\nundoerEl.addEventListener('state', (ev) =\u003e {\n  console.info('user undo or redid', ev.detail);\n});\n\n// set new state with\nundoerEl.state = 'new state';\nundoerEl.state = /* any object */ ;\n\n// or via attribute for string state\nundoerEl.setAttribute('state', 'new state');\n\n```\n\n### Imperative JavaScript\n\nYou can also use the raw `Undoer` class without CEs:\n\n```js\nimport {Undoer} from './node_modules/undoer/undoer.js';\n// or\nimport {Undoer} from 'undoer';  // your build system might allow this\n\n// construct with callback and push state\nconst initialState = null;  // default is null\nconst undoer = new Undoer((data) =\u003e {\n  console.info('user undo or redid', data);\n}, initialState);\nundoer.push('new state');\n```\n\n## Notes\n\nThis makes sense as a Web Component as the undo behavior works by adding a hidden `\u003cdiv contentEditable\u003e` to your page.\nIn the WC case, this is as a child of the element: in the imperative case, it's added (by default) to `document.body`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fundoer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamthor%2Fundoer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fundoer/lists"}