• Stars
    star
    709
  • Rank 61,346 (Top 2 %)
  • Language
    HTML
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Angular JS Tree

Angular Tree Control

npm version Bower version Build Status Coverage Status

Pure AngularJS based tree control component.

ScreenShot

To get started, check out wix.github.io/angular-tree-control

Why yet another tree control

We have tried a number of tree controls built for angular and experience a lot of issues with each. As a result we decided to build a new tree control with the following design guidelines

  • Isolated scope - the tree control should not pollute the scope it is rendered at
  • Does not change the tree data - some tree implementations mark on the tree data the selection and expansion of nodes
  • Allows customization of the tree node label using the angular way - as an angular template
  • Supports large trees with minimal overhead
  • Reacts to changes in the tree data, updating the tree as required
  • Supports css styling, with three built in styles

Installation

Bower: bower install angular-tree-control

The tree control can be used as a Dom element or as an attribute.

Copy the script and css into your project and add a script and link tag to your page.

<script type="text/javascript" src="/angular-tree-control.js"></script>

<!-- Include context-menu module if you're going to use menu-id attribute -->
<script type="text/javascript" src="/context-menu.js"></script>

<!-- link for CSS when using the tree as a Dom element -->
<link rel="stylesheet" type="text/css" href="css/tree-control.css">

<!-- link for CSS when using the tree as an attribute -->
<link rel="stylesheet" type="text/css" href="css/tree-control-attribute.css">

Add a dependency to your application module.

angular.module('myApp', ['treeControl']);

Add tree elements to your Angular template

<!-- as a Dom element -->
<treecontrol class="tree-classic"
   tree-model="dataForTheTree"
   options="treeOptions"
   on-selection="showSelected(node)"
   selected-node="node1">
   employee: {{node.name}} age {{node.age}}
</treecontrol>
<!-- as an attribute -->
<div treecontrol class="tree-classic"
   tree-model="dataForTheTree"
   options="treeOptions"
   on-selection="showSelected(node)"
   selected-node="node1">
   employee: {{node.name}} age {{node.age}}
</div>

and add the data for the tree

$scope.treeOptions = {
    nodeChildren: "children",
    dirSelectable: true,
    injectClasses: {
        ul: "a1",
        li: "a2",
        liSelected: "a7",
        iExpanded: "a3",
        iCollapsed: "a4",
        iLeaf: "a5",
        label: "a6",
        labelSelected: "a8"
    }
}
$scope.dataForTheTree =
[
	{ "name" : "Joe", "age" : "21", "children" : [
		{ "name" : "Smith", "age" : "42", "children" : [] },
		{ "name" : "Gary", "age" : "21", "children" : [
			{ "name" : "Jenifer", "age" : "23", "children" : [
				{ "name" : "Dani", "age" : "32", "children" : [] },
				{ "name" : "Max", "age" : "34", "children" : [] }
			]}
		]}
	]},
	{ "name" : "Albert", "age" : "33", "children" : [] },
	{ "name" : "Ron", "age" : "29", "children" : [] }
];

Usage

