@blocklet/meta 1.8.56 → 1.8.58

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.
@@ -1,4 +1,11 @@
1
- declare const checkLink: (value: any) => boolean;
1
+ declare const checkLink: (value: string) => boolean;
2
+ interface DeepWalkCallback {
3
+ (current: any, parent: any, options: DeepWalkCallbackOptions): void;
4
+ }
5
+ interface DeepWalkCallbackOptions {
6
+ index: number;
7
+ level: number;
8
+ }
2
9
  /**
3
10
  *
4
11
  * @param {object} tree 需要深度遍历的数状结构
@@ -9,17 +16,43 @@ declare const checkLink: (value: any) => boolean;
9
16
  * @param {object} param.parent 当前节点的父节点
10
17
  * @param {number} param.level 当前节点的深度
11
18
  */
12
- declare function deepWalk(tree: any, cb?: () => void, { key, order }?: {
13
- key?: string;
14
- order?: string;
19
+ type TreeNode<K extends string> = Record<string, any> & {
20
+ [key in K]?: TreeNode<K>[];
21
+ };
22
+ declare function deepWalk<K extends string>(tree: TreeNode<K>, cb: DeepWalkCallback, { key, order }: {
23
+ key: K;
24
+ order?: 'first' | 'last';
25
+ }): void;
26
+ declare function deepWalk(tree: TreeNode<'children'>, cb: DeepWalkCallback, { key, order }?: {
27
+ key?: 'children';
28
+ order?: 'first' | 'last';
15
29
  }): void;
16
30
  /**
17
31
  * 判断一个传入值是否属于一个 section
18
32
  * @param {string | array} sections 需要判断的对象
19
33
  * @param {string} section 目标 section
20
34
  */
21
- declare function isMatchSection(sections: any, section: any): boolean;
22
- declare function joinLink(navigation: any, components: any): any;
35
+ declare function isMatchSection(sections: string[] | string, section: string): boolean;
36
+ interface NavigationItem {
37
+ id: string;
38
+ role?: string;
39
+ section?: string;
40
+ title?: string;
41
+ link?: string;
42
+ items?: NavigationItem[];
43
+ component?: string;
44
+ child?: string;
45
+ [key: string]: any;
46
+ }
47
+ interface ComponentItem {
48
+ name: string;
49
+ link: string;
50
+ }
51
+ declare function joinLink(navigation: NavigationItem, components: ComponentItem[]): NavigationItem;
52
+ interface FlatternNavigationOption {
53
+ transform?: (current: any, parent?: any) => any;
54
+ depth?: number;
55
+ }
23
56
  /**
24
57
  * 将树状结构的导航列表进行扁平化处理
25
58
  * @param {array} navigationList 树状结构的导航列表
@@ -28,25 +61,30 @@ declare function joinLink(navigation: any, components: any): any;
28
61
  * @param {function} params.transform 当发生拍平处理时
29
62
  * @returns 扁平化后的导航列表
30
63
  */
31
- declare function flatternNavigation(list?: any[], { depth, transform }?: {
32
- depth?: number;
33
- transform?: (v: any) => any;
34
- }): any[];
64
+ declare function flatternNavigation(list?: NavigationItem[], { depth, transform }?: FlatternNavigationOption): any[];
35
65
  /**
36
66
  * 根据导航中每一个子菜单所属的 section,将原由的导航数据分离为多个导航数据(此时每一个导航 item 只会包含一个 section)
37
67
  * @param {array} navigation 导航列表数据(树状结构,目前只适用于两层的树状结构)
38
68
  * @returns
39
69
  */
40
- declare function splitNavigationBySection(navigation: any): any[];
70
+ declare function splitNavigationBySection(navigation: NavigationItem[]): any[];
41
71
  /**
42
72
  * 将导航数据进行层叠处理
43
73
  * @param {array} list 扁平化的导航数据
44
74
  * @returns 处理后的导航
45
75
  */
46
76
  declare function nestNavigationList(list?: any[]): any[];
47
- declare function filterNavigation(navigationList: any, components?: any[]): any[];
48
- declare function cleanOrphanNavigation(list: any): any;
49
- declare function parseNavigation(blocklet?: {}, options?: {}): {
77
+ declare function filterNavigation(navigationList: NavigationItem[], components?: ComponentItem[]): any[];
78
+ declare function cleanOrphanNavigation(list: NavigationItem[]): NavigationItem[];
79
+ interface Blocklet {
80
+ settings?: {
81
+ navigations?: NavigationItem[];
82
+ };
83
+ }
84
+ interface ParseNavigationOption {
85
+ beforeProcess?: (data: any) => any;
86
+ }
87
+ declare function parseNavigation(blocklet?: Blocklet, options?: ParseNavigationOption): {
50
88
  navigationList: any[];
51
89
  components: any[];
52
90
  builtinList: any[];
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
4
  };
@@ -36,16 +35,6 @@ const checkLink = (value) => {
36
35
  return false;
37
36
  };
38
37
  exports.checkLink = checkLink;
39
- /**
40
- *
41
- * @param {object} tree 需要深度遍历的数状结构
42
- * @param {function} cb 每一个节点的回调函数,回调的参数:当前节点数据,父亲节点数据,{index:当前节点所属的数组中的序号,level: 当前节点所处的深度}
43
- * @param {object} param 深度遍历的参数
44
- * @param {string} param.key 孩子数组的 key 值
45
- * @param {number} param.index 当前节点所属的数组中的序号
46
- * @param {object} param.parent 当前节点的父节点
47
- * @param {number} param.level 当前节点的深度
48
- */
49
38
  function deepWalk(tree, cb = () => { }, { key = 'children', order = 'first' } = {}) {
50
39
  function walk(current, { index = 0, parent = null, level = 0 } = {}) {
51
40
  if (Array.isArray(current)) {
@@ -118,7 +107,7 @@ function optionalJoin(prefix = '/', url = '') {
118
107
  }
119
108
  return resultUrl;
120
109
  }
121
- function smartJoinLink(_parentLink, _childLink, { strict = true } = {}) {
110
+ function smartJoinLink(_parentLink, _childLink, { strict = true, } = {}) {
122
111
  let parentLink = _parentLink;
123
112
  let childLink = _childLink;
124
113
  if (!strict) {
@@ -477,7 +466,18 @@ function filterNavigation(navigationList, components = []) {
477
466
  }
478
467
  }
479
468
  }, { key: 'items' });
480
- const filteredNavigation = nestedNavigation.filter((item) => item.visible !== false);
469
+ const filteredNavigation = nestedNavigation.filter((item) => {
470
+ var _a;
471
+ if (item.visible === false)
472
+ return false;
473
+ // 如果某一菜单的 子菜单 均为隐藏状态,则一级菜单本身也不显示出来
474
+ if (item.items &&
475
+ Array.isArray(item.items) &&
476
+ item.items.length > 0 &&
477
+ ((_a = item.items) === null || _a === void 0 ? void 0 : _a.every((v) => v.visible === false)))
478
+ return false;
479
+ return true;
480
+ });
481
481
  return filteredNavigation;
482
482
  }
483
483
  exports.filterNavigation = filterNavigation;
package/lib/parse.js CHANGED
@@ -87,7 +87,20 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
87
87
  ensureComponentStore }, schemaOptions));
88
88
  const { value, error } = schema.validate(result);
89
89
  if (error) {
90
- throw new Error(`Invalid blocklet.yml: ${error.details.map((x) => x.message).join(', ')}`);
90
+ throw new Error(`Invalid blocklet.yml: ${error.details
91
+ .map((x) => {
92
+ try {
93
+ // 根据 navigation 校验规则定制特殊的错误消息显示
94
+ if (x.type === 'array.unique' && x.path[0] === 'navigation') {
95
+ return `${x.message}: ${x.context.value.id}`;
96
+ }
97
+ }
98
+ catch (_a) {
99
+ //
100
+ }
101
+ return x.message;
102
+ })
103
+ .join(', ')}`);
91
104
  }
92
105
  return value;
93
106
  };
