Installations
npm install @guardian/guration
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
9.8.0
NPM Version
6.1.0
Score
54.5
Supply Chain
92.8
Quality
80.4
Maintenance
100
Vulnerability
99.3
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
guardian
Download Statistics
Total Downloads
8,722
Last Day
12
Last Week
14
Last Month
18
Last Year
373
GitHub Statistics
1 Stars
122 Commits
10 Watching
1 Branches
16 Contributors
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
8,722
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
19
Guration
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.
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};
Component API
<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.
Props
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.
Props
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.
Example
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
- Warn: Repository is archived.
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
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 23 are checked with a SAST tool
Reason
82 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-c6rq-rjc2-86v2
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-9q64-mpxx-87fg
- Warn: Project is vulnerable to: GHSA-jc84-3g44-wf2q
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq
- Warn: Project is vulnerable to: GHSA-pc5p-h8pf-mvwp
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-f9cm-qmx5-m98h
- Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-gqgv-6jq5-jjj9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-hg79-j56m-fxgv
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-78cj-fxph-m83p
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.3
/10
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