@sheinx/base 3.5.4-beta.1 → 3.5.4-beta.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"form-button.d.ts","sourceRoot":"","sources":["form-button.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,QAAA,MAAM,UAAU,UAAW,WAAW,gBAarC,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"form-button.d.ts","sourceRoot":"","sources":["form-button.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,QAAA,MAAM,UAAU,UAAW,WAAW,gBAmBrC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -25,6 +25,11 @@ var FormButton = function FormButton(props) {
25
25
  if (formFunc && props.htmlType === 'button') {
26
26
  formFunc.submit();
27
27
  }
28
+ if (formFunc && props.htmlType === 'reset') {
29
+ // 阻止默认的form reset,改用formFunc.reset。处理嵌套form的reset问题。
30
+ e.preventDefault();
31
+ formFunc.reset();
32
+ }
28
33
  if (props.onClick) {
29
34
  props.onClick(e);
30
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["form.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,QAAA,MAAM,IAAI,4DA4FT,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["form.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,QAAA,MAAM,IAAI,4DA8GT,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/cjs/form/form.js CHANGED
@@ -104,10 +104,25 @@ var Form = function Form(props) {
104
104
  handleFormModalInfo();
105
105
  }, [props.disabled, props.pending]);
106
106
  var rootClass = (0, _classnames.default)([formClasses === null || formClasses === void 0 ? void 0 : formClasses.rootClass, formClasses === null || formClasses === void 0 ? void 0 : formClasses.wrapper, className, props.inline && (formClasses === null || formClasses === void 0 ? void 0 : formClasses.wrapperInline)]);
107
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", _objectSpread(_objectSpread({}, getFormProps({
107
+ var formProps = getFormProps({
108
108
  className: rootClass,
109
109
  style: style
110
+ });
111
+ var formElRef = (0, _react.useRef)(null);
112
+ (0, _react.useEffect)(function () {
113
+ if (formElRef.current instanceof HTMLFormElement) {
114
+ formElRef.current.addEventListener('submit', formProps.onSubmit);
115
+ }
116
+ return function () {
117
+ if (formElRef.current instanceof HTMLFormElement) {
118
+ formElRef.current.removeEventListener('submit', formProps.onSubmit);
119
+ }
120
+ };
121
+ }, [formProps.onSubmit]);
122
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", _objectSpread(_objectSpread({}, _hooks.util.removeProps(formProps, {
123
+ onSubmit: true
110
124
  })), {}, {
125
+ ref: formElRef,
111
126
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, _objectSpread(_objectSpread({}, ProviderProps), {}, {
112
127
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_hooks.FormContext.Provider, {
113
128
  value: formRefObj,
@@ -245,7 +245,7 @@ var Sticky = function Sticky(props) {
245
245
  cancelFixedObserver();
246
246
  context.fixedObserver = new IntersectionObserver(handleFixedInter, {
247
247
  root: null,
248
- rootMargin: "-".concat(top || 0, "px 0px -").concat(bottom || 0, "px 0px"),
248
+ rootMargin: "".concat(-(top || 0), "px 0px ").concat(-(bottom || 0), "px 0px"),
249
249
  threshold: 1.0
250
250
  });
251
251
  };
@@ -281,7 +281,7 @@ var Sticky = function Sticky(props) {
281
281
  if (window.IntersectionObserver) {
282
282
  var observer = new IntersectionObserver(handleTargetPosition, {
283
283
  root: context.target,
284
- rootMargin: "-".concat(top || 0, "px 0px -").concat(bottom || 0, "px 0px"),
284
+ rootMargin: "".concat(-(top || 0), "px 0px ").concat(-(bottom || 0), "px 0px"),
285
285
  threshold: 1.0
286
286
  });
287
287
  context.targetObserver = observer;
@@ -299,7 +299,7 @@ var Sticky = function Sticky(props) {
299
299
  cancelParentObserver();
300
300
  context.parentObserver = new IntersectionObserver(handleParentVisible, {
301
301
  root: context.target,
302
- rootMargin: "-".concat(top || 0, "px 0px -").concat(bottom || 0, "px 0px"),
302
+ rootMargin: "".concat(-(top || 0), "px 0px ").concat(-(bottom || 0), "px 0px"),
303
303
  threshold: 0
304
304
  });
305
305
  context.parentObserver.observe(props.parent);
@@ -1 +1 @@
1
- {"version":3,"file":"form-button.d.ts","sourceRoot":"","sources":["form-button.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,QAAA,MAAM,UAAU,UAAW,WAAW,gBAarC,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"form-button.d.ts","sourceRoot":"","sources":["form-button.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,QAAA,MAAM,UAAU,UAAW,WAAW,gBAmBrC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -18,6 +18,11 @@ var FormButton = function FormButton(props) {
18
18
  if (formFunc && props.htmlType === 'button') {
19
19
  formFunc.submit();
20
20
  }
21
+ if (formFunc && props.htmlType === 'reset') {
22
+ // 阻止默认的form reset,改用formFunc.reset。处理嵌套form的reset问题。
23
+ e.preventDefault();
24
+ formFunc.reset();
25
+ }
21
26
  if (props.onClick) {
22
27
  props.onClick(e);
23
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["form.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,QAAA,MAAM,IAAI,4DA4FT,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["form.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,QAAA,MAAM,IAAI,4DA8GT,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/esm/form/form.js CHANGED
@@ -7,10 +7,10 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
7
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
8
  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; }
9
9
  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; }
10
- import { FormContext, useForm, useInputAble, useLatestObj, usePersistFn } from '@sheinx/hooks';
10
+ import { FormContext, useForm, useInputAble, useLatestObj, usePersistFn, util } from '@sheinx/hooks';
11
11
  import classNames from 'classnames';
12
12
  import { useFormFooter } from "./form-footer-context";
13
- import React, { useEffect } from 'react';
13
+ import React, { useEffect, useRef } from 'react';
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  var Form = function Form(props) {
16
16
  var _jssStyle$form;
@@ -95,10 +95,25 @@ var Form = function Form(props) {
95
95
  handleFormModalInfo();
96
96
  }, [props.disabled, props.pending]);
97
97
  var rootClass = classNames([formClasses === null || formClasses === void 0 ? void 0 : formClasses.rootClass, formClasses === null || formClasses === void 0 ? void 0 : formClasses.wrapper, className, props.inline && (formClasses === null || formClasses === void 0 ? void 0 : formClasses.wrapperInline)]);
98
- return /*#__PURE__*/_jsx("form", _objectSpread(_objectSpread({}, getFormProps({
98
+ var formProps = getFormProps({
99
99
  className: rootClass,
100
100
  style: style
101
+ });
102
+ var formElRef = useRef(null);
103
+ useEffect(function () {
104
+ if (formElRef.current instanceof HTMLFormElement) {
105
+ formElRef.current.addEventListener('submit', formProps.onSubmit);
106
+ }
107
+ return function () {
108
+ if (formElRef.current instanceof HTMLFormElement) {
109
+ formElRef.current.removeEventListener('submit', formProps.onSubmit);
110
+ }
111
+ };
112
+ }, [formProps.onSubmit]);
113
+ return /*#__PURE__*/_jsx("form", _objectSpread(_objectSpread({}, util.removeProps(formProps, {
114
+ onSubmit: true
101
115
  })), {}, {
116
+ ref: formElRef,
102
117
  children: /*#__PURE__*/_jsx(Provider, _objectSpread(_objectSpread({}, ProviderProps), {}, {
103
118
  children: /*#__PURE__*/_jsx(FormContext.Provider, {
104
119
  value: formRefObj,
@@ -239,7 +239,7 @@ var Sticky = function Sticky(props) {
239
239
  cancelFixedObserver();
240
240
  context.fixedObserver = new IntersectionObserver(handleFixedInter, {
241
241
  root: null,
242
- rootMargin: "-".concat(top || 0, "px 0px -").concat(bottom || 0, "px 0px"),
242
+ rootMargin: "".concat(-(top || 0), "px 0px ").concat(-(bottom || 0), "px 0px"),
243
243
  threshold: 1.0
244
244
  });
245
245
  };
@@ -275,7 +275,7 @@ var Sticky = function Sticky(props) {
275
275
  if (window.IntersectionObserver) {
276
276
  var observer = new IntersectionObserver(handleTargetPosition, {
277
277
  root: context.target,
278
- rootMargin: "-".concat(top || 0, "px 0px -").concat(bottom || 0, "px 0px"),
278
+ rootMargin: "".concat(-(top || 0), "px 0px ").concat(-(bottom || 0), "px 0px"),
279
279
  threshold: 1.0
280
280
  });
281
281
  context.targetObserver = observer;
@@ -293,7 +293,7 @@ var Sticky = function Sticky(props) {
293
293
  cancelParentObserver();
294
294
  context.parentObserver = new IntersectionObserver(handleParentVisible, {
295
295
  root: context.target,
296
- rootMargin: "-".concat(top || 0, "px 0px -").concat(bottom || 0, "px 0px"),
296
+ rootMargin: "".concat(-(top || 0), "px 0px ").concat(-(bottom || 0), "px 0px"),
297
297
  threshold: 0
298
298
  });
299
299
  context.parentObserver.observe(props.parent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/base",
3
- "version": "3.5.4-beta.1",
3
+ "version": "3.5.4-beta.3",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "module": "./esm/index.js",
11
11
  "typings": "./cjs/index.d.ts",
12
12
  "dependencies": {
13
- "@sheinx/hooks": "3.5.4-beta.1",
13
+ "@sheinx/hooks": "3.5.4-beta.3",
14
14
  "immer": "^10.0.0",
15
15
  "classnames": "^2.0.0",
16
16
  "@shined/reactive": "^0.1.3-alpha.0"