package/lib/schema.js CHANGED
@@ -42,14 +42,26 @@ const checkLinkHelper = (value, helper) => {
42
42
  return value;
43
43
  }
44
44
  // @ts-expect-error
45
- return helper.message('Invalid navigation link');
45
+ return helper.message(`Invalid navigation link: ${value}
46
+
47
+ A valid navigation link should be a relative url which start with '/' or a absolute url, such as:
48
+ - /en/home
49
+ - /zh/home
50
+ - https://www.arcblock.io`);
46
51
  };
47
52
  const checkId = (value, helper) => {
48
53
  if (!value || (0, is_var_name_1.default)(value)) {
49
54
  return value;
50
55
  }
51
56
  // @ts-expect-error
52
- return helper.message('Invalid navigation id');
57
+ return helper.message(`Invalid navigation id: ${value}
58
+
59
+ A valid navigation id is should follow the rules of javascript variables, such as:
60
+ - foo
61
+ - fooBar
62
+ - foo123
63
+
64
+ see detail in https://www.npmjs.com/package/is-var-name`);
53
65
  };
54
66
  const titleSchema = Joi.string()
55
67
  .trim()
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.56",
6
+ "version": "1.8.58",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "./lib/index.js",
9
9
  "typings": "./lib/index.d.ts",
@@ -24,14 +24,14 @@
24
24
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@abtnode/client": "1.8.56",
28
- "@abtnode/constant": "1.8.56",
29
- "@abtnode/util": "1.8.56",
27
+ "@abtnode/client": "1.8.58",
28
+ "@abtnode/constant": "1.8.58",
29
+ "@abtnode/util": "1.8.58",
30
30
  "@arcblock/did": "1.18.34",
31
31
  "@arcblock/did-ext": "1.18.34",
32
32
  "@arcblock/did-util": "1.18.34",
33
33
  "@arcblock/jwt": "1.18.34",
34
- "@blocklet/constant": "1.8.56",
34
+ "@blocklet/constant": "1.8.58",
35
35
  "@ocap/asset": "1.18.34",
36
36
  "@ocap/mcrypto": "1.18.34",
37
37
  "@ocap/types": "1.18.34",
@@ -80,5 +80,5 @@
80
80
  "ts-node": "^10.9.1",
81
81
  "typescript": "^4.8.4"
82
82
  },
83
- "gitHead": "8c24c9d747e96e05510b9cbe863666960569fb46"
83
+ "gitHead": "697fbc1875ee02f6a0dd18e48a5a3f523209f208"
84
84
  }