@blueking/bkui-form 1.0.1-beta.1 → 1.0.1-beta.3

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.
Files changed (168) hide show
  1. package/esm/adapter/common/FieldGroupWrap.tsx.js +199 -0
  2. package/esm/adapter/field/ArrayField.tsx.js +55 -0
  3. package/esm/adapter/field/BooleanField.tsx.js +41 -0
  4. package/esm/adapter/field/CompositionField.tsx.js +113 -0
  5. package/esm/adapter/field/FieldProps.ts.js +85 -0
  6. package/esm/adapter/field/NumberField.tsx.js +19 -0
  7. package/esm/adapter/field/ObjectField.tsx.js +58 -0
  8. package/esm/adapter/field/SchemaField.tsx.js +28 -0
  9. package/esm/adapter/field/StringField.tsx.js +4 -0
  10. package/esm/adapter/widget/ArrayWidget.ts.js +196 -0
  11. package/esm/adapter/widget/ButtonWidget.ts.js +76 -0
  12. package/esm/adapter/widget/CheckboxWidget.ts.js +101 -0
  13. package/esm/adapter/widget/CollapseGroupWidget.ts.js +140 -0
  14. package/esm/adapter/widget/ColorPickerWidget.ts.js +71 -0
  15. package/esm/adapter/widget/InputWidget.ts.js +79 -0
  16. package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +156 -0
  17. package/esm/adapter/widget/RadioWidget.ts.js +98 -0
  18. package/esm/adapter/widget/SelectWidget.ts.js +98 -0
  19. package/esm/adapter/widget/SwitchWidget.ts.js +73 -0
  20. package/esm/adapter/widget/TabGroupWidget.ts.js +145 -0
  21. package/esm/adapter/widget/TableWidget.ts.js +205 -0
  22. package/esm/adapter/widget/Widget.ts.js +497 -0
  23. package/esm/assets/fonts/iconcool.eot +0 -0
  24. package/esm/assets/fonts/iconcool.ttf +0 -0
  25. package/esm/assets/fonts/iconcool.woff +0 -0
  26. package/esm/assets/style.css +43 -0
  27. package/esm/controller/form.css +164 -0
  28. package/esm/controller/form.tsx.js +159 -0
  29. package/esm/controller/props.ts.js +75 -0
  30. package/esm/core/events.ts.js +74 -0
  31. package/esm/core/expression.ts.js +67 -0
  32. package/esm/core/lang.ts.js +25 -0
  33. package/esm/core/layout.ts.js +149 -0
  34. package/esm/core/path.ts.js +60 -0
  35. package/esm/core/proxy.ts.js +10 -0
  36. package/esm/core/reaction.ts.js +116 -0
  37. package/esm/core/register.ts.js +74 -0
  38. package/esm/core/schema.ts.js +302 -0
  39. package/esm/core/validator.ts.js +248 -0
  40. package/esm/core/widgetTree.ts.js +163 -0
  41. package/esm/index.ts.js +6 -0
  42. package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +35 -0
  43. package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +233 -0
  44. package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +172 -0
  45. package/esm/node_modules/ajv/dist/ajv.js +50 -0
  46. package/esm/node_modules/ajv/dist/compile/codegen/code.js +156 -0
  47. package/esm/node_modules/ajv/dist/compile/codegen/index.js +697 -0
  48. package/esm/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
  49. package/esm/node_modules/ajv/dist/compile/errors.js +123 -0
  50. package/esm/node_modules/ajv/dist/compile/index.js +242 -0
  51. package/esm/node_modules/ajv/dist/compile/names.js +28 -0
  52. package/esm/node_modules/ajv/dist/compile/ref_error.js +12 -0
  53. package/esm/node_modules/ajv/dist/compile/resolve.js +155 -0
  54. package/esm/node_modules/ajv/dist/compile/rules.js +26 -0
  55. package/esm/node_modules/ajv/dist/compile/util.js +178 -0
  56. package/esm/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
  57. package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
  58. package/esm/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
  59. package/esm/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
  60. package/esm/node_modules/ajv/dist/compile/validate/index.js +520 -0
  61. package/esm/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
  62. package/esm/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
  63. package/esm/node_modules/ajv/dist/core.js +618 -0
  64. package/esm/node_modules/ajv/dist/refs/data.json +13 -0
  65. package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
  66. package/esm/node_modules/ajv/dist/runtime/equal.js +7 -0
  67. package/esm/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
  68. package/esm/node_modules/ajv/dist/runtime/uri.js +6 -0
  69. package/esm/node_modules/ajv/dist/runtime/validation_error.js +11 -0
  70. package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
  71. package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
  72. package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
  73. package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
  74. package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
  75. package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
  76. package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
  77. package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
  78. package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
  79. package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
  80. package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
  81. package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
  82. package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
  83. package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
  84. package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
  85. package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
  86. package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
  87. package/esm/node_modules/ajv/dist/vocabularies/code.js +131 -0
  88. package/esm/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
  89. package/esm/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
  90. package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
  91. package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
  92. package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
  93. package/esm/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
  94. package/esm/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
  95. package/esm/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
  96. package/esm/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
  97. package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
  98. package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
  99. package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
  100. package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
  101. package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
  102. package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
  103. package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
  104. package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
  105. package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +24 -0
  106. package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
  107. package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
  108. package/esm/node_modules/ajv-formats/dist/formats.js +173 -0
  109. package/esm/node_modules/ajv-formats/dist/index.js +37 -0
  110. package/esm/node_modules/ajv-formats/dist/limit.js +69 -0
  111. package/esm/node_modules/ajv-i18n/localize/zh/index.js +154 -0
  112. package/esm/node_modules/fast-deep-equal/index.js +46 -0
  113. package/esm/node_modules/fast-uri/index.js +303 -0
  114. package/esm/node_modules/fast-uri/lib/schemes.js +188 -0
  115. package/esm/node_modules/fast-uri/lib/scopedChars.js +30 -0
  116. package/esm/node_modules/fast-uri/lib/utils.js +244 -0
  117. package/esm/node_modules/json-schema-traverse/index.js +89 -0
  118. package/esm/node_modules/semver/classes/comparator.js +143 -0
  119. package/esm/node_modules/semver/classes/range.js +557 -0
  120. package/esm/node_modules/semver/classes/semver.js +333 -0
  121. package/esm/node_modules/semver/functions/clean.js +8 -0
  122. package/esm/node_modules/semver/functions/cmp.js +54 -0
  123. package/esm/node_modules/semver/functions/coerce.js +62 -0
  124. package/esm/node_modules/semver/functions/compare-build.js +9 -0
  125. package/esm/node_modules/semver/functions/compare-loose.js +5 -0
  126. package/esm/node_modules/semver/functions/compare.js +7 -0
  127. package/esm/node_modules/semver/functions/diff.js +60 -0
  128. package/esm/node_modules/semver/functions/eq.js +5 -0
  129. package/esm/node_modules/semver/functions/gt.js +5 -0
  130. package/esm/node_modules/semver/functions/gte.js +5 -0
  131. package/esm/node_modules/semver/functions/inc.js +21 -0
  132. package/esm/node_modules/semver/functions/lt.js +5 -0
  133. package/esm/node_modules/semver/functions/lte.js +5 -0
  134. package/esm/node_modules/semver/functions/major.js +5 -0
  135. package/esm/node_modules/semver/functions/minor.js +5 -0
  136. package/esm/node_modules/semver/functions/neq.js +5 -0
  137. package/esm/node_modules/semver/functions/parse.js +18 -0
  138. package/esm/node_modules/semver/functions/patch.js +5 -0
  139. package/esm/node_modules/semver/functions/prerelease.js +8 -0
  140. package/esm/node_modules/semver/functions/rcompare.js +5 -0
  141. package/esm/node_modules/semver/functions/rsort.js +5 -0
  142. package/esm/node_modules/semver/functions/satisfies.js +12 -0
  143. package/esm/node_modules/semver/functions/sort.js +5 -0
  144. package/esm/node_modules/semver/functions/valid.js +8 -0
  145. package/esm/node_modules/semver/index.js +91 -0
  146. package/esm/node_modules/semver/internal/constants.js +37 -0
  147. package/esm/node_modules/semver/internal/debug.js +11 -0
  148. package/esm/node_modules/semver/internal/identifiers.js +29 -0
  149. package/esm/node_modules/semver/internal/lrucache.js +42 -0
  150. package/esm/node_modules/semver/internal/parse-options.js +17 -0
  151. package/esm/node_modules/semver/internal/re.js +223 -0
  152. package/esm/node_modules/semver/ranges/gtr.js +6 -0
  153. package/esm/node_modules/semver/ranges/intersects.js +9 -0
  154. package/esm/node_modules/semver/ranges/ltr.js +6 -0
  155. package/esm/node_modules/semver/ranges/max-satisfying.js +27 -0
  156. package/esm/node_modules/semver/ranges/min-satisfying.js +26 -0
  157. package/esm/node_modules/semver/ranges/min-version.js +63 -0
  158. package/esm/node_modules/semver/ranges/outside.js +82 -0
  159. package/esm/node_modules/semver/ranges/simplify.js +49 -0
  160. package/esm/node_modules/semver/ranges/subset.js +249 -0
  161. package/esm/node_modules/semver/ranges/to-comparators.js +10 -0
  162. package/esm/node_modules/semver/ranges/valid.js +13 -0
  163. package/esm/util/fetch.ts.js +190 -0
  164. package/esm/util/index.ts.js +276 -0
  165. package/package.json +3 -4
  166. package/dist/main.css +0 -208
  167. package/dist/main.js +0 -17353
  168. /package/{dist/svg/iconcool.eb237688.svg → esm/assets/fonts/iconcool.svg} +0 -0
