rnbw.dev
v0.1
editin rnbw, your design is your code, and your code is your design. you can develop not just inside rnbw but also for rnbw to enhance it with the desired feature.
you can create custom actions and extensions that improve or extend rnbw's ux. all of this becomes possible with the help of the rnbw apis.
rnbw apis supports various operation on rnbw which are related to project files, node tree, and code view. you can get the details like current open file, or open an existing file.
find the current selected node, and much more. you can use the different apis together to expand the limits of what you can do with rnbw.
As rnbw is built on top of react and typescript, therefore APIs in rnbw are exposed via react custom hook. As rnbw APIs are react custom hooks, so they can be consumed only in a react component or another react custom hook.
To get access to rnbw APIs all you need to do is:
const rnbw = useRnbw()
Every files in rnbw consists of a tree of folders and files. at the root of every files is a folder node, and from that node stems sub folder or files.
Files have a number of properties associated with them. some of these are global properties, that exist on every file, whereas other file properties will be specific to the type of file or folder.
example
Creates a new file with the provided name and extension.
params: An object containing the following properties
rnbw.files.createFile(params)
rnbw.files.createFile("about", "html")
Creates a new folder with the provided name. If no name is provided the default folder name is `untitled`.
params: An object containing the following properties
rnbw.files.createFolder(params)
rnbw.files.createFolder("styles")
Returns the tree of the files in the folder that is opened currently in "rnbw".
rnbw.files.getRootTree()
rnbw.files.getRootTree()
{
ROOT:{
uid:'ROOT',
parentUid: null,
name: 'rainbw',
isFile: false,
children: [
'ROOT/index.html',
'ROOT/index.js',
'ROOT/styles.css',
],
url: '/rnbw',
},
'ROOT/index.html': {
...
},
'ROOT/index.js': {
...
},
'ROOT/styles.css': {
...
}
}
Returns the details of the Folder whose uid is passed
params: An object containing the following properties
rnbw.files.getFolderTree(params)
rnbw.files.getFolderTree("ROOT/styles")
'ROOT/styles': {
uid: 'ROOT/styles',
parentUid: 'ROOT',
name: 'styles',
isFile: false,
children: [
'ROOT/styles/footer.css',
'ROOT/styles/navbar.css'
],
url: '/rainbow/styles',
}
Returns the current file details
rnbw.files.getCurrentFile()
rnbw.files.getCurrentFile() //Assuming index.html is the
current file
'ROOT/index.html': {
uid: 'ROOT/index.html',
parentUid: 'ROOT',
name: 'index',
isFile: true,
url: '/rainbow/index.html',
extension:'html',
content: 'content of the file currently',
},
Sets the `rnbw's clipboard state` with the uids passed along with the type as "copy".
params: An object containing the following properties
rnbw.files.copyFiles(params)
rnbw.files.copyFiles({
uids: ['ROOT/index.html',
'ROOT/about.html']
})
clipboardData: {
panel: 'file',
type: 'copy',
uids: [
'ROOT/index.html',
'ROOT/about.html'
]
},
Sets the `rnbw's clipboard state` with the uids passed along with the type as "cut".
params: An object containing the following properties
rnbw.files.cutFiles(params)
rnbw.files.cutFiles({
uids: ['ROOT/index.html',
'ROOT/about.html']
})
clipboardData: {
panel: 'file',
type: 'cut',
uids: [
'ROOT/index.html',
'ROOT/about.html'
]
},
Returns the uids of the selected files and directories in the file tree
rnbw.files.getSelectedFiles()
rnbw.files.getSelectedFiles()
['ROOT/styles/footer.css',
'ROOT/styles/navbar.css']
Sets the file whose uid is passed as the current active file.
params: An object containing the following properties
rnbw.files.setCurrentFile(params)
rnbw.files.setCurrentFile({
uid:'ROOT/about.html'
})
Updates the content of the current file with the content that is passed.
params: An object containing the following properties
rnbw.files.setCurrentFileContent(params)
rnbw.files.setCurrentFileContent({
content:'
<html>
<body>
<p> hello rnbw </p>
</body>
</html>')
Renames the file or folder with the name provided.
params: An object containing the following properties
rnbw.files.rename(params)
rnbw.files.rename({
uid:'ROOT/about.html',
newName:'about-us',
extension:'html'
})
Undo the state of the files one step at a time.
rnbw.files.undo()
rnbw.files.undo()
Redo the state of the files one step at a time.
rnbw.files.redo()
rnbw.files.redo()
Pastes the copied or cut files and folders to the location of the "destination Uid"
params: An object containing the following properties
rnbw.files.paste(params)
rnbw.files.paste({
uids:["ROOT/styles","ROOT/js/index.js"],
targetUid: "ROOT/src",
deleteSource: false
})
Moves the file(s) or folder(s) that are currently selected to the passed destination id.
params: An object containing the following properties
rnbw.files.move(params)
rnbw.files.move({
uids:["ROOT/styles","ROOT/js/index.js"],
targetUid:
"ROOT/src",
})
deletes the selected file(s) or folder(s).
params: An object containing the following properties
rnbw.files.remove(params)
rnbw.files.remove({
uids:[
'ROOT/about.html',
'ROOT/contact.html']
})
Whenever an HTML file is opened in rnbw, a node tree is created.
example
Adds a specified HTML element or comment tag to the code view based on the provided parameters.
params: An object containing the following properties
Returns the updated code, if successful.
rnbw.elements.add(params)
const result: string = rnbw.elements.add
({ tagName: 'div'});
Adds a copy of the selected html element as the child of the selected element's parent.
params: An object containing the following properties (optional):
Returns the updated code, if successful.
rnbw.elements.duplicate(params)
const result: string = rnbw.elements.duplicate()
returns the details of the element whose uid is passed
params:
rnbw.elements.getElement(elementUid)
rnbw.elements.getElement("761")
{
uid: "62",
parentUid: "40",
name: "div",
children: ["114", "115", "116", "117", "118"],
tagName: "div",
textContent: "",
attribs: {
class: "page gap-xl",
id: "code",
},
sourceCodeLocation: {
startLine: 714,
startCol: 9,
startOffset: 36632,
endLine: 728,
endCol: 15,
endOffset: 37258,
startTag:{...},
endTag: {...}
},
}
Returns the "uids" of the elements selected on the stage.
rnbw.elements.getSelectedElements()
rnbw.elements.getSelectedElements()
["761","854"]
Returns the settings object of the elements whose uid is passed.
params:
rnbw.elements.getElementSettings()
rnbw.elements.getElementSettings()
{
class:"box column"
style: "border: 1px solid white"
}
Copies the code of items in the code view to the clipboard. Optionally, it can update the clipboard with the copied code.
If multiple elements are selected then the elements are sorted by their "uid (unique Id)". And then the codes are joined together and copied to the system clipboard.
params: An object containing the following properties (optional):
Returns the copied code, if successful.
rnbw.elements.copy(params)
rnbw.elements.copy()
Selects the elements whose uids are passed replacing the existing selected elements.
If the uids passed doesn't exist then it does nothing.
rnbw.elements.setSelectedElements(elementsUid)
rnbw.elements.setSelectedElements(["215","456"])
Cuts the selected element.
Returns the cut code, and the updated code after cut, if successful.
rnbw.elements.cut()
rnbw.elements.cut()
Pasted the cut or copied elements at a specified position with respect to the selected element.
params: An object containing the following properties (optional):
rnbw.elements.paste(params: Ipaste = {})
const result: Promise<string> = paste();
groups the selected elements by wrapping them in a <div> container.
params: an object containing the following properties (optional):
Returns the updated code, if successful.
rnbw.elements.group(params)
rnbw.elements.group()
Ungroups the selected elements.
params: An object containing the following properties (optional):
Returns the updated code, if successful.
rnbw.elements.ungroup(params)
rnbw.elements.ungroup()
Moves the selected elements inside the target element based on the position.
params: An object containing the following properties:
rnbw.elements.move(params)
rnbw.elements.move({
targetUid: '202',
isBetween: true,
position: 2,
selectedUids: ['356', '357', '358x']
});
Updates the setting of the selected element. Attributes for the elements are passed in the form of key value pairs.
params: An object containing the following properties:
Returns:
rnbw.elements.updateSettings(params)
rnbw.elements.updateSetting({
settings:{
class:"box
column",
id:"hero-section"
}})
Undo the state of the elements by 1 step.
rnbw.elements.undo()
rnbw.elements.undo()
Redo the state of the elements by 1 step.
rnbw.elements.redo()
rnbw.elements.redo()
Deletes the elements whose uids are passed.
params: An object containing the following properties:
Returns the updated code, if successful.
rnbw.elements.remove(params)
rnbw.elements.remove({
uids:["261","351","401"],
skipUpdate:false
})
in rnbw, your design is your code, and your code is your design. you can develop not just inside rnbw but also for rnbw to enhance it with the desired feature.
you can create custom actions and extensions that improve or extend rnbw's ux. all of this becomes possible with the help of the rnbw apis.
To compose the actions we use the rnbw APIs which are exposed via useRnbw custom hook. As hooks can be used either in a React component or a react custom hook so actions are also react custom hooks.
There are two types of actions - internal and external. Internal actions are those which are developed by rnbw team and external actions are developed by the contributors of rnbw.
Think of a use case which you think will enhance your experience with rnbw. It can be related to something you want to do with your html content or something with the files.
//action examples
Remove all the attributes from
an element
or
Remove all the empty folders in a
project
All the actions reside inside the "action" folder in the root of the "rnbw". Now head to the actions directory inside rnbw and create a custom hook file for you action.
//syntax
rnbw > actions >
use<action>.action.tsx
//example
rnbw
> actions > useRemoveAllAttributes.action.tsx
Each action returns a config.The config contains following things:
export default function useTurnInto() { const rnbw = useRnbw(); const selectedElements = rnbw.elements.getSelectedElements();
function turnInto(tagName: string) {
/*perform all the steps
the get the desired results.*/
}
const config = {
name: "Turn Into",
execute: turnInto,
description: "Turn selected
elements into a new tag",
shortcuts: ["cmd+shift+t"],
};
return config;
}
you can use your custom action similar to any react custom hook in rnbw.
const action = useTurnInto()
const actionName = action.name
const execute = action.execute
const description = action.description
const shortcuts = action.shortcuts
extensions are created by the rnbw community to extend the functionality of rnbw. extensions can be as simple as showing some information or can be used to perform one or more actions.
users and organisations can use the power of extensions to customize and enhance their experience to create more efficient workflows.
a big welcome and thank you for considering contributing to rainbow! contributions are always welcome, and you can quickly get your fix or improvement slated for the next release.
the contributors’ community can be found on github discussions where you can ask questions, voice ideas, and share your projects.