UNPKG

ze-react-component-library

Version:
128 lines (118 loc) 4.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.types = void 0; var _react = _interopRequireWildcard(require("react")); var _util = require("../util"); function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var ZEJsonEditor = /*#__PURE__*/(0, _react.lazy)(function () { return Promise.resolve().then(function () { return _interopRequireWildcard(require("../ZEJsonEditor")); }); }); var types = ["entity", "event"]; exports.types = types; var getSchema = function getSchema(json, isCreate) { var scheme = { type: "object", properties: { schema: { type: "string", // 更新时,设定enum,不允许修改 enum: isCreate ? undefined : [json === null || json === void 0 ? void 0 : json.schema], description: "数仓的表名" }, name: { type: "string", description: "指标名称" }, syno: { type: "array", items: { type: "string" }, description: "指标的同义词" }, type: { type: "string", enum: _util.typePropertyOfSchema.constraints.enum, description: "指标类型" }, is_additive: { type: "boolean", description: "是否可加" }, run: { type: "string", description: "js的run函数" }, shouldSplitGroupby: { type: "string", description: "js的shouldSplitGroupby函数" }, sql: { type: "string", description: "sql" }, sqlLeftJoinClause: { type: "string", description: "sqlLeftJoinClause" }, target: { type: "number", description: "目标" }, unit: { type: "string", description: "单位;例如: (元)。此字段会显示在问答的结果旁边。" }, ui: { type: "object", properties: { formatter: { type: "string", description: "数字格式;例如: 0,0.0A。格式配置详情请见使用文档" }, representation: { type: "string", enum: ["column", "bar", "line", "area", "pie"], description: "图表格式" } } }, description: { type: "string", description: "说明" } }, required: ["schema", "name", "type"] }; return scheme; }; var JsonEditor = function JsonEditor(_a) { var value = _a.value, editorRef = _a.editorRef, editable = _a.editable, isCreate = _a.isCreate; (0, _react.useEffect)(function () { if (editorRef.current) { editorRef.current.set(value || {}); } }, [JSON.stringify(value)]); return /*#__PURE__*/_react.default.createElement(_react.Suspense, { fallback: /*#__PURE__*/_react.default.createElement("strong", null, "\u52A0\u8F7D\u4E2D...") }, /*#__PURE__*/_react.default.createElement(ZEJsonEditor, { value: value || {}, editorRef: editorRef, editable: editable, mode: editable ? "code" : "view", modes: editable ? ["tree", "code"] : undefined, schema: getSchema(value, isCreate), templates: [] })); }; var _default = JsonEditor; exports.default = _default;