Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://unpkg.com/@changesets/config@4.0.0/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "FormidableLabs/use-editable", "disableThanks": true }
],
"access": "public",
"baseBranch": "main",
"privatePackages": false
}
10 changes: 10 additions & 0 deletions .changeset/modern-toolchain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'use-editable': major
---

Require React 18 or newer, and ship modern JavaScript.

- **Breaking:** the `react` peer dependency is now `>=18.0.0` (was `>=16.8.0`).
- **Breaking:** `dist/` now targets ES2022 instead of ES5. Bundlers that transpile `node_modules` for older browsers are unaffected.
- Types now live at `dist/use-editable.d.ts` (was `dist/types/index.d.ts`); the `types` field points there, so normal imports are unaffected. The `main` and `module` filenames are unchanged.
- The build moved from rollup, Babel, buble, closure-compiler and terser to tsdown; releases are published from CI with npm provenance.
7 changes: 7 additions & 0 deletions .changeset/stale-caret-restore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'use-editable': patch
---

pr: #37

Don't restore a stale caret position onto content it wasn't computed against. An unrelated re-render landing between a keystroke's `keydown` and `keyup` no longer yanks the caret to the wrong offset.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
82 changes: 53 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,61 @@ on:
push:
branches: [main]

permissions: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
check:
name: Format, typecheck, and build
runs-on: ubuntu-latest
permissions:
contents: read # to check out repo (actions/checkout)
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- name: Check
run: npm run check
- name: Build
run: npm run build