Attributes of angular treecontrol

  • treecontrol : the treeview element.
  • element content : the template to evaluate against each node (and the parent scope of the tree) for the node label.
  • tree-model : [Node|Array[Node]] the tree data on the $scope. This can be an array of nodes or a single node.
  • selected-node : [Node], used when multiSelection=false. Binding for the selected node in the tree. Updating this value updates the selection displayed in the tree. Selecting a node in the tree will update this value.
  • selected-nodes : [Array[Node]], used when multiSelection=true. Binding for the selected nodes in the tree. Updating this value updates the selection displayed in the tree. Selecting a node in the tree will update this value.
  • expanded-nodes : [Array[Node]] binding for the expanded nodes in the tree. Updating this value updates the nodes that are expanded in the tree.
  • on-selection : (node, selected) callback called whenever selecting a node in the tree. The callback expression can use the selected node (node) and a boolean which indicates if the node was selected or deselected (selected).
  • on-node-toggle : (node, expanded) callback called whenever a node expands or collapses in the tree. The callback expression can use the toggled node (node) and a boolean which indicates expansion or collapse (expanded).
  • on-right-click : (node) callback called whenever a node is right-clicked.
  • options : different options to customize the tree control.
    • multiSelection : [Boolean] enable multiple nodes selection in the tree.

    • nodeChildren : the name of the property of each node that holds the node children. Defaults to 'children'.

    • dirSelectable : are directories (nodes with children) selectable? If not, clicking on the dir label will expand and contact the dir. Defaults to true.

    • allowDeselect : are nodes deselectable? If not, clicking on the label will not deselect node. Defaults to true.

    • equality : the function used to determine equality between old nodes and new ones when checking whether a replacement node should be expanded and/or marked as selected. Defaults to a function which uses angular.equals() on everything except the property indicated in nodeChildren.

    • isLeaf : function (node) -> boolean used to determine if a node is a leaf or branch. The default function checks for existence of children of the node to determine leaf or branch.

    • injectClasses : allows to inject additional CSS classes into the tree DOM

      • ul : inject classes into the ul elements
      • li : inject classes into the li elements. Also allows for an external function that takes a single node parameter.
      // Example:
      function getBranchClass(node) {
          // `matchingNodeIds` is local to a parent component controller.
          if (matchingNodeIds.includes(node.id)) {
              return "tree-branch-match";
          }
      }
      • liSelected : inject classes into the li elements only when the node is selected
      • iExpanded : inject classes into the 'i' element for the expanded nodes
      • iCollapsed : inject classes into the 'i' element for the collapsed nodes
      • iLeaf : inject classes into the 'i' element for leaf nodes
      • label : inhject classes into the div element around the label
      • labelSelected : inject classes into the div element around the label only when the node is selected
  • order-by : value for ng-repeat to use for ordering sibling nodes
  • reverse-order : whether or not to reverse the ordering of sibling nodes based on the value of order-by
  • filter-expression : value for ng-repeat to use for filtering the sibling nodes
  • filter-comparator : value for ng-repeat to use for comparing nodes with the filter expression
  • menu-id : the id of an ul element which will be displayed after a right-click

The tree labels

The Angular Tree control uses a similar paradigm to ng-repeat in that it allows using the current node as well as values from the parent scope. The current node is injected into the scope used to render the label as the node member (unlike ng-repeat, we do not allow to name the current node item in the transcluded scope).

In order to render a template that takes a value X from the parent scope of the tree and value Y from the current node, use the following template {{X}} {{node.Y}}

Styling

The angular-tree-control renders to the following DOM structure

<treecontrol class="tree-classic">
  <ul>
    <li class="tree-expanded">
      <i class="tree-branch-head"></i>
      <i class="tree-leaf-head"></i>
      <div class="tree-label">
         ... label - expanded angular template is in the treecontrol element ...
      </div>
      <treeitem>
        <ul>
          <li class="tree-leaf">
            <i class="tree-branch-head"></i>
            <i class="tree-leaf-head"></i>
            <div class="tree-label tree-selected">
              ... label - expanded angular template is in the treecontrol element ...
            </div>
          </li>
          <li class="tree-leaf">
            <i class="tree-branch-head"></i>
            <i class="tree-leaf-head"></i>
            <div class="tree-label">
              ... label - expanded angular template is in the treecontrol element ...
            </div>
          </li>
        </ul>
      </treeitem>
    </li>
  </ul>
</treecontrol>

The following CSS classes are used in the built-in styles for the tree-control. Additional classes can be added using the options.injectClasses member (see above)

  • tree-expanded, tree-collapsed, tree-leaf - are placed on the 'ul' element
  • tree-branch-head, tree-leaf-head - are placed on the 'i' elements. We use those classes to place the icons for the tree
  • tree-selected - placed on the div around the label

Reference

This tree control is based in part on the angular.treeview component

License

The MIT License.

See LICENSE

More Repositories

1

react-native-interactable

Experimental implementation of high performance interactable views in React Native
JavaScript
5,171
star
2

react-templates

Light weight templates for react
JavaScript
2,813
star
3

vscode-glean

The extension provides refactoring tools for your React codebase
TypeScript
1,455
star
4

mjml-react

React component library to generate the HTML emails on the fly
JavaScript
980
star
5

react-native-zss-rich-text-editor

React Native rich text editor based on ZSSRichTextEditor
HTML
838
star
6

react-native-keyboard-input

Use your own custom input component instead of the system keyboard
Objective-C
797
star
7

wml

An alternative to symlinks that actually copies changed files from source to destination folders
JavaScript
769
star
8

DetoxInstruments

Detox Instruments is a performance–analysis and testing framework, designed to help developers profile their mobile apps in order to better understand and optimize their app's behavior and performance.
Objective-C
621
star
9

