Gathering detailed insights and metrics for @guardian/guration
Gathering detailed insights and metrics for @guardian/guration
Gathering detailed insights and metrics for @guardian/guration
Gathering detailed insights and metrics for @guardian/guration
npm install @guardian/guration
Typescript
Module System
Node Version
NPM Version
54.5
Supply Chain
92.8
Quality
80.4
Maintenance
100
Vulnerability
99.3
License
JavaScript (100%)
Total Downloads
8,722
Last Day
12
Last Week
14
Last Month
18
Last Year
373
1 Stars
122 Commits
10 Watching
1 Branches
16 Contributors
Latest Version
3.3.0
Package Id
@guardian/guration@3.3.0
Size
20.28 kB
NPM Version
6.1.0
Node Version
9.8.0
Publised On
04 Sept 2018
Cumulative downloads
Total Downloads
Last day
0%
12
Compared to previous day
Last week
1,300%
14
Compared to previous week
Last month
-52.6%
18
Compared to previous month
Last year
-54.6%
373
Compared to previous year
19
A module that allows you to validate drag and drop actions on a tree of data, culminating in 'edits' that describe the modification on a normalized data structure (rather than the whole tree). There are two types of edits a Move
and an Insert
. The drag and drop logic is handle by the Level
component, so references below to drag zones and drop zones will refer to the drag zones created using the Level
component.
Note that a valid drop doesn't changed the rendered tree, instead the expectation is that state updates will be made in the consumer appilcation in response to these edits that cause a render to the Guration
part of the app that then reflects these edits.
First it will be worth describing edits. Edits are objects that describe an update to the tree and will only be fired when they are deemed to be valid (i.e. a drop of some type
into a position that accepts that type
). Moves into the same position (i.e. moving an node into the drop zone either side of itself) will not fire edits, and edits that are invalid will fire errors.
Move
A Move
edit describes a move of a node from inside the Guration Root
context back into another valid position inside the same Guration Root
context. It has the following shape:
1type Move = { 2 type: 'MOVE', 3 payload: { 4 type, 5 id, 6 from: { 7 parent: { 8 type: string, 9 childrenField: string, 10 index: number, 11 id: string 12 } 13 }, 14 to: { 15 parent: { 16 type: string, 17 childrenField: string, 18 index: number, 19 id: string 20 }, 21 index: newIndex 22 } 23 }, 24 meta: Object 25};
Insert
An Insert
edit will fire for an insert of some item from outside that has been mapped in through mapIn
. It has the following shape:
1type Insert = { 2 type: 'INSERT', 3 payload: { 4 type: string, 5 id: string, 6 path: { 7 index: number, 8 parent: { 9 type: string, 10 childrenField: string, 11 index: number, 12 id: string 13 } 14 } 15 }, 16 meta: Object 17};
<Root />
This is the wrapper around a Guration
context and Levels
cannot be rendered outside of a Root
. It's component that allows you to listen for edits made from drag and drop actions.
id: string
This is the root id that will be used as the parent of the whole tree and will appear in edits that drop into drop zones for the root level of the tree.
type: string
Similarly to the id
this will describe the type of the root node (again, used in edits) but this is also what limits drops into this position: only drops of the same type can be made at the root level.
field?: string
This will set the childrenField
in an edit, which can allow for easier reflection on the type of edit to be made.
onChange?: (edit: Edit) => void
This expects a callback function that will receive an of (edit
)[#Edits] each time an action has happened.
onError?: (error: string) => void
A callback that will recieve strings describing errors regarding invalid drops. For example, dropping an node of one type into a level of another type or dropping an node into a child of itself.
mapIn?: { [string]: string => { id: string, type: string, meta?: Object } }
An object whose keys represent a type
on e.dataTransfer.types
that can be handle by the callback that is in the value position of the object. The callback will receive any data that is found when e.dataTranfer.getData(type)
is called and is expected to return an object of { id: string, type: string }
that can be used to validate and then generate an edit in a drop zone. This object can also have an optional meta
key to pass through to the any subsequent if required.
mapOut?: { [string]: (el: Object, type: string, id: string, path: Path[]) => string }
An object that does the opposite of mapIn
and describes how to transform a node into drag data. The keys on the object are the keys that will be called using e.dataTransfer.setData(key)
, allowing drags from here to other drop zones (possibly other Guration contexts).
<Level />
A Level
is repsonsible for defining the types for a specific level in the tree as well as defining the types for the nodes that are currently rendered in that position. It also provides the props for draggable nodes and renders drop zones between these nodes.
arr: <T: Object>[]
The array of nodes to map over. Passing this in allows the component to handle laying out drop zones between each node (using fragments) and plucking the id of each node in order to construct edits.
children: (item, getNodeProps, index) => ReactElement
This is not a React element but a function child. item
is an item in the array, getNodeProps()
is a function that will return the node props (such as the drag event handlers etc.) to spread on a React DOM node to make it draggable. In future it will taking a prop argument that will allow adding other props to the same Node. Currently, all event handlers that are added by these props, would be remove if adding the same event handlers to the same node.
type: string
Much like Root
this specifies both the time of the draggable nodes at this level and the type of node that can be dragged to this level.
field: ?string
Again much like Root
this specifies the childrenField
field of an edit that can help for making updates.
renderDrop: ?(getDropProps, { canDrop: boolean, isTarget: boolean }, index) => ReactElement
This is a function that will be used to render the drops between the draggable nodes rendered by children
. isOver
is much like :hover
pseduo-selector except that when dropOnNode
is true isTarget
will also be true when that position is the target position for a drop while hovering a node.
getKey: ?(el: T) => string
A function that returns the key from each object in the array, defaults to ({ id }) => id
dedupeType: ?string
Specifying this on a Level
will ensure that anything below this level that is of the same type
and has the same dedupeKey
will act as a move rather than an insert.
getDedupeKey: ?(el: T) => string
The function that returns the key for comapring items for deduping, defaults to getKey
.
dropOnNode: ?boolean
A boolean that defaults to true
, which specifics whether getNodeProps
will return props that allow dropping on top of the node. If this is true, dropping in the top 50% of the node will result in a drop at that node's index, and likewise dropping in the bottom 50% will result in a drop at the index after that node.
1const renderDrop = (getProps, { canDrop, isTarget }) => 2 <DropZone {...getProps()} canDrop={canDrop} isTarget={isTarget} />; 3 4const Front = ({ front }) => ( 5 <Root 6 id={front.id} 7 type="front" 8 onChange={console.log} 9 onError={console.log} 10 > 11 <Level 12 arr={front.collections} 13 type="collection" 14 renderDrop={renderDrop} 15 dedupeType="articleFragment" 16 > 17 {({ title, articleFragments }) => ( 18 <div> 19 <h1>{title}</h1> 20 <Indent> 21 <Level 22 arr={articleFragments} 23 type="articleFragment" 24 renderDrop={renderDrop} 25 > 26 {({ title, meta: { supporting } }, afNodeProps) => ( 27 <div> 28 <h1 {...afNodeProps()}>{title}</h1> 29 <Indent> 30 <Level 31 arr={supporting} 32 type="articleFragment" 33 renderDrop={renderDrop} 34 > 35 {({ title }, sNodeProps) => ( 36 <div> 37 <h1 {...sNodeProps()}>{title}</h1> 38 </div> 39 )} 40 </Level> 41 </Indent> 42 </div> 43 )} 44 </Level> 45 </Indent> 46 </div> 47 )} 48 </Level> 49 </Root> 50);
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
project is archived
Details
Reason
Found 0/17 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
82 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More