react-compat:
name: React ${{ matrix.react }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [18.x]

# The lockfile pins React 19, so `check` above already covers it. This
# job covers the other end of the `>=18.0.0` peer range. React is
# pinned exactly so a newer 18.x can't silently satisfy a claim about
# 18.0.0; the types float on `^18` since they aren't the peer dep.
include:
- react: '18.0.0'
types: '^18'
permissions:
contents: read # to check out repo (actions/checkout)
steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Get Yarn cache directory
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Use Yarn cache
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile

- name: TypeScript Check
run: yarn run check

- name: Build
run: yarn run build
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- name: Pin React ${{ matrix.react }}
run: |
npm pkg set \
devDependencies.react="${{ matrix.react }}" \
"devDependencies.@types/react=${{ matrix.types }}"
npm install --no-package-lock
- name: TypeScript Check
run: npm run check:types
122 changes: 122 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Release

on:
push:
branches:
- main

# Reset permissions and grant them per job, so `id-token: write` only exists on
# the job that actually publishes.
permissions: {}

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
select-mode:
name: Select mode
runs-on: ubuntu-latest
outputs:
mode: ${{ steps.select-mode.outputs.mode }}
publish-plan-artifact-id: ${{ steps.select-mode.outputs.publish-plan-artifact-id }}
permissions:
contents: read # to check out repo (actions/checkout)
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- name: Select Changesets mode
id: select-mode
uses: changesets/action/select-mode@v2

version:
name: Version packages
if: needs.select-mode.outputs.mode == 'version'
needs: select-mode
runs-on: ubuntu-latest
permissions:
contents: write # to commit version changes (changesets/action/version)
pull-requests: write # to open the "Version Packages" PR
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
# Full history so the changelog can link each entry to the commit that
# added its changeset; a shallow clone silently drops those links.
fetch-depth: 0
- uses: actions/setup-node@v7
with:
node-version-file: '.nvmrc'
package-manager-cache: false # avoid cache poisoning
- run: npm ci
- name: Version packages
uses: changesets/action/version@v2
with:
# Not just `changeset version` (the action's default): that bumps
# package.json and leaves package-lock.json pointing at the old
# version. The script refreshes the lockfile in the same commit.
script: npm run changeset:version
env:
# Not for the action itself -- this is for `@changesets/changelog-github`,
# which runs inside `changeset version` and queries the GraphQL API to
# turn each changeset's commit into a PR link. It throws without it.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pack:
name: Pack tarball
if: needs.select-mode.outputs.mode == 'publish'
needs: select-mode
runs-on: ubuntu-latest
outputs:
pack-dir-artifact-id: ${{ steps.pack.outputs.pack-dir-artifact-id }}
permissions:
contents: read # to check out repo (actions/checkout)
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version-file: '.nvmrc'
package-manager-cache: false # avoid cache poisoning
- run: npm ci
# NOTE: the `prepack` script runs the build. `prepublishOnly` would NOT
# run here -- `npm pack` does not trigger it -- which is why that script
# is `prepack`.
- name: Pack packages
id: pack
uses: changesets/action/pack@v2
with:
publish-plan-artifact-id: ${{ needs.select-mode.outputs.publish-plan-artifact-id }}

publish:
name: Publish to npm
needs: pack
runs-on: ubuntu-latest
# Requires manual approval before anything reaches npm. Merging the
# "Version Packages" PR is already a human gate; this is a second one at the
# moment of publish, and it scopes `id-token: write` to an approved run.
environment: Production
permissions:
contents: write # to create git tags and GitHub releases
id-token: write # for npm trusted publishing (OIDC)
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
package-manager-cache: false # avoid cache poisoning
- name: Upgrade npm for OIDC
run: npm i -g npm@">=11.5.1"
- run: npm ci
- name: Publish packages
uses: changesets/action/publish@v2
with:
pack-dir-artifact-id: ${{ needs.pack.outputs.pack-dir-artifact-id }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
yarn-error.log
npm-debug.log*
dist/
node_modules/
coverage/
.DS_Store
.idea/
.vscode/
*.tgz
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
package-lock.json
CHANGELOG.md
30 changes: 15 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,75 @@
## 2.3.3

- Prevent empty text from being inserted
(See [`82ac3eb`](https://github.com/kitten/use-editable/commit/82ac3eb5000e0fa4967924ab54a98738270a1183))
(See [`82ac3eb`](https://github.com/FormidableLabs/use-editable/commit/82ac3eb5000e0fa4967924ab54a98738270a1183))
- Prevent empty or negative ranges from being created for empty elements
(See [`b79d013`](https://github.com/kitten/use-editable/commit/b79d0130527baa9ba703e5193dd9beddc00904e8))
(See [`b79d013`](https://github.com/FormidableLabs/use-editable/commit/b79d0130527baa9ba703e5193dd9beddc00904e8))

## 2.3.2

- Fix missing backspace behaviour on `opts.indentation` for non-plaintext-only browsers
(See [`093b10e`](https://github.com/kitten/use-editable/commit/093b10eb645aece3e8e974721fe8ebf9c1e7a1a3))
(See [`093b10e`](https://github.com/FormidableLabs/use-editable/commit/093b10eb645aece3e8e974721fe8ebf9c1e7a1a3))

## 2.3.1

- Fix Chrome quirk where initial focus would immediately lose its selected range by switching to `selectstart` and checking for `window.getSelection().rangeCount`
(See [`71ae9a2`](https://github.com/kitten/use-editable/commit/71ae9a20bdf09b1bff8b6cb9ee460b5f828ffa69))
(See [`71ae9a2`](https://github.com/FormidableLabs/use-editable/commit/71ae9a20bdf09b1bff8b6cb9ee460b5f828ffa69))

## 2.3.0

- Add `Edit#getState()` method to returned `Edit` handle. `useEditable` returns the `Edit` object with several methods to allow manipulating the current editable.
The `getState()` method allows you to retrieve the current text and position of the editable.
(See [`98cb706`](https://github.com/kitten/use-editable/commit/98cb70625f35254c0e349f129a05edb43d39a3c3))
(See [`98cb706`](https://github.com/FormidableLabs/use-editable/commit/98cb70625f35254c0e349f129a05edb43d39a3c3))

## 2.2.2

- Fix regression from `2.2.1`, which would misplace the indentation pattern and not recognise lines with content when backspace is pressed.
(See [`bc2be15`](https://github.com/kitten/use-editable/commit/bc2be1530e1d85949bd9300d62547ed62e04e43a))
(See [`bc2be15`](https://github.com/FormidableLabs/use-editable/commit/bc2be1530e1d85949bd9300d62547ed62e04e43a))

## 2.2.1

- Add space-only indentation when `opts.indentation` is passed. This means that `useEditable` now inserts spaces over tabs when `opts.indentation` is set and overrides the
default backspace behaviour to delete multiple spaces as needed.
(See [`9291f6c`](https://github.com/kitten/use-editable/commit/9291f6ccdb9a6cfcfba38f59ead89a2024ec2bee))
(See [`9291f6c`](https://github.com/FormidableLabs/use-editable/commit/9291f6ccdb9a6cfcfba38f59ead89a2024ec2bee))

## 2.2.0

- Add `Edit#move()` method to edit the caret position programmatically. The caret can now be moved to a specific character index or row/column coordinates.
(See [`15cea68`](https://github.com/kitten/use-editable/commit/15cea6817242e30deb8bda9996060b9dd11db1ab))
(See [`15cea68`](https://github.com/FormidableLabs/use-editable/commit/15cea6817242e30deb8bda9996060b9dd11db1ab))

## 2.1.2

- Fix undo/redo key combination, which regressed previously, since it was switched to `event.key` rather than `event.code`
(See [`7147dca`](https://github.com/kitten/use-editable/commit/7147dcaa70e389ad9e0cdc6f92f76f6f6bcd724d))
(See [`7147dca`](https://github.com/FormidableLabs/use-editable/commit/7147dcaa70e389ad9e0cdc6f92f76f6f6bcd724d))
- Fix changes from being flushed to eagerly, which was meant to preserve the selected ranges more eagerly
(See [`1feaec5`](https://github.com/kitten/use-editable/commit/1feaec57e72c0edbefaf81464856656662baf89c))
(See [`1feaec5`](https://github.com/FormidableLabs/use-editable/commit/1feaec57e72c0edbefaf81464856656662baf89c))

## 2.1.1

- Fix key repeats (held keys) not flushing changes correctly
(See [`3807bbf`](https://github.com/kitten/use-editable/commit/3807bbf6c143259d46cba52becf2c4f100fb6f69))
(See [`3807bbf`](https://github.com/FormidableLabs/use-editable/commit/3807bbf6c143259d46cba52becf2c4f100fb6f69))

## 2.1.0

- Support non-collpsed selection restoration, in other words, when a range is selected and the component updates in the meantime, the selection is restored correctly.
This is achieved by storing the selection's "extent", i.e. the number of characters it selects past its start.
(See [`a15f8fc`](https://github.com/kitten/use-editable/commit/a15f8fcd9c1731c98c1ee2d96b6b0ed19ad40355))
(See [`a15f8fc`](https://github.com/FormidableLabs/use-editable/commit/a15f8fcd9c1731c98c1ee2d96b6b0ed19ad40355))

## 2.0.2

- Fix inconsistency of deletion behaviour on the beginning of lines. Due to the lack of `plaintext-only` support in Firefox,
computing the current position would be relative to the root element, when plain text is selected. This makes it extremely difficult
to get the current position without small offsets.
(See [`1644f51`](https://github.com/kitten/use-editable/commit/1644f516ad7d4f3367f4fa9fad41268dd9084ddc))
(See [`1644f51`](https://github.com/FormidableLabs/use-editable/commit/1644f516ad7d4f3367f4fa9fad41268dd9084ddc))

## 2.0.1

- Fix `onChange` not being triggered when the cursor moves
(See [`9dfadda`](https://github.com/kitten/use-editable/commit/9dfadda649e7f4d2b850a7d90ddc0ed62f81a041))
(See [`9dfadda`](https://github.com/FormidableLabs/use-editable/commit/9dfadda649e7f4d2b850a7d90ddc0ed62f81a041))

## 2.0.0

- Add `Edit` return value to `useEditable`. The `useEditable` hook now returns an object with multiple methods that may be useful
for controlling the editable's content, behaviour and cursor. Specifically it returns `Edit#update`, which was its previous return value
for updating its content, and `Edit#insert` to append new text.
(See [`c031d7e`](https://github.com/kitten/use-editable/commit/c031d7ee3e2551f6230df7fae0b03a3ce287d202))
(See [`c031d7e`](https://github.com/FormidableLabs/use-editable/commit/c031d7ee3e2551f6230df7fae0b03a3ce287d202))
Loading
Loading