react-native-controllers

Native IOS Navigation for React Native (navbar, tabs, drawer)
Objective-C
610
star
10

react-native-autogrow-textinput

Objective-C
540
star
11

accord

Accord: A sane validation library for Scala
Scala
534
star
12

react-native-crash-course

The React Native crash course by Wix is a self-learning course designed to help you learn everything you need to know before diving into writing production code in React Native.
JavaScript
525
star
13

react-native-keyboard-aware-scrollview

Created by artald
JavaScript
485
star
14

wix-embedded-mysql

embedded mysql based on https://github.com/flapdoodle-oss/de.flapdoodle.embed.process
Java
379
star
15

DetoxRecorder

Detox Recorder is a utility for recordings steps for a Detox test as you use your app in Simulator. After recording the test, add expectations that check if interface elements are in the expected state.
Objective-C
286
star
16

react-dataflow-example

Experimenting with different dataflow approaches for a real life React app
JavaScript
279
star
17

eslint-plugin-lodash

ESLint rules for lodash
JavaScript
272
star
18

pro-gallery

Blazing fast & beautiful galleries built for the web
JavaScript
265
star
19

quix

Quix Notebook Manager
TypeScript
265
star
20

petri

Wix experiment system (A/B test and feature toggle framework)
JavaScript
264
star
21

redux-saga-tester

Full redux environment testing helper for redux-saga
JavaScript
249
star
22

react-native-wordpress-editor

React Native Wrapper for WordPress Rich Text Editor
Objective-C
246
star
23

redux-testkit

Complete and opinionated testkit for testing Redux projects (reducers, selectors, actions, thunks)
JavaScript
227
star
24

remx

Opinionated mobx
JavaScript
221
star
25

exodus

Easily migrate your JVM code from Maven to Bazel
Scala
221
star
26

react-native-action-view

An easy to use component that allows displaying swipeable buttons with a variety of transitions.
Objective-C
187
star
27

tdd-katas

TDD katas
JavaScript
175
star
28

react-native-custom-segmented-control

Custom version of the IOS SegmentedControl component
Objective-C
168
star
29

repluggable

Pluggable micro frontends in React+Redux apps
TypeScript
166
star
30

lerna-script

Lerna addon for adding custom tasks
JavaScript
164
star
31

react-native-wix-engine

Java
164
star
32

angular-widget

Lazy load isolated micro-apps in Angular
JavaScript
163
star
33

angular-viewport-watch

Angular directive that disables watchers in scopes out of viewport
JavaScript
148
star
34

react-native-keyboard-tracking-view

Objective-C
134
star
35

kampos

Tiny and fast effects compositor on WebGL
JavaScript
129
star
36

react-native-swipe-view

Native container for a React Native view which supports swipe behavior (for swipe to delete and such)
Java
124
star
37

list-view-experiments

React Native ListView Experiments
Objective-C
123
star
38

rn-perf-experiments

Various performance experiments with React Native over a swipeable card pattern
JavaScript
119
star
39

rn-perf-experiments2

React Native performance experiments revisited
JavaScript
115
star
40

codio

A media format to record and playback the process of programming
Kotlin
105
star
41

rn-synchronous-render

Experiments with synchronous rendering in React Native
Objective-C
104
star
42

react-native-gifted-chat

JavaScript
99
star
43

as-typed

Ambient mapping from JSON schema to typescript
TypeScript
98
star
44

playable

No hassle, no fuss, just nice and easy video player
TypeScript
95
star
45

tspoon

(DEPRECATED) AST visitors for TypeScript
TypeScript
83
star
46

remote-dom

JavaScript
82
star
47

react-native-paged-contacts

Paged contacts for React Native
Java
80
star
48

react-native-newrelic

New Relic reporting for React Native
JavaScript
79
star
49

obsidian

Dependency injection library for React and React Native applications
TypeScript
74
star
50

react-module-container

Small library for building micro apps in React and Angular
JavaScript
68
star
51

react-native-repackager

Custom extensions for react-native packager
JavaScript
67
star
52

rapido

🏃 A site performance test kit, built using Chrome's DevTools.
JavaScript
63
star
53

BindingListView

React Native ListView experimental implementation supporting direct view binding
Objective-C
62
star
54

rawss

Generic CSS polyfill framework, with a CSS variables implementation
TypeScript
59
star
55

