@piying/view-angular-core 2.3.2 → 2.4.1

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,6 +1,6 @@
1
1
  import { signal, computed, InjectionToken, effect, inject, Injector, untracked, DestroyRef, linkedSignal, isSignal } from '@angular/core';
2
2
  import * as v from 'valibot';
3
- import { isObservable, BehaviorSubject, Subject, tap, pipe, shareReplay, combineLatest, startWith, skip, map } from 'rxjs';
3
+ import { isObservable, BehaviorSubject, Subject, tap, pipe, shareReplay, map, combineLatest, startWith, skip } from 'rxjs';
4
4
  import rfdc from 'rfdc';
5
5
  import { deepEqual } from 'fast-equals';
6
6
  import { createRawConfig, defineType, BaseSchemaHandle, convertSchema, convertCore } from '@piying/valibot-visit';
@@ -1445,10 +1445,10 @@ class FormBuilder {
1445
1445
  : typeof field.type !== 'string'
1446
1446
  ? field.type
1447
1447
  : this.#findConfig.findComponentConfig(field.type);
1448
- const inputs = field.inputs;
1449
- const outputs = field.outputs;
1450
- const attributes = field.attributes;
1451
- const events = field.events;
1448
+ const inputs = asyncObjectSignal(field.inputs);
1449
+ const outputs = asyncObjectSignal(field.outputs);
1450
+ const attributes = asyncObjectSignal(field.attributes);
1451
+ const events = asyncObjectSignal(field.events);
1452
1452
  const formConfig$ = signal(field.formConfig ?? {});
1453
1453
  const renderConfig = signal(field.renderConfig ?? {});
1454
1454
  let control;
@@ -1503,7 +1503,7 @@ class FormBuilder {
1503
1503
  origin: field,
1504
1504
  renderConfig: renderConfig,
1505
1505
  formConfig: formConfig$,
1506
- props: field.props,
1506
+ props: asyncObjectSignal(field.props),
1507
1507
  context: this.#options.context,
1508
1508
  priority: field.priority,
1509
1509
  hooks: field.hooks,
@@ -1523,7 +1523,7 @@ class FormBuilder {
1523
1523
  define: define
1524
1524
  ? signal({ type: define, inputs, outputs, attributes, events })
1525
1525
  : undefined,
1526
- wrappers: field.wrappers,
1526
+ wrappers: this.#wrapperToSignal(field.wrappers, injector),
1527
1527
  injector: injector,
1528
1528
  };
1529
1529
  resolvedConfig =
@@ -1750,6 +1750,21 @@ class FormBuilder {
1750
1750
  parent.fixedChildren().push(inputField);
1751
1751
  }
1752
1752
  #findConfig = inject(FindConfigToken);
1753
+ #wrapperToSignal(list, injector) {
1754
+ return combineSignal(list.map((item) => observableSignal({
1755
+ type: item.type,
1756
+ attributes: asyncObjectSignal(item.attributes),
1757
+ inputs: asyncObjectSignal(item.inputs),
1758
+ outputs: asyncObjectSignal(item.outputs),
1759
+ events: asyncObjectSignal(item.events),
1760
+ }, {
1761
+ pipe: pipe(map((item) => {
1762
+ const defaultWrapperConfig = this.#findConfig.findWrapperComponent(item.type);
1763
+ return { ...item, type: defaultWrapperConfig };
1764
+ })),
1765
+ injector: injector,
1766
+ })));
1767
+ }
1753
1768
  }
1754
1769
  _a = FormBuilder;
1755
1770
 
@@ -1829,19 +1844,15 @@ function mergeOutputFn(field, outputs) {
1829
1844
  });
1830
1845
  }
1831
1846
  const mergeOutputs = (outputs) => rawConfig((field) => {
1832
- field.outputs.update((originOutputs) => {
1833
- originOutputs = { ...originOutputs };
1834
- for (const key in outputs) {
1835
- const oldFn = originOutputs[key];
1836
- originOutputs[key] = (...args) => {
1837
- if (oldFn) {
1838
- oldFn(...args);
1839
- }
1840
- return outputs[key](...args);
1841
- };
1842
- }
1843
- return originOutputs;
1844
- });
1847
+ for (const key in outputs) {
1848
+ const oldFn = field.outputs[key];
1849
+ field.outputs[key] = (...args) => {
1850
+ if (oldFn) {
1851
+ oldFn(...args);
1852
+ }
1853
+ return outputs[key](...args);
1854
+ };
1855
+ }
1845
1856
  });
