{"id":21634629,"url":"https://github.com/curvenote/sidenotes","last_synced_at":"2025-06-25T08:05:31.436Z","repository":{"id":44871566,"uuid":"319137711","full_name":"curvenote/sidenotes","owner":"curvenote","description":"Position floating sidenotes/comments next to a document with inline references.","archived":false,"fork":false,"pushed_at":"2022-08-03T23:00:55.000Z","size":1916,"stargazers_count":56,"open_issues_count":8,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-03T13:16:15.944Z","etag":null,"topics":["comments","comments-widget","google-docs","react","writing-tool"],"latest_commit_sha":null,"homepage":"https://curvenote.com","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/curvenote.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}},"created_at":"2020-12-06T21:43:12.000Z","updated_at":"2025-04-14T16:24:21.000Z","dependencies_parsed_at":"2022-09-21T01:12:52.158Z","dependency_job_id":null,"html_url":"https://github.com/curvenote/sidenotes","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/curvenote/sidenotes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curvenote%2Fsidenotes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curvenote%2Fsidenotes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curvenote%2Fsidenotes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curvenote%2Fsidenotes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/curvenote","download_url":"https://codeload.github.com/curvenote/sidenotes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curvenote%2Fsidenotes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261832632,"owners_count":23216495,"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":["comments","comments-widget","google-docs","react","writing-tool"],"created_at":"2024-11-25T03:17:32.687Z","updated_at":"2025-06-25T08:05:31.407Z","avatar_url":"https://github.com/curvenote.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sidenotes\n\n[![sidenotes on npm](https://img.shields.io/npm/v/sidenotes.svg)](https://www.npmjs.com/package/sidenotes)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/curvenote/sidenotes/main/LICENSE)\n![CI](https://github.com/curvenote/sidenotes/workflows/CI/badge.svg)\n[![demo](https://img.shields.io/badge/live-demo-blue)](https://curvenote.github.io/sidenotes/)\n\n**Position floating sidenotes/comments next to a document with inline references.**\n\n## Goals\n\n- Place notes/comments to the side of one or more documents with inline references.\n- When an inline reference is clicked, animate the relevant sidenote to be as close as possible and move non-relevant sidenotes out of the way without overlapping.\n- Do not provide UI or impose any styling, **only placement**.\n\n## Use cases\n\n- Comment streams next to a document. This is showing [Curvenote](https://curvenote.com), which is a scientific writing platform that connects to Jupyter.\n  [![Comments Using Sidenotes](https://github.com/curvenote/sidenotes/raw/main/images/comments.gif)](https://curvenote.com)\n\n## Choices\n\n- Use React, Redux \u0026 Typescript\n- Used Redux rather than a hook approach (open to discussion if people are passionate!)\n\n## Constraints\n\n- Multiple documents on the page, currently based on the wrapping `\u003carticle\u003e` ID\n- Multiple inline references per sidenote, wrapped in `\u003cInlineAnchor\u003e`; `InlineAnchor` is a `span`\n- Have fallback placements to a `\u003cAnchorBase\u003e`; `AnchorBase` is a `div`\n- Provide actions to attach non-react bases, anchors or reposition sidenotes\n- All positioning is based on the article, and works with `relative`, `fixed` or `absolute` positioning.\n\n## Demo\n\nThe demo is pretty basic, and not nearly as pretty as the gif above, just blue, green and red divs floating around.\nSee [index.tsx](/demo/index.tsx) for full the code/setup.\n\n```\nyarn install\nyarn start\n```\n\n![sidenotes](https://github.com/curvenote/sidenotes/raw/main/images/sidenotes.gif)\n\n## Getting Started:\n\n```\nyarn add sidenotes\n```\n\n## React Setup:\n\n```html\n\u003carticle id=\"{docId}\" onClick=\"{deselect}\"\u003e\n  \u003cAnchorBase anchor=\"{baseId}\"\u003e\n    Content with \u003cInlineAnchor sidenote=\"{sidenoteId}\"\u003einline reference\u003c/InlineAnchor\u003e\n  \u003c/AnchorBase\u003e\n  \u003cdiv className=\"sidenotes\"\u003e\n    \u003cSidenote sidenote=\"{sidenoteId}\" base=\"{baseId}\"\u003e Your custom UI, e.g. a comment \u003c/Sidenote\u003e\n  \u003c/div\u003e\n\u003c/article\u003e\n```\n\nThe `sidenotes` class is the only CSS that is recommended. You can import it directly, or [look at it](/styles/index.scss) and change it (~30 lines of `scss`). To import from javascript (assuming your bundler works with CSS):\n\n```javascript\nimport 'sidenotes/dist/sidenotes.css';\n```\n\n## Simple Javascript\n\nYou can also use sidenotes from vanilla javascript, this is done by first connecting the ID.\n\n```tsx\n// First dispatch the action to connect to any ID in the dom\nstore.dispatch(actions.connectAnchor(docId, sidenoteId, anchorId));\n\n// Then setup your handlers to select that anchor on click\n\u003cspan\n  id={anchorId}\n  onClickCapture={(event) =\u003e {\n    event.stopPropagation();\n    store.dispatch(actions.selectAnchor(docId, anchorId));\n  }}\n\u003e\n  Select a Sidenote with JavaScript! 🚀\n\u003c/span\u003e;\n\n// To clean up later, disconnect the anchor\nstore.dispatch(actions.disconnectAnchor(docId, anchorId));\n```\n\n## Redux state\n\nOnce you create your own store, add a `sidenotes.reducer`, it must be called `sidenotes`. Then pass the `store` to `setup` with options of padding between sidenotes.\n\n```javascript\nimport { combineReducers, applyMiddleware, createStore } from 'redux';\nimport thunkMiddleware from 'redux-thunk';\nimport * as sidenotes from 'sidenotes';\n\nconst reducer = combineReducers({\n  yourStuff: yourReducers,\n  sidenotes: sidenotes.reducer, // Add this to your reducers\n});\n// Create your store as normal, must have thunkMiddleware\nconst store = createStore(reducer, applyMiddleware(thunkMiddleware));\n\n// Then ensure that you pass the `store` to setup the sidenotes\nsidenotes.setup(store as sidenotes.Store, { padding: 10 })\n```\n\n## Redux State\n\nThe `sidenotes.ui` state has the following structure:\n\n```\nsidenotes:\n  ui:\n    docs:\n      [docId]:\n        anchors:\n          [anchorId]: { id: string, sidenote: string, element: [span] }\n        sidenotes:\n          [sidenoteId]: { inlineAnchors: string[], top: number, id: string, baseAnchors: string[] }\n        id: string\n        selectedAnchor: string\n        selectedNote: string\n```\n\n## Actions\n\nIt is common to put a click handler on the body (or similar) to deselect any sidenotes. This can be difficult to stop in some cases, but can be anticipated with a `onClickCapture` that fires the\n`disableNextDeselectSidenote` action. This intercepts the redux action and stops it from happening for one time.\n\n## Roadmap\n\n- Have a better mobile solution that places notes at the bottom.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcurvenote%2Fsidenotes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcurvenote%2Fsidenotes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcurvenote%2Fsidenotes/lists"}