form-driver 0.4.25 → 0.4.27

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/lib/m3.js CHANGED
@@ -24,7 +24,6 @@ var clsx = require('clsx');
24
24
  var Button = require('antd/lib/button');
25
25
  var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
26
26
  var zhCN$1 = require('antd/lib/date-picker/locale/zh_CN');
27
- var ReactDOM = require('react-dom');
28
27
  var debounce = require('lodash/debounce');
29
28
  require('moment/locale/zh-cn');
30
29
  var _extends = require('@babel/runtime/helpers/extends');
@@ -46,7 +45,6 @@ var clsx__default = /*#__PURE__*/_interopDefaultLegacy(clsx);
46
45
  var Button__default = /*#__PURE__*/_interopDefaultLegacy(Button);
47
46
  var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
48
47
  var zhCN__default$1 = /*#__PURE__*/_interopDefaultLegacy(zhCN$1);
49
- var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
50
48
  var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
51
49
  var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
52
50
  var OSS__default = /*#__PURE__*/_interopDefaultLegacy(OSS);
@@ -22970,7 +22968,7 @@ var ARangePicker = /*#__PURE__*/function (_Viewer) {
22970
22968
  ctrlVersion: 1,
22971
22969
  noValidate: false,
22972
22970
  mobileDlg: false,
22973
- mobileStep: 'start'
22971
+ mobileStep: "start"
22974
22972
  };
22975
22973
  return _this;
22976
22974
  }
@@ -22990,12 +22988,14 @@ var ARangePicker = /*#__PURE__*/function (_Viewer) {
22990
22988
 
22991
22989
  if (___default["default"].get(v, "[2]")) {
22992
22990
  // tillnow
22993
- var dom = ReactDOM__default["default"].findDOMNode(this._pickerRef.current);
22991
+ var dom = this._pickerRef.current;
22994
22992
 
22995
22993
  if (dom) {
22996
- // @ts-ignore
22997
22994
  var r = dom.querySelector(":nth-child(3)");
22998
- r.innerHTML = "<input readonly disabled size='12' autocomplete='off' value='至今' style='color: black'>";
22995
+
22996
+ if (r) {
22997
+ r.innerHTML = "<input readonly disabled size='12' autocomplete='off' value='至今' style='color: black'>";
22998
+ }
22999
22999
  }
23000
23000
  }
23001
23001
  }
