@pisell/materials 1.0.84 → 1.0.86
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/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/index.js +1 -1
- package/build/lowcode/meta.js +2 -2
- package/build/lowcode/preview.js +8 -8
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +12 -12
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +11 -11
- package/es/components/table/Table/fields/text/Show/index.js +4 -1
- package/es/components/translation/index.d.ts +13 -0
- package/es/components/translation/index.js +154 -0
- package/es/components/translation/index.less +15 -0
- package/es/components/translation/utils.d.ts +7 -0
- package/es/components/translation/utils.js +32 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/lib/components/table/Table/fields/text/Show/index.js +4 -1
- package/lib/components/translation/index.d.ts +13 -0
- package/lib/components/translation/index.js +173 -0
- package/lib/components/translation/index.less +15 -0
- package/lib/components/translation/utils.d.ts +7 -0
- package/lib/components/translation/utils.js +55 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/lowcode/radio/snippets.ts +1 -0
- package/lowcode/radio.group/meta.ts +6 -1
- package/lowcode/translation/__screenshots__/input-1.png +0 -0
- package/lowcode/translation/meta.ts +186 -0
- package/lowcode/translation/snippets.ts +12 -0
- package/package.json +1 -1
- package/dist/umd/materials.min.css +0 -1
- package/dist/umd/materials.min.js +0 -1
- package/dist/umd/static/DotsSix.57d66266.svg +0 -1
- package/dist/umd/static/arrow-left.e542294f.svg +0 -1
- package/dist/umd/static/arrow-right.763f03e0.svg +0 -1
- package/dist/umd/static/filter-lines.04a54ae9.svg +0 -1
- package/dist/umd/static/help-circle.31c9be40.svg +0 -1
- package/dist/umd/static/switch-vertical-01.7ebe3ba8.svg +0 -1
|
@@ -20,7 +20,10 @@ var Show = function Show(props) {
|
|
|
20
20
|
var _modal$state, _modal$state$utils;
|
|
21
21
|
if (action && modal !== null && modal !== void 0 && (_modal$state = modal.state) !== null && _modal$state !== void 0 && (_modal$state$utils = _modal$state.utils) !== null && _modal$state$utils !== void 0 && _modal$state$utils.action) {
|
|
22
22
|
var _modal$state2, _modal$state2$utils;
|
|
23
|
-
modal === null || modal === void 0 ? void 0 : (_modal$state2 = modal.state) === null || _modal$state2 === void 0 ? void 0 : (_modal$state2$utils = _modal$state2.utils) === null || _modal$state2$utils === void 0 ? void 0 : _modal$state2$utils.action(
|
|
23
|
+
modal === null || modal === void 0 ? void 0 : (_modal$state2 = modal.state) === null || _modal$state2 === void 0 ? void 0 : (_modal$state2$utils = _modal$state2.utils) === null || _modal$state2$utils === void 0 ? void 0 : _modal$state2$utils.action({
|
|
24
|
+
type: action,
|
|
25
|
+
data: record
|
|
26
|
+
});
|
|
24
27
|
}
|
|
25
28
|
};
|
|
26
29
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import './index.less';
|
|
3
|
+
declare type Value = {
|
|
4
|
+
en: string;
|
|
5
|
+
"zh-CN": string;
|
|
6
|
+
"zh-HK": string;
|
|
7
|
+
};
|
|
8
|
+
interface TranslationProps {
|
|
9
|
+
value: Value;
|
|
10
|
+
onChange: (value: Value) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const Translation: React.FC<TranslationProps>;
|
|
13
|
+
export default Translation;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _excluded = ["value", "onChange"];
|
|
3
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
+
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; }
|
|
7
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
8
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
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); }
|
|
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
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
16
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
17
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
18
|
+
import { Input, Modal, Form } from "antd";
|
|
19
|
+
import { isString } from "@pisell/utils";
|
|
20
|
+
import { GlobalOutlined } from "@ant-design/icons";
|
|
21
|
+
import classNames from "classnames";
|
|
22
|
+
import useEngineContext from "../../hooks/useEngineContext";
|
|
23
|
+
import { checkIfAllValuesAreEqual, createTranslationText, locales } from "./utils";
|
|
24
|
+
import "./index.less";
|
|
25
|
+
var defaultGlobal = {
|
|
26
|
+
shopLanguages: {
|
|
27
|
+
primary: "en",
|
|
28
|
+
list: [{
|
|
29
|
+
id: 1,
|
|
30
|
+
code: "zh-CN",
|
|
31
|
+
text: "简体中文",
|
|
32
|
+
primary: 1,
|
|
33
|
+
status: "published"
|
|
34
|
+
}, {
|
|
35
|
+
id: 2,
|
|
36
|
+
code: "en",
|
|
37
|
+
text: "English",
|
|
38
|
+
primary: 0,
|
|
39
|
+
status: "published"
|
|
40
|
+
}, {
|
|
41
|
+
id: 3,
|
|
42
|
+
code: "zh-HK",
|
|
43
|
+
text: "繁體中文",
|
|
44
|
+
primary: 0,
|
|
45
|
+
status: "published"
|
|
46
|
+
}]
|
|
47
|
+
},
|
|
48
|
+
primary_locale: "en"
|
|
49
|
+
};
|
|
50
|
+
var defaultObj = {};
|
|
51
|
+
var Translation = function Translation(props) {
|
|
52
|
+
var _context$appHelper, _store$getState;
|
|
53
|
+
var _props$value = props.value,
|
|
54
|
+
value = _props$value === void 0 ? defaultObj : _props$value,
|
|
55
|
+
onChange = props.onChange,
|
|
56
|
+
others = _objectWithoutProperties(props, _excluded);
|
|
57
|
+
var context = useEngineContext();
|
|
58
|
+
var _useState = useState(false),
|
|
59
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
60
|
+
open = _useState2[0],
|
|
61
|
+
setOpen = _useState2[1];
|
|
62
|
+
var _useState3 = useState(value),
|
|
63
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
64
|
+
_value = _useState4[0],
|
|
65
|
+
set_value = _useState4[1];
|
|
66
|
+
var store = context === null || context === void 0 ? void 0 : (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.store;
|
|
67
|
+
var _ref = (store === null || store === void 0 ? void 0 : (_store$getState = store.getState()) === null || _store$getState === void 0 ? void 0 : _store$getState.global) || defaultGlobal,
|
|
68
|
+
shopLanguages = _ref.shopLanguages;
|
|
69
|
+
useEffect(function () {
|
|
70
|
+
var _newValue = _objectSpread({}, value);
|
|
71
|
+
if (isString(value)) {
|
|
72
|
+
_newValue = createTranslationText(value);
|
|
73
|
+
}
|
|
74
|
+
set_value(_objectSpread(_objectSpread({}, defaultValue), _newValue));
|
|
75
|
+
}, [value]);
|
|
76
|
+
var currentLocale = useMemo(function () {
|
|
77
|
+
return shopLanguages.primary;
|
|
78
|
+
}, [shopLanguages.primary]);
|
|
79
|
+
var inputValue = useMemo(function () {
|
|
80
|
+
if (isString(value)) {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
return value[currentLocale];
|
|
84
|
+
}, [value, currentLocale]);
|
|
85
|
+
var languageList = useMemo(function () {
|
|
86
|
+
return shopLanguages.list;
|
|
87
|
+
}, [shopLanguages.list]);
|
|
88
|
+
var defaultValue = useMemo(function () {
|
|
89
|
+
var obj = {};
|
|
90
|
+
for (var item in locales) {
|
|
91
|
+
obj[item] = "";
|
|
92
|
+
}
|
|
93
|
+
return obj;
|
|
94
|
+
}, []);
|
|
95
|
+
var allChange = function allChange(e) {
|
|
96
|
+
var newValue = _objectSpread(_objectSpread({}, defaultValue), value || {});
|
|
97
|
+
if (checkIfAllValuesAreEqual(newValue)) {
|
|
98
|
+
for (var key in newValue) {
|
|
99
|
+
newValue[key] = e || "";
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
newValue[currentLocale] = e || "";
|
|
103
|
+
}
|
|
104
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
105
|
+
};
|
|
106
|
+
var isActive = useMemo(function () {
|
|
107
|
+
var bol = false;
|
|
108
|
+
for (var key in value) {
|
|
109
|
+
if (key !== currentLocale && value[key]) {
|
|
110
|
+
bol = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return bol;
|
|
114
|
+
}, [value, currentLocale]);
|
|
115
|
+
var _onOk = function _onOk() {
|
|
116
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(_value);
|
|
117
|
+
setOpen(false);
|
|
118
|
+
};
|
|
119
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Input, _extends({}, others, {
|
|
120
|
+
value: inputValue,
|
|
121
|
+
onChange: allChange,
|
|
122
|
+
suffix: /*#__PURE__*/React.createElement(GlobalOutlined, {
|
|
123
|
+
className: classNames("pisell-lowcode-translation-icon", {
|
|
124
|
+
active: isActive
|
|
125
|
+
}),
|
|
126
|
+
onClick: function onClick() {
|
|
127
|
+
return setOpen(true);
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
})), /*#__PURE__*/React.createElement(Modal, {
|
|
131
|
+
open: open,
|
|
132
|
+
onOk: _onOk,
|
|
133
|
+
onCancel: function onCancel() {
|
|
134
|
+
set_value(value || defaultValue);
|
|
135
|
+
setOpen(false);
|
|
136
|
+
}
|
|
137
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
138
|
+
className: "pisell-lowcode-translation-modal"
|
|
139
|
+
}, languageList.map(function (d) {
|
|
140
|
+
return /*#__PURE__*/React.createElement(Form.Item, {
|
|
141
|
+
label: d.text,
|
|
142
|
+
labelCol: {
|
|
143
|
+
span: 24
|
|
144
|
+
},
|
|
145
|
+
key: d.code
|
|
146
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
147
|
+
value: _value[d.code],
|
|
148
|
+
onChange: function onChange(e) {
|
|
149
|
+
set_value(_objectSpread(_objectSpread({}, _value), {}, _defineProperty({}, d.code, e.target.value)));
|
|
150
|
+
}
|
|
151
|
+
}));
|
|
152
|
+
}))));
|
|
153
|
+
};
|
|
154
|
+
export default Translation;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.pisell-lowcode-translation-icon {
|
|
2
|
+
cursor: pointer;
|
|
3
|
+
color: #d9d9d9;
|
|
4
|
+
:hover {
|
|
5
|
+
color: var(--theme-color);
|
|
6
|
+
}
|
|
7
|
+
&.active {
|
|
8
|
+
color: var(--theme-color);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.pisell-lowcode-translation-modal {
|
|
13
|
+
position: relative;
|
|
14
|
+
width: 100%;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
export var locales = {
|
|
8
|
+
en: "",
|
|
9
|
+
"zh-CN": "",
|
|
10
|
+
"zh-HK": ""
|
|
11
|
+
};
|
|
12
|
+
export var checkIfAllValuesAreEqual = function checkIfAllValuesAreEqual(obj) {
|
|
13
|
+
var valuesArray = Object.values(obj);
|
|
14
|
+
return valuesArray.every(function (value) {
|
|
15
|
+
return value === valuesArray[0];
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export var createTranslationText = function createTranslationText(text) {
|
|
19
|
+
var isAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
20
|
+
var primary = localStorage.getItem("shop_primary_locale") || "en";
|
|
21
|
+
var _locales = _objectSpread({}, locales);
|
|
22
|
+
if (text !== "" && text !== undefined) {
|
|
23
|
+
if (isAll) {
|
|
24
|
+
for (var key in _locales) {
|
|
25
|
+
_locales[key] = text;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
_locales[primary] = text;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return _locales;
|
|
32
|
+
};
|
package/es/index.d.ts
CHANGED
|
@@ -62,3 +62,4 @@ export { default as AutoComplete } from "./components/auto-complete";
|
|
|
62
62
|
export { default as Div } from "./components/div";
|
|
63
63
|
export { default as Page } from "./components/page";
|
|
64
64
|
export { default as Filter } from './components/filter';
|
|
65
|
+
export { default as Translation } from './components/translation';
|
package/es/index.js
CHANGED
|
@@ -89,4 +89,5 @@ export { default as Cascader } from "./components/cascader";
|
|
|
89
89
|
export { default as AutoComplete } from "./components/auto-complete";
|
|
90
90
|
export { default as Div } from "./components/div";
|
|
91
91
|
export { default as Page } from "./components/page";
|
|
92
|
-
export { default as Filter } from "./components/filter";
|
|
92
|
+
export { default as Filter } from "./components/filter";
|
|
93
|
+
export { default as Translation } from "./components/translation";
|
|
@@ -52,7 +52,10 @@ var Show = (props) => {
|
|
|
52
52
|
const onClick = () => {
|
|
53
53
|
var _a, _b, _c, _d;
|
|
54
54
|
if (action && ((_b = (_a = modal == null ? void 0 : modal.state) == null ? void 0 : _a.utils) == null ? void 0 : _b.action)) {
|
|
55
|
-
(_d = (_c = modal == null ? void 0 : modal.state) == null ? void 0 : _c.utils) == null ? void 0 : _d.action(
|
|
55
|
+
(_d = (_c = modal == null ? void 0 : modal.state) == null ? void 0 : _c.utils) == null ? void 0 : _d.action({
|
|
56
|
+
type: action,
|
|
57
|
+
data: record
|
|
58
|
+
});
|
|
56
59
|
}
|
|
57
60
|
};
|
|
58
61
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import './index.less';
|
|
3
|
+
declare type Value = {
|
|
4
|
+
en: string;
|
|
5
|
+
"zh-CN": string;
|
|
6
|
+
"zh-HK": string;
|
|
7
|
+
};
|
|
8
|
+
interface TranslationProps {
|
|
9
|
+
value: Value;
|
|
10
|
+
onChange: (value: Value) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const Translation: React.FC<TranslationProps>;
|
|
13
|
+
export default Translation;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/components/translation/index.tsx
|
|
30
|
+
var translation_exports = {};
|
|
31
|
+
__export(translation_exports, {
|
|
32
|
+
default: () => translation_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(translation_exports);
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import_antd = require("antd");
|
|
37
|
+
var import_utils = require("@pisell/utils");
|
|
38
|
+
var import_icons = require("@ant-design/icons");
|
|
39
|
+
var import_classnames = __toESM(require("classnames"));
|
|
40
|
+
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
|
|
41
|
+
var import_utils2 = require("./utils");
|
|
42
|
+
var import_index = require("./index.less");
|
|
43
|
+
var defaultGlobal = {
|
|
44
|
+
shopLanguages: {
|
|
45
|
+
primary: "en",
|
|
46
|
+
list: [
|
|
47
|
+
{
|
|
48
|
+
id: 1,
|
|
49
|
+
code: "zh-CN",
|
|
50
|
+
text: "简体中文",
|
|
51
|
+
primary: 1,
|
|
52
|
+
status: "published"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 2,
|
|
56
|
+
code: "en",
|
|
57
|
+
text: "English",
|
|
58
|
+
primary: 0,
|
|
59
|
+
status: "published"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 3,
|
|
63
|
+
code: "zh-HK",
|
|
64
|
+
text: "繁體中文",
|
|
65
|
+
primary: 0,
|
|
66
|
+
status: "published"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
primary_locale: "en"
|
|
71
|
+
};
|
|
72
|
+
var defaultObj = {};
|
|
73
|
+
var Translation = (props) => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
const { value = defaultObj, onChange, ...others } = props;
|
|
76
|
+
const context = (0, import_useEngineContext.default)();
|
|
77
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
78
|
+
const [_value, set_value] = (0, import_react.useState)(value);
|
|
79
|
+
const store = (_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.store;
|
|
80
|
+
const { shopLanguages } = ((_b = store == null ? void 0 : store.getState()) == null ? void 0 : _b.global) || defaultGlobal;
|
|
81
|
+
(0, import_react.useEffect)(() => {
|
|
82
|
+
let _newValue = { ...value };
|
|
83
|
+
if ((0, import_utils.isString)(value)) {
|
|
84
|
+
_newValue = (0, import_utils2.createTranslationText)(value);
|
|
85
|
+
}
|
|
86
|
+
set_value({ ...defaultValue, ..._newValue });
|
|
87
|
+
}, [value]);
|
|
88
|
+
const currentLocale = (0, import_react.useMemo)(() => {
|
|
89
|
+
return shopLanguages.primary;
|
|
90
|
+
}, [shopLanguages.primary]);
|
|
91
|
+
const inputValue = (0, import_react.useMemo)(() => {
|
|
92
|
+
if ((0, import_utils.isString)(value)) {
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
return value[currentLocale];
|
|
96
|
+
}, [value, currentLocale]);
|
|
97
|
+
const languageList = (0, import_react.useMemo)(() => {
|
|
98
|
+
return shopLanguages.list;
|
|
99
|
+
}, [shopLanguages.list]);
|
|
100
|
+
const defaultValue = (0, import_react.useMemo)(() => {
|
|
101
|
+
let obj = {};
|
|
102
|
+
for (let item in import_utils2.locales) {
|
|
103
|
+
obj[item] = "";
|
|
104
|
+
}
|
|
105
|
+
return obj;
|
|
106
|
+
}, []);
|
|
107
|
+
const allChange = (e) => {
|
|
108
|
+
let newValue = {
|
|
109
|
+
...defaultValue,
|
|
110
|
+
...value || {}
|
|
111
|
+
};
|
|
112
|
+
if ((0, import_utils2.checkIfAllValuesAreEqual)(newValue)) {
|
|
113
|
+
for (let key in newValue) {
|
|
114
|
+
newValue[key] = e || "";
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
newValue[currentLocale] = e || "";
|
|
118
|
+
}
|
|
119
|
+
onChange == null ? void 0 : onChange(newValue);
|
|
120
|
+
};
|
|
121
|
+
const isActive = (0, import_react.useMemo)(() => {
|
|
122
|
+
let bol = false;
|
|
123
|
+
for (let key in value) {
|
|
124
|
+
if (key !== currentLocale && value[key]) {
|
|
125
|
+
bol = true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return bol;
|
|
129
|
+
}, [value, currentLocale]);
|
|
130
|
+
const _onOk = () => {
|
|
131
|
+
onChange == null ? void 0 : onChange(_value);
|
|
132
|
+
setOpen(false);
|
|
133
|
+
};
|
|
134
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
|
|
135
|
+
import_antd.Input,
|
|
136
|
+
{
|
|
137
|
+
...others,
|
|
138
|
+
value: inputValue,
|
|
139
|
+
onChange: allChange,
|
|
140
|
+
suffix: /* @__PURE__ */ import_react.default.createElement(
|
|
141
|
+
import_icons.GlobalOutlined,
|
|
142
|
+
{
|
|
143
|
+
className: (0, import_classnames.default)("pisell-lowcode-translation-icon", {
|
|
144
|
+
active: isActive
|
|
145
|
+
}),
|
|
146
|
+
onClick: () => setOpen(true)
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
151
|
+
import_antd.Modal,
|
|
152
|
+
{
|
|
153
|
+
open,
|
|
154
|
+
onOk: _onOk,
|
|
155
|
+
onCancel: () => {
|
|
156
|
+
set_value(value || defaultValue);
|
|
157
|
+
setOpen(false);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-translation-modal" }, languageList.map((d) => {
|
|
161
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { label: d.text, labelCol: { span: 24 }, key: d.code }, /* @__PURE__ */ import_react.default.createElement(
|
|
162
|
+
import_antd.Input,
|
|
163
|
+
{
|
|
164
|
+
value: _value[d.code],
|
|
165
|
+
onChange: (e) => {
|
|
166
|
+
set_value({ ..._value, [d.code]: e.target.value });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
));
|
|
170
|
+
}))
|
|
171
|
+
));
|
|
172
|
+
};
|
|
173
|
+
var translation_default = Translation;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.pisell-lowcode-translation-icon {
|
|
2
|
+
cursor: pointer;
|
|
3
|
+
color: #d9d9d9;
|
|
4
|
+
:hover {
|
|
5
|
+
color: var(--theme-color);
|
|
6
|
+
}
|
|
7
|
+
&.active {
|
|
8
|
+
color: var(--theme-color);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.pisell-lowcode-translation-modal {
|
|
13
|
+
position: relative;
|
|
14
|
+
width: 100%;
|
|
15
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/components/translation/utils.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
checkIfAllValuesAreEqual: () => checkIfAllValuesAreEqual,
|
|
23
|
+
createTranslationText: () => createTranslationText,
|
|
24
|
+
locales: () => locales
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(utils_exports);
|
|
27
|
+
var locales = {
|
|
28
|
+
en: "",
|
|
29
|
+
"zh-CN": "",
|
|
30
|
+
"zh-HK": ""
|
|
31
|
+
};
|
|
32
|
+
var checkIfAllValuesAreEqual = (obj) => {
|
|
33
|
+
const valuesArray = Object.values(obj);
|
|
34
|
+
return valuesArray.every((value) => value === valuesArray[0]);
|
|
35
|
+
};
|
|
36
|
+
var createTranslationText = (text, isAll = true) => {
|
|
37
|
+
let primary = localStorage.getItem("shop_primary_locale") || "en";
|
|
38
|
+
let _locales = { ...locales };
|
|
39
|
+
if (text !== "" && text !== void 0) {
|
|
40
|
+
if (isAll) {
|
|
41
|
+
for (let key in _locales) {
|
|
42
|
+
_locales[key] = text;
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
_locales[primary] = text;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return _locales;
|
|
49
|
+
};
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
checkIfAllValuesAreEqual,
|
|
53
|
+
createTranslationText,
|
|
54
|
+
locales
|
|
55
|
+
});
|
package/lib/index.d.ts
CHANGED
|
@@ -62,3 +62,4 @@ export { default as AutoComplete } from "./components/auto-complete";
|
|
|
62
62
|
export { default as Div } from "./components/div";
|
|
63
63
|
export { default as Page } from "./components/page";
|
|
64
64
|
export { default as Filter } from './components/filter';
|
|
65
|
+
export { default as Translation } from './components/translation';
|
package/lib/index.js
CHANGED
|
@@ -86,6 +86,7 @@ __export(src_exports, {
|
|
|
86
86
|
Timeline: () => import_antd36.Timeline,
|
|
87
87
|
Tooltip: () => import_antd37.Tooltip,
|
|
88
88
|
Transfer: () => import_antd33.Transfer,
|
|
89
|
+
Translation: () => import_translation.default,
|
|
89
90
|
Tree: () => import_antd34.Tree,
|
|
90
91
|
TreeSelect: () => import_tree_select.default,
|
|
91
92
|
Typography: () => import_antd38.Typography,
|
|
@@ -159,6 +160,7 @@ var import_auto_complete = __toESM(require("./components/auto-complete"));
|
|
|
159
160
|
var import_div = __toESM(require("./components/div"));
|
|
160
161
|
var import_page = __toESM(require("./components/page"));
|
|
161
162
|
var import_filter = __toESM(require("./components/filter"));
|
|
163
|
+
var import_translation = __toESM(require("./components/translation"));
|
|
162
164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
163
165
|
0 && (module.exports = {
|
|
164
166
|
Affix,
|
|
@@ -218,6 +220,7 @@ var import_filter = __toESM(require("./components/filter"));
|
|
|
218
220
|
Timeline,
|
|
219
221
|
Tooltip,
|
|
220
222
|
Transfer,
|
|
223
|
+
Translation,
|
|
221
224
|
Tree,
|
|
222
225
|
TreeSelect,
|
|
223
226
|
Typography,
|
|
@@ -88,7 +88,7 @@ export default {
|
|
|
88
88
|
{
|
|
89
89
|
name: 'label',
|
|
90
90
|
title: '选项名',
|
|
91
|
-
setter: '
|
|
91
|
+
setter: 'PisellI18nSetter',
|
|
92
92
|
isRequired: true
|
|
93
93
|
},
|
|
94
94
|
{
|
|
@@ -116,6 +116,11 @@ export default {
|
|
|
116
116
|
},
|
|
117
117
|
},
|
|
118
118
|
},
|
|
119
|
+
{
|
|
120
|
+
name: 'direction',
|
|
121
|
+
title: { label: '排布方向', tip: '排布方向' },
|
|
122
|
+
propType: { type: 'oneOf', value: ['vertical', 'horizontal'] },
|
|
123
|
+
},
|
|
119
124
|
{
|
|
120
125
|
name: 'optionType',
|
|
121
126
|
title: { label: '类型', tip: '类型' },
|
|
Binary file
|