@rbxts/scribe-react 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 ericplane
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ericplane
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1 +1 @@
1
- {"version":"2.5.0","format":1,"description":"Segments are [packedLine, sourceLine]. Use the last segment at or before the packed line, then add its line offset.","files":{"addons/ui/ScribeReact.luau":{"sourceSha256":"129371347fee37556b753b9ba8c1ba7a20f4a5764c595b505cd53ec3d6b8eb0b","packedSha256":"6e85c1c51649d96cd3b8b3106766f782f1373103ffad31a5e1cbfea632127929","segments":[[1,1]],"packagePath":"init.luau"}}}
1
+ {"version":"2.6.1","format":1,"description":"Segments are [packedLine, sourceLine]. Use the last segment at or before the packed line, then add its line offset.","files":{"addons/ui/ScribeReact.luau":{"sourceSha256":"f41d3f612836b11a19a9b01da12d276e10bd1887a57c086b4e985369825260c1","packedSha256":"f41d3f612836b11a19a9b01da12d276e10bd1887a57c086b4e985369825260c1","segments":[[1,1]],"packagePath":"init.luau"}}}
package/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- import type React = require("@rbxts/react");
2
- import type Scribe from "@rbxts/scribe";
3
-
4
- /** Bind the shared Luau adapter to the React installation used by your game. */
5
- declare function ScribeReact(react: Pick<typeof React, "useState" | "useEffect" | "useBinding">): ScribeReact.Adapter;
6
-
7
- declare namespace ScribeReact {
8
- interface Adapter {
9
- /** Use inside a component. Changes re-render the component. */
10
- readonly useScribe: <T>(this: void, accessor: Scribe.ReadableNode<T>) => T;
11
- /** Use inside a component. Changes update the binding without a re-render. */
12
- readonly useScribeBinding: <T>(this: void, accessor: Scribe.ReadableNode<T>) => React.Binding<T>;
13
- }
14
- }
15
-
16
- export = ScribeReact;
1
+ import type React = require("@rbxts/react");
2
+ import type Scribe from "@rbxts/scribe";
3
+
4
+ /** Bind the shared Luau adapter to the React installation used by your game. */
5
+ declare function ScribeReact(react: Pick<typeof React, "useState" | "useEffect" | "useBinding">): ScribeReact.Adapter;
6
+
7
+ declare namespace ScribeReact {
8
+ interface Adapter {
9
+ /** Use inside a component. Changes re-render the component. */
10
+ readonly useScribe: <T>(this: void, accessor: Scribe.ReadableNode<T>) => T;
11
+ /** Use inside a component. Changes update the binding without a re-render. */
12
+ readonly useScribeBinding: <T>(this: void, accessor: Scribe.ReadableNode<T>) => React.Binding<T>;
13
+ }
14
+ }
15
+
16
+ export = ScribeReact;
package/init.luau CHANGED
@@ -1,33 +1,74 @@
1
1
  --!strict
2
2
  -- React adapter. Copy into your game; not part of the Scribe package.
3
3
  -- local Scribe = require(path.to.ScribeReact)(React)
