3.2.0 • Published 2 years ago

fractional-indexing v3.2.0

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
2 years ago

Fractional Indexing

This is based on Implementing Fractional Indexing by David Greenspan .

Fractional indexing is a technique to create an ordering that can be used for Realtime Editing of Ordered Sequences.

This implementation includes variable-length integers, and the prepend/append optimization described in David's article.

API

generateKeyBetween

Generate a single key in between two points.

generateKeyBetween(
  a: string | null | undefined, // start
  b: string | null | undefined, // end
  digits?: string | undefined = BASE_62_DIGITS, // optional character encoding
): string;
import { generateKeyBetween } from 'fractional-indexing';

const first = generateKeyBetween(null, null); // "a0"

// Insert after 1st
const second = generateKeyBetween(first, null); // "a1"

// Insert after 2nd
const third = generateKeyBetween(second, null); // "a2"

// Insert before 1st
const zeroth = generateKeyBetween(null, first); // "Zz"

// Insert in between 2nd and 3rd (midpoint)
const secondAndHalf = generateKeyBetween(second, third); // "a1V"

generateNKeysBetween

Use this when generating multiple keys at some known position, as it spaces out indexes more evenly and leads to shorter keys.

generateNKeysBetween(
  a: string | null | undefined, // start
  b: string | null | undefined, // end
  n: number // number of keys to generate evenly between start and end
  digits?: string | undefined = BASE_62_DIGITS, // optional character encoding
): string[];
import { generateNKeysBetween } from 'fractional-indexing';

const first = generateNKeysBetween(null, null, 2); // ['a0', 'a1']

// Insert two keys after 2nd
generateNKeysBetween(first[1], null, 2); // ['a2', 'a3']

// Insert two keys before 1st
generateNKeysBetween(null, first[0], 2); // ['Zy', 'Zz']

// Insert two keys in between 1st and 2nd (midpoints)
generateNKeysBetween(second, third, 2); // ['a0G', 'a0V']

Other Languages

These should be byte-for-byte compatible.

LanguageRepo
Gohttps://github.com/rocicorp/fracdex
Pythonhttps://github.com/httpie/fractional-indexing-python
@mui/studio-app@infinitebrahmanuniverse/nolb-frac@everything-registry/sub-chunk-1699@vanillahill99/blocksteaching_component_dstrapi-boing-adminstrapi-maxiphy-adminvscode-apollo@coasys/flux-kanban-view@collectionkit/corekalliope@meeehdi/strapi-admintuple-database@algogrind/blocks@alkemio/excalidraw@alisallon/blocksuite-blocks@bimbeo160/admin@blockeditor/blocks@blockmah/blocks@blocksuite/phasor@blocksuite/affine-model@blocksuite/block-std@blocksuite/blocks@blocksuite-zh/blocks@blocksuite/affine-block-surface@betternotion/excalidraw@cbi-blocksuite/blocks@brainhive/strapi-admin@digicms/admin@danhuyenphan/strapi-adminy-excalidrawtry_excalidraw_whiteboard@dwelle/excalidraw@fluxapp/kanban-view@fileverse-dev/excalidraw@edwardw483/excali@edwardw483/excaliwhitelist@geobrowser/gdk@kristiankostecky/excalidraw@lyn4ed/strapi-admin@lynched-test/strapi-admin@mahblock/blocks@mui/toolpad@mui/toolpad-app@mui/toolpad-core@musaev/strapiadmin@new_blocksuite_blakor/blocks@nexacarts/admin@excalidraw/excalidraw@editorsuite/blocks@moksmo/blocks@kerituni12/blocks@revesuite/phasor@pathintegral/affine-block-surface@pathintegral/affine-model@pathintegral/block-std@pathintegral/blocks@npclown/excalidraw@notud/excalidraw@opentechiz/excalidrawsahil_ccsahil_pkgsahil_ugngx-chk-dynamic-form-builderrn-strapi-adminsofty-note-blockshello_excalhello_excali@weiwenda/excalidraw@tmp_blocksuite_blakor/blocks@triplit/tuple-database@theodoresmotly/custom-strapi-admin@thenewvu/excalidraw@toolpad/studio@toolpad/studio-runtime@viconsol/admin@useblock/blocks@vo2-brand-experience/strapi-admin@zsviczian/excalidraw@zhtecinc/excalidrawchk-dynamic-form-buildercollabted-excalidrawd_teaching_componentdemotest_excalidemowork_excalidraweducatewhiteboard_pkgeasy-fractional-indexingexcalidraw_inside_checkexcalidraw_karatexcalidraw_master_sahilexcalidraw_master_test1excalidraw_new_test_00excalidraw_sigmathexcalidraw_vrandaexcalidraw_vranda_mamexcalidraw-collaborationexcal_inside_checkexcalidraw-local-collab-forkexcalidraw-ua5excalidraw-with-storage
3.2.0

2 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

2.0.0

4 years ago

1.3.0

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago