@neeloong/form 0.24.0 → 0.25.0

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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @neeloong/form v0.24.0
2
+ * @neeloong/form v0.25.0
3
3
  * (c) 2024-2026 Fierflame
4
4
  * @license Apache-2.0
5
5
  */
@@ -904,7 +904,7 @@ class Store {
904
904
  /**
905
905
  * 异步校验
906
906
  * @overload
907
- * @param {true} [path]
907
+ * @param {true} [self]
908
908
  * @returns {Promise<string[] | null>}
909
909
  */
910
910
  /**
@@ -927,6 +927,7 @@ class Store {
927
927
  });
928
928
  }
929
929
  const selfPath = Array.isArray(path) ? path : [];
930
+ if (this.#hidden.get()) { return Promise.resolve([]); }
930
931
  const list = [this.validate(true).then(errors => {
931
932
  if (!errors?.length) { return []; }
932
933
  return [{ path: [...selfPath], store: /** @type {Store} */(this), errors }];
@@ -5048,6 +5049,7 @@ function Line(store, fieldRenderer, layout, {
5048
5049
  const body = root.appendChild(document.createElement('tr'));
5049
5050
  const main = body.appendChild(document.createElement('td'));
5050
5051
  main.colSpan = columns.length;
5052
+ main.appendChild(form);
5051
5053
  body.hidden = true;
5052
5054
  trigger = () => {
5053
5055
  if (body.hidden) {
@@ -5140,6 +5142,64 @@ function Line(store, fieldRenderer, layout, {
5140
5142
  return root;
5141
5143
  }
5142
5144
 
5145
+ /** @import { ArrayStore } from '../Store/index.mjs' */
5146
+ /** @import { StoreLayout } from '../StoreLayout.types.mjs' */
5147
+
5148
+ /**
5149
+ *
5150
+ * @template T
5151
+ * @param {ArrayStore} store
5152
+ * @param {StoreLayout.Field<T>} layout
5153
+ * @param {StoreLayout.Action[]} actionOptions
5154
+ * @param {(fields: { field: string; width: any; label: any; }[]) => StoreLayout.Column<T>[]} createDefault
5155
+ * @returns {StoreLayout.Column<T>[]}
5156
+ */
5157
+ function getColumns(store, layout, actionOptions, createDefault) {
5158
+ const fieldList = Object.entries(store.type || {})
5159
+ .filter(([k, v]) => typeof v?.type !== 'object')
5160
+ .map(([field, { width, label }]) => ({ field, width, label }));
5161
+ const headerColumns = layout.columns;
5162
+ if (Array.isArray(headerColumns)) {
5163
+ const map = new Map(fieldList.map(v => [v.field, v]));
5164
+ /** @type {(StoreLayout.Column<T> | null)[]} */
5165
+ const allColumns = headerColumns.map(v => {
5166
+ if (!v) { return null; }
5167
+ if (typeof v === 'number') { return { placeholder: v }; }
5168
+ if (typeof v === 'string') { return map.get(v) || null; }
5169
+ if (typeof v !== 'object') { return null; }
5170
+ if (Array.isArray(v)) {
5171
+ /** @type {Set<StoreLayout.Action>} */
5172
+ const options = new Set(actionOptions);
5173
+ const actions = v.filter(v => options.delete(v));
5174
+ if (!actions) { return null; }
5175
+ return { actions };
5176
+ }
5177
+ const { action, actions, field, placeholder, pattern, width, label } = v;
5178
+ if (field) {
5179
+ const define = map.get(field);
5180
+ if (define) {
5181
+ return { field, placeholder, width, label: label || define.label };
5182
+ }
5183
+ }
5184
+ const options = new Set(actionOptions);
5185
+ const allActions = [action, actions].flat().filter(v => v && options.delete(v));
5186
+ if (allActions.length) {
5187
+ return { actions: /** @type {StoreLayout.Action[]} */(allActions), width, label };
5188
+ }
5189
+ if (pattern) {
5190
+ return { pattern, placeholder, width, label };
5191
+ }
5192
+ if (placeholder || width) {
5193
+ return { placeholder, width, label };
5194
+ }
5195
+ return null;
5196
+ });
5197
+ const columns = /** @type {StoreLayout.Column<T>[]} */(allColumns.filter(Boolean));
5198
+ if (columns.length) { return columns; }
5199
+ }
5200
+ return createDefault(fieldList);
5201
+ }
5202
+
5143
5203
  /** @import { Store, ArrayStore } from '../Store/index.mjs' */
5144
5204
  /** @import { StoreLayout } from '../StoreLayout.types.mjs' */
5145
5205
 
@@ -5170,6 +5230,7 @@ function renderHead(signal, parent, columns, add, addable, editable) {
5170
5230
  watch(() => !addable.get(), disabled => { button.disabled = disabled; }, true, signal);
5171
5231
  }
5172
5232
  }
5233
+
5173
5234
  /**
5174
5235
  *
5175
5236
  * @template T
@@ -5181,54 +5242,15 @@ function renderHead(signal, parent, columns, add, addable, editable) {
5181
5242
  */
5182
5243
  function Table(store, fieldRenderer, layout, options) {
5183
5244
  if (options?.signal?.aborted) { return null; }
5184
- const headerColumns = layout.columns;
5185
- const fieldList = Object.entries(store.type || {})
5186
- .filter(([k, v]) => typeof v?.type !== 'object')
5187
- .map(([field, { width, label }]) => ({ field, width, label }));
5188
- /** @type {StoreLayout.Column<T>[]} */
5189
- let columns = [];
5190
- if (Array.isArray(headerColumns)) {
5191
- const map = new Map(fieldList.map(v => [v.field, v]));
5192
-
5193
- /** @type {(StoreLayout.Column<T> | null)[]} */
5194
- const allColumns = headerColumns.map(v => {
5195
- if (!v) { return null; }
5196
- if (typeof v === 'number') { return { placeholder: v }; }
5197
- if (typeof v === 'string') { return map.get(v) || null; }
5198
- if (typeof v !== 'object') { return null; }
5199
- if (Array.isArray(v)) {
5200
- /** @type {Set<StoreLayout.Action>} */
5201
- const options = new Set(['add', 'move', 'trigger', 'remove', 'serial', 'open', 'collapse']);
5202
- const actions = v.filter(v => options.delete(v));
5203
- if (!actions) { return null; }
5204
- return { actions };
5205
- }
5206
- const { action, actions, field, placeholder, pattern, width, label } = v;
5207
- if (field) {
5208
- const define = map.get(field);
5209
- if (define) {
5210
- return { field, placeholder, width, label: label || define.label };
5211
- }
5212
- }
5213
- const options = new Set(['add', 'move', 'trigger', 'remove', 'serial']);
5214
- const allActions = [action, actions].flat().filter(v => v && options.delete(v));
5215
- if (allActions.length) {
5216
- return { actions: /** @type {StoreLayout.Action[]} */(allActions), width, label };
5217
- }
5218
- // if (pattern) {
5219
- // return { pattern, placeholder, width, label };
5220
- // }
5221
- return null;
5222
- });
5223
- columns = /** @type {StoreLayout.Column<T>[]} */(allColumns.filter(Boolean));
5224
-
5225
- }
5226
- if (!columns.length) {
5227
- columns = [
5245
+ const columns = getColumns(
5246
+ store,
5247
+ layout,
5248
+ ['add', 'move', 'trigger', 'remove', 'serial'],
5249
+ fields => [
5228
5250
  { actions: ['add', 'trigger', 'move', 'remove', 'serial'] },
5229
- ...fieldList.slice(0, 3),
5230
- ];
5231
- }
5251
+ ...fields.slice(0, 3),
5252
+ ],
5253
+ );
5232
5254
 
5233
5255
  const table = document.createElement('table');
5234
5256
  table.classList.add('NeeloongForm-table');
@@ -5805,56 +5827,16 @@ function createState(store, states, drag, levelKey, index) {
5805
5827
  */
5806
5828
  function Tree(store, fieldRenderer, layout, options) {
5807
5829
  if (options?.signal?.aborted) { return null; }
5808
- const headerColumns = layout.columns;
5809
- const fieldList = Object.entries(store.type || {})
5810
- .filter(([k, v]) => typeof v?.type !== 'object')
5811
- .map(([field, { width, label }]) => ({ field, width, label }));
5812
- /** @type {StoreLayout.Column<T>[]} */
5813
- let columns = [];
5814
- if (Array.isArray(headerColumns)) {
5815
- const map = new Map(fieldList.map(v => [v.field, v]));
5816
- /** @type {(StoreLayout.Column<T> | null)[]} */
5817
- const allColumns = headerColumns.map(v => {
5818
- if (!v) { return null; }
5819
- if (typeof v === 'number') { return { placeholder: v }; }
5820
- if (typeof v === 'string') { return map.get(v) || null; }
5821
- if (typeof v !== 'object') { return null; }
5822
- if (Array.isArray(v)) {
5823
- /** @type {Set<StoreLayout.Action>} */
5824
- const options = new Set(['add', 'move', 'trigger', 'remove', 'serial', 'open', 'collapse']);
5825
- const actions = v.filter(v => options.delete(v));
5826
- if (!actions) { return null; }
5827
- return { actions };
5828
- }
5829
- const { action, actions, field, placeholder, pattern, width, label } = v;
5830
- if (field) {
5831
- const define = map.get(field);
5832
- if (define) {
5833
- return { field, placeholder, width, label: label || define.label };
5834
- }
5835
- }
5836
- const options = new Set(['add', 'move', 'trigger', 'remove', 'serial', 'open', 'collapse']);
5837
- const allActions = [action, actions].flat().filter(v => v && options.delete(v));
5838
- if (allActions.length) {
5839
- return { actions: /** @type {StoreLayout.Action[]} */(allActions), width, label };
5840
- }
5841
- if (pattern) {
5842
- return { pattern, placeholder, width, label };
5843
- }
5844
- if (placeholder || width) {
5845
- return { placeholder, width, label };
5846
- }
5847
- return null;
5848
- });
5849
- columns = /** @type {StoreLayout.Column<T>[]} */(allColumns.filter(Boolean));
5850
- }
5851
- if (!columns.length) {
5852
- columns = [
5830
+ const columns = getColumns(
5831
+ store,
5832
+ layout,
5833
+ ['add', 'move', 'trigger', 'remove', 'serial', 'open', 'collapse'],
5834
+ fields => [
5853
5835
  { actions: ['collapse', 'move'] },
5854
- fieldList[0],
5836
+ fields[0],
5855
5837
  { actions: ['add', 'remove'] },
5856
- ];
5857
- }
5838
+ ]
5839
+ );
5858
5840
 
5859
5841
 
5860
5842
  const root = document.createElement('div');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neeloong/form",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "一个基于响应式数据绑定的表单渲染库",
5
5
  "keywords": [
6
6
  "from",