4
- -- local coins = Scribe.useScribe(Data.Coins) -- re-renders
5
- -- local coins = Scribe.useScribeBinding(Data.Coins) -- property only
6
- --
7
- -- useState + useEffect, not useSyncExternalStore: that is React 18 and jsdotlua
8
- -- React 17.2.1 does not export it.
9
-
10
- return function(React: any)
11
- local Adapter = {}
12
-
13
- --- State tracking one accessor. Re-renders on every change.
14
- function Adapter.useScribe(accessor: any): any
15
- local value, setValue = React.useState(accessor.Get)
4
+ -- local coins = Scribe.useScribe(Data.Coins) -- number; re-renders
5
+ -- local coins = Scribe.useScribeBinding(Data.Coins) -- Binding<number>; property only
6
+ -- Uses jsdotlua React 17.2.1 hooks.
7
+
8
+ export type Disconnect = () -> ()
9
+
10
+ export type Readable<T> = {
11
+ --[[
12
+ Returns the current value.
13
+ ]]
14
+ read Get: () -> T,
15
+ --[[
16
+ Runs on future changes and returns a disconnect function.
17
+ ]]
18
+ read Changed: (callback: (new: T, old: T) -> ()) -> Disconnect,
19
+ }
20
+
21
+ -- Matches react-lua's binding type.
22
+ type CoreBinding<T> = {
23
+ --[[
24
+ Returns the current binding value.
25
+ ]]
26
+ getValue: (self: CoreBinding<T>) -> T,
27
+ _source: string?,
28
+ }
29
+ type BindingMap = {
30
+ --[[
31
+ Creates a binding that transforms this binding's value.
32
+ ]]
33
+ map: <T, U>(self: CoreBinding<T> & BindingMap, (T) -> U) -> BindingMap & CoreBinding<U>,
34
+ }
35
+ export type Binding<T> = CoreBinding<T> & BindingMap
36
+
37
+ export type React = {
38
+ read useState: (initialState: any) -> (any, any),
39
+ read useEffect: (create: any, deps: any) -> (),
40
+ read useBinding: (initialValue: any) -> (any, any),
41
+ }
42
+
43
+ export type Adapter = {
44
+ --[[
45
+ Tracks an accessor and re-renders when it changes.
46
+ ]]
47
+ useScribe: <T>(accessor: Readable<T>) -> T,
48
+ --[[
49
+ Updates a bound property without re-rendering.
50
+ ]]
51
+ useScribeBinding: <T>(accessor: Readable<T>) -> Binding<T>,
52
+ }
53
+
54
+ --[[
55
+ Creates React hooks for Scribe accessors.
56
+ ]]
57
+ return function(React: React): Adapter
58
+ local function useScribe<T>(accessor: Readable<T>): T
59
+ local state: T, setValue: (T) -> () = React.useState(accessor.Get)
16
60
  React.useEffect(function()
17
- -- Re-read before subscribing: a write landing between render and effect is
18
- -- otherwise missed, and the UI sits on the stale first value forever.
61
+ -- Catch writes between render and the effect.
19
62
  setValue(accessor.Get())
20
63
  return accessor.Changed(function(new)
21
64
  setValue(new)
22
65
  end)
23
66
  end, { accessor })
24
- return value
67
+ return state
25
68
  end
26
69
 
27
- --- A binding instead of state: updates the property without re-rendering. Prefer it
28
- --- for a value that only feeds Text or Size.
29
- function Adapter.useScribeBinding(accessor: any): any
30
- local binding, setBinding = React.useBinding(accessor.Get())
70
+ local function useScribeBinding<T>(accessor: Readable<T>): Binding<T>
71
+ local binding: Binding<T>, setBinding: (T) -> () = React.useBinding(accessor.Get())
31
72
  React.useEffect(function()
32
73
  setBinding(accessor.Get())
33
74
  return accessor.Changed(function(new)
@@ -37,5 +78,8 @@ return function(React: any)
37
78
  return binding
38
79
  end
39
80
 
40
- return Adapter
81
+ return {
82
+ useScribe = useScribe,
83
+ useScribeBinding = useScribeBinding,
84
+ }
41
85
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/scribe-react",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
4
4
  "description": "Optional react addon for Scribe",
5
5
  "main": "init.luau",
6
6
  "types": "index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "homepage": "https://scribe.ericplane.dev/",
13
13
  "author": "ericplane",
14
14
  "peerDependencies": {
15
- "@rbxts/scribe": "^2.5.0",
15
+ "@rbxts/scribe": "^2.6.1",
16
16
  "@rbxts/react": "^17.0.0 || ^17.3.7-ts.2"
17
17
  },
18
18
  "publishConfig": {