hyperapp-is 0.1.10 → 0.1.12

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.
package/README.md CHANGED
@@ -532,15 +532,17 @@ getEntriesの返す値
532
532
 
533
533
  ```ts
534
534
  export interface JsonEntry <D> {
535
- name : string
536
- data : D
537
- isNode: boolean
535
+ name : string
536
+ data : D
537
+ isNode : boolean
538
+ extension?: Record<string, any>
538
539
  }
539
540
  ```
540
541
 
541
542
  - name : 名前
542
543
  - data : データ
543
544
  - isNode : ディレクトリか
545
+ - extension?: `NavigatorItem.extension` に追加する値
544
546
 
545
547
  ---
546
548
 
@@ -576,7 +578,6 @@ export const convertJsonToNavigatorItem = function <D> (
576
578
  getEntries : (data: D, depth: number) => JsonEntry<D>[]
577
579
  isNode : boolean
578
580
  depth ?: number
579
- extension ?: (item: NavigatorItem, data: D, depth: number) => Record<string, any> | undefined
580
581
  }
581
582
  ): NavigatorItem
582
583
  ```
@@ -587,7 +588,6 @@ export const convertJsonToNavigatorItem = function <D> (
587
588
  - getEntries: JsonEntry配列を返す関数
588
589
  - isNode : ディレクトリか
589
590
  - depth : 階層の深さ
590
- - extension : 拡張オブジェクトを作成する関数
591
591
 
592
592
  ---
593
593
 
@@ -12,10 +12,12 @@ export interface JsonEntry<D> {
12
12
  name: string;
13
13
  data: D;
14
14
  isNode: boolean;
15
+ extension?: Record<string, any>;
15
16
  }
16
17
  export interface NavigatorColumn {
17
18
  name: string;
18
19
  val: (item: NavigatorItem) => any;
20
+ text?: (item: NavigatorItem) => string;
19
21
  compare?: (a: NavigatorItem, b: NavigatorItem) => number;
20
22
  }
21
23
  export declare const convertJsonToNavigatorItem: <D>(props: {
@@ -25,7 +27,6 @@ export declare const convertJsonToNavigatorItem: <D>(props: {
25
27
  getEntries: (data: D, depth: number) => JsonEntry<D>[];
26
28
  isNode: boolean;
27
29
  depth?: number;
28
- extension?: (item: NavigatorItem, data: D, depth: number) => Record<string, any> | undefined;
29
30
  }) => NavigatorItem;
30
31
  export declare const getParentItems: (item: NavigatorItem | undefined) => NavigatorItem[];
31
32
  /**
@@ -5,25 +5,24 @@ import { el, deleteKeys, SelectButton } from "./component";
5
5
  // convertJsonToNavigatorItem
6
6
  // ---------- ---------- ---------- ---------- ----------
7
7
  export const convertJsonToNavigatorItem = function (props) {
8
- const { parent, name, data, getEntries, isNode, depth = 0, extension } = props;
8
+ const { parent, name, data, getEntries, isNode, depth = 0 } = props;
9
9
  const result = {
10
10
  parent,
11
11
  name,
12
12
  path: parent ? parent.path + "/" + name : "/" + name
13
13
  };
14
- if (extension) {
15
- const ext = extension(result, data, depth);
16
- if (ext)
17
- result.extension = ext;
18
- }
19
- const properties = {};
20
- let hasProperty = false;
14
+ let extension;
15
+ let properties;
21
16
  const children = [];
22
17
  getEntries(data, depth).forEach(entry => {
18
+ if (entry.extension) {
19
+ extension !== null && extension !== void 0 ? extension : (extension = {});
20
+ Object.assign(extension, entry.extension);
21
+ }
23
22
  const isProperty = typeof entry.data !== "object" || Array.isArray(entry.data);
24
23
  if (isProperty) {
24
+ properties !== null && properties !== void 0 ? properties : (properties = {});
25
25
  properties[entry.name] = entry.data;
26
- hasProperty = true;
27
26
  }
28
27
  else {
29
28
  children.push(convertJsonToNavigatorItem({
@@ -32,12 +31,13 @@ export const convertJsonToNavigatorItem = function (props) {
32
31
  data: entry.data,
33
32
  getEntries,
34
33
  isNode: entry.isNode,
35
- depth: depth + 1,
36
- extension
34
+ depth: depth + 1
37
35
  }));
38
36
  }
39
37
  });
40
- if (hasProperty)
38
+ if (extension)
39
+ result.extension = extension;
40
+ if (properties)
41
41
  result.properties = properties;
42
42
  if (isNode)
43
43
  result.children = children;
@@ -179,7 +179,7 @@ export const NavigatorFinder = function (props) {
179
179
  // filter
180
180
  const result = isFilter && searchText !== ""
181
181
  ? item.children.filter(child => {
182
- return columns.some(col => hitTest(col.val(child)));
182
+ return columns.some(col => hitTest(col.text ? col.text(child) : col.val(child)));
183
183
  })
184
184
  : item.children;
185
185
  // maxCount
@@ -203,7 +203,7 @@ export const NavigatorFinder = function (props) {
203
203
  // items hitCount
204
204
  const hitCount = isFilter
205
205
  ? items.length
206
- : items.filter(item => columns.some(col => hitTest(col.val(item)))).length;
206
+ : items.filter(item => columns.some(col => hitTest(col.text ? col.text(item) : col.val(item)))).length;
207
207
  // ---------- ---------- ----------
208
208
  // action_parentClick
209
209
  // ---------- ---------- ----------
@@ -297,10 +297,11 @@ export const NavigatorFinder = function (props) {
297
297
  : [action_itemClick, item]
298
298
  }, columns.map(col => {
299
299
  const v = col.val(item);
300
+ const t = col.text ? col.text(item) : typeof v === "string" ? v : "";
300
301
  return td({
301
- title: String(v)
302
+ title: t
302
303
  }, span({
303
- class: typeof v === "string" && hitTest(v) ? "hit" : ""
304
+ class: hitTest(t) ? "hit" : ""
304
305
  }, v));
305
306
  }))))),
306
307
  // statusBar
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperapp-is",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "UI foundation library for Hyperapp by is4416",
5
5
  "license": "MIT",
6
6
  "type": "module",