@agentscope-ai/flow 0.0.1
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.zh-CN.md +67 -0
- package/dist/components/base-node/index.d.ts +27 -0
- package/dist/components/base-node/index.js +320 -0
- package/dist/components/base-node/index.less +258 -0
- package/dist/components/branch-title-header/index.d.ts +12 -0
- package/dist/components/branch-title-header/index.js +176 -0
- package/dist/components/branch-title-header/index.less +28 -0
- package/dist/components/check-list-btn/index.d.ts +4 -0
- package/dist/components/check-list-btn/index.js +144 -0
- package/dist/components/check-list-btn/index.less +113 -0
- package/dist/components/code-input/index.d.ts +24 -0
- package/dist/components/code-input/index.js +356 -0
- package/dist/components/code-input/index.less +87 -0
- package/dist/components/condition-item/index.d.ts +13 -0
- package/dist/components/condition-item/index.js +185 -0
- package/dist/components/condition-item/index.less +23 -0
- package/dist/components/custom-connection-line/index.d.ts +4 -0
- package/dist/components/custom-connection-line/index.js +28 -0
- package/dist/components/custom-handle/source-handle.d.ts +10 -0
- package/dist/components/custom-handle/source-handle.js +45 -0
- package/dist/components/custom-handle/target-handle.d.ts +6 -0
- package/dist/components/custom-handle/target-handle.js +21 -0
- package/dist/components/custom-inputs-control/index.d.ts +56 -0
- package/dist/components/custom-inputs-control/index.js +366 -0
- package/dist/components/custom-inputs-control/index.less +28 -0
- package/dist/components/custom-outputs-form/index.d.ts +24 -0
- package/dist/components/custom-outputs-form/index.js +346 -0
- package/dist/components/custom-outputs-form/index.less +51 -0
- package/dist/components/drag-panel/index.d.ts +10 -0
- package/dist/components/drag-panel/index.js +79 -0
- package/dist/components/drag-panel/index.less +23 -0
- package/dist/components/draggable-with-handle/index.d.ts +13 -0
- package/dist/components/draggable-with-handle/index.js +81 -0
- package/dist/components/draggable-with-handle/index.less +23 -0
- package/dist/components/flow-aside/index.d.ts +4 -0
- package/dist/components/flow-aside/index.js +62 -0
- package/dist/components/flow-aside/index.less +84 -0
- package/dist/components/flow-base-edge/index.d.ts +5 -0
- package/dist/components/flow-base-edge/index.js +226 -0
- package/dist/components/flow-base-edge/index.less +28 -0
- package/dist/components/flow-base-edge/linear-gradient-svg.d.ts +21 -0
- package/dist/components/flow-base-edge/linear-gradient-svg.js +32 -0
- package/dist/components/flow-icon/index.d.ts +9 -0
- package/dist/components/flow-icon/index.js +30 -0
- package/dist/components/flow-icon/index.less +20 -0
- package/dist/components/flow-mini-map/index.d.ts +4 -0
- package/dist/components/flow-mini-map/index.js +26 -0
- package/dist/components/flow-mini-map/index.less +22 -0
- package/dist/components/flow-panel/config-panel.d.ts +15 -0
- package/dist/components/flow-panel/config-panel.js +303 -0
- package/dist/components/flow-panel/index.d.ts +7 -0
- package/dist/components/flow-panel/index.js +7 -0
- package/dist/components/flow-panel/index.less +85 -0
- package/dist/components/flow-panel/panel-container.d.ts +12 -0
- package/dist/components/flow-panel/panel-container.js +25 -0
- package/dist/components/flow-tools/add-node-btn.d.ts +3 -0
- package/dist/components/flow-tools/add-node-btn.js +26 -0
- package/dist/components/flow-tools/history-btn.d.ts +3 -0
- package/dist/components/flow-tools/history-btn.js +59 -0
- package/dist/components/flow-tools/index.d.ts +4 -0
- package/dist/components/flow-tools/index.js +29 -0
- package/dist/components/flow-tools/index.less +82 -0
- package/dist/components/flow-tools/layout-btn.d.ts +3 -0
- package/dist/components/flow-tools/layout-btn.js +27 -0
- package/dist/components/flow-tools/mini-map-btn.d.ts +3 -0
- package/dist/components/flow-tools/mini-map-btn.js +32 -0
- package/dist/components/flow-tools/scale-btn.d.ts +3 -0
- package/dist/components/flow-tools/scale-btn.js +101 -0
- package/dist/components/flow-tools/short-key-btn.d.ts +3 -0
- package/dist/components/flow-tools/short-key-btn.js +38 -0
- package/dist/components/flow-tools/short-key-content.d.ts +4 -0
- package/dist/components/flow-tools/short-key-content.js +153 -0
- package/dist/components/flow-tools/short-key-content.less +38 -0
- package/dist/components/flow-tools/touch-mode-btn.d.ts +3 -0
- package/dist/components/flow-tools/touch-mode-btn.js +89 -0
- package/dist/components/input-text-area/index.d.ts +16 -0
- package/dist/components/input-text-area/index.js +74 -0
- package/dist/components/input-text-area/index.less +30 -0
- package/dist/components/judge-form/index.d.ts +13 -0
- package/dist/components/judge-form/index.js +182 -0
- package/dist/components/judge-form/index.less +11 -0
- package/dist/components/node-menu/index.d.ts +35 -0
- package/dist/components/node-menu/index.js +266 -0
- package/dist/components/node-menu/index.less +79 -0
- package/dist/components/node-resizer/index.d.ts +11 -0
- package/dist/components/node-resizer/index.js +46 -0
- package/dist/components/node-resizer/index.less +12 -0
- package/dist/components/node-result-panel/index.d.ts +9 -0
- package/dist/components/node-result-panel/index.js +155 -0
- package/dist/components/node-result-panel/index.less +132 -0
- package/dist/components/node-tree/index.d.ts +4 -0
- package/dist/components/node-tree/index.js +213 -0
- package/dist/components/node-tree/index.less +51 -0
- package/dist/components/output-params-tree/index.d.ts +10 -0
- package/dist/components/output-params-tree/index.js +34 -0
- package/dist/components/output-params-tree/index.less +27 -0
- package/dist/components/script-code-mirror/index.d.ts +14 -0
- package/dist/components/script-code-mirror/index.js +162 -0
- package/dist/components/script-code-mirror/index.less +11 -0
- package/dist/components/script-edit-modal/index.d.ts +30 -0
- package/dist/components/script-edit-modal/index.js +84 -0
- package/dist/components/script-edit-modal/index.less +24 -0
- package/dist/components/select-with-desc/index.d.ts +5 -0
- package/dist/components/select-with-desc/index.js +20 -0
- package/dist/components/select-with-desc/index.less +11 -0
- package/dist/components/task-status/index.d.ts +4 -0
- package/dist/components/task-status/index.js +209 -0
- package/dist/components/task-status/index.less +65 -0
- package/dist/components/var-input-text-area/index.d.ts +17 -0
- package/dist/components/var-input-text-area/index.js +211 -0
- package/dist/components/var-input-text-area/index.less +64 -0
- package/dist/components/var-type-prefix/index.d.ts +17 -0
- package/dist/components/var-type-prefix/index.js +21 -0
- package/dist/components/variable-input/index.d.ts +24 -0
- package/dist/components/variable-input/index.js +163 -0
- package/dist/components/variable-input/index.less +13 -0
- package/dist/components/variable-tree-select/index.d.ts +33 -0
- package/dist/components/variable-tree-select/index.js +160 -0
- package/dist/components/variable-tree-select/index.less +61 -0
- package/dist/constant/index.d.ts +61 -0
- package/dist/constant/index.js +515 -0
- package/dist/flow/animate.css +5 -0
- package/dist/flow/context.d.ts +12 -0
- package/dist/flow/context.js +44 -0
- package/dist/flow/index.d.ts +13 -0
- package/dist/flow/index.js +162 -0
- package/dist/flow/index.less +72 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.js +10 -0
- package/dist/hooks/use-edges-interaction.d.ts +11 -0
- package/dist/hooks/use-edges-interaction.js +125 -0
- package/dist/hooks/use-flow-debug-interaction.d.ts +5 -0
- package/dist/hooks/use-flow-debug-interaction.js +23 -0
- package/dist/hooks/use-flow-interaction.d.ts +12 -0
- package/dist/hooks/use-flow-interaction.js +173 -0
- package/dist/hooks/use-flow-key-press.d.ts +1 -0
- package/dist/hooks/use-flow-key-press.js +32 -0
- package/dist/hooks/use-flow-save.d.ts +5 -0
- package/dist/hooks/use-flow-save.js +47 -0
- package/dist/hooks/use-flow-view-port.d.ts +7 -0
- package/dist/hooks/use-flow-view-port.js +46 -0
- package/dist/hooks/use-history.d.ts +21 -0
- package/dist/hooks/use-history.js +80 -0
- package/dist/hooks/use-nodes-interaction.d.ts +34 -0
- package/dist/hooks/use-nodes-interaction.js +777 -0
- package/dist/hooks/use-nodes-output-params.d.ts +31 -0
- package/dist/hooks/use-nodes-output-params.js +300 -0
- package/dist/hooks/use-nodes-update.d.ts +9 -0
- package/dist/hooks/use-nodes-update.js +38 -0
- package/dist/hooks/use-work-flow.d.ts +4 -0
- package/dist/hooks/use-work-flow.js +21 -0
- package/dist/i18n/i18n.d.ts +62 -0
- package/dist/i18n/i18n.js +111 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +12 -0
- package/dist/i18n/locales/en-us.json +327 -0
- package/dist/i18n/locales/ja-jp.json +300 -0
- package/dist/i18n/locales/zh-cn.json +327 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +47 -0
- package/dist/index.less +1 -0
- package/dist/store/index.d.ts +70 -0
- package/dist/store/index.js +146 -0
- package/dist/tailwind.css +28 -0
- package/dist/types/work-flow.d.ts +188 -0
- package/dist/types/work-flow.js +1 -0
- package/dist/utils/default-values.d.ts +2 -0
- package/dist/utils/default-values.js +16 -0
- package/dist/utils/index.d.ts +39 -0
- package/dist/utils/index.js +273 -0
- package/dist/utils/unique-id.d.ts +2 -0
- package/dist/utils/unique-id.js +39 -0
- package/dist/utils/work-flow.d.ts +17 -0
- package/dist/utils/work-flow.js +44 -0
- package/package.json +78 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IVarItem, IVarTreeItem } from "../components/variable-tree-select";
|
|
2
|
+
import { INodeDataOutputParamItem, IValueType, IWorkFlowNode } from "../types/work-flow";
|
|
3
|
+
interface IQueryVariableListParams {
|
|
4
|
+
type?: IValueType;
|
|
5
|
+
scope?: 'sub' | 'global';
|
|
6
|
+
nodeId: string;
|
|
7
|
+
disableShowParentParams?: boolean;
|
|
8
|
+
disableShowVariableParameters?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface ArrayPathInfo {
|
|
11
|
+
fullPath: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const buildOutputParamsTree: ({ outputParams, nodeId, parentKey, parentType, arrayPathStack, arrayWrap, flat, }: {
|
|
14
|
+
outputParams: Array<INodeDataOutputParamItem>;
|
|
15
|
+
nodeId: string;
|
|
16
|
+
parentKey?: string | undefined;
|
|
17
|
+
parentType?: string | undefined;
|
|
18
|
+
arrayPathStack?: ArrayPathInfo[] | undefined;
|
|
19
|
+
arrayWrap?: boolean | undefined;
|
|
20
|
+
flat?: boolean | undefined;
|
|
21
|
+
}) => IVarItem[];
|
|
22
|
+
export declare const filterVarItemsByType: (items: IVarItem[], types: IValueType[]) => IVarItem[];
|
|
23
|
+
export declare const useNodesOutputParams: () => {
|
|
24
|
+
getVariableList: (params: IQueryVariableListParams) => IVarTreeItem[];
|
|
25
|
+
getSubNodesVariables: (nodeId: string) => IVarTreeItem[];
|
|
26
|
+
getSystemVariableList: () => IVarTreeItem[];
|
|
27
|
+
getOutputParamsFromNodesMap: (nodesMap: Record<string, IWorkFlowNode>, options?: {
|
|
28
|
+
arrayWrap?: boolean;
|
|
29
|
+
}) => IVarTreeItem[];
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
|
+
import { useStore } from "../flow/context";
|
|
14
|
+
import $i18n from "../i18n";
|
|
15
|
+
// import { getParentNodeVariableList } from '@/utils';
|
|
16
|
+
import { getNeighborNodes } from "../utils/work-flow";
|
|
17
|
+
import { useStoreApi } from '@xyflow/react';
|
|
18
|
+
import { useCallback } from 'react';
|
|
19
|
+
|
|
20
|
+
// 记录 Array<Object> 层级的完整路径信息
|
|
21
|
+
|
|
22
|
+
export var buildOutputParamsTree = function buildOutputParamsTree(_ref) {
|
|
23
|
+
var outputParams = _ref.outputParams,
|
|
24
|
+
nodeId = _ref.nodeId,
|
|
25
|
+
_ref$parentKey = _ref.parentKey,
|
|
26
|
+
parentKey = _ref$parentKey === void 0 ? '' : _ref$parentKey,
|
|
27
|
+
_ref$parentType = _ref.parentType,
|
|
28
|
+
parentType = _ref$parentType === void 0 ? '' : _ref$parentType,
|
|
29
|
+
_ref$arrayPathStack = _ref.arrayPathStack,
|
|
30
|
+
arrayPathStack = _ref$arrayPathStack === void 0 ? [] : _ref$arrayPathStack,
|
|
31
|
+
_ref$arrayWrap = _ref.arrayWrap,
|
|
32
|
+
arrayWrap = _ref$arrayWrap === void 0 ? false : _ref$arrayWrap,
|
|
33
|
+
_ref$flat = _ref.flat,
|
|
34
|
+
flat = _ref$flat === void 0 ? false : _ref$flat;
|
|
35
|
+
var list = [];
|
|
36
|
+
var flatList = [];
|
|
37
|
+
var keySet = new Set();
|
|
38
|
+
var processItem = function processItem(item) {
|
|
39
|
+
if (!item.key || keySet.has(item.key)) return;
|
|
40
|
+
keySet.add(item.key);
|
|
41
|
+
var itemKey = parentKey ? "".concat(parentKey, ".").concat(item.key) : item.key;
|
|
42
|
+
var itemArrayPathStack = _toConsumableArray(arrayPathStack);
|
|
43
|
+
// 如果父节点是 Array<Object>,记录当前元素的完整路径
|
|
44
|
+
if (parentType.startsWith('Array')) {
|
|
45
|
+
itemArrayPathStack.push({
|
|
46
|
+
fullPath: itemKey
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* Build value format */
|
|
51
|
+
var valueFormat = '';
|
|
52
|
+
if (itemArrayPathStack.length > 0) {
|
|
53
|
+
/* Handle multi-level nested Array<Object> */
|
|
54
|
+
var pathParts = itemKey.split('.');
|
|
55
|
+
|
|
56
|
+
// 找到第一个 Array<Object> 的路径
|
|
57
|
+
var firstArrayPath = itemArrayPathStack[0].fullPath;
|
|
58
|
+
var firstArrayParts = firstArrayPath.split('.');
|
|
59
|
+
|
|
60
|
+
// baseProperty 是第一个 Array<Object> 之前的路径
|
|
61
|
+
var baseProperty = pathParts.slice(0, firstArrayParts.length - 1).join('.');
|
|
62
|
+
|
|
63
|
+
// 构建嵌套路径:需要在各个 Array<Object> 层级之间插入中间的普通 Object 路径
|
|
64
|
+
var nestedPath = '';
|
|
65
|
+
|
|
66
|
+
// 从最后一个数组层级开始向前构建
|
|
67
|
+
for (var i = itemArrayPathStack.length - 1; i >= 0; i--) {
|
|
68
|
+
var currentArrayPath = itemArrayPathStack[i].fullPath;
|
|
69
|
+
var currentArrayParts = currentArrayPath.split('.');
|
|
70
|
+
var currentArrayKey = currentArrayParts[currentArrayParts.length - 1];
|
|
71
|
+
if (i === itemArrayPathStack.length - 1) {
|
|
72
|
+
// 最后一层:包含从最后一个数组到当前元素的路径
|
|
73
|
+
var lastArrayParts = currentArrayParts;
|
|
74
|
+
var remainingParts = pathParts.slice(lastArrayParts.length);
|
|
75
|
+
nestedPath = remainingParts.length > 0 ? "".concat(currentArrayKey, ".").concat(remainingParts.join('.')) : currentArrayKey;
|
|
76
|
+
} else {
|
|
77
|
+
// 中间层:需要包含到下一个数组之间的路径
|
|
78
|
+
var nextArrayPath = itemArrayPathStack[i + 1].fullPath;
|
|
79
|
+
var nextArrayParts = nextArrayPath.split('.');
|
|
80
|
+
|
|
81
|
+
// 计算当前数组和下一个数组之间的中间路径
|
|
82
|
+
var middleParts = nextArrayParts.slice(currentArrayParts.length, nextArrayParts.length - 1);
|
|
83
|
+
var middlePath = middleParts.length > 0 ? "".concat(middleParts.join('.'), ".") : '';
|
|
84
|
+
nestedPath = "".concat(currentArrayKey, ".").concat(middlePath, "[").concat(nestedPath, "]");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (arrayWrap) {
|
|
88
|
+
valueFormat = baseProperty ? "${".concat(nodeId, ".[").concat(baseProperty, ".[").concat(nestedPath, "]]}") : "${".concat(nodeId, ".[").concat(nestedPath, "]}");
|
|
89
|
+
} else {
|
|
90
|
+
valueFormat = baseProperty ? "${".concat(nodeId, ".").concat(baseProperty, ".[").concat(nestedPath, "]}") : "${".concat(nodeId, ".[").concat(nestedPath, "]}");
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
/* Normal property */
|
|
94
|
+
if (arrayWrap) {
|
|
95
|
+
/* If arrayWrap is true, wrap all properties as array structure */
|
|
96
|
+
var _pathParts = itemKey.split('.');
|
|
97
|
+
if (_pathParts.length === 1) {
|
|
98
|
+
/* Single-level property, e.g. ${Script_id.result} -> ${Script_id.[result]} */
|
|
99
|
+
valueFormat = "${".concat(nodeId, ".[").concat(itemKey, "]}");
|
|
100
|
+
} else {
|
|
101
|
+
/* Multi-level property, e.g. ${Script_id.result.name} -> ${Script_id.[result.name]} */
|
|
102
|
+
var _baseProperty = _pathParts[0];
|
|
103
|
+
var _nestedPath = _pathParts.slice(1).join('.');
|
|
104
|
+
valueFormat = "${".concat(nodeId, ".[").concat(_baseProperty, ".").concat(_nestedPath, "]}");
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
valueFormat = "${".concat(nodeId, ".").concat(itemKey, "}");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* Generate new type based on arrayWrap and original type */
|
|
112
|
+
var newType;
|
|
113
|
+
if (arrayWrap) {
|
|
114
|
+
newType = "Array<".concat(item.type || 'String', ">");
|
|
115
|
+
} else {
|
|
116
|
+
newType = item.type;
|
|
117
|
+
}
|
|
118
|
+
var varItem = {
|
|
119
|
+
label: item.key,
|
|
120
|
+
value: valueFormat,
|
|
121
|
+
type: newType
|
|
122
|
+
};
|
|
123
|
+
if (flat) {
|
|
124
|
+
flatList.push(varItem);
|
|
125
|
+
}
|
|
126
|
+
if (item.properties && item.properties.length > 0) {
|
|
127
|
+
var childItems = buildOutputParamsTree({
|
|
128
|
+
outputParams: item.properties,
|
|
129
|
+
nodeId: nodeId,
|
|
130
|
+
parentKey: itemKey,
|
|
131
|
+
parentType: item.type,
|
|
132
|
+
arrayPathStack: itemArrayPathStack,
|
|
133
|
+
arrayWrap: arrayWrap,
|
|
134
|
+
flat: flat
|
|
135
|
+
});
|
|
136
|
+
if (childItems.length > 0) {
|
|
137
|
+
if (flat) {
|
|
138
|
+
flatList.push.apply(flatList, _toConsumableArray(childItems));
|
|
139
|
+
} else {
|
|
140
|
+
varItem.children = childItems;
|
|
141
|
+
list.push(varItem);
|
|
142
|
+
}
|
|
143
|
+
} else if (!flat) {
|
|
144
|
+
list.push(varItem);
|
|
145
|
+
}
|
|
146
|
+
} else if (!flat) {
|
|
147
|
+
list.push(varItem);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
outputParams.forEach(processItem);
|
|
151
|
+
return flat ? flatList : list;
|
|
152
|
+
};
|
|
153
|
+
export var filterVarItemsByType = function filterVarItemsByType(items, types) {
|
|
154
|
+
return items.reduce(function (filtered, item) {
|
|
155
|
+
/* If the type of the current item matches, add it to the result */
|
|
156
|
+
var filteredItem = null;
|
|
157
|
+
if (types.includes(item.type)) {
|
|
158
|
+
filteredItem = item;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* If there are children, recursively process the children */
|
|
162
|
+
if (item.children && item.children.length > 0) {
|
|
163
|
+
var filteredChildren = filterVarItemsByType(item.children, types);
|
|
164
|
+
if (filteredChildren.length > 0) {
|
|
165
|
+
/* If there are matches in the children, keep the current item and update its children */
|
|
166
|
+
filteredItem = _objectSpread(_objectSpread({}, item), {}, {
|
|
167
|
+
children: filteredChildren
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
filteredItem && filtered.push(filteredItem);
|
|
172
|
+
return filtered;
|
|
173
|
+
}, []);
|
|
174
|
+
};
|
|
175
|
+
export var useNodesOutputParams = function useNodesOutputParams() {
|
|
176
|
+
var store = useStoreApi();
|
|
177
|
+
var nodeSchemaMap = useStore(function (state) {
|
|
178
|
+
return state.nodeSchemaMap;
|
|
179
|
+
});
|
|
180
|
+
var getOutputParamsFromNodesMap = useCallback(function (nodesMap) {
|
|
181
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
182
|
+
var outputParams = [];
|
|
183
|
+
Object.keys(nodesMap).forEach(function (nodeId) {
|
|
184
|
+
var _node$data$output_par;
|
|
185
|
+
var node = nodesMap[nodeId];
|
|
186
|
+
if (((_node$data$output_par = node.data.output_params) === null || _node$data$output_par === void 0 ? void 0 : _node$data$output_par.length) > 0) {
|
|
187
|
+
var varItems = buildOutputParamsTree(_objectSpread({
|
|
188
|
+
outputParams: node.data.output_params,
|
|
189
|
+
nodeId: nodeId
|
|
190
|
+
}, options));
|
|
191
|
+
if (varItems.length > 0) {
|
|
192
|
+
outputParams.push({
|
|
193
|
+
label: node.data.label || node.id,
|
|
194
|
+
nodeId: node.id,
|
|
195
|
+
nodeType: node.type,
|
|
196
|
+
children: varItems
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
return outputParams;
|
|
202
|
+
}, [store]);
|
|
203
|
+
var getSystemVariableList = useCallback(function () {
|
|
204
|
+
return [{
|
|
205
|
+
label: $i18n.get({
|
|
206
|
+
id: 'spark-flow.hooks.useNodesOutputParams.builtinVariable',
|
|
207
|
+
dm: '内置变量'
|
|
208
|
+
}),
|
|
209
|
+
nodeId: 'sys',
|
|
210
|
+
nodeType: 'sys',
|
|
211
|
+
children: [{
|
|
212
|
+
label: 'query',
|
|
213
|
+
value: '${sys.query}',
|
|
214
|
+
type: 'String'
|
|
215
|
+
}, {
|
|
216
|
+
label: 'history_list',
|
|
217
|
+
value: '${sys.history_list}',
|
|
218
|
+
type: 'Array<String>'
|
|
219
|
+
}]
|
|
220
|
+
}];
|
|
221
|
+
}, []);
|
|
222
|
+
var getSubNodesVariableList = useCallback(function (subNodes) {
|
|
223
|
+
var nodesMap = subNodes.reduce(function (acc, node) {
|
|
224
|
+
acc[node.id] = node;
|
|
225
|
+
return acc;
|
|
226
|
+
}, {});
|
|
227
|
+
var variableList = getOutputParamsFromNodesMap(nodesMap, {
|
|
228
|
+
arrayWrap: true
|
|
229
|
+
});
|
|
230
|
+
return variableList;
|
|
231
|
+
}, [store, getOutputParamsFromNodesMap]);
|
|
232
|
+
var getVariableList = useCallback(function (params) {
|
|
233
|
+
var nodeId = params.nodeId;
|
|
234
|
+
var _store$getState = store.getState(),
|
|
235
|
+
edges = _store$getState.edges,
|
|
236
|
+
nodes = _store$getState.nodes;
|
|
237
|
+
var targetNode = nodes.find(function (node) {
|
|
238
|
+
return node.id === nodeId;
|
|
239
|
+
});
|
|
240
|
+
if (!targetNode) return [];
|
|
241
|
+
var globalNodes = [];
|
|
242
|
+
var subNodes = [];
|
|
243
|
+
nodes.forEach(function (node) {
|
|
244
|
+
if (!node.parentId) {
|
|
245
|
+
/* Nodes without parentId belong to global nodes */
|
|
246
|
+
globalNodes.push(node);
|
|
247
|
+
} else if (node.parentId === targetNode.parentId) {
|
|
248
|
+
subNodes.push(node);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
/* Get predecessor nodes */
|
|
253
|
+
var neighborNodesMap = {};
|
|
254
|
+
var parentVariableList = [];
|
|
255
|
+
if (targetNode.parentId) {
|
|
256
|
+
/* If it is a sub-node, get the predecessor nodes of the parent node or the predecessor nodes in the sub-canvas */
|
|
257
|
+
var parentNode = nodes.find(function (node) {
|
|
258
|
+
return node.id === targetNode.parentId;
|
|
259
|
+
});
|
|
260
|
+
if (parentNode) {
|
|
261
|
+
var _nodeSchemaMap;
|
|
262
|
+
if (!params.disableShowParentParams && !!((_nodeSchemaMap = nodeSchemaMap[parentNode.type]) !== null && _nodeSchemaMap !== void 0 && _nodeSchemaMap.getParentNodeVariableList)) {
|
|
263
|
+
var _nodeSchemaMap$getPar, _nodeSchemaMap2;
|
|
264
|
+
parentVariableList = ((_nodeSchemaMap$getPar = (_nodeSchemaMap2 = nodeSchemaMap[parentNode.type]).getParentNodeVariableList) === null || _nodeSchemaMap$getPar === void 0 ? void 0 : _nodeSchemaMap$getPar.call(_nodeSchemaMap2, parentNode, {
|
|
265
|
+
disableShowVariableParameters: params.disableShowVariableParameters
|
|
266
|
+
})) || [];
|
|
267
|
+
}
|
|
268
|
+
neighborNodesMap = _objectSpread(_objectSpread(_objectSpread({}, neighborNodesMap), getNeighborNodes({
|
|
269
|
+
nodes: globalNodes,
|
|
270
|
+
edges: edges,
|
|
271
|
+
nodeId: parentNode.id
|
|
272
|
+
})), getNeighborNodes({
|
|
273
|
+
nodes: subNodes,
|
|
274
|
+
edges: edges,
|
|
275
|
+
nodeId: targetNode.id
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
neighborNodesMap = _objectSpread(_objectSpread({}, neighborNodesMap), getNeighborNodes({
|
|
280
|
+
nodes: globalNodes,
|
|
281
|
+
edges: edges,
|
|
282
|
+
nodeId: targetNode.id
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
return [].concat(_toConsumableArray(parentVariableList), _toConsumableArray(getSystemVariableList()), _toConsumableArray(getOutputParamsFromNodesMap(neighborNodesMap)));
|
|
286
|
+
}, [store, getOutputParamsFromNodesMap, nodeSchemaMap]);
|
|
287
|
+
var getSubNodesVariables = useCallback(function (nodeId) {
|
|
288
|
+
var _store$getState2 = store.getState(),
|
|
289
|
+
nodes = _store$getState2.nodes;
|
|
290
|
+
return getSubNodesVariableList(nodes.filter(function (item) {
|
|
291
|
+
return item.parentId === nodeId;
|
|
292
|
+
}));
|
|
293
|
+
}, [store]);
|
|
294
|
+
return {
|
|
295
|
+
getVariableList: getVariableList,
|
|
296
|
+
getSubNodesVariables: getSubNodesVariables,
|
|
297
|
+
getSystemVariableList: getSystemVariableList,
|
|
298
|
+
getOutputParamsFromNodesMap: getOutputParamsFromNodesMap
|
|
299
|
+
};
|
|
300
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IWorkFlowNodeData } from "../types/work-flow";
|
|
2
|
+
type NodeDataUpdatePayload = {
|
|
3
|
+
id: string;
|
|
4
|
+
data: Partial<IWorkFlowNodeData>;
|
|
5
|
+
};
|
|
6
|
+
export declare const useNodeDataUpdate: () => {
|
|
7
|
+
handleNodeDataUpdate: ({ id, data }: NodeDataUpdatePayload) => void;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { useStoreApi } from '@xyflow/react';
|
|
8
|
+
import { useCallback } from 'react';
|
|
9
|
+
import { useFlowSave } from "./use-flow-save";
|
|
10
|
+
import { useNodesReadOnly } from "./use-work-flow";
|
|
11
|
+
export var useNodeDataUpdate = function useNodeDataUpdate() {
|
|
12
|
+
var store = useStoreApi();
|
|
13
|
+
var _useFlowSave = useFlowSave(),
|
|
14
|
+
handleSaveFlowDraft = _useFlowSave.handleSaveFlowDraft;
|
|
15
|
+
var _useNodesReadOnly = useNodesReadOnly(),
|
|
16
|
+
getNodesReadOnly = _useNodesReadOnly.getNodesReadOnly;
|
|
17
|
+
var handleNodeDataUpdate = useCallback(function (_ref) {
|
|
18
|
+
var id = _ref.id,
|
|
19
|
+
data = _ref.data;
|
|
20
|
+
if (getNodesReadOnly()) return;
|
|
21
|
+
var _store$getState = store.getState(),
|
|
22
|
+
nodes = _store$getState.nodes,
|
|
23
|
+
setNodes = _store$getState.setNodes;
|
|
24
|
+
var newNodes = nodes.map(function (node) {
|
|
25
|
+
if (node.id === id) {
|
|
26
|
+
return _objectSpread(_objectSpread({}, node), {}, {
|
|
27
|
+
data: _objectSpread(_objectSpread({}, node.data), data)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return node;
|
|
31
|
+
});
|
|
32
|
+
setNodes(newNodes);
|
|
33
|
+
handleSaveFlowDraft();
|
|
34
|
+
}, [store, handleSaveFlowDraft]);
|
|
35
|
+
return {
|
|
36
|
+
handleNodeDataUpdate: handleNodeDataUpdate
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { WorkflowRunningStatus } from "../constant";
|
|
3
|
+
import { useStore, useWorkflowStore } from "../flow/context";
|
|
4
|
+
export var useNodesReadOnly = function useNodesReadOnly() {
|
|
5
|
+
var workflowStore = useWorkflowStore();
|
|
6
|
+
var taskStore = useStore(function (s) {
|
|
7
|
+
return s.taskStore;
|
|
8
|
+
});
|
|
9
|
+
var readyOnly = useStore(function (s) {
|
|
10
|
+
return s.readyOnly;
|
|
11
|
+
});
|
|
12
|
+
var getNodesReadOnly = useCallback(function () {
|
|
13
|
+
var _workflowStore$getSta = workflowStore.getState(),
|
|
14
|
+
taskStore = _workflowStore$getSta.taskStore;
|
|
15
|
+
return [WorkflowRunningStatus.Running, WorkflowRunningStatus.Paused].includes((taskStore === null || taskStore === void 0 ? void 0 : taskStore.task_status) || '') || readyOnly;
|
|
16
|
+
}, [workflowStore, readyOnly]);
|
|
17
|
+
return {
|
|
18
|
+
nodesReadOnly: [WorkflowRunningStatus.Running, WorkflowRunningStatus.Paused].includes((taskStore === null || taskStore === void 0 ? void 0 : taskStore.task_status) || '') || readyOnly,
|
|
19
|
+
getNodesReadOnly: getNodesReadOnly
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
interface I18nVariables {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
interface IMultiLangMap {
|
|
5
|
+
[key: string]: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
type TLanguage = 'en' | 'zh' | 'ja' | string;
|
|
10
|
+
/**
|
|
11
|
+
* Internationalization (i18n) utility class
|
|
12
|
+
* Handles language management and string translations
|
|
13
|
+
*/
|
|
14
|
+
export default class I18N {
|
|
15
|
+
multiLangMap: IMultiLangMap;
|
|
16
|
+
language: TLanguage;
|
|
17
|
+
/**
|
|
18
|
+
* Initialize I18N instance with multi-language map
|
|
19
|
+
* @param config Configuration object containing multiLangMap
|
|
20
|
+
*/
|
|
21
|
+
constructor({ multiLangMap }: {
|
|
22
|
+
multiLangMap: IMultiLangMap;
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Convert value to string with fallback
|
|
26
|
+
* @param value Input value to convert
|
|
27
|
+
* @param defaultValue Fallback value if conversion fails
|
|
28
|
+
* @returns String representation of the value
|
|
29
|
+
*/
|
|
30
|
+
toString: (value: any, defaultValue: string) => any;
|
|
31
|
+
/**
|
|
32
|
+
* Set current application language
|
|
33
|
+
* @param language Language code to set ('en' or 'zh')
|
|
34
|
+
*/
|
|
35
|
+
setCurrentLanguage(language: TLanguage): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get current application language
|
|
38
|
+
* @returns Current language code
|
|
39
|
+
*/
|
|
40
|
+
getCurrentLanguage(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Format translation string with variables
|
|
43
|
+
* @param idObj Translation ID or object containing ID and default message
|
|
44
|
+
* @param variables Variables to interpolate into the translation
|
|
45
|
+
* @returns Formatted translation string
|
|
46
|
+
*/
|
|
47
|
+
format: (idObj: string | {
|
|
48
|
+
id: string;
|
|
49
|
+
dm: string;
|
|
50
|
+
}, variables: I18nVariables) => string;
|
|
51
|
+
/**
|
|
52
|
+
* Get translation for given ID
|
|
53
|
+
* @param id Translation ID or object containing ID and default message
|
|
54
|
+
* @param variables Optional variables to interpolate
|
|
55
|
+
* @returns Translated string
|
|
56
|
+
*/
|
|
57
|
+
get(id: string | {
|
|
58
|
+
id: string;
|
|
59
|
+
dm: string;
|
|
60
|
+
}, variable?: I18nVariables): string;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
import dayjs from 'dayjs';
|
|
9
|
+
|
|
10
|
+
// Interface for translation variables
|
|
11
|
+
|
|
12
|
+
// Interface for multi-language mapping
|
|
13
|
+
|
|
14
|
+
// Supported language types
|
|
15
|
+
/**
|
|
16
|
+
* Internationalization (i18n) utility class
|
|
17
|
+
* Handles language management and string translations
|
|
18
|
+
*/
|
|
19
|
+
var I18N = /*#__PURE__*/function () {
|
|
20
|
+
/**
|
|
21
|
+
* Initialize I18N instance with multi-language map
|
|
22
|
+
* @param config Configuration object containing multiLangMap
|
|
23
|
+
*/
|
|
24
|
+
function I18N(_ref) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
var _multiLangMap = _ref.multiLangMap;
|
|
27
|
+
_classCallCheck(this, I18N);
|
|
28
|
+
_defineProperty(this, "multiLangMap", void 0);
|
|
29
|
+
_defineProperty(this, "language", void 0);
|
|
30
|
+
/**
|
|
31
|
+
* Convert value to string with fallback
|
|
32
|
+
* @param value Input value to convert
|
|
33
|
+
* @param defaultValue Fallback value if conversion fails
|
|
34
|
+
* @returns String representation of the value
|
|
35
|
+
*/
|
|
36
|
+
_defineProperty(this, "toString", function (value, defaultValue) {
|
|
37
|
+
if (value === undefined || value === null) {
|
|
38
|
+
return defaultValue;
|
|
39
|
+
}
|
|
40
|
+
if (typeof value === 'string') {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
if (value !== null && value !== void 0 && value.toString && typeof value.toString === 'function') {
|
|
44
|
+
return value.toString();
|
|
45
|
+
}
|
|
46
|
+
return value || defaultValue;
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* Format translation string with variables
|
|
50
|
+
* @param idObj Translation ID or object containing ID and default message
|
|
51
|
+
* @param variables Variables to interpolate into the translation
|
|
52
|
+
* @returns Formatted translation string
|
|
53
|
+
*/
|
|
54
|
+
_defineProperty(this, "format", function (idObj, variables) {
|
|
55
|
+
var multiLangMap = _this.multiLangMap,
|
|
56
|
+
language = _this.language;
|
|
57
|
+
var langMap = multiLangMap[language] || {};
|
|
58
|
+
var template = '';
|
|
59
|
+
if (typeof idObj === 'string') {
|
|
60
|
+
template = langMap[idObj] || idObj;
|
|
61
|
+
} else {
|
|
62
|
+
var id = idObj.id,
|
|
63
|
+
dm = idObj.dm;
|
|
64
|
+
template = langMap[id] || dm || id;
|
|
65
|
+
}
|
|
66
|
+
return template.replace(/\{(\w+)\}/g, function (_match, key) {
|
|
67
|
+
return _this.toString(variables[key], _match);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
this.multiLangMap = _multiLangMap;
|
|
71
|
+
this.language = localStorage.getItem('spark-flow-data-prefers-language') || 'en';
|
|
72
|
+
dayjs.locale(this.language);
|
|
73
|
+
}
|
|
74
|
+
_createClass(I18N, [{
|
|
75
|
+
key: "setCurrentLanguage",
|
|
76
|
+
value:
|
|
77
|
+
/**
|
|
78
|
+
* Set current application language
|
|
79
|
+
* @param language Language code to set ('en' or 'zh')
|
|
80
|
+
*/
|
|
81
|
+
function setCurrentLanguage(language) {
|
|
82
|
+
localStorage.setItem('spark-flow-data-prefers-language', language);
|
|
83
|
+
this.language = language;
|
|
84
|
+
dayjs.locale(language);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get current application language
|
|
89
|
+
* @returns Current language code
|
|
90
|
+
*/
|
|
91
|
+
}, {
|
|
92
|
+
key: "getCurrentLanguage",
|
|
93
|
+
value: function getCurrentLanguage() {
|
|
94
|
+
return this.language;
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "get",
|
|
98
|
+
value:
|
|
99
|
+
/**
|
|
100
|
+
* Get translation for given ID
|
|
101
|
+
* @param id Translation ID or object containing ID and default message
|
|
102
|
+
* @param variables Optional variables to interpolate
|
|
103
|
+
* @returns Translated string
|
|
104
|
+
*/
|
|
105
|
+
function get(id, variable) {
|
|
106
|
+
return this.format(id, variable || {});
|
|
107
|
+
}
|
|
108
|
+
}]);
|
|
109
|
+
return I18N;
|
|
110
|
+
}();
|
|
111
|
+
export { I18N as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import I18N from "./i18n";
|
|
2
|
+
import enLangMap from "./locales/en-us.json";
|
|
3
|
+
import jaLangMap from "./locales/ja-jp.json";
|
|
4
|
+
import cnLangMap from "./locales/zh-cn.json";
|
|
5
|
+
var multiLangMap = {
|
|
6
|
+
zh: cnLangMap,
|
|
7
|
+
en: enLangMap,
|
|
8
|
+
ja: jaLangMap
|
|
9
|
+
};
|
|
10
|
+
export default new I18N({
|
|
11
|
+
multiLangMap: multiLangMap
|
|
12
|
+
});
|