1846
1857
  const asyncMergeOutputs = (outputs) => rawConfig((field) => {
1847
1858
  mergeHooksFn({
@@ -1986,7 +1997,7 @@ const createRemovePropertyFn = (key) => (list) => rawConfig((rawField, _, ...arg
1986
1997
  if (args.length > 0 &&
1987
1998
  typeof args[args.length - 1] === 'object' &&
1988
1999
  CustomDataSymbol in args[args.length - 1]) {
1989
- data$ = args[args.length - 1][CustomDataSymbol];
2000
+ data$ = args[args.length - 1][CustomDataSymbol](rawField);
1990
2001
  }
1991
2002
  else {
1992
2003
  data$ = (() => field);
@@ -2008,12 +2019,20 @@ function createPatchAsyncPropertyFn(key) {
2008
2019
  if (args.length > 0 &&
2009
2020
  typeof args[args.length - 1] === 'object' &&
2010
2021
  CustomDataSymbol in args[args.length - 1]) {
2011
- data$ = args[args.length - 1][CustomDataSymbol];
2022
+ data$ = args[args.length - 1][CustomDataSymbol](rawField);
2012
2023
  }
2013
2024
  else {
2014
- data$ = (() => rawField);
2025
+ data$ = rawField;
2015
2026
  }
2016
- const content$ = data$()[key];
2027
+ const content$ = {
2028
+ update: (fn) => {
2029
+ const value = fn(data$[key]);
2030
+ data$[key] = value;
2031
+ },
2032
+ set: (value) => {
2033
+ data$[key] = value;
2034
+ },
2035
+ };
2017
2036
  const inputList = Object.keys(dataObj);
2018
2037
  // 设置初始值
2019
2038
  content$.update((content) => ({
@@ -2025,6 +2044,16 @@ function createPatchAsyncPropertyFn(key) {
2025
2044
  }));
2026
2045
  return mergeHooksFn({
2027
2046
  allFieldsResolved: (field) => {
2047
+ let data$;
2048
+ if (args.length > 0 &&
2049
+ typeof args[args.length - 1] === 'object' &&
2050
+ CustomDataSymbol in args[args.length - 1]) {
2051
+ data$ = args[args.length - 1][CustomDataSymbol](undefined, field);
2052
+ }
2053
+ else {
2054
+ data$ = (() => field);
2055
+ }
2056
+ const content$ = data$()[key];
2028
2057
  Object.entries(dataObj).forEach(([key, value]) => {
2029
2058
  const result = value(field);
2030
2059
  content$.connect(key, result);
@@ -2039,12 +2068,20 @@ function createSetOrPatchPropertyFn(key, isPatch) {
2039
2068
  if (args.length > 0 &&
2040
2069
  typeof args[args.length - 1] === 'object' &&
2041
2070
  CustomDataSymbol in args[args.length - 1]) {
2042
- data$ = args[args.length - 1][CustomDataSymbol];
2071
+ data$ = args[args.length - 1][CustomDataSymbol](rawField);
2043
2072
  }
2044
2073
  else {
2045
- data$ = (() => rawField);
2074
+ data$ = rawField;
2046
2075
  }
2047
- const content$ = data$()[key];
2076
+ const content$ = {
2077
+ update: (fn) => {
2078
+ const value = fn(data$[key]);
2079
+ data$[key] = value;
2080
+ },
2081
+ set: (value) => {
2082
+ data$[key] = value;
2083
+ },
2084
+ };
2048
2085
  if (isPatch) {
2049
2086
  content$.update((data) => ({
2050
2087
  ...data,
@@ -2056,21 +2093,6 @@ function createSetOrPatchPropertyFn(key, isPatch) {
2056
2093
  }
2057
2094
  });
2058
2095
  }
2059
- function createMapPropertyFn(key) {
2060
- return (fn) => rawConfig((rawField, _, ...args) => {
2061
- let data$;
2062
- if (args.length > 0 &&
2063
- typeof args[args.length - 1] === 'object' &&
2064
- CustomDataSymbol in args[args.length - 1]) {
2065
- data$ = args[args.length - 1][CustomDataSymbol];
2066
- }
2067
- else {
2068
- data$ = (() => rawField);
2069
- }
2070
- const content$ = data$()[key];
2071
- content$.map(fn);
2072
- });
2073
- }
2074
2096
  function createMapAsyncPropertyFn(key) {
2075
2097
  return (fn) => rawConfig((rawField, _, ...args) => mergeHooksFn({
2076
2098
  allFieldsResolved: (field) => {
@@ -2078,7 +2100,7 @@ function createMapAsyncPropertyFn(key) {
2078
2100
  if (args.length > 0 &&
2079
2101
  typeof args[args.length - 1] === 'object' &&
2080
2102
  CustomDataSymbol in args[args.length - 1]) {
2081
- data$ = args[args.length - 1][CustomDataSymbol];
2103
+ data$ = args[args.length - 1][CustomDataSymbol](undefined, field);
2082
2104
  }
2083
2105
  else {
2084
2106
  data$ = (() => field);
@@ -2094,7 +2116,6 @@ const __actions = {
2094
2116
  set: createSetOrPatchPropertyFn('inputs'),
2095
2117
  patchAsync: createPatchAsyncPropertyFn('inputs'),
2096
2118
  remove: createRemovePropertyFn('inputs'),
2097
- map: createMapPropertyFn('inputs'),
2098
2119
  mapAsync: createMapAsyncPropertyFn('inputs'),
2099
2120
  },
2100
2121
  outputs: {
@@ -2104,7 +2125,6 @@ const __actions = {
2104
2125
  remove: createRemovePropertyFn('outputs'),
2105
2126
  merge: mergeOutputs,
2106
2127
  mergeAsync: asyncMergeOutputs,
2107
- map: createMapPropertyFn('outputs'),
2108
2128
  mapAsync: createMapAsyncPropertyFn('outputs'),
2109
2129
  },
2110
2130
  attributes: {
@@ -2112,7 +2132,6 @@ const __actions = {
2112
2132
  set: createSetOrPatchPropertyFn('attributes'),
2113
2133
  patchAsync: createPatchAsyncPropertyFn('attributes'),
2114
2134
  remove: createRemovePropertyFn('attributes'),
2115
- map: createMapPropertyFn('attributes'),
2116
2135
  mapAsync: createMapAsyncPropertyFn('attributes'),
2117
2136
  },
2118
2137
  events: {
@@ -2120,7 +2139,6 @@ const __actions = {
2120
2139
  set: createSetOrPatchPropertyFn('events'),
2121
2140
  patchAsync: createPatchAsyncPropertyFn('events'),
2122
2141
  remove: createRemovePropertyFn('events'),
2123
- map: createMapPropertyFn('events'),
2124
2142
  mapAsync: createMapAsyncPropertyFn('events'),
2125
2143
  },
2126
2144
  props: {
@@ -2128,7 +2146,6 @@ const __actions = {
2128
2146
  set: createSetOrPatchPropertyFn('props'),
2129
2147
  patchAsync: createPatchAsyncPropertyFn('props'),
2130
2148
  remove: createRemovePropertyFn('props'),
2131
- map: createMapPropertyFn('props'),
2132
2149
  mapAsync: createMapAsyncPropertyFn('props'),
2133
2150
  },
2134
2151
  };
@@ -2136,48 +2153,43 @@ const __actions = {
2136
2153
  function createSetOrPatchWrappersFn(isPatch) {
2137
2154
  return (wrappers) => rawConfig((rawField, _) => {
2138
2155
  const wrapperConfig = rawField.globalConfig.additionalData['defaultWrapperMetadataGroup'];
2139
- const injector = rawField.globalConfig.additionalData['injector'];
2140
- const OptionDefine = {
2141
- pipe: pipe(map((item) => {
2142
- if (typeof item.type === 'string') {
2143
- const type = wrapperConfig[item.type]?.type;
2144
- if (!type) {
2145
- throw new Error(`🈳wrapper:[${item.type}]❗`);
2146
- }
2147
- return { ...item, type: type };
2148
- }
2149
- return item;
2150
- })),
2151
- injector: injector,
2152
- };
2153
2156
  if (!isPatch) {
2154
- rawField.wrappers.clean();
2155
- }
2156
- wrappers.forEach((item) => {
2157
- if (typeof item === 'string') {
2158
- const defaultActions = wrapperConfig[item]?.actions ?? [];
2159
- const define = observableSignal({
2160
- type: item,
2161
- inputs: asyncObjectSignal({}),
2162
- outputs: asyncObjectSignal({}),
2163
- attributes: asyncObjectSignal({}),
2164
- events: asyncObjectSignal({}),
2165
- }, OptionDefine);
2166
- rawField.wrappers.add(define);
2157
+ rawField.wrappers = [];
2158
+ }
2159
+ wrappers.forEach((wrapperItem) => {
2160
+ if (typeof wrapperItem === 'string') {
2161
+ const defaultActions = wrapperConfig[wrapperItem]?.actions ?? [];
2162
+ const define = {
2163
+ type: wrapperItem,
2164
+ inputs: {},
2165
+ outputs: {},
2166
+ attributes: {},
2167
+ events: {},
2168
+ };
2169
+ rawField.wrappers.push(define);
2167
2170
  defaultActions.forEach((item) => {
2168
2171
  item.value(rawField, _, {
2169
- [CustomDataSymbol]: define,
2172
+ [CustomDataSymbol]: (rawField, field) => {
2173
+ if (rawField) {
2174
+ return define;
2175
+ }
2176
+ else {
2177
+ return field.wrappers
2178
+ .items()
2179
+ .find((item) => item.input().type === wrapperItem);
2180
+ }
2181
+ },
2170
2182
  });
2171
2183
  });
2172
2184
  }
2173
2185
  else {
2174
- rawField.wrappers.add(observableSignal({
2175
- type: item.type,
2176
- inputs: asyncObjectSignal(item.inputs ?? {}),
2177
- outputs: asyncObjectSignal(item.outputs ?? {}),
2178
- attributes: asyncObjectSignal(item.attributes ?? {}),
2179
- events: asyncObjectSignal(item.events ?? {}),
2180
- }, OptionDefine));
2186
+ rawField.wrappers.push({
2187
+ type: wrapperItem.type,
2188
+ inputs: wrapperItem.inputs ?? {},
2189
+ outputs: wrapperItem.outputs ?? {},
2190
+ attributes: wrapperItem.attributes ?? {},
2191
+ events: wrapperItem.events ?? {},
2192
+ });
2181
2193
  }
2182
2194
  });
2183
2195
  });
@@ -2201,6 +2213,12 @@ function removeWrappers(removeList) {
2201
2213
  }, { position: 'bottom' }, field);
2202
2214
  });
2203
2215
  }
2216
+ function setSubInitValue(key, fn, initObj) {
2217
+ if (!Object.keys(initObj[key]).length) {
2218
+ return;
2219
+ }
2220
+ fn()[key].set(initObj[key]);
2221
+ }
2204
2222
  function patchAsyncWrapper(type, actions, options) {
2205
2223
  return rawConfig((rawFiled) => {
2206
2224
  // 在这里增加要处理的wrapper类型
@@ -2228,10 +2246,24 @@ function patchAsyncWrapper(type, actions, options) {
2228
2246
  }
2229
2247
  const allActions = [...defaultActions, ...(actions ?? [])];
2230
2248
  for (const item of allActions) {
2231
- const tempField = {};
2249
+ const tempField = {
2250
+ inputs: {},
2251
+ outputs: {},
2252
+ attributes: {},
2253
+ events: {},
2254
+ };
2232
2255
  item.value(tempField, undefined, {
2233
- [CustomDataSymbol]: initData,
2256
+ [CustomDataSymbol]: (rawField, field) => {
2257
+ if (rawField) {
2258
+ return tempField;
2259
+ }
2260
+ return initData;
2261
+ },
2234
2262
  });
2263
+ setSubInitValue('inputs', initData, tempField);
2264
+ setSubInitValue('outputs', initData, tempField);
2265
+ setSubInitValue('attributes', initData, tempField);
2266
+ setSubInitValue('events', initData, tempField);
2235
2267
  tempField.hooks?.allFieldsResolved?.(field);
2236
2268
  }
2237
2269
  },
@@ -2249,10 +2281,24 @@ function changeAsyncWrapper(indexFn, actions) {
2249
2281
  throw new Error(`change wrapper not found`);
2250
2282
  }
2251
2283
  for (const item of actions) {
2252
- const tempField = {};
2284
+ const tempField = {
2285
+ inputs: {},
2286
+ outputs: {},
2287
+ attributes: {},
2288
+ events: {},
2289
+ };
2253
2290
  item.value(tempField, undefined, {
2254
- [CustomDataSymbol]: initData,
2291
+ [CustomDataSymbol]: (rawField, field) => {
2292
+ if (rawField) {
2293
+ return tempField;
2294
+ }
2295
+ return initData;
2296
+ },
2255
2297
  });
2298
+ setSubInitValue('inputs', initData, tempField);
2299
+ setSubInitValue('outputs', initData, tempField);
2300
+ setSubInitValue('attributes', initData, tempField);
2301
+ setSubInitValue('events', initData, tempField);
2256
2302
  tempField.hooks?.allFieldsResolved?.(field);
2257
2303
  }
2258
2304
  },
@@ -2302,16 +2348,15 @@ const componentClass = (className, merge) => rawConfig((rawField, _, ...args) =>
2302
2348
  if (args.length > 0 &&
2303
2349
  typeof args[args.length - 1] === 'object' &&
2304
2350
  CustomDataSymbol in args[args.length - 1]) {
2305
- data$ = args[args.length - 1][CustomDataSymbol];
2351
+ data$ = args[args.length - 1][CustomDataSymbol](rawField);
2306
2352
  }
2307
2353
  else {
2308
- data$ = (() => rawField);
2354
+ data$ = rawField;
2309
2355
  }
2310
- const content$ = data$()['attributes'];
2311
- content$.update((data) => ({
2312
- ...data,
2313
- class: merge ? clsx(data?.['class'], className) : clsx(className),
2314
- }));
2356
+ const content$ = data$['attributes'];
2357
+ content$['class'] = merge
2358
+ ? clsx(content$['class'], className)
2359
+ : clsx(className);
2315
2360
  });
2316
2361
  const bottomClass = componentClass;
2317
2362
  function patchAsyncClass(fn) {
@@ -2377,12 +2422,12 @@ const actions = {
2377
2422
  };
2378
2423
 
2379
2424
  class CoreSchemaHandle extends BaseSchemaHandle {
2380
- inputs = asyncObjectSignal({});
2381
- outputs = asyncObjectSignal({});
2382
- attributes = asyncObjectSignal({});
2383
- events = asyncObjectSignal({});
2384
- wrappers = combineSignal([]);
2385
- props = asyncObjectSignal({});
2425
+ inputs = {};
2426
+ outputs = {};
2427
+ attributes = {};
2428
+ events = {};
2429
+ wrappers = [];
2430
+ props = {};
2386
2431
  alias;
2387
2432
  movePath;
2388
2433
  renderConfig;
@@ -2471,16 +2516,10 @@ class CoreSchemaHandle extends BaseSchemaHandle {
2471
2516
  this.formConfig.groupMode = 'reset';
2472
2517
  }
2473
2518
  enumSchema(schema) {
2474
- this.props.update((data) => ({
2475
- ...data,
2476
- options: data['options'] ?? schema.options,
2477
- }));
2519
+ this.props['options'] = this.props['options'] ?? schema.options;
2478
2520
  }
2479
2521
  updateProps(key, value) {
2480
- this.props.update((data) => ({
2481
- ...data,
2482
- [key]: value,
2483
- }));
2522
+ this.props[key] = value;
2484
2523
  }
2485
2524
  intersectBefore(schema) {
2486
2525
  if (this.childrenAsVirtualGroup) {