@@ -23040,23 +23040,23 @@ var ARangePicker = /*#__PURE__*/function (_Viewer) {
23040
23040
  var rangePickerData = this._data2rangePicker((_this$getValue = this.getValue()) != null ? _this$getValue : []);
23041
23041
 
23042
23042
  if (MUtil.phoneLike()) {
23043
- var _this$props$schema$da3, _this$props$schema$da4;
23043
+ var _this$props$schema$da3;
23044
23044
 
23045
23045
  var show = MDateRangeType.toReadableN(assembly, this.props.schema, _Viewer.prototype.getValue.call(this)); // 根据 precision 配置确定移动端 DatePicker 精度(使用扁平化属性 dateRangePrecision)
23046
23046
 
23047
- var mobilePrecision = this.props.schema.dateRangePrecision || 'day';
23047
+ var mobilePrecision = this.props.schema.dateRangePrecision || "day";
23048
23048
  return jsxRuntime.jsxs(jsxRuntime.Fragment, {
23049
23049
  children: [jsxRuntime.jsxs("div", {
23050
23050
  className: "backfill",
23051
23051
  onClick: function onClick() {
23052
23052
  return _this2.setState({
23053
23053
  mobileDlg: true,
23054
- mobileStep: 'start'
23054
+ mobileStep: "start"
23055
23055
  });
23056
23056
  },
23057
- children: [" ", show != null ? show : '请点击选择', " "]
23057
+ children: [" ", show != null ? show : "请点击选择", " "]
23058
23058
  }), jsxRuntime.jsx(antdMobile.DatePicker, {
23059
- visible: this.state.mobileDlg && this.state.mobileStep === 'start',
23059
+ visible: this.state.mobileDlg && this.state.mobileStep === "start",
23060
23060
  precision: mobilePrecision,
23061
23061
  title: "\u9009\u62E9\u5F00\u59CB\u65E5\u671F",
23062
23062
  min: this.props.schema.min ? new Date(this.props.schema.min) : undefined,
@@ -23066,7 +23066,7 @@ var ARangePicker = /*#__PURE__*/function (_Viewer) {
23066
23066
 
23067
23067
  _this2.setState({
23068
23068
  mobileStartDate: val,
23069
- mobileStep: 'end'
23069
+ mobileStep: "end"
23070
23070
  });
23071
23071
  },
23072
23072
  onClose: function onClose() {
@@ -23082,14 +23082,14 @@ var ARangePicker = /*#__PURE__*/function (_Viewer) {
23082
23082
  });
23083
23083
  }
23084
23084
  }, "start_" + mobilePrecision), jsxRuntime.jsx(antdMobile.DatePicker, {
23085
- visible: this.state.mobileDlg && this.state.mobileStep === 'end',
23085
+ visible: this.state.mobileDlg && this.state.mobileStep === "end",
23086
23086
  precision: mobilePrecision,
23087
23087
  title: // 如果允许"至今"且开始时间不在未来,在标题区域展示"至今"按钮
23088
- !((_this$props$schema$da3 = this.props.schema.dateRange) != null && _this$props$schema$da3.hideTillNow) && !((_this$props$schema$da4 = this.props.schema.dateRange) != null && _this$props$schema$da4.showTime) && !(this.state.mobileStartDate && this.state.mobileStartDate > new Date()) ? jsxRuntime.jsxs("div", {
23088
+ !((_this$props$schema$da3 = this.props.schema.dateRange) != null && _this$props$schema$da3.hideTillNow) && !(this.state.mobileStartDate && this.state.mobileStartDate > new Date()) ? jsxRuntime.jsxs("div", {
23089
23089
  style: {
23090
- display: 'flex',
23091
- alignItems: 'center',
23092
- justifyContent: 'center',
23090
+ display: "flex",
23091
+ alignItems: "center",
23092
+ justifyContent: "center",
23093
23093
  gap: 12
23094
23094
  },
23095
23095
  children: [jsxRuntime.jsx("span", {
@@ -23130,93 +23130,176 @@ var ARangePicker = /*#__PURE__*/function (_Viewer) {
23130
23130
  onClose: function onClose() {
23131
23131
  // 回退到第一步,让用户可以重新选择开始日期
23132
23132
  _this2.setState({
23133
- mobileStep: 'start'
23133
+ mobileStep: "start"
23134
23134
  });
23135
23135
  }
23136
23136
  }, "end_" + mobilePrecision)]
23137
23137
  });
23138
23138
  } else {
23139
- var _this$props$schema$da5, _this$props$schema$da6, _this$props$schema$da7;
23139
+ var _this$props$schema$da4, _this$props$schema$da5, _this$props$schema$da6;
23140
23140
 
23141
23141
  // 根据 precision 配置确定 PC 端 picker 模式和 showTime(使用扁平化属性 dateRangePrecision)
23142
23142
  var precision = this.props.schema.dateRangePrecision;
23143
- var pcShowTime = precision === 'minute' || ((_this$props$schema$da5 = this.props.schema.dateRange) == null ? void 0 : _this$props$schema$da5.showTime);
23144
- var hideFooter = ((_this$props$schema$da6 = this.props.schema.dateRange) == null ? void 0 : _this$props$schema$da6.hideTillNow) || pcShowTime; // 动态构建额外属性,避免 showTime 和 picker 同时传入导致类型冲突
23143
+ var pcShowTime = precision === "minute" || ((_this$props$schema$da4 = this.props.schema.dateRange) == null ? void 0 : _this$props$schema$da4.showTime);
23144
+ var hideFooter = (_this$props$schema$da5 = this.props.schema.dateRange) == null ? void 0 : _this$props$schema$da5.hideTillNow; // 动态构建额外属性,避免 showTime 和 picker 同时传入导致类型冲突
23145
23145
 
23146
23146
  var extraProps = {};
23147
23147
 
23148
- if (precision === 'year') {
23149
- extraProps.picker = 'year';
23150
- } else if (precision === 'month') {
23151
- extraProps.picker = 'month';
23148
+ if (precision === "year") {
23149
+ extraProps.picker = "year";
23150
+ } else if (precision === "month") {
23151
+ extraProps.picker = "month";
23152
23152
  } else if (pcShowTime) {
23153
23153
  // precision 为 minute 时只展示时分,不展示秒
23154
- extraProps.showTime = precision === 'minute' ? {
23155
- format: 'HH:mm'
23154
+ extraProps.showTime = precision === "minute" ? {
23155
+ format: "HH:mm"
23156
23156
  } : true; // 同步设置输入框的显示格式,避免 showTime.format 只影响面板列而输入框仍显示秒
23157
23157
 
23158
- if (precision === 'minute') {
23159
- extraProps.format = 'YYYY-MM-DD HH:mm';
23158
+ if (precision === "minute") {
23159
+ extraProps.format = "YYYY-MM-DD HH:mm";
23160
+ }
23161
+ } // "至今"按钮的点击处理函数
23162
+
23163
+
23164
+ var handleTillNow = function handleTillNow() {
23165
+ var _this2$_onCalendarCha, _ref, _ref2;
23166
+
23167
+ // 优先级:onCalendarChange 记录的值 > 面板点击捕获的日期 > 已有默认值 > 当前时间
23168
+ var fromCalendarChange = (_this2$_onCalendarCha = _this2._onCalendarChangeValue) == null ? void 0 : _this2$_onCalendarCha[0];
23169
+ var fromPanelClick = _this2._panelClickedDate;
23170
+ var startMoment = (_ref = (_ref2 = fromCalendarChange != null ? fromCalendarChange : fromPanelClick) != null ? _ref2 : rangePickerData == null ? void 0 : rangePickerData[0]) != null ? _ref : moment__default["default"](); // 如果开始时间来自面板点击(只有日期没有时间),将当前时刻的时分附加上去
23171
+
23172
+ if (!fromCalendarChange && fromPanelClick) {
23173
+ var now = moment__default["default"]();
23174
+ startMoment = startMoment.clone().hour(now.hour()).minute(now.minute()).second(0);
23160
23175
  }
23161
- } // 构造元素
23162
23176
 
23177
+ _Viewer.prototype.changeValueEx.call(_this2, _this2._rangePicker2Data([startMoment, moment__default["default"]()], true), true, true);
23178
+ }; // 判断是否应展示"至今"按钮
23163
23179
 
23164
- return jsxRuntime.jsx(antd.DatePicker.RangePicker, _objectSpread$8({
23180
+
23181
+ var showTillNow = !hideFooter; // 构造元素
23182
+
23183
+ return jsxRuntime.jsx("div", {
23165
23184
  ref: this._pickerRef,
23166
- renderExtraFooter: hideFooter ? undefined : function (mode) {
23167
- var _this2$_onCalendarCha;
23185
+ children: jsxRuntime.jsx(antd.DatePicker.RangePicker, _objectSpread$8({
23186
+ panelRender: pcShowTime && showTillNow ? function (panelNode) {
23187
+ // showTime 模式下:通过事件委托捕获面板上日期单元格的点击
23188
+ // 同时在 footer 的"确定"按钮同一行注入"至今"按钮
23189
+ return jsxRuntime.jsx("div", {
23190
+ onClick: function onClick(e) {
23191
+ var target = e.target;
23192
+ var cell = target.closest == null ? void 0 : target.closest(".ant-picker-cell");
23168
23193
 
23169
- // 如果开始时间超过当前时间(未来时间),不展示"至今"按钮
23170
- var startMoment = (_this2$_onCalendarCha = _this2._onCalendarChangeValue) == null ? void 0 : _this2$_onCalendarCha[0];
23194
+ if (cell) {
23195
+ // 排除 disabled 状态的日期单元格
23196
+ if (cell.classList.contains("ant-picker-cell-disabled")) return;
23197
+ var title = cell.getAttribute("title");
23171
23198
 
23172
- if (startMoment && startMoment.isAfter(moment__default["default"]())) {
23173
- return null;
23174
- }
23199
+ if (title) {
23200
+ var parsed = moment__default["default"](title, "YYYY-MM-DD"); // 校验 moment 解析有效性,无效日期不记录
23175
23201
 
23176
- return jsxRuntime.jsx("div", {
23177
- style: {
23178
- textAlign: "right"
23179
- },
23180
- children: jsxRuntime.jsx(antd.Button, {
23181
- size: "small",
23182
- style: {
23183
- width: "100px",
23184
- display: "inline-block",
23185
- marginTop: "5px"
23202
+ if (parsed.isValid()) {
23203
+ _this2._panelClickedDate = parsed;
23204
+ }
23205
+ }
23206
+ }
23186
23207
  },
23187
- onClick: function onClick() {
23188
- _Viewer.prototype.changeValueEx.call(_this2, _this2._rangePicker2Data(_this2._onCalendarChangeValue, true), true, true);
23208
+ ref: function ref(el) {
23209
+ var _ref3, _this2$_onCalendarCha2, _this2$_onCalendarCha3;
23210
+
23211
+ // 面板渲染后,将"至今"按钮注入到 .ant-picker-ok 内部,确定按钮之后
23212
+ // 这样两者在同一个 flex item 中,确定在左、至今在右
23213
+ if (!el) return;
23214
+ var okLi = el.querySelector(".ant-picker-ok");
23215
+ if (!okLi) return; // 开始时间在未来时,移除已有的至今按钮并不再注入
23216
+
23217
+ var previewStart = (_ref3 = (_this2$_onCalendarCha2 = (_this2$_onCalendarCha3 = _this2._onCalendarChangeValue) == null ? void 0 : _this2$_onCalendarCha3[0]) != null ? _this2$_onCalendarCha2 : _this2._panelClickedDate) != null ? _ref3 : rangePickerData == null ? void 0 : rangePickerData[0];
23218
+
23219
+ if (previewStart && previewStart.isAfter(moment__default["default"]())) {
23220
+ var existingBtn = okLi.querySelector(".till-now-btn");
23221
+ if (existingBtn) existingBtn.remove();
23222
+ return;
23223
+ }
23224
+
23225
+ if (!okLi.querySelector(".till-now-btn")) {
23226
+ var tillNowBtn = document.createElement("button");
23227
+ tillNowBtn.className = "ant-btn ant-btn-sm till-now-btn";
23228
+ tillNowBtn.textContent = "至今";
23229
+ tillNowBtn.style.cssText = "margin-left: 8px;"; // 使用具名函数以便于清理;先移除可能的旧监听再添加,防止重复绑定
23230
+
23231
+ var onTillNowClick = function onTillNowClick(e) {
23232
+ e.stopPropagation();
23233
+ handleTillNow();
23234
+ };
23235
+
23236
+ tillNowBtn.addEventListener("click", onTillNowClick);
23237
+ okLi.appendChild(tillNowBtn);
23238
+ }
23189
23239
  },
23190
- children: "\u81F3\u4ECA"
23191
- })
23192
- });
23193
- },
23194
- bordered: this.props.hideBorder ? false : true,
23195
- style: {
23196
- width: "300px"
23197
- },
23198
- locale: zhCN__default$1["default"],
23199
- defaultValue: rangePickerData,
23200
- onCalendarChange: function onCalendarChange(d) {
23201
- _this2._onCalendarChangeValue = d;
23202
- },
23203
- onChange: function onChange(vv) {
23204
- // 用户清空日期范围时,直接置空
23205
- if (!vv) {
23206
- _Viewer.prototype.changeValueEx.call(_this2, undefined, true, true);
23240
+ children: panelNode
23241
+ });
23242
+ } : undefined,
23243
+ renderExtraFooter: !pcShowTime && showTillNow ? function (mode) {
23244
+ var _this2$_onCalendarCha4, _this2$_onCalendarCha5;
23207
23245
 
23208
- return;
23209
- }
23246
+ // 非 showTime 模式:使用 renderExtraFooter 展示"至今"按钮
23247
+ var previewStart = (_this2$_onCalendarCha4 = (_this2$_onCalendarCha5 = _this2._onCalendarChangeValue) == null ? void 0 : _this2$_onCalendarCha5[0]) != null ? _this2$_onCalendarCha4 : rangePickerData == null ? void 0 : rangePickerData[0];
23210
23248
 
23211
- var currentData = _Viewer.prototype.getValue.call(_this2);
23249
+ if (previewStart && previewStart.isAfter(moment__default["default"]())) {
23250
+ return null;
23251
+ }
23212
23252
 
23213
- var isTillNow = ___default["default"].get(currentData, '[2]') === true; // 若当前是"至今"且用户只改了开始时间(结束时间仍为 null),保留 tillNow
23253
+ return jsxRuntime.jsx("div", {
23254
+ style: {
23255
+ textAlign: "right"
23256
+ },
23257
+ children: jsxRuntime.jsx(antd.Button, {
23258
+ size: "small",
23259
+ style: {
23260
+ width: "100px",
23261
+ display: "inline-block",
23262
+ marginTop: "5px"
23263
+ },
23264
+ onClick: handleTillNow,
23265
+ children: "\u81F3\u4ECA"
23266
+ })
23267
+ });
23268
+ } : undefined,
23269
+ bordered: this.props.hideBorder ? false : true,
23270
+ style: {
23271
+ width: "360px"
23272
+ },
23273
+ locale: zhCN__default$1["default"],
23274
+ defaultValue: rangePickerData,
23275
+ onCalendarChange: function onCalendarChange(d) {
23276
+ _this2._onCalendarChangeValue = d; // 用户开始新一轮选择时清理面板点击缓存,避免上一轮过时数据污染
23214
23277
 
23215
- var newTillNow = isTillNow && vv[1] == null;
23278
+ _this2._panelClickedDate = null;
23279
+ },
23280
+ onOpenChange: function onOpenChange(open) {
23281
+ if (!open) {
23282
+ _this2._panelClickedDate = null;
23283
+ }
23284
+ },
23285
+ onChange: function onChange(vv) {
23286
+ // 用户清空日期范围时,直接置空
23287
+ if (!vv) {
23288
+ _Viewer.prototype.changeValueEx.call(_this2, undefined, true, true);
23216
23289
 
23217
- _Viewer.prototype.changeValueEx.call(_this2, _this2._rangePicker2Data(vv, newTillNow), true, true);
23218
- }
23219
- }, extraProps), this.state.ctrlVersion + "_" + ((_this$props$schema$da7 = this.props.schema.dateRangePrecision) != null ? _this$props$schema$da7 : 'day'));
23290
+ return;
23291
+ }
23292
+
23293
+ var currentData = _Viewer.prototype.getValue.call(_this2);
23294
+
23295
+ var isTillNow = ___default["default"].get(currentData, "[2]") === true; // 若当前是"至今"且用户只改了开始时间(结束时间仍为 null),保留 tillNow
23296
+
23297
+ var newTillNow = isTillNow && vv[1] == null;
23298
+
23299
+ _Viewer.prototype.changeValueEx.call(_this2, _this2._rangePicker2Data(vv, newTillNow), true, true);
23300
+ }
23301
+ }, extraProps), this.state.ctrlVersion + "_" + ((_this$props$schema$da6 = this.props.schema.dateRangePrecision) != null ? _this$props$schema$da6 : "day"))
23302
+ });
23220
23303
  }
23221
23304
  };
23222
23305
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "form-driver",
3
- "version": "0.4.25",
3
+ "version": "0.4.27",
4
4
  "description": "An efficient framework for creating forms.",
5
5
  "license": "MIT",
6
6
  "authors": [