@kne/form-creator 0.1.3 → 0.1.4

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.
@@ -5,7 +5,7 @@ import { Space, Tag, Button, Typography, Flex, Dropdown, Empty, message, Checkbo
5
5
  import { createWithIntlProvider, useIntl } from '@kne/react-intl';
6
6
  import { useIsMobile, RESPONSIVE_BOUNDARY_CLASS } from '@kne/responsive-utils';
7
7
  import { ArrowUpOutlined, ArrowDownOutlined, EditOutlined, DeleteOutlined, PlusOutlined, SettingOutlined, FormOutlined, UnorderedListOutlined, TableOutlined, AppstoreOutlined, OrderedListOutlined, ApartmentOutlined, QuestionCircleOutlined } from '@ant-design/icons';
8
- import { hooks, Input, TextArea, InputNumber, Select, RadioGroup, CheckboxGroup, Switch, Checkbox, DatePicker, useFormContext, Slider, SubmitButton, ResetButton, CancelButton } from '@kne/react-form-antd';
8
+ import { hooks, Input, TextArea, InputNumber, Select, RadioGroup, CheckboxGroup, Switch, Checkbox, DatePicker, useFormContext, Slider, SubmitButton, ResetButton, CancelButton, RULES, preset as preset$1 } from '@kne/react-form-antd';
9
9
  import SelectList, { SelectTableList, SelectTree, SelectCascader } from '@kne/super-select';
10
10
  import { SelectFunction, SelectIndustry, SelectAddress } from '@kne/super-select-plus';
11
11
  import '@kne/super-select/dist/index.css';
@@ -690,7 +690,7 @@ const formValuesToStep = (values, existingStep = {}) => {
690
690
  });
691
691
  };
692
692
 
