Skip to content
This repository was archived by the owner on Jul 3, 2025. It is now read-only.

Commit 322e37a

Browse files
committed
use _data not options.data
1 parent 7267d65 commit 322e37a

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

examples/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
// https://iiif-commons.github.io/iiif-av-component/examples/data/iiif/lunchroom-manners.json
6161

6262
Manifold.loadManifest({
63-
iiifResourceUri: 'http://wellcomelibrary.org/iiif/collection/b19974760',
63+
iiifResourceUri: 'https://iiif-commons.github.io/iiif-av-component/examples/data/iiif/lunchroom-manners.json',
6464
collectionIndex: 0,
6565
manifestIndex: 0,
6666
sequenceIndex: 0,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@iiif/iiif-tree-component",
3-
"version": "1.1.11",
3+
"version": "1.1.12",
44
"description": "",
55
"main": "./dist/TreeComponent.js",
66
"types": "./dist/TreeComponent.d.ts",

src/TreeComponent.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ namespace IIIFComponents {
1515
public options: _Components.IBaseComponentOptions;
1616
private _$tree: JQuery;
1717
private _allNodes: Manifold.ITreeNode[] | null; // cache
18+
private _data: ITreeComponentData = this.data();
1819
private _multiSelectableNodes: Manifold.ITreeNode[] | null; // cache
19-
private _selectedNode: Manifold.ITreeNode;
2020
private _rootNode: Manifold.ITreeNode;
21+
private _selectedNode: Manifold.ITreeNode;
2122

2223
constructor(options: _Components.IBaseComponentOptions) {
2324
super(options);
25+
this._data = this.options.data;
2426
this._init();
2527
}
2628

@@ -77,7 +79,11 @@ namespace IIIFComponents {
7779
that._setNodeMultiSelected(node, !!!node.multiSelected);
7880

7981
if (node.isRange()) {
80-
that._getMultiSelectState().selectRange(<Manifold.IRange>node.data, node.multiSelected);
82+
const multiSelectState: Manifold.MultiSelectState | null = that._getMultiSelectState();
83+
84+
if (multiSelectState) {
85+
multiSelectState.selectRange(<Manifold.IRange>node.data, node.multiSelected);
86+
}
8187
}
8288

8389
that.fire(TreeComponent.Events.TREE_NODE_MULTISELECTED, node);
@@ -97,7 +103,7 @@ namespace IIIFComponents {
97103

98104
const node: Manifold.ITreeNode = self.data;
99105

100-
if (node.nodes.length && that.options.data.branchNodesExpandOnClick) {
106+
if (node.nodes.length && that._data.branchNodesExpandOnClick) {
101107
self.toggleExpanded();
102108
}
103109

@@ -107,7 +113,7 @@ namespace IIIFComponents {
107113
if (!node.nodes.length) {
108114
that.fire(TreeComponent.Events.TREE_NODE_SELECTED, node);
109115
that.selectNode(node);
110-
} else if (that.options.data.branchNodesSelectable) {
116+
} else if (that._data.branchNodesSelectable) {
111117
that.fire(TreeComponent.Events.TREE_NODE_SELECTED, node);
112118
that.selectNode(node);
113119
}
@@ -125,25 +131,31 @@ namespace IIIFComponents {
125131

126132
public set(data: ITreeComponentData): void {
127133

128-
this.options.data = data;
134+
this._data = Object.assign(this._data, data);
135+
136+
if (!this._data.helper) {
137+
return;
138+
}
129139

130-
this._rootNode = this.options.data.helper.getTree(this.options.data.topRangeIndex, this.options.data.treeSortType);
140+
this._rootNode = this._data.helper.getTree(this._data.topRangeIndex, this._data.treeSortType) as Manifold.ITreeNode;
131141
this._allNodes = null; // delete cache
132142
this._multiSelectableNodes = null; // delete cache
133143
this._$tree.link($.templates.pageTemplate, this._rootNode);
134144

135-
const multiSelectState: Manifold.MultiSelectState = this._getMultiSelectState();
145+
const multiSelectState: Manifold.MultiSelectState | null = this._getMultiSelectState();
136146

137-
for (let i = 0; i < multiSelectState.ranges.length; i++) {
138-
const range: Manifold.IRange = multiSelectState.ranges[i];
139-
const node: Manifold.ITreeNode = this._getMultiSelectableNodes().en().where(n => n.data.id === range.id).first();
140-
if (node){
141-
this._setNodeMultiSelectEnabled(node, (<Manifold.IMultiSelectable>range).multiSelectEnabled);
142-
this._setNodeMultiSelected(node, range.multiSelected);
147+
if (multiSelectState) {
148+
for (let i = 0; i < multiSelectState.ranges.length; i++) {
149+
const range: Manifold.IRange = multiSelectState.ranges[i];
150+
const node: Manifold.ITreeNode = this._getMultiSelectableNodes().en().where(n => n.data.id === range.id).first();
151+
if (node){
152+
this._setNodeMultiSelectEnabled(node, (<Manifold.IMultiSelectable>range).multiSelectEnabled);
153+
this._setNodeMultiSelected(node, range.multiSelected);
154+
}
143155
}
144156
}
145157

146-
if (this.options.data.autoExpand) {
158+
if (this._data.autoExpand) {
147159
const allNodes: Manifesto.ITreeNode[] = this._getAllNodes();
148160

149161
allNodes.forEach((node: Manifold.ITreeNode, index: number) => {
@@ -154,8 +166,12 @@ namespace IIIFComponents {
154166
}
155167
}
156168

157-
private _getMultiSelectState(): Manifold.MultiSelectState {
158-
return this.options.data.helper.getMultiSelectState();
169+
private _getMultiSelectState(): Manifold.MultiSelectState | null {
170+
171+
if (this._data.helper) {
172+
return this._data.helper.getMultiSelectState();
173+
}
174+
return null;
159175
}
160176

161177
public data(): ITreeComponentData {

0 commit comments

Comments
 (0)