{"id":13515443,"url":"https://github.com/github/session-resume","last_synced_at":"2025-05-16T07:04:32.483Z","repository":{"id":37550011,"uuid":"169452728","full_name":"github/session-resume","owner":"github","description":"Annotate fields to be persisted on navigation away from the current page","archived":false,"fork":false,"pushed_at":"2025-03-17T16:52:49.000Z","size":878,"stargazers_count":162,"open_issues_count":0,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-09T01:20:33.667Z","etag":null,"topics":["decorator"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/github.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-06T18:12:48.000Z","updated_at":"2025-04-12T02:01:44.000Z","dependencies_parsed_at":"2024-02-07T23:29:32.272Z","dependency_job_id":"f25fb0af-3e29-462b-886c-2e2dd9e2d6ad","html_url":"https://github.com/github/session-resume","commit_stats":{"total_commits":81,"total_committers":9,"mean_commits":9.0,"dds":"0.40740740740740744","last_synced_commit":"b1892f5d65c01a80baa8a69ed02a48118ff92520"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fsession-resume","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fsession-resume/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fsession-resume/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fsession-resume/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github","download_url":"https://codeload.github.com/github/session-resume/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485055,"owners_count":22078767,"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":["decorator"],"created_at":"2024-08-01T05:01:11.398Z","updated_at":"2025-05-16T07:04:32.465Z","avatar_url":"https://github.com/github.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Session Resume\n\nAnnotate fields to be persisted on navigation away from the current page.\nFields will be automatically restored when the user revisits the page\nagain in their current browser session (excludes separate tabs).\n\nNot designed for persisted crash recovery.\n\n## Installation\n\n```\n$ npm install @github/session-resume\n```\n\n## Usage\n\n### HTML\n\n``` html\n\u003cform\u003e\n  \u003cinput id=\"new-comment\" class=\"js-session-resumable\"/\u003e\n\u003c/form\u003e\n```\n\n### JS\n\n```js\nimport {persistResumableFields, restoreResumableFields, setForm} from '@github/session-resume'\n\nfunction getPageID() {\n  return window.location.pathname\n}\n\n// Listen for all form submit events and to see if their default submission\n// behavior is invoked.\nwindow.addEventListener('submit', setForm, {capture: true})\n\n// Resume field content on regular page loads.\nwindow.addEventListener('pageshow', function() {\n  restoreResumableFields(getPageID())\n})\n\n// Persist resumable fields when page is unloaded\nwindow.addEventListener('pagehide', function() {\n  persistResumableFields(getPageID())\n})\n```\n\n#### `restoreResumableFields(id: string, options)`\n\nThe `restoreResumableFields(id: string, options)` function supports optional configurations:\n\n* `storage:` - [`Storage`][] instance (defaults to [`window.sessionStorage`][])\n* `keyPrefix:` - `string` prepended onto the storage key (defaults to `\"session-resume\"`)\n\n[`Storage`]: https://developer.mozilla.org/en-US/docs/Web/API/Storage\n[`window.sessionStorage`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage\n\n#### `persistResumableFields(id: string, options)`\n\nThe `persistResumableFields(id: string, options)` function supports optional configurations:\n\n* `storage:` - [`Storage`][] instance (defaults to [`window.sessionStorage`][])\n* `storageFilter:` - `(field: HTMLInputElement | HTMLTextAreaElement) =\u003e boolean` predicate to determine whether or not to store a field (defaults to `(field) =\u003e field.checked !== field.defaultChecked)` for checkbox and radio buttons, `(field) =\u003e field.value !== field.defaultValue` otherwise)\n* `keyPrefix:` - `string` prepended onto the storage key (defaults to `\"session-resume\"`)\n* `scope:` - `ParentNode` used to query field elements (defaults to `document`)\n* `selector:` - `string` used to query field elements (defaults to `\".js-session-resumable\"`)\n* `fields:` - `NodeList | Node[]` provide field elements as an alternative to querying (defaults to `options.scope.querySelectorAll(options.selector)`)\n\n**Note:** When `fields` is specified, `scope` and `selectors` will be ignored.\n\n[`Storage`]: https://developer.mozilla.org/en-US/docs/Web/API/Storage\n[`window.sessionStorage`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage\n\n## Development\n\n```\nnpm install\nnpm test\n```\n\n## License\n\nDistributed under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fsession-resume","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub%2Fsession-resume","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fsession-resume/lists"}