UNPKG

@tldraw/editor

Version:

tldraw infinite canvas SDK (editor).

8 lines (7 loc) 1.66 kB
{ "version": 3, "sources": ["../../../src/lib/hooks/useTLStore.ts"], "sourcesContent": ["import { areObjectsShallowEqual } from '@tldraw/utils'\nimport { useState } from 'react'\nimport {\n\tTLStoreOptions,\n\tTLStoreSchemaOptions,\n\tcreateTLSchemaFromUtils,\n\tcreateTLStore,\n} from '../config/createTLStore'\n\n/** @public */\nexport function useTLStore(opts: TLStoreOptions) {\n\tconst [current, setCurrent] = useState(() => ({ store: createTLStore(opts), opts }))\n\n\tif (!areObjectsShallowEqual(current.opts, opts)) {\n\t\tconst next = { store: createTLStore(opts), opts }\n\t\tsetCurrent(next)\n\t\treturn next.store\n\t}\n\n\treturn current.store\n}\n\n/** @public */\nexport function useTLSchemaFromUtils(opts: TLStoreSchemaOptions) {\n\tconst [current, setCurrent] = useState(() => ({ opts, schema: createTLSchemaFromUtils(opts) }))\n\n\tif (!areObjectsShallowEqual(current.opts, opts)) {\n\t\tconst next = createTLSchemaFromUtils(opts)\n\t\tsetCurrent({ opts, schema: next })\n\t\treturn next\n\t}\n\n\treturn current.schema\n}\n"], "mappings": "AAAA,SAAS,8BAA8B;AACvC,SAAS,gBAAgB;AACzB;AAAA,EAGC;AAAA,EACA;AAAA,OACM;AAGA,SAAS,WAAW,MAAsB;AAChD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,OAAO,EAAE,OAAO,cAAc,IAAI,GAAG,KAAK,EAAE;AAEnF,MAAI,CAAC,uBAAuB,QAAQ,MAAM,IAAI,GAAG;AAChD,UAAM,OAAO,EAAE,OAAO,cAAc,IAAI,GAAG,KAAK;AAChD,eAAW,IAAI;AACf,WAAO,KAAK;AAAA,EACb;AAEA,SAAO,QAAQ;AAChB;AAGO,SAAS,qBAAqB,MAA4B;AAChE,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,OAAO,EAAE,MAAM,QAAQ,wBAAwB,IAAI,EAAE,EAAE;AAE9F,MAAI,CAAC,uBAAuB,QAAQ,MAAM,IAAI,GAAG;AAChD,UAAM,OAAO,wBAAwB,IAAI;AACzC,eAAW,EAAE,MAAM,QAAQ,KAAK,CAAC;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAQ;AAChB;", "names": [] }