Split @tldraw/state into @tldraw/state and @tldraw/state-react (#4170)
The backend code uses `@tldraw/state`, which is fine, but the package has a peer dependency on `react`, which is not fine to impose on backend consumers. So let's split this up again. ### Change type - [ ] `bugfix` - [ ] `improvement` - [ ] `feature` - [x] `api` - [x] `other` ### Test plan 1. Create a shape... 2. - [ ] Unit tests - [ ] End to end tests ### Release notes - Fixed a bug with…
This commit is contained in:
parent
719332d272
commit
7ba4040e84
68 changed files with 243 additions and 121 deletions
|
@ -79,15 +79,15 @@ import { TLStoreSnapshot } from '@tldraw/tlschema';
|
||||||
import { TLUnknownBinding } from '@tldraw/tlschema';
|
import { TLUnknownBinding } from '@tldraw/tlschema';
|
||||||
import { TLUnknownShape } from '@tldraw/tlschema';
|
import { TLUnknownShape } from '@tldraw/tlschema';
|
||||||
import { TLVideoAsset } from '@tldraw/tlschema';
|
import { TLVideoAsset } from '@tldraw/tlschema';
|
||||||
import { track } from '@tldraw/state';
|
import { track } from '@tldraw/state-react';
|
||||||
import { transact } from '@tldraw/state';
|
import { transact } from '@tldraw/state';
|
||||||
import { transaction } from '@tldraw/state';
|
import { transaction } from '@tldraw/state';
|
||||||
import { UnknownRecord } from '@tldraw/store';
|
import { UnknownRecord } from '@tldraw/store';
|
||||||
import { useComputed } from '@tldraw/state';
|
import { useComputed } from '@tldraw/state-react';
|
||||||
import { useQuickReactor } from '@tldraw/state';
|
import { useQuickReactor } from '@tldraw/state-react';
|
||||||
import { useReactor } from '@tldraw/state';
|
import { useReactor } from '@tldraw/state-react';
|
||||||
import { useStateTracking } from '@tldraw/state';
|
import { useStateTracking } from '@tldraw/state-react';
|
||||||
import { useValue } from '@tldraw/state';
|
import { useValue } from '@tldraw/state-react';
|
||||||
import { VecModel } from '@tldraw/tlschema';
|
import { VecModel } from '@tldraw/tlschema';
|
||||||
import { whyAmIRunning } from '@tldraw/state';
|
import { whyAmIRunning } from '@tldraw/state';
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tldraw/state": "workspace:*",
|
"@tldraw/state": "workspace:*",
|
||||||
|
"@tldraw/state-react": "workspace:*",
|
||||||
"@tldraw/store": "workspace:*",
|
"@tldraw/store": "workspace:*",
|
||||||
"@tldraw/tlschema": "workspace:*",
|
"@tldraw/tlschema": "workspace:*",
|
||||||
"@tldraw/utils": "workspace:*",
|
"@tldraw/utils": "workspace:*",
|
||||||
|
|
|
@ -22,18 +22,20 @@ export {
|
||||||
atom,
|
atom,
|
||||||
computed,
|
computed,
|
||||||
react,
|
react,
|
||||||
track,
|
|
||||||
transact,
|
transact,
|
||||||
transaction,
|
transaction,
|
||||||
|
whyAmIRunning,
|
||||||
|
type Atom,
|
||||||
|
type Signal,
|
||||||
|
} from '@tldraw/state'
|
||||||
|
export {
|
||||||
|
track,
|
||||||
useComputed,
|
useComputed,
|
||||||
useQuickReactor,
|
useQuickReactor,
|
||||||
useReactor,
|
useReactor,
|
||||||
useStateTracking,
|
useStateTracking,
|
||||||
useValue,
|
useValue,
|
||||||
whyAmIRunning,
|
} from '@tldraw/state-react'
|
||||||
type Atom,
|
|
||||||
type Signal,
|
|
||||||
} from '@tldraw/state'
|
|
||||||
export {
|
export {
|
||||||
ErrorScreen,
|
ErrorScreen,
|
||||||
LoadingScreen,
|
LoadingScreen,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { track } from '@tldraw/state'
|
import { track } from '@tldraw/state-react'
|
||||||
import { modulate } from '@tldraw/utils'
|
import { modulate } from '@tldraw/utils'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useEditor } from '../hooks/useEditor'
|
import { useEditor } from '../hooks/useEditor'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { track } from '@tldraw/state'
|
import { track } from '@tldraw/state-react'
|
||||||
import { TLInstancePresence } from '@tldraw/tlschema'
|
import { TLInstancePresence } from '@tldraw/tlschema'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { Editor } from '../editor/Editor'
|
import { Editor } from '../editor/Editor'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useQuickReactor, useStateTracking } from '@tldraw/state'
|
import { useQuickReactor, useStateTracking } from '@tldraw/state-react'
|
||||||
import { TLShape, TLShapeId } from '@tldraw/tlschema'
|
import { TLShape, TLShapeId } from '@tldraw/tlschema'
|
||||||
import { memo, useCallback, useRef } from 'react'
|
import { memo, useCallback, useRef } from 'react'
|
||||||
import { ShapeUtil } from '../editor/shapes/ShapeUtil'
|
import { ShapeUtil } from '../editor/shapes/ShapeUtil'
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { react, useQuickReactor, useValue } from '@tldraw/state'
|
import { react } from '@tldraw/state'
|
||||||
|
import { useQuickReactor, useValue } from '@tldraw/state-react'
|
||||||
import { TLHandle, TLShapeId } from '@tldraw/tlschema'
|
import { TLHandle, TLShapeId } from '@tldraw/tlschema'
|
||||||
import { dedupe, modulate, objectMapValues } from '@tldraw/utils'
|
import { dedupe, modulate, objectMapValues } from '@tldraw/utils'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import { noop } from '@tldraw/utils'
|
import { noop } from '@tldraw/utils'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import { ComponentType, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
import { ComponentType, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import { useRef } from 'react'
|
import { useRef } from 'react'
|
||||||
import { useEditor } from '../../hooks/useEditor'
|
import { useEditor } from '../../hooks/useEditor'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useQuickReactor, useStateTracking, useValue } from '@tldraw/state'
|
import { useQuickReactor, useStateTracking, useValue } from '@tldraw/state-react'
|
||||||
import { TLShape, TLShapeId } from '@tldraw/tlschema'
|
import { TLShape, TLShapeId } from '@tldraw/tlschema'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import { memo, useLayoutEffect, useRef } from 'react'
|
import { memo, useLayoutEffect, useRef } from 'react'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import { TLShapeId } from '@tldraw/tlschema'
|
import { TLShapeId } from '@tldraw/tlschema'
|
||||||
import { memo, useRef } from 'react'
|
import { memo, useRef } from 'react'
|
||||||
import { useEditor } from '../../hooks/useEditor'
|
import { useEditor } from '../../hooks/useEditor'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import { useEditor } from '../../../hooks/useEditor'
|
import { useEditor } from '../../../hooks/useEditor'
|
||||||
import { Box } from '../../../primitives/Box'
|
import { Box } from '../../../primitives/Box'
|
||||||
import { getPerfectDashProps } from '../shared/getPerfectDashProps'
|
import { getPerfectDashProps } from '../shared/getPerfectDashProps'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useQuickReactor } from '@tldraw/state'
|
import { useQuickReactor } from '@tldraw/state-react'
|
||||||
import { TLCursorType } from '@tldraw/tlschema'
|
import { TLCursorType } from '@tldraw/tlschema'
|
||||||
import { PI, radiansToDegrees } from '../primitives/utils'
|
import { PI, radiansToDegrees } from '../primitives/utils'
|
||||||
import { useContainer } from './useContainer'
|
import { useContainer } from './useContainer'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { debugFlags } from '../utils/debug-flags'
|
import { debugFlags } from '../utils/debug-flags'
|
||||||
import { useContainer } from './useContainer'
|
import { useContainer } from './useContainer'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { TLKeyboardEventInfo } from '../editor/types/event-types'
|
import { TLKeyboardEventInfo } from '../editor/types/event-types'
|
||||||
import { preventDefault } from '../utils/dom'
|
import { preventDefault } from '../utils/dom'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import { TLShapeId } from '@tldraw/tlschema'
|
import { TLShapeId } from '@tldraw/tlschema'
|
||||||
import { useEditor } from './useEditor'
|
import { useEditor } from './useEditor'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import { useSvgExportContext } from '../editor/types/SvgExportContext'
|
import { useSvgExportContext } from '../editor/types/SvgExportContext'
|
||||||
import { useEditor } from './useEditor'
|
import { useEditor } from './useEditor'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import { TLShapeId } from '@tldraw/tlschema'
|
import { TLShapeId } from '@tldraw/tlschema'
|
||||||
import { useEditor } from './useEditor'
|
import { useEditor } from './useEditor'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useComputed, useValue } from '@tldraw/state'
|
import { useComputed, useValue } from '@tldraw/state-react'
|
||||||
import { uniq } from '../utils/uniq'
|
import { uniq } from '../utils/uniq'
|
||||||
import { useEditor } from './useEditor'
|
import { useEditor } from './useEditor'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useValue } from '@tldraw/state'
|
import { useValue } from '@tldraw/state-react'
|
||||||
import { TLInstancePresence } from '@tldraw/tlschema'
|
import { TLInstancePresence } from '@tldraw/tlschema'
|
||||||
import { useEditor } from './useEditor'
|
import { useEditor } from './useEditor'
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./.tsbuild",
|
"outDir": "./.tsbuild",
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
// TODO: enable these two options
|
|
||||||
"noImplicitOverride": false,
|
"noImplicitOverride": false,
|
||||||
"noImplicitReturns": false,
|
"noImplicitReturns": false,
|
||||||
"types": ["node", "@types/jest"]
|
"types": ["node", "@types/jest"]
|
||||||
|
@ -13,6 +12,9 @@
|
||||||
{
|
{
|
||||||
"path": "../state"
|
"path": "../state"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "../state-react"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "../store"
|
"path": "../store"
|
||||||
},
|
},
|
||||||
|
|
1
packages/state-react/LICENSE.md
Normal file
1
packages/state-react/LICENSE.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This code is licensed under the [tldraw license](https://github.com/tldraw/tldraw/blob/main/LICENSE.md)
|
3
packages/state-react/README.md
Normal file
3
packages/state-react/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# @tldraw/state
|
||||||
|
|
||||||
|
...
|
4
packages/state-react/api-extractor.json
Normal file
4
packages/state-react/api-extractor.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
||||||
|
"extends": "../../config/api-extractor.json"
|
||||||
|
}
|
47
packages/state-react/api-report.md
Normal file
47
packages/state-react/api-report.md
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
## API Report File for "@tldraw/state-react"
|
||||||
|
|
||||||
|
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||||
|
|
||||||
|
```ts
|
||||||
|
|
||||||
|
import { Atom } from '@tldraw/state';
|
||||||
|
import { AtomOptions } from '@tldraw/state';
|
||||||
|
import { Computed } from '@tldraw/state';
|
||||||
|
import { ComputedOptions } from '@tldraw/state';
|
||||||
|
import { FunctionComponent } from 'react';
|
||||||
|
import { default as React_2 } from 'react';
|
||||||
|
import { Signal } from '@tldraw/state';
|
||||||
|
|
||||||
|
// @public
|
||||||
|
export function track<T extends FunctionComponent<any>>(baseComponent: T): React_2.NamedExoticComponent<React_2.ComponentProps<T>>;
|
||||||
|
|
||||||
|
// @public
|
||||||
|
export function useAtom<Value, Diff = unknown>(
|
||||||
|
name: string,
|
||||||
|
valueOrInitialiser: (() => Value) | Value,
|
||||||
|
options?: AtomOptions<Value, Diff>): Atom<Value, Diff>;
|
||||||
|
|
||||||
|
// @public
|
||||||
|
export function useComputed<Value>(name: string, compute: () => Value, deps: any[]): Computed<Value>;
|
||||||
|
|
||||||
|
// @public (undocumented)
|
||||||
|
export function useComputed<Value, Diff = unknown>(name: string, compute: () => Value, opts: ComputedOptions<Value, Diff>, deps: any[]): Computed<Value>;
|
||||||
|
|
||||||
|
// @public (undocumented)
|
||||||
|
export function useQuickReactor(name: string, reactFn: () => void, deps?: any[]): void;
|
||||||
|
|
||||||
|
// @public (undocumented)
|
||||||
|
export function useReactor(name: string, reactFn: () => void, deps?: any[] | undefined): void;
|
||||||
|
|
||||||
|
// @public
|
||||||
|
export function useStateTracking<T>(name: string, render: () => T): T;
|
||||||
|
|
||||||
|
// @public
|
||||||
|
export function useValue<Value>(value: Signal<Value>): Value;
|
||||||
|
|
||||||
|
// @public (undocumented)
|
||||||
|
export function useValue<Value>(name: string, fn: () => Value, deps: unknown[]): Value;
|
||||||
|
|
||||||
|
// (No @packageDocumentation comment for this package)
|
||||||
|
|
||||||
|
```
|
74
packages/state-react/package.json
Normal file
74
packages/state-react/package.json
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
{
|
||||||
|
"name": "@tldraw/state-react",
|
||||||
|
"description": "A tiny little drawing app (react bindings for state).",
|
||||||
|
"version": "2.3.0",
|
||||||
|
"author": {
|
||||||
|
"name": "tldraw Inc.",
|
||||||
|
"email": "hello@tldraw.com"
|
||||||
|
},
|
||||||
|
"homepage": "https://tldraw.dev",
|
||||||
|
"license": "SEE LICENSE IN LICENSE.md",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/tldraw/tldraw"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/tldraw/tldraw/issues"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"tldraw",
|
||||||
|
"drawing",
|
||||||
|
"app",
|
||||||
|
"development",
|
||||||
|
"whiteboard",
|
||||||
|
"canvas",
|
||||||
|
"infinite"
|
||||||
|
],
|
||||||
|
"/* NOTE */": "These `main` and `types` fields are rewritten by the build script. They are not the actual values we publish",
|
||||||
|
"main": "./src/index.ts",
|
||||||
|
"types": "./.tsbuild/index.d.ts",
|
||||||
|
"/* GOTCHA */": "files will include ./dist and index.d.ts by default, add any others you want to include in here",
|
||||||
|
"files": [],
|
||||||
|
"scripts": {
|
||||||
|
"test-ci": "lazy inherit",
|
||||||
|
"test": "yarn run -T jest",
|
||||||
|
"test-coverage": "lazy inherit",
|
||||||
|
"build": "yarn run -T tsx ../../scripts/build-package.ts",
|
||||||
|
"build-api": "yarn run -T tsx ../../scripts/build-api.ts",
|
||||||
|
"prepack": "yarn run -T tsx ../../scripts/prepack.ts",
|
||||||
|
"postpack": "../../scripts/postpack.sh",
|
||||||
|
"pack-tarball": "yarn pack",
|
||||||
|
"lint": "yarn run -T tsx ../../scripts/lint.ts"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"preset": "config/jest/node",
|
||||||
|
"setupFiles": [
|
||||||
|
"raf/polyfill"
|
||||||
|
],
|
||||||
|
"moduleNameMapper": {
|
||||||
|
"^~(.*)": "<rootDir>/src/$1"
|
||||||
|
},
|
||||||
|
"transformIgnorePatterns": [
|
||||||
|
"node_modules/(?!(nanoid)/)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tldraw/state": "workspace:*"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/lodash": "^4.14.188",
|
||||||
|
"@types/react": "^18.2.47",
|
||||||
|
"@types/react-test-renderer": "^18.0.0",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"react-test-renderer": "^18.2.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^18"
|
||||||
|
},
|
||||||
|
"typedoc": {
|
||||||
|
"readmeFile": "none",
|
||||||
|
"entryPoint": "./src/index.ts",
|
||||||
|
"displayName": "@tldraw/state",
|
||||||
|
"tsconfig": "./tsconfig.json"
|
||||||
|
}
|
||||||
|
}
|
7
packages/state-react/src/index.ts
Normal file
7
packages/state-react/src/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export { track } from './lib/track'
|
||||||
|
export { useAtom } from './lib/useAtom'
|
||||||
|
export { useComputed } from './lib/useComputed'
|
||||||
|
export { useQuickReactor } from './lib/useQuickReactor'
|
||||||
|
export { useReactor } from './lib/useReactor'
|
||||||
|
export { useStateTracking } from './lib/useStateTracking'
|
||||||
|
export { useValue } from './lib/useValue'
|
|
@ -1,6 +1,6 @@
|
||||||
|
import { atom } from '@tldraw/state'
|
||||||
import { createRef, forwardRef, memo, useEffect, useImperativeHandle } from 'react'
|
import { createRef, forwardRef, memo, useEffect, useImperativeHandle } from 'react'
|
||||||
import { ReactTestRenderer, act, create } from 'react-test-renderer'
|
import { ReactTestRenderer, act, create } from 'react-test-renderer'
|
||||||
import { atom } from '../core/Atom'
|
|
||||||
import { track } from './track'
|
import { track } from './track'
|
||||||
|
|
||||||
test("tracked components are memo'd", async () => {
|
test("tracked components are memo'd", async () => {
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { Atom } from '@tldraw/state'
|
||||||
import ReactTestRenderer from 'react-test-renderer'
|
import ReactTestRenderer from 'react-test-renderer'
|
||||||
import { Atom } from '../core/Atom'
|
|
||||||
import { useAtom } from './useAtom'
|
import { useAtom } from './useAtom'
|
||||||
import { useValue } from './useValue'
|
import { useValue } from './useValue'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { Atom, AtomOptions, atom } from '@tldraw/state'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Atom, AtomOptions, atom } from '../core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new atom and returns it. The atom will be created only once.
|
* Creates a new atom and returns it. The atom will be created only once.
|
|
@ -1,7 +1,6 @@
|
||||||
|
import { Atom, Computed } from '@tldraw/state'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import ReactTestRenderer from 'react-test-renderer'
|
import ReactTestRenderer from 'react-test-renderer'
|
||||||
import { Atom } from '../core/Atom'
|
|
||||||
import { Computed } from '../core/Computed'
|
|
||||||
import { useAtom } from './useAtom'
|
import { useAtom } from './useAtom'
|
||||||
import { useComputed } from './useComputed'
|
import { useComputed } from './useComputed'
|
||||||
import { useValue } from './useValue'
|
import { useValue } from './useValue'
|
|
@ -1,6 +1,6 @@
|
||||||
/* eslint-disable prefer-rest-params */
|
/* eslint-disable prefer-rest-params */
|
||||||
|
import { Computed, ComputedOptions, computed } from '@tldraw/state'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { Computed, ComputedOptions, computed } from '../core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new computed signal and returns it. The computed signal will be created only once.
|
* Creates a new computed signal and returns it. The computed signal will be created only once.
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { EMPTY_ARRAY, EffectScheduler } from '@tldraw/state'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { EMPTY_ARRAY, EffectScheduler } from '../core'
|
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export function useQuickReactor(name: string, reactFn: () => void, deps: any[] = EMPTY_ARRAY) {
|
export function useQuickReactor(name: string, reactFn: () => void, deps: any[] = EMPTY_ARRAY) {
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { EffectScheduler } from '@tldraw/state'
|
||||||
import { useEffect, useMemo, useRef } from 'react'
|
import { useEffect, useMemo, useRef } from 'react'
|
||||||
import { EffectScheduler } from '../core'
|
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export function useReactor(name: string, reactFn: () => void, deps: undefined | any[] = []) {
|
export function useReactor(name: string, reactFn: () => void, deps: undefined | any[] = []) {
|
|
@ -1,6 +1,6 @@
|
||||||
|
import { atom } from '@tldraw/state'
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { act, create, ReactTestRenderer } from 'react-test-renderer'
|
import { act, create, ReactTestRenderer } from 'react-test-renderer'
|
||||||
import { atom } from '../core/Atom'
|
|
||||||
import { useStateTracking } from './useStateTracking'
|
import { useStateTracking } from './useStateTracking'
|
||||||
|
|
||||||
describe('useStateTracking', () => {
|
describe('useStateTracking', () => {
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { EffectScheduler } from '@tldraw/state'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { EffectScheduler } from '../core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps some synchronous react render logic in a reactive tracking context.
|
* Wraps some synchronous react render logic in a reactive tracking context.
|
|
@ -1,7 +1,6 @@
|
||||||
|
import { Atom, Computed, atom } from '@tldraw/state'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import ReactTestRenderer from 'react-test-renderer'
|
import ReactTestRenderer from 'react-test-renderer'
|
||||||
import { Atom, atom } from '../core/Atom'
|
|
||||||
import { Computed } from '../core/Computed'
|
|
||||||
import { useAtom } from './useAtom'
|
import { useAtom } from './useAtom'
|
||||||
import { useComputed } from './useComputed'
|
import { useComputed } from './useComputed'
|
||||||
import { useValue } from './useValue'
|
import { useValue } from './useValue'
|
|
@ -1,6 +1,6 @@
|
||||||
/* eslint-disable prefer-rest-params */
|
/* eslint-disable prefer-rest-params */
|
||||||
|
import { Signal, computed, react } from '@tldraw/state'
|
||||||
import { useMemo, useRef, useSyncExternalStore } from 'react'
|
import { useMemo, useRef, useSyncExternalStore } from 'react'
|
||||||
import { Signal, computed, react } from '../core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the value from a signal and subscribes to it.
|
* Extracts the value from a signal and subscribes to it.
|
14
packages/state-react/tsconfig.json
Normal file
14
packages/state-react/tsconfig.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"extends": "../../config/tsconfig.base.json",
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["node_modules", "dist", ".tsbuild*"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./.tsbuild",
|
||||||
|
"rootDir": "src"
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "../state"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -4,9 +4,6 @@
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
|
||||||
import { FunctionComponent } from 'react';
|
|
||||||
import { default as React_2 } from 'react';
|
|
||||||
|
|
||||||
// @internal
|
// @internal
|
||||||
export class ArraySet<T> {
|
export class ArraySet<T> {
|
||||||
add(elem: T): boolean;
|
add(elem: T): boolean;
|
||||||
|
@ -162,9 +159,6 @@ export interface Signal<Value, Diff = unknown> {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @public
|
|
||||||
export function track<T extends FunctionComponent<any>>(baseComponent: T): React_2.NamedExoticComponent<React_2.ComponentProps<T>>;
|
|
||||||
|
|
||||||
// @public
|
// @public
|
||||||
export function transact<T>(fn: () => T): T;
|
export function transact<T>(fn: () => T): T;
|
||||||
|
|
||||||
|
@ -180,33 +174,6 @@ export type UNINITIALIZED = typeof UNINITIALIZED;
|
||||||
// @public
|
// @public
|
||||||
export function unsafe__withoutCapture<T>(fn: () => T): T;
|
export function unsafe__withoutCapture<T>(fn: () => T): T;
|
||||||
|
|
||||||
// @public
|
|
||||||
export function useAtom<Value, Diff = unknown>(
|
|
||||||
name: string,
|
|
||||||
valueOrInitialiser: (() => Value) | Value,
|
|
||||||
options?: AtomOptions<Value, Diff>): Atom<Value, Diff>;
|
|
||||||
|
|
||||||
// @public
|
|
||||||
export function useComputed<Value>(name: string, compute: () => Value, deps: any[]): Computed<Value>;
|
|
||||||
|
|
||||||
// @public (undocumented)
|
|
||||||
export function useComputed<Value, Diff = unknown>(name: string, compute: () => Value, opts: ComputedOptions<Value, Diff>, deps: any[]): Computed<Value>;
|
|
||||||
|
|
||||||
// @public (undocumented)
|
|
||||||
export function useQuickReactor(name: string, reactFn: () => void, deps?: any[]): void;
|
|
||||||
|
|
||||||
// @public (undocumented)
|
|
||||||
export function useReactor(name: string, reactFn: () => void, deps?: any[] | undefined): void;
|
|
||||||
|
|
||||||
// @public
|
|
||||||
export function useStateTracking<T>(name: string, render: () => T): T;
|
|
||||||
|
|
||||||
// @public
|
|
||||||
export function useValue<Value>(value: Signal<Value>): Value;
|
|
||||||
|
|
||||||
// @public (undocumented)
|
|
||||||
export function useValue<Value>(name: string, fn: () => Value, deps: unknown[]): Value;
|
|
||||||
|
|
||||||
// @public
|
// @public
|
||||||
export function whyAmIRunning(): void;
|
export function whyAmIRunning(): void;
|
||||||
|
|
||||||
|
|
|
@ -54,13 +54,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash": "^4.14.188",
|
"@types/lodash": "^4.14.188",
|
||||||
"@types/react": "^18.2.47",
|
"lodash": "^4.17.21"
|
||||||
"@types/react-test-renderer": "^18.0.0",
|
|
||||||
"lodash": "^4.17.21",
|
|
||||||
"react-test-renderer": "^18.2.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"react": "^18"
|
|
||||||
},
|
},
|
||||||
"typedoc": {
|
"typedoc": {
|
||||||
"readmeFile": "none",
|
"readmeFile": "none",
|
||||||
|
|
|
@ -1,3 +1,33 @@
|
||||||
/* eslint-disable local/no-export-star */
|
import { singleton } from './lib/helpers'
|
||||||
export * from './lib/core'
|
|
||||||
export * from './lib/react'
|
export { ArraySet } from './lib/ArraySet'
|
||||||
|
export { atom, isAtom } from './lib/Atom'
|
||||||
|
export type { Atom, AtomOptions } from './lib/Atom'
|
||||||
|
export {
|
||||||
|
UNINITIALIZED,
|
||||||
|
computed,
|
||||||
|
getComputedInstance,
|
||||||
|
isUninitialized,
|
||||||
|
withDiff,
|
||||||
|
} from './lib/Computed'
|
||||||
|
export type { Computed, ComputedOptions, WithDiff } from './lib/Computed'
|
||||||
|
export { EffectScheduler, react, reactor } from './lib/EffectScheduler'
|
||||||
|
export type { EffectSchedulerOptions, Reactor } from './lib/EffectScheduler'
|
||||||
|
export { unsafe__withoutCapture, whyAmIRunning } from './lib/capture'
|
||||||
|
export { EMPTY_ARRAY } from './lib/helpers'
|
||||||
|
export { isSignal } from './lib/isSignal'
|
||||||
|
export { transact, transaction } from './lib/transactions'
|
||||||
|
export { RESET_VALUE } from './lib/types'
|
||||||
|
export type { Child, ComputeDiff, Signal } from './lib/types'
|
||||||
|
|
||||||
|
// This should be incremented any time an API change is made. i.e. for additions or removals.
|
||||||
|
// Bugfixes need not increment this.
|
||||||
|
const currentApiVersion = 1
|
||||||
|
|
||||||
|
const actualApiVersion = singleton('apiVersion', () => currentApiVersion)
|
||||||
|
|
||||||
|
if (actualApiVersion !== currentApiVersion) {
|
||||||
|
throw new Error(
|
||||||
|
`You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
import { singleton } from './helpers'
|
|
||||||
|
|
||||||
export { ArraySet } from './ArraySet'
|
|
||||||
export { atom, isAtom } from './Atom'
|
|
||||||
export type { Atom, AtomOptions } from './Atom'
|
|
||||||
export { UNINITIALIZED, computed, getComputedInstance, isUninitialized, withDiff } from './Computed'
|
|
||||||
export type { Computed, ComputedOptions, WithDiff } from './Computed'
|
|
||||||
export { EffectScheduler, react, reactor } from './EffectScheduler'
|
|
||||||
export type { EffectSchedulerOptions, Reactor } from './EffectScheduler'
|
|
||||||
export { unsafe__withoutCapture, whyAmIRunning } from './capture'
|
|
||||||
export { EMPTY_ARRAY } from './helpers'
|
|
||||||
export { isSignal } from './isSignal'
|
|
||||||
export { transact, transaction } from './transactions'
|
|
||||||
export { RESET_VALUE } from './types'
|
|
||||||
export type { Child, ComputeDiff, Signal } from './types'
|
|
||||||
|
|
||||||
// This should be incremented any time an API change is made. i.e. for additions or removals.
|
|
||||||
// Bugfixes need not increment this.
|
|
||||||
const currentApiVersion = 1
|
|
||||||
|
|
||||||
const actualApiVersion = singleton('apiVersion', () => currentApiVersion)
|
|
||||||
|
|
||||||
if (actualApiVersion !== currentApiVersion) {
|
|
||||||
throw new Error(
|
|
||||||
`You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.`
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
export { track } from './track'
|
|
||||||
export { useAtom } from './useAtom'
|
|
||||||
export { useComputed } from './useComputed'
|
|
||||||
export { useQuickReactor } from './useQuickReactor'
|
|
||||||
export { useReactor } from './useReactor'
|
|
||||||
export { useStateTracking } from './useStateTracking'
|
|
||||||
export { useValue } from './useValue'
|
|
15
yarn.lock
15
yarn.lock
|
@ -6110,6 +6110,7 @@ __metadata:
|
||||||
"@testing-library/jest-dom": "npm:^5.16.5"
|
"@testing-library/jest-dom": "npm:^5.16.5"
|
||||||
"@testing-library/react": "npm:^14.0.0"
|
"@testing-library/react": "npm:^14.0.0"
|
||||||
"@tldraw/state": "workspace:*"
|
"@tldraw/state": "workspace:*"
|
||||||
|
"@tldraw/state-react": "workspace:*"
|
||||||
"@tldraw/store": "workspace:*"
|
"@tldraw/store": "workspace:*"
|
||||||
"@tldraw/tlschema": "workspace:*"
|
"@tldraw/tlschema": "workspace:*"
|
||||||
"@tldraw/utils": "workspace:*"
|
"@tldraw/utils": "workspace:*"
|
||||||
|
@ -6224,10 +6225,11 @@ __metadata:
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@tldraw/state@workspace:*, @tldraw/state@workspace:packages/state":
|
"@tldraw/state-react@workspace:*, @tldraw/state-react@workspace:packages/state-react":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@tldraw/state@workspace:packages/state"
|
resolution: "@tldraw/state-react@workspace:packages/state-react"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
"@tldraw/state": "workspace:*"
|
||||||
"@types/lodash": "npm:^4.14.188"
|
"@types/lodash": "npm:^4.14.188"
|
||||||
"@types/react": "npm:^18.2.47"
|
"@types/react": "npm:^18.2.47"
|
||||||
"@types/react-test-renderer": "npm:^18.0.0"
|
"@types/react-test-renderer": "npm:^18.0.0"
|
||||||
|
@ -6238,6 +6240,15 @@ __metadata:
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
"@tldraw/state@workspace:*, @tldraw/state@workspace:packages/state":
|
||||||
|
version: 0.0.0-use.local
|
||||||
|
resolution: "@tldraw/state@workspace:packages/state"
|
||||||
|
dependencies:
|
||||||
|
"@types/lodash": "npm:^4.14.188"
|
||||||
|
lodash: "npm:^4.17.21"
|
||||||
|
languageName: unknown
|
||||||
|
linkType: soft
|
||||||
|
|
||||||
"@tldraw/store@workspace:*, @tldraw/store@workspace:packages/store":
|
"@tldraw/store@workspace:*, @tldraw/store@workspace:packages/store":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@tldraw/store@workspace:packages/store"
|
resolution: "@tldraw/store@workspace:packages/store"
|
||||||
|
|
Loading…
Reference in a new issue