693
- const _excluded$3 = ["children"];
693
+ const _excluded$4 = ["children"];
694
694
  const mapOptionItem = item => {
695
695
  if (!item || typeof item !== 'object') {
696
696
  return item;
@@ -698,7 +698,7 @@ const mapOptionItem = item => {
698
698
  const {
699
699
  children
700
700
  } = item,
701
- rest = _objectWithoutPropertiesLoose(item, _excluded$3);
701
+ rest = _objectWithoutPropertiesLoose(item, _excluded$4);
702
702
  const next = _extends({}, rest);
703
703
  if (Array.isArray(children) && children.length) {
704
704
  next.children = children.map(mapOptionItem);
@@ -711,7 +711,7 @@ const createApiFromOptions = (options = []) => ({
711
711
  })
712
712
  });
713
713
 
714
- const _excluded$2 = ["options", "api", "placeholder"];
714
+ const _excluded$3 = ["options", "api", "placeholder"];
715
715
  const {
716
716
  useOnChange: useOnChange$1
717
717
  } = hooks;
@@ -726,7 +726,7 @@ const createField = (Component, {
726
726
  api,
727
727
  placeholder
728
728
  } = props,
729
- rest = _objectWithoutPropertiesLoose(props, _excluded$2);
729
+ rest = _objectWithoutPropertiesLoose(props, _excluded$3);
730
730
  const useOptionsDirectly = _preferOptions || hasNestedOptions(options);
731
731
  const mergedApi = api || (!useOptionsDirectly && Array.isArray(options) && options.length ? createApiFromOptions(options) : undefined);
732
732
  const resolvedPlaceholder = placeholder != null && String(placeholder).trim() ? placeholder : `${_placeholderPrefix}${props.label || ''}`;
@@ -1596,7 +1596,7 @@ const FieldRow = ({
1596
1596
  };
1597
1597
  var FieldRow$1 = FieldRow;
1598
1598
 
1599
- const _excluded$1 = ["title", "danger"];
1599
+ const _excluded$2 = ["title", "danger"];
1600
1600
  const {
1601
1601
  Text: Text$3
1602
1602
  } = Typography;
@@ -1611,7 +1611,7 @@ const IconBtn = _ref => {
1611
1611
  title,
1612
1612
  danger
1613
1613
  } = _ref,
1614
- props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
1614
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
1615
1615
  return /*#__PURE__*/jsx(Button, _extends({
1616
1616
  type: "text",
1617
1617
  size: "small",
@@ -3212,7 +3212,7 @@ const hasFieldPropsEditor = (type, definition) => {
3212
3212
  };
3213
3213
  var FieldPropsEditor$1 = FieldPropsEditor;
3214
3214
 
3215
- const _excluded = ["columns"];
3215
+ const _excluded$1 = ["columns"];
3216
3216
  const {
3217
3217
  Text
3218
3218
  } = Typography;
@@ -3228,7 +3228,7 @@ const getDefaultSelectProps = () => ({
3228
3228
  columns: [createEmptyColumn()]
3229
3229
  });
3230
3230
  const omitColumns = (_ref = {}) => {
3231
- let rest = _objectWithoutPropertiesLoose(_ref, _excluded);
3231
+ let rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
3232
3232
  return rest;
3233
3233
  };
3234
3234
  const FieldConfigFields = ({
@@ -4240,5 +4240,53 @@ const FormCreator = withLocale$1(({
4240
4240
  });
4241
4241
  var FormCreator$1 = FormCreator;
4242
4242
 
4243
- export { FormCreator$1 as FormCreator, RULE_LEN_PRESET, RULE_PRESET_ITEMS, SchemaRenderer$1 as SchemaRenderer, SchemaRendererInner, applyFromPropsSchema, blockToFormValues, buildRuleString, collectSchemaFields, createBlock, createField$1 as createField, createFieldId, createStep, FormCreator$1 as default, defaultFormActions, defaultSchema, fieldToFormValues, findBlock, formValuesToBlock, formValuesToField, getBlockDefinition, getBlockKindOptions, getFieldComponent, getFieldDefinition, getFieldTypes, getRulePresetItems, hasRenderableContent, isFieldNameUnique, mapBlocks, moveItem, normalizeBlock, normalizeFormActions, normalizeOptions, normalizeSchema, parseRuleString, pickFieldProps, pickFromPropsSchema, registerField, registerRulePreset, updateBlocks };
4243
+ const _excluded = ["label", "validator"];
4244
+
4245
+ /**
4246
+ * 统一注册扩展规则与填写项:运行时校验 + 编辑器规则面板 + 字段类型 registry。
4247
+ * 应用入口调用一次即可,FormCreator / SchemaRenderer 共用。
4248
+ */
4249
+ const preset = ({
4250
+ rules: _rules = {},
4251
+ fields: _fields = {}
4252
+ } = {}) => {
4253
+ const runtimeRules = _extends({}, RULES);
4254
+ Object.entries(_rules).forEach(([value, def]) => {
4255
+ if (def == null) {
4256
+ return;
4257
+ }
4258
+ if (typeof def === 'function') {
4259
+ registerRulePreset({
4260
+ value,
4261
+ label: value
4262
+ });
4263
+ runtimeRules[value] = def;
4264
+ return;
4265
+ }
4266
+ const {
4267
+ label,
4268
+ validator
4269
+ } = def,
4270
+ ruleBody = _objectWithoutPropertiesLoose(def, _excluded);
4271
+ if (label) {
4272
+ registerRulePreset({
4273
+ value,
4274
+ label
4275
+ });
4276
+ }
4277
+ if (typeof validator === 'function') {
4278
+ runtimeRules[value] = validator;
4279
+ } else if (Object.keys(ruleBody).length) {
4280
+ runtimeRules[value] = ruleBody;
4281
+ }
4282
+ });
4283
+ preset$1({
4284
+ rules: runtimeRules
4285
+ });
4286
+ Object.entries(_fields).forEach(([type, definition]) => {
4287
+ registerField(type, definition);
4288
+ });
4289
+ };
4290
+
4291
+ export { FormCreator$1 as FormCreator, RULE_LEN_PRESET, RULE_PRESET_ITEMS, SchemaRenderer$1 as SchemaRenderer, SchemaRendererInner, applyFromPropsSchema, blockToFormValues, buildRuleString, collectSchemaFields, createBlock, createField$1 as createField, createFieldId, createStep, FormCreator$1 as default, defaultFormActions, defaultSchema, fieldToFormValues, findBlock, formValuesToBlock, formValuesToField, getBlockDefinition, getBlockKindOptions, getFieldComponent, getFieldDefinition, getFieldTypes, getRulePresetItems, hasRenderableContent, isFieldNameUnique, mapBlocks, moveItem, normalizeBlock, normalizeFormActions, normalizeOptions, normalizeSchema, parseRuleString, pickFieldProps, pickFromPropsSchema, preset, registerField, registerRulePreset, updateBlocks };
4244
4292
  //# sourceMappingURL=index.modern.js.map