{"id":26630279,"url":"https://github.com/elite174/solid-undo-redo","last_synced_at":"2025-04-10T15:23:01.333Z","repository":{"id":153728706,"uuid":"625880285","full_name":"elite174/solid-undo-redo","owner":"elite174","description":"A list-based (O(1)) implementation of undo-redo for signals!","archived":false,"fork":false,"pushed_at":"2023-09-14T01:34:57.000Z","size":265,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-03-15T06:46:39.804Z","etag":null,"topics":["history","redo","solidjs","time-travel","undo","undo-redo"],"latest_commit_sha":null,"homepage":"https://solid-undo-redo.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elite174.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-10T10:04:15.000Z","updated_at":"2023-10-07T01:52:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"71b93976-10d0-4be5-93a9-4a5138ca94f3","html_url":"https://github.com/elite174/solid-undo-redo","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/elite174%2Fsolid-undo-redo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elite174%2Fsolid-undo-redo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elite174%2Fsolid-undo-redo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elite174%2Fsolid-undo-redo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elite174","download_url":"https://codeload.github.com/elite174/solid-undo-redo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248243421,"owners_count":21071054,"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":["history","redo","solidjs","time-travel","undo","undo-redo"],"created_at":"2025-03-24T13:17:57.775Z","updated_at":"2025-04-10T15:23:01.324Z","avatar_url":"https://github.com/elite174.png","language":"TypeScript","readme":"# solid-undo-redo\n\n[![version](https://img.shields.io/npm/v/solid-undo-redo?style=for-the-badge)](https://www.npmjs.com/package/solid-undo-redo)\n![npm](https://img.shields.io/npm/dw/solid-undo-redo?style=for-the-badge)\n\nA small library for undo-redo operations!\nMake signals with history.\nThe implementation is list-based, so it works in **O(1)** instead of O(n)!\n\n## Features\n\n- Make `undo` or `redo` operations\n- Set your history length\n- React on undo and redo events with callbacks\n- Turn your history into reactive iterator\n\n## Installation\n\n`npm i solid-undo-redo`\n\n`pnpm add solid-undo-redo`\n\n`yarn add solid-undo-redo`\n\n## Usage\n\n```tsx\nimport { createSignalWithHistory } from \"solid-undo-redo\";\n\nconst [value, setValue, history] = createSignalWithHistory\u003cnumber | undefined\u003e(\n  undefined,\n  { historyLength: 10 }\n);\n\nsetValue(1);\n\n// Since we haven't provided the initial value (undefined)\n// the history length equals to 1\nconsole.assert(history.size() === 1);\n\n// Since the history length is 1\n// we can't do undo and redo\nconsole.assert(history.isUndoPossible() === false);\nconsole.assert(history.isRedoPossible() === false);\n\nsetValue(2);\n\n// We added new value to the history\nconsole.assert(history.size() === 2);\n\n// Now we can make undo operation\nconsole.assert(history.isUndoPossible() === true);\n// However we can't do redo because we're at the end\n// of our history\nconsole.assert(history.isRedoPossible() === false);\n\n// let's add some undo/redo listeners\nhistory.registerCallback(\"undo\", (currentValue, previousValue) =\u003e\n  console.log(`Undo: ${currentValue}, ${previousValue}`)\n);\n\nhistory.registerCallback(\"redo\", (currentValue, previousValue) =\u003e {\n  console.log(`Redo: ${currentValue}, ${previousValue}`);\n});\n\n// Don't forget to remove these listeners with api.removeCallback\n// when you don't need them!\n\nhistory.undo();\n// You'll see in the console \"Undo: 1, 2\"\n\n// Now we can't make undo operations\n// because we're at the beginning of our history\nconsole.assert(history.isUndoPossible() === false);\n// But we can do redo!\nconsole.assert(history.isRedoPossible() === true);\n\nhistory.redo();\n// You'll see in the console \"Redo: 2, 1\"\n\n// Let's have a look at our history\nconsole.log(history.toArray()); // [1, 2]\n\n// You can also use history.arraySignal\n// To get a reactive accessor of the history array\n\n// Now let's clear our history and callbacks\nhistory.dispose();\n```\n\n## Docs\n\n```tsx\nfunction createSignalWithHistory\u003cT\u003e(\n  initialValue?: T,\n  options?: SignalWithHistoryOptions\u003cT | undefined\u003e\n): SignalWithHistory\u003cT | undefined\u003e;\n\ntype CallbackTypeMap\u003cT\u003e = {\n  undo: (currentValue: T, previousValue: T) =\u003e void;\n  redo: (currentValue: T, previousValue: T) =\u003e void;\n};\n\nexport interface SignalWithHistoryOptions\u003cT\u003e {\n  /**\n   * Max history length\n   * @default 100\n   */\n  historyLength?: number;\n  /**\n   * Solid signal options\n   */\n  signalOptions?: SignalOptions\u003cT\u003e | undefined;\n}\n\nexport type History\u003cT\u003e = {\n  undo: VoidFunction;\n  redo: VoidFunction;\n\n  /**\n   * Cleas the history\n   * @param clearCurrentValue - clears current value if set to true\n   * @default false\n   */\n  clear: (clearCurrentValue?: boolean) =\u003e void;\n\n  /** Reactive signal which indicates if undo operation is possible */\n  isUndoPossible: Accessor\u003cboolean\u003e;\n  /** Reactive signal which indicates if redo operation is possible */\n  isRedoPossible: Accessor\u003cboolean\u003e;\n\n  /**\n   * Reactive generator function which is retriggered\n   * when the history changes\n   */\n  createHistoryIterator: () =\u003e Generator\u003cT, void, unknown\u003e;\n\n  /**\n   * Reactive signal which shows the current history length\n   */\n  size: Accessor\u003cnumber\u003e;\n\n  /** Register callback for undo/redo */\n  registerCallback: \u003cCallbackType extends keyof CallbackTypeMap\u003cT\u003e\u003e(\n    type: CallbackType,\n    listener: CallbackTypeMap\u003cT\u003e[CallbackType]\n  ) =\u003e void;\n\n  /** Remove callback for undo/redo */\n  removeCallback: \u003cCallbackType extends keyof CallbackTypeMap\u003cT\u003e\u003e(\n    type: CallbackType,\n    listener: CallbackTypeMap\u003cT\u003e[CallbackType]\n  ) =\u003e void;\n\n  /** Returns non-reactive history array */\n  toArray: () =\u003e Array\u003cT\u003e;\n\n  /** Reactive signal of history array */\n  arraySignal: Accessor\u003cArray\u003cT\u003e\u003e;\n\n  /** Clear all registered callbacks and history */\n  dispose: VoidFunction;\n};\n\nexport type SignalWithHistory\u003cT\u003e = [\n  /** Reactive accessor for the value */\n  get: Accessor\u003cT\u003e,\n  /** Setter function for the value */\n  set: Setter\u003cT\u003e,\n  history: History\u003cT\u003e\n];\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felite174%2Fsolid-undo-redo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felite174%2Fsolid-undo-redo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felite174%2Fsolid-undo-redo/lists"}