@ca-plant-list/ca-plant-list 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,6 +61,13 @@ span.rare::before {
61
61
  font-weight: 600;
62
62
  }
63
63
 
64
+ div.grid {
65
+ display: grid;
66
+ grid-auto-flow: row;
67
+ grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
68
+ column-gap: 2rem;
69
+ }
70
+
64
71
  div.wrapper {
65
72
  display: flex;
66
73
  flex-wrap: wrap;
@@ -82,6 +89,8 @@ div.section ul {
82
89
 
83
90
  div.section li {
84
91
  display: block;
92
+ margin-left: 1rem;
93
+ text-indent: -1rem;
85
94
  }
86
95
 
87
96
  div.section ul.indent {
@@ -6,9 +6,9 @@ class Search {
6
6
  static #debounceTimer;
7
7
  static #searchData;
8
8
 
9
- static #debounce( func ) {
9
+ static #debounce( timeout = 500 ) {
10
10
  clearTimeout( this.#debounceTimer );
11
- this.#debounceTimer = setTimeout( func, 500 );
11
+ this.#debounceTimer = setTimeout( Search.#doSearch, timeout );
12
12
  }
13
13
 
14
14
  static #doSearch() {
@@ -141,7 +141,11 @@ class Search {
141
141
  }
142
142
 
143
143
  static #handleChange() {
144
- this.#debounce( Search.#doSearch );
144
+ this.#debounce();
145
+ }
146
+
147
+ static #handleSubmit() {
148
+ this.#debounce( 0 );
145
149
  }
146
150
 
147
151
  static init() {
@@ -149,6 +153,7 @@ class Search {
149
153
  const eName = document.getElementById( "name" );
150
154
  eName.focus();
151
155
  eName.oninput = ( ev ) => { return this.#handleChange( ev ); };
156
+ document.getElementById( "search_form" ).onsubmit = () => { this.#handleSubmit(); return false; };
152
157
  }
153
158
 
154
159
  }
@@ -8,7 +8,7 @@ js: name_search.js
8
8
  const NAMES = {% include names.json%};
9
9
  </script>
10
10
 
11
- <form>
11
+ <form id="search_form">
12
12
  <input type="text" id="name"><label for="name">Search for scientific name, common name, or synonym</label>
13
13
  </form>
14
14
 
@@ -1,17 +1,20 @@
1
1
  import * as fs from "node:fs";
2
2
  import { Config } from "./config.js";
3
+ import { Families } from "./families.js";
3
4
 
4
5
  class BasePageRenderer {
5
6
 
6
7
  static render( outputDir, Taxa ) {
7
8
 
8
9
  // Copy static files
9
- fs.rmSync( outputDir, { force: true, recursive: true, maxRetries: 2, retryDelay: 200 } );
10
+ fs.rmSync( outputDir, { force: true, recursive: true, maxRetries: 2, retryDelay: 400 } );
10
11
  // First copy default Jekyll files from package.
11
12
  fs.cpSync( Config.getPackageDir() + "/jekyll", outputDir, { recursive: true } );
12
13
  // Then copy Jekyll files from current dir (which may override default files).
13
14
  fs.cpSync( "jekyll", outputDir, { recursive: true } );
14
15
 
16
+ Families.renderPages( outputDir );
17
+
15
18
  this.renderTools( outputDir, Taxa );
16
19
 
17
20
  }
package/lib/families.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as fs from "node:fs";
2
2
  import { HTMLPage } from "./htmlpage.js";
3
- import { HTML, HTML_OPTIONS } from "./html.js";
3
+ import { HTML } from "./html.js";
4
4
  import { Jepson } from "./jepson.js";
5
5
  import { Taxa } from "./taxa.js";
6
6
 
@@ -46,7 +46,7 @@ class PageFamilyList extends HTMLPage {
46
46
 
47
47
  let html = this.getFrontMatter( title );
48
48
 
49
- html += HTML.getElement( "h1", title );
49
+ html += HTML.textElement( "h1", title );
50
50
 
51
51
  html += "<ul>";
52
52
  for ( const family of this.#families ) {
@@ -75,13 +75,12 @@ class PageFamily extends HTMLPage {
75
75
 
76
76
  let html = this.getFrontMatter( this.#family.getName() );
77
77
 
78
- html += HTML.getElement( "h1", this.#family.getName() );
78
+ html += HTML.textElement( "h1", this.#family.getName() );
79
79
 
80
- html += HTML.getElement(
80
+ html += HTML.wrap(
81
81
  "div",
82
82
  Jepson.getEFloraLink( this.#family.getJepsonID() ),
83
- { class: "section" },
84
- HTML_OPTIONS.NO_ESCAPE
83
+ { class: "section" }
85
84
  );
86
85
 
87
86
  html += Taxa.getHTMLTable( this.#family.getTaxa() );
package/lib/html.js CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @deprecated
3
+ */
1
4
  const HTML_OPTIONS = {
2
5
  OPEN_NEW: 1,
3
6
  NO_ESCAPE: 2,
@@ -17,6 +20,9 @@ class HTML {
17
20
  return text.replaceAll( "&", "&amp;" ).replaceAll( "<", "&lt;" ).replaceAll( ">", "&gt;" );
18
21
  }
19
22
 
23
+ /**
24
+ * @deprecated
25
+ */
20
26
  static getElement( elName, text, attributes = {}, options = 0 ) {
21
27
  let html = "<" + elName;
22
28
  html += this.renderAttributes( attributes );
@@ -28,6 +34,16 @@ class HTML {
28
34
 
29
35
  }
30
36
 
37
+ static #getElement( elName, text, attributes, escape ) {
38
+ let html = "<" + elName;
39
+ html += this.renderAttributes( attributes );
40
+ if ( escape ) {
41
+ text = this.escapeText( text );
42
+ }
43
+ html += ">" + text + "</" + elName + ">";
44
+ return html;
45
+ }
46
+
31
47
  static getLink( href, linkText, attributes = {}, options = 0 ) {
32
48
  let html = "<a";
33
49
  if ( href !== undefined ) {
@@ -52,6 +68,14 @@ class HTML {
52
68
  return html;
53
69
  }
54
70
 
71
+ static textElement( elName, text, attributes = {} ) {
72
+ return this.#getElement( elName, text, attributes, true );
73
+ }
74
+
75
+ static wrap( elName, text, attributes = {} ) {
76
+ return this.#getElement( elName, text, attributes, false );
77
+ }
78
+
55
79
  }
56
80
 
57
81
  export { HTML, HTML_OPTIONS };
package/lib/index.js CHANGED
@@ -4,7 +4,9 @@ import { CSV } from "./csv.js";
4
4
  import { DataLoader } from "./dataloader.js";
5
5
  import { ErrorLog } from "./errorlog.js";
6
6
  import { Exceptions } from "./exceptions.js";
7
+ import { Files } from "./files.js";
7
8
  import { HTML, HTML_OPTIONS } from "./html.js";
9
+ import { Taxa } from "./taxa.js";
8
10
  import { Taxon } from "./taxon.js";
9
11
 
10
- export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, HTML, HTML_OPTIONS, Taxon };
12
+ export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Files, HTML, HTML_OPTIONS, Taxa, Taxon };
@@ -1,5 +1,4 @@
1
1
  import * as fs from "node:fs";
2
- import { Families } from "./families.js";
3
2
  import { HTML, HTML_OPTIONS } from "./html.js";
4
3
  import { Taxa } from "./taxa.js";
5
4
  import { HTMLPage } from "./htmlpage.js";
@@ -16,8 +15,6 @@ class PageRenderer extends BasePageRenderer {
16
15
 
17
16
  this.renderLists( outputDir );
18
17
 
19
- Families.renderPages( outputDir );
20
-
21
18
  const taxa = Taxa.getTaxa();
22
19
  for ( const taxon of taxa ) {
23
20
  new PageTaxon( taxon ).render( outputDir );
package/lib/pagetaxon.js CHANGED
@@ -20,21 +20,18 @@ class PageTaxon extends HTMLPage {
20
20
  if ( jepsonID ) {
21
21
  links.push( Jepson.getEFloraLink( jepsonID ) );
22
22
  }
23
- const calRecNum = this.#taxon.getCalfloraID();
24
- if ( calRecNum ) {
25
- links.push(
26
- HTML.getLink(
27
- "https://www.calflora.org/app/taxon?crn=" + calRecNum,
28
- "Calflora",
29
- {},
30
- HTML_OPTIONS.OPEN_NEW
31
- )
32
- );
23
+ const cfLink = this.#taxon.getCalfloraTaxonLink();
24
+ if ( cfLink ) {
25
+ links.push( cfLink );
33
26
  }
34
27
  const iNatLink = this.#taxon.getINatTaxonLink();
35
28
  if ( iNatLink ) {
36
29
  links.push( iNatLink );
37
30
  }
31
+ const rpiLink = this.#taxon.getRPITaxonLink();
32
+ if ( rpiLink ) {
33
+ links.push( rpiLink );
34
+ }
38
35
  return links;
39
36
  }
40
37
 
@@ -154,7 +151,7 @@ class PageTaxon extends HTMLPage {
154
151
  );
155
152
  }
156
153
 
157
- html += "<div class=\"wrapper\">";
154
+ html += "<div class=\"grid\">";
158
155
  html += this.#getListSectionHTML( this.#getInfoLinks(), "Information", "info" );
159
156
  html += this.#getListSectionHTML( this.#getObsLinks(), "Observations", "obs" );
160
157
  html += this.#getListSectionHTML( this.#getRelatedTaxaLinks(), "Related Species", "rel-taxa" );
package/lib/taxon.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Config } from "./config.js";
2
- import { ErrorLog } from "./errorlog.js";
3
2
  import { Genera } from "./genera.js";
4
3
  import { HTML, HTML_OPTIONS } from "./html.js";
5
4
  import { RarePlants } from "./rareplants.js";
@@ -32,12 +31,6 @@ class Taxon {
32
31
  this.#rankRPI = rankRPI;
33
32
  this.#cesa = cesa;
34
33
  Genera.addTaxon( this );
35
- if ( !calRecNum ) {
36
- ErrorLog.log( this.getName(), "has no Calflora ID" );
37
- }
38
- if ( !iNatID ) {
39
- ErrorLog.log( this.getName(), "has no iNat ID" );
40
- }
41
34
  }
42
35
 
43
36
  addSynonym( syn, type ) {
@@ -65,6 +58,19 @@ class Taxon {
65
58
  return this.#calRecNum;
66
59
  }
67
60
 
61
+ getCalfloraTaxonLink() {
62
+ const calfloraID = this.getCalfloraID();
63
+ if ( !calfloraID ) {
64
+ return;
65
+ }
66
+ return HTML.getLink(
67
+ "https://www.calflora.org/app/taxon?crn=" + calfloraID,
68
+ "Calflora",
69
+ {},
70
+ HTML_OPTIONS.OPEN_NEW
71
+ );
72
+ }
73
+
68
74
  getCESA() {
69
75
  return this.#cesa;
70
76
  }
@@ -145,6 +151,15 @@ class Taxon {
145
151
  return this.#rankRPI;
146
152
  }
147
153
 
154
+ getRPITaxonLink() {
155
+ const rpiID = this.getRPIID();
156
+ if ( !rpiID ) {
157
+ return "";
158
+ }
159
+ const link = HTML.getLink( "https://rareplants.cnps.org/Plants/Details/" + rpiID, "CNPS Rare Plant Inventory", {}, HTML_OPTIONS.OPEN_NEW );
160
+ return link;
161
+ }
162
+
148
163
  getStatus() {
149
164
  return this.#status;
150
165
  }
@@ -165,6 +180,10 @@ class Taxon {
165
180
  return this.#synonyms;
166
181
  }
167
182
 
183
+ isCANative() {
184
+ return this.#status === "N" || this.#status === "NC";
185
+ }
186
+
168
187
  isNative() {
169
188
  return this.#status === "N";
170
189
  }
@@ -173,18 +192,6 @@ class Taxon {
173
192
  return this.getRPIRank() !== undefined;
174
193
  }
175
194
 
176
- setCalfloraID( id ) {
177
- this.#calRecNum = id;
178
- }
179
-
180
- setINatID( id ) {
181
- this.#iNatID = id;
182
- }
183
-
184
- setJepsonID( id ) {
185
- this.#jepsonID = id;
186
- }
187
-
188
195
  }
189
196
 
190
197
  export { Taxon };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ca-plant-list/ca-plant-list",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Tools to create Jekyll files for a website listing plants in an area of California.",
5
5
  "license": "MIT",
6
6
  "repository": {