wix-animations

Tools for easy and simple animating capabilities
JavaScript
59
star
56

haste

An extendable, blazing fast build system that cares about user experience
JavaScript
58
star
57

kafka-connect-s3

A Kafka-Connect Sink for S3 with no Hadoop dependencies.
Java
56
star
58

unidriver

UniDriver - Universal Component Drivers 🚀
TypeScript
53
star
59

carmi

CARMI - Compiler for Automatic Reactive Modelling of Inference
JavaScript
49
star
60

mobile-crash-course

Crash course for engineers in Wix to start working on the mobile stack
49
star
61

react-native-extended-cli

Extended CLI with convenient scripts and utilities for developing React Native apps
Shell
47
star
62

protractor-helpers

Set of matchers, locators, and helper functions for Protractor
JavaScript
46
star
63

Kompot

Component testing for React Native using Detox
JavaScript
45
star
64

future-perfect

A helper for Futures covering non-functional concerns such as retries, timeouts and reporting
Scala
44
star
65

mjml-react-example

mjml-react example project
JavaScript
42
star
66

specs2-jmock

This is a specs2 adapter + DSL for using the popular mocking framework JMock
Scala
41
star
67

corvid

Download your Wix site, code in a local IDE, collaborate, use git, and more!
JavaScript
39
star
68

javascript-essentials

Essential reading and learning materials for Wix client-side engineers
37
star
69

fed-training-kit

A self-guided onboarding kit for new FED Guild members
JavaScript
35
star
70

commons-validator-js

JavaScript port of Apache Commons Validator
JavaScript
35
star
71

DeviantArt-API

The DeviantArt API
35
star
72

redux-cornell

A Redux library which helps reduce boilerplate
TypeScript
34
star
73

wix-http-testkit

Tools for testing HTTP services
Scala
34
star
74

DetoxSync

Synchronization framework for Detox and other testing frameworks
Objective-C
34
star
75

enzyme-drivers

Enzyme Drivers is a JavaScript library that makes react component testing with enzyme a lot easier and fun to write
JavaScript
33
star
76

mutable

State containers with dirty checking and more
JavaScript
32
star
77

eyes.it

Add screenshot comparison to existing protractor tests simply by changing `it` to `eyes.it`
JavaScript
31
star
78

react-native-sane-listview

Why do we need all this datasource nonsense?!
JavaScript
31
star
79

wix-ui-backoffice

Common React UI components for all Wix backoffice React applications
TypeScript
31
star
80

turnerjs

An angular test kit for components and directives. See:
TypeScript
29
star
81

zorechka-bot

Github bot for keeping your Bazel dependencies up-to-date and clean
Scala
27
star
82

Koboshi

Obsessed with your precious data
Scala
27
star
83

react-popup-manager

Manage react popups, Modals, Lightboxes, Notifications
TypeScript
26
star
84

sample-wix-rest-app

JavaScript
24
star
85

wix-react-native-storybook-template

Server to host storybook for react native apps
JavaScript
24
star
86

wix-code-docs

Wix Code Reference Documentation - docworks jsons
JavaScript
24
star
87

hello-react-templates

Starter project for react-templates
JavaScript
24
star
88

react-native-open-file

Objective-C
24
star
89

isolated-runtime

Run untrusted Javascript code in a multi-tenant, isolated environment
JavaScript
23
star
90

react-hoverbox

Created by malsomnus
JavaScript
23
star
91

react-sequence-animator

A React library for sequence animations
TypeScript
23
star
92

fast-boot

Caching of the FS location of node modules between node process startups
JavaScript
22
star
93

wixmadefor

Wix Madefor font
Python
22
star
94

svg2react-icon

Generate React icon components from SVG raw files
JavaScript
22
star
95

quick-2fa

Safely generate two-factor authentication tokens into clipboard
JavaScript
21
star
96

async-graph-resolver

A Utility to handle execution and aggregation of async actions
TypeScript
21
star
97

DetoxIPC

DetoxIPC is an asynchronous, bi-directional inter-process remote invocation library for Apple platforms with an API similar to Apple's NSXPCConnection.
Objective-C
21
star
98

react-native-animation-library

JavaScript
20
star
99

data-capsule

A pluggable capsule for storing key/value data for your application
TypeScript
20
star
100

DTXLoggingInfra

Logging infrastructure for Apple platforms
Objective-C
18
star