@@ -0,0 +1,163 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ import Path from '../node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js';
15
+ export class WidgetNode {
16
+ // 当前node的值
17
+ get value() {
18
+ var _this_instance;
19
+ return (_this_instance = this.instance) === null || _this_instance === void 0 ? void 0 : _this_instance.value;
20
+ }
21
+ // 是否含有可见子节点
22
+ get isChildrenVisible() {
23
+ if (this.type === 'node') {
24
+ var _this_instance;
25
+ return (_this_instance = this.instance) === null || _this_instance === void 0 ? void 0 : _this_instance.state.visible;
26
+ }
27
+ return this.children.some((child)=>child.isChildrenVisible);
28
+ }
29
+ /**
30
+ * 获取 parents
31
+ */ get parents() {
32
+ if (!this.parent) {
33
+ return [];
34
+ }
35
+ return [
36
+ ...this.parent.parents,
37
+ this.parent
38
+ ];
39
+ }
40
+ // 第一个子节点
41
+ get firstChild() {
42
+ return this.children[0] || null;
43
+ }
44
+ // 最后一个子节点
45
+ get lastChild() {
46
+ return this.children[this.children.length - 1] || null;
47
+ }
48
+ // 指定属性下的同胞节点
49
+ getSibling(lastProp) {
50
+ var _this_parent;
51
+ const reg = new RegExp(`${Path.getPathLastProp(this.id) || ''}$`);
52
+ const id = this.id.replace(reg, lastProp);
53
+ return (_this_parent = this.parent) === null || _this_parent === void 0 ? void 0 : _this_parent.children.find((node)=>node.id === id);
54
+ }
55
+ // 获取所以同胞节点(不含自己)
56
+ getSiblings() {
57
+ var _this_parent;
58
+ return ((_this_parent = this.parent) === null || _this_parent === void 0 ? void 0 : _this_parent.children.filter((node)=>node.instance !== this.instance)) || [];
59
+ }
60
+ /**
61
+ * 是否是叶子节点
62
+ */ get isLeaf() {
63
+ return !this.children.length;
64
+ }
65
+ appendChild(node) {
66
+ const nodes = Array.isArray(node) ? node : [
67
+ node
68
+ ];
69
+ const offset = node.index !== undefined ? node.index : this.children.length;
70
+ this.children.splice(offset, 0, ...nodes);
71
+ this.children.slice(offset).forEach((node, index)=>{
72
+ node.index = offset + index;
73
+ });
74
+ return nodes;
75
+ }
76
+ removeChild(node) {
77
+ const nodes = Array.isArray(node) ? node : [
78
+ node
79
+ ];
80
+ const removedChildIndex = [];
81
+ nodes.forEach((node)=>{
82
+ const { index } = node;
83
+ removedChildIndex.push(index);
84
+ this.children.splice(index, 1);
85
+ });
86
+ const minIndex = Math.min(...removedChildIndex);
87
+ this.children.slice(minIndex).forEach((node, index)=>{
88
+ node.index = minIndex + index;
89
+ });
90
+ return nodes;
91
+ }
92
+ constructor(config){
93
+ _define_property(this, "id", void 0);
94
+ _define_property(this, "instance", void 0);
95
+ _define_property(this, "parent", void 0);
96
+ _define_property(this, "type", void 0);
97
+ _define_property(this, "index", void 0);
98
+ _define_property(this, "children", void 0);
99
+ const { id, instance, parent, index, type, children = [] } = config;
100
+ this.id = id;
101
+ this.type = type;
102
+ this.index = index;
103
+ this.instance = instance;
104
+ this.parent = parent;
105
+ this.children = children;
106
+ }
107
+ }
108
+ export class WidgetTree {
109
+ addWidgetNode(path, instance, type, index) {
110
+ if (path === '') {
111
+ // 根节点
112
+ const node = new WidgetNode({
113
+ id: '',
114
+ type,
115
+ index,
116
+ parent: null,
117
+ instance,
118
+ children: []
119
+ });
120
+ this.widgetMap[path] = node;
121
+ } else {
122
+ // 普通节点
123
+ const parentId = Path.getParentPath(path);
124
+ const parentNode = this.widgetMap[parentId];
125
+ const node = new WidgetNode({
126
+ id: (instance === null || instance === void 0 ? void 0 : instance.path) || path,
127
+ type,
128
+ index,
129
+ parent: parentNode,
130
+ instance,
131
+ children: []
132
+ });
133
+ if (!parentNode) {
134
+ console.warn('Unexpected parent id, please check widget node', node);
135
+ } else {
136
+ parentNode.appendChild(node);
137
+ }
138
+ this.widgetMap[path] = node;
139
+ }
140
+ }
141
+ removeWidgetNode(path, instance) {
142
+ const node = this.widgetMap[path];
143
+ if (node) {
144
+ if (node.parent) {
145
+ const { children } = node.parent;
146
+ const index = children.findIndex((item)=>item.instance === instance);
147
+ if (index > -1) {
148
+ children.splice(index, 1);
149
+ children.slice(index).forEach((node, i)=>{
150
+ node.index = index + i;
151
+ });
152
+ }
153
+ }
154
+ if (node.instance === instance) {
155
+ delete this.widgetMap[path];
156
+ }
157
+ }
158
+ }
159
+ constructor(){
160
+ _define_property(this, "widgetMap", {});
161
+ }
162
+ }
163
+ export default new WidgetTree();
@@ -0,0 +1,6 @@
1
+ import createForm from './controller/form.tsx.js';
2
+ import events from './core/events.ts.js';
3
+ import Schema from './core/schema.ts.js';
4
+ import './assets/style.css';
5
+ export default createForm;
6
+ export { events, Schema };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.posix = exports.isAbsolute = exports.relative = exports.basename = exports.extname = exports.dirname = exports.join = exports.resolve = exports.normalize = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ // 转换路径分隔符为 /
9
+ const normalize = (file) => file.replace(/\\/g, '/');
10
+ exports.normalize = normalize;
11
+ // 解析路径
12
+ const resolve = (...files) => (0, exports.normalize)(node_path_1.default.resolve(...files));
13
+ exports.resolve = resolve;
14
+ // 连接路径
15
+ const join = (...files) => (0, exports.normalize)(node_path_1.default.join(...files));
16
+ exports.join = join;
17
+ // 获取文件目录
18
+ const dirname = (file) => node_path_1.default.dirname(file);
19
+ exports.dirname = dirname;
20
+ // 获取文件扩展名
21
+ const extname = (file) => node_path_1.default.extname(file);
22
+ exports.extname = extname;
23
+ // 获取文件名
24
+ const basename = (file, suffix) => node_path_1.default.basename(file, suffix);
25
+ exports.basename = basename;
26
+ // 获取相对路径
27
+ const relative = (path1, path2) => (0, exports.normalize)(node_path_1.default.relative(path1, path2));
28
+ exports.relative = relative;
29
+ // 判断是否是绝对路径
30
+ const isAbsolute = (file) => node_path_1.default.isAbsolute(file);
31
+ exports.isAbsolute = isAbsolute;
32
+ // posix
33
+ exports.posix = {
34
+ join: (...files) => (0, exports.normalize)(node_path_1.default.posix.join(...files)),
35
+ };
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDirName = exports.getFileName = exports.isNodeBuiltInModule = exports.getUniqueId = exports.deepMerge = exports.getVueVersion = exports.isEmpty = exports.isFunction = exports.isArray = exports.isString = exports.isObject = exports.resolveLocal = exports.resolveUserPath = exports.isAbsolutePath = exports.getAbsolutePath = exports.getRelativePath = exports.getAssetPath = void 0;
7
+ /*
8
+ * Tencent is pleased to support the open source community by making
9
+ * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
10
+ *
11
+ * Copyright (C) 2021 Tencent. All rights reserved.
12
+ *
13
+ * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
14
+ *
15
+ * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
16
+ *
17
+ * ---------------------------------------------------
18
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
19
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
20
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
21
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
22
+ *
23
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
24
+ * the Software.
25
+ *
26
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30
+ * IN THE SOFTWARE.
31
+ */
32
+ const semver_1 = __importDefault(require('../../../../semver/index.js'));
33
+ const path_1 = require('../tools/rust/helper/path.js');
34
+ /**
35
+ * 获取资源路径
36
+ * @param options 配置
37
+ * @param filePath 文件路径
38
+ * @returns 资源路径
39
+ */
40
+ const getAssetPath = (options, filePath) => (options.outputAssetsDirName
41
+ ? path_1.posix.join(options.outputAssetsDirName, filePath)
42
+ : filePath);
43
+ exports.getAssetPath = getAssetPath;
44
+ /**
45
+ * 获取相对路径
46
+ * @param workDir 项目路径
47
+ * @param absolutePath 绝对路径
48
+ * @returns 相对路径
49
+ */
50
+ const getRelativePath = (from, to) => {
51
+ // 获取相对路径
52
+ let relativePath = (0, path_1.relative)(from, to);
53
+ // 处理空路径的情况
54
+ if (!relativePath) {
55
+ return '.';
56
+ }
57
+ // 如果是当前目录,直接返回 ./
58
+ if (relativePath === '.') {
59
+ return relativePath;
60
+ }
61
+ // 如果不是以 . 或 .. 开头,添加 ./
62
+ if (!relativePath.startsWith('.')) {
63
+ relativePath = `./${relativePath}`;
64
+ }
65
+ return relativePath;
66
+ };
67
+ exports.getRelativePath = getRelativePath;
68
+ /**
69
+ * 返回资源绝对路径
70
+ * @param workDir 项目路径
71
+ * @param paths 资源相对路径
72
+ * @returns 绝对路径
73
+ */
74
+ const getAbsolutePath = (workDir, ...paths) => (0, path_1.resolve)(workDir, ...paths.filter(v => v));
75
+ exports.getAbsolutePath = getAbsolutePath;
76
+ /**
77
+ * 判断是否是绝对路径
78
+ * @param userPath 路径
79
+ * @returns 是否是绝对路径
80
+ */
81
+ const isAbsolutePath = (userPath) => (0, path_1.isAbsolute)(userPath);
82
+ exports.isAbsolutePath = isAbsolutePath;
83
+ /**
84
+ * 处理用户输入的路径,如果是绝对路径直接返回,如果是相对路径,返回绝对路径
85
+ * @param workDir 用户目录
86
+ * @param userPath 文件路径
87
+ * @returns 文件绝对路径
88
+ */
89
+ const resolveUserPath = (workDir, userPath) => {
90
+ if ((0, exports.isAbsolutePath)(userPath)) {
91
+ return userPath;
92
+ }
93
+ return (0, exports.getAbsolutePath)(workDir, userPath);
94
+ };
95
+ exports.resolveUserPath = resolveUserPath;
96
+ /**
97
+ * 返回 cli service 所以目录的相对目录
98
+ * @param workDir 用户目录
99
+ * @param _path 文件路径
100
+ * @returns 文件绝对路径
101
+ */
102
+ const resolveLocal = (...dirs) => (0, path_1.join)(__dirname, '../../', ...dirs);
103
+ exports.resolveLocal = resolveLocal;
104
+ /**
105
+ * 判断值是否为对象
106
+ * @param { unknown } target 值
107
+ * @returns boolean
108
+ */
109
+ const isObject = (target) => Object.prototype.toString.call(target) === '[object Object]';
110
+ exports.isObject = isObject;
111
+ /**
112
+ * 判断值是否为字符串
113
+ * @param { unknown } target 值
114
+ * @returns boolean
115
+ */
116
+ const isString = (target) => typeof target === 'string';
117
+ exports.isString = isString;
118
+ /**
119
+ * 判断值是否为数组
120
+ * @param { unknown } target 值
121
+ * @returns boolean
122
+ */
123
+ const isArray = (target) => Array.isArray(target);
124
+ exports.isArray = isArray;
125
+ /**
126
+ * 判断值是否为函数
127
+ * @param { unknown } target 值
128
+ * @returns boolean
129
+ */
130
+ const isFunction = (target) => Object.prototype.toString.call(target) === '[object Function]';
131
+ exports.isFunction = isFunction;
132
+ /**
133
+ * 判断值是否为空
134
+ * @param { unknown } value 值
135
+ * @returns boolean
136
+ */
137
+ const isEmpty = (value) => {
138
+ if (value === ''
139
+ || value === null
140
+ || value === undefined) {
141
+ return true;
142
+ }
143
+ if (Array.isArray(value) && value.length < 1) {
144
+ return true;
145
+ }
146
+ if ((0, exports.isObject)(value) && Object.keys(value).length < 1) {
147
+ return true;
148
+ }
149
+ return false;
150
+ };
151
+ exports.isEmpty = isEmpty;
152
+ /**
153
+ * 获取 vue 版本
154
+ * @returns vue 版本
155
+ */
156
+ const getVueVersion = () => {
157
+ let vue;
158
+ try {
159
+ vue = require('vue');
160
+ }
161
+ catch (error) {
162
+ }
163
+ const vueVersion = vue ? semver_1.default.major(vue.version) : undefined;
164
+ return vueVersion;
165
+ };
166
+ exports.getVueVersion = getVueVersion;
167
+ /**
168
+ * deep merge
169
+ * @param target 目标对象
170
+ * @param source 源对象
171
+ * @returns 深度合并对象
172
+ */
173
+ const deepMerge = (target, source) => {
174
+ const result = { ...target };
175
+ for (const [key, value] of Object.entries(source)) {
176
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
177
+ if (target[key] && typeof target[key] === 'object' && !Array.isArray(target[key])) {
178
+ result[key] = (0, exports.deepMerge)(target[key], value);
179
+ }
180
+ else {
181
+ result[key] = value;
182
+ }
183
+ }
184
+ else {
185
+ result[key] = value;
186
+ }
187
+ }
188
+ return result;
189
+ };
190
+ exports.deepMerge = deepMerge;
191
+ /**
192
+ * 获取唯一 id
193
+ * @returns 唯一 id
194
+ */
195
+ const getUniqueId = (len = 8) => Math.random().toString(36)
196
+ .substring(2, 2 + len);
197
+ exports.getUniqueId = getUniqueId;
198
+ /**
199
+ * 判断是否是 node 内置模块
200
+ * @param moduleName 模块名
201
+ * @returns 是否是 node 内置模块
202
+ */
203
+ const isNodeBuiltInModule = (moduleName) => {
204
+ if (moduleName.startsWith('node:'))
205
+ return true;
206
+ const nodeBuiltinModules = [
207
+ 'fs', 'path', 'http', 'https', 'url', 'os', 'util', 'stream',
208
+ 'events', 'crypto', 'zlib', 'buffer', 'child_process', 'cluster',
209
+ 'dns', 'net', 'querystring', 'readline', 'string_decoder', 'tls',
210
+ 'tty', 'dgram', 'v8', 'vm', 'worker_threads', 'perf_hooks', 'assert',
211
+ 'constants',
212
+ ];
213
+ return nodeBuiltinModules.includes(moduleName);
214
+ };
215
+ exports.isNodeBuiltInModule = isNodeBuiltInModule;
216
+ /**
217
+ * 获取文件名
218
+ * @param filePath 文件路径
219
+ * @returns 文件名
220
+ */
221
+ const getFileName = (filePath) => {
222
+ return (0, path_1.basename)(filePath, (0, path_1.extname)(filePath));
223
+ };
224
+ exports.getFileName = getFileName;
225
+ /**
226
+ * 获取文件所在文件夹的名称
227
+ * @param filePath 文件路径
228
+ * @returns 文件夹名称
229
+ */
230
+ const getDirName = (filePath) => {
231
+ return (0, path_1.dirname)(filePath);
232
+ };
233
+ exports.getDirName = getDirName;
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseDependencyQueryAndHash = exports.getDependencyQueryAndHash = exports.getAbsoluteDependencyPath = exports.isPathMatchExternal = exports.resolveOutputAbsoluteFilePath = exports.resolveFilePath = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const util_1 = require('../../../lib/util.js');
9
+ const path_1 = require('../../../lib/path.js');
10
+ /**
11
+ * 解析文件路径,有一些简写会导致访问不到文件
12
+ * @param filePath 文件路径
13
+ * @returns 解析后的路径
14
+ */
15
+ const resolveFilePath = (filePath) => {
16
+ if (node_fs_1.default.existsSync(filePath) && node_fs_1.default.statSync(filePath).isFile()) {
17
+ return filePath;
18
+ }
19
+ // 如果是目录且存在 package.json,则认为是一个包
20
+ if (node_fs_1.default.existsSync(filePath) && node_fs_1.default.statSync(filePath).isDirectory() && node_fs_1.default.existsSync(`${filePath}/package.json`)) {
21
+ const packageJson = JSON.parse(node_fs_1.default.readFileSync(`${filePath}/package.json`, 'utf-8'));
22
+ if (packageJson.main) {
23
+ return (0, path_1.resolve)(filePath, packageJson.main);
24
+ }
25
+ if (packageJson.module) {
26
+ return (0, path_1.resolve)(filePath, packageJson.module);
27
+ }
28
+ }
29
+ const jsPath = `${filePath}.js`;
30
+ if (node_fs_1.default.existsSync(jsPath)) {
31
+ return jsPath;
32
+ }
33
+ const tsPath = `${filePath}.ts`;
34
+ if (node_fs_1.default.existsSync(tsPath)) {
35
+ return tsPath;
36
+ }
37
+ const tsxPath = `${filePath}.tsx`;
38
+ if (node_fs_1.default.existsSync(tsxPath)) {
39
+ return tsxPath;
40
+ }
41
+ const jsxPath = `${filePath}.jsx`;
42
+ if (node_fs_1.default.existsSync(jsxPath)) {
43
+ return jsxPath;
44
+ }
45
+ const indexJsPath = `${filePath}/index.js`;
46
+ if (node_fs_1.default.existsSync(indexJsPath)) {
47
+ return indexJsPath;
48
+ }
49
+ const indexTsPath = `${filePath}/index.ts`;
50
+ if (node_fs_1.default.existsSync(indexTsPath)) {
51
+ return indexTsPath;
52
+ }
53
+ const indexVuePath = `${filePath}/index.vue`;
54
+ if (node_fs_1.default.existsSync(indexVuePath)) {
55
+ return indexVuePath;
56
+ }
57
+ const indexTsxPath = `${filePath}/index.tsx`;
58
+ if (node_fs_1.default.existsSync(indexTsxPath)) {
59
+ return indexTsxPath;
60
+ }
61
+ const indexJsxPath = `${filePath}/index.jsx`;
62
+ if (node_fs_1.default.existsSync(indexJsxPath)) {
63
+ return indexJsxPath;
64
+ }
65
+ return filePath;
66
+ };
67
+ exports.resolveFilePath = resolveFilePath;
68
+ /**
69
+ * 解析输出路径
70
+ * @param outputAbsoluteFilePath 输出路径
71
+ * @param context 上下文
72
+ * @returns 解析后的路径
73
+ */
74
+ const resolveOutputAbsoluteFilePath = (outputAbsoluteFilePath, context) => {
75
+ if (outputAbsoluteFilePath.includes('node_modules')) {
76
+ return outputAbsoluteFilePath.replace(/.+node_modules\/(.+)/, `${context.workDir}/${context.options.preserveModulesRoot ? `${context.options.preserveModulesRoot}/` : ''}node_modules/$1`);
77
+ }
78
+ return outputAbsoluteFilePath;
79
+ };
80
+ exports.resolveOutputAbsoluteFilePath = resolveOutputAbsoluteFilePath;
81
+ /**
82
+ * 判断路径是否是 External 的路径
83
+ * @param filePath 文件路径
84
+ * @param context 上下文
85
+ * @returns 是否匹配
86
+ */
87
+ const isPathMatchExternal = (filePath, context) => {
88
+ const externals = context.options.configureWebpack?.externals || {};
89
+ const externalKeys = Object.keys(externals);
90
+ let isMatch = false;
91
+ externalKeys.forEach((key) => {
92
+ if (key === filePath) {
93
+ isMatch = true;
94
+ }
95
+ if (filePath.startsWith(`${key}/`)) {
96
+ isMatch = true;
97
+ }
98
+ });
99
+ return isMatch;
100
+ };
101
+ exports.isPathMatchExternal = isPathMatchExternal;
102
+ /**
103
+ * 获取依赖的绝对路径
104
+ * @param dependencyPath 引入依赖的路径
105
+ * @param originAbsoluteFilePath 引入方的绝对路径
106
+ * @param context 上下文
107
+ * @returns 依赖的绝对路径
108
+ */
109
+ const getAbsoluteDependencyPath = (dependencyPath, originAbsoluteFilePath, context) => {
110
+ let toPath = dependencyPath;
111
+ const aliasMap = {
112
+ '@': (0, util_1.getAbsolutePath)(context.workDir, 'src'),
113
+ };
114
+ // 用户配置的 alias
115
+ Object.keys(context.options.configureWebpack?.resolve?.alias || {}).forEach((key) => {
116
+ aliasMap[key] = (0, util_1.resolveUserPath)(context.workDir, context.options.configureWebpack.resolve.alias[key]);
117
+ });
118
+ // 替换 alias 路径
119
+ let aliasKey = '';
120
+ let aliasValue = '';
121
+ // 遍历 aliasMap 替换路径
122
+ Object.keys(aliasMap).forEach((key) => {
123
+ // 命中别名,最长命中优先级更高
124
+ if (toPath.startsWith(key) && key.length > aliasKey.length) {
125
+ aliasKey = key;
126
+ aliasValue = aliasMap[key];
127
+ }
128
+ });
129
+ if (aliasKey && aliasValue) {
130
+ toPath = toPath.replace(aliasKey, aliasValue);
131
+ }
132
+ return (0, util_1.resolveUserPath)((0, util_1.getDirName)(originAbsoluteFilePath), toPath);
133
+ };
134
+ exports.getAbsoluteDependencyPath = getAbsoluteDependencyPath;
135
+ /**
136
+ * 获取依赖的参数
137
+ * @param dependency 依赖
138
+ * @returns 参数
139
+ */
140
+ const getDependencyQueryAndHash = (dependency) => {
141
+ let queryAndHash = '';
142
+ if (dependency.query) {
143
+ queryAndHash += `?${dependency.query}`;
144
+ }
145
+ if (dependency.hash) {
146
+ queryAndHash += `#${dependency.hash}`;
147
+ }
148
+ return queryAndHash;
149
+ };
150
+ exports.getDependencyQueryAndHash = getDependencyQueryAndHash;
151
+ /**
152
+ * 解析依赖参数
153
+ * @param originDependencyPath 原始引用路径
154
+ * @returns 引用参数
155
+ */
156
+ const parseDependencyQueryAndHash = (originDependencyPath) => {
157
+ let hash = '';
158
+ let query = '';
159
+ let dependencyPath = originDependencyPath;
160
+ if (dependencyPath.includes('#')) {
161
+ [dependencyPath, hash] = dependencyPath.split('#');
162
+ }
163
+ if (dependencyPath.includes('?')) {
164
+ [dependencyPath, query] = dependencyPath.split('?');
165
+ }
166
+ return {
167
+ dependencyPath,
168
+ hash,
169
+ query,
170
+ };
171
+ };
172
+ exports.parseDependencyQueryAndHash = parseDependencyQueryAndHash;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MissingRefError = exports.ValidationError = exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = exports.Ajv = void 0;
4
+ const core_1 = require('./core.js');
5
+ const draft7_1 = require('./vocabularies/draft7.js');
6
+ const discriminator_1 = require('./vocabularies/discriminator/index.js');
7
+ const draft7MetaSchema = require('./refs/json-schema-draft-07.json');
8
+ const META_SUPPORT_DATA = ["/properties"];
9
+ const META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
10
+ class Ajv extends core_1.default {
11
+ _addVocabularies() {
12
+ super._addVocabularies();
13
+ draft7_1.default.forEach((v) => this.addVocabulary(v));
14
+ if (this.opts.discriminator)
15
+ this.addKeyword(discriminator_1.default);
16
+ }
17
+ _addDefaultMetaSchema() {
18
+ super._addDefaultMetaSchema();
19
+ if (!this.opts.meta)
20
+ return;
21
+ const metaSchema = this.opts.$data
22
+ ? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA)
23
+ : draft7MetaSchema;
24
+ this.addMetaSchema(metaSchema, META_SCHEMA_ID, false);
25
+ this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
26
+ }
27
+ defaultMeta() {
28
+ return (this.opts.defaultMeta =
29
+ super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined));
30
+ }
31
+ }
32
+ exports.Ajv = Ajv;
33
+ module.exports = exports = Ajv;
34
+ module.exports.Ajv = Ajv;
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.default = Ajv;
37
+ var validate_1 = require('./compile/validate/index.js');
38
+ Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function () { return validate_1.KeywordCxt; } });
39
+ var codegen_1 = require('./compile/codegen/index.js');
40
+ Object.defineProperty(exports, "_", { enumerable: true, get: function () { return codegen_1._; } });
41
+ Object.defineProperty(exports, "str", { enumerable: true, get: function () { return codegen_1.str; } });
42
+ Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
43
+ Object.defineProperty(exports, "nil", { enumerable: true, get: function () { return codegen_1.nil; } });
44
+ Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return codegen_1.Name; } });
45
+ Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function () { return codegen_1.CodeGen; } });
46
+ var validation_error_1 = require('./runtime/validation_error.js');
47
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validation_error_1.default; } });
48
+ var ref_error_1 = require('./compile/ref_error.js');
49
+ Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function () { return ref_error_1.default; } });
50
+ //# sourceMappingURL=ajv.js.map