@nokecy/qc-ui 0.1.26 → 0.1.28
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/dist/cjs/array-table/index.d.ts +1 -6
- package/dist/cjs/array-table/index.js +30 -127
- package/dist/cjs/array-table/interface.d.ts +16 -0
- package/dist/cjs/array-table/interface.js +5 -0
- package/dist/cjs/array-table/utils.d.ts +10 -0
- package/dist/cjs/array-table/utils.js +146 -0
- package/dist/cjs/editable/index.d.ts +8 -0
- package/dist/cjs/editable/index.js +313 -0
- package/dist/cjs/editable/style.d.ts +2 -0
- package/dist/cjs/editable/style.js +55 -0
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +8 -0
- package/dist/esm/array-table/index.d.ts +1 -6
- package/dist/esm/array-table/index.js +23 -121
- package/dist/esm/array-table/interface.d.ts +16 -0
- package/dist/esm/array-table/interface.js +1 -0
- package/dist/esm/array-table/utils.d.ts +10 -0
- package/dist/esm/array-table/utils.js +126 -0
- package/dist/esm/editable/index.d.ts +8 -0
- package/dist/esm/editable/index.js +290 -0
- package/dist/esm/editable/style.d.ts +2 -0
- package/dist/esm/editable/style.js +45 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { useField, useFieldSchema, RecursionField } from '@formily/react';
|
|
9
|
+
import { isArr } from '@formily/shared';
|
|
10
|
+
import { ArrayBase } from '@formily/antd-v5';
|
|
11
|
+
|
|
12
|
+
var isColumnComponent = function isColumnComponent(schema) {
|
|
13
|
+
var _schema$xComponent;
|
|
14
|
+
|
|
15
|
+
return ((_schema$xComponent = schema['x-component']) === null || _schema$xComponent === void 0 ? void 0 : _schema$xComponent.indexOf('Column')) > -1;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
var isOperationsComponent = function isOperationsComponent(schema) {
|
|
19
|
+
var _schema$xComponent2;
|
|
20
|
+
|
|
21
|
+
return ((_schema$xComponent2 = schema['x-component']) === null || _schema$xComponent2 === void 0 ? void 0 : _schema$xComponent2.indexOf('Operations')) > -1;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var isAdditionComponent = function isAdditionComponent(schema) {
|
|
25
|
+
var _schema$xComponent3;
|
|
26
|
+
|
|
27
|
+
return ((_schema$xComponent3 = schema['x-component']) === null || _schema$xComponent3 === void 0 ? void 0 : _schema$xComponent3.indexOf('Addition')) > -1;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var useArrayTableSources = function useArrayTableSources() {
|
|
31
|
+
var arrayField = useField();
|
|
32
|
+
var schema = useFieldSchema();
|
|
33
|
+
|
|
34
|
+
var parseSources = function parseSources(schema) {
|
|
35
|
+
if (isColumnComponent(schema) || isOperationsComponent(schema) || isAdditionComponent(schema)) {
|
|
36
|
+
var _schema$xComponentP, _schema$xComponentP2, _field$component;
|
|
37
|
+
|
|
38
|
+
if (!((_schema$xComponentP = schema['x-component-props']) !== null && _schema$xComponentP !== void 0 && _schema$xComponentP['dataIndex']) && !schema['name']) return [];
|
|
39
|
+
var name = ((_schema$xComponentP2 = schema['x-component-props']) === null || _schema$xComponentP2 === void 0 ? void 0 : _schema$xComponentP2['dataIndex']) || schema['name'];
|
|
40
|
+
var field = arrayField.query(arrayField.address.concat(name)).take();
|
|
41
|
+
var columnProps = (field === null || field === void 0 ? void 0 : (_field$component = field.component) === null || _field$component === void 0 ? void 0 : _field$component[1]) || schema['x-component-props'] || {};
|
|
42
|
+
var display = (field === null || field === void 0 ? void 0 : field.display) || schema['x-display'];
|
|
43
|
+
return [{
|
|
44
|
+
name: name,
|
|
45
|
+
display: display,
|
|
46
|
+
field: field,
|
|
47
|
+
schema: schema,
|
|
48
|
+
columnProps: columnProps
|
|
49
|
+
}];
|
|
50
|
+
} else if (schema.properties) {
|
|
51
|
+
return schema.reduceProperties(function (buf, schema) {
|
|
52
|
+
return buf.concat(parseSources(schema));
|
|
53
|
+
}, []);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return [];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var parseArrayItems = function parseArrayItems(schema) {
|
|
60
|
+
if (!schema) return [];
|
|
61
|
+
var sources = [];
|
|
62
|
+
var items = isArr(schema) ? schema : [schema];
|
|
63
|
+
return items.reduce(function (columns, schema) {
|
|
64
|
+
var item = parseSources(schema);
|
|
65
|
+
|
|
66
|
+
if (item) {
|
|
67
|
+
return columns.concat(item);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return columns;
|
|
71
|
+
}, sources);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (!schema) throw new Error('can not found schema object');
|
|
75
|
+
return parseArrayItems(schema.items);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var useArrayTableColumns = function useArrayTableColumns(field, sources) {
|
|
79
|
+
return sources.reduce(function (buf, _ref, key) {
|
|
80
|
+
var name = _ref.name,
|
|
81
|
+
columnProps = _ref.columnProps,
|
|
82
|
+
schema = _ref.schema,
|
|
83
|
+
display = _ref.display;
|
|
84
|
+
if (display !== 'visible') return buf;
|
|
85
|
+
if (!isColumnComponent(schema)) return buf;
|
|
86
|
+
return buf.concat(_objectSpread(_objectSpread({}, columnProps), {}, {
|
|
87
|
+
field: name,
|
|
88
|
+
cellRenderer: function cellRenderer(_ref2) {
|
|
89
|
+
var _field$value;
|
|
90
|
+
|
|
91
|
+
var value = _ref2.value,
|
|
92
|
+
record = _ref2.data;
|
|
93
|
+
var index = field === null || field === void 0 ? void 0 : (_field$value = field.value) === null || _field$value === void 0 ? void 0 : _field$value.indexOf(record);
|
|
94
|
+
var children = /*#__PURE__*/React.createElement(ArrayBase.Item, {
|
|
95
|
+
index: index,
|
|
96
|
+
record: function record() {
|
|
97
|
+
var _field$value2;
|
|
98
|
+
|
|
99
|
+
return field === null || field === void 0 ? void 0 : (_field$value2 = field.value) === null || _field$value2 === void 0 ? void 0 : _field$value2[index];
|
|
100
|
+
}
|
|
101
|
+
}, /*#__PURE__*/React.createElement(RecursionField, {
|
|
102
|
+
schema: schema,
|
|
103
|
+
name: index,
|
|
104
|
+
onlyRenderProperties: true
|
|
105
|
+
}));
|
|
106
|
+
return children;
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
}, []);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
var useAddition = function useAddition() {
|
|
113
|
+
var schema = useFieldSchema();
|
|
114
|
+
return schema.reduceProperties(function (addition, schema, key) {
|
|
115
|
+
if (isAdditionComponent(schema)) {
|
|
116
|
+
return /*#__PURE__*/React.createElement(RecursionField, {
|
|
117
|
+
schema: schema,
|
|
118
|
+
name: key
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return addition;
|
|
123
|
+
}, null);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export { isColumnComponent, useArrayTableSources, useArrayTableColumns, useAddition };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactFC } from '@formily/react';
|
|
2
|
+
import { PopoverProps } from 'antd/lib/popover';
|
|
3
|
+
import { IFormItemProps } from '@formily/antd-v5';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
export declare const Editable: ReactFC<IFormItemProps> & {
|
|
6
|
+
Popover: React.MemoExoticComponent<ReactFC<PopoverProps>>;
|
|
7
|
+
};
|
|
8
|
+
export default Editable;
|
|
@@ -0,0 +1,290 @@
|
|
|
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
|
+
|
|
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
|
+
|
|
5
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
6
|
+
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
+
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
+
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
|
|
13
|
+
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."); }
|
|
14
|
+
|
|
15
|
+
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); }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
18
|
+
|
|
19
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
+
|
|
21
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
+
|
|
23
|
+
import { CloseOutlined, EditOutlined, MessageOutlined } from '@ant-design/icons';
|
|
24
|
+
import { isVoidField } from '@formily/core';
|
|
25
|
+
import { observer, useField } from '@formily/react';
|
|
26
|
+
import { Popover as AntdPopover } from 'antd';
|
|
27
|
+
import cls from 'classnames';
|
|
28
|
+
import { FormItem } from '@formily/antd-v5';
|
|
29
|
+
import React, { useLayoutEffect, useRef, useState } from 'react';
|
|
30
|
+
import { useClickAway, usePrefixCls } from '@formily/antd-v5/lib/__builtins__';
|
|
31
|
+
import useStyle from "./style";
|
|
32
|
+
|
|
33
|
+
var useParentPattern = function useParentPattern() {
|
|
34
|
+
var _field$parent, _field$form;
|
|
35
|
+
|
|
36
|
+
var field = useField();
|
|
37
|
+
return (field === null || field === void 0 ? void 0 : (_field$parent = field.parent) === null || _field$parent === void 0 ? void 0 : _field$parent.pattern) || (field === null || field === void 0 ? void 0 : (_field$form = field.form) === null || _field$form === void 0 ? void 0 : _field$form.pattern);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var useEditable = function useEditable() {
|
|
41
|
+
var pattern = useParentPattern();
|
|
42
|
+
var field = useField();
|
|
43
|
+
useLayoutEffect(function () {
|
|
44
|
+
if (pattern === 'editable') {
|
|
45
|
+
return field.setPattern('readPretty');
|
|
46
|
+
}
|
|
47
|
+
}, [pattern]);
|
|
48
|
+
return [field.pattern === 'editable', function (payload) {
|
|
49
|
+
if (pattern !== 'editable') return;
|
|
50
|
+
field.setPattern(payload ? 'editable' : 'readPretty');
|
|
51
|
+
}];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var useFormItemProps = function useFormItemProps() {
|
|
55
|
+
var field = useField();
|
|
56
|
+
if (isVoidField(field)) return {};
|
|
57
|
+
if (!field) return {};
|
|
58
|
+
|
|
59
|
+
var takeMessage = function takeMessage() {
|
|
60
|
+
if (field.selfErrors.length) return field.selfErrors;
|
|
61
|
+
if (field.selfWarnings.length) return field.selfWarnings;
|
|
62
|
+
if (field.selfSuccesses.length) return field.selfSuccesses;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
feedbackStatus: field.validateStatus === 'validating' ? 'pending' : field.validateStatus,
|
|
67
|
+
feedbackText: takeMessage(),
|
|
68
|
+
extra: field.description
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
var InternalEditable = observer(function (props) {
|
|
73
|
+
var _useEditable = useEditable(),
|
|
74
|
+
_useEditable2 = _slicedToArray(_useEditable, 2),
|
|
75
|
+
editable = _useEditable2[0],
|
|
76
|
+
setEditable = _useEditable2[1];
|
|
77
|
+
|
|
78
|
+
var pattern = useParentPattern();
|
|
79
|
+
var itemProps = useFormItemProps();
|
|
80
|
+
var field = useField();
|
|
81
|
+
var basePrefixCls = usePrefixCls();
|
|
82
|
+
var prefixCls = usePrefixCls('formily-editable');
|
|
83
|
+
|
|
84
|
+
var _useStyle = useStyle(prefixCls),
|
|
85
|
+
_useStyle2 = _slicedToArray(_useStyle, 2),
|
|
86
|
+
wrapSSR = _useStyle2[0],
|
|
87
|
+
hashId = _useStyle2[1];
|
|
88
|
+
|
|
89
|
+
var ref = useRef();
|
|
90
|
+
var innerRef = useRef(null);
|
|
91
|
+
|
|
92
|
+
var recover = /*#__PURE__*/function () {
|
|
93
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
94
|
+
var _field$errors;
|
|
95
|
+
|
|
96
|
+
var errors;
|
|
97
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
98
|
+
while (1) {
|
|
99
|
+
switch (_context.prev = _context.next) {
|
|
100
|
+
case 0:
|
|
101
|
+
if (!(editable && !(field !== null && field !== void 0 && (_field$errors = field.errors) !== null && _field$errors !== void 0 && _field$errors.length))) {
|
|
102
|
+
_context.next = 11;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_context.prev = 1;
|
|
107
|
+
_context.next = 4;
|
|
108
|
+
return field.form.validate("".concat(field.path));
|
|
109
|
+
|
|
110
|
+
case 4:
|
|
111
|
+
_context.prev = 4;
|
|
112
|
+
errors = field.form.queryFeedbacks({
|
|
113
|
+
type: 'error',
|
|
114
|
+
address: "".concat(field.address)
|
|
115
|
+
});
|
|
116
|
+
console.log(field.address, errors);
|
|
117
|
+
|
|
118
|
+
if (!(errors !== null && errors !== void 0 && errors.length)) {
|
|
119
|
+
_context.next = 9;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return _context.abrupt("return");
|
|
124
|
+
|
|
125
|
+
case 9:
|
|
126
|
+
if (ref.current && !(errors !== null && errors !== void 0 && errors.length)) {
|
|
127
|
+
console.log("false");
|
|
128
|
+
setEditable(false);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return _context.finish(4);
|
|
132
|
+
|
|
133
|
+
case 11:
|
|
134
|
+
case "end":
|
|
135
|
+
return _context.stop();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, _callee, null, [[1,, 4, 11]]);
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
return function recover() {
|
|
142
|
+
return _ref.apply(this, arguments);
|
|
143
|
+
};
|
|
144
|
+
}();
|
|
145
|
+
|
|
146
|
+
var renderEditHelper = function renderEditHelper() {
|
|
147
|
+
if (editable) return;
|
|
148
|
+
return /*#__PURE__*/React.createElement(FormItem.BaseItem, _extends({}, props, itemProps), pattern === 'editable' && /*#__PURE__*/React.createElement(EditOutlined, {
|
|
149
|
+
className: "".concat(prefixCls, "-edit-btn")
|
|
150
|
+
}), pattern !== 'editable' && /*#__PURE__*/React.createElement(MessageOutlined, {
|
|
151
|
+
className: "".concat(prefixCls, "-edit-btn")
|
|
152
|
+
}));
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
var renderCloseHelper = function renderCloseHelper() {
|
|
156
|
+
if (!editable) return;
|
|
157
|
+
return /*#__PURE__*/React.createElement(FormItem.BaseItem, props, /*#__PURE__*/React.createElement(CloseOutlined, {
|
|
158
|
+
className: "".concat(prefixCls, "-close-btn")
|
|
159
|
+
}));
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
useClickAway(function (e) {
|
|
163
|
+
var target = e.target;
|
|
164
|
+
if (target !== null && target !== void 0 && target.closest(".".concat(basePrefixCls, "-select-dropdown"))) return;
|
|
165
|
+
if (target !== null && target !== void 0 && target.closest(".".concat(basePrefixCls, "-picker-dropdown"))) return;
|
|
166
|
+
if (target !== null && target !== void 0 && target.closest(".".concat(basePrefixCls, "-cascader-menus"))) return;
|
|
167
|
+
recover();
|
|
168
|
+
}, innerRef);
|
|
169
|
+
|
|
170
|
+
var onClick = function onClick(e) {
|
|
171
|
+
var _innerRef$current;
|
|
172
|
+
|
|
173
|
+
var target = e.target;
|
|
174
|
+
var close = ((_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 ? void 0 : _innerRef$current.querySelector(".".concat(prefixCls, "-close-btn"))) || null;
|
|
175
|
+
|
|
176
|
+
if (target !== null && target !== void 0 && target.contains(close) || close !== null && close !== void 0 && close.contains(target)) {
|
|
177
|
+
recover();
|
|
178
|
+
} else if (!ref.current) {
|
|
179
|
+
setTimeout(function () {
|
|
180
|
+
setEditable(true);
|
|
181
|
+
setTimeout(function () {
|
|
182
|
+
var _innerRef$current2, _innerRef$current2$qu;
|
|
183
|
+
|
|
184
|
+
(_innerRef$current2 = innerRef.current) === null || _innerRef$current2 === void 0 ? void 0 : (_innerRef$current2$qu = _innerRef$current2.querySelector('input')) === null || _innerRef$current2$qu === void 0 ? void 0 : _innerRef$current2$qu.focus();
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
ref.current = editable;
|
|
191
|
+
return wrapSSR( /*#__PURE__*/React.createElement("div", {
|
|
192
|
+
className: cls(prefixCls, hashId),
|
|
193
|
+
ref: innerRef,
|
|
194
|
+
onClick: onClick
|
|
195
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
196
|
+
className: "".concat(prefixCls, "-content")
|
|
197
|
+
}, /*#__PURE__*/React.createElement(FormItem.BaseItem, _extends({}, props, itemProps), props.children), renderEditHelper(), renderCloseHelper())));
|
|
198
|
+
});
|
|
199
|
+
var Popover = observer(function (props) {
|
|
200
|
+
var field = useField();
|
|
201
|
+
var pattern = useParentPattern();
|
|
202
|
+
|
|
203
|
+
var _useState = useState(false),
|
|
204
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
205
|
+
open = _useState2[0],
|
|
206
|
+
setOpen = _useState2[1];
|
|
207
|
+
|
|
208
|
+
var prefixCls = usePrefixCls('formily-editable');
|
|
209
|
+
|
|
210
|
+
var _useStyle3 = useStyle(prefixCls),
|
|
211
|
+
_useStyle4 = _slicedToArray(_useStyle3, 2),
|
|
212
|
+
wrapSSR = _useStyle4[0],
|
|
213
|
+
hashId = _useStyle4[1];
|
|
214
|
+
|
|
215
|
+
var closePopover = /*#__PURE__*/function () {
|
|
216
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
217
|
+
var errors;
|
|
218
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
219
|
+
while (1) {
|
|
220
|
+
switch (_context2.prev = _context2.next) {
|
|
221
|
+
case 0:
|
|
222
|
+
_context2.prev = 0;
|
|
223
|
+
_context2.next = 3;
|
|
224
|
+
return field.form.validate("".concat(field.address, ".*"));
|
|
225
|
+
|
|
226
|
+
case 3:
|
|
227
|
+
_context2.prev = 3;
|
|
228
|
+
errors = field.form.queryFeedbacks({
|
|
229
|
+
type: 'error',
|
|
230
|
+
address: "".concat(field.address, ".*")
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
if (!(errors !== null && errors !== void 0 && errors.length)) {
|
|
234
|
+
_context2.next = 7;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return _context2.abrupt("return");
|
|
239
|
+
|
|
240
|
+
case 7:
|
|
241
|
+
setOpen(false);
|
|
242
|
+
return _context2.finish(3);
|
|
243
|
+
|
|
244
|
+
case 9:
|
|
245
|
+
case "end":
|
|
246
|
+
return _context2.stop();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}, _callee2, null, [[0,, 3, 9]]);
|
|
250
|
+
}));
|
|
251
|
+
|
|
252
|
+
return function closePopover() {
|
|
253
|
+
return _ref2.apply(this, arguments);
|
|
254
|
+
};
|
|
255
|
+
}();
|
|
256
|
+
|
|
257
|
+
var openPopover = function openPopover() {
|
|
258
|
+
setOpen(true);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return wrapSSR( /*#__PURE__*/React.createElement(AntdPopover, _extends({}, props, {
|
|
262
|
+
title: props.title || field.title,
|
|
263
|
+
open: open,
|
|
264
|
+
className: cls(prefixCls, hashId, props.className),
|
|
265
|
+
content: props.children,
|
|
266
|
+
trigger: "click",
|
|
267
|
+
destroyTooltipOnHide: true,
|
|
268
|
+
onOpenChange: function onOpenChange(open) {
|
|
269
|
+
if (open) {
|
|
270
|
+
openPopover();
|
|
271
|
+
} else {
|
|
272
|
+
closePopover();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FormItem.BaseItem, {
|
|
276
|
+
className: "".concat(prefixCls, "-trigger")
|
|
277
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
278
|
+
className: "".concat(prefixCls, "-content")
|
|
279
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
280
|
+
className: "".concat(prefixCls, "-preview")
|
|
281
|
+
}, props.title || field.title), pattern === 'editable' && /*#__PURE__*/React.createElement(EditOutlined, {
|
|
282
|
+
className: "".concat(prefixCls, "-edit-btn")
|
|
283
|
+
}), pattern !== 'editable' && /*#__PURE__*/React.createElement(MessageOutlined, {
|
|
284
|
+
className: "".concat(prefixCls, "-edit-btn")
|
|
285
|
+
}))))));
|
|
286
|
+
});
|
|
287
|
+
export var Editable = Object.assign(InternalEditable, {
|
|
288
|
+
Popover: Popover
|
|
289
|
+
});
|
|
290
|
+
export default Editable;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
import { genStyleHook } from '@formily/antd-v5/lib/__builtins__';
|
|
4
|
+
export default genStyleHook('editable', function (token) {
|
|
5
|
+
var _$concat, _componentCls;
|
|
6
|
+
|
|
7
|
+
var antCls = token.antCls,
|
|
8
|
+
componentCls = token.componentCls,
|
|
9
|
+
fontSizeSM = token.fontSizeSM,
|
|
10
|
+
colorPrimary = token.colorPrimary;
|
|
11
|
+
return _defineProperty({}, componentCls, (_componentCls = {
|
|
12
|
+
cursor: 'pointer',
|
|
13
|
+
display: 'inline-block !important'
|
|
14
|
+
}, _defineProperty(_componentCls, "".concat(antCls, "-form-text"), (_$concat = {
|
|
15
|
+
display: 'flex',
|
|
16
|
+
alignItems: 'center'
|
|
17
|
+
}, _defineProperty(_$concat, "".concat(antCls, "-tag"), {
|
|
18
|
+
transition: 'none !important'
|
|
19
|
+
}), _defineProperty(_$concat, "".concat(antCls, "-tag:last-child"), {
|
|
20
|
+
paddingInlineEnd: '0 !important'
|
|
21
|
+
}), _$concat)), _defineProperty(_componentCls, "".concat(componentCls, "-content"), {
|
|
22
|
+
display: 'flex',
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
'> *': {
|
|
25
|
+
marginInlineEnd: 3,
|
|
26
|
+
'&:last-child': {
|
|
27
|
+
marginInlineEnd: 0
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}), _defineProperty(_componentCls, "".concat(componentCls, "-edit-btn,\n ").concat(componentCls, "-close-btn"), {
|
|
31
|
+
transition: 'all .25s ease-in-out',
|
|
32
|
+
color: '#aaa',
|
|
33
|
+
fontSize: fontSizeSM,
|
|
34
|
+
'&:hover': {
|
|
35
|
+
color: colorPrimary
|
|
36
|
+
}
|
|
37
|
+
}), _defineProperty(_componentCls, "".concat(componentCls, "-preview"), {
|
|
38
|
+
whiteSpace: 'nowrap',
|
|
39
|
+
textOverflow: 'ellipsis',
|
|
40
|
+
overflow: 'hidden',
|
|
41
|
+
wordBreak: 'break-all',
|
|
42
|
+
maxWidth: '100%',
|
|
43
|
+
display: 'block'
|
|
44
|
+
}), _componentCls));
|
|
45
|
+
});
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import ArrayTable from "./array-table";
|
|
|
2
2
|
import ArrayTableIndex from "./array-table-index";
|
|
3
3
|
import { AgGridColumn, AgGridPlus, flattenTreeDeep } from "./ag-grid-plus";
|
|
4
4
|
import ExtensibleGrid from "./extensible-grid";
|
|
5
|
+
import Editable from "./editable";
|
|
5
6
|
import Dashboard from "./dashboard";
|
|
6
7
|
import Elsa from "./elsa";
|
|
7
|
-
export { ArrayTable, ArrayTableIndex, AgGridColumn, AgGridPlus, ExtensibleGrid, Dashboard, Elsa };
|
|
8
|
+
export { Editable, ArrayTable, ArrayTableIndex, AgGridColumn, AgGridPlus, ExtensibleGrid, Dashboard, Elsa };
|
|
8
9
|
export { flattenTreeDeep };
|
package/dist/esm/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import ArrayTable from "./array-table";
|
|
|
2
2
|
import ArrayTableIndex from "./array-table-index";
|
|
3
3
|
import { AgGridColumn, AgGridPlus, flattenTreeDeep } from "./ag-grid-plus";
|
|
4
4
|
import ExtensibleGrid from "./extensible-grid";
|
|
5
|
+
import Editable from "./editable";
|
|
5
6
|
import Dashboard from "./dashboard";
|
|
6
7
|
import Elsa from "./elsa";
|
|
7
|
-
export { ArrayTable, ArrayTableIndex, AgGridColumn, AgGridPlus, ExtensibleGrid, Dashboard, Elsa };
|
|
8
|
+
export { Editable, ArrayTable, ArrayTableIndex, AgGridColumn, AgGridPlus, ExtensibleGrid, Dashboard, Elsa };
|
|
8
9
|
export { flattenTreeDeep };
|