Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into react-spring-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
vocksel committed Dec 4, 2023
2 parents a4bbe52 + 020c234 commit 60e138a
Show file tree
Hide file tree
Showing 80 changed files with 239 additions and 161 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/Components/Branding.lua → src/Common/Branding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local assets = require(flipbook.assets)
local useTheme = require(flipbook.Hooks.useTheme)
local Sprite = require(flipbook.Components.Sprite)
local useTheme = require(flipbook.Common.useTheme)
local Sprite = require(flipbook.Common.Sprite)

local e = React.createElement

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local flipbook = script:FindFirstAncestor("flipbook")

local Sift = require(flipbook.Packages.Sift)
local React = require(flipbook.Packages.React)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

export type Props = {
[string]: any,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local flipbook = script:FindFirstAncestor("flipbook")
return function()
local React = require(flipbook.Packages.React)
local ReactRoblox = require(flipbook.Packages.ReactRoblox)
local newFolder = require(flipbook.TestHelpers.newFolder)
local newFolder = require(flipbook.Testing.newFolder)
local useDescendants = require(script.Parent.useDescendants)

local container = Instance.new("ScreenGui")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local flipbook = script:FindFirstAncestor("flipbook")
return function()
local React = require(flipbook.Packages.React)
local ReactRoblox = require(flipbook.Packages.ReactRoblox)
local useEvent = require(flipbook.Hooks.useEvent)
local useEvent = require(script.Parent.useEvent)

local container = Instance.new("ScreenGui")
local root = ReactRoblox.createRoot(container)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local flipbook = script:FindFirstAncestor("flipbook")
return function()
local React = require(flipbook.Packages.React)
local ReactRoblox = require(flipbook.Packages.ReactRoblox)
local useEvent = require(flipbook.Hooks.useEvent)
local useEvent = require(flipbook.Common.useEvent)
local usePrevious = require(script.Parent.usePrevious)

local container = Instance.new("ScreenGui")
Expand Down
3 changes: 1 addition & 2 deletions src/Hooks/useTheme.lua → src/Common/useTheme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local themes = require(flipbook.themes)
local types = require(flipbook.types)

local MOCK_STUDIO = {
ThemeChanged = Instance.new("BindableEvent").Event,
Expand All @@ -20,7 +19,7 @@ local function useTheme()
return if success then result else MOCK_STUDIO
end, {})

local theme: types.Theme, set = React.useState(themes[studio.Theme.Name])
local theme: themes.Theme, set = React.useState(themes[studio.Theme.Name])

React.useEffect(function()
local conn = studio.ThemeChanged:Connect(function()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Hooks/useZoom.spec.lua → src/Common/useZoom.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local flipbook = script:FindFirstAncestor("flipbook")
return function()
local React = require(flipbook.Packages.React)
local ReactRoblox = require(flipbook.Packages.ReactRoblox)
local useEvent = require(flipbook.Hooks.useEvent)
local useEvent = require(flipbook.Common.useEvent)
local useZoom = require(script.Parent.useZoom)

local container = Instance.new("ScreenGui")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ local React = require(flipbook.Packages.React)
local ReactSpring = require(flipbook.Packages.ReactSpring)
local assets = require(flipbook.assets)
local constants = require(flipbook.constants)
local useTheme = require(flipbook.Hooks.useTheme)
local Sprite = require(flipbook.Components.Sprite)
local types = require(flipbook.types)
local useTheme = require(flipbook.Common.useTheme)
local Sprite = require(flipbook.Common.Sprite)
local types = require(flipbook.Explorer.types)

local e = React.createElement

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ local React = require(flipbook.Packages.React)
local ReactSpring = require(flipbook.Packages.ReactSpring)
local assets = require(flipbook.assets)
local constants = require(flipbook.constants)
local useTheme = require(flipbook.Hooks.useTheme)
local Sprite = require(flipbook.Components.Sprite)
local types = require(flipbook.types)
local useTheme = require(flipbook.Common.useTheme)
local Sprite = require(flipbook.Common.Sprite)
local types = require(flipbook.Explorer.types)

local e = React.createElement

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ local React = require(flipbook.Packages.React)
local Sift = require(flipbook.Packages.Sift)
local Directory = require(script.Directory)
local Story = require(script.Story)
local types = require(flipbook.types)
local types = require(flipbook.Explorer.types)
local getTreeDescendants = require(flipbook.Explorer.getTreeDescendants)

local e = React.createElement

Expand Down Expand Up @@ -57,10 +58,20 @@ local function Component(props: Props)
end
end

if props.filter and props.node.icon ~= "storybook" then
local match = props.node.name:lower():match(props.filter:lower())
if props.filter then
if props.node.icon == "story" and not props.node.name:lower():match(props.filter:lower()) then
return
end

local isEmpty = true
for _, descendant in getTreeDescendants(props.node) do
if descendant.name:lower():match(props.filter:lower()) then
isEmpty = false
break
end
end

if not match then
if isEmpty then
return
end
end
Expand Down
23 changes: 23 additions & 0 deletions src/Explorer/getTreeDescendants.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local flipbook = script:FindFirstAncestor("flipbook")

local types = require(flipbook.Explorer.types)

local function getTreeDescendants(root: types.ComponentTreeNode): { types.ComponentTreeNode }
local descendants: { types.ComponentTreeNode } = {}

local function traverse(node: types.ComponentTreeNode, isRoot: boolean)
if not isRoot then
table.insert(descendants, node)
end

for _, child in node.children do
traverse(child, false)
end
end

traverse(root, true)

return descendants
end

return getTreeDescendants
31 changes: 31 additions & 0 deletions src/Explorer/getTreeDescendants.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
return function()
local getTreeDescendants = require(script.Parent.getTreeDescendants)

it("should return an empty table when the root has no children", function()
local root = { name = "root", children = {} }

local result = getTreeDescendants(root)
expect(result).to.be.a("table")
expect(#result).to.equal(0)
end)

it("should return a table with all descendants when the root has children", function()
local child1 = { name = "child1", children = {} }
local child2 = { name = "child2", children = {} }
local root = { name = "root", children = { child1, child2 } }

local result = getTreeDescendants(root)
expect(result).to.be.a("table")
expect(#result).to.equal(2)
end)

it("should return a table with all descendants when the tree has multiple levels", function()
local grandchild = { name = "grandchild", children = {} }
local child = { name = "child", children = { grandchild } }
local root = { name = "root", children = { child } }

local result = getTreeDescendants(root)
expect(result).to.be.a("table")
expect(#result).to.equal(2)
end)
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local Component = require(script.Component)
local types = require(flipbook.types)
local types = require(script.types)

local e = React.createElement

Expand Down
14 changes: 14 additions & 0 deletions src/Explorer/types.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local flipbook = script:FindFirstAncestor("flipbook")

local storybookTypes = require(flipbook.Storybook.types)
type Storybook = storybookTypes.Storybook

export type ComponentTreeNode = {
name: string,
children: { ComponentTreeNode },
icon: string?,
instance: Instance?,
storybook: Storybook?,
}

return nil
2 changes: 1 addition & 1 deletion src/Components/Button.lua → src/Forms/Button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local Sift = require(flipbook.Packages.Sift)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

local e = React.createElement

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

export type Props = {
initialState: boolean,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

export type Props = {
placeholder: string?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local Dropdown = require(flipbook.Components.Fields.Dropdown)
local Dropdown = require(flipbook.Forms.Dropdown)

local controls = {
useDefault = true,
Expand Down
4 changes: 2 additions & 2 deletions src/Components/InputField.lua → src/Forms/InputField.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local Sift = require(flipbook.Packages.Sift)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

local e = React.createElement

Expand All @@ -14,7 +14,7 @@ local defaultProps = {

export type Props = typeof(defaultProps) & {
layoutOrder: number?,
onSubmit: ((text: string) -> ()),
onSubmit: (text: string) -> (),
onFocus: (() -> ())?,
onFocusLost: (() -> ())?,
onTextChange: ((new: string, old: string) -> ())?,
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/Components/Searchbar.lua → src/Forms/Searchbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ local ReactSpring = require(flipbook.Packages.ReactSpring)
local Sift = require(flipbook.Packages.Sift)
local assets = require(flipbook.assets)
local constants = require(flipbook.constants)
local useTheme = require(flipbook.Hooks.useTheme)
local mapRanges = require(flipbook.Modules.mapRanges)
local InputField = require(flipbook.Components.InputField)
local Sprite = require(flipbook.Components.Sprite)
local useTheme = require(flipbook.Common.useTheme)
local mapRanges = require(flipbook.Common.mapRanges)
local InputField = require(flipbook.Forms.InputField)
local Sprite = require(flipbook.Common.Sprite)

local e = React.createElement

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local Sift = require(flipbook.Packages.Sift)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

local defaultProps = {
AutomaticSize = Enum.AutomaticSize.XY,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

local e = React.createElement

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

local e = React.createElement

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Navbar/Item.lua → src/Navigation/Item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local flipbook = script:FindFirstAncestor("flipbook")
local React = require(flipbook.Packages.React)
local ReactSpring = require(flipbook.Packages.ReactSpring)
local constants = require(flipbook.constants)
local useTheme = require(flipbook.Hooks.useTheme)
local useTheme = require(flipbook.Common.useTheme)

local e = React.createElement

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local RunService = game:GetService("RunService")
local Sift = require(flipbook.Packages.Sift)
local React = require(flipbook.Packages.React)
local PluginContext = require(flipbook.Plugin.PluginContext)
local types = require(flipbook.types)
local types = require(flipbook.Panels.types)

local defaultProps = {
size = 8, -- px
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local Sift = require(flipbook.Packages.Sift)
local DragHandle = require(flipbook.Components.DragHandle)
local types = require(flipbook.types)
local DragHandle = require(flipbook.Panels.DragHandle)
local types = require(flipbook.Panels.types)

local defaultProps = {
dragHandleSize = 8, -- px
Expand Down
File renamed without changes.
24 changes: 14 additions & 10 deletions src/Components/Sidebar.lua → src/Panels/Sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@ local flipbook = script:FindFirstAncestor("flipbook")

local React = require(flipbook.Packages.React)
local constants = require(flipbook.constants)
local createStoryNodes = require(flipbook.Story.createStoryNodes)
local Branding = require(flipbook.Components.Branding)
local ComponentTree = require(flipbook.Components.ComponentTree)
local Searchbar = require(flipbook.Components.Searchbar)
local ScrollingFrame = require(flipbook.Components.ScrollingFrame)
local useTheme = require(flipbook.Hooks.useTheme)
local types = require(flipbook.types)
local createStoryNodes = require(flipbook.Storybook.createStoryNodes)
local Branding = require(flipbook.Common.Branding)
local ComponentTree = require(flipbook.Explorer)
local Searchbar = require(flipbook.Forms.Searchbar)
local ScrollingFrame = require(flipbook.Common.ScrollingFrame)
local useTheme = require(flipbook.Common.useTheme)
local storybookTypes = require(flipbook.Storybook.types)
local explorerTypes = require(flipbook.Explorer.types)

type Storybook = storybookTypes.Storybook
type ComponentTreeNode = explorerTypes.ComponentTreeNode

local e = React.createElement

type Props = {
layoutOrder: number?,
selectStory: (ModuleScript) -> (),
selectStorybook: (types.Storybook) -> (),
storybooks: { types.Storybook },
selectStorybook: (Storybook) -> (),
storybooks: { Storybook },
}

local function Sidebar(props: Props)
local theme = useTheme()

local activeNode, setActiveNode = React.useState(nil)
local onClick = React.useCallback(function(node: types.ComponentTreeNode)
local onClick = React.useCallback(function(node: ComponentTreeNode)
if node.instance and node.instance:IsA("ModuleScript") and node.name:match(constants.STORY_NAME_PATTERN) then
if node.storybook then
props.selectStorybook(node.storybook)
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/Panels/types.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type DragHandle = "Top" | "Right" | "Bottom" | "Left"

return nil
Loading

0 comments on commit 60e138a

Please sign in to comment.